blob: 2556980cde6735faddd56196e173b1ae755060b3 [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>
Masahiro Yamada75f82d02018-03-05 01:20:11 +09009#include <linux/libfdt.h>
Wang Huan8ce6bec2014-09-05 13:52:34 +080010#include <fdt_support.h>
11#include <asm/io.h>
12#include <asm/processor.h>
13#include <asm/arch/clock.h>
14#include <linux/ctype.h>
15#ifdef CONFIG_FSL_ESDHC
16#include <fsl_esdhc.h>
17#endif
18#include <tsec.h>
Ruchika Gupta272da152014-12-15 11:30:36 +053019#include <asm/arch/immap_ls102xa.h>
20#include <fsl_sec.h>
Bin Meng19c04602019-07-19 00:29:59 +030021#include <dm.h>
Wang Huan8ce6bec2014-09-05 13:52:34 +080022
23DECLARE_GLOBAL_DATA_PTR;
24
25void ft_fixup_enet_phy_connect_type(void *fdt)
26{
Bin Meng19c04602019-07-19 00:29:59 +030027#ifdef CONFIG_DM_ETH
28 struct udevice *dev;
29#else
Wang Huan8ce6bec2014-09-05 13:52:34 +080030 struct eth_device *dev;
Bin Meng19c04602019-07-19 00:29:59 +030031#endif
Wang Huan8ce6bec2014-09-05 13:52:34 +080032 struct tsec_private *priv;
33 const char *enet_path, *phy_path;
34 char enet[16];
35 char phy[16];
36 int phy_node;
37 int i = 0;
Wang Huan8ce6bec2014-09-05 13:52:34 +080038 uint32_t ph;
Bin Meng19c04602019-07-19 00:29:59 +030039#ifdef CONFIG_DM_ETH
40 char *name[3] = { "ethernet@2d10000", "ethernet@2d50000",
41 "ethernet@2d90000" };
42#else
Bin Mengf409b362016-01-11 22:41:26 -080043 char *name[3] = { "eTSEC1", "eTSEC2", "eTSEC3" };
Bin Meng19c04602019-07-19 00:29:59 +030044#endif
Wang Huan8ce6bec2014-09-05 13:52:34 +080045
Bin Mengf409b362016-01-11 22:41:26 -080046 for (; i < ARRAY_SIZE(name); i++) {
47 dev = eth_get_dev_by_name(name[i]);
48 if (dev) {
49 sprintf(enet, "ethernet%d", i);
50 sprintf(phy, "enet%d_rgmii_phy", i);
Alison Wanga304d452015-05-11 15:39:47 +080051 } else {
Wang Huan8ce6bec2014-09-05 13:52:34 +080052 continue;
Alison Wanga304d452015-05-11 15:39:47 +080053 }
Wang Huan8ce6bec2014-09-05 13:52:34 +080054
Simon Glass95588622020-12-22 19:30:28 -070055#ifdef CONFIG_DM_ETH
56 priv = dev_get_priv(dev);
57#else
Wang Huan8ce6bec2014-09-05 13:52:34 +080058 priv = dev->priv;
Simon Glass95588622020-12-22 19:30:28 -070059#endif
Wang Huan8ce6bec2014-09-05 13:52:34 +080060 if (priv->flags & TSEC_SGMII)
61 continue;
62
Wang Huan8ce6bec2014-09-05 13:52:34 +080063 enet_path = fdt_get_alias(fdt, enet);
64 if (!enet_path)
65 continue;
66
Wang Huan8ce6bec2014-09-05 13:52:34 +080067 phy_path = fdt_get_alias(fdt, phy);
68 if (!phy_path)
69 continue;
70
71 phy_node = fdt_path_offset(fdt, phy_path);
72 if (phy_node < 0)
73 continue;
74
75 ph = fdt_create_phandle(fdt, phy_node);
76 if (ph)
77 do_fixup_by_path_u32(fdt, enet_path,
78 "phy-handle", ph, 1);
79
80 do_fixup_by_path(fdt, enet_path, "phy-connection-type",
81 phy_string_for_interface(
82 PHY_INTERFACE_MODE_RGMII_ID),
Brendan Shanks958eda22018-07-16 13:28:24 -070083 strlen(phy_string_for_interface(
84 PHY_INTERFACE_MODE_RGMII_ID)) + 1,
Wang Huan8ce6bec2014-09-05 13:52:34 +080085 1);
86 }
87}
88
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090089void ft_cpu_setup(void *blob, struct bd_info *bd)
Wang Huan8ce6bec2014-09-05 13:52:34 +080090{
91 int off;
92 int val;
93 const char *sysclk_path;
Ruchika Gupta272da152014-12-15 11:30:36 +053094 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
95 unsigned int svr;
96 svr = in_be32(&gur->svr);
Wang Huan8ce6bec2014-09-05 13:52:34 +080097
98 unsigned long busclk = get_bus_freq(0);
99
Ruchika Gupta272da152014-12-15 11:30:36 +0530100 /* delete crypto node if not on an E-processor */
101 if (!IS_E_PROCESSOR(svr))
102 fdt_fixup_crypto_node(blob, 0);
103#if CONFIG_SYS_FSL_SEC_COMPAT >= 4
104 else {
105 ccsr_sec_t __iomem *sec;
106
107 sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
108 fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms));
109 }
110#endif
111
Wang Huan8ce6bec2014-09-05 13:52:34 +0800112 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
113 while (off != -FDT_ERR_NOTFOUND) {
114 val = gd->cpu_clk;
115 fdt_setprop(blob, off, "clock-frequency", &val, 4);
116 off = fdt_node_offset_by_prop_value(blob, off,
117 "device_type", "cpu", 4);
118 }
119
120 do_fixup_by_prop_u32(blob, "device_type", "soc",
Tang Yuantian01e43432014-10-21 13:51:58 +0800121 4, "bus-frequency", busclk, 1);
Wang Huan8ce6bec2014-09-05 13:52:34 +0800122
123 ft_fixup_enet_phy_connect_type(blob);
124
125#ifdef CONFIG_SYS_NS16550
126 do_fixup_by_compat_u32(blob, "fsl,16550-FIFO64",
127 "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
128#endif
129
130 sysclk_path = fdt_get_alias(blob, "sysclk");
131 if (sysclk_path)
132 do_fixup_by_path_u32(blob, sysclk_path, "clock-frequency",
133 CONFIG_SYS_CLK_FREQ, 1);
134 do_fixup_by_compat_u32(blob, "fsl,qoriq-sysclk-2.0",
135 "clock-frequency", CONFIG_SYS_CLK_FREQ, 1);
136
tang yuantian57296e72014-12-17 12:58:05 +0800137#if defined(CONFIG_DEEP_SLEEP) && defined(CONFIG_SD_BOOT)
138#define UBOOT_HEAD_LEN 0x1000
139 /*
140 * Reserved memory in SD boot deep sleep case.
141 * Second stage uboot binary and malloc space should be reserved.
142 * If the memory they occupied has not been reserved, then this
143 * space would be used by kernel and overwritten in uboot when
144 * deep sleep resume, which cause deep sleep failed.
145 * Since second uboot binary has a head, that space need to be
146 * reserved either(assuming its size is less than 0x1000).
147 */
148 off = fdt_add_mem_rsv(blob, CONFIG_SYS_TEXT_BASE - UBOOT_HEAD_LEN,
149 CONFIG_SYS_MONITOR_LEN + CONFIG_SYS_SPL_MALLOC_SIZE +
150 UBOOT_HEAD_LEN);
151 if (off < 0)
152 printf("Failed to reserve memory for SD boot deep sleep: %s\n",
153 fdt_strerror(off));
154#endif
155
Wang Huan8ce6bec2014-09-05 13:52:34 +0800156#if defined(CONFIG_FSL_ESDHC)
157 fdt_fixup_esdhc(blob, bd);
158#endif
159
160 /*
161 * platform bus clock = system bus clock/2
162 * Here busclk = system bus clock
163 * We are using the platform bus clock as 1588 Timer reference
164 * clock source select
165 */
166 do_fixup_by_compat_u32(blob, "fsl, gianfar-ptp-timer",
167 "timer-frequency", busclk / 2, 1);
168
169 /*
170 * clock-freq should change to clock-frequency and
171 * flexcan-v1.0 should change to p1010-flexcan respectively
172 * in the future.
173 */
174 do_fixup_by_compat_u32(blob, "fsl, flexcan-v1.0",
175 "clock_freq", busclk / 2, 1);
176
177 do_fixup_by_compat_u32(blob, "fsl, flexcan-v1.0",
178 "clock-frequency", busclk / 2, 1);
179
180 do_fixup_by_compat_u32(blob, "fsl, ls1021a-flexcan",
181 "clock-frequency", busclk / 2, 1);
Alison Wang92fc30d2014-12-26 13:14:01 +0800182
Alison Wang79fe0782015-10-28 10:40:23 +0800183#if defined(CONFIG_QSPI_BOOT) || defined(CONFIG_SD_BOOT_QSPI)
Alison Wang92fc30d2014-12-26 13:14:01 +0800184 off = fdt_node_offset_by_compat_reg(blob, FSL_IFC_COMPAT,
185 CONFIG_SYS_IFC_ADDR);
186 fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
187#else
188 off = fdt_node_offset_by_compat_reg(blob, FSL_QSPI_COMPAT,
189 QSPI0_BASE_ADDR);
190 fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
191 off = fdt_node_offset_by_compat_reg(blob, FSL_DSPI_COMPAT,
192 DSPI1_BASE_ADDR);
193 fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
194#endif
Wang Huan8ce6bec2014-09-05 13:52:34 +0800195}