Skip to contentSkip to conversation

kernel: Add support for poweroff handler call chain

PATCH In review Guenter Roeck 28 participants 271 messages Oct 7, 2014 – Jun 18, 2015 Page 1 of 2

Subsystems (59)
lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

cover kernel: Add support for poweroff 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 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.

Patch 01/44 implements the poweroff handler API.

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

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

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

Patches 09/44 to 30/44 convert various drivers to register with the kernel poweroff handler instead of setting pm_power_off directly.

Patches 31/44 to 42/44 do the same for architecture code.

Patch 43/44 replaces a direct call to pm_power_off from a hwmon driver with a call to kernel_power_off. This patch is part of the series for completeness, but will find its way upstream through the hwmon subsystem.

Patch 44/44 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. In addition I build several additional configurations for various 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.17, with the pending restart handler patches applied.

I got a number of Acks from architecture maintainers as response to the RFC. I did not add those since the architecture code changed, and I did not think it was appropriate to retain the Acks.

A note on timing: My original plan was to submit this series after 3.18-rc1 was released. However, since the commit window will remain open for three weeks, and the series is, for all practical purposes, ready for review, I decided to submit it now. I plan to rebase it to 3.18-rc1 once available and send another version, hopefully including valuable feedback.

Important changes since RFC:
- Move API to new file kernel/power/poweroff_handler.c.
- Move pm_power_off pointer to kernel/power/poweroff_handler.c. Call pm_power_off from do_kernel_poweroff, and only call do_kernel_poweroff from architecture code instead of calling both pm_power_off and do_kernel_poweroff.
- Provide additional API function register_poweroff_handler_simple to simplify conversion of architecture code.
- Provide additional API function have_kernel_poweroff to check if a poweroff 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 Alexander Graf <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Aurelien Jacquiot <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Chen Liqin <[email protected]>
Cc Chris Metcalf <[email protected]>
Cc Chris Zankel <[email protected]>
Cc Corey Minyard <[email protected]>
Cc David Howells <[email protected]>
Cc David S. Miller <[email protected]>
Cc David Vrabel <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Greg Ungerer <[email protected]>
Cc Guan Xuetao <[email protected]>
Cc Haavard Skinnemoen <[email protected]>
Cc Hans-Christian Egtvedt <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Helge Deller <[email protected]>
Cc Hirokazu Takata <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Ivan Kokshaysky <[email protected]>
Cc James E.J. Bottomley <[email protected]>
Cc James Hogan <[email protected]>
Cc Jean Delvare <[email protected]>
Cc Jeff Dike <[email protected]>
Cc Jesper Nilsson <[email protected]>
Cc Jiri Kosina <[email protected]>
Cc Jonas Bonn <[email protected]>
Cc Joshua Thompson <[email protected]>
Cc Julian Andres Klode <[email protected]>
Cc Koichi Yasutake <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Lee Jones <[email protected]>
Cc Len Brown <[email protected]>
Cc Len Brown <[email protected]>
Cc Lennox Wu <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Maciej W. Rozycki <[email protected]>
Cc Marc Dietrich <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mark Salter <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Matt Fleming <[email protected]>
Cc Matt Turner <[email protected]>
Cc Max Filippov <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Michal Simek <[email protected]>
Cc Mikael Starvik <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Rafael J. Wysocki <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Richard Kuo <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Rob Herring <[email protected]>
Cc Romain Perier <[email protected]>
Cc Russell King <[email protected]>
Cc Rusty Russell <[email protected]>
Cc Samuel Ortiz <[email protected]>
Cc Santosh Shilimkar <[email protected]>
Cc Sebastian Reichel <[email protected]>
Cc Steven Miao <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Tony Luck <[email protected]>
Cc Vineet Gupta <[email protected]>
Cc Will Deacon <[email protected]>

----------------------------------------------------------------
Guenter Roeck (44):
kernel: Add support for poweroff handler call chain
memory: emif: Use API function to determine poweroff capability
hibernate: Call have_kernel_poweroff instead of checking pm_power_off
m68k: Replace mach_power_off with pm_power_off
mfd: as3722: Drop reference to pm_power_off from devicetree bindings
gpio-poweroff: Drop reference to pm_power_off from devicetree bindings
qnap-poweroff: Drop reference to pm_power_off from devicetree bindings
kernel: Move pm_power_off to common code
mfd: palmas: Register with kernel poweroff handler
mfd: axp20x: Register with kernel poweroff handler
mfd: retu: Register with kernel poweroff handler
mfd: ab8500-sysctrl: Register with kernel poweroff handler
mfd: max8907: Register with kernel poweroff handler
mfd: tps80031: Register with kernel poweroff handler
mfd: dm355evm_msp: Register with kernel poweroff handler
mfd: tps6586x: Register with kernel poweroff handler
mfd: tps65910: Register with kernel poweroff handler
mfd: twl4030-power: Register with kernel poweroff handler
ipmi: Register with kernel poweroff handler
power/reset: restart-poweroff: Register with kernel poweroff handler power/reset: gpio-poweroff: Register with kernel poweroff handler power/reset: as3722-poweroff: Register with kernel poweroff handler power/reset: qnap-poweroff: Register with kernel poweroff handler power/reset: msm-powroff: Register with kernel poweroff handler power/reset: vexpress-poweroff: Register with kernel poweroff handler
x86: iris: Register with kernel poweroff handler
x86: apm: Register with kernel poweroff handler
x86: olpc: Register xo1 poweroff handler with kernel poweroff handler
staging: nvec: Register with kernel poweroff handler
acpi: Register poweroff handler with kernel poweroff handler
arm: Register with kernel poweroff handler
arm64: psci: Register with kernel poweroff handler
avr32: atngw100: Register with kernel poweroff handler
ia64: Register with kernel poweroff handler
m68k: Register with kernel poweroff handler
mips: Register with kernel poweroff handler
sh: Register with kernel poweroff handler
x86: lguest: Register with kernel poweroff handler
x86: ce4100: Register with kernel poweroff handler
x86: intel-mid: Drop registration of dummy poweroff handlers
x86: pmc_atom: Register poweroff handler with kernel poweroff handler
efi: Register poweroff handler with kernel poweroff handler
hwmon: (ab8500) Call kernel_power_off instead of pm_power_off
kernel: Remove pm_power_off

 .../devicetree/bindings/gpio/gpio-poweroff.txt     |  10 +-
 Documentation/devicetree/bindings/mfd/as3722.txt   |   3 +-
 .../bindings/power_supply/qnap-poweroff.txt        |   4 +-
 arch/alpha/kernel/process.c                        |   9 +-
 arch/arc/kernel/reset.c                            |   5 +-
 arch/arm/kernel/process.c                          |   5 +-
 arch/arm/kernel/psci.c                             |   2 +-
 arch/arm/mach-at91/board-gsia18s.c                 |   2 +-
 arch/arm/mach-at91/setup.c                         |   4 +-
 arch/arm/mach-bcm/board_bcm2835.c                  |   2 +-
 arch/arm/mach-cns3xxx/cns3420vb.c                  |   2 +-
 arch/arm/mach-cns3xxx/core.c                       |   2 +-
 arch/arm/mach-highbank/highbank.c                  |   2 +-
 arch/arm/mach-imx/mach-mx31moboard.c               |   2 +-
 arch/arm/mach-iop32x/em7210.c                      |   2 +-
 arch/arm/mach-iop32x/glantank.c                    |   2 +-
 arch/arm/mach-iop32x/iq31244.c                     |   2 +-
 arch/arm/mach-iop32x/n2100.c                       |   2 +-
 arch/arm/mach-ixp4xx/dsmg600-setup.c               |   2 +-
 arch/arm/mach-ixp4xx/nas100d-setup.c               |   2 +-
 arch/arm/mach-ixp4xx/nslu2-setup.c                 |   2 +-
 arch/arm/mach-omap2/board-omap3touchbook.c         |   2 +-
 arch/arm/mach-orion5x/board-mss2.c                 |   2 +-
 arch/arm/mach-orion5x/dns323-setup.c               |   6 +-
 arch/arm/mach-orion5x/kurobox_pro-setup.c          |   2 +-
 arch/arm/mach-orion5x/ls-chl-setup.c               |   2 +-
 arch/arm/mach-orion5x/ls_hgl-setup.c               |   2 +-
 arch/arm/mach-orion5x/lsmini-setup.c               |   2 +-
 arch/arm/mach-orion5x/mv2120-setup.c               |   2 +-
 arch/arm/mach-orion5x/net2big-setup.c              |   2 +-
 arch/arm/mach-orion5x/terastation_pro2-setup.c     |   2 +-
 arch/arm/mach-orion5x/ts209-setup.c                |   2 +-
 arch/arm/mach-orion5x/ts409-setup.c                |   2 +-
 arch/arm/mach-pxa/corgi.c                          |   2 +-
 arch/arm/mach-pxa/mioa701.c                        |   2 +-
 arch/arm/mach-pxa/poodle.c                         |   2 +-
 arch/arm/mach-pxa/spitz.c                          |   2 +-
 arch/arm/mach-pxa/tosa.c                           |   2 +-
 arch/arm/mach-pxa/viper.c                          |   2 +-
 arch/arm/mach-pxa/z2.c                             |   6 +-
 arch/arm/mach-pxa/zeus.c                           |   6 +-
 arch/arm/mach-s3c24xx/mach-gta02.c                 |   2 +-
 arch/arm/mach-s3c24xx/mach-jive.c                  |   2 +-
 arch/arm/mach-s3c24xx/mach-vr1000.c                |   2 +-
 arch/arm/mach-s3c64xx/mach-smartq.c                |   2 +-
 arch/arm/mach-sa1100/generic.c                     |   2 +-
 arch/arm/mach-sa1100/simpad.c                      |   2 +-
 arch/arm/mach-u300/regulator.c                     |   2 +-
 arch/arm/mach-vt8500/vt8500.c                      |   2 +-
 arch/arm/xen/enlighten.c                           |   2 +-
 arch/arm64/kernel/process.c                        |   5 +-
 arch/arm64/kernel/psci.c                           |   2 +-
 arch/avr32/boards/atngw100/mrmt.c                  |   2 +-
 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/ia64/sn/kernel/setup.c                        |   4 +-
 arch/m32r/kernel/process.c                         |   8 +-
 arch/m68k/emu/natfeat.c                            |   3 +-
 arch/m68k/include/asm/machdep.h                    |   1 -
 arch/m68k/kernel/process.c                         |   7 +-
 arch/m68k/kernel/setup_mm.c                        |   1 -
 arch/m68k/kernel/setup_no.c                        |   1 -
 arch/m68k/mac/config.c                             |   3 +-
 arch/metag/kernel/process.c                        |   6 +-
 arch/microblaze/kernel/process.c                   |   3 -
 arch/microblaze/kernel/reset.c                     |   1 +
 arch/mips/alchemy/board-gpr.c                      |   2 +-
 arch/mips/alchemy/board-mtx1.c                     |   2 +-
 arch/mips/alchemy/board-xxs1500.c                  |   2 +-
 arch/mips/alchemy/devboards/platform.c             |  17 +-
 arch/mips/ar7/setup.c                              |   2 +-
 arch/mips/ath79/setup.c                            |   2 +-
 arch/mips/bcm47xx/setup.c                          |   2 +-
 arch/mips/bcm63xx/setup.c                          |   2 +-
 arch/mips/cobalt/setup.c                           |   2 +-
 arch/mips/dec/setup.c                              |   2 +-
 arch/mips/emma/markeins/setup.c                    |   2 +-
 arch/mips/jz4740/reset.c                           |   2 +-
 arch/mips/kernel/reset.c                           |   6 +-
 arch/mips/lantiq/falcon/reset.c                    |   2 +-
 arch/mips/lantiq/xway/reset.c                      |   2 +-
 arch/mips/lasat/reset.c                            |   2 +-
 arch/mips/loongson/common/reset.c                  |   2 +-
 arch/mips/loongson1/common/reset.c                 |   2 +-
 arch/mips/mti-malta/malta-reset.c                  |   2 +-
 arch/mips/mti-sead3/sead3-reset.c                  |   2 +-
 arch/mips/netlogic/xlp/setup.c                     |   2 +-
 arch/mips/netlogic/xlr/setup.c                     |   2 +-
 arch/mips/pmcs-msp71xx/msp_setup.c                 |   2 +-
 arch/mips/pnx833x/common/setup.c                   |   2 +-
 arch/mips/ralink/reset.c                           |   2 +-
 arch/mips/rb532/setup.c                            |   2 +-
 arch/mips/sgi-ip22/ip22-reset.c                    |   2 +-
 arch/mips/sgi-ip27/ip27-reset.c                    |   2 +-
 arch/mips/sgi-ip32/ip32-reset.c                    |   2 +-
 arch/mips/sibyte/common/cfe.c                      |   2 +-
 arch/mips/sni/setup.c                              |   2 +-
 arch/mips/txx9/generic/setup.c                     |   2 +-
 arch/mips/vr41xx/common/pmu.c                      |   2 +-
 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/s390/kernel/setup.c                           |   8 +-
 arch/score/kernel/process.c                        |   8 +-
 arch/sh/boards/board-sh7785lcr.c                   |   2 +-
 arch/sh/boards/board-urquell.c                     |   2 +-
 arch/sh/boards/mach-highlander/setup.c             |   2 +-
 arch/sh/boards/mach-landisk/setup.c                |   2 +-
 arch/sh/boards/mach-r2d/setup.c                    |   2 +-
 arch/sh/boards/mach-sdk7786/setup.c                |   2 +-
 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/apm_32.c                           |  20 ++-
 arch/x86/kernel/pmc_atom.c                         |  20 ++-
 arch/x86/kernel/reboot.c                           |  11 +-
 arch/x86/lguest/boot.c                             |   2 +-
 arch/x86/platform/ce4100/ce4100.c                  |   2 +-
 arch/x86/platform/intel-mid/intel-mid.c            |   5 -
 arch/x86/platform/intel-mid/mfld.c                 |   5 -
 arch/x86/platform/iris/iris.c                      |  25 ++-
 arch/x86/platform/olpc/olpc-xo1-pm.c               |  20 ++-
 arch/x86/xen/enlighten.c                           |   3 +-
 arch/xtensa/kernel/process.c                       |   4 -
 drivers/acpi/sleep.c                               |  15 +-
 drivers/char/ipmi/ipmi_poweroff.c                  |  30 ++--
 drivers/firmware/efi/reboot.c                      |  23 ++-
 drivers/hwmon/ab8500.c                             |   5 +-
 drivers/memory/emif.c                              |   4 +-
 drivers/mfd/ab8500-sysctrl.c                       |  26 ++--
 drivers/mfd/axp20x.c                               |  30 ++--
 drivers/mfd/dm355evm_msp.c                         |  18 ++-
 drivers/mfd/max8907.c                              |  24 ++-
 drivers/mfd/palmas.c                               |  30 ++--
 drivers/mfd/retu-mfd.c                             |  33 ++--
 drivers/mfd/tps6586x.c                             |  31 +++-
 drivers/mfd/tps65910.c                             |  27 ++--
 drivers/mfd/tps80031.c                             |  30 ++--
 drivers/mfd/twl4030-power.c                        |  25 ++-
 drivers/parisc/power.c                             |   3 +-
 drivers/power/reset/as3722-poweroff.c              |  36 +++--
 drivers/power/reset/gpio-poweroff.c                |  36 ++---
 drivers/power/reset/msm-poweroff.c                 |  13 +-
 drivers/power/reset/qnap-poweroff.c                |  28 ++--
 drivers/power/reset/restart-poweroff.c             |  25 ++-
 drivers/power/reset/vexpress-poweroff.c            |  19 ++-
 drivers/staging/nvec/nvec.c                        |  24 +--
 drivers/staging/nvec/nvec.h                        |   2 +
 include/linux/i2c/twl.h                            |   1 -
 include/linux/mfd/axp20x.h                         |   1 +
 include/linux/mfd/max8907.h                        |   2 +
 include/linux/mfd/palmas.h                         |   3 +
 include/linux/mfd/tps65910.h                       |   3 +
 include/linux/mfd/tps80031.h                       |   2 +
 include/linux/pm.h                                 |  14 +-
 kernel/power/Makefile                              |   1 +
 kernel/power/hibernate.c                           |   2 +-
 kernel/power/poweroff_handler.c                    | 173 +++++++++++++++++++++
 kernel/reboot.c                                    |   4 +-
 169 files changed, 794 insertions(+), 475 deletions(-)
 create mode 100644 kernel/power/poweroff_handler.c
author maintainer
#1 lore raw

PATCH 1/44 kernel: Add support for poweroff 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 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 <[email protected]>
cc Heiko Stuebner <[email protected]>
Cc Romain Perier <[email protected]>
Cc Rafael J. Wysocki <[email protected]>
Cc Len Brown <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Alexander Graf <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
---
 include/linux/pm.h              |  13 +++
 kernel/power/Makefile           |   1 +
 kernel/power/poweroff_handler.c | 172 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 186 insertions(+)
 create mode 100644 kernel/power/poweroff_handler.c
include/linux/pm.h +13 -0
index 72c0fe0..45271b5 100644
@@ -34,6 +34,19 @@
 extern void (*pm_power_off)(void);
 extern void (*pm_power_off_prepare)(void);
 
+/*
+ * Callbacks to manage poweroff handlers
+ */
+
+struct notifier_block;
+
+extern int register_poweroff_handler(struct notifier_block *);
+extern int register_poweroff_handler_simple(void (*function)(void),
+					    int priority);
+extern int unregister_poweroff_handler(struct notifier_block *);
+extern void do_kernel_poweroff(void);
+extern bool have_kernel_poweroff(void);
+
 struct device; /* we have a circular dep with device.h */
 #ifdef CONFIG_VT_CONSOLE_SLEEP
 extern void pm_vt_switch_required(struct device *dev, bool required);
kernel/power/Makefile +1 -0
index 29472bf..4d9f0c7 100644
@@ -2,6 +2,7 @@
 ccflags-$(CONFIG_PM_DEBUG)	:= -DDEBUG
 
 obj-y				+= qos.o
+obj-y				+= poweroff_handler.o
 obj-$(CONFIG_PM)		+= main.o
 obj-$(CONFIG_VT_CONSOLE_SLEEP)	+= console.o
 obj-$(CONFIG_FREEZER)		+= process.o
kernel/power/poweroff_handler.c new file +172 -0

172 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

Hello

This seems exactly what I would need on the mc13783 to handle cleanly the poweroff, but after reading this patchset I have the following question:

[...]

Quoted 5 lines
kernel/power/poweroff_handler.c new file +5 -0
+/*
+ *	Notifier list for kernel code which wants to be called
+ *	to power off the system.
+ */
+static ATOMIC_NOTIFIER_HEAD(poweroff_handler_list);

[...]

kernel/power/poweroff_handler.c line 162

Quoted 5 lines
kernel/power/poweroff_handler.c new file +5 -0
+void do_kernel_poweroff(void)
+{
+	atomic_notifier_call_chain(&poweroff_handler_list, 0, NULL);
+}
+

It seems that the poweroff callback needs to be atomic as per _atomic_notifier_call_chain documentation:

"Calls each function in a notifier chain in turn. The functions
run in an atomic context"

But this is a problem for many MFD (mc13783, twl4030 etc ...) which are accessible on only a blocking bus (SPI, I2C).

What I am missing here ?

Thanks,

Philippe

#3 lore raw
In reply to Guenter Roeck

Hello

This seems exactly what I would need on the mc13783 to handle cleanly the poweroff, but after reading this patchset I have the following question:

[...]

Quoted 5 lines
kernel/power/poweroff_handler.c new file +5 -0
+/*
+ *	Notifier list for kernel code which wants to be called
+ *	to power off the system.
+ */
+static ATOMIC_NOTIFIER_HEAD(poweroff_handler_list);

[...]

kernel/power/poweroff_handler.c line 162

Quoted 5 lines
kernel/power/poweroff_handler.c new file +5 -0
+void do_kernel_poweroff(void)
+{
+	atomic_notifier_call_chain(&poweroff_handler_list, 0, NULL);
+}
+

It seems that the poweroff callback needs to be atomic as per _atomic_notifier_call_chain documentation:

"Calls each function in a notifier chain in turn. The functions
run in an atomic context"

But this is a problem for many MFD (mc13783, twl4030 etc ...) which are accessible on only a blocking bus (SPI, I2C).

What I am missing here ?

Thanks,

Philippe

#4 lore raw
In reply to Guenter Roeck
Quoted 17 lines · On Mon, 6 Oct 2014 22:28:03 -0700 Guenter Roeck <[email protected]> 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 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.

Quoted 8 lines

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.

Nice...

register_poweroff_handler_simple isn't threadsafe. I'm not sure it matters as we should only have one attempt per platform to use it anyway.

have_kernel_poweroff() has a similar problem - the answer isn't always valid by the time the call returns.

The actual poweroff logic is more of a problem - several of the Intel PMICs are on i2c bus, so are not going to be happy in an atomic context so I wonder if that is storing up problems for the future ?

Alan

author maintainer
#5 lore raw
Quoted 29 lines · One Thousand Gnomes
Quoted 17 lines · On Mon, 6 Oct 2014 22:28:03 -0700 Guenter Roeck <[email protected]> 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 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.

Quoted 8 lines

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.

Quoted 5 lines

Nice...

register_poweroff_handler_simple isn't threadsafe. I'm not sure it matters as we should only have one attempt per platform to use it anyway.

Yes, I know. Agreed, it should not matter, but maybe it can be solved by using raw notifiers and spinlocks for protection.

Quoted 3 lines

have_kernel_poweroff() has a similar problem - the answer isn't always valid by the time the call returns.

This is an interesting one. Logically the answer can not be guaranteed to be correct by the time it is evaluated in the calling code, no matter how much protection I add around it. Not sure if there is anything I can or should do about that.

Quoted 4 lines

The actual poweroff logic is more of a problem - several of the Intel PMICs are on i2c bus, so are not going to be happy in an atomic context so I wonder if that is storing up problems for the future ?

Yes, Philippe brought that up as well. I think I may have to use raw notifiers, and use spinlocks for protection. Would this work ?

Thanks,
Guenter

#6 lore raw
In reply to Guenter Roeck

Hi!

