From: Linus Walleij <linus.walleij@linaro.org>
To: Ismail Kose <Ismail.Kose@maximintegrated.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald <pmeerw@pmeerw.net>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
William Breathitt Gray <vilhelm.gray@gmail.com>,
Jean-Francois Dagenais <jeff.dagenais@gmail.com>,
Fabrice Gasnier <fabrice.gasnier@st.com>,
gwenhael.goavec-merou@trabucayre.com,
Peter Rosin <peda@axentia.se>,
maxime.roussinbelanger@gmail.com, ihkose@gmail.com,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] iio: dac: DS4424: add Maxim DS4422/DS4424 DAC driver support
Date: Thu, 29 Jun 2017 14:47:06 +0200 [thread overview]
Message-ID: <CACRpkdbNz9HSBWjQrntMpJDOaaEYKaNgrm6=qzdhiH8rfv+F1g@mail.gmail.com> (raw)
In-Reply-To: <20170623230404.2283-1-Ismail.Kose@maximintegrated.com>
On Sat, Jun 24, 2017 at 1:04 AM, Ismail Kose
<Ismail.Kose@maximintegrated.com> wrote:
> +Optional properties:
> + - vcc-supply: Power supply us optional. If not defined, driver will ignore it.
*is* optional I guess.
No need to mention the driver.
> +#include <linux/regulator/consumer.h>
(...)
> + struct regulator *vcc_reg;
> + const char *vcc_reg_name;
> + bool regulator_state;
Why do you do this funky stuff?
> +int ds4424_regulator_onoff(struct iio_dev *indio_dev, bool enable)
> +{
> + struct ds4424_data *data = iio_priv(indio_dev);
> + int ret = 0;
> +
> + if (data->vcc_reg == NULL)
> + return ret;
This should not happen.
You get dummy regulators or stubs if the regulator is not there
and that works just fine.
> +
> + if (data->regulator_state == PWR_OFF && enable == PWR_ON) {
> + ret = regulator_enable(data->vcc_reg);
> + if (ret) {
> + pr_err("%s - enable vcc_reg failed, ret=%d\n",
> + __func__, ret);
> + goto done;
> + }
> + } else if (data->regulator_state == PWR_ON && enable == PWR_OFF) {
> + ret = regulator_disable(data->vcc_reg);
> + if (ret) {
> + pr_err("%s - disable vcc_reg failed, ret=%d\n",
> + __func__, ret);
> + goto done;
> + }
> + }
> +
> + data->regulator_state = enable;
> +done:
> + return ret;
> +}
The regulator already has a state and knows if it is on or
off. Why do you insist on having a "regulator state" reinventing
the wheel in the driver?
> + ret = of_property_read_string(node, "vcc-supply", &data->vcc_reg_name);
> + if (ret < 0) {
> + pr_info("DAC vcc-supply is not available in dts\n");
> + data->vcc_reg_name = NULL;
> + }
Don't do this. Just try to get the regulator by name and do not try
to be clever about this, the regulator core will give you a dummy supply
if the regulator is not there.
> + if (data->vcc_reg_name) {
Just skip this check.
> + data->vcc_reg = devm_regulator_get(&client->dev,
> + data->vcc_reg_name);
Just
data->vcc_reg = devm_regulator_get(&client->dev, "vcc");
> + if (IS_ERR(data->vcc_reg)) {
> + ret = PTR_ERR(data->vcc_reg);
> + dev_err(&client->dev,
> + "Failed to get vcc_reg regulator: %d\n", ret);
> + return ret;
> + }
And keep this.
You will get a dummy or stub working just fine if the regulator is not there.
> + ret = ds4424_regulator_onoff(indio_dev, PWR_ON);
> + if (ret < 0) {
> + pr_err("Unable to turn on the regulator. %s:%d, ret: %d\n",
> + __func__, __LINE__, ret);
> + return ret;
> + }
I don't think this helper is even needed. Just enable it here.
Disable it on the other paths.
Problem solved.
Yours,
Linus Walleij
next prev parent reply other threads:[~2017-06-29 12:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-23 23:04 [PATCH] iio: dac: DS4424: add Maxim DS4422/DS4424 DAC driver support Ismail Kose
2017-06-24 17:37 ` Jonathan Cameron
2017-06-25 21:33 ` Peter Meerwald-Stadler
2017-06-26 19:56 ` Rob Herring
2017-06-29 12:47 ` Linus Walleij [this message]
2017-09-18 22:09 ` [PATCH v3] iio: dac: ds4422/ds4424 dac driver Ismail Kose
2017-09-19 4:48 ` Peter Meerwald-Stadler
2017-09-19 6:24 ` Ismail Kose
2017-09-19 7:23 ` [PATCH v5] " Ismail Kose
2017-09-21 23:26 ` Rob Herring
2017-09-22 15:09 ` Jonathan Cameron
2017-09-19 7:06 ` [PATCH v4] " Ismail Kose
2017-09-19 13:34 ` [PATCH v3] " kbuild test robot
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='CACRpkdbNz9HSBWjQrntMpJDOaaEYKaNgrm6=qzdhiH8rfv+F1g@mail.gmail.com' \
--to=linus.walleij@linaro.org \
--cc=Ismail.Kose@maximintegrated.com \
--cc=devicetree@vger.kernel.org \
--cc=fabrice.gasnier@st.com \
--cc=gwenhael.goavec-merou@trabucayre.com \
--cc=ihkose@gmail.com \
--cc=jeff.dagenais@gmail.com \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maxime.roussinbelanger@gmail.com \
--cc=peda@axentia.se \
--cc=pmeerw@pmeerw.net \
--cc=robh+dt@kernel.org \
--cc=vilhelm.gray@gmail.com \
/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).