Skip to content

Commit

Permalink
ASoC: rt5682s: Fix the wrong jack type detected
Browse files Browse the repository at this point in the history
Some powers were changed during the jack insert detection and clk's
enable/disable in CCF.
If in parallel, the influence has a chance to detect the wrong jack
type.

We refer to the below commit of the variant codec (rt5682) to fix
this issue.
  ASoC: rt5682: Fix deadlock on resume

1. Remove rt5682s_headset_detect in rt5682s_jd_check_handler and
   use jack_detect_work instead of.
2. Use dapm mutex used in CCF to protect most of jack_detect_work.

Signed-off-by: Derek Fang <derek.fang@realtek.com>
Link: https://lore.kernel.org/r/20220223101450.4577-1-derek.fang@realtek.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
oortcomet authored and broonie committed Feb 24, 2022
1 parent 7e1d728 commit c07ac3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
26 changes: 9 additions & 17 deletions sound/soc/codecs/rt5682s.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ static void rt5682s_jack_detect_handler(struct work_struct *work)
{
struct rt5682s_priv *rt5682s =
container_of(work, struct rt5682s_priv, jack_detect_work.work);
struct snd_soc_dapm_context *dapm;
int val, btn_type;

if (!rt5682s->component || !rt5682s->component->card ||
Expand All @@ -832,7 +833,9 @@ static void rt5682s_jack_detect_handler(struct work_struct *work)
return;
}

mutex_lock(&rt5682s->jdet_mutex);
dapm = snd_soc_component_get_dapm(rt5682s->component);

snd_soc_dapm_mutex_lock(dapm);
mutex_lock(&rt5682s->calibrate_mutex);

val = snd_soc_component_read(rt5682s->component, RT5682S_AJD1_CTRL)
Expand Down Expand Up @@ -889,6 +892,9 @@ static void rt5682s_jack_detect_handler(struct work_struct *work)
rt5682s->irq_work_delay_time = 50;
}

mutex_unlock(&rt5682s->calibrate_mutex);
snd_soc_dapm_mutex_unlock(dapm);

snd_soc_jack_report(rt5682s->hs_jack, rt5682s->jack_type,
SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
SND_JACK_BTN_2 | SND_JACK_BTN_3);
Expand All @@ -898,24 +904,16 @@ static void rt5682s_jack_detect_handler(struct work_struct *work)
schedule_delayed_work(&rt5682s->jd_check_work, 0);
else
cancel_delayed_work_sync(&rt5682s->jd_check_work);

mutex_unlock(&rt5682s->calibrate_mutex);
mutex_unlock(&rt5682s->jdet_mutex);
}

static void rt5682s_jd_check_handler(struct work_struct *work)
{
struct rt5682s_priv *rt5682s =
container_of(work, struct rt5682s_priv, jd_check_work.work);

if (snd_soc_component_read(rt5682s->component, RT5682S_AJD1_CTRL)
& RT5682S_JDH_RS_MASK) {
if (snd_soc_component_read(rt5682s->component, RT5682S_AJD1_CTRL) & RT5682S_JDH_RS_MASK) {
/* jack out */
rt5682s->jack_type = rt5682s_headset_detect(rt5682s->component, 0);

snd_soc_jack_report(rt5682s->hs_jack, rt5682s->jack_type,
SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
SND_JACK_BTN_2 | SND_JACK_BTN_3);
schedule_delayed_work(&rt5682s->jack_detect_work, 0);
} else {
schedule_delayed_work(&rt5682s->jd_check_work, 500);
}
Expand Down Expand Up @@ -1323,7 +1321,6 @@ static int rt5682s_hp_amp_event(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol, int event)
{
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
struct rt5682s_priv *rt5682s = snd_soc_component_get_drvdata(component);

switch (event) {
case SND_SOC_DAPM_POST_PMU:
Expand All @@ -1339,17 +1336,13 @@ static int rt5682s_hp_amp_event(struct snd_soc_dapm_widget *w,
snd_soc_component_write(component, RT5682S_BIAS_CUR_CTRL_11, 0x6666);
snd_soc_component_write(component, RT5682S_BIAS_CUR_CTRL_12, 0xa82a);

mutex_lock(&rt5682s->jdet_mutex);

snd_soc_component_update_bits(component, RT5682S_HP_CTRL_2,
RT5682S_HPO_L_PATH_MASK | RT5682S_HPO_R_PATH_MASK |
RT5682S_HPO_SEL_IP_EN_SW, RT5682S_HPO_L_PATH_EN |
RT5682S_HPO_R_PATH_EN | RT5682S_HPO_IP_EN_GATING);
usleep_range(5000, 10000);
snd_soc_component_update_bits(component, RT5682S_HP_AMP_DET_CTL_1,
RT5682S_CP_SW_SIZE_MASK, RT5682S_CP_SW_SIZE_L | RT5682S_CP_SW_SIZE_S);

mutex_unlock(&rt5682s->jdet_mutex);
break;

case SND_SOC_DAPM_POST_PMD:
Expand Down Expand Up @@ -3103,7 +3096,6 @@ static int rt5682s_i2c_probe(struct i2c_client *i2c,

mutex_init(&rt5682s->calibrate_mutex);
mutex_init(&rt5682s->sar_mutex);
mutex_init(&rt5682s->jdet_mutex);
rt5682s_calibrate(rt5682s);

regmap_update_bits(rt5682s->regmap, RT5682S_MICBIAS_2,
Expand Down
1 change: 0 additions & 1 deletion sound/soc/codecs/rt5682s.h
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,6 @@ struct rt5682s_priv {
struct delayed_work jd_check_work;
struct mutex calibrate_mutex;
struct mutex sar_mutex;
struct mutex jdet_mutex;

#ifdef CONFIG_COMMON_CLK
struct clk_hw dai_clks_hw[RT5682S_DAI_NUM_CLKS];
Expand Down

0 comments on commit c07ac3e

Please sign in to comment.