Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 350652
b: refs/heads/master
c: 58a1c15
h: refs/heads/master
v: v3
  • Loading branch information
Anton Vorontsov committed Feb 3, 2013
1 parent ceb13d7 commit 166a420
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 34c11a709e928090cf34ecd706f7d3170f4e5026
refs/heads/master: 58a1c154d449aae97a8ecad67ddbfd4024ac8446
6 changes: 6 additions & 0 deletions trunk/drivers/power/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ config AB8500_BM
help
Say Y to include support for AB8500 battery management.

config BATTERY_GOLDFISH
tristate "Goldfish battery driver"
help
Say Y to enable support for the battery and AC power in the
Goldfish emulator.

config CHARGER_PM2301
bool "PM2301 Battery Charger Driver"
depends on AB8500_BM
Expand Down
1 change: 1 addition & 0 deletions trunk/drivers/power/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o
obj-$(CONFIG_BATTERY_DS2780) += ds2780_battery.o
obj-$(CONFIG_BATTERY_DS2781) += ds2781_battery.o
obj-$(CONFIG_BATTERY_DS2782) += ds2782_battery.o
obj-$(CONFIG_BATTERY_GOLDFISH) += goldfish_battery.o
obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o
obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o
obj-$(CONFIG_BATTERY_TOSA) += tosa_battery.o
Expand Down
2 changes: 1 addition & 1 deletion trunk/drivers/power/ab8500_btemp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ static void __exit ab8500_btemp_exit(void)
platform_driver_unregister(&ab8500_btemp_driver);
}

subsys_initcall_sync(ab8500_btemp_init);
device_initcall(ab8500_btemp_init);
module_exit(ab8500_btemp_exit);

MODULE_LICENSE("GPL v2");
Expand Down
69 changes: 69 additions & 0 deletions trunk/drivers/power/ds2782_battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*
* DS2786 added by Yulia Vilensky <vilensky@compulab.co.il>
*
* UEvent sending added by Evgeny Romanov <romanov@neurosoft.ru>
*
* 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.
Expand All @@ -19,6 +21,7 @@
#include <linux/errno.h>
#include <linux/swab.h>
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/idr.h>
#include <linux/power_supply.h>
#include <linux/slab.h>
Expand All @@ -40,6 +43,8 @@

#define DS2786_CURRENT_UNITS 25

#define DS278x_DELAY 1000

struct ds278x_info;

struct ds278x_battery_ops {
Expand All @@ -54,8 +59,11 @@ struct ds278x_info {
struct i2c_client *client;
struct power_supply battery;
struct ds278x_battery_ops *ops;
struct delayed_work bat_work;
int id;
int rsns;
int capacity;
int status; /* State Of Charge */
};

static DEFINE_IDR(battery_id);
Expand Down Expand Up @@ -220,6 +228,8 @@ static int ds278x_get_status(struct ds278x_info *info, int *status)
if (err)
return err;

info->capacity = capacity;

if (capacity == 100)
*status = POWER_SUPPLY_STATUS_FULL;
else if (current_uA == 0)
Expand Down Expand Up @@ -267,6 +277,27 @@ static int ds278x_battery_get_property(struct power_supply *psy,
return ret;
}

static void ds278x_bat_update(struct ds278x_info *info)
{
int old_status = info->status;
int old_capacity = info->capacity;

ds278x_get_status(info, &info->status);

if ((old_status != info->status) || (old_capacity != info->capacity))
power_supply_changed(&info->battery);
}

static void ds278x_bat_work(struct work_struct *work)
{
struct ds278x_info *info;

info = container_of(work, struct ds278x_info, bat_work.work);
ds278x_bat_update(info);

schedule_delayed_work(&info->bat_work, DS278x_DELAY);
}

static enum power_supply_property ds278x_battery_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_CAPACITY,
Expand Down Expand Up @@ -295,10 +326,39 @@ static int ds278x_battery_remove(struct i2c_client *client)
idr_remove(&battery_id, info->id);
mutex_unlock(&battery_lock);

cancel_delayed_work(&info->bat_work);

kfree(info);
return 0;
}

#ifdef CONFIG_PM

static int ds278x_suspend(struct i2c_client *client,
pm_message_t state)
{
struct ds278x_info *info = i2c_get_clientdata(client);

cancel_delayed_work(&info->bat_work);
return 0;
}

static int ds278x_resume(struct i2c_client *client)
{
struct ds278x_info *info = i2c_get_clientdata(client);

schedule_delayed_work(&info->bat_work, DS278x_DELAY);
return 0;
}

#else

#define ds278x_suspend NULL
#define ds278x_resume NULL

#endif /* CONFIG_PM */


enum ds278x_num_id {
DS2782 = 0,
DS2786,
Expand Down Expand Up @@ -368,10 +428,17 @@ static int ds278x_battery_probe(struct i2c_client *client,
info->ops = &ds278x_ops[id->driver_data];
ds278x_power_supply_init(&info->battery);

info->capacity = 100;
info->status = POWER_SUPPLY_STATUS_FULL;

INIT_DELAYED_WORK(&info->bat_work, ds278x_bat_work);

ret = power_supply_register(&client->dev, &info->battery);
if (ret) {
dev_err(&client->dev, "failed to register battery\n");
goto fail_register;
} else {
schedule_delayed_work(&info->bat_work, DS278x_DELAY);
}

return 0;
Expand Down Expand Up @@ -401,6 +468,8 @@ static struct i2c_driver ds278x_battery_driver = {
},
.probe = ds278x_battery_probe,
.remove = ds278x_battery_remove,
.suspend = ds278x_suspend,
.resume = ds278x_resume,
.id_table = ds278x_id,
};
module_i2c_driver(ds278x_battery_driver);
Expand Down
Loading

0 comments on commit 166a420

Please sign in to comment.