power: supply: sbs-battery: Add alert callback
authorPhil Reid <preid@electromag.com.au>
Mon, 1 May 2017 08:49:58 +0000 (16:49 +0800)
committerSebastian Reichel <sre@kernel.org>
Mon, 1 May 2017 12:28:19 +0000 (14:28 +0200)
To simplify the sbs-manager code and notification of battery removal
use the i2c alert callback to notify the sbs-battery driver that an
event has occurred.

Signed-off-by: Phil Reid <preid@electromag.com.au>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
drivers/power/supply/sbs-battery.c

index 171c701a2d492988c0a68401a5a2c42e4853f5fc..e3a114e60f1a3cac1c72bf72800cb859cae12254 100644 (file)
@@ -701,21 +701,30 @@ done:
        return 0;
 }
 
-static irqreturn_t sbs_irq(int irq, void *devid)
+static void sbs_supply_changed(struct sbs_info *chip)
 {
-       struct sbs_info *chip = devid;
        struct power_supply *battery = chip->power_supply;
        int ret;
 
        ret = gpiod_get_value_cansleep(chip->gpio_detect);
        if (ret < 0)
-               return ret;
+               return;
        chip->is_present = ret;
        power_supply_changed(battery);
+}
 
+static irqreturn_t sbs_irq(int irq, void *devid)
+{
+       sbs_supply_changed(devid);
        return IRQ_HANDLED;
 }
 
+static void sbs_alert(struct i2c_client *client, enum i2c_alert_protocol prot,
+       unsigned int data)
+{
+       sbs_supply_changed(i2c_get_clientdata(client));
+}
+
 static void sbs_external_power_changed(struct power_supply *psy)
 {
        struct sbs_info *chip = power_supply_get_drvdata(psy);
@@ -936,6 +945,7 @@ MODULE_DEVICE_TABLE(of, sbs_dt_ids);
 static struct i2c_driver sbs_battery_driver = {
        .probe          = sbs_probe,
        .remove         = sbs_remove,
+       .alert          = sbs_alert,
        .id_table       = sbs_id,
        .driver = {
                .name   = "sbs-battery",