tmio_mmc_pio.c 31 KB

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