tmio_mmc_pio.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  1. /*
  2. * linux/drivers/mmc/host/tmio_mmc_pio.c
  3. *
  4. * Copyright (C) 2011 Guennadi Liakhovetski
  5. * Copyright (C) 2007 Ian Molton
  6. * Copyright (C) 2004 Ian Molton
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * Driver for the MMC / SD / SDIO IP found in:
  13. *
  14. * TC6393XB, TC6391XB, TC6387XB, T7L66XB, ASIC3, SH-Mobile SoCs
  15. *
  16. * This driver draws mainly on scattered spec sheets, Reverse engineering
  17. * of the toshiba e800 SD driver and some parts of the 2.4 ASIC3 driver (4 bit
  18. * support). (Further 4 bit support from a later datasheet).
  19. *
  20. * TODO:
  21. * Investigate using a workqueue for PIO transfers
  22. * Eliminate FIXMEs
  23. * SDIO support
  24. * Better Power management
  25. * Handle MMC errors better
  26. * double buffer support
  27. *
  28. */
  29. #include <linux/delay.h>
  30. #include <linux/device.h>
  31. #include <linux/highmem.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/io.h>
  34. #include <linux/irq.h>
  35. #include <linux/mfd/tmio.h>
  36. #include <linux/mmc/host.h>
  37. #include <linux/mmc/mmc.h>
  38. #include <linux/mmc/slot-gpio.h>
  39. #include <linux/mmc/tmio.h>
  40. #include <linux/module.h>
  41. #include <linux/pagemap.h>
  42. #include <linux/platform_device.h>
  43. #include <linux/pm_qos.h>
  44. #include <linux/pm_runtime.h>
  45. #include <linux/regulator/consumer.h>
  46. #include <linux/mmc/sdio.h>
  47. #include <linux/scatterlist.h>
  48. #include <linux/spinlock.h>
  49. #include <linux/workqueue.h>
  50. #include "tmio_mmc.h"
  51. void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i)
  52. {
  53. host->sdcard_irq_mask &= ~(i & TMIO_MASK_IRQ);
  54. sd_ctrl_write32(host, CTL_IRQ_MASK, host->sdcard_irq_mask);
  55. }
  56. void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i)
  57. {
  58. host->sdcard_irq_mask |= (i & TMIO_MASK_IRQ);
  59. sd_ctrl_write32(host, CTL_IRQ_MASK, host->sdcard_irq_mask);
  60. }
  61. static void tmio_mmc_ack_mmc_irqs(struct tmio_mmc_host *host, u32 i)
  62. {
  63. sd_ctrl_write32(host, CTL_STATUS, ~i);
  64. }
  65. static void tmio_mmc_init_sg(struct tmio_mmc_host *host, struct mmc_data *data)
  66. {
  67. host->sg_len = data->sg_len;
  68. host->sg_ptr = data->sg;
  69. host->sg_orig = data->sg;
  70. host->sg_off = 0;
  71. }
  72. static int tmio_mmc_next_sg(struct tmio_mmc_host *host)
  73. {
  74. host->sg_ptr = sg_next(host->sg_ptr);
  75. host->sg_off = 0;
  76. return --host->sg_len;
  77. }
  78. #ifdef CONFIG_MMC_DEBUG
  79. #define STATUS_TO_TEXT(a, status, i) \
  80. do { \
  81. if (status & TMIO_STAT_##a) { \
  82. if (i++) \
  83. printk(" | "); \
  84. printk(#a); \
  85. } \
  86. } while (0)
  87. static void pr_debug_status(u32 status)
  88. {
  89. int i = 0;
  90. pr_debug("status: %08x = ", status);
  91. STATUS_TO_TEXT(CARD_REMOVE, status, i);
  92. STATUS_TO_TEXT(CARD_INSERT, status, i);
  93. STATUS_TO_TEXT(SIGSTATE, status, i);
  94. STATUS_TO_TEXT(WRPROTECT, status, i);
  95. STATUS_TO_TEXT(CARD_REMOVE_A, status, i);
  96. STATUS_TO_TEXT(CARD_INSERT_A, status, i);
  97. STATUS_TO_TEXT(SIGSTATE_A, status, i);
  98. STATUS_TO_TEXT(CMD_IDX_ERR, status, i);
  99. STATUS_TO_TEXT(STOPBIT_ERR, status, i);
  100. STATUS_TO_TEXT(ILL_FUNC, status, i);
  101. STATUS_TO_TEXT(CMD_BUSY, status, i);
  102. STATUS_TO_TEXT(CMDRESPEND, status, i);
  103. STATUS_TO_TEXT(DATAEND, status, i);
  104. STATUS_TO_TEXT(CRCFAIL, status, i);
  105. STATUS_TO_TEXT(DATATIMEOUT, status, i);
  106. STATUS_TO_TEXT(CMDTIMEOUT, status, i);
  107. STATUS_TO_TEXT(RXOVERFLOW, status, i);
  108. STATUS_TO_TEXT(TXUNDERRUN, status, i);
  109. STATUS_TO_TEXT(RXRDY, status, i);
  110. STATUS_TO_TEXT(TXRQ, status, i);
  111. STATUS_TO_TEXT(ILL_ACCESS, status, i);
  112. printk("\n");
  113. }
  114. #else
  115. #define pr_debug_status(s) do { } while (0)
  116. #endif
  117. static void tmio_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
  118. {
  119. struct tmio_mmc_host *host = mmc_priv(mmc);
  120. if (enable && !host->sdio_irq_enabled) {
  121. /* Keep device active while SDIO irq is enabled */
  122. pm_runtime_get_sync(mmc_dev(mmc));
  123. host->sdio_irq_enabled = true;
  124. host->sdio_irq_mask = TMIO_SDIO_MASK_ALL &
  125. ~TMIO_SDIO_STAT_IOIRQ;
  126. sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0001);
  127. sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask);
  128. } else if (!enable && host->sdio_irq_enabled) {
  129. host->sdio_irq_mask = TMIO_SDIO_MASK_ALL;
  130. sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask);
  131. sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0000);
  132. host->sdio_irq_enabled = false;
  133. pm_runtime_mark_last_busy(mmc_dev(mmc));
  134. pm_runtime_put_autosuspend(mmc_dev(mmc));
  135. }
  136. }
  137. static void tmio_mmc_set_clock(struct tmio_mmc_host *host,
  138. unsigned int new_clock)
  139. {
  140. u32 clk = 0, clock;
  141. if (new_clock) {
  142. for (clock = host->mmc->f_min, clk = 0x80000080;
  143. new_clock >= (clock<<1); clk >>= 1)
  144. clock <<= 1;
  145. clk |= 0x100;
  146. }
  147. if (host->set_clk_div)
  148. host->set_clk_div(host->pdev, (clk>>22) & 1);
  149. sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, clk & 0x1ff);
  150. msleep(10);
  151. }
  152. static void tmio_mmc_clk_stop(struct tmio_mmc_host *host)
  153. {
  154. /* implicit BUG_ON(!res) */
  155. if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG) {
  156. sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0000);
  157. msleep(10);
  158. }
  159. sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~0x0100 &
  160. sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
  161. msleep(10);
  162. }
  163. static void tmio_mmc_clk_start(struct tmio_mmc_host *host)
  164. {
  165. sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, 0x0100 |
  166. sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
  167. msleep(10);
  168. /* implicit BUG_ON(!res) */
  169. if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG) {
  170. sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0100);
  171. msleep(10);
  172. }
  173. }
  174. static void tmio_mmc_reset(struct tmio_mmc_host *host)
  175. {
  176. /* FIXME - should we set stop clock reg here */
  177. sd_ctrl_write16(host, CTL_RESET_SD, 0x0000);
  178. /* implicit BUG_ON(!res) */
  179. if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG)
  180. sd_ctrl_write16(host, CTL_RESET_SDIO, 0x0000);
  181. msleep(10);
  182. sd_ctrl_write16(host, CTL_RESET_SD, 0x0001);
  183. if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG)
  184. sd_ctrl_write16(host, CTL_RESET_SDIO, 0x0001);
  185. msleep(10);
  186. }
  187. static void tmio_mmc_reset_work(struct work_struct *work)
  188. {
  189. struct tmio_mmc_host *host = container_of(work, struct tmio_mmc_host,
  190. delayed_reset_work.work);
  191. struct mmc_request *mrq;
  192. unsigned long flags;
  193. spin_lock_irqsave(&host->lock, flags);
  194. mrq = host->mrq;
  195. /*
  196. * is request already finished? Since we use a non-blocking
  197. * cancel_delayed_work(), it can happen, that a .set_ios() call preempts
  198. * us, so, have to check for IS_ERR(host->mrq)
  199. */
  200. if (IS_ERR_OR_NULL(mrq)
  201. || time_is_after_jiffies(host->last_req_ts +
  202. msecs_to_jiffies(2000))) {
  203. spin_unlock_irqrestore(&host->lock, flags);
  204. return;
  205. }
  206. dev_warn(&host->pdev->dev,
  207. "timeout waiting for hardware interrupt (CMD%u)\n",
  208. mrq->cmd->opcode);
  209. if (host->data)
  210. host->data->error = -ETIMEDOUT;
  211. else if (host->cmd)
  212. host->cmd->error = -ETIMEDOUT;
  213. else
  214. mrq->cmd->error = -ETIMEDOUT;
  215. host->cmd = NULL;
  216. host->data = NULL;
  217. host->force_pio = false;
  218. spin_unlock_irqrestore(&host->lock, flags);
  219. tmio_mmc_reset(host);
  220. /* Ready for new calls */
  221. host->mrq = NULL;
  222. tmio_mmc_abort_dma(host);
  223. mmc_request_done(host->mmc, mrq);
  224. pm_runtime_mark_last_busy(mmc_dev(host->mmc));
  225. pm_runtime_put_autosuspend(mmc_dev(host->mmc));
  226. }
  227. /* called with host->lock held, interrupts disabled */
  228. static void tmio_mmc_finish_request(struct tmio_mmc_host *host)
  229. {
  230. struct mmc_request *mrq;
  231. unsigned long flags;
  232. spin_lock_irqsave(&host->lock, flags);
  233. mrq = host->mrq;
  234. if (IS_ERR_OR_NULL(mrq)) {
  235. spin_unlock_irqrestore(&host->lock, flags);
  236. return;
  237. }
  238. host->cmd = NULL;
  239. host->data = NULL;
  240. host->force_pio = false;
  241. cancel_delayed_work(&host->delayed_reset_work);
  242. host->mrq = NULL;
  243. spin_unlock_irqrestore(&host->lock, flags);
  244. if (mrq->cmd->error || (mrq->data && mrq->data->error))
  245. tmio_mmc_abort_dma(host);
  246. mmc_request_done(host->mmc, mrq);
  247. pm_runtime_mark_last_busy(mmc_dev(host->mmc));
  248. pm_runtime_put_autosuspend(mmc_dev(host->mmc));
  249. }
  250. static void tmio_mmc_done_work(struct work_struct *work)
  251. {
  252. struct tmio_mmc_host *host = container_of(work, struct tmio_mmc_host,
  253. done);
  254. tmio_mmc_finish_request(host);
  255. }
  256. /* These are the bitmasks the tmio chip requires to implement the MMC response
  257. * types. Note that R1 and R6 are the same in this scheme. */
  258. #define APP_CMD 0x0040
  259. #define RESP_NONE 0x0300
  260. #define RESP_R1 0x0400
  261. #define RESP_R1B 0x0500
  262. #define RESP_R2 0x0600
  263. #define RESP_R3 0x0700
  264. #define DATA_PRESENT 0x0800
  265. #define TRANSFER_READ 0x1000
  266. #define TRANSFER_MULTI 0x2000
  267. #define SECURITY_CMD 0x4000
  268. #define NO_CMD12_ISSUE 0x4000 /* TMIO_MMC_HAVE_CMD12_CTRL */
  269. static int tmio_mmc_start_command(struct tmio_mmc_host *host, struct mmc_command *cmd)
  270. {
  271. struct mmc_data *data = host->data;
  272. int c = cmd->opcode;
  273. u32 irq_mask = TMIO_MASK_CMD;
  274. /* CMD12 is handled by hardware */
  275. if (cmd->opcode == MMC_STOP_TRANSMISSION && !cmd->arg) {
  276. sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x001);
  277. return 0;
  278. }
  279. switch (mmc_resp_type(cmd)) {
  280. case MMC_RSP_NONE: c |= RESP_NONE; break;
  281. case MMC_RSP_R1: c |= RESP_R1; break;
  282. case MMC_RSP_R1B: c |= RESP_R1B; break;
  283. case MMC_RSP_R2: c |= RESP_R2; break;
  284. case MMC_RSP_R3: c |= RESP_R3; break;
  285. default:
  286. pr_debug("Unknown response type %d\n", mmc_resp_type(cmd));
  287. return -EINVAL;
  288. }
  289. host->cmd = cmd;
  290. /* FIXME - this seems to be ok commented out but the spec suggest this bit
  291. * should be set when issuing app commands.
  292. * if(cmd->flags & MMC_FLAG_ACMD)
  293. * c |= APP_CMD;
  294. */
  295. if (data) {
  296. c |= DATA_PRESENT;
  297. if (data->blocks > 1) {
  298. sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x100);
  299. c |= TRANSFER_MULTI;
  300. /*
  301. * Disable auto CMD12 at IO_RW_EXTENDED when
  302. * multiple block transfer
  303. */
  304. if ((host->pdata->flags & TMIO_MMC_HAVE_CMD12_CTRL) &&
  305. (cmd->opcode == SD_IO_RW_EXTENDED))
  306. c |= NO_CMD12_ISSUE;
  307. }
  308. if (data->flags & MMC_DATA_READ)
  309. c |= TRANSFER_READ;
  310. }
  311. if (!host->native_hotplug)
  312. irq_mask &= ~(TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT);
  313. tmio_mmc_enable_mmc_irqs(host, irq_mask);
  314. /* Fire off the command */
  315. sd_ctrl_write32(host, CTL_ARG_REG, cmd->arg);
  316. sd_ctrl_write16(host, CTL_SD_CMD, c);
  317. return 0;
  318. }
  319. /*
  320. * This chip always returns (at least?) as much data as you ask for.
  321. * I'm unsure what happens if you ask for less than a block. This should be
  322. * looked into to ensure that a funny length read doesn't hose the controller.
  323. */
  324. static void tmio_mmc_pio_irq(struct tmio_mmc_host *host)
  325. {
  326. struct mmc_data *data = host->data;
  327. void *sg_virt;
  328. unsigned short *buf;
  329. unsigned int count;
  330. unsigned long flags;
  331. if ((host->chan_tx || host->chan_rx) && !host->force_pio) {
  332. pr_err("PIO IRQ in DMA mode!\n");
  333. return;
  334. } else if (!data) {
  335. pr_debug("Spurious PIO IRQ\n");
  336. return;
  337. }
  338. sg_virt = tmio_mmc_kmap_atomic(host->sg_ptr, &flags);
  339. buf = (unsigned short *)(sg_virt + host->sg_off);
  340. count = host->sg_ptr->length - host->sg_off;
  341. if (count > data->blksz)
  342. count = data->blksz;
  343. pr_debug("count: %08x offset: %08x flags %08x\n",
  344. count, host->sg_off, data->flags);
  345. /* Transfer the data */
  346. if (data->flags & MMC_DATA_READ)
  347. sd_ctrl_read16_rep(host, CTL_SD_DATA_PORT, buf, count >> 1);
  348. else
  349. sd_ctrl_write16_rep(host, CTL_SD_DATA_PORT, buf, count >> 1);
  350. host->sg_off += count;
  351. tmio_mmc_kunmap_atomic(host->sg_ptr, &flags, sg_virt);
  352. if (host->sg_off == host->sg_ptr->length)
  353. tmio_mmc_next_sg(host);
  354. return;
  355. }
  356. static void tmio_mmc_check_bounce_buffer(struct tmio_mmc_host *host)
  357. {
  358. if (host->sg_ptr == &host->bounce_sg) {
  359. unsigned long flags;
  360. void *sg_vaddr = tmio_mmc_kmap_atomic(host->sg_orig, &flags);
  361. memcpy(sg_vaddr, host->bounce_buf, host->bounce_sg.length);
  362. tmio_mmc_kunmap_atomic(host->sg_orig, &flags, sg_vaddr);
  363. }
  364. }
  365. /* needs to be called with host->lock held */
  366. void tmio_mmc_do_data_irq(struct tmio_mmc_host *host)
  367. {
  368. struct mmc_data *data = host->data;
  369. struct mmc_command *stop;
  370. host->data = NULL;
  371. if (!data) {
  372. dev_warn(&host->pdev->dev, "Spurious data end IRQ\n");
  373. return;
  374. }
  375. stop = data->stop;
  376. /* FIXME - return correct transfer count on errors */
  377. if (!data->error)
  378. data->bytes_xfered = data->blocks * data->blksz;
  379. else
  380. data->bytes_xfered = 0;
  381. pr_debug("Completed data request\n");
  382. /*
  383. * FIXME: other drivers allow an optional stop command of any given type
  384. * which we dont do, as the chip can auto generate them.
  385. * Perhaps we can be smarter about when to use auto CMD12 and
  386. * only issue the auto request when we know this is the desired
  387. * stop command, allowing fallback to the stop command the
  388. * upper layers expect. For now, we do what works.
  389. */
  390. if (data->flags & MMC_DATA_READ) {
  391. if (host->chan_rx && !host->force_pio)
  392. tmio_mmc_check_bounce_buffer(host);
  393. dev_dbg(&host->pdev->dev, "Complete Rx request %p\n",
  394. host->mrq);
  395. } else {
  396. dev_dbg(&host->pdev->dev, "Complete Tx request %p\n",
  397. host->mrq);
  398. }
  399. if (stop) {
  400. if (stop->opcode == MMC_STOP_TRANSMISSION && !stop->arg)
  401. sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x000);
  402. else
  403. BUG();
  404. }
  405. schedule_work(&host->done);
  406. }
  407. static void tmio_mmc_data_irq(struct tmio_mmc_host *host)
  408. {
  409. struct mmc_data *data;
  410. spin_lock(&host->lock);
  411. data = host->data;
  412. if (!data)
  413. goto out;
  414. if (host->chan_tx && (data->flags & MMC_DATA_WRITE) && !host->force_pio) {
  415. /*
  416. * Has all data been written out yet? Testing on SuperH showed,
  417. * that in most cases the first interrupt comes already with the
  418. * BUSY status bit clear, but on some operations, like mount or
  419. * in the beginning of a write / sync / umount, there is one
  420. * DATAEND interrupt with the BUSY bit set, in this cases
  421. * waiting for one more interrupt fixes the problem.
  422. */
  423. if (!(sd_ctrl_read32(host, CTL_STATUS) & TMIO_STAT_CMD_BUSY)) {
  424. tmio_mmc_disable_mmc_irqs(host, TMIO_STAT_DATAEND);
  425. tasklet_schedule(&host->dma_complete);
  426. }
  427. } else if (host->chan_rx && (data->flags & MMC_DATA_READ) && !host->force_pio) {
  428. tmio_mmc_disable_mmc_irqs(host, TMIO_STAT_DATAEND);
  429. tasklet_schedule(&host->dma_complete);
  430. } else {
  431. tmio_mmc_do_data_irq(host);
  432. tmio_mmc_disable_mmc_irqs(host, TMIO_MASK_READOP | TMIO_MASK_WRITEOP);
  433. }
  434. out:
  435. spin_unlock(&host->lock);
  436. }
  437. static void tmio_mmc_cmd_irq(struct tmio_mmc_host *host,
  438. unsigned int stat)
  439. {
  440. struct mmc_command *cmd = host->cmd;
  441. int i, addr;
  442. spin_lock(&host->lock);
  443. if (!host->cmd) {
  444. pr_debug("Spurious CMD irq\n");
  445. goto out;
  446. }
  447. host->cmd = NULL;
  448. /* This controller is sicker than the PXA one. Not only do we need to
  449. * drop the top 8 bits of the first response word, we also need to
  450. * modify the order of the response for short response command types.
  451. */
  452. for (i = 3, addr = CTL_RESPONSE ; i >= 0 ; i--, addr += 4)
  453. cmd->resp[i] = sd_ctrl_read32(host, addr);
  454. if (cmd->flags & MMC_RSP_136) {
  455. cmd->resp[0] = (cmd->resp[0] << 8) | (cmd->resp[1] >> 24);
  456. cmd->resp[1] = (cmd->resp[1] << 8) | (cmd->resp[2] >> 24);
  457. cmd->resp[2] = (cmd->resp[2] << 8) | (cmd->resp[3] >> 24);
  458. cmd->resp[3] <<= 8;
  459. } else if (cmd->flags & MMC_RSP_R3) {
  460. cmd->resp[0] = cmd->resp[3];
  461. }
  462. if (stat & TMIO_STAT_CMDTIMEOUT)
  463. cmd->error = -ETIMEDOUT;
  464. else if (stat & TMIO_STAT_CRCFAIL && cmd->flags & MMC_RSP_CRC)
  465. cmd->error = -EILSEQ;
  466. /* If there is data to handle we enable data IRQs here, and
  467. * we will ultimatley finish the request in the data_end handler.
  468. * If theres no data or we encountered an error, finish now.
  469. */
  470. if (host->data && !cmd->error) {
  471. if (host->data->flags & MMC_DATA_READ) {
  472. if (host->force_pio || !host->chan_rx)
  473. tmio_mmc_enable_mmc_irqs(host, TMIO_MASK_READOP);
  474. else
  475. tasklet_schedule(&host->dma_issue);
  476. } else {
  477. if (host->force_pio || !host->chan_tx)
  478. tmio_mmc_enable_mmc_irqs(host, TMIO_MASK_WRITEOP);
  479. else
  480. tasklet_schedule(&host->dma_issue);
  481. }
  482. } else {
  483. schedule_work(&host->done);
  484. }
  485. out:
  486. spin_unlock(&host->lock);
  487. }
  488. static void tmio_mmc_card_irq_status(struct tmio_mmc_host *host,
  489. int *ireg, int *status)
  490. {
  491. *status = sd_ctrl_read32(host, CTL_STATUS);
  492. *ireg = *status & TMIO_MASK_IRQ & ~host->sdcard_irq_mask;
  493. pr_debug_status(*status);
  494. pr_debug_status(*ireg);
  495. /* Clear the status except the interrupt status */
  496. sd_ctrl_write32(host, CTL_STATUS, TMIO_MASK_IRQ);
  497. }
  498. static bool __tmio_mmc_card_detect_irq(struct tmio_mmc_host *host,
  499. int ireg, int status)
  500. {
  501. struct mmc_host *mmc = host->mmc;
  502. /* Card insert / remove attempts */
  503. if (ireg & (TMIO_STAT_CARD_INSERT | TMIO_STAT_CARD_REMOVE)) {
  504. tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_CARD_INSERT |
  505. TMIO_STAT_CARD_REMOVE);
  506. if ((((ireg & TMIO_STAT_CARD_REMOVE) && mmc->card) ||
  507. ((ireg & TMIO_STAT_CARD_INSERT) && !mmc->card)) &&
  508. !work_pending(&mmc->detect.work))
  509. mmc_detect_change(host->mmc, msecs_to_jiffies(100));
  510. return true;
  511. }
  512. return false;
  513. }
  514. irqreturn_t tmio_mmc_card_detect_irq(int irq, void *devid)
  515. {
  516. unsigned int ireg, status;
  517. struct tmio_mmc_host *host = devid;
  518. tmio_mmc_card_irq_status(host, &ireg, &status);
  519. __tmio_mmc_card_detect_irq(host, ireg, status);
  520. return IRQ_HANDLED;
  521. }
  522. EXPORT_SYMBOL(tmio_mmc_card_detect_irq);
  523. static bool __tmio_mmc_sdcard_irq(struct tmio_mmc_host *host,
  524. int ireg, int status)
  525. {
  526. /* Command completion */
  527. if (ireg & (TMIO_STAT_CMDRESPEND | TMIO_STAT_CMDTIMEOUT)) {
  528. tmio_mmc_ack_mmc_irqs(host,
  529. TMIO_STAT_CMDRESPEND |
  530. TMIO_STAT_CMDTIMEOUT);
  531. tmio_mmc_cmd_irq(host, status);
  532. return true;
  533. }
  534. /* Data transfer */
  535. if (ireg & (TMIO_STAT_RXRDY | TMIO_STAT_TXRQ)) {
  536. tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_RXRDY | TMIO_STAT_TXRQ);
  537. tmio_mmc_pio_irq(host);
  538. return true;
  539. }
  540. /* Data transfer completion */
  541. if (ireg & TMIO_STAT_DATAEND) {
  542. tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_DATAEND);
  543. tmio_mmc_data_irq(host);
  544. return true;
  545. }
  546. return false;
  547. }
  548. irqreturn_t tmio_mmc_sdcard_irq(int irq, void *devid)
  549. {
  550. unsigned int ireg, status;
  551. struct tmio_mmc_host *host = devid;
  552. tmio_mmc_card_irq_status(host, &ireg, &status);
  553. __tmio_mmc_sdcard_irq(host, ireg, status);
  554. return IRQ_HANDLED;
  555. }
  556. EXPORT_SYMBOL(tmio_mmc_sdcard_irq);
  557. irqreturn_t tmio_mmc_sdio_irq(int irq, void *devid)
  558. {
  559. struct tmio_mmc_host *host = devid;
  560. struct mmc_host *mmc = host->mmc;
  561. struct tmio_mmc_data *pdata = host->pdata;
  562. unsigned int ireg, status;
  563. unsigned int sdio_status;
  564. if (!(pdata->flags & TMIO_MMC_SDIO_IRQ))
  565. return IRQ_HANDLED;
  566. status = sd_ctrl_read16(host, CTL_SDIO_STATUS);
  567. ireg = status & TMIO_SDIO_MASK_ALL & ~host->sdcard_irq_mask;
  568. sdio_status = status & ~TMIO_SDIO_MASK_ALL;
  569. if (pdata->flags & TMIO_MMC_SDIO_STATUS_QUIRK)
  570. sdio_status |= 6;
  571. sd_ctrl_write16(host, CTL_SDIO_STATUS, sdio_status);
  572. if (mmc->caps & MMC_CAP_SDIO_IRQ && ireg & TMIO_SDIO_STAT_IOIRQ)
  573. mmc_signal_sdio_irq(mmc);
  574. return IRQ_HANDLED;
  575. }
  576. EXPORT_SYMBOL(tmio_mmc_sdio_irq);
  577. irqreturn_t tmio_mmc_irq(int irq, void *devid)
  578. {
  579. struct tmio_mmc_host *host = devid;
  580. unsigned int ireg, status;
  581. pr_debug("MMC IRQ begin\n");
  582. tmio_mmc_card_irq_status(host, &ireg, &status);
  583. if (__tmio_mmc_card_detect_irq(host, ireg, status))
  584. return IRQ_HANDLED;
  585. if (__tmio_mmc_sdcard_irq(host, ireg, status))
  586. return IRQ_HANDLED;
  587. tmio_mmc_sdio_irq(irq, devid);
  588. return IRQ_HANDLED;
  589. }
  590. EXPORT_SYMBOL(tmio_mmc_irq);
  591. static int tmio_mmc_start_data(struct tmio_mmc_host *host,
  592. struct mmc_data *data)
  593. {
  594. struct tmio_mmc_data *pdata = host->pdata;
  595. pr_debug("setup data transfer: blocksize %08x nr_blocks %d\n",
  596. data->blksz, data->blocks);
  597. /* Some hardware cannot perform 2 byte requests in 4 bit mode */
  598. if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_4) {
  599. int blksz_2bytes = pdata->flags & TMIO_MMC_BLKSZ_2BYTES;
  600. if (data->blksz < 2 || (data->blksz < 4 && !blksz_2bytes)) {
  601. pr_err("%s: %d byte block unsupported in 4 bit mode\n",
  602. mmc_hostname(host->mmc), data->blksz);
  603. return -EINVAL;
  604. }
  605. }
  606. tmio_mmc_init_sg(host, data);
  607. host->data = data;
  608. /* Set transfer length / blocksize */
  609. sd_ctrl_write16(host, CTL_SD_XFER_LEN, data->blksz);
  610. sd_ctrl_write16(host, CTL_XFER_BLK_COUNT, data->blocks);
  611. tmio_mmc_start_dma(host, data);
  612. return 0;
  613. }
  614. /* Process requests from the MMC layer */
  615. static void tmio_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
  616. {
  617. struct tmio_mmc_host *host = mmc_priv(mmc);
  618. unsigned long flags;
  619. int ret;
  620. spin_lock_irqsave(&host->lock, flags);
  621. if (host->mrq) {
  622. pr_debug("request not null\n");
  623. if (IS_ERR(host->mrq)) {
  624. spin_unlock_irqrestore(&host->lock, flags);
  625. mrq->cmd->error = -EAGAIN;
  626. mmc_request_done(mmc, mrq);
  627. return;
  628. }
  629. }
  630. host->last_req_ts = jiffies;
  631. wmb();
  632. host->mrq = mrq;
  633. spin_unlock_irqrestore(&host->lock, flags);
  634. pm_runtime_get_sync(mmc_dev(mmc));
  635. if (mrq->data) {
  636. ret = tmio_mmc_start_data(host, mrq->data);
  637. if (ret)
  638. goto fail;
  639. }
  640. ret = tmio_mmc_start_command(host, mrq->cmd);
  641. if (!ret) {
  642. schedule_delayed_work(&host->delayed_reset_work,
  643. msecs_to_jiffies(2000));
  644. return;
  645. }
  646. fail:
  647. host->force_pio = false;
  648. host->mrq = NULL;
  649. mrq->cmd->error = ret;
  650. mmc_request_done(mmc, mrq);
  651. pm_runtime_mark_last_busy(mmc_dev(mmc));
  652. pm_runtime_put_autosuspend(mmc_dev(mmc));
  653. }
  654. static int tmio_mmc_clk_update(struct tmio_mmc_host *host)
  655. {
  656. struct mmc_host *mmc = host->mmc;
  657. struct tmio_mmc_data *pdata = host->pdata;
  658. int ret;
  659. if (!pdata->clk_enable)
  660. return -ENOTSUPP;
  661. ret = pdata->clk_enable(host->pdev, &mmc->f_max);
  662. if (!ret)
  663. mmc->f_min = mmc->f_max / 512;
  664. return ret;
  665. }
  666. static void tmio_mmc_power_on(struct tmio_mmc_host *host, unsigned short vdd)
  667. {
  668. struct mmc_host *mmc = host->mmc;
  669. int ret = 0;
  670. /* .set_ios() is returning void, so, no chance to report an error */
  671. if (host->set_pwr)
  672. host->set_pwr(host->pdev, 1);
  673. if (!IS_ERR(mmc->supply.vmmc)) {
  674. ret = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd);
  675. /*
  676. * Attention: empiric value. With a b43 WiFi SDIO card this
  677. * delay proved necessary for reliable card-insertion probing.
  678. * 100us were not enough. Is this the same 140us delay, as in
  679. * tmio_mmc_set_ios()?
  680. */
  681. udelay(200);
  682. }
  683. /*
  684. * It seems, VccQ should be switched on after Vcc, this is also what the
  685. * omap_hsmmc.c driver does.
  686. */
  687. if (!IS_ERR(mmc->supply.vqmmc) && !ret) {
  688. ret = regulator_enable(mmc->supply.vqmmc);
  689. udelay(200);
  690. }
  691. if (ret < 0)
  692. dev_dbg(&host->pdev->dev, "Regulators failed to power up: %d\n",
  693. ret);
  694. }
  695. static void tmio_mmc_power_off(struct tmio_mmc_host *host)
  696. {
  697. struct mmc_host *mmc = host->mmc;
  698. if (!IS_ERR(mmc->supply.vqmmc))
  699. regulator_disable(mmc->supply.vqmmc);
  700. if (!IS_ERR(mmc->supply.vmmc))
  701. mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
  702. if (host->set_pwr)
  703. host->set_pwr(host->pdev, 0);
  704. }
  705. static void tmio_mmc_set_bus_width(struct tmio_mmc_host *host,
  706. unsigned char bus_width)
  707. {
  708. switch (bus_width) {
  709. case MMC_BUS_WIDTH_1:
  710. sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x80e0);
  711. break;
  712. case MMC_BUS_WIDTH_4:
  713. sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x00e0);
  714. break;
  715. }
  716. }
  717. /* Set MMC clock / power.
  718. * Note: This controller uses a simple divider scheme therefore it cannot
  719. * run a MMC card at full speed (20MHz). The max clock is 24MHz on SD, but as
  720. * MMC wont run that fast, it has to be clocked at 12MHz which is the next
  721. * slowest setting.
  722. */
  723. static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  724. {
  725. struct tmio_mmc_host *host = mmc_priv(mmc);
  726. struct device *dev = &host->pdev->dev;
  727. unsigned long flags;
  728. pm_runtime_get_sync(mmc_dev(mmc));
  729. mutex_lock(&host->ios_lock);
  730. spin_lock_irqsave(&host->lock, flags);
  731. if (host->mrq) {
  732. if (IS_ERR(host->mrq)) {
  733. dev_dbg(dev,
  734. "%s.%d: concurrent .set_ios(), clk %u, mode %u\n",
  735. current->comm, task_pid_nr(current),
  736. ios->clock, ios->power_mode);
  737. host->mrq = ERR_PTR(-EINTR);
  738. } else {
  739. dev_dbg(dev,
  740. "%s.%d: CMD%u active since %lu, now %lu!\n",
  741. current->comm, task_pid_nr(current),
  742. host->mrq->cmd->opcode, host->last_req_ts, jiffies);
  743. }
  744. spin_unlock_irqrestore(&host->lock, flags);
  745. mutex_unlock(&host->ios_lock);
  746. return;
  747. }
  748. host->mrq = ERR_PTR(-EBUSY);
  749. spin_unlock_irqrestore(&host->lock, flags);
  750. switch (ios->power_mode) {
  751. case MMC_POWER_OFF:
  752. tmio_mmc_power_off(host);
  753. tmio_mmc_clk_stop(host);
  754. break;
  755. case MMC_POWER_UP:
  756. tmio_mmc_set_clock(host, ios->clock);
  757. tmio_mmc_power_on(host, ios->vdd);
  758. tmio_mmc_clk_start(host);
  759. tmio_mmc_set_bus_width(host, ios->bus_width);
  760. break;
  761. case MMC_POWER_ON:
  762. tmio_mmc_set_clock(host, ios->clock);
  763. tmio_mmc_clk_start(host);
  764. tmio_mmc_set_bus_width(host, ios->bus_width);
  765. break;
  766. }
  767. /* Let things settle. delay taken from winCE driver */
  768. udelay(140);
  769. if (PTR_ERR(host->mrq) == -EINTR)
  770. dev_dbg(&host->pdev->dev,
  771. "%s.%d: IOS interrupted: clk %u, mode %u",
  772. current->comm, task_pid_nr(current),
  773. ios->clock, ios->power_mode);
  774. host->mrq = NULL;
  775. host->clk_cache = ios->clock;
  776. mutex_unlock(&host->ios_lock);
  777. pm_runtime_mark_last_busy(mmc_dev(mmc));
  778. pm_runtime_put_autosuspend(mmc_dev(mmc));
  779. }
  780. static int tmio_mmc_get_ro(struct mmc_host *mmc)
  781. {
  782. struct tmio_mmc_host *host = mmc_priv(mmc);
  783. struct tmio_mmc_data *pdata = host->pdata;
  784. int ret = mmc_gpio_get_ro(mmc);
  785. if (ret >= 0)
  786. return ret;
  787. pm_runtime_get_sync(mmc_dev(mmc));
  788. ret = !((pdata->flags & TMIO_MMC_WRPROTECT_DISABLE) ||
  789. (sd_ctrl_read32(host, CTL_STATUS) & TMIO_STAT_WRPROTECT));
  790. pm_runtime_mark_last_busy(mmc_dev(mmc));
  791. pm_runtime_put_autosuspend(mmc_dev(mmc));
  792. return ret;
  793. }
  794. static const struct mmc_host_ops tmio_mmc_ops = {
  795. .request = tmio_mmc_request,
  796. .set_ios = tmio_mmc_set_ios,
  797. .get_ro = tmio_mmc_get_ro,
  798. .get_cd = mmc_gpio_get_cd,
  799. .enable_sdio_irq = tmio_mmc_enable_sdio_irq,
  800. };
  801. static int tmio_mmc_init_ocr(struct tmio_mmc_host *host)
  802. {
  803. struct tmio_mmc_data *pdata = host->pdata;
  804. struct mmc_host *mmc = host->mmc;
  805. mmc_regulator_get_supply(mmc);
  806. /* use ocr_mask if no regulator */
  807. if (!mmc->ocr_avail)
  808. mmc->ocr_avail = pdata->ocr_mask;
  809. /*
  810. * try again.
  811. * There is possibility that regulator has not been probed
  812. */
  813. if (!mmc->ocr_avail)
  814. return -EPROBE_DEFER;
  815. return 0;
  816. }
  817. static void tmio_mmc_of_parse(struct platform_device *pdev,
  818. struct tmio_mmc_data *pdata)
  819. {
  820. const struct device_node *np = pdev->dev.of_node;
  821. if (!np)
  822. return;
  823. if (of_get_property(np, "toshiba,mmc-wrprotect-disable", NULL))
  824. pdata->flags |= TMIO_MMC_WRPROTECT_DISABLE;
  825. }
  826. int tmio_mmc_host_probe(struct tmio_mmc_host **host,
  827. struct platform_device *pdev,
  828. struct tmio_mmc_data *pdata)
  829. {
  830. struct tmio_mmc_host *_host;
  831. struct mmc_host *mmc;
  832. struct resource *res_ctl;
  833. int ret;
  834. u32 irq_mask = TMIO_MASK_CMD;
  835. tmio_mmc_of_parse(pdev, pdata);
  836. if (!(pdata->flags & TMIO_MMC_HAS_IDLE_WAIT))
  837. pdata->write16_hook = NULL;
  838. res_ctl = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  839. if (!res_ctl)
  840. return -EINVAL;
  841. mmc = mmc_alloc_host(sizeof(struct tmio_mmc_host), &pdev->dev);
  842. if (!mmc)
  843. return -ENOMEM;
  844. ret = mmc_of_parse(mmc);
  845. if (ret < 0)
  846. goto host_free;
  847. pdata->dev = &pdev->dev;
  848. _host = mmc_priv(mmc);
  849. _host->pdata = pdata;
  850. _host->mmc = mmc;
  851. _host->pdev = pdev;
  852. platform_set_drvdata(pdev, mmc);
  853. _host->set_pwr = pdata->set_pwr;
  854. _host->set_clk_div = pdata->set_clk_div;
  855. ret = tmio_mmc_init_ocr(_host);
  856. if (ret < 0)
  857. goto host_free;
  858. _host->ctl = ioremap(res_ctl->start, resource_size(res_ctl));
  859. if (!_host->ctl) {
  860. ret = -ENOMEM;
  861. goto host_free;
  862. }
  863. mmc->ops = &tmio_mmc_ops;
  864. mmc->caps |= MMC_CAP_4_BIT_DATA | pdata->capabilities;
  865. mmc->caps2 |= pdata->capabilities2;
  866. mmc->max_segs = 32;
  867. mmc->max_blk_size = 512;
  868. mmc->max_blk_count = (PAGE_CACHE_SIZE / mmc->max_blk_size) *
  869. mmc->max_segs;
  870. mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
  871. mmc->max_seg_size = mmc->max_req_size;
  872. _host->native_hotplug = !(pdata->flags & TMIO_MMC_USE_GPIO_CD ||
  873. mmc->caps & MMC_CAP_NEEDS_POLL ||
  874. mmc->caps & MMC_CAP_NONREMOVABLE ||
  875. mmc->slot.cd_irq >= 0);
  876. if (tmio_mmc_clk_update(_host) < 0) {
  877. mmc->f_max = pdata->hclk;
  878. mmc->f_min = mmc->f_max / 512;
  879. }
  880. /*
  881. * While using internal tmio hardware logic for card detection, we need
  882. * to ensure it stays powered for it to work.
  883. */
  884. if (_host->native_hotplug)
  885. pm_runtime_get_noresume(&pdev->dev);
  886. tmio_mmc_clk_stop(_host);
  887. tmio_mmc_reset(_host);
  888. _host->sdcard_irq_mask = sd_ctrl_read32(_host, CTL_IRQ_MASK);
  889. tmio_mmc_disable_mmc_irqs(_host, TMIO_MASK_ALL);
  890. /* Unmask the IRQs we want to know about */
  891. if (!_host->chan_rx)
  892. irq_mask |= TMIO_MASK_READOP;
  893. if (!_host->chan_tx)
  894. irq_mask |= TMIO_MASK_WRITEOP;
  895. if (!_host->native_hotplug)
  896. irq_mask &= ~(TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT);
  897. _host->sdcard_irq_mask &= ~irq_mask;
  898. _host->sdio_irq_enabled = false;
  899. if (pdata->flags & TMIO_MMC_SDIO_IRQ) {
  900. _host->sdio_irq_mask = TMIO_SDIO_MASK_ALL;
  901. sd_ctrl_write16(_host, CTL_SDIO_IRQ_MASK, _host->sdio_irq_mask);
  902. sd_ctrl_write16(_host, CTL_TRANSACTION_CTL, 0x0000);
  903. }
  904. spin_lock_init(&_host->lock);
  905. mutex_init(&_host->ios_lock);
  906. /* Init delayed work for request timeouts */
  907. INIT_DELAYED_WORK(&_host->delayed_reset_work, tmio_mmc_reset_work);
  908. INIT_WORK(&_host->done, tmio_mmc_done_work);
  909. /* See if we also get DMA */
  910. tmio_mmc_request_dma(_host, pdata);
  911. pm_runtime_set_active(&pdev->dev);
  912. pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
  913. pm_runtime_use_autosuspend(&pdev->dev);
  914. pm_runtime_enable(&pdev->dev);
  915. ret = mmc_add_host(mmc);
  916. if (ret < 0) {
  917. tmio_mmc_host_remove(_host);
  918. return ret;
  919. }
  920. dev_pm_qos_expose_latency_limit(&pdev->dev, 100);
  921. if (pdata->flags & TMIO_MMC_USE_GPIO_CD) {
  922. ret = mmc_gpio_request_cd(mmc, pdata->cd_gpio, 0);
  923. if (ret < 0) {
  924. tmio_mmc_host_remove(_host);
  925. return ret;
  926. }
  927. }
  928. *host = _host;
  929. return 0;
  930. host_free:
  931. mmc_free_host(mmc);
  932. return ret;
  933. }
  934. EXPORT_SYMBOL(tmio_mmc_host_probe);
  935. void tmio_mmc_host_remove(struct tmio_mmc_host *host)
  936. {
  937. struct platform_device *pdev = host->pdev;
  938. struct mmc_host *mmc = host->mmc;
  939. if (!host->native_hotplug)
  940. pm_runtime_get_sync(&pdev->dev);
  941. dev_pm_qos_hide_latency_limit(&pdev->dev);
  942. mmc_remove_host(mmc);
  943. cancel_work_sync(&host->done);
  944. cancel_delayed_work_sync(&host->delayed_reset_work);
  945. tmio_mmc_release_dma(host);
  946. pm_runtime_put_sync(&pdev->dev);
  947. pm_runtime_disable(&pdev->dev);
  948. iounmap(host->ctl);
  949. mmc_free_host(mmc);
  950. }
  951. EXPORT_SYMBOL(tmio_mmc_host_remove);
  952. #ifdef CONFIG_PM
  953. int tmio_mmc_host_runtime_suspend(struct device *dev)
  954. {
  955. struct mmc_host *mmc = dev_get_drvdata(dev);
  956. struct tmio_mmc_host *host = mmc_priv(mmc);
  957. tmio_mmc_disable_mmc_irqs(host, TMIO_MASK_ALL);
  958. if (host->clk_cache)
  959. tmio_mmc_clk_stop(host);
  960. if (host->pdata->clk_disable)
  961. host->pdata->clk_disable(host->pdev);
  962. return 0;
  963. }
  964. EXPORT_SYMBOL(tmio_mmc_host_runtime_suspend);
  965. int tmio_mmc_host_runtime_resume(struct device *dev)
  966. {
  967. struct mmc_host *mmc = dev_get_drvdata(dev);
  968. struct tmio_mmc_host *host = mmc_priv(mmc);
  969. tmio_mmc_reset(host);
  970. tmio_mmc_clk_update(host);
  971. if (host->clk_cache) {
  972. tmio_mmc_set_clock(host, host->clk_cache);
  973. tmio_mmc_clk_start(host);
  974. }
  975. tmio_mmc_enable_dma(host, true);
  976. return 0;
  977. }
  978. EXPORT_SYMBOL(tmio_mmc_host_runtime_resume);
  979. #endif
  980. MODULE_LICENSE("GPL v2");