Thermal: generic_adc_thermal: Add second value read back on read channel raw
Jinyoung Park [Fri, 21 Jun 2013 06:53:20 +0000 (15:53 +0900)]
Added second value read back on read channel raw.

Bug 1287901

Signed-off-by: Jinyoung Park <jinyoungp@nvidia.com>
Reviewed-on: http://git-master/r/241374
(cherry picked from commit 59aa8e57f663512f4489c11984673bc87e9a5738)

Change-Id: I0bde33c4cb16e1c500b0cf86b64ec3e84e9a61d7
Signed-off-by: Jinyoung Park <jinyoungp@nvidia.com>
Reviewed-on: http://git-master/r/252880
Reviewed-by: Mrutyunjay Sawant <msawant@nvidia.com>
Tested-by: Mrutyunjay Sawant <msawant@nvidia.com>

arch/arm/mach-tegra/board-tegratab-sensors.c
drivers/thermal/generic_adc_thermal.c
include/linux/generic_adc_thermal.h

index 06f1df7..1ce050d 100644 (file)
@@ -738,14 +738,14 @@ static struct ntc_thermistor_adc_table thermistor_table[] = {
 };
 
 static int gadc_thermal_thermistor_adc_to_temp(
-               struct gadc_thermal_platform_data *pdata, int val)
+               struct gadc_thermal_platform_data *pdata, int *val, int *val2)
 {
        int table_size = ARRAY_SIZE(thermistor_table);
        int temp = 0, adc_hi, adc_lo;
        int i;
 
        for (i = 0; i < table_size; i++)
-               if (val >= thermistor_table[i].adc)
+               if (*val >= thermistor_table[i].adc)
                        break;
 
        if (i == 0) {
@@ -756,18 +756,18 @@ static int gadc_thermal_thermistor_adc_to_temp(
                adc_hi = thermistor_table[i - 1].adc;
                adc_lo = thermistor_table[i].adc;
                temp = thermistor_table[i - 1].temp * 1000;
-               temp += ((val - adc_lo) * 1000 / (adc_hi - adc_lo));
+               temp += ((*val - adc_lo) * 1000 / (adc_hi - adc_lo));
        }
 
        return temp;
 };
 
 static int gadc_thermal_tdiode_adc_to_temp(
-               struct gadc_thermal_platform_data *pdata, int val)
+               struct gadc_thermal_platform_data *pdata, int *val, int *val2)
 {
        /* TODO: add adc raw to temp conversion. */
        pr_warn("%s: No adc raw to temp conversion.\n", __func__);
-       return val;
+       return *val;
 };
 
 static struct gadc_thermal_platform_data gadc_thermal_thermistor_pdata = {
index e2f0555..486bd26 100644 (file)
@@ -46,22 +46,23 @@ static int gadc_thermal_get_temp(struct thermal_zone_device *tz,
                                 unsigned long *temp)
 {
        struct gadc_thermal_driver_data *drvdata = tz->devdata;
-       int val;
+       struct gadc_thermal_platform_data *pdata = drvdata->pdata;
+       int val, val2 = 0;
        int ret;
 
-       ret = iio_st_read_channel_raw(drvdata->channel, &val);
+       ret = iio_st_read_channel_raw(drvdata->channel, &val, &val2);
        if (ret < 0) {
                dev_err(drvdata->dev, "%s: Failed to read channel, %d\n",
                        __func__, ret);
                return ret;
        }
 
-       if (drvdata->pdata->adc_to_temp)
-               *temp = drvdata->pdata->adc_to_temp(drvdata->pdata, val);
+       if (pdata->adc_to_temp)
+               *temp = pdata->adc_to_temp(pdata, &val, &val2);
        else
                *temp = val;
 
-       *temp += drvdata->pdata->temp_offset;
+       *temp += pdata->temp_offset;
        return 0;
 }
 
@@ -73,24 +74,24 @@ static struct thermal_zone_device_ops gadc_thermal_ops = {
 static int adc_temp_show(struct seq_file *s, void *p)
 {
        struct gadc_thermal_driver_data *drvdata = s->private;
-       int adc, temp;
+       struct gadc_thermal_platform_data *pdata = drvdata->pdata;
+       int val, val2 = 0, temp;
        int ret;
 
-       ret = iio_st_read_channel_raw(drvdata->channel, &adc);
+       ret = iio_st_read_channel_raw(drvdata->channel, &val, &val2);
        if (ret < 0) {
                dev_err(drvdata->dev, "%s: Failed to read channel, %d\n",
                        __func__, ret);
                return ret;
        }
 
-       if (drvdata->pdata->adc_to_temp)
-               temp = drvdata->pdata->adc_to_temp(drvdata->pdata, adc);
+       if (pdata->adc_to_temp)
+               temp = pdata->adc_to_temp(pdata, &val, &val2);
        else
-               temp = adc;
+               temp = val;
 
-       temp += drvdata->pdata->temp_offset;
-
-       seq_printf(s, "%d %d\n", adc, temp);
+       temp += pdata->temp_offset;
+       seq_printf(s, "%d %d %d\n", val, val2, temp);
        return 0;
 }
 
index 0ab3323..4c060ce 100644 (file)
@@ -29,6 +29,6 @@ struct gadc_thermal_platform_data {
        const char *iio_channel_name;
        const char *tz_name;
        int temp_offset; /* mC */
-       int (*adc_to_temp)(struct gadc_thermal_platform_data *pdata, int val);
+       int (*adc_to_temp)(struct gadc_thermal_platform_data *, int *, int *);
 };
 #endif /* GENERIC_ADC_THERMAL_H */