s3cmci.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879
  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. };
  1131. static const struct s3cmci_reg debug_regs[] = {
  1132. DBG_REG(CON),
  1133. DBG_REG(PRE),
  1134. DBG_REG(CMDARG),
  1135. DBG_REG(CMDCON),
  1136. DBG_REG(CMDSTAT),
  1137. DBG_REG(RSP0),
  1138. DBG_REG(RSP1),
  1139. DBG_REG(RSP2),
  1140. DBG_REG(RSP3),
  1141. DBG_REG(TIMER),
  1142. DBG_REG(BSIZE),
  1143. DBG_REG(DCON),
  1144. DBG_REG(DCNT),
  1145. DBG_REG(DSTA),
  1146. DBG_REG(FSTA),
  1147. {}
  1148. };
  1149. static int s3cmci_regs_show(struct seq_file *seq, void *v)
  1150. {
  1151. struct s3cmci_host *host = seq->private;
  1152. const struct s3cmci_reg *rptr = debug_regs;
  1153. for (; rptr->name; rptr++)
  1154. seq_printf(seq, "SDI%s\t=0x%08x\n", rptr->name,
  1155. readl(host->base + rptr->addr));
  1156. seq_printf(seq, "SDIIMSK\t=0x%08x\n", readl(host->base + host->sdiimsk));
  1157. return 0;
  1158. }
  1159. static int s3cmci_regs_open(struct inode *inode, struct file *file)
  1160. {
  1161. return single_open(file, s3cmci_regs_show, inode->i_private);
  1162. }
  1163. static const struct file_operations s3cmci_fops_regs = {
  1164. .owner = THIS_MODULE,
  1165. .open = s3cmci_regs_open,
  1166. .read = seq_read,
  1167. .llseek = seq_lseek,
  1168. .release = single_release,
  1169. };
  1170. static void s3cmci_debugfs_attach(struct s3cmci_host *host)
  1171. {
  1172. struct device *dev = &host->pdev->dev;
  1173. host->debug_root = debugfs_create_dir(dev_name(dev), NULL);
  1174. if (IS_ERR(host->debug_root)) {
  1175. dev_err(dev, "failed to create debugfs root\n");
  1176. return;
  1177. }
  1178. host->debug_state = debugfs_create_file("state", 0444,
  1179. host->debug_root, host,
  1180. &s3cmci_fops_state);
  1181. if (IS_ERR(host->debug_state))
  1182. dev_err(dev, "failed to create debug state file\n");
  1183. host->debug_regs = debugfs_create_file("regs", 0444,
  1184. host->debug_root, host,
  1185. &s3cmci_fops_regs);
  1186. if (IS_ERR(host->debug_regs))
  1187. dev_err(dev, "failed to create debug regs file\n");
  1188. }
  1189. static void s3cmci_debugfs_remove(struct s3cmci_host *host)
  1190. {
  1191. debugfs_remove(host->debug_regs);
  1192. debugfs_remove(host->debug_state);
  1193. debugfs_remove(host->debug_root);
  1194. }
  1195. #else
  1196. static inline void s3cmci_debugfs_attach(struct s3cmci_host *host) { }
  1197. static inline void s3cmci_debugfs_remove(struct s3cmci_host *host) { }
  1198. #endif /* CONFIG_DEBUG_FS */
  1199. static int s3cmci_probe_pdata(struct s3cmci_host *host)
  1200. {
  1201. struct platform_device *pdev = host->pdev;
  1202. struct mmc_host *mmc = host->mmc;
  1203. struct s3c24xx_mci_pdata *pdata;
  1204. int i, ret;
  1205. host->is2440 = platform_get_device_id(pdev)->driver_data;
  1206. for (i = S3C2410_GPE(5); i <= S3C2410_GPE(10); i++) {
  1207. ret = gpio_request(i, dev_name(&pdev->dev));
  1208. if (ret) {
  1209. dev_err(&pdev->dev, "failed to get gpio %d\n", i);
  1210. for (i--; i >= S3C2410_GPE(5); i--)
  1211. gpio_free(i);
  1212. return ret;
  1213. }
  1214. }
  1215. if (!pdev->dev.platform_data)
  1216. pdev->dev.platform_data = &s3cmci_def_pdata;
  1217. pdata = pdev->dev.platform_data;
  1218. if (pdata->no_wprotect)
  1219. mmc->caps2 |= MMC_CAP2_NO_WRITE_PROTECT;
  1220. if (pdata->no_detect)
  1221. mmc->caps |= MMC_CAP_NEEDS_POLL;
  1222. if (pdata->wprotect_invert)
  1223. mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
  1224. if (pdata->detect_invert)
  1225. mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
  1226. if (gpio_is_valid(pdata->gpio_detect)) {
  1227. ret = mmc_gpio_request_cd(mmc, pdata->gpio_detect, 0);
  1228. if (ret) {
  1229. dev_err(&pdev->dev, "error requesting GPIO for CD %d\n",
  1230. ret);
  1231. return ret;
  1232. }
  1233. }
  1234. if (gpio_is_valid(pdata->gpio_wprotect)) {
  1235. ret = mmc_gpio_request_ro(mmc, pdata->gpio_wprotect);
  1236. if (ret) {
  1237. dev_err(&pdev->dev, "error requesting GPIO for WP %d\n",
  1238. ret);
  1239. return ret;
  1240. }
  1241. }
  1242. return 0;
  1243. }
  1244. static int s3cmci_probe_dt(struct s3cmci_host *host)
  1245. {
  1246. struct platform_device *pdev = host->pdev;
  1247. struct s3c24xx_mci_pdata *pdata;
  1248. struct mmc_host *mmc = host->mmc;
  1249. int ret;
  1250. host->is2440 = (int) of_device_get_match_data(&pdev->dev);
  1251. ret = mmc_of_parse(mmc);
  1252. if (ret)
  1253. return ret;
  1254. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  1255. if (!pdata)
  1256. return -ENOMEM;
  1257. pdev->dev.platform_data = pdata;
  1258. return 0;
  1259. }
  1260. static int s3cmci_probe(struct platform_device *pdev)
  1261. {
  1262. struct s3cmci_host *host;
  1263. struct mmc_host *mmc;
  1264. int ret;
  1265. int i;
  1266. mmc = mmc_alloc_host(sizeof(struct s3cmci_host), &pdev->dev);
  1267. if (!mmc) {
  1268. ret = -ENOMEM;
  1269. goto probe_out;
  1270. }
  1271. host = mmc_priv(mmc);
  1272. host->mmc = mmc;
  1273. host->pdev = pdev;
  1274. if (pdev->dev.of_node)
  1275. ret = s3cmci_probe_dt(host);
  1276. else
  1277. ret = s3cmci_probe_pdata(host);
  1278. if (ret)
  1279. goto probe_free_host;
  1280. host->pdata = pdev->dev.platform_data;
  1281. spin_lock_init(&host->complete_lock);
  1282. tasklet_init(&host->pio_tasklet, pio_tasklet, (unsigned long) host);
  1283. if (host->is2440) {
  1284. host->sdiimsk = S3C2440_SDIIMSK;
  1285. host->sdidata = S3C2440_SDIDATA;
  1286. host->clk_div = 1;
  1287. } else {
  1288. host->sdiimsk = S3C2410_SDIIMSK;
  1289. host->sdidata = S3C2410_SDIDATA;
  1290. host->clk_div = 2;
  1291. }
  1292. host->complete_what = COMPLETION_NONE;
  1293. host->pio_active = XFER_NONE;
  1294. host->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1295. if (!host->mem) {
  1296. dev_err(&pdev->dev,
  1297. "failed to get io memory region resource.\n");
  1298. ret = -ENOENT;
  1299. goto probe_free_gpio;
  1300. }
  1301. host->mem = request_mem_region(host->mem->start,
  1302. resource_size(host->mem), pdev->name);
  1303. if (!host->mem) {
  1304. dev_err(&pdev->dev, "failed to request io memory region.\n");
  1305. ret = -ENOENT;
  1306. goto probe_free_gpio;
  1307. }
  1308. host->base = ioremap(host->mem->start, resource_size(host->mem));
  1309. if (!host->base) {
  1310. dev_err(&pdev->dev, "failed to ioremap() io memory region.\n");
  1311. ret = -EINVAL;
  1312. goto probe_free_mem_region;
  1313. }
  1314. host->irq = platform_get_irq(pdev, 0);
  1315. if (host->irq <= 0) {
  1316. dev_err(&pdev->dev, "failed to get interrupt resource.\n");
  1317. ret = -EINVAL;
  1318. goto probe_iounmap;
  1319. }
  1320. if (request_irq(host->irq, s3cmci_irq, 0, DRIVER_NAME, host)) {
  1321. dev_err(&pdev->dev, "failed to request mci interrupt.\n");
  1322. ret = -ENOENT;
  1323. goto probe_iounmap;
  1324. }
  1325. /* We get spurious interrupts even when we have set the IMSK
  1326. * register to ignore everything, so use disable_irq() to make
  1327. * ensure we don't lock the system with un-serviceable requests. */
  1328. disable_irq(host->irq);
  1329. host->irq_state = false;
  1330. /* Depending on the dma state, get a DMA channel to use. */
  1331. if (s3cmci_host_usedma(host)) {
  1332. host->dma = dma_request_chan(&pdev->dev, "rx-tx");
  1333. ret = PTR_ERR_OR_ZERO(host->dma);
  1334. if (ret) {
  1335. dev_err(&pdev->dev, "cannot get DMA channel.\n");
  1336. goto probe_free_irq;
  1337. }
  1338. }
  1339. host->clk = clk_get(&pdev->dev, "sdi");
  1340. if (IS_ERR(host->clk)) {
  1341. dev_err(&pdev->dev, "failed to find clock source.\n");
  1342. ret = PTR_ERR(host->clk);
  1343. host->clk = NULL;
  1344. goto probe_free_dma;
  1345. }
  1346. ret = clk_prepare_enable(host->clk);
  1347. if (ret) {
  1348. dev_err(&pdev->dev, "failed to enable clock source.\n");
  1349. goto clk_free;
  1350. }
  1351. host->clk_rate = clk_get_rate(host->clk);
  1352. mmc->ops = &s3cmci_ops;
  1353. mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
  1354. #ifdef CONFIG_MMC_S3C_HW_SDIO_IRQ
  1355. mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ;
  1356. #else
  1357. mmc->caps = MMC_CAP_4_BIT_DATA;
  1358. #endif
  1359. mmc->f_min = host->clk_rate / (host->clk_div * 256);
  1360. mmc->f_max = host->clk_rate / host->clk_div;
  1361. if (host->pdata->ocr_avail)
  1362. mmc->ocr_avail = host->pdata->ocr_avail;
  1363. mmc->max_blk_count = 4095;
  1364. mmc->max_blk_size = 4095;
  1365. mmc->max_req_size = 4095 * 512;
  1366. mmc->max_seg_size = mmc->max_req_size;
  1367. mmc->max_segs = 128;
  1368. dbg(host, dbg_debug,
  1369. "probe: mode:%s mapped mci_base:%p irq:%u irq_cd:%u dma:%p.\n",
  1370. (host->is2440?"2440":""),
  1371. host->base, host->irq, host->irq_cd, host->dma);
  1372. ret = s3cmci_cpufreq_register(host);
  1373. if (ret) {
  1374. dev_err(&pdev->dev, "failed to register cpufreq\n");
  1375. goto free_dmabuf;
  1376. }
  1377. ret = mmc_add_host(mmc);
  1378. if (ret) {
  1379. dev_err(&pdev->dev, "failed to add mmc host.\n");
  1380. goto free_cpufreq;
  1381. }
  1382. s3cmci_debugfs_attach(host);
  1383. platform_set_drvdata(pdev, mmc);
  1384. dev_info(&pdev->dev, "%s - using %s, %s SDIO IRQ\n", mmc_hostname(mmc),
  1385. s3cmci_host_usedma(host) ? "dma" : "pio",
  1386. mmc->caps & MMC_CAP_SDIO_IRQ ? "hw" : "sw");
  1387. return 0;
  1388. free_cpufreq:
  1389. s3cmci_cpufreq_deregister(host);
  1390. free_dmabuf:
  1391. clk_disable_unprepare(host->clk);
  1392. clk_free:
  1393. clk_put(host->clk);
  1394. probe_free_dma:
  1395. if (s3cmci_host_usedma(host))
  1396. dma_release_channel(host->dma);
  1397. probe_free_irq:
  1398. free_irq(host->irq, host);
  1399. probe_iounmap:
  1400. iounmap(host->base);
  1401. probe_free_mem_region:
  1402. release_mem_region(host->mem->start, resource_size(host->mem));
  1403. probe_free_gpio:
  1404. if (!pdev->dev.of_node)
  1405. for (i = S3C2410_GPE(5); i <= S3C2410_GPE(10); i++)
  1406. gpio_free(i);
  1407. probe_free_host:
  1408. mmc_free_host(mmc);
  1409. probe_out:
  1410. return ret;
  1411. }
  1412. static void s3cmci_shutdown(struct platform_device *pdev)
  1413. {
  1414. struct mmc_host *mmc = platform_get_drvdata(pdev);
  1415. struct s3cmci_host *host = mmc_priv(mmc);
  1416. if (host->irq_cd >= 0)
  1417. free_irq(host->irq_cd, host);
  1418. s3cmci_debugfs_remove(host);
  1419. s3cmci_cpufreq_deregister(host);
  1420. mmc_remove_host(mmc);
  1421. clk_disable_unprepare(host->clk);
  1422. }
  1423. static int s3cmci_remove(struct platform_device *pdev)
  1424. {
  1425. struct mmc_host *mmc = platform_get_drvdata(pdev);
  1426. struct s3cmci_host *host = mmc_priv(mmc);
  1427. int i;
  1428. s3cmci_shutdown(pdev);
  1429. clk_put(host->clk);
  1430. tasklet_disable(&host->pio_tasklet);
  1431. if (s3cmci_host_usedma(host))
  1432. dma_release_channel(host->dma);
  1433. free_irq(host->irq, host);
  1434. if (!pdev->dev.of_node)
  1435. for (i = S3C2410_GPE(5); i <= S3C2410_GPE(10); i++)
  1436. gpio_free(i);
  1437. iounmap(host->base);
  1438. release_mem_region(host->mem->start, resource_size(host->mem));
  1439. mmc_free_host(mmc);
  1440. return 0;
  1441. }
  1442. static const struct of_device_id s3cmci_dt_match[] = {
  1443. {
  1444. .compatible = "samsung,s3c2410-sdi",
  1445. .data = (void *)0,
  1446. },
  1447. {
  1448. .compatible = "samsung,s3c2412-sdi",
  1449. .data = (void *)1,
  1450. },
  1451. {
  1452. .compatible = "samsung,s3c2440-sdi",
  1453. .data = (void *)1,
  1454. },
  1455. { /* sentinel */ },
  1456. };
  1457. MODULE_DEVICE_TABLE(of, s3cmci_dt_match);
  1458. static const struct platform_device_id s3cmci_driver_ids[] = {
  1459. {
  1460. .name = "s3c2410-sdi",
  1461. .driver_data = 0,
  1462. }, {
  1463. .name = "s3c2412-sdi",
  1464. .driver_data = 1,
  1465. }, {
  1466. .name = "s3c2440-sdi",
  1467. .driver_data = 1,
  1468. },
  1469. { }
  1470. };
  1471. MODULE_DEVICE_TABLE(platform, s3cmci_driver_ids);
  1472. static struct platform_driver s3cmci_driver = {
  1473. .driver = {
  1474. .name = "s3c-sdi",
  1475. .of_match_table = s3cmci_dt_match,
  1476. },
  1477. .id_table = s3cmci_driver_ids,
  1478. .probe = s3cmci_probe,
  1479. .remove = s3cmci_remove,
  1480. .shutdown = s3cmci_shutdown,
  1481. };
  1482. module_platform_driver(s3cmci_driver);
  1483. MODULE_DESCRIPTION("Samsung S3C MMC/SD Card Interface driver");
  1484. MODULE_LICENSE("GPL v2");
  1485. MODULE_AUTHOR("Thomas Kleffel <tk@maintech.de>, Ben Dooks <ben-linux@fluff.org>");