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
33 * Used as index in a zero-terminated array, holes not allowed so
63 * A compensation table should be sorted by the values of .ohm
69 { .temp_c = -40, .ohm = 1747920 },
70 { .temp_c = -35, .ohm = 1245428 },
71 { .temp_c = -30, .ohm = 898485 },
72 { .temp_c = -25, .ohm = 655802 },
73 { .temp_c = -20, .ohm = 483954 },
74 { .temp_c = -15, .ohm = 360850 },
75 { .temp_c = -10, .ohm = 271697 },
76 { .temp_c = -5, .ohm = 206463 },
105 { .temp_c = -40, .ohm = 1610154 },
106 { .temp_c = -35, .ohm = 1130850 },
107 { .temp_c = -30, .ohm = 802609 },
108 { .temp_c = -25, .ohm = 575385 },
109 { .temp_c = -20, .ohm = 416464 },
110 { .temp_c = -15, .ohm = 304219 },
111 { .temp_c = -10, .ohm = 224193 },
112 { .temp_c = -5, .ohm = 166623 },
142 { .temp_c = -40, .ohm = 4397119 },
143 { .temp_c = -35, .ohm = 3088599 },
144 { .temp_c = -30, .ohm = 2197225 },
145 { .temp_c = -25, .ohm = 1581881 },
146 { .temp_c = -20, .ohm = 1151037 },
147 { .temp_c = -15, .ohm = 846579 },
148 { .temp_c = -10, .ohm = 628988 },
149 { .temp_c = -5, .ohm = 471632 },
179 { .temp_c = -40, .ohm = 247565 },
180 { .temp_c = -35, .ohm = 181742 },
181 { .temp_c = -30, .ohm = 135128 },
182 { .temp_c = -25, .ohm = 101678 },
183 { .temp_c = -20, .ohm = 77373 },
184 { .temp_c = -15, .ohm = 59504 },
185 { .temp_c = -10, .ohm = 46222 },
186 { .temp_c = -5, .ohm = 36244 },
220 { .temp_c = -40, .ohm = 190030 },
221 { .temp_c = -35, .ohm = 145360 },
222 { .temp_c = -30, .ohm = 112060 },
223 { .temp_c = -25, .ohm = 87041 },
224 { .temp_c = -20, .ohm = 68104 },
225 { .temp_c = -15, .ohm = 53665 },
226 { .temp_c = -10, .ohm = 42576 },
227 { .temp_c = -5, .ohm = 34001 },
257 { .temp_c = -55.0, .ohm = 878900 },
258 { .temp_c = -50.0, .ohm = 617590 },
259 { .temp_c = -45.0, .ohm = 439340 },
260 { .temp_c = -40.0, .ohm = 316180 },
261 { .temp_c = -35.0, .ohm = 230060 },
262 { .temp_c = -30.0, .ohm = 169150 },
263 { .temp_c = -25.0, .ohm = 125550 },
264 { .temp_c = -20.0, .ohm = 94143 },
265 { .temp_c = -15.0, .ohm = 71172 },
266 { .temp_c = -10.0, .ohm = 54308 },
267 { .temp_c = -5.0, .ohm = 41505 },
328 struct iio_channel *channel = pdata->chan; in ntc_adc_iio_read()
340 uv = (pdata->pullup_uv * (s64)raw) >> 12; in ntc_adc_iio_read()
386 struct device_node *np = dev->of_node; in ntc_thermistor_parse_dt()
395 return ERR_PTR(-ENOMEM); in ntc_thermistor_parse_dt()
406 return ERR_PTR(-EINVAL); in ntc_thermistor_parse_dt()
408 if (of_property_read_u32(np, "pullup-uv", &pdata->pullup_uv)) in ntc_thermistor_parse_dt()
409 return ERR_PTR(-ENODEV); in ntc_thermistor_parse_dt()
410 if (of_property_read_u32(np, "pullup-ohm", &pdata->pullup_ohm)) in ntc_thermistor_parse_dt()
411 return ERR_PTR(-ENODEV); in ntc_thermistor_parse_dt()
412 if (of_property_read_u32(np, "pulldown-ohm", &pdata->pulldown_ohm)) in ntc_thermistor_parse_dt()
413 return ERR_PTR(-ENODEV); in ntc_thermistor_parse_dt()
415 if (of_find_property(np, "connected-positive", NULL)) in ntc_thermistor_parse_dt()
416 pdata->connect = NTC_CONNECTED_POSITIVE; in ntc_thermistor_parse_dt()
418 pdata->connect = NTC_CONNECTED_GROUND; in ntc_thermistor_parse_dt()
420 pdata->chan = chan; in ntc_thermistor_parse_dt()
421 pdata->read_uv = ntc_adc_iio_read; in ntc_thermistor_parse_dt()
447 struct ntc_thermistor_platform_data *pdata = data->pdata; in get_ohm_of_thermistor()
448 u32 puv = pdata->pullup_uv; in get_ohm_of_thermistor()
450 puo = pdata->pullup_ohm; in get_ohm_of_thermistor()
451 pdo = pdata->pulldown_ohm; in get_ohm_of_thermistor()
454 return (pdata->connect == NTC_CONNECTED_POSITIVE) ? in get_ohm_of_thermistor()
457 return (pdata->connect == NTC_CONNECTED_POSITIVE) ? in get_ohm_of_thermistor()
460 if (pdata->connect == NTC_CONNECTED_POSITIVE && puo == 0) in get_ohm_of_thermistor()
461 n = div_u64(pdo * (puv - uv), uv); in get_ohm_of_thermistor()
462 else if (pdata->connect == NTC_CONNECTED_GROUND && pdo == 0) in get_ohm_of_thermistor()
463 n = div_u64(puo * uv, puv - uv); in get_ohm_of_thermistor()
464 else if (pdata->connect == NTC_CONNECTED_POSITIVE) in get_ohm_of_thermistor()
465 n = div64_u64_safe(pdo * puo * (puv - uv), in get_ohm_of_thermistor()
466 puo * uv - pdo * (puv - uv)); in get_ohm_of_thermistor()
468 n = div64_u64_safe(pdo * puo * uv, pdo * (puv - uv) - puo * uv); in get_ohm_of_thermistor()
481 * Handle special cases: Resistance is higher than or equal to in lookup_comp()
482 * resistance in first table entry, or resistance is lower or equal in lookup_comp()
483 * to resistance in last table entry. in lookup_comp()
485 * beginning or to the end of the table depending on the condition. in lookup_comp()
487 if (ohm >= data->comp[0].ohm) { in lookup_comp()
492 if (ohm <= data->comp[data->n_comp - 1].ohm) { in lookup_comp()
493 *i_low = data->n_comp - 1; in lookup_comp()
494 *i_high = data->n_comp - 1; in lookup_comp()
498 /* Do a binary search on compensation table */ in lookup_comp()
500 end = data->n_comp; in lookup_comp()
502 mid = start + (end - start) / 2; in lookup_comp()
505 * data->comp[start].ohm > ohm >= data->comp[end].ohm in lookup_comp()
507 * We could check for "ohm == data->comp[mid].ohm" here, but in lookup_comp()
512 if (ohm >= data->comp[mid].ohm) { in lookup_comp()
517 * ohm >= data->comp[start].ohm might be true here, in lookup_comp()
522 if (ohm >= data->comp[start].ohm) in lookup_comp()
527 * data->comp[start].ohm >= ohm >= data->comp[end].ohm in lookup_comp()
532 * ohm >= data->comp[end].ohm in lookup_comp()
535 if (ohm == data->comp[end].ohm) in lookup_comp()
538 *i_high = end - 1; in lookup_comp()
544 int temp; in get_temp_mc() local
549 temp = data->comp[low].temp_c * 1000; in get_temp_mc()
551 temp = data->comp[low].temp_c * 1000 + in get_temp_mc()
552 ((data->comp[high].temp_c - data->comp[low].temp_c) * in get_temp_mc()
553 1000 * ((int)ohm - (int)data->comp[low].ohm)) / in get_temp_mc()
554 ((int)data->comp[high].ohm - (int)data->comp[low].ohm); in get_temp_mc()
556 return temp; in get_temp_mc()
563 if (data->pdata->read_ohm) in ntc_thermistor_get_ohm()
564 return data->pdata->read_ohm(); in ntc_thermistor_get_ohm()
566 if (data->pdata->read_uv) { in ntc_thermistor_get_ohm()
567 read_uv = data->pdata->read_uv(data->pdata); in ntc_thermistor_get_ohm()
572 return -EINVAL; in ntc_thermistor_get_ohm()
600 return -EINVAL; in ntc_read()
620 HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_TYPE),
636 struct device *dev = &pdev->dev; in ntc_thermistor_probe()
652 return -ENODEV; in ntc_thermistor_probe()
656 if (!pdata->read_uv && !pdata->read_ohm) { in ntc_thermistor_probe()
659 return -EINVAL; in ntc_thermistor_probe()
662 if (pdata->read_uv && pdata->read_ohm) { in ntc_thermistor_probe()
665 pdata->read_uv = NULL; in ntc_thermistor_probe()
668 if (pdata->read_uv && (pdata->pullup_uv == 0 || in ntc_thermistor_probe()
669 (pdata->pullup_ohm == 0 && pdata->connect == in ntc_thermistor_probe()
671 (pdata->pulldown_ohm == 0 && pdata->connect == in ntc_thermistor_probe()
673 (pdata->connect != NTC_CONNECTED_POSITIVE && in ntc_thermistor_probe()
674 pdata->connect != NTC_CONNECTED_GROUND))) { in ntc_thermistor_probe()
676 return -EINVAL; in ntc_thermistor_probe()
681 return -ENOMEM; in ntc_thermistor_probe()
683 pdev_id = of_id ? of_id->data : platform_get_device_id(pdev); in ntc_thermistor_probe()
685 data->pdata = pdata; in ntc_thermistor_probe()
687 if (pdev_id->driver_data >= ARRAY_SIZE(ntc_type)) { in ntc_thermistor_probe()
689 pdev_id->driver_data, pdev_id->name); in ntc_thermistor_probe()
690 return -EINVAL; in ntc_thermistor_probe()
693 data->comp = ntc_type[pdev_id->driver_data].comp; in ntc_thermistor_probe()
694 data->n_comp = ntc_type[pdev_id->driver_data].n_comp; in ntc_thermistor_probe()
696 hwmon_dev = devm_hwmon_device_register_with_info(dev, pdev_id->name, in ntc_thermistor_probe()
705 pdev_id->name); in ntc_thermistor_probe()
712 .name = "ntc-thermistor",
724 MODULE_ALIAS("platform:ntc-thermistor");