From: Thomas Preston <thomas.preston@codethink.co.uk>
To: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Charles Keepax <ckeepax@opensource.cirrus.com>,
Jerome Brunet <jbrunet@baylibre.com>,
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
Marco Felsch <m.felsch@pengutronix.de>,
Paul Cercueil <paul@crapouillou.net>,
Kirill Marinushkin <kmarinushkin@birdec.tech>,
Cheng-Yi Chiang <cychiang@chromium.org>,
Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
Vinod Koul <vkoul@kernel.org>,
Annaliese McDermond <nh6z@nh6z.net>,
Thomas Preston <thomas.preston@codethink.co.uk>,
alsa-devel@alsa-project.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v1 3/4] ASoC: tda7802: Add enable device attribute
Date: Tue, 11 Jun 2019 18:49:08 +0100 [thread overview]
Message-ID: <20190611174909.12162-4-thomas.preston@codethink.co.uk> (raw)
In-Reply-To: <20190611174909.12162-1-thomas.preston@codethink.co.uk>
Add a device attribute to control the enable regulator. Write 1 to
enable, 0 to disable (ref-count minus one), or -1 to force disable the
physical pin.
To disable a set of amplifiers wired to the same enable gpio, each
device must be disabled. For example:
echo 0 > /sys/devices/.../device:00/enable
echo 0 > /sys/devices/.../device:01/enable
In an emergency, we can force disable from any device:
echo -1 > /sys/devices/.../device:00/enable
Signed-off-by: Thomas Preston <thomas.preston@codethink.co.uk>
Cc: Patrick Glaser <pglaser@tesla.com>
Cc: Rob Duncan <rduncan@tesla.com>
Cc: Nate Case <ncase@tesla.com>
---
sound/soc/codecs/tda7802.c | 65 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 64 insertions(+), 1 deletion(-)
diff --git a/sound/soc/codecs/tda7802.c b/sound/soc/codecs/tda7802.c
index 38ca52de85f0..62aae011d9f1 100644
--- a/sound/soc/codecs/tda7802.c
+++ b/sound/soc/codecs/tda7802.c
@@ -458,6 +458,42 @@ static struct snd_soc_dai_driver tda7802_dai_driver = {
.ops = &tda7802_dai_ops,
};
+static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct tda7802_priv *tda7802 = dev_get_drvdata(dev);
+ int enabled = regulator_is_enabled(tda7802->enable_reg) ? 1 : 0;
+
+ return scnprintf(buf, PAGE_SIZE, "%d\n", enabled);
+}
+
+static ssize_t enable_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tda7802_priv *tda7802 = dev_get_drvdata(dev);
+ int err;
+
+ if (sysfs_streq(buf, "1")) {
+ err = regulator_enable(tda7802->enable_reg);
+ if (err < 0)
+ dev_err(dev, "Could not enable (sysfs)\n");
+ } else if (sysfs_streq(buf, "0")) {
+ err = regulator_disable(tda7802->enable_reg);
+ if (err < 0)
+ dev_err(dev, "Could not disable (sysfs)\n");
+ } else if (sysfs_streq(buf, "-1")) {
+ err = regulator_force_disable(tda7802->enable_reg);
+ if (err < 0)
+ dev_err(dev, "Could not force disable (sysfs)\n");
+ } else {
+ return -EINVAL;
+ }
+
+ return count;
+}
+
+static DEVICE_ATTR_RW(enable);
+
/* read device tree or ACPI properties from device */
static int tda7802_read_properties(struct tda7802_priv *tda7802)
{
@@ -493,7 +529,34 @@ static int tda7802_read_properties(struct tda7802_priv *tda7802)
return err;
}
-static const struct snd_soc_component_driver tda7802_component_driver;
+static int tda7802_probe(struct snd_soc_component *component)
+{
+ struct tda7802_priv *tda7802 = snd_soc_component_get_drvdata(component);
+ struct device *dev = &tda7802->i2c->dev;
+ int err;
+
+ dev_dbg(dev, "%s\n", __func__);
+
+ err = device_create_file(dev, &dev_attr_enable);
+ if (err < 0) {
+ dev_err(dev, "Could not create enable attr\n");
+ return err;
+ }
+
+ return err;
+}
+
+static void tda7802_remove(struct snd_soc_component *component)
+{
+ struct tda7802_priv *tda7802 = snd_soc_component_get_drvdata(component);
+
+ device_remove_file(&tda7802->i2c->dev, &dev_attr_enable);
+}
+
+static const struct snd_soc_component_driver tda7802_component_driver = {
+ .probe = tda7802_probe,
+ .remove = tda7802_remove,
+};
static int tda7802_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
--
2.11.0
next prev parent reply other threads:[~2019-06-11 17:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-11 17:49 [PATCH v1 0/4] ASoC: Codecs: Add TDA7802 codec Thomas Preston
2019-06-11 17:49 ` [PATCH v1 1/4] dt-bindings: ASoC: Add TDA7802 amplifier Thomas Preston
2019-06-12 8:10 ` Charles Keepax
2019-06-11 17:49 ` [PATCH v1 2/4] ASoC: Add codec driver for ST TDA7802 Thomas Preston
2019-06-13 18:34 ` Mark Brown
2019-06-14 21:17 ` Kirill Marinushkin
2019-06-11 17:49 ` Thomas Preston [this message]
2019-06-12 17:14 ` [PATCH v1 3/4] ASoC: tda7802: Add enable device attribute Cezary Rojewski
2019-06-13 18:14 ` Mark Brown
2019-06-11 17:49 ` [PATCH v1 4/4] ASoC: tda7802: Add speaker-test sysfs Thomas Preston
2019-06-12 17:56 ` Cezary Rojewski
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=20190611174909.12162-4-thomas.preston@codethink.co.uk \
--to=thomas.preston@codethink.co.uk \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=ckeepax@opensource.cirrus.com \
--cc=cychiang@chromium.org \
--cc=devicetree@vger.kernel.org \
--cc=jbrunet@baylibre.com \
--cc=kmarinushkin@birdec.tech \
--cc=kuninori.morimoto.gx@renesas.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=m.felsch@pengutronix.de \
--cc=mark.rutland@arm.com \
--cc=nh6z@nh6z.net \
--cc=paul@crapouillou.net \
--cc=perex@perex.cz \
--cc=robh+dt@kernel.org \
--cc=srinivas.kandagatla@linaro.org \
--cc=tiwai@suse.com \
--cc=vkoul@kernel.org \
/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).