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