Quoted 22 lines
kernel/power/poweroff_handler.c new file +22 -0
+/**
+ *	register_poweroff_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_poweroff_handler.
+ *
+ *	This is a simplified version of register_poweroff_handler. It does not
+ *	take a notifier as argument, but a function pointer. The function
+ *	registers a poweroff handler with specified priority. Poweroff
+ *	handlers registered with this function can not be unregistered,
+ *	and only a single poweroff handler can be installed using it.
+ *
+ *	This function must not be called from modules and is therefore
+ *	not exported.
+ *
+ *	Returns -EBUSY if a poweroff handler has already been registered
+ *	using register_poweroff_handler_simple. Otherwise returns zero,
+ *	since atomic_notifier_chain_register() currently always returns zero.
+ */
+int register_poweroff_handler_simple(void (*handler)(void), int priority)
+{

kernel/power/poweroff_handler.c line 138

Quoted 10 lines
kernel/power/poweroff_handler.c new file +10 -0
+	char symname[KSYM_NAME_LEN];
+
+	if (poweroff_handler_data.handler) {
+		lookup_symbol_name((unsigned long)poweroff_handler_data.handler,
+				   symname);
+		pr_warn("Poweroff function already registered (%s)", symname);
+		lookup_symbol_name((unsigned long)handler, symname);
+		pr_cont(", cannot register %s\n", symname);
+		return -EBUSY;
+	}

Dunno, are you maybe overdoing the debugging infrastructure a bit? This is not going to happen in production, and if it does happen, developer can look the symbol name himself.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author maintainer
#7 lore raw
Quoted 30 lines · Pavel Machek

Hi!

Quoted 28 lines
kernel/power/poweroff_handler.c new file +28 -0
+/**
+ *	register_poweroff_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_poweroff_handler.
+ *
+ *	This is a simplified version of register_poweroff_handler. It does not
+ *	take a notifier as argument, but a function pointer. The function
+ *	registers a poweroff handler with specified priority. Poweroff
+ *	handlers registered with this function can not be unregistered,
+ *	and only a single poweroff handler can be installed using it.
+ *
+ *	This function must not be called from modules and is therefore
+ *	not exported.
+ *
+ *	Returns -EBUSY if a poweroff handler has already been registered
+ *	using register_poweroff_handler_simple. Otherwise returns zero,
+ *	since atomic_notifier_chain_register() currently always returns zero.
+ */
+int register_poweroff_handler_simple(void (*handler)(void), int priority)
+{
+	char symname[KSYM_NAME_LEN];
+
+	if (poweroff_handler_data.handler) {
+		lookup_symbol_name((unsigned long)poweroff_handler_data.handler,
+				   symname);
+		pr_warn("Poweroff function already registered (%s)", symname);
Quoted 8 lines

kernel/power/poweroff_handler.c line 138

Quoted 4 lines
kernel/power/poweroff_handler.c new file +4 -0
+		lookup_symbol_name((unsigned long)handler, symname);
+		pr_cont(", cannot register %s\n", symname);
+		return -EBUSY;
+	}

Dunno, are you maybe overdoing the debugging infrastructure a bit? This is not going to happen in production, and if it does happen, developer can look the symbol name himself.

On the other side, I don't think it hurts to have that message. Anyway, I'll use %ps as suggested by Geert.

Guenter

author maintainer
#8 lore raw
In reply to Pavel Machek
Quoted 30 lines · Pavel Machek

Hi!

Quoted 28 lines
kernel/power/poweroff_handler.c new file +28 -0
+/**
+ *	register_poweroff_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_poweroff_handler.
+ *
+ *	This is a simplified version of register_poweroff_handler. It does not
+ *	take a notifier as argument, but a function pointer. The function
+ *	registers a poweroff handler with specified priority. Poweroff
+ *	handlers registered with this function can not be unregistered,
+ *	and only a single poweroff handler can be installed using it.
+ *
+ *	This function must not be called from modules and is therefore
+ *	not exported.
+ *
+ *	Returns -EBUSY if a poweroff handler has already been registered
+ *	using register_poweroff_handler_simple. Otherwise returns zero,
+ *	since atomic_notifier_chain_register() currently always returns zero.
+ */
+int register_poweroff_handler_simple(void (*handler)(void), int priority)
+{
+	char symname[KSYM_NAME_LEN];
+
+	if (poweroff_handler_data.handler) {
+		lookup_symbol_name((unsigned long)poweroff_handler_data.handler,
+				   symname);
+		pr_warn("Poweroff function already registered (%s)", symname);
Quoted 8 lines

kernel/power/poweroff_handler.c line 138

Quoted 4 lines
kernel/power/poweroff_handler.c new file +4 -0
+		lookup_symbol_name((unsigned long)handler, symname);
+		pr_cont(", cannot register %s\n", symname);
+		return -EBUSY;
+	}

Dunno, are you maybe overdoing the debugging infrastructure a bit? This is not going to happen in production, and if it does happen, developer can look the symbol name himself.

On the other side, I don't think it hurts to have that message. Anyway, I'll use %ps as suggested by Geert.

Guenter

author maintainer
#9 lore raw
In reply to Pavel Machek
Quoted 30 lines · Pavel Machek

Hi!

Quoted 28 lines
kernel/power/poweroff_handler.c new file +28 -0
+/**
+ *	register_poweroff_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_poweroff_handler.
+ *
+ *	This is a simplified version of register_poweroff_handler. It does not
+ *	take a notifier as argument, but a function pointer. The function
+ *	registers a poweroff handler with specified priority. Poweroff
+ *	handlers registered with this function can not be unregistered,
+ *	and only a single poweroff handler can be installed using it.
+ *
+ *	This function must not be called from modules and is therefore
+ *	not exported.
+ *
+ *	Returns -EBUSY if a poweroff handler has already been registered
+ *	using register_poweroff_handler_simple. Otherwise returns zero,
+ *	since atomic_notifier_chain_register() currently always returns zero.
+ */
+int register_poweroff_handler_simple(void (*handler)(void), int priority)
+{
+	char symname[KSYM_NAME_LEN];
+
+	if (poweroff_handler_data.handler) {
+		lookup_symbol_name((unsigned long)poweroff_handler_data.handler,
+				   symname);
+		pr_warn("Poweroff function already registered (%s)", symname);
Quoted 8 lines

kernel/power/poweroff_handler.c line 138

Quoted 4 lines
kernel/power/poweroff_handler.c new file +4 -0
+		lookup_symbol_name((unsigned long)handler, symname);
+		pr_cont(", cannot register %s\n", symname);
+		return -EBUSY;
+	}

Dunno, are you maybe overdoing the debugging infrastructure a bit? This is not going to happen in production, and if it does happen, developer can look the symbol name himself.

On the other side, I don't think it hurts to have that message. Anyway, I'll use %ps as suggested by Geert.

Guenter

#10 lore raw
In reply to Guenter Roeck

Hi!

Quoted 22 lines
kernel/power/poweroff_handler.c new file +22 -0
+/**
+ *	register_poweroff_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_poweroff_handler.
+ *
+ *	This is a simplified version of register_poweroff_handler. It does not
+ *	take a notifier as argument, but a function pointer. The function
+ *	registers a poweroff handler with specified priority. Poweroff
+ *	handlers registered with this function can not be unregistered,
+ *	and only a single poweroff handler can be installed using it.
+ *
+ *	This function must not be called from modules and is therefore
+ *	not exported.
+ *
+ *	Returns -EBUSY if a poweroff handler has already been registered
+ *	using register_poweroff_handler_simple. Otherwise returns zero,
+ *	since atomic_notifier_chain_register() currently always returns zero.
+ */
+int register_poweroff_handler_simple(void (*handler)(void), int priority)
+{

kernel/power/poweroff_handler.c line 138

Quoted 10 lines
kernel/power/poweroff_handler.c new file +10 -0
+	char symname[KSYM_NAME_LEN];
+
+	if (poweroff_handler_data.handler) {
+		lookup_symbol_name((unsigned long)poweroff_handler_data.handler,
+				   symname);
+		pr_warn("Poweroff function already registered (%s)", symname);
+		lookup_symbol_name((unsigned long)handler, symname);
+		pr_cont(", cannot register %s\n", symname);
+		return -EBUSY;
+	}

Dunno, are you maybe overdoing the debugging infrastructure a bit? This is not going to happen in production, and if it does happen, developer can look the symbol name himself.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#11 lore raw
In reply to Guenter Roeck

kernel/power/poweroff_handler.c line 136

Quoted 10 lines · Guenter Roeck
kernel/power/poweroff_handler.c new file +10 -0
+int register_poweroff_handler_simple(void (*handler)(void), int priority)
+{
+       char symname[KSYM_NAME_LEN];
+
+       if (poweroff_handler_data.handler) {
+               lookup_symbol_name((unsigned long)poweroff_handler_data.handler,
+                                  symname);
+               pr_warn("Poweroff function already registered (%s)", symname);
+               lookup_symbol_name((unsigned long)handler, symname);
+               pr_cont(", cannot register %s\n", symname);

Doesn't %ps work to look up symbols?

pr_warn("Poweroff function already registered (%ps), cannot register %ps\n", poweroff_handler_data.handler, handler);

Review

Quoted 2 lines
(quoted diff) +2 -0
+               return -EBUSY;
+       }

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author maintainer
#12 lore raw
Quoted 14 lines · Geert Uytterhoeven

kernel/power/poweroff_handler.c line 136

Quoted 10 lines · Guenter Roeck
kernel/power/poweroff_handler.c new file +10 -0
+int register_poweroff_handler_simple(void (*handler)(void), int priority)
+{
+       char symname[KSYM_NAME_LEN];
+
+       if (poweroff_handler_data.handler) {
+               lookup_symbol_name((unsigned long)poweroff_handler_data.handler,
+                                  symname);
+               pr_warn("Poweroff function already registered (%s)", symname);
+               lookup_symbol_name((unsigned long)handler, symname);
+               pr_cont(", cannot register %s\n", symname);

Doesn't %ps work to look up symbols?

Quoted 3 lines

pr_warn("Poweroff function already registered (%ps), cannot register %ps\n", poweroff_handler_data.handler, handler);

Hi Geert,

That is great. One never stops learning. I'll use that.

Thanks!

Guenter

author maintainer
#13 lore raw
In reply to Geert Uytterhoeven
Quoted 14 lines · Geert Uytterhoeven

kernel/power/poweroff_handler.c line 136

Quoted 10 lines · Guenter Roeck
kernel/power/poweroff_handler.c new file +10 -0
+int register_poweroff_handler_simple(void (*handler)(void), int priority)
+{
+       char symname[KSYM_NAME_LEN];
+
+       if (poweroff_handler_data.handler) {
+               lookup_symbol_name((unsigned long)poweroff_handler_data.handler,
+                                  symname);
+               pr_warn("Poweroff function already registered (%s)", symname);
+               lookup_symbol_name((unsigned long)handler, symname);
+               pr_cont(", cannot register %s\n", symname);

Doesn't %ps work to look up symbols?

Quoted 3 lines

pr_warn("Poweroff function already registered (%ps), cannot register %ps\n", poweroff_handler_data.handler, handler);

Hi Geert,

That is great. One never stops learning. I'll use that.

Thanks!

Guenter

#14 lore raw
In reply to Guenter Roeck

kernel/power/poweroff_handler.c line 136

Quoted 10 lines · Guenter Roeck
kernel/power/poweroff_handler.c new file +10 -0
+int register_poweroff_handler_simple(void (*handler)(void), int priority)
+{
+       char symname[KSYM_NAME_LEN];
+
+       if (poweroff_handler_data.handler) {
+               lookup_symbol_name((unsigned long)poweroff_handler_data.handler,
+                                  symname);
+               pr_warn("Poweroff function already registered (%s)", symname);
+               lookup_symbol_name((unsigned long)handler, symname);
+               pr_cont(", cannot register %s\n", symname);

Doesn't %ps work to look up symbols?

pr_warn("Poweroff function already registered (%ps), cannot register %ps\n", poweroff_handler_data.handler, handler);

Review

Quoted 2 lines
(quoted diff) +2 -0
+               return -EBUSY;
+       }

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#15 lore raw
In reply to Guenter Roeck
Quoted 17 lines · Guenter Roeck

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.

Quoted 8 lines

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.

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

I'm also considering putting the PMIC configuration part into the reboot notifier chain, because it only does things to change the configuration and not actually any shutdown/restart itself. That removes any requirement to get the priority of notifiers right. This series will still be useful for the MMIO register that needs to be toggled though. Right now I have to assign pm_power_off or hook the reboot notifier with a different priority to make this work.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#16 lore raw
Quoted 27 lines · Stephen Boyd
Quoted 17 lines · Guenter Roeck

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.

Quoted 8 lines

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.

Quoted 6 lines

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

I was wondering the same thing. I did find out that things kind of stalled after Linus cast doubt on the chosen path [1]. I'm not sure there's any consensus on what would be best to do instead.

Frans

[1] https://lkml.org/lkml/2014/11/6/641

author maintainer
#17 lore raw
Quoted 35 lines · Frans Klaver
Quoted 27 lines · Stephen Boyd
Quoted 17 lines · Guenter Roeck

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.

Quoted 8 lines

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.

Quoted 6 lines

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

Quoted 4 lines

I was wondering the same thing. I did find out that things kind of stalled after Linus cast doubt on the chosen path [1]. I'm not sure there's any consensus on what would be best to do instead.

Linus cast doubt on it, then the maintainers started picking it apart. At the end, trying not to use notifier callbacks made the code so complicated that even I didn't understand it anymore. With no consensus in sight, I abandoned it.

Problem is really that the notifier call chain would be perfect to solve the problem, yet Linus didn't like priorities (which are essential), and the power maintainers didn't like that a call chain is supposed to execute _all_ callbacks, which would not be the case here. If I were to start again, I would insist to use notifiers. However, I don't see a chance to get that accepted, so I won't. Feel free to pick it up and give it a try yourself.

Thanks,
Guenter

#18 lore raw
Quoted 53 lines · Guenter Roeck
Quoted 42 lines · Frans Klaver
Quoted 31 lines · Stephen Boyd
Quoted 18 lines · Guenter Roeck

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.

Quoted 9 lines

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.

Quoted 6 lines

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

Quoted 4 lines

I was wondering the same thing. I did find out that things kind of stalled after Linus cast doubt on the chosen path [1]. I'm not sure there's any consensus on what would be best to do instead.

Linus cast doubt on it, then the maintainers started picking it apart. At the end, trying not to use notifier callbacks made the code so complicated that even I didn't understand it anymore. With no consensus in sight, I abandoned it.

Quoted 7 lines

Problem is really that the notifier call chain would be perfect to solve the problem, yet Linus didn't like priorities (which are essential), and the power maintainers didn't like that a call chain is supposed to execute _all_ callbacks, which would not be the case here. If I were to start again, I would insist to use notifiers. However, I don't see a chance to get that accepted, so I won't. Feel free to pick it up and give it a try yourself.

How about having two phases? One where all interested parts of the system get notified, one that does the final shutdown. It's a slightly different approach than you took, but does use the notifier chains as expected, and can be used to prepare peripherals for shutdown, if there's a use case for it.

The two-stage approach does keep the single place to power down. I expect it would become more obvious that it would be silly to have more than one actual system power down sequence and hiding pm_power_off and unifying setting of it should become more straight forward as well.

Thoughts?

Thanks,
Frans

#19 lore raw
In reply to Guenter Roeck
Quoted 53 lines · Guenter Roeck
Quoted 42 lines · Frans Klaver
Quoted 31 lines · Stephen Boyd
Quoted 18 lines · Guenter Roeck

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.

Quoted 9 lines

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.

Quoted 6 lines

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

Quoted 4 lines

I was wondering the same thing. I did find out that things kind of stalled after Linus cast doubt on the chosen path [1]. I'm not sure there's any consensus on what would be best to do instead.

Linus cast doubt on it, then the maintainers started picking it apart. At the end, trying not to use notifier callbacks made the code so complicated that even I didn't understand it anymore. With no consensus in sight, I abandoned it.

Quoted 7 lines

Problem is really that the notifier call chain would be perfect to solve the problem, yet Linus didn't like priorities (which are essential), and the power maintainers didn't like that a call chain is supposed to execute _all_ callbacks, which would not be the case here. If I were to start again, I would insist to use notifiers. However, I don't see a chance to get that accepted, so I won't. Feel free to pick it up and give it a try yourself.

How about having two phases? One where all interested parts of the system get notified, one that does the final shutdown. It's a slightly different approach than you took, but does use the notifier chains as expected, and can be used to prepare peripherals for shutdown, if there's a use case for it.

The two-stage approach does keep the single place to power down. I expect it would become more obvious that it would be silly to have more than one actual system power down sequence and hiding pm_power_off and unifying setting of it should become more straight forward as well.

Thoughts?

Thanks,
Frans

author maintainer
#20 lore raw
In reply to Frans Klaver
Quoted 35 lines · Frans Klaver
Quoted 27 lines · Stephen Boyd
Quoted 17 lines · Guenter Roeck

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.

Quoted 8 lines

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.

Quoted 6 lines

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

Quoted 4 lines

I was wondering the same thing. I did find out that things kind of stalled after Linus cast doubt on the chosen path [1]. I'm not sure there's any consensus on what would be best to do instead.

Linus cast doubt on it, then the maintainers started picking it apart. At the end, trying not to use notifier callbacks made the code so complicated that even I didn't understand it anymore. With no consensus in sight, I abandoned it.

Problem is really that the notifier call chain would be perfect to solve the problem, yet Linus didn't like priorities (which are essential), and the power maintainers didn't like that a call chain is supposed to execute _all_ callbacks, which would not be the case here. If I were to start again, I would insist to use notifiers. However, I don't see a chance to get that accepted, so I won't. Feel free to pick it up and give it a try yourself.

Thanks,
Guenter

author maintainer
#21 lore raw
In reply to Frans Klaver
Quoted 35 lines · Frans Klaver
Quoted 27 lines · Stephen Boyd
Quoted 17 lines · Guenter Roeck

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.

Quoted 8 lines

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.

Quoted 6 lines

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

Quoted 4 lines

I was wondering the same thing. I did find out that things kind of stalled after Linus cast doubt on the chosen path [1]. I'm not sure there's any consensus on what would be best to do instead.

Linus cast doubt on it, then the maintainers started picking it apart. At the end, trying not to use notifier callbacks made the code so complicated that even I didn't understand it anymore. With no consensus in sight, I abandoned it.

Problem is really that the notifier call chain would be perfect to solve the problem, yet Linus didn't like priorities (which are essential), and the power maintainers didn't like that a call chain is supposed to execute _all_ callbacks, which would not be the case here. If I were to start again, I would insist to use notifiers. However, I don't see a chance to get that accepted, so I won't. Feel free to pick it up and give it a try yourself.

Thanks,
Guenter

#22 lore raw
In reply to Stephen Boyd
Quoted 27 lines · Stephen Boyd
Quoted 17 lines · Guenter Roeck

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.

Quoted 8 lines

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.

Quoted 6 lines

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

I was wondering the same thing. I did find out that things kind of stalled after Linus cast doubt on the chosen path [1]. I'm not sure there's any consensus on what would be best to do instead.

Frans

[1] https://lkml.org/lkml/2014/11/6/641

#23 lore raw
In reply to Stephen Boyd
Quoted 27 lines · Stephen Boyd
Quoted 17 lines · Guenter Roeck

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.

Quoted 8 lines

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.

Quoted 6 lines

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

I was wondering the same thing. I did find out that things kind of stalled after Linus cast doubt on the chosen path [1]. I'm not sure there's any consensus on what would be best to do instead.

Frans

[1] https://lkml.org/lkml/2014/11/6/641

author maintainer
#24 lore raw
In reply to Stephen Boyd

On Wed, Jun 17, 2015 at 06:04:54PM -0700, Stephen Boyd wrote:
[ ... ]

Quoted 8 lines

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

Can you use the .shutdown driver callback instead ?

I see other drivers use that, and check for system_state == SYSTEM_POWER_OFF to power off the hardware.

Guenter

#25 lore raw
Quoted 9 lines · Guenter Roeck

On Wed, Jun 17, 2015 at 06:04:54PM -0700, Stephen Boyd wrote:
[ ... ]

Quoted 7 lines

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

Quoted 5 lines

Can you use the .shutdown driver callback instead ?

I see other drivers use that, and check for system_state == SYSTEM_POWER_OFF to power off the hardware.

Yes I think that will work. I'll still have to hook pm_power_off() for the mmio register, but I guess that's ok and I don't need to worry about this series then.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#26 lore raw
In reply to Guenter Roeck
Quoted 9 lines · Guenter Roeck

On Wed, Jun 17, 2015 at 06:04:54PM -0700, Stephen Boyd wrote:
[ ... ]

Quoted 7 lines

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

Quoted 5 lines

Can you use the .shutdown driver callback instead ?

I see other drivers use that, and check for system_state == SYSTEM_POWER_OFF to power off the hardware.

Yes I think that will work. I'll still have to hook pm_power_off() for the mmio register, but I guess that's ok and I don't need to worry about this series then.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
author maintainer
#27 lore raw
In reply to Stephen Boyd

On Wed, Jun 17, 2015 at 06:04:54PM -0700, Stephen Boyd wrote:
[ ... ]

Quoted 8 lines

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

Can you use the .shutdown driver callback instead ?

I see other drivers use that, and check for system_state == SYSTEM_POWER_OFF to power off the hardware.

Guenter

author maintainer
#28 lore raw
In reply to Stephen Boyd

On Wed, Jun 17, 2015 at 06:04:54PM -0700, Stephen Boyd wrote:
[ ... ]

Quoted 8 lines

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

Can you use the .shutdown driver callback instead ?

I see other drivers use that, and check for system_state == SYSTEM_POWER_OFF to power off the hardware.

Guenter

#29 lore raw
In reply to Guenter Roeck
Quoted 17 lines · Guenter Roeck

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.

Quoted 8 lines

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.

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

I'm also considering putting the PMIC configuration part into the reboot notifier chain, because it only does things to change the configuration and not actually any shutdown/restart itself. That removes any requirement to get the priority of notifiers right. This series will still be useful for the MMIO register that needs to be toggled though. Right now I have to assign pm_power_off or hook the reboot notifier with a different priority to make this work.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#30 lore raw
In reply to Guenter Roeck
Quoted 17 lines · Guenter Roeck

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.

Quoted 8 lines

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.

What happened to this series? I want to add shutdown support to my platform and I need to write a register on the PMIC in one driver to configure it for shutdown instead of restart and then write an MMIO register to tell the PMIC to actually do the shutdown in another driver. It seems that the notifier solves this case for me, albeit with the slight complication that I need to order the two with some priority.

I'm also considering putting the PMIC configuration part into the reboot notifier chain, because it only does things to change the configuration and not actually any shutdown/restart itself. That removes any requirement to get the priority of notifiers right. This series will still be useful for the MMIO register that needs to be toggled though. Right now I have to assign pm_power_off or hook the reboot notifier with a different priority to make this work.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
author maintainer
#31 lore raw

PATCH 1/44 kernel: Add support for poweroff handler call chain

In reply to Guenter Roeck

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 <[email protected]>
cc Heiko Stuebner <[email protected]>
Cc Romain Perier <[email protected]>
Cc Rafael J. Wysocki <[email protected]>
Cc Len Brown <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Alexander Graf <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
---
 include/linux/pm.h              |  13 +++
 kernel/power/Makefile           |   1 +
 kernel/power/poweroff_handler.c | 172 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 186 insertions(+)
 create mode 100644 kernel/power/poweroff_handler.c
include/linux/pm.h +13 -0
index 72c0fe0..45271b5 100644
@@ -34,6 +34,19 @@
 extern void (*pm_power_off)(void);
 extern void (*pm_power_off_prepare)(void);
 
+/*
+ * Callbacks to manage poweroff handlers
+ */
+
+struct notifier_block;
+
+extern int register_poweroff_handler(struct notifier_block *);
+extern int register_poweroff_handler_simple(void (*function)(void),
+					    int priority);
+extern int unregister_poweroff_handler(struct notifier_block *);
+extern void do_kernel_poweroff(void);
+extern bool have_kernel_poweroff(void);
+
 struct device; /* we have a circular dep with device.h */
 #ifdef CONFIG_VT_CONSOLE_SLEEP
 extern void pm_vt_switch_required(struct device *dev, bool required);
kernel/power/Makefile +1 -0
index 29472bf..4d9f0c7 100644
@@ -2,6 +2,7 @@
 ccflags-$(CONFIG_PM_DEBUG)	:= -DDEBUG
 
 obj-y				+= qos.o
+obj-y				+= poweroff_handler.o
 obj-$(CONFIG_PM)		+= main.o
 obj-$(CONFIG_VT_CONSOLE_SLEEP)	+= console.o
 obj-$(CONFIG_FREEZER)		+= process.o
kernel/power/poweroff_handler.c new file +172 -0

172 lines not on this page · raw message

Signature · 1 line
1.9.1
author maintainer
#32 lore raw

PATCH 1/44 kernel: Add support for poweroff handler call chain

In reply to Guenter Roeck

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 <[email protected]>
cc Heiko Stuebner <[email protected]>
Cc Romain Perier <[email protected]>
Cc Rafael J. Wysocki <[email protected]>
Cc Len Brown <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Alexander Graf <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
---
 include/linux/pm.h              |  13 +++
 kernel/power/Makefile           |   1 +
 kernel/power/poweroff_handler.c | 172 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 186 insertions(+)
 create mode 100644 kernel/power/poweroff_handler.c
include/linux/pm.h +13 -0
index 72c0fe0..45271b5 100644
@@ -34,6 +34,19 @@
 extern void (*pm_power_off)(void);
 extern void (*pm_power_off_prepare)(void);
 
+/*
+ * Callbacks to manage poweroff handlers
+ */
+
+struct notifier_block;
+
+extern int register_poweroff_handler(struct notifier_block *);
+extern int register_poweroff_handler_simple(void (*function)(void),
+					    int priority);
+extern int unregister_poweroff_handler(struct notifier_block *);
+extern void do_kernel_poweroff(void);
+extern bool have_kernel_poweroff(void);
+
 struct device; /* we have a circular dep with device.h */
 #ifdef CONFIG_VT_CONSOLE_SLEEP
 extern void pm_vt_switch_required(struct device *dev, bool required);
kernel/power/Makefile +1 -0
index 29472bf..4d9f0c7 100644
@@ -2,6 +2,7 @@
 ccflags-$(CONFIG_PM_DEBUG)	:= -DDEBUG
 
 obj-y				+= qos.o
+obj-y				+= poweroff_handler.o
 obj-$(CONFIG_PM)		+= main.o
 obj-$(CONFIG_VT_CONSOLE_SLEEP)	+= console.o
 obj-$(CONFIG_FREEZER)		+= process.o
kernel/power/poweroff_handler.c new file +172 -0

172 lines not on this page · raw message

Signature · 1 line
1.9.1
author maintainer
#33 lore raw

PATCH 2/44 memory: emif: Use API function to determine poweroff capability

In reply to Guenter Roeck

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

Cc Santosh Shilimkar <[email protected]>
---
 drivers/memory/emif.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/memory/emif.c +2 -2
index 04644e7..acd830a 100644
@@ -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_poweroff()) {
 			kernel_power_off();
 		} else {
-			WARN(1, "FIXME: NO pm_power_off!!! trying restart\n");
+			WARN(1, "FIXME: NO kernel poweroff capability!!! trying restart\n");
 			kernel_restart("SDRAM Over-temp Emergency restart");
 		}
 		return IRQ_HANDLED;
Signature · 1 line
1.9.1
author maintainer
#34 lore raw

PATCH 2/44 memory: emif: Use API function to determine poweroff capability

In reply to Guenter Roeck

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

Cc Santosh Shilimkar <[email protected]>
---
 drivers/memory/emif.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/memory/emif.c +2 -2
index 04644e7..acd830a 100644
@@ -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_poweroff()) {
 			kernel_power_off();
 		} else {
-			WARN(1, "FIXME: NO pm_power_off!!! trying restart\n");
+			WARN(1, "FIXME: NO kernel poweroff capability!!! trying restart\n");
 			kernel_restart("SDRAM Over-temp Emergency restart");
 		}
 		return IRQ_HANDLED;
Signature · 1 line
1.9.1
author maintainer
#35 lore raw

PATCH 2/44 memory: emif: Use API function to determine poweroff capability

In reply to Guenter Roeck

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

Cc Santosh Shilimkar <[email protected]>
---
 drivers/memory/emif.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/memory/emif.c +2 -2
index 04644e7..acd830a 100644
@@ -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_poweroff()) {
 			kernel_power_off();
 		} else {
-			WARN(1, "FIXME: NO pm_power_off!!! trying restart\n");
+			WARN(1, "FIXME: NO kernel poweroff capability!!! trying restart\n");
 			kernel_restart("SDRAM Over-temp Emergency restart");
 		}
 		return IRQ_HANDLED;
Signature · 1 line
1.9.1
author maintainer
#36 lore raw

PATCH 3/44 hibernate: Call have_kernel_poweroff instead of checking pm_power_off

In reply to Guenter Roeck

Poweroff handlers may now be installed with register_poweroff_handler. Use the new API function have_kernel_poweroff to determine if a poweroff handler has been installed.

Cc Rafael J. Wysocki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
---
 kernel/power/hibernate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/hibernate.c +1 -1
index a9dfa79..20353c5 100644
@@ -602,7 +602,7 @@ static void power_down(void)
 	case HIBERNATION_PLATFORM:
 		hibernation_platform_enter();
 	case HIBERNATION_SHUTDOWN:
-		if (pm_power_off)
+		if (have_kernel_poweroff())
 			kernel_power_off();
 		break;
 #ifdef CONFIG_SUSPEND
Signature · 1 line
1.9.1
#37 lore raw

Re: [PATCH 03/44] hibernate: Call have_kernel_poweroff instead of checking pm_power_off

Quoted 8 lines · Guenter Roeck

Poweroff handlers may now be installed with register_poweroff_handler. Use the new API function have_kernel_poweroff to determine if a poweroff handler has been installed.

Cc Rafael J. Wysocki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>

ACK

Quoted 18 lines
---
 kernel/power/hibernate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/hibernate.c +1 -1
index a9dfa79..20353c5 100644
@@ -602,7 +602,7 @@ static void power_down(void)
 	case HIBERNATION_PLATFORM:
 		hibernation_platform_enter();
 	case HIBERNATION_SHUTDOWN:
-		if (pm_power_off)
+		if (have_kernel_poweroff())
 			kernel_power_off();
 		break;
 #ifdef CONFIG_SUSPEND
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#38 lore raw

Re: [PATCH 03/44] hibernate: Call have_kernel_poweroff instead of checking pm_power_off

In reply to Guenter Roeck
Quoted 8 lines · Guenter Roeck

Poweroff handlers may now be installed with register_poweroff_handler. Use the new API function have_kernel_poweroff to determine if a poweroff handler has been installed.

Cc Rafael J. Wysocki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>

ACK

Quoted 18 lines
---
 kernel/power/hibernate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/hibernate.c +1 -1
index a9dfa79..20353c5 100644
@@ -602,7 +602,7 @@ static void power_down(void)
 	case HIBERNATION_PLATFORM:
 		hibernation_platform_enter();
 	case HIBERNATION_SHUTDOWN:
-		if (pm_power_off)
+		if (have_kernel_poweroff())
 			kernel_power_off();
 		break;
 #ifdef CONFIG_SUSPEND
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#39 lore raw

Re: [PATCH 03/44] hibernate: Call have_kernel_poweroff instead of checking pm_power_off

In reply to Guenter Roeck
Quoted 17 lines · Guenter Roeck

Poweroff handlers may now be installed with register_poweroff_handler. Use the new API function have_kernel_poweroff to determine if a poweroff handler has been installed.

Cc Rafael J. Wysocki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
---
 kernel/power/hibernate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/hibernate.c +0 -0
index a9dfa79..20353c5 100644

kernel/power/hibernate.c static void power_down(void) · line 607

Quoted 7 lines
kernel/power/hibernate.c +1 -1
@@ -602,7 +602,7 @@ static void power_down(void)
 	case HIBERNATION_PLATFORM:
 		hibernation_platform_enter();
 	case HIBERNATION_SHUTDOWN:
-		if (pm_power_off)
+		if (have_kernel_poweroff())
 			kernel_power_off();
 		break;

poweroff -> power_off.

But if you are playing with this, anyway... does it make sense to introduce kernel_power_off() that just works, no need to check have_..?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author maintainer
#40 lore raw

Re: [PATCH 03/44] hibernate: Call have_kernel_poweroff instead of checking pm_power_off

Quoted 13 lines · Pavel Machek
Quoted 12 lines · Guenter Roeck

Poweroff handlers may now be installed with register_poweroff_handler. Use the new API function have_kernel_poweroff to determine if a poweroff handler has been installed.

Cc Rafael J. Wysocki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
---
  kernel/power/hibernate.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

kernel/power/hibernate.c static void power_down(void) · line 607

Quoted 12 lines
kernel/power/hibernate.c +1 -1
index a9dfa79..20353c5 100644
@@ -602,7 +602,7 @@ static void power_down(void)
  	case HIBERNATION_PLATFORM:
  		hibernation_platform_enter();
  	case HIBERNATION_SHUTDOWN:
-		if (pm_power_off)
+		if (have_kernel_poweroff())
  			kernel_power_off();
  		break;

poweroff -> power_off.

As mentioned in my other reply, that was on purpose to distinguish existing functions from poweroff handler functions.

Quoted 4 lines

But if you are playing with this, anyway... does it make sense to introduce kernel_power_off() that just works, no need to check have_..?
Pavel

I am trying not to change existing behavior.

kernel_power_off is an existing function which does some cleanup before calling machine_power_off which in turn calls do_kernel_poweroff (or currently pm_power_off and may do some other machine specific stuff.

Sure, poweroff handling could be unified further. We could decide to enter an endless loop if machine_power_off() returns, or we could decide to dump a warning or panic in this case. But that is all separate from the issue I am trying to solve here, which is to provide a capability to register more than one poweroff handler. It would also not be that simple, since some architectures call machine_power_off() directly from various places.

Guenter

author maintainer
#41 lore raw

Re: [PATCH 03/44] hibernate: Call have_kernel_poweroff instead of checking pm_power_off

In reply to Pavel Machek
Quoted 13 lines · Pavel Machek
Quoted 12 lines · Guenter Roeck

Poweroff handlers may now be installed with register_poweroff_handler. Use the new API function have_kernel_poweroff to determine if a poweroff handler has been installed.

Cc Rafael J. Wysocki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
---
  kernel/power/hibernate.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

kernel/power/hibernate.c static void power_down(void) · line 607

Quoted 12 lines
kernel/power/hibernate.c +1 -1
index a9dfa79..20353c5 100644
@@ -602,7 +602,7 @@ static void power_down(void)
  	case HIBERNATION_PLATFORM:
  		hibernation_platform_enter();
  	case HIBERNATION_SHUTDOWN:
-		if (pm_power_off)
+		if (have_kernel_poweroff())
  			kernel_power_off();
  		break;

poweroff -> power_off.

As mentioned in my other reply, that was on purpose to distinguish existing functions from poweroff handler functions.

Quoted 4 lines

But if you are playing with this, anyway... does it make sense to introduce kernel_power_off() that just works, no need to check have_..?
Pavel

I am trying not to change existing behavior.

kernel_power_off is an existing function which does some cleanup before calling machine_power_off which in turn calls do_kernel_poweroff (or currently pm_power_off and may do some other machine specific stuff.

Sure, poweroff handling could be unified further. We could decide to enter an endless loop if machine_power_off() returns, or we could decide to dump a warning or panic in this case. But that is all separate from the issue I am trying to solve here, which is to provide a capability to register more than one poweroff handler. It would also not be that simple, since some architectures call machine_power_off() directly from various places.

Guenter

author maintainer
#42 lore raw

Re: [PATCH 03/44] hibernate: Call have_kernel_poweroff instead of checking pm_power_off

In reply to Pavel Machek
Quoted 13 lines · Pavel Machek
Quoted 12 lines · Guenter Roeck

Poweroff handlers may now be installed with register_poweroff_handler. Use the new API function have_kernel_poweroff to determine if a poweroff handler has been installed.

Cc Rafael J. Wysocki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
---
  kernel/power/hibernate.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

kernel/power/hibernate.c static void power_down(void) · line 607

Quoted 12 lines
kernel/power/hibernate.c +1 -1
index a9dfa79..20353c5 100644
@@ -602,7 +602,7 @@ static void power_down(void)
  	case HIBERNATION_PLATFORM:
  		hibernation_platform_enter();
  	case HIBERNATION_SHUTDOWN:
-		if (pm_power_off)
+		if (have_kernel_poweroff())
  			kernel_power_off();
  		break;

poweroff -> power_off.

As mentioned in my other reply, that was on purpose to distinguish existing functions from poweroff handler functions.

Quoted 4 lines

But if you are playing with this, anyway... does it make sense to introduce kernel_power_off() that just works, no need to check have_..?
Pavel

I am trying not to change existing behavior.

kernel_power_off is an existing function which does some cleanup before calling machine_power_off which in turn calls do_kernel_poweroff (or currently pm_power_off and may do some other machine specific stuff.

Sure, poweroff handling could be unified further. We could decide to enter an endless loop if machine_power_off() returns, or we could decide to dump a warning or panic in this case. But that is all separate from the issue I am trying to solve here, which is to provide a capability to register more than one poweroff handler. It would also not be that simple, since some architectures call machine_power_off() directly from various places.

Guenter

#43 lore raw

Re: [PATCH 03/44] hibernate: Call have_kernel_poweroff instead of checking pm_power_off

In reply to Guenter Roeck
Quoted 17 lines · Guenter Roeck

Poweroff handlers may now be installed with register_poweroff_handler. Use the new API function have_kernel_poweroff to determine if a poweroff handler has been installed.

Cc Rafael J. Wysocki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
---
 kernel/power/hibernate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/hibernate.c +0 -0
index a9dfa79..20353c5 100644

kernel/power/hibernate.c static void power_down(void) · line 607

Quoted 7 lines
kernel/power/hibernate.c +1 -1
@@ -602,7 +602,7 @@ static void power_down(void)
 	case HIBERNATION_PLATFORM:
 		hibernation_platform_enter();
 	case HIBERNATION_SHUTDOWN:
-		if (pm_power_off)
+		if (have_kernel_poweroff())
 			kernel_power_off();
 		break;

poweroff -> power_off.

But if you are playing with this, anyway... does it make sense to introduce kernel_power_off() that just works, no need to check have_..?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#44 lore raw

Re: [PATCH 03/44] hibernate: Call have_kernel_poweroff instead of checking pm_power_off

In reply to Guenter Roeck
Quoted 17 lines · Guenter Roeck

Poweroff handlers may now be installed with register_poweroff_handler. Use the new API function have_kernel_poweroff to determine if a poweroff handler has been installed.

Cc Rafael J. Wysocki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
---
 kernel/power/hibernate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/hibernate.c +0 -0
index a9dfa79..20353c5 100644

kernel/power/hibernate.c static void power_down(void) · line 607

Quoted 7 lines
kernel/power/hibernate.c +1 -1
@@ -602,7 +602,7 @@ static void power_down(void)
 	case HIBERNATION_PLATFORM:
 		hibernation_platform_enter();
 	case HIBERNATION_SHUTDOWN:
-		if (pm_power_off)
+		if (have_kernel_poweroff())
 			kernel_power_off();
 		break;

poweroff -> power_off.

But if you are playing with this, anyway... does it make sense to introduce kernel_power_off() that just works, no need to check have_..?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author maintainer
#45 lore raw

PATCH 3/44 hibernate: Call have_kernel_poweroff instead of checking pm_power_off

In reply to Guenter Roeck

Poweroff handlers may now be installed with register_poweroff_handler. Use the new API function have_kernel_poweroff to determine if a poweroff handler has been installed.

Cc Rafael J. Wysocki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
---
 kernel/power/hibernate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/hibernate.c +1 -1
index a9dfa79..20353c5 100644
@@ -602,7 +602,7 @@ static void power_down(void)
 	case HIBERNATION_PLATFORM:
 		hibernation_platform_enter();
 	case HIBERNATION_SHUTDOWN:
-		if (pm_power_off)
+		if (have_kernel_poweroff())
 			kernel_power_off();
 		break;
 #ifdef CONFIG_SUSPEND
Signature · 1 line
1.9.1
author maintainer
#46 lore raw

PATCH 3/44 hibernate: Call have_kernel_poweroff instead of checking pm_power_off

In reply to Guenter Roeck

Poweroff handlers may now be installed with register_poweroff_handler. Use the new API function have_kernel_poweroff to determine if a poweroff handler has been installed.

Cc Rafael J. Wysocki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
---
 kernel/power/hibernate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/hibernate.c +1 -1
index a9dfa79..20353c5 100644
@@ -602,7 +602,7 @@ static void power_down(void)
 	case HIBERNATION_PLATFORM:
 		hibernation_platform_enter();
 	case HIBERNATION_SHUTDOWN:
-		if (pm_power_off)
+		if (have_kernel_poweroff())
 			kernel_power_off();
 		break;
 #ifdef CONFIG_SUSPEND
Signature · 1 line
1.9.1
author maintainer
#47 lore raw

PATCH 4/44 m68k: Replace mach_power_off with pm_power_off

In reply to Guenter Roeck

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]>
---
 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(-)
arch/m68k/emu/natfeat.c +2 -1
index 71b78ec..91e2ae7 100644
@@ -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;
 }
arch/m68k/include/asm/machdep.h +0 -1
index 953ca21..f9fac51 100644
@@ -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;
arch/m68k/kernel/process.c +3 -2
index c55ff71..afe3d6e 100644
@@ -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 (;;);
 }
 
arch/m68k/kernel/setup_mm.c +0 -1
index 5b8ec4d..002fea6 100644
@@ -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);
arch/m68k/kernel/setup_no.c +0 -1
index 88c27d9..1520156 100644
@@ -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)
arch/m68k/mac/config.c +2 -1
index a471eab..677913ff 100644
@@ -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;
Signature · 1 line
1.9.1
maintainer Acked-by on v1 4/44
#48 lore raw

Re: [PATCH 04/44] m68k: Replace mach_power_off with pm_power_off

Quoted 2 lines · Guenter Roeck

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

Thanks!

Quoted 4 lines
Cc Geert Uytterhoeven <[email protected]>
Cc Greg Ungerer <[email protected]>
Cc Joshua Thompson <[email protected]>

Looks OK, so since you said it builds ;-)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

maintainer Acked-by on v1 4/44
#49 lore raw

Re: [PATCH 04/44] m68k: Replace mach_power_off with pm_power_off

In reply to Guenter Roeck
Quoted 2 lines · Guenter Roeck

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

Thanks!

Quoted 4 lines
Cc Geert Uytterhoeven <[email protected]>
Cc Greg Ungerer <[email protected]>
Cc Joshua Thompson <[email protected]>

Looks OK, so since you said it builds ;-)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author maintainer
#50 lore raw

PATCH 4/44 m68k: Replace mach_power_off with pm_power_off

In reply to Guenter Roeck

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]>
---
 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(-)
arch/m68k/emu/natfeat.c +2 -1
index 71b78ec..91e2ae7 100644
@@ -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;
 }
arch/m68k/include/asm/machdep.h +0 -1
index 953ca21..f9fac51 100644
@@ -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;
arch/m68k/kernel/process.c +3 -2
index c55ff71..afe3d6e 100644
@@ -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 (;;);
 }
 
arch/m68k/kernel/setup_mm.c +0 -1
index 5b8ec4d..002fea6 100644
@@ -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);
arch/m68k/kernel/setup_no.c +0 -1
index 88c27d9..1520156 100644
@@ -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)
arch/m68k/mac/config.c +2 -1
index a471eab..677913ff 100644
@@ -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;
Signature · 1 line
1.9.1
author maintainer
#51 lore raw

