mfd: rk808: Prepare rk805 for poweroff
authorStefan Mavrodiev <stefan@olimex.com>
Fri, 7 Jun 2019 12:42:26 +0000 (15:42 +0300)
committerLee Jones <lee.jones@linaro.org>
Tue, 2 Jul 2019 11:11:31 +0000 (12:11 +0100)
RK805 has SLEEP signal, which can put the device into SLEEP or OFF
mode. The default is SLEEP mode.

However, when the kernel performs power-off (actually the ATF) the
device will not go fully off and this will result in higher power
consumption and inability to wake the device with RTC alarm.

The solution is to enable pm_power_off_prepare function, which will
configure SLEEP pin for OFF function.

Signed-off-by: Stefan Mavrodiev <stefan@olimex.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
drivers/mfd/rk808.c
include/linux/mfd/rk808.h

index e234720fee02346ac9d032a16fdb0669ec16663c..09fc8d3da54171caf35beffbb9591ac85e04d9bc 100644 (file)
@@ -474,17 +474,29 @@ static void rk805_device_shutdown(void)
        int ret;
        struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
 
-       if (!rk808) {
-               dev_warn(&rk808_i2c_client->dev,
-                        "have no rk805, so do nothing here\n");
+       if (!rk808)
                return;
-       }
 
        ret = regmap_update_bits(rk808->regmap,
                                 RK805_DEV_CTRL_REG,
                                 DEV_OFF, DEV_OFF);
        if (ret)
-               dev_err(&rk808_i2c_client->dev, "power off error!\n");
+               dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
+}
+
+static void rk805_device_shutdown_prepare(void)
+{
+       int ret;
+       struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
+
+       if (!rk808)
+               return;
+
+       ret = regmap_update_bits(rk808->regmap,
+                                RK805_GPIO_IO_POL_REG,
+                                SLP_SD_MSK, SHUTDOWN_FUN);
+       if (ret)
+               dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
 }
 
 static void rk808_device_shutdown(void)
@@ -492,17 +504,14 @@ static void rk808_device_shutdown(void)
        int ret;
        struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
 
-       if (!rk808) {
-               dev_warn(&rk808_i2c_client->dev,
-                        "have no rk808, so do nothing here\n");
+       if (!rk808)
                return;
-       }
 
        ret = regmap_update_bits(rk808->regmap,
                                 RK808_DEVCTRL_REG,
                                 DEV_OFF_RST, DEV_OFF_RST);
        if (ret)
-               dev_err(&rk808_i2c_client->dev, "power off error!\n");
+               dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
 }
 
 static void rk818_device_shutdown(void)
@@ -510,17 +519,14 @@ static void rk818_device_shutdown(void)
        int ret;
        struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
 
-       if (!rk808) {
-               dev_warn(&rk808_i2c_client->dev,
-                        "have no rk818, so do nothing here\n");
+       if (!rk808)
                return;
-       }
 
        ret = regmap_update_bits(rk808->regmap,
                                 RK818_DEVCTRL_REG,
                                 DEV_OFF, DEV_OFF);
        if (ret)
-               dev_err(&rk808_i2c_client->dev, "power off error!\n");
+               dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
 }
 
 static void rk8xx_syscore_shutdown(void)
@@ -609,6 +615,7 @@ static int rk808_probe(struct i2c_client *client,
                cells = rk805s;
                nr_cells = ARRAY_SIZE(rk805s);
                rk808->pm_pwroff_fn = rk805_device_shutdown;
+               rk808->pm_pwroff_prep_fn = rk805_device_shutdown_prepare;
                break;
        case RK808_ID:
                rk808->regmap_cfg = &rk808_regmap_config;
@@ -694,6 +701,12 @@ static int rk808_probe(struct i2c_client *client,
                pm_power_off = rk808->pm_pwroff_fn;
        }
 
+       if (pm_off && !pm_power_off_prepare) {
+               if (!rk808_i2c_client)
+                       rk808_i2c_client = client;
+               pm_power_off_prepare = rk808->pm_pwroff_prep_fn;
+       }
+
        return 0;
 
 err_irq:
@@ -714,6 +727,13 @@ static int rk808_remove(struct i2c_client *client)
        if (rk808->pm_pwroff_fn && pm_power_off == rk808->pm_pwroff_fn)
                pm_power_off = NULL;
 
+       /**
+        * As above, check if the pointer is set by us before overwrite.
+        */
+       if (rk808->pm_pwroff_prep_fn &&
+           pm_power_off_prepare == rk808->pm_pwroff_prep_fn)
+               pm_power_off_prepare = NULL;
+
        return 0;
 }
 
index 2863163756362275cfd02452fae62bbdc48836d1..b264ac794c74d25a8c4479143a6dad1c1a5dcd60 100644 (file)
@@ -629,5 +629,6 @@ struct rk808 {
        const struct regmap_config      *regmap_cfg;
        const struct regmap_irq_chip    *regmap_irq_chip;
        void                            (*pm_pwroff_fn)(void);
+       void                            (*pm_pwroff_prep_fn)(void);
 };
 #endif /* __LINUX_REGULATOR_RK808_H */