diff options
Diffstat (limited to 'sound/soc/codecs/ad1938.c')
-rw-r--r-- | sound/soc/codecs/ad1938.c | 522 |
1 files changed, 0 insertions, 522 deletions
diff --git a/sound/soc/codecs/ad1938.c b/sound/soc/codecs/ad1938.c deleted file mode 100644 index 240cd155b313..000000000000 --- a/sound/soc/codecs/ad1938.c +++ /dev/null | |||
@@ -1,522 +0,0 @@ | |||
1 | /* | ||
2 | * File: sound/soc/codecs/ad1938.c | ||
3 | * Author: Barry Song <Barry.Song@analog.com> | ||
4 | * | ||
5 | * Created: June 04 2009 | ||
6 | * Description: Driver for AD1938 sound chip | ||
7 | * | ||
8 | * Modified: | ||
9 | * Copyright 2009 Analog Devices Inc. | ||
10 | * | ||
11 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | * | ||
18 | * This program is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | * GNU General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU General Public License | ||
24 | * along with this program; if not, see the file COPYING, or write | ||
25 | * to the Free Software Foundation, Inc., | ||
26 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
27 | */ | ||
28 | |||
29 | #include <linux/init.h> | ||
30 | #include <linux/slab.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/kernel.h> | ||
33 | #include <linux/device.h> | ||
34 | #include <sound/core.h> | ||
35 | #include <sound/pcm.h> | ||
36 | #include <sound/pcm_params.h> | ||
37 | #include <sound/initval.h> | ||
38 | #include <sound/soc.h> | ||
39 | #include <sound/tlv.h> | ||
40 | #include <sound/soc-dapm.h> | ||
41 | #include <linux/spi/spi.h> | ||
42 | #include "ad1938.h" | ||
43 | |||
44 | /* codec private data */ | ||
45 | struct ad1938_priv { | ||
46 | struct snd_soc_codec codec; | ||
47 | u8 reg_cache[AD1938_NUM_REGS]; | ||
48 | }; | ||
49 | |||
50 | /* ad1938 register cache & default register settings */ | ||
51 | static const u8 ad1938_reg[AD1938_NUM_REGS] = { | ||
52 | 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, | ||
53 | }; | ||
54 | |||
55 | static struct snd_soc_codec *ad1938_codec; | ||
56 | struct snd_soc_codec_device soc_codec_dev_ad1938; | ||
57 | static int ad1938_register(struct ad1938_priv *ad1938); | ||
58 | static void ad1938_unregister(struct ad1938_priv *ad1938); | ||
59 | |||
60 | /* | ||
61 | * AD1938 volume/mute/de-emphasis etc. controls | ||
62 | */ | ||
63 | static const char *ad1938_deemp[] = {"None", "48kHz", "44.1kHz", "32kHz"}; | ||
64 | |||
65 | static const struct soc_enum ad1938_deemp_enum = | ||
66 | SOC_ENUM_SINGLE(AD1938_DAC_CTRL2, 1, 4, ad1938_deemp); | ||
67 | |||
68 | static const struct snd_kcontrol_new ad1938_snd_controls[] = { | ||
69 | /* DAC volume control */ | ||
70 | SOC_DOUBLE_R("DAC1 Volume", AD1938_DAC_L1_VOL, | ||
71 | AD1938_DAC_R1_VOL, 0, 0xFF, 1), | ||
72 | SOC_DOUBLE_R("DAC2 Volume", AD1938_DAC_L2_VOL, | ||
73 | AD1938_DAC_R2_VOL, 0, 0xFF, 1), | ||
74 | SOC_DOUBLE_R("DAC3 Volume", AD1938_DAC_L3_VOL, | ||
75 | AD1938_DAC_R3_VOL, 0, 0xFF, 1), | ||
76 | SOC_DOUBLE_R("DAC4 Volume", AD1938_DAC_L4_VOL, | ||
77 | AD1938_DAC_R4_VOL, 0, 0xFF, 1), | ||
78 | |||
79 | /* ADC switch control */ | ||
80 | SOC_DOUBLE("ADC1 Switch", AD1938_ADC_CTRL0, AD1938_ADCL1_MUTE, | ||
81 | AD1938_ADCR1_MUTE, 1, 1), | ||
82 | SOC_DOUBLE("ADC2 Switch", AD1938_ADC_CTRL0, AD1938_ADCL2_MUTE, | ||
83 | AD1938_ADCR2_MUTE, 1, 1), | ||
84 | |||
85 | /* DAC switch control */ | ||
86 | SOC_DOUBLE("DAC1 Switch", AD1938_DAC_CHNL_MUTE, AD1938_DACL1_MUTE, | ||
87 | AD1938_DACR1_MUTE, 1, 1), | ||
88 | SOC_DOUBLE("DAC2 Switch", AD1938_DAC_CHNL_MUTE, AD1938_DACL2_MUTE, | ||
89 | AD1938_DACR2_MUTE, 1, 1), | ||
90 | SOC_DOUBLE("DAC3 Switch", AD1938_DAC_CHNL_MUTE, AD1938_DACL3_MUTE, | ||
91 | AD1938_DACR3_MUTE, 1, 1), | ||
92 | SOC_DOUBLE("DAC4 Switch", AD1938_DAC_CHNL_MUTE, AD1938_DACL4_MUTE, | ||
93 | AD1938_DACR4_MUTE, 1, 1), | ||
94 | |||
95 | /* ADC high-pass filter */ | ||
96 | SOC_SINGLE("ADC High Pass Filter Switch", AD1938_ADC_CTRL0, | ||
97 | AD1938_ADC_HIGHPASS_FILTER, 1, 0), | ||
98 | |||
99 | /* DAC de-emphasis */ | ||
100 | SOC_ENUM("Playback Deemphasis", ad1938_deemp_enum), | ||
101 | }; | ||
102 | |||
103 | static const struct snd_soc_dapm_widget ad1938_dapm_widgets[] = { | ||
104 | SND_SOC_DAPM_DAC("DAC", "Playback", AD1938_DAC_CTRL0, 0, 1), | ||
105 | SND_SOC_DAPM_ADC("ADC", "Capture", SND_SOC_NOPM, 0, 0), | ||
106 | SND_SOC_DAPM_SUPPLY("PLL_PWR", AD1938_PLL_CLK_CTRL0, 0, 1, NULL, 0), | ||
107 | SND_SOC_DAPM_SUPPLY("ADC_PWR", AD1938_ADC_CTRL0, 0, 1, NULL, 0), | ||
108 | SND_SOC_DAPM_OUTPUT("DAC1OUT"), | ||
109 | SND_SOC_DAPM_OUTPUT("DAC2OUT"), | ||
110 | SND_SOC_DAPM_OUTPUT("DAC3OUT"), | ||
111 | SND_SOC_DAPM_OUTPUT("DAC4OUT"), | ||
112 | SND_SOC_DAPM_INPUT("ADC1IN"), | ||
113 | SND_SOC_DAPM_INPUT("ADC2IN"), | ||
114 | }; | ||
115 | |||
116 | static const struct snd_soc_dapm_route audio_paths[] = { | ||
117 | { "DAC", NULL, "PLL_PWR" }, | ||
118 | { "ADC", NULL, "PLL_PWR" }, | ||
119 | { "DAC", NULL, "ADC_PWR" }, | ||
120 | { "ADC", NULL, "ADC_PWR" }, | ||
121 | { "DAC1OUT", "DAC1 Switch", "DAC" }, | ||
122 | { "DAC2OUT", "DAC2 Switch", "DAC" }, | ||
123 | { "DAC3OUT", "DAC3 Switch", "DAC" }, | ||
124 | { "DAC4OUT", "DAC4 Switch", "DAC" }, | ||
125 | { "ADC", "ADC1 Switch", "ADC1IN" }, | ||
126 | { "ADC", "ADC2 Switch", "ADC2IN" }, | ||
127 | }; | ||
128 | |||
129 | /* | ||
130 | * DAI ops entries | ||
131 | */ | ||
132 | |||
133 | static int ad1938_mute(struct snd_soc_dai *dai, int mute) | ||
134 | { | ||
135 | struct snd_soc_codec *codec = dai->codec; | ||
136 | int reg; | ||
137 | |||
138 | reg = snd_soc_read(codec, AD1938_DAC_CTRL2); | ||
139 | reg = (mute > 0) ? reg | AD1938_DAC_MASTER_MUTE : reg & | ||
140 | (~AD1938_DAC_MASTER_MUTE); | ||
141 | snd_soc_write(codec, AD1938_DAC_CTRL2, reg); | ||
142 | |||
143 | return 0; | ||
144 | } | ||
145 | |||
146 | static int ad1938_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, | ||
147 | unsigned int rx_mask, int slots, int width) | ||
148 | { | ||
149 | struct snd_soc_codec *codec = dai->codec; | ||
150 | int dac_reg = snd_soc_read(codec, AD1938_DAC_CTRL1); | ||
151 | int adc_reg = snd_soc_read(codec, AD1938_ADC_CTRL2); | ||
152 | |||
153 | dac_reg &= ~AD1938_DAC_CHAN_MASK; | ||
154 | adc_reg &= ~AD1938_ADC_CHAN_MASK; | ||
155 | |||
156 | switch (slots) { | ||
157 | case 2: | ||
158 | dac_reg |= AD1938_DAC_2_CHANNELS << AD1938_DAC_CHAN_SHFT; | ||
159 | adc_reg |= AD1938_ADC_2_CHANNELS << AD1938_ADC_CHAN_SHFT; | ||
160 | break; | ||
161 | case 4: | ||
162 | dac_reg |= AD1938_DAC_4_CHANNELS << AD1938_DAC_CHAN_SHFT; | ||
163 | adc_reg |= AD1938_ADC_4_CHANNELS << AD1938_ADC_CHAN_SHFT; | ||
164 | break; | ||
165 | case 8: | ||
166 | dac_reg |= AD1938_DAC_8_CHANNELS << AD1938_DAC_CHAN_SHFT; | ||
167 | adc_reg |= AD1938_ADC_8_CHANNELS << AD1938_ADC_CHAN_SHFT; | ||
168 | break; | ||
169 | case 16: | ||
170 | dac_reg |= AD1938_DAC_16_CHANNELS << AD1938_DAC_CHAN_SHFT; | ||
171 | adc_reg |= AD1938_ADC_16_CHANNELS << AD1938_ADC_CHAN_SHFT; | ||
172 | break; | ||
173 | default: | ||
174 | return -EINVAL; | ||
175 | } | ||
176 | |||
177 | snd_soc_write(codec, AD1938_DAC_CTRL1, dac_reg); | ||
178 | snd_soc_write(codec, AD1938_ADC_CTRL2, adc_reg); | ||
179 | |||
180 | return 0; | ||
181 | } | ||
182 | |||
183 | static int ad1938_set_dai_fmt(struct snd_soc_dai *codec_dai, | ||
184 | unsigned int fmt) | ||
185 | { | ||
186 | struct snd_soc_codec *codec = codec_dai->codec; | ||
187 | int adc_reg, dac_reg; | ||
188 | |||
189 | adc_reg = snd_soc_read(codec, AD1938_ADC_CTRL2); | ||
190 | dac_reg = snd_soc_read(codec, AD1938_DAC_CTRL1); | ||
191 | |||
192 | /* At present, the driver only support AUX ADC mode(SND_SOC_DAIFMT_I2S | ||
193 | * with TDM) and ADC&DAC TDM mode(SND_SOC_DAIFMT_DSP_A) | ||
194 | */ | ||
195 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
196 | case SND_SOC_DAIFMT_I2S: | ||
197 | adc_reg &= ~AD1938_ADC_SERFMT_MASK; | ||
198 | adc_reg |= AD1938_ADC_SERFMT_TDM; | ||
199 | break; | ||
200 | case SND_SOC_DAIFMT_DSP_A: | ||
201 | adc_reg &= ~AD1938_ADC_SERFMT_MASK; | ||
202 | adc_reg |= AD1938_ADC_SERFMT_AUX; | ||
203 | break; | ||
204 | default: | ||
205 | return -EINVAL; | ||
206 | } | ||
207 | |||
208 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
209 | case SND_SOC_DAIFMT_NB_NF: /* normal bit clock + frame */ | ||
210 | adc_reg &= ~AD1938_ADC_LEFT_HIGH; | ||
211 | adc_reg &= ~AD1938_ADC_BCLK_INV; | ||
212 | dac_reg &= ~AD1938_DAC_LEFT_HIGH; | ||
213 | dac_reg &= ~AD1938_DAC_BCLK_INV; | ||
214 | break; | ||
215 | case SND_SOC_DAIFMT_NB_IF: /* normal bclk + invert frm */ | ||
216 | adc_reg |= AD1938_ADC_LEFT_HIGH; | ||
217 | adc_reg &= ~AD1938_ADC_BCLK_INV; | ||
218 | dac_reg |= AD1938_DAC_LEFT_HIGH; | ||
219 | dac_reg &= ~AD1938_DAC_BCLK_INV; | ||
220 | break; | ||
221 | case SND_SOC_DAIFMT_IB_NF: /* invert bclk + normal frm */ | ||
222 | adc_reg &= ~AD1938_ADC_LEFT_HIGH; | ||
223 | adc_reg |= AD1938_ADC_BCLK_INV; | ||
224 | dac_reg &= ~AD1938_DAC_LEFT_HIGH; | ||
225 | dac_reg |= AD1938_DAC_BCLK_INV; | ||
226 | break; | ||
227 | |||
228 | case SND_SOC_DAIFMT_IB_IF: /* invert bclk + frm */ | ||
229 | adc_reg |= AD1938_ADC_LEFT_HIGH; | ||
230 | adc_reg |= AD1938_ADC_BCLK_INV; | ||
231 | dac_reg |= AD1938_DAC_LEFT_HIGH; | ||
232 | dac_reg |= AD1938_DAC_BCLK_INV; | ||
233 | break; | ||
234 | default: | ||
235 | return -EINVAL; | ||
236 | } | ||
237 | |||
238 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
239 | case SND_SOC_DAIFMT_CBM_CFM: /* codec clk & frm master */ | ||
240 | adc_reg |= AD1938_ADC_LCR_MASTER; | ||
241 | adc_reg |= AD1938_ADC_BCLK_MASTER; | ||
242 | dac_reg |= AD1938_DAC_LCR_MASTER; | ||
243 | dac_reg |= AD1938_DAC_BCLK_MASTER; | ||
244 | break; | ||
245 | case SND_SOC_DAIFMT_CBS_CFM: /* codec clk slave & frm master */ | ||
246 | adc_reg |= AD1938_ADC_LCR_MASTER; | ||
247 | adc_reg &= ~AD1938_ADC_BCLK_MASTER; | ||
248 | dac_reg |= AD1938_DAC_LCR_MASTER; | ||
249 | dac_reg &= ~AD1938_DAC_BCLK_MASTER; | ||
250 | break; | ||
251 | case SND_SOC_DAIFMT_CBM_CFS: /* codec clk master & frame slave */ | ||
252 | adc_reg &= ~AD1938_ADC_LCR_MASTER; | ||
253 | adc_reg |= AD1938_ADC_BCLK_MASTER; | ||
254 | dac_reg &= ~AD1938_DAC_LCR_MASTER; | ||
255 | dac_reg |= AD1938_DAC_BCLK_MASTER; | ||
256 | break; | ||
257 | case SND_SOC_DAIFMT_CBS_CFS: /* codec clk & frm slave */ | ||
258 | adc_reg &= ~AD1938_ADC_LCR_MASTER; | ||
259 | adc_reg &= ~AD1938_ADC_BCLK_MASTER; | ||
260 | dac_reg &= ~AD1938_DAC_LCR_MASTER; | ||
261 | dac_reg &= ~AD1938_DAC_BCLK_MASTER; | ||
262 | break; | ||
263 | default: | ||
264 | return -EINVAL; | ||
265 | } | ||
266 | |||
267 | snd_soc_write(codec, AD1938_ADC_CTRL2, adc_reg); | ||
268 | snd_soc_write(codec, AD1938_DAC_CTRL1, dac_reg); | ||
269 | |||
270 | return 0; | ||
271 | } | ||
272 | |||
273 | static int ad1938_hw_params(struct snd_pcm_substream *substream, | ||
274 | struct snd_pcm_hw_params *params, | ||
275 | struct snd_soc_dai *dai) | ||
276 | { | ||
277 | int word_len = 0, reg = 0; | ||
278 | |||
279 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
280 | struct snd_soc_device *socdev = rtd->socdev; | ||
281 | struct snd_soc_codec *codec = socdev->card->codec; | ||
282 | |||
283 | /* bit size */ | ||
284 | switch (params_format(params)) { | ||
285 | case SNDRV_PCM_FORMAT_S16_LE: | ||
286 | word_len = 3; | ||
287 | break; | ||
288 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
289 | word_len = 1; | ||
290 | break; | ||
291 | case SNDRV_PCM_FORMAT_S24_LE: | ||
292 | case SNDRV_PCM_FORMAT_S32_LE: | ||
293 | word_len = 0; | ||
294 | break; | ||
295 | } | ||
296 | |||
297 | reg = snd_soc_read(codec, AD1938_DAC_CTRL2); | ||
298 | reg = (reg & (~AD1938_DAC_WORD_LEN_MASK)) | word_len; | ||
299 | snd_soc_write(codec, AD1938_DAC_CTRL2, reg); | ||
300 | |||
301 | reg = snd_soc_read(codec, AD1938_ADC_CTRL1); | ||
302 | reg = (reg & (~AD1938_ADC_WORD_LEN_MASK)) | word_len; | ||
303 | snd_soc_write(codec, AD1938_ADC_CTRL1, reg); | ||
304 | |||
305 | return 0; | ||
306 | } | ||
307 | |||
308 | static int __devinit ad1938_spi_probe(struct spi_device *spi) | ||
309 | { | ||
310 | struct snd_soc_codec *codec; | ||
311 | struct ad1938_priv *ad1938; | ||
312 | |||
313 | ad1938 = kzalloc(sizeof(struct ad1938_priv), GFP_KERNEL); | ||
314 | if (ad1938 == NULL) | ||
315 | return -ENOMEM; | ||
316 | |||
317 | codec = &ad1938->codec; | ||
318 | codec->control_data = spi; | ||
319 | codec->dev = &spi->dev; | ||
320 | |||
321 | dev_set_drvdata(&spi->dev, ad1938); | ||
322 | |||
323 | return ad1938_register(ad1938); | ||
324 | } | ||
325 | |||
326 | static int __devexit ad1938_spi_remove(struct spi_device *spi) | ||
327 | { | ||
328 | struct ad1938_priv *ad1938 = dev_get_drvdata(&spi->dev); | ||
329 | |||
330 | ad1938_unregister(ad1938); | ||
331 | return 0; | ||
332 | } | ||
333 | |||
334 | static struct spi_driver ad1938_spi_driver = { | ||
335 | .driver = { | ||
336 | .name = "ad1938", | ||
337 | .owner = THIS_MODULE, | ||
338 | }, | ||
339 | .probe = ad1938_spi_probe, | ||
340 | .remove = __devexit_p(ad1938_spi_remove), | ||
341 | }; | ||
342 | |||
343 | static struct snd_soc_dai_ops ad1938_dai_ops = { | ||
344 | .hw_params = ad1938_hw_params, | ||
345 | .digital_mute = ad1938_mute, | ||
346 | .set_tdm_slot = ad1938_set_tdm_slot, | ||
347 | .set_fmt = ad1938_set_dai_fmt, | ||
348 | }; | ||
349 | |||
350 | /* codec DAI instance */ | ||
351 | struct snd_soc_dai ad1938_dai = { | ||
352 | .name = "AD1938", | ||
353 | .playback = { | ||
354 | .stream_name = "Playback", | ||
355 | .channels_min = 2, | ||
356 | .channels_max = 8, | ||
357 | .rates = SNDRV_PCM_RATE_48000, | ||
358 | .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE | | ||
359 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE, | ||
360 | }, | ||
361 | .capture = { | ||
362 | .stream_name = "Capture", | ||
363 | .channels_min = 2, | ||
364 | .channels_max = 4, | ||
365 | .rates = SNDRV_PCM_RATE_48000, | ||
366 | .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE | | ||
367 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE, | ||
368 | }, | ||
369 | .ops = &ad1938_dai_ops, | ||
370 | }; | ||
371 | EXPORT_SYMBOL_GPL(ad1938_dai); | ||
372 | |||
373 | static int ad1938_register(struct ad1938_priv *ad1938) | ||
374 | { | ||
375 | int ret; | ||
376 | struct snd_soc_codec *codec = &ad1938->codec; | ||
377 | |||
378 | if (ad1938_codec) { | ||
379 | dev_err(codec->dev, "Another ad1938 is registered\n"); | ||
380 | return -EINVAL; | ||
381 | } | ||
382 | |||
383 | mutex_init(&codec->mutex); | ||
384 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
385 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
386 | codec->private_data = ad1938; | ||
387 | codec->reg_cache = ad1938->reg_cache; | ||
388 | codec->reg_cache_size = AD1938_NUM_REGS; | ||
389 | codec->name = "AD1938"; | ||
390 | codec->owner = THIS_MODULE; | ||
391 | codec->dai = &ad1938_dai; | ||
392 | codec->num_dai = 1; | ||
393 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
394 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
395 | |||
396 | ad1938_dai.dev = codec->dev; | ||
397 | ad1938_codec = codec; | ||
398 | |||
399 | memcpy(codec->reg_cache, ad1938_reg, AD1938_NUM_REGS); | ||
400 | |||
401 | ret = snd_soc_codec_set_cache_io(codec, 16, 8, SND_SOC_SPI); | ||
402 | if (ret < 0) { | ||
403 | dev_err(codec->dev, "failed to set cache I/O: %d\n", | ||
404 | ret); | ||
405 | kfree(ad1938); | ||
406 | return ret; | ||
407 | } | ||
408 | |||
409 | /* default setting for ad1938 */ | ||
410 | |||
411 | /* unmute dac channels */ | ||
412 | snd_soc_write(codec, AD1938_DAC_CHNL_MUTE, 0x0); | ||
413 | /* de-emphasis: 48kHz, powedown dac */ | ||
414 | snd_soc_write(codec, AD1938_DAC_CTRL2, 0x1A); | ||
415 | /* powerdown dac, dac in tdm mode */ | ||
416 | snd_soc_write(codec, AD1938_DAC_CTRL0, 0x41); | ||
417 | /* high-pass filter enable */ | ||
418 | snd_soc_write(codec, AD1938_ADC_CTRL0, 0x3); | ||
419 | /* sata delay=1, adc aux mode */ | ||
420 | snd_soc_write(codec, AD1938_ADC_CTRL1, 0x43); | ||
421 | /* pll input: mclki/xi */ | ||
422 | snd_soc_write(codec, AD1938_PLL_CLK_CTRL0, 0x9D); | ||
423 | snd_soc_write(codec, AD1938_PLL_CLK_CTRL1, 0x04); | ||
424 | |||
425 | ret = snd_soc_register_codec(codec); | ||
426 | if (ret != 0) { | ||
427 | dev_err(codec->dev, "Failed to register codec: %d\n", ret); | ||
428 | kfree(ad1938); | ||
429 | return ret; | ||
430 | } | ||
431 | |||
432 | ret = snd_soc_register_dai(&ad1938_dai); | ||
433 | if (ret != 0) { | ||
434 | dev_err(codec->dev, "Failed to register DAI: %d\n", ret); | ||
435 | snd_soc_unregister_codec(codec); | ||
436 | kfree(ad1938); | ||
437 | return ret; | ||
438 | } | ||
439 | |||
440 | return 0; | ||
441 | } | ||
442 | |||
443 | static void ad1938_unregister(struct ad1938_priv *ad1938) | ||
444 | { | ||
445 | snd_soc_unregister_dai(&ad1938_dai); | ||
446 | snd_soc_unregister_codec(&ad1938->codec); | ||
447 | kfree(ad1938); | ||
448 | ad1938_codec = NULL; | ||
449 | } | ||
450 | |||
451 | static int ad1938_probe(struct platform_device *pdev) | ||
452 | { | ||
453 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
454 | struct snd_soc_codec *codec; | ||
455 | int ret = 0; | ||
456 | |||
457 | if (ad1938_codec == NULL) { | ||
458 | dev_err(&pdev->dev, "Codec device not registered\n"); | ||
459 | return -ENODEV; | ||
460 | } | ||
461 | |||
462 | socdev->card->codec = ad1938_codec; | ||
463 | codec = ad1938_codec; | ||
464 | |||
465 | /* register pcms */ | ||
466 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
467 | if (ret < 0) { | ||
468 | dev_err(codec->dev, "failed to create pcms: %d\n", ret); | ||
469 | goto pcm_err; | ||
470 | } | ||
471 | |||
472 | snd_soc_add_controls(codec, ad1938_snd_controls, | ||
473 | ARRAY_SIZE(ad1938_snd_controls)); | ||
474 | snd_soc_dapm_new_controls(codec, ad1938_dapm_widgets, | ||
475 | ARRAY_SIZE(ad1938_dapm_widgets)); | ||
476 | snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths)); | ||
477 | |||
478 | |||
479 | pcm_err: | ||
480 | return ret; | ||
481 | } | ||
482 | |||
483 | /* power down chip */ | ||
484 | static int ad1938_remove(struct platform_device *pdev) | ||
485 | { | ||
486 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
487 | |||
488 | snd_soc_free_pcms(socdev); | ||
489 | snd_soc_dapm_free(socdev); | ||
490 | |||
491 | return 0; | ||
492 | } | ||
493 | |||
494 | struct snd_soc_codec_device soc_codec_dev_ad1938 = { | ||
495 | .probe = ad1938_probe, | ||
496 | .remove = ad1938_remove, | ||
497 | }; | ||
498 | EXPORT_SYMBOL_GPL(soc_codec_dev_ad1938); | ||
499 | |||
500 | static int __init ad1938_init(void) | ||
501 | { | ||
502 | int ret; | ||
503 | |||
504 | ret = spi_register_driver(&ad1938_spi_driver); | ||
505 | if (ret != 0) { | ||
506 | printk(KERN_ERR "Failed to register ad1938 SPI driver: %d\n", | ||
507 | ret); | ||
508 | } | ||
509 | |||
510 | return ret; | ||
511 | } | ||
512 | module_init(ad1938_init); | ||
513 | |||
514 | static void __exit ad1938_exit(void) | ||
515 | { | ||
516 | spi_unregister_driver(&ad1938_spi_driver); | ||
517 | } | ||
518 | module_exit(ad1938_exit); | ||
519 | |||
520 | MODULE_DESCRIPTION("ASoC ad1938 driver"); | ||
521 | MODULE_AUTHOR("Barry Song "); | ||
522 | MODULE_LICENSE("GPL"); | ||