linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Use LIS3MDL with LSM6DSM sensor-hub
@ 2020-03-11 20:50 Jimmy Assarsson
  2020-03-12  8:51 ` Lorenzo Bianconi
  2020-03-14 12:43 ` Lorenzo Bianconi
  0 siblings, 2 replies; 11+ messages in thread
From: Jimmy Assarsson @ 2020-03-11 20:50 UTC (permalink / raw)
  To: Lorenzo Bianconi, linux-iio

Hi,

We are working on a project where we want to connect LS6DSM (via SPI), and
connect LIS3MDL via the sensor hub, as I2C slave device.

We would like to add settings/configuration for LIS3MDL, to the shub
source, since currently only LIS2MDL is supported. We've made an attempt,
see diff at end of this mail.

1. LIS2MDL only got a single full scale setting, hence it is not possible
    to change. While LIS3MDL got four possible settings. Is it enough to add
    a corresponding function like st_lsm6dsx_shub_set_fs_val() and call it
    from st_lsm6dsx_shub_write_raw(), when mask == IIO_CHAN_INFO_SCALE?
2. LIS3MDL got 8 possible ODR settings, however ST_LSM6DSX_ODR_LIST_SIZE is
    defined to 6 (st_lsm6dsx.h). Is it fine to increase
    ST_LSM6DSX_ODR_LIST_SIZE to 8? This will also affect odr_table in
    struct st_lsm6dsx_settings.
3. In the patch, we've tried to copy the correct registers and values from
    magnetometer/st_magn_core.c, does it look ok?

The IIO subsystem is new to use, we possibly miss fundamental knowledge.

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 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,
+		},
+	},
  };

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-03-24 14:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).