PATCH 4/44 m68k: Replace mach_power_off with pm_power_off

In reply to Guenter Roeck

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]>
---
 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(-)
arch/m68k/emu/natfeat.c +2 -1
index 71b78ec..91e2ae7 100644
@@ -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;
 }
arch/m68k/include/asm/machdep.h +0 -1
index 953ca21..f9fac51 100644
@@ -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;
arch/m68k/kernel/process.c +3 -2
index c55ff71..afe3d6e 100644
@@ -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 (;;);
 }
 
arch/m68k/kernel/setup_mm.c +0 -1
index 5b8ec4d..002fea6 100644
@@ -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);
arch/m68k/kernel/setup_no.c +0 -1
index 88c27d9..1520156 100644
@@ -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)
arch/m68k/mac/config.c +2 -1
index a471eab..677913ff 100644
@@ -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;
Signature · 1 line
1.9.1
author maintainer
#52 lore raw

PATCH 5/44 mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck

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]>
---
 Documentation/devicetree/bindings/mfd/as3722.txt | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Documentation/devicetree/bindings/mfd/as3722.txt +1 -2
index 4f64b2a..0b2a609 100644
@@ -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
Signature · 6 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
reviewer Acked-by on v1 5/44
#53 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

Quoted 11 lines · Guenter Roeck

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]>
---
 Documentation/devicetree/bindings/mfd/as3722.txt | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Thanks for the fix-up!

Mark.

Quoted 23 lines
Documentation/devicetree/bindings/mfd/as3722.txt +1 -2
index 4f64b2a..0b2a609 100644
@@ -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
Signature · 6 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
reviewer Acked-by on v1 5/44
#54 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck
Quoted 11 lines · Guenter Roeck

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]>
---
 Documentation/devicetree/bindings/mfd/as3722.txt | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Thanks for the fix-up!

Mark.

Quoted 23 lines
Documentation/devicetree/bindings/mfd/as3722.txt +1 -2
index 4f64b2a..0b2a609 100644
@@ -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
Signature · 6 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#55 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck
Quoted 3 lines · Guenter Roeck

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

So your argument is that linux/Documentation/devicetree/bindings should not be specific to Linux. Merely hosted in the Linux kernel source repository.

Well that's certainly a point of view.

Rob

author maintainer
#56 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

Quoted 11 lines · Rob Landley
Quoted 3 lines · Guenter Roeck

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

So your argument is that linux/Documentation/devicetree/bindings should not be specific to Linux. Merely hosted in the Linux kernel source repository.

Well that's certainly a point of view.

Not specifically my argument, really, and nothing new either. But, yes, I do think that devicetree bindings descriptions should not include implementation details, especially since those may change over time (as is the case here).

Thanks,
Guenter

#57 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

Quoted 10 lines · Guenter Roeck
Quoted 9 lines · Rob Landley
Quoted 3 lines · Guenter Roeck

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

So your argument is that linux/Documentation/devicetree/bindings should not be specific to Linux. Merely hosted in the Linux kernel source repository.

Quoted 6 lines
Quoted 2 lines

Well that's certainly a point of view.

Not specifically my argument, really, and nothing new either. But, yes, I do think that devicetree bindings descriptions should not include implementation details, especially since those may change over time (as is the case here).

I fully agree.

Many device trees come from outside the kernel (i.e. they are supplied by the system boot environment). Obviously these device trees cannot be changed at the whim of kernel developers, *and* it is perfectly reasonable to think that software other than the Linux kernel will run on this type of system too.

So yes, it is really true, device trees are not a Linux kernel private implementation detail, they are really an external ABI that, although documented in the kernel source tree, cannot be changed in incompatible ways as time progresses.

David Daney

#58 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

Quoted 30 lines · David Daney
Quoted 11 lines · Guenter Roeck
Quoted 10 lines · Rob Landley
Quoted 4 lines · Guenter Roeck

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

So your argument is that linux/Documentation/devicetree/bindings should not be specific to Linux. Merely hosted in the Linux kernel source repository.

Quoted 9 lines
Quoted 2 lines

Well that's certainly a point of view.

Not specifically my argument, really, and nothing new either. But, yes, I do
think that devicetree bindings descriptions should not include implementation
details, especially since those may change over time (as is the case here).

I fully agree.

Many device trees come from outside the kernel (i.e. they are supplied by the system boot environment). Obviously these device trees cannot be changed at the whim of kernel developers, *and* it is perfectly reasonable to think that software other than the Linux kernel will run on this type of system too.

Quoted 4 lines

So yes, it is really true, device trees are not a Linux kernel private implementation detail, they are really an external ABI that, although documented in the kernel source tree, cannot be changed in incompatible ways as time progresses.

Ah. Existing thing with backstory among the in-crowd, so I'll assume "git subtree" was previously suggested and you had that discussion already and decided against it.

Carry on,

Rob
--
To unsubscribe from this list: send the line "unsubscribe linux-metag" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#59 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to David Daney
Quoted 30 lines · David Daney
Quoted 11 lines · Guenter Roeck
Quoted 10 lines · Rob Landley
Quoted 4 lines · Guenter Roeck

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

So your argument is that linux/Documentation/devicetree/bindings should not be specific to Linux. Merely hosted in the Linux kernel source repository.

Quoted 9 lines
Quoted 2 lines

Well that's certainly a point of view.

Not specifically my argument, really, and nothing new either. But, yes, I do
think that devicetree bindings descriptions should not include implementation
details, especially since those may change over time (as is the case here).

I fully agree.

Many device trees come from outside the kernel (i.e. they are supplied by the system boot environment). Obviously these device trees cannot be changed at the whim of kernel developers, *and* it is perfectly reasonable to think that software other than the Linux kernel will run on this type of system too.

Quoted 4 lines

So yes, it is really true, device trees are not a Linux kernel private implementation detail, they are really an external ABI that, although documented in the kernel source tree, cannot be changed in incompatible ways as time progresses.

Ah. Existing thing with backstory among the in-crowd, so I'll assume "git subtree" was previously suggested and you had that discussion already and decided against it.

Carry on,

Rob

#60 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to David Daney
Quoted 30 lines · David Daney
Quoted 11 lines · Guenter Roeck
Quoted 10 lines · Rob Landley
Quoted 4 lines · Guenter Roeck

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

So your argument is that linux/Documentation/devicetree/bindings should not be specific to Linux. Merely hosted in the Linux kernel source repository.

Quoted 9 lines
Quoted 2 lines

Well that's certainly a point of view.

Not specifically my argument, really, and nothing new either. But, yes, I do
think that devicetree bindings descriptions should not include implementation
details, especially since those may change over time (as is the case here).

I fully agree.

Many device trees come from outside the kernel (i.e. they are supplied by the system boot environment). Obviously these device trees cannot be changed at the whim of kernel developers, *and* it is perfectly reasonable to think that software other than the Linux kernel will run on this type of system too.

Quoted 4 lines

So yes, it is really true, device trees are not a Linux kernel private implementation detail, they are really an external ABI that, although documented in the kernel source tree, cannot be changed in incompatible ways as time progresses.

Ah. Existing thing with backstory among the in-crowd, so I'll assume "git subtree" was previously suggested and you had that discussion already and decided against it.

Carry on,

Rob

#61 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck
Quoted 10 lines · Guenter Roeck
Quoted 9 lines · Rob Landley
Quoted 3 lines · Guenter Roeck

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

So your argument is that linux/Documentation/devicetree/bindings should not be specific to Linux. Merely hosted in the Linux kernel source repository.

Quoted 6 lines
Quoted 2 lines

Well that's certainly a point of view.

Not specifically my argument, really, and nothing new either. But, yes, I do think that devicetree bindings descriptions should not include implementation details, especially since those may change over time (as is the case here).

I fully agree.

Many device trees come from outside the kernel (i.e. they are supplied by the system boot environment). Obviously these device trees cannot be changed at the whim of kernel developers, *and* it is perfectly reasonable to think that software other than the Linux kernel will run on this type of system too.

So yes, it is really true, device trees are not a Linux kernel private implementation detail, they are really an external ABI that, although documented in the kernel source tree, cannot be changed in incompatible ways as time progresses.

David Daney

#62 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck
Quoted 10 lines · Guenter Roeck
Quoted 9 lines · Rob Landley
Quoted 3 lines · Guenter Roeck

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

So your argument is that linux/Documentation/devicetree/bindings should not be specific to Linux. Merely hosted in the Linux kernel source repository.

Quoted 6 lines
Quoted 2 lines

Well that's certainly a point of view.

Not specifically my argument, really, and nothing new either. But, yes, I do think that devicetree bindings descriptions should not include implementation details, especially since those may change over time (as is the case here).

I fully agree.

Many device trees come from outside the kernel (i.e. they are supplied by the system boot environment). Obviously these device trees cannot be changed at the whim of kernel developers, *and* it is perfectly reasonable to think that software other than the Linux kernel will run on this type of system too.

So yes, it is really true, device trees are not a Linux kernel private implementation detail, they are really an external ABI that, although documented in the kernel source tree, cannot be changed in incompatible ways as time progresses.

David Daney

author maintainer
#63 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to Rob Landley
Quoted 11 lines · Rob Landley
Quoted 3 lines · Guenter Roeck

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

So your argument is that linux/Documentation/devicetree/bindings should not be specific to Linux. Merely hosted in the Linux kernel source repository.

Well that's certainly a point of view.

Not specifically my argument, really, and nothing new either. But, yes, I do think that devicetree bindings descriptions should not include implementation details, especially since those may change over time (as is the case here).

Thanks,
Guenter

author maintainer
#64 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to Rob Landley
Quoted 11 lines · Rob Landley
Quoted 3 lines · Guenter Roeck

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

So your argument is that linux/Documentation/devicetree/bindings should not be specific to Linux. Merely hosted in the Linux kernel source repository.

Well that's certainly a point of view.

Not specifically my argument, really, and nothing new either. But, yes, I do think that devicetree bindings descriptions should not include implementation details, especially since those may change over time (as is the case here).

Thanks,
Guenter

reviewer
#65 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to Rob Landley
Quoted 8 lines · Rob Landley
Quoted 3 lines · Guenter Roeck

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

So your argument is that linux/Documentation/devicetree/bindings should not be specific to Linux. Merely hosted in the Linux kernel source repository.

Precisely. If nothing else as a general guideline this keeps us honest, and prevents us from embedding arbitrary implementation details into bidnings that cause pain later when we want to change things at either end.

There are already otehr users of these bindings, so we can't really claim they're strictly Linux-specific anyhow.

Quoted 1 line

Well that's certainly a point of view.

As far as I am aware, it's the point of view shared by the device tree maintainers, and it's been that way for a while.

I don't really follow your concern. For one thing were this followed more strictly this file wouldn't need patching at all to correct for this Linux-internal rework...

Thanks,
Mark.

reviewer
#66 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to Rob Landley
Quoted 8 lines · Rob Landley
Quoted 3 lines · Guenter Roeck

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

So your argument is that linux/Documentation/devicetree/bindings should not be specific to Linux. Merely hosted in the Linux kernel source repository.

Precisely. If nothing else as a general guideline this keeps us honest, and prevents us from embedding arbitrary implementation details into bidnings that cause pain later when we want to change things at either end.

There are already otehr users of these bindings, so we can't really claim they're strictly Linux-specific anyhow.

Quoted 1 line

Well that's certainly a point of view.

As far as I am aware, it's the point of view shared by the device tree maintainers, and it's been that way for a while.

I don't really follow your concern. For one thing were this followed more strictly this file wouldn't need patching at all to correct for this Linux-internal rework...

Thanks,
Mark.

#67 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck
Quoted 3 lines · Guenter Roeck

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

So your argument is that linux/Documentation/devicetree/bindings should not be specific to Linux. Merely hosted in the Linux kernel source repository.

Well that's certainly a point of view.

Rob

#68 lore raw

Re: [PATCH 05/44] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck
Quoted 3 lines · Guenter Roeck

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

So your argument is that linux/Documentation/devicetree/bindings should not be specific to Linux. Merely hosted in the Linux kernel source repository.

Well that's certainly a point of view.

Rob

author maintainer
#69 lore raw

PATCH 5/44 mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck

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]>
---
 Documentation/devicetree/bindings/mfd/as3722.txt | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Documentation/devicetree/bindings/mfd/as3722.txt +1 -2
index 4f64b2a..0b2a609 100644
@@ -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
Signature · 1 line
1.9.1
author maintainer
#70 lore raw

PATCH 5/44 mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck

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]>
---
 Documentation/devicetree/bindings/mfd/as3722.txt | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Documentation/devicetree/bindings/mfd/as3722.txt +1 -2
index 4f64b2a..0b2a609 100644
@@ -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
Signature · 1 line
1.9.1
author maintainer
#71 lore raw

PATCH 6/44 gpio-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck

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]>
---
 Documentation/devicetree/bindings/gpio/gpio-poweroff.txt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/gpio/gpio-poweroff.txt +5 -5
index d4eab92..c95a1a6 100644
@@ -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 poweroff 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 poweroff handler is called. If this optional
   property is not specified, the GPIO is initialized as an output in its
   inactive state.
 
Signature · 1 line
1.9.1
reviewer Acked-by on v1 6/44
#72 lore raw

Re: [PATCH 06/44] gpio-poweroff: Drop reference to pm_power_off from devicetree bindings

Quoted 6 lines · Guenter Roeck

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]>
Quoted 39 lines
---
 Documentation/devicetree/bindings/gpio/gpio-poweroff.txt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/gpio/gpio-poweroff.txt +5 -5
index d4eab92..c95a1a6 100644
@@ -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 poweroff 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 poweroff handler is called. If this optional
   property is not specified, the GPIO is initialized as an output in its
   inactive state.
 
Signature · 1 line
1.9.1
reviewer Acked-by on v1 6/44
#73 lore raw

Re: [PATCH 06/44] gpio-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck
Quoted 6 lines · Guenter Roeck

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]>
Quoted 39 lines
---
 Documentation/devicetree/bindings/gpio/gpio-poweroff.txt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/gpio/gpio-poweroff.txt +5 -5
index d4eab92..c95a1a6 100644
@@ -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 poweroff 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 poweroff handler is called. If this optional
   property is not specified, the GPIO is initialized as an output in its
   inactive state.
 
Signature · 1 line
1.9.1
maintainer Acked-by on v1 6/44
#74 lore raw

Re: [PATCH 06/44] gpio-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck
Quoted 7 lines · Guenter Roeck

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]>

Thanks
Andrew

Quoted 42 lines
---
 Documentation/devicetree/bindings/gpio/gpio-poweroff.txt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/gpio/gpio-poweroff.txt +5 -5
index d4eab92..c95a1a6 100644
@@ -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 poweroff 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 poweroff handler is called. If this optional
   property is not specified, the GPIO is initialized as an output in its
   inactive state.
 
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Acked-by on v1 6/44
#75 lore raw

Re: [PATCH 06/44] gpio-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck
Quoted 7 lines · Guenter Roeck

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]>

Thanks
Andrew

Quoted 42 lines
---
 Documentation/devicetree/bindings/gpio/gpio-poweroff.txt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/gpio/gpio-poweroff.txt +5 -5
index d4eab92..c95a1a6 100644
@@ -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 poweroff 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 poweroff handler is called. If this optional
   property is not specified, the GPIO is initialized as an output in its
   inactive state.
 
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Acked-by on v1 6/44
#76 lore raw

Re: [PATCH 06/44] gpio-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck
Quoted 7 lines · Guenter Roeck

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]>

Thanks
Andrew

Quoted 42 lines
---
 Documentation/devicetree/bindings/gpio/gpio-poweroff.txt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/gpio/gpio-poweroff.txt +5 -5
index d4eab92..c95a1a6 100644
@@ -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 poweroff 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 poweroff handler is called. If this optional
   property is not specified, the GPIO is initialized as an output in its
   inactive state.
 
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author maintainer
#77 lore raw

PATCH 6/44 gpio-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck

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]>
---
 Documentation/devicetree/bindings/gpio/gpio-poweroff.txt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/gpio/gpio-poweroff.txt +5 -5
