gpio: mvebu: Make use of devm_pwmchip_add
[platform/kernel/linux-starfive.git] / drivers / mfd / tps65219.c
index 0e402fd..0e0c42e 100644 (file)
@@ -25,13 +25,21 @@ static int tps65219_cold_reset(struct tps65219 *tps)
                                  TPS65219_MFP_COLD_RESET_I2C_CTRL_MASK);
 }
 
-static int tps65219_restart(struct notifier_block *this,
-                           unsigned long reboot_mode, void *cmd)
+static int tps65219_soft_shutdown(struct tps65219 *tps)
 {
-       struct tps65219 *tps;
+       return regmap_update_bits(tps->regmap, TPS65219_REG_MFP_CTRL,
+                                 TPS65219_MFP_I2C_OFF_REQ_MASK,
+                                 TPS65219_MFP_I2C_OFF_REQ_MASK);
+}
 
-       tps = container_of(this, struct tps65219, nb);
+static int tps65219_power_off_handler(struct sys_off_data *data)
+{
+       tps65219_soft_shutdown(data->cb_data);
+       return NOTIFY_DONE;
+}
 
+static int tps65219_restart(struct tps65219 *tps, unsigned long reboot_mode)
+{
        if (reboot_mode == REBOOT_WARM)
                tps65219_warm_reset(tps);
        else
@@ -40,10 +48,11 @@ static int tps65219_restart(struct notifier_block *this,
        return NOTIFY_DONE;
 }
 
-static struct notifier_block pmic_rst_restart_nb = {
-       .notifier_call = tps65219_restart,
-       .priority = 200,
-};
+static int tps65219_restart_handler(struct sys_off_data *data)
+{
+       tps65219_restart(data->cb_data, data->mode);
+       return NOTIFY_DONE;
+}
 
 static const struct resource tps65219_pwrbutton_resources[] = {
        DEFINE_RES_IRQ_NAMED(TPS65219_INT_PB_FALLING_EDGE_DETECT, "falling"),
@@ -106,7 +115,7 @@ static const struct mfd_cell tps65219_cells[] = {
                .resources = tps65219_regulator_resources,
                .num_resources = ARRAY_SIZE(tps65219_regulator_resources),
        },
-       { .name = "tps65219-gpios", },
+       { .name = "tps65219-gpio", },
 };
 
 static const struct mfd_cell tps65219_pwrbutton_cell = {
@@ -269,13 +278,22 @@ static int tps65219_probe(struct i2c_client *client)
                }
        }
 
-       tps->nb = pmic_rst_restart_nb;
-       ret = register_restart_handler(&tps->nb);
+       ret = devm_register_restart_handler(tps->dev,
+                                           tps65219_restart_handler,
+                                           tps);
+
        if (ret) {
                dev_err(tps->dev, "cannot register restart handler, %d\n", ret);
                return ret;
        }
 
+       ret = devm_register_power_off_handler(tps->dev,
+                                             tps65219_power_off_handler,
+                                             tps);
+       if (ret) {
+               dev_err(tps->dev, "failed to register power-off handler: %d\n", ret);
+               return ret;
+       }
        return 0;
 }
 
@@ -290,7 +308,7 @@ static struct i2c_driver tps65219_driver = {
                .name   = "tps65219",
                .of_match_table = of_tps65219_match_table,
        },
-       .probe_new      = tps65219_probe,
+       .probe          = tps65219_probe,
 };
 module_i2c_driver(tps65219_driver);