Skip to content

Commit

Permalink
Merge back reboot/poweroff notifiers rework for 5.19-rc1.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael J. Wysocki committed May 25, 2022
2 parents 09583df + 6779db9 commit 14c03a4
Show file tree
Hide file tree
Showing 27 changed files with 639 additions and 124 deletions.
4 changes: 1 addition & 3 deletions arch/arm/kernel/reboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ void machine_power_off(void)
{
local_irq_disable();
smp_send_stop();

if (pm_power_off)
pm_power_off();
do_kernel_power_off();
}

/*
Expand Down
3 changes: 1 addition & 2 deletions arch/arm64/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ void machine_power_off(void)
{
local_irq_disable();
smp_send_stop();
if (pm_power_off)
pm_power_off();
do_kernel_power_off();
}

/*
Expand Down
6 changes: 2 additions & 4 deletions arch/csky/kernel/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ EXPORT_SYMBOL(pm_power_off);
void machine_power_off(void)
{
local_irq_disable();
if (pm_power_off)
pm_power_off();
do_kernel_power_off();
asm volatile ("bkpt");
}

void machine_halt(void)
{
local_irq_disable();
if (pm_power_off)
pm_power_off();
do_kernel_power_off();
asm volatile ("bkpt");
}

Expand Down
4 changes: 2 additions & 2 deletions arch/ia64/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <linux/module.h>
#include <linux/notifier.h>
#include <linux/personality.h>
#include <linux/reboot.h>
#include <linux/sched.h>
#include <linux/sched/debug.h>
#include <linux/sched/hotplug.h>
Expand Down Expand Up @@ -599,8 +600,7 @@ machine_halt (void)
void
machine_power_off (void)
{
if (pm_power_off)
pm_power_off();
do_kernel_power_off();
machine_halt();
}

Expand Down
3 changes: 2 additions & 1 deletion arch/m68k/emu/natfeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/string.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/reboot.h>
#include <linux/io.h>
#include <asm/machdep.h>
#include <asm/natfeat.h>
Expand Down Expand Up @@ -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;
register_platform_power_off(nf_poweroff);
}
1 change: 0 additions & 1 deletion arch/m68k/include/asm/machdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ extern int (*mach_get_rtc_pll)(struct rtc_pll_info *);
extern int (*mach_set_rtc_pll)(struct rtc_pll_info *);
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 void (*mach_heartbeat) (int);
Expand Down
5 changes: 2 additions & 3 deletions arch/m68k/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ void machine_halt(void)

void machine_power_off(void)
{
if (mach_power_off)
mach_power_off();
do_kernel_power_off();
for (;;);
}

void (*pm_power_off)(void) = machine_power_off;
void (*pm_power_off)(void);
EXPORT_SYMBOL(pm_power_off);

void show_regs(struct pt_regs * regs)
Expand Down
1 change: 0 additions & 1 deletion arch/m68k/kernel/setup_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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 );
#ifdef CONFIG_HEARTBEAT
void (*mach_heartbeat) (int);
EXPORT_SYMBOL(mach_heartbeat);
Expand Down
1 change: 0 additions & 1 deletion arch/m68k/kernel/setup_no.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion arch/m68k/mac/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <linux/errno.h>
#include <linux/module.h>
#include <linux/reboot.h>
#include <linux/types.h>
#include <linux/mm.h>
#include <linux/tty.h>
Expand Down Expand Up @@ -140,7 +141,6 @@ void __init config_mac(void)
mach_hwclk = mac_hwclk;
mach_reset = mac_reset;
mach_halt = mac_poweroff;
mach_power_off = mac_poweroff;
#if IS_ENABLED(CONFIG_INPUT_M68K_BEEP)
mach_beep = mac_mksound;
#endif
Expand All @@ -160,6 +160,8 @@ void __init config_mac(void)

if (macintosh_config->ident == MAC_MODEL_IICI)
mach_l2_flush = via_l2_flush;

register_platform_power_off(mac_poweroff);
}


Expand Down
3 changes: 1 addition & 2 deletions arch/mips/kernel/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ void machine_halt(void)

void machine_power_off(void)
{
if (pm_power_off)
pm_power_off();
do_kernel_power_off();

#ifdef CONFIG_SMP
preempt_disable();
Expand Down
4 changes: 2 additions & 2 deletions arch/parisc/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <linux/module.h>
#include <linux/personality.h>
#include <linux/ptrace.h>
#include <linux/reboot.h>
#include <linux/sched.h>
#include <linux/sched/debug.h>
#include <linux/sched/task.h>
Expand Down Expand Up @@ -116,8 +117,7 @@ void machine_power_off(void)
pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);

/* ipmi_poweroff may have been installed. */
if (pm_power_off)
pm_power_off();
do_kernel_power_off();

/* It seems we have no way to power the system off via
* software. The user has to press the button himself. */
Expand Down
4 changes: 1 addition & 3 deletions arch/powerpc/kernel/setup-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ void machine_restart(char *cmd)
void machine_power_off(void)
{
machine_shutdown();
if (pm_power_off)
pm_power_off();

do_kernel_power_off();
smp_send_stop();
machine_hang();
}
Expand Down
3 changes: 1 addition & 2 deletions arch/powerpc/xmon/xmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,8 +1243,7 @@ static void bootcmds(void)
} else if (cmd == 'h') {
ppc_md.halt();
} else if (cmd == 'p') {
if (pm_power_off)
pm_power_off();
do_kernel_power_off();
}
}

Expand Down
12 changes: 4 additions & 8 deletions arch/riscv/kernel/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ void machine_restart(char *cmd)

void machine_halt(void)
{
if (pm_power_off != NULL)
pm_power_off();
else
default_power_off();
do_kernel_power_off();
default_power_off();
}

