linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain
@ 2014-09-30 18:00 Guenter Roeck
  2014-09-30 18:00 ` [RFC PATCH 01/16] " Guenter Roeck
                   ` (15 more replies)
  0 siblings, 16 replies; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, Andrew Morton, Heiko Stuebner, Romain Perier,
	James E.J. Bottomley, Helge Deller, Russell King,
	Catalin Marinas, Will Deacon, Haavard Skinnemoen,
	Hans-Christian Egtvedt, Mark Salter, Aurelien Jacquiot,
	Tony Luck, Fenghua Yu, James Hogan, Ralf Baechle, Guan Xuetao,
	Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	Konrad Rzeszutek Wilk, Boris Ostrovsky, Sebastian Reichel,
	Dmitry Eremin-Solenikov, David Woodhouse, Samuel Ortiz,
	Lee Jones

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 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 poweroff 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 poweroff 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 poweroff functionality are expected to register with this call chain.
By using the priority field in the notifier block, callers can control
poweroff handler execution sequence and thus ensure that the poweroff
handler with the optimal capabilities to remove power for a given system
is called first.

The poweroff handler is introduced in multiple steps

1) Implement poweroff handler API.
   Patch 01/16.
2) Ensure that pm_power_off is only called from machine_restart.
   Patches 02/16 and 03/16.
3) Implement call to poweroff handler in architecture specific
   machine_restart code.
   Patches 03/16 to 13/16.
4) Convert all drivers to register with poweroff handler
   instead of setting pm_power_off directly.
   Patches 15/16 and 16/16 (examples).
   This can be done in two steps: First convert all drivers which can
   be built as modules, then convert the remaining drivers (possibly after
   unexporting pm_powr_off).
5) Unexport pm_power_off for all architectures,
   and drop it entirely for architectures where it is not really used.
6) [optional] Convert machine specific architecture code to register 
   with poweroff handler instead of setting pm_power_off directly,
   and remove pm_power_off entirely from the system.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Romain Perier <romain.perier@gmail.com>
Cc: James E.J. Bottomley <jejb@parisc-linux.org>
Cc: Helge Deller <deller@gmx.de>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Haavard Skinnemoen <hskinnemoen@gmail.com>
Cc: Hans-Christian Egtvedt <egtvedt@samfundet.no>
Cc: Mark Salter <msalter@redhat.com>
Cc: Aurelien Jacquiot <a-jacquiot@ti.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: James Hogan <james.hogan@imgtec.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Sebastian Reichel <sre@kernel.org>
Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Samuel Ortiz <sameo@linux.intel.com>
Cc: Lee Jones <lee.jones@linaro.org>

