1302987b6SNeil Armstrong // SPDX-License-Identifier: GPL-2.0+
2302987b6SNeil Armstrong /*
3302987b6SNeil Armstrong * Copyright (C) 2016 BayLibre, SAS
4302987b6SNeil Armstrong * Author: Neil Armstrong <narmstrong@baylibre.com>
5302987b6SNeil Armstrong */
6302987b6SNeil Armstrong
7302987b6SNeil Armstrong #include <common.h>
8302987b6SNeil Armstrong #include <dm.h>
9302987b6SNeil Armstrong #include <environment.h>
10302987b6SNeil Armstrong #include <asm/io.h>
11302987b6SNeil Armstrong #include <asm/arch/gx.h>
12302987b6SNeil Armstrong #include <asm/arch/mem.h>
13302987b6SNeil Armstrong #include <asm/arch/sm.h>
14302987b6SNeil Armstrong #include <asm/arch/eth.h>
15302987b6SNeil Armstrong
16302987b6SNeil Armstrong #define EFUSE_SN_OFFSET 20
17302987b6SNeil Armstrong #define EFUSE_SN_SIZE 16
18302987b6SNeil Armstrong #define EFUSE_MAC_OFFSET 52
19302987b6SNeil Armstrong #define EFUSE_MAC_SIZE 6
20302987b6SNeil Armstrong
misc_init_r(void)21302987b6SNeil Armstrong int misc_init_r(void)
22302987b6SNeil Armstrong {
23302987b6SNeil Armstrong u8 mac_addr[EFUSE_MAC_SIZE];
24302987b6SNeil Armstrong char serial[EFUSE_SN_SIZE];
25302987b6SNeil Armstrong ssize_t len;
26302987b6SNeil Armstrong
27*33e33780SJerome Brunet meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
28302987b6SNeil Armstrong
29302987b6SNeil Armstrong /* Reset PHY on GPIOZ_14 */
30302987b6SNeil Armstrong clrbits_le32(GX_GPIO_EN(3), BIT(14));
31302987b6SNeil Armstrong clrbits_le32(GX_GPIO_OUT(3), BIT(14));
32302987b6SNeil Armstrong mdelay(10);
33302987b6SNeil Armstrong setbits_le32(GX_GPIO_OUT(3), BIT(14));
34302987b6SNeil Armstrong
35302987b6SNeil Armstrong if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
36302987b6SNeil Armstrong len = meson_sm_read_efuse(EFUSE_MAC_OFFSET,
37302987b6SNeil Armstrong mac_addr, EFUSE_MAC_SIZE);
38302987b6SNeil Armstrong if (len == EFUSE_MAC_SIZE && is_valid_ethaddr(mac_addr))
39302987b6SNeil Armstrong eth_env_set_enetaddr("ethaddr", mac_addr);
40302987b6SNeil Armstrong }
41302987b6SNeil Armstrong
42302987b6SNeil Armstrong if (!env_get("serial#")) {
43302987b6SNeil Armstrong len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
44302987b6SNeil Armstrong EFUSE_SN_SIZE);
45302987b6SNeil Armstrong if (len == EFUSE_SN_SIZE)
46302987b6SNeil Armstrong env_set("serial#", serial);
47302987b6SNeil Armstrong }
48302987b6SNeil Armstrong
49302987b6SNeil Armstrong return 0;
50302987b6SNeil Armstrong }
51