From: Lars-Peter Clausen <lars@metafoo.de>
To: Waqar Hameed <waqar.hameed@axis.com>,
Jonathan Cameron <jic23@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, kernel@axis.com
Subject: Re: [PATCH 2/2] iio: Add driver for Murata IRS-D200
Date: Fri, 16 Jun 2023 18:37:53 -0700 [thread overview]
Message-ID: <682cf4f8-ba1b-d74a-c744-6aa484c1acd5@metafoo.de> (raw)
In-Reply-To: <d2d8f34c09a2ba0504eaba4f451412de41db2f37.1686926857.git.waqarh@axis.com>
On 6/16/23 08:10, Waqar Hameed wrote:
> Murata IRS-D200 is a PIR sensor for human detection. It has support for
> raw data measurements and detection event notification.
>
> Add a driver with support for triggered buffer and events. Map the
> various settings to the `iio` framework, e.g. threshold values, sampling
> frequency, filter frequencies etc.
>
> Signed-off-by: Waqar Hameed <waqar.hameed@axis.com>
Looks very good, small minor comments.
> [...]
> diff --git a/drivers/iio/proximity/Makefile b/drivers/iio/proximity/Makefile
> index cc838bb5408a..f36598380446 100644
> --- a/drivers/iio/proximity/Makefile
> +++ b/drivers/iio/proximity/Makefile
> @@ -6,6 +6,7 @@
> # When adding new entries keep the list in alphabetical order
> obj-$(CONFIG_AS3935) += as3935.o
> obj-$(CONFIG_CROS_EC_MKBP_PROXIMITY) += cros_ec_mkbp_proximity.o
> +obj-$(CONFIG_IRSD200) += irsd200.o
> obj-$(CONFIG_ISL29501) += isl29501.o
> obj-$(CONFIG_LIDAR_LITE_V2) += pulsedlight-lidar-lite-v2.o
> obj-$(CONFIG_MB1232) += mb1232.o
> diff --git a/drivers/iio/proximity/irsd200.c b/drivers/iio/proximity/irsd200.c
> new file mode 100644
> index 000000000000..699801d60295
> --- /dev/null
> +++ b/drivers/iio/proximity/irsd200.c
> @@ -0,0 +1,1051 @@
> [...]
> +/*
> + * The upper 4 bits in register IRS_REG_COUNT value is the upper count value
> + * (exceeding upper threshold value). The lower 4 is the lower count value
> + * (exceeding lower threshold value).
> + */
> +#define IRS_UPPER_COUNT(count) (count >> 4)
> +#define IRS_LOWER_COUNT(count) (count & GENMASK(3, 0))
Usually we add parenthesis around macro arguments to avoid issues in
case the argument is a non-singular expression.
> [...]
>
> +static int irsd200_read_data(struct irsd200_data *data, s16 *val)
> +{
> + unsigned int tmpval;
> + int ret;
> +
> + ret = regmap_read(data->regmap, IRS_REG_DATA_HI, &tmpval);
> + if (ret < 0) {
> + dev_err(data->dev, "Could not read hi data (%d)\n", ret);
> + return ret;
> + }
> +
> + *val = (s16)(tmpval << 8);
> +
> + ret = regmap_read(data->regmap, IRS_REG_DATA_LO, &tmpval);
> + if (ret < 0) {
> + dev_err(data->dev, "Could not read lo data (%d)\n", ret);
> + return ret;
> + }
Is there a way to bulk read those registers in one go to avoid
inconsistent data if they change while being read?
> + *val |= tmpval;
> +
> + return 0;
> +}
> [...]
> +static int irsd200_write_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int val,
> + int val2, long mask)
> +{
> + struct irsd200_data *data = iio_priv(indio_dev);
> + int ret;
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + ret = irsd200_write_data_rate(data, val);
> + return ret;
Maybe just `return irsd200_write_data_rate(...)`
> + default:
> + return -EINVAL;
> + }
> +}
> +
>
> [...]
> +static int irsd200_probe(struct i2c_client *client)
> +{
> + struct iio_trigger *trigger;
> + struct irsd200_data *data;
> + struct iio_dev *indio_dev;
> + struct regmap *regmap;
> + size_t i;
> + int ret;
> +
> + regmap = devm_regmap_init_i2c(client, &irsd200_regmap_config);
> + if (IS_ERR(regmap)) {
> + dev_err(&client->dev, "Could not initialize regmap\n");
dev_err_probe() is the more modern variant for error reporting in the
probe function. Same for all the other dev_err() in this function.
> + return PTR_ERR(regmap);
> + }
> +
> + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
> + if (!indio_dev) {
> + dev_err(&client->dev, "Could not allocate iio device\n");
> + return -ENOMEM;
> + }
> +
> + data = iio_priv(indio_dev);
> + data->regmap = regmap;
> + data->dev = &client->dev;
> + i2c_set_clientdata(client, indio_dev);
> +
> + for (i = 0; i < IRS_REGF_MAX; ++i) {
> + data->regfields[i] = devm_regmap_field_alloc(
> + data->dev, data->regmap, irsd200_regfields[i]);
> + if (IS_ERR(data->regfields[i])) {
> + dev_err(data->dev,
> + "Could not allocate register field %zu\n", i);
> + return PTR_ERR(data->regfields[i]);
> + }
> + }
> +
> [...]
next prev parent reply other threads:[~2023-06-17 1:38 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-16 15:10 [PATCH 0/2] " Waqar Hameed
2023-06-16 15:10 ` [PATCH 1/2] dt-bindings: iio: proximity: Add bindings " Waqar Hameed
2023-06-17 8:55 ` Krzysztof Kozlowski
2023-06-19 10:40 ` Waqar Hameed
2023-06-19 11:29 ` Krzysztof Kozlowski
2023-06-17 12:55 ` Jonathan Cameron
2023-06-19 10:41 ` Waqar Hameed
2023-07-02 10:34 ` Jonathan Cameron
2023-06-16 15:10 ` [PATCH 2/2] iio: Add driver " Waqar Hameed
2023-06-17 1:37 ` Lars-Peter Clausen [this message]
2023-06-19 11:21 ` Waqar Hameed
2023-06-17 13:35 ` Jonathan Cameron
2023-06-19 11:24 ` Waqar Hameed
2023-06-25 11:06 ` Jonathan Cameron
2023-06-30 8:54 ` Waqar Hameed
2023-07-02 10:42 ` Jonathan Cameron
2023-07-03 8:59 ` Waqar Hameed
2023-07-05 7:50 ` Jonathan Cameron
2023-07-12 15:33 ` Waqar Hameed
2023-07-15 16:51 ` 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=682cf4f8-ba1b-d74a-c744-6aa484c1acd5@metafoo.de \
--to=lars@metafoo.de \
--cc=jic23@kernel.org \
--cc=kernel@axis.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=waqar.hameed@axis.com \
/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
all inboxes | Powered by JetHome®