diff options
author | Paul Mackerras <paulus@samba.org> | 2005-10-29 08:07:56 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2005-10-29 08:07:56 -0400 |
commit | 0cb7b2afd79c5715cbd1d4eee826571fb17fdd65 (patch) | |
tree | 6748e2d741c731aa8afa458152d934b7ad81715c /arch/powerpc/platforms/maple | |
parent | d3f67fbb96b827c1a6a7a82689e589865581155c (diff) |
powerpc: Merge maple support code to arch/powerpc/platforms/maple
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/platforms/maple')
-rw-r--r-- | arch/powerpc/platforms/maple/Makefile | 1 | ||||
-rw-r--r-- | arch/powerpc/platforms/maple/maple.h | 12 | ||||
-rw-r--r-- | arch/powerpc/platforms/maple/pci.c | 522 | ||||
-rw-r--r-- | arch/powerpc/platforms/maple/setup.c | 295 | ||||
-rw-r--r-- | arch/powerpc/platforms/maple/time.c | 180 |
5 files changed, 1010 insertions, 0 deletions
diff --git a/arch/powerpc/platforms/maple/Makefile b/arch/powerpc/platforms/maple/Makefile new file mode 100644 index 000000000000..1be1a993c5f5 --- /dev/null +++ b/arch/powerpc/platforms/maple/Makefile | |||
@@ -0,0 +1 @@ | |||
obj-y += setup.o pci.o time.o | |||
diff --git a/arch/powerpc/platforms/maple/maple.h b/arch/powerpc/platforms/maple/maple.h new file mode 100644 index 000000000000..0657c579b840 --- /dev/null +++ b/arch/powerpc/platforms/maple/maple.h | |||
@@ -0,0 +1,12 @@ | |||
1 | /* | ||
2 | * Declarations for maple-specific code. | ||
3 | * | ||
4 | * Maple is the name of a PPC970 evaluation board. | ||
5 | */ | ||
6 | extern int maple_set_rtc_time(struct rtc_time *tm); | ||
7 | extern void maple_get_rtc_time(struct rtc_time *tm); | ||
8 | extern unsigned long maple_get_boot_time(void); | ||
9 | extern void maple_calibrate_decr(void); | ||
10 | extern void maple_pci_init(void); | ||
11 | extern void maple_pcibios_fixup(void); | ||
12 | extern int maple_pci_get_legacy_ide_irq(struct pci_dev *dev, int channel); | ||
diff --git a/arch/powerpc/platforms/maple/pci.c b/arch/powerpc/platforms/maple/pci.c new file mode 100644 index 000000000000..340c21caeae2 --- /dev/null +++ b/arch/powerpc/platforms/maple/pci.c | |||
@@ -0,0 +1,522 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2004 Benjamin Herrenschmuidt (benh@kernel.crashing.org), | ||
3 | * IBM Corp. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU General Public License | ||
7 | * as published by the Free Software Foundation; either version | ||
8 | * 2 of the License, or (at your option) any later version. | ||
9 | */ | ||
10 | |||
11 | #define DEBUG | ||
12 | |||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/pci.h> | ||
15 | #include <linux/delay.h> | ||
16 | #include <linux/string.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/bootmem.h> | ||
19 | |||
20 | #include <asm/sections.h> | ||
21 | #include <asm/io.h> | ||
22 | #include <asm/prom.h> | ||
23 | #include <asm/pci-bridge.h> | ||
24 | #include <asm/machdep.h> | ||
25 | #include <asm/iommu.h> | ||
26 | #include <asm/ppc-pci.h> | ||
27 | |||
28 | #include "maple.h" | ||
29 | |||
30 | #ifdef DEBUG | ||
31 | #define DBG(x...) printk(x) | ||
32 | #else | ||
33 | #define DBG(x...) | ||
34 | #endif | ||
35 | |||
36 | static struct pci_controller *u3_agp, *u3_ht; | ||
37 | |||
38 | static int __init fixup_one_level_bus_range(struct device_node *node, int higher) | ||
39 | { | ||
40 | for (; node != 0;node = node->sibling) { | ||
41 | int * bus_range; | ||
42 | unsigned int *class_code; | ||
43 | int len; | ||
44 | |||
45 | /* For PCI<->PCI bridges or CardBus bridges, we go down */ | ||
46 | class_code = (unsigned int *) get_property(node, "class-code", NULL); | ||
47 | if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI && | ||
48 | (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS)) | ||
49 | continue; | ||
50 | bus_range = (int *) get_property(node, "bus-range", &len); | ||
51 | if (bus_range != NULL && len > 2 * sizeof(int)) { | ||
52 | if (bus_range[1] > higher) | ||
53 | higher = bus_range[1]; | ||
54 | } | ||
55 | higher = fixup_one_level_bus_range(node->child, higher); | ||
56 | } | ||
57 | return higher; | ||
58 | } | ||
59 | |||
60 | /* This routine fixes the "bus-range" property of all bridges in the | ||
61 | * system since they tend to have their "last" member wrong on macs | ||
62 | * | ||
63 | * Note that the bus numbers manipulated here are OF bus numbers, they | ||
64 | * are not Linux bus numbers. | ||
65 | */ | ||
66 | static void __init fixup_bus_range(struct device_node *bridge) | ||
67 | { | ||
68 | int * bus_range; | ||
69 | int len; | ||
70 | |||
71 | /* Lookup the "bus-range" property for the hose */ | ||
72 | bus_range = (int *) get_property(bridge, "bus-range", &len); | ||
73 | if (bus_range == NULL || len < 2 * sizeof(int)) { | ||
74 | printk(KERN_WARNING "Can't get bus-range for %s\n", | ||
75 | bridge->full_name); | ||
76 | return; | ||
77 | } | ||
78 | bus_range[1] = fixup_one_level_bus_range(bridge->child, bus_range[1]); | ||
79 | } | ||
80 | |||
81 | |||
82 | #define U3_AGP_CFA0(devfn, off) \ | ||
83 | ((1 << (unsigned long)PCI_SLOT(dev_fn)) \ | ||
84 | | (((unsigned long)PCI_FUNC(dev_fn)) << 8) \ | ||
85 | | (((unsigned long)(off)) & 0xFCUL)) | ||
86 | |||
87 | #define U3_AGP_CFA1(bus, devfn, off) \ | ||
88 | ((((unsigned long)(bus)) << 16) \ | ||
89 | |(((unsigned long)(devfn)) << 8) \ | ||
90 | |(((unsigned long)(off)) & 0xFCUL) \ | ||
91 | |1UL) | ||
92 | |||
93 | static unsigned long u3_agp_cfg_access(struct pci_controller* hose, | ||
94 | u8 bus, u8 dev_fn, u8 offset) | ||
95 | { | ||
96 | unsigned int caddr; | ||
97 | |||
98 | if (bus == hose->first_busno) { | ||
99 | if (dev_fn < (11 << 3)) | ||
100 | return 0; | ||
101 | caddr = U3_AGP_CFA0(dev_fn, offset); | ||
102 | } else | ||
103 | caddr = U3_AGP_CFA1(bus, dev_fn, offset); | ||
104 | |||
105 | /* Uninorth will return garbage if we don't read back the value ! */ | ||
106 | do { | ||
107 | out_le32(hose->cfg_addr, caddr); | ||
108 | } while (in_le32(hose->cfg_addr) != caddr); | ||
109 | |||
110 | offset &= 0x07; | ||
111 | return ((unsigned long)hose->cfg_data) + offset; | ||
112 | } | ||
113 | |||
114 | static int u3_agp_read_config(struct pci_bus *bus, unsigned int devfn, | ||
115 | int offset, int len, u32 *val) | ||
116 | { | ||
117 | struct pci_controller *hose; | ||
118 | unsigned long addr; | ||
119 | |||
120 | hose = pci_bus_to_host(bus); | ||
121 | if (hose == NULL) | ||
122 | return PCIBIOS_DEVICE_NOT_FOUND; | ||
123 | |||
124 | addr = u3_agp_cfg_access(hose, bus->number, devfn, offset); | ||
125 | if (!addr) | ||
126 | return PCIBIOS_DEVICE_NOT_FOUND; | ||
127 | /* | ||
128 | * Note: the caller has already checked that offset is | ||
129 | * suitably aligned and that len is 1, 2 or 4. | ||
130 | */ | ||
131 | switch (len) { | ||
132 | case 1: | ||
133 | *val = in_8((u8 *)addr); | ||
134 | break; | ||
135 | case 2: | ||
136 | *val = in_le16((u16 *)addr); | ||
137 | break; | ||
138 | default: | ||
139 | *val = in_le32((u32 *)addr); | ||
140 | break; | ||
141 | } | ||
142 | return PCIBIOS_SUCCESSFUL; | ||
143 | } | ||
144 | |||
145 | static int u3_agp_write_config(struct pci_bus *bus, unsigned int devfn, | ||
146 | int offset, int len, u32 val) | ||
147 | { | ||
148 | struct pci_controller *hose; | ||
149 | unsigned long addr; | ||
150 | |||
151 | hose = pci_bus_to_host(bus); | ||
152 | if (hose == NULL) | ||
153 | return PCIBIOS_DEVICE_NOT_FOUND; | ||
154 | |||
155 | addr = u3_agp_cfg_access(hose, bus->number, devfn, offset); | ||
156 | if (!addr) | ||
157 | return PCIBIOS_DEVICE_NOT_FOUND; | ||
158 | /* | ||
159 | * Note: the caller has already checked that offset is | ||
160 | * suitably aligned and that len is 1, 2 or 4. | ||
161 | */ | ||
162 | switch (len) { | ||
163 | case 1: | ||
164 | out_8((u8 *)addr, val); | ||
165 | (void) in_8((u8 *)addr); | ||
166 | break; | ||
167 | case 2: | ||
168 | out_le16((u16 *)addr, val); | ||
169 | (void) in_le16((u16 *)addr); | ||
170 | break; | ||
171 | default: | ||
172 | out_le32((u32 *)addr, val); | ||
173 | (void) in_le32((u32 *)addr); | ||
174 | break; | ||
175 | } | ||
176 | return PCIBIOS_SUCCESSFUL; | ||
177 | } | ||
178 | |||
179 | static struct pci_ops u3_agp_pci_ops = | ||
180 | { | ||
181 | u3_agp_read_config, | ||
182 | u3_agp_write_config | ||
183 | }; | ||
184 | |||
185 | |||
186 | #define U3_HT_CFA0(devfn, off) \ | ||
187 | ((((unsigned long)devfn) << 8) | offset) | ||
188 | #define U3_HT_CFA1(bus, devfn, off) \ | ||
189 | (U3_HT_CFA0(devfn, off) \ | ||
190 | + (((unsigned long)bus) << 16) \ | ||
191 | + 0x01000000UL) | ||
192 | |||
193 | static unsigned long u3_ht_cfg_access(struct pci_controller* hose, | ||
194 | u8 bus, u8 devfn, u8 offset) | ||
195 | { | ||
196 | if (bus == hose->first_busno) { | ||
197 | if (PCI_SLOT(devfn) == 0) | ||
198 | return 0; | ||
199 | return ((unsigned long)hose->cfg_data) + U3_HT_CFA0(devfn, offset); | ||
200 | } else | ||
201 | return ((unsigned long)hose->cfg_data) + U3_HT_CFA1(bus, devfn, offset); | ||
202 | } | ||
203 | |||
204 | static int u3_ht_read_config(struct pci_bus *bus, unsigned int devfn, | ||
205 | int offset, int len, u32 *val) | ||
206 | { | ||
207 | struct pci_controller *hose; | ||
208 | unsigned long addr; | ||
209 | |||
210 | hose = pci_bus_to_host(bus); | ||
211 | if (hose == NULL) | ||
212 | return PCIBIOS_DEVICE_NOT_FOUND; | ||
213 | |||
214 | addr = u3_ht_cfg_access(hose, bus->number, devfn, offset); | ||
215 | if (!addr) | ||
216 | return PCIBIOS_DEVICE_NOT_FOUND; | ||
217 | |||
218 | /* | ||
219 | * Note: the caller has already checked that offset is | ||
220 | * suitably aligned and that len is 1, 2 or 4. | ||
221 | */ | ||
222 | switch (len) { | ||
223 | case 1: | ||
224 | *val = in_8((u8 *)addr); | ||
225 | break; | ||
226 | case 2: | ||
227 | *val = in_le16((u16 *)addr); | ||
228 | break; | ||
229 | default: | ||
230 | *val = in_le32((u32 *)addr); | ||
231 | break; | ||
232 | } | ||
233 | return PCIBIOS_SUCCESSFUL; | ||
234 | } | ||
235 | |||
236 | static int u3_ht_write_config(struct pci_bus *bus, unsigned int devfn, | ||
237 | int offset, int len, u32 val) | ||
238 | { | ||
239 | struct pci_controller *hose; | ||
240 | unsigned long addr; | ||
241 | |||
242 | hose = pci_bus_to_host(bus); | ||
243 | if (hose == NULL) | ||
244 | return PCIBIOS_DEVICE_NOT_FOUND; | ||
245 | |||
246 | addr = u3_ht_cfg_access(hose, bus->number, devfn, offset); | ||
247 | if (!addr) | ||
248 | return PCIBIOS_DEVICE_NOT_FOUND; | ||
249 | /* | ||
250 | * Note: the caller has already checked that offset is | ||
251 | * suitably aligned and that len is 1, 2 or 4. | ||
252 | */ | ||
253 | switch (len) { | ||
254 | case 1: | ||
255 | out_8((u8 *)addr, val); | ||
256 | (void) in_8((u8 *)addr); | ||
257 | break; | ||
258 | case 2: | ||
259 | out_le16((u16 *)addr, val); | ||
260 | (void) in_le16((u16 *)addr); | ||
261 | break; | ||
262 | default: | ||
263 | out_le32((u32 *)addr, val); | ||
264 | (void) in_le32((u32 *)addr); | ||
265 | break; | ||
266 | } | ||
267 | return PCIBIOS_SUCCESSFUL; | ||
268 | } | ||
269 | |||
270 | static struct pci_ops u3_ht_pci_ops = | ||
271 | { | ||
272 | u3_ht_read_config, | ||
273 | u3_ht_write_config | ||
274 | }; | ||
275 | |||
276 | static void __init setup_u3_agp(struct pci_controller* hose) | ||
277 | { | ||
278 | /* On G5, we move AGP up to high bus number so we don't need | ||
279 | * to reassign bus numbers for HT. If we ever have P2P bridges | ||
280 | * on AGP, we'll have to move pci_assign_all_buses to the | ||
281 | * pci_controller structure so we enable it for AGP and not for | ||
282 | * HT childs. | ||
283 | * We hard code the address because of the different size of | ||
284 | * the reg address cell, we shall fix that by killing struct | ||
285 | * reg_property and using some accessor functions instead | ||
286 | */ | ||
287 | hose->first_busno = 0xf0; | ||
288 | hose->last_busno = 0xff; | ||
289 | hose->ops = &u3_agp_pci_ops; | ||
290 | hose->cfg_addr = ioremap(0xf0000000 + 0x800000, 0x1000); | ||
291 | hose->cfg_data = ioremap(0xf0000000 + 0xc00000, 0x1000); | ||
292 | |||
293 | u3_agp = hose; | ||
294 | } | ||
295 | |||
296 | static void __init setup_u3_ht(struct pci_controller* hose) | ||
297 | { | ||
298 | hose->ops = &u3_ht_pci_ops; | ||
299 | |||
300 | /* We hard code the address because of the different size of | ||
301 | * the reg address cell, we shall fix that by killing struct | ||
302 | * reg_property and using some accessor functions instead | ||
303 | */ | ||
304 | hose->cfg_data = (volatile unsigned char *)ioremap(0xf2000000, 0x02000000); | ||
305 | |||
306 | hose->first_busno = 0; | ||
307 | hose->last_busno = 0xef; | ||
308 | |||
309 | u3_ht = hose; | ||
310 | } | ||
311 | |||
312 | static int __init add_bridge(struct device_node *dev) | ||
313 | { | ||
314 | int len; | ||
315 | struct pci_controller *hose; | ||
316 | char* disp_name; | ||
317 | int *bus_range; | ||
318 | int primary = 1; | ||
319 | struct property *of_prop; | ||
320 | |||
321 | DBG("Adding PCI host bridge %s\n", dev->full_name); | ||
322 | |||
323 | bus_range = (int *) get_property(dev, "bus-range", &len); | ||
324 | if (bus_range == NULL || len < 2 * sizeof(int)) { | ||
325 | printk(KERN_WARNING "Can't get bus-range for %s, assume bus 0\n", | ||
326 | dev->full_name); | ||
327 | } | ||
328 | |||
329 | hose = alloc_bootmem(sizeof(struct pci_controller)); | ||
330 | if (hose == NULL) | ||
331 | return -ENOMEM; | ||
332 | pci_setup_pci_controller(hose); | ||
333 | |||
334 | hose->arch_data = dev; | ||
335 | hose->first_busno = bus_range ? bus_range[0] : 0; | ||
336 | hose->last_busno = bus_range ? bus_range[1] : 0xff; | ||
337 | |||
338 | of_prop = alloc_bootmem(sizeof(struct property) + | ||
339 | sizeof(hose->global_number)); | ||
340 | if (of_prop) { | ||
341 | memset(of_prop, 0, sizeof(struct property)); | ||
342 | of_prop->name = "linux,pci-domain"; | ||
343 | of_prop->length = sizeof(hose->global_number); | ||
344 | of_prop->value = (unsigned char *)&of_prop[1]; | ||
345 | memcpy(of_prop->value, &hose->global_number, sizeof(hose->global_number)); | ||
346 | prom_add_property(dev, of_prop); | ||
347 | } | ||
348 | |||
349 | disp_name = NULL; | ||
350 | if (device_is_compatible(dev, "u3-agp")) { | ||
351 | setup_u3_agp(hose); | ||
352 | disp_name = "U3-AGP"; | ||
353 | primary = 0; | ||
354 | } else if (device_is_compatible(dev, "u3-ht")) { | ||
355 | setup_u3_ht(hose); | ||
356 | disp_name = "U3-HT"; | ||
357 | primary = 1; | ||
358 | } | ||
359 | printk(KERN_INFO "Found %s PCI host bridge. Firmware bus number: %d->%d\n", | ||
360 | disp_name, hose->first_busno, hose->last_busno); | ||
361 | |||
362 | /* Interpret the "ranges" property */ | ||
363 | /* This also maps the I/O region and sets isa_io/mem_base */ | ||
364 | pci_process_bridge_OF_ranges(hose, dev, primary); | ||
365 | pci_setup_phb_io(hose, primary); | ||
366 | |||
367 | /* Fixup "bus-range" OF property */ | ||
368 | fixup_bus_range(dev); | ||
369 | |||
370 | return 0; | ||
371 | } | ||
372 | |||
373 | |||
374 | void __init maple_pcibios_fixup(void) | ||
375 | { | ||
376 | struct pci_dev *dev = NULL; | ||
377 | |||
378 | DBG(" -> maple_pcibios_fixup\n"); | ||
379 | |||
380 | for_each_pci_dev(dev) | ||
381 | pci_read_irq_line(dev); | ||
382 | |||
383 | /* Do the mapping of the IO space */ | ||
384 | phbs_remap_io(); | ||
385 | |||
386 | DBG(" <- maple_pcibios_fixup\n"); | ||
387 | } | ||
388 | |||
389 | static void __init maple_fixup_phb_resources(void) | ||
390 | { | ||
391 | struct pci_controller *hose, *tmp; | ||
392 | |||
393 | list_for_each_entry_safe(hose, tmp, &hose_list, list_node) { | ||
394 | unsigned long offset = (unsigned long)hose->io_base_virt - pci_io_base; | ||
395 | hose->io_resource.start += offset; | ||
396 | hose->io_resource.end += offset; | ||
397 | printk(KERN_INFO "PCI Host %d, io start: %lx; io end: %lx\n", | ||
398 | hose->global_number, | ||
399 | hose->io_resource.start, hose->io_resource.end); | ||
400 | } | ||
401 | } | ||
402 | |||
403 | void __init maple_pci_init(void) | ||
404 | { | ||
405 | struct device_node *np, *root; | ||
406 | struct device_node *ht = NULL; | ||
407 | |||
408 | /* Probe root PCI hosts, that is on U3 the AGP host and the | ||
409 | * HyperTransport host. That one is actually "kept" around | ||
410 | * and actually added last as it's resource management relies | ||
411 | * on the AGP resources to have been setup first | ||
412 | */ | ||
413 | root = of_find_node_by_path("/"); | ||
414 | if (root == NULL) { | ||
415 | printk(KERN_CRIT "maple_find_bridges: can't find root of device tree\n"); | ||
416 | return; | ||
417 | } | ||
418 | for (np = NULL; (np = of_get_next_child(root, np)) != NULL;) { | ||
419 | if (np->name == NULL) | ||
420 | continue; | ||
421 | if (strcmp(np->name, "pci") == 0) { | ||
422 | if (add_bridge(np) == 0) | ||
423 | of_node_get(np); | ||
424 | } | ||
425 | if (strcmp(np->name, "ht") == 0) { | ||
426 | of_node_get(np); | ||
427 | ht = np; | ||
428 | } | ||
429 | } | ||
430 | of_node_put(root); | ||
431 | |||
432 | /* Now setup the HyperTransport host if we found any | ||
433 | */ | ||
434 | if (ht && add_bridge(ht) != 0) | ||
435 | of_node_put(ht); | ||
436 | |||
437 | /* Fixup the IO resources on our host bridges as the common code | ||
438 | * does it only for childs of the host bridges | ||
439 | */ | ||
440 | maple_fixup_phb_resources(); | ||
441 | |||
442 | /* Setup the linkage between OF nodes and PHBs */ | ||
443 | pci_devs_phb_init(); | ||
444 | |||
445 | /* Fixup the PCI<->OF mapping for U3 AGP due to bus renumbering. We | ||
446 | * assume there is no P2P bridge on the AGP bus, which should be a | ||
447 | * safe assumptions hopefully. | ||
448 | */ | ||
449 | if (u3_agp) { | ||
450 | struct device_node *np = u3_agp->arch_data; | ||
451 | PCI_DN(np)->busno = 0xf0; | ||
452 | for (np = np->child; np; np = np->sibling) | ||
453 | PCI_DN(np)->busno = 0xf0; | ||
454 | } | ||
455 | |||
456 | /* Tell pci.c to use the common resource allocation mecanism */ | ||
457 | pci_probe_only = 0; | ||
458 | |||
459 | /* Allow all IO */ | ||
460 | io_page_mask = -1; | ||
461 | } | ||
462 | |||
463 | int maple_pci_get_legacy_ide_irq(struct pci_dev *pdev, int channel) | ||
464 | { | ||
465 | struct device_node *np; | ||
466 | int irq = channel ? 15 : 14; | ||
467 | |||
468 | if (pdev->vendor != PCI_VENDOR_ID_AMD || | ||
469 | pdev->device != PCI_DEVICE_ID_AMD_8111_IDE) | ||
470 | return irq; | ||
471 | |||
472 | np = pci_device_to_OF_node(pdev); | ||
473 | if (np == NULL) | ||
474 | return irq; | ||
475 | if (np->n_intrs < 2) | ||
476 | return irq; | ||
477 | return np->intrs[channel & 0x1].line; | ||
478 | } | ||
479 | |||
480 | /* XXX: To remove once all firmwares are ok */ | ||
481 | static void fixup_maple_ide(struct pci_dev* dev) | ||
482 | { | ||
483 | #if 0 /* Enable this to enable IDE port 0 */ | ||
484 | { | ||
485 | u8 v; | ||
486 | |||
487 | pci_read_config_byte(dev, 0x40, &v); | ||
488 | v |= 2; | ||
489 | pci_write_config_byte(dev, 0x40, v); | ||
490 | } | ||
491 | #endif | ||
492 | #if 0 /* fix bus master base */ | ||
493 | pci_write_config_dword(dev, 0x20, 0xcc01); | ||
494 | printk("old ide resource: %lx -> %lx \n", | ||
495 | dev->resource[4].start, dev->resource[4].end); | ||
496 | dev->resource[4].start = 0xcc00; | ||
497 | dev->resource[4].end = 0xcc10; | ||
498 | #endif | ||
499 | #if 1 /* Enable this to fixup IDE sense/polarity of irqs in IO-APICs */ | ||
500 | { | ||
501 | struct pci_dev *apicdev; | ||
502 | u32 v; | ||
503 | |||
504 | apicdev = pci_get_slot (dev->bus, PCI_DEVFN(5,0)); | ||
505 | if (apicdev == NULL) | ||
506 | printk("IDE Fixup IRQ: Can't find IO-APIC !\n"); | ||
507 | else { | ||
508 | pci_write_config_byte(apicdev, 0xf2, 0x10 + 2*14); | ||
509 | pci_read_config_dword(apicdev, 0xf4, &v); | ||
510 | v &= ~0x00000022; | ||
511 | pci_write_config_dword(apicdev, 0xf4, v); | ||
512 | pci_write_config_byte(apicdev, 0xf2, 0x10 + 2*15); | ||
513 | pci_read_config_dword(apicdev, 0xf4, &v); | ||
514 | v &= ~0x00000022; | ||
515 | pci_write_config_dword(apicdev, 0xf4, v); | ||
516 | pci_dev_put(apicdev); | ||
517 | } | ||
518 | } | ||
519 | #endif | ||
520 | } | ||
521 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_IDE, | ||
522 | fixup_maple_ide); | ||
diff --git a/arch/powerpc/platforms/maple/setup.c b/arch/powerpc/platforms/maple/setup.c new file mode 100644 index 000000000000..7ece8983a105 --- /dev/null +++ b/arch/powerpc/platforms/maple/setup.c | |||
@@ -0,0 +1,295 @@ | |||
1 | /* | ||
2 | * Maple (970 eval board) setup code | ||
3 | * | ||
4 | * (c) Copyright 2004 Benjamin Herrenschmidt (benh@kernel.crashing.org), | ||
5 | * IBM Corp. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * as published by the Free Software Foundation; either version | ||
10 | * 2 of the License, or (at your option) any later version. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #define DEBUG | ||
15 | |||
16 | #include <linux/config.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/errno.h> | ||
19 | #include <linux/sched.h> | ||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/mm.h> | ||
22 | #include <linux/stddef.h> | ||
23 | #include <linux/unistd.h> | ||
24 | #include <linux/ptrace.h> | ||
25 | #include <linux/slab.h> | ||
26 | #include <linux/user.h> | ||
27 | #include <linux/a.out.h> | ||
28 | #include <linux/tty.h> | ||
29 | #include <linux/string.h> | ||
30 | #include <linux/delay.h> | ||
31 | #include <linux/ioport.h> | ||
32 | #include <linux/major.h> | ||
33 | #include <linux/initrd.h> | ||
34 | #include <linux/vt_kern.h> | ||
35 | #include <linux/console.h> | ||
36 | #include <linux/ide.h> | ||
37 | #include <linux/pci.h> | ||
38 | #include <linux/adb.h> | ||
39 | #include <linux/cuda.h> | ||
40 | #include <linux/pmu.h> | ||
41 | #include <linux/irq.h> | ||
42 | #include <linux/seq_file.h> | ||
43 | #include <linux/root_dev.h> | ||
44 | #include <linux/serial.h> | ||
45 | #include <linux/smp.h> | ||
46 | |||
47 | #include <asm/processor.h> | ||
48 | #include <asm/sections.h> | ||
49 | #include <asm/prom.h> | ||
50 | #include <asm/system.h> | ||
51 | #include <asm/pgtable.h> | ||
52 | #include <asm/bitops.h> | ||
53 | #include <asm/io.h> | ||
54 | #include <asm/pci-bridge.h> | ||
55 | #include <asm/iommu.h> | ||
56 | #include <asm/machdep.h> | ||
57 | #include <asm/dma.h> | ||
58 | #include <asm/cputable.h> | ||
59 | #include <asm/time.h> | ||
60 | #include <asm/of_device.h> | ||
61 | #include <asm/lmb.h> | ||
62 | #include <asm/mpic.h> | ||
63 | #include <asm/udbg.h> | ||
64 | |||
65 | #include "maple.h" | ||
66 | |||
67 | #ifdef DEBUG | ||
68 | #define DBG(fmt...) udbg_printf(fmt) | ||
69 | #else | ||
70 | #define DBG(fmt...) | ||
71 | #endif | ||
72 | |||
73 | extern void generic_find_legacy_serial_ports(u64 *physport, | ||
74 | unsigned int *default_speed); | ||
75 | |||
76 | static void maple_restart(char *cmd) | ||
77 | { | ||
78 | unsigned int maple_nvram_base; | ||
79 | unsigned int maple_nvram_offset; | ||
80 | unsigned int maple_nvram_command; | ||
81 | struct device_node *rtcs; | ||
82 | |||
83 | /* find NVRAM device */ | ||
84 | rtcs = find_compatible_devices("nvram", "AMD8111"); | ||
85 | if (rtcs && rtcs->addrs) { | ||
86 | maple_nvram_base = rtcs->addrs[0].address; | ||
87 | } else { | ||
88 | printk(KERN_EMERG "Maple: Unable to find NVRAM\n"); | ||
89 | printk(KERN_EMERG "Maple: Manual Restart Required\n"); | ||
90 | return; | ||
91 | } | ||
92 | |||
93 | /* find service processor device */ | ||
94 | rtcs = find_devices("service-processor"); | ||
95 | if (!rtcs) { | ||
96 | printk(KERN_EMERG "Maple: Unable to find Service Processor\n"); | ||
97 | printk(KERN_EMERG "Maple: Manual Restart Required\n"); | ||
98 | return; | ||
99 | } | ||
100 | maple_nvram_offset = *(unsigned int*) get_property(rtcs, | ||
101 | "restart-addr", NULL); | ||
102 | maple_nvram_command = *(unsigned int*) get_property(rtcs, | ||
103 | "restart-value", NULL); | ||
104 | |||
105 | /* send command */ | ||
106 | outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset); | ||
107 | for (;;) ; | ||
108 | } | ||
109 | |||
110 | static void maple_power_off(void) | ||
111 | { | ||
112 | unsigned int maple_nvram_base; | ||
113 | unsigned int maple_nvram_offset; | ||
114 | unsigned int maple_nvram_command; | ||
115 | struct device_node *rtcs; | ||
116 | |||
117 | /* find NVRAM device */ | ||
118 | rtcs = find_compatible_devices("nvram", "AMD8111"); | ||
119 | if (rtcs && rtcs->addrs) { | ||
120 | maple_nvram_base = rtcs->addrs[0].address; | ||
121 | } else { | ||
122 | printk(KERN_EMERG "Maple: Unable to find NVRAM\n"); | ||
123 | printk(KERN_EMERG "Maple: Manual Power-Down Required\n"); | ||
124 | return; | ||
125 | } | ||
126 | |||
127 | /* find service processor device */ | ||
128 | rtcs = find_devices("service-processor"); | ||
129 | if (!rtcs) { | ||
130 | printk(KERN_EMERG "Maple: Unable to find Service Processor\n"); | ||
131 | printk(KERN_EMERG "Maple: Manual Power-Down Required\n"); | ||
132 | return; | ||
133 | } | ||
134 | maple_nvram_offset = *(unsigned int*) get_property(rtcs, | ||
135 | "power-off-addr", NULL); | ||
136 | maple_nvram_command = *(unsigned int*) get_property(rtcs, | ||
137 | "power-off-value", NULL); | ||
138 | |||
139 | /* send command */ | ||
140 | outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset); | ||
141 | for (;;) ; | ||
142 | } | ||
143 | |||
144 | static void maple_halt(void) | ||
145 | { | ||
146 | maple_power_off(); | ||
147 | } | ||
148 | |||
149 | #ifdef CONFIG_SMP | ||
150 | struct smp_ops_t maple_smp_ops = { | ||
151 | .probe = smp_mpic_probe, | ||
152 | .message_pass = smp_mpic_message_pass, | ||
153 | .kick_cpu = smp_generic_kick_cpu, | ||
154 | .setup_cpu = smp_mpic_setup_cpu, | ||
155 | .give_timebase = smp_generic_give_timebase, | ||
156 | .take_timebase = smp_generic_take_timebase, | ||
157 | }; | ||
158 | #endif /* CONFIG_SMP */ | ||
159 | |||
160 | void __init maple_setup_arch(void) | ||
161 | { | ||
162 | /* init to some ~sane value until calibrate_delay() runs */ | ||
163 | loops_per_jiffy = 50000000; | ||
164 | |||
165 | /* Setup SMP callback */ | ||
166 | #ifdef CONFIG_SMP | ||
167 | smp_ops = &maple_smp_ops; | ||
168 | #endif | ||
169 | /* Lookup PCI hosts */ | ||
170 | maple_pci_init(); | ||
171 | |||
172 | #ifdef CONFIG_DUMMY_CONSOLE | ||
173 | conswitchp = &dummy_con; | ||
174 | #endif | ||
175 | |||
176 | printk(KERN_INFO "Using native/NAP idle loop\n"); | ||
177 | } | ||
178 | |||
179 | /* | ||
180 | * Early initialization. | ||
181 | */ | ||
182 | static void __init maple_init_early(void) | ||
183 | { | ||
184 | unsigned int default_speed; | ||
185 | u64 physport; | ||
186 | |||
187 | DBG(" -> maple_init_early\n"); | ||
188 | |||
189 | /* Initialize hash table, from now on, we can take hash faults | ||
190 | * and call ioremap | ||
191 | */ | ||
192 | hpte_init_native(); | ||
193 | |||
194 | /* Find the serial port */ | ||
195 | generic_find_legacy_serial_ports(&physport, &default_speed); | ||
196 | |||
197 | DBG("phys port addr: %lx\n", (long)physport); | ||
198 | |||
199 | if (physport) { | ||
200 | void *comport; | ||
201 | /* Map the uart for udbg. */ | ||
202 | comport = (void *)ioremap(physport, 16); | ||
203 | udbg_init_uart(comport, default_speed); | ||
204 | |||
205 | DBG("Hello World !\n"); | ||
206 | } | ||
207 | |||
208 | /* Setup interrupt mapping options */ | ||
209 | ppc64_interrupt_controller = IC_OPEN_PIC; | ||
210 | |||
211 | iommu_init_early_u3(); | ||
212 | |||
213 | DBG(" <- maple_init_early\n"); | ||
214 | } | ||
215 | |||
216 | |||
217 | static __init void maple_init_IRQ(void) | ||
218 | { | ||
219 | struct device_node *root; | ||
220 | unsigned int *opprop; | ||
221 | unsigned long opic_addr; | ||
222 | struct mpic *mpic; | ||
223 | unsigned char senses[128]; | ||
224 | int n; | ||
225 | |||
226 | DBG(" -> maple_init_IRQ\n"); | ||
227 | |||
228 | /* XXX: Non standard, replace that with a proper openpic/mpic node | ||
229 | * in the device-tree. Find the Open PIC if present */ | ||
230 | root = of_find_node_by_path("/"); | ||
231 | opprop = (unsigned int *) get_property(root, | ||
232 | "platform-open-pic", NULL); | ||
233 | if (opprop == 0) | ||
234 | panic("OpenPIC not found !\n"); | ||
235 | |||
236 | n = prom_n_addr_cells(root); | ||
237 | for (opic_addr = 0; n > 0; --n) | ||
238 | opic_addr = (opic_addr << 32) + *opprop++; | ||
239 | of_node_put(root); | ||
240 | |||
241 | /* Obtain sense values from device-tree */ | ||
242 | prom_get_irq_senses(senses, 0, 128); | ||
243 | |||
244 | mpic = mpic_alloc(opic_addr, | ||
245 | MPIC_PRIMARY | MPIC_BIG_ENDIAN | | ||
246 | MPIC_BROKEN_U3 | MPIC_WANTS_RESET, | ||
247 | 0, 0, 128, 128, senses, 128, "U3-MPIC"); | ||
248 | BUG_ON(mpic == NULL); | ||
249 | mpic_init(mpic); | ||
250 | |||
251 | DBG(" <- maple_init_IRQ\n"); | ||
252 | } | ||
253 | |||
254 | static void __init maple_progress(char *s, unsigned short hex) | ||
255 | { | ||
256 | printk("*** %04x : %s\n", hex, s ? s : ""); | ||
257 | } | ||
258 | |||
259 | |||
260 | /* | ||
261 | * Called very early, MMU is off, device-tree isn't unflattened | ||
262 | */ | ||
263 | static int __init maple_probe(int platform) | ||
264 | { | ||
265 | if (platform != PLATFORM_MAPLE) | ||
266 | return 0; | ||
267 | /* | ||
268 | * On U3, the DART (iommu) must be allocated now since it | ||
269 | * has an impact on htab_initialize (due to the large page it | ||
270 | * occupies having to be broken up so the DART itself is not | ||
271 | * part of the cacheable linar mapping | ||
272 | */ | ||
273 | alloc_u3_dart_table(); | ||
274 | |||
275 | return 1; | ||
276 | } | ||
277 | |||
278 | struct machdep_calls __initdata maple_md = { | ||
279 | .probe = maple_probe, | ||
280 | .setup_arch = maple_setup_arch, | ||
281 | .init_early = maple_init_early, | ||
282 | .init_IRQ = maple_init_IRQ, | ||
283 | .get_irq = mpic_get_irq, | ||
284 | .pcibios_fixup = maple_pcibios_fixup, | ||
285 | .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq, | ||
286 | .restart = maple_restart, | ||
287 | .power_off = maple_power_off, | ||
288 | .halt = maple_halt, | ||
289 | .get_boot_time = maple_get_boot_time, | ||
290 | .set_rtc_time = maple_set_rtc_time, | ||
291 | .get_rtc_time = maple_get_rtc_time, | ||
292 | .calibrate_decr = generic_calibrate_decr, | ||
293 | .progress = maple_progress, | ||
294 | .idle_loop = native_idle, | ||
295 | }; | ||
diff --git a/arch/powerpc/platforms/maple/time.c b/arch/powerpc/platforms/maple/time.c new file mode 100644 index 000000000000..40fc07a8e606 --- /dev/null +++ b/arch/powerpc/platforms/maple/time.c | |||
@@ -0,0 +1,180 @@ | |||
1 | /* | ||
2 | * arch/ppc64/kernel/maple_time.c | ||
3 | * | ||
4 | * (c) Copyright 2004 Benjamin Herrenschmidt (benh@kernel.crashing.org), | ||
5 | * IBM Corp. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * as published by the Free Software Foundation; either version | ||
10 | * 2 of the License, or (at your option) any later version. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #undef DEBUG | ||
15 | |||
16 | #include <linux/config.h> | ||
17 | #include <linux/errno.h> | ||
18 | #include <linux/sched.h> | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/param.h> | ||
21 | #include <linux/string.h> | ||
22 | #include <linux/mm.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/time.h> | ||
25 | #include <linux/adb.h> | ||
26 | #include <linux/pmu.h> | ||
27 | #include <linux/interrupt.h> | ||
28 | #include <linux/mc146818rtc.h> | ||
29 | #include <linux/bcd.h> | ||
30 | |||
31 | #include <asm/sections.h> | ||
32 | #include <asm/prom.h> | ||
33 | #include <asm/system.h> | ||
34 | #include <asm/io.h> | ||
35 | #include <asm/pgtable.h> | ||
36 | #include <asm/machdep.h> | ||
37 | #include <asm/time.h> | ||
38 | |||
39 | #include "maple.h" | ||
40 | |||
41 | #ifdef DEBUG | ||
42 | #define DBG(x...) printk(x) | ||
43 | #else | ||
44 | #define DBG(x...) | ||
45 | #endif | ||
46 | |||
47 | extern void GregorianDay(struct rtc_time * tm); | ||
48 | |||
49 | static int maple_rtc_addr; | ||
50 | |||
51 | static int maple_clock_read(int addr) | ||
52 | { | ||
53 | outb_p(addr, maple_rtc_addr); | ||
54 | return inb_p(maple_rtc_addr+1); | ||
55 | } | ||
56 | |||
57 | static void maple_clock_write(unsigned long val, int addr) | ||
58 | { | ||
59 | outb_p(addr, maple_rtc_addr); | ||
60 | outb_p(val, maple_rtc_addr+1); | ||
61 | } | ||
62 | |||
63 | void maple_get_rtc_time(struct rtc_time *tm) | ||
64 | { | ||
65 | int uip, i; | ||
66 | |||
67 | /* The Linux interpretation of the CMOS clock register contents: | ||
68 | * When the Update-In-Progress (UIP) flag goes from 1 to 0, the | ||
69 | * RTC registers show the second which has precisely just started. | ||
70 | * Let's hope other operating systems interpret the RTC the same way. | ||
71 | */ | ||
72 | |||
73 | /* Since the UIP flag is set for about 2.2 ms and the clock | ||
74 | * is typically written with a precision of 1 jiffy, trying | ||
75 | * to obtain a precision better than a few milliseconds is | ||
76 | * an illusion. Only consistency is interesting, this also | ||
77 | * allows to use the routine for /dev/rtc without a potential | ||
78 | * 1 second kernel busy loop triggered by any reader of /dev/rtc. | ||
79 | */ | ||
80 | |||
81 | for (i = 0; i<1000000; i++) { | ||
82 | uip = maple_clock_read(RTC_FREQ_SELECT); | ||
83 | tm->tm_sec = maple_clock_read(RTC_SECONDS); | ||
84 | tm->tm_min = maple_clock_read(RTC_MINUTES); | ||
85 | tm->tm_hour = maple_clock_read(RTC_HOURS); | ||
86 | tm->tm_mday = maple_clock_read(RTC_DAY_OF_MONTH); | ||
87 | tm->tm_mon = maple_clock_read(RTC_MONTH); | ||
88 | tm->tm_year = maple_clock_read(RTC_YEAR); | ||
89 | uip |= maple_clock_read(RTC_FREQ_SELECT); | ||
90 | if ((uip & RTC_UIP)==0) | ||
91 | break; | ||
92 | } | ||
93 | |||
94 | if (!(maple_clock_read(RTC_CONTROL) & RTC_DM_BINARY) | ||
95 | || RTC_ALWAYS_BCD) { | ||
96 | BCD_TO_BIN(tm->tm_sec); | ||
97 | BCD_TO_BIN(tm->tm_min); | ||
98 | BCD_TO_BIN(tm->tm_hour); | ||
99 | BCD_TO_BIN(tm->tm_mday); | ||
100 | BCD_TO_BIN(tm->tm_mon); | ||
101 | BCD_TO_BIN(tm->tm_year); | ||
102 | } | ||
103 | if ((tm->tm_year + 1900) < 1970) | ||
104 | tm->tm_year += 100; | ||
105 | |||
106 | GregorianDay(tm); | ||
107 | } | ||
108 | |||
109 | int maple_set_rtc_time(struct rtc_time *tm) | ||
110 | { | ||
111 | unsigned char save_control, save_freq_select; | ||
112 | int sec, min, hour, mon, mday, year; | ||
113 | |||
114 | spin_lock(&rtc_lock); | ||
115 | |||
116 | save_control = maple_clock_read(RTC_CONTROL); /* tell the clock it's being set */ | ||
117 | |||
118 | maple_clock_write((save_control|RTC_SET), RTC_CONTROL); | ||
119 | |||
120 | save_freq_select = maple_clock_read(RTC_FREQ_SELECT); /* stop and reset prescaler */ | ||
121 | |||
122 | maple_clock_write((save_freq_select|RTC_DIV_RESET2), RTC_FREQ_SELECT); | ||
123 | |||
124 | sec = tm->tm_sec; | ||
125 | min = tm->tm_min; | ||
126 | hour = tm->tm_hour; | ||
127 | mon = tm->tm_mon; | ||
128 | mday = tm->tm_mday; | ||
129 | year = tm->tm_year; | ||
130 | |||
131 | if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { | ||
132 | BIN_TO_BCD(sec); | ||
133 | BIN_TO_BCD(min); | ||
134 | BIN_TO_BCD(hour); | ||
135 | BIN_TO_BCD(mon); | ||
136 | BIN_TO_BCD(mday); | ||
137 | BIN_TO_BCD(year); | ||
138 | } | ||
139 | maple_clock_write(sec, RTC_SECONDS); | ||
140 | maple_clock_write(min, RTC_MINUTES); | ||
141 | maple_clock_write(hour, RTC_HOURS); | ||
142 | maple_clock_write(mon, RTC_MONTH); | ||
143 | maple_clock_write(mday, RTC_DAY_OF_MONTH); | ||
144 | maple_clock_write(year, RTC_YEAR); | ||
145 | |||
146 | /* The following flags have to be released exactly in this order, | ||
147 | * otherwise the DS12887 (popular MC146818A clone with integrated | ||
148 | * battery and quartz) will not reset the oscillator and will not | ||
149 | * update precisely 500 ms later. You won't find this mentioned in | ||
150 | * the Dallas Semiconductor data sheets, but who believes data | ||
151 | * sheets anyway ... -- Markus Kuhn | ||
152 | */ | ||
153 | maple_clock_write(save_control, RTC_CONTROL); | ||
154 | maple_clock_write(save_freq_select, RTC_FREQ_SELECT); | ||
155 | |||
156 | spin_unlock(&rtc_lock); | ||
157 | |||
158 | return 0; | ||
159 | } | ||
160 | |||
161 | unsigned long __init maple_get_boot_time(void) | ||
162 | { | ||
163 | struct rtc_time tm; | ||
164 | struct device_node *rtcs; | ||
165 | |||
166 | rtcs = find_compatible_devices("rtc", "pnpPNP,b00"); | ||
167 | if (rtcs && rtcs->addrs) { | ||
168 | maple_rtc_addr = rtcs->addrs[0].address; | ||
169 | printk(KERN_INFO "Maple: Found RTC at 0x%x\n", maple_rtc_addr); | ||
170 | } else { | ||
171 | maple_rtc_addr = RTC_PORT(0); /* legacy address */ | ||
172 | printk(KERN_INFO "Maple: No device node for RTC, assuming " | ||
173 | "legacy address (0x%x)\n", maple_rtc_addr); | ||
174 | } | ||
175 | |||
176 | maple_get_rtc_time(&tm); | ||
177 | return mktime(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, | ||
178 | tm.tm_hour, tm.tm_min, tm.tm_sec); | ||
179 | } | ||
180 | |||