blob: 0fd9a83299107c1cb7e105730aea99d38ce02a12 [file] [log] [blame]
Stanislav Samsonov794d15b2008-06-22 22:45:10 +02001/*
2 * arch/arm/mach-mv78xx0/common.c
3 *
4 * Core functions for Marvell MV78xx0 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>
Riku Voipio69359942009-03-03 21:13:50 +020016#include <linux/mv643xx_i2c.h>
Stanislav Samsonov794d15b2008-06-22 22:45:10 +020017#include <linux/ata_platform.h>
Lennert Buytenhek712424f2009-02-20 02:31:58 +010018#include <linux/ethtool.h>
Stanislav Samsonov794d15b2008-06-22 22:45:10 +020019#include <asm/mach/map.h>
20#include <asm/mach/time.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010021#include <mach/mv78xx0.h>
Nicolas Pitrefdd8b072009-04-22 20:08:17 +010022#include <mach/bridge-regs.h>
Lennert Buytenhek6f088f12008-08-09 13:44:58 +020023#include <plat/cache-feroceon-l2.h>
24#include <plat/ehci-orion.h>
25#include <plat/orion_nand.h>
26#include <plat/time.h>
Andrew Lunn28a2b452011-05-15 13:32:41 +020027#include <plat/common.h>
Stanislav Samsonov794d15b2008-06-22 22:45:10 +020028#include "common.h"
29
Andrew Lunn28a2b452011-05-15 13:32:41 +020030static int get_tclk(void);
Stanislav Samsonov794d15b2008-06-22 22:45:10 +020031
32/*****************************************************************************
33 * Common bits
34 ****************************************************************************/
35int mv78xx0_core_index(void)
36{
37 u32 extra;
38
39 /*
40 * Read Extra Features register.
41 */
42 __asm__("mrc p15, 1, %0, c15, c1, 0" : "=r" (extra));
43
44 return !!(extra & 0x00004000);
45}
46
47static int get_hclk(void)
48{
49 int hclk;
50
51 /*
52 * HCLK tick rate is configured by DEV_D[7:5] pins.
53 */
54 switch ((readl(SAMPLE_AT_RESET_LOW) >> 5) & 7) {
55 case 0:
56 hclk = 166666667;
57 break;
58 case 1:
59 hclk = 200000000;
60 break;
61 case 2:
62 hclk = 266666667;
63 break;
64 case 3:
65 hclk = 333333333;
66 break;
67 case 4:
68 hclk = 400000000;
69 break;
70 default:
71 panic("unknown HCLK PLL setting: %.8x\n",
72 readl(SAMPLE_AT_RESET_LOW));
73 }
74
75 return hclk;
76}
77
78static void get_pclk_l2clk(int hclk, int core_index, int *pclk, int *l2clk)
79{
80 u32 cfg;
81
82 /*
83 * Core #0 PCLK/L2CLK is configured by bits [13:8], core #1
84 * PCLK/L2CLK by bits [19:14].
85 */
86 if (core_index == 0) {
87 cfg = (readl(SAMPLE_AT_RESET_LOW) >> 8) & 0x3f;
88 } else {
89 cfg = (readl(SAMPLE_AT_RESET_LOW) >> 14) & 0x3f;
90 }
91
92 /*
93 * Bits [11:8] ([17:14] for core #1) configure the PCLK:HCLK
94 * ratio (1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6).
95 */
96 *pclk = ((u64)hclk * (2 + (cfg & 0xf))) >> 1;
97
98 /*
99 * Bits [13:12] ([19:18] for core #1) configure the PCLK:L2CLK
100 * ratio (1, 2, 3).
101 */
102 *l2clk = *pclk / (((cfg >> 4) & 3) + 1);
103}
104
105static int get_tclk(void)
106{
107 int tclk;
108
109 /*
110 * TCLK tick rate is configured by DEV_A[2:0] strap pins.
111 */
112 switch ((readl(SAMPLE_AT_RESET_HIGH) >> 6) & 7) {
113 case 1:
114 tclk = 166666667;
115 break;
116 case 3:
117 tclk = 200000000;
118 break;
119 default:
120 panic("unknown TCLK PLL setting: %.8x\n",
121 readl(SAMPLE_AT_RESET_HIGH));
122 }
123
124 return tclk;
125}
126
127
128/*****************************************************************************
129 * I/O Address Mapping
130 ****************************************************************************/
131static struct map_desc mv78xx0_io_desc[] __initdata = {
132 {
133 .virtual = MV78XX0_CORE_REGS_VIRT_BASE,
134 .pfn = 0,
135 .length = MV78XX0_CORE_REGS_SIZE,
136 .type = MT_DEVICE,
137 }, {
138 .virtual = MV78XX0_PCIE_IO_VIRT_BASE(0),
139 .pfn = __phys_to_pfn(MV78XX0_PCIE_IO_PHYS_BASE(0)),
140 .length = MV78XX0_PCIE_IO_SIZE * 8,
141 .type = MT_DEVICE,
142 }, {
143 .virtual = MV78XX0_REGS_VIRT_BASE,
144 .pfn = __phys_to_pfn(MV78XX0_REGS_PHYS_BASE),
145 .length = MV78XX0_REGS_SIZE,
146 .type = MT_DEVICE,
147 },
148};
149
150void __init mv78xx0_map_io(void)
151{
152 unsigned long phys;
153
154 /*
155 * Map the right set of per-core registers depending on
156 * which core we are running on.
157 */
158 if (mv78xx0_core_index() == 0) {
159 phys = MV78XX0_CORE0_REGS_PHYS_BASE;
160 } else {
161 phys = MV78XX0_CORE1_REGS_PHYS_BASE;
162 }
163 mv78xx0_io_desc[0].pfn = __phys_to_pfn(phys);
164
165 iotable_init(mv78xx0_io_desc, ARRAY_SIZE(mv78xx0_io_desc));
166}
167
168
169/*****************************************************************************
170 * EHCI
171 ****************************************************************************/
172static struct orion_ehci_data mv78xx0_ehci_data = {
173 .dram = &mv78xx0_mbus_dram_info,
Ronen Shitritfb6f5522008-09-17 10:08:05 +0300174 .phy_version = EHCI_PHY_NA,
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200175};
176
Andrew Lunn5c602552011-05-15 13:32:40 +0200177static u64 ehci_dmamask = DMA_BIT_MASK(32);
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200178
179
180/*****************************************************************************
181 * EHCI0
182 ****************************************************************************/
183static struct resource mv78xx0_ehci0_resources[] = {
184 {
185 .start = USB0_PHYS_BASE,
Andrew Lunn5c602552011-05-15 13:32:40 +0200186 .end = USB0_PHYS_BASE + SZ_4K - 1,
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200187 .flags = IORESOURCE_MEM,
188 }, {
189 .start = IRQ_MV78XX0_USB_0,
190 .end = IRQ_MV78XX0_USB_0,
191 .flags = IORESOURCE_IRQ,
192 },
193};
194
195static struct platform_device mv78xx0_ehci0 = {
196 .name = "orion-ehci",
197 .id = 0,
198 .dev = {
199 .dma_mask = &ehci_dmamask,
Andrew Lunn5c602552011-05-15 13:32:40 +0200200 .coherent_dma_mask = DMA_BIT_MASK(32),
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200201 .platform_data = &mv78xx0_ehci_data,
202 },
203 .resource = mv78xx0_ehci0_resources,
204 .num_resources = ARRAY_SIZE(mv78xx0_ehci0_resources),
205};
206
207void __init mv78xx0_ehci0_init(void)
208{
209 platform_device_register(&mv78xx0_ehci0);
210}
211
212
213/*****************************************************************************
214 * EHCI1
215 ****************************************************************************/
216static struct resource mv78xx0_ehci1_resources[] = {
217 {
218 .start = USB1_PHYS_BASE,
Andrew Lunn5c602552011-05-15 13:32:40 +0200219 .end = USB1_PHYS_BASE + SZ_4K - 1,
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200220 .flags = IORESOURCE_MEM,
221 }, {
222 .start = IRQ_MV78XX0_USB_1,
223 .end = IRQ_MV78XX0_USB_1,
224 .flags = IORESOURCE_IRQ,
225 },
226};
227
228static struct platform_device mv78xx0_ehci1 = {
229 .name = "orion-ehci",
230 .id = 1,
231 .dev = {
232 .dma_mask = &ehci_dmamask,
Andrew Lunn5c602552011-05-15 13:32:40 +0200233 .coherent_dma_mask = DMA_BIT_MASK(32),
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200234 .platform_data = &mv78xx0_ehci_data,
235 },
236 .resource = mv78xx0_ehci1_resources,
237 .num_resources = ARRAY_SIZE(mv78xx0_ehci1_resources),
238};
239
240void __init mv78xx0_ehci1_init(void)
241{
242 platform_device_register(&mv78xx0_ehci1);
243}
244
245
246/*****************************************************************************
247 * EHCI2
248 ****************************************************************************/
249static struct resource mv78xx0_ehci2_resources[] = {
250 {
251 .start = USB2_PHYS_BASE,
Andrew Lunn5c602552011-05-15 13:32:40 +0200252 .end = USB2_PHYS_BASE + SZ_4K - 1,
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200253 .flags = IORESOURCE_MEM,
254 }, {
255 .start = IRQ_MV78XX0_USB_2,
256 .end = IRQ_MV78XX0_USB_2,
257 .flags = IORESOURCE_IRQ,
258 },
259};
260
261static struct platform_device mv78xx0_ehci2 = {
262 .name = "orion-ehci",
263 .id = 2,
264 .dev = {
265 .dma_mask = &ehci_dmamask,
Andrew Lunn5c602552011-05-15 13:32:40 +0200266 .coherent_dma_mask = DMA_BIT_MASK(32),
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200267 .platform_data = &mv78xx0_ehci_data,
268 },
269 .resource = mv78xx0_ehci2_resources,
270 .num_resources = ARRAY_SIZE(mv78xx0_ehci2_resources),
271};
272
273void __init mv78xx0_ehci2_init(void)
274{
275 platform_device_register(&mv78xx0_ehci2);
276}
277
278
279/*****************************************************************************
280 * GE00
281 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200282void __init mv78xx0_ge00_init(struct mv643xx_eth_platform_data *eth_data)
283{
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200284 orion_ge00_init(eth_data, &mv78xx0_mbus_dram_info,
285 GE00_PHYS_BASE, IRQ_MV78XX0_GE00_SUM,
286 IRQ_MV78XX0_GE_ERR, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200287}
288
289
290/*****************************************************************************
291 * GE01
292 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200293void __init mv78xx0_ge01_init(struct mv643xx_eth_platform_data *eth_data)
294{
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200295 orion_ge01_init(eth_data, &mv78xx0_mbus_dram_info,
296 GE01_PHYS_BASE, IRQ_MV78XX0_GE01_SUM,
297 NO_IRQ, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200298}
299
300
301/*****************************************************************************
302 * GE10
303 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200304void __init mv78xx0_ge10_init(struct mv643xx_eth_platform_data *eth_data)
305{
Lennert Buytenhek712424f2009-02-20 02:31:58 +0100306 u32 dev, rev;
307
Lennert Buytenhek712424f2009-02-20 02:31:58 +0100308 /*
309 * On the Z0, ge10 and ge11 are internally connected back
310 * to back, and not brought out.
311 */
312 mv78xx0_pcie_id(&dev, &rev);
313 if (dev == MV78X00_Z0_DEV_ID) {
314 eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
315 eth_data->speed = SPEED_1000;
316 eth_data->duplex = DUPLEX_FULL;
317 }
318
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200319 orion_ge10_init(eth_data, &mv78xx0_mbus_dram_info,
320 GE10_PHYS_BASE, IRQ_MV78XX0_GE10_SUM,
321 NO_IRQ, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200322}
323
324
325/*****************************************************************************
326 * GE11
327 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200328void __init mv78xx0_ge11_init(struct mv643xx_eth_platform_data *eth_data)
329{
Lennert Buytenhek712424f2009-02-20 02:31:58 +0100330 u32 dev, rev;
331
Lennert Buytenhek712424f2009-02-20 02:31:58 +0100332 /*
333 * On the Z0, ge10 and ge11 are internally connected back
334 * to back, and not brought out.
335 */
336 mv78xx0_pcie_id(&dev, &rev);
337 if (dev == MV78X00_Z0_DEV_ID) {
338 eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
339 eth_data->speed = SPEED_1000;
340 eth_data->duplex = DUPLEX_FULL;
341 }
342
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200343 orion_ge11_init(eth_data, &mv78xx0_mbus_dram_info,
344 GE11_PHYS_BASE, IRQ_MV78XX0_GE11_SUM,
345 NO_IRQ, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200346}
347
Riku Voipio69359942009-03-03 21:13:50 +0200348/*****************************************************************************
349 * I2C bus 0
350 ****************************************************************************/
351
352static struct mv64xxx_i2c_pdata mv78xx0_i2c_0_pdata = {
353 .freq_m = 8, /* assumes 166 MHz TCLK */
354 .freq_n = 3,
355 .timeout = 1000, /* Default timeout of 1 second */
356};
357
358static struct resource mv78xx0_i2c_0_resources[] = {
359 {
Riku Voipio69359942009-03-03 21:13:50 +0200360 .start = I2C_0_PHYS_BASE,
361 .end = I2C_0_PHYS_BASE + 0x1f,
362 .flags = IORESOURCE_MEM,
363 }, {
Riku Voipio69359942009-03-03 21:13:50 +0200364 .start = IRQ_MV78XX0_I2C_0,
365 .end = IRQ_MV78XX0_I2C_0,
366 .flags = IORESOURCE_IRQ,
367 },
368};
369
370
371static struct platform_device mv78xx0_i2c_0 = {
372 .name = MV64XXX_I2C_CTLR_NAME,
373 .id = 0,
374 .num_resources = ARRAY_SIZE(mv78xx0_i2c_0_resources),
375 .resource = mv78xx0_i2c_0_resources,
376 .dev = {
377 .platform_data = &mv78xx0_i2c_0_pdata,
378 },
379};
380
381/*****************************************************************************
382 * I2C bus 1
383 ****************************************************************************/
384
385static struct mv64xxx_i2c_pdata mv78xx0_i2c_1_pdata = {
386 .freq_m = 8, /* assumes 166 MHz TCLK */
387 .freq_n = 3,
388 .timeout = 1000, /* Default timeout of 1 second */
389};
390
391static struct resource mv78xx0_i2c_1_resources[] = {
392 {
Riku Voipio69359942009-03-03 21:13:50 +0200393 .start = I2C_1_PHYS_BASE,
394 .end = I2C_1_PHYS_BASE + 0x1f,
395 .flags = IORESOURCE_MEM,
396 }, {
Riku Voipio69359942009-03-03 21:13:50 +0200397 .start = IRQ_MV78XX0_I2C_1,
398 .end = IRQ_MV78XX0_I2C_1,
399 .flags = IORESOURCE_IRQ,
400 },
401};
402
403
404static struct platform_device mv78xx0_i2c_1 = {
405 .name = MV64XXX_I2C_CTLR_NAME,
406 .id = 1,
407 .num_resources = ARRAY_SIZE(mv78xx0_i2c_1_resources),
408 .resource = mv78xx0_i2c_1_resources,
409 .dev = {
410 .platform_data = &mv78xx0_i2c_1_pdata,
411 },
412};
413
414void __init mv78xx0_i2c_init(void)
415{
416 platform_device_register(&mv78xx0_i2c_0);
417 platform_device_register(&mv78xx0_i2c_1);
418}
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200419
420/*****************************************************************************
421 * SATA
422 ****************************************************************************/
423static struct resource mv78xx0_sata_resources[] = {
424 {
425 .name = "sata base",
426 .start = SATA_PHYS_BASE,
427 .end = SATA_PHYS_BASE + 0x5000 - 1,
428 .flags = IORESOURCE_MEM,
429 }, {
430 .name = "sata irq",
431 .start = IRQ_MV78XX0_SATA,
432 .end = IRQ_MV78XX0_SATA,
433 .flags = IORESOURCE_IRQ,
434 },
435};
436
437static struct platform_device mv78xx0_sata = {
438 .name = "sata_mv",
439 .id = 0,
440 .dev = {
Andrew Lunn5c602552011-05-15 13:32:40 +0200441 .coherent_dma_mask = DMA_BIT_MASK(32),
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200442 },
443 .num_resources = ARRAY_SIZE(mv78xx0_sata_resources),
444 .resource = mv78xx0_sata_resources,
445};
446
447void __init mv78xx0_sata_init(struct mv_sata_platform_data *sata_data)
448{
449 sata_data->dram = &mv78xx0_mbus_dram_info;
450 mv78xx0_sata.dev.platform_data = sata_data;
451 platform_device_register(&mv78xx0_sata);
452}
453
454
455/*****************************************************************************
456 * UART0
457 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200458void __init mv78xx0_uart0_init(void)
459{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200460 orion_uart0_init(UART0_VIRT_BASE, UART0_PHYS_BASE,
461 IRQ_MV78XX0_UART_0, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200462}
463
464
465/*****************************************************************************
466 * UART1
467 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200468void __init mv78xx0_uart1_init(void)
469{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200470 orion_uart1_init(UART1_VIRT_BASE, UART1_PHYS_BASE,
471 IRQ_MV78XX0_UART_1, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200472}
473
474
475/*****************************************************************************
476 * UART2
477 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200478void __init mv78xx0_uart2_init(void)
479{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200480 orion_uart2_init(UART2_VIRT_BASE, UART2_PHYS_BASE,
481 IRQ_MV78XX0_UART_2, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200482}
483
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200484/*****************************************************************************
485 * UART3
486 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200487void __init mv78xx0_uart3_init(void)
488{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200489 orion_uart3_init(UART3_VIRT_BASE, UART3_PHYS_BASE,
490 IRQ_MV78XX0_UART_3, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200491}
492
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200493/*****************************************************************************
494 * Time handling
495 ****************************************************************************/
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200496void __init mv78xx0_init_early(void)
497{
498 orion_time_set_base(TIMER_VIRT_BASE);
499}
500
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200501static void mv78xx0_timer_init(void)
502{
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200503 orion_time_init(BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
504 IRQ_MV78XX0_TIMER_1, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200505}
506
507struct sys_timer mv78xx0_timer = {
508 .init = mv78xx0_timer_init,
509};
510
511
512/*****************************************************************************
513 * General
514 ****************************************************************************/
Lennert Buytenhekcfdeb632009-02-20 02:31:35 +0100515static char * __init mv78xx0_id(void)
516{
517 u32 dev, rev;
518
519 mv78xx0_pcie_id(&dev, &rev);
520
521 if (dev == MV78X00_Z0_DEV_ID) {
522 if (rev == MV78X00_REV_Z0)
523 return "MV78X00-Z0";
524 else
525 return "MV78X00-Rev-Unsupported";
526 } else if (dev == MV78100_DEV_ID) {
527 if (rev == MV78100_REV_A0)
528 return "MV78100-A0";
Lennert Buytenhek662aece2009-09-30 13:02:42 -0700529 else if (rev == MV78100_REV_A1)
530 return "MV78100-A1";
Lennert Buytenhekcfdeb632009-02-20 02:31:35 +0100531 else
532 return "MV78100-Rev-Unsupported";
533 } else if (dev == MV78200_DEV_ID) {
534 if (rev == MV78100_REV_A0)
535 return "MV78200-A0";
536 else
537 return "MV78200-Rev-Unsupported";
538 } else {
539 return "Device-Unknown";
540 }
541}
542
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200543static int __init is_l2_writethrough(void)
544{
545 return !!(readl(CPU_CONTROL) & L2_WRITETHROUGH);
546}
547
548void __init mv78xx0_init(void)
549{
550 int core_index;
551 int hclk;
552 int pclk;
553 int l2clk;
554 int tclk;
555
556 core_index = mv78xx0_core_index();
557 hclk = get_hclk();
558 get_pclk_l2clk(hclk, core_index, &pclk, &l2clk);
559 tclk = get_tclk();
560
Lennert Buytenhekcfdeb632009-02-20 02:31:35 +0100561 printk(KERN_INFO "%s ", mv78xx0_id());
562 printk("core #%d, ", core_index);
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200563 printk("PCLK = %dMHz, ", (pclk + 499999) / 1000000);
564 printk("L2 = %dMHz, ", (l2clk + 499999) / 1000000);
565 printk("HCLK = %dMHz, ", (hclk + 499999) / 1000000);
566 printk("TCLK = %dMHz\n", (tclk + 499999) / 1000000);
567
568 mv78xx0_setup_cpu_mbus();
569
570#ifdef CONFIG_CACHE_FEROCEON_L2
571 feroceon_l2_init(is_l2_writethrough());
572#endif
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200573}