#include <linux/iio/consumer.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/thermal.h>
struct gadc_thermal_info {
struct thermal_zone_device *tz_dev;
struct iio_channel *channel;
static int gadc_thermal_adc_to_temp(struct gadc_thermal_info *gti, int val)
int temp, temp_hi, temp_lo, adc_hi, adc_lo;
for (i = 0; i < gti->nlookup_table; i++) {
if (val >= gti->lookup_table[2 * i + 1])
temp = gti->lookup_table[0];
} else if (i >= gti->nlookup_table) {
temp = gti->lookup_table[2 * (gti->nlookup_table - 1)];
adc_hi = gti->lookup_table[2 * i - 1];
adc_lo = gti->lookup_table[2 * i + 1];
temp_hi = gti->lookup_table[2 * i - 2];
temp_lo = gti->lookup_table[2 * i];
temp = temp_hi + mult_frac(temp_lo - temp_hi, val - adc_hi,
static int gadc_thermal_get_temp(void *data, int *temp)
struct gadc_thermal_info *gti = data;
ret = iio_read_channel_processed(gti->channel, &val);
dev_err(gti->dev, "IIO channel read failed %d\n", ret);