tmio_mmc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /*
  2. * linux/drivers/mmc/tmio_mmc.c
  3. *
  4. * Copyright (C) 2004 Ian Molton
  5. * Copyright (C) 2007 Ian Molton
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Driver for the MMC / SD / SDIO cell found in:
  12. *
  13. * TC6393XB TC6391XB TC6387XB T7L66XB
  14. *
  15. * This driver draws mainly on scattered spec sheets, Reverse engineering
  16. * of the toshiba e800 SD driver and some parts of the 2.4 ASIC3 driver (4 bit
  17. * support). (Further 4 bit support from a later datasheet).
  18. *
  19. * TODO:
  20. * Investigate using a workqueue for PIO transfers
  21. * Eliminate FIXMEs
  22. * SDIO support
  23. * Better Power management
  24. * Handle MMC errors better
  25. * double buffer support
  26. *
  27. */
  28. #include <linux/module.h>
  29. #include <linux/irq.h>
  30. #include <linux/device.h>
  31. #include <linux/delay.h>
  32. #include <linux/mmc/host.h>
  33. #include <linux/mfd/core.h>
  34. #include <linux/mfd/tmio.h>
  35. #include "tmio_mmc.h"
  36. /*
  37. * Fixme - documentation conflicts on what the clock values are for the
  38. * various dividers.
  39. * One document I have says that its a divisor of a 24MHz clock, another 33.
  40. * This probably depends on HCLK for a given platform, so we may need to
  41. * require HCLK be passed to us from the MFD core.
  42. *
  43. */
  44. static void tmio_mmc_set_clock(struct tmio_mmc_host *host, int new_clock)
  45. {
  46. void __iomem *cnf = host->cnf;
  47. void __iomem *ctl = host->ctl;
  48. u32 clk = 0, clock;
  49. if (new_clock) {
  50. for (clock = 46875, clk = 0x100; new_clock >= (clock<<1); ) {
  51. clock <<= 1;
  52. clk >>= 1;
  53. }
  54. if (clk & 0x1)
  55. clk = 0x20000;
  56. clk >>= 2;
  57. tmio_iowrite8((clk & 0x8000) ? 0 : 1, cnf + CNF_SD_CLK_MODE);
  58. clk |= 0x100;
  59. }
  60. tmio_iowrite16(clk, ctl + CTL_SD_CARD_CLK_CTL);
  61. }
  62. static void tmio_mmc_clk_stop(struct tmio_mmc_host *host)
  63. {
  64. void __iomem *ctl = host->ctl;
  65. tmio_iowrite16(0x0000, ctl + CTL_CLK_AND_WAIT_CTL);
  66. msleep(10);
  67. tmio_iowrite16(tmio_ioread16(ctl + CTL_SD_CARD_CLK_CTL) & ~0x0100,
  68. ctl + CTL_SD_CARD_CLK_CTL);
  69. msleep(10);
  70. }
  71. static void tmio_mmc_clk_start(struct tmio_mmc_host *host)
  72. {
  73. void __iomem *ctl = host->ctl;
  74. tmio_iowrite16(tmio_ioread16(ctl + CTL_SD_CARD_CLK_CTL) | 0x0100,
  75. ctl + CTL_SD_CARD_CLK_CTL);
  76. msleep(10);
  77. tmio_iowrite16(0x0100, ctl + CTL_CLK_AND_WAIT_CTL);
  78. msleep(10);
  79. }
  80. static void reset(struct tmio_mmc_host *host)
  81. {
  82. void __iomem *ctl = host->ctl;
  83. /* FIXME - should we set stop clock reg here */
  84. tmio_iowrite16(0x0000, ctl + CTL_RESET_SD);
  85. tmio_iowrite16(0x0000, ctl + CTL_RESET_SDIO);
  86. msleep(10);
  87. tmio_iowrite16(0x0001, ctl + CTL_RESET_SD);
  88. tmio_iowrite16(0x0001, ctl + CTL_RESET_SDIO);
  89. msleep(10);
  90. }
  91. static void
  92. tmio_mmc_finish_request(struct tmio_mmc_host *host)
  93. {
  94. struct mmc_request *mrq = host->mrq;
  95. host->mrq = NULL;
  96. host->cmd = NULL;
  97. host->data = NULL;
  98. mmc_request_done(host->mmc, mrq);
  99. }
  100. /* These are the bitmasks the tmio chip requires to implement the MMC response
  101. * types. Note that R1 and R6 are the same in this scheme. */
  102. #define APP_CMD 0x0040
  103. #define RESP_NONE 0x0300
  104. #define RESP_R1 0x0400
  105. #define RESP_R1B 0x0500
  106. #define RESP_R2 0x0600
  107. #define RESP_R3 0x0700
  108. #define DATA_PRESENT 0x0800
  109. #define TRANSFER_READ 0x1000
  110. #define TRANSFER_MULTI 0x2000
  111. #define SECURITY_CMD 0x4000
  112. static int
  113. tmio_mmc_start_command(struct tmio_mmc_host *host, struct mmc_command *cmd)
  114. {
  115. void __iomem *ctl = host->ctl;
  116. struct mmc_data *data = host->data;
  117. int c = cmd->opcode;
  118. /* Command 12 is handled by hardware */
  119. if (cmd->opcode == 12 && !cmd->arg) {
  120. tmio_iowrite16(0x001, ctl + CTL_STOP_INTERNAL_ACTION);
  121. return 0;
  122. }
  123. switch (mmc_resp_type(cmd)) {
  124. case MMC_RSP_NONE: c |= RESP_NONE; break;
  125. case MMC_RSP_R1: c |= RESP_R1; break;
  126. case MMC_RSP_R1B: c |= RESP_R1B; break;
  127. case MMC_RSP_R2: c |= RESP_R2; break;
  128. case MMC_RSP_R3: c |= RESP_R3; break;
  129. default:
  130. pr_debug("Unknown response type %d\n", mmc_resp_type(cmd));
  131. return -EINVAL;
  132. }
  133. host->cmd = cmd;
  134. /* FIXME - this seems to be ok comented out but the spec suggest this bit should
  135. * be set when issuing app commands.
  136. * if(cmd->flags & MMC_FLAG_ACMD)
  137. * c |= APP_CMD;
  138. */
  139. if (data) {
  140. c |= DATA_PRESENT;
  141. if (data->blocks > 1) {
  142. tmio_iowrite16(0x100, ctl + CTL_STOP_INTERNAL_ACTION);
  143. c |= TRANSFER_MULTI;
  144. }
  145. if (data->flags & MMC_DATA_READ)
  146. c |= TRANSFER_READ;
  147. }
  148. enable_mmc_irqs(ctl, TMIO_MASK_CMD);
  149. /* Fire off the command */
  150. tmio_iowrite32(cmd->arg, ctl + CTL_ARG_REG);
  151. tmio_iowrite16(c, ctl + CTL_SD_CMD);
  152. return 0;
  153. }
  154. /* This chip always returns (at least?) as much data as you ask for.
  155. * I'm unsure what happens if you ask for less than a block. This should be
  156. * looked into to ensure that a funny length read doesnt hose the controller.
  157. *
  158. */
  159. static inline void tmio_mmc_pio_irq(struct tmio_mmc_host *host)
  160. {
  161. void __iomem *ctl = host->ctl;
  162. struct mmc_data *data = host->data;
  163. unsigned short *buf;
  164. unsigned int count;
  165. unsigned long flags;
  166. if (!data) {
  167. pr_debug("Spurious PIO IRQ\n");
  168. return;
  169. }
  170. buf = (unsigned short *)(tmio_mmc_kmap_atomic(host, &flags) +
  171. host->sg_off);
  172. count = host->sg_ptr->length - host->sg_off;
  173. if (count > data->blksz)
  174. count = data->blksz;
  175. pr_debug("count: %08x offset: %08x flags %08x\n",
  176. count, host->sg_off, data->flags);
  177. /* Transfer the data */
  178. if (data->flags & MMC_DATA_READ)
  179. tmio_ioread16_rep(ctl + CTL_SD_DATA_PORT, buf, count >> 1);
  180. else
  181. tmio_iowrite16_rep(ctl + CTL_SD_DATA_PORT, buf, count >> 1);
  182. host->sg_off += count;
  183. tmio_mmc_kunmap_atomic(host, &flags);
  184. if (host->sg_off == host->sg_ptr->length)
  185. tmio_mmc_next_sg(host);
  186. return;
  187. }
  188. static inline void tmio_mmc_data_irq(struct tmio_mmc_host *host)
  189. {
  190. void __iomem *ctl = host->ctl;
  191. struct mmc_data *data = host->data;
  192. struct mmc_command *stop = data->stop;
  193. host->data = NULL;
  194. if (!data) {
  195. pr_debug("Spurious data end IRQ\n");
  196. return;
  197. }
  198. /* FIXME - return correct transfer count on errors */
  199. if (!data->error)
  200. data->bytes_xfered = data->blocks * data->blksz;
  201. else
  202. data->bytes_xfered = 0;
  203. pr_debug("Completed data request\n");
  204. /*FIXME - other drivers allow an optional stop command of any given type
  205. * which we dont do, as the chip can auto generate them.
  206. * Perhaps we can be smarter about when to use auto CMD12 and
  207. * only issue the auto request when we know this is the desired
  208. * stop command, allowing fallback to the stop command the
  209. * upper layers expect. For now, we do what works.
  210. */
  211. if (data->flags & MMC_DATA_READ)
  212. disable_mmc_irqs(ctl, TMIO_MASK_READOP);
  213. else
  214. disable_mmc_irqs(ctl, TMIO_MASK_WRITEOP);
  215. if (stop) {
  216. if (stop->opcode == 12 && !stop->arg)
  217. tmio_iowrite16(0x000, ctl + CTL_STOP_INTERNAL_ACTION);
  218. else
  219. BUG();
  220. }
  221. tmio_mmc_finish_request(host);
  222. }
  223. static inline void tmio_mmc_cmd_irq(struct tmio_mmc_host *host,
  224. unsigned int stat)
  225. {
  226. void __iomem *ctl = host->ctl, *addr;
  227. struct mmc_command *cmd = host->cmd;
  228. int i;
  229. if (!host->cmd) {
  230. pr_debug("Spurious CMD irq\n");
  231. return;
  232. }
  233. host->cmd = NULL;
  234. /* This controller is sicker than the PXA one. Not only do we need to
  235. * drop the top 8 bits of the first response word, we also need to
  236. * modify the order of the response for short response command types.
  237. */
  238. for (i = 3, addr = ctl + CTL_RESPONSE ; i >= 0 ; i--, addr += 4)
  239. cmd->resp[i] = tmio_ioread32(addr);
  240. if (cmd->flags & MMC_RSP_136) {
  241. cmd->resp[0] = (cmd->resp[0] << 8) | (cmd->resp[1] >> 24);
  242. cmd->resp[1] = (cmd->resp[1] << 8) | (cmd->resp[2] >> 24);
  243. cmd->resp[2] = (cmd->resp[2] << 8) | (cmd->resp[3] >> 24);
  244. cmd->resp[3] <<= 8;
  245. } else if (cmd->flags & MMC_RSP_R3) {
  246. cmd->resp[0] = cmd->resp[3];
  247. }
  248. if (stat & TMIO_STAT_CMDTIMEOUT)
  249. cmd->error = -ETIMEDOUT;
  250. else if (stat & TMIO_STAT_CRCFAIL && cmd->flags & MMC_RSP_CRC)
  251. cmd->error = -EILSEQ;
  252. /* If there is data to handle we enable data IRQs here, and
  253. * we will ultimatley finish the request in the data_end handler.
  254. * If theres no data or we encountered an error, finish now.
  255. */
  256. if (host->data && !cmd->error) {
  257. if (host->data->flags & MMC_DATA_READ)
  258. enable_mmc_irqs(ctl, TMIO_MASK_READOP);
  259. else
  260. enable_mmc_irqs(ctl, TMIO_MASK_WRITEOP);
  261. } else {
  262. tmio_mmc_finish_request(host);
  263. }
  264. return;
  265. }
  266. static irqreturn_t tmio_mmc_irq(int irq, void *devid)
  267. {
  268. struct tmio_mmc_host *host = devid;
  269. void __iomem *ctl = host->ctl;
  270. unsigned int ireg, irq_mask, status;
  271. pr_debug("MMC IRQ begin\n");
  272. status = tmio_ioread32(ctl + CTL_STATUS);
  273. irq_mask = tmio_ioread32(ctl + CTL_IRQ_MASK);
  274. ireg = status & TMIO_MASK_IRQ & ~irq_mask;
  275. pr_debug_status(status);
  276. pr_debug_status(ireg);
  277. if (!ireg) {
  278. disable_mmc_irqs(ctl, status & ~irq_mask);
  279. pr_debug("tmio_mmc: Spurious irq, disabling! "
  280. "0x%08x 0x%08x 0x%08x\n", status, irq_mask, ireg);
  281. pr_debug_status(status);
  282. goto out;
  283. }
  284. while (ireg) {
  285. /* Card insert / remove attempts */
  286. if (ireg & (TMIO_STAT_CARD_INSERT | TMIO_STAT_CARD_REMOVE)) {
  287. ack_mmc_irqs(ctl, TMIO_STAT_CARD_INSERT |
  288. TMIO_STAT_CARD_REMOVE);
  289. mmc_detect_change(host->mmc, 0);
  290. }
  291. /* CRC and other errors */
  292. /* if (ireg & TMIO_STAT_ERR_IRQ)
  293. * handled |= tmio_error_irq(host, irq, stat);
  294. */
  295. /* Command completion */
  296. if (ireg & TMIO_MASK_CMD) {
  297. ack_mmc_irqs(ctl, TMIO_MASK_CMD);
  298. tmio_mmc_cmd_irq(host, status);
  299. }
  300. /* Data transfer */
  301. if (ireg & (TMIO_STAT_RXRDY | TMIO_STAT_TXRQ)) {
  302. ack_mmc_irqs(ctl, TMIO_STAT_RXRDY | TMIO_STAT_TXRQ);
  303. tmio_mmc_pio_irq(host);
  304. }
  305. /* Data transfer completion */
  306. if (ireg & TMIO_STAT_DATAEND) {
  307. ack_mmc_irqs(ctl, TMIO_STAT_DATAEND);
  308. tmio_mmc_data_irq(host);
  309. }
  310. /* Check status - keep going until we've handled it all */
  311. status = tmio_ioread32(ctl + CTL_STATUS);
  312. irq_mask = tmio_ioread32(ctl + CTL_IRQ_MASK);
  313. ireg = status & TMIO_MASK_IRQ & ~irq_mask;
  314. pr_debug("Status at end of loop: %08x\n", status);
  315. pr_debug_status(status);
  316. }
  317. pr_debug("MMC IRQ end\n");
  318. out:
  319. return IRQ_HANDLED;
  320. }
  321. static int tmio_mmc_start_data(struct tmio_mmc_host *host,
  322. struct mmc_data *data)
  323. {
  324. void __iomem *ctl = host->ctl;
  325. pr_debug("setup data transfer: blocksize %08x nr_blocks %d\n",
  326. data->blksz, data->blocks);
  327. /* Hardware cannot perform 1 and 2 byte requests in 4 bit mode */
  328. if (data->blksz < 4 && host->mmc->ios.bus_width == MMC_BUS_WIDTH_4) {
  329. printk(KERN_ERR "%s: %d byte block unsupported in 4 bit mode\n",
  330. mmc_hostname(host->mmc), data->blksz);
  331. return -EINVAL;
  332. }
  333. tmio_mmc_init_sg(host, data);
  334. host->data = data;
  335. /* Set transfer length / blocksize */
  336. tmio_iowrite16(data->blksz, ctl + CTL_SD_XFER_LEN);
  337. tmio_iowrite16(data->blocks, ctl + CTL_XFER_BLK_COUNT);
  338. return 0;
  339. }
  340. /* Process requests from the MMC layer */
  341. static void tmio_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
  342. {
  343. struct tmio_mmc_host *host = mmc_priv(mmc);
  344. int ret;
  345. if (host->mrq)
  346. pr_debug("request not null\n");
  347. host->mrq = mrq;
  348. if (mrq->data) {
  349. ret = tmio_mmc_start_data(host, mrq->data);
  350. if (ret)
  351. goto fail;
  352. }
  353. ret = tmio_mmc_start_command(host, mrq->cmd);
  354. if (!ret)
  355. return;
  356. fail:
  357. mrq->cmd->error = ret;
  358. mmc_request_done(mmc, mrq);
  359. }
  360. /* Set MMC clock / power.
  361. * Note: This controller uses a simple divider scheme therefore it cannot
  362. * run a MMC card at full speed (20MHz). The max clock is 24MHz on SD, but as
  363. * MMC wont run that fast, it has to be clocked at 12MHz which is the next
  364. * slowest setting.
  365. */
  366. static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  367. {
  368. struct tmio_mmc_host *host = mmc_priv(mmc);
  369. void __iomem *cnf = host->cnf;
  370. void __iomem *ctl = host->ctl;
  371. if (ios->clock)
  372. tmio_mmc_set_clock(host, ios->clock);
  373. /* Power sequence - OFF -> ON -> UP */
  374. switch (ios->power_mode) {
  375. case MMC_POWER_OFF: /* power down SD bus */
  376. tmio_iowrite8(0x00, cnf + CNF_PWR_CTL_2);
  377. tmio_mmc_clk_stop(host);
  378. break;
  379. case MMC_POWER_ON: /* power up SD bus */
  380. tmio_iowrite8(0x02, cnf + CNF_PWR_CTL_2);
  381. break;
  382. case MMC_POWER_UP: /* start bus clock */
  383. tmio_mmc_clk_start(host);
  384. break;
  385. }
  386. switch (ios->bus_width) {
  387. case MMC_BUS_WIDTH_1:
  388. tmio_iowrite16(0x80e0, ctl + CTL_SD_MEM_CARD_OPT);
  389. break;
  390. case MMC_BUS_WIDTH_4:
  391. tmio_iowrite16(0x00e0, ctl + CTL_SD_MEM_CARD_OPT);
  392. break;
  393. }
  394. /* Let things settle. delay taken from winCE driver */
  395. udelay(140);
  396. }
  397. static int tmio_mmc_get_ro(struct mmc_host *mmc)
  398. {
  399. struct tmio_mmc_host *host = mmc_priv(mmc);
  400. void __iomem *ctl = host->ctl;
  401. return (tmio_ioread16(ctl + CTL_STATUS) & TMIO_STAT_WRPROTECT) ? 0 : 1;
  402. }
  403. static struct mmc_host_ops tmio_mmc_ops = {
  404. .request = tmio_mmc_request,
  405. .set_ios = tmio_mmc_set_ios,
  406. .get_ro = tmio_mmc_get_ro,
  407. };
  408. #ifdef CONFIG_PM
  409. static int tmio_mmc_suspend(struct platform_device *dev, pm_message_t state)
  410. {
  411. struct mfd_cell *cell = (struct mfd_cell *)dev->dev.platform_data;
  412. struct mmc_host *mmc = platform_get_drvdata(dev);
  413. int ret;
  414. ret = mmc_suspend_host(mmc, state);
  415. /* Tell MFD core it can disable us now.*/
  416. if (!ret && cell->disable)
  417. cell->disable(dev);
  418. return ret;
  419. }
  420. static int tmio_mmc_resume(struct platform_device *dev)
  421. {
  422. struct mfd_cell *cell = (struct mfd_cell *)dev->dev.platform_data;
  423. struct mmc_host *mmc = platform_get_drvdata(dev);
  424. struct tmio_mmc_host *host = mmc_priv(mmc);
  425. void __iomem *cnf = host->cnf;
  426. int ret = 0;
  427. /* Enable the MMC/SD Control registers */
  428. tmio_iowrite16(SDCREN, cnf + CNF_CMD);
  429. tmio_iowrite32(dev->resource[0].start & 0xfffe, cnf + CNF_CTL_BASE);
  430. /* Tell the MFD core we are ready to be enabled */
  431. if (cell->enable) {
  432. ret = cell->enable(dev);
  433. if (ret)
  434. goto out;
  435. }
  436. mmc_resume_host(mmc);
  437. out:
  438. return ret;
  439. }
  440. #else
  441. #define tmio_mmc_suspend NULL
  442. #define tmio_mmc_resume NULL
  443. #endif
  444. static int __devinit tmio_mmc_probe(struct platform_device *dev)
  445. {
  446. struct mfd_cell *cell = (struct mfd_cell *)dev->dev.platform_data;
  447. struct resource *res_ctl, *res_cnf;
  448. struct tmio_mmc_host *host;
  449. struct mmc_host *mmc;
  450. int ret = -ENOMEM;
  451. if (dev->num_resources != 3)
  452. goto out;
  453. res_ctl = platform_get_resource(dev, IORESOURCE_MEM, 0);
  454. res_cnf = platform_get_resource(dev, IORESOURCE_MEM, 1);
  455. if (!res_ctl || !res_cnf) {
  456. ret = -EINVAL;
  457. goto out;
  458. }
  459. mmc = mmc_alloc_host(sizeof(struct tmio_mmc_host), &dev->dev);
  460. if (!mmc)
  461. goto out;
  462. host = mmc_priv(mmc);
  463. host->mmc = mmc;
  464. platform_set_drvdata(dev, mmc);
  465. host->ctl = ioremap(res_ctl->start, res_ctl->end - res_ctl->start);
  466. if (!host->ctl)
  467. goto host_free;
  468. host->cnf = ioremap(res_cnf->start, res_cnf->end - res_cnf->start);
  469. if (!host->cnf)
  470. goto unmap_ctl;
  471. mmc->ops = &tmio_mmc_ops;
  472. mmc->caps = MMC_CAP_4_BIT_DATA;
  473. mmc->f_min = 46875; /* 24000000 / 512 */
  474. mmc->f_max = 24000000;
  475. mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
  476. /* Enable the MMC/SD Control registers */
  477. tmio_iowrite16(SDCREN, host->cnf + CNF_CMD);
  478. tmio_iowrite32(dev->resource[0].start & 0xfffe,
  479. host->cnf + CNF_CTL_BASE);
  480. /* Tell the MFD core we are ready to be enabled */
  481. if (cell->enable) {
  482. ret = cell->enable(dev);
  483. if (ret)
  484. goto unmap_cnf;
  485. }
  486. /* Disable SD power during suspend */
  487. tmio_iowrite8(0x01, host->cnf + CNF_PWR_CTL_3);
  488. /* The below is required but why? FIXME */
  489. tmio_iowrite8(0x1f, host->cnf + CNF_STOP_CLK_CTL);
  490. /* Power down SD bus*/
  491. tmio_iowrite8(0x0, host->cnf + CNF_PWR_CTL_2);
  492. tmio_mmc_clk_stop(host);
  493. reset(host);
  494. ret = platform_get_irq(dev, 0);
  495. if (ret >= 0)
  496. host->irq = ret;
  497. else
  498. goto unmap_cnf;
  499. disable_mmc_irqs(host->ctl, TMIO_MASK_ALL);
  500. ret = request_irq(host->irq, tmio_mmc_irq, IRQF_DISABLED, "tmio-mmc",
  501. host);
  502. if (ret)
  503. goto unmap_cnf;
  504. set_irq_type(host->irq, IRQ_TYPE_EDGE_FALLING);
  505. mmc_add_host(mmc);
  506. printk(KERN_INFO "%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
  507. (unsigned long)host->ctl, host->irq);
  508. /* Unmask the IRQs we want to know about */
  509. enable_mmc_irqs(host->ctl, TMIO_MASK_IRQ);
  510. return 0;
  511. unmap_cnf:
  512. iounmap(host->cnf);
  513. unmap_ctl:
  514. iounmap(host->ctl);
  515. host_free:
  516. mmc_free_host(mmc);
  517. out:
  518. return ret;
  519. }
  520. static int __devexit tmio_mmc_remove(struct platform_device *dev)
  521. {
  522. struct mmc_host *mmc = platform_get_drvdata(dev);
  523. platform_set_drvdata(dev, NULL);
  524. if (mmc) {
  525. struct tmio_mmc_host *host = mmc_priv(mmc);
  526. mmc_remove_host(mmc);
  527. mmc_free_host(mmc);
  528. free_irq(host->irq, host);
  529. iounmap(host->ctl);
  530. iounmap(host->cnf);
  531. }
  532. return 0;
  533. }
  534. /* ------------------- device registration ----------------------- */
  535. static struct platform_driver tmio_mmc_driver = {
  536. .driver = {
  537. .name = "tmio-mmc",
  538. .owner = THIS_MODULE,
  539. },
  540. .probe = tmio_mmc_probe,
  541. .remove = __devexit_p(tmio_mmc_remove),
  542. .suspend = tmio_mmc_suspend,
  543. .resume = tmio_mmc_resume,
  544. };
  545. static int __init tmio_mmc_init(void)
  546. {
  547. return platform_driver_register(&tmio_mmc_driver);
  548. }
  549. static void __exit tmio_mmc_exit(void)
  550. {
  551. platform_driver_unregister(&tmio_mmc_driver);
  552. }
  553. module_init(tmio_mmc_init);
  554. module_exit(tmio_mmc_exit);
  555. MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
  556. MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
  557. MODULE_LICENSE("GPL v2");
  558. MODULE_ALIAS("platform:tmio-mmc");