tmio_mmc.c 16 KB

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