index d4eab92..c95a1a6 100644
@@ -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 poweroff 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 poweroff handler is called. If this optional
   property is not specified, the GPIO is initialized as an output in its
   inactive state.
 
Signature · 1 line
1.9.1
author maintainer
#78 lore raw

PATCH 6/44 gpio-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck

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]>
---
 Documentation/devicetree/bindings/gpio/gpio-poweroff.txt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/gpio/gpio-poweroff.txt +5 -5
index d4eab92..c95a1a6 100644
@@ -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 poweroff 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 poweroff handler is called. If this optional
   property is not specified, the GPIO is initialized as an output in its
   inactive state.
 
Signature · 1 line
1.9.1
author maintainer
#79 lore raw

PATCH 7/44 qnap-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck

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]>
---
 Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt +2 -2
index af25e77..1e2260a 100644
@@ -3,8 +3,8 @@
 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. This driver installs a handler
+to power off the system.
 
 Synology NAS devices use a similar scheme, but a different baud rate,
 9600, and a different character, '1'.
Signature · 1 line
1.9.1
reviewer Acked-by on v1 7/44
#80 lore raw

Re: [PATCH 07/44] qnap-poweroff: Drop reference to pm_power_off from devicetree bindings

Quoted 16 lines · Guenter Roeck

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]>
---
 Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt +0 -0
index af25e77..1e2260a 100644

Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt line 7

Quoted 7 lines
Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt +2 -2
@@ -3,8 +3,8 @@
 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. This driver installs a handler
+to power off the system.

I'd remove the last sentence -- the driver is also independent of the HW, and the description of how the power off works at the HW level is sufficient.

With that:

Thanks,
Mark.

author maintainer
#81 lore raw

Re: [PATCH 07/44] qnap-poweroff: Drop reference to pm_power_off from devicetree bindings

Quoted 12 lines · Mark Rutland
Quoted 11 lines · Guenter Roeck

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]>
---
 Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 17 lines

Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt line 7

Quoted 12 lines
Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt +2 -2
index af25e77..1e2260a 100644
@@ -3,8 +3,8 @@
 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. This driver installs a handler
+to power off the system.

I'd remove the last sentence -- the driver is also independent of the HW, and the description of how the power off works at the HW level is sufficient.

Done.

Quoted 4 lines

With that:

Thanks!

Guenter

author maintainer
#82 lore raw

Re: [PATCH 07/44] qnap-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Mark Rutland
Quoted 12 lines · Mark Rutland
Quoted 11 lines · Guenter Roeck

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]>
---
 Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 17 lines

Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt line 7

Quoted 12 lines
Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt +2 -2
index af25e77..1e2260a 100644
@@ -3,8 +3,8 @@
 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. This driver installs a handler
+to power off the system.

I'd remove the last sentence -- the driver is also independent of the HW, and the description of how the power off works at the HW level is sufficient.

Done.

Quoted 4 lines

With that:

Thanks!

Guenter

reviewer Acked-by on v1 7/44
#83 lore raw

Re: [PATCH 07/44] qnap-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck
Quoted 16 lines · Guenter Roeck

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]>
---
 Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt +0 -0
index af25e77..1e2260a 100644

Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt line 7

Quoted 7 lines
Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt +2 -2
@@ -3,8 +3,8 @@
 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. This driver installs a handler
+to power off the system.

I'd remove the last sentence -- the driver is also independent of the HW, and the description of how the power off works at the HW level is sufficient.

With that:

Thanks,
Mark.

maintainer Acked-by on v1 7/44
#84 lore raw

Re: [PATCH 07/44] qnap-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck
Quoted 2 lines · Guenter Roeck

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

Thanks
Andrew

Quoted 32 lines
Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
---
 Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt +2 -2
index af25e77..1e2260a 100644
@@ -3,8 +3,8 @@
 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. This driver installs a handler
+to power off the system.
 
 Synology NAS devices use a similar scheme, but a different baud rate,
 9600, and a different character, '1'.
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Acked-by on v1 7/44
#85 lore raw

Re: [PATCH 07/44] qnap-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck
Quoted 2 lines · Guenter Roeck

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

Thanks
Andrew

Quoted 32 lines
Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
---
 Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt +2 -2
index af25e77..1e2260a 100644
@@ -3,8 +3,8 @@
 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. This driver installs a handler
+to power off the system.
 
 Synology NAS devices use a similar scheme, but a different baud rate,
 9600, and a different character, '1'.
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Acked-by on v1 7/44
#86 lore raw

Re: [PATCH 07/44] qnap-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck
Quoted 2 lines · Guenter Roeck

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

Thanks
Andrew

Quoted 32 lines
Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
---
 Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt +2 -2
index af25e77..1e2260a 100644
@@ -3,8 +3,8 @@
 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. This driver installs a handler
+to power off the system.
 
 Synology NAS devices use a similar scheme, but a different baud rate,
 9600, and a different character, '1'.
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author maintainer
#87 lore raw

PATCH 7/44 qnap-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck

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]>
---
 Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt +2 -2
index af25e77..1e2260a 100644
@@ -3,8 +3,8 @@
 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. This driver installs a handler
+to power off the system.
 
 Synology NAS devices use a similar scheme, but a different baud rate,
 9600, and a different character, '1'.
Signature · 1 line
1.9.1
author maintainer
#88 lore raw

PATCH 7/44 qnap-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck

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]>
---
 Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt +2 -2
index af25e77..1e2260a 100644
@@ -3,8 +3,8 @@
 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. This driver installs a handler
+to power off the system.
 
 Synology NAS devices use a similar scheme, but a different baud rate,
 9600, and a different character, '1'.
Signature · 1 line
1.9.1
author maintainer
#89 lore raw

PATCH 8/44 kernel: Move pm_power_off to common code

In reply to Guenter Roeck

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

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

Cc Richard Henderson <[email protected]>
Cc Ivan Kokshaysky <[email protected]>
Cc Matt Turner <[email protected]>
Cc Vineet Gupta <[email protected]>
Cc Russell King <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Haavard Skinnemoen <[email protected]>
Cc Hans-Christian Egtvedt <[email protected]>
Cc Steven Miao <[email protected]>
Cc Mark Salter <[email protected]>
Cc Aurelien Jacquiot <[email protected]>
Cc Mikael Starvik <[email protected]>
Cc Jesper Nilsson <[email protected]>
Cc David Howells <[email protected]>
Cc Richard Kuo <[email protected]>
Cc Tony Luck <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc Hirokazu Takata <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc James Hogan <[email protected]>
Cc Michal Simek <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Koichi Yasutake <[email protected]>
Cc Jonas Bonn <[email protected]>
Cc James E.J. Bottomley <[email protected]>
Cc Helge Deller <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Chen Liqin <[email protected]>
Cc Lennox Wu <[email protected]>
Cc David S. Miller <[email protected]>
Cc Chris Metcalf <[email protected]>
Cc Jeff Dike <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Guan Xuetao <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc David Vrabel <[email protected]>
Cc Chris Zankel <[email protected]>
Cc Max Filippov <[email protected]>
Cc Rafael J. Wysocki <[email protected]>
Cc Len Brown <[email protected]>
Cc Pavel Machek <[email protected]>
---
 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/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/poweroff_handler.c    |  8 ++++++++
 kernel/reboot.c                    |  4 ++--
 36 files changed, 68 insertions(+), 146 deletions(-)
arch/alpha/kernel/process.c +3 -6
index 1941a07..a463e8f 100644
@@ -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_poweroff();
+
 	common_shutdown(LINUX_REBOOT_CMD_POWER_OFF, NULL);
 }
 
arch/arc/kernel/reset.c +1 -4
index 2768fa1..8a4fc47 100644
@@ -26,9 +26,6 @@ void machine_restart(char *__unused)
 
 void machine_power_off(void)
 {
-	/* FIXME ::  power off ??? */
+	do_kernel_poweroff();
 	machine_halt();
 }
-
-void (*pm_power_off) (void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/arm/kernel/process.c +1 -4
index 9fced7b..954e79c 100644
@@ -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_poweroff();
 }
 
 /*
arch/arm64/kernel/process.c +1 -4
index e0ef8ba..db396bb 100644
@@ -94,8 +94,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);
 
@@ -155,8 +153,7 @@ void machine_power_off(void)
 {
 	local_irq_disable();
 	smp_send_stop();
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_poweroff();
 }
 
 /*
arch/avr32/kernel/process.c +1 -5
index 42a53e74..c6774d8 100644
@@ -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_poweroff();
 }
 
 void machine_restart(char *cmd)
arch/blackfin/kernel/process.c +0 -3
index 4aa5545..812dd83 100644
@@ -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
  */
arch/blackfin/kernel/reboot.c +2 -0
index c4f50a3..1da27d1 100644
@@ -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_poweroff();
 	idle_with_irq_disabled();
 }
 
arch/c6x/kernel/process.c +1 -8
index 57d2ea8..ddc4a61 100644
@@ -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_poweroff();
 	halt_loop();
 }
 
arch/cris/kernel/process.c +1 -3
index b78498e..eaafad0 100644
@@ -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_poweroff();
 }
 
 /*
arch/frv/kernel/process.c +2 -3
index 5d40aeb77..a673725 100644
@@ -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_poweroff();
+
 	for (;;);
 }
 
arch/hexagon/kernel/reset.c +2 -3
index 76483c1..cfb8e3663 100644
@@ -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_poweroff();
 	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);
arch/ia64/kernel/process.c +1 -4
index deed6fa..ac68302 100644
@@ -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_poweroff();
 	machine_halt();
 }
 
arch/m32r/kernel/process.c +4 -4
index e69221d..b71c852 100644
@@ -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_poweroff();
+	for (;;)
+		;
 }
 
 void show_regs(struct pt_regs * regs)
arch/m68k/kernel/process.c +1 -5
index afe3d6e..f2c02fe 100644
@@ -78,14 +78,10 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_poweroff();
 	for (;;);
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void show_regs(struct pt_regs * regs)
 {
 	printk("\n");
arch/metag/kernel/process.c +1 -5
index 483dff9..d725043 100644
@@ -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_poweroff();
 	smp_send_stop();
 	hard_processor_halt(HALT_OK);
 }
arch/microblaze/kernel/process.c +0 -3
index b2dd371..0ebca36 100644
@@ -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)
 {
 }
arch/microblaze/kernel/reset.c +1 -0
index fbe58c6..9498ee7 100644
@@ -103,6 +103,7 @@ void machine_halt(void)
 void machine_power_off(void)
 {
 	pr_notice("Machine power off...\n");
+	do_kernel_poweroff();
 	while (1)
 		;
 }
arch/mips/kernel/reset.c +1 -5
index 07fc524..f5e134d 100644
@@ -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_poweroff();
 }
arch/mn10300/kernel/process.c +2 -6
index 3707da5..00d8b61 100644
@@ -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_poweroff();
 }
 
 void show_regs(struct pt_regs *regs)
arch/openrisc/kernel/process.c +5 -3
index 386af25..f3ad1bc 100644
@@ -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_poweroff();
+
 	__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.
arch/parisc/kernel/process.c +4 -4
index 0bbbf0d..5f1d2af 100644
@@ -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_poweroff();
+
 	/* 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..
  */
arch/powerpc/kernel/setup-common.c +3 -3
index 1b0e260..b6b5fcb 100644
@@ -140,6 +140,9 @@ void machine_power_off(void)
 	machine_shutdown();
 	if (ppc_md.power_off)
 		ppc_md.power_off();
+
+	do_kernel_poweroff();
+
 #ifdef CONFIG_SMP
 	smp_send_stop();
 #endif
@@ -150,9 +153,6 @@ void machine_power_off(void)
 /* Used by the G5 thermal driver */
 EXPORT_SYMBOL_GPL(machine_power_off);
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
-
 void machine_halt(void)
 {
 	machine_shutdown();
arch/s390/kernel/setup.c +2 -6
index 82bc113..1fa182f 100644
@@ -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_poweroff();
+}
 
 static int __init early_parse_mem(char *p)
 {
arch/score/kernel/process.c +4 -4
index a1519ad3..cf9531a 100644
@@ -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_poweroff();
+}
 
 void ret_from_fork(void);
 void ret_from_kernel_thread(void);
arch/sh/kernel/reboot.c +1 -5
index 04afe5b..e59b2aa 100644
@@ -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_poweroff();
 }
 
 static void native_machine_halt(void)
arch/sparc/kernel/process_32.c +2 -8
index 50e7b62..3138191 100644
@@ -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_poweroff();
+
 	machine_halt();
 }
 
arch/sparc/kernel/reboot.c +2 -6
index eba7d91..6717c5d 100644
@@ -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_poweroff();
+
 	prom_halt();
 }
 
arch/tile/kernel/reboot.c +3 -4
index 6c5d2c0..706d3bd 100644
@@ -36,6 +36,9 @@ void machine_power_off(void)
 {
 	arch_local_irq_disable_all();
 	smp_send_stop();
+
+	do_kernel_poweroff();
+
 	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);
arch/um/kernel/reboot.c +0 -2
index ced8903..a82ef28 100644
@@ -11,8 +11,6 @@
 #include <os.h>
 #include <skas.h>
 
-void (*pm_power_off)(void);
-
 static void kill_off_processes(void)
 {
 	if (proc_mm)
arch/unicore32/kernel/process.c +1 -8
index b008e99..2d5d522 100644
@@ -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_poweroff();
 	machine_halt();
 }
 
arch/x86/kernel/reboot.c +3 -8
index 17962e6..7a5cc87 100644
@@ -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_poweroff()) {
 		if (!reboot_force)
 			machine_shutdown();
-		pm_power_off();
+		do_kernel_poweroff();
 	}
+
 	/* A fallback in case there is no PM info available */
 	tboot_shutdown(TB_SHUTDOWN_HALT);
 }
arch/x86/xen/enlighten.c +1 -2
index c0cb11f..ab8e056 100644
@@ -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_poweroff();
 	xen_reboot(SHUTDOWN_poweroff);
 }
 
arch/xtensa/kernel/process.c +0 -4
index 1c85323..c487296 100644
@@ -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)
drivers/parisc/power.c +1 -2
index 90cca5e..de5b2ff 100644
@@ -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();
 		}
 	}
 }
kernel/power/poweroff_handler.c +8 -0
index ed99e5e..96f59ef 100644
@@ -20,6 +20,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);
+
+/*
  *	Notifier list for kernel code which wants to be called
  *	to power off the system.
  */
@@ -157,6 +163,8 @@ int register_poweroff_handler_simple(void (*handler)(void), int priority)
  */
 void do_kernel_poweroff(void)
 {
+	if (pm_power_off)
+		pm_power_off();
 	atomic_notifier_call_chain(&poweroff_handler_list, 0, NULL);
 }
 
kernel/reboot.c +2 -2
index 5925f5a..897e275 100644
@@ -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 poweroff 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_poweroff())
 		cmd = LINUX_REBOOT_CMD_HALT;
 
 	mutex_lock(&reboot_mutex);
Signature · 1 line
1.9.1
maintainer Acked-by on v1 8/44
#90 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

Quoted 7 lines · Guenter Roeck

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

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

 arch/m68k/kernel/process.c         |  6 +-----

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

maintainer Acked-by on v1 8/44
#91 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck
Quoted 7 lines · Guenter Roeck

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

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

 arch/m68k/kernel/process.c         |  6 +-----

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

Acked-by on v1 8/44
#92 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck
Quoted 5 lines · Guenter Roeck

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

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

[...]

Quoted 1 line
 arch/x86/xen/enlighten.c           |  3 +--

The xen bits:

Although for a mechanical change like this I wonder if acks from all subsystem maintainers is really necessary.

David

Acked-by on v1 8/44
#93 lore raw

Re: [Xen-devel] [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck
Quoted 5 lines · Guenter Roeck

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

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

[...]

Quoted 1 line
 arch/x86/xen/enlighten.c           |  3 +--

The xen bits:

Although for a mechanical change like this I wonder if acks from all subsystem maintainers is really necessary.

David

author maintainer
#94 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

Quoted 7 lines · David Vrabel
Quoted 5 lines · Guenter Roeck

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

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

[...]

Quoted 9 lines
Quoted 1 line
  arch/x86/xen/enlighten.c           |  3 +--

The xen bits:

Although for a mechanical change like this I wonder if acks from all subsystem maintainers is really necessary.

Probably not, but helpful. On the other side, as others may have noticed, sending an e-mail with that many Cc: gets it classified as spam by many mailers. I'll have to find a way to cut that down for the next round without offending anyone.

Guenter

author maintainer
#95 lore raw

Re: [Xen-devel] [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to David Vrabel
Quoted 7 lines · David Vrabel
Quoted 5 lines · Guenter Roeck

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

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

[...]

Quoted 9 lines
Quoted 1 line
  arch/x86/xen/enlighten.c           |  3 +--

The xen bits:

Although for a mechanical change like this I wonder if acks from all subsystem maintainers is really necessary.

Probably not, but helpful. On the other side, as others may have noticed, sending an e-mail with that many Cc: gets it classified as spam by many mailers. I'll have to find a way to cut that down for the next round without offending anyone.

Guenter

#98 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck
Quoted 5 lines · Guenter Roeck

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

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

ACK

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#99 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck
Quoted 5 lines · Guenter Roeck

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

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

ACK

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
maintainer Acked-by on v1 8/44
#100 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck
Quoted 1 line · Guenter Roeck

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

For xtensa:

Quoted 3 lines

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

Signature · 2 lines
Thanks.
-- Max
Acked-by on v1 8/44
#101 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck
Quoted 5 lines · Guenter Roeck

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

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

For the CRIS parts:

Quoted 1 line
 arch/cris/kernel/process.c         |  4 +---

/^JN - Jesper Nilsson

Signature · 1 line
               Jesper Nilsson -- [email protected]
Acked-by on v1 8/44
#102 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck
Quoted 5 lines · Guenter Roeck

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

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

For the CRIS parts:

Quoted 1 line
 arch/cris/kernel/process.c         |  4 +---

/^JN - Jesper Nilsson

Signature · 1 line
               Jesper Nilsson -- [email protected]
Acked-by on v1 8/44
#103 lore raw

回复: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck
Quoted 6 lines · ----- Guenter Roeck

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

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

For UniCore32 part,

Thanks
Xuetao

Acked-by on v1 8/44
#104 lore raw

回复: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck
Quoted 6 lines · ----- Guenter Roeck

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

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

For UniCore32 part,

Thanks
Xuetao

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

maintainer Acked-by on v1 8/44
#105 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck
Quoted 14 lines · Guenter Roeck
arch/arm64/kernel/process.c +0 -2
index e0ef8ba..db396bb 100644
@@ -94,8 +94,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);
 

arch/arm64/kernel/process.c void machine_power_off(void) · line 157

Quoted 7 lines
arch/arm64/kernel/process.c +1 -2
@@ -155,8 +153,7 @@ void machine_power_off(void)
 {
        local_irq_disable();
        smp_send_stop();
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_poweroff();
 }
maintainer Acked-by on v1 8/44
#106 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck
Quoted 14 lines · Guenter Roeck
arch/arm64/kernel/process.c +0 -2
index e0ef8ba..db396bb 100644
@@ -94,8 +94,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);
 

arch/arm64/kernel/process.c void machine_power_off(void) · line 157

Quoted 7 lines
arch/arm64/kernel/process.c +1 -2
@@ -155,8 +153,7 @@ void machine_power_off(void)
 {
        local_irq_disable();
        smp_send_stop();
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_poweroff();
 }
Acked-by on v1 8/44
#107 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck

On Tuesday 07 October 2014 11:01 AM, Guenter Roeck wrote:

arch/arc/kernel/reset.c +1 -4
index 2768fa1..8a4fc47 100644
@@ -26,9 +26,6 @@ void machine_restart(char *__unused)
 
 void machine_power_off(void)
 {
-       /* FIXME ::  power off ??? */
+       do_kernel_poweroff();
        machine_halt();
 }
-
-void (*pm_power_off) (void) = NULL;
-EXPORT_SYMBOL(pm_power_off);

Thx,
-Vineet

Acked-by on v1 8/44
#108 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck

On Tuesday 07 October 2014 11:01 AM, Guenter Roeck wrote:

arch/arc/kernel/reset.c +1 -4
index 2768fa1..8a4fc47 100644
@@ -26,9 +26,6 @@ void machine_restart(char *__unused)
 
 void machine_power_off(void)
 {
-       /* FIXME ::  power off ??? */
+       do_kernel_poweroff();
        machine_halt();
 }
-
-void (*pm_power_off) (void) = NULL;
-EXPORT_SYMBOL(pm_power_off);

Thx,
-Vineet

#109 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck

Hi!

arch/alpha/kernel/process.c machine_halt(void) · line 183

Quoted 6 lines
arch/alpha/kernel/process.c +2 -0
@@ -184,6 +179,8 @@ machine_halt(void)
 void
 machine_power_off(void)
 {
+	do_kernel_poweroff();
+

poweroff -> power_off for consistency.

arch/blackfin/kernel/reboot.c void machine_halt(void) · line 113

Quoted 11 lines

index c4f50a3..1da27d1 100644

arch/blackfin/kernel/reboot.c +1 -0
@@ -106,6 +107,7 @@ void machine_halt(void)
 __attribute__((weak))
 void native_machine_power_off(void)
 {
+	do_kernel_poweroff();
 	idle_with_irq_disabled();
 }
 

So here we handle do_kernel_poweroff() returning,

arch/cris/kernel/process.c void machine_halt(void) · line 62

Quoted 11 lines
arch/cris/kernel/process.c +1 -0
index b78498e..eaafad0 100644
@@ -60,6 +57,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
+	do_kernel_poweroff();
 }
 

Here we don't.

arch/frv/kernel/process.c void machine_power_off(void) · line 111

Quoted 13 lines
arch/frv/kernel/process.c +2 -0
index 5d40aeb77..a673725 100644
@@ -107,6 +104,8 @@ void machine_power_off(void)
 	gdbstub_exit(0);
 #endif
 
+	do_kernel_poweroff();
+
 	for (;;);
 }
 

And here we do.

What is right?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author maintainer
#110 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

Quoted 11 lines · Pavel Machek

Hi!

arch/alpha/kernel/process.c machine_halt(void) · line 183

Quoted 6 lines
arch/alpha/kernel/process.c +2 -0
@@ -184,6 +179,8 @@ machine_halt(void)
  void
  machine_power_off(void)
  {
+	do_kernel_poweroff();
+

poweroff -> power_off for consistency.

Dunno; matter of personal preference. I started with that, but ultimately went with poweroff to distinguish poweroff handler functions from existing code, specifically kernel_power_off().

Does anyone else have an opinion ?

Quoted 46 lines

arch/blackfin/kernel/reboot.c void machine_halt(void) · line 113

Quoted 12 lines

index c4f50a3..1da27d1 100644

arch/blackfin/kernel/reboot.c +1 -0
@@ -106,6 +107,7 @@ void machine_halt(void)
  __attribute__((weak))
  void native_machine_power_off(void)
  {
+	do_kernel_poweroff();
  	idle_with_irq_disabled();
  }
 

So here we handle do_kernel_poweroff() returning,

arch/cris/kernel/process.c void machine_halt(void) · line 62

Quoted 11 lines
arch/cris/kernel/process.c +1 -0
index b78498e..eaafad0 100644
@@ -60,6 +57,7 @@ void machine_halt(void)
 
  void machine_power_off(void)
  {
+	do_kernel_poweroff();
  }
 

Here we don't.

arch/frv/kernel/process.c void machine_power_off(void) · line 111

Quoted 13 lines
arch/frv/kernel/process.c +2 -0
index 5d40aeb77..a673725 100644
@@ -107,6 +104,8 @@ void machine_power_off(void)
  	gdbstub_exit(0);
  #endif
 
+	do_kernel_poweroff();
+
  	for (;;);
  }
 

And here we do.

Quoted 2 lines

What is right?
Pavel

Up to the architecture maintainer to decide. My goal was to not change existing behavior if no poweroff handler is registered.

Guenter

#111 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

Hi!

Quoted 9 lines
Quoted 9 lines

arch/alpha/kernel/process.c machine_halt(void) · line 183

