pda-power: add set_charged functionaltity
PATCH 1/3 pda-power: add set_charged functionaltity
This adds a function to let the power supply core know that the battery is fully charged now. This can be done by watching a GPIO line, for example.
Some battery drivers might need that information to calibrate themselves.
--- drivers/power/power_supply_core.c | 16 ++++++++++++++++ include/linux/power_supply.h | 3 +++ 2 files changed, 19 insertions(+), 0 deletions(-)
drivers/power/power_supply_core.c +16 -0
@@ -111,6 +111,22 @@ int power_supply_is_system_supplied(void)return error; } +static int __power_supply_set_battery_charged (struct device *dev,void *data) +{ +struct power_supply *psy =dev_get_drvdata (dev); + +if (psy->type ==POWER_SUPPLY_TYPE_BATTERY && psy->set_charged) + psy->set_charged (psy); + +return 0 ; +} + +void power_supply_set_battery_charged (void ) +{ +class_for_each_device (power_supply_class,NULL ,NULL , + __power_supply_set_battery_charged); +} +int power_supply_register (struct device *parent,struct power_supply *psy) {int rc =0 ;
include/linux/power_supply.h +3 -0
@@ -126,6 +126,7 @@ struct power_supply {enum power_supply_property psp, union power_supply_propval *val);void (*external_power_changed)(struct power_supply *psy); +void (*set_charged)(struct power_supply *psy);/* For APM emulation, think legacy userspace. */ int use_for_apm;
@@ -170,8 +171,10 @@ extern int power_supply_am_i_supplied(struct power_supply *psy);#if defined(CONFIG_POWER_SUPPLY ) || defined(CONFIG_POWER_SUPPLY_MODULE )extern int power_supply_is_system_supplied (void ); +extern void power_supply_set_battery_charged (void );#else static inline int power_supply_is_system_supplied (void ) {return -ENOSYS ; } +static inline void power_supply_set_battery_charged (void ) {}#endif extern int power_supply_register(struct device *parent,
Signature · 1 line
1.6.3.1
PATCH 2/3 pda-power: EXPORT_SYMBOL cleanups
While I'm at it, cleanup the power supply code so that EXPORT_SYMBOL_GPL appears directly after the symbole declaration. checkpatch.pl wants it that way.
--- drivers/power/power_supply_core.c | 17 ++++++++--------- 1 files changed, 8 insertions(+), 9 deletions(-)
drivers/power/power_supply_core.c +8 -9
@@ -20,6 +20,9 @@struct class *power_supply_class; +/* exported for the APM Power driver, APM emulation */ +EXPORT_SYMBOL_GPL (power_supply_class); +static int __power_supply_changed_work (struct device *dev,void *data) {struct power_supply *psy = (struct power_supply *)data;
@@ -55,6 +58,7 @@ void power_supply_changed(struct power_supply *psy)schedule_work (&psy->changed_work); } +EXPORT_SYMBOL_GPL (power_supply_changed);static int __power_supply_am_i_supplied (struct device *dev,void *data) {
@@ -86,6 +90,7 @@ int power_supply_am_i_supplied(struct power_supply *psy)return error; } +EXPORT_SYMBOL_GPL (power_supply_am_i_supplied);static int __power_supply_is_system_supplied (struct device *dev,void *data) {
@@ -110,6 +115,7 @@ int power_supply_is_system_supplied(void)return error; } +EXPORT_SYMBOL_GPL (power_supply_is_system_supplied);static int __power_supply_set_battery_charged (struct device *dev,void *data) {
@@ -160,6 +166,7 @@ dev_create_failed: success:return rc; } +EXPORT_SYMBOL_GPL (power_supply_register);void power_supply_unregister (struct power_supply *psy) {
@@ -168,6 +175,7 @@ void power_supply_unregister(struct power_supply *psy)power_supply_remove_attrs (psy);device_unregister (psy->dev); } +EXPORT_SYMBOL_GPL (power_supply_unregister);static int __init power_supply_class_init (void ) {
@@ -186,15 +194,6 @@ static void __exit power_supply_class_exit(void)class_destroy (power_supply_class); } -EXPORT_SYMBOL_GPL (power_supply_changed); -EXPORT_SYMBOL_GPL (power_supply_am_i_supplied); -EXPORT_SYMBOL_GPL (power_supply_is_system_supplied); -EXPORT_SYMBOL_GPL (power_supply_register); -EXPORT_SYMBOL_GPL (power_supply_unregister); - -/* exported for the APM Power driver, APM emulation */ -EXPORT_SYMBOL_GPL (power_supply_class); -subsys_initcall (power_supply_class_init);module_exit (power_supply_class_exit);
Signature · 1 line
1.6.3.1
PATCH 3/3 ds2760: implement set_charged() feature
The ds2760's internal current meter is not reliable enough as it has an inacurracy of around ~15%. Without any correction for that error, the current accumulator is couting up all the time, even though the battery is already fully charged and hence destroys the static information. The longer it is connected, the worse is the aberration.
Fortunately, this can be corrected by the DS2760_CURRENT_OFFSET_BIAS register. Using the external power_supply_set_battery_charged() function, this register is now gauging the measurement.
A delayed work is used to debounce flaky GPIO signals and to let the current value settle. Also see Maxim's application note AN4188.
--- drivers/power/ds2760_battery.c | 47 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 47 insertions(+), 0 deletions(-)
drivers/power/ds2760_battery.c +47 -0
@@ -56,6 +56,7 @@ struct ds2760_device_info {struct device *w1_dev;struct workqueue_struct *monitor_wqueue;struct delayed_work monitor_work; +struct delayed_work set_charged_work; };static unsigned int cache_time =1000 ;
@@ -327,6 +328,48 @@ static void ds2760_battery_external_power_changed(struct power_supply *psy)queue_delayed_work (di->monitor_wqueue, &di->monitor_work,HZ /10 ); } + +static void ds2760_battery_set_charged_work (struct work_struct *work) +{ +char bias; +struct ds2760_device_info *di =container_of (work, + struct ds2760_device_info, set_charged_work.work); + +dev_dbg (di->dev,"%s\n" , __func__); + +ds2760_battery_read_status (di); + +/* When we get notified by external circuitry that the battery is +* considered fully charged now, we know that there is no current +* flow any more. However, the ds2760's internal current meter is +* too inaccurate to rely on - spec say something ~15% failure. +* Hence, we use the current offset bias register to compensate +* that error. +*/ + +if (!power_supply_am_i_supplied (&di->bat)) +return ; + + bias = di->current_raw + + (signed char ) di->raw[DS2760_CURRENT_OFFSET_BIAS ]; + +dev_dbg (di->dev,"%s: bias = %d\n" , __func__, bias); + +w1_ds2760_write (di->w1_dev, &bias,DS2760_CURRENT_OFFSET_BIAS ,1 ); +w1_ds2760_store_eeprom (di->w1_dev,DS2760_EEPROM_BLOCK1 ); +w1_ds2760_recall_eeprom (di->w1_dev,DS2760_EEPROM_BLOCK1 ); +} + +static void ds2760_battery_set_charged (struct power_supply *psy) +{ +struct ds2760_device_info *di =to_ds2760_device_info (psy); + +/* postpone the actual work by 20 secs. This is for debouncing GPIO +* signals and to let the current value settle. See AN4188. */ +cancel_delayed_work (&di->set_charged_work); +queue_delayed_work (di->monitor_wqueue, &di->set_charged_work,HZ *20 ); +} +static int ds2760_battery_get_property (struct power_supply *psy,enum power_supply_property psp,union power_supply_propval *val)
@@ -412,6 +455,7 @@ static int ds2760_battery_probe(struct platform_device *pdev) di->bat.properties = ds2760_battery_props; di->bat.num_properties =ARRAY_SIZE (ds2760_battery_props); di->bat.get_property = ds2760_battery_get_property; + di->bat.set_charged = ds2760_battery_set_charged; di->bat.external_power_changed = ds2760_battery_external_power_changed;
@@ -443,6 +487,7 @@ static int ds2760_battery_probe(struct platform_device *pdev) }INIT_DELAYED_WORK (&di->monitor_work, ds2760_battery_work); +INIT_DELAYED_WORK (&di->set_charged_work, ds2760_battery_set_charged_work); di->monitor_wqueue =create_singlethread_workqueue (dev_name (&pdev->dev));if (!di->monitor_wqueue) { retval = -ESRCH ;
@@ -467,6 +512,8 @@ static int ds2760_battery_remove(struct platform_device *pdev)cancel_rearming_delayed_workqueue (di->monitor_wqueue, &di->monitor_work); +cancel_rearming_delayed_workqueue (di->monitor_wqueue, + &di->set_charged_work);destroy_workqueue (di->monitor_wqueue);power_supply_unregister (&di->bat);
Signature · 1 line
1.6.3.1
Re: [PATCH 3/3] ds2760: implement set_charged() feature
Quoted 6 lines · Daniel Mack
The ds2760's internal current meter is not reliable enough as it has an inacurracy of around ~15%. Without any correction for that error, the current accumulator is couting up all the time, even though the battery is already fully charged and hence destroys the static information. The longer it is connected, the worse is the aberration.
Quoted 6 lines
Fortunately, this can be corrected by the
DS2760_CURRENT_OFFSET_BIASregister. Using the externalpower_supply_set_battery_charged()function, this register is now gauging the measurement.A delayed work is used to debounce flaky GPIO signals and to let the current value settle. Also see Maxim's application note AN4188.
One more small correction - we need to manually write back the BIAS level to the di->raw buffer as ds2760_battery_read_status() won't do it for us after the first time.
Daniel
commit ebb1173a2c6e1334b1afc7cd119b39eca2350351
Author: Daniel Mack <[email protected]> Date: Thu Jul 16 17:28:56 2009 +0200
ds2760: implement set_charged() feature
The ds2760's internal current meter is not reliable enough as it has an inacurracy of around ~15%. Without any correction for that error, the current accumulator is couting up all the time, even though the battery is already fully charged and hence destroys the static information. The longer it is connected, the worse is the aberration.
Fortunately, this can be corrected by the DS2760_CURRENT_OFFSET_BIAS register. Using the external power_supply_set_battery_charged() function, this register is now gauging the measurement.
A delayed work is used to debounce flaky GPIO signals and to let the current value settle. Also see Maxim's application note AN4188.
drivers/power/ds2760_battery.c +51 -0
@@ -56,6 +56,7 @@ struct ds2760_device_info {struct device *w1_dev;struct workqueue_struct *monitor_wqueue;struct delayed_work monitor_work; +struct delayed_work set_charged_work; };static unsigned int cache_time =1000 ;
@@ -327,6 +328,52 @@ static void ds2760_battery_external_power_changed(struct power_supply *psy)queue_delayed_work (di->monitor_wqueue, &di->monitor_work,HZ /10 ); } + +static void ds2760_battery_set_charged_work (struct work_struct *work) +{ +char bias; +struct ds2760_device_info *di =container_of (work, + struct ds2760_device_info, set_charged_work.work); + +dev_dbg (di->dev,"%s\n" , __func__); + +ds2760_battery_read_status (di); + +/* When we get notified by external circuitry that the battery is +* considered fully charged now, we know that there is no current +* flow any more. However, the ds2760's internal current meter is +* too inaccurate to rely on - spec say something ~15% failure. +* Hence, we use the current offset bias register to compensate +* that error. +*/ + +if (!power_supply_am_i_supplied (&di->bat)) +return ; + + bias = di->current_raw + + (signed char ) di->raw[DS2760_CURRENT_OFFSET_BIAS ]; + +dev_dbg (di->dev,"%s: bias = %d\n" , __func__, bias); + +w1_ds2760_write (di->w1_dev, &bias,DS2760_CURRENT_OFFSET_BIAS ,1 ); +w1_ds2760_store_eeprom (di->w1_dev,DS2760_EEPROM_BLOCK1 ); +w1_ds2760_recall_eeprom (di->w1_dev,DS2760_EEPROM_BLOCK1 ); + +/* Write to the di->raw[] buffer directly - the CURRENT_OFFSET_BIAS +* value won't be read back by ds2760_battery_read_status() */ + di->raw[DS2760_CURRENT_OFFSET_BIAS ] = bias; +} + +static void ds2760_battery_set_charged (struct power_supply *psy) +{ +struct ds2760_device_info *di =to_ds2760_device_info (psy); + +/* postpone the actual work by 20 secs. This is for debouncing GPIO +* signals and to let the current value settle. See AN4188. */ +cancel_delayed_work (&di->set_charged_work); +queue_delayed_work (di->monitor_wqueue, &di->set_charged_work,HZ *20 ); +} +static int ds2760_battery_get_property (struct power_supply *psy,enum power_supply_property psp,union power_supply_propval *val)
@@ -412,6 +459,7 @@ static int ds2760_battery_probe(struct platform_device *pdev) di->bat.properties = ds2760_battery_props; di->bat.num_properties =ARRAY_SIZE (ds2760_battery_props); di->bat.get_property = ds2760_battery_get_property; + di->bat.set_charged = ds2760_battery_set_charged; di->bat.external_power_changed = ds2760_battery_external_power_changed;
@@ -443,6 +491,7 @@ static int ds2760_battery_probe(struct platform_device *pdev) }INIT_DELAYED_WORK (&di->monitor_work, ds2760_battery_work); +INIT_DELAYED_WORK (&di->set_charged_work, ds2760_battery_set_charged_work); di->monitor_wqueue =create_singlethread_workqueue (dev_name (&pdev->dev));if (!di->monitor_wqueue) { retval = -ESRCH ;
@@ -467,6 +516,8 @@ static int ds2760_battery_remove(struct platform_device *pdev)cancel_rearming_delayed_workqueue (di->monitor_wqueue, &di->monitor_work); +cancel_rearming_delayed_workqueue (di->monitor_wqueue, + &di->set_charged_work);destroy_workqueue (di->monitor_wqueue);power_supply_unregister (&di->bat);
Quoted 6 lines · Daniel Mack
This adds a function to let the power supply core know that the battery is fully charged now. This can be done by watching a GPIO line, for example.
Some battery drivers might need that information to calibrate themselves.
Any comments about the last patch series? I've sent one inlined in a reply and three more apart from it, which might have been confusing. Do you want me to resend it as one block?
Thanks,
Daniel
Quoted 6 lines · Daniel Mack
This adds a function to let the power supply core know that the battery is fully charged now. This can be done by watching a GPIO line, for example.
Some battery drivers might need that information to calibrate themselves.
Looks fine to me.
Matt
Quoted 7 lines · Daniel Mack
This adds a function to let the power supply core know that the battery is fully charged now. This can be done by watching a GPIO line, for example.
Some battery drivers might need that information to calibrate themselves.
Quoted 7 lines
Signed-off-by Daniel Mack <[email protected]>Cc Ian Molton <[email protected]>Cc Anton Vorontsov <[email protected]>Cc Matt Reimer <[email protected]>--- drivers/power/power_supply_core.c | 16 ++++++++++++++++ include/linux/power_supply.h | 3 +++
The patch is missing pda_power.c part?
Quoted 42 lines
2 files changed, 19 insertions(+), 0 deletions(-)drivers/power/power_supply_core.c +16
-0@@ -111,6 +111,22 @@ int power_supply_is_system_supplied(void)return error; } +static int __power_supply_set_battery_charged (struct device *dev,void *data) +{ +struct power_supply *psy =dev_get_drvdata (dev); + +if (psy->type ==POWER_SUPPLY_TYPE_BATTERY && psy->set_charged) + psy->set_charged (psy); + +return 0 ; +} + +void power_supply_set_battery_charged (void ) +{ +class_for_each_device (power_supply_class,NULL ,NULL , + __power_supply_set_battery_charged); +} +int power_supply_register (struct device *parent,struct power_supply *psy) {int rc =0 ;include/linux/power_supply.h +1
-0@@ -126,6 +126,7 @@ struct power_supply {enum power_supply_property psp, union power_supply_propval *val);void (*external_power_changed)(struct power_supply *psy); +void (*set_charged)(struct power_supply *psy);/* For APM emulation, think legacy userspace. */ int use_for_apm;
include/linux/power_supply.h extern int power_supply_am_i_supplied(struct power_supply *psy); · line 174
Quoted 4 lines
include/linux/power_supply.h +1
-0@@ -170,8 +171,10 @@ extern int power_supply_am_i_supplied(struct power_supply *psy);#if defined(CONFIG_POWER_SUPPLY ) || defined(CONFIG_POWER_SUPPLY_MODULE )extern int power_supply_is_system_supplied (void ); +extern void power_supply_set_battery_charged (void );
I don't quite like this interface. Note that system might want to know if it's supplied (hence global is_system_supplied(void) call), but having set_battery_charged(void) interface makes little sense (well, it makes sense for small embedded systems that have just one battery and one charger)...
There is a supplied_to psy field that might help you there...
The cleanup patch looks OK though, I'll apply it.
Thanks,
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 16 lines · Anton Vorontsov
Quoted 7 lines · Daniel Mack
This adds a function to let the power supply core know that the battery is fully charged now. This can be done by watching a GPIO line, for example.
Some battery drivers might need that information to calibrate themselves.
Quoted 7 lines
Signed-off-by Daniel Mack <[email protected]>Cc Ian Molton <[email protected]>Cc Anton Vorontsov <[email protected]>Cc Matt Reimer <[email protected]>--- drivers/power/power_supply_core.c | 16 ++++++++++++++++ include/linux/power_supply.h | 3 +++
Quoted 1 line
The patch is missing
pda_power.cpart?
Erm, does it? What would you expect it to do in there?
Quoted 11 lines
Quoted 3 lines
#if
defined(CONFIG_POWER_SUPPLY)||defined(CONFIG_POWER_SUPPLY_MODULE)extern intpower_supply_is_system_supplied(void);
+extern voidpower_supply_set_battery_charged(void);I don't quite like this interface. Note that system might want to know if it's supplied (hence global
is_system_supplied(void)call), but havingset_battery_charged(void)interface makes little sense (well, it makes sense for small embedded systems that have just one battery and one charger)...There is a
supplied_topsy field that might help you there...
Hmm. I thought about that too, but didn't find a way to access the single members of the pda-power device and find the right one to access. They're registered on a string base and matched magically once the battery monitor is probed when found on the one-wire bus. Any proposal how an interface could look like that does that?
All I need is a way to pass this information from my platform code down to the battery driver.
Quoted 1 line
The cleanup patch looks OK though, I'll apply it.
Thanks. What about the one adding support for the bootstrapping of the current_accum value? I've sent that inline as a reply to the other patch series (4/4) last week (which was probably not a good idea).
Daniel
Quoted 17 lines · Daniel Mack
Quoted 16 lines · Anton Vorontsov
Quoted 14 lines · Daniel Mack
This adds a function to let the power supply core know that the battery is fully charged now. This can be done by watching a GPIO line, for example.
Some battery drivers might need that information to calibrate themselves.
Signed-off-by Daniel Mack <[email protected]>Cc Ian Molton <[email protected]>Cc Anton Vorontsov <[email protected]>Cc Matt Reimer <[email protected]>--- drivers/power/power_supply_core.c | 16 ++++++++++++++++ include/linux/power_supply.h | 3 +++
Quoted 3 lines
Quoted 1 line
The patch is missing
pda_power.cpart?Erm, does it? What would you expect it to do in there?
Um... then the patch subject is misleading. It says "pda-power".
Is there any user of this new call, btw? I mean a mainline user, or soon to be?
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
#if
defined(CONFIG_POWER_SUPPLY)||defined(CONFIG_POWER_SUPPLY_MODULE)extern intpower_supply_is_system_supplied(void);
+extern voidpower_supply_set_battery_charged(void);I don't quite like this interface. Note that system might want to know if it's supplied (hence global
is_system_supplied(void)call), but havingset_battery_charged(void)interface makes little sense (well, it makes sense for small embedded systems that have just one battery and one charger)...There is a
supplied_topsy field that might help you there...
Quoted 8 lines
Hmm. I thought about that too, but didn't find a way to access the single members of the pda-power device and find the right one to access. They're registered on a string base and matched magically once the battery monitor is probed when found on the one-wire bus. Any proposal how an interface could look like that does that?
All I need is a way to pass this information from my platform code down to the battery driver.
Yes, I see the problem, but I don't have a solution off-hand. :-/
Let me think about it for awhile.
Quoted 5 lines
Quoted 1 line
The cleanup patch looks OK though, I'll apply it.
Thanks. What about the one adding support for the bootstrapping of the
current_accumvalue? I've sent that inline as a reply to the other patch series (4/4) last week (which was probably not a good idea).
"ds2760: add current_accum module parameter"? Looks perfectly OK.
Thanks!
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 3 lines · Anton Vorontsov
Quoted 1 line
Erm, does it? What would you expect it to do in there?
Um... then the patch subject is misleading. It says "pda-power".
Well, that's the subsystem it addresses :)
Quoted 2 lines
Is there any user of this new call, btw? I mean a mainline user, or soon to be?
No, not yet. We might be merging our platform code mainline some day, but at the moment it doesn't make sense to anyone to have have it. The only prototypes tha exist are on our desks :)
Anyway - the surrounding code is perfectly simple. It just registers an IRQ and calls set_battery_charged() in it. The battery driver cares for debouncing and the like.
Quoted 6 lines
Quoted 6 lines
Hmm. I thought about that too, but didn't find a way to access the single members of the pda-power device and find the right one to access. They're registered on a string base and matched magically once the battery monitor is probed when found on the one-wire bus. Any proposal how an interface could look like that does that?
Quoted 6 lines
Quoted 2 lines
All I need is a way to pass this information from my platform code down to the battery driver.
Yes, I see the problem, but I don't have a solution off-hand. :-/
Let me think about it for awhile.
So will I :)
Quoted 5 lines
Quoted 3 lines
Thanks. What about the one adding support for the bootstrapping of the
current_accumvalue? I've sent that inline as a reply to the other patch series (4/4) last week (which was probably not a good idea)."ds2760: add
current_accummodule parameter"? Looks perfectly OK.
That one, yes. Thanks for applying.
Daniel
Quoted 6 lines · Anton Vorontsov
Quoted 6 lines
Hmm. I thought about that too, but didn't find a way to access the single members of the pda-power device and find the right one to access. They're registered on a string base and matched magically once the battery monitor is probed when found on the one-wire bus. Any proposal how an interface could look like that does that?
Quoted 6 lines
Quoted 2 lines
All I need is a way to pass this information from my platform code down to the battery driver.
Yes, I see the problem, but I don't have a solution off-hand. :-/
Let me think about it for awhile.
What about something like the patch below?
The platform code interface would look like
struct power_supply *psy =
power_support_get_by_name("ds2760.0");
if (psy)
power_supply_set_battery_charged(psy);Couldn't test it yet as my hardware is missing, but I would still like to hear your comments about it :)
Daniel
commit 1a865b0023619c93de095fdb35823e57a496fc0b
Author: Daniel Mack <[email protected]> Date: Thu Jul 16 15:54:46 2009 +0200
pwoer_supply: get_by_name and set_charged functionaltity
This adds a function to get a power_supply device from the class of registered devices by name reference. It can be used to find a specific battery to call power_supply_set_battery_charged() on.
Some battery drivers might need that information to calibrate themselves.
drivers/power/power_supply_core.c +28 -0
@@ -117,6 +117,34 @@ int power_supply_is_system_supplied(void) }EXPORT_SYMBOL_GPL (power_supply_is_system_supplied); +int power_supply_set_battery_charged (struct power_supply *psy) +{ +if (psy->type ==POWER_SUPPLY_TYPE_BATTERY && psy->set_charged) { + psy->set_charged (psy); +return 0 ; + } + +return -EINVAL ; +} +EXPORT_SYMBOL_GPL (power_supply_set_battery_charged); + +static int power_supply_match_device_by_name (struct device *dev,void *data) +{ +const char *name = data; +struct power_supply *psy =dev_get_drvdata (dev); + +return strcmp (psy->name, name) ==0 ; +} + +struct power_supply *power_supply_get_by_name (char *name) +{ +struct device *dev =class_find_device (power_supply_class,NULL , name, + power_supply_match_device_by_name); + +return dev ?dev_get_drvdata (dev) :NULL ; +} +EXPORT_SYMBOL_GPL (power_supply_get_by_name); +int power_supply_register (struct device *parent,struct power_supply *psy) {int rc =0 ;
include/linux/power_supply.h +3 -0
@@ -126,6 +126,7 @@ struct power_supply {enum power_supply_property psp, union power_supply_propval *val);void (*external_power_changed)(struct power_supply *psy); +void (*set_charged)(struct power_supply *psy);/* For APM emulation, think legacy userspace. */ int use_for_apm;
@@ -165,8 +166,10 @@ struct power_supply_info {int use_for_apm; }; +extern struct power_supply *power_supply_get_by_name (char *name);extern void power_supply_changed (struct power_supply *psy);extern int power_supply_am_i_supplied (struct power_supply *psy); +extern int power_supply_set_battery_charged (struct power_supply *psy);#if defined(CONFIG_POWER_SUPPLY ) || defined(CONFIG_POWER_SUPPLY_MODULE )extern int power_supply_is_system_supplied (void );
Quoted 18 lines · Daniel Mack
Quoted 6 lines · Anton Vorontsov
Quoted 6 lines
Hmm. I thought about that too, but didn't find a way to access the single members of the pda-power device and find the right one to access. They're registered on a string base and matched magically once the battery monitor is probed when found on the one-wire bus. Any proposal how an interface could look like that does that?
Quoted 6 lines
Quoted 2 lines
All I need is a way to pass this information from my platform code down to the battery driver.
Yes, I see the problem, but I don't have a solution off-hand. :-/
Let me think about it for awhile.
What about something like the patch below?
The platform code interface would look like
Quoted 7 lines
struct power_supply *psy = power_support_get_by_name("ds2760.0"); if (psy) power_supply_set_battery_charged(psy);Couldn't test it yet as my hardware is missing, but I would still like to hear your comments about it :)
Wow, looks perfect. Let me know when you test it, and I'll apply that patch.
Thanks!
Quoted 84 lines
Daniel
commit
1a865b0023619c93de095fdb35823e57a496fc0bAuthor: Daniel Mack <[email protected]> Date: Thu Jul 16 15:54:46 2009 +0200
pwoer_supply:get_by_nameandset_chargedfunctionaltityThis adds a function to get a
power_supplydevice from the class of registered devices by name reference. It can be used to find a specific battery to callpower_supply_set_battery_charged()on.Some battery drivers might need that information to calibrate themselves.
Signed-off-by Daniel Mack <[email protected]>Cc Ian Molton <[email protected]>Cc Anton Vorontsov <[email protected]>Cc Matt Reimer <[email protected]>drivers/power/power_supply_core.c +28
-0@@ -117,6 +117,34 @@ int power_supply_is_system_supplied(void) }EXPORT_SYMBOL_GPL (power_supply_is_system_supplied); +int power_supply_set_battery_charged (struct power_supply *psy) +{ +if (psy->type ==POWER_SUPPLY_TYPE_BATTERY && psy->set_charged) { + psy->set_charged (psy); +return 0 ; + } + +return -EINVAL ; +} +EXPORT_SYMBOL_GPL (power_supply_set_battery_charged); + +static int power_supply_match_device_by_name (struct device *dev,void *data) +{ +const char *name = data; +struct power_supply *psy =dev_get_drvdata (dev); + +return strcmp (psy->name, name) ==0 ; +} + +struct power_supply *power_supply_get_by_name (char *name) +{ +struct device *dev =class_find_device (power_supply_class,NULL , name, + power_supply_match_device_by_name); + +return dev ?dev_get_drvdata (dev) :NULL ; +} +EXPORT_SYMBOL_GPL (power_supply_get_by_name); +int power_supply_register (struct device *parent,struct power_supply *psy) {int rc =0 ;include/linux/power_supply.h +3
-0@@ -126,6 +126,7 @@ struct power_supply {enum power_supply_property psp, union power_supply_propval *val);void (*external_power_changed)(struct power_supply *psy); +void (*set_charged)(struct power_supply *psy);/* For APM emulation, think legacy userspace. */ int use_for_apm;@@ -165,8 +166,10 @@ struct power_supply_info {int use_for_apm; }; +extern struct power_supply *power_supply_get_by_name (char *name);extern void power_supply_changed (struct power_supply *psy);extern int power_supply_am_i_supplied (struct power_supply *psy); +extern int power_supply_set_battery_charged (struct power_supply *psy);#if defined(CONFIG_POWER_SUPPLY ) || defined(CONFIG_POWER_SUPPLY_MODULE )extern int power_supply_is_system_supplied (void );
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 10 lines · Anton Vorontsov
Quoted 9 lines · Daniel Mack
What about something like the patch below?
The platform code interface would look like
struct power_supply *psy = power_support_get_by_name("ds2760.0"); if (psy) power_supply_set_battery_charged(psy);
Quoted 5 lines
Quoted 2 lines
Couldn't test it yet as my hardware is missing, but I would still like to hear your comments about it :)
Wow, looks perfect. Let me know when you test it, and I'll apply that patch.
That seems to work well. I'm still resending the last two remaining patches as a follow-up to this one - the changelog had a typo.
Thanks,
Daniel
PATCH 1/2 power_supply: get_by_name and set_charged functionality
This adds a function to get a power_supply device from the class of registered devices by name reference. It can be used to find a specific battery to call power_supply_set_battery_charged() on.
Some battery drivers might need that information to calibrate themselves.
--- drivers/power/power_supply_core.c | 28 ++++++++++++++++++++++++++++ include/linux/power_supply.h | 3 +++ 2 files changed, 31 insertions(+), 0 deletions(-)
drivers/power/power_supply_core.c +28 -0
@@ -117,6 +117,34 @@ int power_supply_is_system_supplied(void) }EXPORT_SYMBOL_GPL (power_supply_is_system_supplied); +int power_supply_set_battery_charged (struct power_supply *psy) +{ +if (psy->type ==POWER_SUPPLY_TYPE_BATTERY && psy->set_charged) { + psy->set_charged (psy); +return 0 ; + } + +return -EINVAL ; +} +EXPORT_SYMBOL_GPL (power_supply_set_battery_charged); + +static int power_supply_match_device_by_name (struct device *dev,void *data) +{ +const char *name = data; +struct power_supply *psy =dev_get_drvdata (dev); + +return strcmp (psy->name, name) ==0 ; +} + +struct power_supply *power_supply_get_by_name (char *name) +{ +struct device *dev =class_find_device (power_supply_class,NULL , name, + power_supply_match_device_by_name); + +return dev ?dev_get_drvdata (dev) :NULL ; +} +EXPORT_SYMBOL_GPL (power_supply_get_by_name); +int power_supply_register (struct device *parent,struct power_supply *psy) {int rc =0 ;
include/linux/power_supply.h +3 -0
@@ -126,6 +126,7 @@ struct power_supply {enum power_supply_property psp, union power_supply_propval *val);void (*external_power_changed)(struct power_supply *psy); +void (*set_charged)(struct power_supply *psy);/* For APM emulation, think legacy userspace. */ int use_for_apm;
@@ -165,8 +166,10 @@ struct power_supply_info {int use_for_apm; }; +extern struct power_supply *power_supply_get_by_name (char *name);extern void power_supply_changed (struct power_supply *psy);extern int power_supply_am_i_supplied (struct power_supply *psy); +extern int power_supply_set_battery_charged (struct power_supply *psy);#if defined(CONFIG_POWER_SUPPLY ) || defined(CONFIG_POWER_SUPPLY_MODULE )extern int power_supply_is_system_supplied (void );
Signature · 1 line
1.6.3.1
PATCH 2/2 ds2760: implement set_charged() feature
The ds2760's internal current meter is not reliable enough as it has an inacurracy of around ~15%. Without any correction for that error, the current accumulator is couting up all the time, even though the battery is already fully charged and hence destroys the static information. The longer it is connected, the worse is the aberration.
Fortunately, this can be corrected by the DS2760_CURRENT_OFFSET_BIAS register. Using the external power_supply_set_battery_charged() function, this register is now gauging the measurement.
A delayed work is used to debounce flaky GPIO signals and to let the current value settle. Also see Maxim's application note AN4188.
--- drivers/power/ds2760_battery.c | 51 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 51 insertions(+), 0 deletions(-)
drivers/power/ds2760_battery.c +51 -0
@@ -56,6 +56,7 @@ struct ds2760_device_info {struct device *w1_dev;struct workqueue_struct *monitor_wqueue;struct delayed_work monitor_work; +struct delayed_work set_charged_work; };static unsigned int cache_time =1000 ;
@@ -327,6 +328,52 @@ static void ds2760_battery_external_power_changed(struct power_supply *psy)queue_delayed_work (di->monitor_wqueue, &di->monitor_work,HZ /10 ); } + +static void ds2760_battery_set_charged_work (struct work_struct *work) +{ +char bias; +struct ds2760_device_info *di =container_of (work, + struct ds2760_device_info, set_charged_work.work); + +dev_dbg (di->dev,"%s\n" , __func__); + +ds2760_battery_read_status (di); + +/* When we get notified by external circuitry that the battery is +* considered fully charged now, we know that there is no current +* flow any more. However, the ds2760's internal current meter is +* too inaccurate to rely on - spec say something ~15% failure. +* Hence, we use the current offset bias register to compensate +* that error. +*/ + +if (!power_supply_am_i_supplied (&di->bat)) +return ; + + bias = (signed char ) di->current_raw + + (signed char ) di->raw[DS2760_CURRENT_OFFSET_BIAS ]; + +dev_dbg (di->dev,"%s: bias = %d\n" , __func__, bias); + +w1_ds2760_write (di->w1_dev, &bias,DS2760_CURRENT_OFFSET_BIAS ,1 ); +w1_ds2760_store_eeprom (di->w1_dev,DS2760_EEPROM_BLOCK1 ); +w1_ds2760_recall_eeprom (di->w1_dev,DS2760_EEPROM_BLOCK1 ); + +/* Write to the di->raw[] buffer directly - the CURRENT_OFFSET_BIAS +* value won't be read back by ds2760_battery_read_status() */ + di->raw[DS2760_CURRENT_OFFSET_BIAS ] = bias; +} + +static void ds2760_battery_set_charged (struct power_supply *psy) +{ +struct ds2760_device_info *di =to_ds2760_device_info (psy); + +/* postpone the actual work by 20 secs. This is for debouncing GPIO +* signals and to let the current value settle. See AN4188. */ +cancel_delayed_work (&di->set_charged_work); +queue_delayed_work (di->monitor_wqueue, &di->set_charged_work,HZ *20 ); +} +static int ds2760_battery_get_property (struct power_supply *psy,enum power_supply_property psp,union power_supply_propval *val)
@@ -412,6 +459,7 @@ static int ds2760_battery_probe(struct platform_device *pdev) di->bat.properties = ds2760_battery_props; di->bat.num_properties =ARRAY_SIZE (ds2760_battery_props); di->bat.get_property = ds2760_battery_get_property; + di->bat.set_charged = ds2760_battery_set_charged; di->bat.external_power_changed = ds2760_battery_external_power_changed;
@@ -443,6 +491,7 @@ static int ds2760_battery_probe(struct platform_device *pdev) }INIT_DELAYED_WORK (&di->monitor_work, ds2760_battery_work); +INIT_DELAYED_WORK (&di->set_charged_work, ds2760_battery_set_charged_work); di->monitor_wqueue =create_singlethread_workqueue (dev_name (&pdev->dev));if (!di->monitor_wqueue) { retval = -ESRCH ;
@@ -467,6 +516,8 @@ static int ds2760_battery_remove(struct platform_device *pdev)cancel_rearming_delayed_workqueue (di->monitor_wqueue, &di->monitor_work); +cancel_rearming_delayed_workqueue (di->monitor_wqueue, + &di->set_charged_work);destroy_workqueue (di->monitor_wqueue);power_supply_unregister (&di->bat);
Signature · 1 line
1.6.3.1
Re: [PATCH 1/2] power_supply: get_by_name and set_charged functionality
In reply to Daniel Mackping?
Quoted 81 lines · Daniel Mack
This adds a function to get a
power_supplydevice from the class of registered devices by name reference. It can be used to find a specific battery to callpower_supply_set_battery_charged()on.Some battery drivers might need that information to calibrate themselves.
Signed-off-by Daniel Mack <[email protected]>Cc Ian Molton <[email protected]>Cc Anton Vorontsov <[email protected]>Cc Matt Reimer <[email protected]>--- drivers/power/power_supply_core.c | 28 ++++++++++++++++++++++++++++ include/linux/power_supply.h | 3 +++ 2 files changed, 31 insertions(+), 0 deletions(-)drivers/power/power_supply_core.c +28
-0@@ -117,6 +117,34 @@ int power_supply_is_system_supplied(void) }EXPORT_SYMBOL_GPL (power_supply_is_system_supplied); +int power_supply_set_battery_charged (struct power_supply *psy) +{ +if (psy->type ==POWER_SUPPLY_TYPE_BATTERY && psy->set_charged) { + psy->set_charged (psy); +return 0 ; + } + +return -EINVAL ; +} +EXPORT_SYMBOL_GPL (power_supply_set_battery_charged); + +static int power_supply_match_device_by_name (struct device *dev,void *data) +{ +const char *name = data; +struct power_supply *psy =dev_get_drvdata (dev); + +return strcmp (psy->name, name) ==0 ; +} + +struct power_supply *power_supply_get_by_name (char *name) +{ +struct device *dev =class_find_device (power_supply_class,NULL , name, + power_supply_match_device_by_name); + +return dev ?dev_get_drvdata (dev) :NULL ; +} +EXPORT_SYMBOL_GPL (power_supply_get_by_name); +int power_supply_register (struct device *parent,struct power_supply *psy) {int rc =0 ;include/linux/power_supply.h +3
-0@@ -126,6 +126,7 @@ struct power_supply {enum power_supply_property psp, union power_supply_propval *val);void (*external_power_changed)(struct power_supply *psy); +void (*set_charged)(struct power_supply *psy);/* For APM emulation, think legacy userspace. */ int use_for_apm;@@ -165,8 +166,10 @@ struct power_supply_info {int use_for_apm; }; +extern struct power_supply *power_supply_get_by_name (char *name);extern void power_supply_changed (struct power_supply *psy);extern int power_supply_am_i_supplied (struct power_supply *psy); +extern int power_supply_set_battery_charged (struct power_supply *psy);#if defined(CONFIG_POWER_SUPPLY ) || defined(CONFIG_POWER_SUPPLY_MODULE )extern int power_supply_is_system_supplied (void );Signature · 1 line
1.6.3.1
Re: [PATCH 1/2] power_supply: get_by_name and set_charged functionality
Quoted 1 line · Daniel Mack
ping?
Looks ok. the only comment I have right now is that the comment doesnt quite match the patch - it suggests that the patch doesnt include the power_supply_set_battery_charged() function, when it does in fact.
Quoted 84 lines · Daniel Mack
Quoted 81 lines
This adds a function to get a
power_supplydevice from the class of registered devices by name reference. It can be used to find a specific battery to callpower_supply_set_battery_charged()on.Some battery drivers might need that information to calibrate themselves.
Signed-off-by Daniel Mack <[email protected]>Cc Ian Molton <[email protected]>Cc Anton Vorontsov <[email protected]>Cc Matt Reimer <[email protected]>--- drivers/power/power_supply_core.c | 28 ++++++++++++++++++++++++++++ include/linux/power_supply.h | 3 +++ 2 files changed, 31 insertions(+), 0 deletions(-)drivers/power/power_supply_core.c +28
-0@@ -117,6 +117,34 @@ int power_supply_is_system_supplied(void) }EXPORT_SYMBOL_GPL (power_supply_is_system_supplied); +int power_supply_set_battery_charged (struct power_supply *psy) +{ +if (psy->type ==POWER_SUPPLY_TYPE_BATTERY && psy->set_charged) { + psy->set_charged (psy); +return 0 ; + } + +return -EINVAL ; +} +EXPORT_SYMBOL_GPL (power_supply_set_battery_charged); + +static int power_supply_match_device_by_name (struct device *dev,void *data) +{ +const char *name = data; +struct power_supply *psy =dev_get_drvdata (dev); + +return strcmp (psy->name, name) ==0 ; +} + +struct power_supply *power_supply_get_by_name (char *name) +{ +struct device *dev =class_find_device (power_supply_class,NULL , name, + power_supply_match_device_by_name); + +return dev ?dev_get_drvdata (dev) :NULL ; +} +EXPORT_SYMBOL_GPL (power_supply_get_by_name); +int power_supply_register (struct device *parent,struct power_supply *psy) {int rc =0 ;include/linux/power_supply.h +3
-0@@ -126,6 +126,7 @@ struct power_supply {enum power_supply_property psp, union power_supply_propval *val);void (*external_power_changed)(struct power_supply *psy); +void (*set_charged)(struct power_supply *psy);/* For APM emulation, think legacy userspace. */ int use_for_apm;@@ -165,8 +166,10 @@ struct power_supply_info {int use_for_apm; }; +extern struct power_supply *power_supply_get_by_name (char *name);extern void power_supply_changed (struct power_supply *psy);extern int power_supply_am_i_supplied (struct power_supply *psy); +extern int power_supply_set_battery_charged (struct power_supply *psy);#if defined(CONFIG_POWER_SUPPLY ) || defined(CONFIG_POWER_SUPPLY_MODULE )extern int power_supply_is_system_supplied (void );Signature · 1 line
1.6.3.1
Re: [PATCH 1/2] power_supply: get_by_name and set_charged functionality
Quoted 3 lines · Ian molton
Looks ok. the only comment I have right now is that the comment doesnt quite match the patch - it suggests that the patch doesnt include the
power_supply_set_battery_charged()function, when it does in fact.
The subject mentions it, and the body references it again. Hmm. Anyway. Want me to resend? Or could the commiter add another sentence to point that out? I think that would be Anton, as he agreed to pick all the other patches I recently sent in.
Thanks,
Daniel
Quoted 78 lines
Quoted 77 lines · Daniel Mack
Quoted 76 lines
This adds a function to get a
power_supplydevice from the class of registered devices by name reference. It can be used to find a specific battery to callpower_supply_set_battery_charged()on.Some battery drivers might need that information to calibrate themselves.
Signed-off-by Daniel Mack <[email protected]>Cc Ian Molton <[email protected]>Cc Anton Vorontsov <[email protected]>Cc Matt Reimer <[email protected]>--- drivers/power/power_supply_core.c | 28 ++++++++++++++++++++++++++++ include/linux/power_supply.h | 3 +++ 2 files changed, 31 insertions(+), 0 deletions(-)drivers/power/power_supply_core.c +27
-0@@ -117,6 +117,34 @@ int power_supply_is_system_supplied(void) }EXPORT_SYMBOL_GPL (power_supply_is_system_supplied); +int power_supply_set_battery_charged(struct power_supply *psy) +{ +if (psy->type ==POWER_SUPPLY_TYPE_BATTERY && psy->set_charged) { + psy->set_charged (psy); +return 0 ; + } + +return -EINVAL ; +} +EXPORT_SYMBOL_GPL (power_supply_set_battery_charged); + +static int power_supply_match_device_by_name (struct device *dev,void *data) +{ +const char *name = data; +struct power_supply *psy =dev_get_drvdata (dev); + +return strcmp (psy->name, name) ==0 ; +} + +struct power_supply *power_supply_get_by_name (char *name) +{ +struct device *dev =class_find_device (power_supply_class,NULL , name, + power_supply_match_device_by_name); + +return dev ?dev_get_drvdata (dev) :NULL ; +} +EXPORT_SYMBOL_GPL (power_supply_get_by_name); +int power_supply_register (struct device *parent,struct power_supply *psy) {int rc =0 ;include/linux/power_supply.h +2
-0@@ -126,6 +126,7 @@ struct power_supply {enum power_supply_property psp, union power_supply_propval *val);void (*external_power_changed)(struct power_supply *psy); +void (*set_charged)(struct power_supply *psy);/* For APM emulation, think legacy userspace. */ int use_for_apm;@@ -165,8 +166,10 @@ struct power_supply_info {int use_for_apm; }; +extern struct power_supply *power_supply_get_by_name(char *name);extern void power_supply_changed (struct power_supply *psy);extern int power_supply_am_i_supplied (struct power_supply *psy); +extern int power_supply_set_battery_charged (struct power_supply *psy);#if defined(CONFIG_POWER_SUPPLY ) || defined(CONFIG_POWER_SUPPLY_MODULE )extern int power_supply_is_system_supplied (void );
Re: [PATCH 1/2] power_supply: get_by_name and set_charged functionality
Quoted 7 lines · Daniel Mack
Quoted 1 line · Ian molton
Looks ok. the only comment I have right now is that the comment doesnt quite match the patch - it suggests that the patch doesnt include the
power_supply_set_battery_charged()function, when it does in fact.The subject mentions it, and the body references it again. Hmm. Anyway. Want me to resend? Or could the commiter add another sentence to point that out? I think that would be Anton, as he agreed to pick all the other patches I recently sent in.
I'm not that fussed - you just seemed to want feedback, so I had a read ;-)
If you change it, I'd write something like:
This adds a function that indicates that a battery is fully charged. It also includes functions to get a power_supply device from the class of registered devices by name reference. These can be used to find a specific battery to call power_supply_set_battery_charged() on.
Some battery drivers might need this information to calibrate themselves.
Or something.
Re: [PATCH 1/2] power_supply: get_by_name and set_charged functionality
Quoted 16 lines · Ian Molton
Quoted 10 lines · Daniel Mack
Quoted 4 lines · Ian molton
Looks ok. the only comment I have right now is that the comment doesnt quite match the patch - it suggests that the patch doesnt include the
power_supply_set_battery_charged()function, when it does in fact.The subject mentions it, and the body references it again. Hmm. Anyway. Want me to resend? Or could the commiter add another sentence to point that out? I think that would be Anton, as he agreed to pick all the other patches I recently sent in.
I'm not that fussed - you just seemed to want feedback, so I had a read ;-)
If you change it, I'd write something like:
Quoted 8 lines
This adds a function that indicates that a battery is fully charged. It also includes functions to get a
power_supplydevice from the class of registered devices by name reference. These can be used to find a specific battery to callpower_supply_set_battery_charged()on.Some battery drivers might need this information to calibrate themselves.
Ian, Matt, much thanks for reviews and acks! Daniel, thanks for the patches, and for the patience. :-)
Following patches applied to battery-2.6.git (for -next):
Daniel Mack (8):
ds2760_battery: delay power supply registration
ds2760_battery: export more features
ds2760_battery: add rated_capacity module parameter
ds2760_battery: handle full_active_uAh == 0 case correctly
ds2760_battery: add current_accum module parameter
power_supply: EXPORT_SYMBOL cleanups
power_supply: get_by_name and set_charged functionality
ds2760_battery: implement set_charged() feature
Let me know if I missed anything.
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Re: [PATCH 1/2] power_supply: get_by_name and set_charged functionality
Quoted 16 lines · Anton Vorontsov
Ian, Matt, much thanks for reviews and acks! Daniel, thanks for the patches, and for the patience. :-)
Following patches applied to battery-2.6.git (for -next):
Daniel Mack (8):
ds2760_battery: delay power supply registration
ds2760_battery: export more features
ds2760_battery: addrated_capacitymodule parameter
ds2760_battery: handlefull_active_uAh== 0 case correctly
ds2760_battery: addcurrent_accummodule parameter
power_supply:EXPORT_SYMBOLcleanups
power_supply:get_by_nameandset_chargedfunctionality
ds2760_battery: implementset_charged()feature
Quoted 1 line
Let me know if I missed anything.
Looks good. Thanks a lot :) There might be some more coming up the next days.
Daniel