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