xref: /openbmc/u-boot/arch/powerpc/cpu/mpc83xx/fdt.c (revision 38d67a4e552ac991f21c2d3e442a38fb0098fda6)
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  *
71a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
8a47a12beSStefan Roese  */
9a47a12beSStefan Roese 
10a47a12beSStefan Roese #include <common.h>
11a47a12beSStefan Roese #include <libfdt.h>
12a47a12beSStefan Roese #include <fdt_support.h>
13a47a12beSStefan Roese #include <asm/processor.h>
14a47a12beSStefan Roese 
15a47a12beSStefan Roese extern void ft_qe_setup(void *blob);
16a47a12beSStefan Roese 
17a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR;
18a47a12beSStefan Roese 
1962ddcf05SHeiko Schocher #if defined(CONFIG_BOOTCOUNT_LIMIT) && \
2099509695SHeiko Schocher 	(defined(CONFIG_QE) && !defined(CONFIG_MPC831x))
21*38d67a4eSZhao Qiang #include <linux/immap_qe.h>
22a47a12beSStefan Roese 
23a47a12beSStefan Roese void fdt_fixup_muram (void *blob)
24a47a12beSStefan Roese {
25a47a12beSStefan Roese 	ulong data[2];
26a47a12beSStefan Roese 
27a47a12beSStefan Roese 	data[0] = 0;
28a47a12beSStefan Roese 	data[1] = QE_MURAM_SIZE - 2 * sizeof(unsigned long);
29a47a12beSStefan Roese 	do_fixup_by_compat(blob, "fsl,qe-muram-data", "reg",
30a47a12beSStefan Roese 			data, sizeof (data), 0);
31a47a12beSStefan Roese }
32a47a12beSStefan Roese #endif
33a47a12beSStefan Roese 
34a47a12beSStefan Roese void ft_cpu_setup(void *blob, bd_t *bd)
35a47a12beSStefan Roese {
36a47a12beSStefan Roese 	immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
37a47a12beSStefan Roese 	int spridr = immr->sysconf.spridr;
38a47a12beSStefan Roese 
39a47a12beSStefan Roese 	/*
40a47a12beSStefan Roese 	 * delete crypto node if not on an E-processor
41a47a12beSStefan Roese 	 * initial revisions of the MPC834xE/6xE have the original SEC 2.0.
42a47a12beSStefan Roese 	 * EA revisions got the SEC uprevved to 2.4 but since the default device
43a47a12beSStefan Roese 	 * tree contains SEC 2.0 properties we uprev them here.
44a47a12beSStefan Roese 	 */
45a47a12beSStefan Roese 	if (!IS_E_PROCESSOR(spridr))
46a47a12beSStefan Roese 		fdt_fixup_crypto_node(blob, 0);
47a47a12beSStefan Roese 	else if (IS_E_PROCESSOR(spridr) &&
48a47a12beSStefan Roese 		 (SPR_FAMILY(spridr) == SPR_834X_FAMILY ||
49a47a12beSStefan Roese 		  SPR_FAMILY(spridr) == SPR_836X_FAMILY) &&
50a47a12beSStefan Roese 		 REVID_MAJOR(spridr) >= 2)
51a47a12beSStefan Roese 		fdt_fixup_crypto_node(blob, 0x0204);
52a47a12beSStefan Roese 
53a47a12beSStefan Roese #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\
54a47a12beSStefan Roese     defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3) ||\
55a47a12beSStefan Roese     defined(CONFIG_HAS_ETH4) || defined(CONFIG_HAS_ETH5)
56a47a12beSStefan Roese 	fdt_fixup_ethernet(blob);
57a47a12beSStefan Roese #ifdef CONFIG_MPC8313
58a47a12beSStefan Roese 	/*
59a47a12beSStefan Roese 	* mpc8313e erratum IPIC1 swapped TSEC interrupt ID numbers on rev. 1
60a47a12beSStefan Roese 	* h/w (see AN3545).  The base device tree in use has rev. 1 ID numbers,
61a47a12beSStefan Roese 	* so if on Rev. 2 (and higher) h/w, we fix them up here
62a47a12beSStefan Roese 	*/
63a47a12beSStefan Roese 	if (REVID_MAJOR(immr->sysconf.spridr) >= 2) {
64a47a12beSStefan Roese 		int nodeoffset, path;
65a47a12beSStefan Roese 		const char *prop;
66a47a12beSStefan Roese 
67a47a12beSStefan Roese 		nodeoffset = fdt_path_offset(blob, "/aliases");
68a47a12beSStefan Roese 		if (nodeoffset >= 0) {
69a47a12beSStefan Roese #if defined(CONFIG_HAS_ETH0)
70a47a12beSStefan Roese 			prop = fdt_getprop(blob, nodeoffset, "ethernet0", NULL);
71a47a12beSStefan Roese 			if (prop) {
72a47a12beSStefan Roese 				u32 tmp[] = { 32, 0x8, 33, 0x8, 34, 0x8 };
73a47a12beSStefan Roese 
74a47a12beSStefan Roese 				path = fdt_path_offset(blob, prop);
75a2873bdeSKim Phillips 				prop = fdt_getprop(blob, path, "interrupts",
76a2873bdeSKim Phillips 						   NULL);
77a47a12beSStefan Roese 				if (prop)
78a47a12beSStefan Roese 					fdt_setprop(blob, path, "interrupts",
79a47a12beSStefan Roese 						    &tmp, sizeof(tmp));
80a47a12beSStefan Roese 			}
81a47a12beSStefan Roese #endif
82a47a12beSStefan Roese #if defined(CONFIG_HAS_ETH1)
83a47a12beSStefan Roese 			prop = fdt_getprop(blob, nodeoffset, "ethernet1", NULL);
84a47a12beSStefan Roese 			if (prop) {
85a47a12beSStefan Roese 				u32 tmp[] = { 35, 0x8, 36, 0x8, 37, 0x8 };
86a47a12beSStefan Roese 
87a47a12beSStefan Roese 				path = fdt_path_offset(blob, prop);
88a2873bdeSKim Phillips 				prop = fdt_getprop(blob, path, "interrupts",
89a2873bdeSKim Phillips 						   NULL);
90a47a12beSStefan Roese 				if (prop)
91a47a12beSStefan Roese 					fdt_setprop(blob, path, "interrupts",
92a47a12beSStefan Roese 						    &tmp, sizeof(tmp));
93a47a12beSStefan Roese 			}
94a47a12beSStefan Roese #endif
95a47a12beSStefan Roese 		}
96a47a12beSStefan Roese 	}
97a47a12beSStefan Roese #endif
98a47a12beSStefan Roese #endif
99a47a12beSStefan Roese 
100a47a12beSStefan Roese 	do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
101a47a12beSStefan Roese 		"timebase-frequency", (bd->bi_busfreq / 4), 1);
102a47a12beSStefan Roese 	do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
103a47a12beSStefan Roese 		"bus-frequency", bd->bi_busfreq, 1);
104a47a12beSStefan Roese 	do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
105c6731fe2SSimon Glass 		"clock-frequency", gd->arch.core_clk, 1);
106a47a12beSStefan Roese 	do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
107a47a12beSStefan Roese 		"bus-frequency", bd->bi_busfreq, 1);
108a47a12beSStefan Roese 	do_fixup_by_compat_u32(blob, "fsl,soc",
109a47a12beSStefan Roese 		"bus-frequency", bd->bi_busfreq, 1);
110a47a12beSStefan Roese 	do_fixup_by_compat_u32(blob, "fsl,soc",
111a47a12beSStefan Roese 		"clock-frequency", bd->bi_busfreq, 1);
112a47a12beSStefan Roese 	do_fixup_by_compat_u32(blob, "fsl,immr",
113a47a12beSStefan Roese 		"bus-frequency", bd->bi_busfreq, 1);
114a47a12beSStefan Roese 	do_fixup_by_compat_u32(blob, "fsl,immr",
115a47a12beSStefan Roese 		"clock-frequency", bd->bi_busfreq, 1);
116a47a12beSStefan Roese #ifdef CONFIG_QE
117a47a12beSStefan Roese 	ft_qe_setup(blob);
118a47a12beSStefan Roese #endif
119a47a12beSStefan Roese 
120a47a12beSStefan Roese #ifdef CONFIG_SYS_NS16550
121a47a12beSStefan Roese 	do_fixup_by_compat_u32(blob, "ns16550",
122a47a12beSStefan Roese 		"clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
123a47a12beSStefan Roese #endif
124a47a12beSStefan Roese 
125a47a12beSStefan Roese 	fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
126a47a12beSStefan Roese 
12799509695SHeiko Schocher #if defined(CONFIG_BOOTCOUNT_LIMIT) && \
12899509695SHeiko Schocher 	(defined(CONFIG_QE) && !defined(CONFIG_MPC831x))
129a47a12beSStefan Roese 	fdt_fixup_muram (blob);
130a47a12beSStefan Roese #endif
131a47a12beSStefan Roese }
132