Andrew Lunn | 28a2b45 | 2011-05-15 13:32:41 +0200 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/plat-orion/common.c |
| 3 | * |
| 4 | * Marvell Orion SoC common setup code used by multiple mach-/common.c |
| 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> |
Andrew Lunn | 7e3819d | 2011-05-15 13:32:44 +0200 | [diff] [blame] | 14 | #include <linux/dma-mapping.h> |
Andrew Lunn | 28a2b45 | 2011-05-15 13:32:41 +0200 | [diff] [blame] | 15 | #include <linux/serial_8250.h> |
Andrew Lunn | 7e3819d | 2011-05-15 13:32:44 +0200 | [diff] [blame] | 16 | #include <linux/mbus.h> |
| 17 | #include <linux/mv643xx_eth.h> |
Andrew Lunn | aac7ffa | 2011-05-15 13:32:45 +0200 | [diff] [blame^] | 18 | #include <linux/mv643xx_i2c.h> |
Andrew Lunn | 7e3819d | 2011-05-15 13:32:44 +0200 | [diff] [blame] | 19 | #include <net/dsa.h> |
Andrew Lunn | 28a2b45 | 2011-05-15 13:32:41 +0200 | [diff] [blame] | 20 | |
| 21 | /* Fill in the resources structure and link it into the platform |
| 22 | device structure. There is always a memory region, and nearly |
| 23 | always an interrupt.*/ |
| 24 | static void fill_resources(struct platform_device *device, |
| 25 | struct resource *resources, |
| 26 | resource_size_t mapbase, |
| 27 | resource_size_t size, |
| 28 | unsigned int irq) |
| 29 | { |
| 30 | device->resource = resources; |
| 31 | device->num_resources = 1; |
| 32 | resources[0].flags = IORESOURCE_MEM; |
| 33 | resources[0].start = mapbase; |
| 34 | resources[0].end = mapbase + size; |
| 35 | |
| 36 | if (irq != NO_IRQ) { |
| 37 | device->num_resources++; |
| 38 | resources[1].flags = IORESOURCE_IRQ; |
| 39 | resources[1].start = irq; |
| 40 | resources[1].end = irq; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | /***************************************************************************** |
| 45 | * UART |
| 46 | ****************************************************************************/ |
| 47 | static void __init uart_complete( |
| 48 | struct platform_device *orion_uart, |
| 49 | struct plat_serial8250_port *data, |
| 50 | struct resource *resources, |
| 51 | unsigned int membase, |
| 52 | resource_size_t mapbase, |
| 53 | unsigned int irq, |
| 54 | unsigned int uartclk) |
| 55 | { |
| 56 | data->mapbase = mapbase; |
| 57 | data->membase = (void __iomem *)membase; |
| 58 | data->irq = irq; |
| 59 | data->uartclk = uartclk; |
| 60 | orion_uart->dev.platform_data = data; |
| 61 | |
| 62 | fill_resources(orion_uart, resources, mapbase, 0xff, irq); |
| 63 | platform_device_register(orion_uart); |
| 64 | } |
| 65 | |
| 66 | /***************************************************************************** |
| 67 | * UART0 |
| 68 | ****************************************************************************/ |
| 69 | static struct plat_serial8250_port orion_uart0_data[] = { |
| 70 | { |
| 71 | .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF, |
| 72 | .iotype = UPIO_MEM, |
| 73 | .regshift = 2, |
| 74 | }, { |
| 75 | }, |
| 76 | }; |
| 77 | |
| 78 | static struct resource orion_uart0_resources[2]; |
| 79 | |
| 80 | static struct platform_device orion_uart0 = { |
| 81 | .name = "serial8250", |
| 82 | .id = PLAT8250_DEV_PLATFORM, |
| 83 | }; |
| 84 | |
| 85 | void __init orion_uart0_init(unsigned int membase, |
| 86 | resource_size_t mapbase, |
| 87 | unsigned int irq, |
| 88 | unsigned int uartclk) |
| 89 | { |
| 90 | uart_complete(&orion_uart0, orion_uart0_data, orion_uart0_resources, |
| 91 | membase, mapbase, irq, uartclk); |
| 92 | } |
| 93 | |
| 94 | /***************************************************************************** |
| 95 | * UART1 |
| 96 | ****************************************************************************/ |
| 97 | static struct plat_serial8250_port orion_uart1_data[] = { |
| 98 | { |
| 99 | .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF, |
| 100 | .iotype = UPIO_MEM, |
| 101 | .regshift = 2, |
| 102 | }, { |
| 103 | }, |
| 104 | }; |
| 105 | |
| 106 | static struct resource orion_uart1_resources[2]; |
| 107 | |
| 108 | static struct platform_device orion_uart1 = { |
| 109 | .name = "serial8250", |
| 110 | .id = PLAT8250_DEV_PLATFORM1, |
| 111 | }; |
| 112 | |
| 113 | void __init orion_uart1_init(unsigned int membase, |
| 114 | resource_size_t mapbase, |
| 115 | unsigned int irq, |
| 116 | unsigned int uartclk) |
| 117 | { |
| 118 | uart_complete(&orion_uart1, orion_uart1_data, orion_uart1_resources, |
| 119 | membase, mapbase, irq, uartclk); |
| 120 | } |
| 121 | |
| 122 | /***************************************************************************** |
| 123 | * UART2 |
| 124 | ****************************************************************************/ |
| 125 | static struct plat_serial8250_port orion_uart2_data[] = { |
| 126 | { |
| 127 | .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF, |
| 128 | .iotype = UPIO_MEM, |
| 129 | .regshift = 2, |
| 130 | }, { |
| 131 | }, |
| 132 | }; |
| 133 | |
| 134 | static struct resource orion_uart2_resources[2]; |
| 135 | |
| 136 | static struct platform_device orion_uart2 = { |
| 137 | .name = "serial8250", |
| 138 | .id = PLAT8250_DEV_PLATFORM2, |
| 139 | }; |
| 140 | |
| 141 | void __init orion_uart2_init(unsigned int membase, |
| 142 | resource_size_t mapbase, |
| 143 | unsigned int irq, |
| 144 | unsigned int uartclk) |
| 145 | { |
| 146 | uart_complete(&orion_uart2, orion_uart2_data, orion_uart2_resources, |
| 147 | membase, mapbase, irq, uartclk); |
| 148 | } |
| 149 | |
| 150 | /***************************************************************************** |
| 151 | * UART3 |
| 152 | ****************************************************************************/ |
| 153 | static struct plat_serial8250_port orion_uart3_data[] = { |
| 154 | { |
| 155 | .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF, |
| 156 | .iotype = UPIO_MEM, |
| 157 | .regshift = 2, |
| 158 | }, { |
| 159 | }, |
| 160 | }; |
| 161 | |
| 162 | static struct resource orion_uart3_resources[2]; |
| 163 | |
| 164 | static struct platform_device orion_uart3 = { |
| 165 | .name = "serial8250", |
| 166 | .id = 3, |
| 167 | }; |
| 168 | |
| 169 | void __init orion_uart3_init(unsigned int membase, |
| 170 | resource_size_t mapbase, |
| 171 | unsigned int irq, |
| 172 | unsigned int uartclk) |
| 173 | { |
| 174 | uart_complete(&orion_uart3, orion_uart3_data, orion_uart3_resources, |
| 175 | membase, mapbase, irq, uartclk); |
| 176 | } |
Andrew Lunn | f6eaccb | 2011-05-15 13:32:42 +0200 | [diff] [blame] | 177 | |
| 178 | /***************************************************************************** |
| 179 | * SoC RTC |
| 180 | ****************************************************************************/ |
| 181 | static struct resource orion_rtc_resource[2]; |
| 182 | |
| 183 | void __init orion_rtc_init(unsigned long mapbase, |
| 184 | unsigned long irq) |
| 185 | { |
| 186 | orion_rtc_resource[0].start = mapbase; |
| 187 | orion_rtc_resource[0].end = mapbase + SZ_32 - 1; |
| 188 | orion_rtc_resource[0].flags = IORESOURCE_MEM; |
| 189 | orion_rtc_resource[1].start = irq; |
| 190 | orion_rtc_resource[1].end = irq; |
| 191 | orion_rtc_resource[1].flags = IORESOURCE_IRQ; |
| 192 | |
| 193 | platform_device_register_simple("rtc-mv", -1, orion_rtc_resource, 2); |
| 194 | } |
Andrew Lunn | 7e3819d | 2011-05-15 13:32:44 +0200 | [diff] [blame] | 195 | |
| 196 | /***************************************************************************** |
| 197 | * GE |
| 198 | ****************************************************************************/ |
| 199 | static __init void ge_complete( |
| 200 | struct mv643xx_eth_shared_platform_data *orion_ge_shared_data, |
| 201 | struct mbus_dram_target_info *mbus_dram_info, int tclk, |
| 202 | struct resource *orion_ge_resource, unsigned long irq, |
| 203 | struct platform_device *orion_ge_shared, |
| 204 | struct mv643xx_eth_platform_data *eth_data, |
| 205 | struct platform_device *orion_ge) |
| 206 | { |
| 207 | orion_ge_shared_data->dram = mbus_dram_info; |
| 208 | orion_ge_shared_data->t_clk = tclk; |
| 209 | orion_ge_resource->start = irq; |
| 210 | orion_ge_resource->end = irq; |
| 211 | eth_data->shared = orion_ge_shared; |
| 212 | orion_ge->dev.platform_data = eth_data; |
| 213 | |
| 214 | platform_device_register(orion_ge_shared); |
| 215 | platform_device_register(orion_ge); |
| 216 | } |
| 217 | |
| 218 | /***************************************************************************** |
| 219 | * GE00 |
| 220 | ****************************************************************************/ |
| 221 | struct mv643xx_eth_shared_platform_data orion_ge00_shared_data; |
| 222 | |
| 223 | static struct resource orion_ge00_shared_resources[] = { |
| 224 | { |
| 225 | .name = "ge00 base", |
| 226 | }, { |
| 227 | .name = "ge00 err irq", |
| 228 | }, |
| 229 | }; |
| 230 | |
| 231 | static struct platform_device orion_ge00_shared = { |
| 232 | .name = MV643XX_ETH_SHARED_NAME, |
| 233 | .id = 0, |
| 234 | .dev = { |
| 235 | .platform_data = &orion_ge00_shared_data, |
| 236 | }, |
| 237 | }; |
| 238 | |
| 239 | static struct resource orion_ge00_resources[] = { |
| 240 | { |
| 241 | .name = "ge00 irq", |
| 242 | .flags = IORESOURCE_IRQ, |
| 243 | }, |
| 244 | }; |
| 245 | |
| 246 | static struct platform_device orion_ge00 = { |
| 247 | .name = MV643XX_ETH_NAME, |
| 248 | .id = 0, |
| 249 | .num_resources = 1, |
| 250 | .resource = orion_ge00_resources, |
| 251 | .dev = { |
| 252 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 253 | }, |
| 254 | }; |
| 255 | |
| 256 | void __init orion_ge00_init(struct mv643xx_eth_platform_data *eth_data, |
| 257 | struct mbus_dram_target_info *mbus_dram_info, |
| 258 | unsigned long mapbase, |
| 259 | unsigned long irq, |
| 260 | unsigned long irq_err, |
| 261 | int tclk) |
| 262 | { |
| 263 | fill_resources(&orion_ge00_shared, orion_ge00_shared_resources, |
| 264 | mapbase + 0x2000, SZ_16K - 1, irq_err); |
| 265 | ge_complete(&orion_ge00_shared_data, mbus_dram_info, tclk, |
| 266 | orion_ge00_resources, irq, &orion_ge00_shared, |
| 267 | eth_data, &orion_ge00); |
| 268 | } |
| 269 | |
| 270 | /***************************************************************************** |
| 271 | * GE01 |
| 272 | ****************************************************************************/ |
| 273 | struct mv643xx_eth_shared_platform_data orion_ge01_shared_data = { |
| 274 | .shared_smi = &orion_ge00_shared, |
| 275 | }; |
| 276 | |
| 277 | static struct resource orion_ge01_shared_resources[] = { |
| 278 | { |
| 279 | .name = "ge01 base", |
| 280 | }, { |
| 281 | .name = "ge01 err irq", |
| 282 | }, |
| 283 | }; |
| 284 | |
| 285 | static struct platform_device orion_ge01_shared = { |
| 286 | .name = MV643XX_ETH_SHARED_NAME, |
| 287 | .id = 1, |
| 288 | .dev = { |
| 289 | .platform_data = &orion_ge01_shared_data, |
| 290 | }, |
| 291 | }; |
| 292 | |
| 293 | static struct resource orion_ge01_resources[] = { |
| 294 | { |
| 295 | .name = "ge01 irq", |
| 296 | .flags = IORESOURCE_IRQ, |
| 297 | }, |
| 298 | }; |
| 299 | |
| 300 | static struct platform_device orion_ge01 = { |
| 301 | .name = MV643XX_ETH_NAME, |
| 302 | .id = 1, |
| 303 | .num_resources = 1, |
| 304 | .resource = orion_ge01_resources, |
| 305 | .dev = { |
| 306 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 307 | }, |
| 308 | }; |
| 309 | |
| 310 | void __init orion_ge01_init(struct mv643xx_eth_platform_data *eth_data, |
| 311 | struct mbus_dram_target_info *mbus_dram_info, |
| 312 | unsigned long mapbase, |
| 313 | unsigned long irq, |
| 314 | unsigned long irq_err, |
| 315 | int tclk) |
| 316 | { |
| 317 | fill_resources(&orion_ge01_shared, orion_ge01_shared_resources, |
| 318 | mapbase + 0x2000, SZ_16K - 1, irq_err); |
| 319 | ge_complete(&orion_ge01_shared_data, mbus_dram_info, tclk, |
| 320 | orion_ge01_resources, irq, &orion_ge01_shared, |
| 321 | eth_data, &orion_ge01); |
| 322 | } |
| 323 | |
| 324 | /***************************************************************************** |
| 325 | * GE10 |
| 326 | ****************************************************************************/ |
| 327 | struct mv643xx_eth_shared_platform_data orion_ge10_shared_data = { |
| 328 | .shared_smi = &orion_ge00_shared, |
| 329 | }; |
| 330 | |
| 331 | static struct resource orion_ge10_shared_resources[] = { |
| 332 | { |
| 333 | .name = "ge10 base", |
| 334 | }, { |
| 335 | .name = "ge10 err irq", |
| 336 | }, |
| 337 | }; |
| 338 | |
| 339 | static struct platform_device orion_ge10_shared = { |
| 340 | .name = MV643XX_ETH_SHARED_NAME, |
| 341 | .id = 1, |
| 342 | .dev = { |
| 343 | .platform_data = &orion_ge10_shared_data, |
| 344 | }, |
| 345 | }; |
| 346 | |
| 347 | static struct resource orion_ge10_resources[] = { |
| 348 | { |
| 349 | .name = "ge10 irq", |
| 350 | .flags = IORESOURCE_IRQ, |
| 351 | }, |
| 352 | }; |
| 353 | |
| 354 | static struct platform_device orion_ge10 = { |
| 355 | .name = MV643XX_ETH_NAME, |
| 356 | .id = 1, |
| 357 | .num_resources = 2, |
| 358 | .resource = orion_ge10_resources, |
| 359 | .dev = { |
| 360 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 361 | }, |
| 362 | }; |
| 363 | |
| 364 | void __init orion_ge10_init(struct mv643xx_eth_platform_data *eth_data, |
| 365 | struct mbus_dram_target_info *mbus_dram_info, |
| 366 | unsigned long mapbase, |
| 367 | unsigned long irq, |
| 368 | unsigned long irq_err, |
| 369 | int tclk) |
| 370 | { |
| 371 | fill_resources(&orion_ge10_shared, orion_ge10_shared_resources, |
| 372 | mapbase + 0x2000, SZ_16K - 1, irq_err); |
| 373 | ge_complete(&orion_ge10_shared_data, mbus_dram_info, tclk, |
| 374 | orion_ge10_resources, irq, &orion_ge10_shared, |
| 375 | eth_data, &orion_ge10); |
| 376 | } |
| 377 | |
| 378 | /***************************************************************************** |
| 379 | * GE11 |
| 380 | ****************************************************************************/ |
| 381 | struct mv643xx_eth_shared_platform_data orion_ge11_shared_data = { |
| 382 | .shared_smi = &orion_ge00_shared, |
| 383 | }; |
| 384 | |
| 385 | static struct resource orion_ge11_shared_resources[] = { |
| 386 | { |
| 387 | .name = "ge11 base", |
| 388 | }, { |
| 389 | .name = "ge11 err irq", |
| 390 | }, |
| 391 | }; |
| 392 | |
| 393 | static struct platform_device orion_ge11_shared = { |
| 394 | .name = MV643XX_ETH_SHARED_NAME, |
| 395 | .id = 1, |
| 396 | .dev = { |
| 397 | .platform_data = &orion_ge11_shared_data, |
| 398 | }, |
| 399 | }; |
| 400 | |
| 401 | static struct resource orion_ge11_resources[] = { |
| 402 | { |
| 403 | .name = "ge11 irq", |
| 404 | .flags = IORESOURCE_IRQ, |
| 405 | }, |
| 406 | }; |
| 407 | |
| 408 | static struct platform_device orion_ge11 = { |
| 409 | .name = MV643XX_ETH_NAME, |
| 410 | .id = 1, |
| 411 | .num_resources = 2, |
| 412 | .resource = orion_ge11_resources, |
| 413 | .dev = { |
| 414 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 415 | }, |
| 416 | }; |
| 417 | |
| 418 | void __init orion_ge11_init(struct mv643xx_eth_platform_data *eth_data, |
| 419 | struct mbus_dram_target_info *mbus_dram_info, |
| 420 | unsigned long mapbase, |
| 421 | unsigned long irq, |
| 422 | unsigned long irq_err, |
| 423 | int tclk) |
| 424 | { |
| 425 | fill_resources(&orion_ge11_shared, orion_ge11_shared_resources, |
| 426 | mapbase + 0x2000, SZ_16K - 1, irq_err); |
| 427 | ge_complete(&orion_ge11_shared_data, mbus_dram_info, tclk, |
| 428 | orion_ge11_resources, irq, &orion_ge11_shared, |
| 429 | eth_data, &orion_ge11); |
| 430 | } |
| 431 | |
| 432 | /***************************************************************************** |
| 433 | * Ethernet switch |
| 434 | ****************************************************************************/ |
| 435 | static struct resource orion_switch_resources[] = { |
| 436 | { |
| 437 | .start = 0, |
| 438 | .end = 0, |
| 439 | .flags = IORESOURCE_IRQ, |
| 440 | }, |
| 441 | }; |
| 442 | |
| 443 | static struct platform_device orion_switch_device = { |
| 444 | .name = "dsa", |
| 445 | .id = 0, |
| 446 | .num_resources = 0, |
| 447 | .resource = orion_switch_resources, |
| 448 | }; |
| 449 | |
| 450 | void __init orion_ge00_switch_init(struct dsa_platform_data *d, int irq) |
| 451 | { |
| 452 | int i; |
| 453 | |
| 454 | if (irq != NO_IRQ) { |
| 455 | orion_switch_resources[0].start = irq; |
| 456 | orion_switch_resources[0].end = irq; |
| 457 | orion_switch_device.num_resources = 1; |
| 458 | } |
| 459 | |
| 460 | d->netdev = &orion_ge00.dev; |
| 461 | for (i = 0; i < d->nr_chips; i++) |
| 462 | d->chip[i].mii_bus = &orion_ge00_shared.dev; |
| 463 | orion_switch_device.dev.platform_data = d; |
| 464 | |
| 465 | platform_device_register(&orion_switch_device); |
| 466 | } |
Andrew Lunn | aac7ffa | 2011-05-15 13:32:45 +0200 | [diff] [blame^] | 467 | |
| 468 | /***************************************************************************** |
| 469 | * I2C |
| 470 | ****************************************************************************/ |
| 471 | static struct mv64xxx_i2c_pdata orion_i2c_pdata = { |
| 472 | .freq_n = 3, |
| 473 | .timeout = 1000, /* Default timeout of 1 second */ |
| 474 | }; |
| 475 | |
| 476 | static struct resource orion_i2c_resources[2]; |
| 477 | |
| 478 | static struct platform_device orion_i2c = { |
| 479 | .name = MV64XXX_I2C_CTLR_NAME, |
| 480 | .id = 0, |
| 481 | .dev = { |
| 482 | .platform_data = &orion_i2c_pdata, |
| 483 | }, |
| 484 | }; |
| 485 | |
| 486 | static struct mv64xxx_i2c_pdata orion_i2c_1_pdata = { |
| 487 | .freq_n = 3, |
| 488 | .timeout = 1000, /* Default timeout of 1 second */ |
| 489 | }; |
| 490 | |
| 491 | static struct resource orion_i2c_1_resources[2]; |
| 492 | |
| 493 | static struct platform_device orion_i2c_1 = { |
| 494 | .name = MV64XXX_I2C_CTLR_NAME, |
| 495 | .id = 1, |
| 496 | .dev = { |
| 497 | .platform_data = &orion_i2c_1_pdata, |
| 498 | }, |
| 499 | }; |
| 500 | |
| 501 | void __init orion_i2c_init(unsigned long mapbase, |
| 502 | unsigned long irq, |
| 503 | unsigned long freq_m) |
| 504 | { |
| 505 | orion_i2c_pdata.freq_m = freq_m; |
| 506 | fill_resources(&orion_i2c, orion_i2c_resources, mapbase, |
| 507 | SZ_32 - 1, irq); |
| 508 | platform_device_register(&orion_i2c); |
| 509 | } |
| 510 | |
| 511 | void __init orion_i2c_1_init(unsigned long mapbase, |
| 512 | unsigned long irq, |
| 513 | unsigned long freq_m) |
| 514 | { |
| 515 | orion_i2c_1_pdata.freq_m = freq_m; |
| 516 | fill_resources(&orion_i2c_1, orion_i2c_1_resources, mapbase, |
| 517 | SZ_32 - 1, irq); |
| 518 | platform_device_register(&orion_i2c_1); |
| 519 | } |