blob: 2b6d88ab1b94c9efdbf35e26ece9e9728955ae13 [file] [log] [blame]
Neil Armstrong4c2ea412017-10-12 15:50:32 +02001/*
2 * Copyright (C) 2016 BayLibre, SAS
3 * Author: Neil Armstrong <narmstrong@baylibre.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <dm.h>
10#include <asm/io.h>
11#include <asm/arch/gxbb.h>
Neil Armstrong24e2ca72017-10-18 10:02:12 +020012#include <asm/arch/sm.h>
Neil Armstrongeabf4362017-11-27 10:16:18 +010013#include <asm/arch/eth.h>
Neil Armstrong24e2ca72017-10-18 10:02:12 +020014
15#define EFUSE_SN_OFFSET 20
16#define EFUSE_SN_SIZE 16
17#define EFUSE_MAC_OFFSET 52
18#define EFUSE_MAC_SIZE 6
Neil Armstrong4c2ea412017-10-12 15:50:32 +020019
20int board_init(void)
21{
22 return 0;
23}
24
25int misc_init_r(void)
26{
Neil Armstrong24e2ca72017-10-18 10:02:12 +020027 u8 mac_addr[EFUSE_MAC_SIZE];
28 char serial[EFUSE_SN_SIZE];
29 ssize_t len;
30
Neil Armstrongeabf4362017-11-27 10:16:18 +010031 meson_gx_eth_init(PHY_INTERFACE_MODE_RMII, 0);
Neil Armstrong24e2ca72017-10-18 10:02:12 +020032
33 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
34 len = meson_sm_read_efuse(EFUSE_MAC_OFFSET,
35 mac_addr, EFUSE_MAC_SIZE);
36 if (len == EFUSE_MAC_SIZE && is_valid_ethaddr(mac_addr))
37 eth_env_set_enetaddr("ethaddr", mac_addr);
38 }
39
40 if (!env_get("serial#")) {
41 len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
42 EFUSE_SN_SIZE);
43 if (len == EFUSE_SN_SIZE)
44 env_set("serial#", serial);
45 }
46
47 return 0;
Neil Armstrong4c2ea412017-10-12 15:50:32 +020048}