[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250215-apple-codec-changes-v1-16-723569b21b19@gmail.com>
Date: Sat, 15 Feb 2025 10:02:49 +1000
From: James Calligeros <jcalligeros99@...il.com>
To: Liam Girdwood <lgirdwood@...il.com>, Mark Brown <broonie@...nel.org>,
Jaroslav Kysela <perex@...ex.cz>, Takashi Iwai <tiwai@...e.com>,
Shenghao Ding <shenghao-ding@...com>, Kevin Lu <kevin-lu@...com>,
Baojun Xu <baojun.xu@...com>, Dan Murphy <dmurphy@...com>,
Rob Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>, Shi Fu <shifu0704@...ndersoft.com>
Cc: Alyssa Rosenzweig <alyssa@...enzweig.io>,
Martin PoviĊĦer <povik+lin@...ebit.org>,
Hector Martin <marcan@...can.st>, linux-sound@...r.kernel.org,
linux-kernel@...r.kernel.org, devicetree@...r.kernel.org,
asahi@...ts.linux.dev, James Calligeros <jcalligeros99@...il.com>
Subject: [PATCH 16/27] ASoC: tas2764: Add SDZ regulator
From: Hector Martin <marcan@...can.st>
Multiple amps can be connected to the same SDZ GPIO. Using raw GPIOs for
this breaks, as there is no concept of refcounting/sharing. In order to
model these platforms, introduce support for an SDZ "regulator". This
allows us to represent the SDZ GPIO as a simple regulator-fixed, and
then the regulator core takes care of refcounting so that all codecs are
only powered down once all the driver instances are in the suspend
state.
Signed-off-by: Hector Martin <marcan@...can.st>
Signed-off-by: James Calligeros <jcalligeros99@...il.com>
---
sound/soc/codecs/tas2764.c | 39 ++++++++++++++++++++-----
1 file changed, 32 insertions(+), 7 deletions(-)
diff --git a/sound/soc/codecs/tas2764.c b/sound/soc/codecs/tas2764.c
index 2baa7fbb5fdeaf50cfb76a7eddf752cae2511329..d1eb8ee30415e335adf8e14d14aaa207c949ddcb 100644
--- a/sound/soc/codecs/tas2764.c
+++ b/sound/soc/codecs/tas2764.c
@@ -34,6 +34,7 @@ struct tas2764_priv {
struct snd_soc_component *component;
struct gpio_desc *reset_gpio;
struct gpio_desc *sdz_gpio;
+ struct regulator *sdz_reg;
struct regmap *regmap;
struct device *dev;
int irq;
@@ -153,6 +154,8 @@ static int tas2764_codec_suspend(struct snd_soc_component *component)
if (tas2764->sdz_gpio)
gpiod_set_value_cansleep(tas2764->sdz_gpio, 0);
+ regulator_disable(tas2764->sdz_reg);
+
regcache_cache_only(tas2764->regmap, true);
regcache_mark_dirty(tas2764->regmap);
@@ -164,19 +167,26 @@ static int tas2764_codec_resume(struct snd_soc_component *component)
struct tas2764_priv *tas2764 = snd_soc_component_get_drvdata(component);
int ret;
+ ret = regulator_enable(tas2764->sdz_reg);
+
+ if (ret) {
+ dev_err(tas2764->dev, "Failed to enable regulator\n");
+ return ret;
+ }
+
if (tas2764->sdz_gpio) {
gpiod_set_value_cansleep(tas2764->sdz_gpio, 1);
- usleep_range(1000, 2000);
}
- ret = tas2764_update_pwr_ctrl(tas2764);
+ usleep_range(1000, 2000);
+ regcache_cache_only(tas2764->regmap, false);
+
+ ret = regcache_sync(tas2764->regmap);
if (ret < 0)
return ret;
- regcache_cache_only(tas2764->regmap, false);
-
- return regcache_sync(tas2764->regmap);
+ return tas2764_update_pwr_ctrl(tas2764);
}
#else
#define tas2764_codec_suspend NULL
@@ -209,7 +219,7 @@ static const struct snd_soc_dapm_widget tas2764_dapm_widgets[] = {
SND_SOC_DAPM_DAC("DAC", NULL, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_OUTPUT("OUT"),
SND_SOC_DAPM_SIGGEN("VMON"),
- SND_SOC_DAPM_SIGGEN("IMON")
+ SND_SOC_DAPM_SIGGEN("IMON"),
};
static const struct snd_soc_dapm_route tas2764_audio_map[] = {
@@ -642,11 +652,18 @@ static int tas2764_codec_probe(struct snd_soc_component *component)
tas2764->component = component;
+ ret = regulator_enable(tas2764->sdz_reg);
+ if (ret != 0) {
+ dev_err(tas2764->dev, "Failed to enable regulator: %d\n", ret);
+ return ret;
+ }
+
if (tas2764->sdz_gpio) {
gpiod_set_value_cansleep(tas2764->sdz_gpio, 1);
- usleep_range(1000, 2000);
}
+ usleep_range(1000, 2000);
+
tas2764_reset(tas2764);
regmap_reinit_cache(tas2764->regmap, &tas2764_i2c_regmap);
@@ -721,6 +738,9 @@ static int tas2764_codec_probe(struct snd_soc_component *component)
static void tas2764_codec_remove(struct snd_soc_component *component)
{
+ struct tas2764_priv *tas2764 = snd_soc_component_get_drvdata(component);
+
+ regulator_disable(tas2764->sdz_reg);
sysfs_remove_groups(&component->dev->kobj, tas2764_sysfs_groups);
}
@@ -823,6 +843,11 @@ static int tas2764_parse_dt(struct device *dev, struct tas2764_priv *tas2764)
{
int ret = 0;
+ tas2764->sdz_reg = devm_regulator_get(dev, "SDZ");
+ if (IS_ERR(tas2764->sdz_reg))
+ return dev_err_probe(dev, PTR_ERR(tas2764->sdz_reg),
+ "Failed to get SDZ supply\n");
+
tas2764->reset_gpio = devm_gpiod_get_optional(tas2764->dev, "reset",
GPIOD_OUT_HIGH);
if (IS_ERR(tas2764->reset_gpio)) {
--
2.48.1
Powered by blists - more mailing lists