Lines Matching +full:per +full:- +full:mille

1 // SPDX-License-Identifier: GPL-2.0-or-later
59 "low-noise",
60 "low-power",
79 if (chan->type != IIO_ACCEL) in inv_icm42600_accel_power_mode_set()
80 return -EINVAL; in inv_icm42600_accel_power_mode_set()
83 return -EINVAL; in inv_icm42600_accel_power_mode_set()
86 return -EBUSY; in inv_icm42600_accel_power_mode_set()
91 guard(mutex)(&st->lock); in inv_icm42600_accel_power_mode_set()
96 if (st->conf.accel.odr >= INV_ICM42600_ODR_6_25HZ_LP && in inv_icm42600_accel_power_mode_set()
97 st->conf.accel.odr <= INV_ICM42600_ODR_1_5625HZ_LP) in inv_icm42600_accel_power_mode_set()
98 return -EPERM; in inv_icm42600_accel_power_mode_set()
102 if (st->conf.accel.odr <= INV_ICM42600_ODR_1KHZ_LN) in inv_icm42600_accel_power_mode_set()
103 return -EPERM; in inv_icm42600_accel_power_mode_set()
107 accel_st->power_mode = power_mode; in inv_icm42600_accel_power_mode_set()
108 accel_st->filter = filter; in inv_icm42600_accel_power_mode_set()
121 if (chan->type != IIO_ACCEL) in inv_icm42600_accel_power_mode_get()
122 return -EINVAL; in inv_icm42600_accel_power_mode_get()
124 guard(mutex)(&st->lock); in inv_icm42600_accel_power_mode_get()
127 switch (st->conf.accel.mode) { in inv_icm42600_accel_power_mode_get()
130 power_mode = st->conf.accel.mode; in inv_icm42600_accel_power_mode_get()
133 power_mode = accel_st->power_mode; in inv_icm42600_accel_power_mode_get()
142 return -EINVAL; in inv_icm42600_accel_power_mode_get()
192 /* 3-axis accel + temperature */
203 struct inv_sensors_timestamp *ts = &accel_st->ts; in inv_icm42600_accel_update_scan_mode()
211 mutex_lock(&st->lock); in inv_icm42600_accel_update_scan_mode()
223 conf.mode = accel_st->power_mode; in inv_icm42600_accel_update_scan_mode()
224 conf.filter = accel_st->filter; in inv_icm42600_accel_update_scan_mode()
233 ret = inv_icm42600_buffer_set_fifo_en(st, fifo_en | st->fifo.en); in inv_icm42600_accel_update_scan_mode()
236 mutex_unlock(&st->lock); in inv_icm42600_accel_update_scan_mode()
250 struct device *dev = regmap_get_device(st->map); in inv_icm42600_accel_read_sensor()
256 if (chan->type != IIO_ACCEL) in inv_icm42600_accel_read_sensor()
257 return -EINVAL; in inv_icm42600_accel_read_sensor()
259 switch (chan->channel2) { in inv_icm42600_accel_read_sensor()
270 return -EINVAL; in inv_icm42600_accel_read_sensor()
274 mutex_lock(&st->lock); in inv_icm42600_accel_read_sensor()
277 conf.mode = accel_st->power_mode; in inv_icm42600_accel_read_sensor()
278 conf.filter = accel_st->filter; in inv_icm42600_accel_read_sensor()
284 data = (__be16 *)&st->buffer[0]; in inv_icm42600_accel_read_sensor()
285 ret = regmap_bulk_read(st->map, reg, data, sizeof(*data)); in inv_icm42600_accel_read_sensor()
291 ret = -EINVAL; in inv_icm42600_accel_read_sensor()
293 mutex_unlock(&st->lock); in inv_icm42600_accel_read_sensor()
301 /* +/- 16G => 0.004788403 m/s-2 */
304 /* +/- 8G => 0.002394202 m/s-2 */
307 /* +/- 4G => 0.001197101 m/s-2 */
310 /* +/- 2G => 0.000598550 m/s-2 */
315 /* +/- 32G => 0.009576807 m/s-2 */
318 /* +/- 16G => 0.004788403 m/s-2 */
321 /* +/- 8G => 0.002394202 m/s-2 */
324 /* +/- 4G => 0.001197101 m/s-2 */
327 /* +/- 2G => 0.000598550 m/s-2 */
339 idx = st->conf.accel.fs; in inv_icm42600_accel_read_scale()
341 *val = accel_st->scales[2 * idx]; in inv_icm42600_accel_read_scale()
342 *val2 = accel_st->scales[2 * idx + 1]; in inv_icm42600_accel_read_scale()
351 struct device *dev = regmap_get_device(st->map); in inv_icm42600_accel_write_scale()
356 for (idx = 0; idx < accel_st->scales_len; idx += 2) { in inv_icm42600_accel_write_scale()
357 if (val == accel_st->scales[idx] && in inv_icm42600_accel_write_scale()
358 val2 == accel_st->scales[idx + 1]) in inv_icm42600_accel_write_scale()
361 if (idx >= accel_st->scales_len) in inv_icm42600_accel_write_scale()
362 return -EINVAL; in inv_icm42600_accel_write_scale()
367 mutex_lock(&st->lock); in inv_icm42600_accel_write_scale()
371 mutex_unlock(&st->lock); in inv_icm42600_accel_write_scale()
424 odr = st->conf.accel.odr; in inv_icm42600_accel_read_odr()
431 return -EINVAL; in inv_icm42600_accel_read_odr()
444 struct inv_sensors_timestamp *ts = &accel_st->ts; in inv_icm42600_accel_write_odr()
445 struct device *dev = regmap_get_device(st->map); in inv_icm42600_accel_write_odr()
456 return -EINVAL; in inv_icm42600_accel_write_odr()
461 mutex_lock(&st->lock); in inv_icm42600_accel_write_odr()
475 mutex_unlock(&st->lock); in inv_icm42600_accel_write_odr()
484 * Value is limited to +/-1g coded on 12 bits signed. Step is 0.5mg.
487 -10, 42010, /* min: -10.042010 m/s² */
496 struct device *dev = regmap_get_device(st->map); in inv_icm42600_accel_read_offset()
504 if (chan->type != IIO_ACCEL) in inv_icm42600_accel_read_offset()
505 return -EINVAL; in inv_icm42600_accel_read_offset()
507 switch (chan->channel2) { in inv_icm42600_accel_read_offset()
518 return -EINVAL; in inv_icm42600_accel_read_offset()
522 mutex_lock(&st->lock); in inv_icm42600_accel_read_offset()
524 ret = regmap_bulk_read(st->map, reg, st->buffer, sizeof(data)); in inv_icm42600_accel_read_offset()
525 memcpy(data, st->buffer, sizeof(data)); in inv_icm42600_accel_read_offset()
527 mutex_unlock(&st->lock); in inv_icm42600_accel_read_offset()
534 switch (chan->channel2) { in inv_icm42600_accel_read_offset()
545 return -EINVAL; in inv_icm42600_accel_read_offset()
556 /* for rounding, add + or - divisor (10000) divided by 2 */ in inv_icm42600_accel_read_offset()
560 val64 -= 10000LL / 2LL; in inv_icm42600_accel_read_offset()
572 struct device *dev = regmap_get_device(st->map); in inv_icm42600_accel_write_offset()
579 if (chan->type != IIO_ACCEL) in inv_icm42600_accel_write_offset()
580 return -EINVAL; in inv_icm42600_accel_write_offset()
582 switch (chan->channel2) { in inv_icm42600_accel_write_offset()
593 return -EINVAL; in inv_icm42600_accel_write_offset()
596 /* inv_icm42600_accel_calibbias: min - step - max in micro */ in inv_icm42600_accel_write_offset()
603 return -EINVAL; in inv_icm42600_accel_write_offset()
613 /* for rounding, add + or - divisor (9806650 * 5) divided by 2 */ in inv_icm42600_accel_write_offset()
617 val64 -= 9806650 * 5 / 2; in inv_icm42600_accel_write_offset()
621 if (offset < -2048) in inv_icm42600_accel_write_offset()
622 offset = -2048; in inv_icm42600_accel_write_offset()
627 mutex_lock(&st->lock); in inv_icm42600_accel_write_offset()
629 switch (chan->channel2) { in inv_icm42600_accel_write_offset()
632 ret = regmap_read(st->map, INV_ICM42600_REG_OFFSET_USER4, in inv_icm42600_accel_write_offset()
636 st->buffer[0] = ((offset & 0xF00) >> 4) | (regval & 0x0F); in inv_icm42600_accel_write_offset()
637 st->buffer[1] = offset & 0xFF; in inv_icm42600_accel_write_offset()
641 ret = regmap_read(st->map, INV_ICM42600_REG_OFFSET_USER7, in inv_icm42600_accel_write_offset()
645 st->buffer[0] = offset & 0xFF; in inv_icm42600_accel_write_offset()
646 st->buffer[1] = ((offset & 0xF00) >> 8) | (regval & 0xF0); in inv_icm42600_accel_write_offset()
650 ret = regmap_read(st->map, INV_ICM42600_REG_OFFSET_USER7, in inv_icm42600_accel_write_offset()
654 st->buffer[0] = ((offset & 0xF00) >> 4) | (regval & 0x0F); in inv_icm42600_accel_write_offset()
655 st->buffer[1] = offset & 0xFF; in inv_icm42600_accel_write_offset()
658 ret = -EINVAL; in inv_icm42600_accel_write_offset()
662 ret = regmap_bulk_write(st->map, reg, st->buffer, 2); in inv_icm42600_accel_write_offset()
665 mutex_unlock(&st->lock); in inv_icm42600_accel_write_offset()
679 switch (chan->type) { in inv_icm42600_accel_read_raw()
685 return -EINVAL; in inv_icm42600_accel_read_raw()
706 return -EINVAL; in inv_icm42600_accel_read_raw()
717 if (chan->type != IIO_ACCEL) in inv_icm42600_accel_read_avail()
718 return -EINVAL; in inv_icm42600_accel_read_avail()
722 *vals = accel_st->scales; in inv_icm42600_accel_read_avail()
724 *length = accel_st->scales_len; in inv_icm42600_accel_read_avail()
736 return -EINVAL; in inv_icm42600_accel_read_avail()
747 if (chan->type != IIO_ACCEL) in inv_icm42600_accel_write_raw()
748 return -EINVAL; in inv_icm42600_accel_write_raw()
768 return -EINVAL; in inv_icm42600_accel_write_raw()
776 if (chan->type != IIO_ACCEL) in inv_icm42600_accel_write_raw_get_fmt()
777 return -EINVAL; in inv_icm42600_accel_write_raw_get_fmt()
787 return -EINVAL; in inv_icm42600_accel_write_raw_get_fmt()
797 mutex_lock(&st->lock); in inv_icm42600_accel_hwfifo_set_watermark()
799 st->fifo.watermark.accel = val; in inv_icm42600_accel_hwfifo_set_watermark()
802 mutex_unlock(&st->lock); in inv_icm42600_accel_hwfifo_set_watermark()
816 mutex_lock(&st->lock); in inv_icm42600_accel_hwfifo_flush()
820 ret = st->fifo.nb.accel; in inv_icm42600_accel_hwfifo_flush()
822 mutex_unlock(&st->lock); in inv_icm42600_accel_hwfifo_flush()
840 struct device *dev = regmap_get_device(st->map); in inv_icm42600_accel_init()
847 name = devm_kasprintf(dev, GFP_KERNEL, "%s-accel", st->name); in inv_icm42600_accel_init()
849 return ERR_PTR(-ENOMEM); in inv_icm42600_accel_init()
853 return ERR_PTR(-ENOMEM); in inv_icm42600_accel_init()
856 switch (st->chip) { in inv_icm42600_accel_init()
858 accel_st->scales = inv_icm42686_accel_scale; in inv_icm42600_accel_init()
859 accel_st->scales_len = ARRAY_SIZE(inv_icm42686_accel_scale); in inv_icm42600_accel_init()
862 accel_st->scales = inv_icm42600_accel_scale; in inv_icm42600_accel_init()
863 accel_st->scales_len = ARRAY_SIZE(inv_icm42600_accel_scale); in inv_icm42600_accel_init()
866 /* low-power by default at init */ in inv_icm42600_accel_init()
867 accel_st->power_mode = INV_ICM42600_SENSOR_MODE_LOW_POWER; in inv_icm42600_accel_init()
868 accel_st->filter = INV_ICM42600_FILTER_AVG_16X; in inv_icm42600_accel_init()
872 * jitter is +/- 2% (20 per mille) in inv_icm42600_accel_init()
876 ts_chip.init_period = inv_icm42600_odr_to_period(st->conf.accel.odr); in inv_icm42600_accel_init()
877 inv_sensors_timestamp_init(&accel_st->ts, &ts_chip); in inv_icm42600_accel_init()
880 indio_dev->name = name; in inv_icm42600_accel_init()
881 indio_dev->info = &inv_icm42600_accel_info; in inv_icm42600_accel_init()
882 indio_dev->modes = INDIO_DIRECT_MODE; in inv_icm42600_accel_init()
883 indio_dev->channels = inv_icm42600_accel_channels; in inv_icm42600_accel_init()
884 indio_dev->num_channels = ARRAY_SIZE(inv_icm42600_accel_channels); in inv_icm42600_accel_init()
885 indio_dev->available_scan_masks = inv_icm42600_accel_scan_masks; in inv_icm42600_accel_init()
903 struct inv_sensors_timestamp *ts = &accel_st->ts; in inv_icm42600_accel_parse_fifo()
913 for (i = 0, no = 0; i < st->fifo.count; i += size, ++no) { in inv_icm42600_accel_parse_fifo()
914 size = inv_icm42600_fifo_decode_packet(&st->fifo.data[i], in inv_icm42600_accel_parse_fifo()
926 inv_sensors_timestamp_apply_odr(ts, st->fifo.period, in inv_icm42600_accel_parse_fifo()
927 st->fifo.nb.total, no); in inv_icm42600_accel_parse_fifo()