Quoted 6 lines
arch/alpha/kernel/process.c +2 -0
@@ -184,6 +179,8 @@ machine_halt(void)
 void
 machine_power_off(void)
 {
+	do_kernel_poweroff();
+

poweroff -> power_off for consistency.

Quoted 3 lines

Dunno; matter of personal preference. I started with that, but ultimately went with poweroff to distinguish poweroff handler functions from existing code, specifically kernel_power_off().

That works for you, but once it is merged, it is ugly/confusing typo.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author maintainer
#112 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

Quoted 11 lines · Pavel Machek

Hi!

Quoted 9 lines
Quoted 9 lines

arch/alpha/kernel/process.c machine_halt(void) · line 183

Quoted 6 lines
arch/alpha/kernel/process.c +2 -0
@@ -184,6 +179,8 @@ machine_halt(void)
  void
  machine_power_off(void)
  {
+	do_kernel_poweroff();
+

poweroff -> power_off for consistency.

Quoted 7 lines
Quoted 3 lines

Dunno; matter of personal preference. I started with that, but ultimately went with poweroff to distinguish poweroff handler functions from existing code, specifically kernel_power_off().

That works for you, but once it is merged, it is ugly/confusing typo.
Pavel

Ok, no problem, I'll change it.

Guenter

author maintainer
#113 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Pavel Machek
Quoted 11 lines · Pavel Machek

Hi!

Quoted 9 lines
Quoted 9 lines

arch/alpha/kernel/process.c machine_halt(void) · line 183

Quoted 6 lines
arch/alpha/kernel/process.c +2 -0
@@ -184,6 +179,8 @@ machine_halt(void)
  void
  machine_power_off(void)
  {
+	do_kernel_poweroff();
+

poweroff -> power_off for consistency.

Quoted 7 lines
Quoted 3 lines

Dunno; matter of personal preference. I started with that, but ultimately went with poweroff to distinguish poweroff handler functions from existing code, specifically kernel_power_off().

That works for you, but once it is merged, it is ugly/confusing typo.
Pavel

Ok, no problem, I'll change it.

Guenter

#114 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck

Hi!

Quoted 9 lines
Quoted 9 lines

arch/alpha/kernel/process.c machine_halt(void) · line 183

Quoted 6 lines
arch/alpha/kernel/process.c +2 -0
@@ -184,6 +179,8 @@ machine_halt(void)
 void
 machine_power_off(void)
 {
+	do_kernel_poweroff();
+

poweroff -> power_off for consistency.

Quoted 3 lines

Dunno; matter of personal preference. I started with that, but ultimately went with poweroff to distinguish poweroff handler functions from existing code, specifically kernel_power_off().

That works for you, but once it is merged, it is ugly/confusing typo.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author maintainer
#115 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Pavel Machek
Quoted 11 lines · Pavel Machek

Hi!

arch/alpha/kernel/process.c machine_halt(void) · line 183

Quoted 6 lines
arch/alpha/kernel/process.c +2 -0
@@ -184,6 +179,8 @@ machine_halt(void)
  void
  machine_power_off(void)
  {
+	do_kernel_poweroff();
+

poweroff -> power_off for consistency.

Dunno; matter of personal preference. I started with that, but ultimately went with poweroff to distinguish poweroff handler functions from existing code, specifically kernel_power_off().

Does anyone else have an opinion ?

Quoted 46 lines

arch/blackfin/kernel/reboot.c void machine_halt(void) · line 113

Quoted 12 lines

index c4f50a3..1da27d1 100644

arch/blackfin/kernel/reboot.c +1 -0
@@ -106,6 +107,7 @@ void machine_halt(void)
  __attribute__((weak))
  void native_machine_power_off(void)
  {
+	do_kernel_poweroff();
  	idle_with_irq_disabled();
  }
 

So here we handle do_kernel_poweroff() returning,

arch/cris/kernel/process.c void machine_halt(void) · line 62

Quoted 11 lines
arch/cris/kernel/process.c +1 -0
index b78498e..eaafad0 100644
@@ -60,6 +57,7 @@ void machine_halt(void)
 
  void machine_power_off(void)
  {
+	do_kernel_poweroff();
  }
 

Here we don't.

arch/frv/kernel/process.c void machine_power_off(void) · line 111

Quoted 13 lines
arch/frv/kernel/process.c +2 -0
index 5d40aeb77..a673725 100644
@@ -107,6 +104,8 @@ void machine_power_off(void)
  	gdbstub_exit(0);
  #endif
 
+	do_kernel_poweroff();
+
  	for (;;);
  }
 

And here we do.

Quoted 2 lines

What is right?
Pavel

Up to the architecture maintainer to decide. My goal was to not change existing behavior if no poweroff handler is registered.

Guenter

#116 lore raw

Re: [PATCH 08/44] kernel: Move pm_power_off to common code

In reply to Guenter Roeck

Hi!

arch/alpha/kernel/process.c machine_halt(void) · line 183

Quoted 6 lines
arch/alpha/kernel/process.c +2 -0
@@ -184,6 +179,8 @@ machine_halt(void)
 void
 machine_power_off(void)
 {
+	do_kernel_poweroff();
+

poweroff -> power_off for consistency.

arch/blackfin/kernel/reboot.c void machine_halt(void) · line 113

Quoted 11 lines

index c4f50a3..1da27d1 100644

arch/blackfin/kernel/reboot.c +1 -0
@@ -106,6 +107,7 @@ void machine_halt(void)
 __attribute__((weak))
 void native_machine_power_off(void)
 {
+	do_kernel_poweroff();
 	idle_with_irq_disabled();
 }
 

So here we handle do_kernel_poweroff() returning,

arch/cris/kernel/process.c void machine_halt(void) · line 62

Quoted 11 lines
arch/cris/kernel/process.c +1 -0
index b78498e..eaafad0 100644
@@ -60,6 +57,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
+	do_kernel_poweroff();
 }
 

Here we don't.

arch/frv/kernel/process.c void machine_power_off(void) · line 111

Quoted 13 lines
arch/frv/kernel/process.c +2 -0
index 5d40aeb77..a673725 100644
@@ -107,6 +104,8 @@ void machine_power_off(void)
 	gdbstub_exit(0);
 #endif
 
+	do_kernel_poweroff();
+
 	for (;;);
 }
 

And here we do.

What is right?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author maintainer
#119 lore raw

PATCH 9/44 mfd: palmas: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/palmas.c       | 30 +++++++++++++++++-------------
 include/linux/mfd/palmas.h |  3 +++
 2 files changed, 20 insertions(+), 13 deletions(-)
drivers/mfd/palmas.c +17 -13
index 28cb048..4d78847 100644
@@ -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,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 = 64;
+			ret = register_poweroff_handler(&palmas->poweroff_nb);
+			if (ret) {
+				dev_err(palmas->dev,
+					"Failed to 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;
 }
include/linux/mfd/palmas.h +3 -0
index fb0390a..4715057 100644
@@ -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;
 
Signature · 1 line
1.9.1
author maintainer
#120 lore raw

PATCH 9/44 mfd: palmas: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/palmas.c       | 30 +++++++++++++++++-------------
 include/linux/mfd/palmas.h |  3 +++
 2 files changed, 20 insertions(+), 13 deletions(-)
drivers/mfd/palmas.c +17 -13
index 28cb048..4d78847 100644
@@ -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,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 = 64;
+			ret = register_poweroff_handler(&palmas->poweroff_nb);
+			if (ret) {
+				dev_err(palmas->dev,
+					"Failed to 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;
 }
include/linux/mfd/palmas.h +3 -0
index fb0390a..4715057 100644
@@ -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;
 
Signature · 1 line
1.9.1
author maintainer
#121 lore raw

PATCH 9/44 mfd: palmas: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/palmas.c       | 30 +++++++++++++++++-------------
 include/linux/mfd/palmas.h |  3 +++
 2 files changed, 20 insertions(+), 13 deletions(-)
drivers/mfd/palmas.c +17 -13
index 28cb048..4d78847 100644
@@ -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,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 = 64;
+			ret = register_poweroff_handler(&palmas->poweroff_nb);
+			if (ret) {
+				dev_err(palmas->dev,
+					"Failed to 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;
 }
include/linux/mfd/palmas.h +3 -0
index fb0390a..4715057 100644
@@ -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;
 
Signature · 1 line
1.9.1
author maintainer
#122 lore raw

PATCH 10/44 mfd: axp20x: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 <sameo-VuQAYsv1563Yd54FQh9/[email protected]>
---
 drivers/mfd/axp20x.c       | 30 +++++++++++++++++-------------
 include/linux/mfd/axp20x.h |  1 +
 2 files changed, 18 insertions(+), 13 deletions(-)
drivers/mfd/axp20x.c +17 -13
index dee6539..238db4c 100644
@@ -17,7 +17,8 @@
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/pm_runtime.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
 #include <linux/regulator/consumer.h>
@@ -161,11 +162,16 @@ static struct mfd_cell axp20x_cells[] = {
 	},
 };
 
-static struct axp20x_dev *axp20x_pm_power_off;
-static void axp20x_power_off(void)
+static int axp20x_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
+
 {
-	regmap_write(axp20x_pm_power_off->regmap, AXP20X_OFF_CTRL,
-		     AXP20X_OFF);
+	struct axp20x_dev *axp20x = container_of(this, struct axp20x_dev,
+						 poweroff_nb);
+
+	regmap_write(axp20x->regmap, AXP20X_OFF_CTRL, AXP20X_OFF);
+
+	return NOTIFY_DONE;
 }
 
 static int axp20x_i2c_probe(struct i2c_client *i2c,
@@ -215,10 +221,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->poweroff_nb.notifier_call = axp20x_power_off;
+	axp20x->poweroff_nb.priority = 64;
+	ret = register_poweroff_handler(&axp20x->poweroff_nb);
+	if (ret)
+		dev_err(&i2c->dev, "failed to register poweroff handler\n");
 
 	dev_info(&i2c->dev, "AXP20X driver loaded\n");
 
@@ -229,10 +236,7 @@ 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;
-	}
+	unregister_poweroff_handler(&axp20x->poweroff_nb);
 
 	mfd_remove_devices(axp20x->dev);
 	regmap_del_irq_chip(axp20x->i2c_client->irq, axp20x->regmap_irqc);
include/linux/mfd/axp20x.h +1 -0
index d0e31a2..8f23b39 100644
@@ -175,6 +175,7 @@ struct axp20x_dev {
 	struct regmap			*regmap;
 	struct regmap_irq_chip_data	*regmap_irqc;
 	long				variant;
+	struct notifier_block		poweroff_nb;
 };
 
 #endif /* __LINUX_MFD_AXP20X_H */
Signature · 1 line
1.9.1
author maintainer
#123 lore raw

PATCH 10/44 mfd: axp20x: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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]>
---
 drivers/mfd/axp20x.c       | 30 +++++++++++++++++-------------
 include/linux/mfd/axp20x.h |  1 +
 2 files changed, 18 insertions(+), 13 deletions(-)
drivers/mfd/axp20x.c +17 -13
index dee6539..238db4c 100644
@@ -17,7 +17,8 @@
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/pm_runtime.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
 #include <linux/regulator/consumer.h>
@@ -161,11 +162,16 @@ static struct mfd_cell axp20x_cells[] = {
 	},
 };
 
-static struct axp20x_dev *axp20x_pm_power_off;
-static void axp20x_power_off(void)
+static int axp20x_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
+
 {
-	regmap_write(axp20x_pm_power_off->regmap, AXP20X_OFF_CTRL,
-		     AXP20X_OFF);
+	struct axp20x_dev *axp20x = container_of(this, struct axp20x_dev,
+						 poweroff_nb);
+
+	regmap_write(axp20x->regmap, AXP20X_OFF_CTRL, AXP20X_OFF);
+
+	return NOTIFY_DONE;
 }
 
 static int axp20x_i2c_probe(struct i2c_client *i2c,
@@ -215,10 +221,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->poweroff_nb.notifier_call = axp20x_power_off;
+	axp20x->poweroff_nb.priority = 64;
+	ret = register_poweroff_handler(&axp20x->poweroff_nb);
+	if (ret)
+		dev_err(&i2c->dev, "failed to register poweroff handler\n");
 
 	dev_info(&i2c->dev, "AXP20X driver loaded\n");
 
@@ -229,10 +236,7 @@ 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;
-	}
+	unregister_poweroff_handler(&axp20x->poweroff_nb);
 
 	mfd_remove_devices(axp20x->dev);
 	regmap_del_irq_chip(axp20x->i2c_client->irq, axp20x->regmap_irqc);
include/linux/mfd/axp20x.h +1 -0
index d0e31a2..8f23b39 100644
@@ -175,6 +175,7 @@ struct axp20x_dev {
 	struct regmap			*regmap;
 	struct regmap_irq_chip_data	*regmap_irqc;
 	long				variant;
+	struct notifier_block		poweroff_nb;
 };
 
 #endif /* __LINUX_MFD_AXP20X_H */
Signature · 1 line
1.9.1
author maintainer
#124 lore raw

PATCH 10/44 mfd: axp20x: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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]>
---
 drivers/mfd/axp20x.c       | 30 +++++++++++++++++-------------
 include/linux/mfd/axp20x.h |  1 +
 2 files changed, 18 insertions(+), 13 deletions(-)
drivers/mfd/axp20x.c +17 -13
index dee6539..238db4c 100644
@@ -17,7 +17,8 @@
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/pm_runtime.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
 #include <linux/regulator/consumer.h>
@@ -161,11 +162,16 @@ static struct mfd_cell axp20x_cells[] = {
 	},
 };
 
-static struct axp20x_dev *axp20x_pm_power_off;
-static void axp20x_power_off(void)
+static int axp20x_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
+
 {
-	regmap_write(axp20x_pm_power_off->regmap, AXP20X_OFF_CTRL,
-		     AXP20X_OFF);
+	struct axp20x_dev *axp20x = container_of(this, struct axp20x_dev,
+						 poweroff_nb);
+
+	regmap_write(axp20x->regmap, AXP20X_OFF_CTRL, AXP20X_OFF);
+
+	return NOTIFY_DONE;
 }
 
 static int axp20x_i2c_probe(struct i2c_client *i2c,
@@ -215,10 +221,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->poweroff_nb.notifier_call = axp20x_power_off;
+	axp20x->poweroff_nb.priority = 64;
+	ret = register_poweroff_handler(&axp20x->poweroff_nb);
+	if (ret)
+		dev_err(&i2c->dev, "failed to register poweroff handler\n");
 
 	dev_info(&i2c->dev, "AXP20X driver loaded\n");
 
@@ -229,10 +236,7 @@ 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;
-	}
+	unregister_poweroff_handler(&axp20x->poweroff_nb);
 
 	mfd_remove_devices(axp20x->dev);
 	regmap_del_irq_chip(axp20x->i2c_client->irq, axp20x->regmap_irqc);
include/linux/mfd/axp20x.h +1 -0
index d0e31a2..8f23b39 100644
@@ -175,6 +175,7 @@ struct axp20x_dev {
 	struct regmap			*regmap;
 	struct regmap_irq_chip_data	*regmap_irqc;
 	long				variant;
+	struct notifier_block		poweroff_nb;
 };
 
 #endif /* __LINUX_MFD_AXP20X_H */
Signature · 1 line
1.9.1
author maintainer
#125 lore raw

PATCH 11/44 mfd: retu: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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]>
---
 drivers/mfd/retu-mfd.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
drivers/mfd/retu-mfd.c +19 -14
index 663f8a3..64b60fa 100644
@@ -22,6 +22,8 @@
 #include <linux/slab.h>
 #include <linux/mutex.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/mfd/core.h>
 #include <linux/mfd/retu.h>
@@ -43,6 +45,7 @@ struct retu_dev {
 	struct device			*dev;
 	struct mutex			mutex;
 	struct regmap_irq_chip_data	*irq_data;
+	struct notifier_block		poweroff_nb;
 };
 
 static struct resource retu_pwrbutton_res[] = {
@@ -81,9 +84,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 +165,14 @@ int retu_write(struct retu_dev *rdev, u8 reg, u16 data)
 }
 EXPORT_SYMBOL_GPL(retu_write);
 
-static void retu_power_off(void)
+static int retu_power_off(struct notifier_block *this, unsigned long unused1,
+			  void *unused2)
 {
-	struct retu_dev *rdev = retu_pm_power_off;
+	struct retu_dev *rdev = container_of(this, struct retu_dev,
+					     poweroff_nb);
 	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 +185,9 @@ static void retu_power_off(void)
 	for (;;)
 		cpu_relax();
 
-	mutex_unlock(&retu_pm_power_off->mutex);
+	mutex_unlock(&rdev->mutex);
+
+	return NOTIFY_DONE;
 }
 
 static int retu_regmap_read(void *context, const void *reg, size_t reg_size,
@@ -279,9 +283,13 @@ 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->poweroff_nb.notifier_call = retu_power_off;
+		rdev->poweroff_nb.priority = 64;
+		ret = register_poweroff_handler(&rdev->poweroff_nb);
+		if (ret)
+			dev_err(rdev->dev,
+				"Failed to register poweroff handler\n");
 	}
 
 	return 0;
@@ -291,10 +299,7 @@ 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;
-	}
+	unregister_poweroff_handler(&rdev->poweroff_nb);
 	mfd_remove_devices(rdev->dev);
 	regmap_del_irq_chip(i2c->irq, rdev->irq_data);
 
Signature · 1 line
1.9.1
author maintainer
#126 lore raw

PATCH 11/44 mfd: retu: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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]>
---
 drivers/mfd/retu-mfd.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
drivers/mfd/retu-mfd.c +19 -14
index 663f8a3..64b60fa 100644
@@ -22,6 +22,8 @@
 #include <linux/slab.h>
 #include <linux/mutex.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/mfd/core.h>
 #include <linux/mfd/retu.h>
@@ -43,6 +45,7 @@ struct retu_dev {
 	struct device			*dev;
 	struct mutex			mutex;
 	struct regmap_irq_chip_data	*irq_data;
+	struct notifier_block		poweroff_nb;
 };
 
 static struct resource retu_pwrbutton_res[] = {
@@ -81,9 +84,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 +165,14 @@ int retu_write(struct retu_dev *rdev, u8 reg, u16 data)
 }
 EXPORT_SYMBOL_GPL(retu_write);
 
-static void retu_power_off(void)
+static int retu_power_off(struct notifier_block *this, unsigned long unused1,
+			  void *unused2)
 {
-	struct retu_dev *rdev = retu_pm_power_off;
+	struct retu_dev *rdev = container_of(this, struct retu_dev,
+					     poweroff_nb);
 	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 +185,9 @@ static void retu_power_off(void)
 	for (;;)
 		cpu_relax();
 
-	mutex_unlock(&retu_pm_power_off->mutex);
+	mutex_unlock(&rdev->mutex);
+
+	return NOTIFY_DONE;
 }
 
 static int retu_regmap_read(void *context, const void *reg, size_t reg_size,
@@ -279,9 +283,13 @@ 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->poweroff_nb.notifier_call = retu_power_off;
+		rdev->poweroff_nb.priority = 64;
+		ret = register_poweroff_handler(&rdev->poweroff_nb);
+		if (ret)
+			dev_err(rdev->dev,
+				"Failed to register poweroff handler\n");
 	}
 
 	return 0;
@@ -291,10 +299,7 @@ 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;
-	}
+	unregister_poweroff_handler(&rdev->poweroff_nb);
 	mfd_remove_devices(rdev->dev);
 	regmap_del_irq_chip(i2c->irq, rdev->irq_data);
 
Signature · 1 line
1.9.1
author maintainer
#127 lore raw

PATCH 11/44 mfd: retu: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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]>
---
 drivers/mfd/retu-mfd.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
drivers/mfd/retu-mfd.c +19 -14
index 663f8a3..64b60fa 100644
@@ -22,6 +22,8 @@
 #include <linux/slab.h>
 #include <linux/mutex.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/mfd/core.h>
 #include <linux/mfd/retu.h>
@@ -43,6 +45,7 @@ struct retu_dev {
 	struct device			*dev;
 	struct mutex			mutex;
 	struct regmap_irq_chip_data	*irq_data;
+	struct notifier_block		poweroff_nb;
 };
 
 static struct resource retu_pwrbutton_res[] = {
@@ -81,9 +84,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 +165,14 @@ int retu_write(struct retu_dev *rdev, u8 reg, u16 data)
 }
 EXPORT_SYMBOL_GPL(retu_write);
 
-static void retu_power_off(void)
+static int retu_power_off(struct notifier_block *this, unsigned long unused1,
+			  void *unused2)
 {
-	struct retu_dev *rdev = retu_pm_power_off;
+	struct retu_dev *rdev = container_of(this, struct retu_dev,
+					     poweroff_nb);
 	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 +185,9 @@ static void retu_power_off(void)
 	for (;;)
 		cpu_relax();
 
-	mutex_unlock(&retu_pm_power_off->mutex);
+	mutex_unlock(&rdev->mutex);
+
+	return NOTIFY_DONE;
 }
 
 static int retu_regmap_read(void *context, const void *reg, size_t reg_size,
@@ -279,9 +283,13 @@ 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->poweroff_nb.notifier_call = retu_power_off;
+		rdev->poweroff_nb.priority = 64;
+		ret = register_poweroff_handler(&rdev->poweroff_nb);
+		if (ret)
+			dev_err(rdev->dev,
+				"Failed to register poweroff handler\n");
 	}
 
 	return 0;
@@ -291,10 +299,7 @@ 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;
-	}
+	unregister_poweroff_handler(&rdev->poweroff_nb);
 	mfd_remove_devices(rdev->dev);
 	regmap_del_irq_chip(i2c->irq, rdev->irq_data);
 
Signature · 1 line
1.9.1
author maintainer
#128 lore raw

PATCH 12/44 mfd: ab8500-sysctrl: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Linus Walleij <[email protected]>
Cc Lee Jones <[email protected]>
Cc Samuel Ortiz <[email protected]>
---
 drivers/mfd/ab8500-sysctrl.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/mfd/ab8500-sysctrl.c +15 -11
index 8e0dae5..677438f 100644
@@ -6,6 +6,7 @@
 
 #include <linux/err.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
 #include <linux/reboot.h>
@@ -23,7 +24,8 @@
 
 static struct device *sysctrl_dev;
 