----------------------------------------------------------------
Guenter Roeck (16):
      kernel: Add support for poweroff handler call chain
      hwmon: (ab8500) Call kernel_power_off instead of pm_power_off
      parisc: support poweroff through poweroff handler call chain
      arm: support poweroff through poweroff handler call chain
      arm64: support poweroff through poweroff handler call chain
      avr32: support poweroff through poweroff handler call chain
      c6x: support poweroff through poweroff handler call chain
      ia64: support poweroff through poweroff handler call chain
      metag: support poweroff through poweroff handler call chain
      mips: support poweroff through poweroff handler call chain
      sh: support poweroff through poweroff handler call chain
      unicore32: support poweroff through poweroff handler call chain
      x86: support poweroff through poweroff handler call chain
      x86/xen: support poweroff through poweroff handler call chain
      power/reset: restart-poweroff: Register with kernel poweroff handler
      mfd: palmas: Register with kernel poweroff handler

 arch/arm/kernel/process.c              |  2 +
 arch/arm64/kernel/process.c            |  2 +
 arch/avr32/kernel/process.c            |  2 +
 arch/c6x/kernel/process.c              |  2 +
 arch/ia64/kernel/process.c             |  2 +
 arch/metag/kernel/process.c            |  2 +
 arch/mips/kernel/reset.c               |  2 +
 arch/parisc/kernel/process.c           |  7 ++-
 arch/sh/kernel/reboot.c                |  2 +
 arch/unicore32/kernel/process.c        |  2 +
 arch/x86/kernel/reboot.c               |  4 ++
 arch/x86/xen/enlighten.c               |  2 +
 drivers/hwmon/ab8500.c                 |  5 ++-
 drivers/mfd/palmas.c                   | 30 +++++++------
 drivers/parisc/power.c                 |  3 +-
 drivers/power/reset/restart-poweroff.c | 24 +++++-----
 include/linux/mfd/palmas.h             |  3 ++
 include/linux/reboot.h                 |  4 ++
 kernel/reboot.c                        | 81 ++++++++++++++++++++++++++++++++++
 19 files changed, 149 insertions(+), 32 deletions(-)

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [RFC PATCH 01/16] kernel: Add support for poweroff handler call chain
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  2014-09-30 18:00 ` [RFC PATCH 02/16] hwmon: (ab8500) Call kernel_power_off instead of pm_power_off Guenter Roeck
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, Andrew Morton, Heiko Stuebner, Romain Perier,
	James E.J. Bottomley, Helge Deller, Russell King,
	Catalin Marinas, Will Deacon, Haavard Skinnemoen,
	Hans-Christian Egtvedt, Mark Salter, Aurelien Jacquiot,
	Tony Luck, Fenghua Yu, James Hogan, Ralf Baechle, Guan Xuetao,
	Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	Konrad Rzeszutek Wilk, Boris Ostrovsky, Sebastian Reichel,
	Dmitry Eremin-Solenikov, David Woodhouse, Samuel Ortiz,
	Lee Jones

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 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 poweroff 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 poweroff 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 poweroff functionality are expected to register with this call chain.
By using the priority field in the notifier block, callers can control
poweroff handler execution sequence and thus ensure that the poweroff
handler with the optimal capabilities to remove power for a given system
is called first.

Cc: Andrew Morton <akpm@linux-foundation.org>
cc: Heiko Stuebner <heiko@sntech.de>
Cc: Romain Perier <romain.perier@gmail.com>
Cc: James E.J. Bottomley <jejb@parisc-linux.org>
Cc: Helge Deller <deller@gmx.de>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Haavard Skinnemoen <hskinnemoen@gmail.com>
Cc: Hans-Christian Egtvedt <egtvedt@samfundet.no>
Cc: Mark Salter <msalter@redhat.com>
Cc: Aurelien Jacquiot <a-jacquiot@ti.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: James Hogan <james.hogan@imgtec.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Sebastian Reichel <sre@kernel.org>
Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Samuel Ortiz <sameo@linux.intel.com>
Cc: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 include/linux/reboot.h |  4 +++
 kernel/reboot.c        | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+)

diff --git a/include/linux/reboot.h b/include/linux/reboot.h
index 67fc8fc..b172951 100644
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -38,6 +38,10 @@ extern int reboot_force;
 extern int register_reboot_notifier(struct notifier_block *);
 extern int unregister_reboot_notifier(struct notifier_block *);
 
+extern int register_poweroff_handler(struct notifier_block *);
+extern int unregister_poweroff_handler(struct notifier_block *);
+extern void do_kernel_poweroff(void);
+
 extern int register_restart_handler(struct notifier_block *);
 extern int unregister_restart_handler(struct notifier_block *);
 extern void do_kernel_restart(char *cmd);
diff --git a/kernel/reboot.c b/kernel/reboot.c
index 5925f5a..bdfab65 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -106,6 +106,87 @@ EXPORT_SYMBOL(unregister_reboot_notifier);
 
 /*
  *	Notifier list for kernel code which wants to be called
+ *	to power off the system.
+ */
+static ATOMIC_NOTIFIER_HEAD(poweroff_handler_list);
+
+/**
+ *	register_poweroff_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:	Poweroff handler of last resort,
+ *				with limited poweroff capabilities
+ *			128:	Default poweroff handler; use if no other
+ *				poweroff handler is expected to be available,
+ *				and/or if poweroff functionality is
+ *				sufficient to poweroff the entire system
+ *			255:	Highest priority poweroff handler, will
+ *				preempt all other poweroff handlers
+ *
+ *	Registers a function with code to be called to poweroff the
+ *	system.
+ *
+ *	Registered functions will be called from machine_power_off as last
+ *	step of the poweroff sequence (if the architecture specific
+ *	machine_power_off function calls do_kernel_poweroff - see below
+ *	for details).
+ *	Registered functions are expected to poweroff the system immediately.
+ *	If more than one function is registered, the poweroff handler priority
+ *	selects which function will be called first.
+ *
+ *	Poweroff handlers are expected to be registered from non-architecture
+ *	code, typically from drivers. A typical use case would be a system
+ *	where poweroff functionality is provided through a mfd driver. Multiple
+ *	poweroff handlers may exist; for example, one poweroff handler might
+ *	poweroff the entire system, while another only powers off the CPU.
+ *	In such cases, the poweroff 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 poweroff the system is available.
+ *
+ *	Currently always returns zero, as atomic_notifier_chain_register()
+ *	always returns zero.
+ */
+int register_poweroff_handler(struct notifier_block *nb)
+{
+	return atomic_notifier_chain_register(&poweroff_handler_list, nb);
+}
+EXPORT_SYMBOL(register_poweroff_handler);
+
+/**
+ *	unregister_poweroff_handler - Unregister previously registered
+ *				      poweroff handler
+ *	@nb: Hook to be unregistered
+ *
+ *	Unregisters a previously registered poweroff handler function.
+ *
+ *	Returns zero on success, or %-ENOENT on failure.
+ */
+int unregister_poweroff_handler(struct notifier_block *nb)
+{
+	return atomic_notifier_chain_unregister(&poweroff_handler_list, nb);
+}
+EXPORT_SYMBOL(unregister_poweroff_handler);
+
+/**
+ *	do_kernel_poweroff - Execute kernel poweroff handler call chain
+ *
+ *	Calls functions registered with register_poweroff_handler.
+ *
+ *	Expected to be called from machine_poweroff as last step of the poweroff
+ *	sequence.
+ *
+ *	Powers off the system immediately if a poweroff handler function
+ *	has been registered. Otherwise does nothing.
+ */
+void do_kernel_poweroff(void)
+{
+	atomic_notifier_call_chain(&poweroff_handler_list, 0, NULL);
+}
+
+/*
+ *	Notifier list for kernel code which wants to be called
  *	to restart the system.
  */
 static ATOMIC_NOTIFIER_HEAD(restart_handler_list);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [RFC PATCH 02/16] hwmon: (ab8500) Call kernel_power_off instead of pm_power_off
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
  2014-09-30 18:00 ` [RFC PATCH 01/16] " Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  2014-09-30 18:00 ` [RFC PATCH 03/16] parisc: support poweroff through poweroff handler call chain Guenter Roeck
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, Jean Delvare

