2 * wm8900.c -- WM8900 ALSA Soc Audio driver
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
16 * - FLL source configuration, currently only MCLK is supported.
19 #include <linux/module.h>
20 #include <linux/moduleparam.h>
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/delay.h>
25 #include <linux/i2c.h>
26 #include <linux/platform_device.h>
27 #include <sound/core.h>
28 #include <sound/pcm.h>
29 #include <sound/pcm_params.h>
30 #include <sound/soc.h>
31 #include <sound/soc-dapm.h>
32 #include <sound/initval.h>
33 #include <sound/tlv.h>
39 #define WM8900_DBG(x...) printk(KERN_INFO x)
41 #define WM8900_DBG(x...)
44 /* WM8900 register space */
45 #define WM8900_REG_RESET 0x0
46 #define WM8900_REG_ID 0x0
47 #define WM8900_REG_POWER1 0x1
48 #define WM8900_REG_POWER2 0x2
49 #define WM8900_REG_POWER3 0x3
50 #define WM8900_REG_AUDIO1 0x4
51 #define WM8900_REG_AUDIO2 0x5
52 #define WM8900_REG_CLOCKING1 0x6
53 #define WM8900_REG_CLOCKING2 0x7
54 #define WM8900_REG_AUDIO3 0x8
55 #define WM8900_REG_AUDIO4 0x9
56 #define WM8900_REG_DACCTRL 0xa
57 #define WM8900_REG_LDAC_DV 0xb
58 #define WM8900_REG_RDAC_DV 0xc
59 #define WM8900_REG_SIDETONE 0xd
60 #define WM8900_REG_ADCCTRL 0xe
61 #define WM8900_REG_LADC_DV 0xf
62 #define WM8900_REG_RADC_DV 0x10
63 #define WM8900_REG_GPIO 0x12
64 #define WM8900_REG_INCTL 0x15
65 #define WM8900_REG_LINVOL 0x16
66 #define WM8900_REG_RINVOL 0x17
67 #define WM8900_REG_INBOOSTMIX1 0x18
68 #define WM8900_REG_INBOOSTMIX2 0x19
69 #define WM8900_REG_ADCPATH 0x1a
70 #define WM8900_REG_AUXBOOST 0x1b
71 #define WM8900_REG_ADDCTL 0x1e
72 #define WM8900_REG_FLLCTL1 0x24
73 #define WM8900_REG_FLLCTL2 0x25
74 #define WM8900_REG_FLLCTL3 0x26
75 #define WM8900_REG_FLLCTL4 0x27
76 #define WM8900_REG_FLLCTL5 0x28
77 #define WM8900_REG_FLLCTL6 0x29
78 #define WM8900_REG_LOUTMIXCTL1 0x2c
79 #define WM8900_REG_ROUTMIXCTL1 0x2d
80 #define WM8900_REG_BYPASS1 0x2e
81 #define WM8900_REG_BYPASS2 0x2f
82 #define WM8900_REG_AUXOUT_CTL 0x30
83 #define WM8900_REG_LOUT1CTL 0x33
84 #define WM8900_REG_ROUT1CTL 0x34
85 #define WM8900_REG_LOUT2CTL 0x35
86 #define WM8900_REG_ROUT2CTL 0x36
87 #define WM8900_REG_HPCTL1 0x3a
88 #define WM8900_REG_OUTBIASCTL 0x73
90 #define WM8900_MAXREG 0x80
92 #define WM8900_REG_ADDCTL_OUT1_DIS 0x80
93 #define WM8900_REG_ADDCTL_OUT2_DIS 0x40
94 #define WM8900_REG_ADDCTL_VMID_DIS 0x20
95 #define WM8900_REG_ADDCTL_BIAS_SRC 0x10
96 #define WM8900_REG_ADDCTL_VMID_SOFTST 0x04
97 #define WM8900_REG_ADDCTL_TEMP_SD 0x02
99 #define WM8900_REG_GPIO_TEMP_ENA 0x2
101 #define WM8900_REG_POWER1_STARTUP_BIAS_ENA 0x0100
102 #define WM8900_REG_POWER1_BIAS_ENA 0x0008
103 #define WM8900_REG_POWER1_VMID_BUF_ENA 0x0004
104 #define WM8900_REG_POWER1_FLL_ENA 0x0040
106 #define WM8900_REG_POWER2_SYSCLK_ENA 0x8000
107 #define WM8900_REG_POWER2_ADCL_ENA 0x0002
108 #define WM8900_REG_POWER2_ADCR_ENA 0x0001
110 #define WM8900_REG_POWER3_DACL_ENA 0x0002
111 #define WM8900_REG_POWER3_DACR_ENA 0x0001
113 #define WM8900_REG_AUDIO1_AIF_FMT_MASK 0x0018
114 #define WM8900_REG_AUDIO1_LRCLK_INV 0x0080
115 #define WM8900_REG_AUDIO1_BCLK_INV 0x0100
117 #define WM8900_REG_CLOCKING1_BCLK_DIR 0x1
118 #define WM8900_REG_CLOCKING1_MCLK_SRC 0x100
119 #define WM8900_REG_CLOCKING1_BCLK_MASK (~0x01e)
120 #define WM8900_REG_CLOCKING1_OPCLK_MASK (~0x7000)
122 #define WM8900_REG_CLOCKING2_ADC_CLKDIV 0x1c
123 #define WM8900_REG_CLOCKING2_DAC_CLKDIV 0xe0
125 #define WM8900_REG_DACCTRL_MUTE 0x004
126 #define WM8900_REG_DACCTRL_DAC_SB_FILT 0x100
127 #define WM8900_REG_DACCTRL_AIF_LRCLKRATE 0x400
129 #define WM8900_REG_AUDIO3_ADCLRC_DIR 0x0800
131 #define WM8900_REG_AUDIO4_DACLRC_DIR 0x0800
133 #define WM8900_REG_FLLCTL1_OSC_ENA 0x100
135 #define WM8900_REG_FLLCTL6_FLL_SLOW_LOCK_REF 0x100
137 #define WM8900_REG_HPCTL1_HP_IPSTAGE_ENA 0x80
138 #define WM8900_REG_HPCTL1_HP_OPSTAGE_ENA 0x40
139 #define WM8900_REG_HPCTL1_HP_CLAMP_IP 0x20
140 #define WM8900_REG_HPCTL1_HP_CLAMP_OP 0x10
141 #define WM8900_REG_HPCTL1_HP_SHORT 0x08
142 #define WM8900_REG_HPCTL1_HP_SHORT2 0x04
144 #define WM8900_LRC_MASK 0xfc00
146 struct snd_soc_codec_device soc_codec_dev_wm8900;
149 struct snd_soc_codec codec;
151 u16 reg_cache[WM8900_MAXREG];
153 u32 fll_in; /* FLL input frequency */
154 u32 fll_out; /* FLL output frequency */
158 * wm8900 register cache. We can't read the entire register space and we
159 * have slow control buses so we cache the registers.
161 static const u16 wm8900_reg_defaults[WM8900_MAXREG] = {
190 /* Remaining registers all zero */
193 static int wm8900_volatile_register(unsigned int reg)
197 case WM8900_REG_POWER1:
204 static void wm8900_reset(struct snd_soc_codec *codec)
206 WM8900_DBG("Enter:%s, %d, codec=0x%8X \n", __FUNCTION__, __LINE__,codec);
207 snd_soc_write(codec, WM8900_REG_RESET, 0);
209 memcpy(codec->reg_cache, wm8900_reg_defaults,
210 sizeof(codec->reg_cache));
213 static int wm8900_hp_event(struct snd_soc_dapm_widget *w,
214 struct snd_kcontrol *kcontrol, int event)
216 struct snd_soc_codec *codec = w->codec;
217 u16 hpctl1 = snd_soc_read(codec, WM8900_REG_HPCTL1);
219 WM8900_DBG("Enter:%s, %d \n", __FUNCTION__, __LINE__);
222 case SND_SOC_DAPM_PRE_PMU:
223 /* Clamp headphone outputs */
224 hpctl1 = WM8900_REG_HPCTL1_HP_CLAMP_IP |
225 WM8900_REG_HPCTL1_HP_CLAMP_OP;
226 snd_soc_write(codec, WM8900_REG_HPCTL1, hpctl1);
227 WM8900_DBG("Enter:%s, %d, HPCTL=0x%04X \n", __FUNCTION__, __LINE__, hpctl1);
230 case SND_SOC_DAPM_POST_PMU:
231 /* Enable the input stage */
232 hpctl1 &= ~WM8900_REG_HPCTL1_HP_CLAMP_IP;
233 hpctl1 |= WM8900_REG_HPCTL1_HP_SHORT |
234 WM8900_REG_HPCTL1_HP_SHORT2 |
235 WM8900_REG_HPCTL1_HP_IPSTAGE_ENA;
236 snd_soc_write(codec, WM8900_REG_HPCTL1, hpctl1);
240 /* Enable the output stage */
241 hpctl1 &= ~WM8900_REG_HPCTL1_HP_CLAMP_OP;
242 hpctl1 |= WM8900_REG_HPCTL1_HP_OPSTAGE_ENA;
243 snd_soc_write(codec, WM8900_REG_HPCTL1, hpctl1);
245 /* Remove the shorts */
246 hpctl1 &= ~WM8900_REG_HPCTL1_HP_SHORT2;
247 snd_soc_write(codec, WM8900_REG_HPCTL1, hpctl1);
248 hpctl1 &= ~WM8900_REG_HPCTL1_HP_SHORT;
249 snd_soc_write(codec, WM8900_REG_HPCTL1, hpctl1);
250 WM8900_DBG("Enter:%s, %d, HPCTL=0x%04X \n", __FUNCTION__, __LINE__, hpctl1);
253 case SND_SOC_DAPM_PRE_PMD:
254 /* Short the output */
255 hpctl1 |= WM8900_REG_HPCTL1_HP_SHORT;
256 snd_soc_write(codec, WM8900_REG_HPCTL1, hpctl1);
258 /* Disable the output stage */
259 hpctl1 &= ~WM8900_REG_HPCTL1_HP_OPSTAGE_ENA;
260 snd_soc_write(codec, WM8900_REG_HPCTL1, hpctl1);
262 /* Clamp the outputs and power down input */
263 hpctl1 |= WM8900_REG_HPCTL1_HP_CLAMP_IP |
264 WM8900_REG_HPCTL1_HP_CLAMP_OP;
265 hpctl1 &= ~WM8900_REG_HPCTL1_HP_IPSTAGE_ENA;
266 snd_soc_write(codec, WM8900_REG_HPCTL1, hpctl1);
267 WM8900_DBG("Enter:%s, %d, HPCTL=0x%04X \n", __FUNCTION__, __LINE__, hpctl1);
270 case SND_SOC_DAPM_POST_PMD:
271 /* Disable everything */
272 snd_soc_write(codec, WM8900_REG_HPCTL1, 0);
273 WM8900_DBG("Enter:%s, %d, HPCTL=0x%04X \n", __FUNCTION__, __LINE__, hpctl1);
283 static const DECLARE_TLV_DB_SCALE(out_pga_tlv, -5700, 100, 0);
285 static const DECLARE_TLV_DB_SCALE(out_mix_tlv, -1500, 300, 0);
287 static const DECLARE_TLV_DB_SCALE(in_boost_tlv, -1200, 600, 0);
289 static const DECLARE_TLV_DB_SCALE(in_pga_tlv, -1200, 100, 0);
291 static const DECLARE_TLV_DB_SCALE(dac_boost_tlv, 0, 600, 0);
293 static const DECLARE_TLV_DB_SCALE(dac_tlv, -7200, 75, 1);
295 static const DECLARE_TLV_DB_SCALE(adc_svol_tlv, -3600, 300, 0);
297 static const DECLARE_TLV_DB_SCALE(adc_tlv, -7200, 75, 1);
299 static const char *mic_bias_level_txt[] = { "0.9*AVDD", "0.65*AVDD" };
301 static const struct soc_enum mic_bias_level =
302 SOC_ENUM_SINGLE(WM8900_REG_INCTL, 8, 2, mic_bias_level_txt);
304 static const char *dac_mute_rate_txt[] = { "Fast", "Slow" };
306 static const struct soc_enum dac_mute_rate =
307 SOC_ENUM_SINGLE(WM8900_REG_DACCTRL, 7, 2, dac_mute_rate_txt);
309 static const char *dac_deemphasis_txt[] = {
310 "Disabled", "32kHz", "44.1kHz", "48kHz"
313 static const struct soc_enum dac_deemphasis =
314 SOC_ENUM_SINGLE(WM8900_REG_DACCTRL, 4, 4, dac_deemphasis_txt);
316 static const char *adc_hpf_cut_txt[] = {
317 "Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"
320 static const struct soc_enum adc_hpf_cut =
321 SOC_ENUM_SINGLE(WM8900_REG_ADCCTRL, 5, 4, adc_hpf_cut_txt);
323 static const char *lr_txt[] = {
327 static const struct soc_enum aifl_src =
328 SOC_ENUM_SINGLE(WM8900_REG_AUDIO1, 15, 2, lr_txt);
330 static const struct soc_enum aifr_src =
331 SOC_ENUM_SINGLE(WM8900_REG_AUDIO1, 14, 2, lr_txt);
333 static const struct soc_enum dacl_src =
334 SOC_ENUM_SINGLE(WM8900_REG_AUDIO2, 15, 2, lr_txt);
336 static const struct soc_enum dacr_src =
337 SOC_ENUM_SINGLE(WM8900_REG_AUDIO2, 14, 2, lr_txt);
339 static const char *sidetone_txt[] = {
340 "Disabled", "Left ADC", "Right ADC"
343 static const struct soc_enum dacl_sidetone =
344 SOC_ENUM_SINGLE(WM8900_REG_SIDETONE, 2, 3, sidetone_txt);
346 static const struct soc_enum dacr_sidetone =
347 SOC_ENUM_SINGLE(WM8900_REG_SIDETONE, 0, 3, sidetone_txt);
349 static const struct snd_kcontrol_new wm8900_snd_controls[] = {
350 SOC_ENUM("Mic Bias Level", mic_bias_level),
352 SOC_SINGLE_TLV("Left Input PGA Volume", WM8900_REG_LINVOL, 0, 31, 0,
354 SOC_SINGLE("Left Input PGA Switch", WM8900_REG_LINVOL, 6, 1, 1),
355 SOC_SINGLE("Left Input PGA ZC Switch", WM8900_REG_LINVOL, 7, 1, 0),
357 SOC_SINGLE_TLV("Right Input PGA Volume", WM8900_REG_RINVOL, 0, 31, 0,
359 SOC_SINGLE("Right Input PGA Switch", WM8900_REG_RINVOL, 6, 1, 1),
360 SOC_SINGLE("Right Input PGA ZC Switch", WM8900_REG_RINVOL, 7, 1, 0),
362 SOC_SINGLE("DAC Soft Mute Switch", WM8900_REG_DACCTRL, 6, 1, 1),
363 SOC_ENUM("DAC Mute Rate", dac_mute_rate),
364 SOC_SINGLE("DAC Mono Switch", WM8900_REG_DACCTRL, 9, 1, 0),
365 SOC_ENUM("DAC Deemphasis", dac_deemphasis),
366 SOC_SINGLE("DAC Sigma-Delta Modulator Clock Switch", WM8900_REG_DACCTRL,
369 SOC_SINGLE("ADC HPF Switch", WM8900_REG_ADCCTRL, 8, 1, 0),
370 SOC_ENUM("ADC HPF Cut-Off", adc_hpf_cut),
371 SOC_DOUBLE("ADC Invert Switch", WM8900_REG_ADCCTRL, 1, 0, 1, 0),
372 SOC_SINGLE_TLV("Left ADC Sidetone Volume", WM8900_REG_SIDETONE, 9, 12, 0,
374 SOC_SINGLE_TLV("Right ADC Sidetone Volume", WM8900_REG_SIDETONE, 5, 12, 0,
376 SOC_ENUM("Left Digital Audio Source", aifl_src),
377 SOC_ENUM("Right Digital Audio Source", aifr_src),
379 SOC_SINGLE_TLV("DAC Input Boost Volume", WM8900_REG_AUDIO2, 10, 4, 0,
381 SOC_ENUM("Left DAC Source", dacl_src),
382 SOC_ENUM("Right DAC Source", dacr_src),
383 SOC_ENUM("Left DAC Sidetone", dacl_sidetone),
384 SOC_ENUM("Right DAC Sidetone", dacr_sidetone),
385 SOC_DOUBLE("DAC Invert Switch", WM8900_REG_DACCTRL, 1, 0, 1, 0),
387 SOC_DOUBLE_R_TLV("Digital Playback Volume",
388 WM8900_REG_LDAC_DV, WM8900_REG_RDAC_DV,
390 SOC_DOUBLE_R_TLV("Digital Capture Volume",
391 WM8900_REG_LADC_DV, WM8900_REG_RADC_DV, 1, 119, 0, adc_tlv),
393 SOC_SINGLE_TLV("LINPUT3 Bypass Volume", WM8900_REG_LOUTMIXCTL1, 4, 7, 0,
395 SOC_SINGLE_TLV("RINPUT3 Bypass Volume", WM8900_REG_ROUTMIXCTL1, 4, 7, 0,
397 SOC_SINGLE_TLV("Left AUX Bypass Volume", WM8900_REG_AUXOUT_CTL, 4, 7, 0,
399 SOC_SINGLE_TLV("Right AUX Bypass Volume", WM8900_REG_AUXOUT_CTL, 0, 7, 0,
402 SOC_SINGLE_TLV("LeftIn to RightOut Mixer Volume", WM8900_REG_BYPASS1, 0, 7, 0,
404 SOC_SINGLE_TLV("LeftIn to LeftOut Mixer Volume", WM8900_REG_BYPASS1, 4, 7, 0,
406 SOC_SINGLE_TLV("RightIn to LeftOut Mixer Volume", WM8900_REG_BYPASS2, 0, 7, 0,
408 SOC_SINGLE_TLV("RightIn to RightOut Mixer Volume", WM8900_REG_BYPASS2, 4, 7, 0,
411 SOC_SINGLE_TLV("IN2L Boost Volume", WM8900_REG_INBOOSTMIX1, 0, 3, 0,
413 SOC_SINGLE_TLV("IN3L Boost Volume", WM8900_REG_INBOOSTMIX1, 4, 3, 0,
415 SOC_SINGLE_TLV("IN2R Boost Volume", WM8900_REG_INBOOSTMIX2, 0, 3, 0,
417 SOC_SINGLE_TLV("IN3R Boost Volume", WM8900_REG_INBOOSTMIX2, 4, 3, 0,
419 SOC_SINGLE_TLV("Left AUX Boost Volume", WM8900_REG_AUXBOOST, 4, 3, 0,
421 SOC_SINGLE_TLV("Right AUX Boost Volume", WM8900_REG_AUXBOOST, 0, 3, 0,
424 SOC_DOUBLE_R_TLV("LINEOUT1 Volume", WM8900_REG_LOUT1CTL, WM8900_REG_ROUT1CTL,
425 0, 63, 0, out_pga_tlv),
426 SOC_DOUBLE_R("LINEOUT1 Switch", WM8900_REG_LOUT1CTL, WM8900_REG_ROUT1CTL,
428 SOC_DOUBLE_R("LINEOUT1 ZC Switch", WM8900_REG_LOUT1CTL, WM8900_REG_ROUT1CTL,
431 SOC_DOUBLE_R_TLV("LINEOUT2 Volume",
432 WM8900_REG_LOUT2CTL, WM8900_REG_ROUT2CTL,
433 0, 63, 0, out_pga_tlv),
434 SOC_DOUBLE_R("LINEOUT2 Switch",
435 WM8900_REG_LOUT2CTL, WM8900_REG_ROUT2CTL, 6, 1, 1),
436 SOC_DOUBLE_R("LINEOUT2 ZC Switch",
437 WM8900_REG_LOUT2CTL, WM8900_REG_ROUT2CTL, 7, 1, 0),
438 SOC_SINGLE("LINEOUT2 LP -12dB", WM8900_REG_LOUTMIXCTL1,
443 static const struct snd_kcontrol_new wm8900_dapm_loutput2_control[] = {
444 SOC_DAPM_SINGLE("LINEOUT2L Switch", WM8900_REG_POWER3, 6, 1, 0),};
446 static const struct snd_kcontrol_new wm8900_dapm_routput2_control[] = {
447 SOC_DAPM_SINGLE("LINEOUT2R Switch", WM8900_REG_POWER3, 5, 1, 0),};
449 static const struct snd_kcontrol_new wm8900_loutmix_controls[] = {
450 SOC_DAPM_SINGLE("LINPUT3 Bypass Switch", WM8900_REG_LOUTMIXCTL1, 7, 1, 0),
451 SOC_DAPM_SINGLE("AUX Bypass Switch", WM8900_REG_AUXOUT_CTL, 7, 1, 0),
452 SOC_DAPM_SINGLE("Left Input Mixer Switch", WM8900_REG_BYPASS1, 7, 1, 0),
453 SOC_DAPM_SINGLE("Right Input Mixer Switch", WM8900_REG_BYPASS2, 3, 1, 0),
454 SOC_DAPM_SINGLE("DACL Switch", WM8900_REG_LOUTMIXCTL1, 8, 1, 0),
457 static const struct snd_kcontrol_new wm8900_routmix_controls[] = {
458 SOC_DAPM_SINGLE("RINPUT3 Bypass Switch", WM8900_REG_ROUTMIXCTL1, 7, 1, 0),
459 SOC_DAPM_SINGLE("AUX Bypass Switch", WM8900_REG_AUXOUT_CTL, 3, 1, 0),
460 SOC_DAPM_SINGLE("Left Input Mixer Switch", WM8900_REG_BYPASS1, 3, 1, 0),
461 SOC_DAPM_SINGLE("Right Input Mixer Switch", WM8900_REG_BYPASS2, 7, 1, 0),
462 SOC_DAPM_SINGLE("DACR Switch", WM8900_REG_ROUTMIXCTL1, 8, 1, 0),
465 static const struct snd_kcontrol_new wm8900_linmix_controls[] = {
466 SOC_DAPM_SINGLE("LINPUT2 Switch", WM8900_REG_INBOOSTMIX1, 2, 1, 1),
467 SOC_DAPM_SINGLE("LINPUT3 Switch", WM8900_REG_INBOOSTMIX1, 6, 1, 1),
468 SOC_DAPM_SINGLE("AUX Switch", WM8900_REG_AUXBOOST, 6, 1, 1),
469 SOC_DAPM_SINGLE("Input PGA Switch", WM8900_REG_ADCPATH, 6, 1, 0),
472 static const struct snd_kcontrol_new wm8900_rinmix_controls[] = {
473 SOC_DAPM_SINGLE("RINPUT2 Switch", WM8900_REG_INBOOSTMIX2, 2, 1, 1),
474 SOC_DAPM_SINGLE("RINPUT3 Switch", WM8900_REG_INBOOSTMIX2, 6, 1, 1),
475 SOC_DAPM_SINGLE("AUX Switch", WM8900_REG_AUXBOOST, 2, 1, 1),
476 SOC_DAPM_SINGLE("Input PGA Switch", WM8900_REG_ADCPATH, 2, 1, 0),
479 static const struct snd_kcontrol_new wm8900_linpga_controls[] = {
480 SOC_SINGLE("MIC LINPUT1 Switch", WM8900_REG_INCTL, 6, 1, 0),
481 SOC_SINGLE("MIC LINPUT2 Switch", WM8900_REG_INCTL, 5, 1, 0),
482 SOC_SINGLE("MIC LINPUT3 Switch", WM8900_REG_INCTL, 4, 1, 0),
485 static const struct snd_kcontrol_new wm8900_rinpga_controls[] = {
486 SOC_SINGLE("MIC RINPUT1 Switch", WM8900_REG_INCTL, 2, 1, 0),
487 SOC_SINGLE("MIC RINPUT2 Switch", WM8900_REG_INCTL, 1, 1, 0),
488 SOC_SINGLE("MIC RINPUT3 Switch", WM8900_REG_INCTL, 0, 1, 0),
491 static const struct snd_kcontrol_new wm8900_inmix_controls[] = {
492 SOC_SINGLE("LINPUT PGA Switch", WM8900_REG_ADCPATH, 6, 1, 0),
493 SOC_SINGLE("RINPUT PGA Switch", WM8900_REG_ADCPATH, 2, 1, 0),
496 static const char *wm9700_lp_mux[] = { "Disabled", "Enabled" };
498 static const struct soc_enum wm8900_lineout2_lp_mux =
499 SOC_ENUM_SINGLE(WM8900_REG_LOUTMIXCTL1, 1, 2, wm9700_lp_mux);
501 static const struct snd_kcontrol_new wm8900_lineout2_lp =
502 SOC_DAPM_ENUM("Route", wm8900_lineout2_lp_mux);
504 static const struct snd_soc_dapm_widget wm8900_dapm_widgets[] = {
506 /* Externally visible pins */
507 SND_SOC_DAPM_OUTPUT("LINEOUT1L"),
508 SND_SOC_DAPM_OUTPUT("LINEOUT1R"),
509 SND_SOC_DAPM_OUTPUT("LINEOUT2L"),
510 SND_SOC_DAPM_OUTPUT("LINEOUT2R"),
511 SND_SOC_DAPM_OUTPUT("HP_L"),
512 SND_SOC_DAPM_OUTPUT("HP_R"),
514 SND_SOC_DAPM_INPUT("RINPUT1"),
515 SND_SOC_DAPM_INPUT("LINPUT1"),
516 SND_SOC_DAPM_INPUT("RINPUT2"),
517 SND_SOC_DAPM_INPUT("LINPUT2"),
518 SND_SOC_DAPM_INPUT("RINPUT3"),
519 SND_SOC_DAPM_INPUT("LINPUT3"),
520 SND_SOC_DAPM_INPUT("AUX"),
522 SND_SOC_DAPM_VMID("VMID"),
525 SND_SOC_DAPM_MIXER("Left Input PGA", WM8900_REG_POWER2, 3, 0,
526 wm8900_linpga_controls,
527 ARRAY_SIZE(wm8900_linpga_controls)),
528 SND_SOC_DAPM_MIXER("Right Input PGA", WM8900_REG_POWER2, 2, 0,
529 wm8900_rinpga_controls,
530 ARRAY_SIZE(wm8900_rinpga_controls)),
532 SND_SOC_DAPM_MIXER("Left Input Mixer", WM8900_REG_POWER2, 5, 0,
533 wm8900_linmix_controls,
534 ARRAY_SIZE(wm8900_linmix_controls)),
535 SND_SOC_DAPM_MIXER("Right Input Mixer", WM8900_REG_POWER2, 4, 0,
536 wm8900_rinmix_controls,
537 ARRAY_SIZE(wm8900_rinmix_controls)),
539 SND_SOC_DAPM_MICBIAS("Mic Bias", WM8900_REG_POWER1, 4, 0),
541 SND_SOC_DAPM_ADC("ADCL", "Left HiFi Capture", WM8900_REG_POWER2, 1, 0),
542 SND_SOC_DAPM_ADC("ADCR", "Right HiFi Capture", WM8900_REG_POWER2, 0, 0),
545 SND_SOC_DAPM_DAC("DACL", "Left HiFi Playback", WM8900_REG_POWER3, 1, 0),
546 SND_SOC_DAPM_DAC("DACR", "Right HiFi Playback", WM8900_REG_POWER3, 0, 0),
548 SND_SOC_DAPM_PGA_E("Headphone Amplifier", WM8900_REG_POWER3, 7, 0, NULL, 0,
550 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
551 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
553 SND_SOC_DAPM_PGA("LINEOUT1L PGA", WM8900_REG_POWER2, 8, 0, NULL, 0),
554 SND_SOC_DAPM_PGA("LINEOUT1R PGA", WM8900_REG_POWER2, 7, 0, NULL, 0),
556 SND_SOC_DAPM_MUX("LINEOUT2 LP", SND_SOC_NOPM, 0, 0, &wm8900_lineout2_lp),
557 SND_SOC_DAPM_PGA("LINEOUT2L PGA", WM8900_REG_POWER3, 6, 0, NULL, 0),
558 SND_SOC_DAPM_PGA("LINEOUT2R PGA", WM8900_REG_POWER3, 5, 0, NULL, 0),
560 SND_SOC_DAPM_MIXER("Left Output Mixer", WM8900_REG_POWER3, 3, 0,
561 wm8900_loutmix_controls,
562 ARRAY_SIZE(wm8900_loutmix_controls)),
563 SND_SOC_DAPM_MIXER("Right Output Mixer", WM8900_REG_POWER3, 2, 0,
564 wm8900_routmix_controls,
565 ARRAY_SIZE(wm8900_routmix_controls)),
568 /* Target, Path, Source */
569 static const struct snd_soc_dapm_route audio_map[] = {
571 {"Left Input PGA", "LINPUT1 Switch", "LINPUT1"},
572 {"Left Input PGA", "LINPUT2 Switch", "LINPUT2"},
573 {"Left Input PGA", "LINPUT3 Switch", "LINPUT3"},
575 {"Right Input PGA", "RINPUT1 Switch", "RINPUT1"},
576 {"Right Input PGA", "RINPUT2 Switch", "RINPUT2"},
577 {"Right Input PGA", "RINPUT3 Switch", "RINPUT3"},
579 {"Left Input Mixer", "LINPUT2 Switch", "LINPUT2"},
580 {"Left Input Mixer", "LINPUT3 Switch", "LINPUT3"},
581 {"Left Input Mixer", "AUX Switch", "AUX"},
582 {"Left Input Mixer", "Input PGA Switch", "Left Input PGA"},
584 {"Right Input Mixer", "RINPUT2 Switch", "RINPUT2"},
585 {"Right Input Mixer", "RINPUT3 Switch", "RINPUT3"},
586 {"Right Input Mixer", "AUX Switch", "AUX"},
587 {"Right Input Mixer", "Input PGA Switch", "Right Input PGA"},
589 {"ADCL", NULL, "Left Input Mixer"},
590 {"ADCR", NULL, "Right Input Mixer"},
593 {"LINEOUT1L", NULL, "LINEOUT1L PGA"},
594 {"LINEOUT1L PGA", NULL, "Left Output Mixer"},
595 {"LINEOUT1R", NULL, "LINEOUT1R PGA"},
596 {"LINEOUT1R PGA", NULL, "Right Output Mixer"},
598 {"LINEOUT2L PGA", NULL, "Left Output Mixer"},
599 {"LINEOUT2 LP", "Disabled", "LINEOUT2L PGA"},
600 {"LINEOUT2 LP", "Enabled", "Left Output Mixer"},
601 {"LINEOUT2L", NULL, "LINEOUT2 LP"},
603 {"LINEOUT2R PGA", NULL, "Right Output Mixer"},
604 {"LINEOUT2 LP", "Disabled", "LINEOUT2R PGA"},
605 {"LINEOUT2 LP", "Enabled", "Right Output Mixer"},
606 {"LINEOUT2R", NULL, "LINEOUT2 LP"},
608 {"Left Output Mixer", "LINPUT3 Bypass Switch", "LINPUT3"},
609 {"Left Output Mixer", "AUX Bypass Switch", "AUX"},
610 {"Left Output Mixer", "Left Input Mixer Switch", "Left Input Mixer"},
611 {"Left Output Mixer", "Right Input Mixer Switch", "Right Input Mixer"},
612 {"Left Output Mixer", "DACL Switch", "DACL"},
614 {"Right Output Mixer", "RINPUT3 Bypass Switch", "RINPUT3"},
615 {"Right Output Mixer", "AUX Bypass Switch", "AUX"},
616 {"Right Output Mixer", "Left Input Mixer Switch", "Left Input Mixer"},
617 {"Right Output Mixer", "Right Input Mixer Switch", "Right Input Mixer"},
618 {"Right Output Mixer", "DACR Switch", "DACR"},
620 /* Note that the headphone output stage needs to be connected
621 * externally to LINEOUT2 via DC blocking capacitors. Other
622 * configurations are not supported.
624 * Note also that left and right headphone paths are treated as a
627 {"Headphone Amplifier", NULL, "LINEOUT2 LP"},
628 {"Headphone Amplifier", NULL, "LINEOUT2 LP"},
629 {"HP_L", NULL, "Headphone Amplifier"},
630 {"HP_R", NULL, "Headphone Amplifier"},
633 static int wm8900_add_widgets(struct snd_soc_codec *codec)
635 WM8900_DBG("Enter:%s, %d \n", __FUNCTION__, __LINE__);
637 snd_soc_dapm_new_controls(codec, wm8900_dapm_widgets,
638 ARRAY_SIZE(wm8900_dapm_widgets));
639 WM8900_DBG("Enter:%s, %d \n", __FUNCTION__, __LINE__);
640 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
641 WM8900_DBG("Enter:%s, %d \n", __FUNCTION__, __LINE__);
642 snd_soc_dapm_new_widgets(codec);
647 static int wm8900_hw_params(struct snd_pcm_substream *substream,
648 struct snd_pcm_hw_params *params,
649 struct snd_soc_dai *dai)
651 struct snd_soc_pcm_runtime *rtd = substream->private_data;
652 struct snd_soc_device *socdev = rtd->socdev;
653 struct snd_soc_codec *codec = socdev->card->codec;
656 WM8900_DBG("Enter:%s, %d \n", __FUNCTION__, __LINE__);
658 reg = snd_soc_read(codec, WM8900_REG_AUDIO1) & ~0x60;
660 switch (params_format(params)) {
661 case SNDRV_PCM_FORMAT_S16_LE:
663 case SNDRV_PCM_FORMAT_S20_3LE:
666 case SNDRV_PCM_FORMAT_S24_LE:
669 case SNDRV_PCM_FORMAT_S32_LE:
676 snd_soc_write(codec, WM8900_REG_AUDIO1, reg);
678 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
679 reg = snd_soc_read(codec, WM8900_REG_DACCTRL);
681 if (params_rate(params) <= 24000)
682 reg |= WM8900_REG_DACCTRL_DAC_SB_FILT;
684 reg &= ~WM8900_REG_DACCTRL_DAC_SB_FILT;
686 snd_soc_write(codec, WM8900_REG_DACCTRL, reg);
688 snd_soc_write(codec, WM8900_REG_POWER3, 0xEF);
690 snd_soc_write(codec, WM8900_REG_LOUTMIXCTL1, 0x150);
691 snd_soc_write(codec, WM8900_REG_ROUTMIXCTL1, 0x150);
692 snd_soc_write(codec, WM8900_REG_LOUT2CTL, 0x139);
693 snd_soc_write(codec, WM8900_REG_ROUT2CTL, 0x139);
694 snd_soc_write(codec, WM8900_REG_HPCTL1, 0xC0);
696 snd_soc_write(codec, WM8900_REG_POWER1, 0x211D);
697 snd_soc_write(codec, WM8900_REG_POWER2, 0xC03F);
699 //User for asound.conf File
700 snd_soc_write(codec, WM8900_REG_LADC_DV, 0x00C1);
701 snd_soc_write(codec, WM8900_REG_RADC_DV, 0x01C0);
703 snd_soc_write(codec, WM8900_REG_INCTL, 0x0040);
705 snd_soc_write(codec, WM8900_REG_LINVOL, 0x0115);
706 snd_soc_write(codec, WM8900_REG_RINVOL, 0x0115);
707 snd_soc_write(codec, WM8900_REG_INBOOSTMIX1, 0x0042);
708 snd_soc_write(codec, WM8900_REG_INBOOSTMIX2, 0x0042);
709 snd_soc_write(codec, WM8900_REG_ADCPATH, 0x0055);
714 snd_soc_write(codec, 0x01, 0x211D);
715 snd_soc_write(codec, 0x02, 0xC03C);
716 snd_soc_write(codec, 0x03, 0x00EC);
717 snd_soc_write(codec, 0x16, 0x0115);
718 snd_soc_write(codec, 0x17, 0x0115);
719 snd_soc_write(codec, 0x1A, 0x0077);
721 snd_soc_write(codec, 0x2E, 0x00DD);
722 snd_soc_write(codec, 0x35, 0x011F);
723 snd_soc_write(codec, 0x36, 0x011F);
724 snd_soc_write(codec, 0x3A, 0x00C0);
727 WM8900_DBG("<<<<<<<<<<<<<<<<<<<<Exit:%s, %d \n", __FUNCTION__, __LINE__);
735 u16 fll_slow_lock_ref;
740 /* The size in bits of the FLL divide multiplied by 10
741 * to allow rounding later */
742 #define FIXED_FLL_SIZE ((1 << 16) * 10)
744 static int fll_factors(struct _fll_div *fll_div, unsigned int Fref,
748 unsigned int K, Ndiv, Nmod, target;
753 WM8900_DBG("Enter:%s, %d \n", __FUNCTION__, __LINE__);
755 /* The FLL must run at 90-100MHz which is then scaled down to
756 * the output value by FLLCLK_DIV. */
759 while (target < 90000000) {
764 if (target > 100000000)
765 printk(KERN_WARNING "wm8900: FLL rate %u out of range, Fref=%u"
766 " Fout=%u\n", target, Fref, Fout);
768 printk(KERN_ERR "wm8900: Invalid FLL division rate %u, "
769 "Fref=%u, Fout=%u, target=%u\n",
770 div, Fref, Fout, target);
774 fll_div->fllclk_div = div >> 2;
777 fll_div->fll_slow_lock_ref = 1;
779 fll_div->fll_slow_lock_ref = 0;
781 Ndiv = target / Fref;
784 fll_div->fll_ratio = 8;
786 fll_div->fll_ratio = 1;
788 fll_div->n = Ndiv / fll_div->fll_ratio;
789 Nmod = (target / fll_div->fll_ratio) % Fref;
791 /* Calculate fractional part - scale up so we can round. */
792 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
796 K = Kpart & 0xFFFFFFFF;
801 /* Move down to proper range now rounding is done */
804 BUG_ON(target != Fout * (fll_div->fllclk_div << 2));
805 BUG_ON(!K && target != Fref * fll_div->fll_ratio * fll_div->n);
810 static int wm8900_set_fll(struct snd_soc_codec *codec,
811 int fll_id, unsigned int freq_in, unsigned int freq_out)
813 struct wm8900_priv *wm8900 = codec->private_data;
814 struct _fll_div fll_div;
817 WM8900_DBG("Enter:%s, %d \n", __FUNCTION__, __LINE__);
819 if (wm8900->fll_in == freq_in && wm8900->fll_out == freq_out)
822 /* The digital side should be disabled during any change. */
823 reg = snd_soc_read(codec, WM8900_REG_POWER1);
824 snd_soc_write(codec, WM8900_REG_POWER1,
825 reg & (~WM8900_REG_POWER1_FLL_ENA));
827 /* Disable the FLL? */
828 if (!freq_in || !freq_out) {
829 reg = snd_soc_read(codec, WM8900_REG_CLOCKING1);
830 snd_soc_write(codec, WM8900_REG_CLOCKING1,
831 reg & (~WM8900_REG_CLOCKING1_MCLK_SRC));
833 reg = snd_soc_read(codec, WM8900_REG_FLLCTL1);
834 snd_soc_write(codec, WM8900_REG_FLLCTL1,
835 reg & (~WM8900_REG_FLLCTL1_OSC_ENA));
837 wm8900->fll_in = freq_in;
838 wm8900->fll_out = freq_out;
843 if (fll_factors(&fll_div, freq_in, freq_out) != 0)
846 wm8900->fll_in = freq_in;
847 wm8900->fll_out = freq_out;
849 /* The osclilator *MUST* be enabled before we enable the
850 * digital circuit. */
851 snd_soc_write(codec, WM8900_REG_FLLCTL1,
852 fll_div.fll_ratio | WM8900_REG_FLLCTL1_OSC_ENA);
854 snd_soc_write(codec, WM8900_REG_FLLCTL4, fll_div.n >> 5);
855 snd_soc_write(codec, WM8900_REG_FLLCTL5,
856 (fll_div.fllclk_div << 6) | (fll_div.n & 0x1f));
859 snd_soc_write(codec, WM8900_REG_FLLCTL2,
860 (fll_div.k >> 8) | 0x100);
861 snd_soc_write(codec, WM8900_REG_FLLCTL3, fll_div.k & 0xff);
863 snd_soc_write(codec, WM8900_REG_FLLCTL2, 0);
865 if (fll_div.fll_slow_lock_ref)
866 snd_soc_write(codec, WM8900_REG_FLLCTL6,
867 WM8900_REG_FLLCTL6_FLL_SLOW_LOCK_REF);
869 snd_soc_write(codec, WM8900_REG_FLLCTL6, 0);
871 reg = snd_soc_read(codec, WM8900_REG_POWER1);
872 snd_soc_write(codec, WM8900_REG_POWER1,
873 reg | WM8900_REG_POWER1_FLL_ENA);
876 reg = snd_soc_read(codec, WM8900_REG_CLOCKING1);
877 snd_soc_write(codec, WM8900_REG_CLOCKING1,
878 reg | WM8900_REG_CLOCKING1_MCLK_SRC);
883 static int wm8900_set_dai_pll(struct snd_soc_dai *codec_dai,
884 int pll_id, unsigned int freq_in, unsigned int freq_out)
886 WM8900_DBG("Enter:%s, %d \n", __FUNCTION__, __LINE__);
887 return wm8900_set_fll(codec_dai->codec, pll_id, freq_in, freq_out);
890 static int wm8900_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
893 struct snd_soc_codec *codec = codec_dai->codec;
895 WM8900_DBG("Enter:%s, %d, div_id=%d, div=%d \n", __FUNCTION__, __LINE__, div_id, div);
898 case WM8900_BCLK_DIV:
899 reg = snd_soc_read(codec, WM8900_REG_CLOCKING1);
900 snd_soc_write(codec, WM8900_REG_CLOCKING1,
901 div | (reg & WM8900_REG_CLOCKING1_BCLK_MASK));
903 case WM8900_OPCLK_DIV:
904 reg = snd_soc_read(codec, WM8900_REG_CLOCKING1);
905 snd_soc_write(codec, WM8900_REG_CLOCKING1,
906 div | (reg & WM8900_REG_CLOCKING1_OPCLK_MASK));
908 case WM8900_DAC_LRCLK:
909 reg = snd_soc_read(codec, WM8900_REG_AUDIO4);
910 snd_soc_write(codec, WM8900_REG_AUDIO4,
911 div | (reg & WM8900_LRC_MASK));
913 case WM8900_ADC_LRCLK:
914 reg = snd_soc_read(codec, WM8900_REG_AUDIO3);
915 snd_soc_write(codec, WM8900_REG_AUDIO3,
916 div | (reg & WM8900_LRC_MASK));
918 case WM8900_DAC_CLKDIV:
919 reg = snd_soc_read(codec, WM8900_REG_CLOCKING2);
920 snd_soc_write(codec, WM8900_REG_CLOCKING2,
921 div | (reg & WM8900_REG_CLOCKING2_DAC_CLKDIV));
923 case WM8900_ADC_CLKDIV:
924 reg = snd_soc_read(codec, WM8900_REG_CLOCKING2);
925 snd_soc_write(codec, WM8900_REG_CLOCKING2,
926 div | (reg & WM8900_REG_CLOCKING2_ADC_CLKDIV));
928 case WM8900_LRCLK_MODE:
929 reg = snd_soc_read(codec, WM8900_REG_DACCTRL);
930 snd_soc_write(codec, WM8900_REG_DACCTRL,
931 div | (reg & WM8900_REG_DACCTRL_AIF_LRCLKRATE));
941 static int wm8900_set_dai_fmt(struct snd_soc_dai *codec_dai,
944 struct snd_soc_codec *codec = codec_dai->codec;
945 unsigned int clocking1, aif1, aif3, aif4;
947 WM8900_DBG("Enter:%s, %d, fmt=0x%08X \n", __FUNCTION__, __LINE__, fmt);
949 clocking1 = snd_soc_read(codec, WM8900_REG_CLOCKING1);
950 aif1 = snd_soc_read(codec, WM8900_REG_AUDIO1);
951 aif3 = snd_soc_read(codec, WM8900_REG_AUDIO3);
952 aif4 = snd_soc_read(codec, WM8900_REG_AUDIO4);
954 /* set master/slave audio interface */
955 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
956 case SND_SOC_DAIFMT_CBS_CFS:
957 clocking1 &= ~WM8900_REG_CLOCKING1_BCLK_DIR;
958 aif3 &= ~WM8900_REG_AUDIO3_ADCLRC_DIR;
959 aif4 &= ~WM8900_REG_AUDIO4_DACLRC_DIR;
961 case SND_SOC_DAIFMT_CBS_CFM:
962 clocking1 &= ~WM8900_REG_CLOCKING1_BCLK_DIR;
963 aif3 |= WM8900_REG_AUDIO3_ADCLRC_DIR;
964 aif4 |= WM8900_REG_AUDIO4_DACLRC_DIR;
966 case SND_SOC_DAIFMT_CBM_CFM:
967 clocking1 |= WM8900_REG_CLOCKING1_BCLK_DIR;
968 aif3 |= WM8900_REG_AUDIO3_ADCLRC_DIR;
969 aif4 |= WM8900_REG_AUDIO4_DACLRC_DIR;
971 case SND_SOC_DAIFMT_CBM_CFS:
972 clocking1 |= WM8900_REG_CLOCKING1_BCLK_DIR;
973 aif3 &= ~WM8900_REG_AUDIO3_ADCLRC_DIR;
974 aif4 &= ~WM8900_REG_AUDIO4_DACLRC_DIR;
980 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
981 case SND_SOC_DAIFMT_DSP_A:
982 aif1 |= WM8900_REG_AUDIO1_AIF_FMT_MASK;
983 aif1 &= ~WM8900_REG_AUDIO1_LRCLK_INV;
985 case SND_SOC_DAIFMT_DSP_B:
986 aif1 |= WM8900_REG_AUDIO1_AIF_FMT_MASK;
987 aif1 |= WM8900_REG_AUDIO1_LRCLK_INV;
989 case SND_SOC_DAIFMT_I2S:
990 aif1 &= ~WM8900_REG_AUDIO1_AIF_FMT_MASK;
993 case SND_SOC_DAIFMT_RIGHT_J:
994 aif1 &= ~WM8900_REG_AUDIO1_AIF_FMT_MASK;
996 case SND_SOC_DAIFMT_LEFT_J:
997 aif1 &= ~WM8900_REG_AUDIO1_AIF_FMT_MASK;
1004 /* Clock inversion */
1005 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1006 case SND_SOC_DAIFMT_DSP_A:
1007 case SND_SOC_DAIFMT_DSP_B:
1008 /* frame inversion not valid for DSP modes */
1009 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1010 case SND_SOC_DAIFMT_NB_NF:
1011 aif1 &= ~WM8900_REG_AUDIO1_BCLK_INV;
1013 case SND_SOC_DAIFMT_IB_NF:
1014 aif1 |= WM8900_REG_AUDIO1_BCLK_INV;
1020 case SND_SOC_DAIFMT_I2S:
1021 case SND_SOC_DAIFMT_RIGHT_J:
1022 case SND_SOC_DAIFMT_LEFT_J:
1023 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1024 case SND_SOC_DAIFMT_NB_NF:
1025 aif1 &= ~WM8900_REG_AUDIO1_BCLK_INV;
1026 aif1 &= ~WM8900_REG_AUDIO1_LRCLK_INV;
1028 case SND_SOC_DAIFMT_IB_IF:
1029 aif1 |= WM8900_REG_AUDIO1_BCLK_INV;
1030 aif1 |= WM8900_REG_AUDIO1_LRCLK_INV;
1032 case SND_SOC_DAIFMT_IB_NF:
1033 aif1 |= WM8900_REG_AUDIO1_BCLK_INV;
1034 aif1 &= ~WM8900_REG_AUDIO1_LRCLK_INV;
1036 case SND_SOC_DAIFMT_NB_IF:
1037 aif1 &= ~WM8900_REG_AUDIO1_BCLK_INV;
1038 aif1 |= WM8900_REG_AUDIO1_LRCLK_INV;
1048 snd_soc_write(codec, WM8900_REG_CLOCKING1, clocking1);
1049 snd_soc_write(codec, WM8900_REG_AUDIO1, aif1);
1050 snd_soc_write(codec, WM8900_REG_AUDIO3, aif3);
1051 snd_soc_write(codec, WM8900_REG_AUDIO4, aif4);
1056 static int wm8900_digital_mute(struct snd_soc_dai *codec_dai, int mute)
1058 struct snd_soc_codec *codec = codec_dai->codec;
1060 WM8900_DBG("Enter:%s, %d \n", __FUNCTION__, __LINE__);
1062 reg = snd_soc_read(codec, WM8900_REG_DACCTRL);
1065 reg |= WM8900_REG_DACCTRL_MUTE;
1067 reg &= ~WM8900_REG_DACCTRL_MUTE;
1069 snd_soc_write(codec, WM8900_REG_DACCTRL, reg);
1074 #define WM8900_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
1075 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
1076 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
1078 #define WM8900_PCM_FORMATS \
1079 (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \
1080 SNDRV_PCM_FORMAT_S24_LE)
1082 static struct snd_soc_dai_ops wm8900_dai_ops = {
1083 .hw_params = wm8900_hw_params,
1084 .set_clkdiv = wm8900_set_dai_clkdiv,
1085 .set_pll = wm8900_set_dai_pll,
1086 .set_fmt = wm8900_set_dai_fmt,
1087 .digital_mute = wm8900_digital_mute,
1090 struct snd_soc_dai wm8900_dai = {
1091 .name = "WM8900 HiFi",
1093 .stream_name = "HiFi Playback",
1096 .rates = WM8900_RATES,
1097 .formats = WM8900_PCM_FORMATS,
1100 .stream_name = "HiFi Capture",
1103 .rates = WM8900_RATES,
1104 .formats = WM8900_PCM_FORMATS,
1106 .ops = &wm8900_dai_ops,
1108 EXPORT_SYMBOL_GPL(wm8900_dai);
1110 static int wm8900_set_bias_level(struct snd_soc_codec *codec,
1111 enum snd_soc_bias_level level)
1115 WM8900_DBG("Enter:%s, %d, level=0x%08X \n", __FUNCTION__, __LINE__, level);
1118 case SND_SOC_BIAS_ON:
1119 /* Enable thermal shutdown */
1120 reg = snd_soc_read(codec, WM8900_REG_GPIO);
1121 snd_soc_write(codec, WM8900_REG_GPIO,
1122 reg | WM8900_REG_GPIO_TEMP_ENA);
1123 reg = snd_soc_read(codec, WM8900_REG_ADDCTL);
1124 snd_soc_write(codec, WM8900_REG_ADDCTL,
1125 reg | WM8900_REG_ADDCTL_TEMP_SD);
1128 case SND_SOC_BIAS_PREPARE:
1131 case SND_SOC_BIAS_STANDBY:
1132 /* Charge capacitors if initial power up */
1133 if (codec->bias_level == SND_SOC_BIAS_OFF) {
1134 /* STARTUP_BIAS_ENA on */
1135 snd_soc_write(codec, WM8900_REG_POWER1,
1136 WM8900_REG_POWER1_STARTUP_BIAS_ENA);
1138 /* Startup bias mode */
1139 snd_soc_write(codec, WM8900_REG_ADDCTL,
1140 WM8900_REG_ADDCTL_BIAS_SRC |
1141 WM8900_REG_ADDCTL_VMID_SOFTST);
1144 snd_soc_write(codec, WM8900_REG_POWER1,
1145 WM8900_REG_POWER1_STARTUP_BIAS_ENA | 0x1);
1147 /* Allow capacitors to charge */
1148 schedule_timeout_interruptible(msecs_to_jiffies(400));
1151 snd_soc_write(codec, WM8900_REG_POWER1,
1152 WM8900_REG_POWER1_STARTUP_BIAS_ENA |
1153 WM8900_REG_POWER1_BIAS_ENA | 0x1);
1155 snd_soc_write(codec, WM8900_REG_ADDCTL, 0);
1157 snd_soc_write(codec, WM8900_REG_POWER1,
1158 WM8900_REG_POWER1_BIAS_ENA | 0x1);
1161 reg = snd_soc_read(codec, WM8900_REG_POWER1);
1162 snd_soc_write(codec, WM8900_REG_POWER1,
1163 (reg & WM8900_REG_POWER1_FLL_ENA) |
1164 WM8900_REG_POWER1_BIAS_ENA | 0x1);
1165 snd_soc_write(codec, WM8900_REG_POWER2,
1166 WM8900_REG_POWER2_SYSCLK_ENA);
1167 snd_soc_write(codec, WM8900_REG_POWER3, 0);
1170 case SND_SOC_BIAS_OFF:
1171 /* Startup bias enable */
1172 reg = snd_soc_read(codec, WM8900_REG_POWER1);
1173 snd_soc_write(codec, WM8900_REG_POWER1,
1174 reg & WM8900_REG_POWER1_STARTUP_BIAS_ENA);
1175 snd_soc_write(codec, WM8900_REG_ADDCTL,
1176 WM8900_REG_ADDCTL_BIAS_SRC |
1177 WM8900_REG_ADDCTL_VMID_SOFTST);
1179 /* Discharge caps */
1180 snd_soc_write(codec, WM8900_REG_POWER1,
1181 WM8900_REG_POWER1_STARTUP_BIAS_ENA);
1182 schedule_timeout_interruptible(msecs_to_jiffies(500));
1185 snd_soc_write(codec, WM8900_REG_HPCTL1, 0);
1188 snd_soc_write(codec, WM8900_REG_ADDCTL, 0);
1189 snd_soc_write(codec, WM8900_REG_POWER1, 0);
1190 snd_soc_write(codec, WM8900_REG_POWER2, 0);
1191 snd_soc_write(codec, WM8900_REG_POWER3, 0);
1193 /* Need to let things settle before stopping the clock
1194 * to ensure that restart works, see "Stopping the
1195 * master clock" in the datasheet. */
1196 schedule_timeout_interruptible(msecs_to_jiffies(1));
1197 snd_soc_write(codec, WM8900_REG_POWER2,
1198 WM8900_REG_POWER2_SYSCLK_ENA);
1203 codec->bias_level = level;
1207 static int wm8900_suspend(struct platform_device *pdev, pm_message_t state)
1209 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1210 struct snd_soc_codec *codec = socdev->card->codec;
1211 struct wm8900_priv *wm8900 = codec->private_data;
1213 WM8900_DBG("Enter:%s, %d \n", __FUNCTION__, __LINE__);
1215 int fll_out = wm8900->fll_out;
1216 int fll_in = wm8900->fll_in;
1219 /* Stop the FLL in an orderly fashion */
1220 ret = wm8900_set_fll(codec, 0, 0, 0);
1222 dev_err(&pdev->dev, "Failed to stop FLL\n");
1226 wm8900->fll_out = fll_out;
1227 wm8900->fll_in = fll_in;
1229 wm8900_set_bias_level(codec, SND_SOC_BIAS_OFF);
1234 static int wm8900_resume(struct platform_device *pdev)
1236 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1237 struct snd_soc_codec *codec = socdev->card->codec;
1238 struct wm8900_priv *wm8900 = codec->private_data;
1242 cache = kmemdup(codec->reg_cache, sizeof(wm8900_reg_defaults),
1245 wm8900_reset(codec);
1246 wm8900_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1248 /* Restart the FLL? */
1249 if (wm8900->fll_out) {
1250 int fll_out = wm8900->fll_out;
1251 int fll_in = wm8900->fll_in;
1254 wm8900->fll_out = 0;
1256 ret = wm8900_set_fll(codec, 0, fll_in, fll_out);
1258 dev_err(&pdev->dev, "Failed to restart FLL\n");
1264 for (i = 0; i < WM8900_MAXREG; i++)
1265 snd_soc_write(codec, i, cache[i]);
1268 dev_err(&pdev->dev, "Unable to allocate register cache\n");
1273 static struct snd_soc_codec *wm8900_codec;
1275 static __devinit int wm8900_i2c_probe(struct i2c_client *i2c,
1276 const struct i2c_device_id *id)
1278 struct wm8900_priv *wm8900;
1279 struct snd_soc_codec *codec;
1283 WM8900_DBG("Enter:%s, %d \n", __FUNCTION__, __LINE__);
1285 wm8900 = kzalloc(sizeof(struct wm8900_priv), GFP_KERNEL);
1289 codec = &wm8900->codec;
1290 codec->private_data = wm8900;
1291 codec->reg_cache = &wm8900->reg_cache[0];
1292 codec->reg_cache_size = WM8900_MAXREG;
1294 mutex_init(&codec->mutex);
1295 INIT_LIST_HEAD(&codec->dapm_widgets);
1296 INIT_LIST_HEAD(&codec->dapm_paths);
1298 codec->name = "WM8900";
1299 codec->owner = THIS_MODULE;
1300 codec->dai = &wm8900_dai;
1302 codec->control_data = i2c;
1303 codec->set_bias_level = wm8900_set_bias_level;
1304 codec->volatile_register = wm8900_volatile_register;
1305 codec->dev = &i2c->dev;
1307 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C);
1309 dev_err(&i2c->dev, "Failed to set cache I/O: %d\n", ret);
1313 reg = snd_soc_read(codec, WM8900_REG_ID);
1314 if (reg != 0x8900) {
1315 dev_err(&i2c->dev, "Device is not a WM8900 - ID %x\n", reg);
1320 /* Read back from the chip */
1321 reg = snd_soc_read(codec, WM8900_REG_POWER1);
1322 reg = (reg >> 12) & 0xf;
1323 dev_info(&i2c->dev, "WM8900 revision %d\n", reg);
1325 wm8900_reset(codec);
1327 /* Turn the chip on */
1328 wm8900_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1330 /* Latch the volume update bits */
1331 snd_soc_write(codec, WM8900_REG_LINVOL,
1332 snd_soc_read(codec, WM8900_REG_LINVOL) | 0x100);
1333 snd_soc_write(codec, WM8900_REG_RINVOL,
1334 snd_soc_read(codec, WM8900_REG_RINVOL) | 0x100);
1335 snd_soc_write(codec, WM8900_REG_LOUT1CTL,
1336 snd_soc_read(codec, WM8900_REG_LOUT1CTL) | 0x100);
1337 snd_soc_write(codec, WM8900_REG_ROUT1CTL,
1338 snd_soc_read(codec, WM8900_REG_ROUT1CTL) | 0x100);
1339 snd_soc_write(codec, WM8900_REG_LOUT2CTL,
1340 snd_soc_read(codec, WM8900_REG_LOUT2CTL) | 0x100);
1341 snd_soc_write(codec, WM8900_REG_ROUT2CTL,
1342 snd_soc_read(codec, WM8900_REG_ROUT2CTL) | 0x100);
1343 snd_soc_write(codec, WM8900_REG_LDAC_DV,
1344 snd_soc_read(codec, WM8900_REG_LDAC_DV) | 0x100);
1345 snd_soc_write(codec, WM8900_REG_RDAC_DV,
1346 snd_soc_read(codec, WM8900_REG_RDAC_DV) | 0x100);
1347 snd_soc_write(codec, WM8900_REG_LADC_DV,
1348 snd_soc_read(codec, WM8900_REG_LADC_DV) | 0x100);
1349 snd_soc_write(codec, WM8900_REG_RADC_DV,
1350 snd_soc_read(codec, WM8900_REG_RADC_DV) | 0x100);
1355 snd_soc_write(codec, WM8900_REG_LDAC_DV,
1356 (snd_soc_read(codec, WM8900_REG_LDAC_DV)&0xFF00) | 0xB0);
1357 snd_soc_write(codec, WM8900_REG_RDAC_DV,
1358 (snd_soc_read(codec, WM8900_REG_RDAC_DV)&0xFF00) | 0xB0);
1360 snd_soc_write(codec, WM8900_REG_AUDIO2,
1361 (snd_soc_read(codec, WM8900_REG_AUDIO2) | (0<<10)));
1364 /* Set the DAC and mixer output bias */
1365 snd_soc_write(codec, WM8900_REG_OUTBIASCTL, 0x81);
1367 wm8900_dai.dev = &i2c->dev;
1369 wm8900_codec = codec;
1371 ret = snd_soc_register_codec(codec);
1373 dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
1377 ret = snd_soc_register_dai(&wm8900_dai);
1379 dev_err(&i2c->dev, "Failed to register DAI: %d\n", ret);
1386 snd_soc_unregister_codec(codec);
1389 wm8900_codec = NULL;
1393 static __devexit int wm8900_i2c_remove(struct i2c_client *client)
1395 WM8900_DBG("Enter:%s, %d \n", __FUNCTION__, __LINE__);
1397 snd_soc_unregister_dai(&wm8900_dai);
1398 snd_soc_unregister_codec(wm8900_codec);
1400 wm8900_set_bias_level(wm8900_codec, SND_SOC_BIAS_OFF);
1402 wm8900_dai.dev = NULL;
1403 kfree(wm8900_codec->private_data);
1404 wm8900_codec = NULL;
1410 static int wm8900_i2c_suspend(struct i2c_client *client, pm_message_t msg)
1412 WM8900_DBG("Enter:%s, %d \n", __FUNCTION__, __LINE__);
1413 return snd_soc_suspend_device(&client->dev);
1416 static int wm8900_i2c_resume(struct i2c_client *client)
1418 return snd_soc_resume_device(&client->dev);
1421 #define wm8900_i2c_suspend NULL
1422 #define wm8900_i2c_resume NULL
1425 static const struct i2c_device_id wm8900_i2c_id[] = {
1429 MODULE_DEVICE_TABLE(i2c, wm8900_i2c_id);
1431 static struct i2c_driver wm8900_i2c_driver = {
1434 .owner = THIS_MODULE,
1436 .probe = wm8900_i2c_probe,
1437 .remove = __devexit_p(wm8900_i2c_remove),
1438 .suspend = wm8900_i2c_suspend,
1439 .resume = wm8900_i2c_resume,
1440 .id_table = wm8900_i2c_id,
1443 static int wm8900_probe(struct platform_device *pdev)
1445 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1446 struct snd_soc_codec *codec;
1449 WM8900_DBG("Enter:%s, %d \n", __FUNCTION__, __LINE__);
1451 if (!wm8900_codec) {
1452 dev_err(&pdev->dev, "I2C client not yet instantiated\n");
1456 codec = wm8900_codec;
1457 socdev->card->codec = codec;
1460 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
1462 dev_err(&pdev->dev, "Failed to register new PCMs\n");
1466 snd_soc_add_controls(codec, wm8900_snd_controls,
1467 ARRAY_SIZE(wm8900_snd_controls));
1468 snd_soc_add_controls(codec, wm8900_linpga_controls,
1469 ARRAY_SIZE(wm8900_linpga_controls));
1470 snd_soc_add_controls(codec, wm8900_rinpga_controls,
1471 ARRAY_SIZE(wm8900_rinpga_controls));
1472 snd_soc_add_controls(codec, wm8900_inmix_controls,
1473 ARRAY_SIZE(wm8900_inmix_controls));
1475 wm8900_add_widgets(codec);
1477 ret = snd_soc_init_card(socdev);
1479 dev_err(&pdev->dev, "Failed to register card\n");
1486 snd_soc_free_pcms(socdev);
1487 snd_soc_dapm_free(socdev);
1492 /* power down chip */
1493 static int wm8900_remove(struct platform_device *pdev)
1495 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1497 snd_soc_free_pcms(socdev);
1498 snd_soc_dapm_free(socdev);
1503 struct snd_soc_codec_device soc_codec_dev_wm8900 = {
1504 .probe = wm8900_probe,
1505 .remove = wm8900_remove,
1506 .suspend = wm8900_suspend,
1507 .resume = wm8900_resume,
1509 EXPORT_SYMBOL_GPL(soc_codec_dev_wm8900);
1511 static int __init wm8900_modinit(void)
1513 return i2c_add_driver(&wm8900_i2c_driver);
1515 module_init(wm8900_modinit);
1517 static void __exit wm8900_exit(void)
1519 i2c_del_driver(&wm8900_i2c_driver);
1521 module_exit(wm8900_exit);
1523 MODULE_DESCRIPTION("ASoC WM8900 driver");
1524 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfonmicro.com>");
1525 MODULE_LICENSE("GPL");