1fda8d26eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2290a6ce1SLorenzo Bianconi /* 3290a6ce1SLorenzo Bianconi * STMicroelectronics st_lsm6dsx sensor driver 4290a6ce1SLorenzo Bianconi * 5290a6ce1SLorenzo Bianconi * The ST LSM6DSx IMU MEMS series consists of 3D digital accelerometer 6290a6ce1SLorenzo Bianconi * and 3D digital gyroscope system-in-package with a digital I2C/SPI serial 7290a6ce1SLorenzo Bianconi * interface standard output. 8290a6ce1SLorenzo Bianconi * LSM6DSx IMU MEMS series has a dynamic user-selectable full-scale 9290a6ce1SLorenzo Bianconi * acceleration range of +-2/+-4/+-8/+-16 g and an angular rate range of 10290a6ce1SLorenzo Bianconi * +-125/+-245/+-500/+-1000/+-2000 dps 11290a6ce1SLorenzo Bianconi * LSM6DSx series has an integrated First-In-First-Out (FIFO) buffer 12290a6ce1SLorenzo Bianconi * allowing dynamic batching of sensor data. 1352f4b1f1SMartin Kepplinger * LSM9DSx series is similar but includes an additional magnetometer, handled 1452f4b1f1SMartin Kepplinger * by a different driver. 15290a6ce1SLorenzo Bianconi * 16290a6ce1SLorenzo Bianconi * Supported sensors: 17290a6ce1SLorenzo Bianconi * - LSM6DS3: 18f7d5c18aSSean Nyekjaer * - Accelerometer/Gyroscope supported ODR [Hz]: 12.5, 26, 52, 104, 208, 416 19290a6ce1SLorenzo Bianconi * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16 20290a6ce1SLorenzo Bianconi * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 21290a6ce1SLorenzo Bianconi * - FIFO size: 8KB 22290a6ce1SLorenzo Bianconi * 23dbcd2088SLorenzo Bianconi * - LSM6DS3H/LSM6DSL/LSM6DSM/ISM330DLC/LSM6DS3TR-C: 24f7d5c18aSSean Nyekjaer * - Accelerometer/Gyroscope supported ODR [Hz]: 12.5, 26, 52, 104, 208, 416 25290a6ce1SLorenzo Bianconi * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16 26290a6ce1SLorenzo Bianconi * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 27290a6ce1SLorenzo Bianconi * - FIFO size: 4KB 28290a6ce1SLorenzo Bianconi * 292c57d265SLorenzo Bianconi * - LSM6DSO/LSM6DSOX/ASM330LHH/LSM6DSR/ISM330DHCX/LSM6DST/LSM6DSOP: 30f7d5c18aSSean Nyekjaer * - Accelerometer/Gyroscope supported ODR [Hz]: 12.5, 26, 52, 104, 208, 416, 318f9a5249SLorenzo Bianconi * 833 32801a6e0aSLorenzo Bianconi * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16 33801a6e0aSLorenzo Bianconi * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 34801a6e0aSLorenzo Bianconi * - FIFO size: 3KB 35801a6e0aSLorenzo Bianconi * 36fa060a3dSLorenzo Bianconi * - LSM9DS1/LSM6DS0: 3752f4b1f1SMartin Kepplinger * - Accelerometer supported ODR [Hz]: 10, 50, 119, 238, 476, 952 3852f4b1f1SMartin Kepplinger * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16 3952f4b1f1SMartin Kepplinger * - Gyroscope supported ODR [Hz]: 15, 60, 119, 238, 476, 952 4052f4b1f1SMartin Kepplinger * - Gyroscope supported full-scale [dps]: +-245/+-500/+-2000 4152f4b1f1SMartin Kepplinger * - FIFO size: 32 4252f4b1f1SMartin Kepplinger * 43290a6ce1SLorenzo Bianconi * Copyright 2016 STMicroelectronics Inc. 44290a6ce1SLorenzo Bianconi * 45290a6ce1SLorenzo Bianconi * Lorenzo Bianconi <lorenzo.bianconi@st.com> 46290a6ce1SLorenzo Bianconi * Denis Ciocca <denis.ciocca@st.com> 47290a6ce1SLorenzo Bianconi */ 48290a6ce1SLorenzo Bianconi 49290a6ce1SLorenzo Bianconi #include <linux/kernel.h> 50290a6ce1SLorenzo Bianconi #include <linux/module.h> 51290a6ce1SLorenzo Bianconi #include <linux/delay.h> 521aabad1fSSean Nyekjaer #include <linux/iio/events.h> 53290a6ce1SLorenzo Bianconi #include <linux/iio/iio.h> 54290a6ce1SLorenzo Bianconi #include <linux/iio/sysfs.h> 556ee6a368SSean Nyekjaer #include <linux/interrupt.h> 566ee6a368SSean Nyekjaer #include <linux/irq.h> 57d3f77058SLorenzo Bianconi #include <linux/pm.h> 5803d4c566SAndy Shevchenko #include <linux/property.h> 5951a8b707SLorenzo Bianconi #include <linux/regmap.h> 6051a8b707SLorenzo Bianconi #include <linux/bitfield.h> 61290a6ce1SLorenzo Bianconi 62dba32904SLorenzo Bianconi #include <linux/platform_data/st_sensors_pdata.h> 63dba32904SLorenzo Bianconi 64290a6ce1SLorenzo Bianconi #include "st_lsm6dsx.h" 65290a6ce1SLorenzo Bianconi 66290a6ce1SLorenzo Bianconi #define ST_LSM6DSX_REG_WHOAMI_ADDR 0x0f 67290a6ce1SLorenzo Bianconi 68cb3b6b8eSMario Tesi #define ST_LSM6DSX_TS_SENSITIVITY 25000UL /* 25us */ 69cb3b6b8eSMario Tesi 70f48bc49bSLorenzo Bianconi static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = { 71b5969abfSSean Nyekjaer ST_LSM6DSX_CHANNEL_ACC(IIO_ACCEL, 0x28, IIO_MOD_X, 0), 72b5969abfSSean Nyekjaer ST_LSM6DSX_CHANNEL_ACC(IIO_ACCEL, 0x2a, IIO_MOD_Y, 1), 73b5969abfSSean Nyekjaer ST_LSM6DSX_CHANNEL_ACC(IIO_ACCEL, 0x2c, IIO_MOD_Z, 2), 74f48bc49bSLorenzo Bianconi IIO_CHAN_SOFT_TIMESTAMP(3), 75f48bc49bSLorenzo Bianconi }; 76f48bc49bSLorenzo Bianconi 77f48bc49bSLorenzo Bianconi static const struct iio_chan_spec st_lsm6dsx_gyro_channels[] = { 78f48bc49bSLorenzo Bianconi ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x22, IIO_MOD_X, 0), 79f48bc49bSLorenzo Bianconi ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x24, IIO_MOD_Y, 1), 80f48bc49bSLorenzo Bianconi ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x26, IIO_MOD_Z, 2), 81f48bc49bSLorenzo Bianconi IIO_CHAN_SOFT_TIMESTAMP(3), 82f48bc49bSLorenzo Bianconi }; 83f48bc49bSLorenzo Bianconi 8452f4b1f1SMartin Kepplinger static const struct iio_chan_spec st_lsm6ds0_gyro_channels[] = { 8552f4b1f1SMartin Kepplinger ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x18, IIO_MOD_X, 0), 8652f4b1f1SMartin Kepplinger ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x1a, IIO_MOD_Y, 1), 8752f4b1f1SMartin Kepplinger ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x1c, IIO_MOD_Z, 2), 8852f4b1f1SMartin Kepplinger IIO_CHAN_SOFT_TIMESTAMP(3), 8952f4b1f1SMartin Kepplinger }; 9052f4b1f1SMartin Kepplinger 91290a6ce1SLorenzo Bianconi static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { 92290a6ce1SLorenzo Bianconi { 9366b662a1SLorenzo Bianconi .reset = { 9466b662a1SLorenzo Bianconi .addr = 0x22, 9566b662a1SLorenzo Bianconi .mask = BIT(0), 9666b662a1SLorenzo Bianconi }, 9766b662a1SLorenzo Bianconi .boot = { 9866b662a1SLorenzo Bianconi .addr = 0x22, 9966b662a1SLorenzo Bianconi .mask = BIT(7), 10066b662a1SLorenzo Bianconi }, 10166b662a1SLorenzo Bianconi .bdu = { 10266b662a1SLorenzo Bianconi .addr = 0x22, 10366b662a1SLorenzo Bianconi .mask = BIT(6), 10466b662a1SLorenzo Bianconi }, 10552f4b1f1SMartin Kepplinger .id = { 10652f4b1f1SMartin Kepplinger { 10752f4b1f1SMartin Kepplinger .hw_id = ST_LSM9DS1_ID, 10852f4b1f1SMartin Kepplinger .name = ST_LSM9DS1_DEV_NAME, 10998c3544aSLorenzo Bianconi .wai = 0x68, 110fa060a3dSLorenzo Bianconi }, { 111fa060a3dSLorenzo Bianconi .hw_id = ST_LSM6DS0_ID, 112fa060a3dSLorenzo Bianconi .name = ST_LSM6DS0_DEV_NAME, 11398c3544aSLorenzo Bianconi .wai = 0x68, 11452f4b1f1SMartin Kepplinger }, 11552f4b1f1SMartin Kepplinger }, 11652f4b1f1SMartin Kepplinger .channels = { 11752f4b1f1SMartin Kepplinger [ST_LSM6DSX_ID_ACC] = { 11852f4b1f1SMartin Kepplinger .chan = st_lsm6dsx_acc_channels, 11952f4b1f1SMartin Kepplinger .len = ARRAY_SIZE(st_lsm6dsx_acc_channels), 12052f4b1f1SMartin Kepplinger }, 12152f4b1f1SMartin Kepplinger [ST_LSM6DSX_ID_GYRO] = { 12252f4b1f1SMartin Kepplinger .chan = st_lsm6ds0_gyro_channels, 12352f4b1f1SMartin Kepplinger .len = ARRAY_SIZE(st_lsm6ds0_gyro_channels), 12452f4b1f1SMartin Kepplinger }, 12552f4b1f1SMartin Kepplinger }, 12652f4b1f1SMartin Kepplinger .odr_table = { 12752f4b1f1SMartin Kepplinger [ST_LSM6DSX_ID_ACC] = { 12852f4b1f1SMartin Kepplinger .reg = { 12952f4b1f1SMartin Kepplinger .addr = 0x20, 13052f4b1f1SMartin Kepplinger .mask = GENMASK(7, 5), 13152f4b1f1SMartin Kepplinger }, 132f8710f03SLorenzo Bianconi .odr_avl[0] = { 10000, 0x01 }, 133f8710f03SLorenzo Bianconi .odr_avl[1] = { 50000, 0x02 }, 134f8710f03SLorenzo Bianconi .odr_avl[2] = { 119000, 0x03 }, 135f8710f03SLorenzo Bianconi .odr_avl[3] = { 238000, 0x04 }, 136f8710f03SLorenzo Bianconi .odr_avl[4] = { 476000, 0x05 }, 137f8710f03SLorenzo Bianconi .odr_avl[5] = { 952000, 0x06 }, 13859af4e20SLorenzo Bianconi .odr_len = 6, 13952f4b1f1SMartin Kepplinger }, 14052f4b1f1SMartin Kepplinger [ST_LSM6DSX_ID_GYRO] = { 14152f4b1f1SMartin Kepplinger .reg = { 14252f4b1f1SMartin Kepplinger .addr = 0x10, 14352f4b1f1SMartin Kepplinger .mask = GENMASK(7, 5), 14452f4b1f1SMartin Kepplinger }, 145f8710f03SLorenzo Bianconi .odr_avl[0] = { 14900, 0x01 }, 146f8710f03SLorenzo Bianconi .odr_avl[1] = { 59500, 0x02 }, 147f8710f03SLorenzo Bianconi .odr_avl[2] = { 119000, 0x03 }, 148f8710f03SLorenzo Bianconi .odr_avl[3] = { 238000, 0x04 }, 149f8710f03SLorenzo Bianconi .odr_avl[4] = { 476000, 0x05 }, 150f8710f03SLorenzo Bianconi .odr_avl[5] = { 952000, 0x06 }, 15159af4e20SLorenzo Bianconi .odr_len = 6, 15252f4b1f1SMartin Kepplinger }, 15352f4b1f1SMartin Kepplinger }, 15452f4b1f1SMartin Kepplinger .fs_table = { 15552f4b1f1SMartin Kepplinger [ST_LSM6DSX_ID_ACC] = { 15652f4b1f1SMartin Kepplinger .reg = { 15752f4b1f1SMartin Kepplinger .addr = 0x20, 15852f4b1f1SMartin Kepplinger .mask = GENMASK(4, 3), 15952f4b1f1SMartin Kepplinger }, 16044a76de8SMario Tesi .fs_avl[0] = { IIO_G_TO_M_S_2(61000), 0x0 }, 16144a76de8SMario Tesi .fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 }, 16244a76de8SMario Tesi .fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 }, 16344a76de8SMario Tesi .fs_avl[3] = { IIO_G_TO_M_S_2(732000), 0x1 }, 16485ae3aeeSLorenzo Bianconi .fs_len = 4, 16552f4b1f1SMartin Kepplinger }, 16652f4b1f1SMartin Kepplinger [ST_LSM6DSX_ID_GYRO] = { 16752f4b1f1SMartin Kepplinger .reg = { 16852f4b1f1SMartin Kepplinger .addr = 0x10, 16952f4b1f1SMartin Kepplinger .mask = GENMASK(4, 3), 17052f4b1f1SMartin Kepplinger }, 1711b375101SLorenzo Bianconi 17244a76de8SMario Tesi .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 }, 17344a76de8SMario Tesi .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 }, 17444a76de8SMario Tesi .fs_avl[2] = { IIO_DEGREE_TO_RAD(70000000), 0x3 }, 17585ae3aeeSLorenzo Bianconi .fs_len = 3, 17652f4b1f1SMartin Kepplinger }, 17752f4b1f1SMartin Kepplinger }, 1787e906103SLorenzo Bianconi .irq_config = { 1797e906103SLorenzo Bianconi .irq1 = { 1807e906103SLorenzo Bianconi .addr = 0x0c, 1817e906103SLorenzo Bianconi .mask = BIT(3), 1827e906103SLorenzo Bianconi }, 1837e906103SLorenzo Bianconi .irq2 = { 1847e906103SLorenzo Bianconi .addr = 0x0d, 1857e906103SLorenzo Bianconi .mask = BIT(3), 1867e906103SLorenzo Bianconi }, 18731fe8d4eSLorenzo Bianconi .hla = { 18831fe8d4eSLorenzo Bianconi .addr = 0x22, 18931fe8d4eSLorenzo Bianconi .mask = BIT(5), 19031fe8d4eSLorenzo Bianconi }, 19131fe8d4eSLorenzo Bianconi .od = { 19231fe8d4eSLorenzo Bianconi .addr = 0x22, 19331fe8d4eSLorenzo Bianconi .mask = BIT(4), 19431fe8d4eSLorenzo Bianconi }, 1957e906103SLorenzo Bianconi }, 196*1b7da2faSLorenzo Bianconi .fifo_ops = { 197*1b7da2faSLorenzo Bianconi .max_size = 32, 198*1b7da2faSLorenzo Bianconi }, 19952f4b1f1SMartin Kepplinger }, 20052f4b1f1SMartin Kepplinger { 20166b662a1SLorenzo Bianconi .reset = { 20266b662a1SLorenzo Bianconi .addr = 0x12, 20366b662a1SLorenzo Bianconi .mask = BIT(0), 20466b662a1SLorenzo Bianconi }, 20566b662a1SLorenzo Bianconi .boot = { 20666b662a1SLorenzo Bianconi .addr = 0x12, 20766b662a1SLorenzo Bianconi .mask = BIT(7), 20866b662a1SLorenzo Bianconi }, 20966b662a1SLorenzo Bianconi .bdu = { 21066b662a1SLorenzo Bianconi .addr = 0x12, 21166b662a1SLorenzo Bianconi .mask = BIT(6), 21266b662a1SLorenzo Bianconi }, 213d068e4a0SLorenzo Bianconi .id = { 21481956a93SLorenzo Bianconi { 21581956a93SLorenzo Bianconi .hw_id = ST_LSM6DS3_ID, 21681956a93SLorenzo Bianconi .name = ST_LSM6DS3_DEV_NAME, 21798c3544aSLorenzo Bianconi .wai = 0x69, 21881956a93SLorenzo Bianconi }, 219d068e4a0SLorenzo Bianconi }, 220f48bc49bSLorenzo Bianconi .channels = { 221f48bc49bSLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 222f48bc49bSLorenzo Bianconi .chan = st_lsm6dsx_acc_channels, 223f48bc49bSLorenzo Bianconi .len = ARRAY_SIZE(st_lsm6dsx_acc_channels), 224f48bc49bSLorenzo Bianconi }, 225f48bc49bSLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 226f48bc49bSLorenzo Bianconi .chan = st_lsm6dsx_gyro_channels, 227f48bc49bSLorenzo Bianconi .len = ARRAY_SIZE(st_lsm6dsx_gyro_channels), 228f48bc49bSLorenzo Bianconi }, 229f48bc49bSLorenzo Bianconi }, 23040dd7343SLorenzo Bianconi .odr_table = { 23140dd7343SLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 23240dd7343SLorenzo Bianconi .reg = { 23340dd7343SLorenzo Bianconi .addr = 0x10, 23440dd7343SLorenzo Bianconi .mask = GENMASK(7, 4), 23540dd7343SLorenzo Bianconi }, 236f8710f03SLorenzo Bianconi .odr_avl[0] = { 12500, 0x01 }, 237f8710f03SLorenzo Bianconi .odr_avl[1] = { 26000, 0x02 }, 238f8710f03SLorenzo Bianconi .odr_avl[2] = { 52000, 0x03 }, 239f8710f03SLorenzo Bianconi .odr_avl[3] = { 104000, 0x04 }, 240f8710f03SLorenzo Bianconi .odr_avl[4] = { 208000, 0x05 }, 241f8710f03SLorenzo Bianconi .odr_avl[5] = { 416000, 0x06 }, 24259af4e20SLorenzo Bianconi .odr_len = 6, 24340dd7343SLorenzo Bianconi }, 24440dd7343SLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 24540dd7343SLorenzo Bianconi .reg = { 24640dd7343SLorenzo Bianconi .addr = 0x11, 24740dd7343SLorenzo Bianconi .mask = GENMASK(7, 4), 24840dd7343SLorenzo Bianconi }, 249f8710f03SLorenzo Bianconi .odr_avl[0] = { 12500, 0x01 }, 250f8710f03SLorenzo Bianconi .odr_avl[1] = { 26000, 0x02 }, 251f8710f03SLorenzo Bianconi .odr_avl[2] = { 52000, 0x03 }, 252f8710f03SLorenzo Bianconi .odr_avl[3] = { 104000, 0x04 }, 253f8710f03SLorenzo Bianconi .odr_avl[4] = { 208000, 0x05 }, 254f8710f03SLorenzo Bianconi .odr_avl[5] = { 416000, 0x06 }, 25559af4e20SLorenzo Bianconi .odr_len = 6, 25640dd7343SLorenzo Bianconi }, 25740dd7343SLorenzo Bianconi }, 258640aca3fSLorenzo Bianconi .fs_table = { 259640aca3fSLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 260640aca3fSLorenzo Bianconi .reg = { 261640aca3fSLorenzo Bianconi .addr = 0x10, 262640aca3fSLorenzo Bianconi .mask = GENMASK(3, 2), 263640aca3fSLorenzo Bianconi }, 26444a76de8SMario Tesi .fs_avl[0] = { IIO_G_TO_M_S_2(61000), 0x0 }, 26544a76de8SMario Tesi .fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 }, 26644a76de8SMario Tesi .fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 }, 26744a76de8SMario Tesi .fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 }, 26885ae3aeeSLorenzo Bianconi .fs_len = 4, 269640aca3fSLorenzo Bianconi }, 270640aca3fSLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 271640aca3fSLorenzo Bianconi .reg = { 272640aca3fSLorenzo Bianconi .addr = 0x11, 273640aca3fSLorenzo Bianconi .mask = GENMASK(3, 2), 274640aca3fSLorenzo Bianconi }, 27544a76de8SMario Tesi .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 }, 27644a76de8SMario Tesi .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 }, 27744a76de8SMario Tesi .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 }, 27844a76de8SMario Tesi .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 }, 27985ae3aeeSLorenzo Bianconi .fs_len = 4, 280640aca3fSLorenzo Bianconi }, 281640aca3fSLorenzo Bianconi }, 2827e906103SLorenzo Bianconi .irq_config = { 2837e906103SLorenzo Bianconi .irq1 = { 2847e906103SLorenzo Bianconi .addr = 0x0d, 2857e906103SLorenzo Bianconi .mask = BIT(3), 2867e906103SLorenzo Bianconi }, 2877e906103SLorenzo Bianconi .irq2 = { 2887e906103SLorenzo Bianconi .addr = 0x0e, 2897e906103SLorenzo Bianconi .mask = BIT(3), 2907e906103SLorenzo Bianconi }, 2917e906103SLorenzo Bianconi .lir = { 2927e906103SLorenzo Bianconi .addr = 0x58, 2937e906103SLorenzo Bianconi .mask = BIT(0), 2947e906103SLorenzo Bianconi }, 2957e906103SLorenzo Bianconi .irq1_func = { 2967e906103SLorenzo Bianconi .addr = 0x5e, 2977e906103SLorenzo Bianconi .mask = BIT(5), 2987e906103SLorenzo Bianconi }, 2997e906103SLorenzo Bianconi .irq2_func = { 3007e906103SLorenzo Bianconi .addr = 0x5f, 3017e906103SLorenzo Bianconi .mask = BIT(5), 3027e906103SLorenzo Bianconi }, 30331fe8d4eSLorenzo Bianconi .hla = { 30431fe8d4eSLorenzo Bianconi .addr = 0x12, 30531fe8d4eSLorenzo Bianconi .mask = BIT(5), 30631fe8d4eSLorenzo Bianconi }, 30731fe8d4eSLorenzo Bianconi .od = { 30831fe8d4eSLorenzo Bianconi .addr = 0x12, 30931fe8d4eSLorenzo Bianconi .mask = BIT(4), 31031fe8d4eSLorenzo Bianconi }, 3117e906103SLorenzo Bianconi }, 3127ca3ac9eSLorenzo Bianconi .decimator = { 3137ca3ac9eSLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 3147ca3ac9eSLorenzo Bianconi .addr = 0x08, 3157ca3ac9eSLorenzo Bianconi .mask = GENMASK(2, 0), 3167ca3ac9eSLorenzo Bianconi }, 3177ca3ac9eSLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 3187ca3ac9eSLorenzo Bianconi .addr = 0x08, 3197ca3ac9eSLorenzo Bianconi .mask = GENMASK(5, 3), 3207ca3ac9eSLorenzo Bianconi }, 3217ca3ac9eSLorenzo Bianconi }, 32292617c15SLorenzo Bianconi .fifo_ops = { 3233b72950dSLorenzo Bianconi .update_fifo = st_lsm6dsx_update_fifo, 32450ff457dSLorenzo Bianconi .read_fifo = st_lsm6dsx_read_fifo, 32592617c15SLorenzo Bianconi .fifo_th = { 32692617c15SLorenzo Bianconi .addr = 0x06, 32792617c15SLorenzo Bianconi .mask = GENMASK(11, 0), 32892617c15SLorenzo Bianconi }, 32992617c15SLorenzo Bianconi .fifo_diff = { 33092617c15SLorenzo Bianconi .addr = 0x3a, 33192617c15SLorenzo Bianconi .mask = GENMASK(11, 0), 33292617c15SLorenzo Bianconi }, 333*1b7da2faSLorenzo Bianconi .max_size = 1365, 33492617c15SLorenzo Bianconi .th_wl = 3, /* 1LSB = 2B */ 33592617c15SLorenzo Bianconi }, 33621345107SLorenzo Bianconi .ts_settings = { 33721345107SLorenzo Bianconi .timer_en = { 33821345107SLorenzo Bianconi .addr = 0x58, 33921345107SLorenzo Bianconi .mask = BIT(7), 34021345107SLorenzo Bianconi }, 34121345107SLorenzo Bianconi .hr_timer = { 34221345107SLorenzo Bianconi .addr = 0x5c, 34321345107SLorenzo Bianconi .mask = BIT(4), 34421345107SLorenzo Bianconi }, 34521345107SLorenzo Bianconi .fifo_en = { 34621345107SLorenzo Bianconi .addr = 0x07, 34721345107SLorenzo Bianconi .mask = BIT(7), 34821345107SLorenzo Bianconi }, 34921345107SLorenzo Bianconi .decimator = { 35021345107SLorenzo Bianconi .addr = 0x09, 35121345107SLorenzo Bianconi .mask = GENMASK(5, 3), 35221345107SLorenzo Bianconi }, 35321345107SLorenzo Bianconi }, 354b5969abfSSean Nyekjaer .event_settings = { 355b5969abfSSean Nyekjaer .wakeup_reg = { 356b5969abfSSean Nyekjaer .addr = 0x5B, 357b5969abfSSean Nyekjaer .mask = GENMASK(5, 0), 358b5969abfSSean Nyekjaer }, 3591aabad1fSSean Nyekjaer .wakeup_src_reg = 0x1b, 3601aabad1fSSean Nyekjaer .wakeup_src_status_mask = BIT(3), 3611aabad1fSSean Nyekjaer .wakeup_src_z_mask = BIT(0), 3621aabad1fSSean Nyekjaer .wakeup_src_y_mask = BIT(1), 3631aabad1fSSean Nyekjaer .wakeup_src_x_mask = BIT(2), 364b5969abfSSean Nyekjaer }, 365290a6ce1SLorenzo Bianconi }, 366290a6ce1SLorenzo Bianconi { 36766b662a1SLorenzo Bianconi .reset = { 36866b662a1SLorenzo Bianconi .addr = 0x12, 36966b662a1SLorenzo Bianconi .mask = BIT(0), 37066b662a1SLorenzo Bianconi }, 37166b662a1SLorenzo Bianconi .boot = { 37266b662a1SLorenzo Bianconi .addr = 0x12, 37366b662a1SLorenzo Bianconi .mask = BIT(7), 37466b662a1SLorenzo Bianconi }, 37566b662a1SLorenzo Bianconi .bdu = { 37666b662a1SLorenzo Bianconi .addr = 0x12, 37766b662a1SLorenzo Bianconi .mask = BIT(6), 37866b662a1SLorenzo Bianconi }, 379df47710aSLorenzo Bianconi .id = { 38081956a93SLorenzo Bianconi { 38181956a93SLorenzo Bianconi .hw_id = ST_LSM6DS3H_ID, 38281956a93SLorenzo Bianconi .name = ST_LSM6DS3H_DEV_NAME, 38398c3544aSLorenzo Bianconi .wai = 0x69, 38481956a93SLorenzo Bianconi }, 385df47710aSLorenzo Bianconi }, 386f48bc49bSLorenzo Bianconi .channels = { 387f48bc49bSLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 388f48bc49bSLorenzo Bianconi .chan = st_lsm6dsx_acc_channels, 389f48bc49bSLorenzo Bianconi .len = ARRAY_SIZE(st_lsm6dsx_acc_channels), 390f48bc49bSLorenzo Bianconi }, 391f48bc49bSLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 392f48bc49bSLorenzo Bianconi .chan = st_lsm6dsx_gyro_channels, 393f48bc49bSLorenzo Bianconi .len = ARRAY_SIZE(st_lsm6dsx_gyro_channels), 394f48bc49bSLorenzo Bianconi }, 395f48bc49bSLorenzo Bianconi }, 39640dd7343SLorenzo Bianconi .odr_table = { 39740dd7343SLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 39840dd7343SLorenzo Bianconi .reg = { 39940dd7343SLorenzo Bianconi .addr = 0x10, 40040dd7343SLorenzo Bianconi .mask = GENMASK(7, 4), 40140dd7343SLorenzo Bianconi }, 402f8710f03SLorenzo Bianconi .odr_avl[0] = { 12500, 0x01 }, 403f8710f03SLorenzo Bianconi .odr_avl[1] = { 26000, 0x02 }, 404f8710f03SLorenzo Bianconi .odr_avl[2] = { 52000, 0x03 }, 405f8710f03SLorenzo Bianconi .odr_avl[3] = { 104000, 0x04 }, 406f8710f03SLorenzo Bianconi .odr_avl[4] = { 208000, 0x05 }, 407f8710f03SLorenzo Bianconi .odr_avl[5] = { 416000, 0x06 }, 40859af4e20SLorenzo Bianconi .odr_len = 6, 40940dd7343SLorenzo Bianconi }, 41040dd7343SLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 41140dd7343SLorenzo Bianconi .reg = { 41240dd7343SLorenzo Bianconi .addr = 0x11, 41340dd7343SLorenzo Bianconi .mask = GENMASK(7, 4), 41440dd7343SLorenzo Bianconi }, 415f8710f03SLorenzo Bianconi .odr_avl[0] = { 12500, 0x01 }, 416f8710f03SLorenzo Bianconi .odr_avl[1] = { 26000, 0x02 }, 417f8710f03SLorenzo Bianconi .odr_avl[2] = { 52000, 0x03 }, 418f8710f03SLorenzo Bianconi .odr_avl[3] = { 104000, 0x04 }, 419f8710f03SLorenzo Bianconi .odr_avl[4] = { 208000, 0x05 }, 420f8710f03SLorenzo Bianconi .odr_avl[5] = { 416000, 0x06 }, 42159af4e20SLorenzo Bianconi .odr_len = 6, 42240dd7343SLorenzo Bianconi }, 42340dd7343SLorenzo Bianconi }, 424640aca3fSLorenzo Bianconi .fs_table = { 425640aca3fSLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 426640aca3fSLorenzo Bianconi .reg = { 427640aca3fSLorenzo Bianconi .addr = 0x10, 428640aca3fSLorenzo Bianconi .mask = GENMASK(3, 2), 429640aca3fSLorenzo Bianconi }, 43044a76de8SMario Tesi .fs_avl[0] = { IIO_G_TO_M_S_2(61000), 0x0 }, 43144a76de8SMario Tesi .fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 }, 43244a76de8SMario Tesi .fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 }, 43344a76de8SMario Tesi .fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 }, 43485ae3aeeSLorenzo Bianconi .fs_len = 4, 435640aca3fSLorenzo Bianconi }, 436640aca3fSLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 437640aca3fSLorenzo Bianconi .reg = { 438640aca3fSLorenzo Bianconi .addr = 0x11, 439640aca3fSLorenzo Bianconi .mask = GENMASK(3, 2), 440640aca3fSLorenzo Bianconi }, 44144a76de8SMario Tesi .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 }, 44244a76de8SMario Tesi .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 }, 44344a76de8SMario Tesi .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 }, 44444a76de8SMario Tesi .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 }, 44585ae3aeeSLorenzo Bianconi .fs_len = 4, 446640aca3fSLorenzo Bianconi }, 447640aca3fSLorenzo Bianconi }, 4487e906103SLorenzo Bianconi .irq_config = { 4497e906103SLorenzo Bianconi .irq1 = { 4507e906103SLorenzo Bianconi .addr = 0x0d, 4517e906103SLorenzo Bianconi .mask = BIT(3), 4527e906103SLorenzo Bianconi }, 4537e906103SLorenzo Bianconi .irq2 = { 4547e906103SLorenzo Bianconi .addr = 0x0e, 4557e906103SLorenzo Bianconi .mask = BIT(3), 4567e906103SLorenzo Bianconi }, 4577e906103SLorenzo Bianconi .lir = { 4587e906103SLorenzo Bianconi .addr = 0x58, 4597e906103SLorenzo Bianconi .mask = BIT(0), 4607e906103SLorenzo Bianconi }, 4617e906103SLorenzo Bianconi .irq1_func = { 4627e906103SLorenzo Bianconi .addr = 0x5e, 4637e906103SLorenzo Bianconi .mask = BIT(5), 4647e906103SLorenzo Bianconi }, 4657e906103SLorenzo Bianconi .irq2_func = { 4667e906103SLorenzo Bianconi .addr = 0x5f, 4677e906103SLorenzo Bianconi .mask = BIT(5), 4687e906103SLorenzo Bianconi }, 46931fe8d4eSLorenzo Bianconi .hla = { 47031fe8d4eSLorenzo Bianconi .addr = 0x12, 47131fe8d4eSLorenzo Bianconi .mask = BIT(5), 47231fe8d4eSLorenzo Bianconi }, 47331fe8d4eSLorenzo Bianconi .od = { 47431fe8d4eSLorenzo Bianconi .addr = 0x12, 47531fe8d4eSLorenzo Bianconi .mask = BIT(4), 47631fe8d4eSLorenzo Bianconi }, 4777e906103SLorenzo Bianconi }, 4787ca3ac9eSLorenzo Bianconi .decimator = { 4797ca3ac9eSLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 4807ca3ac9eSLorenzo Bianconi .addr = 0x08, 4817ca3ac9eSLorenzo Bianconi .mask = GENMASK(2, 0), 4827ca3ac9eSLorenzo Bianconi }, 4837ca3ac9eSLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 4847ca3ac9eSLorenzo Bianconi .addr = 0x08, 4857ca3ac9eSLorenzo Bianconi .mask = GENMASK(5, 3), 4867ca3ac9eSLorenzo Bianconi }, 4877ca3ac9eSLorenzo Bianconi }, 48892617c15SLorenzo Bianconi .fifo_ops = { 4893b72950dSLorenzo Bianconi .update_fifo = st_lsm6dsx_update_fifo, 49050ff457dSLorenzo Bianconi .read_fifo = st_lsm6dsx_read_fifo, 49192617c15SLorenzo Bianconi .fifo_th = { 49292617c15SLorenzo Bianconi .addr = 0x06, 49392617c15SLorenzo Bianconi .mask = GENMASK(11, 0), 49492617c15SLorenzo Bianconi }, 49592617c15SLorenzo Bianconi .fifo_diff = { 49692617c15SLorenzo Bianconi .addr = 0x3a, 49792617c15SLorenzo Bianconi .mask = GENMASK(11, 0), 49892617c15SLorenzo Bianconi }, 499*1b7da2faSLorenzo Bianconi .max_size = 682, 50092617c15SLorenzo Bianconi .th_wl = 3, /* 1LSB = 2B */ 50192617c15SLorenzo Bianconi }, 50221345107SLorenzo Bianconi .ts_settings = { 50321345107SLorenzo Bianconi .timer_en = { 50421345107SLorenzo Bianconi .addr = 0x58, 50521345107SLorenzo Bianconi .mask = BIT(7), 50621345107SLorenzo Bianconi }, 50721345107SLorenzo Bianconi .hr_timer = { 50821345107SLorenzo Bianconi .addr = 0x5c, 50921345107SLorenzo Bianconi .mask = BIT(4), 51021345107SLorenzo Bianconi }, 51121345107SLorenzo Bianconi .fifo_en = { 51221345107SLorenzo Bianconi .addr = 0x07, 51321345107SLorenzo Bianconi .mask = BIT(7), 51421345107SLorenzo Bianconi }, 51521345107SLorenzo Bianconi .decimator = { 51621345107SLorenzo Bianconi .addr = 0x09, 51721345107SLorenzo Bianconi .mask = GENMASK(5, 3), 51821345107SLorenzo Bianconi }, 51921345107SLorenzo Bianconi }, 520b5969abfSSean Nyekjaer .event_settings = { 521b5969abfSSean Nyekjaer .wakeup_reg = { 522b5969abfSSean Nyekjaer .addr = 0x5B, 523b5969abfSSean Nyekjaer .mask = GENMASK(5, 0), 524b5969abfSSean Nyekjaer }, 5251aabad1fSSean Nyekjaer .wakeup_src_reg = 0x1b, 5261aabad1fSSean Nyekjaer .wakeup_src_status_mask = BIT(3), 5271aabad1fSSean Nyekjaer .wakeup_src_z_mask = BIT(0), 5281aabad1fSSean Nyekjaer .wakeup_src_y_mask = BIT(1), 5291aabad1fSSean Nyekjaer .wakeup_src_x_mask = BIT(2), 530b5969abfSSean Nyekjaer }, 531df47710aSLorenzo Bianconi }, 532df47710aSLorenzo Bianconi { 53366b662a1SLorenzo Bianconi .reset = { 53466b662a1SLorenzo Bianconi .addr = 0x12, 53566b662a1SLorenzo Bianconi .mask = BIT(0), 53666b662a1SLorenzo Bianconi }, 53766b662a1SLorenzo Bianconi .boot = { 53866b662a1SLorenzo Bianconi .addr = 0x12, 53966b662a1SLorenzo Bianconi .mask = BIT(7), 54066b662a1SLorenzo Bianconi }, 54166b662a1SLorenzo Bianconi .bdu = { 54266b662a1SLorenzo Bianconi .addr = 0x12, 54366b662a1SLorenzo Bianconi .mask = BIT(6), 54466b662a1SLorenzo Bianconi }, 545d068e4a0SLorenzo Bianconi .id = { 54681956a93SLorenzo Bianconi { 54781956a93SLorenzo Bianconi .hw_id = ST_LSM6DSL_ID, 54881956a93SLorenzo Bianconi .name = ST_LSM6DSL_DEV_NAME, 54998c3544aSLorenzo Bianconi .wai = 0x6a, 55081956a93SLorenzo Bianconi }, { 55181956a93SLorenzo Bianconi .hw_id = ST_LSM6DSM_ID, 55281956a93SLorenzo Bianconi .name = ST_LSM6DSM_DEV_NAME, 55398c3544aSLorenzo Bianconi .wai = 0x6a, 55481956a93SLorenzo Bianconi }, { 55581956a93SLorenzo Bianconi .hw_id = ST_ISM330DLC_ID, 55681956a93SLorenzo Bianconi .name = ST_ISM330DLC_DEV_NAME, 55798c3544aSLorenzo Bianconi .wai = 0x6a, 558dbcd2088SLorenzo Bianconi }, { 559dbcd2088SLorenzo Bianconi .hw_id = ST_LSM6DS3TRC_ID, 560dbcd2088SLorenzo Bianconi .name = ST_LSM6DS3TRC_DEV_NAME, 56198c3544aSLorenzo Bianconi .wai = 0x6a, 56281956a93SLorenzo Bianconi }, 563d068e4a0SLorenzo Bianconi }, 564f48bc49bSLorenzo Bianconi .channels = { 565f48bc49bSLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 566f48bc49bSLorenzo Bianconi .chan = st_lsm6dsx_acc_channels, 567f48bc49bSLorenzo Bianconi .len = ARRAY_SIZE(st_lsm6dsx_acc_channels), 568f48bc49bSLorenzo Bianconi }, 569f48bc49bSLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 570f48bc49bSLorenzo Bianconi .chan = st_lsm6dsx_gyro_channels, 571f48bc49bSLorenzo Bianconi .len = ARRAY_SIZE(st_lsm6dsx_gyro_channels), 572f48bc49bSLorenzo Bianconi }, 573f48bc49bSLorenzo Bianconi }, 57440dd7343SLorenzo Bianconi .odr_table = { 57540dd7343SLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 57640dd7343SLorenzo Bianconi .reg = { 57740dd7343SLorenzo Bianconi .addr = 0x10, 57840dd7343SLorenzo Bianconi .mask = GENMASK(7, 4), 57940dd7343SLorenzo Bianconi }, 580f8710f03SLorenzo Bianconi .odr_avl[0] = { 12500, 0x01 }, 581f8710f03SLorenzo Bianconi .odr_avl[1] = { 26000, 0x02 }, 582f8710f03SLorenzo Bianconi .odr_avl[2] = { 52000, 0x03 }, 583f8710f03SLorenzo Bianconi .odr_avl[3] = { 104000, 0x04 }, 584f8710f03SLorenzo Bianconi .odr_avl[4] = { 208000, 0x05 }, 585f8710f03SLorenzo Bianconi .odr_avl[5] = { 416000, 0x06 }, 58659af4e20SLorenzo Bianconi .odr_len = 6, 58740dd7343SLorenzo Bianconi }, 58840dd7343SLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 58940dd7343SLorenzo Bianconi .reg = { 59040dd7343SLorenzo Bianconi .addr = 0x11, 59140dd7343SLorenzo Bianconi .mask = GENMASK(7, 4), 59240dd7343SLorenzo Bianconi }, 593f8710f03SLorenzo Bianconi .odr_avl[0] = { 12500, 0x01 }, 594f8710f03SLorenzo Bianconi .odr_avl[1] = { 26000, 0x02 }, 595f8710f03SLorenzo Bianconi .odr_avl[2] = { 52000, 0x03 }, 596f8710f03SLorenzo Bianconi .odr_avl[3] = { 104000, 0x04 }, 597f8710f03SLorenzo Bianconi .odr_avl[4] = { 208000, 0x05 }, 598f8710f03SLorenzo Bianconi .odr_avl[5] = { 416000, 0x06 }, 59959af4e20SLorenzo Bianconi .odr_len = 6, 60040dd7343SLorenzo Bianconi }, 60140dd7343SLorenzo Bianconi }, 602640aca3fSLorenzo Bianconi .fs_table = { 603640aca3fSLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 604640aca3fSLorenzo Bianconi .reg = { 605640aca3fSLorenzo Bianconi .addr = 0x10, 606640aca3fSLorenzo Bianconi .mask = GENMASK(3, 2), 607640aca3fSLorenzo Bianconi }, 60844a76de8SMario Tesi .fs_avl[0] = { IIO_G_TO_M_S_2(61000), 0x0 }, 60944a76de8SMario Tesi .fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 }, 61044a76de8SMario Tesi .fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 }, 61144a76de8SMario Tesi .fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 }, 61285ae3aeeSLorenzo Bianconi .fs_len = 4, 613640aca3fSLorenzo Bianconi }, 614640aca3fSLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 615640aca3fSLorenzo Bianconi .reg = { 616640aca3fSLorenzo Bianconi .addr = 0x11, 617640aca3fSLorenzo Bianconi .mask = GENMASK(3, 2), 618640aca3fSLorenzo Bianconi }, 61944a76de8SMario Tesi .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 }, 62044a76de8SMario Tesi .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 }, 62144a76de8SMario Tesi .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 }, 62244a76de8SMario Tesi .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 }, 62385ae3aeeSLorenzo Bianconi .fs_len = 4, 624640aca3fSLorenzo Bianconi }, 625640aca3fSLorenzo Bianconi }, 6267e906103SLorenzo Bianconi .irq_config = { 6277e906103SLorenzo Bianconi .irq1 = { 6287e906103SLorenzo Bianconi .addr = 0x0d, 6297e906103SLorenzo Bianconi .mask = BIT(3), 6307e906103SLorenzo Bianconi }, 6317e906103SLorenzo Bianconi .irq2 = { 6327e906103SLorenzo Bianconi .addr = 0x0e, 6337e906103SLorenzo Bianconi .mask = BIT(3), 6347e906103SLorenzo Bianconi }, 6357e906103SLorenzo Bianconi .lir = { 6367e906103SLorenzo Bianconi .addr = 0x58, 6377e906103SLorenzo Bianconi .mask = BIT(0), 6387e906103SLorenzo Bianconi }, 6397e906103SLorenzo Bianconi .irq1_func = { 6407e906103SLorenzo Bianconi .addr = 0x5e, 6417e906103SLorenzo Bianconi .mask = BIT(5), 6427e906103SLorenzo Bianconi }, 6437e906103SLorenzo Bianconi .irq2_func = { 6447e906103SLorenzo Bianconi .addr = 0x5f, 6457e906103SLorenzo Bianconi .mask = BIT(5), 6467e906103SLorenzo Bianconi }, 64731fe8d4eSLorenzo Bianconi .hla = { 64831fe8d4eSLorenzo Bianconi .addr = 0x12, 64931fe8d4eSLorenzo Bianconi .mask = BIT(5), 65031fe8d4eSLorenzo Bianconi }, 65131fe8d4eSLorenzo Bianconi .od = { 65231fe8d4eSLorenzo Bianconi .addr = 0x12, 65331fe8d4eSLorenzo Bianconi .mask = BIT(4), 65431fe8d4eSLorenzo Bianconi }, 6557e906103SLorenzo Bianconi }, 6567ca3ac9eSLorenzo Bianconi .decimator = { 6577ca3ac9eSLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 6587ca3ac9eSLorenzo Bianconi .addr = 0x08, 6597ca3ac9eSLorenzo Bianconi .mask = GENMASK(2, 0), 6607ca3ac9eSLorenzo Bianconi }, 6617ca3ac9eSLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 6627ca3ac9eSLorenzo Bianconi .addr = 0x08, 6637ca3ac9eSLorenzo Bianconi .mask = GENMASK(5, 3), 6647ca3ac9eSLorenzo Bianconi }, 665e485e2a2SLorenzo Bianconi [ST_LSM6DSX_ID_EXT0] = { 666e485e2a2SLorenzo Bianconi .addr = 0x09, 667e485e2a2SLorenzo Bianconi .mask = GENMASK(2, 0), 668e485e2a2SLorenzo Bianconi }, 6697ca3ac9eSLorenzo Bianconi }, 67092617c15SLorenzo Bianconi .fifo_ops = { 6713b72950dSLorenzo Bianconi .update_fifo = st_lsm6dsx_update_fifo, 67250ff457dSLorenzo Bianconi .read_fifo = st_lsm6dsx_read_fifo, 67392617c15SLorenzo Bianconi .fifo_th = { 67492617c15SLorenzo Bianconi .addr = 0x06, 675be75eb86SLorenzo Bianconi .mask = GENMASK(10, 0), 67692617c15SLorenzo Bianconi }, 67792617c15SLorenzo Bianconi .fifo_diff = { 67892617c15SLorenzo Bianconi .addr = 0x3a, 679be75eb86SLorenzo Bianconi .mask = GENMASK(10, 0), 68092617c15SLorenzo Bianconi }, 681*1b7da2faSLorenzo Bianconi .max_size = 682, 68292617c15SLorenzo Bianconi .th_wl = 3, /* 1LSB = 2B */ 68392617c15SLorenzo Bianconi }, 68421345107SLorenzo Bianconi .ts_settings = { 68521345107SLorenzo Bianconi .timer_en = { 68621345107SLorenzo Bianconi .addr = 0x19, 68721345107SLorenzo Bianconi .mask = BIT(5), 68821345107SLorenzo Bianconi }, 68921345107SLorenzo Bianconi .hr_timer = { 69021345107SLorenzo Bianconi .addr = 0x5c, 69121345107SLorenzo Bianconi .mask = BIT(4), 69221345107SLorenzo Bianconi }, 69321345107SLorenzo Bianconi .fifo_en = { 69421345107SLorenzo Bianconi .addr = 0x07, 69521345107SLorenzo Bianconi .mask = BIT(7), 69621345107SLorenzo Bianconi }, 69721345107SLorenzo Bianconi .decimator = { 69821345107SLorenzo Bianconi .addr = 0x09, 69921345107SLorenzo Bianconi .mask = GENMASK(5, 3), 70021345107SLorenzo Bianconi }, 70121345107SLorenzo Bianconi }, 702e485e2a2SLorenzo Bianconi .shub_settings = { 703e485e2a2SLorenzo Bianconi .page_mux = { 704e485e2a2SLorenzo Bianconi .addr = 0x01, 705e485e2a2SLorenzo Bianconi .mask = BIT(7), 706e485e2a2SLorenzo Bianconi }, 707e485e2a2SLorenzo Bianconi .master_en = { 708e485e2a2SLorenzo Bianconi .addr = 0x1a, 709e485e2a2SLorenzo Bianconi .mask = BIT(0), 710e485e2a2SLorenzo Bianconi }, 711e485e2a2SLorenzo Bianconi .pullup_en = { 712e485e2a2SLorenzo Bianconi .addr = 0x1a, 713e485e2a2SLorenzo Bianconi .mask = BIT(3), 714e485e2a2SLorenzo Bianconi }, 715e485e2a2SLorenzo Bianconi .aux_sens = { 716e485e2a2SLorenzo Bianconi .addr = 0x04, 717e485e2a2SLorenzo Bianconi .mask = GENMASK(5, 4), 718e485e2a2SLorenzo Bianconi }, 719e485e2a2SLorenzo Bianconi .wr_once = { 720e485e2a2SLorenzo Bianconi .addr = 0x07, 721e485e2a2SLorenzo Bianconi .mask = BIT(5), 722e485e2a2SLorenzo Bianconi }, 723e485e2a2SLorenzo Bianconi .emb_func = { 724e485e2a2SLorenzo Bianconi .addr = 0x19, 725e485e2a2SLorenzo Bianconi .mask = BIT(2), 726e485e2a2SLorenzo Bianconi }, 727e485e2a2SLorenzo Bianconi .num_ext_dev = 1, 728e485e2a2SLorenzo Bianconi .shub_out = { 729e485e2a2SLorenzo Bianconi .addr = 0x2e, 730e485e2a2SLorenzo Bianconi }, 731e485e2a2SLorenzo Bianconi .slv0_addr = 0x02, 732e485e2a2SLorenzo Bianconi .dw_slv0_addr = 0x0e, 733e485e2a2SLorenzo Bianconi .pause = 0x7, 734e485e2a2SLorenzo Bianconi }, 735b5969abfSSean Nyekjaer .event_settings = { 736b5969abfSSean Nyekjaer .enable_reg = { 737b5969abfSSean Nyekjaer .addr = 0x58, 738b5969abfSSean Nyekjaer .mask = BIT(7), 739b5969abfSSean Nyekjaer }, 740b5969abfSSean Nyekjaer .wakeup_reg = { 741b5969abfSSean Nyekjaer .addr = 0x5B, 742b5969abfSSean Nyekjaer .mask = GENMASK(5, 0), 743b5969abfSSean Nyekjaer }, 7441aabad1fSSean Nyekjaer .wakeup_src_reg = 0x1b, 7451aabad1fSSean Nyekjaer .wakeup_src_status_mask = BIT(3), 7461aabad1fSSean Nyekjaer .wakeup_src_z_mask = BIT(0), 7471aabad1fSSean Nyekjaer .wakeup_src_y_mask = BIT(1), 7481aabad1fSSean Nyekjaer .wakeup_src_x_mask = BIT(2), 749b5969abfSSean Nyekjaer }, 750290a6ce1SLorenzo Bianconi }, 751801a6e0aSLorenzo Bianconi { 75266b662a1SLorenzo Bianconi .reset = { 75366b662a1SLorenzo Bianconi .addr = 0x12, 75466b662a1SLorenzo Bianconi .mask = BIT(0), 75566b662a1SLorenzo Bianconi }, 75666b662a1SLorenzo Bianconi .boot = { 75766b662a1SLorenzo Bianconi .addr = 0x12, 75866b662a1SLorenzo Bianconi .mask = BIT(7), 75966b662a1SLorenzo Bianconi }, 76066b662a1SLorenzo Bianconi .bdu = { 76166b662a1SLorenzo Bianconi .addr = 0x12, 76266b662a1SLorenzo Bianconi .mask = BIT(6), 76366b662a1SLorenzo Bianconi }, 76443901008SLorenzo Bianconi .id = { 76581956a93SLorenzo Bianconi { 76681956a93SLorenzo Bianconi .hw_id = ST_LSM6DSR_ID, 76781956a93SLorenzo Bianconi .name = ST_LSM6DSR_DEV_NAME, 76898c3544aSLorenzo Bianconi .wai = 0x6b, 769db947a79SLorenzo Bianconi }, { 770db947a79SLorenzo Bianconi .hw_id = ST_ISM330DHCX_ID, 771db947a79SLorenzo Bianconi .name = ST_ISM330DHCX_DEV_NAME, 77298c3544aSLorenzo Bianconi .wai = 0x6b, 773cf9c71b3SLorenzo Bianconi }, { 774cf9c71b3SLorenzo Bianconi .hw_id = ST_LSM6DSRX_ID, 775cf9c71b3SLorenzo Bianconi .name = ST_LSM6DSRX_DEV_NAME, 77698c3544aSLorenzo Bianconi .wai = 0x6b, 77798c3544aSLorenzo Bianconi }, { 77898c3544aSLorenzo Bianconi .hw_id = ST_LSM6DSO_ID, 77998c3544aSLorenzo Bianconi .name = ST_LSM6DSO_DEV_NAME, 78098c3544aSLorenzo Bianconi .wai = 0x6c, 78198c3544aSLorenzo Bianconi }, { 78298c3544aSLorenzo Bianconi .hw_id = ST_LSM6DSOX_ID, 78398c3544aSLorenzo Bianconi .name = ST_LSM6DSOX_DEV_NAME, 78498c3544aSLorenzo Bianconi .wai = 0x6c, 78598c3544aSLorenzo Bianconi }, { 7864393e4c5SLorenzo Bianconi .hw_id = ST_LSM6DST_ID, 7874393e4c5SLorenzo Bianconi .name = ST_LSM6DST_DEV_NAME, 78898c3544aSLorenzo Bianconi .wai = 0x6d, 7894393e4c5SLorenzo Bianconi }, 7904393e4c5SLorenzo Bianconi }, 7914393e4c5SLorenzo Bianconi .channels = { 7924393e4c5SLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 7934393e4c5SLorenzo Bianconi .chan = st_lsm6dsx_acc_channels, 7944393e4c5SLorenzo Bianconi .len = ARRAY_SIZE(st_lsm6dsx_acc_channels), 7954393e4c5SLorenzo Bianconi }, 7964393e4c5SLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 7974393e4c5SLorenzo Bianconi .chan = st_lsm6dsx_gyro_channels, 7984393e4c5SLorenzo Bianconi .len = ARRAY_SIZE(st_lsm6dsx_gyro_channels), 7994393e4c5SLorenzo Bianconi }, 8004393e4c5SLorenzo Bianconi }, 8014393e4c5SLorenzo Bianconi .drdy_mask = { 8024393e4c5SLorenzo Bianconi .addr = 0x13, 8034393e4c5SLorenzo Bianconi .mask = BIT(3), 8044393e4c5SLorenzo Bianconi }, 8054393e4c5SLorenzo Bianconi .odr_table = { 8064393e4c5SLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 8074393e4c5SLorenzo Bianconi .reg = { 8084393e4c5SLorenzo Bianconi .addr = 0x10, 8094393e4c5SLorenzo Bianconi .mask = GENMASK(7, 4), 8104393e4c5SLorenzo Bianconi }, 8114393e4c5SLorenzo Bianconi .odr_avl[0] = { 12500, 0x01 }, 8124393e4c5SLorenzo Bianconi .odr_avl[1] = { 26000, 0x02 }, 8134393e4c5SLorenzo Bianconi .odr_avl[2] = { 52000, 0x03 }, 8144393e4c5SLorenzo Bianconi .odr_avl[3] = { 104000, 0x04 }, 8154393e4c5SLorenzo Bianconi .odr_avl[4] = { 208000, 0x05 }, 8164393e4c5SLorenzo Bianconi .odr_avl[5] = { 416000, 0x06 }, 8174393e4c5SLorenzo Bianconi .odr_avl[6] = { 833000, 0x07 }, 8184393e4c5SLorenzo Bianconi .odr_len = 7, 8194393e4c5SLorenzo Bianconi }, 8204393e4c5SLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 8214393e4c5SLorenzo Bianconi .reg = { 8224393e4c5SLorenzo Bianconi .addr = 0x11, 8234393e4c5SLorenzo Bianconi .mask = GENMASK(7, 4), 8244393e4c5SLorenzo Bianconi }, 8254393e4c5SLorenzo Bianconi .odr_avl[0] = { 12500, 0x01 }, 8264393e4c5SLorenzo Bianconi .odr_avl[1] = { 26000, 0x02 }, 8274393e4c5SLorenzo Bianconi .odr_avl[2] = { 52000, 0x03 }, 8284393e4c5SLorenzo Bianconi .odr_avl[3] = { 104000, 0x04 }, 8294393e4c5SLorenzo Bianconi .odr_avl[4] = { 208000, 0x05 }, 8304393e4c5SLorenzo Bianconi .odr_avl[5] = { 416000, 0x06 }, 8314393e4c5SLorenzo Bianconi .odr_avl[6] = { 833000, 0x07 }, 8324393e4c5SLorenzo Bianconi .odr_len = 7, 8334393e4c5SLorenzo Bianconi }, 8344393e4c5SLorenzo Bianconi }, 8354393e4c5SLorenzo Bianconi .fs_table = { 8364393e4c5SLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 8374393e4c5SLorenzo Bianconi .reg = { 8384393e4c5SLorenzo Bianconi .addr = 0x10, 8394393e4c5SLorenzo Bianconi .mask = GENMASK(3, 2), 8404393e4c5SLorenzo Bianconi }, 8414393e4c5SLorenzo Bianconi .fs_avl[0] = { IIO_G_TO_M_S_2(61000), 0x0 }, 8424393e4c5SLorenzo Bianconi .fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 }, 8434393e4c5SLorenzo Bianconi .fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 }, 8444393e4c5SLorenzo Bianconi .fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 }, 8454393e4c5SLorenzo Bianconi .fs_len = 4, 8464393e4c5SLorenzo Bianconi }, 8474393e4c5SLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 8484393e4c5SLorenzo Bianconi .reg = { 8494393e4c5SLorenzo Bianconi .addr = 0x11, 8504393e4c5SLorenzo Bianconi .mask = GENMASK(3, 2), 8514393e4c5SLorenzo Bianconi }, 8524393e4c5SLorenzo Bianconi .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 }, 8534393e4c5SLorenzo Bianconi .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 }, 8544393e4c5SLorenzo Bianconi .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 }, 8554393e4c5SLorenzo Bianconi .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 }, 8564393e4c5SLorenzo Bianconi .fs_len = 4, 8574393e4c5SLorenzo Bianconi }, 8584393e4c5SLorenzo Bianconi }, 8594393e4c5SLorenzo Bianconi .irq_config = { 8604393e4c5SLorenzo Bianconi .irq1 = { 8614393e4c5SLorenzo Bianconi .addr = 0x0d, 8624393e4c5SLorenzo Bianconi .mask = BIT(3), 8634393e4c5SLorenzo Bianconi }, 8644393e4c5SLorenzo Bianconi .irq2 = { 8654393e4c5SLorenzo Bianconi .addr = 0x0e, 8664393e4c5SLorenzo Bianconi .mask = BIT(3), 8674393e4c5SLorenzo Bianconi }, 8684393e4c5SLorenzo Bianconi .lir = { 8694393e4c5SLorenzo Bianconi .addr = 0x56, 8704393e4c5SLorenzo Bianconi .mask = BIT(0), 8714393e4c5SLorenzo Bianconi }, 8724393e4c5SLorenzo Bianconi .clear_on_read = { 8734393e4c5SLorenzo Bianconi .addr = 0x56, 8744393e4c5SLorenzo Bianconi .mask = BIT(6), 8754393e4c5SLorenzo Bianconi }, 8764393e4c5SLorenzo Bianconi .irq1_func = { 8774393e4c5SLorenzo Bianconi .addr = 0x5e, 8784393e4c5SLorenzo Bianconi .mask = BIT(5), 8794393e4c5SLorenzo Bianconi }, 8804393e4c5SLorenzo Bianconi .irq2_func = { 8814393e4c5SLorenzo Bianconi .addr = 0x5f, 8824393e4c5SLorenzo Bianconi .mask = BIT(5), 8834393e4c5SLorenzo Bianconi }, 8844393e4c5SLorenzo Bianconi .hla = { 8854393e4c5SLorenzo Bianconi .addr = 0x12, 8864393e4c5SLorenzo Bianconi .mask = BIT(5), 8874393e4c5SLorenzo Bianconi }, 8884393e4c5SLorenzo Bianconi .od = { 8894393e4c5SLorenzo Bianconi .addr = 0x12, 8904393e4c5SLorenzo Bianconi .mask = BIT(4), 8914393e4c5SLorenzo Bianconi }, 8924393e4c5SLorenzo Bianconi }, 8934393e4c5SLorenzo Bianconi .batch = { 8944393e4c5SLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 8954393e4c5SLorenzo Bianconi .addr = 0x09, 8964393e4c5SLorenzo Bianconi .mask = GENMASK(3, 0), 8974393e4c5SLorenzo Bianconi }, 8984393e4c5SLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 8994393e4c5SLorenzo Bianconi .addr = 0x09, 9004393e4c5SLorenzo Bianconi .mask = GENMASK(7, 4), 9014393e4c5SLorenzo Bianconi }, 9024393e4c5SLorenzo Bianconi }, 9034393e4c5SLorenzo Bianconi .fifo_ops = { 9044393e4c5SLorenzo Bianconi .update_fifo = st_lsm6dsx_update_fifo, 9054393e4c5SLorenzo Bianconi .read_fifo = st_lsm6dsx_read_tagged_fifo, 9064393e4c5SLorenzo Bianconi .fifo_th = { 9074393e4c5SLorenzo Bianconi .addr = 0x07, 9084393e4c5SLorenzo Bianconi .mask = GENMASK(8, 0), 9094393e4c5SLorenzo Bianconi }, 9104393e4c5SLorenzo Bianconi .fifo_diff = { 9114393e4c5SLorenzo Bianconi .addr = 0x3a, 9124393e4c5SLorenzo Bianconi .mask = GENMASK(9, 0), 9134393e4c5SLorenzo Bianconi }, 914*1b7da2faSLorenzo Bianconi .max_size = 512, 9154393e4c5SLorenzo Bianconi .th_wl = 1, 9164393e4c5SLorenzo Bianconi }, 9174393e4c5SLorenzo Bianconi .ts_settings = { 9184393e4c5SLorenzo Bianconi .timer_en = { 9194393e4c5SLorenzo Bianconi .addr = 0x19, 9204393e4c5SLorenzo Bianconi .mask = BIT(5), 9214393e4c5SLorenzo Bianconi }, 9224393e4c5SLorenzo Bianconi .decimator = { 9234393e4c5SLorenzo Bianconi .addr = 0x0a, 9244393e4c5SLorenzo Bianconi .mask = GENMASK(7, 6), 9254393e4c5SLorenzo Bianconi }, 9264393e4c5SLorenzo Bianconi .freq_fine = 0x63, 9274393e4c5SLorenzo Bianconi }, 9284393e4c5SLorenzo Bianconi .shub_settings = { 9294393e4c5SLorenzo Bianconi .page_mux = { 9304393e4c5SLorenzo Bianconi .addr = 0x01, 9314393e4c5SLorenzo Bianconi .mask = BIT(6), 9324393e4c5SLorenzo Bianconi }, 9334393e4c5SLorenzo Bianconi .master_en = { 9344393e4c5SLorenzo Bianconi .sec_page = true, 9354393e4c5SLorenzo Bianconi .addr = 0x14, 9364393e4c5SLorenzo Bianconi .mask = BIT(2), 9374393e4c5SLorenzo Bianconi }, 9384393e4c5SLorenzo Bianconi .pullup_en = { 9394393e4c5SLorenzo Bianconi .sec_page = true, 9404393e4c5SLorenzo Bianconi .addr = 0x14, 9414393e4c5SLorenzo Bianconi .mask = BIT(3), 9424393e4c5SLorenzo Bianconi }, 9434393e4c5SLorenzo Bianconi .aux_sens = { 9444393e4c5SLorenzo Bianconi .addr = 0x14, 9454393e4c5SLorenzo Bianconi .mask = GENMASK(1, 0), 9464393e4c5SLorenzo Bianconi }, 9474393e4c5SLorenzo Bianconi .wr_once = { 9484393e4c5SLorenzo Bianconi .addr = 0x14, 9494393e4c5SLorenzo Bianconi .mask = BIT(6), 9504393e4c5SLorenzo Bianconi }, 9514393e4c5SLorenzo Bianconi .num_ext_dev = 3, 9524393e4c5SLorenzo Bianconi .shub_out = { 9534393e4c5SLorenzo Bianconi .sec_page = true, 9544393e4c5SLorenzo Bianconi .addr = 0x02, 9554393e4c5SLorenzo Bianconi }, 9564393e4c5SLorenzo Bianconi .slv0_addr = 0x15, 9574393e4c5SLorenzo Bianconi .dw_slv0_addr = 0x21, 9584393e4c5SLorenzo Bianconi .batch_en = BIT(3), 9594393e4c5SLorenzo Bianconi }, 9604393e4c5SLorenzo Bianconi .event_settings = { 9614393e4c5SLorenzo Bianconi .enable_reg = { 9624393e4c5SLorenzo Bianconi .addr = 0x58, 9634393e4c5SLorenzo Bianconi .mask = BIT(7), 9644393e4c5SLorenzo Bianconi }, 9654393e4c5SLorenzo Bianconi .wakeup_reg = { 9664393e4c5SLorenzo Bianconi .addr = 0x5b, 9674393e4c5SLorenzo Bianconi .mask = GENMASK(5, 0), 9684393e4c5SLorenzo Bianconi }, 9694393e4c5SLorenzo Bianconi .wakeup_src_reg = 0x1b, 9704393e4c5SLorenzo Bianconi .wakeup_src_status_mask = BIT(3), 9714393e4c5SLorenzo Bianconi .wakeup_src_z_mask = BIT(0), 9724393e4c5SLorenzo Bianconi .wakeup_src_y_mask = BIT(1), 9734393e4c5SLorenzo Bianconi .wakeup_src_x_mask = BIT(2), 9744393e4c5SLorenzo Bianconi }, 9754393e4c5SLorenzo Bianconi }, 97698c3544aSLorenzo Bianconi { 97798c3544aSLorenzo Bianconi .reset = { 97898c3544aSLorenzo Bianconi .addr = 0x12, 97998c3544aSLorenzo Bianconi .mask = BIT(0), 98098c3544aSLorenzo Bianconi }, 98198c3544aSLorenzo Bianconi .boot = { 98298c3544aSLorenzo Bianconi .addr = 0x12, 98398c3544aSLorenzo Bianconi .mask = BIT(7), 98498c3544aSLorenzo Bianconi }, 98598c3544aSLorenzo Bianconi .bdu = { 98698c3544aSLorenzo Bianconi .addr = 0x12, 98798c3544aSLorenzo Bianconi .mask = BIT(6), 98898c3544aSLorenzo Bianconi }, 98998c3544aSLorenzo Bianconi .id = { 99098c3544aSLorenzo Bianconi { 99198c3544aSLorenzo Bianconi .hw_id = ST_ASM330LHH_ID, 99298c3544aSLorenzo Bianconi .name = ST_ASM330LHH_DEV_NAME, 99398c3544aSLorenzo Bianconi .wai = 0x6b, 9942c57d265SLorenzo Bianconi }, { 9952c57d265SLorenzo Bianconi .hw_id = ST_LSM6DSOP_ID, 9962c57d265SLorenzo Bianconi .name = ST_LSM6DSOP_DEV_NAME, 9972c57d265SLorenzo Bianconi .wai = 0x6c, 99898c3544aSLorenzo Bianconi }, 99998c3544aSLorenzo Bianconi }, 100098c3544aSLorenzo Bianconi .channels = { 100198c3544aSLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 100298c3544aSLorenzo Bianconi .chan = st_lsm6dsx_acc_channels, 100398c3544aSLorenzo Bianconi .len = ARRAY_SIZE(st_lsm6dsx_acc_channels), 100498c3544aSLorenzo Bianconi }, 100598c3544aSLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 100698c3544aSLorenzo Bianconi .chan = st_lsm6dsx_gyro_channels, 100798c3544aSLorenzo Bianconi .len = ARRAY_SIZE(st_lsm6dsx_gyro_channels), 100898c3544aSLorenzo Bianconi }, 100998c3544aSLorenzo Bianconi }, 101098c3544aSLorenzo Bianconi .drdy_mask = { 101198c3544aSLorenzo Bianconi .addr = 0x13, 101298c3544aSLorenzo Bianconi .mask = BIT(3), 101398c3544aSLorenzo Bianconi }, 101498c3544aSLorenzo Bianconi .odr_table = { 101598c3544aSLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 101698c3544aSLorenzo Bianconi .reg = { 101798c3544aSLorenzo Bianconi .addr = 0x10, 101898c3544aSLorenzo Bianconi .mask = GENMASK(7, 4), 101998c3544aSLorenzo Bianconi }, 102098c3544aSLorenzo Bianconi .odr_avl[0] = { 12500, 0x01 }, 102198c3544aSLorenzo Bianconi .odr_avl[1] = { 26000, 0x02 }, 102298c3544aSLorenzo Bianconi .odr_avl[2] = { 52000, 0x03 }, 102398c3544aSLorenzo Bianconi .odr_avl[3] = { 104000, 0x04 }, 102498c3544aSLorenzo Bianconi .odr_avl[4] = { 208000, 0x05 }, 102598c3544aSLorenzo Bianconi .odr_avl[5] = { 416000, 0x06 }, 102698c3544aSLorenzo Bianconi .odr_avl[6] = { 833000, 0x07 }, 102798c3544aSLorenzo Bianconi .odr_len = 7, 102898c3544aSLorenzo Bianconi }, 102998c3544aSLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 103098c3544aSLorenzo Bianconi .reg = { 103198c3544aSLorenzo Bianconi .addr = 0x11, 103298c3544aSLorenzo Bianconi .mask = GENMASK(7, 4), 103398c3544aSLorenzo Bianconi }, 103498c3544aSLorenzo Bianconi .odr_avl[0] = { 12500, 0x01 }, 103598c3544aSLorenzo Bianconi .odr_avl[1] = { 26000, 0x02 }, 103698c3544aSLorenzo Bianconi .odr_avl[2] = { 52000, 0x03 }, 103798c3544aSLorenzo Bianconi .odr_avl[3] = { 104000, 0x04 }, 103898c3544aSLorenzo Bianconi .odr_avl[4] = { 208000, 0x05 }, 103998c3544aSLorenzo Bianconi .odr_avl[5] = { 416000, 0x06 }, 104098c3544aSLorenzo Bianconi .odr_avl[6] = { 833000, 0x07 }, 104198c3544aSLorenzo Bianconi .odr_len = 7, 104298c3544aSLorenzo Bianconi }, 104398c3544aSLorenzo Bianconi }, 104498c3544aSLorenzo Bianconi .fs_table = { 104598c3544aSLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 104698c3544aSLorenzo Bianconi .reg = { 104798c3544aSLorenzo Bianconi .addr = 0x10, 104898c3544aSLorenzo Bianconi .mask = GENMASK(3, 2), 104998c3544aSLorenzo Bianconi }, 105098c3544aSLorenzo Bianconi .fs_avl[0] = { IIO_G_TO_M_S_2(61000), 0x0 }, 105198c3544aSLorenzo Bianconi .fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 }, 105298c3544aSLorenzo Bianconi .fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 }, 105398c3544aSLorenzo Bianconi .fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 }, 105498c3544aSLorenzo Bianconi .fs_len = 4, 105598c3544aSLorenzo Bianconi }, 105698c3544aSLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 105798c3544aSLorenzo Bianconi .reg = { 105898c3544aSLorenzo Bianconi .addr = 0x11, 105998c3544aSLorenzo Bianconi .mask = GENMASK(3, 2), 106098c3544aSLorenzo Bianconi }, 106198c3544aSLorenzo Bianconi .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 }, 106298c3544aSLorenzo Bianconi .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 }, 106398c3544aSLorenzo Bianconi .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 }, 106498c3544aSLorenzo Bianconi .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 }, 106598c3544aSLorenzo Bianconi .fs_len = 4, 106698c3544aSLorenzo Bianconi }, 106798c3544aSLorenzo Bianconi }, 106898c3544aSLorenzo Bianconi .irq_config = { 106998c3544aSLorenzo Bianconi .irq1 = { 107098c3544aSLorenzo Bianconi .addr = 0x0d, 107198c3544aSLorenzo Bianconi .mask = BIT(3), 107298c3544aSLorenzo Bianconi }, 107398c3544aSLorenzo Bianconi .irq2 = { 107498c3544aSLorenzo Bianconi .addr = 0x0e, 107598c3544aSLorenzo Bianconi .mask = BIT(3), 107698c3544aSLorenzo Bianconi }, 107798c3544aSLorenzo Bianconi .lir = { 107898c3544aSLorenzo Bianconi .addr = 0x56, 107998c3544aSLorenzo Bianconi .mask = BIT(0), 108098c3544aSLorenzo Bianconi }, 108198c3544aSLorenzo Bianconi .clear_on_read = { 108298c3544aSLorenzo Bianconi .addr = 0x56, 108398c3544aSLorenzo Bianconi .mask = BIT(6), 108498c3544aSLorenzo Bianconi }, 108598c3544aSLorenzo Bianconi .irq1_func = { 108698c3544aSLorenzo Bianconi .addr = 0x5e, 108798c3544aSLorenzo Bianconi .mask = BIT(5), 108898c3544aSLorenzo Bianconi }, 108998c3544aSLorenzo Bianconi .irq2_func = { 109098c3544aSLorenzo Bianconi .addr = 0x5f, 109198c3544aSLorenzo Bianconi .mask = BIT(5), 109298c3544aSLorenzo Bianconi }, 109398c3544aSLorenzo Bianconi .hla = { 109498c3544aSLorenzo Bianconi .addr = 0x12, 109598c3544aSLorenzo Bianconi .mask = BIT(5), 109698c3544aSLorenzo Bianconi }, 109798c3544aSLorenzo Bianconi .od = { 109898c3544aSLorenzo Bianconi .addr = 0x12, 109998c3544aSLorenzo Bianconi .mask = BIT(4), 110098c3544aSLorenzo Bianconi }, 110198c3544aSLorenzo Bianconi }, 110298c3544aSLorenzo Bianconi .batch = { 110398c3544aSLorenzo Bianconi [ST_LSM6DSX_ID_ACC] = { 110498c3544aSLorenzo Bianconi .addr = 0x09, 110598c3544aSLorenzo Bianconi .mask = GENMASK(3, 0), 110698c3544aSLorenzo Bianconi }, 110798c3544aSLorenzo Bianconi [ST_LSM6DSX_ID_GYRO] = { 110898c3544aSLorenzo Bianconi .addr = 0x09, 110998c3544aSLorenzo Bianconi .mask = GENMASK(7, 4), 111098c3544aSLorenzo Bianconi }, 111198c3544aSLorenzo Bianconi }, 111298c3544aSLorenzo Bianconi .fifo_ops = { 111398c3544aSLorenzo Bianconi .update_fifo = st_lsm6dsx_update_fifo, 111498c3544aSLorenzo Bianconi .read_fifo = st_lsm6dsx_read_tagged_fifo, 111598c3544aSLorenzo Bianconi .fifo_th = { 111698c3544aSLorenzo Bianconi .addr = 0x07, 111798c3544aSLorenzo Bianconi .mask = GENMASK(8, 0), 111898c3544aSLorenzo Bianconi }, 111998c3544aSLorenzo Bianconi .fifo_diff = { 112098c3544aSLorenzo Bianconi .addr = 0x3a, 112198c3544aSLorenzo Bianconi .mask = GENMASK(9, 0), 112298c3544aSLorenzo Bianconi }, 1123*1b7da2faSLorenzo Bianconi .max_size = 512, 112498c3544aSLorenzo Bianconi .th_wl = 1, 112598c3544aSLorenzo Bianconi }, 112698c3544aSLorenzo Bianconi .ts_settings = { 112798c3544aSLorenzo Bianconi .timer_en = { 112898c3544aSLorenzo Bianconi .addr = 0x19, 112998c3544aSLorenzo Bianconi .mask = BIT(5), 113098c3544aSLorenzo Bianconi }, 113198c3544aSLorenzo Bianconi .decimator = { 113298c3544aSLorenzo Bianconi .addr = 0x0a, 113398c3544aSLorenzo Bianconi .mask = GENMASK(7, 6), 113498c3544aSLorenzo Bianconi }, 113598c3544aSLorenzo Bianconi .freq_fine = 0x63, 113698c3544aSLorenzo Bianconi }, 113798c3544aSLorenzo Bianconi .event_settings = { 113898c3544aSLorenzo Bianconi .enable_reg = { 113998c3544aSLorenzo Bianconi .addr = 0x58, 114098c3544aSLorenzo Bianconi .mask = BIT(7), 114198c3544aSLorenzo Bianconi }, 114298c3544aSLorenzo Bianconi .wakeup_reg = { 114398c3544aSLorenzo Bianconi .addr = 0x5B, 114498c3544aSLorenzo Bianconi .mask = GENMASK(5, 0), 114598c3544aSLorenzo Bianconi }, 114698c3544aSLorenzo Bianconi .wakeup_src_reg = 0x1b, 114798c3544aSLorenzo Bianconi .wakeup_src_status_mask = BIT(3), 114898c3544aSLorenzo Bianconi .wakeup_src_z_mask = BIT(0), 114998c3544aSLorenzo Bianconi .wakeup_src_y_mask = BIT(1), 115098c3544aSLorenzo Bianconi .wakeup_src_x_mask = BIT(2), 115198c3544aSLorenzo Bianconi }, 115298c3544aSLorenzo Bianconi }, 1153290a6ce1SLorenzo Bianconi }; 1154290a6ce1SLorenzo Bianconi 1155c91c1c84SLorenzo Bianconi int st_lsm6dsx_set_page(struct st_lsm6dsx_hw *hw, bool enable) 1156c91c1c84SLorenzo Bianconi { 1157c91c1c84SLorenzo Bianconi const struct st_lsm6dsx_shub_settings *hub_settings; 1158c91c1c84SLorenzo Bianconi unsigned int data; 1159c91c1c84SLorenzo Bianconi int err; 1160c91c1c84SLorenzo Bianconi 1161c91c1c84SLorenzo Bianconi hub_settings = &hw->settings->shub_settings; 1162c91c1c84SLorenzo Bianconi data = ST_LSM6DSX_SHIFT_VAL(enable, hub_settings->page_mux.mask); 1163c91c1c84SLorenzo Bianconi err = regmap_update_bits(hw->regmap, hub_settings->page_mux.addr, 1164c91c1c84SLorenzo Bianconi hub_settings->page_mux.mask, data); 1165c91c1c84SLorenzo Bianconi usleep_range(100, 150); 1166c91c1c84SLorenzo Bianconi 1167c91c1c84SLorenzo Bianconi return err; 1168c91c1c84SLorenzo Bianconi } 1169c91c1c84SLorenzo Bianconi 117081956a93SLorenzo Bianconi static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id, 117181956a93SLorenzo Bianconi const char **name) 1172290a6ce1SLorenzo Bianconi { 117351a8b707SLorenzo Bianconi int err, i, j, data; 1174290a6ce1SLorenzo Bianconi 1175290a6ce1SLorenzo Bianconi for (i = 0; i < ARRAY_SIZE(st_lsm6dsx_sensor_settings); i++) { 1176d068e4a0SLorenzo Bianconi for (j = 0; j < ST_LSM6DSX_MAX_ID; j++) { 1177fb4fbc89SStephan Gerhold if (st_lsm6dsx_sensor_settings[i].id[j].name && 1178fb4fbc89SStephan Gerhold id == st_lsm6dsx_sensor_settings[i].id[j].hw_id) 1179d068e4a0SLorenzo Bianconi break; 1180d068e4a0SLorenzo Bianconi } 1181d068e4a0SLorenzo Bianconi if (j < ST_LSM6DSX_MAX_ID) 1182290a6ce1SLorenzo Bianconi break; 1183290a6ce1SLorenzo Bianconi } 1184290a6ce1SLorenzo Bianconi 1185290a6ce1SLorenzo Bianconi if (i == ARRAY_SIZE(st_lsm6dsx_sensor_settings)) { 1186290a6ce1SLorenzo Bianconi dev_err(hw->dev, "unsupported hw id [%02x]\n", id); 1187290a6ce1SLorenzo Bianconi return -ENODEV; 1188290a6ce1SLorenzo Bianconi } 1189290a6ce1SLorenzo Bianconi 119051a8b707SLorenzo Bianconi err = regmap_read(hw->regmap, ST_LSM6DSX_REG_WHOAMI_ADDR, &data); 1191290a6ce1SLorenzo Bianconi if (err < 0) { 1192290a6ce1SLorenzo Bianconi dev_err(hw->dev, "failed to read whoami register\n"); 1193290a6ce1SLorenzo Bianconi return err; 1194290a6ce1SLorenzo Bianconi } 1195290a6ce1SLorenzo Bianconi 119698c3544aSLorenzo Bianconi if (data != st_lsm6dsx_sensor_settings[i].id[j].wai) { 1197290a6ce1SLorenzo Bianconi dev_err(hw->dev, "unsupported whoami [%02x]\n", data); 1198290a6ce1SLorenzo Bianconi return -ENODEV; 1199290a6ce1SLorenzo Bianconi } 1200290a6ce1SLorenzo Bianconi 120181956a93SLorenzo Bianconi *name = st_lsm6dsx_sensor_settings[i].id[j].name; 1202290a6ce1SLorenzo Bianconi hw->settings = &st_lsm6dsx_sensor_settings[i]; 1203290a6ce1SLorenzo Bianconi 1204290a6ce1SLorenzo Bianconi return 0; 1205290a6ce1SLorenzo Bianconi } 1206290a6ce1SLorenzo Bianconi 1207290a6ce1SLorenzo Bianconi static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor, 1208290a6ce1SLorenzo Bianconi u32 gain) 1209290a6ce1SLorenzo Bianconi { 1210640aca3fSLorenzo Bianconi const struct st_lsm6dsx_fs_table_entry *fs_table; 1211739aff87SLorenzo Bianconi unsigned int data; 1212290a6ce1SLorenzo Bianconi int i, err; 1213290a6ce1SLorenzo Bianconi 1214640aca3fSLorenzo Bianconi fs_table = &sensor->hw->settings->fs_table[sensor->id]; 121585ae3aeeSLorenzo Bianconi for (i = 0; i < fs_table->fs_len; i++) { 1216640aca3fSLorenzo Bianconi if (fs_table->fs_avl[i].gain == gain) 1217290a6ce1SLorenzo Bianconi break; 121885ae3aeeSLorenzo Bianconi } 1219290a6ce1SLorenzo Bianconi 122085ae3aeeSLorenzo Bianconi if (i == fs_table->fs_len) 1221290a6ce1SLorenzo Bianconi return -EINVAL; 1222290a6ce1SLorenzo Bianconi 1223640aca3fSLorenzo Bianconi data = ST_LSM6DSX_SHIFT_VAL(fs_table->fs_avl[i].val, 1224640aca3fSLorenzo Bianconi fs_table->reg.mask); 1225640aca3fSLorenzo Bianconi err = st_lsm6dsx_update_bits_locked(sensor->hw, fs_table->reg.addr, 1226640aca3fSLorenzo Bianconi fs_table->reg.mask, data); 1227290a6ce1SLorenzo Bianconi if (err < 0) 1228290a6ce1SLorenzo Bianconi return err; 1229290a6ce1SLorenzo Bianconi 1230290a6ce1SLorenzo Bianconi sensor->gain = gain; 1231290a6ce1SLorenzo Bianconi 1232290a6ce1SLorenzo Bianconi return 0; 1233290a6ce1SLorenzo Bianconi } 1234290a6ce1SLorenzo Bianconi 1235f8710f03SLorenzo Bianconi int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u32 odr, u8 *val) 1236290a6ce1SLorenzo Bianconi { 123740dd7343SLorenzo Bianconi const struct st_lsm6dsx_odr_table_entry *odr_table; 12382ccc1503SLorenzo Bianconi int i; 1239290a6ce1SLorenzo Bianconi 124040dd7343SLorenzo Bianconi odr_table = &sensor->hw->settings->odr_table[sensor->id]; 124159af4e20SLorenzo Bianconi for (i = 0; i < odr_table->odr_len; i++) { 12426ffb55e5SLorenzo Bianconi /* 12436ffb55e5SLorenzo Bianconi * ext devices can run at different odr respect to 12446ffb55e5SLorenzo Bianconi * accel sensor 12456ffb55e5SLorenzo Bianconi */ 1246f8710f03SLorenzo Bianconi if (odr_table->odr_avl[i].milli_hz >= odr) 1247290a6ce1SLorenzo Bianconi break; 124859af4e20SLorenzo Bianconi } 1249290a6ce1SLorenzo Bianconi 125059af4e20SLorenzo Bianconi if (i == odr_table->odr_len) 1251290a6ce1SLorenzo Bianconi return -EINVAL; 1252290a6ce1SLorenzo Bianconi 125340dd7343SLorenzo Bianconi *val = odr_table->odr_avl[i].val; 1254f8710f03SLorenzo Bianconi return odr_table->odr_avl[i].milli_hz; 1255290a6ce1SLorenzo Bianconi } 1256290a6ce1SLorenzo Bianconi 1257f8710f03SLorenzo Bianconi static int 1258f8710f03SLorenzo Bianconi st_lsm6dsx_check_odr_dependency(struct st_lsm6dsx_hw *hw, u32 odr, 12596ffb55e5SLorenzo Bianconi enum st_lsm6dsx_sensor_id id) 12602ccc1503SLorenzo Bianconi { 12616ffb55e5SLorenzo Bianconi struct st_lsm6dsx_sensor *ref = iio_priv(hw->iio_devs[id]); 12626ffb55e5SLorenzo Bianconi 12636ffb55e5SLorenzo Bianconi if (odr > 0) { 12646ffb55e5SLorenzo Bianconi if (hw->enable_mask & BIT(id)) 1265f8710f03SLorenzo Bianconi return max_t(u32, ref->odr, odr); 12666ffb55e5SLorenzo Bianconi else 12676ffb55e5SLorenzo Bianconi return odr; 12686ffb55e5SLorenzo Bianconi } else { 12696ffb55e5SLorenzo Bianconi return (hw->enable_mask & BIT(id)) ? ref->odr : 0; 12706ffb55e5SLorenzo Bianconi } 12716ffb55e5SLorenzo Bianconi } 12726ffb55e5SLorenzo Bianconi 1273f8710f03SLorenzo Bianconi static int 1274f8710f03SLorenzo Bianconi st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u32 req_odr) 12756ffb55e5SLorenzo Bianconi { 12766ffb55e5SLorenzo Bianconi struct st_lsm6dsx_sensor *ref_sensor = sensor; 127751a8b707SLorenzo Bianconi struct st_lsm6dsx_hw *hw = sensor->hw; 127851a8b707SLorenzo Bianconi const struct st_lsm6dsx_reg *reg; 1279739aff87SLorenzo Bianconi unsigned int data; 12806ffb55e5SLorenzo Bianconi u8 val = 0; 12812ccc1503SLorenzo Bianconi int err; 12822ccc1503SLorenzo Bianconi 12836ffb55e5SLorenzo Bianconi switch (sensor->id) { 12846ffb55e5SLorenzo Bianconi case ST_LSM6DSX_ID_EXT0: 12856ffb55e5SLorenzo Bianconi case ST_LSM6DSX_ID_EXT1: 12866ffb55e5SLorenzo Bianconi case ST_LSM6DSX_ID_EXT2: 12876ffb55e5SLorenzo Bianconi case ST_LSM6DSX_ID_ACC: { 1288f8710f03SLorenzo Bianconi u32 odr; 12896ffb55e5SLorenzo Bianconi int i; 12906ffb55e5SLorenzo Bianconi 12916ffb55e5SLorenzo Bianconi /* 12926ffb55e5SLorenzo Bianconi * i2c embedded controller relies on the accelerometer sensor as 12936ffb55e5SLorenzo Bianconi * bus read/write trigger so we need to enable accel device 12946ffb55e5SLorenzo Bianconi * at odr = max(accel_odr, ext_odr) in order to properly 12956ffb55e5SLorenzo Bianconi * communicate with i2c slave devices 12966ffb55e5SLorenzo Bianconi */ 12976ffb55e5SLorenzo Bianconi ref_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]); 12986ffb55e5SLorenzo Bianconi for (i = ST_LSM6DSX_ID_ACC; i < ST_LSM6DSX_ID_MAX; i++) { 12996ffb55e5SLorenzo Bianconi if (!hw->iio_devs[i] || i == sensor->id) 13006ffb55e5SLorenzo Bianconi continue; 13016ffb55e5SLorenzo Bianconi 13026ffb55e5SLorenzo Bianconi odr = st_lsm6dsx_check_odr_dependency(hw, req_odr, i); 13036ffb55e5SLorenzo Bianconi if (odr != req_odr) 13046ffb55e5SLorenzo Bianconi /* device already configured */ 13056ffb55e5SLorenzo Bianconi return 0; 13066ffb55e5SLorenzo Bianconi } 13076ffb55e5SLorenzo Bianconi break; 13086ffb55e5SLorenzo Bianconi } 13096ffb55e5SLorenzo Bianconi default: 13106ffb55e5SLorenzo Bianconi break; 13116ffb55e5SLorenzo Bianconi } 13126ffb55e5SLorenzo Bianconi 13136ffb55e5SLorenzo Bianconi if (req_odr > 0) { 13146ffb55e5SLorenzo Bianconi err = st_lsm6dsx_check_odr(ref_sensor, req_odr, &val); 13152ccc1503SLorenzo Bianconi if (err < 0) 13162ccc1503SLorenzo Bianconi return err; 13176ffb55e5SLorenzo Bianconi } 13182ccc1503SLorenzo Bianconi 131940dd7343SLorenzo Bianconi reg = &hw->settings->odr_table[ref_sensor->id].reg; 1320739aff87SLorenzo Bianconi data = ST_LSM6DSX_SHIFT_VAL(val, reg->mask); 1321739aff87SLorenzo Bianconi return st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data); 13222ccc1503SLorenzo Bianconi } 13232ccc1503SLorenzo Bianconi 1324bd41c445SLorenzo Bianconi static int 1325bd41c445SLorenzo Bianconi __st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor, 132617750443SLorenzo Bianconi bool enable) 1327290a6ce1SLorenzo Bianconi { 132851a8b707SLorenzo Bianconi struct st_lsm6dsx_hw *hw = sensor->hw; 1329f8710f03SLorenzo Bianconi u32 odr = enable ? sensor->odr : 0; 1330290a6ce1SLorenzo Bianconi int err; 1331290a6ce1SLorenzo Bianconi 133217750443SLorenzo Bianconi err = st_lsm6dsx_set_odr(sensor, odr); 1333290a6ce1SLorenzo Bianconi if (err < 0) 1334290a6ce1SLorenzo Bianconi return err; 1335290a6ce1SLorenzo Bianconi 133617750443SLorenzo Bianconi if (enable) 133717750443SLorenzo Bianconi hw->enable_mask |= BIT(sensor->id); 133817750443SLorenzo Bianconi else 133917750443SLorenzo Bianconi hw->enable_mask &= ~BIT(sensor->id); 1340290a6ce1SLorenzo Bianconi 1341290a6ce1SLorenzo Bianconi return 0; 1342290a6ce1SLorenzo Bianconi } 1343290a6ce1SLorenzo Bianconi 1344bd41c445SLorenzo Bianconi static int 1345bd41c445SLorenzo Bianconi st_lsm6dsx_check_events(struct st_lsm6dsx_sensor *sensor, bool enable) 1346bd41c445SLorenzo Bianconi { 1347bd41c445SLorenzo Bianconi struct st_lsm6dsx_hw *hw = sensor->hw; 1348bd41c445SLorenzo Bianconi 1349bd41c445SLorenzo Bianconi if (sensor->id == ST_LSM6DSX_ID_GYRO || enable) 1350bd41c445SLorenzo Bianconi return 0; 1351bd41c445SLorenzo Bianconi 1352bd41c445SLorenzo Bianconi return hw->enable_event; 1353bd41c445SLorenzo Bianconi } 1354bd41c445SLorenzo Bianconi 1355bd41c445SLorenzo Bianconi int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor, 1356bd41c445SLorenzo Bianconi bool enable) 1357bd41c445SLorenzo Bianconi { 1358bd41c445SLorenzo Bianconi if (st_lsm6dsx_check_events(sensor, enable)) 1359bd41c445SLorenzo Bianconi return 0; 1360bd41c445SLorenzo Bianconi 1361bd41c445SLorenzo Bianconi return __st_lsm6dsx_sensor_set_enable(sensor, enable); 1362bd41c445SLorenzo Bianconi } 1363bd41c445SLorenzo Bianconi 1364290a6ce1SLorenzo Bianconi static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor, 1365290a6ce1SLorenzo Bianconi u8 addr, int *val) 1366290a6ce1SLorenzo Bianconi { 136751a8b707SLorenzo Bianconi struct st_lsm6dsx_hw *hw = sensor->hw; 1368290a6ce1SLorenzo Bianconi int err, delay; 1369290a6ce1SLorenzo Bianconi __le16 data; 1370290a6ce1SLorenzo Bianconi 137117750443SLorenzo Bianconi err = st_lsm6dsx_sensor_set_enable(sensor, true); 1372290a6ce1SLorenzo Bianconi if (err < 0) 1373290a6ce1SLorenzo Bianconi return err; 1374290a6ce1SLorenzo Bianconi 1375f8710f03SLorenzo Bianconi delay = 1000000000 / sensor->odr; 1376290a6ce1SLorenzo Bianconi usleep_range(delay, 2 * delay); 1377290a6ce1SLorenzo Bianconi 1378739aff87SLorenzo Bianconi err = st_lsm6dsx_read_locked(hw, addr, &data, sizeof(data)); 1379290a6ce1SLorenzo Bianconi if (err < 0) 1380290a6ce1SLorenzo Bianconi return err; 1381290a6ce1SLorenzo Bianconi 1382a2dd9bd9SLorenzo Bianconi if (!hw->enable_event) { 1383a2dd9bd9SLorenzo Bianconi err = st_lsm6dsx_sensor_set_enable(sensor, false); 1384a2dd9bd9SLorenzo Bianconi if (err < 0) 1385a2dd9bd9SLorenzo Bianconi return err; 1386a2dd9bd9SLorenzo Bianconi } 1387290a6ce1SLorenzo Bianconi 13887b9ebe42SLorenzo Bianconi *val = (s16)le16_to_cpu(data); 1389290a6ce1SLorenzo Bianconi 1390290a6ce1SLorenzo Bianconi return IIO_VAL_INT; 1391290a6ce1SLorenzo Bianconi } 1392290a6ce1SLorenzo Bianconi 1393290a6ce1SLorenzo Bianconi static int st_lsm6dsx_read_raw(struct iio_dev *iio_dev, 1394290a6ce1SLorenzo Bianconi struct iio_chan_spec const *ch, 1395290a6ce1SLorenzo Bianconi int *val, int *val2, long mask) 1396290a6ce1SLorenzo Bianconi { 1397290a6ce1SLorenzo Bianconi struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); 1398290a6ce1SLorenzo Bianconi int ret; 1399290a6ce1SLorenzo Bianconi 1400290a6ce1SLorenzo Bianconi switch (mask) { 1401290a6ce1SLorenzo Bianconi case IIO_CHAN_INFO_RAW: 1402290a6ce1SLorenzo Bianconi ret = iio_device_claim_direct_mode(iio_dev); 1403290a6ce1SLorenzo Bianconi if (ret) 1404290a6ce1SLorenzo Bianconi break; 1405290a6ce1SLorenzo Bianconi 1406290a6ce1SLorenzo Bianconi ret = st_lsm6dsx_read_oneshot(sensor, ch->address, val); 1407290a6ce1SLorenzo Bianconi iio_device_release_direct_mode(iio_dev); 1408290a6ce1SLorenzo Bianconi break; 1409290a6ce1SLorenzo Bianconi case IIO_CHAN_INFO_SAMP_FREQ: 1410f8710f03SLorenzo Bianconi *val = sensor->odr / 1000; 1411f8710f03SLorenzo Bianconi *val2 = (sensor->odr % 1000) * 1000; 1412f8710f03SLorenzo Bianconi ret = IIO_VAL_INT_PLUS_MICRO; 1413290a6ce1SLorenzo Bianconi break; 1414290a6ce1SLorenzo Bianconi case IIO_CHAN_INFO_SCALE: 1415290a6ce1SLorenzo Bianconi *val = 0; 1416290a6ce1SLorenzo Bianconi *val2 = sensor->gain; 141744a76de8SMario Tesi ret = IIO_VAL_INT_PLUS_NANO; 1418290a6ce1SLorenzo Bianconi break; 1419290a6ce1SLorenzo Bianconi default: 1420290a6ce1SLorenzo Bianconi ret = -EINVAL; 1421290a6ce1SLorenzo Bianconi break; 1422290a6ce1SLorenzo Bianconi } 1423290a6ce1SLorenzo Bianconi 1424290a6ce1SLorenzo Bianconi return ret; 1425290a6ce1SLorenzo Bianconi } 1426290a6ce1SLorenzo Bianconi 1427290a6ce1SLorenzo Bianconi static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev, 1428290a6ce1SLorenzo Bianconi struct iio_chan_spec const *chan, 1429290a6ce1SLorenzo Bianconi int val, int val2, long mask) 1430290a6ce1SLorenzo Bianconi { 1431290a6ce1SLorenzo Bianconi struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); 1432290a6ce1SLorenzo Bianconi int err; 1433290a6ce1SLorenzo Bianconi 1434290a6ce1SLorenzo Bianconi err = iio_device_claim_direct_mode(iio_dev); 1435290a6ce1SLorenzo Bianconi if (err) 1436290a6ce1SLorenzo Bianconi return err; 1437290a6ce1SLorenzo Bianconi 1438290a6ce1SLorenzo Bianconi switch (mask) { 1439290a6ce1SLorenzo Bianconi case IIO_CHAN_INFO_SCALE: 1440290a6ce1SLorenzo Bianconi err = st_lsm6dsx_set_full_scale(sensor, val2); 1441290a6ce1SLorenzo Bianconi break; 14422ccc1503SLorenzo Bianconi case IIO_CHAN_INFO_SAMP_FREQ: { 14432ccc1503SLorenzo Bianconi u8 data; 14442ccc1503SLorenzo Bianconi 1445f8710f03SLorenzo Bianconi val = val * 1000 + val2 / 1000; 1446fc3f6ad7SLorenzo Bianconi val = st_lsm6dsx_check_odr(sensor, val, &data); 1447fc3f6ad7SLorenzo Bianconi if (val < 0) 1448fc3f6ad7SLorenzo Bianconi err = val; 1449fc3f6ad7SLorenzo Bianconi else 14505e3c3e33SLorenzo Bianconi sensor->odr = val; 1451290a6ce1SLorenzo Bianconi break; 14522ccc1503SLorenzo Bianconi } 1453290a6ce1SLorenzo Bianconi default: 1454290a6ce1SLorenzo Bianconi err = -EINVAL; 1455290a6ce1SLorenzo Bianconi break; 1456290a6ce1SLorenzo Bianconi } 1457290a6ce1SLorenzo Bianconi 1458290a6ce1SLorenzo Bianconi iio_device_release_direct_mode(iio_dev); 1459290a6ce1SLorenzo Bianconi 1460290a6ce1SLorenzo Bianconi return err; 1461290a6ce1SLorenzo Bianconi } 1462290a6ce1SLorenzo Bianconi 1463b5969abfSSean Nyekjaer static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state) 1464b5969abfSSean Nyekjaer { 146584b2e7c3SLorenzo Bianconi const struct st_lsm6dsx_reg *reg; 146604ca37d5SLorenzo Bianconi unsigned int data; 1467b5969abfSSean Nyekjaer int err; 1468b5969abfSSean Nyekjaer 14697e906103SLorenzo Bianconi if (!hw->settings->irq_config.irq1_func.addr) 1470b5969abfSSean Nyekjaer return -ENOTSUPP; 1471b5969abfSSean Nyekjaer 147284b2e7c3SLorenzo Bianconi reg = &hw->settings->event_settings.enable_reg; 147384b2e7c3SLorenzo Bianconi if (reg->addr) { 147404ca37d5SLorenzo Bianconi data = ST_LSM6DSX_SHIFT_VAL(state, reg->mask); 147504ca37d5SLorenzo Bianconi err = st_lsm6dsx_update_bits_locked(hw, reg->addr, 147604ca37d5SLorenzo Bianconi reg->mask, data); 1477b5969abfSSean Nyekjaer if (err < 0) 1478b5969abfSSean Nyekjaer return err; 147984b2e7c3SLorenzo Bianconi } 1480b5969abfSSean Nyekjaer 1481b5969abfSSean Nyekjaer /* Enable wakeup interrupt */ 148204ca37d5SLorenzo Bianconi data = ST_LSM6DSX_SHIFT_VAL(state, hw->irq_routing->mask); 148304ca37d5SLorenzo Bianconi return st_lsm6dsx_update_bits_locked(hw, hw->irq_routing->addr, 148404ca37d5SLorenzo Bianconi hw->irq_routing->mask, data); 1485b5969abfSSean Nyekjaer } 1486b5969abfSSean Nyekjaer 1487b5969abfSSean Nyekjaer static int st_lsm6dsx_read_event(struct iio_dev *iio_dev, 1488b5969abfSSean Nyekjaer const struct iio_chan_spec *chan, 1489b5969abfSSean Nyekjaer enum iio_event_type type, 1490b5969abfSSean Nyekjaer enum iio_event_direction dir, 1491b5969abfSSean Nyekjaer enum iio_event_info info, 1492b5969abfSSean Nyekjaer int *val, int *val2) 1493b5969abfSSean Nyekjaer { 1494b5969abfSSean Nyekjaer struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); 1495b5969abfSSean Nyekjaer struct st_lsm6dsx_hw *hw = sensor->hw; 1496b5969abfSSean Nyekjaer 1497b5969abfSSean Nyekjaer if (type != IIO_EV_TYPE_THRESH) 1498b5969abfSSean Nyekjaer return -EINVAL; 1499b5969abfSSean Nyekjaer 1500b5969abfSSean Nyekjaer *val2 = 0; 1501b5969abfSSean Nyekjaer *val = hw->event_threshold; 1502b5969abfSSean Nyekjaer 1503b5969abfSSean Nyekjaer return IIO_VAL_INT; 1504b5969abfSSean Nyekjaer } 1505b5969abfSSean Nyekjaer 1506b307f495SLorenzo Bianconi static int 1507b307f495SLorenzo Bianconi st_lsm6dsx_write_event(struct iio_dev *iio_dev, 1508b5969abfSSean Nyekjaer const struct iio_chan_spec *chan, 1509b5969abfSSean Nyekjaer enum iio_event_type type, 1510b5969abfSSean Nyekjaer enum iio_event_direction dir, 1511b5969abfSSean Nyekjaer enum iio_event_info info, 1512b5969abfSSean Nyekjaer int val, int val2) 1513b5969abfSSean Nyekjaer { 1514b5969abfSSean Nyekjaer struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); 1515b5969abfSSean Nyekjaer struct st_lsm6dsx_hw *hw = sensor->hw; 151604ca37d5SLorenzo Bianconi const struct st_lsm6dsx_reg *reg; 151704ca37d5SLorenzo Bianconi unsigned int data; 1518b5969abfSSean Nyekjaer int err; 1519b5969abfSSean Nyekjaer 1520b5969abfSSean Nyekjaer if (type != IIO_EV_TYPE_THRESH) 1521b5969abfSSean Nyekjaer return -EINVAL; 1522b5969abfSSean Nyekjaer 1523b5969abfSSean Nyekjaer if (val < 0 || val > 31) 1524b5969abfSSean Nyekjaer return -EINVAL; 1525b5969abfSSean Nyekjaer 152604ca37d5SLorenzo Bianconi reg = &hw->settings->event_settings.wakeup_reg; 152704ca37d5SLorenzo Bianconi data = ST_LSM6DSX_SHIFT_VAL(val, reg->mask); 152804ca37d5SLorenzo Bianconi err = st_lsm6dsx_update_bits_locked(hw, reg->addr, 152904ca37d5SLorenzo Bianconi reg->mask, data); 153004ca37d5SLorenzo Bianconi if (err < 0) 1531b5969abfSSean Nyekjaer return -EINVAL; 1532b5969abfSSean Nyekjaer 1533b5969abfSSean Nyekjaer hw->event_threshold = val; 1534b5969abfSSean Nyekjaer 1535b5969abfSSean Nyekjaer return 0; 1536b5969abfSSean Nyekjaer } 1537b5969abfSSean Nyekjaer 1538b307f495SLorenzo Bianconi static int 1539b307f495SLorenzo Bianconi st_lsm6dsx_read_event_config(struct iio_dev *iio_dev, 1540b5969abfSSean Nyekjaer const struct iio_chan_spec *chan, 1541b5969abfSSean Nyekjaer enum iio_event_type type, 1542b5969abfSSean Nyekjaer enum iio_event_direction dir) 1543b5969abfSSean Nyekjaer { 1544b5969abfSSean Nyekjaer struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); 1545b5969abfSSean Nyekjaer struct st_lsm6dsx_hw *hw = sensor->hw; 1546b5969abfSSean Nyekjaer 1547b5969abfSSean Nyekjaer if (type != IIO_EV_TYPE_THRESH) 1548b5969abfSSean Nyekjaer return -EINVAL; 1549b5969abfSSean Nyekjaer 15501aabad1fSSean Nyekjaer return !!(hw->enable_event & BIT(chan->channel2)); 1551b5969abfSSean Nyekjaer } 1552b5969abfSSean Nyekjaer 1553b307f495SLorenzo Bianconi static int 1554b307f495SLorenzo Bianconi st_lsm6dsx_write_event_config(struct iio_dev *iio_dev, 1555b5969abfSSean Nyekjaer const struct iio_chan_spec *chan, 1556b5969abfSSean Nyekjaer enum iio_event_type type, 1557b307f495SLorenzo Bianconi enum iio_event_direction dir, int state) 1558b5969abfSSean Nyekjaer { 1559b5969abfSSean Nyekjaer struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); 1560b5969abfSSean Nyekjaer struct st_lsm6dsx_hw *hw = sensor->hw; 15611aabad1fSSean Nyekjaer u8 enable_event; 1562bd41c445SLorenzo Bianconi int err; 1563b5969abfSSean Nyekjaer 1564b5969abfSSean Nyekjaer if (type != IIO_EV_TYPE_THRESH) 1565b5969abfSSean Nyekjaer return -EINVAL; 1566b5969abfSSean Nyekjaer 15671aabad1fSSean Nyekjaer if (state) { 15681aabad1fSSean Nyekjaer enable_event = hw->enable_event | BIT(chan->channel2); 15691aabad1fSSean Nyekjaer 1570b5969abfSSean Nyekjaer /* do not enable events if they are already enabled */ 15711aabad1fSSean Nyekjaer if (hw->enable_event) 15721aabad1fSSean Nyekjaer goto out; 15731aabad1fSSean Nyekjaer } else { 15741aabad1fSSean Nyekjaer enable_event = hw->enable_event & ~BIT(chan->channel2); 15751aabad1fSSean Nyekjaer 15761aabad1fSSean Nyekjaer /* only turn off sensor if no events is enabled */ 15771aabad1fSSean Nyekjaer if (enable_event) 15781aabad1fSSean Nyekjaer goto out; 15791aabad1fSSean Nyekjaer } 15801aabad1fSSean Nyekjaer 15811aabad1fSSean Nyekjaer /* stop here if no changes have been made */ 15821aabad1fSSean Nyekjaer if (hw->enable_event == enable_event) 1583b5969abfSSean Nyekjaer return 0; 1584b5969abfSSean Nyekjaer 1585b5969abfSSean Nyekjaer err = st_lsm6dsx_event_setup(hw, state); 1586b5969abfSSean Nyekjaer if (err < 0) 1587b5969abfSSean Nyekjaer return err; 1588b5969abfSSean Nyekjaer 1589d278d447SLorenzo Bianconi mutex_lock(&hw->conf_lock); 1590bd41c445SLorenzo Bianconi if (enable_event || !(hw->fifo_mask & BIT(sensor->id))) 1591bd41c445SLorenzo Bianconi err = __st_lsm6dsx_sensor_set_enable(sensor, state); 1592d278d447SLorenzo Bianconi mutex_unlock(&hw->conf_lock); 1593b5969abfSSean Nyekjaer if (err < 0) 1594b5969abfSSean Nyekjaer return err; 1595b5969abfSSean Nyekjaer 15961aabad1fSSean Nyekjaer out: 15971aabad1fSSean Nyekjaer hw->enable_event = enable_event; 1598b5969abfSSean Nyekjaer 1599b5969abfSSean Nyekjaer return 0; 1600b5969abfSSean Nyekjaer } 1601b5969abfSSean Nyekjaer 1602d40464f3SLorenzo Bianconi int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val) 1603290a6ce1SLorenzo Bianconi { 1604290a6ce1SLorenzo Bianconi struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); 1605290a6ce1SLorenzo Bianconi struct st_lsm6dsx_hw *hw = sensor->hw; 16068f2a88a2SLorenzo Bianconi int err; 1607290a6ce1SLorenzo Bianconi 1608*1b7da2faSLorenzo Bianconi if (val < 1 || val > hw->settings->fifo_ops.max_size) 1609290a6ce1SLorenzo Bianconi return -EINVAL; 1610290a6ce1SLorenzo Bianconi 1611335eaedcSLorenzo Bianconi mutex_lock(&hw->conf_lock); 1612335eaedcSLorenzo Bianconi 1613290a6ce1SLorenzo Bianconi err = st_lsm6dsx_update_watermark(sensor, val); 1614335eaedcSLorenzo Bianconi 1615335eaedcSLorenzo Bianconi mutex_unlock(&hw->conf_lock); 1616335eaedcSLorenzo Bianconi 1617290a6ce1SLorenzo Bianconi if (err < 0) 1618290a6ce1SLorenzo Bianconi return err; 1619290a6ce1SLorenzo Bianconi 1620290a6ce1SLorenzo Bianconi sensor->watermark = val; 1621290a6ce1SLorenzo Bianconi 1622290a6ce1SLorenzo Bianconi return 0; 1623290a6ce1SLorenzo Bianconi } 1624290a6ce1SLorenzo Bianconi 1625290a6ce1SLorenzo Bianconi static ssize_t 1626290a6ce1SLorenzo Bianconi st_lsm6dsx_sysfs_sampling_frequency_avail(struct device *dev, 1627290a6ce1SLorenzo Bianconi struct device_attribute *attr, 1628290a6ce1SLorenzo Bianconi char *buf) 1629290a6ce1SLorenzo Bianconi { 1630290a6ce1SLorenzo Bianconi struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev)); 163159af4e20SLorenzo Bianconi const struct st_lsm6dsx_odr_table_entry *odr_table; 1632290a6ce1SLorenzo Bianconi int i, len = 0; 1633290a6ce1SLorenzo Bianconi 163459af4e20SLorenzo Bianconi odr_table = &sensor->hw->settings->odr_table[sensor->id]; 163559af4e20SLorenzo Bianconi for (i = 0; i < odr_table->odr_len; i++) 1636f8710f03SLorenzo Bianconi len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%03d ", 1637f8710f03SLorenzo Bianconi odr_table->odr_avl[i].milli_hz / 1000, 1638f8710f03SLorenzo Bianconi odr_table->odr_avl[i].milli_hz % 1000); 1639290a6ce1SLorenzo Bianconi buf[len - 1] = '\n'; 1640290a6ce1SLorenzo Bianconi 1641290a6ce1SLorenzo Bianconi return len; 1642290a6ce1SLorenzo Bianconi } 1643290a6ce1SLorenzo Bianconi 1644290a6ce1SLorenzo Bianconi static ssize_t st_lsm6dsx_sysfs_scale_avail(struct device *dev, 1645290a6ce1SLorenzo Bianconi struct device_attribute *attr, 1646290a6ce1SLorenzo Bianconi char *buf) 1647290a6ce1SLorenzo Bianconi { 1648290a6ce1SLorenzo Bianconi struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev)); 16490f7e1728SLorenzo Bianconi const struct st_lsm6dsx_fs_table_entry *fs_table; 1650640aca3fSLorenzo Bianconi struct st_lsm6dsx_hw *hw = sensor->hw; 1651290a6ce1SLorenzo Bianconi int i, len = 0; 1652290a6ce1SLorenzo Bianconi 165385ae3aeeSLorenzo Bianconi fs_table = &hw->settings->fs_table[sensor->id]; 165485ae3aeeSLorenzo Bianconi for (i = 0; i < fs_table->fs_len; i++) 165544a76de8SMario Tesi len += scnprintf(buf + len, PAGE_SIZE - len, "0.%09u ", 16560f7e1728SLorenzo Bianconi fs_table->fs_avl[i].gain); 1657290a6ce1SLorenzo Bianconi buf[len - 1] = '\n'; 1658290a6ce1SLorenzo Bianconi 1659290a6ce1SLorenzo Bianconi return len; 1660290a6ce1SLorenzo Bianconi } 1661290a6ce1SLorenzo Bianconi 166244a76de8SMario Tesi static int st_lsm6dsx_write_raw_get_fmt(struct iio_dev *indio_dev, 166344a76de8SMario Tesi struct iio_chan_spec const *chan, 166444a76de8SMario Tesi long mask) 166544a76de8SMario Tesi { 166644a76de8SMario Tesi switch (mask) { 166744a76de8SMario Tesi case IIO_CHAN_INFO_SCALE: 166844a76de8SMario Tesi switch (chan->type) { 166944a76de8SMario Tesi case IIO_ANGL_VEL: 167044a76de8SMario Tesi case IIO_ACCEL: 167144a76de8SMario Tesi return IIO_VAL_INT_PLUS_NANO; 167244a76de8SMario Tesi default: 167344a76de8SMario Tesi return IIO_VAL_INT_PLUS_MICRO; 167444a76de8SMario Tesi } 167544a76de8SMario Tesi default: 167644a76de8SMario Tesi return IIO_VAL_INT_PLUS_MICRO; 167744a76de8SMario Tesi } 167844a76de8SMario Tesi } 167944a76de8SMario Tesi 1680290a6ce1SLorenzo Bianconi static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(st_lsm6dsx_sysfs_sampling_frequency_avail); 1681290a6ce1SLorenzo Bianconi static IIO_DEVICE_ATTR(in_accel_scale_available, 0444, 1682290a6ce1SLorenzo Bianconi st_lsm6dsx_sysfs_scale_avail, NULL, 0); 1683290a6ce1SLorenzo Bianconi static IIO_DEVICE_ATTR(in_anglvel_scale_available, 0444, 1684290a6ce1SLorenzo Bianconi st_lsm6dsx_sysfs_scale_avail, NULL, 0); 1685290a6ce1SLorenzo Bianconi 1686290a6ce1SLorenzo Bianconi static struct attribute *st_lsm6dsx_acc_attributes[] = { 1687290a6ce1SLorenzo Bianconi &iio_dev_attr_sampling_frequency_available.dev_attr.attr, 1688290a6ce1SLorenzo Bianconi &iio_dev_attr_in_accel_scale_available.dev_attr.attr, 1689290a6ce1SLorenzo Bianconi NULL, 1690290a6ce1SLorenzo Bianconi }; 1691290a6ce1SLorenzo Bianconi 1692290a6ce1SLorenzo Bianconi static const struct attribute_group st_lsm6dsx_acc_attribute_group = { 1693290a6ce1SLorenzo Bianconi .attrs = st_lsm6dsx_acc_attributes, 1694290a6ce1SLorenzo Bianconi }; 1695290a6ce1SLorenzo Bianconi 1696290a6ce1SLorenzo Bianconi static const struct iio_info st_lsm6dsx_acc_info = { 1697290a6ce1SLorenzo Bianconi .attrs = &st_lsm6dsx_acc_attribute_group, 1698290a6ce1SLorenzo Bianconi .read_raw = st_lsm6dsx_read_raw, 1699290a6ce1SLorenzo Bianconi .write_raw = st_lsm6dsx_write_raw, 1700b5969abfSSean Nyekjaer .read_event_value = st_lsm6dsx_read_event, 1701b5969abfSSean Nyekjaer .write_event_value = st_lsm6dsx_write_event, 1702b5969abfSSean Nyekjaer .read_event_config = st_lsm6dsx_read_event_config, 1703b5969abfSSean Nyekjaer .write_event_config = st_lsm6dsx_write_event_config, 1704290a6ce1SLorenzo Bianconi .hwfifo_set_watermark = st_lsm6dsx_set_watermark, 170544a76de8SMario Tesi .write_raw_get_fmt = st_lsm6dsx_write_raw_get_fmt, 1706290a6ce1SLorenzo Bianconi }; 1707290a6ce1SLorenzo Bianconi 1708290a6ce1SLorenzo Bianconi static struct attribute *st_lsm6dsx_gyro_attributes[] = { 1709290a6ce1SLorenzo Bianconi &iio_dev_attr_sampling_frequency_available.dev_attr.attr, 1710290a6ce1SLorenzo Bianconi &iio_dev_attr_in_anglvel_scale_available.dev_attr.attr, 1711290a6ce1SLorenzo Bianconi NULL, 1712290a6ce1SLorenzo Bianconi }; 1713290a6ce1SLorenzo Bianconi 1714290a6ce1SLorenzo Bianconi static const struct attribute_group st_lsm6dsx_gyro_attribute_group = { 1715290a6ce1SLorenzo Bianconi .attrs = st_lsm6dsx_gyro_attributes, 1716290a6ce1SLorenzo Bianconi }; 1717290a6ce1SLorenzo Bianconi 1718290a6ce1SLorenzo Bianconi static const struct iio_info st_lsm6dsx_gyro_info = { 1719290a6ce1SLorenzo Bianconi .attrs = &st_lsm6dsx_gyro_attribute_group, 1720290a6ce1SLorenzo Bianconi .read_raw = st_lsm6dsx_read_raw, 1721290a6ce1SLorenzo Bianconi .write_raw = st_lsm6dsx_write_raw, 1722290a6ce1SLorenzo Bianconi .hwfifo_set_watermark = st_lsm6dsx_set_watermark, 172344a76de8SMario Tesi .write_raw_get_fmt = st_lsm6dsx_write_raw_get_fmt, 1724290a6ce1SLorenzo Bianconi }; 1725290a6ce1SLorenzo Bianconi 172603d4c566SAndy Shevchenko static int st_lsm6dsx_get_drdy_pin(struct st_lsm6dsx_hw *hw, int *drdy_pin) 1727dba32904SLorenzo Bianconi { 172803d4c566SAndy Shevchenko struct device *dev = hw->dev; 1729dba32904SLorenzo Bianconi 173003d4c566SAndy Shevchenko if (!dev_fwnode(dev)) 1731dba32904SLorenzo Bianconi return -EINVAL; 1732dba32904SLorenzo Bianconi 173303d4c566SAndy Shevchenko return device_property_read_u32(dev, "st,drdy-int-pin", drdy_pin); 1734dba32904SLorenzo Bianconi } 1735dba32904SLorenzo Bianconi 17367e906103SLorenzo Bianconi static int 17377e906103SLorenzo Bianconi st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, 17387e906103SLorenzo Bianconi const struct st_lsm6dsx_reg **drdy_reg) 1739dba32904SLorenzo Bianconi { 1740dba32904SLorenzo Bianconi int err = 0, drdy_pin; 1741dba32904SLorenzo Bianconi 174203d4c566SAndy Shevchenko if (st_lsm6dsx_get_drdy_pin(hw, &drdy_pin) < 0) { 1743dba32904SLorenzo Bianconi struct st_sensors_platform_data *pdata; 1744dba32904SLorenzo Bianconi struct device *dev = hw->dev; 1745dba32904SLorenzo Bianconi 1746dba32904SLorenzo Bianconi pdata = (struct st_sensors_platform_data *)dev->platform_data; 1747dba32904SLorenzo Bianconi drdy_pin = pdata ? pdata->drdy_int_pin : 1; 1748dba32904SLorenzo Bianconi } 1749dba32904SLorenzo Bianconi 1750dba32904SLorenzo Bianconi switch (drdy_pin) { 1751dba32904SLorenzo Bianconi case 1: 17527e906103SLorenzo Bianconi hw->irq_routing = &hw->settings->irq_config.irq1_func; 17537e906103SLorenzo Bianconi *drdy_reg = &hw->settings->irq_config.irq1; 1754dba32904SLorenzo Bianconi break; 1755dba32904SLorenzo Bianconi case 2: 17567e906103SLorenzo Bianconi hw->irq_routing = &hw->settings->irq_config.irq2_func; 17577e906103SLorenzo Bianconi *drdy_reg = &hw->settings->irq_config.irq2; 1758dba32904SLorenzo Bianconi break; 1759dba32904SLorenzo Bianconi default: 1760dba32904SLorenzo Bianconi dev_err(hw->dev, "unsupported data ready pin\n"); 1761dba32904SLorenzo Bianconi err = -EINVAL; 1762dba32904SLorenzo Bianconi break; 1763dba32904SLorenzo Bianconi } 1764dba32904SLorenzo Bianconi 1765dba32904SLorenzo Bianconi return err; 1766dba32904SLorenzo Bianconi } 1767dba32904SLorenzo Bianconi 1768c91c1c84SLorenzo Bianconi static int st_lsm6dsx_init_shub(struct st_lsm6dsx_hw *hw) 1769c91c1c84SLorenzo Bianconi { 1770c91c1c84SLorenzo Bianconi const struct st_lsm6dsx_shub_settings *hub_settings; 1771c91c1c84SLorenzo Bianconi struct st_sensors_platform_data *pdata; 177203d4c566SAndy Shevchenko struct device *dev = hw->dev; 1773c91c1c84SLorenzo Bianconi unsigned int data; 1774c91c1c84SLorenzo Bianconi int err = 0; 1775c91c1c84SLorenzo Bianconi 1776c91c1c84SLorenzo Bianconi hub_settings = &hw->settings->shub_settings; 1777c91c1c84SLorenzo Bianconi 177803d4c566SAndy Shevchenko pdata = (struct st_sensors_platform_data *)dev->platform_data; 177903d4c566SAndy Shevchenko if ((dev_fwnode(dev) && device_property_read_bool(dev, "st,pullups")) || 1780c91c1c84SLorenzo Bianconi (pdata && pdata->pullups)) { 17813a431957SLorenzo Bianconi if (hub_settings->pullup_en.sec_page) { 1782c91c1c84SLorenzo Bianconi err = st_lsm6dsx_set_page(hw, true); 1783c91c1c84SLorenzo Bianconi if (err < 0) 1784c91c1c84SLorenzo Bianconi return err; 17853a431957SLorenzo Bianconi } 1786c91c1c84SLorenzo Bianconi 1787c91c1c84SLorenzo Bianconi data = ST_LSM6DSX_SHIFT_VAL(1, hub_settings->pullup_en.mask); 1788c91c1c84SLorenzo Bianconi err = regmap_update_bits(hw->regmap, 1789c91c1c84SLorenzo Bianconi hub_settings->pullup_en.addr, 1790c91c1c84SLorenzo Bianconi hub_settings->pullup_en.mask, data); 1791c91c1c84SLorenzo Bianconi 17923a431957SLorenzo Bianconi if (hub_settings->pullup_en.sec_page) 1793c91c1c84SLorenzo Bianconi st_lsm6dsx_set_page(hw, false); 1794c91c1c84SLorenzo Bianconi 1795c91c1c84SLorenzo Bianconi if (err < 0) 1796c91c1c84SLorenzo Bianconi return err; 1797c91c1c84SLorenzo Bianconi } 1798c91c1c84SLorenzo Bianconi 1799c91c1c84SLorenzo Bianconi if (hub_settings->aux_sens.addr) { 1800c91c1c84SLorenzo Bianconi /* configure aux sensors */ 1801c91c1c84SLorenzo Bianconi err = st_lsm6dsx_set_page(hw, true); 1802c91c1c84SLorenzo Bianconi if (err < 0) 1803c91c1c84SLorenzo Bianconi return err; 1804c91c1c84SLorenzo Bianconi 1805c91c1c84SLorenzo Bianconi data = ST_LSM6DSX_SHIFT_VAL(3, hub_settings->aux_sens.mask); 1806c91c1c84SLorenzo Bianconi err = regmap_update_bits(hw->regmap, 1807c91c1c84SLorenzo Bianconi hub_settings->aux_sens.addr, 1808c91c1c84SLorenzo Bianconi hub_settings->aux_sens.mask, data); 1809c91c1c84SLorenzo Bianconi 1810c91c1c84SLorenzo Bianconi st_lsm6dsx_set_page(hw, false); 1811e485e2a2SLorenzo Bianconi 1812e485e2a2SLorenzo Bianconi if (err < 0) 1813e485e2a2SLorenzo Bianconi return err; 1814e485e2a2SLorenzo Bianconi } 1815e485e2a2SLorenzo Bianconi 1816e485e2a2SLorenzo Bianconi if (hub_settings->emb_func.addr) { 1817e485e2a2SLorenzo Bianconi data = ST_LSM6DSX_SHIFT_VAL(1, hub_settings->emb_func.mask); 1818e485e2a2SLorenzo Bianconi err = regmap_update_bits(hw->regmap, 1819e485e2a2SLorenzo Bianconi hub_settings->emb_func.addr, 1820e485e2a2SLorenzo Bianconi hub_settings->emb_func.mask, data); 1821c91c1c84SLorenzo Bianconi } 1822c91c1c84SLorenzo Bianconi 1823c91c1c84SLorenzo Bianconi return err; 1824c91c1c84SLorenzo Bianconi } 1825c91c1c84SLorenzo Bianconi 182621345107SLorenzo Bianconi static int st_lsm6dsx_init_hw_timer(struct st_lsm6dsx_hw *hw) 182721345107SLorenzo Bianconi { 182821345107SLorenzo Bianconi const struct st_lsm6dsx_hw_ts_settings *ts_settings; 182921345107SLorenzo Bianconi int err, val; 183021345107SLorenzo Bianconi 183121345107SLorenzo Bianconi ts_settings = &hw->settings->ts_settings; 183221345107SLorenzo Bianconi /* enable hw timestamp generation if necessary */ 183321345107SLorenzo Bianconi if (ts_settings->timer_en.addr) { 183421345107SLorenzo Bianconi val = ST_LSM6DSX_SHIFT_VAL(1, ts_settings->timer_en.mask); 183521345107SLorenzo Bianconi err = regmap_update_bits(hw->regmap, 183621345107SLorenzo Bianconi ts_settings->timer_en.addr, 183721345107SLorenzo Bianconi ts_settings->timer_en.mask, val); 183821345107SLorenzo Bianconi if (err < 0) 183921345107SLorenzo Bianconi return err; 184021345107SLorenzo Bianconi } 184121345107SLorenzo Bianconi 184221345107SLorenzo Bianconi /* enable high resolution for hw ts timer if necessary */ 184321345107SLorenzo Bianconi if (ts_settings->hr_timer.addr) { 184421345107SLorenzo Bianconi val = ST_LSM6DSX_SHIFT_VAL(1, ts_settings->hr_timer.mask); 184521345107SLorenzo Bianconi err = regmap_update_bits(hw->regmap, 184621345107SLorenzo Bianconi ts_settings->hr_timer.addr, 184721345107SLorenzo Bianconi ts_settings->hr_timer.mask, val); 184821345107SLorenzo Bianconi if (err < 0) 184921345107SLorenzo Bianconi return err; 185021345107SLorenzo Bianconi } 185121345107SLorenzo Bianconi 185221345107SLorenzo Bianconi /* enable ts queueing in FIFO if necessary */ 185321345107SLorenzo Bianconi if (ts_settings->fifo_en.addr) { 185421345107SLorenzo Bianconi val = ST_LSM6DSX_SHIFT_VAL(1, ts_settings->fifo_en.mask); 185521345107SLorenzo Bianconi err = regmap_update_bits(hw->regmap, 185621345107SLorenzo Bianconi ts_settings->fifo_en.addr, 185721345107SLorenzo Bianconi ts_settings->fifo_en.mask, val); 185821345107SLorenzo Bianconi if (err < 0) 185921345107SLorenzo Bianconi return err; 186021345107SLorenzo Bianconi } 1861cb3b6b8eSMario Tesi 1862cb3b6b8eSMario Tesi /* calibrate timestamp sensitivity */ 1863cb3b6b8eSMario Tesi hw->ts_gain = ST_LSM6DSX_TS_SENSITIVITY; 1864cb3b6b8eSMario Tesi if (ts_settings->freq_fine) { 1865cb3b6b8eSMario Tesi err = regmap_read(hw->regmap, ts_settings->freq_fine, &val); 1866cb3b6b8eSMario Tesi if (err < 0) 1867cb3b6b8eSMario Tesi return err; 1868cb3b6b8eSMario Tesi 1869cb3b6b8eSMario Tesi /* 1870cb3b6b8eSMario Tesi * linearize the AN5192 formula: 1871cb3b6b8eSMario Tesi * 1 / (1 + x) ~= 1 - x (Taylor’s Series) 1872cb3b6b8eSMario Tesi * ttrim[s] = 1 / (40000 * (1 + 0.0015 * val)) 1873cb3b6b8eSMario Tesi * ttrim[ns] ~= 25000 - 37.5 * val 1874cb3b6b8eSMario Tesi * ttrim[ns] ~= 25000 - (37500 * val) / 1000 1875cb3b6b8eSMario Tesi */ 1876cb3b6b8eSMario Tesi hw->ts_gain -= ((s8)val * 37500) / 1000; 1877cb3b6b8eSMario Tesi } 1878cb3b6b8eSMario Tesi 187921345107SLorenzo Bianconi return 0; 188021345107SLorenzo Bianconi } 188121345107SLorenzo Bianconi 18823a63da26SLorenzo Bianconi static int st_lsm6dsx_reset_device(struct st_lsm6dsx_hw *hw) 1883290a6ce1SLorenzo Bianconi { 18847e906103SLorenzo Bianconi const struct st_lsm6dsx_reg *reg; 1885290a6ce1SLorenzo Bianconi int err; 1886290a6ce1SLorenzo Bianconi 18873a63da26SLorenzo Bianconi /* 18883a63da26SLorenzo Bianconi * flush hw FIFO before device reset in order to avoid 18893a63da26SLorenzo Bianconi * possible races on interrupt line 1. If the first interrupt 18903a63da26SLorenzo Bianconi * line is asserted during hw reset the device will work in 18913a63da26SLorenzo Bianconi * I3C-only mode (if it is supported) 18923a63da26SLorenzo Bianconi */ 18933a63da26SLorenzo Bianconi err = st_lsm6dsx_flush_fifo(hw); 18943a63da26SLorenzo Bianconi if (err < 0 && err != -ENOTSUPP) 18953a63da26SLorenzo Bianconi return err; 18963a63da26SLorenzo Bianconi 189719435425SLorenzo Bianconi /* device sw reset */ 189866b662a1SLorenzo Bianconi reg = &hw->settings->reset; 189966b662a1SLorenzo Bianconi err = regmap_update_bits(hw->regmap, reg->addr, reg->mask, 190066b662a1SLorenzo Bianconi ST_LSM6DSX_SHIFT_VAL(1, reg->mask)); 1901290a6ce1SLorenzo Bianconi if (err < 0) 1902290a6ce1SLorenzo Bianconi return err; 1903290a6ce1SLorenzo Bianconi 190419435425SLorenzo Bianconi msleep(50); 190519435425SLorenzo Bianconi 190619435425SLorenzo Bianconi /* reload trimming parameter */ 190766b662a1SLorenzo Bianconi reg = &hw->settings->boot; 190866b662a1SLorenzo Bianconi err = regmap_update_bits(hw->regmap, reg->addr, reg->mask, 190966b662a1SLorenzo Bianconi ST_LSM6DSX_SHIFT_VAL(1, reg->mask)); 191019435425SLorenzo Bianconi if (err < 0) 191119435425SLorenzo Bianconi return err; 191219435425SLorenzo Bianconi 191319435425SLorenzo Bianconi msleep(50); 1914290a6ce1SLorenzo Bianconi 19153a63da26SLorenzo Bianconi return 0; 19163a63da26SLorenzo Bianconi } 19173a63da26SLorenzo Bianconi 19183a63da26SLorenzo Bianconi static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw) 19193a63da26SLorenzo Bianconi { 19203a63da26SLorenzo Bianconi const struct st_lsm6dsx_reg *reg; 19213a63da26SLorenzo Bianconi int err; 19223a63da26SLorenzo Bianconi 19233a63da26SLorenzo Bianconi err = st_lsm6dsx_reset_device(hw); 19243a63da26SLorenzo Bianconi if (err < 0) 19253a63da26SLorenzo Bianconi return err; 19263a63da26SLorenzo Bianconi 1927290a6ce1SLorenzo Bianconi /* enable Block Data Update */ 192866b662a1SLorenzo Bianconi reg = &hw->settings->bdu; 192966b662a1SLorenzo Bianconi err = regmap_update_bits(hw->regmap, reg->addr, reg->mask, 193066b662a1SLorenzo Bianconi ST_LSM6DSX_SHIFT_VAL(1, reg->mask)); 1931290a6ce1SLorenzo Bianconi if (err < 0) 1932290a6ce1SLorenzo Bianconi return err; 1933290a6ce1SLorenzo Bianconi 1934290a6ce1SLorenzo Bianconi /* enable FIFO watermak interrupt */ 19357e906103SLorenzo Bianconi err = st_lsm6dsx_get_drdy_reg(hw, ®); 1936290a6ce1SLorenzo Bianconi if (err < 0) 1937290a6ce1SLorenzo Bianconi return err; 1938290a6ce1SLorenzo Bianconi 19397e906103SLorenzo Bianconi err = regmap_update_bits(hw->regmap, reg->addr, reg->mask, 19407e906103SLorenzo Bianconi ST_LSM6DSX_SHIFT_VAL(1, reg->mask)); 194121345107SLorenzo Bianconi if (err < 0) 194221345107SLorenzo Bianconi return err; 194321345107SLorenzo Bianconi 19449db02d32SLorenzo Bianconi /* enable Latched interrupts for device events */ 19457e906103SLorenzo Bianconi if (hw->settings->irq_config.lir.addr) { 19467e906103SLorenzo Bianconi reg = &hw->settings->irq_config.lir; 19477e906103SLorenzo Bianconi err = regmap_update_bits(hw->regmap, reg->addr, reg->mask, 19487e906103SLorenzo Bianconi ST_LSM6DSX_SHIFT_VAL(1, reg->mask)); 19499db02d32SLorenzo Bianconi if (err < 0) 19509db02d32SLorenzo Bianconi return err; 195122ea5651SLorenzo Bianconi 195222ea5651SLorenzo Bianconi /* enable clear on read for latched interrupts */ 19537e906103SLorenzo Bianconi if (hw->settings->irq_config.clear_on_read.addr) { 19547e906103SLorenzo Bianconi reg = &hw->settings->irq_config.clear_on_read; 195522ea5651SLorenzo Bianconi err = regmap_update_bits(hw->regmap, 19567e906103SLorenzo Bianconi reg->addr, reg->mask, 19577e906103SLorenzo Bianconi ST_LSM6DSX_SHIFT_VAL(1, reg->mask)); 195822ea5651SLorenzo Bianconi if (err < 0) 195922ea5651SLorenzo Bianconi return err; 196022ea5651SLorenzo Bianconi } 19619db02d32SLorenzo Bianconi } 19629db02d32SLorenzo Bianconi 1963960506edSLorenzo Bianconi /* enable drdy-mas if available */ 1964960506edSLorenzo Bianconi if (hw->settings->drdy_mask.addr) { 1965960506edSLorenzo Bianconi reg = &hw->settings->drdy_mask; 1966960506edSLorenzo Bianconi err = regmap_update_bits(hw->regmap, reg->addr, reg->mask, 1967960506edSLorenzo Bianconi ST_LSM6DSX_SHIFT_VAL(1, reg->mask)); 1968960506edSLorenzo Bianconi if (err < 0) 1969960506edSLorenzo Bianconi return err; 1970960506edSLorenzo Bianconi } 1971960506edSLorenzo Bianconi 1972c91c1c84SLorenzo Bianconi err = st_lsm6dsx_init_shub(hw); 1973c91c1c84SLorenzo Bianconi if (err < 0) 1974c91c1c84SLorenzo Bianconi return err; 1975c91c1c84SLorenzo Bianconi 197621345107SLorenzo Bianconi return st_lsm6dsx_init_hw_timer(hw); 1977290a6ce1SLorenzo Bianconi } 1978290a6ce1SLorenzo Bianconi 1979290a6ce1SLorenzo Bianconi static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw, 1980510c0106SLorenzo Bianconi enum st_lsm6dsx_sensor_id id, 1981510c0106SLorenzo Bianconi const char *name) 1982290a6ce1SLorenzo Bianconi { 1983290a6ce1SLorenzo Bianconi struct st_lsm6dsx_sensor *sensor; 1984290a6ce1SLorenzo Bianconi struct iio_dev *iio_dev; 1985290a6ce1SLorenzo Bianconi 1986290a6ce1SLorenzo Bianconi iio_dev = devm_iio_device_alloc(hw->dev, sizeof(*sensor)); 1987290a6ce1SLorenzo Bianconi if (!iio_dev) 1988290a6ce1SLorenzo Bianconi return NULL; 1989290a6ce1SLorenzo Bianconi 1990290a6ce1SLorenzo Bianconi iio_dev->modes = INDIO_DIRECT_MODE; 1991290a6ce1SLorenzo Bianconi iio_dev->available_scan_masks = st_lsm6dsx_available_scan_masks; 1992f48bc49bSLorenzo Bianconi iio_dev->channels = hw->settings->channels[id].chan; 1993f48bc49bSLorenzo Bianconi iio_dev->num_channels = hw->settings->channels[id].len; 1994290a6ce1SLorenzo Bianconi 1995290a6ce1SLorenzo Bianconi sensor = iio_priv(iio_dev); 1996290a6ce1SLorenzo Bianconi sensor->id = id; 1997290a6ce1SLorenzo Bianconi sensor->hw = hw; 1998f8710f03SLorenzo Bianconi sensor->odr = hw->settings->odr_table[id].odr_avl[0].milli_hz; 1999640aca3fSLorenzo Bianconi sensor->gain = hw->settings->fs_table[id].fs_avl[0].gain; 2000290a6ce1SLorenzo Bianconi sensor->watermark = 1; 2001290a6ce1SLorenzo Bianconi 2002290a6ce1SLorenzo Bianconi switch (id) { 2003290a6ce1SLorenzo Bianconi case ST_LSM6DSX_ID_ACC: 2004290a6ce1SLorenzo Bianconi iio_dev->info = &st_lsm6dsx_acc_info; 2005510c0106SLorenzo Bianconi scnprintf(sensor->name, sizeof(sensor->name), "%s_accel", 2006510c0106SLorenzo Bianconi name); 2007290a6ce1SLorenzo Bianconi break; 2008290a6ce1SLorenzo Bianconi case ST_LSM6DSX_ID_GYRO: 2009290a6ce1SLorenzo Bianconi iio_dev->info = &st_lsm6dsx_gyro_info; 2010510c0106SLorenzo Bianconi scnprintf(sensor->name, sizeof(sensor->name), "%s_gyro", 2011510c0106SLorenzo Bianconi name); 2012290a6ce1SLorenzo Bianconi break; 2013290a6ce1SLorenzo Bianconi default: 2014290a6ce1SLorenzo Bianconi return NULL; 2015290a6ce1SLorenzo Bianconi } 2016510c0106SLorenzo Bianconi iio_dev->name = sensor->name; 2017290a6ce1SLorenzo Bianconi 2018290a6ce1SLorenzo Bianconi return iio_dev; 2019290a6ce1SLorenzo Bianconi } 2020290a6ce1SLorenzo Bianconi 2021615bd378SLorenzo Bianconi static bool 2022615bd378SLorenzo Bianconi st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw) 20231aabad1fSSean Nyekjaer { 2024615bd378SLorenzo Bianconi const struct st_lsm6dsx_event_settings *event_settings; 2025615bd378SLorenzo Bianconi int err, data; 2026615bd378SLorenzo Bianconi s64 timestamp; 20271aabad1fSSean Nyekjaer 2028615bd378SLorenzo Bianconi if (!hw->enable_event) 2029615bd378SLorenzo Bianconi return false; 2030615bd378SLorenzo Bianconi 2031615bd378SLorenzo Bianconi event_settings = &hw->settings->event_settings; 2032615bd378SLorenzo Bianconi err = st_lsm6dsx_read_locked(hw, event_settings->wakeup_src_reg, 2033615bd378SLorenzo Bianconi &data, sizeof(data)); 2034615bd378SLorenzo Bianconi if (err < 0) 2035615bd378SLorenzo Bianconi return false; 2036615bd378SLorenzo Bianconi 2037615bd378SLorenzo Bianconi timestamp = iio_get_time_ns(hw->iio_devs[ST_LSM6DSX_ID_ACC]); 20381aabad1fSSean Nyekjaer if ((data & hw->settings->event_settings.wakeup_src_z_mask) && 20391aabad1fSSean Nyekjaer (hw->enable_event & BIT(IIO_MOD_Z))) 20401aabad1fSSean Nyekjaer iio_push_event(hw->iio_devs[ST_LSM6DSX_ID_ACC], 20411aabad1fSSean Nyekjaer IIO_MOD_EVENT_CODE(IIO_ACCEL, 20421aabad1fSSean Nyekjaer 0, 20431aabad1fSSean Nyekjaer IIO_MOD_Z, 20441aabad1fSSean Nyekjaer IIO_EV_TYPE_THRESH, 20451aabad1fSSean Nyekjaer IIO_EV_DIR_EITHER), 20461aabad1fSSean Nyekjaer timestamp); 20471aabad1fSSean Nyekjaer 20481aabad1fSSean Nyekjaer if ((data & hw->settings->event_settings.wakeup_src_y_mask) && 20491aabad1fSSean Nyekjaer (hw->enable_event & BIT(IIO_MOD_Y))) 20501aabad1fSSean Nyekjaer iio_push_event(hw->iio_devs[ST_LSM6DSX_ID_ACC], 20511aabad1fSSean Nyekjaer IIO_MOD_EVENT_CODE(IIO_ACCEL, 20521aabad1fSSean Nyekjaer 0, 20531aabad1fSSean Nyekjaer IIO_MOD_Y, 20541aabad1fSSean Nyekjaer IIO_EV_TYPE_THRESH, 20551aabad1fSSean Nyekjaer IIO_EV_DIR_EITHER), 20561aabad1fSSean Nyekjaer timestamp); 20571aabad1fSSean Nyekjaer 20581aabad1fSSean Nyekjaer if ((data & hw->settings->event_settings.wakeup_src_x_mask) && 20591aabad1fSSean Nyekjaer (hw->enable_event & BIT(IIO_MOD_X))) 20601aabad1fSSean Nyekjaer iio_push_event(hw->iio_devs[ST_LSM6DSX_ID_ACC], 20611aabad1fSSean Nyekjaer IIO_MOD_EVENT_CODE(IIO_ACCEL, 20621aabad1fSSean Nyekjaer 0, 20631aabad1fSSean Nyekjaer IIO_MOD_X, 20641aabad1fSSean Nyekjaer IIO_EV_TYPE_THRESH, 20651aabad1fSSean Nyekjaer IIO_EV_DIR_EITHER), 20661aabad1fSSean Nyekjaer timestamp); 2067615bd378SLorenzo Bianconi 2068615bd378SLorenzo Bianconi return data & event_settings->wakeup_src_status_mask; 20691aabad1fSSean Nyekjaer } 20701aabad1fSSean Nyekjaer 20716ee6a368SSean Nyekjaer static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private) 20726ee6a368SSean Nyekjaer { 20736ee6a368SSean Nyekjaer struct st_lsm6dsx_hw *hw = private; 20743f9bce7aSLorenzo Bianconi int fifo_len = 0, len; 2075615bd378SLorenzo Bianconi bool event; 20761aabad1fSSean Nyekjaer 2077615bd378SLorenzo Bianconi event = st_lsm6dsx_report_motion_event(hw); 20786ee6a368SSean Nyekjaer 2079a912ee4cSLorenzo Bianconi if (!hw->settings->fifo_ops.read_fifo) 2080a912ee4cSLorenzo Bianconi return event ? IRQ_HANDLED : IRQ_NONE; 2081a912ee4cSLorenzo Bianconi 20823f9bce7aSLorenzo Bianconi /* 20833f9bce7aSLorenzo Bianconi * If we are using edge IRQs, new samples can arrive while 20843f9bce7aSLorenzo Bianconi * processing current interrupt since there are no hw 20853f9bce7aSLorenzo Bianconi * guarantees the irq line stays "low" long enough to properly 20863f9bce7aSLorenzo Bianconi * detect the new interrupt. In this case the new sample will 20873f9bce7aSLorenzo Bianconi * be missed. 20883f9bce7aSLorenzo Bianconi * Polling FIFO status register allow us to read new 20893f9bce7aSLorenzo Bianconi * samples even if the interrupt arrives while processing 20903f9bce7aSLorenzo Bianconi * previous data and the timeslot where the line is "low" is 20913f9bce7aSLorenzo Bianconi * too short to be properly detected. 20923f9bce7aSLorenzo Bianconi */ 20933f9bce7aSLorenzo Bianconi do { 20946ee6a368SSean Nyekjaer mutex_lock(&hw->fifo_lock); 20953f9bce7aSLorenzo Bianconi len = hw->settings->fifo_ops.read_fifo(hw); 20966ee6a368SSean Nyekjaer mutex_unlock(&hw->fifo_lock); 20976ee6a368SSean Nyekjaer 20983f9bce7aSLorenzo Bianconi if (len > 0) 20993f9bce7aSLorenzo Bianconi fifo_len += len; 21003f9bce7aSLorenzo Bianconi } while (len > 0); 21013f9bce7aSLorenzo Bianconi 21023f9bce7aSLorenzo Bianconi return fifo_len || event ? IRQ_HANDLED : IRQ_NONE; 21036ee6a368SSean Nyekjaer } 21046ee6a368SSean Nyekjaer 21056ee6a368SSean Nyekjaer static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw) 21066ee6a368SSean Nyekjaer { 210731fe8d4eSLorenzo Bianconi struct st_sensors_platform_data *pdata; 210831fe8d4eSLorenzo Bianconi const struct st_lsm6dsx_reg *reg; 210903d4c566SAndy Shevchenko struct device *dev = hw->dev; 21106ee6a368SSean Nyekjaer unsigned long irq_type; 21116ee6a368SSean Nyekjaer bool irq_active_low; 21126ee6a368SSean Nyekjaer int err; 21136ee6a368SSean Nyekjaer 21146ee6a368SSean Nyekjaer irq_type = irqd_get_trigger_type(irq_get_irq_data(hw->irq)); 21156ee6a368SSean Nyekjaer 21166ee6a368SSean Nyekjaer switch (irq_type) { 21176ee6a368SSean Nyekjaer case IRQF_TRIGGER_HIGH: 21186ee6a368SSean Nyekjaer case IRQF_TRIGGER_RISING: 21196ee6a368SSean Nyekjaer irq_active_low = false; 21206ee6a368SSean Nyekjaer break; 21216ee6a368SSean Nyekjaer case IRQF_TRIGGER_LOW: 21226ee6a368SSean Nyekjaer case IRQF_TRIGGER_FALLING: 21236ee6a368SSean Nyekjaer irq_active_low = true; 21246ee6a368SSean Nyekjaer break; 21256ee6a368SSean Nyekjaer default: 21266ee6a368SSean Nyekjaer dev_info(hw->dev, "mode %lx unsupported\n", irq_type); 21276ee6a368SSean Nyekjaer return -EINVAL; 21286ee6a368SSean Nyekjaer } 21296ee6a368SSean Nyekjaer 213031fe8d4eSLorenzo Bianconi reg = &hw->settings->irq_config.hla; 213131fe8d4eSLorenzo Bianconi err = regmap_update_bits(hw->regmap, reg->addr, reg->mask, 213231fe8d4eSLorenzo Bianconi ST_LSM6DSX_SHIFT_VAL(irq_active_low, 213331fe8d4eSLorenzo Bianconi reg->mask)); 21346ee6a368SSean Nyekjaer if (err < 0) 21356ee6a368SSean Nyekjaer return err; 21366ee6a368SSean Nyekjaer 213703d4c566SAndy Shevchenko pdata = (struct st_sensors_platform_data *)dev->platform_data; 213803d4c566SAndy Shevchenko if ((dev_fwnode(dev) && device_property_read_bool(dev, "drive-open-drain")) || 21396ee6a368SSean Nyekjaer (pdata && pdata->open_drain)) { 214031fe8d4eSLorenzo Bianconi reg = &hw->settings->irq_config.od; 214131fe8d4eSLorenzo Bianconi err = regmap_update_bits(hw->regmap, reg->addr, reg->mask, 214231fe8d4eSLorenzo Bianconi ST_LSM6DSX_SHIFT_VAL(1, reg->mask)); 21436ee6a368SSean Nyekjaer if (err < 0) 21446ee6a368SSean Nyekjaer return err; 21456ee6a368SSean Nyekjaer 21466ee6a368SSean Nyekjaer irq_type |= IRQF_SHARED; 21476ee6a368SSean Nyekjaer } 21486ee6a368SSean Nyekjaer 21496ee6a368SSean Nyekjaer err = devm_request_threaded_irq(hw->dev, hw->irq, 2150a3aa17d4SSean Nyekjaer NULL, 21516ee6a368SSean Nyekjaer st_lsm6dsx_handler_thread, 21526ee6a368SSean Nyekjaer irq_type | IRQF_ONESHOT, 21536ee6a368SSean Nyekjaer "lsm6dsx", hw); 21546ee6a368SSean Nyekjaer if (err) { 21556ee6a368SSean Nyekjaer dev_err(hw->dev, "failed to request trigger irq %d\n", 21566ee6a368SSean Nyekjaer hw->irq); 21576ee6a368SSean Nyekjaer return err; 21586ee6a368SSean Nyekjaer } 21596ee6a368SSean Nyekjaer 21606ee6a368SSean Nyekjaer return 0; 21616ee6a368SSean Nyekjaer } 21626ee6a368SSean Nyekjaer 2163f346b16fSLorenzo Bianconi static int st_lsm6dsx_init_regulators(struct device *dev) 2164f346b16fSLorenzo Bianconi { 2165f346b16fSLorenzo Bianconi struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev); 2166f346b16fSLorenzo Bianconi int err; 2167f346b16fSLorenzo Bianconi 2168f346b16fSLorenzo Bianconi /* vdd-vddio power regulators */ 2169f346b16fSLorenzo Bianconi hw->regulators[0].supply = "vdd"; 2170f346b16fSLorenzo Bianconi hw->regulators[1].supply = "vddio"; 2171f346b16fSLorenzo Bianconi err = devm_regulator_bulk_get(dev, ARRAY_SIZE(hw->regulators), 2172f346b16fSLorenzo Bianconi hw->regulators); 2173f346b16fSLorenzo Bianconi if (err) 2174f346b16fSLorenzo Bianconi return dev_err_probe(dev, err, "failed to get regulators\n"); 2175f346b16fSLorenzo Bianconi 2176f346b16fSLorenzo Bianconi err = regulator_bulk_enable(ARRAY_SIZE(hw->regulators), 2177f346b16fSLorenzo Bianconi hw->regulators); 2178f346b16fSLorenzo Bianconi if (err) { 2179f346b16fSLorenzo Bianconi dev_err(dev, "failed to enable regulators: %d\n", err); 2180f346b16fSLorenzo Bianconi return err; 2181f346b16fSLorenzo Bianconi } 2182f346b16fSLorenzo Bianconi 2183f346b16fSLorenzo Bianconi msleep(50); 2184f346b16fSLorenzo Bianconi 2185f346b16fSLorenzo Bianconi return 0; 2186f346b16fSLorenzo Bianconi } 2187f346b16fSLorenzo Bianconi 2188f346b16fSLorenzo Bianconi static void st_lsm6dsx_chip_uninit(void *data) 2189f346b16fSLorenzo Bianconi { 2190f346b16fSLorenzo Bianconi struct st_lsm6dsx_hw *hw = data; 2191f346b16fSLorenzo Bianconi 2192f346b16fSLorenzo Bianconi regulator_bulk_disable(ARRAY_SIZE(hw->regulators), hw->regulators); 2193f346b16fSLorenzo Bianconi } 2194f346b16fSLorenzo Bianconi 219581956a93SLorenzo Bianconi int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, 219651a8b707SLorenzo Bianconi struct regmap *regmap) 2197290a6ce1SLorenzo Bianconi { 2198b7a73b33SLorenzo Bianconi struct st_sensors_platform_data *pdata = dev->platform_data; 2199c91c1c84SLorenzo Bianconi const struct st_lsm6dsx_shub_settings *hub_settings; 2200290a6ce1SLorenzo Bianconi struct st_lsm6dsx_hw *hw; 220181956a93SLorenzo Bianconi const char *name = NULL; 2202290a6ce1SLorenzo Bianconi int i, err; 2203290a6ce1SLorenzo Bianconi 2204290a6ce1SLorenzo Bianconi hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL); 2205290a6ce1SLorenzo Bianconi if (!hw) 2206290a6ce1SLorenzo Bianconi return -ENOMEM; 2207290a6ce1SLorenzo Bianconi 2208290a6ce1SLorenzo Bianconi dev_set_drvdata(dev, (void *)hw); 2209290a6ce1SLorenzo Bianconi 2210290a6ce1SLorenzo Bianconi mutex_init(&hw->fifo_lock); 2211335eaedcSLorenzo Bianconi mutex_init(&hw->conf_lock); 2212739aff87SLorenzo Bianconi mutex_init(&hw->page_lock); 2213290a6ce1SLorenzo Bianconi 2214f346b16fSLorenzo Bianconi err = st_lsm6dsx_init_regulators(dev); 2215f346b16fSLorenzo Bianconi if (err) 2216f346b16fSLorenzo Bianconi return err; 2217f346b16fSLorenzo Bianconi 2218f346b16fSLorenzo Bianconi err = devm_add_action_or_reset(dev, st_lsm6dsx_chip_uninit, hw); 2219f346b16fSLorenzo Bianconi if (err) 2220f346b16fSLorenzo Bianconi return err; 2221f346b16fSLorenzo Bianconi 222291a6b841SLorenzo Bianconi hw->buff = devm_kzalloc(dev, ST_LSM6DSX_BUFF_SIZE, GFP_KERNEL); 222391a6b841SLorenzo Bianconi if (!hw->buff) 222491a6b841SLorenzo Bianconi return -ENOMEM; 222591a6b841SLorenzo Bianconi 2226290a6ce1SLorenzo Bianconi hw->dev = dev; 2227290a6ce1SLorenzo Bianconi hw->irq = irq; 222851a8b707SLorenzo Bianconi hw->regmap = regmap; 2229290a6ce1SLorenzo Bianconi 223081956a93SLorenzo Bianconi err = st_lsm6dsx_check_whoami(hw, hw_id, &name); 2231290a6ce1SLorenzo Bianconi if (err < 0) 2232290a6ce1SLorenzo Bianconi return err; 2233290a6ce1SLorenzo Bianconi 22346ffb55e5SLorenzo Bianconi for (i = 0; i < ST_LSM6DSX_ID_EXT0; i++) { 2235510c0106SLorenzo Bianconi hw->iio_devs[i] = st_lsm6dsx_alloc_iiodev(hw, i, name); 2236290a6ce1SLorenzo Bianconi if (!hw->iio_devs[i]) 2237290a6ce1SLorenzo Bianconi return -ENOMEM; 2238290a6ce1SLorenzo Bianconi } 2239290a6ce1SLorenzo Bianconi 2240290a6ce1SLorenzo Bianconi err = st_lsm6dsx_init_device(hw); 2241290a6ce1SLorenzo Bianconi if (err < 0) 2242290a6ce1SLorenzo Bianconi return err; 2243290a6ce1SLorenzo Bianconi 2244c91c1c84SLorenzo Bianconi hub_settings = &hw->settings->shub_settings; 2245c91c1c84SLorenzo Bianconi if (hub_settings->master_en.addr) { 2246c91c1c84SLorenzo Bianconi err = st_lsm6dsx_shub_probe(hw, name); 2247c91c1c84SLorenzo Bianconi if (err < 0) 2248c91c1c84SLorenzo Bianconi return err; 2249c91c1c84SLorenzo Bianconi } 2250c91c1c84SLorenzo Bianconi 2251290a6ce1SLorenzo Bianconi if (hw->irq > 0) { 22526ee6a368SSean Nyekjaer err = st_lsm6dsx_irq_setup(hw); 22536ee6a368SSean Nyekjaer if (err < 0) 22546ee6a368SSean Nyekjaer return err; 22556ee6a368SSean Nyekjaer 2256290a6ce1SLorenzo Bianconi err = st_lsm6dsx_fifo_setup(hw); 2257290a6ce1SLorenzo Bianconi if (err < 0) 2258290a6ce1SLorenzo Bianconi return err; 2259290a6ce1SLorenzo Bianconi } 2260290a6ce1SLorenzo Bianconi 2261b892770aSAndy Shevchenko err = iio_read_mount_matrix(hw->dev, &hw->orientation); 226204e6fedbSMartin Kepplinger if (err) 226304e6fedbSMartin Kepplinger return err; 226404e6fedbSMartin Kepplinger 2265290a6ce1SLorenzo Bianconi for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 22666ffb55e5SLorenzo Bianconi if (!hw->iio_devs[i]) 22676ffb55e5SLorenzo Bianconi continue; 22686ffb55e5SLorenzo Bianconi 2269290a6ce1SLorenzo Bianconi err = devm_iio_device_register(hw->dev, hw->iio_devs[i]); 2270290a6ce1SLorenzo Bianconi if (err) 2271290a6ce1SLorenzo Bianconi return err; 2272290a6ce1SLorenzo Bianconi } 2273290a6ce1SLorenzo Bianconi 227403d4c566SAndy Shevchenko if ((dev_fwnode(dev) && device_property_read_bool(dev, "wakeup-source")) || 2275b7a73b33SLorenzo Bianconi (pdata && pdata->wakeup_source)) 22764c997dfaSSean Nyekjaer device_init_wakeup(dev, true); 22774c997dfaSSean Nyekjaer 2278290a6ce1SLorenzo Bianconi return 0; 2279290a6ce1SLorenzo Bianconi } 2280290a6ce1SLorenzo Bianconi EXPORT_SYMBOL(st_lsm6dsx_probe); 2281290a6ce1SLorenzo Bianconi 22823cec4850SLorenzo Bianconi static int __maybe_unused st_lsm6dsx_suspend(struct device *dev) 2283d3f77058SLorenzo Bianconi { 2284d3f77058SLorenzo Bianconi struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev); 2285d3f77058SLorenzo Bianconi struct st_lsm6dsx_sensor *sensor; 2286d3f77058SLorenzo Bianconi int i, err = 0; 2287d3f77058SLorenzo Bianconi 2288d3f77058SLorenzo Bianconi for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 22896ffb55e5SLorenzo Bianconi if (!hw->iio_devs[i]) 22906ffb55e5SLorenzo Bianconi continue; 22916ffb55e5SLorenzo Bianconi 2292d3f77058SLorenzo Bianconi sensor = iio_priv(hw->iio_devs[i]); 2293d3f77058SLorenzo Bianconi if (!(hw->enable_mask & BIT(sensor->id))) 2294d3f77058SLorenzo Bianconi continue; 2295d3f77058SLorenzo Bianconi 22964c997dfaSSean Nyekjaer if (device_may_wakeup(dev) && 22974c997dfaSSean Nyekjaer sensor->id == ST_LSM6DSX_ID_ACC && hw->enable_event) { 22984c997dfaSSean Nyekjaer /* Enable wake from IRQ */ 22994c997dfaSSean Nyekjaer enable_irq_wake(hw->irq); 23004c997dfaSSean Nyekjaer continue; 23014c997dfaSSean Nyekjaer } 23024c997dfaSSean Nyekjaer 2303bce0d57dSLorenzo Bianconi if (sensor->id == ST_LSM6DSX_ID_EXT0 || 2304bce0d57dSLorenzo Bianconi sensor->id == ST_LSM6DSX_ID_EXT1 || 2305bce0d57dSLorenzo Bianconi sensor->id == ST_LSM6DSX_ID_EXT2) 2306bce0d57dSLorenzo Bianconi err = st_lsm6dsx_shub_set_enable(sensor, false); 2307bce0d57dSLorenzo Bianconi else 2308bce0d57dSLorenzo Bianconi err = st_lsm6dsx_sensor_set_enable(sensor, false); 2309d3f77058SLorenzo Bianconi if (err < 0) 2310d3f77058SLorenzo Bianconi return err; 2311bce0d57dSLorenzo Bianconi 2312bce0d57dSLorenzo Bianconi hw->suspend_mask |= BIT(sensor->id); 2313d3f77058SLorenzo Bianconi } 2314d3f77058SLorenzo Bianconi 2315c2686eb2SLorenzo Bianconi if (hw->fifo_mask) 2316d3f77058SLorenzo Bianconi err = st_lsm6dsx_flush_fifo(hw); 2317d3f77058SLorenzo Bianconi 2318d3f77058SLorenzo Bianconi return err; 2319d3f77058SLorenzo Bianconi } 2320d3f77058SLorenzo Bianconi 23213cec4850SLorenzo Bianconi static int __maybe_unused st_lsm6dsx_resume(struct device *dev) 2322d3f77058SLorenzo Bianconi { 2323d3f77058SLorenzo Bianconi struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev); 2324d3f77058SLorenzo Bianconi struct st_lsm6dsx_sensor *sensor; 2325d3f77058SLorenzo Bianconi int i, err = 0; 2326d3f77058SLorenzo Bianconi 2327d3f77058SLorenzo Bianconi for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 23286ffb55e5SLorenzo Bianconi if (!hw->iio_devs[i]) 23296ffb55e5SLorenzo Bianconi continue; 23306ffb55e5SLorenzo Bianconi 2331d3f77058SLorenzo Bianconi sensor = iio_priv(hw->iio_devs[i]); 23324c997dfaSSean Nyekjaer if (device_may_wakeup(dev) && 23334c997dfaSSean Nyekjaer sensor->id == ST_LSM6DSX_ID_ACC && hw->enable_event) 23344c997dfaSSean Nyekjaer disable_irq_wake(hw->irq); 23354c997dfaSSean Nyekjaer 2336bce0d57dSLorenzo Bianconi if (!(hw->suspend_mask & BIT(sensor->id))) 2337d3f77058SLorenzo Bianconi continue; 2338d3f77058SLorenzo Bianconi 2339bce0d57dSLorenzo Bianconi if (sensor->id == ST_LSM6DSX_ID_EXT0 || 2340bce0d57dSLorenzo Bianconi sensor->id == ST_LSM6DSX_ID_EXT1 || 2341bce0d57dSLorenzo Bianconi sensor->id == ST_LSM6DSX_ID_EXT2) 2342bce0d57dSLorenzo Bianconi err = st_lsm6dsx_shub_set_enable(sensor, true); 2343bce0d57dSLorenzo Bianconi else 2344bce0d57dSLorenzo Bianconi err = st_lsm6dsx_sensor_set_enable(sensor, true); 2345d3f77058SLorenzo Bianconi if (err < 0) 2346d3f77058SLorenzo Bianconi return err; 2347bce0d57dSLorenzo Bianconi 2348bce0d57dSLorenzo Bianconi hw->suspend_mask &= ~BIT(sensor->id); 2349d3f77058SLorenzo Bianconi } 2350d3f77058SLorenzo Bianconi 2351c2686eb2SLorenzo Bianconi if (hw->fifo_mask) 2352a1bab939SLorenzo Bianconi err = st_lsm6dsx_resume_fifo(hw); 2353d3f77058SLorenzo Bianconi 2354d3f77058SLorenzo Bianconi return err; 2355d3f77058SLorenzo Bianconi } 2356d3f77058SLorenzo Bianconi 2357d3f77058SLorenzo Bianconi const struct dev_pm_ops st_lsm6dsx_pm_ops = { 2358d3f77058SLorenzo Bianconi SET_SYSTEM_SLEEP_PM_OPS(st_lsm6dsx_suspend, st_lsm6dsx_resume) 2359d3f77058SLorenzo Bianconi }; 2360d3f77058SLorenzo Bianconi EXPORT_SYMBOL(st_lsm6dsx_pm_ops); 2361d3f77058SLorenzo Bianconi 2362290a6ce1SLorenzo Bianconi MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>"); 2363290a6ce1SLorenzo Bianconi MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 2364290a6ce1SLorenzo Bianconi MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx driver"); 2365290a6ce1SLorenzo Bianconi MODULE_LICENSE("GPL v2"); 2366