mmdc_size.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // SPDX-License-Identifier: GPL-2.0+
  2. #include <common.h>
  3. #include <asm/io.h>
  4. #if defined(CONFIG_MX53)
  5. #define MEMCTL_BASE ESDCTL_BASE_ADDR
  6. #elif defined(CONFIG_MX6)
  7. #define MEMCTL_BASE MMDC_P0_BASE_ADDR
  8. #elif defined(CONFIG_MX7ULP)
  9. #define MEMCTL_BASE MMDC0_RBASE
  10. #endif
  11. static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9};
  12. static const unsigned char bank_lookup[] = {3, 2};
  13. /* these MMDC registers are common to the IMX53 and IMX6 */
  14. struct esd_mmdc_regs {
  15. u32 ctl;
  16. u32 pdc;
  17. u32 otc;
  18. u32 cfg0;
  19. u32 cfg1;
  20. u32 cfg2;
  21. u32 misc;
  22. };
  23. #define ESD_MMDC_CTL_GET_ROW(mdctl) ((ctl >> 24) & 7)
  24. #define ESD_MMDC_CTL_GET_COLUMN(mdctl) ((ctl >> 20) & 7)
  25. #define ESD_MMDC_CTL_GET_WIDTH(mdctl) ((ctl >> 16) & 3)
  26. #define ESD_MMDC_CTL_GET_CS1(mdctl) ((ctl >> 30) & 1)
  27. #define ESD_MMDC_MISC_GET_BANK(mdmisc) ((misc >> 5) & 1)
  28. /*
  29. * imx_ddr_size - return size in bytes of DRAM according MMDC config
  30. * The MMDC MDCTL register holds the number of bits for row, col, and data
  31. * width and the MMDC MDMISC register holds the number of banks. Combine
  32. * all these bits to determine the meme size the MMDC has been configured for
  33. */
  34. unsigned int imx_ddr_size(void)
  35. {
  36. struct esd_mmdc_regs *mem = (struct esd_mmdc_regs *)MEMCTL_BASE;
  37. unsigned int ctl = readl(&mem->ctl);
  38. unsigned int misc = readl(&mem->misc);
  39. int bits = 11 + 0 + 0 + 1; /* row + col + bank + width */
  40. bits += ESD_MMDC_CTL_GET_ROW(ctl);
  41. bits += col_lookup[ESD_MMDC_CTL_GET_COLUMN(ctl)];
  42. bits += bank_lookup[ESD_MMDC_MISC_GET_BANK(misc)];
  43. bits += ESD_MMDC_CTL_GET_WIDTH(ctl);
  44. bits += ESD_MMDC_CTL_GET_CS1(ctl);
  45. /* The MX6 can do only 3840 MiB of DRAM */
  46. if (bits == 32)
  47. return 0xf0000000;
  48. return 1 << bits;
  49. }