hc
2024-08-12 233ab1bd4c5697f5cdec94e60206e8c6ac609b4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * (C) Copyright 2019 Rockchip Electronics Co., Ltd
 *
 * SPDX-License-Identifier: GPL-2.0
 */
 
#include <common.h>
#include <dm.h>
#include <sysreset.h>
#include <linux/io.h>
#include <asm/arch/boot_mode.h>
 
#define CMD_PREFIX    "mode-"
 
struct command {
   const char *name;
   u32 magic;
};
 
static const struct command static_defined_command[] = {
   { .name = "bootrom", .magic = BOOT_BROM_DOWNLOAD, }
};
 
static int syscon_reboot_request_by_mode(struct udevice *dev, const char *mode)
{
   const char *prefix = CMD_PREFIX;
   char *command;
   u32 magic;
   int i;
 
   if (!mode)
       return 0;
 
   command = calloc(1, strlen(mode) + sizeof(prefix));
   if (!command)
       return -ENOMEM;
 
   strcat(command, prefix);
   strcat(command, mode);
 
   magic = dev_read_u32_default(dev, command, BOOT_NORMAL);
   if (magic == BOOT_NORMAL) {
       for (i = 0; i < ARRAY_SIZE(static_defined_command); i++) {
           if (!strcmp(static_defined_command[i].name, mode)) {
               magic = static_defined_command[i].magic;
               break;
           }
       }
   }
 
   printf("## Reboot mode: %s(%x)\n\n", mode, magic);
 
   writel(magic, CONFIG_ROCKCHIP_BOOT_MODE_REG);
   free(command);
 
   return 0;
}
 
static const struct sysreset_ops syscon_reboot_ops = {
   .request_by_mode = syscon_reboot_request_by_mode,
};
 
static const struct udevice_id syscon_reboot_match[] = {
   { .compatible = "syscon-reboot-mode", },
   {},
};
 
U_BOOT_DRIVER(sysreset_syscon_reboot) = {
   .name = "sysreset_syscon_reboot",
   .id = UCLASS_SYSRESET,
   .of_match = syscon_reboot_match,
   .ops = &syscon_reboot_ops,
};