ds2760_battery: 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.

Signed-off-by: Daniel Mack <daniel@caiaq.de>
Cc: Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>
Acked-by: Matt Reimer <mreimer@vpop.net>
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
This commit is contained in:
Daniel Mack 2009-07-15 18:20:40 +02:00 committed by Anton Vorontsov
parent 5c6e9bf2c9
commit c1e72193ea
1 changed files with 19 additions and 0 deletions

View File

@ -66,6 +66,10 @@ static unsigned int pmod_enabled;
module_param(pmod_enabled, bool, 0644); module_param(pmod_enabled, bool, 0644);
MODULE_PARM_DESC(pmod_enabled, "PMOD enable bit"); 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 /* Some batteries have their rated capacity stored a N * 10 mAh, while
* others use an index into this table. */ * others use an index into this table. */
static int rated_capacities[] = { 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); 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) static void ds2760_battery_work(struct work_struct *work)
{ {
struct ds2760_device_info *di = container_of(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); 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); retval = power_supply_register(&pdev->dev, &di->bat);
if (retval) { if (retval) {
dev_err(di->dev, "failed to register battery\n"); dev_err(di->dev, "failed to register battery\n");