blob: bf5e77c86aed659b202ce8faac7af7f65faafb74 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Mark Brownaaf1e172009-03-10 10:55:15 +00002/*
3 * wm8400.c -- WM8400 ALSA Soc Audio driver
4 *
Mark Brown656baae2012-05-23 12:39:07 +01005 * Copyright 2008-11 Wolfson Microelectronics PLC.
Mark Brownaaf1e172009-03-10 10:55:15 +00006 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
Mark Brownaaf1e172009-03-10 10:55:15 +00007 */
8
9#include <linux/module.h>
10#include <linux/moduleparam.h>
11#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Mark Brownaaf1e172009-03-10 10:55:15 +000013#include <linux/init.h>
14#include <linux/delay.h>
15#include <linux/pm.h>
16#include <linux/platform_device.h>
17#include <linux/regulator/consumer.h>
18#include <linux/mfd/wm8400-audio.h>
19#include <linux/mfd/wm8400-private.h>
Andres Salomondab15472011-02-17 19:07:27 -080020#include <linux/mfd/core.h>
Mark Brownaaf1e172009-03-10 10:55:15 +000021#include <sound/core.h>
22#include <sound/pcm.h>
23#include <sound/pcm_params.h>
24#include <sound/soc.h>
Mark Brownaaf1e172009-03-10 10:55:15 +000025#include <sound/initval.h>
26#include <sound/tlv.h>
27
28#include "wm8400.h"
29
Mark Brownaaf1e172009-03-10 10:55:15 +000030static struct regulator_bulk_data power[] = {
31 {
32 .supply = "I2S1VDD",
33 },
34 {
35 .supply = "I2S2VDD",
36 },
37 {
38 .supply = "DCVDD",
39 },
40 {
Mark Brown24a51022009-03-18 15:19:48 +000041 .supply = "AVDD",
42 },
43 {
Mark Brownaaf1e172009-03-10 10:55:15 +000044 .supply = "FLLVDD",
45 },
46 {
47 .supply = "HPVDD",
48 },
49 {
50 .supply = "SPKVDD",
51 },
52};
53
54/* codec private data */
55struct wm8400_priv {
Mark Brownaaf1e172009-03-10 10:55:15 +000056 struct wm8400 *wm8400;
57 u16 fake_register;
58 unsigned int sysclk;
59 unsigned int pcmclk;
Mark Browne8523b62009-03-18 18:28:01 +000060 int fll_in, fll_out;
Mark Brownaaf1e172009-03-10 10:55:15 +000061};
62
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +000063static void wm8400_component_reset(struct snd_soc_component *component)
Mark Brownaaf1e172009-03-10 10:55:15 +000064{
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +000065 struct wm8400_priv *wm8400 = snd_soc_component_get_drvdata(component);
Mark Brownaaf1e172009-03-10 10:55:15 +000066
67 wm8400_reset_codec_reg_cache(wm8400->wm8400);
68}
69
Mark Brown3351e9f2010-05-25 10:48:31 -070070static const DECLARE_TLV_DB_SCALE(in_pga_tlv, -1650, 3000, 0);
Mark Brownaaf1e172009-03-10 10:55:15 +000071
Mark Brown3351e9f2010-05-25 10:48:31 -070072static const DECLARE_TLV_DB_SCALE(out_mix_tlv, -2100, 0, 0);
Mark Brownaaf1e172009-03-10 10:55:15 +000073
Mark Brown3351e9f2010-05-25 10:48:31 -070074static const DECLARE_TLV_DB_SCALE(out_pga_tlv, -7300, 600, 0);
Mark Brownaaf1e172009-03-10 10:55:15 +000075
Mark Brown3351e9f2010-05-25 10:48:31 -070076static const DECLARE_TLV_DB_SCALE(out_dac_tlv, -7163, 0, 0);
Mark Brownaaf1e172009-03-10 10:55:15 +000077
Mark Brown3351e9f2010-05-25 10:48:31 -070078static const DECLARE_TLV_DB_SCALE(in_adc_tlv, -7163, 1763, 0);
Mark Brownaaf1e172009-03-10 10:55:15 +000079
Mark Brown3351e9f2010-05-25 10:48:31 -070080static const DECLARE_TLV_DB_SCALE(out_sidetone_tlv, -3600, 0, 0);
Mark Brownaaf1e172009-03-10 10:55:15 +000081
82static int wm8400_outpga_put_volsw_vu(struct snd_kcontrol *kcontrol,
83 struct snd_ctl_elem_value *ucontrol)
84{
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +000085 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
Mark Brownaaf1e172009-03-10 10:55:15 +000086 struct soc_mixer_control *mc =
87 (struct soc_mixer_control *)kcontrol->private_value;
88 int reg = mc->reg;
89 int ret;
90 u16 val;
91
92 ret = snd_soc_put_volsw(kcontrol, ucontrol);
93 if (ret < 0)
94 return ret;
95
96 /* now hit the volume update bits (always bit 8) */
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +090097 val = snd_soc_component_read(component, reg);
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +000098 return snd_soc_component_write(component, reg, val | 0x0100);
Mark Brownaaf1e172009-03-10 10:55:15 +000099}
100
101#define WM8400_OUTPGA_SINGLE_R_TLV(xname, reg, shift, max, invert, tlv_array) \
Lars-Peter Clausena44b5172013-06-19 19:33:54 +0200102 SOC_SINGLE_EXT_TLV(xname, reg, shift, max, invert, \
103 snd_soc_get_volsw, wm8400_outpga_put_volsw_vu, tlv_array)
Mark Brownaaf1e172009-03-10 10:55:15 +0000104
105
106static const char *wm8400_digital_sidetone[] =
107 {"None", "Left ADC", "Right ADC", "Reserved"};
108
Takashi Iwai898b48e2014-02-18 09:34:44 +0100109static SOC_ENUM_SINGLE_DECL(wm8400_left_digital_sidetone_enum,
110 WM8400_DIGITAL_SIDE_TONE,
111 WM8400_ADC_TO_DACL_SHIFT,
112 wm8400_digital_sidetone);
Mark Brownaaf1e172009-03-10 10:55:15 +0000113
Takashi Iwai898b48e2014-02-18 09:34:44 +0100114static SOC_ENUM_SINGLE_DECL(wm8400_right_digital_sidetone_enum,
115 WM8400_DIGITAL_SIDE_TONE,
116 WM8400_ADC_TO_DACR_SHIFT,
117 wm8400_digital_sidetone);
Mark Brownaaf1e172009-03-10 10:55:15 +0000118
119static const char *wm8400_adcmode[] =
120 {"Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"};
121
Takashi Iwai898b48e2014-02-18 09:34:44 +0100122static SOC_ENUM_SINGLE_DECL(wm8400_right_adcmode_enum,
123 WM8400_ADC_CTRL,
124 WM8400_ADC_HPF_CUT_SHIFT,
125 wm8400_adcmode);
Mark Brownaaf1e172009-03-10 10:55:15 +0000126
127static const struct snd_kcontrol_new wm8400_snd_controls[] = {
128/* INMIXL */
129SOC_SINGLE("LIN12 PGA Boost", WM8400_INPUT_MIXER3, WM8400_L12MNBST_SHIFT,
130 1, 0),
131SOC_SINGLE("LIN34 PGA Boost", WM8400_INPUT_MIXER3, WM8400_L34MNBST_SHIFT,
132 1, 0),
133/* INMIXR */
134SOC_SINGLE("RIN12 PGA Boost", WM8400_INPUT_MIXER3, WM8400_R12MNBST_SHIFT,
135 1, 0),
136SOC_SINGLE("RIN34 PGA Boost", WM8400_INPUT_MIXER3, WM8400_R34MNBST_SHIFT,
137 1, 0),
138
139/* LOMIX */
140SOC_SINGLE_TLV("LOMIX LIN3 Bypass Volume", WM8400_OUTPUT_MIXER3,
141 WM8400_LLI3LOVOL_SHIFT, 7, 0, out_mix_tlv),
142SOC_SINGLE_TLV("LOMIX RIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER3,
143 WM8400_LR12LOVOL_SHIFT, 7, 0, out_mix_tlv),
144SOC_SINGLE_TLV("LOMIX LIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER3,
145 WM8400_LL12LOVOL_SHIFT, 7, 0, out_mix_tlv),
146SOC_SINGLE_TLV("LOMIX RIN3 Bypass Volume", WM8400_OUTPUT_MIXER5,
147 WM8400_LRI3LOVOL_SHIFT, 7, 0, out_mix_tlv),
148SOC_SINGLE_TLV("LOMIX AINRMUX Bypass Volume", WM8400_OUTPUT_MIXER5,
149 WM8400_LRBLOVOL_SHIFT, 7, 0, out_mix_tlv),
150SOC_SINGLE_TLV("LOMIX AINLMUX Bypass Volume", WM8400_OUTPUT_MIXER5,
151 WM8400_LRBLOVOL_SHIFT, 7, 0, out_mix_tlv),
152
153/* ROMIX */
154SOC_SINGLE_TLV("ROMIX RIN3 Bypass Volume", WM8400_OUTPUT_MIXER4,
155 WM8400_RRI3ROVOL_SHIFT, 7, 0, out_mix_tlv),
156SOC_SINGLE_TLV("ROMIX LIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER4,
157 WM8400_RL12ROVOL_SHIFT, 7, 0, out_mix_tlv),
158SOC_SINGLE_TLV("ROMIX RIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER4,
159 WM8400_RR12ROVOL_SHIFT, 7, 0, out_mix_tlv),
160SOC_SINGLE_TLV("ROMIX LIN3 Bypass Volume", WM8400_OUTPUT_MIXER6,
161 WM8400_RLI3ROVOL_SHIFT, 7, 0, out_mix_tlv),
162SOC_SINGLE_TLV("ROMIX AINLMUX Bypass Volume", WM8400_OUTPUT_MIXER6,
163 WM8400_RLBROVOL_SHIFT, 7, 0, out_mix_tlv),
164SOC_SINGLE_TLV("ROMIX AINRMUX Bypass Volume", WM8400_OUTPUT_MIXER6,
165 WM8400_RRBROVOL_SHIFT, 7, 0, out_mix_tlv),
166
167/* LOUT */
168WM8400_OUTPGA_SINGLE_R_TLV("LOUT Volume", WM8400_LEFT_OUTPUT_VOLUME,
169 WM8400_LOUTVOL_SHIFT, WM8400_LOUTVOL_MASK, 0, out_pga_tlv),
170SOC_SINGLE("LOUT ZC", WM8400_LEFT_OUTPUT_VOLUME, WM8400_LOZC_SHIFT, 1, 0),
171
172/* ROUT */
173WM8400_OUTPGA_SINGLE_R_TLV("ROUT Volume", WM8400_RIGHT_OUTPUT_VOLUME,
174 WM8400_ROUTVOL_SHIFT, WM8400_ROUTVOL_MASK, 0, out_pga_tlv),
175SOC_SINGLE("ROUT ZC", WM8400_RIGHT_OUTPUT_VOLUME, WM8400_ROZC_SHIFT, 1, 0),
176
177/* LOPGA */
178WM8400_OUTPGA_SINGLE_R_TLV("LOPGA Volume", WM8400_LEFT_OPGA_VOLUME,
179 WM8400_LOPGAVOL_SHIFT, WM8400_LOPGAVOL_MASK, 0, out_pga_tlv),
180SOC_SINGLE("LOPGA ZC Switch", WM8400_LEFT_OPGA_VOLUME,
181 WM8400_LOPGAZC_SHIFT, 1, 0),
182
183/* ROPGA */
184WM8400_OUTPGA_SINGLE_R_TLV("ROPGA Volume", WM8400_RIGHT_OPGA_VOLUME,
185 WM8400_ROPGAVOL_SHIFT, WM8400_ROPGAVOL_MASK, 0, out_pga_tlv),
186SOC_SINGLE("ROPGA ZC Switch", WM8400_RIGHT_OPGA_VOLUME,
187 WM8400_ROPGAZC_SHIFT, 1, 0),
188
189SOC_SINGLE("LON Mute Switch", WM8400_LINE_OUTPUTS_VOLUME,
190 WM8400_LONMUTE_SHIFT, 1, 0),
191SOC_SINGLE("LOP Mute Switch", WM8400_LINE_OUTPUTS_VOLUME,
192 WM8400_LOPMUTE_SHIFT, 1, 0),
193SOC_SINGLE("LOP Attenuation Switch", WM8400_LINE_OUTPUTS_VOLUME,
194 WM8400_LOATTN_SHIFT, 1, 0),
195SOC_SINGLE("RON Mute Switch", WM8400_LINE_OUTPUTS_VOLUME,
196 WM8400_RONMUTE_SHIFT, 1, 0),
197SOC_SINGLE("ROP Mute Switch", WM8400_LINE_OUTPUTS_VOLUME,
198 WM8400_ROPMUTE_SHIFT, 1, 0),
199SOC_SINGLE("ROP Attenuation Switch", WM8400_LINE_OUTPUTS_VOLUME,
200 WM8400_ROATTN_SHIFT, 1, 0),
201
202SOC_SINGLE("OUT3 Mute Switch", WM8400_OUT3_4_VOLUME,
203 WM8400_OUT3MUTE_SHIFT, 1, 0),
204SOC_SINGLE("OUT3 Attenuation Switch", WM8400_OUT3_4_VOLUME,
205 WM8400_OUT3ATTN_SHIFT, 1, 0),
206
207SOC_SINGLE("OUT4 Mute Switch", WM8400_OUT3_4_VOLUME,
208 WM8400_OUT4MUTE_SHIFT, 1, 0),
209SOC_SINGLE("OUT4 Attenuation Switch", WM8400_OUT3_4_VOLUME,
210 WM8400_OUT4ATTN_SHIFT, 1, 0),
211
212SOC_SINGLE("Speaker Mode Switch", WM8400_CLASSD1,
213 WM8400_CDMODE_SHIFT, 1, 0),
214
215SOC_SINGLE("Speaker Output Attenuation Volume", WM8400_SPEAKER_VOLUME,
216 WM8400_SPKATTN_SHIFT, WM8400_SPKATTN_MASK, 0),
217SOC_SINGLE("Speaker DC Boost Volume", WM8400_CLASSD3,
218 WM8400_DCGAIN_SHIFT, 6, 0),
219SOC_SINGLE("Speaker AC Boost Volume", WM8400_CLASSD3,
220 WM8400_ACGAIN_SHIFT, 6, 0),
221
222WM8400_OUTPGA_SINGLE_R_TLV("Left DAC Digital Volume",
223 WM8400_LEFT_DAC_DIGITAL_VOLUME, WM8400_DACL_VOL_SHIFT,
224 127, 0, out_dac_tlv),
225
226WM8400_OUTPGA_SINGLE_R_TLV("Right DAC Digital Volume",
227 WM8400_RIGHT_DAC_DIGITAL_VOLUME, WM8400_DACR_VOL_SHIFT,
228 127, 0, out_dac_tlv),
229
230SOC_ENUM("Left Digital Sidetone", wm8400_left_digital_sidetone_enum),
231SOC_ENUM("Right Digital Sidetone", wm8400_right_digital_sidetone_enum),
232
233SOC_SINGLE_TLV("Left Digital Sidetone Volume", WM8400_DIGITAL_SIDE_TONE,
234 WM8400_ADCL_DAC_SVOL_SHIFT, 15, 0, out_sidetone_tlv),
235SOC_SINGLE_TLV("Right Digital Sidetone Volume", WM8400_DIGITAL_SIDE_TONE,
236 WM8400_ADCR_DAC_SVOL_SHIFT, 15, 0, out_sidetone_tlv),
237
238SOC_SINGLE("ADC Digital High Pass Filter Switch", WM8400_ADC_CTRL,
239 WM8400_ADC_HPF_ENA_SHIFT, 1, 0),
240
241SOC_ENUM("ADC HPF Mode", wm8400_right_adcmode_enum),
242
243WM8400_OUTPGA_SINGLE_R_TLV("Left ADC Digital Volume",
244 WM8400_LEFT_ADC_DIGITAL_VOLUME,
245 WM8400_ADCL_VOL_SHIFT,
246 WM8400_ADCL_VOL_MASK,
247 0,
248 in_adc_tlv),
249
250WM8400_OUTPGA_SINGLE_R_TLV("Right ADC Digital Volume",
251 WM8400_RIGHT_ADC_DIGITAL_VOLUME,
252 WM8400_ADCR_VOL_SHIFT,
253 WM8400_ADCR_VOL_MASK,
254 0,
255 in_adc_tlv),
256
257WM8400_OUTPGA_SINGLE_R_TLV("LIN12 Volume",
258 WM8400_LEFT_LINE_INPUT_1_2_VOLUME,
259 WM8400_LIN12VOL_SHIFT,
260 WM8400_LIN12VOL_MASK,
261 0,
262 in_pga_tlv),
263
264SOC_SINGLE("LIN12 ZC Switch", WM8400_LEFT_LINE_INPUT_1_2_VOLUME,
265 WM8400_LI12ZC_SHIFT, 1, 0),
266
267SOC_SINGLE("LIN12 Mute Switch", WM8400_LEFT_LINE_INPUT_1_2_VOLUME,
268 WM8400_LI12MUTE_SHIFT, 1, 0),
269
270WM8400_OUTPGA_SINGLE_R_TLV("LIN34 Volume",
271 WM8400_LEFT_LINE_INPUT_3_4_VOLUME,
272 WM8400_LIN34VOL_SHIFT,
273 WM8400_LIN34VOL_MASK,
274 0,
275 in_pga_tlv),
276
277SOC_SINGLE("LIN34 ZC Switch", WM8400_LEFT_LINE_INPUT_3_4_VOLUME,
278 WM8400_LI34ZC_SHIFT, 1, 0),
279
280SOC_SINGLE("LIN34 Mute Switch", WM8400_LEFT_LINE_INPUT_3_4_VOLUME,
281 WM8400_LI34MUTE_SHIFT, 1, 0),
282
283WM8400_OUTPGA_SINGLE_R_TLV("RIN12 Volume",
284 WM8400_RIGHT_LINE_INPUT_1_2_VOLUME,
285 WM8400_RIN12VOL_SHIFT,
286 WM8400_RIN12VOL_MASK,
287 0,
288 in_pga_tlv),
289
290SOC_SINGLE("RIN12 ZC Switch", WM8400_RIGHT_LINE_INPUT_1_2_VOLUME,
291 WM8400_RI12ZC_SHIFT, 1, 0),
292
293SOC_SINGLE("RIN12 Mute Switch", WM8400_RIGHT_LINE_INPUT_1_2_VOLUME,
294 WM8400_RI12MUTE_SHIFT, 1, 0),
295
296WM8400_OUTPGA_SINGLE_R_TLV("RIN34 Volume",
297 WM8400_RIGHT_LINE_INPUT_3_4_VOLUME,
298 WM8400_RIN34VOL_SHIFT,
299 WM8400_RIN34VOL_MASK,
300 0,
301 in_pga_tlv),
302
303SOC_SINGLE("RIN34 ZC Switch", WM8400_RIGHT_LINE_INPUT_3_4_VOLUME,
304 WM8400_RI34ZC_SHIFT, 1, 0),
305
306SOC_SINGLE("RIN34 Mute Switch", WM8400_RIGHT_LINE_INPUT_3_4_VOLUME,
307 WM8400_RI34MUTE_SHIFT, 1, 0),
308
309};
310
Mark Brownaaf1e172009-03-10 10:55:15 +0000311/*
312 * _DAPM_ Controls
313 */
314
Mark Brownaaf1e172009-03-10 10:55:15 +0000315static int outmixer_event (struct snd_soc_dapm_widget *w,
316 struct snd_kcontrol * kcontrol, int event)
317{
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +0000318 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
Mark Brownaaf1e172009-03-10 10:55:15 +0000319 struct soc_mixer_control *mc =
320 (struct soc_mixer_control *)kcontrol->private_value;
321 u32 reg_shift = mc->shift;
322 int ret = 0;
323 u16 reg;
324
325 switch (reg_shift) {
326 case WM8400_SPEAKER_MIXER | (WM8400_LDSPK << 8) :
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +0900327 reg = snd_soc_component_read(component, WM8400_OUTPUT_MIXER1);
Mark Brownaaf1e172009-03-10 10:55:15 +0000328 if (reg & WM8400_LDLO) {
329 printk(KERN_WARNING
330 "Cannot set as Output Mixer 1 LDLO Set\n");
331 ret = -1;
332 }
333 break;
334 case WM8400_SPEAKER_MIXER | (WM8400_RDSPK << 8):
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +0900335 reg = snd_soc_component_read(component, WM8400_OUTPUT_MIXER2);
Mark Brownaaf1e172009-03-10 10:55:15 +0000336 if (reg & WM8400_RDRO) {
337 printk(KERN_WARNING
338 "Cannot set as Output Mixer 2 RDRO Set\n");
339 ret = -1;
340 }
341 break;
342 case WM8400_OUTPUT_MIXER1 | (WM8400_LDLO << 8):
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +0900343 reg = snd_soc_component_read(component, WM8400_SPEAKER_MIXER);
Mark Brownaaf1e172009-03-10 10:55:15 +0000344 if (reg & WM8400_LDSPK) {
345 printk(KERN_WARNING
346 "Cannot set as Speaker Mixer LDSPK Set\n");
347 ret = -1;
348 }
349 break;
350 case WM8400_OUTPUT_MIXER2 | (WM8400_RDRO << 8):
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +0900351 reg = snd_soc_component_read(component, WM8400_SPEAKER_MIXER);
Mark Brownaaf1e172009-03-10 10:55:15 +0000352 if (reg & WM8400_RDSPK) {
353 printk(KERN_WARNING
354 "Cannot set as Speaker Mixer RDSPK Set\n");
355 ret = -1;
356 }
357 break;
358 }
359
360 return ret;
361}
362
363/* INMIX dB values */
Lars-Peter Clausen0b65e6c2015-08-02 17:19:59 +0200364static const DECLARE_TLV_DB_SCALE(in_mix_tlv, -1200, 600, 0);
Mark Brownaaf1e172009-03-10 10:55:15 +0000365
366/* Left In PGA Connections */
367static const struct snd_kcontrol_new wm8400_dapm_lin12_pga_controls[] = {
368SOC_DAPM_SINGLE("LIN1 Switch", WM8400_INPUT_MIXER2, WM8400_LMN1_SHIFT, 1, 0),
369SOC_DAPM_SINGLE("LIN2 Switch", WM8400_INPUT_MIXER2, WM8400_LMP2_SHIFT, 1, 0),
370};
371
372static const struct snd_kcontrol_new wm8400_dapm_lin34_pga_controls[] = {
373SOC_DAPM_SINGLE("LIN3 Switch", WM8400_INPUT_MIXER2, WM8400_LMN3_SHIFT, 1, 0),
374SOC_DAPM_SINGLE("LIN4 Switch", WM8400_INPUT_MIXER2, WM8400_LMP4_SHIFT, 1, 0),
375};
376
377/* Right In PGA Connections */
378static const struct snd_kcontrol_new wm8400_dapm_rin12_pga_controls[] = {
379SOC_DAPM_SINGLE("RIN1 Switch", WM8400_INPUT_MIXER2, WM8400_RMN1_SHIFT, 1, 0),
380SOC_DAPM_SINGLE("RIN2 Switch", WM8400_INPUT_MIXER2, WM8400_RMP2_SHIFT, 1, 0),
381};
382
383static const struct snd_kcontrol_new wm8400_dapm_rin34_pga_controls[] = {
384SOC_DAPM_SINGLE("RIN3 Switch", WM8400_INPUT_MIXER2, WM8400_RMN3_SHIFT, 1, 0),
385SOC_DAPM_SINGLE("RIN4 Switch", WM8400_INPUT_MIXER2, WM8400_RMP4_SHIFT, 1, 0),
386};
387
388/* INMIXL */
389static const struct snd_kcontrol_new wm8400_dapm_inmixl_controls[] = {
390SOC_DAPM_SINGLE_TLV("Record Left Volume", WM8400_INPUT_MIXER3,
391 WM8400_LDBVOL_SHIFT, WM8400_LDBVOL_MASK, 0, in_mix_tlv),
392SOC_DAPM_SINGLE_TLV("LIN2 Volume", WM8400_INPUT_MIXER5, WM8400_LI2BVOL_SHIFT,
393 7, 0, in_mix_tlv),
394SOC_DAPM_SINGLE("LINPGA12 Switch", WM8400_INPUT_MIXER3, WM8400_L12MNB_SHIFT,
395 1, 0),
396SOC_DAPM_SINGLE("LINPGA34 Switch", WM8400_INPUT_MIXER3, WM8400_L34MNB_SHIFT,
397 1, 0),
398};
399
400/* INMIXR */
401static const struct snd_kcontrol_new wm8400_dapm_inmixr_controls[] = {
402SOC_DAPM_SINGLE_TLV("Record Right Volume", WM8400_INPUT_MIXER4,
403 WM8400_RDBVOL_SHIFT, WM8400_RDBVOL_MASK, 0, in_mix_tlv),
404SOC_DAPM_SINGLE_TLV("RIN2 Volume", WM8400_INPUT_MIXER6, WM8400_RI2BVOL_SHIFT,
405 7, 0, in_mix_tlv),
406SOC_DAPM_SINGLE("RINPGA12 Switch", WM8400_INPUT_MIXER3, WM8400_L12MNB_SHIFT,
407 1, 0),
408SOC_DAPM_SINGLE("RINPGA34 Switch", WM8400_INPUT_MIXER3, WM8400_L34MNB_SHIFT,
409 1, 0),
410};
411
412/* AINLMUX */
413static const char *wm8400_ainlmux[] =
414 {"INMIXL Mix", "RXVOICE Mix", "DIFFINL Mix"};
415
Takashi Iwai898b48e2014-02-18 09:34:44 +0100416static SOC_ENUM_SINGLE_DECL(wm8400_ainlmux_enum,
417 WM8400_INPUT_MIXER1,
418 WM8400_AINLMODE_SHIFT,
419 wm8400_ainlmux);
Mark Brownaaf1e172009-03-10 10:55:15 +0000420
421static const struct snd_kcontrol_new wm8400_dapm_ainlmux_controls =
422SOC_DAPM_ENUM("Route", wm8400_ainlmux_enum);
423
424/* DIFFINL */
425
426/* AINRMUX */
427static const char *wm8400_ainrmux[] =
428 {"INMIXR Mix", "RXVOICE Mix", "DIFFINR Mix"};
429
Takashi Iwai898b48e2014-02-18 09:34:44 +0100430static SOC_ENUM_SINGLE_DECL(wm8400_ainrmux_enum,
431 WM8400_INPUT_MIXER1,
432 WM8400_AINRMODE_SHIFT,
433 wm8400_ainrmux);
Mark Brownaaf1e172009-03-10 10:55:15 +0000434
435static const struct snd_kcontrol_new wm8400_dapm_ainrmux_controls =
436SOC_DAPM_ENUM("Route", wm8400_ainrmux_enum);
437
Mark Brownaaf1e172009-03-10 10:55:15 +0000438/* LOMIX */
439static const struct snd_kcontrol_new wm8400_dapm_lomix_controls[] = {
440SOC_DAPM_SINGLE("LOMIX Right ADC Bypass Switch", WM8400_OUTPUT_MIXER1,
441 WM8400_LRBLO_SHIFT, 1, 0),
442SOC_DAPM_SINGLE("LOMIX Left ADC Bypass Switch", WM8400_OUTPUT_MIXER1,
443 WM8400_LLBLO_SHIFT, 1, 0),
444SOC_DAPM_SINGLE("LOMIX RIN3 Bypass Switch", WM8400_OUTPUT_MIXER1,
445 WM8400_LRI3LO_SHIFT, 1, 0),
446SOC_DAPM_SINGLE("LOMIX LIN3 Bypass Switch", WM8400_OUTPUT_MIXER1,
447 WM8400_LLI3LO_SHIFT, 1, 0),
448SOC_DAPM_SINGLE("LOMIX RIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER1,
449 WM8400_LR12LO_SHIFT, 1, 0),
450SOC_DAPM_SINGLE("LOMIX LIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER1,
451 WM8400_LL12LO_SHIFT, 1, 0),
452SOC_DAPM_SINGLE("LOMIX Left DAC Switch", WM8400_OUTPUT_MIXER1,
453 WM8400_LDLO_SHIFT, 1, 0),
454};
455
456/* ROMIX */
457static const struct snd_kcontrol_new wm8400_dapm_romix_controls[] = {
458SOC_DAPM_SINGLE("ROMIX Left ADC Bypass Switch", WM8400_OUTPUT_MIXER2,
459 WM8400_RLBRO_SHIFT, 1, 0),
460SOC_DAPM_SINGLE("ROMIX Right ADC Bypass Switch", WM8400_OUTPUT_MIXER2,
461 WM8400_RRBRO_SHIFT, 1, 0),
462SOC_DAPM_SINGLE("ROMIX LIN3 Bypass Switch", WM8400_OUTPUT_MIXER2,
463 WM8400_RLI3RO_SHIFT, 1, 0),
464SOC_DAPM_SINGLE("ROMIX RIN3 Bypass Switch", WM8400_OUTPUT_MIXER2,
465 WM8400_RRI3RO_SHIFT, 1, 0),
466SOC_DAPM_SINGLE("ROMIX LIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER2,
467 WM8400_RL12RO_SHIFT, 1, 0),
468SOC_DAPM_SINGLE("ROMIX RIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER2,
469 WM8400_RR12RO_SHIFT, 1, 0),
470SOC_DAPM_SINGLE("ROMIX Right DAC Switch", WM8400_OUTPUT_MIXER2,
471 WM8400_RDRO_SHIFT, 1, 0),
472};
473
474/* LONMIX */
475static const struct snd_kcontrol_new wm8400_dapm_lonmix_controls[] = {
476SOC_DAPM_SINGLE("LONMIX Left Mixer PGA Switch", WM8400_LINE_MIXER1,
477 WM8400_LLOPGALON_SHIFT, 1, 0),
478SOC_DAPM_SINGLE("LONMIX Right Mixer PGA Switch", WM8400_LINE_MIXER1,
479 WM8400_LROPGALON_SHIFT, 1, 0),
480SOC_DAPM_SINGLE("LONMIX Inverted LOP Switch", WM8400_LINE_MIXER1,
481 WM8400_LOPLON_SHIFT, 1, 0),
482};
483
484/* LOPMIX */
485static const struct snd_kcontrol_new wm8400_dapm_lopmix_controls[] = {
486SOC_DAPM_SINGLE("LOPMIX Right Mic Bypass Switch", WM8400_LINE_MIXER1,
487 WM8400_LR12LOP_SHIFT, 1, 0),
488SOC_DAPM_SINGLE("LOPMIX Left Mic Bypass Switch", WM8400_LINE_MIXER1,
489 WM8400_LL12LOP_SHIFT, 1, 0),
490SOC_DAPM_SINGLE("LOPMIX Left Mixer PGA Switch", WM8400_LINE_MIXER1,
491 WM8400_LLOPGALOP_SHIFT, 1, 0),
492};
493
494/* RONMIX */
495static const struct snd_kcontrol_new wm8400_dapm_ronmix_controls[] = {
496SOC_DAPM_SINGLE("RONMIX Right Mixer PGA Switch", WM8400_LINE_MIXER2,
497 WM8400_RROPGARON_SHIFT, 1, 0),
498SOC_DAPM_SINGLE("RONMIX Left Mixer PGA Switch", WM8400_LINE_MIXER2,
499 WM8400_RLOPGARON_SHIFT, 1, 0),
500SOC_DAPM_SINGLE("RONMIX Inverted ROP Switch", WM8400_LINE_MIXER2,
501 WM8400_ROPRON_SHIFT, 1, 0),
502};
503
504/* ROPMIX */
505static const struct snd_kcontrol_new wm8400_dapm_ropmix_controls[] = {
506SOC_DAPM_SINGLE("ROPMIX Left Mic Bypass Switch", WM8400_LINE_MIXER2,
507 WM8400_RL12ROP_SHIFT, 1, 0),
508SOC_DAPM_SINGLE("ROPMIX Right Mic Bypass Switch", WM8400_LINE_MIXER2,
509 WM8400_RR12ROP_SHIFT, 1, 0),
510SOC_DAPM_SINGLE("ROPMIX Right Mixer PGA Switch", WM8400_LINE_MIXER2,
511 WM8400_RROPGAROP_SHIFT, 1, 0),
512};
513
514/* OUT3MIX */
515static const struct snd_kcontrol_new wm8400_dapm_out3mix_controls[] = {
516SOC_DAPM_SINGLE("OUT3MIX LIN4/RXP Bypass Switch", WM8400_OUT3_4_MIXER,
517 WM8400_LI4O3_SHIFT, 1, 0),
518SOC_DAPM_SINGLE("OUT3MIX Left Out PGA Switch", WM8400_OUT3_4_MIXER,
519 WM8400_LPGAO3_SHIFT, 1, 0),
520};
521
522/* OUT4MIX */
523static const struct snd_kcontrol_new wm8400_dapm_out4mix_controls[] = {
524SOC_DAPM_SINGLE("OUT4MIX Right Out PGA Switch", WM8400_OUT3_4_MIXER,
525 WM8400_RPGAO4_SHIFT, 1, 0),
526SOC_DAPM_SINGLE("OUT4MIX RIN4/RXP Bypass Switch", WM8400_OUT3_4_MIXER,
527 WM8400_RI4O4_SHIFT, 1, 0),
528};
529
530/* SPKMIX */
531static const struct snd_kcontrol_new wm8400_dapm_spkmix_controls[] = {
532SOC_DAPM_SINGLE("SPKMIX LIN2 Bypass Switch", WM8400_SPEAKER_MIXER,
533 WM8400_LI2SPK_SHIFT, 1, 0),
534SOC_DAPM_SINGLE("SPKMIX LADC Bypass Switch", WM8400_SPEAKER_MIXER,
535 WM8400_LB2SPK_SHIFT, 1, 0),
536SOC_DAPM_SINGLE("SPKMIX Left Mixer PGA Switch", WM8400_SPEAKER_MIXER,
537 WM8400_LOPGASPK_SHIFT, 1, 0),
538SOC_DAPM_SINGLE("SPKMIX Left DAC Switch", WM8400_SPEAKER_MIXER,
539 WM8400_LDSPK_SHIFT, 1, 0),
540SOC_DAPM_SINGLE("SPKMIX Right DAC Switch", WM8400_SPEAKER_MIXER,
541 WM8400_RDSPK_SHIFT, 1, 0),
542SOC_DAPM_SINGLE("SPKMIX Right Mixer PGA Switch", WM8400_SPEAKER_MIXER,
543 WM8400_ROPGASPK_SHIFT, 1, 0),
544SOC_DAPM_SINGLE("SPKMIX RADC Bypass Switch", WM8400_SPEAKER_MIXER,
545 WM8400_RL12ROP_SHIFT, 1, 0),
546SOC_DAPM_SINGLE("SPKMIX RIN2 Bypass Switch", WM8400_SPEAKER_MIXER,
547 WM8400_RI2SPK_SHIFT, 1, 0),
548};
549
550static const struct snd_soc_dapm_widget wm8400_dapm_widgets[] = {
551/* Input Side */
552/* Input Lines */
553SND_SOC_DAPM_INPUT("LIN1"),
554SND_SOC_DAPM_INPUT("LIN2"),
555SND_SOC_DAPM_INPUT("LIN3"),
556SND_SOC_DAPM_INPUT("LIN4/RXN"),
557SND_SOC_DAPM_INPUT("RIN3"),
558SND_SOC_DAPM_INPUT("RIN4/RXP"),
559SND_SOC_DAPM_INPUT("RIN1"),
560SND_SOC_DAPM_INPUT("RIN2"),
561SND_SOC_DAPM_INPUT("Internal ADC Source"),
562
563/* DACs */
564SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8400_POWER_MANAGEMENT_2,
565 WM8400_ADCL_ENA_SHIFT, 0),
566SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8400_POWER_MANAGEMENT_2,
567 WM8400_ADCR_ENA_SHIFT, 0),
568
569/* Input PGAs */
570SND_SOC_DAPM_MIXER("LIN12 PGA", WM8400_POWER_MANAGEMENT_2,
571 WM8400_LIN12_ENA_SHIFT,
572 0, &wm8400_dapm_lin12_pga_controls[0],
573 ARRAY_SIZE(wm8400_dapm_lin12_pga_controls)),
574SND_SOC_DAPM_MIXER("LIN34 PGA", WM8400_POWER_MANAGEMENT_2,
575 WM8400_LIN34_ENA_SHIFT,
576 0, &wm8400_dapm_lin34_pga_controls[0],
577 ARRAY_SIZE(wm8400_dapm_lin34_pga_controls)),
578SND_SOC_DAPM_MIXER("RIN12 PGA", WM8400_POWER_MANAGEMENT_2,
579 WM8400_RIN12_ENA_SHIFT,
580 0, &wm8400_dapm_rin12_pga_controls[0],
581 ARRAY_SIZE(wm8400_dapm_rin12_pga_controls)),
582SND_SOC_DAPM_MIXER("RIN34 PGA", WM8400_POWER_MANAGEMENT_2,
583 WM8400_RIN34_ENA_SHIFT,
584 0, &wm8400_dapm_rin34_pga_controls[0],
585 ARRAY_SIZE(wm8400_dapm_rin34_pga_controls)),
586
Mark Brown37c83ed2013-08-31 13:17:08 +0100587SND_SOC_DAPM_SUPPLY("INL", WM8400_POWER_MANAGEMENT_2, WM8400_AINL_ENA_SHIFT,
588 0, NULL, 0),
589SND_SOC_DAPM_SUPPLY("INR", WM8400_POWER_MANAGEMENT_2, WM8400_AINR_ENA_SHIFT,
590 0, NULL, 0),
591
Mark Brownaaf1e172009-03-10 10:55:15 +0000592/* INMIXL */
Mark Brown37c83ed2013-08-31 13:17:08 +0100593SND_SOC_DAPM_MIXER("INMIXL", SND_SOC_NOPM, 0, 0,
Mark Brownaaf1e172009-03-10 10:55:15 +0000594 &wm8400_dapm_inmixl_controls[0],
Mark Brown37c83ed2013-08-31 13:17:08 +0100595 ARRAY_SIZE(wm8400_dapm_inmixl_controls)),
Mark Brownaaf1e172009-03-10 10:55:15 +0000596
597/* AINLMUX */
Mark Brown37c83ed2013-08-31 13:17:08 +0100598SND_SOC_DAPM_MUX("AILNMUX", SND_SOC_NOPM, 0, 0, &wm8400_dapm_ainlmux_controls),
Mark Brownaaf1e172009-03-10 10:55:15 +0000599
600/* INMIXR */
Mark Brown37c83ed2013-08-31 13:17:08 +0100601SND_SOC_DAPM_MIXER("INMIXR", SND_SOC_NOPM, 0, 0,
Mark Brownaaf1e172009-03-10 10:55:15 +0000602 &wm8400_dapm_inmixr_controls[0],
Mark Brown37c83ed2013-08-31 13:17:08 +0100603 ARRAY_SIZE(wm8400_dapm_inmixr_controls)),
Mark Brownaaf1e172009-03-10 10:55:15 +0000604
605/* AINRMUX */
Mark Brown37c83ed2013-08-31 13:17:08 +0100606SND_SOC_DAPM_MUX("AIRNMUX", SND_SOC_NOPM, 0, 0, &wm8400_dapm_ainrmux_controls),
Mark Brownaaf1e172009-03-10 10:55:15 +0000607
608/* Output Side */
609/* DACs */
610SND_SOC_DAPM_DAC("Left DAC", "Left Playback", WM8400_POWER_MANAGEMENT_3,
611 WM8400_DACL_ENA_SHIFT, 0),
612SND_SOC_DAPM_DAC("Right DAC", "Right Playback", WM8400_POWER_MANAGEMENT_3,
613 WM8400_DACR_ENA_SHIFT, 0),
614
615/* LOMIX */
616SND_SOC_DAPM_MIXER_E("LOMIX", WM8400_POWER_MANAGEMENT_3,
617 WM8400_LOMIX_ENA_SHIFT,
618 0, &wm8400_dapm_lomix_controls[0],
619 ARRAY_SIZE(wm8400_dapm_lomix_controls),
620 outmixer_event, SND_SOC_DAPM_PRE_REG),
621
622/* LONMIX */
623SND_SOC_DAPM_MIXER("LONMIX", WM8400_POWER_MANAGEMENT_3, WM8400_LON_ENA_SHIFT,
624 0, &wm8400_dapm_lonmix_controls[0],
625 ARRAY_SIZE(wm8400_dapm_lonmix_controls)),
626
627/* LOPMIX */
628SND_SOC_DAPM_MIXER("LOPMIX", WM8400_POWER_MANAGEMENT_3, WM8400_LOP_ENA_SHIFT,
629 0, &wm8400_dapm_lopmix_controls[0],
630 ARRAY_SIZE(wm8400_dapm_lopmix_controls)),
631
632/* OUT3MIX */
633SND_SOC_DAPM_MIXER("OUT3MIX", WM8400_POWER_MANAGEMENT_1, WM8400_OUT3_ENA_SHIFT,
634 0, &wm8400_dapm_out3mix_controls[0],
635 ARRAY_SIZE(wm8400_dapm_out3mix_controls)),
636
637/* SPKMIX */
638SND_SOC_DAPM_MIXER_E("SPKMIX", WM8400_POWER_MANAGEMENT_1, WM8400_SPK_ENA_SHIFT,
639 0, &wm8400_dapm_spkmix_controls[0],
640 ARRAY_SIZE(wm8400_dapm_spkmix_controls), outmixer_event,
641 SND_SOC_DAPM_PRE_REG),
642
643/* OUT4MIX */
644SND_SOC_DAPM_MIXER("OUT4MIX", WM8400_POWER_MANAGEMENT_1, WM8400_OUT4_ENA_SHIFT,
645 0, &wm8400_dapm_out4mix_controls[0],
646 ARRAY_SIZE(wm8400_dapm_out4mix_controls)),
647
648/* ROPMIX */
649SND_SOC_DAPM_MIXER("ROPMIX", WM8400_POWER_MANAGEMENT_3, WM8400_ROP_ENA_SHIFT,
650 0, &wm8400_dapm_ropmix_controls[0],
651 ARRAY_SIZE(wm8400_dapm_ropmix_controls)),
652
653/* RONMIX */
654SND_SOC_DAPM_MIXER("RONMIX", WM8400_POWER_MANAGEMENT_3, WM8400_RON_ENA_SHIFT,
655 0, &wm8400_dapm_ronmix_controls[0],
656 ARRAY_SIZE(wm8400_dapm_ronmix_controls)),
657
658/* ROMIX */
659SND_SOC_DAPM_MIXER_E("ROMIX", WM8400_POWER_MANAGEMENT_3,
660 WM8400_ROMIX_ENA_SHIFT,
661 0, &wm8400_dapm_romix_controls[0],
662 ARRAY_SIZE(wm8400_dapm_romix_controls),
663 outmixer_event, SND_SOC_DAPM_PRE_REG),
664
665/* LOUT PGA */
666SND_SOC_DAPM_PGA("LOUT PGA", WM8400_POWER_MANAGEMENT_1, WM8400_LOUT_ENA_SHIFT,
667 0, NULL, 0),
668
669/* ROUT PGA */
670SND_SOC_DAPM_PGA("ROUT PGA", WM8400_POWER_MANAGEMENT_1, WM8400_ROUT_ENA_SHIFT,
671 0, NULL, 0),
672
673/* LOPGA */
674SND_SOC_DAPM_PGA("LOPGA", WM8400_POWER_MANAGEMENT_3, WM8400_LOPGA_ENA_SHIFT, 0,
675 NULL, 0),
676
677/* ROPGA */
678SND_SOC_DAPM_PGA("ROPGA", WM8400_POWER_MANAGEMENT_3, WM8400_ROPGA_ENA_SHIFT, 0,
679 NULL, 0),
680
681/* MICBIAS */
Mark Brown3ff51c82011-10-27 09:44:59 +0200682SND_SOC_DAPM_SUPPLY("MICBIAS", WM8400_POWER_MANAGEMENT_1,
683 WM8400_MIC1BIAS_ENA_SHIFT, 0, NULL, 0),
Mark Brownaaf1e172009-03-10 10:55:15 +0000684
685SND_SOC_DAPM_OUTPUT("LON"),
686SND_SOC_DAPM_OUTPUT("LOP"),
687SND_SOC_DAPM_OUTPUT("OUT3"),
688SND_SOC_DAPM_OUTPUT("LOUT"),
689SND_SOC_DAPM_OUTPUT("SPKN"),
690SND_SOC_DAPM_OUTPUT("SPKP"),
691SND_SOC_DAPM_OUTPUT("ROUT"),
692SND_SOC_DAPM_OUTPUT("OUT4"),
693SND_SOC_DAPM_OUTPUT("ROP"),
694SND_SOC_DAPM_OUTPUT("RON"),
695
696SND_SOC_DAPM_OUTPUT("Internal DAC Sink"),
697};
698
Mark Brownb4505ab2011-12-03 11:34:34 +0000699static const struct snd_soc_dapm_route wm8400_dapm_routes[] = {
Mark Brownaaf1e172009-03-10 10:55:15 +0000700 /* Make DACs turn on when playing even if not mixed into any outputs */
701 {"Internal DAC Sink", NULL, "Left DAC"},
702 {"Internal DAC Sink", NULL, "Right DAC"},
703
704 /* Make ADCs turn on when recording
705 * even if not mixed from any inputs */
706 {"Left ADC", NULL, "Internal ADC Source"},
707 {"Right ADC", NULL, "Internal ADC Source"},
708
709 /* Input Side */
710 /* LIN12 PGA */
711 {"LIN12 PGA", "LIN1 Switch", "LIN1"},
712 {"LIN12 PGA", "LIN2 Switch", "LIN2"},
713 /* LIN34 PGA */
714 {"LIN34 PGA", "LIN3 Switch", "LIN3"},
715 {"LIN34 PGA", "LIN4 Switch", "LIN4/RXN"},
716 /* INMIXL */
Mark Brown37c83ed2013-08-31 13:17:08 +0100717 {"INMIXL", NULL, "INL"},
Mark Brownaaf1e172009-03-10 10:55:15 +0000718 {"INMIXL", "Record Left Volume", "LOMIX"},
719 {"INMIXL", "LIN2 Volume", "LIN2"},
720 {"INMIXL", "LINPGA12 Switch", "LIN12 PGA"},
721 {"INMIXL", "LINPGA34 Switch", "LIN34 PGA"},
722 /* AILNMUX */
Mark Brown37c83ed2013-08-31 13:17:08 +0100723 {"AILNMUX", NULL, "INL"},
Mark Brownaaf1e172009-03-10 10:55:15 +0000724 {"AILNMUX", "INMIXL Mix", "INMIXL"},
725 {"AILNMUX", "DIFFINL Mix", "LIN12 PGA"},
726 {"AILNMUX", "DIFFINL Mix", "LIN34 PGA"},
727 {"AILNMUX", "RXVOICE Mix", "LIN4/RXN"},
728 {"AILNMUX", "RXVOICE Mix", "RIN4/RXP"},
729 /* ADC */
730 {"Left ADC", NULL, "AILNMUX"},
731
732 /* RIN12 PGA */
733 {"RIN12 PGA", "RIN1 Switch", "RIN1"},
734 {"RIN12 PGA", "RIN2 Switch", "RIN2"},
735 /* RIN34 PGA */
736 {"RIN34 PGA", "RIN3 Switch", "RIN3"},
737 {"RIN34 PGA", "RIN4 Switch", "RIN4/RXP"},
Mark Brown37c83ed2013-08-31 13:17:08 +0100738 /* INMIXR */
739 {"INMIXR", NULL, "INR"},
Mark Brownaaf1e172009-03-10 10:55:15 +0000740 {"INMIXR", "Record Right Volume", "ROMIX"},
741 {"INMIXR", "RIN2 Volume", "RIN2"},
742 {"INMIXR", "RINPGA12 Switch", "RIN12 PGA"},
743 {"INMIXR", "RINPGA34 Switch", "RIN34 PGA"},
744 /* AIRNMUX */
Mark Brown37c83ed2013-08-31 13:17:08 +0100745 {"AIRNMUX", NULL, "INR"},
Mark Brownaaf1e172009-03-10 10:55:15 +0000746 {"AIRNMUX", "INMIXR Mix", "INMIXR"},
747 {"AIRNMUX", "DIFFINR Mix", "RIN12 PGA"},
748 {"AIRNMUX", "DIFFINR Mix", "RIN34 PGA"},
749 {"AIRNMUX", "RXVOICE Mix", "LIN4/RXN"},
750 {"AIRNMUX", "RXVOICE Mix", "RIN4/RXP"},
751 /* ADC */
752 {"Right ADC", NULL, "AIRNMUX"},
753
754 /* LOMIX */
755 {"LOMIX", "LOMIX RIN3 Bypass Switch", "RIN3"},
756 {"LOMIX", "LOMIX LIN3 Bypass Switch", "LIN3"},
757 {"LOMIX", "LOMIX LIN12 PGA Bypass Switch", "LIN12 PGA"},
758 {"LOMIX", "LOMIX RIN12 PGA Bypass Switch", "RIN12 PGA"},
759 {"LOMIX", "LOMIX Right ADC Bypass Switch", "AIRNMUX"},
760 {"LOMIX", "LOMIX Left ADC Bypass Switch", "AILNMUX"},
761 {"LOMIX", "LOMIX Left DAC Switch", "Left DAC"},
762
763 /* ROMIX */
764 {"ROMIX", "ROMIX RIN3 Bypass Switch", "RIN3"},
765 {"ROMIX", "ROMIX LIN3 Bypass Switch", "LIN3"},
766 {"ROMIX", "ROMIX LIN12 PGA Bypass Switch", "LIN12 PGA"},
767 {"ROMIX", "ROMIX RIN12 PGA Bypass Switch", "RIN12 PGA"},
768 {"ROMIX", "ROMIX Right ADC Bypass Switch", "AIRNMUX"},
769 {"ROMIX", "ROMIX Left ADC Bypass Switch", "AILNMUX"},
770 {"ROMIX", "ROMIX Right DAC Switch", "Right DAC"},
771
772 /* SPKMIX */
773 {"SPKMIX", "SPKMIX LIN2 Bypass Switch", "LIN2"},
774 {"SPKMIX", "SPKMIX RIN2 Bypass Switch", "RIN2"},
775 {"SPKMIX", "SPKMIX LADC Bypass Switch", "AILNMUX"},
776 {"SPKMIX", "SPKMIX RADC Bypass Switch", "AIRNMUX"},
777 {"SPKMIX", "SPKMIX Left Mixer PGA Switch", "LOPGA"},
778 {"SPKMIX", "SPKMIX Right Mixer PGA Switch", "ROPGA"},
779 {"SPKMIX", "SPKMIX Right DAC Switch", "Right DAC"},
780 {"SPKMIX", "SPKMIX Left DAC Switch", "Right DAC"},
781
782 /* LONMIX */
783 {"LONMIX", "LONMIX Left Mixer PGA Switch", "LOPGA"},
784 {"LONMIX", "LONMIX Right Mixer PGA Switch", "ROPGA"},
785 {"LONMIX", "LONMIX Inverted LOP Switch", "LOPMIX"},
786
787 /* LOPMIX */
788 {"LOPMIX", "LOPMIX Right Mic Bypass Switch", "RIN12 PGA"},
789 {"LOPMIX", "LOPMIX Left Mic Bypass Switch", "LIN12 PGA"},
790 {"LOPMIX", "LOPMIX Left Mixer PGA Switch", "LOPGA"},
791
792 /* OUT3MIX */
793 {"OUT3MIX", "OUT3MIX LIN4/RXP Bypass Switch", "LIN4/RXN"},
794 {"OUT3MIX", "OUT3MIX Left Out PGA Switch", "LOPGA"},
795
796 /* OUT4MIX */
797 {"OUT4MIX", "OUT4MIX Right Out PGA Switch", "ROPGA"},
798 {"OUT4MIX", "OUT4MIX RIN4/RXP Bypass Switch", "RIN4/RXP"},
799
800 /* RONMIX */
801 {"RONMIX", "RONMIX Right Mixer PGA Switch", "ROPGA"},
802 {"RONMIX", "RONMIX Left Mixer PGA Switch", "LOPGA"},
803 {"RONMIX", "RONMIX Inverted ROP Switch", "ROPMIX"},
804
805 /* ROPMIX */
806 {"ROPMIX", "ROPMIX Left Mic Bypass Switch", "LIN12 PGA"},
807 {"ROPMIX", "ROPMIX Right Mic Bypass Switch", "RIN12 PGA"},
808 {"ROPMIX", "ROPMIX Right Mixer PGA Switch", "ROPGA"},
809
810 /* Out Mixer PGAs */
811 {"LOPGA", NULL, "LOMIX"},
812 {"ROPGA", NULL, "ROMIX"},
813
814 {"LOUT PGA", NULL, "LOMIX"},
815 {"ROUT PGA", NULL, "ROMIX"},
816
817 /* Output Pins */
818 {"LON", NULL, "LONMIX"},
819 {"LOP", NULL, "LOPMIX"},
820 {"OUT3", NULL, "OUT3MIX"},
821 {"LOUT", NULL, "LOUT PGA"},
822 {"SPKN", NULL, "SPKMIX"},
823 {"ROUT", NULL, "ROUT PGA"},
824 {"OUT4", NULL, "OUT4MIX"},
825 {"ROP", NULL, "ROPMIX"},
826 {"RON", NULL, "RONMIX"},
827};
828
Mark Brownaaf1e172009-03-10 10:55:15 +0000829/*
830 * Clock after FLL and dividers
831 */
832static int wm8400_set_dai_sysclk(struct snd_soc_dai *codec_dai,
833 int clk_id, unsigned int freq, int dir)
834{
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +0000835 struct snd_soc_component *component = codec_dai->component;
836 struct wm8400_priv *wm8400 = snd_soc_component_get_drvdata(component);
Mark Brownaaf1e172009-03-10 10:55:15 +0000837
838 wm8400->sysclk = freq;
839 return 0;
840}
841
Mark Browne8523b62009-03-18 18:28:01 +0000842struct fll_factors {
843 u16 n;
844 u16 k;
845 u16 outdiv;
846 u16 fratio;
847 u16 freq_ref;
848};
849
850#define FIXED_FLL_SIZE ((1 << 16) * 10)
851
852static int fll_factors(struct wm8400_priv *wm8400, struct fll_factors *factors,
853 unsigned int Fref, unsigned int Fout)
854{
855 u64 Kpart;
856 unsigned int K, Nmod, target;
857
858 factors->outdiv = 2;
859 while (Fout * factors->outdiv < 90000000 ||
860 Fout * factors->outdiv > 100000000) {
861 factors->outdiv *= 2;
862 if (factors->outdiv > 32) {
863 dev_err(wm8400->wm8400->dev,
Roel Kluin449bd542009-05-27 17:08:39 -0700864 "Unsupported FLL output frequency %uHz\n",
Mark Browne8523b62009-03-18 18:28:01 +0000865 Fout);
866 return -EINVAL;
867 }
868 }
869 target = Fout * factors->outdiv;
870 factors->outdiv = factors->outdiv >> 2;
871
872 if (Fref < 48000)
873 factors->freq_ref = 1;
874 else
875 factors->freq_ref = 0;
876
877 if (Fref < 1000000)
878 factors->fratio = 9;
879 else
880 factors->fratio = 0;
881
882 /* Ensure we have a fractional part */
883 do {
884 if (Fref < 1000000)
885 factors->fratio--;
886 else
887 factors->fratio++;
888
889 if (factors->fratio < 1 || factors->fratio > 8) {
890 dev_err(wm8400->wm8400->dev,
891 "Unable to calculate FRATIO\n");
892 return -EINVAL;
893 }
894
895 factors->n = target / (Fref * factors->fratio);
896 Nmod = target % (Fref * factors->fratio);
897 } while (Nmod == 0);
898
899 /* Calculate fractional part - scale up so we can round. */
900 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
901
902 do_div(Kpart, (Fref * factors->fratio));
903
904 K = Kpart & 0xFFFFFFFF;
905
906 if ((K % 10) >= 5)
907 K += 5;
908
909 /* Move down to proper range now rounding is done */
910 factors->k = K / 10;
911
912 dev_dbg(wm8400->wm8400->dev,
Roel Kluin449bd542009-05-27 17:08:39 -0700913 "FLL: Fref=%u Fout=%u N=%x K=%x, FRATIO=%x OUTDIV=%x\n",
Mark Browne8523b62009-03-18 18:28:01 +0000914 Fref, Fout,
915 factors->n, factors->k, factors->fratio, factors->outdiv);
916
917 return 0;
918}
919
920static int wm8400_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
Mark Brown85488032009-09-05 18:52:16 +0100921 int source, unsigned int freq_in,
922 unsigned int freq_out)
Mark Browne8523b62009-03-18 18:28:01 +0000923{
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +0000924 struct snd_soc_component *component = codec_dai->component;
925 struct wm8400_priv *wm8400 = snd_soc_component_get_drvdata(component);
Mark Browne8523b62009-03-18 18:28:01 +0000926 struct fll_factors factors;
927 int ret;
928 u16 reg;
929
930 if (freq_in == wm8400->fll_in && freq_out == wm8400->fll_out)
931 return 0;
932
Mark Brown8aa2df52009-07-17 21:53:49 +0100933 if (freq_out) {
Mark Browne8523b62009-03-18 18:28:01 +0000934 ret = fll_factors(wm8400, &factors, freq_in, freq_out);
935 if (ret != 0)
936 return ret;
Mark Brown8aa2df52009-07-17 21:53:49 +0100937 } else {
938 /* Bodge GCC 4.4.0 uninitialised variable warning - it
939 * doesn't seem capable of working out that we exit if
940 * freq_out is 0 before any of the uses. */
941 memset(&factors, 0, sizeof(factors));
Mark Browne8523b62009-03-18 18:28:01 +0000942 }
943
944 wm8400->fll_out = freq_out;
945 wm8400->fll_in = freq_in;
946
947 /* We *must* disable the FLL before any changes */
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +0900948 reg = snd_soc_component_read(component, WM8400_POWER_MANAGEMENT_2);
Mark Browne8523b62009-03-18 18:28:01 +0000949 reg &= ~WM8400_FLL_ENA;
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +0000950 snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_2, reg);
Mark Browne8523b62009-03-18 18:28:01 +0000951
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +0900952 reg = snd_soc_component_read(component, WM8400_FLL_CONTROL_1);
Mark Browne8523b62009-03-18 18:28:01 +0000953 reg &= ~WM8400_FLL_OSC_ENA;
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +0000954 snd_soc_component_write(component, WM8400_FLL_CONTROL_1, reg);
Mark Browne8523b62009-03-18 18:28:01 +0000955
Mark Brown8aa2df52009-07-17 21:53:49 +0100956 if (!freq_out)
Mark Browne8523b62009-03-18 18:28:01 +0000957 return 0;
958
959 reg &= ~(WM8400_FLL_REF_FREQ | WM8400_FLL_FRATIO_MASK);
960 reg |= WM8400_FLL_FRAC | factors.fratio;
961 reg |= factors.freq_ref << WM8400_FLL_REF_FREQ_SHIFT;
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +0000962 snd_soc_component_write(component, WM8400_FLL_CONTROL_1, reg);
Mark Browne8523b62009-03-18 18:28:01 +0000963
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +0000964 snd_soc_component_write(component, WM8400_FLL_CONTROL_2, factors.k);
965 snd_soc_component_write(component, WM8400_FLL_CONTROL_3, factors.n);
Mark Browne8523b62009-03-18 18:28:01 +0000966
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +0900967 reg = snd_soc_component_read(component, WM8400_FLL_CONTROL_4);
Axel Lin1d533de2011-10-22 22:48:27 +0800968 reg &= ~WM8400_FLL_OUTDIV_MASK;
Mark Browne8523b62009-03-18 18:28:01 +0000969 reg |= factors.outdiv;
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +0000970 snd_soc_component_write(component, WM8400_FLL_CONTROL_4, reg);
Mark Browne8523b62009-03-18 18:28:01 +0000971
972 return 0;
973}
974
Mark Brownaaf1e172009-03-10 10:55:15 +0000975/*
976 * Sets ADC and Voice DAC format.
977 */
978static int wm8400_set_dai_fmt(struct snd_soc_dai *codec_dai,
979 unsigned int fmt)
980{
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +0000981 struct snd_soc_component *component = codec_dai->component;
Mark Brownaaf1e172009-03-10 10:55:15 +0000982 u16 audio1, audio3;
983
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +0900984 audio1 = snd_soc_component_read(component, WM8400_AUDIO_INTERFACE_1);
985 audio3 = snd_soc_component_read(component, WM8400_AUDIO_INTERFACE_3);
Mark Brownaaf1e172009-03-10 10:55:15 +0000986
987 /* set master/slave audio interface */
988 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
989 case SND_SOC_DAIFMT_CBS_CFS:
990 audio3 &= ~WM8400_AIF_MSTR1;
991 break;
992 case SND_SOC_DAIFMT_CBM_CFM:
993 audio3 |= WM8400_AIF_MSTR1;
994 break;
995 default:
996 return -EINVAL;
997 }
998
999 audio1 &= ~WM8400_AIF_FMT_MASK;
1000
1001 /* interface format */
1002 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1003 case SND_SOC_DAIFMT_I2S:
1004 audio1 |= WM8400_AIF_FMT_I2S;
1005 audio1 &= ~WM8400_AIF_LRCLK_INV;
1006 break;
1007 case SND_SOC_DAIFMT_RIGHT_J:
1008 audio1 |= WM8400_AIF_FMT_RIGHTJ;
1009 audio1 &= ~WM8400_AIF_LRCLK_INV;
1010 break;
1011 case SND_SOC_DAIFMT_LEFT_J:
1012 audio1 |= WM8400_AIF_FMT_LEFTJ;
1013 audio1 &= ~WM8400_AIF_LRCLK_INV;
1014 break;
1015 case SND_SOC_DAIFMT_DSP_A:
1016 audio1 |= WM8400_AIF_FMT_DSP;
1017 audio1 &= ~WM8400_AIF_LRCLK_INV;
1018 break;
1019 case SND_SOC_DAIFMT_DSP_B:
1020 audio1 |= WM8400_AIF_FMT_DSP | WM8400_AIF_LRCLK_INV;
1021 break;
1022 default:
1023 return -EINVAL;
1024 }
1025
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001026 snd_soc_component_write(component, WM8400_AUDIO_INTERFACE_1, audio1);
1027 snd_soc_component_write(component, WM8400_AUDIO_INTERFACE_3, audio3);
Mark Brownaaf1e172009-03-10 10:55:15 +00001028 return 0;
1029}
1030
1031static int wm8400_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
1032 int div_id, int div)
1033{
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001034 struct snd_soc_component *component = codec_dai->component;
Mark Brownaaf1e172009-03-10 10:55:15 +00001035 u16 reg;
1036
1037 switch (div_id) {
1038 case WM8400_MCLK_DIV:
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +09001039 reg = snd_soc_component_read(component, WM8400_CLOCKING_2) &
Mark Brownaaf1e172009-03-10 10:55:15 +00001040 ~WM8400_MCLK_DIV_MASK;
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001041 snd_soc_component_write(component, WM8400_CLOCKING_2, reg | div);
Mark Brownaaf1e172009-03-10 10:55:15 +00001042 break;
1043 case WM8400_DACCLK_DIV:
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +09001044 reg = snd_soc_component_read(component, WM8400_CLOCKING_2) &
Mark Brownaaf1e172009-03-10 10:55:15 +00001045 ~WM8400_DAC_CLKDIV_MASK;
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001046 snd_soc_component_write(component, WM8400_CLOCKING_2, reg | div);
Mark Brownaaf1e172009-03-10 10:55:15 +00001047 break;
1048 case WM8400_ADCCLK_DIV:
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +09001049 reg = snd_soc_component_read(component, WM8400_CLOCKING_2) &
Mark Brownaaf1e172009-03-10 10:55:15 +00001050 ~WM8400_ADC_CLKDIV_MASK;
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001051 snd_soc_component_write(component, WM8400_CLOCKING_2, reg | div);
Mark Brownaaf1e172009-03-10 10:55:15 +00001052 break;
1053 case WM8400_BCLK_DIV:
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +09001054 reg = snd_soc_component_read(component, WM8400_CLOCKING_1) &
Mark Brownaaf1e172009-03-10 10:55:15 +00001055 ~WM8400_BCLK_DIV_MASK;
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001056 snd_soc_component_write(component, WM8400_CLOCKING_1, reg | div);
Mark Brownaaf1e172009-03-10 10:55:15 +00001057 break;
1058 default:
1059 return -EINVAL;
1060 }
1061
1062 return 0;
1063}
1064
1065/*
1066 * Set PCM DAI bit size and sample rate.
1067 */
1068static int wm8400_hw_params(struct snd_pcm_substream *substream,
1069 struct snd_pcm_hw_params *params,
1070 struct snd_soc_dai *dai)
1071{
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001072 struct snd_soc_component *component = dai->component;
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +09001073 u16 audio1 = snd_soc_component_read(component, WM8400_AUDIO_INTERFACE_1);
Mark Brownaaf1e172009-03-10 10:55:15 +00001074
1075 audio1 &= ~WM8400_AIF_WL_MASK;
1076 /* bit size */
Mark Brown6fe12c22014-07-31 12:49:53 +01001077 switch (params_width(params)) {
1078 case 16:
Mark Brownaaf1e172009-03-10 10:55:15 +00001079 break;
Mark Brown6fe12c22014-07-31 12:49:53 +01001080 case 20:
Mark Brownaaf1e172009-03-10 10:55:15 +00001081 audio1 |= WM8400_AIF_WL_20BITS;
1082 break;
Mark Brown6fe12c22014-07-31 12:49:53 +01001083 case 24:
Mark Brownaaf1e172009-03-10 10:55:15 +00001084 audio1 |= WM8400_AIF_WL_24BITS;
1085 break;
Mark Brown6fe12c22014-07-31 12:49:53 +01001086 case 32:
Mark Brownaaf1e172009-03-10 10:55:15 +00001087 audio1 |= WM8400_AIF_WL_32BITS;
1088 break;
1089 }
1090
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001091 snd_soc_component_write(component, WM8400_AUDIO_INTERFACE_1, audio1);
Mark Brownaaf1e172009-03-10 10:55:15 +00001092 return 0;
1093}
1094
Kuninori Morimoto26d3c162020-07-09 10:56:53 +09001095static int wm8400_mute(struct snd_soc_dai *dai, int mute, int direction)
Mark Brownaaf1e172009-03-10 10:55:15 +00001096{
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001097 struct snd_soc_component *component = dai->component;
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +09001098 u16 val = snd_soc_component_read(component, WM8400_DAC_CTRL) & ~WM8400_DAC_MUTE;
Mark Brownaaf1e172009-03-10 10:55:15 +00001099
1100 if (mute)
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001101 snd_soc_component_write(component, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE);
Mark Brownaaf1e172009-03-10 10:55:15 +00001102 else
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001103 snd_soc_component_write(component, WM8400_DAC_CTRL, val);
Mark Brownaaf1e172009-03-10 10:55:15 +00001104
1105 return 0;
1106}
1107
1108/* TODO: set bias for best performance at standby */
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001109static int wm8400_set_bias_level(struct snd_soc_component *component,
Mark Brownaaf1e172009-03-10 10:55:15 +00001110 enum snd_soc_bias_level level)
1111{
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001112 struct wm8400_priv *wm8400 = snd_soc_component_get_drvdata(component);
Mark Brownaaf1e172009-03-10 10:55:15 +00001113 u16 val;
1114 int ret;
1115
1116 switch (level) {
1117 case SND_SOC_BIAS_ON:
1118 break;
1119
1120 case SND_SOC_BIAS_PREPARE:
1121 /* VMID=2*50k */
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +09001122 val = snd_soc_component_read(component, WM8400_POWER_MANAGEMENT_1) &
Mark Brownaaf1e172009-03-10 10:55:15 +00001123 ~WM8400_VMID_MODE_MASK;
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001124 snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, val | 0x2);
Mark Brownaaf1e172009-03-10 10:55:15 +00001125 break;
1126
1127 case SND_SOC_BIAS_STANDBY:
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001128 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
Mark Brownaaf1e172009-03-10 10:55:15 +00001129 ret = regulator_bulk_enable(ARRAY_SIZE(power),
1130 &power[0]);
1131 if (ret != 0) {
1132 dev_err(wm8400->wm8400->dev,
1133 "Failed to enable regulators: %d\n",
1134 ret);
1135 return ret;
1136 }
1137
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001138 snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1,
Mark Brownaaf1e172009-03-10 10:55:15 +00001139 WM8400_CODEC_ENA | WM8400_SYSCLK_ENA);
1140
Mark Brownaaf1e172009-03-10 10:55:15 +00001141 /* Enable POBCTRL, SOFT_ST, VMIDTOG and BUFDCOPEN */
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001142 snd_soc_component_write(component, WM8400_ANTIPOP2, WM8400_SOFTST |
Mark Brownaaf1e172009-03-10 10:55:15 +00001143 WM8400_BUFDCOPEN | WM8400_POBCTRL);
1144
Mark Browne3598f62009-03-18 15:19:10 +00001145 msleep(50);
Mark Brownaaf1e172009-03-10 10:55:15 +00001146
1147 /* Enable VREF & VMID at 2x50k */
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +09001148 val = snd_soc_component_read(component, WM8400_POWER_MANAGEMENT_1);
Mark Brownaaf1e172009-03-10 10:55:15 +00001149 val |= 0x2 | WM8400_VREF_ENA;
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001150 snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, val);
Mark Brownaaf1e172009-03-10 10:55:15 +00001151
Mark Brownaaf1e172009-03-10 10:55:15 +00001152 /* Enable BUFIOEN */
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001153 snd_soc_component_write(component, WM8400_ANTIPOP2, WM8400_SOFTST |
Mark Brownaaf1e172009-03-10 10:55:15 +00001154 WM8400_BUFDCOPEN | WM8400_POBCTRL |
1155 WM8400_BUFIOEN);
1156
Mark Brownaaf1e172009-03-10 10:55:15 +00001157 /* disable POBCTRL, SOFT_ST and BUFDCOPEN */
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001158 snd_soc_component_write(component, WM8400_ANTIPOP2, WM8400_BUFIOEN);
Mark Brownaaf1e172009-03-10 10:55:15 +00001159 }
1160
1161 /* VMID=2*300k */
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +09001162 val = snd_soc_component_read(component, WM8400_POWER_MANAGEMENT_1) &
Mark Brownaaf1e172009-03-10 10:55:15 +00001163 ~WM8400_VMID_MODE_MASK;
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001164 snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, val | 0x4);
Mark Brownaaf1e172009-03-10 10:55:15 +00001165 break;
1166
1167 case SND_SOC_BIAS_OFF:
1168 /* Enable POBCTRL and SOFT_ST */
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001169 snd_soc_component_write(component, WM8400_ANTIPOP2, WM8400_SOFTST |
Mark Brownaaf1e172009-03-10 10:55:15 +00001170 WM8400_POBCTRL | WM8400_BUFIOEN);
1171
1172 /* Enable POBCTRL, SOFT_ST and BUFDCOPEN */
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001173 snd_soc_component_write(component, WM8400_ANTIPOP2, WM8400_SOFTST |
Mark Brownaaf1e172009-03-10 10:55:15 +00001174 WM8400_BUFDCOPEN | WM8400_POBCTRL |
1175 WM8400_BUFIOEN);
1176
1177 /* mute DAC */
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +09001178 val = snd_soc_component_read(component, WM8400_DAC_CTRL);
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001179 snd_soc_component_write(component, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE);
Mark Brownaaf1e172009-03-10 10:55:15 +00001180
1181 /* Enable any disabled outputs */
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +09001182 val = snd_soc_component_read(component, WM8400_POWER_MANAGEMENT_1);
Mark Brownaaf1e172009-03-10 10:55:15 +00001183 val |= WM8400_SPK_ENA | WM8400_OUT3_ENA |
1184 WM8400_OUT4_ENA | WM8400_LOUT_ENA |
1185 WM8400_ROUT_ENA;
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001186 snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, val);
Mark Brownaaf1e172009-03-10 10:55:15 +00001187
1188 /* Disable VMID */
1189 val &= ~WM8400_VMID_MODE_MASK;
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001190 snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, val);
Mark Brownaaf1e172009-03-10 10:55:15 +00001191
1192 msleep(300);
1193
1194 /* Enable all output discharge bits */
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001195 snd_soc_component_write(component, WM8400_ANTIPOP1, WM8400_DIS_LLINE |
Mark Brownaaf1e172009-03-10 10:55:15 +00001196 WM8400_DIS_RLINE | WM8400_DIS_OUT3 |
1197 WM8400_DIS_OUT4 | WM8400_DIS_LOUT |
1198 WM8400_DIS_ROUT);
1199
1200 /* Disable VREF */
1201 val &= ~WM8400_VREF_ENA;
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001202 snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, val);
Mark Brownaaf1e172009-03-10 10:55:15 +00001203
1204 /* disable POBCTRL, SOFT_ST and BUFDCOPEN */
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001205 snd_soc_component_write(component, WM8400_ANTIPOP2, 0x0);
Mark Brownaaf1e172009-03-10 10:55:15 +00001206
1207 ret = regulator_bulk_disable(ARRAY_SIZE(power),
1208 &power[0]);
1209 if (ret != 0)
1210 return ret;
1211
1212 break;
1213 }
1214
Mark Brownaaf1e172009-03-10 10:55:15 +00001215 return 0;
1216}
1217
1218#define WM8400_RATES SNDRV_PCM_RATE_8000_96000
1219
1220#define WM8400_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1221 SNDRV_PCM_FMTBIT_S24_LE)
1222
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01001223static const struct snd_soc_dai_ops wm8400_dai_ops = {
Mark Brown65ec1cd2009-03-11 16:51:31 +00001224 .hw_params = wm8400_hw_params,
Kuninori Morimoto26d3c162020-07-09 10:56:53 +09001225 .mute_stream = wm8400_mute,
Mark Brown65ec1cd2009-03-11 16:51:31 +00001226 .set_fmt = wm8400_set_dai_fmt,
1227 .set_clkdiv = wm8400_set_dai_clkdiv,
1228 .set_sysclk = wm8400_set_dai_sysclk,
Mark Browne8523b62009-03-18 18:28:01 +00001229 .set_pll = wm8400_set_dai_pll,
Kuninori Morimoto26d3c162020-07-09 10:56:53 +09001230 .no_capture_mute = 1,
Mark Brown65ec1cd2009-03-11 16:51:31 +00001231};
1232
Mark Brownaaf1e172009-03-10 10:55:15 +00001233/*
1234 * The WM8400 supports 2 different and mutually exclusive DAI
1235 * configurations.
1236 *
1237 * 1. ADC/DAC on Primary Interface
1238 * 2. ADC on Primary Interface/DAC on secondary
1239 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001240static struct snd_soc_dai_driver wm8400_dai = {
Mark Brownaaf1e172009-03-10 10:55:15 +00001241/* ADC/DAC on primary */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001242 .name = "wm8400-hifi",
Mark Brownaaf1e172009-03-10 10:55:15 +00001243 .playback = {
1244 .stream_name = "Playback",
1245 .channels_min = 1,
1246 .channels_max = 2,
1247 .rates = WM8400_RATES,
1248 .formats = WM8400_FORMATS,
1249 },
1250 .capture = {
1251 .stream_name = "Capture",
1252 .channels_min = 1,
1253 .channels_max = 2,
1254 .rates = WM8400_RATES,
1255 .formats = WM8400_FORMATS,
1256 },
Mark Brown65ec1cd2009-03-11 16:51:31 +00001257 .ops = &wm8400_dai_ops,
Mark Brownaaf1e172009-03-10 10:55:15 +00001258};
Mark Brownaaf1e172009-03-10 10:55:15 +00001259
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001260static int wm8400_component_probe(struct snd_soc_component *component)
Mark Brownaaf1e172009-03-10 10:55:15 +00001261{
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001262 struct wm8400 *wm8400 = dev_get_platdata(component->dev);
Mark Brownaaf1e172009-03-10 10:55:15 +00001263 struct wm8400_priv *priv;
1264 int ret;
1265 u16 reg;
Mark Brownaaf1e172009-03-10 10:55:15 +00001266
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001267 priv = devm_kzalloc(component->dev, sizeof(struct wm8400_priv),
Mark Brownb903c0e2011-12-03 11:41:27 +00001268 GFP_KERNEL);
Mark Brownaaf1e172009-03-10 10:55:15 +00001269 if (priv == NULL)
1270 return -ENOMEM;
1271
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001272 snd_soc_component_init_regmap(component, wm8400->regmap);
1273 snd_soc_component_set_drvdata(component, priv);
Mark Brownb8cc4152013-08-31 13:21:12 +01001274 priv->wm8400 = wm8400;
Mark Brownaaf1e172009-03-10 10:55:15 +00001275
Sachin Kamat95a5b242012-11-26 17:19:36 +05301276 ret = devm_regulator_bulk_get(wm8400->dev,
Mark Brownaaf1e172009-03-10 10:55:15 +00001277 ARRAY_SIZE(power), &power[0]);
1278 if (ret != 0) {
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001279 dev_err(component->dev, "Failed to get regulators: %d\n", ret);
Mark Brownb903c0e2011-12-03 11:41:27 +00001280 return ret;
Mark Brownaaf1e172009-03-10 10:55:15 +00001281 }
1282
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001283 wm8400_component_reset(component);
Mark Brownaaf1e172009-03-10 10:55:15 +00001284
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +09001285 reg = snd_soc_component_read(component, WM8400_POWER_MANAGEMENT_1);
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001286 snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, reg | WM8400_CODEC_ENA);
Mark Brownaaf1e172009-03-10 10:55:15 +00001287
1288 /* Latch volume update bits */
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +09001289 reg = snd_soc_component_read(component, WM8400_LEFT_LINE_INPUT_1_2_VOLUME);
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001290 snd_soc_component_write(component, WM8400_LEFT_LINE_INPUT_1_2_VOLUME,
Mark Brownaaf1e172009-03-10 10:55:15 +00001291 reg & WM8400_IPVU);
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +09001292 reg = snd_soc_component_read(component, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME);
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001293 snd_soc_component_write(component, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME,
Mark Brownaaf1e172009-03-10 10:55:15 +00001294 reg & WM8400_IPVU);
1295
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001296 snd_soc_component_write(component, WM8400_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8));
1297 snd_soc_component_write(component, WM8400_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8));
Mark Brownaaf1e172009-03-10 10:55:15 +00001298
Mark Brownaaf1e172009-03-10 10:55:15 +00001299 return 0;
Mark Brownaaf1e172009-03-10 10:55:15 +00001300}
1301
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001302static void wm8400_component_remove(struct snd_soc_component *component)
Mark Brownaaf1e172009-03-10 10:55:15 +00001303{
Mark Brownaaf1e172009-03-10 10:55:15 +00001304 u16 reg;
1305
Kuninori Morimoto6d75dfc2020-06-16 14:21:29 +09001306 reg = snd_soc_component_read(component, WM8400_POWER_MANAGEMENT_1);
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001307 snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1,
Mark Brownaaf1e172009-03-10 10:55:15 +00001308 reg & (~WM8400_CODEC_ENA));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001309}
Mark Brownaaf1e172009-03-10 10:55:15 +00001310
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001311static const struct snd_soc_component_driver soc_component_dev_wm8400 = {
1312 .probe = wm8400_component_probe,
1313 .remove = wm8400_component_remove,
1314 .set_bias_level = wm8400_set_bias_level,
1315 .controls = wm8400_snd_controls,
1316 .num_controls = ARRAY_SIZE(wm8400_snd_controls),
1317 .dapm_widgets = wm8400_dapm_widgets,
1318 .num_dapm_widgets = ARRAY_SIZE(wm8400_dapm_widgets),
1319 .dapm_routes = wm8400_dapm_routes,
1320 .num_dapm_routes = ARRAY_SIZE(wm8400_dapm_routes),
1321 .suspend_bias_off = 1,
1322 .idle_bias_on = 1,
1323 .use_pmdown_time = 1,
1324 .endianness = 1,
1325 .non_legacy_dai_naming = 1,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001326};
1327
Bill Pemberton7a79e942012-12-07 09:26:37 -05001328static int wm8400_probe(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001329{
weiyongjun (A)822e70a2018-03-16 07:32:07 +00001330 return devm_snd_soc_register_component(&pdev->dev,
Kuninori Morimoto10dc44c2018-01-29 03:00:04 +00001331 &soc_component_dev_wm8400,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001332 &wm8400_dai, 1);
1333}
1334
Mark Brownaaf1e172009-03-10 10:55:15 +00001335static struct platform_driver wm8400_codec_driver = {
1336 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001337 .name = "wm8400-codec",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001338 },
1339 .probe = wm8400_probe,
Mark Brownaaf1e172009-03-10 10:55:15 +00001340};
1341
Mark Brown5bbcc3c2011-11-23 22:52:08 +00001342module_platform_driver(wm8400_codec_driver);
Mark Brownaaf1e172009-03-10 10:55:15 +00001343
1344MODULE_DESCRIPTION("ASoC WM8400 driver");
1345MODULE_AUTHOR("Mark Brown");
1346MODULE_LICENSE("GPL");
1347MODULE_ALIAS("platform:wm8400-codec");