Lines Matching +full:sensor +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0-only
9 * - 1st data set is reserved for gyroscope data
10 * - 2nd data set is reserved for accelerometer data
18 * - ISM330DLC
19 * - LSM6DS3
20 * - LSM6DS3H
21 * - LSM6DS3TR-C
22 * - LSM6DSL
23 * - LSM6DSM
31 * - ASM330LHB
32 * - ASM330LHH
33 * - ASM330LHHX
34 * - ASM330LHHXG1
35 * - ISM330DHCX
36 * - LSM6DSO
37 * - LSM6DSOP
38 * - LSM6DSOX
39 * - LSM6DSR
40 * - LSM6DSRX
41 * - LSM6DST
42 * - LSM6DSTX
43 * - LSM6DSV
46 * - BYPASS: FIFO disabled
47 * - CONTINUOUS: FIFO enabled. When the buffer is full, the FIFO index
105 st_lsm6dsx_get_decimator_val(struct st_lsm6dsx_sensor *sensor, u32 max_odr) in st_lsm6dsx_get_decimator_val() argument
108 u32 decimator = max_odr / sensor->odr; in st_lsm6dsx_get_decimator_val()
119 sensor->decimator = decimator; in st_lsm6dsx_get_decimator_val()
126 struct st_lsm6dsx_sensor *sensor; in st_lsm6dsx_get_max_min_odr() local
131 if (!hw->iio_devs[i]) in st_lsm6dsx_get_max_min_odr()
134 sensor = iio_priv(hw->iio_devs[i]); in st_lsm6dsx_get_max_min_odr()
136 if (!(hw->enable_mask & BIT(sensor->id))) in st_lsm6dsx_get_max_min_odr()
139 *max_odr = max_t(u32, *max_odr, sensor->odr); in st_lsm6dsx_get_max_min_odr()
140 *min_odr = min_t(u32, *min_odr, sensor->odr); in st_lsm6dsx_get_max_min_odr()
144 static u8 st_lsm6dsx_get_sip(struct st_lsm6dsx_sensor *sensor, u32 min_odr) in st_lsm6dsx_get_sip() argument
146 u8 sip = sensor->odr / min_odr; in st_lsm6dsx_get_sip()
154 struct st_lsm6dsx_sensor *sensor; in st_lsm6dsx_update_decimators() local
165 if (!hw->iio_devs[i]) in st_lsm6dsx_update_decimators()
168 sensor = iio_priv(hw->iio_devs[i]); in st_lsm6dsx_update_decimators()
170 if (hw->enable_mask & BIT(sensor->id)) { in st_lsm6dsx_update_decimators()
171 sensor->sip = st_lsm6dsx_get_sip(sensor, min_odr); in st_lsm6dsx_update_decimators()
172 data = st_lsm6dsx_get_decimator_val(sensor, max_odr); in st_lsm6dsx_update_decimators()
174 sensor->sip = 0; in st_lsm6dsx_update_decimators()
177 ts_sip = max_t(u16, ts_sip, sensor->sip); in st_lsm6dsx_update_decimators()
179 dec_reg = &hw->settings->decimator[sensor->id]; in st_lsm6dsx_update_decimators()
180 if (dec_reg->addr) { in st_lsm6dsx_update_decimators()
181 int val = ST_LSM6DSX_SHIFT_VAL(data, dec_reg->mask); in st_lsm6dsx_update_decimators()
183 err = st_lsm6dsx_update_bits_locked(hw, dec_reg->addr, in st_lsm6dsx_update_decimators()
184 dec_reg->mask, in st_lsm6dsx_update_decimators()
189 sip += sensor->sip; in st_lsm6dsx_update_decimators()
191 hw->sip = sip + ts_sip; in st_lsm6dsx_update_decimators()
192 hw->ts_sip = ts_sip; in st_lsm6dsx_update_decimators()
199 ts_dec_reg = &hw->settings->ts_settings.decimator; in st_lsm6dsx_update_decimators()
200 if (ts_dec_reg->addr) { in st_lsm6dsx_update_decimators()
201 int val, ts_dec = !!hw->ts_sip; in st_lsm6dsx_update_decimators()
203 val = ST_LSM6DSX_SHIFT_VAL(ts_dec, ts_dec_reg->mask); in st_lsm6dsx_update_decimators()
204 err = st_lsm6dsx_update_bits_locked(hw, ts_dec_reg->addr, in st_lsm6dsx_update_decimators()
205 ts_dec_reg->mask, val); in st_lsm6dsx_update_decimators()
220 static int st_lsm6dsx_set_fifo_odr(struct st_lsm6dsx_sensor *sensor, in st_lsm6dsx_set_fifo_odr() argument
223 struct st_lsm6dsx_hw *hw = sensor->hw; in st_lsm6dsx_set_fifo_odr()
227 batch_reg = &hw->settings->batch[sensor->id]; in st_lsm6dsx_set_fifo_odr()
228 if (batch_reg->addr) { in st_lsm6dsx_set_fifo_odr()
234 err = st_lsm6dsx_check_odr(sensor, sensor->odr, in st_lsm6dsx_set_fifo_odr()
241 val = ST_LSM6DSX_SHIFT_VAL(data, batch_reg->mask); in st_lsm6dsx_set_fifo_odr()
242 return st_lsm6dsx_update_bits_locked(hw, batch_reg->addr, in st_lsm6dsx_set_fifo_odr()
243 batch_reg->mask, val); in st_lsm6dsx_set_fifo_odr()
245 data = hw->enable_mask ? ST_LSM6DSX_MAX_FIFO_ODR_VAL : 0; in st_lsm6dsx_set_fifo_odr()
254 int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark) in st_lsm6dsx_update_watermark() argument
257 struct st_lsm6dsx_hw *hw = sensor->hw; in st_lsm6dsx_update_watermark()
262 if (!hw->sip) in st_lsm6dsx_update_watermark()
266 if (!hw->iio_devs[i]) in st_lsm6dsx_update_watermark()
269 cur_sensor = iio_priv(hw->iio_devs[i]); in st_lsm6dsx_update_watermark()
271 if (!(hw->enable_mask & BIT(cur_sensor->id))) in st_lsm6dsx_update_watermark()
274 cur_watermark = (cur_sensor == sensor) ? watermark in st_lsm6dsx_update_watermark()
275 : cur_sensor->watermark; in st_lsm6dsx_update_watermark()
280 fifo_watermark = max_t(u16, fifo_watermark, hw->sip); in st_lsm6dsx_update_watermark()
281 fifo_watermark = (fifo_watermark / hw->sip) * hw->sip; in st_lsm6dsx_update_watermark()
282 fifo_watermark = fifo_watermark * hw->settings->fifo_ops.th_wl; in st_lsm6dsx_update_watermark()
284 mutex_lock(&hw->page_lock); in st_lsm6dsx_update_watermark()
285 err = regmap_read(hw->regmap, hw->settings->fifo_ops.fifo_th.addr + 1, in st_lsm6dsx_update_watermark()
290 fifo_th_mask = hw->settings->fifo_ops.fifo_th.mask; in st_lsm6dsx_update_watermark()
295 err = regmap_bulk_write(hw->regmap, in st_lsm6dsx_update_watermark()
296 hw->settings->fifo_ops.fifo_th.addr, in st_lsm6dsx_update_watermark()
299 mutex_unlock(&hw->page_lock); in st_lsm6dsx_update_watermark()
305 struct st_lsm6dsx_sensor *sensor; in st_lsm6dsx_reset_hw_ts() local
315 if (!hw->iio_devs[i]) in st_lsm6dsx_reset_hw_ts()
318 sensor = iio_priv(hw->iio_devs[i]); in st_lsm6dsx_reset_hw_ts()
323 sensor->ts_ref = iio_get_time_ns(hw->iio_devs[i]); in st_lsm6dsx_reset_hw_ts()
352 word_len = min_t(unsigned int, data_len - read_len, in st_lsm6dsx_read_block()
366 * st_lsm6dsx_read_fifo() - hw FIFO read routine
377 u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE; in st_lsm6dsx_read_fifo()
378 u16 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask; in st_lsm6dsx_read_fifo()
384 hw->settings->fifo_ops.fifo_diff.addr, in st_lsm6dsx_read_fifo()
387 dev_err(hw->dev, "failed to read fifo status (err=%d)\n", in st_lsm6dsx_read_fifo()
402 acc_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]); in st_lsm6dsx_read_fifo()
403 gyro_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_GYRO]); in st_lsm6dsx_read_fifo()
404 if (hw->iio_devs[ST_LSM6DSX_ID_EXT0]) in st_lsm6dsx_read_fifo()
405 ext_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_EXT0]); in st_lsm6dsx_read_fifo()
409 hw->buff, pattern_len, in st_lsm6dsx_read_fifo()
412 dev_err(hw->dev, in st_lsm6dsx_read_fifo()
424 * sensor. in st_lsm6dsx_read_fifo()
428 * - gyroscope ODR = 208Hz, accelerometer ODR = 104Hz in st_lsm6dsx_read_fifo()
431 * - Gx, Gy, Gz, Ax, Ay, Az, Ts, Gx, Gy, Gz, Ts, Gx, .. in st_lsm6dsx_read_fifo()
433 ext_sip = ext_sensor ? ext_sensor->sip : 0; in st_lsm6dsx_read_fifo()
434 gyro_sip = gyro_sensor->sip; in st_lsm6dsx_read_fifo()
435 acc_sip = acc_sensor->sip; in st_lsm6dsx_read_fifo()
436 ts_sip = hw->ts_sip; in st_lsm6dsx_read_fifo()
441 if (gyro_sip > 0 && !(sip % gyro_sensor->decimator)) { in st_lsm6dsx_read_fifo()
442 memcpy(hw->scan[ST_LSM6DSX_ID_GYRO].channels, in st_lsm6dsx_read_fifo()
443 &hw->buff[offset], in st_lsm6dsx_read_fifo()
444 sizeof(hw->scan[ST_LSM6DSX_ID_GYRO].channels)); in st_lsm6dsx_read_fifo()
445 offset += sizeof(hw->scan[ST_LSM6DSX_ID_GYRO].channels); in st_lsm6dsx_read_fifo()
447 if (acc_sip > 0 && !(sip % acc_sensor->decimator)) { in st_lsm6dsx_read_fifo()
448 memcpy(hw->scan[ST_LSM6DSX_ID_ACC].channels, in st_lsm6dsx_read_fifo()
449 &hw->buff[offset], in st_lsm6dsx_read_fifo()
450 sizeof(hw->scan[ST_LSM6DSX_ID_ACC].channels)); in st_lsm6dsx_read_fifo()
451 offset += sizeof(hw->scan[ST_LSM6DSX_ID_ACC].channels); in st_lsm6dsx_read_fifo()
453 if (ext_sip > 0 && !(sip % ext_sensor->decimator)) { in st_lsm6dsx_read_fifo()
454 memcpy(hw->scan[ST_LSM6DSX_ID_EXT0].channels, in st_lsm6dsx_read_fifo()
455 &hw->buff[offset], in st_lsm6dsx_read_fifo()
456 sizeof(hw->scan[ST_LSM6DSX_ID_EXT0].channels)); in st_lsm6dsx_read_fifo()
457 offset += sizeof(hw->scan[ST_LSM6DSX_ID_EXT0].channels); in st_lsm6dsx_read_fifo()
460 if (ts_sip-- > 0) { in st_lsm6dsx_read_fifo()
463 memcpy(data, &hw->buff[offset], sizeof(data)); in st_lsm6dsx_read_fifo()
473 * reset (the sensor generates an interrupt in st_lsm6dsx_read_fifo()
479 ts *= hw->ts_gain; in st_lsm6dsx_read_fifo()
484 if (gyro_sip > 0 && !(sip % gyro_sensor->decimator)) { in st_lsm6dsx_read_fifo()
489 if (gyro_sensor->samples_to_discard > 0) in st_lsm6dsx_read_fifo()
490 gyro_sensor->samples_to_discard--; in st_lsm6dsx_read_fifo()
493 hw->iio_devs[ST_LSM6DSX_ID_GYRO], in st_lsm6dsx_read_fifo()
494 &hw->scan[ST_LSM6DSX_ID_GYRO], in st_lsm6dsx_read_fifo()
495 gyro_sensor->ts_ref + ts); in st_lsm6dsx_read_fifo()
496 gyro_sip--; in st_lsm6dsx_read_fifo()
498 if (acc_sip > 0 && !(sip % acc_sensor->decimator)) { in st_lsm6dsx_read_fifo()
503 if (acc_sensor->samples_to_discard > 0) in st_lsm6dsx_read_fifo()
504 acc_sensor->samples_to_discard--; in st_lsm6dsx_read_fifo()
507 hw->iio_devs[ST_LSM6DSX_ID_ACC], in st_lsm6dsx_read_fifo()
508 &hw->scan[ST_LSM6DSX_ID_ACC], in st_lsm6dsx_read_fifo()
509 acc_sensor->ts_ref + ts); in st_lsm6dsx_read_fifo()
510 acc_sip--; in st_lsm6dsx_read_fifo()
512 if (ext_sip > 0 && !(sip % ext_sensor->decimator)) { in st_lsm6dsx_read_fifo()
514 hw->iio_devs[ST_LSM6DSX_ID_EXT0], in st_lsm6dsx_read_fifo()
515 &hw->scan[ST_LSM6DSX_ID_EXT0], in st_lsm6dsx_read_fifo()
516 ext_sensor->ts_ref + ts); in st_lsm6dsx_read_fifo()
517 ext_sip--; in st_lsm6dsx_read_fifo()
526 dev_err(hw->dev, "failed to reset hw ts (err=%d)\n", in st_lsm6dsx_read_fifo()
540 struct st_lsm6dsx_sensor *sensor; in st_lsm6dsx_push_tagged_data() local
545 return -EINVAL; in st_lsm6dsx_push_tagged_data()
555 iio_dev = hw->iio_devs[ST_LSM6DSX_ID_GYRO]; in st_lsm6dsx_push_tagged_data()
558 iio_dev = hw->iio_devs[ST_LSM6DSX_ID_ACC]; in st_lsm6dsx_push_tagged_data()
561 if (hw->enable_mask & BIT(ST_LSM6DSX_ID_EXT0)) in st_lsm6dsx_push_tagged_data()
562 iio_dev = hw->iio_devs[ST_LSM6DSX_ID_EXT0]; in st_lsm6dsx_push_tagged_data()
563 else if (hw->enable_mask & BIT(ST_LSM6DSX_ID_EXT1)) in st_lsm6dsx_push_tagged_data()
564 iio_dev = hw->iio_devs[ST_LSM6DSX_ID_EXT1]; in st_lsm6dsx_push_tagged_data()
566 iio_dev = hw->iio_devs[ST_LSM6DSX_ID_EXT2]; in st_lsm6dsx_push_tagged_data()
569 if ((hw->enable_mask & BIT(ST_LSM6DSX_ID_EXT0)) && in st_lsm6dsx_push_tagged_data()
570 (hw->enable_mask & BIT(ST_LSM6DSX_ID_EXT1))) in st_lsm6dsx_push_tagged_data()
571 iio_dev = hw->iio_devs[ST_LSM6DSX_ID_EXT1]; in st_lsm6dsx_push_tagged_data()
573 iio_dev = hw->iio_devs[ST_LSM6DSX_ID_EXT2]; in st_lsm6dsx_push_tagged_data()
576 iio_dev = hw->iio_devs[ST_LSM6DSX_ID_EXT2]; in st_lsm6dsx_push_tagged_data()
579 return -EINVAL; in st_lsm6dsx_push_tagged_data()
582 sensor = iio_priv(iio_dev); in st_lsm6dsx_push_tagged_data()
584 ts + sensor->ts_ref); in st_lsm6dsx_push_tagged_data()
590 * st_lsm6dsx_read_tagged_fifo() - tagged hw FIFO read routine
599 u16 pattern_len = hw->sip * ST_LSM6DSX_TAGGED_SAMPLE_SIZE; in st_lsm6dsx_read_tagged_fifo()
615 hw->settings->fifo_ops.fifo_diff.addr, in st_lsm6dsx_read_tagged_fifo()
618 dev_err(hw->dev, "failed to read fifo status (err=%d)\n", in st_lsm6dsx_read_tagged_fifo()
623 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask; in st_lsm6dsx_read_tagged_fifo()
635 hw->buff, pattern_len, in st_lsm6dsx_read_tagged_fifo()
638 dev_err(hw->dev, in st_lsm6dsx_read_tagged_fifo()
646 memcpy(iio_buff, &hw->buff[i + ST_LSM6DSX_TAG_SIZE], in st_lsm6dsx_read_tagged_fifo()
649 tag = hw->buff[i] >> 3; in st_lsm6dsx_read_tagged_fifo()
660 * reset (the sensor generates an interrupt in st_lsm6dsx_read_tagged_fifo()
666 ts *= hw->ts_gain; in st_lsm6dsx_read_tagged_fifo()
686 if (!hw->settings->fifo_ops.read_fifo) in st_lsm6dsx_flush_fifo()
687 return -ENOTSUPP; in st_lsm6dsx_flush_fifo()
689 mutex_lock(&hw->fifo_lock); in st_lsm6dsx_flush_fifo()
691 hw->settings->fifo_ops.read_fifo(hw); in st_lsm6dsx_flush_fifo()
694 mutex_unlock(&hw->fifo_lock); in st_lsm6dsx_flush_fifo()
700 st_lsm6dsx_update_samples_to_discard(struct st_lsm6dsx_sensor *sensor) in st_lsm6dsx_update_samples_to_discard() argument
703 struct st_lsm6dsx_hw *hw = sensor->hw; in st_lsm6dsx_update_samples_to_discard()
706 if (sensor->id != ST_LSM6DSX_ID_GYRO && in st_lsm6dsx_update_samples_to_discard()
707 sensor->id != ST_LSM6DSX_ID_ACC) in st_lsm6dsx_update_samples_to_discard()
711 if (hw->settings->drdy_mask.addr) in st_lsm6dsx_update_samples_to_discard()
714 data = &hw->settings->samples_to_discard[sensor->id]; in st_lsm6dsx_update_samples_to_discard()
716 if (data->val[i].milli_hz == sensor->odr) { in st_lsm6dsx_update_samples_to_discard()
717 sensor->samples_to_discard = data->val[i].samples; in st_lsm6dsx_update_samples_to_discard()
723 int st_lsm6dsx_update_fifo(struct st_lsm6dsx_sensor *sensor, bool enable) in st_lsm6dsx_update_fifo() argument
725 struct st_lsm6dsx_hw *hw = sensor->hw; in st_lsm6dsx_update_fifo()
729 mutex_lock(&hw->conf_lock); in st_lsm6dsx_update_fifo()
732 fifo_mask = hw->fifo_mask | BIT(sensor->id); in st_lsm6dsx_update_fifo()
734 fifo_mask = hw->fifo_mask & ~BIT(sensor->id); in st_lsm6dsx_update_fifo()
736 if (hw->fifo_mask) { in st_lsm6dsx_update_fifo()
743 st_lsm6dsx_update_samples_to_discard(sensor); in st_lsm6dsx_update_fifo()
745 err = st_lsm6dsx_device_set_enable(sensor, enable); in st_lsm6dsx_update_fifo()
749 err = st_lsm6dsx_set_fifo_odr(sensor, enable); in st_lsm6dsx_update_fifo()
757 err = st_lsm6dsx_update_watermark(sensor, sensor->watermark); in st_lsm6dsx_update_fifo()
767 hw->fifo_mask = fifo_mask; in st_lsm6dsx_update_fifo()
770 mutex_unlock(&hw->conf_lock); in st_lsm6dsx_update_fifo()
777 struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); in st_lsm6dsx_buffer_preenable() local
778 struct st_lsm6dsx_hw *hw = sensor->hw; in st_lsm6dsx_buffer_preenable()
780 if (!hw->settings->fifo_ops.update_fifo) in st_lsm6dsx_buffer_preenable()
781 return -ENOTSUPP; in st_lsm6dsx_buffer_preenable()
783 return hw->settings->fifo_ops.update_fifo(sensor, true); in st_lsm6dsx_buffer_preenable()
788 struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); in st_lsm6dsx_buffer_postdisable() local
789 struct st_lsm6dsx_hw *hw = sensor->hw; in st_lsm6dsx_buffer_postdisable()
791 if (!hw->settings->fifo_ops.update_fifo) in st_lsm6dsx_buffer_postdisable()
792 return -ENOTSUPP; in st_lsm6dsx_buffer_postdisable()
794 return hw->settings->fifo_ops.update_fifo(sensor, false); in st_lsm6dsx_buffer_postdisable()
807 if (!hw->iio_devs[i]) in st_lsm6dsx_fifo_setup()
810 ret = devm_iio_kfifo_buffer_setup(hw->dev, hw->iio_devs[i], in st_lsm6dsx_fifo_setup()