2014-11-06 16:43:43

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 00/48] kernel: Add support for power-off handler call chain

Various drivers implement architecture and/or device specific means to
remove power from the system. For the most part, those drivers set the
global variable pm_power_off to point to a function within the driver.

This mechanism has a number of drawbacks. Typically only one means
to remove power is supported (at least if pm_power_off is used).
At least in theory there can be multiple means to remove power, some of
which may be less desirable. For example, one mechanism might power off the
entire system through an I/O port or gpio pin, while another might power off
a board by disabling its power controller. Other mechanisms may really just
execute a restart sequence or drop into the ROM monitor, or put the CPU into
sleep mode. Using pm_power_off can also be racy if the function pointer is
set from a driver built as module, as the driver may be in the process of
being unloaded when pm_power_off is called. If there are multiple power-off
handlers in the system, removing a module with such a handler may
inadvertently reset the pointer to pm_power_off to NULL, leaving the system
with no means to remove power.

Introduce a system power-off handler call chain to solve the described
problems. This call chain is expected to be executed from the architecture
specific machine_power_off() function. Drivers providing system power-off
functionality are expected to register with this call chain. By using the
priority field in the notifier block, callers can control power-off handler
execution sequence and thus ensure that the power-off handler with the
optimal capabilities to remove power for a given system is called first.
A call chain instead of a single call to the highest priority handler is
used to provide fallback: If multiple power-off handlers are installed,
all handlers will be called until one actually succeeds to power off the
system.

Patch 01/48 implements the power-off handler API.

Patches 02/48 to 04/48 are cleanup patches to prepare for the move of
pm_power_off to a common location.

Patches 05/48 to 07/48 remove references to pm_power_off from devicetree
bindings descriptions.

Patch 08/48 moves the pm_power_off variable from architecture code to
kernel/reboot.c.

Patches 09/48 to 34/48 convert various drivers to register with the kernel
power-off handler instead of setting pm_power_off directly.

Patches 35/48 to 47/48 do the same for architecture code.

Patch 48/48 finally removes pm_power_off.

For the most part, the individual patches include explanations why specific
priorities were chosen, at least if the selected priority is not the default
priority. Subsystem and architecture maintainers are encouraged to have a look
at the selected priorities and suggest improvements.

I ran the final code through my normal build and qemu tests. Results are
available at http://server.roeck-us.net:8010/builders in the 'poweroff-handler'
column. I also built all available configurations for arm, mips, powerpc,
m68k, and sh architectures.

The series is available in branch poweroff-handler of my repository at
git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git.
It is based on 3.18-rc3 plus the power-off tracking branch from
git://git.kernel.org/pub/scm/linux/kernel/git/mpe/linux.git (to merge
powerpc related power-off changes).

A note on Cc: In the initial submission I had way too many Cc:, causing the
patchset to be treated as spam by many mailers and mailing list handlers,
which of course defeated the purpose. Starting with v3, the distribution
list has been cut down significantly. Copied mailing lists and individuals are
for the most part generated from the output of get_maintainer.pl for each
individual patch. My apologies to anyone I may have failed to copy; if you
believe that some additional individuals or mailing lists should be copied
on the entire series or on individual patches, please let me know.

Merge plan is to send the entire series directly to Linus during the next commit
window, except for the last patch. The last patch would then be part of another
pull request after -rc1, which would include any changes necessary due to newly
merged power-off handling code.

v5:
- Rebased series to v3.18-rc3
- Merge remote-tracking branch 'power/topic/pm-power-off'
from git://git.kernel.org/pub/scm/linux/kernel/git/mpe/linux.git
and implement powerpc conversion (patch 41/48).
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void.
Code to manage and walk the list of callbacks was derived from notifier.c.
Note that only patch 01/47 was sent for review of this version.
v3:
- Rebased series to v3.18-rc2.
- Do not hold any locks while executing the power-off call chain.
This ensures that power-off handlers are executed in the state
selected by the machine_power_off function for a given architecture,
ie without changing the current semantics of power-off callbacks and
machine_power_off functions.
Power-off handler registration and de-registration is handled in atomic
context with interrupts disabled to ensure that those functions are not
interrupted by code which powers off the system.
- Use [xxx_]power_off[_xxx] instead of [xxx_]poweroff[_xxx] for newly
introduced function and variable names.
- Use power-off instead of poweroff in descriptive text and comments.
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
- Use ACPI: instead of acpi: for messages in acpi code.
v2:
- Rebased series to v3.18-rc1.
- Use raw notifier with spinlock protection instead of atomic notifiers,
since some power-off handlers need to have interrupts enabled.
- Renamed API functions from _poweroff to _power_off.
- Added various Acks.
- Build tested all configurations for arm, powerpc, and mips architectures.
- Fixed two compile errors in mips patch.
- Replaced dev_err and pr_err with dev_warn and pr_warn if an error is not
fatal.
- Provide managed resources API and use where appropriate.
- Provide and use definitions for standard priorities.
- Added patches to convert newly introduced power-off handlers.
- Various minor changes.
v1 (from RFC):
- Move API to new file kernel/power/power_off_handler.c.
- Move pm_power_off pointer to kernel/power/power_off_handler.c. Call
pm_power_off from do_kernel_power_off, and only call do_kernel_power_off
from architecture code instead of calling both pm_power_off and
do_kernel_power_off.
- Provide additional API function register_power_off_handler_simple
to simplify conversion of architecture code.
- Provide additional API function have_kernel_power_off to check if
a power-off handler was installed.
- Convert all drivers and architecture code to use the new API.
- Remove pm_power_off as last patch of the series.

Cc: Alan Cox <[email protected]>
Cc: Alexander Graf <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
cc: Heiko Stuebner <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: Len Brown <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Pavel Machek <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
Cc: Romain Perier <[email protected]>


2014-11-06 16:43:51

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 04/48] m68k: Replace mach_power_off with pm_power_off

Replace mach_power_off with pm_power_off to simplify the subsequent
move of pm_power_off to generic code.

Cc: Geert Uytterhoeven <[email protected]>
Cc: Greg Ungerer <[email protected]>
Cc: Joshua Thompson <[email protected]>
Acked-by: Geert Uytterhoeven <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- No change
v2:
- have_kernel_poweroff -> have_kernel_power_off

arch/m68k/emu/natfeat.c | 3 ++-
arch/m68k/include/asm/machdep.h | 1 -
arch/m68k/kernel/process.c | 5 +++--
arch/m68k/kernel/setup_mm.c | 1 -
arch/m68k/kernel/setup_no.c | 1 -
arch/m68k/mac/config.c | 3 ++-
6 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/m68k/emu/natfeat.c b/arch/m68k/emu/natfeat.c
index 71b78ec..91e2ae7 100644
--- a/arch/m68k/emu/natfeat.c
+++ b/arch/m68k/emu/natfeat.c
@@ -15,6 +15,7 @@
#include <linux/string.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/pm.h>
#include <linux/io.h>
#include <asm/machdep.h>
#include <asm/natfeat.h>
@@ -90,5 +91,5 @@ void __init nf_init(void)
pr_info("NatFeats found (%s, %lu.%lu)\n", buf, version >> 16,
version & 0xffff);

- mach_power_off = nf_poweroff;
+ pm_power_off = nf_poweroff;
}
diff --git a/arch/m68k/include/asm/machdep.h b/arch/m68k/include/asm/machdep.h
index 953ca21..f9fac51 100644
--- a/arch/m68k/include/asm/machdep.h
+++ b/arch/m68k/include/asm/machdep.h
@@ -24,7 +24,6 @@ extern int (*mach_set_rtc_pll)(struct rtc_pll_info *);
extern int (*mach_set_clock_mmss)(unsigned long);
extern void (*mach_reset)( void );
extern void (*mach_halt)( void );
-extern void (*mach_power_off)( void );
extern unsigned long (*mach_hd_init) (unsigned long, unsigned long);
extern void (*mach_hd_setup)(char *, int *);
extern long mach_max_dma_address;
diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
index c55ff71..afe3d6e 100644
--- a/arch/m68k/kernel/process.c
+++ b/arch/m68k/kernel/process.c
@@ -22,6 +22,7 @@
#include <linux/unistd.h>
#include <linux/ptrace.h>
#include <linux/user.h>
+#include <linux/pm.h>
#include <linux/reboot.h>
#include <linux/init_task.h>
#include <linux/mqueue.h>
@@ -77,8 +78,8 @@ void machine_halt(void)

void machine_power_off(void)
{
- if (mach_power_off)
- mach_power_off();
+ if (pm_power_off)
+ pm_power_off();
for (;;);
}

diff --git a/arch/m68k/kernel/setup_mm.c b/arch/m68k/kernel/setup_mm.c
index 5b8ec4d..002fea6 100644
--- a/arch/m68k/kernel/setup_mm.c
+++ b/arch/m68k/kernel/setup_mm.c
@@ -96,7 +96,6 @@ EXPORT_SYMBOL(mach_get_rtc_pll);
EXPORT_SYMBOL(mach_set_rtc_pll);
void (*mach_reset)( void );
void (*mach_halt)( void );
-void (*mach_power_off)( void );
long mach_max_dma_address = 0x00ffffff; /* default set to the lower 16MB */
#ifdef CONFIG_HEARTBEAT
void (*mach_heartbeat) (int);
diff --git a/arch/m68k/kernel/setup_no.c b/arch/m68k/kernel/setup_no.c
index 88c27d9..1520156 100644
--- a/arch/m68k/kernel/setup_no.c
+++ b/arch/m68k/kernel/setup_no.c
@@ -55,7 +55,6 @@ int (*mach_hwclk) (int, struct rtc_time*);
/* machine dependent reboot functions */
void (*mach_reset)(void);
void (*mach_halt)(void);
-void (*mach_power_off)(void);

#ifdef CONFIG_M68000
#if defined(CONFIG_M68328)
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index a471eab..677913ff 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -16,6 +16,7 @@
#include <linux/tty.h>
#include <linux/console.h>
#include <linux/interrupt.h>
+#include <linux/pm.h>
/* keyb */
#include <linux/random.h>
#include <linux/delay.h>
@@ -159,7 +160,7 @@ void __init config_mac(void)
mach_set_clock_mmss = mac_set_clock_mmss;
mach_reset = mac_reset;
mach_halt = mac_poweroff;
- mach_power_off = mac_poweroff;
+ pm_power_off = mac_poweroff;
mach_max_dma_address = 0xffffffff;
#if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
mach_beep = mac_mksound;
--
1.9.1

2014-11-06 16:44:05

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 05/48] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

Devicetree bindings are supposed to be operating system independent
and should thus not describe how a specific functionality is implemented
in Linux.

Cc: Rob Herring <[email protected]>
Cc: Pawel Moll <[email protected]>
Cc: Mark Rutland <[email protected]>
Acked-by: Mark Rutland <[email protected]>
Acked-by: Lee Jones <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- No change
v2:
- No change

Documentation/devicetree/bindings/mfd/as3722.txt | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/mfd/as3722.txt b/Documentation/devicetree/bindings/mfd/as3722.txt
index 4f64b2a..0b2a609 100644
--- a/Documentation/devicetree/bindings/mfd/as3722.txt
+++ b/Documentation/devicetree/bindings/mfd/as3722.txt
@@ -122,8 +122,7 @@ Following are properties of regulator subnode.

Power-off:
=========
-AS3722 supports the system power off by turning off all its rail. This
-is provided through pm_power_off.
+AS3722 supports the system power off by turning off all its rails.
The device node should have the following properties to enable this
functionality
ams,system-power-controller: Boolean, to enable the power off functionality
--
1.9.1

2014-11-06 16:44:12

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 07/48] qnap-poweroff: Drop reference to pm_power_off from devicetree bindings

Replace reference to pm_power_off (which is an implementation detail)
and replace it with a more generic description of the driver's functionality.

Cc: Rob Herring <[email protected]>
Cc: Pawel Moll <[email protected]>
Cc: Mark Rutland <[email protected]>
Acked-by: Mark Rutland <[email protected]>
Acked-by: Andrew Lunn <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- No change
v2:
- Drop implementation details

Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt b/Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt
index af25e77..c363d71 100644
--- a/Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt
+++ b/Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt
@@ -3,8 +3,7 @@
QNAP NAS devices have a microcontroller controlling the main power
supply. This microcontroller is connected to UART1 of the Kirkwood and
Orion5x SoCs. Sending the character 'A', at 19200 baud, tells the
-microcontroller to turn the power off. This driver adds a handler to
-pm_power_off which is called to turn the power off.
+microcontroller to turn the power off.

Synology NAS devices use a similar scheme, but a different baud rate,
9600, and a different character, '1'.
--
1.9.1

2014-11-06 16:44:18

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 10/48] mfd: axp20x: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with a low priority value of 64 to reflect that
the original code only sets pm_power_off if it was not already set.

Cc: Lee Jones <[email protected]>
Cc: Samuel Ortiz <[email protected]>
Acked-by: Lee Jones <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify powroff handler priority
- Use devm_register_power_off_handler
- Use dev_warn instead of dev_err

drivers/mfd/axp20x.c | 24 +++++++++++-------------
include/linux/mfd/axp20x.h | 1 +
2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c
index 6231adb..e2430e6 100644
--- a/drivers/mfd/axp20x.c
+++ b/drivers/mfd/axp20x.c
@@ -150,11 +150,13 @@ static struct mfd_cell axp20x_cells[] = {
},
};

-static struct axp20x_dev *axp20x_pm_power_off;
-static void axp20x_power_off(void)
+static void axp20x_power_off(struct power_off_handler_block *this)
+
{
- regmap_write(axp20x_pm_power_off->regmap, AXP20X_OFF_CTRL,
- AXP20X_OFF);
+ struct axp20x_dev *axp20x = container_of(this, struct axp20x_dev,
+ power_off_hb);
+
+ regmap_write(axp20x->regmap, AXP20X_OFF_CTRL, AXP20X_OFF);
}

