[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250913140008.512a0168@jic23-huawei>
Date: Sat, 13 Sep 2025 14:00:08 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: Antoniu Miclaus <antoniu.miclaus@...log.com>
Cc: <robh@...nel.org>, <conor+dt@...nel.org>, <linux-iio@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <devicetree@...r.kernel.org>
Subject: Re: [PATCH v7 4/6] iio: adc: add ade9000 support
On Mon, 8 Sep 2025 07:35:24 +0000
Antoniu Miclaus <antoniu.miclaus@...log.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@...log.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
Powered by blists - more mailing lists