[POWERPC] chrp: Constify & voidify get_property()
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / powerpc / platforms / maple / setup.c
CommitLineData
1da177e4 1/*
0cb7b2af 2 * Maple (970 eval board) setup code
1da177e4
LT
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
980a6513 14#undef DEBUG
1da177e4 15
1da177e4
LT
16#include <linux/init.h>
17#include <linux/errno.h>
18#include <linux/sched.h>
19#include <linux/kernel.h>
20#include <linux/mm.h>
21#include <linux/stddef.h>
22#include <linux/unistd.h>
23#include <linux/ptrace.h>
24#include <linux/slab.h>
25#include <linux/user.h>
26#include <linux/a.out.h>
27#include <linux/tty.h>
28#include <linux/string.h>
29#include <linux/delay.h>
30#include <linux/ioport.h>
31#include <linux/major.h>
32#include <linux/initrd.h>
33#include <linux/vt_kern.h>
34#include <linux/console.h>
35#include <linux/ide.h>
36#include <linux/pci.h>
37#include <linux/adb.h>
38#include <linux/cuda.h>
39#include <linux/pmu.h>
40#include <linux/irq.h>
41#include <linux/seq_file.h>
42#include <linux/root_dev.h>
43#include <linux/serial.h>
44#include <linux/smp.h>
45
46#include <asm/processor.h>
47#include <asm/sections.h>
48#include <asm/prom.h>
49#include <asm/system.h>
50#include <asm/pgtable.h>
51#include <asm/bitops.h>
52#include <asm/io.h>
3d1229d6 53#include <asm/kexec.h>
1da177e4
LT
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>
bbeb3f4c 62#include <asm/mpic.h>
40ef8cbc 63#include <asm/udbg.h>
1da177e4 64
0cb7b2af
PM
65#include "maple.h"
66
1da177e4
LT
67#ifdef DEBUG
68#define DBG(fmt...) udbg_printf(fmt)
69#else
70#define DBG(fmt...)
71#endif
72
4c882b01
BH
73static unsigned long maple_find_nvram_base(void)
74{
75 struct device_node *rtcs;
76 unsigned long result = 0;
77
78 /* find NVRAM device */
79 rtcs = of_find_compatible_node(NULL, "nvram", "AMD8111");
80 if (rtcs) {
81 struct resource r;
82 if (of_address_to_resource(rtcs, 0, &r)) {
83 printk(KERN_EMERG "Maple: Unable to translate NVRAM"
84 " address\n");
85 goto bail;
86 }
87 if (!(r.flags & IORESOURCE_IO)) {
88 printk(KERN_EMERG "Maple: NVRAM address isn't PIO!\n");
89 goto bail;
90 }
91 result = r.start;
92 } else
93 printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
94 bail:
95 of_node_put(rtcs);
96 return result;
97}
98
1da177e4
LT
99static void maple_restart(char *cmd)
100{
d7152fe1
DG
101 unsigned int maple_nvram_base;
102 unsigned int maple_nvram_offset;
103 unsigned int maple_nvram_command;
4c882b01 104 struct device_node *sp;
d7152fe1 105
4c882b01
BH
106 maple_nvram_base = maple_find_nvram_base();
107 if (maple_nvram_base == 0)
108 goto fail;
d7152fe1
DG
109
110 /* find service processor device */
4c882b01
BH
111 sp = of_find_node_by_name(NULL, "service-processor");
112 if (!sp) {
d7152fe1 113 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
4c882b01 114 goto fail;
d7152fe1 115 }
4c882b01 116 maple_nvram_offset = *(unsigned int*) get_property(sp,
d7152fe1 117 "restart-addr", NULL);
4c882b01 118 maple_nvram_command = *(unsigned int*) get_property(sp,
d7152fe1 119 "restart-value", NULL);
4c882b01 120 of_node_put(sp);
d7152fe1
DG
121
122 /* send command */
123 outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
124 for (;;) ;
4c882b01
BH
125 fail:
126 printk(KERN_EMERG "Maple: Manual Restart Required\n");
1da177e4
LT
127}
128
129static void maple_power_off(void)
130{
d7152fe1
DG
131 unsigned int maple_nvram_base;
132 unsigned int maple_nvram_offset;
133 unsigned int maple_nvram_command;
4c882b01 134 struct device_node *sp;
d7152fe1 135
4c882b01
BH
136 maple_nvram_base = maple_find_nvram_base();
137 if (maple_nvram_base == 0)
138 goto fail;
d7152fe1
DG
139
140 /* find service processor device */
4c882b01
BH
141 sp = of_find_node_by_name(NULL, "service-processor");
142 if (!sp) {
d7152fe1 143 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
4c882b01 144 goto fail;
d7152fe1 145 }
4c882b01 146 maple_nvram_offset = *(unsigned int*) get_property(sp,
d7152fe1 147 "power-off-addr", NULL);
4c882b01 148 maple_nvram_command = *(unsigned int*) get_property(sp,
d7152fe1 149 "power-off-value", NULL);
4c882b01 150 of_node_put(sp);
d7152fe1
DG
151
152 /* send command */
153 outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
154 for (;;) ;
4c882b01
BH
155 fail:
156 printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
1da177e4
LT
157}
158
159static void maple_halt(void)
160{
d7152fe1 161 maple_power_off();
1da177e4
LT
162}
163
164#ifdef CONFIG_SMP
165struct smp_ops_t maple_smp_ops = {
166 .probe = smp_mpic_probe,
167 .message_pass = smp_mpic_message_pass,
168 .kick_cpu = smp_generic_kick_cpu,
169 .setup_cpu = smp_mpic_setup_cpu,
170 .give_timebase = smp_generic_give_timebase,
171 .take_timebase = smp_generic_take_timebase,
172};
173#endif /* CONFIG_SMP */
174
175void __init maple_setup_arch(void)
176{
177 /* init to some ~sane value until calibrate_delay() runs */
178 loops_per_jiffy = 50000000;
179
180 /* Setup SMP callback */
181#ifdef CONFIG_SMP
182 smp_ops = &maple_smp_ops;
183#endif
184 /* Lookup PCI hosts */
185 maple_pci_init();
186
187#ifdef CONFIG_DUMMY_CONSOLE
188 conswitchp = &dummy_con;
189#endif
62d60e9f 190
4baaf0cf 191 printk(KERN_DEBUG "Using native/NAP idle loop\n");
1da177e4
LT
192}
193
194/*
195 * Early initialization.
196 */
197static void __init maple_init_early(void)
198{
1da177e4
LT
199 DBG(" -> maple_init_early\n");
200
1beb6a7d 201 iommu_init_early_dart();
1da177e4
LT
202
203 DBG(" <- maple_init_early\n");
204}
205
0ebfff14
BH
206/*
207 * This is almost identical to pSeries and CHRP. We need to make that
208 * code generic at one point, with appropriate bits in the device-tree to
209 * identify the presence of an HT APIC
210 */
211static void __init maple_init_IRQ(void)
1da177e4 212{
0ebfff14 213 struct device_node *root, *np, *mpic_node = NULL;
1da177e4 214 unsigned int *opprop;
0ebfff14
BH
215 unsigned long openpic_addr = 0;
216 int naddr, n, i, opplen, has_isus = 0;
1da177e4 217 struct mpic *mpic;
0ebfff14 218 unsigned int flags = MPIC_PRIMARY;
1da177e4 219
0ebfff14
BH
220 /* Locate MPIC in the device-tree. Note that there is a bug
221 * in Maple device-tree where the type of the controller is
222 * open-pic and not interrupt-controller
223 */
224 for_each_node_by_type(np, "open-pic") {
225 mpic_node = np;
226 break;
227 }
228 if (mpic_node == NULL) {
229 printk(KERN_ERR
230 "Failed to locate the MPIC interrupt controller\n");
231 return;
232 }
1da177e4 233
0ebfff14 234 /* Find address list in /platform-open-pic */
1da177e4 235 root = of_find_node_by_path("/");
0ebfff14
BH
236 naddr = prom_n_addr_cells(root);
237 opprop = (unsigned int *) get_property(root, "platform-open-pic",
238 &opplen);
239 if (opprop != 0) {
240 openpic_addr = of_read_number(opprop, naddr);
241 has_isus = (opplen > naddr);
242 printk(KERN_DEBUG "OpenPIC addr: %lx, has ISUs: %d\n",
243 openpic_addr, has_isus);
244 }
1da177e4
LT
245 of_node_put(root);
246
0ebfff14 247 BUG_ON(openpic_addr == 0);
1da177e4 248
0ebfff14
BH
249 /* Check for a big endian MPIC */
250 if (get_property(np, "big-endian", NULL) != NULL)
251 flags |= MPIC_BIG_ENDIAN;
252
253 /* XXX Maple specific bits */
254 flags |= MPIC_BROKEN_U3 | MPIC_WANTS_RESET;
255
256 /* Setup the openpic driver. More device-tree junks, we hard code no
257 * ISUs for now. I'll have to revisit some stuffs with the folks doing
258 * the firmware for those
259 */
260 mpic = mpic_alloc(mpic_node, openpic_addr, flags,
261 /*has_isus ? 16 :*/ 0, 0, " MPIC ");
1da177e4 262 BUG_ON(mpic == NULL);
1da177e4 263
0ebfff14
BH
264 /* Add ISUs */
265 opplen /= sizeof(u32);
266 for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
267 unsigned long isuaddr = of_read_number(opprop + i, naddr);
268 mpic_assign_isu(mpic, n, isuaddr);
269 }
270
271 /* All ISUs are setup, complete initialization */
272 mpic_init(mpic);
273 ppc_md.get_irq = mpic_get_irq;
274 of_node_put(mpic_node);
275 of_node_put(root);
1da177e4
LT
276}
277
278static void __init maple_progress(char *s, unsigned short hex)
279{
280 printk("*** %04x : %s\n", hex, s ? s : "");
281}
282
283
284/*
285 * Called very early, MMU is off, device-tree isn't unflattened
286 */
e8222502 287static int __init maple_probe(void)
1da177e4 288{
e8222502 289 unsigned long root = of_get_flat_dt_root();
980a6513
BH
290
291 if (!of_flat_dt_is_compatible(root, "Momentum,Maple") &&
292 !of_flat_dt_is_compatible(root, "Momentum,Apache"))
1da177e4
LT
293 return 0;
294 /*
295 * On U3, the DART (iommu) must be allocated now since it
296 * has an impact on htab_initialize (due to the large page it
297 * occupies having to be broken up so the DART itself is not
298 * part of the cacheable linar mapping
299 */
1beb6a7d 300 alloc_dart_table();
1da177e4 301
7d0daae4
ME
302 hpte_init_native();
303
1da177e4
LT
304 return 1;
305}
306
e8222502
BH
307define_machine(maple_md) {
308 .name = "Maple",
1da177e4
LT
309 .probe = maple_probe,
310 .setup_arch = maple_setup_arch,
311 .init_early = maple_init_early,
312 .init_IRQ = maple_init_IRQ,
1da177e4
LT
313 .pcibios_fixup = maple_pcibios_fixup,
314 .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
315 .restart = maple_restart,
316 .power_off = maple_power_off,
317 .halt = maple_halt,
318 .get_boot_time = maple_get_boot_time,
319 .set_rtc_time = maple_set_rtc_time,
320 .get_rtc_time = maple_get_rtc_time,
10f7e7c1 321 .calibrate_decr = generic_calibrate_decr,
1da177e4 322 .progress = maple_progress,
a0652fc9 323 .power_save = power4_idle,
3d1229d6
ME
324#ifdef CONFIG_KEXEC
325 .machine_kexec = default_machine_kexec,
326 .machine_kexec_prepare = default_machine_kexec_prepare,
cc532915 327 .machine_crash_shutdown = default_machine_crash_shutdown,
3d1229d6 328#endif
1da177e4 329};