static int axp20x_i2c_probe(struct i2c_client *i2c,
@@ -204,10 +206,11 @@ static int axp20x_i2c_probe(struct i2c_client *i2c,
return ret;
}

- if (!pm_power_off) {
- axp20x_pm_power_off = axp20x;
- pm_power_off = axp20x_power_off;
- }
+ axp20x->power_off_hb.handler = axp20x_power_off;
+ axp20x->power_off_hb.priority = POWER_OFF_PRIORITY_LOW;
+ ret = devm_register_power_off_handler(&i2c->dev, &axp20x->power_off_hb);
+ if (ret)
+ dev_warn(&i2c->dev, "failed to register power-off handler\n");

dev_info(&i2c->dev, "AXP20X driver loaded\n");

@@ -218,11 +221,6 @@ static int axp20x_i2c_remove(struct i2c_client *i2c)
{
struct axp20x_dev *axp20x = i2c_get_clientdata(i2c);

- if (axp20x == axp20x_pm_power_off) {
- axp20x_pm_power_off = NULL;
- pm_power_off = NULL;
- }
-
mfd_remove_devices(axp20x->dev);
regmap_del_irq_chip(axp20x->i2c_client->irq, axp20x->regmap_irqc);

diff --git a/include/linux/mfd/axp20x.h b/include/linux/mfd/axp20x.h
index d0e31a2..8f330af 100644
--- a/include/linux/mfd/axp20x.h
+++ b/include/linux/mfd/axp20x.h
@@ -175,6 +175,7 @@ struct axp20x_dev {
struct regmap *regmap;
struct regmap_irq_chip_data *regmap_irqc;
long variant;
+ struct power_off_handler_block power_off_hb;
};

#endif /* __LINUX_MFD_AXP20X_H */
--
1.9.1

2014-11-06 16:44:26

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 14/48] mfd: tps80031: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the original code
only sets pm_power_off if it was not already set.

Cc: Samuel Ortiz <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Acked-by: Lee Jones <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Use dev_warn instead of dev_err

drivers/mfd/tps80031.c | 27 +++++++++++++++------------
include/linux/mfd/tps80031.h | 2 ++
2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/mfd/tps80031.c b/drivers/mfd/tps80031.c
index ed6c5b0..996fd7c 100644
--- a/drivers/mfd/tps80031.c
+++ b/drivers/mfd/tps80031.c
@@ -147,7 +147,6 @@ static const struct tps80031_pupd_data tps80031_pupds[] = {
[TPS80031_CTLI2C_SCL] = PUPD_DATA(4, 0, BIT(2)),
[TPS80031_CTLI2C_SDA] = PUPD_DATA(4, 0, BIT(3)),
};
-static struct tps80031 *tps80031_power_off_dev;

int tps80031_ext_power_req_config(struct device *dev,
unsigned long ext_ctrl_flag, int preq_bit,
@@ -209,11 +208,14 @@ int tps80031_ext_power_req_config(struct device *dev,
}
EXPORT_SYMBOL_GPL(tps80031_ext_power_req_config);

-static void tps80031_power_off(void)
+static void tps80031_power_off(struct power_off_handler_block *this)
{
- dev_info(tps80031_power_off_dev->dev, "switching off PMU\n");
- tps80031_write(tps80031_power_off_dev->dev, TPS80031_SLAVE_ID1,
- TPS80031_PHOENIX_DEV_ON, TPS80031_DEVOFF);
+ struct tps80031 *tps80031 = container_of(this, struct tps80031,
+ power_off_hb);
+
+ dev_info(tps80031->dev, "switching off PMU\n");
+ tps80031_write(tps80031->dev, TPS80031_SLAVE_ID1,
+ TPS80031_PHOENIX_DEV_ON, TPS80031_DEVOFF);
}

static void tps80031_pupd_init(struct tps80031 *tps80031,
@@ -501,9 +503,13 @@ static int tps80031_probe(struct i2c_client *client,
goto fail_mfd_add;
}

- if (pdata->use_power_off && !pm_power_off) {
- tps80031_power_off_dev = tps80031;
- pm_power_off = tps80031_power_off;
+ if (pdata->use_power_off) {
+ tps80031->power_off_hb.handler = tps80031_power_off;
+ tps80031->power_off_hb.priority = POWER_OFF_PRIORITY_LOW;
+ ret = register_power_off_handler(&tps80031->power_off_hb);
+ if (ret)
+ dev_warn(&client->dev,
+ "Failed to register power-off handler\n");
}
return 0;

@@ -523,10 +529,7 @@ static int tps80031_remove(struct i2c_client *client)
struct tps80031 *tps80031 = i2c_get_clientdata(client);
int i;

- if (tps80031_power_off_dev == tps80031) {
- tps80031_power_off_dev = NULL;
- pm_power_off = NULL;
- }
+ unregister_power_off_handler(&tps80031->power_off_hb);

mfd_remove_devices(tps80031->dev);

diff --git a/include/linux/mfd/tps80031.h b/include/linux/mfd/tps80031.h
index 2c75c9c..5716077 100644
--- a/include/linux/mfd/tps80031.h
+++ b/include/linux/mfd/tps80031.h
@@ -24,6 +24,7 @@
#define __LINUX_MFD_TPS80031_H

#include <linux/device.h>
+#include <linux/pm.h>
#include <linux/regmap.h>

/* Pull-ups/Pull-downs */
@@ -513,6 +514,7 @@ struct tps80031 {
struct i2c_client *clients[TPS80031_NUM_SLAVES];
struct regmap *regmap[TPS80031_NUM_SLAVES];
struct regmap_irq_chip_data *irq_data;
+ struct power_off_handler_block power_off_hb;
};

struct tps80031_pupd_init_data {
--
1.9.1

2014-11-06 16:44:35

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 18/48] mfd: twl4030-power: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the original code
only sets pm_power_off if it was not already set.

Make twl4030_power_off static as it is only called from the twl4030-power
driver. Drop remove function as it is no longer needed.

Cc: Samuel Ortiz <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Acked-by: Lee Jones <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Use dev_warn instead of dev_err
- Use devm_register_power_off_handler
- Drop remove function as it is no longer needed.

drivers/mfd/twl4030-power.c | 25 +++++++++++++++----------
include/linux/i2c/twl.h | 1 -
2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c
index cf92a6d..88fd33c 100644
--- a/drivers/mfd/twl4030-power.c
+++ b/drivers/mfd/twl4030-power.c
@@ -25,9 +25,9 @@
*/

#include <linux/module.h>
-#include <linux/pm.h>
#include <linux/i2c/twl.h>
#include <linux/platform_device.h>
+#include <linux/pm.h>
#include <linux/of.h>
#include <linux/of_device.h>

@@ -611,7 +611,7 @@ twl4030_power_configure_resources(const struct twl4030_power_data *pdata)
* After a successful execution, TWL shuts down the power to the SoC
* and all peripherals connected to it.
*/
-void twl4030_power_off(void)
+static void twl4030_power_off(struct power_off_handler_block *this)
{
int err;

@@ -621,6 +621,11 @@ void twl4030_power_off(void)
pr_err("TWL4030 Unable to power off\n");
}

+static struct power_off_handler_block twl4030_power_off_hb = {
+ .handler = twl4030_power_off,
+ .priority = POWER_OFF_PRIORITY_LOW,
+};
+
static bool twl4030_power_use_poweroff(const struct twl4030_power_data *pdata,
struct device_node *node)
{
@@ -839,7 +844,9 @@ static int twl4030_power_probe(struct platform_device *pdev)
}

/* Board has to be wired properly to use this feature */
- if (twl4030_power_use_poweroff(pdata, node) && !pm_power_off) {
+ if (twl4030_power_use_poweroff(pdata, node)) {
+ int ret;
+
/* Default for SEQ_OFFSYNC is set, lets ensure this */
err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val,
TWL4030_PM_MASTER_CFG_P123_TRANSITION);
@@ -856,7 +863,11 @@ static int twl4030_power_probe(struct platform_device *pdev)
}
}

- pm_power_off = twl4030_power_off;
+ ret = devm_register_power_off_handler(&pdev->dev,
+ &twl4030_power_off_hb);
+ if (ret)
+ dev_warn(&pdev->dev,
+ "Failed to register power-off handler\n");
}

relock:
@@ -870,11 +881,6 @@ relock:
return err;
}

-static int twl4030_power_remove(struct platform_device *pdev)
-{
- return 0;
-}
-
static struct platform_driver twl4030_power_driver = {
.driver = {
.name = "twl4030_power",
@@ -882,7 +888,6 @@ static struct platform_driver twl4030_power_driver = {
.of_match_table = of_match_ptr(twl4030_power_of_match),
},
.probe = twl4030_power_probe,
- .remove = twl4030_power_remove,
};

module_platform_driver(twl4030_power_driver);
diff --git a/include/linux/i2c/twl.h b/include/linux/i2c/twl.h
index 8cfb50f..f8544f1 100644
--- a/include/linux/i2c/twl.h
+++ b/include/linux/i2c/twl.h
@@ -680,7 +680,6 @@ struct twl4030_power_data {
};

extern int twl4030_remove_script(u8 flags);
-extern void twl4030_power_off(void);

struct twl4030_codec_data {
unsigned int digimic_delay; /* in ms */
--
1.9.1

2014-11-06 16:44:32

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 16/48] mfd: tps6586x: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the original code
only sets pm_power_off if it was not already set.

Cc: Samuel Ortiz <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Acked-by: Lee Jones <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Use dev_warn instead of dev_err

drivers/mfd/tps6586x.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/mfd/tps6586x.c b/drivers/mfd/tps6586x.c
index 8e1dbc4..f11165f 100644
--- a/drivers/mfd/tps6586x.c
+++ b/drivers/mfd/tps6586x.c
@@ -25,6 +25,7 @@
#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/platform_device.h>
+#include <linux/pm.h>
#include <linux/regmap.h>
#include <linux/of.h>

@@ -133,6 +134,8 @@ struct tps6586x {
u32 irq_en;
u8 mask_reg[5];
struct irq_domain *irq_domain;
+
+ struct power_off_handler_block power_off_hb;
};

static inline struct tps6586x *dev_to_tps6586x(struct device *dev)
@@ -472,13 +475,15 @@ static const struct regmap_config tps6586x_regmap_config = {
.cache_type = REGCACHE_RBTREE,
};

-static struct device *tps6586x_dev;
-static void tps6586x_power_off(void)
+static void tps6586x_power_off(struct power_off_handler_block *this)
{
- if (tps6586x_clr_bits(tps6586x_dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT))
+ struct tps6586x *tps6586x = container_of(this, struct tps6586x,
+ power_off_hb);
+
+ if (tps6586x_clr_bits(tps6586x->dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT))
return;

- tps6586x_set_bits(tps6586x_dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT);
+ tps6586x_set_bits(tps6586x->dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT);
}

static void tps6586x_print_version(struct i2c_client *client, int version)
@@ -575,9 +580,13 @@ static int tps6586x_i2c_probe(struct i2c_client *client,
goto err_add_devs;
}

- if (pdata->pm_off && !pm_power_off) {
- tps6586x_dev = &client->dev;
- pm_power_off = tps6586x_power_off;
+ if (pdata->pm_off) {
+ tps6586x->power_off_hb.handler = tps6586x_power_off;
+ tps6586x->power_off_hb.priority = POWER_OFF_PRIORITY_LOW;
+ ret = register_power_off_handler(&tps6586x->power_off_hb);
+ if (ret)
+ dev_warn(&client->dev,
+ "failed to register power-off handler\n");
}

return 0;
@@ -594,6 +603,8 @@ static int tps6586x_i2c_remove(struct i2c_client *client)
{
struct tps6586x *tps6586x = i2c_get_clientdata(client);

+ unregister_power_off_handler(&tps6586x->power_off_hb);
+
tps6586x_remove_subdevs(tps6586x);
mfd_remove_devices(tps6586x->dev);
if (client->irq)
--
1.9.1

2014-11-06 16:44:39

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 19/48] mfd: rk808: Register power-off handler with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the original code
only sets pm_power_off if it was not already set.

Cc: Chris Zhong <[email protected]>
Cc: Zhang Qing <[email protected]>
Acked-by: Lee Jones <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- New patch

drivers/mfd/rk808.c | 26 ++++++++++++--------------
include/linux/mfd/rk808.h | 2 ++
2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/mfd/rk808.c b/drivers/mfd/rk808.c
index bd02150..93ffcf0 100644
--- a/drivers/mfd/rk808.c
+++ b/drivers/mfd/rk808.c
@@ -21,6 +21,7 @@
#include <linux/mfd/rk808.h>
#include <linux/mfd/core.h>
#include <linux/module.h>
+#include <linux/pm.h>
#include <linux/regmap.h>

struct rk808_reg_data {
@@ -147,23 +148,16 @@ static struct regmap_irq_chip rk808_irq_chip = {
.init_ack_masked = true,
};

-static struct i2c_client *rk808_i2c_client;
-static void rk808_device_shutdown(void)
+static void rk808_device_shutdown(struct power_off_handler_block *this)
{
+ struct rk808 *rk808 = container_of(this, struct rk808, power_off_hb);
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");
- 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->dev, "power off error!\n");
}

static int rk808_probe(struct i2c_client *client,
@@ -222,9 +216,14 @@ static int rk808_probe(struct i2c_client *client,

pm_off = of_property_read_bool(np,
"rockchip,system-power-controller");
- if (pm_off && !pm_power_off) {
- rk808_i2c_client = client;
- pm_power_off = rk808_device_shutdown;
+ if (pm_off) {
+ rk808->power_off_hb.handler = rk808_device_shutdown;
+ rk808->power_off_hb.priority = POWER_OFF_PRIORITY_LOW;
+ ret = devm_register_power_off_handler(&client->dev,
+ &rk808->power_off_hb);
+ if (ret)
+ dev_warn(&client->dev,
+ "Failed to register power-off handler\n");
}

return 0;
@@ -240,7 +239,6 @@ static int rk808_remove(struct i2c_client *client)

regmap_del_irq_chip(client->irq, rk808->irq_data);
mfd_remove_devices(&client->dev);
- pm_power_off = NULL;

return 0;
}
diff --git a/include/linux/mfd/rk808.h b/include/linux/mfd/rk808.h
index fb09312..a6619f2 100644
--- a/include/linux/mfd/rk808.h
+++ b/include/linux/mfd/rk808.h
@@ -19,6 +19,7 @@
#ifndef __LINUX_REGULATOR_rk808_H
#define __LINUX_REGULATOR_rk808_H

+#include <linux/pm.h>
#include <linux/regulator/machine.h>
#include <linux/regmap.h>

@@ -192,5 +193,6 @@ struct rk808 {
struct i2c_client *i2c;
struct regmap_irq_chip_data *irq_data;
struct regmap *regmap;
+ struct power_off_handler_block power_off_hb;
};
#endif /* __LINUX_REGULATOR_rk808_H */
--
1.9.1

2014-11-06 16:44:51

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 25/48] power/reset: qnap-poweroff: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with default priority to reflect that the original
code generates an error if another power-off handler has already been
registered when the driver is loaded.

Drop remove function since it is no longer needed.

Cc: Sebastian Reichel <[email protected]>
Cc: Dmitry Eremin-Solenikov <[email protected]>
Cc: David Woodhouse <[email protected]>
Acked-by: Andrew Lunn <[email protected]>
Acked-by: Sebastian Reichel <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler
- Drop remove function since it is no longer needed

drivers/power/reset/qnap-poweroff.c | 28 ++++++++--------------------
1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/drivers/power/reset/qnap-poweroff.c b/drivers/power/reset/qnap-poweroff.c
index a75db7f..0f39564 100644
--- a/drivers/power/reset/qnap-poweroff.c
+++ b/drivers/power/reset/qnap-poweroff.c
@@ -17,6 +17,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
+#include <linux/pm.h>
#include <linux/serial_reg.h>
#include <linux/kallsyms.h>
#include <linux/of.h>
@@ -55,7 +56,7 @@ static void __iomem *base;
static unsigned long tclk;
static const struct power_off_cfg *cfg;

-static void qnap_power_off(void)
+static void qnap_power_off(struct power_off_handler_block *this)
{
const unsigned divisor = ((tclk + (8 * cfg->baud)) / (16 * cfg->baud));

@@ -74,12 +75,16 @@ static void qnap_power_off(void)
writel(cfg->cmd, UART1_REG(TX));
}

+static struct power_off_handler_block qnap_power_off_hb = {
+ .handler = qnap_power_off,
+ .priority = POWER_OFF_PRIORITY_DEFAULT,
+};
+
static int qnap_power_off_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
struct resource *res;
struct clk *clk;
- char symname[KSYM_NAME_LEN];

const struct of_device_id *match =
of_match_node(qnap_power_off_of_match_table, np);
@@ -106,28 +111,11 @@ static int qnap_power_off_probe(struct platform_device *pdev)

tclk = clk_get_rate(clk);

- /* Check that nothing else has already setup a handler */
- if (pm_power_off) {
- lookup_symbol_name((ulong)pm_power_off, symname);
- dev_err(&pdev->dev,
- "pm_power_off already claimed %p %s",
- pm_power_off, symname);
- return -EBUSY;
- }
- pm_power_off = qnap_power_off;
-
- return 0;
-}
-
-static int qnap_power_off_remove(struct platform_device *pdev)
-{
- pm_power_off = NULL;
- return 0;
+ return devm_register_power_off_handler(&pdev->dev, &qnap_power_off_hb);
}

static struct platform_driver qnap_power_off_driver = {
.probe = qnap_power_off_probe,
- .remove = qnap_power_off_remove,
.driver = {
.owner = THIS_MODULE,
.name = "qnap_power_off",
--
1.9.1

2014-11-06 16:44:43

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 22/48] power/reset: restart-poweroff: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register as power-off handler of last resort since the driver
does not really power off the system but executes a restart.

Drop remove function since it is no longer needed.

Cc: Sebastian Reichel <[email protected]>
Cc: Dmitry Eremin-Solenikov <[email protected]>
Cc: David Woodhouse <[email protected]>
Acked-by: Andrew Lunn <[email protected]>
Acked-by: Sebastian Reichel <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to sepcify poweroff handler priority
- Use devm_register_power_off_handler
- Drop remove function since it is no longer needed

drivers/power/reset/restart-poweroff.c | 29 +++++++++--------------------
1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/drivers/power/reset/restart-poweroff.c b/drivers/power/reset/restart-poweroff.c
index edd707e..ef2a602 100644
--- a/drivers/power/reset/restart-poweroff.c
+++ b/drivers/power/reset/restart-poweroff.c
@@ -15,34 +15,24 @@
#include <linux/platform_device.h>
#include <linux/of_platform.h>
#include <linux/module.h>
+#include <linux/pm.h>
#include <linux/reboot.h>
-#include <asm/system_misc.h>

-static void restart_poweroff_do_poweroff(void)
+static void restart_poweroff_do_poweroff(struct power_off_handler_block *this)
{
reboot_mode = REBOOT_HARD;
machine_restart(NULL);
}

-static int restart_poweroff_probe(struct platform_device *pdev)
-{
- /* If a pm_power_off function has already been added, leave it alone */
- if (pm_power_off != NULL) {
- dev_err(&pdev->dev,
- "pm_power_off function already registered");
- return -EBUSY;
- }
-
- pm_power_off = &restart_poweroff_do_poweroff;
- return 0;
-}
+static struct power_off_handler_block restart_power_off_handler = {
+ .handler = restart_poweroff_do_poweroff,
+ .priority = POWER_OFF_PRIORITY_FALLBACK,
+};

-static int restart_poweroff_remove(struct platform_device *pdev)
+static int restart_poweroff_probe(struct platform_device *pdev)
{
- if (pm_power_off == &restart_poweroff_do_poweroff)
- pm_power_off = NULL;
-
- return 0;
+ return devm_register_power_off_handler(&pdev->dev,
+ &restart_power_off_handler);
}

static const struct of_device_id of_restart_poweroff_match[] = {
@@ -52,7 +42,6 @@ static const struct of_device_id of_restart_poweroff_match[] = {

static struct platform_driver restart_poweroff_driver = {
.probe = restart_poweroff_probe,
- .remove = restart_poweroff_remove,
.driver = {
.name = "poweroff-restart",
.owner = THIS_MODULE,
--
1.9.1

2014-11-06 16:44:56

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 27/48] power/reset: vexpress-poweroff: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Select default priority to reflect that the original code sets
pm_power_off unconditionally.

Acked-by: Sebastian Reichel <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority

drivers/power/reset/vexpress-poweroff.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/power/reset/vexpress-poweroff.c b/drivers/power/reset/vexpress-poweroff.c
index 4dc102e2..ee1bcb5 100644
--- a/drivers/power/reset/vexpress-poweroff.c
+++ b/drivers/power/reset/vexpress-poweroff.c
@@ -36,11 +36,16 @@ static void vexpress_reset_do(struct device *dev, const char *what)

static struct device *vexpress_power_off_device;

-static void vexpress_power_off(void)
+static void vexpress_power_off(struct power_off_handler_block *this)
{
vexpress_reset_do(vexpress_power_off_device, "power off");
}

+static struct power_off_handler_block vexpress_power_off_hb = {
+ .handler = vexpress_power_off,
+ .priority = POWER_OFF_PRIORITY_DEFAULT,
+};
+
static struct device *vexpress_restart_device;

static void vexpress_restart(enum reboot_mode reboot_mode, const char *cmd)
@@ -92,6 +97,7 @@ static int vexpress_reset_probe(struct platform_device *pdev)
const struct of_device_id *match =
of_match_device(vexpress_reset_of_match, &pdev->dev);
struct regmap *regmap;
+ int ret;

if (match)
func = (enum vexpress_reset_func)match->data;
@@ -106,7 +112,12 @@ static int vexpress_reset_probe(struct platform_device *pdev)
switch (func) {
case FUNC_SHUTDOWN:
vexpress_power_off_device = &pdev->dev;
- pm_power_off = vexpress_power_off;
+ ret = register_power_off_handler(&vexpress_power_off_hb);
+ if (ret) {
+ dev_err(&pdev->dev,
+ "Failed to register power-off handler\n");
+ return ret;
+ }
break;
case FUNC_RESET:
if (!vexpress_restart_device)
--
1.9.1

2014-11-06 16:45:05

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 33/48] staging: nvec: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with default priority since we don't know any better.

Cc: Julian Andres Klode <[email protected]>
Cc: Marc Dietrich <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Acked-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Use dev_warn instead of dev_err

drivers/staging/nvec/nvec.c | 21 ++++++++++++---------
drivers/staging/nvec/nvec.h | 2 ++
2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c
index a93208a..acf2ea6 100644
--- a/drivers/staging/nvec/nvec.c
+++ b/drivers/staging/nvec/nvec.c
@@ -33,6 +33,7 @@
#include <linux/mfd/core.h>
#include <linux/mutex.h>
#include <linux/notifier.h>
+#include <linux/pm.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/workqueue.h>
@@ -80,8 +81,6 @@ enum nvec_sleep_subcmds {
#define LID_SWITCH BIT(1)
#define PWR_BUTTON BIT(15)

-static struct nvec_chip *nvec_power_handle;
-
static const struct mfd_cell nvec_devices[] = {
{
.name = "nvec-kbd",
@@ -759,12 +758,14 @@ static void nvec_disable_i2c_slave(struct nvec_chip *nvec)
}
#endif

-static void nvec_power_off(void)
+static void nvec_power_off(struct power_off_handler_block *this)
{
+ struct nvec_chip *nvec = container_of(this, struct nvec_chip,
+ power_off_hb);
char ap_pwr_down[] = { NVEC_SLEEP, AP_PWR_DOWN };

- nvec_toggle_global_events(nvec_power_handle, false);
- nvec_write_async(nvec_power_handle, ap_pwr_down, 2);
+ nvec_toggle_global_events(nvec, false);
+ nvec_write_async(nvec, ap_pwr_down, 2);
}

/*
@@ -878,8 +879,11 @@ static int tegra_nvec_probe(struct platform_device *pdev)
nvec->nvec_status_notifier.notifier_call = nvec_status_notifier;
nvec_register_notifier(nvec, &nvec->nvec_status_notifier, 0);

- nvec_power_handle = nvec;
- pm_power_off = nvec_power_off;
+ nvec->power_off_hb.handler = nvec_power_off;
+ nvec->power_off_hb.priority = POWER_OFF_PRIORITY_DEFAULT;
+ ret = register_power_off_handler(&nvec->power_off_hb);
+ if (ret)
+ dev_warn(nvec->dev, "Failed to register power-off handler\n");

/* Get Firmware Version */
msg = nvec_write_sync(nvec, get_firmware_version, 2);
@@ -914,13 +918,12 @@ static int tegra_nvec_remove(struct platform_device *pdev)
{
struct nvec_chip *nvec = platform_get_drvdata(pdev);

+ unregister_power_off_handler(&nvec->power_off_hb);
nvec_toggle_global_events(nvec, false);
mfd_remove_devices(nvec->dev);
nvec_unregister_notifier(nvec, &nvec->nvec_status_notifier);
cancel_work_sync(&nvec->rx_work);
cancel_work_sync(&nvec->tx_work);
- /* FIXME: needs check wether nvec is responsible for power off */
- pm_power_off = NULL;

return 0;
}
diff --git a/drivers/staging/nvec/nvec.h b/drivers/staging/nvec/nvec.h
index e271375..d4145da 100644
--- a/drivers/staging/nvec/nvec.h
+++ b/drivers/staging/nvec/nvec.h
@@ -163,6 +163,8 @@ struct nvec_chip {
struct nvec_msg *last_sync_msg;

int state;
+
+ struct power_off_handler_block power_off_hb;
};

extern int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
--
1.9.1

2014-11-06 16:45:12

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 32/48] x86: olpc: Register xo1 power-off handler with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with high priority to reflect that the driver
explicitly wants to override default power-off handlers.

Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Acked-by: Thomas Gleixner <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority

arch/x86/platform/olpc/olpc-xo1-pm.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/arch/x86/platform/olpc/olpc-xo1-pm.c b/arch/x86/platform/olpc/olpc-xo1-pm.c
index a9acde7..7a4878eb 100644
--- a/arch/x86/platform/olpc/olpc-xo1-pm.c
+++ b/arch/x86/platform/olpc/olpc-xo1-pm.c
@@ -92,7 +92,7 @@ asmlinkage __visible int xo1_do_sleep(u8 sleep_state)
return 0;
}

-static void xo1_power_off(void)
+static void xo1_power_off(struct power_off_handler_block *this)
{
printk(KERN_INFO "OLPC XO-1 power off sequence...\n");

@@ -110,6 +110,11 @@ static void xo1_power_off(void)
outl(0x00002000, acpi_base + CS5536_PM1_CNT);
}

+static struct power_off_handler_block xo1_power_off_hb = {
+ .handler = xo1_power_off,
+ .priority = POWER_OFF_PRIORITY_HIGH,
+};
+
static int xo1_power_state_valid(suspend_state_t pm_state)
{
/* suspend-to-RAM only */
@@ -146,8 +151,12 @@ static int xo1_pm_probe(struct platform_device *pdev)

/* If we have both addresses, we can override the poweroff hook */
if (pms_base && acpi_base) {
+ err = register_power_off_handler(&xo1_power_off_hb);
+ if (err) {
+ dev_err(&pdev->dev, "Failed to register power-off handler\n");
+ return err;
+ }
suspend_set_ops(&xo1_suspend_ops);
- pm_power_off = xo1_power_off;
printk(KERN_INFO "OLPC XO-1 support registered\n");
}

@@ -158,12 +167,13 @@ static int xo1_pm_remove(struct platform_device *pdev)
{
mfd_cell_disable(pdev);

+ unregister_power_off_handler(&xo1_power_off_hb);
+
if (strcmp(pdev->name, "cs5535-pms") == 0)
pms_base = 0;
else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
acpi_base = 0;

- pm_power_off = NULL;
return 0;
}

--
1.9.1

2014-11-06 16:45:32

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 37/48] avr32: atngw100: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly.

Cc: Haavard Skinnemoen <[email protected]>
Cc: Hans-Christian Egtvedt <[email protected]>
Acked-by: Hans-Christian Egtvedt <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority

arch/avr32/boards/atngw100/mrmt.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/avr32/boards/atngw100/mrmt.c b/arch/avr32/boards/atngw100/mrmt.c
index 91146b4..166c2e1 100644
--- a/arch/avr32/boards/atngw100/mrmt.c
+++ b/arch/avr32/boards/atngw100/mrmt.c
@@ -274,7 +274,8 @@ static int __init mrmt1_init(void)
{
gpio_set_value( PIN_PWR_ON, 1 ); /* Ensure PWR_ON is enabled */

- pm_power_off = mrmt_power_off;
+ register_power_off_handler_simple(mrmt_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

/* Setup USARTS (other than console) */
at32_map_usart(2, 1, 0); /* USART 2: /dev/ttyS1, RMT1:DB9M */
--
1.9.1

2014-11-06 16:45:42

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 45/48] x86: intel-mid: Drop registration of dummy power-off handlers

A dummy power-off handler does not serve any purpose. Drop it.

Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Acked-by: Thomas Gleixner <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- No change
v2:
- No change

arch/x86/platform/intel-mid/intel-mid.c | 5 -----
arch/x86/platform/intel-mid/mfld.c | 5 -----
2 files changed, 10 deletions(-)

diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
index 1bbedc4..4b70666 100644
--- a/arch/x86/platform/intel-mid/intel-mid.c
+++ b/arch/x86/platform/intel-mid/intel-mid.c
@@ -67,10 +67,6 @@ static void *(*get_intel_mid_ops[])(void) = INTEL_MID_OPS_INIT;
enum intel_mid_cpu_type __intel_mid_cpu_chip;
EXPORT_SYMBOL_GPL(__intel_mid_cpu_chip);

-static void intel_mid_power_off(void)
-{
-};
-
static void intel_mid_reboot(void)
{
intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
@@ -183,7 +179,6 @@ void __init x86_intel_mid_early_setup(void)

legacy_pic = &null_legacy_pic;

- pm_power_off = intel_mid_power_off;
machine_ops.emergency_restart = intel_mid_reboot;

/* Avoid searching for BIOS MP tables */
diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
index 23381d2..cf6842f 100644
--- a/arch/x86/platform/intel-mid/mfld.c
+++ b/arch/x86/platform/intel-mid/mfld.c
@@ -23,10 +23,6 @@ static struct intel_mid_ops penwell_ops = {
.arch_setup = penwell_arch_setup,
};

-static void mfld_power_off(void)
-{
-}
-
static unsigned long __init mfld_calibrate_tsc(void)
{
unsigned long fast_calibrate;
@@ -61,7 +57,6 @@ static unsigned long __init mfld_calibrate_tsc(void)
static void __init penwell_arch_setup(void)
{
x86_platform.calibrate_tsc = mfld_calibrate_tsc;
- pm_power_off = mfld_power_off;
}

void *get_penwell_ops(void)
--
1.9.1

2014-11-06 16:45:52

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 48/48] kernel: Remove pm_power_off

No users of pm_power_off are left, so it is safe to remove the function.

Cc: Rafael J. Wysocki <[email protected]>
Cc: Pavel Machek <[email protected]>
Cc: Len Brown <[email protected]>
Acked-by: Rafael J. Wysocki <[email protected]>
Acked-by: Pavel Machek <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
v2:
- poweroff -> power_off for API functions

include/linux/pm.h | 1 -
kernel/power/power_off_handler.c | 13 +------------
2 files changed, 1 insertion(+), 13 deletions(-)

diff --git a/include/linux/pm.h b/include/linux/pm.h
index a4d6bf8..8fcf352 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -31,7 +31,6 @@
/*
* Callbacks for platform drivers to implement.
*/
-extern void (*pm_power_off)(void);
extern void (*pm_power_off_prepare)(void);

struct device; /* we have a circular dep with device.h */
diff --git a/kernel/power/power_off_handler.c b/kernel/power/power_off_handler.c
index e283ea1..d67ab57 100644
--- a/kernel/power/power_off_handler.c
+++ b/kernel/power/power_off_handler.c
@@ -23,12 +23,6 @@
#include <linux/types.h>

/*
- * If set, calling this function will power off the system immediately.
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
-/*
* List of handlers for kernel code which wants to be called
* to power off the system.
*/
@@ -277,10 +271,6 @@ void do_kernel_power_off(void)
* removed while the call chain is traversed, but we'll have to accept
* that risk.
*/
-
- if (pm_power_off)
- pm_power_off();
-
p = rcu_dereference_raw(power_off_handler_list);
while (p) {
next_p = rcu_dereference_raw(p->next);
@@ -296,7 +286,6 @@ void do_kernel_power_off(void)
*/
bool have_kernel_power_off(void)
{
- return pm_power_off != NULL ||
- rcu_dereference_raw(power_off_handler_list) != NULL;
+ return rcu_dereference_raw(power_off_handler_list) != NULL;
}
EXPORT_SYMBOL(have_kernel_power_off);
--
1.9.1

2014-11-06 16:45:38

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 43/48] x86: lguest: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly.

Cc: Rusty Russell <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Acked-by: Thomas Gleixner <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority

arch/x86/lguest/boot.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
index aae9413..9dff406 100644
--- a/arch/x86/lguest/boot.c
+++ b/arch/x86/lguest/boot.c
@@ -1441,7 +1441,8 @@ __init void lguest_init(void)
* the Guest routine to power off, and the reboot hook to our restart
* routine.
*/
- pm_power_off = lguest_power_off;
+ register_power_off_handler_simple(lguest_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
machine_ops.restart = lguest_restart;

/*
--
1.9.1

2014-11-06 16:45:48

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 46/48] x86: pmc_atom: Register power-off handler with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the original code
only sets pm_power_off if it was not already set.

Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Acked-by: Thomas Gleixner <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Use dev_warn instead of dev_err

arch/x86/kernel/pmc_atom.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/pmc_atom.c b/arch/x86/kernel/pmc_atom.c
index 0ee5025e..acb4e78 100644
--- a/arch/x86/kernel/pmc_atom.c
+++ b/arch/x86/kernel/pmc_atom.c
@@ -20,6 +20,7 @@
#include <linux/pci.h>
#include <linux/device.h>
#include <linux/debugfs.h>
+#include <linux/pm.h>
#include <linux/seq_file.h>
#include <linux/io.h>

@@ -92,7 +93,7 @@ static inline void pmc_reg_write(struct pmc_dev *pmc, int reg_offset, u32 val)
writel(val, pmc->regmap + reg_offset);
}

-static void pmc_power_off(void)
+static void pmc_power_off(struct power_off_handler_block *this)
{
u16 pm1_cnt_port;
u32 pm1_cnt_value;
@@ -109,6 +110,11 @@ static void pmc_power_off(void)
outl(pm1_cnt_value, pm1_cnt_port);
}

+static struct power_off_handler_block pmc_power_off_hb = {
+ .handler = pmc_power_off,
+ .priority = POWER_OFF_PRIORITY_LOW,
+};
+
static void pmc_hw_reg_setup(struct pmc_dev *pmc)
{
/*
@@ -252,8 +258,12 @@ static int pmc_setup_dev(struct pci_dev *pdev)
acpi_base_addr &= ACPI_BASE_ADDR_MASK;

/* Install power off function */
- if (acpi_base_addr != 0 && pm_power_off == NULL)
- pm_power_off = pmc_power_off;
+ if (acpi_base_addr != 0) {
+ ret = register_power_off_handler(&pmc_power_off_hb);
+ if (ret)
+ dev_warn(&pdev->dev,
+ "Failed to install power-off handler\n");
+ }

pci_read_config_dword(pdev, PMC_BASE_ADDR_OFFSET, &pmc->base_addr);
pmc->base_addr &= PMC_BASE_ADDR_MASK;
--
1.9.1

2014-11-06 16:46:58

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 47/48] efi: Register power-off handler with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority since the efi code states that
this is a power-off handler of last resort.

Cc: Matt Fleming <[email protected]>
Acked-by: Matt Fleming <[email protected]>
Acked-by: Mark Salter <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority

drivers/firmware/efi/reboot.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/drivers/firmware/efi/reboot.c b/drivers/firmware/efi/reboot.c
index 9c59d1c..0ddec8f 100644
--- a/drivers/firmware/efi/reboot.c
+++ b/drivers/firmware/efi/reboot.c
@@ -3,6 +3,7 @@
* Copyright (c) 2014 Red Hat, Inc., Mark Salter <[email protected]>
*/
#include <linux/efi.h>
+#include <linux/pm.h>
#include <linux/reboot.h>

int efi_reboot_quirk_mode = -1;
@@ -38,19 +39,29 @@ bool __weak efi_poweroff_required(void)
return false;
}

-static void efi_power_off(void)
+static void efi_power_off(struct power_off_handler_block *this)
{
efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
}

+static struct power_off_handler_block efi_power_off_hb = {
+ .handler = efi_power_off,
+ .priority = POWER_OFF_PRIORITY_LOW,
+};
+
static int __init efi_shutdown_init(void)
{
+ int ret = 0;
+
if (!efi_enabled(EFI_RUNTIME_SERVICES))
return -ENODEV;

- if (efi_poweroff_required())
- pm_power_off = efi_power_off;
+ if (efi_poweroff_required()) {
+ ret = register_power_off_handler(&efi_power_off_hb);
+ if (ret)
+ pr_err("efi: Failed to register power-off handler\n");
+ }

- return 0;
+ return ret;
}
late_initcall(efi_shutdown_init);
--
1.9.1

2014-11-06 16:47:50

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 44/48] x86: ce4100: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly.

Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Acked-by: Thomas Gleixner <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority

arch/x86/platform/ce4100/ce4100.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/platform/ce4100/ce4100.c b/arch/x86/platform/ce4100/ce4100.c
index 701fd58..1816bc1 100644
--- a/arch/x86/platform/ce4100/ce4100.c
+++ b/arch/x86/platform/ce4100/ce4100.c
@@ -164,5 +164,6 @@ void __init x86_ce4100_early_setup(void)
*/
reboot_type = BOOT_KBD;

- pm_power_off = ce4100_power_off;
+ register_power_off_handler_simple(ce4100_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
}
--
1.9.1

2014-11-06 16:45:27

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 39/48] m68k: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly.

Cc: Geert Uytterhoeven <[email protected]>
Cc: Joshua Thompson <[email protected]>
Acked-by: Geert Uytterhoeven <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use defines to specify poweroff handler priorities

arch/m68k/emu/natfeat.c | 3 ++-
arch/m68k/mac/config.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/m68k/emu/natfeat.c b/arch/m68k/emu/natfeat.c
index 91e2ae7..38fec50 100644
--- a/arch/m68k/emu/natfeat.c
+++ b/arch/m68k/emu/natfeat.c
@@ -91,5 +91,6 @@ void __init nf_init(void)
pr_info("NatFeats found (%s, %lu.%lu)\n", buf, version >> 16,
version & 0xffff);

- pm_power_off = nf_poweroff;
+ register_power_off_handler_simple(nf_poweroff,
+ POWER_OFF_PRIORITY_DEFAULT);
}
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index 677913ff..14fd981 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -160,7 +160,8 @@ void __init config_mac(void)
mach_set_clock_mmss = mac_set_clock_mmss;
mach_reset = mac_reset;
mach_halt = mac_poweroff;
- pm_power_off = mac_poweroff;
+ register_power_off_handler_simple(mac_poweroff,
+ POWER_OFF_PRIORITY_DEFAULT);
mach_max_dma_address = 0xffffffff;
#if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
mach_beep = mac_mksound;
--
1.9.1

2014-11-06 16:48:22

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 42/48] sh: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly.

Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use defines to specify poweroff handler priorities

arch/sh/boards/board-sh7785lcr.c | 3 ++-
arch/sh/boards/board-urquell.c | 3 ++-
arch/sh/boards/mach-highlander/setup.c | 3 ++-
arch/sh/boards/mach-landisk/setup.c | 3 ++-
arch/sh/boards/mach-r2d/setup.c | 3 ++-
arch/sh/boards/mach-sdk7786/setup.c | 3 ++-
6 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/arch/sh/boards/board-sh7785lcr.c b/arch/sh/boards/board-sh7785lcr.c
index 2c4771e..f7d2ffb 100644
--- a/arch/sh/boards/board-sh7785lcr.c
+++ b/arch/sh/boards/board-sh7785lcr.c
@@ -332,7 +332,8 @@ static void __init sh7785lcr_setup(char **cmdline_p)

printk(KERN_INFO "Renesas Technology Corp. R0P7785LC0011RL support.\n");

- pm_power_off = sh7785lcr_power_off;
+ register_power_off_handler_simple(sh7785lcr_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

/* sm501 DRAM configuration */
sm501_reg = ioremap_nocache(SM107_REG_ADDR, SM501_DRAM_CONTROL);
diff --git a/arch/sh/boards/board-urquell.c b/arch/sh/boards/board-urquell.c
index b52abcc..8f44256 100644
--- a/arch/sh/boards/board-urquell.c
+++ b/arch/sh/boards/board-urquell.c
@@ -204,7 +204,8 @@ static void __init urquell_setup(char **cmdline_p)
{
printk(KERN_INFO "Renesas Technology Corp. Urquell support.\n");

- pm_power_off = urquell_power_off;
+ register_power_off_handler_simple(urquell_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

register_smp_ops(&shx3_smp_ops);
}
diff --git a/arch/sh/boards/mach-highlander/setup.c b/arch/sh/boards/mach-highlander/setup.c
index 4a52590..fc9110a 100644
--- a/arch/sh/boards/mach-highlander/setup.c
+++ b/arch/sh/boards/mach-highlander/setup.c
@@ -385,7 +385,8 @@ static void __init highlander_setup(char **cmdline_p)

__raw_writew(__raw_readw(PA_IVDRCTL) | 0x01, PA_IVDRCTL); /* Si13112 */

- pm_power_off = r7780rp_power_off;
+ register_power_off_handler_simple(r7780rp_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
}

static unsigned char irl2irq[HL_NR_IRL];
diff --git a/arch/sh/boards/mach-landisk/setup.c b/arch/sh/boards/mach-landisk/setup.c
index f1147ca..56adabc 100644
--- a/arch/sh/boards/mach-landisk/setup.c
+++ b/arch/sh/boards/mach-landisk/setup.c
@@ -89,7 +89,8 @@ static void __init landisk_setup(char **cmdline_p)
__raw_writeb(__raw_readb(PA_LED) | 0x03, PA_LED);

printk(KERN_INFO "I-O DATA DEVICE, INC. \"LANDISK Series\" support.\n");
- pm_power_off = landisk_power_off;
+ register_power_off_handler_simple(landisk_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
}

/*
diff --git a/arch/sh/boards/mach-r2d/setup.c b/arch/sh/boards/mach-r2d/setup.c
index 4b98a52..4a23bce 100644
--- a/arch/sh/boards/mach-r2d/setup.c
+++ b/arch/sh/boards/mach-r2d/setup.c
@@ -279,7 +279,8 @@ static void __init rts7751r2d_setup(char **cmdline_p)
(ver >> 4) & 0xf, ver & 0xf);

__raw_writew(0x0000, PA_OUTPORT);
- pm_power_off = rts7751r2d_power_off;
+ register_power_off_handler_simple(rts7751r2d_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

/* sm501 dram configuration:
* ColSizeX = 11 - External Memory Column Size: 256 words.
diff --git a/arch/sh/boards/mach-sdk7786/setup.c b/arch/sh/boards/mach-sdk7786/setup.c
index c29268b..2d77760 100644
--- a/arch/sh/boards/mach-sdk7786/setup.c
+++ b/arch/sh/boards/mach-sdk7786/setup.c
@@ -252,7 +252,8 @@ static void __init sdk7786_setup(char **cmdline_p)
pr_info("\tPCB revision:\t%d\n", fpga_read_reg(PCBRR) & 0xf);

machine_ops.restart = sdk7786_restart;
- pm_power_off = sdk7786_power_off;
+ register_power_off_handler_simple(sdk7786_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

register_smp_ops(&shx3_smp_ops);
}
--
1.9.1

2014-11-06 16:45:23

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 38/48] ia64: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the call is expected
to be replaced at some point in the future.

Cc: Tony Luck <[email protected]>
Cc: Fenghua Yu <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority

arch/ia64/sn/kernel/setup.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/ia64/sn/kernel/setup.c b/arch/ia64/sn/kernel/setup.c
index 5f6b6b4..fc9905e 100644
--- a/arch/ia64/sn/kernel/setup.c
+++ b/arch/ia64/sn/kernel/setup.c
@@ -488,12 +488,13 @@ void __init sn_setup(char **cmdline_p)
sn_timer_init();

/*
- * set pm_power_off to a SAL call to allow
+ * set power-off handler to a SAL call to allow
* sn machines to power off. The SAL call can be replaced
* by an ACPI interface call when ACPI is fully implemented
* for sn.
*/
- pm_power_off = ia64_sn_power_down;
+ register_power_off_handler_simple(ia64_sn_power_down,
+ POWER_OFF_PRIORITY_LOW);
current->thread.flags |= IA64_THREAD_MIGRATION;
}

--
1.9.1

2014-11-06 16:48:42

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 41/48] powerpc: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly.

If there is an indication that there can be more than one power-off handler,
use register_power_off_handler, otherwise use register_power_off_handler_simple
to register the power-off handler.

If the power-off handler only resets or stops the system, select the fallback
priority to indicate that the power-off handler is one of last resort.
If the power-off handler powers off the system, select the default priority,
unless the power-off handler installation code suggests that there can be
more than one power-off handler and the new handler is only installed
conditionally. In this case, install the handler with low priority.

Cc: Alexander Graf <[email protected]>
Cc: Michael Ellerman <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- New patch

arch/powerpc/platforms/44x/ppc476.c | 3 ++-
arch/powerpc/platforms/52xx/efika.c | 3 ++-
arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c | 30 ++++++++++++++++--------
arch/powerpc/platforms/85xx/corenet_generic.c | 3 ++-
arch/powerpc/platforms/85xx/sgy_cts1000.c | 16 +++++++++++--
arch/powerpc/platforms/cell/celleb_setup.c | 6 +++--
arch/powerpc/platforms/cell/qpace_setup.c | 3 ++-
arch/powerpc/platforms/cell/setup.c | 3 ++-
arch/powerpc/platforms/chrp/setup.c | 3 ++-
arch/powerpc/platforms/embedded6xx/gamecube.c | 3 ++-
arch/powerpc/platforms/embedded6xx/linkstation.c | 3 ++-
arch/powerpc/platforms/embedded6xx/wii.c | 3 ++-
arch/powerpc/platforms/maple/setup.c | 6 +++--
arch/powerpc/platforms/powermac/setup.c | 3 ++-
arch/powerpc/platforms/powernv/setup.c | 6 +++--
arch/powerpc/platforms/ps3/setup.c | 3 ++-
arch/powerpc/platforms/pseries/setup.c | 3 ++-
arch/powerpc/sysdev/fsl_soc.c | 6 ++---
18 files changed, 73 insertions(+), 33 deletions(-)

diff --git a/arch/powerpc/platforms/44x/ppc476.c b/arch/powerpc/platforms/44x/ppc476.c
index c11ce65..590d31f 100644
--- a/arch/powerpc/platforms/44x/ppc476.c
+++ b/arch/powerpc/platforms/44x/ppc476.c
@@ -94,7 +94,8 @@ static int avr_probe(struct i2c_client *client,
{
avr_i2c_client = client;
ppc_md.restart = avr_reset_system;
- pm_power_off = avr_power_off_system;
+ register_power_off_handler_simple(avr_power_off_system,
+ POWER_OFF_PRIORITY_DEFAULT);
return 0;
}

diff --git a/arch/powerpc/platforms/52xx/efika.c b/arch/powerpc/platforms/52xx/efika.c
index 6af651e..321a7a7 100644
--- a/arch/powerpc/platforms/52xx/efika.c
+++ b/arch/powerpc/platforms/52xx/efika.c
@@ -212,7 +212,8 @@ static int __init efika_probe(void)
DMA_MODE_READ = 0x44;
DMA_MODE_WRITE = 0x48;

- pm_power_off = rtas_power_off;
+ register_power_off_handler_simple(rtas_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

return 1;
}
diff --git a/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c b/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
index 15e8021..1bf6b0e 100644
--- a/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
+++ b/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
@@ -19,6 +19,7 @@
#include <linux/gpio.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
+#include <linux/pm.h>
#include <linux/slab.h>
#include <linux/kthread.h>
#include <linux/reboot.h>
@@ -86,7 +87,7 @@ static ssize_t show_status(struct device *d,
}
static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);

-static void mcu_power_off(void)
+static void mcu_power_off(struct power_off_handler_block *this)
{
struct mcu *mcu = glob_mcu;

@@ -97,6 +98,11 @@ static void mcu_power_off(void)
mutex_unlock(&mcu->lock);
}

+static struct power_off_handler_block mcu_power_off_hb = {
+ .handler = mcu_power_off,
+ .priority = POWER_OFF_PRIORITY_LOW,
+};
+
static void mcu_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
{
struct mcu *mcu = container_of(gc, struct mcu, gc);
@@ -167,13 +173,15 @@ static int mcu_probe(struct i2c_client *client, const struct i2c_device_id *id)
if (ret)
goto err;

- /* XXX: this is potentially racy, but there is no lock for pm_power_off */
- if (!pm_power_off) {
- glob_mcu = mcu;
- pm_power_off = mcu_power_off;
- dev_info(&client->dev, "will provide power-off service\n");
+ glob_mcu = mcu;
+ ret = register_power_off_handler(&mcu_power_off_hb);
+ if (ret) {
+ dev_err(&client->dev, "Failed to register power-off handler\n");
+ goto err_handler;
}

+ dev_info(&client->dev, "will provide power-off service\n");
+
if (device_create_file(&client->dev, &dev_attr_status))
dev_err(&client->dev,
"couldn't create device file for status\n");
@@ -182,6 +190,10 @@ static int mcu_probe(struct i2c_client *client, const struct i2c_device_id *id)
"mcu-i2c-shdn");

return 0;
+
+err_handler:
+ mcu_gpiochip_remove(mcu);
+ glob_mcu = NULL;
err:
kfree(mcu);
return ret;
@@ -196,10 +208,8 @@ static int mcu_remove(struct i2c_client *client)

device_remove_file(&client->dev, &dev_attr_status);

- if (glob_mcu == mcu) {
- pm_power_off = NULL;
- glob_mcu = NULL;
- }
+ unregister_power_off_handler(&mcu_power_off_hb);
+ glob_mcu = NULL;

ret = mcu_gpiochip_remove(mcu);
if (ret)
diff --git a/arch/powerpc/platforms/85xx/corenet_generic.c b/arch/powerpc/platforms/85xx/corenet_generic.c
index 1f309cc..f0c4b51 100644
--- a/arch/powerpc/platforms/85xx/corenet_generic.c
+++ b/arch/powerpc/platforms/85xx/corenet_generic.c
@@ -170,7 +170,8 @@ static int __init corenet_generic_probe(void)

ppc_md.get_irq = ehv_pic_get_irq;
ppc_md.restart = fsl_hv_restart;
- pm_power_off = fsl_hv_halt;
+ register_power_off_handler_simple(fsl_hv_halt,
+ POWER_OFF_PRIORITY_DEFAULT);
ppc_md.halt = fsl_hv_halt;
#ifdef CONFIG_SMP
/*
diff --git a/arch/powerpc/platforms/85xx/sgy_cts1000.c b/arch/powerpc/platforms/85xx/sgy_cts1000.c
index e149c9e..d849e8f 100644
--- a/arch/powerpc/platforms/85xx/sgy_cts1000.c
+++ b/arch/powerpc/platforms/85xx/sgy_cts1000.c
@@ -16,6 +16,7 @@
#include <linux/module.h>
#include <linux/of_gpio.h>
#include <linux/of_irq.h>
+#include <linux/pm.h>
#include <linux/workqueue.h>
#include <linux/reboot.h>
#include <linux/interrupt.h>
@@ -59,6 +60,16 @@ static void gpio_halt_cb(void)
gpio_set_value(gpio, trigger);
}

+static void gpio_power_off_cb(struct power_off_handler_block *this)
+{
+ gpio_halt_cb();
+}
+
+static struct power_off_handler_block gpio_power_off_hb = {
+ .handler = gpio_power_off_cb,
+ .priority = POWER_OFF_PRIORITY_DEFAULT,
+};
+
/* This IRQ means someone pressed the power button and it is waiting for us
* to handle the shutdown/poweroff. */
static irqreturn_t gpio_halt_irq(int irq, void *__data)
@@ -120,7 +131,8 @@ static int gpio_halt_probe(struct platform_device *pdev)

/* Register our halt function */
ppc_md.halt = gpio_halt_cb;
- pm_power_off = gpio_halt_cb;
+ if (register_power_off_handler(&gpio_power_off_hb))
+ pr_warn("gpio-halt: Failed to register power-off handler\n");

printk(KERN_INFO "gpio-halt: registered GPIO %d (%d trigger, %d"
" irq).\n", gpio, trigger, irq);
@@ -137,7 +149,7 @@ static int gpio_halt_remove(struct platform_device *pdev)
free_irq(irq, halt_node);

ppc_md.halt = NULL;
- pm_power_off = NULL;
+ unregister_power_off_handler(&gpio_power_off_hb);

gpio_free(gpio);

diff --git a/arch/powerpc/platforms/cell/celleb_setup.c b/arch/powerpc/platforms/cell/celleb_setup.c
index 90be8ec..e301b1a 100644
--- a/arch/powerpc/platforms/cell/celleb_setup.c
+++ b/arch/powerpc/platforms/cell/celleb_setup.c
@@ -142,7 +142,8 @@ static int __init celleb_probe_beat(void)
powerpc_firmware_features |= FW_FEATURE_CELLEB_ALWAYS
| FW_FEATURE_BEAT | FW_FEATURE_LPAR;
hpte_init_beat_v3();
- pm_power_off = beat_power_off;
+ register_power_off_handler_simple(beat_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

return 1;
}
@@ -191,7 +192,8 @@ static int __init celleb_probe_native(void)

powerpc_firmware_features |= FW_FEATURE_CELLEB_ALWAYS;
hpte_init_native();
- pm_power_off = rtas_power_off;
+ register_power_off_handler_simple(rtas_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

return 1;
}
diff --git a/arch/powerpc/platforms/cell/qpace_setup.c b/arch/powerpc/platforms/cell/qpace_setup.c
index d328140..223d40a 100644
--- a/arch/powerpc/platforms/cell/qpace_setup.c
+++ b/arch/powerpc/platforms/cell/qpace_setup.c
@@ -127,7 +127,8 @@ static int __init qpace_probe(void)
return 0;

hpte_init_native();
- pm_power_off = rtas_power_off;
+ register_power_off_handler_simple(rtas_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

return 1;
}
diff --git a/arch/powerpc/platforms/cell/setup.c b/arch/powerpc/platforms/cell/setup.c
index d62aa98..ea5460c 100644
--- a/arch/powerpc/platforms/cell/setup.c
+++ b/arch/powerpc/platforms/cell/setup.c
@@ -259,7 +259,8 @@ static int __init cell_probe(void)
return 0;

hpte_init_native();
- pm_power_off = rtas_power_off;
+ register_power_off_handler_simple(rtas_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

return 1;
}
diff --git a/arch/powerpc/platforms/chrp/setup.c b/arch/powerpc/platforms/chrp/setup.c
index 860a59e..0c0288e 100644
--- a/arch/powerpc/platforms/chrp/setup.c
+++ b/arch/powerpc/platforms/chrp/setup.c
@@ -585,7 +585,8 @@ static int __init chrp_probe(void)
DMA_MODE_READ = 0x44;
DMA_MODE_WRITE = 0x48;

- pm_power_off = rtas_power_off;
+ register_power_off_handler_simple(rtas_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

return 1;
}
diff --git a/arch/powerpc/platforms/embedded6xx/gamecube.c b/arch/powerpc/platforms/embedded6xx/gamecube.c
index fe0ed6e..af40f0f 100644
--- a/arch/powerpc/platforms/embedded6xx/gamecube.c
+++ b/arch/powerpc/platforms/embedded6xx/gamecube.c
@@ -67,7 +67,8 @@ static int __init gamecube_probe(void)
if (!of_flat_dt_is_compatible(dt_root, "nintendo,gamecube"))
return 0;

- pm_power_off = gamecube_power_off;
+ register_power_off_handler_simple(gamecube_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

return 1;
}
diff --git a/arch/powerpc/platforms/embedded6xx/linkstation.c b/arch/powerpc/platforms/embedded6xx/linkstation.c
index 540eeb5..0c4dcf8 100644
--- a/arch/powerpc/platforms/embedded6xx/linkstation.c
+++ b/arch/powerpc/platforms/embedded6xx/linkstation.c
@@ -148,7 +148,8 @@ static int __init linkstation_probe(void)
if (!of_flat_dt_is_compatible(root, "linkstation"))
return 0;

- pm_power_off = linkstation_power_off;
+ register_power_off_handler_simple(linkstation_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

return 1;
}
diff --git a/arch/powerpc/platforms/embedded6xx/wii.c b/arch/powerpc/platforms/embedded6xx/wii.c
index 352592d..eea8824 100644
--- a/arch/powerpc/platforms/embedded6xx/wii.c
+++ b/arch/powerpc/platforms/embedded6xx/wii.c
@@ -211,7 +211,8 @@ static int __init wii_probe(void)
if (!of_flat_dt_is_compatible(dt_root, "nintendo,wii"))
return 0;

- pm_power_off = wii_power_off;
+ register_power_off_handler_simple(wii_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

return 1;
}
diff --git a/arch/powerpc/platforms/maple/setup.c b/arch/powerpc/platforms/maple/setup.c
index 56b85cd..73c3988 100644
--- a/arch/powerpc/platforms/maple/setup.c
+++ b/arch/powerpc/platforms/maple/setup.c
@@ -169,7 +169,8 @@ static void __init maple_use_rtas_reboot_and_halt_if_present(void)
if (rtas_service_present("system-reboot") &&
rtas_service_present("power-off")) {
ppc_md.restart = rtas_restart;
- pm_power_off = rtas_power_off;
+ register_power_off_handler_simple(rtas_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
ppc_md.halt = rtas_halt;
}
}
@@ -312,7 +313,8 @@ static int __init maple_probe(void)
alloc_dart_table();

hpte_init_native();
- pm_power_off = maple_power_off;
+ register_power_off_handler_simple(maple_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

return 1;
}
diff --git a/arch/powerpc/platforms/powermac/setup.c b/arch/powerpc/platforms/powermac/setup.c
index 713d36d..6496ae4 100644
--- a/arch/powerpc/platforms/powermac/setup.c
+++ b/arch/powerpc/platforms/powermac/setup.c
@@ -632,7 +632,8 @@ static int __init pmac_probe(void)
smu_cmdbuf_abs = memblock_alloc_base(4096, 4096, 0x80000000UL);
#endif /* CONFIG_PMAC_SMU */

- pm_power_off = pmac_power_off;
+ register_power_off_handler_simple(pmac_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

return 1;
}
diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c
index 941831d..a03c41b 100644
--- a/arch/powerpc/platforms/powernv/setup.c
+++ b/arch/powerpc/platforms/powernv/setup.c
@@ -268,7 +268,8 @@ static void __init pnv_setup_machdep_opal(void)
ppc_md.get_rtc_time = opal_get_rtc_time;
ppc_md.set_rtc_time = opal_set_rtc_time;
ppc_md.restart = pnv_restart;
- pm_power_off = pnv_power_off;
+ register_power_off_handler_simple(pnv_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
ppc_md.halt = pnv_halt;
ppc_md.machine_check_exception = opal_machine_check;
ppc_md.mce_check_early_recovery = opal_mce_check_early_recovery;
@@ -285,7 +286,8 @@ static void __init pnv_setup_machdep_rtas(void)
ppc_md.set_rtc_time = rtas_set_rtc_time;
}
ppc_md.restart = rtas_restart;
- pm_power_off = rtas_power_off;
+ register_power_off_handler_simple(rtas_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
ppc_md.halt = rtas_halt;
}
#endif /* CONFIG_PPC_POWERNV_RTAS */
diff --git a/arch/powerpc/platforms/ps3/setup.c b/arch/powerpc/platforms/ps3/setup.c
index 009a200..77e0dea 100644
--- a/arch/powerpc/platforms/ps3/setup.c
+++ b/arch/powerpc/platforms/ps3/setup.c
@@ -248,7 +248,8 @@ static int __init ps3_probe(void)
ps3_mm_init();
ps3_mm_vas_create(&htab_size);
ps3_hpte_init(htab_size);
- pm_power_off = ps3_power_off;
+ register_power_off_handler_simple(ps3_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

DBG(" <- %s:%d\n", __func__, __LINE__);
return 1;
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index db0fc0c..b3c85bb 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -769,7 +769,8 @@ static int __init pSeries_probe(void)
else
hpte_init_native();

- pm_power_off = pseries_power_off;
+ register_power_off_handler_simple(pseries_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

pr_debug("Machine is%s LPAR !\n",
(powerpc_firmware_features & FW_FEATURE_LPAR) ? "" : " not");
diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
index 1e04568..eeb075f 100644
--- a/arch/powerpc/sysdev/fsl_soc.c
+++ b/arch/powerpc/sysdev/fsl_soc.c
@@ -238,9 +238,9 @@ void fsl_hv_restart(char *cmd)
/*
* Halt the current partition
*
- * This function should be assigned to the pm_power_off and ppc_md.halt
- * function pointers, to shut down the partition when we're running under
- * the Freescale hypervisor.
+ * This function should be registered as power-off handler and be assigned
+ * to the ppc_md.halt function pointer, to shut down the partition when
+ * we're running under the Freescale hypervisor.
*/
void fsl_hv_halt(void)
{
--
1.9.1

2014-11-06 16:49:26

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 40/48] mips: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly.

If there is an indication that there can be more than one power-off handler,
use register_power_off_handler, otherwise use register_power_off_handler_simple
to register the power-off handler.

If the power-off handler only resets or stops the system, select the fallback
priority to indicate that the power-off handler is one of last resort.
If the power-off handler powers off the system, select the default priority,
unless the power-off handler installation code suggests that there can be
more than one power-off handler and the new handler is only installed
conditionally. In this case, install the handler with low priority.

Cc: Ralf Baechle <[email protected]>
Cc: Maciej W. Rozycki <[email protected]>
Acked-by: Ralf Baechle <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use defines to specify poweroff handler priorities

arch/mips/alchemy/board-gpr.c | 3 ++-
arch/mips/alchemy/board-mtx1.c | 3 ++-
arch/mips/alchemy/board-xxs1500.c | 3 ++-
arch/mips/alchemy/devboards/platform.c | 14 ++++++++++++--
arch/mips/ar7/setup.c | 3 ++-
arch/mips/ath79/setup.c | 3 ++-
arch/mips/bcm47xx/setup.c | 3 ++-
arch/mips/bcm63xx/setup.c | 3 ++-
arch/mips/cobalt/setup.c | 3 ++-
arch/mips/dec/setup.c | 3 ++-
arch/mips/emma/markeins/setup.c | 3 ++-
arch/mips/jz4740/reset.c | 3 ++-
arch/mips/lantiq/falcon/reset.c | 3 ++-
arch/mips/lantiq/xway/reset.c | 3 ++-
arch/mips/lasat/reset.c | 3 ++-
arch/mips/loongson/common/reset.c | 3 ++-
arch/mips/loongson1/common/reset.c | 3 ++-
arch/mips/mti-malta/malta-reset.c | 3 ++-
arch/mips/mti-sead3/sead3-reset.c | 3 ++-
arch/mips/netlogic/xlp/setup.c | 3 ++-
arch/mips/netlogic/xlr/setup.c | 3 ++-
arch/mips/pmcs-msp71xx/msp_setup.c | 3 ++-
arch/mips/pnx833x/common/setup.c | 3 ++-
arch/mips/ralink/reset.c | 3 ++-
arch/mips/rb532/setup.c | 3 ++-
arch/mips/sgi-ip22/ip22-reset.c | 3 ++-
arch/mips/sgi-ip27/ip27-reset.c | 3 ++-
arch/mips/sgi-ip32/ip32-reset.c | 3 ++-
arch/mips/sibyte/common/cfe.c | 3 ++-
arch/mips/sni/setup.c | 3 ++-
arch/mips/txx9/generic/setup.c | 3 ++-
arch/mips/vr41xx/common/pmu.c | 3 ++-
32 files changed, 74 insertions(+), 33 deletions(-)

diff --git a/arch/mips/alchemy/board-gpr.c b/arch/mips/alchemy/board-gpr.c
index acf9a2a..abfc93a 100644
--- a/arch/mips/alchemy/board-gpr.c
+++ b/arch/mips/alchemy/board-gpr.c
@@ -89,7 +89,8 @@ void __init board_setup(void)
{
printk(KERN_INFO "Trapeze ITS GPR board\n");

- pm_power_off = gpr_power_off;
+ register_power_off_handler_simple(gpr_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);
_machine_halt = gpr_power_off;
_machine_restart = gpr_reset;

diff --git a/arch/mips/alchemy/board-mtx1.c b/arch/mips/alchemy/board-mtx1.c
index 1e3b102..a78df2c 100644
--- a/arch/mips/alchemy/board-mtx1.c
+++ b/arch/mips/alchemy/board-mtx1.c
@@ -98,7 +98,8 @@ void __init board_setup(void)
alchemy_gpio_direction_output(211, 1); /* green on */
alchemy_gpio_direction_output(212, 0); /* red off */

- pm_power_off = mtx1_power_off;
+ register_power_off_handler_simple(mtx1_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);
_machine_halt = mtx1_power_off;
_machine_restart = mtx1_reset;

diff --git a/arch/mips/alchemy/board-xxs1500.c b/arch/mips/alchemy/board-xxs1500.c
index 0fc53e0..6c413db 100644
--- a/arch/mips/alchemy/board-xxs1500.c
+++ b/arch/mips/alchemy/board-xxs1500.c
@@ -79,7 +79,8 @@ void __init board_setup(void)
{
u32 pin_func;

- pm_power_off = xxs1500_power_off;
+ register_power_off_handler_simple(xxs1500_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);
_machine_halt = xxs1500_power_off;
_machine_restart = xxs1500_reset;

diff --git a/arch/mips/alchemy/devboards/platform.c b/arch/mips/alchemy/devboards/platform.c
index be139a0..75eab8a 100644
--- a/arch/mips/alchemy/devboards/platform.c
+++ b/arch/mips/alchemy/devboards/platform.c
@@ -64,10 +64,20 @@ static void db1x_reset(char *c)
bcsr_write(BCSR_SYSTEM, 0);
}

+static void db1x_power_off_handler(struct power_off_handler_block *this)
+{
+ db1x_power_off();
+}
+
+static struct power_off_handler_block db1x_power_off_hb = {
+ .handler = db1x_power_off_handler,
+ .priority = POWER_OFF_PRIORITY_LOW,
+};
+
static int __init db1x_late_setup(void)
{
- if (!pm_power_off)
- pm_power_off = db1x_power_off;
+ if (register_power_off_handler(&db1x_power_off_hb))
+ pr_warn("dbx1: Failed to register power-off handler\n");
if (!_machine_halt)
_machine_halt = db1x_power_off;
if (!_machine_restart)
diff --git a/arch/mips/ar7/setup.c b/arch/mips/ar7/setup.c
index 820b7a3..7093266 100644
--- a/arch/mips/ar7/setup.c
+++ b/arch/mips/ar7/setup.c
@@ -91,7 +91,8 @@ void __init plat_mem_setup(void)

_machine_restart = ar7_machine_restart;
_machine_halt = ar7_machine_halt;
- pm_power_off = ar7_machine_power_off;
+ register_power_off_handler_simple(ar7_machine_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

io_base = (unsigned long)ioremap(AR7_REGS_BASE, 0x10000);
if (!io_base)
diff --git a/arch/mips/ath79/setup.c b/arch/mips/ath79/setup.c
index 64807a4..66fe138 100644
--- a/arch/mips/ath79/setup.c
+++ b/arch/mips/ath79/setup.c
@@ -203,7 +203,8 @@ void __init plat_mem_setup(void)

_machine_restart = ath79_restart;
_machine_halt = ath79_halt;
- pm_power_off = ath79_halt;
+ register_power_off_handler_simple(ath79_halt,
+ POWER_OFF_PRIORITY_FALLBACK);
}

void __init plat_time_init(void)
diff --git a/arch/mips/bcm47xx/setup.c b/arch/mips/bcm47xx/setup.c
index c00585d..d0a142c 100644
--- a/arch/mips/bcm47xx/setup.c
+++ b/arch/mips/bcm47xx/setup.c
@@ -246,7 +246,8 @@ void __init plat_mem_setup(void)

_machine_restart = bcm47xx_machine_restart;
_machine_halt = bcm47xx_machine_halt;
- pm_power_off = bcm47xx_machine_halt;
+ register_power_off_handler_simple(bcm47xx_machine_halt,
+ POWER_OFF_PRIORITY_FALLBACK);
bcm47xx_board_detect();
mips_set_machine_name(bcm47xx_board_get_name());
}
diff --git a/arch/mips/bcm63xx/setup.c b/arch/mips/bcm63xx/setup.c
index 6660c7d..5050a19 100644
--- a/arch/mips/bcm63xx/setup.c
+++ b/arch/mips/bcm63xx/setup.c
@@ -149,7 +149,8 @@ void __init plat_mem_setup(void)

_machine_halt = bcm63xx_machine_halt;
_machine_restart = __bcm63xx_machine_reboot;
- pm_power_off = bcm63xx_machine_halt;
+ register_power_off_handler_simple(bcm63xx_machine_halt,
+ POWER_OFF_PRIORITY_FALLBACK);

set_io_port_base(0);
ioport_resource.start = 0;
diff --git a/arch/mips/cobalt/setup.c b/arch/mips/cobalt/setup.c
index 9a8c2fe..527f331 100644
--- a/arch/mips/cobalt/setup.c
+++ b/arch/mips/cobalt/setup.c
@@ -78,7 +78,8 @@ void __init plat_mem_setup(void)

_machine_restart = cobalt_machine_restart;
_machine_halt = cobalt_machine_halt;
- pm_power_off = cobalt_machine_halt;
+ register_power_off_handler_simple(cobalt_machine_halt,
+ POWER_OFF_PRIORITY_FALLBACK);

set_io_port_base(CKSEG1ADDR(GT_DEF_PCI0_IO_BASE));

diff --git a/arch/mips/dec/setup.c b/arch/mips/dec/setup.c
index 41bbffd..b5d3200 100644
--- a/arch/mips/dec/setup.c
+++ b/arch/mips/dec/setup.c
@@ -158,7 +158,8 @@ void __init plat_mem_setup(void)

_machine_restart = dec_machine_restart;
_machine_halt = dec_machine_halt;
- pm_power_off = dec_machine_power_off;
+ register_power_off_handler_simple(dec_machine_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

ioport_resource.start = ~0UL;
ioport_resource.end = 0UL;
diff --git a/arch/mips/emma/markeins/setup.c b/arch/mips/emma/markeins/setup.c
index 9100122..4ea7ffb 100644
--- a/arch/mips/emma/markeins/setup.c
+++ b/arch/mips/emma/markeins/setup.c
@@ -103,7 +103,8 @@ void __init plat_mem_setup(void)

_machine_restart = markeins_machine_restart;
_machine_halt = markeins_machine_halt;
- pm_power_off = markeins_machine_power_off;
+ register_power_off_handler_simple(markeins_machine_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);

/* setup resource limits */
ioport_resource.start = EMMA2RH_PCI_IO_BASE;
diff --git a/arch/mips/jz4740/reset.c b/arch/mips/jz4740/reset.c
index b6c6343..157e0e2 100644
--- a/arch/mips/jz4740/reset.c
+++ b/arch/mips/jz4740/reset.c
@@ -114,5 +114,6 @@ void jz4740_reset_init(void)
{
_machine_restart = jz4740_restart;
_machine_halt = jz4740_halt;
- pm_power_off = jz4740_power_off;
+ register_power_off_handler_simple(jz4740_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
}
diff --git a/arch/mips/lantiq/falcon/reset.c b/arch/mips/lantiq/falcon/reset.c
index 5682482..7b60d36 100644
--- a/arch/mips/lantiq/falcon/reset.c
+++ b/arch/mips/lantiq/falcon/reset.c
@@ -83,7 +83,8 @@ static int __init mips_reboot_setup(void)
{
_machine_restart = machine_restart;
_machine_halt = machine_halt;
- pm_power_off = machine_power_off;
+ register_power_off_handler_simple(machine_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);
return 0;
}

diff --git a/arch/mips/lantiq/xway/reset.c b/arch/mips/lantiq/xway/reset.c
index 1fa0f17..9b37cc1 100644
--- a/arch/mips/lantiq/xway/reset.c
+++ b/arch/mips/lantiq/xway/reset.c
@@ -157,7 +157,8 @@ static int __init mips_reboot_setup(void)

_machine_restart = ltq_machine_restart;
_machine_halt = ltq_machine_halt;
- pm_power_off = ltq_machine_power_off;
+ register_power_off_handler_simple(ltq_machine_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);

return 0;
}
diff --git a/arch/mips/lasat/reset.c b/arch/mips/lasat/reset.c
index e21f0b9..91dab32 100644
--- a/arch/mips/lasat/reset.c
+++ b/arch/mips/lasat/reset.c
@@ -56,5 +56,6 @@ void lasat_reboot_setup(void)
{
_machine_restart = lasat_machine_restart;
_machine_halt = lasat_machine_halt;
- pm_power_off = lasat_machine_halt;
+ register_power_off_handler_simple(lasat_machine_halt,
+ POWER_OFF_PRIORITY_FALLBACK);
}
diff --git a/arch/mips/loongson/common/reset.c b/arch/mips/loongson/common/reset.c
index a60715e..32b2de8 100644
--- a/arch/mips/loongson/common/reset.c
+++ b/arch/mips/loongson/common/reset.c
@@ -84,7 +84,8 @@ static int __init mips_reboot_setup(void)
{
_machine_restart = loongson_restart;
_machine_halt = loongson_halt;
- pm_power_off = loongson_poweroff;
+ register_power_off_handler_simple(loongson_poweroff,
+ POWER_OFF_PRIORITY_DEFAULT);

return 0;
}
diff --git a/arch/mips/loongson1/common/reset.c b/arch/mips/loongson1/common/reset.c
index 547f34b..8a3cdd8 100644
--- a/arch/mips/loongson1/common/reset.c
+++ b/arch/mips/loongson1/common/reset.c
@@ -38,7 +38,8 @@ static int __init ls1x_reboot_setup(void)
{
_machine_restart = ls1x_restart;
_machine_halt = ls1x_halt;
- pm_power_off = ls1x_power_off;
+ register_power_off_handler_simple(ls1x_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);

return 0;
}
diff --git a/arch/mips/mti-malta/malta-reset.c b/arch/mips/mti-malta/malta-reset.c
index 2fd2cc2..2e4489f 100644
--- a/arch/mips/mti-malta/malta-reset.c
+++ b/arch/mips/mti-malta/malta-reset.c
@@ -40,7 +40,8 @@ static int __init mips_reboot_setup(void)
{
_machine_restart = mips_machine_restart;
_machine_halt = mips_machine_halt;
- pm_power_off = mips_machine_power_off;
+ register_power_off_handler_simple(mips_machine_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

return 0;
}
diff --git a/arch/mips/mti-sead3/sead3-reset.c b/arch/mips/mti-sead3/sead3-reset.c
index e6fb244..039aaf6 100644
--- a/arch/mips/mti-sead3/sead3-reset.c
+++ b/arch/mips/mti-sead3/sead3-reset.c
@@ -33,7 +33,8 @@ static int __init mips_reboot_setup(void)
{
_machine_restart = mips_machine_restart;
_machine_halt = mips_machine_halt;
- pm_power_off = mips_machine_halt;
+ register_power_off_handler_simple(mips_machine_halt,
+ POWER_OFF_PRIORITY_FALLBACK);

return 0;
}
diff --git a/arch/mips/netlogic/xlp/setup.c b/arch/mips/netlogic/xlp/setup.c
index 4fdd9fd..68529dd 100644
--- a/arch/mips/netlogic/xlp/setup.c
+++ b/arch/mips/netlogic/xlp/setup.c
@@ -106,7 +106,8 @@ void __init plat_mem_setup(void)
#endif
_machine_restart = (void (*)(char *))nlm_linux_exit;
_machine_halt = nlm_linux_exit;
- pm_power_off = nlm_linux_exit;
+ register_power_off_handler_simple(nlm_linux_exit,
+ POWER_OFF_PRIORITY_FALLBACK);

/* memory and bootargs from DT */
xlp_early_init_devtree();
diff --git a/arch/mips/netlogic/xlr/setup.c b/arch/mips/netlogic/xlr/setup.c
index d118b9a..898e950 100644
--- a/arch/mips/netlogic/xlr/setup.c
+++ b/arch/mips/netlogic/xlr/setup.c
@@ -75,7 +75,8 @@ void __init plat_mem_setup(void)
{
_machine_restart = (void (*)(char *))nlm_linux_exit;
_machine_halt = nlm_linux_exit;
- pm_power_off = nlm_linux_exit;
+ register_power_off_handler_simple(nlm_linux_exit,
+ POWER_OFF_PRIORITY_FALLBACK);
}

const char *get_system_type(void)
diff --git a/arch/mips/pmcs-msp71xx/msp_setup.c b/arch/mips/pmcs-msp71xx/msp_setup.c
index 4f925e0..a2b4722 100644
--- a/arch/mips/pmcs-msp71xx/msp_setup.c
+++ b/arch/mips/pmcs-msp71xx/msp_setup.c
@@ -144,7 +144,8 @@ void __init plat_mem_setup(void)
{
_machine_restart = msp_restart;
_machine_halt = msp_halt;
- pm_power_off = msp_power_off;
+ register_power_off_handler_simple(msp_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);
}

void __init prom_init(void)
diff --git a/arch/mips/pnx833x/common/setup.c b/arch/mips/pnx833x/common/setup.c
index 99b4d94..55f7a22 100644
--- a/arch/mips/pnx833x/common/setup.c
+++ b/arch/mips/pnx833x/common/setup.c
@@ -51,7 +51,8 @@ int __init plat_mem_setup(void)

_machine_restart = pnx833x_machine_restart;
_machine_halt = pnx833x_machine_halt;
- pm_power_off = pnx833x_machine_power_off;
+ register_power_off_handler_simple(pnx833x_machine_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

/* IO/MEM resources. */
set_io_port_base(KSEG1);
diff --git a/arch/mips/ralink/reset.c b/arch/mips/ralink/reset.c
index 55c7ec5..7b6dfdf3 100644
--- a/arch/mips/ralink/reset.c
+++ b/arch/mips/ralink/reset.c
@@ -98,7 +98,8 @@ static int __init mips_reboot_setup(void)
{
_machine_restart = ralink_restart;
_machine_halt = ralink_halt;
- pm_power_off = ralink_halt;
+ register_power_off_handler_simple(ralink_halt,
+ POWER_OFF_PRIORITY_FALLBACK);

return 0;
}
diff --git a/arch/mips/rb532/setup.c b/arch/mips/rb532/setup.c
index d0c64e7..1b95326b 100644
--- a/arch/mips/rb532/setup.c
+++ b/arch/mips/rb532/setup.c
@@ -44,7 +44,8 @@ void __init plat_mem_setup(void)

_machine_restart = rb_machine_restart;
_machine_halt = rb_machine_halt;
- pm_power_off = rb_machine_halt;
+ register_power_off_handler_simple(rb_machine_halt,
+ POWER_OFF_PRIORITY_FALLBACK);

set_io_port_base(KSEG1);

diff --git a/arch/mips/sgi-ip22/ip22-reset.c b/arch/mips/sgi-ip22/ip22-reset.c
index 063c2dd..ecd1970 100644
--- a/arch/mips/sgi-ip22/ip22-reset.c
+++ b/arch/mips/sgi-ip22/ip22-reset.c
@@ -188,7 +188,8 @@ static int __init reboot_setup(void)

_machine_restart = sgi_machine_restart;
_machine_halt = sgi_machine_halt;
- pm_power_off = sgi_machine_power_off;
+ register_power_off_handler_simple(sgi_machine_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

res = request_irq(SGI_PANEL_IRQ, panel_int, 0, "Front Panel", NULL);
if (res) {
diff --git a/arch/mips/sgi-ip27/ip27-reset.c b/arch/mips/sgi-ip27/ip27-reset.c
index ac37e54..e695975 100644
--- a/arch/mips/sgi-ip27/ip27-reset.c
+++ b/arch/mips/sgi-ip27/ip27-reset.c
@@ -76,5 +76,6 @@ void ip27_reboot_setup(void)
{
_machine_restart = ip27_machine_restart;
_machine_halt = ip27_machine_halt;
- pm_power_off = ip27_machine_power_off;
+ register_power_off_handler_simple(ip27_machine_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);
}
diff --git a/arch/mips/sgi-ip32/ip32-reset.c b/arch/mips/sgi-ip32/ip32-reset.c
index 1f823da..e3522fd 100644
--- a/arch/mips/sgi-ip32/ip32-reset.c
+++ b/arch/mips/sgi-ip32/ip32-reset.c
@@ -189,7 +189,8 @@ static __init int ip32_reboot_setup(void)

_machine_restart = ip32_machine_restart;
_machine_halt = ip32_machine_halt;
- pm_power_off = ip32_machine_power_off;
+ register_power_off_handler_simple(ip32_machine_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);

init_timer(&blink_timer);
blink_timer.function = blink_timeout;
diff --git a/arch/mips/sibyte/common/cfe.c b/arch/mips/sibyte/common/cfe.c
index 588e180..bf47de7 100644
--- a/arch/mips/sibyte/common/cfe.c
+++ b/arch/mips/sibyte/common/cfe.c
@@ -245,7 +245,8 @@ void __init prom_init(void)

_machine_restart = cfe_linux_restart;
_machine_halt = cfe_linux_halt;
- pm_power_off = cfe_linux_halt;
+ register_power_off_handler_simple(cfe_linux_halt,
+ POWER_OFF_PRIORITY_FALLBACK);

/*
* Check if a loader was used; if NOT, the 4 arguments are
diff --git a/arch/mips/sni/setup.c b/arch/mips/sni/setup.c
index efad85c..d278f0f 100644
--- a/arch/mips/sni/setup.c
+++ b/arch/mips/sni/setup.c
@@ -225,7 +225,8 @@ void __init plat_mem_setup(void)
}

_machine_restart = sni_machine_restart;
- pm_power_off = sni_machine_power_off;
+ register_power_off_handler_simple(sni_machine_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

sni_display_setup();
sni_console_setup();
diff --git a/arch/mips/txx9/generic/setup.c b/arch/mips/txx9/generic/setup.c
index 2791b86..cb48e06 100644
--- a/arch/mips/txx9/generic/setup.c
+++ b/arch/mips/txx9/generic/setup.c
@@ -555,7 +555,8 @@ void __init plat_mem_setup(void)
/* fallback restart/halt routines */
_machine_restart = (void (*)(char *))txx9_machine_halt;
_machine_halt = txx9_machine_halt;
- pm_power_off = txx9_machine_halt;
+ register_power_off_handler_simple(txx9_machine_halt,
+ POWER_OFF_PRIORITY_FALLBACK);

#ifdef CONFIG_PCI
pcibios_plat_setup = txx9_pcibios_setup;
diff --git a/arch/mips/vr41xx/common/pmu.c b/arch/mips/vr41xx/common/pmu.c
index d7f7558..cd9a20d 100644
--- a/arch/mips/vr41xx/common/pmu.c
+++ b/arch/mips/vr41xx/common/pmu.c
@@ -127,7 +127,8 @@ static int __init vr41xx_pmu_init(void)
cpu_wait = vr41xx_cpu_wait;
_machine_restart = vr41xx_restart;
_machine_halt = vr41xx_halt;
- pm_power_off = vr41xx_halt;
+ register_power_off_handler_simple(vr41xx_halt,
+ POWER_OFF_PRIORITY_FALLBACK);

return 0;
}
--
1.9.1

2014-11-06 16:50:01

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 36/48] arm64: psci: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly.

Cc: Catalin Marinas <[email protected]>
Cc: Will Deacon <[email protected]>
Acked-by: Catalin Marinas <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority

arch/arm64/kernel/psci.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/psci.c b/arch/arm64/kernel/psci.c
index 866c1c8..5cab066 100644
--- a/arch/arm64/kernel/psci.c
+++ b/arch/arm64/kernel/psci.c
@@ -359,7 +359,8 @@ static int __init psci_0_2_init(struct device_node *np)

arm_pm_restart = psci_sys_reset;

- pm_power_off = psci_sys_poweroff;
+ register_power_off_handler_simple(psci_sys_poweroff,
+ POWER_OFF_PRIORITY_DEFAULT);

out_put_node:
of_node_put(np);
--
1.9.1

2014-11-06 16:50:05

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 35/48] arm: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Always use register_power_off_handler_simple as there is no
indication that more than one power-off handler is registered.

If the power-off handler only resets the system or puts the CPU in sleep mode,
select the fallback priority to indicate that the power-off handler is one
of last resort. If the power-off handler powers off the system, select the
default priority.

Cc: Russell King <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use defines to specify poweroff handler priorities
- Drop changes in arch/arm/mach-at91/setup.c (file removed upstream)

arch/arm/kernel/psci.c | 3 ++-
arch/arm/mach-at91/board-gsia18s.c | 3 ++-
arch/arm/mach-bcm/board_bcm2835.c | 3 ++-
arch/arm/mach-cns3xxx/cns3420vb.c | 3 ++-
arch/arm/mach-cns3xxx/core.c | 3 ++-
arch/arm/mach-highbank/highbank.c | 3 ++-
arch/arm/mach-imx/mach-mx31moboard.c | 3 ++-
arch/arm/mach-iop32x/em7210.c | 3 ++-
arch/arm/mach-iop32x/glantank.c | 3 ++-
arch/arm/mach-iop32x/iq31244.c | 3 ++-
arch/arm/mach-iop32x/n2100.c | 3 ++-
arch/arm/mach-ixp4xx/dsmg600-setup.c | 3 ++-
arch/arm/mach-ixp4xx/nas100d-setup.c | 3 ++-
arch/arm/mach-ixp4xx/nslu2-setup.c | 3 ++-
arch/arm/mach-omap2/board-omap3touchbook.c | 3 ++-
arch/arm/mach-orion5x/board-mss2.c | 3 ++-
arch/arm/mach-orion5x/dns323-setup.c | 9 ++++++---
arch/arm/mach-orion5x/kurobox_pro-setup.c | 3 ++-
arch/arm/mach-orion5x/ls-chl-setup.c | 3 ++-
arch/arm/mach-orion5x/ls_hgl-setup.c | 3 ++-
arch/arm/mach-orion5x/lsmini-setup.c | 3 ++-
arch/arm/mach-orion5x/mv2120-setup.c | 3 ++-
arch/arm/mach-orion5x/net2big-setup.c | 3 ++-
arch/arm/mach-orion5x/terastation_pro2-setup.c | 3 ++-
arch/arm/mach-orion5x/ts209-setup.c | 3 ++-
arch/arm/mach-orion5x/ts409-setup.c | 3 ++-
arch/arm/mach-pxa/corgi.c | 3 ++-
arch/arm/mach-pxa/mioa701.c | 3 ++-
arch/arm/mach-pxa/poodle.c | 3 ++-
arch/arm/mach-pxa/spitz.c | 3 ++-
arch/arm/mach-pxa/tosa.c | 3 ++-
arch/arm/mach-pxa/viper.c | 3 ++-
arch/arm/mach-pxa/z2.c | 7 ++++---
arch/arm/mach-pxa/zeus.c | 7 ++++---
arch/arm/mach-s3c24xx/mach-gta02.c | 3 ++-
arch/arm/mach-s3c24xx/mach-jive.c | 3 ++-
arch/arm/mach-s3c24xx/mach-vr1000.c | 3 ++-
arch/arm/mach-s3c64xx/mach-smartq.c | 3 ++-
arch/arm/mach-sa1100/generic.c | 3 ++-
arch/arm/mach-sa1100/simpad.c | 3 ++-
arch/arm/mach-u300/regulator.c | 3 ++-
arch/arm/mach-vt8500/vt8500.c | 3 ++-
arch/arm/xen/enlighten.c | 3 ++-
43 files changed, 94 insertions(+), 49 deletions(-)

diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
index f73891b..a7a2b4a 100644
--- a/arch/arm/kernel/psci.c
+++ b/arch/arm/kernel/psci.c
@@ -264,7 +264,8 @@ static int psci_0_2_init(struct device_node *np)

arm_pm_restart = psci_sys_reset;

- pm_power_off = psci_sys_poweroff;
+ register_power_off_handler_simple(psci_sys_poweroff,
+ POWER_OFF_PRIORITY_DEFAULT);

out_put_node:
of_node_put(np);
diff --git a/arch/arm/mach-at91/board-gsia18s.c b/arch/arm/mach-at91/board-gsia18s.c
index bf5cc55..e628c4a 100644
--- a/arch/arm/mach-at91/board-gsia18s.c
+++ b/arch/arm/mach-at91/board-gsia18s.c
@@ -521,7 +521,8 @@ static void gsia18s_power_off(void)

static int __init gsia18s_power_off_init(void)
{
- pm_power_off = gsia18s_power_off;
+ register_power_off_handler_simple(gsia18s_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
return 0;
}

diff --git a/arch/arm/mach-bcm/board_bcm2835.c b/arch/arm/mach-bcm/board_bcm2835.c
index 70f2f39..1d75c76 100644
--- a/arch/arm/mach-bcm/board_bcm2835.c
+++ b/arch/arm/mach-bcm/board_bcm2835.c
@@ -111,7 +111,8 @@ static void __init bcm2835_init(void)

bcm2835_setup_restart();
if (wdt_regs)
- pm_power_off = bcm2835_power_off;
+ register_power_off_handler_simple(bcm2835_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);

bcm2835_init_clocks();

diff --git a/arch/arm/mach-cns3xxx/cns3420vb.c b/arch/arm/mach-cns3xxx/cns3420vb.c
index 6428bcc7..5c50461 100644
--- a/arch/arm/mach-cns3xxx/cns3420vb.c
+++ b/arch/arm/mach-cns3xxx/cns3420vb.c
@@ -224,7 +224,8 @@ static void __init cns3420_init(void)
cns3xxx_ahci_init();
cns3xxx_sdhci_init();

- pm_power_off = cns3xxx_power_off;
+ register_power_off_handler_simple(cns3xxx_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
}

static struct map_desc cns3420_io_desc[] __initdata = {
diff --git a/arch/arm/mach-cns3xxx/core.c b/arch/arm/mach-cns3xxx/core.c
index 4e9837d..9c214cf 100644
--- a/arch/arm/mach-cns3xxx/core.c
+++ b/arch/arm/mach-cns3xxx/core.c
@@ -386,7 +386,8 @@ static void __init cns3xxx_init(void)
cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(SDIO));
}

- pm_power_off = cns3xxx_power_off;
+ register_power_off_handler_simple(cns3xxx_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

of_platform_populate(NULL, of_default_bus_match_table,
cns3xxx_auxdata, NULL);
diff --git a/arch/arm/mach-highbank/highbank.c b/arch/arm/mach-highbank/highbank.c
index 07a0957..6fbdc01 100644
--- a/arch/arm/mach-highbank/highbank.c
+++ b/arch/arm/mach-highbank/highbank.c
@@ -155,7 +155,8 @@ static void __init highbank_init(void)
sregs_base = of_iomap(np, 0);
WARN_ON(!sregs_base);

- pm_power_off = highbank_power_off;
+ register_power_off_handler_simple(highbank_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);
highbank_pm_init();

bus_register_notifier(&platform_bus_type, &highbank_platform_nb);
diff --git a/arch/arm/mach-imx/mach-mx31moboard.c b/arch/arm/mach-imx/mach-mx31moboard.c
index bb6f8a5..3001b14 100644
--- a/arch/arm/mach-imx/mach-mx31moboard.c
+++ b/arch/arm/mach-imx/mach-mx31moboard.c
@@ -559,7 +559,8 @@ static void __init mx31moboard_init(void)

imx_add_platform_device("imx_mc13783", 0, NULL, 0, NULL, 0);

- pm_power_off = mx31moboard_poweroff;
+ register_power_off_handler_simple(mx31moboard_poweroff,
+ POWER_OFF_PRIORITY_DEFAULT);

switch (mx31moboard_baseboard) {
case MX31NOBOARD:
diff --git a/arch/arm/mach-iop32x/em7210.c b/arch/arm/mach-iop32x/em7210.c
index 77e1ff0..fd3ad09 100644
--- a/arch/arm/mach-iop32x/em7210.c
+++ b/arch/arm/mach-iop32x/em7210.c
@@ -201,7 +201,8 @@ static int __init em7210_request_gpios(void)
return 0;
}

- pm_power_off = em7210_power_off;
+ register_power_off_handler_simple(em7210_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

return 0;
}
diff --git a/arch/arm/mach-iop32x/glantank.c b/arch/arm/mach-iop32x/glantank.c
index 547b234..9298ea0 100644
--- a/arch/arm/mach-iop32x/glantank.c
+++ b/arch/arm/mach-iop32x/glantank.c
@@ -199,7 +199,8 @@ static void __init glantank_init_machine(void)
i2c_register_board_info(0, glantank_i2c_devices,
ARRAY_SIZE(glantank_i2c_devices));

- pm_power_off = glantank_power_off;
+ register_power_off_handler_simple(glantank_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
}

MACHINE_START(GLANTANK, "GLAN Tank")
diff --git a/arch/arm/mach-iop32x/iq31244.c b/arch/arm/mach-iop32x/iq31244.c
index 0e1392b..50ba54b 100644
--- a/arch/arm/mach-iop32x/iq31244.c
+++ b/arch/arm/mach-iop32x/iq31244.c
@@ -293,7 +293,8 @@ static void __init iq31244_init_machine(void)
platform_device_register(&iop3xx_dma_1_channel);

if (is_ep80219())
- pm_power_off = ep80219_power_off;
+ register_power_off_handler_simple(ep80219_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

if (!is_80219())
platform_device_register(&iop3xx_aau_channel);
diff --git a/arch/arm/mach-iop32x/n2100.c b/arch/arm/mach-iop32x/n2100.c
index c1cd80e..734a092 100644
--- a/arch/arm/mach-iop32x/n2100.c
+++ b/arch/arm/mach-iop32x/n2100.c
@@ -356,7 +356,8 @@ static void __init n2100_init_machine(void)
i2c_register_board_info(0, n2100_i2c_devices,
ARRAY_SIZE(n2100_i2c_devices));

- pm_power_off = n2100_power_off;
+ register_power_off_handler_simple(n2100_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
}

MACHINE_START(N2100, "Thecus N2100")
diff --git a/arch/arm/mach-ixp4xx/dsmg600-setup.c b/arch/arm/mach-ixp4xx/dsmg600-setup.c
index 43ee06d..f34564d 100644
--- a/arch/arm/mach-ixp4xx/dsmg600-setup.c
+++ b/arch/arm/mach-ixp4xx/dsmg600-setup.c
@@ -281,7 +281,8 @@ static void __init dsmg600_init(void)

platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));

- pm_power_off = dsmg600_power_off;
+ register_power_off_handler_simple(dsmg600_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
}

MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
diff --git a/arch/arm/mach-ixp4xx/nas100d-setup.c b/arch/arm/mach-ixp4xx/nas100d-setup.c
index 4e0f762..43a9333 100644
--- a/arch/arm/mach-ixp4xx/nas100d-setup.c
+++ b/arch/arm/mach-ixp4xx/nas100d-setup.c
@@ -292,7 +292,8 @@ static void __init nas100d_init(void)

platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices));

- pm_power_off = nas100d_power_off;
+ register_power_off_handler_simple(nas100d_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
IRQF_TRIGGER_LOW, "NAS100D reset button", NULL) < 0) {
diff --git a/arch/arm/mach-ixp4xx/nslu2-setup.c b/arch/arm/mach-ixp4xx/nslu2-setup.c
index 88c025f..e094d5f 100644
--- a/arch/arm/mach-ixp4xx/nslu2-setup.c
+++ b/arch/arm/mach-ixp4xx/nslu2-setup.c
@@ -262,7 +262,8 @@ static void __init nslu2_init(void)

platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices));

- pm_power_off = nslu2_power_off;
+ register_power_off_handler_simple(nslu2_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler,
IRQF_TRIGGER_LOW, "NSLU2 reset button", NULL) < 0) {
diff --git a/arch/arm/mach-omap2/board-omap3touchbook.c b/arch/arm/mach-omap2/board-omap3touchbook.c
index a01993e..8abce2c 100644
--- a/arch/arm/mach-omap2/board-omap3touchbook.c
+++ b/arch/arm/mach-omap2/board-omap3touchbook.c
@@ -344,7 +344,8 @@ static void __init omap3_touchbook_init(void)
{
omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);

- pm_power_off = omap3_touchbook_poweroff;
+ register_power_off_handler_simple(omap3_touchbook_poweroff,
+ POWER_OFF_PRIORITY_DEFAULT);

if (system_rev >= 0x20 && system_rev <= 0x34301000) {
omap_mux_init_gpio(23, OMAP_PIN_INPUT);
diff --git a/arch/arm/mach-orion5x/board-mss2.c b/arch/arm/mach-orion5x/board-mss2.c
index 66f9c3b..cac2793 100644
--- a/arch/arm/mach-orion5x/board-mss2.c
+++ b/arch/arm/mach-orion5x/board-mss2.c
@@ -86,5 +86,6 @@ static void mss2_power_off(void)
void __init mss2_init(void)
{
/* register mss2 specific power-off method */
- pm_power_off = mss2_power_off;
+ register_power_off_handler_simple(mss2_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);
}
diff --git a/arch/arm/mach-orion5x/dns323-setup.c b/arch/arm/mach-orion5x/dns323-setup.c
index 09d2a26..9876509 100644
--- a/arch/arm/mach-orion5x/dns323-setup.c
+++ b/arch/arm/mach-orion5x/dns323-setup.c
@@ -669,7 +669,8 @@ static void __init dns323_init(void)
if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
pr_err("DNS-323: failed to setup power-off GPIO\n");
- pm_power_off = dns323a_power_off;
+ register_power_off_handler_simple(dns323a_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
break;
case DNS323_REV_B1:
/* 5182 built-in SATA init */
@@ -686,7 +687,8 @@ static void __init dns323_init(void)
if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
pr_err("DNS-323: failed to setup power-off GPIO\n");
- pm_power_off = dns323b_power_off;
+ register_power_off_handler_simple(dns323b_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
break;
case DNS323_REV_C1:
/* 5182 built-in SATA init */
@@ -696,7 +698,8 @@ static void __init dns323_init(void)
if (gpio_request(DNS323C_GPIO_POWER_OFF, "POWEROFF") != 0 ||
gpio_direction_output(DNS323C_GPIO_POWER_OFF, 0) != 0)
pr_err("DNS-323: failed to setup power-off GPIO\n");
- pm_power_off = dns323c_power_off;
+ register_power_off_handler_simple(dns323c_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

/* Now, -this- should theorically be done by the sata_mv driver
* once I figure out what's going on there. Maybe the behaviour
diff --git a/arch/arm/mach-orion5x/kurobox_pro-setup.c b/arch/arm/mach-orion5x/kurobox_pro-setup.c
index fe6a48a..872d4fe 100644
--- a/arch/arm/mach-orion5x/kurobox_pro-setup.c
+++ b/arch/arm/mach-orion5x/kurobox_pro-setup.c
@@ -376,7 +376,8 @@ static void __init kurobox_pro_init(void)
i2c_register_board_info(0, &kurobox_pro_i2c_rtc, 1);

/* register Kurobox Pro specific power-off method */
- pm_power_off = kurobox_pro_power_off;
+ register_power_off_handler_simple(kurobox_pro_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
}

#ifdef CONFIG_MACH_KUROBOX_PRO
diff --git a/arch/arm/mach-orion5x/ls-chl-setup.c b/arch/arm/mach-orion5x/ls-chl-setup.c
index 028ea03..3f540d1 100644
--- a/arch/arm/mach-orion5x/ls-chl-setup.c
+++ b/arch/arm/mach-orion5x/ls-chl-setup.c
@@ -312,7 +312,8 @@ static void __init lschl_init(void)
gpio_set_value(LSCHL_GPIO_USB_POWER, 1);

/* register power-off method */
- pm_power_off = lschl_power_off;
+ register_power_off_handler_simple(lschl_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);

pr_info("%s: finished\n", __func__);
}
diff --git a/arch/arm/mach-orion5x/ls_hgl-setup.c b/arch/arm/mach-orion5x/ls_hgl-setup.c
index 32b7129..699a5a1 100644
--- a/arch/arm/mach-orion5x/ls_hgl-setup.c
+++ b/arch/arm/mach-orion5x/ls_hgl-setup.c
@@ -259,7 +259,8 @@ static void __init ls_hgl_init(void)
gpio_set_value(LS_HGL_GPIO_USB_POWER, 1);

/* register power-off method */
- pm_power_off = ls_hgl_power_off;
+ register_power_off_handler_simple(ls_hgl_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);

pr_info("%s: finished\n", __func__);
}
diff --git a/arch/arm/mach-orion5x/lsmini-setup.c b/arch/arm/mach-orion5x/lsmini-setup.c
index a6493e7..c5712ff 100644
--- a/arch/arm/mach-orion5x/lsmini-setup.c
+++ b/arch/arm/mach-orion5x/lsmini-setup.c
@@ -260,7 +260,8 @@ static void __init lsmini_init(void)
gpio_set_value(LSMINI_GPIO_USB_POWER, 1);

/* register power-off method */
- pm_power_off = lsmini_power_off;
+ register_power_off_handler_simple(lsmini_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);

pr_info("%s: finished\n", __func__);
}
diff --git a/arch/arm/mach-orion5x/mv2120-setup.c b/arch/arm/mach-orion5x/mv2120-setup.c
index e032f01..13efbec 100644
--- a/arch/arm/mach-orion5x/mv2120-setup.c
+++ b/arch/arm/mach-orion5x/mv2120-setup.c
@@ -225,7 +225,8 @@ static void __init mv2120_init(void)
if (gpio_request(MV2120_GPIO_POWER_OFF, "POWEROFF") != 0 ||
gpio_direction_output(MV2120_GPIO_POWER_OFF, 1) != 0)
pr_err("mv2120: failed to setup power-off GPIO\n");
- pm_power_off = mv2120_power_off;
+ register_power_off_handler_simple(mv2120_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
}

/* Warning: HP uses a wrong mach-type (=526) in their bootloader */
diff --git a/arch/arm/mach-orion5x/net2big-setup.c b/arch/arm/mach-orion5x/net2big-setup.c
index ba73dc7..c7648f0 100644
--- a/arch/arm/mach-orion5x/net2big-setup.c
+++ b/arch/arm/mach-orion5x/net2big-setup.c
@@ -413,7 +413,8 @@ static void __init net2big_init(void)

if (gpio_request(NET2BIG_GPIO_POWER_OFF, "power-off") == 0 &&
gpio_direction_output(NET2BIG_GPIO_POWER_OFF, 0) == 0)
- pm_power_off = net2big_power_off;
+ register_power_off_handler_simple(net2big_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
else
pr_err("net2big: failed to configure power-off GPIO\n");

diff --git a/arch/arm/mach-orion5x/terastation_pro2-setup.c b/arch/arm/mach-orion5x/terastation_pro2-setup.c
index 1208674..227ae91 100644
--- a/arch/arm/mach-orion5x/terastation_pro2-setup.c
+++ b/arch/arm/mach-orion5x/terastation_pro2-setup.c
@@ -353,7 +353,8 @@ static void __init tsp2_init(void)
i2c_register_board_info(0, &tsp2_i2c_rtc, 1);

/* register Terastation Pro II specific power-off method */
- pm_power_off = tsp2_power_off;
+ register_power_off_handler_simple(tsp2_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
}

MACHINE_START(TERASTATION_PRO2, "Buffalo Terastation Pro II/Live")
diff --git a/arch/arm/mach-orion5x/ts209-setup.c b/arch/arm/mach-orion5x/ts209-setup.c
index c725b7c..540e3f3 100644
--- a/arch/arm/mach-orion5x/ts209-setup.c
+++ b/arch/arm/mach-orion5x/ts209-setup.c
@@ -318,7 +318,8 @@ static void __init qnap_ts209_init(void)
i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1);

/* register tsx09 specific power-off method */
- pm_power_off = qnap_tsx09_power_off;
+ register_power_off_handler_simple(qnap_tsx09_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
}

MACHINE_START(TS209, "QNAP TS-109/TS-209")
diff --git a/arch/arm/mach-orion5x/ts409-setup.c b/arch/arm/mach-orion5x/ts409-setup.c
index cf2ab53..40cbdd7 100644
--- a/arch/arm/mach-orion5x/ts409-setup.c
+++ b/arch/arm/mach-orion5x/ts409-setup.c
@@ -307,7 +307,8 @@ static void __init qnap_ts409_init(void)
platform_device_register(&ts409_leds);

/* register tsx09 specific power-off method */
- pm_power_off = qnap_tsx09_power_off;
+ register_power_off_handler_simple(qnap_tsx09_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
}

MACHINE_START(TS409, "QNAP TS-409")
diff --git a/arch/arm/mach-pxa/corgi.c b/arch/arm/mach-pxa/corgi.c
index 06022b2..93b73a1 100644
--- a/arch/arm/mach-pxa/corgi.c
+++ b/arch/arm/mach-pxa/corgi.c
@@ -718,7 +718,8 @@ static void corgi_restart(enum reboot_mode mode, const char *cmd)

static void __init corgi_init(void)
{
- pm_power_off = corgi_poweroff;
+ register_power_off_handler_simple(corgi_poweroff,
+ POWER_OFF_PRIORITY_FALLBACK);

/* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
PCFR |= PCFR_OPDE;
diff --git a/arch/arm/mach-pxa/mioa701.c b/arch/arm/mach-pxa/mioa701.c
index 29997bd..5d318d4 100644
--- a/arch/arm/mach-pxa/mioa701.c
+++ b/arch/arm/mach-pxa/mioa701.c
@@ -750,7 +750,8 @@ static void __init mioa701_machine_init(void)
pxa_set_keypad_info(&mioa701_keypad_info);
pxa_set_udc_info(&mioa701_udc_info);
pxa_set_ac97_info(&mioa701_ac97_info);
- pm_power_off = mioa701_poweroff;
+ register_power_off_handler_simple(mioa701_poweroff,
+ POWER_OFF_PRIORITY_FALLBACK);
platform_add_devices(devices, ARRAY_SIZE(devices));
gsm_init();

diff --git a/arch/arm/mach-pxa/poodle.c b/arch/arm/mach-pxa/poodle.c
index 1319916..749d2af 100644
--- a/arch/arm/mach-pxa/poodle.c
+++ b/arch/arm/mach-pxa/poodle.c
@@ -432,7 +432,8 @@ static void __init poodle_init(void)
{
int ret = 0;

- pm_power_off = poodle_poweroff;
+ register_power_off_handler_simple(poodle_poweroff,
+ POWER_OFF_PRIORITY_FALLBACK);

PCFR |= PCFR_OPDE;

diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c
index 840c3a4..ab25b6c 100644
--- a/arch/arm/mach-pxa/spitz.c
+++ b/arch/arm/mach-pxa/spitz.c
@@ -944,7 +944,8 @@ static void spitz_restart(enum reboot_mode mode, const char *cmd)
static void __init spitz_init(void)
{
init_gpio_reset(SPITZ_GPIO_ON_RESET, 1, 0);
- pm_power_off = spitz_poweroff;
+ register_power_off_handler_simple(spitz_poweroff,
+ POWER_OFF_PRIORITY_FALLBACK);

PMCR = 0x00;

diff --git a/arch/arm/mach-pxa/tosa.c b/arch/arm/mach-pxa/tosa.c
index c158a6e..8823448 100644
--- a/arch/arm/mach-pxa/tosa.c
+++ b/arch/arm/mach-pxa/tosa.c
@@ -940,7 +940,8 @@ static void __init tosa_init(void)

init_gpio_reset(TOSA_GPIO_ON_RESET, 0, 0);

- pm_power_off = tosa_poweroff;
+ register_power_off_handler_simple(tosa_poweroff,
+ POWER_OFF_PRIORITY_FALLBACK);

PCFR |= PCFR_OPDE;

diff --git a/arch/arm/mach-pxa/viper.c b/arch/arm/mach-pxa/viper.c
index de3b080..6bb4de3 100644
--- a/arch/arm/mach-pxa/viper.c
+++ b/arch/arm/mach-pxa/viper.c
@@ -919,7 +919,8 @@ static void __init viper_init(void)
{
u8 version;

- pm_power_off = viper_power_off;
+ register_power_off_handler_simple(viper_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

pxa2xx_mfp_config(ARRAY_AND_SIZE(viper_pin_config));

diff --git a/arch/arm/mach-pxa/z2.c b/arch/arm/mach-pxa/z2.c
index e1a121b..0d0a6ae 100644
--- a/arch/arm/mach-pxa/z2.c
+++ b/arch/arm/mach-pxa/z2.c
@@ -693,8 +693,6 @@ static void z2_power_off(void)
pxa27x_set_pwrmode(PWRMODE_DEEPSLEEP);
pxa27x_cpu_pm_enter(PM_SUSPEND_MEM);
}
-#else
-#define z2_power_off NULL
#endif

/******************************************************************************
@@ -719,7 +717,10 @@ static void __init z2_init(void)
z2_keys_init();
z2_pmic_init();

- pm_power_off = z2_power_off;
+#ifdef CONFIG_PM
+ register_power_off_handler_simple(z2_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);
+#endif
}

MACHINE_START(ZIPIT2, "Zipit Z2")
diff --git a/arch/arm/mach-pxa/zeus.c b/arch/arm/mach-pxa/zeus.c
index 205f9bf..457eed1 100644
--- a/arch/arm/mach-pxa/zeus.c
+++ b/arch/arm/mach-pxa/zeus.c
@@ -690,8 +690,6 @@ static void zeus_power_off(void)
local_irq_disable();
cpu_suspend(PWRMODE_DEEPSLEEP, pxa27x_finish_suspend);
}
-#else
-#define zeus_power_off NULL
#endif

#ifdef CONFIG_APM_EMULATION
@@ -847,7 +845,10 @@ static void __init zeus_init(void)
__raw_writel(msc0, MSC0);
__raw_writel(msc1, MSC1);

- pm_power_off = zeus_power_off;
+#ifdef CONFIG_PM
+ register_power_off_handler_simple(zeus_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);
+#endif
zeus_setup_apm();

pxa2xx_mfp_config(ARRAY_AND_SIZE(zeus_pin_config));
diff --git a/arch/arm/mach-s3c24xx/mach-gta02.c b/arch/arm/mach-s3c24xx/mach-gta02.c
index 6d1e0b9..8366b3e 100644
--- a/arch/arm/mach-s3c24xx/mach-gta02.c
+++ b/arch/arm/mach-s3c24xx/mach-gta02.c
@@ -579,7 +579,8 @@ static void __init gta02_machine_init(void)
i2c_register_board_info(0, gta02_i2c_devs, ARRAY_SIZE(gta02_i2c_devs));

platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
- pm_power_off = gta02_poweroff;
+ register_power_off_handler_simple(gta02_poweroff,
+ POWER_OFF_PRIORITY_DEFAULT);

regulator_has_full_constraints();
}
diff --git a/arch/arm/mach-s3c24xx/mach-jive.c b/arch/arm/mach-s3c24xx/mach-jive.c
index 7d99fe8..20beb39 100644
--- a/arch/arm/mach-s3c24xx/mach-jive.c
+++ b/arch/arm/mach-s3c24xx/mach-jive.c
@@ -657,7 +657,8 @@ static void __init jive_machine_init(void)
s3c_i2c0_set_platdata(&jive_i2c_cfg);
i2c_register_board_info(0, jive_i2c_devs, ARRAY_SIZE(jive_i2c_devs));

- pm_power_off = jive_power_off;
+ register_power_off_handler_simple(jive_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

platform_add_devices(jive_devices, ARRAY_SIZE(jive_devices));
}
diff --git a/arch/arm/mach-s3c24xx/mach-vr1000.c b/arch/arm/mach-s3c24xx/mach-vr1000.c
index 89f32bd..1f32ba7 100644
--- a/arch/arm/mach-s3c24xx/mach-vr1000.c
+++ b/arch/arm/mach-s3c24xx/mach-vr1000.c
@@ -306,7 +306,8 @@ static void vr1000_power_off(void)

static void __init vr1000_map_io(void)
{
- pm_power_off = vr1000_power_off;
+ register_power_off_handler_simple(vr1000_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

s3c24xx_init_io(vr1000_iodesc, ARRAY_SIZE(vr1000_iodesc));
s3c24xx_init_uarts(vr1000_uartcfgs, ARRAY_SIZE(vr1000_uartcfgs));
diff --git a/arch/arm/mach-s3c64xx/mach-smartq.c b/arch/arm/mach-s3c64xx/mach-smartq.c
index b3d1353..b30906f 100644
--- a/arch/arm/mach-s3c64xx/mach-smartq.c
+++ b/arch/arm/mach-s3c64xx/mach-smartq.c
@@ -291,7 +291,8 @@ static int __init smartq_power_off_init(void)
/* leave power on */
gpio_direction_output(S3C64XX_GPK(15), 0);

- pm_power_off = smartq_power_off;
+ register_power_off_handler_simple(smartq_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);

return ret;
}
diff --git a/arch/arm/mach-sa1100/generic.c b/arch/arm/mach-sa1100/generic.c
index d4ea142..371bffe 100644
--- a/arch/arm/mach-sa1100/generic.c
+++ b/arch/arm/mach-sa1100/generic.c
@@ -311,7 +311,8 @@ static struct platform_device *sa11x0_devices[] __initdata = {

static int __init sa1100_init(void)
{
- pm_power_off = sa1100_power_off;
+ register_power_off_handler_simple(sa1100_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);
return platform_add_devices(sa11x0_devices, ARRAY_SIZE(sa11x0_devices));
}

diff --git a/arch/arm/mach-sa1100/simpad.c b/arch/arm/mach-sa1100/simpad.c
index 41e476e..fb85730 100644
--- a/arch/arm/mach-sa1100/simpad.c
+++ b/arch/arm/mach-sa1100/simpad.c
@@ -373,7 +373,8 @@ static int __init simpad_init(void)
if (ret)
printk(KERN_WARNING "simpad: Unable to register cs3 GPIO device");

- pm_power_off = simpad_power_off;
+ register_power_off_handler_simple(simpad_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);

sa11x0_ppc_configure_mcp();
sa11x0_register_mtd(&simpad_flash_data, simpad_flash_resources,
diff --git a/arch/arm/mach-u300/regulator.c b/arch/arm/mach-u300/regulator.c
index 0493a84..4ff09b0 100644
--- a/arch/arm/mach-u300/regulator.c
+++ b/arch/arm/mach-u300/regulator.c
@@ -98,7 +98,8 @@ static int __init __u300_init_boardpower(struct platform_device *pdev)
U300_SYSCON_PMCR_DCON_ENABLE, 0);

/* Register globally exported PM poweroff hook */
- pm_power_off = u300_pm_poweroff;
+ register_power_off_handler_simple(u300_pm_poweroff,
+ POWER_OFF_PRIORITY_DEFAULT);

return 0;
}
diff --git a/arch/arm/mach-vt8500/vt8500.c b/arch/arm/mach-vt8500/vt8500.c
index 3bc0dc9..48e4fbf 100644
--- a/arch/arm/mach-vt8500/vt8500.c
+++ b/arch/arm/mach-vt8500/vt8500.c
@@ -155,7 +155,8 @@ static void __init vt8500_init(void)
pr_err("%s:ioremap(power_off) failed\n", __func__);
}
if (pmc_base)
- pm_power_off = &vt8500_power_off;
+ register_power_off_handler_simple(vt8500_power_off,
+ POWER_OFF_PRIORITY_FALLBACK);
else
pr_err("%s: PMC Hibernation register could not be remapped, not enabling power off!\n", __func__);

diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
index 0e15f01..1c8bce0 100644
--- a/arch/arm/xen/enlighten.c
+++ b/arch/arm/xen/enlighten.c
@@ -336,7 +336,8 @@ static int __init xen_pm_init(void)
if (!xen_domain())
return -ENODEV;

- pm_power_off = xen_power_off;
+ register_power_off_handler_simple(xen_power_off,
+ POWER_OFF_PRIORITY_DEFAULT);
arm_pm_restart = xen_restart;

return 0;
--
1.9.1

2014-11-06 16:45:00

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 29/48] power/reset: ltc2952-poweroff: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the original code
sets pm_power_off only if it was not already set.

Acked-by: Sebastian Reichel <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Added patch

drivers/power/reset/ltc2952-poweroff.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/power/reset/ltc2952-poweroff.c b/drivers/power/reset/ltc2952-poweroff.c
index 116a1ce..e622824 100644
--- a/drivers/power/reset/ltc2952-poweroff.c
+++ b/drivers/power/reset/ltc2952-poweroff.c
@@ -80,6 +80,8 @@ struct ltc2952_poweroff_data {
* 2: kill
*/
struct gpio_desc *gpio[3];
+
+ struct power_off_handler_block power_off_hb;
};

static int ltc2952_poweroff_panic;
@@ -180,7 +182,8 @@ irq_ok:
return IRQ_HANDLED;
}

-static void ltc2952_poweroff_kill(void)
+static void ltc2952_poweroff_kill(struct power_off_handler_block *this)
+
{
gpiod_set_value(ltc2952_data->gpio[POWERPATH_IO_KILL], 1);
}
@@ -285,12 +288,7 @@ err_io:

static int ltc2952_poweroff_probe(struct platform_device *pdev)
{
- int ret;
-
- if (pm_power_off) {
- dev_err(&pdev->dev, "pm_power_off already registered");
- return -EBUSY;
- }
+ int i, ret;

ltc2952_data = kzalloc(sizeof(*ltc2952_data), GFP_KERNEL);
if (!ltc2952_data)
@@ -302,12 +300,20 @@ static int ltc2952_poweroff_probe(struct platform_device *pdev)
if (ret)
goto err;

- pm_power_off = &ltc2952_poweroff_kill;
+ ltc2952_data->power_off_hb.handler = ltc2952_poweroff_kill;
+ ltc2952_data->power_off_hb.priority = POWER_OFF_PRIORITY_LOW;
+ ret = register_power_off_handler(&ltc2952_data->power_off_hb);
+ if (ret)
+ goto err_power;

dev_info(&pdev->dev, "probe successful\n");

return 0;

+err_power:
+ free_irq(ltc2952_data->virq, ltc2952_data);
+ for (i = 0; i < ARRAY_SIZE(ltc2952_data->gpio); i++)
+ gpiod_put(ltc2952_data->gpio[i]);
err:
kfree(ltc2952_data);
return ret;
@@ -317,7 +323,7 @@ static int ltc2952_poweroff_remove(struct platform_device *pdev)
{
unsigned int i;

- pm_power_off = NULL;
+ unregister_power_off_handler(&ltc2952_data->power_off_hb);

if (ltc2952_data) {
free_irq(ltc2952_data->virq, ltc2952_data);
--
1.9.1

2014-11-06 16:51:11

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 34/48] acpi: Register power-off handler with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with high priority to reflect that the driver explicitly
overrides existing power-off handlers.

Cc: Rafael J. Wysocki <[email protected]>
Cc: Len Brown <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
- Replace acpi: with ACPI: in log message
v2:
- Use define to specify poweroff handler priority
- Use pr_warn instead of pr_err

drivers/acpi/sleep.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 05a31b5..a73cfad 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -16,6 +16,7 @@
#include <linux/device.h>
#include <linux/interrupt.h>
#include <linux/suspend.h>
+#include <linux/pm.h>
#include <linux/reboot.h>
#include <linux/acpi.h>
#include <linux/module.h>
@@ -827,7 +828,7 @@ static void acpi_power_off_prepare(void)
acpi_disable_all_gpes();
}

-static void acpi_power_off(void)
+static void acpi_power_off(struct power_off_handler_block *this)
{
/* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
printk(KERN_DEBUG "%s called\n", __func__);
@@ -835,6 +836,11 @@ static void acpi_power_off(void)
acpi_enter_sleep_state(ACPI_STATE_S5);
}

+static struct power_off_handler_block acpi_power_off_hb = {
+ .handler = acpi_power_off,
+ .priority = POWER_OFF_PRIORITY_HIGH,
+};
+
int __init acpi_sleep_init(void)
{
char supported[ACPI_S_STATE_COUNT * 3 + 1];
@@ -851,7 +857,8 @@ int __init acpi_sleep_init(void)
if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
sleep_states[ACPI_STATE_S5] = 1;
pm_power_off_prepare = acpi_power_off_prepare;
- pm_power_off = acpi_power_off;
+ if (register_power_off_handler(&acpi_power_off_hb))
+ pr_warn("ACPI: Failed to register power-off handler\n");
}

supported[0] = 0;
--
1.9.1

2014-11-06 16:51:51

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 31/48] x86: apm: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with high priority to reflect that the original code
overwrites existing power-off handlers.

Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Jiri Kosina <[email protected]>
Acked-by: Thomas Gleixner <[email protected]>
Reviewed-by: Jiri Kosina <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority

arch/x86/kernel/apm_32.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
index 5848744..04910de 100644
--- a/arch/x86/kernel/apm_32.c
+++ b/arch/x86/kernel/apm_32.c
@@ -981,7 +981,7 @@ recalc:
* on their first cpu.
*/

-static void apm_power_off(void)
+static void apm_power_off(struct power_off_handler_block *this)
{
/* Some bioses don't like being called from CPU != 0 */
if (apm_info.realmode_power_off) {
@@ -992,6 +992,11 @@ static void apm_power_off(void)
}
}

+static struct power_off_handler_block apm_power_off_hb = {
+ .handler = apm_power_off,
+ .priority = POWER_OFF_PRIORITY_HIGH,
+};
+
#ifdef CONFIG_APM_DO_ENABLE

/**
@@ -1847,8 +1852,11 @@ static int apm(void *unused)
}

/* Install our power off handler.. */
- if (power_off)
- pm_power_off = apm_power_off;
+ if (power_off) {
+ error = register_power_off_handler(&apm_power_off_hb);
+ if (error)
+ pr_warn("apm: Failed to register power-off handler\n");
+ }

if (num_online_cpus() == 1 || smp) {
#if defined(CONFIG_APM_DISPLAY_BLANK) && defined(CONFIG_VT)
@@ -2408,9 +2416,8 @@ static void __exit apm_exit(void)
apm_error("disengage power management", error);
}
misc_deregister(&apm_device);
+ unregister_power_off_handler(&apm_power_off_hb);
remove_proc_entry("apm", NULL);
- if (power_off)
- pm_power_off = NULL;
if (kapmd_task) {
kthread_stop(kapmd_task);
kapmd_task = NULL;
--
1.9.1

2014-11-06 16:51:56

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 30/48] x86: iris: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with high priority to reflect that the original code
overwrites existing power-off handlers.

Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Acked-by: Thomas Gleixner <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler

arch/x86/platform/iris/iris.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/arch/x86/platform/iris/iris.c b/arch/x86/platform/iris/iris.c
index 4d171e8..7152814 100644
--- a/arch/x86/platform/iris/iris.c
+++ b/arch/x86/platform/iris/iris.c
@@ -47,15 +47,18 @@ static bool force;
module_param(force, bool, 0);
MODULE_PARM_DESC(force, "Set to one to force poweroff handler installation.");

-static void (*old_pm_power_off)(void);
-
-static void iris_power_off(void)
+static void iris_power_off(struct power_off_handler_block *this)
{
outb(IRIS_GIO_PULSE, IRIS_GIO_OUTPUT);
msleep(850);
outb(IRIS_GIO_REST, IRIS_GIO_OUTPUT);
}

+static struct power_off_handler_block iris_power_off_hb = {
+ .handler = iris_power_off,
+ .priority = POWER_OFF_PRIORITY_HIGH,
+};
+
/*
* Before installing the power_off handler, try to make sure the OS is
* running on an Iris. Since Iris does not support DMI, this is done
@@ -65,20 +68,25 @@ static void iris_power_off(void)
static int iris_probe(struct platform_device *pdev)
{
unsigned char status = inb(IRIS_GIO_INPUT);
+ int ret;
+
if (status == IRIS_GIO_NODEV) {
printk(KERN_ERR "This machine does not seem to be an Iris. "
"Power off handler not installed.\n");
return -ENODEV;
}
- old_pm_power_off = pm_power_off;
- pm_power_off = &iris_power_off;
+
+ ret = devm_register_power_off_handler(&pdev->dev, &iris_power_off_hb);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to register power-off handler\n");
+ return ret;
+ }
printk(KERN_INFO "Iris power_off handler installed.\n");
return 0;
}

static int iris_remove(struct platform_device *pdev)
{
- pm_power_off = old_pm_power_off;
printk(KERN_INFO "Iris power_off handler uninstalled.\n");
return 0;
}
--
1.9.1

2014-11-06 16:44:48

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 23/48] power/reset: gpio-poweroff: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the original code
only sets pm_power_off if it was not already set.

Other changes:

Drop note that there can not be an additional instance of this driver.
The original reason no longer applies, it should be obvious that there
can only be one instance of the driver if static variables are used to
reflect its state, and support for multiple instances can now be added
easily if needed by avoiding static variables.

Do not create an error message if another power-off handler has already
been registered. This is perfectly normal and acceptable.

Drop remove function since it is no longer needed.

Cc: Sebastian Reichel <[email protected]>
Cc: Dmitry Eremin-Solenikov <[email protected]>
Cc: David Woodhouse <[email protected]>
Acked-by: Andrew Lunn <[email protected]>
Acked-by: Sebastian Reichel <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2;
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler
- Drop remove function as it is no longer needed

drivers/power/reset/gpio-poweroff.c | 36 +++++++++++++-----------------------
1 file changed, 13 insertions(+), 23 deletions(-)

diff --git a/drivers/power/reset/gpio-poweroff.c b/drivers/power/reset/gpio-poweroff.c
index ce849bc..4d480d2 100644
--- a/drivers/power/reset/gpio-poweroff.c
+++ b/drivers/power/reset/gpio-poweroff.c
@@ -14,18 +14,16 @@
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/delay.h>
+#include <linux/pm.h>
#include <linux/platform_device.h>
#include <linux/gpio/consumer.h>
#include <linux/of_platform.h>
#include <linux/module.h>

-/*
- * Hold configuration here, cannot be more than one instance of the driver
- * since pm_power_off itself is global.
- */
static struct gpio_desc *reset_gpio;

-static void gpio_poweroff_do_poweroff(void)
+static void gpio_poweroff_do_poweroff(struct power_off_handler_block *this)
+
{
BUG_ON(!reset_gpio);

@@ -45,17 +43,15 @@ static void gpio_poweroff_do_poweroff(void)
WARN_ON(1);
}

+static struct power_off_handler_block gpio_power_off_hb = {
+ .handler = gpio_poweroff_do_poweroff,
+ .priority = POWER_OFF_PRIORITY_LOW,
+};
+
static int gpio_poweroff_probe(struct platform_device *pdev)
{
bool input = false;
-
- /* If a pm_power_off function has already been added, leave it alone */
- if (pm_power_off != NULL) {
- dev_err(&pdev->dev,
- "%s: pm_power_off function already registered",
- __func__);
- return -EBUSY;
- }
+ int err;

reset_gpio = devm_gpiod_get(&pdev->dev, NULL);
if (IS_ERR(reset_gpio))
@@ -77,16 +73,11 @@ static int gpio_poweroff_probe(struct platform_device *pdev)
}
}

- pm_power_off = &gpio_poweroff_do_poweroff;
- return 0;
-}
-
-static int gpio_poweroff_remove(struct platform_device *pdev)
-{
- if (pm_power_off == &gpio_poweroff_do_poweroff)
- pm_power_off = NULL;
+ err = devm_register_power_off_handler(&pdev->dev, &gpio_power_off_hb);
+ if (err)
+ dev_err(&pdev->dev, "Failed to register power-off handler\n");

- return 0;
+ return err;
}

static const struct of_device_id of_gpio_poweroff_match[] = {
@@ -96,7 +87,6 @@ static const struct of_device_id of_gpio_poweroff_match[] = {

static struct platform_driver gpio_poweroff_driver = {
.probe = gpio_poweroff_probe,
- .remove = gpio_poweroff_remove,
.driver = {
.name = "poweroff-gpio",
.owner = THIS_MODULE,
--
1.9.1

2014-11-06 16:55:35

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 28/48] power/reset: at91-poweroff: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Select default priority to reflect that the original code sets
pm_power_off unconditionally.

Acked-by: Sebastian Reichel <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Added patch

drivers/power/reset/at91-poweroff.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/power/reset/at91-poweroff.c b/drivers/power/reset/at91-poweroff.c
index c610003..6fc5944 100644
--- a/drivers/power/reset/at91-poweroff.c
+++ b/drivers/power/reset/at91-poweroff.c
@@ -14,6 +14,7 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
+#include <linux/pm.h>
#include <linux/printk.h>

#define AT91_SHDW_CR 0x00 /* Shut Down Control Register */
@@ -66,11 +67,16 @@ static void __init at91_wakeup_status(void)
pr_info("AT91: Wake-Up source: %s\n", reason);
}

-static void at91_poweroff(void)
+static void at91_poweroff(struct power_off_handler_block *this)
{
writel(AT91_SHDW_KEY | AT91_SHDW_SHDW, at91_shdwc_base + AT91_SHDW_CR);
}

+static struct power_off_handler_block at91_power_off_hb = {
+ .handler = at91_poweroff,
+ .priority = POWER_OFF_PRIORITY_DEFAULT,
+};
+
const enum wakeup_type at91_poweroff_get_wakeup_mode(struct device_node *np)
{
const char *pm;
@@ -134,9 +140,7 @@ static int at91_poweroff_probe(struct platform_device *pdev)
if (pdev->dev.of_node)
at91_poweroff_dt_set_wakeup_mode(pdev);

- pm_power_off = at91_poweroff;
-
- return 0;
+ return devm_register_power_off_handler(&pdev->dev, &at91_power_off_hb);
}

static struct of_device_id at91_poweroff_of_match[] = {
--
1.9.1

2014-11-06 16:57:00

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 26/48] power/reset: msm-poweroff: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Select fallback priority since the code does not really poweroff
the system but resets it instead.

Acked-by: Sebastian Reichel <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Fix headline and description
- Merge with restart handler code now used in same driver
- Use dev_warn instead of dev_err

drivers/power/reset/msm-poweroff.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/power/reset/msm-poweroff.c b/drivers/power/reset/msm-poweroff.c
index 4702efd..822f358 100644
--- a/drivers/power/reset/msm-poweroff.c
+++ b/drivers/power/reset/msm-poweroff.c
@@ -23,11 +23,17 @@
#include <linux/pm.h>

static void __iomem *msm_ps_hold;
-static int do_msm_restart(struct notifier_block *nb, unsigned long action,
- void *data)
+
+static void _do_msm_restart(void)
{
writel(0, msm_ps_hold);
mdelay(10000);
+}
+
+static int do_msm_restart(struct notifier_block *nb, unsigned long action,
+ void *data)
+{
+ _do_msm_restart();

return NOTIFY_DONE;
}
@@ -37,12 +43,17 @@ static struct notifier_block restart_nb = {
.priority = 128,
};

-static void do_msm_poweroff(void)
+static void do_msm_power_off(struct power_off_handler_block *this)
{
- /* TODO: Add poweroff capability */
- do_msm_restart(&restart_nb, 0, NULL);
+ /* TODO: Add power-off capability */
+ _do_msm_restart();
}

+static struct power_off_handler_block power_off_hb = {
+ .handler = do_msm_power_off,
+ .priority = POWER_OFF_PRIORITY_FALLBACK,
+};
+
static int msm_restart_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -55,7 +66,8 @@ static int msm_restart_probe(struct platform_device *pdev)

register_restart_handler(&restart_nb);

- pm_power_off = do_msm_poweroff;
+ if (register_power_off_handler(&power_off_hb))
+ dev_warn(&pdev->dev, "Failed to register power-off handler\n");

return 0;
}
--
1.9.1

2014-11-06 16:57:35

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 24/48] power/reset: as3722-poweroff: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the original code
only sets pm_power_off if it was not already set.

Drop remove function since it is no longer needed.

Cc: Sebastian Reichel <[email protected]>
Cc: Dmitry Eremin-Solenikov <[email protected]>
Cc: David Woodhouse <[email protected]>
Acked-by: Sebastian Reichel <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler
- Drop remove function since it is no longer needed

drivers/power/reset/as3722-poweroff.c | 35 +++++++++++------------------------
1 file changed, 11 insertions(+), 24 deletions(-)

diff --git a/drivers/power/reset/as3722-poweroff.c b/drivers/power/reset/as3722-poweroff.c
index 6849711..bd4965b 100644
--- a/drivers/power/reset/as3722-poweroff.c
+++ b/drivers/power/reset/as3722-poweroff.c
@@ -20,28 +20,25 @@
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
+#include <linux/pm.h>
#include <linux/slab.h>

struct as3722_poweroff {
struct device *dev;
struct as3722 *as3722;
+ struct power_off_handler_block power_off_hb;
};

-static struct as3722_poweroff *as3722_pm_poweroff;
-
-static void as3722_pm_power_off(void)
+static void as3722_power_off(struct power_off_handler_block *this)
{
+ struct as3722_poweroff *as3722_poweroff =
+ container_of(this, struct as3722_poweroff, power_off_hb);
int ret;

- if (!as3722_pm_poweroff) {
- pr_err("AS3722 poweroff is not initialised\n");
- return;
- }
-
- ret = as3722_update_bits(as3722_pm_poweroff->as3722,
+ ret = as3722_update_bits(as3722_poweroff->as3722,
AS3722_RESET_CONTROL_REG, AS3722_POWER_OFF, AS3722_POWER_OFF);
if (ret < 0)
- dev_err(as3722_pm_poweroff->dev,
+ dev_err(as3722_poweroff->dev,
"RESET_CONTROL_REG update failed, %d\n", ret);
}

@@ -63,20 +60,11 @@ static int as3722_poweroff_probe(struct platform_device *pdev)

as3722_poweroff->as3722 = dev_get_drvdata(pdev->dev.parent);
as3722_poweroff->dev = &pdev->dev;
- as3722_pm_poweroff = as3722_poweroff;
- if (!pm_power_off)
- pm_power_off = as3722_pm_power_off;
-
- return 0;
-}
-
-static int as3722_poweroff_remove(struct platform_device *pdev)
-{
- if (pm_power_off == as3722_pm_power_off)
- pm_power_off = NULL;
- as3722_pm_poweroff = NULL;
+ as3722_poweroff->power_off_hb.handler = as3722_power_off;
+ as3722_poweroff->power_off_hb.priority = POWER_OFF_PRIORITY_LOW;

- return 0;
+ return devm_register_power_off_handler(&pdev->dev,
+ &as3722_poweroff->power_off_hb);
}

static struct platform_driver as3722_poweroff_driver = {
@@ -85,7 +73,6 @@ static struct platform_driver as3722_poweroff_driver = {
.owner = THIS_MODULE,
},
.probe = as3722_poweroff_probe,
- .remove = as3722_poweroff_remove,
};

module_platform_driver(as3722_poweroff_driver);
--
1.9.1

2014-11-06 16:59:18

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 21/48] ipmi: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with high priority to reflect that the original code
overwrites pm_power_off unconditionally.

Register power-off handler after the ipmi system is ready, and unregister
it prior to cleanup. This avoids having to check for the ready variable
in the poweroff callback.

Reviewed-by: Corey Minyard <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Use pr_warn instead of pr_err
- Call unregister_power_off_handler on exit only if not already unregistered

drivers/char/ipmi/ipmi_poweroff.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c
index 9f2e3be..4ae2f22 100644
--- a/drivers/char/ipmi/ipmi_poweroff.c
+++ b/drivers/char/ipmi/ipmi_poweroff.c
@@ -63,9 +63,6 @@ static ipmi_user_t ipmi_user;
static int ipmi_ifnum;
static void (*specific_poweroff_func)(ipmi_user_t user);

-/* Holds the old poweroff function so we can restore it on removal. */
-static void (*old_poweroff_func)(void);
-
static int set_param_ifnum(const char *val, struct kernel_param *kp)
{
int rv = param_set_int(val, kp);
@@ -544,15 +541,17 @@ static struct poweroff_function poweroff_functions[] = {


/* Called on a powerdown request. */
-static void ipmi_poweroff_function(void)
+static void ipmi_poweroff_function(struct power_off_handler_block *this)
{
- if (!ready)
- return;
-
/* Use run-to-completion mode, since interrupts may be off. */
specific_poweroff_func(ipmi_user);
}

+static struct power_off_handler_block ipmi_power_off_hb = {
+ .handler = ipmi_poweroff_function,
+ .priority = POWER_OFF_PRIORITY_HIGH,
+};
+
/* Wait for an IPMI interface to be installed, the first one installed
will be grabbed by this code and used to perform the powerdown. */
static void ipmi_po_new_smi(int if_num, struct device *device)
@@ -631,9 +630,12 @@ static void ipmi_po_new_smi(int if_num, struct device *device)
printk(KERN_INFO PFX "Found a %s style poweroff function\n",
poweroff_functions[i].platform_type);
specific_poweroff_func = poweroff_functions[i].poweroff_func;
- old_poweroff_func = pm_power_off;
- pm_power_off = ipmi_poweroff_function;
+
ready = 1;
+
+ rv = register_power_off_handler(&ipmi_power_off_hb);
+ if (rv)
+ pr_warn(PFX "failed to register power-off handler\n");
}

static void ipmi_po_smi_gone(int if_num)
@@ -644,9 +646,10 @@ static void ipmi_po_smi_gone(int if_num)
if (ipmi_ifnum != if_num)
return;

+ unregister_power_off_handler(&ipmi_power_off_hb);
+
ready = 0;
ipmi_destroy_user(ipmi_user);
- pm_power_off = old_poweroff_func;
}

static struct ipmi_smi_watcher smi_watcher = {
@@ -733,11 +736,11 @@ static void __exit ipmi_poweroff_cleanup(void)
ipmi_smi_watcher_unregister(&smi_watcher);

if (ready) {
+ unregister_power_off_handler(&ipmi_power_off_hb);
rv = ipmi_destroy_user(ipmi_user);
if (rv)
printk(KERN_ERR PFX "could not cleanup the IPMI"
" user: 0x%x\n", rv);
- pm_power_off = old_poweroff_func;
}
}
module_exit(ipmi_poweroff_cleanup);
--
1.9.1

2014-11-06 16:59:43

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 20/48] mfd: rn5t618: Register power-off handler with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the original code
only sets pm_power_off if it was not already set.

Cc: Beniamino Galvani <[email protected]>
Acked-by: Lee Jones <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- New patch

drivers/mfd/rn5t618.c | 28 ++++++++++++----------------
include/linux/mfd/rn5t618.h | 2 ++
2 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/drivers/mfd/rn5t618.c b/drivers/mfd/rn5t618.c
index 6668571..1492025 100644
--- a/drivers/mfd/rn5t618.c
+++ b/drivers/mfd/rn5t618.c
@@ -15,6 +15,7 @@
#include <linux/mfd/core.h>
#include <linux/mfd/rn5t618.h>
#include <linux/module.h>
+#include <linux/pm.h>
#include <linux/regmap.h>

static const struct mfd_cell rn5t618_cells[] = {
@@ -47,15 +48,16 @@ static const struct regmap_config rn5t618_regmap_config = {
.cache_type = REGCACHE_RBTREE,
};

-static struct rn5t618 *rn5t618_pm_power_off;
-
-static void rn5t618_power_off(void)
+static void rn5t618_power_off(struct power_off_handler_block *this)
{
+ struct rn5t618 *rn5t618 = container_of(this, struct rn5t618,
+ power_off_hb);
+
/* disable automatic repower-on */
- regmap_update_bits(rn5t618_pm_power_off->regmap, RN5T618_REPCNT,
+ regmap_update_bits(rn5t618->regmap, RN5T618_REPCNT,
RN5T618_REPCNT_REPWRON, 0);
/* start power-off sequence */
- regmap_update_bits(rn5t618_pm_power_off->regmap, RN5T618_SLPCNT,
+ regmap_update_bits(rn5t618->regmap, RN5T618_SLPCNT,
RN5T618_SLPCNT_SWPWROFF, RN5T618_SLPCNT_SWPWROFF);
}

@@ -85,23 +87,17 @@ static int rn5t618_i2c_probe(struct i2c_client *i2c,
return ret;
}

- if (!pm_power_off) {
- rn5t618_pm_power_off = priv;
- pm_power_off = rn5t618_power_off;
- }
+ priv->power_off_hb.handler = rn5t618_power_off;
+ priv->power_off_hb.priority = POWER_OFF_PRIORITY_LOW;
+ ret = devm_register_power_off_handler(&i2c->dev, &priv->power_off_hb);
+ if (ret)
+ dev_warn(&i2c->dev, "Failed to register power-off handler\n");

return 0;
}

static int rn5t618_i2c_remove(struct i2c_client *i2c)
{
- struct rn5t618 *priv = i2c_get_clientdata(i2c);
-
- if (priv == rn5t618_pm_power_off) {
- rn5t618_pm_power_off = NULL;
- pm_power_off = NULL;
- }
-
mfd_remove_devices(&i2c->dev);
return 0;
}
diff --git a/include/linux/mfd/rn5t618.h b/include/linux/mfd/rn5t618.h
index c72d534..87e34b3 100644
--- a/include/linux/mfd/rn5t618.h
+++ b/include/linux/mfd/rn5t618.h
@@ -14,6 +14,7 @@
#ifndef __LINUX_MFD_RN5T618_H
#define __LINUX_MFD_RN5T618_H

+#include <linux/pm.h>
#include <linux/regmap.h>

#define RN5T618_LSIVER 0x00
@@ -223,6 +224,7 @@ enum {

struct rn5t618 {
struct regmap *regmap;
+ struct power_off_handler_block power_off_hb;
};

#endif /* __LINUX_MFD_RN5T618_H */
--
1.9.1

2014-11-06 16:44:22

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 11/48] mfd: retu: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the original code
only sets pm_power_off if it was not already set.

Cc: Lee Jones <[email protected]>
Cc: Samuel Ortiz <[email protected]>
Acked-by: Lee Jones <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler
- Use dev_warn instead of dev_err

drivers/mfd/retu-mfd.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/mfd/retu-mfd.c b/drivers/mfd/retu-mfd.c
index 663f8a3..30e746b 100644
--- a/drivers/mfd/retu-mfd.c
+++ b/drivers/mfd/retu-mfd.c
@@ -22,6 +22,7 @@
#include <linux/slab.h>
#include <linux/mutex.h>
#include <linux/module.h>
+#include <linux/pm.h>
#include <linux/regmap.h>
#include <linux/mfd/core.h>
#include <linux/mfd/retu.h>
@@ -43,6 +44,7 @@ struct retu_dev {
struct device *dev;
struct mutex mutex;
struct regmap_irq_chip_data *irq_data;
+ struct power_off_handler_block power_off_hb;
};

static struct resource retu_pwrbutton_res[] = {
@@ -81,9 +83,6 @@ static struct regmap_irq_chip retu_irq_chip = {
.ack_base = RETU_REG_IDR,
};

-/* Retu device registered for the power off. */
-static struct retu_dev *retu_pm_power_off;
-
static struct resource tahvo_usb_res[] = {
{
.name = "tahvo-usb",
@@ -165,12 +164,13 @@ int retu_write(struct retu_dev *rdev, u8 reg, u16 data)
}
EXPORT_SYMBOL_GPL(retu_write);

-static void retu_power_off(void)
+static void retu_power_off(struct power_off_handler_block *this)
{
- struct retu_dev *rdev = retu_pm_power_off;
+ struct retu_dev *rdev = container_of(this, struct retu_dev,
+ power_off_hb);
int reg;

- mutex_lock(&retu_pm_power_off->mutex);
+ mutex_lock(&rdev->mutex);

/* Ignore power button state */
regmap_read(rdev->regmap, RETU_REG_CC1, &reg);
@@ -183,7 +183,7 @@ static void retu_power_off(void)
for (;;)
cpu_relax();

- mutex_unlock(&retu_pm_power_off->mutex);
+ mutex_unlock(&rdev->mutex);
}

static int retu_regmap_read(void *context, const void *reg, size_t reg_size,
@@ -279,9 +279,14 @@ static int retu_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
return ret;
}

- if (i2c->addr == 1 && !pm_power_off) {
- retu_pm_power_off = rdev;
- pm_power_off = retu_power_off;
+ if (i2c->addr == 1) {
+ rdev->power_off_hb.handler = retu_power_off;
+ rdev->power_off_hb.priority = POWER_OFF_PRIORITY_LOW;
+ ret = devm_register_power_off_handler(rdev->dev,
+ &rdev->power_off_hb);
+ if (ret)
+ dev_warn(rdev->dev,
+ "Failed to register power-off handler\n");
}

return 0;
@@ -291,10 +296,6 @@ static int retu_remove(struct i2c_client *i2c)
{
struct retu_dev *rdev = i2c_get_clientdata(i2c);

- if (retu_pm_power_off == rdev) {
- pm_power_off = NULL;
- retu_pm_power_off = NULL;
- }
mfd_remove_devices(rdev->dev);
regmap_del_irq_chip(i2c->irq, rdev->irq_data);

--
1.9.1

2014-11-06 17:00:37

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 17/48] mfd: tps65910: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the original code
only sets pm_power_off if it was not already set.

Cc: Samuel Ortiz <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Acked-by: Lee Jones <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Use dev_warn instead of dev_err

drivers/mfd/tps65910.c | 21 +++++++++++++--------
include/linux/mfd/tps65910.h | 4 ++++
2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
index 7612d89..b312b92 100644
--- a/drivers/mfd/tps65910.c
+++ b/drivers/mfd/tps65910.c
@@ -23,6 +23,7 @@
#include <linux/irq.h>
#include <linux/irqdomain.h>
#include <linux/mfd/core.h>
+#include <linux/pm.h>
#include <linux/regmap.h>
#include <linux/mfd/tps65910.h>
#include <linux/of.h>
@@ -437,12 +438,10 @@ struct tps65910_board *tps65910_parse_dt(struct i2c_client *client,
}
#endif

-static struct i2c_client *tps65910_i2c_client;
-static void tps65910_power_off(void)
+static void tps65910_power_off(struct power_off_handler_block *this)
{
- struct tps65910 *tps65910;
-
- tps65910 = dev_get_drvdata(&tps65910_i2c_client->dev);
+ struct tps65910 *tps65910 = container_of(this, struct tps65910,
+ power_off_hb);

if (tps65910_reg_set_bits(tps65910, TPS65910_DEVCTRL,
DEVCTRL_PWR_OFF_MASK) < 0)
@@ -505,9 +504,13 @@ static 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;
+ if (pmic_plat_data->pm_off) {
+ tps65910->power_off_hb.handler = tps65910_power_off;
+ tps65910->power_off_hb.priority = POWER_OFF_PRIORITY_LOW;
+ ret = register_power_off_handler(&tps65910->power_off_hb);
+ if (ret)
+ dev_warn(&i2c->dev,
+ "failed to register power-off handler\n");
}

ret = mfd_add_devices(tps65910->dev, -1,
@@ -527,6 +530,8 @@ static int tps65910_i2c_remove(struct i2c_client *i2c)
{
struct tps65910 *tps65910 = i2c_get_clientdata(i2c);

+ unregister_power_off_handler(&tps65910->power_off_hb);
+
tps65910_irq_exit(tps65910);
mfd_remove_devices(tps65910->dev);

diff --git a/include/linux/mfd/tps65910.h b/include/linux/mfd/tps65910.h
index 6483a6f..a85ad0f 100644
--- a/include/linux/mfd/tps65910.h
+++ b/include/linux/mfd/tps65910.h
@@ -18,6 +18,7 @@
#define __LINUX_MFD_TPS65910_H

#include <linux/gpio.h>
+#include <linux/pm.h>
#include <linux/regmap.h>

/* TPS chip id list */
@@ -905,6 +906,9 @@ struct tps65910 {
/* IRQ Handling */
int chip_irq;
struct regmap_irq_chip_data *irq_data;
+
+ /* Power-off handling */
+ struct power_off_handler_block power_off_hb;
};

struct tps65910_platform_data {
--
1.9.1

2014-11-06 17:01:40

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 15/48] mfd: dm355evm_msp: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the original code
only sets pm_power_off if it was not already set.

Cc: Samuel Ortiz <[email protected]>
Cc: Lee Jones <[email protected]>
Acked-by: Lee Jones <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Use dev_warn instead of dev_err

drivers/mfd/dm355evm_msp.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/dm355evm_msp.c b/drivers/mfd/dm355evm_msp.c
index 4c826f7..d9ec1e6 100644
--- a/drivers/mfd/dm355evm_msp.c
+++ b/drivers/mfd/dm355evm_msp.c
@@ -14,6 +14,7 @@
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <linux/module.h>
+#include <linux/pm.h>
#include <linux/err.h>
#include <linux/gpio.h>
#include <linux/leds.h>
@@ -352,14 +353,19 @@ static void dm355evm_command(unsigned command)
command, status);
}

-static void dm355evm_power_off(void)
+static void dm355evm_power_off(struct power_off_handler_block *this)
{
dm355evm_command(MSP_COMMAND_POWEROFF);
}

+static struct power_off_handler_block dm355evm_msp_power_off_hb = {
+ .handler = dm355evm_power_off,
+ .priority = POWER_OFF_PRIORITY_LOW,
+};
+
static int dm355evm_msp_remove(struct i2c_client *client)
{
- pm_power_off = NULL;
+ unregister_power_off_handler(&dm355evm_msp_power_off_hb);
msp430 = NULL;
return 0;
}
@@ -398,7 +404,9 @@ dm355evm_msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
goto fail;

/* PM hookup */
- pm_power_off = dm355evm_power_off;
+ status = register_power_off_handler(&dm355evm_msp_power_off_hb);
+ if (status)
+ dev_warn(&client->dev, "Failed to register power-off handler\n");

return 0;

--
1.9.1

2014-11-06 17:02:12

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 13/48] mfd: max8907: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the original code
only sets pm_power_off if it was not already set.

Note that this patch fixes a problem on driver unload as side effect:
The old code did not restore or clean up pm_power_off on remove,
meaning the pointer was left in an undefined state.

Cc: Lee Jones <[email protected]>
Cc: Samuel Ortiz <[email protected]>
Acked-by: Lee Jones <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Use dev_warn instead of dev_err

drivers/mfd/max8907.c | 21 +++++++++++++++------
include/linux/mfd/max8907.h | 1 +
2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/max8907.c b/drivers/mfd/max8907.c
index 232749c..84f8afd 100644
--- a/drivers/mfd/max8907.c
+++ b/drivers/mfd/max8907.c
@@ -19,6 +19,7 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
+#include <linux/pm.h>
#include <linux/regmap.h>
#include <linux/slab.h>

@@ -177,10 +178,12 @@ static const struct regmap_irq_chip max8907_rtc_irq_chip = {
.num_irqs = ARRAY_SIZE(max8907_rtc_irqs),
};

-static struct max8907 *max8907_pm_off;
-static void max8907_power_off(void)
+static void max8907_power_off(struct power_off_handler_block *this)
{
- regmap_update_bits(max8907_pm_off->regmap_gen, MAX8907_REG_RESET_CNFG,
+ struct max8907 *max8907 = container_of(this, struct max8907,
+ power_off_hb);
+
+ regmap_update_bits(max8907->regmap_gen, MAX8907_REG_RESET_CNFG,
MAX8907_MASK_POWER_OFF, MAX8907_MASK_POWER_OFF);
}

@@ -267,9 +270,13 @@ static int max8907_i2c_probe(struct i2c_client *i2c,
goto err_add_devices;
}

- if (pm_off && !pm_power_off) {
- max8907_pm_off = max8907;
- pm_power_off = max8907_power_off;
+ if (pm_off) {
+ max8907->power_off_hb.handler = max8907_power_off;
+ max8907->power_off_hb.priority = POWER_OFF_PRIORITY_LOW;
+ ret = register_power_off_handler(&max8907->power_off_hb);
+ if (ret)
+ dev_warn(&i2c->dev,
+ "Failed to register power-off handler");
}

return 0;
@@ -293,6 +300,8 @@ static int max8907_i2c_remove(struct i2c_client *i2c)
{
struct max8907 *max8907 = i2c_get_clientdata(i2c);

+ unregister_power_off_handler(&max8907->power_off_hb);
+
mfd_remove_devices(max8907->dev);

regmap_del_irq_chip(max8907->i2c_gen->irq, max8907->irqc_rtc);
diff --git a/include/linux/mfd/max8907.h b/include/linux/mfd/max8907.h
index b06f7a6..18a4c68 100644
--- a/include/linux/mfd/max8907.h
+++ b/include/linux/mfd/max8907.h
@@ -247,6 +247,7 @@ struct max8907 {
struct regmap_irq_chip_data *irqc_chg;
struct regmap_irq_chip_data *irqc_on_off;
struct regmap_irq_chip_data *irqc_rtc;
+ struct power_off_handler_block power_off_hb;
};

#endif
--
1.9.1

2014-11-06 17:02:42

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 12/48] mfd: ab8500-sysctrl: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the original code
only sets pm_power_off if it was not already set.

sysctrl_dev is set prior to power-off handler registration, and the
power-off handler is unregistered prior to clearing sysrctrl_dev.
It is therefore not necessary to check if sysctrl_dev is NULL in the
power-off handler, and the check was removed. Setting sysctrl_dev to NULL
in the remove function was also removed as unnecessary. With those changes,
devm_register_power_off_handler can be used to register the poeroff handler.
The now empty remove function was retained since the ab8500_restart function,
which is currently unused, would likely need some cleanup if it was ever used.

Cc: Linus Walleij <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: Samuel Ortiz <[email protected]>
Acked-by: Lee Jones <[email protected]>
Acked-by: Linus Walleij <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler
- Use dev_warn instead of dev_err
- Since we use devm_register_power_off_handler,
we need to check if sysctrl_dev in the poweroff handler to avoid
a race condition on unload, so this check is no longer removed

drivers/mfd/ab8500-sysctrl.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/ab8500-sysctrl.c b/drivers/mfd/ab8500-sysctrl.c
index 8e0dae5..bd382de 100644
--- a/drivers/mfd/ab8500-sysctrl.c
+++ b/drivers/mfd/ab8500-sysctrl.c
@@ -23,7 +23,7 @@

static struct device *sysctrl_dev;

-static void ab8500_power_off(void)
+static void ab8500_power_off(struct power_off_handler_block *this)
{
sigset_t old;
sigset_t all;
@@ -85,6 +85,11 @@ shutdown:
}
}

+static struct power_off_handler_block ab8500_power_off_hb = {
+ .handler = ab8500_power_off,
+ .priority = POWER_OFF_PRIORITY_LOW,
+};
+
/*
* Use the AB WD to reset the platform. It will perform a hard
* reset instead of a soft reset. Write the reset reason to
@@ -185,6 +190,7 @@ static int ab8500_sysctrl_probe(struct platform_device *pdev)
struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
struct ab8500_platform_data *plat;
struct ab8500_sysctrl_platform_data *pdata;
+ int err;

plat = dev_get_platdata(pdev->dev.parent);

@@ -193,8 +199,10 @@ static int ab8500_sysctrl_probe(struct platform_device *pdev)

sysctrl_dev = &pdev->dev;

- if (!pm_power_off)
- pm_power_off = ab8500_power_off;
+ err = devm_register_power_off_handler(sysctrl_dev,
+ &ab8500_power_off_hb);
+ if (err)
+ dev_warn(&pdev->dev, "Failed to register power-off handler\n");

pdata = plat->sysctrl;
if (pdata) {
@@ -228,9 +236,6 @@ static int ab8500_sysctrl_remove(struct platform_device *pdev)
{
sysctrl_dev = NULL;

- if (pm_power_off == ab8500_power_off)
- pm_power_off = NULL;
-
return 0;
}

--
1.9.1

2014-11-06 17:03:03

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 09/48] mfd: palmas: Register with kernel power-off handler

Register with kernel power-off handler instead of setting pm_power_off
directly. Register with low priority to reflect that the original code
only sets pm_power_off if it was not already set.

Cc: Samuel Ortiz <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Acked-by: Lee Jones <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
v2:
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler
- Use dev_warn instead of dev_err

drivers/mfd/palmas.c | 28 ++++++++++++++--------------
include/linux/mfd/palmas.h | 3 +++
2 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/drivers/mfd/palmas.c b/drivers/mfd/palmas.c
index 28cb048..60f81ed 100644
--- a/drivers/mfd/palmas.c
+++ b/drivers/mfd/palmas.c
@@ -19,6 +19,7 @@
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
+#include <linux/pm.h>
#include <linux/regmap.h>
#include <linux/err.h>
#include <linux/mfd/core.h>
@@ -425,20 +426,17 @@ static void palmas_dt_to_pdata(struct i2c_client *i2c,
"ti,system-power-controller");
}

-static struct palmas *palmas_dev;
-static void palmas_power_off(void)
+static void palmas_power_off(struct power_off_handler_block *this)
{
+ struct palmas *palmas = container_of(this, struct palmas, power_off_hb);
unsigned int addr;
int ret, slave;

- if (!palmas_dev)
- return;
-
slave = PALMAS_BASE_TO_SLAVE(PALMAS_PMU_CONTROL_BASE);
addr = PALMAS_BASE_TO_REG(PALMAS_PMU_CONTROL_BASE, PALMAS_DEV_CTRL);

ret = regmap_update_bits(
- palmas_dev->regmap[slave],
+ palmas->regmap[slave],
addr,
PALMAS_DEV_CTRL_DEV_ON,
0);
@@ -668,9 +666,16 @@ no_irq:
ret = of_platform_populate(node, NULL, NULL, &i2c->dev);
if (ret < 0) {
goto err_irq;
- } else if (pdata->pm_off && !pm_power_off) {
- palmas_dev = palmas;
- pm_power_off = palmas_power_off;
+ } else if (pdata->pm_off) {
+ int ret2;
+
+ palmas->power_off_hb.handler = palmas_power_off;
+ palmas->power_off_hb.priority = POWER_OFF_PRIORITY_LOW;
+ ret2 = devm_register_power_off_handler(palmas->dev,
+ &palmas->power_off_hb);
+ if (ret2)
+ dev_warn(palmas->dev,
+ "Failed to register power-off handler");
}
}

@@ -698,11 +703,6 @@ static int palmas_i2c_remove(struct i2c_client *i2c)
i2c_unregister_device(palmas->i2c_clients[i]);
}

- if (palmas == palmas_dev) {
- pm_power_off = NULL;
- palmas_dev = NULL;
- }
-
return 0;
}

diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
index fb0390a..7a43f7b 100644
--- a/include/linux/mfd/palmas.h
+++ b/include/linux/mfd/palmas.h
@@ -18,6 +18,7 @@

#include <linux/usb/otg.h>
#include <linux/leds.h>
+#include <linux/pm.h>
#include <linux/regmap.h>
#include <linux/regulator/driver.h>
#include <linux/extcon.h>
@@ -68,6 +69,8 @@ struct palmas {
struct i2c_client *i2c_clients[PALMAS_NUM_CLIENTS];
struct regmap *regmap[PALMAS_NUM_CLIENTS];

+ struct power_off_handler_block power_off_hb;
+
/* Stored chip id */
int id;

--
1.9.1

2014-11-06 17:03:06

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 08/48] kernel: Move pm_power_off to common code

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off.
Some architectures point pm_power_off to machine_power_off. For those,
call do_kernel_power_off from machine_power_off instead.

Acked-by: David Vrabel <[email protected]>
Acked-by: Geert Uytterhoeven <[email protected]>
Acked-by: Hirokazu Takata <[email protected]>
Acked-by: James Hogan <[email protected]>
Acked-by: Jesper Nilsson <[email protected]>
Acked-by: Max Filippov <[email protected]>
Acked-by: Rafael J. Wysocki <[email protected]>
Acked-by: Richard Weinberger <[email protected]>
Acked-by: Xuetao Guan <[email protected]>
Acked-by: Ralf Baechle <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
- Update powerpc code to reflect merged power-off handler changes
v4:
- No change
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
v2:
- do_kernel_poweroff -> do_kernel_power_off
- have_kernel_poweroff -> have_kernel_power_off

arch/alpha/kernel/process.c | 9 +++------
arch/arc/kernel/reset.c | 5 +----
arch/arm/kernel/process.c | 5 +----
arch/arm64/kernel/process.c | 5 +----
arch/avr32/kernel/process.c | 6 +-----
arch/blackfin/kernel/process.c | 3 ---
arch/blackfin/kernel/reboot.c | 2 ++
arch/c6x/kernel/process.c | 9 +--------
arch/cris/kernel/process.c | 4 +---
arch/frv/kernel/process.c | 5 ++---
arch/hexagon/kernel/reset.c | 5 ++---
arch/ia64/kernel/process.c | 5 +----
arch/m32r/kernel/process.c | 8 ++++----
arch/m68k/kernel/process.c | 6 +-----
arch/metag/kernel/process.c | 6 +-----
arch/microblaze/kernel/process.c | 3 ---
arch/microblaze/kernel/reset.c | 1 +
arch/mips/kernel/reset.c | 6 +-----
arch/mn10300/kernel/process.c | 8 ++------
arch/openrisc/kernel/process.c | 8 +++++---
arch/parisc/kernel/process.c | 8 ++++----
arch/powerpc/kernel/setup-common.c | 6 +-----
arch/powerpc/xmon/xmon.c | 3 +--
arch/s390/kernel/setup.c | 8 ++------
arch/score/kernel/process.c | 8 ++++----
arch/sh/kernel/reboot.c | 6 +-----
arch/sparc/kernel/process_32.c | 10 ++--------
arch/sparc/kernel/reboot.c | 8 ++------
arch/tile/kernel/reboot.c | 7 +++----
arch/um/kernel/reboot.c | 2 --
arch/unicore32/kernel/process.c | 9 +--------
arch/x86/kernel/reboot.c | 11 +++--------
arch/x86/xen/enlighten.c | 3 +--
arch/xtensa/kernel/process.c | 4 ----
drivers/parisc/power.c | 3 +--
kernel/power/power_off_handler.c | 9 +++++++++
kernel/reboot.c | 4 ++--
37 files changed, 68 insertions(+), 150 deletions(-)

diff --git a/arch/alpha/kernel/process.c b/arch/alpha/kernel/process.c
index 1941a07..81c43f8 100644
--- a/arch/alpha/kernel/process.c
+++ b/arch/alpha/kernel/process.c
@@ -24,6 +24,7 @@
#include <linux/vt.h>
#include <linux/mman.h>
#include <linux/elfcore.h>
+#include <linux/pm.h>
#include <linux/reboot.h>
#include <linux/tty.h>
#include <linux/console.h>
@@ -40,12 +41,6 @@
#include "proto.h"
#include "pci_impl.h"

-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
#ifdef CONFIG_ALPHA_WTINT
/*
* Sleep the CPU.
@@ -184,6 +179,8 @@ machine_halt(void)
void
machine_power_off(void)
{
+ do_kernel_power_off();
+
common_shutdown(LINUX_REBOOT_CMD_POWER_OFF, NULL);
}

diff --git a/arch/arc/kernel/reset.c b/arch/arc/kernel/reset.c
index 2768fa1..0758d9d 100644
--- a/arch/arc/kernel/reset.c
+++ b/arch/arc/kernel/reset.c
@@ -26,9 +26,6 @@ void machine_restart(char *__unused)

void machine_power_off(void)
{
- /* FIXME :: power off ??? */
+ do_kernel_power_off();
machine_halt();
}
-
-void (*pm_power_off) (void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index fe972a2..aa3f656 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -117,8 +117,6 @@ void soft_restart(unsigned long addr)
/*
* Function pointers to optional machine specific functions
*/
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);

void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);

@@ -205,8 +203,7 @@ void machine_power_off(void)
local_irq_disable();
smp_send_stop();

- if (pm_power_off)
- pm_power_off();
+ do_kernel_power_off();
}

/*
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index fde9923..6f623a0 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -68,8 +68,6 @@ void soft_restart(unsigned long addr)
/*
* Function pointers to optional machine specific functions
*/
-void (*pm_power_off)(void);
-EXPORT_SYMBOL_GPL(pm_power_off);

void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);

@@ -129,8 +127,7 @@ void machine_power_off(void)
{
local_irq_disable();
smp_send_stop();
- if (pm_power_off)
- pm_power_off();
+ do_kernel_power_off();
}

/*
diff --git a/arch/avr32/kernel/process.c b/arch/avr32/kernel/process.c
index 42a53e74..529c1f6 100644
--- a/arch/avr32/kernel/process.c
+++ b/arch/avr32/kernel/process.c
@@ -23,9 +23,6 @@

#include <mach/pm.h>

-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
/*
* This file handles the architecture-dependent parts of process handling..
*/
@@ -48,8 +45,7 @@ void machine_halt(void)

void machine_power_off(void)
{
- if (pm_power_off)
- pm_power_off();
+ do_kernel_power_off();
}

void machine_restart(char *cmd)
diff --git a/arch/blackfin/kernel/process.c b/arch/blackfin/kernel/process.c
index 4aa5545..812dd83 100644
--- a/arch/blackfin/kernel/process.c
+++ b/arch/blackfin/kernel/process.c
@@ -39,9 +39,6 @@ int nr_l1stack_tasks;
void *l1_stack_base;
unsigned long l1_stack_len;

-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
/*
* The idle loop on BFIN
*/
diff --git a/arch/blackfin/kernel/reboot.c b/arch/blackfin/kernel/reboot.c
index c4f50a3..387d610 100644
--- a/arch/blackfin/kernel/reboot.c
+++ b/arch/blackfin/kernel/reboot.c
@@ -7,6 +7,7 @@
*/

#include <linux/interrupt.h>
+#include <linux/pm.h>
#include <asm/bfin-global.h>
#include <asm/reboot.h>
#include <asm/bfrom.h>
@@ -106,6 +107,7 @@ void machine_halt(void)
__attribute__((weak))
void native_machine_power_off(void)
{
+ do_kernel_power_off();
idle_with_irq_disabled();
}

diff --git a/arch/c6x/kernel/process.c b/arch/c6x/kernel/process.c
index 57d2ea8..edf7e5a 100644
--- a/arch/c6x/kernel/process.c
+++ b/arch/c6x/kernel/process.c
@@ -27,12 +27,6 @@ void (*c6x_halt)(void);
extern asmlinkage void ret_from_fork(void);
extern asmlinkage void ret_from_kernel_thread(void);

-/*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
void arch_cpu_idle(void)
{
unsigned long tmp;
@@ -73,8 +67,7 @@ void machine_halt(void)

void machine_power_off(void)
{
- if (pm_power_off)
- pm_power_off();
+ do_kernel_power_off();
halt_loop();
}

diff --git a/arch/cris/kernel/process.c b/arch/cris/kernel/process.c
index b78498e..9ebd76b 100644
--- a/arch/cris/kernel/process.c
+++ b/arch/cris/kernel/process.c
@@ -31,9 +31,6 @@

extern void default_idle(void);

-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
void arch_cpu_idle(void)
{
default_idle();
@@ -60,6 +57,7 @@ void machine_halt(void)

void machine_power_off(void)
{
+ do_kernel_power_off();
}

/*
diff --git a/arch/frv/kernel/process.c b/arch/frv/kernel/process.c
index 5d40aeb77..502dabb 100644
--- a/arch/frv/kernel/process.c
+++ b/arch/frv/kernel/process.c
@@ -42,9 +42,6 @@ asmlinkage void ret_from_kernel_thread(void);

#include <asm/pgalloc.h>

-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
static void core_sleep_idle(void)
{
#ifdef LED_DEBUG_SLEEP
@@ -107,6 +104,8 @@ void machine_power_off(void)
gdbstub_exit(0);
#endif

+ do_kernel_power_off();
+
for (;;);
}

diff --git a/arch/hexagon/kernel/reset.c b/arch/hexagon/kernel/reset.c
index 76483c1..6f607b6 100644
--- a/arch/hexagon/kernel/reset.c
+++ b/arch/hexagon/kernel/reset.c
@@ -16,11 +16,13 @@
* 02110-1301, USA.
*/

+#include <linux/pm.h>
#include <linux/smp.h>
#include <asm/hexagon_vm.h>

void machine_power_off(void)
{
+ do_kernel_power_off();
smp_send_stop();
__vmstop();
}
@@ -32,6 +34,3 @@ void machine_halt(void)
void machine_restart(char *cmd)
{
}
-
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index b515149..88121a2 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -57,8 +57,6 @@ void (*ia64_mark_idle)(int);

unsigned long boot_option_idle_override = IDLE_NO_OVERRIDE;
EXPORT_SYMBOL(boot_option_idle_override);
-void (*pm_power_off) (void);
-EXPORT_SYMBOL(pm_power_off);

void
ia64_do_show_stack (struct unw_frame_info *info, void *arg)
@@ -675,8 +673,7 @@ machine_halt (void)
void
machine_power_off (void)
{
- if (pm_power_off)
- pm_power_off();
+ do_kernel_power_off();
machine_halt();
}

diff --git a/arch/m32r/kernel/process.c b/arch/m32r/kernel/process.c
index e69221d..65a037e 100644
--- a/arch/m32r/kernel/process.c
+++ b/arch/m32r/kernel/process.c
@@ -23,6 +23,7 @@
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/module.h>
+#include <linux/pm.h>
#include <linux/ptrace.h>
#include <linux/unistd.h>
#include <linux/hardirq.h>
@@ -44,9 +45,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
return tsk->thread.lr;
}

-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
void machine_restart(char *__unused)
{
#if defined(CONFIG_PLAT_MAPPI3)
@@ -67,7 +65,9 @@ void machine_halt(void)

void machine_power_off(void)
{
- /* M32R_FIXME */
+ do_kernel_power_off();
+ for (;;)
+ ;
}

void show_regs(struct pt_regs * regs)
diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
index afe3d6e..bbc0a63 100644
--- a/arch/m68k/kernel/process.c
+++ b/arch/m68k/kernel/process.c
@@ -78,14 +78,10 @@ void machine_halt(void)

void machine_power_off(void)
{
- if (pm_power_off)
- pm_power_off();
+ do_kernel_power_off();
for (;;);
}

-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
void show_regs(struct pt_regs * regs)
{
printk("\n");
diff --git a/arch/metag/kernel/process.c b/arch/metag/kernel/process.c
index 483dff9..8d95773 100644
--- a/arch/metag/kernel/process.c
+++ b/arch/metag/kernel/process.c
@@ -67,9 +67,6 @@ void arch_cpu_idle_dead(void)
}
#endif

-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
void (*soc_restart)(char *cmd);
void (*soc_halt)(void);

@@ -90,8 +87,7 @@ void machine_halt(void)

void machine_power_off(void)
{
- if (pm_power_off)
- pm_power_off();
+ do_kernel_power_off();
smp_send_stop();
hard_processor_halt(HALT_OK);
}
diff --git a/arch/microblaze/kernel/process.c b/arch/microblaze/kernel/process.c
index b2dd371..0ebca36 100644
--- a/arch/microblaze/kernel/process.c
+++ b/arch/microblaze/kernel/process.c
@@ -44,9 +44,6 @@ void show_regs(struct pt_regs *regs)
regs->msr, regs->ear, regs->esr, regs->fsr);
}

-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
void flush_thread(void)
{
}
diff --git a/arch/microblaze/kernel/reset.c b/arch/microblaze/kernel/reset.c
index fbe58c6..2c6b32c 100644
--- a/arch/microblaze/kernel/reset.c
+++ b/arch/microblaze/kernel/reset.c
@@ -103,6 +103,7 @@ void machine_halt(void)
void machine_power_off(void)
{
pr_notice("Machine power off...\n");
+ do_kernel_power_off();
while (1)
;
}
diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
index 07fc524..09e74d2 100644
--- a/arch/mips/kernel/reset.c
+++ b/arch/mips/kernel/reset.c
@@ -21,9 +21,6 @@
*/
void (*_machine_restart)(char *command);
void (*_machine_halt)(void);
-void (*pm_power_off)(void);
-
-EXPORT_SYMBOL(pm_power_off);

void machine_restart(char *command)
{
@@ -39,6 +36,5 @@ void machine_halt(void)

void machine_power_off(void)
{
- if (pm_power_off)
- pm_power_off();
+ do_kernel_power_off();
}
diff --git a/arch/mn10300/kernel/process.c b/arch/mn10300/kernel/process.c
index 3707da5..c78b2eb 100644
--- a/arch/mn10300/kernel/process.c
+++ b/arch/mn10300/kernel/process.c
@@ -20,6 +20,7 @@
#include <linux/user.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
+#include <linux/pm.h>
#include <linux/reboot.h>
#include <linux/percpu.h>
#include <linux/err.h>
@@ -45,12 +46,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
}

/*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
-/*
* On SMP it's slightly faster (but much more power-consuming!)
* to poll the ->work.need_resched flag instead of waiting for the
* cross-CPU IPI to arrive. Use this option with caution.
@@ -93,6 +88,7 @@ void machine_power_off(void)
#ifdef CONFIG_KERNEL_DEBUGGER
gdbstub_exit(0);
#endif
+ do_kernel_power_off();
}

void show_regs(struct pt_regs *regs)
diff --git a/arch/openrisc/kernel/process.c b/arch/openrisc/kernel/process.c
index 386af25..494afd2 100644
--- a/arch/openrisc/kernel/process.c
+++ b/arch/openrisc/kernel/process.c
@@ -25,6 +25,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mm.h>
+#include <linux/pm.h>
#include <linux/stddef.h>
#include <linux/unistd.h>
#include <linux/ptrace.h>
@@ -51,7 +52,7 @@
*/
struct thread_info *current_thread_info_set[NR_CPUS] = { &init_thread_info, };

-void machine_restart(void)
+void machine_restart(char *cmd)
{
printk(KERN_INFO "*** MACHINE RESTART ***\n");
__asm__("l.nop 1");
@@ -72,11 +73,12 @@ void machine_halt(void)
void machine_power_off(void)
{
printk(KERN_INFO "*** MACHINE POWER OFF ***\n");
+
+ do_kernel_power_off();
+
__asm__("l.nop 1");
}

-void (*pm_power_off) (void) = machine_power_off;
-
/*
* When a process does an "exec", machine state like FPU and debug
* registers need to be reset. This is a hook function for that.
diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c
index 0bbbf0d..3f5d14a 100644
--- a/arch/parisc/kernel/process.c
+++ b/arch/parisc/kernel/process.c
@@ -41,6 +41,7 @@
#include <linux/fs.h>
#include <linux/module.h>
#include <linux/personality.h>
+#include <linux/pm.h>
#include <linux/ptrace.h>
#include <linux/sched.h>
#include <linux/slab.h>
@@ -133,7 +134,9 @@ void machine_power_off(void)
pdc_soft_power_button(0);

pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
-
+
+ do_kernel_power_off();
+
/* It seems we have no way to power the system off via
* software. The user has to press the button himself. */

@@ -141,9 +144,6 @@ void machine_power_off(void)
"Please power this system off now.");
}

-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
/*
* Free current thread data structures etc..
*/
diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c
index 44c8d03..a2efce7 100644
--- a/arch/powerpc/kernel/setup-common.c
+++ b/arch/powerpc/kernel/setup-common.c
@@ -139,8 +139,7 @@ void machine_restart(char *cmd)
void machine_power_off(void)
{
machine_shutdown();
- if (pm_power_off)
- pm_power_off();
+ do_kernel_power_off();
#ifdef CONFIG_SMP
smp_send_stop();
#endif
@@ -151,9 +150,6 @@ void machine_power_off(void)
/* Used by the G5 thermal driver */
EXPORT_SYMBOL_GPL(machine_power_off);

-void (*pm_power_off)(void);
-EXPORT_SYMBOL_GPL(pm_power_off);
-
void machine_halt(void)
{
machine_shutdown();
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 506d256..8780178 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -981,8 +981,7 @@ static void bootcmds(void)
else if (cmd == 'h')
ppc_md.halt();
else if (cmd == 'p')
- if (pm_power_off)
- pm_power_off();
+ do_kernel_power_off();
}

static int cpu_cmd(void)
diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
index e80d9ff..267e025 100644
--- a/arch/s390/kernel/setup.c
+++ b/arch/s390/kernel/setup.c
@@ -263,13 +263,9 @@ void machine_power_off(void)
*/
console_unblank();
_machine_power_off();
-}

-/*
- * Dummy power off function.
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
+ do_kernel_power_off();
+}

static int __init early_parse_mem(char *p)
{
diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
index a1519ad3..b76ea67 100644
--- a/arch/score/kernel/process.c
+++ b/arch/score/kernel/process.c
@@ -29,9 +29,6 @@
#include <linux/pm.h>
#include <linux/rcupdate.h>

-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
/* If or when software machine-restart is implemented, add code here. */
void machine_restart(char *command) {}

@@ -39,7 +36,10 @@ void machine_restart(char *command) {}
void machine_halt(void) {}

/* If or when software machine-power-off is implemented, add code here. */
-void machine_power_off(void) {}
+void machine_power_off(void)
+{
+ do_kernel_power_off();
+}

void ret_from_fork(void);
void ret_from_kernel_thread(void);
diff --git a/arch/sh/kernel/reboot.c b/arch/sh/kernel/reboot.c
index 04afe5b..065de12 100644
--- a/arch/sh/kernel/reboot.c
+++ b/arch/sh/kernel/reboot.c
@@ -11,9 +11,6 @@
#include <asm/tlbflush.h>
#include <asm/traps.h>

-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
#ifdef CONFIG_SUPERH32
static void watchdog_trigger_immediate(void)
{
@@ -51,8 +48,7 @@ static void native_machine_shutdown(void)

static void native_machine_power_off(void)
{
- if (pm_power_off)
- pm_power_off();
+ do_kernel_power_off();
}

static void native_machine_halt(void)
diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
index 50e7b62..cb8148a 100644
--- a/arch/sparc/kernel/process_32.c
+++ b/arch/sparc/kernel/process_32.c
@@ -48,14 +48,6 @@
*/
void (*sparc_idle)(void);

-/*
- * Power-off handler instantiation for pm.h compliance
- * This is done via auxio, but could be used as a fallback
- * handler when auxio is not present-- unused for now...
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
/*
* sysctl - toggle power-off restriction for serial console
* systems in machine_power_off()
@@ -112,6 +104,8 @@ void machine_power_off(void)
sbus_writeb(power_register, auxio_power_register);
}

+ do_kernel_power_off();
+
machine_halt();
}

diff --git a/arch/sparc/kernel/reboot.c b/arch/sparc/kernel/reboot.c
index eba7d91..3c0bb03 100644
--- a/arch/sparc/kernel/reboot.c
+++ b/arch/sparc/kernel/reboot.c
@@ -16,17 +16,13 @@
*/
int scons_pwroff = 1;

-/* This isn't actually used, it exists merely to satisfy the
- * reference in kernel/sys.c
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
void machine_power_off(void)
{
if (strcmp(of_console_device->type, "serial") || scons_pwroff)
prom_halt_power_off();

+ do_kernel_power_off();
+
prom_halt();
}

diff --git a/arch/tile/kernel/reboot.c b/arch/tile/kernel/reboot.c
index 6c5d2c0..8ff4a7f 100644
--- a/arch/tile/kernel/reboot.c
+++ b/arch/tile/kernel/reboot.c
@@ -36,6 +36,9 @@ void machine_power_off(void)
{
arch_local_irq_disable_all();
smp_send_stop();
+
+ do_kernel_power_off();
+
hv_power_off();
}

@@ -45,7 +48,3 @@ void machine_restart(char *cmd)
smp_send_stop();
hv_restart((HV_VirtAddr) "vmlinux", (HV_VirtAddr) cmd);
}
-
-/* No interesting distinction to be made here. */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
diff --git a/arch/um/kernel/reboot.c b/arch/um/kernel/reboot.c
index ced8903..a82ef28 100644
--- a/arch/um/kernel/reboot.c
+++ b/arch/um/kernel/reboot.c
@@ -11,8 +11,6 @@
#include <os.h>
#include <skas.h>

-void (*pm_power_off)(void);
-
static void kill_off_processes(void)
{
if (proc_mm)
diff --git a/arch/unicore32/kernel/process.c b/arch/unicore32/kernel/process.c
index b008e99..9490dd5 100644
--- a/arch/unicore32/kernel/process.c
+++ b/arch/unicore32/kernel/process.c
@@ -56,16 +56,9 @@ void machine_halt(void)
gpio_set_value(GPO_SOFT_OFF, 0);
}

-/*
- * Function pointers to optional machine specific functions
- */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
void machine_power_off(void)
{
- if (pm_power_off)
- pm_power_off();
+ do_kernel_power_off();
machine_halt();
}

diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
index 17962e6..5c09e28 100644
--- a/arch/x86/kernel/reboot.c
+++ b/arch/x86/kernel/reboot.c
@@ -30,12 +30,6 @@
#include <asm/x86_init.h>
#include <asm/efi.h>

-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
static const struct desc_ptr no_idt = {};

/*
@@ -647,11 +641,12 @@ static void native_machine_halt(void)

static void native_machine_power_off(void)
{
- if (pm_power_off) {
+ if (have_kernel_power_off()) {
if (!reboot_force)
machine_shutdown();
- pm_power_off();
+ do_kernel_power_off();
}
+
/* A fallback in case there is no PM info available */
tboot_shutdown(TB_SHUTDOWN_HALT);
}
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index fac5e4f..bc08998 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -1320,8 +1320,7 @@ static void xen_machine_halt(void)

static void xen_machine_power_off(void)
{
- if (pm_power_off)
- pm_power_off();
+ do_kernel_power_off();
xen_reboot(SHUTDOWN_poweroff);
}

diff --git a/arch/xtensa/kernel/process.c b/arch/xtensa/kernel/process.c
index 1c85323..c487296 100644
--- a/arch/xtensa/kernel/process.c
+++ b/arch/xtensa/kernel/process.c
@@ -49,10 +49,6 @@ extern void ret_from_kernel_thread(void);

struct task_struct *current_set[NR_CPUS] = {&init_task, };

-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
-
#if XTENSA_HAVE_COPROCESSORS

void coprocessor_release_all(struct thread_info *ti)
diff --git a/drivers/parisc/power.c b/drivers/parisc/power.c
index ef31b77..f10cf92 100644
--- a/drivers/parisc/power.c
+++ b/drivers/parisc/power.c
@@ -95,8 +95,7 @@ static void process_shutdown(void)
/* send kill signal */
if (kill_cad_pid(SIGINT, 1)) {
/* just in case killing init process failed */
- if (pm_power_off)
- pm_power_off();
+ kernel_power_off();
}
}
}
diff --git a/kernel/power/power_off_handler.c b/kernel/power/power_off_handler.c
index e576534..e283ea1 100644
--- a/kernel/power/power_off_handler.c
+++ b/kernel/power/power_off_handler.c
@@ -23,6 +23,12 @@
#include <linux/types.h>

