Battery class driver.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Adding Richard Hughes and David Zeuthen, since they will actually have to talk to your batter class and driver.
Quoted 683 lines · David Woodhouse
At
git://git.infradead.org/battery-2.6.gitthere is an initial implementation of a battery class, along with a driver which makes use of it. The patch is below, and also viewable at
http://git.infradead.org/?p=battery-2.6.git;a=commitdiff;h=master;hp=linusI don't like the sysfs interaction much -- is it really necessary for me to provide a separate function for each attribute, rather than a single function which handles them all and is given the individual attribute as an argument? That seems strange and bloated.
I'm half tempted to ditch the sysfs attributes and just use a single
seq_file, in fact.The idea is that all batteries should be presented to userspace through this class instead of through the existing mess of PMU/APM/ACPI and even APM _emulation_.
I think I probably want to make AC power a separate 'device' too, rather than an attribute of any given battery. And when there are multiple power supplies, there should be multiple such devices. So maybe it should be a 'power supply' class, not a battery class at all?
Comments?
commit
42fe507a262b2a2879ca62740c5312778ae78627Author: David Woodhouse <[email protected]> Date: Mon Oct 23 18:14:54 2006 +0100[BATTERY] Add support for OLPC battery
Signed-off-by David Woodhouse <[email protected]>commit
6cbec3b84e3ce737b4217788841ea10a28a5e340Author: David Woodhouse <[email protected]> Date: Mon Oct 23 18:14:14 2006 +0100[BATTERY] Add initial implementation of battery class
I really don't like the sysfs interaction, and I don't much like the internal interaction with the battery drivers either. In fact, there isn't much I _do_ like, but it's good enough as a straw man.
Signed-off-by David Woodhouse <[email protected]>Makefile renamed from Makefile~ +1
-0@@ -30,6 +30,7 @@ obj-$(CONFIG_PARPORT) += parport/ obj-y += base/ block/ misc/ mfd/ net/ media/ obj-$(CONFIG_NUBUS) += nubus/ obj-$(CONFIG_ATM) += atm/ +obj-$(CONFIG_BATTERY_CLASS) += battery/ obj-$(CONFIG_PPC_PMAC) += macintosh/ obj-$(CONFIG_XEN) += xen/ obj-$(CONFIG_IDE) += ide/Kconfig renamed from Kconfig~ +2
-0@@ -28,6 +28,8 @@ source "drivers/ieee1394/Kconfig" source "drivers/message/i2o/Kconfig" +source "drivers/battery/Kconfig" + source "drivers/macintosh/Kconfig" source "drivers/net/Kconfig"battery/Makefile new file +4
-0@@ -0,0 +1,4 @@ +# Battery code +obj-$(CONFIG_BATTERY_CLASS) += battery-class.o + +obj-$(CONFIG_OLPC_BATTERY) += olpc-battery.obattery/Kconfig new file +22
-0@@ -0,0 +1,22 @@ + +menu "Battery support" + +config BATTERY_CLASS + tristate "Battery support" + help + Say Y to enable battery class support. This allows a battery + information to be presented in a uniform manner for all types + of batteries. + + Battery information from APM and ACPI is not yet available by + this method, but should soon be. If you use APM or ACPI, say + 'N', although saying 'Y' would be harmless. + +config OLPC_BATTERY + tristate "One Laptop Per Child battery" + depends on BATTERY_CLASS && X86_32 + help + Say Y to enable support for the battery on the $100 laptop. + + +endmenubattery/battery-class.c new file +286
-0@@ -0,0 +1,286 @@ +/* +* Battery class core +* +* © 2006 David Woodhouse <[email protected]> +* +* Based on LED Class support, by John Lenz and Richard Purdie: +* +* © 2005 John Lenz <[email protected]> +* © 2005-2006 Richard Purdie <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/device.h> +#include <linux/battery.h> +#include <linux/spinlock.h> +#include <linux/err.h> + +static struct class *battery_class; + +/* OMFG we can't just have a single 'show' routine which is given the +'class_attribute' as an argument -- we have to have 20-odd copies +of almost identical routines */ + +static ssize_t battery_attribute_show_int (struct class_device *dev,char *buf,int attr) +{ +struct battery_classdev *battery_cdev =class_get_devdata (dev); +ssize_t ret =0 ; +long value; + + ret = battery_cdev->query_long (battery_cdev, attr, &value); +if (ret) +return ret; + +sprintf (buf,"%ld\n" , value); + ret =strlen (buf) +1 ; + +return ret; +} + +static ssize_t battery_attribute_show_milli (struct class_device *dev,char *buf,int attr) +{ +struct battery_classdev *battery_cdev =class_get_devdata (dev); +ssize_t ret =0 ; +long value; + + ret = battery_cdev->query_long (battery_cdev, attr, &value); +if (ret) +return ret; + +sprintf (buf,"%ld.%03ld\n" , value/1000 , value %1000 ); + ret =strlen (buf) +1 ; +return ret; +} + +static ssize_t battery_attribute_show_string (struct class_device *dev,char *buf,int attr) +{ +struct battery_classdev *battery_cdev =class_get_devdata (dev); +ssize_t ret =0 ; + + ret = battery_cdev->query_str (battery_cdev, attr, buf,PAGE_SIZE -1 ); +if (ret) +return ret; + +strcat (buf,"\n" ); + ret =strlen (buf) +1 ; +return ret; +} + +static ssize_t battery_attribute_show_status (struct class_device *dev,char *buf) +{ +struct battery_classdev *battery_cdev =class_get_devdata (dev); +ssize_t ret =0 ; +unsigned long status; + + status = battery_cdev->status (battery_cdev, ~BAT_STAT_AC ); +if (status &BAT_STAT_ERROR ) +return -EIO ; + +if (status &BAT_STAT_PRESENT ) +sprintf (buf,"present" ); +else +sprintf (buf,"absent" ); + +if (status &BAT_STAT_LOW ) +strcat (buf,",low" ); + +if (status &BAT_STAT_FULL ) +strcat (buf,",full" ); + +if (status &BAT_STAT_CHARGING ) +strcat (buf,",charging" ); + +if (status &BAT_STAT_DISCHARGING ) +strcat (buf,",discharging" ); + +if (status &BAT_STAT_OVERTEMP ) +strcat (buf,",overtemp" ); + +if (status &BAT_STAT_FIRE ) +strcat (buf,",on-fire" ); + +if (status &BAT_STAT_CHARGE_DONE ) +strcat (buf,",charge-done" ); + +strcat (buf,"\n" ); + ret =strlen (buf) +1 ; +return ret; +} + +static ssize_t battery_attribute_show_ac_status (struct class_device *dev,char *buf) +{ +struct battery_classdev *battery_cdev =class_get_devdata (dev); +ssize_t ret =0 ; +unsigned long status; + + status = battery_cdev->status (battery_cdev,BAT_STAT_AC ); +if (status &BAT_STAT_ERROR ) +return -EIO ; + +if (status &BAT_STAT_AC ) +sprintf (buf,"on-line" ); +else +sprintf (buf,"off-line" ); + +strcat (buf,"\n" ); + ret =strlen (buf) +1 ; +return ret; +} + +/* Ew. We can't even use CLASS_DEVICE_ATTR() if we want one named 'current' */ +#define BATTERY_DEVICE_ATTR (_name, _attr, _type) \ +static ssize_t battery_attr_show_##_attr(struct class_device *dev, char *buf) \ +{ \ + return battery_attribute_show_##_type(dev, buf, BAT_INFO_##_attr); \ +} \ +static struct class_device_attribute class_device_attr_##_attr = { \ + .attr = { .name = _name, .mode = 0444, .owner = THIS_MODULE }, \ + .show = battery_attr_show_##_attr }; + +static CLASS_DEVICE_ATTR(status,0444,battery_attribute_show_status, NULL); +static CLASS_DEVICE_ATTR(ac,0444,battery_attribute_show_ac_status, NULL); +BATTERY_DEVICE_ATTR ("temp1" ,TEMP1 ,milli); +BATTERY_DEVICE_ATTR ("temp1_name" ,TEMP1_NAME ,string); +BATTERY_DEVICE_ATTR ("temp2" ,TEMP2 ,milli); +BATTERY_DEVICE_ATTR ("temp2_name" ,TEMP2_NAME ,string); +BATTERY_DEVICE_ATTR ("voltage" ,VOLTAGE ,milli); +BATTERY_DEVICE_ATTR ("voltage_design" ,VOLTAGE_DESIGN ,milli); +BATTERY_DEVICE_ATTR ("current" ,CURRENT ,milli); +BATTERY_DEVICE_ATTR ("charge_rate" ,CHARGE_RATE ,milli); +BATTERY_DEVICE_ATTR ("charge_max" ,CHARGE_MAX ,milli); +BATTERY_DEVICE_ATTR ("charge_last" ,CHARGE_LAST ,milli); +BATTERY_DEVICE_ATTR ("charge_low" ,CHARGE_LOW ,milli); +BATTERY_DEVICE_ATTR ("charge_warn" ,CHARGE_WARN ,milli); +BATTERY_DEVICE_ATTR ("charge_unit" ,CHARGE_UNITS ,string); +BATTERY_DEVICE_ATTR ("charge_percent" ,CHARGE_PCT ,int); +BATTERY_DEVICE_ATTR ("time_remaining" ,TIME_REMAINING ,int); +BATTERY_DEVICE_ATTR ("manufacturer" ,MANUFACTURER ,string); +BATTERY_DEVICE_ATTR ("technology" ,TECHNOLOGY ,string); +BATTERY_DEVICE_ATTR ("model" ,MODEL ,string); +BATTERY_DEVICE_ATTR ("serial" ,SERIAL ,string); +BATTERY_DEVICE_ATTR ("type" ,TYPE ,string); +BATTERY_DEVICE_ATTR ("oem_info" ,OEM_INFO ,string); + +#define REGISTER_ATTR (_attr) \ + if (battery_cdev->capabilities & (1<<BAT_INFO_##_attr)) \ + class_device_create_file(battery_cdev->class_dev, \ + &class_device_attr_##_attr); +#define UNREGISTER_ATTR (_attr) \ + if (battery_cdev->capabilities & (1<<BAT_INFO_##_attr)) \ + class_device_remove_file(battery_cdev->class_dev, \ + &class_device_attr_##_attr); +/** +* battery_classdev_register - register a new object of battery_classdev class. +* @dev: The device to register. +* @battery_cdev: the battery_classdev structure for this device. +*/ +int battery_classdev_register (struct device *parent,struct battery_classdev *battery_cdev) +{ + battery_cdev->class_dev =class_device_create (battery_class,NULL ,0 , + parent,"%s" , battery_cdev->name); + +if (unlikely (IS_ERR (battery_cdev->class_dev))) +return PTR_ERR (battery_cdev->class_dev); + +class_set_devdata (battery_cdev->class_dev, battery_cdev); + +/* register the attributes */ +class_device_create_file (battery_cdev->class_dev, + &class_device_attr_status); + +if (battery_cdev->status_cap & (1 <<BAT_STAT_AC )) +class_device_create_file (battery_cdev->class_dev, &class_device_attr_ac); + +REGISTER_ATTR (TEMP1 ); +REGISTER_ATTR (TEMP1_NAME ); +REGISTER_ATTR (TEMP2 ); +REGISTER_ATTR (TEMP2_NAME ); +REGISTER_ATTR (VOLTAGE ); +REGISTER_ATTR (VOLTAGE_DESIGN ); +REGISTER_ATTR (CHARGE_PCT ); +REGISTER_ATTR (CURRENT ); +REGISTER_ATTR (CHARGE_RATE ); +REGISTER_ATTR (CHARGE_MAX ); +REGISTER_ATTR (CHARGE_LAST ); +REGISTER_ATTR (CHARGE_LOW ); +REGISTER_ATTR (CHARGE_WARN ); +REGISTER_ATTR (CHARGE_UNITS ); +REGISTER_ATTR (TIME_REMAINING ); +REGISTER_ATTR (MANUFACTURER ); +REGISTER_ATTR (TECHNOLOGY ); +REGISTER_ATTR (MODEL ); +REGISTER_ATTR (SERIAL ); +REGISTER_ATTR (TYPE ); +REGISTER_ATTR (OEM_INFO ); + +printk (KERN_INFO "Registered battery device: %s\n" , + battery_cdev->class_dev->class_id); + +return 0 ; +} +EXPORT_SYMBOL_GPL (battery_classdev_register); + +/** +* battery_classdev_unregister - unregisters a object of battery_properties class. +* @battery_cdev: the battery device to unreigister +* +* Unregisters a previously registered via battery_classdev_register object. +*/ +void battery_classdev_unregister (struct battery_classdev *battery_cdev) +{ +class_device_remove_file (battery_cdev->class_dev, + &class_device_attr_status); + +if (battery_cdev->status_cap & (1 <<BAT_STAT_AC )) +class_device_remove_file (battery_cdev->class_dev, &class_device_attr_ac); + +UNREGISTER_ATTR (TEMP1 ); +UNREGISTER_ATTR (TEMP1_NAME ); +UNREGISTER_ATTR (TEMP2 ); +UNREGISTER_ATTR (TEMP2_NAME ); +UNREGISTER_ATTR (VOLTAGE ); +UNREGISTER_ATTR (VOLTAGE_DESIGN ); +UNREGISTER_ATTR (CHARGE_PCT ); +UNREGISTER_ATTR (CURRENT ); +UNREGISTER_ATTR (CHARGE_RATE ); +UNREGISTER_ATTR (CHARGE_MAX ); +UNREGISTER_ATTR (CHARGE_LAST ); +UNREGISTER_ATTR (CHARGE_LOW ); +UNREGISTER_ATTR (CHARGE_WARN ); +UNREGISTER_ATTR (CHARGE_UNITS ); +UNREGISTER_ATTR (TIME_REMAINING ); +UNREGISTER_ATTR (MANUFACTURER ); +UNREGISTER_ATTR (TECHNOLOGY ); +UNREGISTER_ATTR (MODEL ); +UNREGISTER_ATTR (SERIAL ); +UNREGISTER_ATTR (TYPE ); +UNREGISTER_ATTR (OEM_INFO ); + +class_device_unregister (battery_cdev->class_dev); +} +EXPORT_SYMBOL_GPL (battery_classdev_unregister); + +static int __init battery_init (void ) +{ + battery_class =class_create (THIS_MODULE ,"battery" ); +if (IS_ERR (battery_class)) +return PTR_ERR (battery_class); +return 0 ; +} + +static void __exit battery_exit(void) +{ +class_destroy (battery_class); +} + +subsys_initcall (battery_init); +module_exit (battery_exit); + +MODULE_AUTHOR ("David Woodhouse <[email protected]>" ); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("Battery class interface" );battery/olpc-battery.c new file +198
-0@@ -0,0 +1,198 @@ +/* +* Battery driver for One Laptop Per Child ($100 laptop) board. +* +* © 2006 David Woodhouse <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/device.h> +#include <linux/battery.h> +#include <linux/spinlock.h> +#include <linux/err.h> +#include <asm/io.h> + +#define wBAT_VOLTAGE 0xf900/* *9.76/32, mV */ +#define wBAT_CURRENT 0xf902/* *15.625/120, mA */ +#define wBAT_TEMP 0xf906/* *256/1000, °C */ +#define wAMB_TEMP 0xf908/* *256/1000, °C */ +#define SOC 0xf910/* percentage */ +#define sMBAT_STATUS 0xfaa4 +#define sBAT_PRESENT 1 +#define sBAT_FULL 2 +#define sBAT_DESTROY 4 +#define sBAT_LOW 32 +#define sBAT_DISCHG 64 +#define sMCHARGE_STATUS 0xfaa5 +#define sBAT_CHARGE 1 +#define sBAT_OVERTEMP 4 +#define sBAT_NiMH 8 +#define sPOWER_FLAG 0xfa40 +#define ADAPTER_IN 1 + +static int lock_ec (void ) +{ +unsigned long timeo = jiffies +HZ /20 ; + +while (1 ) { +unsigned char lock =inb (0x6c ) &0x80 ; +if (!lock) +return 0 ; +if (time_after (jiffies, timeo)) +return 1 ; +yield (); + } +} + +static void unlock_ec (void ) +{ +outb (0xff ,0x6c ); +} + +unsigned char read_ec_byte (unsigned short adr) +{ +outb (adr >>8 ,0x381 ); +outb (adr,0x382 ); +return inb (0x383 ); +} + +unsigned short read_ec_word (unsigned short adr) +{ +return (read_ec_byte (adr) <<8 ) |read_ec_byte (adr+1 ); +} + +unsigned long olpc_bat_status (struct battery_classdev *cdev,unsigned long mask) +{ +unsigned long result =0 ; +unsigned short tmp; + +if (lock_ec ()) { +printk (KERN_ERR "Failed to lock EC for battery access\n" ); +return BAT_STAT_ERROR ; + } + +if (mask &BAT_STAT_AC ) { +if (read_ec_byte (sPOWER_FLAG) &ADAPTER_IN ) + result |=BAT_STAT_AC ; + } +if (mask & (BAT_STAT_PRESENT |BAT_STAT_FULL |BAT_STAT_FIRE |BAT_STAT_LOW |BAT_STAT_DISCHARGING )) { + tmp =read_ec_byte (sMBAT_STATUS); + +if (tmp & sBAT_PRESENT) + result |=BAT_STAT_PRESENT ; +if (tmp & sBAT_FULL) + result |=BAT_STAT_FULL ; +if (tmp & sBAT_DESTROY) + result |=BAT_STAT_FIRE ; +if (tmp & sBAT_LOW) + result |=BAT_STAT_LOW ; +if (tmp & sBAT_DISCHG) + result |=BAT_STAT_DISCHARGING ; + } +if (mask & (BAT_STAT_CHARGING |BAT_STAT_OVERTEMP )) { + tmp =read_ec_byte (sMCHARGE_STATUS); +if (tmp & sBAT_CHARGE) + result |=BAT_STAT_CHARGING ; +if (tmp & sBAT_OVERTEMP) + result |=BAT_STAT_OVERTEMP ; + } +unlock_ec (); +return result; +} + +int olpc_bat_query_long (struct battery_classdev *dev,int attr,long *result) +{ +int ret =0 ; + +if (lock_ec ()) +return -EIO ; + +if (!(read_ec_byte (sMBAT_STATUS) & sBAT_PRESENT)) { + ret = -ENODEV ; + }else if (attr ==BAT_INFO_VOLTAGE ) { + *result =read_ec_word (wBAT_VOLTAGE) *9760 /32000 ; + }else if (attr ==BAT_INFO_CURRENT ) { + *result =read_ec_word (wBAT_CURRENT) *15625 /120000 ; + }else if (attr ==BAT_INFO_TEMP1 ) { + *result =read_ec_word (wBAT_TEMP) *1000 /256 ; + }else if (attr ==BAT_INFO_TEMP2 ) { + *result =read_ec_word (wAMB_TEMP) *1000 /256 ; + }else if (attr ==BAT_INFO_CHARGE_PCT ) { + *result =read_ec_byte (SOC ); + }else + ret = -EINVAL ; + +unlock_ec (); +return ret; +} + +int olpc_bat_query_str (struct battery_classdev *dev,int attr,char *str,int len) +{ +int ret =0 ; + +if (attr ==BAT_INFO_TYPE ) { +snprintf (str, len,"OLPC" ); + }else if (attr ==BAT_INFO_TEMP1_NAME ) { +snprintf (str, len,"battery" ); + }else if (attr ==BAT_INFO_TEMP2_NAME ) { +snprintf (str, len,"ambient" ); + }else if (!(read_ec_byte (sMBAT_STATUS) & sBAT_PRESENT)) { + ret = -ENODEV ; + }else if (attr ==BAT_INFO_TECHNOLOGY ) { +if (lock_ec ()) + ret = -EIO ; +else { +unsigned short tmp =read_ec_byte (sMCHARGE_STATUS); +if (tmp & sBAT_NiMH) +snprintf (str, len,"NiMH" ); +else +snprintf (str, len,"unknown" ); + } +unlock_ec (); + }else { + ret = -EINVAL ; + } + +return ret; +} + +static struct battery_classdev olpc_bat = { + .name ="OLPC" , + .capabilities = (1 <<BAT_INFO_VOLTAGE ) | + (1 <<BAT_INFO_CURRENT ) | + (1 <<BAT_INFO_TEMP1 ) | + (1 <<BAT_INFO_TEMP2 ) | + (1 <<BAT_INFO_CHARGE_PCT ) | + (1 <<BAT_INFO_TYPE ) | + (1 <<BAT_INFO_TECHNOLOGY ) | + (1 <<BAT_INFO_TEMP1_NAME ) | + (1 <<BAT_INFO_TEMP2_NAME ), + .status_cap =BAT_STAT_AC |BAT_STAT_PRESENT |BAT_STAT_LOW | +BAT_STAT_FULL |BAT_STAT_CHARGING |BAT_STAT_DISCHARGING | +BAT_STAT_OVERTEMP |BAT_STAT_FIRE , + .status = olpc_bat_status, + .query_long = olpc_bat_query_long, + .query_str = olpc_bat_query_str, +}; + +void __exit olpc_bat_exit(void) +{ +battery_classdev_unregister (&olpc_bat); +} + +int __init olpc_bat_init (void ) +{ +battery_classdev_register (NULL , &olpc_bat); +return 0 ; +} + +module_init (olpc_bat_init); +module_exit (olpc_bat_exit); + +MODULE_AUTHOR ("David Woodhouse <[email protected]>" ); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("Battery class interface" );linux/battery.h new file +84
-0@@ -0,0 +1,84 @@ +/* +* Driver model for batteries +* +* © 2006 David Woodhouse <[email protected]> +* +* Based on LED Class support, by John Lenz and Richard Purdie: +* +* © 2005 John Lenz <[email protected]> +* © 2005-2006 Richard Purdie <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +*/ +#ifndef __LINUX_BATTERY_H__ +#define __LINUX_BATTERY_H__ + +struct device ; +struct class_device ; + +/* +* Battery Core +*/ +#define BAT_STAT_AC (1<<0) +#define BAT_STAT_PRESENT (1<<1) +#define BAT_STAT_LOW (1<<2) +#define BAT_STAT_FULL (1<<3) +#define BAT_STAT_CHARGING (1<<4) +#define BAT_STAT_DISCHARGING (1<<5) +#define BAT_STAT_OVERTEMP (1<<6) +#define BAT_STAT_FIRE (1<<7) +#define BAT_STAT_CHARGE_DONE (1<<8) + +#define BAT_STAT_ERROR (1<<31) + +#define BAT_INFO_TEMP1 (0)/* °C/1000 */ +#define BAT_INFO_TEMP1_NAME (1)/* string */ + +#define BAT_INFO_TEMP2 (2)/* °C/1000 */ +#define BAT_INFO_TEMP2_NAME (3)/* string */ + +#define BAT_INFO_VOLTAGE (4)/* mV */ +#define BAT_INFO_VOLTAGE_DESIGN (5)/* mV */ + +#define BAT_INFO_CURRENT (6)/* mA */ + +#define BAT_INFO_CHARGE_RATE (7)/* BAT_INFO_CHARGE_UNITS */ +#define BAT_INFO_CHARGE (8)/* BAT_INFO_CHARGE_UNITS */ +#define BAT_INFO_CHARGE_MAX (9)/* BAT_INFO_CHARGE_UNITS */ +#define BAT_INFO_CHARGE_LAST (10)/* BAT_INFO_CHARGE_UNITS */ +#define BAT_INFO_CHARGE_LOW (11)/* BAT_INFO_CHARGE_UNITS */ +#define BAT_INFO_CHARGE_WARN (12)/* BAT_INFO_CHARGE_UNITS */ +#define BAT_INFO_CHARGE_UNITS (13)/* string */ +#define BAT_INFO_CHARGE_PCT (14)/* % */ + +#define BAT_INFO_TIME_REMAINING (15)/* seconds */ + +#define BAT_INFO_MANUFACTURER (16)/* string */ +#define BAT_INFO_TECHNOLOGY (17)/* string */ +#define BAT_INFO_MODEL (18)/* string */ +#define BAT_INFO_SERIAL (19)/* string */ +#define BAT_INFO_TYPE (20)/* string */ +#define BAT_INFO_OEM_INFO (21)/* string */ + +struct battery_classdev { +const char *name; +/* Capabilities of this battery driver */ +unsigned long capabilities, status_cap; + +/* Query functions */ +unsigned long (*status)(struct battery_classdev *,unsigned long mask); +int (*query_long)(struct battery_classdev *,int attr,long *result); +int (*query_str)(struct battery_classdev *,int attr,char *str,ssize_t len); + +struct class_device *class_dev; +struct list_head node;/* Battery Device list */ +}; + +extern int battery_classdev_register (struct device *parent, +struct battery_classdev *battery_cdev); +extern void battery_classdev_unregister (struct battery_classdev *battery_cdev); + +#endif /* __LINUX_BATTERY_H__ */ Signature · 6 lines
-- dwmw2 _______________________________________________ Devel mailing list [email protected] http://mailman.laptop.org/mailman/listinfo/devel
Quoted 2 lines · Dan Williams
Adding Richard Hughes and David Zeuthen, since they will actually have to talk to your batter class and driver.
Cool, thanks.
Quoted 6 lines · David Woodhouse
Quoted 5 lines
At
git://git.infradead.org/battery-2.6.gitthere is an initial implementation of a battery class, along with a driver which makes use of it. The patch is below, and also viewable at
http://git.infradead.org/?p=battery-2.6.git;a=commitdiff;h=master;hp=linus
Quoted 7 lines
Quoted 7 lines
I don't like the sysfs interaction much -- is it really necessary for me to provide a separate function for each attribute, rather than a single function which handles them all and is given the individual attribute as an argument? That seems strange and bloated.
I'm half tempted to ditch the sysfs attributes and just use a single
seq_file, in fact.
I can't comment on the kernel implementation side of it much, but see below.
Quoted 3 lines
Quoted 3 lines
The idea is that all batteries should be presented to userspace through this class instead of through the existing mess of PMU/APM/ACPI and even APM _emulation_.
Ohh yes. This would make the battery code in HAL so much better. There is so much legacy crud for batteries that we have to wade through in HAL. A battery kernel class is a very good idea IMO.
Quoted 4 lines
Quoted 4 lines
I think I probably want to make AC power a separate 'device' too, rather than an attribute of any given battery. And when there are multiple power supplies, there should be multiple such devices. So maybe it should be a 'power supply' class, not a battery class at all?
No, I think the distinction between batteries and ac_adapter is large enough to have different classes of devices. You may have many batteries, but you'll only ever have one ac_adapter. I'm not sure it's an obvious abstraction to make.
Quoted 1 line
Quoted 1 line
Comments?
How are battery change notifications delivered to userspace? I know acpi is using the input layer for buttons in the future (very sane IMO), so using sysfs events for each property changing would probably be nice.
Comments on your patch:
Quoted 1 line
+#define
BAT_INFO_TEMP2(2) /* °C/1000 */
Temperature expressed in degrees C/1000? - what if the temperature goes below 0? What about just using mK (kelvin / 1000) - I don't know what is used in the kernel elsewhere tho. Also, are you allowed the ° sign in kernel source now?
Quoted 1 line
+#define
BAT_INFO_CURRENT(6) /* mA */
Can't this also be expressed in mW according to the ACPI spec?
Quoted 1 line
+#define
BAT_STAT_FIRE(1<<7)
I know there is precedent for "FIRE" but maybe CRITICAL or DANGER might be better chosen words. We can reserve the word FIRE for when the faulty battery really is going to explode...
Richard.
Quoted 19 lines
Quoted 19 lines
commit
42fe507a262b2a2879ca62740c5312778ae78627Author: David Woodhouse <[email protected]> Date: Mon Oct 23 18:14:54 2006 +0100[BATTERY] Add support for OLPC battery
Signed-off-by David Woodhouse <[email protected]>commit
6cbec3b84e3ce737b4217788841ea10a28a5e340Author: David Woodhouse <[email protected]> Date: Mon Oct 23 18:14:14 2006 +0100[BATTERY] Add initial implementation of battery class
I really don't like the sysfs interaction, and I don't much like the internal interaction with the battery drivers either. In fact, there isn't much I _do_ like, but it's good enough as a straw man.
Signed-off-by David Woodhouse <[email protected]>
Quoted 4 lines
No, I think the distinction between batteries and
ac_adapteris large enough to have different classes of devices. You may have many batteries, but you'll only ever have oneac_adapter. I'm not sure it's an obvious abstraction to make.
Speaking from ignorance here, but what about (big) systems that have multiple power supplies and multiple rails of AC power? Would it make sense to use the same abstraction for that as well as laptop AC adaptors?
Quoted 4 lines · Richard Hughes
No, I think the distinction between batteries and
ac_adapteris large enough to have different classes of devices. You may have many batteries, but you'll only ever have oneac_adapter. I'm not sure it's an obvious abstraction to make.
∃ machines with more than one individual AC adapter. Which want individual notification when one of them goes down.
You're right that they don't necessarily fit into the 'battery' class, but I'm not entirely sure if it's worth putting them elsewhere, because the information about them is usually available in the same place as the information about the batteries, at least in the laptop case.
The simple case of AC adapters, where we have only 'present' or 'absent', is a subset of what batteries can do. If you have more complicated monitoring, then it's _also_ going to bear a remarkable similarity to what you get from batteries -- you'll be able to monitor temperatures, voltage, current, etc. So they're not _that_ much out of place in a 'power supply' class.
It makes _less_ sense, imho, to have 'ac present' as a property of a battery -- which is what I've done for now.
Quoted 3 lines
How are battery change notifications delivered to userspace? I know acpi is using the input layer for buttons in the future (very sane IMO), so using sysfs events for each property changing would probably be nice.
For selected properties, yes. I wouldn't want it happening every time the current draw changes by a millivolt but for 'battery removed' or 'ac power applied' events it makes some sense.
For sane hardware where we get an interrupt on such changes, that's fine -- but I'm wary of having to implement that by making the kernel poll for them; especially if/when there's nothing in userspace which cares.
Quoted 5 lines
Comments on your patch:
Quoted 1 line
+#define
BAT_INFO_TEMP2(2) /* °C/1000 */Temperature expressed in degrees C/1000? - what if the temperature goes below 0?
It's signed.
Quoted 3 lines
What about just using mK (kelvin / 1000) - I don't know what is used in the kernel elsewhere tho. Also, are you allowed the ° sign in kernel source now?
Welcome to the 21st century.
Quoted 2 lines
Quoted 1 line
+#define
BAT_INFO_CURRENT(6) /* mA */Can't this also be expressed in mW according to the ACPI spec?
No, it can't. The Watt is not a unit of current.
I intended the ACPI 'present rate' to map to the 'charge_rate' property, which is why we have the 'charge_unit' property. I don't like that much, but it seems necessary unless we're going to do something like separate 'charge_rate_mA' and 'charge_rate_mW' properties.
Actually, I suspect that on reflection I would prefer that latter option. DavidZ?
Quoted 4 lines
Quoted 1 line
+#define
BAT_STAT_FIRE(1<<7)I know there is precedent for "FIRE" but maybe CRITICAL or DANGER might be better chosen words. We can reserve the word FIRE for when the faulty battery really is going to explode...
Yes, feasibly. I don't quite know what the 'destroy' bit in the OLPC embedded controller is supposed to mean, and 'FIRE' seemed as good as anything else.
Signature · 1 line
dwmw2
Quoted 3 lines
It makes _less_ sense, imho, to have 'ac present' as a property of a battery -- which is what I've done for now.
Then maybe it's better to call it "in_use" meaning that the system is currently drawing power from that battery rather than "ac_present"...
Ben.
Quoted 6 lines · David Woodhouse
Quoted 4 lines · Richard Hughes
No, I think the distinction between batteries and
ac_adapteris large enough to have different classes of devices. You may have many batteries, but you'll only ever have oneac_adapter. I'm not sure it's an obvious abstraction to make.
Quoted 7 lines
∃ machines with more than one individual AC adapter. Which want individual notification when one of them goes down.
You're right that they don't necessarily fit into the 'battery' class, but I'm not entirely sure if it's worth putting them elsewhere, because the information about them is usually available in the same place as the information about the batteries, at least in the laptop case.
Sure, makes sense I guess.
Quoted 6 lines
The simple case of AC adapters, where we have only 'present' or 'absent', is a subset of what batteries can do. If you have more complicated monitoring, then it's _also_ going to bear a remarkable similarity to what you get from batteries -- you'll be able to monitor temperatures, voltage, current, etc. So they're not _that_ much out of place in a 'power supply' class.
Sure, psu could be a nice class. We would need buy-in from ACPI, APM and PMU maintainers to avoid just creating *another* standard that HAL has to read.
Quoted 2 lines
It makes _less_ sense, imho, to have 'ac present' as a property of a battery -- which is what I've done for now.
Agree.
Quoted 7 lines
Quoted 3 lines
How are battery change notifications delivered to userspace? I know acpi is using the input layer for buttons in the future (very sane IMO), so using sysfs events for each property changing would probably be nice.
For selected properties, yes. I wouldn't want it happening every time the current draw changes by a millivolt but for 'battery removed' or 'ac power applied' events it makes some sense.
Maybe still send events for large changes, like > whole % changes in value. Then HAL hasn't got to poll at all.
Quoted 3 lines
For sane hardware where we get an interrupt on such changes, that's fine -- but I'm wary of having to implement that by making the kernel poll for them; especially if/when there's nothing in userspace which cares.
HAL and gnome-power-manager? There should only be a few changing values on charging and discharging, and one every percentage point change isn't a lot.
Quoted 7 lines
Quoted 5 lines
Comments on your patch:
Quoted 1 line
+#define
BAT_INFO_TEMP2(2) /* °C/1000 */Temperature expressed in degrees C/1000? - what if the temperature goes below 0?
It's signed.
Sure, n/p.
Quoted 5 lines
Quoted 3 lines
What about just using mK (kelvin / 1000) - I don't know what is used in the kernel elsewhere tho. Also, are you allowed the ° sign in kernel source now?
Welcome to the 21st century.
Fair play. :-)
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
+#define
BAT_INFO_CURRENT(6) /* mA */Can't this also be expressed in mW according to the ACPI spec?
No, it can't. The Watt is not a unit of current.
Ahh, current as in electron flow, rather than current power use, apologies.
Quoted 4 lines
I intended the ACPI 'present rate' to map to the '
charge_rate' property, which is why we have the 'charge_unit' property. I don't like that much, but it seems necessary unless we're going to do something like separate 'charge_rate_mA' and 'charge_rate_mW' properties.
Not sure how to best do this for the kernel - maybe just expose the value and the format separately. In HAL we normalise the rate to mWh anyway using the rate in mAh and reported voltage.
Quoted 11 lines
Actually, I suspect that on reflection I would prefer that latter option. DavidZ?
Quoted 4 lines
Quoted 1 line
+#define
BAT_STAT_FIRE(1<<7)I know there is precedent for "FIRE" but maybe CRITICAL or DANGER might be better chosen words. We can reserve the word FIRE for when the faulty battery really is going to explode...
Yes, feasibly. I don't quite know what the 'destroy' bit in the OLPC embedded controller is supposed to mean, and 'FIRE' seemed as good as anything else.
Then maybe just set present to false as a destroyed battery isn't much use anyway...
Richard.
Quoted 2 lines · Richard Hughes
We would need buy-in from ACPI, APM and PMU maintainers to avoid just
creating *another* standard that HAL has to read.
That's the whole point in what I'm doing, yes. And that's why the owners of that code are Cc'd.
Quoted 10 lines
Quoted 7 lines
Quoted 3 lines
How are battery change notifications delivered to userspace? I know acpi is using the input layer for buttons in the future (very sane IMO), so using sysfs events for each property changing would probably be nice.
For selected properties, yes. I wouldn't want it happening every time the current draw changes by a millivolt but for 'battery removed' or 'ac power applied' events it makes some sense.
Maybe still send events for large changes, like > whole % changes in value. Then HAL hasn't got to poll at all.
Yes, perhaps. I'm still reluctant to make the kernel poll when the hardware isn't sensible enough to provide interrupts -- I think we should leave that to be implemented later, if at all. Let's get the basic reporting implemented first.
Quoted 7 lines
Quoted 3 lines
For sane hardware where we get an interrupt on such changes, that's fine -- but I'm wary of having to implement that by making the kernel poll for them; especially if/when there's nothing in userspace which cares.
HAL and gnome-power-manager? There should only be a few changing values on charging and discharging, and one every percentage point change isn't a lot.
My point is that if HAL isn't running, we shouldn't bother to poll. If HAL _is_ running, then _it_ could poll, if the hardware isn't capable of generating events. But let's leave that on the TODO list for now.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
+#define
BAT_INFO_CURRENT(6) /* mA */Can't this also be expressed in mW according to the ACPI spec?
No, it can't. The Watt is not a unit of current.
Ahh, current as in electron flow, rather than current power use, apologies.
Indeed. That's one of the measurements I get from the OLPC battery controller.
Quoted 8 lines
Quoted 4 lines
I intended the ACPI 'present rate' to map to the '
charge_rate' property, which is why we have the 'charge_unit' property. I don't like that much, but it seems necessary unless we're going to do something like separate 'charge_rate_mA' and 'charge_rate_mW' properties.Not sure how to best do this for the kernel - maybe just expose the value and the format separately. In HAL we normalise the rate to mWh anyway using the rate in mAh and reported voltage.
In that case, perhaps we should do the same in the kernel. But I think I prefer to expose the 'raw' data.
Quoted 6 lines
Quoted 3 lines
Yes, feasibly. I don't quite know what the 'destroy' bit in the OLPC embedded controller is supposed to mean, and 'FIRE' seemed as good as anything else.
Then maybe just set present to false as a destroyed battery isn't much use anyway...
Hm, I've now seen it say 'destroy', after leaving it on battery overnight till it shut down. When I applied power again, the battery voltage claimed to be about 2½ volts and the 'destroy' flag was set. It did seem to charge it up again though -- and it definitely wasn't on fire :)
Updated patch in git://git.infradead.org/battery-2.6.git and below. I've redone it to be more like hwmon, as suggested. Individual battery 'drivers' are now responsible for creating their own sysfs files directly, instead of it being done by the core. I've added a list of strings to battery.h which are the _only_ names I want to see in sysfs, with specified units. Obviously we can continue to extend those -- and one of the things I plan is to remove 'charge_units' and provide both 'design_charge' and 'design_energy' (also {energy,charge}_last, _*_thresh etc.) to cover the mWh vs. mAh cases.
I haven't (yet) changed from a single 'status' file to multiple 'is_flag_0' 'is_flag_1' 'is_flag_2' files. I really don't like that idea much -- it doesn't seem any more sensible than exposing each bit of the voltage value through a separate file. These flags are _read_ together, and _used_ together. I'd rather show it as a hex value 'flags' than split it up. But I still think that the current 'present,charging,low' is best.
commit 0aa9acc1c47dbb3c285d61bb55a1a363433c129f
Author: David Woodhouse <[email protected]> Date: Tue Oct 24 16:14:59 2006 +0100
[BATTERY] Update OLPC battery driver
- Use platform_device
- Implement all available status fields
commit 0513b2f5473f1e8bb8880c9dee8e1d63af86336e
Author: David Woodhouse <[email protected]> Date: Tue Oct 24 09:56:46 2006 +0100
[BATTERY] Switch to using device_attribute, from the hardware driver
... instead of the core battery class. Various other cleanups.
commit 74e2a48a77347d348e9ed21576863d0d9b51c690
Author: Greg KH <[email protected]> Date: Tue Oct 24 09:39:31 2006 +0100
[BATTERY] Convert to struct device instead of class_device
From: Greg KH <[email protected]>
commit 42fe507a262b2a2879ca62740c5312778ae78627
Author: David Woodhouse <[email protected]> Date: Mon Oct 23 18:14:54 2006 +0100
[BATTERY] Add support for OLPC battery
commit 6cbec3b84e3ce737b4217788841ea10a28a5e340
Author: David Woodhouse <[email protected]> Date: Mon Oct 23 18:14:14 2006 +0100
[BATTERY] Add initial implementation of battery class
I really don't like the sysfs interaction, and I don't much like the internal interaction with the battery drivers either. In fact, there isn't much I _do_ like, but it's good enough as a straw man.
drivers/Kconfig +2 -0
@@ -34,6 +34,8 @@ source "drivers/ieee1394/Kconfig" source "drivers/message/i2o/Kconfig" +source "drivers/battery/Kconfig" + source "drivers/macintosh/Kconfig" source "drivers/net/Kconfig"
drivers/Makefile +1 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_PARPORT) += parport/ obj-y += base/ block/ misc/ mfd/ net/ media/ obj-$(CONFIG_NUBUS) += nubus/ obj-$(CONFIG_ATM) += atm/ +obj-$(CONFIG_BATTERY_CLASS) += battery/ obj-$(CONFIG_PPC_PMAC) += macintosh/ obj-$(CONFIG_IDE) += ide/ obj-$(CONFIG_FC4) += fc4/
drivers/battery/Kconfig new file +22 -0
@@ -0,0 +1,22 @@ + +menu "Battery support" + +config BATTERY_CLASS + tristate "Battery support" + help + Say Y to enable battery class support. This allows a battery + information to be presented in a uniform manner for all types + of batteries. + + Battery information from APM and ACPI is not yet available by + this method, but should soon be. If you use APM or ACPI, say + 'N', although saying 'Y' would be harmless. + +config OLPC_BATTERY + tristate "One Laptop Per Child battery" + depends on BATTERY_CLASS && X86_32 + help + Say Y to enable support for the battery on the $100 laptop. + + +endmenu
drivers/battery/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# Battery code +obj-$(CONFIG_BATTERY_CLASS) += battery-class.o + +obj-$(CONFIG_OLPC_BATTERY) += olpc-battery.o
drivers/battery/battery-class.c new file +177 -0
177 lines not on this page · raw message
drivers/battery/olpc-battery.c new file +335 -0
335 lines not on this page · raw message
include/linux/battery.h new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
dwmw2
Hi David,
Quoted 7 lines · David Woodhouse
Quoted 7 lines
Quoted 3 lines
For sane hardware where we get an interrupt on such changes, that's fine -- but I'm wary of having to implement that by making the kernel poll for them; especially if/when there's nothing in userspace which cares.
HAL and gnome-power-manager? There should only be a few changing values on charging and discharging, and one every percentage point change isn't a lot.
What about current and power? These change very quickly.
BTW, your patch doesn't address the instantaneous vs. average readout issue in the Smart Battery Data Specification and ThinkPads. Nor a number of other issues I brought up earlier.
Quoted 3 lines
My point is that if HAL isn't running, we shouldn't bother to poll. If HAL _is_ running, then _it_ could poll, if the hardware isn't capable of generating events. But let's leave that on the TODO list for now.
Agreed.
Quoted 3 lines
one of the things I plan is to remove '
charge_units' and provide both 'design_charge' and 'design_energy' (also {energy,charge}_last, _*_thresh etc.) to cover the mWh vs. mAh cases.
You can't do this conversion, since the voltage is not constant. Typically the voltage drops when the charge goes down, so you'll be grossly overestimating the available energy it. And the effect varies with battery chemistry and condition.
So there's no choice, you must use a generic term + units (and I suggest following the Smart Battery Data Specification's term "capacity"). This also takes care of the inevitable hardware that reports in other units, such as normalized percent.
Quoted 3 lines
I'd rather show it as a hex value 'flags' than
split it up. But I still think that the current 'present,charging,low' is best.
Then please make space-separated rather than comma-separated. That's easier to parse in shell and C.
Shem
Quoted 1 line · Shem Multinymous
What about current and power? These change very quickly.
I don't think we'd want to generate events for those, except perhaps if they exceed certain thresholds.
Quoted 3 lines
BTW, your patch doesn't address the instantaneous vs. average readout issue in the Smart Battery Data Specification and ThinkPads. Nor a number of other issues I brought up earlier.
True; it's a work-in-progress, and was actually sent just as I was boarding a plane. I shall attempt to go back through the messages I've received and address anything else that's pending.
If you can summarise the bits I've missed in the meantime that would be wonderfully useful -- especially if you could do so in 'diff -u' form :)
Quoted 8 lines
Quoted 3 lines
one of the things I plan is to remove '
charge_units' and provide both 'design_charge' and 'design_energy' (also {energy,charge}_last, _*_thresh etc.) to cover the mWh vs. mAh cases.You can't do this conversion, since the voltage is not constant. Typically the voltage drops when the charge goes down, so you'll be grossly overestimating the available energy it. And the effect varies with battery chemistry and condition.
Absolutely. I don't want to do the conversion -- I want to present the raw data. I was just a question of whether I provide 'capacity' and 'units' properties, or whether I provide 'capacity_mWh' and 'capacity_mAh' properties (only one of which, presumably, would be available for any given battery). Likewise for the rates, thresholds, etc.
Quoted 6 lines
Quoted 3 lines
I'd rather show it as a hex value 'flags' than
split it up. But I still think that the current 'present,charging,low' is best.Then please make space-separated rather than comma-separated. That's easier to parse in shell and C.
Ok. Committed to git://git.infradead.org/battery-2.6.git
Signature · 1 line
dwmw2
Hi,
Quoted 2 lines · David Woodhouse
If you can summarise the bits I've missed in the meantime that would be wonderfully useful
OK. Looking at the current git snapshot:
current_now is missing.
time_remainig should be split into:
time_to_empty_now
time_to_empty_avg
time_to_full
or even
time_to_empty_now
time_to_empty_avg
time_to_full_now
time_to_full_avg
s/charge_count/cycle_count/, that's the standard name and used by the SBS spec.
Why the reversed order, for example, in design_charge vs. charge_last? Following hwmon style, I think it should be s/design_charge/charge_design/ s/manufacture_date/date_manufactured/ s/first_use/date_first_used/ s/design_voltage/voltage_design/
s/charge_last/charge_last_full/ seems less ambiguous.
s/^charge$/charge_left/ follows SBS and seems better.
And, for the reasons I explained earlier, I strongly suggest not using the term "charge" except when referring to the action of charging. Hence:
s/charge_rate/rate/; s/charge/capacity/
It would be nice to have power_{now,avg}, always in mW regardless of the capacity units.
I take it you don't want to deal with battery control actions for now.
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
one of the things I plan is to remove '
charge_units' and provide both 'design_charge' and 'design_energy' (also {energy,charge}_last, _*_thresh etc.) to cover the mWh vs. mAh cases.You can't do this conversion, since the voltage is not constant. Typically the voltage drops when the charge goes down, so you'll be grossly overestimating the available energy it. And the effect varies with battery chemistry and condition.
Quoted 6 lines
Absolutely. I don't want to do the conversion -- I want to present the raw data. I was just a question of whether I provide 'capacity' and 'units' properties, or whether I provide '
capacity_mWh' and 'capacity_mAh' properties (only one of which, presumably, would be available for any given battery). Likewise for the rates, thresholds, etc.
I think using one set of files and units string makes more sense, for several reasons:
Reduces the number of attributes and kernel code duplication. Can handle weird power sources that use other units. Simpler userspace code. One can do
$ cd /sys/foo; echo `cat capacity_left` out of `cat capacity_last` `cat capaity_units` left. instead of checking multiple sets of files for valid values.
The great majority of apps don't care about the physical values, but just need something that they can parse as a relative quantity and something to show the user. The generic units scheme provides both. We have current_*, voltage etc. for those that do care, but there's no need to duplicate the whole set of _thresholds, _last_full, _design etc.
Shem
Quoted 8 lines · Shem Multinymous
Hi,
Quoted 2 lines · David Woodhouse
If you can summarise the bits I've missed in the meantime that would be wonderfully useful
OK. Looking at the current git snapshot:
< ... >
Ok, thanks for the feedback -- I think I've done all that. It wasn't in 'diff -u' form so I may have misapplied it. Please confirm.
Quoted 1 line
I take it you don't want to deal with battery control actions for now.
They're simple enough to add. We can do it when the tp driver gets converted over.
Quoted 2 lines
I think using one set of files and units string makes more sense, for several reasons:
Yeah, OK. Colour me convinced. I'll leave it as I had it.
Signature · 1 line
dwmw2
Hi,
Quoted 2 lines · David Woodhouse
Ok, thanks for the feedback -- I think I've done all that. It wasn't in 'diff -u' form so I may have misapplied it. Please confirm.
Looks perfect. And I agree that current_{,now} etc. is better than my suggestion of current_{avg,now}.
(I used free text instead of diff -u so I can give the rationale; should have included both, I guess).
Quoted 4 lines
Quoted 1 line
I take it you don't want to deal with battery control actions for now.
They're simple enough to add. We can do it when the tp driver gets converted over.
Sure. But It will require some thought. For example, the interface will need to encompass the non-symmetric pair of force commands on ThinkPads:
"discharge the battery until further notice" vs.
"don't charge the battery for N minutes".
Also, ThinkPads express the start/stop charging thresholds in percent, whereas I imagine some other hardware will represent it as capacity.
What other examples do we have of machines with battery control commands?
Shem
Quoted 9 lines · Shem Multinymous
Quoted 2 lines
They're simple enough to add. We can do it when the tp driver gets converted over.
Sure. But It will require some thought. For example, the interface will need to encompass the non-symmetric pair of force commands on ThinkPads:
"discharge the battery until further notice" vs.
"don't charge the battery for N minutes".
Quoted 3 lines
Also, ThinkPads express the start/stop charging thresholds in percent, whereas I imagine some other hardware will represent it as capacity.
Hm. Again we have the question of whether to export 'threshold_pct' vs. 'threshold_abs', or whether to have a separate string property which says what the 'unit' of the threshold is. I don't care much -- I'll do whatever DavidZ prefers.
The git tree now has support for battery information available from the PMU on Apple laptops. I _really_ don't like the way I have to register a fake platform_device just to be able to get sensible attribute callbacks. I suspect it should go back to being a class_device and we should fix the class_device attribute functions. Greg?
Signature · 1 line
dwmw2
Quoted 5 lines · David Woodhouse
Hm. Again we have the question of whether to export '
threshold_pct' vs.'threshold_abs', or whether to have a separate string property which says what the 'unit' of the threshold is. I don't care much -- I'll do whatever DavidZ prefers.
Unit is easier to process in HAL in my opinion.
Richard.
Quoted 8 lines · Richard Hughes
Quoted 5 lines · David Woodhouse
Hm. Again we have the question of whether to export '
threshold_pct' vs.'threshold_abs', or whether to have a separate string property which says what the 'unit' of the threshold is. I don't care much -- I'll do whatever DavidZ prefers.Unit is easier to process in HAL in my opinion.
That's harder for modifiable attributes, because apps need to know the minimum and maximum values (e.g., for sane GUI). So it's either multiple sets, or strings with fixed semantics (say, "percent" and "capacity"), or adding *_min and *_max read-only attributes.
Speaking of which, battery.h says this:
* Thou shalt not export any attributes in sysfs except these, and with these units: */
Drivers *will* want to violate this. For example, the "inhibit charging for N minutes" command on ThinkPads seems too arcane to be worthy of generalization. I would add a more sensible boolean "charging_inhibit" attribute to battery.h, and let the ThinkPad driver implement it as well as it can. The driver will then expose a non-stadard "charging_inhibit_minutes" attribute to reveal the finer level of access to those who care.
Shem
Quoted 10 lines · Shem Multinymous
* Thou shalt not export any attributes in sysfs except these, and with these units: */
Drivers *will* want to violate this. For example, the "inhibit charging for N minutes" command on ThinkPads seems too arcane to be worthy of generalization. I would add a more sensible boolean "
charging_inhibit" attribute tobattery.h, and let the ThinkPad driver implement it as well as it can. The driver will then expose a non-stadard "charging_inhibit_minutes" attribute to reveal the finer level of access to those who care.
If it makes enough sense that it's worth exporting it to userspace at all, then it can go into battery.h.
Signature · 1 line
dwmw2
Quoted 12 lines · David Woodhouse
Quoted 10 lines · Shem Multinymous
* Thou shalt not export any attributes in sysfs except these, and with these units: */
Drivers *will* want to violate this. For example, the "inhibit charging for N minutes" command on ThinkPads seems too arcane to be worthy of generalization. I would add a more sensible boolean "
charging_inhibit" attribute tobattery.h, and let the ThinkPad driver implement it as well as it can. The driver will then expose a non-stadard "charging_inhibit_minutes" attribute to reveal the finer level of access to those who care.
Quoted 2 lines
If it makes enough sense that it's worth exporting it to userspace at all, then it can go into
battery.h.
If it's non-standard please make sure to prefix the name with something unique e.g.
x_thinkpad_charging_inhibit [1]
to avoid collisions, e.g. two drivers using the same name but the semantics are different. Over time the battery class can standardize on this (if a feature becomes sufficiently common) and drivers can move over if they want to.
David
[1] : The x_ bit is inspired by how non standard email headers are handled e.g. X-Mailer and whatever. It's a very useful hint to user space people (and users in general) that some sysfs attribute is non-standard. I was going to suggest to user a full reverse DNS style naming scheme but I guess something that is unique enough will do.
Hi!
Quoted 9 lines
Quoted 2 lines
If it makes enough sense that it's worth exporting it to userspace at all, then it can go into
battery.h.If it's non-standard please make sure to prefix the name with something unique e.g.
x_thinkpad_charging_inhibit[1]to avoid collisions, e.g. two drivers using the same name but the
You were clearly exposed to harmful dose of smtp.
This is ugly, and unneccessary: kernel is centrally controlled. We *will* want to merge such attributes into something standard.
Pavel
Signature · 1 line
Thanks for all the (sleeping) penguins.
Quoted 1 line · Pavel Machek
You were clearly exposed to harmful dose of smtp.
Actually I got the idea when thinking of .desktop files but whatever.
Quoted 2 lines
This is ugly, and unneccessary: kernel is centrally controlled. We *will* want to merge such attributes into something standard.
Uh, such standards don't happen overnight as this thread painfully demonstrates, i.e. there is not yet any "standard" for handling batteries until dwmw2 actually stepped up. That alone says something. And we're at 2.6.19 about 15 years into development of Linux?
You may or may not like it... but battery class drivers will have such non-standard things. I'm merely suggesting to tag these as non-standard so it's bloody evident they are non-standard. For the record, I also think that making non standard attributes ugly will help accelerate us in standardizing on it. You can also easier grep through the sources to find offending code when you do decide to standardize it.
Playing the "kernel is centrally controlled" card doesn't work here. Do not pass start. Do not collect $200. (It works in a helluva lot of other situations though.)
David
Quoted 8 lines · David Zeuthen
Quoted 2 lines · Pavel Machek
This is ugly, and unneccessary: kernel is centrally controlled. We *will* want to merge such attributes into something standard.
Uh, such standards don't happen overnight as this thread painfully demonstrates, i.e. there is not yet any "standard" for handling batteries until dwmw2 actually stepped up. That alone says something. And we're at 2.6.19 about 15 years into development of Linux?
And we have sys_open. Not sys_x_ext2_open.
Quoted 6 lines
You may or may not like it... but battery class drivers will have such non-standard things. I'm merely suggesting to tag these as non-standard so it's bloody evident they are non-standard. For the record, I also think that making non standard attributes ugly will help accelerate us in standardizing on it. You can also easier grep through the sources to find offending code when you do decide to standardize it.
You can simply _not merge offending code in the first place_.
"Lets design it so that stupid things can be grepped for" is stupid, when we can simply "not allow stupid things to be merged".
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 8 lines · Richard Hughes
Quoted 5 lines · David Woodhouse
Hm. Again we have the question of whether to export '
threshold_pct' vs.'threshold_abs', or whether to have a separate string property which says what the 'unit' of the threshold is. I don't care much -- I'll do whatever DavidZ prefers.Unit is easier to process in HAL in my opinion.
What about just prepending the unit to the 'threshold' file? Then user space can expect the contents of said file to be of the form "%d %s". I don't think that violates the "only one value per file" sysfs mantra.
David
Quoted 1 line · David Zeuthen
What about just prepending the unit to the 'threshold' file?
^^^^
Uh, I meant appending. Haven't had coffee just yet.
David
Hi David,
Quoted 3 lines · David Zeuthen
What about just prepending the unit to the 'threshold' file? Then user space can expect the contents of said file to be of the form "%d %s". I don't think that violates the "only one value per file" sysfs mantra.
The tp_smapi battery driver did just this ("16495 mW"). But I dropped it in a recent version when Pavel pointed out the rest of sysfs, hwmon included, uses undecorated integers.
Consistency aside, it seems reasonable and convenient. You have to decree that writes to the attributes (where relevant) don't include the units, of course, so no one will expect the kernel to parse that.
There's an issue here if a drunk driver decides to specify (say) capacity_remaining in mWh and capacity_last_full in mAa, which will confuse anyone comparing those attributest. So don't do that.
Jean, what's your opinion on letting hwmon-ish attributes specify units as "%d %s" where these are hardware-dependent?
Shem
Quoted 14 lines · Shem Multinymous
Hi David,
Quoted 3 lines · David Zeuthen
What about just prepending the unit to the 'threshold' file? Then user space can expect the contents of said file to be of the form "%d %s". I don't think that violates the "only one value per file" sysfs mantra.
The
tp_smapibattery driver did just this ("16495 mW"). But I dropped it in a recent version when Pavel pointed out the rest of sysfs, hwmon included, uses undecorated integers.
Consistency aside, it seems reasonable and convenient. You have to decree that writes to the attributes (where relevant) don't include the units, of course, so no one will expect the kernel to parse that.
Quoted 6 lines
There's an issue here if a drunk driver decides to specify (say)
capacity_remainingin mWh andcapacity_last_fullin mAa, which will confuse anyone comparing those attributest. So don't do that.Jean, what's your opinion on letting hwmon-ish attributes specify units as "%d %s" where these are hardware-dependent?
No, the sysfs files should just always keep the same units as documented. It's easier all around that way.
thanks,
greg k-h
Hi Greg,
Quoted 16 lines · Greg KH
Quoted 16 lines · David Zeuthen
Quoted 3 lines
What about just prepending the unit to the 'threshold' file? Then user space can expect the contents of said file to be of the form "%d %s". I don't think that violates the "only one value per file" sysfs mantra.
The
tp_smapibattery driver did just this ("16495 mW"). But I dropped it in a recent version when Pavel pointed out the rest of sysfs, hwmon included, uses undecorated integers.
Consistency aside, it seems reasonable and convenient. You have to decree that writes to the attributes (where relevant) don't include the units, of course, so no one will expect the kernel to parse that.There's an issue here if a drunk driver decides to specify (say)
capacity_remainingin mWh andcapacity_last_fullin mAa, which will confuse anyone comparing those attributest. So don't do that.
Quoted 5 lines
Quoted 2 lines
Jean, what's your opinion on letting hwmon-ish attributes specify units as "%d %s" where these are hardware-dependent?
No, the sysfs files should just always keep the same units as documented. It's easier all around that way.
It sure is easier, but we're discussinng the case where units change in runtime; what do we document then? Plug in a different battery and you get reports in mA and mAh insted of mW and mWh.
The suggestions so far were:
1. Append units string to the content of such attribute:
/sys/.../capacity_remaining reads "16495 mW".
2. Add a seprate *_units attribute saying what are units for other attribute:
/sys/.../capacity_units gives the units for /sys/.../capacity_{remaining,last_full,design,min,...}.
3. Append the units to the attribute names:
capacity_{remaining,last_full,design_min,...}:mV.
Shem
Quoted 22 lines · Shem Multinymous
Hi Greg,
Quoted 19 lines · Greg KH
Quoted 18 lines · David Zeuthen
Quoted 3 lines
What about just prepending the unit to the 'threshold' file? Then user space can expect the contents of said file to be of the form "%d %s". I don't think that violates the "only one value per file" sysfs mantra.
The
tp_smapibattery driver did just this ("16495 mW"). But I dropped it in a recent version when Pavel pointed out the rest of sysfs, hwmon included, uses undecorated integers.
Consistency aside, it seems reasonable and convenient. You have to decree that writes to the attributes (where relevant) don't include the units, of course, so no one will expect the kernel to parse that.There's an issue here if a drunk driver decides to specify (say)
capacity_remainingin mWh andcapacity_last_fullin mAa, which will confuse anyone comparing those attributest. So don't do that.Jean, what's your opinion on letting hwmon-ish attributes specify units as "%d %s" where these are hardware-dependent?
Quoted 6 lines
Quoted 2 lines
No, the sysfs files should just always keep the same units as documented. It's easier all around that way.
It sure is easier, but we're discussinng the case where units change in runtime; what do we document then? Plug in a different battery and you get reports in mA and mAh insted of mW and mWh.
Then you should just get different sysfs files then. One that describes power and one that describes current.
Quoted 9 lines
The suggestions so far were:
1. Append units string to the content of such attribute:
/sys/.../capacity_remainingreads "16495 mW".
2. Add a seprate*_unitsattribute saying what are units for other attribute:
/sys/.../capacity_unitsgives the units for/sys/.../capacity_{remaining,last_full,design,min,...}.
3. Append the units to the attribute names:
capacity_{remaining,last_full,design_min,...}:mV.
No, again, one for power and one for current. Two different files depending on the type of battery present. That way there is no need to worry about unit issues.
thanks,
greg k-h
Hi Greg,
Quoted 10 lines · Greg KH
Quoted 9 lines
The suggestions so far were:
1. Append units string to the content of such attribute:
/sys/.../capacity_remainingreads "16495 mW".
2. Add a seprate*_unitsattribute saying what are units for other attribute:
/sys/.../capacity_unitsgives the units for/sys/.../capacity_{remaining,last_full,design,min,...}.
3. Append the units to the attribute names:
capacity_{remaining,last_full,design_min,...}:mV.
Quoted 3 lines
No, again, one for power and one for current. Two different files depending on the type of battery present. That way there is no need to worry about unit issues.
I'm missing something. How is that different from option 3 above? BTW, please note that we're talking about a large set of files that use these units (remaining, last full, design capacity, alarm thresholds, etc.), and not just a single attribute.
This particular alternative indeed seems cleanest for the kernel side. The drawback is that someone in userspace who doesn't care about units but just wants to show a status report or compute the amount of remaining fooergy divided by the amount of a fooergy when fully charged, like your typical battery applet, will need to parse filenames (or try out a fixed and possibly partial list) to find out which attribute files contain the numbers.
Shem
Quoted 13 lines · Shem Multinymous
Hi Greg,
Quoted 10 lines · Greg KH
Quoted 9 lines
The suggestions so far were:
1. Append units string to the content of such attribute:
/sys/.../capacity_remainingreads "16495 mW".
2. Add a seprate*_unitsattribute saying what are units for other attribute:
/sys/.../capacity_unitsgives the units for/sys/.../capacity_{remaining,last_full,design,min,...}.
3. Append the units to the attribute names:
capacity_{remaining,last_full,design_min,...}:mV.
Quoted 5 lines
Quoted 3 lines
No, again, one for power and one for current. Two different files depending on the type of battery present. That way there is no need to worry about unit issues.
I'm missing something. How is that different from option 3 above?
No silly ":mV" on the file name.
Quoted 3 lines
BTW, please note that we're talking about a large set of files that use these units (remaining, last full, design capacity, alarm thresholds, etc.), and not just a single attribute.
Sure, what's wrong with:
capacity_remaining_power
capacity_last_full_power
capacity_design_min_power
if you can read that from the battery, and:
capacity_remaining_current
capacity_last_full_current
capacity_design_min_current
if you can read that instead.
Quoted 7 lines
This particular alternative indeed seems cleanest for the kernel side. The drawback is that someone in userspace who doesn't care about units but just wants to show a status report or compute the amount of remaining fooergy divided by the amount of a fooergy when fully charged, like your typical battery applet, will need to parse filenames (or try out a fixed and possibly partial list) to find out which attribute files contain the numbers.
If the file isn't there, they the attribute isn't present. It doesn't get easier than that.
And of course user apps will have to change, but only once. And then they will work with all types of batterys, unlike today.
thanks,
greg k-h
Quoted 14 lines · Greg KH
Quoted 13 lines · Shem Multinymous
Hi Greg,
Quoted 10 lines · Greg KH
Quoted 9 lines
The suggestions so far were:
1. Append units string to the content of such attribute:
/sys/.../capacity_remainingreads "16495 mW".
2. Add a seprate*_unitsattribute saying what are units for other attribute:
/sys/.../capacity_unitsgives the units for/sys/.../capacity_{remaining,last_full,design,min,...}.
3. Append the units to the attribute names:
capacity_{remaining,last_full,design_min,...}:mV.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
No, again, one for power and one for current. Two different files depending on the type of battery present. That way there is no need to worry about unit issues.
I'm missing something. How is that different from option 3 above?
No silly ":mV" on the file name.
As long as that also means no "silly _mV" in the name. However, if the choice is between :mV and _mV, please go with :mV.
Quoted 4 lines
Quoted 3 lines
BTW, please note that we're talking about a large set of files that use these units (remaining, last full, design capacity, alarm thresholds, etc.), and not just a single attribute.
Quoted 9 lines
Sure, what's wrong with:
capacity_remaining_power
capacity_last_full_power
capacity_design_min_power
if you can read that from the battery, and:
capacity_remaining_current
capacity_last_full_current
capacity_design_min_current
if you can read that instead.
Well, "Wh" measures energy and not power, and "Ah" measures electric charge and not current, so it would be better to make that:
capacity_*_energy (Wh-based)
and
capacity_*_charge (Ah-based)
Also, should we go with mWh/mAh, or with even smaller units because of the tiny battery-driven devices of tomorrow?
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 19 lines · Henrique de Moraes Holschuh
Quoted 18 lines · Greg KH
Quoted 17 lines · Shem Multinymous
Hi Greg,
Quoted 13 lines · Greg KH
Quoted 9 lines
The suggestions so far were:
1. Append units string to the content of such attribute:
/sys/.../capacity_remainingreads "16495 mW".
2. Add a seprate*_unitsattribute saying what are units for other attribute:
/sys/.../capacity_unitsgives the units for/sys/.../capacity_{remaining,last_full,design,min,...}.
3. Append the units to the attribute names:
capacity_{remaining,last_full,design_min,...}:mV.No, again, one for power and one for current. Two different files depending on the type of battery present. That way there is no need to worry about unit issues.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
I'm missing something. How is that different from option 3 above?
No silly ":mV" on the file name.
As long as that also means no "silly
_mV" in the name. However, if the choice is between :mV and_mV, please go with :mV.
Neither should be in the name.
Again, people, look how we already do this in the kernel today with the hwmon drivers. They all just document the units and that's it. No problems.
Quoted 14 lines
Quoted 4 lines
Quoted 3 lines
BTW, please note that we're talking about a large set of files that use these units (remaining, last full, design capacity, alarm thresholds, etc.), and not just a single attribute.
Quoted 9 lines
Sure, what's wrong with:
capacity_remaining_power
capacity_last_full_power
capacity_design_min_power
if you can read that from the battery, and:
capacity_remaining_current
capacity_last_full_current
capacity_design_min_current
if you can read that instead.
Quoted 8 lines
Well, "Wh" measures energy and not power, and "Ah" measures electric charge and not current, so it would be better to make that:
capacity_*_energy (Wh-based)
and
capacity_*_charge (Ah-based)
Ok, that's fine with me.
Quoted 2 lines
Also, should we go with mWh/mAh, or with even smaller units because of the tiny battery-driven devices of tomorrow?
Well, what do the tiny battery-driven devices of today provide (like the Nokia 770, other cell phones, smart hand-helds, etc.) Those should give you a good idea if that would be needed or not.
thanks,
greg k-h
Quoted 39 lines · Henrique de Moraes Holschuh
Quoted 13 lines · Greg KH
Quoted 12 lines · Shem Multinymous
Hi Greg,
Quoted 9 lines · Greg KH
Quoted 9 lines
The suggestions so far were:
1. Append units string to the content of such attribute:
/sys/.../capacity_remainingreads "16495 mW".
2. Add a seprate*_unitsattribute saying what are units for other attribute:
/sys/.../capacity_unitsgives the units for/sys/.../capacity_{remaining,last_full,design,min,...}.
3. Append the units to the attribute names:
capacity_{remaining,last_full,design_min,...}:mV.Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
No, again, one for power and one for current. Two different files depending on the type of battery present. That way there is no need to worry about unit issues.
I'm missing something. How is that different from option 3 above?
No silly ":mV" on the file name.
As long as that also means no "silly
_mV" in the name. However, if the choice is between :mV and_mV, please go with :mV.Quoted 12 lines
Quoted 3 lines
BTW, please note that we're talking about a large set of files that use these units (remaining, last full, design capacity, alarm thresholds, etc.), and not just a single attribute.
Sure, what's wrong with:
capacity_remaining_power
capacity_last_full_power
capacity_design_min_power
if you can read that from the battery, and:
capacity_remaining_current
capacity_last_full_current
capacity_design_min_current
if you can read that instead.Well, "Wh" measures energy and not power, and "Ah" measures electric charge and not current, so it would be better to make that:
Quoted 9 lines
capacity_*_energy (Wh-based)
and
capacity_*_charge (Ah-based)
Also, should we go with mWh/mAh, or with even smaller units because of the tiny battery-driven devices of tomorrow?
Having seen a French consultant with a Windows laptop reporting mJ (Joules) I bet that came from the hardware. And given that laptop batteries run at (almost) constant voltage, could all of these just be converted to mWh for consistency?
Signature · 5 lines
Bill Davidsen <[email protected]> Obscure bug of 2004: BASH BUFFER OVERFLOW - if bash is being run by a normal user and is setuid root, with the "vi" line edit mode selected, and the character set is "big5," an off-by-one errors occurs during wildcard (glob) expansion.
Quoted 2 lines · Bill Davidsen
And given that laptop
batteries run at (almost) constant voltage
No, they really don't.
Richard.
Hi!
Quoted 14 lines
Quoted 6 lines
Well, "Wh" measures energy and not power, and "Ah" measures electric charge
and not current, so it would be better to make that:capacity_*_energy (Wh-based)
Quoted 8 lines
and
capacity_*_charge (Ah-based)
Also, should we go with mWh/mAh, or with even smaller units because of the
tiny battery-driven devices of tomorrow?
Quoted 5 lines
Having seen a French consultant with a Windows laptop reporting mJ (Joules) I bet that came from the hardware. And given that laptop batteries run at (almost) constant voltage, could all of these just be converted to mWh for consistency?
li-ions run from 4.2V down to 3.6V without problems, and you can use them down to 3.0V. I've ran zaurus down to 3.3V, IIRC. That's quite a big range.
Signature · 1 line
Thanks for all the (sleeping) penguins.
Quoted 4 lines · Bill Davidsen
Having seen a French consultant with a Windows laptop reporting mJ (Joules) I bet that came from the hardware. And given that laptop batteries run at (almost) constant voltage, could all of these just be converted to mWh for consistency?
*No*. That adds quite a lot of error, which can be easily avoided by providing the _charge and _energy attribute sets.
You can convert between J and Wh and between C to Ah without significant precision loss. Just don't go cheap on the fixed point calculations, and make sure the destination unit is small enough not to forsake precision.
We can definately be safe from any precision loss using (10^-6) * (A, Ah, W, Wh, V) as the base unit, but that will make for long numbers in sysfs with lots of zeros in many situations (which is MUCH better than precision loss).
We could also use a proper submultiple of J and C instead of Wh and Ah if we'd rather stick to the SI, that wouldn't be a big problem at all.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 1 line · Bill Davidsen
Having seen a French consultant with a Windows laptop reporting mJ
Hehe.... That's the nice thing about SI units.
1W = 1J / 1s
so
1W * 1h = 3600s * 1J / 1s
1mWh = 3.6J
If i did not screw up something :-). I still wonder why they would report mJ, but probably they like big numbers ;-)
Signature · 3 lines
Stefan Seyfried QA / R&D Team Mobile Devices | "Any ideas, John?" SUSE LINUX Products GmbH, Nürnberg | "Well, surrounding them's out."
Hi!
Quoted 11 lines
Well, "Wh" measures energy and not power, and "Ah" measures electric charge and not current, so it would be better to make that:
capacity_*_energy (Wh-based)
and
capacity_*_charge (Ah-based)
Also, should we go with mWh/mAh, or with even smaller units because of the tiny battery-driven devices of tomorrow?
Okay... So I have cellphone here, 700mAh battery, ~2.8Wh battery. It could last 14 days if we were *very* careful.
echo '(700 mA * hour) / (14*day) \ A' | ucalc
ucalc> OK: 0.002083
ucalc>
...that is about 2mA in low power standby mode (but still listening on GSM, getting calls, etc).
...so, mAh are probably good enough for capacity_*_charge, but would suck for current power consumption, as difference between 2mA and 3mA would be way too big. We need some finer unit in that case.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi,
Quoted 6 lines · Pavel Machek
echo '(700 mA * hour) / (14*day) \ A' | ucalc
ucalc> OK: 0.002083
ucalc>
Quoted 7 lines
...that is about 2mA in low power standby mode (but still listening on
GSM, getting calls, etc)....so, mAh are probably good enough for capacity_*_charge, but would
suck for current power consumption, as difference between 2mA and 3mA would be way too big. We need some finer unit in that case.
That very much depends on the system. Having a laptop where the current power consumption is around 10 Watts (or, at about 10 to 12 Volts, nearly 1 A), having a resolution of 10 or even 100 mA would be OK. However, on your cellphone with a standby consumption of 2mA, such a resolution would be meaningless. What kind of resultion does the hardware usually support?
And then there is the measurement error. Any ideas about what the actual error ranges are?
Cheers
Ulrich
Quoted 17 lines · U Kuehn
Hi,
Quoted 6 lines · Pavel Machek
echo '(700 mA * hour) / (14*day) \ A' | ucalc
ucalc> OK: 0.002083
ucalc>Quoted 7 lines
...that is about 2mA in low power standby mode (but still listening on
GSM, getting calls, etc)....so, mAh are probably good enough for capacity_*_charge, but would
suck for current power consumption, as difference between 2mA and 3mA would be way too big. We need some finer unit in that case.
Quoted 6 lines
That very much depends on the system. Having a laptop where the current power consumption is around 10 Watts (or, at about 10 to 12 Volts, nearly 1 A), having a resolution of 10 or even 100 mA would be OK. However, on your cellphone with a standby consumption of 2mA, such a resolution would be meaningless. What kind of resultion does the hardware usually support?
I do not know details. Siemens phones have current monitors, but I do not recall how accurate those are. Anyway, at least for some applications mA is not enough, so we probably should use finer unit. Or use ampers and let kernel be "as precise as it needs" in simulated floating point.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 8 lines · Pavel Machek
Quoted 6 lines · U Kuehn
That very much depends on the system. Having a laptop where the current power consumption is around 10 Watts (or, at about 10 to 12 Volts, nearly 1 A), having a resolution of 10 or even 100 mA would be OK. However, on your cellphone with a standby consumption of 2mA, such a resolution would be meaningless. What kind of resultion does the hardware usually support?
Quoted 5 lines
I do not know details. Siemens phones have current monitors, but I do not recall how accurate those are. Anyway, at least for some applications mA is not enough, so we probably should use finer unit. Or use ampers and let kernel be "as precise as it needs" in simulated floating point.
No. Fixed point, please. Use µA as the unit if needed.
Signature · 1 line
Jean Delvare
Hi!
Quoted 19 lines
Quoted 10 lines
Quoted 9 lines
The suggestions so far were:
1. Append units string to the content of such attribute:
/sys/.../capacity_remainingreads "16495 mW".
2. Add a seprate*_unitsattribute saying what are units for other attribute:
/sys/.../capacity_unitsgives the units for/sys/.../capacity_{remaining,last_full,design,min,...}.
3. Append the units to the attribute names:
capacity_{remaining,last_full,design_min,...}:mV.Quoted 3 lines
No, again, one for power and one for current. Two different files depending on the type of battery present. That way there is no need to worry about unit issues.
I'm missing something. How is that different from option 3 above? BTW, please note that we're talking about a large set of files that use these units (remaining, last full, design capacity, alarm thresholds, etc.), and not just a single attribute.
Quoted 7 lines
This particular alternative indeed seems cleanest for the kernel side. The drawback is that someone in userspace who doesn't care about units but just wants to show a status report or compute the amount of remaining fooergy divided by the amount of a fooergy when fully charged, like your typical battery applet, will need to parse filenames (or try out a fixed and possibly partial list) to find out which attribute files contain the numbers.
That's okay, we want userspace to use common library, and doing
echo $[cat capacity_remaining:* / cat capacity_total:*]
is not exactly rocket science. If greg does not like units suffixes, that's okay, too, I'm sure handy wildcard match will be possible.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 8 lines · Pavel Machek
Quoted 1 line
The drawback is that someone in userspace who doesn't care about
units
Quoted 5 lines
but just wants to show a status report or compute the amount of remaining fooergy divided by the amount of a fooergy when fully charged, like your typical battery applet, will need to parse filenames (or try out a fixed and possibly partial list) to find out which attribute files contain the numbers.
Quoted 6 lines
That's okay, we want userspace to use common library, and doing
echo $[
cat capacity_remaining:*/cat capacity_total:*]is not exactly rocket science. If greg does not like units suffixes, that's okay, too, I'm sure handy wildcard match will be possible.
I'm guessing adding the new code to HAL will allow most stuff to keep working without any changes. I think battstat-applet defaults to using HAL, and I'm sure gnome-power-manager does. :-)
Richard.
Quoted 11 lines · an anonymous coward
Quoted 3 lines · David Zeuthen
What about just prepending the unit to the 'threshold' file? Then user space can expect the contents of said file to be of the form "%d %s". I don't think that violates the "only one value per file" sysfs mantra.
The
tp_smapibattery driver did just this ("16495 mW"). But I dropped it in a recent version when Pavel pointed out the rest of sysfs, hwmon included, uses undecorated integers.
Consistency aside, it seems reasonable and convenient. You have to decree that writes to the attributes (where relevant) don't include the units, of course, so no one will expect the kernel to parse that.
But what value should then be written? One in an absolute aribtrary unit? That would make reads and writes to the sysfs files inconsistent, in direct violation of the sysfs standard. Or in the same unit read from the file? It means that userspace must first read from the file, parse the unit, then convert the value to be written. This doesn't match my definition of "convenient".
Quoted 6 lines
There's an issue here if a drunk driver decides to specify (say)
capacity_remainingin mWh andcapacity_last_fullin mAa, which will confuse anyone comparing those attributest. So don't do that.Jean, what's your opinion on letting hwmon-ish attributes specify units as "%d %s" where these are hardware-dependent?
I fail to see any benefit in doing so, while I see several problems (see above) and potential for confusion. So my opinion is: please don't do that.
Thanks,
--
Jean
Hi Jean,
Quoted 6 lines · Jean Delvare
Quoted 4 lines · someone who remains multinymous
Quoted 3 lines · David Zeuthen
What about just prepending the unit to the 'threshold' file? Then user space can expect the contents of said file to be of the form "%d %s". I don't think that violates the "only one value per file" sysfs mantra.
Quoted 6 lines
Quoted 2 lines
Jean, what's your opinion on letting hwmon-ish attributes specify units as "%d %s" where these are hardware-dependent?
I fail to see any benefit in doing so, while I see several problems (see above) and potential for confusion. So my opinion is: please don't do that.
Well, we have to do *something* about those devices that don't have fixed units (see my mail to Greg from a few minutes ago), so which alternative do you prefer?
Quoted 7 lines
Quoted 6 lines
The
tp_smapibattery driver did just this ("16495 mW"). But I dropped it in a recent version when Pavel pointed out the rest of sysfs, hwmon included, uses undecorated integers.
Consistency aside, it seems reasonable and convenient. You have to decree that writes to the attributes (where relevant) don't include the units, of course, so no one will expect the kernel to parse that.
Quoted 6 lines
But what value should then be written? One in an absolute aribtrary unit? That would make reads and writes to the sysfs files inconsistent, in direct violation of the sysfs standard. Or in the same unit read from the file? It means that userspace must first read from the file, parse the unit, then convert the value to be written. This doesn't match my definition of "convenient".
The latter. Yes, writing is not as convenient as reading; but the same drawback exists in the other two suggestions for dynamic units - you still have to read another attribute, or parse a filename, to get the units.
The "capacity_remaining:mV" option at least saves you the parsing if your're only interested in mV readouts. But battery gauge applets, for examples, shouldn't be hardcoded to specific units, so they will have to do the filename parsing dance.
Shem
Quoted 10 lines · Shem Multinymous
Quoted 6 lines
Quoted 2 lines
Jean, what's your opinion on letting hwmon-ish attributes specify units as "%d %s" where these are hardware-dependent?
I fail to see any benefit in doing so, while I see several problems (see above) and potential for confusion. So my opinion is: please don't do that.
Well, we have to do *something* about those devices that don't have fixed units (see my mail to Greg from a few minutes ago), so which alternative do you prefer?
How about converting on the fly ?
Xav
Quoted 5 lines · Xavier Bestel
Quoted 3 lines
Well, we have to do *something* about those devices that don't have fixed units (see my mail to Greg from a few minutes ago), so which alternative do you prefer?
How about converting on the fly ?
In the case at hand we have mWh and mAh, which measure different physical quantities. You can't convert between them unless you have intimate knowledge of the battery's chemistry and condition, which we don't.
And it would be nice to also allow for power supply devices that use other, incompatible units like "percent" or "minutes" or "hand crank revolutions".
Shem
Quoted 5 lines · Shem Multinymous
In the case at hand we have mWh and mAh, which measure different physical quantities. You can't convert between them unless you have intimate knowledge of the battery's chemistry and condition, which we don't.
I'm thinking specifically for ACPI at the moment.
When ACPI can't work out a value, i.e. it's not known, it returns a value of 0xFFFFFFFF. This can happen either for a split second on disconnect, or if the hardware really doesn't know the value.
With the battery class driver, how would that be conveyed? Would the sysfs file be deleted in this case, or would the value of the sysfs key be something like "<invalid>".
This is something I'm just thinking about for the HAL backend, and whatever is decided should probably be documented.
Richard.
Quoted 3 lines · Richard Hughes
With the battery class driver, how would that be conveyed? Would the sysfs file be deleted in this case, or would the value of the sysfs key be something like "<invalid>".
I'd be inclined to make the read return -EINVAL.
Signature · 1 line
dwmw2
Quoted 6 lines · David Woodhouse
Quoted 3 lines · Richard Hughes
With the battery class driver, how would that be conveyed? Would the sysfs file be deleted in this case, or would the value of the sysfs key be something like "<invalid>".
I'd be inclined to make the read return
-EINVAL.
-EIO for transient errors (e.g. access to the embedded controller/battery charger/whatever fails at that instant), -EINVAL for "not supported" (missing ACPI method, attribute not supported in the specific hardware)?
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 11 lines · Henrique de Moraes Holschuh
Quoted 6 lines · David Woodhouse
Quoted 3 lines · Richard Hughes
With the battery class driver, how would that be conveyed? Would the sysfs file be deleted in this case, or would the value of the sysfs key be something like "<invalid>".
I'd be inclined to make the read return
-EINVAL.
-EIOfor transient errors (e.g. access to the embedded controller/battery charger/whatever fails at that instant),-EINVALfor "not supported" (missing ACPI method, attribute not supported in the specific hardware)?
Shouldn't it be -EIO or -EBUSY for transient errors (depending on type), and -ENXIO when not provided by hardware?
The -EINVAL is more appropriate for bad user-supplied values (out of range etc.) to writable attributes.
Shem
Quoted 7 lines · Shem Multinymous
Quoted 6 lines · Henrique de Moraes Holschuh
Quoted 5 lines · David Woodhouse
Quoted 3 lines · Richard Hughes
With the battery class driver, how would that be conveyed? Would the sysfs file be deleted in this case, or would the value of the sysfs key be something like "<invalid>".
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I'd be inclined to make the read return
-EINVAL.
-EIOfor transient errors (e.g. access to the embedded controller/battery charger/whatever fails at that instant),-EINVALfor "not supported" (missing ACPI method, attribute not supported in the specific hardware)?Shouldn't it be
-EIOor-EBUSYfor transient errors (depending on type), and-ENXIOwhen not provided by hardware?
Sounds good to me, but I haven't seen much stuff returning -ENXIO. Still, AFAIK usually when you don't support something in sysfs, you don't provide the entry at all so ENXIO should be quite rare.
Quoted 2 lines
The
-EINVALis more appropriate for bad user-supplied values (out of range etc.) to writable attributes.
Yes, that makes a lot of sense.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 9 lines · Richard Hughes
Quoted 5 lines · Shem Multinymous
In the case at hand we have mWh and mAh, which measure different physical quantities. You can't convert between them unless you have intimate knowledge of the battery's chemistry and condition, which we don't.
I'm thinking specifically for ACPI at the moment.
Quoted 7 lines
When ACPI can't work out a value, i.e. it's not known, it returns a value of
0xFFFFFFFF. This can happen either for a split second on disconnect, or if the hardware really doesn't know the value.With the battery class driver, how would that be conveyed? Would the sysfs file be deleted in this case, or would the value of the sysfs key be something like "<invalid>".
No, the sysfs file should just not be present.
thanks,
greg k-h
Quoted 4 lines · man with no name
In the case at hand we have mWh and mAh, which measure different physical quantities. You can't convert between them unless you have intimate knowledge of the battery's chemistry and condition, which we don't.
You just need to know the voltage of the battery, what else?
Quoted 3 lines
And it would be nice to also allow for power supply devices that use other, incompatible units like "percent" or "minutes" or "hand crank revolutions".
Do such batteries exist at the moment, or are you just speculating? I don't quite see how a battery could report remaining energy in time units, as power consumption varies over time. Hand crank revolutions wouldn't be a very useful unit either, unless you know how much energy a revolution provides, and then you can just convert it. Percent would make some sense, but you can only express the remaining energy this way, not the total. And if you know the total in mAh or mWh, you can multiply by the percentage and you get the remaining energy in the same unit.
--
Jean Delvare
Quoted 1 line · Jean Delvare
You just need to know the voltage of the battery, what else?
This isn't as easy as you think. The number of broken BIOS's that have the current, last full or design either as 0xFFFF, 0xFFFFFF, 0, 1mV, or 10000mV rather than the present (correct) value is a big problem.
We've got quite a bit of code in HAL to try and sort out all the quirks, although it only works most of the time due to extreme hardware brokenness.
Richard.
Quoted 7 lines · Jean Delvare
Quoted 4 lines · man with no name
In the case at hand we have mWh and mAh, which measure different physical quantities. You can't convert between them unless you have intimate knowledge of the battery's chemistry and condition, which we don't.
You just need to know the voltage of the battery, what else?
The error goes way up when you do such calculations. Not that most battery hardware reports SBS Error margins right, but still...
So doing conversions is not a good idea unless it is from Ah to Coulombs or something else like that which is an exact conversion.
In ThinkPads, you just need to compare what the various "let's calculate it" applets say, and the output of tp_smapi (gets remanining time data directly from the hardware) to see which one is more accurate :-) And the difference is often quite expressive.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 6 lines · Jean Delvare
Quoted 4 lines · man with no name
In the case at hand we have mWh and mAh, which measure different physical quantities. You can't convert between them unless you have intimate knowledge of the battery's chemistry and condition, which we don't.
Quoted 7 lines
You just need to know the voltage of the battery, what else?
Quoted 3 lines
And it would be nice to also allow for power supply devices that use other, incompatible units like "percent" or "minutes" or "hand crank revolutions".
Do such batteries exist at the moment, or are you just speculating?
I have seen joules (or mJ) on a laptop. Yes, it was Windows, but I bet the report came from hardware. Some vendor getting anal about metric?
Quoted 11 lines
I
don't quite see how a battery could report remaining energy in time units, as power consumption varies over time. Hand crank revolutions wouldn't be a very useful unit either, unless you know how much energy a revolution provides, and then you can just convert it. Percent would make some sense, but you can only express the remaining energy this way, not the total. And if you know the total in mAh or mWh, you can multiply by the percentage and you get the remaining energy in the same unit.--
Jean Delvare
Signature · 5 lines
Bill Davidsen <[email protected]> Obscure bug of 2004: BASH BUFFER OVERFLOW - if bash is being run by a normal user and is setuid root, with the "vi" line edit mode selected, and the character set is "big5," an off-by-one errors occurs during wildcard (glob) expansion.
----- Original Message ----- From: "Bill Davidsen" <[email protected]>
To: "Jean Delvare" <[email protected]>
Cc: <[email protected]>; "Richard Hughes" <[email protected]>; "David Woodhouse" <[email protected]>; "Dan Williams" <[email protected]>; <[email protected]>; <[email protected]>; <[email protected]>; <[email protected]>; <[email protected]>; <[email protected]>; "linux-thinkpad mailing list" <[email protected]>; "Pavel Machek" <[email protected]>
Sent: Thursday, November 02, 2006 12:52 PM
Subject: Re: [PATCH v2] Re: Battery class driver.
Quoted 9 lines
Quoted 8 lines · Jean Delvare
Quoted 4 lines · man with no name
In the case at hand we have mWh and mAh, which measure different physical quantities. You can't convert between them unless you have intimate knowledge of the battery's chemistry and condition, which we don't.
You just need to know the voltage of the battery, what else?
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
And it would be nice to also allow for power supply devices that use other, incompatible units like "percent" or "minutes" or "hand crank revolutions".
Do such batteries exist at the moment, or are you just speculating?
I have seen joules (or mJ) on a laptop. Yes, it was Windows, but I bet the report came from hardware. Some vendor getting anal about metric?
The only thing that makes sense with batteries is the total amount of energy available. Such energy has the dimension of watt-seconds, i.e., joules, even though a battery might be rated in ampere-hours. This is because you can't even guess at the amount of energy remaining by looking at a battery's voltage. To get joules, you need to multiply the voltage times the current times the time for all time, both the charge time and the discharge time. When charging, the charging efficiency needs to be taken into account as well. The charging efficiency varies with the battery chemistry, its type, and its stored energy. For instance, a fully charged battery has zero charging efficiency (any current supplied is converted to heat). A typical battery at about one-half its capacity converts over 90% of the applied charge to stored energy.
No known laptop bothers to do this. That's why the batteries fail at the most inoportune times and why it will decide to shut down when it feels like it, based totally upon some detected voltage drop when a disk-drive started.
Analogic makes a portable CAT Scanner. It can be plugged into an ordinary wall outlet even though the X-Ray subsystem takes 10 kilowatts! It does this by storing the needed energy in batteries. Since the X-Ray is on only for a short period of time, the system has plenty of time to charge the batteries while the image is being processed or reviewed. Since it is against FDA regulations to expose a patient to X-Rays unless diagnistically-useful images result, it is mandatory that the charge state of the batteries be known at all times so that an image sequence once started, is guaranteed to complete. For this, we have a software sampler that calculates the charge about 1,000 per second. It does nor assume that the samples are at millisecond intervals, it reads a hardware timer to get the elapsed time between each sample. It measures the voltage, the current, and the time each sample interval. It accumulates these samples into a charge variable with the dimension of joules.
Quoted 9 lines
Quoted 9 lines
I
don't quite see how a battery could report remaining energy in time units, as power consumption varies over time. Hand crank revolutions wouldn't be a very useful unit either, unless you know how much energy a revolution provides, and then you can just convert it. Percent would make some sense, but you can only express the remaining energy this way, not the total. And if you know the total in mAh or mWh, you can multiply by the percentage and you get the remaining energy in the same unit.
Quoted 15 lines
Quoted 2 lines
--
Jean DelvareSignature · 10 lines
Bill Davidsen <[email protected]> Obscure bug of 2004: BASH BUFFER OVERFLOW - if bash is being run by a normal user and is setuid root, with the "vi" line edit mode selected, and the character set is "big5," an off-by-one errors occurs during wildcard (glob) expansion. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Cheers,
Dick Johnson
Penguin : Linux version 2.6.16.24 (somewhere) -- They shut off my email at work!
Book: http://www.AbominableFireug.com
Quoted 4 lines · Richard B. Johnson
No known laptop bothers to do this. That's why the batteries fail at the most inoportune times and why it will decide to shut down when it feels like it, based totally upon some detected voltage drop when a disk-drive started.
Weird, I though the whole point behind a SBS hardware stack requiring something fairly intelligent in the battery pack and allowing for (runtime switchable!) Ah or Wh modes of operation was to allow vendors to do exactly
that: measure (V,A) permanently while the cells are above the safety cut-off fuse level, and accumulate it...
Well, IBM embedded a microcontroller of some sort on every SBS ThinkPad battery pack, and the ThinkPad reports battery data in Wh, so I expected it to actually do the hard work to know how much energy is still left in the pack... especially given how much $$$ they want for the packs :-) I have no idea of what software is really running inside the battery pack, of course, so maybe the SBS battery EC just sits there doing something else instead of taking real-time measurements of the battery charge (that wouldn't surprise me too much...).
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
----- Original Message ----- From: "Henrique de Moraes Holschuh" <[email protected]>
To: "Richard B. Johnson" <[email protected]>
Cc: "Bill Davidsen" <[email protected]>; "Jean Delvare" <[email protected]>; <[email protected]>; "Richard Hughes" <[email protected]>; "David Woodhouse" <[email protected]>; "Dan Williams" <[email protected]>; <[email protected]>; <[email protected]>; <[email protected]>; <[email protected]>; <[email protected]>; <[email protected]>; "linux-thinkpad mailing list" <[email protected]>; "Pavel Machek" <[email protected]>
Sent: Friday, November 03, 2006 8:23 AM
Subject: Re: [PATCH v2] Re: Battery class driver.
Quoted 12 lines · Richard B. Johnson
Quoted 4 lines
No known laptop bothers to do this. That's why the batteries fail at the most inoportune times and why it will decide to shut down when it feels like it, based totally upon some detected voltage drop when a disk-drive started.
Weird, I though the whole point behind a SBS hardware stack requiring something fairly intelligent in the battery pack and allowing for (runtime switchable!) Ah or Wh modes of operation was to allow vendors to do exactly
that: measure (V,A) permanently while the cells are above the safety cut-off fuse level, and accumulate it...
Quoted 8 lines
Well, IBM embedded a microcontroller of some sort on every SBS ThinkPad battery pack, and the ThinkPad reports battery data in Wh, so I expected it to actually do the hard work to know how much energy is still left in the pack... especially given how much $$$ they want for the packs :-) I have no idea of what software is really running inside the battery pack, of course, so maybe the SBS battery EC just sits there doing something else instead of taking real-time measurements of the battery charge (that wouldn't surprise me too much...).
I'm not sure anybody actually embeds a micro. There is some chip, originally make by National, that was supposed to monitor the battery state. I know that I have used five laptops so far and have never been able to obtain any intellegent operation. They just shut down when they feel like it. They do go to "suspend" mode to save power as well, always at the most inopertune moment.
Maybe the "ThinkPad" actually has some intellegence within. The cost of the batteries only reflects the cost of defending lawsuits <grin> and not the cost of its components. Batteries made in China seem to become "excited" at inopertune times.
Quoted 6 lines
Signature · 5 lines
-- "One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Cheers,
Dick Johnson
Penguin : Linux version 2.6.16.24 (somewhere). IT removed email "privileges" for engineers! New Book: http://www.AbominableFirebug.com
Quoted 1 line · Richard B. Johnson
I'm not sure anybody actually embeds a micro. There is some chip,
I'd have to crack open a ThinkPad battery to know for sure, as well. That's why I used "some sort of embedded controller"... I am operating on second-hand data.
Still, stuff like http://focus.ti.com/docs/prod/folders/print/bq20z90.html
gives me some hope the battery packs have some good stuff in it.
Quoted 5 lines
originally make by National, that was supposed to monitor the battery state. I know that I have used five laptops so far and have never been able to obtain any intellegent operation. They just shut down when they feel like it. They do go to "suspend" mode to save power as well, always at the most inopertune moment.
Try a ThinkPad, they are a bit better than that :-) Of course, you have to
disable (or properly configure) stuff that tries to outguess you and are not really enabled to talk to ThinkPad specifics like what comes with KDE and GNOME, if you don't want to get surprise suspends.
I am not sure how better a recent ThinkPad (T42 or newer) behaviour would be by your standards, but still...
Quoted 4 lines
Maybe the "ThinkPad" actually has some intellegence within. The cost of the batteries only reflects the cost of defending lawsuits <grin> and not the cost of its components. Batteries made in China seem to become "excited" at inopertune times.
Well, all of mine come with "made in Japan" seals from Sanyo. I sure hope this means the cells themselves are not from some third-party with shoddy quality control and manufacturing processes.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Hi!
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
Hm. Again we have the question of whether to export '
threshold_pct' vs.'threshold_abs', or whether to have a separate string property which says what the 'unit' of the threshold is. I don't care much -- I'll do whatever DavidZ prefers.Unit is easier to process in HAL in my opinion.
What about just prepending the unit to the 'threshold' file? Then user space can expect the contents of said file to be of the form "%d %s". I don't think that violates the "only one value per file" sysfs mantra.
Bad idea... I bet someone will just ignore the units part, because all the machines he seen had mW there. Just put it into the name:
power_avg_mV
Pavel
Signature · 1 line
Thanks for all the (sleeping) penguins.
Quoted 2 lines · Pavel Machek
Bad idea... I bet someone will just ignore the units part, because all the machines he seen had mW there.
Sure, user space can do silly things. Just ask davej. Let's try to assume they don't.
Quoted 3 lines
Just put it into the name:
power_avg_mV
Bad idea... it means user space will have to try to open different files and what happens when someone introduces a new unit? Ideally I'd like the unit to be part of the payload of the sysfs file. Second to that I think having the unit in a separate file is preferable.
David
Quoted 7 lines · David Zeuthen
Quoted 2 lines · Pavel Machek
Bad idea... I bet someone will just ignore the units part, because all the machines he seen had mW there.
Sure, user space can do silly things. Just ask davej. Let's try to assume they don't.
Quoted 8 lines
Quoted 3 lines
Just put it into the name:
power_avg_mVBad idea... it means user space will have to try to open different files and what happens when someone introduces a new unit? Ideally I'd like the unit to be part of the payload of the sysfs file. Second to that I think having the unit in a separate file is preferable.
Introducing new unit *should* be hard. You know, when you introduce new unit, you automatically break all the userspace.
Having separate files is actually a *feature*. It allows you to introduce new units while providing backwards compatibility.
Imagine going from mV to uV... With voltage_mV, you can have both voltage_mV and voltage_uV. In your system, you'd have to change value from mV to uV, breaking all the userspace....
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 11 lines · Pavel Machek
Quoted 8 lines
Quoted 3 lines
Just put it into the name:
power_avg_mVBad idea... it means user space will have to try to open different files and what happens when someone introduces a new unit? Ideally I'd like the unit to be part of the payload of the sysfs file. Second to that I think having the unit in a separate file is preferable.
Introducing new unit *should* be hard. You know, when you introduce new unit, you automatically break all the userspace.
Well, I just wish whatever is done for battery is also done the same way for ACPI when it moves to sysfs, and if at all possible, also to hwmon: we *are* supposed to move stuff like ACPI temperatures to sysfs using hwmon conventions, AFAIK.
That said, wearing a userspace app writer hat, I'd really prefer if it is named in such a way that I can always extract the unit, like:
power_avg:mV or
power_avg[mV]
or whatever (and I'd prefer :mV a lot more than [mV], it is much cleaner). LED seems already to be using ":" for such qualifiers (they use it for the colors).
I can't just trust that the last _foo is the unit, as it might be something that doesn't have an unit (it is the status quo in hwmon, for example). If the kernel has this unit handling thing clearly defined, I can write a generic application that displays all battery attributes beautifully, instantly aware of the units (and even doing the intelligent thing if you have both power_avg in uV and mV...)
Quoted 2 lines
Having separate files is actually a *feature*. It allows you to introduce new units while providing backwards compatibility.
Agreed.
Quoted 3 lines
Imagine going from mV to uV... With
voltage_mV, you can have bothvoltage_mVandvoltage_uV. In your system, you'd have to change value from mV to uV, breaking all the userspace....
I believe there is a school that says that "this is why userspace is supposed to use a single library helper which will have the knowledge on how to deal with this".
I am not defending such a library approach. But if the sysfs interface does not have the units anywhere, it better be strictly versioned and export that information somewhere, so that such a library is actually doable in a sane and robust way.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 7 lines · Shem Multinymous
Hi,
Quoted 2 lines · David Woodhouse
If you can summarise the bits I've missed in the meantime that would be wonderfully useful
OK. Looking at the current git snapshot:
[...]
Quoted 10 lines
Why the reversed order, for example, in
design_chargevs.charge_last? Following hwmon style, I think it should be s/design_charge/charge_design/ s/manufacture_date/date_manufactured/ s/first_use/date_first_used/ s/design_voltage/voltage_design/s/charge_last/charge_last_full/ seems less ambiguous.
s/^charge$/charge_left/ follows SBS and seems better.
Can I propose a further
s/left/remaining/
...flung at the above? Best to avoid "left" as anything but the opposite of "right", if disambiguation is the goal.
-FeRD
Hi!
Quoted 7 lines
I haven't (yet) changed from a single 'status' file to multiple '
is_flag_0' 'is_flag_1' 'is_flag_2' files. I really don't like that idea much -- it doesn't seem any more sensible than exposing each bit of the voltage value through a separate file. These flags are _read_ together, and _used_ together. I'd rather show it as a hex value 'flags' than split it up. But I still think that the current 'present,charging,low' is best.
Please do this change. sysfs *is* one file per value.. if at least to be consistent with rest of code.
drivers/battery/battery-class.c line 9
Quoted 10 lines
drivers/battery/battery-class.c new file +9
-0@@ -0,0 +1,177 @@ +/* +* Battery class core +* +* ?? 2006 David Woodhouse <[email protected]> +* +* Based on LED Class support, by John Lenz and Richard Purdie: +* +* ?? 2005 John Lenz <[email protected]> +* ?? 2005-2006 Richard Purdie <[email protected]>
Could we get something ascii here? I'm not sure what you see instead of copyright... but I see ??. I could not find it in source, but if you use non-ascii character in file, please fix that, too.
drivers/battery/battery-class.c line 68
Quoted 4 lines
drivers/battery/battery-class.c new file +4
-0+ssize_t battery_attribute_show_ac_status (char *buf,unsigned long status) +{ +return 1 +sprintf (buf,"o%s-line\n" , status?"n" :"ff" ); +}
I guess ac_online should show 0/1...
drivers/battery/battery-class.c line 118
Quoted 4 lines
drivers/battery/battery-class.c new file +4
-0+if (unlikely (err)) +return err; + + battery_dev->dev = device_create(battery_class, parent, 0,
space/tab problem?
Signature · 1 line
Thanks for all the (sleeping) penguins.
Quoted 4 lines
No, I think the distinction between batteries and
ac_adapteris large enough to have different classes of devices. You may have many batteries, but you'll only ever have oneac_adapter. I'm not sure it's an obvious abstraction to make.
No you won't :) You can have several power supplies, you can have UPS too, and limited power budget depending on the "status" of these things (for example, on some blades, we slow things down when one of the power supply fails to limit our load on the remaining one(s), though that's currently done outside of linux).
Ben.
Quoted 44 lines
Quoted 1 line
Quoted 1 line
Comments?
How are battery change notifications delivered to userspace? I know acpi is using the input layer for buttons in the future (very sane IMO), so using sysfs events for each property changing would probably be nice.
Comments on your patch:
Quoted 1 line
+#define
BAT_INFO_TEMP2(2) /* °C/1000 */Temperature expressed in degrees C/1000? - what if the temperature goes below 0? What about just using mK (kelvin / 1000) - I don't know what is used in the kernel elsewhere tho. Also, are you allowed the ° sign in kernel source now?
Quoted 1 line
+#define
BAT_INFO_CURRENT(6) /* mA */Can't this also be expressed in mW according to the ACPI spec?
Quoted 1 line
+#define
BAT_STAT_FIRE(1<<7)I know there is precedent for "FIRE" but maybe CRITICAL or DANGER might be better chosen words. We can reserve the word FIRE for when the faulty battery really is going to explode...
Richard.
Quoted 19 lines
Quoted 19 lines
commit
42fe507a262b2a2879ca62740c5312778ae78627Author: David Woodhouse <[email protected]> Date: Mon Oct 23 18:14:54 2006 +0100[BATTERY] Add support for OLPC battery
Signed-off-by David Woodhouse <[email protected]>commit
6cbec3b84e3ce737b4217788841ea10a28a5e340Author: David Woodhouse <[email protected]> Date: Mon Oct 23 18:14:14 2006 +0100[BATTERY] Add initial implementation of battery class
I really don't like the sysfs interaction, and I don't much like the internal interaction with the battery drivers either. In fact, there isn't much I _do_ like, but it's good enough as a straw man.
Signed-off-by David Woodhouse <[email protected]>