dw_mmc.c 59 KB

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