Lines Matching +full:industrial +full:- +full:consumer +full:- +full:applications

1 // SPDX-License-Identifier: GPL-2.0-only
16 #include <linux/regulator/consumer.h>
27 #include "kionix-kx022a.h"
87 * The HW does not set WHO_AM_I reg as read-only but we don't want to write it
88 * so we still include it in the read-only ranges.
305 return &data->orientation; in kx022a_get_mount_matrix()
391 * range is typically +-2G/4G/8G/16G, distributed over the amount of bits.
394 * => KX022A uses 16 bit (HiRes mode - assume the low 8 bits are zeroed
395 * in low-power mode(?) )
396 * => +/-2G => 4 / 2^16 * 9,80665
397 * => +/-2G - 0.000598550415
398 * +/-4G - 0.00119710083
399 * +/-8G - 0.00239420166
400 * +/-16G - 0.00478840332
428 return -EINVAL; in kx022a_read_avail()
455 ret = regmap_set_bits(data->regmap, data->chip_info->cntl, in kx022a_turn_on_off_unlocked()
458 ret = regmap_clear_bits(data->regmap, data->chip_info->cntl, in kx022a_turn_on_off_unlocked()
461 dev_err(data->dev, "Turn %s fail %d\n", str_on_off(on), ret); in kx022a_turn_on_off_unlocked()
470 mutex_lock(&data->mutex); in kx022a_turn_off_lock()
473 mutex_unlock(&data->mutex); in kx022a_turn_off_lock()
483 mutex_unlock(&data->mutex); in kx022a_turn_on_unlock()
498 return -EINVAL; in kx022a_write_raw_get_fmt()
516 * time-limit). in kx022a_write_raw()
526 while (n--) in kx022a_write_raw()
531 ret = -EINVAL; in kx022a_write_raw()
538 ret = regmap_update_bits(data->regmap, in kx022a_write_raw()
539 data->chip_info->odcntl, in kx022a_write_raw()
541 data->odr_ns = kx022a_odrs[n]; in kx022a_write_raw()
547 while (n-- > 0) in kx022a_write_raw()
552 ret = -EINVAL; in kx022a_write_raw()
560 ret = regmap_update_bits(data->regmap, data->chip_info->cntl, in kx022a_write_raw()
566 ret = -EINVAL; in kx022a_write_raw()
580 threshold = data->watermark; in kx022a_fifo_set_wmi()
582 return regmap_update_bits(data->regmap, data->chip_info->buf_cntl1, in kx022a_fifo_set_wmi()
592 ret = regmap_bulk_read(data->regmap, chan->address, &data->buffer[0], in kx022a_get_axis()
597 *val = le16_to_cpu(data->buffer[0]); in kx022a_get_axis()
616 mutex_lock(&data->mutex); in kx022a_read_raw()
618 mutex_unlock(&data->mutex); in kx022a_read_raw()
625 ret = regmap_read(data->regmap, data->chip_info->odcntl, &regval); in kx022a_read_raw()
631 dev_err(data->dev, "Invalid ODR\n"); in kx022a_read_raw()
632 return -EINVAL; in kx022a_read_raw()
640 ret = regmap_read(data->regmap, data->chip_info->cntl, &regval); in kx022a_read_raw()
649 return -EINVAL; in kx022a_read_raw()
656 val = min(data->chip_info->fifo_length, val); in kx022a_set_watermark()
658 mutex_lock(&data->mutex); in kx022a_set_watermark()
659 data->watermark = val; in kx022a_set_watermark()
660 mutex_unlock(&data->mutex); in kx022a_set_watermark()
673 mutex_lock(&data->mutex); in hwfifo_enabled_show()
674 state = data->state; in hwfifo_enabled_show()
675 mutex_unlock(&data->mutex); in hwfifo_enabled_show()
688 mutex_lock(&data->mutex); in hwfifo_watermark_show()
689 wm = data->watermark; in hwfifo_watermark_show()
690 mutex_unlock(&data->mutex); in hwfifo_watermark_show()
707 * We must clear the old time-stamp to avoid computing the timestamps in kx022a_drop_fifo_contents()
711 * called from fifo-disable where we can guarantee the sensor is not in kx022a_drop_fifo_contents()
713 * user-space access. in kx022a_drop_fifo_contents()
715 data->timestamp = 0; in kx022a_drop_fifo_contents()
717 return regmap_write(data->regmap, data->chip_info->buf_clear, 0x0); in kx022a_drop_fifo_contents()
724 ret = regmap_read(data->regmap, KX022A_REG_BUF_STATUS_1, &fifo_bytes); in kx022a_get_fifo_bytes_available()
726 dev_err(data->dev, "Error reading buffer status\n"); in kx022a_get_fifo_bytes_available()
741 ret = regmap_bulk_read(data->regmap, data->chip_info->buf_status1, in kx132_get_fifo_bytes_available()
744 dev_err(data->dev, "Error reading buffer status\n"); in kx132_get_fifo_bytes_available()
749 fifo_bytes &= data->chip_info->buf_smp_lvl_mask; in kx132_get_fifo_bytes_available()
750 fifo_bytes = min((unsigned int)fifo_bytes, data->chip_info->fifo_length * in kx132_get_fifo_bytes_available()
766 fifo_bytes = data->chip_info->get_fifo_bytes_available(data); in __kx022a_fifo_flush()
769 dev_warn(data->dev, "Bad FIFO alignment. Data may be corrupt\n"); in __kx022a_fifo_flush()
785 * We need to have the IRQ disabled or we risk of messing-up in __kx022a_fifo_flush()
787 * IRQF_ONESHOT has us covered - but if we are ran by the in __kx022a_fifo_flush()
788 * user-space read we need to disable the IRQ to be on a safe in __kx022a_fifo_flush()
793 disable_irq(data->irq); in __kx022a_fifo_flush()
796 data->old_timestamp = data->timestamp; in __kx022a_fifo_flush()
797 data->timestamp = iio_get_time_ns(idev); in __kx022a_fifo_flush()
811 if (data->old_timestamp) { in __kx022a_fifo_flush()
812 sample_period = data->timestamp - data->old_timestamp; in __kx022a_fifo_flush()
815 sample_period = data->odr_ns; in __kx022a_fifo_flush()
817 tstamp = data->timestamp - (count - 1) * sample_period; in __kx022a_fifo_flush()
825 data->timestamp -= (count - samples) * sample_period; in __kx022a_fifo_flush()
830 ret = regmap_noinc_read(data->regmap, data->chip_info->buf_read, in __kx022a_fifo_flush()
831 data->fifo_buffer, fifo_bytes); in __kx022a_fifo_flush()
836 __le16 *sam = &data->fifo_buffer[i * 3]; in __kx022a_fifo_flush()
840 chs = &data->scan.channels[0]; in __kx022a_fifo_flush()
841 for_each_set_bit(bit, idev->active_scan_mask, AXIS_MAX) in __kx022a_fifo_flush()
844 iio_push_to_buffers_with_timestamp(idev, &data->scan, tstamp); in __kx022a_fifo_flush()
853 enable_irq(data->irq); in __kx022a_fifo_flush()
863 mutex_lock(&data->mutex); in kx022a_fifo_flush()
865 mutex_unlock(&data->mutex); in kx022a_fifo_flush()
884 return regmap_set_bits(data->regmap, data->chip_info->cntl, in kx022a_set_drdy_irq()
887 return regmap_clear_bits(data->regmap, data->chip_info->cntl, in kx022a_set_drdy_irq()
900 ret = regmap_update_bits(data->regmap, data->inc_reg, mask, val); in kx022a_prepare_irq_pin()
907 return regmap_set_bits(data->regmap, data->ien_reg, mask); in kx022a_prepare_irq_pin()
918 ret = regmap_clear_bits(data->regmap, data->ien_reg, KX022A_MASK_WMI); in kx022a_fifo_disable()
922 ret = regmap_clear_bits(data->regmap, data->chip_info->buf_cntl2, in kx022a_fifo_disable()
927 data->state &= ~KX022A_STATE_FIFO; in kx022a_fifo_disable()
931 kfree(data->fifo_buffer); in kx022a_fifo_disable()
936 mutex_unlock(&data->mutex); in kx022a_fifo_disable()
955 data->fifo_buffer = kmalloc_array(data->chip_info->fifo_length, in kx022a_fifo_enable()
958 if (!data->fifo_buffer) in kx022a_fifo_enable()
959 return -ENOMEM; in kx022a_fifo_enable()
971 ret = regmap_set_bits(data->regmap, data->chip_info->buf_cntl2, in kx022a_fifo_enable()
976 data->state |= KX022A_STATE_FIFO; in kx022a_fifo_enable()
977 ret = regmap_set_bits(data->regmap, data->ien_reg, in kx022a_fifo_enable()
985 mutex_unlock(&data->mutex); in kx022a_fifo_enable()
995 * If we use data-ready trigger, then the IRQ masks should be handled by in kx022a_buffer_postenable()
997 * results to the IIO fifo when data-ready triggers. in kx022a_buffer_postenable()
1013 struct iio_dev *idev = pf->indio_dev; in kx022a_trigger_handler()
1017 ret = regmap_bulk_read(data->regmap, data->chip_info->xout_l, data->buffer, in kx022a_trigger_handler()
1022 iio_push_to_buffers_with_timestamp(idev, data->buffer, data->timestamp); in kx022a_trigger_handler()
1024 iio_trigger_notify_done(idev->trig); in kx022a_trigger_handler()
1035 data->old_timestamp = data->timestamp; in kx022a_irq_handler()
1036 data->timestamp = iio_get_time_ns(idev); in kx022a_irq_handler()
1038 if (data->state & KX022A_STATE_FIFO || data->trigger_enabled) in kx022a_irq_handler()
1045 * WMI and data-ready IRQs are acked when results are read. If we add
1046 * TILT/WAKE or other IRQs - then we may need to implement the acking
1055 mutex_lock(&data->mutex); in kx022a_irq_thread_handler()
1057 if (data->trigger_enabled) { in kx022a_irq_thread_handler()
1058 iio_trigger_poll_nested(data->trig); in kx022a_irq_thread_handler()
1062 if (data->state & KX022A_STATE_FIFO) { in kx022a_irq_thread_handler()
1065 ok = __kx022a_fifo_flush(idev, data->chip_info->fifo_length, true); in kx022a_irq_thread_handler()
1070 mutex_unlock(&data->mutex); in kx022a_irq_thread_handler()
1081 mutex_lock(&data->mutex); in kx022a_trigger_set_state()
1083 if (data->trigger_enabled == state) in kx022a_trigger_set_state()
1086 if (data->state & KX022A_STATE_FIFO) { in kx022a_trigger_set_state()
1087 dev_warn(data->dev, "Can't set trigger when FIFO enabled\n"); in kx022a_trigger_set_state()
1088 ret = -EBUSY; in kx022a_trigger_set_state()
1096 data->trigger_enabled = state; in kx022a_trigger_set_state()
1104 mutex_unlock(&data->mutex); in kx022a_trigger_set_state()
1118 ret = regmap_write(data->regmap, data->chip_info->cntl2, KX022A_MASK_SRST); in kx022a_chip_init()
1128 ret = regmap_read_poll_timeout(data->regmap, data->chip_info->cntl2, val, in kx022a_chip_init()
1133 dev_err(data->dev, "Sensor reset %s\n", in kx022a_chip_init()
1138 ret = regmap_reinit_cache(data->regmap, data->chip_info->regmap_config); in kx022a_chip_init()
1140 dev_err(data->dev, "Failed to reinit reg cache\n"); in kx022a_chip_init()
1145 ret = regmap_set_bits(data->regmap, data->chip_info->buf_cntl2, in kx022a_chip_init()
1148 dev_err(data->dev, "Failed to set data resolution\n"); in kx022a_chip_init()
1156 .name = "kx022-accel",
1181 .name = "kx132-1211",
1207 * Despite the naming, KX132ACR-LBZ is not similar to KX132-1211 but it is
1208 * exact subset of KX022A. KX132ACR-LBZ is meant to be used for industrial
1209 * applications and the tap/double tap, free fall and tilt engines were
1214 .name = "kx132acr-lbz",
1240 static const char * const regulator_names[] = {"io-vdd", "vdd"}; in kx022a_probe_internal()
1253 return -EINVAL; in kx022a_probe_internal()
1258 return -ENODEV; in kx022a_probe_internal()
1262 return -ENOMEM; in kx022a_probe_internal()
1265 data->chip_info = chip_info; in kx022a_probe_internal()
1273 if (ret && ret != -ENODEV) in kx022a_probe_internal()
1276 ret = regmap_read(regmap, chip_info->who, &chip_id); in kx022a_probe_internal()
1280 if (chip_id != chip_info->id) in kx022a_probe_internal()
1285 data->inc_reg = chip_info->inc1; in kx022a_probe_internal()
1286 data->ien_reg = chip_info->inc4; in kx022a_probe_internal()
1292 data->inc_reg = chip_info->inc5; in kx022a_probe_internal()
1293 data->ien_reg = chip_info->inc6; in kx022a_probe_internal()
1296 data->regmap = regmap; in kx022a_probe_internal()
1297 data->dev = dev; in kx022a_probe_internal()
1298 data->irq = irq; in kx022a_probe_internal()
1299 data->odr_ns = KX022A_DEFAULT_PERIOD_NS; in kx022a_probe_internal()
1300 mutex_init(&data->mutex); in kx022a_probe_internal()
1302 idev->channels = chip_info->channels; in kx022a_probe_internal()
1303 idev->num_channels = chip_info->num_channels; in kx022a_probe_internal()
1304 idev->name = chip_info->name; in kx022a_probe_internal()
1305 idev->info = &kx022a_info; in kx022a_probe_internal()
1306 idev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; in kx022a_probe_internal()
1307 idev->available_scan_masks = kx022a_scan_masks; in kx022a_probe_internal()
1310 ret = iio_read_mount_matrix(dev, &data->orientation); in kx022a_probe_internal()
1321 mutex_unlock(&data->mutex); in kx022a_probe_internal()
1337 return dev_err_probe(data->dev, ret, in kx022a_probe_internal()
1339 indio_trig = devm_iio_trigger_alloc(dev, "%sdata-rdy-dev%d", idev->name, in kx022a_probe_internal()
1342 return -ENOMEM; in kx022a_probe_internal()
1344 data->trig = indio_trig; in kx022a_probe_internal()
1346 indio_trig->ops = &kx022a_trigger_ops; in kx022a_probe_internal()
1353 name = devm_kasprintf(data->dev, GFP_KERNEL, "%s-kx022a", in kx022a_probe_internal()
1354 dev_name(data->dev)); in kx022a_probe_internal()
1356 ret = devm_request_threaded_irq(data->dev, irq, kx022a_irq_handler, in kx022a_probe_internal()
1360 return dev_err_probe(data->dev, ret, "Could not request IRQ\n"); in kx022a_probe_internal()
1364 return dev_err_probe(data->dev, ret, in kx022a_probe_internal()
1367 ret = devm_iio_device_register(data->dev, idev); in kx022a_probe_internal()