CHROMIUM: power: Allow bus used for power supply to be found
authorSimon Glass <sjg@chromium.org>
Sat, 2 Feb 2013 05:52:24 +0000 (21:52 -0800)
committerChromeBot <chrome-bot@google.com>
Wed, 20 Feb 2013 07:01:13 +0000 (23:01 -0800)
Some power supplies such as batteries are connected via a bus such as i2c.
When we want to resume the battery we must resume the bus also, otherwise
it will not be possible to communicate with it.

Add a function which returns the device that a power supply is connected
on, to permit a caller to resume the bus also.

BUG=chrome-os-partner:10617
TEST=build and boot to kernel prompt on snow
Use charger-manager, with other changes, and see that in the
suspend_again() handler, the battery temperature can be read successfully.
This indicates that the i2c bus is working properly.
Change-Id: I1f19606861e0cb7f86621c2ad22415d7761cb060
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/43012
Reviewed-by: Benson Leung <bleung@chromium.org>
drivers/power/sbs-battery.c
include/linux/power_supply.h

index 8bb0715..f2684bd 100644 (file)
@@ -798,6 +798,18 @@ static struct sbs_platform_data *sbs_of_populate_pdata(
 }
 #endif
 
+#ifdef CONFIG_PM
+struct device *sbs_to_i2c_dev(struct power_supply *psy)
+{
+       struct sbs_info *chip;
+
+       chip = container_of(psy, struct sbs_info, power_supply);
+       return &chip->client->adapter->dev;
+}
+#else
+#define sbs_to_i2c_dev NULL
+#endif
+
 static int __devinit sbs_probe(struct i2c_client *client,
        const struct i2c_device_id *id)
 {
@@ -833,6 +845,7 @@ static int __devinit sbs_probe(struct i2c_client *client,
        chip->ignore_changes = 1;
        chip->last_state = POWER_SUPPLY_STATUS_UNKNOWN;
        chip->power_supply.external_power_changed = sbs_external_power_changed;
+       chip->power_supply.to_bus_dev = sbs_to_i2c_dev;
 
        pdata = sbs_of_populate_pdata(client);
 
index c38c13d..802eb93 100644 (file)
@@ -165,6 +165,16 @@ struct power_supply {
                                     enum power_supply_property psp);
        void (*external_power_changed)(struct power_supply *psy);
        void (*set_charged)(struct power_supply *psy);
+       /**
+        * @to_bus_dev - Get the device this power supply connects to
+        *
+        * This can be used in a suspend_again() handler to resume
+        * communications (e.g. attached i2c port) and put it back
+        * into suspend afterwards.
+        *
+        * @psy: Power supply
+        */
+       struct device *(*to_bus_dev)(struct power_supply *psy);
 
        /* For APM emulation, think legacy userspace. */
        int use_for_apm;