pxamci.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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. 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. /* Host doesn't support read only detection so assume writeable */
  313. return 0;
  314. }
  315. static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  316. {
  317. struct pxamci_host *host = mmc_priv(mmc);
  318. if (ios->clock) {
  319. unsigned long rate = host->clkrate;
  320. unsigned int clk = rate / ios->clock;
  321. if (host->clkrt == CLKRT_OFF)
  322. clk_enable(host->clk);
  323. if (ios->clock == 26000000) {
  324. /* to support 26MHz on pxa300/pxa310 */
  325. host->clkrt = 7;
  326. } else {
  327. /* to handle (19.5MHz, 26MHz) */
  328. if (!clk)
  329. clk = 1;
  330. /*
  331. * clk might result in a lower divisor than we
  332. * desire. check for that condition and adjust
  333. * as appropriate.
  334. */
  335. if (rate / clk > ios->clock)
  336. clk <<= 1;
  337. host->clkrt = fls(clk) - 1;
  338. }
  339. /*
  340. * we write clkrt on the next command
  341. */
  342. } else {
  343. pxamci_stop_clock(host);
  344. if (host->clkrt != CLKRT_OFF) {
  345. host->clkrt = CLKRT_OFF;
  346. clk_disable(host->clk);
  347. }
  348. }
  349. if (host->power_mode != ios->power_mode) {
  350. host->power_mode = ios->power_mode;
  351. if (host->pdata && host->pdata->setpower)
  352. host->pdata->setpower(mmc_dev(mmc), ios->vdd);
  353. if (ios->power_mode == MMC_POWER_ON)
  354. host->cmdat |= CMDAT_INIT;
  355. }
  356. if (ios->bus_width == MMC_BUS_WIDTH_4)
  357. host->cmdat |= CMDAT_SD_4DAT;
  358. else
  359. host->cmdat &= ~CMDAT_SD_4DAT;
  360. pr_debug("PXAMCI: clkrt = %x cmdat = %x\n",
  361. host->clkrt, host->cmdat);
  362. }
  363. static void pxamci_enable_sdio_irq(struct mmc_host *host, int enable)
  364. {
  365. struct pxamci_host *pxa_host = mmc_priv(host);
  366. if (enable)
  367. pxamci_enable_irq(pxa_host, SDIO_INT);
  368. else
  369. pxamci_disable_irq(pxa_host, SDIO_INT);
  370. }
  371. static const struct mmc_host_ops pxamci_ops = {
  372. .request = pxamci_request,
  373. .get_ro = pxamci_get_ro,
  374. .set_ios = pxamci_set_ios,
  375. .enable_sdio_irq = pxamci_enable_sdio_irq,
  376. };
  377. static void pxamci_dma_irq(int dma, void *devid)
  378. {
  379. struct pxamci_host *host = devid;
  380. int dcsr = DCSR(dma);
  381. DCSR(dma) = dcsr & ~DCSR_STOPIRQEN;
  382. if (dcsr & DCSR_ENDINTR) {
  383. writel(BUF_PART_FULL, host->base + MMC_PRTBUF);
  384. } else {
  385. printk(KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n",
  386. mmc_hostname(host->mmc), dma, dcsr);
  387. host->data->error = -EIO;
  388. pxamci_data_done(host, 0);
  389. }
  390. }
  391. static irqreturn_t pxamci_detect_irq(int irq, void *devid)
  392. {
  393. struct pxamci_host *host = mmc_priv(devid);
  394. mmc_detect_change(devid, host->pdata->detect_delay);
  395. return IRQ_HANDLED;
  396. }
  397. static int pxamci_probe(struct platform_device *pdev)
  398. {
  399. struct mmc_host *mmc;
  400. struct pxamci_host *host = NULL;
  401. struct resource *r, *dmarx, *dmatx;
  402. int ret, irq;
  403. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  404. irq = platform_get_irq(pdev, 0);
  405. if (!r || irq < 0)
  406. return -ENXIO;
  407. r = request_mem_region(r->start, SZ_4K, DRIVER_NAME);
  408. if (!r)
  409. return -EBUSY;
  410. mmc = mmc_alloc_host(sizeof(struct pxamci_host), &pdev->dev);
  411. if (!mmc) {
  412. ret = -ENOMEM;
  413. goto out;
  414. }
  415. mmc->ops = &pxamci_ops;
  416. /*
  417. * We can do SG-DMA, but we don't because we never know how much
  418. * data we successfully wrote to the card.
  419. */
  420. mmc->max_phys_segs = NR_SG;
  421. /*
  422. * Our hardware DMA can handle a maximum of one page per SG entry.
  423. */
  424. mmc->max_seg_size = PAGE_SIZE;
  425. /*
  426. * Block length register is only 10 bits before PXA27x.
  427. */
  428. mmc->max_blk_size = (cpu_is_pxa21x() || cpu_is_pxa25x()) ? 1023 : 2048;
  429. /*
  430. * Block count register is 16 bits.
  431. */
  432. mmc->max_blk_count = 65535;
  433. host = mmc_priv(mmc);
  434. host->mmc = mmc;
  435. host->dma = -1;
  436. host->pdata = pdev->dev.platform_data;
  437. host->clkrt = CLKRT_OFF;
  438. host->clk = clk_get(&pdev->dev, "MMCCLK");
  439. if (IS_ERR(host->clk)) {
  440. ret = PTR_ERR(host->clk);
  441. host->clk = NULL;
  442. goto out;
  443. }
  444. host->clkrate = clk_get_rate(host->clk);
  445. /*
  446. * Calculate minimum clock rate, rounding up.
  447. */
  448. mmc->f_min = (host->clkrate + 63) / 64;
  449. mmc->f_max = (cpu_is_pxa300() || cpu_is_pxa310()) ? 26000000
  450. : host->clkrate;
  451. mmc->ocr_avail = host->pdata ?
  452. host->pdata->ocr_mask :
  453. MMC_VDD_32_33|MMC_VDD_33_34;
  454. mmc->caps = 0;
  455. host->cmdat = 0;
  456. if (!cpu_is_pxa21x() && !cpu_is_pxa25x()) {
  457. mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ;
  458. host->cmdat |= CMDAT_SDIO_INT_EN;
  459. if (cpu_is_pxa300() || cpu_is_pxa310())
  460. mmc->caps |= MMC_CAP_MMC_HIGHSPEED |
  461. MMC_CAP_SD_HIGHSPEED;
  462. }
  463. host->sg_cpu = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, &host->sg_dma, GFP_KERNEL);
  464. if (!host->sg_cpu) {
  465. ret = -ENOMEM;
  466. goto out;
  467. }
  468. spin_lock_init(&host->lock);
  469. host->res = r;
  470. host->irq = irq;
  471. host->imask = MMC_I_MASK_ALL;
  472. host->base = ioremap(r->start, SZ_4K);
  473. if (!host->base) {
  474. ret = -ENOMEM;
  475. goto out;
  476. }
  477. /*
  478. * Ensure that the host controller is shut down, and setup
  479. * with our defaults.
  480. */
  481. pxamci_stop_clock(host);
  482. writel(0, host->base + MMC_SPI);
  483. writel(64, host->base + MMC_RESTO);
  484. writel(host->imask, host->base + MMC_I_MASK);
  485. host->dma = pxa_request_dma(DRIVER_NAME, DMA_PRIO_LOW,
  486. pxamci_dma_irq, host);
  487. if (host->dma < 0) {
  488. ret = -EBUSY;
  489. goto out;
  490. }
  491. ret = request_irq(host->irq, pxamci_irq, 0, DRIVER_NAME, host);
  492. if (ret)
  493. goto out;
  494. platform_set_drvdata(pdev, mmc);
  495. dmarx = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  496. if (!dmarx) {
  497. ret = -ENXIO;
  498. goto out;
  499. }
  500. host->dma_drcmrrx = dmarx->start;
  501. dmatx = platform_get_resource(pdev, IORESOURCE_DMA, 1);
  502. if (!dmatx) {
  503. ret = -ENXIO;
  504. goto out;
  505. }
  506. host->dma_drcmrtx = dmatx->start;
  507. if (host->pdata && host->pdata->init)
  508. host->pdata->init(&pdev->dev, pxamci_detect_irq, mmc);
  509. mmc_add_host(mmc);
  510. return 0;
  511. out:
  512. if (host) {
  513. if (host->dma >= 0)
  514. pxa_free_dma(host->dma);
  515. if (host->base)
  516. iounmap(host->base);
  517. if (host->sg_cpu)
  518. dma_free_coherent(&pdev->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma);
  519. if (host->clk)
  520. clk_put(host->clk);
  521. }
  522. if (mmc)
  523. mmc_free_host(mmc);
  524. release_resource(r);
  525. return ret;
  526. }
  527. static int pxamci_remove(struct platform_device *pdev)
  528. {
  529. struct mmc_host *mmc = platform_get_drvdata(pdev);
  530. platform_set_drvdata(pdev, NULL);
  531. if (mmc) {
  532. struct pxamci_host *host = mmc_priv(mmc);
  533. if (host->pdata && host->pdata->exit)
  534. host->pdata->exit(&pdev->dev, mmc);
  535. mmc_remove_host(mmc);
  536. pxamci_stop_clock(host);
  537. writel(TXFIFO_WR_REQ|RXFIFO_RD_REQ|CLK_IS_OFF|STOP_CMD|
  538. END_CMD_RES|PRG_DONE|DATA_TRAN_DONE,
  539. host->base + MMC_I_MASK);
  540. DRCMR(host->dma_drcmrrx) = 0;
  541. DRCMR(host->dma_drcmrtx) = 0;
  542. free_irq(host->irq, host);
  543. pxa_free_dma(host->dma);
  544. iounmap(host->base);
  545. dma_free_coherent(&pdev->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma);
  546. clk_put(host->clk);
  547. release_resource(host->res);
  548. mmc_free_host(mmc);
  549. }
  550. return 0;
  551. }
  552. #ifdef CONFIG_PM
  553. static int pxamci_suspend(struct platform_device *dev, pm_message_t state)
  554. {
  555. struct mmc_host *mmc = platform_get_drvdata(dev);
  556. int ret = 0;
  557. if (mmc)
  558. ret = mmc_suspend_host(mmc, state);
  559. return ret;
  560. }
  561. static int pxamci_resume(struct platform_device *dev)
  562. {
  563. struct mmc_host *mmc = platform_get_drvdata(dev);
  564. int ret = 0;
  565. if (mmc)
  566. ret = mmc_resume_host(mmc);
  567. return ret;
  568. }
  569. #else
  570. #define pxamci_suspend NULL
  571. #define pxamci_resume NULL
  572. #endif
  573. static struct platform_driver pxamci_driver = {
  574. .probe = pxamci_probe,
  575. .remove = pxamci_remove,
  576. .suspend = pxamci_suspend,
  577. .resume = pxamci_resume,
  578. .driver = {
  579. .name = DRIVER_NAME,
  580. .owner = THIS_MODULE,
  581. },
  582. };
  583. static int __init pxamci_init(void)
  584. {
  585. return platform_driver_register(&pxamci_driver);
  586. }
  587. static void __exit pxamci_exit(void)
  588. {
  589. platform_driver_unregister(&pxamci_driver);
  590. }
  591. module_init(pxamci_init);
  592. module_exit(pxamci_exit);
  593. MODULE_DESCRIPTION("PXA Multimedia Card Interface Driver");
  594. MODULE_LICENSE("GPL");
  595. MODULE_ALIAS("platform:pxa2xx-mci");