From: Jonathan Cameron <jic23@jic23.retrosnub.co.uk>
To: Gwendal Grignou <gwendal@chromium.org>
Cc: robh+dt@kernel.org, lars@metafoo.de, swboyd@chromium.org,
andy.shevchenko@gmail.com, linux-iio@vger.kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v3 2/4] iio: proximity: Add sx9360 support
Date: Thu, 16 Dec 2021 16:21:46 +0000 [thread overview]
Message-ID: <20211216162139.6008820e@jic23-huawei> (raw)
In-Reply-To: <20211213024057.3824985-3-gwendal@chromium.org>
On Sun, 12 Dec 2021 18:40:55 -0800
Gwendal Grignou <gwendal@chromium.org> wrote:
> A simplified version of SX9324, it only have one pin and
> 2 phases (aka channels).
> Only one event is presented.
>
> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
You don't use the modifier defined in the previous
patch...
> ---
> Changes since v2:
> - Fix issues reported during sx9324 driver review:
> - fix include with iwyu
> - Remove call to ACPI_PTR to prevent unused variable warning.
> - Fix panic when setting frequency to 0.
> - Add offset to decipher interrupt register
> - Fix default register value.
>
> Changes since v1:
> - Remove SX9360_DRIVER_NAME
> - Simplify whoami function
> - Define WHOAMI register value internally.
> - Handle negative values when setting sysfs parameters.
>
> drivers/iio/proximity/Kconfig | 14 +
> drivers/iio/proximity/Makefile | 1 +
> drivers/iio/proximity/sx9360.c | 807 +++++++++++++++++++++++++++++++++
> 3 files changed, 822 insertions(+)
> create mode 100644 drivers/iio/proximity/sx9360.c
>
....
> +static const struct iio_chan_spec sx9360_channels[] = {
> + {
> + .type = IIO_PROXIMITY,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_HARDWAREGAIN),
> + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
> + .info_mask_separate_available =
> + BIT(IIO_CHAN_INFO_HARDWAREGAIN),
> + .info_mask_shared_by_all_available =
> + BIT(IIO_CHAN_INFO_SAMP_FREQ),
> + .extend_name = "reference",
You defined the modifier for this and then didn't use it?
I've suggested in review of patch 1 you might want to use label though
via the read_label() callback.
> + .address = SX9360_REG_USEFUL_PHR_MSB,
> + .channel = 0,
> + .scan_index = 0,
> + .scan_type = {
> + .sign = 's',
> + .realbits = 12,
> + .storagebits = 16,
> + .endianness = IIO_BE,
> + },
> + },
> + {
> + .type = IIO_PROXIMITY,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_HARDWAREGAIN),
> + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
> + .info_mask_separate_available =
> + BIT(IIO_CHAN_INFO_HARDWAREGAIN),
> + .info_mask_shared_by_all_available =
> + BIT(IIO_CHAN_INFO_SAMP_FREQ),
> + .address = SX9360_REG_USEFUL_PHM_MSB,
> + .event_spec = sx_common_events,
> + .num_event_specs = ARRAY_SIZE(sx_common_events),
> + .channel = 1,
> + .scan_index = 1,
> + .scan_type = {
> + .sign = 's',
> + .realbits = 12,
> + .storagebits = 16,
> + .endianness = IIO_BE,
> + },
> + },
> + IIO_CHAN_SOFT_TIMESTAMP(2),
> +};
> +
...
> +
> +static int sx9360_read_samp_freq(struct sx_common_data *data,
> + int *val, int *val2)
> +{
> + int ret, divisor;
> + __be16 buf;
> +
> + ret = regmap_bulk_read(data->regmap, SX9360_REG_GNRL_CTRL1,
> + &buf, sizeof(buf));
> + if (ret < 0)
> + return ret;
> + divisor = be16_to_cpu(buf);
> + if (divisor == 0) {
> + *val = 0;
> + return IIO_VAL_INT;
> + }
> +
> + *val = SX9360_FOSC_HZ;
> + *val2 = be16_to_cpu(buf) * 8192;
*val2 = divisor * 8192;?
> +
> + return IIO_VAL_FRACTIONAL;
> +}
> +
...
> +static int sx9360_write_raw(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan, int val, int val2,
> + long mask)
> +{
> + struct sx_common_data *data = iio_priv(indio_dev);
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + return sx9360_set_samp_freq(data, val, val2);
> + case IIO_CHAN_INFO_HARDWAREGAIN:
> + return sx9360_write_gain(data, chan, val);
> + }
> +
Slight preference for this as a default in the switch.
> + return -EINVAL;
> +}
...
> +static int sx9360_check_whoami(struct device *dev,
> + struct iio_dev *indio_dev)
Will fit on one line under 80 chars I think..
> +{
> + /*
> + * Only one sensor for this driver. Assuming the device tree
> + * is correct, just set the sensor name.
> + */
> + indio_dev->name = "sx9360";
> + return 0;
> +}
> +
> +
> +static int __maybe_unused sx9360_suspend(struct device *dev)
> +{
> + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
I don't feel particularly strongly about this, as there are arguments
either way but this is the same as
struct iio_dev *indio_dev = dev_get_drvdata(dev);
> + struct sx_common_data *data = iio_priv(indio_dev);
> + unsigned int regval;
> + int ret;
> +
> + disable_irq_nosync(data->client->irq);
> +
> + mutex_lock(&data->mutex);
> + ret = regmap_read(data->regmap, SX9360_REG_GNRL_CTRL0, ®val);
> +
> + data->suspend_ctrl =
> + FIELD_GET(SX9360_REG_GNRL_CTRL0_PHEN_MASK, regval);
> +
> + if (ret < 0)
> + goto out;
> +
> + /* Disable all phases, send the device to sleep. */
> + ret = regmap_write(data->regmap, SX9360_REG_GNRL_CTRL0, 0);
> +
> +out:
> + mutex_unlock(&data->mutex);
> + return ret;
> +}
> +
next prev parent reply other threads:[~2021-12-16 16:16 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-13 2:40 [PATCH v3 0/4] Add Semtech SX9360 SAR Sensor support Gwendal Grignou
2021-12-13 2:40 ` [PATCH v3 1/4] iio: add IIO_MOD_REFERENCE modifier Gwendal Grignou
2021-12-16 15:59 ` Jonathan Cameron
2021-12-17 20:24 ` Gwendal Grignou
2021-12-13 2:40 ` [PATCH v3 2/4] iio: proximity: Add sx9360 support Gwendal Grignou
2021-12-15 1:14 ` Stephen Boyd
2021-12-16 16:21 ` Jonathan Cameron [this message]
2021-12-18 0:27 ` Gwendal Grignou
2021-12-13 2:40 ` [PATCH v3 3/4] dt-bindings: iio: Add sx9360 binding Gwendal Grignou
2021-12-15 1:15 ` Stephen Boyd
2021-12-15 20:09 ` Rob Herring
2021-12-13 2:40 ` [PATCH v3 4/4] iio: sx9360: Add dt-binding support Gwendal Grignou
2021-12-15 1:16 ` Stephen Boyd
2021-12-16 16:23 ` 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=20211216162139.6008820e@jic23-huawei \
--to=jic23@jic23.retrosnub.co.uk \
--cc=andy.shevchenko@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=gwendal@chromium.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=swboyd@chromium.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