aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/mmc/brcm,bcm2835-sdhci.txt18
-rw-r--r--drivers/mmc/host/Kconfig11
-rw-r--r--drivers/mmc/host/Makefile1
-rw-r--r--drivers/mmc/host/sdhci-bcm2835.c227
4 files changed, 257 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/mmc/brcm,bcm2835-sdhci.txt b/Documentation/devicetree/bindings/mmc/brcm,bcm2835-sdhci.txt
new file mode 100644
index 000000000000..59476fbdbfa1
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/brcm,bcm2835-sdhci.txt
@@ -0,0 +1,18 @@
1Broadcom BCM2835 SDHCI controller
2
3This file documents differences between the core properties described
4by mmc.txt and the properties that represent the BCM2835 controller.
5
6Required properties:
7- compatible : Should be "brcm,bcm2835-sdhci".
8- clocks : The clock feeding the SDHCI controller.
9
10Example:
11
12sdhci: sdhci {
13 compatible = "brcm,bcm2835-sdhci";
14 reg = <0x7e300000 0x100>;
15 interrupts = <2 30>;
16 clocks = <&clk_mmc>;
17 bus-width = <4>;
18};
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 8d13c6594520..66a54aa68e25 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -241,6 +241,17 @@ config MMC_SDHCI_S3C_DMA
241 241
242 YMMV. 242 YMMV.
243 243
244config MMC_SDHCI_BCM2835
245 tristate "SDHCI platform support for the BCM2835 SD/MMC Controller"
246 depends on ARCH_BCM2835
247 depends on MMC_SDHCI_PLTFM
248 select MMC_SDHCI_IO_ACCESSORS
249 help
250 This selects the BCM2835 SD/MMC controller. If you have a BCM2835
251 platform with SD or MMC devices, say Y or M here.
252
253 If unsure, say N.
254
244config MMC_OMAP 255config MMC_OMAP
245 tristate "TI OMAP Multimedia Card Interface support" 256 tristate "TI OMAP Multimedia Card Interface support"
246 depends on ARCH_OMAP 257 depends on ARCH_OMAP
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index e4e218c930bd..d5ea072207ec 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -58,6 +58,7 @@ obj-$(CONFIG_MMC_SDHCI_DOVE) += sdhci-dove.o
58obj-$(CONFIG_MMC_SDHCI_TEGRA) += sdhci-tegra.o 58obj-$(CONFIG_MMC_SDHCI_TEGRA) += sdhci-tegra.o
59obj-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o 59obj-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o
60obj-$(CONFIG_MMC_SDHCI_OF_HLWD) += sdhci-of-hlwd.o 60obj-$(CONFIG_MMC_SDHCI_OF_HLWD) += sdhci-of-hlwd.o
61obj-$(CONFIG_MMC_SDHCI_BCM2835) += sdhci-bcm2835.o
61 62
62ifeq ($(CONFIG_CB710_DEBUG),y) 63ifeq ($(CONFIG_CB710_DEBUG),y)
63 CFLAGS-cb710-mmc += -DDEBUG 64 CFLAGS-cb710-mmc += -DDEBUG
diff --git a/drivers/mmc/host/sdhci-bcm2835.c b/drivers/mmc/host/sdhci-bcm2835.c
new file mode 100644
index 000000000000..453825fcc5cf
--- /dev/null
+++ b/drivers/mmc/host/sdhci-bcm2835.c
@@ -0,0 +1,227 @@
1/*
2 * BCM2835 SDHCI
3 * Copyright (C) 2012 Stephen Warren
4 * Based on U-Boot's MMC driver for the BCM2835 by Oleksandr Tymoshenko & me
5 * Portions of the code there were obviously based on the Linux kernel at:
6 * git://github.com/raspberrypi/linux.git rpi-3.6.y
7 * commit f5b930b "Main bcm2708 linux port" signed-off-by Dom Cobley.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms and conditions of the GNU General Public License,
11 * version 2, as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include <linux/delay.h>
23#include <linux/module.h>
24#include <linux/mmc/host.h>
25#include "sdhci-pltfm.h"
26
27/*
28 * 400KHz is max freq for card ID etc. Use that as min card clock. We need to
29 * know the min to enable static calculation of max BCM2835_SDHCI_WRITE_DELAY.
30 */
31#define MIN_FREQ 400000
32
33/*
34 * The Arasan has a bugette whereby it may lose the content of successive
35 * writes to registers that are within two SD-card clock cycles of each other
36 * (a clock domain crossing problem). It seems, however, that the data
37 * register does not have this problem, which is just as well - otherwise we'd
38 * have to nobble the DMA engine too.
39 *
40 * This should probably be dynamically calculated based on the actual card
41 * frequency. However, this is the longest we'll have to wait, and doesn't
42 * seem to slow access down too much, so the added complexity doesn't seem
43 * worth it for now.
44 *
45 * 1/MIN_FREQ is (max) time per tick of eMMC clock.
46 * 2/MIN_FREQ is time for two ticks.
47 * Multiply by 1000000 to get uS per two ticks.
48 * *1000000 for uSecs.
49 * +1 for hack rounding.
50 */
51#define BCM2835_SDHCI_WRITE_DELAY (((2 * 1000000) / MIN_FREQ) + 1)
52
53struct bcm2835_sdhci {
54 struct clk *clk;
55 u32 shadow;
56};
57
58static void bcm2835_sdhci_writel(struct sdhci_host *host, u32 val, int reg)
59{
60 writel(val, host->ioaddr + reg);
61
62 udelay(BCM2835_SDHCI_WRITE_DELAY);
63}
64
65static inline u32 bcm2835_sdhci_readl(struct sdhci_host *host, int reg)
66{
67 u32 val = readl(host->ioaddr + reg);
68
69 if (reg == SDHCI_CAPABILITIES)
70 val |= SDHCI_CAN_VDD_330;
71
72 return val;
73}
74
75static void bcm2835_sdhci_writew(struct sdhci_host *host, u16 val, int reg)
76{
77 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
78 struct bcm2835_sdhci *bcm2835_host = pltfm_host->priv;
79 u32 oldval = (reg == SDHCI_COMMAND) ? bcm2835_host->shadow :
80 bcm2835_sdhci_readl(host, reg & ~3);
81 u32 word_num = (reg >> 1) & 1;
82 u32 word_shift = word_num * 16;
83 u32 mask = 0xffff << word_shift;
84 u32 newval = (oldval & ~mask) | (val << word_shift);
85
86 if (reg == SDHCI_TRANSFER_MODE)
87 bcm2835_host->shadow = newval;
88 else
89 bcm2835_sdhci_writel(host, newval, reg & ~3);
90}
91
92static u16 bcm2835_sdhci_readw(struct sdhci_host *host, int reg)
93{
94 u32 val = bcm2835_sdhci_readl(host, (reg & ~3));
95 u32 word_num = (reg >> 1) & 1;
96 u32 word_shift = word_num * 16;
97 u32 word = (val >> word_shift) & 0xffff;
98
99 return word;
100}
101
102static void bcm2835_sdhci_writeb(struct sdhci_host *host, u8 val, int reg)
103{
104 u32 oldval = bcm2835_sdhci_readl(host, reg & ~3);
105 u32 byte_num = reg & 3;
106 u32 byte_shift = byte_num * 8;
107 u32 mask = 0xff << byte_shift;
108 u32 newval = (oldval & ~mask) | (val << byte_shift);
109
110 bcm2835_sdhci_writel(host, newval, reg & ~3);
111}
112
113static u8 bcm2835_sdhci_readb(struct sdhci_host *host, int reg)
114{
115 u32 val = bcm2835_sdhci_readl(host, (reg & ~3));
116 u32 byte_num = reg & 3;
117 u32 byte_shift = byte_num * 8;
118 u32 byte = (val >> byte_shift) & 0xff;
119
120 return byte;
121}
122
123static unsigned int bcm2835_sdhci_get_max_clock(struct sdhci_host *host)
124{
125 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
126 struct bcm2835_sdhci *bcm2835_host = pltfm_host->priv;
127
128 return clk_get_rate(bcm2835_host->clk);
129}
130
131unsigned int bcm2835_sdhci_get_min_clock(struct sdhci_host *host)
132{
133 return MIN_FREQ;
134}
135
136unsigned int bcm2835_sdhci_get_timeout_clock(struct sdhci_host *host)
137{
138 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
139 struct bcm2835_sdhci *bcm2835_host = pltfm_host->priv;
140
141 return clk_get_rate(bcm2835_host->clk);
142}
143
144static struct sdhci_ops bcm2835_sdhci_ops = {
145 .write_l = bcm2835_sdhci_writel,
146 .write_w = bcm2835_sdhci_writew,
147 .write_b = bcm2835_sdhci_writeb,
148 .read_l = bcm2835_sdhci_readl,
149 .read_w = bcm2835_sdhci_readw,
150 .read_b = bcm2835_sdhci_readb,
151 .get_max_clock = bcm2835_sdhci_get_max_clock,
152 .get_min_clock = bcm2835_sdhci_get_min_clock,
153 .get_timeout_clock = bcm2835_sdhci_get_timeout_clock,
154};
155
156static struct sdhci_pltfm_data bcm2835_sdhci_pdata = {
157 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION,
158 .ops = &bcm2835_sdhci_ops,
159};
160
161static int bcm2835_sdhci_probe(struct platform_device *pdev)
162{
163 struct sdhci_host *host;
164 struct bcm2835_sdhci *bcm2835_host;
165 struct sdhci_pltfm_host *pltfm_host;
166 int ret;
167
168 host = sdhci_pltfm_init(pdev, &bcm2835_sdhci_pdata);
169 if (IS_ERR(host))
170 return PTR_ERR(host);
171
172 bcm2835_host = devm_kzalloc(&pdev->dev, sizeof(*bcm2835_host),
173 GFP_KERNEL);
174 if (!bcm2835_host) {
175 dev_err(mmc_dev(host->mmc),
176 "failed to allocate bcm2835_sdhci\n");
177 return -ENOMEM;
178 }
179
180 pltfm_host = sdhci_priv(host);
181 pltfm_host->priv = bcm2835_host;
182
183 bcm2835_host->clk = devm_clk_get(&pdev->dev, NULL);
184 if (IS_ERR(bcm2835_host->clk)) {
185 ret = PTR_ERR(bcm2835_host->clk);
186 goto err;
187 }
188
189 return sdhci_add_host(host);
190
191err:
192 sdhci_pltfm_free(pdev);
193 return ret;
194}
195
196static int bcm2835_sdhci_remove(struct platform_device *pdev)
197{
198 struct sdhci_host *host = platform_get_drvdata(pdev);
199 int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
200
201 sdhci_remove_host(host, dead);
202 sdhci_pltfm_free(pdev);
203
204 return 0;
205}
206
207static const struct of_device_id bcm2835_sdhci_of_match[] = {
208 { .compatible = "brcm,bcm2835-sdhci" },
209 { }
210};
211MODULE_DEVICE_TABLE(of, bcm2835_sdhci_of_match);
212
213static struct platform_driver bcm2835_sdhci_driver = {
214 .driver = {
215 .name = "sdhci-bcm2835",
216 .owner = THIS_MODULE,
217 .of_match_table = bcm2835_sdhci_of_match,
218 .pm = SDHCI_PLTFM_PMOPS,
219 },
220 .probe = bcm2835_sdhci_probe,
221 .remove = bcm2835_sdhci_remove,
222};
223module_platform_driver(bcm2835_sdhci_driver);
224
225MODULE_DESCRIPTION("BCM2835 SDHCI driver");
226MODULE_AUTHOR("Stephen Warren");
227MODULE_LICENSE("GPL v2");