diff options
author | Sachin Nikam <snikam@nvidia.com> | 2010-02-04 10:47:48 +0530 |
---|---|---|
committer | Sachin Nikam <snikam@nvidia.com> | 2010-02-04 10:47:48 +0530 |
commit | 10d98205500f0253b383228bb6fe9723b9f7361a (patch) | |
tree | 454dd5eb4dfb3d43d9d39167e8b6830a24e36f96 /drivers | |
parent | 80b41816eaaf74678a9e56face1542076bb54b7d (diff) |
tegra ec_battery : Polling for Battery and power supply info
Bug 646822
Synopsis:[Harmony/android] Battery status is not updated whenever
there is any change in battery/power supply property
- Created a timer of interval 30 Secs which calls the function
tegra_battery_poll_timer_func().
This reports to the power supply core for power supply changes
for Battery, AC and USB.
Which gets the updated info from EC battery driver and signals the uvent.
The JNI and Battery Info application which is waiting on this uevent
then updates themselves with this lateset info from /sys/class/power_supply/*
- Unregsitered to power_supply in remove function.
- Added suspend-resume functions
- Deleting polling timer while suspend and creating it again while resume.
Change-Id: I5a09bd9c6566f1732e6d2abb2e446d1e29cfdba2
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/power/nvec_battery.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/drivers/power/nvec_battery.c b/drivers/power/nvec_battery.c index 48385e66bab3..d0b2a06410d4 100644 --- a/drivers/power/nvec_battery.c +++ b/drivers/power/nvec_battery.c @@ -40,6 +40,10 @@ #define GET_CHARGER_STATUS 1 +#define NVBATTERY_POLLING_INTERVAL 30000 /* 30 Seconds */ + +static struct timer_list battery_poll_timer; + typedef enum { NvCharger_Type_Battery = 0, @@ -283,7 +287,7 @@ static int tegra_battery_get_property(struct power_supply *psy, /* TODO:Get Charger status here */ #if GET_CHARGER_STATUS if (!NvOdmBatteryGetBatteryStatus(batt_dev->hOdmBattDev, - NvOdmBatteryInst_Main, &state)) + NvOdmBatteryInst_Main, &state)) return -ENODEV; if (state == NVODM_BATTERY_STATUS_UNKNOWN) { @@ -402,6 +406,16 @@ static int tegra_battery_get_property(struct power_supply *psy, return 0; } +static void tegra_battery_poll_timer_func(unsigned long unused) +{ + power_supply_changed(&tegra_power_supplies[NvCharger_Type_Battery]); + power_supply_changed(&tegra_power_supplies[NvCharger_Type_USB]); + power_supply_changed(&tegra_power_supplies[NvCharger_Type_AC]); + + mod_timer(&battery_poll_timer, + jiffies + msecs_to_jiffies(NVBATTERY_POLLING_INTERVAL)); +} + static int tegra_battery_probe(struct platform_device *pdev) { int i; @@ -424,27 +438,59 @@ static int tegra_battery_probe(struct platform_device *pdev) printk(KERN_ERR "Failed to register power supply\n"); } + setup_timer(&battery_poll_timer, tegra_battery_poll_timer_func, 0); + mod_timer(&battery_poll_timer, + jiffies + msecs_to_jiffies(NVBATTERY_POLLING_INTERVAL)); + return 0; } static int tegra_battery_remove(struct platform_device *pdev) { + unsigned int i = 0; + if (batt_dev) { if (batt_dev->hOdmBattDev) { NvOdmBatteryDeviceClose(batt_dev->hOdmBattDev); batt_dev->hOdmBattDev = NULL; + + for (i = 0; i < ARRAY_SIZE(tegra_power_supplies); i++) { + power_supply_unregister(&tegra_power_supplies[i]); + } } kfree(batt_dev); batt_dev = NULL; } + + del_timer_sync(&battery_poll_timer); + + return 0; +} + +static int tegra_battery_suspend(struct platform_device *dev, + pm_message_t state) +{ + /* Kill the Battery Polling timer */ + del_timer_sync(&battery_poll_timer); + return 0; +} + +static int tegra_battery_resume(struct platform_device *dev) +{ + /*Create Battery Polling timer */ + setup_timer(&battery_poll_timer, tegra_battery_poll_timer_func, 0); + mod_timer(&battery_poll_timer, + jiffies + msecs_to_jiffies(NVBATTERY_POLLING_INTERVAL)); return 0; } static struct platform_driver tegra_battery_driver = { .probe = tegra_battery_probe, .remove = tegra_battery_remove, + .suspend= tegra_battery_suspend, + .resume = tegra_battery_resume, .driver = { .name = "tegra_battery", .owner = THIS_MODULE, |