Drivers should not call pm_power_off directly; it is not guaranteed
to be non-NULL. Call kernel_power_off instead.

Cc: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
I already submitted this patch separately as non-RFC. It is included
in this series for completeness.

 drivers/hwmon/ab8500.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/ab8500.c b/drivers/hwmon/ab8500.c
index d844dc8..8b6a4f4 100644
--- a/drivers/hwmon/ab8500.c
+++ b/drivers/hwmon/ab8500.c
@@ -6,7 +6,7 @@
  *
  * When the AB8500 thermal warning temperature is reached (threshold cannot
  * be changed by SW), an interrupt is set, and if no further action is taken
- * within a certain time frame, pm_power off will be called.
+ * within a certain time frame, kernel_power_off will be called.
  *
  * When AB8500 thermal shutdown temperature is reached a hardware shutdown of
  * the AB8500 will occur.
@@ -21,6 +21,7 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/power/ab8500.h>
+#include <linux/reboot.h>
 #include <linux/slab.h>
 #include <linux/sysfs.h>
 #include "abx500.h"
@@ -106,7 +107,7 @@ static void ab8500_thermal_power_off(struct work_struct *work)
 
 	dev_warn(&abx500_data->pdev->dev, "Power off due to critical temp\n");
 
-	pm_power_off();
+	kernel_power_off();
 }
 
 static ssize_t ab8500_show_name(struct device *dev,
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [RFC PATCH 03/16] parisc: support poweroff through poweroff handler call chain
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
  2014-09-30 18:00 ` [RFC PATCH 01/16] " Guenter Roeck
  2014-09-30 18:00 ` [RFC PATCH 02/16] hwmon: (ab8500) Call kernel_power_off instead of pm_power_off Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  2014-09-30 18:00 ` [RFC PATCH 04/16] arm: " Guenter Roeck
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, James E.J. Bottomley, Helge Deller

The kernel core now supports a poweroff handler call chain
to remove power from the system. Call it from machine_power_off.

Also, do not use pm_power_off as alternate pointer to machine_power_off.
Have the parisc/power driver call kernel_power_off() which in turn will
call machine_power_off().

Cc: James E.J. Bottomley <jejb@parisc-linux.org>
Cc: Helge Deller <deller@gmx.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 arch/parisc/kernel/process.c | 7 +++++--
 drivers/parisc/power.c       | 3 +--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c
index 0bbbf0d..21d1ab3 100644
--- a/arch/parisc/kernel/process.c
+++ b/arch/parisc/kernel/process.c
@@ -42,6 +42,7 @@
 #include <linux/module.h>
 #include <linux/personality.h>
 #include <linux/ptrace.h>
+#include <linux/reboot.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/stddef.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_poweroff();
+
 	/* It seems we have no way to power the system off via
 	 * software. The user has to press the button himself. */
 
@@ -141,7 +144,7 @@ void machine_power_off(void)
 	       "Please power this system off now.");
 }
 
-void (*pm_power_off)(void) = machine_power_off;
+void (*pm_power_off)(void);
 EXPORT_SYMBOL(pm_power_off);
 
 /*
diff --git a/drivers/parisc/power.c b/drivers/parisc/power.c
index 90cca5e..de5b2ff 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();
 		}
 	}
 }
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [RFC PATCH 04/16] arm: support poweroff through poweroff handler call chain
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
                   ` (2 preceding siblings ...)
  2014-09-30 18:00 ` [RFC PATCH 03/16] parisc: support poweroff through poweroff handler call chain Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  2014-09-30 18:00 ` [RFC PATCH 05/16] arm64: " Guenter Roeck
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, Russell King

The kernel core now supports a poweroff handler call chain
to remove power from the system. Call it if pm_power_off
is set to NULL.

Cc: Russell King <linux@arm.linux.org.uk>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 arch/arm/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index 250b6f6..848c578 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -207,6 +207,8 @@ void machine_power_off(void)
 
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 }
 
 /*
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [RFC PATCH 05/16] arm64: support poweroff through poweroff handler call chain
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
                   ` (3 preceding siblings ...)
  2014-09-30 18:00 ` [RFC PATCH 04/16] arm: " Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  2014-10-03 10:30   ` Catalin Marinas
  2014-09-30 18:00 ` [RFC PATCH 06/16] avr32: " Guenter Roeck
                   ` (10 subsequent siblings)
  15 siblings, 1 reply; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, Catalin Marinas, Will Deacon

The kernel core now supports a poweroff handler call chain
to remove power from the system. Call it if pm_power_off
is set to NULL.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 arch/arm64/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 398ab05..cc0c63e 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -157,6 +157,8 @@ void machine_power_off(void)
 	smp_send_stop();
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 }
 
 /*
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [RFC PATCH 06/16] avr32: support poweroff through poweroff handler call chain
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
                   ` (4 preceding siblings ...)
  2014-09-30 18:00 ` [RFC PATCH 05/16] arm64: " Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  2014-09-30 18:00 ` [RFC PATCH 07/16] c6x: " Guenter Roeck
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, Haavard Skinnemoen, Hans-Christian Egtvedt

The kernel core now supports a poweroff handler call chain
to remove power from the system. Call it if pm_power_off
is set to NULL.

Cc: Haavard Skinnemoen <hskinnemoen@gmail.com>
Cc: Hans-Christian Egtvedt <egtvedt@samfundet.no>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 arch/avr32/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/avr32/kernel/process.c b/arch/avr32/kernel/process.c
index 42a53e74..6bd6289 100644
--- a/arch/avr32/kernel/process.c
+++ b/arch/avr32/kernel/process.c
@@ -50,6 +50,8 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 }
 
 void machine_restart(char *cmd)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [RFC PATCH 07/16] c6x: support poweroff through poweroff handler call chain
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
                   ` (5 preceding siblings ...)
  2014-09-30 18:00 ` [RFC PATCH 06/16] avr32: " Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  2014-10-03 15:17   ` Mark Salter
  2014-09-30 18:00 ` [RFC PATCH 08/16] ia64: " Guenter Roeck
                   ` (8 subsequent siblings)
  15 siblings, 1 reply; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, Mark Salter, Aurelien Jacquiot

The kernel core now supports a poweroff handler call chain
to remove power from the system. Call it if pm_power_off
is set to NULL.

Cc: Mark Salter <msalter@redhat.com>
Cc: Aurelien Jacquiot <a-jacquiot@ti.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 arch/c6x/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/c6x/kernel/process.c b/arch/c6x/kernel/process.c
index 57d2ea8..ddf088e 100644
--- a/arch/c6x/kernel/process.c
+++ b/arch/c6x/kernel/process.c
@@ -75,6 +75,8 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	halt_loop();
 }
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [RFC PATCH 08/16] ia64: support poweroff through poweroff handler call chain
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
                   ` (6 preceding siblings ...)
  2014-09-30 18:00 ` [RFC PATCH 07/16] c6x: " Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  2014-09-30 18:00 ` [RFC PATCH 09/16] metag: " Guenter Roeck
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, Tony Luck, Fenghua Yu

The kernel core now supports a poweroff handler call chain
to remove power from the system. Call it if pm_power_off
is set to NULL.

Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 arch/ia64/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index deed6fa..489b0d8 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -677,6 +677,8 @@ machine_power_off (void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	machine_halt();
 }
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [RFC PATCH 09/16] metag: support poweroff through poweroff handler call chain
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
                   ` (7 preceding siblings ...)
  2014-09-30 18:00 ` [RFC PATCH 08/16] ia64: " Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  2014-09-30 18:00 ` [RFC PATCH 10/16] mips: " Guenter Roeck
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, James Hogan

The kernel core now supports a poweroff handler call chain
to remove power from the system. Call it if pm_power_off
is set to NULL.

Cc: James Hogan <james.hogan@imgtec.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 arch/metag/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/metag/kernel/process.c b/arch/metag/kernel/process.c
index 483dff9..ff7f3eb 100644
--- a/arch/metag/kernel/process.c
+++ b/arch/metag/kernel/process.c
@@ -92,6 +92,8 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	smp_send_stop();
 	hard_processor_halt(HALT_OK);
 }
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [RFC PATCH 10/16] mips: support poweroff through poweroff handler call chain
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
                   ` (8 preceding siblings ...)
  2014-09-30 18:00 ` [RFC PATCH 09/16] metag: " Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  2014-10-01 13:32   ` Ralf Baechle
  2014-09-30 18:00 ` [RFC PATCH 11/16] sh: " Guenter Roeck
                   ` (5 subsequent siblings)
  15 siblings, 1 reply; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, Ralf Baechle

The kernel core now supports a poweroff handler call chain
to remove power from the system. Call it if pm_power_off
is set to NULL.

Cc: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 arch/mips/kernel/reset.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
index 07fc524..c3391d7 100644
--- a/arch/mips/kernel/reset.c
+++ b/arch/mips/kernel/reset.c
@@ -41,4 +41,6 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 }
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [RFC PATCH 11/16] sh: support poweroff through poweroff handler call chain
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
                   ` (9 preceding siblings ...)
  2014-09-30 18:00 ` [RFC PATCH 10/16] mips: " Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  2014-09-30 18:00 ` [RFC PATCH 12/16] unicore32: " Guenter Roeck
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck

The kernel core now supports a poweroff handler call chain
to remove power from the system. Call it if pm_power_off
is set to NULL.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 arch/sh/kernel/reboot.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/sh/kernel/reboot.c b/arch/sh/kernel/reboot.c
index 04afe5b..8e68926 100644
--- a/arch/sh/kernel/reboot.c
+++ b/arch/sh/kernel/reboot.c
@@ -53,6 +53,8 @@ static void native_machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 }
 
 static void native_machine_halt(void)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [RFC PATCH 12/16] unicore32: support poweroff through poweroff handler call chain
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
                   ` (10 preceding siblings ...)
  2014-09-30 18:00 ` [RFC PATCH 11/16] sh: " Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  2014-09-30 18:00 ` [RFC PATCH 13/16] x86: " Guenter Roeck
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, Guan Xuetao

The kernel core now supports a poweroff handler call chain
to remove power from the system. Call it if pm_power_off
is set to NULL.

Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 arch/unicore32/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/unicore32/kernel/process.c b/arch/unicore32/kernel/process.c
index b008e99..421fde6 100644
--- a/arch/unicore32/kernel/process.c
+++ b/arch/unicore32/kernel/process.c
@@ -66,6 +66,8 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	machine_halt();
 }
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [RFC PATCH 13/16] x86: support poweroff through poweroff handler call chain
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
                   ` (11 preceding siblings ...)
  2014-09-30 18:00 ` [RFC PATCH 12/16] unicore32: " Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  2014-09-30 18:00 ` [RFC PATCH 14/16] x86/xen: " Guenter Roeck
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, Thomas Gleixner, Ingo Molnar, H. Peter Anvin

The kernel core now supports a poweroff handler call chain
to remove power from the system. Call it if pm_power_off
is set to NULL.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 arch/x86/kernel/reboot.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
index 17962e6..c5514aa 100644
--- a/arch/x86/kernel/reboot.c
+++ b/arch/x86/kernel/reboot.c
@@ -651,6 +651,10 @@ static void native_machine_power_off(void)
 		if (!reboot_force)
 			machine_shutdown();
 		pm_power_off();
+	} else {
+		if (!reboot_force)
+			machine_shutdown();
+		do_kernel_poweroff();
 	}
 	/* A fallback in case there is no PM info available */
 	tboot_shutdown(TB_SHUTDOWN_HALT);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [RFC PATCH 14/16] x86/xen: support poweroff through poweroff handler call chain
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
                   ` (12 preceding siblings ...)
  2014-09-30 18:00 ` [RFC PATCH 13/16] x86: " Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  2014-10-02  9:45   ` [Xen-devel] " David Vrabel
  2014-09-30 18:00 ` [RFC PATCH 15/16] power/reset: restart-poweroff: Register with kernel poweroff handler Guenter Roeck
  2014-09-30 18:00 ` [RFC PATCH 16/16] mfd: palmas: " Guenter Roeck
  15 siblings, 1 reply; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	Thomas Gleixner, Ingo Molnar, H. Peter Anvin

