mmc: core: move the cache disabling operation to mmc_suspend
[linux-2.6-block.git] / drivers / mmc / host / sdhci-esdhc-imx.c
CommitLineData
95f25efe
WS
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>
0c6d49ce 18#include <linux/gpio.h>
66506f76 19#include <linux/module.h>
e149860d 20#include <linux/slab.h>
95f25efe 21#include <linux/mmc/host.h>
58ac8177
RZ
22#include <linux/mmc/mmc.h>
23#include <linux/mmc/sdio.h>
fbe5fdd1 24#include <linux/mmc/slot-gpio.h>
abfafc2d
SG
25#include <linux/of.h>
26#include <linux/of_device.h>
27#include <linux/of_gpio.h>
e62d8b8f 28#include <linux/pinctrl/consumer.h>
82906b13 29#include <linux/platform_data/mmc-esdhc-imx.h>
95f25efe
WS
30#include "sdhci-pltfm.h"
31#include "sdhci-esdhc.h"
32
60bf6396 33#define ESDHC_CTRL_D3CD 0x08
58ac8177 34/* VENDOR SPEC register */
60bf6396
SG
35#define ESDHC_VENDOR_SPEC 0xc0
36#define ESDHC_VENDOR_SPEC_SDIO_QUIRK (1 << 1)
37#define ESDHC_WTMK_LVL 0x44
38#define ESDHC_MIX_CTRL 0x48
58ac8177 39
97e4ba6a
RZ
40/*
41 * There is an INT DMA ERR mis-match between eSDHC and STD SDHC SPEC:
42 * Bit25 is used in STD SPEC, and is reserved in fsl eSDHC design,
43 * but bit28 is used as the INT DMA ERR in fsl eSDHC design.
44 * Define this macro DMA error INT for fsl eSDHC
45 */
60bf6396 46#define ESDHC_INT_VENDOR_SPEC_DMA_ERR (1 << 28)
97e4ba6a 47
58ac8177
RZ
48/*
49 * The CMDTYPE of the CMD register (offset 0xE) should be set to
50 * "11" when the STOP CMD12 is issued on imx53 to abort one
51 * open ended multi-blk IO. Otherwise the TC INT wouldn't
52 * be generated.
53 * In exact block transfer, the controller doesn't complete the
54 * operations automatically as required at the end of the
55 * transfer and remains on hold if the abort command is not sent.
56 * As a result, the TC flag is not asserted and SW received timeout
57 * exeception. Bit1 of Vendor Spec registor is used to fix it.
58 */
59#define ESDHC_FLAG_MULTIBLK_NO_INT (1 << 1)
e149860d 60
57ed3314
SG
61enum imx_esdhc_type {
62 IMX25_ESDHC,
63 IMX35_ESDHC,
64 IMX51_ESDHC,
65 IMX53_ESDHC,
95a2482a 66 IMX6Q_USDHC,
57ed3314
SG
67};
68
e149860d
RZ
69struct pltfm_imx_data {
70 int flags;
71 u32 scratchpad;
57ed3314 72 enum imx_esdhc_type devtype;
e62d8b8f 73 struct pinctrl *pinctrl;
842afc02 74 struct esdhc_platform_data boarddata;
52dac615
SH
75 struct clk *clk_ipg;
76 struct clk *clk_ahb;
77 struct clk *clk_per;
e149860d
RZ
78};
79
57ed3314
SG
80static struct platform_device_id imx_esdhc_devtype[] = {
81 {
82 .name = "sdhci-esdhc-imx25",
83 .driver_data = IMX25_ESDHC,
84 }, {
85 .name = "sdhci-esdhc-imx35",
86 .driver_data = IMX35_ESDHC,
87 }, {
88 .name = "sdhci-esdhc-imx51",
89 .driver_data = IMX51_ESDHC,
90 }, {
91 .name = "sdhci-esdhc-imx53",
92 .driver_data = IMX53_ESDHC,
95a2482a
SG
93 }, {
94 .name = "sdhci-usdhc-imx6q",
95 .driver_data = IMX6Q_USDHC,
57ed3314
SG
96 }, {
97 /* sentinel */
98 }
99};
100MODULE_DEVICE_TABLE(platform, imx_esdhc_devtype);
101
abfafc2d
SG
102static const struct of_device_id imx_esdhc_dt_ids[] = {
103 { .compatible = "fsl,imx25-esdhc", .data = &imx_esdhc_devtype[IMX25_ESDHC], },
104 { .compatible = "fsl,imx35-esdhc", .data = &imx_esdhc_devtype[IMX35_ESDHC], },
105 { .compatible = "fsl,imx51-esdhc", .data = &imx_esdhc_devtype[IMX51_ESDHC], },
106 { .compatible = "fsl,imx53-esdhc", .data = &imx_esdhc_devtype[IMX53_ESDHC], },
95a2482a 107 { .compatible = "fsl,imx6q-usdhc", .data = &imx_esdhc_devtype[IMX6Q_USDHC], },
abfafc2d
SG
108 { /* sentinel */ }
109};
110MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids);
111
57ed3314
SG
112static inline int is_imx25_esdhc(struct pltfm_imx_data *data)
113{
114 return data->devtype == IMX25_ESDHC;
115}
116
117static inline int is_imx35_esdhc(struct pltfm_imx_data *data)
118{
119 return data->devtype == IMX35_ESDHC;
120}
121
122static inline int is_imx51_esdhc(struct pltfm_imx_data *data)
123{
124 return data->devtype == IMX51_ESDHC;
125}
126
127static inline int is_imx53_esdhc(struct pltfm_imx_data *data)
128{
129 return data->devtype == IMX53_ESDHC;
130}
131
95a2482a
SG
132static inline int is_imx6q_usdhc(struct pltfm_imx_data *data)
133{
134 return data->devtype == IMX6Q_USDHC;
135}
136
95f25efe
WS
137static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, int reg)
138{
139 void __iomem *base = host->ioaddr + (reg & ~0x3);
140 u32 shift = (reg & 0x3) * 8;
141
142 writel(((readl(base) & ~(mask << shift)) | (val << shift)), base);
143}
144
7e29c306
WS
145static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
146{
7e29c306
WS
147 u32 val = readl(host->ioaddr + reg);
148
97e4ba6a
RZ
149 if (unlikely(reg == SDHCI_CAPABILITIES)) {
150 /* In FSL esdhc IC module, only bit20 is used to indicate the
151 * ADMA2 capability of esdhc, but this bit is messed up on
152 * some SOCs (e.g. on MX25, MX35 this bit is set, but they
153 * don't actually support ADMA2). So set the BROKEN_ADMA
154 * uirk on MX25/35 platforms.
155 */
156
157 if (val & SDHCI_CAN_DO_ADMA1) {
158 val &= ~SDHCI_CAN_DO_ADMA1;
159 val |= SDHCI_CAN_DO_ADMA2;
160 }
161 }
162
163 if (unlikely(reg == SDHCI_INT_STATUS)) {
60bf6396
SG
164 if (val & ESDHC_INT_VENDOR_SPEC_DMA_ERR) {
165 val &= ~ESDHC_INT_VENDOR_SPEC_DMA_ERR;
97e4ba6a
RZ
166 val |= SDHCI_INT_ADMA_ERROR;
167 }
168 }
169
7e29c306
WS
170 return val;
171}
172
173static void esdhc_writel_le(struct sdhci_host *host, u32 val, int reg)
174{
e149860d
RZ
175 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
176 struct pltfm_imx_data *imx_data = pltfm_host->priv;
0d58864b
TL
177 u32 data;
178
179 if (unlikely(reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE)) {
0d58864b
TL
180 if (val & SDHCI_INT_CARD_INT) {
181 /*
182 * Clear and then set D3CD bit to avoid missing the
183 * card interrupt. This is a eSDHC controller problem
184 * so we need to apply the following workaround: clear
185 * and set D3CD bit will make eSDHC re-sample the card
186 * interrupt. In case a card interrupt was lost,
187 * re-sample it by the following steps.
188 */
189 data = readl(host->ioaddr + SDHCI_HOST_CONTROL);
60bf6396 190 data &= ~ESDHC_CTRL_D3CD;
0d58864b 191 writel(data, host->ioaddr + SDHCI_HOST_CONTROL);
60bf6396 192 data |= ESDHC_CTRL_D3CD;
0d58864b
TL
193 writel(data, host->ioaddr + SDHCI_HOST_CONTROL);
194 }
195 }
7e29c306 196
58ac8177
RZ
197 if (unlikely((imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT)
198 && (reg == SDHCI_INT_STATUS)
199 && (val & SDHCI_INT_DATA_END))) {
200 u32 v;
60bf6396
SG
201 v = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
202 v &= ~ESDHC_VENDOR_SPEC_SDIO_QUIRK;
203 writel(v, host->ioaddr + ESDHC_VENDOR_SPEC);
58ac8177
RZ
204 }
205
97e4ba6a
RZ
206 if (unlikely(reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE)) {
207 if (val & SDHCI_INT_ADMA_ERROR) {
208 val &= ~SDHCI_INT_ADMA_ERROR;
60bf6396 209 val |= ESDHC_INT_VENDOR_SPEC_DMA_ERR;
97e4ba6a
RZ
210 }
211 }
212
7e29c306
WS
213 writel(val, host->ioaddr + reg);
214}
215
95f25efe
WS
216static u16 esdhc_readw_le(struct sdhci_host *host, int reg)
217{
ef4d0888
SG
218 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
219 struct pltfm_imx_data *imx_data = pltfm_host->priv;
220
95a2482a 221 if (unlikely(reg == SDHCI_HOST_VERSION)) {
ef4d0888
SG
222 reg ^= 2;
223 if (is_imx6q_usdhc(imx_data)) {
224 /*
225 * The usdhc register returns a wrong host version.
226 * Correct it here.
227 */
228 return SDHCI_SPEC_300;
229 }
95a2482a 230 }
95f25efe
WS
231
232 return readw(host->ioaddr + reg);
233}
234
235static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
236{
237 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
e149860d 238 struct pltfm_imx_data *imx_data = pltfm_host->priv;
95f25efe
WS
239
240 switch (reg) {
241 case SDHCI_TRANSFER_MODE:
242 /*
243 * Postpone this write, we must do it together with a
244 * command write that is down below.
245 */
58ac8177
RZ
246 if ((imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT)
247 && (host->cmd->opcode == SD_IO_RW_EXTENDED)
248 && (host->cmd->data->blocks > 1)
249 && (host->cmd->data->flags & MMC_DATA_READ)) {
250 u32 v;
60bf6396
SG
251 v = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
252 v |= ESDHC_VENDOR_SPEC_SDIO_QUIRK;
253 writel(v, host->ioaddr + ESDHC_VENDOR_SPEC);
58ac8177 254 }
e149860d 255 imx_data->scratchpad = val;
95f25efe
WS
256 return;
257 case SDHCI_COMMAND:
5b6b0ad6
SH
258 if ((host->cmd->opcode == MMC_STOP_TRANSMISSION ||
259 host->cmd->opcode == MMC_SET_BLOCK_COUNT) &&
260 (imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT))
58ac8177 261 val |= SDHCI_CMD_ABORTCMD;
95a2482a
SG
262
263 if (is_imx6q_usdhc(imx_data)) {
60bf6396 264 u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL);
95a2482a 265 m = imx_data->scratchpad | (m & 0xffff0000);
60bf6396 266 writel(m, host->ioaddr + ESDHC_MIX_CTRL);
95a2482a
SG
267 writel(val << 16,
268 host->ioaddr + SDHCI_TRANSFER_MODE);
269 } else {
270 writel(val << 16 | imx_data->scratchpad,
271 host->ioaddr + SDHCI_TRANSFER_MODE);
272 }
95f25efe
WS
273 return;
274 case SDHCI_BLOCK_SIZE:
275 val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
276 break;
277 }
278 esdhc_clrset_le(host, 0xffff, val, reg);
279}
280
281static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg)
282{
9a0985b7
WC
283 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
284 struct pltfm_imx_data *imx_data = pltfm_host->priv;
95f25efe
WS
285 u32 new_val;
286
287 switch (reg) {
288 case SDHCI_POWER_CONTROL:
289 /*
290 * FSL put some DMA bits here
291 * If your board has a regulator, code should be here
292 */
293 return;
294 case SDHCI_HOST_CONTROL:
6b40d182
SG
295 /* FSL messed up here, so we need to manually compose it. */
296 new_val = val & (SDHCI_CTRL_LED | SDHCI_CTRL_4BITBUS);
7122bbb0 297 /* ensure the endianness */
95f25efe 298 new_val |= ESDHC_HOST_CONTROL_LE;
9a0985b7
WC
299 /* bits 8&9 are reserved on mx25 */
300 if (!is_imx25_esdhc(imx_data)) {
301 /* DMA mode bits are shifted */
302 new_val |= (val & SDHCI_CTRL_DMA_MASK) << 5;
303 }
95f25efe
WS
304
305 esdhc_clrset_le(host, 0xffff, new_val, reg);
306 return;
307 }
308 esdhc_clrset_le(host, 0xff, val, reg);
913413c3
SG
309
310 /*
311 * The esdhc has a design violation to SDHC spec which tells
312 * that software reset should not affect card detection circuit.
313 * But esdhc clears its SYSCTL register bits [0..2] during the
314 * software reset. This will stop those clocks that card detection
315 * circuit relies on. To work around it, we turn the clocks on back
316 * to keep card detection circuit functional.
317 */
318 if ((reg == SDHCI_SOFTWARE_RESET) && (val & 1))
319 esdhc_clrset_le(host, 0x7, 0x7, ESDHC_SYSTEM_CONTROL);
95f25efe
WS
320}
321
322static unsigned int esdhc_pltfm_get_max_clock(struct sdhci_host *host)
323{
324 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
325
326 return clk_get_rate(pltfm_host->clk);
327}
328
329static unsigned int esdhc_pltfm_get_min_clock(struct sdhci_host *host)
330{
331 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
332
333 return clk_get_rate(pltfm_host->clk) / 256 / 16;
334}
335
913413c3
SG
336static unsigned int esdhc_pltfm_get_ro(struct sdhci_host *host)
337{
842afc02
SG
338 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
339 struct pltfm_imx_data *imx_data = pltfm_host->priv;
340 struct esdhc_platform_data *boarddata = &imx_data->boarddata;
913413c3
SG
341
342 switch (boarddata->wp_type) {
343 case ESDHC_WP_GPIO:
fbe5fdd1 344 return mmc_gpio_get_ro(host->mmc);
913413c3
SG
345 case ESDHC_WP_CONTROLLER:
346 return !(readl(host->ioaddr + SDHCI_PRESENT_STATE) &
347 SDHCI_WRITE_PROTECT);
348 case ESDHC_WP_NONE:
349 break;
350 }
351
352 return -ENOSYS;
353}
354
0c6d49ce 355static struct sdhci_ops sdhci_esdhc_ops = {
e149860d 356 .read_l = esdhc_readl_le,
0c6d49ce 357 .read_w = esdhc_readw_le,
e149860d 358 .write_l = esdhc_writel_le,
0c6d49ce
WS
359 .write_w = esdhc_writew_le,
360 .write_b = esdhc_writeb_le,
361 .set_clock = esdhc_set_clock,
362 .get_max_clock = esdhc_pltfm_get_max_clock,
363 .get_min_clock = esdhc_pltfm_get_min_clock,
913413c3 364 .get_ro = esdhc_pltfm_get_ro,
0c6d49ce
WS
365};
366
85d6509d 367static struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
97e4ba6a
RZ
368 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_NO_HISPD_BIT
369 | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
370 | SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC
85d6509d 371 | SDHCI_QUIRK_BROKEN_CARD_DETECTION,
85d6509d
SG
372 .ops = &sdhci_esdhc_ops,
373};
374
abfafc2d 375#ifdef CONFIG_OF
c3be1efd 376static int
abfafc2d
SG
377sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
378 struct esdhc_platform_data *boarddata)
379{
380 struct device_node *np = pdev->dev.of_node;
381
382 if (!np)
383 return -ENODEV;
384
7f217794 385 if (of_get_property(np, "non-removable", NULL))
abfafc2d
SG
386 boarddata->cd_type = ESDHC_CD_PERMANENT;
387
388 if (of_get_property(np, "fsl,cd-controller", NULL))
389 boarddata->cd_type = ESDHC_CD_CONTROLLER;
390
391 if (of_get_property(np, "fsl,wp-controller", NULL))
392 boarddata->wp_type = ESDHC_WP_CONTROLLER;
393
394 boarddata->cd_gpio = of_get_named_gpio(np, "cd-gpios", 0);
395 if (gpio_is_valid(boarddata->cd_gpio))
396 boarddata->cd_type = ESDHC_CD_GPIO;
397
398 boarddata->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0);
399 if (gpio_is_valid(boarddata->wp_gpio))
400 boarddata->wp_type = ESDHC_WP_GPIO;
401
402 return 0;
403}
404#else
405static inline int
406sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
407 struct esdhc_platform_data *boarddata)
408{
409 return -ENODEV;
410}
411#endif
412
c3be1efd 413static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
95f25efe 414{
abfafc2d
SG
415 const struct of_device_id *of_id =
416 of_match_device(imx_esdhc_dt_ids, &pdev->dev);
85d6509d
SG
417 struct sdhci_pltfm_host *pltfm_host;
418 struct sdhci_host *host;
419 struct esdhc_platform_data *boarddata;
0c6d49ce 420 int err;
e149860d 421 struct pltfm_imx_data *imx_data;
95f25efe 422
85d6509d
SG
423 host = sdhci_pltfm_init(pdev, &sdhci_esdhc_imx_pdata);
424 if (IS_ERR(host))
425 return PTR_ERR(host);
426
427 pltfm_host = sdhci_priv(host);
428
e3af31c6 429 imx_data = devm_kzalloc(&pdev->dev, sizeof(*imx_data), GFP_KERNEL);
abfafc2d
SG
430 if (!imx_data) {
431 err = -ENOMEM;
e3af31c6 432 goto free_sdhci;
abfafc2d 433 }
57ed3314 434
abfafc2d
SG
435 if (of_id)
436 pdev->id_entry = of_id->data;
57ed3314 437 imx_data->devtype = pdev->id_entry->driver_data;
85d6509d
SG
438 pltfm_host->priv = imx_data;
439
52dac615
SH
440 imx_data->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
441 if (IS_ERR(imx_data->clk_ipg)) {
442 err = PTR_ERR(imx_data->clk_ipg);
e3af31c6 443 goto free_sdhci;
95f25efe 444 }
52dac615
SH
445
446 imx_data->clk_ahb = devm_clk_get(&pdev->dev, "ahb");
447 if (IS_ERR(imx_data->clk_ahb)) {
448 err = PTR_ERR(imx_data->clk_ahb);
e3af31c6 449 goto free_sdhci;
52dac615
SH
450 }
451
452 imx_data->clk_per = devm_clk_get(&pdev->dev, "per");
453 if (IS_ERR(imx_data->clk_per)) {
454 err = PTR_ERR(imx_data->clk_per);
e3af31c6 455 goto free_sdhci;
52dac615
SH
456 }
457
458 pltfm_host->clk = imx_data->clk_per;
459
460 clk_prepare_enable(imx_data->clk_per);
461 clk_prepare_enable(imx_data->clk_ipg);
462 clk_prepare_enable(imx_data->clk_ahb);
95f25efe 463
e62d8b8f
DA
464 imx_data->pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
465 if (IS_ERR(imx_data->pinctrl)) {
466 err = PTR_ERR(imx_data->pinctrl);
e3af31c6 467 goto disable_clk;
e62d8b8f
DA
468 }
469
b8915282 470 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
37865fe9 471
57ed3314 472 if (is_imx25_esdhc(imx_data) || is_imx35_esdhc(imx_data))
0c6d49ce 473 /* Fix errata ENGcm07207 present on i.MX25 and i.MX35 */
97e4ba6a
RZ
474 host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK
475 | SDHCI_QUIRK_BROKEN_ADMA;
0c6d49ce 476
57ed3314 477 if (is_imx53_esdhc(imx_data))
58ac8177
RZ
478 imx_data->flags |= ESDHC_FLAG_MULTIBLK_NO_INT;
479
f750ba9b
SG
480 /*
481 * The imx6q ROM code will change the default watermark level setting
482 * to something insane. Change it back here.
483 */
484 if (is_imx6q_usdhc(imx_data))
60bf6396 485 writel(0x08100810, host->ioaddr + ESDHC_WTMK_LVL);
f750ba9b 486
842afc02 487 boarddata = &imx_data->boarddata;
abfafc2d
SG
488 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
489 if (!host->mmc->parent->platform_data) {
490 dev_err(mmc_dev(host->mmc), "no board data!\n");
491 err = -EINVAL;
e3af31c6 492 goto disable_clk;
abfafc2d
SG
493 }
494 imx_data->boarddata = *((struct esdhc_platform_data *)
495 host->mmc->parent->platform_data);
496 }
913413c3
SG
497
498 /* write_protect */
499 if (boarddata->wp_type == ESDHC_WP_GPIO) {
fbe5fdd1 500 err = mmc_gpio_request_ro(host->mmc, boarddata->wp_gpio);
0c6d49ce 501 if (err) {
fbe5fdd1
SG
502 dev_err(mmc_dev(host->mmc),
503 "failed to request write-protect gpio!\n");
504 goto disable_clk;
0c6d49ce 505 }
fbe5fdd1 506 host->mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
913413c3
SG
507 }
508
509 /* card_detect */
913413c3
SG
510 switch (boarddata->cd_type) {
511 case ESDHC_CD_GPIO:
fbe5fdd1 512 err = mmc_gpio_request_cd(host->mmc, boarddata->cd_gpio);
7e29c306 513 if (err) {
913413c3 514 dev_err(mmc_dev(host->mmc),
fbe5fdd1 515 "failed to request card-detect gpio!\n");
e3af31c6 516 goto disable_clk;
7e29c306 517 }
913413c3 518 /* fall through */
7e29c306 519
913413c3
SG
520 case ESDHC_CD_CONTROLLER:
521 /* we have a working card_detect back */
7e29c306 522 host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
913413c3
SG
523 break;
524
525 case ESDHC_CD_PERMANENT:
526 host->mmc->caps = MMC_CAP_NONREMOVABLE;
527 break;
528
529 case ESDHC_CD_NONE:
530 break;
0c6d49ce 531 }
16a790bc 532
85d6509d
SG
533 err = sdhci_add_host(host);
534 if (err)
e3af31c6 535 goto disable_clk;
85d6509d 536
95f25efe 537 return 0;
7e29c306 538
e3af31c6 539disable_clk:
52dac615
SH
540 clk_disable_unprepare(imx_data->clk_per);
541 clk_disable_unprepare(imx_data->clk_ipg);
542 clk_disable_unprepare(imx_data->clk_ahb);
e3af31c6 543free_sdhci:
85d6509d
SG
544 sdhci_pltfm_free(pdev);
545 return err;
95f25efe
WS
546}
547
6e0ee714 548static int sdhci_esdhc_imx_remove(struct platform_device *pdev)
95f25efe 549{
85d6509d 550 struct sdhci_host *host = platform_get_drvdata(pdev);
95f25efe 551 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
e149860d 552 struct pltfm_imx_data *imx_data = pltfm_host->priv;
85d6509d
SG
553 int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
554
555 sdhci_remove_host(host, dead);
0c6d49ce 556
52dac615
SH
557 clk_disable_unprepare(imx_data->clk_per);
558 clk_disable_unprepare(imx_data->clk_ipg);
559 clk_disable_unprepare(imx_data->clk_ahb);
560
85d6509d
SG
561 sdhci_pltfm_free(pdev);
562
563 return 0;
95f25efe
WS
564}
565
85d6509d
SG
566static struct platform_driver sdhci_esdhc_imx_driver = {
567 .driver = {
568 .name = "sdhci-esdhc-imx",
569 .owner = THIS_MODULE,
abfafc2d 570 .of_match_table = imx_esdhc_dt_ids,
29495aa0 571 .pm = SDHCI_PLTFM_PMOPS,
85d6509d 572 },
57ed3314 573 .id_table = imx_esdhc_devtype,
85d6509d 574 .probe = sdhci_esdhc_imx_probe,
0433c143 575 .remove = sdhci_esdhc_imx_remove,
95f25efe 576};
85d6509d 577
d1f81a64 578module_platform_driver(sdhci_esdhc_imx_driver);
85d6509d
SG
579
580MODULE_DESCRIPTION("SDHCI driver for Freescale i.MX eSDHC");
581MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>");
582MODULE_LICENSE("GPL v2");