From: Jonathan Cameron <jic23@kernel.org>
To: Stephan Gerhold <stephan@gerhold.net>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Rob Herring <robh+dt@kernel.org>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
"H . Nikolaus Schaller" <hns@goldelico.com>,
Linus Walleij <linus.walleij@linaro.org>
Subject: Re: [PATCH 4/4] iio: gyro: bmg160: Add rudimentary regulator support
Date: Sat, 5 Dec 2020 15:38:48 +0000 [thread overview]
Message-ID: <20201205153848.697c77a5@archlinux> (raw)
In-Reply-To: <20201202093322.77114-4-stephan@gerhold.net>
On Wed, 2 Dec 2020 10:33:22 +0100
Stephan Gerhold <stephan@gerhold.net> wrote:
> BMG160 needs VDD and VDDIO regulators that might need to be explicitly
> enabled. Add some rudimentary support to obtain and enable these
> regulators during probe() and disable them during remove()
> or on the error path.
>
> Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Hi Stephan,
This one is a bit tricky due to the extensive use of devm_ managed
cleanup. Normally I'd be very fussy about ensuring remove order
is precise reverse of probe, but in this driver it isn't quite
already, due to that chip_init being before the interrupt allocation.
Having said that I'd rather not make it worse. Would you mind
using automated clean up of the regulator_enable as well via
devm_add_action_or_reset() call?
As a side note, should we not have more cleanup of chip_init()
in error paths, specifically putting the device into it's suspended
mode? Obviously nothing to do with your patch...
Thanks,
Jonathan
> ---
> drivers/iio/gyro/bmg160_core.c | 38 +++++++++++++++++++++++++++-------
> 1 file changed, 31 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/iio/gyro/bmg160_core.c b/drivers/iio/gyro/bmg160_core.c
> index 2d5015801a75..4baa4169c5a2 100644
> --- a/drivers/iio/gyro/bmg160_core.c
> +++ b/drivers/iio/gyro/bmg160_core.c
> @@ -19,6 +19,7 @@
> #include <linux/iio/trigger_consumer.h>
> #include <linux/iio/triggered_buffer.h>
> #include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
> #include "bmg160.h"
>
> #define BMG160_IRQ_NAME "bmg160_event"
> @@ -92,6 +93,7 @@
>
> struct bmg160_data {
> struct regmap *regmap;
> + struct regulator_bulk_data regulators[2];
> struct iio_trigger *dready_trig;
> struct iio_trigger *motion_trig;
> struct iio_mount_matrix orientation;
> @@ -1077,14 +1079,28 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
> data->irq = irq;
> data->regmap = regmap;
>
> + data->regulators[0].supply = "vdd";
> + data->regulators[1].supply = "vddio";
> + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->regulators),
> + data->regulators);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to get regulators\n");
> +
> ret = iio_read_mount_matrix(dev, "mount-matrix",
> &data->orientation);
> if (ret)
> return ret;
Why not put regulator get and enable together?
>
> + ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators),
> + data->regulators);
> + if (ret < 0) {
> + dev_err(dev, "Failed to enable regulators: %d\n", ret);
> + return ret;
> + }
> +
If you were to use devm_add_action_or_reset() and a trivial wrapper
the disable would be automated, simplifying the error handling etc.
> ret = bmg160_chip_init(data);
> if (ret < 0)
> - return ret;
> + goto err_regulator_disable;
>
> mutex_init(&data->mutex);
>
> @@ -1107,28 +1123,32 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
> BMG160_IRQ_NAME,
> indio_dev);
> if (ret)
> - return ret;
> + goto err_regulator_disable;
>
> data->dready_trig = devm_iio_trigger_alloc(dev,
> "%s-dev%d",
> indio_dev->name,
> indio_dev->id);
> - if (!data->dready_trig)
> - return -ENOMEM;
> + if (!data->dready_trig) {
> + ret = -ENOMEM;
> + goto err_regulator_disable;
> + }
>
> data->motion_trig = devm_iio_trigger_alloc(dev,
> "%s-any-motion-dev%d",
> indio_dev->name,
> indio_dev->id);
> - if (!data->motion_trig)
> - return -ENOMEM;
> + if (!data->motion_trig) {
> + ret = -ENOMEM;
> + goto err_regulator_disable;
> + }
>
> data->dready_trig->dev.parent = dev;
> data->dready_trig->ops = &bmg160_trigger_ops;
> iio_trigger_set_drvdata(data->dready_trig, indio_dev);
> ret = iio_trigger_register(data->dready_trig);
> if (ret)
> - return ret;
> + goto err_regulator_disable;
>
> data->motion_trig->dev.parent = dev;
> data->motion_trig->ops = &bmg160_trigger_ops;
> @@ -1174,6 +1194,8 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
> iio_trigger_unregister(data->dready_trig);
> if (data->motion_trig)
> iio_trigger_unregister(data->motion_trig);
> +err_regulator_disable:
> + regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
>
> return ret;
> }
> @@ -1200,6 +1222,8 @@ void bmg160_core_remove(struct device *dev)
> mutex_lock(&data->mutex);
> bmg160_set_mode(data, BMG160_MODE_DEEP_SUSPEND);
> mutex_unlock(&data->mutex);
> +
> + regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
> }
> EXPORT_SYMBOL_GPL(bmg160_core_remove);
>
next prev parent reply other threads:[~2020-12-05 18:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-02 9:33 [PATCH 1/4] dt-bindings: iio: magnetometer: bmc150: Document regulator supplies Stephan Gerhold
2020-12-02 9:33 ` [PATCH 2/4] iio: magnetometer: bmc150: Add rudimentary regulator support Stephan Gerhold
2020-12-02 12:01 ` Linus Walleij
2021-01-06 10:33 ` Stephan Gerhold
2021-01-09 14:21 ` Jonathan Cameron
2020-12-02 9:33 ` [PATCH 3/4] dt-bindings: iio: gyroscope: bmg160: Document regulator supplies Stephan Gerhold
2020-12-02 12:02 ` Linus Walleij
2020-12-09 19:45 ` Rob Herring
2020-12-02 9:33 ` [PATCH 4/4] iio: gyro: bmg160: Add rudimentary regulator support Stephan Gerhold
2020-12-02 12:03 ` Linus Walleij
2020-12-05 15:38 ` Jonathan Cameron [this message]
2020-12-11 18:36 ` Stephan Gerhold
2020-12-02 12:00 ` [PATCH 1/4] dt-bindings: iio: magnetometer: bmc150: Document regulator supplies Linus Walleij
2020-12-09 19:40 ` Rob Herring
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=20201205153848.697c77a5@archlinux \
--to=jic23@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=hns@goldelico.com \
--cc=lars@metafoo.de \
--cc=linus.walleij@linaro.org \
--cc=linux-iio@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
--cc=robh+dt@kernel.org \
--cc=stephan@gerhold.net \
/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).