aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/olpc_battery.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power/olpc_battery.c')
-rw-r--r--drivers/power/olpc_battery.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index 5fbca2681baa..58e419299cd6 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -8,6 +8,7 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10 10
11#include <linux/kernel.h>
11#include <linux/module.h> 12#include <linux/module.h>
12#include <linux/err.h> 13#include <linux/err.h>
13#include <linux/platform_device.h> 14#include <linux/platform_device.h>
@@ -35,6 +36,7 @@
35#define BAT_STAT_AC 0x10 36#define BAT_STAT_AC 0x10
36#define BAT_STAT_CHARGING 0x20 37#define BAT_STAT_CHARGING 0x20
37#define BAT_STAT_DISCHARGING 0x40 38#define BAT_STAT_DISCHARGING 0x40
39#define BAT_STAT_TRICKLE 0x80
38 40
39#define BAT_ERR_INFOFAIL 0x02 41#define BAT_ERR_INFOFAIL 0x02
40#define BAT_ERR_OVERVOLTAGE 0x04 42#define BAT_ERR_OVERVOLTAGE 0x04
@@ -89,7 +91,7 @@ static char bat_serial[17]; /* Ick */
89static int olpc_bat_get_status(union power_supply_propval *val, uint8_t ec_byte) 91static int olpc_bat_get_status(union power_supply_propval *val, uint8_t ec_byte)
90{ 92{
91 if (olpc_platform_info.ecver > 0x44) { 93 if (olpc_platform_info.ecver > 0x44) {
92 if (ec_byte & BAT_STAT_CHARGING) 94 if (ec_byte & (BAT_STAT_CHARGING | BAT_STAT_TRICKLE))
93 val->intval = POWER_SUPPLY_STATUS_CHARGING; 95 val->intval = POWER_SUPPLY_STATUS_CHARGING;
94 else if (ec_byte & BAT_STAT_DISCHARGING) 96 else if (ec_byte & BAT_STAT_DISCHARGING)
95 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; 97 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
@@ -219,7 +221,8 @@ static int olpc_bat_get_property(struct power_supply *psy,
219 It doesn't matter though -- the EC will return the last-known 221 It doesn't matter though -- the EC will return the last-known
220 information, and it's as if we just ran that _little_ bit faster 222 information, and it's as if we just ran that _little_ bit faster
221 and managed to read it out before the battery went away. */ 223 and managed to read it out before the battery went away. */
222 if (!(ec_byte & BAT_STAT_PRESENT) && psp != POWER_SUPPLY_PROP_PRESENT) 224 if (!(ec_byte & (BAT_STAT_PRESENT | BAT_STAT_TRICKLE)) &&
225 psp != POWER_SUPPLY_PROP_PRESENT)
223 return -ENODEV; 226 return -ENODEV;
224 227
225 switch (psp) { 228 switch (psp) {
@@ -229,7 +232,8 @@ static int olpc_bat_get_property(struct power_supply *psy,
229 return ret; 232 return ret;
230 break; 233 break;
231 case POWER_SUPPLY_PROP_PRESENT: 234 case POWER_SUPPLY_PROP_PRESENT:
232 val->intval = !!(ec_byte & BAT_STAT_PRESENT); 235 val->intval = !!(ec_byte & (BAT_STAT_PRESENT |
236 BAT_STAT_TRICKLE));
233 break; 237 break;
234 238
235 case POWER_SUPPLY_PROP_HEALTH: 239 case POWER_SUPPLY_PROP_HEALTH:
@@ -334,21 +338,21 @@ static ssize_t olpc_bat_eeprom_read(struct kobject *kobj,
334 struct bin_attribute *attr, char *buf, loff_t off, size_t count) 338 struct bin_attribute *attr, char *buf, loff_t off, size_t count)
335{ 339{
336 uint8_t ec_byte; 340 uint8_t ec_byte;
337 int ret, end; 341 int ret;
342 int i;
338 343
339 if (off >= EEPROM_SIZE) 344 if (off >= EEPROM_SIZE)
340 return 0; 345 return 0;
341 if (off + count > EEPROM_SIZE) 346 if (off + count > EEPROM_SIZE)
342 count = EEPROM_SIZE - off; 347 count = EEPROM_SIZE - off;
343 348
344 end = EEPROM_START + off + count; 349 for (i = 0; i < count; i++) {
345 for (ec_byte = EEPROM_START + off; ec_byte < end; ec_byte++) { 350 ec_byte = EEPROM_START + off + i;
346 ret = olpc_ec_cmd(EC_BAT_EEPROM, &ec_byte, 1, 351 ret = olpc_ec_cmd(EC_BAT_EEPROM, &ec_byte, 1, &buf[i], 1);
347 &buf[ec_byte - EEPROM_START], 1);
348 if (ret) { 352 if (ret) {
349 printk(KERN_ERR "olpc-battery: EC command " 353 pr_err("olpc-battery: "
350 "EC_BAT_EEPROM @ 0x%x failed -" 354 "EC_BAT_EEPROM cmd @ 0x%x failed - %d!\n",
351 " %d!\n", ec_byte, ret); 355 ec_byte, ret);
352 return -EIO; 356 return -EIO;
353 } 357 }
354 } 358 }