Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 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 | |
| 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 | |
| 20 | #define MMDC_MAPSR 0x404 |
| 21 | #define BP_MMDC_MAPSR_PSD 0 |
| 22 | #define BP_MMDC_MAPSR_PSS 4 |
| 23 | |
| 24 | static int __devinit imx_mmdc_probe(struct platform_device *pdev) |
| 25 | { |
| 26 | struct device_node *np = pdev->dev.of_node; |
| 27 | void __iomem *mmdc_base, *reg; |
| 28 | u32 val; |
| 29 | int timeout = 0x400; |
| 30 | |
| 31 | mmdc_base = of_iomap(np, 0); |
| 32 | WARN_ON(!mmdc_base); |
| 33 | |
| 34 | reg = mmdc_base + MMDC_MAPSR; |
| 35 | |
| 36 | /* Enable automatic power saving */ |
| 37 | val = readl_relaxed(reg); |
| 38 | val &= ~(1 << BP_MMDC_MAPSR_PSD); |
| 39 | writel_relaxed(val, reg); |
| 40 | |
| 41 | /* Ensure it's successfully enabled */ |
| 42 | while (!(readl_relaxed(reg) & 1 << BP_MMDC_MAPSR_PSS) && --timeout) |
| 43 | cpu_relax(); |
| 44 | |
| 45 | if (unlikely(!timeout)) { |
| 46 | pr_warn("%s: failed to enable automatic power saving\n", |
| 47 | __func__); |
| 48 | return -EBUSY; |
| 49 | } |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static struct of_device_id imx_mmdc_dt_ids[] = { |
| 55 | { .compatible = "fsl,imx6q-mmdc", }, |
| 56 | { /* sentinel */ } |
| 57 | }; |
| 58 | |
| 59 | static struct platform_driver imx_mmdc_driver = { |
| 60 | .driver = { |
| 61 | .name = "imx-mmdc", |
| 62 | .owner = THIS_MODULE, |
| 63 | .of_match_table = imx_mmdc_dt_ids, |
| 64 | }, |
| 65 | .probe = imx_mmdc_probe, |
| 66 | }; |
| 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); |