aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/olpc_battery.c
diff options
context:
space:
mode:
authorAndres Salomon <dilinger@collabora.co.uk>2009-06-30 02:15:26 -0400
committerAnton Vorontsov <cbouatmailru@gmail.com>2009-06-30 18:48:37 -0400
commit144bbeaedc53290eab21da82ce1cb5faefd14374 (patch)
treebbcbe31427ae566955323a3f988bb0f8569c49ff /drivers/power/olpc_battery.c
parentb294a290d24d1196d68399cc3a9b8c50bfb55abd (diff)
olpc_battery: Add an 'error' sysfs device that displays raw errors
Grab the error code from EC_BAT_ERRCODE and let the user see it (rather than attempting to decode it as we do with PROP_HEALTH) with a separate error sysfs file. Signed-off-by: Andres Salomon <dilinger@collabora.co.uk> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
Diffstat (limited to 'drivers/power/olpc_battery.c')
-rw-r--r--drivers/power/olpc_battery.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index 3a589df09376..602bbd008f78 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -10,7 +10,9 @@
10 10
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/types.h>
13#include <linux/err.h> 14#include <linux/err.h>
15#include <linux/device.h>
14#include <linux/platform_device.h> 16#include <linux/platform_device.h>
15#include <linux/power_supply.h> 17#include <linux/power_supply.h>
16#include <linux/jiffies.h> 18#include <linux/jiffies.h>
@@ -379,6 +381,29 @@ static struct bin_attribute olpc_bat_eeprom = {
379 .read = olpc_bat_eeprom_read, 381 .read = olpc_bat_eeprom_read,
380}; 382};
381 383
384/* Allow userspace to see the specific error value pulled from the EC */
385
386static ssize_t olpc_bat_error_read(struct device *dev,
387 struct device_attribute *attr, char *buf)
388{
389 uint8_t ec_byte;
390 ssize_t ret;
391
392 ret = olpc_ec_cmd(EC_BAT_ERRCODE, NULL, 0, &ec_byte, 1);
393 if (ret < 0)
394 return ret;
395
396 return sprintf(buf, "%d\n", ec_byte);
397}
398
399static struct device_attribute olpc_bat_error = {
400 .attr = {
401 .name = "error",
402 .mode = S_IRUGO,
403 },
404 .show = olpc_bat_error_read,
405};
406
382/********************************************************************* 407/*********************************************************************
383 * Initialisation 408 * Initialisation
384 *********************************************************************/ 409 *********************************************************************/
@@ -442,8 +467,14 @@ static int __init olpc_bat_init(void)
442 if (ret) 467 if (ret)
443 goto eeprom_failed; 468 goto eeprom_failed;
444 469
470 ret = device_create_file(olpc_bat.dev, &olpc_bat_error);
471 if (ret)
472 goto error_failed;
473
445 goto success; 474 goto success;
446 475
476error_failed:
477 device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom);
447eeprom_failed: 478eeprom_failed:
448 power_supply_unregister(&olpc_bat); 479 power_supply_unregister(&olpc_bat);
449battery_failed: 480battery_failed:
@@ -456,6 +487,7 @@ success:
456 487
457static void __exit olpc_bat_exit(void) 488static void __exit olpc_bat_exit(void)
458{ 489{
490 device_remove_file(olpc_bat.dev, &olpc_bat_error);
459 device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom); 491 device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom);
460 power_supply_unregister(&olpc_bat); 492 power_supply_unregister(&olpc_bat);
461 power_supply_unregister(&olpc_ac); 493 power_supply_unregister(&olpc_ac);