Skip to content

Commit 6bba63b

Browse files
Misael Lopez CruzPeter Ujfalusi
authored andcommitted
ASoC: twl6040: Remove pll and headset mode dependency
Remove dependency between pll (hppll, lppll) and headset power mode (low-power, high-performance), as headset power mode can be used with any pll. A new control is created to allow headset power mode configuration from userspace. Changing headset power mode during earpiece related usecases is not propagated down to the codec as earpiece requires HS DAC in HP mode. Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com> Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1 parent e17e4ab commit 6bba63b

1 file changed

Lines changed: 57 additions & 5 deletions

File tree

‎sound/soc/codecs/twl6040.c‎

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ struct twl6040_data {
7979
int codec_powered;
8080
int pll;
8181
int non_lp;
82+
int hs_power_mode;
83+
int hs_power_mode_locked;
8284
unsigned int clk_in;
8385
unsigned int sysclk;
8486
struct snd_pcm_hw_constraint_list *sysclk_constraints;
@@ -651,15 +653,26 @@ static int twl6040_power_mode_event(struct snd_soc_dapm_widget *w,
651653
{
652654
struct snd_soc_codec *codec = w->codec;
653655
struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
656+
int ret = 0;
654657

655-
if (SND_SOC_DAPM_EVENT_ON(event))
658+
if (SND_SOC_DAPM_EVENT_ON(event)) {
656659
priv->non_lp++;
657-
else
660+
if (!strcmp(w->name, "Earphone Driver")) {
661+
/* Earphone doesn't support low power mode */
662+
priv->hs_power_mode_locked = 1;
663+
ret = headset_power_mode(codec, 1);
664+
}
665+
} else {
658666
priv->non_lp--;
667+
if (!strcmp(w->name, "Earphone Driver")) {
668+
priv->hs_power_mode_locked = 0;
669+
ret = headset_power_mode(codec, priv->hs_power_mode);
670+
}
671+
}
659672

660673
msleep(1);
661674

662-
return 0;
675+
return ret;
663676
}
664677

665678
static void twl6040_hs_jack_report(struct snd_soc_codec *codec,
@@ -964,6 +977,43 @@ static const struct snd_kcontrol_new hfr_mux_controls =
964977
static const struct snd_kcontrol_new ep_driver_switch_controls =
965978
SOC_DAPM_SINGLE("Switch", TWL6040_REG_EARCTL, 0, 1, 0);
966979

980+
/* Headset power mode */
981+
static const char *twl6040_headset_power_texts[] = {
982+
"Low-Power", "High-Perfomance",
983+
};
984+
985+
static const struct soc_enum twl6040_headset_power_enum =
986+
SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(twl6040_headset_power_texts),
987+
twl6040_headset_power_texts);
988+
989+
static int twl6040_headset_power_get_enum(struct snd_kcontrol *kcontrol,
990+
struct snd_ctl_elem_value *ucontrol)
991+
{
992+
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
993+
struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
994+
995+
ucontrol->value.enumerated.item[0] = priv->hs_power_mode;
996+
997+
return 0;
998+
}
999+
1000+
static int twl6040_headset_power_put_enum(struct snd_kcontrol *kcontrol,
1001+
struct snd_ctl_elem_value *ucontrol)
1002+
{
1003+
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1004+
struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
1005+
int high_perf = ucontrol->value.enumerated.item[0];
1006+
int ret = 0;
1007+
1008+
if (!priv->hs_power_mode_locked)
1009+
ret = headset_power_mode(codec, high_perf);
1010+
1011+
if (!ret)
1012+
priv->hs_power_mode = high_perf;
1013+
1014+
return ret;
1015+
}
1016+
9671017
static const struct snd_kcontrol_new twl6040_snd_controls[] = {
9681018
/* Capture gains */
9691019
SOC_DOUBLE_TLV("Capture Preamplifier Volume",
@@ -982,6 +1032,10 @@ static const struct snd_kcontrol_new twl6040_snd_controls[] = {
9821032
TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, hf_tlv),
9831033
SOC_SINGLE_TLV("Earphone Playback Volume",
9841034
TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv),
1035+
1036+
SOC_ENUM_EXT("Headset Power Mode", twl6040_headset_power_enum,
1037+
twl6040_headset_power_get_enum,
1038+
twl6040_headset_power_put_enum),
9851039
};
9861040

9871041
static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = {
@@ -1339,7 +1393,6 @@ static int twl6040_set_dai_sysclk(struct snd_soc_dai *codec_dai,
13391393
if (ret)
13401394
return ret;
13411395

1342-
headset_power_mode(codec, 0);
13431396
priv->sysclk_constraints = &lp_constraints;
13441397
break;
13451398
case TWL6040_SYSCLK_SEL_HPPLL:
@@ -1348,7 +1401,6 @@ static int twl6040_set_dai_sysclk(struct snd_soc_dai *codec_dai,
13481401
if (ret)
13491402
return ret;
13501403

1351-
headset_power_mode(codec, 1);
13521404
priv->sysclk_constraints = &hp_constraints;
13531405
break;
13541406
default:

0 commit comments

Comments
 (0)