Path: blob/master/arch/mips/powertv/asic/asic_devices.c
10818 views
/*1*2* Description: Defines the platform resources for Gaia-based settops.3*4* Copyright (C) 2005-2009 Scientific-Atlanta, Inc.5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License as published by8* the Free Software Foundation; either version 2 of the License, or9* (at your option) any later version.10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16* You should have received a copy of the GNU General Public License17* along with this program; if not, write to the Free Software18* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA19*20* NOTE: The bootloader allocates persistent memory at an address which is21* 16 MiB below the end of the highest address in KSEG0. All fixed22* address memory reservations must avoid this region.23*/2425#include <linux/device.h>26#include <linux/kernel.h>27#include <linux/init.h>28#include <linux/resource.h>29#include <linux/serial_reg.h>30#include <linux/io.h>31#include <linux/bootmem.h>32#include <linux/mm.h>33#include <linux/platform_device.h>34#include <linux/module.h>35#include <asm/page.h>36#include <linux/swap.h>37#include <linux/highmem.h>38#include <linux/dma-mapping.h>3940#include <asm/mach-powertv/asic.h>41#include <asm/mach-powertv/asic_regs.h>42#include <asm/mach-powertv/interrupts.h>4344#ifdef CONFIG_BOOTLOADER_DRIVER45#include <asm/mach-powertv/kbldr.h>46#endif47#include <asm/bootinfo.h>4849#define BOOTLDRFAMILY(byte1, byte0) (((byte1) << 8) | (byte0))5051/*52* Forward Prototypes53*/54static void pmem_setup_resource(void);5556/*57* Global Variables58*/59enum asic_type asic;6061unsigned int platform_features;62unsigned int platform_family;63struct register_map _asic_register_map;64EXPORT_SYMBOL(_asic_register_map); /* Exported for testing */65unsigned long asic_phy_base;66unsigned long asic_base;67EXPORT_SYMBOL(asic_base); /* Exported for testing */68struct resource *gp_resources;6970/*71* Don't recommend to use it directly, it is usually used by kernel internally.72* Portable code should be using interfaces such as ioremp, dma_map_single, etc.73*/74unsigned long phys_to_dma_offset;75EXPORT_SYMBOL(phys_to_dma_offset);7677/*78*79* IO Resource Definition80*81*/8283struct resource asic_resource = {84.name = "ASIC Resource",85.start = 0,86.end = ASIC_IO_SIZE,87.flags = IORESOURCE_MEM,88};8990/*91* Allow override of bootloader-specified model92* Returns zero on success, a negative errno value on failure. This parameter93* allows overriding of the bootloader-specified model.94*/95static char __initdata cmdline[COMMAND_LINE_SIZE];9697#define FORCEFAMILY_PARAM "forcefamily"9899/*100* check_forcefamily - check for, and parse, forcefamily command line parameter101* @forced_family: Pointer to two-character array in which to store the102* value of the forcedfamily parameter, if any.103*/104static __init int check_forcefamily(unsigned char forced_family[2])105{106const char *p;107108forced_family[0] = '\0';109forced_family[1] = '\0';110111/* Check the command line for a forcefamily directive */112strncpy(cmdline, arcs_cmdline, COMMAND_LINE_SIZE - 1);113p = strstr(cmdline, FORCEFAMILY_PARAM);114if (p && (p != cmdline) && (*(p - 1) != ' '))115p = strstr(p, " " FORCEFAMILY_PARAM "=");116117if (p) {118p += strlen(FORCEFAMILY_PARAM "=");119120if (*p == '\0' || *(p + 1) == '\0' ||121(*(p + 2) != '\0' && *(p + 2) != ' '))122pr_err(FORCEFAMILY_PARAM " must be exactly two "123"characters long, ignoring value\n");124125else {126forced_family[0] = *p;127forced_family[1] = *(p + 1);128}129}130131return 0;132}133134/*135* platform_set_family - determine major platform family type.136*137* Returns family type; -1 if none138* Returns the family type; -1 if none139*140*/141static __init noinline void platform_set_family(void)142{143unsigned char forced_family[2];144unsigned short bootldr_family;145146if (check_forcefamily(forced_family) == 0)147bootldr_family = BOOTLDRFAMILY(forced_family[0],148forced_family[1]);149else {150151#ifdef CONFIG_BOOTLOADER_DRIVER152bootldr_family = (unsigned short) kbldr_GetSWFamily();153#else154#if defined(CONFIG_BOOTLOADER_FAMILY)155bootldr_family = (unsigned short) BOOTLDRFAMILY(156CONFIG_BOOTLOADER_FAMILY[0],157CONFIG_BOOTLOADER_FAMILY[1]);158#else159#error "Unknown Bootloader Family"160#endif161#endif162}163164pr_info("Bootloader Family = 0x%04X\n", bootldr_family);165166switch (bootldr_family) {167case BOOTLDRFAMILY('R', '1'):168platform_family = FAMILY_1500;169break;170case BOOTLDRFAMILY('4', '4'):171platform_family = FAMILY_4500;172break;173case BOOTLDRFAMILY('4', '6'):174platform_family = FAMILY_4600;175break;176case BOOTLDRFAMILY('A', '1'):177platform_family = FAMILY_4600VZA;178break;179case BOOTLDRFAMILY('8', '5'):180platform_family = FAMILY_8500;181break;182case BOOTLDRFAMILY('R', '2'):183platform_family = FAMILY_8500RNG;184break;185case BOOTLDRFAMILY('8', '6'):186platform_family = FAMILY_8600;187break;188case BOOTLDRFAMILY('B', '1'):189platform_family = FAMILY_8600VZB;190break;191case BOOTLDRFAMILY('E', '1'):192platform_family = FAMILY_1500VZE;193break;194case BOOTLDRFAMILY('F', '1'):195platform_family = FAMILY_1500VZF;196break;197case BOOTLDRFAMILY('8', '7'):198platform_family = FAMILY_8700;199break;200default:201platform_family = -1;202}203}204205unsigned int platform_get_family(void)206{207return platform_family;208}209EXPORT_SYMBOL(platform_get_family);210211/*212* platform_get_asic - determine the ASIC type.213*214* Returns the ASIC type, or ASIC_UNKNOWN if unknown215*216*/217enum asic_type platform_get_asic(void)218{219return asic;220}221EXPORT_SYMBOL(platform_get_asic);222223/*224* set_register_map - set ASIC register configuration225* @phys_base: Physical address of the base of the ASIC registers226* @map: Description of key ASIC registers227*/228static void __init set_register_map(unsigned long phys_base,229const struct register_map *map)230{231asic_phy_base = phys_base;232_asic_register_map = *map;233register_map_virtualize(&_asic_register_map);234asic_base = (unsigned long)ioremap_nocache(phys_base, ASIC_IO_SIZE);235}236237/**238* configure_platform - configuration based on platform type.239*/240void __init configure_platform(void)241{242platform_set_family();243244switch (platform_family) {245case FAMILY_1500:246case FAMILY_1500VZE:247case FAMILY_1500VZF:248platform_features = FFS_CAPABLE;249asic = ASIC_CALLIOPE;250set_register_map(CALLIOPE_IO_BASE, &calliope_register_map);251252if (platform_family == FAMILY_1500VZE) {253gp_resources = non_dvr_vze_calliope_resources;254pr_info("Platform: 1500/Vz Class E - "255"CALLIOPE, NON_DVR_CAPABLE\n");256} else if (platform_family == FAMILY_1500VZF) {257gp_resources = non_dvr_vzf_calliope_resources;258pr_info("Platform: 1500/Vz Class F - "259"CALLIOPE, NON_DVR_CAPABLE\n");260} else {261gp_resources = non_dvr_calliope_resources;262pr_info("Platform: 1500/RNG100 - CALLIOPE, "263"NON_DVR_CAPABLE\n");264}265break;266267case FAMILY_4500:268platform_features = FFS_CAPABLE | PCIE_CAPABLE |269DISPLAY_CAPABLE;270asic = ASIC_ZEUS;271set_register_map(ZEUS_IO_BASE, &zeus_register_map);272gp_resources = non_dvr_zeus_resources;273274pr_info("Platform: 4500 - ZEUS, NON_DVR_CAPABLE\n");275break;276277case FAMILY_4600:278{279unsigned int chipversion = 0;280281/* The settop has PCIE but it isn't used, so don't advertise282* it*/283platform_features = FFS_CAPABLE | DISPLAY_CAPABLE;284285/* Cronus and Cronus Lite have the same register map */286set_register_map(CRONUS_IO_BASE, &cronus_register_map);287288/* ASIC version will determine if this is a real CronusLite or289* Castrati(Cronus) */290chipversion = asic_read(chipver3) << 24;291chipversion |= asic_read(chipver2) << 16;292chipversion |= asic_read(chipver1) << 8;293chipversion |= asic_read(chipver0);294295if ((chipversion == CRONUS_10) || (chipversion == CRONUS_11))296asic = ASIC_CRONUS;297else298asic = ASIC_CRONUSLITE;299300gp_resources = non_dvr_cronuslite_resources;301pr_info("Platform: 4600 - %s, NON_DVR_CAPABLE, "302"chipversion=0x%08X\n",303(asic == ASIC_CRONUS) ? "CRONUS" : "CRONUS LITE",304chipversion);305break;306}307case FAMILY_4600VZA:308platform_features = FFS_CAPABLE | DISPLAY_CAPABLE;309asic = ASIC_CRONUS;310set_register_map(CRONUS_IO_BASE, &cronus_register_map);311gp_resources = non_dvr_cronus_resources;312313pr_info("Platform: Vz Class A - CRONUS, NON_DVR_CAPABLE\n");314break;315316case FAMILY_8500:317case FAMILY_8500RNG:318platform_features = DVR_CAPABLE | PCIE_CAPABLE |319DISPLAY_CAPABLE;320asic = ASIC_ZEUS;321set_register_map(ZEUS_IO_BASE, &zeus_register_map);322gp_resources = dvr_zeus_resources;323324pr_info("Platform: 8500/RNG200 - ZEUS, DVR_CAPABLE\n");325break;326327case FAMILY_8600:328case FAMILY_8600VZB:329platform_features = DVR_CAPABLE | PCIE_CAPABLE |330DISPLAY_CAPABLE;331asic = ASIC_CRONUS;332set_register_map(CRONUS_IO_BASE, &cronus_register_map);333gp_resources = dvr_cronus_resources;334335pr_info("Platform: 8600/Vz Class B - CRONUS, "336"DVR_CAPABLE\n");337break;338339case FAMILY_8700:340platform_features = FFS_CAPABLE | PCIE_CAPABLE;341asic = ASIC_GAIA;342set_register_map(GAIA_IO_BASE, &gaia_register_map);343gp_resources = dvr_gaia_resources;344345pr_info("Platform: 8700 - GAIA, DVR_CAPABLE\n");346break;347348default:349pr_crit("Platform: UNKNOWN PLATFORM\n");350break;351}352353switch (asic) {354case ASIC_ZEUS:355phys_to_dma_offset = 0x30000000;356break;357case ASIC_CALLIOPE:358phys_to_dma_offset = 0x10000000;359break;360case ASIC_CRONUSLITE:361/* Fall through */362case ASIC_CRONUS:363/*364* TODO: We suppose 0x10000000 aliases into 0x20000000-365* 0x2XXXXXXX. If 0x10000000 aliases into 0x60000000-366* 0x6XXXXXXX, the offset should be 0x50000000, not 0x10000000.367*/368phys_to_dma_offset = 0x10000000;369break;370default:371phys_to_dma_offset = 0x00000000;372break;373}374}375376/*377* RESOURCE ALLOCATION378*379*/380/*381* Allocates/reserves the Platform memory resources early in the boot process.382* This ignores any resources that are designated IORESOURCE_IO383*/384void __init platform_alloc_bootmem(void)385{386int i;387int total = 0;388389/* Get persistent memory data from command line before allocating390* resources. This need to happen before normal command line parsing391* has been done */392pmem_setup_resource();393394/* Loop through looking for resources that want a particular address */395for (i = 0; gp_resources[i].flags != 0; i++) {396int size = gp_resources[i].end - gp_resources[i].start + 1;397if ((gp_resources[i].start != 0) &&398((gp_resources[i].flags & IORESOURCE_MEM) != 0)) {399reserve_bootmem(dma_to_phys(gp_resources[i].start),400size, 0);401total += gp_resources[i].end -402gp_resources[i].start + 1;403pr_info("reserve resource %s at %08x (%u bytes)\n",404gp_resources[i].name, gp_resources[i].start,405gp_resources[i].end -406gp_resources[i].start + 1);407}408}409410/* Loop through assigning addresses for those that are left */411for (i = 0; gp_resources[i].flags != 0; i++) {412int size = gp_resources[i].end - gp_resources[i].start + 1;413if ((gp_resources[i].start == 0) &&414((gp_resources[i].flags & IORESOURCE_MEM) != 0)) {415void *mem = alloc_bootmem_pages(size);416417if (mem == NULL)418pr_err("Unable to allocate bootmem pages "419"for %s\n", gp_resources[i].name);420421else {422gp_resources[i].start =423phys_to_dma(virt_to_phys(mem));424gp_resources[i].end =425gp_resources[i].start + size - 1;426total += size;427pr_info("allocate resource %s at %08x "428"(%u bytes)\n",429gp_resources[i].name,430gp_resources[i].start, size);431}432}433}434435pr_info("Total Platform driver memory allocation: 0x%08x\n", total);436437/* indicate resources that are platform I/O related */438for (i = 0; gp_resources[i].flags != 0; i++) {439if ((gp_resources[i].start != 0) &&440((gp_resources[i].flags & IORESOURCE_IO) != 0)) {441pr_info("reserved platform resource %s at %08x\n",442gp_resources[i].name, gp_resources[i].start);443}444}445}446447/*448*449* PERSISTENT MEMORY (PMEM) CONFIGURATION450*451*/452static unsigned long pmemaddr __initdata;453454static int __init early_param_pmemaddr(char *p)455{456pmemaddr = (unsigned long)simple_strtoul(p, NULL, 0);457return 0;458}459early_param("pmemaddr", early_param_pmemaddr);460461static long pmemlen __initdata;462463static int __init early_param_pmemlen(char *p)464{465/* TODO: we can use this code when and if the bootloader ever changes this */466#if 0467pmemlen = (unsigned long)simple_strtoul(p, NULL, 0);468#else469pmemlen = 0x20000;470#endif471return 0;472}473early_param("pmemlen", early_param_pmemlen);474475/*476* Set up persistent memory. If we were given values, we patch the array of477* resources. Otherwise, persistent memory may be allocated anywhere at all.478*/479static void __init pmem_setup_resource(void)480{481struct resource *resource;482resource = asic_resource_get("DiagPersistentMemory");483484if (resource && pmemaddr && pmemlen) {485/* The address provided by bootloader is in kseg0. Convert to486* a bus address. */487resource->start = phys_to_dma(pmemaddr - 0x80000000);488resource->end = resource->start + pmemlen - 1;489490pr_info("persistent memory: start=0x%x end=0x%x\n",491resource->start, resource->end);492}493}494495/*496*497* RESOURCE ACCESS FUNCTIONS498*499*/500501/**502* asic_resource_get - retrieves parameters for a platform resource.503* @name: string to match resource504*505* Returns a pointer to a struct resource corresponding to the given name.506*507* CANNOT BE NAMED platform_resource_get, which would be the obvious choice,508* as this function name is already declared509*/510struct resource *asic_resource_get(const char *name)511{512int i;513514for (i = 0; gp_resources[i].flags != 0; i++) {515if (strcmp(gp_resources[i].name, name) == 0)516return &gp_resources[i];517}518519return NULL;520}521EXPORT_SYMBOL(asic_resource_get);522523/**524* platform_release_memory - release pre-allocated memory525* @ptr: pointer to memory to release526* @size: size of resource527*528* This must only be called for memory allocated or reserved via the boot529* memory allocator.530*/531void platform_release_memory(void *ptr, int size)532{533unsigned long addr;534unsigned long end;535536addr = ((unsigned long)ptr + (PAGE_SIZE - 1)) & PAGE_MASK;537end = ((unsigned long)ptr + size) & PAGE_MASK;538539for (; addr < end; addr += PAGE_SIZE) {540ClearPageReserved(virt_to_page(__va(addr)));541init_page_count(virt_to_page(__va(addr)));542free_page((unsigned long)__va(addr));543}544}545EXPORT_SYMBOL(platform_release_memory);546547/*548*549* FEATURE AVAILABILITY FUNCTIONS550*551*/552int platform_supports_dvr(void)553{554return (platform_features & DVR_CAPABLE) != 0;555}556557int platform_supports_ffs(void)558{559return (platform_features & FFS_CAPABLE) != 0;560}561562int platform_supports_pcie(void)563{564return (platform_features & PCIE_CAPABLE) != 0;565}566567int platform_supports_display(void)568{569return (platform_features & DISPLAY_CAPABLE) != 0;570}571572573