sfc: Merged efx_page_offset() into efx_rx_buf_offset()
[linux-2.6/verdex.git] / arch / arm / mach-orion5x / common.c
blob4f13fd037f0421ef039bddd38d47a712abd0a05e
1 /*
2 * arch/arm/mach-orion5x/common.c
4 * Core functions for Marvell Orion 5x SoCs
6 * Maintainer: Tzachi Perelstein <tzachi@marvell.com>
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.
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/serial_8250.h>
17 #include <linux/mbus.h>
18 #include <linux/mv643xx_eth.h>
19 #include <linux/mv643xx_i2c.h>
20 #include <linux/ata_platform.h>
21 #include <asm/page.h>
22 #include <asm/setup.h>
23 #include <asm/timex.h>
24 #include <asm/mach/arch.h>
25 #include <asm/mach/map.h>
26 #include <asm/mach/time.h>
27 #include <asm/arch/hardware.h>
28 #include <asm/arch/orion5x.h>
29 #include <asm/plat-orion/ehci-orion.h>
30 #include <asm/plat-orion/orion_nand.h>
31 #include <asm/plat-orion/time.h>
32 #include "common.h"
34 /*****************************************************************************
35 * I/O Address Mapping
36 ****************************************************************************/
37 static struct map_desc orion5x_io_desc[] __initdata = {
39 .virtual = ORION5X_REGS_VIRT_BASE,
40 .pfn = __phys_to_pfn(ORION5X_REGS_PHYS_BASE),
41 .length = ORION5X_REGS_SIZE,
42 .type = MT_DEVICE
45 .virtual = ORION5X_PCIE_IO_VIRT_BASE,
46 .pfn = __phys_to_pfn(ORION5X_PCIE_IO_PHYS_BASE),
47 .length = ORION5X_PCIE_IO_SIZE,
48 .type = MT_DEVICE
51 .virtual = ORION5X_PCI_IO_VIRT_BASE,
52 .pfn = __phys_to_pfn(ORION5X_PCI_IO_PHYS_BASE),
53 .length = ORION5X_PCI_IO_SIZE,
54 .type = MT_DEVICE
57 .virtual = ORION5X_PCIE_WA_VIRT_BASE,
58 .pfn = __phys_to_pfn(ORION5X_PCIE_WA_PHYS_BASE),
59 .length = ORION5X_PCIE_WA_SIZE,
60 .type = MT_DEVICE
64 void __init orion5x_map_io(void)
66 iotable_init(orion5x_io_desc, ARRAY_SIZE(orion5x_io_desc));
69 /*****************************************************************************
70 * UART
71 ****************************************************************************/
73 static struct resource orion5x_uart_resources[] = {
75 .start = UART0_PHYS_BASE,
76 .end = UART0_PHYS_BASE + 0xff,
77 .flags = IORESOURCE_MEM,
80 .start = IRQ_ORION5X_UART0,
81 .end = IRQ_ORION5X_UART0,
82 .flags = IORESOURCE_IRQ,
85 .start = UART1_PHYS_BASE,
86 .end = UART1_PHYS_BASE + 0xff,
87 .flags = IORESOURCE_MEM,
90 .start = IRQ_ORION5X_UART1,
91 .end = IRQ_ORION5X_UART1,
92 .flags = IORESOURCE_IRQ,
96 static struct plat_serial8250_port orion5x_uart_data[] = {
98 .mapbase = UART0_PHYS_BASE,
99 .membase = (char *)UART0_VIRT_BASE,
100 .irq = IRQ_ORION5X_UART0,
101 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
102 .iotype = UPIO_MEM,
103 .regshift = 2,
104 .uartclk = ORION5X_TCLK,
107 .mapbase = UART1_PHYS_BASE,
108 .membase = (char *)UART1_VIRT_BASE,
109 .irq = IRQ_ORION5X_UART1,
110 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
111 .iotype = UPIO_MEM,
112 .regshift = 2,
113 .uartclk = ORION5X_TCLK,
115 { },
118 static struct platform_device orion5x_uart = {
119 .name = "serial8250",
120 .id = PLAT8250_DEV_PLATFORM,
121 .dev = {
122 .platform_data = orion5x_uart_data,
124 .resource = orion5x_uart_resources,
125 .num_resources = ARRAY_SIZE(orion5x_uart_resources),
128 /*******************************************************************************
129 * USB Controller - 2 interfaces
130 ******************************************************************************/
132 static struct resource orion5x_ehci0_resources[] = {
134 .start = ORION5X_USB0_PHYS_BASE,
135 .end = ORION5X_USB0_PHYS_BASE + SZ_4K - 1,
136 .flags = IORESOURCE_MEM,
139 .start = IRQ_ORION5X_USB0_CTRL,
140 .end = IRQ_ORION5X_USB0_CTRL,
141 .flags = IORESOURCE_IRQ,
145 static struct resource orion5x_ehci1_resources[] = {
147 .start = ORION5X_USB1_PHYS_BASE,
148 .end = ORION5X_USB1_PHYS_BASE + SZ_4K - 1,
149 .flags = IORESOURCE_MEM,
152 .start = IRQ_ORION5X_USB1_CTRL,
153 .end = IRQ_ORION5X_USB1_CTRL,
154 .flags = IORESOURCE_IRQ,
158 static struct orion_ehci_data orion5x_ehci_data = {
159 .dram = &orion5x_mbus_dram_info,
162 static u64 ehci_dmamask = 0xffffffffUL;
164 static struct platform_device orion5x_ehci0 = {
165 .name = "orion-ehci",
166 .id = 0,
167 .dev = {
168 .dma_mask = &ehci_dmamask,
169 .coherent_dma_mask = 0xffffffff,
170 .platform_data = &orion5x_ehci_data,
172 .resource = orion5x_ehci0_resources,
173 .num_resources = ARRAY_SIZE(orion5x_ehci0_resources),
176 static struct platform_device orion5x_ehci1 = {
177 .name = "orion-ehci",
178 .id = 1,
179 .dev = {
180 .dma_mask = &ehci_dmamask,
181 .coherent_dma_mask = 0xffffffff,
182 .platform_data = &orion5x_ehci_data,
184 .resource = orion5x_ehci1_resources,
185 .num_resources = ARRAY_SIZE(orion5x_ehci1_resources),
188 /*****************************************************************************
189 * Gigabit Ethernet port
190 * (The Orion and Discovery (MV643xx) families use the same Ethernet driver)
191 ****************************************************************************/
193 struct mv643xx_eth_shared_platform_data orion5x_eth_shared_data = {
194 .dram = &orion5x_mbus_dram_info,
195 .t_clk = ORION5X_TCLK,
198 static struct resource orion5x_eth_shared_resources[] = {
200 .start = ORION5X_ETH_PHYS_BASE + 0x2000,
201 .end = ORION5X_ETH_PHYS_BASE + 0x3fff,
202 .flags = IORESOURCE_MEM,
206 static struct platform_device orion5x_eth_shared = {
207 .name = MV643XX_ETH_SHARED_NAME,
208 .id = 0,
209 .dev = {
210 .platform_data = &orion5x_eth_shared_data,
212 .num_resources = 1,
213 .resource = orion5x_eth_shared_resources,
216 static struct resource orion5x_eth_resources[] = {
218 .name = "eth irq",
219 .start = IRQ_ORION5X_ETH_SUM,
220 .end = IRQ_ORION5X_ETH_SUM,
221 .flags = IORESOURCE_IRQ,
225 static struct platform_device orion5x_eth = {
226 .name = MV643XX_ETH_NAME,
227 .id = 0,
228 .num_resources = 1,
229 .resource = orion5x_eth_resources,
232 void __init orion5x_eth_init(struct mv643xx_eth_platform_data *eth_data)
234 eth_data->shared = &orion5x_eth_shared;
235 orion5x_eth.dev.platform_data = eth_data;
237 platform_device_register(&orion5x_eth_shared);
238 platform_device_register(&orion5x_eth);
241 /*****************************************************************************
242 * I2C controller
243 * (The Orion and Discovery (MV643xx) families share the same I2C controller)
244 ****************************************************************************/
246 static struct mv64xxx_i2c_pdata orion5x_i2c_pdata = {
247 .freq_m = 8, /* assumes 166 MHz TCLK */
248 .freq_n = 3,
249 .timeout = 1000, /* Default timeout of 1 second */
252 static struct resource orion5x_i2c_resources[] = {
254 .name = "i2c base",
255 .start = I2C_PHYS_BASE,
256 .end = I2C_PHYS_BASE + 0x20 -1,
257 .flags = IORESOURCE_MEM,
260 .name = "i2c irq",
261 .start = IRQ_ORION5X_I2C,
262 .end = IRQ_ORION5X_I2C,
263 .flags = IORESOURCE_IRQ,
267 static struct platform_device orion5x_i2c = {
268 .name = MV64XXX_I2C_CTLR_NAME,
269 .id = 0,
270 .num_resources = ARRAY_SIZE(orion5x_i2c_resources),
271 .resource = orion5x_i2c_resources,
272 .dev = {
273 .platform_data = &orion5x_i2c_pdata,
277 /*****************************************************************************
278 * Sata port
279 ****************************************************************************/
280 static struct resource orion5x_sata_resources[] = {
282 .name = "sata base",
283 .start = ORION5X_SATA_PHYS_BASE,
284 .end = ORION5X_SATA_PHYS_BASE + 0x5000 - 1,
285 .flags = IORESOURCE_MEM,
288 .name = "sata irq",
289 .start = IRQ_ORION5X_SATA,
290 .end = IRQ_ORION5X_SATA,
291 .flags = IORESOURCE_IRQ,
295 static struct platform_device orion5x_sata = {
296 .name = "sata_mv",
297 .id = 0,
298 .dev = {
299 .coherent_dma_mask = 0xffffffff,
301 .num_resources = ARRAY_SIZE(orion5x_sata_resources),
302 .resource = orion5x_sata_resources,
305 void __init orion5x_sata_init(struct mv_sata_platform_data *sata_data)
307 sata_data->dram = &orion5x_mbus_dram_info;
308 orion5x_sata.dev.platform_data = sata_data;
309 platform_device_register(&orion5x_sata);
312 /*****************************************************************************
313 * Time handling
314 ****************************************************************************/
316 static void orion5x_timer_init(void)
318 orion_time_init(IRQ_ORION5X_BRIDGE, ORION5X_TCLK);
321 struct sys_timer orion5x_timer = {
322 .init = orion5x_timer_init,
325 /*****************************************************************************
326 * General
327 ****************************************************************************/
330 * Identify device ID and rev from PCIe configuration header space '0'.
332 static void __init orion5x_id(u32 *dev, u32 *rev, char **dev_name)
334 orion5x_pcie_id(dev, rev);
336 if (*dev == MV88F5281_DEV_ID) {
337 if (*rev == MV88F5281_REV_D2) {
338 *dev_name = "MV88F5281-D2";
339 } else if (*rev == MV88F5281_REV_D1) {
340 *dev_name = "MV88F5281-D1";
341 } else {
342 *dev_name = "MV88F5281-Rev-Unsupported";
344 } else if (*dev == MV88F5182_DEV_ID) {
345 if (*rev == MV88F5182_REV_A2) {
346 *dev_name = "MV88F5182-A2";
347 } else {
348 *dev_name = "MV88F5182-Rev-Unsupported";
350 } else if (*dev == MV88F5181_DEV_ID) {
351 if (*rev == MV88F5181_REV_B1) {
352 *dev_name = "MV88F5181-Rev-B1";
353 } else {
354 *dev_name = "MV88F5181-Rev-Unsupported";
356 } else {
357 *dev_name = "Device-Unknown";
361 void __init orion5x_init(void)
363 char *dev_name;
364 u32 dev, rev;
366 orion5x_id(&dev, &rev, &dev_name);
367 printk(KERN_INFO "Orion ID: %s. TCLK=%d.\n", dev_name, ORION5X_TCLK);
370 * Setup Orion address map
372 orion5x_setup_cpu_mbus_bridge();
375 * Register devices.
377 platform_device_register(&orion5x_uart);
378 platform_device_register(&orion5x_ehci0);
379 if (dev == MV88F5182_DEV_ID)
380 platform_device_register(&orion5x_ehci1);
381 platform_device_register(&orion5x_i2c);
385 * Many orion-based systems have buggy bootloader implementations.
386 * This is a common fixup for bogus memory tags.
388 void __init tag_fixup_mem32(struct machine_desc *mdesc, struct tag *t,
389 char **from, struct meminfo *meminfo)
391 for (; t->hdr.size; t = tag_next(t))
392 if (t->hdr.tag == ATAG_MEM &&
393 (!t->u.mem.size || t->u.mem.size & ~PAGE_MASK ||
394 t->u.mem.start & ~PAGE_MASK)) {
395 printk(KERN_WARNING
396 "Clearing invalid memory bank %dKB@0x%08x\n",
397 t->u.mem.size / 1024, t->u.mem.start);
398 t->hdr.tag = 0;