fpga.c 1.6 KB

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