s3cmci.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877
  1. /*
  2. * linux/drivers/mmc/s3cmci.h - Samsung S3C MCI driver
  3. *
  4. * Copyright (C) 2004-2006 maintech GmbH, Thomas Kleffel <tk@maintech.de>
  5. *
  6. * Current driver maintained by Ben Dooks and Simtec Electronics
  7. * Copyright (C) 2008 Simtec Electronics <ben-linux@fluff.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/dmaengine.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/clk.h>
  17. #include <linux/mmc/host.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/cpufreq.h>
  20. #include <linux/debugfs.h>
  21. #include <linux/seq_file.h>
  22. #include <linux/gpio.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/irq.h>
  25. #include <linux/io.h>
  26. #include <linux/of.h>
  27. #include <linux/of_device.h>
  28. #include <linux/of_gpio.h>
  29. #include <linux/mmc/slot-gpio.h>
  30. #include <plat/gpio-cfg.h>
  31. #include <mach/dma.h>
  32. #include <mach/gpio-samsung.h>
  33. #include <linux/platform_data/mmc-s3cmci.h>
  34. #include "s3cmci.h"
  35. #define DRIVER_NAME "s3c-mci"
  36. #define S3C2410_SDICON (0x00)
  37. #define S3C2410_SDIPRE (0x04)
  38. #define S3C2410_SDICMDARG (0x08)
  39. #define S3C2410_SDICMDCON (0x0C)
  40. #define S3C2410_SDICMDSTAT (0x10)
  41. #define S3C2410_SDIRSP0 (0x14)
  42. #define S3C2410_SDIRSP1 (0x18)
  43. #define S3C2410_SDIRSP2 (0x1C)
  44. #define S3C2410_SDIRSP3 (0x20)
  45. #define S3C2410_SDITIMER (0x24)
  46. #define S3C2410_SDIBSIZE (0x28)
  47. #define S3C2410_SDIDCON (0x2C)
  48. #define S3C2410_SDIDCNT (0x30)
  49. #define S3C2410_SDIDSTA (0x34)
  50. #define S3C2410_SDIFSTA (0x38)
  51. #define S3C2410_SDIDATA (0x3C)
  52. #define S3C2410_SDIIMSK (0x40)
  53. #define S3C2440_SDIDATA (0x40)
  54. #define S3C2440_SDIIMSK (0x3C)
  55. #define S3C2440_SDICON_SDRESET (1 << 8)
  56. #define S3C2410_SDICON_SDIOIRQ (1 << 3)
  57. #define S3C2410_SDICON_FIFORESET (1 << 1)
  58. #define S3C2410_SDICON_CLOCKTYPE (1 << 0)
  59. #define S3C2410_SDICMDCON_LONGRSP (1 << 10)
  60. #define S3C2410_SDICMDCON_WAITRSP (1 << 9)
  61. #define S3C2410_SDICMDCON_CMDSTART (1 << 8)
  62. #define S3C2410_SDICMDCON_SENDERHOST (1 << 6)
  63. #define S3C2410_SDICMDCON_INDEX (0x3f)
  64. #define S3C2410_SDICMDSTAT_CRCFAIL (1 << 12)
  65. #define S3C2410_SDICMDSTAT_CMDSENT (1 << 11)
  66. #define S3C2410_SDICMDSTAT_CMDTIMEOUT (1 << 10)
  67. #define S3C2410_SDICMDSTAT_RSPFIN (1 << 9)
  68. #define S3C2440_SDIDCON_DS_WORD (2 << 22)
  69. #define S3C2410_SDIDCON_TXAFTERRESP (1 << 20)
  70. #define S3C2410_SDIDCON_RXAFTERCMD (1 << 19)
  71. #define S3C2410_SDIDCON_BLOCKMODE (1 << 17)
  72. #define S3C2410_SDIDCON_WIDEBUS (1 << 16)
  73. #define S3C2410_SDIDCON_DMAEN (1 << 15)
  74. #define S3C2410_SDIDCON_STOP (1 << 14)
  75. #define S3C2440_SDIDCON_DATSTART (1 << 14)
  76. #define S3C2410_SDIDCON_XFER_RXSTART (2 << 12)
  77. #define S3C2410_SDIDCON_XFER_TXSTART (3 << 12)
  78. #define S3C2410_SDIDCON_BLKNUM_MASK (0xFFF)
  79. #define S3C2410_SDIDSTA_SDIOIRQDETECT (1 << 9)
  80. #define S3C2410_SDIDSTA_FIFOFAIL (1 << 8)
  81. #define S3C2410_SDIDSTA_CRCFAIL (1 << 7)
  82. #define S3C2410_SDIDSTA_RXCRCFAIL (1 << 6)
  83. #define S3C2410_SDIDSTA_DATATIMEOUT (1 << 5)
  84. #define S3C2410_SDIDSTA_XFERFINISH (1 << 4)
  85. #define S3C2410_SDIDSTA_TXDATAON (1 << 1)
  86. #define S3C2410_SDIDSTA_RXDATAON (1 << 0)
  87. #define S3C2440_SDIFSTA_FIFORESET (1 << 16)
  88. #define S3C2440_SDIFSTA_FIFOFAIL (3 << 14)
  89. #define S3C2410_SDIFSTA_TFDET (1 << 13)
  90. #define S3C2410_SDIFSTA_RFDET (1 << 12)
  91. #define S3C2410_SDIFSTA_COUNTMASK (0x7f)
  92. #define S3C2410_SDIIMSK_RESPONSECRC (1 << 17)
  93. #define S3C2410_SDIIMSK_CMDSENT (1 << 16)
  94. #define S3C2410_SDIIMSK_CMDTIMEOUT (1 << 15)
  95. #define S3C2410_SDIIMSK_RESPONSEND (1 << 14)
  96. #define S3C2410_SDIIMSK_SDIOIRQ (1 << 12)
  97. #define S3C2410_SDIIMSK_FIFOFAIL (1 << 11)
  98. #define S3C2410_SDIIMSK_CRCSTATUS (1 << 10)
  99. #define S3C2410_SDIIMSK_DATACRC (1 << 9)
  100. #define S3C2410_SDIIMSK_DATATIMEOUT (1 << 8)
  101. #define S3C2410_SDIIMSK_DATAFINISH (1 << 7)
  102. #define S3C2410_SDIIMSK_TXFIFOHALF (1 << 4)
  103. #define S3C2410_SDIIMSK_RXFIFOLAST (1 << 2)
  104. #define S3C2410_SDIIMSK_RXFIFOHALF (1 << 0)
  105. enum dbg_channels {
  106. dbg_err = (1 << 0),
  107. dbg_debug = (1 << 1),
  108. dbg_info = (1 << 2),
  109. dbg_irq = (1 << 3),
  110. dbg_sg = (1 << 4),
  111. dbg_dma = (1 << 5),
  112. dbg_pio = (1 << 6),
  113. dbg_fail = (1 << 7),
  114. dbg_conf = (1 << 8),
  115. };
  116. static const int dbgmap_err = dbg_fail;
  117. static const int dbgmap_info = dbg_info | dbg_conf;
  118. static const int dbgmap_debug = dbg_err | dbg_debug;
  119. #define dbg(host, channels, args...) \
  120. do { \
  121. if (dbgmap_err & channels) \
  122. dev_err(&host->pdev->dev, args); \
  123. else if (dbgmap_info & channels) \
  124. dev_info(&host->pdev->dev, args); \
  125. else if (dbgmap_debug & channels) \
  126. dev_dbg(&host->pdev->dev, args); \
  127. } while (0)
  128. static void finalize_request(struct s3cmci_host *host);
  129. static void s3cmci_send_request(struct mmc_host *mmc);
  130. static void s3cmci_reset(struct s3cmci_host *host);
  131. #ifdef CONFIG_MMC_DEBUG
  132. static void dbg_dumpregs(struct s3cmci_host *host, char *prefix)
  133. {
  134. u32 con, pre, cmdarg, cmdcon, cmdsta, r0, r1, r2, r3, timer, bsize;
  135. u32 datcon, datcnt, datsta, fsta, imask;
  136. con = readl(host->base + S3C2410_SDICON);
  137. pre = readl(host->base + S3C2410_SDIPRE);
  138. cmdarg = readl(host->base + S3C2410_SDICMDARG);
  139. cmdcon = readl(host->base + S3C2410_SDICMDCON);
  140. cmdsta = readl(host->base + S3C2410_SDICMDSTAT);
  141. r0 = readl(host->base + S3C2410_SDIRSP0);
  142. r1 = readl(host->base + S3C2410_SDIRSP1);
  143. r2 = readl(host->base + S3C2410_SDIRSP2);
  144. r3 = readl(host->base + S3C2410_SDIRSP3);
  145. timer = readl(host->base + S3C2410_SDITIMER);
  146. bsize = readl(host->base + S3C2410_SDIBSIZE);
  147. datcon = readl(host->base + S3C2410_SDIDCON);
  148. datcnt = readl(host->base + S3C2410_SDIDCNT);
  149. datsta = readl(host->base + S3C2410_SDIDSTA);
  150. fsta = readl(host->base + S3C2410_SDIFSTA);
  151. imask = readl(host->base + host->sdiimsk);
  152. dbg(host, dbg_debug, "%s CON:[%08x] PRE:[%08x] TMR:[%08x]\n",
  153. prefix, con, pre, timer);
  154. dbg(host, dbg_debug, "%s CCON:[%08x] CARG:[%08x] CSTA:[%08x]\n",
  155. prefix, cmdcon, cmdarg, cmdsta);
  156. dbg(host, dbg_debug, "%s DCON:[%08x] FSTA:[%08x]"
  157. " DSTA:[%08x] DCNT:[%08x]\n",
  158. prefix, datcon, fsta, datsta, datcnt);
  159. dbg(host, dbg_debug, "%s R0:[%08x] R1:[%08x]"
  160. " R2:[%08x] R3:[%08x]\n",
  161. prefix, r0, r1, r2, r3);
  162. }
  163. static void prepare_dbgmsg(struct s3cmci_host *host, struct mmc_command *cmd,
  164. int stop)
  165. {
  166. snprintf(host->dbgmsg_cmd, 300,
  167. "#%u%s op:%i arg:0x%08x flags:0x08%x retries:%u",
  168. host->ccnt, (stop ? " (STOP)" : ""),
  169. cmd->opcode, cmd->arg, cmd->flags, cmd->retries);
  170. if (cmd->data) {
  171. snprintf(host->dbgmsg_dat, 300,
  172. "#%u bsize:%u blocks:%u bytes:%u",
  173. host->dcnt, cmd->data->blksz,
  174. cmd->data->blocks,
  175. cmd->data->blocks * cmd->data->blksz);
  176. } else {
  177. host->dbgmsg_dat[0] = '\0';
  178. }
  179. }
  180. static void dbg_dumpcmd(struct s3cmci_host *host, struct mmc_command *cmd,
  181. int fail)
  182. {
  183. unsigned int dbglvl = fail ? dbg_fail : dbg_debug;
  184. if (!cmd)
  185. return;
  186. if (cmd->error == 0) {
  187. dbg(host, dbglvl, "CMD[OK] %s R0:0x%08x\n",
  188. host->dbgmsg_cmd, cmd->resp[0]);
  189. } else {
  190. dbg(host, dbglvl, "CMD[ERR %i] %s Status:%s\n",
  191. cmd->error, host->dbgmsg_cmd, host->status);
  192. }
  193. if (!cmd->data)
  194. return;
  195. if (cmd->data->error == 0) {
  196. dbg(host, dbglvl, "DAT[OK] %s\n", host->dbgmsg_dat);
  197. } else {
  198. dbg(host, dbglvl, "DAT[ERR %i] %s DCNT:0x%08x\n",
  199. cmd->data->error, host->dbgmsg_dat,
  200. readl(host->base + S3C2410_SDIDCNT));
  201. }
  202. }
  203. #else
  204. static void dbg_dumpcmd(struct s3cmci_host *host,
  205. struct mmc_command *cmd, int fail) { }
  206. static void prepare_dbgmsg(struct s3cmci_host *host, struct mmc_command *cmd,
  207. int stop) { }
  208. static void dbg_dumpregs(struct s3cmci_host *host, char *prefix) { }
  209. #endif /* CONFIG_MMC_DEBUG */
  210. /**
  211. * s3cmci_host_usedma - return whether the host is using dma or pio
  212. * @host: The host state
  213. *
  214. * Return true if the host is using DMA to transfer data, else false
  215. * to use PIO mode. Will return static data depending on the driver
  216. * configuration.
  217. */
  218. static inline bool s3cmci_host_usedma(struct s3cmci_host *host)
  219. {
  220. #ifdef CONFIG_MMC_S3C_PIO
  221. return false;
  222. #else /* CONFIG_MMC_S3C_DMA */
  223. return true;
  224. #endif
  225. }
  226. static inline u32 enable_imask(struct s3cmci_host *host, u32 imask)
  227. {
  228. u32 newmask;
  229. newmask = readl(host->base + host->sdiimsk);
  230. newmask |= imask;
  231. writel(newmask, host->base + host->sdiimsk);
  232. return newmask;
  233. }
  234. static inline u32 disable_imask(struct s3cmci_host *host, u32 imask)
  235. {
  236. u32 newmask;
  237. newmask = readl(host->base + host->sdiimsk);
  238. newmask &= ~imask;
  239. writel(newmask, host->base + host->sdiimsk);
  240. return newmask;
  241. }
  242. static inline void clear_imask(struct s3cmci_host *host)
  243. {
  244. u32 mask = readl(host->base + host->sdiimsk);
  245. /* preserve the SDIO IRQ mask state */
  246. mask &= S3C2410_SDIIMSK_SDIOIRQ;
  247. writel(mask, host->base + host->sdiimsk);
  248. }
  249. /**
  250. * s3cmci_check_sdio_irq - test whether the SDIO IRQ is being signalled
  251. * @host: The host to check.
  252. *
  253. * Test to see if the SDIO interrupt is being signalled in case the
  254. * controller has failed to re-detect a card interrupt. Read GPE8 and
  255. * see if it is low and if so, signal a SDIO interrupt.
  256. *
  257. * This is currently called if a request is finished (we assume that the
  258. * bus is now idle) and when the SDIO IRQ is enabled in case the IRQ is
  259. * already being indicated.
  260. */
  261. static void s3cmci_check_sdio_irq(struct s3cmci_host *host)
  262. {
  263. if (host->sdio_irqen) {
  264. if (gpio_get_value(S3C2410_GPE(8)) == 0) {
  265. pr_debug("%s: signalling irq\n", __func__);
  266. mmc_signal_sdio_irq(host->mmc);
  267. }
  268. }
  269. }
  270. static inline int get_data_buffer(struct s3cmci_host *host,
  271. u32 *bytes, u32 **pointer)
  272. {
  273. struct scatterlist *sg;
  274. if (host->pio_active == XFER_NONE)
  275. return -EINVAL;
  276. if ((!host->mrq) || (!host->mrq->data))
  277. return -EINVAL;
  278. if (host->pio_sgptr >= host->mrq->data->sg_len) {
  279. dbg(host, dbg_debug, "no more buffers (%i/%i)\n",
  280. host->pio_sgptr, host->mrq->data->sg_len);
  281. return -EBUSY;
  282. }
  283. sg = &host->mrq->data->sg[host->pio_sgptr];
  284. *bytes = sg->length;
  285. *pointer = sg_virt(sg);
  286. host->pio_sgptr++;
  287. dbg(host, dbg_sg, "new buffer (%i/%i)\n",
  288. host->pio_sgptr, host->mrq->data->sg_len);
  289. return 0;
  290. }
  291. static inline u32 fifo_count(struct s3cmci_host *host)
  292. {
  293. u32 fifostat = readl(host->base + S3C2410_SDIFSTA);
  294. fifostat &= S3C2410_SDIFSTA_COUNTMASK;
  295. return fifostat;
  296. }
  297. static inline u32 fifo_free(struct s3cmci_host *host)
  298. {
  299. u32 fifostat = readl(host->base + S3C2410_SDIFSTA);
  300. fifostat &= S3C2410_SDIFSTA_COUNTMASK;
  301. return 63 - fifostat;
  302. }
  303. /**
  304. * s3cmci_enable_irq - enable IRQ, after having disabled it.
  305. * @host: The device state.
  306. * @more: True if more IRQs are expected from transfer.
  307. *
  308. * Enable the main IRQ if needed after it has been disabled.
  309. *
  310. * The IRQ can be one of the following states:
  311. * - disabled during IDLE
  312. * - disabled whilst processing data
  313. * - enabled during transfer
  314. * - enabled whilst awaiting SDIO interrupt detection
  315. */
  316. static void s3cmci_enable_irq(struct s3cmci_host *host, bool more)
  317. {
  318. unsigned long flags;
  319. bool enable = false;
  320. local_irq_save(flags);
  321. host->irq_enabled = more;
  322. host->irq_disabled = false;
  323. enable = more | host->sdio_irqen;
  324. if (host->irq_state != enable) {
  325. host->irq_state = enable;
  326. if (enable)
  327. enable_irq(host->irq);
  328. else
  329. disable_irq(host->irq);
  330. }
  331. local_irq_restore(flags);
  332. }
  333. /**
  334. *
  335. */
  336. static void s3cmci_disable_irq(struct s3cmci_host *host, bool transfer)
  337. {
  338. unsigned long flags;
  339. local_irq_save(flags);
  340. /* pr_debug("%s: transfer %d\n", __func__, transfer); */
  341. host->irq_disabled = transfer;
  342. if (transfer && host->irq_state) {
  343. host->irq_state = false;
  344. disable_irq(host->irq);
  345. }
  346. local_irq_restore(flags);
  347. }
  348. static void do_pio_read(struct s3cmci_host *host)
  349. {
  350. int res;
  351. u32 fifo;
  352. u32 *ptr;
  353. u32 fifo_words;
  354. void __iomem *from_ptr;
  355. /* write real prescaler to host, it might be set slow to fix */
  356. writel(host->prescaler, host->base + S3C2410_SDIPRE);
  357. from_ptr = host->base + host->sdidata;
  358. while ((fifo = fifo_count(host))) {
  359. if (!host->pio_bytes) {
  360. res = get_data_buffer(host, &host->pio_bytes,
  361. &host->pio_ptr);
  362. if (res) {
  363. host->pio_active = XFER_NONE;
  364. host->complete_what = COMPLETION_FINALIZE;
  365. dbg(host, dbg_pio, "pio_read(): "
  366. "complete (no more data).\n");
  367. return;
  368. }
  369. dbg(host, dbg_pio,
  370. "pio_read(): new target: [%i]@[%p]\n",
  371. host->pio_bytes, host->pio_ptr);
  372. }
  373. dbg(host, dbg_pio,
  374. "pio_read(): fifo:[%02i] buffer:[%03i] dcnt:[%08X]\n",
  375. fifo, host->pio_bytes,
  376. readl(host->base + S3C2410_SDIDCNT));
  377. /* If we have reached the end of the block, we can
  378. * read a word and get 1 to 3 bytes. If we in the
  379. * middle of the block, we have to read full words,
  380. * otherwise we will write garbage, so round down to
  381. * an even multiple of 4. */
  382. if (fifo >= host->pio_bytes)
  383. fifo = host->pio_bytes;
  384. else
  385. fifo -= fifo & 3;
  386. host->pio_bytes -= fifo;
  387. host->pio_count += fifo;
  388. fifo_words = fifo >> 2;
  389. ptr = host->pio_ptr;
  390. while (fifo_words--)
  391. *ptr++ = readl(from_ptr);
  392. host->pio_ptr = ptr;
  393. if (fifo & 3) {
  394. u32 n = fifo & 3;
  395. u32 data = readl(from_ptr);
  396. u8 *p = (u8 *)host->pio_ptr;
  397. while (n--) {
  398. *p++ = data;
  399. data >>= 8;
  400. }
  401. }
  402. }
  403. if (!host->pio_bytes) {
  404. res = get_data_buffer(host, &host->pio_bytes, &host->pio_ptr);
  405. if (res) {
  406. dbg(host, dbg_pio,
  407. "pio_read(): complete (no more buffers).\n");
  408. host->pio_active = XFER_NONE;
  409. host->complete_what = COMPLETION_FINALIZE;
  410. return;
  411. }
  412. }
  413. enable_imask(host,
  414. S3C2410_SDIIMSK_RXFIFOHALF | S3C2410_SDIIMSK_RXFIFOLAST);
  415. }
  416. static void do_pio_write(struct s3cmci_host *host)
  417. {
  418. void __iomem *to_ptr;
  419. int res;
  420. u32 fifo;
  421. u32 *ptr;
  422. to_ptr = host->base + host->sdidata;
  423. while ((fifo = fifo_free(host)) > 3) {
  424. if (!host->pio_bytes) {
  425. res = get_data_buffer(host, &host->pio_bytes,
  426. &host->pio_ptr);
  427. if (res) {
  428. dbg(host, dbg_pio,
  429. "pio_write(): complete (no more data).\n");
  430. host->pio_active = XFER_NONE;
  431. return;
  432. }
  433. dbg(host, dbg_pio,
  434. "pio_write(): new source: [%i]@[%p]\n",
  435. host->pio_bytes, host->pio_ptr);
  436. }
  437. /* If we have reached the end of the block, we have to
  438. * write exactly the remaining number of bytes. If we
  439. * in the middle of the block, we have to write full
  440. * words, so round down to an even multiple of 4. */
  441. if (fifo >= host->pio_bytes)
  442. fifo = host->pio_bytes;
  443. else
  444. fifo -= fifo & 3;
  445. host->pio_bytes -= fifo;
  446. host->pio_count += fifo;
  447. fifo = (fifo + 3) >> 2;
  448. ptr = host->pio_ptr;
  449. while (fifo--)
  450. writel(*ptr++, to_ptr);
  451. host->pio_ptr = ptr;
  452. }
  453. enable_imask(host, S3C2410_SDIIMSK_TXFIFOHALF);
  454. }
  455. static void pio_tasklet(unsigned long data)
  456. {
  457. struct s3cmci_host *host = (struct s3cmci_host *) data;
  458. s3cmci_disable_irq(host, true);
  459. if (host->pio_active == XFER_WRITE)
  460. do_pio_write(host);
  461. if (host->pio_active == XFER_READ)
  462. do_pio_read(host);
  463. if (host->complete_what == COMPLETION_FINALIZE) {
  464. clear_imask(host);
  465. if (host->pio_active != XFER_NONE) {
  466. dbg(host, dbg_err, "unfinished %s "
  467. "- pio_count:[%u] pio_bytes:[%u]\n",
  468. (host->pio_active == XFER_READ) ? "read" : "write",
  469. host->pio_count, host->pio_bytes);
  470. if (host->mrq->data)
  471. host->mrq->data->error = -EINVAL;
  472. }
  473. s3cmci_enable_irq(host, false);
  474. finalize_request(host);
  475. } else
  476. s3cmci_enable_irq(host, true);
  477. }
  478. /*
  479. * ISR for SDI Interface IRQ
  480. * Communication between driver and ISR works as follows:
  481. * host->mrq points to current request
  482. * host->complete_what Indicates when the request is considered done
  483. * COMPLETION_CMDSENT when the command was sent
  484. * COMPLETION_RSPFIN when a response was received
  485. * COMPLETION_XFERFINISH when the data transfer is finished
  486. * COMPLETION_XFERFINISH_RSPFIN both of the above.
  487. * host->complete_request is the completion-object the driver waits for
  488. *
  489. * 1) Driver sets up host->mrq and host->complete_what
  490. * 2) Driver prepares the transfer
  491. * 3) Driver enables interrupts
  492. * 4) Driver starts transfer
  493. * 5) Driver waits for host->complete_rquest
  494. * 6) ISR checks for request status (errors and success)
  495. * 6) ISR sets host->mrq->cmd->error and host->mrq->data->error
  496. * 7) ISR completes host->complete_request
  497. * 8) ISR disables interrupts
  498. * 9) Driver wakes up and takes care of the request
  499. *
  500. * Note: "->error"-fields are expected to be set to 0 before the request
  501. * was issued by mmc.c - therefore they are only set, when an error
  502. * contition comes up
  503. */
  504. static irqreturn_t s3cmci_irq(int irq, void *dev_id)
  505. {
  506. struct s3cmci_host *host = dev_id;
  507. struct mmc_command *cmd;
  508. u32 mci_csta, mci_dsta, mci_fsta, mci_dcnt, mci_imsk;
  509. u32 mci_cclear = 0, mci_dclear;
  510. unsigned long iflags;
  511. mci_dsta = readl(host->base + S3C2410_SDIDSTA);
  512. mci_imsk = readl(host->base + host->sdiimsk);
  513. if (mci_dsta & S3C2410_SDIDSTA_SDIOIRQDETECT) {
  514. if (mci_imsk & S3C2410_SDIIMSK_SDIOIRQ) {
  515. mci_dclear = S3C2410_SDIDSTA_SDIOIRQDETECT;
  516. writel(mci_dclear, host->base + S3C2410_SDIDSTA);
  517. mmc_signal_sdio_irq(host->mmc);
  518. return IRQ_HANDLED;
  519. }
  520. }
  521. spin_lock_irqsave(&host->complete_lock, iflags);
  522. mci_csta = readl(host->base + S3C2410_SDICMDSTAT);
  523. mci_dcnt = readl(host->base + S3C2410_SDIDCNT);
  524. mci_fsta = readl(host->base + S3C2410_SDIFSTA);
  525. mci_dclear = 0;
  526. if ((host->complete_what == COMPLETION_NONE) ||
  527. (host->complete_what == COMPLETION_FINALIZE)) {
  528. host->status = "nothing to complete";
  529. clear_imask(host);
  530. goto irq_out;
  531. }
  532. if (!host->mrq) {
  533. host->status = "no active mrq";
  534. clear_imask(host);
  535. goto irq_out;
  536. }
  537. cmd = host->cmd_is_stop ? host->mrq->stop : host->mrq->cmd;
  538. if (!cmd) {
  539. host->status = "no active cmd";
  540. clear_imask(host);
  541. goto irq_out;
  542. }
  543. if (!s3cmci_host_usedma(host)) {
  544. if ((host->pio_active == XFER_WRITE) &&
  545. (mci_fsta & S3C2410_SDIFSTA_TFDET)) {
  546. disable_imask(host, S3C2410_SDIIMSK_TXFIFOHALF);
  547. tasklet_schedule(&host->pio_tasklet);
  548. host->status = "pio tx";
  549. }
  550. if ((host->pio_active == XFER_READ) &&
  551. (mci_fsta & S3C2410_SDIFSTA_RFDET)) {
  552. disable_imask(host,
  553. S3C2410_SDIIMSK_RXFIFOHALF |
  554. S3C2410_SDIIMSK_RXFIFOLAST);
  555. tasklet_schedule(&host->pio_tasklet);
  556. host->status = "pio rx";
  557. }
  558. }
  559. if (mci_csta & S3C2410_SDICMDSTAT_CMDTIMEOUT) {
  560. dbg(host, dbg_err, "CMDSTAT: error CMDTIMEOUT\n");
  561. cmd->error = -ETIMEDOUT;
  562. host->status = "error: command timeout";
  563. goto fail_transfer;
  564. }
  565. if (mci_csta & S3C2410_SDICMDSTAT_CMDSENT) {
  566. if (host->complete_what == COMPLETION_CMDSENT) {
  567. host->status = "ok: command sent";
  568. goto close_transfer;
  569. }
  570. mci_cclear |= S3C2410_SDICMDSTAT_CMDSENT;
  571. }
  572. if (mci_csta & S3C2410_SDICMDSTAT_CRCFAIL) {
  573. if (cmd->flags & MMC_RSP_CRC) {
  574. if (host->mrq->cmd->flags & MMC_RSP_136) {
  575. dbg(host, dbg_irq,
  576. "fixup: ignore CRC fail with long rsp\n");
  577. } else {
  578. /* note, we used to fail the transfer
  579. * here, but it seems that this is just
  580. * the hardware getting it wrong.
  581. *
  582. * cmd->error = -EILSEQ;
  583. * host->status = "error: bad command crc";
  584. * goto fail_transfer;
  585. */
  586. }
  587. }
  588. mci_cclear |= S3C2410_SDICMDSTAT_CRCFAIL;
  589. }
  590. if (mci_csta & S3C2410_SDICMDSTAT_RSPFIN) {
  591. if (host->complete_what == COMPLETION_RSPFIN) {
  592. host->status = "ok: command response received";
  593. goto close_transfer;
  594. }
  595. if (host->complete_what == COMPLETION_XFERFINISH_RSPFIN)
  596. host->complete_what = COMPLETION_XFERFINISH;
  597. mci_cclear |= S3C2410_SDICMDSTAT_RSPFIN;
  598. }
  599. /* errors handled after this point are only relevant
  600. when a data transfer is in progress */
  601. if (!cmd->data)
  602. goto clear_status_bits;
  603. /* Check for FIFO failure */
  604. if (host->is2440) {
  605. if (mci_fsta & S3C2440_SDIFSTA_FIFOFAIL) {
  606. dbg(host, dbg_err, "FIFO failure\n");
  607. host->mrq->data->error = -EILSEQ;
  608. host->status = "error: 2440 fifo failure";
  609. goto fail_transfer;
  610. }
  611. } else {
  612. if (mci_dsta & S3C2410_SDIDSTA_FIFOFAIL) {
  613. dbg(host, dbg_err, "FIFO failure\n");
  614. cmd->data->error = -EILSEQ;
  615. host->status = "error: fifo failure";
  616. goto fail_transfer;
  617. }
  618. }
  619. if (mci_dsta & S3C2410_SDIDSTA_RXCRCFAIL) {
  620. dbg(host, dbg_err, "bad data crc (outgoing)\n");
  621. cmd->data->error = -EILSEQ;
  622. host->status = "error: bad data crc (outgoing)";
  623. goto fail_transfer;
  624. }
  625. if (mci_dsta & S3C2410_SDIDSTA_CRCFAIL) {
  626. dbg(host, dbg_err, "bad data crc (incoming)\n");
  627. cmd->data->error = -EILSEQ;
  628. host->status = "error: bad data crc (incoming)";
  629. goto fail_transfer;
  630. }
  631. if (mci_dsta & S3C2410_SDIDSTA_DATATIMEOUT) {
  632. dbg(host, dbg_err, "data timeout\n");
  633. cmd->data->error = -ETIMEDOUT;
  634. host->status = "error: data timeout";
  635. goto fail_transfer;
  636. }
  637. if (mci_dsta & S3C2410_SDIDSTA_XFERFINISH) {
  638. if (host->complete_what == COMPLETION_XFERFINISH) {
  639. host->status = "ok: data transfer completed";
  640. goto close_transfer;
  641. }
  642. if (host->complete_what == COMPLETION_XFERFINISH_RSPFIN)
  643. host->complete_what = COMPLETION_RSPFIN;
  644. mci_dclear |= S3C2410_SDIDSTA_XFERFINISH;
  645. }
  646. clear_status_bits:
  647. writel(mci_cclear, host->base + S3C2410_SDICMDSTAT);
  648. writel(mci_dclear, host->base + S3C2410_SDIDSTA);
  649. goto irq_out;
  650. fail_transfer:
  651. host->pio_active = XFER_NONE;
  652. close_transfer:
  653. host->complete_what = COMPLETION_FINALIZE;
  654. clear_imask(host);
  655. tasklet_schedule(&host->pio_tasklet);
  656. goto irq_out;
  657. irq_out:
  658. dbg(host, dbg_irq,
  659. "csta:0x%08x dsta:0x%08x fsta:0x%08x dcnt:0x%08x status:%s.\n",
  660. mci_csta, mci_dsta, mci_fsta, mci_dcnt, host->status);
  661. spin_unlock_irqrestore(&host->complete_lock, iflags);
  662. return IRQ_HANDLED;
  663. }
  664. static void s3cmci_dma_done_callback(void *arg)
  665. {
  666. struct s3cmci_host *host = arg;
  667. unsigned long iflags;
  668. BUG_ON(!host->mrq);
  669. BUG_ON(!host->mrq->data);
  670. spin_lock_irqsave(&host->complete_lock, iflags);
  671. dbg(host, dbg_dma, "DMA FINISHED\n");
  672. host->dma_complete = 1;
  673. host->complete_what = COMPLETION_FINALIZE;
  674. tasklet_schedule(&host->pio_tasklet);
  675. spin_unlock_irqrestore(&host->complete_lock, iflags);
  676. }
  677. static void finalize_request(struct s3cmci_host *host)
  678. {
  679. struct mmc_request *mrq = host->mrq;
  680. struct mmc_command *cmd;
  681. int debug_as_failure = 0;
  682. if (host->complete_what != COMPLETION_FINALIZE)
  683. return;
  684. if (!mrq)
  685. return;
  686. cmd = host->cmd_is_stop ? mrq->stop : mrq->cmd;
  687. if (cmd->data && (cmd->error == 0) &&
  688. (cmd->data->error == 0)) {
  689. if (s3cmci_host_usedma(host) && (!host->dma_complete)) {
  690. dbg(host, dbg_dma, "DMA Missing (%d)!\n",
  691. host->dma_complete);
  692. return;
  693. }
  694. }
  695. /* Read response from controller. */
  696. cmd->resp[0] = readl(host->base + S3C2410_SDIRSP0);
  697. cmd->resp[1] = readl(host->base + S3C2410_SDIRSP1);
  698. cmd->resp[2] = readl(host->base + S3C2410_SDIRSP2);
  699. cmd->resp[3] = readl(host->base + S3C2410_SDIRSP3);
  700. writel(host->prescaler, host->base + S3C2410_SDIPRE);
  701. if (cmd->error)
  702. debug_as_failure = 1;
  703. if (cmd->data && cmd->data->error)
  704. debug_as_failure = 1;
  705. dbg_dumpcmd(host, cmd, debug_as_failure);
  706. /* Cleanup controller */
  707. writel(0, host->base + S3C2410_SDICMDARG);
  708. writel(S3C2410_SDIDCON_STOP, host->base + S3C2410_SDIDCON);
  709. writel(0, host->base + S3C2410_SDICMDCON);
  710. clear_imask(host);
  711. if (cmd->data && cmd->error)
  712. cmd->data->error = cmd->error;
  713. if (cmd->data && cmd->data->stop && (!host->cmd_is_stop)) {
  714. host->cmd_is_stop = 1;
  715. s3cmci_send_request(host->mmc);
  716. return;
  717. }
  718. /* If we have no data transfer we are finished here */
  719. if (!mrq->data)
  720. goto request_done;
  721. /* Calculate the amout of bytes transfer if there was no error */
  722. if (mrq->data->error == 0) {
  723. mrq->data->bytes_xfered =
  724. (mrq->data->blocks * mrq->data->blksz);
  725. } else {
  726. mrq->data->bytes_xfered = 0;
  727. }
  728. /* If we had an error while transferring data we flush the
  729. * DMA channel and the fifo to clear out any garbage. */
  730. if (mrq->data->error != 0) {
  731. if (s3cmci_host_usedma(host))
  732. dmaengine_terminate_all(host->dma);
  733. if (host->is2440) {
  734. /* Clear failure register and reset fifo. */
  735. writel(S3C2440_SDIFSTA_FIFORESET |
  736. S3C2440_SDIFSTA_FIFOFAIL,
  737. host->base + S3C2410_SDIFSTA);
  738. } else {
  739. u32 mci_con;
  740. /* reset fifo */
  741. mci_con = readl(host->base + S3C2410_SDICON);
  742. mci_con |= S3C2410_SDICON_FIFORESET;
  743. writel(mci_con, host->base + S3C2410_SDICON);
  744. }
  745. }
  746. request_done:
  747. host->complete_what = COMPLETION_NONE;
  748. host->mrq = NULL;
  749. s3cmci_check_sdio_irq(host);
  750. mmc_request_done(host->mmc, mrq);
  751. }
  752. static void s3cmci_send_command(struct s3cmci_host *host,
  753. struct mmc_command *cmd)
  754. {
  755. u32 ccon, imsk;
  756. imsk = S3C2410_SDIIMSK_CRCSTATUS | S3C2410_SDIIMSK_CMDTIMEOUT |
  757. S3C2410_SDIIMSK_RESPONSEND | S3C2410_SDIIMSK_CMDSENT |
  758. S3C2410_SDIIMSK_RESPONSECRC;
  759. enable_imask(host, imsk);
  760. if (cmd->data)
  761. host->complete_what = COMPLETION_XFERFINISH_RSPFIN;
  762. else if (cmd->flags & MMC_RSP_PRESENT)
  763. host->complete_what = COMPLETION_RSPFIN;
  764. else
  765. host->complete_what = COMPLETION_CMDSENT;
  766. writel(cmd->arg, host->base + S3C2410_SDICMDARG);
  767. ccon = cmd->opcode & S3C2410_SDICMDCON_INDEX;
  768. ccon |= S3C2410_SDICMDCON_SENDERHOST | S3C2410_SDICMDCON_CMDSTART;
  769. if (cmd->flags & MMC_RSP_PRESENT)
  770. ccon |= S3C2410_SDICMDCON_WAITRSP;
  771. if (cmd->flags & MMC_RSP_136)
  772. ccon |= S3C2410_SDICMDCON_LONGRSP;
  773. writel(ccon, host->base + S3C2410_SDICMDCON);
  774. }
  775. static int s3cmci_setup_data(struct s3cmci_host *host, struct mmc_data *data)
  776. {
  777. u32 dcon, imsk, stoptries = 3;
  778. /* write DCON register */
  779. if (!data) {
  780. writel(0, host->base + S3C2410_SDIDCON);
  781. return 0;
  782. }
  783. if ((data->blksz & 3) != 0) {
  784. /* We cannot deal with unaligned blocks with more than
  785. * one block being transferred. */
  786. if (data->blocks > 1) {
  787. pr_warn("%s: can't do non-word sized block transfers (blksz %d)\n",
  788. __func__, data->blksz);
  789. return -EINVAL;
  790. }
  791. }
  792. while (readl(host->base + S3C2410_SDIDSTA) &
  793. (S3C2410_SDIDSTA_TXDATAON | S3C2410_SDIDSTA_RXDATAON)) {
  794. dbg(host, dbg_err,
  795. "mci_setup_data() transfer stillin progress.\n");
  796. writel(S3C2410_SDIDCON_STOP, host->base + S3C2410_SDIDCON);
  797. s3cmci_reset(host);
  798. if ((stoptries--) == 0) {
  799. dbg_dumpregs(host, "DRF");
  800. return -EINVAL;
  801. }
  802. }
  803. dcon = data->blocks & S3C2410_SDIDCON_BLKNUM_MASK;
  804. if (s3cmci_host_usedma(host))
  805. dcon |= S3C2410_SDIDCON_DMAEN;
  806. if (host->bus_width == MMC_BUS_WIDTH_4)
  807. dcon |= S3C2410_SDIDCON_WIDEBUS;
  808. dcon |= S3C2410_SDIDCON_BLOCKMODE;
  809. if (data->flags & MMC_DATA_WRITE) {
  810. dcon |= S3C2410_SDIDCON_TXAFTERRESP;
  811. dcon |= S3C2410_SDIDCON_XFER_TXSTART;
  812. }
  813. if (data->flags & MMC_DATA_READ) {
  814. dcon |= S3C2410_SDIDCON_RXAFTERCMD;
  815. dcon |= S3C2410_SDIDCON_XFER_RXSTART;
  816. }
  817. if (host->is2440) {
  818. dcon |= S3C2440_SDIDCON_DS_WORD;
  819. dcon |= S3C2440_SDIDCON_DATSTART;
  820. }
  821. writel(dcon, host->base + S3C2410_SDIDCON);
  822. /* write BSIZE register */
  823. writel(data->blksz, host->base + S3C2410_SDIBSIZE);
  824. /* add to IMASK register */
  825. imsk = S3C2410_SDIIMSK_FIFOFAIL | S3C2410_SDIIMSK_DATACRC |
  826. S3C2410_SDIIMSK_DATATIMEOUT | S3C2410_SDIIMSK_DATAFINISH;
  827. enable_imask(host, imsk);
  828. /* write TIMER register */
  829. if (host->is2440) {
  830. writel(0x007FFFFF, host->base + S3C2410_SDITIMER);
  831. } else {
  832. writel(0x0000FFFF, host->base + S3C2410_SDITIMER);
  833. /* FIX: set slow clock to prevent timeouts on read */
  834. if (data->flags & MMC_DATA_READ)
  835. writel(0xFF, host->base + S3C2410_SDIPRE);
  836. }
  837. return 0;
  838. }
  839. #define BOTH_DIR (MMC_DATA_WRITE | MMC_DATA_READ)
  840. static int s3cmci_prepare_pio(struct s3cmci_host *host, struct mmc_data *data)
  841. {
  842. int rw = (data->flags & MMC_DATA_WRITE) ? 1 : 0;
  843. BUG_ON((data->flags & BOTH_DIR) == BOTH_DIR);
  844. host->pio_sgptr = 0;
  845. host->pio_bytes = 0;
  846. host->pio_count = 0;
  847. host->pio_active = rw ? XFER_WRITE : XFER_READ;
  848. if (rw) {
  849. do_pio_write(host);
  850. enable_imask(host, S3C2410_SDIIMSK_TXFIFOHALF);
  851. } else {
  852. enable_imask(host, S3C2410_SDIIMSK_RXFIFOHALF
  853. | S3C2410_SDIIMSK_RXFIFOLAST);
  854. }
  855. return 0;
  856. }
  857. static int s3cmci_prepare_dma(struct s3cmci_host *host, struct mmc_data *data)
  858. {
  859. int rw = data->flags & MMC_DATA_WRITE;
  860. struct dma_async_tx_descriptor *desc;
  861. struct dma_slave_config conf = {
  862. .src_addr = host->mem->start + host->sdidata,
  863. .dst_addr = host->mem->start + host->sdidata,
  864. .src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
  865. .dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
  866. };
  867. BUG_ON((data->flags & BOTH_DIR) == BOTH_DIR);
  868. /* Restore prescaler value */
  869. writel(host->prescaler, host->base + S3C2410_SDIPRE);
  870. if (!rw)
  871. conf.direction = DMA_DEV_TO_MEM;
  872. else
  873. conf.direction = DMA_MEM_TO_DEV;
  874. dma_map_sg(mmc_dev(host->mmc), data->sg, data->sg_len,
  875. mmc_get_dma_dir(data));
  876. dmaengine_slave_config(host->dma, &conf);
  877. desc = dmaengine_prep_slave_sg(host->dma, data->sg, data->sg_len,
  878. conf.direction,
  879. DMA_CTRL_ACK | DMA_PREP_INTERRUPT);
  880. if (!desc)
  881. goto unmap_exit;
  882. desc->callback = s3cmci_dma_done_callback;
  883. desc->callback_param = host;
  884. dmaengine_submit(desc);
  885. dma_async_issue_pending(host->dma);
  886. return 0;
  887. unmap_exit:
  888. dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len,
  889. mmc_get_dma_dir(data));
  890. return -ENOMEM;
  891. }
  892. static void s3cmci_send_request(struct mmc_host *mmc)
  893. {
  894. struct s3cmci_host *host = mmc_priv(mmc);
  895. struct mmc_request *mrq = host->mrq;
  896. struct mmc_command *cmd = host->cmd_is_stop ? mrq->stop : mrq->cmd;
  897. host->ccnt++;
  898. prepare_dbgmsg(host, cmd, host->cmd_is_stop);
  899. /* Clear command, data and fifo status registers
  900. Fifo clear only necessary on 2440, but doesn't hurt on 2410
  901. */
  902. writel(0xFFFFFFFF, host->base + S3C2410_SDICMDSTAT);
  903. writel(0xFFFFFFFF, host->base + S3C2410_SDIDSTA);
  904. writel(0xFFFFFFFF, host->base + S3C2410_SDIFSTA);
  905. if (cmd->data) {
  906. int res = s3cmci_setup_data(host, cmd->data);
  907. host->dcnt++;
  908. if (res) {
  909. dbg(host, dbg_err, "setup data error %d\n", res);
  910. cmd->error = res;
  911. cmd->data->error = res;
  912. mmc_request_done(mmc, mrq);
  913. return;
  914. }
  915. if (s3cmci_host_usedma(host))
  916. res = s3cmci_prepare_dma(host, cmd->data);
  917. else
  918. res = s3cmci_prepare_pio(host, cmd->data);
  919. if (res) {
  920. dbg(host, dbg_err, "data prepare error %d\n", res);
  921. cmd->error = res;
  922. cmd->data->error = res;
  923. mmc_request_done(mmc, mrq);
  924. return;
  925. }
  926. }
  927. /* Send command */
  928. s3cmci_send_command(host, cmd);
  929. /* Enable Interrupt */
  930. s3cmci_enable_irq(host, true);
  931. }
  932. static void s3cmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
  933. {
  934. struct s3cmci_host *host = mmc_priv(mmc);
  935. host->status = "mmc request";
  936. host->cmd_is_stop = 0;
  937. host->mrq = mrq;
  938. if (mmc_gpio_get_cd(mmc) == 0) {
  939. dbg(host, dbg_err, "%s: no medium present\n", __func__);
  940. host->mrq->cmd->error = -ENOMEDIUM;
  941. mmc_request_done(mmc, mrq);
  942. } else
  943. s3cmci_send_request(mmc);
  944. }
  945. static void s3cmci_set_clk(struct s3cmci_host *host, struct mmc_ios *ios)
  946. {
  947. u32 mci_psc;
  948. /* Set clock */
  949. for (mci_psc = 0; mci_psc < 255; mci_psc++) {
  950. host->real_rate = host->clk_rate / (host->clk_div*(mci_psc+1));
  951. if (host->real_rate <= ios->clock)
  952. break;
  953. }
  954. if (mci_psc > 255)
  955. mci_psc = 255;
  956. host->prescaler = mci_psc;
  957. writel(host->prescaler, host->base + S3C2410_SDIPRE);
  958. /* If requested clock is 0, real_rate will be 0, too */
  959. if (ios->clock == 0)
  960. host->real_rate = 0;
  961. }
  962. static void s3cmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  963. {
  964. struct s3cmci_host *host = mmc_priv(mmc);
  965. u32 mci_con;
  966. /* Set the power state */
  967. mci_con = readl(host->base + S3C2410_SDICON);
  968. switch (ios->power_mode) {
  969. case MMC_POWER_ON:
  970. case MMC_POWER_UP:
  971. /* Configure GPE5...GPE10 pins in SD mode */
  972. if (!host->pdev->dev.of_node)
  973. s3c_gpio_cfgall_range(S3C2410_GPE(5), 6, S3C_GPIO_SFN(2),
  974. S3C_GPIO_PULL_NONE);
  975. if (host->pdata->set_power)
  976. host->pdata->set_power(ios->power_mode, ios->vdd);
  977. if (!host->is2440)
  978. mci_con |= S3C2410_SDICON_FIFORESET;
  979. break;
  980. case MMC_POWER_OFF:
  981. default:
  982. if (!host->pdev->dev.of_node)
  983. gpio_direction_output(S3C2410_GPE(5), 0);
  984. if (host->is2440)
  985. mci_con |= S3C2440_SDICON_SDRESET;
  986. if (host->pdata->set_power)
  987. host->pdata->set_power(ios->power_mode, ios->vdd);
  988. break;
  989. }
  990. s3cmci_set_clk(host, ios);
  991. /* Set CLOCK_ENABLE */
  992. if (ios->clock)
  993. mci_con |= S3C2410_SDICON_CLOCKTYPE;
  994. else
  995. mci_con &= ~S3C2410_SDICON_CLOCKTYPE;
  996. writel(mci_con, host->base + S3C2410_SDICON);
  997. if ((ios->power_mode == MMC_POWER_ON) ||
  998. (ios->power_mode == MMC_POWER_UP)) {
  999. dbg(host, dbg_conf, "running at %lukHz (requested: %ukHz).\n",
  1000. host->real_rate/1000, ios->clock/1000);
  1001. } else {
  1002. dbg(host, dbg_conf, "powered down.\n");
  1003. }
  1004. host->bus_width = ios->bus_width;
  1005. }
  1006. static void s3cmci_reset(struct s3cmci_host *host)
  1007. {
  1008. u32 con = readl(host->base + S3C2410_SDICON);
  1009. con |= S3C2440_SDICON_SDRESET;
  1010. writel(con, host->base + S3C2410_SDICON);
  1011. }
  1012. static void s3cmci_enable_sdio_irq(struct mmc_host *mmc, int enable)
  1013. {
  1014. struct s3cmci_host *host = mmc_priv(mmc);
  1015. unsigned long flags;
  1016. u32 con;
  1017. local_irq_save(flags);
  1018. con = readl(host->base + S3C2410_SDICON);
  1019. host->sdio_irqen = enable;
  1020. if (enable == host->sdio_irqen)
  1021. goto same_state;
  1022. if (enable) {
  1023. con |= S3C2410_SDICON_SDIOIRQ;
  1024. enable_imask(host, S3C2410_SDIIMSK_SDIOIRQ);
  1025. if (!host->irq_state && !host->irq_disabled) {
  1026. host->irq_state = true;
  1027. enable_irq(host->irq);
  1028. }
  1029. } else {
  1030. disable_imask(host, S3C2410_SDIIMSK_SDIOIRQ);
  1031. con &= ~S3C2410_SDICON_SDIOIRQ;
  1032. if (!host->irq_enabled && host->irq_state) {
  1033. disable_irq_nosync(host->irq);
  1034. host->irq_state = false;
  1035. }
  1036. }
  1037. writel(con, host->base + S3C2410_SDICON);
  1038. same_state:
  1039. local_irq_restore(flags);
  1040. s3cmci_check_sdio_irq(host);
  1041. }
  1042. static const struct mmc_host_ops s3cmci_ops = {
  1043. .request = s3cmci_request,
  1044. .set_ios = s3cmci_set_ios,
  1045. .get_ro = mmc_gpio_get_ro,
  1046. .get_cd = mmc_gpio_get_cd,
  1047. .enable_sdio_irq = s3cmci_enable_sdio_irq,
  1048. };
  1049. static struct s3c24xx_mci_pdata s3cmci_def_pdata = {
  1050. /* This is currently here to avoid a number of if (host->pdata)
  1051. * checks. Any zero fields to ensure reasonable defaults are picked. */
  1052. .no_wprotect = 1,
  1053. .no_detect = 1,
  1054. };
  1055. #ifdef CONFIG_ARM_S3C24XX_CPUFREQ
  1056. static int s3cmci_cpufreq_transition(struct notifier_block *nb,
  1057. unsigned long val, void *data)
  1058. {
  1059. struct s3cmci_host *host;
  1060. struct mmc_host *mmc;
  1061. unsigned long newclk;
  1062. unsigned long flags;
  1063. host = container_of(nb, struct s3cmci_host, freq_transition);
  1064. newclk = clk_get_rate(host->clk);
  1065. mmc = host->mmc;
  1066. if ((val == CPUFREQ_PRECHANGE && newclk > host->clk_rate) ||
  1067. (val == CPUFREQ_POSTCHANGE && newclk < host->clk_rate)) {
  1068. spin_lock_irqsave(&mmc->lock, flags);
  1069. host->clk_rate = newclk;
  1070. if (mmc->ios.power_mode != MMC_POWER_OFF &&
  1071. mmc->ios.clock != 0)
  1072. s3cmci_set_clk(host, &mmc->ios);
  1073. spin_unlock_irqrestore(&mmc->lock, flags);
  1074. }
  1075. return 0;
  1076. }
  1077. static inline int s3cmci_cpufreq_register(struct s3cmci_host *host)
  1078. {
  1079. host->freq_transition.notifier_call = s3cmci_cpufreq_transition;
  1080. return cpufreq_register_notifier(&host->freq_transition,
  1081. CPUFREQ_TRANSITION_NOTIFIER);
  1082. }
  1083. static inline void s3cmci_cpufreq_deregister(struct s3cmci_host *host)
  1084. {
  1085. cpufreq_unregister_notifier(&host->freq_transition,
  1086. CPUFREQ_TRANSITION_NOTIFIER);
  1087. }
  1088. #else
  1089. static inline int s3cmci_cpufreq_register(struct s3cmci_host *host)
  1090. {
  1091. return 0;
  1092. }
  1093. static inline void s3cmci_cpufreq_deregister(struct s3cmci_host *host)
  1094. {
  1095. }
  1096. #endif
  1097. #ifdef CONFIG_DEBUG_FS
  1098. static int s3cmci_state_show(struct seq_file *seq, void *v)
  1099. {
  1100. struct s3cmci_host *host = seq->private;
  1101. seq_printf(seq, "Register base = 0x%08x\n", (u32)host->base);
  1102. seq_printf(seq, "Clock rate = %ld\n", host->clk_rate);
  1103. seq_printf(seq, "Prescale = %d\n", host->prescaler);
  1104. seq_printf(seq, "is2440 = %d\n", host->is2440);
  1105. seq_printf(seq, "IRQ = %d\n", host->irq);
  1106. seq_printf(seq, "IRQ enabled = %d\n", host->irq_enabled);
  1107. seq_printf(seq, "IRQ disabled = %d\n", host->irq_disabled);
  1108. seq_printf(seq, "IRQ state = %d\n", host->irq_state);
  1109. seq_printf(seq, "CD IRQ = %d\n", host->irq_cd);
  1110. seq_printf(seq, "Do DMA = %d\n", s3cmci_host_usedma(host));
  1111. seq_printf(seq, "SDIIMSK at %d\n", host->sdiimsk);
  1112. seq_printf(seq, "SDIDATA at %d\n", host->sdidata);
  1113. return 0;
  1114. }
  1115. static int s3cmci_state_open(struct inode *inode, struct file *file)
  1116. {
  1117. return single_open(file, s3cmci_state_show, inode->i_private);
  1118. }
  1119. static const struct file_operations s3cmci_fops_state = {
  1120. .owner = THIS_MODULE,
  1121. .open = s3cmci_state_open,
  1122. .read = seq_read,
  1123. .llseek = seq_lseek,
  1124. .release = single_release,
  1125. };
  1126. #define DBG_REG(_r) { .addr = S3C2410_SDI##_r, .name = #_r }
  1127. struct s3cmci_reg {
  1128. unsigned short addr;
  1129. unsigned char *name;
  1130. } debug_regs[] = {
  1131. DBG_REG(CON),
  1132. DBG_REG(PRE),
  1133. DBG_REG(CMDARG),
  1134. DBG_REG(CMDCON),
  1135. DBG_REG(CMDSTAT),
  1136. DBG_REG(RSP0),
  1137. DBG_REG(RSP1),
  1138. DBG_REG(RSP2),
  1139. DBG_REG(RSP3),
  1140. DBG_REG(TIMER),
  1141. DBG_REG(BSIZE),
  1142. DBG_REG(DCON),
  1143. DBG_REG(DCNT),
  1144. DBG_REG(DSTA),
  1145. DBG_REG(FSTA),
  1146. {}
  1147. };
  1148. static int s3cmci_regs_show(struct seq_file *seq, void *v)
  1149. {
  1150. struct s3cmci_host *host = seq->private;
  1151. struct s3cmci_reg *rptr = debug_regs;
  1152. for (; rptr->name; rptr++)
  1153. seq_printf(seq, "SDI%s\t=0x%08x\n", rptr->name,
  1154. readl(host->base + rptr->addr));
  1155. seq_printf(seq, "SDIIMSK\t=0x%08x\n", readl(host->base + host->sdiimsk));
  1156. return 0;
  1157. }
  1158. static int s3cmci_regs_open(struct inode *inode, struct file *file)
  1159. {
  1160. return single_open(file, s3cmci_regs_show, inode->i_private);
  1161. }
  1162. static const struct file_operations s3cmci_fops_regs = {
  1163. .owner = THIS_MODULE,
  1164. .open = s3cmci_regs_open,
  1165. .read = seq_read,
  1166. .llseek = seq_lseek,
  1167. .release = single_release,
  1168. };
  1169. static void s3cmci_debugfs_attach(struct s3cmci_host *host)
  1170. {
  1171. struct device *dev = &host->pdev->dev;
  1172. host->debug_root = debugfs_create_dir(dev_name(dev), NULL);
  1173. if (IS_ERR(host->debug_root)) {
  1174. dev_err(dev, "failed to create debugfs root\n");
  1175. return;
  1176. }
  1177. host->debug_state = debugfs_create_file("state", 0444,
  1178. host->debug_root, host,
  1179. &s3cmci_fops_state);
  1180. if (IS_ERR(host->debug_state))
  1181. dev_err(dev, "failed to create debug state file\n");
  1182. host->debug_regs = debugfs_create_file("regs", 0444,
  1183. host->debug_root, host,
  1184. &s3cmci_fops_regs);
  1185. if (IS_ERR(host->debug_regs))
  1186. dev_err(dev, "failed to create debug regs file\n");
  1187. }
  1188. static void s3cmci_debugfs_remove(struct s3cmci_host *host)
  1189. {
  1190. debugfs_remove(host->debug_regs);
  1191. debugfs_remove(host->debug_state);
  1192. debugfs_remove(host->debug_root);
  1193. }
  1194. #else
  1195. static inline void s3cmci_debugfs_attach(struct s3cmci_host *host) { }
  1196. static inline void s3cmci_debugfs_remove(struct s3cmci_host *host) { }
  1197. #endif /* CONFIG_DEBUG_FS */
  1198. static int s3cmci_probe_pdata(struct s3cmci_host *host)
  1199. {
  1200. struct platform_device *pdev = host->pdev;
  1201. struct mmc_host *mmc = host->mmc;
  1202. struct s3c24xx_mci_pdata *pdata;
  1203. int i, ret;
  1204. host->is2440 = platform_get_device_id(pdev)->driver_data;
  1205. for (i = S3C2410_GPE(5); i <= S3C2410_GPE(10); i++) {
  1206. ret = gpio_request(i, dev_name(&pdev->dev));
  1207. if (ret) {
  1208. dev_err(&pdev->dev, "failed to get gpio %d\n", i);
  1209. for (i--; i >= S3C2410_GPE(5); i--)
  1210. gpio_free(i);
  1211. return ret;
  1212. }
  1213. }
  1214. if (!pdev->dev.platform_data)
  1215. pdev->dev.platform_data = &s3cmci_def_pdata;
  1216. pdata = pdev->dev.platform_data;
  1217. if (pdata->no_wprotect)
  1218. mmc->caps2 |= MMC_CAP2_NO_WRITE_PROTECT;
  1219. if (pdata->no_detect)
  1220. mmc->caps |= MMC_CAP_NEEDS_POLL;
  1221. if (pdata->wprotect_invert)
  1222. mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
  1223. if (pdata->detect_invert)
  1224. mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
  1225. if (gpio_is_valid(pdata->gpio_detect)) {
  1226. ret = mmc_gpio_request_cd(mmc, pdata->gpio_detect, 0);
  1227. if (ret) {
  1228. dev_err(&pdev->dev, "error requesting GPIO for CD %d\n",
  1229. ret);
  1230. return ret;
  1231. }
  1232. }
  1233. if (gpio_is_valid(pdata->gpio_wprotect)) {
  1234. ret = mmc_gpio_request_ro(mmc, pdata->gpio_wprotect);
  1235. if (ret) {
  1236. dev_err(&pdev->dev, "error requesting GPIO for WP %d\n",
  1237. ret);
  1238. return ret;
  1239. }
  1240. }
  1241. return 0;
  1242. }
  1243. static int s3cmci_probe_dt(struct s3cmci_host *host)
  1244. {
  1245. struct platform_device *pdev = host->pdev;
  1246. struct s3c24xx_mci_pdata *pdata;
  1247. struct mmc_host *mmc = host->mmc;
  1248. int ret;
  1249. host->is2440 = (int) of_device_get_match_data(&pdev->dev);
  1250. ret = mmc_of_parse(mmc);
  1251. if (ret)
  1252. return ret;
  1253. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  1254. if (!pdata)
  1255. return -ENOMEM;
  1256. pdev->dev.platform_data = pdata;
  1257. return 0;
  1258. }
  1259. static int s3cmci_probe(struct platform_device *pdev)
  1260. {
  1261. struct s3cmci_host *host;
  1262. struct mmc_host *mmc;
  1263. int ret;
  1264. int i;
  1265. mmc = mmc_alloc_host(sizeof(struct s3cmci_host), &pdev->dev);
  1266. if (!mmc) {
  1267. ret = -ENOMEM;
  1268. goto probe_out;
  1269. }
  1270. host = mmc_priv(mmc);
  1271. host->mmc = mmc;
  1272. host->pdev = pdev;
  1273. if (pdev->dev.of_node)
  1274. ret = s3cmci_probe_dt(host);
  1275. else
  1276. ret = s3cmci_probe_pdata(host);
  1277. if (ret)
  1278. goto probe_free_host;
  1279. host->pdata = pdev->dev.platform_data;
  1280. spin_lock_init(&host->complete_lock);
  1281. tasklet_init(&host->pio_tasklet, pio_tasklet, (unsigned long) host);
  1282. if (host->is2440) {
  1283. host->sdiimsk = S3C2440_SDIIMSK;
  1284. host->sdidata = S3C2440_SDIDATA;
  1285. host->clk_div = 1;
  1286. } else {
  1287. host->sdiimsk = S3C2410_SDIIMSK;
  1288. host->sdidata = S3C2410_SDIDATA;
  1289. host->clk_div = 2;
  1290. }
  1291. host->complete_what = COMPLETION_NONE;
  1292. host->pio_active = XFER_NONE;
  1293. host->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1294. if (!host->mem) {
  1295. dev_err(&pdev->dev,
  1296. "failed to get io memory region resource.\n");
  1297. ret = -ENOENT;
  1298. goto probe_free_gpio;
  1299. }
  1300. host->mem = request_mem_region(host->mem->start,
  1301. resource_size(host->mem), pdev->name);
  1302. if (!host->mem) {
  1303. dev_err(&pdev->dev, "failed to request io memory region.\n");
  1304. ret = -ENOENT;
  1305. goto probe_free_gpio;
  1306. }
  1307. host->base = ioremap(host->mem->start, resource_size(host->mem));
  1308. if (!host->base) {
  1309. dev_err(&pdev->dev, "failed to ioremap() io memory region.\n");
  1310. ret = -EINVAL;
  1311. goto probe_free_mem_region;
  1312. }
  1313. host->irq = platform_get_irq(pdev, 0);
  1314. if (host->irq == 0) {
  1315. dev_err(&pdev->dev, "failed to get interrupt resource.\n");
  1316. ret = -EINVAL;
  1317. goto probe_iounmap;
  1318. }
  1319. if (request_irq(host->irq, s3cmci_irq, 0, DRIVER_NAME, host)) {
  1320. dev_err(&pdev->dev, "failed to request mci interrupt.\n");
  1321. ret = -ENOENT;
  1322. goto probe_iounmap;
  1323. }
  1324. /* We get spurious interrupts even when we have set the IMSK
  1325. * register to ignore everything, so use disable_irq() to make
  1326. * ensure we don't lock the system with un-serviceable requests. */
  1327. disable_irq(host->irq);
  1328. host->irq_state = false;
  1329. /* Depending on the dma state, get a DMA channel to use. */
  1330. if (s3cmci_host_usedma(host)) {
  1331. host->dma = dma_request_chan(&pdev->dev, "rx-tx");
  1332. ret = PTR_ERR_OR_ZERO(host->dma);
  1333. if (ret) {
  1334. dev_err(&pdev->dev, "cannot get DMA channel.\n");
  1335. goto probe_free_irq;
  1336. }
  1337. }
  1338. host->clk = clk_get(&pdev->dev, "sdi");
  1339. if (IS_ERR(host->clk)) {
  1340. dev_err(&pdev->dev, "failed to find clock source.\n");
  1341. ret = PTR_ERR(host->clk);
  1342. host->clk = NULL;
  1343. goto probe_free_dma;
  1344. }
  1345. ret = clk_prepare_enable(host->clk);
  1346. if (ret) {
  1347. dev_err(&pdev->dev, "failed to enable clock source.\n");
  1348. goto clk_free;
  1349. }
  1350. host->clk_rate = clk_get_rate(host->clk);
  1351. mmc->ops = &s3cmci_ops;
  1352. mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
  1353. #ifdef CONFIG_MMC_S3C_HW_SDIO_IRQ
  1354. mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ;
  1355. #else
  1356. mmc->caps = MMC_CAP_4_BIT_DATA;
  1357. #endif
  1358. mmc->f_min = host->clk_rate / (host->clk_div * 256);
  1359. mmc->f_max = host->clk_rate / host->clk_div;
  1360. if (host->pdata->ocr_avail)
  1361. mmc->ocr_avail = host->pdata->ocr_avail;
  1362. mmc->max_blk_count = 4095;
  1363. mmc->max_blk_size = 4095;
  1364. mmc->max_req_size = 4095 * 512;
  1365. mmc->max_seg_size = mmc->max_req_size;
  1366. mmc->max_segs = 128;
  1367. dbg(host, dbg_debug,
  1368. "probe: mode:%s mapped mci_base:%p irq:%u irq_cd:%u dma:%p.\n",
  1369. (host->is2440?"2440":""),
  1370. host->base, host->irq, host->irq_cd, host->dma);
  1371. ret = s3cmci_cpufreq_register(host);
  1372. if (ret) {
  1373. dev_err(&pdev->dev, "failed to register cpufreq\n");
  1374. goto free_dmabuf;
  1375. }
  1376. ret = mmc_add_host(mmc);
  1377. if (ret) {
  1378. dev_err(&pdev->dev, "failed to add mmc host.\n");
  1379. goto free_cpufreq;
  1380. }
  1381. s3cmci_debugfs_attach(host);
  1382. platform_set_drvdata(pdev, mmc);
  1383. dev_info(&pdev->dev, "%s - using %s, %s SDIO IRQ\n", mmc_hostname(mmc),
  1384. s3cmci_host_usedma(host) ? "dma" : "pio",
  1385. mmc->caps & MMC_CAP_SDIO_IRQ ? "hw" : "sw");
  1386. return 0;
  1387. free_cpufreq:
  1388. s3cmci_cpufreq_deregister(host);
  1389. free_dmabuf:
  1390. clk_disable_unprepare(host->clk);
  1391. clk_free:
  1392. clk_put(host->clk);
  1393. probe_free_dma:
  1394. if (s3cmci_host_usedma(host))
  1395. dma_release_channel(host->dma);
  1396. probe_free_irq:
  1397. free_irq(host->irq, host);
  1398. probe_iounmap:
  1399. iounmap(host->base);
  1400. probe_free_mem_region:
  1401. release_mem_region(host->mem->start, resource_size(host->mem));
  1402. probe_free_gpio:
  1403. if (!pdev->dev.of_node)
  1404. for (i = S3C2410_GPE(5); i <= S3C2410_GPE(10); i++)
  1405. gpio_free(i);
  1406. probe_free_host:
  1407. mmc_free_host(mmc);
  1408. probe_out:
  1409. return ret;
  1410. }
  1411. static void s3cmci_shutdown(struct platform_device *pdev)
  1412. {
  1413. struct mmc_host *mmc = platform_get_drvdata(pdev);
  1414. struct s3cmci_host *host = mmc_priv(mmc);
  1415. if (host->irq_cd >= 0)
  1416. free_irq(host->irq_cd, host);
  1417. s3cmci_debugfs_remove(host);
  1418. s3cmci_cpufreq_deregister(host);
  1419. mmc_remove_host(mmc);
  1420. clk_disable_unprepare(host->clk);
  1421. }
  1422. static int s3cmci_remove(struct platform_device *pdev)
  1423. {
  1424. struct mmc_host *mmc = platform_get_drvdata(pdev);
  1425. struct s3cmci_host *host = mmc_priv(mmc);
  1426. int i;
  1427. s3cmci_shutdown(pdev);
  1428. clk_put(host->clk);
  1429. tasklet_disable(&host->pio_tasklet);
  1430. if (s3cmci_host_usedma(host))
  1431. dma_release_channel(host->dma);
  1432. free_irq(host->irq, host);
  1433. if (!pdev->dev.of_node)
  1434. for (i = S3C2410_GPE(5); i <= S3C2410_GPE(10); i++)
  1435. gpio_free(i);
  1436. iounmap(host->base);
  1437. release_mem_region(host->mem->start, resource_size(host->mem));
  1438. mmc_free_host(mmc);
  1439. return 0;
  1440. }
  1441. static const struct of_device_id s3cmci_dt_match[] = {
  1442. {
  1443. .compatible = "samsung,s3c2410-sdi",
  1444. .data = (void *)0,
  1445. },
  1446. {
  1447. .compatible = "samsung,s3c2412-sdi",
  1448. .data = (void *)1,
  1449. },
  1450. {
  1451. .compatible = "samsung,s3c2440-sdi",
  1452. .data = (void *)1,
  1453. },
  1454. { /* sentinel */ },
  1455. };
  1456. MODULE_DEVICE_TABLE(of, s3cmci_dt_match);
  1457. static const struct platform_device_id s3cmci_driver_ids[] = {
  1458. {
  1459. .name = "s3c2410-sdi",
  1460. .driver_data = 0,
  1461. }, {
  1462. .name = "s3c2412-sdi",
  1463. .driver_data = 1,
  1464. }, {
  1465. .name = "s3c2440-sdi",
  1466. .driver_data = 1,
  1467. },
  1468. { }
  1469. };
  1470. MODULE_DEVICE_TABLE(platform, s3cmci_driver_ids);
  1471. static struct platform_driver s3cmci_driver = {
  1472. .driver = {
  1473. .name = "s3c-sdi",
  1474. .of_match_table = s3cmci_dt_match,
  1475. },
  1476. .id_table = s3cmci_driver_ids,
  1477. .probe = s3cmci_probe,
  1478. .remove = s3cmci_remove,
  1479. .shutdown = s3cmci_shutdown,
  1480. };
  1481. module_platform_driver(s3cmci_driver);
  1482. MODULE_DESCRIPTION("Samsung S3C MMC/SD Card Interface driver");
  1483. MODULE_LICENSE("GPL v2");
  1484. MODULE_AUTHOR("Thomas Kleffel <tk@maintech.de>, Ben Dooks <ben-linux@fluff.org>");