blob: 0e7d5fa06dc6780aaa34f5f39058f32d9fe2eda3 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wang Huan8ce6bec2014-09-05 13:52:34 +08002/*
3 * Copyright 2014 Freescale Semiconductor, Inc.
Wang Huan8ce6bec2014-09-05 13:52:34 +08004 */
5
6#include <common.h>
Simon Glass85d65312019-12-28 10:44:58 -07007#include <clock_legacy.h>
Simon Glass274e0b02020-05-10 11:39:56 -06008#include <net.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06009#include <asm/global_data.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090010#include <linux/libfdt.h>
Wang Huan8ce6bec2014-09-05 13:52:34 +080011#include <fdt_support.h>
12#include <asm/io.h>
13#include <asm/processor.h>
14#include <asm/arch/clock.h>
15#include <linux/ctype.h>
16#ifdef CONFIG_FSL_ESDHC
17#include <fsl_esdhc.h>
18#endif
19#include <tsec.h>
Ruchika Gupta272da152014-12-15 11:30:36 +053020#include <asm/arch/immap_ls102xa.h>
21#include <fsl_sec.h>
Bin Meng19c04602019-07-19 00:29:59 +030022#include <dm.h>
Wang Huan8ce6bec2014-09-05 13:52:34 +080023
24DECLARE_GLOBAL_DATA_PTR;
25
26void ft_fixup_enet_phy_connect_type(void *fdt)
27{
Bin Meng19c04602019-07-19 00:29:59 +030028#ifdef CONFIG_DM_ETH
29 struct udevice *dev;
30#else
Wang Huan8ce6bec2014-09-05 13:52:34 +080031 struct eth_device *dev;
Bin Meng19c04602019-07-19 00:29:59 +030032#endif
Wang Huan8ce6bec2014-09-05 13:52:34 +080033 struct tsec_private *priv;
34 const char *enet_path, *phy_path;
35 char enet[16];
36 char phy[16];
37 int phy_node;
38 int i = 0;
Wang Huan8ce6bec2014-09-05 13:52:34 +080039 uint32_t ph;
Bin Meng19c04602019-07-19 00:29:59 +030040#ifdef CONFIG_DM_ETH
41 char *name[3] = { "ethernet@2d10000", "ethernet@2d50000",
42 "ethernet@2d90000" };
43#else
Bin Mengf409b362016-01-11 22:41:26 -080044 char *name[3] = { "eTSEC1", "eTSEC2", "eTSEC3" };
Bin Meng19c04602019-07-19 00:29:59 +030045#endif
Wang Huan8ce6bec2014-09-05 13:52:34 +080046
Bin Mengf409b362016-01-11 22:41:26 -080047 for (; i < ARRAY_SIZE(name); i++) {
48 dev = eth_get_dev_by_name(name[i]);
49 if (dev) {
50 sprintf(enet, "ethernet%d", i);
51 sprintf(phy, "enet%d_rgmii_phy", i);
Alison Wanga304d452015-05-11 15:39:47 +080052 } else {
Wang Huan8ce6bec2014-09-05 13:52:34 +080053 continue;
Alison Wanga304d452015-05-11 15:39:47 +080054 }
Wang Huan8ce6bec2014-09-05 13:52:34 +080055
Simon Glass95588622020-12-22 19:30:28 -070056#ifdef CONFIG_DM_ETH
57 priv = dev_get_priv(dev);
58#else
Wang Huan8ce6bec2014-09-05 13:52:34 +080059 priv = dev->priv;
Simon Glass95588622020-12-22 19:30:28 -070060#endif
Wang Huan8ce6bec2014-09-05 13:52:34 +080061 if (priv->flags & TSEC_SGMII)
62 continue;
63
Wang Huan8ce6bec2014-09-05 13:52:34 +080064 enet_path = fdt_get_alias(fdt, enet);
65 if (!enet_path)
66 continue;
67
Wang Huan8ce6bec2014-09-05 13:52:34 +080068 phy_path = fdt_get_alias(fdt, phy);
69 if (!phy_path)
70 continue;
71
72 phy_node = fdt_path_offset(fdt, phy_path);
73 if (phy_node < 0)
74 continue;
75
76 ph = fdt_create_phandle(fdt, phy_node);
77 if (ph)
78 do_fixup_by_path_u32(fdt, enet_path,
79 "phy-handle", ph, 1);
80
81 do_fixup_by_path(fdt, enet_path, "phy-connection-type",
82 phy_string_for_interface(
83 PHY_INTERFACE_MODE_RGMII_ID),
Brendan Shanks958eda22018-07-16 13:28:24 -070084 strlen(phy_string_for_interface(
85 PHY_INTERFACE_MODE_RGMII_ID)) + 1,
Wang Huan8ce6bec2014-09-05 13:52:34 +080086 1);
87 }
88}
89
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090090void ft_cpu_setup(void *blob, struct bd_info *bd)
Wang Huan8ce6bec2014-09-05 13:52:34 +080091{
92 int off;
93 int val;
94 const char *sysclk_path;
Tom Rini376b88a2022-10-28 20:27:13 -040095 struct ccsr_gur __iomem *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR);
Ruchika Gupta272da152014-12-15 11:30:36 +053096 unsigned int svr;
97 svr = in_be32(&gur->svr);
Wang Huan8ce6bec2014-09-05 13:52:34 +080098
99 unsigned long busclk = get_bus_freq(0);
100
Ruchika Gupta272da152014-12-15 11:30:36 +0530101 /* delete crypto node if not on an E-processor */
102 if (!IS_E_PROCESSOR(svr))
103 fdt_fixup_crypto_node(blob, 0);
104#if CONFIG_SYS_FSL_SEC_COMPAT >= 4
105 else {
106 ccsr_sec_t __iomem *sec;
107
Tom Rini376b88a2022-10-28 20:27:13 -0400108 sec = (void __iomem *)CFG_SYS_FSL_SEC_ADDR;
Ruchika Gupta272da152014-12-15 11:30:36 +0530109 fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms));
110 }
111#endif
112
Wang Huan8ce6bec2014-09-05 13:52:34 +0800113 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
114 while (off != -FDT_ERR_NOTFOUND) {
115 val = gd->cpu_clk;
116 fdt_setprop(blob, off, "clock-frequency", &val, 4);
117 off = fdt_node_offset_by_prop_value(blob, off,
118 "device_type", "cpu", 4);
119 }
120
121 do_fixup_by_prop_u32(blob, "device_type", "soc",
Tang Yuantian01e43432014-10-21 13:51:58 +0800122 4, "bus-frequency", busclk, 1);
Wang Huan8ce6bec2014-09-05 13:52:34 +0800123
124 ft_fixup_enet_phy_connect_type(blob);
125
126#ifdef CONFIG_SYS_NS16550
127 do_fixup_by_compat_u32(blob, "fsl,16550-FIFO64",
Tom Rinidf6a2152022-11-16 13:10:28 -0500128 "clock-frequency", CFG_SYS_NS16550_CLK, 1);
Wang Huan8ce6bec2014-09-05 13:52:34 +0800129#endif
130
131 sysclk_path = fdt_get_alias(blob, "sysclk");
132 if (sysclk_path)
133 do_fixup_by_path_u32(blob, sysclk_path, "clock-frequency",
Tom Rini8c70baa2021-12-14 13:36:40 -0500134 get_board_sys_clk(), 1);
Wang Huan8ce6bec2014-09-05 13:52:34 +0800135 do_fixup_by_compat_u32(blob, "fsl,qoriq-sysclk-2.0",
Tom Rini8c70baa2021-12-14 13:36:40 -0500136 "clock-frequency", get_board_sys_clk(), 1);
Wang Huan8ce6bec2014-09-05 13:52:34 +0800137
tang yuantian57296e72014-12-17 12:58:05 +0800138#if defined(CONFIG_DEEP_SLEEP) && defined(CONFIG_SD_BOOT)
139#define UBOOT_HEAD_LEN 0x1000
140 /*
141 * Reserved memory in SD boot deep sleep case.
142 * Second stage uboot binary and malloc space should be reserved.
143 * If the memory they occupied has not been reserved, then this
144 * space would be used by kernel and overwritten in uboot when
145 * deep sleep resume, which cause deep sleep failed.
146 * Since second uboot binary has a head, that space need to be
147 * reserved either(assuming its size is less than 0x1000).
148 */
Simon Glass72cc5382022-10-20 18:22:39 -0600149 off = fdt_add_mem_rsv(blob, CONFIG_TEXT_BASE - UBOOT_HEAD_LEN,
150 CONFIG_SYS_MONITOR_LEN +
151 CONFIG_SYS_SPL_MALLOC_SIZE + UBOOT_HEAD_LEN);
tang yuantian57296e72014-12-17 12:58:05 +0800152 if (off < 0)
153 printf("Failed to reserve memory for SD boot deep sleep: %s\n",
154 fdt_strerror(off));
155#endif
156
Wang Huan8ce6bec2014-09-05 13:52:34 +0800157#if defined(CONFIG_FSL_ESDHC)
158 fdt_fixup_esdhc(blob, bd);
159#endif
160
161 /*
162 * platform bus clock = system bus clock/2
163 * Here busclk = system bus clock
164 * We are using the platform bus clock as 1588 Timer reference
165 * clock source select
166 */
167 do_fixup_by_compat_u32(blob, "fsl, gianfar-ptp-timer",
168 "timer-frequency", busclk / 2, 1);
169
170 /*
171 * clock-freq should change to clock-frequency and
172 * flexcan-v1.0 should change to p1010-flexcan respectively
173 * in the future.
174 */
175 do_fixup_by_compat_u32(blob, "fsl, flexcan-v1.0",
176 "clock_freq", busclk / 2, 1);
177
178 do_fixup_by_compat_u32(blob, "fsl, flexcan-v1.0",
179 "clock-frequency", busclk / 2, 1);
180
181 do_fixup_by_compat_u32(blob, "fsl, ls1021a-flexcan",
182 "clock-frequency", busclk / 2, 1);
Alison Wang92fc30d2014-12-26 13:14:01 +0800183
Alison Wang79fe0782015-10-28 10:40:23 +0800184#if defined(CONFIG_QSPI_BOOT) || defined(CONFIG_SD_BOOT_QSPI)
Alison Wang92fc30d2014-12-26 13:14:01 +0800185 off = fdt_node_offset_by_compat_reg(blob, FSL_IFC_COMPAT,
186 CONFIG_SYS_IFC_ADDR);
Marek Behúnf872e832021-11-26 14:57:08 +0100187 fdt_set_node_status(blob, off, FDT_STATUS_DISABLED);
Alison Wang92fc30d2014-12-26 13:14:01 +0800188#else
189 off = fdt_node_offset_by_compat_reg(blob, FSL_QSPI_COMPAT,
190 QSPI0_BASE_ADDR);
Marek Behúnf872e832021-11-26 14:57:08 +0100191 fdt_set_node_status(blob, off, FDT_STATUS_DISABLED);
Alison Wang92fc30d2014-12-26 13:14:01 +0800192 off = fdt_node_offset_by_compat_reg(blob, FSL_DSPI_COMPAT,
193 DSPI1_BASE_ADDR);
Marek Behúnf872e832021-11-26 14:57:08 +0100194 fdt_set_node_status(blob, off, FDT_STATUS_DISABLED);
Alison Wang92fc30d2014-12-26 13:14:01 +0800195#endif
Wang Huan8ce6bec2014-09-05 13:52:34 +0800196}