1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * wm8753.c -- WM8753 ALSA Soc Audio driver
5 * Copyright 2003-11 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
9 * The WM8753 is a low power, high quality stereo codec with integrated PCM
10 * codec designed for portable digital telephony applications.
14 * This driver support 2 DAI PCM's. This makes the default PCM available for
15 * HiFi audio (e.g. MP3, ogg) playback/capture and the other PCM available for
18 * Please note that the voice PCM can be connected directly to a Bluetooth
19 * codec or GSM modem and thus cannot be read or written to, although it is
20 * available to be configured with snd_hw_params(), etc and kcontrols in the
23 * Fast DAI switching:-
25 * The driver can now fast switch between the DAI configurations via a
26 * an alsa kcontrol. This allows the PCM to remain open.
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/init.h>
32 #include <linux/delay.h>
34 #include <linux/i2c.h>
35 #include <linux/of_device.h>
36 #include <linux/regmap.h>
37 #include <linux/spi/spi.h>
38 #include <linux/slab.h>
39 #include <sound/core.h>
40 #include <sound/pcm.h>
41 #include <sound/pcm_params.h>
42 #include <sound/soc.h>
43 #include <sound/initval.h>
44 #include <sound/tlv.h>
45 #include <asm/div64.h>
49 static int caps_charge
= 2000;
50 module_param(caps_charge
, int, 0);
51 MODULE_PARM_DESC(caps_charge
, "WM8753 cap charge time (msecs)");
53 static int wm8753_hifi_write_dai_fmt(struct snd_soc_component
*component
,
55 static int wm8753_voice_write_dai_fmt(struct snd_soc_component
*component
,
59 * wm8753 register cache
60 * We can't read the WM8753 register space when we
61 * are using 2 wire for device control, so we cache them instead.
63 static const struct reg_default wm8753_reg_defaults
[] = {
130 static bool wm8753_volatile(struct device
*dev
, unsigned int reg
)
132 return reg
== WM8753_RESET
;
135 /* codec private data */
137 struct regmap
*regmap
;
141 unsigned int voice_fmt
;
142 unsigned int hifi_fmt
;
145 struct delayed_work charge_work
;
148 #define wm8753_reset(c) snd_soc_component_write(c, WM8753_RESET, 0)
153 static const char *wm8753_base
[] = {"Linear Control", "Adaptive Boost"};
154 static const char *wm8753_base_filter
[] =
155 {"130Hz @ 48kHz", "200Hz @ 48kHz", "100Hz @ 16kHz", "400Hz @ 48kHz",
156 "100Hz @ 8kHz", "200Hz @ 8kHz"};
157 static const char *wm8753_treble
[] = {"8kHz", "4kHz"};
158 static const char *wm8753_alc_func
[] = {"Off", "Right", "Left", "Stereo"};
159 static const char *wm8753_ng_type
[] = {"Constant PGA Gain", "Mute ADC Output"};
160 static const char *wm8753_3d_func
[] = {"Capture", "Playback"};
161 static const char *wm8753_3d_uc
[] = {"2.2kHz", "1.5kHz"};
162 static const char *wm8753_3d_lc
[] = {"200Hz", "500Hz"};
163 static const char *wm8753_deemp
[] = {"None", "32kHz", "44.1kHz", "48kHz"};
164 static const char *wm8753_mono_mix
[] = {"Stereo", "Left", "Right", "Mono"};
165 static const char *wm8753_dac_phase
[] = {"Non Inverted", "Inverted"};
166 static const char *wm8753_line_mix
[] = {"Line 1 + 2", "Line 1 - 2",
168 static const char *wm8753_mono_mux
[] = {"Line Mix", "Rx Mix"};
169 static const char *wm8753_right_mux
[] = {"Line 2", "Rx Mix"};
170 static const char *wm8753_left_mux
[] = {"Line 1", "Rx Mix"};
171 static const char *wm8753_rxmsel
[] = {"RXP - RXN", "RXP + RXN", "RXP", "RXN"};
172 static const char *wm8753_sidetone_mux
[] = {"Left PGA", "Mic 1", "Mic 2",
174 static const char *wm8753_mono2_src
[] = {"Inverted Mono 1", "Left", "Right",
176 static const char *wm8753_out3
[] = {"VREF", "ROUT2", "Left + Right"};
177 static const char *wm8753_out4
[] = {"VREF", "Capture ST", "LOUT2"};
178 static const char *wm8753_radcsel
[] = {"PGA", "Line or RXP-RXN", "Sidetone"};
179 static const char *wm8753_ladcsel
[] = {"PGA", "Line or RXP-RXN", "Line"};
180 static const char *wm8753_mono_adc
[] = {"Stereo", "Analogue Mix Left",
181 "Analogue Mix Right", "Digital Mono Mix"};
182 static const char *wm8753_adc_hp
[] = {"3.4Hz @ 48kHz", "82Hz @ 16k",
183 "82Hz @ 8kHz", "170Hz @ 8kHz"};
184 static const char *wm8753_adc_filter
[] = {"HiFi", "Voice"};
185 static const char *wm8753_mic_sel
[] = {"Mic 1", "Mic 2", "Mic 3"};
186 static const char *wm8753_dai_mode
[] = {"DAI 0", "DAI 1", "DAI 2", "DAI 3"};
187 static const char *wm8753_dat_sel
[] = {"Stereo", "Left ADC", "Right ADC",
189 static const char *wm8753_rout2_phase
[] = {"Non Inverted", "Inverted"};
191 static const struct soc_enum wm8753_enum
[] = {
192 SOC_ENUM_SINGLE(WM8753_BASS
, 7, 2, wm8753_base
),
193 SOC_ENUM_SINGLE(WM8753_BASS
, 4, 6, wm8753_base_filter
),
194 SOC_ENUM_SINGLE(WM8753_TREBLE
, 6, 2, wm8753_treble
),
195 SOC_ENUM_SINGLE(WM8753_ALC1
, 7, 4, wm8753_alc_func
),
196 SOC_ENUM_SINGLE(WM8753_NGATE
, 1, 2, wm8753_ng_type
),
197 SOC_ENUM_SINGLE(WM8753_3D
, 7, 2, wm8753_3d_func
),
198 SOC_ENUM_SINGLE(WM8753_3D
, 6, 2, wm8753_3d_uc
),
199 SOC_ENUM_SINGLE(WM8753_3D
, 5, 2, wm8753_3d_lc
),
200 SOC_ENUM_SINGLE(WM8753_DAC
, 1, 4, wm8753_deemp
),
201 SOC_ENUM_SINGLE(WM8753_DAC
, 4, 4, wm8753_mono_mix
),
202 SOC_ENUM_SINGLE(WM8753_DAC
, 6, 2, wm8753_dac_phase
),
203 SOC_ENUM_SINGLE(WM8753_INCTL1
, 3, 4, wm8753_line_mix
),
204 SOC_ENUM_SINGLE(WM8753_INCTL1
, 2, 2, wm8753_mono_mux
),
205 SOC_ENUM_SINGLE(WM8753_INCTL1
, 1, 2, wm8753_right_mux
),
206 SOC_ENUM_SINGLE(WM8753_INCTL1
, 0, 2, wm8753_left_mux
),
207 SOC_ENUM_SINGLE(WM8753_INCTL2
, 6, 4, wm8753_rxmsel
),
208 SOC_ENUM_SINGLE(WM8753_INCTL2
, 4, 4, wm8753_sidetone_mux
),
209 SOC_ENUM_SINGLE(WM8753_OUTCTL
, 7, 4, wm8753_mono2_src
),
210 SOC_ENUM_SINGLE(WM8753_OUTCTL
, 0, 3, wm8753_out3
),
211 SOC_ENUM_SINGLE(WM8753_ADCTL2
, 7, 3, wm8753_out4
),
212 SOC_ENUM_SINGLE(WM8753_ADCIN
, 2, 3, wm8753_radcsel
),
213 SOC_ENUM_SINGLE(WM8753_ADCIN
, 0, 3, wm8753_ladcsel
),
214 SOC_ENUM_SINGLE(WM8753_ADCIN
, 4, 4, wm8753_mono_adc
),
215 SOC_ENUM_SINGLE(WM8753_ADC
, 2, 4, wm8753_adc_hp
),
216 SOC_ENUM_SINGLE(WM8753_ADC
, 4, 2, wm8753_adc_filter
),
217 SOC_ENUM_SINGLE(WM8753_MICBIAS
, 6, 3, wm8753_mic_sel
),
218 SOC_ENUM_SINGLE(WM8753_IOCTL
, 2, 4, wm8753_dai_mode
),
219 SOC_ENUM_SINGLE(WM8753_ADC
, 7, 4, wm8753_dat_sel
),
220 SOC_ENUM_SINGLE(WM8753_OUTCTL
, 2, 2, wm8753_rout2_phase
),
224 static int wm8753_get_dai(struct snd_kcontrol
*kcontrol
,
225 struct snd_ctl_elem_value
*ucontrol
)
227 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kcontrol
);
228 struct wm8753_priv
*wm8753
= snd_soc_component_get_drvdata(component
);
230 ucontrol
->value
.enumerated
.item
[0] = wm8753
->dai_func
;
234 static int wm8753_set_dai(struct snd_kcontrol
*kcontrol
,
235 struct snd_ctl_elem_value
*ucontrol
)
237 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kcontrol
);
238 struct wm8753_priv
*wm8753
= snd_soc_component_get_drvdata(component
);
241 if (wm8753
->dai_func
== ucontrol
->value
.enumerated
.item
[0])
244 if (snd_soc_component_is_active(component
))
247 ioctl
= snd_soc_component_read32(component
, WM8753_IOCTL
);
249 wm8753
->dai_func
= ucontrol
->value
.enumerated
.item
[0];
251 if (((ioctl
>> 2) & 0x3) == wm8753
->dai_func
)
254 ioctl
= (ioctl
& 0x1f3) | (wm8753
->dai_func
<< 2);
255 snd_soc_component_write(component
, WM8753_IOCTL
, ioctl
);
258 wm8753_hifi_write_dai_fmt(component
, wm8753
->hifi_fmt
);
259 wm8753_voice_write_dai_fmt(component
, wm8753
->voice_fmt
);
264 static const DECLARE_TLV_DB_SCALE(rec_mix_tlv
, -1500, 300, 0);
265 static const DECLARE_TLV_DB_SCALE(mic_preamp_tlv
, 1200, 600, 0);
266 static const DECLARE_TLV_DB_SCALE(adc_tlv
, -9750, 50, 1);
267 static const DECLARE_TLV_DB_SCALE(dac_tlv
, -12750, 50, 1);
268 static const DECLARE_TLV_DB_RANGE(out_tlv
,
269 /* 0000000 - 0101111 = "Analogue mute" */
270 0, 48, TLV_DB_SCALE_ITEM(-25500, 0, 0),
271 48, 127, TLV_DB_SCALE_ITEM(-7300, 100, 0)
273 static const DECLARE_TLV_DB_SCALE(mix_tlv
, -1500, 300, 0);
274 static const DECLARE_TLV_DB_SCALE(voice_mix_tlv
, -1200, 300, 0);
275 static const DECLARE_TLV_DB_SCALE(pga_tlv
, -1725, 75, 0);
277 static const struct snd_kcontrol_new wm8753_snd_controls
[] = {
278 SOC_SINGLE("Hi-Fi DAC Left/Right channel Swap", WM8753_HIFI
, 5, 1, 0),
279 SOC_DOUBLE_R_TLV("PCM Volume", WM8753_LDAC
, WM8753_RDAC
, 0, 255, 0, dac_tlv
),
281 SOC_DOUBLE_R_TLV("ADC Capture Volume", WM8753_LADC
, WM8753_RADC
, 0, 255, 0,
284 SOC_DOUBLE_R_TLV("Headphone Playback Volume", WM8753_LOUT1V
, WM8753_ROUT1V
,
286 SOC_DOUBLE_R_TLV("Speaker Playback Volume", WM8753_LOUT2V
, WM8753_ROUT2V
, 0,
289 SOC_SINGLE_TLV("Mono Playback Volume", WM8753_MOUTV
, 0, 127, 0, out_tlv
),
291 SOC_DOUBLE_R_TLV("Bypass Playback Volume", WM8753_LOUTM1
, WM8753_ROUTM1
, 4, 7,
293 SOC_DOUBLE_R_TLV("Sidetone Playback Volume", WM8753_LOUTM2
, WM8753_ROUTM2
, 4,
295 SOC_DOUBLE_R_TLV("Voice Playback Volume", WM8753_LOUTM2
, WM8753_ROUTM2
, 0, 7,
298 SOC_DOUBLE_R("Headphone Playback ZC Switch", WM8753_LOUT1V
, WM8753_ROUT1V
, 7,
300 SOC_DOUBLE_R("Speaker Playback ZC Switch", WM8753_LOUT2V
, WM8753_ROUT2V
, 7,
303 SOC_SINGLE_TLV("Mono Bypass Playback Volume", WM8753_MOUTM1
, 4, 7, 1, mix_tlv
),
304 SOC_SINGLE_TLV("Mono Sidetone Playback Volume", WM8753_MOUTM2
, 4, 7, 1,
306 SOC_SINGLE_TLV("Mono Voice Playback Volume", WM8753_MOUTM2
, 0, 7, 1,
308 SOC_SINGLE("Mono Playback ZC Switch", WM8753_MOUTV
, 7, 1, 0),
310 SOC_ENUM("Bass Boost", wm8753_enum
[0]),
311 SOC_ENUM("Bass Filter", wm8753_enum
[1]),
312 SOC_SINGLE("Bass Volume", WM8753_BASS
, 0, 15, 1),
314 SOC_SINGLE("Treble Volume", WM8753_TREBLE
, 0, 15, 1),
315 SOC_ENUM("Treble Cut-off", wm8753_enum
[2]),
317 SOC_DOUBLE_TLV("Sidetone Capture Volume", WM8753_RECMIX1
, 0, 4, 7, 1,
319 SOC_SINGLE_TLV("Voice Sidetone Capture Volume", WM8753_RECMIX2
, 0, 7, 1,
322 SOC_DOUBLE_R_TLV("Capture Volume", WM8753_LINVOL
, WM8753_RINVOL
, 0, 63, 0,
324 SOC_DOUBLE_R("Capture ZC Switch", WM8753_LINVOL
, WM8753_RINVOL
, 6, 1, 0),
325 SOC_DOUBLE_R("Capture Switch", WM8753_LINVOL
, WM8753_RINVOL
, 7, 1, 1),
327 SOC_ENUM("Capture Filter Select", wm8753_enum
[23]),
328 SOC_ENUM("Capture Filter Cut-off", wm8753_enum
[24]),
329 SOC_SINGLE("Capture Filter Switch", WM8753_ADC
, 0, 1, 1),
331 SOC_SINGLE("ALC Capture Target Volume", WM8753_ALC1
, 0, 7, 0),
332 SOC_SINGLE("ALC Capture Max Volume", WM8753_ALC1
, 4, 7, 0),
333 SOC_ENUM("ALC Capture Function", wm8753_enum
[3]),
334 SOC_SINGLE("ALC Capture ZC Switch", WM8753_ALC2
, 8, 1, 0),
335 SOC_SINGLE("ALC Capture Hold Time", WM8753_ALC2
, 0, 15, 1),
336 SOC_SINGLE("ALC Capture Decay Time", WM8753_ALC3
, 4, 15, 1),
337 SOC_SINGLE("ALC Capture Attack Time", WM8753_ALC3
, 0, 15, 0),
338 SOC_SINGLE("ALC Capture NG Threshold", WM8753_NGATE
, 3, 31, 0),
339 SOC_ENUM("ALC Capture NG Type", wm8753_enum
[4]),
340 SOC_SINGLE("ALC Capture NG Switch", WM8753_NGATE
, 0, 1, 0),
342 SOC_ENUM("3D Function", wm8753_enum
[5]),
343 SOC_ENUM("3D Upper Cut-off", wm8753_enum
[6]),
344 SOC_ENUM("3D Lower Cut-off", wm8753_enum
[7]),
345 SOC_SINGLE("3D Volume", WM8753_3D
, 1, 15, 0),
346 SOC_SINGLE("3D Switch", WM8753_3D
, 0, 1, 0),
348 SOC_SINGLE("Capture 6dB Attenuate", WM8753_ADCTL1
, 2, 1, 0),
349 SOC_SINGLE("Playback 6dB Attenuate", WM8753_ADCTL1
, 1, 1, 0),
351 SOC_ENUM("De-emphasis", wm8753_enum
[8]),
352 SOC_ENUM("Playback Mono Mix", wm8753_enum
[9]),
353 SOC_ENUM("Playback Phase", wm8753_enum
[10]),
355 SOC_SINGLE_TLV("Mic2 Capture Volume", WM8753_INCTL1
, 7, 3, 0, mic_preamp_tlv
),
356 SOC_SINGLE_TLV("Mic1 Capture Volume", WM8753_INCTL1
, 5, 3, 0, mic_preamp_tlv
),
358 SOC_ENUM_EXT("DAI Mode", wm8753_enum
[26], wm8753_get_dai
, wm8753_set_dai
),
360 SOC_ENUM("ADC Data Select", wm8753_enum
[27]),
361 SOC_ENUM("ROUT2 Phase", wm8753_enum
[28]),
369 static const struct snd_kcontrol_new wm8753_left_mixer_controls
[] = {
370 SOC_DAPM_SINGLE("Voice Playback Switch", WM8753_LOUTM2
, 8, 1, 0),
371 SOC_DAPM_SINGLE("Sidetone Playback Switch", WM8753_LOUTM2
, 7, 1, 0),
372 SOC_DAPM_SINGLE("Left Playback Switch", WM8753_LOUTM1
, 8, 1, 0),
373 SOC_DAPM_SINGLE("Bypass Playback Switch", WM8753_LOUTM1
, 7, 1, 0),
377 static const struct snd_kcontrol_new wm8753_right_mixer_controls
[] = {
378 SOC_DAPM_SINGLE("Voice Playback Switch", WM8753_ROUTM2
, 8, 1, 0),
379 SOC_DAPM_SINGLE("Sidetone Playback Switch", WM8753_ROUTM2
, 7, 1, 0),
380 SOC_DAPM_SINGLE("Right Playback Switch", WM8753_ROUTM1
, 8, 1, 0),
381 SOC_DAPM_SINGLE("Bypass Playback Switch", WM8753_ROUTM1
, 7, 1, 0),
385 static const struct snd_kcontrol_new wm8753_mono_mixer_controls
[] = {
386 SOC_DAPM_SINGLE("Left Playback Switch", WM8753_MOUTM1
, 8, 1, 0),
387 SOC_DAPM_SINGLE("Right Playback Switch", WM8753_MOUTM2
, 8, 1, 0),
388 SOC_DAPM_SINGLE("Voice Playback Switch", WM8753_MOUTM2
, 3, 1, 0),
389 SOC_DAPM_SINGLE("Sidetone Playback Switch", WM8753_MOUTM2
, 7, 1, 0),
390 SOC_DAPM_SINGLE("Bypass Playback Switch", WM8753_MOUTM1
, 7, 1, 0),
394 static const struct snd_kcontrol_new wm8753_mono2_controls
=
395 SOC_DAPM_ENUM("Route", wm8753_enum
[17]);
398 static const struct snd_kcontrol_new wm8753_out3_controls
=
399 SOC_DAPM_ENUM("Route", wm8753_enum
[18]);
402 static const struct snd_kcontrol_new wm8753_out4_controls
=
403 SOC_DAPM_ENUM("Route", wm8753_enum
[19]);
406 static const struct snd_kcontrol_new wm8753_adc_mono_controls
=
407 SOC_DAPM_ENUM("Route", wm8753_enum
[22]);
410 static const struct snd_kcontrol_new wm8753_record_mixer_controls
[] = {
411 SOC_DAPM_SINGLE("Voice Capture Switch", WM8753_RECMIX2
, 3, 1, 0),
412 SOC_DAPM_SINGLE("Left Capture Switch", WM8753_RECMIX1
, 3, 1, 0),
413 SOC_DAPM_SINGLE("Right Capture Switch", WM8753_RECMIX1
, 7, 1, 0),
417 static const struct snd_kcontrol_new wm8753_adc_left_controls
=
418 SOC_DAPM_ENUM("Route", wm8753_enum
[21]);
421 static const struct snd_kcontrol_new wm8753_adc_right_controls
=
422 SOC_DAPM_ENUM("Route", wm8753_enum
[20]);
425 static const struct snd_kcontrol_new wm8753_mic_mux_controls
=
426 SOC_DAPM_ENUM("Route", wm8753_enum
[16]);
429 static const struct snd_kcontrol_new wm8753_alc_mixer_controls
[] = {
430 SOC_DAPM_SINGLE("Line Capture Switch", WM8753_INCTL2
, 3, 1, 0),
431 SOC_DAPM_SINGLE("Mic2 Capture Switch", WM8753_INCTL2
, 2, 1, 0),
432 SOC_DAPM_SINGLE("Mic1 Capture Switch", WM8753_INCTL2
, 1, 1, 0),
433 SOC_DAPM_SINGLE("Rx Capture Switch", WM8753_INCTL2
, 0, 1, 0),
437 static const struct snd_kcontrol_new wm8753_line_left_controls
=
438 SOC_DAPM_ENUM("Route", wm8753_enum
[14]);
441 static const struct snd_kcontrol_new wm8753_line_right_controls
=
442 SOC_DAPM_ENUM("Route", wm8753_enum
[13]);
445 static const struct snd_kcontrol_new wm8753_line_mono_controls
=
446 SOC_DAPM_ENUM("Route", wm8753_enum
[12]);
448 /* Line mux and mixer */
449 static const struct snd_kcontrol_new wm8753_line_mux_mix_controls
=
450 SOC_DAPM_ENUM("Route", wm8753_enum
[11]);
452 /* Rx mux and mixer */
453 static const struct snd_kcontrol_new wm8753_rx_mux_mix_controls
=
454 SOC_DAPM_ENUM("Route", wm8753_enum
[15]);
456 /* Mic Selector Mux */
457 static const struct snd_kcontrol_new wm8753_mic_sel_mux_controls
=
458 SOC_DAPM_ENUM("Route", wm8753_enum
[25]);
460 static const struct snd_soc_dapm_widget wm8753_dapm_widgets
[] = {
461 SND_SOC_DAPM_MICBIAS("Mic Bias", WM8753_PWR1
, 5, 0),
462 SND_SOC_DAPM_MIXER("Left Mixer", WM8753_PWR4
, 0, 0,
463 &wm8753_left_mixer_controls
[0], ARRAY_SIZE(wm8753_left_mixer_controls
)),
464 SND_SOC_DAPM_PGA("Left Out 1", WM8753_PWR3
, 8, 0, NULL
, 0),
465 SND_SOC_DAPM_PGA("Left Out 2", WM8753_PWR3
, 6, 0, NULL
, 0),
466 SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", WM8753_PWR1
, 3, 0),
467 SND_SOC_DAPM_OUTPUT("LOUT1"),
468 SND_SOC_DAPM_OUTPUT("LOUT2"),
469 SND_SOC_DAPM_MIXER("Right Mixer", WM8753_PWR4
, 1, 0,
470 &wm8753_right_mixer_controls
[0], ARRAY_SIZE(wm8753_right_mixer_controls
)),
471 SND_SOC_DAPM_PGA("Right Out 1", WM8753_PWR3
, 7, 0, NULL
, 0),
472 SND_SOC_DAPM_PGA("Right Out 2", WM8753_PWR3
, 5, 0, NULL
, 0),
473 SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", WM8753_PWR1
, 2, 0),
474 SND_SOC_DAPM_OUTPUT("ROUT1"),
475 SND_SOC_DAPM_OUTPUT("ROUT2"),
476 SND_SOC_DAPM_MIXER("Mono Mixer", WM8753_PWR4
, 2, 0,
477 &wm8753_mono_mixer_controls
[0], ARRAY_SIZE(wm8753_mono_mixer_controls
)),
478 SND_SOC_DAPM_PGA("Mono Out 1", WM8753_PWR3
, 2, 0, NULL
, 0),
479 SND_SOC_DAPM_PGA("Mono Out 2", WM8753_PWR3
, 1, 0, NULL
, 0),
480 SND_SOC_DAPM_DAC("Voice DAC", "Voice Playback", WM8753_PWR1
, 4, 0),
481 SND_SOC_DAPM_OUTPUT("MONO1"),
482 SND_SOC_DAPM_MUX("Mono 2 Mux", SND_SOC_NOPM
, 0, 0, &wm8753_mono2_controls
),
483 SND_SOC_DAPM_OUTPUT("MONO2"),
484 SND_SOC_DAPM_MIXER("Out3 Left + Right", SND_SOC_NOPM
, 0, 0, NULL
, 0),
485 SND_SOC_DAPM_MUX("Out3 Mux", SND_SOC_NOPM
, 0, 0, &wm8753_out3_controls
),
486 SND_SOC_DAPM_PGA("Out 3", WM8753_PWR3
, 4, 0, NULL
, 0),
487 SND_SOC_DAPM_OUTPUT("OUT3"),
488 SND_SOC_DAPM_MUX("Out4 Mux", SND_SOC_NOPM
, 0, 0, &wm8753_out4_controls
),
489 SND_SOC_DAPM_PGA("Out 4", WM8753_PWR3
, 3, 0, NULL
, 0),
490 SND_SOC_DAPM_OUTPUT("OUT4"),
491 SND_SOC_DAPM_MIXER("Playback Mixer", WM8753_PWR4
, 3, 0,
492 &wm8753_record_mixer_controls
[0],
493 ARRAY_SIZE(wm8753_record_mixer_controls
)),
494 SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8753_PWR2
, 3, 0),
495 SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8753_PWR2
, 2, 0),
496 SND_SOC_DAPM_MUX("Capture Left Mixer", SND_SOC_NOPM
, 0, 0,
497 &wm8753_adc_mono_controls
),
498 SND_SOC_DAPM_MUX("Capture Right Mixer", SND_SOC_NOPM
, 0, 0,
499 &wm8753_adc_mono_controls
),
500 SND_SOC_DAPM_MUX("Capture Left Mux", SND_SOC_NOPM
, 0, 0,
501 &wm8753_adc_left_controls
),
502 SND_SOC_DAPM_MUX("Capture Right Mux", SND_SOC_NOPM
, 0, 0,
503 &wm8753_adc_right_controls
),
504 SND_SOC_DAPM_MUX("Mic Sidetone Mux", SND_SOC_NOPM
, 0, 0,
505 &wm8753_mic_mux_controls
),
506 SND_SOC_DAPM_PGA("Left Capture Volume", WM8753_PWR2
, 5, 0, NULL
, 0),
507 SND_SOC_DAPM_PGA("Right Capture Volume", WM8753_PWR2
, 4, 0, NULL
, 0),
508 SND_SOC_DAPM_MIXER("ALC Mixer", WM8753_PWR2
, 6, 0,
509 &wm8753_alc_mixer_controls
[0], ARRAY_SIZE(wm8753_alc_mixer_controls
)),
510 SND_SOC_DAPM_MUX("Line Left Mux", SND_SOC_NOPM
, 0, 0,
511 &wm8753_line_left_controls
),
512 SND_SOC_DAPM_MUX("Line Right Mux", SND_SOC_NOPM
, 0, 0,
513 &wm8753_line_right_controls
),
514 SND_SOC_DAPM_MUX("Line Mono Mux", SND_SOC_NOPM
, 0, 0,
515 &wm8753_line_mono_controls
),
516 SND_SOC_DAPM_MUX("Line Mixer", WM8753_PWR2
, 0, 0,
517 &wm8753_line_mux_mix_controls
),
518 SND_SOC_DAPM_MUX("Rx Mixer", WM8753_PWR2
, 1, 0,
519 &wm8753_rx_mux_mix_controls
),
520 SND_SOC_DAPM_PGA("Mic 1 Volume", WM8753_PWR2
, 8, 0, NULL
, 0),
521 SND_SOC_DAPM_PGA("Mic 2 Volume", WM8753_PWR2
, 7, 0, NULL
, 0),
522 SND_SOC_DAPM_MUX("Mic Selection Mux", SND_SOC_NOPM
, 0, 0,
523 &wm8753_mic_sel_mux_controls
),
524 SND_SOC_DAPM_INPUT("LINE1"),
525 SND_SOC_DAPM_INPUT("LINE2"),
526 SND_SOC_DAPM_INPUT("RXP"),
527 SND_SOC_DAPM_INPUT("RXN"),
528 SND_SOC_DAPM_INPUT("ACIN"),
529 SND_SOC_DAPM_OUTPUT("ACOP"),
530 SND_SOC_DAPM_INPUT("MIC1N"),
531 SND_SOC_DAPM_INPUT("MIC1"),
532 SND_SOC_DAPM_INPUT("MIC2N"),
533 SND_SOC_DAPM_INPUT("MIC2"),
534 SND_SOC_DAPM_VMID("VREF"),
537 static const struct snd_soc_dapm_route wm8753_dapm_routes
[] = {
539 {"Left Mixer", "Left Playback Switch", "Left DAC"},
540 {"Left Mixer", "Voice Playback Switch", "Voice DAC"},
541 {"Left Mixer", "Sidetone Playback Switch", "Mic Sidetone Mux"},
542 {"Left Mixer", "Bypass Playback Switch", "Line Left Mux"},
545 {"Right Mixer", "Right Playback Switch", "Right DAC"},
546 {"Right Mixer", "Voice Playback Switch", "Voice DAC"},
547 {"Right Mixer", "Sidetone Playback Switch", "Mic Sidetone Mux"},
548 {"Right Mixer", "Bypass Playback Switch", "Line Right Mux"},
551 {"Mono Mixer", "Voice Playback Switch", "Voice DAC"},
552 {"Mono Mixer", "Left Playback Switch", "Left DAC"},
553 {"Mono Mixer", "Right Playback Switch", "Right DAC"},
554 {"Mono Mixer", "Sidetone Playback Switch", "Mic Sidetone Mux"},
555 {"Mono Mixer", "Bypass Playback Switch", "Line Mono Mux"},
558 {"Left Out 1", NULL
, "Left Mixer"},
559 {"Left Out 2", NULL
, "Left Mixer"},
560 {"LOUT1", NULL
, "Left Out 1"},
561 {"LOUT2", NULL
, "Left Out 2"},
564 {"Right Out 1", NULL
, "Right Mixer"},
565 {"Right Out 2", NULL
, "Right Mixer"},
566 {"ROUT1", NULL
, "Right Out 1"},
567 {"ROUT2", NULL
, "Right Out 2"},
570 {"Mono Out 1", NULL
, "Mono Mixer"},
571 {"MONO1", NULL
, "Mono Out 1"},
574 {"Mono 2 Mux", "Left + Right", "Out3 Left + Right"},
575 {"Mono 2 Mux", "Inverted Mono 1", "MONO1"},
576 {"Mono 2 Mux", "Left", "Left Mixer"},
577 {"Mono 2 Mux", "Right", "Right Mixer"},
578 {"Mono Out 2", NULL
, "Mono 2 Mux"},
579 {"MONO2", NULL
, "Mono Out 2"},
582 {"Out3 Left + Right", NULL
, "Left Mixer"},
583 {"Out3 Left + Right", NULL
, "Right Mixer"},
584 {"Out3 Mux", "VREF", "VREF"},
585 {"Out3 Mux", "Left + Right", "Out3 Left + Right"},
586 {"Out3 Mux", "ROUT2", "ROUT2"},
587 {"Out 3", NULL
, "Out3 Mux"},
588 {"OUT3", NULL
, "Out 3"},
591 {"Out4 Mux", "VREF", "VREF"},
592 {"Out4 Mux", "Capture ST", "Playback Mixer"},
593 {"Out4 Mux", "LOUT2", "LOUT2"},
594 {"Out 4", NULL
, "Out4 Mux"},
595 {"OUT4", NULL
, "Out 4"},
598 {"Playback Mixer", "Left Capture Switch", "Left Mixer"},
599 {"Playback Mixer", "Voice Capture Switch", "Mono Mixer"},
600 {"Playback Mixer", "Right Capture Switch", "Right Mixer"},
602 /* Mic/SideTone Mux */
603 {"Mic Sidetone Mux", "Left PGA", "Left Capture Volume"},
604 {"Mic Sidetone Mux", "Right PGA", "Right Capture Volume"},
605 {"Mic Sidetone Mux", "Mic 1", "Mic 1 Volume"},
606 {"Mic Sidetone Mux", "Mic 2", "Mic 2 Volume"},
608 /* Capture Left Mux */
609 {"Capture Left Mux", "PGA", "Left Capture Volume"},
610 {"Capture Left Mux", "Line or RXP-RXN", "Line Left Mux"},
611 {"Capture Left Mux", "Line", "LINE1"},
613 /* Capture Right Mux */
614 {"Capture Right Mux", "PGA", "Right Capture Volume"},
615 {"Capture Right Mux", "Line or RXP-RXN", "Line Right Mux"},
616 {"Capture Right Mux", "Sidetone", "Playback Mixer"},
618 /* Mono Capture mixer-mux */
619 {"Capture Right Mixer", "Stereo", "Capture Right Mux"},
620 {"Capture Left Mixer", "Stereo", "Capture Left Mux"},
621 {"Capture Left Mixer", "Analogue Mix Left", "Capture Left Mux"},
622 {"Capture Left Mixer", "Analogue Mix Left", "Capture Right Mux"},
623 {"Capture Right Mixer", "Analogue Mix Right", "Capture Left Mux"},
624 {"Capture Right Mixer", "Analogue Mix Right", "Capture Right Mux"},
625 {"Capture Left Mixer", "Digital Mono Mix", "Capture Left Mux"},
626 {"Capture Left Mixer", "Digital Mono Mix", "Capture Right Mux"},
627 {"Capture Right Mixer", "Digital Mono Mix", "Capture Left Mux"},
628 {"Capture Right Mixer", "Digital Mono Mix", "Capture Right Mux"},
631 {"Left ADC", NULL
, "Capture Left Mixer"},
632 {"Right ADC", NULL
, "Capture Right Mixer"},
634 /* Left Capture Volume */
635 {"Left Capture Volume", NULL
, "ACIN"},
637 /* Right Capture Volume */
638 {"Right Capture Volume", NULL
, "Mic 2 Volume"},
641 {"ALC Mixer", "Line Capture Switch", "Line Mixer"},
642 {"ALC Mixer", "Mic2 Capture Switch", "Mic 2 Volume"},
643 {"ALC Mixer", "Mic1 Capture Switch", "Mic 1 Volume"},
644 {"ALC Mixer", "Rx Capture Switch", "Rx Mixer"},
647 {"Line Left Mux", "Line 1", "LINE1"},
648 {"Line Left Mux", "Rx Mix", "Rx Mixer"},
651 {"Line Right Mux", "Line 2", "LINE2"},
652 {"Line Right Mux", "Rx Mix", "Rx Mixer"},
655 {"Line Mono Mux", "Line Mix", "Line Mixer"},
656 {"Line Mono Mux", "Rx Mix", "Rx Mixer"},
659 {"Line Mixer", "Line 1 + 2", "LINE1"},
660 {"Line Mixer", "Line 1 - 2", "LINE1"},
661 {"Line Mixer", "Line 1 + 2", "LINE2"},
662 {"Line Mixer", "Line 1 - 2", "LINE2"},
663 {"Line Mixer", "Line 1", "LINE1"},
664 {"Line Mixer", "Line 2", "LINE2"},
667 {"Rx Mixer", "RXP - RXN", "RXP"},
668 {"Rx Mixer", "RXP + RXN", "RXP"},
669 {"Rx Mixer", "RXP - RXN", "RXN"},
670 {"Rx Mixer", "RXP + RXN", "RXN"},
671 {"Rx Mixer", "RXP", "RXP"},
672 {"Rx Mixer", "RXN", "RXN"},
675 {"Mic 1 Volume", NULL
, "MIC1N"},
676 {"Mic 1 Volume", NULL
, "Mic Selection Mux"},
679 {"Mic 2 Volume", NULL
, "MIC2N"},
680 {"Mic 2 Volume", NULL
, "MIC2"},
682 /* Mic Selector Mux */
683 {"Mic Selection Mux", "Mic 1", "MIC1"},
684 {"Mic Selection Mux", "Mic 2", "MIC2N"},
685 {"Mic Selection Mux", "Mic 3", "MIC2"},
688 {"ACOP", NULL
, "ALC Mixer"},
698 /* The size in bits of the pll divide multiplied by 10
699 * to allow rounding later */
700 #define FIXED_PLL_SIZE ((1 << 22) * 10)
702 static void pll_factors(struct _pll_div
*pll_div
, unsigned int target
,
706 unsigned int K
, Ndiv
, Nmod
;
708 Ndiv
= target
/ source
;
712 Ndiv
= target
/ source
;
716 if ((Ndiv
< 6) || (Ndiv
> 12))
718 "wm8753: unsupported N = %u\n", Ndiv
);
721 Nmod
= target
% source
;
722 Kpart
= FIXED_PLL_SIZE
* (long long)Nmod
;
724 do_div(Kpart
, source
);
726 K
= Kpart
& 0xFFFFFFFF;
728 /* Check if we need to round */
732 /* Move down to proper range now rounding is done */
738 static int wm8753_set_dai_pll(struct snd_soc_dai
*codec_dai
, int pll_id
,
739 int source
, unsigned int freq_in
, unsigned int freq_out
)
743 struct snd_soc_component
*component
= codec_dai
->component
;
745 if (pll_id
< WM8753_PLL1
|| pll_id
> WM8753_PLL2
)
748 if (pll_id
== WM8753_PLL1
) {
751 reg
= snd_soc_component_read32(component
, WM8753_CLOCK
) & 0xffef;
755 reg
= snd_soc_component_read32(component
, WM8753_CLOCK
) & 0xfff7;
758 if (!freq_in
|| !freq_out
) {
760 snd_soc_component_write(component
, WM8753_PLL1CTL1
+ offset
, 0x0026);
761 snd_soc_component_write(component
, WM8753_CLOCK
, reg
);
765 struct _pll_div pll_div
;
767 pll_factors(&pll_div
, freq_out
* 8, freq_in
);
769 /* set up N and K PLL divisor ratios */
770 /* bits 8:5 = PLL_N, bits 3:0 = PLL_K[21:18] */
771 value
= (pll_div
.n
<< 5) + ((pll_div
.k
& 0x3c0000) >> 18);
772 snd_soc_component_write(component
, WM8753_PLL1CTL2
+ offset
, value
);
774 /* bits 8:0 = PLL_K[17:9] */
775 value
= (pll_div
.k
& 0x03fe00) >> 9;
776 snd_soc_component_write(component
, WM8753_PLL1CTL3
+ offset
, value
);
778 /* bits 8:0 = PLL_K[8:0] */
779 value
= pll_div
.k
& 0x0001ff;
780 snd_soc_component_write(component
, WM8753_PLL1CTL4
+ offset
, value
);
782 /* set PLL as input and enable */
783 snd_soc_component_write(component
, WM8753_PLL1CTL1
+ offset
, 0x0027 |
784 (pll_div
.div2
<< 3));
785 snd_soc_component_write(component
, WM8753_CLOCK
, reg
| enable
);
797 /* codec hifi mclk (after PLL) clock divider coefficients */
798 static const struct _coeff_div coeff_div
[] = {
800 {12288000, 8000, 0x6, 0x0},
801 {11289600, 8000, 0x16, 0x0},
802 {18432000, 8000, 0x7, 0x0},
803 {16934400, 8000, 0x17, 0x0},
804 {12000000, 8000, 0x6, 0x1},
807 {11289600, 11025, 0x18, 0x0},
808 {16934400, 11025, 0x19, 0x0},
809 {12000000, 11025, 0x19, 0x1},
812 {12288000, 16000, 0xa, 0x0},
813 {18432000, 16000, 0xb, 0x0},
814 {12000000, 16000, 0xa, 0x1},
817 {11289600, 22050, 0x1a, 0x0},
818 {16934400, 22050, 0x1b, 0x0},
819 {12000000, 22050, 0x1b, 0x1},
822 {12288000, 32000, 0xc, 0x0},
823 {18432000, 32000, 0xd, 0x0},
824 {12000000, 32000, 0xa, 0x1},
827 {11289600, 44100, 0x10, 0x0},
828 {16934400, 44100, 0x11, 0x0},
829 {12000000, 44100, 0x11, 0x1},
832 {12288000, 48000, 0x0, 0x0},
833 {18432000, 48000, 0x1, 0x0},
834 {12000000, 48000, 0x0, 0x1},
837 {11289600, 88200, 0x1e, 0x0},
838 {16934400, 88200, 0x1f, 0x0},
839 {12000000, 88200, 0x1f, 0x1},
842 {12288000, 96000, 0xe, 0x0},
843 {18432000, 96000, 0xf, 0x0},
844 {12000000, 96000, 0xe, 0x1},
847 static int get_coeff(int mclk
, int rate
)
851 for (i
= 0; i
< ARRAY_SIZE(coeff_div
); i
++) {
852 if (coeff_div
[i
].rate
== rate
&& coeff_div
[i
].mclk
== mclk
)
859 * Clock after PLL and dividers
861 static int wm8753_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
862 int clk_id
, unsigned int freq
, int dir
)
864 struct snd_soc_component
*component
= codec_dai
->component
;
865 struct wm8753_priv
*wm8753
= snd_soc_component_get_drvdata(component
);
873 if (clk_id
== WM8753_MCLK
) {
874 wm8753
->sysclk
= freq
;
876 } else if (clk_id
== WM8753_PCMCLK
) {
877 wm8753
->pcmclk
= freq
;
886 * Set's ADC and Voice DAC format.
888 static int wm8753_vdac_adc_set_dai_fmt(struct snd_soc_component
*component
,
891 u16 voice
= snd_soc_component_read32(component
, WM8753_PCM
) & 0x01ec;
893 /* interface format */
894 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
895 case SND_SOC_DAIFMT_I2S
:
898 case SND_SOC_DAIFMT_RIGHT_J
:
900 case SND_SOC_DAIFMT_LEFT_J
:
903 case SND_SOC_DAIFMT_DSP_A
:
906 case SND_SOC_DAIFMT_DSP_B
:
913 snd_soc_component_write(component
, WM8753_PCM
, voice
);
918 * Set PCM DAI bit size and sample rate.
920 static int wm8753_pcm_hw_params(struct snd_pcm_substream
*substream
,
921 struct snd_pcm_hw_params
*params
,
922 struct snd_soc_dai
*dai
)
924 struct snd_soc_component
*component
= dai
->component
;
925 struct wm8753_priv
*wm8753
= snd_soc_component_get_drvdata(component
);
926 u16 voice
= snd_soc_component_read32(component
, WM8753_PCM
) & 0x01f3;
927 u16 srate
= snd_soc_component_read32(component
, WM8753_SRATE1
) & 0x017f;
930 switch (params_width(params
)) {
945 if (params_rate(params
) * 384 == wm8753
->pcmclk
)
947 snd_soc_component_write(component
, WM8753_SRATE1
, srate
);
949 snd_soc_component_write(component
, WM8753_PCM
, voice
);
954 * Set's PCM dai fmt and BCLK.
956 static int wm8753_pcm_set_dai_fmt(struct snd_soc_component
*component
,
961 voice
= snd_soc_component_read32(component
, WM8753_PCM
) & 0x011f;
962 ioctl
= snd_soc_component_read32(component
, WM8753_IOCTL
) & 0x015d;
964 /* set master/slave audio interface */
965 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
966 case SND_SOC_DAIFMT_CBS_CFS
:
968 case SND_SOC_DAIFMT_CBM_CFM
:
969 ioctl
|= 0x2; /* fall through */
970 case SND_SOC_DAIFMT_CBM_CFS
:
977 /* clock inversion */
978 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
979 case SND_SOC_DAIFMT_DSP_A
:
980 case SND_SOC_DAIFMT_DSP_B
:
981 /* frame inversion not valid for DSP modes */
982 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
983 case SND_SOC_DAIFMT_NB_NF
:
985 case SND_SOC_DAIFMT_IB_NF
:
992 case SND_SOC_DAIFMT_I2S
:
993 case SND_SOC_DAIFMT_RIGHT_J
:
994 case SND_SOC_DAIFMT_LEFT_J
:
996 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
997 case SND_SOC_DAIFMT_NB_NF
:
999 case SND_SOC_DAIFMT_IB_IF
:
1002 case SND_SOC_DAIFMT_IB_NF
:
1005 case SND_SOC_DAIFMT_NB_IF
:
1016 snd_soc_component_write(component
, WM8753_PCM
, voice
);
1017 snd_soc_component_write(component
, WM8753_IOCTL
, ioctl
);
1021 static int wm8753_set_dai_clkdiv(struct snd_soc_dai
*codec_dai
,
1022 int div_id
, int div
)
1024 struct snd_soc_component
*component
= codec_dai
->component
;
1029 reg
= snd_soc_component_read32(component
, WM8753_CLOCK
) & 0x003f;
1030 snd_soc_component_write(component
, WM8753_CLOCK
, reg
| div
);
1032 case WM8753_BCLKDIV
:
1033 reg
= snd_soc_component_read32(component
, WM8753_SRATE2
) & 0x01c7;
1034 snd_soc_component_write(component
, WM8753_SRATE2
, reg
| div
);
1036 case WM8753_VXCLKDIV
:
1037 reg
= snd_soc_component_read32(component
, WM8753_SRATE2
) & 0x003f;
1038 snd_soc_component_write(component
, WM8753_SRATE2
, reg
| div
);
1047 * Set's HiFi DAC format.
1049 static int wm8753_hdac_set_dai_fmt(struct snd_soc_component
*component
,
1052 u16 hifi
= snd_soc_component_read32(component
, WM8753_HIFI
) & 0x01e0;
1054 /* interface format */
1055 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1056 case SND_SOC_DAIFMT_I2S
:
1059 case SND_SOC_DAIFMT_RIGHT_J
:
1061 case SND_SOC_DAIFMT_LEFT_J
:
1064 case SND_SOC_DAIFMT_DSP_A
:
1067 case SND_SOC_DAIFMT_DSP_B
:
1074 snd_soc_component_write(component
, WM8753_HIFI
, hifi
);
1079 * Set's I2S DAI format.
1081 static int wm8753_i2s_set_dai_fmt(struct snd_soc_component
*component
,
1086 hifi
= snd_soc_component_read32(component
, WM8753_HIFI
) & 0x013f;
1087 ioctl
= snd_soc_component_read32(component
, WM8753_IOCTL
) & 0x00ae;
1089 /* set master/slave audio interface */
1090 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1091 case SND_SOC_DAIFMT_CBS_CFS
:
1093 case SND_SOC_DAIFMT_CBM_CFM
:
1094 ioctl
|= 0x1; /* fall through */
1095 case SND_SOC_DAIFMT_CBM_CFS
:
1102 /* clock inversion */
1103 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1104 case SND_SOC_DAIFMT_DSP_A
:
1105 case SND_SOC_DAIFMT_DSP_B
:
1106 /* frame inversion not valid for DSP modes */
1107 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1108 case SND_SOC_DAIFMT_NB_NF
:
1110 case SND_SOC_DAIFMT_IB_NF
:
1117 case SND_SOC_DAIFMT_I2S
:
1118 case SND_SOC_DAIFMT_RIGHT_J
:
1119 case SND_SOC_DAIFMT_LEFT_J
:
1121 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1122 case SND_SOC_DAIFMT_NB_NF
:
1124 case SND_SOC_DAIFMT_IB_IF
:
1127 case SND_SOC_DAIFMT_IB_NF
:
1130 case SND_SOC_DAIFMT_NB_IF
:
1141 snd_soc_component_write(component
, WM8753_HIFI
, hifi
);
1142 snd_soc_component_write(component
, WM8753_IOCTL
, ioctl
);
1147 * Set PCM DAI bit size and sample rate.
1149 static int wm8753_i2s_hw_params(struct snd_pcm_substream
*substream
,
1150 struct snd_pcm_hw_params
*params
,
1151 struct snd_soc_dai
*dai
)
1153 struct snd_soc_component
*component
= dai
->component
;
1154 struct wm8753_priv
*wm8753
= snd_soc_component_get_drvdata(component
);
1155 u16 srate
= snd_soc_component_read32(component
, WM8753_SRATE1
) & 0x01c0;
1156 u16 hifi
= snd_soc_component_read32(component
, WM8753_HIFI
) & 0x01f3;
1159 /* is digital filter coefficient valid ? */
1160 coeff
= get_coeff(wm8753
->sysclk
, params_rate(params
));
1162 printk(KERN_ERR
"wm8753 invalid MCLK or rate\n");
1165 snd_soc_component_write(component
, WM8753_SRATE1
, srate
| (coeff_div
[coeff
].sr
<< 1) |
1166 coeff_div
[coeff
].usb
);
1169 switch (params_width(params
)) {
1183 snd_soc_component_write(component
, WM8753_HIFI
, hifi
);
1187 static int wm8753_mode1v_set_dai_fmt(struct snd_soc_component
*component
,
1192 /* set clk source as pcmclk */
1193 clock
= snd_soc_component_read32(component
, WM8753_CLOCK
) & 0xfffb;
1194 snd_soc_component_write(component
, WM8753_CLOCK
, clock
);
1196 return wm8753_vdac_adc_set_dai_fmt(component
, fmt
);
1199 static int wm8753_mode1h_set_dai_fmt(struct snd_soc_component
*component
,
1202 return wm8753_hdac_set_dai_fmt(component
, fmt
);
1205 static int wm8753_mode2_set_dai_fmt(struct snd_soc_component
*component
,
1210 /* set clk source as pcmclk */
1211 clock
= snd_soc_component_read32(component
, WM8753_CLOCK
) & 0xfffb;
1212 snd_soc_component_write(component
, WM8753_CLOCK
, clock
);
1214 return wm8753_vdac_adc_set_dai_fmt(component
, fmt
);
1217 static int wm8753_mode3_4_set_dai_fmt(struct snd_soc_component
*component
,
1222 /* set clk source as mclk */
1223 clock
= snd_soc_component_read32(component
, WM8753_CLOCK
) & 0xfffb;
1224 snd_soc_component_write(component
, WM8753_CLOCK
, clock
| 0x4);
1226 if (wm8753_hdac_set_dai_fmt(component
, fmt
) < 0)
1228 return wm8753_vdac_adc_set_dai_fmt(component
, fmt
);
1231 static int wm8753_hifi_write_dai_fmt(struct snd_soc_component
*component
,
1234 struct wm8753_priv
*wm8753
= snd_soc_component_get_drvdata(component
);
1237 switch (wm8753
->dai_func
) {
1239 ret
= wm8753_mode1h_set_dai_fmt(component
, fmt
);
1242 ret
= wm8753_mode2_set_dai_fmt(component
, fmt
);
1246 ret
= wm8753_mode3_4_set_dai_fmt(component
, fmt
);
1254 return wm8753_i2s_set_dai_fmt(component
, fmt
);
1257 static int wm8753_hifi_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
1260 struct snd_soc_component
*component
= codec_dai
->component
;
1261 struct wm8753_priv
*wm8753
= snd_soc_component_get_drvdata(component
);
1263 wm8753
->hifi_fmt
= fmt
;
1265 return wm8753_hifi_write_dai_fmt(component
, fmt
);
1268 static int wm8753_voice_write_dai_fmt(struct snd_soc_component
*component
,
1271 struct wm8753_priv
*wm8753
= snd_soc_component_get_drvdata(component
);
1274 if (wm8753
->dai_func
!= 0)
1277 ret
= wm8753_mode1v_set_dai_fmt(component
, fmt
);
1280 ret
= wm8753_pcm_set_dai_fmt(component
, fmt
);
1287 static int wm8753_voice_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
1290 struct snd_soc_component
*component
= codec_dai
->component
;
1291 struct wm8753_priv
*wm8753
= snd_soc_component_get_drvdata(component
);
1293 wm8753
->voice_fmt
= fmt
;
1295 return wm8753_voice_write_dai_fmt(component
, fmt
);
1298 static int wm8753_mute(struct snd_soc_dai
*dai
, int mute
)
1300 struct snd_soc_component
*component
= dai
->component
;
1301 u16 mute_reg
= snd_soc_component_read32(component
, WM8753_DAC
) & 0xfff7;
1302 struct wm8753_priv
*wm8753
= snd_soc_component_get_drvdata(component
);
1304 /* the digital mute covers the HiFi and Voice DAC's on the WM8753.
1305 * make sure we check if they are not both active when we mute */
1306 if (mute
&& wm8753
->dai_func
== 1) {
1307 if (!snd_soc_component_is_active(component
))
1308 snd_soc_component_write(component
, WM8753_DAC
, mute_reg
| 0x8);
1311 snd_soc_component_write(component
, WM8753_DAC
, mute_reg
| 0x8);
1313 snd_soc_component_write(component
, WM8753_DAC
, mute_reg
);
1319 static void wm8753_charge_work(struct work_struct
*work
)
1321 struct wm8753_priv
*wm8753
=
1322 container_of(work
, struct wm8753_priv
, charge_work
.work
);
1325 regmap_update_bits(wm8753
->regmap
, WM8753_PWR1
, 0x0180, 0x0100);
1328 static int wm8753_set_bias_level(struct snd_soc_component
*component
,
1329 enum snd_soc_bias_level level
)
1331 struct wm8753_priv
*wm8753
= snd_soc_component_get_drvdata(component
);
1332 u16 pwr_reg
= snd_soc_component_read32(component
, WM8753_PWR1
) & 0xfe3e;
1335 case SND_SOC_BIAS_ON
:
1336 /* set vmid to 50k and unmute dac */
1337 snd_soc_component_write(component
, WM8753_PWR1
, pwr_reg
| 0x00c0);
1339 case SND_SOC_BIAS_PREPARE
:
1340 /* Wait until fully charged */
1341 flush_delayed_work(&wm8753
->charge_work
);
1343 case SND_SOC_BIAS_STANDBY
:
1344 if (snd_soc_component_get_bias_level(component
) == SND_SOC_BIAS_OFF
) {
1345 /* set vmid to 5k for quick power up */
1346 snd_soc_component_write(component
, WM8753_PWR1
, pwr_reg
| 0x01c1);
1347 schedule_delayed_work(&wm8753
->charge_work
,
1348 msecs_to_jiffies(caps_charge
));
1350 /* mute dac and set vmid to 500k, enable VREF */
1351 snd_soc_component_write(component
, WM8753_PWR1
, pwr_reg
| 0x0141);
1354 case SND_SOC_BIAS_OFF
:
1355 cancel_delayed_work_sync(&wm8753
->charge_work
);
1356 snd_soc_component_write(component
, WM8753_PWR1
, 0x0001);
1362 #define WM8753_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
1363 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
1364 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
1365 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
1367 #define WM8753_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1368 SNDRV_PCM_FMTBIT_S24_LE)
1371 * The WM8753 supports up to 4 different and mutually exclusive DAI
1372 * configurations. This gives 2 PCM's available for use, hifi and voice.
1373 * NOTE: The Voice PCM cannot play or capture audio to the CPU as it's DAI
1374 * is connected between the wm8753 and a BT codec or GSM modem.
1376 * 1. Voice over PCM DAI - HIFI DAC over HIFI DAI
1377 * 2. Voice over HIFI DAI - HIFI disabled
1378 * 3. Voice disabled - HIFI over HIFI
1379 * 4. Voice disabled - HIFI over HIFI, uses voice DAI LRC for capture
1381 static const struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode
= {
1382 .hw_params
= wm8753_i2s_hw_params
,
1383 .digital_mute
= wm8753_mute
,
1384 .set_fmt
= wm8753_hifi_set_dai_fmt
,
1385 .set_clkdiv
= wm8753_set_dai_clkdiv
,
1386 .set_pll
= wm8753_set_dai_pll
,
1387 .set_sysclk
= wm8753_set_dai_sysclk
,
1390 static const struct snd_soc_dai_ops wm8753_dai_ops_voice_mode
= {
1391 .hw_params
= wm8753_pcm_hw_params
,
1392 .digital_mute
= wm8753_mute
,
1393 .set_fmt
= wm8753_voice_set_dai_fmt
,
1394 .set_clkdiv
= wm8753_set_dai_clkdiv
,
1395 .set_pll
= wm8753_set_dai_pll
,
1396 .set_sysclk
= wm8753_set_dai_sysclk
,
1399 static struct snd_soc_dai_driver wm8753_dai
[] = {
1400 /* DAI HiFi mode 1 */
1401 { .name
= "wm8753-hifi",
1403 .stream_name
= "HiFi Playback",
1406 .rates
= WM8753_RATES
,
1407 .formats
= WM8753_FORMATS
1409 .capture
= { /* dummy for fast DAI switching */
1410 .stream_name
= "Capture",
1413 .rates
= WM8753_RATES
,
1414 .formats
= WM8753_FORMATS
1416 .ops
= &wm8753_dai_ops_hifi_mode
,
1418 /* DAI Voice mode 1 */
1419 { .name
= "wm8753-voice",
1421 .stream_name
= "Voice Playback",
1424 .rates
= WM8753_RATES
,
1425 .formats
= WM8753_FORMATS
,
1428 .stream_name
= "Capture",
1431 .rates
= WM8753_RATES
,
1432 .formats
= WM8753_FORMATS
,
1434 .ops
= &wm8753_dai_ops_voice_mode
,
1438 static int wm8753_resume(struct snd_soc_component
*component
)
1440 struct wm8753_priv
*wm8753
= snd_soc_component_get_drvdata(component
);
1442 regcache_sync(wm8753
->regmap
);
1447 static int wm8753_probe(struct snd_soc_component
*component
)
1449 struct wm8753_priv
*wm8753
= snd_soc_component_get_drvdata(component
);
1452 INIT_DELAYED_WORK(&wm8753
->charge_work
, wm8753_charge_work
);
1454 ret
= wm8753_reset(component
);
1456 dev_err(component
->dev
, "Failed to issue reset: %d\n", ret
);
1460 wm8753
->dai_func
= 0;
1462 /* set the update bits */
1463 snd_soc_component_update_bits(component
, WM8753_LDAC
, 0x0100, 0x0100);
1464 snd_soc_component_update_bits(component
, WM8753_RDAC
, 0x0100, 0x0100);
1465 snd_soc_component_update_bits(component
, WM8753_LADC
, 0x0100, 0x0100);
1466 snd_soc_component_update_bits(component
, WM8753_RADC
, 0x0100, 0x0100);
1467 snd_soc_component_update_bits(component
, WM8753_LOUT1V
, 0x0100, 0x0100);
1468 snd_soc_component_update_bits(component
, WM8753_ROUT1V
, 0x0100, 0x0100);
1469 snd_soc_component_update_bits(component
, WM8753_LOUT2V
, 0x0100, 0x0100);
1470 snd_soc_component_update_bits(component
, WM8753_ROUT2V
, 0x0100, 0x0100);
1471 snd_soc_component_update_bits(component
, WM8753_LINVOL
, 0x0100, 0x0100);
1472 snd_soc_component_update_bits(component
, WM8753_RINVOL
, 0x0100, 0x0100);
1477 static const struct snd_soc_component_driver soc_component_dev_wm8753
= {
1478 .probe
= wm8753_probe
,
1479 .resume
= wm8753_resume
,
1480 .set_bias_level
= wm8753_set_bias_level
,
1481 .controls
= wm8753_snd_controls
,
1482 .num_controls
= ARRAY_SIZE(wm8753_snd_controls
),
1483 .dapm_widgets
= wm8753_dapm_widgets
,
1484 .num_dapm_widgets
= ARRAY_SIZE(wm8753_dapm_widgets
),
1485 .dapm_routes
= wm8753_dapm_routes
,
1486 .num_dapm_routes
= ARRAY_SIZE(wm8753_dapm_routes
),
1487 .suspend_bias_off
= 1,
1489 .use_pmdown_time
= 1,
1491 .non_legacy_dai_naming
= 1,
1494 static const struct of_device_id wm8753_of_match
[] = {
1495 { .compatible
= "wlf,wm8753", },
1498 MODULE_DEVICE_TABLE(of
, wm8753_of_match
);
1500 static const struct regmap_config wm8753_regmap
= {
1504 .max_register
= WM8753_ADCTL2
,
1505 .volatile_reg
= wm8753_volatile
,
1507 .cache_type
= REGCACHE_RBTREE
,
1508 .reg_defaults
= wm8753_reg_defaults
,
1509 .num_reg_defaults
= ARRAY_SIZE(wm8753_reg_defaults
),
1512 #if defined(CONFIG_SPI_MASTER)
1513 static int wm8753_spi_probe(struct spi_device
*spi
)
1515 struct wm8753_priv
*wm8753
;
1518 wm8753
= devm_kzalloc(&spi
->dev
, sizeof(struct wm8753_priv
),
1523 spi_set_drvdata(spi
, wm8753
);
1525 wm8753
->regmap
= devm_regmap_init_spi(spi
, &wm8753_regmap
);
1526 if (IS_ERR(wm8753
->regmap
)) {
1527 ret
= PTR_ERR(wm8753
->regmap
);
1528 dev_err(&spi
->dev
, "Failed to allocate register map: %d\n",
1533 ret
= devm_snd_soc_register_component(&spi
->dev
, &soc_component_dev_wm8753
,
1534 wm8753_dai
, ARRAY_SIZE(wm8753_dai
));
1536 dev_err(&spi
->dev
, "Failed to register CODEC: %d\n", ret
);
1541 static struct spi_driver wm8753_spi_driver
= {
1544 .of_match_table
= wm8753_of_match
,
1546 .probe
= wm8753_spi_probe
,
1548 #endif /* CONFIG_SPI_MASTER */
1550 #if IS_ENABLED(CONFIG_I2C)
1551 static int wm8753_i2c_probe(struct i2c_client
*i2c
,
1552 const struct i2c_device_id
*id
)
1554 struct wm8753_priv
*wm8753
;
1557 wm8753
= devm_kzalloc(&i2c
->dev
, sizeof(struct wm8753_priv
),
1562 i2c_set_clientdata(i2c
, wm8753
);
1564 wm8753
->regmap
= devm_regmap_init_i2c(i2c
, &wm8753_regmap
);
1565 if (IS_ERR(wm8753
->regmap
)) {
1566 ret
= PTR_ERR(wm8753
->regmap
);
1567 dev_err(&i2c
->dev
, "Failed to allocate register map: %d\n",
1572 ret
= devm_snd_soc_register_component(&i2c
->dev
, &soc_component_dev_wm8753
,
1573 wm8753_dai
, ARRAY_SIZE(wm8753_dai
));
1575 dev_err(&i2c
->dev
, "Failed to register CODEC: %d\n", ret
);
1580 static const struct i2c_device_id wm8753_i2c_id
[] = {
1584 MODULE_DEVICE_TABLE(i2c
, wm8753_i2c_id
);
1586 static struct i2c_driver wm8753_i2c_driver
= {
1589 .of_match_table
= wm8753_of_match
,
1591 .probe
= wm8753_i2c_probe
,
1592 .id_table
= wm8753_i2c_id
,
1596 static int __init
wm8753_modinit(void)
1599 #if IS_ENABLED(CONFIG_I2C)
1600 ret
= i2c_add_driver(&wm8753_i2c_driver
);
1602 printk(KERN_ERR
"Failed to register wm8753 I2C driver: %d\n",
1606 #if defined(CONFIG_SPI_MASTER)
1607 ret
= spi_register_driver(&wm8753_spi_driver
);
1609 printk(KERN_ERR
"Failed to register wm8753 SPI driver: %d\n",
1615 module_init(wm8753_modinit
);
1617 static void __exit
wm8753_exit(void)
1619 #if IS_ENABLED(CONFIG_I2C)
1620 i2c_del_driver(&wm8753_i2c_driver
);
1622 #if defined(CONFIG_SPI_MASTER)
1623 spi_unregister_driver(&wm8753_spi_driver
);
1626 module_exit(wm8753_exit
);
1628 MODULE_DESCRIPTION("ASoC WM8753 driver");
1629 MODULE_AUTHOR("Liam Girdwood");
1630 MODULE_LICENSE("GPL");