st_lsm6dsx_buffer.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /*
  2. * STMicroelectronics st_lsm6dsx FIFO buffer library driver
  3. *
  4. * LSM6DS3/LSM6DS3H/LSM6DSL/LSM6DSM/ISM330DLC: The FIFO buffer can be
  5. * configured to store data from gyroscope and accelerometer. Samples are
  6. * queued without any tag according to a specific pattern based on
  7. * 'FIFO data sets' (6 bytes each):
  8. * - 1st data set is reserved for gyroscope data
  9. * - 2nd data set is reserved for accelerometer data
  10. * The FIFO pattern changes depending on the ODRs and decimation factors
  11. * assigned to the FIFO data sets. The first sequence of data stored in FIFO
  12. * buffer contains the data of all the enabled FIFO data sets
  13. * (e.g. Gx, Gy, Gz, Ax, Ay, Az), then data are repeated depending on the
  14. * value of the decimation factor and ODR set for each FIFO data set.
  15. * FIFO supported modes:
  16. * - BYPASS: FIFO disabled
  17. * - CONTINUOUS: FIFO enabled. When the buffer is full, the FIFO index
  18. * restarts from the beginning and the oldest sample is overwritten
  19. *
  20. * Copyright 2016 STMicroelectronics Inc.
  21. *
  22. * Lorenzo Bianconi <lorenzo.bianconi@st.com>
  23. * Denis Ciocca <denis.ciocca@st.com>
  24. *
  25. * Licensed under the GPL-2.
  26. */
  27. #include <linux/module.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/irq.h>
  30. #include <linux/iio/kfifo_buf.h>
  31. #include <linux/iio/iio.h>
  32. #include <linux/iio/buffer.h>
  33. #include <linux/regmap.h>
  34. #include <linux/bitfield.h>
  35. #include <linux/platform_data/st_sensors_pdata.h>
  36. #include "st_lsm6dsx.h"
  37. #define ST_LSM6DSX_REG_HLACTIVE_ADDR 0x12
  38. #define ST_LSM6DSX_REG_HLACTIVE_MASK BIT(5)
  39. #define ST_LSM6DSX_REG_PP_OD_ADDR 0x12
  40. #define ST_LSM6DSX_REG_PP_OD_MASK BIT(4)
  41. #define ST_LSM6DSX_REG_FIFO_MODE_ADDR 0x0a
  42. #define ST_LSM6DSX_FIFO_MODE_MASK GENMASK(2, 0)
  43. #define ST_LSM6DSX_FIFO_ODR_MASK GENMASK(6, 3)
  44. #define ST_LSM6DSX_FIFO_EMPTY_MASK BIT(12)
  45. #define ST_LSM6DSX_REG_FIFO_OUTL_ADDR 0x3e
  46. #define ST_LSM6DSX_REG_TS_RESET_ADDR 0x42
  47. #define ST_LSM6DSX_MAX_FIFO_ODR_VAL 0x08
  48. #define ST_LSM6DSX_TS_SENSITIVITY 25000UL /* 25us */
  49. #define ST_LSM6DSX_TS_RESET_VAL 0xaa
  50. struct st_lsm6dsx_decimator_entry {
  51. u8 decimator;
  52. u8 val;
  53. };
  54. static const
  55. struct st_lsm6dsx_decimator_entry st_lsm6dsx_decimator_table[] = {
  56. { 0, 0x0 },
  57. { 1, 0x1 },
  58. { 2, 0x2 },
  59. { 3, 0x3 },
  60. { 4, 0x4 },
  61. { 8, 0x5 },
  62. { 16, 0x6 },
  63. { 32, 0x7 },
  64. };
  65. static int st_lsm6dsx_get_decimator_val(u8 val)
  66. {
  67. const int max_size = ARRAY_SIZE(st_lsm6dsx_decimator_table);
  68. int i;
  69. for (i = 0; i < max_size; i++)
  70. if (st_lsm6dsx_decimator_table[i].decimator == val)
  71. break;
  72. return i == max_size ? 0 : st_lsm6dsx_decimator_table[i].val;
  73. }
  74. static void st_lsm6dsx_get_max_min_odr(struct st_lsm6dsx_hw *hw,
  75. u16 *max_odr, u16 *min_odr)
  76. {
  77. struct st_lsm6dsx_sensor *sensor;
  78. int i;
  79. *max_odr = 0, *min_odr = ~0;
  80. for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
  81. sensor = iio_priv(hw->iio_devs[i]);
  82. if (!(hw->enable_mask & BIT(sensor->id)))
  83. continue;
  84. *max_odr = max_t(u16, *max_odr, sensor->odr);
  85. *min_odr = min_t(u16, *min_odr, sensor->odr);
  86. }
  87. }
  88. static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw)
  89. {
  90. u16 max_odr, min_odr, sip = 0, ts_sip = 0;
  91. const struct st_lsm6dsx_reg *ts_dec_reg;
  92. struct st_lsm6dsx_sensor *sensor;
  93. int err = 0, i;
  94. u8 data;
  95. st_lsm6dsx_get_max_min_odr(hw, &max_odr, &min_odr);
  96. for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
  97. const struct st_lsm6dsx_reg *dec_reg;
  98. sensor = iio_priv(hw->iio_devs[i]);
  99. /* update fifo decimators and sample in pattern */
  100. if (hw->enable_mask & BIT(sensor->id)) {
  101. sensor->sip = sensor->odr / min_odr;
  102. sensor->decimator = max_odr / sensor->odr;
  103. data = st_lsm6dsx_get_decimator_val(sensor->decimator);
  104. } else {
  105. sensor->sip = 0;
  106. sensor->decimator = 0;
  107. data = 0;
  108. }
  109. ts_sip = max_t(u16, ts_sip, sensor->sip);
  110. dec_reg = &hw->settings->decimator[sensor->id];
  111. if (dec_reg->addr) {
  112. int val = ST_LSM6DSX_SHIFT_VAL(data, dec_reg->mask);
  113. err = regmap_update_bits(hw->regmap, dec_reg->addr,
  114. dec_reg->mask, val);
  115. if (err < 0)
  116. return err;
  117. }
  118. sip += sensor->sip;
  119. }
  120. hw->sip = sip + ts_sip;
  121. hw->ts_sip = ts_sip;
  122. /*
  123. * update hw ts decimator if necessary. Decimator for hw timestamp
  124. * is always 1 or 0 in order to have a ts sample for each data
  125. * sample in FIFO
  126. */
  127. ts_dec_reg = &hw->settings->ts_settings.decimator;
  128. if (ts_dec_reg->addr) {
  129. int val, ts_dec = !!hw->ts_sip;
  130. val = ST_LSM6DSX_SHIFT_VAL(ts_dec, ts_dec_reg->mask);
  131. err = regmap_update_bits(hw->regmap, ts_dec_reg->addr,
  132. ts_dec_reg->mask, val);
  133. }
  134. return err;
  135. }
  136. int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
  137. enum st_lsm6dsx_fifo_mode fifo_mode)
  138. {
  139. int err;
  140. err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_FIFO_MODE_ADDR,
  141. ST_LSM6DSX_FIFO_MODE_MASK,
  142. FIELD_PREP(ST_LSM6DSX_FIFO_MODE_MASK,
  143. fifo_mode));
  144. if (err < 0)
  145. return err;
  146. hw->fifo_mode = fifo_mode;
  147. return 0;
  148. }
  149. static int st_lsm6dsx_set_fifo_odr(struct st_lsm6dsx_sensor *sensor,
  150. bool enable)
  151. {
  152. struct st_lsm6dsx_hw *hw = sensor->hw;
  153. u8 data;
  154. data = hw->enable_mask ? ST_LSM6DSX_MAX_FIFO_ODR_VAL : 0;
  155. return regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_FIFO_MODE_ADDR,
  156. ST_LSM6DSX_FIFO_ODR_MASK,
  157. FIELD_PREP(ST_LSM6DSX_FIFO_ODR_MASK, data));
  158. }
  159. int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
  160. {
  161. u16 fifo_watermark = ~0, cur_watermark, fifo_th_mask;
  162. struct st_lsm6dsx_hw *hw = sensor->hw;
  163. struct st_lsm6dsx_sensor *cur_sensor;
  164. int i, err, data;
  165. __le16 wdata;
  166. if (!hw->sip)
  167. return 0;
  168. for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
  169. cur_sensor = iio_priv(hw->iio_devs[i]);
  170. if (!(hw->enable_mask & BIT(cur_sensor->id)))
  171. continue;
  172. cur_watermark = (cur_sensor == sensor) ? watermark
  173. : cur_sensor->watermark;
  174. fifo_watermark = min_t(u16, fifo_watermark, cur_watermark);
  175. }
  176. fifo_watermark = max_t(u16, fifo_watermark, hw->sip);
  177. fifo_watermark = (fifo_watermark / hw->sip) * hw->sip;
  178. fifo_watermark = fifo_watermark * hw->settings->fifo_ops.th_wl;
  179. err = regmap_read(hw->regmap, hw->settings->fifo_ops.fifo_th.addr + 1,
  180. &data);
  181. if (err < 0)
  182. return err;
  183. fifo_th_mask = hw->settings->fifo_ops.fifo_th.mask;
  184. fifo_watermark = ((data << 8) & ~fifo_th_mask) |
  185. (fifo_watermark & fifo_th_mask);
  186. wdata = cpu_to_le16(fifo_watermark);
  187. return regmap_bulk_write(hw->regmap,
  188. hw->settings->fifo_ops.fifo_th.addr,
  189. &wdata, sizeof(wdata));
  190. }
  191. static int st_lsm6dsx_reset_hw_ts(struct st_lsm6dsx_hw *hw)
  192. {
  193. struct st_lsm6dsx_sensor *sensor;
  194. int i, err;
  195. /* reset hw ts counter */
  196. err = regmap_write(hw->regmap, ST_LSM6DSX_REG_TS_RESET_ADDR,
  197. ST_LSM6DSX_TS_RESET_VAL);
  198. if (err < 0)
  199. return err;
  200. for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
  201. sensor = iio_priv(hw->iio_devs[i]);
  202. /*
  203. * store enable buffer timestamp as reference for
  204. * hw timestamp
  205. */
  206. sensor->ts_ref = iio_get_time_ns(hw->iio_devs[i]);
  207. }
  208. return 0;
  209. }
  210. /*
  211. * Set max bulk read to ST_LSM6DSX_MAX_WORD_LEN in order to avoid
  212. * a kmalloc for each bus access
  213. */
  214. static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 *data,
  215. unsigned int data_len)
  216. {
  217. unsigned int word_len, read_len = 0;
  218. int err;
  219. while (read_len < data_len) {
  220. word_len = min_t(unsigned int, data_len - read_len,
  221. ST_LSM6DSX_MAX_WORD_LEN);
  222. err = regmap_bulk_read(hw->regmap,
  223. ST_LSM6DSX_REG_FIFO_OUTL_ADDR,
  224. data + read_len, word_len);
  225. if (err < 0)
  226. return err;
  227. read_len += word_len;
  228. }
  229. return 0;
  230. }
  231. #define ST_LSM6DSX_IIO_BUFF_SIZE (ALIGN(ST_LSM6DSX_SAMPLE_SIZE, \
  232. sizeof(s64)) + sizeof(s64))
  233. /**
  234. * st_lsm6dsx_read_fifo() - hw FIFO read routine
  235. * @hw: Pointer to instance of struct st_lsm6dsx_hw.
  236. *
  237. * Read samples from the hw FIFO and push them to IIO buffers.
  238. *
  239. * Return: Number of bytes read from the FIFO
  240. */
  241. static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
  242. {
  243. u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE;
  244. u16 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask;
  245. int err, acc_sip, gyro_sip, ts_sip, read_len, offset;
  246. struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor;
  247. u8 gyro_buff[ST_LSM6DSX_IIO_BUFF_SIZE];
  248. u8 acc_buff[ST_LSM6DSX_IIO_BUFF_SIZE];
  249. bool reset_ts = false;
  250. __le16 fifo_status;
  251. s64 ts = 0;
  252. err = regmap_bulk_read(hw->regmap,
  253. hw->settings->fifo_ops.fifo_diff.addr,
  254. &fifo_status, sizeof(fifo_status));
  255. if (err < 0) {
  256. dev_err(hw->dev, "failed to read fifo status (err=%d)\n",
  257. err);
  258. return err;
  259. }
  260. if (fifo_status & cpu_to_le16(ST_LSM6DSX_FIFO_EMPTY_MASK))
  261. return 0;
  262. fifo_len = (le16_to_cpu(fifo_status) & fifo_diff_mask) *
  263. ST_LSM6DSX_CHAN_SIZE;
  264. fifo_len = (fifo_len / pattern_len) * pattern_len;
  265. acc_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
  266. gyro_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_GYRO]);
  267. for (read_len = 0; read_len < fifo_len; read_len += pattern_len) {
  268. err = st_lsm6dsx_read_block(hw, hw->buff, pattern_len);
  269. if (err < 0) {
  270. dev_err(hw->dev,
  271. "failed to read pattern from fifo (err=%d)\n",
  272. err);
  273. return err;
  274. }
  275. /*
  276. * Data are written to the FIFO with a specific pattern
  277. * depending on the configured ODRs. The first sequence of data
  278. * stored in FIFO contains the data of all enabled sensors
  279. * (e.g. Gx, Gy, Gz, Ax, Ay, Az, Ts), then data are repeated
  280. * depending on the value of the decimation factor set for each
  281. * sensor.
  282. *
  283. * Supposing the FIFO is storing data from gyroscope and
  284. * accelerometer at different ODRs:
  285. * - gyroscope ODR = 208Hz, accelerometer ODR = 104Hz
  286. * Since the gyroscope ODR is twice the accelerometer one, the
  287. * following pattern is repeated every 9 samples:
  288. * - Gx, Gy, Gz, Ax, Ay, Az, Ts, Gx, Gy, Gz, Ts, Gx, ..
  289. */
  290. gyro_sip = gyro_sensor->sip;
  291. acc_sip = acc_sensor->sip;
  292. ts_sip = hw->ts_sip;
  293. offset = 0;
  294. while (acc_sip > 0 || gyro_sip > 0) {
  295. if (gyro_sip > 0) {
  296. memcpy(gyro_buff, &hw->buff[offset],
  297. ST_LSM6DSX_SAMPLE_SIZE);
  298. offset += ST_LSM6DSX_SAMPLE_SIZE;
  299. }
  300. if (acc_sip > 0) {
  301. memcpy(acc_buff, &hw->buff[offset],
  302. ST_LSM6DSX_SAMPLE_SIZE);
  303. offset += ST_LSM6DSX_SAMPLE_SIZE;
  304. }
  305. if (ts_sip-- > 0) {
  306. u8 data[ST_LSM6DSX_SAMPLE_SIZE];
  307. memcpy(data, &hw->buff[offset], sizeof(data));
  308. /*
  309. * hw timestamp is 3B long and it is stored
  310. * in FIFO using 6B as 4th FIFO data set
  311. * according to this schema:
  312. * B0 = ts[15:8], B1 = ts[23:16], B3 = ts[7:0]
  313. */
  314. ts = data[1] << 16 | data[0] << 8 | data[3];
  315. /*
  316. * check if hw timestamp engine is going to
  317. * reset (the sensor generates an interrupt
  318. * to signal the hw timestamp will reset in
  319. * 1.638s)
  320. */
  321. if (!reset_ts && ts >= 0xff0000)
  322. reset_ts = true;
  323. ts *= ST_LSM6DSX_TS_SENSITIVITY;
  324. offset += ST_LSM6DSX_SAMPLE_SIZE;
  325. }
  326. if (gyro_sip-- > 0)
  327. iio_push_to_buffers_with_timestamp(
  328. hw->iio_devs[ST_LSM6DSX_ID_GYRO],
  329. gyro_buff, gyro_sensor->ts_ref + ts);
  330. if (acc_sip-- > 0)
  331. iio_push_to_buffers_with_timestamp(
  332. hw->iio_devs[ST_LSM6DSX_ID_ACC],
  333. acc_buff, acc_sensor->ts_ref + ts);
  334. }
  335. }
  336. if (unlikely(reset_ts)) {
  337. err = st_lsm6dsx_reset_hw_ts(hw);
  338. if (err < 0) {
  339. dev_err(hw->dev, "failed to reset hw ts (err=%d)\n",
  340. err);
  341. return err;
  342. }
  343. }
  344. return read_len;
  345. }
  346. int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw)
  347. {
  348. int err;
  349. mutex_lock(&hw->fifo_lock);
  350. st_lsm6dsx_read_fifo(hw);
  351. err = st_lsm6dsx_set_fifo_mode(hw, ST_LSM6DSX_FIFO_BYPASS);
  352. mutex_unlock(&hw->fifo_lock);
  353. return err;
  354. }
  355. static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable)
  356. {
  357. struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
  358. struct st_lsm6dsx_hw *hw = sensor->hw;
  359. int err;
  360. mutex_lock(&hw->conf_lock);
  361. if (hw->fifo_mode != ST_LSM6DSX_FIFO_BYPASS) {
  362. err = st_lsm6dsx_flush_fifo(hw);
  363. if (err < 0)
  364. goto out;
  365. }
  366. if (enable) {
  367. err = st_lsm6dsx_sensor_enable(sensor);
  368. if (err < 0)
  369. goto out;
  370. } else {
  371. err = st_lsm6dsx_sensor_disable(sensor);
  372. if (err < 0)
  373. goto out;
  374. }
  375. err = st_lsm6dsx_set_fifo_odr(sensor, enable);
  376. if (err < 0)
  377. goto out;
  378. err = st_lsm6dsx_update_decimators(hw);
  379. if (err < 0)
  380. goto out;
  381. err = st_lsm6dsx_update_watermark(sensor, sensor->watermark);
  382. if (err < 0)
  383. goto out;
  384. if (hw->enable_mask) {
  385. /* reset hw ts counter */
  386. err = st_lsm6dsx_reset_hw_ts(hw);
  387. if (err < 0)
  388. goto out;
  389. err = st_lsm6dsx_set_fifo_mode(hw, ST_LSM6DSX_FIFO_CONT);
  390. }
  391. out:
  392. mutex_unlock(&hw->conf_lock);
  393. return err;
  394. }
  395. static irqreturn_t st_lsm6dsx_handler_irq(int irq, void *private)
  396. {
  397. struct st_lsm6dsx_hw *hw = private;
  398. return hw->sip > 0 ? IRQ_WAKE_THREAD : IRQ_NONE;
  399. }
  400. static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
  401. {
  402. struct st_lsm6dsx_hw *hw = private;
  403. int count;
  404. mutex_lock(&hw->fifo_lock);
  405. count = st_lsm6dsx_read_fifo(hw);
  406. mutex_unlock(&hw->fifo_lock);
  407. return !count ? IRQ_NONE : IRQ_HANDLED;
  408. }
  409. static int st_lsm6dsx_buffer_preenable(struct iio_dev *iio_dev)
  410. {
  411. return st_lsm6dsx_update_fifo(iio_dev, true);
  412. }
  413. static int st_lsm6dsx_buffer_postdisable(struct iio_dev *iio_dev)
  414. {
  415. return st_lsm6dsx_update_fifo(iio_dev, false);
  416. }
  417. static const struct iio_buffer_setup_ops st_lsm6dsx_buffer_ops = {
  418. .preenable = st_lsm6dsx_buffer_preenable,
  419. .postdisable = st_lsm6dsx_buffer_postdisable,
  420. };
  421. int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw)
  422. {
  423. struct device_node *np = hw->dev->of_node;
  424. struct st_sensors_platform_data *pdata;
  425. struct iio_buffer *buffer;
  426. unsigned long irq_type;
  427. bool irq_active_low;
  428. int i, err;
  429. irq_type = irqd_get_trigger_type(irq_get_irq_data(hw->irq));
  430. switch (irq_type) {
  431. case IRQF_TRIGGER_HIGH:
  432. case IRQF_TRIGGER_RISING:
  433. irq_active_low = false;
  434. break;
  435. case IRQF_TRIGGER_LOW:
  436. case IRQF_TRIGGER_FALLING:
  437. irq_active_low = true;
  438. break;
  439. default:
  440. dev_info(hw->dev, "mode %lx unsupported\n", irq_type);
  441. return -EINVAL;
  442. }
  443. err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_HLACTIVE_ADDR,
  444. ST_LSM6DSX_REG_HLACTIVE_MASK,
  445. FIELD_PREP(ST_LSM6DSX_REG_HLACTIVE_MASK,
  446. irq_active_low));
  447. if (err < 0)
  448. return err;
  449. pdata = (struct st_sensors_platform_data *)hw->dev->platform_data;
  450. if ((np && of_property_read_bool(np, "drive-open-drain")) ||
  451. (pdata && pdata->open_drain)) {
  452. err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_PP_OD_ADDR,
  453. ST_LSM6DSX_REG_PP_OD_MASK,
  454. FIELD_PREP(ST_LSM6DSX_REG_PP_OD_MASK,
  455. 1));
  456. if (err < 0)
  457. return err;
  458. irq_type |= IRQF_SHARED;
  459. }
  460. err = devm_request_threaded_irq(hw->dev, hw->irq,
  461. st_lsm6dsx_handler_irq,
  462. st_lsm6dsx_handler_thread,
  463. irq_type | IRQF_ONESHOT,
  464. "lsm6dsx", hw);
  465. if (err) {
  466. dev_err(hw->dev, "failed to request trigger irq %d\n",
  467. hw->irq);
  468. return err;
  469. }
  470. for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
  471. buffer = devm_iio_kfifo_allocate(hw->dev);
  472. if (!buffer)
  473. return -ENOMEM;
  474. iio_device_attach_buffer(hw->iio_devs[i], buffer);
  475. hw->iio_devs[i]->modes |= INDIO_BUFFER_SOFTWARE;
  476. hw->iio_devs[i]->setup_ops = &st_lsm6dsx_buffer_ops;
  477. }
  478. return 0;
  479. }