CHROMIUM: sbs-battery: probe should try talking to the device
authorOlof Johansson <olofj@chromium.org>
Thu, 6 Sep 2012 17:40:17 +0000 (10:40 -0700)
committerGerrit <chrome-bot@google.com>
Fri, 7 Sep 2012 00:32:43 +0000 (17:32 -0700)
Turns out this driver doesn't actually try talking to the device at probe
time, so if it's incorrectly configured in the device tree or platform
data (or if it's been removed from the system), then probe will succeed
and every later access will sit there and time out. The end result is
a system that thinks it has a battery but can never read status, which
isn't very useful.

Instead, just read any register (I chose status) at boot, and if that
fails, don't register the device.

BUG=chrome-os-partner:11381
TEST=modify device tree to have battery at other address, try booting
and make sure the 2 minute timeout is gone (and dmesg has the error
string in it).

Change-Id: I728910968a40a55de3b3c9a10921a3684ace215f
Signed-off-by: Olof Johansson <olofj@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/32406
Reviewed-by: Doug Anderson <dianders@chromium.org>
drivers/power/sbs-battery.c

index b5e65a4..99abd28 100644 (file)
@@ -874,6 +874,16 @@ static int __devinit sbs_probe(struct i2c_client *client,
 
 skip_gpio:
 
+       /* Before we register, we need to make sure we can actually talk
+        * to the battery.
+        */
+       rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
+       if (rc < 0) {
+               dev_err(&client->dev, "%s: Failed to get device status\n",
+                       __func__);
+               goto exit_psupply;
+       }
+
        rc = power_supply_register(&client->dev, &chip->power_supply);
        if (rc) {
                dev_err(&client->dev,