Path: blob/master/arch/sh/boards/mach-sdk7786/fpga.c
15126 views
/*1* SDK7786 FPGA Support.2*3* Copyright (C) 2010 Paul Mundt4*5* This file is subject to the terms and conditions of the GNU General Public6* License. See the file "COPYING" in the main directory of this archive7* for more details.8*/9#include <linux/init.h>10#include <linux/io.h>11#include <linux/bcd.h>12#include <mach/fpga.h>13#include <asm/sizes.h>1415#define FPGA_REGS_OFFSET 0x03fff80016#define FPGA_REGS_SIZE 0x4901718/*19* The FPGA can be mapped in any of the generally available areas,20* so we attempt to scan for it using the fixed SRSTR read magic.21*22* Once the FPGA is located, the rest of the mapping data for the other23* components can be determined dynamically from its section mapping24* registers.25*/26static void __iomem *sdk7786_fpga_probe(void)27{28unsigned long area;29void __iomem *base;3031/*32* Iterate over all of the areas where the FPGA could be mapped.33* The possible range is anywhere from area 0 through 6, area 734* is reserved.35*/36for (area = PA_AREA0; area < PA_AREA7; area += SZ_64M) {37base = ioremap_nocache(area + FPGA_REGS_OFFSET, FPGA_REGS_SIZE);38if (!base) {39/* Failed to remap this area, move along. */40continue;41}4243if (ioread16(base + SRSTR) == SRSTR_MAGIC)44return base; /* Found it! */4546iounmap(base);47}4849return NULL;50}5152void __iomem *sdk7786_fpga_base;5354void __init sdk7786_fpga_init(void)55{56u16 version, date;5758sdk7786_fpga_base = sdk7786_fpga_probe();59if (unlikely(!sdk7786_fpga_base)) {60panic("FPGA detection failed.\n");61return;62}6364version = fpga_read_reg(FPGAVR);65date = fpga_read_reg(FPGADR);6667pr_info("\tFPGA version:\t%d.%d (built on %d/%d/%d)\n",68bcd2bin(version >> 8) & 0xf, bcd2bin(version & 0xf),69((date >> 12) & 0xf) + 2000,70(date >> 8) & 0xf, bcd2bin(date & 0xff));71}727374