void machine_power_off(void)
{
if (pm_power_off != NULL)
pm_power_off();
else
default_power_off();
do_kernel_power_off();
default_power_off();
}
3 changes: 1 addition & 2 deletions arch/sh/kernel/reboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ static void native_machine_shutdown(void)

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

static void native_machine_halt(void)
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kernel/reboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,10 @@ static void native_machine_halt(void)

static void native_machine_power_off(void)
{
if (pm_power_off) {
if (kernel_can_power_off()) {
if (!reboot_force)
machine_shutdown();
pm_power_off();
do_kernel_power_off();
}
/* A fallback in case there is no PM info available */
tboot_shutdown(TB_SHUTDOWN_HALT);
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/xen/enlighten_pv.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <linux/pci.h>
#include <linux/gfp.h>
#include <linux/edd.h>
#include <linux/reboot.h>

#include <xen/xen.h>
#include <xen/events.h>
Expand Down Expand Up @@ -1069,8 +1070,7 @@ static void xen_machine_halt(void)

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

Expand Down
16 changes: 12 additions & 4 deletions drivers/acpi/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -1035,20 +1035,22 @@ static void acpi_sleep_hibernate_setup(void)
static inline void acpi_sleep_hibernate_setup(void) {}
#endif /* !CONFIG_HIBERNATION */

static void acpi_power_off_prepare(void)
static int acpi_power_off_prepare(struct sys_off_data *data)
{
/* Prepare to power off the system */
acpi_sleep_prepare(ACPI_STATE_S5);
acpi_disable_all_gpes();
acpi_os_wait_events_complete();
return NOTIFY_DONE;
}

static void acpi_power_off(void)
static int acpi_power_off(struct sys_off_data *data)
{
/* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
pr_debug("%s called\n", __func__);
local_irq_disable();
acpi_enter_sleep_state(ACPI_STATE_S5);
return NOTIFY_DONE;
}

int __init acpi_sleep_init(void)
Expand All @@ -1067,8 +1069,14 @@ int __init acpi_sleep_init(void)

if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
sleep_states[ACPI_STATE_S5] = 1;
pm_power_off_prepare = acpi_power_off_prepare;
pm_power_off = acpi_power_off;

register_sys_off_handler(SYS_OFF_MODE_POWER_OFF_PREPARE,
SYS_OFF_PRIO_FIRMWARE,
acpi_power_off_prepare, NULL);

register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
SYS_OFF_PRIO_FIRMWARE,
acpi_power_off, NULL);
} else {
acpi_no_s5 = true;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/memory/emif.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ 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 (kernel_can_power_off()) {
kernel_power_off();
} else {
WARN(1, "FIXME: NO pm_power_off!!! trying restart\n");
Expand Down
42 changes: 17 additions & 25 deletions drivers/regulator/pfuze100-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <linux/of_device.h>
#include <linux/regulator/of_regulator.h>
#include <linux/platform_device.h>
#include <linux/reboot.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
#include <linux/regulator/pfuze100.h>
Expand Down Expand Up @@ -571,10 +572,10 @@ static inline struct device_node *match_of_node(int index)
return pfuze_matches[index].of_node;
}

static struct pfuze_chip *syspm_pfuze_chip;

static void pfuze_power_off_prepare(void)
static int pfuze_power_off_prepare(struct sys_off_data *data)
{
struct pfuze_chip *syspm_pfuze_chip = data->cb_data;

dev_info(syspm_pfuze_chip->dev, "Configure standby mode for power off");

/* Switch from default mode: APS/APS to APS/Off */
Expand Down Expand Up @@ -609,28 +610,30 @@ static void pfuze_power_off_prepare(void)
regmap_update_bits(syspm_pfuze_chip->regmap, PFUZE100_VGEN6VOL,
PFUZE100_VGENxLPWR | PFUZE100_VGENxSTBY,
PFUZE100_VGENxSTBY);

return NOTIFY_DONE;
}

static int pfuze_power_off_prepare_init(struct pfuze_chip *pfuze_chip)
{
int err;

if (pfuze_chip->chip_id != PFUZE100) {
dev_warn(pfuze_chip->dev, "Requested pm_power_off_prepare handler for not supported chip\n");
return -ENODEV;
}

if (pm_power_off_prepare) {
dev_warn(pfuze_chip->dev, "pm_power_off_prepare is already registered.\n");
return -EBUSY;
err = devm_register_sys_off_handler(pfuze_chip->dev,
SYS_OFF_MODE_POWER_OFF_PREPARE,
SYS_OFF_PRIO_DEFAULT,
pfuze_power_off_prepare,
pfuze_chip);
if (err) {
dev_err(pfuze_chip->dev, "failed to register sys-off handler: %d\n",
err);
return err;
}

if (syspm_pfuze_chip) {
dev_warn(pfuze_chip->dev, "syspm_pfuze_chip is already set.\n");
return -EBUSY;
}

syspm_pfuze_chip = pfuze_chip;
pm_power_off_prepare = pfuze_power_off_prepare;

return 0;
}

Expand Down Expand Up @@ -839,23 +842,12 @@ static int pfuze100_regulator_probe(struct i2c_client *client,
return 0;
}

static int pfuze100_regulator_remove(struct i2c_client *client)
{
if (syspm_pfuze_chip) {
syspm_pfuze_chip = NULL;
pm_power_off_prepare = NULL;
}

return 0;
}

static struct i2c_driver pfuze_driver = {
.driver = {
.name = "pfuze100-regulator",
.of_match_table = pfuze_dt_ids,
},
.probe = pfuze100_regulator_probe,
.remove = pfuze100_regulator_remove,
};
module_i2c_driver(pfuze_driver);

Expand Down
Loading

0 comments on commit 14c03a4

Please sign in to comment.