From: "Nuno Sá" <noname.nuno@gmail.com>
To: David Lechner <dlechner@baylibre.com>,
Jonathan Cameron <jic23@kernel.org>
Cc: "Michael Hennerich" <Michael.Hennerich@analog.com>,
"Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>,
"Antoniu Miclaus" <antoniu.miclaus@analog.com>,
"Nuno Sá" <nuno.sa@analog.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] iio: dac: ad7293: enable power before reset
Date: Tue, 17 Dec 2024 11:05:38 +0100 [thread overview]
Message-ID: <f24abf927dcd21866bdb335d5ed27f3be4d94705.camel@gmail.com> (raw)
In-Reply-To: <20241216-iio-regulator-cleanup-round-6-v2-1-9482164b68cb@baylibre.com>
On Mon, 2024-12-16 at 15:44 -0600, David Lechner wrote:
> Change the order of regulator enable and reset so that power supplies
> are turned on before touching the reset line. Generally, chips should
> have the VDRIVE supply enabled before applying voltage on any pins.
>
> While we are at it, remove the voltage level checks. If the power
> supplies are not supplying the correct voltage, this is a hardware
> design problem, not a software problem.
>
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> Changes in v2:
> - Dropped patches from "iio: use devm_regulator_get_enable_read_voltage
> round 6" that have already been applied.
> - New patch for ad7293 that just enables power supplies and no longer
> reads the voltage.
> - Link to v1:
> https://lore.kernel.org/r/20241120-iio-regulator-cleanup-round-6-v1-0-d5a5360f7ec3@baylibre.com
> ---
> drivers/iio/dac/ad7293.c | 68 +++++++----------------------------------------
> -
> 1 file changed, 9 insertions(+), 59 deletions(-)
>
> diff --git a/drivers/iio/dac/ad7293.c b/drivers/iio/dac/ad7293.c
> index
> 1d403267048240be1bf3d8b2a59685409b9087fd..d3f49b5337d2f512363d50b434d99d4e9b95
> 059f 100644
> --- a/drivers/iio/dac/ad7293.c
> +++ b/drivers/iio/dac/ad7293.c
> @@ -141,8 +141,6 @@ struct ad7293_state {
> /* Protect against concurrent accesses to the device, page selection
> and data content */
> struct mutex lock;
> struct gpio_desc *gpio_reset;
> - struct regulator *reg_avdd;
> - struct regulator *reg_vdrive;
> u8 page_select;
> u8 data[3] __aligned(IIO_DMA_MINALIGN);
> };
> @@ -777,6 +775,15 @@ static int ad7293_reset(struct ad7293_state *st)
> static int ad7293_properties_parse(struct ad7293_state *st)
> {
> struct spi_device *spi = st->spi;
> + int ret;
> +
> + ret = devm_regulator_get_enable(&spi->dev, "avdd");
> + if (ret)
> + return dev_err_probe(&spi->dev, ret, "failed to enable
> AVDD\n");
> +
> + ret = devm_regulator_get_enable(&spi->dev, "vdrive");
> + if (ret)
> + return dev_err_probe(&spi->dev, ret, "failed to enable
> VDRIVE\n");
>
> st->gpio_reset = devm_gpiod_get_optional(&st->spi->dev, "reset",
> GPIOD_OUT_HIGH);
> @@ -784,24 +791,9 @@ static int ad7293_properties_parse(struct ad7293_state
> *st)
> return dev_err_probe(&spi->dev, PTR_ERR(st->gpio_reset),
> "failed to get the reset GPIO\n");
>
> - st->reg_avdd = devm_regulator_get(&spi->dev, "avdd");
> - if (IS_ERR(st->reg_avdd))
> - return dev_err_probe(&spi->dev, PTR_ERR(st->reg_avdd),
> - "failed to get the AVDD voltage\n");
> -
> - st->reg_vdrive = devm_regulator_get(&spi->dev, "vdrive");
> - if (IS_ERR(st->reg_vdrive))
> - return dev_err_probe(&spi->dev, PTR_ERR(st->reg_vdrive),
> - "failed to get the VDRIVE voltage\n");
> -
> return 0;
> }
>
> -static void ad7293_reg_disable(void *data)
> -{
> - regulator_disable(data);
> -}
> -
> static int ad7293_init(struct ad7293_state *st)
> {
> int ret;
> @@ -816,48 +808,6 @@ static int ad7293_init(struct ad7293_state *st)
> if (ret)
> return ret;
>
> - ret = regulator_enable(st->reg_avdd);
> - if (ret) {
> - dev_err(&spi->dev,
> - "Failed to enable specified AVDD Voltage!\n");
> - return ret;
> - }
> -
> - ret = devm_add_action_or_reset(&spi->dev, ad7293_reg_disable,
> - st->reg_avdd);
> - if (ret)
> - return ret;
> -
> - ret = regulator_enable(st->reg_vdrive);
> - if (ret) {
> - dev_err(&spi->dev,
> - "Failed to enable specified VDRIVE Voltage!\n");
> - return ret;
> - }
> -
> - ret = devm_add_action_or_reset(&spi->dev, ad7293_reg_disable,
> - st->reg_vdrive);
> - if (ret)
> - return ret;
> -
> - ret = regulator_get_voltage(st->reg_avdd);
> - if (ret < 0) {
> - dev_err(&spi->dev, "Failed to read avdd regulator: %d\n",
> ret);
> - return ret;
> - }
> -
> - if (ret > 5500000 || ret < 4500000)
> - return -EINVAL;
> -
> - ret = regulator_get_voltage(st->reg_vdrive);
> - if (ret < 0) {
> - dev_err(&spi->dev,
> - "Failed to read vdrive regulator: %d\n", ret);
> - return ret;
> - }
> - if (ret > 5500000 || ret < 1700000)
> - return -EINVAL;
> -
> /* Check Chip ID */
> ret = __ad7293_spi_read(st, AD7293_REG_DEVICE_ID, &chip_id);
> if (ret)
>
> ---
> base-commit: 01958cb8a00d9721ae56ad1eef9cd7b22b5a34bb
> change-id: 20241120-iio-regulator-cleanup-round-6-78b05be06718
>
> Best regards,
next prev parent reply other threads:[~2024-12-17 10:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-16 21:44 [PATCH v2] iio: dac: ad7293: enable power before reset David Lechner
2024-12-17 10:05 ` Nuno Sá [this message]
2024-12-19 16:37 ` Jonathan Cameron
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=f24abf927dcd21866bdb335d5ed27f3be4d94705.camel@gmail.com \
--to=noname.nuno@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=antoniu.miclaus@analog.com \
--cc=broonie@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.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