2 * wm8510.c -- WM8510 ALSA Soc Audio driver
4 * Copyright 2006 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/module.h>
14 #include <linux/moduleparam.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/delay.h>
19 #include <linux/i2c.h>
20 #include <linux/platform_device.h>
21 #include <linux/spi/spi.h>
22 #include <linux/slab.h>
23 #include <linux/of_device.h>
24 #include <sound/core.h>
25 #include <sound/pcm.h>
26 #include <sound/pcm_params.h>
27 #include <sound/soc.h>
28 #include <sound/initval.h>
33 * wm8510 register cache
34 * We can't read the WM8510 register space when we are
35 * using 2 wire for device control, so we cache them instead.
37 static const u16 wm8510_reg
[WM8510_CACHEREGNUM
] = {
38 0x0000, 0x0000, 0x0000, 0x0000,
39 0x0050, 0x0000, 0x0140, 0x0000,
40 0x0000, 0x0000, 0x0000, 0x00ff,
41 0x0000, 0x0000, 0x0100, 0x00ff,
42 0x0000, 0x0000, 0x012c, 0x002c,
43 0x002c, 0x002c, 0x002c, 0x0000,
44 0x0032, 0x0000, 0x0000, 0x0000,
45 0x0000, 0x0000, 0x0000, 0x0000,
46 0x0038, 0x000b, 0x0032, 0x0000,
47 0x0008, 0x000c, 0x0093, 0x00e9,
48 0x0000, 0x0000, 0x0000, 0x0000,
49 0x0003, 0x0010, 0x0000, 0x0000,
50 0x0000, 0x0002, 0x0001, 0x0000,
51 0x0000, 0x0000, 0x0039, 0x0000,
55 #define WM8510_POWER1_BIASEN 0x08
56 #define WM8510_POWER1_BUFIOEN 0x10
58 #define wm8510_reset(c) snd_soc_write(c, WM8510_RESET, 0)
60 /* codec private data */
62 enum snd_soc_control_type control_type
;
65 static const char *wm8510_companding
[] = { "Off", "NC", "u-law", "A-law" };
66 static const char *wm8510_deemp
[] = { "None", "32kHz", "44.1kHz", "48kHz" };
67 static const char *wm8510_alc
[] = { "ALC", "Limiter" };
69 static const struct soc_enum wm8510_enum
[] = {
70 SOC_ENUM_SINGLE(WM8510_COMP
, 1, 4, wm8510_companding
), /* adc */
71 SOC_ENUM_SINGLE(WM8510_COMP
, 3, 4, wm8510_companding
), /* dac */
72 SOC_ENUM_SINGLE(WM8510_DAC
, 4, 4, wm8510_deemp
),
73 SOC_ENUM_SINGLE(WM8510_ALC3
, 8, 2, wm8510_alc
),
76 static const struct snd_kcontrol_new wm8510_snd_controls
[] = {
78 SOC_SINGLE("Digital Loopback Switch", WM8510_COMP
, 0, 1, 0),
80 SOC_ENUM("DAC Companding", wm8510_enum
[1]),
81 SOC_ENUM("ADC Companding", wm8510_enum
[0]),
83 SOC_ENUM("Playback De-emphasis", wm8510_enum
[2]),
84 SOC_SINGLE("DAC Inversion Switch", WM8510_DAC
, 0, 1, 0),
86 SOC_SINGLE("Master Playback Volume", WM8510_DACVOL
, 0, 127, 0),
88 SOC_SINGLE("High Pass Filter Switch", WM8510_ADC
, 8, 1, 0),
89 SOC_SINGLE("High Pass Cut Off", WM8510_ADC
, 4, 7, 0),
90 SOC_SINGLE("ADC Inversion Switch", WM8510_COMP
, 0, 1, 0),
92 SOC_SINGLE("Capture Volume", WM8510_ADCVOL
, 0, 127, 0),
94 SOC_SINGLE("DAC Playback Limiter Switch", WM8510_DACLIM1
, 8, 1, 0),
95 SOC_SINGLE("DAC Playback Limiter Decay", WM8510_DACLIM1
, 4, 15, 0),
96 SOC_SINGLE("DAC Playback Limiter Attack", WM8510_DACLIM1
, 0, 15, 0),
98 SOC_SINGLE("DAC Playback Limiter Threshold", WM8510_DACLIM2
, 4, 7, 0),
99 SOC_SINGLE("DAC Playback Limiter Boost", WM8510_DACLIM2
, 0, 15, 0),
101 SOC_SINGLE("ALC Enable Switch", WM8510_ALC1
, 8, 1, 0),
102 SOC_SINGLE("ALC Capture Max Gain", WM8510_ALC1
, 3, 7, 0),
103 SOC_SINGLE("ALC Capture Min Gain", WM8510_ALC1
, 0, 7, 0),
105 SOC_SINGLE("ALC Capture ZC Switch", WM8510_ALC2
, 8, 1, 0),
106 SOC_SINGLE("ALC Capture Hold", WM8510_ALC2
, 4, 7, 0),
107 SOC_SINGLE("ALC Capture Target", WM8510_ALC2
, 0, 15, 0),
109 SOC_ENUM("ALC Capture Mode", wm8510_enum
[3]),
110 SOC_SINGLE("ALC Capture Decay", WM8510_ALC3
, 4, 15, 0),
111 SOC_SINGLE("ALC Capture Attack", WM8510_ALC3
, 0, 15, 0),
113 SOC_SINGLE("ALC Capture Noise Gate Switch", WM8510_NGATE
, 3, 1, 0),
114 SOC_SINGLE("ALC Capture Noise Gate Threshold", WM8510_NGATE
, 0, 7, 0),
116 SOC_SINGLE("Capture PGA ZC Switch", WM8510_INPPGA
, 7, 1, 0),
117 SOC_SINGLE("Capture PGA Volume", WM8510_INPPGA
, 0, 63, 0),
119 SOC_SINGLE("Speaker Playback ZC Switch", WM8510_SPKVOL
, 7, 1, 0),
120 SOC_SINGLE("Speaker Playback Switch", WM8510_SPKVOL
, 6, 1, 1),
121 SOC_SINGLE("Speaker Playback Volume", WM8510_SPKVOL
, 0, 63, 0),
122 SOC_SINGLE("Speaker Boost", WM8510_OUTPUT
, 2, 1, 0),
124 SOC_SINGLE("Capture Boost(+20dB)", WM8510_ADCBOOST
, 8, 1, 0),
125 SOC_SINGLE("Mono Playback Switch", WM8510_MONOMIX
, 6, 1, 1),
128 /* Speaker Output Mixer */
129 static const struct snd_kcontrol_new wm8510_speaker_mixer_controls
[] = {
130 SOC_DAPM_SINGLE("Line Bypass Switch", WM8510_SPKMIX
, 1, 1, 0),
131 SOC_DAPM_SINGLE("Aux Playback Switch", WM8510_SPKMIX
, 5, 1, 0),
132 SOC_DAPM_SINGLE("PCM Playback Switch", WM8510_SPKMIX
, 0, 1, 0),
135 /* Mono Output Mixer */
136 static const struct snd_kcontrol_new wm8510_mono_mixer_controls
[] = {
137 SOC_DAPM_SINGLE("Line Bypass Switch", WM8510_MONOMIX
, 1, 1, 0),
138 SOC_DAPM_SINGLE("Aux Playback Switch", WM8510_MONOMIX
, 2, 1, 0),
139 SOC_DAPM_SINGLE("PCM Playback Switch", WM8510_MONOMIX
, 0, 1, 0),
142 static const struct snd_kcontrol_new wm8510_boost_controls
[] = {
143 SOC_DAPM_SINGLE("Mic PGA Switch", WM8510_INPPGA
, 6, 1, 1),
144 SOC_DAPM_SINGLE("Aux Volume", WM8510_ADCBOOST
, 0, 7, 0),
145 SOC_DAPM_SINGLE("Mic Volume", WM8510_ADCBOOST
, 4, 7, 0),
148 static const struct snd_kcontrol_new wm8510_micpga_controls
[] = {
149 SOC_DAPM_SINGLE("MICP Switch", WM8510_INPUT
, 0, 1, 0),
150 SOC_DAPM_SINGLE("MICN Switch", WM8510_INPUT
, 1, 1, 0),
151 SOC_DAPM_SINGLE("AUX Switch", WM8510_INPUT
, 2, 1, 0),
154 static const struct snd_soc_dapm_widget wm8510_dapm_widgets
[] = {
155 SND_SOC_DAPM_MIXER("Speaker Mixer", WM8510_POWER3
, 2, 0,
156 &wm8510_speaker_mixer_controls
[0],
157 ARRAY_SIZE(wm8510_speaker_mixer_controls
)),
158 SND_SOC_DAPM_MIXER("Mono Mixer", WM8510_POWER3
, 3, 0,
159 &wm8510_mono_mixer_controls
[0],
160 ARRAY_SIZE(wm8510_mono_mixer_controls
)),
161 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8510_POWER3
, 0, 0),
162 SND_SOC_DAPM_ADC("ADC", "HiFi Capture", WM8510_POWER2
, 0, 0),
163 SND_SOC_DAPM_PGA("Aux Input", WM8510_POWER1
, 6, 0, NULL
, 0),
164 SND_SOC_DAPM_PGA("SpkN Out", WM8510_POWER3
, 5, 0, NULL
, 0),
165 SND_SOC_DAPM_PGA("SpkP Out", WM8510_POWER3
, 6, 0, NULL
, 0),
166 SND_SOC_DAPM_PGA("Mono Out", WM8510_POWER3
, 7, 0, NULL
, 0),
168 SND_SOC_DAPM_MIXER("Mic PGA", WM8510_POWER2
, 2, 0,
169 &wm8510_micpga_controls
[0],
170 ARRAY_SIZE(wm8510_micpga_controls
)),
171 SND_SOC_DAPM_MIXER("Boost Mixer", WM8510_POWER2
, 4, 0,
172 &wm8510_boost_controls
[0],
173 ARRAY_SIZE(wm8510_boost_controls
)),
175 SND_SOC_DAPM_MICBIAS("Mic Bias", WM8510_POWER1
, 4, 0),
177 SND_SOC_DAPM_INPUT("MICN"),
178 SND_SOC_DAPM_INPUT("MICP"),
179 SND_SOC_DAPM_INPUT("AUX"),
180 SND_SOC_DAPM_OUTPUT("MONOOUT"),
181 SND_SOC_DAPM_OUTPUT("SPKOUTP"),
182 SND_SOC_DAPM_OUTPUT("SPKOUTN"),
185 static const struct snd_soc_dapm_route audio_map
[] = {
186 /* Mono output mixer */
187 {"Mono Mixer", "PCM Playback Switch", "DAC"},
188 {"Mono Mixer", "Aux Playback Switch", "Aux Input"},
189 {"Mono Mixer", "Line Bypass Switch", "Boost Mixer"},
191 /* Speaker output mixer */
192 {"Speaker Mixer", "PCM Playback Switch", "DAC"},
193 {"Speaker Mixer", "Aux Playback Switch", "Aux Input"},
194 {"Speaker Mixer", "Line Bypass Switch", "Boost Mixer"},
197 {"Mono Out", NULL
, "Mono Mixer"},
198 {"MONOOUT", NULL
, "Mono Out"},
199 {"SpkN Out", NULL
, "Speaker Mixer"},
200 {"SpkP Out", NULL
, "Speaker Mixer"},
201 {"SPKOUTN", NULL
, "SpkN Out"},
202 {"SPKOUTP", NULL
, "SpkP Out"},
205 {"Mic PGA", "MICN Switch", "MICN"},
206 {"Mic PGA", "MICP Switch", "MICP"},
207 { "Mic PGA", "AUX Switch", "Aux Input" },
210 {"Boost Mixer", "Mic PGA Switch", "Mic PGA"},
211 {"Boost Mixer", "Mic Volume", "MICP"},
212 {"Boost Mixer", "Aux Volume", "Aux Input"},
214 {"ADC", NULL
, "Boost Mixer"},
217 static int wm8510_add_widgets(struct snd_soc_codec
*codec
)
219 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
221 snd_soc_dapm_new_controls(dapm
, wm8510_dapm_widgets
,
222 ARRAY_SIZE(wm8510_dapm_widgets
));
223 snd_soc_dapm_add_routes(dapm
, audio_map
, ARRAY_SIZE(audio_map
));
229 unsigned int pre_div
:4; /* prescale - 1 */
234 static struct pll_ pll_div
;
236 /* The size in bits of the pll divide multiplied by 10
237 * to allow rounding later */
238 #define FIXED_PLL_SIZE ((1 << 24) * 10)
240 static void pll_factors(unsigned int target
, unsigned int source
)
242 unsigned long long Kpart
;
243 unsigned int K
, Ndiv
, Nmod
;
245 Ndiv
= target
/ source
;
249 Ndiv
= target
/ source
;
253 if ((Ndiv
< 6) || (Ndiv
> 12))
255 "WM8510 N value %u outwith recommended range!d\n",
259 Nmod
= target
% source
;
260 Kpart
= FIXED_PLL_SIZE
* (long long)Nmod
;
262 do_div(Kpart
, source
);
264 K
= Kpart
& 0xFFFFFFFF;
266 /* Check if we need to round */
270 /* Move down to proper range now rounding is done */
276 static int wm8510_set_dai_pll(struct snd_soc_dai
*codec_dai
, int pll_id
,
277 int source
, unsigned int freq_in
, unsigned int freq_out
)
279 struct snd_soc_codec
*codec
= codec_dai
->codec
;
282 if (freq_in
== 0 || freq_out
== 0) {
283 /* Clock CODEC directly from MCLK */
284 reg
= snd_soc_read(codec
, WM8510_CLOCK
);
285 snd_soc_write(codec
, WM8510_CLOCK
, reg
& 0x0ff);
288 reg
= snd_soc_read(codec
, WM8510_POWER1
);
289 snd_soc_write(codec
, WM8510_POWER1
, reg
& 0x1df);
293 pll_factors(freq_out
*4, freq_in
);
295 snd_soc_write(codec
, WM8510_PLLN
, (pll_div
.pre_div
<< 4) | pll_div
.n
);
296 snd_soc_write(codec
, WM8510_PLLK1
, pll_div
.k
>> 18);
297 snd_soc_write(codec
, WM8510_PLLK2
, (pll_div
.k
>> 9) & 0x1ff);
298 snd_soc_write(codec
, WM8510_PLLK3
, pll_div
.k
& 0x1ff);
299 reg
= snd_soc_read(codec
, WM8510_POWER1
);
300 snd_soc_write(codec
, WM8510_POWER1
, reg
| 0x020);
302 /* Run CODEC from PLL instead of MCLK */
303 reg
= snd_soc_read(codec
, WM8510_CLOCK
);
304 snd_soc_write(codec
, WM8510_CLOCK
, reg
| 0x100);
310 * Configure WM8510 clock dividers.
312 static int wm8510_set_dai_clkdiv(struct snd_soc_dai
*codec_dai
,
315 struct snd_soc_codec
*codec
= codec_dai
->codec
;
319 case WM8510_OPCLKDIV
:
320 reg
= snd_soc_read(codec
, WM8510_GPIO
) & 0x1cf;
321 snd_soc_write(codec
, WM8510_GPIO
, reg
| div
);
324 reg
= snd_soc_read(codec
, WM8510_CLOCK
) & 0x11f;
325 snd_soc_write(codec
, WM8510_CLOCK
, reg
| div
);
328 reg
= snd_soc_read(codec
, WM8510_ADC
) & 0x1f7;
329 snd_soc_write(codec
, WM8510_ADC
, reg
| div
);
332 reg
= snd_soc_read(codec
, WM8510_DAC
) & 0x1f7;
333 snd_soc_write(codec
, WM8510_DAC
, reg
| div
);
336 reg
= snd_soc_read(codec
, WM8510_CLOCK
) & 0x1e3;
337 snd_soc_write(codec
, WM8510_CLOCK
, reg
| div
);
346 static int wm8510_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
349 struct snd_soc_codec
*codec
= codec_dai
->codec
;
351 u16 clk
= snd_soc_read(codec
, WM8510_CLOCK
) & 0x1fe;
353 /* set master/slave audio interface */
354 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
355 case SND_SOC_DAIFMT_CBM_CFM
:
358 case SND_SOC_DAIFMT_CBS_CFS
:
364 /* interface format */
365 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
366 case SND_SOC_DAIFMT_I2S
:
369 case SND_SOC_DAIFMT_RIGHT_J
:
371 case SND_SOC_DAIFMT_LEFT_J
:
374 case SND_SOC_DAIFMT_DSP_A
:
381 /* clock inversion */
382 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
383 case SND_SOC_DAIFMT_NB_NF
:
385 case SND_SOC_DAIFMT_IB_IF
:
388 case SND_SOC_DAIFMT_IB_NF
:
391 case SND_SOC_DAIFMT_NB_IF
:
398 snd_soc_write(codec
, WM8510_IFACE
, iface
);
399 snd_soc_write(codec
, WM8510_CLOCK
, clk
);
403 static int wm8510_pcm_hw_params(struct snd_pcm_substream
*substream
,
404 struct snd_pcm_hw_params
*params
,
405 struct snd_soc_dai
*dai
)
407 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
408 struct snd_soc_codec
*codec
= rtd
->codec
;
409 u16 iface
= snd_soc_read(codec
, WM8510_IFACE
) & 0x19f;
410 u16 adn
= snd_soc_read(codec
, WM8510_ADD
) & 0x1f1;
413 switch (params_format(params
)) {
414 case SNDRV_PCM_FORMAT_S16_LE
:
416 case SNDRV_PCM_FORMAT_S20_3LE
:
419 case SNDRV_PCM_FORMAT_S24_LE
:
422 case SNDRV_PCM_FORMAT_S32_LE
:
427 /* filter coefficient */
428 switch (params_rate(params
)) {
449 snd_soc_write(codec
, WM8510_IFACE
, iface
);
450 snd_soc_write(codec
, WM8510_ADD
, adn
);
454 static int wm8510_mute(struct snd_soc_dai
*dai
, int mute
)
456 struct snd_soc_codec
*codec
= dai
->codec
;
457 u16 mute_reg
= snd_soc_read(codec
, WM8510_DAC
) & 0xffbf;
460 snd_soc_write(codec
, WM8510_DAC
, mute_reg
| 0x40);
462 snd_soc_write(codec
, WM8510_DAC
, mute_reg
);
466 /* liam need to make this lower power with dapm */
467 static int wm8510_set_bias_level(struct snd_soc_codec
*codec
,
468 enum snd_soc_bias_level level
)
470 u16 power1
= snd_soc_read(codec
, WM8510_POWER1
) & ~0x3;
473 case SND_SOC_BIAS_ON
:
474 case SND_SOC_BIAS_PREPARE
:
475 power1
|= 0x1; /* VMID 50k */
476 snd_soc_write(codec
, WM8510_POWER1
, power1
);
479 case SND_SOC_BIAS_STANDBY
:
480 power1
|= WM8510_POWER1_BIASEN
| WM8510_POWER1_BUFIOEN
;
482 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_OFF
) {
483 snd_soc_cache_sync(codec
);
485 /* Initial cap charge at VMID 5k */
486 snd_soc_write(codec
, WM8510_POWER1
, power1
| 0x3);
490 power1
|= 0x2; /* VMID 500k */
491 snd_soc_write(codec
, WM8510_POWER1
, power1
);
494 case SND_SOC_BIAS_OFF
:
495 snd_soc_write(codec
, WM8510_POWER1
, 0);
496 snd_soc_write(codec
, WM8510_POWER2
, 0);
497 snd_soc_write(codec
, WM8510_POWER3
, 0);
501 codec
->dapm
.bias_level
= level
;
505 #define WM8510_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
506 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
507 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
509 #define WM8510_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
510 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
512 static struct snd_soc_dai_ops wm8510_dai_ops
= {
513 .hw_params
= wm8510_pcm_hw_params
,
514 .digital_mute
= wm8510_mute
,
515 .set_fmt
= wm8510_set_dai_fmt
,
516 .set_clkdiv
= wm8510_set_dai_clkdiv
,
517 .set_pll
= wm8510_set_dai_pll
,
520 static struct snd_soc_dai_driver wm8510_dai
= {
521 .name
= "wm8510-hifi",
523 .stream_name
= "Playback",
526 .rates
= WM8510_RATES
,
527 .formats
= WM8510_FORMATS
,},
529 .stream_name
= "Capture",
532 .rates
= WM8510_RATES
,
533 .formats
= WM8510_FORMATS
,},
534 .ops
= &wm8510_dai_ops
,
535 .symmetric_rates
= 1,
538 static int wm8510_suspend(struct snd_soc_codec
*codec
, pm_message_t state
)
540 wm8510_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
544 static int wm8510_resume(struct snd_soc_codec
*codec
)
546 wm8510_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
550 static int wm8510_probe(struct snd_soc_codec
*codec
)
552 struct wm8510_priv
*wm8510
= snd_soc_codec_get_drvdata(codec
);
555 ret
= snd_soc_codec_set_cache_io(codec
, 7, 9, wm8510
->control_type
);
557 printk(KERN_ERR
"wm8510: failed to set cache I/O: %d\n", ret
);
563 /* power on device */
564 wm8510_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
565 snd_soc_add_controls(codec
, wm8510_snd_controls
,
566 ARRAY_SIZE(wm8510_snd_controls
));
567 wm8510_add_widgets(codec
);
572 /* power down chip */
573 static int wm8510_remove(struct snd_soc_codec
*codec
)
575 struct wm8510_priv
*wm8510
= snd_soc_codec_get_drvdata(codec
);
577 wm8510_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
582 static struct snd_soc_codec_driver soc_codec_dev_wm8510
= {
583 .probe
= wm8510_probe
,
584 .remove
= wm8510_remove
,
585 .suspend
= wm8510_suspend
,
586 .resume
= wm8510_resume
,
587 .set_bias_level
= wm8510_set_bias_level
,
588 .reg_cache_size
= ARRAY_SIZE(wm8510_reg
),
589 .reg_word_size
= sizeof(u16
),
590 .reg_cache_default
=wm8510_reg
,
593 static const struct of_device_id wm8510_of_match
[] = {
594 { .compatible
= "wlf,wm8510" },
598 #if defined(CONFIG_SPI_MASTER)
599 static int __devinit
wm8510_spi_probe(struct spi_device
*spi
)
601 struct wm8510_priv
*wm8510
;
604 wm8510
= kzalloc(sizeof(struct wm8510_priv
), GFP_KERNEL
);
608 wm8510
->control_type
= SND_SOC_SPI
;
609 spi_set_drvdata(spi
, wm8510
);
611 ret
= snd_soc_register_codec(&spi
->dev
,
612 &soc_codec_dev_wm8510
, &wm8510_dai
, 1);
618 static int __devexit
wm8510_spi_remove(struct spi_device
*spi
)
620 snd_soc_unregister_codec(&spi
->dev
);
624 static struct spi_driver wm8510_spi_driver
= {
627 .owner
= THIS_MODULE
,
628 .of_match_table
= wm8510_of_match
,
630 .probe
= wm8510_spi_probe
,
631 .remove
= __devexit_p(wm8510_spi_remove
),
633 #endif /* CONFIG_SPI_MASTER */
635 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
636 static __devinit
int wm8510_i2c_probe(struct i2c_client
*i2c
,
637 const struct i2c_device_id
*id
)
639 struct wm8510_priv
*wm8510
;
642 wm8510
= kzalloc(sizeof(struct wm8510_priv
), GFP_KERNEL
);
646 i2c_set_clientdata(i2c
, wm8510
);
647 wm8510
->control_type
= SND_SOC_I2C
;
649 ret
= snd_soc_register_codec(&i2c
->dev
,
650 &soc_codec_dev_wm8510
, &wm8510_dai
, 1);
656 static __devexit
int wm8510_i2c_remove(struct i2c_client
*client
)
658 snd_soc_unregister_codec(&client
->dev
);
662 static const struct i2c_device_id wm8510_i2c_id
[] = {
666 MODULE_DEVICE_TABLE(i2c
, wm8510_i2c_id
);
668 static struct i2c_driver wm8510_i2c_driver
= {
670 .name
= "wm8510-codec",
671 .owner
= THIS_MODULE
,
672 .of_match_table
= wm8510_of_match
,
674 .probe
= wm8510_i2c_probe
,
675 .remove
= __devexit_p(wm8510_i2c_remove
),
676 .id_table
= wm8510_i2c_id
,
680 static int __init
wm8510_modinit(void)
683 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
684 ret
= i2c_add_driver(&wm8510_i2c_driver
);
686 printk(KERN_ERR
"Failed to register WM8510 I2C driver: %d\n",
690 #if defined(CONFIG_SPI_MASTER)
691 ret
= spi_register_driver(&wm8510_spi_driver
);
693 printk(KERN_ERR
"Failed to register WM8510 SPI driver: %d\n",
699 module_init(wm8510_modinit
);
701 static void __exit
wm8510_exit(void)
703 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
704 i2c_del_driver(&wm8510_i2c_driver
);
706 #if defined(CONFIG_SPI_MASTER)
707 spi_unregister_driver(&wm8510_spi_driver
);
710 module_exit(wm8510_exit
);
712 MODULE_DESCRIPTION("ASoC WM8510 driver");
713 MODULE_AUTHOR("Liam Girdwood");
714 MODULE_LICENSE("GPL");