aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorScott Wood <scottwood@freescale.com>2007-08-20 13:40:02 -0400
committerPaul Mackerras <paulus@samba.org>2007-08-22 01:37:09 -0400
commite5d8d54db25790524da34b0143f4e0176fb7677b (patch)
tree5424562c9dd166eadd10b58d38ea9b3ce1a68ae0 /arch
parent0b195812dfbccc2ac33e17b35b899dd4fea7611f (diff)
[POWERPC] bootwrapper: Add PowerQUICC II (82xx with CPM) cuboot support
This allows booting on legacy, non-device-tree aware versions of U-boot. It also fixes up the hardware to match the PCI and chipselect information in the device tree, as u-boot is inconsistent in setting these up correctly (or at all). Signed-off-by: Scott Wood <scottwood@freescale.com> Acked-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/powerpc/boot/Makefile3
-rw-r--r--arch/powerpc/boot/cuboot-pq2.c283
-rw-r--r--arch/powerpc/boot/devtree.c6
-rw-r--r--arch/powerpc/boot/ops.h9
-rw-r--r--arch/powerpc/platforms/Kconfig1
5 files changed, 298 insertions, 4 deletions
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index 6b9af78b67d4..cd7c05769e41 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -48,7 +48,7 @@ src-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \
48 cpm-serial.c 48 cpm-serial.c
49src-plat := of.c cuboot-83xx.c cuboot-85xx.c holly.c \ 49src-plat := of.c cuboot-83xx.c cuboot-85xx.c holly.c \
50 cuboot-ebony.c treeboot-ebony.c prpmc2800.c \ 50 cuboot-ebony.c treeboot-ebony.c prpmc2800.c \
51 ps3-head.S ps3-hvcall.S ps3.c treeboot-bamboo.c cuboot-8xx.c 51 ps3-head.S ps3-hvcall.S ps3.c treeboot-bamboo.c cuboot-8xx.c cuboot-pq2.c
52src-boot := $(src-wlib) $(src-plat) empty.c 52src-boot := $(src-wlib) $(src-plat) empty.c
53 53
54src-boot := $(addprefix $(obj)/, $(src-boot)) 54src-boot := $(addprefix $(obj)/, $(src-boot))
@@ -141,6 +141,7 @@ image-$(CONFIG_DEFAULT_UIMAGE) += uImage
141 141
142ifneq ($(CONFIG_DEVICE_TREE),"") 142ifneq ($(CONFIG_DEVICE_TREE),"")
143image-$(CONFIG_PPC_8xx) += cuImage.8xx 143image-$(CONFIG_PPC_8xx) += cuImage.8xx
144image-$(CONFIG_8260) += cuImage.pq2
144image-$(CONFIG_PPC_83xx) += cuImage.83xx 145image-$(CONFIG_PPC_83xx) += cuImage.83xx
145image-$(CONFIG_PPC_85xx) += cuImage.85xx 146image-$(CONFIG_PPC_85xx) += cuImage.85xx
146image-$(CONFIG_EBONY) += treeImage.ebony cuImage.ebony 147image-$(CONFIG_EBONY) += treeImage.ebony cuImage.ebony
diff --git a/arch/powerpc/boot/cuboot-pq2.c b/arch/powerpc/boot/cuboot-pq2.c
new file mode 100644
index 000000000000..8021fd4a43bc
--- /dev/null
+++ b/arch/powerpc/boot/cuboot-pq2.c
@@ -0,0 +1,283 @@
1/*
2 * Old U-boot compatibility for PowerQUICC II
3 * (a.k.a. 82xx with CPM, not the 8240 family of chips)
4 *
5 * Author: Scott Wood <scottwood@freescale.com>
6 *
7 * Copyright (c) 2007 Freescale Semiconductor, Inc.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
12 */
13
14#include "ops.h"
15#include "stdio.h"
16#include "cuboot.h"
17#include "io.h"
18
19#define TARGET_CPM2
20#define TARGET_HAS_ETH1
21#include "ppcboot.h"
22
23static bd_t bd;
24
25struct cs_range {
26 u32 csnum;
27 u32 base; /* must be zero */
28 u32 addr;
29 u32 size;
30};
31
32struct pci_range {
33 u32 flags;
34 u32 pci_addr[2];
35 u32 phys_addr;
36 u32 size[2];
37};
38
39struct cs_range cs_ranges_buf[MAX_PROP_LEN / sizeof(struct cs_range)];
40struct pci_range pci_ranges_buf[MAX_PROP_LEN / sizeof(struct pci_range)];
41
42/* Different versions of u-boot put the BCSR in different places, and
43 * some don't set up the PCI PIC at all, so we assume the device tree is
44 * sane and update the BRx registers appropriately.
45 *
46 * For any node defined as compatible with fsl,pq2-chipselect,
47 * #address/#size must be 2/1 for chipselect bus, 1/1 for parent bus,
48 * and ranges must be for whole chip selects.
49 */
50static void update_cs_ranges(void)
51{
52 u32 ctrl_ph;
53 void *ctrl_node, *bus_node, *parent_node;
54 u32 *ctrl_addr;
55 unsigned long ctrl_size;
56 u32 naddr, nsize;
57 int len;
58 int i;
59
60 bus_node = finddevice("/chipselect");
61 if (!bus_node || !dt_is_compatible(bus_node, "fsl,pq2-chipselect"))
62 return;
63
64 dt_get_reg_format(bus_node, &naddr, &nsize);
65 if (naddr != 2 || nsize != 1)
66 goto err;
67
68 parent_node = get_parent(bus_node);
69 if (!parent_node)
70 goto err;
71
72 dt_get_reg_format(parent_node, &naddr, &nsize);
73 if (naddr != 1 || nsize != 1)
74 goto err;
75
76 len = getprop(bus_node, "fsl,ctrl", &ctrl_ph, 4);
77 if (len != 4)
78 goto err;
79
80 ctrl_node = find_node_by_prop_value(NULL, "linux,phandle",
81 (char *)&ctrl_ph, 4);
82 if (!ctrl_node)
83 goto err;
84
85 if (!dt_is_compatible(ctrl_node, "fsl,pq2-chipselect-ctrl"))
86 goto err;
87
88 if (!dt_xlate_reg(ctrl_node, 0, (unsigned long *)&ctrl_addr,
89 &ctrl_size))
90 goto err;
91
92 len = getprop(bus_node, "ranges", cs_ranges_buf, sizeof(cs_ranges_buf));
93
94 for (i = 0; i < len / sizeof(struct cs_range); i++) {
95 u32 base, option;
96 int cs = cs_ranges_buf[i].csnum;
97 if (cs >= ctrl_size / 8)
98 goto err;
99
100 if (cs_ranges_buf[i].base != 0)
101 goto err;
102
103 base = in_be32(&ctrl_addr[cs * 2]);
104
105 /* If CS is already valid, use the existing flags.
106 * Otherwise, guess a sane default.
107 */
108 if (base & 1) {
109 base &= 0x7fff;
110 option = in_be32(&ctrl_addr[cs * 2 + 1]) & 0x7fff;
111 } else {
112 base = 0x1801;
113 option = 0x10;
114 }
115
116 out_be32(&ctrl_addr[cs * 2], 0);
117 out_be32(&ctrl_addr[cs * 2 + 1],
118 option | ~(cs_ranges_buf[i].size - 1));
119 out_be32(&ctrl_addr[cs * 2], base | cs_ranges_buf[i].addr);
120 }
121
122 return;
123
124err:
125 printf("Bad /chipselect or fsl,pq2-chipselect-ctrl node\r\n");
126}
127
128/* Older u-boots don't set PCI up properly. Update the hardware to match
129 * the device tree. The prefetch mem region and non-prefetch mem region
130 * must be contiguous in the host bus. As required by the PCI binding,
131 * PCI #addr/#size must be 3/2. The parent bus must be 1/1. Only
132 * 32-bit PCI is supported. All three region types (prefetchable mem,
133 * non-prefetchable mem, and I/O) must be present.
134 */
135static void fixup_pci(void)
136{
137 struct pci_range *mem = NULL, *mmio = NULL,
138 *io = NULL, *mem_base = NULL;
139 u32 *pci_regs[3];
140 u8 *soc_regs;
141 int i, len;
142 void *ctrl_node, *bus_node, *parent_node, *soc_node;
143 u32 naddr, nsize, bus_ph, mem_log2;
144
145 ctrl_node = finddevice("/soc/pci");
146 if (!ctrl_node || !dt_is_compatible(ctrl_node, "fsl,pq2-pci"))
147 return;
148
149 soc_node = finddevice("/soc");
150 if (!soc_node || !dt_is_compatible(soc_node, "fsl,pq2-soc"))
151 goto err;
152
153 for (i = 0; i < 3; i++)
154 if (!dt_xlate_reg(ctrl_node, i,
155 (unsigned long *)&pci_regs[i], NULL))
156 goto err;
157
158 if (!dt_xlate_reg(soc_node, 0, (unsigned long *)&soc_regs, NULL))
159 goto err;
160
161 len = getprop(ctrl_node, "fsl,bus", &bus_ph, 4);
162 if (len != 4)
163 goto err;
164
165 bus_node = find_node_by_prop_value(NULL, "linux,phandle",
166 (char *)&bus_ph, 4);
167 if (!bus_node)
168 goto err;
169
170 dt_get_reg_format(bus_node, &naddr, &nsize);
171 if (naddr != 3 || nsize != 2)
172 goto err;
173
174 parent_node = get_parent(bus_node);
175 if (!parent_node)
176 goto err;
177
178 dt_get_reg_format(parent_node, &naddr, &nsize);
179 if (naddr != 1 || nsize != 1)
180 goto err;
181
182 len = getprop(bus_node, "ranges", pci_ranges_buf,
183 sizeof(pci_ranges_buf));
184
185 for (i = 0; i < len / sizeof(struct pci_range); i++) {
186 u32 flags = pci_ranges_buf[i].flags & 0x43000000;
187
188 if (flags == 0x42000000)
189 mem = &pci_ranges_buf[i];
190 else if (flags == 0x02000000)
191 mmio = &pci_ranges_buf[i];
192 else if (flags == 0x01000000)
193 io = &pci_ranges_buf[i];
194 }
195
196 if (!mem || !mmio || !io)
197 goto err;
198
199 if (mem->phys_addr + mem->size[1] == mmio->phys_addr)
200 mem_base = mem;
201 else if (mmio->phys_addr + mmio->size[1] == mem->phys_addr)
202 mem_base = mmio;
203 else
204 goto err;
205
206 out_be32(&pci_regs[1][0], mem_base->phys_addr | 1);
207 out_be32(&pci_regs[2][0], ~(mem->size[1] + mmio->size[1] - 1));
208
209 out_be32(&pci_regs[1][1], io->phys_addr | 1);
210 out_be32(&pci_regs[2][1], ~(io->size[1] - 1));
211
212 out_le32(&pci_regs[0][0], mem->pci_addr[1] >> 12);
213 out_le32(&pci_regs[0][2], mem->phys_addr >> 12);
214 out_le32(&pci_regs[0][4], (~(mem->size[1] - 1) >> 12) | 0xa0000000);
215
216 out_le32(&pci_regs[0][6], mmio->pci_addr[1] >> 12);
217 out_le32(&pci_regs[0][8], mmio->phys_addr >> 12);
218 out_le32(&pci_regs[0][10], (~(mmio->size[1] - 1) >> 12) | 0x80000000);
219
220 out_le32(&pci_regs[0][12], io->pci_addr[1] >> 12);
221 out_le32(&pci_regs[0][14], io->phys_addr >> 12);
222 out_le32(&pci_regs[0][16], (~(io->size[1] - 1) >> 12) | 0xc0000000);
223
224 /* Inbound translation */
225 out_le32(&pci_regs[0][58], 0);
226 out_le32(&pci_regs[0][60], 0);
227
228 mem_log2 = 1 << (__ilog2_u32(bd.bi_memsize - 1) + 1);
229 out_le32(&pci_regs[0][62], 0xa0000000 | ~((1 << (mem_log2 - 12)) - 1));
230
231 /* If PCI is disabled, drive RST high to enable. */
232 if (!(in_le32(&pci_regs[0][32]) & 1)) {
233 /* Tpvrh (Power valid to RST# high) 100 ms */
234 udelay(100000);
235
236 out_le32(&pci_regs[0][32], 1);
237
238 /* Trhfa (RST# high to first cfg access) 2^25 clocks */
239 udelay(1020000);
240 }
241
242 /* Enable bus master and memory access */
243 out_le32(&pci_regs[0][64], 0x80000004);
244 out_le32(&pci_regs[0][65], in_le32(&pci_regs[0][65]) | 6);
245
246 /* Park the bus on PCI, and elevate PCI's arbitration priority,
247 * as required by section 9.6 of the user's manual.
248 */
249 out_8(&soc_regs[0x10028], 3);
250 out_be32((u32 *)&soc_regs[0x1002c], 0x01236745);
251
252 return;
253
254err:
255 printf("Bad PCI node\r\n");
256}
257
258static void pq2_platform_fixups(void)
259{
260 void *node;
261
262 dt_fixup_memory(bd.bi_memstart, bd.bi_memsize);
263 dt_fixup_mac_addresses(bd.bi_enetaddr, bd.bi_enet1addr);
264 dt_fixup_cpu_clocks(bd.bi_intfreq, bd.bi_busfreq / 4, bd.bi_busfreq);
265
266 node = finddevice("/soc/cpm");
267 if (node) {
268 setprop(node, "clock-frequency", &bd.bi_cpmfreq, 4);
269 setprop(node, "fsl,brg-frequency", &bd.bi_brgfreq, 4);
270 }
271
272 update_cs_ranges();
273 fixup_pci();
274}
275
276void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
277 unsigned long r6, unsigned long r7)
278{
279 CUBOOT_INIT();
280 ft_init(_dtb_start, _dtb_end - _dtb_start, 32);
281 serial_console_init();
282 platform_ops.fixups = pq2_platform_fixups;
283}
diff --git a/arch/powerpc/boot/devtree.c b/arch/powerpc/boot/devtree.c
index 3a18bfe0fdf7..e1b8122b4393 100644
--- a/arch/powerpc/boot/devtree.c
+++ b/arch/powerpc/boot/devtree.c
@@ -114,7 +114,7 @@ void __dt_fixup_mac_addresses(u32 startindex, ...)
114 114
115#define MAX_ADDR_CELLS 4 115#define MAX_ADDR_CELLS 4
116 116
117static void get_reg_format(void *node, u32 *naddr, u32 *nsize) 117void dt_get_reg_format(void *node, u32 *naddr, u32 *nsize)
118{ 118{
119 if (getprop(node, "#address-cells", naddr, 4) != 4) 119 if (getprop(node, "#address-cells", naddr, 4) != 4)
120 *naddr = 2; 120 *naddr = 2;
@@ -224,7 +224,7 @@ static int dt_xlate(void *node, int res, int reglen, unsigned long *addr,
224 if (!parent) 224 if (!parent)
225 return 0; 225 return 0;
226 226
227 get_reg_format(parent, &naddr, &nsize); 227 dt_get_reg_format(parent, &naddr, &nsize);
228 228
229 if (nsize > 2) 229 if (nsize > 2)
230 return 0; 230 return 0;
@@ -252,7 +252,7 @@ static int dt_xlate(void *node, int res, int reglen, unsigned long *addr,
252 if (!parent) 252 if (!parent)
253 break; 253 break;
254 254
255 get_reg_format(parent, &naddr, &nsize); 255 dt_get_reg_format(parent, &naddr, &nsize);
256 256
257 buflen = getprop(node, "ranges", prop_buf, 257 buflen = getprop(node, "ranges", prop_buf,
258 sizeof(prop_buf)); 258 sizeof(prop_buf));
diff --git a/arch/powerpc/boot/ops.h b/arch/powerpc/boot/ops.h
index e4b6139d2d6e..45c2268d5c56 100644
--- a/arch/powerpc/boot/ops.h
+++ b/arch/powerpc/boot/ops.h
@@ -89,6 +89,7 @@ extern void flush_cache(void *, unsigned long);
89int dt_xlate_reg(void *node, int res, unsigned long *addr, unsigned long *size); 89int dt_xlate_reg(void *node, int res, unsigned long *addr, unsigned long *size);
90int dt_xlate_addr(void *node, u32 *buf, int buflen, unsigned long *xlated_addr); 90int dt_xlate_addr(void *node, u32 *buf, int buflen, unsigned long *xlated_addr);
91int dt_is_compatible(void *node, const char *compat); 91int dt_is_compatible(void *node, const char *compat);
92void dt_get_reg_format(void *node, u32 *naddr, u32 *nsize);
92 93
93static inline void *finddevice(const char *name) 94static inline void *finddevice(const char *name)
94{ 95{
@@ -206,4 +207,12 @@ extern char _initrd_end[];
206extern char _dtb_start[]; 207extern char _dtb_start[];
207extern char _dtb_end[]; 208extern char _dtb_end[];
208 209
210static inline __attribute__((const))
211int __ilog2_u32(u32 n)
212{
213 int bit;
214 asm ("cntlzw %0,%1" : "=r" (bit) : "r" (n));
215 return 31 - bit;
216}
217
209#endif /* _PPC_BOOT_OPS_H_ */ 218#endif /* _PPC_BOOT_OPS_H_ */
diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index 932538a93c2b..2c937fb207fe 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -19,6 +19,7 @@ config EMBEDDED6xx
19config PPC_82xx 19config PPC_82xx
20 bool "Freescale 82xx" 20 bool "Freescale 82xx"
21 depends on 6xx 21 depends on 6xx
22 select WANT_DEVICE_TREE
22 23
23config PPC_83xx 24config PPC_83xx
24 bool "Freescale 83xx" 25 bool "Freescale 83xx"