2 * (C) Copyright 2017 Theobroma Systems Design und Consulting GmbH
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <dm/pinctrl.h>
11 #include <dm/uclass-internal.h>
12 #include <asm/setup.h>
13 #include <asm/arch/periph.h>
14 #include <power/regulator.h>
16 #include <u-boot/sha256.h>
18 DECLARE_GLOBAL_DATA_PTR;
22 struct udevice *pinctrl, *regulator;
26 * The PWM does not have decicated interrupt number in dts and can
27 * not get periph_id by pinctrl framework, so let's init them here.
28 * The PWM2 and PWM3 are for pwm regulators.
30 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
32 debug("%s: Cannot find pinctrl device\n", __func__);
36 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM2);
38 debug("%s PWM2 pinctrl init fail!\n", __func__);
42 /* rk3399 need to init vdd_center to get the correct output voltage */
43 ret = regulator_get_by_platname("vdd_center", ®ulator);
45 debug("%s: Cannot get vdd_center regulator\n", __func__);
47 ret = regulator_get_by_platname("vcc5v0_host", ®ulator);
49 debug("%s vcc5v0_host init fail! ret %d\n", __func__, ret);
53 ret = regulator_set_enable(regulator, true);
55 debug("%s vcc5v0-host-en set fail!\n", __func__);
63 void spl_board_init(void)
65 preloader_console_init();
68 static void setup_macaddr(void)
70 #if CONFIG_IS_ENABLED(CMD_NET)
72 const char *cpuid = env_get("cpuid#");
73 u8 hash[SHA256_SUM_LEN];
74 int size = sizeof(hash);
77 /* Only generate a MAC address, if none is set in the environment */
78 if (env_get("ethaddr"))
82 debug("%s: could not retrieve 'cpuid#'\n", __func__);
86 ret = hash_block("sha256", (void *)cpuid, strlen(cpuid), hash, &size);
88 debug("%s: failed to calculate SHA256\n", __func__);
92 /* Copy 6 bytes of the hash to base the MAC address on */
93 memcpy(mac_addr, hash, 6);
95 /* Make this a valid MAC address and set it */
96 mac_addr[0] &= 0xfe; /* clear multicast bit */
97 mac_addr[0] |= 0x02; /* set local assignment bit (IEEE802) */
98 eth_env_set_enetaddr("ethaddr", mac_addr);
102 static void setup_serial(void)
104 #if CONFIG_IS_ENABLED(ROCKCHIP_EFUSE)
105 const u32 cpuid_offset = 0x7;
106 const u32 cpuid_length = 0x10;
110 u8 cpuid[cpuid_length];
111 u8 low[cpuid_length/2], high[cpuid_length/2];
112 char cpuid_str[cpuid_length * 2 + 1];
114 char serialno_str[17];
116 /* retrieve the device */
117 ret = uclass_get_device_by_driver(UCLASS_MISC,
118 DM_GET_DRIVER(rockchip_efuse), &dev);
120 debug("%s: could not find efuse device\n", __func__);
124 /* read the cpu_id range from the efuses */
125 ret = misc_read(dev, cpuid_offset, &cpuid, sizeof(cpuid));
127 debug("%s: reading cpuid from the efuses failed\n",
132 memset(cpuid_str, 0, sizeof(cpuid_str));
133 for (i = 0; i < 16; i++)
134 sprintf(&cpuid_str[i * 2], "%02x", cpuid[i]);
136 debug("cpuid: %s\n", cpuid_str);
139 * Mix the cpuid bytes using the same rules as in
140 * ${linux}/drivers/soc/rockchip/rockchip-cpuinfo.c
142 for (i = 0; i < 8; i++) {
143 low[i] = cpuid[1 + (i << 1)];
144 high[i] = cpuid[i << 1];
147 serialno = crc32_no_comp(0, low, 8);
148 serialno |= (u64)crc32_no_comp(serialno, high, 8) << 32;
149 snprintf(serialno_str, sizeof(serialno_str), "%llx", serialno);
151 env_set("cpuid#", cpuid_str);
152 env_set("serial#", serialno_str);
156 int misc_init_r(void)
164 #ifdef CONFIG_SERIAL_TAG
165 void get_board_serial(struct tag_serialnr *serialnr)
170 serial_string = env_get("serial#");
173 serial = simple_strtoull(serial_string, NULL, 16);
175 serialnr->high = (u32)(serial >> 32);
176 serialnr->low = (u32)(serial & 0xffffffff);