[WATCHDOG] orion5x_wdt: fix compile issue by providing tclk as platform data
[safe/jmp/linux-2.6] / arch / arm / mach-orion5x / common.c
1 /*
2  * arch/arm/mach-orion5x/common.c
3  *
4  * Core functions for Marvell Orion 5x SoCs
5  *
6  * Maintainer: Tzachi Perelstein <tzachi@marvell.com>
7  *
8  * This file is licensed under the terms of the GNU General Public
9  * License version 2.  This program is licensed "as is" without any
10  * warranty of any kind, whether express or implied.
11  */
12
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/serial_8250.h>
17 #include <linux/mbus.h>
18 #include <linux/mv643xx_eth.h>
19 #include <linux/mv643xx_i2c.h>
20 #include <linux/ata_platform.h>
21 #include <linux/spi/orion_spi.h>
22 #include <net/dsa.h>
23 #include <asm/page.h>
24 #include <asm/setup.h>
25 #include <asm/timex.h>
26 #include <asm/mach/arch.h>
27 #include <asm/mach/map.h>
28 #include <asm/mach/time.h>
29 #include <mach/hardware.h>
30 #include <mach/orion5x.h>
31 #include <plat/ehci-orion.h>
32 #include <plat/mv_xor.h>
33 #include <plat/orion_nand.h>
34 #include <plat/orion5x_wdt.h>
35 #include <plat/time.h>
36 #include "common.h"
37
38 /*****************************************************************************
39  * I/O Address Mapping
40  ****************************************************************************/
41 static struct map_desc orion5x_io_desc[] __initdata = {
42         {
43                 .virtual        = ORION5X_REGS_VIRT_BASE,
44                 .pfn            = __phys_to_pfn(ORION5X_REGS_PHYS_BASE),
45                 .length         = ORION5X_REGS_SIZE,
46                 .type           = MT_DEVICE,
47         }, {
48                 .virtual        = ORION5X_PCIE_IO_VIRT_BASE,
49                 .pfn            = __phys_to_pfn(ORION5X_PCIE_IO_PHYS_BASE),
50                 .length         = ORION5X_PCIE_IO_SIZE,
51                 .type           = MT_DEVICE,
52         }, {
53                 .virtual        = ORION5X_PCI_IO_VIRT_BASE,
54                 .pfn            = __phys_to_pfn(ORION5X_PCI_IO_PHYS_BASE),
55                 .length         = ORION5X_PCI_IO_SIZE,
56                 .type           = MT_DEVICE,
57         }, {
58                 .virtual        = ORION5X_PCIE_WA_VIRT_BASE,
59                 .pfn            = __phys_to_pfn(ORION5X_PCIE_WA_PHYS_BASE),
60                 .length         = ORION5X_PCIE_WA_SIZE,
61                 .type           = MT_DEVICE,
62         },
63 };
64
65 void __init orion5x_map_io(void)
66 {
67         iotable_init(orion5x_io_desc, ARRAY_SIZE(orion5x_io_desc));
68 }
69
70
71 /*****************************************************************************
72  * EHCI
73  ****************************************************************************/
74 static struct orion_ehci_data orion5x_ehci_data = {
75         .dram           = &orion5x_mbus_dram_info,
76         .phy_version    = EHCI_PHY_ORION,
77 };
78
79 static u64 ehci_dmamask = 0xffffffffUL;
80
81
82 /*****************************************************************************
83  * EHCI0
84  ****************************************************************************/
85 static struct resource orion5x_ehci0_resources[] = {
86         {
87                 .start  = ORION5X_USB0_PHYS_BASE,
88                 .end    = ORION5X_USB0_PHYS_BASE + SZ_4K - 1,
89                 .flags  = IORESOURCE_MEM,
90         }, {
91                 .start  = IRQ_ORION5X_USB0_CTRL,
92                 .end    = IRQ_ORION5X_USB0_CTRL,
93                 .flags  = IORESOURCE_IRQ,
94         },
95 };
96
97 static struct platform_device orion5x_ehci0 = {
98         .name           = "orion-ehci",
99         .id             = 0,
100         .dev            = {
101                 .dma_mask               = &ehci_dmamask,
102                 .coherent_dma_mask      = 0xffffffff,
103                 .platform_data          = &orion5x_ehci_data,
104         },
105         .resource       = orion5x_ehci0_resources,
106         .num_resources  = ARRAY_SIZE(orion5x_ehci0_resources),
107 };
108
109 void __init orion5x_ehci0_init(void)
110 {
111         platform_device_register(&orion5x_ehci0);
112 }
113
114
115 /*****************************************************************************
116  * EHCI1
117  ****************************************************************************/
118 static struct resource orion5x_ehci1_resources[] = {
119         {
120                 .start  = ORION5X_USB1_PHYS_BASE,
121                 .end    = ORION5X_USB1_PHYS_BASE + SZ_4K - 1,
122                 .flags  = IORESOURCE_MEM,
123         }, {
124                 .start  = IRQ_ORION5X_USB1_CTRL,
125                 .end    = IRQ_ORION5X_USB1_CTRL,
126                 .flags  = IORESOURCE_IRQ,
127         },
128 };
129
130 static struct platform_device orion5x_ehci1 = {
131         .name           = "orion-ehci",
132         .id             = 1,
133         .dev            = {
134                 .dma_mask               = &ehci_dmamask,
135                 .coherent_dma_mask      = 0xffffffff,
136                 .platform_data          = &orion5x_ehci_data,
137         },
138         .resource       = orion5x_ehci1_resources,
139         .num_resources  = ARRAY_SIZE(orion5x_ehci1_resources),
140 };
141
142 void __init orion5x_ehci1_init(void)
143 {
144         platform_device_register(&orion5x_ehci1);
145 }
146
147
148 /*****************************************************************************
149  * GigE
150  ****************************************************************************/
151 struct mv643xx_eth_shared_platform_data orion5x_eth_shared_data = {
152         .dram           = &orion5x_mbus_dram_info,
153 };
154
155 static struct resource orion5x_eth_shared_resources[] = {
156         {
157                 .start  = ORION5X_ETH_PHYS_BASE + 0x2000,
158                 .end    = ORION5X_ETH_PHYS_BASE + 0x3fff,
159                 .flags  = IORESOURCE_MEM,
160         }, {
161                 .start  = IRQ_ORION5X_ETH_ERR,
162                 .end    = IRQ_ORION5X_ETH_ERR,
163                 .flags  = IORESOURCE_IRQ,
164         },
165 };
166
167 static struct platform_device orion5x_eth_shared = {
168         .name           = MV643XX_ETH_SHARED_NAME,
169         .id             = 0,
170         .dev            = {
171                 .platform_data  = &orion5x_eth_shared_data,
172         },
173         .num_resources  = ARRAY_SIZE(orion5x_eth_shared_resources),
174         .resource       = orion5x_eth_shared_resources,
175 };
176
177 static struct resource orion5x_eth_resources[] = {
178         {
179                 .name   = "eth irq",
180                 .start  = IRQ_ORION5X_ETH_SUM,
181                 .end    = IRQ_ORION5X_ETH_SUM,
182                 .flags  = IORESOURCE_IRQ,
183         },
184 };
185
186 static struct platform_device orion5x_eth = {
187         .name           = MV643XX_ETH_NAME,
188         .id             = 0,
189         .num_resources  = 1,
190         .resource       = orion5x_eth_resources,
191 };
192
193 void __init orion5x_eth_init(struct mv643xx_eth_platform_data *eth_data)
194 {
195         eth_data->shared = &orion5x_eth_shared;
196         orion5x_eth.dev.platform_data = eth_data;
197
198         platform_device_register(&orion5x_eth_shared);
199         platform_device_register(&orion5x_eth);
200 }
201
202
203 /*****************************************************************************
204  * Ethernet switch
205  ****************************************************************************/
206 static struct resource orion5x_switch_resources[] = {
207         {
208                 .start  = 0,
209                 .end    = 0,
210                 .flags  = IORESOURCE_IRQ,
211         },
212 };
213
214 static struct platform_device orion5x_switch_device = {
215         .name           = "dsa",
216         .id             = 0,
217         .num_resources  = 0,
218         .resource       = orion5x_switch_resources,
219 };
220
221 void __init orion5x_eth_switch_init(struct dsa_platform_data *d, int irq)
222 {
223         if (irq != NO_IRQ) {
224                 orion5x_switch_resources[0].start = irq;
225                 orion5x_switch_resources[0].end = irq;
226                 orion5x_switch_device.num_resources = 1;
227         }
228
229         d->mii_bus = &orion5x_eth_shared.dev;
230         d->netdev = &orion5x_eth.dev;
231         orion5x_switch_device.dev.platform_data = d;
232
233         platform_device_register(&orion5x_switch_device);
234 }
235
236
237 /*****************************************************************************
238  * I2C
239  ****************************************************************************/
240 static struct mv64xxx_i2c_pdata orion5x_i2c_pdata = {
241         .freq_m         = 8, /* assumes 166 MHz TCLK */
242         .freq_n         = 3,
243         .timeout        = 1000, /* Default timeout of 1 second */
244 };
245
246 static struct resource orion5x_i2c_resources[] = {
247         {
248                 .name   = "i2c base",
249                 .start  = I2C_PHYS_BASE,
250                 .end    = I2C_PHYS_BASE + 0x1f,
251                 .flags  = IORESOURCE_MEM,
252         }, {
253                 .name   = "i2c irq",
254                 .start  = IRQ_ORION5X_I2C,
255                 .end    = IRQ_ORION5X_I2C,
256                 .flags  = IORESOURCE_IRQ,
257         },
258 };
259
260 static struct platform_device orion5x_i2c = {
261         .name           = MV64XXX_I2C_CTLR_NAME,
262         .id             = 0,
263         .num_resources  = ARRAY_SIZE(orion5x_i2c_resources),
264         .resource       = orion5x_i2c_resources,
265         .dev            = {
266                 .platform_data  = &orion5x_i2c_pdata,
267         },
268 };
269
270 void __init orion5x_i2c_init(void)
271 {
272         platform_device_register(&orion5x_i2c);
273 }
274
275
276 /*****************************************************************************
277  * SATA
278  ****************************************************************************/
279 static struct resource orion5x_sata_resources[] = {
280         {
281                 .name   = "sata base",
282                 .start  = ORION5X_SATA_PHYS_BASE,
283                 .end    = ORION5X_SATA_PHYS_BASE + 0x5000 - 1,
284                 .flags  = IORESOURCE_MEM,
285         }, {
286                 .name   = "sata irq",
287                 .start  = IRQ_ORION5X_SATA,
288                 .end    = IRQ_ORION5X_SATA,
289                 .flags  = IORESOURCE_IRQ,
290         },
291 };
292
293 static struct platform_device orion5x_sata = {
294         .name           = "sata_mv",
295         .id             = 0,
296         .dev            = {
297                 .coherent_dma_mask      = 0xffffffff,
298         },
299         .num_resources  = ARRAY_SIZE(orion5x_sata_resources),
300         .resource       = orion5x_sata_resources,
301 };
302
303 void __init orion5x_sata_init(struct mv_sata_platform_data *sata_data)
304 {
305         sata_data->dram = &orion5x_mbus_dram_info;
306         orion5x_sata.dev.platform_data = sata_data;
307         platform_device_register(&orion5x_sata);
308 }
309
310
311 /*****************************************************************************
312  * SPI
313  ****************************************************************************/
314 static struct orion_spi_info orion5x_spi_plat_data = {
315         .tclk                   = 0,
316         .enable_clock_fix       = 1,
317 };
318
319 static struct resource orion5x_spi_resources[] = {
320         {
321                 .name   = "spi base",
322                 .start  = SPI_PHYS_BASE,
323                 .end    = SPI_PHYS_BASE + 0x1f,
324                 .flags  = IORESOURCE_MEM,
325         },
326 };
327
328 static struct platform_device orion5x_spi = {
329         .name           = "orion_spi",
330         .id             = 0,
331         .dev            = {
332                 .platform_data  = &orion5x_spi_plat_data,
333         },
334         .num_resources  = ARRAY_SIZE(orion5x_spi_resources),
335         .resource       = orion5x_spi_resources,
336 };
337
338 void __init orion5x_spi_init()
339 {
340         platform_device_register(&orion5x_spi);
341 }
342
343
344 /*****************************************************************************
345  * UART0
346  ****************************************************************************/
347 static struct plat_serial8250_port orion5x_uart0_data[] = {
348         {
349                 .mapbase        = UART0_PHYS_BASE,
350                 .membase        = (char *)UART0_VIRT_BASE,
351                 .irq            = IRQ_ORION5X_UART0,
352                 .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
353                 .iotype         = UPIO_MEM,
354                 .regshift       = 2,
355                 .uartclk        = 0,
356         }, {
357         },
358 };
359
360 static struct resource orion5x_uart0_resources[] = {
361         {
362                 .start          = UART0_PHYS_BASE,
363                 .end            = UART0_PHYS_BASE + 0xff,
364                 .flags          = IORESOURCE_MEM,
365         }, {
366                 .start          = IRQ_ORION5X_UART0,
367                 .end            = IRQ_ORION5X_UART0,
368                 .flags          = IORESOURCE_IRQ,
369         },
370 };
371
372 static struct platform_device orion5x_uart0 = {
373         .name                   = "serial8250",
374         .id                     = PLAT8250_DEV_PLATFORM,
375         .dev                    = {
376                 .platform_data  = orion5x_uart0_data,
377         },
378         .resource               = orion5x_uart0_resources,
379         .num_resources          = ARRAY_SIZE(orion5x_uart0_resources),
380 };
381
382 void __init orion5x_uart0_init(void)
383 {
384         platform_device_register(&orion5x_uart0);
385 }
386
387
388 /*****************************************************************************
389  * UART1
390  ****************************************************************************/
391 static struct plat_serial8250_port orion5x_uart1_data[] = {
392         {
393                 .mapbase        = UART1_PHYS_BASE,
394                 .membase        = (char *)UART1_VIRT_BASE,
395                 .irq            = IRQ_ORION5X_UART1,
396                 .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
397                 .iotype         = UPIO_MEM,
398                 .regshift       = 2,
399                 .uartclk        = 0,
400         }, {
401         },
402 };
403
404 static struct resource orion5x_uart1_resources[] = {
405         {
406                 .start          = UART1_PHYS_BASE,
407                 .end            = UART1_PHYS_BASE + 0xff,
408                 .flags          = IORESOURCE_MEM,
409         }, {
410                 .start          = IRQ_ORION5X_UART1,
411                 .end            = IRQ_ORION5X_UART1,
412                 .flags          = IORESOURCE_IRQ,
413         },
414 };
415
416 static struct platform_device orion5x_uart1 = {
417         .name                   = "serial8250",
418         .id                     = PLAT8250_DEV_PLATFORM1,
419         .dev                    = {
420                 .platform_data  = orion5x_uart1_data,
421         },
422         .resource               = orion5x_uart1_resources,
423         .num_resources          = ARRAY_SIZE(orion5x_uart1_resources),
424 };
425
426 void __init orion5x_uart1_init(void)
427 {
428         platform_device_register(&orion5x_uart1);
429 }
430
431
432 /*****************************************************************************
433  * XOR engine
434  ****************************************************************************/
435 struct mv_xor_platform_shared_data orion5x_xor_shared_data = {
436         .dram           = &orion5x_mbus_dram_info,
437 };
438
439 static struct resource orion5x_xor_shared_resources[] = {
440         {
441                 .name   = "xor low",
442                 .start  = ORION5X_XOR_PHYS_BASE,
443                 .end    = ORION5X_XOR_PHYS_BASE + 0xff,
444                 .flags  = IORESOURCE_MEM,
445         }, {
446                 .name   = "xor high",
447                 .start  = ORION5X_XOR_PHYS_BASE + 0x200,
448                 .end    = ORION5X_XOR_PHYS_BASE + 0x2ff,
449                 .flags  = IORESOURCE_MEM,
450         },
451 };
452
453 static struct platform_device orion5x_xor_shared = {
454         .name           = MV_XOR_SHARED_NAME,
455         .id             = 0,
456         .dev            = {
457                 .platform_data  = &orion5x_xor_shared_data,
458         },
459         .num_resources  = ARRAY_SIZE(orion5x_xor_shared_resources),
460         .resource       = orion5x_xor_shared_resources,
461 };
462
463 static u64 orion5x_xor_dmamask = DMA_32BIT_MASK;
464
465 static struct resource orion5x_xor0_resources[] = {
466         [0] = {
467                 .start  = IRQ_ORION5X_XOR0,
468                 .end    = IRQ_ORION5X_XOR0,
469                 .flags  = IORESOURCE_IRQ,
470         },
471 };
472
473 static struct mv_xor_platform_data orion5x_xor0_data = {
474         .shared         = &orion5x_xor_shared,
475         .hw_id          = 0,
476         .pool_size      = PAGE_SIZE,
477 };
478
479 static struct platform_device orion5x_xor0_channel = {
480         .name           = MV_XOR_NAME,
481         .id             = 0,
482         .num_resources  = ARRAY_SIZE(orion5x_xor0_resources),
483         .resource       = orion5x_xor0_resources,
484         .dev            = {
485                 .dma_mask               = &orion5x_xor_dmamask,
486                 .coherent_dma_mask      = DMA_64BIT_MASK,
487                 .platform_data          = (void *)&orion5x_xor0_data,
488         },
489 };
490
491 static struct resource orion5x_xor1_resources[] = {
492         [0] = {
493                 .start  = IRQ_ORION5X_XOR1,
494                 .end    = IRQ_ORION5X_XOR1,
495                 .flags  = IORESOURCE_IRQ,
496         },
497 };
498
499 static struct mv_xor_platform_data orion5x_xor1_data = {
500         .shared         = &orion5x_xor_shared,
501         .hw_id          = 1,
502         .pool_size      = PAGE_SIZE,
503 };
504
505 static struct platform_device orion5x_xor1_channel = {
506         .name           = MV_XOR_NAME,
507         .id             = 1,
508         .num_resources  = ARRAY_SIZE(orion5x_xor1_resources),
509         .resource       = orion5x_xor1_resources,
510         .dev            = {
511                 .dma_mask               = &orion5x_xor_dmamask,
512                 .coherent_dma_mask      = DMA_64BIT_MASK,
513                 .platform_data          = (void *)&orion5x_xor1_data,
514         },
515 };
516
517 void __init orion5x_xor_init(void)
518 {
519         platform_device_register(&orion5x_xor_shared);
520
521         /*
522          * two engines can't do memset simultaneously, this limitation
523          * satisfied by removing memset support from one of the engines.
524          */
525         dma_cap_set(DMA_MEMCPY, orion5x_xor0_data.cap_mask);
526         dma_cap_set(DMA_XOR, orion5x_xor0_data.cap_mask);
527         platform_device_register(&orion5x_xor0_channel);
528
529         dma_cap_set(DMA_MEMCPY, orion5x_xor1_data.cap_mask);
530         dma_cap_set(DMA_MEMSET, orion5x_xor1_data.cap_mask);
531         dma_cap_set(DMA_XOR, orion5x_xor1_data.cap_mask);
532         platform_device_register(&orion5x_xor1_channel);
533 }
534
535
536 /*****************************************************************************
537  * Watchdog
538  ****************************************************************************/
539 static struct orion5x_wdt_platform_data orion5x_wdt_data = {
540         .tclk                   = 0,
541 };
542
543 static struct platform_device orion5x_wdt_device = {
544         .name           = "orion5x_wdt",
545         .id             = -1,
546         .dev            = {
547                 .platform_data  = &orion5x_wdt_data,
548         },
549         .num_resources  = 0,
550 };
551
552 void __init orion5x_wdt_init(void)
553 {
554         orion5x_wdt_data.tclk = orion5x_tclk;
555         platform_device_register(&orion5x_wdt_device);
556 }
557
558
559 /*****************************************************************************
560  * Time handling
561  ****************************************************************************/
562 int orion5x_tclk;
563
564 int __init orion5x_find_tclk(void)
565 {
566         u32 dev, rev;
567
568         orion5x_pcie_id(&dev, &rev);
569         if (dev == MV88F6183_DEV_ID &&
570             (readl(MPP_RESET_SAMPLE) & 0x00000200) == 0)
571                 return 133333333;
572
573         return 166666667;
574 }
575
576 static void orion5x_timer_init(void)
577 {
578         orion5x_tclk = orion5x_find_tclk();
579         orion_time_init(IRQ_ORION5X_BRIDGE, orion5x_tclk);
580 }
581
582 struct sys_timer orion5x_timer = {
583         .init = orion5x_timer_init,
584 };
585
586
587 /*****************************************************************************
588  * General
589  ****************************************************************************/
590 /*
591  * Identify device ID and rev from PCIe configuration header space '0'.
592  */
593 static void __init orion5x_id(u32 *dev, u32 *rev, char **dev_name)
594 {
595         orion5x_pcie_id(dev, rev);
596
597         if (*dev == MV88F5281_DEV_ID) {
598                 if (*rev == MV88F5281_REV_D2) {
599                         *dev_name = "MV88F5281-D2";
600                 } else if (*rev == MV88F5281_REV_D1) {
601                         *dev_name = "MV88F5281-D1";
602                 } else if (*rev == MV88F5281_REV_D0) {
603                         *dev_name = "MV88F5281-D0";
604                 } else {
605                         *dev_name = "MV88F5281-Rev-Unsupported";
606                 }
607         } else if (*dev == MV88F5182_DEV_ID) {
608                 if (*rev == MV88F5182_REV_A2) {
609                         *dev_name = "MV88F5182-A2";
610                 } else {
611                         *dev_name = "MV88F5182-Rev-Unsupported";
612                 }
613         } else if (*dev == MV88F5181_DEV_ID) {
614                 if (*rev == MV88F5181_REV_B1) {
615                         *dev_name = "MV88F5181-Rev-B1";
616                 } else if (*rev == MV88F5181L_REV_A1) {
617                         *dev_name = "MV88F5181L-Rev-A1";
618                 } else {
619                         *dev_name = "MV88F5181(L)-Rev-Unsupported";
620                 }
621         } else if (*dev == MV88F6183_DEV_ID) {
622                 if (*rev == MV88F6183_REV_B0) {
623                         *dev_name = "MV88F6183-Rev-B0";
624                 } else {
625                         *dev_name = "MV88F6183-Rev-Unsupported";
626                 }
627         } else {
628                 *dev_name = "Device-Unknown";
629         }
630 }
631
632 void __init orion5x_init(void)
633 {
634         char *dev_name;
635         u32 dev, rev;
636
637         orion5x_id(&dev, &rev, &dev_name);
638         printk(KERN_INFO "Orion ID: %s. TCLK=%d.\n", dev_name, orion5x_tclk);
639
640         orion5x_eth_shared_data.t_clk = orion5x_tclk;
641         orion5x_spi_plat_data.tclk = orion5x_tclk;
642         orion5x_uart0_data[0].uartclk = orion5x_tclk;
643         orion5x_uart1_data[0].uartclk = orion5x_tclk;
644
645         /*
646          * Setup Orion address map
647          */
648         orion5x_setup_cpu_mbus_bridge();
649
650         /*
651          * Don't issue "Wait for Interrupt" instruction if we are
652          * running on D0 5281 silicon.
653          */
654         if (dev == MV88F5281_DEV_ID && rev == MV88F5281_REV_D0) {
655                 printk(KERN_INFO "Orion: Applying 5281 D0 WFI workaround.\n");
656                 disable_hlt();
657         }
658
659         /*
660          * Register watchdog driver
661          */
662         orion5x_wdt_init();
663 }
664
665 /*
666  * Many orion-based systems have buggy bootloader implementations.
667  * This is a common fixup for bogus memory tags.
668  */
669 void __init tag_fixup_mem32(struct machine_desc *mdesc, struct tag *t,
670                             char **from, struct meminfo *meminfo)
671 {
672         for (; t->hdr.size; t = tag_next(t))
673                 if (t->hdr.tag == ATAG_MEM &&
674                     (!t->u.mem.size || t->u.mem.size & ~PAGE_MASK ||
675                      t->u.mem.start & ~PAGE_MASK)) {
676                         printk(KERN_WARNING
677                                "Clearing invalid memory bank %dKB@0x%08x\n",
678                                t->u.mem.size / 1024, t->u.mem.start);
679                         t->hdr.tag = 0;
680                 }
681 }