3 * Description: Defines the platform resources for Gaia-based settops.
5 * Copyright (C) 2005-2009 Scientific-Atlanta, Inc.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * NOTE: The bootloader allocates persistent memory at an address which is
22 * 16 MiB below the end of the highest address in KSEG0. All fixed
23 * address memory reservations must avoid this region.
26 #include <linux/device.h>
27 #include <linux/kernel.h>
28 #include <linux/init.h>
29 #include <linux/resource.h>
30 #include <linux/serial_reg.h>
32 #include <linux/bootmem.h>
34 #include <linux/platform_device.h>
35 #include <linux/module.h>
36 #include <linux/gfp.h>
38 #include <linux/swap.h>
39 #include <linux/highmem.h>
40 #include <linux/dma-mapping.h>
42 #include <asm/mach-powertv/asic.h>
43 #include <asm/mach-powertv/asic_regs.h>
44 #include <asm/mach-powertv/interrupts.h>
46 #ifdef CONFIG_BOOTLOADER_DRIVER
47 #include <asm/mach-powertv/kbldr.h>
49 #include <asm/bootinfo.h>
51 #define BOOTLDRFAMILY(byte1, byte0) (((byte1) << 8) | (byte0))
56 static void pmem_setup_resource(void);
63 unsigned int platform_features;
64 unsigned int platform_family;
65 struct register_map _asic_register_map;
66 EXPORT_SYMBOL(_asic_register_map); /* Exported for testing */
67 unsigned long asic_phy_base;
68 unsigned long asic_base;
69 EXPORT_SYMBOL(asic_base); /* Exported for testing */
70 struct resource *gp_resources;
71 static bool usb_configured;
74 * Don't recommend to use it directly, it is usually used by kernel internally.
75 * Portable code should be using interfaces such as ioremp, dma_map_single, etc.
77 unsigned long phys_to_dma_offset;
78 EXPORT_SYMBOL(phys_to_dma_offset);
82 * IO Resource Definition
86 struct resource asic_resource = {
87 .name = "ASIC Resource",
90 .flags = IORESOURCE_MEM,
95 * USB Host Resource Definition
99 static struct resource ehci_resources[] = {
101 .parent = &asic_resource,
104 .flags = IORESOURCE_MEM,
107 .start = irq_usbehci,
109 .flags = IORESOURCE_IRQ,
113 static u64 ehci_dmamask = DMA_BIT_MASK(32);
115 static struct platform_device ehci_device = {
116 .name = "powertv-ehci",
119 .resource = ehci_resources,
121 .dma_mask = &ehci_dmamask,
122 .coherent_dma_mask = DMA_BIT_MASK(32),
126 static struct resource ohci_resources[] = {
128 .parent = &asic_resource,
131 .flags = IORESOURCE_MEM,
134 .start = irq_usbohci,
136 .flags = IORESOURCE_IRQ,
140 static u64 ohci_dmamask = DMA_BIT_MASK(32);
142 static struct platform_device ohci_device = {
143 .name = "powertv-ohci",
146 .resource = ohci_resources,
148 .dma_mask = &ohci_dmamask,
149 .coherent_dma_mask = DMA_BIT_MASK(32),
153 static struct platform_device *platform_devices[] = {
160 * Platform Configuration and Device Initialization
163 static void __init fs_update(int pe, int md, int sdiv, int disable_div_by_3)
165 int en_prg, byp, pwr, nsb, val;
174 val = ((sdiv << 29) | (md << 24) | (pe<<8) | (sout<<3) | (byp<<2) |
175 (nsb<<1) | (disable_div_by_3<<5));
177 asic_write(val, fs432x4b4_usb_ctl);
178 asic_write(val | (en_prg<<4), fs432x4b4_usb_ctl);
179 asic_write(val | (en_prg<<4) | pwr, fs432x4b4_usb_ctl);
183 * Allow override of bootloader-specified model
185 static char __initdata cmdline[COMMAND_LINE_SIZE];
187 #define FORCEFAMILY_PARAM "forcefamily"
189 static __init int check_forcefamily(unsigned char forced_family[2])
193 forced_family[0] = '\0';
194 forced_family[1] = '\0';
196 /* Check the command line for a forcefamily directive */
197 strncpy(cmdline, arcs_cmdline, COMMAND_LINE_SIZE - 1);
198 p = strstr(cmdline, FORCEFAMILY_PARAM);
199 if (p && (p != cmdline) && (*(p - 1) != ' '))
200 p = strstr(p, " " FORCEFAMILY_PARAM "=");
203 p += strlen(FORCEFAMILY_PARAM "=");
205 if (*p == '\0' || *(p + 1) == '\0' ||
206 (*(p + 2) != '\0' && *(p + 2) != ' '))
207 pr_err(FORCEFAMILY_PARAM " must be exactly two "
208 "characters long, ignoring value\n");
211 forced_family[0] = *p;
212 forced_family[1] = *(p + 1);
220 * platform_set_family - determine major platform family type.
222 * Returns family type; -1 if none
223 * Returns the family type; -1 if none
226 static __init noinline void platform_set_family(void)
228 #define BOOTLDRFAMILY(byte1, byte0) (((byte1) << 8) | (byte0))
230 unsigned char forced_family[2];
231 unsigned short bootldr_family;
233 check_forcefamily(forced_family);
235 if (forced_family[0] != '\0' && forced_family[1] != '\0')
236 bootldr_family = BOOTLDRFAMILY(forced_family[0],
240 #ifdef CONFIG_BOOTLOADER_DRIVER
241 bootldr_family = (unsigned short) kbldr_GetSWFamily();
243 #if defined(CONFIG_BOOTLOADER_FAMILY)
244 bootldr_family = (unsigned short) BOOTLDRFAMILY(
245 CONFIG_BOOTLOADER_FAMILY[0],
246 CONFIG_BOOTLOADER_FAMILY[1]);
248 #error "Unknown Bootloader Family"
253 pr_info("Bootloader Family = 0x%04X\n", bootldr_family);
255 switch (bootldr_family) {
256 case BOOTLDRFAMILY('R', '1'):
257 platform_family = FAMILY_1500;
259 case BOOTLDRFAMILY('4', '4'):
260 platform_family = FAMILY_4500;
262 case BOOTLDRFAMILY('4', '6'):
263 platform_family = FAMILY_4600;
265 case BOOTLDRFAMILY('A', '1'):
266 platform_family = FAMILY_4600VZA;
268 case BOOTLDRFAMILY('8', '5'):
269 platform_family = FAMILY_8500;
271 case BOOTLDRFAMILY('R', '2'):
272 platform_family = FAMILY_8500RNG;
274 case BOOTLDRFAMILY('8', '6'):
275 platform_family = FAMILY_8600;
277 case BOOTLDRFAMILY('B', '1'):
278 platform_family = FAMILY_8600VZB;
280 case BOOTLDRFAMILY('E', '1'):
281 platform_family = FAMILY_1500VZE;
283 case BOOTLDRFAMILY('F', '1'):
284 platform_family = FAMILY_1500VZF;
286 case BOOTLDRFAMILY('8', '7'):
287 platform_family = FAMILY_8700;
290 platform_family = -1;
294 unsigned int platform_get_family(void)
296 return platform_family;
298 EXPORT_SYMBOL(platform_get_family);
301 * \brief usb_eye_configure() for optimizing the USB eye on Calliope.
303 * \param unsigned int value saved to the register.
308 static void __init usb_eye_configure(unsigned int value)
310 asic_write(asic_read(crt_spare) | value, crt_spare);
314 * platform_get_asic - determine the ASIC type.
318 * \return ASIC type; ASIC_UNKNOWN if none
321 enum asic_type platform_get_asic(void)
325 EXPORT_SYMBOL(platform_get_asic);
328 * platform_configure_usb - usb configuration based on platform type.
329 * @bcm1_usb2_ctl: value for the BCM1_USB2_CTL register, which is
332 static void __init platform_configure_usb(void)
342 case ASIC_CRONUSLITE:
343 fs_update(0x0000, 0x11, 0x02, 0);
344 bcm1_usb2_ctl = 0x803;
348 fs_update(0x0000, 0x11, 0x02, 1);
350 switch (platform_family) {
355 usb_eye_configure(0x003c0000);
359 usb_eye_configure(0x00300000);
363 bcm1_usb2_ctl = 0x803;
367 pr_err("Unknown ASIC type: %d\n", asic);
371 /* turn on USB power */
372 asic_write(0, usb2_strap);
373 /* Enable all OHCI interrupts */
374 asic_write(bcm1_usb2_ctl, usb2_control);
375 /* USB2_STBUS_OBC store32/load32 */
376 asic_write(3, usb2_stbus_obc);
377 /* USB2_STBUS_MESS_SIZE 2 packets */
378 asic_write(1, usb2_stbus_mess_size);
379 /* USB2_STBUS_CHUNK_SIZE 2 packets */
380 asic_write(1, usb2_stbus_chunk_size);
382 usb_configured = true;
386 * Set up the USB EHCI interface
388 void platform_configure_usb_ehci()
390 platform_configure_usb();
394 * Set up the USB OHCI interface
396 void platform_configure_usb_ohci()
398 platform_configure_usb();
402 * Shut the USB EHCI interface down--currently a NOP
404 void platform_unconfigure_usb_ehci()
409 * Shut the USB OHCI interface down--currently a NOP
411 void platform_unconfigure_usb_ohci()
415 static void __init set_register_map(unsigned long phys_base,
416 const struct register_map *map)
418 asic_phy_base = phys_base;
419 _asic_register_map = *map;
420 register_map_virtualize(&_asic_register_map);
421 asic_base = (unsigned long)ioremap_nocache(phys_base, ASIC_IO_SIZE);
425 * configure_platform - configuration based on platform type.
427 void __init configure_platform(void)
429 platform_set_family();
431 switch (platform_family) {
435 platform_features = FFS_CAPABLE;
436 asic = ASIC_CALLIOPE;
437 set_register_map(CALLIOPE_IO_BASE, &calliope_register_map);
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");
448 gp_resources = non_dvr_calliope_resources;
449 pr_info("Platform: 1500/RNG100 - CALLIOPE, "
450 "NON_DVR_CAPABLE\n");
455 platform_features = FFS_CAPABLE | PCIE_CAPABLE |
458 set_register_map(ZEUS_IO_BASE, &zeus_register_map);
459 gp_resources = non_dvr_zeus_resources;
461 pr_info("Platform: 4500 - ZEUS, NON_DVR_CAPABLE\n");
466 unsigned int chipversion = 0;
468 /* The settop has PCIE but it isn't used, so don't advertise
470 platform_features = FFS_CAPABLE | DISPLAY_CAPABLE;
472 /* Cronus and Cronus Lite have the same register map */
473 set_register_map(CRONUS_IO_BASE, &cronus_register_map);
475 /* ASIC version will determine if this is a real CronusLite or
476 * Castrati(Cronus) */
477 chipversion = asic_read(chipver3) << 24;
478 chipversion |= asic_read(chipver2) << 16;
479 chipversion |= asic_read(chipver1) << 8;
480 chipversion |= asic_read(chipver0);
482 if ((chipversion == CRONUS_10) || (chipversion == CRONUS_11))
485 asic = ASIC_CRONUSLITE;
487 gp_resources = non_dvr_cronuslite_resources;
488 pr_info("Platform: 4600 - %s, NON_DVR_CAPABLE, "
489 "chipversion=0x%08X\n",
490 (asic == ASIC_CRONUS) ? "CRONUS" : "CRONUS LITE",
495 platform_features = FFS_CAPABLE | DISPLAY_CAPABLE;
497 set_register_map(CRONUS_IO_BASE, &cronus_register_map);
498 gp_resources = non_dvr_cronus_resources;
500 pr_info("Platform: Vz Class A - CRONUS, NON_DVR_CAPABLE\n");
505 platform_features = DVR_CAPABLE | PCIE_CAPABLE |
508 set_register_map(ZEUS_IO_BASE, &zeus_register_map);
509 gp_resources = dvr_zeus_resources;
511 pr_info("Platform: 8500/RNG200 - ZEUS, DVR_CAPABLE\n");
516 platform_features = DVR_CAPABLE | PCIE_CAPABLE |
519 set_register_map(CRONUS_IO_BASE, &cronus_register_map);
520 gp_resources = dvr_cronus_resources;
522 pr_info("Platform: 8600/Vz Class B - CRONUS, "
527 platform_features = FFS_CAPABLE | PCIE_CAPABLE;
529 set_register_map(GAIA_IO_BASE, &gaia_register_map);
530 gp_resources = dvr_gaia_resources;
532 pr_info("Platform: 8700 - GAIA, DVR_CAPABLE\n");
536 pr_crit("Platform: UNKNOWN PLATFORM\n");
542 phys_to_dma_offset = 0x30000000;
545 phys_to_dma_offset = 0x10000000;
547 case ASIC_CRONUSLITE:
551 * TODO: We suppose 0x10000000 aliases into 0x20000000-
552 * 0x2XXXXXXX. If 0x10000000 aliases into 0x60000000-
553 * 0x6XXXXXXX, the offset should be 0x50000000, not 0x10000000.
555 phys_to_dma_offset = 0x10000000;
558 phys_to_dma_offset = 0x00000000;
564 * platform_devices_init - sets up USB device resourse.
566 static int __init platform_devices_init(void)
568 pr_notice("%s: ----- Initializing USB resources -----\n", __func__);
570 asic_resource.start = asic_phy_base;
571 asic_resource.end += asic_resource.start;
573 ehci_resources[0].start = asic_reg_phys_addr(ehci_hcapbase);
574 ehci_resources[0].end += ehci_resources[0].start;
576 ohci_resources[0].start = asic_reg_phys_addr(ohci_hc_revision);
577 ohci_resources[0].end += ohci_resources[0].start;
581 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
586 arch_initcall(platform_devices_init);
594 * Allocates/reserves the Platform memory resources early in the boot process.
595 * This ignores any resources that are designated IORESOURCE_IO
597 void __init platform_alloc_bootmem(void)
602 /* Get persistent memory data from command line before allocating
603 * resources. This need to happen before normal command line parsing
605 pmem_setup_resource();
607 /* Loop through looking for resources that want a particular address */
608 for (i = 0; gp_resources[i].flags != 0; i++) {
609 int size = gp_resources[i].end - gp_resources[i].start + 1;
610 if ((gp_resources[i].start != 0) &&
611 ((gp_resources[i].flags & IORESOURCE_MEM) != 0)) {
612 reserve_bootmem(dma_to_phys(gp_resources[i].start),
614 total += gp_resources[i].end -
615 gp_resources[i].start + 1;
616 pr_info("reserve resource %s at %08x (%u bytes)\n",
617 gp_resources[i].name, gp_resources[i].start,
618 gp_resources[i].end -
619 gp_resources[i].start + 1);
623 /* Loop through assigning addresses for those that are left */
624 for (i = 0; gp_resources[i].flags != 0; i++) {
625 int size = gp_resources[i].end - gp_resources[i].start + 1;
626 if ((gp_resources[i].start == 0) &&
627 ((gp_resources[i].flags & IORESOURCE_MEM) != 0)) {
628 void *mem = alloc_bootmem_pages(size);
631 pr_err("Unable to allocate bootmem pages "
632 "for %s\n", gp_resources[i].name);
635 gp_resources[i].start =
636 phys_to_dma(virt_to_phys(mem));
637 gp_resources[i].end =
638 gp_resources[i].start + size - 1;
640 pr_info("allocate resource %s at %08x "
642 gp_resources[i].name,
643 gp_resources[i].start, size);
648 pr_info("Total Platform driver memory allocation: 0x%08x\n", total);
650 /* indicate resources that are platform I/O related */
651 for (i = 0; gp_resources[i].flags != 0; i++) {
652 if ((gp_resources[i].start != 0) &&
653 ((gp_resources[i].flags & IORESOURCE_IO) != 0)) {
654 pr_info("reserved platform resource %s at %08x\n",
655 gp_resources[i].name, gp_resources[i].start);
662 * PERSISTENT MEMORY (PMEM) CONFIGURATION
665 static unsigned long pmemaddr __initdata;
667 static int __init early_param_pmemaddr(char *p)
669 pmemaddr = (unsigned long)simple_strtoul(p, NULL, 0);
672 early_param("pmemaddr", early_param_pmemaddr);
674 static long pmemlen __initdata;
676 static int __init early_param_pmemlen(char *p)
678 /* TODO: we can use this code when and if the bootloader ever changes this */
680 pmemlen = (unsigned long)simple_strtoul(p, NULL, 0);
686 early_param("pmemlen", early_param_pmemlen);
689 * Set up persistent memory. If we were given values, we patch the array of
690 * resources. Otherwise, persistent memory may be allocated anywhere at all.
692 static void __init pmem_setup_resource(void)
694 struct resource *resource;
695 resource = asic_resource_get("DiagPersistentMemory");
697 if (resource && pmemaddr && pmemlen) {
698 /* The address provided by bootloader is in kseg0. Convert to
700 resource->start = phys_to_dma(pmemaddr - 0x80000000);
701 resource->end = resource->start + pmemlen - 1;
703 pr_info("persistent memory: start=0x%x end=0x%x\n",
704 resource->start, resource->end);
710 * RESOURCE ACCESS FUNCTIONS
715 * asic_resource_get - retrieves parameters for a platform resource.
716 * @name: string to match resource
718 * Returns a pointer to a struct resource corresponding to the given name.
720 * CANNOT BE NAMED platform_resource_get, which would be the obvious choice,
721 * as this function name is already declared
723 struct resource *asic_resource_get(const char *name)
727 for (i = 0; gp_resources[i].flags != 0; i++) {
728 if (strcmp(gp_resources[i].name, name) == 0)
729 return &gp_resources[i];
734 EXPORT_SYMBOL(asic_resource_get);
737 * platform_release_memory - release pre-allocated memory
738 * @ptr: pointer to memory to release
739 * @size: size of resource
741 * This must only be called for memory allocated or reserved via the boot
744 void platform_release_memory(void *ptr, int size)
749 addr = ((unsigned long)ptr + (PAGE_SIZE - 1)) & PAGE_MASK;
750 end = ((unsigned long)ptr + size) & PAGE_MASK;
752 for (; addr < end; addr += PAGE_SIZE) {
753 ClearPageReserved(virt_to_page(__va(addr)));
754 init_page_count(virt_to_page(__va(addr)));
755 free_page((unsigned long)__va(addr));
758 EXPORT_SYMBOL(platform_release_memory);
762 * FEATURE AVAILABILITY FUNCTIONS
765 int platform_supports_dvr(void)
767 return (platform_features & DVR_CAPABLE) != 0;
770 int platform_supports_ffs(void)
772 return (platform_features & FFS_CAPABLE) != 0;
775 int platform_supports_pcie(void)
777 return (platform_features & PCIE_CAPABLE) != 0;
780 int platform_supports_display(void)
782 return (platform_features & DISPLAY_CAPABLE) != 0;