/*
+ * If set, calling this function will power off the system immediately.
+ */
+void (*pm_power_off)(void);
+EXPORT_SYMBOL(pm_power_off);
+
+/*
* List of handlers for kernel code which wants to be called
* to power off the system.
*/
@@ -272,6 +278,9 @@ void do_kernel_power_off(void)
* that risk.
*/

+ if (pm_power_off)
+ pm_power_off();
+
p = rcu_dereference_raw(power_off_handler_list);
while (p) {
next_p = rcu_dereference_raw(p->next);
diff --git a/kernel/reboot.c b/kernel/reboot.c
index 5925f5a..d87d921 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -306,9 +306,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
return ret;

/* Instead of trying to make the power_off code look like
- * halt when pm_power_off is not set do it the easy way.
+ * halt when no power-off handler exists do it the easy way.
*/
- if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
+ if (cmd == LINUX_REBOOT_CMD_POWER_OFF && !have_kernel_power_off())
cmd = LINUX_REBOOT_CMD_HALT;

mutex_lock(&reboot_mutex);
--
1.9.1

2014-11-06 16:44:01

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 06/48] gpio-poweroff: Drop reference to pm_power_off from devicetree bindings

pm_power_off is an implementation detail. Replace it with a more generic
description of the driver's functionality.

