dw_mmc.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880
  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/scatterlist.h>
  25. #include <linux/seq_file.h>
  26. #include <linux/slab.h>
  27. #include <linux/stat.h>
  28. #include <linux/delay.h>
  29. #include <linux/irq.h>
  30. #include <linux/mmc/host.h>
  31. #include <linux/mmc/mmc.h>
  32. #include <linux/mmc/dw_mmc.h>
  33. #include <linux/bitops.h>
  34. #include <linux/regulator/consumer.h>
  35. #include <linux/workqueue.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 & 0x03ffc000) | ((s) & 0x3fff))
  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. static struct workqueue_struct *dw_mci_card_workqueue;
  93. #if defined(CONFIG_DEBUG_FS)
  94. static int dw_mci_req_show(struct seq_file *s, void *v)
  95. {
  96. struct dw_mci_slot *slot = s->private;
  97. struct mmc_request *mrq;
  98. struct mmc_command *cmd;
  99. struct mmc_command *stop;
  100. struct mmc_data *data;
  101. /* Make sure we get a consistent snapshot */
  102. spin_lock_bh(&slot->host->lock);
  103. mrq = slot->mrq;
  104. if (mrq) {
  105. cmd = mrq->cmd;
  106. data = mrq->data;
  107. stop = mrq->stop;
  108. if (cmd)
  109. seq_printf(s,
  110. "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
  111. cmd->opcode, cmd->arg, cmd->flags,
  112. cmd->resp[0], cmd->resp[1], cmd->resp[2],
  113. cmd->resp[2], cmd->error);
  114. if (data)
  115. seq_printf(s, "DATA %u / %u * %u flg %x err %d\n",
  116. data->bytes_xfered, data->blocks,
  117. data->blksz, data->flags, data->error);
  118. if (stop)
  119. seq_printf(s,
  120. "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
  121. stop->opcode, stop->arg, stop->flags,
  122. stop->resp[0], stop->resp[1], stop->resp[2],
  123. stop->resp[2], stop->error);
  124. }
  125. spin_unlock_bh(&slot->host->lock);
  126. return 0;
  127. }
  128. static int dw_mci_req_open(struct inode *inode, struct file *file)
  129. {
  130. return single_open(file, dw_mci_req_show, inode->i_private);
  131. }
  132. static const struct file_operations dw_mci_req_fops = {
  133. .owner = THIS_MODULE,
  134. .open = dw_mci_req_open,
  135. .read = seq_read,
  136. .llseek = seq_lseek,
  137. .release = single_release,
  138. };
  139. static int dw_mci_regs_show(struct seq_file *s, void *v)
  140. {
  141. seq_printf(s, "STATUS:\t0x%08x\n", SDMMC_STATUS);
  142. seq_printf(s, "RINTSTS:\t0x%08x\n", SDMMC_RINTSTS);
  143. seq_printf(s, "CMD:\t0x%08x\n", SDMMC_CMD);
  144. seq_printf(s, "CTRL:\t0x%08x\n", SDMMC_CTRL);
  145. seq_printf(s, "INTMASK:\t0x%08x\n", SDMMC_INTMASK);
  146. seq_printf(s, "CLKENA:\t0x%08x\n", SDMMC_CLKENA);
  147. return 0;
  148. }
  149. static int dw_mci_regs_open(struct inode *inode, struct file *file)
  150. {
  151. return single_open(file, dw_mci_regs_show, inode->i_private);
  152. }
  153. static const struct file_operations dw_mci_regs_fops = {
  154. .owner = THIS_MODULE,
  155. .open = dw_mci_regs_open,
  156. .read = seq_read,
  157. .llseek = seq_lseek,
  158. .release = single_release,
  159. };
  160. static void dw_mci_init_debugfs(struct dw_mci_slot *slot)
  161. {
  162. struct mmc_host *mmc = slot->mmc;
  163. struct dw_mci *host = slot->host;
  164. struct dentry *root;
  165. struct dentry *node;
  166. root = mmc->debugfs_root;
  167. if (!root)
  168. return;
  169. node = debugfs_create_file("regs", S_IRUSR, root, host,
  170. &dw_mci_regs_fops);
  171. if (!node)
  172. goto err;
  173. node = debugfs_create_file("req", S_IRUSR, root, slot,
  174. &dw_mci_req_fops);
  175. if (!node)
  176. goto err;
  177. node = debugfs_create_u32("state", S_IRUSR, root, (u32 *)&host->state);
  178. if (!node)
  179. goto err;
  180. node = debugfs_create_x32("pending_events", S_IRUSR, root,
  181. (u32 *)&host->pending_events);
  182. if (!node)
  183. goto err;
  184. node = debugfs_create_x32("completed_events", S_IRUSR, root,
  185. (u32 *)&host->completed_events);
  186. if (!node)
  187. goto err;
  188. return;
  189. err:
  190. dev_err(&mmc->class_dev, "failed to initialize debugfs for slot\n");
  191. }
  192. #endif /* defined(CONFIG_DEBUG_FS) */
  193. static void dw_mci_set_timeout(struct dw_mci *host)
  194. {
  195. /* timeout (maximum) */
  196. mci_writel(host, TMOUT, 0xffffffff);
  197. }
  198. static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
  199. {
  200. struct mmc_data *data;
  201. u32 cmdr;
  202. cmd->error = -EINPROGRESS;
  203. cmdr = cmd->opcode;
  204. if (cmdr == MMC_STOP_TRANSMISSION)
  205. cmdr |= SDMMC_CMD_STOP;
  206. else
  207. cmdr |= SDMMC_CMD_PRV_DAT_WAIT;
  208. if (cmd->flags & MMC_RSP_PRESENT) {
  209. /* We expect a response, so set this bit */
  210. cmdr |= SDMMC_CMD_RESP_EXP;
  211. if (cmd->flags & MMC_RSP_136)
  212. cmdr |= SDMMC_CMD_RESP_LONG;
  213. }
  214. if (cmd->flags & MMC_RSP_CRC)
  215. cmdr |= SDMMC_CMD_RESP_CRC;
  216. data = cmd->data;
  217. if (data) {
  218. cmdr |= SDMMC_CMD_DAT_EXP;
  219. if (data->flags & MMC_DATA_STREAM)
  220. cmdr |= SDMMC_CMD_STRM_MODE;
  221. if (data->flags & MMC_DATA_WRITE)
  222. cmdr |= SDMMC_CMD_DAT_WR;
  223. }
  224. return cmdr;
  225. }
  226. static void dw_mci_start_command(struct dw_mci *host,
  227. struct mmc_command *cmd, u32 cmd_flags)
  228. {
  229. host->cmd = cmd;
  230. dev_vdbg(&host->pdev->dev,
  231. "start command: ARGR=0x%08x CMDR=0x%08x\n",
  232. cmd->arg, cmd_flags);
  233. mci_writel(host, CMDARG, cmd->arg);
  234. wmb();
  235. mci_writel(host, CMD, cmd_flags | SDMMC_CMD_START);
  236. }
  237. static void send_stop_cmd(struct dw_mci *host, struct mmc_data *data)
  238. {
  239. dw_mci_start_command(host, data->stop, host->stop_cmdr);
  240. }
  241. /* DMA interface functions */
  242. static void dw_mci_stop_dma(struct dw_mci *host)
  243. {
  244. if (host->use_dma) {
  245. host->dma_ops->stop(host);
  246. host->dma_ops->cleanup(host);
  247. } else {
  248. /* Data transfer was stopped by the interrupt handler */
  249. set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
  250. }
  251. }
  252. #ifdef CONFIG_MMC_DW_IDMAC
  253. static void dw_mci_dma_cleanup(struct dw_mci *host)
  254. {
  255. struct mmc_data *data = host->data;
  256. if (data)
  257. dma_unmap_sg(&host->pdev->dev, data->sg, data->sg_len,
  258. ((data->flags & MMC_DATA_WRITE)
  259. ? DMA_TO_DEVICE : DMA_FROM_DEVICE));
  260. }
  261. static void dw_mci_idmac_stop_dma(struct dw_mci *host)
  262. {
  263. u32 temp;
  264. /* Disable and reset the IDMAC interface */
  265. temp = mci_readl(host, CTRL);
  266. temp &= ~SDMMC_CTRL_USE_IDMAC;
  267. temp |= SDMMC_CTRL_DMA_RESET;
  268. mci_writel(host, CTRL, temp);
  269. /* Stop the IDMAC running */
  270. temp = mci_readl(host, BMOD);
  271. temp &= ~(SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB);
  272. mci_writel(host, BMOD, temp);
  273. }
  274. static void dw_mci_idmac_complete_dma(struct dw_mci *host)
  275. {
  276. struct mmc_data *data = host->data;
  277. dev_vdbg(&host->pdev->dev, "DMA complete\n");
  278. host->dma_ops->cleanup(host);
  279. /*
  280. * If the card was removed, data will be NULL. No point in trying to
  281. * send the stop command or waiting for NBUSY in this case.
  282. */
  283. if (data) {
  284. set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
  285. tasklet_schedule(&host->tasklet);
  286. }
  287. }
  288. static void dw_mci_translate_sglist(struct dw_mci *host, struct mmc_data *data,
  289. unsigned int sg_len)
  290. {
  291. int i;
  292. struct idmac_desc *desc = host->sg_cpu;
  293. for (i = 0; i < sg_len; i++, desc++) {
  294. unsigned int length = sg_dma_len(&data->sg[i]);
  295. u32 mem_addr = sg_dma_address(&data->sg[i]);
  296. /* Set the OWN bit and disable interrupts for this descriptor */
  297. desc->des0 = IDMAC_DES0_OWN | IDMAC_DES0_DIC | IDMAC_DES0_CH;
  298. /* Buffer length */
  299. IDMAC_SET_BUFFER1_SIZE(desc, length);
  300. /* Physical address to DMA to/from */
  301. desc->des2 = mem_addr;
  302. }
  303. /* Set first descriptor */
  304. desc = host->sg_cpu;
  305. desc->des0 |= IDMAC_DES0_FD;
  306. /* Set last descriptor */
  307. desc = host->sg_cpu + (i - 1) * sizeof(struct idmac_desc);
  308. desc->des0 &= ~(IDMAC_DES0_CH | IDMAC_DES0_DIC);
  309. desc->des0 |= IDMAC_DES0_LD;
  310. wmb();
  311. }
  312. static void dw_mci_idmac_start_dma(struct dw_mci *host, unsigned int sg_len)
  313. {
  314. u32 temp;
  315. dw_mci_translate_sglist(host, host->data, sg_len);
  316. /* Select IDMAC interface */
  317. temp = mci_readl(host, CTRL);
  318. temp |= SDMMC_CTRL_USE_IDMAC;
  319. mci_writel(host, CTRL, temp);
  320. wmb();
  321. /* Enable the IDMAC */
  322. temp = mci_readl(host, BMOD);
  323. temp |= SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB;
  324. mci_writel(host, BMOD, temp);
  325. /* Start it running */
  326. mci_writel(host, PLDMND, 1);
  327. }
  328. static int dw_mci_idmac_init(struct dw_mci *host)
  329. {
  330. struct idmac_desc *p;
  331. int i;
  332. /* Number of descriptors in the ring buffer */
  333. host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc);
  334. /* Forward link the descriptor list */
  335. for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++)
  336. p->des3 = host->sg_dma + (sizeof(struct idmac_desc) * (i + 1));
  337. /* Set the last descriptor as the end-of-ring descriptor */
  338. p->des3 = host->sg_dma;
  339. p->des0 = IDMAC_DES0_ER;
  340. /* Mask out interrupts - get Tx & Rx complete only */
  341. mci_writel(host, IDINTEN, SDMMC_IDMAC_INT_NI | SDMMC_IDMAC_INT_RI |
  342. SDMMC_IDMAC_INT_TI);
  343. /* Set the descriptor base address */
  344. mci_writel(host, DBADDR, host->sg_dma);
  345. return 0;
  346. }
  347. static struct dw_mci_dma_ops dw_mci_idmac_ops = {
  348. .init = dw_mci_idmac_init,
  349. .start = dw_mci_idmac_start_dma,
  350. .stop = dw_mci_idmac_stop_dma,
  351. .complete = dw_mci_idmac_complete_dma,
  352. .cleanup = dw_mci_dma_cleanup,
  353. };
  354. #endif /* CONFIG_MMC_DW_IDMAC */
  355. static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
  356. {
  357. struct scatterlist *sg;
  358. unsigned int i, direction, sg_len;
  359. u32 temp;
  360. /* If we don't have a channel, we can't do DMA */
  361. if (!host->use_dma)
  362. return -ENODEV;
  363. /*
  364. * We don't do DMA on "complex" transfers, i.e. with
  365. * non-word-aligned buffers or lengths. Also, we don't bother
  366. * with all the DMA setup overhead for short transfers.
  367. */
  368. if (data->blocks * data->blksz < DW_MCI_DMA_THRESHOLD)
  369. return -EINVAL;
  370. if (data->blksz & 3)
  371. return -EINVAL;
  372. for_each_sg(data->sg, sg, data->sg_len, i) {
  373. if (sg->offset & 3 || sg->length & 3)
  374. return -EINVAL;
  375. }
  376. if (data->flags & MMC_DATA_READ)
  377. direction = DMA_FROM_DEVICE;
  378. else
  379. direction = DMA_TO_DEVICE;
  380. sg_len = dma_map_sg(&host->pdev->dev, data->sg, data->sg_len,
  381. direction);
  382. dev_vdbg(&host->pdev->dev,
  383. "sd sg_cpu: %#lx sg_dma: %#lx sg_len: %d\n",
  384. (unsigned long)host->sg_cpu, (unsigned long)host->sg_dma,
  385. sg_len);
  386. /* Enable the DMA interface */
  387. temp = mci_readl(host, CTRL);
  388. temp |= SDMMC_CTRL_DMA_ENABLE;
  389. mci_writel(host, CTRL, temp);
  390. /* Disable RX/TX IRQs, let DMA handle it */
  391. temp = mci_readl(host, INTMASK);
  392. temp &= ~(SDMMC_INT_RXDR | SDMMC_INT_TXDR);
  393. mci_writel(host, INTMASK, temp);
  394. host->dma_ops->start(host, sg_len);
  395. return 0;
  396. }
  397. static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data)
  398. {
  399. u32 temp;
  400. data->error = -EINPROGRESS;
  401. WARN_ON(host->data);
  402. host->sg = NULL;
  403. host->data = data;
  404. if (dw_mci_submit_data_dma(host, data)) {
  405. host->sg = data->sg;
  406. host->pio_offset = 0;
  407. if (data->flags & MMC_DATA_READ)
  408. host->dir_status = DW_MCI_RECV_STATUS;
  409. else
  410. host->dir_status = DW_MCI_SEND_STATUS;
  411. mci_writel(host, RINTSTS, SDMMC_INT_TXDR | SDMMC_INT_RXDR);
  412. temp = mci_readl(host, INTMASK);
  413. temp |= SDMMC_INT_TXDR | SDMMC_INT_RXDR;
  414. mci_writel(host, INTMASK, temp);
  415. temp = mci_readl(host, CTRL);
  416. temp &= ~SDMMC_CTRL_DMA_ENABLE;
  417. mci_writel(host, CTRL, temp);
  418. }
  419. }
  420. static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg)
  421. {
  422. struct dw_mci *host = slot->host;
  423. unsigned long timeout = jiffies + msecs_to_jiffies(500);
  424. unsigned int cmd_status = 0;
  425. mci_writel(host, CMDARG, arg);
  426. wmb();
  427. mci_writel(host, CMD, SDMMC_CMD_START | cmd);
  428. while (time_before(jiffies, timeout)) {
  429. cmd_status = mci_readl(host, CMD);
  430. if (!(cmd_status & SDMMC_CMD_START))
  431. return;
  432. }
  433. dev_err(&slot->mmc->class_dev,
  434. "Timeout sending command (cmd %#x arg %#x status %#x)\n",
  435. cmd, arg, cmd_status);
  436. }
  437. static void dw_mci_setup_bus(struct dw_mci_slot *slot)
  438. {
  439. struct dw_mci *host = slot->host;
  440. u32 div;
  441. if (slot->clock != host->current_speed) {
  442. if (host->bus_hz % slot->clock)
  443. /*
  444. * move the + 1 after the divide to prevent
  445. * over-clocking the card.
  446. */
  447. div = ((host->bus_hz / slot->clock) >> 1) + 1;
  448. else
  449. div = (host->bus_hz / slot->clock) >> 1;
  450. dev_info(&slot->mmc->class_dev,
  451. "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ"
  452. " div = %d)\n", slot->id, host->bus_hz, slot->clock,
  453. div ? ((host->bus_hz / div) >> 1) : host->bus_hz, div);
  454. /* disable clock */
  455. mci_writel(host, CLKENA, 0);
  456. mci_writel(host, CLKSRC, 0);
  457. /* inform CIU */
  458. mci_send_cmd(slot,
  459. SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
  460. /* set clock to desired speed */
  461. mci_writel(host, CLKDIV, div);
  462. /* inform CIU */
  463. mci_send_cmd(slot,
  464. SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
  465. /* enable clock */
  466. mci_writel(host, CLKENA, SDMMC_CLKEN_ENABLE |
  467. SDMMC_CLKEN_LOW_PWR);
  468. /* inform CIU */
  469. mci_send_cmd(slot,
  470. SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
  471. host->current_speed = slot->clock;
  472. }
  473. /* Set the current slot bus width */
  474. mci_writel(host, CTYPE, (slot->ctype << slot->id));
  475. }
  476. static void dw_mci_start_request(struct dw_mci *host,
  477. struct dw_mci_slot *slot)
  478. {
  479. struct mmc_request *mrq;
  480. struct mmc_command *cmd;
  481. struct mmc_data *data;
  482. u32 cmdflags;
  483. mrq = slot->mrq;
  484. if (host->pdata->select_slot)
  485. host->pdata->select_slot(slot->id);
  486. /* Slot specific timing and width adjustment */
  487. dw_mci_setup_bus(slot);
  488. host->cur_slot = slot;
  489. host->mrq = mrq;
  490. host->pending_events = 0;
  491. host->completed_events = 0;
  492. host->data_status = 0;
  493. data = mrq->data;
  494. if (data) {
  495. dw_mci_set_timeout(host);
  496. mci_writel(host, BYTCNT, data->blksz*data->blocks);
  497. mci_writel(host, BLKSIZ, data->blksz);
  498. }
  499. cmd = mrq->cmd;
  500. cmdflags = dw_mci_prepare_command(slot->mmc, cmd);
  501. /* this is the first command, send the initialization clock */
  502. if (test_and_clear_bit(DW_MMC_CARD_NEED_INIT, &slot->flags))
  503. cmdflags |= SDMMC_CMD_INIT;
  504. if (data) {
  505. dw_mci_submit_data(host, data);
  506. wmb();
  507. }
  508. dw_mci_start_command(host, cmd, cmdflags);
  509. if (mrq->stop)
  510. host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop);
  511. }
  512. /* must be called with host->lock held */
  513. static void dw_mci_queue_request(struct dw_mci *host, struct dw_mci_slot *slot,
  514. struct mmc_request *mrq)
  515. {
  516. dev_vdbg(&slot->mmc->class_dev, "queue request: state=%d\n",
  517. host->state);
  518. slot->mrq = mrq;
  519. if (host->state == STATE_IDLE) {
  520. host->state = STATE_SENDING_CMD;
  521. dw_mci_start_request(host, slot);
  522. } else {
  523. list_add_tail(&slot->queue_node, &host->queue);
  524. }
  525. }
  526. static void dw_mci_request(struct mmc_host *mmc, struct mmc_request *mrq)
  527. {
  528. struct dw_mci_slot *slot = mmc_priv(mmc);
  529. struct dw_mci *host = slot->host;
  530. WARN_ON(slot->mrq);
  531. /*
  532. * The check for card presence and queueing of the request must be
  533. * atomic, otherwise the card could be removed in between and the
  534. * request wouldn't fail until another card was inserted.
  535. */
  536. spin_lock_bh(&host->lock);
  537. if (!test_bit(DW_MMC_CARD_PRESENT, &slot->flags)) {
  538. spin_unlock_bh(&host->lock);
  539. mrq->cmd->error = -ENOMEDIUM;
  540. mmc_request_done(mmc, mrq);
  541. return;
  542. }
  543. dw_mci_queue_request(host, slot, mrq);
  544. spin_unlock_bh(&host->lock);
  545. }
  546. static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  547. {
  548. struct dw_mci_slot *slot = mmc_priv(mmc);
  549. u32 regs;
  550. /* set default 1 bit mode */
  551. slot->ctype = SDMMC_CTYPE_1BIT;
  552. switch (ios->bus_width) {
  553. case MMC_BUS_WIDTH_1:
  554. slot->ctype = SDMMC_CTYPE_1BIT;
  555. break;
  556. case MMC_BUS_WIDTH_4:
  557. slot->ctype = SDMMC_CTYPE_4BIT;
  558. break;
  559. case MMC_BUS_WIDTH_8:
  560. slot->ctype = SDMMC_CTYPE_8BIT;
  561. break;
  562. }
  563. /* DDR mode set */
  564. if (ios->ddr) {
  565. regs = mci_readl(slot->host, UHS_REG);
  566. regs |= (0x1 << slot->id) << 16;
  567. mci_writel(slot->host, UHS_REG, regs);
  568. }
  569. if (ios->clock) {
  570. /*
  571. * Use mirror of ios->clock to prevent race with mmc
  572. * core ios update when finding the minimum.
  573. */
  574. slot->clock = ios->clock;
  575. }
  576. switch (ios->power_mode) {
  577. case MMC_POWER_UP:
  578. set_bit(DW_MMC_CARD_NEED_INIT, &slot->flags);
  579. break;
  580. default:
  581. break;
  582. }
  583. }
  584. static int dw_mci_get_ro(struct mmc_host *mmc)
  585. {
  586. int read_only;
  587. struct dw_mci_slot *slot = mmc_priv(mmc);
  588. struct dw_mci_board *brd = slot->host->pdata;
  589. /* Use platform get_ro function, else try on board write protect */
  590. if (brd->get_ro)
  591. read_only = brd->get_ro(slot->id);
  592. else
  593. read_only =
  594. mci_readl(slot->host, WRTPRT) & (1 << slot->id) ? 1 : 0;
  595. dev_dbg(&mmc->class_dev, "card is %s\n",
  596. read_only ? "read-only" : "read-write");
  597. return read_only;
  598. }
  599. static int dw_mci_get_cd(struct mmc_host *mmc)
  600. {
  601. int present;
  602. struct dw_mci_slot *slot = mmc_priv(mmc);
  603. struct dw_mci_board *brd = slot->host->pdata;
  604. /* Use platform get_cd function, else try onboard card detect */
  605. if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION)
  606. present = 1;
  607. else if (brd->get_cd)
  608. present = !brd->get_cd(slot->id);
  609. else
  610. present = (mci_readl(slot->host, CDETECT) & (1 << slot->id))
  611. == 0 ? 1 : 0;
  612. if (present)
  613. dev_dbg(&mmc->class_dev, "card is present\n");
  614. else
  615. dev_dbg(&mmc->class_dev, "card is not present\n");
  616. return present;
  617. }
  618. static const struct mmc_host_ops dw_mci_ops = {
  619. .request = dw_mci_request,
  620. .set_ios = dw_mci_set_ios,
  621. .get_ro = dw_mci_get_ro,
  622. .get_cd = dw_mci_get_cd,
  623. };
  624. static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)
  625. __releases(&host->lock)
  626. __acquires(&host->lock)
  627. {
  628. struct dw_mci_slot *slot;
  629. struct mmc_host *prev_mmc = host->cur_slot->mmc;
  630. WARN_ON(host->cmd || host->data);
  631. host->cur_slot->mrq = NULL;
  632. host->mrq = NULL;
  633. if (!list_empty(&host->queue)) {
  634. slot = list_entry(host->queue.next,
  635. struct dw_mci_slot, queue_node);
  636. list_del(&slot->queue_node);
  637. dev_vdbg(&host->pdev->dev, "list not empty: %s is next\n",
  638. mmc_hostname(slot->mmc));
  639. host->state = STATE_SENDING_CMD;
  640. dw_mci_start_request(host, slot);
  641. } else {
  642. dev_vdbg(&host->pdev->dev, "list empty\n");
  643. host->state = STATE_IDLE;
  644. }
  645. spin_unlock(&host->lock);
  646. mmc_request_done(prev_mmc, mrq);
  647. spin_lock(&host->lock);
  648. }
  649. static void dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd)
  650. {
  651. u32 status = host->cmd_status;
  652. host->cmd_status = 0;
  653. /* Read the response from the card (up to 16 bytes) */
  654. if (cmd->flags & MMC_RSP_PRESENT) {
  655. if (cmd->flags & MMC_RSP_136) {
  656. cmd->resp[3] = mci_readl(host, RESP0);
  657. cmd->resp[2] = mci_readl(host, RESP1);
  658. cmd->resp[1] = mci_readl(host, RESP2);
  659. cmd->resp[0] = mci_readl(host, RESP3);
  660. } else {
  661. cmd->resp[0] = mci_readl(host, RESP0);
  662. cmd->resp[1] = 0;
  663. cmd->resp[2] = 0;
  664. cmd->resp[3] = 0;
  665. }
  666. }
  667. if (status & SDMMC_INT_RTO)
  668. cmd->error = -ETIMEDOUT;
  669. else if ((cmd->flags & MMC_RSP_CRC) && (status & SDMMC_INT_RCRC))
  670. cmd->error = -EILSEQ;
  671. else if (status & SDMMC_INT_RESP_ERR)
  672. cmd->error = -EIO;
  673. else
  674. cmd->error = 0;
  675. if (cmd->error) {
  676. /* newer ip versions need a delay between retries */
  677. if (host->quirks & DW_MCI_QUIRK_RETRY_DELAY)
  678. mdelay(20);
  679. if (cmd->data) {
  680. host->data = NULL;
  681. dw_mci_stop_dma(host);
  682. }
  683. }
  684. }
  685. static void dw_mci_tasklet_func(unsigned long priv)
  686. {
  687. struct dw_mci *host = (struct dw_mci *)priv;
  688. struct mmc_data *data;
  689. struct mmc_command *cmd;
  690. enum dw_mci_state state;
  691. enum dw_mci_state prev_state;
  692. u32 status;
  693. spin_lock(&host->lock);
  694. state = host->state;
  695. data = host->data;
  696. do {
  697. prev_state = state;
  698. switch (state) {
  699. case STATE_IDLE:
  700. break;
  701. case STATE_SENDING_CMD:
  702. if (!test_and_clear_bit(EVENT_CMD_COMPLETE,
  703. &host->pending_events))
  704. break;
  705. cmd = host->cmd;
  706. host->cmd = NULL;
  707. set_bit(EVENT_CMD_COMPLETE, &host->completed_events);
  708. dw_mci_command_complete(host, host->mrq->cmd);
  709. if (!host->mrq->data || cmd->error) {
  710. dw_mci_request_end(host, host->mrq);
  711. goto unlock;
  712. }
  713. prev_state = state = STATE_SENDING_DATA;
  714. /* fall through */
  715. case STATE_SENDING_DATA:
  716. if (test_and_clear_bit(EVENT_DATA_ERROR,
  717. &host->pending_events)) {
  718. dw_mci_stop_dma(host);
  719. if (data->stop)
  720. send_stop_cmd(host, data);
  721. state = STATE_DATA_ERROR;
  722. break;
  723. }
  724. if (!test_and_clear_bit(EVENT_XFER_COMPLETE,
  725. &host->pending_events))
  726. break;
  727. set_bit(EVENT_XFER_COMPLETE, &host->completed_events);
  728. prev_state = state = STATE_DATA_BUSY;
  729. /* fall through */
  730. case STATE_DATA_BUSY:
  731. if (!test_and_clear_bit(EVENT_DATA_COMPLETE,
  732. &host->pending_events))
  733. break;
  734. host->data = NULL;
  735. set_bit(EVENT_DATA_COMPLETE, &host->completed_events);
  736. status = host->data_status;
  737. if (status & DW_MCI_DATA_ERROR_FLAGS) {
  738. if (status & SDMMC_INT_DTO) {
  739. dev_err(&host->pdev->dev,
  740. "data timeout error\n");
  741. data->error = -ETIMEDOUT;
  742. } else if (status & SDMMC_INT_DCRC) {
  743. dev_err(&host->pdev->dev,
  744. "data CRC error\n");
  745. data->error = -EILSEQ;
  746. } else {
  747. dev_err(&host->pdev->dev,
  748. "data FIFO error "
  749. "(status=%08x)\n",
  750. status);
  751. data->error = -EIO;
  752. }
  753. } else {
  754. data->bytes_xfered = data->blocks * data->blksz;
  755. data->error = 0;
  756. }
  757. if (!data->stop) {
  758. dw_mci_request_end(host, host->mrq);
  759. goto unlock;
  760. }
  761. prev_state = state = STATE_SENDING_STOP;
  762. if (!data->error)
  763. send_stop_cmd(host, data);
  764. /* fall through */
  765. case STATE_SENDING_STOP:
  766. if (!test_and_clear_bit(EVENT_CMD_COMPLETE,
  767. &host->pending_events))
  768. break;
  769. host->cmd = NULL;
  770. dw_mci_command_complete(host, host->mrq->stop);
  771. dw_mci_request_end(host, host->mrq);
  772. goto unlock;
  773. case STATE_DATA_ERROR:
  774. if (!test_and_clear_bit(EVENT_XFER_COMPLETE,
  775. &host->pending_events))
  776. break;
  777. state = STATE_DATA_BUSY;
  778. break;
  779. }
  780. } while (state != prev_state);
  781. host->state = state;
  782. unlock:
  783. spin_unlock(&host->lock);
  784. }
  785. static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
  786. {
  787. u16 *pdata = (u16 *)buf;
  788. WARN_ON(cnt % 2 != 0);
  789. cnt = cnt >> 1;
  790. while (cnt > 0) {
  791. mci_writew(host, DATA, *pdata++);
  792. cnt--;
  793. }
  794. }
  795. static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
  796. {
  797. u16 *pdata = (u16 *)buf;
  798. WARN_ON(cnt % 2 != 0);
  799. cnt = cnt >> 1;
  800. while (cnt > 0) {
  801. *pdata++ = mci_readw(host, DATA);
  802. cnt--;
  803. }
  804. }
  805. static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
  806. {
  807. u32 *pdata = (u32 *)buf;
  808. WARN_ON(cnt % 4 != 0);
  809. WARN_ON((unsigned long)pdata & 0x3);
  810. cnt = cnt >> 2;
  811. while (cnt > 0) {
  812. mci_writel(host, DATA, *pdata++);
  813. cnt--;
  814. }
  815. }
  816. static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
  817. {
  818. u32 *pdata = (u32 *)buf;
  819. WARN_ON(cnt % 4 != 0);
  820. WARN_ON((unsigned long)pdata & 0x3);
  821. cnt = cnt >> 2;
  822. while (cnt > 0) {
  823. *pdata++ = mci_readl(host, DATA);
  824. cnt--;
  825. }
  826. }
  827. static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
  828. {
  829. u64 *pdata = (u64 *)buf;
  830. WARN_ON(cnt % 8 != 0);
  831. cnt = cnt >> 3;
  832. while (cnt > 0) {
  833. mci_writeq(host, DATA, *pdata++);
  834. cnt--;
  835. }
  836. }
  837. static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
  838. {
  839. u64 *pdata = (u64 *)buf;
  840. WARN_ON(cnt % 8 != 0);
  841. cnt = cnt >> 3;
  842. while (cnt > 0) {
  843. *pdata++ = mci_readq(host, DATA);
  844. cnt--;
  845. }
  846. }
  847. static void dw_mci_read_data_pio(struct dw_mci *host)
  848. {
  849. struct scatterlist *sg = host->sg;
  850. void *buf = sg_virt(sg);
  851. unsigned int offset = host->pio_offset;
  852. struct mmc_data *data = host->data;
  853. int shift = host->data_shift;
  854. u32 status;
  855. unsigned int nbytes = 0, len;
  856. do {
  857. len = SDMMC_GET_FCNT(mci_readl(host, STATUS)) << shift;
  858. if (offset + len <= sg->length) {
  859. host->pull_data(host, (void *)(buf + offset), len);
  860. offset += len;
  861. nbytes += len;
  862. if (offset == sg->length) {
  863. flush_dcache_page(sg_page(sg));
  864. host->sg = sg = sg_next(sg);
  865. if (!sg)
  866. goto done;
  867. offset = 0;
  868. buf = sg_virt(sg);
  869. }
  870. } else {
  871. unsigned int remaining = sg->length - offset;
  872. host->pull_data(host, (void *)(buf + offset),
  873. remaining);
  874. nbytes += remaining;
  875. flush_dcache_page(sg_page(sg));
  876. host->sg = sg = sg_next(sg);
  877. if (!sg)
  878. goto done;
  879. offset = len - remaining;
  880. buf = sg_virt(sg);
  881. host->pull_data(host, buf, offset);
  882. nbytes += offset;
  883. }
  884. status = mci_readl(host, MINTSTS);
  885. mci_writel(host, RINTSTS, SDMMC_INT_RXDR);
  886. if (status & DW_MCI_DATA_ERROR_FLAGS) {
  887. host->data_status = status;
  888. data->bytes_xfered += nbytes;
  889. smp_wmb();
  890. set_bit(EVENT_DATA_ERROR, &host->pending_events);
  891. tasklet_schedule(&host->tasklet);
  892. return;
  893. }
  894. } while (status & SDMMC_INT_RXDR); /*if the RXDR is ready read again*/
  895. len = SDMMC_GET_FCNT(mci_readl(host, STATUS));
  896. host->pio_offset = offset;
  897. data->bytes_xfered += nbytes;
  898. return;
  899. done:
  900. data->bytes_xfered += nbytes;
  901. smp_wmb();
  902. set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
  903. }
  904. static void dw_mci_write_data_pio(struct dw_mci *host)
  905. {
  906. struct scatterlist *sg = host->sg;
  907. void *buf = sg_virt(sg);
  908. unsigned int offset = host->pio_offset;
  909. struct mmc_data *data = host->data;
  910. int shift = host->data_shift;
  911. u32 status;
  912. unsigned int nbytes = 0, len;
  913. do {
  914. len = SDMMC_FIFO_SZ -
  915. (SDMMC_GET_FCNT(mci_readl(host, STATUS)) << shift);
  916. if (offset + len <= sg->length) {
  917. host->push_data(host, (void *)(buf + offset), len);
  918. offset += len;
  919. nbytes += len;
  920. if (offset == sg->length) {
  921. host->sg = sg = sg_next(sg);
  922. if (!sg)
  923. goto done;
  924. offset = 0;
  925. buf = sg_virt(sg);
  926. }
  927. } else {
  928. unsigned int remaining = sg->length - offset;
  929. host->push_data(host, (void *)(buf + offset),
  930. remaining);
  931. nbytes += remaining;
  932. host->sg = sg = sg_next(sg);
  933. if (!sg)
  934. goto done;
  935. offset = len - remaining;
  936. buf = sg_virt(sg);
  937. host->push_data(host, (void *)buf, offset);
  938. nbytes += offset;
  939. }
  940. status = mci_readl(host, MINTSTS);
  941. mci_writel(host, RINTSTS, SDMMC_INT_TXDR);
  942. if (status & DW_MCI_DATA_ERROR_FLAGS) {
  943. host->data_status = status;
  944. data->bytes_xfered += nbytes;
  945. smp_wmb();
  946. set_bit(EVENT_DATA_ERROR, &host->pending_events);
  947. tasklet_schedule(&host->tasklet);
  948. return;
  949. }
  950. } while (status & SDMMC_INT_TXDR); /* if TXDR write again */
  951. host->pio_offset = offset;
  952. data->bytes_xfered += nbytes;
  953. return;
  954. done:
  955. data->bytes_xfered += nbytes;
  956. smp_wmb();
  957. set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
  958. }
  959. static void dw_mci_cmd_interrupt(struct dw_mci *host, u32 status)
  960. {
  961. if (!host->cmd_status)
  962. host->cmd_status = status;
  963. smp_wmb();
  964. set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
  965. tasklet_schedule(&host->tasklet);
  966. }
  967. static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
  968. {
  969. struct dw_mci *host = dev_id;
  970. u32 status, pending;
  971. unsigned int pass_count = 0;
  972. do {
  973. status = mci_readl(host, RINTSTS);
  974. pending = mci_readl(host, MINTSTS); /* read-only mask reg */
  975. /*
  976. * DTO fix - version 2.10a and below, and only if internal DMA
  977. * is configured.
  978. */
  979. if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO) {
  980. if (!pending &&
  981. ((mci_readl(host, STATUS) >> 17) & 0x1fff))
  982. pending |= SDMMC_INT_DATA_OVER;
  983. }
  984. if (!pending)
  985. break;
  986. if (pending & DW_MCI_CMD_ERROR_FLAGS) {
  987. mci_writel(host, RINTSTS, DW_MCI_CMD_ERROR_FLAGS);
  988. host->cmd_status = status;
  989. smp_wmb();
  990. set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
  991. }
  992. if (pending & DW_MCI_DATA_ERROR_FLAGS) {
  993. /* if there is an error report DATA_ERROR */
  994. mci_writel(host, RINTSTS, DW_MCI_DATA_ERROR_FLAGS);
  995. host->data_status = status;
  996. smp_wmb();
  997. set_bit(EVENT_DATA_ERROR, &host->pending_events);
  998. if (!(pending & (SDMMC_INT_DTO | SDMMC_INT_DCRC |
  999. SDMMC_INT_SBE | SDMMC_INT_EBE)))
  1000. tasklet_schedule(&host->tasklet);
  1001. }
  1002. if (pending & SDMMC_INT_DATA_OVER) {
  1003. mci_writel(host, RINTSTS, SDMMC_INT_DATA_OVER);
  1004. if (!host->data_status)
  1005. host->data_status = status;
  1006. smp_wmb();
  1007. if (host->dir_status == DW_MCI_RECV_STATUS) {
  1008. if (host->sg != NULL)
  1009. dw_mci_read_data_pio(host);
  1010. }
  1011. set_bit(EVENT_DATA_COMPLETE, &host->pending_events);
  1012. tasklet_schedule(&host->tasklet);
  1013. }
  1014. if (pending & SDMMC_INT_RXDR) {
  1015. mci_writel(host, RINTSTS, SDMMC_INT_RXDR);
  1016. if (host->dir_status == DW_MCI_RECV_STATUS && host->sg)
  1017. dw_mci_read_data_pio(host);
  1018. }
  1019. if (pending & SDMMC_INT_TXDR) {
  1020. mci_writel(host, RINTSTS, SDMMC_INT_TXDR);
  1021. if (host->dir_status == DW_MCI_SEND_STATUS && host->sg)
  1022. dw_mci_write_data_pio(host);
  1023. }
  1024. if (pending & SDMMC_INT_CMD_DONE) {
  1025. mci_writel(host, RINTSTS, SDMMC_INT_CMD_DONE);
  1026. dw_mci_cmd_interrupt(host, status);
  1027. }
  1028. if (pending & SDMMC_INT_CD) {
  1029. mci_writel(host, RINTSTS, SDMMC_INT_CD);
  1030. queue_work(dw_mci_card_workqueue, &host->card_work);
  1031. }
  1032. } while (pass_count++ < 5);
  1033. #ifdef CONFIG_MMC_DW_IDMAC
  1034. /* Handle DMA interrupts */
  1035. pending = mci_readl(host, IDSTS);
  1036. if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) {
  1037. mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI);
  1038. mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI);
  1039. set_bit(EVENT_DATA_COMPLETE, &host->pending_events);
  1040. host->dma_ops->complete(host);
  1041. }
  1042. #endif
  1043. return IRQ_HANDLED;
  1044. }
  1045. static void dw_mci_work_routine_card(struct work_struct *work)
  1046. {
  1047. struct dw_mci *host = container_of(work, struct dw_mci, card_work);
  1048. int i;
  1049. for (i = 0; i < host->num_slots; i++) {
  1050. struct dw_mci_slot *slot = host->slot[i];
  1051. struct mmc_host *mmc = slot->mmc;
  1052. struct mmc_request *mrq;
  1053. int present;
  1054. u32 ctrl;
  1055. present = dw_mci_get_cd(mmc);
  1056. while (present != slot->last_detect_state) {
  1057. dev_dbg(&slot->mmc->class_dev, "card %s\n",
  1058. present ? "inserted" : "removed");
  1059. /* Power up slot (before spin_lock, may sleep) */
  1060. if (present != 0 && host->pdata->setpower)
  1061. host->pdata->setpower(slot->id, mmc->ocr_avail);
  1062. spin_lock_bh(&host->lock);
  1063. /* Card change detected */
  1064. slot->last_detect_state = present;
  1065. /* Mark card as present if applicable */
  1066. if (present != 0)
  1067. set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
  1068. /* Clean up queue if present */
  1069. mrq = slot->mrq;
  1070. if (mrq) {
  1071. if (mrq == host->mrq) {
  1072. host->data = NULL;
  1073. host->cmd = NULL;
  1074. switch (host->state) {
  1075. case STATE_IDLE:
  1076. break;
  1077. case STATE_SENDING_CMD:
  1078. mrq->cmd->error = -ENOMEDIUM;
  1079. if (!mrq->data)
  1080. break;
  1081. /* fall through */
  1082. case STATE_SENDING_DATA:
  1083. mrq->data->error = -ENOMEDIUM;
  1084. dw_mci_stop_dma(host);
  1085. break;
  1086. case STATE_DATA_BUSY:
  1087. case STATE_DATA_ERROR:
  1088. if (mrq->data->error == -EINPROGRESS)
  1089. mrq->data->error = -ENOMEDIUM;
  1090. if (!mrq->stop)
  1091. break;
  1092. /* fall through */
  1093. case STATE_SENDING_STOP:
  1094. mrq->stop->error = -ENOMEDIUM;
  1095. break;
  1096. }
  1097. dw_mci_request_end(host, mrq);
  1098. } else {
  1099. list_del(&slot->queue_node);
  1100. mrq->cmd->error = -ENOMEDIUM;
  1101. if (mrq->data)
  1102. mrq->data->error = -ENOMEDIUM;
  1103. if (mrq->stop)
  1104. mrq->stop->error = -ENOMEDIUM;
  1105. spin_unlock(&host->lock);
  1106. mmc_request_done(slot->mmc, mrq);
  1107. spin_lock(&host->lock);
  1108. }
  1109. }
  1110. /* Power down slot */
  1111. if (present == 0) {
  1112. clear_bit(DW_MMC_CARD_PRESENT, &slot->flags);
  1113. /*
  1114. * Clear down the FIFO - doing so generates a
  1115. * block interrupt, hence setting the
  1116. * scatter-gather pointer to NULL.
  1117. */
  1118. host->sg = NULL;
  1119. ctrl = mci_readl(host, CTRL);
  1120. ctrl |= SDMMC_CTRL_FIFO_RESET;
  1121. mci_writel(host, CTRL, ctrl);
  1122. #ifdef CONFIG_MMC_DW_IDMAC
  1123. ctrl = mci_readl(host, BMOD);
  1124. ctrl |= 0x01; /* Software reset of DMA */
  1125. mci_writel(host, BMOD, ctrl);
  1126. #endif
  1127. }
  1128. spin_unlock_bh(&host->lock);
  1129. /* Power down slot (after spin_unlock, may sleep) */
  1130. if (present == 0 && host->pdata->setpower)
  1131. host->pdata->setpower(slot->id, 0);
  1132. present = dw_mci_get_cd(mmc);
  1133. }
  1134. mmc_detect_change(slot->mmc,
  1135. msecs_to_jiffies(host->pdata->detect_delay_ms));
  1136. }
  1137. }
  1138. static int __init dw_mci_init_slot(struct dw_mci *host, unsigned int id)
  1139. {
  1140. struct mmc_host *mmc;
  1141. struct dw_mci_slot *slot;
  1142. mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), &host->pdev->dev);
  1143. if (!mmc)
  1144. return -ENOMEM;
  1145. slot = mmc_priv(mmc);
  1146. slot->id = id;
  1147. slot->mmc = mmc;
  1148. slot->host = host;
  1149. mmc->ops = &dw_mci_ops;
  1150. mmc->f_min = DIV_ROUND_UP(host->bus_hz, 510);
  1151. mmc->f_max = host->bus_hz;
  1152. if (host->pdata->get_ocr)
  1153. mmc->ocr_avail = host->pdata->get_ocr(id);
  1154. else
  1155. mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
  1156. /*
  1157. * Start with slot power disabled, it will be enabled when a card
  1158. * is detected.
  1159. */
  1160. if (host->pdata->setpower)
  1161. host->pdata->setpower(id, 0);
  1162. if (host->pdata->caps)
  1163. mmc->caps = host->pdata->caps;
  1164. else
  1165. mmc->caps = 0;
  1166. if (host->pdata->get_bus_wd)
  1167. if (host->pdata->get_bus_wd(slot->id) >= 4)
  1168. mmc->caps |= MMC_CAP_4_BIT_DATA;
  1169. if (host->pdata->quirks & DW_MCI_QUIRK_HIGHSPEED)
  1170. mmc->caps |= MMC_CAP_SD_HIGHSPEED;
  1171. #ifdef CONFIG_MMC_DW_IDMAC
  1172. mmc->max_segs = host->ring_size;
  1173. mmc->max_blk_size = 65536;
  1174. mmc->max_blk_count = host->ring_size;
  1175. mmc->max_seg_size = 0x1000;
  1176. mmc->max_req_size = mmc->max_seg_size * mmc->max_blk_count;
  1177. #else
  1178. if (host->pdata->blk_settings) {
  1179. mmc->max_segs = host->pdata->blk_settings->max_segs;
  1180. mmc->max_blk_size = host->pdata->blk_settings->max_blk_size;
  1181. mmc->max_blk_count = host->pdata->blk_settings->max_blk_count;
  1182. mmc->max_req_size = host->pdata->blk_settings->max_req_size;
  1183. mmc->max_seg_size = host->pdata->blk_settings->max_seg_size;
  1184. } else {
  1185. /* Useful defaults if platform data is unset. */
  1186. mmc->max_segs = 64;
  1187. mmc->max_blk_size = 65536; /* BLKSIZ is 16 bits */
  1188. mmc->max_blk_count = 512;
  1189. mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
  1190. mmc->max_seg_size = mmc->max_req_size;
  1191. }
  1192. #endif /* CONFIG_MMC_DW_IDMAC */
  1193. host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
  1194. if (IS_ERR(host->vmmc)) {
  1195. printk(KERN_INFO "%s: no vmmc regulator found\n", mmc_hostname(mmc));
  1196. host->vmmc = NULL;
  1197. } else
  1198. regulator_enable(host->vmmc);
  1199. if (dw_mci_get_cd(mmc))
  1200. set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
  1201. else
  1202. clear_bit(DW_MMC_CARD_PRESENT, &slot->flags);
  1203. host->slot[id] = slot;
  1204. mmc_add_host(mmc);
  1205. #if defined(CONFIG_DEBUG_FS)
  1206. dw_mci_init_debugfs(slot);
  1207. #endif
  1208. /* Card initially undetected */
  1209. slot->last_detect_state = 0;
  1210. /*
  1211. * Card may have been plugged in prior to boot so we
  1212. * need to run the detect tasklet
  1213. */
  1214. queue_work(dw_mci_card_workqueue, &host->card_work);
  1215. return 0;
  1216. }
  1217. static void dw_mci_cleanup_slot(struct dw_mci_slot *slot, unsigned int id)
  1218. {
  1219. /* Shutdown detect IRQ */
  1220. if (slot->host->pdata->exit)
  1221. slot->host->pdata->exit(id);
  1222. /* Debugfs stuff is cleaned up by mmc core */
  1223. mmc_remove_host(slot->mmc);
  1224. slot->host->slot[id] = NULL;
  1225. mmc_free_host(slot->mmc);
  1226. }
  1227. static void dw_mci_init_dma(struct dw_mci *host)
  1228. {
  1229. /* Alloc memory for sg translation */
  1230. host->sg_cpu = dma_alloc_coherent(&host->pdev->dev, PAGE_SIZE,
  1231. &host->sg_dma, GFP_KERNEL);
  1232. if (!host->sg_cpu) {
  1233. dev_err(&host->pdev->dev, "%s: could not alloc DMA memory\n",
  1234. __func__);
  1235. goto no_dma;
  1236. }
  1237. /* Determine which DMA interface to use */
  1238. #ifdef CONFIG_MMC_DW_IDMAC
  1239. host->dma_ops = &dw_mci_idmac_ops;
  1240. dev_info(&host->pdev->dev, "Using internal DMA controller.\n");
  1241. #endif
  1242. if (!host->dma_ops)
  1243. goto no_dma;
  1244. if (host->dma_ops->init) {
  1245. if (host->dma_ops->init(host)) {
  1246. dev_err(&host->pdev->dev, "%s: Unable to initialize "
  1247. "DMA Controller.\n", __func__);
  1248. goto no_dma;
  1249. }
  1250. } else {
  1251. dev_err(&host->pdev->dev, "DMA initialization not found.\n");
  1252. goto no_dma;
  1253. }
  1254. host->use_dma = 1;
  1255. return;
  1256. no_dma:
  1257. dev_info(&host->pdev->dev, "Using PIO mode.\n");
  1258. host->use_dma = 0;
  1259. return;
  1260. }
  1261. static bool mci_wait_reset(struct device *dev, struct dw_mci *host)
  1262. {
  1263. unsigned long timeout = jiffies + msecs_to_jiffies(500);
  1264. unsigned int ctrl;
  1265. mci_writel(host, CTRL, (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET |
  1266. SDMMC_CTRL_DMA_RESET));
  1267. /* wait till resets clear */
  1268. do {
  1269. ctrl = mci_readl(host, CTRL);
  1270. if (!(ctrl & (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET |
  1271. SDMMC_CTRL_DMA_RESET)))
  1272. return true;
  1273. } while (time_before(jiffies, timeout));
  1274. dev_err(dev, "Timeout resetting block (ctrl %#x)\n", ctrl);
  1275. return false;
  1276. }
  1277. static int dw_mci_probe(struct platform_device *pdev)
  1278. {
  1279. struct dw_mci *host;
  1280. struct resource *regs;
  1281. struct dw_mci_board *pdata;
  1282. int irq, ret, i, width;
  1283. u32 fifo_size;
  1284. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1285. if (!regs)
  1286. return -ENXIO;
  1287. irq = platform_get_irq(pdev, 0);
  1288. if (irq < 0)
  1289. return irq;
  1290. host = kzalloc(sizeof(struct dw_mci), GFP_KERNEL);
  1291. if (!host)
  1292. return -ENOMEM;
  1293. host->pdev = pdev;
  1294. host->pdata = pdata = pdev->dev.platform_data;
  1295. if (!pdata || !pdata->init) {
  1296. dev_err(&pdev->dev,
  1297. "Platform data must supply init function\n");
  1298. ret = -ENODEV;
  1299. goto err_freehost;
  1300. }
  1301. if (!pdata->select_slot && pdata->num_slots > 1) {
  1302. dev_err(&pdev->dev,
  1303. "Platform data must supply select_slot function\n");
  1304. ret = -ENODEV;
  1305. goto err_freehost;
  1306. }
  1307. if (!pdata->bus_hz) {
  1308. dev_err(&pdev->dev,
  1309. "Platform data must supply bus speed\n");
  1310. ret = -ENODEV;
  1311. goto err_freehost;
  1312. }
  1313. host->bus_hz = pdata->bus_hz;
  1314. host->quirks = pdata->quirks;
  1315. spin_lock_init(&host->lock);
  1316. INIT_LIST_HEAD(&host->queue);
  1317. ret = -ENOMEM;
  1318. host->regs = ioremap(regs->start, regs->end - regs->start + 1);
  1319. if (!host->regs)
  1320. goto err_freehost;
  1321. host->dma_ops = pdata->dma_ops;
  1322. dw_mci_init_dma(host);
  1323. /*
  1324. * Get the host data width - this assumes that HCON has been set with
  1325. * the correct values.
  1326. */
  1327. i = (mci_readl(host, HCON) >> 7) & 0x7;
  1328. if (!i) {
  1329. host->push_data = dw_mci_push_data16;
  1330. host->pull_data = dw_mci_pull_data16;
  1331. width = 16;
  1332. host->data_shift = 1;
  1333. } else if (i == 2) {
  1334. host->push_data = dw_mci_push_data64;
  1335. host->pull_data = dw_mci_pull_data64;
  1336. width = 64;
  1337. host->data_shift = 3;
  1338. } else {
  1339. /* Check for a reserved value, and warn if it is */
  1340. WARN((i != 1),
  1341. "HCON reports a reserved host data width!\n"
  1342. "Defaulting to 32-bit access.\n");
  1343. host->push_data = dw_mci_push_data32;
  1344. host->pull_data = dw_mci_pull_data32;
  1345. width = 32;
  1346. host->data_shift = 2;
  1347. }
  1348. /* Reset all blocks */
  1349. if (!mci_wait_reset(&pdev->dev, host)) {
  1350. ret = -ENODEV;
  1351. goto err_dmaunmap;
  1352. }
  1353. /* Clear the interrupts for the host controller */
  1354. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  1355. mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
  1356. /* Put in max timeout */
  1357. mci_writel(host, TMOUT, 0xFFFFFFFF);
  1358. /*
  1359. * FIFO threshold settings RxMark = fifo_size / 2 - 1,
  1360. * Tx Mark = fifo_size / 2 DMA Size = 8
  1361. */
  1362. fifo_size = mci_readl(host, FIFOTH);
  1363. fifo_size = (fifo_size >> 16) & 0x7ff;
  1364. host->fifoth_val = ((0x2 << 28) | ((fifo_size/2 - 1) << 16) |
  1365. ((fifo_size/2) << 0));
  1366. mci_writel(host, FIFOTH, host->fifoth_val);
  1367. /* disable clock to CIU */
  1368. mci_writel(host, CLKENA, 0);
  1369. mci_writel(host, CLKSRC, 0);
  1370. tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host);
  1371. dw_mci_card_workqueue = alloc_workqueue("dw-mci-card",
  1372. WQ_MEM_RECLAIM | WQ_NON_REENTRANT, 1);
  1373. if (!dw_mci_card_workqueue)
  1374. goto err_dmaunmap;
  1375. INIT_WORK(&host->card_work, dw_mci_work_routine_card);
  1376. ret = request_irq(irq, dw_mci_interrupt, 0, "dw-mci", host);
  1377. if (ret)
  1378. goto err_workqueue;
  1379. platform_set_drvdata(pdev, host);
  1380. if (host->pdata->num_slots)
  1381. host->num_slots = host->pdata->num_slots;
  1382. else
  1383. host->num_slots = ((mci_readl(host, HCON) >> 1) & 0x1F) + 1;
  1384. /* We need at least one slot to succeed */
  1385. for (i = 0; i < host->num_slots; i++) {
  1386. ret = dw_mci_init_slot(host, i);
  1387. if (ret) {
  1388. ret = -ENODEV;
  1389. goto err_init_slot;
  1390. }
  1391. }
  1392. /*
  1393. * Enable interrupts for command done, data over, data empty, card det,
  1394. * receive ready and error such as transmit, receive timeout, crc error
  1395. */
  1396. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  1397. mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
  1398. SDMMC_INT_TXDR | SDMMC_INT_RXDR |
  1399. DW_MCI_ERROR_FLAGS | SDMMC_INT_CD);
  1400. mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); /* Enable mci interrupt */
  1401. dev_info(&pdev->dev, "DW MMC controller at irq %d, "
  1402. "%d bit host data width\n", irq, width);
  1403. if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO)
  1404. dev_info(&pdev->dev, "Internal DMAC interrupt fix enabled.\n");
  1405. return 0;
  1406. err_init_slot:
  1407. /* De-init any initialized slots */
  1408. while (i > 0) {
  1409. if (host->slot[i])
  1410. dw_mci_cleanup_slot(host->slot[i], i);
  1411. i--;
  1412. }
  1413. free_irq(irq, host);
  1414. err_workqueue:
  1415. destroy_workqueue(dw_mci_card_workqueue);
  1416. err_dmaunmap:
  1417. if (host->use_dma && host->dma_ops->exit)
  1418. host->dma_ops->exit(host);
  1419. dma_free_coherent(&host->pdev->dev, PAGE_SIZE,
  1420. host->sg_cpu, host->sg_dma);
  1421. iounmap(host->regs);
  1422. if (host->vmmc) {
  1423. regulator_disable(host->vmmc);
  1424. regulator_put(host->vmmc);
  1425. }
  1426. err_freehost:
  1427. kfree(host);
  1428. return ret;
  1429. }
  1430. static int __exit dw_mci_remove(struct platform_device *pdev)
  1431. {
  1432. struct dw_mci *host = platform_get_drvdata(pdev);
  1433. int i;
  1434. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  1435. mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
  1436. platform_set_drvdata(pdev, NULL);
  1437. for (i = 0; i < host->num_slots; i++) {
  1438. dev_dbg(&pdev->dev, "remove slot %d\n", i);
  1439. if (host->slot[i])
  1440. dw_mci_cleanup_slot(host->slot[i], i);
  1441. }
  1442. /* disable clock to CIU */
  1443. mci_writel(host, CLKENA, 0);
  1444. mci_writel(host, CLKSRC, 0);
  1445. free_irq(platform_get_irq(pdev, 0), host);
  1446. destroy_workqueue(dw_mci_card_workqueue);
  1447. dma_free_coherent(&pdev->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma);
  1448. if (host->use_dma && host->dma_ops->exit)
  1449. host->dma_ops->exit(host);
  1450. if (host->vmmc) {
  1451. regulator_disable(host->vmmc);
  1452. regulator_put(host->vmmc);
  1453. }
  1454. iounmap(host->regs);
  1455. kfree(host);
  1456. return 0;
  1457. }
  1458. #ifdef CONFIG_PM
  1459. /*
  1460. * TODO: we should probably disable the clock to the card in the suspend path.
  1461. */
  1462. static int dw_mci_suspend(struct platform_device *pdev, pm_message_t mesg)
  1463. {
  1464. int i, ret;
  1465. struct dw_mci *host = platform_get_drvdata(pdev);
  1466. for (i = 0; i < host->num_slots; i++) {
  1467. struct dw_mci_slot *slot = host->slot[i];
  1468. if (!slot)
  1469. continue;
  1470. ret = mmc_suspend_host(slot->mmc);
  1471. if (ret < 0) {
  1472. while (--i >= 0) {
  1473. slot = host->slot[i];
  1474. if (slot)
  1475. mmc_resume_host(host->slot[i]->mmc);
  1476. }
  1477. return ret;
  1478. }
  1479. }
  1480. if (host->vmmc)
  1481. regulator_disable(host->vmmc);
  1482. return 0;
  1483. }
  1484. static int dw_mci_resume(struct platform_device *pdev)
  1485. {
  1486. int i, ret;
  1487. struct dw_mci *host = platform_get_drvdata(pdev);
  1488. if (host->vmmc)
  1489. regulator_enable(host->vmmc);
  1490. if (host->dma_ops->init)
  1491. host->dma_ops->init(host);
  1492. if (!mci_wait_reset(&pdev->dev, host)) {
  1493. ret = -ENODEV;
  1494. return ret;
  1495. }
  1496. /* Restore the old value at FIFOTH register */
  1497. mci_writel(host, FIFOTH, host->fifoth_val);
  1498. mci_writel(host, RINTSTS, 0xFFFFFFFF);
  1499. mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
  1500. SDMMC_INT_TXDR | SDMMC_INT_RXDR |
  1501. DW_MCI_ERROR_FLAGS | SDMMC_INT_CD);
  1502. mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE);
  1503. for (i = 0; i < host->num_slots; i++) {
  1504. struct dw_mci_slot *slot = host->slot[i];
  1505. if (!slot)
  1506. continue;
  1507. ret = mmc_resume_host(host->slot[i]->mmc);
  1508. if (ret < 0)
  1509. return ret;
  1510. }
  1511. return 0;
  1512. }
  1513. #else
  1514. #define dw_mci_suspend NULL
  1515. #define dw_mci_resume NULL
  1516. #endif /* CONFIG_PM */
  1517. static struct platform_driver dw_mci_driver = {
  1518. .remove = __exit_p(dw_mci_remove),
  1519. .suspend = dw_mci_suspend,
  1520. .resume = dw_mci_resume,
  1521. .driver = {
  1522. .name = "dw_mmc",
  1523. },
  1524. };
  1525. static int __init dw_mci_init(void)
  1526. {
  1527. return platform_driver_probe(&dw_mci_driver, dw_mci_probe);
  1528. }
  1529. static void __exit dw_mci_exit(void)
  1530. {
  1531. platform_driver_unregister(&dw_mci_driver);
  1532. }
  1533. module_init(dw_mci_init);
  1534. module_exit(dw_mci_exit);
  1535. MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
  1536. MODULE_AUTHOR("NXP Semiconductor VietNam");
  1537. MODULE_AUTHOR("Imagination Technologies Ltd");
  1538. MODULE_LICENSE("GPL v2");