1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2014 Freescale Semiconductor, Inc.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+
5*4882a593Smuzhiyun */
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun #include <common.h>
8*4882a593Smuzhiyun #include <linux/libfdt.h>
9*4882a593Smuzhiyun #include <fdt_support.h>
10*4882a593Smuzhiyun #include <asm/io.h>
11*4882a593Smuzhiyun #include <asm/processor.h>
12*4882a593Smuzhiyun #include <asm/arch/clock.h>
13*4882a593Smuzhiyun #include <linux/ctype.h>
14*4882a593Smuzhiyun #ifdef CONFIG_FSL_ESDHC
15*4882a593Smuzhiyun #include <fsl_esdhc.h>
16*4882a593Smuzhiyun #endif
17*4882a593Smuzhiyun #include <tsec.h>
18*4882a593Smuzhiyun #include <asm/arch/immap_ls102xa.h>
19*4882a593Smuzhiyun #include <fsl_sec.h>
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
22*4882a593Smuzhiyun
ft_fixup_enet_phy_connect_type(void * fdt)23*4882a593Smuzhiyun void ft_fixup_enet_phy_connect_type(void *fdt)
24*4882a593Smuzhiyun {
25*4882a593Smuzhiyun struct eth_device *dev;
26*4882a593Smuzhiyun struct tsec_private *priv;
27*4882a593Smuzhiyun const char *enet_path, *phy_path;
28*4882a593Smuzhiyun char enet[16];
29*4882a593Smuzhiyun char phy[16];
30*4882a593Smuzhiyun int phy_node;
31*4882a593Smuzhiyun int i = 0;
32*4882a593Smuzhiyun uint32_t ph;
33*4882a593Smuzhiyun char *name[3] = { "eTSEC1", "eTSEC2", "eTSEC3" };
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun for (; i < ARRAY_SIZE(name); i++) {
36*4882a593Smuzhiyun dev = eth_get_dev_by_name(name[i]);
37*4882a593Smuzhiyun if (dev) {
38*4882a593Smuzhiyun sprintf(enet, "ethernet%d", i);
39*4882a593Smuzhiyun sprintf(phy, "enet%d_rgmii_phy", i);
40*4882a593Smuzhiyun } else {
41*4882a593Smuzhiyun continue;
42*4882a593Smuzhiyun }
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun priv = dev->priv;
45*4882a593Smuzhiyun if (priv->flags & TSEC_SGMII)
46*4882a593Smuzhiyun continue;
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun enet_path = fdt_get_alias(fdt, enet);
49*4882a593Smuzhiyun if (!enet_path)
50*4882a593Smuzhiyun continue;
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun phy_path = fdt_get_alias(fdt, phy);
53*4882a593Smuzhiyun if (!phy_path)
54*4882a593Smuzhiyun continue;
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun phy_node = fdt_path_offset(fdt, phy_path);
57*4882a593Smuzhiyun if (phy_node < 0)
58*4882a593Smuzhiyun continue;
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun ph = fdt_create_phandle(fdt, phy_node);
61*4882a593Smuzhiyun if (ph)
62*4882a593Smuzhiyun do_fixup_by_path_u32(fdt, enet_path,
63*4882a593Smuzhiyun "phy-handle", ph, 1);
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun do_fixup_by_path(fdt, enet_path, "phy-connection-type",
66*4882a593Smuzhiyun phy_string_for_interface(
67*4882a593Smuzhiyun PHY_INTERFACE_MODE_RGMII_ID),
68*4882a593Smuzhiyun sizeof(phy_string_for_interface(
69*4882a593Smuzhiyun PHY_INTERFACE_MODE_RGMII_ID)),
70*4882a593Smuzhiyun 1);
71*4882a593Smuzhiyun }
72*4882a593Smuzhiyun }
73*4882a593Smuzhiyun
ft_cpu_setup(void * blob,bd_t * bd)74*4882a593Smuzhiyun void ft_cpu_setup(void *blob, bd_t *bd)
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun int off;
77*4882a593Smuzhiyun int val;
78*4882a593Smuzhiyun const char *sysclk_path;
79*4882a593Smuzhiyun struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
80*4882a593Smuzhiyun unsigned int svr;
81*4882a593Smuzhiyun svr = in_be32(&gur->svr);
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun unsigned long busclk = get_bus_freq(0);
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun /* delete crypto node if not on an E-processor */
86*4882a593Smuzhiyun if (!IS_E_PROCESSOR(svr))
87*4882a593Smuzhiyun fdt_fixup_crypto_node(blob, 0);
88*4882a593Smuzhiyun #if CONFIG_SYS_FSL_SEC_COMPAT >= 4
89*4882a593Smuzhiyun else {
90*4882a593Smuzhiyun ccsr_sec_t __iomem *sec;
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
93*4882a593Smuzhiyun fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms));
94*4882a593Smuzhiyun }
95*4882a593Smuzhiyun #endif
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
98*4882a593Smuzhiyun while (off != -FDT_ERR_NOTFOUND) {
99*4882a593Smuzhiyun val = gd->cpu_clk;
100*4882a593Smuzhiyun fdt_setprop(blob, off, "clock-frequency", &val, 4);
101*4882a593Smuzhiyun off = fdt_node_offset_by_prop_value(blob, off,
102*4882a593Smuzhiyun "device_type", "cpu", 4);
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun do_fixup_by_prop_u32(blob, "device_type", "soc",
106*4882a593Smuzhiyun 4, "bus-frequency", busclk, 1);
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun ft_fixup_enet_phy_connect_type(blob);
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun #ifdef CONFIG_SYS_NS16550
111*4882a593Smuzhiyun do_fixup_by_compat_u32(blob, "fsl,16550-FIFO64",
112*4882a593Smuzhiyun "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
113*4882a593Smuzhiyun #endif
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun sysclk_path = fdt_get_alias(blob, "sysclk");
116*4882a593Smuzhiyun if (sysclk_path)
117*4882a593Smuzhiyun do_fixup_by_path_u32(blob, sysclk_path, "clock-frequency",
118*4882a593Smuzhiyun CONFIG_SYS_CLK_FREQ, 1);
119*4882a593Smuzhiyun do_fixup_by_compat_u32(blob, "fsl,qoriq-sysclk-2.0",
120*4882a593Smuzhiyun "clock-frequency", CONFIG_SYS_CLK_FREQ, 1);
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun #if defined(CONFIG_DEEP_SLEEP) && defined(CONFIG_SD_BOOT)
123*4882a593Smuzhiyun #define UBOOT_HEAD_LEN 0x1000
124*4882a593Smuzhiyun /*
125*4882a593Smuzhiyun * Reserved memory in SD boot deep sleep case.
126*4882a593Smuzhiyun * Second stage uboot binary and malloc space should be reserved.
127*4882a593Smuzhiyun * If the memory they occupied has not been reserved, then this
128*4882a593Smuzhiyun * space would be used by kernel and overwritten in uboot when
129*4882a593Smuzhiyun * deep sleep resume, which cause deep sleep failed.
130*4882a593Smuzhiyun * Since second uboot binary has a head, that space need to be
131*4882a593Smuzhiyun * reserved either(assuming its size is less than 0x1000).
132*4882a593Smuzhiyun */
133*4882a593Smuzhiyun off = fdt_add_mem_rsv(blob, CONFIG_SYS_TEXT_BASE - UBOOT_HEAD_LEN,
134*4882a593Smuzhiyun CONFIG_SYS_MONITOR_LEN + CONFIG_SYS_SPL_MALLOC_SIZE +
135*4882a593Smuzhiyun UBOOT_HEAD_LEN);
136*4882a593Smuzhiyun if (off < 0)
137*4882a593Smuzhiyun printf("Failed to reserve memory for SD boot deep sleep: %s\n",
138*4882a593Smuzhiyun fdt_strerror(off));
139*4882a593Smuzhiyun #endif
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun #if defined(CONFIG_FSL_ESDHC)
142*4882a593Smuzhiyun fdt_fixup_esdhc(blob, bd);
143*4882a593Smuzhiyun #endif
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun /*
146*4882a593Smuzhiyun * platform bus clock = system bus clock/2
147*4882a593Smuzhiyun * Here busclk = system bus clock
148*4882a593Smuzhiyun * We are using the platform bus clock as 1588 Timer reference
149*4882a593Smuzhiyun * clock source select
150*4882a593Smuzhiyun */
151*4882a593Smuzhiyun do_fixup_by_compat_u32(blob, "fsl, gianfar-ptp-timer",
152*4882a593Smuzhiyun "timer-frequency", busclk / 2, 1);
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun /*
155*4882a593Smuzhiyun * clock-freq should change to clock-frequency and
156*4882a593Smuzhiyun * flexcan-v1.0 should change to p1010-flexcan respectively
157*4882a593Smuzhiyun * in the future.
158*4882a593Smuzhiyun */
159*4882a593Smuzhiyun do_fixup_by_compat_u32(blob, "fsl, flexcan-v1.0",
160*4882a593Smuzhiyun "clock_freq", busclk / 2, 1);
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun do_fixup_by_compat_u32(blob, "fsl, flexcan-v1.0",
163*4882a593Smuzhiyun "clock-frequency", busclk / 2, 1);
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun do_fixup_by_compat_u32(blob, "fsl, ls1021a-flexcan",
166*4882a593Smuzhiyun "clock-frequency", busclk / 2, 1);
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun #if defined(CONFIG_QSPI_BOOT) || defined(CONFIG_SD_BOOT_QSPI)
169*4882a593Smuzhiyun off = fdt_node_offset_by_compat_reg(blob, FSL_IFC_COMPAT,
170*4882a593Smuzhiyun CONFIG_SYS_IFC_ADDR);
171*4882a593Smuzhiyun fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
172*4882a593Smuzhiyun #else
173*4882a593Smuzhiyun off = fdt_node_offset_by_compat_reg(blob, FSL_QSPI_COMPAT,
174*4882a593Smuzhiyun QSPI0_BASE_ADDR);
175*4882a593Smuzhiyun fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
176*4882a593Smuzhiyun off = fdt_node_offset_by_compat_reg(blob, FSL_DSPI_COMPAT,
177*4882a593Smuzhiyun DSPI1_BASE_ADDR);
178*4882a593Smuzhiyun fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
179*4882a593Smuzhiyun #endif
180*4882a593Smuzhiyun }
181