mmdc.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #include "common.h"
  19. #define MMDC_MAPSR 0x404
  20. #define BP_MMDC_MAPSR_PSD 0
  21. #define BP_MMDC_MAPSR_PSS 4
  22. #define MMDC_MDMISC 0x18
  23. #define BM_MMDC_MDMISC_DDR_TYPE 0x18
  24. #define BP_MMDC_MDMISC_DDR_TYPE 0x3
  25. static int ddr_type;
  26. static int imx_mmdc_probe(struct platform_device *pdev)
  27. {
  28. struct device_node *np = pdev->dev.of_node;
  29. void __iomem *mmdc_base, *reg;
  30. u32 val;
  31. int timeout = 0x400;
  32. mmdc_base = of_iomap(np, 0);
  33. WARN_ON(!mmdc_base);
  34. reg = mmdc_base + MMDC_MDMISC;
  35. /* Get ddr type */
  36. val = readl_relaxed(reg);
  37. ddr_type = (val & BM_MMDC_MDMISC_DDR_TYPE) >>
  38. BP_MMDC_MDMISC_DDR_TYPE;
  39. reg = mmdc_base + MMDC_MAPSR;
  40. /* Enable automatic power saving */
  41. val = readl_relaxed(reg);
  42. val &= ~(1 << BP_MMDC_MAPSR_PSD);
  43. writel_relaxed(val, reg);
  44. /* Ensure it's successfully enabled */
  45. while (!(readl_relaxed(reg) & 1 << BP_MMDC_MAPSR_PSS) && --timeout)
  46. cpu_relax();
  47. if (unlikely(!timeout)) {
  48. pr_warn("%s: failed to enable automatic power saving\n",
  49. __func__);
  50. return -EBUSY;
  51. }
  52. return 0;
  53. }
  54. int imx_mmdc_get_ddr_type(void)
  55. {
  56. return ddr_type;
  57. }
  58. static const struct of_device_id imx_mmdc_dt_ids[] = {
  59. { .compatible = "fsl,imx6q-mmdc", },
  60. { /* sentinel */ }
  61. };
  62. static struct platform_driver imx_mmdc_driver = {
  63. .driver = {
  64. .name = "imx-mmdc",
  65. .of_match_table = imx_mmdc_dt_ids,
  66. },
  67. .probe = imx_mmdc_probe,
  68. };
  69. static int __init imx_mmdc_init(void)
  70. {
  71. return platform_driver_register(&imx_mmdc_driver);
  72. }
  73. postcore_initcall(imx_mmdc_init);