David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * ASIC Device List Intialization |
| 3 | * |
| 4 | * Description: Defines the platform resources for the SA settop. |
| 5 | * |
| 6 | * Copyright (C) 2005-2009 Scientific-Atlanta, Inc. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | * |
| 22 | * Author: Ken Eppinett |
| 23 | * David Schleef <ds@schleef.org> |
| 24 | * |
| 25 | * Description: Defines the platform resources for the SA settop. |
| 26 | * |
| 27 | * NOTE: The bootloader allocates persistent memory at an address which is |
| 28 | * 16 MiB below the end of the highest address in KSEG0. All fixed |
| 29 | * address memory reservations must avoid this region. |
| 30 | */ |
| 31 | |
| 32 | #include <linux/device.h> |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/resource.h> |
| 36 | #include <linux/serial_reg.h> |
| 37 | #include <linux/io.h> |
| 38 | #include <linux/bootmem.h> |
| 39 | #include <linux/mm.h> |
| 40 | #include <linux/platform_device.h> |
| 41 | #include <linux/module.h> |
| 42 | #include <asm/page.h> |
| 43 | #include <linux/swap.h> |
| 44 | #include <linux/highmem.h> |
| 45 | #include <linux/dma-mapping.h> |
| 46 | |
| 47 | #include <asm/mach-powertv/asic.h> |
| 48 | #include <asm/mach-powertv/asic_regs.h> |
| 49 | #include <asm/mach-powertv/interrupts.h> |
| 50 | |
| 51 | #ifdef CONFIG_BOOTLOADER_DRIVER |
| 52 | #include <asm/mach-powertv/kbldr.h> |
| 53 | #endif |
| 54 | #include <asm/bootinfo.h> |
| 55 | |
| 56 | #define BOOTLDRFAMILY(byte1, byte0) (((byte1) << 8) | (byte0)) |
| 57 | |
| 58 | /* |
| 59 | * Forward Prototypes |
| 60 | */ |
| 61 | static void pmem_setup_resource(void); |
| 62 | |
| 63 | /* |
| 64 | * Global Variables |
| 65 | */ |
| 66 | enum asic_type asic; |
| 67 | |
| 68 | unsigned int platform_features; |
| 69 | unsigned int platform_family; |
| 70 | const struct register_map *register_map; |
| 71 | EXPORT_SYMBOL(register_map); /* Exported for testing */ |
| 72 | unsigned long asic_phy_base; |
| 73 | unsigned long asic_base; |
| 74 | EXPORT_SYMBOL(asic_base); /* Exported for testing */ |
| 75 | struct resource *gp_resources; |
| 76 | static bool usb_configured; |
| 77 | |
| 78 | /* |
| 79 | * Don't recommend to use it directly, it is usually used by kernel internally. |
| 80 | * Portable code should be using interfaces such as ioremp, dma_map_single, etc. |
| 81 | */ |
| 82 | unsigned long phys_to_bus_offset; |
| 83 | EXPORT_SYMBOL(phys_to_bus_offset); |
| 84 | |
| 85 | /* |
| 86 | * |
| 87 | * IO Resource Definition |
| 88 | * |
| 89 | */ |
| 90 | |
| 91 | struct resource asic_resource = { |
| 92 | .name = "ASIC Resource", |
| 93 | .start = 0, |
| 94 | .end = ASIC_IO_SIZE, |
| 95 | .flags = IORESOURCE_MEM, |
| 96 | }; |
| 97 | |
| 98 | /* |
| 99 | * |
| 100 | * USB Host Resource Definition |
| 101 | * |
| 102 | */ |
| 103 | |
| 104 | static struct resource ehci_resources[] = { |
| 105 | { |
| 106 | .parent = &asic_resource, |
| 107 | .start = 0, |
| 108 | .end = 0xff, |
| 109 | .flags = IORESOURCE_MEM, |
| 110 | }, |
| 111 | { |
| 112 | .start = irq_usbehci, |
| 113 | .end = irq_usbehci, |
| 114 | .flags = IORESOURCE_IRQ, |
| 115 | }, |
| 116 | }; |
| 117 | |
| 118 | static u64 ehci_dmamask = DMA_BIT_MASK(32); |
| 119 | |
| 120 | static struct platform_device ehci_device = { |
| 121 | .name = "powertv-ehci", |
| 122 | .id = 0, |
| 123 | .num_resources = 2, |
| 124 | .resource = ehci_resources, |
| 125 | .dev = { |
| 126 | .dma_mask = &ehci_dmamask, |
| 127 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 128 | }, |
| 129 | }; |
| 130 | |
| 131 | static struct resource ohci_resources[] = { |
| 132 | { |
| 133 | .parent = &asic_resource, |
| 134 | .start = 0, |
| 135 | .end = 0xff, |
| 136 | .flags = IORESOURCE_MEM, |
| 137 | }, |
| 138 | { |
| 139 | .start = irq_usbohci, |
| 140 | .end = irq_usbohci, |
| 141 | .flags = IORESOURCE_IRQ, |
| 142 | }, |
| 143 | }; |
| 144 | |
| 145 | static u64 ohci_dmamask = DMA_BIT_MASK(32); |
| 146 | |
| 147 | static struct platform_device ohci_device = { |
| 148 | .name = "powertv-ohci", |
| 149 | .id = 0, |
| 150 | .num_resources = 2, |
| 151 | .resource = ohci_resources, |
| 152 | .dev = { |
| 153 | .dma_mask = &ohci_dmamask, |
| 154 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 155 | }, |
| 156 | }; |
| 157 | |
| 158 | static struct platform_device *platform_devices[] = { |
| 159 | &ehci_device, |
| 160 | &ohci_device, |
| 161 | }; |
| 162 | |
| 163 | /* |
| 164 | * |
| 165 | * Platform Configuration and Device Initialization |
| 166 | * |
| 167 | */ |
| 168 | static void __init fs_update(int pe, int md, int sdiv, int disable_div_by_3) |
| 169 | { |
| 170 | int en_prg, byp, pwr, nsb, val; |
| 171 | int sout; |
| 172 | |
| 173 | sout = 1; |
| 174 | en_prg = 1; |
| 175 | byp = 0; |
| 176 | nsb = 1; |
| 177 | pwr = 1; |
| 178 | |
| 179 | val = ((sdiv << 29) | (md << 24) | (pe<<8) | (sout<<3) | (byp<<2) | |
| 180 | (nsb<<1) | (disable_div_by_3<<5)); |
| 181 | |
| 182 | asic_write(val, usb_fs); |
| 183 | asic_write(val | (en_prg<<4), usb_fs); |
| 184 | asic_write(val | (en_prg<<4) | pwr, usb_fs); |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | * Allow override of bootloader-specified model |
| 189 | */ |
| 190 | static char __initdata cmdline[COMMAND_LINE_SIZE]; |
| 191 | |
| 192 | #define FORCEFAMILY_PARAM "forcefamily" |
| 193 | |
| 194 | static __init int check_forcefamily(unsigned char forced_family[2]) |
| 195 | { |
| 196 | const char *p; |
| 197 | |
| 198 | forced_family[0] = '\0'; |
| 199 | forced_family[1] = '\0'; |
| 200 | |
| 201 | /* Check the command line for a forcefamily directive */ |
| 202 | strncpy(cmdline, arcs_cmdline, COMMAND_LINE_SIZE - 1); |
| 203 | p = strstr(cmdline, FORCEFAMILY_PARAM); |
| 204 | if (p && (p != cmdline) && (*(p - 1) != ' ')) |
| 205 | p = strstr(p, " " FORCEFAMILY_PARAM "="); |
| 206 | |
| 207 | if (p) { |
| 208 | p += strlen(FORCEFAMILY_PARAM "="); |
| 209 | |
| 210 | if (*p == '\0' || *(p + 1) == '\0' || |
| 211 | (*(p + 2) != '\0' && *(p + 2) != ' ')) |
| 212 | pr_err(FORCEFAMILY_PARAM " must be exactly two " |
| 213 | "characters long, ignoring value\n"); |
| 214 | |
| 215 | else { |
| 216 | forced_family[0] = *p; |
| 217 | forced_family[1] = *(p + 1); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | /* |
| 225 | * platform_set_family - determine major platform family type. |
| 226 | * |
| 227 | * Returns family type; -1 if none |
| 228 | * Returns the family type; -1 if none |
| 229 | * |
| 230 | */ |
| 231 | static __init noinline void platform_set_family(void) |
| 232 | { |
| 233 | #define BOOTLDRFAMILY(byte1, byte0) (((byte1) << 8) | (byte0)) |
| 234 | |
| 235 | unsigned char forced_family[2]; |
| 236 | unsigned short bootldr_family; |
| 237 | |
| 238 | check_forcefamily(forced_family); |
| 239 | |
| 240 | if (forced_family[0] != '\0' && forced_family[1] != '\0') |
| 241 | bootldr_family = BOOTLDRFAMILY(forced_family[0], |
| 242 | forced_family[1]); |
| 243 | else { |
| 244 | |
| 245 | #ifdef CONFIG_BOOTLOADER_DRIVER |
| 246 | bootldr_family = (unsigned short) kbldr_GetSWFamily(); |
| 247 | #else |
| 248 | #if defined(CONFIG_BOOTLOADER_FAMILY) |
| 249 | bootldr_family = (unsigned short) BOOTLDRFAMILY( |
| 250 | CONFIG_BOOTLOADER_FAMILY[0], |
| 251 | CONFIG_BOOTLOADER_FAMILY[1]); |
| 252 | #else |
| 253 | #error "Unknown Bootloader Family" |
| 254 | #endif |
| 255 | #endif |
| 256 | } |
| 257 | |
| 258 | pr_info("Bootloader Family = 0x%04X\n", bootldr_family); |
| 259 | |
| 260 | switch (bootldr_family) { |
| 261 | case BOOTLDRFAMILY('R', '1'): |
| 262 | platform_family = FAMILY_1500; |
| 263 | break; |
| 264 | case BOOTLDRFAMILY('4', '4'): |
| 265 | platform_family = FAMILY_4500; |
| 266 | break; |
| 267 | case BOOTLDRFAMILY('4', '6'): |
| 268 | platform_family = FAMILY_4600; |
| 269 | break; |
| 270 | case BOOTLDRFAMILY('A', '1'): |
| 271 | platform_family = FAMILY_4600VZA; |
| 272 | break; |
| 273 | case BOOTLDRFAMILY('8', '5'): |
| 274 | platform_family = FAMILY_8500; |
| 275 | break; |
| 276 | case BOOTLDRFAMILY('R', '2'): |
| 277 | platform_family = FAMILY_8500RNG; |
| 278 | break; |
| 279 | case BOOTLDRFAMILY('8', '6'): |
| 280 | platform_family = FAMILY_8600; |
| 281 | break; |
| 282 | case BOOTLDRFAMILY('B', '1'): |
| 283 | platform_family = FAMILY_8600VZB; |
| 284 | break; |
| 285 | case BOOTLDRFAMILY('E', '1'): |
| 286 | platform_family = FAMILY_1500VZE; |
| 287 | break; |
| 288 | case BOOTLDRFAMILY('F', '1'): |
| 289 | platform_family = FAMILY_1500VZF; |
| 290 | break; |
| 291 | default: |
| 292 | platform_family = -1; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | unsigned int platform_get_family(void) |
| 297 | { |
| 298 | return platform_family; |
| 299 | } |
| 300 | EXPORT_SYMBOL(platform_get_family); |
| 301 | |
| 302 | /* |
| 303 | * \brief usb_eye_configure() for optimizing the USB eye on Calliope. |
| 304 | * |
| 305 | * \param unsigned int value saved to the register. |
| 306 | * |
| 307 | * \return none |
| 308 | * |
| 309 | */ |
| 310 | static void __init usb_eye_configure(unsigned int value) |
| 311 | { |
| 312 | asic_write(asic_read(crt_spare) | value, crt_spare); |
| 313 | } |
| 314 | |
| 315 | /* |
| 316 | * platform_get_asic - determine the ASIC type. |
| 317 | * |
| 318 | * \param none |
| 319 | * |
| 320 | * \return ASIC type; ASIC_UNKNOWN if none |
| 321 | * |
| 322 | */ |
| 323 | enum asic_type platform_get_asic(void) |
| 324 | { |
| 325 | return asic; |
| 326 | } |
| 327 | EXPORT_SYMBOL(platform_get_asic); |
| 328 | |
| 329 | /* |
| 330 | * platform_configure_usb - usb configuration based on platform type. |
| 331 | * @bcm1_usb2_ctl: value for the BCM1_USB2_CTL register, which is |
| 332 | * quirky |
| 333 | */ |
| 334 | static void __init platform_configure_usb(void) |
| 335 | { |
| 336 | u32 bcm1_usb2_ctl; |
| 337 | |
| 338 | if (usb_configured) |
| 339 | return; |
| 340 | |
| 341 | switch (asic) { |
| 342 | case ASIC_ZEUS: |
| 343 | fs_update(0x0000, 0x11, 0x02, 0); |
| 344 | bcm1_usb2_ctl = 0x803; |
| 345 | break; |
| 346 | |
| 347 | case ASIC_CRONUS: |
| 348 | case ASIC_CRONUSLITE: |
| 349 | fs_update(0x0000, 0x11, 0x02, 0); |
| 350 | bcm1_usb2_ctl = 0x803; |
| 351 | break; |
| 352 | |
| 353 | case ASIC_CALLIOPE: |
| 354 | fs_update(0x0000, 0x11, 0x02, 1); |
| 355 | |
| 356 | switch (platform_family) { |
| 357 | case FAMILY_1500VZE: |
| 358 | break; |
| 359 | |
| 360 | case FAMILY_1500VZF: |
| 361 | usb_eye_configure(0x003c0000); |
| 362 | break; |
| 363 | |
| 364 | default: |
| 365 | usb_eye_configure(0x00300000); |
| 366 | break; |
| 367 | } |
| 368 | |
| 369 | bcm1_usb2_ctl = 0x803; |
| 370 | break; |
| 371 | |
| 372 | default: |
| 373 | pr_err("Unknown ASIC type: %d\n", asic); |
| 374 | break; |
| 375 | } |
| 376 | |
| 377 | /* turn on USB power */ |
| 378 | asic_write(0, usb2_strap); |
| 379 | /* Enable all OHCI interrupts */ |
| 380 | asic_write(bcm1_usb2_ctl, usb2_control); |
| 381 | /* USB2_STBUS_OBC store32/load32 */ |
| 382 | asic_write(3, usb2_stbus_obc); |
| 383 | /* USB2_STBUS_MESS_SIZE 2 packets */ |
| 384 | asic_write(1, usb2_stbus_mess_size); |
| 385 | /* USB2_STBUS_CHUNK_SIZE 2 packets */ |
| 386 | asic_write(1, usb2_stbus_chunk_size); |
| 387 | |
| 388 | usb_configured = true; |
| 389 | } |
| 390 | |
| 391 | /* |
| 392 | * Set up the USB EHCI interface |
| 393 | */ |
| 394 | void platform_configure_usb_ehci() |
| 395 | { |
| 396 | platform_configure_usb(); |
| 397 | } |
| 398 | |
| 399 | /* |
| 400 | * Set up the USB OHCI interface |
| 401 | */ |
| 402 | void platform_configure_usb_ohci() |
| 403 | { |
| 404 | platform_configure_usb(); |
| 405 | } |
| 406 | |
| 407 | /* |
| 408 | * Shut the USB EHCI interface down--currently a NOP |
| 409 | */ |
| 410 | void platform_unconfigure_usb_ehci() |
| 411 | { |
| 412 | } |
| 413 | |
| 414 | /* |
| 415 | * Shut the USB OHCI interface down--currently a NOP |
| 416 | */ |
| 417 | void platform_unconfigure_usb_ohci() |
| 418 | { |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * configure_platform - configuration based on platform type. |
| 423 | */ |
| 424 | void __init configure_platform(void) |
| 425 | { |
| 426 | platform_set_family(); |
| 427 | |
| 428 | switch (platform_family) { |
| 429 | case FAMILY_1500: |
| 430 | case FAMILY_1500VZE: |
| 431 | case FAMILY_1500VZF: |
| 432 | platform_features = FFS_CAPABLE; |
| 433 | asic = ASIC_CALLIOPE; |
| 434 | asic_phy_base = CALLIOPE_IO_BASE; |
| 435 | register_map = &calliope_register_map; |
| 436 | asic_base = (unsigned long)ioremap_nocache(asic_phy_base, |
| 437 | ASIC_IO_SIZE); |
| 438 | |
| 439 | if (platform_family == FAMILY_1500VZE) { |
| 440 | gp_resources = non_dvr_vze_calliope_resources; |
| 441 | pr_info("Platform: 1500/Vz Class E - " |
| 442 | "CALLIOPE, NON_DVR_CAPABLE\n"); |
| 443 | } else if (platform_family == FAMILY_1500VZF) { |
| 444 | gp_resources = non_dvr_vzf_calliope_resources; |
| 445 | pr_info("Platform: 1500/Vz Class F - " |
| 446 | "CALLIOPE, NON_DVR_CAPABLE\n"); |
| 447 | } else { |
| 448 | gp_resources = non_dvr_calliope_resources; |
| 449 | pr_info("Platform: 1500/RNG100 - CALLIOPE, " |
| 450 | "NON_DVR_CAPABLE\n"); |
| 451 | } |
| 452 | break; |
| 453 | |
| 454 | case FAMILY_4500: |
| 455 | platform_features = FFS_CAPABLE | PCIE_CAPABLE | |
| 456 | DISPLAY_CAPABLE; |
| 457 | asic = ASIC_ZEUS; |
| 458 | asic_phy_base = ZEUS_IO_BASE; |
| 459 | register_map = &zeus_register_map; |
| 460 | asic_base = (unsigned long)ioremap_nocache(asic_phy_base, |
| 461 | ASIC_IO_SIZE); |
| 462 | gp_resources = non_dvr_zeus_resources; |
| 463 | |
| 464 | pr_info("Platform: 4500 - ZEUS, NON_DVR_CAPABLE\n"); |
| 465 | break; |
| 466 | |
| 467 | case FAMILY_4600: |
| 468 | { |
| 469 | unsigned int chipversion = 0; |
| 470 | |
| 471 | /* The settop has PCIE but it isn't used, so don't advertise |
| 472 | * it*/ |
| 473 | platform_features = FFS_CAPABLE | DISPLAY_CAPABLE; |
| 474 | asic_phy_base = CRONUS_IO_BASE; /* same as Cronus */ |
| 475 | register_map = &cronus_register_map; /* same as Cronus */ |
| 476 | asic_base = (unsigned long)ioremap_nocache(asic_phy_base, |
| 477 | ASIC_IO_SIZE); |
| 478 | gp_resources = non_dvr_cronuslite_resources; |
| 479 | |
| 480 | /* ASIC version will determine if this is a real CronusLite or |
| 481 | * Castrati(Cronus) */ |
| 482 | chipversion = asic_read(chipver3) << 24; |
| 483 | chipversion |= asic_read(chipver2) << 16; |
| 484 | chipversion |= asic_read(chipver1) << 8; |
| 485 | chipversion |= asic_read(chipver0); |
| 486 | |
| 487 | if ((chipversion == CRONUS_10) || (chipversion == CRONUS_11)) |
| 488 | asic = ASIC_CRONUS; |
| 489 | else |
| 490 | asic = ASIC_CRONUSLITE; |
| 491 | |
| 492 | pr_info("Platform: 4600 - %s, NON_DVR_CAPABLE, " |
| 493 | "chipversion=0x%08X\n", |
| 494 | (asic == ASIC_CRONUS) ? "CRONUS" : "CRONUS LITE", |
| 495 | chipversion); |
| 496 | break; |
| 497 | } |
| 498 | case FAMILY_4600VZA: |
| 499 | platform_features = FFS_CAPABLE | DISPLAY_CAPABLE; |
| 500 | asic = ASIC_CRONUS; |
| 501 | asic_phy_base = CRONUS_IO_BASE; |
| 502 | register_map = &cronus_register_map; |
| 503 | asic_base = (unsigned long)ioremap_nocache(asic_phy_base, |
| 504 | ASIC_IO_SIZE); |
| 505 | gp_resources = non_dvr_cronus_resources; |
| 506 | |
| 507 | pr_info("Platform: Vz Class A - CRONUS, NON_DVR_CAPABLE\n"); |
| 508 | break; |
| 509 | |
| 510 | case FAMILY_8500: |
| 511 | case FAMILY_8500RNG: |
| 512 | platform_features = DVR_CAPABLE | PCIE_CAPABLE | |
| 513 | DISPLAY_CAPABLE; |
| 514 | asic = ASIC_ZEUS; |
| 515 | asic_phy_base = ZEUS_IO_BASE; |
| 516 | register_map = &zeus_register_map; |
| 517 | asic_base = (unsigned long)ioremap_nocache(asic_phy_base, |
| 518 | ASIC_IO_SIZE); |
| 519 | gp_resources = dvr_zeus_resources; |
| 520 | |
| 521 | pr_info("Platform: 8500/RNG200 - ZEUS, DVR_CAPABLE\n"); |
| 522 | break; |
| 523 | |
| 524 | case FAMILY_8600: |
| 525 | case FAMILY_8600VZB: |
| 526 | platform_features = DVR_CAPABLE | PCIE_CAPABLE | |
| 527 | DISPLAY_CAPABLE; |
| 528 | asic = ASIC_CRONUS; |
| 529 | asic_phy_base = CRONUS_IO_BASE; |
| 530 | register_map = &cronus_register_map; |
| 531 | asic_base = (unsigned long)ioremap_nocache(asic_phy_base, |
| 532 | ASIC_IO_SIZE); |
| 533 | gp_resources = dvr_cronus_resources; |
| 534 | |
| 535 | pr_info("Platform: 8600/Vz Class B - CRONUS, " |
| 536 | "DVR_CAPABLE\n"); |
| 537 | break; |
| 538 | |
| 539 | default: |
| 540 | pr_crit("Platform: UNKNOWN PLATFORM\n"); |
| 541 | break; |
| 542 | } |
| 543 | |
| 544 | switch (asic) { |
| 545 | case ASIC_ZEUS: |
| 546 | phys_to_bus_offset = 0x30000000; |
| 547 | break; |
| 548 | case ASIC_CALLIOPE: |
| 549 | phys_to_bus_offset = 0x10000000; |
| 550 | break; |
| 551 | case ASIC_CRONUSLITE: |
| 552 | /* Fall through */ |
| 553 | case ASIC_CRONUS: |
| 554 | /* |
| 555 | * TODO: We suppose 0x10000000 aliases into 0x20000000- |
| 556 | * 0x2XXXXXXX. If 0x10000000 aliases into 0x60000000- |
| 557 | * 0x6XXXXXXX, the offset should be 0x50000000, not 0x10000000. |
| 558 | */ |
| 559 | phys_to_bus_offset = 0x10000000; |
| 560 | break; |
| 561 | default: |
| 562 | phys_to_bus_offset = 0x00000000; |
| 563 | break; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * platform_devices_init - sets up USB device resourse. |
| 569 | */ |
| 570 | static int __init platform_devices_init(void) |
| 571 | { |
| 572 | pr_notice("%s: ----- Initializing USB resources -----\n", __func__); |
| 573 | |
| 574 | asic_resource.start = asic_phy_base; |
| 575 | asic_resource.end += asic_resource.start; |
| 576 | |
| 577 | ehci_resources[0].start = asic_reg_phys_addr(ehci_hcapbase); |
| 578 | ehci_resources[0].end += ehci_resources[0].start; |
| 579 | |
| 580 | ohci_resources[0].start = asic_reg_phys_addr(ohci_hc_revision); |
| 581 | ohci_resources[0].end += ohci_resources[0].start; |
| 582 | |
| 583 | set_io_port_base(0); |
| 584 | |
| 585 | platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices)); |
| 586 | |
| 587 | return 0; |
| 588 | } |
| 589 | |
| 590 | arch_initcall(platform_devices_init); |
| 591 | |
| 592 | /* |
| 593 | * |
| 594 | * BOOTMEM ALLOCATION |
| 595 | * |
| 596 | */ |
| 597 | /* |
| 598 | * Allocates/reserves the Platform memory resources early in the boot process. |
| 599 | * This ignores any resources that are designated IORESOURCE_IO |
| 600 | */ |
| 601 | void __init platform_alloc_bootmem(void) |
| 602 | { |
| 603 | int i; |
| 604 | int total = 0; |
| 605 | |
| 606 | /* Get persistent memory data from command line before allocating |
| 607 | * resources. This need to happen before normal command line parsing |
| 608 | * has been done */ |
| 609 | pmem_setup_resource(); |
| 610 | |
| 611 | /* Loop through looking for resources that want a particular address */ |
| 612 | for (i = 0; gp_resources[i].flags != 0; i++) { |
| 613 | int size = gp_resources[i].end - gp_resources[i].start + 1; |
| 614 | if ((gp_resources[i].start != 0) && |
| 615 | ((gp_resources[i].flags & IORESOURCE_MEM) != 0)) { |
| 616 | reserve_bootmem(bus_to_phys(gp_resources[i].start), |
| 617 | size, 0); |
| 618 | total += gp_resources[i].end - |
| 619 | gp_resources[i].start + 1; |
| 620 | pr_info("reserve resource %s at %08x (%u bytes)\n", |
| 621 | gp_resources[i].name, gp_resources[i].start, |
| 622 | gp_resources[i].end - |
| 623 | gp_resources[i].start + 1); |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | /* Loop through assigning addresses for those that are left */ |
| 628 | for (i = 0; gp_resources[i].flags != 0; i++) { |
| 629 | int size = gp_resources[i].end - gp_resources[i].start + 1; |
| 630 | if ((gp_resources[i].start == 0) && |
| 631 | ((gp_resources[i].flags & IORESOURCE_MEM) != 0)) { |
| 632 | void *mem = alloc_bootmem_pages(size); |
| 633 | |
| 634 | if (mem == NULL) |
| 635 | pr_err("Unable to allocate bootmem pages " |
| 636 | "for %s\n", gp_resources[i].name); |
| 637 | |
| 638 | else { |
| 639 | gp_resources[i].start = |
| 640 | phys_to_bus(virt_to_phys(mem)); |
| 641 | gp_resources[i].end = |
| 642 | gp_resources[i].start + size - 1; |
| 643 | total += size; |
| 644 | pr_info("allocate resource %s at %08x " |
| 645 | "(%u bytes)\n", |
| 646 | gp_resources[i].name, |
| 647 | gp_resources[i].start, size); |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | pr_info("Total Platform driver memory allocation: 0x%08x\n", total); |
| 653 | |
| 654 | /* indicate resources that are platform I/O related */ |
| 655 | for (i = 0; gp_resources[i].flags != 0; i++) { |
| 656 | if ((gp_resources[i].start != 0) && |
| 657 | ((gp_resources[i].flags & IORESOURCE_IO) != 0)) { |
| 658 | pr_info("reserved platform resource %s at %08x\n", |
| 659 | gp_resources[i].name, gp_resources[i].start); |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | /* |
| 665 | * |
| 666 | * PERSISTENT MEMORY (PMEM) CONFIGURATION |
| 667 | * |
| 668 | */ |
| 669 | static unsigned long pmemaddr __initdata; |
| 670 | |
| 671 | static int __init early_param_pmemaddr(char *p) |
| 672 | { |
| 673 | pmemaddr = (unsigned long)simple_strtoul(p, NULL, 0); |
| 674 | return 0; |
| 675 | } |
| 676 | early_param("pmemaddr", early_param_pmemaddr); |
| 677 | |
| 678 | static long pmemlen __initdata; |
| 679 | |
| 680 | static int __init early_param_pmemlen(char *p) |
| 681 | { |
| 682 | /* TODO: we can use this code when and if the bootloader ever changes this */ |
| 683 | #if 0 |
| 684 | pmemlen = (unsigned long)simple_strtoul(p, NULL, 0); |
| 685 | #else |
| 686 | pmemlen = 0x20000; |
| 687 | #endif |
| 688 | return 0; |
| 689 | } |
| 690 | early_param("pmemlen", early_param_pmemlen); |
| 691 | |
| 692 | /* |
| 693 | * Set up persistent memory. If we were given values, we patch the array of |
| 694 | * resources. Otherwise, persistent memory may be allocated anywhere at all. |
| 695 | */ |
| 696 | static void __init pmem_setup_resource(void) |
| 697 | { |
| 698 | struct resource *resource; |
| 699 | resource = asic_resource_get("DiagPersistentMemory"); |
| 700 | |
| 701 | if (resource && pmemaddr && pmemlen) { |
| 702 | /* The address provided by bootloader is in kseg0. Convert to |
| 703 | * a bus address. */ |
| 704 | resource->start = phys_to_bus(pmemaddr - 0x80000000); |
| 705 | resource->end = resource->start + pmemlen - 1; |
| 706 | |
| 707 | pr_info("persistent memory: start=0x%x end=0x%x\n", |
| 708 | resource->start, resource->end); |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | /* |
| 713 | * |
| 714 | * RESOURCE ACCESS FUNCTIONS |
| 715 | * |
| 716 | */ |
| 717 | |
| 718 | /** |
| 719 | * asic_resource_get - retrieves parameters for a platform resource. |
| 720 | * @name: string to match resource |
| 721 | * |
| 722 | * Returns a pointer to a struct resource corresponding to the given name. |
| 723 | * |
| 724 | * CANNOT BE NAMED platform_resource_get, which would be the obvious choice, |
| 725 | * as this function name is already declared |
| 726 | */ |
| 727 | struct resource *asic_resource_get(const char *name) |
| 728 | { |
| 729 | int i; |
| 730 | |
| 731 | for (i = 0; gp_resources[i].flags != 0; i++) { |
| 732 | if (strcmp(gp_resources[i].name, name) == 0) |
| 733 | return &gp_resources[i]; |
| 734 | } |
| 735 | |
| 736 | return NULL; |
| 737 | } |
| 738 | EXPORT_SYMBOL(asic_resource_get); |
| 739 | |
| 740 | /** |
| 741 | * platform_release_memory - release pre-allocated memory |
| 742 | * @ptr: pointer to memory to release |
| 743 | * @size: size of resource |
| 744 | * |
| 745 | * This must only be called for memory allocated or reserved via the boot |
| 746 | * memory allocator. |
| 747 | */ |
| 748 | void platform_release_memory(void *ptr, int size) |
| 749 | { |
| 750 | unsigned long addr; |
| 751 | unsigned long end; |
| 752 | |
| 753 | addr = ((unsigned long)ptr + (PAGE_SIZE - 1)) & PAGE_MASK; |
| 754 | end = ((unsigned long)ptr + size) & PAGE_MASK; |
| 755 | |
| 756 | for (; addr < end; addr += PAGE_SIZE) { |
| 757 | ClearPageReserved(virt_to_page(__va(addr))); |
| 758 | init_page_count(virt_to_page(__va(addr))); |
| 759 | free_page((unsigned long)__va(addr)); |
| 760 | } |
| 761 | } |
| 762 | EXPORT_SYMBOL(platform_release_memory); |
| 763 | |
| 764 | /* |
| 765 | * |
| 766 | * FEATURE AVAILABILITY FUNCTIONS |
| 767 | * |
| 768 | */ |
| 769 | int platform_supports_dvr(void) |
| 770 | { |
| 771 | return (platform_features & DVR_CAPABLE) != 0; |
| 772 | } |
| 773 | |
| 774 | int platform_supports_ffs(void) |
| 775 | { |
| 776 | return (platform_features & FFS_CAPABLE) != 0; |
| 777 | } |
| 778 | |
| 779 | int platform_supports_pcie(void) |
| 780 | { |
| 781 | return (platform_features & PCIE_CAPABLE) != 0; |
| 782 | } |
| 783 | |
| 784 | int platform_supports_display(void) |
| 785 | { |
| 786 | return (platform_features & DISPLAY_CAPABLE) != 0; |
| 787 | } |