All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Knecht <vincent.knecht@mailoo.org>
To: Mark Brown <broonie@kernel.org>
Cc: phone-devel@vger.kernel.org,
	~postmarketos/upstreaming@lists.sr.ht,
	Vincent Knecht <vincent.knecht@mailoo.org>,
	Stephan Gerhold <stephan@gerhold.net>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Rob Herring <robh+dt@kernel.org>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	alsa-devel@alsa-project.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v1 4/4] ASoC: codecs: tfa989x: Add support for optional vddd-supply
Date: Fri, 28 May 2021 12:51:01 +0200	[thread overview]
Message-ID: <20210528105101.508254-4-vincent.knecht@mailoo.org> (raw)
In-Reply-To: <20210528105101.508254-1-vincent.knecht@mailoo.org>

Allow specifying Vddd regulator/supply to be enabled on I2C probing.

Signed-off-by: Vincent Knecht <vincent.knecht@mailoo.org>
---
 sound/soc/codecs/tfa989x.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/sound/soc/codecs/tfa989x.c b/sound/soc/codecs/tfa989x.c
index 6d94865c534b..643b45188b6f 100644
--- a/sound/soc/codecs/tfa989x.c
+++ b/sound/soc/codecs/tfa989x.c
@@ -10,6 +10,7 @@
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 #include <sound/soc.h>
 
 #define TFA989X_STATUSREG		0x00
@@ -51,6 +52,10 @@ struct tfa989x_rev {
 	int (*init)(struct regmap *regmap);
 };
 
+struct tfa989x {
+	struct regulator *vddd_supply;
+};
+
 static bool tfa989x_writeable_reg(struct device *dev, unsigned int reg)
 {
 	return reg > TFA989X_REVISIONNUMBER;
@@ -242,10 +247,18 @@ static int tfa989x_dsp_bypass(struct regmap *regmap)
 				 BIT(TFA989X_SYS_CTRL_AMPC));
 }
 
+static void tfa989x_regulator_disable(void *data)
+{
+	struct tfa989x *tfa989x = data;
+
+	regulator_disable(tfa989x->vddd_supply);
+}
+
 static int tfa989x_i2c_probe(struct i2c_client *i2c)
 {
 	struct device *dev = &i2c->dev;
 	const struct tfa989x_rev *rev;
+	struct tfa989x *tfa989x;
 	struct regmap *regmap;
 	unsigned int val;
 	int ret;
@@ -256,10 +269,31 @@ static int tfa989x_i2c_probe(struct i2c_client *i2c)
 		return -ENODEV;
 	}
 
+	tfa989x = devm_kzalloc(dev, sizeof(*tfa989x), GFP_KERNEL);
+	if (!tfa989x)
+		return -ENOMEM;
+
+	i2c_set_clientdata(i2c, tfa989x);
+
+	tfa989x->vddd_supply = devm_regulator_get(dev, "vddd");
+	if (IS_ERR(tfa989x->vddd_supply))
+		return dev_err_probe(dev, PTR_ERR(tfa989x->vddd_supply),
+				     "Failed to get vddd regulator\n");
+
 	regmap = devm_regmap_init_i2c(i2c, &tfa989x_regmap);
 	if (IS_ERR(regmap))
 		return PTR_ERR(regmap);
 
+	ret = regulator_enable(tfa989x->vddd_supply);
+	if (ret) {
+		dev_err(dev, "Failed to enable vddd regulator: %d\n", ret);
+		return ret;
+	}
+
+	ret = devm_add_action_or_reset(dev, tfa989x_regulator_disable, tfa989x);
+	if (ret)
+		return ret;
+
 	/* Bypass regcache for reset and init sequence */
 	regcache_cache_bypass(regmap, true);
 
-- 
2.31.1




WARNING: multiple messages have this Message-ID (diff)
From: Vincent Knecht <vincent.knecht@mailoo.org>
To: Mark Brown <broonie@kernel.org>
Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org,
	Stephan Gerhold <stephan@gerhold.net>,
	linux-kernel@vger.kernel.org, Takashi Iwai <tiwai@suse.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Rob Herring <robh+dt@kernel.org>,
	~postmarketos/upstreaming@lists.sr.ht,
	phone-devel@vger.kernel.org,
	Vincent Knecht <vincent.knecht@mailoo.org>
Subject: [PATCH v1 4/4] ASoC: codecs: tfa989x: Add support for optional vddd-supply
Date: Fri, 28 May 2021 12:51:01 +0200	[thread overview]
Message-ID: <20210528105101.508254-4-vincent.knecht@mailoo.org> (raw)
In-Reply-To: <20210528105101.508254-1-vincent.knecht@mailoo.org>

Allow specifying Vddd regulator/supply to be enabled on I2C probing.

