1
2
3
4
5
6
7
8
9
10
11
12#include <linux/init.h>
13#include <linux/irq.h>
14#include <linux/platform_device.h>
15#include <linux/delay.h>
16#include <linux/gpio.h>
17#include <linux/smsc911x.h>
18#include <linux/mtd/mtd.h>
19#include <linux/mtd/partitions.h>
20#include <linux/mtd/physmap.h>
21#include <linux/mtd/map.h>
22#include <mach/magicpanelr2.h>
23#include <asm/heartbeat.h>
24#include <cpu/sh7720.h>
25
26#define LAN9115_READY (__raw_readl(0xA8000084UL) & 0x00000001UL)
27
28
29static const char *probes[] = { "cmdlinepart", "RedBoot", NULL };
30
31
32static int __init ethernet_reset_finished(void)
33{
34 int i;
35
36 if (LAN9115_READY)
37 return 1;
38
39 for (i = 0; i < 10; ++i) {
40 mdelay(10);
41 if (LAN9115_READY)
42 return 1;
43 }
44
45 return 0;
46}
47
48static void __init reset_ethernet(void)
49{
50
51 CLRBITS_OUTB(0x10, PORT_PMDR);
52
53 udelay(200);
54
55
56 SETBITS_OUTB(0x10, PORT_PMDR);
57}
58
59static void __init setup_chip_select(void)
60{
61
62
63 __raw_writel(0x36db0400, CS2BCR);
64
65 __raw_writel(0x000003c0, CS2WCR);
66
67
68
69 __raw_writel(0x00000200, CS4BCR);
70
71 __raw_writel(0x00100981, CS4WCR);
72
73
74
75 __raw_writel(0x00000200, CS5ABCR);
76
77 __raw_writel(0x00100981, CS5AWCR);
78
79
80
81 __raw_writel(0x00000200, CS5BBCR);
82
83 __raw_writel(0x00100981, CS5BWCR);
84
85
86
87 __raw_writel(0x00000200, CS6ABCR);
88
89 __raw_writel(0x001009C1, CS6AWCR);
90}
91
92static void __init setup_port_multiplexing(void)
93{
94
95
96
97 __raw_writew(0x5555, PORT_PACR);
98
99
100
101
102 __raw_writew(0x5555, PORT_PBCR);
103
104
105
106
107 __raw_writew(0x5500, PORT_PCCR);
108
109
110
111
112 __raw_writew(0x5555, PORT_PDCR);
113
114
115
116
117 __raw_writew(0x3C00, PORT_PECR);
118
119
120
121
122 __raw_writew(0x0002, PORT_PFCR);
123
124
125
126
127 __raw_writew(0x03D5, PORT_PGCR);
128
129
130
131
132 __raw_writew(0x0050, PORT_PHCR);
133
134
135
136
137 __raw_writew(0x0000, PORT_PJCR);
138
139
140
141
142 __raw_writew(0x00FF, PORT_PKCR);
143
144
145
146
147 __raw_writew(0x0000, PORT_PLCR);
148
149
150
151
152
153 __raw_writew(0x5552, PORT_PMCR);
154
155
156
157
158#if CONFIG_SH_MAGIC_PANEL_R2_VERSION == 2
159 __raw_writeb(0x30, PORT_PMDR);
160#elif CONFIG_SH_MAGIC_PANEL_R2_VERSION == 3
161 __raw_writeb(0xF0, PORT_PMDR);
162#else
163#error Unknown revision of PLATFORM_MP_R2
164#endif
165
166
167
168
169
170 __raw_writew(0x0100, PORT_PPCR);
171 __raw_writeb(0x10, PORT_PPDR);
172
173
174
175
176 gpio_request(GPIO_FN_A25, NULL);
177 gpio_request(GPIO_FN_A24, NULL);
178 gpio_request(GPIO_FN_A23, NULL);
179 gpio_request(GPIO_FN_A22, NULL);
180 gpio_request(GPIO_FN_A21, NULL);
181 gpio_request(GPIO_FN_A20, NULL);
182 gpio_request(GPIO_FN_A19, NULL);
183 gpio_request(GPIO_FN_A0, NULL);
184
185
186
187
188 __raw_writew(0x0140, PORT_PSCR);
189
190
191
192
193 __raw_writew(0x0001, PORT_PTCR);
194
195
196
197
198 __raw_writew(0x0240, PORT_PUCR);
199
200
201
202
203 __raw_writew(0x0142, PORT_PVCR);
204}
205
206static void __init mpr2_setup(char **cmdline_p)
207{
208
209
210
211
212 __raw_writew(0xAABC, PORT_PSELA);
213
214
215
216
217 __raw_writew(0x3C00, PORT_PSELB);
218
219
220
221 __raw_writew(0x0000, PORT_PSELC);
222
223
224
225 __raw_writew(0x0000, PORT_PSELD);
226
227 __raw_writew(0x0101, PORT_UTRCTL);
228
229 __raw_writew(0xA5C0, PORT_UCLKCR_W);
230
231 setup_chip_select();
232
233 setup_port_multiplexing();
234
235 reset_ethernet();
236
237 printk(KERN_INFO "Magic Panel Release 2 A.%i\n",
238 CONFIG_SH_MAGIC_PANEL_R2_VERSION);
239
240 if (ethernet_reset_finished() == 0)
241 printk(KERN_WARNING "Ethernet not ready\n");
242}
243
244static struct resource smsc911x_resources[] = {
245 [0] = {
246 .start = 0xa8000000,
247 .end = 0xabffffff,
248 .flags = IORESOURCE_MEM,
249 },
250 [1] = {
251 .start = 35,
252 .end = 35,
253 .flags = IORESOURCE_IRQ,
254 },
255};
256
257static struct smsc911x_platform_config smsc911x_config = {
258 .phy_interface = PHY_INTERFACE_MODE_MII,
259 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
260 .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
261 .flags = SMSC911X_USE_32BIT,
262};
263
264static struct platform_device smsc911x_device = {
265 .name = "smsc911x",
266 .id = -1,
267 .num_resources = ARRAY_SIZE(smsc911x_resources),
268 .resource = smsc911x_resources,
269 .dev = {
270 .platform_data = &smsc911x_config,
271 },
272};
273
274static struct resource heartbeat_resources[] = {
275 [0] = {
276 .start = PA_LED,
277 .end = PA_LED,
278 .flags = IORESOURCE_MEM,
279 },
280};
281
282static struct heartbeat_data heartbeat_data = {
283 .flags = HEARTBEAT_INVERTED,
284};
285
286static struct platform_device heartbeat_device = {
287 .name = "heartbeat",
288 .id = -1,
289 .dev = {
290 .platform_data = &heartbeat_data,
291 },
292 .num_resources = ARRAY_SIZE(heartbeat_resources),
293 .resource = heartbeat_resources,
294};
295
296static struct mtd_partition *parsed_partitions;
297
298static struct mtd_partition mpr2_partitions[] = {
299
300 {
301 .name = "Bootloader",
302 .offset = 0x00000000UL,
303 .size = MPR2_MTD_BOOTLOADER_SIZE,
304 .mask_flags = MTD_WRITEABLE,
305 },
306
307 {
308 .name = "Kernel",
309 .offset = MTDPART_OFS_NXTBLK,
310 .size = MPR2_MTD_KERNEL_SIZE,
311 },
312
313 {
314 .name = "Flash_FS",
315 .offset = MTDPART_OFS_NXTBLK,
316 .size = MTDPART_SIZ_FULL,
317 }
318};
319
320static struct physmap_flash_data flash_data = {
321 .width = 2,
322};
323
324static struct resource flash_resource = {
325 .start = 0x00000000,
326 .end = 0x2000000UL,
327 .flags = IORESOURCE_MEM,
328};
329
330static struct platform_device flash_device = {
331 .name = "physmap-flash",
332 .id = -1,
333 .resource = &flash_resource,
334 .num_resources = 1,
335 .dev = {
336 .platform_data = &flash_data,
337 },
338};
339
340static struct mtd_info *flash_mtd;
341
342static struct map_info mpr2_flash_map = {
343 .name = "Magic Panel R2 Flash",
344 .size = 0x2000000UL,
345 .bankwidth = 2,
346};
347
348static void __init set_mtd_partitions(void)
349{
350 int nr_parts = 0;
351
352 simple_map_init(&mpr2_flash_map);
353 flash_mtd = do_map_probe("cfi_probe", &mpr2_flash_map);
354 nr_parts = parse_mtd_partitions(flash_mtd, probes,
355 &parsed_partitions, 0);
356
357 if (nr_parts <= 0) {
358 flash_data.parts = mpr2_partitions;
359 flash_data.nr_parts = ARRAY_SIZE(mpr2_partitions);
360 } else {
361 flash_data.nr_parts = nr_parts;
362 flash_data.parts = parsed_partitions;
363 }
364}
365
366
367
368
369
370static struct platform_device *mpr2_devices[] __initdata = {
371 &heartbeat_device,
372 &smsc911x_device,
373 &flash_device,
374};
375
376
377static int __init mpr2_devices_setup(void)
378{
379 set_mtd_partitions();
380 return platform_add_devices(mpr2_devices, ARRAY_SIZE(mpr2_devices));
381}
382device_initcall(mpr2_devices_setup);
383
384
385
386
387static void __init init_mpr2_IRQ(void)
388{
389 plat_irq_setup_pins(IRQ_MODE_IRQ);
390
391 irq_set_irq_type(32, IRQ_TYPE_LEVEL_LOW);
392 irq_set_irq_type(33, IRQ_TYPE_LEVEL_LOW);
393 irq_set_irq_type(34, IRQ_TYPE_LEVEL_LOW);
394 irq_set_irq_type(35, IRQ_TYPE_LEVEL_LOW);
395 irq_set_irq_type(36, IRQ_TYPE_EDGE_RISING);
396 irq_set_irq_type(37, IRQ_TYPE_EDGE_FALLING);
397
398 intc_set_priority(32, 13);
399 intc_set_priority(33, 13);
400 intc_set_priority(34, 13);
401 intc_set_priority(35, 6);
402}
403
404
405
406
407
408static struct sh_machine_vector mv_mpr2 __initmv = {
409 .mv_name = "mpr2",
410 .mv_setup = mpr2_setup,
411 .mv_init_irq = init_mpr2_IRQ,
412};
413