blob: 1aadffff5991954edc7a56ff8a10babdc5a5c047 [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>
Masahiro Yamada75f82d02018-03-05 01:20:11 +09007#include <linux/libfdt.h>
Wang Huan8ce6bec2014-09-05 13:52:34 +08008#include <fdt_support.h>
9#include <asm/io.h>
10#include <asm/processor.h>
11#include <asm/arch/clock.h>
12#include <linux/ctype.h>
13#ifdef CONFIG_FSL_ESDHC
14#include <fsl_esdhc.h>
15#endif
16#include <tsec.h>
Ruchika Gupta272da152014-12-15 11:30:36 +053017#include <asm/arch/immap_ls102xa.h>
18#include <fsl_sec.h>
Bin Meng19c04602019-07-19 00:29:59 +030019#include <dm.h>
Wang Huan8ce6bec2014-09-05 13:52:34 +080020
21DECLARE_GLOBAL_DATA_PTR;
22
23void ft_fixup_enet_phy_connect_type(void *fdt)
24{
Bin Meng19c04602019-07-19 00:29:59 +030025#ifdef CONFIG_DM_ETH
26 struct udevice *dev;
27#else
Wang Huan8ce6bec2014-09-05 13:52:34 +080028 struct eth_device *dev;
Bin Meng19c04602019-07-19 00:29:59 +030029#endif
Wang Huan8ce6bec2014-09-05 13:52:34 +080030 struct tsec_private *priv;
31 const char *enet_path, *phy_path;
32 char enet[16];
33 char phy[16];
34 int phy_node;
35 int i = 0;
Wang Huan8ce6bec2014-09-05 13:52:34 +080036 uint32_t ph;
Bin Meng19c04602019-07-19 00:29:59 +030037#ifdef CONFIG_DM_ETH
38 char *name[3] = { "ethernet@2d10000", "ethernet@2d50000",
39 "ethernet@2d90000" };
40#else
Bin Mengf409b362016-01-11 22:41:26 -080041 char *name[3] = { "eTSEC1", "eTSEC2", "eTSEC3" };
Bin Meng19c04602019-07-19 00:29:59 +030042#endif
Wang Huan8ce6bec2014-09-05 13:52:34 +080043
Bin Mengf409b362016-01-11 22:41:26 -080044 for (; i < ARRAY_SIZE(name); i++) {
45 dev = eth_get_dev_by_name(name[i]);
46 if (dev) {
47 sprintf(enet, "ethernet%d", i);
48 sprintf(phy, "enet%d_rgmii_phy", i);
Alison Wanga304d452015-05-11 15:39:47 +080049 } else {
Wang Huan8ce6bec2014-09-05 13:52:34 +080050 continue;
Alison Wanga304d452015-05-11 15:39:47 +080051 }
Wang Huan8ce6bec2014-09-05 13:52:34 +080052
53 priv = dev->priv;
54 if (priv->flags & TSEC_SGMII)
55 continue;
56
Wang Huan8ce6bec2014-09-05 13:52:34 +080057 enet_path = fdt_get_alias(fdt, enet);
58 if (!enet_path)
59 continue;
60
Wang Huan8ce6bec2014-09-05 13:52:34 +080061 phy_path = fdt_get_alias(fdt, phy);
62 if (!phy_path)
63 continue;
64
65 phy_node = fdt_path_offset(fdt, phy_path);
66 if (phy_node < 0)
67 continue;
68
69 ph = fdt_create_phandle(fdt, phy_node);
70 if (ph)
71 do_fixup_by_path_u32(fdt, enet_path,
72 "phy-handle", ph, 1);
73
74 do_fixup_by_path(fdt, enet_path, "phy-connection-type",
75 phy_string_for_interface(
76 PHY_INTERFACE_MODE_RGMII_ID),
Brendan Shanks958eda22018-07-16 13:28:24 -070077 strlen(phy_string_for_interface(
78 PHY_INTERFACE_MODE_RGMII_ID)) + 1,
Wang Huan8ce6bec2014-09-05 13:52:34 +080079 1);
80 }
81}
82
83void ft_cpu_setup(void *blob, bd_t *bd)
84{
85 int off;
86 int val;
87 const char *sysclk_path;
Ruchika Gupta272da152014-12-15 11:30:36 +053088 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
89 unsigned int svr;
90 svr = in_be32(&gur->svr);
Wang Huan8ce6bec2014-09-05 13:52:34 +080091
92 unsigned long busclk = get_bus_freq(0);
93
Ruchika Gupta272da152014-12-15 11:30:36 +053094 /* delete crypto node if not on an E-processor */
95 if (!IS_E_PROCESSOR(svr))
96 fdt_fixup_crypto_node(blob, 0);
97#if CONFIG_SYS_FSL_SEC_COMPAT >= 4
98 else {
99 ccsr_sec_t __iomem *sec;
100
101 sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
102 fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms));
103 }
104#endif
105
Wang Huan8ce6bec2014-09-05 13:52:34 +0800106 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
107 while (off != -FDT_ERR_NOTFOUND) {
108 val = gd->cpu_clk;
109 fdt_setprop(blob, off, "clock-frequency", &val, 4);
110 off = fdt_node_offset_by_prop_value(blob, off,
111 "device_type", "cpu", 4);
112 }
113
114 do_fixup_by_prop_u32(blob, "device_type", "soc",
Tang Yuantian01e43432014-10-21 13:51:58 +0800115 4, "bus-frequency", busclk, 1);
Wang Huan8ce6bec2014-09-05 13:52:34 +0800116
117 ft_fixup_enet_phy_connect_type(blob);
118
119#ifdef CONFIG_SYS_NS16550
120 do_fixup_by_compat_u32(blob, "fsl,16550-FIFO64",
121 "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
122#endif
123
124 sysclk_path = fdt_get_alias(blob, "sysclk");
125 if (sysclk_path)
126 do_fixup_by_path_u32(blob, sysclk_path, "clock-frequency",
127 CONFIG_SYS_CLK_FREQ, 1);
128 do_fixup_by_compat_u32(blob, "fsl,qoriq-sysclk-2.0",
129 "clock-frequency", CONFIG_SYS_CLK_FREQ, 1);
130
tang yuantian57296e72014-12-17 12:58:05 +0800131#if defined(CONFIG_DEEP_SLEEP) && defined(CONFIG_SD_BOOT)
132#define UBOOT_HEAD_LEN 0x1000
133 /*
134 * Reserved memory in SD boot deep sleep case.
135 * Second stage uboot binary and malloc space should be reserved.
136 * If the memory they occupied has not been reserved, then this
137 * space would be used by kernel and overwritten in uboot when
138 * deep sleep resume, which cause deep sleep failed.
139 * Since second uboot binary has a head, that space need to be
140 * reserved either(assuming its size is less than 0x1000).
141 */
142 off = fdt_add_mem_rsv(blob, CONFIG_SYS_TEXT_BASE - UBOOT_HEAD_LEN,
143 CONFIG_SYS_MONITOR_LEN + CONFIG_SYS_SPL_MALLOC_SIZE +
144 UBOOT_HEAD_LEN);
145 if (off < 0)
146 printf("Failed to reserve memory for SD boot deep sleep: %s\n",
147 fdt_strerror(off));
148#endif
149
Wang Huan8ce6bec2014-09-05 13:52:34 +0800150#if defined(CONFIG_FSL_ESDHC)
151 fdt_fixup_esdhc(blob, bd);
152#endif
153
154 /*
155 * platform bus clock = system bus clock/2
156 * Here busclk = system bus clock
157 * We are using the platform bus clock as 1588 Timer reference
158 * clock source select
159 */
160 do_fixup_by_compat_u32(blob, "fsl, gianfar-ptp-timer",
161 "timer-frequency", busclk / 2, 1);
162
163 /*
164 * clock-freq should change to clock-frequency and
165 * flexcan-v1.0 should change to p1010-flexcan respectively
166 * in the future.
167 */
168 do_fixup_by_compat_u32(blob, "fsl, flexcan-v1.0",
169 "clock_freq", busclk / 2, 1);
170
171 do_fixup_by_compat_u32(blob, "fsl, flexcan-v1.0",
172 "clock-frequency", busclk / 2, 1);
173
174 do_fixup_by_compat_u32(blob, "fsl, ls1021a-flexcan",
175 "clock-frequency", busclk / 2, 1);
Alison Wang92fc30d2014-12-26 13:14:01 +0800176
Alison Wang79fe0782015-10-28 10:40:23 +0800177#if defined(CONFIG_QSPI_BOOT) || defined(CONFIG_SD_BOOT_QSPI)
Alison Wang92fc30d2014-12-26 13:14:01 +0800178 off = fdt_node_offset_by_compat_reg(blob, FSL_IFC_COMPAT,
179 CONFIG_SYS_IFC_ADDR);
180 fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
181#else
182 off = fdt_node_offset_by_compat_reg(blob, FSL_QSPI_COMPAT,
183 QSPI0_BASE_ADDR);
184 fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
185 off = fdt_node_offset_by_compat_reg(blob, FSL_DSPI_COMPAT,
186 DSPI1_BASE_ADDR);
187 fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
188#endif
Wang Huan8ce6bec2014-09-05 13:52:34 +0800189}