1
2
3
4
5
6#include <common.h>
7#include <dm.h>
8#include <env.h>
9#include <init.h>
10#include <log.h>
11#include <misc.h>
12#include <spl.h>
13#include <syscon.h>
14#include <u-boot/crc.h>
15#include <usb.h>
16#include <dm/pinctrl.h>
17#include <dm/uclass-internal.h>
18#include <asm/io.h>
19#include <asm/setup.h>
20#include <asm/arch-rockchip/clock.h>
21#include <asm/arch-rockchip/hardware.h>
22#include <asm/arch-rockchip/grf_rk3399.h>
23#include <asm/arch-rockchip/periph.h>
24#include <asm/arch-rockchip/misc.h>
25#include <power/regulator.h>
26#include <u-boot/sha256.h>
27
28static void setup_iodomain(void)
29{
30 const u32 GRF_IO_VSEL_GPIO4CD_SHIFT = 3;
31 struct rk3399_grf_regs *grf =
32 syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
33
34
35
36
37
38
39 rk_setreg(&grf->io_vsel, 1 << GRF_IO_VSEL_GPIO4CD_SHIFT);
40}
41
42
43
44
45
46
47
48
49
50
51static int setup_boottargets(void)
52{
53 const char *boot_device =
54 ofnode_read_chosen_string("u-boot,spl-boot-device");
55 char *env_default, *env;
56
57 if (!boot_device) {
58 debug("%s: /chosen/u-boot,spl-boot-device not set\n",
59 __func__);
60 return -1;
61 }
62 debug("%s: booted from %s\n", __func__, boot_device);
63
64 env_default = env_get_default("boot_targets");
65 env = env_get("boot_targets");
66 if (!env) {
67 debug("%s: boot_targets does not exist\n", __func__);
68 return -1;
69 }
70 debug("%s: boot_targets current: %s - default: %s\n",
71 __func__, env, env_default);
72
73 if (strcmp(env_default, env) != 0) {
74 debug("%s: boot_targets not default, don't change it\n",
75 __func__);
76 return 0;
77 }
78
79
80
81
82
83
84
85
86
87
88 if (!strcmp(boot_device, "/mmc@fe320000")) {
89 char *mmc0, *mmc1;
90
91 debug("%s: booted from SD-Card\n", __func__);
92 mmc0 = strstr(env, "mmc0");
93 mmc1 = strstr(env, "mmc1");
94
95 if (!mmc0 || !mmc1) {
96 debug("%s: only one mmc boot_target found\n", __func__);
97 return -1;
98 }
99
100
101
102
103
104 if (mmc0 < mmc1) {
105 mmc0[3] = '1';
106 mmc1[3] = '0';
107 debug("%s: set boot_targets to: %s\n", __func__, env);
108 env_set("boot_targets", env);
109 }
110 }
111
112 return 0;
113}
114
115int misc_init_r(void)
116{
117 const u32 cpuid_offset = 0x7;
118 const u32 cpuid_length = 0x10;
119 u8 cpuid[cpuid_length];
120 int ret;
121
122 ret = rockchip_cpuid_from_efuse(cpuid_offset, cpuid_length, cpuid);
123 if (ret)
124 return ret;
125
126 ret = rockchip_cpuid_set(cpuid, cpuid_length);
127 if (ret)
128 return ret;
129
130 ret = rockchip_setup_macaddr();
131 if (ret)
132 return ret;
133
134 setup_iodomain();
135 setup_boottargets();
136
137 return 0;
138}
139
140#ifdef CONFIG_SERIAL_TAG
141void get_board_serial(struct tag_serialnr *serialnr)
142{
143 char *serial_string;
144 u64 serial = 0;
145
146 serial_string = env_get("serial#");
147
148 if (serial_string)
149 serial = simple_strtoull(serial_string, NULL, 16);
150
151 serialnr->high = (u32)(serial >> 32);
152 serialnr->low = (u32)(serial & 0xffffffff);
153}
154#endif
155