Lines Matching +full:milli +full:- +full:ohms
1 // SPDX-License-Identifier: GPL-2.0
3 * Analog Devices LTC2983 Multi-Sensor Digital Temperature Measurement System
57 (((chan - 1) * 4) + LTC2983_CHAN_ASSIGN_START_REG)
59 (((chan - 1) * 4) + LTC2983_TEMP_RES_START_REG)
308 * instance a resolution of 2^-10 means we have 10 fractional bits.
322 s64 __res = -(s32)val; in __convert_to_raw_sign()
326 return (u32)-__res; in __convert_to_raw_sign()
333 const struct device *dev = &st->spi->dev; in __ltc2983_fault_handler()
337 return -EIO; in __ltc2983_fault_handler()
350 u32 reg = LTC2983_CHAN_START_ADDR(sensor->chan); in __ltc2983_chan_assign_common()
352 chan_val |= LTC2983_CHAN_TYPE(sensor->type); in __ltc2983_chan_assign_common()
353 dev_dbg(&st->spi->dev, "Assign reg:0x%04X, val:0x%08X\n", reg, in __ltc2983_chan_assign_common()
355 st->chan_val = cpu_to_be32(chan_val); in __ltc2983_chan_assign_common()
356 return regmap_bulk_write(st->regmap, reg, &st->chan_val, in __ltc2983_chan_assign_common()
357 sizeof(st->chan_val)); in __ltc2983_chan_assign_common()
365 u8 mult = custom->is_steinhart ? LTC2983_CUSTOM_STEINHART_ENTRY_SZ : in __ltc2983_chan_custom_sensor_assign()
367 const struct device *dev = &st->spi->dev; in __ltc2983_chan_custom_sensor_assign()
369 * custom->size holds the raw size of the table. However, when in __ltc2983_chan_custom_sensor_assign()
374 const u8 len = custom->is_steinhart ? 0 : in __ltc2983_chan_custom_sensor_assign()
375 (custom->size / LTC2983_CUSTOM_SENSOR_ENTRY_SZ) - 1; in __ltc2983_chan_custom_sensor_assign()
380 if (custom->offset < 0) { in __ltc2983_chan_custom_sensor_assign()
387 if (st->custom_table_size + custom->size > in __ltc2983_chan_custom_sensor_assign()
388 (LTC2983_CUST_SENS_TBL_END_REG - in __ltc2983_chan_custom_sensor_assign()
392 st->custom_table_size, in __ltc2983_chan_custom_sensor_assign()
393 custom->size); in __ltc2983_chan_custom_sensor_assign()
394 return -EINVAL; in __ltc2983_chan_custom_sensor_assign()
397 custom->offset = st->custom_table_size / in __ltc2983_chan_custom_sensor_assign()
399 st->custom_table_size += custom->size; in __ltc2983_chan_custom_sensor_assign()
402 reg = (custom->offset * mult) + LTC2983_CUST_SENS_TBL_START_REG; in __ltc2983_chan_custom_sensor_assign()
405 *chan_val |= LTC2983_CUSTOM_ADDR(custom->offset); in __ltc2983_chan_custom_sensor_assign()
407 reg, custom->offset, in __ltc2983_chan_custom_sensor_assign()
408 custom->size); in __ltc2983_chan_custom_sensor_assign()
410 return regmap_bulk_write(st->regmap, reg, custom->table, custom->size); in __ltc2983_chan_custom_sensor_assign()
419 struct device *dev = &st->spi->dev; in __ltc2983_custom_sensor_new()
435 return ERR_PTR(-EINVAL); in __ltc2983_custom_sensor_new()
440 return ERR_PTR(-ENOMEM); in __ltc2983_custom_sensor_new()
442 new_custom->size = n_entries * n_size; in __ltc2983_custom_sensor_new()
444 if (is_steinhart && new_custom->size != LTC2983_CUSTOM_STEINHART_SIZE) { in __ltc2983_custom_sensor_new()
445 dev_err(dev, "Steinhart sensors size(%zu) must be %u\n", new_custom->size, in __ltc2983_custom_sensor_new()
447 return ERR_PTR(-EINVAL); in __ltc2983_custom_sensor_new()
450 if (st->custom_table_size + new_custom->size > in __ltc2983_custom_sensor_new()
451 (LTC2983_CUST_SENS_TBL_END_REG - in __ltc2983_custom_sensor_new()
454 st->custom_table_size, new_custom->size); in __ltc2983_custom_sensor_new()
455 return ERR_PTR(-EINVAL); in __ltc2983_custom_sensor_new()
460 new_custom->table = devm_kcalloc(dev, n_entries, sizeof(u32), GFP_KERNEL); in __ltc2983_custom_sensor_new()
462 new_custom->table = devm_kcalloc(dev, n_entries, sizeof(u64), GFP_KERNEL); in __ltc2983_custom_sensor_new()
463 if (!new_custom->table) in __ltc2983_custom_sensor_new()
464 return ERR_PTR(-ENOMEM); in __ltc2983_custom_sensor_new()
474 ret = fwnode_property_read_u32_array(fn, propname, new_custom->table, n_entries); in __ltc2983_custom_sensor_new()
478 cpu_to_be32_array(new_custom->table, new_custom->table, n_entries); in __ltc2983_custom_sensor_new()
480 ret = fwnode_property_read_u64_array(fn, propname, new_custom->table, n_entries); in __ltc2983_custom_sensor_new()
485 u64 temp = ((u64 *)new_custom->table)[index]; in __ltc2983_custom_sensor_new()
494 put_unaligned_be24(temp, new_custom->table + index * 3); in __ltc2983_custom_sensor_new()
498 new_custom->is_steinhart = is_steinhart; in __ltc2983_custom_sensor_new()
503 * sure that sensor_addr - 0x250(start address) is a multiple of 4 in __ltc2983_custom_sensor_new()
506 * also a multiple of 6, we guarantee that the first non-steinhart in __ltc2983_custom_sensor_new()
511 new_custom->offset = st->custom_table_size / in __ltc2983_custom_sensor_new()
513 st->custom_table_size += new_custom->size; in __ltc2983_custom_sensor_new()
516 new_custom->offset = -1; in __ltc2983_custom_sensor_new()
544 chan_val = LTC2983_CHAN_ASSIGN(thermo->cold_junction_chan); in ltc2983_thermocouple_assign_chan()
545 chan_val |= LTC2983_THERMOCOUPLE_CFG(thermo->sensor_config); in ltc2983_thermocouple_assign_chan()
547 if (thermo->custom) { in ltc2983_thermocouple_assign_chan()
550 ret = __ltc2983_chan_custom_sensor_assign(st, thermo->custom, in ltc2983_thermocouple_assign_chan()
564 chan_val = LTC2983_CHAN_ASSIGN(rtd->r_sense_chan); in ltc2983_rtd_assign_chan()
565 chan_val |= LTC2983_RTD_CFG(rtd->sensor_config); in ltc2983_rtd_assign_chan()
566 chan_val |= LTC2983_RTD_EXC_CURRENT(rtd->excitation_current); in ltc2983_rtd_assign_chan()
567 chan_val |= LTC2983_RTD_CURVE(rtd->rtd_curve); in ltc2983_rtd_assign_chan()
569 if (rtd->custom) { in ltc2983_rtd_assign_chan()
572 ret = __ltc2983_chan_custom_sensor_assign(st, rtd->custom, in ltc2983_rtd_assign_chan()
586 chan_val = LTC2983_CHAN_ASSIGN(thermistor->r_sense_chan); in ltc2983_thermistor_assign_chan()
587 chan_val |= LTC2983_THERMISTOR_CFG(thermistor->sensor_config); in ltc2983_thermistor_assign_chan()
589 LTC2983_THERMISTOR_EXC_CURRENT(thermistor->excitation_current); in ltc2983_thermistor_assign_chan()
591 if (thermistor->custom) { in ltc2983_thermistor_assign_chan()
595 thermistor->custom, in ltc2983_thermistor_assign_chan()
609 chan_val = LTC2983_DIODE_CFG(diode->sensor_config); in ltc2983_diode_assign_chan()
610 chan_val |= LTC2983_DIODE_EXC_CURRENT(diode->excitation_current); in ltc2983_diode_assign_chan()
611 chan_val |= LTC2983_DIODE_IDEAL_FACTOR(diode->ideal_factor_value); in ltc2983_diode_assign_chan()
622 chan_val = LTC2983_R_SENSE_VAL(rsense->r_sense_val); in ltc2983_r_sense_assign_chan()
633 chan_val = LTC2983_ADC_SINGLE_ENDED(adc->single_ended); in ltc2983_adc_assign_chan()
645 chan_val = LTC2983_ADC_SINGLE_ENDED(temp->single_ended); in ltc2983_temp_assign_chan()
647 ret = __ltc2983_chan_custom_sensor_assign(st, temp->custom, &chan_val); in ltc2983_temp_assign_chan()
663 thermo = devm_kzalloc(&st->spi->dev, sizeof(*thermo), GFP_KERNEL); in ltc2983_thermocouple_new()
665 return ERR_PTR(-ENOMEM); in ltc2983_thermocouple_new()
667 if (fwnode_property_read_bool(child, "adi,single-ended")) in ltc2983_thermocouple_new()
668 thermo->sensor_config = LTC2983_THERMOCOUPLE_SGL(1); in ltc2983_thermocouple_new()
670 ret = fwnode_property_read_u32(child, "adi,sensor-oc-current-microamp", &oc_current); in ltc2983_thermocouple_new()
674 thermo->sensor_config |= in ltc2983_thermocouple_new()
678 thermo->sensor_config |= in ltc2983_thermocouple_new()
682 thermo->sensor_config |= in ltc2983_thermocouple_new()
686 thermo->sensor_config |= in ltc2983_thermocouple_new()
690 dev_err(&st->spi->dev, in ltc2983_thermocouple_new()
692 return ERR_PTR(-EINVAL); in ltc2983_thermocouple_new()
695 thermo->sensor_config |= LTC2983_THERMOCOUPLE_OC_CHECK(1); in ltc2983_thermocouple_new()
698 if (!(thermo->sensor_config & LTC2983_THERMOCOUPLE_DIFF_MASK) && in ltc2983_thermocouple_new()
699 sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { in ltc2983_thermocouple_new()
700 dev_err(&st->spi->dev, in ltc2983_thermocouple_new()
702 sensor->chan); in ltc2983_thermocouple_new()
703 return ERR_PTR(-EINVAL); in ltc2983_thermocouple_new()
706 ref = fwnode_find_reference(child, "adi,cold-junction-handle", 0); in ltc2983_thermocouple_new()
710 ret = fwnode_property_read_u32(ref, "reg", &thermo->cold_junction_chan); in ltc2983_thermocouple_new()
716 dev_err(&st->spi->dev, "Property reg must be given\n"); in ltc2983_thermocouple_new()
722 if (sensor->type == LTC2983_SENSOR_THERMOCOUPLE_CUSTOM) { in ltc2983_thermocouple_new()
723 const char *propname = "adi,custom-thermocouple"; in ltc2983_thermocouple_new()
725 thermo->custom = __ltc2983_custom_sensor_new(st, child, in ltc2983_thermocouple_new()
728 if (IS_ERR(thermo->custom)) { in ltc2983_thermocouple_new()
729 ret = PTR_ERR(thermo->custom); in ltc2983_thermocouple_new()
735 thermo->sensor.fault_handler = ltc2983_thermocouple_fault_handler; in ltc2983_thermocouple_new()
736 thermo->sensor.assign_chan = ltc2983_thermocouple_assign_chan; in ltc2983_thermocouple_new()
739 return &thermo->sensor; in ltc2983_thermocouple_new()
752 struct device *dev = &st->spi->dev; in ltc2983_rtd_new()
758 return ERR_PTR(-ENOMEM); in ltc2983_rtd_new()
760 ref = fwnode_find_reference(child, "adi,rsense-handle", 0); in ltc2983_rtd_new()
762 dev_err(dev, "Property adi,rsense-handle missing or invalid"); in ltc2983_rtd_new()
766 ret = fwnode_property_read_u32(ref, "reg", &rtd->r_sense_chan); in ltc2983_rtd_new()
772 ret = fwnode_property_read_u32(child, "adi,number-of-wires", &n_wires); in ltc2983_rtd_new()
776 rtd->sensor_config = LTC2983_RTD_N_WIRES(0); in ltc2983_rtd_new()
779 rtd->sensor_config = LTC2983_RTD_N_WIRES(1); in ltc2983_rtd_new()
782 rtd->sensor_config = LTC2983_RTD_N_WIRES(2); in ltc2983_rtd_new()
786 rtd->sensor_config = LTC2983_RTD_N_WIRES(3); in ltc2983_rtd_new()
790 ret = -EINVAL; in ltc2983_rtd_new()
795 if (fwnode_property_read_bool(child, "adi,rsense-share")) { in ltc2983_rtd_new()
797 if (fwnode_property_read_bool(child, "adi,current-rotate")) { in ltc2983_rtd_new()
801 ret = -EINVAL; in ltc2983_rtd_new()
804 rtd->sensor_config |= LTC2983_RTD_C_ROTATE(1); in ltc2983_rtd_new()
806 rtd->sensor_config |= LTC2983_RTD_R_SHARE(1); in ltc2983_rtd_new()
814 * <=1 since chanel - 1 and channel - 2 are used. in ltc2983_rtd_new()
816 if (rtd->sensor_config & LTC2983_RTD_4_WIRE_MASK) { in ltc2983_rtd_new()
817 /* 4-wire */ in ltc2983_rtd_new()
819 max = st->info->max_channels_nr; in ltc2983_rtd_new()
821 if (rtd->sensor_config & LTC2983_RTD_ROTATION_MASK) in ltc2983_rtd_new()
822 max = st->info->max_channels_nr - 1; in ltc2983_rtd_new()
824 if (((rtd->sensor_config & LTC2983_RTD_KELVIN_R_SENSE_MASK) in ltc2983_rtd_new()
826 (rtd->r_sense_chan <= min)) { in ltc2983_rtd_new()
830 rtd->r_sense_chan); in ltc2983_rtd_new()
832 ret = -EINVAL; in ltc2983_rtd_new()
836 if (sensor->chan < min || sensor->chan > max) { in ltc2983_rtd_new()
838 sensor->chan); in ltc2983_rtd_new()
840 ret = -EINVAL; in ltc2983_rtd_new()
845 if (sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { in ltc2983_rtd_new()
846 dev_err(&st->spi->dev, in ltc2983_rtd_new()
847 "Invalid chann:%d for RTD", sensor->chan); in ltc2983_rtd_new()
849 ret = -EINVAL; in ltc2983_rtd_new()
855 if (sensor->type == LTC2983_SENSOR_RTD_CUSTOM) { in ltc2983_rtd_new()
856 rtd->custom = __ltc2983_custom_sensor_new(st, child, in ltc2983_rtd_new()
857 "adi,custom-rtd", in ltc2983_rtd_new()
859 if (IS_ERR(rtd->custom)) { in ltc2983_rtd_new()
860 ret = PTR_ERR(rtd->custom); in ltc2983_rtd_new()
866 rtd->sensor.fault_handler = ltc2983_common_fault_handler; in ltc2983_rtd_new()
867 rtd->sensor.assign_chan = ltc2983_rtd_assign_chan; in ltc2983_rtd_new()
869 ret = fwnode_property_read_u32(child, "adi,excitation-current-microamp", in ltc2983_rtd_new()
873 rtd->excitation_current = 1; in ltc2983_rtd_new()
877 rtd->excitation_current = 0x01; in ltc2983_rtd_new()
880 rtd->excitation_current = 0x02; in ltc2983_rtd_new()
883 rtd->excitation_current = 0x03; in ltc2983_rtd_new()
886 rtd->excitation_current = 0x04; in ltc2983_rtd_new()
889 rtd->excitation_current = 0x05; in ltc2983_rtd_new()
892 rtd->excitation_current = 0x06; in ltc2983_rtd_new()
895 rtd->excitation_current = 0x07; in ltc2983_rtd_new()
898 rtd->excitation_current = 0x08; in ltc2983_rtd_new()
901 dev_err(&st->spi->dev, in ltc2983_rtd_new()
904 ret = -EINVAL; in ltc2983_rtd_new()
909 fwnode_property_read_u32(child, "adi,rtd-curve", &rtd->rtd_curve); in ltc2983_rtd_new()
912 return &rtd->sensor; in ltc2983_rtd_new()
923 struct device *dev = &st->spi->dev; in ltc2983_thermistor_new()
930 return ERR_PTR(-ENOMEM); in ltc2983_thermistor_new()
932 ref = fwnode_find_reference(child, "adi,rsense-handle", 0); in ltc2983_thermistor_new()
934 dev_err(dev, "Property adi,rsense-handle missing or invalid"); in ltc2983_thermistor_new()
938 ret = fwnode_property_read_u32(ref, "reg", &thermistor->r_sense_chan); in ltc2983_thermistor_new()
944 if (fwnode_property_read_bool(child, "adi,single-ended")) { in ltc2983_thermistor_new()
945 thermistor->sensor_config = LTC2983_THERMISTOR_SGL(1); in ltc2983_thermistor_new()
946 } else if (fwnode_property_read_bool(child, "adi,rsense-share")) { in ltc2983_thermistor_new()
948 if (fwnode_property_read_bool(child, "adi,current-rotate")) in ltc2983_thermistor_new()
949 thermistor->sensor_config = in ltc2983_thermistor_new()
952 thermistor->sensor_config = in ltc2983_thermistor_new()
956 if (!(thermistor->sensor_config & LTC2983_THERMISTOR_DIFF_MASK) && in ltc2983_thermistor_new()
957 sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { in ltc2983_thermistor_new()
958 dev_err(&st->spi->dev, in ltc2983_thermistor_new()
960 sensor->chan); in ltc2983_thermistor_new()
961 ret = -EINVAL; in ltc2983_thermistor_new()
966 if (sensor->type >= LTC2983_SENSOR_THERMISTOR_STEINHART) { in ltc2983_thermistor_new()
970 if (sensor->type == LTC2983_SENSOR_THERMISTOR_STEINHART) { in ltc2983_thermistor_new()
972 propname = "adi,custom-steinhart"; in ltc2983_thermistor_new()
974 propname = "adi,custom-thermistor"; in ltc2983_thermistor_new()
977 thermistor->custom = __ltc2983_custom_sensor_new(st, child, in ltc2983_thermistor_new()
981 if (IS_ERR(thermistor->custom)) { in ltc2983_thermistor_new()
982 ret = PTR_ERR(thermistor->custom); in ltc2983_thermistor_new()
987 thermistor->sensor.fault_handler = ltc2983_common_fault_handler; in ltc2983_thermistor_new()
988 thermistor->sensor.assign_chan = ltc2983_thermistor_assign_chan; in ltc2983_thermistor_new()
990 ret = fwnode_property_read_u32(child, "adi,excitation-current-nanoamp", in ltc2983_thermistor_new()
994 if (sensor->type >= LTC2983_SENSOR_THERMISTOR_STEINHART) in ltc2983_thermistor_new()
996 thermistor->excitation_current = 0x03; in ltc2983_thermistor_new()
998 /* default to auto-range */ in ltc2983_thermistor_new()
999 thermistor->excitation_current = 0x0c; in ltc2983_thermistor_new()
1004 if (sensor->type >= in ltc2983_thermistor_new()
1006 dev_err(&st->spi->dev, in ltc2983_thermistor_new()
1008 ret = -EINVAL; in ltc2983_thermistor_new()
1011 thermistor->excitation_current = 0x0c; in ltc2983_thermistor_new()
1014 thermistor->excitation_current = 0x01; in ltc2983_thermistor_new()
1017 thermistor->excitation_current = 0x02; in ltc2983_thermistor_new()
1020 thermistor->excitation_current = 0x03; in ltc2983_thermistor_new()
1023 thermistor->excitation_current = 0x04; in ltc2983_thermistor_new()
1026 thermistor->excitation_current = 0x05; in ltc2983_thermistor_new()
1029 thermistor->excitation_current = 0x06; in ltc2983_thermistor_new()
1032 thermistor->excitation_current = 0x07; in ltc2983_thermistor_new()
1035 thermistor->excitation_current = 0x08; in ltc2983_thermistor_new()
1038 thermistor->excitation_current = 0x09; in ltc2983_thermistor_new()
1041 thermistor->excitation_current = 0x0a; in ltc2983_thermistor_new()
1044 thermistor->excitation_current = 0x0b; in ltc2983_thermistor_new()
1047 dev_err(&st->spi->dev, in ltc2983_thermistor_new()
1050 ret = -EINVAL; in ltc2983_thermistor_new()
1056 return &thermistor->sensor; in ltc2983_thermistor_new()
1070 diode = devm_kzalloc(&st->spi->dev, sizeof(*diode), GFP_KERNEL); in ltc2983_diode_new()
1072 return ERR_PTR(-ENOMEM); in ltc2983_diode_new()
1074 if (fwnode_property_read_bool(child, "adi,single-ended")) in ltc2983_diode_new()
1075 diode->sensor_config = LTC2983_DIODE_SGL(1); in ltc2983_diode_new()
1077 if (fwnode_property_read_bool(child, "adi,three-conversion-cycles")) in ltc2983_diode_new()
1078 diode->sensor_config |= LTC2983_DIODE_3_CONV_CYCLE(1); in ltc2983_diode_new()
1080 if (fwnode_property_read_bool(child, "adi,average-on")) in ltc2983_diode_new()
1081 diode->sensor_config |= LTC2983_DIODE_AVERAGE_ON(1); in ltc2983_diode_new()
1084 if (!(diode->sensor_config & LTC2983_DIODE_DIFF_MASK) && in ltc2983_diode_new()
1085 sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { in ltc2983_diode_new()
1086 dev_err(&st->spi->dev, in ltc2983_diode_new()
1088 sensor->chan); in ltc2983_diode_new()
1089 return ERR_PTR(-EINVAL); in ltc2983_diode_new()
1092 diode->sensor.fault_handler = ltc2983_common_fault_handler; in ltc2983_diode_new()
1093 diode->sensor.assign_chan = ltc2983_diode_assign_chan; in ltc2983_diode_new()
1095 ret = fwnode_property_read_u32(child, "adi,excitation-current-microamp", in ltc2983_diode_new()
1100 diode->excitation_current = 0x00; in ltc2983_diode_new()
1103 diode->excitation_current = 0x01; in ltc2983_diode_new()
1106 diode->excitation_current = 0x02; in ltc2983_diode_new()
1109 diode->excitation_current = 0x03; in ltc2983_diode_new()
1112 dev_err(&st->spi->dev, in ltc2983_diode_new()
1115 return ERR_PTR(-EINVAL); in ltc2983_diode_new()
1119 fwnode_property_read_u32(child, "adi,ideal-factor-value", &temp); in ltc2983_diode_new()
1122 diode->ideal_factor_value = __convert_to_raw(temp, 1048576); in ltc2983_diode_new()
1124 return &diode->sensor; in ltc2983_diode_new()
1135 rsense = devm_kzalloc(&st->spi->dev, sizeof(*rsense), GFP_KERNEL); in ltc2983_r_sense_new()
1137 return ERR_PTR(-ENOMEM); in ltc2983_r_sense_new()
1140 if (sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { in ltc2983_r_sense_new()
1141 dev_err(&st->spi->dev, "Invalid chann:%d for r_sense", in ltc2983_r_sense_new()
1142 sensor->chan); in ltc2983_r_sense_new()
1143 return ERR_PTR(-EINVAL); in ltc2983_r_sense_new()
1146 ret = fwnode_property_read_u32(child, "adi,rsense-val-milli-ohms", &temp); in ltc2983_r_sense_new()
1148 dev_err(&st->spi->dev, "Property adi,rsense-val-milli-ohms missing\n"); in ltc2983_r_sense_new()
1149 return ERR_PTR(-EINVAL); in ltc2983_r_sense_new()
1152 * Times 1000 because we have milli-ohms and __convert_to_raw in ltc2983_r_sense_new()
1157 rsense->r_sense_val = __convert_to_raw((u64)temp * 1000, 1024); in ltc2983_r_sense_new()
1160 rsense->sensor.assign_chan = ltc2983_r_sense_assign_chan; in ltc2983_r_sense_new()
1162 return &rsense->sensor; in ltc2983_r_sense_new()
1171 adc = devm_kzalloc(&st->spi->dev, sizeof(*adc), GFP_KERNEL); in ltc2983_adc_new()
1173 return ERR_PTR(-ENOMEM); in ltc2983_adc_new()
1175 if (fwnode_property_read_bool(child, "adi,single-ended")) in ltc2983_adc_new()
1176 adc->single_ended = true; in ltc2983_adc_new()
1178 if (!adc->single_ended && in ltc2983_adc_new()
1179 sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { in ltc2983_adc_new()
1180 dev_err(&st->spi->dev, "Invalid chan:%d for differential adc\n", in ltc2983_adc_new()
1181 sensor->chan); in ltc2983_adc_new()
1182 return ERR_PTR(-EINVAL); in ltc2983_adc_new()
1185 adc->sensor.assign_chan = ltc2983_adc_assign_chan; in ltc2983_adc_new()
1186 adc->sensor.fault_handler = ltc2983_common_fault_handler; in ltc2983_adc_new()
1188 return &adc->sensor; in ltc2983_adc_new()
1197 temp = devm_kzalloc(&st->spi->dev, sizeof(*temp), GFP_KERNEL); in ltc2983_temp_new()
1199 return ERR_PTR(-ENOMEM); in ltc2983_temp_new()
1201 if (fwnode_property_read_bool(child, "adi,single-ended")) in ltc2983_temp_new()
1202 temp->single_ended = true; in ltc2983_temp_new()
1204 if (!temp->single_ended && in ltc2983_temp_new()
1205 sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { in ltc2983_temp_new()
1206 dev_err(&st->spi->dev, "Invalid chan:%d for differential temp\n", in ltc2983_temp_new()
1207 sensor->chan); in ltc2983_temp_new()
1208 return ERR_PTR(-EINVAL); in ltc2983_temp_new()
1211 temp->custom = __ltc2983_custom_sensor_new(st, child, "adi,custom-temp", in ltc2983_temp_new()
1213 if (IS_ERR(temp->custom)) in ltc2983_temp_new()
1214 return ERR_CAST(temp->custom); in ltc2983_temp_new()
1217 temp->sensor.assign_chan = ltc2983_temp_assign_chan; in ltc2983_temp_new()
1218 temp->sensor.fault_handler = ltc2983_common_fault_handler; in ltc2983_temp_new()
1220 return &temp->sensor; in ltc2983_temp_new()
1231 start_conversion |= LTC2983_STATUS_CHAN_SEL(sensor->chan); in ltc2983_chan_read()
1232 dev_dbg(&st->spi->dev, "Start conversion on chan:%d, status:%02X\n", in ltc2983_chan_read()
1233 sensor->chan, start_conversion); in ltc2983_chan_read()
1235 ret = regmap_write(st->regmap, LTC2983_STATUS_REG, start_conversion); in ltc2983_chan_read()
1239 reinit_completion(&st->completion); in ltc2983_chan_read()
1246 time = wait_for_completion_timeout(&st->completion, in ltc2983_chan_read()
1249 dev_warn(&st->spi->dev, "Conversion timed out\n"); in ltc2983_chan_read()
1250 return -ETIMEDOUT; in ltc2983_chan_read()
1254 ret = regmap_bulk_read(st->regmap, LTC2983_CHAN_RES_ADDR(sensor->chan), in ltc2983_chan_read()
1255 &st->temp, sizeof(st->temp)); in ltc2983_chan_read()
1259 *val = __be32_to_cpu(st->temp); in ltc2983_chan_read()
1262 dev_err(&st->spi->dev, "Invalid conversion detected\n"); in ltc2983_chan_read()
1263 return -EIO; in ltc2983_chan_read()
1266 ret = sensor->fault_handler(st, *val); in ltc2983_chan_read()
1282 if (chan->address >= st->num_channels) { in ltc2983_read_raw()
1283 dev_err(&st->spi->dev, "Invalid chan address:%ld", in ltc2983_read_raw()
1284 chan->address); in ltc2983_read_raw()
1285 return -EINVAL; in ltc2983_read_raw()
1290 mutex_lock(&st->lock); in ltc2983_read_raw()
1291 ret = ltc2983_chan_read(st, st->sensors[chan->address], val); in ltc2983_read_raw()
1292 mutex_unlock(&st->lock); in ltc2983_read_raw()
1295 switch (chan->type) { in ltc2983_read_raw()
1297 /* value in milli degrees */ in ltc2983_read_raw()
1309 return -EINVAL; in ltc2983_read_raw()
1313 return -EINVAL; in ltc2983_read_raw()
1324 return regmap_read(st->regmap, reg, readval); in ltc2983_reg_access()
1326 return regmap_write(st->regmap, reg, writeval); in ltc2983_reg_access()
1333 complete(&st->completion); in ltc2983_irq_handler()
1351 struct device *dev = &st->spi->dev; in ltc2983_parse_dt()
1355 device_property_read_u32(dev, "adi,mux-delay-config-us", &st->mux_delay_config); in ltc2983_parse_dt()
1357 device_property_read_u32(dev, "adi,filter-notch-freq", &st->filter_notch_freq); in ltc2983_parse_dt()
1359 st->num_channels = device_get_child_node_count(dev); in ltc2983_parse_dt()
1360 if (!st->num_channels) { in ltc2983_parse_dt()
1361 dev_err(&st->spi->dev, "At least one channel must be given!"); in ltc2983_parse_dt()
1362 return -EINVAL; in ltc2983_parse_dt()
1365 st->sensors = devm_kcalloc(dev, st->num_channels, sizeof(*st->sensors), in ltc2983_parse_dt()
1367 if (!st->sensors) in ltc2983_parse_dt()
1368 return -ENOMEM; in ltc2983_parse_dt()
1370 st->iio_channels = st->num_channels; in ltc2983_parse_dt()
1382 sensor.chan > st->info->max_channels_nr) { in ltc2983_parse_dt()
1383 ret = -EINVAL; in ltc2983_parse_dt()
1385 LTC2983_MIN_CHANNELS_NR, st->info->max_channels_nr); in ltc2983_parse_dt()
1388 ret = -EINVAL; in ltc2983_parse_dt()
1393 ret = fwnode_property_read_u32(child, "adi,sensor-type", &sensor.type); in ltc2983_parse_dt()
1396 "adi,sensor-type property must given for child nodes\n"); in ltc2983_parse_dt()
1406 st->sensors[chan] = ltc2983_thermocouple_new(child, st, in ltc2983_parse_dt()
1410 st->sensors[chan] = ltc2983_rtd_new(child, st, &sensor); in ltc2983_parse_dt()
1413 st->sensors[chan] = ltc2983_thermistor_new(child, st, in ltc2983_parse_dt()
1416 st->sensors[chan] = ltc2983_diode_new(child, st, in ltc2983_parse_dt()
1419 st->sensors[chan] = ltc2983_r_sense_new(child, st, in ltc2983_parse_dt()
1422 st->iio_channels--; in ltc2983_parse_dt()
1424 st->sensors[chan] = ltc2983_adc_new(child, st, &sensor); in ltc2983_parse_dt()
1425 } else if (st->info->has_temp && in ltc2983_parse_dt()
1427 st->sensors[chan] = ltc2983_temp_new(child, st, &sensor); in ltc2983_parse_dt()
1430 ret = -EINVAL; in ltc2983_parse_dt()
1434 if (IS_ERR(st->sensors[chan])) { in ltc2983_parse_dt()
1436 PTR_ERR(st->sensors[chan])); in ltc2983_parse_dt()
1437 ret = PTR_ERR(st->sensors[chan]); in ltc2983_parse_dt()
1441 st->sensors[chan]->chan = sensor.chan; in ltc2983_parse_dt()
1442 st->sensors[chan]->type = sensor.type; in ltc2983_parse_dt()
1462 ret = regmap_bulk_write(st->regmap, LTC2983_EEPROM_KEY_REG, in ltc2983_eeprom_cmd()
1463 &st->eeprom_key, sizeof(st->eeprom_key)); in ltc2983_eeprom_cmd()
1467 reinit_completion(&st->completion); in ltc2983_eeprom_cmd()
1469 ret = regmap_write(st->regmap, LTC2983_STATUS_REG, in ltc2983_eeprom_cmd()
1474 time = wait_for_completion_timeout(&st->completion, in ltc2983_eeprom_cmd()
1477 dev_err(&st->spi->dev, "EEPROM command timed out\n"); in ltc2983_eeprom_cmd()
1478 return -ETIMEDOUT; in ltc2983_eeprom_cmd()
1481 ret = regmap_read(st->regmap, status_reg, &val); in ltc2983_eeprom_cmd()
1486 dev_err(&st->spi->dev, "EEPROM command failed: 0x%02X\n", val); in ltc2983_eeprom_cmd()
1487 return -EINVAL; in ltc2983_eeprom_cmd()
1499 ret = regmap_read_poll_timeout(st->regmap, LTC2983_STATUS_REG, status, in ltc2983_setup()
1503 dev_err(&st->spi->dev, "Device startup timed out\n"); in ltc2983_setup()
1507 ret = regmap_update_bits(st->regmap, LTC2983_GLOBAL_CONFIG_REG, in ltc2983_setup()
1509 LTC2983_NOTCH_FREQ(st->filter_notch_freq)); in ltc2983_setup()
1513 ret = regmap_write(st->regmap, LTC2983_MUX_CONFIG_REG, in ltc2983_setup()
1514 st->mux_delay_config); in ltc2983_setup()
1518 if (st->info->has_eeprom && !assign_iio) { in ltc2983_setup()
1527 for (chan = 0; chan < st->num_channels; chan++) { in ltc2983_setup()
1530 ret = st->sensors[chan]->assign_chan(st, st->sensors[chan]); in ltc2983_setup()
1536 * re-configure the device channels. in ltc2983_setup()
1539 if (st->sensors[chan]->type == LTC2983_SENSOR_SENSE_RESISTOR || in ltc2983_setup()
1544 if (st->sensors[chan]->type != LTC2983_SENSOR_DIRECT_ADC) { in ltc2983_setup()
1556 st->iio_chan[iio_idx++] = LTC2983_CHAN(chan_type, (*iio_chan)++, in ltc2983_setup()
1608 const char *name = spi_get_device_id(spi)->name; in ltc2983_probe()
1611 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ltc2983_probe()
1613 return -ENOMEM; in ltc2983_probe()
1617 st->info = device_get_match_data(&spi->dev); in ltc2983_probe()
1618 if (!st->info) in ltc2983_probe()
1619 st->info = (void *)spi_get_device_id(spi)->driver_data; in ltc2983_probe()
1620 if (!st->info) in ltc2983_probe()
1621 return -ENODEV; in ltc2983_probe()
1623 st->regmap = devm_regmap_init_spi(spi, <c2983_regmap_config); in ltc2983_probe()
1624 if (IS_ERR(st->regmap)) { in ltc2983_probe()
1625 dev_err(&spi->dev, "Failed to initialize regmap\n"); in ltc2983_probe()
1626 return PTR_ERR(st->regmap); in ltc2983_probe()
1629 mutex_init(&st->lock); in ltc2983_probe()
1630 init_completion(&st->completion); in ltc2983_probe()
1631 st->spi = spi; in ltc2983_probe()
1632 st->eeprom_key = cpu_to_be32(LTC2983_EEPROM_KEY); in ltc2983_probe()
1639 gpio = devm_gpiod_get_optional(&st->spi->dev, "reset", GPIOD_OUT_HIGH); in ltc2983_probe()
1649 st->iio_chan = devm_kzalloc(&spi->dev, in ltc2983_probe()
1650 st->iio_channels * sizeof(*st->iio_chan), in ltc2983_probe()
1652 if (!st->iio_chan) in ltc2983_probe()
1653 return -ENOMEM; in ltc2983_probe()
1659 ret = devm_request_irq(&spi->dev, spi->irq, ltc2983_irq_handler, in ltc2983_probe()
1662 dev_err(&spi->dev, "failed to request an irq, %d", ret); in ltc2983_probe()
1666 if (st->info->has_eeprom) { in ltc2983_probe()
1675 indio_dev->name = name; in ltc2983_probe()
1676 indio_dev->num_channels = st->iio_channels; in ltc2983_probe()
1677 indio_dev->channels = st->iio_chan; in ltc2983_probe()
1678 indio_dev->modes = INDIO_DIRECT_MODE; in ltc2983_probe()
1679 indio_dev->info = <c2983_iio_info; in ltc2983_probe()
1681 return devm_iio_device_register(&spi->dev, indio_dev); in ltc2983_probe()
1690 regmap_read(st->regmap, LTC2983_STATUS_REG, &dummy); in ltc2983_resume()
1691 /* we need to re-assign the channels */ in ltc2983_resume()
1699 return regmap_write(st->regmap, LTC2983_STATUS_REG, LTC2983_SLEEP); in ltc2983_suspend()