aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorKim, Milo <Milo.Kim@ti.com>2012-08-31 05:24:28 -0400
committerAnton Vorontsov <anton.vorontsov@linaro.org>2012-09-20 21:00:55 -0400
commitb1ad079680b24386d12aa99dd9afd4eb7093bbee (patch)
tree4e5abc11573948c8d7fdd7f4ad3a2e42bcda63ed /drivers/power
parent638555d2769b7dfb8654bae513cff295ea9a3837 (diff)
lp8727_charger: Fix code for getting battery temp
For better understanding, use specific function and definitions rather than magic numbers. New enum type for die temperature is matched with hex codes. Specific temperature names are better than 0x1, 0x2 and 0x3. And lp8727_is_high_temperature() function has better readability than comparing raw register values. Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com> Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/lp8727_charger.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c
index b5567bc99000..1a5f4b27e001 100644
--- a/drivers/power/lp8727_charger.c
+++ b/drivers/power/lp8727_charger.c
@@ -58,6 +58,7 @@
58 58
59/* STATUS2 register */ 59/* STATUS2 register */
60#define TEMP_STAT (3 << 5) 60#define TEMP_STAT (3 << 5)
61#define TEMP_SHIFT 5
61 62
62enum lp8727_dev_id { 63enum lp8727_dev_id {
63 ID_NONE, 64 ID_NONE,
@@ -75,6 +76,13 @@ enum lp8727_chg_stat {
75 EOC, 76 EOC,
76}; 77};
77 78
79enum lp8727_die_temp {
80 LP8788_TEMP_75C,
81 LP8788_TEMP_95C,
82 LP8788_TEMP_115C,
83 LP8788_TEMP_135C,
84};
85
78struct lp8727_psy { 86struct lp8727_psy {
79 struct power_supply ac; 87 struct power_supply ac;
80 struct power_supply usb; 88 struct power_supply usb;
@@ -315,12 +323,25 @@ static int lp8727_charger_get_property(struct power_supply *psy,
315 return 0; 323 return 0;
316} 324}
317 325
326static bool lp8727_is_high_temperature(enum lp8727_die_temp temp)
327{
328 switch (temp) {
329 case LP8788_TEMP_95C:
330 case LP8788_TEMP_115C:
331 case LP8788_TEMP_135C:
332 return true;
333 default:
334 return false;
335 }
336}
337
318static int lp8727_battery_get_property(struct power_supply *psy, 338static int lp8727_battery_get_property(struct power_supply *psy,
319 enum power_supply_property psp, 339 enum power_supply_property psp,
320 union power_supply_propval *val) 340 union power_supply_propval *val)
321{ 341{
322 struct lp8727_chg *pchg = dev_get_drvdata(psy->dev->parent); 342 struct lp8727_chg *pchg = dev_get_drvdata(psy->dev->parent);
323 struct lp8727_platform_data *pdata = pchg->pdata; 343 struct lp8727_platform_data *pdata = pchg->pdata;
344 enum lp8727_die_temp temp;
324 u8 read; 345 u8 read;
325 346
326 switch (psp) { 347 switch (psp) {
@@ -337,11 +358,11 @@ static int lp8727_battery_get_property(struct power_supply *psy,
337 break; 358 break;
338 case POWER_SUPPLY_PROP_HEALTH: 359 case POWER_SUPPLY_PROP_HEALTH:
339 lp8727_read_byte(pchg, STATUS2, &read); 360 lp8727_read_byte(pchg, STATUS2, &read);
340 read = (read & TEMP_STAT) >> 5; 361 temp = (read & TEMP_STAT) >> TEMP_SHIFT;
341 if (read >= 0x1 && read <= 0x3) 362
342 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; 363 val->intval = lp8727_is_high_temperature(temp) ?
343 else 364 POWER_SUPPLY_HEALTH_OVERHEAT :
344 val->intval = POWER_SUPPLY_HEALTH_GOOD; 365 POWER_SUPPLY_HEALTH_GOOD;
345 break; 366 break;
346 case POWER_SUPPLY_PROP_PRESENT: 367 case POWER_SUPPLY_PROP_PRESENT:
347 if (!pdata) 368 if (!pdata)