diff options
-rw-r--r-- | include/linux/i2c-id.h | 1 | ||||
-rw-r--r-- | sound/soc/codecs/wm8753.c | 1811 | ||||
-rw-r--r-- | sound/soc/codecs/wm8753.h | 126 |
3 files changed, 1938 insertions, 0 deletions
diff --git a/include/linux/i2c-id.h b/include/linux/i2c-id.h index 0e8da684ce68..aa83d4163096 100644 --- a/include/linux/i2c-id.h +++ b/include/linux/i2c-id.h | |||
@@ -117,6 +117,7 @@ | |||
117 | #define I2C_DRIVERID_ISL1208 88 /* Intersil ISL1208 RTC */ | 117 | #define I2C_DRIVERID_ISL1208 88 /* Intersil ISL1208 RTC */ |
118 | #define I2C_DRIVERID_WM8731 89 /* Wolfson WM8731 audio codec */ | 118 | #define I2C_DRIVERID_WM8731 89 /* Wolfson WM8731 audio codec */ |
119 | #define I2C_DRIVERID_WM8750 90 /* Wolfson WM8750 audio codec */ | 119 | #define I2C_DRIVERID_WM8750 90 /* Wolfson WM8750 audio codec */ |
120 | #define I2C_DRIVERID_WM8753 91 /* Wolfson WM8753 audio codec */ | ||
120 | 121 | ||
121 | #define I2C_DRIVERID_I2CDEV 900 | 122 | #define I2C_DRIVERID_I2CDEV 900 |
122 | #define I2C_DRIVERID_ARP 902 /* SMBus ARP Client */ | 123 | #define I2C_DRIVERID_ARP 902 /* SMBus ARP Client */ |
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c new file mode 100644 index 000000000000..efced934566d --- /dev/null +++ b/sound/soc/codecs/wm8753.c | |||
@@ -0,0 +1,1811 @@ | |||
1 | /* | ||
2 | * wm8753.c -- WM8753 ALSA Soc Audio driver | ||
3 | * | ||
4 | * Copyright 2003 Wolfson Microelectronics PLC. | ||
5 | * Author: Liam Girdwood | ||
6 | * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | * Notes: | ||
14 | * The WM8753 is a low power, high quality stereo codec with integrated PCM | ||
15 | * codec designed for portable digital telephony applications. | ||
16 | * | ||
17 | * Dual DAI:- | ||
18 | * | ||
19 | * This driver support 2 DAI PCM's. This makes the default PCM available for | ||
20 | * HiFi audio (e.g. MP3, ogg) playback/capture and the other PCM available for | ||
21 | * voice. | ||
22 | * | ||
23 | * Please note that the voice PCM can be connected directly to a Bluetooth | ||
24 | * codec or GSM modem and thus cannot be read or written to, although it is | ||
25 | * available to be configured with snd_hw_params(), etc and kcontrols in the | ||
26 | * normal alsa manner. | ||
27 | * | ||
28 | * Fast DAI switching:- | ||
29 | * | ||
30 | * The driver can now fast switch between the DAI configurations via a | ||
31 | * an alsa kcontrol. This allows the PCM to remain open. | ||
32 | * | ||
33 | */ | ||
34 | |||
35 | #include <linux/module.h> | ||
36 | #include <linux/moduleparam.h> | ||
37 | #include <linux/version.h> | ||
38 | #include <linux/kernel.h> | ||
39 | #include <linux/init.h> | ||
40 | #include <linux/delay.h> | ||
41 | #include <linux/pm.h> | ||
42 | #include <linux/i2c.h> | ||
43 | #include <linux/platform_device.h> | ||
44 | #include <sound/driver.h> | ||
45 | #include <sound/core.h> | ||
46 | #include <sound/pcm.h> | ||
47 | #include <sound/pcm_params.h> | ||
48 | #include <sound/soc.h> | ||
49 | #include <sound/soc-dapm.h> | ||
50 | #include <sound/initval.h> | ||
51 | #include <asm/div64.h> | ||
52 | |||
53 | #include "wm8753.h" | ||
54 | |||
55 | #define AUDIO_NAME "wm8753" | ||
56 | #define WM8753_VERSION "0.16" | ||
57 | |||
58 | /* | ||
59 | * Debug | ||
60 | */ | ||
61 | |||
62 | #define WM8753_DEBUG 0 | ||
63 | |||
64 | #ifdef WM8753_DEBUG | ||
65 | #define dbg(format, arg...) \ | ||
66 | printk(KERN_DEBUG AUDIO_NAME ": " format "\n" , ## arg) | ||
67 | #else | ||
68 | #define dbg(format, arg...) do {} while (0) | ||
69 | #endif | ||
70 | #define err(format, arg...) \ | ||
71 | printk(KERN_ERR AUDIO_NAME ": " format "\n" , ## arg) | ||
72 | #define info(format, arg...) \ | ||
73 | printk(KERN_INFO AUDIO_NAME ": " format "\n" , ## arg) | ||
74 | #define warn(format, arg...) \ | ||
75 | printk(KERN_WARNING AUDIO_NAME ": " format "\n" , ## arg) | ||
76 | |||
77 | static int caps_charge = 2000; | ||
78 | module_param(caps_charge, int, 0); | ||
79 | MODULE_PARM_DESC(caps_charge, "WM8753 cap charge time (msecs)"); | ||
80 | |||
81 | static void wm8753_set_dai_mode(struct snd_soc_codec *codec, | ||
82 | unsigned int mode); | ||
83 | |||
84 | /* codec private data */ | ||
85 | struct wm8753_priv { | ||
86 | unsigned int sysclk; | ||
87 | unsigned int pcmclk; | ||
88 | }; | ||
89 | |||
90 | /* | ||
91 | * wm8753 register cache | ||
92 | * We can't read the WM8753 register space when we | ||
93 | * are using 2 wire for device control, so we cache them instead. | ||
94 | */ | ||
95 | static const u16 wm8753_reg[] = { | ||
96 | 0x0008, 0x0000, 0x000a, 0x000a, | ||
97 | 0x0033, 0x0000, 0x0007, 0x00ff, | ||
98 | 0x00ff, 0x000f, 0x000f, 0x007b, | ||
99 | 0x0000, 0x0032, 0x0000, 0x00c3, | ||
100 | 0x00c3, 0x00c0, 0x0000, 0x0000, | ||
101 | 0x0000, 0x0000, 0x0000, 0x0000, | ||
102 | 0x0000, 0x0000, 0x0000, 0x0000, | ||
103 | 0x0000, 0x0000, 0x0000, 0x0055, | ||
104 | 0x0005, 0x0050, 0x0055, 0x0050, | ||
105 | 0x0055, 0x0050, 0x0055, 0x0079, | ||
106 | 0x0079, 0x0079, 0x0079, 0x0079, | ||
107 | 0x0000, 0x0000, 0x0000, 0x0000, | ||
108 | 0x0097, 0x0097, 0x0000, 0x0004, | ||
109 | 0x0000, 0x0083, 0x0024, 0x01ba, | ||
110 | 0x0000, 0x0083, 0x0024, 0x01ba, | ||
111 | 0x0000, 0x0000 | ||
112 | }; | ||
113 | |||
114 | /* | ||
115 | * read wm8753 register cache | ||
116 | */ | ||
117 | static inline unsigned int wm8753_read_reg_cache(struct snd_soc_codec *codec, | ||
118 | unsigned int reg) | ||
119 | { | ||
120 | u16 *cache = codec->reg_cache; | ||
121 | if (reg < 1 || reg > (ARRAY_SIZE(wm8753_reg) + 1)) | ||
122 | return -1; | ||
123 | return cache[reg - 1]; | ||
124 | } | ||
125 | |||
126 | /* | ||
127 | * write wm8753 register cache | ||
128 | */ | ||
129 | static inline void wm8753_write_reg_cache(struct snd_soc_codec *codec, | ||
130 | unsigned int reg, unsigned int value) | ||
131 | { | ||
132 | u16 *cache = codec->reg_cache; | ||
133 | if (reg < 1 || reg > 0x3f) | ||
134 | return; | ||
135 | cache[reg - 1] = value; | ||
136 | } | ||
137 | |||
138 | /* | ||
139 | * write to the WM8753 register space | ||
140 | */ | ||
141 | static int wm8753_write(struct snd_soc_codec *codec, unsigned int reg, | ||
142 | unsigned int value) | ||
143 | { | ||
144 | u8 data[2]; | ||
145 | |||
146 | /* data is | ||
147 | * D15..D9 WM8753 register offset | ||
148 | * D8...D0 register data | ||
149 | */ | ||
150 | data[0] = (reg << 1) | ((value >> 8) & 0x0001); | ||
151 | data[1] = value & 0x00ff; | ||
152 | |||
153 | wm8753_write_reg_cache (codec, reg, value); | ||
154 | if (codec->hw_write(codec->control_data, data, 2) == 2) | ||
155 | return 0; | ||
156 | else | ||
157 | return -EIO; | ||
158 | } | ||
159 | |||
160 | #define wm8753_reset(c) wm8753_write(c, WM8753_RESET, 0) | ||
161 | |||
162 | /* | ||
163 | * WM8753 Controls | ||
164 | */ | ||
165 | static const char *wm8753_base[] = {"Linear Control", "Adaptive Boost"}; | ||
166 | static const char *wm8753_base_filter[] = | ||
167 | {"130Hz @ 48kHz", "200Hz @ 48kHz", "100Hz @ 16kHz", "400Hz @ 48kHz", | ||
168 | "100Hz @ 8kHz", "200Hz @ 8kHz"}; | ||
169 | static const char *wm8753_treble[] = {"8kHz", "4kHz"}; | ||
170 | static const char *wm8753_alc_func[] = {"Off", "Right", "Left", "Stereo"}; | ||
171 | static const char *wm8753_ng_type[] = {"Constant PGA Gain", "Mute ADC Output"}; | ||
172 | static const char *wm8753_3d_func[] = {"Capture", "Playback"}; | ||
173 | static const char *wm8753_3d_uc[] = {"2.2kHz", "1.5kHz"}; | ||
174 | static const char *wm8753_3d_lc[] = {"200Hz", "500Hz"}; | ||
175 | static const char *wm8753_deemp[] = {"None", "32kHz", "44.1kHz", "48kHz"}; | ||
176 | static const char *wm8753_mono_mix[] = {"Stereo", "Left", "Right", "Mono"}; | ||
177 | static const char *wm8753_dac_phase[] = {"Non Inverted", "Inverted"}; | ||
178 | static const char *wm8753_line_mix[] = {"Line 1 + 2", "Line 1 - 2", | ||
179 | "Line 1", "Line 2"}; | ||
180 | static const char *wm8753_mono_mux[] = {"Line Mix", "Rx Mix"}; | ||
181 | static const char *wm8753_right_mux[] = {"Line 2", "Rx Mix"}; | ||
182 | static const char *wm8753_left_mux[] = {"Line 1", "Rx Mix"}; | ||
183 | static const char *wm8753_rxmsel[] = {"RXP - RXN", "RXP + RXN", "RXP", "RXN"}; | ||
184 | static const char *wm8753_sidetone_mux[] = {"Left PGA", "Mic 1", "Mic 2", | ||
185 | "Right PGA"}; | ||
186 | static const char *wm8753_mono2_src[] = {"Inverted Mono 1", "Left", "Right", | ||
187 | "Left + Right"}; | ||
188 | static const char *wm8753_out3[] = {"VREF", "ROUT2", "Left + Right"}; | ||
189 | static const char *wm8753_out4[] = {"VREF", "Capture ST", "LOUT2"}; | ||
190 | static const char *wm8753_radcsel[] = {"PGA", "Line or RXP-RXN", "Sidetone"}; | ||
191 | static const char *wm8753_ladcsel[] = {"PGA", "Line or RXP-RXN", "Line"}; | ||
192 | static const char *wm8753_mono_adc[] = {"Stereo", "Analogue Mix Left", | ||
193 | "Analogue Mix Right", "Digital Mono Mix"}; | ||
194 | static const char *wm8753_adc_hp[] = {"3.4Hz @ 48kHz", "82Hz @ 16k", | ||
195 | "82Hz @ 8kHz", "170Hz @ 8kHz"}; | ||
196 | static const char *wm8753_adc_filter[] = {"HiFi", "Voice"}; | ||
197 | static const char *wm8753_mic_sel[] = {"Mic 1", "Mic 2", "Mic 3"}; | ||
198 | static const char *wm8753_dai_mode[] = {"DAI 0", "DAI 1", "DAI 2", "DAI 3"}; | ||
199 | static const char *wm8753_dat_sel[] = {"Stereo", "Left ADC", "Right ADC", | ||
200 | "Channel Swap"}; | ||
201 | |||
202 | static const struct soc_enum wm8753_enum[] = { | ||
203 | SOC_ENUM_SINGLE(WM8753_BASS, 7, 2, wm8753_base), | ||
204 | SOC_ENUM_SINGLE(WM8753_BASS, 4, 6, wm8753_base_filter), | ||
205 | SOC_ENUM_SINGLE(WM8753_TREBLE, 6, 2, wm8753_treble), | ||
206 | SOC_ENUM_SINGLE(WM8753_ALC1, 7, 4, wm8753_alc_func), | ||
207 | SOC_ENUM_SINGLE(WM8753_NGATE, 1, 2, wm8753_ng_type), | ||
208 | SOC_ENUM_SINGLE(WM8753_3D, 7, 2, wm8753_3d_func), | ||
209 | SOC_ENUM_SINGLE(WM8753_3D, 6, 2, wm8753_3d_uc), | ||
210 | SOC_ENUM_SINGLE(WM8753_3D, 5, 2, wm8753_3d_lc), | ||
211 | SOC_ENUM_SINGLE(WM8753_DAC, 1, 4, wm8753_deemp), | ||
212 | SOC_ENUM_SINGLE(WM8753_DAC, 4, 4, wm8753_mono_mix), | ||
213 | SOC_ENUM_SINGLE(WM8753_DAC, 6, 2, wm8753_dac_phase), | ||
214 | SOC_ENUM_SINGLE(WM8753_INCTL1, 3, 4, wm8753_line_mix), | ||
215 | SOC_ENUM_SINGLE(WM8753_INCTL1, 2, 2, wm8753_mono_mux), | ||
216 | SOC_ENUM_SINGLE(WM8753_INCTL1, 1, 2, wm8753_right_mux), | ||
217 | SOC_ENUM_SINGLE(WM8753_INCTL1, 0, 2, wm8753_left_mux), | ||
218 | SOC_ENUM_SINGLE(WM8753_INCTL2, 6, 4, wm8753_rxmsel), | ||
219 | SOC_ENUM_SINGLE(WM8753_INCTL2, 4, 4, wm8753_sidetone_mux), | ||
220 | SOC_ENUM_SINGLE(WM8753_OUTCTL, 7, 4, wm8753_mono2_src), | ||
221 | SOC_ENUM_SINGLE(WM8753_OUTCTL, 0, 3, wm8753_out3), | ||
222 | SOC_ENUM_SINGLE(WM8753_ADCTL2, 7, 3, wm8753_out4), | ||
223 | SOC_ENUM_SINGLE(WM8753_ADCIN, 2, 3, wm8753_radcsel), | ||
224 | SOC_ENUM_SINGLE(WM8753_ADCIN, 0, 3, wm8753_ladcsel), | ||
225 | SOC_ENUM_SINGLE(WM8753_ADCIN, 4, 4, wm8753_mono_adc), | ||
226 | SOC_ENUM_SINGLE(WM8753_ADC, 2, 4, wm8753_adc_hp), | ||
227 | SOC_ENUM_SINGLE(WM8753_ADC, 4, 2, wm8753_adc_filter), | ||
228 | SOC_ENUM_SINGLE(WM8753_MICBIAS, 6, 3, wm8753_mic_sel), | ||
229 | SOC_ENUM_SINGLE(WM8753_IOCTL, 2, 4, wm8753_dai_mode), | ||
230 | SOC_ENUM_SINGLE(WM8753_ADC, 7, 4, wm8753_dat_sel), | ||
231 | }; | ||
232 | |||
233 | |||
234 | static int wm8753_get_dai(struct snd_kcontrol *kcontrol, | ||
235 | struct snd_ctl_elem_value *ucontrol) | ||
236 | { | ||
237 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
238 | int mode = wm8753_read_reg_cache(codec, WM8753_IOCTL); | ||
239 | |||
240 | ucontrol->value.integer.value[0] = (mode & 0xc) >> 2; | ||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | static int wm8753_set_dai(struct snd_kcontrol *kcontrol, | ||
245 | struct snd_ctl_elem_value *ucontrol) | ||
246 | { | ||
247 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
248 | int mode = wm8753_read_reg_cache(codec, WM8753_IOCTL); | ||
249 | |||
250 | if (((mode &0xc) >> 2) == ucontrol->value.integer.value[0]) | ||
251 | return 0; | ||
252 | |||
253 | mode &= 0xfff3; | ||
254 | mode |= (ucontrol->value.integer.value[0] << 2); | ||
255 | |||
256 | wm8753_write(codec, WM8753_IOCTL, mode); | ||
257 | wm8753_set_dai_mode(codec, ucontrol->value.integer.value[0]); | ||
258 | return 1; | ||
259 | } | ||
260 | |||
261 | static const struct snd_kcontrol_new wm8753_snd_controls[] = { | ||
262 | SOC_DOUBLE_R("PCM Volume", WM8753_LDAC, WM8753_RDAC, 0, 255, 0), | ||
263 | |||
264 | SOC_DOUBLE_R("ADC Capture Volume", WM8753_LADC, WM8753_RADC, 0, 255, 0), | ||
265 | |||
266 | SOC_DOUBLE_R("Headphone Playback Volume", WM8753_LOUT1V, WM8753_ROUT1V, 0, 127, 0), | ||
267 | SOC_DOUBLE_R("Speaker Playback Volume", WM8753_LOUT2V, WM8753_ROUT2V, 0, 127, 0), | ||
268 | |||
269 | SOC_SINGLE("Mono Playback Volume", WM8753_MOUTV, 0, 127, 0), | ||
270 | |||
271 | SOC_DOUBLE_R("Bypass Playback Volume", WM8753_LOUTM1, WM8753_ROUTM1, 4, 7, 1), | ||
272 | SOC_DOUBLE_R("Sidetone Playback Volume", WM8753_LOUTM2, WM8753_ROUTM2, 4, 7, 1), | ||
273 | SOC_DOUBLE_R("Voice Playback Volume", WM8753_LOUTM2, WM8753_ROUTM2, 0, 7, 1), | ||
274 | |||
275 | SOC_DOUBLE_R("Headphone Playback ZC Switch", WM8753_LOUT1V, WM8753_ROUT1V, 7, 1, 0), | ||
276 | SOC_DOUBLE_R("Speaker Playback ZC Switch", WM8753_LOUT2V, WM8753_ROUT2V, 7, 1, 0), | ||
277 | |||
278 | SOC_SINGLE("Mono Bypass Playback Volume", WM8753_MOUTM1, 4, 7, 1), | ||
279 | SOC_SINGLE("Mono Sidetone Playback Volume", WM8753_MOUTM2, 4, 7, 1), | ||
280 | SOC_SINGLE("Mono Voice Playback Volume", WM8753_MOUTM2, 4, 7, 1), | ||
281 | SOC_SINGLE("Mono Playback ZC Switch", WM8753_MOUTV, 7, 1, 0), | ||
282 | |||
283 | SOC_ENUM("Bass Boost", wm8753_enum[0]), | ||
284 | SOC_ENUM("Bass Filter", wm8753_enum[1]), | ||
285 | SOC_SINGLE("Bass Volume", WM8753_BASS, 0, 15, 1), | ||
286 | |||
287 | SOC_SINGLE("Treble Volume", WM8753_TREBLE, 0, 15, 1), | ||
288 | SOC_ENUM("Treble Cut-off", wm8753_enum[2]), | ||
289 | |||
290 | SOC_DOUBLE("Sidetone Capture Volume", WM8753_RECMIX1, 0, 4, 7, 1), | ||
291 | SOC_SINGLE("Voice Sidetone Capture Volume", WM8753_RECMIX2, 0, 7, 1), | ||
292 | |||
293 | SOC_DOUBLE_R("Capture Volume", WM8753_LINVOL, WM8753_RINVOL, 0, 63, 0), | ||
294 | SOC_DOUBLE_R("Capture ZC Switch", WM8753_LINVOL, WM8753_RINVOL, 6, 1, 0), | ||
295 | SOC_DOUBLE_R("Capture Switch", WM8753_LINVOL, WM8753_RINVOL, 7, 1, 1), | ||
296 | |||
297 | SOC_ENUM("Capture Filter Select", wm8753_enum[23]), | ||
298 | SOC_ENUM("Capture Filter Cut-off", wm8753_enum[24]), | ||
299 | SOC_SINGLE("Capture Filter Switch", WM8753_ADC, 0, 1, 1), | ||
300 | |||
301 | SOC_SINGLE("ALC Capture Target Volume", WM8753_ALC1, 0, 7, 0), | ||
302 | SOC_SINGLE("ALC Capture Max Volume", WM8753_ALC1, 4, 7, 0), | ||
303 | SOC_ENUM("ALC Capture Function", wm8753_enum[3]), | ||
304 | SOC_SINGLE("ALC Capture ZC Switch", WM8753_ALC2, 8, 1, 0), | ||
305 | SOC_SINGLE("ALC Capture Hold Time", WM8753_ALC2, 0, 15, 1), | ||
306 | SOC_SINGLE("ALC Capture Decay Time", WM8753_ALC3, 4, 15, 1), | ||
307 | SOC_SINGLE("ALC Capture Attack Time", WM8753_ALC3, 0, 15, 0), | ||
308 | SOC_SINGLE("ALC Capture NG Threshold", WM8753_NGATE, 3, 31, 0), | ||
309 | SOC_ENUM("ALC Capture NG Type", wm8753_enum[4]), | ||
310 | SOC_SINGLE("ALC Capture NG Switch", WM8753_NGATE, 0, 1, 0), | ||
311 | |||
312 | SOC_ENUM("3D Function", wm8753_enum[5]), | ||
313 | SOC_ENUM("3D Upper Cut-off", wm8753_enum[6]), | ||
314 | SOC_ENUM("3D Lower Cut-off", wm8753_enum[7]), | ||
315 | SOC_SINGLE("3D Volume", WM8753_3D, 1, 15, 0), | ||
316 | SOC_SINGLE("3D Switch", WM8753_3D, 0, 1, 0), | ||
317 | |||
318 | SOC_SINGLE("Capture 6dB Attenuate", WM8753_ADCTL1, 2, 1, 0), | ||
319 | SOC_SINGLE("Playback 6dB Attenuate", WM8753_ADCTL1, 1, 1, 0), | ||
320 | |||
321 | SOC_ENUM("De-emphasis", wm8753_enum[8]), | ||
322 | SOC_ENUM("Playback Mono Mix", wm8753_enum[9]), | ||
323 | SOC_ENUM("Playback Phase", wm8753_enum[10]), | ||
324 | |||
325 | SOC_SINGLE("Mic2 Capture Volume", WM8753_INCTL1, 7, 3, 0), | ||
326 | SOC_SINGLE("Mic1 Capture Volume", WM8753_INCTL1, 5, 3, 0), | ||
327 | |||
328 | SOC_ENUM_EXT("DAI Mode", wm8753_enum[26], wm8753_get_dai, wm8753_set_dai), | ||
329 | |||
330 | SOC_ENUM("ADC Data Select", wm8753_enum[27]), | ||
331 | }; | ||
332 | |||
333 | /* add non dapm controls */ | ||
334 | static int wm8753_add_controls(struct snd_soc_codec *codec) | ||
335 | { | ||
336 | int err, i; | ||
337 | |||
338 | for (i = 0; i < ARRAY_SIZE(wm8753_snd_controls); i++) { | ||
339 | err = snd_ctl_add(codec->card, | ||
340 | snd_soc_cnew(&wm8753_snd_controls[i],codec, NULL)); | ||
341 | if (err < 0) | ||
342 | return err; | ||
343 | } | ||
344 | return 0; | ||
345 | } | ||
346 | |||
347 | /* | ||
348 | * _DAPM_ Controls | ||
349 | */ | ||
350 | |||
351 | /* Left Mixer */ | ||
352 | static const struct snd_kcontrol_new wm8753_left_mixer_controls[] = { | ||
353 | SOC_DAPM_SINGLE("Voice Playback Switch", WM8753_LOUTM2, 8, 1, 0), | ||
354 | SOC_DAPM_SINGLE("Sidetone Playback Switch", WM8753_LOUTM2, 7, 1, 0), | ||
355 | SOC_DAPM_SINGLE("Left Playback Switch", WM8753_LOUTM1, 8, 1, 0), | ||
356 | SOC_DAPM_SINGLE("Bypass Playback Switch", WM8753_LOUTM1, 7, 1, 0), | ||
357 | }; | ||
358 | |||
359 | /* Right mixer */ | ||
360 | static const struct snd_kcontrol_new wm8753_right_mixer_controls[] = { | ||
361 | SOC_DAPM_SINGLE("Voice Playback Switch", WM8753_ROUTM2, 8, 1, 0), | ||
362 | SOC_DAPM_SINGLE("Sidetone Playback Switch", WM8753_ROUTM2, 7, 1, 0), | ||
363 | SOC_DAPM_SINGLE("Right Playback Switch", WM8753_ROUTM1, 8, 1, 0), | ||
364 | SOC_DAPM_SINGLE("Bypass Playback Switch", WM8753_ROUTM1, 7, 1, 0), | ||
365 | }; | ||
366 | |||
367 | /* Mono mixer */ | ||
368 | static const struct snd_kcontrol_new wm8753_mono_mixer_controls[] = { | ||
369 | SOC_DAPM_SINGLE("Left Playback Switch", WM8753_MOUTM1, 8, 1, 0), | ||
370 | SOC_DAPM_SINGLE("Right Playback Switch", WM8753_MOUTM2, 8, 1, 0), | ||
371 | SOC_DAPM_SINGLE("Voice Playback Switch", WM8753_MOUTM2, 3, 1, 0), | ||
372 | SOC_DAPM_SINGLE("Sidetone Playback Switch", WM8753_MOUTM2, 7, 1, 0), | ||
373 | SOC_DAPM_SINGLE("Bypass Playback Switch", WM8753_MOUTM1, 7, 1, 0), | ||
374 | }; | ||
375 | |||
376 | /* Mono 2 Mux */ | ||
377 | static const struct snd_kcontrol_new wm8753_mono2_controls = | ||
378 | SOC_DAPM_ENUM("Route", wm8753_enum[17]); | ||
379 | |||
380 | /* Out 3 Mux */ | ||
381 | static const struct snd_kcontrol_new wm8753_out3_controls = | ||
382 | SOC_DAPM_ENUM("Route", wm8753_enum[18]); | ||
383 | |||
384 | /* Out 4 Mux */ | ||
385 | static const struct snd_kcontrol_new wm8753_out4_controls = | ||
386 | SOC_DAPM_ENUM("Route", wm8753_enum[19]); | ||
387 | |||
388 | /* ADC Mono Mix */ | ||
389 | static const struct snd_kcontrol_new wm8753_adc_mono_controls = | ||
390 | SOC_DAPM_ENUM("Route", wm8753_enum[22]); | ||
391 | |||
392 | /* Record mixer */ | ||
393 | static const struct snd_kcontrol_new wm8753_record_mixer_controls[] = { | ||
394 | SOC_DAPM_SINGLE("Voice Capture Switch", WM8753_RECMIX2, 3, 1, 0), | ||
395 | SOC_DAPM_SINGLE("Left Capture Switch", WM8753_RECMIX1, 3, 1, 0), | ||
396 | SOC_DAPM_SINGLE("Right Capture Switch", WM8753_RECMIX1, 7, 1, 0), | ||
397 | }; | ||
398 | |||
399 | /* Left ADC mux */ | ||
400 | static const struct snd_kcontrol_new wm8753_adc_left_controls = | ||
401 | SOC_DAPM_ENUM("Route", wm8753_enum[21]); | ||
402 | |||
403 | /* Right ADC mux */ | ||
404 | static const struct snd_kcontrol_new wm8753_adc_right_controls = | ||
405 | SOC_DAPM_ENUM("Route", wm8753_enum[20]); | ||
406 | |||
407 | /* MIC mux */ | ||
408 | static const struct snd_kcontrol_new wm8753_mic_mux_controls = | ||
409 | SOC_DAPM_ENUM("Route", wm8753_enum[16]); | ||
410 | |||
411 | /* ALC mixer */ | ||
412 | static const struct snd_kcontrol_new wm8753_alc_mixer_controls[] = { | ||
413 | SOC_DAPM_SINGLE("Line Capture Switch", WM8753_INCTL2, 3, 1, 0), | ||
414 | SOC_DAPM_SINGLE("Mic2 Capture Switch", WM8753_INCTL2, 2, 1, 0), | ||
415 | SOC_DAPM_SINGLE("Mic1 Capture Switch", WM8753_INCTL2, 1, 1, 0), | ||
416 | SOC_DAPM_SINGLE("Rx Capture Switch", WM8753_INCTL2, 0, 1, 0), | ||
417 | }; | ||
418 | |||
419 | /* Left Line mux */ | ||
420 | static const struct snd_kcontrol_new wm8753_line_left_controls = | ||
421 | SOC_DAPM_ENUM("Route", wm8753_enum[14]); | ||
422 | |||
423 | /* Right Line mux */ | ||
424 | static const struct snd_kcontrol_new wm8753_line_right_controls = | ||
425 | SOC_DAPM_ENUM("Route", wm8753_enum[13]); | ||
426 | |||
427 | /* Mono Line mux */ | ||
428 | static const struct snd_kcontrol_new wm8753_line_mono_controls = | ||
429 | SOC_DAPM_ENUM("Route", wm8753_enum[12]); | ||
430 | |||
431 | /* Line mux and mixer */ | ||
432 | static const struct snd_kcontrol_new wm8753_line_mux_mix_controls = | ||
433 | SOC_DAPM_ENUM("Route", wm8753_enum[11]); | ||
434 | |||
435 | /* Rx mux and mixer */ | ||
436 | static const struct snd_kcontrol_new wm8753_rx_mux_mix_controls = | ||
437 | SOC_DAPM_ENUM("Route", wm8753_enum[15]); | ||
438 | |||
439 | /* Mic Selector Mux */ | ||
440 | static const struct snd_kcontrol_new wm8753_mic_sel_mux_controls = | ||
441 | SOC_DAPM_ENUM("Route", wm8753_enum[25]); | ||
442 | |||
443 | static const struct snd_soc_dapm_widget wm8753_dapm_widgets[] = { | ||
444 | SND_SOC_DAPM_MICBIAS("Mic Bias", WM8753_PWR1, 5, 0), | ||
445 | SND_SOC_DAPM_MIXER("Left Mixer", WM8753_PWR4, 0, 0, | ||
446 | &wm8753_left_mixer_controls[0], ARRAY_SIZE(wm8753_left_mixer_controls)), | ||
447 | SND_SOC_DAPM_PGA("Left Out 1", WM8753_PWR3, 8, 0, NULL, 0), | ||
448 | SND_SOC_DAPM_PGA("Left Out 2", WM8753_PWR3, 6, 0, NULL, 0), | ||
449 | SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", WM8753_PWR1, 3, 0), | ||
450 | SND_SOC_DAPM_OUTPUT("LOUT1"), | ||
451 | SND_SOC_DAPM_OUTPUT("LOUT2"), | ||
452 | SND_SOC_DAPM_MIXER("Right Mixer", WM8753_PWR4, 1, 0, | ||
453 | &wm8753_right_mixer_controls[0], ARRAY_SIZE(wm8753_right_mixer_controls)), | ||
454 | SND_SOC_DAPM_PGA("Right Out 1", WM8753_PWR3, 7, 0, NULL, 0), | ||
455 | SND_SOC_DAPM_PGA("Right Out 2", WM8753_PWR3, 5, 0, NULL, 0), | ||
456 | SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", WM8753_PWR1, 2, 0), | ||
457 | SND_SOC_DAPM_OUTPUT("ROUT1"), | ||
458 | SND_SOC_DAPM_OUTPUT("ROUT2"), | ||
459 | SND_SOC_DAPM_MIXER("Mono Mixer", WM8753_PWR4, 2, 0, | ||
460 | &wm8753_mono_mixer_controls[0], ARRAY_SIZE(wm8753_mono_mixer_controls)), | ||
461 | SND_SOC_DAPM_PGA("Mono Out 1", WM8753_PWR3, 2, 0, NULL, 0), | ||
462 | SND_SOC_DAPM_PGA("Mono Out 2", WM8753_PWR3, 1, 0, NULL, 0), | ||
463 | SND_SOC_DAPM_DAC("Voice DAC", "Voice Playback", WM8753_PWR1, 4, 0), | ||
464 | SND_SOC_DAPM_OUTPUT("MONO1"), | ||
465 | SND_SOC_DAPM_MUX("Mono 2 Mux", SND_SOC_NOPM, 0, 0, &wm8753_mono2_controls), | ||
466 | SND_SOC_DAPM_OUTPUT("MONO2"), | ||
467 | SND_SOC_DAPM_MIXER("Out3 Left + Right", -1, 0, 0, NULL, 0), | ||
468 | SND_SOC_DAPM_MUX("Out3 Mux", SND_SOC_NOPM, 0, 0, &wm8753_out3_controls), | ||
469 | SND_SOC_DAPM_PGA("Out 3", WM8753_PWR3, 4, 0, NULL, 0), | ||
470 | SND_SOC_DAPM_OUTPUT("OUT3"), | ||
471 | SND_SOC_DAPM_MUX("Out4 Mux", SND_SOC_NOPM, 0, 0, &wm8753_out4_controls), | ||
472 | SND_SOC_DAPM_PGA("Out 4", WM8753_PWR3, 3, 0, NULL, 0), | ||
473 | SND_SOC_DAPM_OUTPUT("OUT4"), | ||
474 | SND_SOC_DAPM_MIXER("Playback Mixer", WM8753_PWR4, 3, 0, | ||
475 | &wm8753_record_mixer_controls[0], | ||
476 | ARRAY_SIZE(wm8753_record_mixer_controls)), | ||
477 | SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8753_PWR2, 3, 0), | ||
478 | SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8753_PWR2, 2, 0), | ||
479 | SND_SOC_DAPM_MUX("Capture Left Mixer", SND_SOC_NOPM, 0, 0, | ||
480 | &wm8753_adc_mono_controls), | ||
481 | SND_SOC_DAPM_MUX("Capture Right Mixer", SND_SOC_NOPM, 0, 0, | ||
482 | &wm8753_adc_mono_controls), | ||
483 | SND_SOC_DAPM_MUX("Capture Left Mux", SND_SOC_NOPM, 0, 0, | ||
484 | &wm8753_adc_left_controls), | ||
485 | SND_SOC_DAPM_MUX("Capture Right Mux", SND_SOC_NOPM, 0, 0, | ||
486 | &wm8753_adc_right_controls), | ||
487 | SND_SOC_DAPM_MUX("Mic Sidetone Mux", SND_SOC_NOPM, 0, 0, | ||
488 | &wm8753_mic_mux_controls), | ||
489 | SND_SOC_DAPM_PGA("Left Capture Volume", WM8753_PWR2, 5, 0, NULL, 0), | ||
490 | SND_SOC_DAPM_PGA("Right Capture Volume", WM8753_PWR2, 4, 0, NULL, 0), | ||
491 | SND_SOC_DAPM_MIXER("ALC Mixer", WM8753_PWR2, 6, 0, | ||
492 | &wm8753_alc_mixer_controls[0], ARRAY_SIZE(wm8753_alc_mixer_controls)), | ||
493 | SND_SOC_DAPM_MUX("Line Left Mux", SND_SOC_NOPM, 0, 0, | ||
494 | &wm8753_line_left_controls), | ||
495 | SND_SOC_DAPM_MUX("Line Right Mux", SND_SOC_NOPM, 0, 0, | ||
496 | &wm8753_line_right_controls), | ||
497 | SND_SOC_DAPM_MUX("Line Mono Mux", SND_SOC_NOPM, 0, 0, | ||
498 | &wm8753_line_mono_controls), | ||
499 | SND_SOC_DAPM_MUX("Line Mixer", WM8753_PWR2, 0, 0, | ||
500 | &wm8753_line_mux_mix_controls), | ||
501 | SND_SOC_DAPM_MUX("Rx Mixer", WM8753_PWR2, 1, 0, | ||
502 | &wm8753_rx_mux_mix_controls), | ||
503 | SND_SOC_DAPM_PGA("Mic 1 Volume", WM8753_PWR2, 8, 0, NULL, 0), | ||
504 | SND_SOC_DAPM_PGA("Mic 2 Volume", WM8753_PWR2, 7, 0, NULL, 0), | ||
505 | SND_SOC_DAPM_MUX("Mic Selection Mux", SND_SOC_NOPM, 0, 0, | ||
506 | &wm8753_mic_sel_mux_controls), | ||
507 | SND_SOC_DAPM_INPUT("LINE1"), | ||
508 | SND_SOC_DAPM_INPUT("LINE2"), | ||
509 | SND_SOC_DAPM_INPUT("RXP"), | ||
510 | SND_SOC_DAPM_INPUT("RXN"), | ||
511 | SND_SOC_DAPM_INPUT("ACIN"), | ||
512 | SND_SOC_DAPM_OUTPUT("ACOP"), | ||
513 | SND_SOC_DAPM_INPUT("MIC1N"), | ||
514 | SND_SOC_DAPM_INPUT("MIC1"), | ||
515 | SND_SOC_DAPM_INPUT("MIC2N"), | ||
516 | SND_SOC_DAPM_INPUT("MIC2"), | ||
517 | SND_SOC_DAPM_VMID("VREF"), | ||
518 | }; | ||
519 | |||
520 | static const char *audio_map[][3] = { | ||
521 | /* left mixer */ | ||
522 | {"Left Mixer", "Left Playback Switch", "Left DAC"}, | ||
523 | {"Left Mixer", "Voice Playback Switch", "Voice DAC"}, | ||
524 | {"Left Mixer", "Sidetone Playback Switch", "Mic Sidetone Mux"}, | ||
525 | {"Left Mixer", "Bypass Playback Switch", "Line Left Mux"}, | ||
526 | |||
527 | /* right mixer */ | ||
528 | {"Right Mixer", "Right Playback Switch", "Right DAC"}, | ||
529 | {"Right Mixer", "Voice Playback Switch", "Voice DAC"}, | ||
530 | {"Right Mixer", "Sidetone Playback Switch", "Mic Sidetone Mux"}, | ||
531 | {"Right Mixer", "Bypass Playback Switch", "Line Right Mux"}, | ||
532 | |||
533 | /* mono mixer */ | ||
534 | {"Mono Mixer", "Voice Playback Switch", "Voice DAC"}, | ||
535 | {"Mono Mixer", "Left Playback Switch", "Left DAC"}, | ||
536 | {"Mono Mixer", "Right Playback Switch", "Right DAC"}, | ||
537 | {"Mono Mixer", "Sidetone Playback Switch", "Mic Sidetone Mux"}, | ||
538 | {"Mono Mixer", "Bypass Playback Switch", "Line Mono Mux"}, | ||
539 | |||
540 | /* left out */ | ||
541 | {"Left Out 1", NULL, "Left Mixer"}, | ||
542 | {"Left Out 2", NULL, "Left Mixer"}, | ||
543 | {"LOUT1", NULL, "Left Out 1"}, | ||
544 | {"LOUT2", NULL, "Left Out 2"}, | ||
545 | |||
546 | /* right out */ | ||
547 | {"Right Out 1", NULL, "Right Mixer"}, | ||
548 | {"Right Out 2", NULL, "Right Mixer"}, | ||
549 | {"ROUT1", NULL, "Right Out 1"}, | ||
550 | {"ROUT2", NULL, "Right Out 2"}, | ||
551 | |||
552 | /* mono 1 out */ | ||
553 | {"Mono Out 1", NULL, "Mono Mixer"}, | ||
554 | {"MONO1", NULL, "Mono Out 1"}, | ||
555 | |||
556 | /* mono 2 out */ | ||
557 | {"Mono 2 Mux", "Left + Right", "Out3 Left + Right"}, | ||
558 | {"Mono 2 Mux", "Inverted Mono 1", "MONO1"}, | ||
559 | {"Mono 2 Mux", "Left", "Left Mixer"}, | ||
560 | {"Mono 2 Mux", "Right", "Right Mixer"}, | ||
561 | {"Mono Out 2", NULL, "Mono 2 Mux"}, | ||
562 | {"MONO2", NULL, "Mono Out 2"}, | ||
563 | |||
564 | /* out 3 */ | ||
565 | {"Out3 Left + Right", NULL, "Left Mixer"}, | ||
566 | {"Out3 Left + Right", NULL, "Right Mixer"}, | ||
567 | {"Out3 Mux", "VREF", "VREF"}, | ||
568 | {"Out3 Mux", "Left + Right", "Out3 Left + Right"}, | ||
569 | {"Out3 Mux", "ROUT2", "ROUT2"}, | ||
570 | {"Out 3", NULL, "Out3 Mux"}, | ||
571 | {"OUT3", NULL, "Out 3"}, | ||
572 | |||
573 | /* out 4 */ | ||
574 | {"Out4 Mux", "VREF", "VREF"}, | ||
575 | {"Out4 Mux", "Capture ST", "Capture ST Mixer"}, | ||
576 | {"Out4 Mux", "LOUT2", "LOUT2"}, | ||
577 | {"Out 4", NULL, "Out4 Mux"}, | ||
578 | {"OUT4", NULL, "Out 4"}, | ||
579 | |||
580 | /* record mixer */ | ||
581 | {"Playback Mixer", "Left Capture Switch", "Left Mixer"}, | ||
582 | {"Playback Mixer", "Voice Capture Switch", "Mono Mixer"}, | ||
583 | {"Playback Mixer", "Right Capture Switch", "Right Mixer"}, | ||
584 | |||
585 | /* Mic/SideTone Mux */ | ||
586 | {"Mic Sidetone Mux", "Left PGA", "Left Capture Volume"}, | ||
587 | {"Mic Sidetone Mux", "Right PGA", "Right Capture Volume"}, | ||
588 | {"Mic Sidetone Mux", "Mic 1", "Mic 1 Volume"}, | ||
589 | {"Mic Sidetone Mux", "Mic 2", "Mic 2 Volume"}, | ||
590 | |||
591 | /* Capture Left Mux */ | ||
592 | {"Capture Left Mux", "PGA", "Left Capture Volume"}, | ||
593 | {"Capture Left Mux", "Line or RXP-RXN", "Line Left Mux"}, | ||
594 | {"Capture Left Mux", "Line", "LINE1"}, | ||
595 | |||
596 | /* Capture Right Mux */ | ||
597 | {"Capture Right Mux", "PGA", "Right Capture Volume"}, | ||
598 | {"Capture Right Mux", "Line or RXP-RXN", "Line Right Mux"}, | ||
599 | {"Capture Right Mux", "Sidetone", "Capture ST Mixer"}, | ||
600 | |||
601 | /* Mono Capture mixer-mux */ | ||
602 | {"Capture Right Mixer", "Stereo", "Capture Right Mux"}, | ||
603 | {"Capture Left Mixer", "Analogue Mix Left", "Capture Left Mux"}, | ||
604 | {"Capture Left Mixer", "Analogue Mix Left", "Capture Right Mux"}, | ||
605 | {"Capture Right Mixer", "Analogue Mix Right", "Capture Left Mux"}, | ||
606 | {"Capture Right Mixer", "Analogue Mix Right", "Capture Right Mux"}, | ||
607 | {"Capture Left Mixer", "Digital Mono Mix", "Capture Left Mux"}, | ||
608 | {"Capture Left Mixer", "Digital Mono Mix", "Capture Right Mux"}, | ||
609 | {"Capture Right Mixer", "Digital Mono Mix", "Capture Left Mux"}, | ||
610 | {"Capture Right Mixer", "Digital Mono Mix", "Capture Right Mux"}, | ||
611 | |||
612 | /* ADC */ | ||
613 | {"Left ADC", NULL, "Capture Left Mixer"}, | ||
614 | {"Right ADC", NULL, "Capture Right Mixer"}, | ||
615 | |||
616 | /* Left Capture Volume */ | ||
617 | {"Left Capture Volume", NULL, "ACIN"}, | ||
618 | |||
619 | /* Right Capture Volume */ | ||
620 | {"Right Capture Volume", NULL, "Mic 2 Volume"}, | ||
621 | |||
622 | /* ALC Mixer */ | ||
623 | {"ALC Mixer", "Line Capture Switch", "Line Mixer"}, | ||
624 | {"ALC Mixer", "Mic2 Capture Switch", "Mic 2 Volume"}, | ||
625 | {"ALC Mixer", "Mic1 Capture Switch", "Mic 1 Volume"}, | ||
626 | {"ALC Mixer", "Rx Capture Switch", "Rx Mixer"}, | ||
627 | |||
628 | /* Line Left Mux */ | ||
629 | {"Line Left Mux", "Line 1", "LINE1"}, | ||
630 | {"Line Left Mux", "Rx Mix", "Rx Mixer"}, | ||
631 | |||
632 | /* Line Right Mux */ | ||
633 | {"Line Right Mux", "Line 2", "LINE2"}, | ||
634 | {"Line Right Mux", "Rx Mix", "Rx Mixer"}, | ||
635 | |||
636 | /* Line Mono Mux */ | ||
637 | {"Line Mono Mux", "Line Mix", "Line Mixer"}, | ||
638 | {"Line Mono Mux", "Rx Mix", "Rx Mixer"}, | ||
639 | |||
640 | /* Line Mixer/Mux */ | ||
641 | {"Line Mixer", "Line 1 + 2", "LINE1"}, | ||
642 | {"Line Mixer", "Line 1 - 2", "LINE1"}, | ||
643 | {"Line Mixer", "Line 1 + 2", "LINE2"}, | ||
644 | {"Line Mixer", "Line 1 - 2", "LINE2"}, | ||
645 | {"Line Mixer", "Line 1", "LINE1"}, | ||
646 | {"Line Mixer", "Line 2", "LINE2"}, | ||
647 | |||
648 | /* Rx Mixer/Mux */ | ||
649 | {"Rx Mixer", "RXP - RXN", "RXP"}, | ||
650 | {"Rx Mixer", "RXP + RXN", "RXP"}, | ||
651 | {"Rx Mixer", "RXP - RXN", "RXN"}, | ||
652 | {"Rx Mixer", "RXP + RXN", "RXN"}, | ||
653 | {"Rx Mixer", "RXP", "RXP"}, | ||
654 | {"Rx Mixer", "RXN", "RXN"}, | ||
655 | |||
656 | /* Mic 1 Volume */ | ||
657 | {"Mic 1 Volume", NULL, "MIC1N"}, | ||
658 | {"Mic 1 Volume", NULL, "Mic Selection Mux"}, | ||
659 | |||
660 | /* Mic 2 Volume */ | ||
661 | {"Mic 2 Volume", NULL, "MIC2N"}, | ||
662 | {"Mic 2 Volume", NULL, "MIC2"}, | ||
663 | |||
664 | /* Mic Selector Mux */ | ||
665 | {"Mic Selection Mux", "Mic 1", "MIC1"}, | ||
666 | {"Mic Selection Mux", "Mic 2", "MIC2N"}, | ||
667 | {"Mic Selection Mux", "Mic 3", "MIC2"}, | ||
668 | |||
669 | /* ACOP */ | ||
670 | {"ACOP", NULL, "ALC Mixer"}, | ||
671 | |||
672 | /* terminator */ | ||
673 | {NULL, NULL, NULL}, | ||
674 | }; | ||
675 | |||
676 | static int wm8753_add_widgets(struct snd_soc_codec *codec) | ||
677 | { | ||
678 | int i; | ||
679 | |||
680 | for (i = 0; i < ARRAY_SIZE(wm8753_dapm_widgets); i++) | ||
681 | snd_soc_dapm_new_control(codec, &wm8753_dapm_widgets[i]); | ||
682 | |||
683 | /* set up the WM8753 audio map */ | ||
684 | for (i = 0; audio_map[i][0] != NULL; i++) { | ||
685 | snd_soc_dapm_connect_input(codec, audio_map[i][0], | ||
686 | audio_map[i][1], audio_map[i][2]); | ||
687 | } | ||
688 | |||
689 | snd_soc_dapm_new_widgets(codec); | ||
690 | return 0; | ||
691 | } | ||
692 | |||
693 | /* PLL divisors */ | ||
694 | struct _pll_div { | ||
695 | u32 div2:1; | ||
696 | u32 n:4; | ||
697 | u32 k:24; | ||
698 | }; | ||
699 | |||
700 | /* The size in bits of the pll divide multiplied by 10 | ||
701 | * to allow rounding later */ | ||
702 | #define FIXED_PLL_SIZE ((1 << 22) * 10) | ||
703 | |||
704 | static void pll_factors(struct _pll_div *pll_div, unsigned int target, | ||
705 | unsigned int source) | ||
706 | { | ||
707 | u64 Kpart; | ||
708 | unsigned int K, Ndiv, Nmod; | ||
709 | |||
710 | Ndiv = target / source; | ||
711 | if (Ndiv < 6) { | ||
712 | source >>= 1; | ||
713 | pll_div->div2 = 1; | ||
714 | Ndiv = target / source; | ||
715 | } else | ||
716 | pll_div->div2 = 0; | ||
717 | |||
718 | if ((Ndiv < 6) || (Ndiv > 12)) | ||
719 | printk(KERN_WARNING | ||
720 | "WM8753 N value outwith recommended range! N = %d\n",Ndiv); | ||
721 | |||
722 | pll_div->n = Ndiv; | ||
723 | Nmod = target % source; | ||
724 | Kpart = FIXED_PLL_SIZE * (long long)Nmod; | ||
725 | |||
726 | do_div(Kpart, source); | ||
727 | |||
728 | K = Kpart & 0xFFFFFFFF; | ||
729 | |||
730 | /* Check if we need to round */ | ||
731 | if ((K % 10) >= 5) | ||
732 | K += 5; | ||
733 | |||
734 | /* Move down to proper range now rounding is done */ | ||
735 | K /= 10; | ||
736 | |||
737 | pll_div->k = K; | ||
738 | } | ||
739 | |||
740 | static int wm8753_set_dai_pll(struct snd_soc_codec_dai *codec_dai, | ||
741 | int pll_id, unsigned int freq_in, unsigned int freq_out) | ||
742 | { | ||
743 | u16 reg, enable; | ||
744 | int offset; | ||
745 | struct snd_soc_codec *codec = codec_dai->codec; | ||
746 | |||
747 | if (pll_id < WM8753_PLL1 || pll_id > WM8753_PLL2) | ||
748 | return -ENODEV; | ||
749 | |||
750 | if (pll_id == WM8753_PLL1) { | ||
751 | offset = 0; | ||
752 | enable = 0x10; | ||
753 | reg = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xffef; | ||
754 | } else { | ||
755 | offset = 4; | ||
756 | enable = 0x8; | ||
757 | reg = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xfff7; | ||
758 | } | ||
759 | |||
760 | if (!freq_in || !freq_out) { | ||
761 | /* disable PLL */ | ||
762 | wm8753_write(codec, WM8753_PLL1CTL1 + offset, 0x0026); | ||
763 | wm8753_write(codec, WM8753_CLOCK, reg); | ||
764 | return 0; | ||
765 | } else { | ||
766 | u16 value = 0; | ||
767 | struct _pll_div pll_div; | ||
768 | |||
769 | pll_factors(&pll_div, freq_out * 8, freq_in); | ||
770 | |||
771 | /* set up N and K PLL divisor ratios */ | ||
772 | /* bits 8:5 = PLL_N, bits 3:0 = PLL_K[21:18] */ | ||
773 | value = (pll_div.n << 5) + ((pll_div.k & 0x3c0000) >> 18); | ||
774 | wm8753_write(codec, WM8753_PLL1CTL2 + offset, value); | ||
775 | |||
776 | /* bits 8:0 = PLL_K[17:9] */ | ||
777 | value = (pll_div.k & 0x03fe00) >> 9; | ||
778 | wm8753_write(codec, WM8753_PLL1CTL3 + offset, value); | ||
779 | |||
780 | /* bits 8:0 = PLL_K[8:0] */ | ||
781 | value = pll_div.k & 0x0001ff; | ||
782 | wm8753_write(codec, WM8753_PLL1CTL4 + offset, value); | ||
783 | |||
784 | /* set PLL as input and enable */ | ||
785 | wm8753_write(codec, WM8753_PLL1CTL1 + offset, 0x0027 | | ||
786 | (pll_div.div2 << 3)); | ||
787 | wm8753_write(codec, WM8753_CLOCK, reg | enable); | ||
788 | } | ||
789 | return 0; | ||
790 | } | ||
791 | |||
792 | struct _coeff_div { | ||
793 | u32 mclk; | ||
794 | u32 rate; | ||
795 | u8 sr:5; | ||
796 | u8 usb:1; | ||
797 | }; | ||
798 | |||
799 | /* codec hifi mclk (after PLL) clock divider coefficients */ | ||
800 | static const struct _coeff_div coeff_div[] = { | ||
801 | /* 8k */ | ||
802 | {12288000, 8000, 0x6, 0x0}, | ||
803 | {11289600, 8000, 0x16, 0x0}, | ||
804 | {18432000, 8000, 0x7, 0x0}, | ||
805 | {16934400, 8000, 0x17, 0x0}, | ||
806 | {12000000, 8000, 0x6, 0x1}, | ||
807 | |||
808 | /* 11.025k */ | ||
809 | {11289600, 11025, 0x18, 0x0}, | ||
810 | {16934400, 11025, 0x19, 0x0}, | ||
811 | {12000000, 11025, 0x19, 0x1}, | ||
812 | |||
813 | /* 16k */ | ||
814 | {12288000, 16000, 0xa, 0x0}, | ||
815 | {18432000, 16000, 0xb, 0x0}, | ||
816 | {12000000, 16000, 0xa, 0x1}, | ||
817 | |||
818 | /* 22.05k */ | ||
819 | {11289600, 22050, 0x1a, 0x0}, | ||
820 | {16934400, 22050, 0x1b, 0x0}, | ||
821 | {12000000, 22050, 0x1b, 0x1}, | ||
822 | |||
823 | /* 32k */ | ||
824 | {12288000, 32000, 0xc, 0x0}, | ||
825 | {18432000, 32000, 0xd, 0x0}, | ||
826 | {12000000, 32000, 0xa, 0x1}, | ||
827 | |||
828 | /* 44.1k */ | ||
829 | {11289600, 44100, 0x10, 0x0}, | ||
830 | {16934400, 44100, 0x11, 0x0}, | ||
831 | {12000000, 44100, 0x11, 0x1}, | ||
832 | |||
833 | /* 48k */ | ||
834 | {12288000, 48000, 0x0, 0x0}, | ||
835 | {18432000, 48000, 0x1, 0x0}, | ||
836 | {12000000, 48000, 0x0, 0x1}, | ||
837 | |||
838 | /* 88.2k */ | ||
839 | {11289600, 88200, 0x1e, 0x0}, | ||
840 | {16934400, 88200, 0x1f, 0x0}, | ||
841 | {12000000, 88200, 0x1f, 0x1}, | ||
842 | |||
843 | /* 96k */ | ||
844 | {12288000, 96000, 0xe, 0x0}, | ||
845 | {18432000, 96000, 0xf, 0x0}, | ||
846 | {12000000, 96000, 0xe, 0x1}, | ||
847 | }; | ||
848 | |||
849 | static int get_coeff(int mclk, int rate) | ||
850 | { | ||
851 | int i; | ||
852 | |||
853 | for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { | ||
854 | if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk) | ||
855 | return i; | ||
856 | } | ||
857 | return -EINVAL; | ||
858 | } | ||
859 | |||
860 | /* | ||
861 | * Clock after PLL and dividers | ||
862 | */ | ||
863 | static int wm8753_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai, | ||
864 | int clk_id, unsigned int freq, int dir) | ||
865 | { | ||
866 | struct snd_soc_codec *codec = codec_dai->codec; | ||
867 | struct wm8753_priv *wm8753 = codec->private_data; | ||
868 | |||
869 | switch (freq) { | ||
870 | case 11289600: | ||
871 | case 12000000: | ||
872 | case 12288000: | ||
873 | case 16934400: | ||
874 | case 18432000: | ||
875 | if (clk_id == WM8753_MCLK) { | ||
876 | wm8753->sysclk = freq; | ||
877 | return 0; | ||
878 | } else if (clk_id == WM8753_PCMCLK) { | ||
879 | wm8753->pcmclk = freq; | ||
880 | return 0; | ||
881 | } | ||
882 | break; | ||
883 | } | ||
884 | return -EINVAL; | ||
885 | } | ||
886 | |||
887 | /* | ||
888 | * Set's ADC and Voice DAC format. | ||
889 | */ | ||
890 | static int wm8753_vdac_adc_set_dai_fmt(struct snd_soc_codec_dai *codec_dai, | ||
891 | unsigned int fmt) | ||
892 | { | ||
893 | struct snd_soc_codec *codec = codec_dai->codec; | ||
894 | u16 voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x01ec; | ||
895 | |||
896 | /* interface format */ | ||
897 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
898 | case SND_SOC_DAIFMT_I2S: | ||
899 | voice |= 0x0002; | ||
900 | break; | ||
901 | case SND_SOC_DAIFMT_RIGHT_J: | ||
902 | break; | ||
903 | case SND_SOC_DAIFMT_LEFT_J: | ||
904 | voice |= 0x0001; | ||
905 | break; | ||
906 | case SND_SOC_DAIFMT_DSP_A: | ||
907 | voice |= 0x0003; | ||
908 | break; | ||
909 | case SND_SOC_DAIFMT_DSP_B: | ||
910 | voice |= 0x0013; | ||
911 | break; | ||
912 | default: | ||
913 | return -EINVAL; | ||
914 | } | ||
915 | |||
916 | wm8753_write(codec, WM8753_PCM, voice); | ||
917 | return 0; | ||
918 | } | ||
919 | |||
920 | /* | ||
921 | * Set PCM DAI bit size and sample rate. | ||
922 | */ | ||
923 | static int wm8753_pcm_hw_params(struct snd_pcm_substream *substream, | ||
924 | struct snd_pcm_hw_params *params) | ||
925 | { | ||
926 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
927 | struct snd_soc_device *socdev = rtd->socdev; | ||
928 | struct snd_soc_codec *codec = socdev->codec; | ||
929 | struct wm8753_priv *wm8753 = codec->private_data; | ||
930 | u16 voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x01f3; | ||
931 | u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x017f; | ||
932 | |||
933 | /* bit size */ | ||
934 | switch (params_format(params)) { | ||
935 | case SNDRV_PCM_FORMAT_S16_LE: | ||
936 | break; | ||
937 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
938 | voice |= 0x0004; | ||
939 | break; | ||
940 | case SNDRV_PCM_FORMAT_S24_LE: | ||
941 | voice |= 0x0008; | ||
942 | break; | ||
943 | case SNDRV_PCM_FORMAT_S32_LE: | ||
944 | voice |= 0x000c; | ||
945 | break; | ||
946 | } | ||
947 | |||
948 | /* sample rate */ | ||
949 | if (params_rate(params) * 384 == wm8753->pcmclk) | ||
950 | srate |= 0x80; | ||
951 | wm8753_write(codec, WM8753_SRATE1, srate); | ||
952 | |||
953 | wm8753_write(codec, WM8753_PCM, voice); | ||
954 | return 0; | ||
955 | } | ||
956 | |||
957 | /* | ||
958 | * Set's PCM dai fmt and BCLK. | ||
959 | */ | ||
960 | static int wm8753_pcm_set_dai_fmt(struct snd_soc_codec_dai *codec_dai, | ||
961 | unsigned int fmt) | ||
962 | { | ||
963 | struct snd_soc_codec *codec = codec_dai->codec; | ||
964 | u16 voice, ioctl; | ||
965 | |||
966 | voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x011f; | ||
967 | ioctl = wm8753_read_reg_cache(codec, WM8753_IOCTL) & 0x015d; | ||
968 | |||
969 | /* set master/slave audio interface */ | ||
970 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
971 | case SND_SOC_DAIFMT_CBS_CFS: | ||
972 | break; | ||
973 | case SND_SOC_DAIFMT_CBM_CFM: | ||
974 | ioctl |= 0x2; | ||
975 | case SND_SOC_DAIFMT_CBM_CFS: | ||
976 | voice |= 0x0040; | ||
977 | break; | ||
978 | default: | ||
979 | return -EINVAL; | ||
980 | } | ||
981 | |||
982 | /* clock inversion */ | ||
983 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
984 | case SND_SOC_DAIFMT_DSP_A: | ||
985 | case SND_SOC_DAIFMT_DSP_B: | ||
986 | /* frame inversion not valid for DSP modes */ | ||
987 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
988 | case SND_SOC_DAIFMT_NB_NF: | ||
989 | break; | ||
990 | case SND_SOC_DAIFMT_IB_NF: | ||
991 | voice |= 0x0080; | ||
992 | break; | ||
993 | default: | ||
994 | return -EINVAL; | ||
995 | } | ||
996 | break; | ||
997 | case SND_SOC_DAIFMT_I2S: | ||
998 | case SND_SOC_DAIFMT_RIGHT_J: | ||
999 | case SND_SOC_DAIFMT_LEFT_J: | ||
1000 | voice &= ~0x0010; | ||
1001 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
1002 | case SND_SOC_DAIFMT_NB_NF: | ||
1003 | break; | ||
1004 | case SND_SOC_DAIFMT_IB_IF: | ||
1005 | voice |= 0x0090; | ||
1006 | break; | ||
1007 | case SND_SOC_DAIFMT_IB_NF: | ||
1008 | voice |= 0x0080; | ||
1009 | break; | ||
1010 | case SND_SOC_DAIFMT_NB_IF: | ||
1011 | voice |= 0x0010; | ||
1012 | break; | ||
1013 | default: | ||
1014 | return -EINVAL; | ||
1015 | } | ||
1016 | break; | ||
1017 | default: | ||
1018 | return -EINVAL; | ||
1019 | } | ||
1020 | |||
1021 | wm8753_write(codec, WM8753_PCM, voice); | ||
1022 | wm8753_write(codec, WM8753_IOCTL, ioctl); | ||
1023 | return 0; | ||
1024 | } | ||
1025 | |||
1026 | static int wm8753_set_dai_clkdiv(struct snd_soc_codec_dai *codec_dai, | ||
1027 | int div_id, int div) | ||
1028 | { | ||
1029 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1030 | u16 reg; | ||
1031 | |||
1032 | switch (div_id) { | ||
1033 | case WM8753_PCMDIV: | ||
1034 | reg = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0x003f; | ||
1035 | wm8753_write(codec, WM8753_CLOCK, reg | div); | ||
1036 | break; | ||
1037 | case WM8753_BCLKDIV: | ||
1038 | reg = wm8753_read_reg_cache(codec, WM8753_SRATE2) & 0x01c7; | ||
1039 | wm8753_write(codec, WM8753_SRATE2, reg | div); | ||
1040 | break; | ||
1041 | case WM8753_VXCLKDIV: | ||
1042 | reg = wm8753_read_reg_cache(codec, WM8753_SRATE2) & 0x003f; | ||
1043 | wm8753_write(codec, WM8753_SRATE2, reg | div); | ||
1044 | break; | ||
1045 | default: | ||
1046 | return -EINVAL; | ||
1047 | } | ||
1048 | return 0; | ||
1049 | } | ||
1050 | |||
1051 | /* | ||
1052 | * Set's HiFi DAC format. | ||
1053 | */ | ||
1054 | static int wm8753_hdac_set_dai_fmt(struct snd_soc_codec_dai *codec_dai, | ||
1055 | unsigned int fmt) | ||
1056 | { | ||
1057 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1058 | u16 hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x01e0; | ||
1059 | |||
1060 | /* interface format */ | ||
1061 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
1062 | case SND_SOC_DAIFMT_I2S: | ||
1063 | hifi |= 0x0002; | ||
1064 | break; | ||
1065 | case SND_SOC_DAIFMT_RIGHT_J: | ||
1066 | break; | ||
1067 | case SND_SOC_DAIFMT_LEFT_J: | ||
1068 | hifi |= 0x0001; | ||
1069 | break; | ||
1070 | case SND_SOC_DAIFMT_DSP_A: | ||
1071 | hifi |= 0x0003; | ||
1072 | break; | ||
1073 | case SND_SOC_DAIFMT_DSP_B: | ||
1074 | hifi |= 0x0013; | ||
1075 | break; | ||
1076 | default: | ||
1077 | return -EINVAL; | ||
1078 | } | ||
1079 | |||
1080 | wm8753_write(codec, WM8753_HIFI, hifi); | ||
1081 | return 0; | ||
1082 | } | ||
1083 | |||
1084 | /* | ||
1085 | * Set's I2S DAI format. | ||
1086 | */ | ||
1087 | static int wm8753_i2s_set_dai_fmt(struct snd_soc_codec_dai *codec_dai, | ||
1088 | unsigned int fmt) | ||
1089 | { | ||
1090 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1091 | u16 ioctl, hifi; | ||
1092 | |||
1093 | hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x011f; | ||
1094 | ioctl = wm8753_read_reg_cache(codec, WM8753_IOCTL) & 0x00ae; | ||
1095 | |||
1096 | /* set master/slave audio interface */ | ||
1097 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
1098 | case SND_SOC_DAIFMT_CBS_CFS: | ||
1099 | break; | ||
1100 | case SND_SOC_DAIFMT_CBM_CFM: | ||
1101 | ioctl |= 0x1; | ||
1102 | case SND_SOC_DAIFMT_CBM_CFS: | ||
1103 | hifi |= 0x0040; | ||
1104 | break; | ||
1105 | default: | ||
1106 | return -EINVAL; | ||
1107 | } | ||
1108 | |||
1109 | /* clock inversion */ | ||
1110 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
1111 | case SND_SOC_DAIFMT_DSP_A: | ||
1112 | case SND_SOC_DAIFMT_DSP_B: | ||
1113 | /* frame inversion not valid for DSP modes */ | ||
1114 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
1115 | case SND_SOC_DAIFMT_NB_NF: | ||
1116 | break; | ||
1117 | case SND_SOC_DAIFMT_IB_NF: | ||
1118 | hifi |= 0x0080; | ||
1119 | break; | ||
1120 | default: | ||
1121 | return -EINVAL; | ||
1122 | } | ||
1123 | break; | ||
1124 | case SND_SOC_DAIFMT_I2S: | ||
1125 | case SND_SOC_DAIFMT_RIGHT_J: | ||
1126 | case SND_SOC_DAIFMT_LEFT_J: | ||
1127 | hifi &= ~0x0010; | ||
1128 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
1129 | case SND_SOC_DAIFMT_NB_NF: | ||
1130 | break; | ||
1131 | case SND_SOC_DAIFMT_IB_IF: | ||
1132 | hifi |= 0x0090; | ||
1133 | break; | ||
1134 | case SND_SOC_DAIFMT_IB_NF: | ||
1135 | hifi |= 0x0080; | ||
1136 | break; | ||
1137 | case SND_SOC_DAIFMT_NB_IF: | ||
1138 | hifi |= 0x0010; | ||
1139 | break; | ||
1140 | default: | ||
1141 | return -EINVAL; | ||
1142 | } | ||
1143 | break; | ||
1144 | default: | ||
1145 | return -EINVAL; | ||
1146 | } | ||
1147 | |||
1148 | wm8753_write(codec, WM8753_HIFI, hifi); | ||
1149 | wm8753_write(codec, WM8753_IOCTL, ioctl); | ||
1150 | return 0; | ||
1151 | } | ||
1152 | |||
1153 | /* | ||
1154 | * Set PCM DAI bit size and sample rate. | ||
1155 | */ | ||
1156 | static int wm8753_i2s_hw_params(struct snd_pcm_substream *substream, | ||
1157 | struct snd_pcm_hw_params *params) | ||
1158 | { | ||
1159 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
1160 | struct snd_soc_device *socdev = rtd->socdev; | ||
1161 | struct snd_soc_codec *codec = socdev->codec; | ||
1162 | struct wm8753_priv *wm8753 = codec->private_data; | ||
1163 | u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x01c0; | ||
1164 | u16 hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x01f3; | ||
1165 | int coeff; | ||
1166 | |||
1167 | /* is digital filter coefficient valid ? */ | ||
1168 | coeff = get_coeff(wm8753->sysclk, params_rate(params)); | ||
1169 | if (coeff < 0) { | ||
1170 | printk(KERN_ERR "wm8753 invalid MCLK or rate\n"); | ||
1171 | return coeff; | ||
1172 | } | ||
1173 | wm8753_write(codec, WM8753_SRATE1, srate | (coeff_div[coeff].sr << 1) | | ||
1174 | coeff_div[coeff].usb); | ||
1175 | |||
1176 | /* bit size */ | ||
1177 | switch (params_format(params)) { | ||
1178 | case SNDRV_PCM_FORMAT_S16_LE: | ||
1179 | break; | ||
1180 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
1181 | hifi |= 0x0004; | ||
1182 | break; | ||
1183 | case SNDRV_PCM_FORMAT_S24_LE: | ||
1184 | hifi |= 0x0008; | ||
1185 | break; | ||
1186 | case SNDRV_PCM_FORMAT_S32_LE: | ||
1187 | hifi |= 0x000c; | ||
1188 | break; | ||
1189 | } | ||
1190 | |||
1191 | wm8753_write(codec, WM8753_HIFI, hifi); | ||
1192 | return 0; | ||
1193 | } | ||
1194 | |||
1195 | static int wm8753_mode1v_set_dai_fmt(struct snd_soc_codec_dai *codec_dai, | ||
1196 | unsigned int fmt) | ||
1197 | { | ||
1198 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1199 | u16 clock; | ||
1200 | |||
1201 | /* set clk source as pcmclk */ | ||
1202 | clock = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xfffb; | ||
1203 | wm8753_write(codec, WM8753_CLOCK, clock); | ||
1204 | |||
1205 | if (wm8753_vdac_adc_set_dai_fmt(codec_dai, fmt) < 0) | ||
1206 | return -EINVAL; | ||
1207 | return wm8753_pcm_set_dai_fmt(codec_dai, fmt); | ||
1208 | } | ||
1209 | |||
1210 | static int wm8753_mode1h_set_dai_fmt(struct snd_soc_codec_dai *codec_dai, | ||
1211 | unsigned int fmt) | ||
1212 | { | ||
1213 | if (wm8753_hdac_set_dai_fmt(codec_dai, fmt) < 0) | ||
1214 | return -EINVAL; | ||
1215 | return wm8753_i2s_set_dai_fmt(codec_dai, fmt); | ||
1216 | } | ||
1217 | |||
1218 | static int wm8753_mode2_set_dai_fmt(struct snd_soc_codec_dai *codec_dai, | ||
1219 | unsigned int fmt) | ||
1220 | { | ||
1221 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1222 | u16 clock; | ||
1223 | |||
1224 | /* set clk source as pcmclk */ | ||
1225 | clock = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xfffb; | ||
1226 | wm8753_write(codec, WM8753_CLOCK, clock); | ||
1227 | |||
1228 | if (wm8753_vdac_adc_set_dai_fmt(codec_dai, fmt) < 0) | ||
1229 | return -EINVAL; | ||
1230 | return wm8753_i2s_set_dai_fmt(codec_dai, fmt); | ||
1231 | } | ||
1232 | |||
1233 | static int wm8753_mode3_4_set_dai_fmt(struct snd_soc_codec_dai *codec_dai, | ||
1234 | unsigned int fmt) | ||
1235 | { | ||
1236 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1237 | u16 clock; | ||
1238 | |||
1239 | /* set clk source as mclk */ | ||
1240 | clock = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xfffb; | ||
1241 | wm8753_write(codec, WM8753_CLOCK, clock | 0x4); | ||
1242 | |||
1243 | if (wm8753_hdac_set_dai_fmt(codec_dai, fmt) < 0) | ||
1244 | return -EINVAL; | ||
1245 | if (wm8753_vdac_adc_set_dai_fmt(codec_dai, fmt) < 0) | ||
1246 | return -EINVAL; | ||
1247 | return wm8753_i2s_set_dai_fmt(codec_dai, fmt); | ||
1248 | } | ||
1249 | |||
1250 | static int wm8753_mute(struct snd_soc_codec_dai *dai, int mute) | ||
1251 | { | ||
1252 | struct snd_soc_codec *codec = dai->codec; | ||
1253 | u16 mute_reg = wm8753_read_reg_cache(codec, WM8753_DAC) & 0xfff7; | ||
1254 | |||
1255 | /* the digital mute covers the HiFi and Voice DAC's on the WM8753. | ||
1256 | * make sure we check if they are not both active when we mute */ | ||
1257 | if (mute && dai->id == 1) { | ||
1258 | if (!wm8753_dai[WM8753_DAI_VOICE].playback.active || | ||
1259 | !wm8753_dai[WM8753_DAI_HIFI].playback.active) | ||
1260 | wm8753_write(codec, WM8753_DAC, mute_reg | 0x8); | ||
1261 | } else { | ||
1262 | if (mute) | ||
1263 | wm8753_write(codec, WM8753_DAC, mute_reg | 0x8); | ||
1264 | else | ||
1265 | wm8753_write(codec, WM8753_DAC, mute_reg); | ||
1266 | } | ||
1267 | |||
1268 | return 0; | ||
1269 | } | ||
1270 | |||
1271 | static int wm8753_dapm_event(struct snd_soc_codec *codec, int event) | ||
1272 | { | ||
1273 | u16 pwr_reg = wm8753_read_reg_cache(codec, WM8753_PWR1) & 0xfe3e; | ||
1274 | |||
1275 | switch (event) { | ||
1276 | case SNDRV_CTL_POWER_D0: /* full On */ | ||
1277 | /* set vmid to 50k and unmute dac */ | ||
1278 | wm8753_write(codec, WM8753_PWR1, pwr_reg | 0x00c0); | ||
1279 | break; | ||
1280 | case SNDRV_CTL_POWER_D1: /* partial On */ | ||
1281 | case SNDRV_CTL_POWER_D2: /* partial On */ | ||
1282 | /* set vmid to 5k for quick power up */ | ||
1283 | wm8753_write(codec, WM8753_PWR1, pwr_reg | 0x01c1); | ||
1284 | break; | ||
1285 | case SNDRV_CTL_POWER_D3hot: /* Off, with power */ | ||
1286 | /* mute dac and set vmid to 500k, enable VREF */ | ||
1287 | wm8753_write(codec, WM8753_PWR1, pwr_reg | 0x0141); | ||
1288 | break; | ||
1289 | case SNDRV_CTL_POWER_D3cold: /* Off, without power */ | ||
1290 | wm8753_write(codec, WM8753_PWR1, 0x0001); | ||
1291 | break; | ||
1292 | } | ||
1293 | codec->dapm_state = event; | ||
1294 | return 0; | ||
1295 | } | ||
1296 | |||
1297 | #define WM8753_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ | ||
1298 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \ | ||
1299 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) | ||
1300 | |||
1301 | #define WM8753_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | ||
1302 | SNDRV_PCM_FMTBIT_S24_LE) | ||
1303 | |||
1304 | /* | ||
1305 | * The WM8753 supports upto 4 different and mutually exclusive DAI | ||
1306 | * configurations. This gives 2 PCM's available for use, hifi and voice. | ||
1307 | * NOTE: The Voice PCM cannot play or capture audio to the CPU as it's DAI | ||
1308 | * is connected between the wm8753 and a BT codec or GSM modem. | ||
1309 | * | ||
1310 | * 1. Voice over PCM DAI - HIFI DAC over HIFI DAI | ||
1311 | * 2. Voice over HIFI DAI - HIFI disabled | ||
1312 | * 3. Voice disabled - HIFI over HIFI | ||
1313 | * 4. Voice disabled - HIFI over HIFI, uses voice DAI LRC for capture | ||
1314 | */ | ||
1315 | static const struct snd_soc_codec_dai wm8753_all_dai[] = { | ||
1316 | /* DAI HiFi mode 1 */ | ||
1317 | { .name = "WM8753 HiFi", | ||
1318 | .id = 1, | ||
1319 | .playback = { | ||
1320 | .stream_name = "HiFi Playback", | ||
1321 | .channels_min = 1, | ||
1322 | .channels_max = 2, | ||
1323 | .rates = WM8753_RATES, | ||
1324 | .formats = WM8753_FORMATS,}, | ||
1325 | .capture = { /* dummy for fast DAI switching */ | ||
1326 | .stream_name = "Capture", | ||
1327 | .channels_min = 1, | ||
1328 | .channels_max = 2, | ||
1329 | .rates = WM8753_RATES, | ||
1330 | .formats = WM8753_FORMATS,}, | ||
1331 | .ops = { | ||
1332 | .hw_params = wm8753_i2s_hw_params,}, | ||
1333 | .dai_ops = { | ||
1334 | .digital_mute = wm8753_mute, | ||
1335 | .set_fmt = wm8753_mode1h_set_dai_fmt, | ||
1336 | .set_clkdiv = wm8753_set_dai_clkdiv, | ||
1337 | .set_pll = wm8753_set_dai_pll, | ||
1338 | .set_sysclk = wm8753_set_dai_sysclk, | ||
1339 | }, | ||
1340 | }, | ||
1341 | /* DAI Voice mode 1 */ | ||
1342 | { .name = "WM8753 Voice", | ||
1343 | .id = 1, | ||
1344 | .playback = { | ||
1345 | .stream_name = "Voice Playback", | ||
1346 | .channels_min = 1, | ||
1347 | .channels_max = 1, | ||
1348 | .rates = WM8753_RATES, | ||
1349 | .formats = WM8753_FORMATS,}, | ||
1350 | .capture = { | ||
1351 | .stream_name = "Capture", | ||
1352 | .channels_min = 1, | ||
1353 | .channels_max = 2, | ||
1354 | .rates = WM8753_RATES, | ||
1355 | .formats = WM8753_FORMATS,}, | ||
1356 | .ops = { | ||
1357 | .hw_params = wm8753_pcm_hw_params,}, | ||
1358 | .dai_ops = { | ||
1359 | .digital_mute = wm8753_mute, | ||
1360 | .set_fmt = wm8753_mode1v_set_dai_fmt, | ||
1361 | .set_clkdiv = wm8753_set_dai_clkdiv, | ||
1362 | .set_pll = wm8753_set_dai_pll, | ||
1363 | .set_sysclk = wm8753_set_dai_sysclk, | ||
1364 | }, | ||
1365 | }, | ||
1366 | /* DAI HiFi mode 2 - dummy */ | ||
1367 | { .name = "WM8753 HiFi", | ||
1368 | .id = 2, | ||
1369 | }, | ||
1370 | /* DAI Voice mode 2 */ | ||
1371 | { .name = "WM8753 Voice", | ||
1372 | .id = 2, | ||
1373 | .playback = { | ||
1374 | .stream_name = "Voice Playback", | ||
1375 | .channels_min = 1, | ||
1376 | .channels_max = 1, | ||
1377 | .rates = WM8753_RATES, | ||
1378 | .formats = WM8753_FORMATS,}, | ||
1379 | .capture = { | ||
1380 | .stream_name = "Capture", | ||
1381 | .channels_min = 1, | ||
1382 | .channels_max = 2, | ||
1383 | .rates = WM8753_RATES, | ||
1384 | .formats = WM8753_FORMATS,}, | ||
1385 | .ops = { | ||
1386 | .hw_params = wm8753_pcm_hw_params,}, | ||
1387 | .dai_ops = { | ||
1388 | .digital_mute = wm8753_mute, | ||
1389 | .set_fmt = wm8753_mode2_set_dai_fmt, | ||
1390 | .set_clkdiv = wm8753_set_dai_clkdiv, | ||
1391 | .set_pll = wm8753_set_dai_pll, | ||
1392 | .set_sysclk = wm8753_set_dai_sysclk, | ||
1393 | }, | ||
1394 | }, | ||
1395 | /* DAI HiFi mode 3 */ | ||
1396 | { .name = "WM8753 HiFi", | ||
1397 | .id = 3, | ||
1398 | .playback = { | ||
1399 | .stream_name = "HiFi Playback", | ||
1400 | .channels_min = 1, | ||
1401 | .channels_max = 2, | ||
1402 | .rates = WM8753_RATES, | ||
1403 | .formats = WM8753_FORMATS,}, | ||
1404 | .capture = { | ||
1405 | .stream_name = "Capture", | ||
1406 | .channels_min = 1, | ||
1407 | .channels_max = 2, | ||
1408 | .rates = WM8753_RATES, | ||
1409 | .formats = WM8753_FORMATS,}, | ||
1410 | .ops = { | ||
1411 | .hw_params = wm8753_i2s_hw_params,}, | ||
1412 | .dai_ops = { | ||
1413 | .digital_mute = wm8753_mute, | ||
1414 | .set_fmt = wm8753_mode3_4_set_dai_fmt, | ||
1415 | .set_clkdiv = wm8753_set_dai_clkdiv, | ||
1416 | .set_pll = wm8753_set_dai_pll, | ||
1417 | .set_sysclk = wm8753_set_dai_sysclk, | ||
1418 | }, | ||
1419 | }, | ||
1420 | /* DAI Voice mode 3 - dummy */ | ||
1421 | { .name = "WM8753 Voice", | ||
1422 | .id = 3, | ||
1423 | }, | ||
1424 | /* DAI HiFi mode 4 */ | ||
1425 | { .name = "WM8753 HiFi", | ||
1426 | .id = 4, | ||
1427 | .playback = { | ||
1428 | .stream_name = "HiFi Playback", | ||
1429 | .channels_min = 1, | ||
1430 | .channels_max = 2, | ||
1431 | .rates = WM8753_RATES, | ||
1432 | .formats = WM8753_FORMATS,}, | ||
1433 | .capture = { | ||
1434 | .stream_name = "Capture", | ||
1435 | .channels_min = 1, | ||
1436 | .channels_max = 2, | ||
1437 | .rates = WM8753_RATES, | ||
1438 | .formats = WM8753_FORMATS,}, | ||
1439 | .ops = { | ||
1440 | .hw_params = wm8753_i2s_hw_params,}, | ||
1441 | .dai_ops = { | ||
1442 | .digital_mute = wm8753_mute, | ||
1443 | .set_fmt = wm8753_mode3_4_set_dai_fmt, | ||
1444 | .set_clkdiv = wm8753_set_dai_clkdiv, | ||
1445 | .set_pll = wm8753_set_dai_pll, | ||
1446 | .set_sysclk = wm8753_set_dai_sysclk, | ||
1447 | }, | ||
1448 | }, | ||
1449 | /* DAI Voice mode 4 - dummy */ | ||
1450 | { .name = "WM8753 Voice", | ||
1451 | .id = 4, | ||
1452 | }, | ||
1453 | }; | ||
1454 | |||
1455 | struct snd_soc_codec_dai wm8753_dai[2]; | ||
1456 | EXPORT_SYMBOL_GPL(wm8753_dai); | ||
1457 | |||
1458 | static void wm8753_set_dai_mode(struct snd_soc_codec *codec, unsigned int mode) | ||
1459 | { | ||
1460 | if (mode < 4) { | ||
1461 | int playback_active, capture_active, codec_active, pop_wait; | ||
1462 | void *private_data; | ||
1463 | |||
1464 | playback_active = wm8753_dai[0].playback.active; | ||
1465 | capture_active = wm8753_dai[0].capture.active; | ||
1466 | codec_active = wm8753_dai[0].active; | ||
1467 | private_data = wm8753_dai[0].private_data; | ||
1468 | pop_wait = wm8753_dai[0].pop_wait; | ||
1469 | wm8753_dai[0] = wm8753_all_dai[mode << 1]; | ||
1470 | wm8753_dai[0].playback.active = playback_active; | ||
1471 | wm8753_dai[0].capture.active = capture_active; | ||
1472 | wm8753_dai[0].active = codec_active; | ||
1473 | wm8753_dai[0].private_data = private_data; | ||
1474 | wm8753_dai[0].pop_wait = pop_wait; | ||
1475 | |||
1476 | playback_active = wm8753_dai[1].playback.active; | ||
1477 | capture_active = wm8753_dai[1].capture.active; | ||
1478 | codec_active = wm8753_dai[1].active; | ||
1479 | private_data = wm8753_dai[1].private_data; | ||
1480 | pop_wait = wm8753_dai[1].pop_wait; | ||
1481 | wm8753_dai[1] = wm8753_all_dai[(mode << 1) + 1]; | ||
1482 | wm8753_dai[1].playback.active = playback_active; | ||
1483 | wm8753_dai[1].capture.active = capture_active; | ||
1484 | wm8753_dai[1].active = codec_active; | ||
1485 | wm8753_dai[1].private_data = private_data; | ||
1486 | wm8753_dai[1].pop_wait = pop_wait; | ||
1487 | } | ||
1488 | wm8753_dai[0].codec = codec; | ||
1489 | wm8753_dai[1].codec = codec; | ||
1490 | } | ||
1491 | |||
1492 | static void wm8753_work(struct work_struct *work) | ||
1493 | { | ||
1494 | struct snd_soc_codec *codec = | ||
1495 | container_of(work, struct snd_soc_codec, delayed_work.work); | ||
1496 | wm8753_dapm_event(codec, codec->dapm_state); | ||
1497 | } | ||
1498 | |||
1499 | static int wm8753_suspend(struct platform_device *pdev, pm_message_t state) | ||
1500 | { | ||
1501 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1502 | struct snd_soc_codec *codec = socdev->codec; | ||
1503 | |||
1504 | /* we only need to suspend if we are a valid card */ | ||
1505 | if(!codec->card) | ||
1506 | return 0; | ||
1507 | |||
1508 | wm8753_dapm_event(codec, SNDRV_CTL_POWER_D3cold); | ||
1509 | return 0; | ||
1510 | } | ||
1511 | |||
1512 | static int wm8753_resume(struct platform_device *pdev) | ||
1513 | { | ||
1514 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1515 | struct snd_soc_codec *codec = socdev->codec; | ||
1516 | int i; | ||
1517 | u8 data[2]; | ||
1518 | u16 *cache = codec->reg_cache; | ||
1519 | |||
1520 | /* we only need to resume if we are a valid card */ | ||
1521 | if(!codec->card) | ||
1522 | return 0; | ||
1523 | |||
1524 | /* Sync reg_cache with the hardware */ | ||
1525 | for (i = 0; i < ARRAY_SIZE(wm8753_reg); i++) { | ||
1526 | if (i + 1 == WM8753_RESET) | ||
1527 | continue; | ||
1528 | data[0] = ((i + 1) << 1) | ((cache[i] >> 8) & 0x0001); | ||
1529 | data[1] = cache[i] & 0x00ff; | ||
1530 | codec->hw_write(codec->control_data, data, 2); | ||
1531 | } | ||
1532 | |||
1533 | wm8753_dapm_event(codec, SNDRV_CTL_POWER_D3hot); | ||
1534 | |||
1535 | /* charge wm8753 caps */ | ||
1536 | if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0) { | ||
1537 | wm8753_dapm_event(codec, SNDRV_CTL_POWER_D2); | ||
1538 | codec->dapm_state = SNDRV_CTL_POWER_D0; | ||
1539 | schedule_delayed_work(&codec->delayed_work, | ||
1540 | msecs_to_jiffies(caps_charge)); | ||
1541 | } | ||
1542 | |||
1543 | return 0; | ||
1544 | } | ||
1545 | |||
1546 | /* | ||
1547 | * initialise the WM8753 driver | ||
1548 | * register the mixer and dsp interfaces with the kernel | ||
1549 | */ | ||
1550 | static int wm8753_init(struct snd_soc_device *socdev) | ||
1551 | { | ||
1552 | struct snd_soc_codec *codec = socdev->codec; | ||
1553 | int reg, ret = 0; | ||
1554 | |||
1555 | codec->name = "WM8753"; | ||
1556 | codec->owner = THIS_MODULE; | ||
1557 | codec->read = wm8753_read_reg_cache; | ||
1558 | codec->write = wm8753_write; | ||
1559 | codec->dapm_event = wm8753_dapm_event; | ||
1560 | codec->dai = wm8753_dai; | ||
1561 | codec->num_dai = 2; | ||
1562 | codec->reg_cache_size = sizeof(wm8753_reg); | ||
1563 | codec->reg_cache = kmemdup(wm8753_reg, sizeof(wm8753_reg), GFP_KERNEL); | ||
1564 | |||
1565 | if (codec->reg_cache == NULL) | ||
1566 | return -ENOMEM; | ||
1567 | |||
1568 | wm8753_set_dai_mode(codec, 0); | ||
1569 | |||
1570 | wm8753_reset(codec); | ||
1571 | |||
1572 | /* register pcms */ | ||
1573 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
1574 | if (ret < 0) { | ||
1575 | printk(KERN_ERR "wm8753: failed to create pcms\n"); | ||
1576 | goto pcm_err; | ||
1577 | } | ||
1578 | |||
1579 | /* charge output caps */ | ||
1580 | wm8753_dapm_event(codec, SNDRV_CTL_POWER_D2); | ||
1581 | codec->dapm_state = SNDRV_CTL_POWER_D3hot; | ||
1582 | schedule_delayed_work(&codec->delayed_work, | ||
1583 | msecs_to_jiffies(caps_charge)); | ||
1584 | |||
1585 | /* set the update bits */ | ||
1586 | reg = wm8753_read_reg_cache(codec, WM8753_LDAC); | ||
1587 | wm8753_write(codec, WM8753_LDAC, reg | 0x0100); | ||
1588 | reg = wm8753_read_reg_cache(codec, WM8753_RDAC); | ||
1589 | wm8753_write(codec, WM8753_RDAC, reg | 0x0100); | ||
1590 | reg = wm8753_read_reg_cache(codec, WM8753_LADC); | ||
1591 | wm8753_write(codec, WM8753_LADC, reg | 0x0100); | ||
1592 | reg = wm8753_read_reg_cache(codec, WM8753_RADC); | ||
1593 | wm8753_write(codec, WM8753_RADC, reg | 0x0100); | ||
1594 | reg = wm8753_read_reg_cache(codec, WM8753_LOUT1V); | ||
1595 | wm8753_write(codec, WM8753_LOUT1V, reg | 0x0100); | ||
1596 | reg = wm8753_read_reg_cache(codec, WM8753_ROUT1V); | ||
1597 | wm8753_write(codec, WM8753_ROUT1V, reg | 0x0100); | ||
1598 | reg = wm8753_read_reg_cache(codec, WM8753_LOUT2V); | ||
1599 | wm8753_write(codec, WM8753_LOUT2V, reg | 0x0100); | ||
1600 | reg = wm8753_read_reg_cache(codec, WM8753_ROUT2V); | ||
1601 | wm8753_write(codec, WM8753_ROUT2V, reg | 0x0100); | ||
1602 | reg = wm8753_read_reg_cache(codec, WM8753_LINVOL); | ||
1603 | wm8753_write(codec, WM8753_LINVOL, reg | 0x0100); | ||
1604 | reg = wm8753_read_reg_cache(codec, WM8753_RINVOL); | ||
1605 | wm8753_write(codec, WM8753_RINVOL, reg | 0x0100); | ||
1606 | |||
1607 | wm8753_add_controls(codec); | ||
1608 | wm8753_add_widgets(codec); | ||
1609 | ret = snd_soc_register_card(socdev); | ||
1610 | if (ret < 0) { | ||
1611 | printk(KERN_ERR "wm8753: failed to register card\n"); | ||
1612 | goto card_err; | ||
1613 | } | ||
1614 | return ret; | ||
1615 | |||
1616 | card_err: | ||
1617 | snd_soc_free_pcms(socdev); | ||
1618 | snd_soc_dapm_free(socdev); | ||
1619 | pcm_err: | ||
1620 | kfree(codec->reg_cache); | ||
1621 | return ret; | ||
1622 | } | ||
1623 | |||
1624 | /* If the i2c layer weren't so broken, we could pass this kind of data | ||
1625 | around */ | ||
1626 | static struct snd_soc_device *wm8753_socdev; | ||
1627 | |||
1628 | #if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) | ||
1629 | |||
1630 | /* | ||
1631 | * WM8753 2 wire address is determined by GPIO5 | ||
1632 | * state during powerup. | ||
1633 | * low = 0x1a | ||
1634 | * high = 0x1b | ||
1635 | */ | ||
1636 | static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END }; | ||
1637 | |||
1638 | /* Magic definition of all other variables and things */ | ||
1639 | I2C_CLIENT_INSMOD; | ||
1640 | |||
1641 | static struct i2c_driver wm8753_i2c_driver; | ||
1642 | static struct i2c_client client_template; | ||
1643 | |||
1644 | static int wm8753_codec_probe(struct i2c_adapter *adap, int addr, int kind) | ||
1645 | { | ||
1646 | struct snd_soc_device *socdev = wm8753_socdev; | ||
1647 | struct wm8753_setup_data *setup = socdev->codec_data; | ||
1648 | struct snd_soc_codec *codec = socdev->codec; | ||
1649 | struct i2c_client *i2c; | ||
1650 | int ret; | ||
1651 | |||
1652 | if (addr != setup->i2c_address) | ||
1653 | return -ENODEV; | ||
1654 | |||
1655 | client_template.adapter = adap; | ||
1656 | client_template.addr = addr; | ||
1657 | |||
1658 | i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL); | ||
1659 | if (i2c == NULL){ | ||
1660 | kfree(codec); | ||
1661 | return -ENOMEM; | ||
1662 | } | ||
1663 | i2c_set_clientdata(i2c, codec); | ||
1664 | codec->control_data = i2c; | ||
1665 | |||
1666 | ret = i2c_attach_client(i2c); | ||
1667 | if (ret < 0) { | ||
1668 | err("failed to attach codec at addr %x\n", addr); | ||
1669 | goto err; | ||
1670 | } | ||
1671 | |||
1672 | ret = wm8753_init(socdev); | ||
1673 | if (ret < 0) { | ||
1674 | err("failed to initialise WM8753\n"); | ||
1675 | goto err; | ||
1676 | } | ||
1677 | |||
1678 | return ret; | ||
1679 | |||
1680 | err: | ||
1681 | kfree(codec); | ||
1682 | kfree(i2c); | ||
1683 | return ret; | ||
1684 | } | ||
1685 | |||
1686 | static int wm8753_i2c_detach(struct i2c_client *client) | ||
1687 | { | ||
1688 | struct snd_soc_codec *codec = i2c_get_clientdata(client); | ||
1689 | i2c_detach_client(client); | ||
1690 | kfree(codec->reg_cache); | ||
1691 | kfree(client); | ||
1692 | return 0; | ||
1693 | } | ||
1694 | |||
1695 | static int wm8753_i2c_attach(struct i2c_adapter *adap) | ||
1696 | { | ||
1697 | return i2c_probe(adap, &addr_data, wm8753_codec_probe); | ||
1698 | } | ||
1699 | |||
1700 | /* corgi i2c codec control layer */ | ||
1701 | static struct i2c_driver wm8753_i2c_driver = { | ||
1702 | .driver = { | ||
1703 | .name = "WM8753 I2C Codec", | ||
1704 | .owner = THIS_MODULE, | ||
1705 | }, | ||
1706 | .id = I2C_DRIVERID_WM8753, | ||
1707 | .attach_adapter = wm8753_i2c_attach, | ||
1708 | .detach_client = wm8753_i2c_detach, | ||
1709 | .command = NULL, | ||
1710 | }; | ||
1711 | |||
1712 | static struct i2c_client client_template = { | ||
1713 | .name = "WM8753", | ||
1714 | .driver = &wm8753_i2c_driver, | ||
1715 | }; | ||
1716 | #endif | ||
1717 | |||
1718 | static int wm8753_probe(struct platform_device *pdev) | ||
1719 | { | ||
1720 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1721 | struct wm8753_setup_data *setup; | ||
1722 | struct snd_soc_codec *codec; | ||
1723 | struct wm8753_priv *wm8753; | ||
1724 | int ret = 0; | ||
1725 | |||
1726 | info("WM8753 Audio Codec %s", WM8753_VERSION); | ||
1727 | |||
1728 | setup = socdev->codec_data; | ||
1729 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | ||
1730 | if (codec == NULL) | ||
1731 | return -ENOMEM; | ||
1732 | |||
1733 | wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL); | ||
1734 | if (wm8753 == NULL) { | ||
1735 | kfree(codec); | ||
1736 | return -ENOMEM; | ||
1737 | } | ||
1738 | |||
1739 | codec->private_data = wm8753; | ||
1740 | socdev->codec = codec; | ||
1741 | mutex_init(&codec->mutex); | ||
1742 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
1743 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
1744 | wm8753_socdev = socdev; | ||
1745 | INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work); | ||
1746 | |||
1747 | #if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) | ||
1748 | if (setup->i2c_address) { | ||
1749 | normal_i2c[0] = setup->i2c_address; | ||
1750 | codec->hw_write = (hw_write_t)i2c_master_send; | ||
1751 | ret = i2c_add_driver(&wm8753_i2c_driver); | ||
1752 | if (ret != 0) | ||
1753 | printk(KERN_ERR "can't add i2c driver"); | ||
1754 | } | ||
1755 | #else | ||
1756 | /* Add other interfaces here */ | ||
1757 | #endif | ||
1758 | return ret; | ||
1759 | } | ||
1760 | |||
1761 | /* | ||
1762 | * This function forces any delayed work to be queued and run. | ||
1763 | */ | ||
1764 | static int run_delayed_work(struct delayed_work *dwork) | ||
1765 | { | ||
1766 | int ret; | ||
1767 | |||
1768 | /* cancel any work waiting to be queued. */ | ||
1769 | ret = cancel_delayed_work(dwork); | ||
1770 | |||
1771 | /* if there was any work waiting then we run it now and | ||
1772 | * wait for it's completion */ | ||
1773 | if (ret) { | ||
1774 | schedule_delayed_work(dwork, 0); | ||
1775 | flush_scheduled_work(); | ||
1776 | } | ||
1777 | return ret; | ||
1778 | } | ||
1779 | |||
1780 | /* power down chip */ | ||
1781 | static int wm8753_remove(struct platform_device *pdev) | ||
1782 | { | ||
1783 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1784 | struct snd_soc_codec *codec = socdev->codec; | ||
1785 | |||
1786 | if (codec->control_data) | ||
1787 | wm8753_dapm_event(codec, SNDRV_CTL_POWER_D3cold); | ||
1788 | run_delayed_work(&codec->delayed_work); | ||
1789 | snd_soc_free_pcms(socdev); | ||
1790 | snd_soc_dapm_free(socdev); | ||
1791 | #if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) | ||
1792 | i2c_del_driver(&wm8753_i2c_driver); | ||
1793 | #endif | ||
1794 | kfree(codec->private_data); | ||
1795 | kfree(codec); | ||
1796 | |||
1797 | return 0; | ||
1798 | } | ||
1799 | |||
1800 | struct snd_soc_codec_device soc_codec_dev_wm8753 = { | ||
1801 | .probe = wm8753_probe, | ||
1802 | .remove = wm8753_remove, | ||
1803 | .suspend = wm8753_suspend, | ||
1804 | .resume = wm8753_resume, | ||
1805 | }; | ||
1806 | |||
1807 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753); | ||
1808 | |||
1809 | MODULE_DESCRIPTION("ASoC WM8753 driver"); | ||
1810 | MODULE_AUTHOR("Liam Girdwood"); | ||
1811 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/wm8753.h b/sound/soc/codecs/wm8753.h new file mode 100644 index 000000000000..95e2a1f53169 --- /dev/null +++ b/sound/soc/codecs/wm8753.h | |||
@@ -0,0 +1,126 @@ | |||
1 | /* | ||
2 | * wm8753.h -- audio driver for WM8753 | ||
3 | * | ||
4 | * Copyright 2003 Wolfson Microelectronics PLC. | ||
5 | * Author: Liam Girdwood | ||
6 | * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #ifndef _WM8753_H | ||
16 | #define _WM8753_H | ||
17 | |||
18 | /* WM8753 register space */ | ||
19 | |||
20 | #define WM8753_DAC 0x01 | ||
21 | #define WM8753_ADC 0x02 | ||
22 | #define WM8753_PCM 0x03 | ||
23 | #define WM8753_HIFI 0x04 | ||
24 | #define WM8753_IOCTL 0x05 | ||
25 | #define WM8753_SRATE1 0x06 | ||
26 | #define WM8753_SRATE2 0x07 | ||
27 | #define WM8753_LDAC 0x08 | ||
28 | #define WM8753_RDAC 0x09 | ||
29 | #define WM8753_BASS 0x0a | ||
30 | #define WM8753_TREBLE 0x0b | ||
31 | #define WM8753_ALC1 0x0c | ||
32 | #define WM8753_ALC2 0x0d | ||
33 | #define WM8753_ALC3 0x0e | ||
34 | #define WM8753_NGATE 0x0f | ||
35 | #define WM8753_LADC 0x10 | ||
36 | #define WM8753_RADC 0x11 | ||
37 | #define WM8753_ADCTL1 0x12 | ||
38 | #define WM8753_3D 0x13 | ||
39 | #define WM8753_PWR1 0x14 | ||
40 | #define WM8753_PWR2 0x15 | ||
41 | #define WM8753_PWR3 0x16 | ||
42 | #define WM8753_PWR4 0x17 | ||
43 | #define WM8753_ID 0x18 | ||
44 | #define WM8753_INTPOL 0x19 | ||
45 | #define WM8753_INTEN 0x1a | ||
46 | #define WM8753_GPIO1 0x1b | ||
47 | #define WM8753_GPIO2 0x1c | ||
48 | #define WM8753_RESET 0x1f | ||
49 | #define WM8753_RECMIX1 0x20 | ||
50 | #define WM8753_RECMIX2 0x21 | ||
51 | #define WM8753_LOUTM1 0x22 | ||
52 | #define WM8753_LOUTM2 0x23 | ||
53 | #define WM8753_ROUTM1 0x24 | ||
54 | #define WM8753_ROUTM2 0x25 | ||
55 | #define WM8753_MOUTM1 0x26 | ||
56 | #define WM8753_MOUTM2 0x27 | ||
57 | #define WM8753_LOUT1V 0x28 | ||
58 | #define WM8753_ROUT1V 0x29 | ||
59 | #define WM8753_LOUT2V 0x2a | ||
60 | #define WM8753_ROUT2V 0x2b | ||
61 | #define WM8753_MOUTV 0x2c | ||
62 | #define WM8753_OUTCTL 0x2d | ||
63 | #define WM8753_ADCIN 0x2e | ||
64 | #define WM8753_INCTL1 0x2f | ||
65 | #define WM8753_INCTL2 0x30 | ||
66 | #define WM8753_LINVOL 0x31 | ||
67 | #define WM8753_RINVOL 0x32 | ||
68 | #define WM8753_MICBIAS 0x33 | ||
69 | #define WM8753_CLOCK 0x34 | ||
70 | #define WM8753_PLL1CTL1 0x35 | ||
71 | #define WM8753_PLL1CTL2 0x36 | ||
72 | #define WM8753_PLL1CTL3 0x37 | ||
73 | #define WM8753_PLL1CTL4 0x38 | ||
74 | #define WM8753_PLL2CTL1 0x39 | ||
75 | #define WM8753_PLL2CTL2 0x3a | ||
76 | #define WM8753_PLL2CTL3 0x3b | ||
77 | #define WM8753_PLL2CTL4 0x3c | ||
78 | #define WM8753_BIASCTL 0x3d | ||
79 | #define WM8753_ADCTL2 0x3f | ||
80 | |||
81 | struct wm8753_setup_data { | ||
82 | unsigned short i2c_address; | ||
83 | }; | ||
84 | |||
85 | #define WM8753_PLL1 0 | ||
86 | #define WM8753_PLL2 1 | ||
87 | |||
88 | /* clock inputs */ | ||
89 | #define WM8753_MCLK 0 | ||
90 | #define WM8753_PCMCLK 1 | ||
91 | |||
92 | /* clock divider id's */ | ||
93 | #define WM8753_PCMDIV 0 | ||
94 | #define WM8753_BCLKDIV 1 | ||
95 | #define WM8753_VXCLKDIV 2 | ||
96 | |||
97 | /* PCM clock dividers */ | ||
98 | #define WM8753_PCM_DIV_1 (0 << 6) | ||
99 | #define WM8753_PCM_DIV_3 (2 << 6) | ||
100 | #define WM8753_PCM_DIV_5_5 (3 << 6) | ||
101 | #define WM8753_PCM_DIV_2 (4 << 6) | ||
102 | #define WM8753_PCM_DIV_4 (5 << 6) | ||
103 | #define WM8753_PCM_DIV_6 (6 << 6) | ||
104 | #define WM8753_PCM_DIV_8 (7 << 6) | ||
105 | |||
106 | /* BCLK clock dividers */ | ||
107 | #define WM8753_BCLK_DIV_1 (0 << 3) | ||
108 | #define WM8753_BCLK_DIV_2 (1 << 3) | ||
109 | #define WM8753_BCLK_DIV_4 (2 << 3) | ||
110 | #define WM8753_BCLK_DIV_8 (3 << 3) | ||
111 | #define WM8753_BCLK_DIV_16 (4 << 3) | ||
112 | |||
113 | /* VXCLK clock dividers */ | ||
114 | #define WM8753_VXCLK_DIV_1 (0 << 6) | ||
115 | #define WM8753_VXCLK_DIV_2 (1 << 6) | ||
116 | #define WM8753_VXCLK_DIV_4 (2 << 6) | ||
117 | #define WM8753_VXCLK_DIV_8 (3 << 6) | ||
118 | #define WM8753_VXCLK_DIV_16 (4 << 6) | ||
119 | |||
120 | #define WM8753_DAI_HIFI 0 | ||
121 | #define WM8753_DAI_VOICE 1 | ||
122 | |||
123 | extern struct snd_soc_codec_dai wm8753_dai[2]; | ||
124 | extern struct snd_soc_codec_device soc_codec_dev_wm8753; | ||
125 | |||
126 | #endif | ||