blob: a5dcf766a3f9ca53a050c8f4be1ec2823ac98145 [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>
Stanislav Samsonov794d15b2008-06-22 22:45:10 +020015#include <linux/ata_platform.h>
Lennert Buytenhek712424f2009-02-20 02:31:58 +010016#include <linux/ethtool.h>
Stanislav Samsonov794d15b2008-06-22 22:45:10 +020017#include <asm/mach/map.h>
18#include <asm/mach/time.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010019#include <mach/mv78xx0.h>
Nicolas Pitrefdd8b072009-04-22 20:08:17 +010020#include <mach/bridge-regs.h>
Lennert Buytenhek6f088f12008-08-09 13:44:58 +020021#include <plat/cache-feroceon-l2.h>
Andrew Lunn72053352012-02-08 15:52:47 +010022#include <plat/ehci-orion.h>
Lennert Buytenhek6f088f12008-08-09 13:44:58 +020023#include <plat/orion_nand.h>
24#include <plat/time.h>
Andrew Lunn28a2b452011-05-15 13:32:41 +020025#include <plat/common.h>
Andrew Lunn45173d52011-12-07 21:48:06 +010026#include <plat/addr-map.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 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200171void __init mv78xx0_ehci0_init(void)
172{
Andrew Lunn72053352012-02-08 15:52:47 +0100173 orion_ehci_init(USB0_PHYS_BASE, IRQ_MV78XX0_USB_0, EHCI_PHY_NA);
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200174}
175
176
177/*****************************************************************************
178 * EHCI1
179 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200180void __init mv78xx0_ehci1_init(void)
181{
Andrew Lunndb33f4d2011-12-07 21:48:08 +0100182 orion_ehci_1_init(USB1_PHYS_BASE, IRQ_MV78XX0_USB_1);
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200183}
184
185
186/*****************************************************************************
187 * EHCI2
188 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200189void __init mv78xx0_ehci2_init(void)
190{
Andrew Lunndb33f4d2011-12-07 21:48:08 +0100191 orion_ehci_2_init(USB2_PHYS_BASE, IRQ_MV78XX0_USB_2);
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200192}
193
194
195/*****************************************************************************
196 * GE00
197 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200198void __init mv78xx0_ge00_init(struct mv643xx_eth_platform_data *eth_data)
199{
Andrew Lunndb33f4d2011-12-07 21:48:08 +0100200 orion_ge00_init(eth_data,
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200201 GE00_PHYS_BASE, IRQ_MV78XX0_GE00_SUM,
202 IRQ_MV78XX0_GE_ERR, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200203}
204
205
206/*****************************************************************************
207 * GE01
208 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200209void __init mv78xx0_ge01_init(struct mv643xx_eth_platform_data *eth_data)
210{
Andrew Lunndb33f4d2011-12-07 21:48:08 +0100211 orion_ge01_init(eth_data,
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200212 GE01_PHYS_BASE, IRQ_MV78XX0_GE01_SUM,
213 NO_IRQ, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200214}
215
216
217/*****************************************************************************
218 * GE10
219 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200220void __init mv78xx0_ge10_init(struct mv643xx_eth_platform_data *eth_data)
221{
Lennert Buytenhek712424f2009-02-20 02:31:58 +0100222 u32 dev, rev;
223
Lennert Buytenhek712424f2009-02-20 02:31:58 +0100224 /*
225 * On the Z0, ge10 and ge11 are internally connected back
226 * to back, and not brought out.
227 */
228 mv78xx0_pcie_id(&dev, &rev);
229 if (dev == MV78X00_Z0_DEV_ID) {
230 eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
231 eth_data->speed = SPEED_1000;
232 eth_data->duplex = DUPLEX_FULL;
233 }
234
Andrew Lunndb33f4d2011-12-07 21:48:08 +0100235 orion_ge10_init(eth_data,
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200236 GE10_PHYS_BASE, IRQ_MV78XX0_GE10_SUM,
237 NO_IRQ, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200238}
239
240
241/*****************************************************************************
242 * GE11
243 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200244void __init mv78xx0_ge11_init(struct mv643xx_eth_platform_data *eth_data)
245{
Lennert Buytenhek712424f2009-02-20 02:31:58 +0100246 u32 dev, rev;
247
Lennert Buytenhek712424f2009-02-20 02:31:58 +0100248 /*
249 * On the Z0, ge10 and ge11 are internally connected back
250 * to back, and not brought out.
251 */
252 mv78xx0_pcie_id(&dev, &rev);
253 if (dev == MV78X00_Z0_DEV_ID) {
254 eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
255 eth_data->speed = SPEED_1000;
256 eth_data->duplex = DUPLEX_FULL;
257 }
258
Andrew Lunndb33f4d2011-12-07 21:48:08 +0100259 orion_ge11_init(eth_data,
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200260 GE11_PHYS_BASE, IRQ_MV78XX0_GE11_SUM,
261 NO_IRQ, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200262}
263
Riku Voipio69359942009-03-03 21:13:50 +0200264/*****************************************************************************
Andrew Lunnaac7ffa2011-05-15 13:32:45 +0200265 * I2C
Riku Voipio69359942009-03-03 21:13:50 +0200266 ****************************************************************************/
Riku Voipio69359942009-03-03 21:13:50 +0200267void __init mv78xx0_i2c_init(void)
268{
Andrew Lunnaac7ffa2011-05-15 13:32:45 +0200269 orion_i2c_init(I2C_0_PHYS_BASE, IRQ_MV78XX0_I2C_0, 8);
270 orion_i2c_1_init(I2C_1_PHYS_BASE, IRQ_MV78XX0_I2C_1, 8);
Riku Voipio69359942009-03-03 21:13:50 +0200271}
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200272
273/*****************************************************************************
274 * SATA
275 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200276void __init mv78xx0_sata_init(struct mv_sata_platform_data *sata_data)
277{
Andrew Lunndb33f4d2011-12-07 21:48:08 +0100278 orion_sata_init(sata_data, SATA_PHYS_BASE, IRQ_MV78XX0_SATA);
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200279}
280
281
282/*****************************************************************************
283 * UART0
284 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200285void __init mv78xx0_uart0_init(void)
286{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200287 orion_uart0_init(UART0_VIRT_BASE, UART0_PHYS_BASE,
288 IRQ_MV78XX0_UART_0, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200289}
290
291
292/*****************************************************************************
293 * UART1
294 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200295void __init mv78xx0_uart1_init(void)
296{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200297 orion_uart1_init(UART1_VIRT_BASE, UART1_PHYS_BASE,
298 IRQ_MV78XX0_UART_1, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200299}
300
301
302/*****************************************************************************
303 * UART2
304 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200305void __init mv78xx0_uart2_init(void)
306{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200307 orion_uart2_init(UART2_VIRT_BASE, UART2_PHYS_BASE,
308 IRQ_MV78XX0_UART_2, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200309}
310
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200311/*****************************************************************************
312 * UART3
313 ****************************************************************************/
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200314void __init mv78xx0_uart3_init(void)
315{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200316 orion_uart3_init(UART3_VIRT_BASE, UART3_PHYS_BASE,
317 IRQ_MV78XX0_UART_3, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200318}
319
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200320/*****************************************************************************
321 * Time handling
322 ****************************************************************************/
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200323void __init mv78xx0_init_early(void)
324{
325 orion_time_set_base(TIMER_VIRT_BASE);
326}
327
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200328static void mv78xx0_timer_init(void)
329{
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200330 orion_time_init(BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
331 IRQ_MV78XX0_TIMER_1, get_tclk());
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200332}
333
334struct sys_timer mv78xx0_timer = {
335 .init = mv78xx0_timer_init,
336};
337
338
339/*****************************************************************************
340 * General
341 ****************************************************************************/
Lennert Buytenhekcfdeb632009-02-20 02:31:35 +0100342static char * __init mv78xx0_id(void)
343{
344 u32 dev, rev;
345
346 mv78xx0_pcie_id(&dev, &rev);
347
348 if (dev == MV78X00_Z0_DEV_ID) {
349 if (rev == MV78X00_REV_Z0)
350 return "MV78X00-Z0";
351 else
352 return "MV78X00-Rev-Unsupported";
353 } else if (dev == MV78100_DEV_ID) {
354 if (rev == MV78100_REV_A0)
355 return "MV78100-A0";
Lennert Buytenhek662aece2009-09-30 13:02:42 -0700356 else if (rev == MV78100_REV_A1)
357 return "MV78100-A1";
Lennert Buytenhekcfdeb632009-02-20 02:31:35 +0100358 else
359 return "MV78100-Rev-Unsupported";
360 } else if (dev == MV78200_DEV_ID) {
361 if (rev == MV78100_REV_A0)
362 return "MV78200-A0";
363 else
364 return "MV78200-Rev-Unsupported";
365 } else {
366 return "Device-Unknown";
367 }
368}
369
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200370static int __init is_l2_writethrough(void)
371{
372 return !!(readl(CPU_CONTROL) & L2_WRITETHROUGH);
373}
374
375void __init mv78xx0_init(void)
376{
377 int core_index;
378 int hclk;
379 int pclk;
380 int l2clk;
381 int tclk;
382
383 core_index = mv78xx0_core_index();
384 hclk = get_hclk();
385 get_pclk_l2clk(hclk, core_index, &pclk, &l2clk);
386 tclk = get_tclk();
387
Lennert Buytenhekcfdeb632009-02-20 02:31:35 +0100388 printk(KERN_INFO "%s ", mv78xx0_id());
389 printk("core #%d, ", core_index);
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200390 printk("PCLK = %dMHz, ", (pclk + 499999) / 1000000);
391 printk("L2 = %dMHz, ", (l2clk + 499999) / 1000000);
392 printk("HCLK = %dMHz, ", (hclk + 499999) / 1000000);
393 printk("TCLK = %dMHz\n", (tclk + 499999) / 1000000);
394
395 mv78xx0_setup_cpu_mbus();
396
397#ifdef CONFIG_CACHE_FEROCEON_L2
398 feroceon_l2_init(is_l2_writethrough());
399#endif
Stanislav Samsonov794d15b2008-06-22 22:45:10 +0200400}
Russell King9635f9c2011-11-05 10:09:15 +0000401
402void mv78xx0_restart(char mode, const char *cmd)
403{
404 /*
405 * Enable soft reset to assert RSTOUTn.
406 */
407 writel(SOFT_RESET_OUT_EN, RSTOUTn_MASK);
408
409 /*
410 * Assert soft reset.
411 */
412 writel(SOFT_RESET, SYSTEM_SOFT_RESET);
413
414 while (1)
415 ;
416}