sram.c 1.7 KB

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