Signed-off-by: Vincent Knecht <vincent.knecht@mailoo.org>
---
 sound/soc/codecs/tfa989x.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/sound/soc/codecs/tfa989x.c b/sound/soc/codecs/tfa989x.c
index 6d94865c534b..643b45188b6f 100644
--- a/sound/soc/codecs/tfa989x.c
+++ b/sound/soc/codecs/tfa989x.c
@@ -10,6 +10,7 @@
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 #include <sound/soc.h>
 
 #define TFA989X_STATUSREG		0x00
@@ -51,6 +52,10 @@ struct tfa989x_rev {
 	int (*init)(struct regmap *regmap);
 };
 
+struct tfa989x {
+	struct regulator *vddd_supply;
+};
+
 static bool tfa989x_writeable_reg(struct device *dev, unsigned int reg)
 {
 	return reg > TFA989X_REVISIONNUMBER;
@@ -242,10 +247,18 @@ static int tfa989x_dsp_bypass(struct regmap *regmap)
 				 BIT(TFA989X_SYS_CTRL_AMPC));
 }
 
+static void tfa989x_regulator_disable(void *data)
+{
+	struct tfa989x *tfa989x = data;
+
+	regulator_disable(tfa989x->vddd_supply);
+}
+
 static int tfa989x_i2c_probe(struct i2c_client *i2c)
 {
 	struct device *dev = &i2c->dev;
 	const struct tfa989x_rev *rev;
+	struct tfa989x *tfa989x;
 	struct regmap *regmap;
 	unsigned int val;
 	int ret;
@@ -256,10 +269,31 @@ static int tfa989x_i2c_probe(struct i2c_client *i2c)
 		return -ENODEV;
 	}
 
+	tfa989x = devm_kzalloc(dev, sizeof(*tfa989x), GFP_KERNEL);
+	if (!tfa989x)
+		return -ENOMEM;
+
+	i2c_set_clientdata(i2c, tfa989x);
+
+	tfa989x->vddd_supply = devm_regulator_get(dev, "vddd");
+	if (IS_ERR(tfa989x->vddd_supply))
+		return dev_err_probe(dev, PTR_ERR(tfa989x->vddd_supply),
+				     "Failed to get vddd regulator\n");
+
 	regmap = devm_regmap_init_i2c(i2c, &tfa989x_regmap);
 	if (IS_ERR(regmap))
 		return PTR_ERR(regmap);
 
+	ret = regulator_enable(tfa989x->vddd_supply);
+	if (ret) {
+		dev_err(dev, "Failed to enable vddd regulator: %d\n", ret);
+		return ret;
+	}
+
+	ret = devm_add_action_or_reset(dev, tfa989x_regulator_disable, tfa989x);
+	if (ret)
+		return ret;
+
 	/* Bypass regcache for reset and init sequence */
 	regcache_cache_bypass(regmap, true);
 
-- 
2.31.1




  parent reply	other threads:[~2021-05-28 10:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-28 10:50 [PATCH v1 1/4] ASoC: dt-bindings: nxp,tfa989x: Add tfa9897 support Vincent Knecht
2021-05-28 10:50 ` Vincent Knecht
2021-05-28 10:50 ` [PATCH v1 2/4] ASoC: codecs: tfa989x: Add support for tfa9897 Vincent Knecht
2021-05-28 10:50   ` Vincent Knecht
2021-05-28 11:53   ` Stephan Gerhold
2021-05-28 11:53     ` Stephan Gerhold
2021-05-28 10:51 ` [PATCH v1 3/4] ASoC: dt-bindings: nxp,tfa989x: Add vddd-supply property Vincent Knecht
2021-05-28 10:51   ` [PATCH v1 3/4] ASoC: dt-bindings: nxp, tfa989x: " Vincent Knecht
2021-05-28 10:51 ` Vincent Knecht [this message]
2021-05-28 10:51   ` [PATCH v1 4/4] ASoC: codecs: tfa989x: Add support for optional vddd-supply Vincent Knecht
2021-05-28 11:54   ` Stephan Gerhold
2021-05-28 11:54     ` Stephan Gerhold
2021-05-28 11:40 ` [PATCH v1 1/4] ASoC: dt-bindings: nxp,tfa989x: Add tfa9897 support Stephan Gerhold
2021-05-28 11:40   ` Stephan Gerhold
2021-06-02 16:16 ` Mark Brown
2021-06-02 16:16   ` [PATCH v1 1/4] ASoC: dt-bindings: nxp, tfa989x: " 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=20210528105101.508254-4-vincent.knecht@mailoo.org \
    --to=vincent.knecht@mailoo.org \
    --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=perex@perex.cz \
    --cc=phone-devel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=stephan@gerhold.net \
    --cc=tiwai@suse.com \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /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.