Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2022 Marek Vasut <marex@denx.de> |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <asm/arch/clock.h> |
| 8 | #include <asm/arch/sys_proto.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <dm.h> |
| 11 | #include <env.h> |
| 12 | #include <env_internal.h> |
| 13 | #include <i2c_eeprom.h> |
| 14 | #include <malloc.h> |
| 15 | #include <net.h> |
| 16 | #include <miiphy.h> |
| 17 | |
| 18 | #include "lpddr4_timing.h" |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 19 | #include "../common/dh_common.h" |
| 20 | #include "../common/dh_imx.h" |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
| 24 | int mach_cpu_init(void) |
| 25 | { |
| 26 | icache_enable(); |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | int board_phys_sdram_size(phys_size_t *size) |
| 31 | { |
| 32 | const u16 memsz[] = { 512, 1024, 1536, 2048, 3072, 4096, 6144, 8192 }; |
| 33 | u8 memcfg = dh_get_memcfg(); |
| 34 | |
| 35 | *size = (u64)memsz[memcfg] << 20ULL; |
| 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 40 | static int dh_imx8_setup_ethaddr(void) |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 41 | { |
| 42 | unsigned char enetaddr[6]; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 43 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 44 | if (dh_mac_is_in_env("ethaddr")) |
| 45 | return 0; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 46 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 47 | if (!dh_imx_get_mac_from_fuse(enetaddr)) |
| 48 | goto out; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 49 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 50 | if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0")) |
| 51 | goto out; |
| 52 | |
| 53 | return -ENXIO; |
| 54 | |
| 55 | out: |
| 56 | return eth_env_set_enetaddr("ethaddr", enetaddr); |
| 57 | } |
| 58 | |
| 59 | static int dh_imx8_setup_eth1addr(void) |
| 60 | { |
| 61 | unsigned char enetaddr[6]; |
| 62 | |
| 63 | if (dh_mac_is_in_env("eth1addr")) |
| 64 | return 0; |
| 65 | |
| 66 | if (!dh_imx_get_mac_from_fuse(enetaddr)) |
| 67 | goto increment_out; |
| 68 | |
| 69 | if (!dh_get_mac_from_eeprom(enetaddr, "eeprom1")) |
| 70 | goto out; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | * Populate second ethernet MAC from first ethernet EEPROM with MAC |
| 74 | * address LSByte incremented by 1. This is only used on SoMs without |
| 75 | * second ethernet EEPROM, i.e. early prototypes. |
| 76 | */ |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 77 | if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0")) |
| 78 | goto increment_out; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 79 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 80 | return -ENXIO; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 81 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 82 | increment_out: |
| 83 | enetaddr[5]++; |
| 84 | |
| 85 | out: |
| 86 | return eth_env_set_enetaddr("eth1addr", enetaddr); |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 87 | } |
| 88 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 89 | int dh_setup_mac_address(void) |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 90 | { |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 91 | int ret; |
| 92 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 93 | ret = dh_imx8_setup_ethaddr(); |
| 94 | if (ret) |
| 95 | printf("%s: Unable to setup ethaddr! ret = %d\n", __func__, ret); |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 96 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 97 | ret = dh_imx8_setup_eth1addr(); |
| 98 | if (ret) |
| 99 | printf("%s: Unable to setup eth1addr! ret = %d\n", __func__, ret); |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 100 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 101 | return ret; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | int board_init(void) |
| 105 | { |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | int board_late_init(void) |
| 110 | { |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 111 | dh_setup_mac_address(); |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | enum env_location env_get_location(enum env_operation op, int prio) |
| 116 | { |
| 117 | return prio ? ENVL_UNKNOWN : ENVL_SPI_FLASH; |
| 118 | } |