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