diff options
Diffstat (limited to 'sound/soc/codecs/ad193x.c')
-rw-r--r-- | sound/soc/codecs/ad193x.c | 547 |
1 files changed, 547 insertions, 0 deletions
diff --git a/sound/soc/codecs/ad193x.c b/sound/soc/codecs/ad193x.c new file mode 100644 index 000000000000..c8ca1142b2f4 --- /dev/null +++ b/sound/soc/codecs/ad193x.c | |||
@@ -0,0 +1,547 @@ | |||
1 | /* | ||
2 | * AD193X Audio Codec driver supporting AD1936/7/8/9 | ||
3 | * | ||
4 | * Copyright 2010 Analog Devices Inc. | ||
5 | * | ||
6 | * Licensed under the GPL-2 or later. | ||
7 | */ | ||
8 | |||
9 | #include <linux/init.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/device.h> | ||
13 | #include <linux/i2c.h> | ||
14 | #include <linux/spi/spi.h> | ||
15 | #include <linux/slab.h> | ||
16 | #include <sound/core.h> | ||
17 | #include <sound/pcm.h> | ||
18 | #include <sound/pcm_params.h> | ||
19 | #include <sound/initval.h> | ||
20 | #include <sound/soc.h> | ||
21 | #include <sound/tlv.h> | ||
22 | #include <sound/soc-dapm.h> | ||
23 | #include "ad193x.h" | ||
24 | |||
25 | /* codec private data */ | ||
26 | struct ad193x_priv { | ||
27 | struct snd_soc_codec codec; | ||
28 | u8 reg_cache[AD193X_NUM_REGS]; | ||
29 | }; | ||
30 | |||
31 | /* ad193x register cache & default register settings */ | ||
32 | static const u8 ad193x_reg[AD193X_NUM_REGS] = { | ||
33 | 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, | ||
34 | }; | ||
35 | |||
36 | static struct snd_soc_codec *ad193x_codec; | ||
37 | struct snd_soc_codec_device soc_codec_dev_ad193x; | ||
38 | |||
39 | /* | ||
40 | * AD193X volume/mute/de-emphasis etc. controls | ||
41 | */ | ||
42 | static const char *ad193x_deemp[] = {"None", "48kHz", "44.1kHz", "32kHz"}; | ||
43 | |||
44 | static const struct soc_enum ad193x_deemp_enum = | ||
45 | SOC_ENUM_SINGLE(AD193X_DAC_CTRL2, 1, 4, ad193x_deemp); | ||
46 | |||
47 | static const struct snd_kcontrol_new ad193x_snd_controls[] = { | ||
48 | /* DAC volume control */ | ||
49 | SOC_DOUBLE_R("DAC1 Volume", AD193X_DAC_L1_VOL, | ||
50 | AD193X_DAC_R1_VOL, 0, 0xFF, 1), | ||
51 | SOC_DOUBLE_R("DAC2 Volume", AD193X_DAC_L2_VOL, | ||
52 | AD193X_DAC_R2_VOL, 0, 0xFF, 1), | ||
53 | SOC_DOUBLE_R("DAC3 Volume", AD193X_DAC_L3_VOL, | ||
54 | AD193X_DAC_R3_VOL, 0, 0xFF, 1), | ||
55 | SOC_DOUBLE_R("DAC4 Volume", AD193X_DAC_L4_VOL, | ||
56 | AD193X_DAC_R4_VOL, 0, 0xFF, 1), | ||
57 | |||
58 | /* ADC switch control */ | ||
59 | SOC_DOUBLE("ADC1 Switch", AD193X_ADC_CTRL0, AD193X_ADCL1_MUTE, | ||
60 | AD193X_ADCR1_MUTE, 1, 1), | ||
61 | SOC_DOUBLE("ADC2 Switch", AD193X_ADC_CTRL0, AD193X_ADCL2_MUTE, | ||
62 | AD193X_ADCR2_MUTE, 1, 1), | ||
63 | |||
64 | /* DAC switch control */ | ||
65 | SOC_DOUBLE("DAC1 Switch", AD193X_DAC_CHNL_MUTE, AD193X_DACL1_MUTE, | ||
66 | AD193X_DACR1_MUTE, 1, 1), | ||
67 | SOC_DOUBLE("DAC2 Switch", AD193X_DAC_CHNL_MUTE, AD193X_DACL2_MUTE, | ||
68 | AD193X_DACR2_MUTE, 1, 1), | ||
69 | SOC_DOUBLE("DAC3 Switch", AD193X_DAC_CHNL_MUTE, AD193X_DACL3_MUTE, | ||
70 | AD193X_DACR3_MUTE, 1, 1), | ||
71 | SOC_DOUBLE("DAC4 Switch", AD193X_DAC_CHNL_MUTE, AD193X_DACL4_MUTE, | ||
72 | AD193X_DACR4_MUTE, 1, 1), | ||
73 | |||
74 | /* ADC high-pass filter */ | ||
75 | SOC_SINGLE("ADC High Pass Filter Switch", AD193X_ADC_CTRL0, | ||
76 | AD193X_ADC_HIGHPASS_FILTER, 1, 0), | ||
77 | |||
78 | /* DAC de-emphasis */ | ||
79 | SOC_ENUM("Playback Deemphasis", ad193x_deemp_enum), | ||
80 | }; | ||
81 | |||
82 | static const struct snd_soc_dapm_widget ad193x_dapm_widgets[] = { | ||
83 | SND_SOC_DAPM_DAC("DAC", "Playback", AD193X_DAC_CTRL0, 0, 1), | ||
84 | SND_SOC_DAPM_ADC("ADC", "Capture", SND_SOC_NOPM, 0, 0), | ||
85 | SND_SOC_DAPM_SUPPLY("PLL_PWR", AD193X_PLL_CLK_CTRL0, 0, 1, NULL, 0), | ||
86 | SND_SOC_DAPM_SUPPLY("ADC_PWR", AD193X_ADC_CTRL0, 0, 1, NULL, 0), | ||
87 | SND_SOC_DAPM_OUTPUT("DAC1OUT"), | ||
88 | SND_SOC_DAPM_OUTPUT("DAC2OUT"), | ||
89 | SND_SOC_DAPM_OUTPUT("DAC3OUT"), | ||
90 | SND_SOC_DAPM_OUTPUT("DAC4OUT"), | ||
91 | SND_SOC_DAPM_INPUT("ADC1IN"), | ||
92 | SND_SOC_DAPM_INPUT("ADC2IN"), | ||
93 | }; | ||
94 | |||
95 | static const struct snd_soc_dapm_route audio_paths[] = { | ||
96 | { "DAC", NULL, "PLL_PWR" }, | ||
97 | { "ADC", NULL, "PLL_PWR" }, | ||
98 | { "DAC", NULL, "ADC_PWR" }, | ||
99 | { "ADC", NULL, "ADC_PWR" }, | ||
100 | { "DAC1OUT", "DAC1 Switch", "DAC" }, | ||
101 | { "DAC2OUT", "DAC2 Switch", "DAC" }, | ||
102 | { "DAC3OUT", "DAC3 Switch", "DAC" }, | ||
103 | { "DAC4OUT", "DAC4 Switch", "DAC" }, | ||
104 | { "ADC", "ADC1 Switch", "ADC1IN" }, | ||
105 | { "ADC", "ADC2 Switch", "ADC2IN" }, | ||
106 | }; | ||
107 | |||
108 | /* | ||
109 | * DAI ops entries | ||
110 | */ | ||
111 | |||
112 | static int ad193x_mute(struct snd_soc_dai *dai, int mute) | ||
113 | { | ||
114 | struct snd_soc_codec *codec = dai->codec; | ||
115 | int reg; | ||
116 | |||
117 | reg = snd_soc_read(codec, AD193X_DAC_CTRL2); | ||
118 | reg = (mute > 0) ? reg | AD193X_DAC_MASTER_MUTE : reg & | ||
119 | (~AD193X_DAC_MASTER_MUTE); | ||
120 | snd_soc_write(codec, AD193X_DAC_CTRL2, reg); | ||
121 | |||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | static int ad193x_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, | ||
126 | unsigned int rx_mask, int slots, int width) | ||
127 | { | ||
128 | struct snd_soc_codec *codec = dai->codec; | ||
129 | int dac_reg = snd_soc_read(codec, AD193X_DAC_CTRL1); | ||
130 | int adc_reg = snd_soc_read(codec, AD193X_ADC_CTRL2); | ||
131 | |||
132 | dac_reg &= ~AD193X_DAC_CHAN_MASK; | ||
133 | adc_reg &= ~AD193X_ADC_CHAN_MASK; | ||
134 | |||
135 | switch (slots) { | ||
136 | case 2: | ||
137 | dac_reg |= AD193X_DAC_2_CHANNELS << AD193X_DAC_CHAN_SHFT; | ||
138 | adc_reg |= AD193X_ADC_2_CHANNELS << AD193X_ADC_CHAN_SHFT; | ||
139 | break; | ||
140 | case 4: | ||
141 | dac_reg |= AD193X_DAC_4_CHANNELS << AD193X_DAC_CHAN_SHFT; | ||
142 | adc_reg |= AD193X_ADC_4_CHANNELS << AD193X_ADC_CHAN_SHFT; | ||
143 | break; | ||
144 | case 8: | ||
145 | dac_reg |= AD193X_DAC_8_CHANNELS << AD193X_DAC_CHAN_SHFT; | ||
146 | adc_reg |= AD193X_ADC_8_CHANNELS << AD193X_ADC_CHAN_SHFT; | ||
147 | break; | ||
148 | case 16: | ||
149 | dac_reg |= AD193X_DAC_16_CHANNELS << AD193X_DAC_CHAN_SHFT; | ||
150 | adc_reg |= AD193X_ADC_16_CHANNELS << AD193X_ADC_CHAN_SHFT; | ||
151 | break; | ||
152 | default: | ||
153 | return -EINVAL; | ||
154 | } | ||
155 | |||
156 | snd_soc_write(codec, AD193X_DAC_CTRL1, dac_reg); | ||
157 | snd_soc_write(codec, AD193X_ADC_CTRL2, adc_reg); | ||
158 | |||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | static int ad193x_set_dai_fmt(struct snd_soc_dai *codec_dai, | ||
163 | unsigned int fmt) | ||
164 | { | ||
165 | struct snd_soc_codec *codec = codec_dai->codec; | ||
166 | int adc_reg1, adc_reg2, dac_reg; | ||
167 | |||
168 | adc_reg1 = snd_soc_read(codec, AD193X_ADC_CTRL1); | ||
169 | adc_reg2 = snd_soc_read(codec, AD193X_ADC_CTRL2); | ||
170 | dac_reg = snd_soc_read(codec, AD193X_DAC_CTRL1); | ||
171 | |||
172 | /* At present, the driver only support AUX ADC mode(SND_SOC_DAIFMT_I2S | ||
173 | * with TDM) and ADC&DAC TDM mode(SND_SOC_DAIFMT_DSP_A) | ||
174 | */ | ||
175 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
176 | case SND_SOC_DAIFMT_I2S: | ||
177 | adc_reg1 &= ~AD193X_ADC_SERFMT_MASK; | ||
178 | adc_reg1 |= AD193X_ADC_SERFMT_TDM; | ||
179 | break; | ||
180 | case SND_SOC_DAIFMT_DSP_A: | ||
181 | adc_reg1 &= ~AD193X_ADC_SERFMT_MASK; | ||
182 | adc_reg1 |= AD193X_ADC_SERFMT_AUX; | ||
183 | break; | ||
184 | default: | ||
185 | return -EINVAL; | ||
186 | } | ||
187 | |||
188 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
189 | case SND_SOC_DAIFMT_NB_NF: /* normal bit clock + frame */ | ||
190 | adc_reg2 &= ~AD193X_ADC_LEFT_HIGH; | ||
191 | adc_reg2 &= ~AD193X_ADC_BCLK_INV; | ||
192 | dac_reg &= ~AD193X_DAC_LEFT_HIGH; | ||
193 | dac_reg &= ~AD193X_DAC_BCLK_INV; | ||
194 | break; | ||
195 | case SND_SOC_DAIFMT_NB_IF: /* normal bclk + invert frm */ | ||
196 | adc_reg2 |= AD193X_ADC_LEFT_HIGH; | ||
197 | adc_reg2 &= ~AD193X_ADC_BCLK_INV; | ||
198 | dac_reg |= AD193X_DAC_LEFT_HIGH; | ||
199 | dac_reg &= ~AD193X_DAC_BCLK_INV; | ||
200 | break; | ||
201 | case SND_SOC_DAIFMT_IB_NF: /* invert bclk + normal frm */ | ||
202 | adc_reg2 &= ~AD193X_ADC_LEFT_HIGH; | ||
203 | adc_reg2 |= AD193X_ADC_BCLK_INV; | ||
204 | dac_reg &= ~AD193X_DAC_LEFT_HIGH; | ||
205 | dac_reg |= AD193X_DAC_BCLK_INV; | ||
206 | break; | ||
207 | |||
208 | case SND_SOC_DAIFMT_IB_IF: /* invert bclk + frm */ | ||
209 | adc_reg2 |= AD193X_ADC_LEFT_HIGH; | ||
210 | adc_reg2 |= AD193X_ADC_BCLK_INV; | ||
211 | dac_reg |= AD193X_DAC_LEFT_HIGH; | ||
212 | dac_reg |= AD193X_DAC_BCLK_INV; | ||
213 | break; | ||
214 | default: | ||
215 | return -EINVAL; | ||
216 | } | ||
217 | |||
218 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
219 | case SND_SOC_DAIFMT_CBM_CFM: /* codec clk & frm master */ | ||
220 | adc_reg2 |= AD193X_ADC_LCR_MASTER; | ||
221 | adc_reg2 |= AD193X_ADC_BCLK_MASTER; | ||
222 | dac_reg |= AD193X_DAC_LCR_MASTER; | ||
223 | dac_reg |= AD193X_DAC_BCLK_MASTER; | ||
224 | break; | ||
225 | case SND_SOC_DAIFMT_CBS_CFM: /* codec clk slave & frm master */ | ||
226 | adc_reg2 |= AD193X_ADC_LCR_MASTER; | ||
227 | adc_reg2 &= ~AD193X_ADC_BCLK_MASTER; | ||
228 | dac_reg |= AD193X_DAC_LCR_MASTER; | ||
229 | dac_reg &= ~AD193X_DAC_BCLK_MASTER; | ||
230 | break; | ||
231 | case SND_SOC_DAIFMT_CBM_CFS: /* codec clk master & frame slave */ | ||
232 | adc_reg2 &= ~AD193X_ADC_LCR_MASTER; | ||
233 | adc_reg2 |= AD193X_ADC_BCLK_MASTER; | ||
234 | dac_reg &= ~AD193X_DAC_LCR_MASTER; | ||
235 | dac_reg |= AD193X_DAC_BCLK_MASTER; | ||
236 | break; | ||
237 | case SND_SOC_DAIFMT_CBS_CFS: /* codec clk & frm slave */ | ||
238 | adc_reg2 &= ~AD193X_ADC_LCR_MASTER; | ||
239 | adc_reg2 &= ~AD193X_ADC_BCLK_MASTER; | ||
240 | dac_reg &= ~AD193X_DAC_LCR_MASTER; | ||
241 | dac_reg &= ~AD193X_DAC_BCLK_MASTER; | ||
242 | break; | ||
243 | default: | ||
244 | return -EINVAL; | ||
245 | } | ||
246 | |||
247 | snd_soc_write(codec, AD193X_ADC_CTRL1, adc_reg1); | ||
248 | snd_soc_write(codec, AD193X_ADC_CTRL2, adc_reg2); | ||
249 | snd_soc_write(codec, AD193X_DAC_CTRL1, dac_reg); | ||
250 | |||
251 | return 0; | ||
252 | } | ||
253 | |||
254 | static int ad193x_hw_params(struct snd_pcm_substream *substream, | ||
255 | struct snd_pcm_hw_params *params, | ||
256 | struct snd_soc_dai *dai) | ||
257 | { | ||
258 | int word_len = 0, reg = 0; | ||
259 | |||
260 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
261 | struct snd_soc_device *socdev = rtd->socdev; | ||
262 | struct snd_soc_codec *codec = socdev->card->codec; | ||
263 | |||
264 | /* bit size */ | ||
265 | switch (params_format(params)) { | ||
266 | case SNDRV_PCM_FORMAT_S16_LE: | ||
267 | word_len = 3; | ||
268 | break; | ||
269 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
270 | word_len = 1; | ||
271 | break; | ||
272 | case SNDRV_PCM_FORMAT_S24_LE: | ||
273 | case SNDRV_PCM_FORMAT_S32_LE: | ||
274 | word_len = 0; | ||
275 | break; | ||
276 | } | ||
277 | |||
278 | reg = snd_soc_read(codec, AD193X_DAC_CTRL2); | ||
279 | reg = (reg & (~AD193X_DAC_WORD_LEN_MASK)) | word_len; | ||
280 | snd_soc_write(codec, AD193X_DAC_CTRL2, reg); | ||
281 | |||
282 | reg = snd_soc_read(codec, AD193X_ADC_CTRL1); | ||
283 | reg = (reg & (~AD193X_ADC_WORD_LEN_MASK)) | word_len; | ||
284 | snd_soc_write(codec, AD193X_ADC_CTRL1, reg); | ||
285 | |||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | static int ad193x_bus_probe(struct device *dev, void *ctrl_data, int bus_type) | ||
290 | { | ||
291 | struct snd_soc_codec *codec; | ||
292 | struct ad193x_priv *ad193x; | ||
293 | int ret; | ||
294 | |||
295 | if (ad193x_codec) { | ||
296 | dev_err(dev, "Another ad193x is registered\n"); | ||
297 | return -EINVAL; | ||
298 | } | ||
299 | |||
300 | ad193x = kzalloc(sizeof(struct ad193x_priv), GFP_KERNEL); | ||
301 | if (ad193x == NULL) | ||
302 | return -ENOMEM; | ||
303 | |||
304 | dev_set_drvdata(dev, ad193x); | ||
305 | |||
306 | codec = &ad193x->codec; | ||
307 | mutex_init(&codec->mutex); | ||
308 | codec->control_data = ctrl_data; | ||
309 | codec->dev = dev; | ||
310 | snd_soc_codec_set_drvdata(codec, ad193x); | ||
311 | codec->reg_cache = ad193x->reg_cache; | ||
312 | codec->reg_cache_size = AD193X_NUM_REGS; | ||
313 | codec->name = "AD193X"; | ||
314 | codec->owner = THIS_MODULE; | ||
315 | codec->dai = &ad193x_dai; | ||
316 | codec->num_dai = 1; | ||
317 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
318 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
319 | |||
320 | ad193x_dai.dev = codec->dev; | ||
321 | ad193x_codec = codec; | ||
322 | |||
323 | memcpy(codec->reg_cache, ad193x_reg, AD193X_NUM_REGS); | ||
324 | |||
325 | if (bus_type == SND_SOC_I2C) | ||
326 | ret = snd_soc_codec_set_cache_io(codec, 8, 8, bus_type); | ||
327 | else | ||
328 | ret = snd_soc_codec_set_cache_io(codec, 16, 8, bus_type); | ||
329 | if (ret < 0) { | ||
330 | dev_err(codec->dev, "failed to set cache I/O: %d\n", | ||
331 | ret); | ||
332 | kfree(ad193x); | ||
333 | return ret; | ||
334 | } | ||
335 | |||
336 | /* default setting for ad193x */ | ||
337 | |||
338 | /* unmute dac channels */ | ||
339 | snd_soc_write(codec, AD193X_DAC_CHNL_MUTE, 0x0); | ||
340 | /* de-emphasis: 48kHz, powedown dac */ | ||
341 | snd_soc_write(codec, AD193X_DAC_CTRL2, 0x1A); | ||
342 | /* powerdown dac, dac in tdm mode */ | ||
343 | snd_soc_write(codec, AD193X_DAC_CTRL0, 0x41); | ||
344 | /* high-pass filter enable */ | ||
345 | snd_soc_write(codec, AD193X_ADC_CTRL0, 0x3); | ||
346 | /* sata delay=1, adc aux mode */ | ||
347 | snd_soc_write(codec, AD193X_ADC_CTRL1, 0x43); | ||
348 | /* pll input: mclki/xi */ | ||
349 | snd_soc_write(codec, AD193X_PLL_CLK_CTRL0, 0x99); /* mclk=24.576Mhz: 0x9D; mclk=12.288Mhz: 0x99 */ | ||
350 | snd_soc_write(codec, AD193X_PLL_CLK_CTRL1, 0x04); | ||
351 | |||
352 | ret = snd_soc_register_codec(codec); | ||
353 | if (ret != 0) { | ||
354 | dev_err(codec->dev, "Failed to register codec: %d\n", ret); | ||
355 | kfree(ad193x); | ||
356 | return ret; | ||
357 | } | ||
358 | |||
359 | ret = snd_soc_register_dai(&ad193x_dai); | ||
360 | if (ret != 0) { | ||
361 | dev_err(codec->dev, "Failed to register DAI: %d\n", ret); | ||
362 | snd_soc_unregister_codec(codec); | ||
363 | kfree(ad193x); | ||
364 | return ret; | ||
365 | } | ||
366 | |||
367 | return 0; | ||
368 | } | ||
369 | |||
370 | static int ad193x_bus_remove(struct device *dev) | ||
371 | { | ||
372 | struct ad193x_priv *ad193x = dev_get_drvdata(dev); | ||
373 | |||
374 | snd_soc_unregister_dai(&ad193x_dai); | ||
375 | snd_soc_unregister_codec(&ad193x->codec); | ||
376 | kfree(ad193x); | ||
377 | ad193x_codec = NULL; | ||
378 | |||
379 | return 0; | ||
380 | } | ||
381 | |||
382 | static struct snd_soc_dai_ops ad193x_dai_ops = { | ||
383 | .hw_params = ad193x_hw_params, | ||
384 | .digital_mute = ad193x_mute, | ||
385 | .set_tdm_slot = ad193x_set_tdm_slot, | ||
386 | .set_fmt = ad193x_set_dai_fmt, | ||
387 | }; | ||
388 | |||
389 | /* codec DAI instance */ | ||
390 | struct snd_soc_dai ad193x_dai = { | ||
391 | .name = "AD193X", | ||
392 | .playback = { | ||
393 | .stream_name = "Playback", | ||
394 | .channels_min = 2, | ||
395 | .channels_max = 8, | ||
396 | .rates = SNDRV_PCM_RATE_48000, | ||
397 | .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE | | ||
398 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE, | ||
399 | }, | ||
400 | .capture = { | ||
401 | .stream_name = "Capture", | ||
402 | .channels_min = 2, | ||
403 | .channels_max = 4, | ||
404 | .rates = SNDRV_PCM_RATE_48000, | ||
405 | .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE | | ||
406 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE, | ||
407 | }, | ||
408 | .ops = &ad193x_dai_ops, | ||
409 | }; | ||
410 | EXPORT_SYMBOL_GPL(ad193x_dai); | ||
411 | |||
412 | static int ad193x_probe(struct platform_device *pdev) | ||
413 | { | ||
414 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
415 | struct snd_soc_codec *codec; | ||
416 | int ret = 0; | ||
417 | |||
418 | if (ad193x_codec == NULL) { | ||
419 | dev_err(&pdev->dev, "Codec device not registered\n"); | ||
420 | return -ENODEV; | ||
421 | } | ||
422 | |||
423 | socdev->card->codec = ad193x_codec; | ||
424 | codec = ad193x_codec; | ||
425 | |||
426 | /* register pcms */ | ||
427 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
428 | if (ret < 0) { | ||
429 | dev_err(codec->dev, "failed to create pcms: %d\n", ret); | ||
430 | goto pcm_err; | ||
431 | } | ||
432 | |||
433 | snd_soc_add_controls(codec, ad193x_snd_controls, | ||
434 | ARRAY_SIZE(ad193x_snd_controls)); | ||
435 | snd_soc_dapm_new_controls(codec, ad193x_dapm_widgets, | ||
436 | ARRAY_SIZE(ad193x_dapm_widgets)); | ||
437 | snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths)); | ||
438 | |||
439 | pcm_err: | ||
440 | return ret; | ||
441 | } | ||
442 | |||
443 | /* power down chip */ | ||
444 | static int ad193x_remove(struct platform_device *pdev) | ||
445 | { | ||
446 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
447 | |||
448 | snd_soc_free_pcms(socdev); | ||
449 | snd_soc_dapm_free(socdev); | ||
450 | |||
451 | return 0; | ||
452 | } | ||
453 | |||
454 | struct snd_soc_codec_device soc_codec_dev_ad193x = { | ||
455 | .probe = ad193x_probe, | ||
456 | .remove = ad193x_remove, | ||
457 | }; | ||
458 | EXPORT_SYMBOL_GPL(soc_codec_dev_ad193x); | ||
459 | |||
460 | #if defined(CONFIG_SPI_MASTER) | ||
461 | static int __devinit ad193x_spi_probe(struct spi_device *spi) | ||
462 | { | ||
463 | return ad193x_bus_probe(&spi->dev, spi, SND_SOC_SPI); | ||
464 | } | ||
465 | |||
466 | static int __devexit ad193x_spi_remove(struct spi_device *spi) | ||
467 | { | ||
468 | return ad193x_bus_remove(&spi->dev); | ||
469 | } | ||
470 | |||
471 | static struct spi_driver ad193x_spi_driver = { | ||
472 | .driver = { | ||
473 | .name = "ad193x", | ||
474 | .owner = THIS_MODULE, | ||
475 | }, | ||
476 | .probe = ad193x_spi_probe, | ||
477 | .remove = __devexit_p(ad193x_spi_remove), | ||
478 | }; | ||
479 | #endif | ||
480 | |||
481 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
482 | static const struct i2c_device_id ad193x_id[] = { | ||
483 | { "ad1936", 0 }, | ||
484 | { "ad1937", 0 }, | ||
485 | { } | ||
486 | }; | ||
487 | MODULE_DEVICE_TABLE(i2c, ad193x_id); | ||
488 | |||
489 | static int __devinit ad193x_i2c_probe(struct i2c_client *client, | ||
490 | const struct i2c_device_id *id) | ||
491 | { | ||
492 | return ad193x_bus_probe(&client->dev, client, SND_SOC_I2C); | ||
493 | } | ||
494 | |||
495 | static int __devexit ad193x_i2c_remove(struct i2c_client *client) | ||
496 | { | ||
497 | return ad193x_bus_remove(&client->dev); | ||
498 | } | ||
499 | |||
500 | static struct i2c_driver ad193x_i2c_driver = { | ||
501 | .driver = { | ||
502 | .name = "ad193x", | ||
503 | }, | ||
504 | .probe = ad193x_i2c_probe, | ||
505 | .remove = __devexit_p(ad193x_i2c_remove), | ||
506 | .id_table = ad193x_id, | ||
507 | }; | ||
508 | #endif | ||
509 | |||
510 | static int __init ad193x_modinit(void) | ||
511 | { | ||
512 | int ret; | ||
513 | |||
514 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
515 | ret = i2c_add_driver(&ad193x_i2c_driver); | ||
516 | if (ret != 0) { | ||
517 | printk(KERN_ERR "Failed to register AD193X I2C driver: %d\n", | ||
518 | ret); | ||
519 | } | ||
520 | #endif | ||
521 | |||
522 | #if defined(CONFIG_SPI_MASTER) | ||
523 | ret = spi_register_driver(&ad193x_spi_driver); | ||
524 | if (ret != 0) { | ||
525 | printk(KERN_ERR "Failed to register AD193X SPI driver: %d\n", | ||
526 | ret); | ||
527 | } | ||
528 | #endif | ||
529 | return ret; | ||
530 | } | ||
531 | module_init(ad193x_modinit); | ||
532 | |||
533 | static void __exit ad193x_modexit(void) | ||
534 | { | ||
535 | #if defined(CONFIG_SPI_MASTER) | ||
536 | spi_unregister_driver(&ad193x_spi_driver); | ||
537 | #endif | ||
538 | |||
539 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
540 | i2c_del_driver(&ad193x_i2c_driver); | ||
541 | #endif | ||
542 | } | ||
543 | module_exit(ad193x_modexit); | ||
544 | |||
545 | MODULE_DESCRIPTION("ASoC ad193x driver"); | ||
546 | MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); | ||
547 | MODULE_LICENSE("GPL"); | ||