power:palmas_battery: get battery temperature from battery gauge core
Laxman Dewangan [Wed, 26 Jun 2013 09:59:15 +0000 (14:59 +0530)]
In place of reading the battery temperature from the ADC directly and
calculating the temp based on the ADC raw data, get the temperature
from battery gauge core driver.

bug 1259466

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/242406
(cherry picked from commit 29ddc88b6f05737173514e31ad774a22dc4e8e7a)

Change-Id: I506a65bee5cbdf04e3706daf895dabde155f8239
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/253360
Reviewed-by: Simone Willett <swillett@nvidia.com>
Tested-by: Simone Willett <swillett@nvidia.com>

drivers/power/palmas_battery.c
include/linux/mfd/palmas.h

index 1f26974..1abe411 100644 (file)
@@ -52,7 +52,6 @@
 
 /* GPADC Channels */
 #define VBAT_CHANNEL           "vbat_channel"
-#define TEMP_CHANNEL           "temp_channel"
 
 /* Voltage that that is used for the EDV */
 #define EDV_VOLTAGE     (cell->config->edv->averaging ? \
@@ -625,32 +624,14 @@ static void palmas_battery_voltage_now(struct palmas_battery_info *di)
        di->battery_voltage_uV = ret*1000;
 }
 
-static void palmas_battery_temperature(struct palmas_battery_info *di)
-{
-       int temp, adc_code, ret;
-
-       ret = palmas_gpadc_conversion(TEMP_CHANNEL);
-       if (ret < 0)
-               dev_err(di->dev, "Error in Battery Voltage conversion\n");
-
-       adc_code = ret;
-       for (temp = 0; temp < di->battery_temperature_chart_size; temp++) {
-               if (adc_code >= di->battery_temperature_chart[temp])
-                       break;
-       }
-       /*
-        * first 2 values are for negative temperature
-        * temperature in tenths of degree Celsius
-        */
-       di->battery_termperature_tenthC = (temp - 2) * 10;
-}
-
 static int palmas_battery_get_props(struct power_supply *psy,
                                enum power_supply_property psp,
                                        union power_supply_propval *val)
 {
        struct palmas_battery_info *di = container_of(psy,
                struct palmas_battery_info, battery);
+       int temp;
+       int ret;
 
        switch (psp) {
        case POWER_SUPPLY_PROP_TECHNOLOGY:
@@ -671,8 +652,10 @@ static int palmas_battery_get_props(struct power_supply *psy,
                val->intval = di->battery_current_uA;
                break;
        case POWER_SUPPLY_PROP_TEMP:
-               palmas_battery_temperature(di);
-               val->intval = di->battery_termperature_tenthC;
+               ret = battery_gauge_get_battery_temperature(di->bg_dev, &temp);
+               if (ret < 0)
+                       return -EINVAL;
+               val->intval = temp * 10;
                break;
        case POWER_SUPPLY_PROP_ONLINE:
                val->intval = (di->battery_online || di->battery_soldered);
@@ -1631,6 +1614,7 @@ static int palmas_battery_probe(struct platform_device *pdev)
                return ret;
        }
 
+       palmas_battery_gauge_info.tz_name = pdata->therm_zone_name;
        di->bg_dev = battery_gauge_register(di->dev, &palmas_battery_gauge_info);
        if (IS_ERR(di->bg_dev)) {
                ret = PTR_ERR(di->bg_dev);
index 3183e52..44ce29b 100644 (file)
@@ -546,6 +546,7 @@ struct palmas_extcon_platform_data {
 };
 
 struct palmas_battery_platform_data {
+       const char *therm_zone_name;
        /* Battery Values */
        int battery_soldered; /* if battery detection should not be used */
        int battery_status_interval; /* time in ms for charge status polling */