The kernel core now supports a poweroff handler call chain
to remove power from the system. Call it if pm_power_off
is set to NULL.

Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 arch/x86/xen/enlighten.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index c0cb11f..645d00f 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -1322,6 +1322,8 @@ static void xen_machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	xen_reboot(SHUTDOWN_poweroff);
 }
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [RFC PATCH 15/16] power/reset: restart-poweroff: Register with kernel poweroff handler
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
                   ` (13 preceding siblings ...)
  2014-09-30 18:00 ` [RFC PATCH 14/16] x86/xen: " Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  2014-10-03 14:27   ` Sebastian Reichel
  2014-09-30 18:00 ` [RFC PATCH 16/16] mfd: palmas: " Guenter Roeck
  15 siblings, 1 reply; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, Sebastian Reichel, Dmitry Eremin-Solenikov,
	David Woodhouse

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

Cc: Sebastian Reichel <sre@kernel.org>
Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/power/reset/restart-poweroff.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/drivers/power/reset/restart-poweroff.c b/drivers/power/reset/restart-poweroff.c
index edd707e..82d058f 100644
--- a/drivers/power/reset/restart-poweroff.c
+++ b/drivers/power/reset/restart-poweroff.c
@@ -12,35 +12,33 @@
  */
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/notifier.h>
 #include <linux/platform_device.h>
 #include <linux/of_platform.h>
 #include <linux/module.h>
 #include <linux/reboot.h>
-#include <asm/system_misc.h>
 
-static void restart_poweroff_do_poweroff(void)
+static int restart_poweroff_do_poweroff(struct notifier_block *this,
+					unsigned long unused1, void *unused2)
 {
 	reboot_mode = REBOOT_HARD;
 	machine_restart(NULL);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block restart_poweroff_handler = {
+	.notifier_call = restart_poweroff_do_poweroff,
+};
+
 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;
+	return register_restart_handler(&restart_poweroff_handler);
 }
 
 static int restart_poweroff_remove(struct platform_device *pdev)
 {
-	if (pm_power_off == &restart_poweroff_do_poweroff)
-		pm_power_off = NULL;
+	unregister_restart_handler(&restart_poweroff_handler);
 
 	return 0;
 }
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [RFC PATCH 16/16] mfd: palmas: Register with kernel poweroff handler
  2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
                   ` (14 preceding siblings ...)
  2014-09-30 18:00 ` [RFC PATCH 15/16] power/reset: restart-poweroff: Register with kernel poweroff handler Guenter Roeck
@ 2014-09-30 18:00 ` Guenter Roeck
  15 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2014-09-30 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-pm, linux-arm-kernel, linux-c6x-dev, linux-ia64,
	linux-metag, linux-mips, linux-parisc, linux-sh, xen-devel,
	Guenter Roeck, Samuel Ortiz, Lee Jones

