blob: caf7fd68100708b578483a45d38bb25bcc484b70 [file] [log] [blame]
Pascal Vizelieeac0372020-06-18 16:40:37 +02001// 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
16#define EFUSE_MAC_OFFSET 20
17#define EFUSE_MAC_SIZE 12
18#define MAC_ADDR_LEN 6
19
20int misc_init_r(void)
21{
22 u8 mac_addr[MAC_ADDR_LEN];
23 char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
24 ssize_t len;
25
26 meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
27
28 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
29 len = meson_sm_read_efuse(EFUSE_MAC_OFFSET,
30 efuse_mac_addr, EFUSE_MAC_SIZE);
31 if (len != EFUSE_MAC_SIZE)
32 return 0;
33
34 /* MAC is stored in ASCII format, 1bytes = 2characters */
35 for (int i = 0; i < 6; i++) {
36 tmp[0] = efuse_mac_addr[i * 2];
37 tmp[1] = efuse_mac_addr[i * 2 + 1];
38 tmp[2] = '\0';
39 mac_addr[i] = simple_strtoul(tmp, NULL, 16);
40 }
41
42 if (is_valid_ethaddr(mac_addr))
43 eth_env_set_enetaddr("ethaddr", mac_addr);
44 else
45 meson_generate_serial_ethaddr();
46 }
47
48 return 0;
49}