Cc: Rob Herring <[email protected]>
Cc: Pawel Moll <[email protected]>
Cc: Mark Rutland <[email protected]>
Acked-by: Mark Rutland <[email protected]>
Acked-by: Andrew Lunn <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
v2:
- No change

Documentation/devicetree/bindings/gpio/gpio-poweroff.txt | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/Documentation/devicetree/bindings/gpio/gpio-poweroff.txt b/Documentation/devicetree/bindings/gpio/gpio-poweroff.txt
index d4eab92..78262de 100644
--- a/Documentation/devicetree/bindings/gpio/gpio-poweroff.txt
+++ b/Documentation/devicetree/bindings/gpio/gpio-poweroff.txt
@@ -2,12 +2,12 @@ Driver a GPIO line that can be used to turn the power off.

The driver supports both level triggered and edge triggered power off.
At driver load time, the driver will request the given gpio line and
-install a pm_power_off handler. If the optional properties 'input' is
-not found, the GPIO line will be driven in the inactive
+install a handler to power off the system. If the optional properties
+'input' is not found, the GPIO line will be driven in the inactive
state. Otherwise its configured as an input.

-When the pm_power_off is called, the gpio is configured as an output,
-and drive active, so triggering a level triggered power off
+When the the power-off handler is called, the gpio is configured as an
+output, and drive active, so triggering a level triggered power off
condition. This will also cause an inactive->active edge condition, so
triggering positive edge triggered power off. After a delay of 100ms,
the GPIO is set to inactive, thus causing an active->inactive edge,
@@ -24,7 +24,7 @@ Required properties:

