Lines Matching +full:thermistor +full:- +full:termination

1 // SPDX-License-Identifier: GPL-2.0
128 #define AD7280A_NUM_CH (AD7280A_AUX_ADC_6_REG - \
134 (c) - AD7280A_CELLS_PER_DEV)
142 /* 5-bit device address is sent LSB first */
202 unsigned char crc = ad7280_calc_crc8(st->crc_tab, val >> 10); in ad7280_check_crc()
205 return -EIO; in ad7280_check_crc()
220 if (st->readback_delay_us < 50) in ad7280_delay()
221 udelay(st->readback_delay_us); in ad7280_delay()
230 .tx_buf = &st->tx, in __ad7280_read32()
231 .rx_buf = &st->rx, in __ad7280_read32()
232 .len = sizeof(st->tx), in __ad7280_read32()
235 st->tx = cpu_to_be32(AD7280A_READ_TXVAL); in __ad7280_read32()
237 ret = spi_sync_transfer(st->spi, &t, 1); in __ad7280_read32()
241 *val = be32_to_cpu(st->rx); in __ad7280_read32()
255 ad7280_calc_crc8(st->crc_tab, reg >> 11)); in ad7280_write()
259 st->tx = cpu_to_be32(reg); in ad7280_write()
261 return spi_write(st->spi, &st->tx, sizeof(st->tx)); in ad7280_write()
277 st->oversampling_ratio)); in ad7280_read_reg()
288 st->oversampling_ratio)); in ad7280_read_reg()
303 return -EIO; in ad7280_read_reg()
307 return -EFAULT; in ad7280_read_reg()
329 st->oversampling_ratio)); in ad7280_read_channel()
341 st->oversampling_ratio)); in ad7280_read_channel()
352 return -EIO; in ad7280_read_channel()
356 return -EFAULT; in ad7280_read_channel()
380 st->oversampling_ratio)); in ad7280_read_all_channels()
392 return -EIO; in ad7280_read_all_channels()
411 FIELD_PREP(AD7280A_CTRL_HB_CONV_AVG_MSK, st->oversampling_ratio)); in ad7280_sw_power_down()
424 st->ctrl_lb); in ad7280_chain_setup()
433 st->ctrl_lb); in ad7280_chain_setup()
448 return n - 1; in ad7280_chain_setup()
451 ret = -EIO; in ad7280_chain_setup()
456 ret = -EIO; in ad7280_chain_setup()
460 ret = -EFAULT; in ad7280_chain_setup()
465 FIELD_PREP(AD7280A_CTRL_HB_CONV_AVG_MSK, st->oversampling_ratio)); in ad7280_chain_setup()
477 !!(st->cb_mask[chan->address >> 8] & in ad7280_show_balance_sw()
478 BIT(chan->address & 0xFF))); in ad7280_show_balance_sw()
495 devaddr = chan->address >> 8; in ad7280_store_balance_sw()
496 ch = chan->address & 0xFF; in ad7280_store_balance_sw()
498 mutex_lock(&st->lock); in ad7280_store_balance_sw()
500 st->cb_mask[devaddr] |= BIT(ch); in ad7280_store_balance_sw()
502 st->cb_mask[devaddr] &= ~BIT(ch); in ad7280_store_balance_sw()
506 st->cb_mask[devaddr])); in ad7280_store_balance_sw()
507 mutex_unlock(&st->lock); in ad7280_store_balance_sw()
521 mutex_lock(&st->lock); in ad7280_show_balance_timer()
522 ret = ad7280_read_reg(st, chan->address >> 8, in ad7280_show_balance_timer()
523 (chan->address & 0xFF) + AD7280A_CB1_TIMER_REG); in ad7280_show_balance_timer()
524 mutex_unlock(&st->lock); in ad7280_show_balance_timer()
551 return -EINVAL; in ad7280_store_balance_timer()
553 mutex_lock(&st->lock); in ad7280_store_balance_timer()
554 ret = ad7280_write(st, chan->address >> 8, in ad7280_store_balance_timer()
555 (chan->address & 0xFF) + AD7280A_CB1_TIMER_REG, 0, in ad7280_store_balance_timer()
557 mutex_unlock(&st->lock); in ad7280_store_balance_timer()
592 chan->type = IIO_VOLTAGE; in ad7280_voltage_channel_init()
593 chan->differential = 1; in ad7280_voltage_channel_init()
594 chan->channel = i; in ad7280_voltage_channel_init()
595 chan->channel2 = chan->channel + 1; in ad7280_voltage_channel_init()
597 chan->event_spec = ad7280_events; in ad7280_voltage_channel_init()
598 chan->num_event_specs = ARRAY_SIZE(ad7280_events); in ad7280_voltage_channel_init()
600 chan->ext_info = ad7280_cell_ext_info; in ad7280_voltage_channel_init()
606 chan->type = IIO_TEMP; in ad7280_temp_channel_init()
607 chan->channel = i; in ad7280_temp_channel_init()
609 chan->event_spec = ad7280_events; in ad7280_temp_channel_init()
610 chan->num_event_specs = ARRAY_SIZE(ad7280_events); in ad7280_temp_channel_init()
617 chan->indexed = 1; in ad7280_common_fields_init()
618 chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); in ad7280_common_fields_init()
619 chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE); in ad7280_common_fields_init()
620 chan->info_mask_shared_by_all = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO); in ad7280_common_fields_init()
621 chan->address = addr; in ad7280_common_fields_init()
622 chan->scan_index = cnt; in ad7280_common_fields_init()
623 chan->scan_type.sign = 'u'; in ad7280_common_fields_init()
624 chan->scan_type.realbits = 12; in ad7280_common_fields_init()
625 chan->scan_type.storagebits = 32; in ad7280_common_fields_init()
631 chan->type = IIO_VOLTAGE; in ad7280_total_voltage_channel_init()
632 chan->differential = 1; in ad7280_total_voltage_channel_init()
633 chan->channel = 0; in ad7280_total_voltage_channel_init()
634 chan->channel2 = dev * AD7280A_CELLS_PER_DEV; in ad7280_total_voltage_channel_init()
635 chan->address = AD7280A_ALL_CELLS; in ad7280_total_voltage_channel_init()
636 chan->indexed = 1; in ad7280_total_voltage_channel_init()
637 chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); in ad7280_total_voltage_channel_init()
638 chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE); in ad7280_total_voltage_channel_init()
639 chan->scan_index = cnt; in ad7280_total_voltage_channel_init()
640 chan->scan_type.sign = 'u'; in ad7280_total_voltage_channel_init()
641 chan->scan_type.realbits = 32; in ad7280_total_voltage_channel_init()
642 chan->scan_type.storagebits = 32; in ad7280_total_voltage_channel_init()
652 chan = &st->channels[*cnt]; in ad7280_init_dev_channels()
673 st->channels = devm_kcalloc(&st->spi->dev, (st->slave_num + 1) * 12 + 1, in ad7280_channel_init()
674 sizeof(*st->channels), GFP_KERNEL); in ad7280_channel_init()
675 if (!st->channels) in ad7280_channel_init()
676 return -ENOMEM; in ad7280_channel_init()
678 for (dev = 0; dev <= st->slave_num; dev++) in ad7280_channel_init()
681 ad7280_total_voltage_channel_init(&st->channels[cnt], cnt, dev); in ad7280_channel_init()
694 switch (chan->type) { in ad7280a_read_thresh()
698 *val = 1000 + (st->cell_threshhigh * 1568L) / 100; in ad7280a_read_thresh()
701 *val = 1000 + (st->cell_threshlow * 1568L) / 100; in ad7280a_read_thresh()
704 return -EINVAL; in ad7280a_read_thresh()
710 *val = ((st->aux_threshhigh) * 196L) / 10; in ad7280a_read_thresh()
713 *val = (st->aux_threshlow * 196L) / 10; in ad7280a_read_thresh()
716 return -EINVAL; in ad7280a_read_thresh()
720 return -EINVAL; in ad7280a_read_thresh()
737 return -EINVAL; in ad7280a_write_thresh()
739 mutex_lock(&st->lock); in ad7280a_write_thresh()
740 switch (chan->type) { in ad7280a_write_thresh()
742 value = ((val - 1000) * 100) / 1568; /* LSB 15.68mV */ in ad7280a_write_thresh()
751 st->cell_threshhigh = value; in ad7280a_write_thresh()
759 st->cell_threshlow = value; in ad7280a_write_thresh()
762 ret = -EINVAL; in ad7280a_write_thresh()
776 st->aux_threshhigh = value; in ad7280a_write_thresh()
784 st->aux_threshlow = value; in ad7280a_write_thresh()
787 ret = -EINVAL; in ad7280a_write_thresh()
792 ret = -EINVAL; in ad7280a_write_thresh()
797 mutex_unlock(&st->lock); in ad7280a_write_thresh()
809 channels = kcalloc(st->scan_cnt, sizeof(*channels), GFP_KERNEL); in ad7280_event_handler()
813 ret = ad7280_read_all_channels(st, st->scan_cnt, channels); in ad7280_event_handler()
817 for (i = 0; i < st->scan_cnt; i++) { in ad7280_event_handler()
823 if (val >= st->cell_threshhigh) { in ad7280_event_handler()
830 } else if (val <= st->cell_threshlow) { in ad7280_event_handler()
839 if (val >= st->aux_threshhigh) { in ad7280_event_handler()
845 } else if (val <= st->aux_threshlow) { in ad7280_event_handler()
866 * tACQ + ((N - 1) * tDELAY) in ad7280_update_delay()
871 st->readback_delay_us = in ad7280_update_delay()
872 ((ad7280a_t_acq_ns[st->acquisition_time & 0x3] + 720) * in ad7280_update_delay()
873 (AD7280A_NUM_CH * ad7280a_n_avg[st->oversampling_ratio & 0x3])) - in ad7280_update_delay()
874 ad7280a_t_acq_ns[st->acquisition_time & 0x3] + st->slave_num * 250; in ad7280_update_delay()
877 st->readback_delay_us = DIV_ROUND_UP(st->readback_delay_us, 1000); in ad7280_update_delay()
878 st->readback_delay_us += 5; /* Add tWAIT */ in ad7280_update_delay()
892 mutex_lock(&st->lock); in ad7280_read_raw()
893 if (chan->address == AD7280A_ALL_CELLS) in ad7280_read_raw()
894 ret = ad7280_read_all_channels(st, st->scan_cnt, NULL); in ad7280_read_raw()
896 ret = ad7280_read_channel(st, chan->address >> 8, in ad7280_read_raw()
897 chan->address & 0xFF); in ad7280_read_raw()
898 mutex_unlock(&st->lock); in ad7280_read_raw()
907 if ((chan->address & 0xFF) <= AD7280A_CELL_VOLTAGE_6_REG) in ad7280_read_raw()
915 *val = ad7280a_n_avg[st->oversampling_ratio]; in ad7280_read_raw()
918 return -EINVAL; in ad7280_read_raw()
931 return -EINVAL; in ad7280_write_raw()
934 st->oversampling_ratio = i; in ad7280_write_raw()
939 return -EINVAL; in ad7280_write_raw()
941 return -EINVAL; in ad7280_write_raw()
959 struct device *dev = &spi->dev; in ad7280_probe()
966 return -ENOMEM; in ad7280_probe()
970 st->spi = spi; in ad7280_probe()
971 mutex_init(&st->lock); in ad7280_probe()
973 st->thermistor_term_en = in ad7280_probe()
974 device_property_read_bool(dev, "adi,thermistor-termination"); in ad7280_probe()
976 if (device_property_present(dev, "adi,acquisition-time-ns")) { in ad7280_probe()
979 ret = device_property_read_u32(dev, "adi,acquisition-time-ns", &val); in ad7280_probe()
985 st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_400ns; in ad7280_probe()
988 st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_800ns; in ad7280_probe()
991 st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_1200ns; in ad7280_probe()
994 st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_1600ns; in ad7280_probe()
998 return -EINVAL; in ad7280_probe()
1001 st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_400ns; in ad7280_probe()
1005 if (device_property_present(dev, "adi,voltage-alert-last-chan")) { in ad7280_probe()
1008 ret = device_property_read_u32(dev, "adi,voltage-alert-last-chan", &val); in ad7280_probe()
1014 st->chain_last_alert_ignore |= AD7280A_ALERT_REMOVE_VIN4_VIN5; in ad7280_probe()
1017 st->chain_last_alert_ignore |= AD7280A_ALERT_REMOVE_VIN5; in ad7280_probe()
1027 crc8_populate_msb(st->crc_tab, POLYNOM); in ad7280_probe()
1029 st->spi->max_speed_hz = AD7280A_MAX_SPI_CLK_HZ; in ad7280_probe()
1030 st->spi->mode = SPI_MODE_1; in ad7280_probe()
1031 spi_setup(st->spi); in ad7280_probe()
1033 st->ctrl_lb = FIELD_PREP(AD7280A_CTRL_LB_ACQ_TIME_MSK, st->acquisition_time) | in ad7280_probe()
1034 FIELD_PREP(AD7280A_CTRL_LB_THERMISTOR_MSK, st->thermistor_term_en); in ad7280_probe()
1035 st->oversampling_ratio = 0; /* No oversampling */ in ad7280_probe()
1041 st->slave_num = ret; in ad7280_probe()
1042 st->scan_cnt = (st->slave_num + 1) * AD7280A_NUM_CH; in ad7280_probe()
1043 st->cell_threshhigh = 0xFF; in ad7280_probe()
1044 st->aux_threshhigh = 0xFF; in ad7280_probe()
1052 indio_dev->name = spi_get_device_id(spi)->name; in ad7280_probe()
1053 indio_dev->modes = INDIO_DIRECT_MODE; in ad7280_probe()
1055 ret = ad7280_channel_init(st, spi->irq > 0); in ad7280_probe()
1059 indio_dev->num_channels = ret; in ad7280_probe()
1060 indio_dev->channels = st->channels; in ad7280_probe()
1061 if (spi->irq > 0) { in ad7280_probe()
1068 ret = ad7280_write(st, ad7280a_devaddr(st->slave_num), in ad7280_probe()
1072 st->chain_last_alert_ignore)); in ad7280_probe()
1076 ret = devm_request_threaded_irq(dev, spi->irq, in ad7280_probe()
1081 indio_dev->name, in ad7280_probe()
1086 indio_dev->info = &ad7280_info; in ad7280_probe()
1088 indio_dev->info = &ad7280_info_no_irq; in ad7280_probe()