From: Jonathan Cameron <jic23@kernel.org>
To: Antoniu Miclaus <antoniu.miclaus@analog.com>
Cc: <robh@kernel.org>, <conor+dt@kernel.org>,
<linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<devicetree@vger.kernel.org>
Subject: Re: [PATCH v7 4/6] iio: adc: add ade9000 support
Date: Sat, 13 Sep 2025 14:00:08 +0100 [thread overview]
Message-ID: <20250913140008.512a0168@jic23-huawei> (raw)
In-Reply-To: <20250908073531.3639-5-antoniu.miclaus@analog.com>
On Mon, 8 Sep 2025 07:35:24 +0000
Antoniu Miclaus <antoniu.miclaus@analog.com> wrote:
> Add driver support for the ade9000. highly accurate,
> fully integrated, multiphase energy and power quality
> monitoring device.
>
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
> +static int ade9000_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int *val,
> + int *val2,
> + long mask)
> +{
> + case IIO_CHAN_INFO_RAW:
> + if (chan->type == IIO_ENERGY) {
> + u16 lo_reg = chan->address;
> +
> + ret = regmap_bulk_read(st->regmap, lo_reg,
> + st->bulk_read_buf, 2);
> + if (ret)
> + return ret;
> +
> + *val = st->bulk_read_buf[0]; /* Lower 32 bits */
> + *val2 = st->bulk_read_buf[1]; /* Upper 32 bits */
> + return IIO_VAL_INT_64;
> + }
> +
> + ret = iio_device_claim_direct(indio_dev);
Sparse wins. The sense of this is backwards.
One other case of that an access to the private masklength element of iio_dev.
Makes me thing you forwards ported this from an older kernel and didn't
test it.
Anyhow, I have the following diff - some long and short line tweaks in here
along with the real code changes. Please check the result which I'll push
out as testing shortly.
diff --git a/drivers/iio/adc/ade9000.c b/drivers/iio/adc/ade9000.c
index 9aea09180d62..94e05e11abd9 100644
--- a/drivers/iio/adc/ade9000.c
+++ b/drivers/iio/adc/ade9000.c
@@ -790,8 +790,7 @@ static int ade9000_iio_push_streaming(struct iio_dev *indio_dev)
return IRQ_HANDLED;
}
- ade9000_configure_scan(indio_dev,
- ADE9000_REG_WF_BUFF);
+ ade9000_configure_scan(indio_dev, ADE9000_REG_WF_BUFF);
}
return 0;
@@ -807,7 +806,8 @@ static int ade9000_iio_push_buffer(struct iio_dev *indio_dev)
ret = spi_sync(st->spi, &st->spi_msg);
if (ret) {
- dev_err_ratelimited(&st->spi->dev, "SPI fail in trigger handler\n");
+ dev_err_ratelimited(&st->spi->dev,
+ "SPI fail in trigger handler\n");
return ret;
}
@@ -862,7 +862,8 @@ static irqreturn_t ade9000_irq0_thread(int irq, void *data)
if (iio_buffer_enabled(indio_dev)) {
ret = ade9000_iio_push_buffer(indio_dev);
if (ret) {
- dev_err_ratelimited(dev, "IRQ0 IIO push fail @ WFB TRIG\n");
+ dev_err_ratelimited(dev,
+ "IRQ0 IIO push fail @ WFB TRIG\n");
return IRQ_HANDLED;
}
}
@@ -901,9 +902,11 @@ static irqreturn_t ade9000_irq1_thread(int irq, void *data)
/* Clear the reset done status bit */
ret = regmap_write(st->regmap, ADE9000_REG_STATUS1, ADE9000_ST1_RSTDONE_BIT);
if (ret)
- dev_err_ratelimited(&st->spi->dev, "IRQ1 clear reset status fail\n");
+ dev_err_ratelimited(&st->spi->dev,
+ "IRQ1 clear reset status fail\n");
} else {
- dev_err_ratelimited(&st->spi->dev, "Error testing reset done\n");
+ dev_err_ratelimited(&st->spi->dev,
+ "Error testing reset done\n");
}
return IRQ_HANDLED;
@@ -1026,9 +1029,8 @@ static int ade9000_read_raw(struct iio_dev *indio_dev,
return IIO_VAL_INT_64;
}
- ret = iio_device_claim_direct(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = regmap_read(st->regmap, chan->address, &measured);
iio_device_release_direct(indio_dev);
@@ -1040,9 +1042,8 @@ static int ade9000_read_raw(struct iio_dev *indio_dev,
return IIO_VAL_INT;
case IIO_CHAN_INFO_POWERFACTOR:
- ret = iio_device_claim_direct(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = regmap_read(st->regmap, chan->address, &measured);
iio_device_release_direct(indio_dev);
@@ -1206,7 +1207,8 @@ static int ade9000_read_event_config(struct iio_dev *indio_dev,
return !!(interrupts1 & ADE9000_ST1_SWELLA_BIT);
else if (chan->type == IIO_ALTVOLTAGE && dir == IIO_EV_DIR_FALLING)
return !!(interrupts1 & ADE9000_ST1_DIPA_BIT);
- dev_err_ratelimited(&indio_dev->dev, "Invalid channel type %d or direction %d for phase A\n", chan->type, dir);
+ dev_err_ratelimited(&indio_dev->dev,
+ "Invalid channel type %d or direction %d for phase A\n", chan->type, dir);
return -EINVAL;
case ADE9000_PHASE_B_NR:
if (chan->type == IIO_VOLTAGE && dir == IIO_EV_DIR_EITHER)
@@ -1217,7 +1219,8 @@ static int ade9000_read_event_config(struct iio_dev *indio_dev,
return !!(interrupts1 & ADE9000_ST1_SWELLB_BIT);
else if (chan->type == IIO_ALTVOLTAGE && dir == IIO_EV_DIR_FALLING)
return !!(interrupts1 & ADE9000_ST1_DIPB_BIT);
- dev_err_ratelimited(&indio_dev->dev, "Invalid channel type %d or direction %d for phase B\n", chan->type, dir);
+ dev_err_ratelimited(&indio_dev->dev,
+ "Invalid channel type %d or direction %d for phase B\n", chan->type, dir);
return -EINVAL;
case ADE9000_PHASE_C_NR:
if (chan->type == IIO_VOLTAGE && dir == IIO_EV_DIR_EITHER)
@@ -1228,7 +1231,8 @@ static int ade9000_read_event_config(struct iio_dev *indio_dev,
return !!(interrupts1 & ADE9000_ST1_SWELLC_BIT);
else if (chan->type == IIO_ALTVOLTAGE && dir == IIO_EV_DIR_FALLING)
return !!(interrupts1 & ADE9000_ST1_DIPC_BIT);
- dev_err_ratelimited(&indio_dev->dev, "Invalid channel type %d or direction %d for phase C\n", chan->type, dir);
+ dev_err_ratelimited(&indio_dev->dev,
+ "Invalid channel type %d or direction %d for phase C\n", chan->type, dir);
return -EINVAL;
default:
return -EINVAL;
@@ -1309,7 +1313,8 @@ static int ade9000_write_event_config(struct iio_dev *indio_dev,
else
st->wfb_trg &= ~ADE9000_WFB_TRG_DIP_BIT;
} else {
- dev_err_ratelimited(&indio_dev->dev, "Invalid channel type %d or direction %d for phase B\n",
+ dev_err_ratelimited(&indio_dev->dev,
+ "Invalid channel type %d or direction %d for phase B\n",
chan->type, dir);
return -EINVAL;
}
@@ -1340,7 +1345,8 @@ static int ade9000_write_event_config(struct iio_dev *indio_dev,
else
st->wfb_trg &= ~ADE9000_WFB_TRG_DIP_BIT;
} else {
- dev_err_ratelimited(&indio_dev->dev, "Invalid channel type %d or direction %d for phase C\n",
+ dev_err_ratelimited(&indio_dev->dev,
+ "Invalid channel type %d or direction %d for phase C\n",
chan->type, dir);
return -EINVAL;
}
@@ -1418,7 +1424,7 @@ static int ade9000_waveform_buffer_config(struct iio_dev *indio_dev)
u32 active_scans;
bitmap_to_arr32(&active_scans, indio_dev->active_scan_mask,
- indio_dev->masklength);
+ iio_get_masklength(indio_dev));
switch (active_scans) {
case ADE9000_SCAN_POS_IA | ADE9000_SCAN_POS_VA:
> + if (ret)
> + return ret;
> +
> + ret = regmap_read(st->regmap, chan->address, &measured);
> + iio_device_release_direct(indio_dev);
> + if (ret)
> + return ret;
> +
> + *val = measured;
> +
> + return IIO_VAL_INT;
> +
Jonathan
next prev parent reply other threads:[~2025-09-13 13:00 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-08 7:35 [PATCH v7 0/6] iio: adc: add support for ADE9000 Energy Monitoring IC Antoniu Miclaus
2025-09-08 7:35 ` [PATCH v7 1/6] iio: add IIO_ALTCURRENT channel type Antoniu Miclaus
2025-09-08 7:35 ` [PATCH v7 2/6] iio: add power and energy measurement modifiers Antoniu Miclaus
2025-09-08 7:35 ` [PATCH v7 3/6] dt-bindings: iio: adc: add ade9000 Antoniu Miclaus
2025-09-08 18:27 ` Conor Dooley
2025-09-08 7:35 ` [PATCH v7 4/6] iio: adc: add ade9000 support Antoniu Miclaus
2025-09-13 12:46 ` Jonathan Cameron
2025-09-13 13:00 ` Jonathan Cameron [this message]
2025-09-08 7:35 ` [PATCH v7 5/6] docs: iio: add documentation for ade9000 driver Antoniu Miclaus
2025-09-13 12:46 ` Jonathan Cameron
2025-09-13 13:20 ` Jonathan Cameron
2025-09-08 7:35 ` [PATCH v7 6/6] Documentation: ABI: iio: add sinc4+lp Antoniu Miclaus
2025-09-13 13:22 ` [PATCH v7 0/6] iio: adc: add support for ADE9000 Energy Monitoring IC 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=20250913140008.512a0168@jic23-huawei \
--to=jic23@kernel.org \
--cc=antoniu.miclaus@analog.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@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