-static void ab8500_power_off(void)
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}
-
 	/*
 	 * If we have a charger connected and we're powering off,
 	 * reboot into charge-only mode.
@@ -83,8 +80,15 @@ shutdown:
 					 AB8500_STW4500CTRL1_SWRESET4500N);
 		(void)sigprocmask(SIG_SETMASK, &old, NULL);
 	}
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block ab8500_poweroff_nb = {
+	.notifier_call = ab8500_power_off,
+	.priority = 64,
+};
+
 /*
  * 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 +189,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 +198,9 @@ static int ab8500_sysctrl_probe(struct platform_device *pdev)
 
 	sysctrl_dev = &pdev->dev;
 
-	if (!pm_power_off)
-		pm_power_off = ab8500_power_off;
+	err = register_poweroff_handler(&ab8500_poweroff_nb);
+	if (err)
+		dev_err(&pdev->dev, "Failed to register poweroff handler\n");
 
 	pdata = plat->sysctrl;
 	if (pdata) {
@@ -226,11 +232,9 @@ static int ab8500_sysctrl_probe(struct platform_device *pdev)
 
 static int ab8500_sysctrl_remove(struct platform_device *pdev)
 {
+	unregister_poweroff_handler(&ab8500_poweroff_nb);
 	sysctrl_dev = NULL;
 
-	if (pm_power_off == ab8500_power_off)
-		pm_power_off = NULL;
-
 	return 0;
 }
 
Signature · 1 line
1.9.1
#129 lore raw

Re: [PATCH 12/44] mfd: ab8500-sysctrl: Register with kernel poweroff handler

Quoted 17 lines · Guenter Roeck

Register with kernel poweroff 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 Linus Walleij <[email protected]>
Cc Lee Jones <[email protected]>
Cc Samuel Ortiz <[email protected]>
---
 drivers/mfd/ab8500-sysctrl.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/mfd/ab8500-sysctrl.c +0 -0
index 8e0dae5..677438f 100644
@@ -6,6 +6,7 @@

[...]

drivers/mfd/ab8500-sysctrl.c static void ab8500_power_off(void) · line 40

Quoted 13 lines
drivers/mfd/ab8500-sysctrl.c +2 -4
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}

Can you explain the purpose of this change please?

Quoted 10 lines
drivers/mfd/ab8500-sysctrl.c +2 -0
 	/*
 	 * If we have a charger connected and we're powering off,
 	 * reboot into charge-only mode.
@@ -83,8 +80,15 @@ shutdown:
 					 AB8500_STW4500CTRL1_SWRESET4500N);
 		(void)sigprocmask(SIG_SETMASK, &old, NULL);
 	}
+
+	return NOTIFY_DONE;
 }
Signature · 8 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe linux-parisc" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#130 lore raw

Re: [PATCH 12/44] mfd: ab8500-sysctrl: Register with kernel poweroff handler

Quoted 16 lines · Lee Jones
Quoted 3 lines · Guenter Roeck
drivers/mfd/ab8500-sysctrl.c +0 -0
@@ -6,6 +6,7 @@

[...]

Quoted 9 lines
drivers/mfd/ab8500-sysctrl.c +2 -0
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
Quoted 6 lines

drivers/mfd/ab8500-sysctrl.c static void ab8500_power_off(void) · line 40

Quoted 4 lines
drivers/mfd/ab8500-sysctrl.c +0 -4
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}

Can you explain the purpose of this change please?

I guess it's because the sysctrl_dev is already initialised when registering the power_off handler, so there isn't a way to call the above function with a NULL sysctrl_dev. Probably even with the original code you didn't need this check (after some race fix in ab8500_sysctrl_remove but races is one of the things Guenter's patches try to address).

Signature · 1 line
Catalin
#131 lore raw

Re: [PATCH 12/44] mfd: ab8500-sysctrl: Register with kernel poweroff handler

Quoted 24 lines · Catalin Marinas
Quoted 16 lines · Lee Jones
Quoted 3 lines · Guenter Roeck
drivers/mfd/ab8500-sysctrl.c +0 -0
@@ -6,6 +6,7 @@

[...]

Quoted 9 lines
drivers/mfd/ab8500-sysctrl.c +2 -0
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
Quoted 6 lines

drivers/mfd/ab8500-sysctrl.c static void ab8500_power_off(void) · line 40

Quoted 4 lines
drivers/mfd/ab8500-sysctrl.c +0 -4
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}

Can you explain the purpose of this change please?

Quoted 6 lines

I guess it's because the sysctrl_dev is already initialised when registering the power_off handler, so there isn't a way to call the above function with a NULL sysctrl_dev. Probably even with the original code you didn't need this check (after some race fix in ab8500_sysctrl_remove but races is one of the things Guenter's patches try to address).

Sounds reasonable, although I think this change should be part of another patch.

Signature · 8 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author maintainer
#132 lore raw

Re: [PATCH 12/44] mfd: ab8500-sysctrl: Register with kernel poweroff handler

Quoted 33 lines · Lee Jones
Quoted 24 lines · Catalin Marinas
Quoted 16 lines · Lee Jones
Quoted 3 lines · Guenter Roeck
drivers/mfd/ab8500-sysctrl.c +0 -0
@@ -6,6 +6,7 @@

[...]

Quoted 9 lines
drivers/mfd/ab8500-sysctrl.c +2 -0
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
  {
  	sigset_t old;
  	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
  	struct power_supply *psy;
  	int ret;
 
Quoted 6 lines

drivers/mfd/ab8500-sysctrl.c static void ab8500_power_off(void) · line 40

Quoted 4 lines
drivers/mfd/ab8500-sysctrl.c +0 -4
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}

Can you explain the purpose of this change please?

Quoted 6 lines

I guess it's because the sysctrl_dev is already initialised when registering the power_off handler, so there isn't a way to call the above function with a NULL sysctrl_dev. Probably even with the original code you didn't need this check (after some race fix in ab8500_sysctrl_remove but races is one of the things Guenter's patches try to address).

Quoted 3 lines

Sounds reasonable, although I think this change should be part of another patch.

Sure, no problem. I'll split this into two patches.

Since we are at it, any idea what to do with the restart function in the same file ? It is not used anywhere.

Guenter

#133 lore raw

Re: [PATCH 12/44] mfd: ab8500-sysctrl: Register with kernel poweroff handler

Quoted 34 lines · Guenter Roeck
Quoted 33 lines · Lee Jones
Quoted 30 lines · Catalin Marinas
Quoted 16 lines · Lee Jones
Quoted 3 lines · Guenter Roeck
drivers/mfd/ab8500-sysctrl.c +0 -0
@@ -6,6 +6,7 @@

[...]

Quoted 9 lines
drivers/mfd/ab8500-sysctrl.c +2 -0
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
Quoted 6 lines

drivers/mfd/ab8500-sysctrl.c static void ab8500_power_off(void) · line 40

Quoted 4 lines
drivers/mfd/ab8500-sysctrl.c +0 -4
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}

Can you explain the purpose of this change please?

I guess it's because the sysctrl_dev is already initialised when registering the power_off handler, so there isn't a way to call the above function with a NULL sysctrl_dev. Probably even with the original code you didn't need this check (after some race fix in ab8500_sysctrl_remove but races is one of the things Guenter's patches try to address).

Quoted 7 lines
Quoted 3 lines

Sounds reasonable, although I think this change should be part of another patch.

Sure, no problem. I'll split this into two patches.

Since we are at it, any idea what to do with the restart function in the same file ? It is not used anywhere.

You can strip it out with Linus Walleij's Ack. Or I'll be happy to do it?

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author maintainer
#134 lore raw

Re: [PATCH 12/44] mfd: ab8500-sysctrl: Register with kernel poweroff handler

Quoted 39 lines · Lee Jones
Quoted 37 lines · Guenter Roeck
Quoted 36 lines · Lee Jones
Quoted 24 lines · Catalin Marinas
Quoted 16 lines · Lee Jones
Quoted 3 lines · Guenter Roeck
drivers/mfd/ab8500-sysctrl.c +0 -0
@@ -6,6 +6,7 @@

[...]

Quoted 9 lines
drivers/mfd/ab8500-sysctrl.c +2 -0
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
Quoted 6 lines

drivers/mfd/ab8500-sysctrl.c static void ab8500_power_off(void) · line 40

Quoted 4 lines
drivers/mfd/ab8500-sysctrl.c +0 -4
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}

Can you explain the purpose of this change please?

Quoted 6 lines

I guess it's because the sysctrl_dev is already initialised when registering the power_off handler, so there isn't a way to call the above function with a NULL sysctrl_dev. Probably even with the original code you didn't need this check (after some race fix in ab8500_sysctrl_remove but races is one of the things Guenter's patches try to address).

Sounds reasonable, although I think this change should be part of another patch.

Quoted 8 lines
Quoted 4 lines

Sure, no problem. I'll split this into two patches.

Since we are at it, any idea what to do with the restart function in the same file ? It is not used anywhere.

You can strip it out with Linus Walleij's Ack. Or I'll be happy to do it?

I'll strip it out in a 3rd patch.

Guenter

author maintainer
#135 lore raw

Re: [PATCH 12/44] mfd: ab8500-sysctrl: Register with kernel poweroff handler

In reply to Lee Jones
Quoted 39 lines · Lee Jones
Quoted 37 lines · Guenter Roeck
Quoted 36 lines · Lee Jones
Quoted 24 lines · Catalin Marinas
Quoted 16 lines · Lee Jones
Quoted 3 lines · Guenter Roeck
drivers/mfd/ab8500-sysctrl.c +0 -0
@@ -6,6 +6,7 @@

[...]

Quoted 9 lines
drivers/mfd/ab8500-sysctrl.c +2 -0
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
Quoted 6 lines

drivers/mfd/ab8500-sysctrl.c static void ab8500_power_off(void) · line 40

Quoted 4 lines
drivers/mfd/ab8500-sysctrl.c +0 -4
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}

Can you explain the purpose of this change please?

Quoted 6 lines

I guess it's because the sysctrl_dev is already initialised when registering the power_off handler, so there isn't a way to call the above function with a NULL sysctrl_dev. Probably even with the original code you didn't need this check (after some race fix in ab8500_sysctrl_remove but races is one of the things Guenter's patches try to address).

Sounds reasonable, although I think this change should be part of another patch.

Quoted 8 lines
Quoted 4 lines

Sure, no problem. I'll split this into two patches.

Since we are at it, any idea what to do with the restart function in the same file ? It is not used anywhere.

You can strip it out with Linus Walleij's Ack. Or I'll be happy to do it?

I'll strip it out in a 3rd patch.

Guenter

#136 lore raw

Re: [PATCH 12/44] mfd: ab8500-sysctrl: Register with kernel poweroff handler

In reply to Guenter Roeck
Quoted 34 lines · Guenter Roeck
Quoted 33 lines · Lee Jones
Quoted 30 lines · Catalin Marinas
Quoted 16 lines · Lee Jones
Quoted 3 lines · Guenter Roeck
drivers/mfd/ab8500-sysctrl.c +0 -0
@@ -6,6 +6,7 @@

[...]

Quoted 9 lines
drivers/mfd/ab8500-sysctrl.c +2 -0
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
Quoted 6 lines

drivers/mfd/ab8500-sysctrl.c static void ab8500_power_off(void) · line 40

Quoted 4 lines
drivers/mfd/ab8500-sysctrl.c +0 -4
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}

Can you explain the purpose of this change please?

I guess it's because the sysctrl_dev is already initialised when registering the power_off handler, so there isn't a way to call the above function with a NULL sysctrl_dev. Probably even with the original code you didn't need this check (after some race fix in ab8500_sysctrl_remove but races is one of the things Guenter's patches try to address).

Quoted 7 lines
Quoted 3 lines

Sounds reasonable, although I think this change should be part of another patch.

Sure, no problem. I'll split this into two patches.

Since we are at it, any idea what to do with the restart function in the same file ? It is not used anywhere.

You can strip it out with Linus Walleij's Ack. Or I'll be happy to do it?

Signature · 9 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author maintainer
#137 lore raw

Re: [PATCH 12/44] mfd: ab8500-sysctrl: Register with kernel poweroff handler

In reply to Lee Jones
Quoted 33 lines · Lee Jones
Quoted 24 lines · Catalin Marinas
Quoted 16 lines · Lee Jones
Quoted 3 lines · Guenter Roeck
drivers/mfd/ab8500-sysctrl.c +0 -0
@@ -6,6 +6,7 @@

[...]

Quoted 9 lines
drivers/mfd/ab8500-sysctrl.c +2 -0
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
  {
  	sigset_t old;
  	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
  	struct power_supply *psy;
  	int ret;
 
Quoted 6 lines

drivers/mfd/ab8500-sysctrl.c static void ab8500_power_off(void) · line 40

Quoted 4 lines
drivers/mfd/ab8500-sysctrl.c +0 -4
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}

Can you explain the purpose of this change please?

Quoted 6 lines

I guess it's because the sysctrl_dev is already initialised when registering the power_off handler, so there isn't a way to call the above function with a NULL sysctrl_dev. Probably even with the original code you didn't need this check (after some race fix in ab8500_sysctrl_remove but races is one of the things Guenter's patches try to address).

Quoted 3 lines

Sounds reasonable, although I think this change should be part of another patch.

Sure, no problem. I'll split this into two patches.

Since we are at it, any idea what to do with the restart function in the same file ? It is not used anywhere.

Guenter

author maintainer
#138 lore raw

Re: [PATCH 12/44] mfd: ab8500-sysctrl: Register with kernel poweroff handler

In reply to Lee Jones
Quoted 33 lines · Lee Jones
Quoted 24 lines · Catalin Marinas
Quoted 16 lines · Lee Jones
Quoted 3 lines · Guenter Roeck
drivers/mfd/ab8500-sysctrl.c +0 -0
@@ -6,6 +6,7 @@

[...]

Quoted 9 lines
drivers/mfd/ab8500-sysctrl.c +2 -0
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
Quoted 6 lines

drivers/mfd/ab8500-sysctrl.c static void ab8500_power_off(void) · line 40

Quoted 4 lines
drivers/mfd/ab8500-sysctrl.c +0 -4
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}

Can you explain the purpose of this change please?

Quoted 6 lines

I guess it's because the sysctrl_dev is already initialised when registering the power_off handler, so there isn't a way to call the above function with a NULL sysctrl_dev. Probably even with the original code you didn't need this check (after some race fix in ab8500_sysctrl_remove but races is one of the things Guenter's patches try to address).

Quoted 3 lines

Sounds reasonable, although I think this change should be part of another patch.

Turns out the options are to either drop the check or to use the device managed function to register the poweroff handler. I decided to keep the check and use the device managed function.

Guenter

author maintainer
#139 lore raw

Re: [PATCH 12/44] mfd: ab8500-sysctrl: Register with kernel poweroff handler

In reply to Lee Jones
Quoted 33 lines · Lee Jones
Quoted 24 lines · Catalin Marinas
Quoted 16 lines · Lee Jones
Quoted 3 lines · Guenter Roeck
drivers/mfd/ab8500-sysctrl.c +0 -0
@@ -6,6 +6,7 @@

[...]

Quoted 9 lines
drivers/mfd/ab8500-sysctrl.c +2 -0
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
Quoted 6 lines

drivers/mfd/ab8500-sysctrl.c static void ab8500_power_off(void) · line 40

Quoted 4 lines
drivers/mfd/ab8500-sysctrl.c +0 -4
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}

Can you explain the purpose of this change please?

Quoted 6 lines

I guess it's because the sysctrl_dev is already initialised when registering the power_off handler, so there isn't a way to call the above function with a NULL sysctrl_dev. Probably even with the original code you didn't need this check (after some race fix in ab8500_sysctrl_remove but races is one of the things Guenter's patches try to address).

Quoted 3 lines

Sounds reasonable, although I think this change should be part of another patch.

Turns out the options are to either drop the check or to use the device managed function to register the poweroff handler. I decided to keep the check and use the device managed function.

Guenter

#140 lore raw

Re: [PATCH 12/44] mfd: ab8500-sysctrl: Register with kernel poweroff handler

In reply to Catalin Marinas
Quoted 24 lines · Catalin Marinas
Quoted 16 lines · Lee Jones
Quoted 3 lines · Guenter Roeck
drivers/mfd/ab8500-sysctrl.c +0 -0
@@ -6,6 +6,7 @@

[...]

Quoted 9 lines
drivers/mfd/ab8500-sysctrl.c +2 -0
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
Quoted 6 lines

drivers/mfd/ab8500-sysctrl.c static void ab8500_power_off(void) · line 40

Quoted 4 lines
drivers/mfd/ab8500-sysctrl.c +0 -4
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}

Can you explain the purpose of this change please?

Quoted 6 lines

I guess it's because the sysctrl_dev is already initialised when registering the power_off handler, so there isn't a way to call the above function with a NULL sysctrl_dev. Probably even with the original code you didn't need this check (after some race fix in ab8500_sysctrl_remove but races is one of the things Guenter's patches try to address).

Sounds reasonable, although I think this change should be part of another patch.

Signature · 9 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
maintainer
#141 lore raw

Re: [PATCH 12/44] mfd: ab8500-sysctrl: Register with kernel poweroff handler

In reply to Lee Jones
Quoted 16 lines · Lee Jones
Quoted 3 lines · Guenter Roeck
drivers/mfd/ab8500-sysctrl.c +0 -0
@@ -6,6 +6,7 @@

[...]

Quoted 9 lines
drivers/mfd/ab8500-sysctrl.c +2 -0
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
Quoted 6 lines

drivers/mfd/ab8500-sysctrl.c static void ab8500_power_off(void) · line 40

Quoted 4 lines
drivers/mfd/ab8500-sysctrl.c +0 -4
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}

Can you explain the purpose of this change please?

I guess it's because the sysctrl_dev is already initialised when registering the power_off handler, so there isn't a way to call the above function with a NULL sysctrl_dev. Probably even with the original code you didn't need this check (after some race fix in ab8500_sysctrl_remove but races is one of the things Guenter's patches try to address).

Signature · 1 line
Catalin
#142 lore raw

Re: [PATCH 12/44] mfd: ab8500-sysctrl: Register with kernel poweroff handler

In reply to Guenter Roeck
Quoted 17 lines · Guenter Roeck

Register with kernel poweroff 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 Linus Walleij <[email protected]>
Cc Lee Jones <[email protected]>
Cc Samuel Ortiz <[email protected]>
---
 drivers/mfd/ab8500-sysctrl.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/mfd/ab8500-sysctrl.c +0 -0
index 8e0dae5..677438f 100644
@@ -6,6 +6,7 @@

[...]

drivers/mfd/ab8500-sysctrl.c static void ab8500_power_off(void) · line 40

Quoted 13 lines
drivers/mfd/ab8500-sysctrl.c +2 -4
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}

Can you explain the purpose of this change please?

Quoted 10 lines
drivers/mfd/ab8500-sysctrl.c +2 -0
 	/*
 	 * If we have a charger connected and we're powering off,
 	 * reboot into charge-only mode.
@@ -83,8 +80,15 @@ shutdown:
 					 AB8500_STW4500CTRL1_SWRESET4500N);
 		(void)sigprocmask(SIG_SETMASK, &old, NULL);
 	}
+
+	return NOTIFY_DONE;
 }
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#143 lore raw

Re: [PATCH 12/44] mfd: ab8500-sysctrl: Register with kernel poweroff handler

In reply to Guenter Roeck
Quoted 17 lines · Guenter Roeck

Register with kernel poweroff 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 Linus Walleij <[email protected]>
Cc Lee Jones <[email protected]>
Cc Samuel Ortiz <[email protected]>
---
 drivers/mfd/ab8500-sysctrl.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/mfd/ab8500-sysctrl.c +0 -0
index 8e0dae5..677438f 100644
@@ -6,6 +6,7 @@

[...]

drivers/mfd/ab8500-sysctrl.c static void ab8500_power_off(void) · line 40

Quoted 13 lines
drivers/mfd/ab8500-sysctrl.c +2 -4
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}

Can you explain the purpose of this change please?

Quoted 10 lines
drivers/mfd/ab8500-sysctrl.c +2 -0
 	/*
 	 * If we have a charger connected and we're powering off,
 	 * reboot into charge-only mode.
@@ -83,8 +80,15 @@ shutdown:
 					 AB8500_STW4500CTRL1_SWRESET4500N);
 		(void)sigprocmask(SIG_SETMASK, &old, NULL);
 	}
+
+	return NOTIFY_DONE;
 }
Signature · 9 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author maintainer
#144 lore raw

PATCH 12/44 mfd: ab8500-sysctrl: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Linus Walleij <[email protected]>
Cc Lee Jones <[email protected]>
Cc Samuel Ortiz <[email protected]>
---
 drivers/mfd/ab8500-sysctrl.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/mfd/ab8500-sysctrl.c +15 -11
index 8e0dae5..677438f 100644
@@ -6,6 +6,7 @@
 
 #include <linux/err.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
 #include <linux/reboot.h>
@@ -23,7 +24,8 @@
 
 static struct device *sysctrl_dev;
 
-static void ab8500_power_off(void)
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}
-
 	/*
 	 * If we have a charger connected and we're powering off,
 	 * reboot into charge-only mode.
@@ -83,8 +80,15 @@ shutdown:
 					 AB8500_STW4500CTRL1_SWRESET4500N);
 		(void)sigprocmask(SIG_SETMASK, &old, NULL);
 	}
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block ab8500_poweroff_nb = {
+	.notifier_call = ab8500_power_off,
+	.priority = 64,
+};
+
 /*
  * 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 +189,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 +198,9 @@ static int ab8500_sysctrl_probe(struct platform_device *pdev)
 
 	sysctrl_dev = &pdev->dev;
 
-	if (!pm_power_off)
-		pm_power_off = ab8500_power_off;
+	err = register_poweroff_handler(&ab8500_poweroff_nb);
+	if (err)
+		dev_err(&pdev->dev, "Failed to register poweroff handler\n");
 
 	pdata = plat->sysctrl;
 	if (pdata) {
@@ -226,11 +232,9 @@ static int ab8500_sysctrl_probe(struct platform_device *pdev)
 
 static int ab8500_sysctrl_remove(struct platform_device *pdev)
 {
+	unregister_poweroff_handler(&ab8500_poweroff_nb);
 	sysctrl_dev = NULL;
 
-	if (pm_power_off == ab8500_power_off)
-		pm_power_off = NULL;
-
 	return 0;
 }
 
Signature · 1 line
1.9.1
author maintainer
#145 lore raw

PATCH 12/44 mfd: ab8500-sysctrl: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Linus Walleij <[email protected]>
Cc Lee Jones <[email protected]>
Cc Samuel Ortiz <[email protected]>
---
 drivers/mfd/ab8500-sysctrl.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/mfd/ab8500-sysctrl.c +15 -11
index 8e0dae5..677438f 100644
@@ -6,6 +6,7 @@
 
 #include <linux/err.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
 #include <linux/reboot.h>
@@ -23,7 +24,8 @@
 
 static struct device *sysctrl_dev;
 
-static void ab8500_power_off(void)
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -34,11 +36,6 @@ static void ab8500_power_off(void)
 	struct power_supply *psy;
 	int ret;
 
-	if (sysctrl_dev == NULL) {
-		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
-	}
-
 	/*
 	 * If we have a charger connected and we're powering off,
 	 * reboot into charge-only mode.
@@ -83,8 +80,15 @@ shutdown:
 					 AB8500_STW4500CTRL1_SWRESET4500N);
 		(void)sigprocmask(SIG_SETMASK, &old, NULL);
 	}
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block ab8500_poweroff_nb = {
+	.notifier_call = ab8500_power_off,
+	.priority = 64,
+};
+
 /*
  * 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 +189,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 +198,9 @@ static int ab8500_sysctrl_probe(struct platform_device *pdev)
 
 	sysctrl_dev = &pdev->dev;
 
-	if (!pm_power_off)
-		pm_power_off = ab8500_power_off;
+	err = register_poweroff_handler(&ab8500_poweroff_nb);
+	if (err)
+		dev_err(&pdev->dev, "Failed to register poweroff handler\n");
 
 	pdata = plat->sysctrl;
 	if (pdata) {
@@ -226,11 +232,9 @@ static int ab8500_sysctrl_probe(struct platform_device *pdev)
 
 static int ab8500_sysctrl_remove(struct platform_device *pdev)
 {
+	unregister_poweroff_handler(&ab8500_poweroff_nb);
 	sysctrl_dev = NULL;
 
-	if (pm_power_off == ab8500_power_off)
-		pm_power_off = NULL;
-
 	return 0;
 }
 
Signature · 1 line
1.9.1
author maintainer
#146 lore raw

PATCH 13/44 mfd: max8907: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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.

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 <sameo-VuQAYsv1563Yd54FQh9/[email protected]>
---
 drivers/mfd/max8907.c       | 24 ++++++++++++++++++------
 include/linux/mfd/max8907.h |  2 ++
 2 files changed, 20 insertions(+), 6 deletions(-)
drivers/mfd/max8907.c +18 -6
index 232749c..b8cddc1 100644
@@ -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,11 +178,16 @@ 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 int max8907_power_off(struct notifier_block *this, unsigned long unused1,
+			     void *unused2)
 {
-	regmap_update_bits(max8907_pm_off->regmap_gen, MAX8907_REG_RESET_CNFG,
+	struct max8907 *max8907 = container_of(this, struct max8907,
+					       poweroff_nb);
+
+	regmap_update_bits(max8907->regmap_gen, MAX8907_REG_RESET_CNFG,
 			MAX8907_MASK_POWER_OFF, MAX8907_MASK_POWER_OFF);
+
+	return NOTIFY_DONE;
 }
 
 static int max8907_i2c_probe(struct i2c_client *i2c,
@@ -267,9 +273,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->poweroff_nb.notifier_call = max8907_power_off;
+		max8907->poweroff_nb.priority = 64;
+		ret = register_poweroff_handler(&max8907->poweroff_nb);
+		if (ret)
+			dev_err(&i2c->dev,
+				"Failed to register poweroff handler");
 	}
 
 	return 0;
@@ -293,6 +303,8 @@ static int max8907_i2c_remove(struct i2c_client *i2c)
 {
 	struct max8907 *max8907 = i2c_get_clientdata(i2c);
 
+	unregister_poweroff_handler(&max8907->poweroff_nb);
+
 	mfd_remove_devices(max8907->dev);
 
 	regmap_del_irq_chip(max8907->i2c_gen->irq, max8907->irqc_rtc);
include/linux/mfd/max8907.h +2 -0
index b06f7a6..016428e 100644
@@ -13,6 +13,7 @@
 #define __LINUX_MFD_MAX8907_H
 
 #include <linux/mutex.h>
+#include <linux/notifier.h>
 #include <linux/pm.h>
 
 #define MAX8907_GEN_I2C_ADDR		(0x78 >> 1)
@@ -247,6 +248,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 notifier_block		poweroff_nb;
 };
 
 #endif
Signature · 1 line
1.9.1
author maintainer
#147 lore raw

PATCH 13/44 mfd: max8907: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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.

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]>
---
 drivers/mfd/max8907.c       | 24 ++++++++++++++++++------
 include/linux/mfd/max8907.h |  2 ++
 2 files changed, 20 insertions(+), 6 deletions(-)
drivers/mfd/max8907.c +18 -6
index 232749c..b8cddc1 100644
@@ -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,11 +178,16 @@ 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 int max8907_power_off(struct notifier_block *this, unsigned long unused1,
+			     void *unused2)
 {
-	regmap_update_bits(max8907_pm_off->regmap_gen, MAX8907_REG_RESET_CNFG,
+	struct max8907 *max8907 = container_of(this, struct max8907,
+					       poweroff_nb);
+
+	regmap_update_bits(max8907->regmap_gen, MAX8907_REG_RESET_CNFG,
 			MAX8907_MASK_POWER_OFF, MAX8907_MASK_POWER_OFF);
+
+	return NOTIFY_DONE;
 }
 
 static int max8907_i2c_probe(struct i2c_client *i2c,
@@ -267,9 +273,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->poweroff_nb.notifier_call = max8907_power_off;
+		max8907->poweroff_nb.priority = 64;
+		ret = register_poweroff_handler(&max8907->poweroff_nb);
+		if (ret)
+			dev_err(&i2c->dev,
+				"Failed to register poweroff handler");
 	}
 
 	return 0;
@@ -293,6 +303,8 @@ static int max8907_i2c_remove(struct i2c_client *i2c)
 {
 	struct max8907 *max8907 = i2c_get_clientdata(i2c);
 
+	unregister_poweroff_handler(&max8907->poweroff_nb);
+
 	mfd_remove_devices(max8907->dev);
 
 	regmap_del_irq_chip(max8907->i2c_gen->irq, max8907->irqc_rtc);
include/linux/mfd/max8907.h +2 -0
index b06f7a6..016428e 100644
@@ -13,6 +13,7 @@
 #define __LINUX_MFD_MAX8907_H
 
 #include <linux/mutex.h>
+#include <linux/notifier.h>
 #include <linux/pm.h>
 
 #define MAX8907_GEN_I2C_ADDR		(0x78 >> 1)
@@ -247,6 +248,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 notifier_block		poweroff_nb;
 };
 
 #endif
Signature · 1 line
1.9.1
author maintainer
#148 lore raw

PATCH 13/44 mfd: max8907: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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.

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]>
---
 drivers/mfd/max8907.c       | 24 ++++++++++++++++++------
 include/linux/mfd/max8907.h |  2 ++
 2 files changed, 20 insertions(+), 6 deletions(-)
drivers/mfd/max8907.c +18 -6
index 232749c..b8cddc1 100644
@@ -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,11 +178,16 @@ 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 int max8907_power_off(struct notifier_block *this, unsigned long unused1,
+			     void *unused2)
 {
-	regmap_update_bits(max8907_pm_off->regmap_gen, MAX8907_REG_RESET_CNFG,
+	struct max8907 *max8907 = container_of(this, struct max8907,
+					       poweroff_nb);
+
+	regmap_update_bits(max8907->regmap_gen, MAX8907_REG_RESET_CNFG,
 			MAX8907_MASK_POWER_OFF, MAX8907_MASK_POWER_OFF);
+
+	return NOTIFY_DONE;
 }
 
 static int max8907_i2c_probe(struct i2c_client *i2c,
@@ -267,9 +273,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->poweroff_nb.notifier_call = max8907_power_off;
+		max8907->poweroff_nb.priority = 64;
+		ret = register_poweroff_handler(&max8907->poweroff_nb);
+		if (ret)
+			dev_err(&i2c->dev,
+				"Failed to register poweroff handler");
 	}
 
 	return 0;
@@ -293,6 +303,8 @@ static int max8907_i2c_remove(struct i2c_client *i2c)
 {
 	struct max8907 *max8907 = i2c_get_clientdata(i2c);
 
+	unregister_poweroff_handler(&max8907->poweroff_nb);
+
 	mfd_remove_devices(max8907->dev);
 
 	regmap_del_irq_chip(max8907->i2c_gen->irq, max8907->irqc_rtc);
include/linux/mfd/max8907.h +2 -0
index b06f7a6..016428e 100644
@@ -13,6 +13,7 @@
 #define __LINUX_MFD_MAX8907_H
 
 #include <linux/mutex.h>
+#include <linux/notifier.h>
 #include <linux/pm.h>
 
 #define MAX8907_GEN_I2C_ADDR		(0x78 >> 1)
@@ -247,6 +248,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 notifier_block		poweroff_nb;
 };
 
 #endif
Signature · 1 line
1.9.1
author maintainer
#149 lore raw

PATCH 14/44 mfd: tps80031: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/tps80031.c       | 30 ++++++++++++++++++------------
 include/linux/mfd/tps80031.h |  2 ++
 2 files changed, 20 insertions(+), 12 deletions(-)
drivers/mfd/tps80031.c +18 -12
index ed6c5b0..24625a6 100644
@@ -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,17 @@ int tps80031_ext_power_req_config(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(tps80031_ext_power_req_config);
 
-static void tps80031_power_off(void)
+static int tps80031_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
-	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,
+						 poweroff_nb);
+
+	dev_info(tps80031->dev, "switching off PMU\n");
+	tps80031_write(tps80031->dev, TPS80031_SLAVE_ID1,
+		       TPS80031_PHOENIX_DEV_ON, TPS80031_DEVOFF);
+
+	return NOTIFY_DONE;
 }
 
 static void tps80031_pupd_init(struct tps80031 *tps80031,
@@ -501,9 +506,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->poweroff_nb.notifier_call = tps80031_power_off;
+		tps80031->poweroff_nb.priority = 64;
+		ret = register_poweroff_handler(&tps80031->poweroff_nb);
+		if (ret)
+			dev_err(&client->dev,
+				"Failed to register poweroff handler\n");
 	}
 	return 0;
 
@@ -523,10 +532,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_poweroff_handler(&tps80031->poweroff_nb);
 
 	mfd_remove_devices(tps80031->dev);
 
include/linux/mfd/tps80031.h +2 -0
index 2c75c9c..49bc006 100644
@@ -24,6 +24,7 @@
 #define __LINUX_MFD_TPS80031_H
 
 #include <linux/device.h>
+#include <linux/notifier.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 notifier_block	poweroff_nb;
 };
 
 struct tps80031_pupd_init_data {
Signature · 1 line
1.9.1
author maintainer
#150 lore raw

PATCH 14/44 mfd: tps80031: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/tps80031.c       | 30 ++++++++++++++++++------------
 include/linux/mfd/tps80031.h |  2 ++
 2 files changed, 20 insertions(+), 12 deletions(-)
drivers/mfd/tps80031.c +18 -12
index ed6c5b0..24625a6 100644
@@ -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,17 @@ int tps80031_ext_power_req_config(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(tps80031_ext_power_req_config);
 
-static void tps80031_power_off(void)
+static int tps80031_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
-	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,
+						 poweroff_nb);
+
+	dev_info(tps80031->dev, "switching off PMU\n");
+	tps80031_write(tps80031->dev, TPS80031_SLAVE_ID1,
+		       TPS80031_PHOENIX_DEV_ON, TPS80031_DEVOFF);
+
+	return NOTIFY_DONE;
 }
 
 static void tps80031_pupd_init(struct tps80031 *tps80031,
@@ -501,9 +506,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->poweroff_nb.notifier_call = tps80031_power_off;
+		tps80031->poweroff_nb.priority = 64;
+		ret = register_poweroff_handler(&tps80031->poweroff_nb);
+		if (ret)
+			dev_err(&client->dev,
+				"Failed to register poweroff handler\n");
 	}
 	return 0;
 
@@ -523,10 +532,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_poweroff_handler(&tps80031->poweroff_nb);
 
 	mfd_remove_devices(tps80031->dev);
 
include/linux/mfd/tps80031.h +2 -0
index 2c75c9c..49bc006 100644
@@ -24,6 +24,7 @@
 #define __LINUX_MFD_TPS80031_H
 
 #include <linux/device.h>
+#include <linux/notifier.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 notifier_block	poweroff_nb;
 };
 
 struct tps80031_pupd_init_data {
Signature · 1 line
1.9.1
author maintainer
#151 lore raw

PATCH 14/44 mfd: tps80031: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/tps80031.c       | 30 ++++++++++++++++++------------
 include/linux/mfd/tps80031.h |  2 ++
 2 files changed, 20 insertions(+), 12 deletions(-)
drivers/mfd/tps80031.c +18 -12
index ed6c5b0..24625a6 100644
@@ -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,17 @@ int tps80031_ext_power_req_config(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(tps80031_ext_power_req_config);
 
-static void tps80031_power_off(void)
+static int tps80031_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
-	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,
+						 poweroff_nb);
+
+	dev_info(tps80031->dev, "switching off PMU\n");
+	tps80031_write(tps80031->dev, TPS80031_SLAVE_ID1,
+		       TPS80031_PHOENIX_DEV_ON, TPS80031_DEVOFF);
+
+	return NOTIFY_DONE;
 }
 
 static void tps80031_pupd_init(struct tps80031 *tps80031,
@@ -501,9 +506,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->poweroff_nb.notifier_call = tps80031_power_off;
+		tps80031->poweroff_nb.priority = 64;
+		ret = register_poweroff_handler(&tps80031->poweroff_nb);
+		if (ret)
+			dev_err(&client->dev,
+				"Failed to register poweroff handler\n");
 	}
 	return 0;
 
@@ -523,10 +532,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_poweroff_handler(&tps80031->poweroff_nb);
 
 	mfd_remove_devices(tps80031->dev);
 
include/linux/mfd/tps80031.h +2 -0
index 2c75c9c..49bc006 100644
@@ -24,6 +24,7 @@
 #define __LINUX_MFD_TPS80031_H
 
 #include <linux/device.h>
+#include <linux/notifier.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 notifier_block	poweroff_nb;
 };
 
 struct tps80031_pupd_init_data {
Signature · 1 line
1.9.1
author maintainer
#152 lore raw

PATCH 15/44 mfd: dm355evm_msp: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Samuel Ortiz <sameo-VuQAYsv1563Yd54FQh9/[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/dm355evm_msp.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/mfd/dm355evm_msp.c +15 -3
index 4c826f7..52a82f3 100644
@@ -14,6 +14,8 @@
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/err.h>
 #include <linux/gpio.h>
 #include <linux/leds.h>
@@ -352,14 +354,22 @@ static void dm355evm_command(unsigned command)
 				command, status);
 }
 
-static void dm355evm_power_off(void)
+static int dm355evm_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
 	dm355evm_command(MSP_COMMAND_POWEROFF);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block dm355evm_msp_poweroff_nb = {
+	.notifier_call = dm355evm_power_off,
+	.priority = 64,
+};
+
 static int dm355evm_msp_remove(struct i2c_client *client)
 {
-	pm_power_off = NULL;
+	unregister_poweroff_handler(&dm355evm_msp_poweroff_nb);
 	msp430 = NULL;
 	return 0;
 }
@@ -398,7 +408,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_poweroff_handler(&dm355evm_msp_poweroff_nb);
+	if (status)
+		dev_err(&client->dev, "Failed to register poweroff handler\n");
 
 	return 0;
 
Signature · 1 line
1.9.1
author maintainer
#153 lore raw

PATCH 15/44 mfd: dm355evm_msp: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/dm355evm_msp.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/mfd/dm355evm_msp.c +15 -3
index 4c826f7..52a82f3 100644
@@ -14,6 +14,8 @@
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/err.h>
 #include <linux/gpio.h>
 #include <linux/leds.h>
@@ -352,14 +354,22 @@ static void dm355evm_command(unsigned command)
 				command, status);
 }
 
-static void dm355evm_power_off(void)
+static int dm355evm_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
 	dm355evm_command(MSP_COMMAND_POWEROFF);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block dm355evm_msp_poweroff_nb = {
+	.notifier_call = dm355evm_power_off,
+	.priority = 64,
+};
+
 static int dm355evm_msp_remove(struct i2c_client *client)
 {
-	pm_power_off = NULL;
+	unregister_poweroff_handler(&dm355evm_msp_poweroff_nb);
 	msp430 = NULL;
 	return 0;
 }
@@ -398,7 +408,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_poweroff_handler(&dm355evm_msp_poweroff_nb);
+	if (status)
+		dev_err(&client->dev, "Failed to register poweroff handler\n");
 
 	return 0;
 
Signature · 1 line
1.9.1
author maintainer
#154 lore raw

PATCH 15/44 mfd: dm355evm_msp: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/dm355evm_msp.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/mfd/dm355evm_msp.c +15 -3
index 4c826f7..52a82f3 100644
@@ -14,6 +14,8 @@
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/err.h>
 #include <linux/gpio.h>
 #include <linux/leds.h>
@@ -352,14 +354,22 @@ static void dm355evm_command(unsigned command)
 				command, status);
 }
 
-static void dm355evm_power_off(void)
+static int dm355evm_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
 	dm355evm_command(MSP_COMMAND_POWEROFF);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block dm355evm_msp_poweroff_nb = {
+	.notifier_call = dm355evm_power_off,
+	.priority = 64,
+};
+
 static int dm355evm_msp_remove(struct i2c_client *client)
 {
-	pm_power_off = NULL;
+	unregister_poweroff_handler(&dm355evm_msp_poweroff_nb);
 	msp430 = NULL;
 	return 0;
 }
@@ -398,7 +408,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_poweroff_handler(&dm355evm_msp_poweroff_nb);
+	if (status)
+		dev_err(&client->dev, "Failed to register poweroff handler\n");
 
 	return 0;
 
Signature · 1 line
1.9.1
author maintainer
#155 lore raw

PATCH 16/44 mfd: tps6586x: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/tps6586x.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
drivers/mfd/tps6586x.c +23 -8
index 8e1dbc4..bc14509 100644
@@ -21,10 +21,12 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/notifier.h>
 #include <linux/slab.h>
 #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 +135,8 @@ struct tps6586x {
 	u32			irq_en;
 	u8			mask_reg[5];
 	struct irq_domain	*irq_domain;
+
+	struct notifier_block	poweroff_nb;
 };
 
 static inline struct tps6586x *dev_to_tps6586x(struct device *dev)
@@ -472,13 +476,18 @@ static const struct regmap_config tps6586x_regmap_config = {
 	.cache_type = REGCACHE_RBTREE,
 };
 
-static struct device *tps6586x_dev;
-static void tps6586x_power_off(void)
+static int tps6586x_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
-	if (tps6586x_clr_bits(tps6586x_dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT))
-		return;
+	struct tps6586x *tps6586x = container_of(this, struct tps6586x,
+						 poweroff_nb);
+
+	if (tps6586x_clr_bits(tps6586x->dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT))
+		return NOTIFY_DONE;
 
-	tps6586x_set_bits(tps6586x_dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT);
+	tps6586x_set_bits(tps6586x->dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT);
+
+	return NOTIFY_DONE;
 }
 
 static void tps6586x_print_version(struct i2c_client *client, int version)
@@ -575,9 +584,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->poweroff_nb.notifier_call = tps6586x_power_off;
+		tps6586x->poweroff_nb.priority = 64;
+		ret = register_poweroff_handler(&tps6586x->poweroff_nb);
+		if (ret)
+			dev_err(&client->dev,
+				"failed to register poweroff handler\n");
 	}
 
 	return 0;
@@ -594,6 +607,8 @@ static int tps6586x_i2c_remove(struct i2c_client *client)
 {
 	struct tps6586x *tps6586x = i2c_get_clientdata(client);
 
+	unregister_poweroff_handler(&tps6586x->poweroff_nb);
+
 	tps6586x_remove_subdevs(tps6586x);
 	mfd_remove_devices(tps6586x->dev);
 	if (client->irq)
Signature · 1 line
1.9.1
author maintainer
#156 lore raw

PATCH 16/44 mfd: tps6586x: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/tps6586x.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
drivers/mfd/tps6586x.c +23 -8
index 8e1dbc4..bc14509 100644
@@ -21,10 +21,12 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/notifier.h>
 #include <linux/slab.h>
 #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 +135,8 @@ struct tps6586x {
 	u32			irq_en;
 	u8			mask_reg[5];
 	struct irq_domain	*irq_domain;
+
+	struct notifier_block	poweroff_nb;
 };
 
 static inline struct tps6586x *dev_to_tps6586x(struct device *dev)
@@ -472,13 +476,18 @@ static const struct regmap_config tps6586x_regmap_config = {
 	.cache_type = REGCACHE_RBTREE,
 };
 
-static struct device *tps6586x_dev;
-static void tps6586x_power_off(void)
+static int tps6586x_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
-	if (tps6586x_clr_bits(tps6586x_dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT))
-		return;
+	struct tps6586x *tps6586x = container_of(this, struct tps6586x,
+						 poweroff_nb);
+
+	if (tps6586x_clr_bits(tps6586x->dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT))
+		return NOTIFY_DONE;
 
-	tps6586x_set_bits(tps6586x_dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT);
+	tps6586x_set_bits(tps6586x->dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT);
+
+	return NOTIFY_DONE;
 }
 
 static void tps6586x_print_version(struct i2c_client *client, int version)
@@ -575,9 +584,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->poweroff_nb.notifier_call = tps6586x_power_off;
+		tps6586x->poweroff_nb.priority = 64;
+		ret = register_poweroff_handler(&tps6586x->poweroff_nb);
+		if (ret)
+			dev_err(&client->dev,
+				"failed to register poweroff handler\n");
 	}
 
 	return 0;
@@ -594,6 +607,8 @@ static int tps6586x_i2c_remove(struct i2c_client *client)
 {
 	struct tps6586x *tps6586x = i2c_get_clientdata(client);
 
+	unregister_poweroff_handler(&tps6586x->poweroff_nb);
+
 	tps6586x_remove_subdevs(tps6586x);
 	mfd_remove_devices(tps6586x->dev);
 	if (client->irq)
Signature · 1 line
1.9.1
author maintainer
#157 lore raw

PATCH 16/44 mfd: tps6586x: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/tps6586x.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
drivers/mfd/tps6586x.c +23 -8
index 8e1dbc4..bc14509 100644
@@ -21,10 +21,12 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/notifier.h>
 #include <linux/slab.h>
 #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 +135,8 @@ struct tps6586x {
 	u32			irq_en;
 	u8			mask_reg[5];
 	struct irq_domain	*irq_domain;
+
+	struct notifier_block	poweroff_nb;
 };
 
 static inline struct tps6586x *dev_to_tps6586x(struct device *dev)
@@ -472,13 +476,18 @@ static const struct regmap_config tps6586x_regmap_config = {
 	.cache_type = REGCACHE_RBTREE,
 };
 
-static struct device *tps6586x_dev;
-static void tps6586x_power_off(void)
+static int tps6586x_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
-	if (tps6586x_clr_bits(tps6586x_dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT))
-		return;
+	struct tps6586x *tps6586x = container_of(this, struct tps6586x,
+						 poweroff_nb);
+
+	if (tps6586x_clr_bits(tps6586x->dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT))
+		return NOTIFY_DONE;
 
-	tps6586x_set_bits(tps6586x_dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT);
+	tps6586x_set_bits(tps6586x->dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT);
+
+	return NOTIFY_DONE;
 }
 
 static void tps6586x_print_version(struct i2c_client *client, int version)
@@ -575,9 +584,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->poweroff_nb.notifier_call = tps6586x_power_off;
+		tps6586x->poweroff_nb.priority = 64;
+		ret = register_poweroff_handler(&tps6586x->poweroff_nb);
+		if (ret)
+			dev_err(&client->dev,
+				"failed to register poweroff handler\n");
 	}
 
 	return 0;
@@ -594,6 +607,8 @@ static int tps6586x_i2c_remove(struct i2c_client *client)
 {
 	struct tps6586x *tps6586x = i2c_get_clientdata(client);
 
+	unregister_poweroff_handler(&tps6586x->poweroff_nb);
+
 	tps6586x_remove_subdevs(tps6586x);
 	mfd_remove_devices(tps6586x->dev);
 	if (client->irq)
Signature · 1 line
1.9.1
author maintainer
#158 lore raw

PATCH 17/44 mfd: tps65910: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/tps65910.c       | 27 ++++++++++++++++++---------
 include/linux/mfd/tps65910.h |  3 +++
 2 files changed, 21 insertions(+), 9 deletions(-)
drivers/mfd/tps65910.c +18 -9
index f243e75..0b114d3 100644
@@ -23,6 +23,8 @@
 #include <linux/irq.h>
 #include <linux/irqdomain.h>
 #include <linux/mfd/core.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/mfd/tps65910.h>
 #include <linux/of.h>
@@ -437,19 +439,20 @@ 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 int tps65910_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
-	struct tps65910 *tps65910;
-
-	tps65910 = dev_get_drvdata(&tps65910_i2c_client->dev);
+	struct tps65910 *tps65910 = container_of(this, struct tps65910,
+						 poweroff_nb);
 
 	if (tps65910_reg_set_bits(tps65910, TPS65910_DEVCTRL,
 			DEVCTRL_PWR_OFF_MASK) < 0)
-		return;
+		return NOTIFY_DONE;
 
 	tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
 			DEVCTRL_DEV_ON_MASK);
+
+	return NOTIFY_DONE;
 }
 
 static int tps65910_i2c_probe(struct i2c_client *i2c,
@@ -500,9 +503,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->poweroff_nb.notifier_call = tps65910_power_off;
+		tps65910->poweroff_nb.priority = 64;
+		ret = register_poweroff_handler(&tps65910->poweroff_nb);
+		if (ret)
+			dev_err(&i2c->dev,
+				"failed to register poweroff handler\n");
 	}
 
 	ret = mfd_add_devices(tps65910->dev, -1,
@@ -522,6 +529,8 @@ static int tps65910_i2c_remove(struct i2c_client *i2c)
 {
 	struct tps65910 *tps65910 = i2c_get_clientdata(i2c);
 
+	unregister_poweroff_handler(&tps65910->poweroff_nb);
+
 	tps65910_irq_exit(tps65910);
 	mfd_remove_devices(tps65910->dev);
 
include/linux/mfd/tps65910.h +3 -0
index 6483a6f..65cae2c 100644
@@ -905,6 +905,9 @@ struct tps65910 {
 	/* IRQ Handling */
 	int chip_irq;
 	struct regmap_irq_chip_data *irq_data;
