]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/theobroma-systems/puma_rk3399/puma-rk3399.c
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
;
25 * We need to call into regulators_enable_boot_on() again, as the call
26 * during SPL may have not included all regulators.
28 ret
= regulators_enable_boot_on(false);
30 debug("%s: Cannot enable boot on regulator\n", __func__
);
35 void spl_board_init(void)
40 * Turning the eMMC and SPI back on (if disabled via the Qseven
41 * BIOS_ENABLE) signal is done through a always-on regulator).
43 ret
= regulators_enable_boot_on(false);
45 debug("%s: Cannot enable boot on regulator\n", __func__
);
47 preloader_console_init();
50 static void setup_macaddr(void)
52 #if CONFIG_IS_ENABLED(CMD_NET)
54 const char *cpuid
= env_get("cpuid#");
55 u8 hash
[SHA256_SUM_LEN
];
56 int size
= sizeof(hash
);
59 /* Only generate a MAC address, if none is set in the environment */
60 if (env_get("ethaddr"))
64 debug("%s: could not retrieve 'cpuid#'\n", __func__
);
68 ret
= hash_block("sha256", (void *)cpuid
, strlen(cpuid
), hash
, &size
);
70 debug("%s: failed to calculate SHA256\n", __func__
);
74 /* Copy 6 bytes of the hash to base the MAC address on */
75 memcpy(mac_addr
, hash
, 6);
77 /* Make this a valid MAC address and set it */
78 mac_addr
[0] &= 0xfe; /* clear multicast bit */
79 mac_addr
[0] |= 0x02; /* set local assignment bit (IEEE802) */
80 eth_env_set_enetaddr("ethaddr", mac_addr
);
84 static void setup_serial(void)
86 #if CONFIG_IS_ENABLED(ROCKCHIP_EFUSE)
87 const u32 cpuid_offset
= 0x7;
88 const u32 cpuid_length
= 0x10;
92 u8 cpuid
[cpuid_length
];
93 u8 low
[cpuid_length
/2], high
[cpuid_length
/2];
94 char cpuid_str
[cpuid_length
* 2 + 1];
96 char serialno_str
[17];
98 /* retrieve the device */
99 ret
= uclass_get_device_by_driver(UCLASS_MISC
,
100 DM_GET_DRIVER(rockchip_efuse
), &dev
);
102 debug("%s: could not find efuse device\n", __func__
);
106 /* read the cpu_id range from the efuses */
107 ret
= misc_read(dev
, cpuid_offset
, &cpuid
, sizeof(cpuid
));
109 debug("%s: reading cpuid from the efuses failed\n",
114 memset(cpuid_str
, 0, sizeof(cpuid_str
));
115 for (i
= 0; i
< 16; i
++)
116 sprintf(&cpuid_str
[i
* 2], "%02x", cpuid
[i
]);
118 debug("cpuid: %s\n", cpuid_str
);
121 * Mix the cpuid bytes using the same rules as in
122 * ${linux}/drivers/soc/rockchip/rockchip-cpuinfo.c
124 for (i
= 0; i
< 8; i
++) {
125 low
[i
] = cpuid
[1 + (i
<< 1)];
126 high
[i
] = cpuid
[i
<< 1];
129 serialno
= crc32_no_comp(0, low
, 8);
130 serialno
|= (u64
)crc32_no_comp(serialno
, high
, 8) << 32;
131 snprintf(serialno_str
, sizeof(serialno_str
), "%llx", serialno
);
133 env_set("cpuid#", cpuid_str
);
134 env_set("serial#", serialno_str
);
138 int misc_init_r(void)
146 #ifdef CONFIG_SERIAL_TAG
147 void get_board_serial(struct tag_serialnr
*serialnr
)
152 serial_string
= env_get("serial#");
155 serial
= simple_strtoull(serial_string
, NULL
, 16);
157 serialnr
->high
= (u32
)(serial
>> 32);
158 serialnr
->low
= (u32
)(serial
& 0xffffffff);