aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/platforms
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/platforms')
-rw-r--r--arch/powerpc/platforms/Kconfig.cputype2
-rw-r--r--arch/powerpc/platforms/embedded6xx/Kconfig33
-rw-r--r--arch/powerpc/platforms/embedded6xx/Makefile4
-rw-r--r--arch/powerpc/platforms/embedded6xx/flipper-pic.c263
-rw-r--r--arch/powerpc/platforms/embedded6xx/flipper-pic.h25
-rw-r--r--arch/powerpc/platforms/embedded6xx/gamecube.c118
-rw-r--r--arch/powerpc/platforms/embedded6xx/hlwd-pic.c241
-rw-r--r--arch/powerpc/platforms/embedded6xx/hlwd-pic.h22
-rw-r--r--arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c328
-rw-r--r--arch/powerpc/platforms/embedded6xx/usbgecko_udbg.h32
-rw-r--r--arch/powerpc/platforms/embedded6xx/wii.c268
11 files changed, 1335 insertions, 1 deletions
diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype
index 2eab27a94cc9..fa0f690d3867 100644
--- a/arch/powerpc/platforms/Kconfig.cputype
+++ b/arch/powerpc/platforms/Kconfig.cputype
@@ -311,7 +311,7 @@ config NR_CPUS
311 311
312config NOT_COHERENT_CACHE 312config NOT_COHERENT_CACHE
313 bool 313 bool
314 depends on 4xx || 8xx || E200 || PPC_MPC512x 314 depends on 4xx || 8xx || E200 || PPC_MPC512x || GAMECUBE_COMMON
315 default y 315 default y
316 316
317config CHECK_CACHE_COHERENCY 317config CHECK_CACHE_COHERENCY
diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig b/arch/powerpc/platforms/embedded6xx/Kconfig
index 291ac9d8cbee..524d971a1478 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -90,3 +90,36 @@ config MPC10X_OPENPIC
90config MPC10X_STORE_GATHERING 90config MPC10X_STORE_GATHERING
91 bool "Enable MPC10x store gathering" 91 bool "Enable MPC10x store gathering"
92 depends on MPC10X_BRIDGE 92 depends on MPC10X_BRIDGE
93
94config GAMECUBE_COMMON
95 bool
96
97config USBGECKO_UDBG
98 bool "USB Gecko udbg console for the Nintendo GameCube/Wii"
99 depends on GAMECUBE_COMMON
100 help
101 If you say yes to this option, support will be included for the
102 USB Gecko adapter as an udbg console.
103 The USB Gecko is a EXI to USB Serial converter that can be plugged
104 into a memcard slot in the Nintendo GameCube/Wii.
105
106 This driver bypasses the EXI layer completely.
107
108 If in doubt, say N here.
109
110config GAMECUBE
111 bool "Nintendo-GameCube"
112 depends on EMBEDDED6xx
113 select GAMECUBE_COMMON
114 help
115 Select GAMECUBE if configuring for the Nintendo GameCube.
116 More information at: <http://gc-linux.sourceforge.net/>
117
118config WII
119 bool "Nintendo-Wii"
120 depends on EMBEDDED6xx
121 select GAMECUBE_COMMON
122 help
123 Select WII if configuring for the Nintendo Wii.
124 More information at: <http://gc-linux.sourceforge.net/>
125
diff --git a/arch/powerpc/platforms/embedded6xx/Makefile b/arch/powerpc/platforms/embedded6xx/Makefile
index 0773c08bd444..66c23e423f40 100644
--- a/arch/powerpc/platforms/embedded6xx/Makefile
+++ b/arch/powerpc/platforms/embedded6xx/Makefile
@@ -7,3 +7,7 @@ obj-$(CONFIG_STORCENTER) += storcenter.o
7obj-$(CONFIG_PPC_HOLLY) += holly.o 7obj-$(CONFIG_PPC_HOLLY) += holly.o
8obj-$(CONFIG_PPC_PRPMC2800) += prpmc2800.o 8obj-$(CONFIG_PPC_PRPMC2800) += prpmc2800.o
9obj-$(CONFIG_PPC_C2K) += c2k.o 9obj-$(CONFIG_PPC_C2K) += c2k.o
10obj-$(CONFIG_USBGECKO_UDBG) += usbgecko_udbg.o
11obj-$(CONFIG_GAMECUBE_COMMON) += flipper-pic.o
12obj-$(CONFIG_GAMECUBE) += gamecube.o
13obj-$(CONFIG_WII) += wii.o hlwd-pic.o
diff --git a/arch/powerpc/platforms/embedded6xx/flipper-pic.c b/arch/powerpc/platforms/embedded6xx/flipper-pic.c
new file mode 100644
index 000000000000..d5963285e3be
--- /dev/null
+++ b/arch/powerpc/platforms/embedded6xx/flipper-pic.c
@@ -0,0 +1,263 @@
1/*
2 * arch/powerpc/platforms/embedded6xx/flipper-pic.c
3 *
4 * Nintendo GameCube/Wii "Flipper" interrupt controller support.
5 * Copyright (C) 2004-2009 The GameCube Linux Team
6 * Copyright (C) 2007,2008,2009 Albert Herranz
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 */
14#define DRV_MODULE_NAME "flipper-pic"
15#define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt
16
17#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/irq.h>
20#include <linux/of.h>
21#include <asm/io.h>
22
23#include "flipper-pic.h"
24
25#define FLIPPER_NR_IRQS 32
26
27/*
28 * Each interrupt has a corresponding bit in both
29 * the Interrupt Cause (ICR) and Interrupt Mask (IMR) registers.
30 *
31 * Enabling/disabling an interrupt line involves setting/clearing
32 * the corresponding bit in IMR.
33 * Except for the RSW interrupt, all interrupts get deasserted automatically
34 * when the source deasserts the interrupt.
35 */
36#define FLIPPER_ICR 0x00
37#define FLIPPER_ICR_RSS (1<<16) /* reset switch state */
38
39#define FLIPPER_IMR 0x04
40
41#define FLIPPER_RESET 0x24
42
43
44/*
45 * IRQ chip hooks.
46 *
47 */
48
49static void flipper_pic_mask_and_ack(unsigned int virq)
50{
51 int irq = virq_to_hw(virq);
52 void __iomem *io_base = get_irq_chip_data(virq);
53 u32 mask = 1 << irq;
54
55 clrbits32(io_base + FLIPPER_IMR, mask);
56 /* this is at least needed for RSW */
57 out_be32(io_base + FLIPPER_ICR, mask);
58}
59
60static void flipper_pic_ack(unsigned int virq)
61{
62 int irq = virq_to_hw(virq);
63 void __iomem *io_base = get_irq_chip_data(virq);
64
65 /* this is at least needed for RSW */
66 out_be32(io_base + FLIPPER_ICR, 1 << irq);
67}
68
69static void flipper_pic_mask(unsigned int virq)
70{
71 int irq = virq_to_hw(virq);
72 void __iomem *io_base = get_irq_chip_data(virq);
73
74 clrbits32(io_base + FLIPPER_IMR, 1 << irq);
75}
76
77static void flipper_pic_unmask(unsigned int virq)
78{
79 int irq = virq_to_hw(virq);
80 void __iomem *io_base = get_irq_chip_data(virq);
81
82 setbits32(io_base + FLIPPER_IMR, 1 << irq);
83}
84
85
86static struct irq_chip flipper_pic = {
87 .name = "flipper-pic",
88 .ack = flipper_pic_ack,
89 .mask_ack = flipper_pic_mask_and_ack,
90 .mask = flipper_pic_mask,
91 .unmask = flipper_pic_unmask,
92};
93
94/*
95 * IRQ host hooks.
96 *
97 */
98
99static struct irq_host *flipper_irq_host;
100
101static int flipper_pic_map(struct irq_host *h, unsigned int virq,
102 irq_hw_number_t hwirq)
103{
104 set_irq_chip_data(virq, h->host_data);
105 get_irq_desc(virq)->status |= IRQ_LEVEL;
106 set_irq_chip_and_handler(virq, &flipper_pic, handle_level_irq);
107 return 0;
108}
109
110static void flipper_pic_unmap(struct irq_host *h, unsigned int irq)
111{
112 set_irq_chip_data(irq, NULL);
113 set_irq_chip(irq, NULL);
114}
115
116static int flipper_pic_match(struct irq_host *h, struct device_node *np)
117{
118 return 1;
119}
120
121
122static struct irq_host_ops flipper_irq_host_ops = {
123 .map = flipper_pic_map,
124 .unmap = flipper_pic_unmap,
125 .match = flipper_pic_match,
126};
127
128/*
129 * Platform hooks.
130 *
131 */
132
133static void __flipper_quiesce(void __iomem *io_base)
134{
135 /* mask and ack all IRQs */
136 out_be32(io_base + FLIPPER_IMR, 0x00000000);
137 out_be32(io_base + FLIPPER_ICR, 0xffffffff);
138}
139
140struct irq_host * __init flipper_pic_init(struct device_node *np)
141{
142 struct device_node *pi;
143 struct irq_host *irq_host = NULL;
144 struct resource res;
145 void __iomem *io_base;
146 int retval;
147
148 pi = of_get_parent(np);
149 if (!pi) {
150 pr_err("no parent found\n");
151 goto out;
152 }
153 if (!of_device_is_compatible(pi, "nintendo,flipper-pi")) {
154 pr_err("unexpected parent compatible\n");
155 goto out;
156 }
157
158 retval = of_address_to_resource(pi, 0, &res);
159 if (retval) {
160 pr_err("no io memory range found\n");
161 goto out;
162 }
163 io_base = ioremap(res.start, resource_size(&res));
164
165 pr_info("controller at 0x%08x mapped to 0x%p\n", res.start, io_base);
166
167 __flipper_quiesce(io_base);
168
169 irq_host = irq_alloc_host(np, IRQ_HOST_MAP_LINEAR, FLIPPER_NR_IRQS,
170 &flipper_irq_host_ops, -1);
171 if (!irq_host) {
172 pr_err("failed to allocate irq_host\n");
173 return NULL;
174 }
175
176 irq_host->host_data = io_base;
177
178out:
179 return irq_host;
180}
181
182unsigned int flipper_pic_get_irq(void)
183{
184 void __iomem *io_base = flipper_irq_host->host_data;
185 int irq;
186 u32 irq_status;
187
188 irq_status = in_be32(io_base + FLIPPER_ICR) &
189 in_be32(io_base + FLIPPER_IMR);
190 if (irq_status == 0)
191 return NO_IRQ; /* no more IRQs pending */
192
193 irq = __ffs(irq_status);
194 return irq_linear_revmap(flipper_irq_host, irq);
195}
196
197/*
198 * Probe function.
199 *
200 */
201
202void __init flipper_pic_probe(void)
203{
204 struct device_node *np;
205
206 np = of_find_compatible_node(NULL, NULL, "nintendo,flipper-pic");
207 BUG_ON(!np);
208
209 flipper_irq_host = flipper_pic_init(np);
210 BUG_ON(!flipper_irq_host);
211
212 irq_set_default_host(flipper_irq_host);
213
214 of_node_put(np);
215}
216
217/*
218 * Misc functions related to the flipper chipset.
219 *
220 */
221
222/**
223 * flipper_quiesce() - quiesce flipper irq controller
224 *
225 * Mask and ack all interrupt sources.
226 *
227 */
228void flipper_quiesce(void)
229{
230 void __iomem *io_base = flipper_irq_host->host_data;
231
232 __flipper_quiesce(io_base);
233}
234
235/*
236 * Resets the platform.
237 */
238void flipper_platform_reset(void)
239{
240 void __iomem *io_base;
241
242 if (flipper_irq_host && flipper_irq_host->host_data) {
243 io_base = flipper_irq_host->host_data;
244 out_8(io_base + FLIPPER_RESET, 0x00);
245 }
246}
247
248/*
249 * Returns non-zero if the reset button is pressed.
250 */
251int flipper_is_reset_button_pressed(void)
252{
253 void __iomem *io_base;
254 u32 icr;
255
256 if (flipper_irq_host && flipper_irq_host->host_data) {
257 io_base = flipper_irq_host->host_data;
258 icr = in_be32(io_base + FLIPPER_ICR);
259 return !(icr & FLIPPER_ICR_RSS);
260 }
261 return 0;
262}
263
diff --git a/arch/powerpc/platforms/embedded6xx/flipper-pic.h b/arch/powerpc/platforms/embedded6xx/flipper-pic.h
new file mode 100644
index 000000000000..e339186b5663
--- /dev/null
+++ b/arch/powerpc/platforms/embedded6xx/flipper-pic.h
@@ -0,0 +1,25 @@
1/*
2 * arch/powerpc/platforms/embedded6xx/flipper-pic.h
3 *
4 * Nintendo GameCube/Wii "Flipper" interrupt controller support.
5 * Copyright (C) 2004-2009 The GameCube Linux Team
6 * Copyright (C) 2007,2008,2009 Albert Herranz
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 */
14
15#ifndef __FLIPPER_PIC_H
16#define __FLIPPER_PIC_H
17
18unsigned int flipper_pic_get_irq(void);
19void __init flipper_pic_probe(void);
20
21void flipper_quiesce(void);
22void flipper_platform_reset(void);
23int flipper_is_reset_button_pressed(void);
24
25#endif
diff --git a/arch/powerpc/platforms/embedded6xx/gamecube.c b/arch/powerpc/platforms/embedded6xx/gamecube.c
new file mode 100644
index 000000000000..1106fd99627f
--- /dev/null
+++ b/arch/powerpc/platforms/embedded6xx/gamecube.c
@@ -0,0 +1,118 @@
1/*
2 * arch/powerpc/platforms/embedded6xx/gamecube.c
3 *
4 * Nintendo GameCube board-specific support
5 * Copyright (C) 2004-2009 The GameCube Linux Team
6 * Copyright (C) 2007,2008,2009 Albert Herranz
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 */
14
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/irq.h>
18#include <linux/kexec.h>
19#include <linux/seq_file.h>
20#include <linux/of_platform.h>
21
22#include <asm/io.h>
23#include <asm/machdep.h>
24#include <asm/prom.h>
25#include <asm/time.h>
26#include <asm/udbg.h>
27
28#include "flipper-pic.h"
29#include "usbgecko_udbg.h"
30
31
32static void gamecube_spin(void)
33{
34 /* spin until power button pressed */
35 for (;;)
36 cpu_relax();
37}
38
39static void gamecube_restart(char *cmd)
40{
41 local_irq_disable();
42 flipper_platform_reset();
43 gamecube_spin();
44}
45
46static void gamecube_power_off(void)
47{
48 local_irq_disable();
49 gamecube_spin();
50}
51
52static void gamecube_halt(void)
53{
54 gamecube_restart(NULL);
55}
56
57static void __init gamecube_init_early(void)
58{
59 ug_udbg_init();
60}
61
62static int __init gamecube_probe(void)
63{
64 unsigned long dt_root;
65
66 dt_root = of_get_flat_dt_root();
67 if (!of_flat_dt_is_compatible(dt_root, "nintendo,gamecube"))
68 return 0;
69
70 return 1;
71}
72
73static void gamecube_shutdown(void)
74{
75 flipper_quiesce();
76}
77
78#ifdef CONFIG_KEXEC
79static int gamecube_kexec_prepare(struct kimage *image)
80{
81 return 0;
82}
83#endif /* CONFIG_KEXEC */
84
85
86define_machine(gamecube) {
87 .name = "gamecube",
88 .probe = gamecube_probe,
89 .init_early = gamecube_init_early,
90 .restart = gamecube_restart,
91 .power_off = gamecube_power_off,
92 .halt = gamecube_halt,
93 .init_IRQ = flipper_pic_probe,
94 .get_irq = flipper_pic_get_irq,
95 .calibrate_decr = generic_calibrate_decr,
96 .progress = udbg_progress,
97 .machine_shutdown = gamecube_shutdown,
98#ifdef CONFIG_KEXEC
99 .machine_kexec_prepare = gamecube_kexec_prepare,
100#endif
101};
102
103
104static struct of_device_id gamecube_of_bus[] = {
105 { .compatible = "nintendo,flipper", },
106 { },
107};
108
109static int __init gamecube_device_probe(void)
110{
111 if (!machine_is(gamecube))
112 return 0;
113
114 of_platform_bus_probe(NULL, gamecube_of_bus, NULL);
115 return 0;
116}
117device_initcall(gamecube_device_probe);
118
diff --git a/arch/powerpc/platforms/embedded6xx/hlwd-pic.c b/arch/powerpc/platforms/embedded6xx/hlwd-pic.c
new file mode 100644
index 000000000000..dd20bff33207
--- /dev/null
+++ b/arch/powerpc/platforms/embedded6xx/hlwd-pic.c
@@ -0,0 +1,241 @@
1/*
2 * arch/powerpc/platforms/embedded6xx/hlwd-pic.c
3 *
4 * Nintendo Wii "Hollywood" interrupt controller support.
5 * Copyright (C) 2009 The GameCube Linux Team
6 * Copyright (C) 2009 Albert Herranz
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 */
14#define DRV_MODULE_NAME "hlwd-pic"
15#define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt
16
17#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/irq.h>
20#include <linux/of.h>
21#include <asm/io.h>
22
23#include "hlwd-pic.h"
24
25#define HLWD_NR_IRQS 32
26
27/*
28 * Each interrupt has a corresponding bit in both
29 * the Interrupt Cause (ICR) and Interrupt Mask (IMR) registers.
30 *
31 * Enabling/disabling an interrupt line involves asserting/clearing
32 * the corresponding bit in IMR. ACK'ing a request simply involves
33 * asserting the corresponding bit in ICR.
34 */
35#define HW_BROADWAY_ICR 0x00
36#define HW_BROADWAY_IMR 0x04
37
38
39/*
40 * IRQ chip hooks.
41 *
42 */
43
44static void hlwd_pic_mask_and_ack(unsigned int virq)
45{
46 int irq = virq_to_hw(virq);
47 void __iomem *io_base = get_irq_chip_data(virq);
48 u32 mask = 1 << irq;
49
50 clrbits32(io_base + HW_BROADWAY_IMR, mask);
51 out_be32(io_base + HW_BROADWAY_ICR, mask);
52}
53
54static void hlwd_pic_ack(unsigned int virq)
55{
56 int irq = virq_to_hw(virq);
57 void __iomem *io_base = get_irq_chip_data(virq);
58
59 out_be32(io_base + HW_BROADWAY_ICR, 1 << irq);
60}
61
62static void hlwd_pic_mask(unsigned int virq)
63{
64 int irq = virq_to_hw(virq);
65 void __iomem *io_base = get_irq_chip_data(virq);
66
67 clrbits32(io_base + HW_BROADWAY_IMR, 1 << irq);
68}
69
70static void hlwd_pic_unmask(unsigned int virq)
71{
72 int irq = virq_to_hw(virq);
73 void __iomem *io_base = get_irq_chip_data(virq);
74
75 setbits32(io_base + HW_BROADWAY_IMR, 1 << irq);
76}
77
78
79static struct irq_chip hlwd_pic = {
80 .name = "hlwd-pic",
81 .ack = hlwd_pic_ack,
82 .mask_ack = hlwd_pic_mask_and_ack,
83 .mask = hlwd_pic_mask,
84 .unmask = hlwd_pic_unmask,
85};
86
87/*
88 * IRQ host hooks.
89 *
90 */
91
92static struct irq_host *hlwd_irq_host;
93
94static int hlwd_pic_map(struct irq_host *h, unsigned int virq,
95 irq_hw_number_t hwirq)
96{
97 set_irq_chip_data(virq, h->host_data);
98 get_irq_desc(virq)->status |= IRQ_LEVEL;
99 set_irq_chip_and_handler(virq, &hlwd_pic, handle_level_irq);
100 return 0;
101}
102
103static void hlwd_pic_unmap(struct irq_host *h, unsigned int irq)
104{
105 set_irq_chip_data(irq, NULL);
106 set_irq_chip(irq, NULL);
107}
108
109static struct irq_host_ops hlwd_irq_host_ops = {
110 .map = hlwd_pic_map,
111 .unmap = hlwd_pic_unmap,
112};
113
114static unsigned int __hlwd_pic_get_irq(struct irq_host *h)
115{
116 void __iomem *io_base = h->host_data;
117 int irq;
118 u32 irq_status;
119
120 irq_status = in_be32(io_base + HW_BROADWAY_ICR) &
121 in_be32(io_base + HW_BROADWAY_IMR);
122 if (irq_status == 0)
123 return NO_IRQ; /* no more IRQs pending */
124
125 irq = __ffs(irq_status);
126 return irq_linear_revmap(h, irq);
127}
128
129static void hlwd_pic_irq_cascade(unsigned int cascade_virq,
130 struct irq_desc *desc)
131{
132 struct irq_host *irq_host = get_irq_data(cascade_virq);
133 unsigned int virq;
134
135 spin_lock(&desc->lock);
136 desc->chip->mask(cascade_virq); /* IRQ_LEVEL */
137 spin_unlock(&desc->lock);
138
139 virq = __hlwd_pic_get_irq(irq_host);
140 if (virq != NO_IRQ)
141 generic_handle_irq(virq);
142 else
143 pr_err("spurious interrupt!\n");
144
145 spin_lock(&desc->lock);
146 desc->chip->ack(cascade_virq); /* IRQ_LEVEL */
147 if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask)
148 desc->chip->unmask(cascade_virq);
149 spin_unlock(&desc->lock);
150}
151
152/*
153 * Platform hooks.
154 *
155 */
156
157static void __hlwd_quiesce(void __iomem *io_base)
158{
159 /* mask and ack all IRQs */
160 out_be32(io_base + HW_BROADWAY_IMR, 0);
161 out_be32(io_base + HW_BROADWAY_ICR, 0xffffffff);
162}
163
164struct irq_host *hlwd_pic_init(struct device_node *np)
165{
166 struct irq_host *irq_host;
167 struct resource res;
168 void __iomem *io_base;
169 int retval;
170
171 retval = of_address_to_resource(np, 0, &res);
172 if (retval) {
173 pr_err("no io memory range found\n");
174 return NULL;
175 }
176 io_base = ioremap(res.start, resource_size(&res));
177 if (!io_base) {
178 pr_err("ioremap failed\n");
179 return NULL;
180 }
181
182 pr_info("controller at 0x%08x mapped to 0x%p\n", res.start, io_base);
183
184 __hlwd_quiesce(io_base);
185
186 irq_host = irq_alloc_host(np, IRQ_HOST_MAP_LINEAR, HLWD_NR_IRQS,
187 &hlwd_irq_host_ops, -1);
188 if (!irq_host) {
189 pr_err("failed to allocate irq_host\n");
190 return NULL;
191 }
192 irq_host->host_data = io_base;
193
194 return irq_host;
195}
196
197unsigned int hlwd_pic_get_irq(void)
198{
199 return __hlwd_pic_get_irq(hlwd_irq_host);
200}
201
202/*
203 * Probe function.
204 *
205 */
206
207void hlwd_pic_probe(void)
208{
209 struct irq_host *host;
210 struct device_node *np;
211 const u32 *interrupts;
212 int cascade_virq;
213
214 for_each_compatible_node(np, NULL, "nintendo,hollywood-pic") {
215 interrupts = of_get_property(np, "interrupts", NULL);
216 if (interrupts) {
217 host = hlwd_pic_init(np);
218 BUG_ON(!host);
219 cascade_virq = irq_of_parse_and_map(np, 0);
220 set_irq_data(cascade_virq, host);
221 set_irq_chained_handler(cascade_virq,
222 hlwd_pic_irq_cascade);
223 hlwd_irq_host = host;
224 break;
225 }
226 }
227}
228
229/**
230 * hlwd_quiesce() - quiesce hollywood irq controller
231 *
232 * Mask and ack all interrupt sources.
233 *
234 */
235void hlwd_quiesce(void)
236{
237 void __iomem *io_base = hlwd_irq_host->host_data;
238
239 __hlwd_quiesce(io_base);
240}
241
diff --git a/arch/powerpc/platforms/embedded6xx/hlwd-pic.h b/arch/powerpc/platforms/embedded6xx/hlwd-pic.h
new file mode 100644
index 000000000000..d2e5a092761e
--- /dev/null
+++ b/arch/powerpc/platforms/embedded6xx/hlwd-pic.h
@@ -0,0 +1,22 @@
1/*
2 * arch/powerpc/platforms/embedded6xx/hlwd-pic.h
3 *
4 * Nintendo Wii "Hollywood" interrupt controller support.
5 * Copyright (C) 2009 The GameCube Linux Team
6 * Copyright (C) 2009 Albert Herranz
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 */
14
15#ifndef __HLWD_PIC_H
16#define __HLWD_PIC_H
17
18extern unsigned int hlwd_pic_get_irq(void);
19extern void hlwd_pic_probe(void);
20extern void hlwd_quiesce(void);
21
22#endif
diff --git a/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c b/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c
new file mode 100644
index 000000000000..edc956cc8b13
--- /dev/null
+++ b/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c
@@ -0,0 +1,328 @@
1/*
2 * arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c
3 *
4 * udbg serial input/output routines for the USB Gecko adapter.
5 * Copyright (C) 2008-2009 The GameCube Linux Team
6 * Copyright (C) 2008,2009 Albert Herranz
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 */
14
15#include <mm/mmu_decl.h>
16
17#include <asm/io.h>
18#include <asm/prom.h>
19#include <asm/udbg.h>
20#include <asm/fixmap.h>
21
22#include "usbgecko_udbg.h"
23
24
25#define EXI_CLK_32MHZ 5
26
27#define EXI_CSR 0x00
28#define EXI_CSR_CLKMASK (0x7<<4)
29#define EXI_CSR_CLK_32MHZ (EXI_CLK_32MHZ<<4)
30#define EXI_CSR_CSMASK (0x7<<7)
31#define EXI_CSR_CS_0 (0x1<<7) /* Chip Select 001 */
32
33#define EXI_CR 0x0c
34#define EXI_CR_TSTART (1<<0)
35#define EXI_CR_WRITE (1<<2)
36#define EXI_CR_READ_WRITE (2<<2)
37#define EXI_CR_TLEN(len) (((len)-1)<<4)
38
39#define EXI_DATA 0x10
40
41#define UG_READ_ATTEMPTS 100
42#define UG_WRITE_ATTEMPTS 100
43
44
45static void __iomem *ug_io_base;
46
47/*
48 * Performs one input/output transaction between the exi host and the usbgecko.
49 */
50static u32 ug_io_transaction(u32 in)
51{
52 u32 __iomem *csr_reg = ug_io_base + EXI_CSR;
53 u32 __iomem *data_reg = ug_io_base + EXI_DATA;
54 u32 __iomem *cr_reg = ug_io_base + EXI_CR;
55 u32 csr, data, cr;
56
57 /* select */
58 csr = EXI_CSR_CLK_32MHZ | EXI_CSR_CS_0;
59 out_be32(csr_reg, csr);
60
61 /* read/write */
62 data = in;
63 out_be32(data_reg, data);
64 cr = EXI_CR_TLEN(2) | EXI_CR_READ_WRITE | EXI_CR_TSTART;
65 out_be32(cr_reg, cr);
66
67 while (in_be32(cr_reg) & EXI_CR_TSTART)
68 barrier();
69
70 /* deselect */
71 out_be32(csr_reg, 0);
72
73 /* result */
74 data = in_be32(data_reg);
75
76 return data;
77}
78
79/*
80 * Returns true if an usbgecko adapter is found.
81 */
82static int ug_is_adapter_present(void)
83{
84 if (!ug_io_base)
85 return 0;
86
87 return ug_io_transaction(0x90000000) == 0x04700000;
88}
89
90/*
91 * Returns true if the TX fifo is ready for transmission.
92 */
93static int ug_is_txfifo_ready(void)
94{
95 return ug_io_transaction(0xc0000000) & 0x04000000;
96}
97
98/*
99 * Tries to transmit a character.
100 * If the TX fifo is not ready the result is undefined.
101 */
102static void ug_raw_putc(char ch)
103{
104 ug_io_transaction(0xb0000000 | (ch << 20));
105}
106
107/*
108 * Transmits a character.
109 * It silently fails if the TX fifo is not ready after a number of retries.
110 */
111static void ug_putc(char ch)
112{
113 int count = UG_WRITE_ATTEMPTS;
114
115 if (!ug_io_base)
116 return;
117
118 if (ch == '\n')
119 ug_putc('\r');
120
121 while (!ug_is_txfifo_ready() && count--)
122 barrier();
123 if (count)
124 ug_raw_putc(ch);
125}
126
127/*
128 * Returns true if the RX fifo is ready for transmission.
129 */
130static int ug_is_rxfifo_ready(void)
131{
132 return ug_io_transaction(0xd0000000) & 0x04000000;
133}
134
135/*
136 * Tries to receive a character.
137 * If a character is unavailable the function returns -1.
138 */
139static int ug_raw_getc(void)
140{
141 u32 data = ug_io_transaction(0xa0000000);
142 if (data & 0x08000000)
143 return (data >> 16) & 0xff;
144 else
145 return -1;
146}
147
148/*
149 * Receives a character.
150 * It fails if the RX fifo is not ready after a number of retries.
151 */
152static int ug_getc(void)
153{
154 int count = UG_READ_ATTEMPTS;
155
156 if (!ug_io_base)
157 return -1;
158
159 while (!ug_is_rxfifo_ready() && count--)
160 barrier();
161 return ug_raw_getc();
162}
163
164/*
165 * udbg functions.
166 *
167 */
168
169/*
170 * Transmits a character.
171 */
172void ug_udbg_putc(char ch)
173{
174 ug_putc(ch);
175}
176
177/*
178 * Receives a character. Waits until a character is available.
179 */
180static int ug_udbg_getc(void)
181{
182 int ch;
183
184 while ((ch = ug_getc()) == -1)
185 barrier();
186 return ch;
187}
188
189/*
190 * Receives a character. If a character is not available, returns -1.
191 */
192static int ug_udbg_getc_poll(void)
193{
194 if (!ug_is_rxfifo_ready())
195 return -1;
196 return ug_getc();
197}
198
199/*
200 * Retrieves and prepares the virtual address needed to access the hardware.
201 */
202static void __iomem *ug_udbg_setup_exi_io_base(struct device_node *np)
203{
204 void __iomem *exi_io_base = NULL;
205 phys_addr_t paddr;
206 const unsigned int *reg;
207
208 reg = of_get_property(np, "reg", NULL);
209 if (reg) {
210 paddr = of_translate_address(np, reg);
211 if (paddr)
212 exi_io_base = ioremap(paddr, reg[1]);
213 }
214 return exi_io_base;
215}
216
217/*
218 * Checks if a USB Gecko adapter is inserted in any memory card slot.
219 */
220static void __iomem *ug_udbg_probe(void __iomem *exi_io_base)
221{
222 int i;
223
224 /* look for a usbgecko on memcard slots A and B */
225 for (i = 0; i < 2; i++) {
226 ug_io_base = exi_io_base + 0x14 * i;
227 if (ug_is_adapter_present())
228 break;
229 }
230 if (i == 2)
231 ug_io_base = NULL;
232 return ug_io_base;
233
234}
235
236/*
237 * USB Gecko udbg support initialization.
238 */
239void __init ug_udbg_init(void)
240{
241 struct device_node *np;
242 void __iomem *exi_io_base;
243
244 if (ug_io_base)
245 udbg_printf("%s: early -> final\n", __func__);
246
247 np = of_find_compatible_node(NULL, NULL, "nintendo,flipper-exi");
248 if (!np) {
249 udbg_printf("%s: EXI node not found\n", __func__);
250 goto done;
251 }
252
253 exi_io_base = ug_udbg_setup_exi_io_base(np);
254 if (!exi_io_base) {
255 udbg_printf("%s: failed to setup EXI io base\n", __func__);
256 goto done;
257 }
258
259 if (!ug_udbg_probe(exi_io_base)) {
260 udbg_printf("usbgecko_udbg: not found\n");
261 iounmap(exi_io_base);
262 } else {
263 udbg_putc = ug_udbg_putc;
264 udbg_getc = ug_udbg_getc;
265 udbg_getc_poll = ug_udbg_getc_poll;
266 udbg_printf("usbgecko_udbg: ready\n");
267 }
268
269done:
270 if (np)
271 of_node_put(np);
272 return;
273}
274
275#ifdef CONFIG_PPC_EARLY_DEBUG_USBGECKO
276
277static phys_addr_t __init ug_early_grab_io_addr(void)
278{
279#if defined(CONFIG_GAMECUBE)
280 return 0x0c000000;
281#elif defined(CONFIG_WII)
282 return 0x0d000000;
283#else
284#error Invalid platform for USB Gecko based early debugging.
285#endif
286}
287
288/*
289 * USB Gecko early debug support initialization for udbg.
290 */
291void __init udbg_init_usbgecko(void)
292{
293 void __iomem *early_debug_area;
294 void __iomem *exi_io_base;
295
296 /*
297 * At this point we have a BAT already setup that enables I/O
298 * to the EXI hardware.
299 *
300 * The BAT uses a virtual address range reserved at the fixmap.
301 * This must match the virtual address configured in
302 * head_32.S:setup_usbgecko_bat().
303 */
304 early_debug_area = (void __iomem *)__fix_to_virt(FIX_EARLY_DEBUG_BASE);
305 exi_io_base = early_debug_area + 0x00006800;
306
307 /* try to detect a USB Gecko */
308 if (!ug_udbg_probe(exi_io_base))
309 return;
310
311 /* we found a USB Gecko, load udbg hooks */
312 udbg_putc = ug_udbg_putc;
313 udbg_getc = ug_udbg_getc;
314 udbg_getc_poll = ug_udbg_getc_poll;
315
316 /*
317 * Prepare again the same BAT for MMU_init.
318 * This allows udbg I/O to continue working after the MMU is
319 * turned on for real.
320 * It is safe to continue using the same virtual address as it is
321 * a reserved fixmap area.
322 */
323 setbat(1, (unsigned long)early_debug_area,
324 ug_early_grab_io_addr(), 128*1024, PAGE_KERNEL_NCG);
325}
326
327#endif /* CONFIG_PPC_EARLY_DEBUG_USBGECKO */
328
diff --git a/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.h b/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.h
new file mode 100644
index 000000000000..bb6cde4ad764
--- /dev/null
+++ b/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.h
@@ -0,0 +1,32 @@
1/*
2 * arch/powerpc/platforms/embedded6xx/usbgecko_udbg.h
3 *
4 * udbg serial input/output routines for the USB Gecko adapter.
5 * Copyright (C) 2008-2009 The GameCube Linux Team
6 * Copyright (C) 2008,2009 Albert Herranz
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 */
14
15#ifndef __USBGECKO_UDBG_H
16#define __USBGECKO_UDBG_H
17
18#ifdef CONFIG_USBGECKO_UDBG
19
20extern void __init ug_udbg_init(void);
21
22#else
23
24static inline void __init ug_udbg_init(void)
25{
26}
27
28#endif /* CONFIG_USBGECKO_UDBG */
29
30void __init udbg_init_usbgecko(void);
31
32#endif /* __USBGECKO_UDBG_H */
diff --git a/arch/powerpc/platforms/embedded6xx/wii.c b/arch/powerpc/platforms/embedded6xx/wii.c
new file mode 100644
index 000000000000..57e5b608fa1a
--- /dev/null
+++ b/arch/powerpc/platforms/embedded6xx/wii.c
@@ -0,0 +1,268 @@
1/*
2 * arch/powerpc/platforms/embedded6xx/wii.c
3 *
4 * Nintendo Wii board-specific support
5 * Copyright (C) 2008-2009 The GameCube Linux Team
6 * Copyright (C) 2008,2009 Albert Herranz
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 */
14#define DRV_MODULE_NAME "wii"
15#define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt
16
17#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/irq.h>
20#include <linux/seq_file.h>
21#include <linux/kexec.h>
22#include <linux/of_platform.h>
23#include <linux/lmb.h>
24#include <mm/mmu_decl.h>
25
26#include <asm/io.h>
27#include <asm/machdep.h>
28#include <asm/prom.h>
29#include <asm/time.h>
30#include <asm/udbg.h>
31
32#include "flipper-pic.h"
33#include "hlwd-pic.h"
34#include "usbgecko_udbg.h"
35
36/* control block */
37#define HW_CTRL_COMPATIBLE "nintendo,hollywood-control"
38
39#define HW_CTRL_RESETS 0x94
40#define HW_CTRL_RESETS_SYS (1<<0)
41
42/* gpio */
43#define HW_GPIO_COMPATIBLE "nintendo,hollywood-gpio"
44
45#define HW_GPIO_BASE(idx) (idx * 0x20)
46#define HW_GPIO_OUT(idx) (HW_GPIO_BASE(idx) + 0)
47#define HW_GPIO_DIR(idx) (HW_GPIO_BASE(idx) + 4)
48
49#define HW_GPIO_SHUTDOWN (1<<1)
50#define HW_GPIO_SLOT_LED (1<<5)
51#define HW_GPIO_SENSOR_BAR (1<<8)
52
53
54static void __iomem *hw_ctrl;
55static void __iomem *hw_gpio;
56
57unsigned long wii_hole_start;
58unsigned long wii_hole_size;
59
60
61static int __init page_aligned(unsigned long x)
62{
63 return !(x & (PAGE_SIZE-1));
64}
65
66void __init wii_memory_fixups(void)
67{
68 struct lmb_property *p = lmb.memory.region;
69
70 /*
71 * This is part of a workaround to allow the use of two
72 * discontiguous RAM ranges on the Wii, even if this is
73 * currently unsupported on 32-bit PowerPC Linux.
74 *
75 * We coealesce the two memory ranges of the Wii into a
76 * single range, then create a reservation for the "hole"
77 * between both ranges.
78 */
79
80 BUG_ON(lmb.memory.cnt != 2);
81 BUG_ON(!page_aligned(p[0].base) || !page_aligned(p[1].base));
82
83 p[0].size = _ALIGN_DOWN(p[0].size, PAGE_SIZE);
84 p[1].size = _ALIGN_DOWN(p[1].size, PAGE_SIZE);
85
86 wii_hole_start = p[0].base + p[0].size;
87 wii_hole_size = p[1].base - wii_hole_start;
88
89 pr_info("MEM1: <%08llx %08llx>\n", p[0].base, p[0].size);
90 pr_info("HOLE: <%08lx %08lx>\n", wii_hole_start, wii_hole_size);
91 pr_info("MEM2: <%08llx %08llx>\n", p[1].base, p[1].size);
92
93 p[0].size += wii_hole_size + p[1].size;
94
95 lmb.memory.cnt = 1;
96 lmb_analyze();
97
98 /* reserve the hole */
99 lmb_reserve(wii_hole_start, wii_hole_size);
100
101 /* allow ioremapping the address space in the hole */
102 __allow_ioremap_reserved = 1;
103}
104
105unsigned long __init wii_mmu_mapin_mem2(unsigned long top)
106{
107 unsigned long delta, size, bl;
108 unsigned long max_size = (256<<20);
109
110 /* MEM2 64MB@0x10000000 */
111 delta = wii_hole_start + wii_hole_size;
112 size = top - delta;
113 for (bl = 128<<10; bl < max_size; bl <<= 1) {
114 if (bl * 2 > size)
115 break;
116 }
117 setbat(4, PAGE_OFFSET+delta, delta, bl, PAGE_KERNEL_X);
118 return delta + bl;
119}
120
121static void wii_spin(void)
122{
123 local_irq_disable();
124 for (;;)
125 cpu_relax();
126}
127
128static void __iomem *wii_ioremap_hw_regs(char *name, char *compatible)
129{
130 void __iomem *hw_regs = NULL;
131 struct device_node *np;
132 struct resource res;
133 int error = -ENODEV;
134
135 np = of_find_compatible_node(NULL, NULL, compatible);
136 if (!np) {
137 pr_err("no compatible node found for %s\n", compatible);
138 goto out;
139 }
140 error = of_address_to_resource(np, 0, &res);
141 if (error) {
142 pr_err("no valid reg found for %s\n", np->name);
143 goto out_put;
144 }
145
146 hw_regs = ioremap(res.start, resource_size(&res));
147 if (hw_regs) {
148 pr_info("%s at 0x%08x mapped to 0x%p\n", name,
149 res.start, hw_regs);
150 }
151
152out_put:
153 of_node_put(np);
154out:
155 return hw_regs;
156}
157
158static void __init wii_setup_arch(void)
159{
160 hw_ctrl = wii_ioremap_hw_regs("hw_ctrl", HW_CTRL_COMPATIBLE);
161 hw_gpio = wii_ioremap_hw_regs("hw_gpio", HW_GPIO_COMPATIBLE);
162 if (hw_gpio) {
163 /* turn off the front blue led and IR light */
164 clrbits32(hw_gpio + HW_GPIO_OUT(0),
165 HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR);
166 }
167}
168
169static void wii_restart(char *cmd)
170{
171 local_irq_disable();
172
173 if (hw_ctrl) {
174 /* clear the system reset pin to cause a reset */
175 clrbits32(hw_ctrl + HW_CTRL_RESETS, HW_CTRL_RESETS_SYS);
176 }
177 wii_spin();
178}
179
180static void wii_power_off(void)
181{
182 local_irq_disable();
183
184 if (hw_gpio) {
185 /* make sure that the poweroff GPIO is configured as output */
186 setbits32(hw_gpio + HW_GPIO_DIR(1), HW_GPIO_SHUTDOWN);
187
188 /* drive the poweroff GPIO high */
189 setbits32(hw_gpio + HW_GPIO_OUT(1), HW_GPIO_SHUTDOWN);
190 }
191 wii_spin();
192}
193
194static void wii_halt(void)
195{
196 if (ppc_md.restart)
197 ppc_md.restart(NULL);
198 wii_spin();
199}
200
201static void __init wii_init_early(void)
202{
203 ug_udbg_init();
204}
205
206static void __init wii_pic_probe(void)
207{
208 flipper_pic_probe();
209 hlwd_pic_probe();
210}
211
212static int __init wii_probe(void)
213{
214 unsigned long dt_root;
215
216 dt_root = of_get_flat_dt_root();
217 if (!of_flat_dt_is_compatible(dt_root, "nintendo,wii"))
218 return 0;
219
220 return 1;
221}
222
223static void wii_shutdown(void)
224{
225 hlwd_quiesce();
226 flipper_quiesce();
227}
228
229#ifdef CONFIG_KEXEC
230static int wii_machine_kexec_prepare(struct kimage *image)
231{
232 return 0;
233}
234#endif /* CONFIG_KEXEC */
235
236define_machine(wii) {
237 .name = "wii",
238 .probe = wii_probe,
239 .init_early = wii_init_early,
240 .setup_arch = wii_setup_arch,
241 .restart = wii_restart,
242 .power_off = wii_power_off,
243 .halt = wii_halt,
244 .init_IRQ = wii_pic_probe,
245 .get_irq = flipper_pic_get_irq,
246 .calibrate_decr = generic_calibrate_decr,
247 .progress = udbg_progress,
248 .machine_shutdown = wii_shutdown,
249#ifdef CONFIG_KEXEC
250 .machine_kexec_prepare = wii_machine_kexec_prepare,
251#endif
252};
253
254static struct of_device_id wii_of_bus[] = {
255 { .compatible = "nintendo,hollywood", },
256 { },
257};
258
259static int __init wii_device_probe(void)
260{
261 if (!machine_is(wii))
262 return 0;
263
264 of_platform_bus_probe(NULL, wii_of_bus, NULL);
265 return 0;
266}
267device_initcall(wii_device_probe);
268