xref: /openbmc/u-boot/arch/powerpc/cpu/mpc83xx/fdt.c (revision a47a12becf66f02a56da91c161e2edb625e9f20c)
1*a47a12beSStefan Roese /*
2*a47a12beSStefan Roese  * Copyright 2007 Freescale Semiconductor, Inc.
3*a47a12beSStefan Roese  *
4*a47a12beSStefan Roese  * (C) Copyright 2000
5*a47a12beSStefan Roese  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6*a47a12beSStefan Roese  *
7*a47a12beSStefan Roese  * See file CREDITS for list of people who contributed to this
8*a47a12beSStefan Roese  * project.
9*a47a12beSStefan Roese  *
10*a47a12beSStefan Roese  * This program is free software; you can redistribute it and/or
11*a47a12beSStefan Roese  * modify it under the terms of the GNU General Public License as
12*a47a12beSStefan Roese  * published by the Free Software Foundation; either version 2 of
13*a47a12beSStefan Roese  * the License, or (at your option) any later version.
14*a47a12beSStefan Roese  *
15*a47a12beSStefan Roese  * This program is distributed in the hope that it will be useful,
16*a47a12beSStefan Roese  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*a47a12beSStefan Roese  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*a47a12beSStefan Roese  * GNU General Public License for more details.
19*a47a12beSStefan Roese  *
20*a47a12beSStefan Roese  * You should have received a copy of the GNU General Public License
21*a47a12beSStefan Roese  * along with this program; if not, write to the Free Software
22*a47a12beSStefan Roese  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23*a47a12beSStefan Roese  * MA 02111-1307 USA
24*a47a12beSStefan Roese  */
25*a47a12beSStefan Roese 
26*a47a12beSStefan Roese #include <common.h>
27*a47a12beSStefan Roese #include <libfdt.h>
28*a47a12beSStefan Roese #include <fdt_support.h>
29*a47a12beSStefan Roese #include <asm/processor.h>
30*a47a12beSStefan Roese 
31*a47a12beSStefan Roese extern void ft_qe_setup(void *blob);
32*a47a12beSStefan Roese 
33*a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR;
34*a47a12beSStefan Roese 
35*a47a12beSStefan Roese #if defined(CONFIG_BOOTCOUNT_LIMIT) && defined(CONFIG_MPC8360)
36*a47a12beSStefan Roese #include <asm/immap_qe.h>
37*a47a12beSStefan Roese 
38*a47a12beSStefan Roese void fdt_fixup_muram (void *blob)
39*a47a12beSStefan Roese {
40*a47a12beSStefan Roese 	ulong data[2];
41*a47a12beSStefan Roese 
42*a47a12beSStefan Roese 	data[0] = 0;
43*a47a12beSStefan Roese 	data[1] = QE_MURAM_SIZE - 2 * sizeof(unsigned long);
44*a47a12beSStefan Roese 	do_fixup_by_compat(blob, "fsl,qe-muram-data", "reg",
45*a47a12beSStefan Roese 			data, sizeof (data), 0);
46*a47a12beSStefan Roese }
47*a47a12beSStefan Roese #endif
48*a47a12beSStefan Roese 
49*a47a12beSStefan Roese void ft_cpu_setup(void *blob, bd_t *bd)
50*a47a12beSStefan Roese {
51*a47a12beSStefan Roese 	immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
52*a47a12beSStefan Roese 	int spridr = immr->sysconf.spridr;
53*a47a12beSStefan Roese 
54*a47a12beSStefan Roese 	/*
55*a47a12beSStefan Roese 	 * delete crypto node if not on an E-processor
56*a47a12beSStefan Roese 	 * initial revisions of the MPC834xE/6xE have the original SEC 2.0.
57*a47a12beSStefan Roese 	 * EA revisions got the SEC uprevved to 2.4 but since the default device
58*a47a12beSStefan Roese 	 * tree contains SEC 2.0 properties we uprev them here.
59*a47a12beSStefan Roese 	 */
60*a47a12beSStefan Roese 	if (!IS_E_PROCESSOR(spridr))
61*a47a12beSStefan Roese 		fdt_fixup_crypto_node(blob, 0);
62*a47a12beSStefan Roese 	else if (IS_E_PROCESSOR(spridr) &&
63*a47a12beSStefan Roese 		 (SPR_FAMILY(spridr) == SPR_834X_FAMILY ||
64*a47a12beSStefan Roese 		  SPR_FAMILY(spridr) == SPR_836X_FAMILY) &&
65*a47a12beSStefan Roese 		 REVID_MAJOR(spridr) >= 2)
66*a47a12beSStefan Roese 		fdt_fixup_crypto_node(blob, 0x0204);
67*a47a12beSStefan Roese 
68*a47a12beSStefan Roese #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\
69*a47a12beSStefan Roese     defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3) ||\
70*a47a12beSStefan Roese     defined(CONFIG_HAS_ETH4) || defined(CONFIG_HAS_ETH5)
71*a47a12beSStefan Roese 	fdt_fixup_ethernet(blob);
72*a47a12beSStefan Roese #ifdef CONFIG_MPC8313
73*a47a12beSStefan Roese 	/*
74*a47a12beSStefan Roese 	* mpc8313e erratum IPIC1 swapped TSEC interrupt ID numbers on rev. 1
75*a47a12beSStefan Roese 	* h/w (see AN3545).  The base device tree in use has rev. 1 ID numbers,
76*a47a12beSStefan Roese 	* so if on Rev. 2 (and higher) h/w, we fix them up here
77*a47a12beSStefan Roese 	*/
78*a47a12beSStefan Roese 	if (REVID_MAJOR(immr->sysconf.spridr) >= 2) {
79*a47a12beSStefan Roese 		int nodeoffset, path;
80*a47a12beSStefan Roese 		const char *prop;
81*a47a12beSStefan Roese 
82*a47a12beSStefan Roese 		nodeoffset = fdt_path_offset(blob, "/aliases");
83*a47a12beSStefan Roese 		if (nodeoffset >= 0) {
84*a47a12beSStefan Roese #if defined(CONFIG_HAS_ETH0)
85*a47a12beSStefan Roese 			prop = fdt_getprop(blob, nodeoffset, "ethernet0", NULL);
86*a47a12beSStefan Roese 			if (prop) {
87*a47a12beSStefan Roese 				u32 tmp[] = { 32, 0x8, 33, 0x8, 34, 0x8 };
88*a47a12beSStefan Roese 
89*a47a12beSStefan Roese 				path = fdt_path_offset(blob, prop);
90*a47a12beSStefan Roese 				prop = fdt_getprop(blob, path, "interrupts", 0);
91*a47a12beSStefan Roese 				if (prop)
92*a47a12beSStefan Roese 					fdt_setprop(blob, path, "interrupts",
93*a47a12beSStefan Roese 						    &tmp, sizeof(tmp));
94*a47a12beSStefan Roese 			}
95*a47a12beSStefan Roese #endif
96*a47a12beSStefan Roese #if defined(CONFIG_HAS_ETH1)
97*a47a12beSStefan Roese 			prop = fdt_getprop(blob, nodeoffset, "ethernet1", NULL);
98*a47a12beSStefan Roese 			if (prop) {
99*a47a12beSStefan Roese 				u32 tmp[] = { 35, 0x8, 36, 0x8, 37, 0x8 };
100*a47a12beSStefan Roese 
101*a47a12beSStefan Roese 				path = fdt_path_offset(blob, prop);
102*a47a12beSStefan Roese 				prop = fdt_getprop(blob, path, "interrupts", 0);
103*a47a12beSStefan Roese 				if (prop)
104*a47a12beSStefan Roese 					fdt_setprop(blob, path, "interrupts",
105*a47a12beSStefan Roese 						    &tmp, sizeof(tmp));
106*a47a12beSStefan Roese 			}
107*a47a12beSStefan Roese #endif
108*a47a12beSStefan Roese 		}
109*a47a12beSStefan Roese 	}
110*a47a12beSStefan Roese #endif
111*a47a12beSStefan Roese #endif
112*a47a12beSStefan Roese 
113*a47a12beSStefan Roese 	do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
114*a47a12beSStefan Roese 		"timebase-frequency", (bd->bi_busfreq / 4), 1);
115*a47a12beSStefan Roese 	do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
116*a47a12beSStefan Roese 		"bus-frequency", bd->bi_busfreq, 1);
117*a47a12beSStefan Roese 	do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
118*a47a12beSStefan Roese 		"clock-frequency", gd->core_clk, 1);
119*a47a12beSStefan Roese 	do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
120*a47a12beSStefan Roese 		"bus-frequency", bd->bi_busfreq, 1);
121*a47a12beSStefan Roese 	do_fixup_by_compat_u32(blob, "fsl,soc",
122*a47a12beSStefan Roese 		"bus-frequency", bd->bi_busfreq, 1);
123*a47a12beSStefan Roese 	do_fixup_by_compat_u32(blob, "fsl,soc",
124*a47a12beSStefan Roese 		"clock-frequency", bd->bi_busfreq, 1);
125*a47a12beSStefan Roese 	do_fixup_by_compat_u32(blob, "fsl,immr",
126*a47a12beSStefan Roese 		"bus-frequency", bd->bi_busfreq, 1);
127*a47a12beSStefan Roese 	do_fixup_by_compat_u32(blob, "fsl,immr",
128*a47a12beSStefan Roese 		"clock-frequency", bd->bi_busfreq, 1);
129*a47a12beSStefan Roese #ifdef CONFIG_QE
130*a47a12beSStefan Roese 	ft_qe_setup(blob);
131*a47a12beSStefan Roese #endif
132*a47a12beSStefan Roese 
133*a47a12beSStefan Roese #ifdef CONFIG_SYS_NS16550
134*a47a12beSStefan Roese 	do_fixup_by_compat_u32(blob, "ns16550",
135*a47a12beSStefan Roese 		"clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
136*a47a12beSStefan Roese #endif
137*a47a12beSStefan Roese 
138*a47a12beSStefan Roese 	fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
139*a47a12beSStefan Roese 
140*a47a12beSStefan Roese #if defined(CONFIG_BOOTCOUNT_LIMIT)
141*a47a12beSStefan Roese 	fdt_fixup_muram (blob);
142*a47a12beSStefan Roese #endif
143*a47a12beSStefan Roese }
144