sram.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * SDK7786 FPGA SRAM Support.
  4. *
  5. * Copyright (C) 2010 Paul Mundt
  6. */
  7. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  8. #include <linux/init.h>
  9. #include <linux/kernel.h>
  10. #include <linux/types.h>
  11. #include <linux/io.h>
  12. #include <linux/string.h>
  13. #include <mach/fpga.h>
  14. #include <asm/sram.h>
  15. #include <linux/sizes.h>
  16. static int __init fpga_sram_init(void)
  17. {
  18. unsigned long phys;
  19. unsigned int area;
  20. void __iomem *vaddr;
  21. int ret;
  22. u16 data;
  23. /* Enable FPGA SRAM */
  24. data = fpga_read_reg(LCLASR);
  25. data |= LCLASR_FRAMEN;
  26. fpga_write_reg(data, LCLASR);
  27. /*
  28. * FPGA_SEL determines the area mapping
  29. */
  30. area = (data & LCLASR_FPGA_SEL_MASK) >> LCLASR_FPGA_SEL_SHIFT;
  31. if (unlikely(area == LCLASR_AREA_MASK)) {
  32. pr_err("FPGA memory unmapped.\n");
  33. return -ENXIO;
  34. }
  35. /*
  36. * The memory itself occupies a 2KiB range at the top of the area
  37. * immediately below the system registers.
  38. */
  39. phys = (area << 26) + SZ_64M - SZ_4K;
  40. /*
  41. * The FPGA SRAM resides in translatable physical space, so set
  42. * up a mapping prior to inserting it in to the pool.
  43. */
  44. vaddr = ioremap(phys, SZ_2K);
  45. if (unlikely(!vaddr)) {
  46. pr_err("Failed remapping FPGA memory.\n");
  47. return -ENXIO;
  48. }
  49. pr_info("Adding %dKiB of FPGA memory at 0x%08lx-0x%08lx "
  50. "(area %d) to pool.\n",
  51. SZ_2K >> 10, phys, phys + SZ_2K - 1, area);
  52. ret = gen_pool_add(sram_pool, (unsigned long)vaddr, SZ_2K, -1);
  53. if (unlikely(ret < 0)) {
  54. pr_err("Failed adding memory\n");
  55. iounmap(vaddr);
  56. return ret;
  57. }
  58. return 0;
  59. }
  60. postcore_initcall(fpga_sram_init);