devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Jagath Jog J <jagathjog1996@gmail.com>
Cc: Matti Vaittinen <mazziesaccount@gmail.com>,
	Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Dmitry Rokosov <DDRokosov@sberdevices.ru>,
	Cosmin Tanislav <demonsingur@gmail.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 2/3] iio: accel: Support Kionix/ROHM KX022A accelerometer
Date: Wed, 18 Oct 2023 20:34:23 +0100	[thread overview]
Message-ID: <20231018203423.06f20a6c@jic23-huawei> (raw)
In-Reply-To: <CAM+2Eu+Xp6j1ppLd+zHMTu6jfc6DQKBShfe-nAyokVi0MUmoSA@mail.gmail.com>

On Wed, 18 Oct 2023 01:37:12 +0530
Jagath Jog J <jagathjog1996@gmail.com> wrote:

> Hi Matti,
> 
> On Mon, Oct 24, 2022 at 6:10 PM Matti Vaittinen
> <mazziesaccount@gmail.com> wrote:
> >
> > KX022A is a 3-axis accelerometer from ROHM/Kionix. The sensor features
> > include variable ODRs, I2C and SPI control, FIFO/LIFO with watermark IRQ,
> > tap/motion detection, wake-up & back-to-sleep events, four acceleration
> > ranges (2, 4, 8 and 16g), and probably some other cool features.  
> 
> This is a nice driver, and I found it very helpful as a reference.
> One question regarding scale please see below.
> 
> > + * range is typically +-2G/4G/8G/16G, distributed over the amount of bits.
> > + * The scale table can be calculated using
> > + *     (range / 2^bits) * g = (range / 2^bits) * 9.80665 m/s^2
> > + *     => KX022A uses 16 bit (HiRes mode - assume the low 8 bits are zeroed
> > + *     in low-power mode(?) )
> > + *     => +/-2G  => 4 / 2^16 * 9,80665 * 10^6 (to scale to micro)
> > + *     => +/-2G  - 598.550415
> > + *        +/-4G  - 1197.10083
> > + *        +/-8G  - 2394.20166
> > + *        +/-16G - 4788.40332
> > + */
> > +static const int kx022a_scale_table[][2] = {
> > +       { 598, 550415 },
> > +       { 1197, 100830 },
> > +       { 2394, 201660 },
> > +       { 4788, 403320 },
> > +};  
> 
> Given that the integer part is non-zero, and
> IIO_VAL_INT_PLUS_MICRO is returned for read_scale,
> As raw value will never be fractional how does this
> correspond to a reading of 9.8 m/s² for the Z-axis?

Definitely suspicious as should be in m/s^2 for an acceleration and
it should be

9.8*16/2^bits

So I think these are out by a factor of 10^6



> 
> > +
> > +static int kx022a_read_avail(struct iio_dev *indio_dev,
> > +                            struct iio_chan_spec const *chan,
> > +                            const int **vals, int *type, int *length,
> > +                            long mask)
> > +{
> > +       switch (mask) {
> > +       case IIO_CHAN_INFO_SAMP_FREQ:
> > +               *vals = (const int *)kx022a_accel_samp_freq_table;
> > +               *length = ARRAY_SIZE(kx022a_accel_samp_freq_table) *
> > +                         ARRAY_SIZE(kx022a_accel_samp_freq_table[0]);
> > +               *type = IIO_VAL_INT_PLUS_MICRO;
> > +               return IIO_AVAIL_LIST;
> > +       case IIO_CHAN_INFO_SCALE:
> > +               *vals = (const int *)kx022a_scale_table;
> > +               *length = ARRAY_SIZE(kx022a_scale_table) *
> > +                         ARRAY_SIZE(kx022a_scale_table[0]);
> > +               *type = IIO_VAL_INT_PLUS_MICRO;
> > +               return IIO_AVAIL_LIST;
> > +       default:
> > +               return -EINVAL;
> > +       }
> > +}  
> 
> Regards
> Jagath


  reply	other threads:[~2023-10-18 19:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-24 12:37 [PATCH v5 0/3] iio: Support ROHM/Kionix kx022a Matti Vaittinen
2022-10-24 12:40 ` [PATCH v5 1/3] dt-bindings: iio: Add KX022A accelerometer Matti Vaittinen
2022-10-24 12:40 ` [PATCH v5 2/3] iio: accel: Support Kionix/ROHM " Matti Vaittinen
2022-10-24 12:54   ` Andy Shevchenko
2022-10-24 14:14     ` Matti Vaittinen
2022-10-29 14:18   ` Jonathan Cameron
2023-10-17 20:07   ` Jagath Jog J
2023-10-18 19:34     ` Jonathan Cameron [this message]
2023-10-19  5:53       ` Matti Vaittinen
2023-10-19 11:12         ` Jonathan Cameron
2022-10-24 12:40 ` [PATCH v5 3/3] MAINTAINERS: Add KX022A maintainer entry Matti Vaittinen
2022-10-29 14:20   ` Jonathan Cameron
2022-10-31  5:40     ` Vaittinen, Matti
2022-10-29 14:23 ` [PATCH v5 0/3] iio: Support ROHM/Kionix kx022a 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=20231018203423.06f20a6c@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=DDRokosov@sberdevices.ru \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=demonsingur@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jagathjog1996@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=mazziesaccount@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).