dw_mmc.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453
  1. /*
  2. * Synopsys DesignWare Multimedia Card Interface driver
  3. * (Based on NXP driver for lpc 31xx)
  4. *
  5. * Copyright (C) 2009 NXP Semiconductors
  6. * Copyright (C) 2009, 2010 Imagination Technologies Ltd.
  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 as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/blkdev.h>
  14. #include <linux/clk.h>
  15. #include <linux/debugfs.h>
  16. #include <linux/device.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/err.h>
  19. #include <linux/init.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/ioport.h>
  22. #include <linux/module.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/seq_file.h>
  25. #include <linux/slab.h>
  26. #include <linux/stat.h>
  27. #include <linux/delay.h>
  28. #include <linux/irq.h>
  29. #include <linux/mmc/host.h>
  30. #include <linux/mmc/mmc.h>
  31. #include <linux/mmc/dw_mmc.h>
  32. #include <linux/bitops.h>
  33. #include <linux/regulator/consumer.h>
  34. #include <linux/workqueue.h>
  35. #include <linux/of.h>
  36. #include "dw_mmc.h"
  37. /* Common flag combinations */
  38. #define DW_MCI_DATA_ERROR_FLAGS (SDMMC_INT_DTO | SDMMC_INT_DCRC | \
  39. SDMMC_INT_HTO | SDMMC_INT_SBE | \
  40. SDMMC_INT_EBE)
  41. #define DW_MCI_CMD_ERROR_FLAGS (SDMMC_INT_RTO | SDMMC_INT_RCRC | \
  42. SDMMC_INT_RESP_ERR)
  43. #define DW_MCI_ERROR_FLAGS (DW_MCI_DATA_ERROR_FLAGS | \
  44. DW_MCI_CMD_ERROR_FLAGS | SDMMC_INT_HLE)
  45. #define DW_MCI_SEND_STATUS 1
  46. #define DW_MCI_RECV_STATUS 2
  47. #define DW_MCI_DMA_THRESHOLD 16
  48. #ifdef CONFIG_MMC_DW_IDMAC
  49. struct idmac_desc {
  50. u32 des0; /* Control Descriptor */
  51. #define IDMAC_DES0_DIC BIT(1)
  52. #define IDMAC_DES0_LD BIT(2)
  53. #define IDMAC_DES0_FD BIT(3)
  54. #define IDMAC_DES0_CH BIT(4)
  55. #define IDMAC_DES0_ER BIT(5)
  56. #define IDMAC_DES0_CES BIT(30)
  57. #define IDMAC_DES0_OWN BIT(31)
  58. u32 des1; /* Buffer sizes */
  59. #define IDMAC_SET_BUFFER1_SIZE(d, s) \
  60. ((d)->des1 = ((d)->des1 & 0x03ffe000) | ((s) & 0x1fff))
  61. u32 des2; /* buffer 1 physical address */
  62. u32 des3; /* buffer 2 physical address */
  63. };
  64. #endif /* CONFIG_MMC_DW_IDMAC */
  65. /**
  66. * struct dw_mci_slot - MMC slot state
  67. * @mmc: The mmc_host representing this slot.
  68. * @host: The MMC controller this slot is using.
  69. * @ctype: Card type for this slot.
  70. * @mrq: mmc_request currently being processed or waiting to be
  71. * processed, or NULL when the slot is idle.
  72. * @queue_node: List node for placing this node in the @queue list of
  73. * &struct dw_mci.
  74. * @clock: Clock rate configured by set_ios(). Protected by host->lock.
  75. * @flags: Random state bits associated with the slot.
  76. * @id: Number of this slot.
  77. * @last_detect_state: Most recently observed card detect state.
  78. */
  79. struct dw_mci_slot {
  80. struct mmc_host *mmc;
  81. struct dw_mci *host;
  82. u32 ctype;
  83. struct mmc_request *mrq;
  84. struct list_head queue_node;
  85. unsigned int clock;
  86. unsigned long flags;
  87. #define DW_MMC_CARD_PRESENT 0
  88. #define DW_MMC_CARD_NEED_INIT 1
  89. int id;
  90. int last_detect_state;
  91. };
  92. #if defined(CONFIG_DEBUG_FS)
  93. static int dw_mci_req_show(struct seq_file *s, void *v)
  94. {
  95. struct dw_mci_slot *slot = s->private;
  96. struct mmc_request *mrq;
  97. struct mmc_command *cmd;
  98. struct mmc_command *stop;
  99. struct mmc_data *data;
  100. /* Make sure we get a consistent snapshot */
  101. spin_lock_bh(&slot->host->lock);
  102. mrq = slot->mrq;
  103. if (mrq) {
  104. cmd = mrq->cmd;
  105. data = mrq->data;
  106. stop = mrq->stop;
  107. if (cmd)
  108. seq_printf(s,
  109. "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
  110. cmd->opcode, cmd->arg, cmd->flags,
  111. cmd->resp[0], cmd->resp[1], cmd->resp[2],
  112. cmd->resp[2], cmd->error);
  113. if (data)
  114. seq_printf(s, "DATA %u / %u * %u flg %x err %d\n",
  115. data->bytes_xfered, data->blocks,
  116. data->blksz, data->flags, data->error);
  117. if (stop)
  118. seq_printf(s,
  119. "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
  120. stop->opcode, stop->arg, stop->flags,
  121. stop->resp[0], stop->resp[1], stop->resp[2],
  122. stop->resp[2], stop->error);
  123. }
  124. spin_unlock_bh(&slot->host->lock);
  125. return 0;
  126. }
  127. static int dw_mci_req_open(struct inode *inode, struct file *file)
  128. {
  129. return single_open(file, dw_mci_req_show, inode->i_private);
  130. }
  131. static const struct file_operations dw_mci_req_fops = {
  132. .owner = THIS_MODULE,
  133. .open = dw_mci_req_open,
  134. .read = seq_read,
  135. .llseek = seq_lseek,
  136. .release = single_release,
  137. };
  138. static int dw_mci_regs_show(struct seq_file *s, void *v)
  139. {
  140. seq_printf(s, "STATUS:\t0x%08x\n", SDMMC_STATUS);
  141. seq_printf(s, "RINTSTS:\t0x%08x\n", SDMMC_RINTSTS);
  142. seq_printf(s, "CMD:\t0x%08x\n", SDMMC_CMD);
  143. seq_printf(s, "CTRL:\t0x%08x\n", SDMMC_CTRL);
  144. seq_printf(s, "INTMASK:\t0x%08x\n", SDMMC_INTMASK);
  145. seq_printf(s, "CLKENA:\t0x%08x\n", SDMMC_CLKENA);
  146. return 0;
  147. }
  148. static int dw_mci_regs_open(struct inode *inode, struct file *file)
  149. {
  150. return single_open(file, dw_mci_regs_show, inode->i_private);
  151. }
  152. static const struct file_operations dw_mci_regs_fops = {
  153. .owner = THIS_MODULE,
  154. .open = dw_mci_regs_open,
  155. .read = seq_read,
  156. .llseek = seq_lseek,
  157. .release = single_release,
  158. };
  159. static void dw_mci_init_debugfs(struct dw_mci_slot *slot)
  160. {
  161. struct mmc_host *mmc = slot->mmc;
  162. struct dw_mci *host = slot->host;
  163. struct dentry *root;
  164. struct dentry *node;
  165. root = mmc->debugfs_root;
  166. if (!root)
  167. return;
  168. node = debugfs_create_file("regs", S_IRUSR, root, host,
  169. &dw_mci_regs_fops);
  170. if (!node)
  171. goto err;
  172. node = debugfs_create_file("req", S_IRUSR, root, slot,
  173. &dw_mci_req_fops);
  174. if (!node)
  175. goto err;
  176. node = debugfs_create_u32("state", S_IRUSR, root, (u32 *)&host->state);
  177. if (!node)
  178. goto err;
  179. node = debugfs_create_x32("pending_events", S_IRUSR, root,
  180. (u32 *)&host->pending_events);
  181. if (!node)
  182. goto err;
  183. node = debugfs_create_x32("completed_events", S_IRUSR, root,
  184. (u32 *)&host->completed_events);
  185. if (!node)
  186. goto err;
  187. return;
  188. err:
  189. dev_err(&mmc->class_dev, "failed to initialize debugfs for slot\n");
  190. }
  191. #endif /* defined(CONFIG_DEBUG_FS) */
  192. static void dw_mci_set_timeout(struct dw_mci *host)
  193. {
  194. /* timeout (maximum) */
  195. mci_writel(host, TMOUT, 0xffffffff);
  196. }
  197. static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
  198. {
  199. struct mmc_data *data;
  200. struct dw_mci_slot *slot = mmc_priv(mmc);
  201. const struct dw_mci_drv_data *drv_data = slot->host->drv_data;
  202. u32 cmdr;
  203. cmd->error = -EINPROGRESS;
  204. cmdr = cmd->opcode;
  205. if (cmdr == MMC_STOP_TRANSMISSION)
  206. cmdr |= SDMMC_CMD_STOP;
  207. else
  208. cmdr |= SDMMC_CMD_PRV_DAT_WAIT;
  209. if (cmd->flags & MMC_RSP_PRESENT) {
  210. /* We expect a response, so set this bit */
  211. cmdr |= SDMMC_CMD_RESP_EXP;
  212. if (cmd->flags & MMC_RSP_136)
  213. cmdr |= SDMMC_CMD_RESP_LONG;
  214. }
  215. if (cmd->flags & MMC_RSP_CRC)
  216. cmdr |= SDMMC_CMD_RESP_CRC;
  217. data = cmd->data;
  218. if (data) {
  219. cmdr |= SDMMC_CMD_DAT_EXP;
  220. if (data->flags & MMC_DATA_STREAM)
  221. cmdr |= SDMMC_CMD_STRM_MODE;
  222. if (data->flags & MMC_DATA_WRITE)
  223. cmdr |= SDMMC_CMD_DAT_WR;
  224. }
  225. if (drv_data && drv_data->prepare_command)
  226. drv_data->prepare_command(slot->host, &cmdr);
  227. return cmdr;
  228. }
  229. static void dw_mci_start_command(struct dw_mci *host,
  230. struct mmc_command *cmd, u32 cmd_flags)
  231. {
  232. host->cmd = cmd;
  233. dev_vdbg(host->dev,
  234. "start command: ARGR=0x%08x CMDR=0x%08x\n",
  235. cmd->arg, cmd_flags);
  236. mci_writel(host, CMDARG, cmd->arg);
  237. wmb();
  238. mci_writel(host, CMD, cmd_flags | SDMMC_CMD_START);
  239. }
  240. static void send_stop_cmd(struct dw_mci *host, struct mmc_data *data)
  241. {
  242. dw_mci_start_command(host, data->stop, host->stop_cmdr);
  243. }
  244. /* DMA interface functions */
  245. static void dw_mci_stop_dma(struct dw_mci *host)
  246. {
  247. if (host->using_dma) {
  248. host->dma_ops->stop(host);
  249. host->dma_ops->cleanup(host);
  250. } else {
  251. /* Data transfer was stopped by the interrupt handler */
  252. set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
  253. }
  254. }
  255. static int dw_mci_get_dma_dir(struct mmc_data *data)
  256. {
  257. if (data->flags & MMC_DATA_WRITE)
  258. return DMA_TO_DEVICE;
  259. else
  260. return DMA_FROM_DEVICE;
  261. }
  262. #ifdef CONFIG_MMC_DW_IDMAC
  263. static void dw_mci_dma_cleanup(struct dw_mci *host)
  264. {
  265. struct mmc_data *data = host->data;
  266. if (data)
  267. if (!data->host_cookie)
  268. dma_unmap_sg(host->dev,
  269. data->sg,
  270. data->sg_len,
  271. dw_mci_get_dma_dir(data));
  272. }
  273. static void dw_mci_idmac_stop_dma(struct dw_mci *host)
  274. {
  275. u32 temp;
  276. /* Disable and reset the IDMAC interface */
  277. temp = mci_readl(host, CTRL);
  278. temp &= ~SDMMC_CTRL_USE_IDMAC;
  279. temp |= SDMMC_CTRL_DMA_RESET;
  280. mci_writel(host, CTRL, temp);
  281. /* Stop the IDMAC running */
  282. temp = mci_readl(host, BMOD);
  283. temp &= ~(SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB);
  284. mci_writel(host, BMOD, temp);
  285. }
  286. static void dw_mci_idmac_complete_dma(struct dw_mci *host)
  287. {
  288. struct mmc_data *data = host->data;
  289. dev_vdbg(host->dev, "DMA complete\n");
  290. host->dma_ops->cleanup(host);
  291. /*
  292. * If the card was removed, data will be NULL. No point in trying to
  293. * send the stop command or waiting for NBUSY in this case.
  294. */
  295. if (data) {
  296. set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
  297. tasklet_schedule(&host->tasklet);
  298. }
  299. }
  300. static void dw_mci_translate_sglist(struct dw_mci *host, struct mmc_data *data,
  301. unsigned int sg_len)
  302. {
  303. int i;
  304. struct idmac_desc *desc = host->sg_cpu;
  305. for (i = 0; i < sg_len; i++, desc++) {
  306. unsigned int length = sg_dma_len(&data->sg[i]);
  307. u32 mem_addr = sg_dma_address(&data->sg[i]);
  308. /* Set the OWN bit and disable interrupts for this descriptor */
  309. desc->des0 = IDMAC_DES0_OWN | IDMAC_DES0_DIC | IDMAC_DES0_CH;
  310. /* Buffer length */
  311. IDMAC_SET_BUFFER1_SIZE(desc, length);
  312. /* Physical address to DMA to/from */
  313. desc->des2 = mem_addr;
  314. }
  315. /* Set first descriptor */
  316. desc = host->sg_cpu;
  317. desc->des0 |= IDMAC_DES0_FD;
  318. /* Set last descriptor */
  319. desc = host->sg_cpu + (i - 1) * sizeof(struct idmac_desc);
  320. desc->des0 &= ~(IDMAC_DES0_CH | IDMAC_DES0_DIC);
  321. desc->des0 |= IDMAC_DES0_LD;
  322. wmb();
  323. }
  324. static void dw_mci_idmac_start_dma(struct dw_mci *host, unsigned int sg_len)
  325. {
  326. u32 temp;
  327. dw_mci_translate_sglist(host, host->data, sg_len);
  328. /* Select IDMAC interface */
  329. temp = mci_readl(host, CTRL);
  330. temp |= SDMMC_CTRL_USE_IDMAC;
  331. mci_writel(host, CTRL, temp);
  332. wmb();
  333. /* Enable the IDMAC */
  334. temp = mci_readl(host, BMOD);
  335. temp |= SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB;
  336. mci_writel(host, BMOD, temp);
  337. /* Start it running */
  338. mci_writel(host, PLDMND, 1);
  339. }
  340. static int dw_mci_idmac_init(struct dw_mci *host)
  341. {
  342. struct idmac_desc *p;
  343. int i;
  344. /* Number of descriptors in the ring buffer */
  345. host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc);
  346. /* Forward link the descriptor list */
  347. for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++)
  348. p->des3 = host->sg_dma + (sizeof(struct idmac_desc) * (i + 1));
  349. /* Set the last descriptor as the end-of-ring descriptor */
  350. p->des3 = host->sg_dma;
  351. p->des0 = IDMAC_DES0_ER;
  352. mci_writel(host, BMOD, SDMMC_IDMAC_SWRESET);
  353. /* Mask out interrupts - get Tx & Rx complete only */
  354. mci_writel(host, IDINTEN, SDMMC_IDMAC_INT_NI | SDMMC_IDMAC_INT_RI |
  355. SDMMC_IDMAC_INT_TI);
  356. /* Set the descriptor base address */
  357. mci_writel(host, DBADDR, host->sg_dma);
  358. return 0;
  359. }
  360. static const struct dw_mci_dma_ops dw_mci_idmac_ops = {
  361. .init = dw_mci_idmac_init,
  362. .start = dw_mci_idmac_start_dma,
  363. .stop = dw_mci_idmac_stop_dma,
  364. .complete = dw_mci_idmac_complete_dma,
  365. .cleanup = dw_mci_dma_cleanup,
  366. };
  367. #endif /* CONFIG_MMC_DW_IDMAC */
  368. static int dw_mci_pre_dma_transfer(struct dw_mci *host,
  369. struct mmc_data *data,
  370. bool next)
  371. {
  372. struct scatterlist *sg;
  373. unsigned int i, sg_len;
  374. if (!next && data->host_cookie)
  375. return data->host_cookie;
  376. /*
  377. * We don't do DMA on "complex" transfers, i.e. with
  378. * non-word-aligned buffers or lengths. Also, we don't bother
  379. * with all the DMA setup overhead for short transfers.
  380. */
  381. if (data->blocks * data->blksz < DW_MCI_DMA_THRESHOLD)
  382. return -EINVAL;
  383. if (data->blksz & 3)
  384. return -EINVAL;
  385. for_each_sg(data->sg, sg, data->sg_len, i) {
  386. if (sg->offset & 3 || sg->length & 3)
  387. return -EINVAL;
  388. }
  389. sg_len = dma_map_sg(host->dev,
  390. data->sg,
  391. data->sg_len,
  392. dw_mci_get_dma_dir(data));
  393. if (sg_len == 0)
  394. return -EINVAL;
  395. if (next)
  396. data->host_cookie = sg_len;
  397. return sg_len;
  398. }
  399. static void dw_mci_pre_req(struct mmc_host *mmc,
  400. struct mmc_request *mrq,
  401. bool is_first_req)
  402. {
  403. struct dw_mci_slot *slot = mmc_priv(mmc);
  404. struct mmc_data *data = mrq->data;
  405. if (!slot->host->use_dma || !data)
  406. return;
  407. if (data->host_cookie) {
  408. data->host_cookie = 0;
  409. return;
  410. }
  411. if (dw_mci_pre_dma_transfer(slot->host, mrq->data, 1) < 0)
  412. data->host_cookie = 0;
  413. }
  414. static void dw_mci_post_req(struct mmc_host *mmc,
  415. struct mmc_request *mrq,
  416. int err)
  417. {
  418. struct dw_mci_slot *slot = mmc_priv(mmc);
  419. struct mmc_data *data = mrq->data;
  420. if (!slot->host->use_dma || !data)
  421. return;
  422. if (data->host_cookie)
  423. dma_unmap_sg(slot->host->dev,
  424. data->sg,
  425. data->sg_len,
  426. dw_mci_get_dma_dir(data));
  427. data->host_cookie = 0;
  428. }
  429. static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
  430. {
  431. int sg_len;
  432. u32 temp;
  433. host->using_dma = 0;
  434. /* If we don't have a channel, we can't do DMA */
  435. if (!host->use_dma)
  436. return -ENODEV;
  437. sg_len = dw_mci_pre_dma_transfer(host, data, 0);
  438. if (sg_len < 0) {
  439. host->dma_ops->stop(host);
  440. return sg_len;
  441. }
  442. host->using_dma = 1;
  443. dev_vdbg(host->dev,
  444. "sd sg_cpu: %#lx sg_dma: %#lx sg_len: %d\n",
  445. (unsigned long)host->sg_cpu, (unsigned long)host->sg_dma,
  446. sg_len);
  447. /* Enable the DMA interface */
  448. temp = mci_readl(host, CTRL);
  449. temp |= SDMMC_CTRL_DMA_ENABLE;
  450. mci_writel(host, CTRL, temp);
  451. /* Disable RX/TX IRQs, let DMA handle it */
  452. temp = mci_readl(host, INTMASK);
  453. temp &= ~(SDMMC_INT_RXDR | SDMMC_INT_TXDR);
  454. mci_writel(host, INTMASK, temp);
  455. host->dma_ops->start(host, sg_len);
  456. return 0;
  457. }
  458. static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data)
  459. {
  460. u32 temp;
  461. data->error = -EINPROGRESS;
  462. WARN_ON(host->data);
  463. host->sg = NULL;
  464. host->data = data;
  465. if (data->flags & MMC_DATA_READ)
  466. host->dir_status = DW_MCI_RECV_STATUS;
  467. else
  468. host->dir_status = DW_MCI_SEND_STATUS;
  469. if (dw_mci_submit_data_dma(host, data)) {
  470. int flags = SG_MITER_ATOMIC;
  471. if (host->data->flags & MMC_DATA_READ)
  472. flags |= SG_MITER_TO_SG;
  473. else
  474. flags |= SG_MITER_FROM_SG;
  475. sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
  476. host->sg = data->sg;
  477. host->part_buf_start = 0;
  478. host->part_buf_count = 0;
  479. mci_writel(host, RINTSTS, SDMMC_INT_TXDR | SDMMC_INT_RXDR);
  480. temp = mci_readl(host, INTMASK);
  481. temp |= SDMMC_INT_TXDR | SDMMC_INT_RXDR;
  482. mci_writel(host, INTMASK, temp);
  483. temp = mci_readl(host, CTRL);
  484. temp &= ~SDMMC_CTRL_DMA_ENABLE;
  485. mci_writel(host, CTRL, temp);
  486. }
  487. }
  488. static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg)
  489. {
  490. struct dw_mci *host = slot->host;
  491. unsigned long timeout = jiffies + msecs_to_jiffies(500);
  492. unsigned int cmd_status = 0;
  493. mci_writel(host, CMDARG, arg);
  494. wmb();
  495. mci_writel(host, CMD, SDMMC_CMD_START | cmd);
  496. while (time_before(jiffies, timeout)) {
  497. cmd_status = mci_readl(host, CMD);
  498. if (!(cmd_status & SDMMC_CMD_START))
  499. return;
  500. }
  501. dev_err(&slot->mmc->class_dev,
  502. "Timeout sending command (cmd %#x arg %#x status %#x)\n",
  503. cmd, arg, cmd_status);
  504. }
  505. static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
  506. {
  507. struct dw_mci *host = slot->host;
  508. u32 div;
  509. u32 clk_en_a;
  510. if (slot->clock != host->current_speed || force_clkinit) {
  511. div = host->bus_hz / slot->clock;
  512. if (host->bus_hz % slot->clock && host->bus_hz > slot->clock)
  513. /*
  514. * move the + 1 after the divide to prevent
  515. * over-clocking the card.
  516. */
  517. div += 1;
  518. div = (host->bus_hz != slot->clock) ? DIV_ROUND_UP(div, 2) : 0;
  519. dev_info(&slot->mmc->class_dev,
  520. "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ"
  521. " div = %d)\n", slot->id, host->bus_hz, slot->clock,
  522. div ? ((host->bus_hz / div) >> 1) : host->bus_hz, div);
  523. /* disable clock */
  524. mci_writel(host, CLKENA, 0);
  525. mci_writel(host, CLKSRC, 0);
  526. /* inform CIU */
  527. mci_send_cmd(slot,
  528. SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
  529. /* set clock to desired speed */
  530. mci_writel(host, CLKDIV, div);
  531. /* inform CIU */
  532. mci_send_cmd(slot,
  533. SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
  534. /* enable clock; only low power if no SDIO */
  535. clk_en_a = SDMMC_CLKEN_ENABLE << slot->id;
  536. if (!(mci_readl(host, INTMASK) & SDMMC_INT_SDIO(slot->id)))
  537. clk_en_a |= SDMMC_CLKEN_LOW_PWR << slot->id;
  538. mci_writel(host, CLKENA, clk_en_a);
  539. /* inform CIU */
  540. mci_send_cmd(slot,
  541. SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
  542. host->current_speed = slot->clock;
  543. }
  544. /* Set the current slot bus width */
  545. mci_writel(host, CTYPE, (slot->ctype << slot->id));
  546. }
  547. static void __dw_mci_start_request(struct dw_mci *host,
  548. struct dw_mci_slot *slot,
  549. struct mmc_command *cmd)
  550. {
  551. struct mmc_request *mrq;
  552. struct mmc_data *data;
  553. u32 cmdflags;
  554. mrq = slot->mrq;
  555. if (host->pdata->select_slot)
  556. host->pdata->select_slot(slot->id);
  557. /* Slot specific timing and width adjustment */
  558. dw_mci_setup_bus(slot, false);
  559. host->cur_slot = slot;
  560. host->mrq = mrq;
  561. host->pending_events = 0;
  562. host->completed_events = 0;
  563. host->data_status = 0;
  564. data = cmd->data;
  565. if (data) {
  566. dw_mci_set_timeout(host);
  567. mci_writel(host, BYTCNT, data->blksz*data->blocks);
  568. mci_writel(host, BLKSIZ, data->blksz);
  569. }
  570. cmdflags = dw_mci_prepare_command(slot->mmc, cmd);
  571. /* this is the first command, send the initialization clock */
  572. if (test_and_clear_bit(DW_MMC_CARD_NEED_INIT, &slot->flags))
  573. cmdflags |= SDMMC_CMD_INIT;
  574. if (data) {
  575. dw_mci_submit_data(host, data);
  576. wmb();
  577. }
  578. dw_mci_start_command(host, cmd, cmdflags);
  579. if (mrq->stop)
  580. host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop);
  581. }
  582. static void dw_mci_start_request(struct dw_mci *host,
  583. struct dw_mci_slot *slot)
  584. {
  585. struct mmc_request *mrq = slot->mrq;
  586. struct mmc_command *cmd;
  587. cmd = mrq->sbc ? mrq->sbc : mrq->cmd;
  588. __dw_mci_start_request(host, slot, cmd);
  589. }
  590. /* must be called with host->lock held */
  591. static void dw_mci_queue_request(struct dw_mci *host, struct dw_mci_slot *slot,
  592. struct mmc_request *mrq)
  593. {
  594. dev_vdbg(&slot->mmc->class_dev, "queue request: state=%d\n",
  595. host->state);
  596. slot->mrq = mrq;
  597. if (host->state == STATE_IDLE) {
  598. host->state = STATE_SENDING_CMD;
  599. dw_mci_start_request(host, slot);
  600. } else {
  601. list_add_tail(&slot->queue_node, &host->queue);
  602. }
  603. }
  604. static void dw_mci_request(struct mmc_host *mmc, struct mmc_request *mrq)
  605. {
  606. struct dw_mci_slot *slot = mmc_priv(mmc);
  607. struct dw_mci *host = slot->host;
  608. WARN_ON(slot->mrq);
  609. /*
  610. * The check for card presence and queueing of the request must be
  611. * atomic, otherwise the card could be removed in between and the
  612. * request wouldn't fail until another card was inserted.
  613. */
  614. spin_lock_bh(&host->lock);
  615. if (!test_bit(DW_MMC_CARD_PRESENT, &slot->flags)) {
  616. spin_unlock_bh(&host->lock);
  617. mrq->cmd->error = -ENOMEDIUM;
  618. mmc_request_done(mmc, mrq);
  619. return;
  620. }
  621. dw_mci_queue_request(host, slot, mrq);
  622. spin_unlock_bh(&host->lock);
  623. }
  624. static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  625. {
  626. struct dw_mci_slot *slot = mmc_priv(mmc);
  627. const struct dw_mci_drv_data *drv_data = slot->host->drv_data;
  628. u32 regs;
  629. /* set default 1 bit mode */
  630. slot->ctype = SDMMC_CTYPE_1BIT;
  631. switch (ios->bus_width) {
  632. case MMC_BUS_WIDTH_1:
  633. slot->ctype = SDMMC_CTYPE_1BIT;
  634. break;
  635. case MMC_BUS_WIDTH_4:
  636. slot->ctype = SDMMC_CTYPE_4BIT;
  637. break;
  638. case MMC_BUS_WIDTH_8:
  639. slot->ctype = SDMMC_CTYPE_8BIT;
  640. break;
  641. }
  642. regs = mci_readl(slot->host, UHS_REG);
  643. /* DDR mode set */
  644. if (ios->timing == MMC_TIMING_UHS_DDR50)
  645. regs |= (0x1 << slot->id) << 16;
  646. else
  647. regs &= ~(0x1 << slot->id) << 16;
  648. mci_writel(slot->host, UHS_REG, regs);
  649. if (ios->clock) {
  650. /*
  651. * Use mirror of ios->clock to prevent race with mmc
  652. * core ios update when finding the minimum.
  653. */
  654. slot->clock = ios->clock;
  655. }
  656. if (drv_data && drv_data->set_ios)
  657. drv_data->set_ios(slot->host, ios);
  658. switch (ios->power_mode) {
  659. case MMC_POWER_UP:
  660. set_bit(DW_MMC_CARD_NEED_INIT, &slot->flags);
  661. break;
  662. default:
  663. break;
  664. }
  665. }
  666. static int dw_mci_get_ro(struct mmc_host *mmc)
  667. {
  668. int read_only;
  669. struct dw_mci_slot *slot = mmc_priv(mmc);
  670. struct dw_mci_board *brd = slot->host->pdata;
  671. /* Use platform get_ro function, else try on board write protect */
  672. if (brd->quirks & DW_MCI_QUIRK_NO_WRITE_PROTECT)
  673. read_only = 0;
  674. else if (brd->get_ro)
  675. read_only = brd->get_ro(slot->id);
  676. else
  677. read_only =
  678. mci_readl(slot->host, WRTPRT) & (1 << slot->id) ? 1 : 0;
  679. dev_dbg(&mmc->class_dev, "card is %s\n",
  680. read_only ? "read-only" : "read-write");
  681. return read_only;
  682. }
  683. static int dw_mci_get_cd(struct mmc_host *mmc)
  684. {
  685. int present;
  686. struct dw_mci_slot *slot = mmc_priv(mmc);
  687. struct dw_mci_board *brd = slot->host->pdata;
  688. /* Use platform get_cd function, else try onboard card detect */
  689. if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION)
  690. present = 1;
  691. else if (brd->get_cd)
  692. present = !brd->get_cd(slot->id);
  693. else
  694. present = (mci_readl(slot->host, CDETECT) & (1 << slot->id))
  695. == 0 ? 1 : 0;
  696. if (present)
  697. dev_dbg(&mmc->class_dev, "card is present\n");
  698. else
  699. dev_dbg(&mmc->class_dev, "card is not present\n");
  700. return present;
  701. }
  702. /*
  703. * Disable lower power mode.
  704. *
  705. * Low power mode will stop the card clock when idle. According to the
  706. * description of the CLKENA register we should disable low power mode
  707. * for SDIO cards if we need SDIO interrupts to work.
  708. *
  709. * This function is fast if low power mode is already disabled.
  710. */
  711. static void dw_mci_disable_low_power(struct dw_mci_slot *slot)
  712. {
  713. struct dw_mci *host = slot->host;
  714. u32 clk_en_a;
  715. const u32 clken_low_pwr = SDMMC_CLKEN_LOW_PWR << slot->id;
  716. clk_en_a = mci_readl(host, CLKENA);
  717. if (clk_en_a & clken_low_pwr) {
  718. mci_writel(host, CLKENA, clk_en_a & ~clken_low_pwr);
  719. mci_send_cmd(slot, SDMMC_CMD_UPD_CLK |
  720. SDMMC_CMD_PRV_DAT_WAIT, 0);
  721. }
  722. }
  723. static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb)
  724. {
  725. struct dw_mci_slot *slot = mmc_priv(mmc);
  726. struct dw_mci *host = slot->host;
  727. u32 int_mask;
  728. /* Enable/disable Slot Specific SDIO interrupt */
  729. int_mask = mci_readl(host, INTMASK);
  730. if (enb) {
  731. /*
  732. * Turn off low power mode if it was enabled. This is a bit of
  733. * a heavy operation and we disable / enable IRQs a lot, so
  734. * we'll leave low power mode disabled and it will get
  735. * re-enabled again in dw_mci_setup_bus().
  736. */
  737. dw_mci_disable_low_power(slot);
  738. mci_writel(host, INTMASK,
  739. (int_mask | SDMMC_INT_SDIO(slot->id)));
  740. } else {
  741. mci_writel(host, INTMASK,
  742. (int_mask & ~SDMMC_INT_SDIO(slot->id)));
  743. }
  744. }
  745. static const struct mmc_host_ops dw_mci_ops = {
  746. .request = dw_mci_request,
  747. .pre_req = dw_mci_pre_req,
  748. .post_req = dw_mci_post_req,
  749. .set_ios = dw_mci_set_ios,
  750. .get_ro = dw_mci_get_ro,
  751. .get_cd = dw_mci_get_cd,
  752. .enable_sdio_irq = dw_mci_enable_sdio_irq,
  753. };
  754. static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)
  755. __releases(&host->lock)
  756. __acquires(&host->lock)
  757. {
  758. struct dw_mci_slot *slot;
  759. struct mmc_host *prev_mmc = host->cur_slot->mmc;
  760. WARN_ON(host->cmd || host->data);
  761. host->cur_slot->mrq = NULL;
  762. host->mrq = NULL;
  763. if (!list_empty(&host->queue)) {
  764. slot = list_entry(host->queue.next,
  765. struct dw_mci_slot, queue_node);
  766. list_del(&slot->queue_node);
  767. dev_vdbg(host->dev, "list not empty: %s is next\n",
  768. mmc_hostname(slot->mmc));
  769. host->state = STATE_SENDING_CMD;
  770. dw_mci_start_request(host, slot);
  771. } else {
  772. dev_vdbg(host->dev, "list empty\n");
  773. host->state = STATE_IDLE;
  774. }
  775. spin_unlock(&host->lock);
  776. mmc_request_done(prev_mmc, mrq);
  777. spin_lock(&host->lock);
  778. }
  779. static void dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd)
  780. {
  781. u32 status = host->cmd_status;
  782. host->cmd_status = 0;
  783. /* Read the response from the card (up to 16 bytes) */
  784. if (cmd->flags & MMC_RSP_PRESENT) {
  785. if (cmd->flags & MMC_RSP_136) {
  786. cmd->resp[3] = mci_readl(host, RESP0);
  787. cmd->resp[2] = mci_readl(host, RESP1);
  788. cmd->resp[1] = mci_readl(host, RESP2);
  789. cmd->resp[0] = mci_readl(host, RESP3);
  790. } else {
  791. cmd->resp[0] = mci_readl(host, RESP0);
  792. cmd->resp[1] = 0;
  793. cmd->resp[2] = 0;
  794. cmd->resp[3] = 0;
  795. }
  796. }
  797. if (status & SDMMC_INT_RTO)
  798. cmd->error = -ETIMEDOUT;
  799. else if ((cmd->flags & MMC_RSP_CRC) && (status & SDMMC_INT_RCRC))
  800. cmd->error = -EILSEQ;
  801. else if (status & SDMMC_INT_RESP_ERR)
  802. cmd->error = -EIO;
  803. else
  804. cmd->error = 0;
  805. if (cmd->error) {
  806. /* newer ip versions need a delay between retries */
  807. if (host->quirks & DW_MCI_QUIRK_RETRY_DELAY)
  808. mdelay(20);
  809. if (cmd->data) {
  810. dw_mci_stop_dma(host);
  811. host->data = NULL;
  812. }
  813. }
  814. }
  815. static void dw_mci_tasklet_func(unsigned long priv)
  816. {
  817. struct dw_mci *host = (struct dw_mci *)priv;
  818. struct mmc_data *data;
  819. struct mmc_command *cmd;
  820. enum dw_mci_state state;
  821. enum dw_mci_state prev_state;
  822. u32 status, ctrl;
  823. spin_lock(&host->lock);
  824. state = host->state;
  825. data = host->data;
  826. do {
  827. prev_state = state;
  828. switch (state) {
  829. case STATE_IDLE:
  830. break;
  831. case STATE_SENDING_CMD:
  832. if (!test_and_clear_bit(EVENT_CMD_COMPLETE,
  833. &host->pending_events))
  834. break;
  835. cmd = host->cmd;
  836. host->cmd = NULL;
  837. set_bit(EVENT_CMD_COMPLETE, &host->completed_events);
  838. dw_mci_command_complete(host, cmd);
  839. if (cmd == host->mrq->sbc && !cmd->error) {
  840. prev_state = state = STATE_SENDING_CMD;
  841. __dw_mci_start_request(host, host->cur_slot,
  842. host->mrq->cmd);
  843. goto unlock;
  844. }
  845. if (!host->mrq->data || cmd->error) {
  846. dw_mci_request_end(host, host->mrq);
  847. goto unlock;
  848. }
  849. prev_state = state = STATE_SENDING_DATA;
  850. /* fall through */
  851. case STATE_SENDING_DATA:
  852. if (test_and_clear_bit(EVENT_DATA_ERROR,
  853. &host->pending_events)) {
  854. dw_mci_stop_dma(host);
  855. if (data->stop)
  856. send_stop_cmd(host, data);
  857. state = STATE_DATA_ERROR;
  858. break;
  859. }
  860. if (!test_and_clear_bit(EVENT_XFER_COMPLETE,
  861. &host->pending_events))
  862. break;
  863. set_bit(EVENT_XFER_COMPLETE, &host->completed_events);
  864. prev_state = state = STATE_DATA_BUSY;
  865. /* fall through */
  866. case STATE_DATA_BUSY:
  867. if (!test_and_clear_bit(EVENT_DATA_COMPLETE,
  868. &host->pending_events))
  869. break;
  870. host->data = NULL;
  871. set_bit(EVENT_DATA_COMPLETE, &host->completed_events);
  872. status = host->data_status;
  873. if (status & DW_MCI_DATA_ERROR_FLAGS) {
  874. if (status & SDMMC_INT_DTO) {
  875. data->error = -ETIMEDOUT;
  876. } else if (status & SDMMC_INT_DCRC) {
  877. data->error = -EILSEQ;
  878. } else if (status & SDMMC_INT_EBE &&
  879. host->dir_status ==
  880. DW_MCI_SEND_STATUS) {
  881. /*
  882. * No data CRC status was returned.
  883. * The number of bytes transferred will
  884. * be exaggerated in PIO mode.
  885. */
  886. data->bytes_xfered = 0;
  887. data->error = -ETIMEDOUT;
  888. } else {
  889. dev_err(host->dev,
  890. "data FIFO error "
  891. "(status=%08x)\n",
  892. status);
  893. data->error = -EIO;
  894. }
  895. /*
  896. * After an error, there may be data lingering
  897. * in the FIFO, so reset it - doing so
  898. * generates a block interrupt, hence setting
  899. * the scatter-gather pointer to NULL.
  900. */
  901. sg_miter_stop(&host->sg_miter);
  902. host->sg = NULL;
  903. ctrl = mci_readl(host, CTRL);
  904. ctrl |= SDMMC_CTRL_FIFO_RESET;
  905. mci_writel(host, CTRL, ctrl);
  906. } else {
  907. data->bytes_xfered = data->blocks * data->blksz;
  908. data->error = 0;
  909. }
  910. if (!data->stop) {
  911. dw_mci_request_end(host, host->mrq);
  912. goto unlock;
  913. }
  914. if (host->mrq->sbc && !data->error) {
  915. data->stop->error = 0;
  916. dw_mci_request_end(host, host->mrq);
  917. goto unlock;
  918. }
  919. prev_state = state = STATE_SENDING_STOP;
  920. if (!data->error)
  921. send_stop_cmd(host, data);
  922. /* fall through */
  923. case STATE_SENDING_STOP:
  924. if (!test_and_clear_bit(EVENT_CMD_COMPLETE,
  925. &host->pending_events))
  926. break;
  927. host->cmd = NULL;
  928. dw_mci_command_complete(host, host->mrq->stop);
  929. dw_mci_request_end(host, host->mrq);
  930. goto unlock;
  931. case STATE_DATA_ERROR:
  932. if (!test_and_clear_bit(EVENT_XFER_COMPLETE,
  933. &host->pending_events))
  934. break;
  935. state = STATE_DATA_BUSY;
  936. break;
  937. }
  938. } while (state != prev_state);
  939. host->state = state;
  940. unlock:
  941. spin_unlock(&host->lock);
  942. }
  943. /* push final bytes to part_buf, only use during push */
  944. static void dw_mci_set_part_bytes(struct dw_mci *host, void *buf, int cnt)
  945. {
  946. memcpy((void *)&host->part_buf, buf, cnt);
  947. host->part_buf_count = cnt;
  948. }
  949. /* append bytes to part_buf, only use during push */
  950. static int dw_mci_push_part_bytes(struct dw_mci *host, void *buf, int cnt)
  951. {
  952. cnt = min(cnt, (1 << host->data_shift) - host->part_buf_count);
  953. memcpy((void *)&host->part_buf + host->part_buf_count, buf, cnt);
  954. host->part_buf_count += cnt;
  955. return cnt;
  956. }
  957. /* pull first bytes from part_buf, only use during pull */
  958. static int dw_mci_pull_part_bytes(struct dw_mci *host, void *buf, int cnt)
  959. {
  960. cnt = min(cnt, (int)host->part_buf_count);
  961. if (cnt) {
  962. memcpy(buf, (void *)&host->part_buf + host->part_buf_start,
  963. cnt);
  964. host->part_buf_count -= cnt;
  965. host->part_buf_start += cnt;
  966. }
  967. return cnt;
  968. }
  969. /* pull final bytes from the part_buf, assuming it's just been filled */
  970. static void dw_mci_pull_final_bytes(struct dw_mci *host, void *buf, int cnt)
  971. {
  972. memcpy(buf, &host->part_buf, cnt);
  973. host->part_buf_start = cnt;
  974. host->part_buf_count = (1 << host->data_shift) - cnt;
  975. }
  976. static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
  977. {
  978. /* try and push anything in the part_buf */
  979. if (unlikely(host->part_buf_count)) {
  980. int len = dw_mci_push_part_bytes(host, buf, cnt);
  981. buf += len;
  982. cnt -= len;
  983. if (!sg_next(host->sg) || host->part_buf_count == 2) {
  984. mci_writew(host, DATA(host->data_offset),
  985. host->part_buf16);
  986. host->part_buf_count = 0;
  987. }
  988. }
  989. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  990. if (unlikely((unsigned long)buf & 0x1)) {
  991. while (cnt >= 2) {
  992. u16 aligned_buf[64];
  993. int len = min(cnt & -2, (int)sizeof(aligned_buf));
  994. int items = len >> 1;
  995. int i;
  996. /* memcpy from input buffer into aligned buffer */
  997. memcpy(aligned_buf, buf, len);
  998. buf += len;
  999. cnt -= len;
  1000. /* push data from aligned buffer into fifo */
  1001. for (i = 0; i < items; ++i)
  1002. mci_writew(host, DATA(host->data_offset),
  1003. aligned_buf[i]);
  1004. }
  1005. } else
  1006. #endif
  1007. {
  1008. u16 *pdata = buf;
  1009. for (; cnt >= 2; cnt -= 2)
  1010. mci_writew(host, DATA(host->data_offset), *pdata++);
  1011. buf = pdata;
  1012. }
  1013. /* put anything remaining in the part_buf */
  1014. if (cnt) {
  1015. dw_mci_set_part_bytes(host, buf, cnt);
  1016. if (!sg_next(host->sg))
  1017. mci_writew(host, DATA(host->data_offset),
  1018. host->part_buf16);
  1019. }
  1020. }
  1021. static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
  1022. {
  1023. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1024. if (unlikely((unsigned long)buf & 0x1)) {
  1025. while (cnt >= 2) {
  1026. /* pull data from fifo into aligned buffer */
  1027. u16 aligned_buf[64];
  1028. int len = min(cnt & -2, (int)sizeof(aligned_buf));
  1029. int items = len >> 1;
  1030. int i;
  1031. for (i = 0; i < items; ++i)
  1032. aligned_buf[i] = mci_readw(host,
  1033. DATA(host->data_offset));
  1034. /* memcpy from aligned buffer into output buffer */
  1035. memcpy(buf, aligned_buf, len);
  1036. buf += len;
  1037. cnt -= len;
  1038. }
  1039. } else
  1040. #endif
  1041. {
  1042. u16 *pdata = buf;
  1043. for (; cnt >= 2; cnt -= 2)
  1044. *pdata++ = mci_readw(host, DATA(host->data_offset));
  1045. buf = pdata;
  1046. }
  1047. if (cnt) {
  1048. host->part_buf16 = mci_readw(host, DATA(host->data_offset));
  1049. dw_mci_pull_final_bytes(host, buf, cnt);
  1050. }
  1051. }
  1052. static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
  1053. {
  1054. /* try and push anything in the part_buf */
  1055. if (unlikely(host->part_buf_count)) {
  1056. int len = dw_mci_push_part_bytes(host, buf, cnt);
  1057. buf += len;
  1058. cnt -= len;
  1059. if (!sg_next(host->sg) || host->part_buf_count == 4) {
  1060. mci_writel(host, DATA(host->data_offset),
  1061. host->part_buf32);
  1062. host->part_buf_count = 0;
  1063. }
  1064. }
  1065. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1066. if (unlikely((unsigned long)buf & 0x3)) {
  1067. while (cnt >= 4) {
  1068. u32 aligned_buf[32];
  1069. int len = min(cnt & -4, (int)sizeof(aligned_buf));
  1070. int items = len >> 2;
  1071. int i;
  1072. /* memcpy from input buffer into aligned buffer */
  1073. memcpy(aligned_buf, buf, len);
  1074. buf += len;
  1075. cnt -= len;
  1076. /* push data from aligned buffer into fifo */
  1077. for (i = 0; i < items; ++i)
  1078. mci_writel(host, DATA(host->data_offset),
  1079. aligned_buf[i]);
  1080. }
  1081. } else
  1082. #endif
  1083. {
  1084. u32 *pdata = buf;
  1085. for (; cnt >= 4; cnt -= 4)
  1086. mci_writel(host, DATA(host->data_offset), *pdata++);
  1087. buf = pdata;
  1088. }
  1089. /* put anything remaining in the part_buf */
  1090. if (cnt) {
  1091. dw_mci_set_part_bytes(host, buf, cnt);
  1092. if (!sg_next(host->sg))
  1093. mci_writel(host, DATA(host->data_offset),
  1094. host->part_buf32);
  1095. }
  1096. }
  1097. static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
  1098. {
  1099. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1100. if (unlikely((unsigned long)buf & 0x3)) {
  1101. while (cnt >= 4) {
  1102. /* pull data from fifo into aligned buffer */
  1103. u32 aligned_buf[32];
  1104. int len = min(cnt & -4, (int)sizeof(aligned_buf));
  1105. int items = len >> 2;
  1106. int i;
  1107. for (i = 0; i < items; ++i)
  1108. aligned_buf[i] = mci_readl(host,
  1109. DATA(host->data_offset));
  1110. /* memcpy from aligned buffer into output buffer */
  1111. memcpy(buf, aligned_buf, len);
  1112. buf += len;
  1113. cnt -= len;
  1114. }
  1115. } else
  1116. #endif
  1117. {
  1118. u32 *pdata = buf;
  1119. for (; cnt >= 4; cnt -= 4)
  1120. *pdata++ = mci_readl(host, DATA(host->data_offset));
  1121. buf = pdata;
  1122. }
  1123. if (cnt) {
  1124. host->part_buf32 = mci_readl(host, DATA(host->data_offset));
  1125. dw_mci_pull_final_bytes(host, buf, cnt);
  1126. }
  1127. }
  1128. static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
  1129. {
  1130. /* try and push anything in the part_buf */
  1131. if (unlikely(host->part_buf_count)) {
  1132. int len = dw_mci_push_part_bytes(host, buf, cnt);
  1133. buf += len;
  1134. cnt -= len;
  1135. if (!sg_next(host->sg) || host->part_buf_count == 8) {
  1136. mci_writew(host, DATA(host->data_offset),
  1137. host->part_buf);
  1138. host->part_buf_count = 0;
  1139. }
  1140. }
  1141. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1142. if (unlikely((unsigned long)buf & 0x7)) {
  1143. while (cnt >= 8) {
  1144. u64 aligned_buf[16];
  1145. int len = min(cnt & -8, (int)sizeof(aligned_buf));
  1146. int items = len >> 3;
  1147. int i;
  1148. /* memcpy from input buffer into aligned buffer */
  1149. memcpy(aligned_buf, buf, len);
  1150. buf += len;
  1151. cnt -= len;
  1152. /* push data from aligned buffer into fifo */
  1153. for (i = 0; i < items; ++i)
  1154. mci_writeq(host, DATA(host->data_offset),
  1155. aligned_buf[i]);
  1156. }
  1157. } else
  1158. #endif
  1159. {
  1160. u64 *pdata = buf;
  1161. for (; cnt >= 8; cnt -= 8)
  1162. mci_writeq(host, DATA(host->data_offset), *pdata++);
  1163. buf = pdata;
  1164. }
  1165. /* put anything remaining in the part_buf */
  1166. if (cnt) {
  1167. dw_mci_set_part_bytes(host, buf, cnt);
  1168. if (!sg_next(host->sg))
  1169. mci_writeq(host, DATA(host->data_offset),
  1170. host->part_buf);
  1171. }
  1172. }
  1173. static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
  1174. {
  1175. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1176. if (unlikely((unsigned long)buf & 0x7)) {
  1177. while (cnt >= 8) {
  1178. /* pull data from fifo into aligned buffer */
  1179. u64 aligned_buf[16];
  1180. int len = min(cnt & -8, (int)sizeof(aligned_buf));
  1181. int items = len >> 3;
  1182. int i;
  1183. for (i = 0; i < items; ++i)
  1184. aligned_buf[i] = mci_readq(host,
  1185. DATA(host->data_offset));
  1186. /* memcpy from aligned buffer into output buffer */
  1187. memcpy(buf, aligned_buf, len);
  1188. buf += len;
  1189. cnt -= len;
  1190. }
  1191. } else
  1192. #endif
  1193. {
  1194. u64 *pdata = buf;
  1195. for (; cnt >= 8; cnt -= 8)
  1196. *pdata++ = mci_readq(host, DATA(host->data_offset));
  1197. buf = pdata;
  1198. }
  1199. if (cnt) {
  1200. host->part_buf = mci_readq(host, DATA(host->data_offset));
  1201. dw_mci_pull_final_bytes(host, buf, cnt);
  1202. }
  1203. }
  1204. static void dw_mci_pull_data(struct dw_mci *host, void *buf, int cnt)
  1205. {
  1206. int len;
  1207. /* get remaining partial bytes */
  1208. len = dw_mci_pull_part_bytes(host, buf, cnt);
  1209. if (unlikely(len == cnt))
  1210. return;
  1211. buf += len;
  1212. cnt -= len;
  1213. /* get the rest of the data */
  1214. host->pull_data(host, buf, cnt);
  1215. }
  1216. static void dw_mci_read_data_pio(struct dw_mci *host)
  1217. {
  1218. struct sg_mapping_iter *sg_miter = &host->sg_miter;
  1219. void *buf;
  1220. unsigned int offset;
  1221. struct mmc_data *data = host->data;
  1222. int shift = host->data_shift;
  1223. u32 status;
  1224. unsigned int nbytes = 0, len;
  1225. unsigned int remain, fcnt;
  1226. do {
  1227. if (!sg_miter_next(sg_miter))
  1228. goto done;
  1229. host->sg = sg_miter->__sg;
  1230. buf = sg_miter->addr;
  1231. remain = sg_miter->length;
  1232. offset = 0;
  1233. do {
  1234. fcnt = (SDMMC_GET_FCNT(mci_readl(host, STATUS))
  1235. << shift) + host->part_buf_count;
  1236. len = min(remain, fcnt);
  1237. if (!len)
  1238. break;
  1239. dw_mci_pull_data(host, (void *)(buf + offset), len);
  1240. offset += len;
  1241. nbytes += len;
  1242. remain -= len;
  1243. } while (remain);
  1244. sg_miter->consumed = offset;
  1245. status = mci_readl(host, MINTSTS);
  1246. mci_writel(host, RINTSTS, SDMMC_INT_RXDR);
  1247. } while (status & SDMMC_INT_RXDR); /*if the RXDR is ready read again*/
  1248. data->bytes_xfered += nbytes;
  1249. if (!remain) {
  1250. if (!sg_miter_next(sg_miter))
  1251. goto done;
  1252. sg_miter->consumed = 0;
  1253. }
  1254. sg_miter_stop(sg_miter);
  1255. return;
  1256. done:
  1257. data->bytes_xfered += nbytes;
  1258. sg_miter_stop(sg_miter);
  1259. host->sg = NULL;
  1260. smp_wmb();
  1261. set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
  1262. }
  1263. static void dw_mci_write_data_pio(struct dw_mci *host)
  1264. {
  1265. struct sg_mapping_iter *sg_miter = &host->sg_miter;
  1266. void *buf;
  1267. unsigned int offset;
  1268. struct mmc_data *data = host->data;
  1269. int shift = host->data_shift;
  1270. u32 status;
  1271. unsigned int nbytes = 0, len;
  1272. unsigned int fifo_depth = host->fifo_depth;
  1273. unsigned int remain, fcnt;
  1274. do {
  1275. if (!sg_miter_next(sg_miter))
  1276. goto done;
  1277. host->sg = sg_miter->__sg;
  1278. buf = sg_miter->addr;
  1279. remain = sg_miter->length;
  1280. offset = 0;
  1281. do {
  1282. fcnt = ((fifo_depth -
  1283. SDMMC_GET_FCNT(mci_readl(host, STATUS)))
  1284. << shift) - host->part_buf_count;
  1285. len = min(remain, fcnt);
  1286. if (!len)
  1287. break;
  1288. host->push_data(host, (void *)(buf + offset), len);
  1289. offset += len;
  1290. nbytes += len;
  1291. remain -= len;
  1292. } while (remain);
  1293. sg_miter->consumed = offset;
  1294. status = mci_readl(host, MINTSTS);
  1295. mci_writel(host, RINTSTS, SDMMC_INT_TXDR);
  1296. } while (status & SDMMC_INT_TXDR); /* if TXDR write again */
  1297. data->bytes_xfered += nbytes;
  1298. if (!remain) {
  1299. if (!sg_miter_next(sg_miter))
  1300. goto done;
  1301. sg_miter->consumed = 0;
  1302. }
  1303. sg_miter_stop(sg_miter);
  1304. return;
  1305. done:
  1306. data->bytes_xfered += nbytes;
  1307. sg_miter_stop(sg_miter);
  1308. host->sg = NULL;
  1309. smp_wmb();
  1310. set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
  1311. }
  1312. static void dw_mci_cmd_interrupt(struct dw_mci *host, u32 status)
  1313. {
  1314. if (!host->cmd_status)
  1315. host->cmd_status = status;
  1316. smp_wmb();
  1317. set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
  1318. tasklet_schedule(&host->tasklet);
  1319. }
  1320. static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
  1321. {
  1322. struct dw_mci *host = dev_id;
  1323. u32 pending;
  1324. unsigned int pass_count = 0;
  1325. int i;
  1326. do {
  1327. pending = mci_readl(host, MINTSTS); /* read-only mask reg */
  1328. /*
  1329. * DTO fix - version 2.10a and below, and only if internal DMA
  1330. * is configured.
  1331. */
  1332. if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO) {
  1333. if (!pending &&
  1334. ((mci_readl(host, STATUS) >> 17) & 0x1fff))
  1335. pending |= SDMMC_INT_DATA_OVER;
  1336. }
  1337. if (!pending)
  1338. break;
  1339. if (pending & DW_MCI_CMD_ERROR_FLAGS) {
  1340. mci_writel(host, RINTSTS, DW_MCI_CMD_ERROR_FLAGS);
  1341. host->cmd_status = pending;
  1342. smp_wmb();
  1343. set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
  1344. }
  1345. if (pending & DW_MCI_DATA_ERROR_FLAGS) {
  1346. /* if there is an error report DATA_ERROR */
  1347. mci_writel(host, RINTSTS, DW_MCI_DATA_ERROR_FLAGS);
  1348. host->data_status = pending;
  1349. smp_wmb();
  1350. set_bit(EVENT_DATA_ERROR, &host->pending_events);
  1351. tasklet_schedule(&host->tasklet);
  1352. }
  1353. if (pending & SDMMC_INT_DATA_OVER) {
  1354. mci_writel(host, RINTSTS, SDMMC_INT_DATA_OVER);
  1355. if (!host->data_status)
  1356. host->data_status = pending;
  1357. smp_wmb();
  1358. if (host->dir_status == DW_MCI_RECV_STATUS) {
  1359. if (host->sg != NULL)
  1360. dw_mci_read_data_pio(host);
  1361. }
  1362. set_bit(EVENT_DATA_COMPLETE, &host->pending_events);
  1363. tasklet_schedule(&host->tasklet);
  1364. }
  1365. if (pending & SDMMC_INT_RXDR) {
  1366. mci_writel(host, RINTSTS, SDMMC_INT_RXDR);
  1367. if (host->dir_status == DW_MCI_RECV_STATUS && host->sg)
  1368. dw_mci_read_data_pio(host);
  1369. }
  1370. if (pending & SDMMC_INT_TXDR) {
  1371. mci_writel(host, RINTSTS, SDMMC_INT_TXDR);
  1372. if (host->dir_status == DW_MCI_SEND_STATUS && host->sg)
  1373. dw_mci_write_data_pio(host);
  1374. }
  1375. if (pending & SDMMC_INT_CMD_DONE) {
  1376. mci_writel(host, RINTSTS, SDMMC_INT_CMD_DONE);
  1377. dw_mci_cmd_interrupt(host, pending);
  1378. }
  1379. if (pending & SDMMC_INT_CD) {
  1380. mci_writel(host, RINTSTS, SDMMC_INT_CD);
  1381. queue_work(host->card_workqueue, &host->card_work);
  1382. }
  1383. /* Handle SDIO Interrupts */
  1384. for (i = 0; i < host->num_slots; i++) {
  1385. struct dw_mci_slot *slot = host->slot[i];
  1386. if (pending & SDMMC_INT_SDIO(i)) {
  1387. mci_writel(host, RINTSTS, SDMMC_INT_SDIO(i));
  1388. mmc_signal_sdio_irq(slot->mmc);
  1389. }
  1390. }
  1391. } while (pass_count++ < 5);
  1392. #ifdef CONFIG_MMC_DW_IDMAC
  1393. /* Handle DMA interrupts */
  1394. pending = mci_readl(host, IDSTS);
  1395. if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) {
  1396. mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI);
  1397. mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI);
  1398. host->dma_ops->complete(host);
  1399. }
  1400. #endif
  1401. return IRQ_HANDLED;
  1402. }
  1403. static void dw_mci_work_routine_card(struct work_struct *work)
  1404. {
  1405. struct dw_mci *host = container_of(work, struct dw_mci, card_work);
  1406. int i;
  1407. for (i = 0; i < host->num_slots; i++) {
  1408. struct dw_mci_slot *slot = host->slot[i];
  1409. struct mmc_host *mmc = slot->mmc;
  1410. struct mmc_request *mrq;
  1411. int present;
  1412. u32 ctrl;
  1413. present = dw_mci_get_cd(mmc);
  1414. while (present != slot->last_detect_state) {
  1415. dev_dbg(&slot->mmc->class_dev, "card %s\n",
  1416. present ? "inserted" : "removed");
  1417. /* Power up slot (before spin_lock, may sleep) */
  1418. if (present != 0 && host->pdata->setpower)
  1419. host->pdata->setpower(slot->id, mmc->ocr_avail);
  1420. spin_lock_bh(&host->lock);
  1421. /* Card change detected */
  1422. slot->last_detect_state = present;
  1423. /* Mark card as present if applicable */
  1424. if (present != 0)
  1425. set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
  1426. /* Clean up queue if present */
  1427. mrq = slot->mrq;
  1428. if (mrq) {
  1429. if (mrq == host->mrq) {
  1430. host->data = NULL;
  1431. host->cmd = NULL;
  1432. switch (host->state) {
  1433. case STATE_IDLE:
  1434. break;
  1435. case STATE_SENDING_CMD:
  1436. mrq->cmd->error = -ENOMEDIUM;
  1437. if (!mrq->data)
  1438. break;
  1439. /* fall through */
  1440. case STATE_SENDING_DATA:
  1441. mrq->data->error = -ENOMEDIUM;
  1442. dw_mci_stop_dma(host);
  1443. break;
  1444. case STATE_DATA_BUSY:
  1445. case STATE_DATA_ERROR:
  1446. if (mrq->data->error == -EINPROGRESS)
  1447. mrq->data->error = -ENOMEDIUM;
  1448. if (!mrq->stop)
  1449. break;
  1450. /* fall through */
  1451. case STATE_SENDING_STOP:
  1452. mrq->stop->error = -ENOMEDIUM;
  1453. break;
  1454. }
  1455. dw_mci_request_end(host, mrq);
  1456. } else {
  1457. list_del(&slot->queue_node);
  1458. mrq->cmd->error = -ENOMEDIUM;
  1459. if (mrq->data)
  1460. mrq->data->error = -ENOMEDIUM;
  1461. if (mrq->stop)
  1462. mrq->stop->error = -ENOMEDIUM;
  1463. spin_unlock(&host->lock);
  1464. mmc_request_done(slot->mmc, mrq);
  1465. spin_lock(&host->lock);
  1466. }
  1467. }
  1468. /* Power down slot */
  1469. if (present == 0) {
  1470. clear_bit(DW_MMC_CARD_PRESENT, &slot->flags);
  1471. /*
  1472. * Clear down the FIFO - doing so generates a
  1473. * block interrupt, hence setting the
  1474. * scatter-gather pointer to NULL.
  1475. */
  1476. sg_miter_stop(&host->sg_miter);
  1477. host->sg = NULL;
  1478. ctrl = mci_readl(host, CTRL);
  1479. ctrl |= SDMMC_CTRL_FIFO_RESET;
  1480. mci_writel(host, CTRL, ctrl);
  1481. #ifdef CONFIG_MMC_DW_IDMAC
  1482. ctrl = mci_readl(host, BMOD);
  1483. /* Software reset of DMA */
  1484. ctrl |= SDMMC_IDMAC_SWRESET;
  1485. mci_writel(host, BMOD, ctrl);
  1486. #endif
  1487. }
  1488. spin_unlock_bh(&host->lock);
  1489. /* Power down slot (after spin_unlock, may sleep) */
  1490. if (present == 0 && host->pdata->setpower)
  1491. host->pdata->setpower(slot->id, 0);
  1492. present = dw_mci_get_cd(mmc);
  1493. }
  1494. mmc_detect_change(slot->mmc,
  1495. msecs_to_jiffies(host->pdata->detect_delay_ms));
  1496. }
  1497. }
  1498. #ifdef CONFIG_OF
  1499. /* given a slot id, find out the device node representing that slot */
  1500. static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot)
  1501. {
  1502. struct device_node *np;
  1503. const __be32 *addr;
  1504. int len;
  1505. if (!dev || !dev->of_node)
  1506. return NULL;
  1507. for_each_child_of_node(dev->of_node, np) {
  1508. addr = of_get_property(np, "reg", &len);
  1509. if (!addr || (len < sizeof(int)))
  1510. continue;
  1511. if (be32_to_cpup(addr) == slot)
  1512. return np;
  1513. }
  1514. return NULL;
  1515. }
  1516. /* find out bus-width for a given slot */
  1517. static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot)
  1518. {
  1519. struct device_node *np = dw_mci_of_find_slot_node(dev, slot);
  1520. u32 bus_wd = 1;
  1521. if (!np)
  1522. return 1;
  1523. if (of_property_read_u32(np, "bus-width", &bus_wd))
  1524. dev_err(dev, "bus-width property not found, assuming width"
  1525. " as 1\n");
  1526. return bus_wd;
  1527. }
  1528. #else /* CONFIG_OF */
  1529. static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot)
  1530. {
  1531. return 1;
  1532. }
  1533. static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot)
  1534. {
  1535. return NULL;
  1536. }
  1537. #endif /* CONFIG_OF */
  1538. static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
  1539. {
  1540. struct mmc_host *mmc;
  1541. struct dw_mci_slot *slot;
  1542. const struct dw_mci_drv_data *drv_data = host->drv_data;
  1543. int ctrl_id, ret;
  1544. u8 bus_width;
  1545. mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), host->dev);
  1546. if (!mmc)
  1547. return -ENOMEM;
  1548. slot = mmc_priv(mmc);
  1549. slot->id = id;
  1550. slot->mmc = mmc;
  1551. slot->host = host;
  1552. host->slot[id] = slot;
  1553. mmc->ops = &dw_mci_ops;
  1554. mmc->f_min = DIV_ROUND_UP(host->bus_hz, 510);
  1555. mmc->f_max = host->bus_hz;
  1556. if (host->pdata->get_ocr)
  1557. mmc->ocr_avail = host->pdata->get_ocr(id);
  1558. else
  1559. mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
  1560. /*
  1561. * Start with slot power disabled, it will be enabled when a card
  1562. * is detected.
  1563. */
  1564. if (host->pdata->setpower)
  1565. host->pdata->setpower(id, 0);
  1566. if (host->pdata->caps)
  1567. mmc->caps = host->pdata->caps;
  1568. if (host->pdata->pm_caps)
  1569. mmc->pm_caps = host->pdata->pm_caps;
  1570. if (host->dev->of_node) {
  1571. ctrl_id = of_alias_get_id(host->dev->of_node, "mshc");
  1572. if (ctrl_id < 0)
  1573. ctrl_id = 0;
  1574. } else {
  1575. ctrl_id = to_platform_device(host->dev)->id;
  1576. }
  1577. if (drv_data && drv_data->caps)
  1578. mmc->caps |= drv_data->caps[ctrl_id];
  1579. if (host->pdata->caps2)
  1580. mmc->caps2 = host->pdata->caps2;
  1581. if (host->pdata->get_bus_wd)
  1582. bus_width = host->pdata->get_bus_wd(slot->id);
  1583. else if (host->dev->of_node)
  1584. bus_width = dw_mci_of_get_bus_wd(host->dev, slot->id);
  1585. else
  1586. bus_width = 1;
  1587. if (drv_data && drv_data->setup_bus) {
  1588. struct device_node *slot_np;
  1589. slot_np = dw_mci_of_find_slot_node(host->dev, slot->id);
  1590. ret = drv_data->setup_bus(host, slot_np, bus_width);
  1591. if (ret)
  1592. goto err_setup_bus;
  1593. }
  1594. switch (bus_width) {
  1595. case 8:
  1596. mmc->caps |= MMC_CAP_8_BIT_DATA;
  1597. case 4:
  1598. mmc->caps |= MMC_CAP_4_BIT_DATA;
  1599. }
  1600. if (host->pdata->quirks & DW_MCI_QUIRK_HIGHSPEED)
  1601. mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
  1602. if (host->pdata->blk_settings) {
  1603. mmc->max_segs = host->pdata->blk_settings->max_segs;
  1604. mmc->max_blk_size = host->pdata->blk_settings->max_blk_size;
  1605. mmc->max_blk_count = host->pdata->blk_settings->max_blk_count;
  1606. mmc->max_req_size = host->pdata->blk_settings->max_req_size;
  1607. mmc->max_seg_size = host->pdata->blk_settings->max_seg_size;
  1608. } else {
  1609. /* Useful defaults if platform data is unset. */
  1610. #ifdef CONFIG_MMC_DW_IDMAC
  1611. mmc->max_segs = host->ring_size;
  1612. mmc->max_blk_size = 65536;
  1613. mmc->max_blk_count = host->ring_size;
  1614. mmc->max_seg_size = 0x1000;
  1615. mmc->max_req_size = mmc->max_seg_size * mmc->max_blk_count;
  1616. #else
  1617. mmc->max_segs = 64;
  1618. mmc->max_blk_size = 65536; /* BLKSIZ is 16 bits */
  1619. mmc->max_blk_count = 512;
  1620. mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
  1621. mmc->max_seg_size = mmc->max_req_size;
  1622. #endif /* CONFIG_MMC_DW_IDMAC */
  1623. }
  1624. host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
  1625. if (IS_ERR(host->vmmc)) {
  1626. pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
  1627. host->vmmc = NULL;
  1628. } else
  1629. regulator_enable(host->vmmc);
  1630. if (dw_mci_get_cd(mmc))
  1631. set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
  1632. else
  1633. clear_bit(DW_MMC_CARD_PRESENT, &slot->flags);
  1634. mmc_add_host(mmc);
  1635. #if defined(CONFIG_DEBUG_FS)
  1636. dw_mci_init_debugfs(slot);
  1637. #endif
  1638. /* Card initially undetected */
  1639. slot->last_detect_state = 0;
  1640. /*
  1641. * Card may have been plugged in prior to boot so we
  1642. * need to run the detect tasklet
  1643. */
  1644. queue_work(host->card_workqueue, &host->card_work);
  1645. return 0;
  1646. err_setup_bus:
  1647. mmc_free_host(mmc);
  1648. return -EINVAL;
  1649. }
  1650. static void dw_mci_cleanup_slot(struct dw_mci_slot *slot, unsigned int id)
  1651. {
  1652. /* Shutdown detect IRQ */
  1653. if (slot->host->pdata->exit)
  1654. slot->host->pdata->exit(id);
  1655. /* Debugfs stuff is cleaned up by mmc core */
  1656. mmc_remove_host(slot->mmc);
  1657. slot->host->slot[id] = NULL;
  1658. mmc_free_host(slot->mmc);
  1659. }
  1660. static void dw_mci_init_dma(struct dw_mci *host)
  1661. {
  1662. /* Alloc memory for sg translation */
  1663. host->sg_cpu = dma_alloc_coherent(host->dev, PAGE_SIZE,
  1664. &host->sg_dma, GFP_KERNEL);
  1665. if (!host->sg_cpu) {
  1666. dev_err(host->dev, "%s: could not alloc DMA memory\n",
  1667. __func__);
  1668. goto no_dma;
  1669. }
  1670. /* Determine which DMA interface to use */
  1671. #ifdef CONFIG_MMC_DW_IDMAC
  1672. host->dma_ops = &dw_mci_idmac_ops;
  1673. dev_info(host->dev, "Using internal DMA controller.\n");
  1674. #endif
  1675. if (!host->dma_ops)
  1676. goto no_dma;
  1677. if (host->dma_ops->init && host->dma_ops->start &&
  1678. host->dma_ops->stop && host->dma_ops->cleanup) {
  1679. if (host->dma_ops->init(host)) {
  1680. dev_err(host->dev, "%s: Unable to initialize "
  1681. "DMA Controller.\n", __func__);
  1682. goto no_dma;
  1683. }
  1684. } else {
  1685. dev_err(host->dev, "DMA initialization not found.\n");
  1686. goto no_dma;
  1687. }
  1688. host->use_dma = 1;
  1689. return;
  1690. no_dma:
  1691. dev_info(host->dev, "Using PIO mode.\n");
  1692. host->use_dma = 0;
  1693. return;
  1694. }
  1695. static bool mci_wait_reset(struct device *dev, struct dw_mci *host)
  1696. {
  1697. unsigned long timeout = jiffies + msecs_to_jiffies(500);
  1698. unsigned int ctrl;
  1699. mci_writel(host, CTRL, (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET |
  1700. SDMMC_CTRL_DMA_RESET));
  1701. /* wait till resets clear */
  1702. do {
  1703. ctrl = mci_readl(host, CTRL);
  1704. if (!(ctrl & (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET |
  1705. SDMMC_CTRL_DMA_RESET)))
  1706. return true;
  1707. } while (time_before(jiffies, timeout));
  1708. dev_err(dev, "Timeout resetting block (ctrl %#x)\n", ctrl);
  1709. return false;
  1710. }
  1711. #ifdef CONFIG_OF
  1712. static struct dw_mci_of_quirks {
  1713. char *quirk;
  1714. int id;
  1715. } of_quirks[] = {
  1716. {
  1717. .quirk = "supports-highspeed",
  1718. .id = DW_MCI_QUIRK_HIGHSPEED,
  1719. }, {
  1720. .quirk = "broken-cd",
  1721. .id = DW_MCI_QUIRK_BROKEN_CARD_DETECTION,
  1722. },
  1723. };
  1724. static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
  1725. {
  1726. struct dw_mci_board *pdata;
  1727. struct device *dev = host->dev;
  1728. struct device_node *np = dev->of_node;
  1729. const struct dw_mci_drv_data *drv_data = host->drv_data;
  1730. int idx, ret;
  1731. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  1732. if (!pdata) {
  1733. dev_err(dev, "could not allocate memory for pdata\n");
  1734. return ERR_PTR(-ENOMEM);
  1735. }
  1736. /* find out number of slots supported */
  1737. if (of_property_read_u32(dev->of_node, "num-slots",
  1738. &pdata->num_slots)) {
  1739. dev_info(dev, "num-slots property not found, "
  1740. "assuming 1 slot is available\n");
  1741. pdata->num_slots = 1;
  1742. }
  1743. /* get quirks */
  1744. for (idx = 0; idx < ARRAY_SIZE(of_quirks); idx++)
  1745. if (of_get_property(np, of_quirks[idx].quirk, NULL))
  1746. pdata->quirks |= of_quirks[idx].id;
  1747. if (of_property_read_u32(np, "fifo-depth", &pdata->fifo_depth))
  1748. dev_info(dev, "fifo-depth property not found, using "
  1749. "value of FIFOTH register as default\n");
  1750. of_property_read_u32(np, "card-detect-delay", &pdata->detect_delay_ms);
  1751. if (drv_data && drv_data->parse_dt) {
  1752. ret = drv_data->parse_dt(host);
  1753. if (ret)
  1754. return ERR_PTR(ret);
  1755. }
  1756. if (of_find_property(np, "keep-power-in-suspend", NULL))
  1757. pdata->pm_caps |= MMC_PM_KEEP_POWER;
  1758. if (of_find_property(np, "enable-sdio-wakeup", NULL))
  1759. pdata->pm_caps |= MMC_PM_WAKE_SDIO_IRQ;
  1760. return pdata;
  1761. }
  1762. #else /* CONFIG_OF */
  1763. static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
  1764. {
  1765. return ERR_PTR(-EINVAL);
  1766. }
  1767. #endif /* CONFIG_OF */
  1768. int dw_mci_probe(struct dw_mci *host)
  1769. {
  1770. const struct dw_mci_drv_data *drv_data = host->drv_data;
  1771. int width, i, ret = 0;
  1772. u32 fifo_size;
  1773. int init_slots = 0;
  1774. if (!host->pdata) {
  1775. host->pdata = dw_mci_parse_dt(host);
  1776. if (IS_ERR(host->pdata)) {
  1777. dev_err(host->dev, "platform data not available\n");
  1778. return -EINVAL;
  1779. }
  1780. }
  1781. if (!host->pdata->select_slot && host->pdata->num_slots > 1) {
  1782. dev_err(host->dev,
  1783. "Platform data must supply select_slot function\n");
  1784. return -ENODEV;
  1785. }
  1786. host->biu_clk = clk_get(host->dev, "biu");
  1787. if (IS_ERR(host->biu_clk)) {
  1788. dev_dbg(host->dev, "biu clock not available\n");
  1789. } else {
  1790. ret = clk_prepare_enable(host->biu_clk);
  1791. if (ret) {
  1792. dev_err(host->dev, "failed to enable biu clock\n");
  1793. clk_put(host->biu_clk);
  1794. return ret;
  1795. }
  1796. }
  1797. host->ciu_clk = clk_get(host->dev, "ciu");
  1798. if (IS_ERR(host->ciu_clk)) {
  1799. dev_dbg(host->dev, "ciu clock not available\n");
  1800. } else {
  1801. ret = clk_prepare_enable(host->ciu_clk);
  1802. if (ret) {
  1803. dev_err(host->dev, "failed to enable ciu clock\n");
  1804. clk_put(host->ciu_clk);
  1805. goto err_clk_biu;
  1806. }
  1807. }
  1808. if (IS_ERR(host->ciu_clk))
  1809. host->bus_hz = host->pdata->bus_hz;
  1810. else
  1811. host->bus_hz = clk_get_rate(host->ciu_clk);
  1812. if (drv_data && drv_data->setup_clock) {
  1813. ret = drv_data->setup_clock(host);
  1814. if (ret) {
  1815. dev_err(host->dev,
  1816. "implementation specific clock setup failed\n");
  1817. goto err_clk_ciu;
  1818. }
  1819. }
  1820. if (!host->bus_hz) {
  1821. dev_err(host->dev,
  1822. "Platform data must supply bus speed\n");
  1823. ret = -ENODEV;
  1824. goto err_clk_ciu;
  1825. }
  1826. host->quirks = host->pdata->quirks;
  1827. spin_lock_init(&host->lock);
  1828. INIT_LIST_HEAD(&host->queue);
  1829. /*
  1830. * Get the host data width - this assumes that HCON has been set with
  1831. * the correct values.
  1832. */
  1833. i = (mci_readl(host, HCON) >> 7) & 0x7;
  1834. if (!i) {
  1835. host->push_data = dw_mci_push_data16;
  1836. host->pull_data = dw_mci_pull_data16;
  1837. width = 16;
  1838. host->data_shift = 1;
  1839. } else if (i == 2) {
  1840. host->push_data = dw_mci_push_data64;
  1841. host->pull_data = dw_mci_pull_data64;
  1842. width = 64;
  1843. host->data_shift = 3;
  1844. } else {
  1845. /* Check for a reserved value, and warn if it is */
  1846. WARN((i != 1),
  1847. "HCON reports a reserved host data width!\n"
  1848. "Defaulting to 32-bit access.\n");
  1849. host->push_data = dw_mci_push_data32;
  1850. host->pull_data = dw_mci_pull_data32;
  1851. width = 32;
  1852. host->data_shift = 2;
  1853. }
  1854. /* Reset all blocks */
  1855. if (!mci_wait_reset(host->dev, host))
  1856. return -ENODEV;
  1857. host->dma_ops = host->pdata->dma_ops;
  1858. dw_mci_init_dma(host);
  1859. /* Clear the interrupts for the host controller */
  1860. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  1861. mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
  1862. /* Put in max timeout */
  1863. mci_writel(host, TMOUT, 0xFFFFFFFF);
  1864. /*
  1865. * FIFO threshold settings RxMark = fifo_size / 2 - 1,
  1866. * Tx Mark = fifo_size / 2 DMA Size = 8
  1867. */
  1868. if (!host->pdata->fifo_depth) {
  1869. /*
  1870. * Power-on value of RX_WMark is FIFO_DEPTH-1, but this may
  1871. * have been overwritten by the bootloader, just like we're
  1872. * about to do, so if you know the value for your hardware, you
  1873. * should put it in the platform data.
  1874. */
  1875. fifo_size = mci_readl(host, FIFOTH);
  1876. fifo_size = 1 + ((fifo_size >> 16) & 0xfff);
  1877. } else {
  1878. fifo_size = host->pdata->fifo_depth;
  1879. }
  1880. host->fifo_depth = fifo_size;
  1881. host->fifoth_val = ((0x2 << 28) | ((fifo_size/2 - 1) << 16) |
  1882. ((fifo_size/2) << 0));
  1883. mci_writel(host, FIFOTH, host->fifoth_val);
  1884. /* disable clock to CIU */
  1885. mci_writel(host, CLKENA, 0);
  1886. mci_writel(host, CLKSRC, 0);
  1887. tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host);
  1888. host->card_workqueue = alloc_workqueue("dw-mci-card",
  1889. WQ_MEM_RECLAIM | WQ_NON_REENTRANT, 1);
  1890. if (!host->card_workqueue)
  1891. goto err_dmaunmap;
  1892. INIT_WORK(&host->card_work, dw_mci_work_routine_card);
  1893. ret = request_irq(host->irq, dw_mci_interrupt, host->irq_flags, "dw-mci", host);
  1894. if (ret)
  1895. goto err_workqueue;
  1896. if (host->pdata->num_slots)
  1897. host->num_slots = host->pdata->num_slots;
  1898. else
  1899. host->num_slots = ((mci_readl(host, HCON) >> 1) & 0x1F) + 1;
  1900. /*
  1901. * Enable interrupts for command done, data over, data empty, card det,
  1902. * receive ready and error such as transmit, receive timeout, crc error
  1903. */
  1904. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  1905. mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
  1906. SDMMC_INT_TXDR | SDMMC_INT_RXDR |
  1907. DW_MCI_ERROR_FLAGS | SDMMC_INT_CD);
  1908. mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); /* Enable mci interrupt */
  1909. dev_info(host->dev, "DW MMC controller at irq %d, "
  1910. "%d bit host data width, "
  1911. "%u deep fifo\n",
  1912. host->irq, width, fifo_size);
  1913. /* We need at least one slot to succeed */
  1914. for (i = 0; i < host->num_slots; i++) {
  1915. ret = dw_mci_init_slot(host, i);
  1916. if (ret)
  1917. dev_dbg(host->dev, "slot %d init failed\n", i);
  1918. else
  1919. init_slots++;
  1920. }
  1921. if (init_slots) {
  1922. dev_info(host->dev, "%d slots initialized\n", init_slots);
  1923. } else {
  1924. dev_dbg(host->dev, "attempted to initialize %d slots, "
  1925. "but failed on all\n", host->num_slots);
  1926. goto err_init_slot;
  1927. }
  1928. /*
  1929. * In 2.40a spec, Data offset is changed.
  1930. * Need to check the version-id and set data-offset for DATA register.
  1931. */
  1932. host->verid = SDMMC_GET_VERID(mci_readl(host, VERID));
  1933. dev_info(host->dev, "Version ID is %04x\n", host->verid);
  1934. if (host->verid < DW_MMC_240A)
  1935. host->data_offset = DATA_OFFSET;
  1936. else
  1937. host->data_offset = DATA_240A_OFFSET;
  1938. if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO)
  1939. dev_info(host->dev, "Internal DMAC interrupt fix enabled.\n");
  1940. return 0;
  1941. err_init_slot:
  1942. free_irq(host->irq, host);
  1943. err_workqueue:
  1944. destroy_workqueue(host->card_workqueue);
  1945. err_dmaunmap:
  1946. if (host->use_dma && host->dma_ops->exit)
  1947. host->dma_ops->exit(host);
  1948. dma_free_coherent(host->dev, PAGE_SIZE,
  1949. host->sg_cpu, host->sg_dma);
  1950. if (host->vmmc) {
  1951. regulator_disable(host->vmmc);
  1952. regulator_put(host->vmmc);
  1953. }
  1954. err_clk_ciu:
  1955. if (!IS_ERR(host->ciu_clk)) {
  1956. clk_disable_unprepare(host->ciu_clk);
  1957. clk_put(host->ciu_clk);
  1958. }
  1959. err_clk_biu:
  1960. if (!IS_ERR(host->biu_clk)) {
  1961. clk_disable_unprepare(host->biu_clk);
  1962. clk_put(host->biu_clk);
  1963. }
  1964. return ret;
  1965. }
  1966. EXPORT_SYMBOL(dw_mci_probe);
  1967. void dw_mci_remove(struct dw_mci *host)
  1968. {
  1969. int i;
  1970. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  1971. mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
  1972. for (i = 0; i < host->num_slots; i++) {
  1973. dev_dbg(host->dev, "remove slot %d\n", i);
  1974. if (host->slot[i])
  1975. dw_mci_cleanup_slot(host->slot[i], i);
  1976. }
  1977. /* disable clock to CIU */
  1978. mci_writel(host, CLKENA, 0);
  1979. mci_writel(host, CLKSRC, 0);
  1980. free_irq(host->irq, host);
  1981. destroy_workqueue(host->card_workqueue);
  1982. dma_free_coherent(host->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma);
  1983. if (host->use_dma && host->dma_ops->exit)
  1984. host->dma_ops->exit(host);
  1985. if (host->vmmc) {
  1986. regulator_disable(host->vmmc);
  1987. regulator_put(host->vmmc);
  1988. }
  1989. if (!IS_ERR(host->ciu_clk))
  1990. clk_disable_unprepare(host->ciu_clk);
  1991. if (!IS_ERR(host->biu_clk))
  1992. clk_disable_unprepare(host->biu_clk);
  1993. clk_put(host->ciu_clk);
  1994. clk_put(host->biu_clk);
  1995. }
  1996. EXPORT_SYMBOL(dw_mci_remove);
  1997. #ifdef CONFIG_PM_SLEEP
  1998. /*
  1999. * TODO: we should probably disable the clock to the card in the suspend path.
  2000. */
  2001. int dw_mci_suspend(struct dw_mci *host)
  2002. {
  2003. int i, ret = 0;
  2004. for (i = 0; i < host->num_slots; i++) {
  2005. struct dw_mci_slot *slot = host->slot[i];
  2006. if (!slot)
  2007. continue;
  2008. ret = mmc_suspend_host(slot->mmc);
  2009. if (ret < 0) {
  2010. while (--i >= 0) {
  2011. slot = host->slot[i];
  2012. if (slot)
  2013. mmc_resume_host(host->slot[i]->mmc);
  2014. }
  2015. return ret;
  2016. }
  2017. }
  2018. if (host->vmmc)
  2019. regulator_disable(host->vmmc);
  2020. return 0;
  2021. }
  2022. EXPORT_SYMBOL(dw_mci_suspend);
  2023. int dw_mci_resume(struct dw_mci *host)
  2024. {
  2025. int i, ret;
  2026. if (host->vmmc)
  2027. regulator_enable(host->vmmc);
  2028. if (!mci_wait_reset(host->dev, host)) {
  2029. ret = -ENODEV;
  2030. return ret;
  2031. }
  2032. if (host->use_dma && host->dma_ops->init)
  2033. host->dma_ops->init(host);
  2034. /* Restore the old value at FIFOTH register */
  2035. mci_writel(host, FIFOTH, host->fifoth_val);
  2036. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  2037. mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
  2038. SDMMC_INT_TXDR | SDMMC_INT_RXDR |
  2039. DW_MCI_ERROR_FLAGS | SDMMC_INT_CD);
  2040. mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE);
  2041. for (i = 0; i < host->num_slots; i++) {
  2042. struct dw_mci_slot *slot = host->slot[i];
  2043. if (!slot)
  2044. continue;
  2045. if (slot->mmc->pm_flags & MMC_PM_KEEP_POWER) {
  2046. dw_mci_set_ios(slot->mmc, &slot->mmc->ios);
  2047. dw_mci_setup_bus(slot, true);
  2048. }
  2049. ret = mmc_resume_host(host->slot[i]->mmc);
  2050. if (ret < 0)
  2051. return ret;
  2052. }
  2053. return 0;
  2054. }
  2055. EXPORT_SYMBOL(dw_mci_resume);
  2056. #endif /* CONFIG_PM_SLEEP */
  2057. static int __init dw_mci_init(void)
  2058. {
  2059. printk(KERN_INFO "Synopsys Designware Multimedia Card Interface Driver");
  2060. return 0;
  2061. }
  2062. static void __exit dw_mci_exit(void)
  2063. {
  2064. }
  2065. module_init(dw_mci_init);
  2066. module_exit(dw_mci_exit);
  2067. MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
  2068. MODULE_AUTHOR("NXP Semiconductor VietNam");
  2069. MODULE_AUTHOR("Imagination Technologies Ltd");
  2070. MODULE_LICENSE("GPL v2");