ALSA: Fix debugfs_create_dir's error checking method for sound/soc/
[linux-2.6] / 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 <asm/page.h>
20 #include <asm/timex.h>
21 #include <asm/mach/map.h>
22 #include <asm/mach/time.h>
23 #include <mach/kirkwood.h>
24 #include <plat/cache-feroceon-l2.h>
25 #include <plat/ehci-orion.h>
26 #include <plat/mv_xor.h>
27 #include <plat/orion_nand.h>
28 #include <plat/time.h>
29 #include "common.h"
30
31 /*****************************************************************************
32  * I/O Address Mapping
33  ****************************************************************************/
34 static struct map_desc kirkwood_io_desc[] __initdata = {
35         {
36                 .virtual        = KIRKWOOD_PCIE_IO_VIRT_BASE,
37                 .pfn            = __phys_to_pfn(KIRKWOOD_PCIE_IO_PHYS_BASE),
38                 .length         = KIRKWOOD_PCIE_IO_SIZE,
39                 .type           = MT_DEVICE,
40         }, {
41                 .virtual        = KIRKWOOD_REGS_VIRT_BASE,
42                 .pfn            = __phys_to_pfn(KIRKWOOD_REGS_PHYS_BASE),
43                 .length         = KIRKWOOD_REGS_SIZE,
44                 .type           = MT_DEVICE,
45         },
46 };
47
48 void __init kirkwood_map_io(void)
49 {
50         iotable_init(kirkwood_io_desc, ARRAY_SIZE(kirkwood_io_desc));
51 }
52
53
54 /*****************************************************************************
55  * EHCI
56  ****************************************************************************/
57 static struct orion_ehci_data kirkwood_ehci_data = {
58         .dram           = &kirkwood_mbus_dram_info,
59 };
60
61 static u64 ehci_dmamask = 0xffffffffUL;
62
63
64 /*****************************************************************************
65  * EHCI0
66  ****************************************************************************/
67 static struct resource kirkwood_ehci_resources[] = {
68         {
69                 .start  = USB_PHYS_BASE,
70                 .end    = USB_PHYS_BASE + 0x0fff,
71                 .flags  = IORESOURCE_MEM,
72         }, {
73                 .start  = IRQ_KIRKWOOD_USB,
74                 .end    = IRQ_KIRKWOOD_USB,
75                 .flags  = IORESOURCE_IRQ,
76         },
77 };
78
79 static struct platform_device kirkwood_ehci = {
80         .name           = "orion-ehci",
81         .id             = 0,
82         .dev            = {
83                 .dma_mask               = &ehci_dmamask,
84                 .coherent_dma_mask      = 0xffffffff,
85                 .platform_data          = &kirkwood_ehci_data,
86         },
87         .resource       = kirkwood_ehci_resources,
88         .num_resources  = ARRAY_SIZE(kirkwood_ehci_resources),
89 };
90
91 void __init kirkwood_ehci_init(void)
92 {
93         platform_device_register(&kirkwood_ehci);
94 }
95
96
97 /*****************************************************************************
98  * GE00
99  ****************************************************************************/
100 struct mv643xx_eth_shared_platform_data kirkwood_ge00_shared_data = {
101         .t_clk          = KIRKWOOD_TCLK,
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 };
113
114 static struct platform_device kirkwood_ge00_shared = {
115         .name           = MV643XX_ETH_SHARED_NAME,
116         .id             = 0,
117         .dev            = {
118                 .platform_data  = &kirkwood_ge00_shared_data,
119         },
120         .num_resources  = 1,
121         .resource       = kirkwood_ge00_shared_resources,
122 };
123
124 static struct resource kirkwood_ge00_resources[] = {
125         {
126                 .name   = "ge00 irq",
127                 .start  = IRQ_KIRKWOOD_GE00_SUM,
128                 .end    = IRQ_KIRKWOOD_GE00_SUM,
129                 .flags  = IORESOURCE_IRQ,
130         },
131 };
132
133 static struct platform_device kirkwood_ge00 = {
134         .name           = MV643XX_ETH_NAME,
135         .id             = 0,
136         .num_resources  = 1,
137         .resource       = kirkwood_ge00_resources,
138 };
139
140 void __init kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data)
141 {
142         eth_data->shared = &kirkwood_ge00_shared;
143         kirkwood_ge00.dev.platform_data = eth_data;
144
145         platform_device_register(&kirkwood_ge00_shared);
146         platform_device_register(&kirkwood_ge00);
147 }
148
149
150 /*****************************************************************************
151  * SoC RTC
152  ****************************************************************************/
153 static struct resource kirkwood_rtc_resource = {
154         .start  = RTC_PHYS_BASE,
155         .end    = RTC_PHYS_BASE + SZ_16 - 1,
156         .flags  = IORESOURCE_MEM,
157 };
158
159 void __init kirkwood_rtc_init(void)
160 {
161         platform_device_register_simple("rtc-mv", -1, &kirkwood_rtc_resource, 1);
162 }
163
164
165 /*****************************************************************************
166  * SATA
167  ****************************************************************************/
168 static struct resource kirkwood_sata_resources[] = {
169         {
170                 .name   = "sata base",
171                 .start  = SATA_PHYS_BASE,
172                 .end    = SATA_PHYS_BASE + 0x5000 - 1,
173                 .flags  = IORESOURCE_MEM,
174         }, {
175                 .name   = "sata irq",
176                 .start  = IRQ_KIRKWOOD_SATA,
177                 .end    = IRQ_KIRKWOOD_SATA,
178                 .flags  = IORESOURCE_IRQ,
179         },
180 };
181
182 static struct platform_device kirkwood_sata = {
183         .name           = "sata_mv",
184         .id             = 0,
185         .dev            = {
186                 .coherent_dma_mask      = 0xffffffff,
187         },
188         .num_resources  = ARRAY_SIZE(kirkwood_sata_resources),
189         .resource       = kirkwood_sata_resources,
190 };
191
192 void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data)
193 {
194         sata_data->dram = &kirkwood_mbus_dram_info;
195         kirkwood_sata.dev.platform_data = sata_data;
196         platform_device_register(&kirkwood_sata);
197 }
198
199
200 /*****************************************************************************
201  * SPI
202  ****************************************************************************/
203 static struct orion_spi_info kirkwood_spi_plat_data = {
204         .tclk           = KIRKWOOD_TCLK,
205 };
206
207 static struct resource kirkwood_spi_resources[] = {
208         {
209                 .start  = SPI_PHYS_BASE,
210                 .end    = SPI_PHYS_BASE + SZ_512 - 1,
211                 .flags  = IORESOURCE_MEM,
212         },
213 };
214
215 static struct platform_device kirkwood_spi = {
216         .name           = "orion_spi",
217         .id             = 0,
218         .resource       = kirkwood_spi_resources,
219         .dev            = {
220                 .platform_data  = &kirkwood_spi_plat_data,
221         },
222         .num_resources  = ARRAY_SIZE(kirkwood_spi_resources),
223 };
224
225 void __init kirkwood_spi_init()
226 {
227         platform_device_register(&kirkwood_spi);
228 }
229
230
231 /*****************************************************************************
232  * UART0
233  ****************************************************************************/
234 static struct plat_serial8250_port kirkwood_uart0_data[] = {
235         {
236                 .mapbase        = UART0_PHYS_BASE,
237                 .membase        = (char *)UART0_VIRT_BASE,
238                 .irq            = IRQ_KIRKWOOD_UART_0,
239                 .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
240                 .iotype         = UPIO_MEM,
241                 .regshift       = 2,
242                 .uartclk        = KIRKWOOD_TCLK,
243         }, {
244         },
245 };
246
247 static struct resource kirkwood_uart0_resources[] = {
248         {
249                 .start          = UART0_PHYS_BASE,
250                 .end            = UART0_PHYS_BASE + 0xff,
251                 .flags          = IORESOURCE_MEM,
252         }, {
253                 .start          = IRQ_KIRKWOOD_UART_0,
254                 .end            = IRQ_KIRKWOOD_UART_0,
255                 .flags          = IORESOURCE_IRQ,
256         },
257 };
258
259 static struct platform_device kirkwood_uart0 = {
260         .name                   = "serial8250",
261         .id                     = 0,
262         .dev                    = {
263                 .platform_data  = kirkwood_uart0_data,
264         },
265         .resource               = kirkwood_uart0_resources,
266         .num_resources          = ARRAY_SIZE(kirkwood_uart0_resources),
267 };
268
269 void __init kirkwood_uart0_init(void)
270 {
271         platform_device_register(&kirkwood_uart0);
272 }
273
274
275 /*****************************************************************************
276  * UART1
277  ****************************************************************************/
278 static struct plat_serial8250_port kirkwood_uart1_data[] = {
279         {
280                 .mapbase        = UART1_PHYS_BASE,
281                 .membase        = (char *)UART1_VIRT_BASE,
282                 .irq            = IRQ_KIRKWOOD_UART_1,
283                 .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
284                 .iotype         = UPIO_MEM,
285                 .regshift       = 2,
286                 .uartclk        = KIRKWOOD_TCLK,
287         }, {
288         },
289 };
290
291 static struct resource kirkwood_uart1_resources[] = {
292         {
293                 .start          = UART1_PHYS_BASE,
294                 .end            = UART1_PHYS_BASE + 0xff,
295                 .flags          = IORESOURCE_MEM,
296         }, {
297                 .start          = IRQ_KIRKWOOD_UART_1,
298                 .end            = IRQ_KIRKWOOD_UART_1,
299                 .flags          = IORESOURCE_IRQ,
300         },
301 };
302
303 static struct platform_device kirkwood_uart1 = {
304         .name                   = "serial8250",
305         .id                     = 1,
306         .dev                    = {
307                 .platform_data  = kirkwood_uart1_data,
308         },
309         .resource               = kirkwood_uart1_resources,
310         .num_resources          = ARRAY_SIZE(kirkwood_uart1_resources),
311 };
312
313 void __init kirkwood_uart1_init(void)
314 {
315         platform_device_register(&kirkwood_uart1);
316 }
317
318
319 /*****************************************************************************
320  * XOR
321  ****************************************************************************/
322 static struct mv_xor_platform_shared_data kirkwood_xor_shared_data = {
323         .dram           = &kirkwood_mbus_dram_info,
324 };
325
326 static u64 kirkwood_xor_dmamask = DMA_32BIT_MASK;
327
328
329 /*****************************************************************************
330  * XOR0
331  ****************************************************************************/
332 static struct resource kirkwood_xor0_shared_resources[] = {
333         {
334                 .name   = "xor 0 low",
335                 .start  = XOR0_PHYS_BASE,
336                 .end    = XOR0_PHYS_BASE + 0xff,
337                 .flags  = IORESOURCE_MEM,
338         }, {
339                 .name   = "xor 0 high",
340                 .start  = XOR0_HIGH_PHYS_BASE,
341                 .end    = XOR0_HIGH_PHYS_BASE + 0xff,
342                 .flags  = IORESOURCE_MEM,
343         },
344 };
345
346 static struct platform_device kirkwood_xor0_shared = {
347         .name           = MV_XOR_SHARED_NAME,
348         .id             = 0,
349         .dev            = {
350                 .platform_data = &kirkwood_xor_shared_data,
351         },
352         .num_resources  = ARRAY_SIZE(kirkwood_xor0_shared_resources),
353         .resource       = kirkwood_xor0_shared_resources,
354 };
355
356 static struct resource kirkwood_xor00_resources[] = {
357         [0] = {
358                 .start  = IRQ_KIRKWOOD_XOR_00,
359                 .end    = IRQ_KIRKWOOD_XOR_00,
360                 .flags  = IORESOURCE_IRQ,
361         },
362 };
363
364 static struct mv_xor_platform_data kirkwood_xor00_data = {
365         .shared         = &kirkwood_xor0_shared,
366         .hw_id          = 0,
367         .pool_size      = PAGE_SIZE,
368 };
369
370 static struct platform_device kirkwood_xor00_channel = {
371         .name           = MV_XOR_NAME,
372         .id             = 0,
373         .num_resources  = ARRAY_SIZE(kirkwood_xor00_resources),
374         .resource       = kirkwood_xor00_resources,
375         .dev            = {
376                 .dma_mask               = &kirkwood_xor_dmamask,
377                 .coherent_dma_mask      = DMA_64BIT_MASK,
378                 .platform_data          = (void *)&kirkwood_xor00_data,
379         },
380 };
381
382 static struct resource kirkwood_xor01_resources[] = {
383         [0] = {
384                 .start  = IRQ_KIRKWOOD_XOR_01,
385                 .end    = IRQ_KIRKWOOD_XOR_01,
386                 .flags  = IORESOURCE_IRQ,
387         },
388 };
389
390 static struct mv_xor_platform_data kirkwood_xor01_data = {
391         .shared         = &kirkwood_xor0_shared,
392         .hw_id          = 1,
393         .pool_size      = PAGE_SIZE,
394 };
395
396 static struct platform_device kirkwood_xor01_channel = {
397         .name           = MV_XOR_NAME,
398         .id             = 1,
399         .num_resources  = ARRAY_SIZE(kirkwood_xor01_resources),
400         .resource       = kirkwood_xor01_resources,
401         .dev            = {
402                 .dma_mask               = &kirkwood_xor_dmamask,
403                 .coherent_dma_mask      = DMA_64BIT_MASK,
404                 .platform_data          = (void *)&kirkwood_xor01_data,
405         },
406 };
407
408 void __init kirkwood_xor0_init(void)
409 {
410         platform_device_register(&kirkwood_xor0_shared);
411
412         /*
413          * two engines can't do memset simultaneously, this limitation
414          * satisfied by removing memset support from one of the engines.
415          */
416         dma_cap_set(DMA_MEMCPY, kirkwood_xor00_data.cap_mask);
417         dma_cap_set(DMA_XOR, kirkwood_xor00_data.cap_mask);
418         platform_device_register(&kirkwood_xor00_channel);
419
420         dma_cap_set(DMA_MEMCPY, kirkwood_xor01_data.cap_mask);
421         dma_cap_set(DMA_MEMSET, kirkwood_xor01_data.cap_mask);
422         dma_cap_set(DMA_XOR, kirkwood_xor01_data.cap_mask);
423         platform_device_register(&kirkwood_xor01_channel);
424 }
425
426
427 /*****************************************************************************
428  * XOR1
429  ****************************************************************************/
430 static struct resource kirkwood_xor1_shared_resources[] = {
431         {
432                 .name   = "xor 1 low",
433                 .start  = XOR1_PHYS_BASE,
434                 .end    = XOR1_PHYS_BASE + 0xff,
435                 .flags  = IORESOURCE_MEM,
436         }, {
437                 .name   = "xor 1 high",
438                 .start  = XOR1_HIGH_PHYS_BASE,
439                 .end    = XOR1_HIGH_PHYS_BASE + 0xff,
440                 .flags  = IORESOURCE_MEM,
441         },
442 };
443
444 static struct platform_device kirkwood_xor1_shared = {
445         .name           = MV_XOR_SHARED_NAME,
446         .id             = 1,
447         .dev            = {
448                 .platform_data = &kirkwood_xor_shared_data,
449         },
450         .num_resources  = ARRAY_SIZE(kirkwood_xor1_shared_resources),
451         .resource       = kirkwood_xor1_shared_resources,
452 };
453
454 static struct resource kirkwood_xor10_resources[] = {
455         [0] = {
456                 .start  = IRQ_KIRKWOOD_XOR_10,
457                 .end    = IRQ_KIRKWOOD_XOR_10,
458                 .flags  = IORESOURCE_IRQ,
459         },
460 };
461
462 static struct mv_xor_platform_data kirkwood_xor10_data = {
463         .shared         = &kirkwood_xor1_shared,
464         .hw_id          = 0,
465         .pool_size      = PAGE_SIZE,
466 };
467
468 static struct platform_device kirkwood_xor10_channel = {
469         .name           = MV_XOR_NAME,
470         .id             = 2,
471         .num_resources  = ARRAY_SIZE(kirkwood_xor10_resources),
472         .resource       = kirkwood_xor10_resources,
473         .dev            = {
474                 .dma_mask               = &kirkwood_xor_dmamask,
475                 .coherent_dma_mask      = DMA_64BIT_MASK,
476                 .platform_data          = (void *)&kirkwood_xor10_data,
477         },
478 };
479
480 static struct resource kirkwood_xor11_resources[] = {
481         [0] = {
482                 .start  = IRQ_KIRKWOOD_XOR_11,
483                 .end    = IRQ_KIRKWOOD_XOR_11,
484                 .flags  = IORESOURCE_IRQ,
485         },
486 };
487
488 static struct mv_xor_platform_data kirkwood_xor11_data = {
489         .shared         = &kirkwood_xor1_shared,
490         .hw_id          = 1,
491         .pool_size      = PAGE_SIZE,
492 };
493
494 static struct platform_device kirkwood_xor11_channel = {
495         .name           = MV_XOR_NAME,
496         .id             = 3,
497         .num_resources  = ARRAY_SIZE(kirkwood_xor11_resources),
498         .resource       = kirkwood_xor11_resources,
499         .dev            = {
500                 .dma_mask               = &kirkwood_xor_dmamask,
501                 .coherent_dma_mask      = DMA_64BIT_MASK,
502                 .platform_data          = (void *)&kirkwood_xor11_data,
503         },
504 };
505
506 void __init kirkwood_xor1_init(void)
507 {
508         platform_device_register(&kirkwood_xor1_shared);
509
510         /*
511          * two engines can't do memset simultaneously, this limitation
512          * satisfied by removing memset support from one of the engines.
513          */
514         dma_cap_set(DMA_MEMCPY, kirkwood_xor10_data.cap_mask);
515         dma_cap_set(DMA_XOR, kirkwood_xor10_data.cap_mask);
516         platform_device_register(&kirkwood_xor10_channel);
517
518         dma_cap_set(DMA_MEMCPY, kirkwood_xor11_data.cap_mask);
519         dma_cap_set(DMA_MEMSET, kirkwood_xor11_data.cap_mask);
520         dma_cap_set(DMA_XOR, kirkwood_xor11_data.cap_mask);
521         platform_device_register(&kirkwood_xor11_channel);
522 }
523
524
525 /*****************************************************************************
526  * Time handling
527  ****************************************************************************/
528 static void kirkwood_timer_init(void)
529 {
530         orion_time_init(IRQ_KIRKWOOD_BRIDGE, KIRKWOOD_TCLK);
531 }
532
533 struct sys_timer kirkwood_timer = {
534         .init = kirkwood_timer_init,
535 };
536
537
538 /*****************************************************************************
539  * General
540  ****************************************************************************/
541 static char * __init kirkwood_id(void)
542 {
543         switch (readl(DEVICE_ID) & 0x3) {
544         case 0:
545                 return "88F6180";
546         case 1:
547                 return "88F6192";
548         case 2:
549                 return "88F6281";
550         }
551
552         return "unknown 88F6000 variant";
553 }
554
555 static int __init is_l2_writethrough(void)
556 {
557         return !!(readl(L2_CONFIG_REG) & L2_WRITETHROUGH);
558 }
559
560 void __init kirkwood_init(void)
561 {
562         printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
563                 kirkwood_id(), KIRKWOOD_TCLK);
564
565         kirkwood_setup_cpu_mbus();
566
567 #ifdef CONFIG_CACHE_FEROCEON_L2
568         feroceon_l2_init(is_l2_writethrough());
569 #endif
570 }