power: reset: reboot-mode: Don't miss panic reboot mode
pre_restart will rewrite reboot mode with normal mode when panic.
Fixes: c0b196cd5b85 ("power: reset: reboot-mode: Register callback for kernel pre restart")
Signed-off-by: Tao Huang <huangtao@rock-chips.com>
Change-Id: I8ad03b8f699b9c1a544a46bbdb60d118381d8356
This commit is contained in:
@ -55,6 +55,8 @@ static int get_reboot_mode_magic(struct reboot_mode_driver *reboot,
|
|||||||
return magic;
|
return magic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int last_magic;
|
||||||
|
|
||||||
static void reboot_mode_write(struct reboot_mode_driver *reboot,
|
static void reboot_mode_write(struct reboot_mode_driver *reboot,
|
||||||
const void *cmd)
|
const void *cmd)
|
||||||
{
|
{
|
||||||
@ -63,8 +65,10 @@ static void reboot_mode_write(struct reboot_mode_driver *reboot,
|
|||||||
magic = get_reboot_mode_magic(reboot, cmd);
|
magic = get_reboot_mode_magic(reboot, cmd);
|
||||||
if (!magic)
|
if (!magic)
|
||||||
magic = get_reboot_mode_magic(reboot, NULL);
|
magic = get_reboot_mode_magic(reboot, NULL);
|
||||||
if (magic)
|
if (magic) {
|
||||||
reboot->write(reboot, magic);
|
reboot->write(reboot, magic);
|
||||||
|
last_magic = magic;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int reboot_mode_notify(struct notifier_block *this,
|
static int reboot_mode_notify(struct notifier_block *this,
|
||||||
@ -78,6 +82,18 @@ static int reboot_mode_notify(struct notifier_block *this,
|
|||||||
return NOTIFY_DONE;
|
return NOTIFY_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int reboot_mode_pre_restart_notify(struct notifier_block *this,
|
||||||
|
unsigned long mode, void *cmd)
|
||||||
|
{
|
||||||
|
struct reboot_mode_driver *reboot;
|
||||||
|
|
||||||
|
reboot = container_of(this, struct reboot_mode_driver, pre_restart_notifier);
|
||||||
|
if (cmd || !last_magic)
|
||||||
|
reboot_mode_write(reboot, cmd);
|
||||||
|
|
||||||
|
return NOTIFY_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
static int reboot_mode_panic_notify(struct notifier_block *this,
|
static int reboot_mode_panic_notify(struct notifier_block *this,
|
||||||
unsigned long ev, void *ptr)
|
unsigned long ev, void *ptr)
|
||||||
{
|
{
|
||||||
@ -155,9 +171,10 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
|
|||||||
|
|
||||||
boot_mode_parse(reboot);
|
boot_mode_parse(reboot);
|
||||||
reboot->reboot_notifier.notifier_call = reboot_mode_notify;
|
reboot->reboot_notifier.notifier_call = reboot_mode_notify;
|
||||||
|
reboot->pre_restart_notifier.notifier_call = reboot_mode_pre_restart_notify;
|
||||||
reboot->panic_notifier.notifier_call = reboot_mode_panic_notify;
|
reboot->panic_notifier.notifier_call = reboot_mode_panic_notify;
|
||||||
register_reboot_notifier(&reboot->reboot_notifier);
|
register_reboot_notifier(&reboot->reboot_notifier);
|
||||||
register_pre_restart_handler(&reboot->reboot_notifier);
|
register_pre_restart_handler(&reboot->pre_restart_notifier);
|
||||||
atomic_notifier_chain_register(&panic_notifier_list,
|
atomic_notifier_chain_register(&panic_notifier_list,
|
||||||
&reboot->panic_notifier);
|
&reboot->panic_notifier);
|
||||||
ret = sysfs_create_file(kernel_kobj, &kobj_boot_mode.attr);
|
ret = sysfs_create_file(kernel_kobj, &kobj_boot_mode.attr);
|
||||||
|
|||||||
@ -8,6 +8,7 @@ struct reboot_mode_driver {
|
|||||||
int (*write)(struct reboot_mode_driver *reboot, unsigned int magic);
|
int (*write)(struct reboot_mode_driver *reboot, unsigned int magic);
|
||||||
int (*read)(struct reboot_mode_driver *reboot);
|
int (*read)(struct reboot_mode_driver *reboot);
|
||||||
struct notifier_block reboot_notifier;
|
struct notifier_block reboot_notifier;
|
||||||
|
struct notifier_block pre_restart_notifier;
|
||||||
struct notifier_block panic_notifier;
|
struct notifier_block panic_notifier;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user