• Home
  • Raw
  • Download

Lines Matching +full:cold +full:- +full:junction +full:- +full:handle

1 // SPDX-License-Identifier: GPL-2.0
3 * Analog Devices LTC2983 Multi-Sensor Digital Temperature Measurement System
42 (((chan - 1) * 4) + LTC2983_CHAN_ASSIGN_START_REG)
44 (((chan - 1) * 4) + LTC2983_TEMP_RES_START_REG)
112 /* cold junction for thermocouples and rsense for rtd's and thermistor's */
274 * instance a resolution of 2^-10 means we have 10 fractional bits.
288 s64 __res = -(s32)val; in __convert_to_raw_sign()
292 return (u32)-__res; in __convert_to_raw_sign()
299 const struct device *dev = &st->spi->dev; in __ltc2983_fault_handler()
303 return -EIO; in __ltc2983_fault_handler()
316 u32 reg = LTC2983_CHAN_START_ADDR(sensor->chan); in __ltc2983_chan_assign_common()
319 chan_val |= LTC2983_CHAN_TYPE(sensor->type); in __ltc2983_chan_assign_common()
320 dev_dbg(&st->spi->dev, "Assign reg:0x%04X, val:0x%08X\n", reg, in __ltc2983_chan_assign_common()
323 return regmap_bulk_write(st->regmap, reg, &__chan_val, in __ltc2983_chan_assign_common()
332 u8 mult = custom->is_steinhart ? LTC2983_CUSTOM_STEINHART_ENTRY_SZ : in __ltc2983_chan_custom_sensor_assign()
334 const struct device *dev = &st->spi->dev; in __ltc2983_chan_custom_sensor_assign()
336 * custom->size holds the raw size of the table. However, when in __ltc2983_chan_custom_sensor_assign()
341 const u8 len = custom->is_steinhart ? 0 : in __ltc2983_chan_custom_sensor_assign()
342 (custom->size / LTC2983_CUSTOM_SENSOR_ENTRY_SZ) - 1; in __ltc2983_chan_custom_sensor_assign()
347 if (custom->offset < 0) { in __ltc2983_chan_custom_sensor_assign()
354 if (st->custom_table_size + custom->size > in __ltc2983_chan_custom_sensor_assign()
355 (LTC2983_CUST_SENS_TBL_END_REG - in __ltc2983_chan_custom_sensor_assign()
359 st->custom_table_size, in __ltc2983_chan_custom_sensor_assign()
360 custom->size); in __ltc2983_chan_custom_sensor_assign()
361 return -EINVAL; in __ltc2983_chan_custom_sensor_assign()
364 custom->offset = st->custom_table_size / in __ltc2983_chan_custom_sensor_assign()
366 st->custom_table_size += custom->size; in __ltc2983_chan_custom_sensor_assign()
369 reg = (custom->offset * mult) + LTC2983_CUST_SENS_TBL_START_REG; in __ltc2983_chan_custom_sensor_assign()
372 *chan_val |= LTC2983_CUSTOM_ADDR(custom->offset); in __ltc2983_chan_custom_sensor_assign()
374 reg, custom->offset, in __ltc2983_chan_custom_sensor_assign()
375 custom->size); in __ltc2983_chan_custom_sensor_assign()
377 return regmap_bulk_write(st->regmap, reg, custom->table, custom->size); in __ltc2983_chan_custom_sensor_assign()
390 struct device *dev = &st->spi->dev; in __ltc2983_custom_sensor_new()
402 return ERR_PTR(-EINVAL); in __ltc2983_custom_sensor_new()
407 return ERR_PTR(-ENOMEM); in __ltc2983_custom_sensor_new()
409 new_custom->size = n_entries * n_size; in __ltc2983_custom_sensor_new()
411 if (is_steinhart && new_custom->size != LTC2983_CUSTOM_STEINHART_SIZE) { in __ltc2983_custom_sensor_new()
413 new_custom->size); in __ltc2983_custom_sensor_new()
414 return ERR_PTR(-EINVAL); in __ltc2983_custom_sensor_new()
417 if (st->custom_table_size + new_custom->size > in __ltc2983_custom_sensor_new()
418 (LTC2983_CUST_SENS_TBL_END_REG - in __ltc2983_custom_sensor_new()
421 st->custom_table_size, new_custom->size); in __ltc2983_custom_sensor_new()
422 return ERR_PTR(-EINVAL); in __ltc2983_custom_sensor_new()
426 new_custom->table = devm_kzalloc(dev, new_custom->size, GFP_KERNEL); in __ltc2983_custom_sensor_new()
427 if (!new_custom->table) in __ltc2983_custom_sensor_new()
428 return ERR_PTR(-ENOMEM); in __ltc2983_custom_sensor_new()
456 new_custom->table[tbl++] = in __ltc2983_custom_sensor_new()
457 temp >> (8 * (n_size - j - 1)); in __ltc2983_custom_sensor_new()
460 new_custom->is_steinhart = is_steinhart; in __ltc2983_custom_sensor_new()
465 * sure that sensor_addr - 0x250(start address) is a multiple of 4 in __ltc2983_custom_sensor_new()
468 * also a multiple of 6, we guarantee that the first non-steinhart in __ltc2983_custom_sensor_new()
473 new_custom->offset = st->custom_table_size / in __ltc2983_custom_sensor_new()
475 st->custom_table_size += new_custom->size; in __ltc2983_custom_sensor_new()
478 new_custom->offset = -1; in __ltc2983_custom_sensor_new()
506 chan_val = LTC2983_CHAN_ASSIGN(thermo->cold_junction_chan); in ltc2983_thermocouple_assign_chan()
507 chan_val |= LTC2983_THERMOCOUPLE_CFG(thermo->sensor_config); in ltc2983_thermocouple_assign_chan()
509 if (thermo->custom) { in ltc2983_thermocouple_assign_chan()
512 ret = __ltc2983_chan_custom_sensor_assign(st, thermo->custom, in ltc2983_thermocouple_assign_chan()
526 chan_val = LTC2983_CHAN_ASSIGN(rtd->r_sense_chan); in ltc2983_rtd_assign_chan()
527 chan_val |= LTC2983_RTD_CFG(rtd->sensor_config); in ltc2983_rtd_assign_chan()
528 chan_val |= LTC2983_RTD_EXC_CURRENT(rtd->excitation_current); in ltc2983_rtd_assign_chan()
529 chan_val |= LTC2983_RTD_CURVE(rtd->rtd_curve); in ltc2983_rtd_assign_chan()
531 if (rtd->custom) { in ltc2983_rtd_assign_chan()
534 ret = __ltc2983_chan_custom_sensor_assign(st, rtd->custom, in ltc2983_rtd_assign_chan()
548 chan_val = LTC2983_CHAN_ASSIGN(thermistor->r_sense_chan); in ltc2983_thermistor_assign_chan()
549 chan_val |= LTC2983_THERMISTOR_CFG(thermistor->sensor_config); in ltc2983_thermistor_assign_chan()
551 LTC2983_THERMISTOR_EXC_CURRENT(thermistor->excitation_current); in ltc2983_thermistor_assign_chan()
553 if (thermistor->custom) { in ltc2983_thermistor_assign_chan()
557 thermistor->custom, in ltc2983_thermistor_assign_chan()
571 chan_val = LTC2983_DIODE_CFG(diode->sensor_config); in ltc2983_diode_assign_chan()
572 chan_val |= LTC2983_DIODE_EXC_CURRENT(diode->excitation_current); in ltc2983_diode_assign_chan()
573 chan_val |= LTC2983_DIODE_IDEAL_FACTOR(diode->ideal_factor_value); in ltc2983_diode_assign_chan()
584 chan_val = LTC2983_R_SENSE_VAL(rsense->r_sense_val); in ltc2983_r_sense_assign_chan()
595 chan_val = LTC2983_ADC_SINGLE_ENDED(adc->single_ended); in ltc2983_adc_assign_chan()
610 thermo = devm_kzalloc(&st->spi->dev, sizeof(*thermo), GFP_KERNEL); in ltc2983_thermocouple_new()
612 return ERR_PTR(-ENOMEM); in ltc2983_thermocouple_new()
614 if (of_property_read_bool(child, "adi,single-ended")) in ltc2983_thermocouple_new()
615 thermo->sensor_config = LTC2983_THERMOCOUPLE_SGL(1); in ltc2983_thermocouple_new()
617 ret = of_property_read_u32(child, "adi,sensor-oc-current-microamp", in ltc2983_thermocouple_new()
622 thermo->sensor_config |= in ltc2983_thermocouple_new()
626 thermo->sensor_config |= in ltc2983_thermocouple_new()
630 thermo->sensor_config |= in ltc2983_thermocouple_new()
634 thermo->sensor_config |= in ltc2983_thermocouple_new()
638 dev_err(&st->spi->dev, in ltc2983_thermocouple_new()
640 return ERR_PTR(-EINVAL); in ltc2983_thermocouple_new()
643 thermo->sensor_config |= LTC2983_THERMOCOUPLE_OC_CHECK(1); in ltc2983_thermocouple_new()
646 if (!(thermo->sensor_config & LTC2983_THERMOCOUPLE_DIFF_MASK) && in ltc2983_thermocouple_new()
647 sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { in ltc2983_thermocouple_new()
648 dev_err(&st->spi->dev, in ltc2983_thermocouple_new()
650 sensor->chan); in ltc2983_thermocouple_new()
651 return ERR_PTR(-EINVAL); in ltc2983_thermocouple_new()
654 phandle = of_parse_phandle(child, "adi,cold-junction-handle", 0); in ltc2983_thermocouple_new()
659 &thermo->cold_junction_chan); in ltc2983_thermocouple_new()
665 dev_err(&st->spi->dev, "Property reg must be given\n"); in ltc2983_thermocouple_new()
667 return ERR_PTR(-EINVAL); in ltc2983_thermocouple_new()
672 if (sensor->type == LTC2983_SENSOR_THERMOCOUPLE_CUSTOM) { in ltc2983_thermocouple_new()
673 const char *propname = "adi,custom-thermocouple"; in ltc2983_thermocouple_new()
675 thermo->custom = __ltc2983_custom_sensor_new(st, child, in ltc2983_thermocouple_new()
678 if (IS_ERR(thermo->custom)) { in ltc2983_thermocouple_new()
680 return ERR_CAST(thermo->custom); in ltc2983_thermocouple_new()
685 thermo->sensor.fault_handler = ltc2983_thermocouple_fault_handler; in ltc2983_thermocouple_new()
686 thermo->sensor.assign_chan = ltc2983_thermocouple_assign_chan; in ltc2983_thermocouple_new()
689 return &thermo->sensor; in ltc2983_thermocouple_new()
698 struct device *dev = &st->spi->dev; in ltc2983_rtd_new()
704 return ERR_PTR(-ENOMEM); in ltc2983_rtd_new()
706 phandle = of_parse_phandle(child, "adi,rsense-handle", 0); in ltc2983_rtd_new()
708 dev_err(dev, "Property adi,rsense-handle missing or invalid"); in ltc2983_rtd_new()
709 return ERR_PTR(-EINVAL); in ltc2983_rtd_new()
712 ret = of_property_read_u32(phandle, "reg", &rtd->r_sense_chan); in ltc2983_rtd_new()
718 ret = of_property_read_u32(child, "adi,number-of-wires", &n_wires); in ltc2983_rtd_new()
722 rtd->sensor_config = LTC2983_RTD_N_WIRES(0); in ltc2983_rtd_new()
725 rtd->sensor_config = LTC2983_RTD_N_WIRES(1); in ltc2983_rtd_new()
728 rtd->sensor_config = LTC2983_RTD_N_WIRES(2); in ltc2983_rtd_new()
732 rtd->sensor_config = LTC2983_RTD_N_WIRES(3); in ltc2983_rtd_new()
736 ret = -EINVAL; in ltc2983_rtd_new()
741 if (of_property_read_bool(child, "adi,rsense-share")) { in ltc2983_rtd_new()
743 if (of_property_read_bool(child, "adi,current-rotate")) { in ltc2983_rtd_new()
747 ret = -EINVAL; in ltc2983_rtd_new()
750 rtd->sensor_config |= LTC2983_RTD_C_ROTATE(1); in ltc2983_rtd_new()
752 rtd->sensor_config |= LTC2983_RTD_R_SHARE(1); in ltc2983_rtd_new()
760 * <=1 since chanel - 1 and channel - 2 are used. in ltc2983_rtd_new()
762 if (rtd->sensor_config & LTC2983_RTD_4_WIRE_MASK) { in ltc2983_rtd_new()
763 /* 4-wire */ in ltc2983_rtd_new()
767 if (rtd->sensor_config & LTC2983_RTD_ROTATION_MASK) in ltc2983_rtd_new()
768 max = LTC2983_MAX_CHANNELS_NR - 1; in ltc2983_rtd_new()
770 if (((rtd->sensor_config & LTC2983_RTD_KELVIN_R_SENSE_MASK) in ltc2983_rtd_new()
772 (rtd->r_sense_chan <= min)) { in ltc2983_rtd_new()
776 rtd->r_sense_chan); in ltc2983_rtd_new()
778 ret = -EINVAL; in ltc2983_rtd_new()
782 if (sensor->chan < min || sensor->chan > max) { in ltc2983_rtd_new()
784 sensor->chan); in ltc2983_rtd_new()
786 ret = -EINVAL; in ltc2983_rtd_new()
791 if (sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { in ltc2983_rtd_new()
792 dev_err(&st->spi->dev, in ltc2983_rtd_new()
793 "Invalid chann:%d for RTD", sensor->chan); in ltc2983_rtd_new()
795 ret = -EINVAL; in ltc2983_rtd_new()
801 if (sensor->type == LTC2983_SENSOR_RTD_CUSTOM) { in ltc2983_rtd_new()
802 rtd->custom = __ltc2983_custom_sensor_new(st, child, in ltc2983_rtd_new()
803 "adi,custom-rtd", in ltc2983_rtd_new()
805 if (IS_ERR(rtd->custom)) { in ltc2983_rtd_new()
807 return ERR_CAST(rtd->custom); in ltc2983_rtd_new()
812 rtd->sensor.fault_handler = ltc2983_common_fault_handler; in ltc2983_rtd_new()
813 rtd->sensor.assign_chan = ltc2983_rtd_assign_chan; in ltc2983_rtd_new()
815 ret = of_property_read_u32(child, "adi,excitation-current-microamp", in ltc2983_rtd_new()
819 rtd->excitation_current = 1; in ltc2983_rtd_new()
823 rtd->excitation_current = 0x01; in ltc2983_rtd_new()
826 rtd->excitation_current = 0x02; in ltc2983_rtd_new()
829 rtd->excitation_current = 0x03; in ltc2983_rtd_new()
832 rtd->excitation_current = 0x04; in ltc2983_rtd_new()
835 rtd->excitation_current = 0x05; in ltc2983_rtd_new()
838 rtd->excitation_current = 0x06; in ltc2983_rtd_new()
841 rtd->excitation_current = 0x07; in ltc2983_rtd_new()
844 rtd->excitation_current = 0x08; in ltc2983_rtd_new()
847 dev_err(&st->spi->dev, in ltc2983_rtd_new()
850 ret = -EINVAL; in ltc2983_rtd_new()
855 of_property_read_u32(child, "adi,rtd-curve", &rtd->rtd_curve); in ltc2983_rtd_new()
858 return &rtd->sensor; in ltc2983_rtd_new()
870 struct device *dev = &st->spi->dev; in ltc2983_thermistor_new()
877 return ERR_PTR(-ENOMEM); in ltc2983_thermistor_new()
879 phandle = of_parse_phandle(child, "adi,rsense-handle", 0); in ltc2983_thermistor_new()
881 dev_err(dev, "Property adi,rsense-handle missing or invalid"); in ltc2983_thermistor_new()
882 return ERR_PTR(-EINVAL); in ltc2983_thermistor_new()
885 ret = of_property_read_u32(phandle, "reg", &thermistor->r_sense_chan); in ltc2983_thermistor_new()
891 if (of_property_read_bool(child, "adi,single-ended")) { in ltc2983_thermistor_new()
892 thermistor->sensor_config = LTC2983_THERMISTOR_SGL(1); in ltc2983_thermistor_new()
893 } else if (of_property_read_bool(child, "adi,rsense-share")) { in ltc2983_thermistor_new()
895 if (of_property_read_bool(child, "adi,current-rotate")) in ltc2983_thermistor_new()
896 thermistor->sensor_config = in ltc2983_thermistor_new()
899 thermistor->sensor_config = in ltc2983_thermistor_new()
903 if (!(thermistor->sensor_config & LTC2983_THERMISTOR_DIFF_MASK) && in ltc2983_thermistor_new()
904 sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { in ltc2983_thermistor_new()
905 dev_err(&st->spi->dev, in ltc2983_thermistor_new()
907 sensor->chan); in ltc2983_thermistor_new()
908 ret = -EINVAL; in ltc2983_thermistor_new()
913 if (sensor->type >= LTC2983_SENSOR_THERMISTOR_STEINHART) { in ltc2983_thermistor_new()
917 if (sensor->type == LTC2983_SENSOR_THERMISTOR_STEINHART) { in ltc2983_thermistor_new()
919 propname = "adi,custom-steinhart"; in ltc2983_thermistor_new()
921 propname = "adi,custom-thermistor"; in ltc2983_thermistor_new()
924 thermistor->custom = __ltc2983_custom_sensor_new(st, child, in ltc2983_thermistor_new()
928 if (IS_ERR(thermistor->custom)) { in ltc2983_thermistor_new()
930 return ERR_CAST(thermistor->custom); in ltc2983_thermistor_new()
934 thermistor->sensor.fault_handler = ltc2983_common_fault_handler; in ltc2983_thermistor_new()
935 thermistor->sensor.assign_chan = ltc2983_thermistor_assign_chan; in ltc2983_thermistor_new()
937 ret = of_property_read_u32(child, "adi,excitation-current-nanoamp", in ltc2983_thermistor_new()
941 if (sensor->type >= LTC2983_SENSOR_THERMISTOR_STEINHART) in ltc2983_thermistor_new()
943 thermistor->excitation_current = 0x03; in ltc2983_thermistor_new()
945 /* default to auto-range */ in ltc2983_thermistor_new()
946 thermistor->excitation_current = 0x0c; in ltc2983_thermistor_new()
951 if (sensor->type >= in ltc2983_thermistor_new()
953 dev_err(&st->spi->dev, in ltc2983_thermistor_new()
955 ret = -EINVAL; in ltc2983_thermistor_new()
958 thermistor->excitation_current = 0x0c; in ltc2983_thermistor_new()
961 thermistor->excitation_current = 0x01; in ltc2983_thermistor_new()
964 thermistor->excitation_current = 0x02; in ltc2983_thermistor_new()
967 thermistor->excitation_current = 0x03; in ltc2983_thermistor_new()
970 thermistor->excitation_current = 0x04; in ltc2983_thermistor_new()
973 thermistor->excitation_current = 0x05; in ltc2983_thermistor_new()
976 thermistor->excitation_current = 0x06; in ltc2983_thermistor_new()
979 thermistor->excitation_current = 0x07; in ltc2983_thermistor_new()
982 thermistor->excitation_current = 0x08; in ltc2983_thermistor_new()
985 thermistor->excitation_current = 0x09; in ltc2983_thermistor_new()
988 thermistor->excitation_current = 0x0a; in ltc2983_thermistor_new()
991 thermistor->excitation_current = 0x0b; in ltc2983_thermistor_new()
994 dev_err(&st->spi->dev, in ltc2983_thermistor_new()
997 ret = -EINVAL; in ltc2983_thermistor_new()
1003 return &thermistor->sensor; in ltc2983_thermistor_new()
1018 diode = devm_kzalloc(&st->spi->dev, sizeof(*diode), GFP_KERNEL); in ltc2983_diode_new()
1020 return ERR_PTR(-ENOMEM); in ltc2983_diode_new()
1022 if (of_property_read_bool(child, "adi,single-ended")) in ltc2983_diode_new()
1023 diode->sensor_config = LTC2983_DIODE_SGL(1); in ltc2983_diode_new()
1025 if (of_property_read_bool(child, "adi,three-conversion-cycles")) in ltc2983_diode_new()
1026 diode->sensor_config |= LTC2983_DIODE_3_CONV_CYCLE(1); in ltc2983_diode_new()
1028 if (of_property_read_bool(child, "adi,average-on")) in ltc2983_diode_new()
1029 diode->sensor_config |= LTC2983_DIODE_AVERAGE_ON(1); in ltc2983_diode_new()
1032 if (!(diode->sensor_config & LTC2983_DIODE_DIFF_MASK) && in ltc2983_diode_new()
1033 sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { in ltc2983_diode_new()
1034 dev_err(&st->spi->dev, in ltc2983_diode_new()
1036 sensor->chan); in ltc2983_diode_new()
1037 return ERR_PTR(-EINVAL); in ltc2983_diode_new()
1040 diode->sensor.fault_handler = ltc2983_common_fault_handler; in ltc2983_diode_new()
1041 diode->sensor.assign_chan = ltc2983_diode_assign_chan; in ltc2983_diode_new()
1043 ret = of_property_read_u32(child, "adi,excitation-current-microamp", in ltc2983_diode_new()
1048 diode->excitation_current = 0x00; in ltc2983_diode_new()
1051 diode->excitation_current = 0x01; in ltc2983_diode_new()
1054 diode->excitation_current = 0x02; in ltc2983_diode_new()
1057 diode->excitation_current = 0x03; in ltc2983_diode_new()
1060 dev_err(&st->spi->dev, in ltc2983_diode_new()
1063 return ERR_PTR(-EINVAL); in ltc2983_diode_new()
1067 of_property_read_u32(child, "adi,ideal-factor-value", &temp); in ltc2983_diode_new()
1070 diode->ideal_factor_value = __convert_to_raw(temp, 1048576); in ltc2983_diode_new()
1072 return &diode->sensor; in ltc2983_diode_new()
1083 rsense = devm_kzalloc(&st->spi->dev, sizeof(*rsense), GFP_KERNEL); in ltc2983_r_sense_new()
1085 return ERR_PTR(-ENOMEM); in ltc2983_r_sense_new()
1088 if (sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { in ltc2983_r_sense_new()
1089 dev_err(&st->spi->dev, "Invalid chann:%d for r_sense", in ltc2983_r_sense_new()
1090 sensor->chan); in ltc2983_r_sense_new()
1091 return ERR_PTR(-EINVAL); in ltc2983_r_sense_new()
1094 ret = of_property_read_u32(child, "adi,rsense-val-milli-ohms", &temp); in ltc2983_r_sense_new()
1096 dev_err(&st->spi->dev, "Property adi,rsense-val-milli-ohms missing\n"); in ltc2983_r_sense_new()
1097 return ERR_PTR(-EINVAL); in ltc2983_r_sense_new()
1100 * Times 1000 because we have milli-ohms and __convert_to_raw in ltc2983_r_sense_new()
1105 rsense->r_sense_val = __convert_to_raw((u64)temp * 1000, 1024); in ltc2983_r_sense_new()
1108 rsense->sensor.assign_chan = ltc2983_r_sense_assign_chan; in ltc2983_r_sense_new()
1110 return &rsense->sensor; in ltc2983_r_sense_new()
1119 adc = devm_kzalloc(&st->spi->dev, sizeof(*adc), GFP_KERNEL); in ltc2983_adc_new()
1121 return ERR_PTR(-ENOMEM); in ltc2983_adc_new()
1123 if (of_property_read_bool(child, "adi,single-ended")) in ltc2983_adc_new()
1124 adc->single_ended = true; in ltc2983_adc_new()
1126 if (!adc->single_ended && in ltc2983_adc_new()
1127 sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { in ltc2983_adc_new()
1128 dev_err(&st->spi->dev, "Invalid chan:%d for differential adc\n", in ltc2983_adc_new()
1129 sensor->chan); in ltc2983_adc_new()
1130 return ERR_PTR(-EINVAL); in ltc2983_adc_new()
1133 adc->sensor.assign_chan = ltc2983_adc_assign_chan; in ltc2983_adc_new()
1134 adc->sensor.fault_handler = ltc2983_common_fault_handler; in ltc2983_adc_new()
1136 return &adc->sensor; in ltc2983_adc_new()
1147 start_conversion |= LTC2983_STATUS_CHAN_SEL(sensor->chan); in ltc2983_chan_read()
1148 dev_dbg(&st->spi->dev, "Start conversion on chan:%d, status:%02X\n", in ltc2983_chan_read()
1149 sensor->chan, start_conversion); in ltc2983_chan_read()
1151 ret = regmap_write(st->regmap, LTC2983_STATUS_REG, start_conversion); in ltc2983_chan_read()
1155 reinit_completion(&st->completion); in ltc2983_chan_read()
1162 time = wait_for_completion_timeout(&st->completion, in ltc2983_chan_read()
1165 dev_warn(&st->spi->dev, "Conversion timed out\n"); in ltc2983_chan_read()
1166 return -ETIMEDOUT; in ltc2983_chan_read()
1170 ret = regmap_bulk_read(st->regmap, LTC2983_CHAN_RES_ADDR(sensor->chan), in ltc2983_chan_read()
1171 &st->temp, sizeof(st->temp)); in ltc2983_chan_read()
1175 *val = __be32_to_cpu(st->temp); in ltc2983_chan_read()
1178 dev_err(&st->spi->dev, "Invalid conversion detected\n"); in ltc2983_chan_read()
1179 return -EIO; in ltc2983_chan_read()
1182 ret = sensor->fault_handler(st, *val); in ltc2983_chan_read()
1198 if (chan->address >= st->num_channels) { in ltc2983_read_raw()
1199 dev_err(&st->spi->dev, "Invalid chan address:%ld", in ltc2983_read_raw()
1200 chan->address); in ltc2983_read_raw()
1201 return -EINVAL; in ltc2983_read_raw()
1206 mutex_lock(&st->lock); in ltc2983_read_raw()
1207 ret = ltc2983_chan_read(st, st->sensors[chan->address], val); in ltc2983_read_raw()
1208 mutex_unlock(&st->lock); in ltc2983_read_raw()
1211 switch (chan->type) { in ltc2983_read_raw()
1225 return -EINVAL; in ltc2983_read_raw()
1229 return -EINVAL; in ltc2983_read_raw()
1240 return regmap_read(st->regmap, reg, readval); in ltc2983_reg_access()
1242 return regmap_write(st->regmap, reg, writeval); in ltc2983_reg_access()
1249 complete(&st->completion); in ltc2983_irq_handler()
1268 struct device *dev = &st->spi->dev; in ltc2983_parse_dt()
1271 of_property_read_u32(dev->of_node, "adi,mux-delay-config-us", in ltc2983_parse_dt()
1272 &st->mux_delay_config); in ltc2983_parse_dt()
1274 of_property_read_u32(dev->of_node, "adi,filter-notch-freq", in ltc2983_parse_dt()
1275 &st->filter_notch_freq); in ltc2983_parse_dt()
1277 st->num_channels = of_get_available_child_count(dev->of_node); in ltc2983_parse_dt()
1278 st->sensors = devm_kcalloc(dev, st->num_channels, sizeof(*st->sensors), in ltc2983_parse_dt()
1280 if (!st->sensors) in ltc2983_parse_dt()
1281 return -ENOMEM; in ltc2983_parse_dt()
1283 st->iio_channels = st->num_channels; in ltc2983_parse_dt()
1284 for_each_available_child_of_node(dev->of_node, child) { in ltc2983_parse_dt()
1296 ret = -EINVAL; in ltc2983_parse_dt()
1301 ret = -EINVAL; in ltc2983_parse_dt()
1306 ret = of_property_read_u32(child, "adi,sensor-type", in ltc2983_parse_dt()
1310 "adi,sensor-type property must given for child nodes\n"); in ltc2983_parse_dt()
1320 st->sensors[chan] = ltc2983_thermocouple_new(child, st, in ltc2983_parse_dt()
1324 st->sensors[chan] = ltc2983_rtd_new(child, st, &sensor); in ltc2983_parse_dt()
1327 st->sensors[chan] = ltc2983_thermistor_new(child, st, in ltc2983_parse_dt()
1330 st->sensors[chan] = ltc2983_diode_new(child, st, in ltc2983_parse_dt()
1333 st->sensors[chan] = ltc2983_r_sense_new(child, st, in ltc2983_parse_dt()
1336 st->iio_channels--; in ltc2983_parse_dt()
1338 st->sensors[chan] = ltc2983_adc_new(child, st, &sensor); in ltc2983_parse_dt()
1341 ret = -EINVAL; in ltc2983_parse_dt()
1345 if (IS_ERR(st->sensors[chan])) { in ltc2983_parse_dt()
1347 PTR_ERR(st->sensors[chan])); in ltc2983_parse_dt()
1348 ret = PTR_ERR(st->sensors[chan]); in ltc2983_parse_dt()
1352 st->sensors[chan]->chan = sensor.chan; in ltc2983_parse_dt()
1353 st->sensors[chan]->type = sensor.type; in ltc2983_parse_dt()
1371 ret = regmap_read_poll_timeout(st->regmap, LTC2983_STATUS_REG, status, in ltc2983_setup()
1375 dev_err(&st->spi->dev, "Device startup timed out\n"); in ltc2983_setup()
1379 st->iio_chan = devm_kzalloc(&st->spi->dev, in ltc2983_setup()
1380 st->iio_channels * sizeof(*st->iio_chan), in ltc2983_setup()
1383 if (!st->iio_chan) in ltc2983_setup()
1384 return -ENOMEM; in ltc2983_setup()
1386 ret = regmap_update_bits(st->regmap, LTC2983_GLOBAL_CONFIG_REG, in ltc2983_setup()
1388 LTC2983_NOTCH_FREQ(st->filter_notch_freq)); in ltc2983_setup()
1392 ret = regmap_write(st->regmap, LTC2983_MUX_CONFIG_REG, in ltc2983_setup()
1393 st->mux_delay_config); in ltc2983_setup()
1397 for (chan = 0; chan < st->num_channels; chan++) { in ltc2983_setup()
1400 ret = st->sensors[chan]->assign_chan(st, st->sensors[chan]); in ltc2983_setup()
1406 * re-configure the device channels. in ltc2983_setup()
1409 if (st->sensors[chan]->type == LTC2983_SENSOR_SENSE_RESISTOR || in ltc2983_setup()
1414 if (st->sensors[chan]->type != LTC2983_SENSOR_DIRECT_ADC) { in ltc2983_setup()
1426 st->iio_chan[iio_idx++] = LTC2983_CHAN(chan_type, (*iio_chan)++, in ltc2983_setup()
1473 const char *name = spi_get_device_id(spi)->name; in ltc2983_probe()
1476 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ltc2983_probe()
1478 return -ENOMEM; in ltc2983_probe()
1482 st->regmap = devm_regmap_init_spi(spi, &ltc2983_regmap_config); in ltc2983_probe()
1483 if (IS_ERR(st->regmap)) { in ltc2983_probe()
1484 dev_err(&spi->dev, "Failed to initialize regmap\n"); in ltc2983_probe()
1485 return PTR_ERR(st->regmap); in ltc2983_probe()
1488 mutex_init(&st->lock); in ltc2983_probe()
1489 init_completion(&st->completion); in ltc2983_probe()
1490 st->spi = spi; in ltc2983_probe()
1501 ret = devm_request_irq(&spi->dev, spi->irq, ltc2983_irq_handler, in ltc2983_probe()
1504 dev_err(&spi->dev, "failed to request an irq, %d", ret); in ltc2983_probe()
1508 indio_dev->name = name; in ltc2983_probe()
1509 indio_dev->num_channels = st->iio_channels; in ltc2983_probe()
1510 indio_dev->channels = st->iio_chan; in ltc2983_probe()
1511 indio_dev->modes = INDIO_DIRECT_MODE; in ltc2983_probe()
1512 indio_dev->info = &ltc2983_iio_info; in ltc2983_probe()
1514 return devm_iio_device_register(&spi->dev, indio_dev); in ltc2983_probe()
1523 regmap_read(st->regmap, LTC2983_STATUS_REG, &dummy); in ltc2983_resume()
1524 /* we need to re-assign the channels */ in ltc2983_resume()
1532 return regmap_write(st->regmap, LTC2983_STATUS_REG, LTC2983_SLEEP); in ltc2983_suspend()