summaryrefslogtreecommitdiff
path: root/drivers/power
diff options
context:
space:
mode:
authorrohitk <rohitk@nvidia.com>2011-01-21 16:14:14 +0530
committerVarun Colbert <vcolbert@nvidia.com>2011-01-21 15:16:02 -0800
commit7f720a4461305777e92bdd19ce99562b8b70c45f (patch)
treefbdcd6d61c44318f2e47d099ffe2bb442a90ea85 /drivers/power
parentb88014559b16532c2a4061b646c9dbe71a3c186d (diff)
power: bq20z75-battery: Add flag to check presence of battery.
- Added a flag to cache whether the battery is present or not. - Added checks for battery presence before trying to communicate with the battery over i2c. Bug 781962 Change-Id: I30d5842dee052baa33e7242c1cfa1e58d554d9d2 Reviewed-on: http://git-master/r/16526 Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com> Tested-by: Bharat Nihalani <bnihalani@nvidia.com> Tested-by: Varun Wadekar <vwadekar@nvidia.com> Reviewed-by: Nitin Kumbhar <nkumbhar@nvidia.com>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/bq20z75_battery.c41
1 files changed, 28 insertions, 13 deletions
diff --git a/drivers/power/bq20z75_battery.c b/drivers/power/bq20z75_battery.c
index b0d0468b4ae6..842b59404362 100644
--- a/drivers/power/bq20z75_battery.c
+++ b/drivers/power/bq20z75_battery.c
@@ -144,6 +144,7 @@ static struct bq20z75_device_info {
struct timer_list battery_poll_timer;
struct i2c_client *client;
int irq;
+ bool battery_present;
} *bq20z75_device;
static int bq20z75_get_ac_status(void)
@@ -395,8 +396,6 @@ static int bq20z75_probe(struct i2c_client *client,
if (!bq20z75_device)
return -ENOMEM;
- memset(bq20z75_device, 0, sizeof(*bq20z75_device));
-
bq20z75_device->client = client;
flags = bq20z75_device->client->flags;
bq20z75_device->client->flags &= ~I2C_M_IGNORE_NAK;
@@ -407,6 +406,8 @@ static int bq20z75_probe(struct i2c_client *client,
dev_err(&bq20z75_device->client->dev,
"%s: no battery present(%d)\n", __func__, rc);
supply_index = SUPPLY_TYPE_AC;
+ } else {
+ bq20z75_device->battery_present = true;
}
bq20z75_device->client->flags = flags;
@@ -434,10 +435,12 @@ static int bq20z75_probe(struct i2c_client *client,
}
}
- setup_timer(&bq20z75_device->battery_poll_timer,
- battery_poll_timer_func, 0);
- mod_timer(&bq20z75_device->battery_poll_timer,
- jiffies + msecs_to_jiffies(BATTERY_POLL_PERIOD));
+ if (bq20z75_device->battery_present) {
+ setup_timer(&bq20z75_device->battery_poll_timer,
+ battery_poll_timer_func, 0);
+ mod_timer(&bq20z75_device->battery_poll_timer,
+ jiffies + msecs_to_jiffies(BATTERY_POLL_PERIOD));
+ }
dev_info(&bq20z75_device->client->dev, "driver registered\n");
return 0;
@@ -453,13 +456,16 @@ fail_irq:
static int bq20z75_remove(struct i2c_client *client)
{
- struct bq20z75_device_info *bq20z75_device;
- int i;
+ struct bq20z75_device_info *bq20z75_device =
+ i2c_get_clientdata(client);
+ int supply_index = 0, i;
- bq20z75_device = i2c_get_clientdata(client);
- del_timer_sync(&bq20z75_device->battery_poll_timer);
+ if (bq20z75_device->battery_present)
+ del_timer_sync(&bq20z75_device->battery_poll_timer);
+ else
+ supply_index = SUPPLY_TYPE_AC;
- for (i = 0; i < ARRAY_SIZE(bq20z75_supply); i++)
+ for (i = supply_index; i < ARRAY_SIZE(bq20z75_supply); i++)
power_supply_unregister(&bq20z75_supply[i]);
kfree(bq20z75_device);
@@ -472,9 +478,12 @@ static int bq20z75_suspend(struct i2c_client *client,
pm_message_t state)
{
s32 ret;
- struct bq20z75_device_info *bq20z75_device;
+ struct bq20z75_device_info *bq20z75_device =
+ i2c_get_clientdata(client);
+
+ if (!bq20z75_device->battery_present)
+ return 0;
- bq20z75_device = i2c_get_clientdata(client);
del_timer_sync(&bq20z75_device->battery_poll_timer);
/* write to manufacture access with sleep command */
@@ -494,6 +503,12 @@ static int bq20z75_suspend(struct i2c_client *client,
/* any smbus transaction will wake up bq20z75 */
static int bq20z75_resume(struct i2c_client *client)
{
+ struct bq20z75_device_info *bq20z75_device =
+ i2c_get_clientdata(client);
+
+ if (!bq20z75_device->battery_present)
+ return 0;
+
setup_timer(&bq20z75_device->battery_poll_timer,
battery_poll_timer_func, 0);
mod_timer(&bq20z75_device->battery_poll_timer,