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