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