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