+
+	/* Poweroff handling */
+	struct notifier_block poweroff_nb;
 };
 
 struct tps65910_platform_data {
Signature · 1 line
1.9.1
author maintainer
#159 lore raw

PATCH 17/44 mfd: tps65910: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/tps65910.c       | 27 ++++++++++++++++++---------
 include/linux/mfd/tps65910.h |  3 +++
 2 files changed, 21 insertions(+), 9 deletions(-)
drivers/mfd/tps65910.c +18 -9
index f243e75..0b114d3 100644
@@ -23,6 +23,8 @@
 #include <linux/irq.h>
 #include <linux/irqdomain.h>
 #include <linux/mfd/core.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/mfd/tps65910.h>
 #include <linux/of.h>
@@ -437,19 +439,20 @@ 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 int tps65910_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
-	struct tps65910 *tps65910;
-
-	tps65910 = dev_get_drvdata(&tps65910_i2c_client->dev);
+	struct tps65910 *tps65910 = container_of(this, struct tps65910,
+						 poweroff_nb);
 
 	if (tps65910_reg_set_bits(tps65910, TPS65910_DEVCTRL,
 			DEVCTRL_PWR_OFF_MASK) < 0)
-		return;
+		return NOTIFY_DONE;
 
 	tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
 			DEVCTRL_DEV_ON_MASK);
+
+	return NOTIFY_DONE;
 }
 
 static int tps65910_i2c_probe(struct i2c_client *i2c,
@@ -500,9 +503,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->poweroff_nb.notifier_call = tps65910_power_off;
+		tps65910->poweroff_nb.priority = 64;
+		ret = register_poweroff_handler(&tps65910->poweroff_nb);
+		if (ret)
+			dev_err(&i2c->dev,
+				"failed to register poweroff handler\n");
 	}
 
 	ret = mfd_add_devices(tps65910->dev, -1,
@@ -522,6 +529,8 @@ static int tps65910_i2c_remove(struct i2c_client *i2c)
 {
 	struct tps65910 *tps65910 = i2c_get_clientdata(i2c);
 
+	unregister_poweroff_handler(&tps65910->poweroff_nb);
+
 	tps65910_irq_exit(tps65910);
 	mfd_remove_devices(tps65910->dev);
 
include/linux/mfd/tps65910.h +3 -0
index 6483a6f..65cae2c 100644
@@ -905,6 +905,9 @@ struct tps65910 {
 	/* IRQ Handling */
 	int chip_irq;
 	struct regmap_irq_chip_data *irq_data;
+
+	/* Poweroff handling */
+	struct notifier_block poweroff_nb;
 };
 
 struct tps65910_platform_data {
Signature · 1 line
1.9.1
author maintainer
#160 lore raw

PATCH 17/44 mfd: tps65910: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/tps65910.c       | 27 ++++++++++++++++++---------
 include/linux/mfd/tps65910.h |  3 +++
 2 files changed, 21 insertions(+), 9 deletions(-)
drivers/mfd/tps65910.c +18 -9
index f243e75..0b114d3 100644
@@ -23,6 +23,8 @@
 #include <linux/irq.h>
 #include <linux/irqdomain.h>
 #include <linux/mfd/core.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/mfd/tps65910.h>
 #include <linux/of.h>
@@ -437,19 +439,20 @@ 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 int tps65910_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
-	struct tps65910 *tps65910;
-
-	tps65910 = dev_get_drvdata(&tps65910_i2c_client->dev);
+	struct tps65910 *tps65910 = container_of(this, struct tps65910,
+						 poweroff_nb);
 
 	if (tps65910_reg_set_bits(tps65910, TPS65910_DEVCTRL,
 			DEVCTRL_PWR_OFF_MASK) < 0)
-		return;
+		return NOTIFY_DONE;
 
 	tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
 			DEVCTRL_DEV_ON_MASK);
+
+	return NOTIFY_DONE;
 }
 
 static int tps65910_i2c_probe(struct i2c_client *i2c,
@@ -500,9 +503,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->poweroff_nb.notifier_call = tps65910_power_off;
+		tps65910->poweroff_nb.priority = 64;
+		ret = register_poweroff_handler(&tps65910->poweroff_nb);
+		if (ret)
+			dev_err(&i2c->dev,
+				"failed to register poweroff handler\n");
 	}
 
 	ret = mfd_add_devices(tps65910->dev, -1,
@@ -522,6 +529,8 @@ static int tps65910_i2c_remove(struct i2c_client *i2c)
 {
 	struct tps65910 *tps65910 = i2c_get_clientdata(i2c);
 
+	unregister_poweroff_handler(&tps65910->poweroff_nb);
+
 	tps65910_irq_exit(tps65910);
 	mfd_remove_devices(tps65910->dev);
 
include/linux/mfd/tps65910.h +3 -0
index 6483a6f..65cae2c 100644
@@ -905,6 +905,9 @@ struct tps65910 {
 	/* IRQ Handling */
 	int chip_irq;
 	struct regmap_irq_chip_data *irq_data;
+
+	/* Poweroff handling */
+	struct notifier_block poweroff_nb;
 };
 
 struct tps65910_platform_data {
Signature · 1 line
1.9.1
author maintainer
#161 lore raw

PATCH 18/44 mfd: twl4030-power: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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.

Make twl4030_power_off static as it is only called from the twl4030-power driver.

Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/twl4030-power.c | 25 +++++++++++++++++++++----
 include/linux/i2c/twl.h     |  1 -
 2 files changed, 21 insertions(+), 5 deletions(-)
drivers/mfd/twl4030-power.c +21 -4
index 4d3ff37..bd6b830 100644
@@ -25,9 +25,10 @@
  */
 
 #include <linux/module.h>
-#include <linux/pm.h>
+#include <linux/notifier.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 +612,8 @@ 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 int twl4030_power_off(struct notifier_block *this, unsigned long unused1,
+			     void *unused2)
 {
 	int err;
 
@@ -619,8 +621,15 @@ void twl4030_power_off(void)
 			       TWL4030_PM_MASTER_P1_SW_EVENTS);
 	if (err)
 		pr_err("TWL4030 Unable to power off\n");
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block twl4030_poweroff_nb = {
+	.notifier_call = twl4030_power_off,
+	.priority = 64,
+};
+
 static bool twl4030_power_use_poweroff(const struct twl4030_power_data *pdata,
 					struct device_node *node)
 {
@@ -836,7 +845,7 @@ 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)) {
 		/* 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);
@@ -853,7 +862,13 @@ static int twl4030_power_probe(struct platform_device *pdev)
 			}
 		}
 
-		pm_power_off = twl4030_power_off;
+		err = register_poweroff_handler(&twl4030_poweroff_nb);
+		if (err) {
+			dev_err(&pdev->dev,
+				"Failed to register poweroff handler\n");
+			/* Not a fatal error */
+			err = 0;
+		}
 	}
 
 relock:
@@ -869,6 +884,8 @@ relock:
 
 static int twl4030_power_remove(struct platform_device *pdev)
 {
+	unregister_poweroff_handler(&twl4030_poweroff_nb);
+
 	return 0;
 }
 
include/linux/i2c/twl.h +0 -1
index 8cfb50f..f8544f1 100644
@@ -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 */
Signature · 1 line
1.9.1
#162 lore raw

Re: [PATCH 18/44] mfd: twl4030-power: Register with kernel poweroff handler

Quoted 42 lines · Guenter Roeck

Register with kernel poweroff 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.

Make twl4030_power_off static as it is only called from the twl4030-power driver.

Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/twl4030-power.c | 25 +++++++++++++++++++++----
 include/linux/i2c/twl.h     |  1 -
 2 files changed, 21 insertions(+), 5 deletions(-)
drivers/mfd/twl4030-power.c +4 -2
index 4d3ff37..bd6b830 100644
@@ -25,9 +25,10 @@
  */
 
 #include <linux/module.h>
-#include <linux/pm.h>
+#include <linux/notifier.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 +612,8 @@ 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 int twl4030_power_off(struct notifier_block *this, unsigned long unused1,
+			     void *unused2)
 {
 	int err;
 

drivers/mfd/twl4030-power.c void twl4030_power_off(void) · line 630

Quoted 10 lines
drivers/mfd/twl4030-power.c +5 -0
@@ -619,8 +621,15 @@ void twl4030_power_off(void)
 			       TWL4030_PM_MASTER_P1_SW_EVENTS);
 	if (err)
 		pr_err("TWL4030 Unable to power off\n");
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block twl4030_poweroff_nb = {
+	.notifier_call = twl4030_power_off,
+	.priority = 64,

64 out of what? How is this calculated? Wouldn't it be better to define these?

Quoted 15 lines
drivers/mfd/twl4030-power.c +3 -1
+};
+
 static bool twl4030_power_use_poweroff(const struct twl4030_power_data *pdata,
 					struct device_node *node)
 {
@@ -836,7 +845,7 @@ 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)) {
 		/* 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);

drivers/mfd/twl4030-power.c static int twl4030_power_probe(struct platform_device *pdev) · line 868

Quoted 8 lines
drivers/mfd/twl4030-power.c +4 -1
@@ -853,7 +862,13 @@ static int twl4030_power_probe(struct platform_device *pdev)
 			}
 		}
 
-		pm_power_off = twl4030_power_off;
+		err = register_poweroff_handler(&twl4030_poweroff_nb);
+		if (err) {
+			dev_err(&pdev->dev,
+				"Failed to register poweroff handler\n");

If this is not fatal, you should issue a dev_warn() instead.

drivers/mfd/twl4030-power.c static int twl4030_power_probe(struct platform_device *pdev) · line 870

Quoted 2 lines
drivers/mfd/twl4030-power.c +2 -0
+			/* Not a fatal error */
+			err = 0;

How about using your own variable for this? Then you don't have to worry about resetting it.

drivers/mfd/twl4030-power.c relock: · line 887

Quoted 9 lines
drivers/mfd/twl4030-power.c +2 -0
+		}
 	}
 
 relock:
@@ -869,6 +884,8 @@ relock:
 
 static int twl4030_power_remove(struct platform_device *pdev)
 {
+	unregister_poweroff_handler(&twl4030_poweroff_nb);

Perhaps a naive question, but is there any way you can do this using devres (devm_* managed resources)?

Quoted 15 lines
drivers/mfd/twl4030-power.c +0 -0
 	return 0;
 }
 
include/linux/i2c/twl.h +0 -1
index 8cfb50f..f8544f1 100644
@@ -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 */
Signature · 8 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe linux-alpha" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#163 lore raw

Re: [PATCH 18/44] mfd: twl4030-power: Register with kernel poweroff handler

In reply to Guenter Roeck
Quoted 42 lines · Guenter Roeck

Register with kernel poweroff 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.

Make twl4030_power_off static as it is only called from the twl4030-power driver.

Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/twl4030-power.c | 25 +++++++++++++++++++++----
 include/linux/i2c/twl.h     |  1 -
 2 files changed, 21 insertions(+), 5 deletions(-)
drivers/mfd/twl4030-power.c +4 -2
index 4d3ff37..bd6b830 100644
@@ -25,9 +25,10 @@
  */
 
 #include <linux/module.h>
-#include <linux/pm.h>
+#include <linux/notifier.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 +612,8 @@ 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 int twl4030_power_off(struct notifier_block *this, unsigned long unused1,
+			     void *unused2)
 {
 	int err;
 

drivers/mfd/twl4030-power.c void twl4030_power_off(void) · line 630

Quoted 10 lines
drivers/mfd/twl4030-power.c +5 -0
@@ -619,8 +621,15 @@ void twl4030_power_off(void)
 			       TWL4030_PM_MASTER_P1_SW_EVENTS);
 	if (err)
 		pr_err("TWL4030 Unable to power off\n");
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block twl4030_poweroff_nb = {
+	.notifier_call = twl4030_power_off,
+	.priority = 64,

64 out of what? How is this calculated? Wouldn't it be better to define these?

Quoted 15 lines
drivers/mfd/twl4030-power.c +3 -1
+};
+
 static bool twl4030_power_use_poweroff(const struct twl4030_power_data *pdata,
 					struct device_node *node)
 {
@@ -836,7 +845,7 @@ 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)) {
 		/* 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);

drivers/mfd/twl4030-power.c static int twl4030_power_probe(struct platform_device *pdev) · line 868

Quoted 8 lines
drivers/mfd/twl4030-power.c +4 -1
@@ -853,7 +862,13 @@ static int twl4030_power_probe(struct platform_device *pdev)
 			}
 		}
 
-		pm_power_off = twl4030_power_off;
+		err = register_poweroff_handler(&twl4030_poweroff_nb);
+		if (err) {
+			dev_err(&pdev->dev,
+				"Failed to register poweroff handler\n");

If this is not fatal, you should issue a dev_warn() instead.

drivers/mfd/twl4030-power.c static int twl4030_power_probe(struct platform_device *pdev) · line 870

Quoted 2 lines
drivers/mfd/twl4030-power.c +2 -0
+			/* Not a fatal error */
+			err = 0;

How about using your own variable for this? Then you don't have to worry about resetting it.

drivers/mfd/twl4030-power.c relock: · line 887

Quoted 9 lines
drivers/mfd/twl4030-power.c +2 -0
+		}
 	}
 
 relock:
@@ -869,6 +884,8 @@ relock:
 
 static int twl4030_power_remove(struct platform_device *pdev)
 {
+	unregister_poweroff_handler(&twl4030_poweroff_nb);

Perhaps a naive question, but is there any way you can do this using devres (devm_* managed resources)?

Quoted 15 lines
drivers/mfd/twl4030-power.c +0 -0
 	return 0;
 }
 
include/linux/i2c/twl.h +0 -1
index 8cfb50f..f8544f1 100644
@@ -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 */
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#164 lore raw

Re: [PATCH 18/44] mfd: twl4030-power: Register with kernel poweroff handler

In reply to Guenter Roeck
Quoted 42 lines · Guenter Roeck

Register with kernel poweroff 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.

Make twl4030_power_off static as it is only called from the twl4030-power driver.

Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/twl4030-power.c | 25 +++++++++++++++++++++----
 include/linux/i2c/twl.h     |  1 -
 2 files changed, 21 insertions(+), 5 deletions(-)
drivers/mfd/twl4030-power.c +4 -2
index 4d3ff37..bd6b830 100644
@@ -25,9 +25,10 @@
  */
 
 #include <linux/module.h>
