forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.c
343 lines (294 loc) · 7.03 KB
/
setup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*
* PlayStation 2 system setup functions
*
* Copyright (C) 2010-2013 Jürgen Urban
* Copyright (C) 2017 Fredrik Noring
*
* SPDX-License-Identifier: GPL-2.0
*/
#include <linux/init.h>
#include <linux/ioport.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/platform_device.h>
#include <asm/bootinfo.h>
#include <asm/cacheflush.h>
#include <asm/reboot.h>
#include <asm/mach-ps2/iop-registers.h>
#include <asm/mach-ps2/ps2.h>
#include <asm/mach-ps2/dma.h>
const char *get_system_type(void)
{
return "Sony PlayStation 2";
}
#define VU0_BASE 0x11000000
#define VU1_BASE 0x11008000
#define IOP_RAM_BASE 0x1c000000
#define IOP_OHCI_BASE 0x1f801600
#define GS_REG_BASE 0x12000000
static struct resource iop_resources[] = {
[0] = {
.name = "IOP RAM",
.start = IOP_RAM_BASE,
.end = IOP_RAM_BASE + 0x1fffff,
.flags = IORESOURCE_MEM, /* 2 MiB IOP RAM */
},
};
static struct platform_device iop_device = {
.name = "iop",
.id = -1,
.num_resources = ARRAY_SIZE(iop_resources),
.resource = iop_resources,
};
static struct resource ohci_resources[] = { /* FIXME: Subresource to IOP */
[0] = {
.name = "USB OHCI",
.start = IOP_OHCI_BASE,
.end = IOP_OHCI_BASE + 0xff,
.flags = IORESOURCE_MEM, /* 256 byte HCCA. */
},
[1] = {
.start = IRQ_INTC_SBUS,
.end = IRQ_INTC_SBUS,
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_SHAREABLE,
},
};
static struct platform_device ohci_device = {
.name = "ohci-ps2",
.id = -1,
.num_resources = ARRAY_SIZE(ohci_resources),
.resource = ohci_resources,
};
static struct resource gs_resources[] = {
[0] = {
.name = "Graphics Synthesizer",
.start = GS_REG_BASE,
.end = GS_REG_BASE + 0x1ffffff,
.flags = IORESOURCE_MEM, /* FIXME: IORESOURCE_REG? */
},
[1] = {
.start = IRQ_DMAC_2, /* GS interface (GIF) */
.end = IRQ_DMAC_2,
.flags = IORESOURCE_IRQ,
},
[2] = {
.start = IRQ_GS_SIGNAL,
.end = IRQ_GS_EXVSYNC,
.flags = IORESOURCE_IRQ,
},
};
static struct resource vu0_resources[] = {
[0] = {
.name = "Vector unit 0 code",
.start = VU0_BASE,
.end = VU0_BASE + 0xfff,
.flags = IORESOURCE_MEM,
},
[1] = {
.name = "Vector unit 0 data",
.start = VU0_BASE + 0x4000,
.end = VU0_BASE + 0x4fff,
.flags = IORESOURCE_MEM,
},
};
static struct resource vu1_resources[] = {
[2] = {
.name = "Vector unit 1 code",
.start = VU1_BASE,
.end = VU1_BASE + 0x3fff,
.flags = IORESOURCE_MEM,
},
[3] = {
.name = "Vector unit 1 data",
.start = VU1_BASE + 0x4000,
.end = VU1_BASE + 0x7fff,
.flags = IORESOURCE_MEM,
},
};
static struct platform_device gs_device = {
.name = "gs",
.id = -1,
.num_resources = ARRAY_SIZE(gs_resources),
.resource = gs_resources,
};
static struct platform_device fb_device = {
.name = "ps2fb", /* FIXME: Remove from platform? */
.id = -1,
};
static struct platform_device vu0_device = {
.name = "vu0",
.id = -1,
.num_resources = ARRAY_SIZE(vu0_resources),
.resource = vu0_resources,
};
static struct platform_device vu1_device = {
.name = "vu1",
.id = -1,
.num_resources = ARRAY_SIZE(vu1_resources),
.resource = vu1_resources,
};
#if 0
/*
* PATA disk driver
*
* Compatible with:
* - driver/ide (old)
* - drivers/ata (new)
*/
static struct resource pata_resources[] = {
/* IO base, 8 16bit registers */
[0] = {
.start = CPHYSADDR(0xb4000040),
.end = CPHYSADDR(0xb4000040 + (8 * 2) - 1),
.flags = IORESOURCE_MEM,
},
/* CTRL base, 1 16bit register */
[1] = {
.start = CPHYSADDR(0xb400005c),
.end = CPHYSADDR(0xb400005c + (1 * 2) - 1),
.flags = IORESOURCE_MEM,
},
/* IRQ */
[2] = {
.start = IRQ_SBUS_PCIC,
.end = IRQ_SBUS_PCIC,
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_SHAREABLE,
},
};
static struct pata_platform_info pata_platform_data = {
.ioport_shift = 1,
.irq_flags = IRQF_SHARED,
};
static struct platform_device pata_device = {
.name = "pata_platform",
.id = -1,
.num_resources = ARRAY_SIZE(pata_resources),
.resource = pata_resources,
.dev = {
.platform_data = &pata_platform_data,
},
};
#else
/*
* PATA disk driver
*
* For new Playstation 2 PATA driver
*/
static struct resource pata_resources[] = {
/* IO base, 8 16bit registers */
[0] = {
.start = CPHYSADDR(0xb4000040),
.end = CPHYSADDR(0xb4000040 + (8 * 2) - 1),
.flags = IORESOURCE_MEM,
},
/* CTRL base, 1 16bit register */
[1] = {
.start = CPHYSADDR(0xb400005c),
.end = CPHYSADDR(0xb400005c + (1 * 2) - 1),
.flags = IORESOURCE_MEM,
},
/* IRQ */
[2] = {
.start = IRQ_INTC_SBUS,
.end = IRQ_INTC_SBUS,
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_SHAREABLE,
},
};
static struct platform_device pata_device = {
.name = "pata_ps2",
.id = -1,
.num_resources = ARRAY_SIZE(pata_resources),
.resource = pata_resources,
};
#endif
#if 0 /* FIXME */
static struct platform_device smap_device = {
.name = "smap",
.id = -1,
};
static struct platform_device smaprpc_device = {
.name = "smaprpc",
.id = -1,
};
#endif
static void __noreturn ps2_machine_halt(void)
{
local_irq_disable();
cpu_relax_forever();
}
static void __noreturn ps2_machine_restart(char *command)
{
void (* const mips_reset_vec)(void) = (void (*)(void))0xbfc00000;
local_irq_disable();
/* FIXME: Does not work? Does a GPIO reset method exist? */
set_c0_status(ST0_BEV | ST0_ERL);
change_c0_config(CONF_CM_CMASK, CONF_CM_UNCACHED);
__flush_cache_all();
write_c0_wired(0);
mips_reset_vec();
cpu_relax_forever();
}
static inline void iop_cdvd_write_scmd(const u8 scmd) /* FIXME */
{
outb(scmd, 0x1F402016);
}
static inline void iop_cdvd_write_sdin(const u8 sdin) /* FIXME */
{
outb(sdin, 0x1F402017);
}
static void __noreturn power_off(void)
{
local_irq_disable();
outw(inw(0x1f80146c) & 0xFFFE, 0x1f80146c);
outw(0, 0x1f801460);
outw(0, 0x1f80146c);
iop_cdvd_write_sdin(0);
iop_cdvd_write_scmd(0xF); /* Power off */
cpu_relax_forever();
}
void __init plat_mem_setup(void)
{
ioport_resource.start = 0x10000000;
ioport_resource.end = 0x1fffffff;
iomem_resource.start = 0x00000000;
iomem_resource.end = KSEG2 - 1;
add_memory_region(0x00000000, 0x02000000, BOOT_MEM_RAM);
add_memory_region(0x1fc00000, 0x02000000, BOOT_MEM_ROM_DATA);
set_io_port_base(CKSEG1); /* KSEG1 is uncached */
_machine_restart = ps2_machine_restart;
_machine_halt = ps2_machine_halt;
pm_power_off = power_off;
}
static struct platform_device *ps2_platform_devices[] __initdata = {
&iop_device,
&ohci_device,
&gs_device,
&fb_device,
&vu0_device,
&vu1_device,
&pata_device,
#if 0 /* FIXME */
&smap_device,
&smaprpc_device,
#endif
};
static int __init ps2_board_setup(void)
{
printk("PlayStation 2 board setup\n");
/*
* FIXME: As far as I remember the following enables the clock,
* so that ohci->regs->fminterval can count.
*/
// iop_set_dma_dpcr2(IOP_DMA_DPCR2_DEV9);
/* FIXME: D_CTRL: DMA control register: Enable all DMAs. EE User's p. 64 */
return 0;
}
arch_initcall(ps2_board_setup);
static int __init ps2_device_setup(void)
{
ps2rtc_init();
return platform_add_devices(ps2_platform_devices,
ARRAY_SIZE(ps2_platform_devices));
}
device_initcall(ps2_device_setup);
EXPORT_SYMBOL(do_IRQ); /* FIXME */