Register with kernel poweroff handler instead of setting pm_power_off
directly.

Cc: Samuel Ortiz <sameo@linux.intel.com>
Cc: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/mfd/palmas.c       | 30 +++++++++++++++++-------------
 include/linux/mfd/palmas.h |  3 +++
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/drivers/mfd/palmas.c b/drivers/mfd/palmas.c
index 28cb048..e8ef345a 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/reboot.h>
 #include <linux/regmap.h>
 #include <linux/err.h>
 #include <linux/mfd/core.h>
@@ -425,20 +426,18 @@ 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 int palmas_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
+	struct palmas *palmas = container_of(this, struct palmas, poweroff_nb);
 	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);
@@ -446,6 +445,8 @@ static void palmas_power_off(void)
 	if (ret)
 		pr_err("%s: Unable to write to DEV_CTRL_DEV_ON: %d\n",
 				__func__, ret);
+
+	return NOTIFY_DONE;
 }
 
 static unsigned int palmas_features = PALMAS_PMIC_FEATURE_SMPS10_BOOST;
@@ -668,9 +669,15 @@ 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) {
+			palmas->poweroff_nb.notifier_call = palmas_power_off;
+			palmas->poweroff_nb.priority = 128;
+			ret = register_poweroff_handler(&palmas->poweroff_nb);
+			if (ret) {
+				dev_err(palmas->dev,
+					"cannot register poweroff handler");
+				ret = 0;
+			}
 		}
 	}
 
