Skip to content

Commit 103abab

Browse files
oortcometbroonie
authored andcommitted
ASoC: rt5645: Fix the electric noise due to the CBJ contacts floating
The codec leaves tie combo jack's sleeve/ring2 to floating status default. It would cause electric noise while connecting the active speaker jack during boot or shutdown. This patch requests a gpio to control the additional jack circuit to tie the contacts to the ground or floating. Signed-off-by: Derek Fang <[email protected]> Link: https://msgid.link/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 4b9a474 commit 103abab

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

sound/soc/codecs/rt5645.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ struct rt5645_priv {
444444
struct regmap *regmap;
445445
struct i2c_client *i2c;
446446
struct gpio_desc *gpiod_hp_det;
447+
struct gpio_desc *gpiod_cbj_sleeve;
447448
struct snd_soc_jack *hp_jack;
448449
struct snd_soc_jack *mic_jack;
449450
struct snd_soc_jack *btn_jack;
@@ -3186,6 +3187,9 @@ static int rt5645_jack_detect(struct snd_soc_component *component, int jack_inse
31863187
regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2,
31873188
RT5645_CBJ_MN_JD, 0);
31883189

3190+
if (rt5645->gpiod_cbj_sleeve)
3191+
gpiod_set_value(rt5645->gpiod_cbj_sleeve, 1);
3192+
31893193
msleep(600);
31903194
regmap_read(rt5645->regmap, RT5645_IN1_CTRL3, &val);
31913195
val &= 0x7;
@@ -3202,6 +3206,8 @@ static int rt5645_jack_detect(struct snd_soc_component *component, int jack_inse
32023206
snd_soc_dapm_disable_pin(dapm, "Mic Det Power");
32033207
snd_soc_dapm_sync(dapm);
32043208
rt5645->jack_type = SND_JACK_HEADPHONE;
3209+
if (rt5645->gpiod_cbj_sleeve)
3210+
gpiod_set_value(rt5645->gpiod_cbj_sleeve, 0);
32053211
}
32063212
if (rt5645->pdata.level_trigger_irq)
32073213
regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2,
@@ -3229,6 +3235,9 @@ static int rt5645_jack_detect(struct snd_soc_component *component, int jack_inse
32293235
if (rt5645->pdata.level_trigger_irq)
32303236
regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2,
32313237
RT5645_JD_1_1_MASK, RT5645_JD_1_1_INV);
3238+
3239+
if (rt5645->gpiod_cbj_sleeve)
3240+
gpiod_set_value(rt5645->gpiod_cbj_sleeve, 0);
32323241
}
32333242

32343243
return rt5645->jack_type;
@@ -4012,6 +4021,16 @@ static int rt5645_i2c_probe(struct i2c_client *i2c)
40124021
return ret;
40134022
}
40144023

4024+
rt5645->gpiod_cbj_sleeve = devm_gpiod_get_optional(&i2c->dev, "cbj-sleeve",
4025+
GPIOD_OUT_LOW);
4026+
4027+
if (IS_ERR(rt5645->gpiod_cbj_sleeve)) {
4028+
ret = PTR_ERR(rt5645->gpiod_cbj_sleeve);
4029+
dev_info(&i2c->dev, "failed to initialize gpiod, ret=%d\n", ret);
4030+
if (ret != -ENOENT)
4031+
return ret;
4032+
}
4033+
40154034
for (i = 0; i < ARRAY_SIZE(rt5645->supplies); i++)
40164035
rt5645->supplies[i].supply = rt5645_supply_names[i];
40174036

@@ -4259,6 +4278,9 @@ static void rt5645_i2c_remove(struct i2c_client *i2c)
42594278
cancel_delayed_work_sync(&rt5645->jack_detect_work);
42604279
cancel_delayed_work_sync(&rt5645->rcclock_work);
42614280

4281+
if (rt5645->gpiod_cbj_sleeve)
4282+
gpiod_set_value(rt5645->gpiod_cbj_sleeve, 0);
4283+
42624284
regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies);
42634285
}
42644286

@@ -4274,6 +4296,9 @@ static void rt5645_i2c_shutdown(struct i2c_client *i2c)
42744296
0);
42754297
msleep(20);
42764298
regmap_write(rt5645->regmap, RT5645_RESET, 0);
4299+
4300+
if (rt5645->gpiod_cbj_sleeve)
4301+
gpiod_set_value(rt5645->gpiod_cbj_sleeve, 0);
42774302
}
42784303

42794304
static int __maybe_unused rt5645_sys_suspend(struct device *dev)

0 commit comments

Comments
 (0)