tmio_mmc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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;
  193. host->data = NULL;
  194. if (!data) {
  195. pr_debug("Spurious data end IRQ\n");
  196. return;
  197. }
  198. stop = data->stop;
  199. /* FIXME - return correct transfer count on errors */
  200. if (!data->error)
  201. data->bytes_xfered = data->blocks * data->blksz;
  202. else
  203. data->bytes_xfered = 0;
  204. pr_debug("Completed data request\n");
  205. /*FIXME - other drivers allow an optional stop command of any given type
  206. * which we dont do, as the chip can auto generate them.
  207. * Perhaps we can be smarter about when to use auto CMD12 and
  208. * only issue the auto request when we know this is the desired
  209. * stop command, allowing fallback to the stop command the
  210. * upper layers expect. For now, we do what works.
  211. */
  212. if (data->flags & MMC_DATA_READ)
  213. disable_mmc_irqs(ctl, TMIO_MASK_READOP);
  214. else
  215. disable_mmc_irqs(ctl, TMIO_MASK_WRITEOP);
  216. if (stop) {
  217. if (stop->opcode == 12 && !stop->arg)
  218. tmio_iowrite16(0x000, ctl + CTL_STOP_INTERNAL_ACTION);
  219. else
  220. BUG();
  221. }
  222. tmio_mmc_finish_request(host);
  223. }
  224. static inline void tmio_mmc_cmd_irq(struct tmio_mmc_host *host,
  225. unsigned int stat)
  226. {
  227. void __iomem *ctl = host->ctl, *addr;
  228. struct mmc_command *cmd = host->cmd;
  229. int i;
  230. if (!host->cmd) {
  231. pr_debug("Spurious CMD irq\n");
  232. return;
  233. }
  234. host->cmd = NULL;
  235. /* This controller is sicker than the PXA one. Not only do we need to
  236. * drop the top 8 bits of the first response word, we also need to
  237. * modify the order of the response for short response command types.
  238. */
  239. for (i = 3, addr = ctl + CTL_RESPONSE ; i >= 0 ; i--, addr += 4)
  240. cmd->resp[i] = tmio_ioread32(addr);
  241. if (cmd->flags & MMC_RSP_136) {
  242. cmd->resp[0] = (cmd->resp[0] << 8) | (cmd->resp[1] >> 24);
  243. cmd->resp[1] = (cmd->resp[1] << 8) | (cmd->resp[2] >> 24);
  244. cmd->resp[2] = (cmd->resp[2] << 8) | (cmd->resp[3] >> 24);
  245. cmd->resp[3] <<= 8;
  246. } else if (cmd->flags & MMC_RSP_R3) {
  247. cmd->resp[0] = cmd->resp[3];
  248. }
  249. if (stat & TMIO_STAT_CMDTIMEOUT)
  250. cmd->error = -ETIMEDOUT;
  251. else if (stat & TMIO_STAT_CRCFAIL && cmd->flags & MMC_RSP_CRC)
  252. cmd->error = -EILSEQ;
  253. /* If there is data to handle we enable data IRQs here, and
  254. * we will ultimatley finish the request in the data_end handler.
  255. * If theres no data or we encountered an error, finish now.
  256. */
  257. if (host->data && !cmd->error) {
  258. if (host->data->flags & MMC_DATA_READ)
  259. enable_mmc_irqs(ctl, TMIO_MASK_READOP);
  260. else
  261. enable_mmc_irqs(ctl, TMIO_MASK_WRITEOP);
  262. } else {
  263. tmio_mmc_finish_request(host);
  264. }
  265. return;
  266. }
  267. static irqreturn_t tmio_mmc_irq(int irq, void *devid)
  268. {
  269. struct tmio_mmc_host *host = devid;
  270. void __iomem *ctl = host->ctl;
  271. unsigned int ireg, irq_mask, status;
  272. pr_debug("MMC IRQ begin\n");
  273. status = tmio_ioread32(ctl + CTL_STATUS);
  274. irq_mask = tmio_ioread32(ctl + CTL_IRQ_MASK);
  275. ireg = status & TMIO_MASK_IRQ & ~irq_mask;
  276. pr_debug_status(status);
  277. pr_debug_status(ireg);
  278. if (!ireg) {
  279. disable_mmc_irqs(ctl, status & ~irq_mask);
  280. pr_debug("tmio_mmc: Spurious irq, disabling! "
  281. "0x%08x 0x%08x 0x%08x\n", status, irq_mask, ireg);
  282. pr_debug_status(status);
  283. goto out;
  284. }
  285. while (ireg) {
  286. /* Card insert / remove attempts */
  287. if (ireg & (TMIO_STAT_CARD_INSERT | TMIO_STAT_CARD_REMOVE)) {
  288. ack_mmc_irqs(ctl, TMIO_STAT_CARD_INSERT |
  289. TMIO_STAT_CARD_REMOVE);
  290. mmc_detect_change(host->mmc, 0);
  291. }
  292. /* CRC and other errors */
  293. /* if (ireg & TMIO_STAT_ERR_IRQ)
  294. * handled |= tmio_error_irq(host, irq, stat);
  295. */
  296. /* Command completion */
  297. if (ireg & TMIO_MASK_CMD) {
  298. ack_mmc_irqs(ctl, TMIO_MASK_CMD);
  299. tmio_mmc_cmd_irq(host, status);
  300. }
  301. /* Data transfer */
  302. if (ireg & (TMIO_STAT_RXRDY | TMIO_STAT_TXRQ)) {
  303. ack_mmc_irqs(ctl, TMIO_STAT_RXRDY | TMIO_STAT_TXRQ);
  304. tmio_mmc_pio_irq(host);
  305. }
  306. /* Data transfer completion */
  307. if (ireg & TMIO_STAT_DATAEND) {
  308. ack_mmc_irqs(ctl, TMIO_STAT_DATAEND);
  309. tmio_mmc_data_irq(host);
  310. }
  311. /* Check status - keep going until we've handled it all */
  312. status = tmio_ioread32(ctl + CTL_STATUS);
  313. irq_mask = tmio_ioread32(ctl + CTL_IRQ_MASK);
  314. ireg = status & TMIO_MASK_IRQ & ~irq_mask;
  315. pr_debug("Status at end of loop: %08x\n", status);
  316. pr_debug_status(status);
  317. }
  318. pr_debug("MMC IRQ end\n");
  319. out:
  320. return IRQ_HANDLED;
  321. }
  322. static int tmio_mmc_start_data(struct tmio_mmc_host *host,
  323. struct mmc_data *data)
  324. {
  325. void __iomem *ctl = host->ctl;
  326. pr_debug("setup data transfer: blocksize %08x nr_blocks %d\n",
  327. data->blksz, data->blocks);
  328. /* Hardware cannot perform 1 and 2 byte requests in 4 bit mode */
  329. if (data->blksz < 4 && host->mmc->ios.bus_width == MMC_BUS_WIDTH_4) {
  330. printk(KERN_ERR "%s: %d byte block unsupported in 4 bit mode\n",
  331. mmc_hostname(host->mmc), data->blksz);
  332. return -EINVAL;
  333. }
  334. tmio_mmc_init_sg(host, data);
  335. host->data = data;
  336. /* Set transfer length / blocksize */
  337. tmio_iowrite16(data->blksz, ctl + CTL_SD_XFER_LEN);
  338. tmio_iowrite16(data->blocks, ctl + CTL_XFER_BLK_COUNT);
  339. return 0;
  340. }
  341. /* Process requests from the MMC layer */
  342. static void tmio_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
  343. {
  344. struct tmio_mmc_host *host = mmc_priv(mmc);
  345. int ret;
  346. if (host->mrq)
  347. pr_debug("request not null\n");
  348. host->mrq = mrq;
  349. if (mrq->data) {
  350. ret = tmio_mmc_start_data(host, mrq->data);
  351. if (ret)
  352. goto fail;
  353. }
  354. ret = tmio_mmc_start_command(host, mrq->cmd);
  355. if (!ret)
  356. return;
  357. fail:
  358. mrq->cmd->error = ret;
  359. mmc_request_done(mmc, mrq);
  360. }
  361. /* Set MMC clock / power.
  362. * Note: This controller uses a simple divider scheme therefore it cannot
  363. * run a MMC card at full speed (20MHz). The max clock is 24MHz on SD, but as
  364. * MMC wont run that fast, it has to be clocked at 12MHz which is the next
  365. * slowest setting.
  366. */
  367. static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  368. {
  369. struct tmio_mmc_host *host = mmc_priv(mmc);
  370. void __iomem *cnf = host->cnf;
  371. void __iomem *ctl = host->ctl;
  372. if (ios->clock)
  373. tmio_mmc_set_clock(host, ios->clock);
  374. /* Power sequence - OFF -> ON -> UP */
  375. switch (ios->power_mode) {
  376. case MMC_POWER_OFF: /* power down SD bus */
  377. tmio_iowrite8(0x00, cnf + CNF_PWR_CTL_2);
  378. tmio_mmc_clk_stop(host);
  379. break;
  380. case MMC_POWER_ON: /* power up SD bus */
  381. tmio_iowrite8(0x02, cnf + CNF_PWR_CTL_2);
  382. break;
  383. case MMC_POWER_UP: /* start bus clock */
  384. tmio_mmc_clk_start(host);
  385. break;
  386. }
  387. switch (ios->bus_width) {
  388. case MMC_BUS_WIDTH_1:
  389. tmio_iowrite16(0x80e0, ctl + CTL_SD_MEM_CARD_OPT);
  390. break;
  391. case MMC_BUS_WIDTH_4:
  392. tmio_iowrite16(0x00e0, ctl + CTL_SD_MEM_CARD_OPT);
  393. break;
  394. }
  395. /* Let things settle. delay taken from winCE driver */
  396. udelay(140);
  397. }
  398. static int tmio_mmc_get_ro(struct mmc_host *mmc)
  399. {
  400. struct tmio_mmc_host *host = mmc_priv(mmc);
  401. void __iomem *ctl = host->ctl;
  402. return (tmio_ioread16(ctl + CTL_STATUS) & TMIO_STAT_WRPROTECT) ? 0 : 1;
  403. }
  404. static struct mmc_host_ops tmio_mmc_ops = {
  405. .request = tmio_mmc_request,
  406. .set_ios = tmio_mmc_set_ios,
  407. .get_ro = tmio_mmc_get_ro,
  408. };
  409. #ifdef CONFIG_PM
  410. static int tmio_mmc_suspend(struct platform_device *dev, pm_message_t state)
  411. {
  412. struct mfd_cell *cell = (struct mfd_cell *)dev->dev.platform_data;
  413. struct mmc_host *mmc = platform_get_drvdata(dev);
  414. int ret;
  415. ret = mmc_suspend_host(mmc, state);
  416. /* Tell MFD core it can disable us now.*/
  417. if (!ret && cell->disable)
  418. cell->disable(dev);
  419. return ret;
  420. }
  421. static int tmio_mmc_resume(struct platform_device *dev)
  422. {
  423. struct mfd_cell *cell = (struct mfd_cell *)dev->dev.platform_data;
  424. struct mmc_host *mmc = platform_get_drvdata(dev);
  425. struct tmio_mmc_host *host = mmc_priv(mmc);
  426. void __iomem *cnf = host->cnf;
  427. int ret = 0;
  428. /* Enable the MMC/SD Control registers */
  429. tmio_iowrite16(SDCREN, cnf + CNF_CMD);
  430. tmio_iowrite32(dev->resource[0].start & 0xfffe, cnf + CNF_CTL_BASE);
  431. /* Tell the MFD core we are ready to be enabled */
  432. if (cell->enable) {
  433. ret = cell->enable(dev);
  434. if (ret)
  435. goto out;
  436. }
  437. mmc_resume_host(mmc);
  438. out:
  439. return ret;
  440. }
  441. #else
  442. #define tmio_mmc_suspend NULL
  443. #define tmio_mmc_resume NULL
  444. #endif
  445. static int __devinit tmio_mmc_probe(struct platform_device *dev)
  446. {
  447. struct mfd_cell *cell = (struct mfd_cell *)dev->dev.platform_data;
  448. struct resource *res_ctl, *res_cnf;
  449. struct tmio_mmc_host *host;
  450. struct mmc_host *mmc;
  451. int ret = -ENOMEM;
  452. if (dev->num_resources != 3)
  453. goto out;
  454. res_ctl = platform_get_resource(dev, IORESOURCE_MEM, 0);
  455. res_cnf = platform_get_resource(dev, IORESOURCE_MEM, 1);
  456. if (!res_ctl || !res_cnf) {
  457. ret = -EINVAL;
  458. goto out;
  459. }
  460. mmc = mmc_alloc_host(sizeof(struct tmio_mmc_host), &dev->dev);
  461. if (!mmc)
  462. goto out;
  463. host = mmc_priv(mmc);
  464. host->mmc = mmc;
  465. platform_set_drvdata(dev, mmc);
  466. host->ctl = ioremap(res_ctl->start, res_ctl->end - res_ctl->start);
  467. if (!host->ctl)
  468. goto host_free;
  469. host->cnf = ioremap(res_cnf->start, res_cnf->end - res_cnf->start);
  470. if (!host->cnf)
  471. goto unmap_ctl;
  472. mmc->ops = &tmio_mmc_ops;
  473. mmc->caps = MMC_CAP_4_BIT_DATA;
  474. mmc->f_min = 46875; /* 24000000 / 512 */
  475. mmc->f_max = 24000000;
  476. mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
  477. /* Enable the MMC/SD Control registers */
  478. tmio_iowrite16(SDCREN, host->cnf + CNF_CMD);
  479. tmio_iowrite32(dev->resource[0].start & 0xfffe,
  480. host->cnf + CNF_CTL_BASE);
  481. /* Tell the MFD core we are ready to be enabled */
  482. if (cell->enable) {
  483. ret = cell->enable(dev);
  484. if (ret)
  485. goto unmap_cnf;
  486. }
  487. /* Disable SD power during suspend */
  488. tmio_iowrite8(0x01, host->cnf + CNF_PWR_CTL_3);
  489. /* The below is required but why? FIXME */
  490. tmio_iowrite8(0x1f, host->cnf + CNF_STOP_CLK_CTL);
  491. /* Power down SD bus*/
  492. tmio_iowrite8(0x0, host->cnf + CNF_PWR_CTL_2);
  493. tmio_mmc_clk_stop(host);
  494. reset(host);
  495. ret = platform_get_irq(dev, 0);
  496. if (ret >= 0)
  497. host->irq = ret;
  498. else
  499. goto unmap_cnf;
  500. disable_mmc_irqs(host->ctl, TMIO_MASK_ALL);
  501. ret = request_irq(host->irq, tmio_mmc_irq, IRQF_DISABLED, "tmio-mmc",
  502. host);
  503. if (ret)
  504. goto unmap_cnf;
  505. set_irq_type(host->irq, IRQ_TYPE_EDGE_FALLING);
  506. mmc_add_host(mmc);
  507. printk(KERN_INFO "%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
  508. (unsigned long)host->ctl, host->irq);
  509. /* Unmask the IRQs we want to know about */
  510. enable_mmc_irqs(host->ctl, TMIO_MASK_IRQ);
  511. return 0;
  512. unmap_cnf:
  513. iounmap(host->cnf);
  514. unmap_ctl:
  515. iounmap(host->ctl);
  516. host_free:
  517. mmc_free_host(mmc);
  518. out:
  519. return ret;
  520. }
  521. static int __devexit tmio_mmc_remove(struct platform_device *dev)
  522. {
  523. struct mmc_host *mmc = platform_get_drvdata(dev);
  524. platform_set_drvdata(dev, NULL);
  525. if (mmc) {
  526. struct tmio_mmc_host *host = mmc_priv(mmc);
  527. mmc_remove_host(mmc);
  528. mmc_free_host(mmc);
  529. free_irq(host->irq, host);
  530. iounmap(host->ctl);
  531. iounmap(host->cnf);
  532. }
  533. return 0;
  534. }
  535. /* ------------------- device registration ----------------------- */
  536. static struct platform_driver tmio_mmc_driver = {
  537. .driver = {
  538. .name = "tmio-mmc",
  539. .owner = THIS_MODULE,
  540. },
  541. .probe = tmio_mmc_probe,
  542. .remove = __devexit_p(tmio_mmc_remove),
  543. .suspend = tmio_mmc_suspend,
  544. .resume = tmio_mmc_resume,
  545. };
  546. static int __init tmio_mmc_init(void)
  547. {
  548. return platform_driver_register(&tmio_mmc_driver);
  549. }
  550. static void __exit tmio_mmc_exit(void)
  551. {
  552. platform_driver_unregister(&tmio_mmc_driver);
  553. }
  554. module_init(tmio_mmc_init);
  555. module_exit(tmio_mmc_exit);
  556. MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
  557. MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
  558. MODULE_LICENSE("GPL v2");
  559. MODULE_ALIAS("platform:tmio-mmc");