From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Jimmy Assarsson <jimmyassarsson@gmail.com>
Cc: linux-iio@vger.kernel.org
Subject: Re: Use LIS3MDL with LSM6DSM sensor-hub
Date: Thu, 19 Mar 2020 21:49:37 +0100 [thread overview]
Message-ID: <20200319204937.GB1564882@lore-desk-wlan> (raw)
In-Reply-To: <ef4aa50f-4aa6-cb87-06b6-913e2abbb23c@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 6421 bytes --]
> On 2020-03-19 18:40, Lorenzo Bianconi wrote:
> > > On 2020-03-14 13:43, Lorenzo Bianconi wrote:
> > > > On Mar 11, Jimmy Assarsson wrote:
> > > > > Hi,
> > > > >
[...]
> > > > Hi Jimmy,
> > > >
> > > > in order to set the full scale on LIS3MDL you can try the following patch (just
> > > > compiled, not tested)
> > > >
> > > > Regards,
> > > > Lorenzo
> > >
> > > Hi Lorenzo,
> > >
> > > Sorry for the late response and thanks for the patch!
> >
> > Hi Jimmy,
> >
> > ok, I will post the patch, thx for testing.
>
> Great, you can add
> Tested-by: Jimmy Assarsson <jimmyassarsson@gmail.com>
>
> > > The patches seems to work.
> > > Are there any specific tests that we should carry out?
> > > Via the sysfs interface, we've tested reading raw values of each channel and
> > > configuring ODR and full scale.
> >
> > you can try to enable batching in the hw FIFO doing something like:
> >
> > $echo 1 > /sys/bus/iio/devices/<iio-magn>/scan_elements/in_magn_x_en
> > $echo 1 > /sys/bus/iio/devices/<iio-magn>/scan_elements/in_magn_y_en
> > $echo 1 > /sys/bus/iio/devices/<iio-magn>/scan_elements/in_magn_z_en
> > $echo 1 > /sys/bus/iio/devices/<iio-magn>/scan_elements/in_timestamp_en
> >
> > $watermark=64
> > $echo $((2*watermark)) > /sys/bus/iio/devices/<iio-magn>/buffer/length
> > $echo $watermark > /sys/bus/iio/devices/<iio-magn>/buffer/watermark
> >
> > $generic_buffer -gn lsm6dsm_magn -c <# of samples>
>
> Ok. I don't got any scan_elements nor buffer directory, for any of the devices.
> I guess it is not possible to use the FIFO without configuring any interrupt?
> We got the following dts:
> &spi1 {
> #address-cells = <1>;
> #size-cells = <0>;
> lsm6dsm@0 {
> compatible = "st,lsm6dsm";
> reg = <0x0>;
>
> spi-max-frequency = <500000>;
> st,pullups = "true";
yes, you need to provide the interrupt line doing something like (this is from
the dts on my rpi):
lsm6dsm@0 {
...
interrupt-parent = <&gpio>;
interrupts = <21 0x4>;
...
};
> };
> };
>
> I'll look into this tomorrow or in the beginning of next week, thanks for the help.
>
> Regards,
> jimmy
>
> >
> > Regards,
> > Lorenzo
> >
> > >
> > > Regards,
> > > jimmy
> > >
> > > > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > > > index 64ef07a30726..fec1dbd5f00d 100644
> > > > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > > > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > > > @@ -518,6 +518,36 @@ st_lsm6dsx_shub_read_raw(struct iio_dev *iio_dev,
> > > > return ret;
> > > > }
> > > > +static int
> > > > +st_lsm6dsx_shub_set_full_scale(struct st_lsm6dsx_sensor *sensor,
> > > > + u32 gain)
> > > > +{
> > > > + const struct st_lsm6dsx_fs_table_entry *fs_table;
> > > > + int i, err;
> > > > +
> > > > + fs_table = &sensor->ext_info.settings->fs_table;
> > > > + if (!fs_table->reg.addr)
> > > > + return -ENOTSUPP;
> > > > +
> > > > + for (i = 0; i < fs_table->fs_len; i++) {
> > > > + if (fs_table->fs_avl[i].gain == gain)
> > > > + break;
> > > > + }
> > > > +
> > > > + if (i == fs_table->fs_len)
> > > > + return -EINVAL;
> > > > +
> > > > + err = st_lsm6dsx_shub_write_with_mask(sensor, fs_table->reg.addr,
> > > > + fs_table->reg.mask,
> > > > + fs_table->fs_avl[i].val);
> > > > + if (err < 0)
> > > > + return err;
> > > > +
> > > > + sensor->gain = gain;
> > > > +
> > > > + return 0;
> > > > +}
> > > > +
> > > > static int
> > > > st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
> > > > struct iio_chan_spec const *chan,
> > > > @@ -552,6 +582,9 @@ st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
> > > > }
> > > > break;
> > > > }
> > > > + case IIO_CHAN_INFO_SCALE:
> > > > + err = st_lsm6dsx_shub_set_full_scale(sensor, val2);
> > > > + break;
> > > > default:
> > > > err = -EINVAL;
> > > > break;
> > > >
> > > > >
> > > > > ---
> > > > > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > > > > index eea5556..8621dba 100644
> > > > > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > > > > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > > > > @@ -88,6 +88,69 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = {
> > > > > .len = 6,
> > > > > },
> > > > > },
> > > > > + /* LIS3MDL */
> > > > > + {
> > > > > + .i2c_addr = { 0x1e },
> > > > > + .wai = {
> > > > > + .addr = 0x0f,
> > > > > + .val = 0x3d,
> > > > > + },
> > > > > + .id = ST_LSM6DSX_ID_MAGN,
> > > > > + .odr_table = {
> > > > > + .reg = {
> > > > > + .addr = 0x20,
> > > > > + .mask = GENMASK(4, 2),
> > > > > + },
> > > > > + .odr_avl[0] = { 1000, 0x0 },
> > > > > + .odr_avl[1] = { 2000, 0x1 },
> > > > > + .odr_avl[2] = { 3000, 0x2 },
> > > > > + .odr_avl[3] = { 5000, 0x3 },
> > > > > + .odr_avl[4] = { 10000, 0x4 },
> > > > > + .odr_avl[5] = { 20000, 0x5 },
> > > > > + .odr_avl[6] = { 40000, 0x6 },
> > > > > + .odr_avl[7] = { 80000, 0x7 },
> > > > > + .odr_len = 8,
> > > > > + },
> > > > > + .fs_table = {
> > > > > + .reg = {
> > > > > + .addr = 0x21,
> > > > > + .mask = GENMASK(6, 5),
> > > > > + },
> > > > > + .fs_avl[0] = {
> > > > > + .gain = 146,
> > > > > + .val = 0x00,
> > > > > + }, /* 4000 uG/LSB */
> > > > > + .fs_avl[1] = {
> > > > > + .gain = 292,
> > > > > + .val = 0x01,
> > > > > + }, /* 8000 uG/LSB */
> > > > > + .fs_avl[2] = {
> > > > > + .gain = 438,
> > > > > + .val = 0x02,
> > > > > + }, /* 12000 uG/LSB */
> > > > > + .fs_avl[3] = {
> > > > > + .gain = 584,
> > > > > + .val = 0x03,
> > > > > + }, /* 16000 uG/LSB */
> > > > > + .fs_len = 4,
> > > > > + },
> > > > > + .pwr_table = {
> > > > > + .reg = {
> > > > > + .addr = 0x22,
> > > > > + .mask = GENMASK(1, 0),
> > > > > + },
> > > > > + .off_val = 0x2,
> > > > > + .on_val = 0x0,
> > > > > + },
> > > > > + .bdu = {
> > > > > + .addr = 0x24,
> > > > > + .mask = BIT(6),
> > > > > + },
> > > > > + .out = {
> > > > > + .addr = 0x28,
> > > > > + .len = 6,
> > > > > + },
> > > > > + },
> > > > > };
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2020-03-19 20:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-11 20:50 Use LIS3MDL with LSM6DSM sensor-hub Jimmy Assarsson
2020-03-12 8:51 ` Lorenzo Bianconi
2020-03-14 12:43 ` Lorenzo Bianconi
2020-03-19 14:41 ` Jimmy Assarsson
2020-03-19 17:40 ` Lorenzo Bianconi
2020-03-19 18:45 ` Jimmy Assarsson
2020-03-19 20:49 ` Lorenzo Bianconi [this message]
2020-03-23 15:21 ` Jimmy Assarsson
2020-03-24 8:20 ` Lorenzo Bianconi
2020-03-24 13:47 ` Jimmy Assarsson
2020-03-24 14:09 ` Lorenzo Bianconi
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=20200319204937.GB1564882@lore-desk-wlan \
--to=lorenzo@kernel.org \
--cc=jimmyassarsson@gmail.com \
--cc=linux-iio@vger.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