s3cmci.c 46 KB

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