pxamci.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /*
  2. * linux/drivers/mmc/host/pxa.c - PXA MMCI driver
  3. *
  4. * Copyright (C) 2003 Russell King, All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This hardware is really sick:
  11. * - No way to clear interrupts.
  12. * - Have to turn off the clock whenever we touch the device.
  13. * - Doesn't tell you how many data blocks were transferred.
  14. * Yuck!
  15. *
  16. * 1 and 3 byte data transfers not supported
  17. * max block length up to 1023
  18. */
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/ioport.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/delay.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/clk.h>
  27. #include <linux/err.h>
  28. #include <linux/mmc/host.h>
  29. #include <linux/io.h>
  30. #include <asm/sizes.h>
  31. #include <mach/dma.h>
  32. #include <mach/hardware.h>
  33. #include <mach/pxa-regs.h>
  34. #include <mach/mmc.h>
  35. #include "pxamci.h"
  36. #define DRIVER_NAME "pxa2xx-mci"
  37. #define NR_SG 1
  38. #define CLKRT_OFF (~0)
  39. struct pxamci_host {
  40. struct mmc_host *mmc;
  41. spinlock_t lock;
  42. struct resource *res;
  43. void __iomem *base;
  44. struct clk *clk;
  45. unsigned long clkrate;
  46. int irq;
  47. int dma;
  48. unsigned int clkrt;
  49. unsigned int cmdat;
  50. unsigned int imask;
  51. unsigned int power_mode;
  52. struct pxamci_platform_data *pdata;
  53. struct mmc_request *mrq;
  54. struct mmc_command *cmd;
  55. struct mmc_data *data;
  56. dma_addr_t sg_dma;
  57. struct pxa_dma_desc *sg_cpu;
  58. unsigned int dma_len;
  59. unsigned int dma_dir;
  60. unsigned int dma_drcmrrx;
  61. unsigned int dma_drcmrtx;
  62. };
  63. static void pxamci_stop_clock(struct pxamci_host *host)
  64. {
  65. if (readl(host->base + MMC_STAT) & STAT_CLK_EN) {
  66. unsigned long timeout = 10000;
  67. unsigned int v;
  68. writel(STOP_CLOCK, host->base + MMC_STRPCL);
  69. do {
  70. v = readl(host->base + MMC_STAT);
  71. if (!(v & STAT_CLK_EN))
  72. break;
  73. udelay(1);
  74. } while (timeout--);
  75. if (v & STAT_CLK_EN)
  76. dev_err(mmc_dev(host->mmc), "unable to stop clock\n");
  77. }
  78. }
  79. static void pxamci_enable_irq(struct pxamci_host *host, unsigned int mask)
  80. {
  81. unsigned long flags;
  82. spin_lock_irqsave(&host->lock, flags);
  83. host->imask &= ~mask;
  84. writel(host->imask, host->base + MMC_I_MASK);
  85. spin_unlock_irqrestore(&host->lock, flags);
  86. }
  87. static void pxamci_disable_irq(struct pxamci_host *host, unsigned int mask)
  88. {
  89. unsigned long flags;
  90. spin_lock_irqsave(&host->lock, flags);
  91. host->imask |= mask;
  92. writel(host->imask, host->base + MMC_I_MASK);
  93. spin_unlock_irqrestore(&host->lock, flags);
  94. }
  95. static void pxamci_setup_data(struct pxamci_host *host, struct mmc_data *data)
  96. {
  97. unsigned int nob = data->blocks;
  98. unsigned long long clks;
  99. unsigned int timeout;
  100. bool dalgn = 0;
  101. u32 dcmd;
  102. int i;
  103. host->data = data;
  104. if (data->flags & MMC_DATA_STREAM)
  105. nob = 0xffff;
  106. writel(nob, host->base + MMC_NOB);
  107. writel(data->blksz, host->base + MMC_BLKLEN);
  108. clks = (unsigned long long)data->timeout_ns * host->clkrate;
  109. do_div(clks, 1000000000UL);
  110. timeout = (unsigned int)clks + (data->timeout_clks << host->clkrt);
  111. writel((timeout + 255) / 256, host->base + MMC_RDTO);
  112. if (data->flags & MMC_DATA_READ) {
  113. host->dma_dir = DMA_FROM_DEVICE;
  114. dcmd = DCMD_INCTRGADDR | DCMD_FLOWTRG;
  115. DRCMR(host->dma_drcmrtx) = 0;
  116. DRCMR(host->dma_drcmrrx) = host->dma | DRCMR_MAPVLD;
  117. } else {
  118. host->dma_dir = DMA_TO_DEVICE;
  119. dcmd = DCMD_INCSRCADDR | DCMD_FLOWSRC;
  120. DRCMR(host->dma_drcmrrx) = 0;
  121. DRCMR(host->dma_drcmrtx) = host->dma | DRCMR_MAPVLD;
  122. }
  123. dcmd |= DCMD_BURST32 | DCMD_WIDTH1;
  124. host->dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg, data->sg_len,
  125. host->dma_dir);
  126. for (i = 0; i < host->dma_len; i++) {
  127. unsigned int length = sg_dma_len(&data->sg[i]);
  128. host->sg_cpu[i].dcmd = dcmd | length;
  129. if (length & 31 && !(data->flags & MMC_DATA_READ))
  130. host->sg_cpu[i].dcmd |= DCMD_ENDIRQEN;
  131. /* Not aligned to 8-byte boundary? */
  132. if (sg_dma_address(&data->sg[i]) & 0x7)
  133. dalgn = 1;
  134. if (data->flags & MMC_DATA_READ) {
  135. host->sg_cpu[i].dsadr = host->res->start + MMC_RXFIFO;
  136. host->sg_cpu[i].dtadr = sg_dma_address(&data->sg[i]);
  137. } else {
  138. host->sg_cpu[i].dsadr = sg_dma_address(&data->sg[i]);
  139. host->sg_cpu[i].dtadr = host->res->start + MMC_TXFIFO;
  140. }
  141. host->sg_cpu[i].ddadr = host->sg_dma + (i + 1) *
  142. sizeof(struct pxa_dma_desc);
  143. }
  144. host->sg_cpu[host->dma_len - 1].ddadr = DDADR_STOP;
  145. wmb();
  146. /*
  147. * The PXA27x DMA controller encounters overhead when working with
  148. * unaligned (to 8-byte boundaries) data, so switch on byte alignment
  149. * mode only if we have unaligned data.
  150. */
  151. if (dalgn)
  152. DALGN |= (1 << host->dma);
  153. else
  154. DALGN &= ~(1 << host->dma);
  155. DDADR(host->dma) = host->sg_dma;
  156. DCSR(host->dma) = DCSR_RUN;
  157. }
  158. static void pxamci_start_cmd(struct pxamci_host *host, struct mmc_command *cmd, unsigned int cmdat)
  159. {
  160. WARN_ON(host->cmd != NULL);
  161. host->cmd = cmd;
  162. if (cmd->flags & MMC_RSP_BUSY)
  163. cmdat |= CMDAT_BUSY;
  164. #define RSP_TYPE(x) ((x) & ~(MMC_RSP_BUSY|MMC_RSP_OPCODE))
  165. switch (RSP_TYPE(mmc_resp_type(cmd))) {
  166. case RSP_TYPE(MMC_RSP_R1): /* r1, r1b, r6, r7 */
  167. cmdat |= CMDAT_RESP_SHORT;
  168. break;
  169. case RSP_TYPE(MMC_RSP_R3):
  170. cmdat |= CMDAT_RESP_R3;
  171. break;
  172. case RSP_TYPE(MMC_RSP_R2):
  173. cmdat |= CMDAT_RESP_R2;
  174. break;
  175. default:
  176. break;
  177. }
  178. writel(cmd->opcode, host->base + MMC_CMD);
  179. writel(cmd->arg >> 16, host->base + MMC_ARGH);
  180. writel(cmd->arg & 0xffff, host->base + MMC_ARGL);
  181. writel(cmdat, host->base + MMC_CMDAT);
  182. writel(host->clkrt, host->base + MMC_CLKRT);
  183. writel(START_CLOCK, host->base + MMC_STRPCL);
  184. pxamci_enable_irq(host, END_CMD_RES);
  185. }
  186. static void pxamci_finish_request(struct pxamci_host *host, struct mmc_request *mrq)
  187. {
  188. host->mrq = NULL;
  189. host->cmd = NULL;
  190. host->data = NULL;
  191. mmc_request_done(host->mmc, mrq);
  192. }
  193. static int pxamci_cmd_done(struct pxamci_host *host, unsigned int stat)
  194. {
  195. struct mmc_command *cmd = host->cmd;
  196. int i;
  197. u32 v;
  198. if (!cmd)
  199. return 0;
  200. host->cmd = NULL;
  201. /*
  202. * Did I mention this is Sick. We always need to
  203. * discard the upper 8 bits of the first 16-bit word.
  204. */
  205. v = readl(host->base + MMC_RES) & 0xffff;
  206. for (i = 0; i < 4; i++) {
  207. u32 w1 = readl(host->base + MMC_RES) & 0xffff;
  208. u32 w2 = readl(host->base + MMC_RES) & 0xffff;
  209. cmd->resp[i] = v << 24 | w1 << 8 | w2 >> 8;
  210. v = w2;
  211. }
  212. if (stat & STAT_TIME_OUT_RESPONSE) {
  213. cmd->error = -ETIMEDOUT;
  214. } else if (stat & STAT_RES_CRC_ERR && cmd->flags & MMC_RSP_CRC) {
  215. #ifdef CONFIG_PXA27x
  216. /*
  217. * workaround for erratum #42:
  218. * Intel PXA27x Family Processor Specification Update Rev 001
  219. * A bogus CRC error can appear if the msb of a 136 bit
  220. * response is a one.
  221. */
  222. if (cmd->flags & MMC_RSP_136 && cmd->resp[0] & 0x80000000) {
  223. pr_debug("ignoring CRC from command %d - *risky*\n", cmd->opcode);
  224. } else
  225. #endif
  226. cmd->error = -EILSEQ;
  227. }
  228. pxamci_disable_irq(host, END_CMD_RES);
  229. if (host->data && !cmd->error) {
  230. pxamci_enable_irq(host, DATA_TRAN_DONE);
  231. } else {
  232. pxamci_finish_request(host, host->mrq);
  233. }
  234. return 1;
  235. }
  236. static int pxamci_data_done(struct pxamci_host *host, unsigned int stat)
  237. {
  238. struct mmc_data *data = host->data;
  239. if (!data)
  240. return 0;
  241. DCSR(host->dma) = 0;
  242. dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len,
  243. host->dma_dir);
  244. if (stat & STAT_READ_TIME_OUT)
  245. data->error = -ETIMEDOUT;
  246. else if (stat & (STAT_CRC_READ_ERROR|STAT_CRC_WRITE_ERROR))
  247. data->error = -EILSEQ;
  248. /*
  249. * There appears to be a hardware design bug here. There seems to
  250. * be no way to find out how much data was transferred to the card.
  251. * This means that if there was an error on any block, we mark all
  252. * data blocks as being in error.
  253. */
  254. if (!data->error)
  255. data->bytes_xfered = data->blocks * data->blksz;
  256. else
  257. data->bytes_xfered = 0;
  258. pxamci_disable_irq(host, DATA_TRAN_DONE);
  259. host->data = NULL;
  260. if (host->mrq->stop) {
  261. pxamci_stop_clock(host);
  262. pxamci_start_cmd(host, host->mrq->stop, host->cmdat);
  263. } else {
  264. pxamci_finish_request(host, host->mrq);
  265. }
  266. return 1;
  267. }
  268. static irqreturn_t pxamci_irq(int irq, void *devid)
  269. {
  270. struct pxamci_host *host = devid;
  271. unsigned int ireg;
  272. int handled = 0;
  273. ireg = readl(host->base + MMC_I_REG) & ~readl(host->base + MMC_I_MASK);
  274. if (ireg) {
  275. unsigned stat = readl(host->base + MMC_STAT);
  276. pr_debug("PXAMCI: irq %08x stat %08x\n", ireg, stat);
  277. if (ireg & END_CMD_RES)
  278. handled |= pxamci_cmd_done(host, stat);
  279. if (ireg & DATA_TRAN_DONE)
  280. handled |= pxamci_data_done(host, stat);
  281. if (ireg & SDIO_INT) {
  282. mmc_signal_sdio_irq(host->mmc);
  283. handled = 1;
  284. }
  285. }
  286. return IRQ_RETVAL(handled);
  287. }
  288. static void pxamci_request(struct mmc_host *mmc, struct mmc_request *mrq)
  289. {
  290. struct pxamci_host *host = mmc_priv(mmc);
  291. unsigned int cmdat;
  292. WARN_ON(host->mrq != NULL);
  293. host->mrq = mrq;
  294. pxamci_stop_clock(host);
  295. cmdat = host->cmdat;
  296. host->cmdat &= ~CMDAT_INIT;
  297. if (mrq->data) {
  298. pxamci_setup_data(host, mrq->data);
  299. cmdat &= ~CMDAT_BUSY;
  300. cmdat |= CMDAT_DATAEN | CMDAT_DMAEN;
  301. if (mrq->data->flags & MMC_DATA_WRITE)
  302. cmdat |= CMDAT_WRITE;
  303. if (mrq->data->flags & MMC_DATA_STREAM)
  304. cmdat |= CMDAT_STREAM;
  305. }
  306. pxamci_start_cmd(host, mrq->cmd, cmdat);
  307. }
  308. static int pxamci_get_ro(struct mmc_host *mmc)
  309. {
  310. struct pxamci_host *host = mmc_priv(mmc);
  311. if (host->pdata && host->pdata->get_ro)
  312. return !!host->pdata->get_ro(mmc_dev(mmc));
  313. /*
  314. * Board doesn't support read only detection; let the mmc core
  315. * decide what to do.
  316. */
  317. return -ENOSYS;
  318. }
  319. static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  320. {
  321. struct pxamci_host *host = mmc_priv(mmc);
  322. if (ios->clock) {
  323. unsigned long rate = host->clkrate;
  324. unsigned int clk = rate / ios->clock;
  325. if (host->clkrt == CLKRT_OFF)
  326. clk_enable(host->clk);
  327. if (ios->clock == 26000000) {
  328. /* to support 26MHz on pxa300/pxa310 */
  329. host->clkrt = 7;
  330. } else {
  331. /* to handle (19.5MHz, 26MHz) */
  332. if (!clk)
  333. clk = 1;
  334. /*
  335. * clk might result in a lower divisor than we
  336. * desire. check for that condition and adjust
  337. * as appropriate.
  338. */
  339. if (rate / clk > ios->clock)
  340. clk <<= 1;
  341. host->clkrt = fls(clk) - 1;
  342. }
  343. /*
  344. * we write clkrt on the next command
  345. */
  346. } else {
  347. pxamci_stop_clock(host);
  348. if (host->clkrt != CLKRT_OFF) {
  349. host->clkrt = CLKRT_OFF;
  350. clk_disable(host->clk);
  351. }
  352. }
  353. if (host->power_mode != ios->power_mode) {
  354. host->power_mode = ios->power_mode;
  355. if (host->pdata && host->pdata->setpower)
  356. host->pdata->setpower(mmc_dev(mmc), ios->vdd);
  357. if (ios->power_mode == MMC_POWER_ON)
  358. host->cmdat |= CMDAT_INIT;
  359. }
  360. if (ios->bus_width == MMC_BUS_WIDTH_4)
  361. host->cmdat |= CMDAT_SD_4DAT;
  362. else
  363. host->cmdat &= ~CMDAT_SD_4DAT;
  364. pr_debug("PXAMCI: clkrt = %x cmdat = %x\n",
  365. host->clkrt, host->cmdat);
  366. }
  367. static void pxamci_enable_sdio_irq(struct mmc_host *host, int enable)
  368. {
  369. struct pxamci_host *pxa_host = mmc_priv(host);
  370. if (enable)
  371. pxamci_enable_irq(pxa_host, SDIO_INT);
  372. else
  373. pxamci_disable_irq(pxa_host, SDIO_INT);
  374. }
  375. static const struct mmc_host_ops pxamci_ops = {
  376. .request = pxamci_request,
  377. .get_ro = pxamci_get_ro,
  378. .set_ios = pxamci_set_ios,
  379. .enable_sdio_irq = pxamci_enable_sdio_irq,
  380. };
  381. static void pxamci_dma_irq(int dma, void *devid)
  382. {
  383. struct pxamci_host *host = devid;
  384. int dcsr = DCSR(dma);
  385. DCSR(dma) = dcsr & ~DCSR_STOPIRQEN;
  386. if (dcsr & DCSR_ENDINTR) {
  387. writel(BUF_PART_FULL, host->base + MMC_PRTBUF);
  388. } else {
  389. printk(KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n",
  390. mmc_hostname(host->mmc), dma, dcsr);
  391. host->data->error = -EIO;
  392. pxamci_data_done(host, 0);
  393. }
  394. }
  395. static irqreturn_t pxamci_detect_irq(int irq, void *devid)
  396. {
  397. struct pxamci_host *host = mmc_priv(devid);
  398. mmc_detect_change(devid, host->pdata->detect_delay);
  399. return IRQ_HANDLED;
  400. }
  401. static int pxamci_probe(struct platform_device *pdev)
  402. {
  403. struct mmc_host *mmc;
  404. struct pxamci_host *host = NULL;
  405. struct resource *r, *dmarx, *dmatx;
  406. int ret, irq;
  407. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  408. irq = platform_get_irq(pdev, 0);
  409. if (!r || irq < 0)
  410. return -ENXIO;
  411. r = request_mem_region(r->start, SZ_4K, DRIVER_NAME);
  412. if (!r)
  413. return -EBUSY;
  414. mmc = mmc_alloc_host(sizeof(struct pxamci_host), &pdev->dev);
  415. if (!mmc) {
  416. ret = -ENOMEM;
  417. goto out;
  418. }
  419. mmc->ops = &pxamci_ops;
  420. /*
  421. * We can do SG-DMA, but we don't because we never know how much
  422. * data we successfully wrote to the card.
  423. */
  424. mmc->max_phys_segs = NR_SG;
  425. /*
  426. * Our hardware DMA can handle a maximum of one page per SG entry.
  427. */
  428. mmc->max_seg_size = PAGE_SIZE;
  429. /*
  430. * Block length register is only 10 bits before PXA27x.
  431. */
  432. mmc->max_blk_size = cpu_is_pxa25x() ? 1023 : 2048;
  433. /*
  434. * Block count register is 16 bits.
  435. */
  436. mmc->max_blk_count = 65535;
  437. host = mmc_priv(mmc);
  438. host->mmc = mmc;
  439. host->dma = -1;
  440. host->pdata = pdev->dev.platform_data;
  441. host->clkrt = CLKRT_OFF;
  442. host->clk = clk_get(&pdev->dev, NULL);
  443. if (IS_ERR(host->clk)) {
  444. ret = PTR_ERR(host->clk);
  445. host->clk = NULL;
  446. goto out;
  447. }
  448. host->clkrate = clk_get_rate(host->clk);
  449. /*
  450. * Calculate minimum clock rate, rounding up.
  451. */
  452. mmc->f_min = (host->clkrate + 63) / 64;
  453. mmc->f_max = (cpu_is_pxa300() || cpu_is_pxa310()) ? 26000000
  454. : host->clkrate;
  455. mmc->ocr_avail = host->pdata ?
  456. host->pdata->ocr_mask :
  457. MMC_VDD_32_33|MMC_VDD_33_34;
  458. mmc->caps = 0;
  459. host->cmdat = 0;
  460. if (!cpu_is_pxa25x()) {
  461. mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ;
  462. host->cmdat |= CMDAT_SDIO_INT_EN;
  463. if (cpu_is_pxa300() || cpu_is_pxa310())
  464. mmc->caps |= MMC_CAP_MMC_HIGHSPEED |
  465. MMC_CAP_SD_HIGHSPEED;
  466. }
  467. host->sg_cpu = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, &host->sg_dma, GFP_KERNEL);
  468. if (!host->sg_cpu) {
  469. ret = -ENOMEM;
  470. goto out;
  471. }
  472. spin_lock_init(&host->lock);
  473. host->res = r;
  474. host->irq = irq;
  475. host->imask = MMC_I_MASK_ALL;
  476. host->base = ioremap(r->start, SZ_4K);
  477. if (!host->base) {
  478. ret = -ENOMEM;
  479. goto out;
  480. }
  481. /*
  482. * Ensure that the host controller is shut down, and setup
  483. * with our defaults.
  484. */
  485. pxamci_stop_clock(host);
  486. writel(0, host->base + MMC_SPI);
  487. writel(64, host->base + MMC_RESTO);
  488. writel(host->imask, host->base + MMC_I_MASK);
  489. host->dma = pxa_request_dma(DRIVER_NAME, DMA_PRIO_LOW,
  490. pxamci_dma_irq, host);
  491. if (host->dma < 0) {
  492. ret = -EBUSY;
  493. goto out;
  494. }
  495. ret = request_irq(host->irq, pxamci_irq, 0, DRIVER_NAME, host);
  496. if (ret)
  497. goto out;
  498. platform_set_drvdata(pdev, mmc);
  499. dmarx = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  500. if (!dmarx) {
  501. ret = -ENXIO;
  502. goto out;
  503. }
  504. host->dma_drcmrrx = dmarx->start;
  505. dmatx = platform_get_resource(pdev, IORESOURCE_DMA, 1);
  506. if (!dmatx) {
  507. ret = -ENXIO;
  508. goto out;
  509. }
  510. host->dma_drcmrtx = dmatx->start;
  511. if (host->pdata && host->pdata->init)
  512. host->pdata->init(&pdev->dev, pxamci_detect_irq, mmc);
  513. mmc_add_host(mmc);
  514. return 0;
  515. out:
  516. if (host) {
  517. if (host->dma >= 0)
  518. pxa_free_dma(host->dma);
  519. if (host->base)
  520. iounmap(host->base);
  521. if (host->sg_cpu)
  522. dma_free_coherent(&pdev->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma);
  523. if (host->clk)
  524. clk_put(host->clk);
  525. }
  526. if (mmc)
  527. mmc_free_host(mmc);
  528. release_resource(r);
  529. return ret;
  530. }
  531. static int pxamci_remove(struct platform_device *pdev)
  532. {
  533. struct mmc_host *mmc = platform_get_drvdata(pdev);
  534. platform_set_drvdata(pdev, NULL);
  535. if (mmc) {
  536. struct pxamci_host *host = mmc_priv(mmc);
  537. if (host->pdata && host->pdata->exit)
  538. host->pdata->exit(&pdev->dev, mmc);
  539. mmc_remove_host(mmc);
  540. pxamci_stop_clock(host);
  541. writel(TXFIFO_WR_REQ|RXFIFO_RD_REQ|CLK_IS_OFF|STOP_CMD|
  542. END_CMD_RES|PRG_DONE|DATA_TRAN_DONE,
  543. host->base + MMC_I_MASK);
  544. DRCMR(host->dma_drcmrrx) = 0;
  545. DRCMR(host->dma_drcmrtx) = 0;
  546. free_irq(host->irq, host);
  547. pxa_free_dma(host->dma);
  548. iounmap(host->base);
  549. dma_free_coherent(&pdev->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma);
  550. clk_put(host->clk);
  551. release_resource(host->res);
  552. mmc_free_host(mmc);
  553. }
  554. return 0;
  555. }
  556. #ifdef CONFIG_PM
  557. static int pxamci_suspend(struct platform_device *dev, pm_message_t state)
  558. {
  559. struct mmc_host *mmc = platform_get_drvdata(dev);
  560. int ret = 0;
  561. if (mmc)
  562. ret = mmc_suspend_host(mmc, state);
  563. return ret;
  564. }
  565. static int pxamci_resume(struct platform_device *dev)
  566. {
  567. struct mmc_host *mmc = platform_get_drvdata(dev);
  568. int ret = 0;
  569. if (mmc)
  570. ret = mmc_resume_host(mmc);
  571. return ret;
  572. }
  573. #else
  574. #define pxamci_suspend NULL
  575. #define pxamci_resume NULL
  576. #endif
  577. static struct platform_driver pxamci_driver = {
  578. .probe = pxamci_probe,
  579. .remove = pxamci_remove,
  580. .suspend = pxamci_suspend,
  581. .resume = pxamci_resume,
  582. .driver = {
  583. .name = DRIVER_NAME,
  584. .owner = THIS_MODULE,
  585. },
  586. };
  587. static int __init pxamci_init(void)
  588. {
  589. return platform_driver_register(&pxamci_driver);
  590. }
  591. static void __exit pxamci_exit(void)
  592. {
  593. platform_driver_unregister(&pxamci_driver);
  594. }
  595. module_init(pxamci_init);
  596. module_exit(pxamci_exit);
  597. MODULE_DESCRIPTION("PXA Multimedia Card Interface Driver");
  598. MODULE_LICENSE("GPL");
  599. MODULE_ALIAS("platform:pxa2xx-mci");