[ARM] Orion: instantiate the dsa switch driver
[linux-2.6.git] / arch / arm / mach-kirkwood / common.c
1 /*
2  * arch/arm/mach-kirkwood/common.c
3  *
4  * Core functions for Marvell Kirkwood SoCs
5  *
6  * This file is licensed under the terms of the GNU General Public
7  * License version 2.  This program is licensed "as is" without any
8  * warranty of any kind, whether express or implied.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/serial_8250.h>
15 #include <linux/mbus.h>
16 #include <linux/mv643xx_eth.h>
17 #include <linux/ata_platform.h>
18 #include <linux/spi/orion_spi.h>
19 #include <net/dsa.h>
20 #include <asm/page.h>
21 #include <asm/timex.h>
22 #include <asm/mach/map.h>
23 #include <asm/mach/time.h>
24 #include <mach/kirkwood.h>
25 #include <plat/cache-feroceon-l2.h>
26 #include <plat/ehci-orion.h>
27 #include <plat/mv_xor.h>
28 #include <plat/orion_nand.h>
29 #include <plat/time.h>
30 #include "common.h"
31
32 /*****************************************************************************
33  * I/O Address Mapping
34  ****************************************************************************/
35 static struct map_desc kirkwood_io_desc[] __initdata = {
36         {
37                 .virtual        = KIRKWOOD_PCIE_IO_VIRT_BASE,
38                 .pfn            = __phys_to_pfn(KIRKWOOD_PCIE_IO_PHYS_BASE),
39                 .length         = KIRKWOOD_PCIE_IO_SIZE,
40                 .type           = MT_DEVICE,
41         }, {
42                 .virtual        = KIRKWOOD_REGS_VIRT_BASE,
43                 .pfn            = __phys_to_pfn(KIRKWOOD_REGS_PHYS_BASE),
44                 .length         = KIRKWOOD_REGS_SIZE,
45                 .type           = MT_DEVICE,
46         },
47 };
48
49 void __init kirkwood_map_io(void)
50 {
51         iotable_init(kirkwood_io_desc, ARRAY_SIZE(kirkwood_io_desc));
52 }
53
54
55 /*****************************************************************************
56  * EHCI
57  ****************************************************************************/
58 static struct orion_ehci_data kirkwood_ehci_data = {
59         .dram           = &kirkwood_mbus_dram_info,
60 };
61
62 static u64 ehci_dmamask = 0xffffffffUL;
63
64
65 /*****************************************************************************
66  * EHCI0
67  ****************************************************************************/
68 static struct resource kirkwood_ehci_resources[] = {
69         {
70                 .start  = USB_PHYS_BASE,
71                 .end    = USB_PHYS_BASE + 0x0fff,
72                 .flags  = IORESOURCE_MEM,
73         }, {
74                 .start  = IRQ_KIRKWOOD_USB,
75                 .end    = IRQ_KIRKWOOD_USB,
76                 .flags  = IORESOURCE_IRQ,
77         },
78 };
79
80 static struct platform_device kirkwood_ehci = {
81         .name           = "orion-ehci",
82         .id             = 0,
83         .dev            = {
84                 .dma_mask               = &ehci_dmamask,
85                 .coherent_dma_mask      = 0xffffffff,
86                 .platform_data          = &kirkwood_ehci_data,
87         },
88         .resource       = kirkwood_ehci_resources,
89         .num_resources  = ARRAY_SIZE(kirkwood_ehci_resources),
90 };
91
92 void __init kirkwood_ehci_init(void)
93 {
94         platform_device_register(&kirkwood_ehci);
95 }
96
97
98 /*****************************************************************************
99  * GE00
100  ****************************************************************************/
101 struct mv643xx_eth_shared_platform_data kirkwood_ge00_shared_data = {
102         .dram           = &kirkwood_mbus_dram_info,
103 };
104
105 static struct resource kirkwood_ge00_shared_resources[] = {
106         {
107                 .name   = "ge00 base",
108                 .start  = GE00_PHYS_BASE + 0x2000,
109                 .end    = GE00_PHYS_BASE + 0x3fff,
110                 .flags  = IORESOURCE_MEM,
111         }, {
112                 .name   = "ge00 err irq",
113                 .start  = IRQ_KIRKWOOD_GE00_ERR,
114                 .end    = IRQ_KIRKWOOD_GE00_ERR,
115                 .flags  = IORESOURCE_IRQ,
116         },
117 };
118
119 static struct platform_device kirkwood_ge00_shared = {
120         .name           = MV643XX_ETH_SHARED_NAME,
121         .id             = 0,
122         .dev            = {
123                 .platform_data  = &kirkwood_ge00_shared_data,
124         },
125         .num_resources  = ARRAY_SIZE(kirkwood_ge00_shared_resources),
126         .resource       = kirkwood_ge00_shared_resources,
127 };
128
129 static struct resource kirkwood_ge00_resources[] = {
130         {
131                 .name   = "ge00 irq",
132                 .start  = IRQ_KIRKWOOD_GE00_SUM,
133                 .end    = IRQ_KIRKWOOD_GE00_SUM,
134                 .flags  = IORESOURCE_IRQ,
135         },
136 };
137
138 static struct platform_device kirkwood_ge00 = {
139         .name           = MV643XX_ETH_NAME,
140         .id             = 0,
141         .num_resources  = 1,
142         .resource       = kirkwood_ge00_resources,
143 };
144
145 void __init kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data)
146 {
147         eth_data->shared = &kirkwood_ge00_shared;
148         kirkwood_ge00.dev.platform_data = eth_data;
149
150         platform_device_register(&kirkwood_ge00_shared);
151         platform_device_register(&kirkwood_ge00);
152 }
153
154
155 /*****************************************************************************
156  * Ethernet switch
157  ****************************************************************************/
158 static struct resource kirkwood_switch_resources[] = {
159         {
160                 .start  = 0,
161                 .end    = 0,
162                 .flags  = IORESOURCE_IRQ,
163         },
164 };
165
166 static struct platform_device kirkwood_switch_device = {
167         .name           = "dsa",
168         .id             = 0,
169         .num_resources  = 0,
170         .resource       = kirkwood_switch_resources,
171 };
172
173 void __init kirkwood_ge00_switch_init(struct dsa_platform_data *d, int irq)
174 {
175         if (irq != NO_IRQ) {
176                 kirkwood_switch_resources[0].start = irq;
177                 kirkwood_switch_resources[0].end = irq;
178                 kirkwood_switch_device.num_resources = 1;
179         }
180
181         d->mii_bus = &kirkwood_ge00_shared.dev;
182         d->netdev = &kirkwood_ge00.dev;
183         kirkwood_switch_device.dev.platform_data = d;
184
185         platform_device_register(&kirkwood_switch_device);
186 }
187
188
189 /*****************************************************************************
190  * SoC RTC
191  ****************************************************************************/
192 static struct resource kirkwood_rtc_resource = {
193         .start  = RTC_PHYS_BASE,
194         .end    = RTC_PHYS_BASE + SZ_16 - 1,
195         .flags  = IORESOURCE_MEM,
196 };
197
198 void __init kirkwood_rtc_init(void)
199 {
200         platform_device_register_simple("rtc-mv", -1, &kirkwood_rtc_resource, 1);
201 }
202
203
204 /*****************************************************************************
205  * SATA
206  ****************************************************************************/
207 static struct resource kirkwood_sata_resources[] = {
208         {
209                 .name   = "sata base",
210                 .start  = SATA_PHYS_BASE,
211                 .end    = SATA_PHYS_BASE + 0x5000 - 1,
212                 .flags  = IORESOURCE_MEM,
213         }, {
214                 .name   = "sata irq",
215                 .start  = IRQ_KIRKWOOD_SATA,
216                 .end    = IRQ_KIRKWOOD_SATA,
217                 .flags  = IORESOURCE_IRQ,
218         },
219 };
220
221 static struct platform_device kirkwood_sata = {
222         .name           = "sata_mv",
223         .id             = 0,
224         .dev            = {
225                 .coherent_dma_mask      = 0xffffffff,
226         },
227         .num_resources  = ARRAY_SIZE(kirkwood_sata_resources),
228         .resource       = kirkwood_sata_resources,
229 };
230
231 void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data)
232 {
233         sata_data->dram = &kirkwood_mbus_dram_info;
234         kirkwood_sata.dev.platform_data = sata_data;
235         platform_device_register(&kirkwood_sata);
236 }
237
238
239 /*****************************************************************************
240  * SPI
241  ****************************************************************************/
242 static struct orion_spi_info kirkwood_spi_plat_data = {
243 };
244
245 static struct resource kirkwood_spi_resources[] = {
246         {
247                 .start  = SPI_PHYS_BASE,
248                 .end    = SPI_PHYS_BASE + SZ_512 - 1,
249                 .flags  = IORESOURCE_MEM,
250         },
251 };
252
253 static struct platform_device kirkwood_spi = {
254         .name           = "orion_spi",
255         .id             = 0,
256         .resource       = kirkwood_spi_resources,
257         .dev            = {
258                 .platform_data  = &kirkwood_spi_plat_data,
259         },
260         .num_resources  = ARRAY_SIZE(kirkwood_spi_resources),
261 };
262
263 void __init kirkwood_spi_init()
264 {
265         platform_device_register(&kirkwood_spi);
266 }
267
268
269 /*****************************************************************************
270  * UART0
271  ****************************************************************************/
272 static struct plat_serial8250_port kirkwood_uart0_data[] = {
273         {
274                 .mapbase        = UART0_PHYS_BASE,
275                 .membase        = (char *)UART0_VIRT_BASE,
276                 .irq            = IRQ_KIRKWOOD_UART_0,
277                 .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
278                 .iotype         = UPIO_MEM,
279                 .regshift       = 2,
280                 .uartclk        = 0,
281         }, {
282         },
283 };
284
285 static struct resource kirkwood_uart0_resources[] = {
286         {
287                 .start          = UART0_PHYS_BASE,
288                 .end            = UART0_PHYS_BASE + 0xff,
289                 .flags          = IORESOURCE_MEM,
290         }, {
291                 .start          = IRQ_KIRKWOOD_UART_0,
292                 .end            = IRQ_KIRKWOOD_UART_0,
293                 .flags          = IORESOURCE_IRQ,
294         },
295 };
296
297 static struct platform_device kirkwood_uart0 = {
298         .name                   = "serial8250",
299         .id                     = 0,
300         .dev                    = {
301                 .platform_data  = kirkwood_uart0_data,
302         },
303         .resource               = kirkwood_uart0_resources,
304         .num_resources          = ARRAY_SIZE(kirkwood_uart0_resources),
305 };
306
307 void __init kirkwood_uart0_init(void)
308 {
309         platform_device_register(&kirkwood_uart0);
310 }
311
312
313 /*****************************************************************************
314  * UART1
315  ****************************************************************************/
316 static struct plat_serial8250_port kirkwood_uart1_data[] = {
317         {
318                 .mapbase        = UART1_PHYS_BASE,
319                 .membase        = (char *)UART1_VIRT_BASE,
320                 .irq            = IRQ_KIRKWOOD_UART_1,
321                 .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
322                 .iotype         = UPIO_MEM,
323                 .regshift       = 2,
324                 .uartclk        = 0,
325         }, {
326         },
327 };
328
329 static struct resource kirkwood_uart1_resources[] = {
330         {
331                 .start          = UART1_PHYS_BASE,
332                 .end            = UART1_PHYS_BASE + 0xff,
333                 .flags          = IORESOURCE_MEM,
334         }, {
335                 .start          = IRQ_KIRKWOOD_UART_1,
336                 .end            = IRQ_KIRKWOOD_UART_1,
337                 .flags          = IORESOURCE_IRQ,
338         },
339 };
340
341 static struct platform_device kirkwood_uart1 = {
342         .name                   = "serial8250",
343         .id                     = 1,
344         .dev                    = {
345                 .platform_data  = kirkwood_uart1_data,
346         },
347         .resource               = kirkwood_uart1_resources,
348         .num_resources          = ARRAY_SIZE(kirkwood_uart1_resources),
349 };
350
351 void __init kirkwood_uart1_init(void)
352 {
353         platform_device_register(&kirkwood_uart1);
354 }
355
356
357 /*****************************************************************************
358  * XOR
359  ****************************************************************************/
360 static struct mv_xor_platform_shared_data kirkwood_xor_shared_data = {
361         .dram           = &kirkwood_mbus_dram_info,
362 };
363
364 static u64 kirkwood_xor_dmamask = DMA_32BIT_MASK;
365
366
367 /*****************************************************************************
368  * XOR0
369  ****************************************************************************/
370 static struct resource kirkwood_xor0_shared_resources[] = {
371         {
372                 .name   = "xor 0 low",
373                 .start  = XOR0_PHYS_BASE,
374                 .end    = XOR0_PHYS_BASE + 0xff,
375                 .flags  = IORESOURCE_MEM,
376         }, {
377                 .name   = "xor 0 high",
378                 .start  = XOR0_HIGH_PHYS_BASE,
379                 .end    = XOR0_HIGH_PHYS_BASE + 0xff,
380                 .flags  = IORESOURCE_MEM,
381         },
382 };
383
384 static struct platform_device kirkwood_xor0_shared = {
385         .name           = MV_XOR_SHARED_NAME,
386         .id             = 0,
387         .dev            = {
388                 .platform_data = &kirkwood_xor_shared_data,
389         },
390         .num_resources  = ARRAY_SIZE(kirkwood_xor0_shared_resources),
391         .resource       = kirkwood_xor0_shared_resources,
392 };
393
394 static struct resource kirkwood_xor00_resources[] = {
395         [0] = {
396                 .start  = IRQ_KIRKWOOD_XOR_00,
397                 .end    = IRQ_KIRKWOOD_XOR_00,
398                 .flags  = IORESOURCE_IRQ,
399         },
400 };
401
402 static struct mv_xor_platform_data kirkwood_xor00_data = {
403         .shared         = &kirkwood_xor0_shared,
404         .hw_id          = 0,
405         .pool_size      = PAGE_SIZE,
406 };
407
408 static struct platform_device kirkwood_xor00_channel = {
409         .name           = MV_XOR_NAME,
410         .id             = 0,
411         .num_resources  = ARRAY_SIZE(kirkwood_xor00_resources),
412         .resource       = kirkwood_xor00_resources,
413         .dev            = {
414                 .dma_mask               = &kirkwood_xor_dmamask,
415                 .coherent_dma_mask      = DMA_64BIT_MASK,
416                 .platform_data          = (void *)&kirkwood_xor00_data,
417         },
418 };
419
420 static struct resource kirkwood_xor01_resources[] = {
421         [0] = {
422                 .start  = IRQ_KIRKWOOD_XOR_01,
423                 .end    = IRQ_KIRKWOOD_XOR_01,
424                 .flags  = IORESOURCE_IRQ,
425         },
426 };
427
428 static struct mv_xor_platform_data kirkwood_xor01_data = {
429         .shared         = &kirkwood_xor0_shared,
430         .hw_id          = 1,
431         .pool_size      = PAGE_SIZE,
432 };
433
434 static struct platform_device kirkwood_xor01_channel = {
435         .name           = MV_XOR_NAME,
436         .id             = 1,
437         .num_resources  = ARRAY_SIZE(kirkwood_xor01_resources),
438         .resource       = kirkwood_xor01_resources,
439         .dev            = {
440                 .dma_mask               = &kirkwood_xor_dmamask,
441                 .coherent_dma_mask      = DMA_64BIT_MASK,
442                 .platform_data          = (void *)&kirkwood_xor01_data,
443         },
444 };
445
446 void __init kirkwood_xor0_init(void)
447 {
448         platform_device_register(&kirkwood_xor0_shared);
449
450         /*
451          * two engines can't do memset simultaneously, this limitation
452          * satisfied by removing memset support from one of the engines.
453          */
454         dma_cap_set(DMA_MEMCPY, kirkwood_xor00_data.cap_mask);
455         dma_cap_set(DMA_XOR, kirkwood_xor00_data.cap_mask);
456         platform_device_register(&kirkwood_xor00_channel);
457
458         dma_cap_set(DMA_MEMCPY, kirkwood_xor01_data.cap_mask);
459         dma_cap_set(DMA_MEMSET, kirkwood_xor01_data.cap_mask);
460         dma_cap_set(DMA_XOR, kirkwood_xor01_data.cap_mask);
461         platform_device_register(&kirkwood_xor01_channel);
462 }
463
464
465 /*****************************************************************************
466  * XOR1
467  ****************************************************************************/
468 static struct resource kirkwood_xor1_shared_resources[] = {
469         {
470                 .name   = "xor 1 low",
471                 .start  = XOR1_PHYS_BASE,
472                 .end    = XOR1_PHYS_BASE + 0xff,
473                 .flags  = IORESOURCE_MEM,
474         }, {
475                 .name   = "xor 1 high",
476                 .start  = XOR1_HIGH_PHYS_BASE,
477                 .end    = XOR1_HIGH_PHYS_BASE + 0xff,
478                 .flags  = IORESOURCE_MEM,
479         },
480 };
481
482 static struct platform_device kirkwood_xor1_shared = {
483         .name           = MV_XOR_SHARED_NAME,
484         .id             = 1,
485         .dev            = {
486                 .platform_data = &kirkwood_xor_shared_data,
487         },
488         .num_resources  = ARRAY_SIZE(kirkwood_xor1_shared_resources),
489         .resource       = kirkwood_xor1_shared_resources,
490 };
491
492 static struct resource kirkwood_xor10_resources[] = {
493         [0] = {
494                 .start  = IRQ_KIRKWOOD_XOR_10,
495                 .end    = IRQ_KIRKWOOD_XOR_10,
496                 .flags  = IORESOURCE_IRQ,
497         },
498 };
499
500 static struct mv_xor_platform_data kirkwood_xor10_data = {
501         .shared         = &kirkwood_xor1_shared,
502         .hw_id          = 0,
503         .pool_size      = PAGE_SIZE,
504 };
505
506 static struct platform_device kirkwood_xor10_channel = {
507         .name           = MV_XOR_NAME,
508         .id             = 2,
509         .num_resources  = ARRAY_SIZE(kirkwood_xor10_resources),
510         .resource       = kirkwood_xor10_resources,
511         .dev            = {
512                 .dma_mask               = &kirkwood_xor_dmamask,
513                 .coherent_dma_mask      = DMA_64BIT_MASK,
514                 .platform_data          = (void *)&kirkwood_xor10_data,
515         },
516 };
517
518 static struct resource kirkwood_xor11_resources[] = {
519         [0] = {
520                 .start  = IRQ_KIRKWOOD_XOR_11,
521                 .end    = IRQ_KIRKWOOD_XOR_11,
522                 .flags  = IORESOURCE_IRQ,
523         },
524 };
525
526 static struct mv_xor_platform_data kirkwood_xor11_data = {
527         .shared         = &kirkwood_xor1_shared,
528         .hw_id          = 1,
529         .pool_size      = PAGE_SIZE,
530 };
531
532 static struct platform_device kirkwood_xor11_channel = {
533         .name           = MV_XOR_NAME,
534         .id             = 3,
535         .num_resources  = ARRAY_SIZE(kirkwood_xor11_resources),
536         .resource       = kirkwood_xor11_resources,
537         .dev            = {
538                 .dma_mask               = &kirkwood_xor_dmamask,
539                 .coherent_dma_mask      = DMA_64BIT_MASK,
540                 .platform_data          = (void *)&kirkwood_xor11_data,
541         },
542 };
543
544 void __init kirkwood_xor1_init(void)
545 {
546         platform_device_register(&kirkwood_xor1_shared);
547
548         /*
549          * two engines can't do memset simultaneously, this limitation
550          * satisfied by removing memset support from one of the engines.
551          */
552         dma_cap_set(DMA_MEMCPY, kirkwood_xor10_data.cap_mask);
553         dma_cap_set(DMA_XOR, kirkwood_xor10_data.cap_mask);
554         platform_device_register(&kirkwood_xor10_channel);
555
556         dma_cap_set(DMA_MEMCPY, kirkwood_xor11_data.cap_mask);
557         dma_cap_set(DMA_MEMSET, kirkwood_xor11_data.cap_mask);
558         dma_cap_set(DMA_XOR, kirkwood_xor11_data.cap_mask);
559         platform_device_register(&kirkwood_xor11_channel);
560 }
561
562
563 /*****************************************************************************
564  * Time handling
565  ****************************************************************************/
566 int kirkwood_tclk;
567
568 int __init kirkwood_find_tclk(void)
569 {
570         u32 dev, rev;
571
572         kirkwood_pcie_id(&dev, &rev);
573         if (dev == MV88F6281_DEV_ID && rev == MV88F6281_REV_A0)
574                 return 200000000;
575
576         return 166666667;
577 }
578
579 static void kirkwood_timer_init(void)
580 {
581         kirkwood_tclk = kirkwood_find_tclk();
582         orion_time_init(IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
583 }
584
585 struct sys_timer kirkwood_timer = {
586         .init = kirkwood_timer_init,
587 };
588
589
590 /*****************************************************************************
591  * General
592  ****************************************************************************/
593 /*
594  * Identify device ID and revision.
595  */
596 static char * __init kirkwood_id(void)
597 {
598         u32 dev, rev;
599
600         kirkwood_pcie_id(&dev, &rev);
601
602         if (dev == MV88F6281_DEV_ID) {
603                 if (rev == MV88F6281_REV_Z0)
604                         return "MV88F6281-Z0";
605                 else if (rev == MV88F6281_REV_A0)
606                         return "MV88F6281-A0";
607                 else
608                         return "MV88F6281-Rev-Unsupported";
609         } else if (dev == MV88F6192_DEV_ID) {
610                 if (rev == MV88F6192_REV_Z0)
611                         return "MV88F6192-Z0";
612                 else if (rev == MV88F6192_REV_A0)
613                         return "MV88F6192-A0";
614                 else
615                         return "MV88F6192-Rev-Unsupported";
616         } else if (dev == MV88F6180_DEV_ID) {
617                 if (rev == MV88F6180_REV_A0)
618                         return "MV88F6180-Rev-A0";
619                 else
620                         return "MV88F6180-Rev-Unsupported";
621         } else {
622                 return "Device-Unknown";
623         }
624 }
625
626 static void __init kirkwood_l2_init(void)
627 {
628 #ifdef CONFIG_CACHE_FEROCEON_L2_WRITETHROUGH
629         writel(readl(L2_CONFIG_REG) | L2_WRITETHROUGH, L2_CONFIG_REG);
630         feroceon_l2_init(1);
631 #else
632         writel(readl(L2_CONFIG_REG) & ~L2_WRITETHROUGH, L2_CONFIG_REG);
633         feroceon_l2_init(0);
634 #endif
635 }
636
637 void __init kirkwood_init(void)
638 {
639         printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
640                 kirkwood_id(), kirkwood_tclk);
641         kirkwood_ge00_shared_data.t_clk = kirkwood_tclk;
642         kirkwood_spi_plat_data.tclk = kirkwood_tclk;
643         kirkwood_uart0_data[0].uartclk = kirkwood_tclk;
644         kirkwood_uart1_data[0].uartclk = kirkwood_tclk;
645
646         kirkwood_setup_cpu_mbus();
647
648 #ifdef CONFIG_CACHE_FEROCEON_L2
649         kirkwood_l2_init();
650 #endif
651 }