1/*
2 * Copyright (C) ST-Ericsson SA 2012
3 *
4 * Author: Ola Lilja <ola.o.lilja@stericsson.com>,
5 * Kristoffer Karlsson <kristoffer.karlsson@stericsson.com>,
6 * Roger Nilsson <roger.xr.nilsson@stericsson.com>,
7 * for ST-Ericsson.
8 *
9 * Based on the early work done by:
10 * Mikko J. Lehto <mikko.lehto@symbio.com>,
11 * Mikko Sarmanne <mikko.sarmanne@symbio.com>,
12 * Jarmo K. Kuronen <jarmo.kuronen@symbio.com>,
13 * for ST-Ericsson.
14 *
15 * License terms:
16 *
17 * This program is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License version 2 as published
19 * by the Free Software Foundation.
20 */
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/device.h>
25#include <linux/slab.h>
26#include <linux/moduleparam.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/pm.h>
30#include <linux/platform_device.h>
31#include <linux/mutex.h>
32#include <linux/mfd/abx500/ab8500.h>
33#include <linux/mfd/abx500.h>
34#include <linux/mfd/abx500/ab8500-sysctrl.h>
35#include <linux/mfd/abx500/ab8500-codec.h>
36#include <linux/regulator/consumer.h>
37#include <linux/of.h>
38
39#include <sound/core.h>
40#include <sound/pcm.h>
41#include <sound/pcm_params.h>
42#include <sound/initval.h>
43#include <sound/soc.h>
44#include <sound/soc-dapm.h>
45#include <sound/tlv.h>
46
47#include "ab8500-codec.h"
48
49/* Macrocell value definitions */
50#define CLK_32K_OUT2_DISABLE 0x01
51#define INACTIVE_RESET_AUDIO 0x02
52#define ENABLE_AUDIO_CLK_TO_AUDIO_BLK 0x10
53#define ENABLE_VINTCORE12_SUPPLY 0x04
54#define GPIO27_DIR_OUTPUT 0x04
55#define GPIO29_DIR_OUTPUT 0x10
56#define GPIO31_DIR_OUTPUT 0x40
57
58/* Macrocell register definitions */
59#define AB8500_GPIO_DIR4_REG 0x13 /* Bank AB8500_MISC */
60
61/* Nr of FIR/IIR-coeff banks in ANC-block */
62#define AB8500_NR_OF_ANC_COEFF_BANKS 2
63
64/* Minimum duration to keep ANC IIR Init bit high or
65low before proceeding with the configuration sequence */
66#define AB8500_ANC_SM_DELAY 2000
67
68#define AB8500_FILTER_CONTROL(xname, xcount, xmin, xmax) \
69{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
70 .info = filter_control_info, \
71 .get = filter_control_get, .put = filter_control_put, \
72 .private_value = (unsigned long)&(struct filter_control) \
73 {.count = xcount, .min = xmin, .max = xmax} }
74
75struct filter_control {
76 long min, max;
77 unsigned int count;
78 long value[128];
79};
80
81/* Sidetone states */
82static const char * const enum_sid_state[] = {
83 "Unconfigured",
84 "Apply FIR",
85 "FIR is configured",
86};
87enum sid_state {
88 SID_UNCONFIGURED = 0,
89 SID_APPLY_FIR = 1,
90 SID_FIR_CONFIGURED = 2,
91};
92
93static const char * const enum_anc_state[] = {
94 "Unconfigured",
95 "Apply FIR and IIR",
96 "FIR and IIR are configured",
97 "Apply FIR",
98 "FIR is configured",
99 "Apply IIR",
100 "IIR is configured"
101};
102enum anc_state {
103 ANC_UNCONFIGURED = 0,
104 ANC_APPLY_FIR_IIR = 1,
105 ANC_FIR_IIR_CONFIGURED = 2,
106 ANC_APPLY_FIR = 3,
107 ANC_FIR_CONFIGURED = 4,
108 ANC_APPLY_IIR = 5,
109 ANC_IIR_CONFIGURED = 6
110};
111
112/* Analog microphones */
113enum amic_idx {
114 AMIC_IDX_1A,
115 AMIC_IDX_1B,
116 AMIC_IDX_2
117};
118
119struct ab8500_codec_drvdata_dbg {
120 struct regulator *vaud;
121 struct regulator *vamic1;
122 struct regulator *vamic2;
123 struct regulator *vdmic;
124};
125
126/* Private data for AB8500 device-driver */
127struct ab8500_codec_drvdata {
128 struct regmap *regmap;
129 struct mutex ctrl_lock;
130
131 /* Sidetone */
132 long *sid_fir_values;
133 enum sid_state sid_status;
134
135 /* ANC */
136 long *anc_fir_values;
137 long *anc_iir_values;
138 enum anc_state anc_status;
139};
140
141static inline const char *amic_micbias_str(enum amic_micbias micbias)
142{
143 switch (micbias) {
144 case AMIC_MICBIAS_VAMIC1:
145 return "VAMIC1";
146 case AMIC_MICBIAS_VAMIC2:
147 return "VAMIC2";
148 default:
149 return "Unknown";
150 }
151}
152
153static inline const char *amic_type_str(enum amic_type type)
154{
155 switch (type) {
156 case AMIC_TYPE_DIFFERENTIAL:
157 return "DIFFERENTIAL";
158 case AMIC_TYPE_SINGLE_ENDED:
159 return "SINGLE ENDED";
160 default:
161 return "Unknown";
162 }
163}
164
165/*
166 * Read'n'write functions
167 */
168
169/* Read a register from the audio-bank of AB8500 */
170static int ab8500_codec_read_reg(void *context, unsigned int reg,
171 unsigned int *value)
172{
173 struct device *dev = context;
174 int status;
175
176 u8 value8;
177 status = abx500_get_register_interruptible(dev, AB8500_AUDIO,
178 reg, &value8);
179 *value = (unsigned int)value8;
180
181 return status;
182}
183
184/* Write to a register in the audio-bank of AB8500 */
185static int ab8500_codec_write_reg(void *context, unsigned int reg,
186 unsigned int value)
187{
188 struct device *dev = context;
189
190 return abx500_set_register_interruptible(dev, AB8500_AUDIO,
191 reg, value);
192}
193
194static const struct regmap_config ab8500_codec_regmap = {
195 .reg_read = ab8500_codec_read_reg,
196 .reg_write = ab8500_codec_write_reg,
197};
198
199/*
200 * Controls - DAPM
201 */
202
203/* Earpiece */
204
205/* Earpiece source selector */
206static const char * const enum_ear_lineout_source[] = {"Headset Left",
207 "Speaker Left"};
208static SOC_ENUM_SINGLE_DECL(dapm_enum_ear_lineout_source, AB8500_DMICFILTCONF,
209 AB8500_DMICFILTCONF_DA3TOEAR, enum_ear_lineout_source);
210static const struct snd_kcontrol_new dapm_ear_lineout_source =
211 SOC_DAPM_ENUM("Earpiece or LineOut Mono Source",
212 dapm_enum_ear_lineout_source);
213
214/* LineOut */
215
216/* LineOut source selector */
217static const char * const enum_lineout_source[] = {"Mono Path", "Stereo Path"};
218static SOC_ENUM_DOUBLE_DECL(dapm_enum_lineout_source, AB8500_ANACONF5,
219 AB8500_ANACONF5_HSLDACTOLOL,
220 AB8500_ANACONF5_HSRDACTOLOR, enum_lineout_source);
221static const struct snd_kcontrol_new dapm_lineout_source[] = {
222 SOC_DAPM_ENUM("LineOut Source", dapm_enum_lineout_source),
223};
224
225/* Handsfree */
226
227/* Speaker Left - ANC selector */
228static const char * const enum_HFx_sel[] = {"Audio Path", "ANC"};
229static SOC_ENUM_SINGLE_DECL(dapm_enum_HFl_sel, AB8500_DIGMULTCONF2,
230 AB8500_DIGMULTCONF2_HFLSEL, enum_HFx_sel);
231static const struct snd_kcontrol_new dapm_HFl_select[] = {
232 SOC_DAPM_ENUM("Speaker Left Source", dapm_enum_HFl_sel),
233};
234
235/* Speaker Right - ANC selector */
236static SOC_ENUM_SINGLE_DECL(dapm_enum_HFr_sel, AB8500_DIGMULTCONF2,
237 AB8500_DIGMULTCONF2_HFRSEL, enum_HFx_sel);
238static const struct snd_kcontrol_new dapm_HFr_select[] = {
239 SOC_DAPM_ENUM("Speaker Right Source", dapm_enum_HFr_sel),
240};
241
242/* Mic 1 */
243
244/* Mic 1 - Mic 1a or 1b selector */
245static const char * const enum_mic1ab_sel[] = {"Mic 1b", "Mic 1a"};
246static SOC_ENUM_SINGLE_DECL(dapm_enum_mic1ab_sel, AB8500_ANACONF3,
247 AB8500_ANACONF3_MIC1SEL, enum_mic1ab_sel);
248static const struct snd_kcontrol_new dapm_mic1ab_mux[] = {
249 SOC_DAPM_ENUM("Mic 1a or 1b Select", dapm_enum_mic1ab_sel),
250};
251
252/* Mic 1 - AD3 - Mic 1 or DMic 3 selector */
253static const char * const enum_ad3_sel[] = {"Mic 1", "DMic 3"};
254static SOC_ENUM_SINGLE_DECL(dapm_enum_ad3_sel, AB8500_DIGMULTCONF1,
255 AB8500_DIGMULTCONF1_AD3SEL, enum_ad3_sel);
256static const struct snd_kcontrol_new dapm_ad3_select[] = {
257 SOC_DAPM_ENUM("AD3 Source Select", dapm_enum_ad3_sel),
258};
259
260/* Mic 1 - AD6 - Mic 1 or DMic 6 selector */
261static const char * const enum_ad6_sel[] = {"Mic 1", "DMic 6"};
262static SOC_ENUM_SINGLE_DECL(dapm_enum_ad6_sel, AB8500_DIGMULTCONF1,
263 AB8500_DIGMULTCONF1_AD6SEL, enum_ad6_sel);
264static const struct snd_kcontrol_new dapm_ad6_select[] = {
265 SOC_DAPM_ENUM("AD6 Source Select", dapm_enum_ad6_sel),
266};
267
268/* Mic 2 */
269
270/* Mic 2 - AD5 - Mic 2 or DMic 5 selector */
271static const char * const enum_ad5_sel[] = {"Mic 2", "DMic 5"};
272static SOC_ENUM_SINGLE_DECL(dapm_enum_ad5_sel, AB8500_DIGMULTCONF1,
273 AB8500_DIGMULTCONF1_AD5SEL, enum_ad5_sel);
274static const struct snd_kcontrol_new dapm_ad5_select[] = {
275 SOC_DAPM_ENUM("AD5 Source Select", dapm_enum_ad5_sel),
276};
277
278/* LineIn */
279
280/* LineIn left - AD1 - LineIn Left or DMic 1 selector */
281static const char * const enum_ad1_sel[] = {"LineIn Left", "DMic 1"};
282static SOC_ENUM_SINGLE_DECL(dapm_enum_ad1_sel, AB8500_DIGMULTCONF1,
283 AB8500_DIGMULTCONF1_AD1SEL, enum_ad1_sel);
284static const struct snd_kcontrol_new dapm_ad1_select[] = {
285 SOC_DAPM_ENUM("AD1 Source Select", dapm_enum_ad1_sel),
286};
287
288/* LineIn right - Mic 2 or LineIn Right selector */
289static const char * const enum_mic2lr_sel[] = {"Mic 2", "LineIn Right"};
290static SOC_ENUM_SINGLE_DECL(dapm_enum_mic2lr_sel, AB8500_ANACONF3,
291 AB8500_ANACONF3_LINRSEL, enum_mic2lr_sel);
292static const struct snd_kcontrol_new dapm_mic2lr_select[] = {
293 SOC_DAPM_ENUM("Mic 2 or LINR Select", dapm_enum_mic2lr_sel),
294};
295
296/* LineIn right - AD2 - LineIn Right or DMic2 selector */
297static const char * const enum_ad2_sel[] = {"LineIn Right", "DMic 2"};
298static SOC_ENUM_SINGLE_DECL(dapm_enum_ad2_sel, AB8500_DIGMULTCONF1,
299 AB8500_DIGMULTCONF1_AD2SEL, enum_ad2_sel);
300static const struct snd_kcontrol_new dapm_ad2_select[] = {
301 SOC_DAPM_ENUM("AD2 Source Select", dapm_enum_ad2_sel),
302};
303
304
305/* ANC */
306
307static const char * const enum_anc_in_sel[] = {"Mic 1 / DMic 6",
308 "Mic 2 / DMic 5"};
309static SOC_ENUM_SINGLE_DECL(dapm_enum_anc_in_sel, AB8500_DMICFILTCONF,
310 AB8500_DMICFILTCONF_ANCINSEL, enum_anc_in_sel);
311static const struct snd_kcontrol_new dapm_anc_in_select[] = {
312 SOC_DAPM_ENUM("ANC Source", dapm_enum_anc_in_sel),
313};
314
315/* ANC - Enable/Disable */
316static const struct snd_kcontrol_new dapm_anc_enable[] = {
317 SOC_DAPM_SINGLE("Switch", AB8500_ANCCONF1,
318 AB8500_ANCCONF1_ENANC, 0, 0),
319};
320
321/* ANC to Earpiece - Mute */
322static const struct snd_kcontrol_new dapm_anc_ear_mute[] = {
323 SOC_DAPM_SINGLE("Switch", AB8500_DIGMULTCONF1,
324 AB8500_DIGMULTCONF1_ANCSEL, 1, 0),
325};
326
327
328
329/* Sidetone left */
330
331/* Sidetone left - Input selector */
332static const char * const enum_stfir1_in_sel[] = {
333 "LineIn Left", "LineIn Right", "Mic 1", "Headset Left"
334};
335static SOC_ENUM_SINGLE_DECL(dapm_enum_stfir1_in_sel, AB8500_DIGMULTCONF2,
336 AB8500_DIGMULTCONF2_FIRSID1SEL, enum_stfir1_in_sel);
337static const struct snd_kcontrol_new dapm_stfir1_in_select[] = {
338 SOC_DAPM_ENUM("Sidetone Left Source", dapm_enum_stfir1_in_sel),
339};
340
341/* Sidetone right path */
342
343/* Sidetone right - Input selector */
344static const char * const enum_stfir2_in_sel[] = {
345 "LineIn Right", "Mic 1", "DMic 4", "Headset Right"
346};
347static SOC_ENUM_SINGLE_DECL(dapm_enum_stfir2_in_sel, AB8500_DIGMULTCONF2,
348 AB8500_DIGMULTCONF2_FIRSID2SEL, enum_stfir2_in_sel);
349static const struct snd_kcontrol_new dapm_stfir2_in_select[] = {
350 SOC_DAPM_ENUM("Sidetone Right Source", dapm_enum_stfir2_in_sel),
351};
352
353/* Vibra */
354
355static const char * const enum_pwm2vibx[] = {"Audio Path", "PWM Generator"};
356
357static SOC_ENUM_SINGLE_DECL(dapm_enum_pwm2vib1, AB8500_PWMGENCONF1,
358 AB8500_PWMGENCONF1_PWMTOVIB1, enum_pwm2vibx);
359
360static const struct snd_kcontrol_new dapm_pwm2vib1[] = {
361 SOC_DAPM_ENUM("Vibra 1 Controller", dapm_enum_pwm2vib1),
362};
363
364static SOC_ENUM_SINGLE_DECL(dapm_enum_pwm2vib2, AB8500_PWMGENCONF1,
365 AB8500_PWMGENCONF1_PWMTOVIB2, enum_pwm2vibx);
366
367static const struct snd_kcontrol_new dapm_pwm2vib2[] = {
368 SOC_DAPM_ENUM("Vibra 2 Controller", dapm_enum_pwm2vib2),
369};
370
371/*
372 * DAPM-widgets
373 */
374
375static const struct snd_soc_dapm_widget ab8500_dapm_widgets[] = {
376
377 /* Clocks */
378 SND_SOC_DAPM_CLOCK_SUPPLY("audioclk"),
379
380 /* Regulators */
381 SND_SOC_DAPM_REGULATOR_SUPPLY("V-AUD", 0, 0),
382 SND_SOC_DAPM_REGULATOR_SUPPLY("V-AMIC1", 0, 0),
383 SND_SOC_DAPM_REGULATOR_SUPPLY("V-AMIC2", 0, 0),
384 SND_SOC_DAPM_REGULATOR_SUPPLY("V-DMIC", 0, 0),
385
386 /* Power */
387 SND_SOC_DAPM_SUPPLY("Audio Power",
388 AB8500_POWERUP, AB8500_POWERUP_POWERUP, 0,
389 NULL, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
390 SND_SOC_DAPM_SUPPLY("Audio Analog Power",
391 AB8500_POWERUP, AB8500_POWERUP_ENANA, 0,
392 NULL, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
393
394 /* Main supply node */
395 SND_SOC_DAPM_SUPPLY("Main Supply", SND_SOC_NOPM, 0, 0,
396 NULL, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
397
398 /* DA/AD */
399
400 SND_SOC_DAPM_INPUT("ADC Input"),
401 SND_SOC_DAPM_ADC("ADC", "ab8500_0c", SND_SOC_NOPM, 0, 0),
402
403 SND_SOC_DAPM_DAC("DAC", NULL, SND_SOC_NOPM, 0, 0),
404 SND_SOC_DAPM_OUTPUT("DAC Output"),
405
406 SND_SOC_DAPM_AIF_IN("DA_IN1", NULL, 0, SND_SOC_NOPM, 0, 0),
407 SND_SOC_DAPM_AIF_IN("DA_IN2", NULL, 0, SND_SOC_NOPM, 0, 0),
408 SND_SOC_DAPM_AIF_IN("DA_IN3", NULL, 0, SND_SOC_NOPM, 0, 0),
409 SND_SOC_DAPM_AIF_IN("DA_IN4", NULL, 0, SND_SOC_NOPM, 0, 0),
410 SND_SOC_DAPM_AIF_IN("DA_IN5", NULL, 0, SND_SOC_NOPM, 0, 0),
411 SND_SOC_DAPM_AIF_IN("DA_IN6", NULL, 0, SND_SOC_NOPM, 0, 0),
412 SND_SOC_DAPM_AIF_OUT("AD_OUT1", NULL, 0, SND_SOC_NOPM, 0, 0),
413 SND_SOC_DAPM_AIF_OUT("AD_OUT2", NULL, 0, SND_SOC_NOPM, 0, 0),
414 SND_SOC_DAPM_AIF_OUT("AD_OUT3", NULL, 0, SND_SOC_NOPM, 0, 0),
415 SND_SOC_DAPM_AIF_OUT("AD_OUT4", NULL, 0, SND_SOC_NOPM, 0, 0),
416 SND_SOC_DAPM_AIF_OUT("AD_OUT57", NULL, 0, SND_SOC_NOPM, 0, 0),
417 SND_SOC_DAPM_AIF_OUT("AD_OUT68", NULL, 0, SND_SOC_NOPM, 0, 0),
418
419 /* Headset path */
420
421 SND_SOC_DAPM_SUPPLY("Charge Pump", AB8500_ANACONF5,
422 AB8500_ANACONF5_ENCPHS, 0, NULL, 0),
423
424 SND_SOC_DAPM_DAC("DA1 Enable", "ab8500_0p",
425 AB8500_DAPATHENA, AB8500_DAPATHENA_ENDA1, 0),
426 SND_SOC_DAPM_DAC("DA2 Enable", "ab8500_0p",
427 AB8500_DAPATHENA, AB8500_DAPATHENA_ENDA2, 0),
428
429 SND_SOC_DAPM_PGA("HSL Digital Volume", SND_SOC_NOPM, 0, 0,
430 NULL, 0),
431 SND_SOC_DAPM_PGA("HSR Digital Volume", SND_SOC_NOPM, 0, 0,
432 NULL, 0),
433
434 SND_SOC_DAPM_DAC("HSL DAC", "ab8500_0p",
435 AB8500_DAPATHCONF, AB8500_DAPATHCONF_ENDACHSL, 0),
436 SND_SOC_DAPM_DAC("HSR DAC", "ab8500_0p",
437 AB8500_DAPATHCONF, AB8500_DAPATHCONF_ENDACHSR, 0),
438 SND_SOC_DAPM_MIXER("HSL DAC Mute", AB8500_MUTECONF,
439 AB8500_MUTECONF_MUTDACHSL, 1,
440 NULL, 0),
441 SND_SOC_DAPM_MIXER("HSR DAC Mute", AB8500_MUTECONF,
442 AB8500_MUTECONF_MUTDACHSR, 1,
443 NULL, 0),
444 SND_SOC_DAPM_DAC("HSL DAC Driver", "ab8500_0p",
445 AB8500_ANACONF3, AB8500_ANACONF3_ENDRVHSL, 0),
446 SND_SOC_DAPM_DAC("HSR DAC Driver", "ab8500_0p",
447 AB8500_ANACONF3, AB8500_ANACONF3_ENDRVHSR, 0),
448
449 SND_SOC_DAPM_MIXER("HSL Mute",
450 AB8500_MUTECONF, AB8500_MUTECONF_MUTHSL, 1,
451 NULL, 0),
452 SND_SOC_DAPM_MIXER("HSR Mute",
453 AB8500_MUTECONF, AB8500_MUTECONF_MUTHSR, 1,
454 NULL, 0),
455 SND_SOC_DAPM_MIXER("HSL Enable",
456 AB8500_ANACONF4, AB8500_ANACONF4_ENHSL, 0,
457 NULL, 0),
458 SND_SOC_DAPM_MIXER("HSR Enable",
459 AB8500_ANACONF4, AB8500_ANACONF4_ENHSR, 0,
460 NULL, 0),
461 SND_SOC_DAPM_PGA("HSL Volume",
462 SND_SOC_NOPM, 0, 0,
463 NULL, 0),
464 SND_SOC_DAPM_PGA("HSR Volume",
465 SND_SOC_NOPM, 0, 0,
466 NULL, 0),
467
468 SND_SOC_DAPM_OUTPUT("Headset Left"),
469 SND_SOC_DAPM_OUTPUT("Headset Right"),
470
471 /* LineOut path */
472
473 SND_SOC_DAPM_MUX("LineOut Source",
474 SND_SOC_NOPM, 0, 0, dapm_lineout_source),
475
476 SND_SOC_DAPM_MIXER("LOL Disable HFL",
477 AB8500_ANACONF4, AB8500_ANACONF4_ENHFL, 1,
478 NULL, 0),
479 SND_SOC_DAPM_MIXER("LOR Disable HFR",
480 AB8500_ANACONF4, AB8500_ANACONF4_ENHFR, 1,
481 NULL, 0),
482
483 SND_SOC_DAPM_MIXER("LOL Enable",
484 AB8500_ANACONF5, AB8500_ANACONF5_ENLOL, 0,
485 NULL, 0),
486 SND_SOC_DAPM_MIXER("LOR Enable",
487 AB8500_ANACONF5, AB8500_ANACONF5_ENLOR, 0,
488 NULL, 0),
489
490 SND_SOC_DAPM_OUTPUT("LineOut Left"),
491 SND_SOC_DAPM_OUTPUT("LineOut Right"),
492
493 /* Earpiece path */
494
495 SND_SOC_DAPM_MUX("Earpiece or LineOut Mono Source",
496 SND_SOC_NOPM, 0, 0, &dapm_ear_lineout_source),
497 SND_SOC_DAPM_MIXER("EAR DAC",
498 AB8500_DAPATHCONF, AB8500_DAPATHCONF_ENDACEAR, 0,
499 NULL, 0),
500 SND_SOC_DAPM_MIXER("EAR Mute",
501 AB8500_MUTECONF, AB8500_MUTECONF_MUTEAR, 1,
502 NULL, 0),
503 SND_SOC_DAPM_MIXER("EAR Enable",
504 AB8500_ANACONF4, AB8500_ANACONF4_ENEAR, 0,
505 NULL, 0),
506
507 SND_SOC_DAPM_OUTPUT("Earpiece"),
508
509 /* Handsfree path */
510
511 SND_SOC_DAPM_MIXER("DA3 Channel Volume",
512 AB8500_DAPATHENA, AB8500_DAPATHENA_ENDA3, 0,
513 NULL, 0),
514 SND_SOC_DAPM_MIXER("DA4 Channel Volume",
515 AB8500_DAPATHENA, AB8500_DAPATHENA_ENDA4, 0,
516 NULL, 0),
517 SND_SOC_DAPM_MUX("Speaker Left Source",
518 SND_SOC_NOPM, 0, 0, dapm_HFl_select),
519 SND_SOC_DAPM_MUX("Speaker Right Source",
520 SND_SOC_NOPM, 0, 0, dapm_HFr_select),
521 SND_SOC_DAPM_MIXER("HFL DAC", AB8500_DAPATHCONF,
522 AB8500_DAPATHCONF_ENDACHFL, 0,
523 NULL, 0),
524 SND_SOC_DAPM_MIXER("HFR DAC",
525 AB8500_DAPATHCONF, AB8500_DAPATHCONF_ENDACHFR, 0,
526 NULL, 0),
527 SND_SOC_DAPM_MIXER("DA4 or ANC path to HfR",
528 AB8500_DIGMULTCONF2, AB8500_DIGMULTCONF2_DATOHFREN, 0,
529 NULL, 0),
530 SND_SOC_DAPM_MIXER("DA3 or ANC path to HfL",
531 AB8500_DIGMULTCONF2, AB8500_DIGMULTCONF2_DATOHFLEN, 0,
532 NULL, 0),
533 SND_SOC_DAPM_MIXER("HFL Enable",
534 AB8500_ANACONF4, AB8500_ANACONF4_ENHFL, 0,
535 NULL, 0),
536 SND_SOC_DAPM_MIXER("HFR Enable",
537 AB8500_ANACONF4, AB8500_ANACONF4_ENHFR, 0,
538 NULL, 0),
539
540 SND_SOC_DAPM_OUTPUT("Speaker Left"),
541 SND_SOC_DAPM_OUTPUT("Speaker Right"),
542
543 /* Vibrator path */
544
545 SND_SOC_DAPM_INPUT("PWMGEN1"),
546 SND_SOC_DAPM_INPUT("PWMGEN2"),
547
548 SND_SOC_DAPM_MIXER("DA5 Channel Volume",
549 AB8500_DAPATHENA, AB8500_DAPATHENA_ENDA5, 0,
550 NULL, 0),
551 SND_SOC_DAPM_MIXER("DA6 Channel Volume",
552 AB8500_DAPATHENA, AB8500_DAPATHENA_ENDA6, 0,
553 NULL, 0),
554 SND_SOC_DAPM_MIXER("VIB1 DAC",
555 AB8500_DAPATHCONF, AB8500_DAPATHCONF_ENDACVIB1, 0,
556 NULL, 0),
557 SND_SOC_DAPM_MIXER("VIB2 DAC",
558 AB8500_DAPATHCONF, AB8500_DAPATHCONF_ENDACVIB2, 0,
559 NULL, 0),
560 SND_SOC_DAPM_MUX("Vibra 1 Controller",
561 SND_SOC_NOPM, 0, 0, dapm_pwm2vib1),
562 SND_SOC_DAPM_MUX("Vibra 2 Controller",
563 SND_SOC_NOPM, 0, 0, dapm_pwm2vib2),
564 SND_SOC_DAPM_MIXER("VIB1 Enable",
565 AB8500_ANACONF4, AB8500_ANACONF4_ENVIB1, 0,
566 NULL, 0),
567 SND_SOC_DAPM_MIXER("VIB2 Enable",
568 AB8500_ANACONF4, AB8500_ANACONF4_ENVIB2, 0,
569 NULL, 0),
570
571 SND_SOC_DAPM_OUTPUT("Vibra 1"),
572 SND_SOC_DAPM_OUTPUT("Vibra 2"),
573
574 /* Mic 1 */
575
576 SND_SOC_DAPM_INPUT("Mic 1"),
577
578 SND_SOC_DAPM_MUX("Mic 1a or 1b Select",
579 SND_SOC_NOPM, 0, 0, dapm_mic1ab_mux),
580 SND_SOC_DAPM_MIXER("MIC1 Mute",
581 AB8500_ANACONF2, AB8500_ANACONF2_MUTMIC1, 1,
582 NULL, 0),
583 SND_SOC_DAPM_MIXER("MIC1A V-AMICx Enable",
584 AB8500_ANACONF2, AB8500_ANACONF2_ENMIC1, 0,
585 NULL, 0),
586 SND_SOC_DAPM_MIXER("MIC1B V-AMICx Enable",
587 AB8500_ANACONF2, AB8500_ANACONF2_ENMIC1, 0,
588 NULL, 0),
589 SND_SOC_DAPM_MIXER("MIC1 ADC",
590 AB8500_ANACONF3, AB8500_ANACONF3_ENADCMIC, 0,
591 NULL, 0),
592 SND_SOC_DAPM_MUX("AD3 Source Select",
593 SND_SOC_NOPM, 0, 0, dapm_ad3_select),
594 SND_SOC_DAPM_MIXER("AD3 Channel Volume",
595 SND_SOC_NOPM, 0, 0,
596 NULL, 0),
597 SND_SOC_DAPM_MIXER("AD3 Enable",
598 AB8500_ADPATHENA, AB8500_ADPATHENA_ENAD34, 0,
599 NULL, 0),
600
601 /* Mic 2 */
602
603 SND_SOC_DAPM_INPUT("Mic 2"),
604
605 SND_SOC_DAPM_MIXER("MIC2 Mute",
606 AB8500_ANACONF2, AB8500_ANACONF2_MUTMIC2, 1,
607 NULL, 0),
608 SND_SOC_DAPM_MIXER("MIC2 V-AMICx Enable", AB8500_ANACONF2,
609 AB8500_ANACONF2_ENMIC2, 0,
610 NULL, 0),
611
612 /* LineIn */
613
614 SND_SOC_DAPM_INPUT("LineIn Left"),
615 SND_SOC_DAPM_INPUT("LineIn Right"),
616
617 SND_SOC_DAPM_MIXER("LINL Mute",
618 AB8500_ANACONF2, AB8500_ANACONF2_MUTLINL, 1,
619 NULL, 0),
620 SND_SOC_DAPM_MIXER("LINR Mute",
621 AB8500_ANACONF2, AB8500_ANACONF2_MUTLINR, 1,
622 NULL, 0),
623 SND_SOC_DAPM_MIXER("LINL Enable", AB8500_ANACONF2,
624 AB8500_ANACONF2_ENLINL, 0,
625 NULL, 0),
626 SND_SOC_DAPM_MIXER("LINR Enable", AB8500_ANACONF2,
627 AB8500_ANACONF2_ENLINR, 0,
628 NULL, 0),
629
630 /* LineIn Bypass path */
631 SND_SOC_DAPM_MIXER("LINL to HSL Volume",
632 SND_SOC_NOPM, 0, 0,
633 NULL, 0),
634 SND_SOC_DAPM_MIXER("LINR to HSR Volume",
635 SND_SOC_NOPM, 0, 0,
636 NULL, 0),
637
638 /* LineIn, Mic 2 */
639 SND_SOC_DAPM_MUX("Mic 2 or LINR Select",
640 SND_SOC_NOPM, 0, 0, dapm_mic2lr_select),
641 SND_SOC_DAPM_MIXER("LINL ADC", AB8500_ANACONF3,
642 AB8500_ANACONF3_ENADCLINL, 0,
643 NULL, 0),
644 SND_SOC_DAPM_MIXER("LINR ADC", AB8500_ANACONF3,
645 AB8500_ANACONF3_ENADCLINR, 0,
646 NULL, 0),
647 SND_SOC_DAPM_MUX("AD1 Source Select",
648 SND_SOC_NOPM, 0, 0, dapm_ad1_select),
649 SND_SOC_DAPM_MUX("AD2 Source Select",
650 SND_SOC_NOPM, 0, 0, dapm_ad2_select),
651 SND_SOC_DAPM_MIXER("AD1 Channel Volume",
652 SND_SOC_NOPM, 0, 0,
653 NULL, 0),
654 SND_SOC_DAPM_MIXER("AD2 Channel Volume",
655 SND_SOC_NOPM, 0, 0,
656 NULL, 0),
657
658 SND_SOC_DAPM_MIXER("AD12 Enable",
659 AB8500_ADPATHENA, AB8500_ADPATHENA_ENAD12, 0,
660 NULL, 0),
661
662 /* HD Capture path */
663
664 SND_SOC_DAPM_MUX("AD5 Source Select",
665 SND_SOC_NOPM, 0, 0, dapm_ad5_select),
666 SND_SOC_DAPM_MUX("AD6 Source Select",
667 SND_SOC_NOPM, 0, 0, dapm_ad6_select),
668 SND_SOC_DAPM_MIXER("AD5 Channel Volume",
669 SND_SOC_NOPM, 0, 0,
670 NULL, 0),
671 SND_SOC_DAPM_MIXER("AD6 Channel Volume",
672 SND_SOC_NOPM, 0, 0,
673 NULL, 0),
674 SND_SOC_DAPM_MIXER("AD57 Enable",
675 AB8500_ADPATHENA, AB8500_ADPATHENA_ENAD5768, 0,
676 NULL, 0),
677 SND_SOC_DAPM_MIXER("AD68 Enable",
678 AB8500_ADPATHENA, AB8500_ADPATHENA_ENAD5768, 0,
679 NULL, 0),
680
681 /* Digital Microphone path */
682
683 SND_SOC_DAPM_INPUT("DMic 1"),
684 SND_SOC_DAPM_INPUT("DMic 2"),
685 SND_SOC_DAPM_INPUT("DMic 3"),
686 SND_SOC_DAPM_INPUT("DMic 4"),
687 SND_SOC_DAPM_INPUT("DMic 5"),
688 SND_SOC_DAPM_INPUT("DMic 6"),
689
690 SND_SOC_DAPM_MIXER("DMIC1",
691 AB8500_DIGMICCONF, AB8500_DIGMICCONF_ENDMIC1, 0,
692 NULL, 0),
693 SND_SOC_DAPM_MIXER("DMIC2",
694 AB8500_DIGMICCONF, AB8500_DIGMICCONF_ENDMIC2, 0,
695 NULL, 0),
696 SND_SOC_DAPM_MIXER("DMIC3",
697 AB8500_DIGMICCONF, AB8500_DIGMICCONF_ENDMIC3, 0,
698 NULL, 0),
699 SND_SOC_DAPM_MIXER("DMIC4",
700 AB8500_DIGMICCONF, AB8500_DIGMICCONF_ENDMIC4, 0,
701 NULL, 0),
702 SND_SOC_DAPM_MIXER("DMIC5",
703 AB8500_DIGMICCONF, AB8500_DIGMICCONF_ENDMIC5, 0,
704 NULL, 0),
705 SND_SOC_DAPM_MIXER("DMIC6",
706 AB8500_DIGMICCONF, AB8500_DIGMICCONF_ENDMIC6, 0,
707 NULL, 0),
708 SND_SOC_DAPM_MIXER("AD4 Channel Volume",
709 SND_SOC_NOPM, 0, 0,
710 NULL, 0),
711 SND_SOC_DAPM_MIXER("AD4 Enable",
712 AB8500_ADPATHENA, AB8500_ADPATHENA_ENAD34,
713 0, NULL, 0),
714
715 /* Acoustical Noise Cancellation path */
716
717 SND_SOC_DAPM_INPUT("ANC Configure Input"),
718 SND_SOC_DAPM_OUTPUT("ANC Configure Output"),
719
720 SND_SOC_DAPM_MUX("ANC Source",
721 SND_SOC_NOPM, 0, 0,
722 dapm_anc_in_select),
723 SND_SOC_DAPM_SWITCH("ANC",
724 SND_SOC_NOPM, 0, 0,
725 dapm_anc_enable),
726 SND_SOC_DAPM_SWITCH("ANC to Earpiece",
727 SND_SOC_NOPM, 0, 0,
728 dapm_anc_ear_mute),
729
730 /* Sidetone Filter path */
731
732 SND_SOC_DAPM_MUX("Sidetone Left Source",
733 SND_SOC_NOPM, 0, 0,
734 dapm_stfir1_in_select),
735 SND_SOC_DAPM_MUX("Sidetone Right Source",
736 SND_SOC_NOPM, 0, 0,
737 dapm_stfir2_in_select),
738 SND_SOC_DAPM_MIXER("STFIR1 Control",
739 SND_SOC_NOPM, 0, 0,
740 NULL, 0),
741 SND_SOC_DAPM_MIXER("STFIR2 Control",
742 SND_SOC_NOPM, 0, 0,
743 NULL, 0),
744 SND_SOC_DAPM_MIXER("STFIR1 Volume",
745 SND_SOC_NOPM, 0, 0,
746 NULL, 0),
747 SND_SOC_DAPM_MIXER("STFIR2 Volume",
748 SND_SOC_NOPM, 0, 0,
749 NULL, 0),
750};
751
752/*
753 * DAPM-routes
754 */
755static const struct snd_soc_dapm_route ab8500_dapm_routes[] = {
756 /* Power AB8500 audio-block when AD/DA is active */
757 {"Main Supply", NULL, "V-AUD"},
758 {"Main Supply", NULL, "audioclk"},
759 {"Main Supply", NULL, "Audio Power"},
760 {"Main Supply", NULL, "Audio Analog Power"},
761
762 {"DAC", NULL, "ab8500_0p"},
763 {"DAC", NULL, "Main Supply"},
764 {"ADC", NULL, "ab8500_0c"},
765 {"ADC", NULL, "Main Supply"},
766
767 /* ANC Configure */
768 {"ANC Configure Input", NULL, "Main Supply"},
769 {"ANC Configure Output", NULL, "ANC Configure Input"},
770
771 /* AD/DA */
772 {"ADC", NULL, "ADC Input"},
773 {"DAC Output", NULL, "DAC"},
774
775 /* Powerup charge pump if DA1/2 is in use */
776
777 {"DA_IN1", NULL, "ab8500_0p"},
778 {"DA_IN1", NULL, "Charge Pump"},
779 {"DA_IN2", NULL, "ab8500_0p"},
780 {"DA_IN2", NULL, "Charge Pump"},
781
782 /* Headset path */
783
784 {"DA1 Enable", NULL, "DA_IN1"},
785 {"DA2 Enable", NULL, "DA_IN2"},
786
787 {"HSL Digital Volume", NULL, "DA1 Enable"},
788 {"HSR Digital Volume", NULL, "DA2 Enable"},
789
790 {"HSL DAC", NULL, "HSL Digital Volume"},
791 {"HSR DAC", NULL, "HSR Digital Volume"},
792
793 {"HSL DAC Mute", NULL, "HSL DAC"},
794 {"HSR DAC Mute", NULL, "HSR DAC"},
795
796 {"HSL DAC Driver", NULL, "HSL DAC Mute"},
797 {"HSR DAC Driver", NULL, "HSR DAC Mute"},
798
799 {"HSL Mute", NULL, "HSL DAC Driver"},
800 {"HSR Mute", NULL, "HSR DAC Driver"},
801
802 {"HSL Enable", NULL, "HSL Mute"},
803 {"HSR Enable", NULL, "HSR Mute"},
804
805 {"HSL Volume", NULL, "HSL Enable"},
806 {"HSR Volume", NULL, "HSR Enable"},
807
808 {"Headset Left", NULL, "HSL Volume"},
809 {"Headset Right", NULL, "HSR Volume"},
810
811 /* HF or LineOut path */
812
813 {"DA_IN3", NULL, "ab8500_0p"},
814 {"DA3 Channel Volume", NULL, "DA_IN3"},
815 {"DA_IN4", NULL, "ab8500_0p"},
816 {"DA4 Channel Volume", NULL, "DA_IN4"},
817
818 {"Speaker Left Source", "Audio Path", "DA3 Channel Volume"},
819 {"Speaker Right Source", "Audio Path", "DA4 Channel Volume"},
820
821 {"DA3 or ANC path to HfL", NULL, "Speaker Left Source"},
822 {"DA4 or ANC path to HfR", NULL, "Speaker Right Source"},
823
824 /* HF path */
825
826 {"HFL DAC", NULL, "DA3 or ANC path to HfL"},
827 {"HFR DAC", NULL, "DA4 or ANC path to HfR"},
828
829 {"HFL Enable", NULL, "HFL DAC"},
830 {"HFR Enable", NULL, "HFR DAC"},
831
832 {"Speaker Left", NULL, "HFL Enable"},
833 {"Speaker Right", NULL, "HFR Enable"},
834
835 /* Earpiece path */
836
837 {"Earpiece or LineOut Mono Source", "Headset Left",
838 "HSL Digital Volume"},
839 {"Earpiece or LineOut Mono Source", "Speaker Left",
840 "DA3 or ANC path to HfL"},
841
842 {"EAR DAC", NULL, "Earpiece or LineOut Mono Source"},
843
844 {"EAR Mute", NULL, "EAR DAC"},
845
846 {"EAR Enable", NULL, "EAR Mute"},
847
848 {"Earpiece", NULL, "EAR Enable"},
849
850 /* LineOut path stereo */
851
852 {"LineOut Source", "Stereo Path", "HSL DAC Driver"},
853 {"LineOut Source", "Stereo Path", "HSR DAC Driver"},
854
855 /* LineOut path mono */
856
857 {"LineOut Source", "Mono Path", "EAR DAC"},
858
859 /* LineOut path */
860
861 {"LOL Disable HFL", NULL, "LineOut Source"},
862 {"LOR Disable HFR", NULL, "LineOut Source"},
863
864 {"LOL Enable", NULL, "LOL Disable HFL"},
865 {"LOR Enable", NULL, "LOR Disable HFR"},
866
867 {"LineOut Left", NULL, "LOL Enable"},
868 {"LineOut Right", NULL, "LOR Enable"},
869
870 /* Vibrator path */
871
872 {"DA_IN5", NULL, "ab8500_0p"},
873 {"DA5 Channel Volume", NULL, "DA_IN5"},
874 {"DA_IN6", NULL, "ab8500_0p"},
875 {"DA6 Channel Volume", NULL, "DA_IN6"},
876
877 {"VIB1 DAC", NULL, "DA5 Channel Volume"},
878 {"VIB2 DAC", NULL, "DA6 Channel Volume"},
879
880 {"Vibra 1 Controller", "Audio Path", "VIB1 DAC"},
881 {"Vibra 2 Controller", "Audio Path", "VIB2 DAC"},
882 {"Vibra 1 Controller", "PWM Generator", "PWMGEN1"},
883 {"Vibra 2 Controller", "PWM Generator", "PWMGEN2"},
884
885 {"VIB1 Enable", NULL, "Vibra 1 Controller"},
886 {"VIB2 Enable", NULL, "Vibra 2 Controller"},
887
888 {"Vibra 1", NULL, "VIB1 Enable"},
889 {"Vibra 2", NULL, "VIB2 Enable"},
890
891
892 /* Mic 2 */
893
894 {"MIC2 V-AMICx Enable", NULL, "Mic 2"},
895
896 /* LineIn */
897 {"LINL Mute", NULL, "LineIn Left"},
898 {"LINR Mute", NULL, "LineIn Right"},
899
900 {"LINL Enable", NULL, "LINL Mute"},
901 {"LINR Enable", NULL, "LINR Mute"},
902
903 /* LineIn, Mic 2 */
904 {"Mic 2 or LINR Select", "LineIn Right", "LINR Enable"},
905 {"Mic 2 or LINR Select", "Mic 2", "MIC2 V-AMICx Enable"},
906
907 {"LINL ADC", NULL, "LINL Enable"},
908 {"LINR ADC", NULL, "Mic 2 or LINR Select"},
909
910 {"AD1 Source Select", "LineIn Left", "LINL ADC"},
911 {"AD2 Source Select", "LineIn Right", "LINR ADC"},
912
913 {"AD1 Channel Volume", NULL, "AD1 Source Select"},
914 {"AD2 Channel Volume", NULL, "AD2 Source Select"},
915
916 {"AD12 Enable", NULL, "AD1 Channel Volume"},
917 {"AD12 Enable", NULL, "AD2 Channel Volume"},
918
919 {"AD_OUT1", NULL, "ab8500_0c"},
920 {"AD_OUT1", NULL, "AD12 Enable"},
921 {"AD_OUT2", NULL, "ab8500_0c"},
922 {"AD_OUT2", NULL, "AD12 Enable"},
923
924 /* Mic 1 */
925
926 {"MIC1 Mute", NULL, "Mic 1"},
927
928 {"MIC1A V-AMICx Enable", NULL, "MIC1 Mute"},
929 {"MIC1B V-AMICx Enable", NULL, "MIC1 Mute"},
930
931 {"Mic 1a or 1b Select", "Mic 1a", "MIC1A V-AMICx Enable"},
932 {"Mic 1a or 1b Select", "Mic 1b", "MIC1B V-AMICx Enable"},
933
934 {"MIC1 ADC", NULL, "Mic 1a or 1b Select"},
935
936 {"AD3 Source Select", "Mic 1", "MIC1 ADC"},
937
938 {"AD3 Channel Volume", NULL, "AD3 Source Select"},
939
940 {"AD3 Enable", NULL, "AD3 Channel Volume"},
941
942 {"AD_OUT3", NULL, "ab8500_0c"},
943 {"AD_OUT3", NULL, "AD3 Enable"},
944
945 /* HD Capture path */
946
947 {"AD5 Source Select", "Mic 2", "LINR ADC"},
948 {"AD6 Source Select", "Mic 1", "MIC1 ADC"},
949
950 {"AD5 Channel Volume", NULL, "AD5 Source Select"},
951 {"AD6 Channel Volume", NULL, "AD6 Source Select"},
952
953 {"AD57 Enable", NULL, "AD5 Channel Volume"},
954 {"AD68 Enable", NULL, "AD6 Channel Volume"},
955
956 {"AD_OUT57", NULL, "ab8500_0c"},
957 {"AD_OUT57", NULL, "AD57 Enable"},
958 {"AD_OUT68", NULL, "ab8500_0c"},
959 {"AD_OUT68", NULL, "AD68 Enable"},
960
961 /* Digital Microphone path */
962
963 {"DMic 1", NULL, "V-DMIC"},
964 {"DMic 2", NULL, "V-DMIC"},
965 {"DMic 3", NULL, "V-DMIC"},
966 {"DMic 4", NULL, "V-DMIC"},
967 {"DMic 5", NULL, "V-DMIC"},
968 {"DMic 6", NULL, "V-DMIC"},
969
970 {"AD1 Source Select", NULL, "DMic 1"},
971 {"AD2 Source Select", NULL, "DMic 2"},
972 {"AD3 Source Select", NULL, "DMic 3"},
973 {"AD5 Source Select", NULL, "DMic 5"},
974 {"AD6 Source Select", NULL, "DMic 6"},
975
976 {"AD4 Channel Volume", NULL, "DMic 4"},
977 {"AD4 Enable", NULL, "AD4 Channel Volume"},
978
979 {"AD_OUT4", NULL, "ab8500_0c"},
980 {"AD_OUT4", NULL, "AD4 Enable"},
981
982 /* LineIn Bypass path */
983
984 {"LINL to HSL Volume", NULL, "LINL Enable"},
985 {"LINR to HSR Volume", NULL, "LINR Enable"},
986
987 {"HSL DAC Driver", NULL, "LINL to HSL Volume"},
988 {"HSR DAC Driver", NULL, "LINR to HSR Volume"},
989
990 /* ANC path (Acoustic Noise Cancellation) */
991
992 {"ANC Source", "Mic 2 / DMic 5", "AD5 Channel Volume"},
993 {"ANC Source", "Mic 1 / DMic 6", "AD6 Channel Volume"},
994
995 {"ANC", "Switch", "ANC Source"},
996
997 {"Speaker Left Source", "ANC", "ANC"},
998 {"Speaker Right Source", "ANC", "ANC"},
999 {"ANC to Earpiece", "Switch", "ANC"},
1000
1001 {"HSL Digital Volume", NULL, "ANC to Earpiece"},
1002
1003 /* Sidetone Filter path */
1004
1005 {"Sidetone Left Source", "LineIn Left", "AD12 Enable"},
1006 {"Sidetone Left Source", "LineIn Right", "AD12 Enable"},
1007 {"Sidetone Left Source", "Mic 1", "AD3 Enable"},
1008 {"Sidetone Left Source", "Headset Left", "DA_IN1"},
1009 {"Sidetone Right Source", "LineIn Right", "AD12 Enable"},
1010 {"Sidetone Right Source", "Mic 1", "AD3 Enable"},
1011 {"Sidetone Right Source", "DMic 4", "AD4 Enable"},
1012 {"Sidetone Right Source", "Headset Right", "DA_IN2"},
1013
1014 {"STFIR1 Control", NULL, "Sidetone Left Source"},
1015 {"STFIR2 Control", NULL, "Sidetone Right Source"},
1016
1017 {"STFIR1 Volume", NULL, "STFIR1 Control"},
1018 {"STFIR2 Volume", NULL, "STFIR2 Control"},
1019
1020 {"DA1 Enable", NULL, "STFIR1 Volume"},
1021 {"DA2 Enable", NULL, "STFIR2 Volume"},
1022};
1023
1024static const struct snd_soc_dapm_route ab8500_dapm_routes_mic1a_vamicx[] = {
1025 {"MIC1A V-AMICx Enable", NULL, "V-AMIC1"},
1026 {"MIC1A V-AMICx Enable", NULL, "V-AMIC2"},
1027};
1028
1029static const struct snd_soc_dapm_route ab8500_dapm_routes_mic1b_vamicx[] = {
1030 {"MIC1B V-AMICx Enable", NULL, "V-AMIC1"},
1031 {"MIC1B V-AMICx Enable", NULL, "V-AMIC2"},
1032};
1033
1034static const struct snd_soc_dapm_route ab8500_dapm_routes_mic2_vamicx[] = {
1035 {"MIC2 V-AMICx Enable", NULL, "V-AMIC1"},
1036 {"MIC2 V-AMICx Enable", NULL, "V-AMIC2"},
1037};
1038
1039/* ANC FIR-coefficients configuration sequence */
1040static void anc_fir(struct snd_soc_component *component,
1041 unsigned int bnk, unsigned int par, unsigned int val)
1042{
1043 if (par == 0 && bnk == 0)
1044 snd_soc_component_update_bits(component, AB8500_ANCCONF1,
1045 BIT(AB8500_ANCCONF1_ANCFIRUPDATE),
1046 BIT(AB8500_ANCCONF1_ANCFIRUPDATE));
1047
1048 snd_soc_component_write(component, AB8500_ANCCONF5, val >> 8 & 0xff);
1049 snd_soc_component_write(component, AB8500_ANCCONF6, val & 0xff);
1050
1051 if (par == AB8500_ANC_FIR_COEFFS - 1 && bnk == 1)
1052 snd_soc_component_update_bits(component, AB8500_ANCCONF1,
1053 BIT(AB8500_ANCCONF1_ANCFIRUPDATE), 0);
1054}
1055
1056/* ANC IIR-coefficients configuration sequence */
1057static void anc_iir(struct snd_soc_component *component, unsigned int bnk,
1058 unsigned int par, unsigned int val)
1059{
1060 if (par == 0) {
1061 if (bnk == 0) {
1062 snd_soc_component_update_bits(component, AB8500_ANCCONF1,
1063 BIT(AB8500_ANCCONF1_ANCIIRINIT),
1064 BIT(AB8500_ANCCONF1_ANCIIRINIT));
1065 usleep_range(AB8500_ANC_SM_DELAY, AB8500_ANC_SM_DELAY);
1066 snd_soc_component_update_bits(component, AB8500_ANCCONF1,
1067 BIT(AB8500_ANCCONF1_ANCIIRINIT), 0);
1068 usleep_range(AB8500_ANC_SM_DELAY, AB8500_ANC_SM_DELAY);
1069 } else {
1070 snd_soc_component_update_bits(component, AB8500_ANCCONF1,
1071 BIT(AB8500_ANCCONF1_ANCIIRUPDATE),
1072 BIT(AB8500_ANCCONF1_ANCIIRUPDATE));
1073 }
1074 } else if (par > 3) {
1075 snd_soc_component_write(component, AB8500_ANCCONF7, 0);
1076 snd_soc_component_write(component, AB8500_ANCCONF8, val >> 16 & 0xff);
1077 }
1078
1079 snd_soc_component_write(component, AB8500_ANCCONF7, val >> 8 & 0xff);
1080 snd_soc_component_write(component, AB8500_ANCCONF8, val & 0xff);
1081
1082 if (par == AB8500_ANC_IIR_COEFFS - 1 && bnk == 1)
1083 snd_soc_component_update_bits(component, AB8500_ANCCONF1,
1084 BIT(AB8500_ANCCONF1_ANCIIRUPDATE), 0);
1085}
1086
1087/* ANC IIR-/FIR-coefficients configuration sequence */
1088static void anc_configure(struct snd_soc_component *component,
1089 bool apply_fir, bool apply_iir)
1090{
1091 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(component->dev);
1092 unsigned int bnk, par, val;
1093
1094 dev_dbg(component->dev, "%s: Enter.\n", __func__);
1095
1096 if (apply_fir)
1097 snd_soc_component_update_bits(component, AB8500_ANCCONF1,
1098 BIT(AB8500_ANCCONF1_ENANC), 0);
1099
1100 snd_soc_component_update_bits(component, AB8500_ANCCONF1,
1101 BIT(AB8500_ANCCONF1_ENANC), BIT(AB8500_ANCCONF1_ENANC));
1102
1103 if (apply_fir)
1104 for (bnk = 0; bnk < AB8500_NR_OF_ANC_COEFF_BANKS; bnk++)
1105 for (par = 0; par < AB8500_ANC_FIR_COEFFS; par++) {
1106 val = snd_soc_component_read32(component,
1107 drvdata->anc_fir_values[par]);
1108 anc_fir(component, bnk, par, val);
1109 }
1110
1111 if (apply_iir)
1112 for (bnk = 0; bnk < AB8500_NR_OF_ANC_COEFF_BANKS; bnk++)
1113 for (par = 0; par < AB8500_ANC_IIR_COEFFS; par++) {
1114 val = snd_soc_component_read32(component,
1115 drvdata->anc_iir_values[par]);
1116 anc_iir(component, bnk, par, val);
1117 }
1118
1119 dev_dbg(component->dev, "%s: Exit.\n", __func__);
1120}
1121
1122/*
1123 * Control-events
1124 */
1125
1126static int sid_status_control_get(struct snd_kcontrol *kcontrol,
1127 struct snd_ctl_elem_value *ucontrol)
1128{
1129 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1130 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(component->dev);
1131
1132 mutex_lock(&drvdata->ctrl_lock);
1133 ucontrol->value.enumerated.item[0] = drvdata->sid_status;
1134 mutex_unlock(&drvdata->ctrl_lock);
1135
1136 return 0;
1137}
1138
1139/* Write sidetone FIR-coefficients configuration sequence */
1140static int sid_status_control_put(struct snd_kcontrol *kcontrol,
1141 struct snd_ctl_elem_value *ucontrol)
1142{
1143 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1144 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(component->dev);
1145 unsigned int param, sidconf, val;
1146 int status = 1;
1147
1148 dev_dbg(component->dev, "%s: Enter\n", __func__);
1149
1150 if (ucontrol->value.enumerated.item[0] != SID_APPLY_FIR) {
1151 dev_err(component->dev,
1152 "%s: ERROR: This control supports '%s' only!\n",
1153 __func__, enum_sid_state[SID_APPLY_FIR]);
1154 return -EIO;
1155 }
1156
1157 mutex_lock(&drvdata->ctrl_lock);
1158
1159 sidconf = snd_soc_component_read32(component, AB8500_SIDFIRCONF);
1160 if (((sidconf & BIT(AB8500_SIDFIRCONF_FIRSIDBUSY)) != 0)) {
1161 if ((sidconf & BIT(AB8500_SIDFIRCONF_ENFIRSIDS)) == 0) {
1162 dev_err(component->dev, "%s: Sidetone busy while off!\n",
1163 __func__);
1164 status = -EPERM;
1165 } else {
1166 status = -EBUSY;
1167 }
1168 goto out;
1169 }
1170
1171 snd_soc_component_write(component, AB8500_SIDFIRADR, 0);
1172
1173 for (param = 0; param < AB8500_SID_FIR_COEFFS; param++) {
1174 val = snd_soc_component_read32(component, drvdata->sid_fir_values[param]);
1175 snd_soc_component_write(component, AB8500_SIDFIRCOEF1, val >> 8 & 0xff);
1176 snd_soc_component_write(component, AB8500_SIDFIRCOEF2, val & 0xff);
1177 }
1178
1179 snd_soc_component_update_bits(component, AB8500_SIDFIRADR,
1180 BIT(AB8500_SIDFIRADR_FIRSIDSET),
1181 BIT(AB8500_SIDFIRADR_FIRSIDSET));
1182 snd_soc_component_update_bits(component, AB8500_SIDFIRADR,
1183 BIT(AB8500_SIDFIRADR_FIRSIDSET), 0);
1184
1185 drvdata->sid_status = SID_FIR_CONFIGURED;
1186
1187out:
1188 mutex_unlock(&drvdata->ctrl_lock);
1189
1190 dev_dbg(component->dev, "%s: Exit\n", __func__);
1191
1192 return status;
1193}
1194
1195static int anc_status_control_get(struct snd_kcontrol *kcontrol,
1196 struct snd_ctl_elem_value *ucontrol)
1197{
1198 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1199 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(component->dev);
1200
1201 mutex_lock(&drvdata->ctrl_lock);
1202 ucontrol->value.enumerated.item[0] = drvdata->anc_status;
1203 mutex_unlock(&drvdata->ctrl_lock);
1204
1205 return 0;
1206}
1207
1208static int anc_status_control_put(struct snd_kcontrol *kcontrol,
1209 struct snd_ctl_elem_value *ucontrol)
1210{
1211 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1212 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
1213 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(component->dev);
1214 struct device *dev = component->dev;
1215 bool apply_fir, apply_iir;
1216 unsigned int req;
1217 int status;
1218
1219 dev_dbg(dev, "%s: Enter.\n", __func__);
1220
1221 mutex_lock(&drvdata->ctrl_lock);
1222
1223 req = ucontrol->value.enumerated.item[0];
1224 if (req >= ARRAY_SIZE(enum_anc_state)) {
1225 status = -EINVAL;
1226 goto cleanup;
1227 }
1228 if (req != ANC_APPLY_FIR_IIR && req != ANC_APPLY_FIR &&
1229 req != ANC_APPLY_IIR) {
1230 dev_err(dev, "%s: ERROR: Unsupported status to set '%s'!\n",
1231 __func__, enum_anc_state[req]);
1232 status = -EINVAL;
1233 goto cleanup;
1234 }
1235 apply_fir = req == ANC_APPLY_FIR || req == ANC_APPLY_FIR_IIR;
1236 apply_iir = req == ANC_APPLY_IIR || req == ANC_APPLY_FIR_IIR;
1237
1238 status = snd_soc_dapm_force_enable_pin(dapm, "ANC Configure Input");
1239 if (status < 0) {
1240 dev_err(dev,
1241 "%s: ERROR: Failed to enable power (status = %d)!\n",
1242 __func__, status);
1243 goto cleanup;
1244 }
1245 snd_soc_dapm_sync(dapm);
1246
1247 anc_configure(component, apply_fir, apply_iir);
1248
1249 if (apply_fir) {
1250 if (drvdata->anc_status == ANC_IIR_CONFIGURED)
1251 drvdata->anc_status = ANC_FIR_IIR_CONFIGURED;
1252 else if (drvdata->anc_status != ANC_FIR_IIR_CONFIGURED)
1253 drvdata->anc_status = ANC_FIR_CONFIGURED;
1254 }
1255 if (apply_iir) {
1256 if (drvdata->anc_status == ANC_FIR_CONFIGURED)
1257 drvdata->anc_status = ANC_FIR_IIR_CONFIGURED;
1258 else if (drvdata->anc_status != ANC_FIR_IIR_CONFIGURED)
1259 drvdata->anc_status = ANC_IIR_CONFIGURED;
1260 }
1261
1262 status = snd_soc_dapm_disable_pin(dapm, "ANC Configure Input");
1263 snd_soc_dapm_sync(dapm);
1264
1265cleanup:
1266 mutex_unlock(&drvdata->ctrl_lock);
1267
1268 if (status < 0)
1269 dev_err(dev, "%s: Unable to configure ANC! (status = %d)\n",
1270 __func__, status);
1271
1272 dev_dbg(dev, "%s: Exit.\n", __func__);
1273
1274 return (status < 0) ? status : 1;
1275}
1276
1277static int filter_control_info(struct snd_kcontrol *kcontrol,
1278 struct snd_ctl_elem_info *uinfo)
1279{
1280 struct filter_control *fc =
1281 (struct filter_control *)kcontrol->private_value;
1282
1283 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1284 uinfo->count = fc->count;
1285 uinfo->value.integer.min = fc->min;
1286 uinfo->value.integer.max = fc->max;
1287
1288 return 0;
1289}
1290
1291static int filter_control_get(struct snd_kcontrol *kcontrol,
1292 struct snd_ctl_elem_value *ucontrol)
1293{
1294 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1295 struct ab8500_codec_drvdata *drvdata = snd_soc_component_get_drvdata(component);
1296 struct filter_control *fc =
1297 (struct filter_control *)kcontrol->private_value;
1298 unsigned int i;
1299
1300 mutex_lock(&drvdata->ctrl_lock);
1301 for (i = 0; i < fc->count; i++)
1302 ucontrol->value.integer.value[i] = fc->value[i];
1303 mutex_unlock(&drvdata->ctrl_lock);
1304
1305 return 0;
1306}
1307
1308static int filter_control_put(struct snd_kcontrol *kcontrol,
1309 struct snd_ctl_elem_value *ucontrol)
1310{
1311 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1312 struct ab8500_codec_drvdata *drvdata = snd_soc_component_get_drvdata(component);
1313 struct filter_control *fc =
1314 (struct filter_control *)kcontrol->private_value;
1315 unsigned int i;
1316
1317 mutex_lock(&drvdata->ctrl_lock);
1318 for (i = 0; i < fc->count; i++)
1319 fc->value[i] = ucontrol->value.integer.value[i];
1320 mutex_unlock(&drvdata->ctrl_lock);
1321
1322 return 0;
1323}
1324
1325/*
1326 * Controls - Non-DAPM ASoC
1327 */
1328
1329static DECLARE_TLV_DB_SCALE(adx_dig_gain_tlv, -3200, 100, 1);
1330/* -32dB = Mute */
1331
1332static DECLARE_TLV_DB_SCALE(dax_dig_gain_tlv, -6300, 100, 1);
1333/* -63dB = Mute */
1334
1335static DECLARE_TLV_DB_SCALE(hs_ear_dig_gain_tlv, -100, 100, 1);
1336/* -1dB = Mute */
1337
1338static const DECLARE_TLV_DB_RANGE(hs_gain_tlv,
1339 0, 3, TLV_DB_SCALE_ITEM(-3200, 400, 0),
1340 4, 15, TLV_DB_SCALE_ITEM(-1800, 200, 0)
1341);
1342
1343static DECLARE_TLV_DB_SCALE(mic_gain_tlv, 0, 100, 0);
1344
1345static DECLARE_TLV_DB_SCALE(lin_gain_tlv, -1000, 200, 0);
1346
1347static DECLARE_TLV_DB_SCALE(lin2hs_gain_tlv, -3800, 200, 1);
1348/* -38dB = Mute */
1349
1350static const char * const enum_hsfadspeed[] = {"2ms", "0.5ms", "10.6ms",
1351 "5ms"};
1352static SOC_ENUM_SINGLE_DECL(soc_enum_hsfadspeed,
1353 AB8500_DIGMICCONF, AB8500_DIGMICCONF_HSFADSPEED, enum_hsfadspeed);
1354
1355static const char * const enum_envdetthre[] = {
1356 "250mV", "300mV", "350mV", "400mV",
1357 "450mV", "500mV", "550mV", "600mV",
1358 "650mV", "700mV", "750mV", "800mV",
1359 "850mV", "900mV", "950mV", "1.00V" };
1360static SOC_ENUM_SINGLE_DECL(soc_enum_envdeththre,
1361 AB8500_ENVCPCONF, AB8500_ENVCPCONF_ENVDETHTHRE, enum_envdetthre);
1362static SOC_ENUM_SINGLE_DECL(soc_enum_envdetlthre,
1363 AB8500_ENVCPCONF, AB8500_ENVCPCONF_ENVDETLTHRE, enum_envdetthre);
1364static const char * const enum_envdettime[] = {
1365 "26.6us", "53.2us", "106us", "213us",
1366 "426us", "851us", "1.70ms", "3.40ms",
1367 "6.81ms", "13.6ms", "27.2ms", "54.5ms",
1368 "109ms", "218ms", "436ms", "872ms" };
1369static SOC_ENUM_SINGLE_DECL(soc_enum_envdettime,
1370 AB8500_SIGENVCONF, AB8500_SIGENVCONF_ENVDETTIME, enum_envdettime);
1371
1372static const char * const enum_sinc31[] = {"Sinc 3", "Sinc 1"};
1373static SOC_ENUM_SINGLE_DECL(soc_enum_hsesinc, AB8500_HSLEARDIGGAIN,
1374 AB8500_HSLEARDIGGAIN_HSSINC1, enum_sinc31);
1375
1376static const char * const enum_fadespeed[] = {"1ms", "4ms", "8ms", "16ms"};
1377static SOC_ENUM_SINGLE_DECL(soc_enum_fadespeed, AB8500_HSRDIGGAIN,
1378 AB8500_HSRDIGGAIN_FADESPEED, enum_fadespeed);
1379
1380/* Earpiece */
1381
1382static const char * const enum_lowpow[] = {"Normal", "Low Power"};
1383static SOC_ENUM_SINGLE_DECL(soc_enum_eardaclowpow, AB8500_ANACONF1,
1384 AB8500_ANACONF1_EARDACLOWPOW, enum_lowpow);
1385static SOC_ENUM_SINGLE_DECL(soc_enum_eardrvlowpow, AB8500_ANACONF1,
1386 AB8500_ANACONF1_EARDRVLOWPOW, enum_lowpow);
1387
1388static const char * const enum_av_mode[] = {"Audio", "Voice"};
1389static SOC_ENUM_DOUBLE_DECL(soc_enum_ad12voice, AB8500_ADFILTCONF,
1390 AB8500_ADFILTCONF_AD1VOICE, AB8500_ADFILTCONF_AD2VOICE, enum_av_mode);
1391static SOC_ENUM_DOUBLE_DECL(soc_enum_ad34voice, AB8500_ADFILTCONF,
1392 AB8500_ADFILTCONF_AD3VOICE, AB8500_ADFILTCONF_AD4VOICE, enum_av_mode);
1393
1394/* DA */
1395
1396static SOC_ENUM_SINGLE_DECL(soc_enum_da12voice,
1397 AB8500_DASLOTCONF1, AB8500_DASLOTCONF1_DA12VOICE,
1398