-#include <linux/pm.h>
+#include <linux/notifier.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 +612,8 @@ 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 int twl4030_power_off(struct notifier_block *this, unsigned long unused1,
+			     void *unused2)
 {
 	int err;
 

drivers/mfd/twl4030-power.c void twl4030_power_off(void) · line 630

Quoted 10 lines
drivers/mfd/twl4030-power.c +5 -0
@@ -619,8 +621,15 @@ void twl4030_power_off(void)
 			       TWL4030_PM_MASTER_P1_SW_EVENTS);
 	if (err)
 		pr_err("TWL4030 Unable to power off\n");
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block twl4030_poweroff_nb = {
+	.notifier_call = twl4030_power_off,
+	.priority = 64,

64 out of what? How is this calculated? Wouldn't it be better to define these?

Quoted 15 lines
drivers/mfd/twl4030-power.c +3 -1
+};
+
 static bool twl4030_power_use_poweroff(const struct twl4030_power_data *pdata,
 					struct device_node *node)
 {
@@ -836,7 +845,7 @@ 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)) {
 		/* 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);

drivers/mfd/twl4030-power.c static int twl4030_power_probe(struct platform_device *pdev) · line 868

Quoted 8 lines
drivers/mfd/twl4030-power.c +4 -1
@@ -853,7 +862,13 @@ static int twl4030_power_probe(struct platform_device *pdev)
 			}
 		}
 
-		pm_power_off = twl4030_power_off;
+		err = register_poweroff_handler(&twl4030_poweroff_nb);
+		if (err) {
+			dev_err(&pdev->dev,
+				"Failed to register poweroff handler\n");

If this is not fatal, you should issue a dev_warn() instead.

drivers/mfd/twl4030-power.c static int twl4030_power_probe(struct platform_device *pdev) · line 870

Quoted 2 lines
drivers/mfd/twl4030-power.c +2 -0
+			/* Not a fatal error */
+			err = 0;

How about using your own variable for this? Then you don't have to worry about resetting it.

drivers/mfd/twl4030-power.c relock: · line 887

Quoted 9 lines
drivers/mfd/twl4030-power.c +2 -0
+		}
 	}
 
 relock:
@@ -869,6 +884,8 @@ relock:
 
 static int twl4030_power_remove(struct platform_device *pdev)
 {
+	unregister_poweroff_handler(&twl4030_poweroff_nb);

Perhaps a naive question, but is there any way you can do this using devres (devm_* managed resources)?

Quoted 15 lines
drivers/mfd/twl4030-power.c +0 -0
 	return 0;
 }
 
include/linux/i2c/twl.h +0 -1
index 8cfb50f..f8544f1 100644
@@ -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 */
Signature · 9 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author maintainer
#165 lore raw

PATCH 18/44 mfd: twl4030-power: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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.

Make twl4030_power_off static as it is only called from the twl4030-power driver.

Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/twl4030-power.c | 25 +++++++++++++++++++++----
 include/linux/i2c/twl.h     |  1 -
 2 files changed, 21 insertions(+), 5 deletions(-)
drivers/mfd/twl4030-power.c +21 -4
index 4d3ff37..bd6b830 100644
@@ -25,9 +25,10 @@
  */
 
 #include <linux/module.h>
-#include <linux/pm.h>
+#include <linux/notifier.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 +612,8 @@ 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 int twl4030_power_off(struct notifier_block *this, unsigned long unused1,
+			     void *unused2)
 {
 	int err;
 
@@ -619,8 +621,15 @@ void twl4030_power_off(void)
 			       TWL4030_PM_MASTER_P1_SW_EVENTS);
 	if (err)
 		pr_err("TWL4030 Unable to power off\n");
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block twl4030_poweroff_nb = {
+	.notifier_call = twl4030_power_off,
+	.priority = 64,
+};
+
 static bool twl4030_power_use_poweroff(const struct twl4030_power_data *pdata,
 					struct device_node *node)
 {
@@ -836,7 +845,7 @@ 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)) {
 		/* 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);
@@ -853,7 +862,13 @@ static int twl4030_power_probe(struct platform_device *pdev)
 			}
 		}
 
-		pm_power_off = twl4030_power_off;
+		err = register_poweroff_handler(&twl4030_poweroff_nb);
+		if (err) {
+			dev_err(&pdev->dev,
+				"Failed to register poweroff handler\n");
+			/* Not a fatal error */
+			err = 0;
+		}
 	}
 
 relock:
@@ -869,6 +884,8 @@ relock:
 
 static int twl4030_power_remove(struct platform_device *pdev)
 {
+	unregister_poweroff_handler(&twl4030_poweroff_nb);
+
 	return 0;
 }
 
include/linux/i2c/twl.h +0 -1
index 8cfb50f..f8544f1 100644
@@ -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 */
Signature · 1 line
1.9.1
author maintainer
#166 lore raw

PATCH 18/44 mfd: twl4030-power: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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.

Make twl4030_power_off static as it is only called from the twl4030-power driver.

Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/twl4030-power.c | 25 +++++++++++++++++++++----
 include/linux/i2c/twl.h     |  1 -
 2 files changed, 21 insertions(+), 5 deletions(-)
drivers/mfd/twl4030-power.c +21 -4
index 4d3ff37..bd6b830 100644
@@ -25,9 +25,10 @@
  */
 
 #include <linux/module.h>
-#include <linux/pm.h>
+#include <linux/notifier.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 +612,8 @@ 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 int twl4030_power_off(struct notifier_block *this, unsigned long unused1,
+			     void *unused2)
 {
 	int err;
 
@@ -619,8 +621,15 @@ void twl4030_power_off(void)
 			       TWL4030_PM_MASTER_P1_SW_EVENTS);
 	if (err)
 		pr_err("TWL4030 Unable to power off\n");
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block twl4030_poweroff_nb = {
+	.notifier_call = twl4030_power_off,
+	.priority = 64,
+};
+
 static bool twl4030_power_use_poweroff(const struct twl4030_power_data *pdata,
 					struct device_node *node)
 {
@@ -836,7 +845,7 @@ 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)) {
 		/* 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);
@@ -853,7 +862,13 @@ static int twl4030_power_probe(struct platform_device *pdev)
 			}
 		}
 
-		pm_power_off = twl4030_power_off;
+		err = register_poweroff_handler(&twl4030_poweroff_nb);
+		if (err) {
+			dev_err(&pdev->dev,
+				"Failed to register poweroff handler\n");
+			/* Not a fatal error */
+			err = 0;
+		}
 	}
 
 relock:
@@ -869,6 +884,8 @@ relock:
 
 static int twl4030_power_remove(struct platform_device *pdev)
 {
+	unregister_poweroff_handler(&twl4030_poweroff_nb);
+
 	return 0;
 }
 
include/linux/i2c/twl.h +0 -1
index 8cfb50f..f8544f1 100644
@@ -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 */
Signature · 1 line
1.9.1
author maintainer
#167 lore raw

PATCH 19/44 ipmi: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with a high priority value of 192 to reflect that the original code overwrites pm_power_off unconditionally.

Register poweroff 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.

---
 drivers/char/ipmi/ipmi_poweroff.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)
drivers/char/ipmi/ipmi_poweroff.c +19 -11
index 9f2e3be..a942a41 100644
@@ -36,6 +36,7 @@
 #include <linux/proc_fs.h>
 #include <linux/string.h>
 #include <linux/completion.h>
+#include <linux/notifier.h>
 #include <linux/pm.h>
 #include <linux/kdev_t.h>
 #include <linux/ipmi.h>
@@ -63,9 +64,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 +542,20 @@ static struct poweroff_function poweroff_functions[] = {
 
 
 /* Called on a powerdown request. */
-static void ipmi_poweroff_function(void)
+static int ipmi_poweroff_function(struct notifier_block *this,
+				  unsigned long unused1, void *unused2)
 {
-	if (!ready)
-		return;
-
 	/* Use run-to-completion mode, since interrupts may be off. */
 	specific_poweroff_func(ipmi_user);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block ipmi_poweroff_nb = {
+	.notifier_call = ipmi_poweroff_function,
+	.priority = 192,
+};
+
 /* 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 +634,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_poweroff_handler(&ipmi_poweroff_nb);
+	if (rv)
+		pr_err(PFX "failed to register poweroff handler\n");
 }
 
 static void ipmi_po_smi_gone(int if_num)
@@ -644,9 +650,10 @@ static void ipmi_po_smi_gone(int if_num)
 	if (ipmi_ifnum != if_num)
 		return;
 
+	unregister_poweroff_handler(&ipmi_poweroff_nb);
+
 	ready = 0;
 	ipmi_destroy_user(ipmi_user);
-	pm_power_off = old_poweroff_func;
 }
 
 static struct ipmi_smi_watcher smi_watcher = {
@@ -732,12 +739,13 @@ static void __exit ipmi_poweroff_cleanup(void)
 
 	ipmi_smi_watcher_unregister(&smi_watcher);
 
+	unregister_poweroff_handler(&ipmi_poweroff_nb);
+
 	if (ready) {
 		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);
Signature · 1 line
1.9.1
author maintainer
#168 lore raw

PATCH 19/44 ipmi: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with a high priority value of 192 to reflect that the original code overwrites pm_power_off unconditionally.

Register poweroff 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.

---
 drivers/char/ipmi/ipmi_poweroff.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)
drivers/char/ipmi/ipmi_poweroff.c +19 -11
index 9f2e3be..a942a41 100644
@@ -36,6 +36,7 @@
 #include <linux/proc_fs.h>
 #include <linux/string.h>
 #include <linux/completion.h>
+#include <linux/notifier.h>
 #include <linux/pm.h>
 #include <linux/kdev_t.h>
 #include <linux/ipmi.h>
@@ -63,9 +64,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 +542,20 @@ static struct poweroff_function poweroff_functions[] = {
 
 
 /* Called on a powerdown request. */
-static void ipmi_poweroff_function(void)
+static int ipmi_poweroff_function(struct notifier_block *this,
+				  unsigned long unused1, void *unused2)
 {
-	if (!ready)
-		return;
-
 	/* Use run-to-completion mode, since interrupts may be off. */
 	specific_poweroff_func(ipmi_user);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block ipmi_poweroff_nb = {
+	.notifier_call = ipmi_poweroff_function,
+	.priority = 192,
+};
+
 /* 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 +634,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_poweroff_handler(&ipmi_poweroff_nb);
+	if (rv)
+		pr_err(PFX "failed to register poweroff handler\n");
 }
 
 static void ipmi_po_smi_gone(int if_num)
@@ -644,9 +650,10 @@ static void ipmi_po_smi_gone(int if_num)
 	if (ipmi_ifnum != if_num)
 		return;
 
+	unregister_poweroff_handler(&ipmi_poweroff_nb);
+
 	ready = 0;
 	ipmi_destroy_user(ipmi_user);
-	pm_power_off = old_poweroff_func;
 }
 
 static struct ipmi_smi_watcher smi_watcher = {
@@ -732,12 +739,13 @@ static void __exit ipmi_poweroff_cleanup(void)
 
 	ipmi_smi_watcher_unregister(&smi_watcher);
 
+	unregister_poweroff_handler(&ipmi_poweroff_nb);
+
 	if (ready) {
 		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);
Signature · 1 line
1.9.1
author maintainer
#169 lore raw

PATCH 20/44 power/reset: restart-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

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 <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/restart-poweroff.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/power/reset/restart-poweroff.c +12 -13
index edd707e..5437697 100644
@@ -12,35 +12,34 @@
  */
 #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/pm.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_poweroff_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_poweroff_handler(&restart_poweroff_handler);
 
 	return 0;
 }
Signature · 1 line
1.9.1
maintainer Acked-by on v1 20/44
#170 lore raw

Re: [PATCH 20/44] power/reset: restart-poweroff: Register with kernel poweroff handler

Quoted 3 lines · Guenter Roeck

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.

I would not say last resort, this is how it is designed to work. There is no way to turn the power off from with linux, it is designed that u-boot will put the hardware into minimal power consumption until the "power" button is pressed.

Other than that,

Thanks
Andrew

Quoted 69 lines
Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/restart-poweroff.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/power/reset/restart-poweroff.c +12 -13
index edd707e..5437697 100644
@@ -12,35 +12,34 @@
  */
 #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/pm.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_poweroff_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_poweroff_handler(&restart_poweroff_handler);
 
 	return 0;
 }
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Acked-by on v1 20/44
#171 lore raw

Re: [PATCH 20/44] power/reset: restart-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck
Quoted 3 lines · Guenter Roeck

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.

I would not say last resort, this is how it is designed to work. There is no way to turn the power off from with linux, it is designed that u-boot will put the hardware into minimal power consumption until the "power" button is pressed.

Other than that,

Thanks
Andrew

Quoted 69 lines
Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/restart-poweroff.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/power/reset/restart-poweroff.c +12 -13
index edd707e..5437697 100644
@@ -12,35 +12,34 @@
  */
 #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/pm.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_poweroff_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_poweroff_handler(&restart_poweroff_handler);
 
 	return 0;
 }
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Acked-by on v1 20/44
#172 lore raw

Re: [PATCH 20/44] power/reset: restart-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck
Quoted 3 lines · Guenter Roeck

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.

I would not say last resort, this is how it is designed to work. There is no way to turn the power off from with linux, it is designed that u-boot will put the hardware into minimal power consumption until the "power" button is pressed.

Other than that,

Thanks
Andrew

Quoted 69 lines
Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/restart-poweroff.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/power/reset/restart-poweroff.c +12 -13
index edd707e..5437697 100644
@@ -12,35 +12,34 @@
  */
 #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/pm.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_poweroff_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_poweroff_handler(&restart_poweroff_handler);
 
 	return 0;
 }
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author maintainer
#173 lore raw

PATCH 20/44 power/reset: restart-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

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 <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/restart-poweroff.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/power/reset/restart-poweroff.c +12 -13
index edd707e..5437697 100644
@@ -12,35 +12,34 @@
  */
 #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/pm.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_poweroff_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_poweroff_handler(&restart_poweroff_handler);
 
 	return 0;
 }
Signature · 1 line
1.9.1
author maintainer
#174 lore raw

PATCH 20/44 power/reset: restart-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

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 <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/restart-poweroff.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/power/reset/restart-poweroff.c +12 -13
index edd707e..5437697 100644
@@ -12,35 +12,34 @@
  */
 #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/pm.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_poweroff_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_poweroff_handler(&restart_poweroff_handler);
 
 	return 0;
 }
Signature · 1 line
1.9.1
author maintainer
#175 lore raw

PATCH 21/44 power/reset: gpio-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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.

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 poweroff handler has already been registered. This is perfectly normal and acceptable.

Do not display a warning traceback if the poweroff handler fails to power off the system. There may be other poweroff handlers.

Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/gpio-poweroff.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/power/reset/gpio-poweroff.c +18 -18
index ce849bc..e95a7a1 100644
@@ -14,18 +14,18 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/notifier.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 int gpio_poweroff_do_poweroff(struct notifier_block *this,
+				     unsigned long unused1, void *unused2)
+
 {
 	BUG_ON(!reset_gpio);
 
@@ -42,20 +42,18 @@ static void gpio_poweroff_do_poweroff(void)
 	/* give it some time */
 	mdelay(3000);
 
-	WARN_ON(1);
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block gpio_poweroff_nb = {
+	.notifier_call = gpio_poweroff_do_poweroff,
+	.priority = 64,
+};
+
 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,14 +75,16 @@ static int gpio_poweroff_probe(struct platform_device *pdev)
 		}
 	}
 
-	pm_power_off = &gpio_poweroff_do_poweroff;
-	return 0;
+	err = register_poweroff_handler(&gpio_poweroff_nb);
+	if (err)
+		dev_err(&pdev->dev, "Failed to register poweroff handler\n");
+
+	return err;
 }
 
 static int gpio_poweroff_remove(struct platform_device *pdev)
 {
-	if (pm_power_off == &gpio_poweroff_do_poweroff)
-		pm_power_off = NULL;
+	unregister_poweroff_handler(&gpio_poweroff_nb);
 
 	return 0;
 }
Signature · 1 line
1.9.1
maintainer Acked-by on v1 21/44
#176 lore raw

Re: [PATCH 21/44] power/reset: gpio-poweroff: Register with kernel poweroff handler

Quoted 12 lines · Guenter Roeck

Register with kernel poweroff 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.

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.

Quoted 5 lines

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

Do not display a warning traceback if the poweroff handler fails to power off the system. There may be other poweroff handlers.

I would prefer to keep the warning traceback. We found on some hardware the GPIO transitions were too fast and it failed to power off. Seeing the traceback gives an idea where to go look for the problem.

Other than that,

Quoted 94 lines
Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/gpio-poweroff.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/power/reset/gpio-poweroff.c +18 -18
index ce849bc..e95a7a1 100644
@@ -14,18 +14,18 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/notifier.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 int gpio_poweroff_do_poweroff(struct notifier_block *this,
+				     unsigned long unused1, void *unused2)
+
 {
 	BUG_ON(!reset_gpio);
 
@@ -42,20 +42,18 @@ static void gpio_poweroff_do_poweroff(void)
 	/* give it some time */
 	mdelay(3000);
 
-	WARN_ON(1);
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block gpio_poweroff_nb = {
+	.notifier_call = gpio_poweroff_do_poweroff,
+	.priority = 64,
+};
+
 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,14 +75,16 @@ static int gpio_poweroff_probe(struct platform_device *pdev)
 		}
 	}
 
-	pm_power_off = &gpio_poweroff_do_poweroff;
-	return 0;
+	err = register_poweroff_handler(&gpio_poweroff_nb);
+	if (err)
+		dev_err(&pdev->dev, "Failed to register poweroff handler\n");
+
+	return err;
 }
 
 static int gpio_poweroff_remove(struct platform_device *pdev)
 {
-	if (pm_power_off == &gpio_poweroff_do_poweroff)
-		pm_power_off = NULL;
+	unregister_poweroff_handler(&gpio_poweroff_nb);
 
 	return 0;
 }
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Acked-by on v1 21/44
#177 lore raw

Re: [PATCH 21/44] power/reset: gpio-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck
Quoted 12 lines · Guenter Roeck

Register with kernel poweroff 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.

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.

Quoted 5 lines

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

Do not display a warning traceback if the poweroff handler fails to power off the system. There may be other poweroff handlers.

I would prefer to keep the warning traceback. We found on some hardware the GPIO transitions were too fast and it failed to power off. Seeing the traceback gives an idea where to go look for the problem.

Other than that,

Quoted 94 lines
Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/gpio-poweroff.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/power/reset/gpio-poweroff.c +18 -18
index ce849bc..e95a7a1 100644
@@ -14,18 +14,18 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/notifier.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 int gpio_poweroff_do_poweroff(struct notifier_block *this,
+				     unsigned long unused1, void *unused2)
+
 {
 	BUG_ON(!reset_gpio);
 
@@ -42,20 +42,18 @@ static void gpio_poweroff_do_poweroff(void)
 	/* give it some time */
 	mdelay(3000);
 
-	WARN_ON(1);
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block gpio_poweroff_nb = {
+	.notifier_call = gpio_poweroff_do_poweroff,
+	.priority = 64,
+};
+
 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,14 +75,16 @@ static int gpio_poweroff_probe(struct platform_device *pdev)
 		}
 	}
 
-	pm_power_off = &gpio_poweroff_do_poweroff;
-	return 0;
+	err = register_poweroff_handler(&gpio_poweroff_nb);
+	if (err)
+		dev_err(&pdev->dev, "Failed to register poweroff handler\n");
+
+	return err;
 }
 
 static int gpio_poweroff_remove(struct platform_device *pdev)
 {
-	if (pm_power_off == &gpio_poweroff_do_poweroff)
-		pm_power_off = NULL;
+	unregister_poweroff_handler(&gpio_poweroff_nb);
 
 	return 0;
 }
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Acked-by on v1 21/44
#178 lore raw

Re: [PATCH 21/44] power/reset: gpio-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck
Quoted 12 lines · Guenter Roeck

Register with kernel poweroff 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.

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.

Quoted 5 lines

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

Do not display a warning traceback if the poweroff handler fails to power off the system. There may be other poweroff handlers.

I would prefer to keep the warning traceback. We found on some hardware the GPIO transitions were too fast and it failed to power off. Seeing the traceback gives an idea where to go look for the problem.

Other than that,

Quoted 94 lines
Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/gpio-poweroff.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/power/reset/gpio-poweroff.c +18 -18
index ce849bc..e95a7a1 100644
@@ -14,18 +14,18 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/notifier.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 int gpio_poweroff_do_poweroff(struct notifier_block *this,
+				     unsigned long unused1, void *unused2)
+
 {
 	BUG_ON(!reset_gpio);
 
@@ -42,20 +42,18 @@ static void gpio_poweroff_do_poweroff(void)
 	/* give it some time */
 	mdelay(3000);
 
-	WARN_ON(1);
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block gpio_poweroff_nb = {
+	.notifier_call = gpio_poweroff_do_poweroff,
+	.priority = 64,
+};
+
 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,14 +75,16 @@ static int gpio_poweroff_probe(struct platform_device *pdev)
 		}
 	}
 
-	pm_power_off = &gpio_poweroff_do_poweroff;
-	return 0;
+	err = register_poweroff_handler(&gpio_poweroff_nb);
+	if (err)
+		dev_err(&pdev->dev, "Failed to register poweroff handler\n");
+
+	return err;
 }
 
 static int gpio_poweroff_remove(struct platform_device *pdev)
 {
-	if (pm_power_off == &gpio_poweroff_do_poweroff)
-		pm_power_off = NULL;
+	unregister_poweroff_handler(&gpio_poweroff_nb);
 
 	return 0;
 }
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author maintainer
#179 lore raw

PATCH 21/44 power/reset: gpio-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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.

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 poweroff handler has already been registered. This is perfectly normal and acceptable.

Do not display a warning traceback if the poweroff handler fails to power off the system. There may be other poweroff handlers.

Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/gpio-poweroff.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/power/reset/gpio-poweroff.c +18 -18
index ce849bc..e95a7a1 100644
@@ -14,18 +14,18 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/notifier.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 int gpio_poweroff_do_poweroff(struct notifier_block *this,
+				     unsigned long unused1, void *unused2)
+
 {
 	BUG_ON(!reset_gpio);
 
@@ -42,20 +42,18 @@ static void gpio_poweroff_do_poweroff(void)
 	/* give it some time */
 	mdelay(3000);
 
-	WARN_ON(1);
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block gpio_poweroff_nb = {
+	.notifier_call = gpio_poweroff_do_poweroff,
+	.priority = 64,
+};
+
 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,14 +75,16 @@ static int gpio_poweroff_probe(struct platform_device *pdev)
 		}
 	}
 
-	pm_power_off = &gpio_poweroff_do_poweroff;
-	return 0;
+	err = register_poweroff_handler(&gpio_poweroff_nb);
+	if (err)
+		dev_err(&pdev->dev, "Failed to register poweroff handler\n");
+
+	return err;
 }
 
 static int gpio_poweroff_remove(struct platform_device *pdev)
 {
-	if (pm_power_off == &gpio_poweroff_do_poweroff)
-		pm_power_off = NULL;
+	unregister_poweroff_handler(&gpio_poweroff_nb);
 
 	return 0;
 }
Signature · 1 line
1.9.1
author maintainer
#180 lore raw

PATCH 22/44 power/reset: as3722-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/as3722-poweroff.c | 36 ++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)
drivers/power/reset/as3722-poweroff.c +19 -17
index 6849711..7ebaed9 100644
@@ -17,32 +17,33 @@
 
 #include <linux/mfd/as3722.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #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 notifier_block poweroff_nb;
 };
 
-static struct as3722_poweroff *as3722_pm_poweroff;
-
-static void as3722_pm_power_off(void)
+static int as3722_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
+	struct as3722_poweroff *as3722_poweroff =
+		container_of(this, struct as3722_poweroff, poweroff_nb);
 	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);
+
+	return NOTIFY_DONE;
 }
 
 static int as3722_poweroff_probe(struct platform_device *pdev)
@@ -63,18 +64,19 @@ 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;
+	as3722_poweroff->poweroff_nb.notifier_call = as3722_power_off;
+	as3722_poweroff->poweroff_nb.priority = 64;
 
-	return 0;
+	platform_set_drvdata(pdev, as3722_poweroff);
+
+	return register_poweroff_handler(&as3722_poweroff->poweroff_nb);
 }
 
 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;
+	struct as3722_poweroff *as3722_poweroff = platform_get_drvdata(pdev);
+
+	unregister_poweroff_handler(&as3722_poweroff->poweroff_nb);
 
 	return 0;
 }
Signature · 1 line
1.9.1
author maintainer
#181 lore raw

PATCH 22/44 power/reset: as3722-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/as3722-poweroff.c | 36 ++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)
drivers/power/reset/as3722-poweroff.c +19 -17
index 6849711..7ebaed9 100644
@@ -17,32 +17,33 @@
 
 #include <linux/mfd/as3722.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #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 notifier_block poweroff_nb;
 };
 
-static struct as3722_poweroff *as3722_pm_poweroff;
-
-static void as3722_pm_power_off(void)
+static int as3722_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
+	struct as3722_poweroff *as3722_poweroff =
+		container_of(this, struct as3722_poweroff, poweroff_nb);
 	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);
+
+	return NOTIFY_DONE;
 }
 
 static int as3722_poweroff_probe(struct platform_device *pdev)
@@ -63,18 +64,19 @@ 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;
+	as3722_poweroff->poweroff_nb.notifier_call = as3722_power_off;
+	as3722_poweroff->poweroff_nb.priority = 64;
 
-	return 0;
+	platform_set_drvdata(pdev, as3722_poweroff);
+
+	return register_poweroff_handler(&as3722_poweroff->poweroff_nb);
 }
 
 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;
+	struct as3722_poweroff *as3722_poweroff = platform_get_drvdata(pdev);
+
+	unregister_poweroff_handler(&as3722_poweroff->poweroff_nb);
 
 	return 0;
 }
Signature · 1 line
1.9.1
author maintainer
#182 lore raw

PATCH 22/44 power/reset: as3722-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff 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 Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/as3722-poweroff.c | 36 ++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)
drivers/power/reset/as3722-poweroff.c +19 -17
index 6849711..7ebaed9 100644
@@ -17,32 +17,33 @@
 
 #include <linux/mfd/as3722.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #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 notifier_block poweroff_nb;
 };
 
-static struct as3722_poweroff *as3722_pm_poweroff;
-
-static void as3722_pm_power_off(void)
+static int as3722_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
+	struct as3722_poweroff *as3722_poweroff =
+		container_of(this, struct as3722_poweroff, poweroff_nb);
 	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);
+
+	return NOTIFY_DONE;
 }
 
 static int as3722_poweroff_probe(struct platform_device *pdev)
@@ -63,18 +64,19 @@ 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;
+	as3722_poweroff->poweroff_nb.notifier_call = as3722_power_off;
+	as3722_poweroff->poweroff_nb.priority = 64;
 
-	return 0;
+	platform_set_drvdata(pdev, as3722_poweroff);
+
+	return register_poweroff_handler(&as3722_poweroff->poweroff_nb);
 }
 
 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;
+	struct as3722_poweroff *as3722_poweroff = platform_get_drvdata(pdev);
+
+	unregister_poweroff_handler(&as3722_poweroff->poweroff_nb);
 
 	return 0;
 }
Signature · 1 line
1.9.1