Pascal Vizeli | eeac037 | 2020-06-18 16:40:37 +0200 | [diff] [blame] | 1 | // 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 Szyprowski | b3e9712 | 2020-12-18 15:26:45 +0100 | [diff] [blame] | 13 | #include <asm/arch/boot.h> |
Pascal Vizeli | eeac037 | 2020-06-18 16:40:37 +0200 | [diff] [blame] | 14 | #include <asm/arch/sm.h> |
| 15 | #include <asm/arch/eth.h> |
Pascal Vizeli | 0716854 | 2020-11-27 17:28:21 +0100 | [diff] [blame] | 16 | #include <asm/arch/boot.h> |
Pascal Vizeli | eeac037 | 2020-06-18 16:40:37 +0200 | [diff] [blame] | 17 | |
| 18 | #define EFUSE_MAC_OFFSET 20 |
| 19 | #define EFUSE_MAC_SIZE 12 |
| 20 | #define MAC_ADDR_LEN 6 |
| 21 | |
Marek Szyprowski | b3e9712 | 2020-12-18 15:26:45 +0100 | [diff] [blame] | 22 | int mmc_get_env_dev(void) |
| 23 | { |
| 24 | if (meson_get_boot_device() == BOOT_DEVICE_EMMC) |
| 25 | return 1; |
| 26 | return 0; |
| 27 | } |
| 28 | |
Pascal Vizeli | eeac037 | 2020-06-18 16:40:37 +0200 | [diff] [blame] | 29 | int 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 Vizeli | 0716854 | 2020-11-27 17:28:21 +0100 | [diff] [blame] | 35 | 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 Vizeli | eeac037 | 2020-06-18 16:40:37 +0200 | [diff] [blame] | 39 | 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 | } |