Skip to content

Commit

Permalink
ASoC: rt5682: Re-detect the combo jack after resuming
Browse files Browse the repository at this point in the history
[ Upstream commit 2cd9b0e ]

Sometimes, end-users change the jack type under suspending,
so it needs to re-detect the combo jack type after resuming to
avoid any unexpected behaviors.

Signed-off-by: Derek Fang <derek.fang@realtek.com>
Link: https://lore.kernel.org/r/20211109095450.12950-2-derek.fang@realtek.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
oortcomet authored and gregkh committed Jul 12, 2022
1 parent 4b72179 commit f536e0d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions sound/soc/codecs/rt5682-i2c.c
Expand Up @@ -196,6 +196,7 @@ static int rt5682_i2c_probe(struct i2c_client *i2c,
}

mutex_init(&rt5682->calibrate_mutex);
mutex_init(&rt5682->jdet_mutex);
rt5682_calibrate(rt5682);

rt5682_apply_patch_list(rt5682, &i2c->dev);
Expand Down
23 changes: 20 additions & 3 deletions sound/soc/codecs/rt5682.c
Expand Up @@ -49,6 +49,7 @@ static const struct reg_sequence patch_list[] = {
{RT5682_CHARGE_PUMP_1, 0x0210},
{RT5682_HP_LOGIC_CTRL_2, 0x0007},
{RT5682_SAR_IL_CMD_2, 0xac00},
{RT5682_CBJ_CTRL_7, 0x0104},
};

void rt5682_apply_patch_list(struct rt5682_priv *rt5682, struct device *dev)
Expand Down Expand Up @@ -943,6 +944,10 @@ int rt5682_headset_detect(struct snd_soc_component *component, int jack_insert)
snd_soc_component_update_bits(component,
RT5682_HP_CHARGE_PUMP_1,
RT5682_OSW_L_MASK | RT5682_OSW_R_MASK, 0);
rt5682_enable_push_button_irq(component, false);
snd_soc_component_update_bits(component, RT5682_CBJ_CTRL_1,
RT5682_TRIG_JD_MASK, RT5682_TRIG_JD_LOW);
usleep_range(55000, 60000);
snd_soc_component_update_bits(component, RT5682_CBJ_CTRL_1,
RT5682_TRIG_JD_MASK, RT5682_TRIG_JD_HIGH);

Expand Down Expand Up @@ -1099,6 +1104,7 @@ void rt5682_jack_detect_handler(struct work_struct *work)
return;
}

mutex_lock(&rt5682->jdet_mutex);
mutex_lock(&rt5682->calibrate_mutex);

val = snd_soc_component_read(rt5682->component, RT5682_AJD1_CTRL)
Expand Down Expand Up @@ -1172,6 +1178,7 @@ void rt5682_jack_detect_handler(struct work_struct *work)
}

mutex_unlock(&rt5682->calibrate_mutex);
mutex_unlock(&rt5682->jdet_mutex);
}
EXPORT_SYMBOL_GPL(rt5682_jack_detect_handler);

Expand Down Expand Up @@ -1521,6 +1528,7 @@ static int rt5682_hp_event(struct snd_soc_dapm_widget *w,
{
struct snd_soc_component *component =
snd_soc_dapm_to_component(w->dapm);
struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);

switch (event) {
case SND_SOC_DAPM_PRE_PMU:
Expand All @@ -1532,12 +1540,17 @@ static int rt5682_hp_event(struct snd_soc_dapm_widget *w,
RT5682_DEPOP_1, 0x60, 0x60);
snd_soc_component_update_bits(component,
RT5682_DAC_ADC_DIG_VOL1, 0x00c0, 0x0080);

mutex_lock(&rt5682->jdet_mutex);

snd_soc_component_update_bits(component, RT5682_HP_CTRL_2,
RT5682_HP_C2_DAC_L_EN | RT5682_HP_C2_DAC_R_EN,
RT5682_HP_C2_DAC_L_EN | RT5682_HP_C2_DAC_R_EN);
usleep_range(5000, 10000);
snd_soc_component_update_bits(component, RT5682_CHARGE_PUMP_1,
RT5682_CP_SW_SIZE_MASK, RT5682_CP_SW_SIZE_L);

mutex_unlock(&rt5682->jdet_mutex);
break;

case SND_SOC_DAPM_POST_PMD:
Expand Down Expand Up @@ -2969,7 +2982,7 @@ static int rt5682_suspend(struct snd_soc_component *component)

cancel_delayed_work_sync(&rt5682->jack_detect_work);
cancel_delayed_work_sync(&rt5682->jd_check_work);
if (rt5682->hs_jack && rt5682->jack_type == SND_JACK_HEADSET) {
if (rt5682->hs_jack && (rt5682->jack_type & SND_JACK_HEADSET) == SND_JACK_HEADSET) {
val = snd_soc_component_read(component,
RT5682_CBJ_CTRL_2) & RT5682_JACK_TYPE_MASK;

Expand Down Expand Up @@ -3000,6 +3013,8 @@ static int rt5682_suspend(struct snd_soc_component *component)
snd_soc_component_update_bits(component, RT5682_SAR_IL_CMD_1,
RT5682_SAR_BUTT_DET_MASK | RT5682_SAR_BUTDET_MODE_MASK,
RT5682_SAR_BUTT_DET_EN | RT5682_SAR_BUTDET_POW_SAV);
snd_soc_component_update_bits(component, RT5682_HP_CHARGE_PUMP_1,
RT5682_OSW_L_MASK | RT5682_OSW_R_MASK, 0);
}

regcache_cache_only(rt5682->regmap, true);
Expand All @@ -3017,19 +3032,21 @@ static int rt5682_resume(struct snd_soc_component *component)
regcache_cache_only(rt5682->regmap, false);
regcache_sync(rt5682->regmap);

if (rt5682->hs_jack && rt5682->jack_type == SND_JACK_HEADSET) {
if (rt5682->hs_jack && (rt5682->jack_type & SND_JACK_HEADSET) == SND_JACK_HEADSET) {
snd_soc_component_update_bits(component, RT5682_SAR_IL_CMD_1,
RT5682_SAR_BUTDET_MODE_MASK | RT5682_SAR_SEL_MB1_MB2_MASK,
RT5682_SAR_BUTDET_POW_NORM | RT5682_SAR_SEL_MB1_MB2_AUTO);
usleep_range(5000, 6000);
snd_soc_component_update_bits(component, RT5682_CBJ_CTRL_1,
RT5682_MB1_PATH_MASK | RT5682_MB2_PATH_MASK,
RT5682_CTRL_MB1_FSM | RT5682_CTRL_MB2_FSM);
snd_soc_component_update_bits(component, RT5682_PWR_ANLG_3,
RT5682_PWR_CBJ, RT5682_PWR_CBJ);
}

rt5682->jack_type = 0;
mod_delayed_work(system_power_efficient_wq,
&rt5682->jack_detect_work, msecs_to_jiffies(250));
&rt5682->jack_detect_work, msecs_to_jiffies(0));

return 0;
}
Expand Down
1 change: 1 addition & 0 deletions sound/soc/codecs/rt5682.h
Expand Up @@ -1462,6 +1462,7 @@ struct rt5682_priv {

int jack_type;
int irq_work_delay_time;
struct mutex jdet_mutex;
};

extern const char *rt5682_supply_names[RT5682_NUM_SUPPLIES];
Expand Down

0 comments on commit f536e0d

Please sign in to comment.