blob: aa27c154cd0d0e7733a9e8ad38d1e13fb480bde9 [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>
Stanislav Samsonov794d15b2008-06-22 22:45:10 +020016#include <linux/ata_platform.h>
Lennert Buytenhek712424f2009-02-20 02:31:58 +010017#include <linux/ethtool.h>
Stanislav Samsonov794d15b2008-06-22 22:45:10 +020018#include <asm/mach/map.h>
19#include <asm/mach/time.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010020#include <mach/mv78xx0.h>
Nicolas Pitrefdd8b072009-04-22 20:08:17 +010021#include <mach/bridge-regs.h>
Lennert Buytenhek6f088f12008-08-09 13:44:58 +020022#include <plat/cache-feroceon-l2.h>
23#include <plat/ehci-orion.h>
24#include <plat/orion_nand.h>
25#include <plat/time.h>
Andrew Lunn28a2b452011-05-15 13:32:41 +020026#include <plat/common.h>
Stanislav Samsonov794d15b2008-06-22 22:45:10 +020027#include "common.h"
28
Andrew Lunn28a2b452011-05-15 13:32:41 +020029static int get_tclk(void);
Stanislav Samsonov794d15b2008-06-22 22:45:10 +020030
31/*****************************************************************************
32 * Common bits
33 ****************************************************************************/
34int mv78xx0_core_index(void)
35{
36 u32 extra;
37
38 /*
39 * Read Extra Features register.
40 */
41 __asm__("mrc p15, 1, %0, c15, c1, 0" : "=r" (extra));
42
43 return !!(extra & 0x00004000);
44}
45
46static int get_hclk(void)
47{
48 int hclk;
49
50 /*
51 * HCLK tick rate is configured by DEV_D[7:5] pins.
52 */
53 switch ((readl(SAMPLE_AT_RESET_LOW) >> 5) & 7) {
54 case 0:
55 hclk = 166666667;
56 break;
57 case 1:
58 hclk = 200000000;
59 break;
60 case 2:
61 hclk = 266666667;
62 break;
63 case 3:
64 hclk = 333333333;
65 break;
66 case 4:
67 hclk = 400000000;
68 break;
69 default:
70 panic("unknown HCLK PLL setting: %.8x\n",
71 readl(SAMPLE_AT_RESET_LOW));
72 }
73
74 return hclk;
75}
76
77static void get_pclk_l2clk(int hclk, int core_index, int *pclk, int *l2clk)
78{
79 u32 cfg;
80
81 /*
82 * Core #0 PCLK/L2CLK is configured by bits [13:8], core #1
83 * PCLK/L2CLK by bits [19:14].
84 */
85 if (core_index == 0) {
86 cfg = (readl(SAMPLE_AT_RESET_LOW) >> 8) & 0x3f;
87 } else {
88 cfg = (readl(SAMPLE_AT_RESET_LOW) >> 14) & 0x3f;
89 }
90
91 /*
92 * Bits [11:8] ([17:14] for core #1) configure the PCLK:HCLK
93 * ratio (1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6).
94 */
95 *pclk = ((u64)hclk * (2 + (cfg & 0xf))) >> 1;
96
97 /*
98 * Bits [13:12] ([19:18] for core #1) configure the PCLK:L2CLK
99 * ratio (1, 2, 3).
100 */
101 *l2clk = *pclk / (((cfg >> 4) & 3) + 1);
102}
103
104static int get_tclk(void)
105{
106 int tclk;
107
108 /*
109 * TCLK tick rate is configured by DEV_A[2:0] strap pins.
110 */
111 switch ((readl(SAMPLE_AT_RESET_HIGH) >> 6) & 7) {
112 case 1:
113 tclk = 166666667;
114 break;
115 case 3:
116 tclk = 200000000;
117 break;
118 default:
119 panic("unknown TCLK PLL setting: %.8x\n",
120 readl(SAMPLE_AT_RESET_HIGH));
121 }
122
123 return tclk;
124}
125
126
127/*****************************************************************************
128 * I/O Address Mapping
129 ****************************************************************************/
130static struct map_desc mv78xx0_io_desc[] __initdata = {
131 {
132 .virtual = MV78XX0_CORE_REGS_VIRT_BASE,
133 .pfn = 0,
134 .length = MV78XX0_CORE_REGS_SIZE,
135 .type = MT_DEVICE,
136 }, {
137 .virtual = MV78XX0_PCIE_IO_VIRT_BASE(0),
138 .pfn = __phys_to_pfn(MV78XX0_PCIE_IO_PHYS_BASE(0)),
139 .length = MV78XX0_PCIE_IO_SIZE * 8,
140 .type = MT_DEVICE,
141 }, {
142 .virtual = MV78XX0_REGS_VIRT_BASE,
143 .pfn = __phys_to_pfn(MV78XX0_REGS_PHYS_BASE),
144 .length = MV78XX0_REGS_SIZE,
145 .type = MT_DEVICE,
146 },
147};
148
149void __init mv78xx0_map_io(void)
150{
151 unsigned long phys;
152
153 /*
154 * Map the right set of per-core registers depending on
155 * which core we are running on.
156 */
157 if (mv78xx0_core_index() == 0) {
158 phys = MV78XX0_CORE0_REGS_PHYS_BASE;
159 } else {
160 phys = MV78XX0_CORE1_REGS_PHYS_BASE;
161 }
162 mv78xx0_io_desc[0].pfn = __phys_to_pfn(phys);
163
164 iotable_init(mv78xx0_io_desc, ARRAY_SIZE(mv78xx0_io_desc));
165}
166
167
168/*****************************************************************************
169 * EHCI
170 ****************************************************************************/
171static struct orion_ehci_data mv78xx0_ehci_data = {
172 .dram = &mv78xx0_mbus_dram_info,
Ronen Shitritfb6f5522008-09-17 10:08:05 +0300173 .phy_version = EHCI_PHY_NA,
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200174};
175
Andrew Lunn5c602552011-05-15 13:32:40 +0200176static u64 ehci_dmamask = DMA_BIT_MASK(32);
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200177
178
179/*****************************************************************************
180 * EHCI0
181 ****************************************************************************/
182static struct resource mv78xx0_ehci0_resources[] = {
183 {
184 .start = USB0_PHYS_BASE,
Andrew Lunn5c602552011-05-15 13:32:40 +0200185 .end = USB0_PHYS_BASE + SZ_4K - 1,
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200186 .flags = IORESOURCE_MEM,
187 }, {
188 .start = IRQ_MV78XX0_USB_0,
189 .end = IRQ_MV78XX0_USB_0,
190 .flags = IORESOURCE_IRQ,
191 },
192};
193
194static struct platform_device mv78xx0_ehci0 = {
195 .name = "orion-ehci",
196 .id = 0,
197 .dev = {
198 .dma_mask = &ehci_dmamask,
Andrew Lunn5c602552011-05-15 13:32:40 +0200199 .coherent_dma_mask = DMA_BIT_MASK(32),
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200200 .platform_data = &mv78xx0_ehci_data,
201 },
202 .resource = mv78xx0_ehci0_resources,
203 .num_resources = ARRAY_SIZE(mv78xx0_ehci0_resources),
204};
205
206void __init mv78xx0_ehci0_init(void)
207{
208 platform_device_register(&mv78xx0_ehci0);
209}
210
211
212/*****************************************************************************
213 * EHCI1
214 ****************************************************************************/
215static struct resource mv78xx0_ehci1_resources[] = {
216 {
217 .start = USB1_PHYS_BASE,
Andrew Lunn5c602552011-05-15 13:32:40 +0200218 .end = USB1_PHYS_BASE + SZ_4K - 1,
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200219 .flags = IORESOURCE_MEM,
220 }, {
221 .start = IRQ_MV78XX0_USB_1,
222 .end = IRQ_MV78XX0_USB_1,
223 .flags = IORESOURCE_IRQ,
224 },
225};
226
227static struct platform_device mv78xx0_ehci1 = {
228 .name = "orion-ehci",
229 .id = 1,
230 .dev = {
231 .dma_mask = &ehci_dmamask,
Andrew Lunn5c602552011-05-15 13:32:40 +0200232 .coherent_dma_mask = DMA_BIT_MASK(32),
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200233 .platform_data = &mv78xx0_ehci_data,
234 },
235 .resource = mv78xx0_ehci1_resources,
236 .num_resources = ARRAY_SIZE(mv78xx0_ehci1_resources),
237};
238
239void __init mv78xx0_ehci1_init(void)
240{
241 platform_device_register(&mv78xx0_ehci1);
242}
243
244
245/*****************************************************************************
246 * EHCI2
247 ****************************************************************************/
248static struct resource mv78xx0_ehci2_resources[] = {
249 {
250 .start = USB2_PHYS_BASE,
Andrew Lunn5c602552011-05-15 13:32:40 +0200251 .end = USB2_PHYS_BASE + SZ_4K - 1,
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200252 .flags = IORESOURCE_MEM,
253 }, {
254 .start = IRQ_MV78XX0_USB_2,
255 .end = IRQ_MV78XX0_USB_2,
256 .flags = IORESOURCE_IRQ,
257 },
258};
259
260static struct platform_device mv78xx0_ehci2 = {
261 .name = "orion-ehci",
262 .id = 2,
263 .dev = {
264 .dma_mask = &ehci_dmamask,
Andrew Lunn5c602552011-05-15 13:32:40 +0200265 .coherent_dma_mask = DMA_BIT_MASK(32),
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200266 .platform_data = &mv78xx0_ehci_data,
267 },
268 .resource = mv78xx0_ehci2_resources,
269 .num_resources = ARRAY_SIZE(mv78xx0_ehci2_resources),
270};
271
272void __init mv78xx0_ehci2_init(void)
273{
274 platform_device_register(&mv78xx0_ehci2);
275}
276
277
278/*****************************************************************************
279 * GE00
280 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200281void __init mv78xx0_ge00_init(struct mv643xx_eth_platform_data *eth_data)
282{
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200283 orion_ge00_init(eth_data, &mv78xx0_mbus_dram_info,
284 GE00_PHYS_BASE, IRQ_MV78XX0_GE00_SUM,
285 IRQ_MV78XX0_GE_ERR, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200286}
287
288
289/*****************************************************************************
290 * GE01
291 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200292void __init mv78xx0_ge01_init(struct mv643xx_eth_platform_data *eth_data)
293{
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200294 orion_ge01_init(eth_data, &mv78xx0_mbus_dram_info,
295 GE01_PHYS_BASE, IRQ_MV78XX0_GE01_SUM,
296 NO_IRQ, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200297}
298
299
300/*****************************************************************************
301 * GE10
302 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200303void __init mv78xx0_ge10_init(struct mv643xx_eth_platform_data *eth_data)
304{
Lennert Buytenhek712424f2009-02-20 02:31:58 +0100305 u32 dev, rev;
306
Lennert Buytenhek712424f2009-02-20 02:31:58 +0100307 /*
308 * On the Z0, ge10 and ge11 are internally connected back
309 * to back, and not brought out.
310 */
311 mv78xx0_pcie_id(&dev, &rev);
312 if (dev == MV78X00_Z0_DEV_ID) {
313 eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
314 eth_data->speed = SPEED_1000;
315 eth_data->duplex = DUPLEX_FULL;
316 }
317
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200318 orion_ge10_init(eth_data, &mv78xx0_mbus_dram_info,
319 GE10_PHYS_BASE, IRQ_MV78XX0_GE10_SUM,
320 NO_IRQ, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200321}
322
323
324/*****************************************************************************
325 * GE11
326 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200327void __init mv78xx0_ge11_init(struct mv643xx_eth_platform_data *eth_data)
328{
Lennert Buytenhek712424f2009-02-20 02:31:58 +0100329 u32 dev, rev;
330
Lennert Buytenhek712424f2009-02-20 02:31:58 +0100331 /*
332 * On the Z0, ge10 and ge11 are internally connected back
333 * to back, and not brought out.
334 */
335 mv78xx0_pcie_id(&dev, &rev);
336 if (dev == MV78X00_Z0_DEV_ID) {
337 eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
338 eth_data->speed = SPEED_1000;
339 eth_data->duplex = DUPLEX_FULL;
340 }
341
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200342 orion_ge11_init(eth_data, &mv78xx0_mbus_dram_info,
343 GE11_PHYS_BASE, IRQ_MV78XX0_GE11_SUM,
344 NO_IRQ, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200345}
346
Riku Voipio69359942009-03-03 21:13:50 +0200347/*****************************************************************************
Andrew Lunnaac7ffa2011-05-15 13:32:45 +0200348 * I2C
Riku Voipio69359942009-03-03 21:13:50 +0200349 ****************************************************************************/
Riku Voipio69359942009-03-03 21:13:50 +0200350void __init mv78xx0_i2c_init(void)
351{
Andrew Lunnaac7ffa2011-05-15 13:32:45 +0200352 orion_i2c_init(I2C_0_PHYS_BASE, IRQ_MV78XX0_I2C_0, 8);
353 orion_i2c_1_init(I2C_1_PHYS_BASE, IRQ_MV78XX0_I2C_1, 8);
Riku Voipio69359942009-03-03 21:13:50 +0200354}
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200355
356/*****************************************************************************
357 * SATA
358 ****************************************************************************/
359static struct resource mv78xx0_sata_resources[] = {
360 {
361 .name = "sata base",
362 .start = SATA_PHYS_BASE,
363 .end = SATA_PHYS_BASE + 0x5000 - 1,
364 .flags = IORESOURCE_MEM,
365 }, {
366 .name = "sata irq",
367 .start = IRQ_MV78XX0_SATA,
368 .end = IRQ_MV78XX0_SATA,
369 .flags = IORESOURCE_IRQ,
370 },
371};
372
373static struct platform_device mv78xx0_sata = {
374 .name = "sata_mv",
375 .id = 0,
376 .dev = {
Andrew Lunn5c602552011-05-15 13:32:40 +0200377 .coherent_dma_mask = DMA_BIT_MASK(32),
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200378 },
379 .num_resources = ARRAY_SIZE(mv78xx0_sata_resources),
380 .resource = mv78xx0_sata_resources,
381};
382
383void __init mv78xx0_sata_init(struct mv_sata_platform_data *sata_data)
384{
385 sata_data->dram = &mv78xx0_mbus_dram_info;
386 mv78xx0_sata.dev.platform_data = sata_data;
387 platform_device_register(&mv78xx0_sata);
388}
389
390
391/*****************************************************************************
392 * UART0
393 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200394void __init mv78xx0_uart0_init(void)
395{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200396 orion_uart0_init(UART0_VIRT_BASE, UART0_PHYS_BASE,
397 IRQ_MV78XX0_UART_0, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200398}
399
400
401/*****************************************************************************
402 * UART1
403 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200404void __init mv78xx0_uart1_init(void)
405{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200406 orion_uart1_init(UART1_VIRT_BASE, UART1_PHYS_BASE,
407 IRQ_MV78XX0_UART_1, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200408}
409
410
411/*****************************************************************************
412 * UART2
413 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200414void __init mv78xx0_uart2_init(void)
415{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200416 orion_uart2_init(UART2_VIRT_BASE, UART2_PHYS_BASE,
417 IRQ_MV78XX0_UART_2, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200418}
419
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200420/*****************************************************************************
421 * UART3
422 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200423void __init mv78xx0_uart3_init(void)
424{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200425 orion_uart3_init(UART3_VIRT_BASE, UART3_PHYS_BASE,
426 IRQ_MV78XX0_UART_3, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200427}
428
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200429/*****************************************************************************
430 * Time handling
431 ****************************************************************************/
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200432void __init mv78xx0_init_early(void)
433{
434 orion_time_set_base(TIMER_VIRT_BASE);
435}
436
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200437static void mv78xx0_timer_init(void)
438{
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200439 orion_time_init(BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
440 IRQ_MV78XX0_TIMER_1, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200441}
442
443struct sys_timer mv78xx0_timer = {
444 .init = mv78xx0_timer_init,
445};
446
447
448/*****************************************************************************
449 * General
450 ****************************************************************************/
Lennert Buytenhekcfdeb632009-02-20 02:31:35 +0100451static char * __init mv78xx0_id(void)
452{
453 u32 dev, rev;
454
455 mv78xx0_pcie_id(&dev, &rev);
456
457 if (dev == MV78X00_Z0_DEV_ID) {
458 if (rev == MV78X00_REV_Z0)
459 return "MV78X00-Z0";
460 else
461 return "MV78X00-Rev-Unsupported";
462 } else if (dev == MV78100_DEV_ID) {
463 if (rev == MV78100_REV_A0)
464 return "MV78100-A0";
Lennert Buytenhek662aece2009-09-30 13:02:42 -0700465 else if (rev == MV78100_REV_A1)
466 return "MV78100-A1";
Lennert Buytenhekcfdeb632009-02-20 02:31:35 +0100467 else
468 return "MV78100-Rev-Unsupported";
469 } else if (dev == MV78200_DEV_ID) {
470 if (rev == MV78100_REV_A0)
471 return "MV78200-A0";
472 else
473 return "MV78200-Rev-Unsupported";
474 } else {
475 return "Device-Unknown";
476 }
477}
478
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200479static int __init is_l2_writethrough(void)
480{
481 return !!(readl(CPU_CONTROL) & L2_WRITETHROUGH);
482}
483
484void __init mv78xx0_init(void)
485{
486 int core_index;
487 int hclk;
488 int pclk;
489 int l2clk;
490 int tclk;
491
492 core_index = mv78xx0_core_index();
493 hclk = get_hclk();
494 get_pclk_l2clk(hclk, core_index, &pclk, &l2clk);
495 tclk = get_tclk();
496
Lennert Buytenhekcfdeb632009-02-20 02:31:35 +0100497 printk(KERN_INFO "%s ", mv78xx0_id());
498 printk("core #%d, ", core_index);
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200499 printk("PCLK = %dMHz, ", (pclk + 499999) / 1000000);
500 printk("L2 = %dMHz, ", (l2clk + 499999) / 1000000);
501 printk("HCLK = %dMHz, ", (hclk + 499999) / 1000000);
502 printk("TCLK = %dMHz\n", (tclk + 499999) / 1000000);
503
504 mv78xx0_setup_cpu_mbus();
505
506#ifdef CONFIG_CACHE_FEROCEON_L2
507 feroceon_l2_init(is_l2_writethrough());
508#endif
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200509}