ds2760: delay power supply registration
PATCH 1/4 ds2760: delay power supply registration
This fixes a race condition I recently introduced with the PMOD feature addition (cef437e3: "w1: ds2760_battery: add support for sleep mode feature").
Postpone the call to power_supply_register() to fix it.
--- drivers/power/ds2760_battery.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
drivers/power/ds2760_battery.c +6 -6
@@ -381,12 +381,6 @@ static int ds2760_battery_probe(struct platform_device *pdev) di->charge_status =POWER_SUPPLY_STATUS_UNKNOWN ; - retval =power_supply_register (&pdev->dev, &di->bat); -if (retval) { -dev_err (di->dev,"failed to register battery\n" ); - goto batt_failed; - } -/* enable sleep mode feature */ ds2760_battery_read_status (di); status = di->raw[DS2760_STATUS_REG ];
@@ -397,6 +391,12 @@ static int ds2760_battery_probe(struct platform_device *pdev)ds2760_battery_write_status (di, status); + retval =power_supply_register (&pdev->dev, &di->bat); +if (retval) { +dev_err (di->dev,"failed to register battery\n" ); + goto batt_failed; + } +INIT_DELAYED_WORK (&di->monitor_work, ds2760_battery_work); di->monitor_wqueue =create_singlethread_workqueue (dev_name (&pdev->dev));if (!di->monitor_wqueue) {
Signature · 1 line
1.6.3.1
PATCH 2/4 ds2760: export more features
Export POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW and POWER_SUPPLY_PROP_CAPACITY features to the power supply core.
--- drivers/power/ds2760_battery.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
drivers/power/ds2760_battery.c +8 -0
@@ -337,6 +337,12 @@ static int ds2760_battery_get_property(struct power_supply *psy,case POWER_SUPPLY_PROP_TEMP : val->intval = di->temp_C;break ; +case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW : + val->intval = di->life_sec; +break ; +case POWER_SUPPLY_PROP_CAPACITY : + val->intval = di->rem_capacity; +break ;default :return -EINVAL ; }
@@ -353,6 +359,8 @@ static enum power_supply_property ds2760_battery_props[] = {POWER_SUPPLY_PROP_CHARGE_EMPTY ,POWER_SUPPLY_PROP_CHARGE_NOW ,POWER_SUPPLY_PROP_TEMP , +POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW , + POWER_SUPPLY_PROP_CAPACITY, };static int ds2760_battery_probe (struct platform_device *pdev)
Signature · 1 line
1.6.3.1
PATCH 3/4 ds2760: add rated_capacity module parameter
For systems where the ds2760 is soldered directly on the PCB, the 'rated capacity' register is not set to anything useful.
In order to allow users to bootstrap this value, introduce a new module parameter 'rated_capacity' and use it to write the internal EEPROM in case the value differes from what's been given.
--- drivers/power/ds2760_battery.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-)
drivers/power/ds2760_battery.c +19 -0
@@ -66,6 +66,10 @@ static unsigned int pmod_enabled;module_param (pmod_enabled, bool,0644 );MODULE_PARM_DESC (pmod_enabled,"PMOD enable bit" ); +static unsigned int rated_capacity; +module_param (rated_capacity, uint,0644 ); +MODULE_PARM_DESC (rated_capacity,"rated battery capacity, 10*mAh or index" ); +/* Some batteries have their rated capacity stored a N * 10 mAh, while * others use an index into this table. */ static int rated_capacities[] = {
@@ -274,6 +278,17 @@ static void ds2760_battery_write_status(struct ds2760_device_info *di,w1_ds2760_recall_eeprom (di->w1_dev,DS2760_EEPROM_BLOCK1 ); } +static void ds2760_battery_write_rated_capacity (struct ds2760_device_info *di, +unsigned char rated_capacity) +{ +if (rated_capacity == di->raw[DS2760_RATED_CAPACITY ]) +return ; + +w1_ds2760_write (di->w1_dev, &rated_capacity,DS2760_RATED_CAPACITY ,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_work (struct work_struct *work) { struct ds2760_device_info *di = container_of(work,
@@ -399,6 +414,10 @@ static int ds2760_battery_probe(struct platform_device *pdev)ds2760_battery_write_status (di, status); +/* set rated capacity from module param */ +if (rated_capacity) +ds2760_battery_write_rated_capacity (di, rated_capacity); + retval =power_supply_register (&pdev->dev, &di->bat);if (retval) {dev_err (di->dev,"failed to register battery\n" );
Signature · 1 line
1.6.3.1
PATCH 4/4 ds2760: handle full_active_uAh == 0 case correctly
In systems where the battery monitor is not part of the battery pack and is hence not bootstrapped with sane values, the full_active_uAh is likely to be zero.
Handle that case by defaulting to the rated_capacity information which can be passed to the driver using the new module parameter.
--- drivers/power/ds2760_battery.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
drivers/power/ds2760_battery.c +7 -2
@@ -172,8 +172,13 @@ static int ds2760_battery_read_status(struct ds2760_device_info *di) di->full_active_uAh = di->raw[DS2760_ACTIVE_FULL ] <<8 | di->raw[DS2760_ACTIVE_FULL +1 ]; - scale[0 ] = di->raw[DS2760_ACTIVE_FULL ] <<8 | - di->raw[DS2760_ACTIVE_FULL +1 ]; +/* If the full_active_uAh value is not given, fall back to the rated +* capacity. This is likely to happen when chips are not part of the +* battery pack and is therefore not bootstrapped. */ +if (di->full_active_uAh ==0 ) + di->full_active_uAh = di->rated_capacity /1000L ; + + scale[0 ] = di->full_active_uAh;for (i =1 ; i <5 ; i++) scale[i] = scale[i -1 ] + di->raw[DS2760_ACTIVE_FULL +2 + i];
Signature · 1 line
1.6.3.1
Re: [PATCH 4/4] ds2760: handle full_active_uAh == 0 case correctly
Quoted 11 lines · Daniel Mack
In systems where the battery monitor is not part of the battery pack and is hence not bootstrapped with sane values, the
full_active_uAhis likely to be zero.Handle that case by defaulting to the
rated_capacityinformation which can be passed to the driver using the new module parameter.Signed-off-by Daniel Mack <[email protected]>Cc Szabolcs Gyurko <[email protected]>Cc Matt Reimer <[email protected]>Cc Anton Vorontsov <[email protected]>
Matt
Re: [PATCH 4/4] ds2760: handle full_active_uAh == 0 case correctly
Quoted 10 lines · Matt Reimer
Quoted 8 lines · Daniel Mack
In systems where the battery monitor is not part of the battery pack and
is hence not bootstrapped with sane values, thefull_active_uAhis likely to be zero.Handle that case by defaulting to the
rated_capacityinformation which can be passed to the driver using the new module parameter.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Daniel Mack <[email protected]>Cc Szabolcs Gyurko <[email protected]>Cc Matt Reimer <[email protected]>Cc Anton Vorontsov <[email protected]>Acked-by Matt Reimer <[email protected]>
Thanks Matt :) Andrew, will they go thru your channel?
Daniel
Re: [PATCH 4/4] ds2760: handle full_active_uAh == 0 case correctly
Quoted 11 lines · On Wed, 15 Jul 2009 20:51:59 +0200 Daniel Mack <[email protected]> wrote:
Quoted 10 lines · Matt Reimer
Quoted 8 lines · Daniel Mack
In systems where the battery monitor is not part of the battery pack and
is hence not bootstrapped with sane values, thefull_active_uAhis likely to be zero.Handle that case by defaulting to the
rated_capacityinformation which can be passed to the driver using the new module parameter.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Signed-off-by Daniel Mack <[email protected]>Cc Szabolcs Gyurko <[email protected]>Cc Matt Reimer <[email protected]>Cc Anton Vorontsov <[email protected]>Acked-by Matt Reimer <[email protected]>Thanks Matt :) Andrew, will they go thru your channel?
Well. I'll look at them, as I try to do when someone cc'ed me. But drivers/power is usually handled by Anton?
Re: [PATCH 4/4] ds2760: handle full_active_uAh == 0 case correctly
Quoted 19 lines · Andrew Morton
Quoted 16 lines · On Wed, 15 Jul 2009 20:51:59 +0200 Daniel Mack <[email protected]> wrote:
Quoted 15 lines · Matt Reimer
Quoted 12 lines · Daniel Mack
In systems where the battery monitor is not part of the battery pack and
is hence not bootstrapped with sane values, thefull_active_uAhis likely to be zero.Handle that case by defaulting to the
rated_capacityinformation which can be passed to the driver using the new module parameter.Signed-off-by Daniel Mack <[email protected]>Cc Szabolcs Gyurko <[email protected]>Cc Matt Reimer <[email protected]>Cc Anton Vorontsov <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Acked-by Matt Reimer <[email protected]>Thanks Matt :) Andrew, will they go thru your channel?
Well. I'll look at them, as I try to do when someone cc'ed me. But
drivers/poweris usually handled by Anton?
Yep. All patches look good, I'll apply them to battery-2.6.git.
Thanks,
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Re: [PATCH 4/4] ds2760: handle full_active_uAh == 0 case correctly
Quoted 5 lines · Anton Vorontsov
Quoted 2 lines · Andrew Morton
Well. I'll look at them, as I try to do when someone cc'ed me. But
drivers/poweris usually handled by Anton?Yep. All patches look good, I'll apply them to battery-2.6.git.
Thanks. Please consider applying the one below as well if you're fine with it. We need that parameter for bootstrapping in the factory when devices are produced.
Thanks,
Daniel
Quoted 1 line
From
75b680d069596351da674023146f34b1737ea8abMon Sep 17 00:00:00 2001
From: Daniel Mack <[email protected]>
Date: Wed, 15 Jul 2009 21:57:29 +0200
Subject: [PATCH] ds2760: add current_accum module parameter
When connecting a ds2760 to a partly loaded battery the first time, there must be a way to bootstrap the current_accum value. Without that, the current capactity value is bogus until the battery is fully charged for the first time.
--- drivers/power/ds2760_battery.c | 36 +++++++++++++++++++++++------------- 1 files changed, 23 insertions(+), 13 deletions(-)
drivers/power/ds2760_battery.c +23 -13
@@ -70,6 +70,10 @@ static unsigned int rated_capacity;module_param (rated_capacity, uint,0644 );MODULE_PARM_DESC (rated_capacity,"rated battery capacity, 10*mAh or index" ); +static unsigned int current_accum; +module_param (current_accum, uint,0644 ); +MODULE_PARM_DESC (current_accum,"current accumulator value" ); +/* Some batteries have their rated capacity stored a N * 10 mAh, while * others use an index into this table. */ static int rated_capacities[] = {
@@ -215,6 +219,18 @@ static int ds2760_battery_read_status(struct ds2760_device_info *di)return 0 ; } +static void ds2760_battery_set_current_accum (struct ds2760_device_info *di, +unsigned int acr_val) +{ +unsigned char acr[2 ]; + + acr[0 ] = acr_val >>8 ; + acr[1 ] = acr_val &0xff ; + +if (w1_ds2760_write (di->w1_dev, acr,DS2760_CURRENT_ACCUM_MSB ,2 ) <2 ) +dev_warn (di->dev,"ACR write failed\n" ); +} +static void ds2760_battery_update_status (struct ds2760_device_info *di) {int old_charge_status = di->charge_status;
@@ -246,20 +262,9 @@ static void ds2760_battery_update_status(struct ds2760_device_info *di)if (di->full_counter <2 ) { di->charge_status =POWER_SUPPLY_STATUS_CHARGING ; }else { -unsigned char acr[2 ]; -int acr_val; -/* acr is in units of 0.25 mAh */ - acr_val = di->full_active_uAh *4L /1000 ; - - acr[0 ] = acr_val >>8 ; - acr[1 ] = acr_val &0xff ; - -if (w1_ds2760_write (di->w1_dev, acr, -DS2760_CURRENT_ACCUM_MSB ,2 ) <2 ) -dev_warn (di->dev, -"ACR reset failed\n" ); - +int acr_val = di->full_active_uAh *4L /1000 ; +ds2760_battery_set_current_accum (di, acr_val); di->charge_status =POWER_SUPPLY_STATUS_FULL ; } }
@@ -423,6 +428,11 @@ static int ds2760_battery_probe(struct platform_device *pdev)if (rated_capacity)ds2760_battery_write_rated_capacity (di, rated_capacity); +/* set current accumulator if given as parameter. +* this should only be done for bootstrapping the value */ +if (current_accum) +ds2760_battery_set_current_accum (di, current_accum); + retval =power_supply_register (&pdev->dev, &di->bat);if (retval) {dev_err (di->dev,"failed to register battery\n" );
Signature · 1 line
1.6.3.1
Re: [PATCH 4/4] ds2760: handle full_active_uAh == 0 case correctly
Quoted 11 lines · Daniel Mack
Quoted 1 line · Anton Vorontsov
Yep. All patches look good, I'll apply them to battery-2.6.git.
Thanks. Please consider applying the one below as well if you're fine with it. We need that parameter for bootstrapping in the factory when devices are produced.
When connecting a ds2760 to a partly loaded battery the first time, there must be a way to bootstrap the
current_accumvalue. Without that, the current capactity value is bogus until the battery is fully charged for the first time.
Erm, sorry, here's another version that does the 0.25mAh -> Ah calculation in ds2760_battery_set_current_accum().
Daniel
Quoted 1 line
From
e89cd102afe30dcb26fa3c788b439aebc52a93c3Mon Sep 17 00:00:00 2001
From: Daniel Mack <[email protected]>
Date: Wed, 15 Jul 2009 21:57:29 +0200
Subject: [PATCH] ds2760: add current_accum module parameter
When connecting a ds2760 to a partly loaded battery the first time, there must be a way to bootstrap the current_accum value. Without that, the current capactity value is bogus until the battery is fully charged for the first time.
--- drivers/power/ds2760_battery.c | 41 ++++++++++++++++++++++++++------------- 1 files changed, 27 insertions(+), 14 deletions(-)
drivers/power/ds2760_battery.c +27 -14
@@ -70,6 +70,10 @@ static unsigned int rated_capacity;module_param (rated_capacity, uint,0644 );MODULE_PARM_DESC (rated_capacity,"rated battery capacity, 10*mAh or index" ); +static unsigned int current_accum; +module_param (current_accum, uint,0644 ); +MODULE_PARM_DESC (current_accum,"current accumulator value" ); +/* Some batteries have their rated capacity stored a N * 10 mAh, while * others use an index into this table. */ static int rated_capacities[] = {
@@ -215,6 +219,22 @@ static int ds2760_battery_read_status(struct ds2760_device_info *di)return 0 ; } +static void ds2760_battery_set_current_accum (struct ds2760_device_info *di, +unsigned int acr_val) +{ +unsigned char acr[2 ]; + +/* acr is in units of 0.25 mAh */ + acr_val *=4L ; + acr_val /=1000 ; + + acr[0 ] = acr_val >>8 ; + acr[1 ] = acr_val &0xff ; + +if (w1_ds2760_write (di->w1_dev, acr,DS2760_CURRENT_ACCUM_MSB ,2 ) <2 ) +dev_warn (di->dev,"ACR write failed\n" ); +} +static void ds2760_battery_update_status (struct ds2760_device_info *di) {int old_charge_status = di->charge_status;
@@ -246,21 +266,9 @@ static void ds2760_battery_update_status(struct ds2760_device_info *di)if (di->full_counter <2 ) { di->charge_status =POWER_SUPPLY_STATUS_CHARGING ; }else { -unsigned char acr[2 ]; -int acr_val; - -/* acr is in units of 0.25 mAh */ - acr_val = di->full_active_uAh *4L /1000 ; - - acr[0 ] = acr_val >>8 ; - acr[1 ] = acr_val &0xff ; - -if (w1_ds2760_write (di->w1_dev, acr, -DS2760_CURRENT_ACCUM_MSB ,2 ) <2 ) -dev_warn (di->dev, -"ACR reset failed\n" ); - di->charge_status =POWER_SUPPLY_STATUS_FULL ; +ds2760_battery_set_current_accum (di, + di->full_active_uAh); } } }else {
@@ -423,6 +431,11 @@ static int ds2760_battery_probe(struct platform_device *pdev)if (rated_capacity)ds2760_battery_write_rated_capacity (di, rated_capacity); +/* set current accumulator if given as parameter. +* this should only be done for bootstrapping the value */ +if (current_accum) +ds2760_battery_set_current_accum (di, current_accum); + retval =power_supply_register (&pdev->dev, &di->bat);if (retval) {dev_err (di->dev,"failed to register battery\n" );
Signature · 1 line
1.6.3.1
Re: [PATCH 3/4] ds2760: add rated_capacity module parameter
In reply to Daniel MackQuoted 11 lines · Daniel Mack
For systems where the ds2760 is soldered directly on the PCB, the 'rated capacity' register is not set to anything useful.
In order to allow users to bootstrap this value, introduce a new module parameter '
rated_capacity' and use it to write the internal EEPROM in case the value differes from what's been given.Signed-off-by Daniel Mack <[email protected]>Cc Szabolcs Gyurko <[email protected]>Cc Matt Reimer <[email protected]>Cc Anton Vorontsov <[email protected]>
Matt
Re: [PATCH 2/4] ds2760: export more features
In reply to Daniel MackQuoted 7 lines · Daniel Mack
Export
POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOWandPOWER_SUPPLY_PROP_CAPACITYfeatures to the power supply core.Signed-off-by Daniel Mack <[email protected]>Cc Szabolcs Gyurko <[email protected]>Cc Matt Reimer <[email protected]>Cc Anton Vorontsov <[email protected]>
Matt
Quoted 10 lines · Daniel Mack
This fixes a race condition I recently introduced with the PMOD feature addition (
cef437e3: "w1:ds2760_battery: add support for sleep mode feature").Postpone the call to
power_supply_register()to fix it.Signed-off-by Daniel Mack <[email protected]>Cc Szabolcs Gyurko <[email protected]>Cc Matt Reimer <[email protected]>Cc Anton Vorontsov <[email protected]>
Matt