blob: c635735d89cb92d748014a39c974290ebd28d1b3 [file] [log] [blame]
Marek Vasutf670cd72022-05-21 16:56:26 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2022 Marek Vasut <marex@denx.de>
4 */
5
Marek Vasutf670cd72022-05-21 16:56:26 +02006#include <asm/arch/clock.h>
Marek Vasuteae88ad2023-12-16 06:42:29 +01007#include <asm/arch/ddr.h>
Marek Vasutf670cd72022-05-21 16:56:26 +02008#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 Oberfichtnerd24f1de2022-07-26 15:04:52 +020019#include "../common/dh_common.h"
20#include "../common/dh_imx.h"
Marek Vasutf670cd72022-05-21 16:56:26 +020021
22DECLARE_GLOBAL_DATA_PTR;
23
24int mach_cpu_init(void)
25{
26 icache_enable();
27 return 0;
28}
29
30int board_phys_sdram_size(phys_size_t *size)
31{
32 const u16 memsz[] = { 512, 1024, 1536, 2048, 3072, 4096, 6144, 8192 };
Marek Vasuteae88ad2023-12-16 06:42:29 +010033 const u8 ecc = readl(DDRC_ECCCFG0(0)) & DDRC_ECCCFG0_ECC_MODE_MASK;
Marek Vasutf670cd72022-05-21 16:56:26 +020034 u8 memcfg = dh_get_memcfg();
35
Marek Vasuteae88ad2023-12-16 06:42:29 +010036 /* 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 Vasutf670cd72022-05-21 16:56:26 +020038
39 return 0;
40}
41
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020042static int dh_imx8_setup_ethaddr(void)
Marek Vasutf670cd72022-05-21 16:56:26 +020043{
44 unsigned char enetaddr[6];
Marek Vasutf670cd72022-05-21 16:56:26 +020045
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020046 if (dh_mac_is_in_env("ethaddr"))
47 return 0;
Marek Vasutf670cd72022-05-21 16:56:26 +020048
Marek Vasut29ab1a92024-03-12 22:15:58 +010049 if (dh_get_mac_is_enabled("ethernet0"))
50 return 0;
51
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020052 if (!dh_imx_get_mac_from_fuse(enetaddr))
53 goto out;
Marek Vasutf670cd72022-05-21 16:56:26 +020054
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020055 if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
56 goto out;
57
58 return -ENXIO;
59
60out:
61 return eth_env_set_enetaddr("ethaddr", enetaddr);
62}
63
64static 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 Vasut29ab1a92024-03-12 22:15:58 +010071 if (dh_get_mac_is_enabled("ethernet1"))
72 return 0;
73
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020074 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 Vasutf670cd72022-05-21 16:56:26 +020079
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 Oberfichtnerd24f1de2022-07-26 15:04:52 +020085 if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
86 goto increment_out;
Marek Vasutf670cd72022-05-21 16:56:26 +020087
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020088 return -ENXIO;
Marek Vasutf670cd72022-05-21 16:56:26 +020089
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020090increment_out:
91 enetaddr[5]++;
92
93out:
94 return eth_env_set_enetaddr("eth1addr", enetaddr);
Marek Vasutf670cd72022-05-21 16:56:26 +020095}
96
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020097int dh_setup_mac_address(void)
Marek Vasutf670cd72022-05-21 16:56:26 +020098{
Marek Vasutf670cd72022-05-21 16:56:26 +020099 int ret;
100
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +0200101 ret = dh_imx8_setup_ethaddr();
102 if (ret)
103 printf("%s: Unable to setup ethaddr! ret = %d\n", __func__, ret);
Marek Vasutf670cd72022-05-21 16:56:26 +0200104
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +0200105 ret = dh_imx8_setup_eth1addr();
106 if (ret)
107 printf("%s: Unable to setup eth1addr! ret = %d\n", __func__, ret);
Marek Vasutf670cd72022-05-21 16:56:26 +0200108
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +0200109 return ret;
Marek Vasutf670cd72022-05-21 16:56:26 +0200110}
111
112int board_init(void)
113{
Marek Vasutf670cd72022-05-21 16:56:26 +0200114 return 0;
115}
116
117int board_late_init(void)
118{
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +0200119 dh_setup_mac_address();
Marek Vasutf670cd72022-05-21 16:56:26 +0200120 return 0;
121}
122
123enum env_location env_get_location(enum env_operation op, int prio)
124{
125 return prio ? ENVL_UNKNOWN : ENVL_SPI_FLASH;
126}