Optional properties:
- input : Initially configure the GPIO line as an input. Only reconfigure
- it to an output when the pm_power_off function is called. If this optional
+ it to an output when the power-off handler is called. If this optional
property is not specified, the GPIO is initialized as an output in its
inactive state.

--
1.9.1

2014-11-06 16:43:47

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 02/48] memory: emif: Use API function to determine power-off capability

Use have_kernel_power_off() to determine if the kernel is able
to power off the system.

Cc: Santosh Shilimkar <[email protected]>
Acked-by: Santosh Shilimkar <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
v2:
- poweroff -> power_off

drivers/memory/emif.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/memory/emif.c b/drivers/memory/emif.c
index 04644e7..317d49f 100644
--- a/drivers/memory/emif.c
+++ b/drivers/memory/emif.c
@@ -1053,10 +1053,10 @@ static irqreturn_t emif_threaded_isr(int irq, void *dev_id)
dev_emerg(emif->dev, "SDRAM temperature exceeds operating limit.. Needs shut down!!!\n");

/* If we have Power OFF ability, use it, else try restarting */
- if (pm_power_off) {
+ if (have_kernel_power_off()) {
kernel_power_off();
} else {
- WARN(1, "FIXME: NO pm_power_off!!! trying restart\n");
+ WARN(1, "FIXME: NO kernel power-off capability!!! trying restart\n");
kernel_restart("SDRAM Over-temp Emergency restart");
}
return IRQ_HANDLED;
--
1.9.1

2014-11-06 17:04:53

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 03/48] hibernate: Call have_kernel_power_off instead of checking pm_power_off

