dw_mmc.c 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522
  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. goto disable;
  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. host->timing != MMC_TIMING_MMC_HS400)
  887. goto disable;
  888. blksz_depth = blksz / (1 << host->data_shift);
  889. fifo_depth = host->fifo_depth;
  890. if (blksz_depth > fifo_depth)
  891. goto disable;
  892. /*
  893. * If (blksz_depth) >= (fifo_depth >> 1), should be 'thld_size <= blksz'
  894. * If (blksz_depth) < (fifo_depth >> 1), should be thld_size = blksz
  895. * Currently just choose blksz.
  896. */
  897. thld_size = blksz;
  898. mci_writel(host, CDTHRCTL, SDMMC_SET_THLD(thld_size, enable));
  899. return;
  900. disable:
  901. mci_writel(host, CDTHRCTL, 0);
  902. }
  903. static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
  904. {
  905. unsigned long irqflags;
  906. int sg_len;
  907. u32 temp;
  908. host->using_dma = 0;
  909. /* If we don't have a channel, we can't do DMA */
  910. if (!host->use_dma)
  911. return -ENODEV;
  912. sg_len = dw_mci_pre_dma_transfer(host, data, COOKIE_MAPPED);
  913. if (sg_len < 0) {
  914. host->dma_ops->stop(host);
  915. return sg_len;
  916. }
  917. host->using_dma = 1;
  918. if (host->use_dma == TRANS_MODE_IDMAC)
  919. dev_vdbg(host->dev,
  920. "sd sg_cpu: %#lx sg_dma: %#lx sg_len: %d\n",
  921. (unsigned long)host->sg_cpu,
  922. (unsigned long)host->sg_dma,
  923. sg_len);
  924. /*
  925. * Decide the MSIZE and RX/TX Watermark.
  926. * If current block size is same with previous size,
  927. * no need to update fifoth.
  928. */
  929. if (host->prev_blksz != data->blksz)
  930. dw_mci_adjust_fifoth(host, data);
  931. /* Enable the DMA interface */
  932. temp = mci_readl(host, CTRL);
  933. temp |= SDMMC_CTRL_DMA_ENABLE;
  934. mci_writel(host, CTRL, temp);
  935. /* Disable RX/TX IRQs, let DMA handle it */
  936. spin_lock_irqsave(&host->irq_lock, irqflags);
  937. temp = mci_readl(host, INTMASK);
  938. temp &= ~(SDMMC_INT_RXDR | SDMMC_INT_TXDR);
  939. mci_writel(host, INTMASK, temp);
  940. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  941. if (host->dma_ops->start(host, sg_len)) {
  942. host->dma_ops->stop(host);
  943. /* We can't do DMA, try PIO for this one */
  944. dev_dbg(host->dev,
  945. "%s: fall back to PIO mode for current transfer\n",
  946. __func__);
  947. return -ENODEV;
  948. }
  949. return 0;
  950. }
  951. static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data)
  952. {
  953. unsigned long irqflags;
  954. int flags = SG_MITER_ATOMIC;
  955. u32 temp;
  956. data->error = -EINPROGRESS;
  957. WARN_ON(host->data);
  958. host->sg = NULL;
  959. host->data = data;
  960. if (data->flags & MMC_DATA_READ)
  961. host->dir_status = DW_MCI_RECV_STATUS;
  962. else
  963. host->dir_status = DW_MCI_SEND_STATUS;
  964. dw_mci_ctrl_thld(host, data);
  965. if (dw_mci_submit_data_dma(host, data)) {
  966. if (host->data->flags & MMC_DATA_READ)
  967. flags |= SG_MITER_TO_SG;
  968. else
  969. flags |= SG_MITER_FROM_SG;
  970. sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
  971. host->sg = data->sg;
  972. host->part_buf_start = 0;
  973. host->part_buf_count = 0;
  974. mci_writel(host, RINTSTS, SDMMC_INT_TXDR | SDMMC_INT_RXDR);
  975. spin_lock_irqsave(&host->irq_lock, irqflags);
  976. temp = mci_readl(host, INTMASK);
  977. temp |= SDMMC_INT_TXDR | SDMMC_INT_RXDR;
  978. mci_writel(host, INTMASK, temp);
  979. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  980. temp = mci_readl(host, CTRL);
  981. temp &= ~SDMMC_CTRL_DMA_ENABLE;
  982. mci_writel(host, CTRL, temp);
  983. /*
  984. * Use the initial fifoth_val for PIO mode. If wm_algined
  985. * is set, we set watermark same as data size.
  986. * If next issued data may be transfered by DMA mode,
  987. * prev_blksz should be invalidated.
  988. */
  989. if (host->wm_aligned)
  990. dw_mci_adjust_fifoth(host, data);
  991. else
  992. mci_writel(host, FIFOTH, host->fifoth_val);
  993. host->prev_blksz = 0;
  994. } else {
  995. /*
  996. * Keep the current block size.
  997. * It will be used to decide whether to update
  998. * fifoth register next time.
  999. */
  1000. host->prev_blksz = data->blksz;
  1001. }
  1002. }
  1003. static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
  1004. {
  1005. struct dw_mci *host = slot->host;
  1006. unsigned int clock = slot->clock;
  1007. u32 div;
  1008. u32 clk_en_a;
  1009. u32 sdmmc_cmd_bits = SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT;
  1010. /* We must continue to set bit 28 in CMD until the change is complete */
  1011. if (host->state == STATE_WAITING_CMD11_DONE)
  1012. sdmmc_cmd_bits |= SDMMC_CMD_VOLT_SWITCH;
  1013. slot->mmc->actual_clock = 0;
  1014. if (!clock) {
  1015. mci_writel(host, CLKENA, 0);
  1016. mci_send_cmd(slot, sdmmc_cmd_bits, 0);
  1017. } else if (clock != host->current_speed || force_clkinit) {
  1018. div = host->bus_hz / clock;
  1019. if (host->bus_hz % clock && host->bus_hz > clock)
  1020. /*
  1021. * move the + 1 after the divide to prevent
  1022. * over-clocking the card.
  1023. */
  1024. div += 1;
  1025. div = (host->bus_hz != clock) ? DIV_ROUND_UP(div, 2) : 0;
  1026. if ((clock != slot->__clk_old &&
  1027. !test_bit(DW_MMC_CARD_NEEDS_POLL, &slot->flags)) ||
  1028. force_clkinit) {
  1029. /* Silent the verbose log if calling from PM context */
  1030. if (!force_clkinit)
  1031. dev_info(&slot->mmc->class_dev,
  1032. "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ div = %d)\n",
  1033. slot->id, host->bus_hz, clock,
  1034. div ? ((host->bus_hz / div) >> 1) :
  1035. host->bus_hz, div);
  1036. /*
  1037. * If card is polling, display the message only
  1038. * one time at boot time.
  1039. */
  1040. if (slot->mmc->caps & MMC_CAP_NEEDS_POLL &&
  1041. slot->mmc->f_min == clock)
  1042. set_bit(DW_MMC_CARD_NEEDS_POLL, &slot->flags);
  1043. }
  1044. /* disable clock */
  1045. mci_writel(host, CLKENA, 0);
  1046. mci_writel(host, CLKSRC, 0);
  1047. /* inform CIU */
  1048. mci_send_cmd(slot, sdmmc_cmd_bits, 0);
  1049. /* set clock to desired speed */
  1050. mci_writel(host, CLKDIV, div);
  1051. /* inform CIU */
  1052. mci_send_cmd(slot, sdmmc_cmd_bits, 0);
  1053. /* enable clock; only low power if no SDIO */
  1054. clk_en_a = SDMMC_CLKEN_ENABLE << slot->id;
  1055. if (!test_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags))
  1056. clk_en_a |= SDMMC_CLKEN_LOW_PWR << slot->id;
  1057. mci_writel(host, CLKENA, clk_en_a);
  1058. /* inform CIU */
  1059. mci_send_cmd(slot, sdmmc_cmd_bits, 0);
  1060. /* keep the last clock value that was requested from core */
  1061. slot->__clk_old = clock;
  1062. slot->mmc->actual_clock = div ? ((host->bus_hz / div) >> 1) :
  1063. host->bus_hz;
  1064. }
  1065. host->current_speed = clock;
  1066. /* Set the current slot bus width */
  1067. mci_writel(host, CTYPE, (slot->ctype << slot->id));
  1068. }
  1069. static void __dw_mci_start_request(struct dw_mci *host,
  1070. struct dw_mci_slot *slot,
  1071. struct mmc_command *cmd)
  1072. {
  1073. struct mmc_request *mrq;
  1074. struct mmc_data *data;
  1075. u32 cmdflags;
  1076. mrq = slot->mrq;
  1077. host->mrq = mrq;
  1078. host->pending_events = 0;
  1079. host->completed_events = 0;
  1080. host->cmd_status = 0;
  1081. host->data_status = 0;
  1082. host->dir_status = 0;
  1083. data = cmd->data;
  1084. if (data) {
  1085. mci_writel(host, TMOUT, 0xFFFFFFFF);
  1086. mci_writel(host, BYTCNT, data->blksz*data->blocks);
  1087. mci_writel(host, BLKSIZ, data->blksz);
  1088. }
  1089. cmdflags = dw_mci_prepare_command(slot->mmc, cmd);
  1090. /* this is the first command, send the initialization clock */
  1091. if (test_and_clear_bit(DW_MMC_CARD_NEED_INIT, &slot->flags))
  1092. cmdflags |= SDMMC_CMD_INIT;
  1093. if (data) {
  1094. dw_mci_submit_data(host, data);
  1095. wmb(); /* drain writebuffer */
  1096. }
  1097. dw_mci_start_command(host, cmd, cmdflags);
  1098. if (cmd->opcode == SD_SWITCH_VOLTAGE) {
  1099. unsigned long irqflags;
  1100. /*
  1101. * Databook says to fail after 2ms w/ no response, but evidence
  1102. * shows that sometimes the cmd11 interrupt takes over 130ms.
  1103. * We'll set to 500ms, plus an extra jiffy just in case jiffies
  1104. * is just about to roll over.
  1105. *
  1106. * We do this whole thing under spinlock and only if the
  1107. * command hasn't already completed (indicating the the irq
  1108. * already ran so we don't want the timeout).
  1109. */
  1110. spin_lock_irqsave(&host->irq_lock, irqflags);
  1111. if (!test_bit(EVENT_CMD_COMPLETE, &host->pending_events))
  1112. mod_timer(&host->cmd11_timer,
  1113. jiffies + msecs_to_jiffies(500) + 1);
  1114. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  1115. }
  1116. host->stop_cmdr = dw_mci_prep_stop_abort(host, cmd);
  1117. }
  1118. static void dw_mci_start_request(struct dw_mci *host,
  1119. struct dw_mci_slot *slot)
  1120. {
  1121. struct mmc_request *mrq = slot->mrq;
  1122. struct mmc_command *cmd;
  1123. cmd = mrq->sbc ? mrq->sbc : mrq->cmd;
  1124. __dw_mci_start_request(host, slot, cmd);
  1125. }
  1126. /* must be called with host->lock held */
  1127. static void dw_mci_queue_request(struct dw_mci *host, struct dw_mci_slot *slot,
  1128. struct mmc_request *mrq)
  1129. {
  1130. dev_vdbg(&slot->mmc->class_dev, "queue request: state=%d\n",
  1131. host->state);
  1132. slot->mrq = mrq;
  1133. if (host->state == STATE_WAITING_CMD11_DONE) {
  1134. dev_warn(&slot->mmc->class_dev,
  1135. "Voltage change didn't complete\n");
  1136. /*
  1137. * this case isn't expected to happen, so we can
  1138. * either crash here or just try to continue on
  1139. * in the closest possible state
  1140. */
  1141. host->state = STATE_IDLE;
  1142. }
  1143. if (host->state == STATE_IDLE) {
  1144. host->state = STATE_SENDING_CMD;
  1145. dw_mci_start_request(host, slot);
  1146. } else {
  1147. list_add_tail(&slot->queue_node, &host->queue);
  1148. }
  1149. }
  1150. static void dw_mci_request(struct mmc_host *mmc, struct mmc_request *mrq)
  1151. {
  1152. struct dw_mci_slot *slot = mmc_priv(mmc);
  1153. struct dw_mci *host = slot->host;
  1154. WARN_ON(slot->mrq);
  1155. /*
  1156. * The check for card presence and queueing of the request must be
  1157. * atomic, otherwise the card could be removed in between and the
  1158. * request wouldn't fail until another card was inserted.
  1159. */
  1160. if (!dw_mci_get_cd(mmc)) {
  1161. mrq->cmd->error = -ENOMEDIUM;
  1162. mmc_request_done(mmc, mrq);
  1163. return;
  1164. }
  1165. spin_lock_bh(&host->lock);
  1166. dw_mci_queue_request(host, slot, mrq);
  1167. spin_unlock_bh(&host->lock);
  1168. }
  1169. static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  1170. {
  1171. struct dw_mci_slot *slot = mmc_priv(mmc);
  1172. const struct dw_mci_drv_data *drv_data = slot->host->drv_data;
  1173. u32 regs;
  1174. int ret;
  1175. switch (ios->bus_width) {
  1176. case MMC_BUS_WIDTH_4:
  1177. slot->ctype = SDMMC_CTYPE_4BIT;
  1178. break;
  1179. case MMC_BUS_WIDTH_8:
  1180. slot->ctype = SDMMC_CTYPE_8BIT;
  1181. break;
  1182. default:
  1183. /* set default 1 bit mode */
  1184. slot->ctype = SDMMC_CTYPE_1BIT;
  1185. }
  1186. regs = mci_readl(slot->host, UHS_REG);
  1187. /* DDR mode set */
  1188. if (ios->timing == MMC_TIMING_MMC_DDR52 ||
  1189. ios->timing == MMC_TIMING_UHS_DDR50 ||
  1190. ios->timing == MMC_TIMING_MMC_HS400)
  1191. regs |= ((0x1 << slot->id) << 16);
  1192. else
  1193. regs &= ~((0x1 << slot->id) << 16);
  1194. mci_writel(slot->host, UHS_REG, regs);
  1195. slot->host->timing = ios->timing;
  1196. /*
  1197. * Use mirror of ios->clock to prevent race with mmc
  1198. * core ios update when finding the minimum.
  1199. */
  1200. slot->clock = ios->clock;
  1201. if (drv_data && drv_data->set_ios)
  1202. drv_data->set_ios(slot->host, ios);
  1203. switch (ios->power_mode) {
  1204. case MMC_POWER_UP:
  1205. if (!IS_ERR(mmc->supply.vmmc)) {
  1206. ret = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,
  1207. ios->vdd);
  1208. if (ret) {
  1209. dev_err(slot->host->dev,
  1210. "failed to enable vmmc regulator\n");
  1211. /*return, if failed turn on vmmc*/
  1212. return;
  1213. }
  1214. }
  1215. set_bit(DW_MMC_CARD_NEED_INIT, &slot->flags);
  1216. regs = mci_readl(slot->host, PWREN);
  1217. regs |= (1 << slot->id);
  1218. mci_writel(slot->host, PWREN, regs);
  1219. break;
  1220. case MMC_POWER_ON:
  1221. if (!slot->host->vqmmc_enabled) {
  1222. if (!IS_ERR(mmc->supply.vqmmc)) {
  1223. ret = regulator_enable(mmc->supply.vqmmc);
  1224. if (ret < 0)
  1225. dev_err(slot->host->dev,
  1226. "failed to enable vqmmc\n");
  1227. else
  1228. slot->host->vqmmc_enabled = true;
  1229. } else {
  1230. /* Keep track so we don't reset again */
  1231. slot->host->vqmmc_enabled = true;
  1232. }
  1233. /* Reset our state machine after powering on */
  1234. dw_mci_ctrl_reset(slot->host,
  1235. SDMMC_CTRL_ALL_RESET_FLAGS);
  1236. }
  1237. /* Adjust clock / bus width after power is up */
  1238. dw_mci_setup_bus(slot, false);
  1239. break;
  1240. case MMC_POWER_OFF:
  1241. /* Turn clock off before power goes down */
  1242. dw_mci_setup_bus(slot, false);
  1243. if (!IS_ERR(mmc->supply.vmmc))
  1244. mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
  1245. if (!IS_ERR(mmc->supply.vqmmc) && slot->host->vqmmc_enabled)
  1246. regulator_disable(mmc->supply.vqmmc);
  1247. slot->host->vqmmc_enabled = false;
  1248. regs = mci_readl(slot->host, PWREN);
  1249. regs &= ~(1 << slot->id);
  1250. mci_writel(slot->host, PWREN, regs);
  1251. break;
  1252. default:
  1253. break;
  1254. }
  1255. if (slot->host->state == STATE_WAITING_CMD11_DONE && ios->clock != 0)
  1256. slot->host->state = STATE_IDLE;
  1257. }
  1258. static int dw_mci_card_busy(struct mmc_host *mmc)
  1259. {
  1260. struct dw_mci_slot *slot = mmc_priv(mmc);
  1261. u32 status;
  1262. /*
  1263. * Check the busy bit which is low when DAT[3:0]
  1264. * (the data lines) are 0000
  1265. */
  1266. status = mci_readl(slot->host, STATUS);
  1267. return !!(status & SDMMC_STATUS_BUSY);
  1268. }
  1269. static int dw_mci_switch_voltage(struct mmc_host *mmc, struct mmc_ios *ios)
  1270. {
  1271. struct dw_mci_slot *slot = mmc_priv(mmc);
  1272. struct dw_mci *host = slot->host;
  1273. const struct dw_mci_drv_data *drv_data = host->drv_data;
  1274. u32 uhs;
  1275. u32 v18 = SDMMC_UHS_18V << slot->id;
  1276. int ret;
  1277. if (drv_data && drv_data->switch_voltage)
  1278. return drv_data->switch_voltage(mmc, ios);
  1279. /*
  1280. * Program the voltage. Note that some instances of dw_mmc may use
  1281. * the UHS_REG for this. For other instances (like exynos) the UHS_REG
  1282. * does no harm but you need to set the regulator directly. Try both.
  1283. */
  1284. uhs = mci_readl(host, UHS_REG);
  1285. if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330)
  1286. uhs &= ~v18;
  1287. else
  1288. uhs |= v18;
  1289. if (!IS_ERR(mmc->supply.vqmmc)) {
  1290. ret = mmc_regulator_set_vqmmc(mmc, ios);
  1291. if (ret) {
  1292. dev_dbg(&mmc->class_dev,
  1293. "Regulator set error %d - %s V\n",
  1294. ret, uhs & v18 ? "1.8" : "3.3");
  1295. return ret;
  1296. }
  1297. }
  1298. mci_writel(host, UHS_REG, uhs);
  1299. return 0;
  1300. }
  1301. static int dw_mci_get_ro(struct mmc_host *mmc)
  1302. {
  1303. int read_only;
  1304. struct dw_mci_slot *slot = mmc_priv(mmc);
  1305. int gpio_ro = mmc_gpio_get_ro(mmc);
  1306. /* Use platform get_ro function, else try on board write protect */
  1307. if (gpio_ro >= 0)
  1308. read_only = gpio_ro;
  1309. else
  1310. read_only =
  1311. mci_readl(slot->host, WRTPRT) & (1 << slot->id) ? 1 : 0;
  1312. dev_dbg(&mmc->class_dev, "card is %s\n",
  1313. read_only ? "read-only" : "read-write");
  1314. return read_only;
  1315. }
  1316. static void dw_mci_hw_reset(struct mmc_host *mmc)
  1317. {
  1318. struct dw_mci_slot *slot = mmc_priv(mmc);
  1319. struct dw_mci *host = slot->host;
  1320. int reset;
  1321. if (host->use_dma == TRANS_MODE_IDMAC)
  1322. dw_mci_idmac_reset(host);
  1323. if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_DMA_RESET |
  1324. SDMMC_CTRL_FIFO_RESET))
  1325. return;
  1326. /*
  1327. * According to eMMC spec, card reset procedure:
  1328. * tRstW >= 1us: RST_n pulse width
  1329. * tRSCA >= 200us: RST_n to Command time
  1330. * tRSTH >= 1us: RST_n high period
  1331. */
  1332. reset = mci_readl(host, RST_N);
  1333. reset &= ~(SDMMC_RST_HWACTIVE << slot->id);
  1334. mci_writel(host, RST_N, reset);
  1335. usleep_range(1, 2);
  1336. reset |= SDMMC_RST_HWACTIVE << slot->id;
  1337. mci_writel(host, RST_N, reset);
  1338. usleep_range(200, 300);
  1339. }
  1340. static void dw_mci_init_card(struct mmc_host *mmc, struct mmc_card *card)
  1341. {
  1342. struct dw_mci_slot *slot = mmc_priv(mmc);
  1343. struct dw_mci *host = slot->host;
  1344. /*
  1345. * Low power mode will stop the card clock when idle. According to the
  1346. * description of the CLKENA register we should disable low power mode
  1347. * for SDIO cards if we need SDIO interrupts to work.
  1348. */
  1349. if (mmc->caps & MMC_CAP_SDIO_IRQ) {
  1350. const u32 clken_low_pwr = SDMMC_CLKEN_LOW_PWR << slot->id;
  1351. u32 clk_en_a_old;
  1352. u32 clk_en_a;
  1353. clk_en_a_old = mci_readl(host, CLKENA);
  1354. if (card->type == MMC_TYPE_SDIO ||
  1355. card->type == MMC_TYPE_SD_COMBO) {
  1356. set_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags);
  1357. clk_en_a = clk_en_a_old & ~clken_low_pwr;
  1358. } else {
  1359. clear_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags);
  1360. clk_en_a = clk_en_a_old | clken_low_pwr;
  1361. }
  1362. if (clk_en_a != clk_en_a_old) {
  1363. mci_writel(host, CLKENA, clk_en_a);
  1364. mci_send_cmd(slot, SDMMC_CMD_UPD_CLK |
  1365. SDMMC_CMD_PRV_DAT_WAIT, 0);
  1366. }
  1367. }
  1368. }
  1369. static void __dw_mci_enable_sdio_irq(struct dw_mci_slot *slot, int enb)
  1370. {
  1371. struct dw_mci *host = slot->host;
  1372. unsigned long irqflags;
  1373. u32 int_mask;
  1374. spin_lock_irqsave(&host->irq_lock, irqflags);
  1375. /* Enable/disable Slot Specific SDIO interrupt */
  1376. int_mask = mci_readl(host, INTMASK);
  1377. if (enb)
  1378. int_mask |= SDMMC_INT_SDIO(slot->sdio_id);
  1379. else
  1380. int_mask &= ~SDMMC_INT_SDIO(slot->sdio_id);
  1381. mci_writel(host, INTMASK, int_mask);
  1382. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  1383. }
  1384. static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb)
  1385. {
  1386. struct dw_mci_slot *slot = mmc_priv(mmc);
  1387. struct dw_mci *host = slot->host;
  1388. __dw_mci_enable_sdio_irq(slot, enb);
  1389. /* Avoid runtime suspending the device when SDIO IRQ is enabled */
  1390. if (enb)
  1391. pm_runtime_get_noresume(host->dev);
  1392. else
  1393. pm_runtime_put_noidle(host->dev);
  1394. }
  1395. static void dw_mci_ack_sdio_irq(struct mmc_host *mmc)
  1396. {
  1397. struct dw_mci_slot *slot = mmc_priv(mmc);
  1398. __dw_mci_enable_sdio_irq(slot, 1);
  1399. }
  1400. static int dw_mci_execute_tuning(struct mmc_host *mmc, u32 opcode)
  1401. {
  1402. struct dw_mci_slot *slot = mmc_priv(mmc);
  1403. struct dw_mci *host = slot->host;
  1404. const struct dw_mci_drv_data *drv_data = host->drv_data;
  1405. int err = -EINVAL;
  1406. if (drv_data && drv_data->execute_tuning)
  1407. err = drv_data->execute_tuning(slot, opcode);
  1408. return err;
  1409. }
  1410. static int dw_mci_prepare_hs400_tuning(struct mmc_host *mmc,
  1411. struct mmc_ios *ios)
  1412. {
  1413. struct dw_mci_slot *slot = mmc_priv(mmc);
  1414. struct dw_mci *host = slot->host;
  1415. const struct dw_mci_drv_data *drv_data = host->drv_data;
  1416. if (drv_data && drv_data->prepare_hs400_tuning)
  1417. return drv_data->prepare_hs400_tuning(host, ios);
  1418. return 0;
  1419. }
  1420. static bool dw_mci_reset(struct dw_mci *host)
  1421. {
  1422. u32 flags = SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET;
  1423. bool ret = false;
  1424. u32 status = 0;
  1425. /*
  1426. * Resetting generates a block interrupt, hence setting
  1427. * the scatter-gather pointer to NULL.
  1428. */
  1429. if (host->sg) {
  1430. sg_miter_stop(&host->sg_miter);
  1431. host->sg = NULL;
  1432. }
  1433. if (host->use_dma)
  1434. flags |= SDMMC_CTRL_DMA_RESET;
  1435. if (dw_mci_ctrl_reset(host, flags)) {
  1436. /*
  1437. * In all cases we clear the RAWINTS
  1438. * register to clear any interrupts.
  1439. */
  1440. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  1441. if (!host->use_dma) {
  1442. ret = true;
  1443. goto ciu_out;
  1444. }
  1445. /* Wait for dma_req to be cleared */
  1446. if (readl_poll_timeout_atomic(host->regs + SDMMC_STATUS,
  1447. status,
  1448. !(status & SDMMC_STATUS_DMA_REQ),
  1449. 1, 500 * USEC_PER_MSEC)) {
  1450. dev_err(host->dev,
  1451. "%s: Timeout waiting for dma_req to be cleared\n",
  1452. __func__);
  1453. goto ciu_out;
  1454. }
  1455. /* when using DMA next we reset the fifo again */
  1456. if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET))
  1457. goto ciu_out;
  1458. } else {
  1459. /* if the controller reset bit did clear, then set clock regs */
  1460. if (!(mci_readl(host, CTRL) & SDMMC_CTRL_RESET)) {
  1461. dev_err(host->dev,
  1462. "%s: fifo/dma reset bits didn't clear but ciu was reset, doing clock update\n",
  1463. __func__);
  1464. goto ciu_out;
  1465. }
  1466. }
  1467. if (host->use_dma == TRANS_MODE_IDMAC)
  1468. /* It is also required that we reinit idmac */
  1469. dw_mci_idmac_init(host);
  1470. ret = true;
  1471. ciu_out:
  1472. /* After a CTRL reset we need to have CIU set clock registers */
  1473. mci_send_cmd(host->slot, SDMMC_CMD_UPD_CLK, 0);
  1474. return ret;
  1475. }
  1476. static const struct mmc_host_ops dw_mci_ops = {
  1477. .request = dw_mci_request,
  1478. .pre_req = dw_mci_pre_req,
  1479. .post_req = dw_mci_post_req,
  1480. .set_ios = dw_mci_set_ios,
  1481. .get_ro = dw_mci_get_ro,
  1482. .get_cd = dw_mci_get_cd,
  1483. .hw_reset = dw_mci_hw_reset,
  1484. .enable_sdio_irq = dw_mci_enable_sdio_irq,
  1485. .ack_sdio_irq = dw_mci_ack_sdio_irq,
  1486. .execute_tuning = dw_mci_execute_tuning,
  1487. .card_busy = dw_mci_card_busy,
  1488. .start_signal_voltage_switch = dw_mci_switch_voltage,
  1489. .init_card = dw_mci_init_card,
  1490. .prepare_hs400_tuning = dw_mci_prepare_hs400_tuning,
  1491. };
  1492. static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)
  1493. __releases(&host->lock)
  1494. __acquires(&host->lock)
  1495. {
  1496. struct dw_mci_slot *slot;
  1497. struct mmc_host *prev_mmc = host->slot->mmc;
  1498. WARN_ON(host->cmd || host->data);
  1499. host->slot->mrq = NULL;
  1500. host->mrq = NULL;
  1501. if (!list_empty(&host->queue)) {
  1502. slot = list_entry(host->queue.next,
  1503. struct dw_mci_slot, queue_node);
  1504. list_del(&slot->queue_node);
  1505. dev_vdbg(host->dev, "list not empty: %s is next\n",
  1506. mmc_hostname(slot->mmc));
  1507. host->state = STATE_SENDING_CMD;
  1508. dw_mci_start_request(host, slot);
  1509. } else {
  1510. dev_vdbg(host->dev, "list empty\n");
  1511. if (host->state == STATE_SENDING_CMD11)
  1512. host->state = STATE_WAITING_CMD11_DONE;
  1513. else
  1514. host->state = STATE_IDLE;
  1515. }
  1516. spin_unlock(&host->lock);
  1517. mmc_request_done(prev_mmc, mrq);
  1518. spin_lock(&host->lock);
  1519. }
  1520. static int dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd)
  1521. {
  1522. u32 status = host->cmd_status;
  1523. host->cmd_status = 0;
  1524. /* Read the response from the card (up to 16 bytes) */
  1525. if (cmd->flags & MMC_RSP_PRESENT) {
  1526. if (cmd->flags & MMC_RSP_136) {
  1527. cmd->resp[3] = mci_readl(host, RESP0);
  1528. cmd->resp[2] = mci_readl(host, RESP1);
  1529. cmd->resp[1] = mci_readl(host, RESP2);
  1530. cmd->resp[0] = mci_readl(host, RESP3);
  1531. } else {
  1532. cmd->resp[0] = mci_readl(host, RESP0);
  1533. cmd->resp[1] = 0;
  1534. cmd->resp[2] = 0;
  1535. cmd->resp[3] = 0;
  1536. }
  1537. }
  1538. if (status & SDMMC_INT_RTO)
  1539. cmd->error = -ETIMEDOUT;
  1540. else if ((cmd->flags & MMC_RSP_CRC) && (status & SDMMC_INT_RCRC))
  1541. cmd->error = -EILSEQ;
  1542. else if (status & SDMMC_INT_RESP_ERR)
  1543. cmd->error = -EIO;
  1544. else
  1545. cmd->error = 0;
  1546. return cmd->error;
  1547. }
  1548. static int dw_mci_data_complete(struct dw_mci *host, struct mmc_data *data)
  1549. {
  1550. u32 status = host->data_status;
  1551. if (status & DW_MCI_DATA_ERROR_FLAGS) {
  1552. if (status & SDMMC_INT_DRTO) {
  1553. data->error = -ETIMEDOUT;
  1554. } else if (status & SDMMC_INT_DCRC) {
  1555. data->error = -EILSEQ;
  1556. } else if (status & SDMMC_INT_EBE) {
  1557. if (host->dir_status ==
  1558. DW_MCI_SEND_STATUS) {
  1559. /*
  1560. * No data CRC status was returned.
  1561. * The number of bytes transferred
  1562. * will be exaggerated in PIO mode.
  1563. */
  1564. data->bytes_xfered = 0;
  1565. data->error = -ETIMEDOUT;
  1566. } else if (host->dir_status ==
  1567. DW_MCI_RECV_STATUS) {
  1568. data->error = -EILSEQ;
  1569. }
  1570. } else {
  1571. /* SDMMC_INT_SBE is included */
  1572. data->error = -EILSEQ;
  1573. }
  1574. dev_dbg(host->dev, "data error, status 0x%08x\n", status);
  1575. /*
  1576. * After an error, there may be data lingering
  1577. * in the FIFO
  1578. */
  1579. dw_mci_reset(host);
  1580. } else {
  1581. data->bytes_xfered = data->blocks * data->blksz;
  1582. data->error = 0;
  1583. }
  1584. return data->error;
  1585. }
  1586. static void dw_mci_set_drto(struct dw_mci *host)
  1587. {
  1588. unsigned int drto_clks;
  1589. unsigned int drto_div;
  1590. unsigned int drto_ms;
  1591. unsigned long irqflags;
  1592. drto_clks = mci_readl(host, TMOUT) >> 8;
  1593. drto_div = (mci_readl(host, CLKDIV) & 0xff) * 2;
  1594. if (drto_div == 0)
  1595. drto_div = 1;
  1596. drto_ms = DIV_ROUND_UP_ULL((u64)MSEC_PER_SEC * drto_clks * drto_div,
  1597. host->bus_hz);
  1598. /* add a bit spare time */
  1599. drto_ms += 10;
  1600. spin_lock_irqsave(&host->irq_lock, irqflags);
  1601. if (!test_bit(EVENT_DATA_COMPLETE, &host->pending_events))
  1602. mod_timer(&host->dto_timer,
  1603. jiffies + msecs_to_jiffies(drto_ms));
  1604. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  1605. }
  1606. static bool dw_mci_clear_pending_cmd_complete(struct dw_mci *host)
  1607. {
  1608. if (!test_bit(EVENT_CMD_COMPLETE, &host->pending_events))
  1609. return false;
  1610. /*
  1611. * Really be certain that the timer has stopped. This is a bit of
  1612. * paranoia and could only really happen if we had really bad
  1613. * interrupt latency and the interrupt routine and timeout were
  1614. * running concurrently so that the del_timer() in the interrupt
  1615. * handler couldn't run.
  1616. */
  1617. WARN_ON(del_timer_sync(&host->cto_timer));
  1618. clear_bit(EVENT_CMD_COMPLETE, &host->pending_events);
  1619. return true;
  1620. }
  1621. static bool dw_mci_clear_pending_data_complete(struct dw_mci *host)
  1622. {
  1623. if (!test_bit(EVENT_DATA_COMPLETE, &host->pending_events))
  1624. return false;
  1625. /* Extra paranoia just like dw_mci_clear_pending_cmd_complete() */
  1626. WARN_ON(del_timer_sync(&host->dto_timer));
  1627. clear_bit(EVENT_DATA_COMPLETE, &host->pending_events);
  1628. return true;
  1629. }
  1630. static void dw_mci_tasklet_func(unsigned long priv)
  1631. {
  1632. struct dw_mci *host = (struct dw_mci *)priv;
  1633. struct mmc_data *data;
  1634. struct mmc_command *cmd;
  1635. struct mmc_request *mrq;
  1636. enum dw_mci_state state;
  1637. enum dw_mci_state prev_state;
  1638. unsigned int err;
  1639. spin_lock(&host->lock);
  1640. state = host->state;
  1641. data = host->data;
  1642. mrq = host->mrq;
  1643. do {
  1644. prev_state = state;
  1645. switch (state) {
  1646. case STATE_IDLE:
  1647. case STATE_WAITING_CMD11_DONE:
  1648. break;
  1649. case STATE_SENDING_CMD11:
  1650. case STATE_SENDING_CMD:
  1651. if (!dw_mci_clear_pending_cmd_complete(host))
  1652. break;
  1653. cmd = host->cmd;
  1654. host->cmd = NULL;
  1655. set_bit(EVENT_CMD_COMPLETE, &host->completed_events);
  1656. err = dw_mci_command_complete(host, cmd);
  1657. if (cmd == mrq->sbc && !err) {
  1658. __dw_mci_start_request(host, host->slot,
  1659. mrq->cmd);
  1660. goto unlock;
  1661. }
  1662. if (cmd->data && err) {
  1663. /*
  1664. * During UHS tuning sequence, sending the stop
  1665. * command after the response CRC error would
  1666. * throw the system into a confused state
  1667. * causing all future tuning phases to report
  1668. * failure.
  1669. *
  1670. * In such case controller will move into a data
  1671. * transfer state after a response error or
  1672. * response CRC error. Let's let that finish
  1673. * before trying to send a stop, so we'll go to
  1674. * STATE_SENDING_DATA.
  1675. *
  1676. * Although letting the data transfer take place
  1677. * will waste a bit of time (we already know
  1678. * the command was bad), it can't cause any
  1679. * errors since it's possible it would have
  1680. * taken place anyway if this tasklet got
  1681. * delayed. Allowing the transfer to take place
  1682. * avoids races and keeps things simple.
  1683. */
  1684. if ((err != -ETIMEDOUT) &&
  1685. (cmd->opcode == MMC_SEND_TUNING_BLOCK)) {
  1686. state = STATE_SENDING_DATA;
  1687. continue;
  1688. }
  1689. dw_mci_stop_dma(host);
  1690. send_stop_abort(host, data);
  1691. state = STATE_SENDING_STOP;
  1692. break;
  1693. }
  1694. if (!cmd->data || err) {
  1695. dw_mci_request_end(host, mrq);
  1696. goto unlock;
  1697. }
  1698. prev_state = state = STATE_SENDING_DATA;
  1699. /* fall through */
  1700. case STATE_SENDING_DATA:
  1701. /*
  1702. * We could get a data error and never a transfer
  1703. * complete so we'd better check for it here.
  1704. *
  1705. * Note that we don't really care if we also got a
  1706. * transfer complete; stopping the DMA and sending an
  1707. * abort won't hurt.
  1708. */
  1709. if (test_and_clear_bit(EVENT_DATA_ERROR,
  1710. &host->pending_events)) {
  1711. dw_mci_stop_dma(host);
  1712. if (!(host->data_status & (SDMMC_INT_DRTO |
  1713. SDMMC_INT_EBE)))
  1714. send_stop_abort(host, data);
  1715. state = STATE_DATA_ERROR;
  1716. break;
  1717. }
  1718. if (!test_and_clear_bit(EVENT_XFER_COMPLETE,
  1719. &host->pending_events)) {
  1720. /*
  1721. * If all data-related interrupts don't come
  1722. * within the given time in reading data state.
  1723. */
  1724. if (host->dir_status == DW_MCI_RECV_STATUS)
  1725. dw_mci_set_drto(host);
  1726. break;
  1727. }
  1728. set_bit(EVENT_XFER_COMPLETE, &host->completed_events);
  1729. /*
  1730. * Handle an EVENT_DATA_ERROR that might have shown up
  1731. * before the transfer completed. This might not have
  1732. * been caught by the check above because the interrupt
  1733. * could have gone off between the previous check and
  1734. * the check for transfer complete.
  1735. *
  1736. * Technically this ought not be needed assuming we
  1737. * get a DATA_COMPLETE eventually (we'll notice the
  1738. * error and end the request), but it shouldn't hurt.
  1739. *
  1740. * This has the advantage of sending the stop command.
  1741. */
  1742. if (test_and_clear_bit(EVENT_DATA_ERROR,
  1743. &host->pending_events)) {
  1744. dw_mci_stop_dma(host);
  1745. if (!(host->data_status & (SDMMC_INT_DRTO |
  1746. SDMMC_INT_EBE)))
  1747. send_stop_abort(host, data);
  1748. state = STATE_DATA_ERROR;
  1749. break;
  1750. }
  1751. prev_state = state = STATE_DATA_BUSY;
  1752. /* fall through */
  1753. case STATE_DATA_BUSY:
  1754. if (!dw_mci_clear_pending_data_complete(host)) {
  1755. /*
  1756. * If data error interrupt comes but data over
  1757. * interrupt doesn't come within the given time.
  1758. * in reading data state.
  1759. */
  1760. if (host->dir_status == DW_MCI_RECV_STATUS)
  1761. dw_mci_set_drto(host);
  1762. break;
  1763. }
  1764. host->data = NULL;
  1765. set_bit(EVENT_DATA_COMPLETE, &host->completed_events);
  1766. err = dw_mci_data_complete(host, data);
  1767. if (!err) {
  1768. if (!data->stop || mrq->sbc) {
  1769. if (mrq->sbc && data->stop)
  1770. data->stop->error = 0;
  1771. dw_mci_request_end(host, mrq);
  1772. goto unlock;
  1773. }
  1774. /* stop command for open-ended transfer*/
  1775. if (data->stop)
  1776. send_stop_abort(host, data);
  1777. } else {
  1778. /*
  1779. * If we don't have a command complete now we'll
  1780. * never get one since we just reset everything;
  1781. * better end the request.
  1782. *
  1783. * If we do have a command complete we'll fall
  1784. * through to the SENDING_STOP command and
  1785. * everything will be peachy keen.
  1786. */
  1787. if (!test_bit(EVENT_CMD_COMPLETE,
  1788. &host->pending_events)) {
  1789. host->cmd = NULL;
  1790. dw_mci_request_end(host, mrq);
  1791. goto unlock;
  1792. }
  1793. }
  1794. /*
  1795. * If err has non-zero,
  1796. * stop-abort command has been already issued.
  1797. */
  1798. prev_state = state = STATE_SENDING_STOP;
  1799. /* fall through */
  1800. case STATE_SENDING_STOP:
  1801. if (!dw_mci_clear_pending_cmd_complete(host))
  1802. break;
  1803. /* CMD error in data command */
  1804. if (mrq->cmd->error && mrq->data)
  1805. dw_mci_reset(host);
  1806. host->cmd = NULL;
  1807. host->data = NULL;
  1808. if (!mrq->sbc && mrq->stop)
  1809. dw_mci_command_complete(host, mrq->stop);
  1810. else
  1811. host->cmd_status = 0;
  1812. dw_mci_request_end(host, mrq);
  1813. goto unlock;
  1814. case STATE_DATA_ERROR:
  1815. if (!test_and_clear_bit(EVENT_XFER_COMPLETE,
  1816. &host->pending_events))
  1817. break;
  1818. state = STATE_DATA_BUSY;
  1819. break;
  1820. }
  1821. } while (state != prev_state);
  1822. host->state = state;
  1823. unlock:
  1824. spin_unlock(&host->lock);
  1825. }
  1826. /* push final bytes to part_buf, only use during push */
  1827. static void dw_mci_set_part_bytes(struct dw_mci *host, void *buf, int cnt)
  1828. {
  1829. memcpy((void *)&host->part_buf, buf, cnt);
  1830. host->part_buf_count = cnt;
  1831. }
  1832. /* append bytes to part_buf, only use during push */
  1833. static int dw_mci_push_part_bytes(struct dw_mci *host, void *buf, int cnt)
  1834. {
  1835. cnt = min(cnt, (1 << host->data_shift) - host->part_buf_count);
  1836. memcpy((void *)&host->part_buf + host->part_buf_count, buf, cnt);
  1837. host->part_buf_count += cnt;
  1838. return cnt;
  1839. }
  1840. /* pull first bytes from part_buf, only use during pull */
  1841. static int dw_mci_pull_part_bytes(struct dw_mci *host, void *buf, int cnt)
  1842. {
  1843. cnt = min_t(int, cnt, host->part_buf_count);
  1844. if (cnt) {
  1845. memcpy(buf, (void *)&host->part_buf + host->part_buf_start,
  1846. cnt);
  1847. host->part_buf_count -= cnt;
  1848. host->part_buf_start += cnt;
  1849. }
  1850. return cnt;
  1851. }
  1852. /* pull final bytes from the part_buf, assuming it's just been filled */
  1853. static void dw_mci_pull_final_bytes(struct dw_mci *host, void *buf, int cnt)
  1854. {
  1855. memcpy(buf, &host->part_buf, cnt);
  1856. host->part_buf_start = cnt;
  1857. host->part_buf_count = (1 << host->data_shift) - cnt;
  1858. }
  1859. static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
  1860. {
  1861. struct mmc_data *data = host->data;
  1862. int init_cnt = cnt;
  1863. /* try and push anything in the part_buf */
  1864. if (unlikely(host->part_buf_count)) {
  1865. int len = dw_mci_push_part_bytes(host, buf, cnt);
  1866. buf += len;
  1867. cnt -= len;
  1868. if (host->part_buf_count == 2) {
  1869. mci_fifo_writew(host->fifo_reg, host->part_buf16);
  1870. host->part_buf_count = 0;
  1871. }
  1872. }
  1873. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1874. if (unlikely((unsigned long)buf & 0x1)) {
  1875. while (cnt >= 2) {
  1876. u16 aligned_buf[64];
  1877. int len = min(cnt & -2, (int)sizeof(aligned_buf));
  1878. int items = len >> 1;
  1879. int i;
  1880. /* memcpy from input buffer into aligned buffer */
  1881. memcpy(aligned_buf, buf, len);
  1882. buf += len;
  1883. cnt -= len;
  1884. /* push data from aligned buffer into fifo */
  1885. for (i = 0; i < items; ++i)
  1886. mci_fifo_writew(host->fifo_reg, aligned_buf[i]);
  1887. }
  1888. } else
  1889. #endif
  1890. {
  1891. u16 *pdata = buf;
  1892. for (; cnt >= 2; cnt -= 2)
  1893. mci_fifo_writew(host->fifo_reg, *pdata++);
  1894. buf = pdata;
  1895. }
  1896. /* put anything remaining in the part_buf */
  1897. if (cnt) {
  1898. dw_mci_set_part_bytes(host, buf, cnt);
  1899. /* Push data if we have reached the expected data length */
  1900. if ((data->bytes_xfered + init_cnt) ==
  1901. (data->blksz * data->blocks))
  1902. mci_fifo_writew(host->fifo_reg, host->part_buf16);
  1903. }
  1904. }
  1905. static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
  1906. {
  1907. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1908. if (unlikely((unsigned long)buf & 0x1)) {
  1909. while (cnt >= 2) {
  1910. /* pull data from fifo into aligned buffer */
  1911. u16 aligned_buf[64];
  1912. int len = min(cnt & -2, (int)sizeof(aligned_buf));
  1913. int items = len >> 1;
  1914. int i;
  1915. for (i = 0; i < items; ++i)
  1916. aligned_buf[i] = mci_fifo_readw(host->fifo_reg);
  1917. /* memcpy from aligned buffer into output buffer */
  1918. memcpy(buf, aligned_buf, len);
  1919. buf += len;
  1920. cnt -= len;
  1921. }
  1922. } else
  1923. #endif
  1924. {
  1925. u16 *pdata = buf;
  1926. for (; cnt >= 2; cnt -= 2)
  1927. *pdata++ = mci_fifo_readw(host->fifo_reg);
  1928. buf = pdata;
  1929. }
  1930. if (cnt) {
  1931. host->part_buf16 = mci_fifo_readw(host->fifo_reg);
  1932. dw_mci_pull_final_bytes(host, buf, cnt);
  1933. }
  1934. }
  1935. static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
  1936. {
  1937. struct mmc_data *data = host->data;
  1938. int init_cnt = cnt;
  1939. /* try and push anything in the part_buf */
  1940. if (unlikely(host->part_buf_count)) {
  1941. int len = dw_mci_push_part_bytes(host, buf, cnt);
  1942. buf += len;
  1943. cnt -= len;
  1944. if (host->part_buf_count == 4) {
  1945. mci_fifo_writel(host->fifo_reg, host->part_buf32);
  1946. host->part_buf_count = 0;
  1947. }
  1948. }
  1949. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1950. if (unlikely((unsigned long)buf & 0x3)) {
  1951. while (cnt >= 4) {
  1952. u32 aligned_buf[32];
  1953. int len = min(cnt & -4, (int)sizeof(aligned_buf));
  1954. int items = len >> 2;
  1955. int i;
  1956. /* memcpy from input buffer into aligned buffer */
  1957. memcpy(aligned_buf, buf, len);
  1958. buf += len;
  1959. cnt -= len;
  1960. /* push data from aligned buffer into fifo */
  1961. for (i = 0; i < items; ++i)
  1962. mci_fifo_writel(host->fifo_reg, aligned_buf[i]);
  1963. }
  1964. } else
  1965. #endif
  1966. {
  1967. u32 *pdata = buf;
  1968. for (; cnt >= 4; cnt -= 4)
  1969. mci_fifo_writel(host->fifo_reg, *pdata++);
  1970. buf = pdata;
  1971. }
  1972. /* put anything remaining in the part_buf */
  1973. if (cnt) {
  1974. dw_mci_set_part_bytes(host, buf, cnt);
  1975. /* Push data if we have reached the expected data length */
  1976. if ((data->bytes_xfered + init_cnt) ==
  1977. (data->blksz * data->blocks))
  1978. mci_fifo_writel(host->fifo_reg, host->part_buf32);
  1979. }
  1980. }
  1981. static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
  1982. {
  1983. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1984. if (unlikely((unsigned long)buf & 0x3)) {
  1985. while (cnt >= 4) {
  1986. /* pull data from fifo into aligned buffer */
  1987. u32 aligned_buf[32];
  1988. int len = min(cnt & -4, (int)sizeof(aligned_buf));
  1989. int items = len >> 2;
  1990. int i;
  1991. for (i = 0; i < items; ++i)
  1992. aligned_buf[i] = mci_fifo_readl(host->fifo_reg);
  1993. /* memcpy from aligned buffer into output buffer */
  1994. memcpy(buf, aligned_buf, len);
  1995. buf += len;
  1996. cnt -= len;
  1997. }
  1998. } else
  1999. #endif
  2000. {
  2001. u32 *pdata = buf;
  2002. for (; cnt >= 4; cnt -= 4)
  2003. *pdata++ = mci_fifo_readl(host->fifo_reg);
  2004. buf = pdata;
  2005. }
  2006. if (cnt) {
  2007. host->part_buf32 = mci_fifo_readl(host->fifo_reg);
  2008. dw_mci_pull_final_bytes(host, buf, cnt);
  2009. }
  2010. }
  2011. static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
  2012. {
  2013. struct mmc_data *data = host->data;
  2014. int init_cnt = cnt;
  2015. /* try and push anything in the part_buf */
  2016. if (unlikely(host->part_buf_count)) {
  2017. int len = dw_mci_push_part_bytes(host, buf, cnt);
  2018. buf += len;
  2019. cnt -= len;
  2020. if (host->part_buf_count == 8) {
  2021. mci_fifo_writeq(host->fifo_reg, host->part_buf);
  2022. host->part_buf_count = 0;
  2023. }
  2024. }
  2025. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  2026. if (unlikely((unsigned long)buf & 0x7)) {
  2027. while (cnt >= 8) {
  2028. u64 aligned_buf[16];
  2029. int len = min(cnt & -8, (int)sizeof(aligned_buf));
  2030. int items = len >> 3;
  2031. int i;
  2032. /* memcpy from input buffer into aligned buffer */
  2033. memcpy(aligned_buf, buf, len);
  2034. buf += len;
  2035. cnt -= len;
  2036. /* push data from aligned buffer into fifo */
  2037. for (i = 0; i < items; ++i)
  2038. mci_fifo_writeq(host->fifo_reg, aligned_buf[i]);
  2039. }
  2040. } else
  2041. #endif
  2042. {
  2043. u64 *pdata = buf;
  2044. for (; cnt >= 8; cnt -= 8)
  2045. mci_fifo_writeq(host->fifo_reg, *pdata++);
  2046. buf = pdata;
  2047. }
  2048. /* put anything remaining in the part_buf */
  2049. if (cnt) {
  2050. dw_mci_set_part_bytes(host, buf, cnt);
  2051. /* Push data if we have reached the expected data length */
  2052. if ((data->bytes_xfered + init_cnt) ==
  2053. (data->blksz * data->blocks))
  2054. mci_fifo_writeq(host->fifo_reg, host->part_buf);
  2055. }
  2056. }
  2057. static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
  2058. {
  2059. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  2060. if (unlikely((unsigned long)buf & 0x7)) {
  2061. while (cnt >= 8) {
  2062. /* pull data from fifo into aligned buffer */
  2063. u64 aligned_buf[16];
  2064. int len = min(cnt & -8, (int)sizeof(aligned_buf));
  2065. int items = len >> 3;
  2066. int i;
  2067. for (i = 0; i < items; ++i)
  2068. aligned_buf[i] = mci_fifo_readq(host->fifo_reg);
  2069. /* memcpy from aligned buffer into output buffer */
  2070. memcpy(buf, aligned_buf, len);
  2071. buf += len;
  2072. cnt -= len;
  2073. }
  2074. } else
  2075. #endif
  2076. {
  2077. u64 *pdata = buf;
  2078. for (; cnt >= 8; cnt -= 8)
  2079. *pdata++ = mci_fifo_readq(host->fifo_reg);
  2080. buf = pdata;
  2081. }
  2082. if (cnt) {
  2083. host->part_buf = mci_fifo_readq(host->fifo_reg);
  2084. dw_mci_pull_final_bytes(host, buf, cnt);
  2085. }
  2086. }
  2087. static void dw_mci_pull_data(struct dw_mci *host, void *buf, int cnt)
  2088. {
  2089. int len;
  2090. /* get remaining partial bytes */
  2091. len = dw_mci_pull_part_bytes(host, buf, cnt);
  2092. if (unlikely(len == cnt))
  2093. return;
  2094. buf += len;
  2095. cnt -= len;
  2096. /* get the rest of the data */
  2097. host->pull_data(host, buf, cnt);
  2098. }
  2099. static void dw_mci_read_data_pio(struct dw_mci *host, bool dto)
  2100. {
  2101. struct sg_mapping_iter *sg_miter = &host->sg_miter;
  2102. void *buf;
  2103. unsigned int offset;
  2104. struct mmc_data *data = host->data;
  2105. int shift = host->data_shift;
  2106. u32 status;
  2107. unsigned int len;
  2108. unsigned int remain, fcnt;
  2109. do {
  2110. if (!sg_miter_next(sg_miter))
  2111. goto done;
  2112. host->sg = sg_miter->piter.sg;
  2113. buf = sg_miter->addr;
  2114. remain = sg_miter->length;
  2115. offset = 0;
  2116. do {
  2117. fcnt = (SDMMC_GET_FCNT(mci_readl(host, STATUS))
  2118. << shift) + host->part_buf_count;
  2119. len = min(remain, fcnt);
  2120. if (!len)
  2121. break;
  2122. dw_mci_pull_data(host, (void *)(buf + offset), len);
  2123. data->bytes_xfered += len;
  2124. offset += len;
  2125. remain -= len;
  2126. } while (remain);
  2127. sg_miter->consumed = offset;
  2128. status = mci_readl(host, MINTSTS);
  2129. mci_writel(host, RINTSTS, SDMMC_INT_RXDR);
  2130. /* if the RXDR is ready read again */
  2131. } while ((status & SDMMC_INT_RXDR) ||
  2132. (dto && SDMMC_GET_FCNT(mci_readl(host, STATUS))));
  2133. if (!remain) {
  2134. if (!sg_miter_next(sg_miter))
  2135. goto done;
  2136. sg_miter->consumed = 0;
  2137. }
  2138. sg_miter_stop(sg_miter);
  2139. return;
  2140. done:
  2141. sg_miter_stop(sg_miter);
  2142. host->sg = NULL;
  2143. smp_wmb(); /* drain writebuffer */
  2144. set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
  2145. }
  2146. static void dw_mci_write_data_pio(struct dw_mci *host)
  2147. {
  2148. struct sg_mapping_iter *sg_miter = &host->sg_miter;
  2149. void *buf;
  2150. unsigned int offset;
  2151. struct mmc_data *data = host->data;
  2152. int shift = host->data_shift;
  2153. u32 status;
  2154. unsigned int len;
  2155. unsigned int fifo_depth = host->fifo_depth;
  2156. unsigned int remain, fcnt;
  2157. do {
  2158. if (!sg_miter_next(sg_miter))
  2159. goto done;
  2160. host->sg = sg_miter->piter.sg;
  2161. buf = sg_miter->addr;
  2162. remain = sg_miter->length;
  2163. offset = 0;
  2164. do {
  2165. fcnt = ((fifo_depth -
  2166. SDMMC_GET_FCNT(mci_readl(host, STATUS)))
  2167. << shift) - host->part_buf_count;
  2168. len = min(remain, fcnt);
  2169. if (!len)
  2170. break;
  2171. host->push_data(host, (void *)(buf + offset), len);
  2172. data->bytes_xfered += len;
  2173. offset += len;
  2174. remain -= len;
  2175. } while (remain);
  2176. sg_miter->consumed = offset;
  2177. status = mci_readl(host, MINTSTS);
  2178. mci_writel(host, RINTSTS, SDMMC_INT_TXDR);
  2179. } while (status & SDMMC_INT_TXDR); /* if TXDR write again */
  2180. if (!remain) {
  2181. if (!sg_miter_next(sg_miter))
  2182. goto done;
  2183. sg_miter->consumed = 0;
  2184. }
  2185. sg_miter_stop(sg_miter);
  2186. return;
  2187. done:
  2188. sg_miter_stop(sg_miter);
  2189. host->sg = NULL;
  2190. smp_wmb(); /* drain writebuffer */
  2191. set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
  2192. }
  2193. static void dw_mci_cmd_interrupt(struct dw_mci *host, u32 status)
  2194. {
  2195. del_timer(&host->cto_timer);
  2196. if (!host->cmd_status)
  2197. host->cmd_status = status;
  2198. smp_wmb(); /* drain writebuffer */
  2199. set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
  2200. tasklet_schedule(&host->tasklet);
  2201. }
  2202. static void dw_mci_handle_cd(struct dw_mci *host)
  2203. {
  2204. struct dw_mci_slot *slot = host->slot;
  2205. if (slot->mmc->ops->card_event)
  2206. slot->mmc->ops->card_event(slot->mmc);
  2207. mmc_detect_change(slot->mmc,
  2208. msecs_to_jiffies(host->pdata->detect_delay_ms));
  2209. }
  2210. static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
  2211. {
  2212. struct dw_mci *host = dev_id;
  2213. u32 pending;
  2214. struct dw_mci_slot *slot = host->slot;
  2215. unsigned long irqflags;
  2216. pending = mci_readl(host, MINTSTS); /* read-only mask reg */
  2217. if (pending) {
  2218. /* Check volt switch first, since it can look like an error */
  2219. if ((host->state == STATE_SENDING_CMD11) &&
  2220. (pending & SDMMC_INT_VOLT_SWITCH)) {
  2221. mci_writel(host, RINTSTS, SDMMC_INT_VOLT_SWITCH);
  2222. pending &= ~SDMMC_INT_VOLT_SWITCH;
  2223. /*
  2224. * Hold the lock; we know cmd11_timer can't be kicked
  2225. * off after the lock is released, so safe to delete.
  2226. */
  2227. spin_lock_irqsave(&host->irq_lock, irqflags);
  2228. dw_mci_cmd_interrupt(host, pending);
  2229. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  2230. del_timer(&host->cmd11_timer);
  2231. }
  2232. if (pending & DW_MCI_CMD_ERROR_FLAGS) {
  2233. spin_lock_irqsave(&host->irq_lock, irqflags);
  2234. del_timer(&host->cto_timer);
  2235. mci_writel(host, RINTSTS, DW_MCI_CMD_ERROR_FLAGS);
  2236. host->cmd_status = pending;
  2237. smp_wmb(); /* drain writebuffer */
  2238. set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
  2239. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  2240. }
  2241. if (pending & DW_MCI_DATA_ERROR_FLAGS) {
  2242. /* if there is an error report DATA_ERROR */
  2243. mci_writel(host, RINTSTS, DW_MCI_DATA_ERROR_FLAGS);
  2244. host->data_status = pending;
  2245. smp_wmb(); /* drain writebuffer */
  2246. set_bit(EVENT_DATA_ERROR, &host->pending_events);
  2247. tasklet_schedule(&host->tasklet);
  2248. }
  2249. if (pending & SDMMC_INT_DATA_OVER) {
  2250. spin_lock_irqsave(&host->irq_lock, irqflags);
  2251. del_timer(&host->dto_timer);
  2252. mci_writel(host, RINTSTS, SDMMC_INT_DATA_OVER);
  2253. if (!host->data_status)
  2254. host->data_status = pending;
  2255. smp_wmb(); /* drain writebuffer */
  2256. if (host->dir_status == DW_MCI_RECV_STATUS) {
  2257. if (host->sg != NULL)
  2258. dw_mci_read_data_pio(host, true);
  2259. }
  2260. set_bit(EVENT_DATA_COMPLETE, &host->pending_events);
  2261. tasklet_schedule(&host->tasklet);
  2262. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  2263. }
  2264. if (pending & SDMMC_INT_RXDR) {
  2265. mci_writel(host, RINTSTS, SDMMC_INT_RXDR);
  2266. if (host->dir_status == DW_MCI_RECV_STATUS && host->sg)
  2267. dw_mci_read_data_pio(host, false);
  2268. }
  2269. if (pending & SDMMC_INT_TXDR) {
  2270. mci_writel(host, RINTSTS, SDMMC_INT_TXDR);
  2271. if (host->dir_status == DW_MCI_SEND_STATUS && host->sg)
  2272. dw_mci_write_data_pio(host);
  2273. }
  2274. if (pending & SDMMC_INT_CMD_DONE) {
  2275. spin_lock_irqsave(&host->irq_lock, irqflags);
  2276. mci_writel(host, RINTSTS, SDMMC_INT_CMD_DONE);
  2277. dw_mci_cmd_interrupt(host, pending);
  2278. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  2279. }
  2280. if (pending & SDMMC_INT_CD) {
  2281. mci_writel(host, RINTSTS, SDMMC_INT_CD);
  2282. dw_mci_handle_cd(host);
  2283. }
  2284. if (pending & SDMMC_INT_SDIO(slot->sdio_id)) {
  2285. mci_writel(host, RINTSTS,
  2286. SDMMC_INT_SDIO(slot->sdio_id));
  2287. __dw_mci_enable_sdio_irq(slot, 0);
  2288. sdio_signal_irq(slot->mmc);
  2289. }
  2290. }
  2291. if (host->use_dma != TRANS_MODE_IDMAC)
  2292. return IRQ_HANDLED;
  2293. /* Handle IDMA interrupts */
  2294. if (host->dma_64bit_address == 1) {
  2295. pending = mci_readl(host, IDSTS64);
  2296. if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) {
  2297. mci_writel(host, IDSTS64, SDMMC_IDMAC_INT_TI |
  2298. SDMMC_IDMAC_INT_RI);
  2299. mci_writel(host, IDSTS64, SDMMC_IDMAC_INT_NI);
  2300. if (!test_bit(EVENT_DATA_ERROR, &host->pending_events))
  2301. host->dma_ops->complete((void *)host);
  2302. }
  2303. } else {
  2304. pending = mci_readl(host, IDSTS);
  2305. if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) {
  2306. mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI |
  2307. SDMMC_IDMAC_INT_RI);
  2308. mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI);
  2309. if (!test_bit(EVENT_DATA_ERROR, &host->pending_events))
  2310. host->dma_ops->complete((void *)host);
  2311. }
  2312. }
  2313. return IRQ_HANDLED;
  2314. }
  2315. static int dw_mci_init_slot_caps(struct dw_mci_slot *slot)
  2316. {
  2317. struct dw_mci *host = slot->host;
  2318. const struct dw_mci_drv_data *drv_data = host->drv_data;
  2319. struct mmc_host *mmc = slot->mmc;
  2320. int ctrl_id;
  2321. if (host->pdata->caps)
  2322. mmc->caps = host->pdata->caps;
  2323. /*
  2324. * Support MMC_CAP_ERASE by default.
  2325. * It needs to use trim/discard/erase commands.
  2326. */
  2327. mmc->caps |= MMC_CAP_ERASE;
  2328. if (host->pdata->pm_caps)
  2329. mmc->pm_caps = host->pdata->pm_caps;
  2330. if (host->dev->of_node) {
  2331. ctrl_id = of_alias_get_id(host->dev->of_node, "mshc");
  2332. if (ctrl_id < 0)
  2333. ctrl_id = 0;
  2334. } else {
  2335. ctrl_id = to_platform_device(host->dev)->id;
  2336. }
  2337. if (drv_data && drv_data->caps) {
  2338. if (ctrl_id >= drv_data->num_caps) {
  2339. dev_err(host->dev, "invalid controller id %d\n",
  2340. ctrl_id);
  2341. return -EINVAL;
  2342. }
  2343. mmc->caps |= drv_data->caps[ctrl_id];
  2344. }
  2345. if (host->pdata->caps2)
  2346. mmc->caps2 = host->pdata->caps2;
  2347. mmc->f_min = DW_MCI_FREQ_MIN;
  2348. if (!mmc->f_max)
  2349. mmc->f_max = DW_MCI_FREQ_MAX;
  2350. /* Process SDIO IRQs through the sdio_irq_work. */
  2351. if (mmc->caps & MMC_CAP_SDIO_IRQ)
  2352. mmc->caps2 |= MMC_CAP2_SDIO_IRQ_NOTHREAD;
  2353. return 0;
  2354. }
  2355. static int dw_mci_init_slot(struct dw_mci *host)
  2356. {
  2357. struct mmc_host *mmc;
  2358. struct dw_mci_slot *slot;
  2359. int ret;
  2360. mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), host->dev);
  2361. if (!mmc)
  2362. return -ENOMEM;
  2363. slot = mmc_priv(mmc);
  2364. slot->id = 0;
  2365. slot->sdio_id = host->sdio_id0 + slot->id;
  2366. slot->mmc = mmc;
  2367. slot->host = host;
  2368. host->slot = slot;
  2369. mmc->ops = &dw_mci_ops;
  2370. /*if there are external regulators, get them*/
  2371. ret = mmc_regulator_get_supply(mmc);
  2372. if (ret)
  2373. goto err_host_allocated;
  2374. if (!mmc->ocr_avail)
  2375. mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
  2376. ret = mmc_of_parse(mmc);
  2377. if (ret)
  2378. goto err_host_allocated;
  2379. ret = dw_mci_init_slot_caps(slot);
  2380. if (ret)
  2381. goto err_host_allocated;
  2382. /* Useful defaults if platform data is unset. */
  2383. if (host->use_dma == TRANS_MODE_IDMAC) {
  2384. mmc->max_segs = host->ring_size;
  2385. mmc->max_blk_size = 65535;
  2386. mmc->max_seg_size = 0x1000;
  2387. mmc->max_req_size = mmc->max_seg_size * host->ring_size;
  2388. mmc->max_blk_count = mmc->max_req_size / 512;
  2389. } else if (host->use_dma == TRANS_MODE_EDMAC) {
  2390. mmc->max_segs = 64;
  2391. mmc->max_blk_size = 65535;
  2392. mmc->max_blk_count = 65535;
  2393. mmc->max_req_size =
  2394. mmc->max_blk_size * mmc->max_blk_count;
  2395. mmc->max_seg_size = mmc->max_req_size;
  2396. } else {
  2397. /* TRANS_MODE_PIO */
  2398. mmc->max_segs = 64;
  2399. mmc->max_blk_size = 65535; /* BLKSIZ is 16 bits */
  2400. mmc->max_blk_count = 512;
  2401. mmc->max_req_size = mmc->max_blk_size *
  2402. mmc->max_blk_count;
  2403. mmc->max_seg_size = mmc->max_req_size;
  2404. }
  2405. dw_mci_get_cd(mmc);
  2406. ret = mmc_add_host(mmc);
  2407. if (ret)
  2408. goto err_host_allocated;
  2409. #if defined(CONFIG_DEBUG_FS)
  2410. dw_mci_init_debugfs(slot);
  2411. #endif
  2412. return 0;
  2413. err_host_allocated:
  2414. mmc_free_host(mmc);
  2415. return ret;
  2416. }
  2417. static void dw_mci_cleanup_slot(struct dw_mci_slot *slot)
  2418. {
  2419. /* Debugfs stuff is cleaned up by mmc core */
  2420. mmc_remove_host(slot->mmc);
  2421. slot->host->slot = NULL;
  2422. mmc_free_host(slot->mmc);
  2423. }
  2424. static void dw_mci_init_dma(struct dw_mci *host)
  2425. {
  2426. int addr_config;
  2427. struct device *dev = host->dev;
  2428. /*
  2429. * Check tansfer mode from HCON[17:16]
  2430. * Clear the ambiguous description of dw_mmc databook:
  2431. * 2b'00: No DMA Interface -> Actually means using Internal DMA block
  2432. * 2b'01: DesignWare DMA Interface -> Synopsys DW-DMA block
  2433. * 2b'10: Generic DMA Interface -> non-Synopsys generic DMA block
  2434. * 2b'11: Non DW DMA Interface -> pio only
  2435. * Compared to DesignWare DMA Interface, Generic DMA Interface has a
  2436. * simpler request/acknowledge handshake mechanism and both of them
  2437. * are regarded as external dma master for dw_mmc.
  2438. */
  2439. host->use_dma = SDMMC_GET_TRANS_MODE(mci_readl(host, HCON));
  2440. if (host->use_dma == DMA_INTERFACE_IDMA) {
  2441. host->use_dma = TRANS_MODE_IDMAC;
  2442. } else if (host->use_dma == DMA_INTERFACE_DWDMA ||
  2443. host->use_dma == DMA_INTERFACE_GDMA) {
  2444. host->use_dma = TRANS_MODE_EDMAC;
  2445. } else {
  2446. goto no_dma;
  2447. }
  2448. /* Determine which DMA interface to use */
  2449. if (host->use_dma == TRANS_MODE_IDMAC) {
  2450. /*
  2451. * Check ADDR_CONFIG bit in HCON to find
  2452. * IDMAC address bus width
  2453. */
  2454. addr_config = SDMMC_GET_ADDR_CONFIG(mci_readl(host, HCON));
  2455. if (addr_config == 1) {
  2456. /* host supports IDMAC in 64-bit address mode */
  2457. host->dma_64bit_address = 1;
  2458. dev_info(host->dev,
  2459. "IDMAC supports 64-bit address mode.\n");
  2460. if (!dma_set_mask(host->dev, DMA_BIT_MASK(64)))
  2461. dma_set_coherent_mask(host->dev,
  2462. DMA_BIT_MASK(64));
  2463. } else {
  2464. /* host supports IDMAC in 32-bit address mode */
  2465. host->dma_64bit_address = 0;
  2466. dev_info(host->dev,
  2467. "IDMAC supports 32-bit address mode.\n");
  2468. }
  2469. /* Alloc memory for sg translation */
  2470. host->sg_cpu = dmam_alloc_coherent(host->dev,
  2471. DESC_RING_BUF_SZ,
  2472. &host->sg_dma, GFP_KERNEL);
  2473. if (!host->sg_cpu) {
  2474. dev_err(host->dev,
  2475. "%s: could not alloc DMA memory\n",
  2476. __func__);
  2477. goto no_dma;
  2478. }
  2479. host->dma_ops = &dw_mci_idmac_ops;
  2480. dev_info(host->dev, "Using internal DMA controller.\n");
  2481. } else {
  2482. /* TRANS_MODE_EDMAC: check dma bindings again */
  2483. if ((device_property_read_string_array(dev, "dma-names",
  2484. NULL, 0) < 0) ||
  2485. !device_property_present(dev, "dmas")) {
  2486. goto no_dma;
  2487. }
  2488. host->dma_ops = &dw_mci_edmac_ops;
  2489. dev_info(host->dev, "Using external DMA controller.\n");
  2490. }
  2491. if (host->dma_ops->init && host->dma_ops->start &&
  2492. host->dma_ops->stop && host->dma_ops->cleanup) {
  2493. if (host->dma_ops->init(host)) {
  2494. dev_err(host->dev, "%s: Unable to initialize DMA Controller.\n",
  2495. __func__);
  2496. goto no_dma;
  2497. }
  2498. } else {
  2499. dev_err(host->dev, "DMA initialization not found.\n");
  2500. goto no_dma;
  2501. }
  2502. return;
  2503. no_dma:
  2504. dev_info(host->dev, "Using PIO mode.\n");
  2505. host->use_dma = TRANS_MODE_PIO;
  2506. }
  2507. static void dw_mci_cmd11_timer(struct timer_list *t)
  2508. {
  2509. struct dw_mci *host = from_timer(host, t, cmd11_timer);
  2510. if (host->state != STATE_SENDING_CMD11) {
  2511. dev_warn(host->dev, "Unexpected CMD11 timeout\n");
  2512. return;
  2513. }
  2514. host->cmd_status = SDMMC_INT_RTO;
  2515. set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
  2516. tasklet_schedule(&host->tasklet);
  2517. }
  2518. static void dw_mci_cto_timer(struct timer_list *t)
  2519. {
  2520. struct dw_mci *host = from_timer(host, t, cto_timer);
  2521. unsigned long irqflags;
  2522. u32 pending;
  2523. spin_lock_irqsave(&host->irq_lock, irqflags);
  2524. /*
  2525. * If somehow we have very bad interrupt latency it's remotely possible
  2526. * that the timer could fire while the interrupt is still pending or
  2527. * while the interrupt is midway through running. Let's be paranoid
  2528. * and detect those two cases. Note that this is paranoia is somewhat
  2529. * justified because in this function we don't actually cancel the
  2530. * pending command in the controller--we just assume it will never come.
  2531. */
  2532. pending = mci_readl(host, MINTSTS); /* read-only mask reg */
  2533. if (pending & (DW_MCI_CMD_ERROR_FLAGS | SDMMC_INT_CMD_DONE)) {
  2534. /* The interrupt should fire; no need to act but we can warn */
  2535. dev_warn(host->dev, "Unexpected interrupt latency\n");
  2536. goto exit;
  2537. }
  2538. if (test_bit(EVENT_CMD_COMPLETE, &host->pending_events)) {
  2539. /* Presumably interrupt handler couldn't delete the timer */
  2540. dev_warn(host->dev, "CTO timeout when already completed\n");
  2541. goto exit;
  2542. }
  2543. /*
  2544. * Continued paranoia to make sure we're in the state we expect.
  2545. * This paranoia isn't really justified but it seems good to be safe.
  2546. */
  2547. switch (host->state) {
  2548. case STATE_SENDING_CMD11:
  2549. case STATE_SENDING_CMD:
  2550. case STATE_SENDING_STOP:
  2551. /*
  2552. * If CMD_DONE interrupt does NOT come in sending command
  2553. * state, we should notify the driver to terminate current
  2554. * transfer and report a command timeout to the core.
  2555. */
  2556. host->cmd_status = SDMMC_INT_RTO;
  2557. set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
  2558. tasklet_schedule(&host->tasklet);
  2559. break;
  2560. default:
  2561. dev_warn(host->dev, "Unexpected command timeout, state %d\n",
  2562. host->state);
  2563. break;
  2564. }
  2565. exit:
  2566. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  2567. }
  2568. static void dw_mci_dto_timer(struct timer_list *t)
  2569. {
  2570. struct dw_mci *host = from_timer(host, t, dto_timer);
  2571. unsigned long irqflags;
  2572. u32 pending;
  2573. spin_lock_irqsave(&host->irq_lock, irqflags);
  2574. /*
  2575. * The DTO timer is much longer than the CTO timer, so it's even less
  2576. * likely that we'll these cases, but it pays to be paranoid.
  2577. */
  2578. pending = mci_readl(host, MINTSTS); /* read-only mask reg */
  2579. if (pending & SDMMC_INT_DATA_OVER) {
  2580. /* The interrupt should fire; no need to act but we can warn */
  2581. dev_warn(host->dev, "Unexpected data interrupt latency\n");
  2582. goto exit;
  2583. }
  2584. if (test_bit(EVENT_DATA_COMPLETE, &host->pending_events)) {
  2585. /* Presumably interrupt handler couldn't delete the timer */
  2586. dev_warn(host->dev, "DTO timeout when already completed\n");
  2587. goto exit;
  2588. }
  2589. /*
  2590. * Continued paranoia to make sure we're in the state we expect.
  2591. * This paranoia isn't really justified but it seems good to be safe.
  2592. */
  2593. switch (host->state) {
  2594. case STATE_SENDING_DATA:
  2595. case STATE_DATA_BUSY:
  2596. /*
  2597. * If DTO interrupt does NOT come in sending data state,
  2598. * we should notify the driver to terminate current transfer
  2599. * and report a data timeout to the core.
  2600. */
  2601. host->data_status = SDMMC_INT_DRTO;
  2602. set_bit(EVENT_DATA_ERROR, &host->pending_events);
  2603. set_bit(EVENT_DATA_COMPLETE, &host->pending_events);
  2604. tasklet_schedule(&host->tasklet);
  2605. break;
  2606. default:
  2607. dev_warn(host->dev, "Unexpected data timeout, state %d\n",
  2608. host->state);
  2609. break;
  2610. }
  2611. exit:
  2612. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  2613. }
  2614. #ifdef CONFIG_OF
  2615. static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
  2616. {
  2617. struct dw_mci_board *pdata;
  2618. struct device *dev = host->dev;
  2619. const struct dw_mci_drv_data *drv_data = host->drv_data;
  2620. int ret;
  2621. u32 clock_frequency;
  2622. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  2623. if (!pdata)
  2624. return ERR_PTR(-ENOMEM);
  2625. /* find reset controller when exist */
  2626. pdata->rstc = devm_reset_control_get_optional_exclusive(dev, "reset");
  2627. if (IS_ERR(pdata->rstc)) {
  2628. if (PTR_ERR(pdata->rstc) == -EPROBE_DEFER)
  2629. return ERR_PTR(-EPROBE_DEFER);
  2630. }
  2631. if (device_property_read_u32(dev, "fifo-depth", &pdata->fifo_depth))
  2632. dev_info(dev,
  2633. "fifo-depth property not found, using value of FIFOTH register as default\n");
  2634. device_property_read_u32(dev, "card-detect-delay",
  2635. &pdata->detect_delay_ms);
  2636. device_property_read_u32(dev, "data-addr", &host->data_addr_override);
  2637. if (device_property_present(dev, "fifo-watermark-aligned"))
  2638. host->wm_aligned = true;
  2639. if (!device_property_read_u32(dev, "clock-frequency", &clock_frequency))
  2640. pdata->bus_hz = clock_frequency;
  2641. if (drv_data && drv_data->parse_dt) {
  2642. ret = drv_data->parse_dt(host);
  2643. if (ret)
  2644. return ERR_PTR(ret);
  2645. }
  2646. return pdata;
  2647. }
  2648. #else /* CONFIG_OF */
  2649. static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
  2650. {
  2651. return ERR_PTR(-EINVAL);
  2652. }
  2653. #endif /* CONFIG_OF */
  2654. static void dw_mci_enable_cd(struct dw_mci *host)
  2655. {
  2656. unsigned long irqflags;
  2657. u32 temp;
  2658. /*
  2659. * No need for CD if all slots have a non-error GPIO
  2660. * as well as broken card detection is found.
  2661. */
  2662. if (host->slot->mmc->caps & MMC_CAP_NEEDS_POLL)
  2663. return;
  2664. if (mmc_gpio_get_cd(host->slot->mmc) < 0) {
  2665. spin_lock_irqsave(&host->irq_lock, irqflags);
  2666. temp = mci_readl(host, INTMASK);
  2667. temp |= SDMMC_INT_CD;
  2668. mci_writel(host, INTMASK, temp);
  2669. spin_unlock_irqrestore(&host->irq_lock, irqflags);
  2670. }
  2671. }
  2672. int dw_mci_probe(struct dw_mci *host)
  2673. {
  2674. const struct dw_mci_drv_data *drv_data = host->drv_data;
  2675. int width, i, ret = 0;
  2676. u32 fifo_size;
  2677. if (!host->pdata) {
  2678. host->pdata = dw_mci_parse_dt(host);
  2679. if (PTR_ERR(host->pdata) == -EPROBE_DEFER) {
  2680. return -EPROBE_DEFER;
  2681. } else if (IS_ERR(host->pdata)) {
  2682. dev_err(host->dev, "platform data not available\n");
  2683. return -EINVAL;
  2684. }
  2685. }
  2686. host->biu_clk = devm_clk_get(host->dev, "biu");
  2687. if (IS_ERR(host->biu_clk)) {
  2688. dev_dbg(host->dev, "biu clock not available\n");
  2689. } else {
  2690. ret = clk_prepare_enable(host->biu_clk);
  2691. if (ret) {
  2692. dev_err(host->dev, "failed to enable biu clock\n");
  2693. return ret;
  2694. }
  2695. }
  2696. host->ciu_clk = devm_clk_get(host->dev, "ciu");
  2697. if (IS_ERR(host->ciu_clk)) {
  2698. dev_dbg(host->dev, "ciu clock not available\n");
  2699. host->bus_hz = host->pdata->bus_hz;
  2700. } else {
  2701. ret = clk_prepare_enable(host->ciu_clk);
  2702. if (ret) {
  2703. dev_err(host->dev, "failed to enable ciu clock\n");
  2704. goto err_clk_biu;
  2705. }
  2706. if (host->pdata->bus_hz) {
  2707. ret = clk_set_rate(host->ciu_clk, host->pdata->bus_hz);
  2708. if (ret)
  2709. dev_warn(host->dev,
  2710. "Unable to set bus rate to %uHz\n",
  2711. host->pdata->bus_hz);
  2712. }
  2713. host->bus_hz = clk_get_rate(host->ciu_clk);
  2714. }
  2715. if (!host->bus_hz) {
  2716. dev_err(host->dev,
  2717. "Platform data must supply bus speed\n");
  2718. ret = -ENODEV;
  2719. goto err_clk_ciu;
  2720. }
  2721. if (!IS_ERR(host->pdata->rstc)) {
  2722. reset_control_assert(host->pdata->rstc);
  2723. usleep_range(10, 50);
  2724. reset_control_deassert(host->pdata->rstc);
  2725. }
  2726. if (drv_data && drv_data->init) {
  2727. ret = drv_data->init(host);
  2728. if (ret) {
  2729. dev_err(host->dev,
  2730. "implementation specific init failed\n");
  2731. goto err_clk_ciu;
  2732. }
  2733. }
  2734. timer_setup(&host->cmd11_timer, dw_mci_cmd11_timer, 0);
  2735. timer_setup(&host->cto_timer, dw_mci_cto_timer, 0);
  2736. timer_setup(&host->dto_timer, dw_mci_dto_timer, 0);
  2737. spin_lock_init(&host->lock);
  2738. spin_lock_init(&host->irq_lock);
  2739. INIT_LIST_HEAD(&host->queue);
  2740. /*
  2741. * Get the host data width - this assumes that HCON has been set with
  2742. * the correct values.
  2743. */
  2744. i = SDMMC_GET_HDATA_WIDTH(mci_readl(host, HCON));
  2745. if (!i) {
  2746. host->push_data = dw_mci_push_data16;
  2747. host->pull_data = dw_mci_pull_data16;
  2748. width = 16;
  2749. host->data_shift = 1;
  2750. } else if (i == 2) {
  2751. host->push_data = dw_mci_push_data64;
  2752. host->pull_data = dw_mci_pull_data64;
  2753. width = 64;
  2754. host->data_shift = 3;
  2755. } else {
  2756. /* Check for a reserved value, and warn if it is */
  2757. WARN((i != 1),
  2758. "HCON reports a reserved host data width!\n"
  2759. "Defaulting to 32-bit access.\n");
  2760. host->push_data = dw_mci_push_data32;
  2761. host->pull_data = dw_mci_pull_data32;
  2762. width = 32;
  2763. host->data_shift = 2;
  2764. }
  2765. /* Reset all blocks */
  2766. if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_ALL_RESET_FLAGS)) {
  2767. ret = -ENODEV;
  2768. goto err_clk_ciu;
  2769. }
  2770. host->dma_ops = host->pdata->dma_ops;
  2771. dw_mci_init_dma(host);
  2772. /* Clear the interrupts for the host controller */
  2773. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  2774. mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
  2775. /* Put in max timeout */
  2776. mci_writel(host, TMOUT, 0xFFFFFFFF);
  2777. /*
  2778. * FIFO threshold settings RxMark = fifo_size / 2 - 1,
  2779. * Tx Mark = fifo_size / 2 DMA Size = 8
  2780. */
  2781. if (!host->pdata->fifo_depth) {
  2782. /*
  2783. * Power-on value of RX_WMark is FIFO_DEPTH-1, but this may
  2784. * have been overwritten by the bootloader, just like we're
  2785. * about to do, so if you know the value for your hardware, you
  2786. * should put it in the platform data.
  2787. */
  2788. fifo_size = mci_readl(host, FIFOTH);
  2789. fifo_size = 1 + ((fifo_size >> 16) & 0xfff);
  2790. } else {
  2791. fifo_size = host->pdata->fifo_depth;
  2792. }
  2793. host->fifo_depth = fifo_size;
  2794. host->fifoth_val =
  2795. SDMMC_SET_FIFOTH(0x2, fifo_size / 2 - 1, fifo_size / 2);
  2796. mci_writel(host, FIFOTH, host->fifoth_val);
  2797. /* disable clock to CIU */
  2798. mci_writel(host, CLKENA, 0);
  2799. mci_writel(host, CLKSRC, 0);
  2800. /*
  2801. * In 2.40a spec, Data offset is changed.
  2802. * Need to check the version-id and set data-offset for DATA register.
  2803. */
  2804. host->verid = SDMMC_GET_VERID(mci_readl(host, VERID));
  2805. dev_info(host->dev, "Version ID is %04x\n", host->verid);
  2806. if (host->data_addr_override)
  2807. host->fifo_reg = host->regs + host->data_addr_override;
  2808. else if (host->verid < DW_MMC_240A)
  2809. host->fifo_reg = host->regs + DATA_OFFSET;
  2810. else
  2811. host->fifo_reg = host->regs + DATA_240A_OFFSET;
  2812. tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host);
  2813. ret = devm_request_irq(host->dev, host->irq, dw_mci_interrupt,
  2814. host->irq_flags, "dw-mci", host);
  2815. if (ret)
  2816. goto err_dmaunmap;
  2817. /*
  2818. * Enable interrupts for command done, data over, data empty,
  2819. * receive ready and error such as transmit, receive timeout, crc error
  2820. */
  2821. mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
  2822. SDMMC_INT_TXDR | SDMMC_INT_RXDR |
  2823. DW_MCI_ERROR_FLAGS);
  2824. /* Enable mci interrupt */
  2825. mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE);
  2826. dev_info(host->dev,
  2827. "DW MMC controller at irq %d,%d bit host data width,%u deep fifo\n",
  2828. host->irq, width, fifo_size);
  2829. /* We need at least one slot to succeed */
  2830. ret = dw_mci_init_slot(host);
  2831. if (ret) {
  2832. dev_dbg(host->dev, "slot %d init failed\n", i);
  2833. goto err_dmaunmap;
  2834. }
  2835. /* Now that slots are all setup, we can enable card detect */
  2836. dw_mci_enable_cd(host);
  2837. return 0;
  2838. err_dmaunmap:
  2839. if (host->use_dma && host->dma_ops->exit)
  2840. host->dma_ops->exit(host);
  2841. if (!IS_ERR(host->pdata->rstc))
  2842. reset_control_assert(host->pdata->rstc);
  2843. err_clk_ciu:
  2844. clk_disable_unprepare(host->ciu_clk);
  2845. err_clk_biu:
  2846. clk_disable_unprepare(host->biu_clk);
  2847. return ret;
  2848. }
  2849. EXPORT_SYMBOL(dw_mci_probe);
  2850. void dw_mci_remove(struct dw_mci *host)
  2851. {
  2852. dev_dbg(host->dev, "remove slot\n");
  2853. if (host->slot)
  2854. dw_mci_cleanup_slot(host->slot);
  2855. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  2856. mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
  2857. /* disable clock to CIU */
  2858. mci_writel(host, CLKENA, 0);
  2859. mci_writel(host, CLKSRC, 0);
  2860. if (host->use_dma && host->dma_ops->exit)
  2861. host->dma_ops->exit(host);
  2862. if (!IS_ERR(host->pdata->rstc))
  2863. reset_control_assert(host->pdata->rstc);
  2864. clk_disable_unprepare(host->ciu_clk);
  2865. clk_disable_unprepare(host->biu_clk);
  2866. }
  2867. EXPORT_SYMBOL(dw_mci_remove);
  2868. #ifdef CONFIG_PM
  2869. int dw_mci_runtime_suspend(struct device *dev)
  2870. {
  2871. struct dw_mci *host = dev_get_drvdata(dev);
  2872. if (host->use_dma && host->dma_ops->exit)
  2873. host->dma_ops->exit(host);
  2874. clk_disable_unprepare(host->ciu_clk);
  2875. if (host->slot &&
  2876. (mmc_can_gpio_cd(host->slot->mmc) ||
  2877. !mmc_card_is_removable(host->slot->mmc)))
  2878. clk_disable_unprepare(host->biu_clk);
  2879. return 0;
  2880. }
  2881. EXPORT_SYMBOL(dw_mci_runtime_suspend);
  2882. int dw_mci_runtime_resume(struct device *dev)
  2883. {
  2884. int ret = 0;
  2885. struct dw_mci *host = dev_get_drvdata(dev);
  2886. if (host->slot &&
  2887. (mmc_can_gpio_cd(host->slot->mmc) ||
  2888. !mmc_card_is_removable(host->slot->mmc))) {
  2889. ret = clk_prepare_enable(host->biu_clk);
  2890. if (ret)
  2891. return ret;
  2892. }
  2893. ret = clk_prepare_enable(host->ciu_clk);
  2894. if (ret)
  2895. goto err;
  2896. if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_ALL_RESET_FLAGS)) {
  2897. clk_disable_unprepare(host->ciu_clk);
  2898. ret = -ENODEV;
  2899. goto err;
  2900. }
  2901. if (host->use_dma && host->dma_ops->init)
  2902. host->dma_ops->init(host);
  2903. /*
  2904. * Restore the initial value at FIFOTH register
  2905. * And Invalidate the prev_blksz with zero
  2906. */
  2907. mci_writel(host, FIFOTH, host->fifoth_val);
  2908. host->prev_blksz = 0;
  2909. /* Put in max timeout */
  2910. mci_writel(host, TMOUT, 0xFFFFFFFF);
  2911. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  2912. mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
  2913. SDMMC_INT_TXDR | SDMMC_INT_RXDR |
  2914. DW_MCI_ERROR_FLAGS);
  2915. mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE);
  2916. if (host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)
  2917. dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios);
  2918. /* Force setup bus to guarantee available clock output */
  2919. dw_mci_setup_bus(host->slot, true);
  2920. /* Now that slots are all setup, we can enable card detect */
  2921. dw_mci_enable_cd(host);
  2922. return 0;
  2923. err:
  2924. if (host->slot &&
  2925. (mmc_can_gpio_cd(host->slot->mmc) ||
  2926. !mmc_card_is_removable(host->slot->mmc)))
  2927. clk_disable_unprepare(host->biu_clk);
  2928. return ret;
  2929. }
  2930. EXPORT_SYMBOL(dw_mci_runtime_resume);
  2931. #endif /* CONFIG_PM */
  2932. static int __init dw_mci_init(void)
  2933. {
  2934. pr_info("Synopsys Designware Multimedia Card Interface Driver\n");
  2935. return 0;
  2936. }
  2937. static void __exit dw_mci_exit(void)
  2938. {
  2939. }
  2940. module_init(dw_mci_init);
  2941. module_exit(dw_mci_exit);
  2942. MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
  2943. MODULE_AUTHOR("NXP Semiconductor VietNam");
  2944. MODULE_AUTHOR("Imagination Technologies Ltd");
  2945. MODULE_LICENSE("GPL v2");