From: Jonathan Cameron <jic23@kernel.org>
To: Mehdi Djait <mehdi.djait.k@gmail.com>
Cc: mazziesaccount@gmail.com, krzysztof.kozlowski+dt@linaro.org,
andriy.shevchenko@linux.intel.com, robh+dt@kernel.org,
lars@metafoo.de, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 7/7] iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer
Date: Sat, 6 May 2023 17:46:51 +0100 [thread overview]
Message-ID: <20230506174651.5c5740d9@jic23-huawei> (raw)
In-Reply-To: <ZFVG1cyY/Ge/nXOh@carbian>
On Fri, 5 May 2023 20:11:33 +0200
Mehdi Djait <mehdi.djait.k@gmail.com> wrote:
> Hello Jonathan,
>
> On Mon, May 01, 2023 at 03:56:45PM +0100, Jonathan Cameron wrote:
> > On Tue, 25 Apr 2023 00:22:27 +0200
> > Mehdi Djait <mehdi.djait.k@gmail.com> wrote:
> >
> > > Kionix KX132-1211 is a tri-axis 16-bit accelerometer that can support
> > > ranges from ±2G to ±16G, digital output through I²C/SPI.
> > > Add support for basic accelerometer features such as reading acceleration
> > > via IIO using raw reads, triggered buffer (data-ready), or the WMI IRQ.
> > >
> > > Datasheet: https://kionixfs.azureedge.net/en/document/KX132-1211-Technical-Reference-Manual-Rev-5.0.pdf
> > > Signed-off-by: Mehdi Djait <mehdi.djait.k@gmail.com>
> >
> > Two tiny things inline.
> >
> > > +static int kx132_get_fifo_bytes(struct kx022a_data *data)
> > > +{
> > > + struct device *dev = regmap_get_device(data->regmap);
> > > + __le16 buf_status;
> > > + int ret, fifo_bytes;
> > > +
> > > + ret = regmap_bulk_read(data->regmap, data->chip_info->buf_status1,
> > > + &buf_status, sizeof(buf_status));
> > > + if (ret) {
> > > + dev_err(dev, "Error reading buffer status\n");
> > > + return ret;
> > > + }
> > > +
> > > + fifo_bytes = le16_to_cpu(buf_status);
> > > + fifo_bytes &= data->chip_info->buf_smp_lvl_mask;
> >
> > Slight preference for FIELD_GET() as it saves me checking the mask includes
> > lowest bits.
>
> This will mean I have the remove the chip_info member buf_smp_lvl_mask
> and use KX132_MASK_BUF_SMP_LVL directly because otherwise the
> __builtin_constant_p function will cause an error when building.
> Check: https://elixir.bootlin.com/linux/latest/source/include/linux/bitfield.h#L65
>
> I can change it to FIELD_GET() if you want to.
Good point. You could use le16_get_bits() though which I'm fairly sure will take
a variable just fine.
>
> >
> >
> > > +
> > > + return fifo_bytes;
> > > +}
> > > +
> > > static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples,
> > > bool irq)
> > > {
> > > @@ -1036,6 +1157,32 @@ const struct kx022a_chip_info kx022a_chip_info = {
> > > };
> > > EXPORT_SYMBOL_NS_GPL(kx022a_chip_info, IIO_KX022A);
> > >
> > > +const struct kx022a_chip_info kx132_chip_info = {
> > > + .name = "kx132-1211",
> > > + .regmap_config = &kx132_regmap_config,
> > > + .channels = kx132_channels,
> > > + .num_channels = ARRAY_SIZE(kx132_channels),
> > > + .fifo_length = KX132_FIFO_LENGTH,
> > > + .who = KX132_REG_WHO,
> > > + .id = KX132_ID,
> > > + .cntl = KX132_REG_CNTL,
> > > + .cntl2 = KX132_REG_CNTL2,
> > > + .odcntl = KX132_REG_ODCNTL,
> > > + .buf_cntl1 = KX132_REG_BUF_CNTL1,
> > > + .buf_cntl2 = KX132_REG_BUF_CNTL2,
> > > + .buf_clear = KX132_REG_BUF_CLEAR,
> > > + .buf_status1 = KX132_REG_BUF_STATUS_1,
> > > + .buf_smp_lvl_mask = KX132_MASK_BUF_SMP_LVL,
> >
> > There are some things in here (typically where the define isn't used
> > anywhere else) where I think it would be easier to follow if the
> > value was listed here. Masks and IDs for example.
> >
>
> After removing buf_smp_lvl_mask, which members will be easier to understand (besides id) ?
I haven't gone through them. Length seems an obvious one. It's a number not a magic value.
Register addresses might also be simpler if they aren't used elsewhere.
Not really about understanding just about a define that adds nothing if all we do is
assign it to a variable of the same name.
>
> --
> Kind Regards
> Mehdi Djait
next prev parent reply other threads:[~2023-05-06 16:31 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-24 22:22 [PATCH v3 0/7] iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer Mehdi Djait
2023-04-24 22:22 ` [PATCH v3 1/7] dt-bindings: iio: Add " Mehdi Djait
2023-04-24 22:22 ` [PATCH v3 2/7] iio: accel: kionix-kx022a: Remove blank lines Mehdi Djait
2023-04-25 5:26 ` Matti Vaittinen
2023-04-24 22:22 ` [PATCH v3 3/7] iio: accel: kionix-kx022a: Warn on failed matches and assume compatibility Mehdi Djait
2023-04-24 22:22 ` [PATCH v3 4/7] iio: accel: kionix-kx022a: Add an i2c_device_id table Mehdi Djait
2023-04-25 5:31 ` Matti Vaittinen
2023-05-01 14:42 ` Jonathan Cameron
2023-04-25 13:40 ` Andy Shevchenko
2023-04-29 13:10 ` Mehdi Djait
2023-04-24 22:22 ` [PATCH v3 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure Mehdi Djait
2023-04-25 6:50 ` Matti Vaittinen
2023-04-25 7:24 ` Mehdi Djait
2023-04-25 8:12 ` Matti Vaittinen
2023-04-29 12:59 ` Mehdi Djait
2023-04-29 13:56 ` Matti Vaittinen
2023-05-01 14:50 ` Jonathan Cameron
2023-05-07 20:45 ` Mehdi Djait
2023-05-08 6:12 ` Matti Vaittinen
2023-04-25 15:57 ` Andi Shyti
2023-04-29 13:07 ` Mehdi Djait
2023-04-30 17:49 ` Jonathan Cameron
2023-05-02 19:41 ` Andy Shevchenko
2023-05-05 18:12 ` Mehdi Djait
2023-04-24 22:22 ` [PATCH v3 6/7] iio: accel: kionix-kx022a: Add a function to retrieve number of bytes in buffer Mehdi Djait
2023-04-25 7:07 ` Matti Vaittinen
2023-04-25 7:26 ` Mehdi Djait
2023-04-24 22:22 ` [PATCH v3 7/7] iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer Mehdi Djait
2023-04-25 8:06 ` Matti Vaittinen
2023-05-01 15:04 ` Jonathan Cameron
2023-05-01 14:56 ` Jonathan Cameron
2023-05-05 18:11 ` Mehdi Djait
2023-05-06 16:46 ` Jonathan Cameron [this message]
2023-05-07 14:56 ` Mehdi Djait
2023-05-13 17:13 ` 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=20230506174651.5c5740d9@jic23-huawei \
--to=jic23@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=devicetree@vger.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=mazziesaccount@gmail.com \
--cc=mehdi.djait.k@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;
as well as URLs for NNTP newsgroup(s).