blob: db9621c718ecae1ff2567f596f4d71ecd6428c4a [file] [log] [blame]
Shawn Guo9fbbe682011-09-06 14:39:44 +08001/*
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
13#include <linux/init.h>
14#include <linux/io.h>
15#include <linux/module.h>
16#include <linux/of.h>
17#include <linux/of_address.h>
18#include <linux/of_device.h>
19
Fabio Estevam666c8842015-04-02 19:23:32 -030020#include "common.h"
21
Shawn Guo9fbbe682011-09-06 14:39:44 +080022#define MMDC_MAPSR 0x404
23#define BP_MMDC_MAPSR_PSD 0
24#define BP_MMDC_MAPSR_PSS 4
25
Anson Huangec336b22014-09-17 11:11:45 +080026#define MMDC_MDMISC 0x18
27#define BM_MMDC_MDMISC_DDR_TYPE 0x18
28#define BP_MMDC_MDMISC_DDR_TYPE 0x3
29
30static int ddr_type;
31
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -080032static int imx_mmdc_probe(struct platform_device *pdev)
Shawn Guo9fbbe682011-09-06 14:39:44 +080033{
34 struct device_node *np = pdev->dev.of_node;
35 void __iomem *mmdc_base, *reg;
36 u32 val;
37 int timeout = 0x400;
38
39 mmdc_base = of_iomap(np, 0);
40 WARN_ON(!mmdc_base);
41
Anson Huangec336b22014-09-17 11:11:45 +080042 reg = mmdc_base + MMDC_MDMISC;
43 /* Get ddr type */
44 val = readl_relaxed(reg);
45 ddr_type = (val & BM_MMDC_MDMISC_DDR_TYPE) >>
46 BP_MMDC_MDMISC_DDR_TYPE;
47
Shawn Guo9fbbe682011-09-06 14:39:44 +080048 reg = mmdc_base + MMDC_MAPSR;
49
50 /* Enable automatic power saving */
51 val = readl_relaxed(reg);
52 val &= ~(1 << BP_MMDC_MAPSR_PSD);
53 writel_relaxed(val, reg);
54
55 /* Ensure it's successfully enabled */
56 while (!(readl_relaxed(reg) & 1 << BP_MMDC_MAPSR_PSS) && --timeout)
57 cpu_relax();
58
59 if (unlikely(!timeout)) {
60 pr_warn("%s: failed to enable automatic power saving\n",
61 __func__);
62 return -EBUSY;
63 }
64
65 return 0;
66}
67
Anson Huangec336b22014-09-17 11:11:45 +080068int imx_mmdc_get_ddr_type(void)
69{
70 return ddr_type;
71}
72
Uwe Kleine-König444d2d32015-02-18 21:19:56 +010073static const struct of_device_id imx_mmdc_dt_ids[] = {
Shawn Guo9fbbe682011-09-06 14:39:44 +080074 { .compatible = "fsl,imx6q-mmdc", },
75 { /* sentinel */ }
76};
77
78static struct platform_driver imx_mmdc_driver = {
79 .driver = {
80 .name = "imx-mmdc",
Shawn Guo9fbbe682011-09-06 14:39:44 +080081 .of_match_table = imx_mmdc_dt_ids,
82 },
83 .probe = imx_mmdc_probe,
84};
85
86static int __init imx_mmdc_init(void)
87{
88 return platform_driver_register(&imx_mmdc_driver);
89}
90postcore_initcall(imx_mmdc_init);