Skip to contentSkip to conversation

ASoC: rt5670: add HS ground control

PATCH In review Bard Liao 3 participants 9 messages Dec 29, 2016 – Feb 4, 2017 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

Bard Liao

author
#0 lore raw

PATCH 1/1 ASoC: rt5670: add HS ground control

Some project use external circuit to prevent the headset ground noise. It will need to use GPIO to control it. Dell Wyse 3040 is the only project that has the external circuit so far and it uses GPIO2 for that. This patch provide the support fot it.

---
 include/sound/rt5670.h    |  7 +++++
 sound/soc/codecs/rt5670.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 80 insertions(+), 1 deletion(-)
include/sound/rt5670.h +7 -0
index b7d6051..0b445b0 100644
@@ -11,12 +11,19 @@
 #ifndef __LINUX_SND_RT5670_H
 #define __LINUX_SND_RT5670_H
 
+enum rt5670_gpios {
+	RT5670_GPIO_NONE = 0,
+	RT5670_GPIO2,
+};
+
+
 struct rt5670_platform_data {
 	int jd_mode;
 	bool in2_diff;
 	bool dev_gpio;
 
 	bool dmic_en;
+	enum rt5670_gpios hs_ground_control_gpio;
 	unsigned int dmic1_data_pin;
 	/* 0 = GPIO6; 1 = IN2P; 3 = GPIO7*/
 	unsigned int dmic2_data_pin;
sound/soc/codecs/rt5670.c +73 -1

134 lines not on this page · raw message

Signature · 1 line
1.8.1.1.439.g50a6b54
Tested-by Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Bard Liao

Some project use external circuit to prevent the headset ground noise. It will need to use GPIO to control it. Dell Wyse 3040 is the only project that has the external circuit so far and it uses GPIO2 for that. This patch provide the support fot it.

thanks,

Takashi

Quoted 179 lines
---
 include/sound/rt5670.h    |  7 +++++
 sound/soc/codecs/rt5670.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 80 insertions(+), 1 deletion(-)
include/sound/rt5670.h +7 -0
index b7d6051..0b445b0 100644
@@ -11,12 +11,19 @@
 #ifndef __LINUX_SND_RT5670_H
 #define __LINUX_SND_RT5670_H
 
+enum rt5670_gpios {
+	RT5670_GPIO_NONE = 0,
+	RT5670_GPIO2,
+};
+
+
 struct rt5670_platform_data {
 	int jd_mode;
 	bool in2_diff;
 	bool dev_gpio;
 
 	bool dmic_en;
+	enum rt5670_gpios hs_ground_control_gpio;
 	unsigned int dmic1_data_pin;
 	/* 0 = GPIO6; 1 = IN2P; 3 = GPIO7*/
 	unsigned int dmic2_data_pin;
sound/soc/codecs/rt5670.c +73 -1
index 97bafac..1d94cec 100644
@@ -420,13 +420,15 @@ static int rt5670_headset_detect(struct snd_soc_codec *codec, int jack_insert)
 	struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec);
 
 	if (jack_insert) {
+		if (rt5670->pdata.hs_ground_control_gpio)
+			snd_soc_dapm_force_enable_pin(dapm, "HS GND Control");
+
 		snd_soc_dapm_force_enable_pin(dapm, "Mic Det Power");
 		snd_soc_dapm_sync(dapm);
 		snd_soc_update_bits(codec, RT5670_GEN_CTRL3, 0x4, 0x0);
 		snd_soc_update_bits(codec, RT5670_CJ_CTRL2,
 			RT5670_CBJ_DET_MODE | RT5670_CBJ_MN_JD,
 			RT5670_CBJ_MN_JD);
-		snd_soc_write(codec, RT5670_GPIO_CTRL2, 0x0004);
 		snd_soc_update_bits(codec, RT5670_GPIO_CTRL1,
 			RT5670_GP1_PIN_MASK, RT5670_GP1_PIN_IRQ);
 		snd_soc_update_bits(codec, RT5670_CJ_CTRL1,
@@ -450,6 +452,10 @@ static int rt5670_headset_detect(struct snd_soc_codec *codec, int jack_insert)
 			snd_soc_dapm_disable_pin(dapm, "Mic Det Power");
 			snd_soc_dapm_sync(dapm);
 		}
+		if (rt5670->pdata.hs_ground_control_gpio) {
+			snd_soc_dapm_disable_pin(dapm, "HS GND Control");
+			snd_soc_dapm_sync(dapm);
+		}
 	} else {
 		snd_soc_update_bits(codec, RT5670_INT_IRQ_ST, 0x8, 0x0);
 		snd_soc_update_bits(codec, RT5670_GEN_CTRL3, 0x4, 0x4);
@@ -1542,6 +1548,29 @@ static int rt5670_bst2_event(struct snd_soc_dapm_widget *w,
 	return 0;
 }
 
+static int rt5670_hs_ground_control_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
+
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+		snd_soc_update_bits(codec, RT5670_GPIO_CTRL2,
+				RT5670_GP2_OUT_MASK, RT5670_GP2_OUT_HI);
+		break;
+
+	case SND_SOC_DAPM_POST_PMD:
+		snd_soc_update_bits(codec, RT5670_GPIO_CTRL2,
+				RT5670_GP2_OUT_MASK, RT5670_GP2_OUT_LO);
+		break;
+
+	default:
+		return 0;
+	}
+
+	return 0;
+}
+
 static const struct snd_soc_dapm_widget rt5670_dapm_widgets[] = {
 	SND_SOC_DAPM_SUPPLY("PLL1", RT5670_PWR_ANLG2,
 			    RT5670_PWR_PLL_BIT, 0, NULL, 0),
@@ -1917,6 +1946,12 @@ static int rt5670_bst2_event(struct snd_soc_dapm_widget *w,
 	SND_SOC_DAPM_OUTPUT("SPORN"),
 };
 
+static const struct snd_soc_dapm_widget hs_gnd_cnotrol_widgets[] = {
+	SND_SOC_DAPM_SUPPLY("HS GND Control", SND_SOC_NOPM, 0, 0,
+			rt5670_hs_ground_control_event,
+			SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
+};
+
 static const struct snd_soc_dapm_route rt5670_dapm_routes[] = {
 	{ "ADC Stereo1 Filter", NULL, "ADC STO1 ASRC", is_using_asrc },
 	{ "ADC Stereo2 Filter", NULL, "ADC STO2 ASRC", is_using_asrc },
@@ -2314,6 +2349,11 @@ static int rt5670_bst2_event(struct snd_soc_dapm_widget *w,
 	{ "SPORN", NULL, "SPO Amp" },
 };
 
+static const struct snd_soc_dapm_route hs_gnd_cnotrol_routes[] = {
+	{ "BST1", NULL, "HS GND Control" },
+	{ "HP Amp", NULL, "HS GND Control" },
+};
+
 static int rt5670_hw_params(struct snd_pcm_substream *substream,
 	struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
 {
@@ -2679,6 +2719,13 @@ static int rt5670_probe(struct snd_soc_codec *codec)
 			"The driver is for RT5670 RT5671 or RT5672 only\n");
 		return -ENODEV;
 	}
+	if (rt5670->pdata.hs_ground_control_gpio) {
+		snd_soc_dapm_new_controls(dapm, hs_gnd_cnotrol_widgets,
+			ARRAY_SIZE(hs_gnd_cnotrol_widgets));
+		snd_soc_dapm_add_routes(dapm, hs_gnd_cnotrol_routes,
+			ARRAY_SIZE(hs_gnd_cnotrol_routes));
+	}
+
 	rt5670->codec = codec;
 
 	return 0;
@@ -2827,6 +2874,10 @@ static int rt5670_resume(struct snd_soc_codec *codec)
 			DMI_MATCH(DMI_BOARD_NAME, "Braswell CRB"),
 		},
 	},
+	{}
+};
+
+static const struct dmi_system_id dmi_platform_dell_wyse[] = {
 	{
 		.ident = "Dell Wyse 3040",
 		.matches = {
@@ -2861,6 +2912,12 @@ static int rt5670_i2c_probe(struct i2c_client *i2c,
 		rt5670->pdata.dmic1_data_pin = RT5670_DMIC_DATA_IN2P;
 		rt5670->pdata.dev_gpio = true;
 		rt5670->pdata.jd_mode = 1;
+		rt5670->pdata.hs_ground_control_gpio = RT5670_GPIO_NONE;
+	} else if (dmi_check_system(dmi_platform_dell_wyse)) {
+		rt5670->pdata.dmic_en = false;
+		rt5670->pdata.dev_gpio = true;
+		rt5670->pdata.jd_mode = 1;
+		rt5670->pdata.hs_ground_control_gpio = RT5670_GPIO2;
 	}
 
 	rt5670->regmap = devm_regmap_init_i2c(i2c, &rt5670_regmap);
@@ -2886,6 +2943,21 @@ static int rt5670_i2c_probe(struct i2c_client *i2c,
 
 	regmap_write(rt5670->regmap, RT5670_RESET, 0);
 
+	switch (rt5670->pdata.hs_ground_control_gpio) {
+	case RT5670_GPIO_NONE:
+		break;
+	case RT5670_GPIO2:
+		regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL2,
+			RT5670_GP2_PF_MASK | RT5670_GP2_OUT_MASK,
+			RT5670_GP2_PF_OUT | RT5670_GP2_OUT_LO);
+		break;
+	default:
+		rt5670->pdata.hs_ground_control_gpio =
+			RT5670_GPIO_NONE;
+		dev_warn(&i2c->dev, "Only Support GPIO2 currently\n");
+			break;
+	}
+
 	regmap_read(rt5670->regmap, RT5670_VENDOR_ID, &val);
 	if (val >= 4)
 		regmap_write(rt5670->regmap, RT5670_GPIO_CTRL3, 0x0980);
Signature · 1 line
1.8.1.1.439.g50a6b54
Tested-by on v1 1/1
#2 lore raw
In reply to Bard Liao
Quoted 7 lines · Bard Liao

Some project use external circuit to prevent the headset ground noise. It will need to use GPIO to control it. Dell Wyse 3040 is the only project that has the external circuit so far and it uses GPIO2 for that. This patch provide the support fot it.

Mark, this seems overlooked?

Feel free to add:

thanks,

Takashi

Quoted 184 lines
---
 include/sound/rt5670.h    |  7 +++++
 sound/soc/codecs/rt5670.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 80 insertions(+), 1 deletion(-)
include/sound/rt5670.h +7 -0
index b7d6051..0b445b0 100644
@@ -11,12 +11,19 @@
 #ifndef __LINUX_SND_RT5670_H
 #define __LINUX_SND_RT5670_H
 
+enum rt5670_gpios {
+	RT5670_GPIO_NONE = 0,
+	RT5670_GPIO2,
+};
+
+
 struct rt5670_platform_data {
 	int jd_mode;
 	bool in2_diff;
 	bool dev_gpio;
 
 	bool dmic_en;
+	enum rt5670_gpios hs_ground_control_gpio;
 	unsigned int dmic1_data_pin;
 	/* 0 = GPIO6; 1 = IN2P; 3 = GPIO7*/
 	unsigned int dmic2_data_pin;
sound/soc/codecs/rt5670.c +73 -1
index 97bafac..1d94cec 100644
@@ -420,13 +420,15 @@ static int rt5670_headset_detect(struct snd_soc_codec *codec, int jack_insert)
 	struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec);
 
 	if (jack_insert) {
+		if (rt5670->pdata.hs_ground_control_gpio)
+			snd_soc_dapm_force_enable_pin(dapm, "HS GND Control");
+
 		snd_soc_dapm_force_enable_pin(dapm, "Mic Det Power");
 		snd_soc_dapm_sync(dapm);
 		snd_soc_update_bits(codec, RT5670_GEN_CTRL3, 0x4, 0x0);
 		snd_soc_update_bits(codec, RT5670_CJ_CTRL2,
 			RT5670_CBJ_DET_MODE | RT5670_CBJ_MN_JD,
 			RT5670_CBJ_MN_JD);
-		snd_soc_write(codec, RT5670_GPIO_CTRL2, 0x0004);
 		snd_soc_update_bits(codec, RT5670_GPIO_CTRL1,
 			RT5670_GP1_PIN_MASK, RT5670_GP1_PIN_IRQ);
 		snd_soc_update_bits(codec, RT5670_CJ_CTRL1,
@@ -450,6 +452,10 @@ static int rt5670_headset_detect(struct snd_soc_codec *codec, int jack_insert)
 			snd_soc_dapm_disable_pin(dapm, "Mic Det Power");
 			snd_soc_dapm_sync(dapm);
 		}
+		if (rt5670->pdata.hs_ground_control_gpio) {
+			snd_soc_dapm_disable_pin(dapm, "HS GND Control");
+			snd_soc_dapm_sync(dapm);
+		}
 	} else {
 		snd_soc_update_bits(codec, RT5670_INT_IRQ_ST, 0x8, 0x0);
 		snd_soc_update_bits(codec, RT5670_GEN_CTRL3, 0x4, 0x4);
@@ -1542,6 +1548,29 @@ static int rt5670_bst2_event(struct snd_soc_dapm_widget *w,
 	return 0;
 }
 
+static int rt5670_hs_ground_control_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
+
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+		snd_soc_update_bits(codec, RT5670_GPIO_CTRL2,
+				RT5670_GP2_OUT_MASK, RT5670_GP2_OUT_HI);
+		break;
+
+	case SND_SOC_DAPM_POST_PMD:
+		snd_soc_update_bits(codec, RT5670_GPIO_CTRL2,
+				RT5670_GP2_OUT_MASK, RT5670_GP2_OUT_LO);
+		break;
+
+	default:
+		return 0;
+	}
+
+	return 0;
+}
+
 static const struct snd_soc_dapm_widget rt5670_dapm_widgets[] = {
 	SND_SOC_DAPM_SUPPLY("PLL1", RT5670_PWR_ANLG2,
 			    RT5670_PWR_PLL_BIT, 0, NULL, 0),
@@ -1917,6 +1946,12 @@ static int rt5670_bst2_event(struct snd_soc_dapm_widget *w,
 	SND_SOC_DAPM_OUTPUT("SPORN"),
 };
 
+static const struct snd_soc_dapm_widget hs_gnd_cnotrol_widgets[] = {
+	SND_SOC_DAPM_SUPPLY("HS GND Control", SND_SOC_NOPM, 0, 0,
+			rt5670_hs_ground_control_event,
+			SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
+};
+
 static const struct snd_soc_dapm_route rt5670_dapm_routes[] = {
 	{ "ADC Stereo1 Filter", NULL, "ADC STO1 ASRC", is_using_asrc },
 	{ "ADC Stereo2 Filter", NULL, "ADC STO2 ASRC", is_using_asrc },
@@ -2314,6 +2349,11 @@ static int rt5670_bst2_event(struct snd_soc_dapm_widget *w,
 	{ "SPORN", NULL, "SPO Amp" },
 };
 
+static const struct snd_soc_dapm_route hs_gnd_cnotrol_routes[] = {
+	{ "BST1", NULL, "HS GND Control" },
+	{ "HP Amp", NULL, "HS GND Control" },
+};
+
 static int rt5670_hw_params(struct snd_pcm_substream *substream,
 	struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
 {
@@ -2679,6 +2719,13 @@ static int rt5670_probe(struct snd_soc_codec *codec)
 			"The driver is for RT5670 RT5671 or RT5672 only\n");
 		return -ENODEV;
 	}
+	if (rt5670->pdata.hs_ground_control_gpio) {
+		snd_soc_dapm_new_controls(dapm, hs_gnd_cnotrol_widgets,
+			ARRAY_SIZE(hs_gnd_cnotrol_widgets));
+		snd_soc_dapm_add_routes(dapm, hs_gnd_cnotrol_routes,
+			ARRAY_SIZE(hs_gnd_cnotrol_routes));
+	}
+
 	rt5670->codec = codec;
 
 	return 0;
@@ -2827,6 +2874,10 @@ static int rt5670_resume(struct snd_soc_codec *codec)
 			DMI_MATCH(DMI_BOARD_NAME, "Braswell CRB"),
 		},
 	},
+	{}
+};
+
+static const struct dmi_system_id dmi_platform_dell_wyse[] = {
 	{
 		.ident = "Dell Wyse 3040",
 		.matches = {
@@ -2861,6 +2912,12 @@ static int rt5670_i2c_probe(struct i2c_client *i2c,
 		rt5670->pdata.dmic1_data_pin = RT5670_DMIC_DATA_IN2P;
 		rt5670->pdata.dev_gpio = true;
 		rt5670->pdata.jd_mode = 1;
+		rt5670->pdata.hs_ground_control_gpio = RT5670_GPIO_NONE;
+	} else if (dmi_check_system(dmi_platform_dell_wyse)) {
+		rt5670->pdata.dmic_en = false;
+		rt5670->pdata.dev_gpio = true;
+		rt5670->pdata.jd_mode = 1;
+		rt5670->pdata.hs_ground_control_gpio = RT5670_GPIO2;
 	}
 
 	rt5670->regmap = devm_regmap_init_i2c(i2c, &rt5670_regmap);
@@ -2886,6 +2943,21 @@ static int rt5670_i2c_probe(struct i2c_client *i2c,
 
 	regmap_write(rt5670->regmap, RT5670_RESET, 0);
 
+	switch (rt5670->pdata.hs_ground_control_gpio) {
+	case RT5670_GPIO_NONE:
+		break;
+	case RT5670_GPIO2:
+		regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL2,
+			RT5670_GP2_PF_MASK | RT5670_GP2_OUT_MASK,
+			RT5670_GP2_PF_OUT | RT5670_GP2_OUT_LO);
+		break;
+	default:
+		rt5670->pdata.hs_ground_control_gpio =
+			RT5670_GPIO_NONE;
+		dev_warn(&i2c->dev, "Only Support GPIO2 currently\n");
+			break;
+	}
+
 	regmap_read(rt5670->regmap, RT5670_VENDOR_ID, &val);
 	if (val >= 4)
 		regmap_write(rt5670->regmap, RT5670_GPIO_CTRL3, 0x0980);
Signature · 6 lines
1.8.1.1.439.g50a6b54

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
maintainer
#3 lore raw
Quoted 8 lines · Takashi Iwai

On Thu, 29 Dec 2016 09:23:47 +0100,

Quoted 4 lines

Some project use external circuit to prevent the headset ground noise. It will need to use GPIO to control it. Dell Wyse 3040 is the only project that has the external circuit so far and it uses GPIO2 for that. This patch provide the support fot it.

Mark, this seems overlooked?

No, it's complicated. IIRC it's not *actually* doing GPIO management, it's adding an option to wiggle a pin on the one board you've so far that happens to have this issue but if someone finds a GPIO from somewhere else it'll run into trouble. But now when I go look at it again you sent a content free ping so...

#4 lore raw
Quoted 9 lines · Mark Brown
Quoted 6 lines · Takashi Iwai

On Thu, 29 Dec 2016 09:23:47 +0100,

Quoted 4 lines

Some project use external circuit to prevent the headset ground noise. It will need to use GPIO to control it. Dell Wyse 3040 is the only project that has the external circuit so far and it uses GPIO2 for that. This patch provide the support fot it.

Quoted 6 lines
Quoted 1 line

Mark, this seems overlooked?

No, it's complicated. IIRC it's not *actually* doing GPIO management, it's adding an option to wiggle a pin on the one board you've so far that happens to have this issue but if someone finds a GPIO from somewhere else it'll run into trouble.

How that can happen? It applies only via DMI matching.

Takashi

maintainer
#5 lore raw
Quoted 8 lines · Takashi Iwai
Quoted 4 lines · Mark Brown

No, it's complicated. IIRC it's not *actually* doing GPIO management, it's adding an option to wiggle a pin on the one board you've so far that happens to have this issue but if someone finds a GPIO from somewhere else it'll run into trouble.

How that can happen? It applies only via DMI matching.

Sure, it works on that one machine but if someone else did something similar but using a different GPIO it (from what I remember) might not work. I think I was going to try to figure out if it was really a GPIO or if perhaps the changelog is just not clear.

But anyway, content free ping so...

#6 lore raw
Quoted 9 lines · Mark Brown
Quoted 6 lines · Takashi Iwai
Quoted 4 lines · Mark Brown

No, it's complicated. IIRC it's not *actually* doing GPIO management, it's adding an option to wiggle a pin on the one board you've so far that happens to have this issue but if someone finds a GPIO from somewhere else it'll run into trouble.

Quoted 5 lines
Quoted 1 line

How that can happen? It applies only via DMI matching.

Sure, it works on that one machine but if someone else did something similar but using a different GPIO it (from what I remember) might not work.

For other GPIO pin, you'll need to write another similar codes, sure. But why do you need to worry so much about it? It doesn't work even without this patch, and a complete generalization isn't so trivial, I'm afraid, as it's anyway pretty device-specific.

Quoted 2 lines

I think I was going to try to figure out if it was really a GPIO or if perhaps the changelog is just not clear.

The changelog looks fairly short and maybe not sufficiently explaining the actual code changes. Basically the patch gives a new DMI-based quirk entry to add a control of GPIO2 pin via DAPM per headset detection.

The single deleted line is the removal of the GPIO_CTRL2 reg write at headset detection, and according to Bard, this was superfluous and should have been removed.

Quoted 1 line

But anyway, content free ping so...

I'm not the author of this patch, either, but just a by-stander casually involved with the development, so I leave the rest to Bard :)

thanks,

Takashi

maintainer
#7 lore raw
Quoted 10 lines · Takashi Iwai
Quoted 3 lines · Mark Brown

Sure, it works on that one machine but if someone else did something similar but using a different GPIO it (from what I remember) might not work.

For other GPIO pin, you'll need to write another similar codes, sure. But why do you need to worry so much about it? It doesn't work even without this patch, and a complete generalization isn't so trivial, I'm afraid, as it's anyway pretty device-specific.

I don't know, I need to figure this stuff out which is why the patch is still in the queue. If it is just using a regular GPIO then gpiolib is pretty trivial to use.

A message that is not in the archive (sent off-list or not yet received): ABFD875FF5FB574BA706497D987D48D70124DF38@RTITMBSV03.realtek.com.tw

maintainer
#9 lore raw
Quoted 4 lines · Bard Liao

It is a codec GPIO, indeed. But we don't register it to gpiolib. So there is no other way to touch the GPIO. We are using it to do headset ground control and we should control its level according to if headset is using. That's why we control it by a DAPM event.

So one option here would be to register it with gpiolib...