blob: 78aae412350153e134fe97f8c747d3d3563563e6 [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>
Marek Vasut891c5ef2024-09-25 00:08:23 +020017#include <power/regulator.h>
Marek Vasutf670cd72022-05-21 16:56:26 +020018
19#include "lpddr4_timing.h"
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020020#include "../common/dh_common.h"
21#include "../common/dh_imx.h"
Marek Vasutf670cd72022-05-21 16:56:26 +020022
23DECLARE_GLOBAL_DATA_PTR;
24
25int mach_cpu_init(void)
26{
27 icache_enable();
28 return 0;
29}
30
31int board_phys_sdram_size(phys_size_t *size)
32{
33 const u16 memsz[] = { 512, 1024, 1536, 2048, 3072, 4096, 6144, 8192 };
Marek Vasuteae88ad2023-12-16 06:42:29 +010034 const u8 ecc = readl(DDRC_ECCCFG0(0)) & DDRC_ECCCFG0_ECC_MODE_MASK;
Marek Vasutf670cd72022-05-21 16:56:26 +020035 u8 memcfg = dh_get_memcfg();
36
Marek Vasuteae88ad2023-12-16 06:42:29 +010037 /* 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 Vasutf670cd72022-05-21 16:56:26 +020039
40 return 0;
41}
42
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020043static int dh_imx8_setup_ethaddr(void)
Marek Vasutf670cd72022-05-21 16:56:26 +020044{
45 unsigned char enetaddr[6];
Marek Vasutf670cd72022-05-21 16:56:26 +020046
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020047 if (dh_mac_is_in_env("ethaddr"))
48 return 0;
Marek Vasutf670cd72022-05-21 16:56:26 +020049
Marek Vasut29ab1a92024-03-12 22:15:58 +010050 if (dh_get_mac_is_enabled("ethernet0"))
51 return 0;
52
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020053 if (!dh_imx_get_mac_from_fuse(enetaddr))
54 goto out;
Marek Vasutf670cd72022-05-21 16:56:26 +020055
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020056 if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
57 goto out;
58
59 return -ENXIO;
60
61out:
62 return eth_env_set_enetaddr("ethaddr", enetaddr);
63}
64
65static 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 Vasut29ab1a92024-03-12 22:15:58 +010072 if (dh_get_mac_is_enabled("ethernet1"))
73 return 0;
74
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020075 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 Vasutf670cd72022-05-21 16:56:26 +020080
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 Oberfichtnerd24f1de2022-07-26 15:04:52 +020086 if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
87 goto increment_out;
Marek Vasutf670cd72022-05-21 16:56:26 +020088
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020089 return -ENXIO;
Marek Vasutf670cd72022-05-21 16:56:26 +020090
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020091increment_out:
92 enetaddr[5]++;
93
94out:
95 return eth_env_set_enetaddr("eth1addr", enetaddr);
Marek Vasutf670cd72022-05-21 16:56:26 +020096}
97
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020098int dh_setup_mac_address(void)
Marek Vasutf670cd72022-05-21 16:56:26 +020099{
Marek Vasutf670cd72022-05-21 16:56:26 +0200100 int ret;
101
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +0200102 ret = dh_imx8_setup_ethaddr();
103 if (ret)
104 printf("%s: Unable to setup ethaddr! ret = %d\n", __func__, ret);
Marek Vasutf670cd72022-05-21 16:56:26 +0200105
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +0200106 ret = dh_imx8_setup_eth1addr();
107 if (ret)
108 printf("%s: Unable to setup eth1addr! ret = %d\n", __func__, ret);
Marek Vasutf670cd72022-05-21 16:56:26 +0200109
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +0200110 return ret;
Marek Vasutf670cd72022-05-21 16:56:26 +0200111}
112
113int board_init(void)
114{
Marek Vasutf670cd72022-05-21 16:56:26 +0200115 return 0;
116}
117
118int board_late_init(void)
119{
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +0200120 dh_setup_mac_address();
Marek Vasutf670cd72022-05-21 16:56:26 +0200121 return 0;
122}
123
124enum env_location env_get_location(enum env_operation op, int prio)
125{
126 return prio ? ENVL_UNKNOWN : ENVL_SPI_FLASH;
127}