alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Dan Murphy <dmurphy@ti.com>
To: <lgirdwood@gmail.com>, <broonie@kernel.org>, <tiwai@suse.com>,
	<robh+dt@kernel.org>
Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org,
	linux-kernel@vger.kernel.org, Dan Murphy <dmurphy@ti.com>
Subject: [PATCH 2/6] ASoC: tas2770: Add shutdown capability via a GPIO
Date: Wed, 23 Sep 2020 08:25:56 -0500	[thread overview]
Message-ID: <20200923132600.10652-2-dmurphy@ti.com> (raw)
In-Reply-To: <20200923132600.10652-1-dmurphy@ti.com>

Add the hardware shutdown mechanism to shutdown and wake up the device
via a GPIO.

Signed-off-by: Dan Murphy <dmurphy@ti.com>
---
 sound/soc/codecs/tas2770.c | 53 ++++++++++++++++++++++++++++----------
 sound/soc/codecs/tas2770.h |  1 +
 2 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/sound/soc/codecs/tas2770.c b/sound/soc/codecs/tas2770.c
index 386aaa11fa08..9f7363927c50 100644
--- a/sound/soc/codecs/tas2770.c
+++ b/sound/soc/codecs/tas2770.c
@@ -79,28 +79,42 @@ static int tas2770_set_bias_level(struct snd_soc_component *component,
 #ifdef CONFIG_PM
 static int tas2770_codec_suspend(struct snd_soc_component *component)
 {
-	int ret;
+	struct tas2770_priv *tas2770 = snd_soc_component_get_drvdata(component);
+	int ret = 0;
 
-	ret = snd_soc_component_update_bits(component, TAS2770_PWR_CTRL,
-					    TAS2770_PWR_CTRL_MASK,
-					    TAS2770_PWR_CTRL_SHUTDOWN);
-	if (ret < 0)
-		return ret;
+	if (tas2770->sdz_gpio) {
+		gpiod_set_value_cansleep(tas2770->sdz_gpio, 0);
+	} else {
+		ret = snd_soc_component_update_bits(component, TAS2770_PWR_CTRL,
+						    TAS2770_PWR_CTRL_MASK,
+						    TAS2770_PWR_CTRL_SHUTDOWN);
+		if (ret < 0)
+			return ret;
 
-	return 0;
+		ret = 0;
+	}
+
+	return ret;
 }
 
 static int tas2770_codec_resume(struct snd_soc_component *component)
 {
-	int ret;
+	struct tas2770_priv *tas2770 = snd_soc_component_get_drvdata(component);
+	int ret = 0;
 
-	ret = snd_soc_component_update_bits(component, TAS2770_PWR_CTRL,
-					    TAS2770_PWR_CTRL_MASK,
-					    TAS2770_PWR_CTRL_ACTIVE);
-	if (ret < 0)
-		return ret;
+	if (tas2770->sdz_gpio) {
+		gpiod_set_value_cansleep(tas2770->sdz_gpio, 1);
+	} else {
+		ret = snd_soc_component_update_bits(component, TAS2770_PWR_CTRL,
+						    TAS2770_PWR_CTRL_MASK,
+						    TAS2770_PWR_CTRL_ACTIVE);
+		if (ret < 0)
+			return ret;
 
-	return 0;
+		ret = 0;
+	}
+
+	return ret;
 }
 #else
 #define tas2770_codec_suspend NULL
@@ -498,6 +512,9 @@ static int tas2770_codec_probe(struct snd_soc_component *component)
 
 	tas2770->component = component;
 
+	if (tas2770->sdz_gpio)
+		gpiod_set_value_cansleep(tas2770->sdz_gpio, 1);
+
 	tas2770_reset(tas2770);
 
 	return 0;
@@ -650,6 +667,14 @@ static int tas2770_parse_dt(struct device *dev, struct tas2770_priv *tas2770)
 		tas2770->v_sense_slot = 2;
 	}
 
+	tas2770->sdz_gpio = devm_gpiod_get_optional(dev, "shutdown", GPIOD_OUT_HIGH);
+	if (IS_ERR(tas2770->sdz_gpio)) {
+		if (PTR_ERR(tas2770->sdz_gpio) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+
+		tas2770->sdz_gpio = NULL;
+	}
+
 	return 0;
 }
 
diff --git a/sound/soc/codecs/tas2770.h b/sound/soc/codecs/tas2770.h
index 07e3556fc702..b3fc4a487033 100644
--- a/sound/soc/codecs/tas2770.h
+++ b/sound/soc/codecs/tas2770.h
@@ -134,6 +134,7 @@ struct tas2770_priv {
 	int power_state;
 	int asi_format;
 	struct gpio_desc *reset_gpio;
+	struct gpio_desc *sdz_gpio;
 	int sampling_rate;
 	int channel_size;
 	int slot_width;
-- 
2.28.0


  reply	other threads:[~2020-09-23 13:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-23 13:25 [PATCH 1/6] dt-bindings: tas2770: Add shutdown gpio property Dan Murphy
2020-09-23 13:25 ` Dan Murphy [this message]
2020-09-23 13:25 ` [PATCH 3/6] ASoC: tas2770: Set regcache when shutting down and waking device Dan Murphy
2020-09-23 13:25 ` [PATCH 4/6] dt-bindings: tas2770: Remove ti,asi-format property Dan Murphy
2020-09-23 15:51   ` Mark Brown
2020-09-23 16:11     ` Dan Murphy
2020-09-23 13:25 ` [PATCH 5/6] ASoC: tas2770: Remove ti,asi-format code Dan Murphy
2020-09-23 13:26 ` [PATCH 6/6] ASoC: tas2770: Remove unused variables Dan Murphy
2020-09-23 19:00 ` [PATCH 1/6] dt-bindings: tas2770: Add shutdown gpio property 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=20200923132600.10652-2-dmurphy@ti.com \
    --to=dmurphy@ti.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=tiwai@suse.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).