Lines Matching +full:resistance +full:- +full:temp +full:- +full:table
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ntc_thermistor.c - NTC Thermistors
16 #include <linux/fixp-arith.h>
35 * Used as index in a zero-terminated array, holes not allowed so
68 * A compensation table should be sorted by the values of .ohm
74 { .temp_c = -40, .ohm = 1747920 },
75 { .temp_c = -35, .ohm = 1245428 },
76 { .temp_c = -30, .ohm = 898485 },
77 { .temp_c = -25, .ohm = 655802 },
78 { .temp_c = -20, .ohm = 483954 },
79 { .temp_c = -15, .ohm = 360850 },
80 { .temp_c = -10, .ohm = 271697 },
81 { .temp_c = -5, .ohm = 206463 },
110 { .temp_c = -40, .ohm = 1610154 },
111 { .temp_c = -35, .ohm = 1130850 },
112 { .temp_c = -30, .ohm = 802609 },
113 { .temp_c = -25, .ohm = 575385 },
114 { .temp_c = -20, .ohm = 416464 },
115 { .temp_c = -15, .ohm = 304219 },
116 { .temp_c = -10, .ohm = 224193 },
117 { .temp_c = -5, .ohm = 166623 },
147 { .temp_c = -40, .ohm = 4397119 },
148 { .temp_c = -35, .ohm = 3088599 },
149 { .temp_c = -30, .ohm = 2197225 },
150 { .temp_c = -25, .ohm = 1581881 },
151 { .temp_c = -20, .ohm = 1151037 },
152 { .temp_c = -15, .ohm = 846579 },
153 { .temp_c = -10, .ohm = 628988 },
154 { .temp_c = -5, .ohm = 471632 },
184 { .temp_c = -40, .ohm = 247565 },
185 { .temp_c = -35, .ohm = 181742 },
186 { .temp_c = -30, .ohm = 135128 },
187 { .temp_c = -25, .ohm = 101678 },
188 { .temp_c = -20, .ohm = 77373 },
189 { .temp_c = -15, .ohm = 59504 },
190 { .temp_c = -10, .ohm = 46222 },
191 { .temp_c = -5, .ohm = 36244 },
225 { .temp_c = -40, .ohm = 190030 },
226 { .temp_c = -35, .ohm = 145360 },
227 { .temp_c = -30, .ohm = 112060 },
228 { .temp_c = -25, .ohm = 87041 },
229 { .temp_c = -20, .ohm = 68104 },
230 { .temp_c = -15, .ohm = 53665 },
231 { .temp_c = -10, .ohm = 42576 },
232 { .temp_c = -5, .ohm = 34001 },
262 { .temp_c = -55.0, .ohm = 878900 },
263 { .temp_c = -50.0, .ohm = 617590 },
264 { .temp_c = -45.0, .ohm = 439340 },
265 { .temp_c = -40.0, .ohm = 316180 },
266 { .temp_c = -35.0, .ohm = 230060 },
267 { .temp_c = -30.0, .ohm = 169150 },
268 { .temp_c = -25.0, .ohm = 125550 },
269 { .temp_c = -20.0, .ohm = 94143 },
270 { .temp_c = -15.0, .ohm = 71172 },
271 { .temp_c = -10.0, .ohm = 54308 },
272 { .temp_c = -5.0, .ohm = 41505 },
330 * pullup/down_ohm: 0 for infinite / not-connected
347 struct iio_channel *channel = data->chan; in ntc_adc_iio_read()
367 uv = (data->pullup_uv * (s64)raw) >> 12; in ntc_adc_iio_read()
385 u32 puv = data->pullup_uv; in get_ohm_of_thermistor()
387 puo = data->pullup_ohm; in get_ohm_of_thermistor()
388 pdo = data->pulldown_ohm; in get_ohm_of_thermistor()
391 return (data->connect == NTC_CONNECTED_POSITIVE) ? in get_ohm_of_thermistor()
394 return (data->connect == NTC_CONNECTED_POSITIVE) ? in get_ohm_of_thermistor()
397 if (data->connect == NTC_CONNECTED_POSITIVE && puo == 0) in get_ohm_of_thermistor()
398 n = div_u64(pdo * (puv - uv), uv); in get_ohm_of_thermistor()
399 else if (data->connect == NTC_CONNECTED_GROUND && pdo == 0) in get_ohm_of_thermistor()
400 n = div_u64(puo * uv, puv - uv); in get_ohm_of_thermistor()
401 else if (data->connect == NTC_CONNECTED_POSITIVE) in get_ohm_of_thermistor()
402 n = div64_u64_safe(pdo * puo * (puv - uv), in get_ohm_of_thermistor()
403 puo * uv - pdo * (puv - uv)); in get_ohm_of_thermistor()
405 n = div64_u64_safe(pdo * puo * uv, pdo * (puv - uv) - puo * uv); in get_ohm_of_thermistor()
418 * Handle special cases: Resistance is higher than or equal to in lookup_comp()
419 * resistance in first table entry, or resistance is lower or equal in lookup_comp()
420 * to resistance in last table entry. in lookup_comp()
422 * beginning or to the end of the table depending on the condition. in lookup_comp()
424 if (ohm >= data->comp[0].ohm) { in lookup_comp()
429 if (ohm <= data->comp[data->n_comp - 1].ohm) { in lookup_comp()
430 *i_low = data->n_comp - 1; in lookup_comp()
431 *i_high = data->n_comp - 1; in lookup_comp()
435 /* Do a binary search on compensation table */ in lookup_comp()
437 end = data->n_comp; in lookup_comp()
439 mid = start + (end - start) / 2; in lookup_comp()
442 * data->comp[start].ohm > ohm >= data->comp[end].ohm in lookup_comp()
444 * We could check for "ohm == data->comp[mid].ohm" here, but in lookup_comp()
449 if (ohm >= data->comp[mid].ohm) { in lookup_comp()
454 * ohm >= data->comp[start].ohm might be true here, in lookup_comp()
459 if (ohm >= data->comp[start].ohm) in lookup_comp()
464 * data->comp[start].ohm >= ohm >= data->comp[end].ohm in lookup_comp()
469 * ohm >= data->comp[end].ohm in lookup_comp()
472 if (ohm == data->comp[end].ohm) in lookup_comp()
475 *i_high = end - 1; in lookup_comp()
481 int temp; in get_temp_mc() local
485 * First multiplying the table temperatures with 1000 to get to in get_temp_mc()
489 temp = fixp_linear_interpolate(data->comp[low].ohm, in get_temp_mc()
490 data->comp[low].temp_c * 1000, in get_temp_mc()
491 data->comp[high].ohm, in get_temp_mc()
492 data->comp[high].temp_c * 1000, in get_temp_mc()
494 return temp; in get_temp_mc()
532 return -EINVAL; in ntc_read()
552 HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_TYPE),
582 return -EINVAL; in ntc_thermistor_parse_props()
584 ret = device_property_read_u32(dev, "pullup-uv", &data->pullup_uv); in ntc_thermistor_parse_props()
586 return dev_err_probe(dev, ret, "pullup-uv not specified\n"); in ntc_thermistor_parse_props()
588 ret = device_property_read_u32(dev, "pullup-ohm", &data->pullup_ohm); in ntc_thermistor_parse_props()
590 return dev_err_probe(dev, ret, "pullup-ohm not specified\n"); in ntc_thermistor_parse_props()
592 ret = device_property_read_u32(dev, "pulldown-ohm", &data->pulldown_ohm); in ntc_thermistor_parse_props()
594 return dev_err_probe(dev, ret, "pulldown-ohm not specified\n"); in ntc_thermistor_parse_props()
596 if (device_property_read_bool(dev, "connected-positive")) in ntc_thermistor_parse_props()
597 data->connect = NTC_CONNECTED_POSITIVE; in ntc_thermistor_parse_props()
599 data->connect = NTC_CONNECTED_GROUND; in ntc_thermistor_parse_props()
601 data->chan = chan; in ntc_thermistor_parse_props()
608 struct device *dev = &pdev->dev; in ntc_thermistor_probe()
616 return -ENOMEM; in ntc_thermistor_probe()
622 if (data->pullup_uv == 0 || in ntc_thermistor_probe()
623 (data->pullup_ohm == 0 && data->connect == in ntc_thermistor_probe()
625 (data->pulldown_ohm == 0 && data->connect == in ntc_thermistor_probe()
627 (data->connect != NTC_CONNECTED_POSITIVE && in ntc_thermistor_probe()
628 data->connect != NTC_CONNECTED_GROUND)) { in ntc_thermistor_probe()
630 return -EINVAL; in ntc_thermistor_probe()
635 if (pdev_id->driver_data >= ARRAY_SIZE(ntc_type)) { in ntc_thermistor_probe()
637 pdev_id->driver_data, pdev_id->name); in ntc_thermistor_probe()
638 return -EINVAL; in ntc_thermistor_probe()
641 data->comp = ntc_type[pdev_id->driver_data].comp; in ntc_thermistor_probe()
642 data->n_comp = ntc_type[pdev_id->driver_data].n_comp; in ntc_thermistor_probe()
644 hwmon_dev = devm_hwmon_device_register_with_info(dev, pdev_id->name, in ntc_thermistor_probe()
653 pdev_id->name); in ntc_thermistor_probe()
677 { .compatible = "samsung,1404-001221",
697 .name = "ntc-thermistor",
709 MODULE_ALIAS("platform:ntc-thermistor");