s3cmci.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  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. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/dma-mapping.h>
  12. #include <linux/clk.h>
  13. #include <linux/mmc/host.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/irq.h>
  16. #include <linux/io.h>
  17. #include <asm/dma.h>
  18. #include <asm/arch/regs-sdi.h>
  19. #include <asm/arch/regs-gpio.h>
  20. #include "s3cmci.h"
  21. #define DRIVER_NAME "s3c-mci"
  22. enum dbg_channels {
  23. dbg_err = (1 << 0),
  24. dbg_debug = (1 << 1),
  25. dbg_info = (1 << 2),
  26. dbg_irq = (1 << 3),
  27. dbg_sg = (1 << 4),
  28. dbg_dma = (1 << 5),
  29. dbg_pio = (1 << 6),
  30. dbg_fail = (1 << 7),
  31. dbg_conf = (1 << 8),
  32. };
  33. static const int dbgmap_err = dbg_err | dbg_fail;
  34. static const int dbgmap_info = dbg_info | dbg_conf;
  35. static const int dbgmap_debug = dbg_debug;
  36. #define dbg(host, channels, args...) \
  37. do { \
  38. if (dbgmap_err & channels) \
  39. dev_err(&host->pdev->dev, args); \
  40. else if (dbgmap_info & channels) \
  41. dev_info(&host->pdev->dev, args); \
  42. else if (dbgmap_debug & channels) \
  43. dev_dbg(&host->pdev->dev, args); \
  44. } while (0)
  45. #define RESSIZE(ressource) (((ressource)->end - (ressource)->start)+1)
  46. static struct s3c2410_dma_client s3cmci_dma_client = {
  47. .name = "s3c-mci",
  48. };
  49. static void finalize_request(struct s3cmci_host *host);
  50. static void s3cmci_send_request(struct mmc_host *mmc);
  51. static void s3cmci_reset(struct s3cmci_host *host);
  52. #ifdef CONFIG_MMC_DEBUG
  53. static void dbg_dumpregs(struct s3cmci_host *host, char *prefix)
  54. {
  55. u32 con, pre, cmdarg, cmdcon, cmdsta, r0, r1, r2, r3, timer, bsize;
  56. u32 datcon, datcnt, datsta, fsta, imask;
  57. con = readl(host->base + S3C2410_SDICON);
  58. pre = readl(host->base + S3C2410_SDIPRE);
  59. cmdarg = readl(host->base + S3C2410_SDICMDARG);
  60. cmdcon = readl(host->base + S3C2410_SDICMDCON);
  61. cmdsta = readl(host->base + S3C2410_SDICMDSTAT);
  62. r0 = readl(host->base + S3C2410_SDIRSP0);
  63. r1 = readl(host->base + S3C2410_SDIRSP1);
  64. r2 = readl(host->base + S3C2410_SDIRSP2);
  65. r3 = readl(host->base + S3C2410_SDIRSP3);
  66. timer = readl(host->base + S3C2410_SDITIMER);
  67. bsize = readl(host->base + S3C2410_SDIBSIZE);
  68. datcon = readl(host->base + S3C2410_SDIDCON);
  69. datcnt = readl(host->base + S3C2410_SDIDCNT);
  70. datsta = readl(host->base + S3C2410_SDIDSTA);
  71. fsta = readl(host->base + S3C2410_SDIFSTA);
  72. imask = readl(host->base + host->sdiimsk);
  73. dbg(host, dbg_debug, "%s CON:[%08x] PRE:[%08x] TMR:[%08x]\n",
  74. prefix, con, pre, timer);
  75. dbg(host, dbg_debug, "%s CCON:[%08x] CARG:[%08x] CSTA:[%08x]\n",
  76. prefix, cmdcon, cmdarg, cmdsta);
  77. dbg(host, dbg_debug, "%s DCON:[%08x] FSTA:[%08x]"
  78. " DSTA:[%08x] DCNT:[%08x]\n",
  79. prefix, datcon, fsta, datsta, datcnt);
  80. dbg(host, dbg_debug, "%s R0:[%08x] R1:[%08x]"
  81. " R2:[%08x] R3:[%08x]\n",
  82. prefix, r0, r1, r2, r3);
  83. }
  84. static void prepare_dbgmsg(struct s3cmci_host *host, struct mmc_command *cmd,
  85. int stop)
  86. {
  87. snprintf(host->dbgmsg_cmd, 300,
  88. "#%u%s op:%i arg:0x%08x flags:0x08%x retries:%u",
  89. host->ccnt, (stop ? " (STOP)" : ""),
  90. cmd->opcode, cmd->arg, cmd->flags, cmd->retries);
  91. if (cmd->data) {
  92. snprintf(host->dbgmsg_dat, 300,
  93. "#%u bsize:%u blocks:%u bytes:%u",
  94. host->dcnt, cmd->data->blksz,
  95. cmd->data->blocks,
  96. cmd->data->blocks * cmd->data->blksz);
  97. } else {
  98. host->dbgmsg_dat[0] = '\0';
  99. }
  100. }
  101. static void dbg_dumpcmd(struct s3cmci_host *host, struct mmc_command *cmd,
  102. int fail)
  103. {
  104. unsigned int dbglvl = fail ? dbg_fail : dbg_debug;
  105. if (!cmd)
  106. return;
  107. if (cmd->error == 0) {
  108. dbg(host, dbglvl, "CMD[OK] %s R0:0x%08x\n",
  109. host->dbgmsg_cmd, cmd->resp[0]);
  110. } else {
  111. dbg(host, dbglvl, "CMD[ERR %i] %s Status:%s\n",
  112. cmd->error, host->dbgmsg_cmd, host->status);
  113. }
  114. if (!cmd->data)
  115. return;
  116. if (cmd->data->error == 0) {
  117. dbg(host, dbglvl, "DAT[OK] %s\n", host->dbgmsg_dat);
  118. } else {
  119. dbg(host, dbglvl, "DAT[ERR %i] %s DCNT:0x%08x\n",
  120. cmd->data->error, host->dbgmsg_dat,
  121. readl(host->base + S3C2410_SDIDCNT));
  122. }
  123. }
  124. #else
  125. static void dbg_dumpcmd(struct s3cmci_host *host,
  126. struct mmc_command *cmd, int fail) { }
  127. static void prepare_dbgmsg(struct s3cmci_host *host, struct mmc_command *cmd,
  128. int stop) { }
  129. static void dbg_dumpregs(struct s3cmci_host *host, char *prefix) { }
  130. #endif /* CONFIG_MMC_DEBUG */
  131. static inline u32 enable_imask(struct s3cmci_host *host, u32 imask)
  132. {
  133. u32 newmask;
  134. newmask = readl(host->base + host->sdiimsk);
  135. newmask |= imask;
  136. writel(newmask, host->base + host->sdiimsk);
  137. return newmask;
  138. }
  139. static inline u32 disable_imask(struct s3cmci_host *host, u32 imask)
  140. {
  141. u32 newmask;
  142. newmask = readl(host->base + host->sdiimsk);
  143. newmask &= ~imask;
  144. writel(newmask, host->base + host->sdiimsk);
  145. return newmask;
  146. }
  147. static inline void clear_imask(struct s3cmci_host *host)
  148. {
  149. writel(0, host->base + host->sdiimsk);
  150. }
  151. static inline int get_data_buffer(struct s3cmci_host *host,
  152. u32 *words, u32 **pointer)
  153. {
  154. struct scatterlist *sg;
  155. if (host->pio_active == XFER_NONE)
  156. return -EINVAL;
  157. if ((!host->mrq) || (!host->mrq->data))
  158. return -EINVAL;
  159. if (host->pio_sgptr >= host->mrq->data->sg_len) {
  160. dbg(host, dbg_debug, "no more buffers (%i/%i)\n",
  161. host->pio_sgptr, host->mrq->data->sg_len);
  162. return -EBUSY;
  163. }
  164. sg = &host->mrq->data->sg[host->pio_sgptr];
  165. *words = sg->length >> 2;
  166. *pointer = sg_virt(sg);
  167. host->pio_sgptr++;
  168. dbg(host, dbg_sg, "new buffer (%i/%i)\n",
  169. host->pio_sgptr, host->mrq->data->sg_len);
  170. return 0;
  171. }
  172. static inline u32 fifo_count(struct s3cmci_host *host)
  173. {
  174. u32 fifostat = readl(host->base + S3C2410_SDIFSTA);
  175. fifostat &= S3C2410_SDIFSTA_COUNTMASK;
  176. return fifostat >> 2;
  177. }
  178. static inline u32 fifo_free(struct s3cmci_host *host)
  179. {
  180. u32 fifostat = readl(host->base + S3C2410_SDIFSTA);
  181. fifostat &= S3C2410_SDIFSTA_COUNTMASK;
  182. return (63 - fifostat) >> 2;
  183. }
  184. static void do_pio_read(struct s3cmci_host *host)
  185. {
  186. int res;
  187. u32 fifo;
  188. void __iomem *from_ptr;
  189. /* write real prescaler to host, it might be set slow to fix */
  190. writel(host->prescaler, host->base + S3C2410_SDIPRE);
  191. from_ptr = host->base + host->sdidata;
  192. while ((fifo = fifo_count(host))) {
  193. if (!host->pio_words) {
  194. res = get_data_buffer(host, &host->pio_words,
  195. &host->pio_ptr);
  196. if (res) {
  197. host->pio_active = XFER_NONE;
  198. host->complete_what = COMPLETION_FINALIZE;
  199. dbg(host, dbg_pio, "pio_read(): "
  200. "complete (no more data).\n");
  201. return;
  202. }
  203. dbg(host, dbg_pio,
  204. "pio_read(): new target: [%i]@[%p]\n",
  205. host->pio_words, host->pio_ptr);
  206. }
  207. dbg(host, dbg_pio,
  208. "pio_read(): fifo:[%02i] buffer:[%03i] dcnt:[%08X]\n",
  209. fifo, host->pio_words,
  210. readl(host->base + S3C2410_SDIDCNT));
  211. if (fifo > host->pio_words)
  212. fifo = host->pio_words;
  213. host->pio_words -= fifo;
  214. host->pio_count += fifo;
  215. while (fifo--)
  216. *(host->pio_ptr++) = readl(from_ptr);
  217. }
  218. if (!host->pio_words) {
  219. res = get_data_buffer(host, &host->pio_words, &host->pio_ptr);
  220. if (res) {
  221. dbg(host, dbg_pio,
  222. "pio_read(): complete (no more buffers).\n");
  223. host->pio_active = XFER_NONE;
  224. host->complete_what = COMPLETION_FINALIZE;
  225. return;
  226. }
  227. }
  228. enable_imask(host,
  229. S3C2410_SDIIMSK_RXFIFOHALF | S3C2410_SDIIMSK_RXFIFOLAST);
  230. }
  231. static void do_pio_write(struct s3cmci_host *host)
  232. {
  233. void __iomem *to_ptr;
  234. int res;
  235. u32 fifo;
  236. to_ptr = host->base + host->sdidata;
  237. while ((fifo = fifo_free(host))) {
  238. if (!host->pio_words) {
  239. res = get_data_buffer(host, &host->pio_words,
  240. &host->pio_ptr);
  241. if (res) {
  242. dbg(host, dbg_pio,
  243. "pio_write(): complete (no more data).\n");
  244. host->pio_active = XFER_NONE;
  245. return;
  246. }
  247. dbg(host, dbg_pio,
  248. "pio_write(): new source: [%i]@[%p]\n",
  249. host->pio_words, host->pio_ptr);
  250. }
  251. if (fifo > host->pio_words)
  252. fifo = host->pio_words;
  253. host->pio_words -= fifo;
  254. host->pio_count += fifo;
  255. while (fifo--)
  256. writel(*(host->pio_ptr++), to_ptr);
  257. }
  258. enable_imask(host, S3C2410_SDIIMSK_TXFIFOHALF);
  259. }
  260. static void pio_tasklet(unsigned long data)
  261. {
  262. struct s3cmci_host *host = (struct s3cmci_host *) data;
  263. if (host->pio_active == XFER_WRITE)
  264. do_pio_write(host);
  265. if (host->pio_active == XFER_READ)
  266. do_pio_read(host);
  267. if (host->complete_what == COMPLETION_FINALIZE) {
  268. clear_imask(host);
  269. if (host->pio_active != XFER_NONE) {
  270. dbg(host, dbg_err, "unfinished %s "
  271. "- pio_count:[%u] pio_words:[%u]\n",
  272. (host->pio_active == XFER_READ) ? "read" : "write",
  273. host->pio_count, host->pio_words);
  274. host->mrq->data->error = -EINVAL;
  275. }
  276. disable_irq(host->irq);
  277. finalize_request(host);
  278. }
  279. }
  280. /*
  281. * ISR for SDI Interface IRQ
  282. * Communication between driver and ISR works as follows:
  283. * host->mrq points to current request
  284. * host->complete_what Indicates when the request is considered done
  285. * COMPLETION_CMDSENT when the command was sent
  286. * COMPLETION_RSPFIN when a response was received
  287. * COMPLETION_XFERFINISH when the data transfer is finished
  288. * COMPLETION_XFERFINISH_RSPFIN both of the above.
  289. * host->complete_request is the completion-object the driver waits for
  290. *
  291. * 1) Driver sets up host->mrq and host->complete_what
  292. * 2) Driver prepares the transfer
  293. * 3) Driver enables interrupts
  294. * 4) Driver starts transfer
  295. * 5) Driver waits for host->complete_rquest
  296. * 6) ISR checks for request status (errors and success)
  297. * 6) ISR sets host->mrq->cmd->error and host->mrq->data->error
  298. * 7) ISR completes host->complete_request
  299. * 8) ISR disables interrupts
  300. * 9) Driver wakes up and takes care of the request
  301. *
  302. * Note: "->error"-fields are expected to be set to 0 before the request
  303. * was issued by mmc.c - therefore they are only set, when an error
  304. * contition comes up
  305. */
  306. static irqreturn_t s3cmci_irq(int irq, void *dev_id)
  307. {
  308. struct s3cmci_host *host = dev_id;
  309. struct mmc_command *cmd;
  310. u32 mci_csta, mci_dsta, mci_fsta, mci_dcnt, mci_imsk;
  311. u32 mci_cclear, mci_dclear;
  312. unsigned long iflags;
  313. spin_lock_irqsave(&host->complete_lock, iflags);
  314. mci_csta = readl(host->base + S3C2410_SDICMDSTAT);
  315. mci_dsta = readl(host->base + S3C2410_SDIDSTA);
  316. mci_dcnt = readl(host->base + S3C2410_SDIDCNT);
  317. mci_fsta = readl(host->base + S3C2410_SDIFSTA);
  318. mci_imsk = readl(host->base + host->sdiimsk);
  319. mci_cclear = 0;
  320. mci_dclear = 0;
  321. if ((host->complete_what == COMPLETION_NONE) ||
  322. (host->complete_what == COMPLETION_FINALIZE)) {
  323. host->status = "nothing to complete";
  324. clear_imask(host);
  325. goto irq_out;
  326. }
  327. if (!host->mrq) {
  328. host->status = "no active mrq";
  329. clear_imask(host);
  330. goto irq_out;
  331. }
  332. cmd = host->cmd_is_stop ? host->mrq->stop : host->mrq->cmd;
  333. if (!cmd) {
  334. host->status = "no active cmd";
  335. clear_imask(host);
  336. goto irq_out;
  337. }
  338. if (!host->dodma) {
  339. if ((host->pio_active == XFER_WRITE) &&
  340. (mci_fsta & S3C2410_SDIFSTA_TFDET)) {
  341. disable_imask(host, S3C2410_SDIIMSK_TXFIFOHALF);
  342. tasklet_schedule(&host->pio_tasklet);
  343. host->status = "pio tx";
  344. }
  345. if ((host->pio_active == XFER_READ) &&
  346. (mci_fsta & S3C2410_SDIFSTA_RFDET)) {
  347. disable_imask(host,
  348. S3C2410_SDIIMSK_RXFIFOHALF |
  349. S3C2410_SDIIMSK_RXFIFOLAST);
  350. tasklet_schedule(&host->pio_tasklet);
  351. host->status = "pio rx";
  352. }
  353. }
  354. if (mci_csta & S3C2410_SDICMDSTAT_CMDTIMEOUT) {
  355. cmd->error = -ETIMEDOUT;
  356. host->status = "error: command timeout";
  357. goto fail_transfer;
  358. }
  359. if (mci_csta & S3C2410_SDICMDSTAT_CMDSENT) {
  360. if (host->complete_what == COMPLETION_CMDSENT) {
  361. host->status = "ok: command sent";
  362. goto close_transfer;
  363. }
  364. mci_cclear |= S3C2410_SDICMDSTAT_CMDSENT;
  365. }
  366. if (mci_csta & S3C2410_SDICMDSTAT_CRCFAIL) {
  367. if (cmd->flags & MMC_RSP_CRC) {
  368. if (host->mrq->cmd->flags & MMC_RSP_136) {
  369. dbg(host, dbg_irq,
  370. "fixup: ignore CRC fail with long rsp\n");
  371. } else {
  372. /* note, we used to fail the transfer
  373. * here, but it seems that this is just
  374. * the hardware getting it wrong.
  375. *
  376. * cmd->error = -EILSEQ;
  377. * host->status = "error: bad command crc";
  378. * goto fail_transfer;
  379. */
  380. }
  381. }
  382. mci_cclear |= S3C2410_SDICMDSTAT_CRCFAIL;
  383. }
  384. if (mci_csta & S3C2410_SDICMDSTAT_RSPFIN) {
  385. if (host->complete_what == COMPLETION_RSPFIN) {
  386. host->status = "ok: command response received";
  387. goto close_transfer;
  388. }
  389. if (host->complete_what == COMPLETION_XFERFINISH_RSPFIN)
  390. host->complete_what = COMPLETION_XFERFINISH;
  391. mci_cclear |= S3C2410_SDICMDSTAT_RSPFIN;
  392. }
  393. /* errors handled after this point are only relevant
  394. when a data transfer is in progress */
  395. if (!cmd->data)
  396. goto clear_status_bits;
  397. /* Check for FIFO failure */
  398. if (host->is2440) {
  399. if (mci_fsta & S3C2440_SDIFSTA_FIFOFAIL) {
  400. host->mrq->data->error = -EILSEQ;
  401. host->status = "error: 2440 fifo failure";
  402. goto fail_transfer;
  403. }
  404. } else {
  405. if (mci_dsta & S3C2410_SDIDSTA_FIFOFAIL) {
  406. cmd->data->error = -EILSEQ;
  407. host->status = "error: fifo failure";
  408. goto fail_transfer;
  409. }
  410. }
  411. if (mci_dsta & S3C2410_SDIDSTA_RXCRCFAIL) {
  412. cmd->data->error = -EILSEQ;
  413. host->status = "error: bad data crc (outgoing)";
  414. goto fail_transfer;
  415. }
  416. if (mci_dsta & S3C2410_SDIDSTA_CRCFAIL) {
  417. cmd->data->error = -EILSEQ;
  418. host->status = "error: bad data crc (incoming)";
  419. goto fail_transfer;
  420. }
  421. if (mci_dsta & S3C2410_SDIDSTA_DATATIMEOUT) {
  422. cmd->data->error = -ETIMEDOUT;
  423. host->status = "error: data timeout";
  424. goto fail_transfer;
  425. }
  426. if (mci_dsta & S3C2410_SDIDSTA_XFERFINISH) {
  427. if (host->complete_what == COMPLETION_XFERFINISH) {
  428. host->status = "ok: data transfer completed";
  429. goto close_transfer;
  430. }
  431. if (host->complete_what == COMPLETION_XFERFINISH_RSPFIN)
  432. host->complete_what = COMPLETION_RSPFIN;
  433. mci_dclear |= S3C2410_SDIDSTA_XFERFINISH;
  434. }
  435. clear_status_bits:
  436. writel(mci_cclear, host->base + S3C2410_SDICMDSTAT);
  437. writel(mci_dclear, host->base + S3C2410_SDIDSTA);
  438. goto irq_out;
  439. fail_transfer:
  440. host->pio_active = XFER_NONE;
  441. close_transfer:
  442. host->complete_what = COMPLETION_FINALIZE;
  443. clear_imask(host);
  444. tasklet_schedule(&host->pio_tasklet);
  445. goto irq_out;
  446. irq_out:
  447. dbg(host, dbg_irq,
  448. "csta:0x%08x dsta:0x%08x fsta:0x%08x dcnt:0x%08x status:%s.\n",
  449. mci_csta, mci_dsta, mci_fsta, mci_dcnt, host->status);
  450. spin_unlock_irqrestore(&host->complete_lock, iflags);
  451. return IRQ_HANDLED;
  452. }
  453. /*
  454. * ISR for the CardDetect Pin
  455. */
  456. static irqreturn_t s3cmci_irq_cd(int irq, void *dev_id)
  457. {
  458. struct s3cmci_host *host = (struct s3cmci_host *)dev_id;
  459. dbg(host, dbg_irq, "card detect\n");
  460. mmc_detect_change(host->mmc, 500);
  461. return IRQ_HANDLED;
  462. }
  463. void s3cmci_dma_done_callback(struct s3c2410_dma_chan *dma_ch, void *buf_id,
  464. int size, enum s3c2410_dma_buffresult result)
  465. {
  466. struct s3cmci_host *host = buf_id;
  467. unsigned long iflags;
  468. u32 mci_csta, mci_dsta, mci_fsta, mci_dcnt;
  469. mci_csta = readl(host->base + S3C2410_SDICMDSTAT);
  470. mci_dsta = readl(host->base + S3C2410_SDIDSTA);
  471. mci_fsta = readl(host->base + S3C2410_SDIFSTA);
  472. mci_dcnt = readl(host->base + S3C2410_SDIDCNT);
  473. BUG_ON(!host->mrq);
  474. BUG_ON(!host->mrq->data);
  475. BUG_ON(!host->dmatogo);
  476. spin_lock_irqsave(&host->complete_lock, iflags);
  477. if (result != S3C2410_RES_OK) {
  478. dbg(host, dbg_fail, "DMA FAILED: csta=0x%08x dsta=0x%08x "
  479. "fsta=0x%08x dcnt:0x%08x result:0x%08x toGo:%u\n",
  480. mci_csta, mci_dsta, mci_fsta,
  481. mci_dcnt, result, host->dmatogo);
  482. goto fail_request;
  483. }
  484. host->dmatogo--;
  485. if (host->dmatogo) {
  486. dbg(host, dbg_dma, "DMA DONE Size:%i DSTA:[%08x] "
  487. "DCNT:[%08x] toGo:%u\n",
  488. size, mci_dsta, mci_dcnt, host->dmatogo);
  489. goto out;
  490. }
  491. dbg(host, dbg_dma, "DMA FINISHED Size:%i DSTA:%08x DCNT:%08x\n",
  492. size, mci_dsta, mci_dcnt);
  493. host->complete_what = COMPLETION_FINALIZE;
  494. out:
  495. tasklet_schedule(&host->pio_tasklet);
  496. spin_unlock_irqrestore(&host->complete_lock, iflags);
  497. return;
  498. fail_request:
  499. host->mrq->data->error = -EINVAL;
  500. host->complete_what = COMPLETION_FINALIZE;
  501. writel(0, host->base + host->sdiimsk);
  502. goto out;
  503. }
  504. static void finalize_request(struct s3cmci_host *host)
  505. {
  506. struct mmc_request *mrq = host->mrq;
  507. struct mmc_command *cmd = host->cmd_is_stop ? mrq->stop : mrq->cmd;
  508. int debug_as_failure = 0;
  509. if (host->complete_what != COMPLETION_FINALIZE)
  510. return;
  511. if (!mrq)
  512. return;
  513. if (cmd->data && (cmd->error == 0) &&
  514. (cmd->data->error == 0)) {
  515. if (host->dodma && (!host->dma_complete)) {
  516. dbg(host, dbg_dma, "DMA Missing!\n");
  517. return;
  518. }
  519. }
  520. /* Read response from controller. */
  521. cmd->resp[0] = readl(host->base + S3C2410_SDIRSP0);
  522. cmd->resp[1] = readl(host->base + S3C2410_SDIRSP1);
  523. cmd->resp[2] = readl(host->base + S3C2410_SDIRSP2);
  524. cmd->resp[3] = readl(host->base + S3C2410_SDIRSP3);
  525. writel(host->prescaler, host->base + S3C2410_SDIPRE);
  526. if (cmd->error)
  527. debug_as_failure = 1;
  528. if (cmd->data && cmd->data->error)
  529. debug_as_failure = 1;
  530. dbg_dumpcmd(host, cmd, debug_as_failure);
  531. /* Cleanup controller */
  532. writel(0, host->base + S3C2410_SDICMDARG);
  533. writel(0, host->base + S3C2410_SDIDCON);
  534. writel(0, host->base + S3C2410_SDICMDCON);
  535. writel(0, host->base + host->sdiimsk);
  536. if (cmd->data && cmd->error)
  537. cmd->data->error = cmd->error;
  538. if (cmd->data && cmd->data->stop && (!host->cmd_is_stop)) {
  539. host->cmd_is_stop = 1;
  540. s3cmci_send_request(host->mmc);
  541. return;
  542. }
  543. /* If we have no data transfer we are finished here */
  544. if (!mrq->data)
  545. goto request_done;
  546. /* Calulate the amout of bytes transfer if there was no error */
  547. if (mrq->data->error == 0) {
  548. mrq->data->bytes_xfered =
  549. (mrq->data->blocks * mrq->data->blksz);
  550. } else {
  551. mrq->data->bytes_xfered = 0;
  552. }
  553. /* If we had an error while transfering data we flush the
  554. * DMA channel and the fifo to clear out any garbage. */
  555. if (mrq->data->error != 0) {
  556. if (host->dodma)
  557. s3c2410_dma_ctrl(host->dma, S3C2410_DMAOP_FLUSH);
  558. if (host->is2440) {
  559. /* Clear failure register and reset fifo. */
  560. writel(S3C2440_SDIFSTA_FIFORESET |
  561. S3C2440_SDIFSTA_FIFOFAIL,
  562. host->base + S3C2410_SDIFSTA);
  563. } else {
  564. u32 mci_con;
  565. /* reset fifo */
  566. mci_con = readl(host->base + S3C2410_SDICON);
  567. mci_con |= S3C2410_SDICON_FIFORESET;
  568. writel(mci_con, host->base + S3C2410_SDICON);
  569. }
  570. }
  571. request_done:
  572. host->complete_what = COMPLETION_NONE;
  573. host->mrq = NULL;
  574. mmc_request_done(host->mmc, mrq);
  575. }
  576. void s3cmci_dma_setup(struct s3cmci_host *host, enum s3c2410_dmasrc source)
  577. {
  578. static enum s3c2410_dmasrc last_source = -1;
  579. static int setup_ok;
  580. if (last_source == source)
  581. return;
  582. last_source = source;
  583. s3c2410_dma_devconfig(host->dma, source, 3,
  584. host->mem->start + host->sdidata);
  585. if (!setup_ok) {
  586. s3c2410_dma_config(host->dma, 4,
  587. (S3C2410_DCON_HWTRIG | S3C2410_DCON_CH0_SDI));
  588. s3c2410_dma_set_buffdone_fn(host->dma,
  589. s3cmci_dma_done_callback);
  590. s3c2410_dma_setflags(host->dma, S3C2410_DMAF_AUTOSTART);
  591. setup_ok = 1;
  592. }
  593. }
  594. static void s3cmci_send_command(struct s3cmci_host *host,
  595. struct mmc_command *cmd)
  596. {
  597. u32 ccon, imsk;
  598. imsk = S3C2410_SDIIMSK_CRCSTATUS | S3C2410_SDIIMSK_CMDTIMEOUT |
  599. S3C2410_SDIIMSK_RESPONSEND | S3C2410_SDIIMSK_CMDSENT |
  600. S3C2410_SDIIMSK_RESPONSECRC;
  601. enable_imask(host, imsk);
  602. if (cmd->data)
  603. host->complete_what = COMPLETION_XFERFINISH_RSPFIN;
  604. else if (cmd->flags & MMC_RSP_PRESENT)
  605. host->complete_what = COMPLETION_RSPFIN;
  606. else
  607. host->complete_what = COMPLETION_CMDSENT;
  608. writel(cmd->arg, host->base + S3C2410_SDICMDARG);
  609. ccon = cmd->opcode & S3C2410_SDICMDCON_INDEX;
  610. ccon |= S3C2410_SDICMDCON_SENDERHOST | S3C2410_SDICMDCON_CMDSTART;
  611. if (cmd->flags & MMC_RSP_PRESENT)
  612. ccon |= S3C2410_SDICMDCON_WAITRSP;
  613. if (cmd->flags & MMC_RSP_136)
  614. ccon |= S3C2410_SDICMDCON_LONGRSP;
  615. writel(ccon, host->base + S3C2410_SDICMDCON);
  616. }
  617. static int s3cmci_setup_data(struct s3cmci_host *host, struct mmc_data *data)
  618. {
  619. u32 dcon, imsk, stoptries = 3;
  620. /* write DCON register */
  621. if (!data) {
  622. writel(0, host->base + S3C2410_SDIDCON);
  623. return 0;
  624. }
  625. while (readl(host->base + S3C2410_SDIDSTA) &
  626. (S3C2410_SDIDSTA_TXDATAON | S3C2410_SDIDSTA_RXDATAON)) {
  627. dbg(host, dbg_err,
  628. "mci_setup_data() transfer stillin progress.\n");
  629. writel(0, host->base + S3C2410_SDIDCON);
  630. s3cmci_reset(host);
  631. if ((stoptries--) == 0) {
  632. dbg_dumpregs(host, "DRF");
  633. return -EINVAL;
  634. }
  635. }
  636. dcon = data->blocks & S3C2410_SDIDCON_BLKNUM_MASK;
  637. if (host->dodma)
  638. dcon |= S3C2410_SDIDCON_DMAEN;
  639. if (host->bus_width == MMC_BUS_WIDTH_4)
  640. dcon |= S3C2410_SDIDCON_WIDEBUS;
  641. if (!(data->flags & MMC_DATA_STREAM))
  642. dcon |= S3C2410_SDIDCON_BLOCKMODE;
  643. if (data->flags & MMC_DATA_WRITE) {
  644. dcon |= S3C2410_SDIDCON_TXAFTERRESP;
  645. dcon |= S3C2410_SDIDCON_XFER_TXSTART;
  646. }
  647. if (data->flags & MMC_DATA_READ) {
  648. dcon |= S3C2410_SDIDCON_RXAFTERCMD;
  649. dcon |= S3C2410_SDIDCON_XFER_RXSTART;
  650. }
  651. if (host->is2440) {
  652. dcon |= S3C2440_SDIDCON_DS_WORD;
  653. dcon |= S3C2440_SDIDCON_DATSTART;
  654. }
  655. writel(dcon, host->base + S3C2410_SDIDCON);
  656. /* write BSIZE register */
  657. writel(data->blksz, host->base + S3C2410_SDIBSIZE);
  658. /* add to IMASK register */
  659. imsk = S3C2410_SDIIMSK_FIFOFAIL | S3C2410_SDIIMSK_DATACRC |
  660. S3C2410_SDIIMSK_DATATIMEOUT | S3C2410_SDIIMSK_DATAFINISH;
  661. enable_imask(host, imsk);
  662. /* write TIMER register */
  663. if (host->is2440) {
  664. writel(0x007FFFFF, host->base + S3C2410_SDITIMER);
  665. } else {
  666. writel(0x0000FFFF, host->base + S3C2410_SDITIMER);
  667. /* FIX: set slow clock to prevent timeouts on read */
  668. if (data->flags & MMC_DATA_READ)
  669. writel(0xFF, host->base + S3C2410_SDIPRE);
  670. }
  671. return 0;
  672. }
  673. #define BOTH_DIR (MMC_DATA_WRITE | MMC_DATA_READ)
  674. static int s3cmci_prepare_pio(struct s3cmci_host *host, struct mmc_data *data)
  675. {
  676. int rw = (data->flags & MMC_DATA_WRITE) ? 1 : 0;
  677. BUG_ON((data->flags & BOTH_DIR) == BOTH_DIR);
  678. host->pio_sgptr = 0;
  679. host->pio_words = 0;
  680. host->pio_count = 0;
  681. host->pio_active = rw ? XFER_WRITE : XFER_READ;
  682. if (rw) {
  683. do_pio_write(host);
  684. enable_imask(host, S3C2410_SDIIMSK_TXFIFOHALF);
  685. } else {
  686. enable_imask(host, S3C2410_SDIIMSK_RXFIFOHALF
  687. | S3C2410_SDIIMSK_RXFIFOLAST);
  688. }
  689. return 0;
  690. }
  691. static int s3cmci_prepare_dma(struct s3cmci_host *host, struct mmc_data *data)
  692. {
  693. int dma_len, i;
  694. int rw = (data->flags & MMC_DATA_WRITE) ? 1 : 0;
  695. BUG_ON((data->flags & BOTH_DIR) == BOTH_DIR);
  696. s3cmci_dma_setup(host, rw ? S3C2410_DMASRC_MEM : S3C2410_DMASRC_HW);
  697. s3c2410_dma_ctrl(host->dma, S3C2410_DMAOP_FLUSH);
  698. dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg, data->sg_len,
  699. (rw) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
  700. if (dma_len == 0)
  701. return -ENOMEM;
  702. host->dma_complete = 0;
  703. host->dmatogo = dma_len;
  704. for (i = 0; i < dma_len; i++) {
  705. int res;
  706. dbg(host, dbg_dma, "enqueue %i:%u@%u\n", i,
  707. sg_dma_address(&data->sg[i]),
  708. sg_dma_len(&data->sg[i]));
  709. res = s3c2410_dma_enqueue(host->dma, (void *) host,
  710. sg_dma_address(&data->sg[i]),
  711. sg_dma_len(&data->sg[i]));
  712. if (res) {
  713. s3c2410_dma_ctrl(host->dma, S3C2410_DMAOP_FLUSH);
  714. return -EBUSY;
  715. }
  716. }
  717. s3c2410_dma_ctrl(host->dma, S3C2410_DMAOP_START);
  718. return 0;
  719. }
  720. static void s3cmci_send_request(struct mmc_host *mmc)
  721. {
  722. struct s3cmci_host *host = mmc_priv(mmc);
  723. struct mmc_request *mrq = host->mrq;
  724. struct mmc_command *cmd = host->cmd_is_stop ? mrq->stop : mrq->cmd;
  725. host->ccnt++;
  726. prepare_dbgmsg(host, cmd, host->cmd_is_stop);
  727. /* Clear command, data and fifo status registers
  728. Fifo clear only necessary on 2440, but doesn't hurt on 2410
  729. */
  730. writel(0xFFFFFFFF, host->base + S3C2410_SDICMDSTAT);
  731. writel(0xFFFFFFFF, host->base + S3C2410_SDIDSTA);
  732. writel(0xFFFFFFFF, host->base + S3C2410_SDIFSTA);
  733. if (cmd->data) {
  734. int res = s3cmci_setup_data(host, cmd->data);
  735. host->dcnt++;
  736. if (res) {
  737. cmd->error = -EINVAL;
  738. cmd->data->error = -EINVAL;
  739. mmc_request_done(mmc, mrq);
  740. return;
  741. }
  742. if (host->dodma)
  743. res = s3cmci_prepare_dma(host, cmd->data);
  744. else
  745. res = s3cmci_prepare_pio(host, cmd->data);
  746. if (res) {
  747. cmd->error = res;
  748. cmd->data->error = res;
  749. mmc_request_done(mmc, mrq);
  750. return;
  751. }
  752. }
  753. /* Send command */
  754. s3cmci_send_command(host, cmd);
  755. /* Enable Interrupt */
  756. enable_irq(host->irq);
  757. }
  758. static void s3cmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
  759. {
  760. struct s3cmci_host *host = mmc_priv(mmc);
  761. host->status = "mmc request";
  762. host->cmd_is_stop = 0;
  763. host->mrq = mrq;
  764. s3cmci_send_request(mmc);
  765. }
  766. static void s3cmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  767. {
  768. struct s3cmci_host *host = mmc_priv(mmc);
  769. u32 mci_psc, mci_con;
  770. /* Set the power state */
  771. mci_con = readl(host->base + S3C2410_SDICON);
  772. switch (ios->power_mode) {
  773. case MMC_POWER_ON:
  774. case MMC_POWER_UP:
  775. s3c2410_gpio_cfgpin(S3C2410_GPE5, S3C2410_GPE5_SDCLK);
  776. s3c2410_gpio_cfgpin(S3C2410_GPE6, S3C2410_GPE6_SDCMD);
  777. s3c2410_gpio_cfgpin(S3C2410_GPE7, S3C2410_GPE7_SDDAT0);
  778. s3c2410_gpio_cfgpin(S3C2410_GPE8, S3C2410_GPE8_SDDAT1);
  779. s3c2410_gpio_cfgpin(S3C2410_GPE9, S3C2410_GPE9_SDDAT2);
  780. s3c2410_gpio_cfgpin(S3C2410_GPE10, S3C2410_GPE10_SDDAT3);
  781. if (!host->is2440)
  782. mci_con |= S3C2410_SDICON_FIFORESET;
  783. break;
  784. case MMC_POWER_OFF:
  785. default:
  786. s3c2410_gpio_setpin(S3C2410_GPE5, 0);
  787. s3c2410_gpio_cfgpin(S3C2410_GPE5, S3C2410_GPE5_OUTP);
  788. if (host->is2440)
  789. mci_con |= S3C2440_SDICON_SDRESET;
  790. break;
  791. }
  792. /* Set clock */
  793. for (mci_psc = 0; mci_psc < 255; mci_psc++) {
  794. host->real_rate = host->clk_rate / (host->clk_div*(mci_psc+1));
  795. if (host->real_rate <= ios->clock)
  796. break;
  797. }
  798. if (mci_psc > 255)
  799. mci_psc = 255;
  800. host->prescaler = mci_psc;
  801. writel(host->prescaler, host->base + S3C2410_SDIPRE);
  802. /* If requested clock is 0, real_rate will be 0, too */
  803. if (ios->clock == 0)
  804. host->real_rate = 0;
  805. /* Set CLOCK_ENABLE */
  806. if (ios->clock)
  807. mci_con |= S3C2410_SDICON_CLOCKTYPE;
  808. else
  809. mci_con &= ~S3C2410_SDICON_CLOCKTYPE;
  810. writel(mci_con, host->base + S3C2410_SDICON);
  811. if ((ios->power_mode == MMC_POWER_ON) ||
  812. (ios->power_mode == MMC_POWER_UP)) {
  813. dbg(host, dbg_conf, "running at %lukHz (requested: %ukHz).\n",
  814. host->real_rate/1000, ios->clock/1000);
  815. } else {
  816. dbg(host, dbg_conf, "powered down.\n");
  817. }
  818. host->bus_width = ios->bus_width;
  819. }
  820. static void s3cmci_reset(struct s3cmci_host *host)
  821. {
  822. u32 con = readl(host->base + S3C2410_SDICON);
  823. con |= S3C2440_SDICON_SDRESET;
  824. writel(con, host->base + S3C2410_SDICON);
  825. }
  826. static struct mmc_host_ops s3cmci_ops = {
  827. .request = s3cmci_request,
  828. .set_ios = s3cmci_set_ios,
  829. };
  830. static int __devinit s3cmci_probe(struct platform_device *pdev, int is2440)
  831. {
  832. struct s3cmci_host *host;
  833. struct mmc_host *mmc;
  834. int ret;
  835. mmc = mmc_alloc_host(sizeof(struct s3cmci_host), &pdev->dev);
  836. if (!mmc) {
  837. ret = -ENOMEM;
  838. goto probe_out;
  839. }
  840. host = mmc_priv(mmc);
  841. host->mmc = mmc;
  842. host->pdev = pdev;
  843. host->is2440 = is2440;
  844. spin_lock_init(&host->complete_lock);
  845. tasklet_init(&host->pio_tasklet, pio_tasklet, (unsigned long) host);
  846. if (is2440) {
  847. host->sdiimsk = S3C2440_SDIIMSK;
  848. host->sdidata = S3C2440_SDIDATA;
  849. host->clk_div = 1;
  850. } else {
  851. host->sdiimsk = S3C2410_SDIIMSK;
  852. host->sdidata = S3C2410_SDIDATA;
  853. host->clk_div = 2;
  854. }
  855. host->dodma = 0;
  856. host->complete_what = COMPLETION_NONE;
  857. host->pio_active = XFER_NONE;
  858. host->dma = S3CMCI_DMA;
  859. host->irq_cd = IRQ_EINT2;
  860. host->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  861. if (!host->mem) {
  862. dev_err(&pdev->dev,
  863. "failed to get io memory region resouce.\n");
  864. ret = -ENOENT;
  865. goto probe_free_host;
  866. }
  867. host->mem = request_mem_region(host->mem->start,
  868. RESSIZE(host->mem), pdev->name);
  869. if (!host->mem) {
  870. dev_err(&pdev->dev, "failed to request io memory region.\n");
  871. ret = -ENOENT;
  872. goto probe_free_host;
  873. }
  874. host->base = ioremap(host->mem->start, RESSIZE(host->mem));
  875. if (host->base == 0) {
  876. dev_err(&pdev->dev, "failed to ioremap() io memory region.\n");
  877. ret = -EINVAL;
  878. goto probe_free_mem_region;
  879. }
  880. host->irq = platform_get_irq(pdev, 0);
  881. if (host->irq == 0) {
  882. dev_err(&pdev->dev, "failed to get interrupt resouce.\n");
  883. ret = -EINVAL;
  884. goto probe_iounmap;
  885. }
  886. if (request_irq(host->irq, s3cmci_irq, 0, DRIVER_NAME, host)) {
  887. dev_err(&pdev->dev, "failed to request mci interrupt.\n");
  888. ret = -ENOENT;
  889. goto probe_iounmap;
  890. }
  891. /* We get spurious interrupts even when we have set the IMSK
  892. * register to ignore everything, so use disable_irq() to make
  893. * ensure we don't lock the system with un-serviceable requests. */
  894. disable_irq(host->irq);
  895. s3c2410_gpio_cfgpin(S3C2410_GPF2, S3C2410_GPF2_EINT2);
  896. set_irq_type(host->irq_cd, IRQT_BOTHEDGE);
  897. if (request_irq(host->irq_cd, s3cmci_irq_cd, 0, DRIVER_NAME, host)) {
  898. dev_err(&pdev->dev,
  899. "failed to request card detect interrupt.\n");
  900. ret = -ENOENT;
  901. goto probe_free_irq;
  902. }
  903. if (s3c2410_dma_request(S3CMCI_DMA, &s3cmci_dma_client, NULL)) {
  904. dev_err(&pdev->dev, "unable to get DMA channel.\n");
  905. ret = -EBUSY;
  906. goto probe_free_irq_cd;
  907. }
  908. host->clk = clk_get(&pdev->dev, "sdi");
  909. if (IS_ERR(host->clk)) {
  910. dev_err(&pdev->dev, "failed to find clock source.\n");
  911. ret = PTR_ERR(host->clk);
  912. host->clk = NULL;
  913. goto probe_free_host;
  914. }
  915. ret = clk_enable(host->clk);
  916. if (ret) {
  917. dev_err(&pdev->dev, "failed to enable clock source.\n");
  918. goto clk_free;
  919. }
  920. host->clk_rate = clk_get_rate(host->clk);
  921. mmc->ops = &s3cmci_ops;
  922. mmc->ocr_avail = MMC_VDD_32_33;
  923. mmc->caps = MMC_CAP_4_BIT_DATA;
  924. mmc->f_min = host->clk_rate / (host->clk_div * 256);
  925. mmc->f_max = host->clk_rate / host->clk_div;
  926. mmc->max_blk_count = 4095;
  927. mmc->max_blk_size = 4095;
  928. mmc->max_req_size = 4095 * 512;
  929. mmc->max_seg_size = mmc->max_req_size;
  930. mmc->max_phys_segs = 128;
  931. mmc->max_hw_segs = 128;
  932. dbg(host, dbg_debug,
  933. "probe: mode:%s mapped mci_base:%p irq:%u irq_cd:%u dma:%u.\n",
  934. (host->is2440?"2440":""),
  935. host->base, host->irq, host->irq_cd, host->dma);
  936. ret = mmc_add_host(mmc);
  937. if (ret) {
  938. dev_err(&pdev->dev, "failed to add mmc host.\n");
  939. goto free_dmabuf;
  940. }
  941. platform_set_drvdata(pdev, mmc);
  942. dev_info(&pdev->dev, "initialisation done.\n");
  943. return 0;
  944. free_dmabuf:
  945. clk_disable(host->clk);
  946. clk_free:
  947. clk_put(host->clk);
  948. probe_free_irq_cd:
  949. free_irq(host->irq_cd, host);
  950. probe_free_irq:
  951. free_irq(host->irq, host);
  952. probe_iounmap:
  953. iounmap(host->base);
  954. probe_free_mem_region:
  955. release_mem_region(host->mem->start, RESSIZE(host->mem));
  956. probe_free_host:
  957. mmc_free_host(mmc);
  958. probe_out:
  959. return ret;
  960. }
  961. static int __devexit s3cmci_remove(struct platform_device *pdev)
  962. {
  963. struct mmc_host *mmc = platform_get_drvdata(pdev);
  964. struct s3cmci_host *host = mmc_priv(mmc);
  965. mmc_remove_host(mmc);
  966. clk_disable(host->clk);
  967. clk_put(host->clk);
  968. tasklet_disable(&host->pio_tasklet);
  969. s3c2410_dma_free(S3CMCI_DMA, &s3cmci_dma_client);
  970. free_irq(host->irq_cd, host);
  971. free_irq(host->irq, host);
  972. iounmap(host->base);
  973. release_mem_region(host->mem->start, RESSIZE(host->mem));
  974. mmc_free_host(mmc);
  975. return 0;
  976. }
  977. static int __devinit s3cmci_probe_2410(struct platform_device *dev)
  978. {
  979. return s3cmci_probe(dev, 0);
  980. }
  981. static int __devinit s3cmci_probe_2412(struct platform_device *dev)
  982. {
  983. return s3cmci_probe(dev, 1);
  984. }
  985. static int __devinit s3cmci_probe_2440(struct platform_device *dev)
  986. {
  987. return s3cmci_probe(dev, 1);
  988. }
  989. #ifdef CONFIG_PM
  990. static int s3cmci_suspend(struct platform_device *dev, pm_message_t state)
  991. {
  992. struct mmc_host *mmc = platform_get_drvdata(dev);
  993. return mmc_suspend_host(mmc, state);
  994. }
  995. static int s3cmci_resume(struct platform_device *dev)
  996. {
  997. struct mmc_host *mmc = platform_get_drvdata(dev);
  998. return mmc_resume_host(mmc);
  999. }
  1000. #else /* CONFIG_PM */
  1001. #define s3cmci_suspend NULL
  1002. #define s3cmci_resume NULL
  1003. #endif /* CONFIG_PM */
  1004. static struct platform_driver s3cmci_driver_2410 = {
  1005. .driver.name = "s3c2410-sdi",
  1006. .driver.owner = THIS_MODULE,
  1007. .probe = s3cmci_probe_2410,
  1008. .remove = __devexit_p(s3cmci_remove),
  1009. .suspend = s3cmci_suspend,
  1010. .resume = s3cmci_resume,
  1011. };
  1012. static struct platform_driver s3cmci_driver_2412 = {
  1013. .driver.name = "s3c2412-sdi",
  1014. .driver.owner = THIS_MODULE,
  1015. .probe = s3cmci_probe_2412,
  1016. .remove = __devexit_p(s3cmci_remove),
  1017. .suspend = s3cmci_suspend,
  1018. .resume = s3cmci_resume,
  1019. };
  1020. static struct platform_driver s3cmci_driver_2440 = {
  1021. .driver.name = "s3c2440-sdi",
  1022. .driver.owner = THIS_MODULE,
  1023. .probe = s3cmci_probe_2440,
  1024. .remove = __devexit_p(s3cmci_remove),
  1025. .suspend = s3cmci_suspend,
  1026. .resume = s3cmci_resume,
  1027. };
  1028. static int __init s3cmci_init(void)
  1029. {
  1030. platform_driver_register(&s3cmci_driver_2410);
  1031. platform_driver_register(&s3cmci_driver_2412);
  1032. platform_driver_register(&s3cmci_driver_2440);
  1033. return 0;
  1034. }
  1035. static void __exit s3cmci_exit(void)
  1036. {
  1037. platform_driver_unregister(&s3cmci_driver_2410);
  1038. platform_driver_unregister(&s3cmci_driver_2412);
  1039. platform_driver_unregister(&s3cmci_driver_2440);
  1040. }
  1041. module_init(s3cmci_init);
  1042. module_exit(s3cmci_exit);
  1043. MODULE_DESCRIPTION("Samsung S3C MMC/SD Card Interface driver");
  1044. MODULE_LICENSE("GPL v2");
  1045. MODULE_AUTHOR("Thomas Kleffel <tk@maintech.de>");