xref: /openbmc/u-boot/board/amlogic/p212/p212.c (revision 93e72ac472b537bb4b0c6a97a7e6aab2b37860c6)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2cade865aSNeil Armstrong /*
3cade865aSNeil Armstrong  * Copyright (C) 2016 BayLibre, SAS
4cade865aSNeil Armstrong  * Author: Neil Armstrong <narmstrong@baylibre.com>
5cade865aSNeil Armstrong  */
6cade865aSNeil Armstrong 
7cade865aSNeil Armstrong #include <common.h>
8cade865aSNeil Armstrong #include <dm.h>
99925f1dbSAlex Kiernan #include <environment.h>
10cade865aSNeil Armstrong #include <asm/io.h>
11f0f3762cSNeil Armstrong #include <asm/arch/gx.h>
12ae0d82fcSNeil Armstrong #include <asm/arch/sm.h>
13f49638e9SNeil Armstrong #include <asm/arch/eth.h>
14c7be3e5aSNeil Armstrong #include <asm/arch/mem.h>
15ae0d82fcSNeil Armstrong 
16ae0d82fcSNeil Armstrong #define EFUSE_SN_OFFSET		20
17ae0d82fcSNeil Armstrong #define EFUSE_SN_SIZE		16
18ae0d82fcSNeil Armstrong #define EFUSE_MAC_OFFSET	52
19ae0d82fcSNeil Armstrong #define EFUSE_MAC_SIZE		6
20cade865aSNeil Armstrong 
misc_init_r(void)21cade865aSNeil Armstrong int misc_init_r(void)
22cade865aSNeil Armstrong {
23ae0d82fcSNeil Armstrong 	u8 mac_addr[EFUSE_MAC_SIZE];
24ae0d82fcSNeil Armstrong 	char serial[EFUSE_SN_SIZE];
25ae0d82fcSNeil Armstrong 	ssize_t len;
26ae0d82fcSNeil Armstrong 
27*33e33780SJerome Brunet 	meson_eth_init(PHY_INTERFACE_MODE_RMII,
28*33e33780SJerome Brunet 		       MESON_USE_INTERNAL_RMII_PHY);
29ae0d82fcSNeil Armstrong 
30ae0d82fcSNeil Armstrong 	if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
31ae0d82fcSNeil Armstrong 		len = meson_sm_read_efuse(EFUSE_MAC_OFFSET,
32ae0d82fcSNeil Armstrong 					  mac_addr, EFUSE_MAC_SIZE);
33ae0d82fcSNeil Armstrong 		if (len == EFUSE_MAC_SIZE && is_valid_ethaddr(mac_addr))
34ae0d82fcSNeil Armstrong 			eth_env_set_enetaddr("ethaddr", mac_addr);
35ae0d82fcSNeil Armstrong 	}
36ae0d82fcSNeil Armstrong 
37ae0d82fcSNeil Armstrong 	if (!env_get("serial#")) {
38ae0d82fcSNeil Armstrong 		len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
39ae0d82fcSNeil Armstrong 			EFUSE_SN_SIZE);
40ae0d82fcSNeil Armstrong 		if (len == EFUSE_SN_SIZE)
41ae0d82fcSNeil Armstrong 			env_set("serial#", serial);
42ae0d82fcSNeil Armstrong 	}
43ae0d82fcSNeil Armstrong 
44cade865aSNeil Armstrong 	return 0;
45cade865aSNeil Armstrong }
46