Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5945001ybi; Wed, 12 Jun 2019 11:08:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqwtmY/4bCUBSHKHQcO1t9M5F5WrOnys7CNsg6pAERiKZdlM4T1JSQ8iSvtAS//ftwvOZwOy X-Received: by 2002:a17:902:b609:: with SMTP id b9mr4261515pls.8.1560362929796; Wed, 12 Jun 2019 11:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560362929; cv=none; d=google.com; s=arc-20160816; b=BmB8pHZeWPvKfmALKbwHS/9O3hnGmWcHcKWRUYPoSdbS+2M9BnTPxA/SQOqUyrwHjq CHkMwQRDo4Da6bfD0AYIYmEOmVpqyYW8r1HOqXmMMp5Bl0q1pdTIEXvBOf9n2PBgg+Jd Shpi3JlgbPDyEoXOd0J1yVW3YLWmwyfucESV+g1A9sUOH4/z1DSl+jcx1RtVAFenCZbU 47IC189x9eYUZYfza5PXRc0KtHUOUinKiWiMvir4s2h00IE+Ft63u5smtwfX9MxnrY/B qZ5CAG6cp7L7YhQorrGyDtPfjVNKrWOx7H6Q7M2QW5e0vh71B5UJXuy+e2sAIJXdq3uV eR7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject; bh=qYeeAzaTl5li/ns3qqd0SNV5Go8AXcKPgbvau11gU6Y=; b=or7sYl8oKzzdIlMhIs1dRi2ULH9GUPrA2KGwEvKXMugYyIIiSJ6cHbKXJQHnPYSNqG Uf/tgyV/9LylWlWfyjF9ujvL26gENp3vfpVg9d9pJbgsSTLDbnqOkOUonHbJ5fv5QstH ruNreV6oWiwFiQ/6QqyhU15A3gE0sO0RHvtBXOdMFBdQp6lCPAcTOAcRV0+1ikZSJUlN XAxtIWdupnJpH4WuWxMb2tTlGewTG3wXm3D6/uDwO9322UDwtk+fvzKwMOL3r2gxtRdV ruSSrodhWQg46qw6lRUSffGhgVMqqTsHx3Ya/0Nt6E99zlE+0lpUxCVJNNSaH55y9aoR hUdg== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n2si159098pgi.45.2019.06.12.11.08.34; Wed, 12 Jun 2019 11:08:49 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392087AbfFLRPH (ORCPT + 99 others); Wed, 12 Jun 2019 13:15:07 -0400 Received: from mga01.intel.com ([192.55.52.88]:22360 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729107AbfFLRPH (ORCPT ); Wed, 12 Jun 2019 13:15:07 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jun 2019 10:15:06 -0700 X-ExtLoop1: 1 Received: from crojewsk-mobl1.ger.corp.intel.com (HELO [10.252.15.160]) ([10.252.15.160]) by fmsmga004.fm.intel.com with ESMTP; 12 Jun 2019 10:14:58 -0700 Subject: Re: [PATCH v1 3/4] ASoC: tda7802: Add enable device attribute To: Thomas Preston , 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 , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190611174909.12162-1-thomas.preston@codethink.co.uk> <20190611174909.12162-4-thomas.preston@codethink.co.uk> From: Cezary Rojewski Message-ID: <1546f318-2b34-b42c-7aa3-a51429020bca@intel.com> Date: Wed, 12 Jun 2019 19:14:57 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190611174909.12162-4-thomas.preston@codethink.co.uk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-06-11 19:49, Thomas Preston wrote: > 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__); Function name alone ain't very informational. Is this intended? > + > + err = device_create_file(dev, &dev_attr_enable); > + if (err < 0) { > + dev_err(dev, "Could not create enable attr\n"); > + return err; > + } Regardless of outcome, you'll be returning err here. Consider leaving error message alone within if-statement. Remove redundant brackets if you decide to do so. > + > + 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) >