arm: imx: Zero entire imxdma structure
[linux/fpc-iii.git] / drivers / mmc / host / sdhci-esdhc-imx.c
blob9b82910b9dbb3ec01ab07a0ff2f19f6ec59a9ed7
1 /*
2 * Freescale eSDHC i.MX controller driver for the platform bus.
4 * derived from the OF-version.
6 * Copyright (c) 2010 Pengutronix e.K.
7 * Author: Wolfram Sang <w.sang@pengutronix.de>
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.
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 <mach/hardware.h>
21 #include "sdhci.h"
22 #include "sdhci-pltfm.h"
23 #include "sdhci-esdhc.h"
25 static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, int reg)
27 void __iomem *base = host->ioaddr + (reg & ~0x3);
28 u32 shift = (reg & 0x3) * 8;
30 writel(((readl(base) & ~(mask << shift)) | (val << shift)), base);
33 static u16 esdhc_readw_le(struct sdhci_host *host, int reg)
35 if (unlikely(reg == SDHCI_HOST_VERSION))
36 reg ^= 2;
38 return readw(host->ioaddr + reg);
41 static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
43 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
45 switch (reg) {
46 case SDHCI_TRANSFER_MODE:
48 * Postpone this write, we must do it together with a
49 * command write that is down below.
51 pltfm_host->scratchpad = val;
52 return;
53 case SDHCI_COMMAND:
54 writel(val << 16 | pltfm_host->scratchpad,
55 host->ioaddr + SDHCI_TRANSFER_MODE);
56 return;
57 case SDHCI_BLOCK_SIZE:
58 val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
59 break;
61 esdhc_clrset_le(host, 0xffff, val, reg);
64 static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg)
66 u32 new_val;
68 switch (reg) {
69 case SDHCI_POWER_CONTROL:
71 * FSL put some DMA bits here
72 * If your board has a regulator, code should be here
74 return;
75 case SDHCI_HOST_CONTROL:
76 /* FSL messed up here, so we can just keep those two */
77 new_val = val & (SDHCI_CTRL_LED | SDHCI_CTRL_4BITBUS);
78 /* ensure the endianess */
79 new_val |= ESDHC_HOST_CONTROL_LE;
80 /* DMA mode bits are shifted */
81 new_val |= (val & SDHCI_CTRL_DMA_MASK) << 5;
83 esdhc_clrset_le(host, 0xffff, new_val, reg);
84 return;
86 esdhc_clrset_le(host, 0xff, val, reg);
89 static unsigned int esdhc_pltfm_get_max_clock(struct sdhci_host *host)
91 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
93 return clk_get_rate(pltfm_host->clk);
96 static unsigned int esdhc_pltfm_get_min_clock(struct sdhci_host *host)
98 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
100 return clk_get_rate(pltfm_host->clk) / 256 / 16;
103 static int esdhc_pltfm_init(struct sdhci_host *host, struct sdhci_pltfm_data *pdata)
105 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
106 struct clk *clk;
108 clk = clk_get(mmc_dev(host->mmc), NULL);
109 if (IS_ERR(clk)) {
110 dev_err(mmc_dev(host->mmc), "clk err\n");
111 return PTR_ERR(clk);
113 clk_enable(clk);
114 pltfm_host->clk = clk;
116 if (cpu_is_mx35() || cpu_is_mx51())
117 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
119 /* Fix errata ENGcm07207 which is present on i.MX25 and i.MX35 */
120 if (cpu_is_mx25() || cpu_is_mx35())
121 host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK;
123 return 0;
126 static void esdhc_pltfm_exit(struct sdhci_host *host)
128 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
130 clk_disable(pltfm_host->clk);
131 clk_put(pltfm_host->clk);
134 static struct sdhci_ops sdhci_esdhc_ops = {
135 .read_w = esdhc_readw_le,
136 .write_w = esdhc_writew_le,
137 .write_b = esdhc_writeb_le,
138 .set_clock = esdhc_set_clock,
139 .get_max_clock = esdhc_pltfm_get_max_clock,
140 .get_min_clock = esdhc_pltfm_get_min_clock,
143 struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
144 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_ADMA,
145 /* ADMA has issues. Might be fixable */
146 .ops = &sdhci_esdhc_ops,
147 .init = esdhc_pltfm_init,
148 .exit = esdhc_pltfm_exit,