blob: dc0d933a39e6f6cd98d13dd2bd9828dfe2f1d8a8 [file] [log] [blame]
Christian Hewittb3be2ee2020-12-18 08:45:42 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2020 BayLibre, SAS
4 * Author: Neil Armstrong <narmstrong@baylibre.com>
5 */
6
7#include <common.h>
8#include <dm.h>
9#include <env.h>
10#include <init.h>
11#include <net.h>
12#include <asm/io.h>
13#include <asm/arch/sm.h>
14#include <asm/arch/eth.h>
15#include <asm/arch/boot.h>
16
17#define EFUSE_MAC_OFFSET 20
18#define EFUSE_MAC_SIZE 12
19#define MAC_ADDR_LEN 6
20
21int misc_init_r(void)
22{
23 u8 mac_addr[MAC_ADDR_LEN];
24 char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
25 ssize_t len;
26
27 if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG) &&
28 meson_get_soc_rev(tmp, sizeof(tmp)) > 0)
29 env_set("soc_rev", tmp);
30
31 meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
32
33 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
34 len = meson_sm_read_efuse(EFUSE_MAC_OFFSET,
35 efuse_mac_addr, EFUSE_MAC_SIZE);
36 if (len != EFUSE_MAC_SIZE)
37 return 0;
38
39 /* MAC is stored in ASCII format, 1bytes = 2characters */
40 for (int i = 0; i < 6; i++) {
41 tmp[0] = efuse_mac_addr[i * 2];
42 tmp[1] = efuse_mac_addr[i * 2 + 1];
43 tmp[2] = '\0';
44 mac_addr[i] = simple_strtoul(tmp, NULL, 16);
45 }
46
47 if (is_valid_ethaddr(mac_addr))
48 eth_env_set_enetaddr("ethaddr", mac_addr);
49 else
50 meson_generate_serial_ethaddr();
51 }
52
53 return 0;
54}