aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc
diff options
context:
space:
mode:
authorZhangfei Gao <zhangfei.gao@marvell.com>2010-09-20 10:51:28 -0400
committerChris Ball <cjb@laptop.org>2010-10-24 21:29:07 -0400
commit536ac998f6076a0ae423b1046b85d7690e8b7107 (patch)
tree865881c030dcf65ec5436c4eb0f928b040b1e570 /drivers/mmc
parent5e71b7a64cb4c6cff75ca42b535d8227526ec592 (diff)
mmc: add new sdhci-pxa driver for Marvell SoCs
Support Marvell PXA168/PXA910/MMP2 SD Host Controller. Signed-off-by: Zhangfei Gao <zhangfei.gao@marvell.com> Acked-by: Haojian Zhuang <haojian.zhuang@marvell.com> Signed-off-by: Chris Ball <cjb@laptop.org>
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/host/Kconfig12
-rw-r--r--drivers/mmc/host/Makefile1
-rw-r--r--drivers/mmc/host/sdhci-pxa.c253
3 files changed, 266 insertions, 0 deletions
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index c9c2520a0c4a..40b0fb9a47fb 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -155,6 +155,18 @@ config MMC_SDHCI_S3C
155 155
156 If unsure, say N. 156 If unsure, say N.
157 157
158config MMC_SDHCI_PXA
159 tristate "Marvell PXA168/PXA910/MMP2 SD Host Controller support"
160 depends on ARCH_PXA || ARCH_MMP
161 select MMC_SDHCI
162 select MMC_SDHCI_IO_ACCESSORS
163 help
164 This selects the Marvell(R) PXA168/PXA910/MMP2 SD Host Controller.
165 If you have a PXA168/PXA910/MMP2 platform with SD Host Controller
166 and a card slot, say Y or M here.
167
168 If unsure, say N.
169
158config MMC_SDHCI_SPEAR 170config MMC_SDHCI_SPEAR
159 tristate "SDHCI support on ST SPEAr platform" 171 tristate "SDHCI support on ST SPEAr platform"
160 depends on MMC_SDHCI && PLAT_SPEAR 172 depends on MMC_SDHCI && PLAT_SPEAR
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index 6c4ac67f739f..7b645ff43b30 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_MMC_IMX) += imxmmc.o
8obj-$(CONFIG_MMC_MXC) += mxcmmc.o 8obj-$(CONFIG_MMC_MXC) += mxcmmc.o
9obj-$(CONFIG_MMC_SDHCI) += sdhci.o 9obj-$(CONFIG_MMC_SDHCI) += sdhci.o
10obj-$(CONFIG_MMC_SDHCI_PCI) += sdhci-pci.o 10obj-$(CONFIG_MMC_SDHCI_PCI) += sdhci-pci.o
11obj-$(CONFIG_MMC_SDHCI_PXA) += sdhci-pxa.o
11obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o 12obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
12obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o 13obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
13obj-$(CONFIG_MMC_WBSD) += wbsd.o 14obj-$(CONFIG_MMC_WBSD) += wbsd.o
diff --git a/drivers/mmc/host/sdhci-pxa.c b/drivers/mmc/host/sdhci-pxa.c
new file mode 100644
index 000000000000..fc406ac5d193
--- /dev/null
+++ b/drivers/mmc/host/sdhci-pxa.c
@@ -0,0 +1,253 @@
1/* linux/drivers/mmc/host/sdhci-pxa.c
2 *
3 * Copyright (C) 2010 Marvell International Ltd.
4 * Zhangfei Gao <zhangfei.gao@marvell.com>
5 * Kevin Wang <dwang4@marvell.com>
6 * Mingwei Wang <mwwang@marvell.com>
7 * Philip Rakity <prakity@marvell.com>
8 * Mark Brown <markb@marvell.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15/* Supports:
16 * SDHCI support for MMP2/PXA910/PXA168
17 *
18 * Refer to sdhci-s3c.c.
19 */
20
21#include <linux/delay.h>
22#include <linux/platform_device.h>
23#include <linux/mmc/host.h>
24#include <linux/clk.h>
25#include <linux/io.h>
26#include <linux/err.h>
27#include <plat/sdhci.h>
28#include "sdhci.h"
29
30#define DRIVER_NAME "sdhci-pxa"
31
32#define SD_FIFO_PARAM 0x104
33#define DIS_PAD_SD_CLK_GATE 0x400
34
35struct sdhci_pxa {
36 struct sdhci_host *host;
37 struct sdhci_pxa_platdata *pdata;
38 struct clk *clk;
39 struct resource *res;
40
41 u8 clk_enable;
42};
43
44/*****************************************************************************\
45 * *
46 * SDHCI core callbacks *
47 * *
48\*****************************************************************************/
49static void set_clock(struct sdhci_host *host, unsigned int clock)
50{
51 struct sdhci_pxa *pxa = sdhci_priv(host);
52 u32 tmp = 0;
53
54 if (clock == 0) {
55 if (pxa->clk_enable) {
56 clk_disable(pxa->clk);
57 pxa->clk_enable = 0;
58 }
59 } else {
60 if (0 == pxa->clk_enable) {
61 if (pxa->pdata->flags & PXA_FLAG_DISABLE_CLOCK_GATING) {
62 tmp = readl(host->ioaddr + SD_FIFO_PARAM);
63 tmp |= DIS_PAD_SD_CLK_GATE;
64 writel(tmp, host->ioaddr + SD_FIFO_PARAM);
65 }
66 clk_enable(pxa->clk);
67 pxa->clk_enable = 1;
68 }
69 }
70}
71
72static struct sdhci_ops sdhci_pxa_ops = {
73 .set_clock = set_clock,
74};
75
76/*****************************************************************************\
77 * *
78 * Device probing/removal *
79 * *
80\*****************************************************************************/
81
82static int __devinit sdhci_pxa_probe(struct platform_device *pdev)
83{
84 struct sdhci_pxa_platdata *pdata = pdev->dev.platform_data;
85 struct device *dev = &pdev->dev;
86 struct sdhci_host *host = NULL;
87 struct resource *iomem = NULL;
88 struct sdhci_pxa *pxa = NULL;
89 int ret, irq;
90
91 irq = platform_get_irq(pdev, 0);
92 if (irq < 0) {
93 dev_err(dev, "no irq specified\n");
94 return irq;
95 }
96
97 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
98 if (!iomem) {
99 dev_err(dev, "no memory specified\n");
100 return -ENOENT;
101 }
102
103 host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pxa));
104 if (IS_ERR(host)) {
105 dev_err(dev, "failed to alloc host\n");
106 return PTR_ERR(host);
107 }
108
109 pxa = sdhci_priv(host);
110 pxa->host = host;
111 pxa->pdata = pdata;
112 pxa->clk_enable = 0;
113
114 pxa->clk = clk_get(dev, "PXA-SDHCLK");
115 if (IS_ERR(pxa->clk)) {
116 dev_err(dev, "failed to get io clock\n");
117 ret = PTR_ERR(pxa->clk);
118 goto out;
119 }
120
121 pxa->res = request_mem_region(iomem->start, resource_size(iomem),
122 mmc_hostname(host->mmc));
123 if (!pxa->res) {
124 dev_err(&pdev->dev, "cannot request region\n");
125 ret = -EBUSY;
126 goto out;
127 }
128
129 host->ioaddr = ioremap(iomem->start, resource_size(iomem));
130 if (!host->ioaddr) {
131 dev_err(&pdev->dev, "failed to remap registers\n");
132 ret = -ENOMEM;
133 goto out;
134 }
135
136 host->hw_name = "MMC";
137 host->ops = &sdhci_pxa_ops;
138 host->irq = irq;
139 host->quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
140
141 if (pdata->quirks)
142 host->quirks |= pdata->quirks;
143
144 ret = sdhci_add_host(host);
145 if (ret) {
146 dev_err(&pdev->dev, "failed to add host\n");
147 goto out;
148 }
149
150 if (pxa->pdata->max_speed)
151 host->mmc->f_max = pxa->pdata->max_speed;
152
153 platform_set_drvdata(pdev, host);
154
155 return 0;
156out:
157 if (host) {
158 clk_put(pxa->clk);
159 if (host->ioaddr)
160 iounmap(host->ioaddr);
161 if (pxa->res)
162 release_mem_region(pxa->res->start,
163 resource_size(pxa->res));
164 sdhci_free_host(host);
165 }
166
167 return ret;
168}
169
170static int __devexit sdhci_pxa_remove(struct platform_device *pdev)
171{
172 struct sdhci_host *host = platform_get_drvdata(pdev);
173 struct sdhci_pxa *pxa = sdhci_priv(host);
174 int dead = 0;
175 u32 scratch;
176
177 if (host) {
178 scratch = readl(host->ioaddr + SDHCI_INT_STATUS);
179 if (scratch == (u32)-1)
180 dead = 1;
181
182 sdhci_remove_host(host, dead);
183
184 if (host->ioaddr)
185 iounmap(host->ioaddr);
186 if (pxa->res)
187 release_mem_region(pxa->res->start,
188 resource_size(pxa->res));
189 if (pxa->clk_enable) {
190 clk_disable(pxa->clk);
191 pxa->clk_enable = 0;
192 }
193 clk_put(pxa->clk);
194
195 sdhci_free_host(host);
196 platform_set_drvdata(pdev, NULL);
197 }
198
199 return 0;
200}
201
202#ifdef CONFIG_PM
203static int sdhci_pxa_suspend(struct platform_device *dev, pm_message_t state)
204{
205 struct sdhci_host *host = platform_get_drvdata(dev);
206
207 return sdhci_suspend_host(host, state);
208}
209
210static int sdhci_pxa_resume(struct platform_device *dev)
211{
212 struct sdhci_host *host = platform_get_drvdata(dev);
213
214 return sdhci_resume_host(host);
215}
216#else
217#define sdhci_pxa_suspend NULL
218#define sdhci_pxa_resume NULL
219#endif
220
221static struct platform_driver sdhci_pxa_driver = {
222 .probe = sdhci_pxa_probe,
223 .remove = __devexit_p(sdhci_pxa_remove),
224 .suspend = sdhci_pxa_suspend,
225 .resume = sdhci_pxa_resume,
226 .driver = {
227 .name = DRIVER_NAME,
228 .owner = THIS_MODULE,
229 },
230};
231
232/*****************************************************************************\
233 * *
234 * Driver init/exit *
235 * *
236\*****************************************************************************/
237
238static int __init sdhci_pxa_init(void)
239{
240 return platform_driver_register(&sdhci_pxa_driver);
241}
242
243static void __exit sdhci_pxa_exit(void)
244{
245 platform_driver_unregister(&sdhci_pxa_driver);
246}
247
248module_init(sdhci_pxa_init);
249module_exit(sdhci_pxa_exit);
250
251MODULE_DESCRIPTION("SDH controller driver for PXA168/PXA910/MMP2");
252MODULE_AUTHOR("Zhangfei Gao <zhangfei.gao@marvell.com>");
253MODULE_LICENSE("GPL v2");