fpga.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * SDK7786 FPGA Support.
  3. *
  4. * Copyright (C) 2010 Paul Mundt
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/io.h>
  12. #include <linux/bcd.h>
  13. #include <mach/fpga.h>
  14. #include <asm/sizes.h>
  15. #define FPGA_REGS_OFFSET 0x03fff800
  16. #define FPGA_REGS_SIZE 0x490
  17. /*
  18. * The FPGA can be mapped in any of the generally available areas,
  19. * so we attempt to scan for it using the fixed SRSTR read magic.
  20. *
  21. * Once the FPGA is located, the rest of the mapping data for the other
  22. * components can be determined dynamically from its section mapping
  23. * registers.
  24. */
  25. static void __iomem *sdk7786_fpga_probe(void)
  26. {
  27. unsigned long area;
  28. void __iomem *base;
  29. /*
  30. * Iterate over all of the areas where the FPGA could be mapped.
  31. * The possible range is anywhere from area 0 through 6, area 7
  32. * is reserved.
  33. */
  34. for (area = PA_AREA0; area < PA_AREA7; area += SZ_64M) {
  35. base = ioremap_nocache(area + FPGA_REGS_OFFSET, FPGA_REGS_SIZE);
  36. if (!base) {
  37. /* Failed to remap this area, move along. */
  38. continue;
  39. }
  40. if (ioread16(base + SRSTR) == SRSTR_MAGIC)
  41. return base; /* Found it! */
  42. iounmap(base);
  43. }
  44. return NULL;
  45. }
  46. void __iomem *sdk7786_fpga_base;
  47. void __init sdk7786_fpga_init(void)
  48. {
  49. u16 version, date;
  50. sdk7786_fpga_base = sdk7786_fpga_probe();
  51. if (unlikely(!sdk7786_fpga_base)) {
  52. panic("FPGA detection failed.\n");
  53. return;
  54. }
  55. version = fpga_read_reg(FPGAVR);
  56. date = fpga_read_reg(FPGADR);
  57. pr_info("\tFPGA version:\t%d.%d (built on %d/%d/%d)\n",
  58. bcd2bin(version >> 8) & 0xf, bcd2bin(version & 0xf),
  59. ((date >> 12) & 0xf) + 2000,
  60. (date >> 8) & 0xf, bcd2bin(date & 0xff));
  61. }