blob: 5edb85e1de53376e5dedae54d4f16966f73d7418 [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>
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 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 };
33 u8 memcfg = dh_get_memcfg();
34
35 *size = (u64)memsz[memcfg] << 20ULL;
36
37 return 0;
38}
39
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020040static int dh_imx8_setup_ethaddr(void)
Marek Vasutf670cd72022-05-21 16:56:26 +020041{
42 unsigned char enetaddr[6];
Marek Vasutf670cd72022-05-21 16:56:26 +020043
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020044 if (dh_mac_is_in_env("ethaddr"))
45 return 0;
Marek Vasutf670cd72022-05-21 16:56:26 +020046
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020047 if (!dh_imx_get_mac_from_fuse(enetaddr))
48 goto out;
Marek Vasutf670cd72022-05-21 16:56:26 +020049
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020050 if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
51 goto out;
52
53 return -ENXIO;
54
55out:
56 return eth_env_set_enetaddr("ethaddr", enetaddr);
57}
58
59static int dh_imx8_setup_eth1addr(void)
60{
61 unsigned char enetaddr[6];
62
63 if (dh_mac_is_in_env("eth1addr"))
64 return 0;
65
66 if (!dh_imx_get_mac_from_fuse(enetaddr))
67 goto increment_out;
68
69 if (!dh_get_mac_from_eeprom(enetaddr, "eeprom1"))
70 goto out;
Marek Vasutf670cd72022-05-21 16:56:26 +020071
72 /*
73 * Populate second ethernet MAC from first ethernet EEPROM with MAC
74 * address LSByte incremented by 1. This is only used on SoMs without
75 * second ethernet EEPROM, i.e. early prototypes.
76 */
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020077 if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
78 goto increment_out;
Marek Vasutf670cd72022-05-21 16:56:26 +020079
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020080 return -ENXIO;
Marek Vasutf670cd72022-05-21 16:56:26 +020081
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020082increment_out:
83 enetaddr[5]++;
84
85out:
86 return eth_env_set_enetaddr("eth1addr", enetaddr);
Marek Vasutf670cd72022-05-21 16:56:26 +020087}
88
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020089int dh_setup_mac_address(void)
Marek Vasutf670cd72022-05-21 16:56:26 +020090{
Marek Vasutf670cd72022-05-21 16:56:26 +020091 int ret;
92
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020093 ret = dh_imx8_setup_ethaddr();
94 if (ret)
95 printf("%s: Unable to setup ethaddr! ret = %d\n", __func__, ret);
Marek Vasutf670cd72022-05-21 16:56:26 +020096
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +020097 ret = dh_imx8_setup_eth1addr();
98 if (ret)
99 printf("%s: Unable to setup eth1addr! ret = %d\n", __func__, ret);
Marek Vasutf670cd72022-05-21 16:56:26 +0200100
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +0200101 return ret;
Marek Vasutf670cd72022-05-21 16:56:26 +0200102}
103
104int board_init(void)
105{
Marek Vasutf670cd72022-05-21 16:56:26 +0200106 return 0;
107}
108
109int board_late_init(void)
110{
Philip Oberfichtnerd24f1de2022-07-26 15:04:52 +0200111 dh_setup_mac_address();
Marek Vasutf670cd72022-05-21 16:56:26 +0200112 return 0;
113}
114
115enum env_location env_get_location(enum env_operation op, int prio)
116{
117 return prio ? ENVL_UNKNOWN : ENVL_SPI_FLASH;
118}