Lines Matching refs:st
101 void inv_icm42600_buffer_update_fifo_period(struct inv_icm42600_state *st) in inv_icm42600_buffer_update_fifo_period() argument
105 if (st->fifo.en & INV_ICM42600_SENSOR_GYRO) in inv_icm42600_buffer_update_fifo_period()
106 period_gyro = inv_icm42600_odr_to_period(st->conf.gyro.odr); in inv_icm42600_buffer_update_fifo_period()
110 if (st->fifo.en & INV_ICM42600_SENSOR_ACCEL) in inv_icm42600_buffer_update_fifo_period()
111 period_accel = inv_icm42600_odr_to_period(st->conf.accel.odr); in inv_icm42600_buffer_update_fifo_period()
120 st->fifo.period = period; in inv_icm42600_buffer_update_fifo_period()
123 int inv_icm42600_buffer_set_fifo_en(struct inv_icm42600_state *st, in inv_icm42600_buffer_set_fifo_en() argument
143 ret = regmap_update_bits(st->map, INV_ICM42600_REG_FIFO_CONFIG1, mask, val); in inv_icm42600_buffer_set_fifo_en()
147 st->fifo.en = fifo_en; in inv_icm42600_buffer_set_fifo_en()
148 inv_icm42600_buffer_update_fifo_period(st); in inv_icm42600_buffer_set_fifo_en()
203 int inv_icm42600_buffer_update_watermark(struct inv_icm42600_state *st) in inv_icm42600_buffer_update_watermark() argument
213 packet_size = inv_icm42600_get_packet_size(st->fifo.en); in inv_icm42600_buffer_update_watermark()
216 wm_gyro = inv_icm42600_wm_truncate(st->fifo.watermark.gyro, packet_size); in inv_icm42600_buffer_update_watermark()
217 wm_accel = inv_icm42600_wm_truncate(st->fifo.watermark.accel, packet_size); in inv_icm42600_buffer_update_watermark()
219 period_gyro = inv_icm42600_odr_to_period(st->conf.gyro.odr) / 1000UL; in inv_icm42600_buffer_update_watermark()
220 period_accel = inv_icm42600_odr_to_period(st->conf.accel.odr) / 1000UL; in inv_icm42600_buffer_update_watermark()
250 ret = regmap_update_bits_check(st->map, INV_ICM42600_REG_INT_SOURCE0, in inv_icm42600_buffer_update_watermark()
257 memcpy(st->buffer, &raw_wm, sizeof(raw_wm)); in inv_icm42600_buffer_update_watermark()
258 ret = regmap_bulk_write(st->map, INV_ICM42600_REG_FIFO_WATERMARK, in inv_icm42600_buffer_update_watermark()
259 st->buffer, sizeof(raw_wm)); in inv_icm42600_buffer_update_watermark()
265 ret = regmap_update_bits(st->map, INV_ICM42600_REG_INT_SOURCE0, in inv_icm42600_buffer_update_watermark()
277 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); in inv_icm42600_buffer_preenable() local
278 struct device *dev = regmap_get_device(st->map); in inv_icm42600_buffer_preenable()
283 mutex_lock(&st->lock); in inv_icm42600_buffer_preenable()
285 mutex_unlock(&st->lock); in inv_icm42600_buffer_preenable()
296 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); in inv_icm42600_buffer_postenable() local
299 mutex_lock(&st->lock); in inv_icm42600_buffer_postenable()
302 if (st->fifo.on) { in inv_icm42600_buffer_postenable()
308 ret = regmap_update_bits(st->map, INV_ICM42600_REG_INT_SOURCE0, in inv_icm42600_buffer_postenable()
315 ret = regmap_write(st->map, INV_ICM42600_REG_SIGNAL_PATH_RESET, in inv_icm42600_buffer_postenable()
321 ret = regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG, in inv_icm42600_buffer_postenable()
327 ret = regmap_bulk_read(st->map, INV_ICM42600_REG_FIFO_COUNT, st->buffer, 2); in inv_icm42600_buffer_postenable()
333 st->fifo.on++; in inv_icm42600_buffer_postenable()
335 mutex_unlock(&st->lock); in inv_icm42600_buffer_postenable()
341 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); in inv_icm42600_buffer_predisable() local
344 mutex_lock(&st->lock); in inv_icm42600_buffer_predisable()
347 if (st->fifo.on > 1) { in inv_icm42600_buffer_predisable()
353 ret = regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG, in inv_icm42600_buffer_predisable()
359 ret = regmap_write(st->map, INV_ICM42600_REG_SIGNAL_PATH_RESET, in inv_icm42600_buffer_predisable()
365 ret = regmap_update_bits(st->map, INV_ICM42600_REG_INT_SOURCE0, in inv_icm42600_buffer_predisable()
372 st->fifo.on--; in inv_icm42600_buffer_predisable()
374 mutex_unlock(&st->lock); in inv_icm42600_buffer_predisable()
380 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); in inv_icm42600_buffer_postdisable() local
381 struct device *dev = regmap_get_device(st->map); in inv_icm42600_buffer_postdisable()
390 if (indio_dev == st->indio_gyro) { in inv_icm42600_buffer_postdisable()
392 watermark = &st->fifo.watermark.gyro; in inv_icm42600_buffer_postdisable()
393 } else if (indio_dev == st->indio_accel) { in inv_icm42600_buffer_postdisable()
395 watermark = &st->fifo.watermark.accel; in inv_icm42600_buffer_postdisable()
400 mutex_lock(&st->lock); in inv_icm42600_buffer_postdisable()
402 ret = inv_icm42600_buffer_set_fifo_en(st, st->fifo.en & ~sensor); in inv_icm42600_buffer_postdisable()
407 ret = inv_icm42600_buffer_update_watermark(st); in inv_icm42600_buffer_postdisable()
413 ret = inv_icm42600_set_gyro_conf(st, &conf, &sleep_sensor); in inv_icm42600_buffer_postdisable()
415 ret = inv_icm42600_set_accel_conf(st, &conf, &sleep_sensor); in inv_icm42600_buffer_postdisable()
420 if (!st->fifo.on) in inv_icm42600_buffer_postdisable()
421 ret = inv_icm42600_set_temp_conf(st, false, &sleep_temp); in inv_icm42600_buffer_postdisable()
424 mutex_unlock(&st->lock); in inv_icm42600_buffer_postdisable()
447 int inv_icm42600_buffer_fifo_read(struct inv_icm42600_state *st, in inv_icm42600_buffer_fifo_read() argument
459 st->fifo.count = 0; in inv_icm42600_buffer_fifo_read()
460 st->fifo.nb.gyro = 0; in inv_icm42600_buffer_fifo_read()
461 st->fifo.nb.accel = 0; in inv_icm42600_buffer_fifo_read()
462 st->fifo.nb.total = 0; in inv_icm42600_buffer_fifo_read()
466 max_count = sizeof(st->fifo.data); in inv_icm42600_buffer_fifo_read()
468 max_count = max * inv_icm42600_get_packet_size(st->fifo.en); in inv_icm42600_buffer_fifo_read()
471 raw_fifo_count = (__be16 *)st->buffer; in inv_icm42600_buffer_fifo_read()
472 ret = regmap_bulk_read(st->map, INV_ICM42600_REG_FIFO_COUNT, in inv_icm42600_buffer_fifo_read()
476 st->fifo.count = be16_to_cpup(raw_fifo_count); in inv_icm42600_buffer_fifo_read()
479 if (st->fifo.count == 0) in inv_icm42600_buffer_fifo_read()
481 if (st->fifo.count > max_count) in inv_icm42600_buffer_fifo_read()
482 st->fifo.count = max_count; in inv_icm42600_buffer_fifo_read()
485 ret = regmap_noinc_read(st->map, INV_ICM42600_REG_FIFO_DATA, in inv_icm42600_buffer_fifo_read()
486 st->fifo.data, st->fifo.count); in inv_icm42600_buffer_fifo_read()
491 for (i = 0; i < st->fifo.count; i += size) { in inv_icm42600_buffer_fifo_read()
492 size = inv_icm42600_fifo_decode_packet(&st->fifo.data[i], in inv_icm42600_buffer_fifo_read()
497 st->fifo.nb.gyro++; in inv_icm42600_buffer_fifo_read()
499 st->fifo.nb.accel++; in inv_icm42600_buffer_fifo_read()
500 st->fifo.nb.total++; in inv_icm42600_buffer_fifo_read()
506 int inv_icm42600_buffer_fifo_parse(struct inv_icm42600_state *st) in inv_icm42600_buffer_fifo_parse() argument
511 if (st->fifo.nb.total == 0) in inv_icm42600_buffer_fifo_parse()
515 ts = iio_priv(st->indio_gyro); in inv_icm42600_buffer_fifo_parse()
516 inv_sensors_timestamp_interrupt(ts, st->fifo.period, st->fifo.nb.total, in inv_icm42600_buffer_fifo_parse()
517 st->fifo.nb.gyro, st->timestamp.gyro); in inv_icm42600_buffer_fifo_parse()
518 if (st->fifo.nb.gyro > 0) { in inv_icm42600_buffer_fifo_parse()
519 ret = inv_icm42600_gyro_parse_fifo(st->indio_gyro); in inv_icm42600_buffer_fifo_parse()
525 ts = iio_priv(st->indio_accel); in inv_icm42600_buffer_fifo_parse()
526 inv_sensors_timestamp_interrupt(ts, st->fifo.period, st->fifo.nb.total, in inv_icm42600_buffer_fifo_parse()
527 st->fifo.nb.accel, st->timestamp.accel); in inv_icm42600_buffer_fifo_parse()
528 if (st->fifo.nb.accel > 0) { in inv_icm42600_buffer_fifo_parse()
529 ret = inv_icm42600_accel_parse_fifo(st->indio_accel); in inv_icm42600_buffer_fifo_parse()
537 int inv_icm42600_buffer_hwfifo_flush(struct inv_icm42600_state *st, in inv_icm42600_buffer_hwfifo_flush() argument
544 gyro_ts = iio_get_time_ns(st->indio_gyro); in inv_icm42600_buffer_hwfifo_flush()
545 accel_ts = iio_get_time_ns(st->indio_accel); in inv_icm42600_buffer_hwfifo_flush()
547 ret = inv_icm42600_buffer_fifo_read(st, count); in inv_icm42600_buffer_hwfifo_flush()
551 if (st->fifo.nb.total == 0) in inv_icm42600_buffer_hwfifo_flush()
554 if (st->fifo.nb.gyro > 0) { in inv_icm42600_buffer_hwfifo_flush()
555 ts = iio_priv(st->indio_gyro); in inv_icm42600_buffer_hwfifo_flush()
556 inv_sensors_timestamp_interrupt(ts, st->fifo.period, in inv_icm42600_buffer_hwfifo_flush()
557 st->fifo.nb.total, st->fifo.nb.gyro, in inv_icm42600_buffer_hwfifo_flush()
559 ret = inv_icm42600_gyro_parse_fifo(st->indio_gyro); in inv_icm42600_buffer_hwfifo_flush()
564 if (st->fifo.nb.accel > 0) { in inv_icm42600_buffer_hwfifo_flush()
565 ts = iio_priv(st->indio_accel); in inv_icm42600_buffer_hwfifo_flush()
566 inv_sensors_timestamp_interrupt(ts, st->fifo.period, in inv_icm42600_buffer_hwfifo_flush()
567 st->fifo.nb.total, st->fifo.nb.accel, in inv_icm42600_buffer_hwfifo_flush()
569 ret = inv_icm42600_accel_parse_fifo(st->indio_accel); in inv_icm42600_buffer_hwfifo_flush()
577 int inv_icm42600_buffer_init(struct inv_icm42600_state *st) in inv_icm42600_buffer_init() argument
589 ret = regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG0, in inv_icm42600_buffer_init()
600 return regmap_update_bits(st->map, INV_ICM42600_REG_FIFO_CONFIG1, in inv_icm42600_buffer_init()