pxamci.c 17 KB

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