aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/host/sdhci-esdhc-imx.c
diff options
context:
space:
mode:
authorWolfram Sang <w.sang@pengutronix.de>2010-10-15 06:21:04 -0400
committerChris Ball <cjb@laptop.org>2010-10-23 09:11:22 -0400
commit95f25efe0ce22e28d61722d655d2ef582f5f7520 (patch)
tree90ce49eee31ae50ca91b812d7d9dda4d35136043 /drivers/mmc/host/sdhci-esdhc-imx.c
parent80872e21b0263f016f2edb7b72dd8be5636d7ca7 (diff)
mmc: sdhci-pltfm: add -pltfm driver for imx35/51
This driver adds basic support for the esdhc-core found on e.g. imx35/51, as a platform driver. Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Acked-by: Anton Vorontsov <cbouatmailru@gmail.com> Tested-by: Eric BĂ©nard <eric@eukrea.com> Signed-off-by: Chris Ball <cjb@laptop.org>
Diffstat (limited to 'drivers/mmc/host/sdhci-esdhc-imx.c')
-rw-r--r--drivers/mmc/host/sdhci-esdhc-imx.c143
1 files changed, 143 insertions, 0 deletions
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
new file mode 100644
index 000000000000..2e9cca19c90b
--- /dev/null
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -0,0 +1,143 @@
1/*
2 * Freescale eSDHC i.MX controller driver for the platform bus.
3 *
4 * derived from the OF-version.
5 *
6 * Copyright (c) 2010 Pengutronix e.K.
7 * Author: Wolfram Sang <w.sang@pengutronix.de>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License.
12 */
13
14#include <linux/io.h>
15#include <linux/delay.h>
16#include <linux/err.h>
17#include <linux/clk.h>
18#include <linux/mmc/host.h>
19#include <linux/mmc/sdhci-pltfm.h>
20#include "sdhci.h"
21#include "sdhci-pltfm.h"
22#include "sdhci-esdhc.h"
23
24static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, int reg)
25{
26 void __iomem *base = host->ioaddr + (reg & ~0x3);
27 u32 shift = (reg & 0x3) * 8;
28
29 writel(((readl(base) & ~(mask << shift)) | (val << shift)), base);
30}
31
32static u16 esdhc_readw_le(struct sdhci_host *host, int reg)
33{
34 if (unlikely(reg == SDHCI_HOST_VERSION))
35 reg ^= 2;
36
37 return readw(host->ioaddr + reg);
38}
39
40static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
41{
42 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
43
44 switch (reg) {
45 case SDHCI_TRANSFER_MODE:
46 /*
47 * Postpone this write, we must do it together with a
48 * command write that is down below.
49 */
50 pltfm_host->scratchpad = val;
51 return;
52 case SDHCI_COMMAND:
53 writel(val << 16 | pltfm_host->scratchpad,
54 host->ioaddr + SDHCI_TRANSFER_MODE);
55 return;
56 case SDHCI_BLOCK_SIZE:
57 val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
58 break;
59 }
60 esdhc_clrset_le(host, 0xffff, val, reg);
61}
62
63static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg)
64{
65 u32 new_val;
66
67 switch (reg) {
68 case SDHCI_POWER_CONTROL:
69 /*
70 * FSL put some DMA bits here
71 * If your board has a regulator, code should be here
72 */
73 return;
74 case SDHCI_HOST_CONTROL:
75 /* FSL messed up here, so we can just keep those two */
76 new_val = val & (SDHCI_CTRL_LED | SDHCI_CTRL_4BITBUS);
77 /* ensure the endianess */
78 new_val |= ESDHC_HOST_CONTROL_LE;
79 /* DMA mode bits are shifted */
80 new_val |= (val & SDHCI_CTRL_DMA_MASK) << 5;
81
82 esdhc_clrset_le(host, 0xffff, new_val, reg);
83 return;
84 }
85 esdhc_clrset_le(host, 0xff, val, reg);
86}
87
88static unsigned int esdhc_pltfm_get_max_clock(struct sdhci_host *host)
89{
90 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
91
92 return clk_get_rate(pltfm_host->clk);
93}
94
95static unsigned int esdhc_pltfm_get_min_clock(struct sdhci_host *host)
96{
97 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
98
99 return clk_get_rate(pltfm_host->clk) / 256 / 16;
100}
101
102static int esdhc_pltfm_init(struct sdhci_host *host, struct sdhci_pltfm_data *pdata)
103{
104 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
105 struct clk *clk;
106
107 clk = clk_get(mmc_dev(host->mmc), NULL);
108 if (IS_ERR(clk)) {
109 dev_err(mmc_dev(host->mmc), "clk err\n");
110 return PTR_ERR(clk);
111 }
112 clk_enable(clk);
113 pltfm_host->clk = clk;
114
115 return 0;
116}
117
118static void esdhc_pltfm_exit(struct sdhci_host *host)
119{
120 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
121
122 clk_disable(pltfm_host->clk);
123 clk_put(pltfm_host->clk);
124}
125
126static struct sdhci_ops sdhci_esdhc_ops = {
127 .read_w = esdhc_readw_le,
128 .write_w = esdhc_writew_le,
129 .write_b = esdhc_writeb_le,
130 .set_clock = esdhc_set_clock,
131 .get_max_clock = esdhc_pltfm_get_max_clock,
132 .get_min_clock = esdhc_pltfm_get_min_clock,
133};
134
135struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
136 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_NO_MULTIBLOCK
137 | SDHCI_QUIRK_BROKEN_ADMA,
138 /* ADMA has issues. Might be fixable */
139 /* NO_MULTIBLOCK might be MX35 only (Errata: ENGcm07207) */
140 .ops = &sdhci_esdhc_ops,
141 .init = esdhc_pltfm_init,
142 .exit = esdhc_pltfm_exit,
143};