blob: cd9aa43bb47405549c0a576aa76a2d3dfe9bd936 [file] [log] [blame]
Tzachi Perelstein585cf172007-10-23 15:14:41 -04001/*
2 * arch/arm/mach-orion/common.c
3 *
4 * Core functions for Marvell Orion System On Chip
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>
Tzachi Perelsteinca26f7d2007-10-23 15:14:42 -040015#include <linux/platform_device.h>
16#include <linux/serial_8250.h>
Lennert Buytenhek83b6d822008-03-27 14:51:39 -040017#include <linux/mbus.h>
Tzachi Perelsteine07c9d82007-10-31 12:42:41 +020018#include <linux/mv643xx_eth.h>
Herbert Valerio Riedel144aa3d2007-11-12 09:51:36 +020019#include <linux/mv643xx_i2c.h>
Tzachi Perelstein585cf172007-10-23 15:14:41 -040020#include <asm/page.h>
Guennadi Liakhovetskibe73a342008-02-29 21:12:57 +010021#include <asm/setup.h>
Tzachi Perelsteinc67de5b2007-10-23 15:14:42 -040022#include <asm/timex.h>
Guennadi Liakhovetskibe73a342008-02-29 21:12:57 +010023#include <asm/mach/arch.h>
Tzachi Perelstein585cf172007-10-23 15:14:41 -040024#include <asm/mach/map.h>
Saeed Bisharaf244baa2008-01-29 11:33:32 -110025#include <asm/arch/hardware.h>
Tzachi Perelstein585cf172007-10-23 15:14:41 -040026#include "common.h"
27
28/*****************************************************************************
29 * I/O Address Mapping
30 ****************************************************************************/
31static struct map_desc orion_io_desc[] __initdata = {
32 {
Lennert Buytenhek7f74c2c2008-02-07 21:55:17 +010033 .virtual = ORION_REGS_VIRT_BASE,
34 .pfn = __phys_to_pfn(ORION_REGS_PHYS_BASE),
Tzachi Perelstein585cf172007-10-23 15:14:41 -040035 .length = ORION_REGS_SIZE,
36 .type = MT_DEVICE
37 },
38 {
Lennert Buytenhek7f74c2c2008-02-07 21:55:17 +010039 .virtual = ORION_PCIE_IO_VIRT_BASE,
40 .pfn = __phys_to_pfn(ORION_PCIE_IO_PHYS_BASE),
Tzachi Perelstein585cf172007-10-23 15:14:41 -040041 .length = ORION_PCIE_IO_SIZE,
42 .type = MT_DEVICE
43 },
44 {
Lennert Buytenhek7f74c2c2008-02-07 21:55:17 +010045 .virtual = ORION_PCI_IO_VIRT_BASE,
46 .pfn = __phys_to_pfn(ORION_PCI_IO_PHYS_BASE),
Tzachi Perelstein585cf172007-10-23 15:14:41 -040047 .length = ORION_PCI_IO_SIZE,
48 .type = MT_DEVICE
49 },
50 {
Lennert Buytenhek7f74c2c2008-02-07 21:55:17 +010051 .virtual = ORION_PCIE_WA_VIRT_BASE,
52 .pfn = __phys_to_pfn(ORION_PCIE_WA_PHYS_BASE),
Tzachi Perelstein585cf172007-10-23 15:14:41 -040053 .length = ORION_PCIE_WA_SIZE,
54 .type = MT_DEVICE
55 },
56};
57
58void __init orion_map_io(void)
59{
60 iotable_init(orion_io_desc, ARRAY_SIZE(orion_io_desc));
61}
Tzachi Perelsteinc67de5b2007-10-23 15:14:42 -040062
63/*****************************************************************************
Tzachi Perelsteinca26f7d2007-10-23 15:14:42 -040064 * UART
65 ****************************************************************************/
66
67static struct resource orion_uart_resources[] = {
68 {
Lennert Buytenhek7f74c2c2008-02-07 21:55:17 +010069 .start = UART0_PHYS_BASE,
70 .end = UART0_PHYS_BASE + 0xff,
Tzachi Perelsteinca26f7d2007-10-23 15:14:42 -040071 .flags = IORESOURCE_MEM,
72 },
73 {
74 .start = IRQ_ORION_UART0,
75 .end = IRQ_ORION_UART0,
76 .flags = IORESOURCE_IRQ,
77 },
78 {
Lennert Buytenhek7f74c2c2008-02-07 21:55:17 +010079 .start = UART1_PHYS_BASE,
80 .end = UART1_PHYS_BASE + 0xff,
Tzachi Perelsteinca26f7d2007-10-23 15:14:42 -040081 .flags = IORESOURCE_MEM,
82 },
83 {
84 .start = IRQ_ORION_UART1,
85 .end = IRQ_ORION_UART1,
86 .flags = IORESOURCE_IRQ,
87 },
88};
89
90static struct plat_serial8250_port orion_uart_data[] = {
91 {
Lennert Buytenhek7f74c2c2008-02-07 21:55:17 +010092 .mapbase = UART0_PHYS_BASE,
93 .membase = (char *)UART0_VIRT_BASE,
Tzachi Perelsteinca26f7d2007-10-23 15:14:42 -040094 .irq = IRQ_ORION_UART0,
95 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
96 .iotype = UPIO_MEM,
97 .regshift = 2,
98 .uartclk = ORION_TCLK,
99 },
100 {
Lennert Buytenhek7f74c2c2008-02-07 21:55:17 +0100101 .mapbase = UART1_PHYS_BASE,
102 .membase = (char *)UART1_VIRT_BASE,
Tzachi Perelsteinca26f7d2007-10-23 15:14:42 -0400103 .irq = IRQ_ORION_UART1,
104 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
105 .iotype = UPIO_MEM,
106 .regshift = 2,
107 .uartclk = ORION_TCLK,
108 },
109 { },
110};
111
112static struct platform_device orion_uart = {
113 .name = "serial8250",
114 .id = PLAT8250_DEV_PLATFORM,
115 .dev = {
116 .platform_data = orion_uart_data,
117 },
118 .resource = orion_uart_resources,
119 .num_resources = ARRAY_SIZE(orion_uart_resources),
120};
121
122/*******************************************************************************
123 * USB Controller - 2 interfaces
124 ******************************************************************************/
125
126static struct resource orion_ehci0_resources[] = {
127 {
Lennert Buytenhek7f74c2c2008-02-07 21:55:17 +0100128 .start = ORION_USB0_PHYS_BASE,
129 .end = ORION_USB0_PHYS_BASE + SZ_4K,
Tzachi Perelsteinca26f7d2007-10-23 15:14:42 -0400130 .flags = IORESOURCE_MEM,
131 },
132 {
133 .start = IRQ_ORION_USB0_CTRL,
134 .end = IRQ_ORION_USB0_CTRL,
135 .flags = IORESOURCE_IRQ,
136 },
137};
138
139static struct resource orion_ehci1_resources[] = {
140 {
Lennert Buytenhek7f74c2c2008-02-07 21:55:17 +0100141 .start = ORION_USB1_PHYS_BASE,
142 .end = ORION_USB1_PHYS_BASE + SZ_4K,
Tzachi Perelsteinca26f7d2007-10-23 15:14:42 -0400143 .flags = IORESOURCE_MEM,
144 },
145 {
146 .start = IRQ_ORION_USB1_CTRL,
147 .end = IRQ_ORION_USB1_CTRL,
148 .flags = IORESOURCE_IRQ,
149 },
150};
151
152static u64 ehci_dmamask = 0xffffffffUL;
153
154static struct platform_device orion_ehci0 = {
155 .name = "orion-ehci",
156 .id = 0,
157 .dev = {
158 .dma_mask = &ehci_dmamask,
159 .coherent_dma_mask = 0xffffffff,
160 },
161 .resource = orion_ehci0_resources,
162 .num_resources = ARRAY_SIZE(orion_ehci0_resources),
163};
164
165static struct platform_device orion_ehci1 = {
166 .name = "orion-ehci",
167 .id = 1,
168 .dev = {
169 .dma_mask = &ehci_dmamask,
170 .coherent_dma_mask = 0xffffffff,
171 },
172 .resource = orion_ehci1_resources,
173 .num_resources = ARRAY_SIZE(orion_ehci1_resources),
174};
175
176/*****************************************************************************
Tzachi Perelsteine07c9d82007-10-31 12:42:41 +0200177 * Gigabit Ethernet port
178 * (The Orion and Discovery (MV643xx) families use the same Ethernet driver)
179 ****************************************************************************/
180
181static struct resource orion_eth_shared_resources[] = {
182 {
Lennert Buytenhek88603f12008-03-07 11:41:18 +0100183 .start = ORION_ETH_PHYS_BASE + 0x2000,
184 .end = ORION_ETH_PHYS_BASE + 0x3fff,
Tzachi Perelsteine07c9d82007-10-31 12:42:41 +0200185 .flags = IORESOURCE_MEM,
186 },
187};
188
189static struct platform_device orion_eth_shared = {
190 .name = MV643XX_ETH_SHARED_NAME,
191 .id = 0,
192 .num_resources = 1,
193 .resource = orion_eth_shared_resources,
194};
195
196static struct resource orion_eth_resources[] = {
197 {
198 .name = "eth irq",
199 .start = IRQ_ORION_ETH_SUM,
200 .end = IRQ_ORION_ETH_SUM,
201 .flags = IORESOURCE_IRQ,
202 }
203};
204
205static struct platform_device orion_eth = {
206 .name = MV643XX_ETH_NAME,
207 .id = 0,
208 .num_resources = 1,
209 .resource = orion_eth_resources,
210};
211
212void __init orion_eth_init(struct mv643xx_eth_platform_data *eth_data)
213{
214 orion_eth.dev.platform_data = eth_data;
215 platform_device_register(&orion_eth_shared);
216 platform_device_register(&orion_eth);
217}
218
219/*****************************************************************************
Herbert Valerio Riedel144aa3d2007-11-12 09:51:36 +0200220 * I2C controller
221 * (The Orion and Discovery (MV643xx) families share the same I2C controller)
222 ****************************************************************************/
223
224static struct mv64xxx_i2c_pdata orion_i2c_pdata = {
225 .freq_m = 8, /* assumes 166 MHz TCLK */
226 .freq_n = 3,
227 .timeout = 1000, /* Default timeout of 1 second */
228};
229
230static struct resource orion_i2c_resources[] = {
231 {
232 .name = "i2c base",
Lennert Buytenhek7f74c2c2008-02-07 21:55:17 +0100233 .start = I2C_PHYS_BASE,
234 .end = I2C_PHYS_BASE + 0x20 -1,
Herbert Valerio Riedel144aa3d2007-11-12 09:51:36 +0200235 .flags = IORESOURCE_MEM,
236 },
237 {
238 .name = "i2c irq",
239 .start = IRQ_ORION_I2C,
240 .end = IRQ_ORION_I2C,
241 .flags = IORESOURCE_IRQ,
242 },
243};
244
245static struct platform_device orion_i2c = {
246 .name = MV64XXX_I2C_CTLR_NAME,
247 .id = 0,
248 .num_resources = ARRAY_SIZE(orion_i2c_resources),
249 .resource = orion_i2c_resources,
250 .dev = {
251 .platform_data = &orion_i2c_pdata,
252 },
253};
254
255/*****************************************************************************
Saeed Bisharaf244baa2008-01-29 11:33:32 -1100256 * Sata port
257 ****************************************************************************/
258static struct resource orion_sata_resources[] = {
259 {
260 .name = "sata base",
Lennert Buytenhek7f74c2c2008-02-07 21:55:17 +0100261 .start = ORION_SATA_PHYS_BASE,
262 .end = ORION_SATA_PHYS_BASE + 0x5000 - 1,
Saeed Bisharaf244baa2008-01-29 11:33:32 -1100263 .flags = IORESOURCE_MEM,
264 },
265 {
266 .name = "sata irq",
267 .start = IRQ_ORION_SATA,
268 .end = IRQ_ORION_SATA,
269 .flags = IORESOURCE_IRQ,
270 },
271};
272
273static struct platform_device orion_sata = {
274 .name = "sata_mv",
275 .id = 0,
276 .dev = {
277 .coherent_dma_mask = 0xffffffff,
278 },
279 .num_resources = ARRAY_SIZE(orion_sata_resources),
280 .resource = orion_sata_resources,
281};
282
283void __init orion_sata_init(struct mv_sata_platform_data *sata_data)
284{
285 orion_sata.dev.platform_data = sata_data;
286 platform_device_register(&orion_sata);
287}
288
289/*****************************************************************************
Tzachi Perelsteinc67de5b2007-10-23 15:14:42 -0400290 * General
291 ****************************************************************************/
292
293/*
294 * Identify device ID and rev from PCIE configuration header space '0'.
295 */
296static void orion_id(u32 *dev, u32 *rev, char **dev_name)
297{
298 orion_pcie_id(dev, rev);
299
300 if (*dev == MV88F5281_DEV_ID) {
301 if (*rev == MV88F5281_REV_D2) {
302 *dev_name = "MV88F5281-D2";
303 } else if (*rev == MV88F5281_REV_D1) {
304 *dev_name = "MV88F5281-D1";
305 } else {
306 *dev_name = "MV88F5281-Rev-Unsupported";
307 }
308 } else if (*dev == MV88F5182_DEV_ID) {
309 if (*rev == MV88F5182_REV_A2) {
310 *dev_name = "MV88F5182-A2";
311 } else {
312 *dev_name = "MV88F5182-Rev-Unsupported";
313 }
Herbert Valerio Riedelc9e3de92007-11-11 12:05:11 +0100314 } else if (*dev == MV88F5181_DEV_ID) {
315 if (*rev == MV88F5181_REV_B1) {
316 *dev_name = "MV88F5181-Rev-B1";
317 } else {
318 *dev_name = "MV88F5181-Rev-Unsupported";
319 }
Tzachi Perelsteinc67de5b2007-10-23 15:14:42 -0400320 } else {
321 *dev_name = "Device-Unknown";
322 }
323}
324
325void __init orion_init(void)
326{
327 char *dev_name;
328 u32 dev, rev;
329
330 orion_id(&dev, &rev, &dev_name);
331 printk(KERN_INFO "Orion ID: %s. TCLK=%d.\n", dev_name, ORION_TCLK);
332
333 /*
334 * Setup Orion address map
335 */
336 orion_setup_cpu_wins();
337 orion_setup_usb_wins();
338 orion_setup_eth_wins();
339 orion_setup_pci_wins();
340 orion_setup_pcie_wins();
341 if (dev == MV88F5182_DEV_ID)
342 orion_setup_sata_wins();
Tzachi Perelsteinca26f7d2007-10-23 15:14:42 -0400343
344 /*
345 * REgister devices
346 */
347 platform_device_register(&orion_uart);
348 platform_device_register(&orion_ehci0);
349 if (dev == MV88F5182_DEV_ID)
350 platform_device_register(&orion_ehci1);
Herbert Valerio Riedel144aa3d2007-11-12 09:51:36 +0200351 platform_device_register(&orion_i2c);
Tzachi Perelsteinc67de5b2007-10-23 15:14:42 -0400352}
Guennadi Liakhovetskibe73a342008-02-29 21:12:57 +0100353
354/*
355 * Many orion-based systems have buggy bootloader implementations.
356 * This is a common fixup for bogus memory tags.
357 */
358void __init tag_fixup_mem32(struct machine_desc *mdesc, struct tag *t,
359 char **from, struct meminfo *meminfo)
360{
361 for (; t->hdr.size; t = tag_next(t))
362 if (t->hdr.tag == ATAG_MEM &&
363 (!t->u.mem.size || t->u.mem.size & ~PAGE_MASK ||
364 t->u.mem.start & ~PAGE_MASK)) {
365 printk(KERN_WARNING
366 "Clearing invalid memory bank %dKB@0x%08x\n",
367 t->u.mem.size / 1024, t->u.mem.start);
368 t->hdr.tag = 0;
369 }
370}