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