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()
123 if (!pdev->dev.of_node) { in gadc_thermal_probe()
124 dev_err(&pdev->dev, "Only DT based supported\n"); in gadc_thermal_probe()
125 return -ENODEV; in gadc_thermal_probe()
128 gti = devm_kzalloc(&pdev->dev, sizeof(*gti), GFP_KERNEL); in gadc_thermal_probe()
130 return -ENOMEM; in gadc_thermal_probe()
132 gti->channel = devm_iio_channel_get(&pdev->dev, "sensor-channel"); in gadc_thermal_probe()
133 if (IS_ERR(gti->channel)) { in gadc_thermal_probe()
134 ret = PTR_ERR(gti->channel); in gadc_thermal_probe()
135 if (ret != -EPROBE_DEFER) in gadc_thermal_probe()
136 dev_err(&pdev->dev, "IIO channel not found: %d\n", ret); in gadc_thermal_probe()
140 ret = gadc_thermal_read_linear_lookup_table(&pdev->dev, gti); in gadc_thermal_probe()
144 gti->dev = &pdev->dev; in gadc_thermal_probe()
146 gti->tz_dev = devm_thermal_of_zone_register(&pdev->dev, 0, gti, in gadc_thermal_probe()
148 if (IS_ERR(gti->tz_dev)) { in gadc_thermal_probe()
149 ret = PTR_ERR(gti->tz_dev); in gadc_thermal_probe()
150 if (ret != -EPROBE_DEFER) in gadc_thermal_probe()
151 dev_err(&pdev->dev, in gadc_thermal_probe()
152 "Thermal zone sensor register failed: %d\n", in gadc_thermal_probe()
157 devm_thermal_add_hwmon_sysfs(&pdev->dev, gti->tz_dev); in gadc_thermal_probe()
163 { .compatible = "generic-adc-thermal", },
170 .name = "generic-adc-thermal",
179 MODULE_DESCRIPTION("Generic ADC thermal driver using IIO framework with DT");