s3cmci.c 45 KB

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