pxamci.c 16 KB

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