dw_mmc.c 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521
  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/iopoll.h>
  22. #include <linux/ioport.h>
  23. #include <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/pm_runtime.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/slab.h>
  28. #include <linux/stat.h>
  29. #include <linux/delay.h>
  30. #include <linux/irq.h>
  31. #include <linux/mmc/card.h>
  32. #include <linux/mmc/host.h>
  33. #include <linux/mmc/mmc.h>
  34. #include <linux/mmc/sd.h>
  35. #include <linux/mmc/sdio.h>
  36. #include <linux/bitops.h>
  37. #include <linux/regulator/consumer.h>
  38. #include <linux/of.h>
  39. #include <linux/of_gpio.h>
  40. #include <linux/mmc/slot-gpio.h>
  41. #include "dw_mmc.h"
  42. /* Common flag combinations */
  43. #define DW_MCI_DATA_ERROR_FLAGS (SDMMC_INT_DRTO | SDMMC_INT_DCRC | \
  44. SDMMC_INT_HTO | SDMMC_INT_SBE | \
  45. SDMMC_INT_EBE | SDMMC_INT_HLE)
  46. #define DW_MCI_CMD_ERROR_FLAGS (SDMMC_INT_RTO | SDMMC_INT_RCRC | \
  47. SDMMC_INT_RESP_ERR | SDMMC_INT_HLE)
  48. #define DW_MCI_ERROR_FLAGS (DW_MCI_DATA_ERROR_FLAGS | \
  49. DW_MCI_CMD_ERROR_FLAGS)
  50. #define DW_MCI_SEND_STATUS 1
  51. #define DW_MCI_RECV_STATUS 2
  52. #define DW_MCI_DMA_THRESHOLD 16
  53. #define DW_MCI_FREQ_MAX 200000000 /* unit: HZ */
  54. #define DW_MCI_FREQ_MIN 100000 /* unit: HZ */
  55. #define IDMAC_INT_CLR (SDMMC_IDMAC_INT_AI | SDMMC_IDMAC_INT_NI | \
  56. SDMMC_IDMAC_INT_CES | SDMMC_IDMAC_INT_DU | \
  57. SDMMC_IDMAC_INT_FBE | SDMMC_IDMAC_INT_RI | \
  58. SDMMC_IDMAC_INT_TI)
  59. #define DESC_RING_BUF_SZ PAGE_SIZE
  60. struct idmac_desc_64addr {
  61. u32 des0; /* Control Descriptor */
  62. #define IDMAC_OWN_CLR64(x) \
  63. !((x) & cpu_to_le32(IDMAC_DES0_OWN))
  64. u32 des1; /* Reserved */
  65. u32 des2; /*Buffer sizes */
  66. #define IDMAC_64ADDR_SET_BUFFER1_SIZE(d, s) \
  67. ((d)->des2 = ((d)->des2 & cpu_to_le32(0x03ffe000)) | \
  68. ((cpu_to_le32(s)) & cpu_to_le32(0x1fff)))
  69. u32 des3; /* Reserved */
  70. u32 des4; /* Lower 32-bits of Buffer Address Pointer 1*/
  71. u32 des5; /* Upper 32-bits of Buffer Address Pointer 1*/
  72. u32 des6; /* Lower 32-bits of Next Descriptor Address */
  73. u32 des7; /* Upper 32-bits of Next Descriptor Address */
  74. };
  75. struct idmac_desc {
  76. __le32 des0; /* Control Descriptor */
  77. #define IDMAC_DES0_DIC BIT(1)
  78. #define IDMAC_DES0_LD BIT(2)
  79. #define IDMAC_DES0_FD BIT(3)
  80. #define IDMAC_DES0_CH BIT(4)
  81. #define IDMAC_DES0_ER BIT(5)
  82. #define IDMAC_DES0_CES BIT(30)
  83. #define IDMAC_DES0_OWN BIT(31)
  84. __le32 des1; /* Buffer sizes */
  85. #define IDMAC_SET_BUFFER1_SIZE(d, s) \
  86. ((d)->des1 = ((d)->des1 & cpu_to_le32(0x03ffe000)) | (cpu_to_le32((s) & 0x1fff)))
  87. __le32 des2; /* buffer 1 physical address */
  88. __le32 des3; /* buffer 2 physical address */
  89. };
  90. /* Each descriptor can transfer up to 4KB of data in chained mode */
  91. #define DW_MCI_DESC_DATA_LENGTH 0x1000
  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. DEFINE_SHOW_ATTRIBUTE(dw_mci_req);
  128. static int dw_mci_regs_show(struct seq_file *s, void *v)
  129. {
  130. struct dw_mci *host = s->private;
  131. pm_runtime_get_sync(host->dev);
  132. seq_printf(s, "STATUS:\t0x%08x\n", mci_readl(host, STATUS));
  133. seq_printf(s, "RINTSTS:\t0x%08x\n", mci_readl(host, RINTSTS));
  134. seq_printf(s, "CMD:\t0x%08x\n", mci_readl(host, CMD));
  135. seq_printf(s, "CTRL:\t0x%08x\n", mci_readl(host, CTRL));
  136. seq_printf(s, "INTMASK:\t0x%08x\n", mci_readl(host, INTMASK));
  137. seq_printf(s, "CLKENA:\t0x%08x\n", mci_readl(host, CLKENA));
  138. pm_runtime_put_autosuspend(host->dev);
  139. return 0;
  140. }
  141. DEFINE_SHOW_ATTRIBUTE(dw_mci_regs);
  142. static void dw_mci_init_debugfs(struct dw_mci_slot *slot)
  143. {
  144. struct mmc_host *mmc = slot->mmc;
  145. struct dw_mci *host = slot->host;
  146. struct dentry *root;
  147. struct dentry *node;
  148. root = mmc->debugfs_root;
  149. if (!root)
  150. return;
  151. node = debugfs_create_file("regs", S_IRUSR, root, host,
  152. &dw_mci_regs_fops);
  153. if (!node)
  154. goto err;
  155. node = debugfs_create_file("req", S_IRUSR, root, slot,
  156. &dw_mci_req_fops);
  157. if (!node)
  158. goto err;
  159. node = debugfs_create_u32("state", S_IRUSR, root, (u32 *)&host->state);
  160. if (!node)
  161. goto err;
  162. node = debugfs_create_x32("pending_events", S_IRUSR, root,
  163. (u32 *)&host->pending_events);
  164. if (!node)
  165. goto err;
  166. node = debugfs_create_x32("completed_events", S_IRUSR, root,
  167. (u32 *)&host->completed_events);
  168. if (!node)
  169. goto err;
  170. return;
  171. err:
  172. dev_err(&mmc->class_dev, "failed to initialize debugfs for slot\n");
  173. }
  174. #endif /* defined(CONFIG_DEBUG_FS) */
  175. static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset)
  176. {
  177. u32 ctrl;
  178. ctrl = mci_readl(host, CTRL);
  179. ctrl |= reset;
  180. mci_writel(host, CTRL, ctrl);
  181. /* wait till resets clear */
  182. if (readl_poll_timeout_atomic(host->regs + SDMMC_CTRL, ctrl,
  183. !(ctrl & reset),
  184. 1, 500 * USEC_PER_MSEC)) {
  185. dev_err(host->dev,
  186. "Timeout resetting block (ctrl reset %#x)\n",
  187. ctrl & reset);
  188. return false;
  189. }
  190. return true;
  191. }
  192. static void dw_mci_wait_while_busy(struct dw_mci *host, u32 cmd_flags)
  193. {
  194. u32 status;
  195. /*
  196. * Databook says that before issuing a new data transfer command
  197. * we need to check to see if the card is busy. Data transfer commands
  198. * all have SDMMC_CMD_PRV_DAT_WAIT set, so we'll key off that.
  199. *
  200. * ...also allow sending for SDMMC_CMD_VOLT_SWITCH where busy is
  201. * expected.
  202. */
  203. if ((cmd_flags & SDMMC_CMD_PRV_DAT_WAIT) &&
  204. !(cmd_flags & SDMMC_CMD_VOLT_SWITCH)) {
  205. if (readl_poll_timeout_atomic(host->regs + SDMMC_STATUS,
  206. status,
  207. !(status & SDMMC_STATUS_BUSY),
  208. 10, 500 * USEC_PER_MSEC))
  209. dev_err(host->dev, "Busy; trying anyway\n");
  210. }
  211. }
  212. static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg)
  213. {
  214. struct dw_mci *host = slot->host;
  215. unsigned int cmd_status = 0;
  216. mci_writel(host, CMDARG, arg);
  217. wmb(); /* drain writebuffer */
  218. dw_mci_wait_while_busy(host, cmd);
  219. mci_writel(host, CMD, SDMMC_CMD_START | cmd);
  220. if (readl_poll_timeout_atomic(host->regs + SDMMC_CMD, cmd_status,
  221. !(cmd_status & SDMMC_CMD_START),
  222. 1, 500 * USEC_PER_MSEC))
  223. dev_err(&slot->mmc->class_dev,
  224. "Timeout sending command (cmd %#x arg %#x status %#x)\n",
  225. cmd, arg, cmd_status);
  226. }
  227. static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
  228. {
  229. struct dw_mci_slot *slot = mmc_priv(mmc);
  230. struct dw_mci *host = slot->host;
  231. u32 cmdr;
  232. cmd->error = -EINPROGRESS;
  233. cmdr = cmd->opcode;
  234. if (cmd->opcode == MMC_STOP_TRANSMISSION ||
  235. cmd->opcode == MMC_GO_IDLE_STATE ||
  236. cmd->opcode == MMC_GO_INACTIVE_STATE ||
  237. (cmd->opcode == SD_IO_RW_DIRECT &&
  238. ((cmd->arg >> 9) & 0x1FFFF) == SDIO_CCCR_ABORT))
  239. cmdr |= SDMMC_CMD_STOP;
  240. else if (cmd->opcode != MMC_SEND_STATUS && cmd->data)
  241. cmdr |= SDMMC_CMD_PRV_DAT_WAIT;
  242. if (cmd->opcode == SD_SWITCH_VOLTAGE) {
  243. u32 clk_en_a;
  244. /* Special bit makes CMD11 not die */
  245. cmdr |= SDMMC_CMD_VOLT_SWITCH;
  246. /* Change state to continue to handle CMD11 weirdness */
  247. WARN_ON(slot->host->state != STATE_SENDING_CMD);
  248. slot->host->state = STATE_SENDING_CMD11;
  249. /*
  250. * We need to disable low power mode (automatic clock stop)
  251. * while doing voltage switch so we don't confuse the card,
  252. * since stopping the clock is a specific part of the UHS
  253. * voltage change dance.
  254. *
  255. * Note that low power mode (SDMMC_CLKEN_LOW_PWR) will be
  256. * unconditionally turned back on in dw_mci_setup_bus() if it's
  257. * ever called with a non-zero clock. That shouldn't happen
  258. * until the voltage change is all done.
  259. */
  260. clk_en_a = mci_readl(host, CLKENA);
  261. clk_en_a &= ~(SDMMC_CLKEN_LOW_PWR << slot->id);
  262. mci_writel(host, CLKENA, clk_en_a);
  263. mci_send_cmd(slot, SDMMC_CMD_UPD_CLK |
  264. SDMMC_CMD_PRV_DAT_WAIT, 0);
  265. }
  266. if (cmd->flags & MMC_RSP_PRESENT) {
  267. /* We expect a response, so set this bit */
  268. cmdr |= SDMMC_CMD_RESP_EXP;
  269. if (cmd->flags & MMC_RSP_136)
  270. cmdr |= SDMMC_CMD_RESP_LONG;
  271. }
  272. if (cmd->flags & MMC_RSP_CRC)
  273. cmdr |= SDMMC_CMD_RESP_CRC;
  274. if (cmd->data) {
  275. cmdr |= SDMMC_CMD_DAT_EXP;
  276. if (cmd->data->flags & MMC_DATA_WRITE)
  277. cmdr |= SDMMC_CMD_DAT_WR;
  278. }
  279. if (!test_bit(DW_MMC_CARD_NO_USE_HOLD, &slot->flags))
  280. cmdr |= SDMMC_CMD_USE_HOLD_REG;
  281. return cmdr;
  282. }
  283. static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd)
  284. {
  285. struct mmc_command *stop;
  286. u32 cmdr;
  287. if (!cmd->data)
  288. return 0;
  289. stop = &host->stop_abort;
  290. cmdr = cmd->opcode;
  291. memset(stop, 0, sizeof(struct mmc_command));
  292. if (cmdr == MMC_READ_SINGLE_BLOCK ||
  293. cmdr == MMC_READ_MULTIPLE_BLOCK ||
  294. cmdr == MMC_WRITE_BLOCK ||
  295. cmdr == MMC_WRITE_MULTIPLE_BLOCK ||
  296. cmdr == MMC_SEND_TUNING_BLOCK ||
  297. cmdr == MMC_SEND_TUNING_BLOCK_HS200) {
  298. stop->opcode = MMC_STOP_TRANSMISSION;
  299. stop->arg = 0;
  300. stop->flags = MMC_RSP_R1B | MMC_CMD_AC;
  301. } else if (cmdr == SD_IO_RW_EXTENDED) {
  302. stop->opcode = SD_IO_RW_DIRECT;
  303. stop->arg |= (1 << 31) | (0 << 28) | (SDIO_CCCR_ABORT << 9) |
  304. ((cmd->arg >> 28) & 0x7);
  305. stop->flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_AC;
  306. } else {
  307. return 0;
  308. }
  309. cmdr = stop->opcode | SDMMC_CMD_STOP |
  310. SDMMC_CMD_RESP_CRC | SDMMC_CMD_RESP_EXP;
  311. if (!test_bit(DW_MMC_CARD_NO_USE_HOLD, &host->slot->flags))
  312. cmdr |= SDMMC_CMD_USE_HOLD_REG;
  313. return cmdr;
  314. }
  315. static inline void dw_mci_set_cto(struct dw_mci *host)
  316. {
  317. unsigned int cto_clks;
  318. unsigned int cto_div;
  319. unsigned int cto_ms;
  320. unsigned long irqflags;
  321. cto_clks = mci_readl(host, TMOUT) & 0xff;
  322. cto_div = (mci_readl(host, CLKDIV) & 0xff) * 2;
  323. if (cto_div == 0)
  324. cto_div = 1;
  325. cto_ms = DIV_ROUND_UP_ULL((u64)MSEC_PER_SEC * cto_clks * cto_div,
  326. host->bus_hz);
  327. /* add a bit spare time */
  328. cto_ms += 10;
  329. /*
  330. * The durations we're working with are fairly short so we have to be
  331. * extra careful about synchronization here. Specifically in hardware a
  332. * command timeout is _at most_ 5.1 ms, so that means we expect an
  333. * interrupt (either command done or timeout) to come rather quickly
  334. * after the mci_writel. ...but just in case we have a long interrupt
  335. * latency let's add a bit of paranoia.
  336. *
  337. * In general we'll assume that at least an interrupt will be asserted
  338. * in hardware by the time the cto_timer runs. ...and if it hasn't
  339. * been asserted in hardware by that time then we'll assume it'll never
  340. * come.
  341. */
  342. spin_lock_irqsave(&host->irq_lock, irqflags);
  343. if (!test_bit(EVENT_CMD_COMPLETE, &host->pending_events))
  344. mod_timer(&host->cto_timer,
  345. jiffies + msecs_to_jiffies(cto_ms) + 1);
  346. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  347. }
  348. static void dw_mci_start_command(struct dw_mci *host,
  349. struct mmc_command *cmd, u32 cmd_flags)
  350. {
  351. host->cmd = cmd;
  352. dev_vdbg(host->dev,
  353. "start command: ARGR=0x%08x CMDR=0x%08x\n",
  354. cmd->arg, cmd_flags);
  355. mci_writel(host, CMDARG, cmd->arg);
  356. wmb(); /* drain writebuffer */
  357. dw_mci_wait_while_busy(host, cmd_flags);
  358. mci_writel(host, CMD, cmd_flags | SDMMC_CMD_START);
  359. /* response expected command only */
  360. if (cmd_flags & SDMMC_CMD_RESP_EXP)
  361. dw_mci_set_cto(host);
  362. }
  363. static inline void send_stop_abort(struct dw_mci *host, struct mmc_data *data)
  364. {
  365. struct mmc_command *stop = &host->stop_abort;
  366. dw_mci_start_command(host, stop, host->stop_cmdr);
  367. }
  368. /* DMA interface functions */
  369. static void dw_mci_stop_dma(struct dw_mci *host)
  370. {
  371. if (host->using_dma) {
  372. host->dma_ops->stop(host);
  373. host->dma_ops->cleanup(host);
  374. }
  375. /* Data transfer was stopped by the interrupt handler */
  376. set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
  377. }
  378. static void dw_mci_dma_cleanup(struct dw_mci *host)
  379. {
  380. struct mmc_data *data = host->data;
  381. if (data && data->host_cookie == COOKIE_MAPPED) {
  382. dma_unmap_sg(host->dev,
  383. data->sg,
  384. data->sg_len,
  385. mmc_get_dma_dir(data));
  386. data->host_cookie = COOKIE_UNMAPPED;
  387. }
  388. }
  389. static void dw_mci_idmac_reset(struct dw_mci *host)
  390. {
  391. u32 bmod = mci_readl(host, BMOD);
  392. /* Software reset of DMA */
  393. bmod |= SDMMC_IDMAC_SWRESET;
  394. mci_writel(host, BMOD, bmod);
  395. }
  396. static void dw_mci_idmac_stop_dma(struct dw_mci *host)
  397. {
  398. u32 temp;
  399. /* Disable and reset the IDMAC interface */
  400. temp = mci_readl(host, CTRL);
  401. temp &= ~SDMMC_CTRL_USE_IDMAC;
  402. temp |= SDMMC_CTRL_DMA_RESET;
  403. mci_writel(host, CTRL, temp);
  404. /* Stop the IDMAC running */
  405. temp = mci_readl(host, BMOD);
  406. temp &= ~(SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB);
  407. temp |= SDMMC_IDMAC_SWRESET;
  408. mci_writel(host, BMOD, temp);
  409. }
  410. static void dw_mci_dmac_complete_dma(void *arg)
  411. {
  412. struct dw_mci *host = arg;
  413. struct mmc_data *data = host->data;
  414. dev_vdbg(host->dev, "DMA complete\n");
  415. if ((host->use_dma == TRANS_MODE_EDMAC) &&
  416. data && (data->flags & MMC_DATA_READ))
  417. /* Invalidate cache after read */
  418. dma_sync_sg_for_cpu(mmc_dev(host->slot->mmc),
  419. data->sg,
  420. data->sg_len,
  421. DMA_FROM_DEVICE);
  422. host->dma_ops->cleanup(host);
  423. /*
  424. * If the card was removed, data will be NULL. No point in trying to
  425. * send the stop command or waiting for NBUSY in this case.
  426. */
  427. if (data) {
  428. set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
  429. tasklet_schedule(&host->tasklet);
  430. }
  431. }
  432. static int dw_mci_idmac_init(struct dw_mci *host)
  433. {
  434. int i;
  435. if (host->dma_64bit_address == 1) {
  436. struct idmac_desc_64addr *p;
  437. /* Number of descriptors in the ring buffer */
  438. host->ring_size =
  439. DESC_RING_BUF_SZ / sizeof(struct idmac_desc_64addr);
  440. /* Forward link the descriptor list */
  441. for (i = 0, p = host->sg_cpu; i < host->ring_size - 1;
  442. i++, p++) {
  443. p->des6 = (host->sg_dma +
  444. (sizeof(struct idmac_desc_64addr) *
  445. (i + 1))) & 0xffffffff;
  446. p->des7 = (u64)(host->sg_dma +
  447. (sizeof(struct idmac_desc_64addr) *
  448. (i + 1))) >> 32;
  449. /* Initialize reserved and buffer size fields to "0" */
  450. p->des0 = 0;
  451. p->des1 = 0;
  452. p->des2 = 0;
  453. p->des3 = 0;
  454. }
  455. /* Set the last descriptor as the end-of-ring descriptor */
  456. p->des6 = host->sg_dma & 0xffffffff;
  457. p->des7 = (u64)host->sg_dma >> 32;
  458. p->des0 = IDMAC_DES0_ER;
  459. } else {
  460. struct idmac_desc *p;
  461. /* Number of descriptors in the ring buffer */
  462. host->ring_size =
  463. DESC_RING_BUF_SZ / sizeof(struct idmac_desc);
  464. /* Forward link the descriptor list */
  465. for (i = 0, p = host->sg_cpu;
  466. i < host->ring_size - 1;
  467. i++, p++) {
  468. p->des3 = cpu_to_le32(host->sg_dma +
  469. (sizeof(struct idmac_desc) * (i + 1)));
  470. p->des0 = 0;
  471. p->des1 = 0;
  472. }
  473. /* Set the last descriptor as the end-of-ring descriptor */
  474. p->des3 = cpu_to_le32(host->sg_dma);
  475. p->des0 = cpu_to_le32(IDMAC_DES0_ER);
  476. }
  477. dw_mci_idmac_reset(host);
  478. if (host->dma_64bit_address == 1) {
  479. /* Mask out interrupts - get Tx & Rx complete only */
  480. mci_writel(host, IDSTS64, IDMAC_INT_CLR);
  481. mci_writel(host, IDINTEN64, SDMMC_IDMAC_INT_NI |
  482. SDMMC_IDMAC_INT_RI | SDMMC_IDMAC_INT_TI);
  483. /* Set the descriptor base address */
  484. mci_writel(host, DBADDRL, host->sg_dma & 0xffffffff);
  485. mci_writel(host, DBADDRU, (u64)host->sg_dma >> 32);
  486. } else {
  487. /* Mask out interrupts - get Tx & Rx complete only */
  488. mci_writel(host, IDSTS, IDMAC_INT_CLR);
  489. mci_writel(host, IDINTEN, SDMMC_IDMAC_INT_NI |
  490. SDMMC_IDMAC_INT_RI | SDMMC_IDMAC_INT_TI);
  491. /* Set the descriptor base address */
  492. mci_writel(host, DBADDR, host->sg_dma);
  493. }
  494. return 0;
  495. }
  496. static inline int dw_mci_prepare_desc64(struct dw_mci *host,
  497. struct mmc_data *data,
  498. unsigned int sg_len)
  499. {
  500. unsigned int desc_len;
  501. struct idmac_desc_64addr *desc_first, *desc_last, *desc;
  502. u32 val;
  503. int i;
  504. desc_first = desc_last = desc = host->sg_cpu;
  505. for (i = 0; i < sg_len; i++) {
  506. unsigned int length = sg_dma_len(&data->sg[i]);
  507. u64 mem_addr = sg_dma_address(&data->sg[i]);
  508. for ( ; length ; desc++) {
  509. desc_len = (length <= DW_MCI_DESC_DATA_LENGTH) ?
  510. length : DW_MCI_DESC_DATA_LENGTH;
  511. length -= desc_len;
  512. /*
  513. * Wait for the former clear OWN bit operation
  514. * of IDMAC to make sure that this descriptor
  515. * isn't still owned by IDMAC as IDMAC's write
  516. * ops and CPU's read ops are asynchronous.
  517. */
  518. if (readl_poll_timeout_atomic(&desc->des0, val,
  519. !(val & IDMAC_DES0_OWN),
  520. 10, 100 * USEC_PER_MSEC))
  521. goto err_own_bit;
  522. /*
  523. * Set the OWN bit and disable interrupts
  524. * for this descriptor
  525. */
  526. desc->des0 = IDMAC_DES0_OWN | IDMAC_DES0_DIC |
  527. IDMAC_DES0_CH;
  528. /* Buffer length */
  529. IDMAC_64ADDR_SET_BUFFER1_SIZE(desc, desc_len);
  530. /* Physical address to DMA to/from */
  531. desc->des4 = mem_addr & 0xffffffff;
  532. desc->des5 = mem_addr >> 32;
  533. /* Update physical address for the next desc */
  534. mem_addr += desc_len;
  535. /* Save pointer to the last descriptor */
  536. desc_last = desc;
  537. }
  538. }
  539. /* Set first descriptor */
  540. desc_first->des0 |= IDMAC_DES0_FD;
  541. /* Set last descriptor */
  542. desc_last->des0 &= ~(IDMAC_DES0_CH | IDMAC_DES0_DIC);
  543. desc_last->des0 |= IDMAC_DES0_LD;
  544. return 0;
  545. err_own_bit:
  546. /* restore the descriptor chain as it's polluted */
  547. dev_dbg(host->dev, "descriptor is still owned by IDMAC.\n");
  548. memset(host->sg_cpu, 0, DESC_RING_BUF_SZ);
  549. dw_mci_idmac_init(host);
  550. return -EINVAL;
  551. }
  552. static inline int dw_mci_prepare_desc32(struct dw_mci *host,
  553. struct mmc_data *data,
  554. unsigned int sg_len)
  555. {
  556. unsigned int desc_len;
  557. struct idmac_desc *desc_first, *desc_last, *desc;
  558. u32 val;
  559. int i;
  560. desc_first = desc_last = desc = host->sg_cpu;
  561. for (i = 0; i < sg_len; i++) {
  562. unsigned int length = sg_dma_len(&data->sg[i]);
  563. u32 mem_addr = sg_dma_address(&data->sg[i]);
  564. for ( ; length ; desc++) {
  565. desc_len = (length <= DW_MCI_DESC_DATA_LENGTH) ?
  566. length : DW_MCI_DESC_DATA_LENGTH;
  567. length -= desc_len;
  568. /*
  569. * Wait for the former clear OWN bit operation
  570. * of IDMAC to make sure that this descriptor
  571. * isn't still owned by IDMAC as IDMAC's write
  572. * ops and CPU's read ops are asynchronous.
  573. */
  574. if (readl_poll_timeout_atomic(&desc->des0, val,
  575. IDMAC_OWN_CLR64(val),
  576. 10,
  577. 100 * USEC_PER_MSEC))
  578. goto err_own_bit;
  579. /*
  580. * Set the OWN bit and disable interrupts
  581. * for this descriptor
  582. */
  583. desc->des0 = cpu_to_le32(IDMAC_DES0_OWN |
  584. IDMAC_DES0_DIC |
  585. IDMAC_DES0_CH);
  586. /* Buffer length */
  587. IDMAC_SET_BUFFER1_SIZE(desc, desc_len);
  588. /* Physical address to DMA to/from */
  589. desc->des2 = cpu_to_le32(mem_addr);
  590. /* Update physical address for the next desc */
  591. mem_addr += desc_len;
  592. /* Save pointer to the last descriptor */
  593. desc_last = desc;
  594. }
  595. }
  596. /* Set first descriptor */
  597. desc_first->des0 |= cpu_to_le32(IDMAC_DES0_FD);
  598. /* Set last descriptor */
  599. desc_last->des0 &= cpu_to_le32(~(IDMAC_DES0_CH |
  600. IDMAC_DES0_DIC));
  601. desc_last->des0 |= cpu_to_le32(IDMAC_DES0_LD);
  602. return 0;
  603. err_own_bit:
  604. /* restore the descriptor chain as it's polluted */
  605. dev_dbg(host->dev, "descriptor is still owned by IDMAC.\n");
  606. memset(host->sg_cpu, 0, DESC_RING_BUF_SZ);
  607. dw_mci_idmac_init(host);
  608. return -EINVAL;
  609. }
  610. static int dw_mci_idmac_start_dma(struct dw_mci *host, unsigned int sg_len)
  611. {
  612. u32 temp;
  613. int ret;
  614. if (host->dma_64bit_address == 1)
  615. ret = dw_mci_prepare_desc64(host, host->data, sg_len);
  616. else
  617. ret = dw_mci_prepare_desc32(host, host->data, sg_len);
  618. if (ret)
  619. goto out;
  620. /* drain writebuffer */
  621. wmb();
  622. /* Make sure to reset DMA in case we did PIO before this */
  623. dw_mci_ctrl_reset(host, SDMMC_CTRL_DMA_RESET);
  624. dw_mci_idmac_reset(host);
  625. /* Select IDMAC interface */
  626. temp = mci_readl(host, CTRL);
  627. temp |= SDMMC_CTRL_USE_IDMAC;
  628. mci_writel(host, CTRL, temp);
  629. /* drain writebuffer */
  630. wmb();
  631. /* Enable the IDMAC */
  632. temp = mci_readl(host, BMOD);
  633. temp |= SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB;
  634. mci_writel(host, BMOD, temp);
  635. /* Start it running */
  636. mci_writel(host, PLDMND, 1);
  637. out:
  638. return ret;
  639. }
  640. static const struct dw_mci_dma_ops dw_mci_idmac_ops = {
  641. .init = dw_mci_idmac_init,
  642. .start = dw_mci_idmac_start_dma,
  643. .stop = dw_mci_idmac_stop_dma,
  644. .complete = dw_mci_dmac_complete_dma,
  645. .cleanup = dw_mci_dma_cleanup,
  646. };
  647. static void dw_mci_edmac_stop_dma(struct dw_mci *host)
  648. {
  649. dmaengine_terminate_async(host->dms->ch);
  650. }
  651. static int dw_mci_edmac_start_dma(struct dw_mci *host,
  652. unsigned int sg_len)
  653. {
  654. struct dma_slave_config cfg;
  655. struct dma_async_tx_descriptor *desc = NULL;
  656. struct scatterlist *sgl = host->data->sg;
  657. static const u32 mszs[] = {1, 4, 8, 16, 32, 64, 128, 256};
  658. u32 sg_elems = host->data->sg_len;
  659. u32 fifoth_val;
  660. u32 fifo_offset = host->fifo_reg - host->regs;
  661. int ret = 0;
  662. /* Set external dma config: burst size, burst width */
  663. cfg.dst_addr = host->phy_regs + fifo_offset;
  664. cfg.src_addr = cfg.dst_addr;
  665. cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  666. cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  667. /* Match burst msize with external dma config */
  668. fifoth_val = mci_readl(host, FIFOTH);
  669. cfg.dst_maxburst = mszs[(fifoth_val >> 28) & 0x7];
  670. cfg.src_maxburst = cfg.dst_maxburst;
  671. if (host->data->flags & MMC_DATA_WRITE)
  672. cfg.direction = DMA_MEM_TO_DEV;
  673. else
  674. cfg.direction = DMA_DEV_TO_MEM;
  675. ret = dmaengine_slave_config(host->dms->ch, &cfg);
  676. if (ret) {
  677. dev_err(host->dev, "Failed to config edmac.\n");
  678. return -EBUSY;
  679. }
  680. desc = dmaengine_prep_slave_sg(host->dms->ch, sgl,
  681. sg_len, cfg.direction,
  682. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  683. if (!desc) {
  684. dev_err(host->dev, "Can't prepare slave sg.\n");
  685. return -EBUSY;
  686. }
  687. /* Set dw_mci_dmac_complete_dma as callback */
  688. desc->callback = dw_mci_dmac_complete_dma;
  689. desc->callback_param = (void *)host;
  690. dmaengine_submit(desc);
  691. /* Flush cache before write */
  692. if (host->data->flags & MMC_DATA_WRITE)
  693. dma_sync_sg_for_device(mmc_dev(host->slot->mmc), sgl,
  694. sg_elems, DMA_TO_DEVICE);
  695. dma_async_issue_pending(host->dms->ch);
  696. return 0;
  697. }
  698. static int dw_mci_edmac_init(struct dw_mci *host)
  699. {
  700. /* Request external dma channel */
  701. host->dms = kzalloc(sizeof(struct dw_mci_dma_slave), GFP_KERNEL);
  702. if (!host->dms)
  703. return -ENOMEM;
  704. host->dms->ch = dma_request_slave_channel(host->dev, "rx-tx");
  705. if (!host->dms->ch) {
  706. dev_err(host->dev, "Failed to get external DMA channel.\n");
  707. kfree(host->dms);
  708. host->dms = NULL;
  709. return -ENXIO;
  710. }
  711. return 0;
  712. }
  713. static void dw_mci_edmac_exit(struct dw_mci *host)
  714. {
  715. if (host->dms) {
  716. if (host->dms->ch) {
  717. dma_release_channel(host->dms->ch);
  718. host->dms->ch = NULL;
  719. }
  720. kfree(host->dms);
  721. host->dms = NULL;
  722. }
  723. }
  724. static const struct dw_mci_dma_ops dw_mci_edmac_ops = {
  725. .init = dw_mci_edmac_init,
  726. .exit = dw_mci_edmac_exit,
  727. .start = dw_mci_edmac_start_dma,
  728. .stop = dw_mci_edmac_stop_dma,
  729. .complete = dw_mci_dmac_complete_dma,
  730. .cleanup = dw_mci_dma_cleanup,
  731. };
  732. static int dw_mci_pre_dma_transfer(struct dw_mci *host,
  733. struct mmc_data *data,
  734. int cookie)
  735. {
  736. struct scatterlist *sg;
  737. unsigned int i, sg_len;
  738. if (data->host_cookie == COOKIE_PRE_MAPPED)
  739. return data->sg_len;
  740. /*
  741. * We don't do DMA on "complex" transfers, i.e. with
  742. * non-word-aligned buffers or lengths. Also, we don't bother
  743. * with all the DMA setup overhead for short transfers.
  744. */
  745. if (data->blocks * data->blksz < DW_MCI_DMA_THRESHOLD)
  746. return -EINVAL;
  747. if (data->blksz & 3)
  748. return -EINVAL;
  749. for_each_sg(data->sg, sg, data->sg_len, i) {
  750. if (sg->offset & 3 || sg->length & 3)
  751. return -EINVAL;
  752. }
  753. sg_len = dma_map_sg(host->dev,
  754. data->sg,
  755. data->sg_len,
  756. mmc_get_dma_dir(data));
  757. if (sg_len == 0)
  758. return -EINVAL;
  759. data->host_cookie = cookie;
  760. return sg_len;
  761. }
  762. static void dw_mci_pre_req(struct mmc_host *mmc,
  763. struct mmc_request *mrq)
  764. {
  765. struct dw_mci_slot *slot = mmc_priv(mmc);
  766. struct mmc_data *data = mrq->data;
  767. if (!slot->host->use_dma || !data)
  768. return;
  769. /* This data might be unmapped at this time */
  770. data->host_cookie = COOKIE_UNMAPPED;
  771. if (dw_mci_pre_dma_transfer(slot->host, mrq->data,
  772. COOKIE_PRE_MAPPED) < 0)
  773. data->host_cookie = COOKIE_UNMAPPED;
  774. }
  775. static void dw_mci_post_req(struct mmc_host *mmc,
  776. struct mmc_request *mrq,
  777. int err)
  778. {
  779. struct dw_mci_slot *slot = mmc_priv(mmc);
  780. struct mmc_data *data = mrq->data;
  781. if (!slot->host->use_dma || !data)
  782. return;
  783. if (data->host_cookie != COOKIE_UNMAPPED)
  784. dma_unmap_sg(slot->host->dev,
  785. data->sg,
  786. data->sg_len,
  787. mmc_get_dma_dir(data));
  788. data->host_cookie = COOKIE_UNMAPPED;
  789. }
  790. static int dw_mci_get_cd(struct mmc_host *mmc)
  791. {
  792. int present;
  793. struct dw_mci_slot *slot = mmc_priv(mmc);
  794. struct dw_mci *host = slot->host;
  795. int gpio_cd = mmc_gpio_get_cd(mmc);
  796. /* Use platform get_cd function, else try onboard card detect */
  797. if (((mmc->caps & MMC_CAP_NEEDS_POLL)
  798. || !mmc_card_is_removable(mmc))) {
  799. present = 1;
  800. if (!test_bit(DW_MMC_CARD_PRESENT, &slot->flags)) {
  801. if (mmc->caps & MMC_CAP_NEEDS_POLL) {
  802. dev_info(&mmc->class_dev,
  803. "card is polling.\n");
  804. } else {
  805. dev_info(&mmc->class_dev,
  806. "card is non-removable.\n");
  807. }
  808. set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
  809. }
  810. return present;
  811. } else if (gpio_cd >= 0)
  812. present = gpio_cd;
  813. else
  814. present = (mci_readl(slot->host, CDETECT) & (1 << slot->id))
  815. == 0 ? 1 : 0;
  816. spin_lock_bh(&host->lock);
  817. if (present && !test_and_set_bit(DW_MMC_CARD_PRESENT, &slot->flags))
  818. dev_dbg(&mmc->class_dev, "card is present\n");
  819. else if (!present &&
  820. !test_and_clear_bit(DW_MMC_CARD_PRESENT, &slot->flags))
  821. dev_dbg(&mmc->class_dev, "card is not present\n");
  822. spin_unlock_bh(&host->lock);
  823. return present;
  824. }
  825. static void dw_mci_adjust_fifoth(struct dw_mci *host, struct mmc_data *data)
  826. {
  827. unsigned int blksz = data->blksz;
  828. static const u32 mszs[] = {1, 4, 8, 16, 32, 64, 128, 256};
  829. u32 fifo_width = 1 << host->data_shift;
  830. u32 blksz_depth = blksz / fifo_width, fifoth_val;
  831. u32 msize = 0, rx_wmark = 1, tx_wmark, tx_wmark_invers;
  832. int idx = ARRAY_SIZE(mszs) - 1;
  833. /* pio should ship this scenario */
  834. if (!host->use_dma)
  835. return;
  836. tx_wmark = (host->fifo_depth) / 2;
  837. tx_wmark_invers = host->fifo_depth - tx_wmark;
  838. /*
  839. * MSIZE is '1',
  840. * if blksz is not a multiple of the FIFO width
  841. */
  842. if (blksz % fifo_width)
  843. goto done;
  844. do {
  845. if (!((blksz_depth % mszs[idx]) ||
  846. (tx_wmark_invers % mszs[idx]))) {
  847. msize = idx;
  848. rx_wmark = mszs[idx] - 1;
  849. break;
  850. }
  851. } while (--idx > 0);
  852. /*
  853. * If idx is '0', it won't be tried
  854. * Thus, initial values are uesed
  855. */
  856. done:
  857. fifoth_val = SDMMC_SET_FIFOTH(msize, rx_wmark, tx_wmark);
  858. mci_writel(host, FIFOTH, fifoth_val);
  859. }
  860. static void dw_mci_ctrl_thld(struct dw_mci *host, struct mmc_data *data)
  861. {
  862. unsigned int blksz = data->blksz;
  863. u32 blksz_depth, fifo_depth;
  864. u16 thld_size;
  865. u8 enable;
  866. /*
  867. * CDTHRCTL doesn't exist prior to 240A (in fact that register offset is
  868. * in the FIFO region, so we really shouldn't access it).
  869. */
  870. if (host->verid < DW_MMC_240A ||
  871. (host->verid < DW_MMC_280A && data->flags & MMC_DATA_WRITE))
  872. return;
  873. /*
  874. * Card write Threshold is introduced since 2.80a
  875. * It's used when HS400 mode is enabled.
  876. */
  877. if (data->flags & MMC_DATA_WRITE &&
  878. !(host->timing != MMC_TIMING_MMC_HS400))
  879. return;
  880. if (data->flags & MMC_DATA_WRITE)
  881. enable = SDMMC_CARD_WR_THR_EN;
  882. else
  883. enable = SDMMC_CARD_RD_THR_EN;
  884. if (host->timing != MMC_TIMING_MMC_HS200 &&
  885. host->timing != MMC_TIMING_UHS_SDR104)
  886. goto disable;
  887. blksz_depth = blksz / (1 << host->data_shift);
  888. fifo_depth = host->fifo_depth;
  889. if (blksz_depth > fifo_depth)
  890. goto disable;
  891. /*
  892. * If (blksz_depth) >= (fifo_depth >> 1), should be 'thld_size <= blksz'
  893. * If (blksz_depth) < (fifo_depth >> 1), should be thld_size = blksz
  894. * Currently just choose blksz.
  895. */
  896. thld_size = blksz;
  897. mci_writel(host, CDTHRCTL, SDMMC_SET_THLD(thld_size, enable));
  898. return;
  899. disable:
  900. mci_writel(host, CDTHRCTL, 0);
  901. }
  902. static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
  903. {
  904. unsigned long irqflags;
  905. int sg_len;
  906. u32 temp;
  907. host->using_dma = 0;
  908. /* If we don't have a channel, we can't do DMA */
  909. if (!host->use_dma)
  910. return -ENODEV;
  911. sg_len = dw_mci_pre_dma_transfer(host, data, COOKIE_MAPPED);
  912. if (sg_len < 0) {
  913. host->dma_ops->stop(host);
  914. return sg_len;
  915. }
  916. host->using_dma = 1;
  917. if (host->use_dma == TRANS_MODE_IDMAC)
  918. dev_vdbg(host->dev,
  919. "sd sg_cpu: %#lx sg_dma: %#lx sg_len: %d\n",
  920. (unsigned long)host->sg_cpu,
  921. (unsigned long)host->sg_dma,
  922. sg_len);
  923. /*
  924. * Decide the MSIZE and RX/TX Watermark.
  925. * If current block size is same with previous size,
  926. * no need to update fifoth.
  927. */
  928. if (host->prev_blksz != data->blksz)
  929. dw_mci_adjust_fifoth(host, data);
  930. /* Enable the DMA interface */
  931. temp = mci_readl(host, CTRL);
  932. temp |= SDMMC_CTRL_DMA_ENABLE;
  933. mci_writel(host, CTRL, temp);
  934. /* Disable RX/TX IRQs, let DMA handle it */
  935. spin_lock_irqsave(&host->irq_lock, irqflags);
  936. temp = mci_readl(host, INTMASK);
  937. temp &= ~(SDMMC_INT_RXDR | SDMMC_INT_TXDR);
  938. mci_writel(host, INTMASK, temp);
  939. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  940. if (host->dma_ops->start(host, sg_len)) {
  941. host->dma_ops->stop(host);
  942. /* We can't do DMA, try PIO for this one */
  943. dev_dbg(host->dev,
  944. "%s: fall back to PIO mode for current transfer\n",
  945. __func__);
  946. return -ENODEV;
  947. }
  948. return 0;
  949. }
  950. static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data)
  951. {
  952. unsigned long irqflags;
  953. int flags = SG_MITER_ATOMIC;
  954. u32 temp;
  955. data->error = -EINPROGRESS;
  956. WARN_ON(host->data);
  957. host->sg = NULL;
  958. host->data = data;
  959. if (data->flags & MMC_DATA_READ)
  960. host->dir_status = DW_MCI_RECV_STATUS;
  961. else
  962. host->dir_status = DW_MCI_SEND_STATUS;
  963. dw_mci_ctrl_thld(host, data);
  964. if (dw_mci_submit_data_dma(host, data)) {
  965. if (host->data->flags & MMC_DATA_READ)
  966. flags |= SG_MITER_TO_SG;
  967. else
  968. flags |= SG_MITER_FROM_SG;
  969. sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
  970. host->sg = data->sg;
  971. host->part_buf_start = 0;
  972. host->part_buf_count = 0;
  973. mci_writel(host, RINTSTS, SDMMC_INT_TXDR | SDMMC_INT_RXDR);
  974. spin_lock_irqsave(&host->irq_lock, irqflags);
  975. temp = mci_readl(host, INTMASK);
  976. temp |= SDMMC_INT_TXDR | SDMMC_INT_RXDR;
  977. mci_writel(host, INTMASK, temp);
  978. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  979. temp = mci_readl(host, CTRL);
  980. temp &= ~SDMMC_CTRL_DMA_ENABLE;
  981. mci_writel(host, CTRL, temp);
  982. /*
  983. * Use the initial fifoth_val for PIO mode. If wm_algined
  984. * is set, we set watermark same as data size.
  985. * If next issued data may be transfered by DMA mode,
  986. * prev_blksz should be invalidated.
  987. */
  988. if (host->wm_aligned)
  989. dw_mci_adjust_fifoth(host, data);
  990. else
  991. mci_writel(host, FIFOTH, host->fifoth_val);
  992. host->prev_blksz = 0;
  993. } else {
  994. /*
  995. * Keep the current block size.
  996. * It will be used to decide whether to update
  997. * fifoth register next time.
  998. */
  999. host->prev_blksz = data->blksz;
  1000. }
  1001. }
  1002. static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
  1003. {
  1004. struct dw_mci *host = slot->host;
  1005. unsigned int clock = slot->clock;
  1006. u32 div;
  1007. u32 clk_en_a;
  1008. u32 sdmmc_cmd_bits = SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT;
  1009. /* We must continue to set bit 28 in CMD until the change is complete */
  1010. if (host->state == STATE_WAITING_CMD11_DONE)
  1011. sdmmc_cmd_bits |= SDMMC_CMD_VOLT_SWITCH;
  1012. slot->mmc->actual_clock = 0;
  1013. if (!clock) {
  1014. mci_writel(host, CLKENA, 0);
  1015. mci_send_cmd(slot, sdmmc_cmd_bits, 0);
  1016. } else if (clock != host->current_speed || force_clkinit) {
  1017. div = host->bus_hz / clock;
  1018. if (host->bus_hz % clock && host->bus_hz > clock)
  1019. /*
  1020. * move the + 1 after the divide to prevent
  1021. * over-clocking the card.
  1022. */
  1023. div += 1;
  1024. div = (host->bus_hz != clock) ? DIV_ROUND_UP(div, 2) : 0;
  1025. if ((clock != slot->__clk_old &&
  1026. !test_bit(DW_MMC_CARD_NEEDS_POLL, &slot->flags)) ||
  1027. force_clkinit) {
  1028. /* Silent the verbose log if calling from PM context */
  1029. if (!force_clkinit)
  1030. dev_info(&slot->mmc->class_dev,
  1031. "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ div = %d)\n",
  1032. slot->id, host->bus_hz, clock,
  1033. div ? ((host->bus_hz / div) >> 1) :
  1034. host->bus_hz, div);
  1035. /*
  1036. * If card is polling, display the message only
  1037. * one time at boot time.
  1038. */
  1039. if (slot->mmc->caps & MMC_CAP_NEEDS_POLL &&
  1040. slot->mmc->f_min == clock)
  1041. set_bit(DW_MMC_CARD_NEEDS_POLL, &slot->flags);
  1042. }
  1043. /* disable clock */
  1044. mci_writel(host, CLKENA, 0);
  1045. mci_writel(host, CLKSRC, 0);
  1046. /* inform CIU */
  1047. mci_send_cmd(slot, sdmmc_cmd_bits, 0);
  1048. /* set clock to desired speed */
  1049. mci_writel(host, CLKDIV, div);
  1050. /* inform CIU */
  1051. mci_send_cmd(slot, sdmmc_cmd_bits, 0);
  1052. /* enable clock; only low power if no SDIO */
  1053. clk_en_a = SDMMC_CLKEN_ENABLE << slot->id;
  1054. if (!test_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags))
  1055. clk_en_a |= SDMMC_CLKEN_LOW_PWR << slot->id;
  1056. mci_writel(host, CLKENA, clk_en_a);
  1057. /* inform CIU */
  1058. mci_send_cmd(slot, sdmmc_cmd_bits, 0);
  1059. /* keep the last clock value that was requested from core */
  1060. slot->__clk_old = clock;
  1061. slot->mmc->actual_clock = div ? ((host->bus_hz / div) >> 1) :
  1062. host->bus_hz;
  1063. }
  1064. host->current_speed = clock;
  1065. /* Set the current slot bus width */
  1066. mci_writel(host, CTYPE, (slot->ctype << slot->id));
  1067. }
  1068. static void __dw_mci_start_request(struct dw_mci *host,
  1069. struct dw_mci_slot *slot,
  1070. struct mmc_command *cmd)
  1071. {
  1072. struct mmc_request *mrq;
  1073. struct mmc_data *data;
  1074. u32 cmdflags;
  1075. mrq = slot->mrq;
  1076. host->mrq = mrq;
  1077. host->pending_events = 0;
  1078. host->completed_events = 0;
  1079. host->cmd_status = 0;
  1080. host->data_status = 0;
  1081. host->dir_status = 0;
  1082. data = cmd->data;
  1083. if (data) {
  1084. mci_writel(host, TMOUT, 0xFFFFFFFF);
  1085. mci_writel(host, BYTCNT, data->blksz*data->blocks);
  1086. mci_writel(host, BLKSIZ, data->blksz);
  1087. }
  1088. cmdflags = dw_mci_prepare_command(slot->mmc, cmd);
  1089. /* this is the first command, send the initialization clock */
  1090. if (test_and_clear_bit(DW_MMC_CARD_NEED_INIT, &slot->flags))
  1091. cmdflags |= SDMMC_CMD_INIT;
  1092. if (data) {
  1093. dw_mci_submit_data(host, data);
  1094. wmb(); /* drain writebuffer */
  1095. }
  1096. dw_mci_start_command(host, cmd, cmdflags);
  1097. if (cmd->opcode == SD_SWITCH_VOLTAGE) {
  1098. unsigned long irqflags;
  1099. /*
  1100. * Databook says to fail after 2ms w/ no response, but evidence
  1101. * shows that sometimes the cmd11 interrupt takes over 130ms.
  1102. * We'll set to 500ms, plus an extra jiffy just in case jiffies
  1103. * is just about to roll over.
  1104. *
  1105. * We do this whole thing under spinlock and only if the
  1106. * command hasn't already completed (indicating the the irq
  1107. * already ran so we don't want the timeout).
  1108. */
  1109. spin_lock_irqsave(&host->irq_lock, irqflags);
  1110. if (!test_bit(EVENT_CMD_COMPLETE, &host->pending_events))
  1111. mod_timer(&host->cmd11_timer,
  1112. jiffies + msecs_to_jiffies(500) + 1);
  1113. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  1114. }
  1115. host->stop_cmdr = dw_mci_prep_stop_abort(host, cmd);
  1116. }
  1117. static void dw_mci_start_request(struct dw_mci *host,
  1118. struct dw_mci_slot *slot)
  1119. {
  1120. struct mmc_request *mrq = slot->mrq;
  1121. struct mmc_command *cmd;
  1122. cmd = mrq->sbc ? mrq->sbc : mrq->cmd;
  1123. __dw_mci_start_request(host, slot, cmd);
  1124. }
  1125. /* must be called with host->lock held */
  1126. static void dw_mci_queue_request(struct dw_mci *host, struct dw_mci_slot *slot,
  1127. struct mmc_request *mrq)
  1128. {
  1129. dev_vdbg(&slot->mmc->class_dev, "queue request: state=%d\n",
  1130. host->state);
  1131. slot->mrq = mrq;
  1132. if (host->state == STATE_WAITING_CMD11_DONE) {
  1133. dev_warn(&slot->mmc->class_dev,
  1134. "Voltage change didn't complete\n");
  1135. /*
  1136. * this case isn't expected to happen, so we can
  1137. * either crash here or just try to continue on
  1138. * in the closest possible state
  1139. */
  1140. host->state = STATE_IDLE;
  1141. }
  1142. if (host->state == STATE_IDLE) {
  1143. host->state = STATE_SENDING_CMD;
  1144. dw_mci_start_request(host, slot);
  1145. } else {
  1146. list_add_tail(&slot->queue_node, &host->queue);
  1147. }
  1148. }
  1149. static void dw_mci_request(struct mmc_host *mmc, struct mmc_request *mrq)
  1150. {
  1151. struct dw_mci_slot *slot = mmc_priv(mmc);
  1152. struct dw_mci *host = slot->host;
  1153. WARN_ON(slot->mrq);
  1154. /*
  1155. * The check for card presence and queueing of the request must be
  1156. * atomic, otherwise the card could be removed in between and the
  1157. * request wouldn't fail until another card was inserted.
  1158. */
  1159. if (!dw_mci_get_cd(mmc)) {
  1160. mrq->cmd->error = -ENOMEDIUM;
  1161. mmc_request_done(mmc, mrq);
  1162. return;
  1163. }
  1164. spin_lock_bh(&host->lock);
  1165. dw_mci_queue_request(host, slot, mrq);
  1166. spin_unlock_bh(&host->lock);
  1167. }
  1168. static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  1169. {
  1170. struct dw_mci_slot *slot = mmc_priv(mmc);
  1171. const struct dw_mci_drv_data *drv_data = slot->host->drv_data;
  1172. u32 regs;
  1173. int ret;
  1174. switch (ios->bus_width) {
  1175. case MMC_BUS_WIDTH_4:
  1176. slot->ctype = SDMMC_CTYPE_4BIT;
  1177. break;
  1178. case MMC_BUS_WIDTH_8:
  1179. slot->ctype = SDMMC_CTYPE_8BIT;
  1180. break;
  1181. default:
  1182. /* set default 1 bit mode */
  1183. slot->ctype = SDMMC_CTYPE_1BIT;
  1184. }
  1185. regs = mci_readl(slot->host, UHS_REG);
  1186. /* DDR mode set */
  1187. if (ios->timing == MMC_TIMING_MMC_DDR52 ||
  1188. ios->timing == MMC_TIMING_UHS_DDR50 ||
  1189. ios->timing == MMC_TIMING_MMC_HS400)
  1190. regs |= ((0x1 << slot->id) << 16);
  1191. else
  1192. regs &= ~((0x1 << slot->id) << 16);
  1193. mci_writel(slot->host, UHS_REG, regs);
  1194. slot->host->timing = ios->timing;
  1195. /*
  1196. * Use mirror of ios->clock to prevent race with mmc
  1197. * core ios update when finding the minimum.
  1198. */
  1199. slot->clock = ios->clock;
  1200. if (drv_data && drv_data->set_ios)
  1201. drv_data->set_ios(slot->host, ios);
  1202. switch (ios->power_mode) {
  1203. case MMC_POWER_UP:
  1204. if (!IS_ERR(mmc->supply.vmmc)) {
  1205. ret = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,
  1206. ios->vdd);
  1207. if (ret) {
  1208. dev_err(slot->host->dev,
  1209. "failed to enable vmmc regulator\n");
  1210. /*return, if failed turn on vmmc*/
  1211. return;
  1212. }
  1213. }
  1214. set_bit(DW_MMC_CARD_NEED_INIT, &slot->flags);
  1215. regs = mci_readl(slot->host, PWREN);
  1216. regs |= (1 << slot->id);
  1217. mci_writel(slot->host, PWREN, regs);
  1218. break;
  1219. case MMC_POWER_ON:
  1220. if (!slot->host->vqmmc_enabled) {
  1221. if (!IS_ERR(mmc->supply.vqmmc)) {
  1222. ret = regulator_enable(mmc->supply.vqmmc);
  1223. if (ret < 0)
  1224. dev_err(slot->host->dev,
  1225. "failed to enable vqmmc\n");
  1226. else
  1227. slot->host->vqmmc_enabled = true;
  1228. } else {
  1229. /* Keep track so we don't reset again */
  1230. slot->host->vqmmc_enabled = true;
  1231. }
  1232. /* Reset our state machine after powering on */
  1233. dw_mci_ctrl_reset(slot->host,
  1234. SDMMC_CTRL_ALL_RESET_FLAGS);
  1235. }
  1236. /* Adjust clock / bus width after power is up */
  1237. dw_mci_setup_bus(slot, false);
  1238. break;
  1239. case MMC_POWER_OFF:
  1240. /* Turn clock off before power goes down */
  1241. dw_mci_setup_bus(slot, false);
  1242. if (!IS_ERR(mmc->supply.vmmc))
  1243. mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
  1244. if (!IS_ERR(mmc->supply.vqmmc) && slot->host->vqmmc_enabled)
  1245. regulator_disable(mmc->supply.vqmmc);
  1246. slot->host->vqmmc_enabled = false;
  1247. regs = mci_readl(slot->host, PWREN);
  1248. regs &= ~(1 << slot->id);
  1249. mci_writel(slot->host, PWREN, regs);
  1250. break;
  1251. default:
  1252. break;
  1253. }
  1254. if (slot->host->state == STATE_WAITING_CMD11_DONE && ios->clock != 0)
  1255. slot->host->state = STATE_IDLE;
  1256. }
  1257. static int dw_mci_card_busy(struct mmc_host *mmc)
  1258. {
  1259. struct dw_mci_slot *slot = mmc_priv(mmc);
  1260. u32 status;
  1261. /*
  1262. * Check the busy bit which is low when DAT[3:0]
  1263. * (the data lines) are 0000
  1264. */
  1265. status = mci_readl(slot->host, STATUS);
  1266. return !!(status & SDMMC_STATUS_BUSY);
  1267. }
  1268. static int dw_mci_switch_voltage(struct mmc_host *mmc, struct mmc_ios *ios)
  1269. {
  1270. struct dw_mci_slot *slot = mmc_priv(mmc);
  1271. struct dw_mci *host = slot->host;
  1272. const struct dw_mci_drv_data *drv_data = host->drv_data;
  1273. u32 uhs;
  1274. u32 v18 = SDMMC_UHS_18V << slot->id;
  1275. int ret;
  1276. if (drv_data && drv_data->switch_voltage)
  1277. return drv_data->switch_voltage(mmc, ios);
  1278. /*
  1279. * Program the voltage. Note that some instances of dw_mmc may use
  1280. * the UHS_REG for this. For other instances (like exynos) the UHS_REG
  1281. * does no harm but you need to set the regulator directly. Try both.
  1282. */
  1283. uhs = mci_readl(host, UHS_REG);
  1284. if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330)
  1285. uhs &= ~v18;
  1286. else
  1287. uhs |= v18;
  1288. if (!IS_ERR(mmc->supply.vqmmc)) {
  1289. ret = mmc_regulator_set_vqmmc(mmc, ios);
  1290. if (ret) {
  1291. dev_dbg(&mmc->class_dev,
  1292. "Regulator set error %d - %s V\n",
  1293. ret, uhs & v18 ? "1.8" : "3.3");
  1294. return ret;
  1295. }
  1296. }
  1297. mci_writel(host, UHS_REG, uhs);
  1298. return 0;
  1299. }
  1300. static int dw_mci_get_ro(struct mmc_host *mmc)
  1301. {
  1302. int read_only;
  1303. struct dw_mci_slot *slot = mmc_priv(mmc);
  1304. int gpio_ro = mmc_gpio_get_ro(mmc);
  1305. /* Use platform get_ro function, else try on board write protect */
  1306. if (gpio_ro >= 0)
  1307. read_only = gpio_ro;
  1308. else
  1309. read_only =
  1310. mci_readl(slot->host, WRTPRT) & (1 << slot->id) ? 1 : 0;
  1311. dev_dbg(&mmc->class_dev, "card is %s\n",
  1312. read_only ? "read-only" : "read-write");
  1313. return read_only;
  1314. }
  1315. static void dw_mci_hw_reset(struct mmc_host *mmc)
  1316. {
  1317. struct dw_mci_slot *slot = mmc_priv(mmc);
  1318. struct dw_mci *host = slot->host;
  1319. int reset;
  1320. if (host->use_dma == TRANS_MODE_IDMAC)
  1321. dw_mci_idmac_reset(host);
  1322. if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_DMA_RESET |
  1323. SDMMC_CTRL_FIFO_RESET))
  1324. return;
  1325. /*
  1326. * According to eMMC spec, card reset procedure:
  1327. * tRstW >= 1us: RST_n pulse width
  1328. * tRSCA >= 200us: RST_n to Command time
  1329. * tRSTH >= 1us: RST_n high period
  1330. */
  1331. reset = mci_readl(host, RST_N);
  1332. reset &= ~(SDMMC_RST_HWACTIVE << slot->id);
  1333. mci_writel(host, RST_N, reset);
  1334. usleep_range(1, 2);
  1335. reset |= SDMMC_RST_HWACTIVE << slot->id;
  1336. mci_writel(host, RST_N, reset);
  1337. usleep_range(200, 300);
  1338. }
  1339. static void dw_mci_init_card(struct mmc_host *mmc, struct mmc_card *card)
  1340. {
  1341. struct dw_mci_slot *slot = mmc_priv(mmc);
  1342. struct dw_mci *host = slot->host;
  1343. /*
  1344. * Low power mode will stop the card clock when idle. According to the
  1345. * description of the CLKENA register we should disable low power mode
  1346. * for SDIO cards if we need SDIO interrupts to work.
  1347. */
  1348. if (mmc->caps & MMC_CAP_SDIO_IRQ) {
  1349. const u32 clken_low_pwr = SDMMC_CLKEN_LOW_PWR << slot->id;
  1350. u32 clk_en_a_old;
  1351. u32 clk_en_a;
  1352. clk_en_a_old = mci_readl(host, CLKENA);
  1353. if (card->type == MMC_TYPE_SDIO ||
  1354. card->type == MMC_TYPE_SD_COMBO) {
  1355. set_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags);
  1356. clk_en_a = clk_en_a_old & ~clken_low_pwr;
  1357. } else {
  1358. clear_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags);
  1359. clk_en_a = clk_en_a_old | clken_low_pwr;
  1360. }
  1361. if (clk_en_a != clk_en_a_old) {
  1362. mci_writel(host, CLKENA, clk_en_a);
  1363. mci_send_cmd(slot, SDMMC_CMD_UPD_CLK |
  1364. SDMMC_CMD_PRV_DAT_WAIT, 0);
  1365. }
  1366. }
  1367. }
  1368. static void __dw_mci_enable_sdio_irq(struct dw_mci_slot *slot, int enb)
  1369. {
  1370. struct dw_mci *host = slot->host;
  1371. unsigned long irqflags;
  1372. u32 int_mask;
  1373. spin_lock_irqsave(&host->irq_lock, irqflags);
  1374. /* Enable/disable Slot Specific SDIO interrupt */
  1375. int_mask = mci_readl(host, INTMASK);
  1376. if (enb)
  1377. int_mask |= SDMMC_INT_SDIO(slot->sdio_id);
  1378. else
  1379. int_mask &= ~SDMMC_INT_SDIO(slot->sdio_id);
  1380. mci_writel(host, INTMASK, int_mask);
  1381. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  1382. }
  1383. static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb)
  1384. {
  1385. struct dw_mci_slot *slot = mmc_priv(mmc);
  1386. struct dw_mci *host = slot->host;
  1387. __dw_mci_enable_sdio_irq(slot, enb);
  1388. /* Avoid runtime suspending the device when SDIO IRQ is enabled */
  1389. if (enb)
  1390. pm_runtime_get_noresume(host->dev);
  1391. else
  1392. pm_runtime_put_noidle(host->dev);
  1393. }
  1394. static void dw_mci_ack_sdio_irq(struct mmc_host *mmc)
  1395. {
  1396. struct dw_mci_slot *slot = mmc_priv(mmc);
  1397. __dw_mci_enable_sdio_irq(slot, 1);
  1398. }
  1399. static int dw_mci_execute_tuning(struct mmc_host *mmc, u32 opcode)
  1400. {
  1401. struct dw_mci_slot *slot = mmc_priv(mmc);
  1402. struct dw_mci *host = slot->host;
  1403. const struct dw_mci_drv_data *drv_data = host->drv_data;
  1404. int err = -EINVAL;
  1405. if (drv_data && drv_data->execute_tuning)
  1406. err = drv_data->execute_tuning(slot, opcode);
  1407. return err;
  1408. }
  1409. static int dw_mci_prepare_hs400_tuning(struct mmc_host *mmc,
  1410. struct mmc_ios *ios)
  1411. {
  1412. struct dw_mci_slot *slot = mmc_priv(mmc);
  1413. struct dw_mci *host = slot->host;
  1414. const struct dw_mci_drv_data *drv_data = host->drv_data;
  1415. if (drv_data && drv_data->prepare_hs400_tuning)
  1416. return drv_data->prepare_hs400_tuning(host, ios);
  1417. return 0;
  1418. }
  1419. static bool dw_mci_reset(struct dw_mci *host)
  1420. {
  1421. u32 flags = SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET;
  1422. bool ret = false;
  1423. u32 status = 0;
  1424. /*
  1425. * Resetting generates a block interrupt, hence setting
  1426. * the scatter-gather pointer to NULL.
  1427. */
  1428. if (host->sg) {
  1429. sg_miter_stop(&host->sg_miter);
  1430. host->sg = NULL;
  1431. }
  1432. if (host->use_dma)
  1433. flags |= SDMMC_CTRL_DMA_RESET;
  1434. if (dw_mci_ctrl_reset(host, flags)) {
  1435. /*
  1436. * In all cases we clear the RAWINTS
  1437. * register to clear any interrupts.
  1438. */
  1439. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  1440. if (!host->use_dma) {
  1441. ret = true;
  1442. goto ciu_out;
  1443. }
  1444. /* Wait for dma_req to be cleared */
  1445. if (readl_poll_timeout_atomic(host->regs + SDMMC_STATUS,
  1446. status,
  1447. !(status & SDMMC_STATUS_DMA_REQ),
  1448. 1, 500 * USEC_PER_MSEC)) {
  1449. dev_err(host->dev,
  1450. "%s: Timeout waiting for dma_req to be cleared\n",
  1451. __func__);
  1452. goto ciu_out;
  1453. }
  1454. /* when using DMA next we reset the fifo again */
  1455. if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET))
  1456. goto ciu_out;
  1457. } else {
  1458. /* if the controller reset bit did clear, then set clock regs */
  1459. if (!(mci_readl(host, CTRL) & SDMMC_CTRL_RESET)) {
  1460. dev_err(host->dev,
  1461. "%s: fifo/dma reset bits didn't clear but ciu was reset, doing clock update\n",
  1462. __func__);
  1463. goto ciu_out;
  1464. }
  1465. }
  1466. if (host->use_dma == TRANS_MODE_IDMAC)
  1467. /* It is also required that we reinit idmac */
  1468. dw_mci_idmac_init(host);
  1469. ret = true;
  1470. ciu_out:
  1471. /* After a CTRL reset we need to have CIU set clock registers */
  1472. mci_send_cmd(host->slot, SDMMC_CMD_UPD_CLK, 0);
  1473. return ret;
  1474. }
  1475. static const struct mmc_host_ops dw_mci_ops = {
  1476. .request = dw_mci_request,
  1477. .pre_req = dw_mci_pre_req,
  1478. .post_req = dw_mci_post_req,
  1479. .set_ios = dw_mci_set_ios,
  1480. .get_ro = dw_mci_get_ro,
  1481. .get_cd = dw_mci_get_cd,
  1482. .hw_reset = dw_mci_hw_reset,
  1483. .enable_sdio_irq = dw_mci_enable_sdio_irq,
  1484. .ack_sdio_irq = dw_mci_ack_sdio_irq,
  1485. .execute_tuning = dw_mci_execute_tuning,
  1486. .card_busy = dw_mci_card_busy,
  1487. .start_signal_voltage_switch = dw_mci_switch_voltage,
  1488. .init_card = dw_mci_init_card,
  1489. .prepare_hs400_tuning = dw_mci_prepare_hs400_tuning,
  1490. };
  1491. static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)
  1492. __releases(&host->lock)
  1493. __acquires(&host->lock)
  1494. {
  1495. struct dw_mci_slot *slot;
  1496. struct mmc_host *prev_mmc = host->slot->mmc;
  1497. WARN_ON(host->cmd || host->data);
  1498. host->slot->mrq = NULL;
  1499. host->mrq = NULL;
  1500. if (!list_empty(&host->queue)) {
  1501. slot = list_entry(host->queue.next,
  1502. struct dw_mci_slot, queue_node);
  1503. list_del(&slot->queue_node);
  1504. dev_vdbg(host->dev, "list not empty: %s is next\n",
  1505. mmc_hostname(slot->mmc));
  1506. host->state = STATE_SENDING_CMD;
  1507. dw_mci_start_request(host, slot);
  1508. } else {
  1509. dev_vdbg(host->dev, "list empty\n");
  1510. if (host->state == STATE_SENDING_CMD11)
  1511. host->state = STATE_WAITING_CMD11_DONE;
  1512. else
  1513. host->state = STATE_IDLE;
  1514. }
  1515. spin_unlock(&host->lock);
  1516. mmc_request_done(prev_mmc, mrq);
  1517. spin_lock(&host->lock);
  1518. }
  1519. static int dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd)
  1520. {
  1521. u32 status = host->cmd_status;
  1522. host->cmd_status = 0;
  1523. /* Read the response from the card (up to 16 bytes) */
  1524. if (cmd->flags & MMC_RSP_PRESENT) {
  1525. if (cmd->flags & MMC_RSP_136) {
  1526. cmd->resp[3] = mci_readl(host, RESP0);
  1527. cmd->resp[2] = mci_readl(host, RESP1);
  1528. cmd->resp[1] = mci_readl(host, RESP2);
  1529. cmd->resp[0] = mci_readl(host, RESP3);
  1530. } else {
  1531. cmd->resp[0] = mci_readl(host, RESP0);
  1532. cmd->resp[1] = 0;
  1533. cmd->resp[2] = 0;
  1534. cmd->resp[3] = 0;
  1535. }
  1536. }
  1537. if (status & SDMMC_INT_RTO)
  1538. cmd->error = -ETIMEDOUT;
  1539. else if ((cmd->flags & MMC_RSP_CRC) && (status & SDMMC_INT_RCRC))
  1540. cmd->error = -EILSEQ;
  1541. else if (status & SDMMC_INT_RESP_ERR)
  1542. cmd->error = -EIO;
  1543. else
  1544. cmd->error = 0;
  1545. return cmd->error;
  1546. }
  1547. static int dw_mci_data_complete(struct dw_mci *host, struct mmc_data *data)
  1548. {
  1549. u32 status = host->data_status;
  1550. if (status & DW_MCI_DATA_ERROR_FLAGS) {
  1551. if (status & SDMMC_INT_DRTO) {
  1552. data->error = -ETIMEDOUT;
  1553. } else if (status & SDMMC_INT_DCRC) {
  1554. data->error = -EILSEQ;
  1555. } else if (status & SDMMC_INT_EBE) {
  1556. if (host->dir_status ==
  1557. DW_MCI_SEND_STATUS) {
  1558. /*
  1559. * No data CRC status was returned.
  1560. * The number of bytes transferred
  1561. * will be exaggerated in PIO mode.
  1562. */
  1563. data->bytes_xfered = 0;
  1564. data->error = -ETIMEDOUT;
  1565. } else if (host->dir_status ==
  1566. DW_MCI_RECV_STATUS) {
  1567. data->error = -EILSEQ;
  1568. }
  1569. } else {
  1570. /* SDMMC_INT_SBE is included */
  1571. data->error = -EILSEQ;
  1572. }
  1573. dev_dbg(host->dev, "data error, status 0x%08x\n", status);
  1574. /*
  1575. * After an error, there may be data lingering
  1576. * in the FIFO
  1577. */
  1578. dw_mci_reset(host);
  1579. } else {
  1580. data->bytes_xfered = data->blocks * data->blksz;
  1581. data->error = 0;
  1582. }
  1583. return data->error;
  1584. }
  1585. static void dw_mci_set_drto(struct dw_mci *host)
  1586. {
  1587. unsigned int drto_clks;
  1588. unsigned int drto_div;
  1589. unsigned int drto_ms;
  1590. unsigned long irqflags;
  1591. drto_clks = mci_readl(host, TMOUT) >> 8;
  1592. drto_div = (mci_readl(host, CLKDIV) & 0xff) * 2;
  1593. if (drto_div == 0)
  1594. drto_div = 1;
  1595. drto_ms = DIV_ROUND_UP_ULL((u64)MSEC_PER_SEC * drto_clks * drto_div,
  1596. host->bus_hz);
  1597. /* add a bit spare time */
  1598. drto_ms += 10;
  1599. spin_lock_irqsave(&host->irq_lock, irqflags);
  1600. if (!test_bit(EVENT_DATA_COMPLETE, &host->pending_events))
  1601. mod_timer(&host->dto_timer,
  1602. jiffies + msecs_to_jiffies(drto_ms));
  1603. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  1604. }
  1605. static bool dw_mci_clear_pending_cmd_complete(struct dw_mci *host)
  1606. {
  1607. if (!test_bit(EVENT_CMD_COMPLETE, &host->pending_events))
  1608. return false;
  1609. /*
  1610. * Really be certain that the timer has stopped. This is a bit of
  1611. * paranoia and could only really happen if we had really bad
  1612. * interrupt latency and the interrupt routine and timeout were
  1613. * running concurrently so that the del_timer() in the interrupt
  1614. * handler couldn't run.
  1615. */
  1616. WARN_ON(del_timer_sync(&host->cto_timer));
  1617. clear_bit(EVENT_CMD_COMPLETE, &host->pending_events);
  1618. return true;
  1619. }
  1620. static bool dw_mci_clear_pending_data_complete(struct dw_mci *host)
  1621. {
  1622. if (!test_bit(EVENT_DATA_COMPLETE, &host->pending_events))
  1623. return false;
  1624. /* Extra paranoia just like dw_mci_clear_pending_cmd_complete() */
  1625. WARN_ON(del_timer_sync(&host->dto_timer));
  1626. clear_bit(EVENT_DATA_COMPLETE, &host->pending_events);
  1627. return true;
  1628. }
  1629. static void dw_mci_tasklet_func(unsigned long priv)
  1630. {
  1631. struct dw_mci *host = (struct dw_mci *)priv;
  1632. struct mmc_data *data;
  1633. struct mmc_command *cmd;
  1634. struct mmc_request *mrq;
  1635. enum dw_mci_state state;
  1636. enum dw_mci_state prev_state;
  1637. unsigned int err;
  1638. spin_lock(&host->lock);
  1639. state = host->state;
  1640. data = host->data;
  1641. mrq = host->mrq;
  1642. do {
  1643. prev_state = state;
  1644. switch (state) {
  1645. case STATE_IDLE:
  1646. case STATE_WAITING_CMD11_DONE:
  1647. break;
  1648. case STATE_SENDING_CMD11:
  1649. case STATE_SENDING_CMD:
  1650. if (!dw_mci_clear_pending_cmd_complete(host))
  1651. break;
  1652. cmd = host->cmd;
  1653. host->cmd = NULL;
  1654. set_bit(EVENT_CMD_COMPLETE, &host->completed_events);
  1655. err = dw_mci_command_complete(host, cmd);
  1656. if (cmd == mrq->sbc && !err) {
  1657. __dw_mci_start_request(host, host->slot,
  1658. mrq->cmd);
  1659. goto unlock;
  1660. }
  1661. if (cmd->data && err) {
  1662. /*
  1663. * During UHS tuning sequence, sending the stop
  1664. * command after the response CRC error would
  1665. * throw the system into a confused state
  1666. * causing all future tuning phases to report
  1667. * failure.
  1668. *
  1669. * In such case controller will move into a data
  1670. * transfer state after a response error or
  1671. * response CRC error. Let's let that finish
  1672. * before trying to send a stop, so we'll go to
  1673. * STATE_SENDING_DATA.
  1674. *
  1675. * Although letting the data transfer take place
  1676. * will waste a bit of time (we already know
  1677. * the command was bad), it can't cause any
  1678. * errors since it's possible it would have
  1679. * taken place anyway if this tasklet got
  1680. * delayed. Allowing the transfer to take place
  1681. * avoids races and keeps things simple.
  1682. */
  1683. if ((err != -ETIMEDOUT) &&
  1684. (cmd->opcode == MMC_SEND_TUNING_BLOCK)) {
  1685. state = STATE_SENDING_DATA;
  1686. continue;
  1687. }
  1688. dw_mci_stop_dma(host);
  1689. send_stop_abort(host, data);
  1690. state = STATE_SENDING_STOP;
  1691. break;
  1692. }
  1693. if (!cmd->data || err) {
  1694. dw_mci_request_end(host, mrq);
  1695. goto unlock;
  1696. }
  1697. prev_state = state = STATE_SENDING_DATA;
  1698. /* fall through */
  1699. case STATE_SENDING_DATA:
  1700. /*
  1701. * We could get a data error and never a transfer
  1702. * complete so we'd better check for it here.
  1703. *
  1704. * Note that we don't really care if we also got a
  1705. * transfer complete; stopping the DMA and sending an
  1706. * abort won't hurt.
  1707. */
  1708. if (test_and_clear_bit(EVENT_DATA_ERROR,
  1709. &host->pending_events)) {
  1710. dw_mci_stop_dma(host);
  1711. if (!(host->data_status & (SDMMC_INT_DRTO |
  1712. SDMMC_INT_EBE)))
  1713. send_stop_abort(host, data);
  1714. state = STATE_DATA_ERROR;
  1715. break;
  1716. }
  1717. if (!test_and_clear_bit(EVENT_XFER_COMPLETE,
  1718. &host->pending_events)) {
  1719. /*
  1720. * If all data-related interrupts don't come
  1721. * within the given time in reading data state.
  1722. */
  1723. if (host->dir_status == DW_MCI_RECV_STATUS)
  1724. dw_mci_set_drto(host);
  1725. break;
  1726. }
  1727. set_bit(EVENT_XFER_COMPLETE, &host->completed_events);
  1728. /*
  1729. * Handle an EVENT_DATA_ERROR that might have shown up
  1730. * before the transfer completed. This might not have
  1731. * been caught by the check above because the interrupt
  1732. * could have gone off between the previous check and
  1733. * the check for transfer complete.
  1734. *
  1735. * Technically this ought not be needed assuming we
  1736. * get a DATA_COMPLETE eventually (we'll notice the
  1737. * error and end the request), but it shouldn't hurt.
  1738. *
  1739. * This has the advantage of sending the stop command.
  1740. */
  1741. if (test_and_clear_bit(EVENT_DATA_ERROR,
  1742. &host->pending_events)) {
  1743. dw_mci_stop_dma(host);
  1744. if (!(host->data_status & (SDMMC_INT_DRTO |
  1745. SDMMC_INT_EBE)))
  1746. send_stop_abort(host, data);
  1747. state = STATE_DATA_ERROR;
  1748. break;
  1749. }
  1750. prev_state = state = STATE_DATA_BUSY;
  1751. /* fall through */
  1752. case STATE_DATA_BUSY:
  1753. if (!dw_mci_clear_pending_data_complete(host)) {
  1754. /*
  1755. * If data error interrupt comes but data over
  1756. * interrupt doesn't come within the given time.
  1757. * in reading data state.
  1758. */
  1759. if (host->dir_status == DW_MCI_RECV_STATUS)
  1760. dw_mci_set_drto(host);
  1761. break;
  1762. }
  1763. host->data = NULL;
  1764. set_bit(EVENT_DATA_COMPLETE, &host->completed_events);
  1765. err = dw_mci_data_complete(host, data);
  1766. if (!err) {
  1767. if (!data->stop || mrq->sbc) {
  1768. if (mrq->sbc && data->stop)
  1769. data->stop->error = 0;
  1770. dw_mci_request_end(host, mrq);
  1771. goto unlock;
  1772. }
  1773. /* stop command for open-ended transfer*/
  1774. if (data->stop)
  1775. send_stop_abort(host, data);
  1776. } else {
  1777. /*
  1778. * If we don't have a command complete now we'll
  1779. * never get one since we just reset everything;
  1780. * better end the request.
  1781. *
  1782. * If we do have a command complete we'll fall
  1783. * through to the SENDING_STOP command and
  1784. * everything will be peachy keen.
  1785. */
  1786. if (!test_bit(EVENT_CMD_COMPLETE,
  1787. &host->pending_events)) {
  1788. host->cmd = NULL;
  1789. dw_mci_request_end(host, mrq);
  1790. goto unlock;
  1791. }
  1792. }
  1793. /*
  1794. * If err has non-zero,
  1795. * stop-abort command has been already issued.
  1796. */
  1797. prev_state = state = STATE_SENDING_STOP;
  1798. /* fall through */
  1799. case STATE_SENDING_STOP:
  1800. if (!dw_mci_clear_pending_cmd_complete(host))
  1801. break;
  1802. /* CMD error in data command */
  1803. if (mrq->cmd->error && mrq->data)
  1804. dw_mci_reset(host);
  1805. host->cmd = NULL;
  1806. host->data = NULL;
  1807. if (!mrq->sbc && mrq->stop)
  1808. dw_mci_command_complete(host, mrq->stop);
  1809. else
  1810. host->cmd_status = 0;
  1811. dw_mci_request_end(host, mrq);
  1812. goto unlock;
  1813. case STATE_DATA_ERROR:
  1814. if (!test_and_clear_bit(EVENT_XFER_COMPLETE,
  1815. &host->pending_events))
  1816. break;
  1817. state = STATE_DATA_BUSY;
  1818. break;
  1819. }
  1820. } while (state != prev_state);
  1821. host->state = state;
  1822. unlock:
  1823. spin_unlock(&host->lock);
  1824. }
  1825. /* push final bytes to part_buf, only use during push */
  1826. static void dw_mci_set_part_bytes(struct dw_mci *host, void *buf, int cnt)
  1827. {
  1828. memcpy((void *)&host->part_buf, buf, cnt);
  1829. host->part_buf_count = cnt;
  1830. }
  1831. /* append bytes to part_buf, only use during push */
  1832. static int dw_mci_push_part_bytes(struct dw_mci *host, void *buf, int cnt)
  1833. {
  1834. cnt = min(cnt, (1 << host->data_shift) - host->part_buf_count);
  1835. memcpy((void *)&host->part_buf + host->part_buf_count, buf, cnt);
  1836. host->part_buf_count += cnt;
  1837. return cnt;
  1838. }
  1839. /* pull first bytes from part_buf, only use during pull */
  1840. static int dw_mci_pull_part_bytes(struct dw_mci *host, void *buf, int cnt)
  1841. {
  1842. cnt = min_t(int, cnt, host->part_buf_count);
  1843. if (cnt) {
  1844. memcpy(buf, (void *)&host->part_buf + host->part_buf_start,
  1845. cnt);
  1846. host->part_buf_count -= cnt;
  1847. host->part_buf_start += cnt;
  1848. }
  1849. return cnt;
  1850. }
  1851. /* pull final bytes from the part_buf, assuming it's just been filled */
  1852. static void dw_mci_pull_final_bytes(struct dw_mci *host, void *buf, int cnt)
  1853. {
  1854. memcpy(buf, &host->part_buf, cnt);
  1855. host->part_buf_start = cnt;
  1856. host->part_buf_count = (1 << host->data_shift) - cnt;
  1857. }
  1858. static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
  1859. {
  1860. struct mmc_data *data = host->data;
  1861. int init_cnt = cnt;
  1862. /* try and push anything in the part_buf */
  1863. if (unlikely(host->part_buf_count)) {
  1864. int len = dw_mci_push_part_bytes(host, buf, cnt);
  1865. buf += len;
  1866. cnt -= len;
  1867. if (host->part_buf_count == 2) {
  1868. mci_fifo_writew(host->fifo_reg, host->part_buf16);
  1869. host->part_buf_count = 0;
  1870. }
  1871. }
  1872. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1873. if (unlikely((unsigned long)buf & 0x1)) {
  1874. while (cnt >= 2) {
  1875. u16 aligned_buf[64];
  1876. int len = min(cnt & -2, (int)sizeof(aligned_buf));
  1877. int items = len >> 1;
  1878. int i;
  1879. /* memcpy from input buffer into aligned buffer */
  1880. memcpy(aligned_buf, buf, len);
  1881. buf += len;
  1882. cnt -= len;
  1883. /* push data from aligned buffer into fifo */
  1884. for (i = 0; i < items; ++i)
  1885. mci_fifo_writew(host->fifo_reg, aligned_buf[i]);
  1886. }
  1887. } else
  1888. #endif
  1889. {
  1890. u16 *pdata = buf;
  1891. for (; cnt >= 2; cnt -= 2)
  1892. mci_fifo_writew(host->fifo_reg, *pdata++);
  1893. buf = pdata;
  1894. }
  1895. /* put anything remaining in the part_buf */
  1896. if (cnt) {
  1897. dw_mci_set_part_bytes(host, buf, cnt);
  1898. /* Push data if we have reached the expected data length */
  1899. if ((data->bytes_xfered + init_cnt) ==
  1900. (data->blksz * data->blocks))
  1901. mci_fifo_writew(host->fifo_reg, host->part_buf16);
  1902. }
  1903. }
  1904. static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
  1905. {
  1906. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1907. if (unlikely((unsigned long)buf & 0x1)) {
  1908. while (cnt >= 2) {
  1909. /* pull data from fifo into aligned buffer */
  1910. u16 aligned_buf[64];
  1911. int len = min(cnt & -2, (int)sizeof(aligned_buf));
  1912. int items = len >> 1;
  1913. int i;
  1914. for (i = 0; i < items; ++i)
  1915. aligned_buf[i] = mci_fifo_readw(host->fifo_reg);
  1916. /* memcpy from aligned buffer into output buffer */
  1917. memcpy(buf, aligned_buf, len);
  1918. buf += len;
  1919. cnt -= len;
  1920. }
  1921. } else
  1922. #endif
  1923. {
  1924. u16 *pdata = buf;
  1925. for (; cnt >= 2; cnt -= 2)
  1926. *pdata++ = mci_fifo_readw(host->fifo_reg);
  1927. buf = pdata;
  1928. }
  1929. if (cnt) {
  1930. host->part_buf16 = mci_fifo_readw(host->fifo_reg);
  1931. dw_mci_pull_final_bytes(host, buf, cnt);
  1932. }
  1933. }
  1934. static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
  1935. {
  1936. struct mmc_data *data = host->data;
  1937. int init_cnt = cnt;
  1938. /* try and push anything in the part_buf */
  1939. if (unlikely(host->part_buf_count)) {
  1940. int len = dw_mci_push_part_bytes(host, buf, cnt);
  1941. buf += len;
  1942. cnt -= len;
  1943. if (host->part_buf_count == 4) {
  1944. mci_fifo_writel(host->fifo_reg, host->part_buf32);
  1945. host->part_buf_count = 0;
  1946. }
  1947. }
  1948. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1949. if (unlikely((unsigned long)buf & 0x3)) {
  1950. while (cnt >= 4) {
  1951. u32 aligned_buf[32];
  1952. int len = min(cnt & -4, (int)sizeof(aligned_buf));
  1953. int items = len >> 2;
  1954. int i;
  1955. /* memcpy from input buffer into aligned buffer */
  1956. memcpy(aligned_buf, buf, len);
  1957. buf += len;
  1958. cnt -= len;
  1959. /* push data from aligned buffer into fifo */
  1960. for (i = 0; i < items; ++i)
  1961. mci_fifo_writel(host->fifo_reg, aligned_buf[i]);
  1962. }
  1963. } else
  1964. #endif
  1965. {
  1966. u32 *pdata = buf;
  1967. for (; cnt >= 4; cnt -= 4)
  1968. mci_fifo_writel(host->fifo_reg, *pdata++);
  1969. buf = pdata;
  1970. }
  1971. /* put anything remaining in the part_buf */
  1972. if (cnt) {
  1973. dw_mci_set_part_bytes(host, buf, cnt);
  1974. /* Push data if we have reached the expected data length */
  1975. if ((data->bytes_xfered + init_cnt) ==
  1976. (data->blksz * data->blocks))
  1977. mci_fifo_writel(host->fifo_reg, host->part_buf32);
  1978. }
  1979. }
  1980. static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
  1981. {
  1982. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1983. if (unlikely((unsigned long)buf & 0x3)) {
  1984. while (cnt >= 4) {
  1985. /* pull data from fifo into aligned buffer */
  1986. u32 aligned_buf[32];
  1987. int len = min(cnt & -4, (int)sizeof(aligned_buf));
  1988. int items = len >> 2;
  1989. int i;
  1990. for (i = 0; i < items; ++i)
  1991. aligned_buf[i] = mci_fifo_readl(host->fifo_reg);
  1992. /* memcpy from aligned buffer into output buffer */
  1993. memcpy(buf, aligned_buf, len);
  1994. buf += len;
  1995. cnt -= len;
  1996. }
  1997. } else
  1998. #endif
  1999. {
  2000. u32 *pdata = buf;
  2001. for (; cnt >= 4; cnt -= 4)
  2002. *pdata++ = mci_fifo_readl(host->fifo_reg);
  2003. buf = pdata;
  2004. }
  2005. if (cnt) {
  2006. host->part_buf32 = mci_fifo_readl(host->fifo_reg);
  2007. dw_mci_pull_final_bytes(host, buf, cnt);
  2008. }
  2009. }
  2010. static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
  2011. {
  2012. struct mmc_data *data = host->data;
  2013. int init_cnt = cnt;
  2014. /* try and push anything in the part_buf */
  2015. if (unlikely(host->part_buf_count)) {
  2016. int len = dw_mci_push_part_bytes(host, buf, cnt);
  2017. buf += len;
  2018. cnt -= len;
  2019. if (host->part_buf_count == 8) {
  2020. mci_fifo_writeq(host->fifo_reg, host->part_buf);
  2021. host->part_buf_count = 0;
  2022. }
  2023. }
  2024. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  2025. if (unlikely((unsigned long)buf & 0x7)) {
  2026. while (cnt >= 8) {
  2027. u64 aligned_buf[16];
  2028. int len = min(cnt & -8, (int)sizeof(aligned_buf));
  2029. int items = len >> 3;
  2030. int i;
  2031. /* memcpy from input buffer into aligned buffer */
  2032. memcpy(aligned_buf, buf, len);
  2033. buf += len;
  2034. cnt -= len;
  2035. /* push data from aligned buffer into fifo */
  2036. for (i = 0; i < items; ++i)
  2037. mci_fifo_writeq(host->fifo_reg, aligned_buf[i]);
  2038. }
  2039. } else
  2040. #endif
  2041. {
  2042. u64 *pdata = buf;
  2043. for (; cnt >= 8; cnt -= 8)
  2044. mci_fifo_writeq(host->fifo_reg, *pdata++);
  2045. buf = pdata;
  2046. }
  2047. /* put anything remaining in the part_buf */
  2048. if (cnt) {
  2049. dw_mci_set_part_bytes(host, buf, cnt);
  2050. /* Push data if we have reached the expected data length */
  2051. if ((data->bytes_xfered + init_cnt) ==
  2052. (data->blksz * data->blocks))
  2053. mci_fifo_writeq(host->fifo_reg, host->part_buf);
  2054. }
  2055. }
  2056. static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
  2057. {
  2058. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  2059. if (unlikely((unsigned long)buf & 0x7)) {
  2060. while (cnt >= 8) {
  2061. /* pull data from fifo into aligned buffer */
  2062. u64 aligned_buf[16];
  2063. int len = min(cnt & -8, (int)sizeof(aligned_buf));
  2064. int items = len >> 3;
  2065. int i;
  2066. for (i = 0; i < items; ++i)
  2067. aligned_buf[i] = mci_fifo_readq(host->fifo_reg);
  2068. /* memcpy from aligned buffer into output buffer */
  2069. memcpy(buf, aligned_buf, len);
  2070. buf += len;
  2071. cnt -= len;
  2072. }
  2073. } else
  2074. #endif
  2075. {
  2076. u64 *pdata = buf;
  2077. for (; cnt >= 8; cnt -= 8)
  2078. *pdata++ = mci_fifo_readq(host->fifo_reg);
  2079. buf = pdata;
  2080. }
  2081. if (cnt) {
  2082. host->part_buf = mci_fifo_readq(host->fifo_reg);
  2083. dw_mci_pull_final_bytes(host, buf, cnt);
  2084. }
  2085. }
  2086. static void dw_mci_pull_data(struct dw_mci *host, void *buf, int cnt)
  2087. {
  2088. int len;
  2089. /* get remaining partial bytes */
  2090. len = dw_mci_pull_part_bytes(host, buf, cnt);
  2091. if (unlikely(len == cnt))
  2092. return;
  2093. buf += len;
  2094. cnt -= len;
  2095. /* get the rest of the data */
  2096. host->pull_data(host, buf, cnt);
  2097. }
  2098. static void dw_mci_read_data_pio(struct dw_mci *host, bool dto)
  2099. {
  2100. struct sg_mapping_iter *sg_miter = &host->sg_miter;
  2101. void *buf;
  2102. unsigned int offset;
  2103. struct mmc_data *data = host->data;
  2104. int shift = host->data_shift;
  2105. u32 status;
  2106. unsigned int len;
  2107. unsigned int remain, fcnt;
  2108. do {
  2109. if (!sg_miter_next(sg_miter))
  2110. goto done;
  2111. host->sg = sg_miter->piter.sg;
  2112. buf = sg_miter->addr;
  2113. remain = sg_miter->length;
  2114. offset = 0;
  2115. do {
  2116. fcnt = (SDMMC_GET_FCNT(mci_readl(host, STATUS))
  2117. << shift) + host->part_buf_count;
  2118. len = min(remain, fcnt);
  2119. if (!len)
  2120. break;
  2121. dw_mci_pull_data(host, (void *)(buf + offset), len);
  2122. data->bytes_xfered += len;
  2123. offset += len;
  2124. remain -= len;
  2125. } while (remain);
  2126. sg_miter->consumed = offset;
  2127. status = mci_readl(host, MINTSTS);
  2128. mci_writel(host, RINTSTS, SDMMC_INT_RXDR);
  2129. /* if the RXDR is ready read again */
  2130. } while ((status & SDMMC_INT_RXDR) ||
  2131. (dto && SDMMC_GET_FCNT(mci_readl(host, STATUS))));
  2132. if (!remain) {
  2133. if (!sg_miter_next(sg_miter))
  2134. goto done;
  2135. sg_miter->consumed = 0;
  2136. }
  2137. sg_miter_stop(sg_miter);
  2138. return;
  2139. done:
  2140. sg_miter_stop(sg_miter);
  2141. host->sg = NULL;
  2142. smp_wmb(); /* drain writebuffer */
  2143. set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
  2144. }
  2145. static void dw_mci_write_data_pio(struct dw_mci *host)
  2146. {
  2147. struct sg_mapping_iter *sg_miter = &host->sg_miter;
  2148. void *buf;
  2149. unsigned int offset;
  2150. struct mmc_data *data = host->data;
  2151. int shift = host->data_shift;
  2152. u32 status;
  2153. unsigned int len;
  2154. unsigned int fifo_depth = host->fifo_depth;
  2155. unsigned int remain, fcnt;
  2156. do {
  2157. if (!sg_miter_next(sg_miter))
  2158. goto done;
  2159. host->sg = sg_miter->piter.sg;
  2160. buf = sg_miter->addr;
  2161. remain = sg_miter->length;
  2162. offset = 0;
  2163. do {
  2164. fcnt = ((fifo_depth -
  2165. SDMMC_GET_FCNT(mci_readl(host, STATUS)))
  2166. << shift) - host->part_buf_count;
  2167. len = min(remain, fcnt);
  2168. if (!len)
  2169. break;
  2170. host->push_data(host, (void *)(buf + offset), len);
  2171. data->bytes_xfered += len;
  2172. offset += len;
  2173. remain -= len;
  2174. } while (remain);
  2175. sg_miter->consumed = offset;
  2176. status = mci_readl(host, MINTSTS);
  2177. mci_writel(host, RINTSTS, SDMMC_INT_TXDR);
  2178. } while (status & SDMMC_INT_TXDR); /* if TXDR write again */
  2179. if (!remain) {
  2180. if (!sg_miter_next(sg_miter))
  2181. goto done;
  2182. sg_miter->consumed = 0;
  2183. }
  2184. sg_miter_stop(sg_miter);
  2185. return;
  2186. done:
  2187. sg_miter_stop(sg_miter);
  2188. host->sg = NULL;
  2189. smp_wmb(); /* drain writebuffer */
  2190. set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
  2191. }
  2192. static void dw_mci_cmd_interrupt(struct dw_mci *host, u32 status)
  2193. {
  2194. del_timer(&host->cto_timer);
  2195. if (!host->cmd_status)
  2196. host->cmd_status = status;
  2197. smp_wmb(); /* drain writebuffer */
  2198. set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
  2199. tasklet_schedule(&host->tasklet);
  2200. }
  2201. static void dw_mci_handle_cd(struct dw_mci *host)
  2202. {
  2203. struct dw_mci_slot *slot = host->slot;
  2204. if (slot->mmc->ops->card_event)
  2205. slot->mmc->ops->card_event(slot->mmc);
  2206. mmc_detect_change(slot->mmc,
  2207. msecs_to_jiffies(host->pdata->detect_delay_ms));
  2208. }
  2209. static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
  2210. {
  2211. struct dw_mci *host = dev_id;
  2212. u32 pending;
  2213. struct dw_mci_slot *slot = host->slot;
  2214. unsigned long irqflags;
  2215. pending = mci_readl(host, MINTSTS); /* read-only mask reg */
  2216. if (pending) {
  2217. /* Check volt switch first, since it can look like an error */
  2218. if ((host->state == STATE_SENDING_CMD11) &&
  2219. (pending & SDMMC_INT_VOLT_SWITCH)) {
  2220. mci_writel(host, RINTSTS, SDMMC_INT_VOLT_SWITCH);
  2221. pending &= ~SDMMC_INT_VOLT_SWITCH;
  2222. /*
  2223. * Hold the lock; we know cmd11_timer can't be kicked
  2224. * off after the lock is released, so safe to delete.
  2225. */
  2226. spin_lock_irqsave(&host->irq_lock, irqflags);
  2227. dw_mci_cmd_interrupt(host, pending);
  2228. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  2229. del_timer(&host->cmd11_timer);
  2230. }
  2231. if (pending & DW_MCI_CMD_ERROR_FLAGS) {
  2232. spin_lock_irqsave(&host->irq_lock, irqflags);
  2233. del_timer(&host->cto_timer);
  2234. mci_writel(host, RINTSTS, DW_MCI_CMD_ERROR_FLAGS);
  2235. host->cmd_status = pending;
  2236. smp_wmb(); /* drain writebuffer */
  2237. set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
  2238. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  2239. }
  2240. if (pending & DW_MCI_DATA_ERROR_FLAGS) {
  2241. /* if there is an error report DATA_ERROR */
  2242. mci_writel(host, RINTSTS, DW_MCI_DATA_ERROR_FLAGS);
  2243. host->data_status = pending;
  2244. smp_wmb(); /* drain writebuffer */
  2245. set_bit(EVENT_DATA_ERROR, &host->pending_events);
  2246. tasklet_schedule(&host->tasklet);
  2247. }
  2248. if (pending & SDMMC_INT_DATA_OVER) {
  2249. spin_lock_irqsave(&host->irq_lock, irqflags);
  2250. del_timer(&host->dto_timer);
  2251. mci_writel(host, RINTSTS, SDMMC_INT_DATA_OVER);
  2252. if (!host->data_status)
  2253. host->data_status = pending;
  2254. smp_wmb(); /* drain writebuffer */
  2255. if (host->dir_status == DW_MCI_RECV_STATUS) {
  2256. if (host->sg != NULL)
  2257. dw_mci_read_data_pio(host, true);
  2258. }
  2259. set_bit(EVENT_DATA_COMPLETE, &host->pending_events);
  2260. tasklet_schedule(&host->tasklet);
  2261. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  2262. }
  2263. if (pending & SDMMC_INT_RXDR) {
  2264. mci_writel(host, RINTSTS, SDMMC_INT_RXDR);
  2265. if (host->dir_status == DW_MCI_RECV_STATUS && host->sg)
  2266. dw_mci_read_data_pio(host, false);
  2267. }
  2268. if (pending & SDMMC_INT_TXDR) {
  2269. mci_writel(host, RINTSTS, SDMMC_INT_TXDR);
  2270. if (host->dir_status == DW_MCI_SEND_STATUS && host->sg)
  2271. dw_mci_write_data_pio(host);
  2272. }
  2273. if (pending & SDMMC_INT_CMD_DONE) {
  2274. spin_lock_irqsave(&host->irq_lock, irqflags);
  2275. mci_writel(host, RINTSTS, SDMMC_INT_CMD_DONE);
  2276. dw_mci_cmd_interrupt(host, pending);
  2277. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  2278. }
  2279. if (pending & SDMMC_INT_CD) {
  2280. mci_writel(host, RINTSTS, SDMMC_INT_CD);
  2281. dw_mci_handle_cd(host);
  2282. }
  2283. if (pending & SDMMC_INT_SDIO(slot->sdio_id)) {
  2284. mci_writel(host, RINTSTS,
  2285. SDMMC_INT_SDIO(slot->sdio_id));
  2286. __dw_mci_enable_sdio_irq(slot, 0);
  2287. sdio_signal_irq(slot->mmc);
  2288. }
  2289. }
  2290. if (host->use_dma != TRANS_MODE_IDMAC)
  2291. return IRQ_HANDLED;
  2292. /* Handle IDMA interrupts */
  2293. if (host->dma_64bit_address == 1) {
  2294. pending = mci_readl(host, IDSTS64);
  2295. if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) {
  2296. mci_writel(host, IDSTS64, SDMMC_IDMAC_INT_TI |
  2297. SDMMC_IDMAC_INT_RI);
  2298. mci_writel(host, IDSTS64, SDMMC_IDMAC_INT_NI);
  2299. if (!test_bit(EVENT_DATA_ERROR, &host->pending_events))
  2300. host->dma_ops->complete((void *)host);
  2301. }
  2302. } else {
  2303. pending = mci_readl(host, IDSTS);
  2304. if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) {
  2305. mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI |
  2306. SDMMC_IDMAC_INT_RI);
  2307. mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI);
  2308. if (!test_bit(EVENT_DATA_ERROR, &host->pending_events))
  2309. host->dma_ops->complete((void *)host);
  2310. }
  2311. }
  2312. return IRQ_HANDLED;
  2313. }
  2314. static int dw_mci_init_slot_caps(struct dw_mci_slot *slot)
  2315. {
  2316. struct dw_mci *host = slot->host;
  2317. const struct dw_mci_drv_data *drv_data = host->drv_data;
  2318. struct mmc_host *mmc = slot->mmc;
  2319. int ctrl_id;
  2320. if (host->pdata->caps)
  2321. mmc->caps = host->pdata->caps;
  2322. /*
  2323. * Support MMC_CAP_ERASE by default.
  2324. * It needs to use trim/discard/erase commands.
  2325. */
  2326. mmc->caps |= MMC_CAP_ERASE;
  2327. if (host->pdata->pm_caps)
  2328. mmc->pm_caps = host->pdata->pm_caps;
  2329. if (host->dev->of_node) {
  2330. ctrl_id = of_alias_get_id(host->dev->of_node, "mshc");
  2331. if (ctrl_id < 0)
  2332. ctrl_id = 0;
  2333. } else {
  2334. ctrl_id = to_platform_device(host->dev)->id;
  2335. }
  2336. if (drv_data && drv_data->caps) {
  2337. if (ctrl_id >= drv_data->num_caps) {
  2338. dev_err(host->dev, "invalid controller id %d\n",
  2339. ctrl_id);
  2340. return -EINVAL;
  2341. }
  2342. mmc->caps |= drv_data->caps[ctrl_id];
  2343. }
  2344. if (host->pdata->caps2)
  2345. mmc->caps2 = host->pdata->caps2;
  2346. mmc->f_min = DW_MCI_FREQ_MIN;
  2347. if (!mmc->f_max)
  2348. mmc->f_max = DW_MCI_FREQ_MAX;
  2349. /* Process SDIO IRQs through the sdio_irq_work. */
  2350. if (mmc->caps & MMC_CAP_SDIO_IRQ)
  2351. mmc->caps2 |= MMC_CAP2_SDIO_IRQ_NOTHREAD;
  2352. return 0;
  2353. }
  2354. static int dw_mci_init_slot(struct dw_mci *host)
  2355. {
  2356. struct mmc_host *mmc;
  2357. struct dw_mci_slot *slot;
  2358. int ret;
  2359. mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), host->dev);
  2360. if (!mmc)
  2361. return -ENOMEM;
  2362. slot = mmc_priv(mmc);
  2363. slot->id = 0;
  2364. slot->sdio_id = host->sdio_id0 + slot->id;
  2365. slot->mmc = mmc;
  2366. slot->host = host;
  2367. host->slot = slot;
  2368. mmc->ops = &dw_mci_ops;
  2369. /*if there are external regulators, get them*/
  2370. ret = mmc_regulator_get_supply(mmc);
  2371. if (ret)
  2372. goto err_host_allocated;
  2373. if (!mmc->ocr_avail)
  2374. mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
  2375. ret = mmc_of_parse(mmc);
  2376. if (ret)
  2377. goto err_host_allocated;
  2378. ret = dw_mci_init_slot_caps(slot);
  2379. if (ret)
  2380. goto err_host_allocated;
  2381. /* Useful defaults if platform data is unset. */
  2382. if (host->use_dma == TRANS_MODE_IDMAC) {
  2383. mmc->max_segs = host->ring_size;
  2384. mmc->max_blk_size = 65535;
  2385. mmc->max_seg_size = 0x1000;
  2386. mmc->max_req_size = mmc->max_seg_size * host->ring_size;
  2387. mmc->max_blk_count = mmc->max_req_size / 512;
  2388. } else if (host->use_dma == TRANS_MODE_EDMAC) {
  2389. mmc->max_segs = 64;
  2390. mmc->max_blk_size = 65535;
  2391. mmc->max_blk_count = 65535;
  2392. mmc->max_req_size =
  2393. mmc->max_blk_size * mmc->max_blk_count;
  2394. mmc->max_seg_size = mmc->max_req_size;
  2395. } else {
  2396. /* TRANS_MODE_PIO */
  2397. mmc->max_segs = 64;
  2398. mmc->max_blk_size = 65535; /* BLKSIZ is 16 bits */
  2399. mmc->max_blk_count = 512;
  2400. mmc->max_req_size = mmc->max_blk_size *
  2401. mmc->max_blk_count;
  2402. mmc->max_seg_size = mmc->max_req_size;
  2403. }
  2404. dw_mci_get_cd(mmc);
  2405. ret = mmc_add_host(mmc);
  2406. if (ret)
  2407. goto err_host_allocated;
  2408. #if defined(CONFIG_DEBUG_FS)
  2409. dw_mci_init_debugfs(slot);
  2410. #endif
  2411. return 0;
  2412. err_host_allocated:
  2413. mmc_free_host(mmc);
  2414. return ret;
  2415. }
  2416. static void dw_mci_cleanup_slot(struct dw_mci_slot *slot)
  2417. {
  2418. /* Debugfs stuff is cleaned up by mmc core */
  2419. mmc_remove_host(slot->mmc);
  2420. slot->host->slot = NULL;
  2421. mmc_free_host(slot->mmc);
  2422. }
  2423. static void dw_mci_init_dma(struct dw_mci *host)
  2424. {
  2425. int addr_config;
  2426. struct device *dev = host->dev;
  2427. /*
  2428. * Check tansfer mode from HCON[17:16]
  2429. * Clear the ambiguous description of dw_mmc databook:
  2430. * 2b'00: No DMA Interface -> Actually means using Internal DMA block
  2431. * 2b'01: DesignWare DMA Interface -> Synopsys DW-DMA block
  2432. * 2b'10: Generic DMA Interface -> non-Synopsys generic DMA block
  2433. * 2b'11: Non DW DMA Interface -> pio only
  2434. * Compared to DesignWare DMA Interface, Generic DMA Interface has a
  2435. * simpler request/acknowledge handshake mechanism and both of them
  2436. * are regarded as external dma master for dw_mmc.
  2437. */
  2438. host->use_dma = SDMMC_GET_TRANS_MODE(mci_readl(host, HCON));
  2439. if (host->use_dma == DMA_INTERFACE_IDMA) {
  2440. host->use_dma = TRANS_MODE_IDMAC;
  2441. } else if (host->use_dma == DMA_INTERFACE_DWDMA ||
  2442. host->use_dma == DMA_INTERFACE_GDMA) {
  2443. host->use_dma = TRANS_MODE_EDMAC;
  2444. } else {
  2445. goto no_dma;
  2446. }
  2447. /* Determine which DMA interface to use */
  2448. if (host->use_dma == TRANS_MODE_IDMAC) {
  2449. /*
  2450. * Check ADDR_CONFIG bit in HCON to find
  2451. * IDMAC address bus width
  2452. */
  2453. addr_config = SDMMC_GET_ADDR_CONFIG(mci_readl(host, HCON));
  2454. if (addr_config == 1) {
  2455. /* host supports IDMAC in 64-bit address mode */
  2456. host->dma_64bit_address = 1;
  2457. dev_info(host->dev,
  2458. "IDMAC supports 64-bit address mode.\n");
  2459. if (!dma_set_mask(host->dev, DMA_BIT_MASK(64)))
  2460. dma_set_coherent_mask(host->dev,
  2461. DMA_BIT_MASK(64));
  2462. } else {
  2463. /* host supports IDMAC in 32-bit address mode */
  2464. host->dma_64bit_address = 0;
  2465. dev_info(host->dev,
  2466. "IDMAC supports 32-bit address mode.\n");
  2467. }
  2468. /* Alloc memory for sg translation */
  2469. host->sg_cpu = dmam_alloc_coherent(host->dev,
  2470. DESC_RING_BUF_SZ,
  2471. &host->sg_dma, GFP_KERNEL);
  2472. if (!host->sg_cpu) {
  2473. dev_err(host->dev,
  2474. "%s: could not alloc DMA memory\n",
  2475. __func__);
  2476. goto no_dma;
  2477. }
  2478. host->dma_ops = &dw_mci_idmac_ops;
  2479. dev_info(host->dev, "Using internal DMA controller.\n");
  2480. } else {
  2481. /* TRANS_MODE_EDMAC: check dma bindings again */
  2482. if ((device_property_read_string_array(dev, "dma-names",
  2483. NULL, 0) < 0) ||
  2484. !device_property_present(dev, "dmas")) {
  2485. goto no_dma;
  2486. }
  2487. host->dma_ops = &dw_mci_edmac_ops;
  2488. dev_info(host->dev, "Using external DMA controller.\n");
  2489. }
  2490. if (host->dma_ops->init && host->dma_ops->start &&
  2491. host->dma_ops->stop && host->dma_ops->cleanup) {
  2492. if (host->dma_ops->init(host)) {
  2493. dev_err(host->dev, "%s: Unable to initialize DMA Controller.\n",
  2494. __func__);
  2495. goto no_dma;
  2496. }
  2497. } else {
  2498. dev_err(host->dev, "DMA initialization not found.\n");
  2499. goto no_dma;
  2500. }
  2501. return;
  2502. no_dma:
  2503. dev_info(host->dev, "Using PIO mode.\n");
  2504. host->use_dma = TRANS_MODE_PIO;
  2505. }
  2506. static void dw_mci_cmd11_timer(struct timer_list *t)
  2507. {
  2508. struct dw_mci *host = from_timer(host, t, cmd11_timer);
  2509. if (host->state != STATE_SENDING_CMD11) {
  2510. dev_warn(host->dev, "Unexpected CMD11 timeout\n");
  2511. return;
  2512. }
  2513. host->cmd_status = SDMMC_INT_RTO;
  2514. set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
  2515. tasklet_schedule(&host->tasklet);
  2516. }
  2517. static void dw_mci_cto_timer(struct timer_list *t)
  2518. {
  2519. struct dw_mci *host = from_timer(host, t, cto_timer);
  2520. unsigned long irqflags;
  2521. u32 pending;
  2522. spin_lock_irqsave(&host->irq_lock, irqflags);
  2523. /*
  2524. * If somehow we have very bad interrupt latency it's remotely possible
  2525. * that the timer could fire while the interrupt is still pending or
  2526. * while the interrupt is midway through running. Let's be paranoid
  2527. * and detect those two cases. Note that this is paranoia is somewhat
  2528. * justified because in this function we don't actually cancel the
  2529. * pending command in the controller--we just assume it will never come.
  2530. */
  2531. pending = mci_readl(host, MINTSTS); /* read-only mask reg */
  2532. if (pending & (DW_MCI_CMD_ERROR_FLAGS | SDMMC_INT_CMD_DONE)) {
  2533. /* The interrupt should fire; no need to act but we can warn */
  2534. dev_warn(host->dev, "Unexpected interrupt latency\n");
  2535. goto exit;
  2536. }
  2537. if (test_bit(EVENT_CMD_COMPLETE, &host->pending_events)) {
  2538. /* Presumably interrupt handler couldn't delete the timer */
  2539. dev_warn(host->dev, "CTO timeout when already completed\n");
  2540. goto exit;
  2541. }
  2542. /*
  2543. * Continued paranoia to make sure we're in the state we expect.
  2544. * This paranoia isn't really justified but it seems good to be safe.
  2545. */
  2546. switch (host->state) {
  2547. case STATE_SENDING_CMD11:
  2548. case STATE_SENDING_CMD:
  2549. case STATE_SENDING_STOP:
  2550. /*
  2551. * If CMD_DONE interrupt does NOT come in sending command
  2552. * state, we should notify the driver to terminate current
  2553. * transfer and report a command timeout to the core.
  2554. */
  2555. host->cmd_status = SDMMC_INT_RTO;
  2556. set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
  2557. tasklet_schedule(&host->tasklet);
  2558. break;
  2559. default:
  2560. dev_warn(host->dev, "Unexpected command timeout, state %d\n",
  2561. host->state);
  2562. break;
  2563. }
  2564. exit:
  2565. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  2566. }
  2567. static void dw_mci_dto_timer(struct timer_list *t)
  2568. {
  2569. struct dw_mci *host = from_timer(host, t, dto_timer);
  2570. unsigned long irqflags;
  2571. u32 pending;
  2572. spin_lock_irqsave(&host->irq_lock, irqflags);
  2573. /*
  2574. * The DTO timer is much longer than the CTO timer, so it's even less
  2575. * likely that we'll these cases, but it pays to be paranoid.
  2576. */
  2577. pending = mci_readl(host, MINTSTS); /* read-only mask reg */
  2578. if (pending & SDMMC_INT_DATA_OVER) {
  2579. /* The interrupt should fire; no need to act but we can warn */
  2580. dev_warn(host->dev, "Unexpected data interrupt latency\n");
  2581. goto exit;
  2582. }
  2583. if (test_bit(EVENT_DATA_COMPLETE, &host->pending_events)) {
  2584. /* Presumably interrupt handler couldn't delete the timer */
  2585. dev_warn(host->dev, "DTO timeout when already completed\n");
  2586. goto exit;
  2587. }
  2588. /*
  2589. * Continued paranoia to make sure we're in the state we expect.
  2590. * This paranoia isn't really justified but it seems good to be safe.
  2591. */
  2592. switch (host->state) {
  2593. case STATE_SENDING_DATA:
  2594. case STATE_DATA_BUSY:
  2595. /*
  2596. * If DTO interrupt does NOT come in sending data state,
  2597. * we should notify the driver to terminate current transfer
  2598. * and report a data timeout to the core.
  2599. */
  2600. host->data_status = SDMMC_INT_DRTO;
  2601. set_bit(EVENT_DATA_ERROR, &host->pending_events);
  2602. set_bit(EVENT_DATA_COMPLETE, &host->pending_events);
  2603. tasklet_schedule(&host->tasklet);
  2604. break;
  2605. default:
  2606. dev_warn(host->dev, "Unexpected data timeout, state %d\n",
  2607. host->state);
  2608. break;
  2609. }
  2610. exit:
  2611. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  2612. }
  2613. #ifdef CONFIG_OF
  2614. static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
  2615. {
  2616. struct dw_mci_board *pdata;
  2617. struct device *dev = host->dev;
  2618. const struct dw_mci_drv_data *drv_data = host->drv_data;
  2619. int ret;
  2620. u32 clock_frequency;
  2621. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  2622. if (!pdata)
  2623. return ERR_PTR(-ENOMEM);
  2624. /* find reset controller when exist */
  2625. pdata->rstc = devm_reset_control_get_optional_exclusive(dev, "reset");
  2626. if (IS_ERR(pdata->rstc)) {
  2627. if (PTR_ERR(pdata->rstc) == -EPROBE_DEFER)
  2628. return ERR_PTR(-EPROBE_DEFER);
  2629. }
  2630. if (device_property_read_u32(dev, "fifo-depth", &pdata->fifo_depth))
  2631. dev_info(dev,
  2632. "fifo-depth property not found, using value of FIFOTH register as default\n");
  2633. device_property_read_u32(dev, "card-detect-delay",
  2634. &pdata->detect_delay_ms);
  2635. device_property_read_u32(dev, "data-addr", &host->data_addr_override);
  2636. if (device_property_present(dev, "fifo-watermark-aligned"))
  2637. host->wm_aligned = true;
  2638. if (!device_property_read_u32(dev, "clock-frequency", &clock_frequency))
  2639. pdata->bus_hz = clock_frequency;
  2640. if (drv_data && drv_data->parse_dt) {
  2641. ret = drv_data->parse_dt(host);
  2642. if (ret)
  2643. return ERR_PTR(ret);
  2644. }
  2645. return pdata;
  2646. }
  2647. #else /* CONFIG_OF */
  2648. static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
  2649. {
  2650. return ERR_PTR(-EINVAL);
  2651. }
  2652. #endif /* CONFIG_OF */
  2653. static void dw_mci_enable_cd(struct dw_mci *host)
  2654. {
  2655. unsigned long irqflags;
  2656. u32 temp;
  2657. /*
  2658. * No need for CD if all slots have a non-error GPIO
  2659. * as well as broken card detection is found.
  2660. */
  2661. if (host->slot->mmc->caps & MMC_CAP_NEEDS_POLL)
  2662. return;
  2663. if (mmc_gpio_get_cd(host->slot->mmc) < 0) {
  2664. spin_lock_irqsave(&host->irq_lock, irqflags);
  2665. temp = mci_readl(host, INTMASK);
  2666. temp |= SDMMC_INT_CD;
  2667. mci_writel(host, INTMASK, temp);
  2668. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  2669. }
  2670. }
  2671. int dw_mci_probe(struct dw_mci *host)
  2672. {
  2673. const struct dw_mci_drv_data *drv_data = host->drv_data;
  2674. int width, i, ret = 0;
  2675. u32 fifo_size;
  2676. if (!host->pdata) {
  2677. host->pdata = dw_mci_parse_dt(host);
  2678. if (PTR_ERR(host->pdata) == -EPROBE_DEFER) {
  2679. return -EPROBE_DEFER;
  2680. } else if (IS_ERR(host->pdata)) {
  2681. dev_err(host->dev, "platform data not available\n");
  2682. return -EINVAL;
  2683. }
  2684. }
  2685. host->biu_clk = devm_clk_get(host->dev, "biu");
  2686. if (IS_ERR(host->biu_clk)) {
  2687. dev_dbg(host->dev, "biu clock not available\n");
  2688. } else {
  2689. ret = clk_prepare_enable(host->biu_clk);
  2690. if (ret) {
  2691. dev_err(host->dev, "failed to enable biu clock\n");
  2692. return ret;
  2693. }
  2694. }
  2695. host->ciu_clk = devm_clk_get(host->dev, "ciu");
  2696. if (IS_ERR(host->ciu_clk)) {
  2697. dev_dbg(host->dev, "ciu clock not available\n");
  2698. host->bus_hz = host->pdata->bus_hz;
  2699. } else {
  2700. ret = clk_prepare_enable(host->ciu_clk);
  2701. if (ret) {
  2702. dev_err(host->dev, "failed to enable ciu clock\n");
  2703. goto err_clk_biu;
  2704. }
  2705. if (host->pdata->bus_hz) {
  2706. ret = clk_set_rate(host->ciu_clk, host->pdata->bus_hz);
  2707. if (ret)
  2708. dev_warn(host->dev,
  2709. "Unable to set bus rate to %uHz\n",
  2710. host->pdata->bus_hz);
  2711. }
  2712. host->bus_hz = clk_get_rate(host->ciu_clk);
  2713. }
  2714. if (!host->bus_hz) {
  2715. dev_err(host->dev,
  2716. "Platform data must supply bus speed\n");
  2717. ret = -ENODEV;
  2718. goto err_clk_ciu;
  2719. }
  2720. if (!IS_ERR(host->pdata->rstc)) {
  2721. reset_control_assert(host->pdata->rstc);
  2722. usleep_range(10, 50);
  2723. reset_control_deassert(host->pdata->rstc);
  2724. }
  2725. if (drv_data && drv_data->init) {
  2726. ret = drv_data->init(host);
  2727. if (ret) {
  2728. dev_err(host->dev,
  2729. "implementation specific init failed\n");
  2730. goto err_clk_ciu;
  2731. }
  2732. }
  2733. timer_setup(&host->cmd11_timer, dw_mci_cmd11_timer, 0);
  2734. timer_setup(&host->cto_timer, dw_mci_cto_timer, 0);
  2735. timer_setup(&host->dto_timer, dw_mci_dto_timer, 0);
  2736. spin_lock_init(&host->lock);
  2737. spin_lock_init(&host->irq_lock);
  2738. INIT_LIST_HEAD(&host->queue);
  2739. /*
  2740. * Get the host data width - this assumes that HCON has been set with
  2741. * the correct values.
  2742. */
  2743. i = SDMMC_GET_HDATA_WIDTH(mci_readl(host, HCON));
  2744. if (!i) {
  2745. host->push_data = dw_mci_push_data16;
  2746. host->pull_data = dw_mci_pull_data16;
  2747. width = 16;
  2748. host->data_shift = 1;
  2749. } else if (i == 2) {
  2750. host->push_data = dw_mci_push_data64;
  2751. host->pull_data = dw_mci_pull_data64;
  2752. width = 64;
  2753. host->data_shift = 3;
  2754. } else {
  2755. /* Check for a reserved value, and warn if it is */
  2756. WARN((i != 1),
  2757. "HCON reports a reserved host data width!\n"
  2758. "Defaulting to 32-bit access.\n");
  2759. host->push_data = dw_mci_push_data32;
  2760. host->pull_data = dw_mci_pull_data32;
  2761. width = 32;
  2762. host->data_shift = 2;
  2763. }
  2764. /* Reset all blocks */
  2765. if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_ALL_RESET_FLAGS)) {
  2766. ret = -ENODEV;
  2767. goto err_clk_ciu;
  2768. }
  2769. host->dma_ops = host->pdata->dma_ops;
  2770. dw_mci_init_dma(host);
  2771. /* Clear the interrupts for the host controller */
  2772. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  2773. mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
  2774. /* Put in max timeout */
  2775. mci_writel(host, TMOUT, 0xFFFFFFFF);
  2776. /*
  2777. * FIFO threshold settings RxMark = fifo_size / 2 - 1,
  2778. * Tx Mark = fifo_size / 2 DMA Size = 8
  2779. */
  2780. if (!host->pdata->fifo_depth) {
  2781. /*
  2782. * Power-on value of RX_WMark is FIFO_DEPTH-1, but this may
  2783. * have been overwritten by the bootloader, just like we're
  2784. * about to do, so if you know the value for your hardware, you
  2785. * should put it in the platform data.
  2786. */
  2787. fifo_size = mci_readl(host, FIFOTH);
  2788. fifo_size = 1 + ((fifo_size >> 16) & 0xfff);
  2789. } else {
  2790. fifo_size = host->pdata->fifo_depth;
  2791. }
  2792. host->fifo_depth = fifo_size;
  2793. host->fifoth_val =
  2794. SDMMC_SET_FIFOTH(0x2, fifo_size / 2 - 1, fifo_size / 2);
  2795. mci_writel(host, FIFOTH, host->fifoth_val);
  2796. /* disable clock to CIU */
  2797. mci_writel(host, CLKENA, 0);
  2798. mci_writel(host, CLKSRC, 0);
  2799. /*
  2800. * In 2.40a spec, Data offset is changed.
  2801. * Need to check the version-id and set data-offset for DATA register.
  2802. */
  2803. host->verid = SDMMC_GET_VERID(mci_readl(host, VERID));
  2804. dev_info(host->dev, "Version ID is %04x\n", host->verid);
  2805. if (host->data_addr_override)
  2806. host->fifo_reg = host->regs + host->data_addr_override;
  2807. else if (host->verid < DW_MMC_240A)
  2808. host->fifo_reg = host->regs + DATA_OFFSET;
  2809. else
  2810. host->fifo_reg = host->regs + DATA_240A_OFFSET;
  2811. tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host);
  2812. ret = devm_request_irq(host->dev, host->irq, dw_mci_interrupt,
  2813. host->irq_flags, "dw-mci", host);
  2814. if (ret)
  2815. goto err_dmaunmap;
  2816. /*
  2817. * Enable interrupts for command done, data over, data empty,
  2818. * receive ready and error such as transmit, receive timeout, crc error
  2819. */
  2820. mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
  2821. SDMMC_INT_TXDR | SDMMC_INT_RXDR |
  2822. DW_MCI_ERROR_FLAGS);
  2823. /* Enable mci interrupt */
  2824. mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE);
  2825. dev_info(host->dev,
  2826. "DW MMC controller at irq %d,%d bit host data width,%u deep fifo\n",
  2827. host->irq, width, fifo_size);
  2828. /* We need at least one slot to succeed */
  2829. ret = dw_mci_init_slot(host);
  2830. if (ret) {
  2831. dev_dbg(host->dev, "slot %d init failed\n", i);
  2832. goto err_dmaunmap;
  2833. }
  2834. /* Now that slots are all setup, we can enable card detect */
  2835. dw_mci_enable_cd(host);
  2836. return 0;
  2837. err_dmaunmap:
  2838. if (host->use_dma && host->dma_ops->exit)
  2839. host->dma_ops->exit(host);
  2840. if (!IS_ERR(host->pdata->rstc))
  2841. reset_control_assert(host->pdata->rstc);
  2842. err_clk_ciu:
  2843. clk_disable_unprepare(host->ciu_clk);
  2844. err_clk_biu:
  2845. clk_disable_unprepare(host->biu_clk);
  2846. return ret;
  2847. }
  2848. EXPORT_SYMBOL(dw_mci_probe);
  2849. void dw_mci_remove(struct dw_mci *host)
  2850. {
  2851. dev_dbg(host->dev, "remove slot\n");
  2852. if (host->slot)
  2853. dw_mci_cleanup_slot(host->slot);
  2854. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  2855. mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
  2856. /* disable clock to CIU */
  2857. mci_writel(host, CLKENA, 0);
  2858. mci_writel(host, CLKSRC, 0);
  2859. if (host->use_dma && host->dma_ops->exit)
  2860. host->dma_ops->exit(host);
  2861. if (!IS_ERR(host->pdata->rstc))
  2862. reset_control_assert(host->pdata->rstc);
  2863. clk_disable_unprepare(host->ciu_clk);
  2864. clk_disable_unprepare(host->biu_clk);
  2865. }
  2866. EXPORT_SYMBOL(dw_mci_remove);
  2867. #ifdef CONFIG_PM
  2868. int dw_mci_runtime_suspend(struct device *dev)
  2869. {
  2870. struct dw_mci *host = dev_get_drvdata(dev);
  2871. if (host->use_dma && host->dma_ops->exit)
  2872. host->dma_ops->exit(host);
  2873. clk_disable_unprepare(host->ciu_clk);
  2874. if (host->slot &&
  2875. (mmc_can_gpio_cd(host->slot->mmc) ||
  2876. !mmc_card_is_removable(host->slot->mmc)))
  2877. clk_disable_unprepare(host->biu_clk);
  2878. return 0;
  2879. }
  2880. EXPORT_SYMBOL(dw_mci_runtime_suspend);
  2881. int dw_mci_runtime_resume(struct device *dev)
  2882. {
  2883. int ret = 0;
  2884. struct dw_mci *host = dev_get_drvdata(dev);
  2885. if (host->slot &&
  2886. (mmc_can_gpio_cd(host->slot->mmc) ||
  2887. !mmc_card_is_removable(host->slot->mmc))) {
  2888. ret = clk_prepare_enable(host->biu_clk);
  2889. if (ret)
  2890. return ret;
  2891. }
  2892. ret = clk_prepare_enable(host->ciu_clk);
  2893. if (ret)
  2894. goto err;
  2895. if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_ALL_RESET_FLAGS)) {
  2896. clk_disable_unprepare(host->ciu_clk);
  2897. ret = -ENODEV;
  2898. goto err;
  2899. }
  2900. if (host->use_dma && host->dma_ops->init)
  2901. host->dma_ops->init(host);
  2902. /*
  2903. * Restore the initial value at FIFOTH register
  2904. * And Invalidate the prev_blksz with zero
  2905. */
  2906. mci_writel(host, FIFOTH, host->fifoth_val);
  2907. host->prev_blksz = 0;
  2908. /* Put in max timeout */
  2909. mci_writel(host, TMOUT, 0xFFFFFFFF);
  2910. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  2911. mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
  2912. SDMMC_INT_TXDR | SDMMC_INT_RXDR |
  2913. DW_MCI_ERROR_FLAGS);
  2914. mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE);
  2915. if (host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)
  2916. dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios);
  2917. /* Force setup bus to guarantee available clock output */
  2918. dw_mci_setup_bus(host->slot, true);
  2919. /* Now that slots are all setup, we can enable card detect */
  2920. dw_mci_enable_cd(host);
  2921. return 0;
  2922. err:
  2923. if (host->slot &&
  2924. (mmc_can_gpio_cd(host->slot->mmc) ||
  2925. !mmc_card_is_removable(host->slot->mmc)))
  2926. clk_disable_unprepare(host->biu_clk);
  2927. return ret;
  2928. }
  2929. EXPORT_SYMBOL(dw_mci_runtime_resume);
  2930. #endif /* CONFIG_PM */
  2931. static int __init dw_mci_init(void)
  2932. {
  2933. pr_info("Synopsys Designware Multimedia Card Interface Driver\n");
  2934. return 0;
  2935. }
  2936. static void __exit dw_mci_exit(void)
  2937. {
  2938. }
  2939. module_init(dw_mci_init);
  2940. module_exit(dw_mci_exit);
  2941. MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
  2942. MODULE_AUTHOR("NXP Semiconductor VietNam");
  2943. MODULE_AUTHOR("Imagination Technologies Ltd");
  2944. MODULE_LICENSE("GPL v2");