8 #include <linux/module.h>
13 #include <linux/device.h>
16 #include <linux/slab.h>
49 struct aic26 *
aic26 = snd_soc_codec_get_drvdata(codec);
63 buffer[0] = (cmd >> 8) & 0xff;
64 buffer[1] = cmd & 0xff;
67 dev_err(&aic26->
spi->dev,
"AIC26 reg read error\n");
70 value = (buffer[0] << 8) | buffer[1];
77 static unsigned int aic26_reg_read_cache(
struct snd_soc_codec *codec,
90 static int aic26_reg_write(
struct snd_soc_codec *codec,
unsigned int reg,
93 struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
107 buffer[0] = (cmd >> 8) & 0xff;
108 buffer[1] = cmd & 0xff;
109 buffer[2] = value >> 8;
111 rc = spi_write(aic26->
spi, buffer, 4);
113 dev_err(&aic26->
spi->dev,
"AIC26 reg read error\n");
130 struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
131 int fsref,
divisor, wlen, pval, jval, dval, qval;
134 dev_dbg(&aic26->
spi->dev,
"aic26_hw_params(substream=%p, params=%p)\n",
140 case 8000: fsref = 48000; divisor =
AIC26_DIV_6;
break;
141 case 11025: fsref = 44100; divisor =
AIC26_DIV_4;
break;
142 case 12000: fsref = 48000; divisor =
AIC26_DIV_4;
break;
143 case 16000: fsref = 48000; divisor =
AIC26_DIV_3;
break;
144 case 22050: fsref = 44100; divisor =
AIC26_DIV_2;
break;
145 case 24000: fsref = 48000; divisor =
AIC26_DIV_2;
break;
147 case 44100: fsref = 44100; divisor =
AIC26_DIV_1;
break;
148 case 48000: fsref = 48000; divisor =
AIC26_DIV_1;
break;
170 jval = fsref / (aic26->
mclk / 2048);
172 dval = fsref - (jval * (aic26->
mclk / 2048));
173 dval = (10000 * dval) / (aic26->
mclk / 2048);
174 dev_dbg(&aic26->
spi->dev,
"Setting PLLM to %d.%04d\n", jval, dval);
176 reg = 0x8000 | qval << 11 | pval << 8 | jval << 2;
193 reg |= wlen | aic26->
datfm | (divisor << 3) | divisor;
205 struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
208 dev_dbg(&aic26->
spi->dev,
"aic26_mute(dai=%p, mute=%i)\n",
220 static int aic26_set_sysclk(
struct snd_soc_dai *codec_dai,
221 int clk_id,
unsigned int freq,
int dir)
224 struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
226 dev_dbg(&aic26->
spi->dev,
"aic26_set_sysclk(dai=%p, clk_id==%i,"
227 " freq=%i, dir=%i)\n",
228 codec_dai, clk_id, freq, dir);
231 if ((freq < 2000000) || (freq > 50000000))
238 static int aic26_set_fmt(
struct snd_soc_dai *codec_dai,
unsigned int fmt)
241 struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
243 dev_dbg(&aic26->
spi->dev,
"aic26_set_fmt(dai=%p, fmt==%i)\n",
270 #define AIC26_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
271 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
272 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
273 SNDRV_PCM_RATE_48000)
274 #define AIC26_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_BE |\
275 SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S32_BE)
278 .hw_params = aic26_hw_params,
279 .digital_mute = aic26_mute,
280 .set_sysclk = aic26_set_sysclk,
281 .set_fmt = aic26_set_fmt,
285 .name =
"tlv320aic26-hifi",
287 .stream_name =
"Playback",
294 .stream_name =
"Capture",
300 .ops = &aic26_dai_ops,
306 static const char *aic26_capture_src_text[] = {
"Mic",
"Aux"};
307 static const struct soc_enum aic26_capture_src_enum =
320 SOC_ENUM(
"Capture Source", aic26_capture_src_enum),
334 amp = (val >> 12) & 0x7;
335 freq = (125 << ((val >> 8) & 0x7)) >> 1;
336 len = 2 * (1 + ((val >> 4) & 0xf));
338 return sprintf(buf,
"amp=%x freq=%iHz len=%iclks\n", amp, freq, len);
356 static DEVICE_ATTR(keyclick, 0644, aic26_keyclick_show, aic26_keyclick_set);
365 dev_info(codec->
dev,
"Probing AIC26 SoC CODEC driver\n");
380 for (i = 0; i < codec->
driver->reg_cache_size; i++)
381 aic26_reg_read(codec, i);
387 dev_info(codec->
dev,
"error creating sysfs files\n");
390 dev_dbg(codec->
dev,
"Registering controls\n");
399 .probe = aic26_probe,
400 .read = aic26_reg_read,
401 .write = aic26_reg_write,
403 .reg_word_size =
sizeof(
u16),
415 dev_dbg(&spi->
dev,
"probing tlv320aic26 spi device\n");
428 &aic26_soc_codec_dev, &aic26_dai, 1);
432 static int aic26_spi_remove(
struct spi_device *spi)
440 .name =
"tlv320aic26-codec",
443 .probe = aic26_spi_probe,
444 .remove = aic26_spi_remove,