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 | |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 6 | #include <asm/arch/clock.h> |
Marek Vasut | eae88ad | 2023-12-16 06:42:29 +0100 | [diff] [blame] | 7 | #include <asm/arch/ddr.h> |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 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 }; |
Marek Vasut | eae88ad | 2023-12-16 06:42:29 +0100 | [diff] [blame] | 33 | const u8 ecc = readl(DDRC_ECCCFG0(0)) & DDRC_ECCCFG0_ECC_MODE_MASK; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 34 | u8 memcfg = dh_get_memcfg(); |
| 35 | |
Marek Vasut | eae88ad | 2023-12-16 06:42:29 +0100 | [diff] [blame] | 36 | /* 896 kiB, i.e. 1 MiB without 12.5% reserved for in-band ECC */ |
| 37 | *size = (u64)memsz[memcfg] * (SZ_1M - (ecc ? (SZ_1M / 8) : 0)); |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 42 | static int dh_imx8_setup_ethaddr(void) |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 43 | { |
| 44 | unsigned char enetaddr[6]; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 45 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 46 | if (dh_mac_is_in_env("ethaddr")) |
| 47 | return 0; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 48 | |
Marek Vasut | 29ab1a9 | 2024-03-12 22:15:58 +0100 | [diff] [blame] | 49 | if (dh_get_mac_is_enabled("ethernet0")) |
| 50 | return 0; |
| 51 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 52 | if (!dh_imx_get_mac_from_fuse(enetaddr)) |
| 53 | goto out; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 54 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 55 | if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0")) |
| 56 | goto out; |
| 57 | |
| 58 | return -ENXIO; |
| 59 | |
| 60 | out: |
| 61 | return eth_env_set_enetaddr("ethaddr", enetaddr); |
| 62 | } |
| 63 | |
| 64 | static int dh_imx8_setup_eth1addr(void) |
| 65 | { |
| 66 | unsigned char enetaddr[6]; |
| 67 | |
| 68 | if (dh_mac_is_in_env("eth1addr")) |
| 69 | return 0; |
| 70 | |
Marek Vasut | 29ab1a9 | 2024-03-12 22:15:58 +0100 | [diff] [blame] | 71 | if (dh_get_mac_is_enabled("ethernet1")) |
| 72 | return 0; |
| 73 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 74 | if (!dh_imx_get_mac_from_fuse(enetaddr)) |
| 75 | goto increment_out; |
| 76 | |
| 77 | if (!dh_get_mac_from_eeprom(enetaddr, "eeprom1")) |
| 78 | goto out; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * Populate second ethernet MAC from first ethernet EEPROM with MAC |
| 82 | * address LSByte incremented by 1. This is only used on SoMs without |
| 83 | * second ethernet EEPROM, i.e. early prototypes. |
| 84 | */ |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 85 | if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0")) |
| 86 | goto increment_out; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 87 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 88 | return -ENXIO; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 89 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 90 | increment_out: |
| 91 | enetaddr[5]++; |
| 92 | |
| 93 | out: |
| 94 | return eth_env_set_enetaddr("eth1addr", enetaddr); |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 95 | } |
| 96 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 97 | int dh_setup_mac_address(void) |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 98 | { |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 99 | int ret; |
| 100 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 101 | ret = dh_imx8_setup_ethaddr(); |
| 102 | if (ret) |
| 103 | printf("%s: Unable to setup ethaddr! ret = %d\n", __func__, ret); |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 104 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 105 | ret = dh_imx8_setup_eth1addr(); |
| 106 | if (ret) |
| 107 | printf("%s: Unable to setup eth1addr! ret = %d\n", __func__, ret); |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 108 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 109 | return ret; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | int board_init(void) |
| 113 | { |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | int board_late_init(void) |
| 118 | { |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 119 | dh_setup_mac_address(); |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | enum env_location env_get_location(enum env_operation op, int prio) |
| 124 | { |
| 125 | return prio ? ENVL_UNKNOWN : ENVL_SPI_FLASH; |
| 126 | } |