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