mmdc.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright 2011 Freescale Semiconductor, Inc.
  3. * Copyright 2011 Linaro Ltd.
  4. *
  5. * The code contained herein is licensed under the GNU General Public
  6. * License. You may obtain a copy of the GNU General Public License
  7. * Version 2 or later at the following locations:
  8. *
  9. * http://www.opensource.org/licenses/gpl-license.html
  10. * http://www.gnu.org/copyleft/gpl.html
  11. */
  12. #include <linux/init.h>
  13. #include <linux/io.h>
  14. #include <linux/module.h>
  15. #include <linux/of.h>
  16. #include <linux/of_address.h>
  17. #include <linux/of_device.h>
  18. #define MMDC_MAPSR 0x404
  19. #define BP_MMDC_MAPSR_PSD 0
  20. #define BP_MMDC_MAPSR_PSS 4
  21. #define MMDC_MDMISC 0x18
  22. #define BM_MMDC_MDMISC_DDR_TYPE 0x18
  23. #define BP_MMDC_MDMISC_DDR_TYPE 0x3
  24. static int ddr_type;
  25. static int imx_mmdc_probe(struct platform_device *pdev)
  26. {
  27. struct device_node *np = pdev->dev.of_node;
  28. void __iomem *mmdc_base, *reg;
  29. u32 val;
  30. int timeout = 0x400;
  31. mmdc_base = of_iomap(np, 0);
  32. WARN_ON(!mmdc_base);
  33. reg = mmdc_base + MMDC_MDMISC;
  34. /* Get ddr type */
  35. val = readl_relaxed(reg);
  36. ddr_type = (val & BM_MMDC_MDMISC_DDR_TYPE) >>
  37. BP_MMDC_MDMISC_DDR_TYPE;
  38. reg = mmdc_base + MMDC_MAPSR;
  39. /* Enable automatic power saving */
  40. val = readl_relaxed(reg);
  41. val &= ~(1 << BP_MMDC_MAPSR_PSD);
  42. writel_relaxed(val, reg);
  43. /* Ensure it's successfully enabled */
  44. while (!(readl_relaxed(reg) & 1 << BP_MMDC_MAPSR_PSS) && --timeout)
  45. cpu_relax();
  46. if (unlikely(!timeout)) {
  47. pr_warn("%s: failed to enable automatic power saving\n",
  48. __func__);
  49. return -EBUSY;
  50. }
  51. return 0;
  52. }
  53. int imx_mmdc_get_ddr_type(void)
  54. {
  55. return ddr_type;
  56. }
  57. static const struct of_device_id imx_mmdc_dt_ids[] = {
  58. { .compatible = "fsl,imx6q-mmdc", },
  59. { /* sentinel */ }
  60. };
  61. static struct platform_driver imx_mmdc_driver = {
  62. .driver = {
  63. .name = "imx-mmdc",
  64. .of_match_table = imx_mmdc_dt_ids,
  65. },
  66. .probe = imx_mmdc_probe,
  67. };
  68. static int __init imx_mmdc_init(void)
  69. {
  70. return platform_driver_register(&imx_mmdc_driver);
  71. }
  72. postcore_initcall(imx_mmdc_init);