From: Jonathan Cameron <jic23@kernel.org>
To: Petar Stoykov via B4 Relay <devnull+pd.pstoykov.gmail.com@kernel.org>
Cc: pd.pstoykov@gmail.com, linux-iio@vger.kernel.org,
Lars-Peter Clausen <lars@metafoo.de>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/3] iio: pressure: Add driver for Sensirion SDP500
Date: Sun, 28 Jul 2024 16:28:28 +0100 [thread overview]
Message-ID: <20240728162828.3c9cc118@jic23-huawei> (raw)
In-Reply-To: <20240725-mainline_sdp500-v4-2-ea2f5b189958@gmail.com>
On Thu, 25 Jul 2024 17:37:28 +0200
Petar Stoykov via B4 Relay <devnull+pd.pstoykov.gmail.com@kernel.org> wrote:
> From: Petar Stoykov <pd.pstoykov@gmail.com>
>
> Sensirion SDP500 is a digital differential pressure sensor. The sensor is
> accessed over I2C.
>
> Signed-off-by: Petar Stoykov <pd.pstoykov@gmail.com>
Hi Petar,
Some really trivial things inline + Krzysztof's comment.
Rather than go around again, I'll tidy them up as follows and apply this series
to the testing branch of iio.git
Thanks,
Jonathan
diff --git a/drivers/iio/pressure/sdp500.c b/drivers/iio/pressure/sdp500.c
index 77d7e68f5dea..6ff32e3fa637 100644
--- a/drivers/iio/pressure/sdp500.c
+++ b/drivers/iio/pressure/sdp500.c
@@ -62,7 +62,7 @@ static int sdp500_read_raw(struct iio_dev *indio_dev,
received_crc = rxbuf[2];
calculated_crc = crc8(sdp500_crc8_table, rxbuf,
- sizeof(rxbuf) - 1, 0x00);
+ sizeof(rxbuf) - 1, 0x00);
if (received_crc != calculated_crc) {
dev_err(data->dev,
"calculated crc = 0x%.2X, received 0x%.2X",
@@ -123,7 +123,7 @@ static int sdp500_probe(struct i2c_client *client)
i2c_master_recv(client, rxbuf, SDP500_READ_SIZE);
ret = devm_iio_device_register(dev, indio_dev);
- if (ret < 0)
+ if (ret)
return dev_err_probe(dev, ret, "Failed to register indio_dev");
return 0;
@@ -137,7 +137,6 @@ MODULE_DEVICE_TABLE(i2c, sdp500_id);
static const struct of_device_id sdp500_of_match[] = {
{ .compatible = "sensirion,sdp500" },
- { .compatible = "sensirion,sdp510" },
{ }
};
MODULE_DEVICE_TABLE(of, sdp500_of_match);
> st_pressure-$(CONFIG_IIO_BUFFER) += st_pressure_buffer.o
> diff --git a/drivers/iio/pressure/sdp500.c b/drivers/iio/pressure/sdp500.c
> new file mode 100644
> index 000000000000..77d7e68f5dea
> --- /dev/null
> +++ b/drivers/iio/pressure/sdp500.c
> @@ -0,0 +1,157 @@
...
> +
> +static int sdp500_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int *val, int *val2, long mask)
> +{
> + int ret;
> + u8 rxbuf[SDP500_READ_SIZE];
> + u8 received_crc, calculated_crc;
> + struct sdp500_data *data = iio_priv(indio_dev);
> + struct i2c_client *client = to_i2c_client(data->dev);
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_RAW:
> + ret = i2c_master_recv(client, rxbuf, SDP500_READ_SIZE);
> + if (ret < 0) {
> + dev_err(data->dev, "Failed to receive data");
> + return ret;
> + }
> + if (ret != SDP500_READ_SIZE) {
> + dev_err(data->dev, "Data is received wrongly");
> + return -EIO;
> + }
> +
> + received_crc = rxbuf[2];
> + calculated_crc = crc8(sdp500_crc8_table, rxbuf,
> + sizeof(rxbuf) - 1, 0x00);
align just after (
> + if (received_crc != calculated_crc) {
> + dev_err(data->dev,
> + "calculated crc = 0x%.2X, received 0x%.2X",
> + calculated_crc, received_crc);
> + return -EIO;
> + }
> +
> + *val = get_unaligned_be16(rxbuf);
> + return IIO_VAL_INT;
> + case IIO_CHAN_INFO_SCALE:
> + *val = 1;
> + *val2 = 60;
> +
> + return IIO_VAL_FRACTIONAL;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static const struct iio_info sdp500_info = {
> + .read_raw = &sdp500_read_raw,
> +};
> +
> +static int sdp500_probe(struct i2c_client *client)
> +{
> + struct iio_dev *indio_dev;
> + struct sdp500_data *data;
> + struct device *dev = &client->dev;
> + int ret;
> + u8 rxbuf[SDP500_READ_SIZE];
> +
> + ret = devm_regulator_get_enable(dev, "vdd");
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "Failed to get and enable regulator\n");
> +
> + indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
> + if (!indio_dev)
> + return -ENOMEM;
> +
> + /* has to be done before the first i2c communication */
> + crc8_populate_msb(sdp500_crc8_table, SDP500_CRC8_POLYNOMIAL);
> +
> + data = iio_priv(indio_dev);
> + data->dev = dev;
> +
> + indio_dev->name = "sdp500";
> + indio_dev->channels = sdp500_channels;
> + indio_dev->info = &sdp500_info;
> + indio_dev->modes = INDIO_DIRECT_MODE;
> + indio_dev->num_channels = ARRAY_SIZE(sdp500_channels);
> +
> + ret = sdp500_start_measurement(data);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to start measurement");
> +
> + /* First measurement is not correct, read it out to get rid of it */
> + i2c_master_recv(client, rxbuf, SDP500_READ_SIZE);
> +
> + ret = devm_iio_device_register(dev, indio_dev);
> + if (ret < 0)
if (ret) is more consistent with other handling in the driver (and my preference
in general for checking IIO core code calls).
> + return dev_err_probe(dev, ret, "Failed to register indio_dev");
> +
> + return 0;
> +}
next prev parent reply other threads:[~2024-07-28 15:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-25 15:37 [PATCH v4 0/3] Add support for Sensirion SDP500 Petar Stoykov via B4 Relay
2024-07-25 15:37 ` [PATCH v4 1/3] dt-bindings: iio: pressure: Add " Petar Stoykov via B4 Relay
2024-07-28 9:13 ` Krzysztof Kozlowski
2024-07-25 15:37 ` [PATCH v4 2/3] iio: pressure: Add driver for " Petar Stoykov via B4 Relay
2024-07-28 9:12 ` Krzysztof Kozlowski
2024-07-28 15:29 ` Jonathan Cameron
2024-07-28 15:28 ` Jonathan Cameron [this message]
2024-07-25 15:37 ` [PATCH v4 3/3] MAINTAINERS: Add " Petar Stoykov via B4 Relay
2024-07-28 15:30 ` [PATCH v4 0/3] Add support for " 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=20240728162828.3c9cc118@jic23-huawei \
--to=jic23@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=devnull+pd.pstoykov.gmail.com@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pd.pstoykov@gmail.com \
--cc=robh+dt@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