@@ -698,10 +705,7 @@ 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;
-	}
+	unregister_poweroff_handler(&palmas->poweroff_nb);
 
 	return 0;
 }
diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
index fb0390a..4715057 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/notifier.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 notifier_block poweroff_nb;
+
 	/* Stored chip id */
 	int id;
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [RFC PATCH 10/16] mips: support poweroff through poweroff handler call chain
  2014-09-30 18:00 ` [RFC PATCH 10/16] mips: " Guenter Roeck
@ 2014-10-01 13:32   ` Ralf Baechle
  2014-10-01 16:26     ` Guenter Roeck
  0 siblings, 1 reply; 25+ messages in thread
From: Ralf Baechle @ 2014-10-01 13:32 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-kernel, linux-pm, linux-arm-kernel, linux-c6x-dev,
	linux-ia64, linux-metag, linux-mips, linux-parisc, linux-sh,
	xen-devel

On Tue, Sep 30, 2014 at 11:00:50AM -0700, Guenter Roeck wrote:

> The kernel core now supports a poweroff handler call chain
> to remove power from the system. Call it if pm_power_off
> is set to NULL.
> 
> Cc: Ralf Baechle <ralf@linux-mips.org>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  arch/mips/kernel/reset.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
> index 07fc524..c3391d7 100644
> --- a/arch/mips/kernel/reset.c
> +++ b/arch/mips/kernel/reset.c
> @@ -41,4 +41,6 @@ void machine_power_off(void)
>  {
>  	if (pm_power_off)
>  		pm_power_off();
> +	else
> +		do_kernel_poweroff();

I'm happy with this as long as in a later version pm_power_off indeed
goes away.

  Ralf

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [RFC PATCH 10/16] mips: support poweroff through poweroff handler call chain
  2014-10-01 13:32   ` Ralf Baechle
@ 2014-10-01 16:26     ` Guenter Roeck
  0 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2014-10-01 16:26 UTC (permalink / raw)
  To: Ralf Baechle
  Cc: linux-kernel, linux-pm, linux-arm-kernel, linux-c6x-dev,
	linux-ia64, linux-metag, linux-mips, linux-parisc, linux-sh,
	xen-devel

On Wed, Oct 01, 2014 at 03:32:39PM +0200, Ralf Baechle wrote:
> On Tue, Sep 30, 2014 at 11:00:50AM -0700, Guenter Roeck wrote:
> 
> > The kernel core now supports a poweroff handler call chain
> > to remove power from the system. Call it if pm_power_off
> > is set to NULL.
> > 
> > Cc: Ralf Baechle <ralf@linux-mips.org>
> > Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> > ---
> >  arch/mips/kernel/reset.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
> > index 07fc524..c3391d7 100644
> > --- a/arch/mips/kernel/reset.c
> > +++ b/arch/mips/kernel/reset.c
> > @@ -41,4 +41,6 @@ void machine_power_off(void)
> >  {
> >  	if (pm_power_off)
> >  		pm_power_off();
> > +	else
> > +		do_kernel_poweroff();
> 
> I'm happy with this as long as in a later version pm_power_off indeed
> goes away.
> 
Yes, that would be the ultimate goal. Hope we can get there.

Guenter

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Xen-devel] [RFC PATCH 14/16] x86/xen: support poweroff through poweroff handler call chain
  2014-09-30 18:00 ` [RFC PATCH 14/16] x86/xen: " Guenter Roeck
@ 2014-10-02  9:45   ` David Vrabel
  2014-10-02 13:27     ` Guenter Roeck
  0 siblings, 1 reply; 25+ messages in thread
From: David Vrabel @ 2014-10-02  9:45 UTC (permalink / raw)
  To: Guenter Roeck, linux-kernel
  Cc: linux-mips, linux-ia64, linux-c6x-dev, linux-parisc, linux-pm,
	linux-sh, Ingo Molnar, Thomas Gleixner, H. Peter Anvin,
	xen-devel, Boris Ostrovsky, linux-metag, linux-arm-kernel

