blob: d9955433bf36d75b464b8481e9f3e62b357b47f0 [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>
Marek Szyprowskib3e97122020-12-18 15:26:45 +010013#include <asm/arch/boot.h>
Pascal Vizelieeac0372020-06-18 16:40:37 +020014#include <asm/arch/sm.h>
15#include <asm/arch/eth.h>
Pascal Vizeli07168542020-11-27 17:28:21 +010016#include <asm/arch/boot.h>
Pascal Vizelieeac0372020-06-18 16:40:37 +020017
18#define EFUSE_MAC_OFFSET 20
19#define EFUSE_MAC_SIZE 12
20#define MAC_ADDR_LEN 6
21
Marek Szyprowskib3e97122020-12-18 15:26:45 +010022int mmc_get_env_dev(void)
23{
24 if (meson_get_boot_device() == BOOT_DEVICE_EMMC)
25 return 1;
26 return 0;
27}
28
Pascal Vizelieeac0372020-06-18 16:40:37 +020029int misc_init_r(void)
30{
31 u8 mac_addr[MAC_ADDR_LEN];
32 char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
33 ssize_t len;
34
Pascal Vizeli07168542020-11-27 17:28:21 +010035 if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG) &&
36 meson_get_soc_rev(tmp, sizeof(tmp)) > 0)
37 env_set("soc_rev", tmp);
38
Pascal Vizelieeac0372020-06-18 16:40:37 +020039 meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
40
41 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
42 len = meson_sm_read_efuse(EFUSE_MAC_OFFSET,
43 efuse_mac_addr, EFUSE_MAC_SIZE);
44 if (len != EFUSE_MAC_SIZE)
45 return 0;
46
47 /* MAC is stored in ASCII format, 1bytes = 2characters */
48 for (int i = 0; i < 6; i++) {
49 tmp[0] = efuse_mac_addr[i * 2];
50 tmp[1] = efuse_mac_addr[i * 2 + 1];
51 tmp[2] = '\0';
52 mac_addr[i] = simple_strtoul(tmp, NULL, 16);
53 }
54
55 if (is_valid_ethaddr(mac_addr))
56 eth_env_set_enetaddr("ethaddr", mac_addr);
57 else
58 meson_generate_serial_ethaddr();
59 }
60
61 return 0;
62}