blob: 8bf9c42b2260870e6cf0cc308e22f8dcbba3ab74 [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>
Wang Huan8ce6bec2014-09-05 13:52:34 +080019
20DECLARE_GLOBAL_DATA_PTR;
21
22void ft_fixup_enet_phy_connect_type(void *fdt)
23{
24 struct eth_device *dev;
25 struct tsec_private *priv;
26 const char *enet_path, *phy_path;
27 char enet[16];
28 char phy[16];
29 int phy_node;
30 int i = 0;
Wang Huan8ce6bec2014-09-05 13:52:34 +080031 uint32_t ph;
Bin Mengf409b362016-01-11 22:41:26 -080032 char *name[3] = { "eTSEC1", "eTSEC2", "eTSEC3" };
Wang Huan8ce6bec2014-09-05 13:52:34 +080033
Bin Mengf409b362016-01-11 22:41:26 -080034 for (; i < ARRAY_SIZE(name); i++) {
35 dev = eth_get_dev_by_name(name[i]);
36 if (dev) {
37 sprintf(enet, "ethernet%d", i);
38 sprintf(phy, "enet%d_rgmii_phy", i);
Alison Wanga304d452015-05-11 15:39:47 +080039 } else {
Wang Huan8ce6bec2014-09-05 13:52:34 +080040 continue;
Alison Wanga304d452015-05-11 15:39:47 +080041 }
Wang Huan8ce6bec2014-09-05 13:52:34 +080042
43 priv = dev->priv;
44 if (priv->flags & TSEC_SGMII)
45 continue;
46
Wang Huan8ce6bec2014-09-05 13:52:34 +080047 enet_path = fdt_get_alias(fdt, enet);
48 if (!enet_path)
49 continue;
50
Wang Huan8ce6bec2014-09-05 13:52:34 +080051 phy_path = fdt_get_alias(fdt, phy);
52 if (!phy_path)
53 continue;
54
55 phy_node = fdt_path_offset(fdt, phy_path);
56 if (phy_node < 0)
57 continue;
58
59 ph = fdt_create_phandle(fdt, phy_node);
60 if (ph)
61 do_fixup_by_path_u32(fdt, enet_path,
62 "phy-handle", ph, 1);
63
64 do_fixup_by_path(fdt, enet_path, "phy-connection-type",
65 phy_string_for_interface(
66 PHY_INTERFACE_MODE_RGMII_ID),
Brendan Shanks958eda22018-07-16 13:28:24 -070067 strlen(phy_string_for_interface(
68 PHY_INTERFACE_MODE_RGMII_ID)) + 1,
Wang Huan8ce6bec2014-09-05 13:52:34 +080069 1);
70 }
71}
72
73void ft_cpu_setup(void *blob, bd_t *bd)
74{
75 int off;
76 int val;
77 const char *sysclk_path;
Ruchika Gupta272da152014-12-15 11:30:36 +053078 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
79 unsigned int svr;
80 svr = in_be32(&gur->svr);
Wang Huan8ce6bec2014-09-05 13:52:34 +080081
82 unsigned long busclk = get_bus_freq(0);
83
Ruchika Gupta272da152014-12-15 11:30:36 +053084 /* delete crypto node if not on an E-processor */
85 if (!IS_E_PROCESSOR(svr))
86 fdt_fixup_crypto_node(blob, 0);
87#if CONFIG_SYS_FSL_SEC_COMPAT >= 4
88 else {
89 ccsr_sec_t __iomem *sec;
90
91 sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
92 fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms));
93 }
94#endif
95
Wang Huan8ce6bec2014-09-05 13:52:34 +080096 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
97 while (off != -FDT_ERR_NOTFOUND) {
98 val = gd->cpu_clk;
99 fdt_setprop(blob, off, "clock-frequency", &val, 4);
100 off = fdt_node_offset_by_prop_value(blob, off,
101 "device_type", "cpu", 4);
102 }
103
104 do_fixup_by_prop_u32(blob, "device_type", "soc",
Tang Yuantian01e43432014-10-21 13:51:58 +0800105 4, "bus-frequency", busclk, 1);
Wang Huan8ce6bec2014-09-05 13:52:34 +0800106
107 ft_fixup_enet_phy_connect_type(blob);
108
109#ifdef CONFIG_SYS_NS16550
110 do_fixup_by_compat_u32(blob, "fsl,16550-FIFO64",
111 "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
112#endif
113
114 sysclk_path = fdt_get_alias(blob, "sysclk");
115 if (sysclk_path)
116 do_fixup_by_path_u32(blob, sysclk_path, "clock-frequency",
117 CONFIG_SYS_CLK_FREQ, 1);
118 do_fixup_by_compat_u32(blob, "fsl,qoriq-sysclk-2.0",
119 "clock-frequency", CONFIG_SYS_CLK_FREQ, 1);
120
tang yuantian57296e72014-12-17 12:58:05 +0800121#if defined(CONFIG_DEEP_SLEEP) && defined(CONFIG_SD_BOOT)
122#define UBOOT_HEAD_LEN 0x1000
123 /*
124 * Reserved memory in SD boot deep sleep case.
125 * Second stage uboot binary and malloc space should be reserved.
126 * If the memory they occupied has not been reserved, then this
127 * space would be used by kernel and overwritten in uboot when
128 * deep sleep resume, which cause deep sleep failed.
129 * Since second uboot binary has a head, that space need to be
130 * reserved either(assuming its size is less than 0x1000).
131 */
132 off = fdt_add_mem_rsv(blob, CONFIG_SYS_TEXT_BASE - UBOOT_HEAD_LEN,
133 CONFIG_SYS_MONITOR_LEN + CONFIG_SYS_SPL_MALLOC_SIZE +
134 UBOOT_HEAD_LEN);
135 if (off < 0)
136 printf("Failed to reserve memory for SD boot deep sleep: %s\n",
137 fdt_strerror(off));
138#endif
139
Wang Huan8ce6bec2014-09-05 13:52:34 +0800140#if defined(CONFIG_FSL_ESDHC)
141 fdt_fixup_esdhc(blob, bd);
142#endif
143
144 /*
145 * platform bus clock = system bus clock/2
146 * Here busclk = system bus clock
147 * We are using the platform bus clock as 1588 Timer reference
148 * clock source select
149 */
150 do_fixup_by_compat_u32(blob, "fsl, gianfar-ptp-timer",
151 "timer-frequency", busclk / 2, 1);
152
153 /*
154 * clock-freq should change to clock-frequency and
155 * flexcan-v1.0 should change to p1010-flexcan respectively
156 * in the future.
157 */
158 do_fixup_by_compat_u32(blob, "fsl, flexcan-v1.0",
159 "clock_freq", busclk / 2, 1);
160
161 do_fixup_by_compat_u32(blob, "fsl, flexcan-v1.0",
162 "clock-frequency", busclk / 2, 1);
163
164 do_fixup_by_compat_u32(blob, "fsl, ls1021a-flexcan",
165 "clock-frequency", busclk / 2, 1);
Alison Wang92fc30d2014-12-26 13:14:01 +0800166
Alison Wang79fe0782015-10-28 10:40:23 +0800167#if defined(CONFIG_QSPI_BOOT) || defined(CONFIG_SD_BOOT_QSPI)
Alison Wang92fc30d2014-12-26 13:14:01 +0800168 off = fdt_node_offset_by_compat_reg(blob, FSL_IFC_COMPAT,
169 CONFIG_SYS_IFC_ADDR);
170 fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
171#else
172 off = fdt_node_offset_by_compat_reg(blob, FSL_QSPI_COMPAT,
173 QSPI0_BASE_ADDR);
174 fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
175 off = fdt_node_offset_by_compat_reg(blob, FSL_DSPI_COMPAT,
176 DSPI1_BASE_ADDR);
177 fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
178#endif
Wang Huan8ce6bec2014-09-05 13:52:34 +0800179}