s3cmci.c 46 KB

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