Power-off handlers may now be installed with register_power_off_handler.
Use the new API function have_kernel_power_off to determine if a power-off
handler has been installed.

Cc: Rafael J. Wysocki <[email protected]>
Cc: Pavel Machek <[email protected]>
Cc: Len Brown <[email protected]>
Acked-by: Rafael J. Wysocki <[email protected]>
Acked-by: Pavel Machek <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- No change
v3:
- No change
v2:
- have_kernel_poweroff -> have_kernel_power_off

kernel/power/hibernate.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 1f35a34..1202cf0 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -608,7 +608,7 @@ static void power_down(void)
case HIBERNATION_PLATFORM:
hibernation_platform_enter();
case HIBERNATION_SHUTDOWN:
- if (pm_power_off)
+ if (have_kernel_power_off())
kernel_power_off();
break;
#ifdef CONFIG_SUSPEND
--
1.9.1

2014-11-06 17:05:24

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH v5 01/48] kernel: Add support for power-off handler call chain

Various drivers implement architecture and/or device specific means to
power off the system. For the most part, those drivers set the global
variable pm_power_off to point to a function within the driver.

This mechanism has a number of drawbacks. Typically only one scheme
to remove power is supported (at least if pm_power_off is used).
At least in theory there can be multiple means remove power, some of
which may be less desirable. For example, some mechanisms may only
power off the CPU or the CPU card, while another may power off the
entire system. Others may really just execute a restart sequence
or drop into the ROM monitor. Using pm_power_off can also be racy
if the function pointer is set from a driver built as module, as the
driver may be in the process of being unloaded when pm_power_off is
called. If there are multiple power-off handlers in the system, removing
a module with such a handler may inadvertently reset the pointer to
pm_power_off to NULL, leaving the system with no means to remove power.

Introduce a system power-off handler call chain to solve the described
problems. This call chain is expected to be executed from the architecture
specific machine_power_off() function. Drivers and architeceture code
providing system power-off functionality are expected to register with
this call chain. When registering a power-off handler, callers can
provide a priority to control power-off handler execution sequence
and thus ensure that the power-off handler with the optimal capabilities
to remove power for a given system is called first.

Cc: Alan Cox <[email protected]>
Cc: Alexander Graf <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Heiko Stuebner <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: Len Brown <[email protected]>
Cc: Pavel Machek <[email protected]>
Cc: Philippe Rétornaz <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
Cc: Romain Perier <[email protected]>
Acked-by: Pavel Machek <[email protected]>
Acked-by: Heiko Stuebner <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
v5:
- Rebase to v3.18-rc3
v4:
- Do not use notifiers but internal functions and data structures to manage
the list of power-off handlers. Drop unused parameters from callbacks, and
make the power-off function type void.
Code to manage and walk the list of callbacks is derived from notifier.c.
v3:
- Rename new file to power_off_handler.c
- Replace poweroff in all newly introduced variables and in text
with power_off or power-off as appropriate
- Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
- Execute power-off handlers without any locks held
v2:
- poweroff -> power_off
- Add defines for default priorities
- Use raw notifiers protected by spinlocks instead of atomic notifiers
- Add register_poweroff_handler_simple
- Add devm_register_power_off_handler

include/linux/pm.h | 28 ++++
kernel/power/Makefile | 1 +
kernel/power/power_off_handler.c | 293 +++++++++++++++++++++++++++++++++++++++
3 files changed, 322 insertions(+)
create mode 100644 kernel/power/power_off_handler.c

diff --git a/include/linux/pm.h b/include/linux/pm.h
index 383fd68..a4d6bf8 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -35,6 +35,34 @@ extern void (*pm_power_off)(void);
extern void (*pm_power_off_prepare)(void);

struct device; /* we have a circular dep with device.h */
+
+/*
+ * Data structures and callbacks to manage power-off handlers
+ */
+
+struct power_off_handler_block {
+ void (*handler)(struct power_off_handler_block *);
+ struct power_off_handler_block __rcu *next;
+ int priority;
+};
+
+int register_power_off_handler(struct power_off_handler_block *);
+int devm_register_power_off_handler(struct device *,
+ struct power_off_handler_block *);
+int register_power_off_handler_simple(void (*function)(void), int priority);
+int unregister_power_off_handler(struct power_off_handler_block *);
+void do_kernel_power_off(void);
+bool have_kernel_power_off(void);
+
+/*
+ * Pre-defined power-off handler priorities
+ */
+#define POWER_OFF_PRIORITY_FALLBACK 0
+#define POWER_OFF_PRIORITY_LOW 64
+#define POWER_OFF_PRIORITY_DEFAULT 128
+#define POWER_OFF_PRIORITY_HIGH 192
+#define POWER_OFF_PRIORITY_HIGHEST 255
+
#ifdef CONFIG_VT_CONSOLE_SLEEP
extern void pm_vt_switch_required(struct device *dev, bool required);
extern void pm_vt_switch_unregister(struct device *dev);
diff --git a/kernel/power/Makefile b/kernel/power/Makefile
index 29472bf..567eda5 100644
--- a/kernel/power/Makefile
+++ b/kernel/power/Makefile
@@ -2,6 +2,7 @@
ccflags-$(CONFIG_PM_DEBUG) := -DDEBUG

