x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / mmc / host / sdhci-esdhc-imx.c
blobabc8cf01e6e3317ecc3e95d32aa66236def768e9
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/gpio.h>
19 #include <linux/module.h>
20 #include <linux/slab.h>
21 #include <linux/mmc/host.h>
22 #include <linux/mmc/mmc.h>
23 #include <linux/mmc/sdio.h>
24 #include <linux/mmc/slot-gpio.h>
25 #include <linux/of.h>
26 #include <linux/of_device.h>
27 #include <linux/of_gpio.h>
28 #include <linux/pinctrl/consumer.h>
29 #include <linux/platform_data/mmc-esdhc-imx.h>
30 #include "sdhci-pltfm.h"
31 #include "sdhci-esdhc.h"
33 #define ESDHC_CTRL_D3CD 0x08
34 /* VENDOR SPEC register */
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
39 #define ESDHC_MIX_CTRL_AC23EN (1 << 7)
40 /* Bits 3 and 6 are not SDHCI standard definitions */
41 #define ESDHC_MIX_CTRL_SDHCI_MASK 0xb7
44 * Our interpretation of the SDHCI_HOST_CONTROL register
46 #define ESDHC_CTRL_4BITBUS (0x1 << 1)
47 #define ESDHC_CTRL_8BITBUS (0x2 << 1)
48 #define ESDHC_CTRL_BUSWIDTH_MASK (0x3 << 1)
51 * There is an INT DMA ERR mis-match between eSDHC and STD SDHC SPEC:
52 * Bit25 is used in STD SPEC, and is reserved in fsl eSDHC design,
53 * but bit28 is used as the INT DMA ERR in fsl eSDHC design.
54 * Define this macro DMA error INT for fsl eSDHC
56 #define ESDHC_INT_VENDOR_SPEC_DMA_ERR (1 << 28)
59 * The CMDTYPE of the CMD register (offset 0xE) should be set to
60 * "11" when the STOP CMD12 is issued on imx53 to abort one
61 * open ended multi-blk IO. Otherwise the TC INT wouldn't
62 * be generated.
63 * In exact block transfer, the controller doesn't complete the
64 * operations automatically as required at the end of the
65 * transfer and remains on hold if the abort command is not sent.
66 * As a result, the TC flag is not asserted and SW received timeout
67 * exeception. Bit1 of Vendor Spec registor is used to fix it.
69 #define ESDHC_FLAG_MULTIBLK_NO_INT (1 << 1)
71 enum imx_esdhc_type {
72 IMX25_ESDHC,
73 IMX35_ESDHC,
74 IMX51_ESDHC,
75 IMX53_ESDHC,
76 IMX6Q_USDHC,
79 struct pltfm_imx_data {
80 int flags;
81 u32 scratchpad;
82 enum imx_esdhc_type devtype;
83 struct pinctrl *pinctrl;
84 struct esdhc_platform_data boarddata;
85 struct clk *clk_ipg;
86 struct clk *clk_ahb;
87 struct clk *clk_per;
88 enum {
89 NO_CMD_PENDING, /* no multiblock command pending*/
90 MULTIBLK_IN_PROCESS, /* exact multiblock cmd in process */
91 WAIT_FOR_INT, /* sent CMD12, waiting for response INT */
92 } multiblock_status;
96 static struct platform_device_id imx_esdhc_devtype[] = {
98 .name = "sdhci-esdhc-imx25",
99 .driver_data = IMX25_ESDHC,
100 }, {
101 .name = "sdhci-esdhc-imx35",
102 .driver_data = IMX35_ESDHC,
103 }, {
104 .name = "sdhci-esdhc-imx51",
105 .driver_data = IMX51_ESDHC,
106 }, {
107 .name = "sdhci-esdhc-imx53",
108 .driver_data = IMX53_ESDHC,
109 }, {
110 .name = "sdhci-usdhc-imx6q",
111 .driver_data = IMX6Q_USDHC,
112 }, {
113 /* sentinel */
116 MODULE_DEVICE_TABLE(platform, imx_esdhc_devtype);
118 static const struct of_device_id imx_esdhc_dt_ids[] = {
119 { .compatible = "fsl,imx25-esdhc", .data = &imx_esdhc_devtype[IMX25_ESDHC], },
120 { .compatible = "fsl,imx35-esdhc", .data = &imx_esdhc_devtype[IMX35_ESDHC], },
121 { .compatible = "fsl,imx51-esdhc", .data = &imx_esdhc_devtype[IMX51_ESDHC], },
122 { .compatible = "fsl,imx53-esdhc", .data = &imx_esdhc_devtype[IMX53_ESDHC], },
123 { .compatible = "fsl,imx6q-usdhc", .data = &imx_esdhc_devtype[IMX6Q_USDHC], },
124 { /* sentinel */ }
126 MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids);
128 static inline int is_imx25_esdhc(struct pltfm_imx_data *data)
130 return data->devtype == IMX25_ESDHC;
133 static inline int is_imx35_esdhc(struct pltfm_imx_data *data)
135 return data->devtype == IMX35_ESDHC;
138 static inline int is_imx51_esdhc(struct pltfm_imx_data *data)
140 return data->devtype == IMX51_ESDHC;
143 static inline int is_imx53_esdhc(struct pltfm_imx_data *data)
145 return data->devtype == IMX53_ESDHC;
148 static inline int is_imx6q_usdhc(struct pltfm_imx_data *data)
150 return data->devtype == IMX6Q_USDHC;
153 static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, int reg)
155 void __iomem *base = host->ioaddr + (reg & ~0x3);
156 u32 shift = (reg & 0x3) * 8;
158 writel(((readl(base) & ~(mask << shift)) | (val << shift)), base);
161 static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
163 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
164 struct pltfm_imx_data *imx_data = pltfm_host->priv;
165 u32 val = readl(host->ioaddr + reg);
167 if (unlikely(reg == SDHCI_CAPABILITIES)) {
168 /* In FSL esdhc IC module, only bit20 is used to indicate the
169 * ADMA2 capability of esdhc, but this bit is messed up on
170 * some SOCs (e.g. on MX25, MX35 this bit is set, but they
171 * don't actually support ADMA2). So set the BROKEN_ADMA
172 * uirk on MX25/35 platforms.
175 if (val & SDHCI_CAN_DO_ADMA1) {
176 val &= ~SDHCI_CAN_DO_ADMA1;
177 val |= SDHCI_CAN_DO_ADMA2;
181 if (unlikely(reg == SDHCI_INT_STATUS)) {
182 if (val & ESDHC_INT_VENDOR_SPEC_DMA_ERR) {
183 val &= ~ESDHC_INT_VENDOR_SPEC_DMA_ERR;
184 val |= SDHCI_INT_ADMA_ERROR;
188 * mask off the interrupt we get in response to the manually
189 * sent CMD12
191 if ((imx_data->multiblock_status == WAIT_FOR_INT) &&
192 ((val & SDHCI_INT_RESPONSE) == SDHCI_INT_RESPONSE)) {
193 val &= ~SDHCI_INT_RESPONSE;
194 writel(SDHCI_INT_RESPONSE, host->ioaddr +
195 SDHCI_INT_STATUS);
196 imx_data->multiblock_status = NO_CMD_PENDING;
200 return val;
203 static void esdhc_writel_le(struct sdhci_host *host, u32 val, int reg)
205 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
206 struct pltfm_imx_data *imx_data = pltfm_host->priv;
207 u32 data;
209 if (unlikely(reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE)) {
210 if (val & SDHCI_INT_CARD_INT) {
212 * Clear and then set D3CD bit to avoid missing the
213 * card interrupt. This is a eSDHC controller problem
214 * so we need to apply the following workaround: clear
215 * and set D3CD bit will make eSDHC re-sample the card
216 * interrupt. In case a card interrupt was lost,
217 * re-sample it by the following steps.
219 data = readl(host->ioaddr + SDHCI_HOST_CONTROL);
220 data &= ~ESDHC_CTRL_D3CD;
221 writel(data, host->ioaddr + SDHCI_HOST_CONTROL);
222 data |= ESDHC_CTRL_D3CD;
223 writel(data, host->ioaddr + SDHCI_HOST_CONTROL);
227 if (unlikely((imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT)
228 && (reg == SDHCI_INT_STATUS)
229 && (val & SDHCI_INT_DATA_END))) {
230 u32 v;
231 v = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
232 v &= ~ESDHC_VENDOR_SPEC_SDIO_QUIRK;
233 writel(v, host->ioaddr + ESDHC_VENDOR_SPEC);
235 if (imx_data->multiblock_status == MULTIBLK_IN_PROCESS)
237 /* send a manual CMD12 with RESPTYP=none */
238 data = MMC_STOP_TRANSMISSION << 24 |
239 SDHCI_CMD_ABORTCMD << 16;
240 writel(data, host->ioaddr + SDHCI_TRANSFER_MODE);
241 imx_data->multiblock_status = WAIT_FOR_INT;
245 if (unlikely(reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE)) {
246 if (val & SDHCI_INT_ADMA_ERROR) {
247 val &= ~SDHCI_INT_ADMA_ERROR;
248 val |= ESDHC_INT_VENDOR_SPEC_DMA_ERR;
252 writel(val, host->ioaddr + reg);
255 static u16 esdhc_readw_le(struct sdhci_host *host, int reg)
257 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
258 struct pltfm_imx_data *imx_data = pltfm_host->priv;
260 if (unlikely(reg == SDHCI_HOST_VERSION)) {
261 reg ^= 2;
262 if (is_imx6q_usdhc(imx_data)) {
264 * The usdhc register returns a wrong host version.
265 * Correct it here.
267 return SDHCI_SPEC_300;
271 return readw(host->ioaddr + reg);
274 static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
276 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
277 struct pltfm_imx_data *imx_data = pltfm_host->priv;
279 switch (reg) {
280 case SDHCI_TRANSFER_MODE:
281 if ((imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT)
282 && (host->cmd->opcode == SD_IO_RW_EXTENDED)
283 && (host->cmd->data->blocks > 1)
284 && (host->cmd->data->flags & MMC_DATA_READ)) {
285 u32 v;
286 v = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
287 v |= ESDHC_VENDOR_SPEC_SDIO_QUIRK;
288 writel(v, host->ioaddr + ESDHC_VENDOR_SPEC);
291 if (is_imx6q_usdhc(imx_data)) {
292 u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL);
293 /* Swap AC23 bit */
294 if (val & SDHCI_TRNS_AUTO_CMD23) {
295 val &= ~SDHCI_TRNS_AUTO_CMD23;
296 val |= ESDHC_MIX_CTRL_AC23EN;
298 m = val | (m & ~ESDHC_MIX_CTRL_SDHCI_MASK);
299 writel(m, host->ioaddr + ESDHC_MIX_CTRL);
300 } else {
302 * Postpone this write, we must do it together with a
303 * command write that is down below.
305 imx_data->scratchpad = val;
307 return;
308 case SDHCI_COMMAND:
309 if (host->cmd->opcode == MMC_STOP_TRANSMISSION)
310 val |= SDHCI_CMD_ABORTCMD;
312 if ((host->cmd->opcode == MMC_SET_BLOCK_COUNT) &&
313 (imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT))
314 imx_data->multiblock_status = MULTIBLK_IN_PROCESS;
316 if (is_imx6q_usdhc(imx_data))
317 writel(val << 16,
318 host->ioaddr + SDHCI_TRANSFER_MODE);
319 else
320 writel(val << 16 | imx_data->scratchpad,
321 host->ioaddr + SDHCI_TRANSFER_MODE);
322 return;
323 case SDHCI_BLOCK_SIZE:
324 val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
325 break;
327 esdhc_clrset_le(host, 0xffff, val, reg);
330 static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg)
332 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
333 struct pltfm_imx_data *imx_data = pltfm_host->priv;
334 u32 new_val;
335 u32 mask;
337 switch (reg) {
338 case SDHCI_POWER_CONTROL:
340 * FSL put some DMA bits here
341 * If your board has a regulator, code should be here
343 return;
344 case SDHCI_HOST_CONTROL:
345 /* FSL messed up here, so we need to manually compose it. */
346 new_val = val & SDHCI_CTRL_LED;
347 /* ensure the endianness */
348 new_val |= ESDHC_HOST_CONTROL_LE;
349 /* bits 8&9 are reserved on mx25 */
350 if (!is_imx25_esdhc(imx_data)) {
351 /* DMA mode bits are shifted */
352 new_val |= (val & SDHCI_CTRL_DMA_MASK) << 5;
356 * Do not touch buswidth bits here. This is done in
357 * esdhc_pltfm_bus_width.
358 * Do not touch the D3CD bit either which is used for the
359 * SDIO interrupt errata workaround.
361 mask = 0xffff & ~(ESDHC_CTRL_BUSWIDTH_MASK | ESDHC_CTRL_D3CD);
363 esdhc_clrset_le(host, mask, new_val, reg);
364 return;
366 esdhc_clrset_le(host, 0xff, val, reg);
369 * The esdhc has a design violation to SDHC spec which tells
370 * that software reset should not affect card detection circuit.
371 * But esdhc clears its SYSCTL register bits [0..2] during the
372 * software reset. This will stop those clocks that card detection
373 * circuit relies on. To work around it, we turn the clocks on back
374 * to keep card detection circuit functional.
376 if ((reg == SDHCI_SOFTWARE_RESET) && (val & 1)) {
377 esdhc_clrset_le(host, 0x7, 0x7, ESDHC_SYSTEM_CONTROL);
379 * The reset on usdhc fails to clear MIX_CTRL register.
380 * Do it manually here.
382 if (is_imx6q_usdhc(imx_data))
383 writel(0, host->ioaddr + ESDHC_MIX_CTRL);
387 static unsigned int esdhc_pltfm_get_max_clock(struct sdhci_host *host)
389 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
390 struct pltfm_imx_data *imx_data = pltfm_host->priv;
391 struct esdhc_platform_data *boarddata = &imx_data->boarddata;
393 u32 f_host = clk_get_rate(pltfm_host->clk);
395 if (boarddata->f_max && (boarddata->f_max < f_host))
396 return boarddata->f_max;
397 else
398 return f_host;
401 static unsigned int esdhc_pltfm_get_min_clock(struct sdhci_host *host)
403 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
405 return clk_get_rate(pltfm_host->clk) / 256 / 16;
408 static inline void esdhc_pltfm_set_clock(struct sdhci_host *host,
409 unsigned int clock)
411 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
413 esdhc_set_clock(host, clock, clk_get_rate(pltfm_host->clk));
416 static unsigned int esdhc_pltfm_get_ro(struct sdhci_host *host)
418 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
419 struct pltfm_imx_data *imx_data = pltfm_host->priv;
420 struct esdhc_platform_data *boarddata = &imx_data->boarddata;
422 switch (boarddata->wp_type) {
423 case ESDHC_WP_GPIO:
424 return mmc_gpio_get_ro(host->mmc);
425 case ESDHC_WP_CONTROLLER:
426 return !(readl(host->ioaddr + SDHCI_PRESENT_STATE) &
427 SDHCI_WRITE_PROTECT);
428 case ESDHC_WP_NONE:
429 break;
432 return -ENOSYS;
435 static int esdhc_pltfm_bus_width(struct sdhci_host *host, int width)
437 u32 ctrl;
439 switch (width) {
440 case MMC_BUS_WIDTH_8:
441 ctrl = ESDHC_CTRL_8BITBUS;
442 break;
443 case MMC_BUS_WIDTH_4:
444 ctrl = ESDHC_CTRL_4BITBUS;
445 break;
446 default:
447 ctrl = 0;
448 break;
451 esdhc_clrset_le(host, ESDHC_CTRL_BUSWIDTH_MASK, ctrl,
452 SDHCI_HOST_CONTROL);
454 return 0;
457 static const struct sdhci_ops sdhci_esdhc_ops = {
458 .read_l = esdhc_readl_le,
459 .read_w = esdhc_readw_le,
460 .write_l = esdhc_writel_le,
461 .write_w = esdhc_writew_le,
462 .write_b = esdhc_writeb_le,
463 .set_clock = esdhc_pltfm_set_clock,
464 .get_max_clock = esdhc_pltfm_get_max_clock,
465 .get_min_clock = esdhc_pltfm_get_min_clock,
466 .get_ro = esdhc_pltfm_get_ro,
467 .platform_bus_width = esdhc_pltfm_bus_width,
470 static const struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
471 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_NO_HISPD_BIT
472 | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
473 | SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC
474 | SDHCI_QUIRK_BROKEN_CARD_DETECTION,
475 .ops = &sdhci_esdhc_ops,
478 #ifdef CONFIG_OF
479 static int
480 sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
481 struct esdhc_platform_data *boarddata)
483 struct device_node *np = pdev->dev.of_node;
485 if (!np)
486 return -ENODEV;
488 if (of_get_property(np, "non-removable", NULL))
489 boarddata->cd_type = ESDHC_CD_PERMANENT;
491 if (of_get_property(np, "fsl,cd-controller", NULL))
492 boarddata->cd_type = ESDHC_CD_CONTROLLER;
494 if (of_get_property(np, "fsl,wp-controller", NULL))
495 boarddata->wp_type = ESDHC_WP_CONTROLLER;
497 boarddata->cd_gpio = of_get_named_gpio(np, "cd-gpios", 0);
498 if (gpio_is_valid(boarddata->cd_gpio))
499 boarddata->cd_type = ESDHC_CD_GPIO;
501 boarddata->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0);
502 if (gpio_is_valid(boarddata->wp_gpio))
503 boarddata->wp_type = ESDHC_WP_GPIO;
505 of_property_read_u32(np, "bus-width", &boarddata->max_bus_width);
507 of_property_read_u32(np, "max-frequency", &boarddata->f_max);
509 return 0;
511 #else
512 static inline int
513 sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
514 struct esdhc_platform_data *boarddata)
516 return -ENODEV;
518 #endif
520 static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
522 const struct of_device_id *of_id =
523 of_match_device(imx_esdhc_dt_ids, &pdev->dev);
524 struct sdhci_pltfm_host *pltfm_host;
525 struct sdhci_host *host;
526 struct esdhc_platform_data *boarddata;
527 int err;
528 struct pltfm_imx_data *imx_data;
530 host = sdhci_pltfm_init(pdev, &sdhci_esdhc_imx_pdata, 0);
531 if (IS_ERR(host))
532 return PTR_ERR(host);
534 pltfm_host = sdhci_priv(host);
536 imx_data = devm_kzalloc(&pdev->dev, sizeof(*imx_data), GFP_KERNEL);
537 if (!imx_data) {
538 err = -ENOMEM;
539 goto free_sdhci;
542 if (of_id)
543 pdev->id_entry = of_id->data;
544 imx_data->devtype = pdev->id_entry->driver_data;
545 pltfm_host->priv = imx_data;
547 imx_data->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
548 if (IS_ERR(imx_data->clk_ipg)) {
549 err = PTR_ERR(imx_data->clk_ipg);
550 goto free_sdhci;
553 imx_data->clk_ahb = devm_clk_get(&pdev->dev, "ahb");
554 if (IS_ERR(imx_data->clk_ahb)) {
555 err = PTR_ERR(imx_data->clk_ahb);
556 goto free_sdhci;
559 imx_data->clk_per = devm_clk_get(&pdev->dev, "per");
560 if (IS_ERR(imx_data->clk_per)) {
561 err = PTR_ERR(imx_data->clk_per);
562 goto free_sdhci;
565 pltfm_host->clk = imx_data->clk_per;
567 clk_prepare_enable(imx_data->clk_per);
568 clk_prepare_enable(imx_data->clk_ipg);
569 clk_prepare_enable(imx_data->clk_ahb);
571 imx_data->pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
572 if (IS_ERR(imx_data->pinctrl)) {
573 err = PTR_ERR(imx_data->pinctrl);
574 goto disable_clk;
577 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
579 if (is_imx25_esdhc(imx_data) || is_imx35_esdhc(imx_data))
580 /* Fix errata ENGcm07207 present on i.MX25 and i.MX35 */
581 host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK
582 | SDHCI_QUIRK_BROKEN_ADMA;
584 if (is_imx53_esdhc(imx_data))
585 imx_data->flags |= ESDHC_FLAG_MULTIBLK_NO_INT;
588 * The imx6q ROM code will change the default watermark level setting
589 * to something insane. Change it back here.
591 if (is_imx6q_usdhc(imx_data))
592 writel(0x08100810, host->ioaddr + ESDHC_WTMK_LVL);
594 boarddata = &imx_data->boarddata;
595 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
596 if (!host->mmc->parent->platform_data) {
597 dev_err(mmc_dev(host->mmc), "no board data!\n");
598 err = -EINVAL;
599 goto disable_clk;
601 imx_data->boarddata = *((struct esdhc_platform_data *)
602 host->mmc->parent->platform_data);
605 /* write_protect */
606 if (boarddata->wp_type == ESDHC_WP_GPIO) {
607 err = mmc_gpio_request_ro(host->mmc, boarddata->wp_gpio);
608 if (err) {
609 dev_err(mmc_dev(host->mmc),
610 "failed to request write-protect gpio!\n");
611 goto disable_clk;
613 host->mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
616 /* card_detect */
617 switch (boarddata->cd_type) {
618 case ESDHC_CD_GPIO:
619 err = mmc_gpio_request_cd(host->mmc, boarddata->cd_gpio, 0);
620 if (err) {
621 dev_err(mmc_dev(host->mmc),
622 "failed to request card-detect gpio!\n");
623 goto disable_clk;
625 /* fall through */
627 case ESDHC_CD_CONTROLLER:
628 /* we have a working card_detect back */
629 host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
630 break;
632 case ESDHC_CD_PERMANENT:
633 host->mmc->caps = MMC_CAP_NONREMOVABLE;
634 break;
636 case ESDHC_CD_NONE:
637 break;
640 switch (boarddata->max_bus_width) {
641 case 8:
642 host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_4_BIT_DATA;
643 break;
644 case 4:
645 host->mmc->caps |= MMC_CAP_4_BIT_DATA;
646 break;
647 case 1:
648 default:
649 host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA;
650 break;
653 err = sdhci_add_host(host);
654 if (err)
655 goto disable_clk;
657 return 0;
659 disable_clk:
660 clk_disable_unprepare(imx_data->clk_per);
661 clk_disable_unprepare(imx_data->clk_ipg);
662 clk_disable_unprepare(imx_data->clk_ahb);
663 free_sdhci:
664 sdhci_pltfm_free(pdev);
665 return err;
668 static int sdhci_esdhc_imx_remove(struct platform_device *pdev)
670 struct sdhci_host *host = platform_get_drvdata(pdev);
671 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
672 struct pltfm_imx_data *imx_data = pltfm_host->priv;
673 int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
675 sdhci_remove_host(host, dead);
677 clk_disable_unprepare(imx_data->clk_per);
678 clk_disable_unprepare(imx_data->clk_ipg);
679 clk_disable_unprepare(imx_data->clk_ahb);
681 sdhci_pltfm_free(pdev);
683 return 0;
686 static struct platform_driver sdhci_esdhc_imx_driver = {
687 .driver = {
688 .name = "sdhci-esdhc-imx",
689 .owner = THIS_MODULE,
690 .of_match_table = imx_esdhc_dt_ids,
691 .pm = SDHCI_PLTFM_PMOPS,
693 .id_table = imx_esdhc_devtype,
694 .probe = sdhci_esdhc_imx_probe,
695 .remove = sdhci_esdhc_imx_remove,
698 module_platform_driver(sdhci_esdhc_imx_driver);
700 MODULE_DESCRIPTION("SDHCI driver for Freescale i.MX eSDHC");
701 MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>");
702 MODULE_LICENSE("GPL v2");