Lines Matching +full:generic +full:- +full:adc +full:- +full:thermal

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Generic ADC thermal driver
14 #include <linux/thermal.h>
31 if (!gti->lookup_table) in gadc_thermal_adc_to_temp()
34 for (i = 0; i < gti->nlookup_table; i++) { in gadc_thermal_adc_to_temp()
35 if (val >= gti->lookup_table[2 * i + 1]) in gadc_thermal_adc_to_temp()
40 temp = gti->lookup_table[0]; in gadc_thermal_adc_to_temp()
41 } else if (i >= gti->nlookup_table) { in gadc_thermal_adc_to_temp()
42 temp = gti->lookup_table[2 * (gti->nlookup_table - 1)]; in gadc_thermal_adc_to_temp()
44 adc_hi = gti->lookup_table[2 * i - 1]; in gadc_thermal_adc_to_temp()
45 adc_lo = gti->lookup_table[2 * i + 1]; in gadc_thermal_adc_to_temp()
47 temp_hi = gti->lookup_table[2 * i - 2]; in gadc_thermal_adc_to_temp()
48 temp_lo = gti->lookup_table[2 * i]; in gadc_thermal_adc_to_temp()
50 temp = temp_hi + mult_frac(temp_lo - temp_hi, val - adc_hi, in gadc_thermal_adc_to_temp()
51 adc_lo - adc_hi); in gadc_thermal_adc_to_temp()
63 ret = iio_read_channel_processed(gti->channel, &val); in gadc_thermal_get_temp()
79 struct device_node *np = dev->of_node; in gadc_thermal_read_linear_lookup_table()
84 ntable = of_property_count_elems_of_size(np, "temperature-lookup-table", in gadc_thermal_read_linear_lookup_table()
87 ret = iio_get_channel_type(gti->channel, &chan_type); in gadc_thermal_read_linear_lookup_table()
95 dev_err(dev, "Pair of temperature vs ADC read value missing\n"); in gadc_thermal_read_linear_lookup_table()
96 return -EINVAL; in gadc_thermal_read_linear_lookup_table()
99 gti->lookup_table = devm_kcalloc(dev, in gadc_thermal_read_linear_lookup_table()
100 ntable, sizeof(*gti->lookup_table), in gadc_thermal_read_linear_lookup_table()
102 if (!gti->lookup_table) in gadc_thermal_read_linear_lookup_table()
103 return -ENOMEM; in gadc_thermal_read_linear_lookup_table()
105 ret = of_property_read_u32_array(np, "temperature-lookup-table", in gadc_thermal_read_linear_lookup_table()
106 (u32 *)gti->lookup_table, ntable); in gadc_thermal_read_linear_lookup_table()
113 gti->nlookup_table = ntable / 2; in gadc_thermal_read_linear_lookup_table()
120 struct device *dev = &pdev->dev; in gadc_thermal_probe()
124 if (!dev->of_node) { in gadc_thermal_probe()
126 return -ENODEV; in gadc_thermal_probe()
131 return -ENOMEM; in gadc_thermal_probe()
133 gti->channel = devm_iio_channel_get(dev, "sensor-channel"); in gadc_thermal_probe()
134 if (IS_ERR(gti->channel)) in gadc_thermal_probe()
135 return dev_err_probe(dev, PTR_ERR(gti->channel), "IIO channel not found\n"); in gadc_thermal_probe()
141 gti->dev = dev; in gadc_thermal_probe()
143 gti->tz_dev = devm_thermal_of_zone_register(dev, 0, gti, in gadc_thermal_probe()
145 if (IS_ERR(gti->tz_dev)) { in gadc_thermal_probe()
146 ret = PTR_ERR(gti->tz_dev); in gadc_thermal_probe()
147 if (ret != -EPROBE_DEFER) in gadc_thermal_probe()
149 "Thermal zone sensor register failed: %d\n", in gadc_thermal_probe()
154 devm_thermal_add_hwmon_sysfs(dev, gti->tz_dev); in gadc_thermal_probe()
160 { .compatible = "generic-adc-thermal", },
167 .name = "generic-adc-thermal",
176 MODULE_DESCRIPTION("Generic ADC thermal driver using IIO framework with DT");