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>
30 * Used as index in a zero-terminated array, holes not allowed so
60 * A compensation table should be sorted by the values of .ohm
66 { .temp_c = -40, .ohm = 1747920 },
67 { .temp_c = -35, .ohm = 1245428 },
68 { .temp_c = -30, .ohm = 898485 },
69 { .temp_c = -25, .ohm = 655802 },
70 { .temp_c = -20, .ohm = 483954 },
71 { .temp_c = -15, .ohm = 360850 },
72 { .temp_c = -10, .ohm = 271697 },
73 { .temp_c = -5, .ohm = 206463 },
102 { .temp_c = -40, .ohm = 1610154 },
103 { .temp_c = -35, .ohm = 1130850 },
104 { .temp_c = -30, .ohm = 802609 },
105 { .temp_c = -25, .ohm = 575385 },
106 { .temp_c = -20, .ohm = 416464 },
107 { .temp_c = -15, .ohm = 304219 },
108 { .temp_c = -10, .ohm = 224193 },
109 { .temp_c = -5, .ohm = 166623 },
139 { .temp_c = -40, .ohm = 4397119 },
140 { .temp_c = -35, .ohm = 3088599 },
141 { .temp_c = -30, .ohm = 2197225 },
142 { .temp_c = -25, .ohm = 1581881 },
143 { .temp_c = -20, .ohm = 1151037 },
144 { .temp_c = -15, .ohm = 846579 },
145 { .temp_c = -10, .ohm = 628988 },
146 { .temp_c = -5, .ohm = 471632 },
176 { .temp_c = -40, .ohm = 247565 },
177 { .temp_c = -35, .ohm = 181742 },
178 { .temp_c = -30, .ohm = 135128 },
179 { .temp_c = -25, .ohm = 101678 },
180 { .temp_c = -20, .ohm = 77373 },
181 { .temp_c = -15, .ohm = 59504 },
182 { .temp_c = -10, .ohm = 46222 },
183 { .temp_c = -5, .ohm = 36244 },
217 { .temp_c = -40, .ohm = 190030 },
218 { .temp_c = -35, .ohm = 145360 },
219 { .temp_c = -30, .ohm = 112060 },
220 { .temp_c = -25, .ohm = 87041 },
221 { .temp_c = -20, .ohm = 68104 },
222 { .temp_c = -15, .ohm = 53665 },
223 { .temp_c = -10, .ohm = 42576 },
224 { .temp_c = -5, .ohm = 34001 },
254 { .temp_c = -55.0, .ohm = 878900 },
255 { .temp_c = -50.0, .ohm = 617590 },
256 { .temp_c = -45.0, .ohm = 439340 },
257 { .temp_c = -40.0, .ohm = 316180 },
258 { .temp_c = -35.0, .ohm = 230060 },
259 { .temp_c = -30.0, .ohm = 169150 },
260 { .temp_c = -25.0, .ohm = 125550 },
261 { .temp_c = -20.0, .ohm = 94143 },
262 { .temp_c = -15.0, .ohm = 71172 },
263 { .temp_c = -10.0, .ohm = 54308 },
264 { .temp_c = -5.0, .ohm = 41505 },
325 struct iio_channel *channel = pdata->chan; in ntc_adc_iio_read()
345 uv = (pdata->pullup_uv * (s64)raw) >> 12; in ntc_adc_iio_read()
392 struct device_node *np = dev->of_node; in ntc_thermistor_parse_dt()
401 return ERR_PTR(-ENOMEM); in ntc_thermistor_parse_dt()
412 return ERR_PTR(-EINVAL); in ntc_thermistor_parse_dt()
414 if (of_property_read_u32(np, "pullup-uv", &pdata->pullup_uv)) in ntc_thermistor_parse_dt()
415 return ERR_PTR(-ENODEV); in ntc_thermistor_parse_dt()
416 if (of_property_read_u32(np, "pullup-ohm", &pdata->pullup_ohm)) in ntc_thermistor_parse_dt()
417 return ERR_PTR(-ENODEV); in ntc_thermistor_parse_dt()
418 if (of_property_read_u32(np, "pulldown-ohm", &pdata->pulldown_ohm)) in ntc_thermistor_parse_dt()
419 return ERR_PTR(-ENODEV); in ntc_thermistor_parse_dt()
421 if (of_find_property(np, "connected-positive", NULL)) in ntc_thermistor_parse_dt()
422 pdata->connect = NTC_CONNECTED_POSITIVE; in ntc_thermistor_parse_dt()
424 pdata->connect = NTC_CONNECTED_GROUND; in ntc_thermistor_parse_dt()
426 pdata->chan = chan; in ntc_thermistor_parse_dt()
427 pdata->read_uv = ntc_adc_iio_read; in ntc_thermistor_parse_dt()
453 struct ntc_thermistor_platform_data *pdata = data->pdata; in get_ohm_of_thermistor()
454 u32 puv = pdata->pullup_uv; in get_ohm_of_thermistor()
456 puo = pdata->pullup_ohm; in get_ohm_of_thermistor()
457 pdo = pdata->pulldown_ohm; in get_ohm_of_thermistor()
460 return (pdata->connect == NTC_CONNECTED_POSITIVE) ? in get_ohm_of_thermistor()
463 return (pdata->connect == NTC_CONNECTED_POSITIVE) ? in get_ohm_of_thermistor()
466 if (pdata->connect == NTC_CONNECTED_POSITIVE && puo == 0) in get_ohm_of_thermistor()
467 n = div_u64(pdo * (puv - uv), uv); in get_ohm_of_thermistor()
468 else if (pdata->connect == NTC_CONNECTED_GROUND && pdo == 0) in get_ohm_of_thermistor()
469 n = div_u64(puo * uv, puv - uv); in get_ohm_of_thermistor()
470 else if (pdata->connect == NTC_CONNECTED_POSITIVE) in get_ohm_of_thermistor()
471 n = div64_u64_safe(pdo * puo * (puv - uv), in get_ohm_of_thermistor()
472 puo * uv - pdo * (puv - uv)); in get_ohm_of_thermistor()
474 n = div64_u64_safe(pdo * puo * uv, pdo * (puv - uv) - puo * uv); in get_ohm_of_thermistor()
487 * Handle special cases: Resistance is higher than or equal to in lookup_comp()
488 * resistance in first table entry, or resistance is lower or equal in lookup_comp()
489 * to resistance in last table entry. in lookup_comp()
491 * beginning or to the end of the table depending on the condition. in lookup_comp()
493 if (ohm >= data->comp[0].ohm) { in lookup_comp()
498 if (ohm <= data->comp[data->n_comp - 1].ohm) { in lookup_comp()
499 *i_low = data->n_comp - 1; in lookup_comp()
500 *i_high = data->n_comp - 1; in lookup_comp()
504 /* Do a binary search on compensation table */ in lookup_comp()
506 end = data->n_comp; in lookup_comp()
508 mid = start + (end - start) / 2; in lookup_comp()
511 * data->comp[start].ohm > ohm >= data->comp[end].ohm in lookup_comp()
513 * We could check for "ohm == data->comp[mid].ohm" here, but in lookup_comp()
518 if (ohm >= data->comp[mid].ohm) { in lookup_comp()
523 * ohm >= data->comp[start].ohm might be true here, in lookup_comp()
528 if (ohm >= data->comp[start].ohm) in lookup_comp()
533 * data->comp[start].ohm >= ohm >= data->comp[end].ohm in lookup_comp()
538 * ohm >= data->comp[end].ohm in lookup_comp()
541 if (ohm == data->comp[end].ohm) in lookup_comp()
544 *i_high = end - 1; in lookup_comp()
550 int temp; in get_temp_mc() local
554 * First multiplying the table temperatures with 1000 to get to in get_temp_mc()
558 temp = fixp_linear_interpolate(data->comp[low].ohm, in get_temp_mc()
559 data->comp[low].temp_c * 1000, in get_temp_mc()
560 data->comp[high].ohm, in get_temp_mc()
561 data->comp[high].temp_c * 1000, in get_temp_mc()
563 return temp; in get_temp_mc()
570 if (data->pdata->read_ohm) in ntc_thermistor_get_ohm()
571 return data->pdata->read_ohm(); in ntc_thermistor_get_ohm()
573 if (data->pdata->read_uv) { in ntc_thermistor_get_ohm()
574 read_uv = data->pdata->read_uv(data->pdata); in ntc_thermistor_get_ohm()
579 return -EINVAL; in ntc_thermistor_get_ohm()
607 return -EINVAL; in ntc_read()
627 HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_TYPE),
643 struct device *dev = &pdev->dev; in ntc_thermistor_probe()
659 return -ENODEV; in ntc_thermistor_probe()
663 if (!pdata->read_uv && !pdata->read_ohm) { in ntc_thermistor_probe()
666 return -EINVAL; in ntc_thermistor_probe()
669 if (pdata->read_uv && pdata->read_ohm) { in ntc_thermistor_probe()
672 pdata->read_uv = NULL; in ntc_thermistor_probe()
675 if (pdata->read_uv && (pdata->pullup_uv == 0 || in ntc_thermistor_probe()
676 (pdata->pullup_ohm == 0 && pdata->connect == in ntc_thermistor_probe()
678 (pdata->pulldown_ohm == 0 && pdata->connect == in ntc_thermistor_probe()
680 (pdata->connect != NTC_CONNECTED_POSITIVE && in ntc_thermistor_probe()
681 pdata->connect != NTC_CONNECTED_GROUND))) { in ntc_thermistor_probe()
683 return -EINVAL; in ntc_thermistor_probe()
688 return -ENOMEM; in ntc_thermistor_probe()
690 pdev_id = of_id ? of_id->data : platform_get_device_id(pdev); in ntc_thermistor_probe()
692 data->pdata = pdata; in ntc_thermistor_probe()
694 if (pdev_id->driver_data >= ARRAY_SIZE(ntc_type)) { in ntc_thermistor_probe()
696 pdev_id->driver_data, pdev_id->name); in ntc_thermistor_probe()
697 return -EINVAL; in ntc_thermistor_probe()
700 data->comp = ntc_type[pdev_id->driver_data].comp; in ntc_thermistor_probe()
701 data->n_comp = ntc_type[pdev_id->driver_data].n_comp; in ntc_thermistor_probe()
703 hwmon_dev = devm_hwmon_device_register_with_info(dev, pdev_id->name, in ntc_thermistor_probe()
712 pdev_id->name); in ntc_thermistor_probe()
719 .name = "ntc-thermistor",
731 MODULE_ALIAS("platform:ntc-thermistor");