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> |
Marek Vasut | 891c5ef | 2024-09-25 00:08:23 +0200 | [diff] [blame] | 17 | #include <power/regulator.h> |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 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 | |
Marek Vasut | 29ab1a9 | 2024-03-12 22:15:58 +0100 | [diff] [blame] | 50 | if (dh_get_mac_is_enabled("ethernet0")) |
| 51 | return 0; |
| 52 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 53 | if (!dh_imx_get_mac_from_fuse(enetaddr)) |
| 54 | goto out; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 55 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 56 | if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0")) |
| 57 | goto out; |
| 58 | |
| 59 | return -ENXIO; |
| 60 | |
| 61 | out: |
| 62 | return eth_env_set_enetaddr("ethaddr", enetaddr); |
| 63 | } |
| 64 | |
| 65 | static int dh_imx8_setup_eth1addr(void) |
| 66 | { |
| 67 | unsigned char enetaddr[6]; |
| 68 | |
| 69 | if (dh_mac_is_in_env("eth1addr")) |
| 70 | return 0; |
| 71 | |
Marek Vasut | 29ab1a9 | 2024-03-12 22:15:58 +0100 | [diff] [blame] | 72 | if (dh_get_mac_is_enabled("ethernet1")) |
| 73 | return 0; |
| 74 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 75 | if (!dh_imx_get_mac_from_fuse(enetaddr)) |
| 76 | goto increment_out; |
| 77 | |
| 78 | if (!dh_get_mac_from_eeprom(enetaddr, "eeprom1")) |
| 79 | goto out; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * Populate second ethernet MAC from first ethernet EEPROM with MAC |
| 83 | * address LSByte incremented by 1. This is only used on SoMs without |
| 84 | * second ethernet EEPROM, i.e. early prototypes. |
| 85 | */ |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 86 | if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0")) |
| 87 | goto increment_out; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 88 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 89 | return -ENXIO; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 90 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 91 | increment_out: |
| 92 | enetaddr[5]++; |
| 93 | |
| 94 | out: |
| 95 | return eth_env_set_enetaddr("eth1addr", enetaddr); |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 96 | } |
| 97 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 98 | int dh_setup_mac_address(void) |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 99 | { |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 100 | int ret; |
| 101 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 102 | ret = dh_imx8_setup_ethaddr(); |
| 103 | if (ret) |
| 104 | printf("%s: Unable to setup ethaddr! ret = %d\n", __func__, ret); |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 105 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 106 | ret = dh_imx8_setup_eth1addr(); |
| 107 | if (ret) |
| 108 | printf("%s: Unable to setup eth1addr! ret = %d\n", __func__, ret); |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 109 | |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 110 | return ret; |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | int board_init(void) |
| 114 | { |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | int board_late_init(void) |
| 119 | { |
Philip Oberfichtner | d24f1de | 2022-07-26 15:04:52 +0200 | [diff] [blame] | 120 | dh_setup_mac_address(); |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | enum env_location env_get_location(enum env_operation op, int prio) |
| 125 | { |
| 126 | return prio ? ENVL_UNKNOWN : ENVL_SPI_FLASH; |
| 127 | } |