On 30/09/14 19:00, Guenter Roeck wrote:
> The kernel core now supports a poweroff handler call chain
> to remove power from the system. Call it if pm_power_off
> is set to NULL.
> 
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: H. Peter Anvin <hpa@zytor.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  arch/x86/xen/enlighten.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
> index c0cb11f..645d00f 100644
> --- a/arch/x86/xen/enlighten.c
> +++ b/arch/x86/xen/enlighten.c
> @@ -1322,6 +1322,8 @@ static void xen_machine_power_off(void)
>  {
>  	if (pm_power_off)
>  		pm_power_off();
> +	else
> +		do_kernel_poweroff();

Why isn't this if (pm_power_off) check in do_kernel_poweroff()?

That way when you finally remove pm_power_off you need only update one
place.  A quick skim of the other archs suggest this would work for them
too.

David

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Xen-devel] [RFC PATCH 14/16] x86/xen: support poweroff through poweroff handler call chain
  2014-10-02  9:45   ` [Xen-devel] " David Vrabel
@ 2014-10-02 13:27     ` Guenter Roeck
  0 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2014-10-02 13:27 UTC (permalink / raw)
  To: David Vrabel, linux-kernel
  Cc: linux-mips, linux-ia64, linux-c6x-dev, linux-parisc, linux-pm,
	linux-sh, Ingo Molnar, Thomas Gleixner, H. Peter Anvin,
	xen-devel, Boris Ostrovsky, linux-metag, linux-arm-kernel

