^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2016, Fuzhou Rockchip Electronics Co., Ltd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kobject.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/reboot-mode.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define PREFIX "mode-"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct mode_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) const char *mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) u32 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static const char *boot_mode = "coldboot";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static ssize_t boot_mode_show(struct kobject *kobj, struct kobj_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return scnprintf(buf, PAGE_SIZE, "%s\n", boot_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static struct kobj_attribute kobj_boot_mode = __ATTR_RO(boot_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static int get_reboot_mode_magic(struct reboot_mode_driver *reboot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) const char *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) const char *normal = "normal";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int magic = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct mode_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (!cmd || !cmd[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) cmd = normal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) list_for_each_entry(info, &reboot->head, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (!strcmp(info->mode, cmd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) magic = info->magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static int last_magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static void reboot_mode_write(struct reboot_mode_driver *reboot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) const void *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) int magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) magic = get_reboot_mode_magic(reboot, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (!magic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) magic = get_reboot_mode_magic(reboot, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (magic) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) reboot->write(reboot, magic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) last_magic = magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static int reboot_mode_notify(struct notifier_block *this,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) unsigned long mode, void *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct reboot_mode_driver *reboot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) reboot = container_of(this, struct reboot_mode_driver, reboot_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) reboot_mode_write(reboot, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static int reboot_mode_pre_restart_notify(struct notifier_block *this,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) unsigned long mode, void *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct reboot_mode_driver *reboot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) reboot = container_of(this, struct reboot_mode_driver, pre_restart_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (cmd || !last_magic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) reboot_mode_write(reboot, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static int reboot_mode_panic_notify(struct notifier_block *this,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) unsigned long ev, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct reboot_mode_driver *reboot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) const char *cmd = "panic";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) reboot = container_of(this, struct reboot_mode_driver, panic_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) reboot_mode_write(reboot, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static int boot_mode_parse(struct reboot_mode_driver *reboot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct mode_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) unsigned int magic = reboot->read(reboot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) list_for_each_entry(info, &reboot->head, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (info->magic == magic) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) boot_mode = info->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * reboot_mode_register - register a reboot mode driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * @reboot: reboot mode driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * Returns: 0 on success or a negative error code on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int reboot_mode_register(struct reboot_mode_driver *reboot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct mode_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct property *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct device_node *np = reboot->dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) size_t len = strlen(PREFIX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) INIT_LIST_HEAD(&reboot->head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) for_each_property_of_node(np, prop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (strncmp(prop->name, PREFIX, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) info = devm_kzalloc(reboot->dev, sizeof(*info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (!info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (of_property_read_u32(np, prop->name, &info->magic)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) dev_err(reboot->dev, "reboot mode %s without magic number\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) info->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) devm_kfree(reboot->dev, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) info->mode = kstrdup_const(prop->name + len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (!info->mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) } else if (info->mode[0] == '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) kfree_const(info->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) dev_err(reboot->dev, "invalid mode name(%s): too short!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) prop->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) list_add_tail(&info->list, &reboot->head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) boot_mode_parse(reboot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) reboot->reboot_notifier.notifier_call = reboot_mode_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) reboot->pre_restart_notifier.notifier_call = reboot_mode_pre_restart_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) reboot->panic_notifier.notifier_call = reboot_mode_panic_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) register_reboot_notifier(&reboot->reboot_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) register_pre_restart_handler(&reboot->pre_restart_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) atomic_notifier_chain_register(&panic_notifier_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) &reboot->panic_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) ret = sysfs_create_file(kernel_kobj, &kobj_boot_mode.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) list_for_each_entry(info, &reboot->head, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) kfree_const(info->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) EXPORT_SYMBOL_GPL(reboot_mode_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * reboot_mode_unregister - unregister a reboot mode driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * @reboot: reboot mode driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) int reboot_mode_unregister(struct reboot_mode_driver *reboot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct mode_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) unregister_reboot_notifier(&reboot->reboot_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) list_for_each_entry(info, &reboot->head, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) kfree_const(info->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) EXPORT_SYMBOL_GPL(reboot_mode_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static void devm_reboot_mode_release(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) reboot_mode_unregister(*(struct reboot_mode_driver **)res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * devm_reboot_mode_register() - resource managed reboot_mode_register()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * @dev: device to associate this resource with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * @reboot: reboot mode driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * Returns: 0 on success or a negative error code on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) int devm_reboot_mode_register(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct reboot_mode_driver *reboot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct reboot_mode_driver **dr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) dr = devres_alloc(devm_reboot_mode_release, sizeof(*dr), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (!dr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) rc = reboot_mode_register(reboot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) devres_free(dr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) *dr = reboot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) devres_add(dev, dr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) EXPORT_SYMBOL_GPL(devm_reboot_mode_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static int devm_reboot_mode_match(struct device *dev, void *res, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct reboot_mode_driver **p = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (WARN_ON(!p || !*p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return *p == data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * devm_reboot_mode_unregister() - resource managed reboot_mode_unregister()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * @dev: device to associate this resource with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * @reboot: reboot mode driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) void devm_reboot_mode_unregister(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct reboot_mode_driver *reboot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) WARN_ON(devres_release(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) devm_reboot_mode_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) devm_reboot_mode_match, reboot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) EXPORT_SYMBOL_GPL(devm_reboot_mode_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) MODULE_AUTHOR("Andy Yan <andy.yan@rock-chips.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) MODULE_DESCRIPTION("System reboot mode core library");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) MODULE_LICENSE("GPL v2");