sdhci-esdhc-imx.c 17 KB

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