Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] ASoC: rt5645: Fix the electric noise due to the CBJ contacts floating
@ 2024-04-08  9:10 derek.fang
  2024-04-08  9:10 ` [PATCH 2/2] ASoC: dt-bindings: rt5645: add cbj sleeve gpio property derek.fang
  2024-04-09 18:08 ` [PATCH 1/2] ASoC: rt5645: Fix the electric noise due to the CBJ contacts floating Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: derek.fang @ 2024-04-08  9:10 UTC (permalink / raw)
  To: broonie, lgirdwood
  Cc: alsa-devel, lars, flove, oder_chiou, jack.yu, shumingf,
	albertchen, nico_cui, Derek Fang

From: Derek Fang <derek.fang@realtek.com>

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 <derek.fang@realtek.com>

diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index e3ba04484813..d0d24a53df74 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -444,6 +444,7 @@ struct rt5645_priv {
 	struct regmap *regmap;
 	struct i2c_client *i2c;
 	struct gpio_desc *gpiod_hp_det;
+	struct gpio_desc *gpiod_cbj_sleeve;
 	struct snd_soc_jack *hp_jack;
 	struct snd_soc_jack *mic_jack;
 	struct snd_soc_jack *btn_jack;
@@ -3186,6 +3187,9 @@ static int rt5645_jack_detect(struct snd_soc_component *component, int jack_inse
 		regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2,
 			RT5645_CBJ_MN_JD, 0);
 
+		if (rt5645->gpiod_cbj_sleeve)
+			gpiod_set_value(rt5645->gpiod_cbj_sleeve, 1);
+
 		msleep(600);
 		regmap_read(rt5645->regmap, RT5645_IN1_CTRL3, &val);
 		val &= 0x7;
@@ -3202,6 +3206,8 @@ static int rt5645_jack_detect(struct snd_soc_component *component, int jack_inse
 			snd_soc_dapm_disable_pin(dapm, "Mic Det Power");
 			snd_soc_dapm_sync(dapm);
 			rt5645->jack_type = SND_JACK_HEADPHONE;
+			if (rt5645->gpiod_cbj_sleeve)
+				gpiod_set_value(rt5645->gpiod_cbj_sleeve, 0);
 		}
 		if (rt5645->pdata.level_trigger_irq)
 			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
 		if (rt5645->pdata.level_trigger_irq)
 			regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2,
 				RT5645_JD_1_1_MASK, RT5645_JD_1_1_INV);
+
+		if (rt5645->gpiod_cbj_sleeve)
+			gpiod_set_value(rt5645->gpiod_cbj_sleeve, 0);
 	}
 
 	return rt5645->jack_type;
@@ -4012,6 +4021,16 @@ static int rt5645_i2c_probe(struct i2c_client *i2c)
 			return ret;
 	}
 
+	rt5645->gpiod_cbj_sleeve = devm_gpiod_get_optional(&i2c->dev, "cbj-sleeve",
+							   GPIOD_OUT_LOW);
+
+	if (IS_ERR(rt5645->gpiod_cbj_sleeve)) {
+		ret = PTR_ERR(rt5645->gpiod_cbj_sleeve);
+		dev_info(&i2c->dev, "failed to initialize gpiod, ret=%d\n", ret);
+		if (ret != -ENOENT)
+			return ret;
+	}
+
 	for (i = 0; i < ARRAY_SIZE(rt5645->supplies); i++)
 		rt5645->supplies[i].supply = rt5645_supply_names[i];
 
@@ -4259,6 +4278,9 @@ static void rt5645_i2c_remove(struct i2c_client *i2c)
 	cancel_delayed_work_sync(&rt5645->jack_detect_work);
 	cancel_delayed_work_sync(&rt5645->rcclock_work);
 
+	if (rt5645->gpiod_cbj_sleeve)
+		gpiod_set_value(rt5645->gpiod_cbj_sleeve, 0);
+
 	regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies);
 }
 
@@ -4274,6 +4296,9 @@ static void rt5645_i2c_shutdown(struct i2c_client *i2c)
 		0);
 	msleep(20);
 	regmap_write(rt5645->regmap, RT5645_RESET, 0);
