blob: 5f12d787d3835a644399b983cc87d881f78717d5 [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
6#include <common.h>
7#include <asm/arch/clock.h>
Marek Vasuteae88ad2023-12-16 06:42:29 +01008#include <asm/arch/ddr.h>
Marek Vasutf670cd72022-05-21 16:56:26 +02009#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 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
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020050 if (!dh_imx_get_mac_from_fuse(enetaddr))
51 goto out;
Marek Vasutf670cd72022-05-21 16:56:26 +020052
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020053 if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
54 goto out;
55
56 return -ENXIO;
57
58out:
59 return eth_env_set_enetaddr("ethaddr", enetaddr);
60}
61
62static 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 Vasutf670cd72022-05-21 16:56:26 +020074
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 Oberfichtnerd24f1de2022-07-26 15:04:52 +020080 if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
81 goto increment_out;
Marek Vasutf670cd72022-05-21 16:56:26 +020082
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020083 return -ENXIO;
Marek Vasutf670cd72022-05-21 16:56:26 +020084
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020085increment_out:
86 enetaddr[5]++;
87
88out:
89 return eth_env_set_enetaddr("eth1addr", enetaddr);
Marek Vasutf670cd72022-05-21 16:56:26 +020090}
91
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020092int dh_setup_mac_address(void)
Marek Vasutf670cd72022-05-21 16:56:26 +020093{
Marek Vasutf670cd72022-05-21 16:56:26 +020094 int ret;
95
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020096 ret = dh_imx8_setup_ethaddr();
97 if (ret)
98 printf("%s: Unable to setup ethaddr! ret = %d\n", __func__, ret);
Marek Vasutf670cd72022-05-21 16:56:26 +020099
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +0200100 ret = dh_imx8_setup_eth1addr();
101 if (ret)
102 printf("%s: Unable to setup eth1addr! ret = %d\n", __func__, ret);
Marek Vasutf670cd72022-05-21 16:56:26 +0200103
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +0200104 return ret;
Marek Vasutf670cd72022-05-21 16:56:26 +0200105}
106
107int board_init(void)
108{
Marek Vasutf670cd72022-05-21 16:56:26 +0200109 return 0;
110}
111
112int board_late_init(void)
113{
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +0200114 dh_setup_mac_address();
Marek Vasutf670cd72022-05-21 16:56:26 +0200115 return 0;
116}
117
118enum env_location env_get_location(enum env_operation op, int prio)
119{
120 return prio ? ENVL_UNKNOWN : ENVL_SPI_FLASH;
121}