Re: [PATCH v3 2/3] iio: pressure: Add driver for Sensirion SDP500

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 02 Jul 2024 16:59:09 +0200
Petar Stoykov via B4 Relay <devnull+pd.pstoykov.gmail.com@xxxxxxxxxx> wrote:

> From: Petar Stoykov <pd.pstoykov@xxxxxxxxx>
> 
> Sensirion SDP500 is a digital differential pressure sensor. The sensor is
> accessed over I2C.
> 
> Signed-off-by: Petar Stoykov <pd.pstoykov@xxxxxxxxx>
Hi Petar

Given you are going to be doing a v4, a few comments inline on things
to tidy up in here.

Note that I've already tagged what may be the last pull request from me
for the 6.11 merge window, so this is probably 6.12 material now anyway.
Hence plenty of time to tidy up.

Jonathan

> diff --git a/drivers/iio/pressure/sdp500.c b/drivers/iio/pressure/sdp500.c
> new file mode 100644
> index 000000000000..661c70bc1b5b
> --- /dev/null
> +++ b/drivers/iio/pressure/sdp500.c
> @@ -0,0 +1,153 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Driver for Sensirion sdp500 and sdp510 pressure sensors
> + *
> + * Datasheet: https://sensirion.com/resource/datasheet/sdp600
> + */
> +
> +#include <linux/i2c.h>
> +#include <linux/crc8.h>
> +#include <linux/iio/iio.h>

#include <linux/mod_devicetable.h> appropriate for the id tables.

> +#include <linux/regulator/consumer.h>
> +#include <asm/unaligned.h>
> +
> +#define SDP500_CRC8_POLYNOMIAL  0x31   // x8 + x5 + x4 + 1 (normalized to 0x31)

For IIO we tend to just use c style comments /* xxx */
and not c++ ones.

> +#define SDP500_READ_SIZE        3

> +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);
A line break in here to keep it under 80 chars would be good (see below).

> +		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");
Given you are going around again.  Add a line break before "
General rule is stay under 80 chars unless it hurts readability.
 
> +




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux