From: Jonathan Cameron <jic23@kernel.org>
To: Jagath Jog J <jagathjog1996@gmail.com>
Cc: dan@dlrobertson.com, andy.shevchenko@gmail.com,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/5] iio: accel: bma400: conversion to device-managed function
Date: Sun, 27 Mar 2022 17:35:51 +0100 [thread overview]
Message-ID: <20220327173551.4fdcc706@jic23-huawei> (raw)
In-Reply-To: <20220326194146.15549-3-jagathjog1996@gmail.com>
On Sun, 27 Mar 2022 01:11:43 +0530
Jagath Jog J <jagathjog1996@gmail.com> wrote:
> This is a conversion to device-managed by using devm_iio_device_register
> inside probe function, now disabling the regulator and putting bma400 to
> power down via a devm_add_action_or_reset() hook.
I would state here that previously the bma400 was not put into power down
mode in some error paths in probe where it now is, but that should cause no
harm.
>
> The dev_set_drvdata() call, bma400_remove() function and hooks in the I2C
> and SPI driver struct is removed as devm_iio_device_register function is
> used to automatically unregister on driver detach.
>
> Signed-off-by: Jagath Jog J <jagathjog1996@gmail.com>
one other minor thing inline.
Jonathan
> ---
> drivers/iio/accel/bma400.h | 2 -
> drivers/iio/accel/bma400_core.c | 77 ++++++++++++++++-----------------
> drivers/iio/accel/bma400_i2c.c | 8 ----
> drivers/iio/accel/bma400_spi.c | 8 ----
> 4 files changed, 38 insertions(+), 57 deletions(-)
>
> diff --git a/drivers/iio/accel/bma400.h b/drivers/iio/accel/bma400.h
> index 190366debdb3..c1b3dbfbd98f 100644
> --- a/drivers/iio/accel/bma400.h
> +++ b/drivers/iio/accel/bma400.h
> @@ -112,6 +112,4 @@ extern const struct regmap_config bma400_regmap_config;
>
> int bma400_probe(struct device *dev, struct regmap *regmap, const char *name);
>
> -void bma400_remove(struct device *dev);
> -
> #endif
> diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c
> index fd2647b728d3..dc273381a0a2 100644
> --- a/drivers/iio/accel/bma400_core.c
> +++ b/drivers/iio/accel/bma400_core.c
> @@ -560,6 +560,26 @@ static void bma400_init_tables(void)
> }
> }
>
> +static void bma400_regulators_disable(void *data_ptr)
> +{
> + struct bma400_data *data = data_ptr;
> +
> + regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
> +}
> +
> +static void bma400_power_disable(void *data_ptr)
> +{
> + struct bma400_data *data = data_ptr;
> + int ret;
> +
> + mutex_lock(&data->mutex);
> + ret = bma400_set_power_mode(data, POWER_MODE_SLEEP);
> + if (ret)
> + dev_warn(data->dev, "Failed to put device into sleep mode (%pe)\n",
> + ERR_PTR(ret));
Drop the check on ret out of the locked region. No reason for it to be done
under the lock so generally nice not to do so. Also matches the previous
ordering so there shouldnt' be any questions about it.
> + mutex_unlock(&data->mutex);
> +}
> +
> static int bma400_init(struct bma400_data *data)
> {
> unsigned int val;
> @@ -569,13 +589,12 @@ static int bma400_init(struct bma400_data *data)
> ret = regmap_read(data->regmap, BMA400_CHIP_ID_REG, &val);
> if (ret) {
> dev_err(data->dev, "Failed to read chip id register\n");
> - goto out;
> + return ret;
> }
>
> if (val != BMA400_ID_REG_VAL) {
> dev_err(data->dev, "Chip ID mismatch\n");
> - ret = -ENODEV;
> - goto out;
> + return -ENODEV;
> }
>
> data->regulators[BMA400_VDD_REGULATOR].supply = "vdd";
> @@ -589,27 +608,31 @@ static int bma400_init(struct bma400_data *data)
> "Failed to get regulators: %d\n",
> ret);
>
> - goto out;
> + return ret;
> }
> ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators),
> data->regulators);
> if (ret) {
> dev_err(data->dev, "Failed to enable regulators: %d\n",
> ret);
> - goto out;
> + return ret;
> }
>
> + ret = devm_add_action_or_reset(data->dev, bma400_regulators_disable, data);
> + if (ret)
> + return ret;
> +
> ret = bma400_get_power_mode(data);
> if (ret) {
> dev_err(data->dev, "Failed to get the initial power-mode\n");
> - goto err_reg_disable;
> + return ret;
> }
>
> if (data->power_mode != POWER_MODE_NORMAL) {
> ret = bma400_set_power_mode(data, POWER_MODE_NORMAL);
> if (ret) {
> dev_err(data->dev, "Failed to wake up the device\n");
> - goto err_reg_disable;
> + return ret;
> }
> /*
> * TODO: The datasheet waits 1500us here in the example, but
> @@ -618,19 +641,23 @@ static int bma400_init(struct bma400_data *data)
> usleep_range(1500, 2000);
> }
>
> + ret = devm_add_action_or_reset(data->dev, bma400_power_disable, data);
> + if (ret)
> + return ret;
> +
> bma400_init_tables();
>
> ret = bma400_get_accel_output_data_rate(data);
> if (ret)
> - goto err_reg_disable;
> + return ret;
>
> ret = bma400_get_accel_oversampling_ratio(data);
> if (ret)
> - goto err_reg_disable;
> + return ret;
>
> ret = bma400_get_accel_scale(data);
> if (ret)
> - goto err_reg_disable;
> + return ret;
>
> /*
> * Once the interrupt engine is supported we might use the
> @@ -639,12 +666,6 @@ static int bma400_init(struct bma400_data *data)
> * channel.
> */
> return regmap_write(data->regmap, BMA400_ACC_CONFIG2_REG, 0x00);
> -
> -err_reg_disable:
> - regulator_bulk_disable(ARRAY_SIZE(data->regulators),
> - data->regulators);
> -out:
> - return ret;
> }
>
> static int bma400_read_raw(struct iio_dev *indio_dev,
> @@ -822,32 +843,10 @@ int bma400_probe(struct device *dev, struct regmap *regmap, const char *name)
> indio_dev->num_channels = ARRAY_SIZE(bma400_channels);
> indio_dev->modes = INDIO_DIRECT_MODE;
>
> - dev_set_drvdata(dev, indio_dev);
> -
> - return iio_device_register(indio_dev);
> + return devm_iio_device_register(dev, indio_dev);
> }
> EXPORT_SYMBOL(bma400_probe);
>
> -void bma400_remove(struct device *dev)
> -{
> - struct iio_dev *indio_dev = dev_get_drvdata(dev);
> - struct bma400_data *data = iio_priv(indio_dev);
> - int ret;
> -
> - mutex_lock(&data->mutex);
> - ret = bma400_set_power_mode(data, POWER_MODE_SLEEP);
> - mutex_unlock(&data->mutex);
> -
> - if (ret)
> - dev_warn(dev, "Failed to put device into sleep mode (%pe)\n", ERR_PTR(ret));
> -
> - regulator_bulk_disable(ARRAY_SIZE(data->regulators),
> - data->regulators);
> -
> - iio_device_unregister(indio_dev);
> -}
> -EXPORT_SYMBOL(bma400_remove);
> -
next prev parent reply other threads:[~2022-03-27 16:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-26 19:41 [PATCH v2 0/5] iio: accel: bma400: Add support for buffer and step Jagath Jog J
2022-03-26 19:41 ` [PATCH v2 1/5] iio: accel: bma400: Fix the scale min and max macro values Jagath Jog J
2022-03-27 16:31 ` Jonathan Cameron
2022-03-26 19:41 ` [PATCH v2 2/5] iio: accel: bma400: conversion to device-managed function Jagath Jog J
2022-03-27 16:35 ` Jonathan Cameron [this message]
2022-03-26 19:41 ` [PATCH v2 3/5] iio: accel: bma400: Add triggered buffer support Jagath Jog J
2022-03-27 16:45 ` Jonathan Cameron
2022-03-28 18:38 ` Jagath Jog J
2022-03-27 19:45 ` Andy Shevchenko
2022-03-28 17:02 ` Jonathan Cameron
2022-03-26 19:41 ` [PATCH v2 4/5] iio: accel: bma400: Add separate channel for step counter Jagath Jog J
2022-03-27 19:43 ` Andy Shevchenko
2022-03-26 19:41 ` [PATCH v2 5/5] iio: accel: bma400: Add step change event Jagath Jog J
2022-03-27 16:50 ` Jonathan Cameron
2022-03-28 20:37 ` Jagath Jog J
2022-04-02 16:37 ` Jonathan Cameron
2022-04-03 7:48 ` Jagath Jog J
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=20220327173551.4fdcc706@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy.shevchenko@gmail.com \
--cc=dan@dlrobertson.com \
--cc=jagathjog1996@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.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