1 // SPDX-License-Identifier: GPL-2.0-only
3 * STMicroelectronics st_lsm6dsx sensor driver
5 * The ST LSM6DSx IMU MEMS series consists of 3D digital accelerometer
6 * and 3D digital gyroscope system-in-package with a digital I2C/SPI serial
7 * interface standard output.
8 * LSM6DSx IMU MEMS series has a dynamic user-selectable full-scale
9 * acceleration range of +-2/+-4/+-8/+-16 g and an angular rate range of
10 * +-125/+-245/+-500/+-1000/+-2000 dps
11 * LSM6DSx series has an integrated First-In-First-Out (FIFO) buffer
12 * allowing dynamic batching of sensor data.
13 * LSM9DSx series is similar but includes an additional magnetometer, handled
14 * by a different driver.
19 * - Accelerometer/Gyroscope supported ODR [Hz]: 12.5, 26, 52, 104, 208, 416
20 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16
21 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000
29 * - Accelerometer/Gyroscope supported ODR [Hz]: 12.5, 26, 52, 104, 208, 416
30 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16
31 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000
46 * - Accelerometer/Gyroscope supported ODR [Hz]: 12.5, 26, 52, 104, 208, 416,
48 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16
49 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000
54 * - Accelerometer/Gyroscope supported ODR [Hz]: 7.5, 15, 30, 60, 120, 240,
56 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16
57 * - Gyroscope supported full-scale [dps]: +-125/+-250/+-500/+-1000/+-2000
62 * - Accelerometer supported ODR [Hz]: 10, 50, 119, 238, 476, 952
63 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16
64 * - Gyroscope supported ODR [Hz]: 15, 60, 119, 238, 476, 952
65 * - Gyroscope supported full-scale [dps]: +-245/+-500/+-2000
68 * Copyright 2016 STMicroelectronics Inc.
70 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
71 * Denis Ciocca <denis.ciocca@st.com>
74 #include <linux/kernel.h>
75 #include <linux/module.h>
76 #include <linux/acpi.h>
77 #include <linux/delay.h>
78 #include <linux/iio/events.h>
79 #include <linux/iio/iio.h>
80 #include <linux/iio/sysfs.h>
81 #include <linux/iio/triggered_buffer.h>
82 #include <linux/iio/trigger_consumer.h>
83 #include <linux/interrupt.h>
84 #include <linux/irq.h>
85 #include <linux/minmax.h>
87 #include <linux/property.h>
88 #include <linux/regmap.h>
89 #include <linux/bitfield.h>
91 #include <linux/platform_data/st_sensors_pdata.h>
93 #include "st_lsm6dsx.h"
95 #define ST_LSM6DSX_REG_WHOAMI_ADDR 0x0f
97 #define ST_LSM6DSX_TS_SENSITIVITY 25000UL /* 25us */
99 static const struct iio_chan_spec st_lsm6dsx_acc_channels
[] = {
100 ST_LSM6DSX_CHANNEL_ACC(IIO_ACCEL
, 0x28, IIO_MOD_X
, 0),
101 ST_LSM6DSX_CHANNEL_ACC(IIO_ACCEL
, 0x2a, IIO_MOD_Y
, 1),
102 ST_LSM6DSX_CHANNEL_ACC(IIO_ACCEL
, 0x2c, IIO_MOD_Z
, 2),
103 IIO_CHAN_SOFT_TIMESTAMP(3),
106 static const struct iio_chan_spec st_lsm6dsx_gyro_channels
[] = {
107 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL
, 0x22, IIO_MOD_X
, 0),
108 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL
, 0x24, IIO_MOD_Y
, 1),
109 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL
, 0x26, IIO_MOD_Z
, 2),
110 IIO_CHAN_SOFT_TIMESTAMP(3),
113 static const struct iio_chan_spec st_lsm6ds0_gyro_channels
[] = {
114 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL
, 0x18, IIO_MOD_X
, 0),
115 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL
, 0x1a, IIO_MOD_Y
, 1),
116 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL
, 0x1c, IIO_MOD_Z
, 2),
117 IIO_CHAN_SOFT_TIMESTAMP(3),
120 static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings
[] = {
136 .hw_id
= ST_LSM9DS1_ID
,
137 .name
= ST_LSM9DS1_DEV_NAME
,
140 .hw_id
= ST_LSM6DS0_ID
,
141 .name
= ST_LSM6DS0_DEV_NAME
,
146 [ST_LSM6DSX_ID_ACC
] = {
147 .chan
= st_lsm6dsx_acc_channels
,
148 .len
= ARRAY_SIZE(st_lsm6dsx_acc_channels
),
150 [ST_LSM6DSX_ID_GYRO
] = {
151 .chan
= st_lsm6ds0_gyro_channels
,
152 .len
= ARRAY_SIZE(st_lsm6ds0_gyro_channels
),
156 [ST_LSM6DSX_ID_ACC
] = {
159 .mask
= GENMASK(7, 5),
161 .odr_avl
[0] = { 10000, 0x01 },
162 .odr_avl
[1] = { 50000, 0x02 },
163 .odr_avl
[2] = { 119000, 0x03 },
164 .odr_avl
[3] = { 238000, 0x04 },
165 .odr_avl
[4] = { 476000, 0x05 },
166 .odr_avl
[5] = { 952000, 0x06 },
169 [ST_LSM6DSX_ID_GYRO
] = {
172 .mask
= GENMASK(7, 5),
174 .odr_avl
[0] = { 14900, 0x01 },
175 .odr_avl
[1] = { 59500, 0x02 },
176 .odr_avl
[2] = { 119000, 0x03 },
177 .odr_avl
[3] = { 238000, 0x04 },
178 .odr_avl
[4] = { 476000, 0x05 },
179 .odr_avl
[5] = { 952000, 0x06 },
184 [ST_LSM6DSX_ID_ACC
] = {
187 .mask
= GENMASK(4, 3),
189 .fs_avl
[0] = { IIO_G_TO_M_S_2(61000), 0x0 },
190 .fs_avl
[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
191 .fs_avl
[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
192 .fs_avl
[3] = { IIO_G_TO_M_S_2(732000), 0x1 },
195 [ST_LSM6DSX_ID_GYRO
] = {
198 .mask
= GENMASK(4, 3),
201 .fs_avl
[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 },
202 .fs_avl
[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
203 .fs_avl
[2] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
244 .hw_id
= ST_LSM6DS3_ID
,
245 .name
= ST_LSM6DS3_DEV_NAME
,
250 [ST_LSM6DSX_ID_ACC
] = {
251 .chan
= st_lsm6dsx_acc_channels
,
252 .len
= ARRAY_SIZE(st_lsm6dsx_acc_channels
),
254 [ST_LSM6DSX_ID_GYRO
] = {
255 .chan
= st_lsm6dsx_gyro_channels
,
256 .len
= ARRAY_SIZE(st_lsm6dsx_gyro_channels
),
260 [ST_LSM6DSX_ID_ACC
] = {
263 .mask
= GENMASK(7, 4),
265 .odr_avl
[0] = { 12500, 0x01 },
266 .odr_avl
[1] = { 26000, 0x02 },
267 .odr_avl
[2] = { 52000, 0x03 },
268 .odr_avl
[3] = { 104000, 0x04 },
269 .odr_avl
[4] = { 208000, 0x05 },
270 .odr_avl
[5] = { 416000, 0x06 },
273 [ST_LSM6DSX_ID_GYRO
] = {
276 .mask
= GENMASK(7, 4),
278 .odr_avl
[0] = { 12500, 0x01 },
279 .odr_avl
[1] = { 26000, 0x02 },
280 .odr_avl
[2] = { 52000, 0x03 },
281 .odr_avl
[3] = { 104000, 0x04 },
282 .odr_avl
[4] = { 208000, 0x05 },
283 .odr_avl
[5] = { 416000, 0x06 },
288 [ST_LSM6DSX_ID_ACC
] = {
291 .mask
= GENMASK(3, 2),
293 .fs_avl
[0] = { IIO_G_TO_M_S_2(61000), 0x0 },
294 .fs_avl
[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
295 .fs_avl
[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
296 .fs_avl
[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
299 [ST_LSM6DSX_ID_GYRO
] = {
302 .mask
= GENMASK(3, 2),
304 .fs_avl
[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 },
305 .fs_avl
[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
306 .fs_avl
[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
307 .fs_avl
[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
342 [ST_LSM6DSX_ID_ACC
] = {
344 .mask
= GENMASK(2, 0),
346 [ST_LSM6DSX_ID_GYRO
] = {
348 .mask
= GENMASK(5, 3),
352 .update_fifo
= st_lsm6dsx_update_fifo
,
353 .read_fifo
= st_lsm6dsx_read_fifo
,
356 .mask
= GENMASK(11, 0),
360 .mask
= GENMASK(11, 0),
363 .th_wl
= 3, /* 1LSB = 2B */
380 .mask
= GENMASK(5, 3),
386 .mask
= GENMASK(5, 0),
388 .wakeup_src_reg
= 0x1b,
389 .wakeup_src_status_mask
= BIT(3),
390 .wakeup_src_z_mask
= BIT(0),
391 .wakeup_src_y_mask
= BIT(1),
392 .wakeup_src_x_mask
= BIT(2),
410 .hw_id
= ST_LSM6DS3H_ID
,
411 .name
= ST_LSM6DS3H_DEV_NAME
,
416 [ST_LSM6DSX_ID_ACC
] = {
417 .chan
= st_lsm6dsx_acc_channels
,
418 .len
= ARRAY_SIZE(st_lsm6dsx_acc_channels
),
420 [ST_LSM6DSX_ID_GYRO
] = {
421 .chan
= st_lsm6dsx_gyro_channels
,
422 .len
= ARRAY_SIZE(st_lsm6dsx_gyro_channels
),
426 [ST_LSM6DSX_ID_ACC
] = {
429 .mask
= GENMASK(7, 4),
431 .odr_avl
[0] = { 12500, 0x01 },
432 .odr_avl
[1] = { 26000, 0x02 },
433 .odr_avl
[2] = { 52000, 0x03 },
434 .odr_avl
[3] = { 104000, 0x04 },
435 .odr_avl
[4] = { 208000, 0x05 },
436 .odr_avl
[5] = { 416000, 0x06 },
439 [ST_LSM6DSX_ID_GYRO
] = {
442 .mask
= GENMASK(7, 4),
444 .odr_avl
[0] = { 12500, 0x01 },
445 .odr_avl
[1] = { 26000, 0x02 },
446 .odr_avl
[2] = { 52000, 0x03 },
447 .odr_avl
[3] = { 104000, 0x04 },
448 .odr_avl
[4] = { 208000, 0x05 },
449 .odr_avl
[5] = { 416000, 0x06 },
454 [ST_LSM6DSX_ID_ACC
] = {
457 .mask
= GENMASK(3, 2),
459 .fs_avl
[0] = { IIO_G_TO_M_S_2(61000), 0x0 },
460 .fs_avl
[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
461 .fs_avl
[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
462 .fs_avl
[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
465 [ST_LSM6DSX_ID_GYRO
] = {
468 .mask
= GENMASK(3, 2),
470 .fs_avl
[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 },
471 .fs_avl
[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
472 .fs_avl
[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
473 .fs_avl
[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
508 [ST_LSM6DSX_ID_ACC
] = {
510 .mask
= GENMASK(2, 0),
512 [ST_LSM6DSX_ID_GYRO
] = {
514 .mask
= GENMASK(5, 3),
518 .update_fifo
= st_lsm6dsx_update_fifo
,
519 .read_fifo
= st_lsm6dsx_read_fifo
,
522 .mask
= GENMASK(11, 0),
526 .mask
= GENMASK(11, 0),
529 .th_wl
= 3, /* 1LSB = 2B */
546 .mask
= GENMASK(5, 3),
552 .mask
= GENMASK(5, 0),
554 .wakeup_src_reg
= 0x1b,
555 .wakeup_src_status_mask
= BIT(3),
556 .wakeup_src_z_mask
= BIT(0),
557 .wakeup_src_y_mask
= BIT(1),
558 .wakeup_src_x_mask
= BIT(2),
576 .hw_id
= ST_LSM6DSL_ID
,
577 .name
= ST_LSM6DSL_DEV_NAME
,
580 .hw_id
= ST_LSM6DSM_ID
,
581 .name
= ST_LSM6DSM_DEV_NAME
,
584 .hw_id
= ST_ISM330DLC_ID
,
585 .name
= ST_ISM330DLC_DEV_NAME
,
588 .hw_id
= ST_LSM6DS3TRC_ID
,
589 .name
= ST_LSM6DS3TRC_DEV_NAME
,
594 [ST_LSM6DSX_ID_ACC
] = {
595 .chan
= st_lsm6dsx_acc_channels
,
596 .len
= ARRAY_SIZE(st_lsm6dsx_acc_channels
),
598 [ST_LSM6DSX_ID_GYRO
] = {
599 .chan
= st_lsm6dsx_gyro_channels
,
600 .len
= ARRAY_SIZE(st_lsm6dsx_gyro_channels
),
604 [ST_LSM6DSX_ID_ACC
] = {
607 .mask
= GENMASK(7, 4),
609 .odr_avl
[0] = { 12500, 0x01 },
610 .odr_avl
[1] = { 26000, 0x02 },
611 .odr_avl
[2] = { 52000, 0x03 },
612 .odr_avl
[3] = { 104000, 0x04 },
613 .odr_avl
[4] = { 208000, 0x05 },
614 .odr_avl
[5] = { 416000, 0x06 },
617 [ST_LSM6DSX_ID_GYRO
] = {
620 .mask
= GENMASK(7, 4),
622 .odr_avl
[0] = { 12500, 0x01 },
623 .odr_avl
[1] = { 26000, 0x02 },
624 .odr_avl
[2] = { 52000, 0x03 },
625 .odr_avl
[3] = { 104000, 0x04 },
626 .odr_avl
[4] = { 208000, 0x05 },
627 .odr_avl
[5] = { 416000, 0x06 },
632 [ST_LSM6DSX_ID_ACC
] = {
635 .mask
= GENMASK(3, 2),
637 .fs_avl
[0] = { IIO_G_TO_M_S_2(61000), 0x0 },
638 .fs_avl
[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
639 .fs_avl
[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
640 .fs_avl
[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
643 [ST_LSM6DSX_ID_GYRO
] = {
646 .mask
= GENMASK(3, 2),
648 .fs_avl
[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 },
649 .fs_avl
[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
650 .fs_avl
[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
651 .fs_avl
[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
655 .samples_to_discard
= {
656 [ST_LSM6DSX_ID_ACC
] = {
657 .val
[0] = { 12500, 1 },
658 .val
[1] = { 26000, 1 },
659 .val
[2] = { 52000, 1 },
660 .val
[3] = { 104000, 2 },
661 .val
[4] = { 208000, 2 },
662 .val
[5] = { 416000, 2 },
664 [ST_LSM6DSX_ID_GYRO
] = {
665 .val
[0] = { 12500, 2 },
666 .val
[1] = { 26000, 5 },
667 .val
[2] = { 52000, 7 },
668 .val
[3] = { 104000, 12 },
669 .val
[4] = { 208000, 20 },
670 .val
[5] = { 416000, 36 },
704 [ST_LSM6DSX_ID_ACC
] = {
706 .mask
= GENMASK(2, 0),
708 [ST_LSM6DSX_ID_GYRO
] = {
710 .mask
= GENMASK(5, 3),
712 [ST_LSM6DSX_ID_EXT0
] = {
714 .mask
= GENMASK(2, 0),
718 .update_fifo
= st_lsm6dsx_update_fifo
,
719 .read_fifo
= st_lsm6dsx_read_fifo
,
722 .mask
= GENMASK(10, 0),
726 .mask
= GENMASK(10, 0),
729 .th_wl
= 3, /* 1LSB = 2B */
746 .mask
= GENMASK(5, 3),
764 .mask
= GENMASK(5, 4),
779 .dw_slv0_addr
= 0x0e,
789 .mask
= GENMASK(5, 0),
791 .wakeup_src_reg
= 0x1b,
792 .wakeup_src_status_mask
= BIT(3),
793 .wakeup_src_z_mask
= BIT(0),
794 .wakeup_src_y_mask
= BIT(1),
795 .wakeup_src_x_mask
= BIT(2),
813 .hw_id
= ST_LSM6DSR_ID
,
814 .name
= ST_LSM6DSR_DEV_NAME
,
817 .hw_id
= ST_ISM330DHCX_ID
,
818 .name
= ST_ISM330DHCX_DEV_NAME
,
821 .hw_id
= ST_LSM6DSRX_ID
,
822 .name
= ST_LSM6DSRX_DEV_NAME
,
825 .hw_id
= ST_LSM6DSO_ID
,
826 .name
= ST_LSM6DSO_DEV_NAME
,
829 .hw_id
= ST_LSM6DSOX_ID
,
830 .name
= ST_LSM6DSOX_DEV_NAME
,
833 .hw_id
= ST_LSM6DST_ID
,
834 .name
= ST_LSM6DST_DEV_NAME
,
837 .hw_id
= ST_ASM330LHHX_ID
,
838 .name
= ST_ASM330LHHX_DEV_NAME
,
841 .hw_id
= ST_ASM330LHHXG1_ID
,
842 .name
= ST_ASM330LHHXG1_DEV_NAME
,
845 .hw_id
= ST_LSM6DSTX_ID
,
846 .name
= ST_LSM6DSTX_DEV_NAME
,
851 [ST_LSM6DSX_ID_ACC
] = {
852 .chan
= st_lsm6dsx_acc_channels
,
853 .len
= ARRAY_SIZE(st_lsm6dsx_acc_channels
),
855 [ST_LSM6DSX_ID_GYRO
] = {
856 .chan
= st_lsm6dsx_gyro_channels
,
857 .len
= ARRAY_SIZE(st_lsm6dsx_gyro_channels
),
865 [ST_LSM6DSX_ID_ACC
] = {
868 .mask
= GENMASK(7, 4),
870 .odr_avl
[0] = { 12500, 0x01 },
871 .odr_avl
[1] = { 26000, 0x02 },
872 .odr_avl
[2] = { 52000, 0x03 },
873 .odr_avl
[3] = { 104000, 0x04 },
874 .odr_avl
[4] = { 208000, 0x05 },
875 .odr_avl
[5] = { 416000, 0x06 },
876 .odr_avl
[6] = { 833000, 0x07 },
879 [ST_LSM6DSX_ID_GYRO
] = {
882 .mask
= GENMASK(7, 4),
884 .odr_avl
[0] = { 12500, 0x01 },
885 .odr_avl
[1] = { 26000, 0x02 },
886 .odr_avl
[2] = { 52000, 0x03 },
887 .odr_avl
[3] = { 104000, 0x04 },
888 .odr_avl
[4] = { 208000, 0x05 },
889 .odr_avl
[5] = { 416000, 0x06 },
890 .odr_avl
[6] = { 833000, 0x07 },
895 [ST_LSM6DSX_ID_ACC
] = {
898 .mask
= GENMASK(3, 2),
900 .fs_avl
[0] = { IIO_G_TO_M_S_2(61000), 0x0 },
901 .fs_avl
[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
902 .fs_avl
[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
903 .fs_avl
[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
906 [ST_LSM6DSX_ID_GYRO
] = {
909 .mask
= GENMASK(3, 2),
911 .fs_avl
[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 },
912 .fs_avl
[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
913 .fs_avl
[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
914 .fs_avl
[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
953 [ST_LSM6DSX_ID_ACC
] = {
955 .mask
= GENMASK(3, 0),
957 [ST_LSM6DSX_ID_GYRO
] = {
959 .mask
= GENMASK(7, 4),
963 .update_fifo
= st_lsm6dsx_update_fifo
,
964 .read_fifo
= st_lsm6dsx_read_tagged_fifo
,
967 .mask
= GENMASK(8, 0),
971 .mask
= GENMASK(9, 0),
983 .mask
= GENMASK(7, 6),
1004 .mask
= GENMASK(1, 0),
1016 .dw_slv0_addr
= 0x21,
1026 .mask
= GENMASK(5, 0),
1028 .wakeup_src_reg
= 0x1b,
1029 .wakeup_src_status_mask
= BIT(3),
1030 .wakeup_src_z_mask
= BIT(0),
1031 .wakeup_src_y_mask
= BIT(1),
1032 .wakeup_src_x_mask
= BIT(2),
1050 .hw_id
= ST_ASM330LHH_ID
,
1051 .name
= ST_ASM330LHH_DEV_NAME
,
1054 .hw_id
= ST_LSM6DSOP_ID
,
1055 .name
= ST_LSM6DSOP_DEV_NAME
,
1058 .hw_id
= ST_ASM330LHB_ID
,
1059 .name
= ST_ASM330LHB_DEV_NAME
,
1064 [ST_LSM6DSX_ID_ACC
] = {
1065 .chan
= st_lsm6dsx_acc_channels
,
1066 .len
= ARRAY_SIZE(st_lsm6dsx_acc_channels
),
1068 [ST_LSM6DSX_ID_GYRO
] = {
1069 .chan
= st_lsm6dsx_gyro_channels
,
1070 .len
= ARRAY_SIZE(st_lsm6dsx_gyro_channels
),
1078 [ST_LSM6DSX_ID_ACC
] = {
1081 .mask
= GENMASK(7, 4),
1083 .odr_avl
[0] = { 12500, 0x01 },
1084 .odr_avl
[1] = { 26000, 0x02 },
1085 .odr_avl
[2] = { 52000, 0x03 },
1086 .odr_avl
[3] = { 104000, 0x04 },
1087 .odr_avl
[4] = { 208000, 0x05 },
1088 .odr_avl
[5] = { 416000, 0x06 },
1089 .odr_avl
[6] = { 833000, 0x07 },
1092 [ST_LSM6DSX_ID_GYRO
] = {
1095 .mask
= GENMASK(7, 4),
1097 .odr_avl
[0] = { 12500, 0x01 },
1098 .odr_avl
[1] = { 26000, 0x02 },
1099 .odr_avl
[2] = { 52000, 0x03 },
1100 .odr_avl
[3] = { 104000, 0x04 },
1101 .odr_avl
[4] = { 208000, 0x05 },
1102 .odr_avl
[5] = { 416000, 0x06 },
1103 .odr_avl
[6] = { 833000, 0x07 },
1108 [ST_LSM6DSX_ID_ACC
] = {
1111 .mask
= GENMASK(3, 2),
1113 .fs_avl
[0] = { IIO_G_TO_M_S_2(61000), 0x0 },
1114 .fs_avl
[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
1115 .fs_avl
[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
1116 .fs_avl
[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
1119 [ST_LSM6DSX_ID_GYRO
] = {
1122 .mask
= GENMASK(3, 2),
1124 .fs_avl
[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 },
1125 .fs_avl
[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
1126 .fs_avl
[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
1127 .fs_avl
[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
1166 [ST_LSM6DSX_ID_ACC
] = {
1168 .mask
= GENMASK(3, 0),
1170 [ST_LSM6DSX_ID_GYRO
] = {
1172 .mask
= GENMASK(7, 4),
1176 .update_fifo
= st_lsm6dsx_update_fifo
,
1177 .read_fifo
= st_lsm6dsx_read_tagged_fifo
,
1180 .mask
= GENMASK(8, 0),
1184 .mask
= GENMASK(9, 0),
1196 .mask
= GENMASK(7, 6),
1207 .mask
= GENMASK(5, 0),
1209 .wakeup_src_reg
= 0x1b,
1210 .wakeup_src_status_mask
= BIT(3),
1211 .wakeup_src_z_mask
= BIT(0),
1212 .wakeup_src_y_mask
= BIT(1),
1213 .wakeup_src_x_mask
= BIT(2),
1231 .hw_id
= ST_LSM6DSV_ID
,
1232 .name
= ST_LSM6DSV_DEV_NAME
,
1235 .hw_id
= ST_LSM6DSV16X_ID
,
1236 .name
= ST_LSM6DSV16X_DEV_NAME
,
1241 [ST_LSM6DSX_ID_ACC
] = {
1242 .chan
= st_lsm6dsx_acc_channels
,
1243 .len
= ARRAY_SIZE(st_lsm6dsx_acc_channels
),
1245 [ST_LSM6DSX_ID_GYRO
] = {
1246 .chan
= st_lsm6dsx_gyro_channels
,
1247 .len
= ARRAY_SIZE(st_lsm6dsx_gyro_channels
),
1255 [ST_LSM6DSX_ID_ACC
] = {
1258 .mask
= GENMASK(3, 0),
1260 .odr_avl
[0] = { 7500, 0x02 },
1261 .odr_avl
[1] = { 15000, 0x03 },
1262 .odr_avl
[2] = { 30000, 0x04 },
1263 .odr_avl
[3] = { 60000, 0x05 },
1264 .odr_avl
[4] = { 120000, 0x06 },
1265 .odr_avl
[5] = { 240000, 0x07 },
1266 .odr_avl
[6] = { 480000, 0x08 },
1267 .odr_avl
[7] = { 960000, 0x09 },
1270 [ST_LSM6DSX_ID_GYRO
] = {
1273 .mask
= GENMASK(3, 0),
1275 .odr_avl
[0] = { 7500, 0x02 },
1276 .odr_avl
[1] = { 15000, 0x03 },
1277 .odr_avl
[2] = { 30000, 0x04 },
1278 .odr_avl
[3] = { 60000, 0x05 },
1279 .odr_avl
[4] = { 120000, 0x06 },
1280 .odr_avl
[5] = { 240000, 0x07 },
1281 .odr_avl
[6] = { 480000, 0x08 },
1282 .odr_avl
[7] = { 960000, 0x09 },
1287 [ST_LSM6DSX_ID_ACC
] = {
1290 .mask
= GENMASK(1, 0),
1292 .fs_avl
[0] = { IIO_G_TO_M_S_2(61000), 0x0 },
1293 .fs_avl
[1] = { IIO_G_TO_M_S_2(122000), 0x1 },
1294 .fs_avl
[2] = { IIO_G_TO_M_S_2(244000), 0x2 },
1295 .fs_avl
[3] = { IIO_G_TO_M_S_2(488000), 0x3 },
1298 [ST_LSM6DSX_ID_GYRO
] = {
1301 .mask
= GENMASK(3, 0),
1303 .fs_avl
[0] = { IIO_DEGREE_TO_RAD(8750000), 0x1 },
1304 .fs_avl
[1] = { IIO_DEGREE_TO_RAD(17500000), 0x2 },
1305 .fs_avl
[2] = { IIO_DEGREE_TO_RAD(35000000), 0x3 },
1306 .fs_avl
[3] = { IIO_DEGREE_TO_RAD(70000000), 0x4 },
1341 [ST_LSM6DSX_ID_ACC
] = {
1343 .mask
= GENMASK(3, 0),
1345 [ST_LSM6DSX_ID_GYRO
] = {
1347 .mask
= GENMASK(7, 4),
1351 .update_fifo
= st_lsm6dsx_update_fifo
,
1352 .read_fifo
= st_lsm6dsx_read_tagged_fifo
,
1355 .mask
= GENMASK(7, 0),
1359 .mask
= GENMASK(8, 0),
1371 .mask
= GENMASK(7, 6),
1391 .mask
= GENMASK(1, 0),
1403 .dw_slv0_addr
= 0x21,
1413 .mask
= GENMASK(5, 0),
1415 .wakeup_src_reg
= 0x45,
1416 .wakeup_src_status_mask
= BIT(3),
1417 .wakeup_src_z_mask
= BIT(0),
1418 .wakeup_src_y_mask
= BIT(1),
1419 .wakeup_src_x_mask
= BIT(2),
1437 .hw_id
= ST_LSM6DSO16IS_ID
,
1438 .name
= ST_LSM6DSO16IS_DEV_NAME
,
1441 .hw_id
= ST_ISM330IS_ID
,
1442 .name
= ST_ISM330IS_DEV_NAME
,
1447 [ST_LSM6DSX_ID_ACC
] = {
1448 .chan
= st_lsm6dsx_acc_channels
,
1449 .len
= ARRAY_SIZE(st_lsm6dsx_acc_channels
),
1451 [ST_LSM6DSX_ID_GYRO
] = {
1452 .chan
= st_lsm6dsx_gyro_channels
,
1453 .len
= ARRAY_SIZE(st_lsm6dsx_gyro_channels
),
1457 [ST_LSM6DSX_ID_ACC
] = {
1460 .mask
= GENMASK(7, 4),
1462 .odr_avl
[0] = { 12500, 0x01 },
1463 .odr_avl
[1] = { 26000, 0x02 },
1464 .odr_avl
[2] = { 52000, 0x03 },
1465 .odr_avl
[3] = { 104000, 0x04 },
1466 .odr_avl
[4] = { 208000, 0x05 },
1467 .odr_avl
[5] = { 416000, 0x06 },
1468 .odr_avl
[6] = { 833000, 0x07 },
1471 [ST_LSM6DSX_ID_GYRO
] = {
1474 .mask
= GENMASK(7, 4),
1476 .odr_avl
[0] = { 12500, 0x01 },
1477 .odr_avl
[1] = { 26000, 0x02 },
1478 .odr_avl
[2] = { 52000, 0x03 },
1479 .odr_avl
[3] = { 104000, 0x04 },
1480 .odr_avl
[4] = { 208000, 0x05 },
1481 .odr_avl
[5] = { 416000, 0x06 },
1482 .odr_avl
[6] = { 833000, 0x07 },
1487 [ST_LSM6DSX_ID_ACC
] = {
1490 .mask
= GENMASK(3, 2),
1492 .fs_avl
[0] = { IIO_G_TO_M_S_2(61000), 0x0 },
1493 .fs_avl
[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
1494 .fs_avl
[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
1495 .fs_avl
[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
1498 [ST_LSM6DSX_ID_GYRO
] = {
1501 .mask
= GENMASK(3, 2),
1503 .fs_avl
[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 },
1504 .fs_avl
[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
1505 .fs_avl
[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
1506 .fs_avl
[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
1537 .mask
= GENMASK(1, 0),
1549 .dw_slv0_addr
= 0x21,
1554 int st_lsm6dsx_set_page(struct st_lsm6dsx_hw
*hw
, bool enable
)
1556 const struct st_lsm6dsx_shub_settings
*hub_settings
;
1560 hub_settings
= &hw
->settings
->shub_settings
;
1561 data
= ST_LSM6DSX_SHIFT_VAL(enable
, hub_settings
->page_mux
.mask
);
1562 err
= regmap_update_bits(hw
->regmap
, hub_settings
->page_mux
.addr
,
1563 hub_settings
->page_mux
.mask
, data
);
1564 usleep_range(100, 150);
1569 static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw
*hw
, int id
,
1572 int err
, i
, j
, data
;
1574 for (i
= 0; i
< ARRAY_SIZE(st_lsm6dsx_sensor_settings
); i
++) {
1575 for (j
= 0; j
< ST_LSM6DSX_MAX_ID
; j
++) {
1576 if (st_lsm6dsx_sensor_settings
[i
].id
[j
].name
&&
1577 id
== st_lsm6dsx_sensor_settings
[i
].id
[j
].hw_id
)
1580 if (j
< ST_LSM6DSX_MAX_ID
)
1584 if (i
== ARRAY_SIZE(st_lsm6dsx_sensor_settings
)) {
1585 dev_err(hw
->dev
, "unsupported hw id [%02x]\n", id
);
1589 err
= regmap_read(hw
->regmap
, ST_LSM6DSX_REG_WHOAMI_ADDR
, &data
);
1591 dev_err(hw
->dev
, "failed to read whoami register\n");
1595 if (data
!= st_lsm6dsx_sensor_settings
[i
].id
[j
].wai
) {
1596 dev_err(hw
->dev
, "unsupported whoami [%02x]\n", data
);
1600 *name
= st_lsm6dsx_sensor_settings
[i
].id
[j
].name
;
1601 hw
->settings
= &st_lsm6dsx_sensor_settings
[i
];
1606 static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor
*sensor
,
1609 const struct st_lsm6dsx_fs_table_entry
*fs_table
;
1613 fs_table
= &sensor
->hw
->settings
->fs_table
[sensor
->id
];
1614 for (i
= 0; i
< fs_table
->fs_len
; i
++) {
1615 if (fs_table
->fs_avl
[i
].gain
== gain
)
1619 if (i
== fs_table
->fs_len
)
1622 data
= ST_LSM6DSX_SHIFT_VAL(fs_table
->fs_avl
[i
].val
,
1623 fs_table
->reg
.mask
);
1624 err
= st_lsm6dsx_update_bits_locked(sensor
->hw
, fs_table
->reg
.addr
,
1625 fs_table
->reg
.mask
, data
);
1629 sensor
->gain
= gain
;
1634 int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor
*sensor
, u32 odr
, u8
*val
)
1636 const struct st_lsm6dsx_odr_table_entry
*odr_table
;
1639 odr_table
= &sensor
->hw
->settings
->odr_table
[sensor
->id
];
1640 for (i
= 0; i
< odr_table
->odr_len
; i
++) {
1642 * ext devices can run at different odr respect to
1645 if (odr_table
->odr_avl
[i
].milli_hz
>= odr
)
1649 if (i
== odr_table
->odr_len
)
1652 *val
= odr_table
->odr_avl
[i
].val
;
1653 return odr_table
->odr_avl
[i
].milli_hz
;
1657 st_lsm6dsx_check_odr_dependency(struct st_lsm6dsx_hw
*hw
, u32 odr
,
1658 enum st_lsm6dsx_sensor_id id
)
1660 struct st_lsm6dsx_sensor
*ref
= iio_priv(hw
->iio_devs
[id
]);
1663 if (hw
->enable_mask
& BIT(id
))
1664 return max_t(u32
, ref
->odr
, odr
);
1668 return (hw
->enable_mask
& BIT(id
)) ? ref
->odr
: 0;
1673 st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor
*sensor
, u32 req_odr
)
1675 struct st_lsm6dsx_sensor
*ref_sensor
= sensor
;
1676 struct st_lsm6dsx_hw
*hw
= sensor
->hw
;
1677 const struct st_lsm6dsx_reg
*reg
;
1682 switch (sensor
->id
) {
1683 case ST_LSM6DSX_ID_GYRO
:
1685 case ST_LSM6DSX_ID_EXT0
:
1686 case ST_LSM6DSX_ID_EXT1
:
1687 case ST_LSM6DSX_ID_EXT2
:
1688 case ST_LSM6DSX_ID_ACC
: {
1693 * i2c embedded controller relies on the accelerometer sensor as
1694 * bus read/write trigger so we need to enable accel device
1695 * at odr = max(accel_odr, ext_odr) in order to properly
1696 * communicate with i2c slave devices
1698 ref_sensor
= iio_priv(hw
->iio_devs
[ST_LSM6DSX_ID_ACC
]);
1699 for (i
= ST_LSM6DSX_ID_ACC
; i
< ST_LSM6DSX_ID_MAX
; i
++) {
1700 if (!hw
->iio_devs
[i
] || i
== sensor
->id
)
1703 odr
= st_lsm6dsx_check_odr_dependency(hw
, req_odr
, i
);
1705 /* device already configured */
1710 default: /* should never occur */
1715 err
= st_lsm6dsx_check_odr(ref_sensor
, req_odr
, &val
);
1720 reg
= &hw
->settings
->odr_table
[ref_sensor
->id
].reg
;
1721 data
= ST_LSM6DSX_SHIFT_VAL(val
, reg
->mask
);
1722 return st_lsm6dsx_update_bits_locked(hw
, reg
->addr
, reg
->mask
, data
);
1726 __st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor
*sensor
,
1729 struct st_lsm6dsx_hw
*hw
= sensor
->hw
;
1730 u32 odr
= enable
? sensor
->odr
: 0;
1733 err
= st_lsm6dsx_set_odr(sensor
, odr
);
1738 hw
->enable_mask
|= BIT(sensor
->id
);
1740 hw
->enable_mask
&= ~BIT(sensor
->id
);
1746 st_lsm6dsx_check_events(struct st_lsm6dsx_sensor
*sensor
, bool enable
)
1748 struct st_lsm6dsx_hw
*hw
= sensor
->hw
;
1750 if (sensor
->id
== ST_LSM6DSX_ID_GYRO
|| enable
)
1753 return hw
->enable_event
;
1756 int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor
*sensor
,
1759 if (st_lsm6dsx_check_events(sensor
, enable
))
1762 return __st_lsm6dsx_sensor_set_enable(sensor
, enable
);
1765 static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor
*sensor
,
1768 struct st_lsm6dsx_hw
*hw
= sensor
->hw
;
1772 err
= st_lsm6dsx_sensor_set_enable(sensor
, true);
1777 * we need to wait for sensor settling time before
1778 * reading data in order to avoid corrupted samples
1780 delay
= 1000000000 / sensor
->odr
;
1781 usleep_range(3 * delay
, 4 * delay
);
1783 err
= st_lsm6dsx_read_locked(hw
, addr
, &data
, sizeof(data
));
1787 if (!hw
->enable_event
) {
1788 err
= st_lsm6dsx_sensor_set_enable(sensor
, false);
1793 *val
= (s16
)le16_to_cpu(data
);
1798 static int st_lsm6dsx_read_raw(struct iio_dev
*iio_dev
,
1799 struct iio_chan_spec
const *ch
,
1800 int *val
, int *val2
, long mask
)
1802 struct st_lsm6dsx_sensor
*sensor
= iio_priv(iio_dev
);
1806 case IIO_CHAN_INFO_RAW
:
1807 ret
= iio_device_claim_direct_mode(iio_dev
);
1811 ret
= st_lsm6dsx_read_oneshot(sensor
, ch
->address
, val
);
1812 iio_device_release_direct_mode(iio_dev
);
1814 case IIO_CHAN_INFO_SAMP_FREQ
:
1815 *val
= sensor
->odr
/ 1000;
1816 *val2
= (sensor
->odr
% 1000) * 1000;
1817 ret
= IIO_VAL_INT_PLUS_MICRO
;
1819 case IIO_CHAN_INFO_SCALE
:
1821 *val2
= sensor
->gain
;
1822 ret
= IIO_VAL_INT_PLUS_NANO
;
1832 static int st_lsm6dsx_write_raw(struct iio_dev
*iio_dev
,
1833 struct iio_chan_spec
const *chan
,
1834 int val
, int val2
, long mask
)
1836 struct st_lsm6dsx_sensor
*sensor
= iio_priv(iio_dev
);
1839 err
= iio_device_claim_direct_mode(iio_dev
);
1844 case IIO_CHAN_INFO_SCALE
:
1845 err
= st_lsm6dsx_set_full_scale(sensor
, val2
);
1847 case IIO_CHAN_INFO_SAMP_FREQ
: {
1850 val
= val
* 1000 + val2
/ 1000;
1851 val
= st_lsm6dsx_check_odr(sensor
, val
, &data
);
1863 iio_device_release_direct_mode(iio_dev
);
1868 static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw
*hw
, bool state
)
1870 const struct st_lsm6dsx_reg
*reg
;
1874 if (!hw
->settings
->irq_config
.irq1_func
.addr
)
1877 reg
= &hw
->settings
->event_settings
.enable_reg
;
1879 data
= ST_LSM6DSX_SHIFT_VAL(state
, reg
->mask
);
1880 err
= st_lsm6dsx_update_bits_locked(hw
, reg
->addr
,
1886 /* Enable wakeup interrupt */
1887 data
= ST_LSM6DSX_SHIFT_VAL(state
, hw
->irq_routing
->mask
);
1888 return st_lsm6dsx_update_bits_locked(hw
, hw
->irq_routing
->addr
,
1889 hw
->irq_routing
->mask
, data
);
1892 static int st_lsm6dsx_read_event(struct iio_dev
*iio_dev
,
1893 const struct iio_chan_spec
*chan
,
1894 enum iio_event_type type
,
1895 enum iio_event_direction dir
,
1896 enum iio_event_info info
,
1897 int *val
, int *val2
)
1899 struct st_lsm6dsx_sensor
*sensor
= iio_priv(iio_dev
);
1900 struct st_lsm6dsx_hw
*hw
= sensor
->hw
;
1902 if (type
!= IIO_EV_TYPE_THRESH
)
1906 *val
= hw
->event_threshold
;
1912 st_lsm6dsx_write_event(struct iio_dev
*iio_dev
,
1913 const struct iio_chan_spec
*chan
,
1914 enum iio_event_type type
,
1915 enum iio_event_direction dir
,
1916 enum iio_event_info info
,
1919 struct st_lsm6dsx_sensor
*sensor
= iio_priv(iio_dev
);
1920 struct st_lsm6dsx_hw
*hw
= sensor
->hw
;
1921 const struct st_lsm6dsx_reg
*reg
;
1925 if (type
!= IIO_EV_TYPE_THRESH
)
1928 if (val
< 0 || val
> 31)
1931 reg
= &hw
->settings
->event_settings
.wakeup_reg
;
1932 data
= ST_LSM6DSX_SHIFT_VAL(val
, reg
->mask
);
1933 err
= st_lsm6dsx_update_bits_locked(hw
, reg
->addr
,
1938 hw
->event_threshold
= val
;
1944 st_lsm6dsx_read_event_config(struct iio_dev
*iio_dev
,
1945 const struct iio_chan_spec
*chan
,
1946 enum iio_event_type type
,
1947 enum iio_event_direction dir
)
1949 struct st_lsm6dsx_sensor
*sensor
= iio_priv(iio_dev
);
1950 struct st_lsm6dsx_hw
*hw
= sensor
->hw
;
1952 if (type
!= IIO_EV_TYPE_THRESH
)
1955 return !!(hw
->enable_event
& BIT(chan
->channel2
));
1959 st_lsm6dsx_write_event_config(struct iio_dev
*iio_dev
,
1960 const struct iio_chan_spec
*chan
,
1961 enum iio_event_type type
,
1962 enum iio_event_direction dir
, bool state
)
1964 struct st_lsm6dsx_sensor
*sensor
= iio_priv(iio_dev
);
1965 struct st_lsm6dsx_hw
*hw
= sensor
->hw
;
1969 if (type
!= IIO_EV_TYPE_THRESH
)
1973 enable_event
= hw
->enable_event
| BIT(chan
->channel2
);
1975 /* do not enable events if they are already enabled */
1976 if (hw
->enable_event
)
1979 enable_event
= hw
->enable_event
& ~BIT(chan
->channel2
);
1981 /* only turn off sensor if no events is enabled */
1986 /* stop here if no changes have been made */
1987 if (hw
->enable_event
== enable_event
)
1990 err
= st_lsm6dsx_event_setup(hw
, state
);
1994 mutex_lock(&hw
->conf_lock
);
1995 if (enable_event
|| !(hw
->fifo_mask
& BIT(sensor
->id
)))
1996 err
= __st_lsm6dsx_sensor_set_enable(sensor
, state
);
1997 mutex_unlock(&hw
->conf_lock
);
2002 hw
->enable_event
= enable_event
;
2007 int st_lsm6dsx_set_watermark(struct iio_dev
*iio_dev
, unsigned int val
)
2009 struct st_lsm6dsx_sensor
*sensor
= iio_priv(iio_dev
);
2010 struct st_lsm6dsx_hw
*hw
= sensor
->hw
;
2013 val
= clamp_val(val
, 1, hw
->settings
->fifo_ops
.max_size
);
2015 mutex_lock(&hw
->conf_lock
);
2017 err
= st_lsm6dsx_update_watermark(sensor
, val
);
2019 mutex_unlock(&hw
->conf_lock
);
2024 sensor
->watermark
= val
;
2030 st_lsm6dsx_sysfs_sampling_frequency_avail(struct device
*dev
,
2031 struct device_attribute
*attr
,
2034 struct st_lsm6dsx_sensor
*sensor
= iio_priv(dev_to_iio_dev(dev
));
2035 const struct st_lsm6dsx_odr_table_entry
*odr_table
;
2038 odr_table
= &sensor
->hw
->settings
->odr_table
[sensor
->id
];
2039 for (i
= 0; i
< odr_table
->odr_len
; i
++)
2040 len
+= scnprintf(buf
+ len
, PAGE_SIZE
- len
, "%d.%03d ",
2041 odr_table
->odr_avl
[i
].milli_hz
/ 1000,
2042 odr_table
->odr_avl
[i
].milli_hz
% 1000);
2043 buf
[len
- 1] = '\n';
2048 static ssize_t
st_lsm6dsx_sysfs_scale_avail(struct device
*dev
,
2049 struct device_attribute
*attr
,
2052 struct st_lsm6dsx_sensor
*sensor
= iio_priv(dev_to_iio_dev(dev
));
2053 const struct st_lsm6dsx_fs_table_entry
*fs_table
;
2054 struct st_lsm6dsx_hw
*hw
= sensor
->hw
;
2057 fs_table
= &hw
->settings
->fs_table
[sensor
->id
];
2058 for (i
= 0; i
< fs_table
->fs_len
; i
++)
2059 len
+= scnprintf(buf
+ len
, PAGE_SIZE
- len
, "0.%09u ",
2060 fs_table
->fs_avl
[i
].gain
);
2061 buf
[len
- 1] = '\n';
2066 static int st_lsm6dsx_write_raw_get_fmt(struct iio_dev
*indio_dev
,
2067 struct iio_chan_spec
const *chan
,
2071 case IIO_CHAN_INFO_SCALE
:
2072 switch (chan
->type
) {
2075 return IIO_VAL_INT_PLUS_NANO
;
2077 return IIO_VAL_INT_PLUS_MICRO
;
2080 return IIO_VAL_INT_PLUS_MICRO
;
2084 static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(st_lsm6dsx_sysfs_sampling_frequency_avail
);
2085 static IIO_DEVICE_ATTR(in_accel_scale_available
, 0444,
2086 st_lsm6dsx_sysfs_scale_avail
, NULL
, 0);
2087 static IIO_DEVICE_ATTR(in_anglvel_scale_available
, 0444,
2088 st_lsm6dsx_sysfs_scale_avail
, NULL
, 0);
2090 static struct attribute
*st_lsm6dsx_acc_attributes
[] = {
2091 &iio_dev_attr_sampling_frequency_available
.dev_attr
.attr
,
2092 &iio_dev_attr_in_accel_scale_available
.dev_attr
.attr
,
2096 static const struct attribute_group st_lsm6dsx_acc_attribute_group
= {
2097 .attrs
= st_lsm6dsx_acc_attributes
,
2100 static const struct iio_info st_lsm6dsx_acc_info
= {
2101 .attrs
= &st_lsm6dsx_acc_attribute_group
,
2102 .read_raw
= st_lsm6dsx_read_raw
,
2103 .write_raw
= st_lsm6dsx_write_raw
,
2104 .read_event_value
= st_lsm6dsx_read_event
,
2105 .write_event_value
= st_lsm6dsx_write_event
,
2106 .read_event_config
= st_lsm6dsx_read_event_config
,
2107 .write_event_config
= st_lsm6dsx_write_event_config
,
2108 .hwfifo_set_watermark
= st_lsm6dsx_set_watermark
,
2109 .write_raw_get_fmt
= st_lsm6dsx_write_raw_get_fmt
,
2112 static struct attribute
*st_lsm6dsx_gyro_attributes
[] = {
2113 &iio_dev_attr_sampling_frequency_available
.dev_attr
.attr
,
2114 &iio_dev_attr_in_anglvel_scale_available
.dev_attr
.attr
,
2118 static const struct attribute_group st_lsm6dsx_gyro_attribute_group
= {
2119 .attrs
= st_lsm6dsx_gyro_attributes
,
2122 static const struct iio_info st_lsm6dsx_gyro_info
= {
2123 .attrs
= &st_lsm6dsx_gyro_attribute_group
,
2124 .read_raw
= st_lsm6dsx_read_raw
,
2125 .write_raw
= st_lsm6dsx_write_raw
,
2126 .hwfifo_set_watermark
= st_lsm6dsx_set_watermark
,
2127 .write_raw_get_fmt
= st_lsm6dsx_write_raw_get_fmt
,
2131 st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw
*hw
,
2132 const struct st_lsm6dsx_reg
**drdy_reg
)
2134 struct device
*dev
= hw
->dev
;
2135 const struct st_sensors_platform_data
*pdata
= dev_get_platdata(dev
);
2136 int err
= 0, drdy_pin
;
2138 if (device_property_read_u32(dev
, "st,drdy-int-pin", &drdy_pin
) < 0)
2139 drdy_pin
= pdata
? pdata
->drdy_int_pin
: 1;
2143 hw
->irq_routing
= &hw
->settings
->irq_config
.irq1_func
;
2144 *drdy_reg
= &hw
->settings
->irq_config
.irq1
;
2147 hw
->irq_routing
= &hw
->settings
->irq_config
.irq2_func
;
2148 *drdy_reg
= &hw
->settings
->irq_config
.irq2
;
2151 dev_err(hw
->dev
, "unsupported data ready pin\n");
2159 static int st_lsm6dsx_init_shub(struct st_lsm6dsx_hw
*hw
)
2161 const struct st_lsm6dsx_shub_settings
*hub_settings
;
2162 struct device
*dev
= hw
->dev
;
2163 const struct st_sensors_platform_data
*pdata
= dev_get_platdata(dev
);
2167 hub_settings
= &hw
->settings
->shub_settings
;
2169 if (device_property_read_bool(dev
, "st,pullups") ||
2170 (pdata
&& pdata
->pullups
)) {
2171 if (hub_settings
->pullup_en
.sec_page
) {
2172 err
= st_lsm6dsx_set_page(hw
, true);
2177 data
= ST_LSM6DSX_SHIFT_VAL(1, hub_settings
->pullup_en
.mask
);
2178 err
= regmap_update_bits(hw
->regmap
,
2179 hub_settings
->pullup_en
.addr
,
2180 hub_settings
->pullup_en
.mask
, data
);
2182 if (hub_settings
->pullup_en
.sec_page
)
2183 st_lsm6dsx_set_page(hw
, false);
2189 if (hub_settings
->aux_sens
.addr
) {
2190 /* configure aux sensors */
2191 err
= st_lsm6dsx_set_page(hw
, true);
2195 data
= ST_LSM6DSX_SHIFT_VAL(3, hub_settings
->aux_sens
.mask
);
2196 err
= regmap_update_bits(hw
->regmap
,
2197 hub_settings
->aux_sens
.addr
,
2198 hub_settings
->aux_sens
.mask
, data
);
2200 st_lsm6dsx_set_page(hw
, false);
2206 if (hub_settings
->emb_func
.addr
) {
2207 data
= ST_LSM6DSX_SHIFT_VAL(1, hub_settings
->emb_func
.mask
);
2208 err
= regmap_update_bits(hw
->regmap
,
2209 hub_settings
->emb_func
.addr
,
2210 hub_settings
->emb_func
.mask
, data
);
2216 static int st_lsm6dsx_init_hw_timer(struct st_lsm6dsx_hw
*hw
)
2218 const struct st_lsm6dsx_hw_ts_settings
*ts_settings
;
2221 ts_settings
= &hw
->settings
->ts_settings
;
2222 /* enable hw timestamp generation if necessary */
2223 if (ts_settings
->timer_en
.addr
) {
2224 val
= ST_LSM6DSX_SHIFT_VAL(1, ts_settings
->timer_en
.mask
);
2225 err
= regmap_update_bits(hw
->regmap
,
2226 ts_settings
->timer_en
.addr
,
2227 ts_settings
->timer_en
.mask
, val
);
2232 /* enable high resolution for hw ts timer if necessary */
2233 if (ts_settings
->hr_timer
.addr
) {
2234 val
= ST_LSM6DSX_SHIFT_VAL(1, ts_settings
->hr_timer
.mask
);
2235 err
= regmap_update_bits(hw
->regmap
,
2236 ts_settings
->hr_timer
.addr
,
2237 ts_settings
->hr_timer
.mask
, val
);
2242 /* enable ts queueing in FIFO if necessary */
2243 if (ts_settings
->fifo_en
.addr
) {
2244 val
= ST_LSM6DSX_SHIFT_VAL(1, ts_settings
->fifo_en
.mask
);
2245 err
= regmap_update_bits(hw
->regmap
,
2246 ts_settings
->fifo_en
.addr
,
2247 ts_settings
->fifo_en
.mask
, val
);
2252 /* calibrate timestamp sensitivity */
2253 hw
->ts_gain
= ST_LSM6DSX_TS_SENSITIVITY
;
2254 if (ts_settings
->freq_fine
) {
2255 err
= regmap_read(hw
->regmap
, ts_settings
->freq_fine
, &val
);
2260 * linearize the AN5192 formula:
2261 * 1 / (1 + x) ~= 1 - x (Taylor’s Series)
2262 * ttrim[s] = 1 / (40000 * (1 + 0.0015 * val))
2263 * ttrim[ns] ~= 25000 - 37.5 * val
2264 * ttrim[ns] ~= 25000 - (37500 * val) / 1000
2266 hw
->ts_gain
-= ((s8
)val
* 37500) / 1000;
2272 static int st_lsm6dsx_reset_device(struct st_lsm6dsx_hw
*hw
)
2274 const struct st_lsm6dsx_reg
*reg
;
2278 * flush hw FIFO before device reset in order to avoid
2279 * possible races on interrupt line 1. If the first interrupt
2280 * line is asserted during hw reset the device will work in
2281 * I3C-only mode (if it is supported)
2283 err
= st_lsm6dsx_flush_fifo(hw
);
2284 if (err
< 0 && err
!= -ENOTSUPP
)
2287 /* device sw reset */
2288 reg
= &hw
->settings
->reset
;
2289 err
= regmap_update_bits(hw
->regmap
, reg
->addr
, reg
->mask
,
2290 ST_LSM6DSX_SHIFT_VAL(1, reg
->mask
));
2296 /* reload trimming parameter */
2297 reg
= &hw
->settings
->boot
;
2298 err
= regmap_update_bits(hw
->regmap
, reg
->addr
, reg
->mask
,
2299 ST_LSM6DSX_SHIFT_VAL(1, reg
->mask
));
2308 static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw
*hw
)
2310 const struct st_lsm6dsx_reg
*reg
;
2313 err
= st_lsm6dsx_reset_device(hw
);
2317 /* enable Block Data Update */
2318 reg
= &hw
->settings
->bdu
;
2319 err
= regmap_update_bits(hw
->regmap
, reg
->addr
, reg
->mask
,
2320 ST_LSM6DSX_SHIFT_VAL(1, reg
->mask
));
2324 /* enable FIFO watermak interrupt */
2325 err
= st_lsm6dsx_get_drdy_reg(hw
, ®
);
2329 err
= regmap_update_bits(hw
->regmap
, reg
->addr
, reg
->mask
,
2330 ST_LSM6DSX_SHIFT_VAL(1, reg
->mask
));
2334 /* enable Latched interrupts for device events */
2335 if (hw
->settings
->irq_config
.lir
.addr
) {
2336 reg
= &hw
->settings
->irq_config
.lir
;
2337 err
= regmap_update_bits(hw
->regmap
, reg
->addr
, reg
->mask
,
2338 ST_LSM6DSX_SHIFT_VAL(1, reg
->mask
));
2342 /* enable clear on read for latched interrupts */
2343 if (hw
->settings
->irq_config
.clear_on_read
.addr
) {
2344 reg
= &hw
->settings
->irq_config
.clear_on_read
;
2345 err
= regmap_update_bits(hw
->regmap
,
2346 reg
->addr
, reg
->mask
,
2347 ST_LSM6DSX_SHIFT_VAL(1, reg
->mask
));
2353 /* enable drdy-mas if available */
2354 if (hw
->settings
->drdy_mask
.addr
) {
2355 reg
= &hw
->settings
->drdy_mask
;
2356 err
= regmap_update_bits(hw
->regmap
, reg
->addr
, reg
->mask
,
2357 ST_LSM6DSX_SHIFT_VAL(1, reg
->mask
));
2362 err
= st_lsm6dsx_init_shub(hw
);
2366 return st_lsm6dsx_init_hw_timer(hw
);
2369 static struct iio_dev
*st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw
*hw
,
2370 enum st_lsm6dsx_sensor_id id
,
2373 struct st_lsm6dsx_sensor
*sensor
;
2374 struct iio_dev
*iio_dev
;
2376 iio_dev
= devm_iio_device_alloc(hw
->dev
, sizeof(*sensor
));
2380 iio_dev
->modes
= INDIO_DIRECT_MODE
;
2381 iio_dev
->available_scan_masks
= st_lsm6dsx_available_scan_masks
;
2382 iio_dev
->channels
= hw
->settings
->channels
[id
].chan
;
2383 iio_dev
->num_channels
= hw
->settings
->channels
[id
].len
;
2385 sensor
= iio_priv(iio_dev
);
2388 sensor
->odr
= hw
->settings
->odr_table
[id
].odr_avl
[0].milli_hz
;
2389 sensor
->gain
= hw
->settings
->fs_table
[id
].fs_avl
[0].gain
;
2390 sensor
->watermark
= 1;
2393 case ST_LSM6DSX_ID_ACC
:
2394 iio_dev
->info
= &st_lsm6dsx_acc_info
;
2395 scnprintf(sensor
->name
, sizeof(sensor
->name
), "%s_accel",
2398 case ST_LSM6DSX_ID_GYRO
:
2399 iio_dev
->info
= &st_lsm6dsx_gyro_info
;
2400 scnprintf(sensor
->name
, sizeof(sensor
->name
), "%s_gyro",
2406 iio_dev
->name
= sensor
->name
;
2412 st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw
*hw
)
2414 const struct st_lsm6dsx_event_settings
*event_settings
;
2418 if (!hw
->enable_event
)
2421 event_settings
= &hw
->settings
->event_settings
;
2422 err
= st_lsm6dsx_read_locked(hw
, event_settings
->wakeup_src_reg
,
2423 &data
, sizeof(data
));
2427 timestamp
= iio_get_time_ns(hw
->iio_devs
[ST_LSM6DSX_ID_ACC
]);
2428 if ((data
& hw
->settings
->event_settings
.wakeup_src_z_mask
) &&
2429 (hw
->enable_event
& BIT(IIO_MOD_Z
)))
2430 iio_push_event(hw
->iio_devs
[ST_LSM6DSX_ID_ACC
],
2431 IIO_MOD_EVENT_CODE(IIO_ACCEL
,
2438 if ((data
& hw
->settings
->event_settings
.wakeup_src_y_mask
) &&
2439 (hw
->enable_event
& BIT(IIO_MOD_Y
)))
2440 iio_push_event(hw
->iio_devs
[ST_LSM6DSX_ID_ACC
],
2441 IIO_MOD_EVENT_CODE(IIO_ACCEL
,
2448 if ((data
& hw
->settings
->event_settings
.wakeup_src_x_mask
) &&
2449 (hw
->enable_event
& BIT(IIO_MOD_X
)))
2450 iio_push_event(hw
->iio_devs
[ST_LSM6DSX_ID_ACC
],
2451 IIO_MOD_EVENT_CODE(IIO_ACCEL
,
2458 return data
& event_settings
->wakeup_src_status_mask
;
2461 static irqreturn_t
st_lsm6dsx_handler_thread(int irq
, void *private)
2463 struct st_lsm6dsx_hw
*hw
= private;
2464 int fifo_len
= 0, len
;
2467 event
= st_lsm6dsx_report_motion_event(hw
);
2469 if (!hw
->settings
->fifo_ops
.read_fifo
)
2470 return event
? IRQ_HANDLED
: IRQ_NONE
;
2473 * If we are using edge IRQs, new samples can arrive while
2474 * processing current interrupt since there are no hw
2475 * guarantees the irq line stays "low" long enough to properly
2476 * detect the new interrupt. In this case the new sample will
2478 * Polling FIFO status register allow us to read new
2479 * samples even if the interrupt arrives while processing
2480 * previous data and the timeslot where the line is "low" is
2481 * too short to be properly detected.
2484 mutex_lock(&hw
->fifo_lock
);
2485 len
= hw
->settings
->fifo_ops
.read_fifo(hw
);
2486 mutex_unlock(&hw
->fifo_lock
);
2492 return fifo_len
|| event
? IRQ_HANDLED
: IRQ_NONE
;
2495 static irqreturn_t
st_lsm6dsx_sw_trigger_handler_thread(int irq
,
2498 struct iio_poll_func
*pf
= private;
2499 struct iio_dev
*iio_dev
= pf
->indio_dev
;
2500 struct st_lsm6dsx_sensor
*sensor
= iio_priv(iio_dev
);
2501 struct st_lsm6dsx_hw
*hw
= sensor
->hw
;
2503 if (sensor
->id
== ST_LSM6DSX_ID_EXT0
||
2504 sensor
->id
== ST_LSM6DSX_ID_EXT1
||
2505 sensor
->id
== ST_LSM6DSX_ID_EXT2
)
2506 st_lsm6dsx_shub_read_output(hw
,
2507 (u8
*)hw
->scan
[sensor
->id
].channels
,
2508 sizeof(hw
->scan
[sensor
->id
].channels
));
2510 st_lsm6dsx_read_locked(hw
, iio_dev
->channels
[0].address
,
2511 hw
->scan
[sensor
->id
].channels
,
2512 sizeof(hw
->scan
[sensor
->id
].channels
));
2514 iio_push_to_buffers_with_timestamp(iio_dev
, &hw
->scan
[sensor
->id
],
2515 iio_get_time_ns(iio_dev
));
2516 iio_trigger_notify_done(iio_dev
->trig
);
2521 static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw
*hw
)
2523 const struct st_lsm6dsx_reg
*reg
;
2524 struct device
*dev
= hw
->dev
;
2525 const struct st_sensors_platform_data
*pdata
= dev_get_platdata(dev
);
2526 unsigned long irq_type
;
2527 bool irq_active_low
;
2530 irq_type
= irq_get_trigger_type(hw
->irq
);
2532 case IRQF_TRIGGER_HIGH
:
2533 case IRQF_TRIGGER_RISING
:
2534 irq_active_low
= false;
2536 case IRQF_TRIGGER_LOW
:
2537 case IRQF_TRIGGER_FALLING
:
2538 irq_active_low
= true;
2541 dev_info(hw
->dev
, "mode %lx unsupported\n", irq_type
);
2545 reg
= &hw
->settings
->irq_config
.hla
;
2546 err
= regmap_update_bits(hw
->regmap
, reg
->addr
, reg
->mask
,
2547 ST_LSM6DSX_SHIFT_VAL(irq_active_low
,
2552 if (device_property_read_bool(dev
, "drive-open-drain") ||
2553 (pdata
&& pdata
->open_drain
)) {
2554 reg
= &hw
->settings
->irq_config
.od
;
2555 err
= regmap_update_bits(hw
->regmap
, reg
->addr
, reg
->mask
,
2556 ST_LSM6DSX_SHIFT_VAL(1, reg
->mask
));
2560 irq_type
|= IRQF_SHARED
;
2563 err
= devm_request_threaded_irq(hw
->dev
, hw
->irq
,
2565 st_lsm6dsx_handler_thread
,
2566 irq_type
| IRQF_ONESHOT
,
2569 dev_err(hw
->dev
, "failed to request trigger irq %d\n",
2577 static int st_lsm6dsx_sw_buffer_preenable(struct iio_dev
*iio_dev
)
2579 struct st_lsm6dsx_sensor
*sensor
= iio_priv(iio_dev
);
2581 return st_lsm6dsx_device_set_enable(sensor
, true);
2584 static int st_lsm6dsx_sw_buffer_postdisable(struct iio_dev
*iio_dev
)
2586 struct st_lsm6dsx_sensor
*sensor
= iio_priv(iio_dev
);
2588 return st_lsm6dsx_device_set_enable(sensor
, false);
2591 static const struct iio_buffer_setup_ops st_lsm6dsx_sw_buffer_ops
= {
2592 .preenable
= st_lsm6dsx_sw_buffer_preenable
,
2593 .postdisable
= st_lsm6dsx_sw_buffer_postdisable
,
2596 static int st_lsm6dsx_sw_buffers_setup(struct st_lsm6dsx_hw
*hw
)
2600 for (i
= 0; i
< ST_LSM6DSX_ID_MAX
; i
++) {
2603 if (!hw
->iio_devs
[i
])
2606 err
= devm_iio_triggered_buffer_setup(hw
->dev
,
2607 hw
->iio_devs
[i
], NULL
,
2608 st_lsm6dsx_sw_trigger_handler_thread
,
2609 &st_lsm6dsx_sw_buffer_ops
);
2617 static int st_lsm6dsx_init_regulators(struct device
*dev
)
2619 /* vdd-vddio power regulators */
2620 static const char * const regulators
[] = { "vdd", "vddio" };
2623 err
= devm_regulator_bulk_get_enable(dev
, ARRAY_SIZE(regulators
),
2626 return dev_err_probe(dev
, err
, "failed to enable regulators\n");
2633 int st_lsm6dsx_probe(struct device
*dev
, int irq
, int hw_id
,
2634 struct regmap
*regmap
)
2636 const struct st_sensors_platform_data
*pdata
= dev_get_platdata(dev
);
2637 const struct st_lsm6dsx_shub_settings
*hub_settings
;
2638 struct st_lsm6dsx_hw
*hw
;
2639 const char *name
= NULL
;
2642 hw
= devm_kzalloc(dev
, sizeof(*hw
), GFP_KERNEL
);
2646 dev_set_drvdata(dev
, hw
);
2648 mutex_init(&hw
->fifo_lock
);
2649 mutex_init(&hw
->conf_lock
);
2650 mutex_init(&hw
->page_lock
);
2652 err
= st_lsm6dsx_init_regulators(dev
);
2656 hw
->buff
= devm_kzalloc(dev
, ST_LSM6DSX_BUFF_SIZE
, GFP_KERNEL
);
2662 hw
->regmap
= regmap
;
2664 err
= st_lsm6dsx_check_whoami(hw
, hw_id
, &name
);
2668 for (i
= 0; i
< ST_LSM6DSX_ID_EXT0
; i
++) {
2669 hw
->iio_devs
[i
] = st_lsm6dsx_alloc_iiodev(hw
, i
, name
);
2670 if (!hw
->iio_devs
[i
])
2674 err
= st_lsm6dsx_init_device(hw
);
2678 hub_settings
= &hw
->settings
->shub_settings
;
2679 if (hub_settings
->master_en
.addr
&&
2680 !device_property_read_bool(dev
, "st,disable-sensor-hub")) {
2681 err
= st_lsm6dsx_shub_probe(hw
, name
);
2687 err
= st_lsm6dsx_irq_setup(hw
);
2691 err
= st_lsm6dsx_fifo_setup(hw
);
2696 if (!hw
->irq
|| !hw
->settings
->fifo_ops
.read_fifo
) {
2698 * Rely on sw triggers (e.g. hr-timers) if irq pin is not
2699 * connected of if the device does not support HW FIFO
2701 err
= st_lsm6dsx_sw_buffers_setup(hw
);
2706 if (!iio_read_acpi_mount_matrix(hw
->dev
, &hw
->orientation
, "ROTM")) {
2707 err
= iio_read_mount_matrix(hw
->dev
, &hw
->orientation
);
2712 for (i
= 0; i
< ST_LSM6DSX_ID_MAX
; i
++) {
2713 if (!hw
->iio_devs
[i
])
2716 err
= devm_iio_device_register(hw
->dev
, hw
->iio_devs
[i
]);
2721 if (device_property_read_bool(dev
, "wakeup-source") ||
2722 (pdata
&& pdata
->wakeup_source
))
2723 device_init_wakeup(dev
, true);
2727 EXPORT_SYMBOL_NS(st_lsm6dsx_probe
, "IIO_LSM6DSX");
2729 static int st_lsm6dsx_suspend(struct device
*dev
)
2731 struct st_lsm6dsx_hw
*hw
= dev_get_drvdata(dev
);
2732 struct st_lsm6dsx_sensor
*sensor
;
2735 for (i
= 0; i
< ST_LSM6DSX_ID_MAX
; i
++) {
2736 if (!hw
->iio_devs
[i
])
2739 sensor
= iio_priv(hw
->iio_devs
[i
]);
2740 if (!(hw
->enable_mask
& BIT(sensor
->id
)))
2743 if (device_may_wakeup(dev
) &&
2744 sensor
->id
== ST_LSM6DSX_ID_ACC
&& hw
->enable_event
) {
2745 /* Enable wake from IRQ */
2746 enable_irq_wake(hw
->irq
);
2750 err
= st_lsm6dsx_device_set_enable(sensor
, false);
2754 hw
->suspend_mask
|= BIT(sensor
->id
);
2758 err
= st_lsm6dsx_flush_fifo(hw
);
2763 static int st_lsm6dsx_resume(struct device
*dev
)
2765 struct st_lsm6dsx_hw
*hw
= dev_get_drvdata(dev
);
2766 struct st_lsm6dsx_sensor
*sensor
;
2769 for (i
= 0; i
< ST_LSM6DSX_ID_MAX
; i
++) {
2770 if (!hw
->iio_devs
[i
])
2773 sensor
= iio_priv(hw
->iio_devs
[i
]);
2774 if (device_may_wakeup(dev
) &&
2775 sensor
->id
== ST_LSM6DSX_ID_ACC
&& hw
->enable_event
)
2776 disable_irq_wake(hw
->irq
);
2778 if (!(hw
->suspend_mask
& BIT(sensor
->id
)))
2781 err
= st_lsm6dsx_device_set_enable(sensor
, true);
2785 hw
->suspend_mask
&= ~BIT(sensor
->id
);
2789 err
= st_lsm6dsx_resume_fifo(hw
);
2794 EXPORT_NS_SIMPLE_DEV_PM_OPS(st_lsm6dsx_pm_ops
, st_lsm6dsx_suspend
,
2795 st_lsm6dsx_resume
, IIO_LSM6DSX
);
2797 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
2798 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
2799 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx driver");
2800 MODULE_LICENSE("GPL v2");