diff options
-rw-r--r-- | sound/soc/codecs/Kconfig | 7 | ||||
-rw-r--r-- | sound/soc/codecs/Makefile | 2 | ||||
-rw-r--r-- | sound/soc/codecs/adau1701.c | 548 | ||||
-rw-r--r-- | sound/soc/codecs/adau1701.h | 17 |
4 files changed, 573 insertions, 1 deletions
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 98175a096df2..f745e557831e 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig | |||
@@ -17,6 +17,7 @@ config SND_SOC_ALL_CODECS | |||
17 | select SND_SOC_AD193X if SND_SOC_I2C_AND_SPI | 17 | select SND_SOC_AD193X if SND_SOC_I2C_AND_SPI |
18 | select SND_SOC_AD1980 if SND_SOC_AC97_BUS | 18 | select SND_SOC_AD1980 if SND_SOC_AC97_BUS |
19 | select SND_SOC_AD73311 | 19 | select SND_SOC_AD73311 |
20 | select SND_SOC_ADAU1701 if I2C | ||
20 | select SND_SOC_ADS117X | 21 | select SND_SOC_ADS117X |
21 | select SND_SOC_AK4104 if SPI_MASTER | 22 | select SND_SOC_AK4104 if SPI_MASTER |
22 | select SND_SOC_AK4535 if I2C | 23 | select SND_SOC_AK4535 if I2C |
@@ -130,7 +131,11 @@ config SND_SOC_AD1980 | |||
130 | 131 | ||
131 | config SND_SOC_AD73311 | 132 | config SND_SOC_AD73311 |
132 | tristate | 133 | tristate |
133 | 134 | ||
135 | config SND_SOC_ADAU1701 | ||
136 | select SIGMA | ||
137 | tristate | ||
138 | |||
134 | config SND_SOC_ADS117X | 139 | config SND_SOC_ADS117X |
135 | tristate | 140 | tristate |
136 | 141 | ||
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index fd8558406ef0..30a4c631aef4 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile | |||
@@ -4,6 +4,7 @@ snd-soc-ad1836-objs := ad1836.o | |||
4 | snd-soc-ad193x-objs := ad193x.o | 4 | snd-soc-ad193x-objs := ad193x.o |
5 | snd-soc-ad1980-objs := ad1980.o | 5 | snd-soc-ad1980-objs := ad1980.o |
6 | snd-soc-ad73311-objs := ad73311.o | 6 | snd-soc-ad73311-objs := ad73311.o |
7 | snd-soc-adau1701-objs := adau1701.o | ||
7 | snd-soc-ads117x-objs := ads117x.o | 8 | snd-soc-ads117x-objs := ads117x.o |
8 | snd-soc-ak4104-objs := ak4104.o | 9 | snd-soc-ak4104-objs := ak4104.o |
9 | snd-soc-ak4535-objs := ak4535.o | 10 | snd-soc-ak4535-objs := ak4535.o |
@@ -95,6 +96,7 @@ obj-$(CONFIG_SND_SOC_AD1836) += snd-soc-ad1836.o | |||
95 | obj-$(CONFIG_SND_SOC_AD193X) += snd-soc-ad193x.o | 96 | obj-$(CONFIG_SND_SOC_AD193X) += snd-soc-ad193x.o |
96 | obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o | 97 | obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o |
97 | obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o | 98 | obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o |
99 | obj-$(CONFIG_SND_SOC_ADAU1701) += snd-soc-adau1701.o | ||
98 | obj-$(CONFIG_SND_SOC_ADS117X) += snd-soc-ads117x.o | 100 | obj-$(CONFIG_SND_SOC_ADS117X) += snd-soc-ads117x.o |
99 | obj-$(CONFIG_SND_SOC_AK4104) += snd-soc-ak4104.o | 101 | obj-$(CONFIG_SND_SOC_AK4104) += snd-soc-ak4104.o |
100 | obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o | 102 | obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o |
diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c new file mode 100644 index 000000000000..6c01bb649123 --- /dev/null +++ b/sound/soc/codecs/adau1701.c | |||
@@ -0,0 +1,548 @@ | |||
1 | /* | ||
2 | * Driver for ADAU1701 SigmaDSP processor | ||
3 | * | ||
4 | * Copyright 2011 Analog Devices Inc. | ||
5 | * Author: Lars-Peter Clausen <lars@metafoo.de> | ||
6 | * based on an inital version by Cliff Cai <cliff.cai@analog.com> | ||
7 | * | ||
8 | * Licensed under the GPL-2 or later. | ||
9 | */ | ||
10 | |||
11 | #include <linux/module.h> | ||
12 | #include <linux/init.h> | ||
13 | #include <linux/i2c.h> | ||
14 | #include <linux/delay.h> | ||
15 | #include <linux/sigma.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <sound/core.h> | ||
18 | #include <sound/pcm.h> | ||
19 | #include <sound/pcm_params.h> | ||
20 | #include <sound/soc.h> | ||
21 | |||
22 | #include "adau1701.h" | ||
23 | |||
24 | #define ADAU1701_DSPCTRL 0x1c | ||
25 | #define ADAU1701_SEROCTL 0x1e | ||
26 | #define ADAU1701_SERICTL 0x1f | ||
27 | |||
28 | #define ADAU1701_AUXNPOW 0x22 | ||
29 | |||
30 | #define ADAU1701_OSCIPOW 0x26 | ||
31 | #define ADAU1701_DACSET 0x27 | ||
32 | |||
33 | #define ADAU1701_NUM_REGS 0x28 | ||
34 | |||
35 | #define ADAU1701_DSPCTRL_CR (1 << 2) | ||
36 | #define ADAU1701_DSPCTRL_DAM (1 << 3) | ||
37 | #define ADAU1701_DSPCTRL_ADM (1 << 4) | ||
38 | #define ADAU1701_DSPCTRL_SR_48 0x00 | ||
39 | #define ADAU1701_DSPCTRL_SR_96 0x01 | ||
40 | #define ADAU1701_DSPCTRL_SR_192 0x02 | ||
41 | #define ADAU1701_DSPCTRL_SR_MASK 0x03 | ||
42 | |||
43 | #define ADAU1701_SEROCTL_INV_LRCLK 0x2000 | ||
44 | #define ADAU1701_SEROCTL_INV_BCLK 0x1000 | ||
45 | #define ADAU1701_SEROCTL_MASTER 0x0800 | ||
46 | |||
47 | #define ADAU1701_SEROCTL_OBF16 0x0000 | ||
48 | #define ADAU1701_SEROCTL_OBF8 0x0200 | ||
49 | #define ADAU1701_SEROCTL_OBF4 0x0400 | ||
50 | #define ADAU1701_SEROCTL_OBF2 0x0600 | ||
51 | #define ADAU1701_SEROCTL_OBF_MASK 0x0600 | ||
52 | |||
53 | #define ADAU1701_SEROCTL_OLF1024 0x0000 | ||
54 | #define ADAU1701_SEROCTL_OLF512 0x0080 | ||
55 | #define ADAU1701_SEROCTL_OLF256 0x0100 | ||
56 | #define ADAU1701_SEROCTL_OLF_MASK 0x0180 | ||
57 | |||
58 | #define ADAU1701_SEROCTL_MSB_DEALY1 0x0000 | ||
59 | #define ADAU1701_SEROCTL_MSB_DEALY0 0x0004 | ||
60 | #define ADAU1701_SEROCTL_MSB_DEALY8 0x0008 | ||
61 | #define ADAU1701_SEROCTL_MSB_DEALY12 0x000c | ||
62 | #define ADAU1701_SEROCTL_MSB_DEALY16 0x0010 | ||
63 | #define ADAU1701_SEROCTL_MSB_DEALY_MASK 0x001c | ||
64 | |||
65 | #define ADAU1701_SEROCTL_WORD_LEN_24 0x0000 | ||
66 | #define ADAU1701_SEROCTL_WORD_LEN_20 0x0001 | ||
67 | #define ADAU1701_SEROCTL_WORD_LEN_16 0x0010 | ||
68 | #define ADAU1701_SEROCTL_WORD_LEN_MASK 0x0003 | ||
69 | |||
70 | #define ADAU1701_AUXNPOW_VBPD 0x40 | ||
71 | #define ADAU1701_AUXNPOW_VRPD 0x20 | ||
72 | |||
73 | #define ADAU1701_SERICTL_I2S 0 | ||
74 | #define ADAU1701_SERICTL_LEFTJ 1 | ||
75 | #define ADAU1701_SERICTL_TDM 2 | ||
76 | #define ADAU1701_SERICTL_RIGHTJ_24 3 | ||
77 | #define ADAU1701_SERICTL_RIGHTJ_20 4 | ||
78 | #define ADAU1701_SERICTL_RIGHTJ_18 5 | ||
79 | #define ADAU1701_SERICTL_RIGHTJ_16 6 | ||
80 | #define ADAU1701_SERICTL_MODE_MASK 7 | ||
81 | #define ADAU1701_SERICTL_INV_BCLK BIT(3) | ||
82 | #define ADAU1701_SERICTL_INV_LRCLK BIT(4) | ||
83 | |||
84 | #define ADAU1701_OSCIPOW_OPD 0x04 | ||
85 | #define ADAU1701_DACSET_DACINIT 1 | ||
86 | |||
87 | #define ADAU1701_FIRMWARE "adau1701.bin" | ||
88 | |||
89 | struct adau1701 { | ||
90 | unsigned int dai_fmt; | ||
91 | }; | ||
92 | |||
93 | static const struct snd_kcontrol_new adau1701_controls[] = { | ||
94 | SOC_SINGLE("Master Capture Switch", ADAU1701_DSPCTRL, 4, 1, 0), | ||
95 | }; | ||
96 | |||
97 | static const struct snd_soc_dapm_widget adau1701_dapm_widgets[] = { | ||
98 | SND_SOC_DAPM_DAC("DAC0", "Playback", ADAU1701_AUXNPOW, 3, 1), | ||
99 | SND_SOC_DAPM_DAC("DAC1", "Playback", ADAU1701_AUXNPOW, 2, 1), | ||
100 | SND_SOC_DAPM_DAC("DAC2", "Playback", ADAU1701_AUXNPOW, 1, 1), | ||
101 | SND_SOC_DAPM_DAC("DAC3", "Playback", ADAU1701_AUXNPOW, 0, 1), | ||
102 | SND_SOC_DAPM_ADC("ADC", "Capture", ADAU1701_AUXNPOW, 7, 1), | ||
103 | |||
104 | SND_SOC_DAPM_OUTPUT("OUT0"), | ||
105 | SND_SOC_DAPM_OUTPUT("OUT1"), | ||
106 | SND_SOC_DAPM_OUTPUT("OUT2"), | ||
107 | SND_SOC_DAPM_OUTPUT("OUT3"), | ||
108 | SND_SOC_DAPM_INPUT("IN0"), | ||
109 | SND_SOC_DAPM_INPUT("IN1"), | ||
110 | }; | ||
111 | |||
112 | static const struct snd_soc_dapm_route adau1701_dapm_routes[] = { | ||
113 | { "OUT0", NULL, "DAC0" }, | ||
114 | { "OUT1", NULL, "DAC1" }, | ||
115 | { "OUT2", NULL, "DAC2" }, | ||
116 | { "OUT3", NULL, "DAC3" }, | ||
117 | |||
118 | { "ADC", NULL, "IN0" }, | ||
119 | { "ADC", NULL, "IN1" }, | ||
120 | }; | ||
121 | |||
122 | static unsigned int adau1701_register_size(struct snd_soc_codec *codec, | ||
123 | unsigned int reg) | ||
124 | { | ||
125 | switch (reg) { | ||
126 | case ADAU1701_DSPCTRL: | ||
127 | case ADAU1701_SEROCTL: | ||
128 | case ADAU1701_AUXNPOW: | ||
129 | case ADAU1701_OSCIPOW: | ||
130 | case ADAU1701_DACSET: | ||
131 | return 2; | ||
132 | case ADAU1701_SERICTL: | ||
133 | return 1; | ||
134 | } | ||
135 | |||
136 | dev_err(codec->dev, "Unsupported register address: %d\n", reg); | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | static int adau1701_write(struct snd_soc_codec *codec, unsigned int reg, | ||
141 | unsigned int value) | ||
142 | { | ||
143 | unsigned int i, ret; | ||
144 | unsigned int size; | ||
145 | uint8_t buf[4]; | ||
146 | |||
147 | size = adau1701_register_size(codec, reg); | ||
148 | if (size == 0) | ||
149 | return -EINVAL; | ||
150 | |||
151 | snd_soc_cache_write(codec, reg, value); | ||
152 | |||
153 | buf[0] = 0x08; | ||
154 | buf[1] = reg; | ||
155 | |||
156 | for (i = size + 1; i >= 2; --i) { | ||
157 | buf[i] = value; | ||
158 | value >>= 8; | ||
159 | } | ||
160 | |||
161 | ret = i2c_master_send(to_i2c_client(codec->dev), buf, size + 2); | ||
162 | if (ret == size + 2) | ||
163 | return 0; | ||
164 | else if (ret < 0) | ||
165 | return ret; | ||
166 | else | ||
167 | return -EIO; | ||
168 | } | ||
169 | |||
170 | static unsigned int adau1701_read(struct snd_soc_codec *codec, unsigned int reg) | ||
171 | { | ||
172 | unsigned int value; | ||
173 | unsigned int ret; | ||
174 | |||
175 | ret = snd_soc_cache_read(codec, reg, &value); | ||
176 | if (ret) | ||
177 | return ret; | ||
178 | |||
179 | return value; | ||
180 | } | ||
181 | |||
182 | static int adau1701_load_firmware(struct snd_soc_codec *codec) | ||
183 | { | ||
184 | return process_sigma_firmware(codec->control_data, ADAU1701_FIRMWARE); | ||
185 | } | ||
186 | |||
187 | static int adau1701_set_capture_pcm_format(struct snd_soc_codec *codec, | ||
188 | snd_pcm_format_t format) | ||
189 | { | ||
190 | struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec); | ||
191 | unsigned int mask = ADAU1701_SEROCTL_WORD_LEN_MASK; | ||
192 | unsigned int val; | ||
193 | |||
194 | switch (format) { | ||
195 | case SNDRV_PCM_FORMAT_S16_LE: | ||
196 | val = ADAU1701_SEROCTL_WORD_LEN_16; | ||
197 | break; | ||
198 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
199 | val = ADAU1701_SEROCTL_WORD_LEN_20; | ||
200 | break; | ||
201 | case SNDRV_PCM_FORMAT_S24_LE: | ||
202 | val = ADAU1701_SEROCTL_WORD_LEN_24; | ||
203 | break; | ||
204 | default: | ||
205 | return -EINVAL; | ||
206 | } | ||
207 | |||
208 | if (adau1701->dai_fmt == SND_SOC_DAIFMT_RIGHT_J) { | ||
209 | switch (format) { | ||
210 | case SNDRV_PCM_FORMAT_S16_LE: | ||
211 | val |= ADAU1701_SEROCTL_MSB_DEALY16; | ||
212 | break; | ||
213 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
214 | val |= ADAU1701_SEROCTL_MSB_DEALY12; | ||
215 | break; | ||
216 | case SNDRV_PCM_FORMAT_S24_LE: | ||
217 | val |= ADAU1701_SEROCTL_MSB_DEALY8; | ||
218 | break; | ||
219 | } | ||
220 | mask |= ADAU1701_SEROCTL_MSB_DEALY_MASK; | ||
221 | } | ||
222 | |||
223 | snd_soc_update_bits(codec, ADAU1701_SEROCTL, mask, val); | ||
224 | |||
225 | return 0; | ||
226 | } | ||
227 | |||
228 | static int adau1701_set_playback_pcm_format(struct snd_soc_codec *codec, | ||
229 | snd_pcm_format_t format) | ||
230 | { | ||
231 | struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec); | ||
232 | unsigned int val; | ||
233 | |||
234 | if (adau1701->dai_fmt != SND_SOC_DAIFMT_RIGHT_J) | ||
235 | return 0; | ||
236 | |||
237 | switch (format) { | ||
238 | case SNDRV_PCM_FORMAT_S16_LE: | ||
239 | val = ADAU1701_SERICTL_RIGHTJ_16; | ||
240 | break; | ||
241 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
242 | val = ADAU1701_SERICTL_RIGHTJ_20; | ||
243 | break; | ||
244 | case SNDRV_PCM_FORMAT_S24_LE: | ||
245 | val = ADAU1701_SERICTL_RIGHTJ_24; | ||
246 | break; | ||
247 | default: | ||
248 | return -EINVAL; | ||
249 | } | ||
250 | |||
251 | snd_soc_update_bits(codec, ADAU1701_SERICTL, | ||
252 | ADAU1701_SERICTL_MODE_MASK, val); | ||
253 | |||
254 | return 0; | ||
255 | } | ||
256 | |||
257 | static int adau1701_hw_params(struct snd_pcm_substream *substream, | ||
258 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) | ||
259 | { | ||
260 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
261 | struct snd_soc_codec *codec = rtd->codec; | ||
262 | snd_pcm_format_t format; | ||
263 | unsigned int val; | ||
264 | |||
265 | switch (params_rate(params)) { | ||
266 | case 192000: | ||
267 | val = ADAU1701_DSPCTRL_SR_192; | ||
268 | break; | ||
269 | case 96000: | ||
270 | val = ADAU1701_DSPCTRL_SR_96; | ||
271 | break; | ||
272 | case 48000: | ||
273 | val = ADAU1701_DSPCTRL_SR_48; | ||
274 | break; | ||
275 | default: | ||
276 | return -EINVAL; | ||
277 | } | ||
278 | |||
279 | snd_soc_update_bits(codec, ADAU1701_DSPCTRL, | ||
280 | ADAU1701_DSPCTRL_SR_MASK, val); | ||
281 | |||
282 | format = params_format(params); | ||
283 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
284 | return adau1701_set_playback_pcm_format(codec, format); | ||
285 | else | ||
286 | return adau1701_set_capture_pcm_format(codec, format); | ||
287 | } | ||
288 | |||
289 | static int adau1701_set_dai_fmt(struct snd_soc_dai *codec_dai, | ||
290 | unsigned int fmt) | ||
291 | { | ||
292 | struct snd_soc_codec *codec = codec_dai->codec; | ||
293 | struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec); | ||
294 | unsigned int serictl = 0x00, seroctl = 0x00; | ||
295 | bool invert_lrclk; | ||
296 | |||
297 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
298 | case SND_SOC_DAIFMT_CBM_CFM: | ||
299 | /* master, 64-bits per sample, 1 frame per sample */ | ||
300 | seroctl |= ADAU1701_SEROCTL_MASTER | ADAU1701_SEROCTL_OBF16 | ||
301 | | ADAU1701_SEROCTL_OLF1024; | ||
302 | break; | ||
303 | case SND_SOC_DAIFMT_CBS_CFS: | ||
304 | break; | ||
305 | default: | ||
306 | return -EINVAL; | ||
307 | } | ||
308 | |||
309 | /* clock inversion */ | ||
310 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
311 | case SND_SOC_DAIFMT_NB_NF: | ||
312 | invert_lrclk = false; | ||
313 | break; | ||
314 | case SND_SOC_DAIFMT_NB_IF: | ||
315 | invert_lrclk = true; | ||
316 | break; | ||
317 | case SND_SOC_DAIFMT_IB_NF: | ||
318 | invert_lrclk = false; | ||
319 | serictl |= ADAU1701_SERICTL_INV_BCLK; | ||
320 | seroctl |= ADAU1701_SEROCTL_INV_BCLK; | ||
321 | break; | ||
322 | case SND_SOC_DAIFMT_IB_IF: | ||
323 | invert_lrclk = true; | ||
324 | serictl |= ADAU1701_SERICTL_INV_BCLK; | ||
325 | seroctl |= ADAU1701_SEROCTL_INV_BCLK; | ||
326 | break; | ||
327 | default: | ||
328 | return -EINVAL; | ||
329 | } | ||
330 | |||
331 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
332 | case SND_SOC_DAIFMT_I2S: | ||
333 | break; | ||
334 | case SND_SOC_DAIFMT_LEFT_J: | ||
335 | serictl |= ADAU1701_SERICTL_LEFTJ; | ||
336 | seroctl |= ADAU1701_SEROCTL_MSB_DEALY0; | ||
337 | invert_lrclk = !invert_lrclk; | ||
338 | break; | ||
339 | case SND_SOC_DAIFMT_RIGHT_J: | ||
340 | serictl |= ADAU1701_SERICTL_RIGHTJ_24; | ||
341 | seroctl |= ADAU1701_SEROCTL_MSB_DEALY8; | ||
342 | invert_lrclk = !invert_lrclk; | ||
343 | break; | ||
344 | default: | ||
345 | return -EINVAL; | ||
346 | } | ||
347 | |||
348 | if (invert_lrclk) { | ||
349 | seroctl |= ADAU1701_SEROCTL_INV_LRCLK; | ||
350 | serictl |= ADAU1701_SERICTL_INV_LRCLK; | ||
351 | } | ||
352 | |||
353 | adau1701->dai_fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK; | ||
354 | |||
355 | snd_soc_write(codec, ADAU1701_SERICTL, serictl); | ||
356 | snd_soc_update_bits(codec, ADAU1701_SEROCTL, | ||
357 | ~ADAU1701_SEROCTL_WORD_LEN_MASK, seroctl); | ||
358 | |||
359 | return 0; | ||
360 | } | ||
361 | |||
362 | static int adau1701_set_bias_level(struct snd_soc_codec *codec, | ||
363 | enum snd_soc_bias_level level) | ||
364 | { | ||
365 | unsigned int mask = ADAU1701_AUXNPOW_VBPD | ADAU1701_AUXNPOW_VRPD; | ||
366 | |||
367 | switch (level) { | ||
368 | case SND_SOC_BIAS_ON: | ||
369 | break; | ||
370 | case SND_SOC_BIAS_PREPARE: | ||
371 | break; | ||
372 | case SND_SOC_BIAS_STANDBY: | ||
373 | /* Enable VREF and VREF buffer */ | ||
374 | snd_soc_update_bits(codec, ADAU1701_AUXNPOW, mask, 0x00); | ||
375 | break; | ||
376 | case SND_SOC_BIAS_OFF: | ||
377 | /* Disable VREF and VREF buffer */ | ||
378 | snd_soc_update_bits(codec, ADAU1701_AUXNPOW, mask, mask); | ||
379 | break; | ||
380 | } | ||
381 | |||
382 | codec->dapm.bias_level = level; | ||
383 | return 0; | ||
384 | } | ||
385 | |||
386 | static int adau1701_digital_mute(struct snd_soc_dai *dai, int mute) | ||
387 | { | ||
388 | struct snd_soc_codec *codec = dai->codec; | ||
389 | unsigned int mask = ADAU1701_DSPCTRL_DAM; | ||
390 | unsigned int val; | ||
391 | |||
392 | if (mute) | ||
393 | val = 0; | ||
394 | else | ||
395 | val = mask; | ||
396 | |||
397 | snd_soc_update_bits(codec, ADAU1701_DSPCTRL, mask, val); | ||
398 | |||
399 | return 0; | ||
400 | } | ||
401 | |||
402 | static int adau1701_set_sysclk(struct snd_soc_codec *codec, int clk_id, | ||
403 | unsigned int freq, int dir) | ||
404 | { | ||
405 | unsigned int val; | ||
406 | |||
407 | switch (clk_id) { | ||
408 | case ADAU1701_CLK_SRC_OSC: | ||
409 | val = 0x0; | ||
410 | break; | ||
411 | case ADAU1701_CLK_SRC_MCLK: | ||
412 | val = ADAU1701_OSCIPOW_OPD; | ||
413 | break; | ||
414 | default: | ||
415 | return -EINVAL; | ||
416 | } | ||
417 | |||
418 | snd_soc_update_bits(codec, ADAU1701_OSCIPOW, ADAU1701_OSCIPOW_OPD, val); | ||
419 | |||
420 | return 0; | ||
421 | } | ||
422 | |||
423 | #define ADAU1701_RATES (SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | \ | ||
424 | SNDRV_PCM_RATE_192000) | ||
425 | |||
426 | #define ADAU1701_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | ||
427 | SNDRV_PCM_FMTBIT_S24_LE) | ||
428 | |||
429 | static const struct snd_soc_dai_ops adau1701_dai_ops = { | ||
430 | .set_fmt = adau1701_set_dai_fmt, | ||
431 | .hw_params = adau1701_hw_params, | ||
432 | .digital_mute = adau1701_digital_mute, | ||
433 | }; | ||
434 | |||
435 | static struct snd_soc_dai_driver adau1701_dai = { | ||
436 | .name = "adau1701", | ||
437 | .playback = { | ||
438 | .stream_name = "Playback", | ||
439 | .channels_min = 2, | ||
440 | .channels_max = 8, | ||
441 | .rates = ADAU1701_RATES, | ||
442 | .formats = ADAU1701_FORMATS, | ||
443 | }, | ||
444 | .capture = { | ||
445 | .stream_name = "Capture", | ||
446 | .channels_min = 2, | ||
447 | .channels_max = 8, | ||
448 | .rates = ADAU1701_RATES, | ||
449 | .formats = ADAU1701_FORMATS, | ||
450 | }, | ||
451 | .ops = &adau1701_dai_ops, | ||
452 | .symmetric_rates = 1, | ||
453 | }; | ||
454 | |||
455 | static int adau1701_probe(struct snd_soc_codec *codec) | ||
456 | { | ||
457 | int ret; | ||
458 | |||
459 | codec->dapm.idle_bias_off = 1; | ||
460 | |||
461 | ret = adau1701_load_firmware(codec); | ||
462 | if (ret) | ||
463 | dev_warn(codec->dev, "Failed to load firmware\n"); | ||
464 | |||
465 | snd_soc_write(codec, ADAU1701_DACSET, ADAU1701_DACSET_DACINIT); | ||
466 | snd_soc_write(codec, ADAU1701_DSPCTRL, ADAU1701_DSPCTRL_CR); | ||
467 | |||
468 | return 0; | ||
469 | } | ||
470 | |||
471 | static struct snd_soc_codec_driver adau1701_codec_drv = { | ||
472 | .probe = adau1701_probe, | ||
473 | .set_bias_level = adau1701_set_bias_level, | ||
474 | |||
475 | .reg_cache_size = ADAU1701_NUM_REGS, | ||
476 | .reg_word_size = sizeof(u16), | ||
477 | |||
478 | .controls = adau1701_controls, | ||
479 | .num_controls = ARRAY_SIZE(adau1701_controls), | ||
480 | .dapm_widgets = adau1701_dapm_widgets, | ||
481 | .num_dapm_widgets = ARRAY_SIZE(adau1701_dapm_widgets), | ||
482 | .dapm_routes = adau1701_dapm_routes, | ||
483 | .num_dapm_routes = ARRAY_SIZE(adau1701_dapm_routes), | ||
484 | |||
485 | .write = adau1701_write, | ||
486 | .read = adau1701_read, | ||
487 | |||
488 | .set_sysclk = adau1701_set_sysclk, | ||
489 | }; | ||
490 | |||
491 | static __devinit int adau1701_i2c_probe(struct i2c_client *client, | ||
492 | const struct i2c_device_id *id) | ||
493 | { | ||
494 | struct adau1701 *adau1701; | ||
495 | int ret; | ||
496 | |||
497 | adau1701 = kzalloc(sizeof(*adau1701), GFP_KERNEL); | ||
498 | if (!adau1701) | ||
499 | return -ENOMEM; | ||
500 | |||
501 | i2c_set_clientdata(client, adau1701); | ||
502 | ret = snd_soc_register_codec(&client->dev, &adau1701_codec_drv, | ||
503 | &adau1701_dai, 1); | ||
504 | if (ret < 0) | ||
505 | kfree(adau1701); | ||
506 | |||
507 | return ret; | ||
508 | } | ||
509 | |||
510 | static __devexit int adau1701_i2c_remove(struct i2c_client *client) | ||
511 | { | ||
512 | snd_soc_unregister_codec(&client->dev); | ||
513 | kfree(i2c_get_clientdata(client)); | ||
514 | return 0; | ||
515 | } | ||
516 | |||
517 | static const struct i2c_device_id adau1701_i2c_id[] = { | ||
518 | { "adau1701", 0 }, | ||
519 | { } | ||
520 | }; | ||
521 | MODULE_DEVICE_TABLE(i2c, adau1701_i2c_id); | ||
522 | |||
523 | static struct i2c_driver adau1701_i2c_driver = { | ||
524 | .driver = { | ||
525 | .name = "adau1701", | ||
526 | .owner = THIS_MODULE, | ||
527 | }, | ||
528 | .probe = adau1701_i2c_probe, | ||
529 | .remove = __devexit_p(adau1701_i2c_remove), | ||
530 | .id_table = adau1701_i2c_id, | ||
531 | }; | ||
532 | |||
533 | static int __init adau1701_init(void) | ||
534 | { | ||
535 | return i2c_add_driver(&adau1701_i2c_driver); | ||
536 | } | ||
537 | module_init(adau1701_init); | ||
538 | |||
539 | static void __exit adau1701_exit(void) | ||
540 | { | ||
541 | i2c_del_driver(&adau1701_i2c_driver); | ||
542 | } | ||
543 | module_exit(adau1701_exit); | ||
544 | |||
545 | MODULE_DESCRIPTION("ASoC ADAU1701 SigmaDSP driver"); | ||
546 | MODULE_AUTHOR("Cliff Cai <cliff.cai@analog.com>"); | ||
547 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); | ||
548 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/adau1701.h b/sound/soc/codecs/adau1701.h new file mode 100644 index 000000000000..8d0949a2aec9 --- /dev/null +++ b/sound/soc/codecs/adau1701.h | |||
@@ -0,0 +1,17 @@ | |||
1 | /* | ||
2 | * header file for ADAU1701 SigmaDSP processor | ||
3 | * | ||
4 | * Copyright 2011 Analog Devices Inc. | ||
5 | * | ||
6 | * Licensed under the GPL-2 or later. | ||
7 | */ | ||
8 | |||
9 | #ifndef _ADAU1701_H | ||
10 | #define _ADAU1701_H | ||
11 | |||
12 | enum adau1701_clk_src { | ||
13 | ADAU1701_CLK_SRC_OSC, | ||
14 | ADAU1701_CLK_SRC_MCLK, | ||
15 | }; | ||
16 | |||
17 | #endif | ||