Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4692495ybi; Tue, 11 Jun 2019 10:50:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEBZCPHC6HrggMj+1VkdvQhiqnbQlQSOVh39222QEasaz7WTygykQBL3BxpNjDuEPd+gJN X-Received: by 2002:a62:2b81:: with SMTP id r123mr40449715pfr.108.1560275413414; Tue, 11 Jun 2019 10:50:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560275413; cv=none; d=google.com; s=arc-20160816; b=of5BBivUr3FbxZiBaRtFDF/FbhrnEVutqVbp7wvrNIvESbTtLuzDG1o1vdInryaFNt s1V8N9YBeJiUb68Wzfj4w+X2YOJeNf0JyZR7ZWJaYD6eFnUxEGOaTVk+gBaTlS9vu/zy Zgi1OMvMphSHLsfhrfQk7UBIpknc4+Ct7xfXuJtprkTDZShYSuVRGFMavQSyZIJgsY+T sp79gLHUpZAlHQ3Ey67kENwdEvhyEvcEe1mcL2YdTAVz9Ph/yELZJfvc9V2bYJ2Mc5TE YLrpzzid+o5TX8izz8yyIvT6Cgkhu1jJv0pZf5tv/JCyoke4nyNUdg0ldKTVJg3G60wn lxNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from; bh=y7pcY+IefuRCyQs2Izu3RT+2bAdLAVgU/B+YSCMjMb8=; b=pgyk04Lsfxx5idGidpxpgaiJVhWUcy1auRV2L1VD+rI8yoSEAnSQJALy57vClorxd6 ATzHDeBuN4qENuxDmRPYq4V6iyKED8dEZTrr/ZSHm1O/atTMkCdmWsa+njQlF60ch3Ly FeDPXcC2jxBJMXCEKQA0UrIEztPJujMn2nLRm0cI8UMMxbY5fe/4WjdFY1Jqn3B3T9Tj fdLxv6+WcgqUc1bM8fK0uQgLuWKNX42pHi+Wu4FhFb+Weyl1pz4Vs5DMSZNr/qyK8X8A i5H49+wnL2nARVUH+L2mQsr7vBni4ESXP/hnIxSHXuiMIGwtm/ukHto2KRT56TcS19tY 6bmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u38si12955199pgm.538.2019.06.11.10.49.58; Tue, 11 Jun 2019 10:50:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406527AbfFKRtt (ORCPT + 99 others); Tue, 11 Jun 2019 13:49:49 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:36904 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405488AbfFKRts (ORCPT ); Tue, 11 Jun 2019 13:49:48 -0400 Received: from [167.98.27.226] (helo=ct-lt-1124.office.codethink.co.uk) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1haktf-0001PN-FW; Tue, 11 Jun 2019 18:49:23 +0100 From: Thomas Preston To: Liam Girdwood , Mark Brown , Rob Herring , Mark Rutland , Jaroslav Kysela , Takashi Iwai , Charles Keepax , Jerome Brunet , Srinivas Kandagatla , Marco Felsch , Paul Cercueil , Kirill Marinushkin , Cheng-Yi Chiang , Kuninori Morimoto , Vinod Koul , Annaliese McDermond , Thomas Preston , 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 Message-Id: <20190611174909.12162-4-thomas.preston@codethink.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190611174909.12162-1-thomas.preston@codethink.co.uk> References: <20190611174909.12162-1-thomas.preston@codethink.co.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Patrick Glaser Cc: Rob Duncan Cc: Nate Case --- 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