On 10/02/2014 02:45 AM, David Vrabel wrote:
> On 30/09/14 19:00, Guenter Roeck wrote:
>> The kernel core now supports a poweroff handler call chain
>> to remove power from the system. Call it if pm_power_off
>> is set to NULL.
>>
>> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
>> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
>> Cc: Thomas Gleixner <tglx@linutronix.de>
>> Cc: Ingo Molnar <mingo@redhat.com>
>> Cc: H. Peter Anvin <hpa@zytor.com>
>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>>   arch/x86/xen/enlighten.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
>> index c0cb11f..645d00f 100644
>> --- a/arch/x86/xen/enlighten.c
>> +++ b/arch/x86/xen/enlighten.c
>> @@ -1322,6 +1322,8 @@ static void xen_machine_power_off(void)
>>   {
>>   	if (pm_power_off)
>>   		pm_power_off();
>> +	else
>> +		do_kernel_poweroff();
>
> Why isn't this if (pm_power_off) check in do_kernel_poweroff()?
>
> That way when you finally remove pm_power_off you need only update one
> place.  A quick skim of the other archs suggest this would work for them
> too.
>

Good idea. I'll do that for the next version of the patch set.

Guenter



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [RFC PATCH 05/16] arm64: support poweroff through poweroff handler call chain
  2014-09-30 18:00 ` [RFC PATCH 05/16] arm64: " Guenter Roeck
@ 2014-10-03 10:30   ` Catalin Marinas
  2014-10-03 13:12     ` Guenter Roeck
  0 siblings, 1 reply; 25+ messages in thread
From: Catalin Marinas @ 2014-10-03 10:30 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-kernel, linux-pm, linux-arm-kernel, linux-c6x-dev,
	linux-ia64, linux-metag, linux-mips, linux-parisc, linux-sh,
	xen-devel, Will Deacon

On Tue, Sep 30, 2014 at 07:00:45PM +0100, Guenter Roeck wrote:
> The kernel core now supports a poweroff handler call chain
> to remove power from the system. Call it if pm_power_off
> is set to NULL.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  arch/arm64/kernel/process.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> index 398ab05..cc0c63e 100644
> --- a/arch/arm64/kernel/process.c
> +++ b/arch/arm64/kernel/process.c
> @@ -157,6 +157,8 @@ void machine_power_off(void)
>  	smp_send_stop();
>  	if (pm_power_off)
>  		pm_power_off();
> +	else
> +		do_kernel_poweroff();

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

As others already stated, I think we should eventually remove
pm_power_off entirely.

Catalin

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [RFC PATCH 05/16] arm64: support poweroff through poweroff handler call chain
  2014-10-03 10:30   ` Catalin Marinas
@ 2014-10-03 13:12     ` Guenter Roeck
  0 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2014-10-03 13:12 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: linux-kernel, linux-pm, linux-arm-kernel, linux-c6x-dev,
	linux-ia64, linux-metag, linux-mips, linux-parisc, linux-sh,
	xen-devel, Will Deacon

On 10/03/2014 03:30 AM, Catalin Marinas wrote:
> On Tue, Sep 30, 2014 at 07:00:45PM +0100, Guenter Roeck wrote:
>> The kernel core now supports a poweroff handler call chain
>> to remove power from the system. Call it if pm_power_off
>> is set to NULL.
>>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Will Deacon <will.deacon@arm.com>
>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>>   arch/arm64/kernel/process.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
>> index 398ab05..cc0c63e 100644
>> --- a/arch/arm64/kernel/process.c
>> +++ b/arch/arm64/kernel/process.c
>> @@ -157,6 +157,8 @@ void machine_power_off(void)
>>   	smp_send_stop();
>>   	if (pm_power_off)
>>   		pm_power_off();
>> +	else
>> +		do_kernel_poweroff();
>
> Acked-by: Catalin Marinas <catalin.marinas@arm.com>
>
> As others already stated, I think we should eventually remove
> pm_power_off entirely.
>

Hi Catalin,
yes, already working on it. As suggested by others, I'll move pm_power_off
to a central location (no need to declare the same variable for each
architecture) and hide the call to it in do_kernel_poweroff() as a
first step. You'll see this in the next version of the series.
This will make it much easier to remove it later on.

Thanks,
Guenter


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [RFC PATCH 15/16] power/reset: restart-poweroff: Register with kernel poweroff handler
  2014-09-30 18:00 ` [RFC PATCH 15/16] power/reset: restart-poweroff: Register with kernel poweroff handler Guenter Roeck
@ 2014-10-03 14:27   ` Sebastian Reichel
  0 siblings, 0 replies; 25+ messages in thread
From: Sebastian Reichel @ 2014-10-03 14:27 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-kernel, linux-pm, linux-arm-kernel, linux-c6x-dev,
	linux-ia64, linux-metag, linux-mips, linux-parisc, linux-sh,
	xen-devel, Dmitry Eremin-Solenikov, David Woodhouse

[-- Attachment #1: Type: text/plain, Size: 544 bytes --]

Hi,

On Tue, Sep 30, 2014 at 11:00:55AM -0700, Guenter Roeck wrote:
> Register with kernel poweroff handler instead of seting pm_power_off
> directly.  Register as poweroff handler of last resort since the driver
> does not really power off the system but executes a restart.
> 
> Cc: Sebastian Reichel <sre@kernel.org>
> Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
> Cc: David Woodhouse <dwmw2@infradead.org>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Acked-By: Sebastian Reichel <sre@kernel.org>

-- Sebastian

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [RFC PATCH 07/16] c6x: support poweroff through poweroff handler call chain
  2014-09-30 18:00 ` [RFC PATCH 07/16] c6x: " Guenter Roeck
@ 2014-10-03 15:17   ` Mark Salter
  0 siblings, 0 replies; 25+ messages in thread
From: Mark Salter @ 2014-10-03 15:17 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-kernel, linux-pm, linux-arm-kernel, linux-c6x-dev,
	linux-ia64, linux-metag, linux-mips, linux-parisc, linux-sh,
	xen-devel, Aurelien Jacquiot

On Tue, 2014-09-30 at 11:00 -0700, Guenter Roeck wrote:
> The kernel core now supports a poweroff handler call chain
> to remove power from the system. Call it if pm_power_off
> is set to NULL.
> 
> Cc: Mark Salter <msalter@redhat.com>
> Cc: Aurelien Jacquiot <a-jacquiot@ti.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---

Acked-by: Mark Salter <msalter@redhat.com>

>  arch/c6x/kernel/process.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/c6x/kernel/process.c b/arch/c6x/kernel/process.c
> index 57d2ea8..ddf088e 100644
> --- a/arch/c6x/kernel/process.c
> +++ b/arch/c6x/kernel/process.c
> @@ -75,6 +75,8 @@ void machine_power_off(void)
>  {
>  	if (pm_power_off)
>  		pm_power_off();
> +	else
> +		do_kernel_poweroff();
>  	halt_loop();
>  }
>  



^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2014-10-03 15:18 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-30 18:00 [RFC PATCH 00/16] kernel: Add support for poweroff handler call chain Guenter Roeck
2014-09-30 18:00 ` [RFC PATCH 01/16] " Guenter Roeck
2014-09-30 18:00 ` [RFC PATCH 02/16] hwmon: (ab8500) Call kernel_power_off instead of pm_power_off Guenter Roeck
2014-09-30 18:00 ` [RFC PATCH 03/16] parisc: support poweroff through poweroff handler call chain Guenter Roeck
2014-09-30 18:00 ` [RFC PATCH 04/16] arm: " Guenter Roeck
2014-09-30 18:00 ` [RFC PATCH 05/16] arm64: " Guenter Roeck
2014-10-03 10:30   ` Catalin Marinas
2014-10-03 13:12     ` Guenter Roeck
2014-09-30 18:00 ` [RFC PATCH 06/16] avr32: " Guenter Roeck
2014-09-30 18:00 ` [RFC PATCH 07/16] c6x: " Guenter Roeck
2014-10-03 15:17   ` Mark Salter
2014-09-30 18:00 ` [RFC PATCH 08/16] ia64: " Guenter Roeck
2014-09-30 18:00 ` [RFC PATCH 09/16] metag: " Guenter Roeck
2014-09-30 18:00 ` [RFC PATCH 10/16] mips: " Guenter Roeck
2014-10-01 13:32   ` Ralf Baechle
2014-10-01 16:26     ` Guenter Roeck
2014-09-30 18:00 ` [RFC PATCH 11/16] sh: " Guenter Roeck
2014-09-30 18:00 ` [RFC PATCH 12/16] unicore32: " Guenter Roeck
2014-09-30 18:00 ` [RFC PATCH 13/16] x86: " Guenter Roeck
2014-09-30 18:00 ` [RFC PATCH 14/16] x86/xen: " Guenter Roeck
2014-10-02  9:45   ` [Xen-devel] " David Vrabel
2014-10-02 13:27     ` Guenter Roeck
2014-09-30 18:00 ` [RFC PATCH 15/16] power/reset: restart-poweroff: Register with kernel poweroff handler Guenter Roeck
2014-10-03 14:27   ` Sebastian Reichel
2014-09-30 18:00 ` [RFC PATCH 16/16] mfd: palmas: " Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).