2 * wm8753.c -- WM8753 ALSA Soc Audio driver
4 * Copyright 2003 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
13 * The WM8753 is a low power, high quality stereo codec with integrated PCM
14 * codec designed for portable digital telephony applications.
18 * This driver support 2 DAI PCM's. This makes the default PCM available for
19 * HiFi audio (e.g. MP3, ogg) playback/capture and the other PCM available for
22 * Please note that the voice PCM can be connected directly to a Bluetooth
23 * codec or GSM modem and thus cannot be read or written to, although it is
24 * available to be configured with snd_hw_params(), etc and kcontrols in the
27 * Fast DAI switching:-
29 * The driver can now fast switch between the DAI configurations via a
30 * an alsa kcontrol. This allows the PCM to remain open.
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/kernel.h>
37 #include <linux/init.h>
38 #include <linux/delay.h>
40 #include <linux/i2c.h>
41 #include <linux/platform_device.h>
42 #include <linux/spi/spi.h>
43 #include <linux/slab.h>
44 #include <sound/core.h>
45 #include <sound/pcm.h>
46 #include <sound/pcm_params.h>
47 #include <sound/soc.h>
48 #include <sound/initval.h>
49 #include <sound/tlv.h>
50 #include <asm/div64.h>
54 static int caps_charge
= 2000;
55 module_param(caps_charge
, int, 0);
56 MODULE_PARM_DESC(caps_charge
, "WM8753 cap charge time (msecs)");
58 static void wm8753_set_dai_mode(struct snd_soc_codec
*codec
,
59 struct snd_soc_dai
*dai
, unsigned int hifi
);
62 * wm8753 register cache
63 * We can't read the WM8753 register space when we
64 * are using 2 wire for device control, so we cache them instead.
66 static const u16 wm8753_reg
[] = {
67 0x0000, 0x0008, 0x0000, 0x000a,
68 0x000a, 0x0033, 0x0000, 0x0007,
69 0x00ff, 0x00ff, 0x000f, 0x000f,
70 0x007b, 0x0000, 0x0032, 0x0000,
71 0x00c3, 0x00c3, 0x00c0, 0x0000,
72 0x0000, 0x0000, 0x0000, 0x0000,
73 0x0000, 0x0000, 0x0000, 0x0000,
74 0x0000, 0x0000, 0x0000, 0x0000,
75 0x0055, 0x0005, 0x0050, 0x0055,
76 0x0050, 0x0055, 0x0050, 0x0055,
77 0x0079, 0x0079, 0x0079, 0x0079,
78 0x0079, 0x0000, 0x0000, 0x0000,
79 0x0000, 0x0097, 0x0097, 0x0000,
80 0x0004, 0x0000, 0x0083, 0x0024,
81 0x01ba, 0x0000, 0x0083, 0x0024,
82 0x01ba, 0x0000, 0x0000, 0x0000
85 /* codec private data */
87 enum snd_soc_control_type control_type
;
93 #define wm8753_reset(c) snd_soc_write(c, WM8753_RESET, 0)
98 static const char *wm8753_base
[] = {"Linear Control", "Adaptive Boost"};
99 static const char *wm8753_base_filter
[] =
100 {"130Hz @ 48kHz", "200Hz @ 48kHz", "100Hz @ 16kHz", "400Hz @ 48kHz",
101 "100Hz @ 8kHz", "200Hz @ 8kHz"};
102 static const char *wm8753_treble
[] = {"8kHz", "4kHz"};
103 static const char *wm8753_alc_func
[] = {"Off", "Right", "Left", "Stereo"};
104 static const char *wm8753_ng_type
[] = {"Constant PGA Gain", "Mute ADC Output"};
105 static const char *wm8753_3d_func
[] = {"Capture", "Playback"};
106 static const char *wm8753_3d_uc
[] = {"2.2kHz", "1.5kHz"};
107 static const char *wm8753_3d_lc
[] = {"200Hz", "500Hz"};
108 static const char *wm8753_deemp
[] = {"None", "32kHz", "44.1kHz", "48kHz"};
109 static const char *wm8753_mono_mix
[] = {"Stereo", "Left", "Right", "Mono"};
110 static const char *wm8753_dac_phase
[] = {"Non Inverted", "Inverted"};
111 static const char *wm8753_line_mix
[] = {"Line 1 + 2", "Line 1 - 2",
113 static const char *wm8753_mono_mux
[] = {"Line Mix", "Rx Mix"};
114 static const char *wm8753_right_mux
[] = {"Line 2", "Rx Mix"};
115 static const char *wm8753_left_mux
[] = {"Line 1", "Rx Mix"};
116 static const char *wm8753_rxmsel
[] = {"RXP - RXN", "RXP + RXN", "RXP", "RXN"};
117 static const char *wm8753_sidetone_mux
[] = {"Left PGA", "Mic 1", "Mic 2",
119 static const char *wm8753_mono2_src
[] = {"Inverted Mono 1", "Left", "Right",
121 static const char *wm8753_out3
[] = {"VREF", "ROUT2", "Left + Right"};
122 static const char *wm8753_out4
[] = {"VREF", "Capture ST", "LOUT2"};
123 static const char *wm8753_radcsel
[] = {"PGA", "Line or RXP-RXN", "Sidetone"};
124 static const char *wm8753_ladcsel
[] = {"PGA", "Line or RXP-RXN", "Line"};
125 static const char *wm8753_mono_adc
[] = {"Stereo", "Analogue Mix Left",
126 "Analogue Mix Right", "Digital Mono Mix"};
127 static const char *wm8753_adc_hp
[] = {"3.4Hz @ 48kHz", "82Hz @ 16k",
128 "82Hz @ 8kHz", "170Hz @ 8kHz"};
129 static const char *wm8753_adc_filter
[] = {"HiFi", "Voice"};
130 static const char *wm8753_mic_sel
[] = {"Mic 1", "Mic 2", "Mic 3"};
131 static const char *wm8753_dai_mode
[] = {"DAI 0", "DAI 1", "DAI 2", "DAI 3"};
132 static const char *wm8753_dat_sel
[] = {"Stereo", "Left ADC", "Right ADC",
134 static const char *wm8753_rout2_phase
[] = {"Non Inverted", "Inverted"};
136 static const struct soc_enum wm8753_enum
[] = {
137 SOC_ENUM_SINGLE(WM8753_BASS
, 7, 2, wm8753_base
),
138 SOC_ENUM_SINGLE(WM8753_BASS
, 4, 6, wm8753_base_filter
),
139 SOC_ENUM_SINGLE(WM8753_TREBLE
, 6, 2, wm8753_treble
),
140 SOC_ENUM_SINGLE(WM8753_ALC1
, 7, 4, wm8753_alc_func
),
141 SOC_ENUM_SINGLE(WM8753_NGATE
, 1, 2, wm8753_ng_type
),
142 SOC_ENUM_SINGLE(WM8753_3D
, 7, 2, wm8753_3d_func
),
143 SOC_ENUM_SINGLE(WM8753_3D
, 6, 2, wm8753_3d_uc
),
144 SOC_ENUM_SINGLE(WM8753_3D
, 5, 2, wm8753_3d_lc
),
145 SOC_ENUM_SINGLE(WM8753_DAC
, 1, 4, wm8753_deemp
),
146 SOC_ENUM_SINGLE(WM8753_DAC
, 4, 4, wm8753_mono_mix
),
147 SOC_ENUM_SINGLE(WM8753_DAC
, 6, 2, wm8753_dac_phase
),
148 SOC_ENUM_SINGLE(WM8753_INCTL1
, 3, 4, wm8753_line_mix
),
149 SOC_ENUM_SINGLE(WM8753_INCTL1
, 2, 2, wm8753_mono_mux
),
150 SOC_ENUM_SINGLE(WM8753_INCTL1
, 1, 2, wm8753_right_mux
),
151 SOC_ENUM_SINGLE(WM8753_INCTL1
, 0, 2, wm8753_left_mux
),
152 SOC_ENUM_SINGLE(WM8753_INCTL2
, 6, 4, wm8753_rxmsel
),
153 SOC_ENUM_SINGLE(WM8753_INCTL2
, 4, 4, wm8753_sidetone_mux
),
154 SOC_ENUM_SINGLE(WM8753_OUTCTL
, 7, 4, wm8753_mono2_src
),
155 SOC_ENUM_SINGLE(WM8753_OUTCTL
, 0, 3, wm8753_out3
),
156 SOC_ENUM_SINGLE(WM8753_ADCTL2
, 7, 3, wm8753_out4
),
157 SOC_ENUM_SINGLE(WM8753_ADCIN
, 2, 3, wm8753_radcsel
),
158 SOC_ENUM_SINGLE(WM8753_ADCIN
, 0, 3, wm8753_ladcsel
),
159 SOC_ENUM_SINGLE(WM8753_ADCIN
, 4, 4, wm8753_mono_adc
),
160 SOC_ENUM_SINGLE(WM8753_ADC
, 2, 4, wm8753_adc_hp
),
161 SOC_ENUM_SINGLE(WM8753_ADC
, 4, 2, wm8753_adc_filter
),
162 SOC_ENUM_SINGLE(WM8753_MICBIAS
, 6, 3, wm8753_mic_sel
),
163 SOC_ENUM_SINGLE(WM8753_IOCTL
, 2, 4, wm8753_dai_mode
),
164 SOC_ENUM_SINGLE(WM8753_ADC
, 7, 4, wm8753_dat_sel
),
165 SOC_ENUM_SINGLE(WM8753_OUTCTL
, 2, 2, wm8753_rout2_phase
),
169 static int wm8753_get_dai(struct snd_kcontrol
*kcontrol
,
170 struct snd_ctl_elem_value
*ucontrol
)
172 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
173 int mode
= snd_soc_read(codec
, WM8753_IOCTL
);
175 ucontrol
->value
.integer
.value
[0] = (mode
& 0xc) >> 2;
179 static int wm8753_set_dai(struct snd_kcontrol
*kcontrol
,
180 struct snd_ctl_elem_value
*ucontrol
)
182 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
183 int mode
= snd_soc_read(codec
, WM8753_IOCTL
);
184 struct wm8753_priv
*wm8753
= snd_soc_codec_get_drvdata(codec
);
186 if (((mode
& 0xc) >> 2) == ucontrol
->value
.integer
.value
[0])
190 mode
|= (ucontrol
->value
.integer
.value
[0] << 2);
192 wm8753
->dai_func
= ucontrol
->value
.integer
.value
[0];
196 static const DECLARE_TLV_DB_SCALE(rec_mix_tlv
, -1500, 300, 0);
197 static const DECLARE_TLV_DB_SCALE(mic_preamp_tlv
, 1200, 600, 0);
198 static const DECLARE_TLV_DB_SCALE(adc_tlv
, -9750, 50, 1);
199 static const DECLARE_TLV_DB_SCALE(dac_tlv
, -12750, 50, 1);
200 static const unsigned int out_tlv
[] = {
201 TLV_DB_RANGE_HEAD(2),
202 /* 0000000 - 0101111 = "Analogue mute" */
203 0, 48, TLV_DB_SCALE_ITEM(-25500, 0, 0),
204 48, 127, TLV_DB_SCALE_ITEM(-7300, 100, 0),
206 static const DECLARE_TLV_DB_SCALE(mix_tlv
, -1500, 300, 0);
207 static const DECLARE_TLV_DB_SCALE(voice_mix_tlv
, -1200, 300, 0);
208 static const DECLARE_TLV_DB_SCALE(pga_tlv
, -1725, 75, 0);
210 static const struct snd_kcontrol_new wm8753_snd_controls
[] = {
211 SOC_DOUBLE_R_TLV("PCM Volume", WM8753_LDAC
, WM8753_RDAC
, 0, 255, 0, dac_tlv
),
213 SOC_DOUBLE_R_TLV("ADC Capture Volume", WM8753_LADC
, WM8753_RADC
, 0, 255, 0,
216 SOC_DOUBLE_R_TLV("Headphone Playback Volume", WM8753_LOUT1V
, WM8753_ROUT1V
,
218 SOC_DOUBLE_R_TLV("Speaker Playback Volume", WM8753_LOUT2V
, WM8753_ROUT2V
, 0,
221 SOC_SINGLE_TLV("Mono Playback Volume", WM8753_MOUTV
, 0, 127, 0, out_tlv
),
223 SOC_DOUBLE_R_TLV("Bypass Playback Volume", WM8753_LOUTM1
, WM8753_ROUTM1
, 4, 7,
225 SOC_DOUBLE_R_TLV("Sidetone Playback Volume", WM8753_LOUTM2
, WM8753_ROUTM2
, 4,
227 SOC_DOUBLE_R_TLV("Voice Playback Volume", WM8753_LOUTM2
, WM8753_ROUTM2
, 0, 7,
230 SOC_DOUBLE_R("Headphone Playback ZC Switch", WM8753_LOUT1V
, WM8753_ROUT1V
, 7,
232 SOC_DOUBLE_R("Speaker Playback ZC Switch", WM8753_LOUT2V
, WM8753_ROUT2V
, 7,
235 SOC_SINGLE_TLV("Mono Bypass Playback Volume", WM8753_MOUTM1
, 4, 7, 1, mix_tlv
),
236 SOC_SINGLE_TLV("Mono Sidetone Playback Volume", WM8753_MOUTM2
, 4, 7, 1,
238 SOC_SINGLE_TLV("Mono Voice Playback Volume", WM8753_MOUTM2
, 0, 7, 1,
240 SOC_SINGLE("Mono Playback ZC Switch", WM8753_MOUTV
, 7, 1, 0),
242 SOC_ENUM("Bass Boost", wm8753_enum
[0]),
243 SOC_ENUM("Bass Filter", wm8753_enum
[1]),
244 SOC_SINGLE("Bass Volume", WM8753_BASS
, 0, 15, 1),
246 SOC_SINGLE("Treble Volume", WM8753_TREBLE
, 0, 15, 1),
247 SOC_ENUM("Treble Cut-off", wm8753_enum
[2]),
249 SOC_DOUBLE_TLV("Sidetone Capture Volume", WM8753_RECMIX1
, 0, 4, 7, 1,
251 SOC_SINGLE_TLV("Voice Sidetone Capture Volume", WM8753_RECMIX2
, 0, 7, 1,
254 SOC_DOUBLE_R_TLV("Capture Volume", WM8753_LINVOL
, WM8753_RINVOL
, 0, 63, 0,
256 SOC_DOUBLE_R("Capture ZC Switch", WM8753_LINVOL
, WM8753_RINVOL
, 6, 1, 0),
257 SOC_DOUBLE_R("Capture Switch", WM8753_LINVOL
, WM8753_RINVOL
, 7, 1, 1),
259 SOC_ENUM("Capture Filter Select", wm8753_enum
[23]),
260 SOC_ENUM("Capture Filter Cut-off", wm8753_enum
[24]),
261 SOC_SINGLE("Capture Filter Switch", WM8753_ADC
, 0, 1, 1),
263 SOC_SINGLE("ALC Capture Target Volume", WM8753_ALC1
, 0, 7, 0),
264 SOC_SINGLE("ALC Capture Max Volume", WM8753_ALC1
, 4, 7, 0),
265 SOC_ENUM("ALC Capture Function", wm8753_enum
[3]),
266 SOC_SINGLE("ALC Capture ZC Switch", WM8753_ALC2
, 8, 1, 0),
267 SOC_SINGLE("ALC Capture Hold Time", WM8753_ALC2
, 0, 15, 1),
268 SOC_SINGLE("ALC Capture Decay Time", WM8753_ALC3
, 4, 15, 1),
269 SOC_SINGLE("ALC Capture Attack Time", WM8753_ALC3
, 0, 15, 0),
270 SOC_SINGLE("ALC Capture NG Threshold", WM8753_NGATE
, 3, 31, 0),
271 SOC_ENUM("ALC Capture NG Type", wm8753_enum
[4]),
272 SOC_SINGLE("ALC Capture NG Switch", WM8753_NGATE
, 0, 1, 0),
274 SOC_ENUM("3D Function", wm8753_enum
[5]),
275 SOC_ENUM("3D Upper Cut-off", wm8753_enum
[6]),
276 SOC_ENUM("3D Lower Cut-off", wm8753_enum
[7]),
277 SOC_SINGLE("3D Volume", WM8753_3D
, 1, 15, 0),
278 SOC_SINGLE("3D Switch", WM8753_3D
, 0, 1, 0),
280 SOC_SINGLE("Capture 6dB Attenuate", WM8753_ADCTL1
, 2, 1, 0),
281 SOC_SINGLE("Playback 6dB Attenuate", WM8753_ADCTL1
, 1, 1, 0),
283 SOC_ENUM("De-emphasis", wm8753_enum
[8]),
284 SOC_ENUM("Playback Mono Mix", wm8753_enum
[9]),
285 SOC_ENUM("Playback Phase", wm8753_enum
[10]),
287 SOC_SINGLE_TLV("Mic2 Capture Volume", WM8753_INCTL1
, 7, 3, 0, mic_preamp_tlv
),
288 SOC_SINGLE_TLV("Mic1 Capture Volume", WM8753_INCTL1
, 5, 3, 0, mic_preamp_tlv
),
290 SOC_ENUM_EXT("DAI Mode", wm8753_enum
[26], wm8753_get_dai
, wm8753_set_dai
),
292 SOC_ENUM("ADC Data Select", wm8753_enum
[27]),
293 SOC_ENUM("ROUT2 Phase", wm8753_enum
[28]),
301 static const struct snd_kcontrol_new wm8753_left_mixer_controls
[] = {
302 SOC_DAPM_SINGLE("Voice Playback Switch", WM8753_LOUTM2
, 8, 1, 0),
303 SOC_DAPM_SINGLE("Sidetone Playback Switch", WM8753_LOUTM2
, 7, 1, 0),
304 SOC_DAPM_SINGLE("Left Playback Switch", WM8753_LOUTM1
, 8, 1, 0),
305 SOC_DAPM_SINGLE("Bypass Playback Switch", WM8753_LOUTM1
, 7, 1, 0),
309 static const struct snd_kcontrol_new wm8753_right_mixer_controls
[] = {
310 SOC_DAPM_SINGLE("Voice Playback Switch", WM8753_ROUTM2
, 8, 1, 0),
311 SOC_DAPM_SINGLE("Sidetone Playback Switch", WM8753_ROUTM2
, 7, 1, 0),
312 SOC_DAPM_SINGLE("Right Playback Switch", WM8753_ROUTM1
, 8, 1, 0),
313 SOC_DAPM_SINGLE("Bypass Playback Switch", WM8753_ROUTM1
, 7, 1, 0),
317 static const struct snd_kcontrol_new wm8753_mono_mixer_controls
[] = {
318 SOC_DAPM_SINGLE("Left Playback Switch", WM8753_MOUTM1
, 8, 1, 0),
319 SOC_DAPM_SINGLE("Right Playback Switch", WM8753_MOUTM2
, 8, 1, 0),
320 SOC_DAPM_SINGLE("Voice Playback Switch", WM8753_MOUTM2
, 3, 1, 0),
321 SOC_DAPM_SINGLE("Sidetone Playback Switch", WM8753_MOUTM2
, 7, 1, 0),
322 SOC_DAPM_SINGLE("Bypass Playback Switch", WM8753_MOUTM1
, 7, 1, 0),
326 static const struct snd_kcontrol_new wm8753_mono2_controls
=
327 SOC_DAPM_ENUM("Route", wm8753_enum
[17]);
330 static const struct snd_kcontrol_new wm8753_out3_controls
=
331 SOC_DAPM_ENUM("Route", wm8753_enum
[18]);
334 static const struct snd_kcontrol_new wm8753_out4_controls
=
335 SOC_DAPM_ENUM("Route", wm8753_enum
[19]);
338 static const struct snd_kcontrol_new wm8753_adc_mono_controls
=
339 SOC_DAPM_ENUM("Route", wm8753_enum
[22]);
342 static const struct snd_kcontrol_new wm8753_record_mixer_controls
[] = {
343 SOC_DAPM_SINGLE("Voice Capture Switch", WM8753_RECMIX2
, 3, 1, 0),
344 SOC_DAPM_SINGLE("Left Capture Switch", WM8753_RECMIX1
, 3, 1, 0),
345 SOC_DAPM_SINGLE("Right Capture Switch", WM8753_RECMIX1
, 7, 1, 0),
349 static const struct snd_kcontrol_new wm8753_adc_left_controls
=
350 SOC_DAPM_ENUM("Route", wm8753_enum
[21]);
353 static const struct snd_kcontrol_new wm8753_adc_right_controls
=
354 SOC_DAPM_ENUM("Route", wm8753_enum
[20]);
357 static const struct snd_kcontrol_new wm8753_mic_mux_controls
=
358 SOC_DAPM_ENUM("Route", wm8753_enum
[16]);
361 static const struct snd_kcontrol_new wm8753_alc_mixer_controls
[] = {
362 SOC_DAPM_SINGLE("Line Capture Switch", WM8753_INCTL2
, 3, 1, 0),
363 SOC_DAPM_SINGLE("Mic2 Capture Switch", WM8753_INCTL2
, 2, 1, 0),
364 SOC_DAPM_SINGLE("Mic1 Capture Switch", WM8753_INCTL2
, 1, 1, 0),
365 SOC_DAPM_SINGLE("Rx Capture Switch", WM8753_INCTL2
, 0, 1, 0),
369 static const struct snd_kcontrol_new wm8753_line_left_controls
=
370 SOC_DAPM_ENUM("Route", wm8753_enum
[14]);
373 static const struct snd_kcontrol_new wm8753_line_right_controls
=
374 SOC_DAPM_ENUM("Route", wm8753_enum
[13]);
377 static const struct snd_kcontrol_new wm8753_line_mono_controls
=
378 SOC_DAPM_ENUM("Route", wm8753_enum
[12]);
380 /* Line mux and mixer */
381 static const struct snd_kcontrol_new wm8753_line_mux_mix_controls
=
382 SOC_DAPM_ENUM("Route", wm8753_enum
[11]);
384 /* Rx mux and mixer */
385 static const struct snd_kcontrol_new wm8753_rx_mux_mix_controls
=
386 SOC_DAPM_ENUM("Route", wm8753_enum
[15]);
388 /* Mic Selector Mux */
389 static const struct snd_kcontrol_new wm8753_mic_sel_mux_controls
=
390 SOC_DAPM_ENUM("Route", wm8753_enum
[25]);
392 static const struct snd_soc_dapm_widget wm8753_dapm_widgets
[] = {
393 SND_SOC_DAPM_MICBIAS("Mic Bias", WM8753_PWR1
, 5, 0),
394 SND_SOC_DAPM_MIXER("Left Mixer", WM8753_PWR4
, 0, 0,
395 &wm8753_left_mixer_controls
[0], ARRAY_SIZE(wm8753_left_mixer_controls
)),
396 SND_SOC_DAPM_PGA("Left Out 1", WM8753_PWR3
, 8, 0, NULL
, 0),
397 SND_SOC_DAPM_PGA("Left Out 2", WM8753_PWR3
, 6, 0, NULL
, 0),
398 SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", WM8753_PWR1
, 3, 0),
399 SND_SOC_DAPM_OUTPUT("LOUT1"),
400 SND_SOC_DAPM_OUTPUT("LOUT2"),
401 SND_SOC_DAPM_MIXER("Right Mixer", WM8753_PWR4
, 1, 0,
402 &wm8753_right_mixer_controls
[0], ARRAY_SIZE(wm8753_right_mixer_controls
)),
403 SND_SOC_DAPM_PGA("Right Out 1", WM8753_PWR3
, 7, 0, NULL
, 0),
404 SND_SOC_DAPM_PGA("Right Out 2", WM8753_PWR3
, 5, 0, NULL
, 0),
405 SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", WM8753_PWR1
, 2, 0),
406 SND_SOC_DAPM_OUTPUT("ROUT1"),
407 SND_SOC_DAPM_OUTPUT("ROUT2"),
408 SND_SOC_DAPM_MIXER("Mono Mixer", WM8753_PWR4
, 2, 0,
409 &wm8753_mono_mixer_controls
[0], ARRAY_SIZE(wm8753_mono_mixer_controls
)),
410 SND_SOC_DAPM_PGA("Mono Out 1", WM8753_PWR3
, 2, 0, NULL
, 0),
411 SND_SOC_DAPM_PGA("Mono Out 2", WM8753_PWR3
, 1, 0, NULL
, 0),
412 SND_SOC_DAPM_DAC("Voice DAC", "Voice Playback", WM8753_PWR1
, 4, 0),
413 SND_SOC_DAPM_OUTPUT("MONO1"),
414 SND_SOC_DAPM_MUX("Mono 2 Mux", SND_SOC_NOPM
, 0, 0, &wm8753_mono2_controls
),
415 SND_SOC_DAPM_OUTPUT("MONO2"),
416 SND_SOC_DAPM_MIXER("Out3 Left + Right", -1, 0, 0, NULL
, 0),
417 SND_SOC_DAPM_MUX("Out3 Mux", SND_SOC_NOPM
, 0, 0, &wm8753_out3_controls
),
418 SND_SOC_DAPM_PGA("Out 3", WM8753_PWR3
, 4, 0, NULL
, 0),
419 SND_SOC_DAPM_OUTPUT("OUT3"),
420 SND_SOC_DAPM_MUX("Out4 Mux", SND_SOC_NOPM
, 0, 0, &wm8753_out4_controls
),
421 SND_SOC_DAPM_PGA("Out 4", WM8753_PWR3
, 3, 0, NULL
, 0),
422 SND_SOC_DAPM_OUTPUT("OUT4"),
423 SND_SOC_DAPM_MIXER("Playback Mixer", WM8753_PWR4
, 3, 0,
424 &wm8753_record_mixer_controls
[0],
425 ARRAY_SIZE(wm8753_record_mixer_controls
)),
426 SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8753_PWR2
, 3, 0),
427 SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8753_PWR2
, 2, 0),
428 SND_SOC_DAPM_MUX("Capture Left Mixer", SND_SOC_NOPM
, 0, 0,
429 &wm8753_adc_mono_controls
),
430 SND_SOC_DAPM_MUX("Capture Right Mixer", SND_SOC_NOPM
, 0, 0,
431 &wm8753_adc_mono_controls
),
432 SND_SOC_DAPM_MUX("Capture Left Mux", SND_SOC_NOPM
, 0, 0,
433 &wm8753_adc_left_controls
),
434 SND_SOC_DAPM_MUX("Capture Right Mux", SND_SOC_NOPM
, 0, 0,
435 &wm8753_adc_right_controls
),
436 SND_SOC_DAPM_MUX("Mic Sidetone Mux", SND_SOC_NOPM
, 0, 0,
437 &wm8753_mic_mux_controls
),
438 SND_SOC_DAPM_PGA("Left Capture Volume", WM8753_PWR2
, 5, 0, NULL
, 0),
439 SND_SOC_DAPM_PGA("Right Capture Volume", WM8753_PWR2
, 4, 0, NULL
, 0),
440 SND_SOC_DAPM_MIXER("ALC Mixer", WM8753_PWR2
, 6, 0,
441 &wm8753_alc_mixer_controls
[0], ARRAY_SIZE(wm8753_alc_mixer_controls
)),
442 SND_SOC_DAPM_MUX("Line Left Mux", SND_SOC_NOPM
, 0, 0,
443 &wm8753_line_left_controls
),
444 SND_SOC_DAPM_MUX("Line Right Mux", SND_SOC_NOPM
, 0, 0,
445 &wm8753_line_right_controls
),
446 SND_SOC_DAPM_MUX("Line Mono Mux", SND_SOC_NOPM
, 0, 0,
447 &wm8753_line_mono_controls
),
448 SND_SOC_DAPM_MUX("Line Mixer", WM8753_PWR2
, 0, 0,
449 &wm8753_line_mux_mix_controls
),
450 SND_SOC_DAPM_MUX("Rx Mixer", WM8753_PWR2
, 1, 0,
451 &wm8753_rx_mux_mix_controls
),
452 SND_SOC_DAPM_PGA("Mic 1 Volume", WM8753_PWR2
, 8, 0, NULL
, 0),
453 SND_SOC_DAPM_PGA("Mic 2 Volume", WM8753_PWR2
, 7, 0, NULL
, 0),
454 SND_SOC_DAPM_MUX("Mic Selection Mux", SND_SOC_NOPM
, 0, 0,
455 &wm8753_mic_sel_mux_controls
),
456 SND_SOC_DAPM_INPUT("LINE1"),
457 SND_SOC_DAPM_INPUT("LINE2"),
458 SND_SOC_DAPM_INPUT("RXP"),
459 SND_SOC_DAPM_INPUT("RXN"),
460 SND_SOC_DAPM_INPUT("ACIN"),
461 SND_SOC_DAPM_OUTPUT("ACOP"),
462 SND_SOC_DAPM_INPUT("MIC1N"),
463 SND_SOC_DAPM_INPUT("MIC1"),
464 SND_SOC_DAPM_INPUT("MIC2N"),
465 SND_SOC_DAPM_INPUT("MIC2"),
466 SND_SOC_DAPM_VMID("VREF"),
469 static const struct snd_soc_dapm_route audio_map
[] = {
471 {"Left Mixer", "Left Playback Switch", "Left DAC"},
472 {"Left Mixer", "Voice Playback Switch", "Voice DAC"},
473 {"Left Mixer", "Sidetone Playback Switch", "Mic Sidetone Mux"},
474 {"Left Mixer", "Bypass Playback Switch", "Line Left Mux"},
477 {"Right Mixer", "Right Playback Switch", "Right DAC"},
478 {"Right Mixer", "Voice Playback Switch", "Voice DAC"},
479 {"Right Mixer", "Sidetone Playback Switch", "Mic Sidetone Mux"},
480 {"Right Mixer", "Bypass Playback Switch", "Line Right Mux"},
483 {"Mono Mixer", "Voice Playback Switch", "Voice DAC"},
484 {"Mono Mixer", "Left Playback Switch", "Left DAC"},
485 {"Mono Mixer", "Right Playback Switch", "Right DAC"},
486 {"Mono Mixer", "Sidetone Playback Switch", "Mic Sidetone Mux"},
487 {"Mono Mixer", "Bypass Playback Switch", "Line Mono Mux"},
490 {"Left Out 1", NULL
, "Left Mixer"},
491 {"Left Out 2", NULL
, "Left Mixer"},
492 {"LOUT1", NULL
, "Left Out 1"},
493 {"LOUT2", NULL
, "Left Out 2"},
496 {"Right Out 1", NULL
, "Right Mixer"},
497 {"Right Out 2", NULL
, "Right Mixer"},
498 {"ROUT1", NULL
, "Right Out 1"},
499 {"ROUT2", NULL
, "Right Out 2"},
502 {"Mono Out 1", NULL
, "Mono Mixer"},
503 {"MONO1", NULL
, "Mono Out 1"},
506 {"Mono 2 Mux", "Left + Right", "Out3 Left + Right"},
507 {"Mono 2 Mux", "Inverted Mono 1", "MONO1"},
508 {"Mono 2 Mux", "Left", "Left Mixer"},
509 {"Mono 2 Mux", "Right", "Right Mixer"},
510 {"Mono Out 2", NULL
, "Mono 2 Mux"},
511 {"MONO2", NULL
, "Mono Out 2"},
514 {"Out3 Left + Right", NULL
, "Left Mixer"},
515 {"Out3 Left + Right", NULL
, "Right Mixer"},
516 {"Out3 Mux", "VREF", "VREF"},
517 {"Out3 Mux", "Left + Right", "Out3 Left + Right"},
518 {"Out3 Mux", "ROUT2", "ROUT2"},
519 {"Out 3", NULL
, "Out3 Mux"},
520 {"OUT3", NULL
, "Out 3"},
523 {"Out4 Mux", "VREF", "VREF"},
524 {"Out4 Mux", "Capture ST", "Playback Mixer"},
525 {"Out4 Mux", "LOUT2", "LOUT2"},
526 {"Out 4", NULL
, "Out4 Mux"},
527 {"OUT4", NULL
, "Out 4"},
530 {"Playback Mixer", "Left Capture Switch", "Left Mixer"},
531 {"Playback Mixer", "Voice Capture Switch", "Mono Mixer"},
532 {"Playback Mixer", "Right Capture Switch", "Right Mixer"},
534 /* Mic/SideTone Mux */
535 {"Mic Sidetone Mux", "Left PGA", "Left Capture Volume"},
536 {"Mic Sidetone Mux", "Right PGA", "Right Capture Volume"},
537 {"Mic Sidetone Mux", "Mic 1", "Mic 1 Volume"},
538 {"Mic Sidetone Mux", "Mic 2", "Mic 2 Volume"},
540 /* Capture Left Mux */
541 {"Capture Left Mux", "PGA", "Left Capture Volume"},
542 {"Capture Left Mux", "Line or RXP-RXN", "Line Left Mux"},
543 {"Capture Left Mux", "Line", "LINE1"},
545 /* Capture Right Mux */
546 {"Capture Right Mux", "PGA", "Right Capture Volume"},
547 {"Capture Right Mux", "Line or RXP-RXN", "Line Right Mux"},
548 {"Capture Right Mux", "Sidetone", "Playback Mixer"},
550 /* Mono Capture mixer-mux */
551 {"Capture Right Mixer", "Stereo", "Capture Right Mux"},
552 {"Capture Left Mixer", "Stereo", "Capture Left Mux"},
553 {"Capture Left Mixer", "Analogue Mix Left", "Capture Left Mux"},
554 {"Capture Left Mixer", "Analogue Mix Left", "Capture Right Mux"},
555 {"Capture Right Mixer", "Analogue Mix Right", "Capture Left Mux"},
556 {"Capture Right Mixer", "Analogue Mix Right", "Capture Right Mux"},
557 {"Capture Left Mixer", "Digital Mono Mix", "Capture Left Mux"},
558 {"Capture Left Mixer", "Digital Mono Mix", "Capture Right Mux"},
559 {"Capture Right Mixer", "Digital Mono Mix", "Capture Left Mux"},
560 {"Capture Right Mixer", "Digital Mono Mix", "Capture Right Mux"},
563 {"Left ADC", NULL
, "Capture Left Mixer"},
564 {"Right ADC", NULL
, "Capture Right Mixer"},
566 /* Left Capture Volume */
567 {"Left Capture Volume", NULL
, "ACIN"},
569 /* Right Capture Volume */
570 {"Right Capture Volume", NULL
, "Mic 2 Volume"},
573 {"ALC Mixer", "Line Capture Switch", "Line Mixer"},
574 {"ALC Mixer", "Mic2 Capture Switch", "Mic 2 Volume"},
575 {"ALC Mixer", "Mic1 Capture Switch", "Mic 1 Volume"},
576 {"ALC Mixer", "Rx Capture Switch", "Rx Mixer"},
579 {"Line Left Mux", "Line 1", "LINE1"},
580 {"Line Left Mux", "Rx Mix", "Rx Mixer"},
583 {"Line Right Mux", "Line 2", "LINE2"},
584 {"Line Right Mux", "Rx Mix", "Rx Mixer"},
587 {"Line Mono Mux", "Line Mix", "Line Mixer"},
588 {"Line Mono Mux", "Rx Mix", "Rx Mixer"},
591 {"Line Mixer", "Line 1 + 2", "LINE1"},
592 {"Line Mixer", "Line 1 - 2", "LINE1"},
593 {"Line Mixer", "Line 1 + 2", "LINE2"},
594 {"Line Mixer", "Line 1 - 2", "LINE2"},
595 {"Line Mixer", "Line 1", "LINE1"},
596 {"Line Mixer", "Line 2", "LINE2"},
599 {"Rx Mixer", "RXP - RXN", "RXP"},
600 {"Rx Mixer", "RXP + RXN", "RXP"},
601 {"Rx Mixer", "RXP - RXN", "RXN"},
602 {"Rx Mixer", "RXP + RXN", "RXN"},
603 {"Rx Mixer", "RXP", "RXP"},
604 {"Rx Mixer", "RXN", "RXN"},
607 {"Mic 1 Volume", NULL
, "MIC1N"},
608 {"Mic 1 Volume", NULL
, "Mic Selection Mux"},
611 {"Mic 2 Volume", NULL
, "MIC2N"},
612 {"Mic 2 Volume", NULL
, "MIC2"},
614 /* Mic Selector Mux */
615 {"Mic Selection Mux", "Mic 1", "MIC1"},
616 {"Mic Selection Mux", "Mic 2", "MIC2N"},
617 {"Mic Selection Mux", "Mic 3", "MIC2"},
620 {"ACOP", NULL
, "ALC Mixer"},
623 static int wm8753_add_widgets(struct snd_soc_codec
*codec
)
625 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
627 snd_soc_dapm_new_controls(dapm
, wm8753_dapm_widgets
,
628 ARRAY_SIZE(wm8753_dapm_widgets
));
629 snd_soc_dapm_add_routes(dapm
, audio_map
, ARRAY_SIZE(audio_map
));
641 /* The size in bits of the pll divide multiplied by 10
642 * to allow rounding later */
643 #define FIXED_PLL_SIZE ((1 << 22) * 10)
645 static void pll_factors(struct _pll_div
*pll_div
, unsigned int target
,
649 unsigned int K
, Ndiv
, Nmod
;
651 Ndiv
= target
/ source
;
655 Ndiv
= target
/ source
;
659 if ((Ndiv
< 6) || (Ndiv
> 12))
661 "wm8753: unsupported N = %u\n", Ndiv
);
664 Nmod
= target
% source
;
665 Kpart
= FIXED_PLL_SIZE
* (long long)Nmod
;
667 do_div(Kpart
, source
);
669 K
= Kpart
& 0xFFFFFFFF;
671 /* Check if we need to round */
675 /* Move down to proper range now rounding is done */
681 static int wm8753_set_dai_pll(struct snd_soc_dai
*codec_dai
, int pll_id
,
682 int source
, unsigned int freq_in
, unsigned int freq_out
)
686 struct snd_soc_codec
*codec
= codec_dai
->codec
;
688 if (pll_id
< WM8753_PLL1
|| pll_id
> WM8753_PLL2
)
691 if (pll_id
== WM8753_PLL1
) {
694 reg
= snd_soc_read(codec
, WM8753_CLOCK
) & 0xffef;
698 reg
= snd_soc_read(codec
, WM8753_CLOCK
) & 0xfff7;
701 if (!freq_in
|| !freq_out
) {
703 snd_soc_write(codec
, WM8753_PLL1CTL1
+ offset
, 0x0026);
704 snd_soc_write(codec
, WM8753_CLOCK
, reg
);
708 struct _pll_div pll_div
;
710 pll_factors(&pll_div
, freq_out
* 8, freq_in
);
712 /* set up N and K PLL divisor ratios */
713 /* bits 8:5 = PLL_N, bits 3:0 = PLL_K[21:18] */
714 value
= (pll_div
.n
<< 5) + ((pll_div
.k
& 0x3c0000) >> 18);
715 snd_soc_write(codec
, WM8753_PLL1CTL2
+ offset
, value
);
717 /* bits 8:0 = PLL_K[17:9] */
718 value
= (pll_div
.k
& 0x03fe00) >> 9;
719 snd_soc_write(codec
, WM8753_PLL1CTL3
+ offset
, value
);
721 /* bits 8:0 = PLL_K[8:0] */
722 value
= pll_div
.k
& 0x0001ff;
723 snd_soc_write(codec
, WM8753_PLL1CTL4
+ offset
, value
);
725 /* set PLL as input and enable */
726 snd_soc_write(codec
, WM8753_PLL1CTL1
+ offset
, 0x0027 |
727 (pll_div
.div2
<< 3));
728 snd_soc_write(codec
, WM8753_CLOCK
, reg
| enable
);
740 /* codec hifi mclk (after PLL) clock divider coefficients */
741 static const struct _coeff_div coeff_div
[] = {
743 {12288000, 8000, 0x6, 0x0},
744 {11289600, 8000, 0x16, 0x0},
745 {18432000, 8000, 0x7, 0x0},
746 {16934400, 8000, 0x17, 0x0},
747 {12000000, 8000, 0x6, 0x1},
750 {11289600, 11025, 0x18, 0x0},
751 {16934400, 11025, 0x19, 0x0},
752 {12000000, 11025, 0x19, 0x1},
755 {12288000, 16000, 0xa, 0x0},
756 {18432000, 16000, 0xb, 0x0},
757 {12000000, 16000, 0xa, 0x1},
760 {11289600, 22050, 0x1a, 0x0},
761 {16934400, 22050, 0x1b, 0x0},
762 {12000000, 22050, 0x1b, 0x1},
765 {12288000, 32000, 0xc, 0x0},
766 {18432000, 32000, 0xd, 0x0},
767 {12000000, 32000, 0xa, 0x1},
770 {11289600, 44100, 0x10, 0x0},
771 {16934400, 44100, 0x11, 0x0},
772 {12000000, 44100, 0x11, 0x1},
775 {12288000, 48000, 0x0, 0x0},
776 {18432000, 48000, 0x1, 0x0},
777 {12000000, 48000, 0x0, 0x1},
780 {11289600, 88200, 0x1e, 0x0},
781 {16934400, 88200, 0x1f, 0x0},
782 {12000000, 88200, 0x1f, 0x1},
785 {12288000, 96000, 0xe, 0x0},
786 {18432000, 96000, 0xf, 0x0},
787 {12000000, 96000, 0xe, 0x1},
790 static int get_coeff(int mclk
, int rate
)
794 for (i
= 0; i
< ARRAY_SIZE(coeff_div
); i
++) {
795 if (coeff_div
[i
].rate
== rate
&& coeff_div
[i
].mclk
== mclk
)
802 * Clock after PLL and dividers
804 static int wm8753_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
805 int clk_id
, unsigned int freq
, int dir
)
807 struct snd_soc_codec
*codec
= codec_dai
->codec
;
808 struct wm8753_priv
*wm8753
= snd_soc_codec_get_drvdata(codec
);
816 if (clk_id
== WM8753_MCLK
) {
817 wm8753
->sysclk
= freq
;
819 } else if (clk_id
== WM8753_PCMCLK
) {
820 wm8753
->pcmclk
= freq
;
829 * Set's ADC and Voice DAC format.
831 static int wm8753_vdac_adc_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
834 struct snd_soc_codec
*codec
= codec_dai
->codec
;
835 u16 voice
= snd_soc_read(codec
, WM8753_PCM
) & 0x01ec;
837 /* interface format */
838 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
839 case SND_SOC_DAIFMT_I2S
:
842 case SND_SOC_DAIFMT_RIGHT_J
:
844 case SND_SOC_DAIFMT_LEFT_J
:
847 case SND_SOC_DAIFMT_DSP_A
:
850 case SND_SOC_DAIFMT_DSP_B
:
857 snd_soc_write(codec
, WM8753_PCM
, voice
);
861 static int wm8753_pcm_startup(struct snd_pcm_substream
*substream
,
862 struct snd_soc_dai
*dai
)
864 wm8753_set_dai_mode(dai
->codec
, dai
, 0);
869 * Set PCM DAI bit size and sample rate.
871 static int wm8753_pcm_hw_params(struct snd_pcm_substream
*substream
,
872 struct snd_pcm_hw_params
*params
,
873 struct snd_soc_dai
*dai
)
875 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
876 struct snd_soc_codec
*codec
= rtd
->codec
;
877 struct wm8753_priv
*wm8753
= snd_soc_codec_get_drvdata(codec
);
878 u16 voice
= snd_soc_read(codec
, WM8753_PCM
) & 0x01f3;
879 u16 srate
= snd_soc_read(codec
, WM8753_SRATE1
) & 0x017f;
882 switch (params_format(params
)) {
883 case SNDRV_PCM_FORMAT_S16_LE
:
885 case SNDRV_PCM_FORMAT_S20_3LE
:
888 case SNDRV_PCM_FORMAT_S24_LE
:
891 case SNDRV_PCM_FORMAT_S32_LE
:
897 if (params_rate(params
) * 384 == wm8753
->pcmclk
)
899 snd_soc_write(codec
, WM8753_SRATE1
, srate
);
901 snd_soc_write(codec
, WM8753_PCM
, voice
);
906 * Set's PCM dai fmt and BCLK.
908 static int wm8753_pcm_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
911 struct snd_soc_codec
*codec
= codec_dai
->codec
;
914 voice
= snd_soc_read(codec
, WM8753_PCM
) & 0x011f;
915 ioctl
= snd_soc_read(codec
, WM8753_IOCTL
) & 0x015d;
917 /* set master/slave audio interface */
918 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
919 case SND_SOC_DAIFMT_CBS_CFS
:
921 case SND_SOC_DAIFMT_CBM_CFM
:
923 case SND_SOC_DAIFMT_CBM_CFS
:
930 /* clock inversion */
931 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
932 case SND_SOC_DAIFMT_DSP_A
:
933 case SND_SOC_DAIFMT_DSP_B
:
934 /* frame inversion not valid for DSP modes */
935 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
936 case SND_SOC_DAIFMT_NB_NF
:
938 case SND_SOC_DAIFMT_IB_NF
:
945 case SND_SOC_DAIFMT_I2S
:
946 case SND_SOC_DAIFMT_RIGHT_J
:
947 case SND_SOC_DAIFMT_LEFT_J
:
949 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
950 case SND_SOC_DAIFMT_NB_NF
:
952 case SND_SOC_DAIFMT_IB_IF
:
955 case SND_SOC_DAIFMT_IB_NF
:
958 case SND_SOC_DAIFMT_NB_IF
:
969 snd_soc_write(codec
, WM8753_PCM
, voice
);
970 snd_soc_write(codec
, WM8753_IOCTL
, ioctl
);
974 static int wm8753_set_dai_clkdiv(struct snd_soc_dai
*codec_dai
,
977 struct snd_soc_codec
*codec
= codec_dai
->codec
;
982 reg
= snd_soc_read(codec
, WM8753_CLOCK
) & 0x003f;
983 snd_soc_write(codec
, WM8753_CLOCK
, reg
| div
);
986 reg
= snd_soc_read(codec
, WM8753_SRATE2
) & 0x01c7;
987 snd_soc_write(codec
, WM8753_SRATE2
, reg
| div
);
989 case WM8753_VXCLKDIV
:
990 reg
= snd_soc_read(codec
, WM8753_SRATE2
) & 0x003f;
991 snd_soc_write(codec
, WM8753_SRATE2
, reg
| div
);
1000 * Set's HiFi DAC format.
1002 static int wm8753_hdac_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
1005 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1006 u16 hifi
= snd_soc_read(codec
, WM8753_HIFI
) & 0x01e0;
1008 /* interface format */
1009 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1010 case SND_SOC_DAIFMT_I2S
:
1013 case SND_SOC_DAIFMT_RIGHT_J
:
1015 case SND_SOC_DAIFMT_LEFT_J
:
1018 case SND_SOC_DAIFMT_DSP_A
:
1021 case SND_SOC_DAIFMT_DSP_B
:
1028 snd_soc_write(codec
, WM8753_HIFI
, hifi
);
1033 * Set's I2S DAI format.
1035 static int wm8753_i2s_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
1038 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1041 hifi
= snd_soc_read(codec
, WM8753_HIFI
) & 0x011f;
1042 ioctl
= snd_soc_read(codec
, WM8753_IOCTL
) & 0x00ae;
1044 /* set master/slave audio interface */
1045 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1046 case SND_SOC_DAIFMT_CBS_CFS
:
1048 case SND_SOC_DAIFMT_CBM_CFM
:
1050 case SND_SOC_DAIFMT_CBM_CFS
:
1057 /* clock inversion */
1058 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1059 case SND_SOC_DAIFMT_DSP_A
:
1060 case SND_SOC_DAIFMT_DSP_B
:
1061 /* frame inversion not valid for DSP modes */
1062 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1063 case SND_SOC_DAIFMT_NB_NF
:
1065 case SND_SOC_DAIFMT_IB_NF
:
1072 case SND_SOC_DAIFMT_I2S
:
1073 case SND_SOC_DAIFMT_RIGHT_J
:
1074 case SND_SOC_DAIFMT_LEFT_J
:
1076 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1077 case SND_SOC_DAIFMT_NB_NF
:
1079 case SND_SOC_DAIFMT_IB_IF
:
1082 case SND_SOC_DAIFMT_IB_NF
:
1085 case SND_SOC_DAIFMT_NB_IF
:
1096 snd_soc_write(codec
, WM8753_HIFI
, hifi
);
1097 snd_soc_write(codec
, WM8753_IOCTL
, ioctl
);
1101 static int wm8753_i2s_startup(struct snd_pcm_substream
*substream
,
1102 struct snd_soc_dai
*dai
)
1104 wm8753_set_dai_mode(dai
->codec
, dai
, 1);
1109 * Set PCM DAI bit size and sample rate.
1111 static int wm8753_i2s_hw_params(struct snd_pcm_substream
*substream
,
1112 struct snd_pcm_hw_params
*params
,
1113 struct snd_soc_dai
*dai
)
1115 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
1116 struct snd_soc_codec
*codec
= rtd
->codec
;
1117 struct wm8753_priv
*wm8753
= snd_soc_codec_get_drvdata(codec
);
1118 u16 srate
= snd_soc_read(codec
, WM8753_SRATE1
) & 0x01c0;
1119 u16 hifi
= snd_soc_read(codec
, WM8753_HIFI
) & 0x01f3;
1122 /* is digital filter coefficient valid ? */
1123 coeff
= get_coeff(wm8753
->sysclk
, params_rate(params
));
1125 printk(KERN_ERR
"wm8753 invalid MCLK or rate\n");
1128 snd_soc_write(codec
, WM8753_SRATE1
, srate
| (coeff_div
[coeff
].sr
<< 1) |
1129 coeff_div
[coeff
].usb
);
1132 switch (params_format(params
)) {
1133 case SNDRV_PCM_FORMAT_S16_LE
:
1135 case SNDRV_PCM_FORMAT_S20_3LE
:
1138 case SNDRV_PCM_FORMAT_S24_LE
:
1141 case SNDRV_PCM_FORMAT_S32_LE
:
1146 snd_soc_write(codec
, WM8753_HIFI
, hifi
);
1150 static int wm8753_mode1v_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
1153 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1156 /* set clk source as pcmclk */
1157 clock
= snd_soc_read(codec
, WM8753_CLOCK
) & 0xfffb;
1158 snd_soc_write(codec
, WM8753_CLOCK
, clock
);
1160 if (wm8753_vdac_adc_set_dai_fmt(codec_dai
, fmt
) < 0)
1162 return wm8753_pcm_set_dai_fmt(codec_dai
, fmt
);
1165 static int wm8753_mode1h_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
1168 if (wm8753_hdac_set_dai_fmt(codec_dai
, fmt
) < 0)
1170 return wm8753_i2s_set_dai_fmt(codec_dai
, fmt
);
1173 static int wm8753_mode2_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
1176 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1179 /* set clk source as pcmclk */
1180 clock
= snd_soc_read(codec
, WM8753_CLOCK
) & 0xfffb;
1181 snd_soc_write(codec
, WM8753_CLOCK
, clock
);
1183 if (wm8753_vdac_adc_set_dai_fmt(codec_dai
, fmt
) < 0)
1185 return wm8753_i2s_set_dai_fmt(codec_dai
, fmt
);
1188 static int wm8753_mode3_4_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
1191 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1194 /* set clk source as mclk */
1195 clock
= snd_soc_read(codec
, WM8753_CLOCK
) & 0xfffb;
1196 snd_soc_write(codec
, WM8753_CLOCK
, clock
| 0x4);
1198 if (wm8753_hdac_set_dai_fmt(codec_dai
, fmt
) < 0)
1200 if (wm8753_vdac_adc_set_dai_fmt(codec_dai
, fmt
) < 0)
1202 return wm8753_i2s_set_dai_fmt(codec_dai
, fmt
);
1205 static int wm8753_mute(struct snd_soc_dai
*dai
, int mute
)
1207 struct snd_soc_codec
*codec
= dai
->codec
;
1208 u16 mute_reg
= snd_soc_read(codec
, WM8753_DAC
) & 0xfff7;
1209 struct wm8753_priv
*wm8753
= snd_soc_codec_get_drvdata(codec
);
1211 /* the digital mute covers the HiFi and Voice DAC's on the WM8753.
1212 * make sure we check if they are not both active when we mute */
1213 if (mute
&& wm8753
->dai_func
== 1) {
1215 snd_soc_write(codec
, WM8753_DAC
, mute_reg
| 0x8);
1218 snd_soc_write(codec
, WM8753_DAC
, mute_reg
| 0x8);
1220 snd_soc_write(codec
, WM8753_DAC
, mute_reg
);
1226 static int wm8753_set_bias_level(struct snd_soc_codec
*codec
,
1227 enum snd_soc_bias_level level
)
1229 u16 pwr_reg
= snd_soc_read(codec
, WM8753_PWR1
) & 0xfe3e;
1232 case SND_SOC_BIAS_ON
:
1233 /* set vmid to 50k and unmute dac */
1234 snd_soc_write(codec
, WM8753_PWR1
, pwr_reg
| 0x00c0);
1236 case SND_SOC_BIAS_PREPARE
:
1237 /* set vmid to 5k for quick power up */
1238 snd_soc_write(codec
, WM8753_PWR1
, pwr_reg
| 0x01c1);
1240 case SND_SOC_BIAS_STANDBY
:
1241 /* mute dac and set vmid to 500k, enable VREF */
1242 snd_soc_write(codec
, WM8753_PWR1
, pwr_reg
| 0x0141);
1244 case SND_SOC_BIAS_OFF
:
1245 snd_soc_write(codec
, WM8753_PWR1
, 0x0001);
1248 codec
->dapm
.bias_level
= level
;
1252 #define WM8753_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
1253 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
1254 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
1255 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
1257 #define WM8753_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1258 SNDRV_PCM_FMTBIT_S24_LE)
1261 * The WM8753 supports upto 4 different and mutually exclusive DAI
1262 * configurations. This gives 2 PCM's available for use, hifi and voice.
1263 * NOTE: The Voice PCM cannot play or capture audio to the CPU as it's DAI
1264 * is connected between the wm8753 and a BT codec or GSM modem.
1266 * 1. Voice over PCM DAI - HIFI DAC over HIFI DAI
1267 * 2. Voice over HIFI DAI - HIFI disabled
1268 * 3. Voice disabled - HIFI over HIFI
1269 * 4. Voice disabled - HIFI over HIFI, uses voice DAI LRC for capture
1271 static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode1
= {
1272 .startup
= wm8753_i2s_startup
,
1273 .hw_params
= wm8753_i2s_hw_params
,
1274 .digital_mute
= wm8753_mute
,
1275 .set_fmt
= wm8753_mode1h_set_dai_fmt
,
1276 .set_clkdiv
= wm8753_set_dai_clkdiv
,
1277 .set_pll
= wm8753_set_dai_pll
,
1278 .set_sysclk
= wm8753_set_dai_sysclk
,
1281 static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode1
= {
1282 .startup
= wm8753_pcm_startup
,
1283 .hw_params
= wm8753_pcm_hw_params
,
1284 .digital_mute
= wm8753_mute
,
1285 .set_fmt
= wm8753_mode1v_set_dai_fmt
,
1286 .set_clkdiv
= wm8753_set_dai_clkdiv
,
1287 .set_pll
= wm8753_set_dai_pll
,
1288 .set_sysclk
= wm8753_set_dai_sysclk
,
1291 static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode2
= {
1292 .startup
= wm8753_pcm_startup
,
1293 .hw_params
= wm8753_pcm_hw_params
,
1294 .digital_mute
= wm8753_mute
,
1295 .set_fmt
= wm8753_mode2_set_dai_fmt
,
1296 .set_clkdiv
= wm8753_set_dai_clkdiv
,
1297 .set_pll
= wm8753_set_dai_pll
,
1298 .set_sysclk
= wm8753_set_dai_sysclk
,
1301 static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode3
= {
1302 .startup
= wm8753_i2s_startup
,
1303 .hw_params
= wm8753_i2s_hw_params
,
1304 .digital_mute
= wm8753_mute
,
1305 .set_fmt
= wm8753_mode3_4_set_dai_fmt
,
1306 .set_clkdiv
= wm8753_set_dai_clkdiv
,
1307 .set_pll
= wm8753_set_dai_pll
,
1308 .set_sysclk
= wm8753_set_dai_sysclk
,
1311 static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode4
= {
1312 .startup
= wm8753_i2s_startup
,
1313 .hw_params
= wm8753_i2s_hw_params
,
1314 .digital_mute
= wm8753_mute
,
1315 .set_fmt
= wm8753_mode3_4_set_dai_fmt
,
1316 .set_clkdiv
= wm8753_set_dai_clkdiv
,
1317 .set_pll
= wm8753_set_dai_pll
,
1318 .set_sysclk
= wm8753_set_dai_sysclk
,
1321 static struct snd_soc_dai_driver wm8753_all_dai
[] = {
1322 /* DAI HiFi mode 1 */
1323 { .name
= "wm8753-hifi",
1325 .stream_name
= "HiFi Playback",
1328 .rates
= WM8753_RATES
,
1329 .formats
= WM8753_FORMATS
},
1330 .capture
= { /* dummy for fast DAI switching */
1331 .stream_name
= "Capture",
1334 .rates
= WM8753_RATES
,
1335 .formats
= WM8753_FORMATS
},
1336 .ops
= &wm8753_dai_ops_hifi_mode1
,
1338 /* DAI Voice mode 1 */
1339 { .name
= "wm8753-voice",
1341 .stream_name
= "Voice Playback",
1344 .rates
= WM8753_RATES
,
1345 .formats
= WM8753_FORMATS
,},
1347 .stream_name
= "Capture",
1350 .rates
= WM8753_RATES
,
1351 .formats
= WM8753_FORMATS
,},
1352 .ops
= &wm8753_dai_ops_voice_mode1
,
1354 /* DAI HiFi mode 2 - dummy */
1355 { .name
= "wm8753-hifi",
1357 /* DAI Voice mode 2 */
1358 { .name
= "wm8753-voice",
1360 .stream_name
= "Voice Playback",
1363 .rates
= WM8753_RATES
,
1364 .formats
= WM8753_FORMATS
,},
1366 .stream_name
= "Capture",
1369 .rates
= WM8753_RATES
,
1370 .formats
= WM8753_FORMATS
,},
1371 .ops
= &wm8753_dai_ops_voice_mode2
,
1373 /* DAI HiFi mode 3 */
1374 { .name
= "wm8753-hifi",
1376 .stream_name
= "HiFi Playback",
1379 .rates
= WM8753_RATES
,
1380 .formats
= WM8753_FORMATS
,},
1382 .stream_name
= "Capture",
1385 .rates
= WM8753_RATES
,
1386 .formats
= WM8753_FORMATS
,},
1387 .ops
= &wm8753_dai_ops_hifi_mode3
,
1389 /* DAI Voice mode 3 - dummy */
1390 { .name
= "wm8753-voice",
1392 /* DAI HiFi mode 4 */
1393 { .name
= "wm8753-hifi",
1395 .stream_name
= "HiFi Playback",
1398 .rates
= WM8753_RATES
,
1399 .formats
= WM8753_FORMATS
,},
1401 .stream_name
= "Capture",
1404 .rates
= WM8753_RATES
,
1405 .formats
= WM8753_FORMATS
,},
1406 .ops
= &wm8753_dai_ops_hifi_mode4
,
1408 /* DAI Voice mode 4 - dummy */
1409 { .name
= "wm8753-voice",
1413 static struct snd_soc_dai_driver wm8753_dai
[] = {
1415 .name
= "wm8753-aif0",
1418 .name
= "wm8753-aif1",
1422 static void wm8753_set_dai_mode(struct snd_soc_codec
*codec
,
1423 struct snd_soc_dai
*dai
, unsigned int hifi
)
1425 struct wm8753_priv
*wm8753
= snd_soc_codec_get_drvdata(codec
);
1427 if (wm8753
->dai_func
< 4) {
1429 dai
->driver
= &wm8753_all_dai
[wm8753
->dai_func
<< 1];
1431 dai
->driver
= &wm8753_all_dai
[(wm8753
->dai_func
<< 1) + 1];
1433 snd_soc_write(codec
, WM8753_IOCTL
, wm8753
->dai_func
);
1436 static void wm8753_work(struct work_struct
*work
)
1438 struct snd_soc_dapm_context
*dapm
=
1439 container_of(work
, struct snd_soc_dapm_context
,
1441 struct snd_soc_codec
*codec
= dapm
->codec
;
1442 wm8753_set_bias_level(codec
, dapm
->bias_level
);
1445 static int wm8753_suspend(struct snd_soc_codec
*codec
, pm_message_t state
)
1447 wm8753_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
1451 static int wm8753_resume(struct snd_soc_codec
*codec
)
1453 u16
*reg_cache
= codec
->reg_cache
;
1456 /* Sync reg_cache with the hardware */
1457 for (i
= 1; i
< ARRAY_SIZE(wm8753_reg
); i
++) {
1458 if (i
== WM8753_RESET
)
1461 /* No point in writing hardware default values back */
1462 if (reg_cache
[i
] == wm8753_reg
[i
])
1465 snd_soc_write(codec
, i
, reg_cache
[i
]);
1468 wm8753_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
1470 /* charge wm8753 caps */
1471 if (codec
->dapm
.suspend_bias_level
== SND_SOC_BIAS_ON
) {
1472 wm8753_set_bias_level(codec
, SND_SOC_BIAS_PREPARE
);
1473 codec
->dapm
.bias_level
= SND_SOC_BIAS_ON
;
1474 schedule_delayed_work(&codec
->dapm
.delayed_work
,
1475 msecs_to_jiffies(caps_charge
));
1481 static int wm8753_probe(struct snd_soc_codec
*codec
)
1483 struct wm8753_priv
*wm8753
= snd_soc_codec_get_drvdata(codec
);
1486 INIT_DELAYED_WORK(&codec
->dapm
.delayed_work
, wm8753_work
);
1488 ret
= snd_soc_codec_set_cache_io(codec
, 7, 9, wm8753
->control_type
);
1490 dev_err(codec
->dev
, "Failed to set cache I/O: %d\n", ret
);
1494 ret
= wm8753_reset(codec
);
1496 dev_err(codec
->dev
, "Failed to issue reset: %d\n", ret
);
1500 wm8753_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
1501 wm8753
->dai_func
= 0;
1503 /* charge output caps */
1504 wm8753_set_bias_level(codec
, SND_SOC_BIAS_PREPARE
);
1505 schedule_delayed_work(&codec
->dapm
.delayed_work
,
1506 msecs_to_jiffies(caps_charge
));
1508 /* set the update bits */
1509 snd_soc_update_bits(codec
, WM8753_LDAC
, 0x0100, 0x0100);
1510 snd_soc_update_bits(codec
, WM8753_RDAC
, 0x0100, 0x0100);
1511 snd_soc_update_bits(codec
, WM8753_LDAC
, 0x0100, 0x0100);
1512 snd_soc_update_bits(codec
, WM8753_RDAC
, 0x0100, 0x0100);
1513 snd_soc_update_bits(codec
, WM8753_LOUT1V
, 0x0100, 0x0100);
1514 snd_soc_update_bits(codec
, WM8753_ROUT1V
, 0x0100, 0x0100);
1515 snd_soc_update_bits(codec
, WM8753_LOUT2V
, 0x0100, 0x0100);
1516 snd_soc_update_bits(codec
, WM8753_ROUT2V
, 0x0100, 0x0100);
1517 snd_soc_update_bits(codec
, WM8753_LINVOL
, 0x0100, 0x0100);
1518 snd_soc_update_bits(codec
, WM8753_RINVOL
, 0x0100, 0x0100);
1520 snd_soc_add_controls(codec
, wm8753_snd_controls
,
1521 ARRAY_SIZE(wm8753_snd_controls
));
1522 wm8753_add_widgets(codec
);
1527 /* power down chip */
1528 static int wm8753_remove(struct snd_soc_codec
*codec
)
1530 flush_delayed_work_sync(&codec
->dapm
.delayed_work
);
1531 wm8753_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
1536 static struct snd_soc_codec_driver soc_codec_dev_wm8753
= {
1537 .probe
= wm8753_probe
,
1538 .remove
= wm8753_remove
,
1539 .suspend
= wm8753_suspend
,
1540 .resume
= wm8753_resume
,
1541 .set_bias_level
= wm8753_set_bias_level
,
1542 .reg_cache_size
= ARRAY_SIZE(wm8753_reg
),
1543 .reg_word_size
= sizeof(u16
),
1544 .reg_cache_default
= wm8753_reg
,
1547 #if defined(CONFIG_SPI_MASTER)
1548 static int __devinit
wm8753_spi_probe(struct spi_device
*spi
)
1550 struct wm8753_priv
*wm8753
;
1553 wm8753
= kzalloc(sizeof(struct wm8753_priv
), GFP_KERNEL
);
1557 wm8753
->control_type
= SND_SOC_SPI
;
1558 spi_set_drvdata(spi
, wm8753
);
1560 ret
= snd_soc_register_codec(&spi
->dev
,
1561 &soc_codec_dev_wm8753
, wm8753_dai
, ARRAY_SIZE(wm8753_dai
));
1567 static int __devexit
wm8753_spi_remove(struct spi_device
*spi
)
1569 snd_soc_unregister_codec(&spi
->dev
);
1570 kfree(spi_get_drvdata(spi
));
1574 static struct spi_driver wm8753_spi_driver
= {
1576 .name
= "wm8753-codec",
1577 .owner
= THIS_MODULE
,
1579 .probe
= wm8753_spi_probe
,
1580 .remove
= __devexit_p(wm8753_spi_remove
),
1582 #endif /* CONFIG_SPI_MASTER */
1584 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1585 static __devinit
int wm8753_i2c_probe(struct i2c_client
*i2c
,
1586 const struct i2c_device_id
*id
)
1588 struct wm8753_priv
*wm8753
;
1591 wm8753
= kzalloc(sizeof(struct wm8753_priv
), GFP_KERNEL
);
1595 i2c_set_clientdata(i2c
, wm8753
);
1596 wm8753
->control_type
= SND_SOC_I2C
;
1598 ret
= snd_soc_register_codec(&i2c
->dev
,
1599 &soc_codec_dev_wm8753
, wm8753_dai
, ARRAY_SIZE(wm8753_dai
));
1605 static __devexit
int wm8753_i2c_remove(struct i2c_client
*client
)
1607 snd_soc_unregister_codec(&client
->dev
);
1608 kfree(i2c_get_clientdata(client
));
1612 static const struct i2c_device_id wm8753_i2c_id
[] = {
1616 MODULE_DEVICE_TABLE(i2c
, wm8753_i2c_id
);
1618 static struct i2c_driver wm8753_i2c_driver
= {
1620 .name
= "wm8753-codec",
1621 .owner
= THIS_MODULE
,
1623 .probe
= wm8753_i2c_probe
,
1624 .remove
= __devexit_p(wm8753_i2c_remove
),
1625 .id_table
= wm8753_i2c_id
,
1629 static int __init
wm8753_modinit(void)
1632 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1633 ret
= i2c_add_driver(&wm8753_i2c_driver
);
1635 printk(KERN_ERR
"Failed to register wm8753 I2C driver: %d\n",
1639 #if defined(CONFIG_SPI_MASTER)
1640 ret
= spi_register_driver(&wm8753_spi_driver
);
1642 printk(KERN_ERR
"Failed to register wm8753 SPI driver: %d\n",
1648 module_init(wm8753_modinit
);
1650 static void __exit
wm8753_exit(void)
1652 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1653 i2c_del_driver(&wm8753_i2c_driver
);
1655 #if defined(CONFIG_SPI_MASTER)
1656 spi_unregister_driver(&wm8753_spi_driver
);
1659 module_exit(wm8753_exit
);
1661 MODULE_DESCRIPTION("ASoC WM8753 driver");
1662 MODULE_AUTHOR("Liam Girdwood");
1663 MODULE_LICENSE("GPL");