2 * wm8974.c -- WM8974 ALSA Soc Audio driver
4 * Copyright 2006-2009 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood <linux@wolfsonmicro.com>
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 <sound/core.h>
22 #include <sound/pcm.h>
23 #include <sound/pcm_params.h>
24 #include <sound/soc.h>
25 #include <sound/soc-dapm.h>
26 #include <sound/initval.h>
27 #include <sound/tlv.h>
31 static const u16 wm8974_reg
[WM8974_CACHEREGNUM
] = {
32 0x0000, 0x0000, 0x0000, 0x0000,
33 0x0050, 0x0000, 0x0140, 0x0000,
34 0x0000, 0x0000, 0x0000, 0x00ff,
35 0x0000, 0x0000, 0x0100, 0x00ff,
36 0x0000, 0x0000, 0x012c, 0x002c,
37 0x002c, 0x002c, 0x002c, 0x0000,
38 0x0032, 0x0000, 0x0000, 0x0000,
39 0x0000, 0x0000, 0x0000, 0x0000,
40 0x0038, 0x000b, 0x0032, 0x0000,
41 0x0008, 0x000c, 0x0093, 0x00e9,
42 0x0000, 0x0000, 0x0000, 0x0000,
43 0x0003, 0x0010, 0x0000, 0x0000,
44 0x0000, 0x0002, 0x0000, 0x0000,
45 0x0000, 0x0000, 0x0039, 0x0000,
49 #define WM8974_POWER1_BIASEN 0x08
50 #define WM8974_POWER1_BUFIOEN 0x10
53 struct snd_soc_codec codec
;
54 u16 reg_cache
[WM8974_CACHEREGNUM
];
57 static struct snd_soc_codec
*wm8974_codec
;
59 #define wm8974_reset(c) snd_soc_write(c, WM8974_RESET, 0)
61 static const char *wm8974_companding
[] = {"Off", "NC", "u-law", "A-law" };
62 static const char *wm8974_deemp
[] = {"None", "32kHz", "44.1kHz", "48kHz" };
63 static const char *wm8974_eqmode
[] = {"Capture", "Playback" };
64 static const char *wm8974_bw
[] = {"Narrow", "Wide" };
65 static const char *wm8974_eq1
[] = {"80Hz", "105Hz", "135Hz", "175Hz" };
66 static const char *wm8974_eq2
[] = {"230Hz", "300Hz", "385Hz", "500Hz" };
67 static const char *wm8974_eq3
[] = {"650Hz", "850Hz", "1.1kHz", "1.4kHz" };
68 static const char *wm8974_eq4
[] = {"1.8kHz", "2.4kHz", "3.2kHz", "4.1kHz" };
69 static const char *wm8974_eq5
[] = {"5.3kHz", "6.9kHz", "9kHz", "11.7kHz" };
70 static const char *wm8974_alc
[] = {"ALC", "Limiter" };
72 static const struct soc_enum wm8974_enum
[] = {
73 SOC_ENUM_SINGLE(WM8974_COMP
, 1, 4, wm8974_companding
), /* adc */
74 SOC_ENUM_SINGLE(WM8974_COMP
, 3, 4, wm8974_companding
), /* dac */
75 SOC_ENUM_SINGLE(WM8974_DAC
, 4, 4, wm8974_deemp
),
76 SOC_ENUM_SINGLE(WM8974_EQ1
, 8, 2, wm8974_eqmode
),
78 SOC_ENUM_SINGLE(WM8974_EQ1
, 5, 4, wm8974_eq1
),
79 SOC_ENUM_SINGLE(WM8974_EQ2
, 8, 2, wm8974_bw
),
80 SOC_ENUM_SINGLE(WM8974_EQ2
, 5, 4, wm8974_eq2
),
81 SOC_ENUM_SINGLE(WM8974_EQ3
, 8, 2, wm8974_bw
),
83 SOC_ENUM_SINGLE(WM8974_EQ3
, 5, 4, wm8974_eq3
),
84 SOC_ENUM_SINGLE(WM8974_EQ4
, 8, 2, wm8974_bw
),
85 SOC_ENUM_SINGLE(WM8974_EQ4
, 5, 4, wm8974_eq4
),
86 SOC_ENUM_SINGLE(WM8974_EQ5
, 8, 2, wm8974_bw
),
88 SOC_ENUM_SINGLE(WM8974_EQ5
, 5, 4, wm8974_eq5
),
89 SOC_ENUM_SINGLE(WM8974_ALC3
, 8, 2, wm8974_alc
),
92 static const char *wm8974_auxmode_text
[] = { "Buffer", "Mixer" };
94 static const struct soc_enum wm8974_auxmode
=
95 SOC_ENUM_SINGLE(WM8974_INPUT
, 3, 2, wm8974_auxmode_text
);
97 static const DECLARE_TLV_DB_SCALE(digital_tlv
, -12750, 50, 1);
98 static const DECLARE_TLV_DB_SCALE(eq_tlv
, -1200, 100, 0);
99 static const DECLARE_TLV_DB_SCALE(inpga_tlv
, -1200, 75, 0);
100 static const DECLARE_TLV_DB_SCALE(spk_tlv
, -5700, 100, 0);
102 static const struct snd_kcontrol_new wm8974_snd_controls
[] = {
104 SOC_SINGLE("Digital Loopback Switch", WM8974_COMP
, 0, 1, 0),
106 SOC_ENUM("DAC Companding", wm8974_enum
[1]),
107 SOC_ENUM("ADC Companding", wm8974_enum
[0]),
109 SOC_ENUM("Playback De-emphasis", wm8974_enum
[2]),
110 SOC_SINGLE("DAC Inversion Switch", WM8974_DAC
, 0, 1, 0),
112 SOC_SINGLE_TLV("PCM Volume", WM8974_DACVOL
, 0, 255, 0, digital_tlv
),
114 SOC_SINGLE("High Pass Filter Switch", WM8974_ADC
, 8, 1, 0),
115 SOC_SINGLE("High Pass Cut Off", WM8974_ADC
, 4, 7, 0),
116 SOC_SINGLE("ADC Inversion Switch", WM8974_ADC
, 0, 1, 0),
118 SOC_SINGLE_TLV("Capture Volume", WM8974_ADCVOL
, 0, 255, 0, digital_tlv
),
120 SOC_ENUM("Equaliser Function", wm8974_enum
[3]),
121 SOC_ENUM("EQ1 Cut Off", wm8974_enum
[4]),
122 SOC_SINGLE_TLV("EQ1 Volume", WM8974_EQ1
, 0, 24, 1, eq_tlv
),
124 SOC_ENUM("Equaliser EQ2 Bandwith", wm8974_enum
[5]),
125 SOC_ENUM("EQ2 Cut Off", wm8974_enum
[6]),
126 SOC_SINGLE_TLV("EQ2 Volume", WM8974_EQ2
, 0, 24, 1, eq_tlv
),
128 SOC_ENUM("Equaliser EQ3 Bandwith", wm8974_enum
[7]),
129 SOC_ENUM("EQ3 Cut Off", wm8974_enum
[8]),
130 SOC_SINGLE_TLV("EQ3 Volume", WM8974_EQ3
, 0, 24, 1, eq_tlv
),
132 SOC_ENUM("Equaliser EQ4 Bandwith", wm8974_enum
[9]),
133 SOC_ENUM("EQ4 Cut Off", wm8974_enum
[10]),
134 SOC_SINGLE_TLV("EQ4 Volume", WM8974_EQ4
, 0, 24, 1, eq_tlv
),
136 SOC_ENUM("Equaliser EQ5 Bandwith", wm8974_enum
[11]),
137 SOC_ENUM("EQ5 Cut Off", wm8974_enum
[12]),
138 SOC_SINGLE_TLV("EQ5 Volume", WM8974_EQ5
, 0, 24, 1, eq_tlv
),
140 SOC_SINGLE("DAC Playback Limiter Switch", WM8974_DACLIM1
, 8, 1, 0),
141 SOC_SINGLE("DAC Playback Limiter Decay", WM8974_DACLIM1
, 4, 15, 0),
142 SOC_SINGLE("DAC Playback Limiter Attack", WM8974_DACLIM1
, 0, 15, 0),
144 SOC_SINGLE("DAC Playback Limiter Threshold", WM8974_DACLIM2
, 4, 7, 0),
145 SOC_SINGLE("DAC Playback Limiter Boost", WM8974_DACLIM2
, 0, 15, 0),
147 SOC_SINGLE("ALC Enable Switch", WM8974_ALC1
, 8, 1, 0),
148 SOC_SINGLE("ALC Capture Max Gain", WM8974_ALC1
, 3, 7, 0),
149 SOC_SINGLE("ALC Capture Min Gain", WM8974_ALC1
, 0, 7, 0),
151 SOC_SINGLE("ALC Capture ZC Switch", WM8974_ALC2
, 8, 1, 0),
152 SOC_SINGLE("ALC Capture Hold", WM8974_ALC2
, 4, 7, 0),
153 SOC_SINGLE("ALC Capture Target", WM8974_ALC2
, 0, 15, 0),
155 SOC_ENUM("ALC Capture Mode", wm8974_enum
[13]),
156 SOC_SINGLE("ALC Capture Decay", WM8974_ALC3
, 4, 15, 0),
157 SOC_SINGLE("ALC Capture Attack", WM8974_ALC3
, 0, 15, 0),
159 SOC_SINGLE("ALC Capture Noise Gate Switch", WM8974_NGATE
, 3, 1, 0),
160 SOC_SINGLE("ALC Capture Noise Gate Threshold", WM8974_NGATE
, 0, 7, 0),
162 SOC_SINGLE("Capture PGA ZC Switch", WM8974_INPPGA
, 7, 1, 0),
163 SOC_SINGLE_TLV("Capture PGA Volume", WM8974_INPPGA
, 0, 63, 0, inpga_tlv
),
165 SOC_SINGLE("Speaker Playback ZC Switch", WM8974_SPKVOL
, 7, 1, 0),
166 SOC_SINGLE("Speaker Playback Switch", WM8974_SPKVOL
, 6, 1, 1),
167 SOC_SINGLE_TLV("Speaker Playback Volume", WM8974_SPKVOL
, 0, 63, 0, spk_tlv
),
169 SOC_ENUM("Aux Mode", wm8974_auxmode
),
171 SOC_SINGLE("Capture Boost(+20dB)", WM8974_ADCBOOST
, 8, 1, 0),
172 SOC_SINGLE("Mono Playback Switch", WM8974_MONOMIX
, 6, 1, 1),
175 /* Speaker Output Mixer */
176 static const struct snd_kcontrol_new wm8974_speaker_mixer_controls
[] = {
177 SOC_DAPM_SINGLE("Line Bypass Switch", WM8974_SPKMIX
, 1, 1, 0),
178 SOC_DAPM_SINGLE("Aux Playback Switch", WM8974_SPKMIX
, 5, 1, 0),
179 SOC_DAPM_SINGLE("PCM Playback Switch", WM8974_SPKMIX
, 0, 1, 1),
182 /* Mono Output Mixer */
183 static const struct snd_kcontrol_new wm8974_mono_mixer_controls
[] = {
184 SOC_DAPM_SINGLE("Line Bypass Switch", WM8974_MONOMIX
, 1, 1, 0),
185 SOC_DAPM_SINGLE("Aux Playback Switch", WM8974_MONOMIX
, 2, 1, 0),
186 SOC_DAPM_SINGLE("PCM Playback Switch", WM8974_MONOMIX
, 0, 1, 0),
190 static const struct snd_kcontrol_new wm8974_boost_mixer
[] = {
191 SOC_DAPM_SINGLE("Aux Switch", WM8974_INPPGA
, 6, 1, 0),
195 static const struct snd_kcontrol_new wm8974_inpga
[] = {
196 SOC_DAPM_SINGLE("Aux Switch", WM8974_INPUT
, 2, 1, 0),
197 SOC_DAPM_SINGLE("MicN Switch", WM8974_INPUT
, 1, 1, 0),
198 SOC_DAPM_SINGLE("MicP Switch", WM8974_INPUT
, 0, 1, 0),
201 /* AUX Input boost vol */
202 static const struct snd_kcontrol_new wm8974_aux_boost_controls
=
203 SOC_DAPM_SINGLE("Aux Volume", WM8974_ADCBOOST
, 0, 7, 0);
205 /* Mic Input boost vol */
206 static const struct snd_kcontrol_new wm8974_mic_boost_controls
=
207 SOC_DAPM_SINGLE("Mic Volume", WM8974_ADCBOOST
, 4, 7, 0);
209 static const struct snd_soc_dapm_widget wm8974_dapm_widgets
[] = {
210 SND_SOC_DAPM_MIXER("Speaker Mixer", WM8974_POWER3
, 2, 0,
211 &wm8974_speaker_mixer_controls
[0],
212 ARRAY_SIZE(wm8974_speaker_mixer_controls
)),
213 SND_SOC_DAPM_MIXER("Mono Mixer", WM8974_POWER3
, 3, 0,
214 &wm8974_mono_mixer_controls
[0],
215 ARRAY_SIZE(wm8974_mono_mixer_controls
)),
216 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8974_POWER3
, 0, 0),
217 SND_SOC_DAPM_ADC("ADC", "HiFi Capture", WM8974_POWER2
, 0, 0),
218 SND_SOC_DAPM_PGA("Aux Input", WM8974_POWER1
, 6, 0, NULL
, 0),
219 SND_SOC_DAPM_PGA("SpkN Out", WM8974_POWER3
, 5, 0, NULL
, 0),
220 SND_SOC_DAPM_PGA("SpkP Out", WM8974_POWER3
, 6, 0, NULL
, 0),
221 SND_SOC_DAPM_PGA("Mono Out", WM8974_POWER3
, 7, 0, NULL
, 0),
223 SND_SOC_DAPM_MIXER("Input PGA", WM8974_POWER2
, 2, 0, wm8974_inpga
,
224 ARRAY_SIZE(wm8974_inpga
)),
225 SND_SOC_DAPM_MIXER("Boost Mixer", WM8974_POWER2
, 4, 0,
226 wm8974_boost_mixer
, ARRAY_SIZE(wm8974_boost_mixer
)),
228 SND_SOC_DAPM_MICBIAS("Mic Bias", WM8974_POWER1
, 4, 0),
230 SND_SOC_DAPM_INPUT("MICN"),
231 SND_SOC_DAPM_INPUT("MICP"),
232 SND_SOC_DAPM_INPUT("AUX"),
233 SND_SOC_DAPM_OUTPUT("MONOOUT"),
234 SND_SOC_DAPM_OUTPUT("SPKOUTP"),
235 SND_SOC_DAPM_OUTPUT("SPKOUTN"),
238 static const struct snd_soc_dapm_route audio_map
[] = {
239 /* Mono output mixer */
240 {"Mono Mixer", "PCM Playback Switch", "DAC"},
241 {"Mono Mixer", "Aux Playback Switch", "Aux Input"},
242 {"Mono Mixer", "Line Bypass Switch", "Boost Mixer"},
244 /* Speaker output mixer */
245 {"Speaker Mixer", "PCM Playback Switch", "DAC"},
246 {"Speaker Mixer", "Aux Playback Switch", "Aux Input"},
247 {"Speaker Mixer", "Line Bypass Switch", "Boost Mixer"},
250 {"Mono Out", NULL
, "Mono Mixer"},
251 {"MONOOUT", NULL
, "Mono Out"},
252 {"SpkN Out", NULL
, "Speaker Mixer"},
253 {"SpkP Out", NULL
, "Speaker Mixer"},
254 {"SPKOUTN", NULL
, "SpkN Out"},
255 {"SPKOUTP", NULL
, "SpkP Out"},
258 {"ADC", NULL
, "Boost Mixer"},
259 {"Boost Mixer", "Aux Switch", "Aux Input"},
260 {"Boost Mixer", NULL
, "Input PGA"},
261 {"Boost Mixer", NULL
, "MICP"},
264 {"Input PGA", "Aux Switch", "Aux Input"},
265 {"Input PGA", "MicN Switch", "MICN"},
266 {"Input PGA", "MicP Switch", "MICP"},
269 {"Aux Input", NULL
, "AUX"},
272 static int wm8974_add_widgets(struct snd_soc_codec
*codec
)
274 snd_soc_dapm_new_controls(codec
, wm8974_dapm_widgets
,
275 ARRAY_SIZE(wm8974_dapm_widgets
));
277 snd_soc_dapm_add_routes(codec
, audio_map
, ARRAY_SIZE(audio_map
));
279 snd_soc_dapm_new_widgets(codec
);
284 unsigned int pre_div
:1;
289 /* The size in bits of the pll divide multiplied by 10
290 * to allow rounding later */
291 #define FIXED_PLL_SIZE ((1 << 24) * 10)
293 static void pll_factors(struct pll_
*pll_div
,
294 unsigned int target
, unsigned int source
)
296 unsigned long long Kpart
;
297 unsigned int K
, Ndiv
, Nmod
;
299 /* There is a fixed divide by 4 in the output path */
302 Ndiv
= target
/ source
;
305 pll_div
->pre_div
= 1;
306 Ndiv
= target
/ source
;
308 pll_div
->pre_div
= 0;
310 if ((Ndiv
< 6) || (Ndiv
> 12))
312 "WM8974 N value %u outwith recommended range!\n",
316 Nmod
= target
% source
;
317 Kpart
= FIXED_PLL_SIZE
* (long long)Nmod
;
319 do_div(Kpart
, source
);
321 K
= Kpart
& 0xFFFFFFFF;
323 /* Check if we need to round */
327 /* Move down to proper range now rounding is done */
333 static int wm8974_set_dai_pll(struct snd_soc_dai
*codec_dai
, int pll_id
,
334 int source
, unsigned int freq_in
, unsigned int freq_out
)
336 struct snd_soc_codec
*codec
= codec_dai
->codec
;
340 if (freq_in
== 0 || freq_out
== 0) {
341 /* Clock CODEC directly from MCLK */
342 reg
= snd_soc_read(codec
, WM8974_CLOCK
);
343 snd_soc_write(codec
, WM8974_CLOCK
, reg
& 0x0ff);
346 reg
= snd_soc_read(codec
, WM8974_POWER1
);
347 snd_soc_write(codec
, WM8974_POWER1
, reg
& 0x1df);
351 pll_factors(&pll_div
, freq_out
, freq_in
);
353 snd_soc_write(codec
, WM8974_PLLN
, (pll_div
.pre_div
<< 4) | pll_div
.n
);
354 snd_soc_write(codec
, WM8974_PLLK1
, pll_div
.k
>> 18);
355 snd_soc_write(codec
, WM8974_PLLK2
, (pll_div
.k
>> 9) & 0x1ff);
356 snd_soc_write(codec
, WM8974_PLLK3
, pll_div
.k
& 0x1ff);
357 reg
= snd_soc_read(codec
, WM8974_POWER1
);
358 snd_soc_write(codec
, WM8974_POWER1
, reg
| 0x020);
360 /* Run CODEC from PLL instead of MCLK */
361 reg
= snd_soc_read(codec
, WM8974_CLOCK
);
362 snd_soc_write(codec
, WM8974_CLOCK
, reg
| 0x100);
368 * Configure WM8974 clock dividers.
370 static int wm8974_set_dai_clkdiv(struct snd_soc_dai
*codec_dai
,
373 struct snd_soc_codec
*codec
= codec_dai
->codec
;
377 case WM8974_OPCLKDIV
:
378 reg
= snd_soc_read(codec
, WM8974_GPIO
) & 0x1cf;
379 snd_soc_write(codec
, WM8974_GPIO
, reg
| div
);
382 reg
= snd_soc_read(codec
, WM8974_CLOCK
) & 0x11f;
383 snd_soc_write(codec
, WM8974_CLOCK
, reg
| div
);
386 reg
= snd_soc_read(codec
, WM8974_ADC
) & 0x1f7;
387 snd_soc_write(codec
, WM8974_ADC
, reg
| div
);
390 reg
= snd_soc_read(codec
, WM8974_DAC
) & 0x1f7;
391 snd_soc_write(codec
, WM8974_DAC
, reg
| div
);
394 reg
= snd_soc_read(codec
, WM8974_CLOCK
) & 0x1e3;
395 snd_soc_write(codec
, WM8974_CLOCK
, reg
| div
);
404 static int wm8974_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
407 struct snd_soc_codec
*codec
= codec_dai
->codec
;
409 u16 clk
= snd_soc_read(codec
, WM8974_CLOCK
) & 0x1fe;
411 /* set master/slave audio interface */
412 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
413 case SND_SOC_DAIFMT_CBM_CFM
:
416 case SND_SOC_DAIFMT_CBS_CFS
:
422 /* interface format */
423 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
424 case SND_SOC_DAIFMT_I2S
:
427 case SND_SOC_DAIFMT_RIGHT_J
:
429 case SND_SOC_DAIFMT_LEFT_J
:
432 case SND_SOC_DAIFMT_DSP_A
:
439 /* clock inversion */
440 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
441 case SND_SOC_DAIFMT_NB_NF
:
443 case SND_SOC_DAIFMT_IB_IF
:
446 case SND_SOC_DAIFMT_IB_NF
:
449 case SND_SOC_DAIFMT_NB_IF
:
456 snd_soc_write(codec
, WM8974_IFACE
, iface
);
457 snd_soc_write(codec
, WM8974_CLOCK
, clk
);
461 static int wm8974_pcm_hw_params(struct snd_pcm_substream
*substream
,
462 struct snd_pcm_hw_params
*params
,
463 struct snd_soc_dai
*dai
)
465 struct snd_soc_codec
*codec
= dai
->codec
;
466 u16 iface
= snd_soc_read(codec
, WM8974_IFACE
) & 0x19f;
467 u16 adn
= snd_soc_read(codec
, WM8974_ADD
) & 0x1f1;
470 switch (params_format(params
)) {
471 case SNDRV_PCM_FORMAT_S16_LE
:
473 case SNDRV_PCM_FORMAT_S20_3LE
:
476 case SNDRV_PCM_FORMAT_S24_LE
:
479 case SNDRV_PCM_FORMAT_S32_LE
:
484 /* filter coefficient */
485 switch (params_rate(params
)) {
486 case SNDRV_PCM_RATE_8000
:
489 case SNDRV_PCM_RATE_11025
:
492 case SNDRV_PCM_RATE_16000
:
495 case SNDRV_PCM_RATE_22050
:
498 case SNDRV_PCM_RATE_32000
:
501 case SNDRV_PCM_RATE_44100
:
502 case SNDRV_PCM_RATE_48000
:
506 snd_soc_write(codec
, WM8974_IFACE
, iface
);
507 snd_soc_write(codec
, WM8974_ADD
, adn
);
511 static int wm8974_mute(struct snd_soc_dai
*dai
, int mute
)
513 struct snd_soc_codec
*codec
= dai
->codec
;
514 u16 mute_reg
= snd_soc_read(codec
, WM8974_DAC
) & 0xffbf;
517 snd_soc_write(codec
, WM8974_DAC
, mute_reg
| 0x40);
519 snd_soc_write(codec
, WM8974_DAC
, mute_reg
);
523 /* liam need to make this lower power with dapm */
524 static int wm8974_set_bias_level(struct snd_soc_codec
*codec
,
525 enum snd_soc_bias_level level
)
527 u16 power1
= snd_soc_read(codec
, WM8974_POWER1
) & ~0x3;
530 case SND_SOC_BIAS_ON
:
531 case SND_SOC_BIAS_PREPARE
:
532 power1
|= 0x1; /* VMID 50k */
533 snd_soc_write(codec
, WM8974_POWER1
, power1
);
536 case SND_SOC_BIAS_STANDBY
:
537 power1
|= WM8974_POWER1_BIASEN
| WM8974_POWER1_BUFIOEN
;
539 if (codec
->bias_level
== SND_SOC_BIAS_OFF
) {
540 /* Initial cap charge at VMID 5k */
541 snd_soc_write(codec
, WM8974_POWER1
, power1
| 0x3);
545 power1
|= 0x2; /* VMID 500k */
546 snd_soc_write(codec
, WM8974_POWER1
, power1
);
549 case SND_SOC_BIAS_OFF
:
550 snd_soc_write(codec
, WM8974_POWER1
, 0);
551 snd_soc_write(codec
, WM8974_POWER2
, 0);
552 snd_soc_write(codec
, WM8974_POWER3
, 0);
556 codec
->bias_level
= level
;
560 #define WM8974_RATES (SNDRV_PCM_RATE_8000_48000)
562 #define WM8974_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
563 SNDRV_PCM_FMTBIT_S24_LE)
565 static struct snd_soc_dai_ops wm8974_ops
= {
566 .hw_params
= wm8974_pcm_hw_params
,
567 .digital_mute
= wm8974_mute
,
568 .set_fmt
= wm8974_set_dai_fmt
,
569 .set_clkdiv
= wm8974_set_dai_clkdiv
,
570 .set_pll
= wm8974_set_dai_pll
,
573 struct snd_soc_dai wm8974_dai
= {
574 .name
= "WM8974 HiFi",
576 .stream_name
= "Playback",
578 .channels_max
= 2, /* Only 1 channel of data */
579 .rates
= WM8974_RATES
,
580 .formats
= WM8974_FORMATS
,},
582 .stream_name
= "Capture",
584 .channels_max
= 2, /* Only 1 channel of data */
585 .rates
= WM8974_RATES
,
586 .formats
= WM8974_FORMATS
,},
588 .symmetric_rates
= 1,
590 EXPORT_SYMBOL_GPL(wm8974_dai
);
592 static int wm8974_suspend(struct platform_device
*pdev
, pm_message_t state
)
594 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
595 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
597 wm8974_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
601 static int wm8974_resume(struct platform_device
*pdev
)
603 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
604 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
607 u16
*cache
= codec
->reg_cache
;
609 /* Sync reg_cache with the hardware */
610 for (i
= 0; i
< ARRAY_SIZE(wm8974_reg
); i
++) {
611 data
[0] = (i
<< 1) | ((cache
[i
] >> 8) & 0x0001);
612 data
[1] = cache
[i
] & 0x00ff;
613 codec
->hw_write(codec
->control_data
, data
, 2);
615 wm8974_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
616 wm8974_set_bias_level(codec
, codec
->suspend_bias_level
);
620 static int wm8974_probe(struct platform_device
*pdev
)
622 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
623 struct snd_soc_codec
*codec
;
626 if (wm8974_codec
== NULL
) {
627 dev_err(&pdev
->dev
, "Codec device not registered\n");
631 socdev
->card
->codec
= wm8974_codec
;
632 codec
= wm8974_codec
;
635 ret
= snd_soc_new_pcms(socdev
, SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
);
637 dev_err(codec
->dev
, "failed to create pcms: %d\n", ret
);
641 snd_soc_add_controls(codec
, wm8974_snd_controls
,
642 ARRAY_SIZE(wm8974_snd_controls
));
643 wm8974_add_widgets(codec
);
644 ret
= snd_soc_init_card(socdev
);
646 dev_err(codec
->dev
, "failed to register card: %d\n", ret
);
653 snd_soc_free_pcms(socdev
);
654 snd_soc_dapm_free(socdev
);
659 /* power down chip */
660 static int wm8974_remove(struct platform_device
*pdev
)
662 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
664 snd_soc_free_pcms(socdev
);
665 snd_soc_dapm_free(socdev
);
670 struct snd_soc_codec_device soc_codec_dev_wm8974
= {
671 .probe
= wm8974_probe
,
672 .remove
= wm8974_remove
,
673 .suspend
= wm8974_suspend
,
674 .resume
= wm8974_resume
,
676 EXPORT_SYMBOL_GPL(soc_codec_dev_wm8974
);
678 static __devinit
int wm8974_register(struct wm8974_priv
*wm8974
)
681 struct snd_soc_codec
*codec
= &wm8974
->codec
;
684 dev_err(codec
->dev
, "Another WM8974 is registered\n");
688 mutex_init(&codec
->mutex
);
689 INIT_LIST_HEAD(&codec
->dapm_widgets
);
690 INIT_LIST_HEAD(&codec
->dapm_paths
);
692 codec
->private_data
= wm8974
;
693 codec
->name
= "WM8974";
694 codec
->owner
= THIS_MODULE
;
695 codec
->bias_level
= SND_SOC_BIAS_OFF
;
696 codec
->set_bias_level
= wm8974_set_bias_level
;
697 codec
->dai
= &wm8974_dai
;
699 codec
->reg_cache_size
= WM8974_CACHEREGNUM
;
700 codec
->reg_cache
= &wm8974
->reg_cache
;
702 ret
= snd_soc_codec_set_cache_io(codec
, 7, 9, SND_SOC_I2C
);
704 dev_err(codec
->dev
, "Failed to set cache I/O: %d\n", ret
);
708 memcpy(codec
->reg_cache
, wm8974_reg
, sizeof(wm8974_reg
));
710 ret
= wm8974_reset(codec
);
712 dev_err(codec
->dev
, "Failed to issue reset\n");
716 wm8974_dai
.dev
= codec
->dev
;
718 wm8974_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
720 wm8974_codec
= codec
;
722 ret
= snd_soc_register_codec(codec
);
724 dev_err(codec
->dev
, "Failed to register codec: %d\n", ret
);
728 ret
= snd_soc_register_dai(&wm8974_dai
);
730 dev_err(codec
->dev
, "Failed to register DAI: %d\n", ret
);
737 snd_soc_unregister_codec(codec
);
743 static __devexit
void wm8974_unregister(struct wm8974_priv
*wm8974
)
745 wm8974_set_bias_level(&wm8974
->codec
, SND_SOC_BIAS_OFF
);
746 snd_soc_unregister_dai(&wm8974_dai
);
747 snd_soc_unregister_codec(&wm8974
->codec
);
752 static __devinit
int wm8974_i2c_probe(struct i2c_client
*i2c
,
753 const struct i2c_device_id
*id
)
755 struct wm8974_priv
*wm8974
;
756 struct snd_soc_codec
*codec
;
758 wm8974
= kzalloc(sizeof(struct wm8974_priv
), GFP_KERNEL
);
762 codec
= &wm8974
->codec
;
763 codec
->hw_write
= (hw_write_t
)i2c_master_send
;
765 i2c_set_clientdata(i2c
, wm8974
);
766 codec
->control_data
= i2c
;
768 codec
->dev
= &i2c
->dev
;
770 return wm8974_register(wm8974
);
773 static __devexit
int wm8974_i2c_remove(struct i2c_client
*client
)
775 struct wm8974_priv
*wm8974
= i2c_get_clientdata(client
);
776 wm8974_unregister(wm8974
);
780 static const struct i2c_device_id wm8974_i2c_id
[] = {
784 MODULE_DEVICE_TABLE(i2c
, wm8974_i2c_id
);
786 static struct i2c_driver wm8974_i2c_driver
= {
789 .owner
= THIS_MODULE
,
791 .probe
= wm8974_i2c_probe
,
792 .remove
= __devexit_p(wm8974_i2c_remove
),
793 .id_table
= wm8974_i2c_id
,
796 static int __init
wm8974_modinit(void)
798 return i2c_add_driver(&wm8974_i2c_driver
);
800 module_init(wm8974_modinit
);
802 static void __exit
wm8974_exit(void)
804 i2c_del_driver(&wm8974_i2c_driver
);
806 module_exit(wm8974_exit
);
808 MODULE_DESCRIPTION("ASoC WM8974 driver");
809 MODULE_AUTHOR("Liam Girdwood");
810 MODULE_LICENSE("GPL");