From: Jonathan Cameron <jic23@kernel.org>
To: <alexandru.tachici@analog.com>
Cc: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 5/8] iio: adc: ad7124: add sequencer support
Date: Sat, 19 Mar 2022 16:09:01 +0000 [thread overview]
Message-ID: <20220319160901.61b13399@jic23-huawei> (raw)
In-Reply-To: <20220318162722.51215-6-alexandru.tachici@analog.com>
On Fri, 18 Mar 2022 18:27:19 +0200
<alexandru.tachici@analog.com> wrote:
> From: Alexandru Tachici <alexandru.tachici@analog.com>
>
> Add sequencer support for AD7124.
>
> Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com>
Hi Alexandru,
A few comments inline.
Thanks,
Jonathan
> ---
> drivers/iio/adc/ad7124.c | 32 +++++++++++++++++++++++++-------
> 1 file changed, 25 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> index 428ec3e257d7..782b7cdd8ebe 100644
> --- a/drivers/iio/adc/ad7124.c
> +++ b/drivers/iio/adc/ad7124.c
> @@ -43,6 +43,8 @@
> #define AD7124_STATUS_POR_FLAG_MSK BIT(4)
>
> /* AD7124_ADC_CONTROL */
> +#define AD7124_ADC_STATUS_EN_MSK BIT(10)
> +#define AD7124_ADC_STATUS_EN(x) FIELD_PREP(AD7124_ADC_STATUS_EN_MSK, x)
> #define AD7124_ADC_CTRL_REF_EN_MSK BIT(8)
> #define AD7124_ADC_CTRL_REF_EN(x) FIELD_PREP(AD7124_ADC_CTRL_REF_EN_MSK, x)
> #define AD7124_ADC_CTRL_PWR_MSK GENMASK(7, 6)
> @@ -512,14 +514,27 @@ static int ad7124_set_channel(struct ad_sigma_delta *sd, unsigned int channel)
> return ret;
> }
>
> +static int ad7124_append_status(struct ad_sigma_delta *sd, bool append)
> +{
> + struct ad7124_state *st = container_of(sd, struct ad7124_state, sd);
> +
> + st->adc_control &= ~AD7124_ADC_STATUS_EN_MSK;
> + st->adc_control |= AD7124_ADC_STATUS_EN(append);
Generally avoid updating cached state until you know the write succeeded.
So I would operate on a local variable and if ad_sd_write_reg() succeeds
copy that back into st->adc_control.
Obviously on error it 'might' have been updated successfully and something failed
after the write, but it is probably more likely the write failed.
> +
> + return ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL, 2, st->adc_control);
> +}
> +
> static const struct ad_sigma_delta_info ad7124_sigma_delta_info = {
> .set_channel = ad7124_set_channel,
> + .append_status = ad7124_append_status,
> .set_mode = ad7124_set_mode,
> .has_registers = true,
> .addr_shift = 0,
> .read_mask = BIT(6),
> + .status_ch_mask = GENMASK(3, 0),
> .data_reg = AD7124_DATA,
> - .irq_flags = IRQF_TRIGGER_FALLING
> + .num_slots = 8,
> + .irq_flags = IRQF_TRIGGER_FALLING,
> };
>
> static int ad7124_read_raw(struct iio_dev *indio_dev,
> @@ -679,10 +694,11 @@ static int ad7124_update_scan_mode(struct iio_dev *indio_dev,
>
> for (i = 0; i < st->num_channels; i++) {
> bit_set = test_bit(i, scan_mask);
> - ret = ad7124_spi_write_mask(st, AD7124_CHANNEL(i),
> - AD7124_CHANNEL_EN_MSK,
> - AD7124_CHANNEL_EN(bit_set),
> - 2);
> + if (bit_set)
> + ret = ad7124_set_channel(&st->sd, i);
This is going to repeatedly take an release the cfg mutex. Perhaps it's worth
introducing a __ad7124_set_channel() that doesn't take the lock then take it around
this loop instead?
> + else
> + ret = ad7124_spi_write_mask(st, AD7124_CHANNEL(i), AD7124_CHANNEL_EN_MSK,
> + 0, 2);
> if (ret < 0)
> return ret;
> }
> @@ -906,12 +922,14 @@ static int ad7124_probe(struct spi_device *spi)
>
> st->chip_info = info;
>
> - ad_sd_init(&st->sd, indio_dev, spi, &ad7124_sigma_delta_info);
> -
> indio_dev->name = st->chip_info->name;
> indio_dev->modes = INDIO_DIRECT_MODE;
> indio_dev->info = &ad7124_info;
>
> + ret = ad_sd_init(&st->sd, indio_dev, spi, &ad7124_sigma_delta_info);
> + if (ret < 0)
> + return ret;
> +
> ret = ad7124_of_parse_channel_config(indio_dev, spi->dev.of_node);
> if (ret < 0)
> return ret;
next prev parent reply other threads:[~2022-03-19 16:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-18 16:27 [PATCH v2 0/8] iio: adc: ad_sigma_delta: Add sequencer support alexandru.tachici
2022-03-18 16:27 ` [PATCH v2 1/8] iio: adc: ad7124: Remove shift from scan_type alexandru.tachici
2022-03-19 15:38 ` Jonathan Cameron
2022-03-18 16:27 ` [PATCH v2 2/8] iio: adc: ad7124: Add update_scan_mode alexandru.tachici
2022-03-19 15:45 ` Jonathan Cameron
2022-03-18 16:27 ` [PATCH v2 3/8] iio: adc: ad7192: " alexandru.tachici
2022-03-18 16:27 ` [PATCH v2 4/8] iio: adc: ad_sigma_delta: Add sequencer support alexandru.tachici
2022-03-19 16:03 ` Jonathan Cameron
2022-03-18 16:27 ` [PATCH v2 5/8] iio: adc: ad7124: add " alexandru.tachici
2022-03-19 16:09 ` Jonathan Cameron [this message]
2022-03-18 16:27 ` [PATCH v2 6/8] iio: adc: ad7192: " alexandru.tachici
2022-03-19 16:11 ` Jonathan Cameron
2022-03-18 16:27 ` [PATCH v2 7/8] iio: adc: ad7124: add disable_all() callback alexandru.tachici
2022-03-19 16:10 ` Jonathan Cameron
2022-03-18 16:27 ` [PATCH v2 8/8] iio: adc: ad7192: " alexandru.tachici
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=20220319160901.61b13399@jic23-huawei \
--to=jic23@kernel.org \
--cc=alexandru.tachici@analog.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