mfd: dt: tps65910: Add power off control
[cascardo/linux.git] / drivers / mfd / tps65910.c
index d3ce4d5..ca90294 100644 (file)
@@ -198,6 +198,8 @@ static struct tps65910_board *tps65910_parse_dt(struct i2c_client *client,
 
        board_info->irq = client->irq;
        board_info->irq_base = -1;
+       board_info->pm_off = of_property_read_bool(np,
+                       "ti,system-power-controller");
 
        return board_info;
 }
@@ -210,6 +212,21 @@ struct tps65910_board *tps65910_parse_dt(struct i2c_client *client,
 }
 #endif
 
+static struct i2c_client *tps65910_i2c_client;
+static void tps65910_power_off(void)
+{
+       struct tps65910 *tps65910;
+
+       tps65910 = dev_get_drvdata(&tps65910_i2c_client->dev);
+
+       if (tps65910_reg_set_bits(tps65910, TPS65910_DEVCTRL,
+                       DEVCTRL_PWR_OFF_MASK) < 0)
+               return;
+
+       tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
+                       DEVCTRL_DEV_ON_MASK);
+}
+
 static __devinit int tps65910_i2c_probe(struct i2c_client *i2c,
                                        const struct i2c_device_id *id)
 {
@@ -267,6 +284,11 @@ static __devinit int tps65910_i2c_probe(struct i2c_client *i2c,
        tps65910_ck32k_init(tps65910, pmic_plat_data);
        tps65910_sleepinit(tps65910, pmic_plat_data);
 
+       if (pmic_plat_data->pm_off && !pm_power_off) {
+               tps65910_i2c_client = i2c;
+               pm_power_off = tps65910_power_off;
+       }
+
        return ret;
 }