All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bard Liao <bardliao@realtek.com>
To: broonie@kernel.org, lgirdwood@gmail.com
Cc: oder_chiou@realtek.com, jack.yu@realtek.com,
	alsa-devel@alsa-project.org, lars@metafoo.de, tiwai@suse.de,
	shumingf@realtek.com, Bard Liao <bardliao@realtek.com>,
	flove@realtek.com
Subject: [PATCH] ASoC: rt5670: add HS ground control
Date: Thu, 29 Dec 2016 16:23:47 +0800	[thread overview]
Message-ID: <1482999827-14705-1-git-send-email-bardliao@realtek.com> (raw)

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.

Signed-off-by: Bard Liao <bardliao@realtek.com>
---
 include/sound/rt5670.h    |  7 +++++
 sound/soc/codecs/rt5670.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/include/sound/rt5670.h b/include/sound/rt5670.h
index b7d6051..0b445b0 100644
--- a/include/sound/rt5670.h
+++ b/include/sound/rt5670.h
@@ -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;
diff --git a/sound/soc/codecs/rt5670.c b/sound/soc/codecs/rt5670.c
index 97bafac..1d94cec 100644
--- a/sound/soc/codecs/rt5670.c
+++ b/sound/soc/codecs/rt5670.c
@@ -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);
-- 
1.8.1.1.439.g50a6b54

             reply	other threads:[~2016-12-29  8:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-29  8:23 Bard Liao [this message]
2017-01-02 12:03 ` [PATCH] ASoC: rt5670: add HS ground control Takashi Iwai
2017-01-30  9:58 ` Takashi Iwai
2017-02-01 11:47   ` Mark Brown
2017-02-01 12:52     ` Takashi Iwai
2017-02-01 14:59       ` Mark Brown
2017-02-01 15:32         ` Takashi Iwai
2017-02-01 17:43           ` Mark Brown
     [not found]             ` <ABFD875FF5FB574BA706497D987D48D70124DF38@RTITMBSV03.realtek.com.tw>
2017-02-04 16:11               ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1482999827-14705-1-git-send-email-bardliao@realtek.com \
    --to=bardliao@realtek.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=flove@realtek.com \
    --cc=jack.yu@realtek.com \
    --cc=lars@metafoo.de \
    --cc=lgirdwood@gmail.com \
    --cc=oder_chiou@realtek.com \
    --cc=shumingf@realtek.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.