2 * Copyright 2011 Freescale Semiconductor, Inc.
3 * Copyright 2011 Linaro Ltd.
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:
9 * http://www.opensource.org/licenses/gpl-license.html
10 * http://www.gnu.org/copyleft/gpl.html
13 #include <linux/init.h>
15 #include <linux/module.h>
17 #include <linux/of_address.h>
18 #include <linux/of_device.h>
22 #define MMDC_MAPSR 0x404
23 #define BP_MMDC_MAPSR_PSD 0
24 #define BP_MMDC_MAPSR_PSS 4
26 #define MMDC_MDMISC 0x18
27 #define BM_MMDC_MDMISC_DDR_TYPE 0x18
28 #define BP_MMDC_MDMISC_DDR_TYPE 0x3
32 static int imx_mmdc_probe(struct platform_device
*pdev
)
34 struct device_node
*np
= pdev
->dev
.of_node
;
35 void __iomem
*mmdc_base
, *reg
;
39 mmdc_base
= of_iomap(np
, 0);
42 reg
= mmdc_base
+ MMDC_MDMISC
;
44 val
= readl_relaxed(reg
);
45 ddr_type
= (val
& BM_MMDC_MDMISC_DDR_TYPE
) >>
46 BP_MMDC_MDMISC_DDR_TYPE
;
48 reg
= mmdc_base
+ MMDC_MAPSR
;
50 /* Enable automatic power saving */
51 val
= readl_relaxed(reg
);
52 val
&= ~(1 << BP_MMDC_MAPSR_PSD
);
53 writel_relaxed(val
, reg
);
55 /* Ensure it's successfully enabled */
56 while (!(readl_relaxed(reg
) & 1 << BP_MMDC_MAPSR_PSS
) && --timeout
)
59 if (unlikely(!timeout
)) {
60 pr_warn("%s: failed to enable automatic power saving\n",
68 int imx_mmdc_get_ddr_type(void)
73 static const struct of_device_id imx_mmdc_dt_ids
[] = {
74 { .compatible
= "fsl,imx6q-mmdc", },
78 static struct platform_driver imx_mmdc_driver
= {
81 .of_match_table
= imx_mmdc_dt_ids
,
83 .probe
= imx_mmdc_probe
,
86 static int __init
imx_mmdc_init(void)
88 return platform_driver_register(&imx_mmdc_driver
);
90 postcore_initcall(imx_mmdc_init
);