22 #include <linux/module.h>
27 #include <linux/i2c.h>
32 #include <linux/slab.h>
45 #define TWL4030_REG_SW_SHADOW 0x4A
46 #define TWL4030_CACHEREGNUM (TWL4030_REG_SW_SHADOW + 1)
49 #define TWL4030_HFL_EN 0x01
50 #define TWL4030_HFR_EN 0x02
192 unsigned int reg,
unsigned int value)
194 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
195 int write_to_reg = 0;
197 twl4030_write_reg_cache(codec, reg, value);
237 static inline void twl4030_wait_ms(
int time)
249 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
270 static inline void twl4030_check_defaults(
struct snd_soc_codec *codec)
272 int i, difference = 0;
275 dev_dbg(codec->
dev,
"Checking TWL audio default configuration\n");
278 if (val != twl4030_reg[i]) {
281 "Reg 0x%02x: chip: 0x%02x driver: 0x%02x\n",
282 i, val, twl4030_reg[i]);
285 dev_dbg(codec->
dev,
"Found %d non-matching registers. %s\n",
286 difference, difference ?
"Not OK" :
"OK");
289 static inline void twl4030_reset_registers(
struct snd_soc_codec *codec)
296 twl4030_write(codec, i, twl4030_reg[i]);
305 of_property_read_u32(node,
"ti,digimic_delay",
307 of_property_read_u32(node,
"ti,ramp_delay_value",
309 of_property_read_u32(node,
"ti,offset_cncl_path",
311 if (!of_property_read_u32(node,
"ti,hs_extmute", &value))
315 "ti,hs_extmute_gpio", 0);
328 if (!pdata && twl4030_codec_node) {
333 dev_err(codec->
dev,
"Can not allocate memory\n");
336 twl4030_setup_pdata_of(pdata, twl4030_codec_node);
345 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
349 pdata = twl4030_get_pdata(codec);
357 "Extmute GPIO is 0 is this correct?\n");
362 dev_err(codec->
dev,
"Failed to get hs_extmute GPIO\n");
369 twl4030_check_defaults(codec);
373 twl4030_reset_registers(codec);
404 twl4030_codec_enable(codec, 1);
422 }
while ((i++ < 100) &&
424 TWL4030_CNCL_OFFSET_START));
429 twl4030_codec_enable(codec, 0);
432 static void twl4030_apll_enable(
struct snd_soc_codec *codec,
int enable)
434 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
506 static const char *twl4030_handsfreel_texts[] =
507 {
"Voice",
"AudioL1",
"AudioL2",
"AudioR2"};
509 static const struct soc_enum twl4030_handsfreel_enum =
512 twl4030_handsfreel_texts);
522 static const char *twl4030_handsfreer_texts[] =
523 {
"Voice",
"AudioR1",
"AudioR2",
"AudioL2"};
525 static const struct soc_enum twl4030_handsfreer_enum =
528 twl4030_handsfreer_texts);
539 static const char *twl4030_vibra_texts[] =
540 {
"AudioL1",
"AudioR1",
"AudioL2",
"AudioR2"};
542 static const struct soc_enum twl4030_vibra_enum =
545 twl4030_vibra_texts);
551 static const char *twl4030_vibrapath_texts[] =
552 {
"Local vibrator",
"Audio"};
554 static const struct soc_enum twl4030_vibrapath_enum =
557 twl4030_vibrapath_texts);
581 static const char *twl4030_micpathtx1_texts[] =
582 {
"Analog",
"Digimic0"};
584 static const struct soc_enum twl4030_micpathtx1_enum =
587 twl4030_micpathtx1_texts);
593 static const char *twl4030_micpathtx2_texts[] =
594 {
"Analog",
"Digimic1"};
596 static const struct soc_enum twl4030_micpathtx2_enum =
599 twl4030_micpathtx2_texts);
625 static const unsigned int twl4030_dapm_dbypass_tlv[] = {
636 twl4030_dapm_dbypass_tlv);
642 twl4030_dapm_dbypass_tlv);
654 twl4030_dapm_dbypassv_tlv);
664 #define TWL4030_OUTPUT_PGA(pin_name, reg, mask) \
665 static int pin_name##pga_event(struct snd_soc_dapm_widget *w, \
666 struct snd_kcontrol *kcontrol, int event) \
668 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec); \
671 case SND_SOC_DAPM_POST_PMU: \
672 twl4030->pin_name##_enabled = 1; \
673 twl4030_write(w->codec, reg, \
674 twl4030_read_reg_cache(w->codec, reg)); \
676 case SND_SOC_DAPM_POST_PMD: \
677 twl4030->pin_name##_enabled = 0; \
678 twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, \
691 static void handsfree_ramp(
struct snd_soc_codec *codec,
int reg,
int ramp)
693 unsigned char hs_ctl;
695 hs_ctl = twl4030_read_reg_cache(codec, reg);
700 twl4030_write(codec, reg, hs_ctl);
703 twl4030_write(codec, reg, hs_ctl);
707 twl4030_write(codec, reg, hs_ctl);
712 twl4030_write(codec, reg, hs_ctl);
714 twl4030_write(codec, reg, hs_ctl);
717 twl4030_write(codec, reg, hs_ctl);
761 twl4030_apll_enable(w->
codec, 1);
764 twl4030_apll_enable(w->
codec, 0);
780 twl4030_apll_enable(w->
codec, 1);
789 twl4030_apll_enable(w->
codec, 0);
795 static void headset_ramp(
struct snd_soc_codec *codec,
int ramp)
797 unsigned char hs_gain, hs_pop;
798 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
801 unsigned int ramp_base[] = {524288, 1048576, 2097152, 4194304,
802 8388608, 16777216, 33554432, 67108864};
832 twl4030_wait_ms(delay);
839 twl4030_wait_ms(delay);
869 headset_ramp(w->
codec, 1);
876 headset_ramp(w->
codec, 0);
893 headset_ramp(w->
codec, 1);
900 headset_ramp(w->
codec, 0);
929 static int snd_soc_get_volsw_twl4030(
struct snd_kcontrol *kcontrol,
935 unsigned int reg = mc->
reg;
939 int mask = (1 << fls(max)) - 1;
941 ucontrol->
value.integer.value[0] =
943 if (ucontrol->
value.integer.value[0])
944 ucontrol->
value.integer.value[0] =
945 max + 1 - ucontrol->
value.integer.value[0];
947 if (shift != rshift) {
948 ucontrol->
value.integer.value[1] =
950 if (ucontrol->
value.integer.value[1])
951 ucontrol->
value.integer.value[1] =
952 max + 1 - ucontrol->
value.integer.value[1];
958 static int snd_soc_put_volsw_twl4030(
struct snd_kcontrol *kcontrol,
964 unsigned int reg = mc->
reg;
965 unsigned int shift = mc->
shift;
966 unsigned int rshift = mc->
rshift;
968 int mask = (1 << fls(max)) - 1;
969 unsigned short val, val2, val_mask;
971 val = (ucontrol->
value.integer.value[0] &
mask);
973 val_mask = mask <<
shift;
977 if (shift != rshift) {
978 val2 = (ucontrol->
value.integer.value[1] &
mask);
979 val_mask |= mask <<
rshift;
981 val2 = max + 1 - val2;
987 static int snd_soc_get_volsw_r2_twl4030(
struct snd_kcontrol *kcontrol,
993 unsigned int reg = mc->
reg;
995 unsigned int shift = mc->
shift;
997 int mask = (1<<fls(max))-1;
999 ucontrol->
value.integer.value[0] =
1001 ucontrol->
value.integer.value[1] =
1004 if (ucontrol->
value.integer.value[0])
1005 ucontrol->
value.integer.value[0] =
1006 max + 1 - ucontrol->
value.integer.value[0];
1007 if (ucontrol->
value.integer.value[1])
1008 ucontrol->
value.integer.value[1] =
1009 max + 1 - ucontrol->
value.integer.value[1];
1014 static int snd_soc_put_volsw_r2_twl4030(
struct snd_kcontrol *kcontrol,
1020 unsigned int reg = mc->
reg;
1021 unsigned int reg2 = mc->
rreg;
1022 unsigned int shift = mc->
shift;
1024 int mask = (1 << fls(max)) - 1;
1026 unsigned short val, val2, val_mask;
1028 val_mask = mask <<
shift;
1029 val = (ucontrol->
value.integer.value[0] &
mask);
1030 val2 = (ucontrol->
value.integer.value[1] &
mask);
1033 val = max + 1 -
val;
1035 val2 = max + 1 - val2;
1038 val2 = val2 <<
shift;
1049 static const char *twl4030_op_modes_texts[] = {
1050 "Option 2 (voice/audio)",
"Option 1 (audio)"
1053 static const struct soc_enum twl4030_op_modes_enum =
1056 twl4030_op_modes_texts);
1058 static int snd_soc_put_twl4030_opmode_enum_double(
struct snd_kcontrol *kcontrol,
1062 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
1065 unsigned short mask;
1069 "operation mode cannot be changed on-the-fly\n");
1073 if (ucontrol->
value.enumerated.item[0] > e->
max - 1)
1076 val = ucontrol->
value.enumerated.item[0] << e->
shift_l;
1079 if (ucontrol->
value.enumerated.item[1] > e->
max - 1)
1081 val |= ucontrol->
value.enumerated.item[1] << e->
shift_r;
1138 static const char *twl4030_avadc_clk_priority_texts[] = {
1139 "Voice high priority",
"HiFi high priority"
1142 static const struct soc_enum twl4030_avadc_clk_priority_enum =
1144 ARRAY_SIZE(twl4030_avadc_clk_priority_texts),
1145 twl4030_avadc_clk_priority_texts);
1147 static const char *twl4030_rampdelay_texts[] = {
1148 "27/20/14 ms",
"55/40/27 ms",
"109/81/55 ms",
"218/161/109 ms",
1149 "437/323/218 ms",
"874/645/437 ms",
"1748/1291/874 ms",
1153 static const struct soc_enum twl4030_rampdelay_enum =
1156 twl4030_rampdelay_texts);
1159 static const char *twl4030_vibradirmode_texts[] = {
1160 "Vibra H-bridge direction",
"Audio data MSB",
1163 static const struct soc_enum twl4030_vibradirmode_enum =
1166 twl4030_vibradirmode_texts);
1169 static const char *twl4030_vibradir_texts[] = {
1170 "Positive polarity",
"Negative polarity",
1173 static const struct soc_enum twl4030_vibradir_enum =
1176 twl4030_vibradir_texts);
1179 static const char *twl4030_digimicswap_texts[] = {
1180 "Not swapped",
"Swapped",
1183 static const struct soc_enum twl4030_digimicswap_enum =
1186 twl4030_digimicswap_texts);
1190 SOC_ENUM_EXT(
"Codec Operation Mode", twl4030_op_modes_enum,
1192 snd_soc_put_twl4030_opmode_enum_double),
1197 0, 0x3f, 0, digital_fine_tlv),
1200 0, 0x3f, 0, digital_fine_tlv),
1204 6, 0x2, 0, digital_coarse_tlv),
1207 6, 0x2, 0, digital_coarse_tlv),
1211 3, 0x12, 1, analog_tlv),
1214 3, 0x12, 1, analog_tlv),
1229 SOC_SINGLE(
"DAC Voice Analog Downlink Switch",
1235 4, 3, 0, snd_soc_get_volsw_r2_twl4030,
1236 snd_soc_put_volsw_r2_twl4030, output_tvl),
1240 snd_soc_put_volsw_twl4030, output_tvl),
1244 4, 3, 0, snd_soc_get_volsw_r2_twl4030,
1245 snd_soc_put_volsw_r2_twl4030, output_tvl),
1249 snd_soc_put_volsw_twl4030, output_ear_tvl),
1254 0, 0x1f, 0, digital_capture_tlv),
1257 0, 0x1f, 0, digital_capture_tlv),
1260 0, 3, 5, 0, input_gain_tlv),
1262 SOC_ENUM(
"AVADC Clock Priority", twl4030_avadc_clk_priority_enum),
1264 SOC_ENUM(
"HS ramp delay", twl4030_rampdelay_enum),
1266 SOC_ENUM(
"Vibra H-bridge mode", twl4030_vibradirmode_enum),
1267 SOC_ENUM(
"Vibra H-bridge direction", twl4030_vibradir_enum),
1269 SOC_ENUM(
"Digimic LR Swap", twl4030_digimicswap_enum),
1311 &twl4030_dapm_abypassr1_control),
1313 &twl4030_dapm_abypassl1_control),
1315 &twl4030_dapm_abypassr2_control),
1317 &twl4030_dapm_abypassl2_control),
1319 &twl4030_dapm_abypassv_control),
1327 &twl4030_dapm_dbypassl_control),
1329 &twl4030_dapm_dbypassr_control),
1331 &twl4030_dapm_dbypassv_control),
1366 &twl4030_dapm_earpiece_controls[0],
1369 0, 0,
NULL, 0, earpiecepga_event,
1373 &twl4030_dapm_predrivel_controls[0],
1374 ARRAY_SIZE(twl4030_dapm_predrivel_controls)),
1376 0, 0,
NULL, 0, predrivelpga_event,
1379 &twl4030_dapm_predriver_controls[0],
1380 ARRAY_SIZE(twl4030_dapm_predriver_controls)),
1382 0, 0,
NULL, 0, predriverpga_event,
1386 &twl4030_dapm_hsol_controls[0],
1389 0, 0,
NULL, 0, headsetlpga_event,
1392 &twl4030_dapm_hsor_controls[0],
1395 0, 0,
NULL, 0, headsetrpga_event,
1399 &twl4030_dapm_carkitl_controls[0],
1402 0, 0,
NULL, 0, carkitlpga_event,
1405 &twl4030_dapm_carkitr_controls[0],
1408 0, 0,
NULL, 0, carkitrpga_event,
1414 &twl4030_dapm_handsfreel_control),
1416 &twl4030_dapm_handsfreelmute_control),
1418 0, 0,
NULL, 0, handsfreelpga_event,
1421 &twl4030_dapm_handsfreer_control),
1423 &twl4030_dapm_handsfreermute_control),
1425 0, 0,
NULL, 0, handsfreerpga_event,
1429 &twl4030_dapm_vibra_control, vibramux_event,
1432 &twl4030_dapm_vibrapath_control),
1445 &twl4030_dapm_micpathtx1_control),
1447 &twl4030_dapm_micpathtx2_control),
1452 &twl4030_dapm_analoglmic_controls[0],
1453 ARRAY_SIZE(twl4030_dapm_analoglmic_controls)),
1456 &twl4030_dapm_analogrmic_controls[0],
1457 ARRAY_SIZE(twl4030_dapm_analogrmic_controls)),
1484 {
"DAC Right1",
NULL,
"HiFi Playback"},
1485 {
"DAC Left1",
NULL,
"HiFi Playback"},
1486 {
"DAC Right2",
NULL,
"HiFi Playback"},
1487 {
"DAC Left2",
NULL,
"HiFi Playback"},
1488 {
"DAC Voice",
NULL,
"Voice Playback"},
1491 {
"HiFi Capture",
NULL,
"ADC Virtual Left1"},
1492 {
"HiFi Capture",
NULL,
"ADC Virtual Right1"},
1493 {
"HiFi Capture",
NULL,
"ADC Virtual Left2"},
1494 {
"HiFi Capture",
NULL,
"ADC Virtual Right2"},
1495 {
"Voice Capture",
NULL,
"ADC Virtual Left1"},
1496 {
"Voice Capture",
NULL,
"ADC Virtual Right1"},
1497 {
"Voice Capture",
NULL,
"ADC Virtual Left2"},
1498 {
"Voice Capture",
NULL,
"ADC Virtual Right2"},
1500 {
"Digital L1 Playback Mixer",
NULL,
"DAC Left1"},
1501 {
"Digital R1 Playback Mixer",
NULL,
"DAC Right1"},
1502 {
"Digital L2 Playback Mixer",
NULL,
"DAC Left2"},
1503 {
"Digital R2 Playback Mixer",
NULL,
"DAC Right2"},
1504 {
"Digital Voice Playback Mixer",
NULL,
"DAC Voice"},
1507 {
"Digital Voice Playback Mixer",
NULL,
"APLL Enable"},
1509 {
"DAC Left1",
NULL,
"AIF Enable"},
1510 {
"DAC Right1",
NULL,
"AIF Enable"},
1511 {
"DAC Left2",
NULL,
"AIF Enable"},
1512 {
"DAC Right1",
NULL,
"AIF Enable"},
1514 {
"Digital R2 Playback Mixer",
NULL,
"AIF Enable"},
1515 {
"Digital L2 Playback Mixer",
NULL,
"AIF Enable"},
1517 {
"Analog L1 Playback Mixer",
NULL,
"Digital L1 Playback Mixer"},
1518 {
"Analog R1 Playback Mixer",
NULL,
"Digital R1 Playback Mixer"},
1519 {
"Analog L2 Playback Mixer",
NULL,
"Digital L2 Playback Mixer"},
1520 {
"Analog R2 Playback Mixer",
NULL,
"Digital R2 Playback Mixer"},
1521 {
"Analog Voice Playback Mixer",
NULL,
"Digital Voice Playback Mixer"},
1525 {
"Earpiece Mixer",
"Voice",
"Analog Voice Playback Mixer"},
1526 {
"Earpiece Mixer",
"AudioL1",
"Analog L1 Playback Mixer"},
1527 {
"Earpiece Mixer",
"AudioL2",
"Analog L2 Playback Mixer"},
1528 {
"Earpiece Mixer",
"AudioR1",
"Analog R1 Playback Mixer"},
1529 {
"Earpiece PGA",
NULL,
"Earpiece Mixer"},
1531 {
"PredriveL Mixer",
"Voice",
"Analog Voice Playback Mixer"},
1532 {
"PredriveL Mixer",
"AudioL1",
"Analog L1 Playback Mixer"},
1533 {
"PredriveL Mixer",
"AudioL2",
"Analog L2 Playback Mixer"},
1534 {
"PredriveL Mixer",
"AudioR2",
"Analog R2 Playback Mixer"},
1535 {
"PredriveL PGA",
NULL,
"PredriveL Mixer"},
1537 {
"PredriveR Mixer",
"Voice",
"Analog Voice Playback Mixer"},
1538 {
"PredriveR Mixer",
"AudioR1",
"Analog R1 Playback Mixer"},
1539 {
"PredriveR Mixer",
"AudioR2",
"Analog R2 Playback Mixer"},
1540 {
"PredriveR Mixer",
"AudioL2",
"Analog L2 Playback Mixer"},
1541 {
"PredriveR PGA",
NULL,
"PredriveR Mixer"},
1543 {
"HeadsetL Mixer",
"Voice",
"Analog Voice Playback Mixer"},
1544 {
"HeadsetL Mixer",
"AudioL1",
"Analog L1 Playback Mixer"},
1545 {
"HeadsetL Mixer",
"AudioL2",
"Analog L2 Playback Mixer"},
1546 {
"HeadsetL PGA",
NULL,
"HeadsetL Mixer"},
1548 {
"HeadsetR Mixer",
"Voice",
"Analog Voice Playback Mixer"},
1549 {
"HeadsetR Mixer",
"AudioR1",
"Analog R1 Playback Mixer"},
1550 {
"HeadsetR Mixer",
"AudioR2",
"Analog R2 Playback Mixer"},
1551 {
"HeadsetR PGA",
NULL,
"HeadsetR Mixer"},
1553 {
"CarkitL Mixer",
"Voice",
"Analog Voice Playback Mixer"},
1554 {
"CarkitL Mixer",
"AudioL1",
"Analog L1 Playback Mixer"},
1555 {
"CarkitL Mixer",
"AudioL2",
"Analog L2 Playback Mixer"},
1556 {
"CarkitL PGA",
NULL,
"CarkitL Mixer"},
1558 {
"CarkitR Mixer",
"Voice",
"Analog Voice Playback Mixer"},
1559 {
"CarkitR Mixer",
"AudioR1",
"Analog R1 Playback Mixer"},
1560 {
"CarkitR Mixer",
"AudioR2",
"Analog R2 Playback Mixer"},
1561 {
"CarkitR PGA",
NULL,
"CarkitR Mixer"},
1563 {
"HandsfreeL Mux",
"Voice",
"Analog Voice Playback Mixer"},
1564 {
"HandsfreeL Mux",
"AudioL1",
"Analog L1 Playback Mixer"},
1565 {
"HandsfreeL Mux",
"AudioL2",
"Analog L2 Playback Mixer"},
1566 {
"HandsfreeL Mux",
"AudioR2",
"Analog R2 Playback Mixer"},
1567 {
"HandsfreeL",
"Switch",
"HandsfreeL Mux"},
1568 {
"HandsfreeL PGA",
NULL,
"HandsfreeL"},
1570 {
"HandsfreeR Mux",
"Voice",
"Analog Voice Playback Mixer"},
1571 {
"HandsfreeR Mux",
"AudioR1",
"Analog R1 Playback Mixer"},
1572 {
"HandsfreeR Mux",
"AudioR2",
"Analog R2 Playback Mixer"},
1573 {
"HandsfreeR Mux",
"AudioL2",
"Analog L2 Playback Mixer"},
1574 {
"HandsfreeR",
"Switch",
"HandsfreeR Mux"},
1575 {
"HandsfreeR PGA",
NULL,
"HandsfreeR"},
1577 {
"Vibra Mux",
"AudioL1",
"DAC Left1"},
1578 {
"Vibra Mux",
"AudioR1",
"DAC Right1"},
1579 {
"Vibra Mux",
"AudioL2",
"DAC Left2"},
1580 {
"Vibra Mux",
"AudioR2",
"DAC Right2"},
1584 {
"Virtual HiFi OUT",
NULL,
"DAC Left1"},
1585 {
"Virtual HiFi OUT",
NULL,
"DAC Right1"},
1586 {
"Virtual HiFi OUT",
NULL,
"DAC Left2"},
1587 {
"Virtual HiFi OUT",
NULL,
"DAC Right2"},
1589 {
"Virtual Voice OUT",
NULL,
"Digital Voice Playback Mixer"},
1591 {
"EARPIECE",
NULL,
"Earpiece PGA"},
1592 {
"PREDRIVEL",
NULL,
"PredriveL PGA"},
1593 {
"PREDRIVER",
NULL,
"PredriveR PGA"},
1594 {
"HSOL",
NULL,
"HeadsetL PGA"},
1595 {
"HSOR",
NULL,
"HeadsetR PGA"},
1596 {
"CARKITL",
NULL,
"CarkitL PGA"},
1597 {
"CARKITR",
NULL,
"CarkitR PGA"},
1598 {
"HFL",
NULL,
"HandsfreeL PGA"},
1599 {
"HFR",
NULL,
"HandsfreeR PGA"},
1600 {
"Vibra Route",
"Audio",
"Vibra Mux"},
1601 {
"VIBRA",
NULL,
"Vibra Route"},
1605 {
"ADC Virtual Left1",
NULL,
"Virtual HiFi IN"},
1606 {
"ADC Virtual Right1",
NULL,
"Virtual HiFi IN"},
1607 {
"ADC Virtual Left2",
NULL,
"Virtual HiFi IN"},
1608 {
"ADC Virtual Right2",
NULL,
"Virtual HiFi IN"},
1610 {
"Analog Left",
"Main Mic Capture Switch",
"MAINMIC"},
1611 {
"Analog Left",
"Headset Mic Capture Switch",
"HSMIC"},
1612 {
"Analog Left",
"AUXL Capture Switch",
"AUXL"},
1613 {
"Analog Left",
"Carkit Mic Capture Switch",
"CARKITMIC"},
1615 {
"Analog Right",
"Sub Mic Capture Switch",
"SUBMIC"},
1616 {
"Analog Right",
"AUXR Capture Switch",
"AUXR"},
1618 {
"ADC Physical Left",
NULL,
"Analog Left"},
1619 {
"ADC Physical Right",
NULL,
"Analog Right"},
1621 {
"Digimic0 Enable",
NULL,
"DIGIMIC0"},
1622 {
"Digimic1 Enable",
NULL,
"DIGIMIC1"},
1624 {
"DIGIMIC0",
NULL,
"micbias1 select"},
1625 {
"DIGIMIC1",
NULL,
"micbias2 select"},
1628 {
"TX1 Capture Route",
"Analog",
"ADC Physical Left"},
1629 {
"TX1 Capture Route",
"Digimic0",
"Digimic0 Enable"},
1631 {
"TX1 Capture Route",
"Analog",
"ADC Physical Right"},
1632 {
"TX1 Capture Route",
"Digimic0",
"Digimic0 Enable"},
1634 {
"TX2 Capture Route",
"Analog",
"ADC Physical Left"},
1635 {
"TX2 Capture Route",
"Digimic1",
"Digimic1 Enable"},
1637 {
"TX2 Capture Route",
"Analog",
"ADC Physical Right"},
1638 {
"TX2 Capture Route",
"Digimic1",
"Digimic1 Enable"},
1640 {
"ADC Virtual Left1",
NULL,
"TX1 Capture Route"},
1641 {
"ADC Virtual Right1",
NULL,
"TX1 Capture Route"},
1642 {
"ADC Virtual Left2",
NULL,
"TX2 Capture Route"},
1643 {
"ADC Virtual Right2",
NULL,
"TX2 Capture Route"},
1645 {
"ADC Virtual Left1",
NULL,
"AIF Enable"},
1646 {
"ADC Virtual Right1",
NULL,
"AIF Enable"},
1647 {
"ADC Virtual Left2",
NULL,
"AIF Enable"},
1648 {
"ADC Virtual Right2",
NULL,
"AIF Enable"},
1651 {
"Right1 Analog Loopback",
"Switch",
"Analog Right"},
1652 {
"Left1 Analog Loopback",
"Switch",
"Analog Left"},
1653 {
"Right2 Analog Loopback",
"Switch",
"Analog Right"},
1654 {
"Left2 Analog Loopback",
"Switch",
"Analog Left"},
1655 {
"Voice Analog Loopback",
"Switch",
"Analog Left"},
1658 {
"Right1 Analog Loopback",
NULL,
"FM Loop Enable"},
1659 {
"Left1 Analog Loopback",
NULL,
"FM Loop Enable"},
1660 {
"Right2 Analog Loopback",
NULL,
"FM Loop Enable"},
1661 {
"Left2 Analog Loopback",
NULL,
"FM Loop Enable"},
1662 {
"Voice Analog Loopback",
NULL,
"FM Loop Enable"},
1664 {
"Analog R1 Playback Mixer",
NULL,
"Right1 Analog Loopback"},
1665 {
"Analog L1 Playback Mixer",
NULL,
"Left1 Analog Loopback"},
1666 {
"Analog R2 Playback Mixer",
NULL,
"Right2 Analog Loopback"},
1667 {
"Analog L2 Playback Mixer",
NULL,
"Left2 Analog Loopback"},
1668 {
"Analog Voice Playback Mixer",
NULL,
"Voice Analog Loopback"},
1671 {
"Right Digital Loopback",
"Volume",
"TX1 Capture Route"},
1672 {
"Left Digital Loopback",
"Volume",
"TX1 Capture Route"},
1673 {
"Voice Digital Loopback",
"Volume",
"TX2 Capture Route"},
1675 {
"Digital R2 Playback Mixer",
NULL,
"Right Digital Loopback"},
1676 {
"Digital L2 Playback Mixer",
NULL,
"Left Digital Loopback"},
1677 {
"Digital Voice Playback Mixer",
NULL,
"Voice Digital Loopback"},
1681 static int twl4030_set_bias_level(
struct snd_soc_codec *codec,
1691 twl4030_codec_enable(codec, 1);
1694 twl4030_codec_enable(codec, 0);
1702 static void twl4030_constraints(
struct twl4030_priv *twl4030,
1758 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
1787 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
1802 if (substream->
runtime->channels == 4)
1803 twl4030_tdm_enable(codec, substream->
stream, 0);
1811 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
1823 twl4030_tdm_enable(codec, substream->
stream, 1);
1833 old_mode = twl4030_read_reg_cache(codec,
1869 dev_err(codec->
dev,
"%s: unknown rate %d\n", __func__,
1876 format = old_format;
1886 dev_err(codec->
dev,
"%s: unknown format %d\n", __func__,
1891 if (format != old_format || mode != old_mode) {
1897 twl4030_codec_enable(codec, 0);
1900 twl4030_codec_enable(codec, 1);
1919 twl4030_constraints(twl4030, substream);
1924 static int twl4030_set_dai_sysclk(
struct snd_soc_dai *codec_dai,
1925 int clk_id,
unsigned int freq,
int dir)
1928 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
1936 dev_err(codec->
dev,
"Unsupported HFCLKIN: %u\n", freq);
1940 if ((freq / 1000) != twl4030->
sysclk) {
1942 "Mismatch in HFCLKIN: %u (configured: %u)\n",
1943 freq, twl4030->
sysclk * 1000);
1950 static int twl4030_set_dai_fmt(
struct snd_soc_dai *codec_dai,
1954 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
1959 format = old_format;
1988 if (format != old_format) {
1994 twl4030_codec_enable(codec, 0);
1996 twl4030_codec_enable(codec, 1);
2020 static void twl4030_voice_enable(
struct snd_soc_codec *codec,
int direction,
2044 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
2050 if (twl4030->
sysclk != 26000) {
2052 "%s: HFCLKIN is %u KHz, voice interface needs 26MHz\n",
2053 __func__, twl4030->
sysclk);
2064 dev_err(codec->
dev,
"%s: the codec mode is not option2\n",
2078 twl4030_voice_enable(codec, substream->
stream, 0);
2085 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
2089 twl4030_voice_enable(codec, substream->
stream, 1);
2104 dev_err(codec->
dev,
"%s: unknown rate %d\n", __func__,
2109 if (mode != old_mode) {
2115 twl4030_codec_enable(codec, 0);
2117 twl4030_codec_enable(codec, 1);
2126 static int twl4030_voice_set_dai_sysclk(
struct snd_soc_dai *codec_dai,
2127 int clk_id,
unsigned int freq,
int dir)
2130 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
2132 if (freq != 26000000) {
2134 "%s: HFCLKIN is %u KHz, voice interface needs 26MHz\n",
2135 __func__, freq / 1000);
2138 if ((freq / 1000) != twl4030->
sysclk) {
2140 "Mismatch in HFCLKIN: %u (configured: %u)\n",
2141 freq, twl4030->
sysclk * 1000);
2147 static int twl4030_voice_set_dai_fmt(
struct snd_soc_dai *codec_dai,
2151 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
2156 format = old_format;
2159 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2182 if (format != old_format) {
2188 twl4030_codec_enable(codec, 0);
2190 twl4030_codec_enable(codec, 1);
2199 static int twl4030_voice_set_tristate(
struct snd_soc_dai *dai,
int tristate)
2212 #define TWL4030_RATES (SNDRV_PCM_RATE_8000_48000)
2213 #define TWL4030_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
2216 .startup = twl4030_startup,
2217 .shutdown = twl4030_shutdown,
2218 .hw_params = twl4030_hw_params,
2219 .set_sysclk = twl4030_set_dai_sysclk,
2220 .set_fmt = twl4030_set_dai_fmt,
2221 .set_tristate = twl4030_set_tristate,
2225 .startup = twl4030_voice_startup,
2226 .shutdown = twl4030_voice_shutdown,
2227 .hw_params = twl4030_voice_hw_params,
2228 .set_sysclk = twl4030_voice_set_dai_sysclk,
2229 .set_fmt = twl4030_voice_set_dai_fmt,
2230 .set_tristate = twl4030_voice_set_tristate,
2235 .name =
"twl4030-hifi",
2237 .stream_name =
"HiFi Playback",
2244 .stream_name =
"HiFi Capture",
2250 .ops = &twl4030_dai_hifi_ops,
2253 .name =
"twl4030-voice",
2255 .stream_name =
"Voice Playback",
2261 .stream_name =
"Voice Capture",
2266 .ops = &twl4030_dai_voice_ops,
2288 if (twl4030 ==
NULL) {
2289 dev_err(codec->
dev,
"Can not allocate memory\n");
2292 snd_soc_codec_set_drvdata(codec, twl4030);
2296 twl4030_init_chip(codec);
2303 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
2307 twl4030_reset_registers(codec);
2317 .probe = twl4030_soc_probe,
2318 .remove = twl4030_soc_remove,
2319 .suspend = twl4030_soc_suspend,
2320 .resume = twl4030_soc_resume,
2321 .read = twl4030_read_reg_cache,
2322 .write = twl4030_write,
2323 .set_bias_level = twl4030_set_bias_level,
2324 .idle_bias_off =
true,
2325 .reg_cache_size =
sizeof(twl4030_reg),
2327 .reg_cache_default = twl4030_reg,
2329 .controls = twl4030_snd_controls,
2330 .num_controls =
ARRAY_SIZE(twl4030_snd_controls),
2331 .dapm_widgets = twl4030_dapm_widgets,
2332 .num_dapm_widgets =
ARRAY_SIZE(twl4030_dapm_widgets),
2333 .dapm_routes = intercon,
2352 .probe = twl4030_codec_probe,
2355 .name =
"twl4030-codec",