obj-y += qos.o
+obj-y += power_off_handler.o
obj-$(CONFIG_PM) += main.o
obj-$(CONFIG_VT_CONSOLE_SLEEP) += console.o
obj-$(CONFIG_FREEZER) += process.o
diff --git a/kernel/power/power_off_handler.c b/kernel/power/power_off_handler.c
new file mode 100644
index 0000000..e576534
--- /dev/null
+++ b/kernel/power/power_off_handler.c
@@ -0,0 +1,293 @@
+/*
+ * kernel/power/power_off_handler.c - Power-off handling functions
+ *
+ * Copyright (c) 2014 Guenter Roeck
+ *
+ * List management code derived from kernel/notifier.c.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#define pr_fmt(fmt) "power-off: " fmt
+
+#include <linux/ctype.h>
+#include <linux/device.h>
+#include <linux/export.h>
+#include <linux/kallsyms.h>
+#include <linux/pm.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/types.h>
+
+/*
+ * List of handlers for kernel code which wants to be called
+ * to power off the system.
+ */
+static struct power_off_handler_block __rcu *power_off_handler_list;
+static DEFINE_SPINLOCK(power_off_handler_lock);
+
+/*
+ * Internal function to register power-off handler.
+ * Must be called with power-off spinlock acquired.
+ */
+static void _register_power_off_handler(struct power_off_handler_block *p)
+{
+ struct power_off_handler_block **pl = &power_off_handler_list;
+
+ while ((*pl) != NULL) {
+ if (p->priority > (*pl)->priority)
+ break;
+ pl = &((*pl)->next);
+ }
+ p->next = *pl;
+ rcu_assign_pointer(*pl, p);
+}
+
+/*
+ * Internal function to unregister a power-off handler.
+ * Must be called with power-off spinlock acquired.
+ */
+static int _unregister_power_off_handler(struct power_off_handler_block *p)
+{
+ struct power_off_handler_block **pl = &power_off_handler_list;
+
+ while ((*pl) != NULL) {
+ if ((*pl) == p) {
+ rcu_assign_pointer(*pl, p->next);
+ return 0;
+ }
+ pl = &((*pl)->next);
+ }
+ return -ENOENT;
+}
+
+/**
+ * register_power_off_handler - Register function to be called to power off
+ * the system
+ * @nb: Info about handler function to be called
+ * @nb->priority: Handler priority. Handlers should follow the
+ * following guidelines for setting priorities.
+ * 0: Power-off handler of last resort,
+ * with limited power-off capabilities,
+ * such as power-off handlers which
+ * do not really power off the system
+ * but loop forever or stop the CPU.
+ * 128: Default power-off handler; use if no other
+ * power-off handler is expected to be available,
+ * and/or if power-off functionality is
+ * sufficient to power off the entire system
+ * 255: Highest priority power-off handler, will
+ * preempt all other power-off handlers
+ *
+ * Registers a function with code to be called to power off the
+ * system.
+ *
+ * Registered functions will be called from machine_power_off as last
+ * step of the power-off sequence. Registered functions are expected
+ * to power off the system immediately. If more than one function is
+ * registered, the power-off handler priority selects which function
+ * will be called first.
+ *
+ * Power-off handlers may be registered from architecture code or from
+ * drivers. A typical use case would be a system where power off
+ * functionality is provided through a multi-function chip or through
+ * a programmable power controller. Multiple power-off handlers may exist;
+ * for example, one power-off handler might power off the entire system,
+ * while another only powers off the CPU card. In such cases, the
+ * power-off handler which only powers off part of the hardware is
+ * expected to register with low priority to ensure that it only
+ * runs if no other means to power off the system are available.
+ *
+ * Always returns zero.
+ */
+int register_power_off_handler(struct power_off_handler_block *pb)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&power_off_handler_lock, flags);
+ _register_power_off_handler(pb);
+ spin_unlock_irqrestore(&power_off_handler_lock, flags);
+
+ return 0;
+}
+EXPORT_SYMBOL(register_power_off_handler);
+
+/**
+ * unregister_power_off_handler - Unregister previously registered
+ * power-off handler
+ * @nb: Hook to be unregistered
+ *
+ * Unregisters a previously registered power-off handler function.
+ *
+ * Returns zero on success, or %-ENOENT on failure.
+ */
+int unregister_power_off_handler(struct power_off_handler_block *pb)
+{
+ unsigned long flags;
+ int ret;
+
+ spin_lock_irqsave(&power_off_handler_lock, flags);
+ ret = _unregister_power_off_handler(pb);
+ spin_unlock_irqrestore(&power_off_handler_lock, flags);
+
+ return ret;
+}
+EXPORT_SYMBOL(unregister_power_off_handler);
+
+struct _power_off_handler_data {
+ void (*handler)(void);
+ struct power_off_handler_block power_off_hb;
+};
+
+static void _power_off_handler(struct power_off_handler_block *this)
+{
+ struct _power_off_handler_data *poh =
+ container_of(this, struct _power_off_handler_data,
+ power_off_hb);
+
+ poh->handler();
+}
+
+static struct _power_off_handler_data power_off_handler_data;
+
+/**
+ * register_power_off_handler_simple - Register function to be called
+ * to power off the system
+ * @handler: Function to be called to power off the system
+ * @priority: Handler priority. For priority guidelines see
+ * register_power_off_handler.
+ *
+ * This is a simplified version of register_power_off_handler. It does
+ * not take a power-off handler as argument, but a function pointer.
+ * The function registers a power-off handler with specified priority.
+ * Power-off handlers registered with this function can not be
+ * unregistered, and only a single power-off handler can be installed
+ * using it.
+ *
+ * This function must not be called from modules and is therefore
+ * not exported.
+ *
+ * Returns %-EBUSY if a power-off handler has already been registered
+ * using register_power_off_handler_simple. Otherwise returns zero.
+ */
+int register_power_off_handler_simple(void (*handler)(void), int priority)
+{
+ unsigned long flags;
+ int ret = 0;
+
+ spin_lock_irqsave(&power_off_handler_lock, flags);
+
+ if (power_off_handler_data.handler) {
+ pr_warn("Power-off function already registered (%ps), cannot register %ps",
+ power_off_handler_data.handler, handler);
+ ret = -EBUSY;
+ goto abort;
+ }
+
+ power_off_handler_data.handler = handler;
+ power_off_handler_data.power_off_hb.handler = _power_off_handler;
+ power_off_handler_data.power_off_hb.priority = priority;
+
+ _register_power_off_handler(&power_off_handler_data.power_off_hb);
+abort:
+ spin_unlock_irqrestore(&power_off_handler_lock, flags);
+ return ret;
+}
+
+/* Device managed power-off handler registration */
+
+static void devm_power_off_release(struct device *dev, void *res)
+{
+ struct power_off_handler_block *hb;
+
+ hb = *(struct power_off_handler_block **)res;
+ unregister_power_off_handler(hb);
+}
+
+/**
+ * devm_register_power_off_handler - Register function to be called
+ * to power off the system
+ * @dev: The device registering the power-off handler.
+ * @handler: Function to be called to power off the system
+ * @priority: Handler priority. For priority guidelines see
+ * register_power_off_handler.
+ *
+ * This is the device managed version of register_power_off_handler.
+ *
+ * Returns %-EINVAL if dev is NULL. Returns %-ENOMEM if the system is
+ * out of memory. Otherwise returns zero.
+ */
+int devm_register_power_off_handler(struct device *dev,
+ struct power_off_handler_block *hb)
+{
+ struct power_off_handler_block **ptr;
+ unsigned long flags;
+
+ if (!dev)
+ return -EINVAL;
+
+ ptr = devres_alloc(devm_power_off_release, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return -ENOMEM;
+
+ spin_lock_irqsave(&power_off_handler_lock, flags);
+ _register_power_off_handler(hb);
+ spin_unlock_irqrestore(&power_off_handler_lock, flags);
+
+ *ptr = hb;
+ devres_add(dev, ptr);
+ return 0;
+}
+EXPORT_SYMBOL(devm_register_power_off_handler);
+
+/**
+ * do_kernel_power_off - Execute kernel power-off handler call chain
+ *
+ * Calls functions registered with register_power_off_handler.
+ *
+ * Expected to be called from machine_power_off as last step of
+ * the power-off sequence.
+ *
+ * Powers the system off immediately if a power-off handler function
+ * has been registered. Otherwise does nothing.
+ */
+void do_kernel_power_off(void)
+{
+ struct power_off_handler_block *p, *next_p;
+
+ /*
+ * No locking. This code can be called from both atomic and non-atomic
+ * context, with interrupts enabled or disabled, depending on the
+ * architecture and platform.
+ *
+ * Power-off handler registration and de-registration are executed in
+ * atomic context with interrupts disabled, which guarantees that
+ * do_kernel_power_off() will not be called while a power-off handler
+ * is installed or removed.
+ * There is a theoretic risc that a power-off handler is installed or
+ * removed while the call chain is traversed, but we'll have to accept
+ * that risk.
+ */
+
+ p = rcu_dereference_raw(power_off_handler_list);
+ while (p) {
+ next_p = rcu_dereference_raw(p->next);
+ p->handler(p);
+ p = next_p;
+ }
+}
+
+/**
+ * have_kernel_power_off() - Check if kernel power-off handler is available
+ *
+ * Returns true if a kernel power-off handler is available, false otherwise.
+ */
+bool have_kernel_power_off(void)
+{
+ return pm_power_off != NULL ||
+ rcu_dereference_raw(power_off_handler_list) != NULL;
+}
+EXPORT_SYMBOL(have_kernel_power_off);
--
1.9.1

2014-11-06 17:08:25

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 00/48] kernel: Add support for power-off handler call chain

On Thu, Nov 06, 2014 at 08:42:44AM -0800, Guenter Roeck wrote:
> Various drivers implement architecture and/or device specific means to
> remove power from the system. For the most part, those drivers set the
> global variable pm_power_off to point to a function within the driver.
>
> This mechanism has a number of drawbacks. Typically only one means
> to remove power is supported (at least if pm_power_off is used).
> At least in theory there can be multiple means to remove power, some of
> which may be less desirable. For example, one mechanism might power off the
> entire system through an I/O port or gpio pin, while another might power off
> a board by disabling its power controller. Other mechanisms may really just
> execute a restart sequence or drop into the ROM monitor, or put the CPU into
> sleep mode. Using pm_power_off can also be racy if the function pointer is
> set from a driver built as module, as the driver may be in the process of
> being unloaded when pm_power_off is called. If there are multiple power-off
> handlers in the system, removing a module with such a handler may
> inadvertently reset the pointer to pm_power_off to NULL, leaving the system
> with no means to remove power.
>
> Introduce a system power-off handler call chain to solve the described
> problems. This call chain is expected to be executed from the architecture
> specific machine_power_off() function. Drivers providing system power-off
> functionality are expected to register with this call chain. By using the
> priority field in the notifier block, callers can control power-off handler
> execution sequence and thus ensure that the power-off handler with the
> optimal capabilities to remove power for a given system is called first.
> A call chain instead of a single call to the highest priority handler is
> used to provide fallback: If multiple power-off handlers are installed,
> all handlers will be called until one actually succeeds to power off the
> system.
>
> Patch 01/48 implements the power-off handler API.
>
> Patches 02/48 to 04/48 are cleanup patches to prepare for the move of
> pm_power_off to a common location.
>
> Patches 05/48 to 07/48 remove references to pm_power_off from devicetree
> bindings descriptions.
>
> Patch 08/48 moves the pm_power_off variable from architecture code to
> kernel/reboot.c.
>
> Patches 09/48 to 34/48 convert various drivers to register with the kernel
> power-off handler instead of setting pm_power_off directly.
>
> Patches 35/48 to 47/48 do the same for architecture code.
>
> Patch 48/48 finally removes pm_power_off.
>
> For the most part, the individual patches include explanations why specific
> priorities were chosen, at least if the selected priority is not the default
> priority. Subsystem and architecture maintainers are encouraged to have a look
> at the selected priorities and suggest improvements.
>
> I ran the final code through my normal build and qemu tests. Results are
> available at http://server.roeck-us.net:8010/builders in the 'poweroff-handler'
> column. I also built all available configurations for arm, mips, powerpc,
> m68k, and sh architectures.
>
> The series is available in branch poweroff-handler of my repository at
> git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git.
> It is based on 3.18-rc3 plus the power-off tracking branch from
> git://git.kernel.org/pub/scm/linux/kernel/git/mpe/linux.git (to merge
> powerpc related power-off changes).
>
> A note on Cc: In the initial submission I had way too many Cc:, causing the
> patchset to be treated as spam by many mailers and mailing list handlers,
> which of course defeated the purpose. Starting with v3, the distribution
> list has been cut down significantly. Copied mailing lists and individuals are
> for the most part generated from the output of get_maintainer.pl for each
> individual patch. My apologies to anyone I may have failed to copy; if you
> believe that some additional individuals or mailing lists should be copied
> on the entire series or on individual patches, please let me know.
>
> Merge plan is to send the entire series directly to Linus during the next commit
> window, except for the last patch. The last patch would then be part of another
> pull request after -rc1, which would include any changes necessary due to newly
> merged power-off handling code.
>

I should have added that I plan to have the series (except for the last patch)
added to -next shortly.

Linus,

are you ok with this plan ?

Thanks,
Guenter

> v5:
> - Rebased series to v3.18-rc3
> - Merge remote-tracking branch 'power/topic/pm-power-off'
> from git://git.kernel.org/pub/scm/linux/kernel/git/mpe/linux.git
> and implement powerpc conversion (patch 41/48).
> v4:
> - Do not use notifiers but internal functions and data structures to manage
> the list of power-off handlers. Drop unused parameters from callbacks, and
> make the power-off function type void.
> Code to manage and walk the list of callbacks was derived from notifier.c.
> Note that only patch 01/47 was sent for review of this version.
> v3:
> - Rebased series to v3.18-rc2.
> - Do not hold any locks while executing the power-off call chain.
> This ensures that power-off handlers are executed in the state
> selected by the machine_power_off function for a given architecture,
> ie without changing the current semantics of power-off callbacks and
> machine_power_off functions.
> Power-off handler registration and de-registration is handled in atomic
> context with interrupts disabled to ensure that those functions are not
> interrupted by code which powers off the system.
> - Use [xxx_]power_off[_xxx] instead of [xxx_]poweroff[_xxx] for newly
> introduced function and variable names.
> - Use power-off instead of poweroff in descriptive text and comments.
> - Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
> - Use ACPI: instead of acpi: for messages in acpi code.
> v2:
> - Rebased series to v3.18-rc1.
> - Use raw notifier with spinlock protection instead of atomic notifiers,
> since some power-off handlers need to have interrupts enabled.
> - Renamed API functions from _poweroff to _power_off.
> - Added various Acks.
> - Build tested all configurations for arm, powerpc, and mips architectures.
> - Fixed two compile errors in mips patch.
> - Replaced dev_err and pr_err with dev_warn and pr_warn if an error is not
> fatal.
> - Provide managed resources API and use where appropriate.
> - Provide and use definitions for standard priorities.
> - Added patches to convert newly introduced power-off handlers.
> - Various minor changes.
> v1 (from RFC):
> - Move API to new file kernel/power/power_off_handler.c.
> - Move pm_power_off pointer to kernel/power/power_off_handler.c. Call
> pm_power_off from do_kernel_power_off, and only call do_kernel_power_off
> from architecture code instead of calling both pm_power_off and
> do_kernel_power_off.
> - Provide additional API function register_power_off_handler_simple
> to simplify conversion of architecture code.
> - Provide additional API function have_kernel_power_off to check if
> a power-off handler was installed.
> - Convert all drivers and architecture code to use the new API.
> - Remove pm_power_off as last patch of the series.
>
> Cc: Alan Cox <[email protected]>
> Cc: Alexander Graf <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Cc: Geert Uytterhoeven <[email protected]>
> cc: Heiko Stuebner <[email protected]>
> Cc: Lee Jones <[email protected]>
> Cc: Len Brown <[email protected]>
> Cc: Linus Torvalds <[email protected]>
> Cc: Pavel Machek <[email protected]>
> Cc: Rafael J. Wysocki <[email protected]>
> Cc: Romain Perier <[email protected]>

2014-11-06 17:23:11

by Mark Rutland

[permalink] [raw]
Subject: Re: [PATCH v5 36/48] arm64: psci: Register with kernel power-off handler

On Thu, Nov 06, 2014 at 04:43:20PM +0000, Guenter Roeck wrote:
> Register with kernel power-off handler instead of setting pm_power_off
> directly.
>
> Cc: Catalin Marinas <[email protected]>
> Cc: Will Deacon <[email protected]>
> Acked-by: Catalin Marinas <[email protected]>
> Signed-off-by: Guenter Roeck <[email protected]>

I just fetched your current poweroff-handler branch and gave it a spin
on Juno. It looks like this hasn't broken since the last time I tried
it. :)

Tested-by: Mark Rutland <[email protected]>

Thanks,
Mark.

> ---
> v5:
> - Rebase to v3.18-rc3
> v4:
> - No change
> v3:
> - Replace poweroff in all newly introduced variables and in text
> with power_off or power-off as appropriate
> - Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
> v2:
> - Use define to specify poweroff handler priority
>
> arch/arm64/kernel/psci.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm64/kernel/psci.c b/arch/arm64/kernel/psci.c
> index 866c1c8..5cab066 100644
> --- a/arch/arm64/kernel/psci.c
> +++ b/arch/arm64/kernel/psci.c
> @@ -359,7 +359,8 @@ static int __init psci_0_2_init(struct device_node *np)
>
> arm_pm_restart = psci_sys_reset;
>
> - pm_power_off = psci_sys_poweroff;
> + register_power_off_handler_simple(psci_sys_poweroff,
> + POWER_OFF_PRIORITY_DEFAULT);
>
> out_put_node:
> of_node_put(np);
> --
> 1.9.1
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>

2014-11-06 18:02:56

by Linus Torvalds

[permalink] [raw]
Subject: Re: [PATCH v5 00/48] kernel: Add support for power-off handler call chain

On Thu, Nov 6, 2014 at 9:08 AM, Guenter Roeck <[email protected]> wrote:
>>
>> Merge plan is to send the entire series directly to Linus during the next commit
>> window, except for the last patch. The last patch would then be part of another
>> pull request after -rc1, which would include any changes necessary due to newly
>> merged power-off handling code.
>
> I should have added that I plan to have the series (except for the last patch)
> added to -next shortly.
>
> Linus,
>
> are you ok with this plan ?

Do people actually agree that the code makes sense at all?

Because quite frankly, every time somebody adds this kind of "register
callback" stuff, the end result tends to end up being an unmitigated
disaster. People care about ordering etc, and there seems to be no
sane support for that. Then people do random ugly hacks for their
insane platforms. You already did that by having the "priority" thing,
but that just makes me think that people will pick random priorities.
TYou seem to even *encourage* that random behavior by spreading out
the "named" priorities, so that people can randomly say "I'm one
higher than LOW".

What kind of games are the actual new users already doing wrt this? I
have a bad feeling about it all.

Linus

2014-11-06 18:48:51

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 00/48] kernel: Add support for power-off handler call chain

On Thu, Nov 06, 2014 at 10:02:54AM -0800, Linus Torvalds wrote:
> On Thu, Nov 6, 2014 at 9:08 AM, Guenter Roeck <[email protected]> wrote:
> >>
> >> Merge plan is to send the entire series directly to Linus during the next commit
> >> window, except for the last patch. The last patch would then be part of another
> >> pull request after -rc1, which would include any changes necessary due to newly
> >> merged power-off handling code.
> >
> > I should have added that I plan to have the series (except for the last patch)
> > added to -next shortly.
> >
> > Linus,
> >
> > are you ok with this plan ?
>
> Do people actually agree that the code makes sense at all?
>
The series has Acks from 24 different people, so I would think
that there is a decent level of agreement.

> Because quite frankly, every time somebody adds this kind of "register
> callback" stuff, the end result tends to end up being an unmitigated
> disaster. People care about ordering etc, and there seems to be no
> sane support for that. Then people do random ugly hacks for their
> insane platforms. You already did that by having the "priority" thing,
> but that just makes me think that people will pick random priorities.
> TYou seem to even *encourage* that random behavior by spreading out
> the "named" priorities, so that people can randomly say "I'm one
> higher than LOW".
>
Yes, that is actually the idea. Keep in mind this is for power-off, so
(hopefully) only the handler with highest priority will actually be executed.
The larger number space is an added benefit here, not a disadvantage -
I _want_ people to be able to say "my priority is one higher than X because
I _want_ this method to power off the system to be tried first".

> What kind of games are the actual new users already doing wrt this? I
> have a bad feeling about it all.

Currently there is a single exported pointer, "pm_power_off", which is set
by architecture code and various drivers, and called from machine_power_off
to turn off power. 'git grep "pm_power_off =" | wc' returns 146, so there
are a lot of those. In linux-next the number is 150, so there are now four
more (all in drivers if I recall correctly). A patch pending for powerpc,
which targets the possibility that there can be more than one power-off
handler for this architecture, will increase the number by another 21.

Sometimes the pm_power_off pointer it is set conditionally if it is non-null,
sometimes it is set unconditionally. Sometimes it is set from drivers
and cleared to NULL on unload, sometimes those drivers restore the previous
setting, sometimes the drivers do not clear the pointer at all on unload.

The point here is that the _current_ solution has a problem, since there can
be more than one power-off handler in a system, there is no ordering at all,
and insertion/removal is racy. The priority field is trying to introduce some
execution order. If multiple handlers install a handler with the same priority,
it does not matter (much) since all handlers will be executed, and one will
hopefully succeed to power off the system. Ultimately, the priority is just
an added benefit - much more importantly, the code is not racy anymore.
Sure, people can say "my power-off priority is one above LOW", but that only
means that the code will be executed before the handler(s) with priority "LOW"
are executed. Hopefully one of them really powers off the system. Note in this
context that I introduced the named priorities because several reviewers asked
for it. The original code used notifier callbacks and numbered priorities
as specified for notifiers.

Having said that, the new solution may not be perfect, but it is the best
I have been able come up with. If you have a better idea for being able to
support multiple power-off handlers with different priorities, with non-racy
registration and unregistration, please let me know, and I'll be happy to
implement it.

Thanks,
Guenter

2014-11-06 18:52:10

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 36/48] arm64: psci: Register with kernel power-off handler

On Thu, Nov 06, 2014 at 05:22:23PM +0000, Mark Rutland wrote:
> On Thu, Nov 06, 2014 at 04:43:20PM +0000, Guenter Roeck wrote:
> > Register with kernel power-off handler instead of setting pm_power_off
> > directly.
> >
> > Cc: Catalin Marinas <[email protected]>
> > Cc: Will Deacon <[email protected]>
> > Acked-by: Catalin Marinas <[email protected]>
> > Signed-off-by: Guenter Roeck <[email protected]>
>
> I just fetched your current poweroff-handler branch and gave it a spin
> on Juno. It looks like this hasn't broken since the last time I tried
> it. :)
>
> Tested-by: Mark Rutland <[email protected]>
>
Thanks a lot!

Guenter

2014-11-06 22:10:17

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v5 01/48] kernel: Add support for power-off handler call chain

On Thursday, November 06, 2014 08:42:45 AM Guenter Roeck wrote:
> Various drivers implement architecture and/or device specific means to
> power off the system. For the most part, those drivers set the global
> variable pm_power_off to point to a function within the driver.
>
> This mechanism has a number of drawbacks. Typically only one scheme
> to remove power is supported (at least if pm_power_off is used).
> At least in theory there can be multiple means remove power, some of
> which may be less desirable. For example, some mechanisms may only
> power off the CPU or the CPU card, while another may power off the
> entire system. Others may really just execute a restart sequence
> or drop into the ROM monitor. Using pm_power_off can also be racy
> if the function pointer is set from a driver built as module, as the
> driver may be in the process of being unloaded when pm_power_off is
> called. If there are multiple power-off handlers in the system, removing
> a module with such a handler may inadvertently reset the pointer to
> pm_power_off to NULL, leaving the system with no means to remove power.
>
> Introduce a system power-off handler call chain to solve the described
> problems. This call chain is expected to be executed from the architecture
> specific machine_power_off() function. Drivers and architeceture code
> providing system power-off functionality are expected to register with
> this call chain. When registering a power-off handler, callers can
> provide a priority to control power-off handler execution sequence
> and thus ensure that the power-off handler with the optimal capabilities
> to remove power for a given system is called first.
>
> Cc: Alan Cox <[email protected]>
> Cc: Alexander Graf <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Cc: Geert Uytterhoeven <[email protected]>
> Cc: Heiko Stuebner <[email protected]>
> Cc: Lee Jones <[email protected]>
> Cc: Len Brown <[email protected]>
> Cc: Pavel Machek <[email protected]>
> Cc: Philippe Rétornaz <[email protected]>
> Cc: Rafael J. Wysocki <[email protected]>
> Cc: Romain Perier <[email protected]>
> Acked-by: Pavel Machek <[email protected]>
> Acked-by: Heiko Stuebner <[email protected]>
> Signed-off-by: Guenter Roeck <[email protected]>
> ---
> v5:
> - Rebase to v3.18-rc3
> v4:
> - Do not use notifiers but internal functions and data structures to manage
> the list of power-off handlers. Drop unused parameters from callbacks, and
> make the power-off function type void.
> Code to manage and walk the list of callbacks is derived from notifier.c.
> v3:
> - Rename new file to power_off_handler.c
> - Replace poweroff in all newly introduced variables and in text
> with power_off or power-off as appropriate
> - Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
> - Execute power-off handlers without any locks held
> v2:
> - poweroff -> power_off
> - Add defines for default priorities
> - Use raw notifiers protected by spinlocks instead of atomic notifiers
> - Add register_poweroff_handler_simple
> - Add devm_register_power_off_handler
>
> include/linux/pm.h | 28 ++++
> kernel/power/Makefile | 1 +
> kernel/power/power_off_handler.c | 293 +++++++++++++++++++++++++++++++++++++++
> 3 files changed, 322 insertions(+)
> create mode 100644 kernel/power/power_off_handler.c
>
> diff --git a/include/linux/pm.h b/include/linux/pm.h
> index 383fd68..a4d6bf8 100644
> --- a/include/linux/pm.h
> +++ b/include/linux/pm.h
> @@ -35,6 +35,34 @@ extern void (*pm_power_off)(void);
> extern void (*pm_power_off_prepare)(void);
>
> struct device; /* we have a circular dep with device.h */
> +
> +/*
> + * Data structures and callbacks to manage power-off handlers
> + */
> +
> +struct power_off_handler_block {
> + void (*handler)(struct power_off_handler_block *);
> + struct power_off_handler_block __rcu *next;
> + int priority;
> +};
> +
> +int register_power_off_handler(struct power_off_handler_block *);
> +int devm_register_power_off_handler(struct device *,
> + struct power_off_handler_block *);
> +int register_power_off_handler_simple(void (*function)(void), int priority);
> +int unregister_power_off_handler(struct power_off_handler_block *);
> +void do_kernel_power_off(void);
> +bool have_kernel_power_off(void);
> +
> +/*
> + * Pre-defined power-off handler priorities
> + */
> +#define POWER_OFF_PRIORITY_FALLBACK 0
> +#define POWER_OFF_PRIORITY_LOW 64
> +#define POWER_OFF_PRIORITY_DEFAULT 128
> +#define POWER_OFF_PRIORITY_HIGH 192
> +#define POWER_OFF_PRIORITY_HIGHEST 255

I'm not sure why we need these gaps in the priority space.

I guess it might be possible to use

enum power_off_priority {
POWER_OFF_PRIORITY_FALLBACK = 0,
POWER_OFF_PRIORITY_LOW,
POWER_OFF_PRIORITY_DEFAULT,
POWER_OFF_PRIORITY_HIGH,
POWER_OFF_PRIORITY_HIGHEST,
POWER_OFF_PRIORITY_LIMIT,
};

and then make register_ complain if priority is POWER_OFF_PRIORITY_LIMIT
or greater.

But I'm OK with the rest, so if no one else sees a problem here,
I'm not going to make a fuss about it.

Rafael

2014-11-06 22:11:43

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v5 34/48] acpi: Register power-off handler with kernel power-off handler

On Thursday, November 06, 2014 08:43:18 AM Guenter Roeck wrote:
> Register with kernel power-off handler instead of setting pm_power_off
> directly. Register with high priority to reflect that the driver explicitly
> overrides existing power-off handlers.
>
> Cc: Rafael J. Wysocki <[email protected]>
> Cc: Len Brown <[email protected]>
> Signed-off-by: Guenter Roeck <[email protected]>

That's fine by me.

Rafael


> ---
> v5:
> - Rebase to v3.18-rc3
> v4:
> - Do not use notifiers but internal functions and data structures to manage
> the list of power-off handlers. Drop unused parameters from callbacks, and
> make the power-off function type void
> v3:
> - Replace poweroff in all newly introduced variables and in text
> with power_off or power-off as appropriate
> - Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
> - Replace acpi: with ACPI: in log message
> v2:
> - Use define to specify poweroff handler priority
> - Use pr_warn instead of pr_err
>
> drivers/acpi/sleep.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
> index 05a31b5..a73cfad 100644
> --- a/drivers/acpi/sleep.c
> +++ b/drivers/acpi/sleep.c
> @@ -16,6 +16,7 @@
> #include <linux/device.h>
> #include <linux/interrupt.h>
> #include <linux/suspend.h>
> +#include <linux/pm.h>
> #include <linux/reboot.h>
> #include <linux/acpi.h>
> #include <linux/module.h>
> @@ -827,7 +828,7 @@ static void acpi_power_off_prepare(void)
> acpi_disable_all_gpes();
> }
>
> -static void acpi_power_off(void)
> +static void acpi_power_off(struct power_off_handler_block *this)
> {
> /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
> printk(KERN_DEBUG "%s called\n", __func__);
> @@ -835,6 +836,11 @@ static void acpi_power_off(void)
> acpi_enter_sleep_state(ACPI_STATE_S5);
> }
>
> +static struct power_off_handler_block acpi_power_off_hb = {
> + .handler = acpi_power_off,
> + .priority = POWER_OFF_PRIORITY_HIGH,
> +};
> +
> int __init acpi_sleep_init(void)
> {
> char supported[ACPI_S_STATE_COUNT * 3 + 1];
> @@ -851,7 +857,8 @@ int __init acpi_sleep_init(void)
> if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
> sleep_states[ACPI_STATE_S5] = 1;
> pm_power_off_prepare = acpi_power_off_prepare;
> - pm_power_off = acpi_power_off;
> + if (register_power_off_handler(&acpi_power_off_hb))
> + pr_warn("ACPI: Failed to register power-off handler\n");
> }
>
> supported[0] = 0;
>

--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2014-11-06 22:27:14

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 01/48] kernel: Add support for power-off handler call chain

On Thu, Nov 06, 2014 at 11:30:59PM +0100, Rafael J. Wysocki wrote:
> On Thursday, November 06, 2014 08:42:45 AM Guenter Roeck wrote:
> > Various drivers implement architecture and/or device specific means to
> > power off the system. For the most part, those drivers set the global
> > variable pm_power_off to point to a function within the driver.
> >
> > This mechanism has a number of drawbacks. Typically only one scheme
> > to remove power is supported (at least if pm_power_off is used).
> > At least in theory there can be multiple means remove power, some of
> > which may be less desirable. For example, some mechanisms may only
> > power off the CPU or the CPU card, while another may power off the
> > entire system. Others may really just execute a restart sequence
> > or drop into the ROM monitor. Using pm_power_off can also be racy
> > if the function pointer is set from a driver built as module, as the
> > driver may be in the process of being unloaded when pm_power_off is
> > called. If there are multiple power-off handlers in the system, removing
> > a module with such a handler may inadvertently reset the pointer to
> > pm_power_off to NULL, leaving the system with no means to remove power.
> >
> > Introduce a system power-off handler call chain to solve the described
> > problems. This call chain is expected to be executed from the architecture
> > specific machine_power_off() function. Drivers and architeceture code
> > providing system power-off functionality are expected to register with
> > this call chain. When registering a power-off handler, callers can
> > provide a priority to control power-off handler execution sequence
> > and thus ensure that the power-off handler with the optimal capabilities
> > to remove power for a given system is called first.
> >
> > Cc: Alan Cox <[email protected]>
> > Cc: Alexander Graf <[email protected]>
> > Cc: Andrew Morton <[email protected]>
> > Cc: Geert Uytterhoeven <[email protected]>
> > Cc: Heiko Stuebner <[email protected]>
> > Cc: Lee Jones <[email protected]>
> > Cc: Len Brown <[email protected]>
> > Cc: Pavel Machek <[email protected]>
> > Cc: Philippe R?tornaz <[email protected]>
> > Cc: Rafael J. Wysocki <[email protected]>
> > Cc: Romain Perier <[email protected]>
> > Acked-by: Pavel Machek <[email protected]>
> > Acked-by: Heiko Stuebner <[email protected]>
> > Signed-off-by: Guenter Roeck <[email protected]>
> > ---
> > v5:
> > - Rebase to v3.18-rc3
> > v4:
> > - Do not use notifiers but internal functions and data structures to manage
> > the list of power-off handlers. Drop unused parameters from callbacks, and
> > make the power-off function type void.
> > Code to manage and walk the list of callbacks is derived from notifier.c.
> > v3:
> > - Rename new file to power_off_handler.c
> > - Replace poweroff in all newly introduced variables and in text
> > with power_off or power-off as appropriate
> > - Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
> > - Execute power-off handlers without any locks held
> > v2:
> > - poweroff -> power_off
> > - Add defines for default priorities
> > - Use raw notifiers protected by spinlocks instead of atomic notifiers
> > - Add register_poweroff_handler_simple
> > - Add devm_register_power_off_handler
> >
> > include/linux/pm.h | 28 ++++
> > kernel/power/Makefile | 1 +
> > kernel/power/power_off_handler.c | 293 +++++++++++++++++++++++++++++++++++++++
> > 3 files changed, 322 insertions(+)
> > create mode 100644 kernel/power/power_off_handler.c
> >
> > diff --git a/include/linux/pm.h b/include/linux/pm.h
> > index 383fd68..a4d6bf8 100644
> > --- a/include/linux/pm.h
> > +++ b/include/linux/pm.h
> > @@ -35,6 +35,34 @@ extern void (*pm_power_off)(void);
> > extern void (*pm_power_off_prepare)(void);
> >
> > struct device; /* we have a circular dep with device.h */
> > +
> > +/*
> > + * Data structures and callbacks to manage power-off handlers
> > + */
> > +
> > +struct power_off_handler_block {
> > + void (*handler)(struct power_off_handler_block *);
> > + struct power_off_handler_block __rcu *next;
> > + int priority;
> > +};
> > +
> > +int register_power_off_handler(struct power_off_handler_block *);
> > +int devm_register_power_off_handler(struct device *,
> > + struct power_off_handler_block *);
> > +int register_power_off_handler_simple(void (*function)(void), int priority);
> > +int unregister_power_off_handler(struct power_off_handler_block *);
> > +void do_kernel_power_off(void);
> > +bool have_kernel_power_off(void);
> > +
> > +/*
> > + * Pre-defined power-off handler priorities
> > + */
> > +#define POWER_OFF_PRIORITY_FALLBACK 0
> > +#define POWER_OFF_PRIORITY_LOW 64
> > +#define POWER_OFF_PRIORITY_DEFAULT 128
> > +#define POWER_OFF_PRIORITY_HIGH 192
> > +#define POWER_OFF_PRIORITY_HIGHEST 255
>
> I'm not sure why we need these gaps in the priority space.
>
> I guess it might be possible to use
>
> enum power_off_priority {
> POWER_OFF_PRIORITY_FALLBACK = 0,
> POWER_OFF_PRIORITY_LOW,
> POWER_OFF_PRIORITY_DEFAULT,
> POWER_OFF_PRIORITY_HIGH,
> POWER_OFF_PRIORITY_HIGHEST,
> POWER_OFF_PRIORITY_LIMIT,
> };

I retained the large number space on purpose, specifically to permit in-between
priorities. In other words, I want people to be able to say "priority for this
handler is higher than low but lower than default". After all, the defines were
intended as hints, not as a "Thou shall use those and only those priorities".

