Lines Matching +full:acquisition +full:- +full:time

1 // SPDX-License-Identifier: GPL-2.0
129 #define AD7280A_NUM_CH (AD7280A_AUX_ADC_6_REG - \
135 (c) - AD7280A_CELLS_PER_DEV)
143 /* 5-bit device address is sent LSB first */
203 unsigned char crc = ad7280_calc_crc8(st->crc_tab, val >> 10); in ad7280_check_crc()
206 return -EIO; in ad7280_check_crc()
215 * conversion delays and acquisition time options it may take up to 250us, in
221 if (st->readback_delay_us < 50) in ad7280_delay()
222 udelay(st->readback_delay_us); in ad7280_delay()
231 .tx_buf = &st->tx, in __ad7280_read32()
232 .rx_buf = &st->rx, in __ad7280_read32()
233 .len = sizeof(st->tx), in __ad7280_read32()
236 st->tx = cpu_to_be32(AD7280A_READ_TXVAL); in __ad7280_read32()
238 ret = spi_sync_transfer(st->spi, &t, 1); in __ad7280_read32()
242 *val = be32_to_cpu(st->rx); in __ad7280_read32()
256 ad7280_calc_crc8(st->crc_tab, reg >> 11)); in ad7280_write()
260 st->tx = cpu_to_be32(reg); in ad7280_write()
262 return spi_write(st->spi, &st->tx, sizeof(st->tx)); in ad7280_write()
278 st->oversampling_ratio)); in ad7280_read_reg()
289 st->oversampling_ratio)); in ad7280_read_reg()
304 return -EIO; in ad7280_read_reg()
308 return -EFAULT; in ad7280_read_reg()
330 st->oversampling_ratio)); in ad7280_read_channel()
342 st->oversampling_ratio)); in ad7280_read_channel()
353 return -EIO; in ad7280_read_channel()
357 return -EFAULT; in ad7280_read_channel()
381 st->oversampling_ratio)); in ad7280_read_all_channels()
393 return -EIO; in ad7280_read_all_channels()
412 FIELD_PREP(AD7280A_CTRL_HB_CONV_AVG_MSK, st->oversampling_ratio)); in ad7280_sw_power_down()
425 st->ctrl_lb); in ad7280_chain_setup()
434 st->ctrl_lb); in ad7280_chain_setup()
449 return n - 1; in ad7280_chain_setup()
452 ret = -EIO; in ad7280_chain_setup()
457 ret = -EIO; in ad7280_chain_setup()
461 ret = -EFAULT; in ad7280_chain_setup()
466 FIELD_PREP(AD7280A_CTRL_HB_CONV_AVG_MSK, st->oversampling_ratio)); in ad7280_chain_setup()
478 !!(st->cb_mask[chan->address >> 8] & in ad7280_show_balance_sw()
479 BIT(chan->address & 0xFF))); in ad7280_show_balance_sw()
496 devaddr = chan->address >> 8; in ad7280_store_balance_sw()
497 ch = chan->address & 0xFF; in ad7280_store_balance_sw()
499 mutex_lock(&st->lock); in ad7280_store_balance_sw()
501 st->cb_mask[devaddr] |= BIT(ch); in ad7280_store_balance_sw()
503 st->cb_mask[devaddr] &= ~BIT(ch); in ad7280_store_balance_sw()
507 st->cb_mask[devaddr])); in ad7280_store_balance_sw()
508 mutex_unlock(&st->lock); in ad7280_store_balance_sw()
522 mutex_lock(&st->lock); in ad7280_show_balance_timer()
523 ret = ad7280_read_reg(st, chan->address >> 8, in ad7280_show_balance_timer()
524 (chan->address & 0xFF) + AD7280A_CB1_TIMER_REG); in ad7280_show_balance_timer()
525 mutex_unlock(&st->lock); in ad7280_show_balance_timer()
552 return -EINVAL; in ad7280_store_balance_timer()
554 mutex_lock(&st->lock); in ad7280_store_balance_timer()
555 ret = ad7280_write(st, chan->address >> 8, in ad7280_store_balance_timer()
556 (chan->address & 0xFF) + AD7280A_CB1_TIMER_REG, 0, in ad7280_store_balance_timer()
558 mutex_unlock(&st->lock); in ad7280_store_balance_timer()
593 chan->type = IIO_VOLTAGE; in ad7280_voltage_channel_init()
594 chan->differential = 1; in ad7280_voltage_channel_init()
595 chan->channel = i; in ad7280_voltage_channel_init()
596 chan->channel2 = chan->channel + 1; in ad7280_voltage_channel_init()
598 chan->event_spec = ad7280_events; in ad7280_voltage_channel_init()
599 chan->num_event_specs = ARRAY_SIZE(ad7280_events); in ad7280_voltage_channel_init()
601 chan->ext_info = ad7280_cell_ext_info; in ad7280_voltage_channel_init()
607 chan->type = IIO_TEMP; in ad7280_temp_channel_init()
608 chan->channel = i; in ad7280_temp_channel_init()
610 chan->event_spec = ad7280_events; in ad7280_temp_channel_init()
611 chan->num_event_specs = ARRAY_SIZE(ad7280_events); in ad7280_temp_channel_init()
618 chan->indexed = 1; in ad7280_common_fields_init()
619 chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); in ad7280_common_fields_init()
620 chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE); in ad7280_common_fields_init()
621 chan->info_mask_shared_by_all = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO); in ad7280_common_fields_init()
622 chan->address = addr; in ad7280_common_fields_init()
623 chan->scan_index = cnt; in ad7280_common_fields_init()
624 chan->scan_type.sign = 'u'; in ad7280_common_fields_init()
625 chan->scan_type.realbits = 12; in ad7280_common_fields_init()
626 chan->scan_type.storagebits = 32; in ad7280_common_fields_init()
632 chan->type = IIO_VOLTAGE; in ad7280_total_voltage_channel_init()
633 chan->differential = 1; in ad7280_total_voltage_channel_init()
634 chan->channel = 0; in ad7280_total_voltage_channel_init()
635 chan->channel2 = dev * AD7280A_CELLS_PER_DEV; in ad7280_total_voltage_channel_init()
636 chan->address = AD7280A_ALL_CELLS; in ad7280_total_voltage_channel_init()
637 chan->indexed = 1; in ad7280_total_voltage_channel_init()
638 chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); in ad7280_total_voltage_channel_init()
639 chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE); in ad7280_total_voltage_channel_init()
640 chan->scan_index = cnt; in ad7280_total_voltage_channel_init()
641 chan->scan_type.sign = 'u'; in ad7280_total_voltage_channel_init()
642 chan->scan_type.realbits = 32; in ad7280_total_voltage_channel_init()
643 chan->scan_type.storagebits = 32; in ad7280_total_voltage_channel_init()
653 chan = &st->channels[*cnt]; in ad7280_init_dev_channels()
674 st->channels = devm_kcalloc(&st->spi->dev, (st->slave_num + 1) * 12 + 1, in ad7280_channel_init()
675 sizeof(*st->channels), GFP_KERNEL); in ad7280_channel_init()
676 if (!st->channels) in ad7280_channel_init()
677 return -ENOMEM; in ad7280_channel_init()
679 for (dev = 0; dev <= st->slave_num; dev++) in ad7280_channel_init()
682 ad7280_total_voltage_channel_init(&st->channels[cnt], cnt, dev); in ad7280_channel_init()
695 switch (chan->type) { in ad7280a_read_thresh()
699 *val = 1000 + (st->cell_threshhigh * 1568L) / 100; in ad7280a_read_thresh()
702 *val = 1000 + (st->cell_threshlow * 1568L) / 100; in ad7280a_read_thresh()
705 return -EINVAL; in ad7280a_read_thresh()
711 *val = ((st->aux_threshhigh) * 196L) / 10; in ad7280a_read_thresh()
714 *val = (st->aux_threshlow * 196L) / 10; in ad7280a_read_thresh()
717 return -EINVAL; in ad7280a_read_thresh()
721 return -EINVAL; in ad7280a_read_thresh()
738 return -EINVAL; in ad7280a_write_thresh()
740 mutex_lock(&st->lock); in ad7280a_write_thresh()
741 switch (chan->type) { in ad7280a_write_thresh()
743 value = ((val - 1000) * 100) / 1568; /* LSB 15.68mV */ in ad7280a_write_thresh()
752 st->cell_threshhigh = value; in ad7280a_write_thresh()
760 st->cell_threshlow = value; in ad7280a_write_thresh()
763 ret = -EINVAL; in ad7280a_write_thresh()
777 st->aux_threshhigh = value; in ad7280a_write_thresh()
785 st->aux_threshlow = value; in ad7280a_write_thresh()
788 ret = -EINVAL; in ad7280a_write_thresh()
793 ret = -EINVAL; in ad7280a_write_thresh()
798 mutex_unlock(&st->lock); in ad7280a_write_thresh()
809 unsigned int *channels __free(kfree) = kcalloc(st->scan_cnt, sizeof(*channels), in ad7280_event_handler()
814 ret = ad7280_read_all_channels(st, st->scan_cnt, channels); in ad7280_event_handler()
818 for (i = 0; i < st->scan_cnt; i++) { in ad7280_event_handler()
824 if (val >= st->cell_threshhigh) { in ad7280_event_handler()
831 } else if (val <= st->cell_threshlow) { in ad7280_event_handler()
840 if (val >= st->aux_threshhigh) { in ad7280_event_handler()
846 } else if (val <= st->aux_threshlow) { in ad7280_event_handler()
862 * Total Conversion Time = ((tACQ + tCONV) * in ad7280_update_delay()
864 * tACQ + ((N - 1) * tDELAY) in ad7280_update_delay()
866 * Readback Delay = Total Conversion Time + tWAIT in ad7280_update_delay()
869 st->readback_delay_us = in ad7280_update_delay()
870 ((ad7280a_t_acq_ns[st->acquisition_time & 0x3] + 720) * in ad7280_update_delay()
871 (AD7280A_NUM_CH * ad7280a_n_avg[st->oversampling_ratio & 0x3])) - in ad7280_update_delay()
872 ad7280a_t_acq_ns[st->acquisition_time & 0x3] + st->slave_num * 250; in ad7280_update_delay()
875 st->readback_delay_us = DIV_ROUND_UP(st->readback_delay_us, 1000); in ad7280_update_delay()
876 st->readback_delay_us += 5; /* Add tWAIT */ in ad7280_update_delay()
890 mutex_lock(&st->lock); in ad7280_read_raw()
891 if (chan->address == AD7280A_ALL_CELLS) in ad7280_read_raw()
892 ret = ad7280_read_all_channels(st, st->scan_cnt, NULL); in ad7280_read_raw()
894 ret = ad7280_read_channel(st, chan->address >> 8, in ad7280_read_raw()
895 chan->address & 0xFF); in ad7280_read_raw()
896 mutex_unlock(&st->lock); in ad7280_read_raw()
905 if ((chan->address & 0xFF) <= AD7280A_CELL_VOLTAGE_6_REG) in ad7280_read_raw()
913 *val = ad7280a_n_avg[st->oversampling_ratio]; in ad7280_read_raw()
916 return -EINVAL; in ad7280_read_raw()
929 return -EINVAL; in ad7280_write_raw()
932 st->oversampling_ratio = i; in ad7280_write_raw()
937 return -EINVAL; in ad7280_write_raw()
939 return -EINVAL; in ad7280_write_raw()
957 struct device *dev = &spi->dev; in ad7280_probe()
964 return -ENOMEM; in ad7280_probe()
968 st->spi = spi; in ad7280_probe()
969 mutex_init(&st->lock); in ad7280_probe()
971 st->thermistor_term_en = in ad7280_probe()
972 device_property_read_bool(dev, "adi,thermistor-termination"); in ad7280_probe()
974 if (device_property_present(dev, "adi,acquisition-time-ns")) { in ad7280_probe()
977 ret = device_property_read_u32(dev, "adi,acquisition-time-ns", &val); in ad7280_probe()
983 st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_400ns; in ad7280_probe()
986 st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_800ns; in ad7280_probe()
989 st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_1200ns; in ad7280_probe()
992 st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_1600ns; in ad7280_probe()
995 dev_err(dev, "Firmware provided acquisition time is invalid\n"); in ad7280_probe()
996 return -EINVAL; in ad7280_probe()
999 st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_400ns; in ad7280_probe()
1003 if (device_property_present(dev, "adi,voltage-alert-last-chan")) { in ad7280_probe()
1006 ret = device_property_read_u32(dev, "adi,voltage-alert-last-chan", &val); in ad7280_probe()
1012 st->chain_last_alert_ignore |= AD7280A_ALERT_REMOVE_VIN4_VIN5; in ad7280_probe()
1015 st->chain_last_alert_ignore |= AD7280A_ALERT_REMOVE_VIN5; in ad7280_probe()
1025 crc8_populate_msb(st->crc_tab, POLYNOM); in ad7280_probe()
1027 st->spi->max_speed_hz = AD7280A_MAX_SPI_CLK_HZ; in ad7280_probe()
1028 st->spi->mode = SPI_MODE_1; in ad7280_probe()
1029 spi_setup(st->spi); in ad7280_probe()
1031 st->ctrl_lb = FIELD_PREP(AD7280A_CTRL_LB_ACQ_TIME_MSK, st->acquisition_time) | in ad7280_probe()
1032 FIELD_PREP(AD7280A_CTRL_LB_THERMISTOR_MSK, st->thermistor_term_en); in ad7280_probe()
1033 st->oversampling_ratio = 0; /* No oversampling */ in ad7280_probe()
1039 st->slave_num = ret; in ad7280_probe()
1040 st->scan_cnt = (st->slave_num + 1) * AD7280A_NUM_CH; in ad7280_probe()
1041 st->cell_threshhigh = 0xFF; in ad7280_probe()
1042 st->aux_threshhigh = 0xFF; in ad7280_probe()
1050 indio_dev->name = spi_get_device_id(spi)->name; in ad7280_probe()
1051 indio_dev->modes = INDIO_DIRECT_MODE; in ad7280_probe()
1053 ret = ad7280_channel_init(st, spi->irq > 0); in ad7280_probe()
1057 indio_dev->num_channels = ret; in ad7280_probe()
1058 indio_dev->channels = st->channels; in ad7280_probe()
1059 if (spi->irq > 0) { in ad7280_probe()
1066 ret = ad7280_write(st, ad7280a_devaddr(st->slave_num), in ad7280_probe()
1070 st->chain_last_alert_ignore)); in ad7280_probe()
1074 ret = devm_request_threaded_irq(dev, spi->irq, in ad7280_probe()
1079 indio_dev->name, in ad7280_probe()
1084 indio_dev->info = &ad7280_info; in ad7280_probe()
1086 indio_dev->info = &ad7280_info_no_irq; in ad7280_probe()