2 * ALSA SoC TWL4030 codec driver
4 * Author: Steve Sakoman, <steve@sakoman.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 #include <linux/module.h>
23 #include <linux/moduleparam.h>
24 #include <linux/init.h>
25 #include <linux/delay.h>
27 #include <linux/i2c.h>
28 #include <linux/platform_device.h>
30 #include <linux/of_gpio.h>
31 #include <linux/mfd/twl.h>
32 #include <linux/slab.h>
33 #include <linux/gpio.h>
34 #include <sound/core.h>
35 #include <sound/pcm.h>
36 #include <sound/pcm_params.h>
37 #include <sound/soc.h>
38 #include <sound/initval.h>
39 #include <sound/tlv.h>
41 /* Register descriptions are here */
42 #include <linux/mfd/twl4030-audio.h>
44 /* TWL4030 PMBR1 Register */
45 #define TWL4030_PMBR1_REG 0x0D
46 /* TWL4030 PMBR1 Register GPIO6 mux bits */
47 #define TWL4030_GPIO6_PWM0_MUTE(value) ((value & 0x03) << 2)
49 #define TWL4030_CACHEREGNUM (TWL4030_REG_MISC_SET_2 + 1)
51 /* codec private data */
53 unsigned int codec_powered
;
55 /* reference counts of AIF/APLL users */
56 unsigned int apll_enabled
;
58 struct snd_pcm_substream
*master_substream
;
59 struct snd_pcm_substream
*slave_substream
;
61 unsigned int configured
;
63 unsigned int sample_bits
;
64 unsigned int channels
;
68 /* Output (with associated amp) states */
69 u8 hsl_enabled
, hsr_enabled
;
71 u8 predrivel_enabled
, predriver_enabled
;
72 u8 carkitl_enabled
, carkitr_enabled
;
73 u8 ctl_cache
[TWL4030_REG_PRECKR_CTL
- TWL4030_REG_EAR_CTL
+ 1];
75 struct twl4030_codec_data
*pdata
;
78 static void tw4030_init_ctl_cache(struct twl4030_priv
*twl4030
)
83 for (i
= TWL4030_REG_EAR_CTL
; i
<= TWL4030_REG_PRECKR_CTL
; i
++) {
84 twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE
, &byte
, i
);
85 twl4030
->ctl_cache
[i
- TWL4030_REG_EAR_CTL
] = byte
;
89 static unsigned int twl4030_read(struct snd_soc_codec
*codec
, unsigned int reg
)
91 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
94 if (reg
>= TWL4030_CACHEREGNUM
)
98 case TWL4030_REG_EAR_CTL
:
99 case TWL4030_REG_PREDL_CTL
:
100 case TWL4030_REG_PREDR_CTL
:
101 case TWL4030_REG_PRECKL_CTL
:
102 case TWL4030_REG_PRECKR_CTL
:
103 case TWL4030_REG_HS_GAIN_SET
:
104 value
= twl4030
->ctl_cache
[reg
- TWL4030_REG_EAR_CTL
];
107 twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE
, &value
, reg
);
114 static bool twl4030_can_write_to_chip(struct twl4030_priv
*twl4030
,
117 bool write_to_reg
= false;
119 /* Decide if the given register can be written */
121 case TWL4030_REG_EAR_CTL
:
122 if (twl4030
->earpiece_enabled
)
125 case TWL4030_REG_PREDL_CTL
:
126 if (twl4030
->predrivel_enabled
)
129 case TWL4030_REG_PREDR_CTL
:
130 if (twl4030
->predriver_enabled
)
133 case TWL4030_REG_PRECKL_CTL
:
134 if (twl4030
->carkitl_enabled
)
137 case TWL4030_REG_PRECKR_CTL
:
138 if (twl4030
->carkitr_enabled
)
141 case TWL4030_REG_HS_GAIN_SET
:
142 if (twl4030
->hsl_enabled
|| twl4030
->hsr_enabled
)
146 /* All other register can be written */
154 static int twl4030_write(struct snd_soc_codec
*codec
, unsigned int reg
,
157 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
159 /* Update the ctl cache */
161 case TWL4030_REG_EAR_CTL
:
162 case TWL4030_REG_PREDL_CTL
:
163 case TWL4030_REG_PREDR_CTL
:
164 case TWL4030_REG_PRECKL_CTL
:
165 case TWL4030_REG_PRECKR_CTL
:
166 case TWL4030_REG_HS_GAIN_SET
:
167 twl4030
->ctl_cache
[reg
- TWL4030_REG_EAR_CTL
] = value
;
173 if (twl4030_can_write_to_chip(twl4030
, reg
))
174 return twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE
, value
, reg
);
179 static inline void twl4030_wait_ms(int time
)
183 usleep_range(time
, time
+ 500);
189 static void twl4030_codec_enable(struct snd_soc_codec
*codec
, int enable
)
191 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
194 if (enable
== twl4030
->codec_powered
)
198 mode
= twl4030_audio_enable_resource(TWL4030_AUDIO_RES_POWER
);
200 mode
= twl4030_audio_disable_resource(TWL4030_AUDIO_RES_POWER
);
203 twl4030
->codec_powered
= enable
;
205 /* REVISIT: this delay is present in TI sample drivers */
206 /* but there seems to be no TRM requirement for it */
210 static void twl4030_setup_pdata_of(struct twl4030_codec_data
*pdata
,
211 struct device_node
*node
)
215 of_property_read_u32(node
, "ti,digimic_delay",
216 &pdata
->digimic_delay
);
217 of_property_read_u32(node
, "ti,ramp_delay_value",
218 &pdata
->ramp_delay_value
);
219 of_property_read_u32(node
, "ti,offset_cncl_path",
220 &pdata
->offset_cncl_path
);
221 if (!of_property_read_u32(node
, "ti,hs_extmute", &value
))
222 pdata
->hs_extmute
= value
;
224 pdata
->hs_extmute_gpio
= of_get_named_gpio(node
,
225 "ti,hs_extmute_gpio", 0);
226 if (gpio_is_valid(pdata
->hs_extmute_gpio
))
227 pdata
->hs_extmute
= 1;
230 static struct twl4030_codec_data
*twl4030_get_pdata(struct snd_soc_codec
*codec
)
232 struct twl4030_codec_data
*pdata
= dev_get_platdata(codec
->dev
);
233 struct device_node
*twl4030_codec_node
= NULL
;
235 twl4030_codec_node
= of_get_child_by_name(codec
->dev
->parent
->of_node
,
238 if (!pdata
&& twl4030_codec_node
) {
239 pdata
= devm_kzalloc(codec
->dev
,
240 sizeof(struct twl4030_codec_data
),
243 dev_err(codec
->dev
, "Can not allocate memory\n");
244 of_node_put(twl4030_codec_node
);
247 twl4030_setup_pdata_of(pdata
, twl4030_codec_node
);
248 of_node_put(twl4030_codec_node
);
254 static void twl4030_init_chip(struct snd_soc_codec
*codec
)
256 struct twl4030_codec_data
*pdata
;
257 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
261 pdata
= twl4030_get_pdata(codec
);
263 if (pdata
&& pdata
->hs_extmute
) {
264 if (gpio_is_valid(pdata
->hs_extmute_gpio
)) {
267 if (!pdata
->hs_extmute_gpio
)
269 "Extmute GPIO is 0 is this correct?\n");
271 ret
= gpio_request_one(pdata
->hs_extmute_gpio
,
276 "Failed to get hs_extmute GPIO\n");
277 pdata
->hs_extmute_gpio
= -1;
282 /* Set TWL4030 GPIO6 as EXTMUTE signal */
283 twl_i2c_read_u8(TWL4030_MODULE_INTBR
, &pin_mux
,
285 pin_mux
&= ~TWL4030_GPIO6_PWM0_MUTE(0x03);
286 pin_mux
|= TWL4030_GPIO6_PWM0_MUTE(0x02);
287 twl_i2c_write_u8(TWL4030_MODULE_INTBR
, pin_mux
,
292 /* Initialize the local ctl register cache */
293 tw4030_init_ctl_cache(twl4030
);
295 /* anti-pop when changing analog gain */
296 reg
= twl4030_read(codec
, TWL4030_REG_MISC_SET_1
);
297 twl4030_write(codec
, TWL4030_REG_MISC_SET_1
,
298 reg
| TWL4030_SMOOTH_ANAVOL_EN
);
300 twl4030_write(codec
, TWL4030_REG_OPTION
,
301 TWL4030_ATXL1_EN
| TWL4030_ATXR1_EN
|
302 TWL4030_ARXL2_EN
| TWL4030_ARXR2_EN
);
304 /* REG_ARXR2_APGA_CTL reset according to the TRM: 0dB, DA_EN */
305 twl4030_write(codec
, TWL4030_REG_ARXR2_APGA_CTL
, 0x32);
307 /* Machine dependent setup */
311 twl4030
->pdata
= pdata
;
313 reg
= twl4030_read(codec
, TWL4030_REG_HS_POPN_SET
);
314 reg
&= ~TWL4030_RAMP_DELAY
;
315 reg
|= (pdata
->ramp_delay_value
<< 2);
316 twl4030_write(codec
, TWL4030_REG_HS_POPN_SET
, reg
);
318 /* initiate offset cancellation */
319 twl4030_codec_enable(codec
, 1);
321 reg
= twl4030_read(codec
, TWL4030_REG_ANAMICL
);
322 reg
&= ~TWL4030_OFFSET_CNCL_SEL
;
323 reg
|= pdata
->offset_cncl_path
;
324 twl4030_write(codec
, TWL4030_REG_ANAMICL
,
325 reg
| TWL4030_CNCL_OFFSET_START
);
328 * Wait for offset cancellation to complete.
329 * Since this takes a while, do not slam the i2c.
330 * Start polling the status after ~20ms.
334 usleep_range(1000, 2000);
335 twl_set_regcache_bypass(TWL4030_MODULE_AUDIO_VOICE
, true);
336 twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE
, &byte
,
337 TWL4030_REG_ANAMICL
);
338 twl_set_regcache_bypass(TWL4030_MODULE_AUDIO_VOICE
, false);
339 } while ((i
++ < 100) &&
340 ((byte
& TWL4030_CNCL_OFFSET_START
) ==
341 TWL4030_CNCL_OFFSET_START
));
343 twl4030_codec_enable(codec
, 0);
346 static void twl4030_apll_enable(struct snd_soc_codec
*codec
, int enable
)
348 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
351 twl4030
->apll_enabled
++;
352 if (twl4030
->apll_enabled
== 1)
353 twl4030_audio_enable_resource(
354 TWL4030_AUDIO_RES_APLL
);
356 twl4030
->apll_enabled
--;
357 if (!twl4030
->apll_enabled
)
358 twl4030_audio_disable_resource(
359 TWL4030_AUDIO_RES_APLL
);
364 static const struct snd_kcontrol_new twl4030_dapm_earpiece_controls
[] = {
365 SOC_DAPM_SINGLE("Voice", TWL4030_REG_EAR_CTL
, 0, 1, 0),
366 SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_EAR_CTL
, 1, 1, 0),
367 SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_EAR_CTL
, 2, 1, 0),
368 SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_EAR_CTL
, 3, 1, 0),
372 static const struct snd_kcontrol_new twl4030_dapm_predrivel_controls
[] = {
373 SOC_DAPM_SINGLE("Voice", TWL4030_REG_PREDL_CTL
, 0, 1, 0),
374 SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_PREDL_CTL
, 1, 1, 0),
375 SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_PREDL_CTL
, 2, 1, 0),
376 SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_PREDL_CTL
, 3, 1, 0),
380 static const struct snd_kcontrol_new twl4030_dapm_predriver_controls
[] = {
381 SOC_DAPM_SINGLE("Voice", TWL4030_REG_PREDR_CTL
, 0, 1, 0),
382 SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_PREDR_CTL
, 1, 1, 0),
383 SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_PREDR_CTL
, 2, 1, 0),
384 SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_PREDR_CTL
, 3, 1, 0),
388 static const struct snd_kcontrol_new twl4030_dapm_hsol_controls
[] = {
389 SOC_DAPM_SINGLE("Voice", TWL4030_REG_HS_SEL
, 0, 1, 0),
390 SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_HS_SEL
, 1, 1, 0),
391 SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_HS_SEL
, 2, 1, 0),
395 static const struct snd_kcontrol_new twl4030_dapm_hsor_controls
[] = {
396 SOC_DAPM_SINGLE("Voice", TWL4030_REG_HS_SEL
, 3, 1, 0),
397 SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_HS_SEL
, 4, 1, 0),
398 SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_HS_SEL
, 5, 1, 0),
402 static const struct snd_kcontrol_new twl4030_dapm_carkitl_controls
[] = {
403 SOC_DAPM_SINGLE("Voice", TWL4030_REG_PRECKL_CTL
, 0, 1, 0),
404 SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_PRECKL_CTL
, 1, 1, 0),
405 SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_PRECKL_CTL
, 2, 1, 0),
409 static const struct snd_kcontrol_new twl4030_dapm_carkitr_controls
[] = {
410 SOC_DAPM_SINGLE("Voice", TWL4030_REG_PRECKR_CTL
, 0, 1, 0),
411 SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_PRECKR_CTL
, 1, 1, 0),
412 SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_PRECKR_CTL
, 2, 1, 0),
416 static const char *twl4030_handsfreel_texts
[] =
417 {"Voice", "AudioL1", "AudioL2", "AudioR2"};
419 static SOC_ENUM_SINGLE_DECL(twl4030_handsfreel_enum
,
420 TWL4030_REG_HFL_CTL
, 0,
421 twl4030_handsfreel_texts
);
423 static const struct snd_kcontrol_new twl4030_dapm_handsfreel_control
=
424 SOC_DAPM_ENUM("Route", twl4030_handsfreel_enum
);
426 /* Handsfree Left virtual mute */
427 static const struct snd_kcontrol_new twl4030_dapm_handsfreelmute_control
=
428 SOC_DAPM_SINGLE_VIRT("Switch", 1);
430 /* Handsfree Right */
431 static const char *twl4030_handsfreer_texts
[] =
432 {"Voice", "AudioR1", "AudioR2", "AudioL2"};
434 static SOC_ENUM_SINGLE_DECL(twl4030_handsfreer_enum
,
435 TWL4030_REG_HFR_CTL
, 0,
436 twl4030_handsfreer_texts
);
438 static const struct snd_kcontrol_new twl4030_dapm_handsfreer_control
=
439 SOC_DAPM_ENUM("Route", twl4030_handsfreer_enum
);
441 /* Handsfree Right virtual mute */
442 static const struct snd_kcontrol_new twl4030_dapm_handsfreermute_control
=
443 SOC_DAPM_SINGLE_VIRT("Switch", 1);
446 /* Vibra audio path selection */
447 static const char *twl4030_vibra_texts
[] =
448 {"AudioL1", "AudioR1", "AudioL2", "AudioR2"};
450 static SOC_ENUM_SINGLE_DECL(twl4030_vibra_enum
,
451 TWL4030_REG_VIBRA_CTL
, 2,
452 twl4030_vibra_texts
);
454 static const struct snd_kcontrol_new twl4030_dapm_vibra_control
=
455 SOC_DAPM_ENUM("Route", twl4030_vibra_enum
);
457 /* Vibra path selection: local vibrator (PWM) or audio driven */
458 static const char *twl4030_vibrapath_texts
[] =
459 {"Local vibrator", "Audio"};
461 static SOC_ENUM_SINGLE_DECL(twl4030_vibrapath_enum
,
462 TWL4030_REG_VIBRA_CTL
, 4,
463 twl4030_vibrapath_texts
);
465 static const struct snd_kcontrol_new twl4030_dapm_vibrapath_control
=
466 SOC_DAPM_ENUM("Route", twl4030_vibrapath_enum
);
468 /* Left analog microphone selection */
469 static const struct snd_kcontrol_new twl4030_dapm_analoglmic_controls
[] = {
470 SOC_DAPM_SINGLE("Main Mic Capture Switch",
471 TWL4030_REG_ANAMICL
, 0, 1, 0),
472 SOC_DAPM_SINGLE("Headset Mic Capture Switch",
473 TWL4030_REG_ANAMICL
, 1, 1, 0),
474 SOC_DAPM_SINGLE("AUXL Capture Switch",
475 TWL4030_REG_ANAMICL
, 2, 1, 0),
476 SOC_DAPM_SINGLE("Carkit Mic Capture Switch",
477 TWL4030_REG_ANAMICL
, 3, 1, 0),
480 /* Right analog microphone selection */
481 static const struct snd_kcontrol_new twl4030_dapm_analogrmic_controls
[] = {
482 SOC_DAPM_SINGLE("Sub Mic Capture Switch", TWL4030_REG_ANAMICR
, 0, 1, 0),
483 SOC_DAPM_SINGLE("AUXR Capture Switch", TWL4030_REG_ANAMICR
, 2, 1, 0),
486 /* TX1 L/R Analog/Digital microphone selection */
487 static const char *twl4030_micpathtx1_texts
[] =
488 {"Analog", "Digimic0"};
490 static SOC_ENUM_SINGLE_DECL(twl4030_micpathtx1_enum
,
491 TWL4030_REG_ADCMICSEL
, 0,
492 twl4030_micpathtx1_texts
);
494 static const struct snd_kcontrol_new twl4030_dapm_micpathtx1_control
=
495 SOC_DAPM_ENUM("Route", twl4030_micpathtx1_enum
);
497 /* TX2 L/R Analog/Digital microphone selection */
498 static const char *twl4030_micpathtx2_texts
[] =
499 {"Analog", "Digimic1"};
501 static SOC_ENUM_SINGLE_DECL(twl4030_micpathtx2_enum
,
502 TWL4030_REG_ADCMICSEL
, 2,
503 twl4030_micpathtx2_texts
);
505 static const struct snd_kcontrol_new twl4030_dapm_micpathtx2_control
=
506 SOC_DAPM_ENUM("Route", twl4030_micpathtx2_enum
);
508 /* Analog bypass for AudioR1 */
509 static const struct snd_kcontrol_new twl4030_dapm_abypassr1_control
=
510 SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXR1_APGA_CTL
, 2, 1, 0);
512 /* Analog bypass for AudioL1 */
513 static const struct snd_kcontrol_new twl4030_dapm_abypassl1_control
=
514 SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXL1_APGA_CTL
, 2, 1, 0);
516 /* Analog bypass for AudioR2 */
517 static const struct snd_kcontrol_new twl4030_dapm_abypassr2_control
=
518 SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXR2_APGA_CTL
, 2, 1, 0);
520 /* Analog bypass for AudioL2 */
521 static const struct snd_kcontrol_new twl4030_dapm_abypassl2_control
=
522 SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXL2_APGA_CTL
, 2, 1, 0);
524 /* Analog bypass for Voice */
525 static const struct snd_kcontrol_new twl4030_dapm_abypassv_control
=
526 SOC_DAPM_SINGLE("Switch", TWL4030_REG_VDL_APGA_CTL
, 2, 1, 0);
528 /* Digital bypass gain, mute instead of -30dB */
529 static const DECLARE_TLV_DB_RANGE(twl4030_dapm_dbypass_tlv
,
530 0, 1, TLV_DB_SCALE_ITEM(-3000, 600, 1),
531 2, 3, TLV_DB_SCALE_ITEM(-2400, 0, 0),
532 4, 7, TLV_DB_SCALE_ITEM(-1800, 600, 0)
535 /* Digital bypass left (TX1L -> RX2L) */
536 static const struct snd_kcontrol_new twl4030_dapm_dbypassl_control
=
537 SOC_DAPM_SINGLE_TLV("Volume",
538 TWL4030_REG_ATX2ARXPGA
, 3, 7, 0,
539 twl4030_dapm_dbypass_tlv
);
541 /* Digital bypass right (TX1R -> RX2R) */
542 static const struct snd_kcontrol_new twl4030_dapm_dbypassr_control
=
543 SOC_DAPM_SINGLE_TLV("Volume",
544 TWL4030_REG_ATX2ARXPGA
, 0, 7, 0,
545 twl4030_dapm_dbypass_tlv
);
548 * Voice Sidetone GAIN volume control:
549 * from -51 to -10 dB in 1 dB steps (mute instead of -51 dB)
551 static DECLARE_TLV_DB_SCALE(twl4030_dapm_dbypassv_tlv
, -5100, 100, 1);
553 /* Digital bypass voice: sidetone (VUL -> VDL)*/
554 static const struct snd_kcontrol_new twl4030_dapm_dbypassv_control
=
555 SOC_DAPM_SINGLE_TLV("Volume",
556 TWL4030_REG_VSTPGA
, 0, 0x29, 0,
557 twl4030_dapm_dbypassv_tlv
);
560 * Output PGA builder:
561 * Handle the muting and unmuting of the given output (turning off the
562 * amplifier associated with the output pin)
563 * On mute bypass the reg_cache and write 0 to the register
564 * On unmute: restore the register content from the reg_cache
565 * Outputs handled in this way: Earpiece, PreDrivL/R, CarkitL/R
567 #define TWL4030_OUTPUT_PGA(pin_name, reg, mask) \
568 static int pin_name##pga_event(struct snd_soc_dapm_widget *w, \
569 struct snd_kcontrol *kcontrol, int event) \
571 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); \
572 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); \
575 case SND_SOC_DAPM_POST_PMU: \
576 twl4030->pin_name##_enabled = 1; \
577 twl4030_write(codec, reg, twl4030_read(codec, reg)); \
579 case SND_SOC_DAPM_POST_PMD: \
580 twl4030->pin_name##_enabled = 0; \
581 twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, 0, reg); \
587 TWL4030_OUTPUT_PGA(earpiece
, TWL4030_REG_EAR_CTL
, TWL4030_EAR_GAIN
);
588 TWL4030_OUTPUT_PGA(predrivel
, TWL4030_REG_PREDL_CTL
, TWL4030_PREDL_GAIN
);
589 TWL4030_OUTPUT_PGA(predriver
, TWL4030_REG_PREDR_CTL
, TWL4030_PREDR_GAIN
);
590 TWL4030_OUTPUT_PGA(carkitl
, TWL4030_REG_PRECKL_CTL
, TWL4030_PRECKL_GAIN
);
591 TWL4030_OUTPUT_PGA(carkitr
, TWL4030_REG_PRECKR_CTL
, TWL4030_PRECKR_GAIN
);
593 static void handsfree_ramp(struct snd_soc_codec
*codec
, int reg
, int ramp
)
595 unsigned char hs_ctl
;
597 hs_ctl
= twl4030_read(codec
, reg
);
601 hs_ctl
|= TWL4030_HF_CTL_REF_EN
;
602 twl4030_write(codec
, reg
, hs_ctl
);
604 hs_ctl
|= TWL4030_HF_CTL_RAMP_EN
;
605 twl4030_write(codec
, reg
, hs_ctl
);
607 hs_ctl
|= TWL4030_HF_CTL_LOOP_EN
;
608 hs_ctl
|= TWL4030_HF_CTL_HB_EN
;
609 twl4030_write(codec
, reg
, hs_ctl
);
612 hs_ctl
&= ~TWL4030_HF_CTL_LOOP_EN
;
613 hs_ctl
&= ~TWL4030_HF_CTL_HB_EN
;
614 twl4030_write(codec
, reg
, hs_ctl
);
615 hs_ctl
&= ~TWL4030_HF_CTL_RAMP_EN
;
616 twl4030_write(codec
, reg
, hs_ctl
);
618 hs_ctl
&= ~TWL4030_HF_CTL_REF_EN
;
619 twl4030_write(codec
, reg
, hs_ctl
);
623 static int handsfreelpga_event(struct snd_soc_dapm_widget
*w
,
624 struct snd_kcontrol
*kcontrol
, int event
)
626 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
629 case SND_SOC_DAPM_POST_PMU
:
630 handsfree_ramp(codec
, TWL4030_REG_HFL_CTL
, 1);
632 case SND_SOC_DAPM_POST_PMD
:
633 handsfree_ramp(codec
, TWL4030_REG_HFL_CTL
, 0);
639 static int handsfreerpga_event(struct snd_soc_dapm_widget
*w
,
640 struct snd_kcontrol
*kcontrol
, int event
)
642 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
645 case SND_SOC_DAPM_POST_PMU
:
646 handsfree_ramp(codec
, TWL4030_REG_HFR_CTL
, 1);
648 case SND_SOC_DAPM_POST_PMD
:
649 handsfree_ramp(codec
, TWL4030_REG_HFR_CTL
, 0);
655 static int vibramux_event(struct snd_soc_dapm_widget
*w
,
656 struct snd_kcontrol
*kcontrol
, int event
)
658 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
660 twl4030_write(codec
, TWL4030_REG_VIBRA_SET
, 0xff);
664 static int apll_event(struct snd_soc_dapm_widget
*w
,
665 struct snd_kcontrol
*kcontrol
, int event
)
667 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
670 case SND_SOC_DAPM_PRE_PMU
:
671 twl4030_apll_enable(codec
, 1);
673 case SND_SOC_DAPM_POST_PMD
:
674 twl4030_apll_enable(codec
, 0);
680 static int aif_event(struct snd_soc_dapm_widget
*w
,
681 struct snd_kcontrol
*kcontrol
, int event
)
683 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
686 audio_if
= twl4030_read(codec
, TWL4030_REG_AUDIO_IF
);
688 case SND_SOC_DAPM_PRE_PMU
:
690 /* enable the PLL before we use it to clock the DAI */
691 twl4030_apll_enable(codec
, 1);
693 twl4030_write(codec
, TWL4030_REG_AUDIO_IF
,
694 audio_if
| TWL4030_AIF_EN
);
696 case SND_SOC_DAPM_POST_PMD
:
697 /* disable the DAI before we stop it's source PLL */
698 twl4030_write(codec
, TWL4030_REG_AUDIO_IF
,
699 audio_if
& ~TWL4030_AIF_EN
);
700 twl4030_apll_enable(codec
, 0);
706 static void headset_ramp(struct snd_soc_codec
*codec
, int ramp
)
708 unsigned char hs_gain
, hs_pop
;
709 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
710 struct twl4030_codec_data
*pdata
= twl4030
->pdata
;
711 /* Base values for ramp delay calculation: 2^19 - 2^26 */
712 unsigned int ramp_base
[] = {524288, 1048576, 2097152, 4194304,
713 8388608, 16777216, 33554432, 67108864};
716 hs_gain
= twl4030_read(codec
, TWL4030_REG_HS_GAIN_SET
);
717 hs_pop
= twl4030_read(codec
, TWL4030_REG_HS_POPN_SET
);
718 delay
= (ramp_base
[(hs_pop
& TWL4030_RAMP_DELAY
) >> 2] /
719 twl4030
->sysclk
) + 1;
721 /* Enable external mute control, this dramatically reduces
723 if (pdata
&& pdata
->hs_extmute
) {
724 if (gpio_is_valid(pdata
->hs_extmute_gpio
)) {
725 gpio_set_value(pdata
->hs_extmute_gpio
, 1);
727 hs_pop
|= TWL4030_EXTMUTE
;
728 twl4030_write(codec
, TWL4030_REG_HS_POPN_SET
, hs_pop
);
733 /* Headset ramp-up according to the TRM */
734 hs_pop
|= TWL4030_VMID_EN
;
735 twl4030_write(codec
, TWL4030_REG_HS_POPN_SET
, hs_pop
);
736 /* Actually write to the register */
737 twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE
, hs_gain
,
738 TWL4030_REG_HS_GAIN_SET
);
739 hs_pop
|= TWL4030_RAMP_EN
;
740 twl4030_write(codec
, TWL4030_REG_HS_POPN_SET
, hs_pop
);
741 /* Wait ramp delay time + 1, so the VMID can settle */
742 twl4030_wait_ms(delay
);
744 /* Headset ramp-down _not_ according to
745 * the TRM, but in a way that it is working */
746 hs_pop
&= ~TWL4030_RAMP_EN
;
747 twl4030_write(codec
, TWL4030_REG_HS_POPN_SET
, hs_pop
);
748 /* Wait ramp delay time + 1, so the VMID can settle */
749 twl4030_wait_ms(delay
);
750 /* Bypass the reg_cache to mute the headset */
751 twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE
, hs_gain
& (~0x0f),
752 TWL4030_REG_HS_GAIN_SET
);
754 hs_pop
&= ~TWL4030_VMID_EN
;
755 twl4030_write(codec
, TWL4030_REG_HS_POPN_SET
, hs_pop
);
758 /* Disable external mute */
759 if (pdata
&& pdata
->hs_extmute
) {
760 if (gpio_is_valid(pdata
->hs_extmute_gpio
)) {
761 gpio_set_value(pdata
->hs_extmute_gpio
, 0);
763 hs_pop
&= ~TWL4030_EXTMUTE
;
764 twl4030_write(codec
, TWL4030_REG_HS_POPN_SET
, hs_pop
);
769 static int headsetlpga_event(struct snd_soc_dapm_widget
*w
,
770 struct snd_kcontrol
*kcontrol
, int event
)
772 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
773 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
776 case SND_SOC_DAPM_POST_PMU
:
777 /* Do the ramp-up only once */
778 if (!twl4030
->hsr_enabled
)
779 headset_ramp(codec
, 1);
781 twl4030
->hsl_enabled
= 1;
783 case SND_SOC_DAPM_POST_PMD
:
784 /* Do the ramp-down only if both headsetL/R is disabled */
785 if (!twl4030
->hsr_enabled
)
786 headset_ramp(codec
, 0);
788 twl4030
->hsl_enabled
= 0;
794 static int headsetrpga_event(struct snd_soc_dapm_widget
*w
,
795 struct snd_kcontrol
*kcontrol
, int event
)
797 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
798 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
801 case SND_SOC_DAPM_POST_PMU
:
802 /* Do the ramp-up only once */
803 if (!twl4030
->hsl_enabled
)
804 headset_ramp(codec
, 1);
806 twl4030
->hsr_enabled
= 1;
808 case SND_SOC_DAPM_POST_PMD
:
809 /* Do the ramp-down only if both headsetL/R is disabled */
810 if (!twl4030
->hsl_enabled
)
811 headset_ramp(codec
, 0);
813 twl4030
->hsr_enabled
= 0;
819 static int digimic_event(struct snd_soc_dapm_widget
*w
,
820 struct snd_kcontrol
*kcontrol
, int event
)
822 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
823 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
824 struct twl4030_codec_data
*pdata
= twl4030
->pdata
;
826 if (pdata
&& pdata
->digimic_delay
)
827 twl4030_wait_ms(pdata
->digimic_delay
);
832 * Some of the gain controls in TWL (mostly those which are associated with
833 * the outputs) are implemented in an interesting way:
834 * 0x0 : Power down (mute)
838 * Inverting not going to help with these.
839 * Custom volsw and volsw_2r get/put functions to handle these gain bits.
841 static int snd_soc_get_volsw_twl4030(struct snd_kcontrol
*kcontrol
,
842 struct snd_ctl_elem_value
*ucontrol
)
844 struct soc_mixer_control
*mc
=
845 (struct soc_mixer_control
*)kcontrol
->private_value
;
846 struct snd_soc_codec
*codec
= snd_soc_kcontrol_codec(kcontrol
);
847 unsigned int reg
= mc
->reg
;
848 unsigned int shift
= mc
->shift
;
849 unsigned int rshift
= mc
->rshift
;
851 int mask
= (1 << fls(max
)) - 1;
853 ucontrol
->value
.integer
.value
[0] =
854 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
855 if (ucontrol
->value
.integer
.value
[0])
856 ucontrol
->value
.integer
.value
[0] =
857 max
+ 1 - ucontrol
->value
.integer
.value
[0];
859 if (shift
!= rshift
) {
860 ucontrol
->value
.integer
.value
[1] =
861 (snd_soc_read(codec
, reg
) >> rshift
) & mask
;
862 if (ucontrol
->value
.integer
.value
[1])
863 ucontrol
->value
.integer
.value
[1] =
864 max
+ 1 - ucontrol
->value
.integer
.value
[1];
870 static int snd_soc_put_volsw_twl4030(struct snd_kcontrol
*kcontrol
,
871 struct snd_ctl_elem_value
*ucontrol
)
873 struct soc_mixer_control
*mc
=
874 (struct soc_mixer_control
*)kcontrol
->private_value
;
875 struct snd_soc_codec
*codec
= snd_soc_kcontrol_codec(kcontrol
);
876 unsigned int reg
= mc
->reg
;
877 unsigned int shift
= mc
->shift
;
878 unsigned int rshift
= mc
->rshift
;
880 int mask
= (1 << fls(max
)) - 1;
881 unsigned short val
, val2
, val_mask
;
883 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
885 val_mask
= mask
<< shift
;
889 if (shift
!= rshift
) {
890 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
891 val_mask
|= mask
<< rshift
;
893 val2
= max
+ 1 - val2
;
894 val
|= val2
<< rshift
;
896 return snd_soc_update_bits(codec
, reg
, val_mask
, val
);
899 static int snd_soc_get_volsw_r2_twl4030(struct snd_kcontrol
*kcontrol
,
900 struct snd_ctl_elem_value
*ucontrol
)
902 struct soc_mixer_control
*mc
=
903 (struct soc_mixer_control
*)kcontrol
->private_value
;
904 struct snd_soc_codec
*codec
= snd_soc_kcontrol_codec(kcontrol
);
905 unsigned int reg
= mc
->reg
;
906 unsigned int reg2
= mc
->rreg
;
907 unsigned int shift
= mc
->shift
;
909 int mask
= (1<<fls(max
))-1;
911 ucontrol
->value
.integer
.value
[0] =
912 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
913 ucontrol
->value
.integer
.value
[1] =
914 (snd_soc_read(codec
, reg2
) >> shift
) & mask
;
916 if (ucontrol
->value
.integer
.value
[0])
917 ucontrol
->value
.integer
.value
[0] =
918 max
+ 1 - ucontrol
->value
.integer
.value
[0];
919 if (ucontrol
->value
.integer
.value
[1])
920 ucontrol
->value
.integer
.value
[1] =
921 max
+ 1 - ucontrol
->value
.integer
.value
[1];
926 static int snd_soc_put_volsw_r2_twl4030(struct snd_kcontrol
*kcontrol
,
927 struct snd_ctl_elem_value
*ucontrol
)
929 struct soc_mixer_control
*mc
=
930 (struct soc_mixer_control
*)kcontrol
->private_value
;
931 struct snd_soc_codec
*codec
= snd_soc_kcontrol_codec(kcontrol
);
932 unsigned int reg
= mc
->reg
;
933 unsigned int reg2
= mc
->rreg
;
934 unsigned int shift
= mc
->shift
;
936 int mask
= (1 << fls(max
)) - 1;
938 unsigned short val
, val2
, val_mask
;
940 val_mask
= mask
<< shift
;
941 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
942 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
947 val2
= max
+ 1 - val2
;
950 val2
= val2
<< shift
;
952 err
= snd_soc_update_bits(codec
, reg
, val_mask
, val
);
956 err
= snd_soc_update_bits(codec
, reg2
, val_mask
, val2
);
960 /* Codec operation modes */
961 static const char *twl4030_op_modes_texts
[] = {
962 "Option 2 (voice/audio)", "Option 1 (audio)"
965 static SOC_ENUM_SINGLE_DECL(twl4030_op_modes_enum
,
966 TWL4030_REG_CODEC_MODE
, 0,
967 twl4030_op_modes_texts
);
969 static int snd_soc_put_twl4030_opmode_enum_double(struct snd_kcontrol
*kcontrol
,
970 struct snd_ctl_elem_value
*ucontrol
)
972 struct snd_soc_codec
*codec
= snd_soc_kcontrol_codec(kcontrol
);
973 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
975 if (twl4030
->configured
) {
977 "operation mode cannot be changed on-the-fly\n");
981 return snd_soc_put_enum_double(kcontrol
, ucontrol
);
985 * FGAIN volume control:
986 * from -62 to 0 dB in 1 dB steps (mute instead of -63 dB)
988 static DECLARE_TLV_DB_SCALE(digital_fine_tlv
, -6300, 100, 1);
991 * CGAIN volume control:
992 * 0 dB to 12 dB in 6 dB steps
993 * value 2 and 3 means 12 dB
995 static DECLARE_TLV_DB_SCALE(digital_coarse_tlv
, 0, 600, 0);
998 * Voice Downlink GAIN volume control:
999 * from -37 to 12 dB in 1 dB steps (mute instead of -37 dB)
1001 static DECLARE_TLV_DB_SCALE(digital_voice_downlink_tlv
, -3700, 100, 1);
1004 * Analog playback gain
1005 * -24 dB to 12 dB in 2 dB steps
1007 static DECLARE_TLV_DB_SCALE(analog_tlv
, -2400, 200, 0);
1010 * Gain controls tied to outputs
1011 * -6 dB to 6 dB in 6 dB steps (mute instead of -12)
1013 static DECLARE_TLV_DB_SCALE(output_tvl
, -1200, 600, 1);
1016 * Gain control for earpiece amplifier
1017 * 0 dB to 12 dB in 6 dB steps (mute instead of -6)
1019 static DECLARE_TLV_DB_SCALE(output_ear_tvl
, -600, 600, 1);
1022 * Capture gain after the ADCs
1023 * from 0 dB to 31 dB in 1 dB steps
1025 static DECLARE_TLV_DB_SCALE(digital_capture_tlv
, 0, 100, 0);
1028 * Gain control for input amplifiers
1029 * 0 dB to 30 dB in 6 dB steps
1031 static DECLARE_TLV_DB_SCALE(input_gain_tlv
, 0, 600, 0);
1033 /* AVADC clock priority */
1034 static const char *twl4030_avadc_clk_priority_texts
[] = {
1035 "Voice high priority", "HiFi high priority"
1038 static SOC_ENUM_SINGLE_DECL(twl4030_avadc_clk_priority_enum
,
1039 TWL4030_REG_AVADC_CTL
, 2,
1040 twl4030_avadc_clk_priority_texts
);
1042 static const char *twl4030_rampdelay_texts
[] = {
1043 "27/20/14 ms", "55/40/27 ms", "109/81/55 ms", "218/161/109 ms",
1044 "437/323/218 ms", "874/645/437 ms", "1748/1291/874 ms",
1048 static SOC_ENUM_SINGLE_DECL(twl4030_rampdelay_enum
,
1049 TWL4030_REG_HS_POPN_SET
, 2,
1050 twl4030_rampdelay_texts
);
1052 /* Vibra H-bridge direction mode */
1053 static const char *twl4030_vibradirmode_texts
[] = {
1054 "Vibra H-bridge direction", "Audio data MSB",
1057 static SOC_ENUM_SINGLE_DECL(twl4030_vibradirmode_enum
,
1058 TWL4030_REG_VIBRA_CTL
, 5,
1059 twl4030_vibradirmode_texts
);
1061 /* Vibra H-bridge direction */
1062 static const char *twl4030_vibradir_texts
[] = {
1063 "Positive polarity", "Negative polarity",
1066 static SOC_ENUM_SINGLE_DECL(twl4030_vibradir_enum
,
1067 TWL4030_REG_VIBRA_CTL
, 1,
1068 twl4030_vibradir_texts
);
1070 /* Digimic Left and right swapping */
1071 static const char *twl4030_digimicswap_texts
[] = {
1072 "Not swapped", "Swapped",
1075 static SOC_ENUM_SINGLE_DECL(twl4030_digimicswap_enum
,
1076 TWL4030_REG_MISC_SET_1
, 0,
1077 twl4030_digimicswap_texts
);
1079 static const struct snd_kcontrol_new twl4030_snd_controls
[] = {
1080 /* Codec operation mode control */
1081 SOC_ENUM_EXT("Codec Operation Mode", twl4030_op_modes_enum
,
1082 snd_soc_get_enum_double
,
1083 snd_soc_put_twl4030_opmode_enum_double
),
1085 /* Common playback gain controls */
1086 SOC_DOUBLE_R_TLV("DAC1 Digital Fine Playback Volume",
1087 TWL4030_REG_ARXL1PGA
, TWL4030_REG_ARXR1PGA
,
1088 0, 0x3f, 0, digital_fine_tlv
),
1089 SOC_DOUBLE_R_TLV("DAC2 Digital Fine Playback Volume",
1090 TWL4030_REG_ARXL2PGA
, TWL4030_REG_ARXR2PGA
,
1091 0, 0x3f, 0, digital_fine_tlv
),
1093 SOC_DOUBLE_R_TLV("DAC1 Digital Coarse Playback Volume",
1094 TWL4030_REG_ARXL1PGA
, TWL4030_REG_ARXR1PGA
,
1095 6, 0x2, 0, digital_coarse_tlv
),
1096 SOC_DOUBLE_R_TLV("DAC2 Digital Coarse Playback Volume",
1097 TWL4030_REG_ARXL2PGA
, TWL4030_REG_ARXR2PGA
,
1098 6, 0x2, 0, digital_coarse_tlv
),
1100 SOC_DOUBLE_R_TLV("DAC1 Analog Playback Volume",
1101 TWL4030_REG_ARXL1_APGA_CTL
, TWL4030_REG_ARXR1_APGA_CTL
,
1102 3, 0x12, 1, analog_tlv
),
1103 SOC_DOUBLE_R_TLV("DAC2 Analog Playback Volume",
1104 TWL4030_REG_ARXL2_APGA_CTL
, TWL4030_REG_ARXR2_APGA_CTL
,
1105 3, 0x12, 1, analog_tlv
),
1106 SOC_DOUBLE_R("DAC1 Analog Playback Switch",
1107 TWL4030_REG_ARXL1_APGA_CTL
, TWL4030_REG_ARXR1_APGA_CTL
,
1109 SOC_DOUBLE_R("DAC2 Analog Playback Switch",
1110 TWL4030_REG_ARXL2_APGA_CTL
, TWL4030_REG_ARXR2_APGA_CTL
,
1113 /* Common voice downlink gain controls */
1114 SOC_SINGLE_TLV("DAC Voice Digital Downlink Volume",
1115 TWL4030_REG_VRXPGA
, 0, 0x31, 0, digital_voice_downlink_tlv
),
1117 SOC_SINGLE_TLV("DAC Voice Analog Downlink Volume",
1118 TWL4030_REG_VDL_APGA_CTL
, 3, 0x12, 1, analog_tlv
),
1120 SOC_SINGLE("DAC Voice Analog Downlink Switch",
1121 TWL4030_REG_VDL_APGA_CTL
, 1, 1, 0),
1123 /* Separate output gain controls */
1124 SOC_DOUBLE_R_EXT_TLV("PreDriv Playback Volume",
1125 TWL4030_REG_PREDL_CTL
, TWL4030_REG_PREDR_CTL
,
1126 4, 3, 0, snd_soc_get_volsw_r2_twl4030
,
1127 snd_soc_put_volsw_r2_twl4030
, output_tvl
),
1129 SOC_DOUBLE_EXT_TLV("Headset Playback Volume",
1130 TWL4030_REG_HS_GAIN_SET
, 0, 2, 3, 0, snd_soc_get_volsw_twl4030
,
1131 snd_soc_put_volsw_twl4030
, output_tvl
),
1133 SOC_DOUBLE_R_EXT_TLV("Carkit Playback Volume",
1134 TWL4030_REG_PRECKL_CTL
, TWL4030_REG_PRECKR_CTL
,
1135 4, 3, 0, snd_soc_get_volsw_r2_twl4030
,
1136 snd_soc_put_volsw_r2_twl4030
, output_tvl
),
1138 SOC_SINGLE_EXT_TLV("Earpiece Playback Volume",
1139 TWL4030_REG_EAR_CTL
, 4, 3, 0, snd_soc_get_volsw_twl4030
,
1140 snd_soc_put_volsw_twl4030
, output_ear_tvl
),
1142 /* Common capture gain controls */
1143 SOC_DOUBLE_R_TLV("TX1 Digital Capture Volume",
1144 TWL4030_REG_ATXL1PGA
, TWL4030_REG_ATXR1PGA
,
1145 0, 0x1f, 0, digital_capture_tlv
),
1146 SOC_DOUBLE_R_TLV("TX2 Digital Capture Volume",
1147 TWL4030_REG_AVTXL2PGA
, TWL4030_REG_AVTXR2PGA
,
1148 0, 0x1f, 0, digital_capture_tlv
),
1150 SOC_DOUBLE_TLV("Analog Capture Volume", TWL4030_REG_ANAMIC_GAIN
,
1151 0, 3, 5, 0, input_gain_tlv
),
1153 SOC_ENUM("AVADC Clock Priority", twl4030_avadc_clk_priority_enum
),
1155 SOC_ENUM("HS ramp delay", twl4030_rampdelay_enum
),
1157 SOC_ENUM("Vibra H-bridge mode", twl4030_vibradirmode_enum
),
1158 SOC_ENUM("Vibra H-bridge direction", twl4030_vibradir_enum
),
1160 SOC_ENUM("Digimic LR Swap", twl4030_digimicswap_enum
),
1163 static const struct snd_soc_dapm_widget twl4030_dapm_widgets
[] = {
1164 /* Left channel inputs */
1165 SND_SOC_DAPM_INPUT("MAINMIC"),
1166 SND_SOC_DAPM_INPUT("HSMIC"),
1167 SND_SOC_DAPM_INPUT("AUXL"),
1168 SND_SOC_DAPM_INPUT("CARKITMIC"),
1169 /* Right channel inputs */
1170 SND_SOC_DAPM_INPUT("SUBMIC"),
1171 SND_SOC_DAPM_INPUT("AUXR"),
1172 /* Digital microphones (Stereo) */
1173 SND_SOC_DAPM_INPUT("DIGIMIC0"),
1174 SND_SOC_DAPM_INPUT("DIGIMIC1"),
1177 SND_SOC_DAPM_OUTPUT("EARPIECE"),
1178 SND_SOC_DAPM_OUTPUT("PREDRIVEL"),
1179 SND_SOC_DAPM_OUTPUT("PREDRIVER"),
1180 SND_SOC_DAPM_OUTPUT("HSOL"),
1181 SND_SOC_DAPM_OUTPUT("HSOR"),
1182 SND_SOC_DAPM_OUTPUT("CARKITL"),
1183 SND_SOC_DAPM_OUTPUT("CARKITR"),
1184 SND_SOC_DAPM_OUTPUT("HFL"),
1185 SND_SOC_DAPM_OUTPUT("HFR"),
1186 SND_SOC_DAPM_OUTPUT("VIBRA"),
1188 /* AIF and APLL clocks for running DAIs (including loopback) */
1189 SND_SOC_DAPM_OUTPUT("Virtual HiFi OUT"),
1190 SND_SOC_DAPM_INPUT("Virtual HiFi IN"),
1191 SND_SOC_DAPM_OUTPUT("Virtual Voice OUT"),
1194 SND_SOC_DAPM_DAC("DAC Right1", NULL
, SND_SOC_NOPM
, 0, 0),
1195 SND_SOC_DAPM_DAC("DAC Left1", NULL
, SND_SOC_NOPM
, 0, 0),
1196 SND_SOC_DAPM_DAC("DAC Right2", NULL
, SND_SOC_NOPM
, 0, 0),
1197 SND_SOC_DAPM_DAC("DAC Left2", NULL
, SND_SOC_NOPM
, 0, 0),
1198 SND_SOC_DAPM_DAC("DAC Voice", NULL
, SND_SOC_NOPM
, 0, 0),
1200 SND_SOC_DAPM_AIF_IN("VAIFIN", "Voice Playback", 0,
1201 TWL4030_REG_VOICE_IF
, 6, 0),
1203 /* Analog bypasses */
1204 SND_SOC_DAPM_SWITCH("Right1 Analog Loopback", SND_SOC_NOPM
, 0, 0,
1205 &twl4030_dapm_abypassr1_control
),
1206 SND_SOC_DAPM_SWITCH("Left1 Analog Loopback", SND_SOC_NOPM
, 0, 0,
1207 &twl4030_dapm_abypassl1_control
),
1208 SND_SOC_DAPM_SWITCH("Right2 Analog Loopback", SND_SOC_NOPM
, 0, 0,
1209 &twl4030_dapm_abypassr2_control
),
1210 SND_SOC_DAPM_SWITCH("Left2 Analog Loopback", SND_SOC_NOPM
, 0, 0,
1211 &twl4030_dapm_abypassl2_control
),
1212 SND_SOC_DAPM_SWITCH("Voice Analog Loopback", SND_SOC_NOPM
, 0, 0,
1213 &twl4030_dapm_abypassv_control
),
1215 /* Master analog loopback switch */
1216 SND_SOC_DAPM_SUPPLY("FM Loop Enable", TWL4030_REG_MISC_SET_1
, 5, 0,
1219 /* Digital bypasses */
1220 SND_SOC_DAPM_SWITCH("Left Digital Loopback", SND_SOC_NOPM
, 0, 0,
1221 &twl4030_dapm_dbypassl_control
),
1222 SND_SOC_DAPM_SWITCH("Right Digital Loopback", SND_SOC_NOPM
, 0, 0,
1223 &twl4030_dapm_dbypassr_control
),
1224 SND_SOC_DAPM_SWITCH("Voice Digital Loopback", SND_SOC_NOPM
, 0, 0,
1225 &twl4030_dapm_dbypassv_control
),
1227 /* Digital mixers, power control for the physical DACs */
1228 SND_SOC_DAPM_MIXER("Digital R1 Playback Mixer",
1229 TWL4030_REG_AVDAC_CTL
, 0, 0, NULL
, 0),
1230 SND_SOC_DAPM_MIXER("Digital L1 Playback Mixer",
1231 TWL4030_REG_AVDAC_CTL
, 1, 0, NULL
, 0),
1232 SND_SOC_DAPM_MIXER("Digital R2 Playback Mixer",
1233 TWL4030_REG_AVDAC_CTL
, 2, 0, NULL
, 0),
1234 SND_SOC_DAPM_MIXER("Digital L2 Playback Mixer",
1235 TWL4030_REG_AVDAC_CTL
, 3, 0, NULL
, 0),
1236 SND_SOC_DAPM_MIXER("Digital Voice Playback Mixer",
1237 TWL4030_REG_AVDAC_CTL
, 4, 0, NULL
, 0),
1239 /* Analog mixers, power control for the physical PGAs */
1240 SND_SOC_DAPM_MIXER("Analog R1 Playback Mixer",
1241 TWL4030_REG_ARXR1_APGA_CTL
, 0, 0, NULL
, 0),
1242 SND_SOC_DAPM_MIXER("Analog L1 Playback Mixer",
1243 TWL4030_REG_ARXL1_APGA_CTL
, 0, 0, NULL
, 0),
1244 SND_SOC_DAPM_MIXER("Analog R2 Playback Mixer",
1245 TWL4030_REG_ARXR2_APGA_CTL
, 0, 0, NULL
, 0),
1246 SND_SOC_DAPM_MIXER("Analog L2 Playback Mixer",
1247 TWL4030_REG_ARXL2_APGA_CTL
, 0, 0, NULL
, 0),
1248 SND_SOC_DAPM_MIXER("Analog Voice Playback Mixer",
1249 TWL4030_REG_VDL_APGA_CTL
, 0, 0, NULL
, 0),
1251 SND_SOC_DAPM_SUPPLY("APLL Enable", SND_SOC_NOPM
, 0, 0, apll_event
,
1252 SND_SOC_DAPM_PRE_PMU
|SND_SOC_DAPM_POST_PMD
),
1254 SND_SOC_DAPM_SUPPLY("AIF Enable", SND_SOC_NOPM
, 0, 0, aif_event
,
1255 SND_SOC_DAPM_PRE_PMU
|SND_SOC_DAPM_POST_PMD
),
1257 /* Output MIXER controls */
1259 SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM
, 0, 0,
1260 &twl4030_dapm_earpiece_controls
[0],
1261 ARRAY_SIZE(twl4030_dapm_earpiece_controls
)),
1262 SND_SOC_DAPM_PGA_E("Earpiece PGA", SND_SOC_NOPM
,
1263 0, 0, NULL
, 0, earpiecepga_event
,
1264 SND_SOC_DAPM_POST_PMU
|SND_SOC_DAPM_POST_PMD
),
1266 SND_SOC_DAPM_MIXER("PredriveL Mixer", SND_SOC_NOPM
, 0, 0,
1267 &twl4030_dapm_predrivel_controls
[0],
1268 ARRAY_SIZE(twl4030_dapm_predrivel_controls
)),
1269 SND_SOC_DAPM_PGA_E("PredriveL PGA", SND_SOC_NOPM
,
1270 0, 0, NULL
, 0, predrivelpga_event
,
1271 SND_SOC_DAPM_POST_PMU
|SND_SOC_DAPM_POST_PMD
),
1272 SND_SOC_DAPM_MIXER("PredriveR Mixer", SND_SOC_NOPM
, 0, 0,
1273 &twl4030_dapm_predriver_controls
[0],
1274 ARRAY_SIZE(twl4030_dapm_predriver_controls
)),
1275 SND_SOC_DAPM_PGA_E("PredriveR PGA", SND_SOC_NOPM
,
1276 0, 0, NULL
, 0, predriverpga_event
,
1277 SND_SOC_DAPM_POST_PMU
|SND_SOC_DAPM_POST_PMD
),
1279 SND_SOC_DAPM_MIXER("HeadsetL Mixer", SND_SOC_NOPM
, 0, 0,
1280 &twl4030_dapm_hsol_controls
[0],
1281 ARRAY_SIZE(twl4030_dapm_hsol_controls
)),
1282 SND_SOC_DAPM_PGA_E("HeadsetL PGA", SND_SOC_NOPM
,
1283 0, 0, NULL
, 0, headsetlpga_event
,
1284 SND_SOC_DAPM_POST_PMU
|SND_SOC_DAPM_POST_PMD
),
1285 SND_SOC_DAPM_MIXER("HeadsetR Mixer", SND_SOC_NOPM
, 0, 0,
1286 &twl4030_dapm_hsor_controls
[0],
1287 ARRAY_SIZE(twl4030_dapm_hsor_controls
)),
1288 SND_SOC_DAPM_PGA_E("HeadsetR PGA", SND_SOC_NOPM
,
1289 0, 0, NULL
, 0, headsetrpga_event
,
1290 SND_SOC_DAPM_POST_PMU
|SND_SOC_DAPM_POST_PMD
),
1292 SND_SOC_DAPM_MIXER("CarkitL Mixer", SND_SOC_NOPM
, 0, 0,
1293 &twl4030_dapm_carkitl_controls
[0],
1294 ARRAY_SIZE(twl4030_dapm_carkitl_controls
)),
1295 SND_SOC_DAPM_PGA_E("CarkitL PGA", SND_SOC_NOPM
,
1296 0, 0, NULL
, 0, carkitlpga_event
,
1297 SND_SOC_DAPM_POST_PMU
|SND_SOC_DAPM_POST_PMD
),
1298 SND_SOC_DAPM_MIXER("CarkitR Mixer", SND_SOC_NOPM
, 0, 0,
1299 &twl4030_dapm_carkitr_controls
[0],
1300 ARRAY_SIZE(twl4030_dapm_carkitr_controls
)),
1301 SND_SOC_DAPM_PGA_E("CarkitR PGA", SND_SOC_NOPM
,
1302 0, 0, NULL
, 0, carkitrpga_event
,
1303 SND_SOC_DAPM_POST_PMU
|SND_SOC_DAPM_POST_PMD
),
1305 /* Output MUX controls */
1307 SND_SOC_DAPM_MUX("HandsfreeL Mux", SND_SOC_NOPM
, 0, 0,
1308 &twl4030_dapm_handsfreel_control
),
1309 SND_SOC_DAPM_SWITCH("HandsfreeL", SND_SOC_NOPM
, 0, 0,
1310 &twl4030_dapm_handsfreelmute_control
),
1311 SND_SOC_DAPM_PGA_E("HandsfreeL PGA", SND_SOC_NOPM
,
1312 0, 0, NULL
, 0, handsfreelpga_event
,
1313 SND_SOC_DAPM_POST_PMU
|SND_SOC_DAPM_POST_PMD
),
1314 SND_SOC_DAPM_MUX("HandsfreeR Mux", SND_SOC_NOPM
, 5, 0,
1315 &twl4030_dapm_handsfreer_control
),
1316 SND_SOC_DAPM_SWITCH("HandsfreeR", SND_SOC_NOPM
, 0, 0,
1317 &twl4030_dapm_handsfreermute_control
),
1318 SND_SOC_DAPM_PGA_E("HandsfreeR PGA", SND_SOC_NOPM
,
1319 0, 0, NULL
, 0, handsfreerpga_event
,
1320 SND_SOC_DAPM_POST_PMU
|SND_SOC_DAPM_POST_PMD
),
1322 SND_SOC_DAPM_MUX_E("Vibra Mux", TWL4030_REG_VIBRA_CTL
, 0, 0,
1323 &twl4030_dapm_vibra_control
, vibramux_event
,
1324 SND_SOC_DAPM_PRE_PMU
),
1325 SND_SOC_DAPM_MUX("Vibra Route", SND_SOC_NOPM
, 0, 0,
1326 &twl4030_dapm_vibrapath_control
),
1328 /* Introducing four virtual ADC, since TWL4030 have four channel for
1330 SND_SOC_DAPM_ADC("ADC Virtual Left1", NULL
, SND_SOC_NOPM
, 0, 0),
1331 SND_SOC_DAPM_ADC("ADC Virtual Right1", NULL
, SND_SOC_NOPM
, 0, 0),
1332 SND_SOC_DAPM_ADC("ADC Virtual Left2", NULL
, SND_SOC_NOPM
, 0, 0),
1333 SND_SOC_DAPM_ADC("ADC Virtual Right2", NULL
, SND_SOC_NOPM
, 0, 0),
1335 SND_SOC_DAPM_AIF_OUT("VAIFOUT", "Voice Capture", 0,
1336 TWL4030_REG_VOICE_IF
, 5, 0),
1338 /* Analog/Digital mic path selection.
1339 TX1 Left/Right: either analog Left/Right or Digimic0
1340 TX2 Left/Right: either analog Left/Right or Digimic1 */
1341 SND_SOC_DAPM_MUX("TX1 Capture Route", SND_SOC_NOPM
, 0, 0,
1342 &twl4030_dapm_micpathtx1_control
),
1343 SND_SOC_DAPM_MUX("TX2 Capture Route", SND_SOC_NOPM
, 0, 0,
1344 &twl4030_dapm_micpathtx2_control
),
1346 /* Analog input mixers for the capture amplifiers */
1347 SND_SOC_DAPM_MIXER("Analog Left",
1348 TWL4030_REG_ANAMICL
, 4, 0,
1349 &twl4030_dapm_analoglmic_controls
[0],
1350 ARRAY_SIZE(twl4030_dapm_analoglmic_controls
)),
1351 SND_SOC_DAPM_MIXER("Analog Right",
1352 TWL4030_REG_ANAMICR
, 4, 0,
1353 &twl4030_dapm_analogrmic_controls
[0],
1354 ARRAY_SIZE(twl4030_dapm_analogrmic_controls
)),
1356 SND_SOC_DAPM_PGA("ADC Physical Left",
1357 TWL4030_REG_AVADC_CTL
, 3, 0, NULL
, 0),
1358 SND_SOC_DAPM_PGA("ADC Physical Right",
1359 TWL4030_REG_AVADC_CTL
, 1, 0, NULL
, 0),
1361 SND_SOC_DAPM_PGA_E("Digimic0 Enable",
1362 TWL4030_REG_ADCMICSEL
, 1, 0, NULL
, 0,
1363 digimic_event
, SND_SOC_DAPM_POST_PMU
),
1364 SND_SOC_DAPM_PGA_E("Digimic1 Enable",
1365 TWL4030_REG_ADCMICSEL
, 3, 0, NULL
, 0,
1366 digimic_event
, SND_SOC_DAPM_POST_PMU
),
1368 SND_SOC_DAPM_SUPPLY("micbias1 select", TWL4030_REG_MICBIAS_CTL
, 5, 0,
1370 SND_SOC_DAPM_SUPPLY("micbias2 select", TWL4030_REG_MICBIAS_CTL
, 6, 0,
1373 /* Microphone bias */
1374 SND_SOC_DAPM_SUPPLY("Mic Bias 1",
1375 TWL4030_REG_MICBIAS_CTL
, 0, 0, NULL
, 0),
1376 SND_SOC_DAPM_SUPPLY("Mic Bias 2",
1377 TWL4030_REG_MICBIAS_CTL
, 1, 0, NULL
, 0),
1378 SND_SOC_DAPM_SUPPLY("Headset Mic Bias",
1379 TWL4030_REG_MICBIAS_CTL
, 2, 0, NULL
, 0),
1381 SND_SOC_DAPM_SUPPLY("VIF Enable", TWL4030_REG_VOICE_IF
, 0, 0, NULL
, 0),
1384 static const struct snd_soc_dapm_route intercon
[] = {
1385 /* Stream -> DAC mapping */
1386 {"DAC Right1", NULL
, "HiFi Playback"},
1387 {"DAC Left1", NULL
, "HiFi Playback"},
1388 {"DAC Right2", NULL
, "HiFi Playback"},
1389 {"DAC Left2", NULL
, "HiFi Playback"},
1390 {"DAC Voice", NULL
, "VAIFIN"},
1392 /* ADC -> Stream mapping */
1393 {"HiFi Capture", NULL
, "ADC Virtual Left1"},
1394 {"HiFi Capture", NULL
, "ADC Virtual Right1"},
1395 {"HiFi Capture", NULL
, "ADC Virtual Left2"},
1396 {"HiFi Capture", NULL
, "ADC Virtual Right2"},
1397 {"VAIFOUT", NULL
, "ADC Virtual Left2"},
1398 {"VAIFOUT", NULL
, "ADC Virtual Right2"},
1399 {"VAIFOUT", NULL
, "VIF Enable"},
1401 {"Digital L1 Playback Mixer", NULL
, "DAC Left1"},
1402 {"Digital R1 Playback Mixer", NULL
, "DAC Right1"},
1403 {"Digital L2 Playback Mixer", NULL
, "DAC Left2"},
1404 {"Digital R2 Playback Mixer", NULL
, "DAC Right2"},
1405 {"Digital Voice Playback Mixer", NULL
, "DAC Voice"},
1407 /* Supply for the digital part (APLL) */
1408 {"Digital Voice Playback Mixer", NULL
, "APLL Enable"},
1410 {"DAC Left1", NULL
, "AIF Enable"},
1411 {"DAC Right1", NULL
, "AIF Enable"},
1412 {"DAC Left2", NULL
, "AIF Enable"},
1413 {"DAC Right1", NULL
, "AIF Enable"},
1414 {"DAC Voice", NULL
, "VIF Enable"},
1416 {"Digital R2 Playback Mixer", NULL
, "AIF Enable"},
1417 {"Digital L2 Playback Mixer", NULL
, "AIF Enable"},
1419 {"Analog L1 Playback Mixer", NULL
, "Digital L1 Playback Mixer"},
1420 {"Analog R1 Playback Mixer", NULL
, "Digital R1 Playback Mixer"},
1421 {"Analog L2 Playback Mixer", NULL
, "Digital L2 Playback Mixer"},
1422 {"Analog R2 Playback Mixer", NULL
, "Digital R2 Playback Mixer"},
1423 {"Analog Voice Playback Mixer", NULL
, "Digital Voice Playback Mixer"},
1425 /* Internal playback routings */
1427 {"Earpiece Mixer", "Voice", "Analog Voice Playback Mixer"},
1428 {"Earpiece Mixer", "AudioL1", "Analog L1 Playback Mixer"},
1429 {"Earpiece Mixer", "AudioL2", "Analog L2 Playback Mixer"},
1430 {"Earpiece Mixer", "AudioR1", "Analog R1 Playback Mixer"},
1431 {"Earpiece PGA", NULL
, "Earpiece Mixer"},
1433 {"PredriveL Mixer", "Voice", "Analog Voice Playback Mixer"},
1434 {"PredriveL Mixer", "AudioL1", "Analog L1 Playback Mixer"},
1435 {"PredriveL Mixer", "AudioL2", "Analog L2 Playback Mixer"},
1436 {"PredriveL Mixer", "AudioR2", "Analog R2 Playback Mixer"},
1437 {"PredriveL PGA", NULL
, "PredriveL Mixer"},
1439 {"PredriveR Mixer", "Voice", "Analog Voice Playback Mixer"},
1440 {"PredriveR Mixer", "AudioR1", "Analog R1 Playback Mixer"},
1441 {"PredriveR Mixer", "AudioR2", "Analog R2 Playback Mixer"},
1442 {"PredriveR Mixer", "AudioL2", "Analog L2 Playback Mixer"},
1443 {"PredriveR PGA", NULL
, "PredriveR Mixer"},
1445 {"HeadsetL Mixer", "Voice", "Analog Voice Playback Mixer"},
1446 {"HeadsetL Mixer", "AudioL1", "Analog L1 Playback Mixer"},
1447 {"HeadsetL Mixer", "AudioL2", "Analog L2 Playback Mixer"},
1448 {"HeadsetL PGA", NULL
, "HeadsetL Mixer"},
1450 {"HeadsetR Mixer", "Voice", "Analog Voice Playback Mixer"},
1451 {"HeadsetR Mixer", "AudioR1", "Analog R1 Playback Mixer"},
1452 {"HeadsetR Mixer", "AudioR2", "Analog R2 Playback Mixer"},
1453 {"HeadsetR PGA", NULL
, "HeadsetR Mixer"},
1455 {"CarkitL Mixer", "Voice", "Analog Voice Playback Mixer"},
1456 {"CarkitL Mixer", "AudioL1", "Analog L1 Playback Mixer"},
1457 {"CarkitL Mixer", "AudioL2", "Analog L2 Playback Mixer"},
1458 {"CarkitL PGA", NULL
, "CarkitL Mixer"},
1460 {"CarkitR Mixer", "Voice", "Analog Voice Playback Mixer"},
1461 {"CarkitR Mixer", "AudioR1", "Analog R1 Playback Mixer"},
1462 {"CarkitR Mixer", "AudioR2", "Analog R2 Playback Mixer"},
1463 {"CarkitR PGA", NULL
, "CarkitR Mixer"},
1465 {"HandsfreeL Mux", "Voice", "Analog Voice Playback Mixer"},
1466 {"HandsfreeL Mux", "AudioL1", "Analog L1 Playback Mixer"},
1467 {"HandsfreeL Mux", "AudioL2", "Analog L2 Playback Mixer"},
1468 {"HandsfreeL Mux", "AudioR2", "Analog R2 Playback Mixer"},
1469 {"HandsfreeL", "Switch", "HandsfreeL Mux"},
1470 {"HandsfreeL PGA", NULL
, "HandsfreeL"},
1472 {"HandsfreeR Mux", "Voice", "Analog Voice Playback Mixer"},
1473 {"HandsfreeR Mux", "AudioR1", "Analog R1 Playback Mixer"},
1474 {"HandsfreeR Mux", "AudioR2", "Analog R2 Playback Mixer"},
1475 {"HandsfreeR Mux", "AudioL2", "Analog L2 Playback Mixer"},
1476 {"HandsfreeR", "Switch", "HandsfreeR Mux"},
1477 {"HandsfreeR PGA", NULL
, "HandsfreeR"},
1479 {"Vibra Mux", "AudioL1", "DAC Left1"},
1480 {"Vibra Mux", "AudioR1", "DAC Right1"},
1481 {"Vibra Mux", "AudioL2", "DAC Left2"},
1482 {"Vibra Mux", "AudioR2", "DAC Right2"},
1485 /* Must be always connected (for AIF and APLL) */
1486 {"Virtual HiFi OUT", NULL
, "DAC Left1"},
1487 {"Virtual HiFi OUT", NULL
, "DAC Right1"},
1488 {"Virtual HiFi OUT", NULL
, "DAC Left2"},
1489 {"Virtual HiFi OUT", NULL
, "DAC Right2"},
1490 /* Must be always connected (for APLL) */
1491 {"Virtual Voice OUT", NULL
, "Digital Voice Playback Mixer"},
1492 /* Physical outputs */
1493 {"EARPIECE", NULL
, "Earpiece PGA"},
1494 {"PREDRIVEL", NULL
, "PredriveL PGA"},
1495 {"PREDRIVER", NULL
, "PredriveR PGA"},
1496 {"HSOL", NULL
, "HeadsetL PGA"},
1497 {"HSOR", NULL
, "HeadsetR PGA"},
1498 {"CARKITL", NULL
, "CarkitL PGA"},
1499 {"CARKITR", NULL
, "CarkitR PGA"},
1500 {"HFL", NULL
, "HandsfreeL PGA"},
1501 {"HFR", NULL
, "HandsfreeR PGA"},
1502 {"Vibra Route", "Audio", "Vibra Mux"},
1503 {"VIBRA", NULL
, "Vibra Route"},
1506 /* Must be always connected (for AIF and APLL) */
1507 {"ADC Virtual Left1", NULL
, "Virtual HiFi IN"},
1508 {"ADC Virtual Right1", NULL
, "Virtual HiFi IN"},
1509 {"ADC Virtual Left2", NULL
, "Virtual HiFi IN"},
1510 {"ADC Virtual Right2", NULL
, "Virtual HiFi IN"},
1511 /* Physical inputs */
1512 {"Analog Left", "Main Mic Capture Switch", "MAINMIC"},
1513 {"Analog Left", "Headset Mic Capture Switch", "HSMIC"},
1514 {"Analog Left", "AUXL Capture Switch", "AUXL"},
1515 {"Analog Left", "Carkit Mic Capture Switch", "CARKITMIC"},
1517 {"Analog Right", "Sub Mic Capture Switch", "SUBMIC"},
1518 {"Analog Right", "AUXR Capture Switch", "AUXR"},
1520 {"ADC Physical Left", NULL
, "Analog Left"},
1521 {"ADC Physical Right", NULL
, "Analog Right"},
1523 {"Digimic0 Enable", NULL
, "DIGIMIC0"},
1524 {"Digimic1 Enable", NULL
, "DIGIMIC1"},
1526 {"DIGIMIC0", NULL
, "micbias1 select"},
1527 {"DIGIMIC1", NULL
, "micbias2 select"},
1529 /* TX1 Left capture path */
1530 {"TX1 Capture Route", "Analog", "ADC Physical Left"},
1531 {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"},
1532 /* TX1 Right capture path */
1533 {"TX1 Capture Route", "Analog", "ADC Physical Right"},
1534 {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"},
1535 /* TX2 Left capture path */
1536 {"TX2 Capture Route", "Analog", "ADC Physical Left"},
1537 {"TX2 Capture Route", "Digimic1", "Digimic1 Enable"},
1538 /* TX2 Right capture path */
1539 {"TX2 Capture Route", "Analog", "ADC Physical Right"},
1540 {"TX2 Capture Route", "Digimic1", "Digimic1 Enable"},
1542 {"ADC Virtual Left1", NULL
, "TX1 Capture Route"},
1543 {"ADC Virtual Right1", NULL
, "TX1 Capture Route"},
1544 {"ADC Virtual Left2", NULL
, "TX2 Capture Route"},
1545 {"ADC Virtual Right2", NULL
, "TX2 Capture Route"},
1547 {"ADC Virtual Left1", NULL
, "AIF Enable"},
1548 {"ADC Virtual Right1", NULL
, "AIF Enable"},
1549 {"ADC Virtual Left2", NULL
, "AIF Enable"},
1550 {"ADC Virtual Right2", NULL
, "AIF Enable"},
1552 /* Analog bypass routes */
1553 {"Right1 Analog Loopback", "Switch", "Analog Right"},
1554 {"Left1 Analog Loopback", "Switch", "Analog Left"},
1555 {"Right2 Analog Loopback", "Switch", "Analog Right"},
1556 {"Left2 Analog Loopback", "Switch", "Analog Left"},
1557 {"Voice Analog Loopback", "Switch", "Analog Left"},
1559 /* Supply for the Analog loopbacks */
1560 {"Right1 Analog Loopback", NULL
, "FM Loop Enable"},
1561 {"Left1 Analog Loopback", NULL
, "FM Loop Enable"},
1562 {"Right2 Analog Loopback", NULL
, "FM Loop Enable"},
1563 {"Left2 Analog Loopback", NULL
, "FM Loop Enable"},
1564 {"Voice Analog Loopback", NULL
, "FM Loop Enable"},
1566 {"Analog R1 Playback Mixer", NULL
, "Right1 Analog Loopback"},
1567 {"Analog L1 Playback Mixer", NULL
, "Left1 Analog Loopback"},
1568 {"Analog R2 Playback Mixer", NULL
, "Right2 Analog Loopback"},
1569 {"Analog L2 Playback Mixer", NULL
, "Left2 Analog Loopback"},
1570 {"Analog Voice Playback Mixer", NULL
, "Voice Analog Loopback"},
1572 /* Digital bypass routes */
1573 {"Right Digital Loopback", "Volume", "TX1 Capture Route"},
1574 {"Left Digital Loopback", "Volume", "TX1 Capture Route"},
1575 {"Voice Digital Loopback", "Volume", "TX2 Capture Route"},
1577 {"Digital R2 Playback Mixer", NULL
, "Right Digital Loopback"},
1578 {"Digital L2 Playback Mixer", NULL
, "Left Digital Loopback"},
1579 {"Digital Voice Playback Mixer", NULL
, "Voice Digital Loopback"},
1583 static int twl4030_set_bias_level(struct snd_soc_codec
*codec
,
1584 enum snd_soc_bias_level level
)
1587 case SND_SOC_BIAS_ON
:
1589 case SND_SOC_BIAS_PREPARE
:
1591 case SND_SOC_BIAS_STANDBY
:
1592 if (snd_soc_codec_get_bias_level(codec
) == SND_SOC_BIAS_OFF
)
1593 twl4030_codec_enable(codec
, 1);
1595 case SND_SOC_BIAS_OFF
:
1596 twl4030_codec_enable(codec
, 0);
1603 static void twl4030_constraints(struct twl4030_priv
*twl4030
,
1604 struct snd_pcm_substream
*mst_substream
)
1606 struct snd_pcm_substream
*slv_substream
;
1608 /* Pick the stream, which need to be constrained */
1609 if (mst_substream
== twl4030
->master_substream
)
1610 slv_substream
= twl4030
->slave_substream
;
1611 else if (mst_substream
== twl4030
->slave_substream
)
1612 slv_substream
= twl4030
->master_substream
;
1613 else /* This should not happen.. */
1616 /* Set the constraints according to the already configured stream */
1617 snd_pcm_hw_constraint_single(slv_substream
->runtime
,
1618 SNDRV_PCM_HW_PARAM_RATE
,
1621 snd_pcm_hw_constraint_single(slv_substream
->runtime
,
1622 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
1623 twl4030
->sample_bits
);
1625 snd_pcm_hw_constraint_single(slv_substream
->runtime
,
1626 SNDRV_PCM_HW_PARAM_CHANNELS
,
1630 /* In case of 4 channel mode, the RX1 L/R for playback and the TX2 L/R for
1631 * capture has to be enabled/disabled. */
1632 static void twl4030_tdm_enable(struct snd_soc_codec
*codec
, int direction
,
1637 reg
= twl4030_read(codec
, TWL4030_REG_OPTION
);
1639 if (direction
== SNDRV_PCM_STREAM_PLAYBACK
)
1640 mask
= TWL4030_ARXL1_VRX_EN
| TWL4030_ARXR1_EN
;
1642 mask
= TWL4030_ATXL2_VTXL_EN
| TWL4030_ATXR2_VTXR_EN
;
1649 twl4030_write(codec
, TWL4030_REG_OPTION
, reg
);
1652 static int twl4030_startup(struct snd_pcm_substream
*substream
,
1653 struct snd_soc_dai
*dai
)
1655 struct snd_soc_codec
*codec
= dai
->codec
;
1656 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
1658 if (twl4030
->master_substream
) {
1659 twl4030
->slave_substream
= substream
;
1660 /* The DAI has one configuration for playback and capture, so
1661 * if the DAI has been already configured then constrain this
1662 * substream to match it. */
1663 if (twl4030
->configured
)
1664 twl4030_constraints(twl4030
, twl4030
->master_substream
);
1666 if (!(twl4030_read(codec
, TWL4030_REG_CODEC_MODE
) &
1667 TWL4030_OPTION_1
)) {
1668 /* In option2 4 channel is not supported, set the
1669 * constraint for the first stream for channels, the
1670 * second stream will 'inherit' this cosntraint */
1671 snd_pcm_hw_constraint_single(substream
->runtime
,
1672 SNDRV_PCM_HW_PARAM_CHANNELS
,
1675 twl4030
->master_substream
= substream
;
1681 static void twl4030_shutdown(struct snd_pcm_substream
*substream
,
1682 struct snd_soc_dai
*dai
)
1684 struct snd_soc_codec
*codec
= dai
->codec
;
1685 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
1687 if (twl4030
->master_substream
== substream
)
1688 twl4030
->master_substream
= twl4030
->slave_substream
;
1690 twl4030
->slave_substream
= NULL
;
1692 /* If all streams are closed, or the remaining stream has not yet
1693 * been configured than set the DAI as not configured. */
1694 if (!twl4030
->master_substream
)
1695 twl4030
->configured
= 0;
1696 else if (!twl4030
->master_substream
->runtime
->channels
)
1697 twl4030
->configured
= 0;
1699 /* If the closing substream had 4 channel, do the necessary cleanup */
1700 if (substream
->runtime
->channels
== 4)
1701 twl4030_tdm_enable(codec
, substream
->stream
, 0);
1704 static int twl4030_hw_params(struct snd_pcm_substream
*substream
,
1705 struct snd_pcm_hw_params
*params
,
1706 struct snd_soc_dai
*dai
)
1708 struct snd_soc_codec
*codec
= dai
->codec
;
1709 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
1710 u8 mode
, old_mode
, format
, old_format
;
1712 /* If the substream has 4 channel, do the necessary setup */
1713 if (params_channels(params
) == 4) {
1714 format
= twl4030_read(codec
, TWL4030_REG_AUDIO_IF
);
1715 mode
= twl4030_read(codec
, TWL4030_REG_CODEC_MODE
);
1717 /* Safety check: are we in the correct operating mode and
1718 * the interface is in TDM mode? */
1719 if ((mode
& TWL4030_OPTION_1
) &&
1720 ((format
& TWL4030_AIF_FORMAT
) == TWL4030_AIF_FORMAT_TDM
))
1721 twl4030_tdm_enable(codec
, substream
->stream
, 1);
1726 if (twl4030
->configured
)
1727 /* Ignoring hw_params for already configured DAI */
1731 old_mode
= twl4030_read(codec
,
1732 TWL4030_REG_CODEC_MODE
) & ~TWL4030_CODECPDZ
;
1733 mode
= old_mode
& ~TWL4030_APLL_RATE
;
1735 switch (params_rate(params
)) {
1737 mode
|= TWL4030_APLL_RATE_8000
;
1740 mode
|= TWL4030_APLL_RATE_11025
;
1743 mode
|= TWL4030_APLL_RATE_12000
;
1746 mode
|= TWL4030_APLL_RATE_16000
;
1749 mode
|= TWL4030_APLL_RATE_22050
;
1752 mode
|= TWL4030_APLL_RATE_24000
;
1755 mode
|= TWL4030_APLL_RATE_32000
;
1758 mode
|= TWL4030_APLL_RATE_44100
;
1761 mode
|= TWL4030_APLL_RATE_48000
;
1764 mode
|= TWL4030_APLL_RATE_96000
;
1767 dev_err(codec
->dev
, "%s: unknown rate %d\n", __func__
,
1768 params_rate(params
));
1773 old_format
= twl4030_read(codec
, TWL4030_REG_AUDIO_IF
);
1774 format
= old_format
;
1775 format
&= ~TWL4030_DATA_WIDTH
;
1776 switch (params_width(params
)) {
1778 format
|= TWL4030_DATA_WIDTH_16S_16W
;
1781 format
|= TWL4030_DATA_WIDTH_32S_24W
;
1784 dev_err(codec
->dev
, "%s: unsupported bits/sample %d\n",
1785 __func__
, params_width(params
));
1789 if (format
!= old_format
|| mode
!= old_mode
) {
1790 if (twl4030
->codec_powered
) {
1792 * If the codec is powered, than we need to toggle the
1795 twl4030_codec_enable(codec
, 0);
1796 twl4030_write(codec
, TWL4030_REG_CODEC_MODE
, mode
);
1797 twl4030_write(codec
, TWL4030_REG_AUDIO_IF
, format
);
1798 twl4030_codec_enable(codec
, 1);
1800 twl4030_write(codec
, TWL4030_REG_CODEC_MODE
, mode
);
1801 twl4030_write(codec
, TWL4030_REG_AUDIO_IF
, format
);
1805 /* Store the important parameters for the DAI configuration and set
1806 * the DAI as configured */
1807 twl4030
->configured
= 1;
1808 twl4030
->rate
= params_rate(params
);
1809 twl4030
->sample_bits
= hw_param_interval(params
,
1810 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
)->min
;
1811 twl4030
->channels
= params_channels(params
);
1813 /* If both playback and capture streams are open, and one of them
1814 * is setting the hw parameters right now (since we are here), set
1815 * constraints to the other stream to match the current one. */
1816 if (twl4030
->slave_substream
)
1817 twl4030_constraints(twl4030
, substream
);
1822 static int twl4030_set_dai_sysclk(struct snd_soc_dai
*codec_dai
, int clk_id
,
1823 unsigned int freq
, int dir
)
1825 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1826 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
1834 dev_err(codec
->dev
, "Unsupported HFCLKIN: %u\n", freq
);
1838 if ((freq
/ 1000) != twl4030
->sysclk
) {
1840 "Mismatch in HFCLKIN: %u (configured: %u)\n",
1841 freq
, twl4030
->sysclk
* 1000);
1848 static int twl4030_set_dai_fmt(struct snd_soc_dai
*codec_dai
, unsigned int fmt
)
1850 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1851 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
1852 u8 old_format
, format
;
1855 old_format
= twl4030_read(codec
, TWL4030_REG_AUDIO_IF
);
1856 format
= old_format
;
1858 /* set master/slave audio interface */
1859 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1860 case SND_SOC_DAIFMT_CBM_CFM
:
1861 format
&= ~(TWL4030_AIF_SLAVE_EN
);
1862 format
&= ~(TWL4030_CLK256FS_EN
);
1864 case SND_SOC_DAIFMT_CBS_CFS
:
1865 format
|= TWL4030_AIF_SLAVE_EN
;
1866 format
|= TWL4030_CLK256FS_EN
;
1872 /* interface format */
1873 format
&= ~TWL4030_AIF_FORMAT
;
1874 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1875 case SND_SOC_DAIFMT_I2S
:
1876 format
|= TWL4030_AIF_FORMAT_CODEC
;
1878 case SND_SOC_DAIFMT_DSP_A
:
1879 format
|= TWL4030_AIF_FORMAT_TDM
;
1885 if (format
!= old_format
) {
1886 if (twl4030
->codec_powered
) {
1888 * If the codec is powered, than we need to toggle the
1891 twl4030_codec_enable(codec
, 0);
1892 twl4030_write(codec
, TWL4030_REG_AUDIO_IF
, format
);
1893 twl4030_codec_enable(codec
, 1);
1895 twl4030_write(codec
, TWL4030_REG_AUDIO_IF
, format
);
1902 static int twl4030_set_tristate(struct snd_soc_dai
*dai
, int tristate
)
1904 struct snd_soc_codec
*codec
= dai
->codec
;
1905 u8 reg
= twl4030_read(codec
, TWL4030_REG_AUDIO_IF
);
1908 reg
|= TWL4030_AIF_TRI_EN
;
1910 reg
&= ~TWL4030_AIF_TRI_EN
;
1912 return twl4030_write(codec
, TWL4030_REG_AUDIO_IF
, reg
);
1915 /* In case of voice mode, the RX1 L(VRX) for downlink and the TX2 L/R
1916 * (VTXL, VTXR) for uplink has to be enabled/disabled. */
1917 static void twl4030_voice_enable(struct snd_soc_codec
*codec
, int direction
,
1922 reg
= twl4030_read(codec
, TWL4030_REG_OPTION
);
1924 if (direction
== SNDRV_PCM_STREAM_PLAYBACK
)
1925 mask
= TWL4030_ARXL1_VRX_EN
;
1927 mask
= TWL4030_ATXL2_VTXL_EN
| TWL4030_ATXR2_VTXR_EN
;
1934 twl4030_write(codec
, TWL4030_REG_OPTION
, reg
);
1937 static int twl4030_voice_startup(struct snd_pcm_substream
*substream
,
1938 struct snd_soc_dai
*dai
)
1940 struct snd_soc_codec
*codec
= dai
->codec
;
1941 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
1944 /* If the system master clock is not 26MHz, the voice PCM interface is
1947 if (twl4030
->sysclk
!= 26000) {
1949 "%s: HFCLKIN is %u KHz, voice interface needs 26MHz\n",
1950 __func__
, twl4030
->sysclk
);
1954 /* If the codec mode is not option2, the voice PCM interface is not
1957 mode
= twl4030_read(codec
, TWL4030_REG_CODEC_MODE
)
1960 if (mode
!= TWL4030_OPTION_2
) {
1961 dev_err(codec
->dev
, "%s: the codec mode is not option2\n",
1969 static void twl4030_voice_shutdown(struct snd_pcm_substream
*substream
,
1970 struct snd_soc_dai
*dai
)
1972 struct snd_soc_codec
*codec
= dai
->codec
;
1974 /* Enable voice digital filters */
1975 twl4030_voice_enable(codec
, substream
->stream
, 0);
1978 static int twl4030_voice_hw_params(struct snd_pcm_substream
*substream
,
1979 struct snd_pcm_hw_params
*params
,
1980 struct snd_soc_dai
*dai
)
1982 struct snd_soc_codec
*codec
= dai
->codec
;
1983 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
1986 /* Enable voice digital filters */
1987 twl4030_voice_enable(codec
, substream
->stream
, 1);
1990 old_mode
= twl4030_read(codec
,
1991 TWL4030_REG_CODEC_MODE
) & ~TWL4030_CODECPDZ
;
1994 switch (params_rate(params
)) {
1996 mode
&= ~(TWL4030_SEL_16K
);
1999 mode
|= TWL4030_SEL_16K
;
2002 dev_err(codec
->dev
, "%s: unknown rate %d\n", __func__
,
2003 params_rate(params
));
2007 if (mode
!= old_mode
) {
2008 if (twl4030
->codec_powered
) {
2010 * If the codec is powered, than we need to toggle the
2013 twl4030_codec_enable(codec
, 0);
2014 twl4030_write(codec
, TWL4030_REG_CODEC_MODE
, mode
);
2015 twl4030_codec_enable(codec
, 1);
2017 twl4030_write(codec
, TWL4030_REG_CODEC_MODE
, mode
);
2024 static int twl4030_voice_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
2025 int clk_id
, unsigned int freq
, int dir
)
2027 struct snd_soc_codec
*codec
= codec_dai
->codec
;
2028 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
2030 if (freq
!= 26000000) {
2032 "%s: HFCLKIN is %u KHz, voice interface needs 26MHz\n",
2033 __func__
, freq
/ 1000);
2036 if ((freq
/ 1000) != twl4030
->sysclk
) {
2038 "Mismatch in HFCLKIN: %u (configured: %u)\n",
2039 freq
, twl4030
->sysclk
* 1000);
2045 static int twl4030_voice_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
2048 struct snd_soc_codec
*codec
= codec_dai
->codec
;
2049 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
2050 u8 old_format
, format
;
2053 old_format
= twl4030_read(codec
, TWL4030_REG_VOICE_IF
);
2054 format
= old_format
;
2056 /* set master/slave audio interface */
2057 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
2058 case SND_SOC_DAIFMT_CBM_CFM
:
2059 format
&= ~(TWL4030_VIF_SLAVE_EN
);
2061 case SND_SOC_DAIFMT_CBS_CFS
:
2062 format
|= TWL4030_VIF_SLAVE_EN
;
2068 /* clock inversion */
2069 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
2070 case SND_SOC_DAIFMT_IB_NF
:
2071 format
&= ~(TWL4030_VIF_FORMAT
);
2073 case SND_SOC_DAIFMT_NB_IF
:
2074 format
|= TWL4030_VIF_FORMAT
;
2080 if (format
!= old_format
) {
2081 if (twl4030
->codec_powered
) {
2083 * If the codec is powered, than we need to toggle the
2086 twl4030_codec_enable(codec
, 0);
2087 twl4030_write(codec
, TWL4030_REG_VOICE_IF
, format
);
2088 twl4030_codec_enable(codec
, 1);
2090 twl4030_write(codec
, TWL4030_REG_VOICE_IF
, format
);
2097 static int twl4030_voice_set_tristate(struct snd_soc_dai
*dai
, int tristate
)
2099 struct snd_soc_codec
*codec
= dai
->codec
;
2100 u8 reg
= twl4030_read(codec
, TWL4030_REG_VOICE_IF
);
2103 reg
|= TWL4030_VIF_TRI_EN
;
2105 reg
&= ~TWL4030_VIF_TRI_EN
;
2107 return twl4030_write(codec
, TWL4030_REG_VOICE_IF
, reg
);
2110 #define TWL4030_RATES (SNDRV_PCM_RATE_8000_48000)
2111 #define TWL4030_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
2113 static const struct snd_soc_dai_ops twl4030_dai_hifi_ops
= {
2114 .startup
= twl4030_startup
,
2115 .shutdown
= twl4030_shutdown
,
2116 .hw_params
= twl4030_hw_params
,
2117 .set_sysclk
= twl4030_set_dai_sysclk
,
2118 .set_fmt
= twl4030_set_dai_fmt
,
2119 .set_tristate
= twl4030_set_tristate
,
2122 static const struct snd_soc_dai_ops twl4030_dai_voice_ops
= {
2123 .startup
= twl4030_voice_startup
,
2124 .shutdown
= twl4030_voice_shutdown
,
2125 .hw_params
= twl4030_voice_hw_params
,
2126 .set_sysclk
= twl4030_voice_set_dai_sysclk
,
2127 .set_fmt
= twl4030_voice_set_dai_fmt
,
2128 .set_tristate
= twl4030_voice_set_tristate
,
2131 static struct snd_soc_dai_driver twl4030_dai
[] = {
2133 .name
= "twl4030-hifi",
2135 .stream_name
= "HiFi Playback",
2138 .rates
= TWL4030_RATES
| SNDRV_PCM_RATE_96000
,
2139 .formats
= TWL4030_FORMATS
,
2142 .stream_name
= "HiFi Capture",
2145 .rates
= TWL4030_RATES
,
2146 .formats
= TWL4030_FORMATS
,
2148 .ops
= &twl4030_dai_hifi_ops
,
2151 .name
= "twl4030-voice",
2153 .stream_name
= "Voice Playback",
2156 .rates
= SNDRV_PCM_RATE_8000
| SNDRV_PCM_RATE_16000
,
2157 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
2159 .stream_name
= "Voice Capture",
2162 .rates
= SNDRV_PCM_RATE_8000
| SNDRV_PCM_RATE_16000
,
2163 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
2164 .ops
= &twl4030_dai_voice_ops
,
2168 static int twl4030_soc_probe(struct snd_soc_codec
*codec
)
2170 struct twl4030_priv
*twl4030
;
2172 twl4030
= devm_kzalloc(codec
->dev
, sizeof(struct twl4030_priv
),
2176 snd_soc_codec_set_drvdata(codec
, twl4030
);
2177 /* Set the defaults, and power up the codec */
2178 twl4030
->sysclk
= twl4030_audio_get_mclk() / 1000;
2180 twl4030_init_chip(codec
);
2185 static int twl4030_soc_remove(struct snd_soc_codec
*codec
)
2187 struct twl4030_priv
*twl4030
= snd_soc_codec_get_drvdata(codec
);
2188 struct twl4030_codec_data
*pdata
= twl4030
->pdata
;
2190 if (pdata
&& pdata
->hs_extmute
&& gpio_is_valid(pdata
->hs_extmute_gpio
))
2191 gpio_free(pdata
->hs_extmute_gpio
);
2196 static const struct snd_soc_codec_driver soc_codec_dev_twl4030
= {
2197 .probe
= twl4030_soc_probe
,
2198 .remove
= twl4030_soc_remove
,
2199 .read
= twl4030_read
,
2200 .write
= twl4030_write
,
2201 .set_bias_level
= twl4030_set_bias_level
,
2202 .idle_bias_off
= true,
2204 .component_driver
= {
2205 .controls
= twl4030_snd_controls
,
2206 .num_controls
= ARRAY_SIZE(twl4030_snd_controls
),
2207 .dapm_widgets
= twl4030_dapm_widgets
,
2208 .num_dapm_widgets
= ARRAY_SIZE(twl4030_dapm_widgets
),
2209 .dapm_routes
= intercon
,
2210 .num_dapm_routes
= ARRAY_SIZE(intercon
),
2214 static int twl4030_codec_probe(struct platform_device
*pdev
)
2216 return snd_soc_register_codec(&pdev
->dev
, &soc_codec_dev_twl4030
,
2217 twl4030_dai
, ARRAY_SIZE(twl4030_dai
));
2220 static int twl4030_codec_remove(struct platform_device
*pdev
)
2222 snd_soc_unregister_codec(&pdev
->dev
);
2226 MODULE_ALIAS("platform:twl4030-codec");
2228 static struct platform_driver twl4030_codec_driver
= {
2229 .probe
= twl4030_codec_probe
,
2230 .remove
= twl4030_codec_remove
,
2232 .name
= "twl4030-codec",
2236 module_platform_driver(twl4030_codec_driver
);
2238 MODULE_DESCRIPTION("ASoC TWL4030 codec driver");
2239 MODULE_AUTHOR("Steve Sakoman");
2240 MODULE_LICENSE("GPL");