+
+	if (rt5645->gpiod_cbj_sleeve)
+		gpiod_set_value(rt5645->gpiod_cbj_sleeve, 0);
 }
 
 static int __maybe_unused rt5645_sys_suspend(struct device *dev)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] ASoC: dt-bindings: rt5645: add cbj sleeve gpio property
  2024-04-08  9:10 [PATCH 1/2] ASoC: rt5645: Fix the electric noise due to the CBJ contacts floating derek.fang
@ 2024-04-08  9:10 ` derek.fang
  2024-04-09 18:08 ` [PATCH 1/2] ASoC: rt5645: Fix the electric noise due to the CBJ contacts floating Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: derek.fang @ 2024-04-08  9:10 UTC (permalink / raw)
  To: broonie, lgirdwood
  Cc: alsa-devel, lars, flove, oder_chiou, jack.yu, shumingf,
	albertchen, nico_cui, Derek Fang

From: Derek Fang <derek.fang@realtek.com>

Add an optional gpio property to control external CBJ circuits
to avoid some electric noise caused by sleeve/ring2 contacts floating.

Signed-off-by: Derek Fang <derek.fang@realtek.com>

diff --git a/Documentation/devicetree/bindings/sound/rt5645.txt b/Documentation/devicetree/bindings/sound/rt5645.txt
index 41a62fd2ae1f..c1fa379f5f3e 100644
--- a/Documentation/devicetree/bindings/sound/rt5645.txt
+++ b/Documentation/devicetree/bindings/sound/rt5645.txt
@@ -20,6 +20,11 @@ Optional properties:
   a GPIO spec for the external headphone detect pin. If jd-mode = 0,
   we will get the JD status by getting the value of hp-detect-gpios.
 
+- cbj-sleeve-gpios:
+  a GPIO spec to control the external combo jack circuit to tie the sleeve/ring2
+  contacts to the ground or floating. It could avoid some electric noise from the
+  active speaker jacks.
+
 - realtek,in2-differential
   Boolean. Indicate MIC2 input are differential, rather than single-ended.
 
@@ -68,6 +73,7 @@ codec: rt5650@1a {
 	compatible = "realtek,rt5650";
 	reg = <0x1a>;
 	hp-detect-gpios = <&gpio 19 0>;
+	cbj-sleeve-gpios = <&gpio 20 0>;
 	interrupt-parent = <&gpio>;
 	interrupts = <7 IRQ_TYPE_EDGE_FALLING>;
 	realtek,dmic-en = "true";
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] ASoC: rt5645: Fix the electric noise due to the CBJ contacts floating
  2024-04-08  9:10 [PATCH 1/2] ASoC: rt5645: Fix the electric noise due to the CBJ contacts floating derek.fang
  2024-04-08  9:10 ` [PATCH 2/2] ASoC: dt-bindings: rt5645: add cbj sleeve gpio property derek.fang
@ 2024-04-09 18:08 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2024-04-09 18:08 UTC (permalink / raw)
  To: lgirdwood, derek.fang
  Cc: alsa-devel, lars, flove, oder_chiou, jack.yu, shumingf,
	albertchen, nico_cui

On Mon, 08 Apr 2024 17:10:56 +0800, derek.fang@realtek.com wrote:
> 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.
> 
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/2] ASoC: rt5645: Fix the electric noise due to the CBJ contacts floating
      commit: 103abab975087e1f01b76fcb54c91dbb65dbc249
[2/2] ASoC: dt-bindings: rt5645: add cbj sleeve gpio property
      commit: 306b38e3fa727d22454a148a364123709e356600

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-09 18:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-08  9:10 [PATCH 1/2] ASoC: rt5645: Fix the electric noise due to the CBJ contacts floating derek.fang
2024-04-08  9:10 ` [PATCH 2/2] ASoC: dt-bindings: rt5645: add cbj sleeve gpio property derek.fang
2024-04-09 18:08 ` [PATCH 1/2] ASoC: rt5645: Fix the electric noise due to the CBJ contacts floating Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox