[PATCH v2 29/45] mfd: acer-a500: Use devm_register_power_handler()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: Thierry Reding <thierry.reding@xxxxxxxxx>, Jonathan Hunter <jonathanh@xxxxxxxxxx>, Lee Jones <lee.jones@xxxxxxxxxx>, "Rafael J . Wysocki" <rafael@xxxxxxxxxx>, Mark Brown <broonie@xxxxxxxxxx>, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>, Guenter Roeck <linux@xxxxxxxxxxxx>, Russell King <linux@xxxxxxxxxxxxxxx>, Daniel Lezcano <daniel.lezcano@xxxxxxxxxx>, Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>, Ulf Hansson <ulf.hansson@xxxxxxxxxx>
- Subject: [PATCH v2 29/45] mfd: acer-a500: Use devm_register_power_handler()
- From: Dmitry Osipenko <digetx@xxxxxxxxx>
- Date: Thu, 28 Oct 2021 00:16:59 +0300
- Cc: Catalin Marinas <catalin.marinas@xxxxxxx>, Will Deacon <will@xxxxxxxxxx>, Guo Ren <guoren@xxxxxxxxxx>, Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>, Greg Ungerer <gerg@xxxxxxxxxxxxxx>, Joshua Thompson <funaho@xxxxxxxxx>, Thomas Bogendoerfer <tsbogend@xxxxxxxxxxxxxxxx>, Nick Hu <nickhu@xxxxxxxxxxxxx>, Greentime Hu <green.hu@xxxxxxxxx>, Vincent Chen <deanbo422@xxxxxxxxx>, "James E.J. Bottomley" <James.Bottomley@xxxxxxxxxxxxxxxxxxxxx>, Helge Deller <deller@xxxxxx>, Michael Ellerman <mpe@xxxxxxxxxxxxxx>, Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx>, Paul Mackerras <paulus@xxxxxxxxx>, Paul Walmsley <paul.walmsley@xxxxxxxxxx>, Palmer Dabbelt <palmer@xxxxxxxxxxx>, Albert Ou <aou@xxxxxxxxxxxxxxxxx>, Yoshinori Sato <ysato@xxxxxxxxxxxxx>, Rich Felker <dalias@xxxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Borislav Petkov <bp@xxxxxxxxx>, Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>, x86@xxxxxxxxxx, "H. Peter Anvin" <hpa@xxxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Len Brown <lenb@xxxxxxxxxx>, Santosh Shilimkar <ssantosh@xxxxxxxxxx>, Krzysztof Kozlowski <krzysztof.kozlowski@xxxxxxxxxxxxx>, Linus Walleij <linus.walleij@xxxxxxxxxx>, Chen-Yu Tsai <wens@xxxxxxxx>, Jonathan Neuschäfer <j.neuschaefer@xxxxxxx>, Tony Lindgren <tony@xxxxxxxxxxx>, Liam Girdwood <lgirdwood@xxxxxxxxx>, Philipp Zabel <p.zabel@xxxxxxxxxxxxxx>, Vladimir Zapolskiy <vz@xxxxxxxxx>, Avi Fishman <avifishman70@xxxxxxxxx>, Tomer Maimon <tmaimon77@xxxxxxxxx>, Tali Perry <tali.perry1@xxxxxxxxx>, Patrick Venture <venture@xxxxxxxxxx>, Nancy Yuen <yuenn@xxxxxxxxxx>, Benjamin Fair <benjaminfair@xxxxxxxxxx>, Pavel Machek <pavel@xxxxxx>, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, linux-csky@xxxxxxxxxxxxxxx, linux-ia64@xxxxxxxxxxxxxxx, linux-m68k@xxxxxxxxxxxxxxx, linux-mips@xxxxxxxxxxxxxxx, linux-parisc@xxxxxxxxxxxxxxx, linuxppc-dev@xxxxxxxxxxxxxxxx, linux-riscv@xxxxxxxxxxxxxxxxxxx, linux-sh@xxxxxxxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx, linux-acpi@xxxxxxxxxxxxxxx, linux-omap@xxxxxxxxxxxxxxx, openbmc@xxxxxxxxxxxxxxxx, linux-tegra@xxxxxxxxxxxxxxx, linux-pm@xxxxxxxxxxxxxxx
- In-reply-to: <20211027211715.12671-1-digetx@gmail.com>
- References: <20211027211715.12671-1-digetx@gmail.com>
Use devm_register_power_handler() that replaces global pm_power_off
variable and allows to register multiple power-off handlers. It also
provides restart-handler support, i.e. all in one API.
Signed-off-by: Dmitry Osipenko <digetx@xxxxxxxxx>
---
drivers/mfd/acer-ec-a500.c | 52 ++++++++++++++------------------------
1 file changed, 19 insertions(+), 33 deletions(-)
diff --git a/drivers/mfd/acer-ec-a500.c b/drivers/mfd/acer-ec-a500.c
index 80c2fdd14fc4..fc864abc0049 100644
--- a/drivers/mfd/acer-ec-a500.c
+++ b/drivers/mfd/acer-ec-a500.c
@@ -31,8 +31,6 @@ enum {
REG_COLD_REBOOT = 0x55,
};
-static struct i2c_client *a500_ec_client_pm_off;
-
static int a500_ec_read(void *context, const void *reg_buf, size_t reg_size,
void *val_buf, size_t val_sizel)
{
@@ -104,32 +102,35 @@ static const struct regmap_bus a500_ec_regmap_bus = {
.max_raw_read = 2,
};
-static void a500_ec_poweroff(void)
+static void a500_ec_power_off_handler(struct power_off_data *data)
{
- i2c_smbus_write_word_data(a500_ec_client_pm_off,
- REG_SHUTDOWN, CMD_SHUTDOWN);
+ struct i2c_client *client = data->cb_data;
+
+ i2c_smbus_write_word_data(client, REG_SHUTDOWN, CMD_SHUTDOWN);
mdelay(A500_EC_POWER_CMD_TIMEOUT);
}
-static int a500_ec_restart_notify(struct notifier_block *this,
- unsigned long reboot_mode, void *data)
+static void a500_ec_restart_handler(struct restart_data *data)
{
- if (reboot_mode == REBOOT_WARM)
- i2c_smbus_write_word_data(a500_ec_client_pm_off,
+ struct i2c_client *client = data->cb_data;
+
+ if (data->mode == REBOOT_WARM)
+ i2c_smbus_write_word_data(client,
REG_WARM_REBOOT, CMD_WARM_REBOOT);
else
- i2c_smbus_write_word_data(a500_ec_client_pm_off,
+ i2c_smbus_write_word_data(client,
REG_COLD_REBOOT, CMD_COLD_REBOOT);
mdelay(A500_EC_POWER_CMD_TIMEOUT);
-
- return NOTIFY_DONE;
}
-static struct notifier_block a500_ec_restart_handler = {
- .notifier_call = a500_ec_restart_notify,
- .priority = 200,
+static struct power_handler a500_ec_power_handler = {
+ .restart_cb = a500_ec_restart_handler,
+ .restart_priority = RESTART_PRIO_HIGH,
+
+ .power_off_cb = a500_ec_power_off_handler,
+ .power_off_priority = POWEROFF_PRIO_HIGH,
};
static const struct mfd_cell a500_ec_cells[] = {
@@ -156,26 +157,12 @@ static int a500_ec_probe(struct i2c_client *client)
}
if (of_device_is_system_power_controller(client->dev.of_node)) {
- a500_ec_client_pm_off = client;
+ a500_ec_power_handler.cb_data = client;
- err = register_restart_handler(&a500_ec_restart_handler);
+ err = devm_register_power_handler(&client->dev,
+ &a500_ec_power_handler);
if (err)
return err;
-
- if (!pm_power_off)
- pm_power_off = a500_ec_poweroff;
- }
-
- return 0;
-}
-
-static int a500_ec_remove(struct i2c_client *client)
-{
- if (of_device_is_system_power_controller(client->dev.of_node)) {
- if (pm_power_off == a500_ec_poweroff)
- pm_power_off = NULL;
-
- unregister_restart_handler(&a500_ec_restart_handler);
}
return 0;
@@ -193,7 +180,6 @@ static struct i2c_driver a500_ec_driver = {
.of_match_table = a500_ec_match,
},
.probe_new = a500_ec_probe,
- .remove = a500_ec_remove,
};
module_i2c_driver(a500_ec_driver);
--
2.33.1
[Index of Archives]
[Linux Kernel]
[Sparc Linux]
[DCCP]
[Linux ARM]
[Yosemite News]
[Linux SCSI]
[Linux x86_64]
[Linux for Ham Radio]