Having said that, the important part is to get the series accepted, so I won't
argue if that is what it takes to get an Ack. Let me know.

Thanks,
Guenter

>
> and then make register_ complain if priority is POWER_OFF_PRIORITY_LIMIT
> or greater.
>
> But I'm OK with the rest, so if no one else sees a problem here,
> I'm not going to make a fuss about it.
>
> Rafael
>

2014-11-06 23:56:10

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v5 01/48] kernel: Add support for power-off handler call chain

On Thursday, November 06, 2014 02:27:03 PM Guenter Roeck wrote:
> On Thu, Nov 06, 2014 at 11:30:59PM +0100, Rafael J. Wysocki wrote:
> > On Thursday, November 06, 2014 08:42:45 AM Guenter Roeck wrote:
> > > Various drivers implement architecture and/or device specific means to
> > > power off the system. For the most part, those drivers set the global
> > > variable pm_power_off to point to a function within the driver.
> > >
> > > This mechanism has a number of drawbacks. Typically only one scheme
> > > to remove power is supported (at least if pm_power_off is used).
> > > At least in theory there can be multiple means remove power, some of
> > > which may be less desirable. For example, some mechanisms may only
> > > power off the CPU or the CPU card, while another may power off the
> > > entire system. Others may really just execute a restart sequence
> > > or drop into the ROM monitor. Using pm_power_off can also be racy
> > > if the function pointer is set from a driver built as module, as the
> > > driver may be in the process of being unloaded when pm_power_off is
> > > called. If there are multiple power-off handlers in the system, removing
> > > a module with such a handler may inadvertently reset the pointer to
> > > pm_power_off to NULL, leaving the system with no means to remove power.
> > >
> > > Introduce a system power-off handler call chain to solve the described
> > > problems. This call chain is expected to be executed from the architecture
> > > specific machine_power_off() function. Drivers and architeceture code
> > > providing system power-off functionality are expected to register with
> > > this call chain. When registering a power-off handler, callers can
> > > provide a priority to control power-off handler execution sequence
> > > and thus ensure that the power-off handler with the optimal capabilities
> > > to remove power for a given system is called first.
> > >
> > > Cc: Alan Cox <[email protected]>
> > > Cc: Alexander Graf <[email protected]>
> > > Cc: Andrew Morton <[email protected]>
> > > Cc: Geert Uytterhoeven <[email protected]>
> > > Cc: Heiko Stuebner <[email protected]>
> > > Cc: Lee Jones <[email protected]>
> > > Cc: Len Brown <[email protected]>
> > > Cc: Pavel Machek <[email protected]>
> > > Cc: Philippe Rétornaz <[email protected]>
> > > Cc: Rafael J. Wysocki <[email protected]>
> > > Cc: Romain Perier <[email protected]>
> > > Acked-by: Pavel Machek <[email protected]>
> > > Acked-by: Heiko Stuebner <[email protected]>
> > > Signed-off-by: Guenter Roeck <[email protected]>
> > > ---
> > > v5:
> > > - Rebase to v3.18-rc3
> > > v4:
> > > - Do not use notifiers but internal functions and data structures to manage
> > > the list of power-off handlers. Drop unused parameters from callbacks, and
> > > make the power-off function type void.
> > > Code to manage and walk the list of callbacks is derived from notifier.c.
> > > v3:
> > > - Rename new file to power_off_handler.c
> > > - Replace poweroff in all newly introduced variables and in text
> > > with power_off or power-off as appropriate
> > > - Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
> > > - Execute power-off handlers without any locks held
> > > v2:
> > > - poweroff -> power_off
> > > - Add defines for default priorities
> > > - Use raw notifiers protected by spinlocks instead of atomic notifiers
> > > - Add register_poweroff_handler_simple
> > > - Add devm_register_power_off_handler
> > >
> > > include/linux/pm.h | 28 ++++
> > > kernel/power/Makefile | 1 +
> > > kernel/power/power_off_handler.c | 293 +++++++++++++++++++++++++++++++++++++++
> > > 3 files changed, 322 insertions(+)
> > > create mode 100644 kernel/power/power_off_handler.c
> > >
> > > diff --git a/include/linux/pm.h b/include/linux/pm.h
> > > index 383fd68..a4d6bf8 100644
> > > --- a/include/linux/pm.h
> > > +++ b/include/linux/pm.h
> > > @@ -35,6 +35,34 @@ extern void (*pm_power_off)(void);
> > > extern void (*pm_power_off_prepare)(void);
> > >
> > > struct device; /* we have a circular dep with device.h */
> > > +
> > > +/*
> > > + * Data structures and callbacks to manage power-off handlers
> > > + */
> > > +
> > > +struct power_off_handler_block {
> > > + void (*handler)(struct power_off_handler_block *);
> > > + struct power_off_handler_block __rcu *next;
> > > + int priority;
> > > +};
> > > +
> > > +int register_power_off_handler(struct power_off_handler_block *);
> > > +int devm_register_power_off_handler(struct device *,
> > > + struct power_off_handler_block *);
> > > +int register_power_off_handler_simple(void (*function)(void), int priority);
> > > +int unregister_power_off_handler(struct power_off_handler_block *);
> > > +void do_kernel_power_off(void);
> > > +bool have_kernel_power_off(void);
> > > +
> > > +/*
> > > + * Pre-defined power-off handler priorities
> > > + */
> > > +#define POWER_OFF_PRIORITY_FALLBACK 0
> > > +#define POWER_OFF_PRIORITY_LOW 64
> > > +#define POWER_OFF_PRIORITY_DEFAULT 128
> > > +#define POWER_OFF_PRIORITY_HIGH 192
> > > +#define POWER_OFF_PRIORITY_HIGHEST 255
> >
> > I'm not sure why we need these gaps in the priority space.
> >
> > I guess it might be possible to use
> >
> > enum power_off_priority {
> > POWER_OFF_PRIORITY_FALLBACK = 0,
> > POWER_OFF_PRIORITY_LOW,
> > POWER_OFF_PRIORITY_DEFAULT,
> > POWER_OFF_PRIORITY_HIGH,
> > POWER_OFF_PRIORITY_HIGHEST,
> > POWER_OFF_PRIORITY_LIMIT,
> > };
>
> I retained the large number space on purpose, specifically to permit in-between
> priorities. In other words, I want people to be able to say "priority for this
> handler is higher than low but lower than default". After all, the defines were
> intended as hints, not as a "Thou shall use those and only those priorities".

Problem with that is how they are supposed to know what priority to use then.

How do I know if my priority is between DEFAULT and HIGH and whether it is
closer to HIGH or closer to DEFAULT? What are the rules?

The only rule that seems to be there is "this handler should be tried before
that one, so it needs to have a higher priority". But now the question is
how people are going to know which handlers they are competing with and whether
or not they are more "important".

> Having said that, the important part is to get the series accepted, so I won't
> argue if that is what it takes to get an Ack. Let me know.

This isn't worth fighting over in my view, so I won't if everyone else is fine
with it.

Just feel free to ignore this concern if you don't think it is valid.

Rafael

2014-11-07 03:01:25

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 01/48] kernel: Add support for power-off handler call chain

On 11/06/2014 04:16 PM, Rafael J. Wysocki wrote:
> On Thursday, November 06, 2014 02:27:03 PM Guenter Roeck wrote:
>> On Thu, Nov 06, 2014 at 11:30:59PM +0100, Rafael J. Wysocki wrote:
>>> On Thursday, November 06, 2014 08:42:45 AM Guenter Roeck wrote:
>>>> Various drivers implement architecture and/or device specific means to
>>>> power off the system. For the most part, those drivers set the global
>>>> variable pm_power_off to point to a function within the driver.
>>>>
>>>> This mechanism has a number of drawbacks. Typically only one scheme
>>>> to remove power is supported (at least if pm_power_off is used).
>>>> At least in theory there can be multiple means remove power, some of
>>>> which may be less desirable. For example, some mechanisms may only
>>>> power off the CPU or the CPU card, while another may power off the
>>>> entire system. Others may really just execute a restart sequence
>>>> or drop into the ROM monitor. Using pm_power_off can also be racy
>>>> if the function pointer is set from a driver built as module, as the
>>>> driver may be in the process of being unloaded when pm_power_off is
>>>> called. If there are multiple power-off handlers in the system, removing
>>>> a module with such a handler may inadvertently reset the pointer to
>>>> pm_power_off to NULL, leaving the system with no means to remove power.
>>>>
>>>> Introduce a system power-off handler call chain to solve the described
>>>> problems. This call chain is expected to be executed from the architecture
>>>> specific machine_power_off() function. Drivers and architeceture code
>>>> providing system power-off functionality are expected to register with
>>>> this call chain. When registering a power-off handler, callers can
>>>> provide a priority to control power-off handler execution sequence
>>>> and thus ensure that the power-off handler with the optimal capabilities
>>>> to remove power for a given system is called first.
>>>>
>>>> Cc: Alan Cox <[email protected]>
>>>> Cc: Alexander Graf <[email protected]>
>>>> Cc: Andrew Morton <[email protected]>
>>>> Cc: Geert Uytterhoeven <[email protected]>
>>>> Cc: Heiko Stuebner <[email protected]>
>>>> Cc: Lee Jones <[email protected]>
>>>> Cc: Len Brown <[email protected]>
>>>> Cc: Pavel Machek <[email protected]>
>>>> Cc: Philippe Rétornaz <[email protected]>
>>>> Cc: Rafael J. Wysocki <[email protected]>
>>>> Cc: Romain Perier <[email protected]>
>>>> Acked-by: Pavel Machek <[email protected]>
>>>> Acked-by: Heiko Stuebner <[email protected]>
>>>> Signed-off-by: Guenter Roeck <[email protected]>
>>>> ---
>>>> v5:
>>>> - Rebase to v3.18-rc3
>>>> v4:
>>>> - Do not use notifiers but internal functions and data structures to manage
>>>> the list of power-off handlers. Drop unused parameters from callbacks, and
>>>> make the power-off function type void.
>>>> Code to manage and walk the list of callbacks is derived from notifier.c.
>>>> v3:
>>>> - Rename new file to power_off_handler.c
>>>> - Replace poweroff in all newly introduced variables and in text
>>>> with power_off or power-off as appropriate
>>>> - Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
>>>> - Execute power-off handlers without any locks held
>>>> v2:
>>>> - poweroff -> power_off
>>>> - Add defines for default priorities
>>>> - Use raw notifiers protected by spinlocks instead of atomic notifiers
>>>> - Add register_poweroff_handler_simple
>>>> - Add devm_register_power_off_handler
>>>>
>>>> include/linux/pm.h | 28 ++++
>>>> kernel/power/Makefile | 1 +
>>>> kernel/power/power_off_handler.c | 293 +++++++++++++++++++++++++++++++++++++++
>>>> 3 files changed, 322 insertions(+)
>>>> create mode 100644 kernel/power/power_off_handler.c
>>>>
>>>> diff --git a/include/linux/pm.h b/include/linux/pm.h
>>>> index 383fd68..a4d6bf8 100644
>>>> --- a/include/linux/pm.h
>>>> +++ b/include/linux/pm.h
>>>> @@ -35,6 +35,34 @@ extern void (*pm_power_off)(void);
>>>> extern void (*pm_power_off_prepare)(void);
>>>>
>>>> struct device; /* we have a circular dep with device.h */
>>>> +
>>>> +/*
>>>> + * Data structures and callbacks to manage power-off handlers
>>>> + */
>>>> +
>>>> +struct power_off_handler_block {
>>>> + void (*handler)(struct power_off_handler_block *);
>>>> + struct power_off_handler_block __rcu *next;
>>>> + int priority;
>>>> +};
>>>> +
>>>> +int register_power_off_handler(struct power_off_handler_block *);
>>>> +int devm_register_power_off_handler(struct device *,
>>>> + struct power_off_handler_block *);
>>>> +int register_power_off_handler_simple(void (*function)(void), int priority);
>>>> +int unregister_power_off_handler(struct power_off_handler_block *);
>>>> +void do_kernel_power_off(void);
>>>> +bool have_kernel_power_off(void);
>>>> +
>>>> +/*
>>>> + * Pre-defined power-off handler priorities
>>>> + */
>>>> +#define POWER_OFF_PRIORITY_FALLBACK 0
>>>> +#define POWER_OFF_PRIORITY_LOW 64
>>>> +#define POWER_OFF_PRIORITY_DEFAULT 128
>>>> +#define POWER_OFF_PRIORITY_HIGH 192
>>>> +#define POWER_OFF_PRIORITY_HIGHEST 255
>>>
>>> I'm not sure why we need these gaps in the priority space.
>>>
>>> I guess it might be possible to use
>>>
>>> enum power_off_priority {
>>> POWER_OFF_PRIORITY_FALLBACK = 0,
>>> POWER_OFF_PRIORITY_LOW,
>>> POWER_OFF_PRIORITY_DEFAULT,
>>> POWER_OFF_PRIORITY_HIGH,
>>> POWER_OFF_PRIORITY_HIGHEST,
>>> POWER_OFF_PRIORITY_LIMIT,
>>> };
>>
>> I retained the large number space on purpose, specifically to permit in-between
>> priorities. In other words, I want people to be able to say "priority for this
>> handler is higher than low but lower than default". After all, the defines were
>> intended as hints, not as a "Thou shall use those and only those priorities".
>
> Problem with that is how they are supposed to know what priority to use then.
>
> How do I know if my priority is between DEFAULT and HIGH and whether it is
> closer to HIGH or closer to DEFAULT? What are the rules?
>
Guess there is too much of a Libertarian in me to make up such rules.
Or, in other words, I didn't think that more explicit rules than the ones
provided were needed.

> The only rule that seems to be there is "this handler should be tried before
> that one, so it needs to have a higher priority". But now the question is
> how people are going to know which handlers they are competing with and whether
> or not they are more "important".
>
Keep in mind those are power-off handlers. The "rule", if one is needed,
would be that the power-off handler which powers off more parts of the system
should get higher priority. Which one that is is depends on the platform.
I would think that it is in people's interest not to shoot themselves
into the foot, but maybe I am wrong.

>> Having said that, the important part is to get the series accepted, so I won't
>> argue if that is what it takes to get an Ack. Let me know.
>
> This isn't worth fighting over in my view, so I won't if everyone else is fine
> with it.
>

Linus raised pretty much the same or a similar concern. Everyone else, as far
as I can see, doesn't seem to care. Given that, and since I don't have a strong
opinion either, I'll change it to an enum in the next version. If there is anyone
who disagrees with that, the time to speak up is now.

Please let me know if you have any other concerns.

Thanks,
Guenter

2014-11-07 19:47:36

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 34/48] acpi: Register power-off handler with kernel power-off handler

On Thu, Nov 06, 2014 at 11:32:26PM +0100, Rafael J. Wysocki wrote:
> On Thursday, November 06, 2014 08:43:18 AM Guenter Roeck wrote:
> > Register with kernel power-off handler instead of setting pm_power_off
> > directly. Register with high priority to reflect that the driver explicitly
> > overrides existing power-off handlers.
> >
> > Cc: Rafael J. Wysocki <[email protected]>
> > Cc: Len Brown <[email protected]>
> > Signed-off-by: Guenter Roeck <[email protected]>
>
> That's fine by me.
>
I'll record that as an Acked-by: unless I hear otherwise from you.

Thanks,
Guenter

> Rafael
>
>
> > ---
> > v5:
> > - Rebase to v3.18-rc3
> > v4:
> > - Do not use notifiers but internal functions and data structures to manage
> > the list of power-off handlers. Drop unused parameters from callbacks, and
> > make the power-off function type void
> > v3:
> > - Replace poweroff in all newly introduced variables and in text
> > with power_off or power-off as appropriate
> > - Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
> > - Replace acpi: with ACPI: in log message
> > v2:
> > - Use define to specify poweroff handler priority
> > - Use pr_warn instead of pr_err
> >
> > drivers/acpi/sleep.c | 11 +++++++++--
> > 1 file changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
> > index 05a31b5..a73cfad 100644
> > --- a/drivers/acpi/sleep.c
> > +++ b/drivers/acpi/sleep.c
> > @@ -16,6 +16,7 @@
> > #include <linux/device.h>
> > #include <linux/interrupt.h>
> > #include <linux/suspend.h>
> > +#include <linux/pm.h>
> > #include <linux/reboot.h>
> > #include <linux/acpi.h>
> > #include <linux/module.h>
> > @@ -827,7 +828,7 @@ static void acpi_power_off_prepare(void)
> > acpi_disable_all_gpes();
> > }
> >
> > -static void acpi_power_off(void)
> > +static void acpi_power_off(struct power_off_handler_block *this)
> > {
> > /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
> > printk(KERN_DEBUG "%s called\n", __func__);
> > @@ -835,6 +836,11 @@ static void acpi_power_off(void)
> > acpi_enter_sleep_state(ACPI_STATE_S5);
> > }
> >
> > +static struct power_off_handler_block acpi_power_off_hb = {
> > + .handler = acpi_power_off,
> > + .priority = POWER_OFF_PRIORITY_HIGH,
> > +};
> > +
> > int __init acpi_sleep_init(void)
> > {
> > char supported[ACPI_S_STATE_COUNT * 3 + 1];
> > @@ -851,7 +857,8 @@ int __init acpi_sleep_init(void)
> > if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
> > sleep_states[ACPI_STATE_S5] = 1;
> > pm_power_off_prepare = acpi_power_off_prepare;
> > - pm_power_off = acpi_power_off;
> > + if (register_power_off_handler(&acpi_power_off_hb))
> > + pr_warn("ACPI: Failed to register power-off handler\n");
> > }
> >
> > supported[0] = 0;
> >
>
> --
> I speak only for myself.
> Rafael J. Wysocki, Intel Open Source Technology Center.

2014-11-07 21:02:20

by Beniamino Galvani

[permalink] [raw]
Subject: Re: [PATCH v5 20/48] mfd: rn5t618: Register power-off handler with kernel power-off handler

On Thu, Nov 06, 2014 at 08:43:04AM -0800, Guenter Roeck wrote:
> Register with kernel power-off handler instead of setting pm_power_off
> directly. Register with low priority to reflect that the original code
> only sets pm_power_off if it was not already set.
>
> Cc: Beniamino Galvani <[email protected]>
> Acked-by: Lee Jones <[email protected]>
> Signed-off-by: Guenter Roeck <[email protected]>
> ---
> v5:
> - Rebase to v3.18-rc3
> v4:
> - Do not use notifiers but internal functions and data structures to manage
> the list of power-off handlers. Drop unused parameters from callbacks, and
> make the power-off function type void
> v3:
> - Replace poweroff in all newly introduced variables and in text
> with power_off or power-off as appropriate
> - Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
> v2:
> - New patch
>
> drivers/mfd/rn5t618.c | 28 ++++++++++++----------------
> include/linux/mfd/rn5t618.h | 2 ++
> 2 files changed, 14 insertions(+), 16 deletions(-)

Tested-by: Beniamino Galvani <[email protected]>

2014-11-08 04:19:17

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 20/48] mfd: rn5t618: Register power-off handler with kernel power-off handler

On 11/07/2014 01:00 PM, Beniamino Galvani wrote:
> On Thu, Nov 06, 2014 at 08:43:04AM -0800, Guenter Roeck wrote:
>> Register with kernel power-off handler instead of setting pm_power_off
>> directly. Register with low priority to reflect that the original code
>> only sets pm_power_off if it was not already set.
>>
>> Cc: Beniamino Galvani <[email protected]>
>> Acked-by: Lee Jones <[email protected]>
>> Signed-off-by: Guenter Roeck <[email protected]>
>> ---
>> v5:
>> - Rebase to v3.18-rc3
>> v4:
>> - Do not use notifiers but internal functions and data structures to manage
>> the list of power-off handlers. Drop unused parameters from callbacks, and
>> make the power-off function type void
>> v3:
>> - Replace poweroff in all newly introduced variables and in text
>> with power_off or power-off as appropriate
>> - Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
>> v2:
>> - New patch
>>
>> drivers/mfd/rn5t618.c | 28 ++++++++++++----------------
>> include/linux/mfd/rn5t618.h | 2 ++
>> 2 files changed, 14 insertions(+), 16 deletions(-)
>
> Tested-by: Beniamino Galvani <[email protected]>
>
Thanks!

Guenter

2014-11-09 21:57:42

by Marc Dietrich

[permalink] [raw]
Subject: Re: [PATCH v5 33/48] staging: nvec: Register with kernel power-off handler

Am Donnerstag 06 November 2014, 08:43:17 schrieb Guenter Roeck:
> Register with kernel power-off handler instead of setting pm_power_off
> directly. Register with default priority since we don't know any better.
>
> Cc: Julian Andres Klode <[email protected]>
> Cc: Marc Dietrich <[email protected]>
> Cc: Greg Kroah-Hartman <[email protected]>
> Acked-by: Greg Kroah-Hartman <[email protected]>
> Signed-off-by: Guenter Roeck <[email protected]

ok, this version (V5) actually switches the device off in contrast to the
first implementation. Somehow I have to find out why it works at all without
irqs.

Acked-by: Marc Dietrich <[email protected]>

> ---
> v5:
> - Rebase to v3.18-rc3
> v4:
> - Do not use notifiers but internal functions and data structures to manage
> the list of power-off handlers. Drop unused parameters from callbacks, and
> make the power-off function type void
> v3:
> - Replace poweroff in all newly introduced variables and in text
> with power_off or power-off as appropriate
> - Replace POWEROFF_PRIORITY_xxx with POWER_OFF_PRIORITY_xxx
> v2:
> - Use define to specify poweroff handler priority
> - Use dev_warn instead of dev_err
>
> drivers/staging/nvec/nvec.c | 21 ++++++++++++---------
> drivers/staging/nvec/nvec.h | 2 ++
> 2 files changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c
> index a93208a..acf2ea6 100644
> --- a/drivers/staging/nvec/nvec.c
> +++ b/drivers/staging/nvec/nvec.c
> @@ -33,6 +33,7 @@
> #include <linux/mfd/core.h>
> #include <linux/mutex.h>
> #include <linux/notifier.h>
> +#include <linux/pm.h>
> #include <linux/slab.h>
> #include <linux/spinlock.h>
> #include <linux/workqueue.h>
> @@ -80,8 +81,6 @@ enum nvec_sleep_subcmds {
> #define LID_SWITCH BIT(1)
> #define PWR_BUTTON BIT(15)
>
> -static struct nvec_chip *nvec_power_handle;
> -
> static const struct mfd_cell nvec_devices[] = {
> {
> .name = "nvec-kbd",
> @@ -759,12 +758,14 @@ static void nvec_disable_i2c_slave(struct nvec_chip
> *nvec) }
> #endif
>
> -static void nvec_power_off(void)
> +static void nvec_power_off(struct power_off_handler_block *this)
> {
> + struct nvec_chip *nvec = container_of(this, struct nvec_chip,
> + power_off_hb);
> char ap_pwr_down[] = { NVEC_SLEEP, AP_PWR_DOWN };
>
> - nvec_toggle_global_events(nvec_power_handle, false);
> - nvec_write_async(nvec_power_handle, ap_pwr_down, 2);
> + nvec_toggle_global_events(nvec, false);
> + nvec_write_async(nvec, ap_pwr_down, 2);
> }
>
> /*
> @@ -878,8 +879,11 @@ static int tegra_nvec_probe(struct platform_device
> *pdev) nvec->nvec_status_notifier.notifier_call = nvec_status_notifier;
> nvec_register_notifier(nvec, &nvec->nvec_status_notifier, 0);
>
> - nvec_power_handle = nvec;
> - pm_power_off = nvec_power_off;
> + nvec->power_off_hb.handler = nvec_power_off;
> + nvec->power_off_hb.priority = POWER_OFF_PRIORITY_DEFAULT;
> + ret = register_power_off_handler(&nvec->power_off_hb);
> + if (ret)
> + dev_warn(nvec->dev, "Failed to register power-off handler\n");
>
> /* Get Firmware Version */
> msg = nvec_write_sync(nvec, get_firmware_version, 2);
> @@ -914,13 +918,12 @@ static int tegra_nvec_remove(struct platform_device
> *pdev) {
> struct nvec_chip *nvec = platform_get_drvdata(pdev);
>
> + unregister_power_off_handler(&nvec->power_off_hb);
> nvec_toggle_global_events(nvec, false);
> mfd_remove_devices(nvec->dev);
> nvec_unregister_notifier(nvec, &nvec->nvec_status_notifier);
> cancel_work_sync(&nvec->rx_work);
> cancel_work_sync(&nvec->tx_work);
> - /* FIXME: needs check wether nvec is responsible for power off */
> - pm_power_off = NULL;
>
> return 0;
> }
> diff --git a/drivers/staging/nvec/nvec.h b/drivers/staging/nvec/nvec.h
> index e271375..d4145da 100644
> --- a/drivers/staging/nvec/nvec.h
> +++ b/drivers/staging/nvec/nvec.h
> @@ -163,6 +163,8 @@ struct nvec_chip {
> struct nvec_msg *last_sync_msg;
>
> int state;
> +
> + struct power_off_handler_block power_off_hb;
> };
>
> extern int nvec_write_async(struct nvec_chip *nvec, const unsigned char
> *data,

2014-11-09 23:06:30

by Andreas Färber

[permalink] [raw]
Subject: Re: [PATCH v5 33/48] staging: nvec: Register with kernel power-off handler

Am 09.11.2014 um 22:41 schrieb Marc Dietrich:
> Am Donnerstag 06 November 2014, 08:43:17 schrieb Guenter Roeck:
>> Register with kernel power-off handler instead of setting pm_power_off
>> directly. Register with default priority since we don't know any better.
>>
>> Cc: Julian Andres Klode <[email protected]>
>> Cc: Marc Dietrich <[email protected]>
>> Cc: Greg Kroah-Hartman <[email protected]>
>> Acked-by: Greg Kroah-Hartman <[email protected]>
>> Signed-off-by: Guenter Roeck <[email protected]
>
> ok, this version (V5) actually switches the device off in contrast to the
> first implementation. Somehow I have to find out why it works at all without
> irqs.
>
> Acked-by: Marc Dietrich <[email protected]>

'r' missing in email? :)

Cheers,
Andreas

--
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imend?rffer; HRB 21284 AG N?rnberg

2014-11-09 23:55:05

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 33/48] staging: nvec: Register with kernel power-off handler

On 11/09/2014 01:41 PM, Marc Dietrich wrote:
> Am Donnerstag 06 November 2014, 08:43:17 schrieb Guenter Roeck:
>> Register with kernel power-off handler instead of setting pm_power_off
>> directly. Register with default priority since we don't know any better.
>>
>> Cc: Julian Andres Klode <[email protected]>
>> Cc: Marc Dietrich <[email protected]>
>> Cc: Greg Kroah-Hartman <[email protected]>
>> Acked-by: Greg Kroah-Hartman <[email protected]>
>> Signed-off-by: Guenter Roeck <[email protected]
>
> ok, this version (V5) actually switches the device off in contrast to the
> first implementation. Somehow I have to find out why it works at all without
> irqs.
>
> Acked-by: Marc Dietrich <[email protected]>
>

Hi Marc,

The most recent version does not turn off interrupts as long as the
infrastructure (architecture code, ie machine_power_off) doesn't
turn it off.

Thanks a lot for (re-)testing.

Guenter

2014-11-10 08:46:06

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH v5 18/48] mfd: twl4030-power: Register with kernel power-off handler

Hi!

> @@ -611,7 +611,7 @@ twl4030_power_configure_resources(const struct twl4030_power_data *pdata)
> * After a successful execution, TWL shuts down the power to the SoC
> * and all peripherals connected to it.
> */
> -void twl4030_power_off(void)
> +static void twl4030_power_off(struct power_off_handler_block *this)
> {
> int err;
>
> @@ -621,6 +621,11 @@ void twl4030_power_off(void)
> pr_err("TWL4030 Unable to power off\n");
> }
>
> +static struct power_off_handler_block twl4030_power_off_hb = {
> + .handler = twl4030_power_off,
> + .priority = POWER_OFF_PRIORITY_LOW,
> +};
> +
> static bool twl4030_power_use_poweroff(const struct twl4030_power_data *pdata,
> struct device_node *node)
> {
> @@ -839,7 +844,9 @@ static int twl4030_power_probe(struct platform_device *pdev)
> }
>
> /* Board has to be wired properly to use this feature */
> - if (twl4030_power_use_poweroff(pdata, node) && !pm_power_off) {
> + if (twl4030_power_use_poweroff(pdata, node)) {
> + int ret;
> +
> /* Default for SEQ_OFFSYNC is set, lets ensure this */
> err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val,
> TWL4030_PM_MASTER_CFG_P123_TRANSITION);
> @@ -856,7 +863,11 @@ static int twl4030_power_probe(struct platform_device *pdev)
> }
> }
>
> - pm_power_off = twl4030_power_off;
> + ret = devm_register_power_off_handler(&pdev->dev,
> + &twl4030_power_off_hb);
> + if (ret)
> + dev_warn(&pdev->dev,
> + "Failed to register power-off handler\n");
> }
>

Could we get rid of the "struct power_off_handler_block" and guarantee
that register_power_off never fails (or print message from the
register_power_off...)? That way, your patch would be an cleanup.

You could then add priorities if they turn out to be really
neccessary, later...
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

2014-11-10 14:09:27

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 18/48] mfd: twl4030-power: Register with kernel power-off handler

On 11/10/2014 12:46 AM, Pavel Machek wrote:
> Hi!
>
>> @@ -611,7 +611,7 @@ twl4030_power_configure_resources(const struct twl4030_power_data *pdata)
>> * After a successful execution, TWL shuts down the power to the SoC
>> * and all peripherals connected to it.
>> */
>> -void twl4030_power_off(void)
>> +static void twl4030_power_off(struct power_off_handler_block *this)
>> {
>> int err;
>>
>> @@ -621,6 +621,11 @@ void twl4030_power_off(void)
>> pr_err("TWL4030 Unable to power off\n");
>> }
>>
>> +static struct power_off_handler_block twl4030_power_off_hb = {
>> + .handler = twl4030_power_off,
>> + .priority = POWER_OFF_PRIORITY_LOW,
>> +};
>> +
>> static bool twl4030_power_use_poweroff(const struct twl4030_power_data *pdata,
>> struct device_node *node)
>> {
>> @@ -839,7 +844,9 @@ static int twl4030_power_probe(struct platform_device *pdev)
>> }
>>
>> /* Board has to be wired properly to use this feature */
>> - if (twl4030_power_use_poweroff(pdata, node) && !pm_power_off) {
>> + if (twl4030_power_use_poweroff(pdata, node)) {
>> + int ret;
>> +
>> /* Default for SEQ_OFFSYNC is set, lets ensure this */
>> err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val,
>> TWL4030_PM_MASTER_CFG_P123_TRANSITION);
>> @@ -856,7 +863,11 @@ static int twl4030_power_probe(struct platform_device *pdev)
>> }
>> }
>>
>> - pm_power_off = twl4030_power_off;
>> + ret = devm_register_power_off_handler(&pdev->dev,
>> + &twl4030_power_off_hb);
>> + if (ret)
>> + dev_warn(&pdev->dev,
>> + "Failed to register power-off handler\n");
>> }
>>
>
> Could we get rid of the "struct power_off_handler_block" and guarantee
> that register_power_off never fails (or print message from the
> register_power_off...)? That way, your patch would be an cleanup.
>
> You could then add priorities if they turn out to be really
> neccessary, later...

Priorities are necessary. We had _that_ discussion before.
Priorities solve the problem where multiple handlers are installed,
either conditionally or unconditionally. If I take priorities away,
a substantial part of the patch set's value gets lost, and I might
as well drop it.

Guenter

2014-11-10 14:50:03

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 18/48] mfd: twl4030-power: Register with kernel power-off handler

On 11/10/2014 06:09 AM, Guenter Roeck wrote:
> On 11/10/2014 12:46 AM, Pavel Machek wrote:
>> Hi!
>>
>>> @@ -611,7 +611,7 @@ twl4030_power_configure_resources(const struct twl4030_power_data *pdata)
>>> * After a successful execution, TWL shuts down the power to the SoC
>>> * and all peripherals connected to it.
>>> */
>>> -void twl4030_power_off(void)
>>> +static void twl4030_power_off(struct power_off_handler_block *this)
>>> {
>>> int err;
>>>
>>> @@ -621,6 +621,11 @@ void twl4030_power_off(void)
>>> pr_err("TWL4030 Unable to power off\n");
>>> }
>>>
>>> +static struct power_off_handler_block twl4030_power_off_hb = {
>>> + .handler = twl4030_power_off,
>>> + .priority = POWER_OFF_PRIORITY_LOW,
>>> +};
>>> +
>>> static bool twl4030_power_use_poweroff(const struct twl4030_power_data *pdata,
>>> struct device_node *node)
>>> {
>>> @@ -839,7 +844,9 @@ static int twl4030_power_probe(struct platform_device *pdev)
>>> }
>>>
>>> /* Board has to be wired properly to use this feature */
>>> - if (twl4030_power_use_poweroff(pdata, node) && !pm_power_off) {
>>> + if (twl4030_power_use_poweroff(pdata, node)) {
>>> + int ret;
>>> +
>>> /* Default for SEQ_OFFSYNC is set, lets ensure this */
>>> err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val,
>>> TWL4030_PM_MASTER_CFG_P123_TRANSITION);
>>> @@ -856,7 +863,11 @@ static int twl4030_power_probe(struct platform_device *pdev)
>>> }
>>> }
>>>
>>> - pm_power_off = twl4030_power_off;
>>> + ret = devm_register_power_off_handler(&pdev->dev,
>>> + &twl4030_power_off_hb);
>>> + if (ret)
>>> + dev_warn(&pdev->dev,
>>> + "Failed to register power-off handler\n");
>>> }
>>>
>>
>> Could we get rid of the "struct power_off_handler_block" and guarantee
>> that register_power_off never fails (or print message from the
>> register_power_off...)? That way, your patch would be an cleanup.
>>
>> You could then add priorities if they turn out to be really
>> neccessary, later...
>
> Priorities are necessary. We had _that_ discussion before.
> Priorities solve the problem where multiple handlers are installed,
> either conditionally or unconditionally. If I take priorities away,
> a substantial part of the patch set's value gets lost, and I might
> as well drop it.
>
I have an idea: Instead of dropping the priority, drop
power_off_handler_block and add two parameters to register_power_off_handler
and devm_register_power_off_handler instead: the priority and a context.
At the same time, declare that those two functions must be called
with the memory subsystem initialized (register_power_off_handler_simple
must be used otherwise).

With this change, the registration functions can still fail due to memory
allocation errors, but we can get rid of the data structure and simplify
the calling code while retaining functionality. I'll explore that for v7.

Guenter