msm_sdcc.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  1. /*
  2. * linux/drivers/mmc/host/msm_sdcc.c - Qualcomm MSM 7X00A SDCC Driver
  3. *
  4. * Copyright (C) 2007 Google Inc,
  5. * Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Based on mmci.c
  12. *
  13. * Author: San Mehat (san@android.com)
  14. *
  15. */
  16. #include <linux/module.h>
  17. #include <linux/moduleparam.h>
  18. #include <linux/init.h>
  19. #include <linux/ioport.h>
  20. #include <linux/device.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/delay.h>
  23. #include <linux/err.h>
  24. #include <linux/highmem.h>
  25. #include <linux/log2.h>
  26. #include <linux/mmc/host.h>
  27. #include <linux/mmc/card.h>
  28. #include <linux/mmc/sdio.h>
  29. #include <linux/clk.h>
  30. #include <linux/scatterlist.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/debugfs.h>
  34. #include <linux/io.h>
  35. #include <linux/memory.h>
  36. #include <asm/cacheflush.h>
  37. #include <asm/div64.h>
  38. #include <asm/sizes.h>
  39. #include <mach/mmc.h>
  40. #include <mach/msm_iomap.h>
  41. #include <mach/dma.h>
  42. #include "msm_sdcc.h"
  43. #define DRIVER_NAME "msm-sdcc"
  44. static unsigned int msmsdcc_fmin = 144000;
  45. static unsigned int msmsdcc_fmax = 50000000;
  46. static unsigned int msmsdcc_4bit = 1;
  47. static unsigned int msmsdcc_pwrsave = 1;
  48. static unsigned int msmsdcc_piopoll = 1;
  49. static unsigned int msmsdcc_sdioirq;
  50. #define PIO_SPINMAX 30
  51. #define CMD_SPINMAX 20
  52. static inline int
  53. msmsdcc_enable_clocks(struct msmsdcc_host *host, int enable)
  54. {
  55. int rc;
  56. WARN_ON(enable == host->clks_on);
  57. if (enable) {
  58. rc = clk_enable(host->pclk);
  59. if (rc)
  60. return rc;
  61. rc = clk_enable(host->clk);
  62. if (rc) {
  63. clk_disable(host->pclk);
  64. return rc;
  65. }
  66. udelay(1 + ((3 * USEC_PER_SEC) /
  67. (host->clk_rate ? host->clk_rate : msmsdcc_fmin)));
  68. host->clks_on = 1;
  69. } else {
  70. clk_disable(host->clk);
  71. clk_disable(host->pclk);
  72. host->clks_on = 0;
  73. }
  74. return 0;
  75. }
  76. static inline unsigned int
  77. msmsdcc_readl(struct msmsdcc_host *host, unsigned int reg)
  78. {
  79. return readl(host->base + reg);
  80. }
  81. static inline void
  82. msmsdcc_writel(struct msmsdcc_host *host, u32 data, unsigned int reg)
  83. {
  84. writel(data, host->base + reg);
  85. /* 3 clk delay required! */
  86. udelay(1 + ((3 * USEC_PER_SEC) /
  87. (host->clk_rate ? host->clk_rate : msmsdcc_fmin)));
  88. }
  89. static void
  90. msmsdcc_start_command(struct msmsdcc_host *host, struct mmc_command *cmd,
  91. u32 c);
  92. static void
  93. msmsdcc_request_end(struct msmsdcc_host *host, struct mmc_request *mrq)
  94. {
  95. msmsdcc_writel(host, 0, MMCICOMMAND);
  96. BUG_ON(host->curr.data);
  97. host->curr.mrq = NULL;
  98. host->curr.cmd = NULL;
  99. if (mrq->data)
  100. mrq->data->bytes_xfered = host->curr.data_xfered;
  101. if (mrq->cmd->error == -ETIMEDOUT)
  102. mdelay(5);
  103. if (host->use_bustimer)
  104. mod_timer(&host->busclk_timer, jiffies + HZ);
  105. /*
  106. * Need to drop the host lock here; mmc_request_done may call
  107. * back into the driver...
  108. */
  109. spin_unlock(&host->lock);
  110. mmc_request_done(host->mmc, mrq);
  111. spin_lock(&host->lock);
  112. }
  113. static void
  114. msmsdcc_stop_data(struct msmsdcc_host *host)
  115. {
  116. msmsdcc_writel(host, 0, MMCIDATACTRL);
  117. host->curr.data = NULL;
  118. host->curr.got_dataend = host->curr.got_datablkend = 0;
  119. }
  120. uint32_t msmsdcc_fifo_addr(struct msmsdcc_host *host)
  121. {
  122. switch (host->pdev_id) {
  123. case 1:
  124. return MSM_SDC1_PHYS + MMCIFIFO;
  125. case 2:
  126. return MSM_SDC2_PHYS + MMCIFIFO;
  127. case 3:
  128. return MSM_SDC3_PHYS + MMCIFIFO;
  129. case 4:
  130. return MSM_SDC4_PHYS + MMCIFIFO;
  131. }
  132. BUG();
  133. return 0;
  134. }
  135. static void
  136. msmsdcc_dma_complete_func(struct msm_dmov_cmd *cmd,
  137. unsigned int result,
  138. struct msm_dmov_errdata *err)
  139. {
  140. struct msmsdcc_dma_data *dma_data =
  141. container_of(cmd, struct msmsdcc_dma_data, hdr);
  142. struct msmsdcc_host *host = dma_data->host;
  143. unsigned long flags;
  144. struct mmc_request *mrq;
  145. spin_lock_irqsave(&host->lock, flags);
  146. mrq = host->curr.mrq;
  147. BUG_ON(!mrq);
  148. if (!(result & DMOV_RSLT_VALID)) {
  149. pr_err("msmsdcc: Invalid DataMover result\n");
  150. goto out;
  151. }
  152. if (result & DMOV_RSLT_DONE) {
  153. host->curr.data_xfered = host->curr.xfer_size;
  154. } else {
  155. /* Error or flush */
  156. if (result & DMOV_RSLT_ERROR)
  157. pr_err("%s: DMA error (0x%.8x)\n",
  158. mmc_hostname(host->mmc), result);
  159. if (result & DMOV_RSLT_FLUSH)
  160. pr_err("%s: DMA channel flushed (0x%.8x)\n",
  161. mmc_hostname(host->mmc), result);
  162. if (err)
  163. pr_err("Flush data: %.8x %.8x %.8x %.8x %.8x %.8x\n",
  164. err->flush[0], err->flush[1], err->flush[2],
  165. err->flush[3], err->flush[4], err->flush[5]);
  166. if (!mrq->data->error)
  167. mrq->data->error = -EIO;
  168. }
  169. host->dma.busy = 0;
  170. dma_unmap_sg(mmc_dev(host->mmc), host->dma.sg, host->dma.num_ents,
  171. host->dma.dir);
  172. if (host->curr.user_pages) {
  173. struct scatterlist *sg = host->dma.sg;
  174. int i;
  175. for (i = 0; i < host->dma.num_ents; i++)
  176. flush_dcache_page(sg_page(sg++));
  177. }
  178. host->dma.sg = NULL;
  179. if ((host->curr.got_dataend && host->curr.got_datablkend)
  180. || mrq->data->error) {
  181. /*
  182. * If we've already gotten our DATAEND / DATABLKEND
  183. * for this request, then complete it through here.
  184. */
  185. msmsdcc_stop_data(host);
  186. if (!mrq->data->error)
  187. host->curr.data_xfered = host->curr.xfer_size;
  188. if (!mrq->data->stop || mrq->cmd->error) {
  189. msmsdcc_writel(host, 0, MMCICOMMAND);
  190. host->curr.mrq = NULL;
  191. host->curr.cmd = NULL;
  192. mrq->data->bytes_xfered = host->curr.data_xfered;
  193. spin_unlock_irqrestore(&host->lock, flags);
  194. mmc_request_done(host->mmc, mrq);
  195. return;
  196. } else
  197. msmsdcc_start_command(host, mrq->data->stop, 0);
  198. }
  199. out:
  200. spin_unlock_irqrestore(&host->lock, flags);
  201. return;
  202. }
  203. static int validate_dma(struct msmsdcc_host *host, struct mmc_data *data)
  204. {
  205. if (host->dma.channel == -1)
  206. return -ENOENT;
  207. if ((data->blksz * data->blocks) < MCI_FIFOSIZE)
  208. return -EINVAL;
  209. if ((data->blksz * data->blocks) % MCI_FIFOSIZE)
  210. return -EINVAL;
  211. return 0;
  212. }
  213. static int msmsdcc_config_dma(struct msmsdcc_host *host, struct mmc_data *data)
  214. {
  215. struct msmsdcc_nc_dmadata *nc;
  216. dmov_box *box;
  217. uint32_t rows;
  218. uint32_t crci;
  219. unsigned int n;
  220. int i, rc;
  221. struct scatterlist *sg = data->sg;
  222. rc = validate_dma(host, data);
  223. if (rc)
  224. return rc;
  225. host->dma.sg = data->sg;
  226. host->dma.num_ents = data->sg_len;
  227. nc = host->dma.nc;
  228. switch (host->pdev_id) {
  229. case 1:
  230. crci = MSMSDCC_CRCI_SDC1;
  231. break;
  232. case 2:
  233. crci = MSMSDCC_CRCI_SDC2;
  234. break;
  235. case 3:
  236. crci = MSMSDCC_CRCI_SDC3;
  237. break;
  238. case 4:
  239. crci = MSMSDCC_CRCI_SDC4;
  240. break;
  241. default:
  242. host->dma.sg = NULL;
  243. host->dma.num_ents = 0;
  244. return -ENOENT;
  245. }
  246. if (data->flags & MMC_DATA_READ)
  247. host->dma.dir = DMA_FROM_DEVICE;
  248. else
  249. host->dma.dir = DMA_TO_DEVICE;
  250. host->curr.user_pages = 0;
  251. n = dma_map_sg(mmc_dev(host->mmc), host->dma.sg,
  252. host->dma.num_ents, host->dma.dir);
  253. if (n != host->dma.num_ents) {
  254. pr_err("%s: Unable to map in all sg elements\n",
  255. mmc_hostname(host->mmc));
  256. host->dma.sg = NULL;
  257. host->dma.num_ents = 0;
  258. return -ENOMEM;
  259. }
  260. box = &nc->cmd[0];
  261. for (i = 0; i < host->dma.num_ents; i++) {
  262. box->cmd = CMD_MODE_BOX;
  263. if (i == (host->dma.num_ents - 1))
  264. box->cmd |= CMD_LC;
  265. rows = (sg_dma_len(sg) % MCI_FIFOSIZE) ?
  266. (sg_dma_len(sg) / MCI_FIFOSIZE) + 1 :
  267. (sg_dma_len(sg) / MCI_FIFOSIZE) ;
  268. if (data->flags & MMC_DATA_READ) {
  269. box->src_row_addr = msmsdcc_fifo_addr(host);
  270. box->dst_row_addr = sg_dma_address(sg);
  271. box->src_dst_len = (MCI_FIFOSIZE << 16) |
  272. (MCI_FIFOSIZE);
  273. box->row_offset = MCI_FIFOSIZE;
  274. box->num_rows = rows * ((1 << 16) + 1);
  275. box->cmd |= CMD_SRC_CRCI(crci);
  276. } else {
  277. box->src_row_addr = sg_dma_address(sg);
  278. box->dst_row_addr = msmsdcc_fifo_addr(host);
  279. box->src_dst_len = (MCI_FIFOSIZE << 16) |
  280. (MCI_FIFOSIZE);
  281. box->row_offset = (MCI_FIFOSIZE << 16);
  282. box->num_rows = rows * ((1 << 16) + 1);
  283. box->cmd |= CMD_DST_CRCI(crci);
  284. }
  285. box++;
  286. sg++;
  287. }
  288. /* location of command block must be 64 bit aligned */
  289. BUG_ON(host->dma.cmd_busaddr & 0x07);
  290. nc->cmdptr = (host->dma.cmd_busaddr >> 3) | CMD_PTR_LP;
  291. host->dma.hdr.cmdptr = DMOV_CMD_PTR_LIST |
  292. DMOV_CMD_ADDR(host->dma.cmdptr_busaddr);
  293. host->dma.hdr.complete_func = msmsdcc_dma_complete_func;
  294. host->dma.hdr.execute_func = NULL;
  295. return 0;
  296. }
  297. static void
  298. msmsdcc_start_data(struct msmsdcc_host *host, struct mmc_data *data)
  299. {
  300. unsigned int datactrl, timeout;
  301. unsigned long long clks;
  302. unsigned int pio_irqmask = 0;
  303. host->curr.data = data;
  304. host->curr.xfer_size = data->blksz * data->blocks;
  305. host->curr.xfer_remain = host->curr.xfer_size;
  306. host->curr.data_xfered = 0;
  307. host->curr.got_dataend = 0;
  308. host->curr.got_datablkend = 0;
  309. memset(&host->pio, 0, sizeof(host->pio));
  310. clks = (unsigned long long)data->timeout_ns * host->clk_rate;
  311. do_div(clks, NSEC_PER_SEC);
  312. timeout = data->timeout_clks + (unsigned int)clks;
  313. msmsdcc_writel(host, timeout, MMCIDATATIMER);
  314. msmsdcc_writel(host, host->curr.xfer_size, MMCIDATALENGTH);
  315. datactrl = MCI_DPSM_ENABLE | (data->blksz << 4);
  316. if (!msmsdcc_config_dma(host, data))
  317. datactrl |= MCI_DPSM_DMAENABLE;
  318. else {
  319. host->pio.sg = data->sg;
  320. host->pio.sg_len = data->sg_len;
  321. host->pio.sg_off = 0;
  322. if (data->flags & MMC_DATA_READ) {
  323. pio_irqmask = MCI_RXFIFOHALFFULLMASK;
  324. if (host->curr.xfer_remain < MCI_FIFOSIZE)
  325. pio_irqmask |= MCI_RXDATAAVLBLMASK;
  326. } else
  327. pio_irqmask = MCI_TXFIFOHALFEMPTYMASK;
  328. }
  329. if (data->flags & MMC_DATA_READ)
  330. datactrl |= MCI_DPSM_DIRECTION;
  331. msmsdcc_writel(host, pio_irqmask, MMCIMASK1);
  332. msmsdcc_writel(host, datactrl, MMCIDATACTRL);
  333. if (datactrl & MCI_DPSM_DMAENABLE) {
  334. host->dma.busy = 1;
  335. msm_dmov_enqueue_cmd(host->dma.channel, &host->dma.hdr);
  336. }
  337. }
  338. static int
  339. snoop_cccr_abort(struct mmc_command *cmd)
  340. {
  341. if ((cmd->opcode == 52) &&
  342. (cmd->arg & 0x80000000) &&
  343. (((cmd->arg >> 9) & 0x1ffff) == SDIO_CCCR_ABORT))
  344. return 1;
  345. return 0;
  346. }
  347. static void
  348. msmsdcc_start_command(struct msmsdcc_host *host, struct mmc_command *cmd, u32 c)
  349. {
  350. if (msmsdcc_readl(host, MMCICOMMAND) & MCI_CPSM_ENABLE)
  351. msmsdcc_writel(host, 0, MMCICOMMAND);
  352. c |= cmd->opcode | MCI_CPSM_ENABLE;
  353. if (cmd->flags & MMC_RSP_PRESENT) {
  354. if (cmd->flags & MMC_RSP_136)
  355. c |= MCI_CPSM_LONGRSP;
  356. c |= MCI_CPSM_RESPONSE;
  357. }
  358. if (cmd->opcode == 17 || cmd->opcode == 18 ||
  359. cmd->opcode == 24 || cmd->opcode == 25 ||
  360. cmd->opcode == 53)
  361. c |= MCI_CSPM_DATCMD;
  362. if (cmd == cmd->mrq->stop)
  363. c |= MCI_CSPM_MCIABORT;
  364. if (snoop_cccr_abort(cmd))
  365. c |= MCI_CSPM_MCIABORT;
  366. host->curr.cmd = cmd;
  367. host->stats.cmds++;
  368. msmsdcc_writel(host, cmd->arg, MMCIARGUMENT);
  369. msmsdcc_writel(host, c, MMCICOMMAND);
  370. }
  371. static void
  372. msmsdcc_data_err(struct msmsdcc_host *host, struct mmc_data *data,
  373. unsigned int status)
  374. {
  375. if (status & MCI_DATACRCFAIL) {
  376. pr_err("%s: Data CRC error\n", mmc_hostname(host->mmc));
  377. pr_err("%s: opcode 0x%.8x\n", __func__,
  378. data->mrq->cmd->opcode);
  379. pr_err("%s: blksz %d, blocks %d\n", __func__,
  380. data->blksz, data->blocks);
  381. data->error = -EILSEQ;
  382. } else if (status & MCI_DATATIMEOUT) {
  383. pr_err("%s: Data timeout\n", mmc_hostname(host->mmc));
  384. data->error = -ETIMEDOUT;
  385. } else if (status & MCI_RXOVERRUN) {
  386. pr_err("%s: RX overrun\n", mmc_hostname(host->mmc));
  387. data->error = -EIO;
  388. } else if (status & MCI_TXUNDERRUN) {
  389. pr_err("%s: TX underrun\n", mmc_hostname(host->mmc));
  390. data->error = -EIO;
  391. } else {
  392. pr_err("%s: Unknown error (0x%.8x)\n",
  393. mmc_hostname(host->mmc), status);
  394. data->error = -EIO;
  395. }
  396. }
  397. static int
  398. msmsdcc_pio_read(struct msmsdcc_host *host, char *buffer, unsigned int remain)
  399. {
  400. uint32_t *ptr = (uint32_t *) buffer;
  401. int count = 0;
  402. while (msmsdcc_readl(host, MMCISTATUS) & MCI_RXDATAAVLBL) {
  403. *ptr = msmsdcc_readl(host, MMCIFIFO + (count % MCI_FIFOSIZE));
  404. ptr++;
  405. count += sizeof(uint32_t);
  406. remain -= sizeof(uint32_t);
  407. if (remain == 0)
  408. break;
  409. }
  410. return count;
  411. }
  412. static int
  413. msmsdcc_pio_write(struct msmsdcc_host *host, char *buffer,
  414. unsigned int remain, u32 status)
  415. {
  416. void __iomem *base = host->base;
  417. char *ptr = buffer;
  418. do {
  419. unsigned int count, maxcnt;
  420. maxcnt = status & MCI_TXFIFOEMPTY ? MCI_FIFOSIZE :
  421. MCI_FIFOHALFSIZE;
  422. count = min(remain, maxcnt);
  423. writesl(base + MMCIFIFO, ptr, count >> 2);
  424. ptr += count;
  425. remain -= count;
  426. if (remain == 0)
  427. break;
  428. status = msmsdcc_readl(host, MMCISTATUS);
  429. } while (status & MCI_TXFIFOHALFEMPTY);
  430. return ptr - buffer;
  431. }
  432. static int
  433. msmsdcc_spin_on_status(struct msmsdcc_host *host, uint32_t mask, int maxspin)
  434. {
  435. while (maxspin) {
  436. if ((msmsdcc_readl(host, MMCISTATUS) & mask))
  437. return 0;
  438. udelay(1);
  439. --maxspin;
  440. }
  441. return -ETIMEDOUT;
  442. }
  443. static int
  444. msmsdcc_pio_irq(int irq, void *dev_id)
  445. {
  446. struct msmsdcc_host *host = dev_id;
  447. uint32_t status;
  448. status = msmsdcc_readl(host, MMCISTATUS);
  449. do {
  450. unsigned long flags;
  451. unsigned int remain, len;
  452. char *buffer;
  453. if (!(status & (MCI_TXFIFOHALFEMPTY | MCI_RXDATAAVLBL))) {
  454. if (host->curr.xfer_remain == 0 || !msmsdcc_piopoll)
  455. break;
  456. if (msmsdcc_spin_on_status(host,
  457. (MCI_TXFIFOHALFEMPTY |
  458. MCI_RXDATAAVLBL),
  459. PIO_SPINMAX)) {
  460. break;
  461. }
  462. }
  463. /* Map the current scatter buffer */
  464. local_irq_save(flags);
  465. buffer = kmap_atomic(sg_page(host->pio.sg),
  466. KM_BIO_SRC_IRQ) + host->pio.sg->offset;
  467. buffer += host->pio.sg_off;
  468. remain = host->pio.sg->length - host->pio.sg_off;
  469. len = 0;
  470. if (status & MCI_RXACTIVE)
  471. len = msmsdcc_pio_read(host, buffer, remain);
  472. if (status & MCI_TXACTIVE)
  473. len = msmsdcc_pio_write(host, buffer, remain, status);
  474. /* Unmap the buffer */
  475. kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
  476. local_irq_restore(flags);
  477. host->pio.sg_off += len;
  478. host->curr.xfer_remain -= len;
  479. host->curr.data_xfered += len;
  480. remain -= len;
  481. if (remain == 0) {
  482. /* This sg page is full - do some housekeeping */
  483. if (status & MCI_RXACTIVE && host->curr.user_pages)
  484. flush_dcache_page(sg_page(host->pio.sg));
  485. if (!--host->pio.sg_len) {
  486. memset(&host->pio, 0, sizeof(host->pio));
  487. break;
  488. }
  489. /* Advance to next sg */
  490. host->pio.sg++;
  491. host->pio.sg_off = 0;
  492. }
  493. status = msmsdcc_readl(host, MMCISTATUS);
  494. } while (1);
  495. if (status & MCI_RXACTIVE && host->curr.xfer_remain < MCI_FIFOSIZE)
  496. msmsdcc_writel(host, MCI_RXDATAAVLBLMASK, MMCIMASK1);
  497. if (!host->curr.xfer_remain)
  498. msmsdcc_writel(host, 0, MMCIMASK1);
  499. return IRQ_HANDLED;
  500. }
  501. static void msmsdcc_do_cmdirq(struct msmsdcc_host *host, uint32_t status)
  502. {
  503. struct mmc_command *cmd = host->curr.cmd;
  504. host->curr.cmd = NULL;
  505. cmd->resp[0] = msmsdcc_readl(host, MMCIRESPONSE0);
  506. cmd->resp[1] = msmsdcc_readl(host, MMCIRESPONSE1);
  507. cmd->resp[2] = msmsdcc_readl(host, MMCIRESPONSE2);
  508. cmd->resp[3] = msmsdcc_readl(host, MMCIRESPONSE3);
  509. del_timer(&host->command_timer);
  510. if (status & MCI_CMDTIMEOUT) {
  511. cmd->error = -ETIMEDOUT;
  512. } else if (status & MCI_CMDCRCFAIL &&
  513. cmd->flags & MMC_RSP_CRC) {
  514. pr_err("%s: Command CRC error\n", mmc_hostname(host->mmc));
  515. cmd->error = -EILSEQ;
  516. }
  517. if (!cmd->data || cmd->error) {
  518. if (host->curr.data && host->dma.sg)
  519. msm_dmov_stop_cmd(host->dma.channel,
  520. &host->dma.hdr, 0);
  521. else if (host->curr.data) { /* Non DMA */
  522. msmsdcc_stop_data(host);
  523. msmsdcc_request_end(host, cmd->mrq);
  524. } else /* host->data == NULL */
  525. msmsdcc_request_end(host, cmd->mrq);
  526. } else if (!(cmd->data->flags & MMC_DATA_READ))
  527. msmsdcc_start_data(host, cmd->data);
  528. }
  529. static void
  530. msmsdcc_handle_irq_data(struct msmsdcc_host *host, u32 status,
  531. void __iomem *base)
  532. {
  533. struct mmc_data *data = host->curr.data;
  534. if (!data)
  535. return;
  536. /* Check for data errors */
  537. if (status & (MCI_DATACRCFAIL | MCI_DATATIMEOUT |
  538. MCI_TXUNDERRUN | MCI_RXOVERRUN)) {
  539. msmsdcc_data_err(host, data, status);
  540. host->curr.data_xfered = 0;
  541. if (host->dma.sg)
  542. msm_dmov_stop_cmd(host->dma.channel,
  543. &host->dma.hdr, 0);
  544. else {
  545. msmsdcc_stop_data(host);
  546. if (!data->stop)
  547. msmsdcc_request_end(host, data->mrq);
  548. else
  549. msmsdcc_start_command(host, data->stop, 0);
  550. }
  551. }
  552. /* Check for data done */
  553. if (!host->curr.got_dataend && (status & MCI_DATAEND))
  554. host->curr.got_dataend = 1;
  555. if (!host->curr.got_datablkend && (status & MCI_DATABLOCKEND))
  556. host->curr.got_datablkend = 1;
  557. /*
  558. * If DMA is still in progress, we complete via the completion handler
  559. */
  560. if (host->curr.got_dataend && host->curr.got_datablkend &&
  561. !host->dma.busy) {
  562. /*
  563. * There appears to be an issue in the controller where
  564. * if you request a small block transfer (< fifo size),
  565. * you may get your DATAEND/DATABLKEND irq without the
  566. * PIO data irq.
  567. *
  568. * Check to see if there is still data to be read,
  569. * and simulate a PIO irq.
  570. */
  571. if (readl(base + MMCISTATUS) & MCI_RXDATAAVLBL)
  572. msmsdcc_pio_irq(1, host);
  573. msmsdcc_stop_data(host);
  574. if (!data->error)
  575. host->curr.data_xfered = host->curr.xfer_size;
  576. if (!data->stop)
  577. msmsdcc_request_end(host, data->mrq);
  578. else
  579. msmsdcc_start_command(host, data->stop, 0);
  580. }
  581. }
  582. static irqreturn_t
  583. msmsdcc_irq(int irq, void *dev_id)
  584. {
  585. struct msmsdcc_host *host = dev_id;
  586. void __iomem *base = host->base;
  587. u32 status;
  588. int ret = 0;
  589. int cardint = 0;
  590. spin_lock(&host->lock);
  591. do {
  592. struct mmc_data *data;
  593. status = msmsdcc_readl(host, MMCISTATUS);
  594. status &= (msmsdcc_readl(host, MMCIMASK0) |
  595. MCI_DATABLOCKENDMASK);
  596. msmsdcc_writel(host, status, MMCICLEAR);
  597. if (status & MCI_SDIOINTR)
  598. status &= ~MCI_SDIOINTR;
  599. if (!status)
  600. break;
  601. msmsdcc_handle_irq_data(host, status, base);
  602. if (status & (MCI_CMDSENT | MCI_CMDRESPEND | MCI_CMDCRCFAIL |
  603. MCI_CMDTIMEOUT) && host->curr.cmd) {
  604. msmsdcc_do_cmdirq(host, status);
  605. }
  606. if (status & MCI_SDIOINTOPER) {
  607. cardint = 1;
  608. status &= ~MCI_SDIOINTOPER;
  609. }
  610. ret = 1;
  611. } while (status);
  612. spin_unlock(&host->lock);
  613. /*
  614. * We have to delay handling the card interrupt as it calls
  615. * back into the driver.
  616. */
  617. if (cardint)
  618. mmc_signal_sdio_irq(host->mmc);
  619. return IRQ_RETVAL(ret);
  620. }
  621. static void
  622. msmsdcc_request(struct mmc_host *mmc, struct mmc_request *mrq)
  623. {
  624. struct msmsdcc_host *host = mmc_priv(mmc);
  625. unsigned long flags;
  626. WARN_ON(host->curr.mrq != NULL);
  627. WARN_ON(host->pwr == 0);
  628. spin_lock_irqsave(&host->lock, flags);
  629. host->stats.reqs++;
  630. if (host->eject) {
  631. if (mrq->data && !(mrq->data->flags & MMC_DATA_READ)) {
  632. mrq->cmd->error = 0;
  633. mrq->data->bytes_xfered = mrq->data->blksz *
  634. mrq->data->blocks;
  635. } else
  636. mrq->cmd->error = -ENOMEDIUM;
  637. spin_unlock_irqrestore(&host->lock, flags);
  638. mmc_request_done(mmc, mrq);
  639. return;
  640. }
  641. host->curr.mrq = mrq;
  642. if (!host->clks_on)
  643. msmsdcc_enable_clocks(host, 1);
  644. if (mrq->data && mrq->data->flags & MMC_DATA_READ)
  645. msmsdcc_start_data(host, mrq->data);
  646. msmsdcc_start_command(host, mrq->cmd, 0);
  647. if (host->cmdpoll && !msmsdcc_spin_on_status(host,
  648. MCI_CMDRESPEND|MCI_CMDCRCFAIL|MCI_CMDTIMEOUT,
  649. CMD_SPINMAX)) {
  650. uint32_t status = msmsdcc_readl(host, MMCISTATUS);
  651. msmsdcc_do_cmdirq(host, status);
  652. msmsdcc_writel(host,
  653. MCI_CMDRESPEND | MCI_CMDCRCFAIL | MCI_CMDTIMEOUT,
  654. MMCICLEAR);
  655. host->stats.cmdpoll_hits++;
  656. } else {
  657. host->stats.cmdpoll_misses++;
  658. mod_timer(&host->command_timer, jiffies + HZ);
  659. }
  660. spin_unlock_irqrestore(&host->lock, flags);
  661. }
  662. static void
  663. msmsdcc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  664. {
  665. struct msmsdcc_host *host = mmc_priv(mmc);
  666. u32 clk = 0, pwr = 0;
  667. int rc;
  668. unsigned long flags;
  669. spin_lock_irqsave(&host->lock, flags);
  670. if (!host->clks_on)
  671. msmsdcc_enable_clocks(host, 1);
  672. if (ios->clock) {
  673. if (ios->clock != host->clk_rate) {
  674. rc = clk_set_rate(host->clk, ios->clock);
  675. if (rc < 0)
  676. pr_err("%s: Error setting clock rate (%d)\n",
  677. mmc_hostname(host->mmc), rc);
  678. else
  679. host->clk_rate = ios->clock;
  680. }
  681. clk |= MCI_CLK_ENABLE;
  682. }
  683. if (ios->bus_width == MMC_BUS_WIDTH_4)
  684. clk |= (2 << 10); /* Set WIDEBUS */
  685. if (ios->clock > 400000 && msmsdcc_pwrsave)
  686. clk |= (1 << 9); /* PWRSAVE */
  687. clk |= (1 << 12); /* FLOW_ENA */
  688. clk |= (1 << 15); /* feedback clock */
  689. if (host->plat->translate_vdd)
  690. pwr |= host->plat->translate_vdd(mmc_dev(mmc), ios->vdd);
  691. switch (ios->power_mode) {
  692. case MMC_POWER_OFF:
  693. break;
  694. case MMC_POWER_UP:
  695. pwr |= MCI_PWR_UP;
  696. break;
  697. case MMC_POWER_ON:
  698. pwr |= MCI_PWR_ON;
  699. break;
  700. }
  701. if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
  702. pwr |= MCI_OD;
  703. msmsdcc_writel(host, clk, MMCICLOCK);
  704. if (host->pwr != pwr) {
  705. host->pwr = pwr;
  706. msmsdcc_writel(host, pwr, MMCIPOWER);
  707. }
  708. if (host->clks_on)
  709. msmsdcc_enable_clocks(host, 0);
  710. spin_unlock_irqrestore(&host->lock, flags);
  711. }
  712. static void msmsdcc_enable_sdio_irq(struct mmc_host *mmc, int enable)
  713. {
  714. struct msmsdcc_host *host = mmc_priv(mmc);
  715. unsigned long flags;
  716. u32 status;
  717. spin_lock_irqsave(&host->lock, flags);
  718. if (msmsdcc_sdioirq == 1) {
  719. status = msmsdcc_readl(host, MMCIMASK0);
  720. if (enable)
  721. status |= MCI_SDIOINTOPERMASK;
  722. else
  723. status &= ~MCI_SDIOINTOPERMASK;
  724. host->saved_irq0mask = status;
  725. msmsdcc_writel(host, status, MMCIMASK0);
  726. }
  727. spin_unlock_irqrestore(&host->lock, flags);
  728. }
  729. static const struct mmc_host_ops msmsdcc_ops = {
  730. .request = msmsdcc_request,
  731. .set_ios = msmsdcc_set_ios,
  732. .enable_sdio_irq = msmsdcc_enable_sdio_irq,
  733. };
  734. static void
  735. msmsdcc_check_status(unsigned long data)
  736. {
  737. struct msmsdcc_host *host = (struct msmsdcc_host *)data;
  738. unsigned int status;
  739. if (!host->plat->status) {
  740. mmc_detect_change(host->mmc, 0);
  741. goto out;
  742. }
  743. status = host->plat->status(mmc_dev(host->mmc));
  744. host->eject = !status;
  745. if (status ^ host->oldstat) {
  746. pr_info("%s: Slot status change detected (%d -> %d)\n",
  747. mmc_hostname(host->mmc), host->oldstat, status);
  748. if (status)
  749. mmc_detect_change(host->mmc, (5 * HZ) / 2);
  750. else
  751. mmc_detect_change(host->mmc, 0);
  752. }
  753. host->oldstat = status;
  754. out:
  755. if (host->timer.function)
  756. mod_timer(&host->timer, jiffies + HZ);
  757. }
  758. static irqreturn_t
  759. msmsdcc_platform_status_irq(int irq, void *dev_id)
  760. {
  761. struct msmsdcc_host *host = dev_id;
  762. printk(KERN_DEBUG "%s: %d\n", __func__, irq);
  763. msmsdcc_check_status((unsigned long) host);
  764. return IRQ_HANDLED;
  765. }
  766. static void
  767. msmsdcc_status_notify_cb(int card_present, void *dev_id)
  768. {
  769. struct msmsdcc_host *host = dev_id;
  770. printk(KERN_DEBUG "%s: card_present %d\n", mmc_hostname(host->mmc),
  771. card_present);
  772. msmsdcc_check_status((unsigned long) host);
  773. }
  774. static void
  775. msmsdcc_busclk_expired(unsigned long _data)
  776. {
  777. struct msmsdcc_host *host = (struct msmsdcc_host *) _data;
  778. unsigned long flags;
  779. spin_lock_irqsave(&host->lock, flags);
  780. if (host->clks_on)
  781. msmsdcc_enable_clocks(host, 0);
  782. spin_unlock_irqrestore(&host->lock, flags);
  783. }
  784. /*
  785. * called when a command expires.
  786. * Dump some debugging, and then error
  787. * out the transaction.
  788. */
  789. static void
  790. msmsdcc_command_expired(unsigned long _data)
  791. {
  792. struct msmsdcc_host *host = (struct msmsdcc_host *) _data;
  793. struct mmc_request *mrq;
  794. unsigned long flags;
  795. spin_lock_irqsave(&host->lock, flags);
  796. mrq = host->curr.mrq;
  797. if (!mrq) {
  798. spin_unlock_irqrestore(&host->lock, flags);
  799. return;
  800. }
  801. pr_err("%s: Controller lockup detected\n",
  802. mmc_hostname(host->mmc));
  803. mrq->cmd->error = -ETIMEDOUT;
  804. msmsdcc_stop_data(host);
  805. msmsdcc_writel(host, 0, MMCICOMMAND);
  806. host->curr.mrq = NULL;
  807. host->curr.cmd = NULL;
  808. if (host->clks_on)
  809. msmsdcc_enable_clocks(host, 0);
  810. spin_unlock_irqrestore(&host->lock, flags);
  811. mmc_request_done(host->mmc, mrq);
  812. }
  813. static int
  814. msmsdcc_init_dma(struct msmsdcc_host *host)
  815. {
  816. memset(&host->dma, 0, sizeof(struct msmsdcc_dma_data));
  817. host->dma.host = host;
  818. host->dma.channel = -1;
  819. if (!host->dmares)
  820. return -ENODEV;
  821. host->dma.nc = dma_alloc_coherent(NULL,
  822. sizeof(struct msmsdcc_nc_dmadata),
  823. &host->dma.nc_busaddr,
  824. GFP_KERNEL);
  825. if (host->dma.nc == NULL) {
  826. pr_err("Unable to allocate DMA buffer\n");
  827. return -ENOMEM;
  828. }
  829. memset(host->dma.nc, 0x00, sizeof(struct msmsdcc_nc_dmadata));
  830. host->dma.cmd_busaddr = host->dma.nc_busaddr;
  831. host->dma.cmdptr_busaddr = host->dma.nc_busaddr +
  832. offsetof(struct msmsdcc_nc_dmadata, cmdptr);
  833. host->dma.channel = host->dmares->start;
  834. return 0;
  835. }
  836. #ifdef CONFIG_MMC_MSM7X00A_RESUME_IN_WQ
  837. static void
  838. do_resume_work(struct work_struct *work)
  839. {
  840. struct msmsdcc_host *host =
  841. container_of(work, struct msmsdcc_host, resume_task);
  842. struct mmc_host *mmc = host->mmc;
  843. if (mmc) {
  844. mmc_resume_host(mmc);
  845. if (host->stat_irq)
  846. enable_irq(host->stat_irq);
  847. }
  848. }
  849. #endif
  850. static int
  851. msmsdcc_probe(struct platform_device *pdev)
  852. {
  853. struct mmc_platform_data *plat = pdev->dev.platform_data;
  854. struct msmsdcc_host *host;
  855. struct mmc_host *mmc;
  856. struct resource *cmd_irqres = NULL;
  857. struct resource *pio_irqres = NULL;
  858. struct resource *stat_irqres = NULL;
  859. struct resource *memres = NULL;
  860. struct resource *dmares = NULL;
  861. int ret;
  862. /* must have platform data */
  863. if (!plat) {
  864. pr_err("%s: Platform data not available\n", __func__);
  865. ret = -EINVAL;
  866. goto out;
  867. }
  868. if (pdev->id < 1 || pdev->id > 4)
  869. return -EINVAL;
  870. if (pdev->resource == NULL || pdev->num_resources < 2) {
  871. pr_err("%s: Invalid resource\n", __func__);
  872. return -ENXIO;
  873. }
  874. memres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  875. dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  876. cmd_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
  877. "cmd_irq");
  878. pio_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
  879. "pio_irq");
  880. stat_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
  881. "status_irq");
  882. if (!cmd_irqres || !pio_irqres || !memres) {
  883. pr_err("%s: Invalid resource\n", __func__);
  884. return -ENXIO;
  885. }
  886. /*
  887. * Setup our host structure
  888. */
  889. mmc = mmc_alloc_host(sizeof(struct msmsdcc_host), &pdev->dev);
  890. if (!mmc) {
  891. ret = -ENOMEM;
  892. goto out;
  893. }
  894. host = mmc_priv(mmc);
  895. host->pdev_id = pdev->id;
  896. host->plat = plat;
  897. host->mmc = mmc;
  898. host->cmdpoll = 1;
  899. host->use_bustimer = 1;
  900. host->base = ioremap(memres->start, PAGE_SIZE);
  901. if (!host->base) {
  902. ret = -ENOMEM;
  903. goto out;
  904. }
  905. host->cmd_irqres = cmd_irqres;
  906. host->pio_irqres = pio_irqres;
  907. host->memres = memres;
  908. host->dmares = dmares;
  909. spin_lock_init(&host->lock);
  910. /*
  911. * Setup DMA
  912. */
  913. msmsdcc_init_dma(host);
  914. /* Get our clocks */
  915. host->pclk = clk_get(&pdev->dev, "sdc_pclk");
  916. if (IS_ERR(host->pclk)) {
  917. ret = PTR_ERR(host->pclk);
  918. goto host_free;
  919. }
  920. host->clk = clk_get(&pdev->dev, "sdc_clk");
  921. if (IS_ERR(host->clk)) {
  922. ret = PTR_ERR(host->clk);
  923. goto pclk_put;
  924. }
  925. /* Enable clocks */
  926. ret = msmsdcc_enable_clocks(host, 1);
  927. if (ret)
  928. goto clk_put;
  929. ret = clk_set_rate(host->clk, msmsdcc_fmin);
  930. if (ret) {
  931. pr_err("%s: Clock rate set failed (%d)\n", __func__, ret);
  932. goto clk_disable;
  933. }
  934. host->pclk_rate = clk_get_rate(host->pclk);
  935. host->clk_rate = clk_get_rate(host->clk);
  936. /*
  937. * Setup MMC host structure
  938. */
  939. mmc->ops = &msmsdcc_ops;
  940. mmc->f_min = msmsdcc_fmin;
  941. mmc->f_max = msmsdcc_fmax;
  942. mmc->ocr_avail = plat->ocr_mask;
  943. if (msmsdcc_4bit)
  944. mmc->caps |= MMC_CAP_4_BIT_DATA;
  945. if (msmsdcc_sdioirq)
  946. mmc->caps |= MMC_CAP_SDIO_IRQ;
  947. mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED;
  948. mmc->max_phys_segs = NR_SG;
  949. mmc->max_hw_segs = NR_SG;
  950. mmc->max_blk_size = 4096; /* MCI_DATA_CTL BLOCKSIZE up to 4096 */
  951. mmc->max_blk_count = 65536;
  952. mmc->max_req_size = 33554432; /* MCI_DATA_LENGTH is 25 bits */
  953. mmc->max_seg_size = mmc->max_req_size;
  954. msmsdcc_writel(host, 0, MMCIMASK0);
  955. msmsdcc_writel(host, 0x5e007ff, MMCICLEAR);
  956. msmsdcc_writel(host, MCI_IRQENABLE, MMCIMASK0);
  957. host->saved_irq0mask = MCI_IRQENABLE;
  958. /*
  959. * Setup card detect change
  960. */
  961. memset(&host->timer, 0, sizeof(host->timer));
  962. if (stat_irqres && !(stat_irqres->flags & IORESOURCE_DISABLED)) {
  963. unsigned long irqflags = IRQF_SHARED |
  964. (stat_irqres->flags & IRQF_TRIGGER_MASK);
  965. host->stat_irq = stat_irqres->start;
  966. ret = request_irq(host->stat_irq,
  967. msmsdcc_platform_status_irq,
  968. irqflags,
  969. DRIVER_NAME " (slot)",
  970. host);
  971. if (ret) {
  972. pr_err("%s: Unable to get slot IRQ %d (%d)\n",
  973. mmc_hostname(mmc), host->stat_irq, ret);
  974. goto clk_disable;
  975. }
  976. } else if (plat->register_status_notify) {
  977. plat->register_status_notify(msmsdcc_status_notify_cb, host);
  978. } else if (!plat->status)
  979. pr_err("%s: No card detect facilities available\n",
  980. mmc_hostname(mmc));
  981. else {
  982. init_timer(&host->timer);
  983. host->timer.data = (unsigned long)host;
  984. host->timer.function = msmsdcc_check_status;
  985. host->timer.expires = jiffies + HZ;
  986. add_timer(&host->timer);
  987. }
  988. if (plat->status) {
  989. host->oldstat = host->plat->status(mmc_dev(host->mmc));
  990. host->eject = !host->oldstat;
  991. }
  992. /*
  993. * Setup a command timer. We currently need this due to
  994. * some 'strange' timeout / error handling situations.
  995. */
  996. init_timer(&host->command_timer);
  997. host->command_timer.data = (unsigned long) host;
  998. host->command_timer.function = msmsdcc_command_expired;
  999. init_timer(&host->busclk_timer);
  1000. host->busclk_timer.data = (unsigned long) host;
  1001. host->busclk_timer.function = msmsdcc_busclk_expired;
  1002. ret = request_irq(cmd_irqres->start, msmsdcc_irq, IRQF_SHARED,
  1003. DRIVER_NAME " (cmd)", host);
  1004. if (ret)
  1005. goto stat_irq_free;
  1006. ret = request_irq(pio_irqres->start, msmsdcc_pio_irq, IRQF_SHARED,
  1007. DRIVER_NAME " (pio)", host);
  1008. if (ret)
  1009. goto cmd_irq_free;
  1010. mmc_set_drvdata(pdev, mmc);
  1011. mmc_add_host(mmc);
  1012. pr_info("%s: Qualcomm MSM SDCC at 0x%016llx irq %d,%d dma %d\n",
  1013. mmc_hostname(mmc), (unsigned long long)memres->start,
  1014. (unsigned int) cmd_irqres->start,
  1015. (unsigned int) host->stat_irq, host->dma.channel);
  1016. pr_info("%s: 4 bit data mode %s\n", mmc_hostname(mmc),
  1017. (mmc->caps & MMC_CAP_4_BIT_DATA ? "enabled" : "disabled"));
  1018. pr_info("%s: MMC clock %u -> %u Hz, PCLK %u Hz\n",
  1019. mmc_hostname(mmc), msmsdcc_fmin, msmsdcc_fmax, host->pclk_rate);
  1020. pr_info("%s: Slot eject status = %d\n", mmc_hostname(mmc), host->eject);
  1021. pr_info("%s: Power save feature enable = %d\n",
  1022. mmc_hostname(mmc), msmsdcc_pwrsave);
  1023. if (host->dma.channel != -1) {
  1024. pr_info("%s: DM non-cached buffer at %p, dma_addr 0x%.8x\n",
  1025. mmc_hostname(mmc), host->dma.nc, host->dma.nc_busaddr);
  1026. pr_info("%s: DM cmd busaddr 0x%.8x, cmdptr busaddr 0x%.8x\n",
  1027. mmc_hostname(mmc), host->dma.cmd_busaddr,
  1028. host->dma.cmdptr_busaddr);
  1029. } else
  1030. pr_info("%s: PIO transfer enabled\n", mmc_hostname(mmc));
  1031. if (host->timer.function)
  1032. pr_info("%s: Polling status mode enabled\n", mmc_hostname(mmc));
  1033. return 0;
  1034. cmd_irq_free:
  1035. free_irq(cmd_irqres->start, host);
  1036. stat_irq_free:
  1037. if (host->stat_irq)
  1038. free_irq(host->stat_irq, host);
  1039. clk_disable:
  1040. msmsdcc_enable_clocks(host, 0);
  1041. clk_put:
  1042. clk_put(host->clk);
  1043. pclk_put:
  1044. clk_put(host->pclk);
  1045. host_free:
  1046. mmc_free_host(mmc);
  1047. out:
  1048. return ret;
  1049. }
  1050. static int
  1051. msmsdcc_suspend(struct platform_device *dev, pm_message_t state)
  1052. {
  1053. struct mmc_host *mmc = mmc_get_drvdata(dev);
  1054. int rc = 0;
  1055. if (mmc) {
  1056. struct msmsdcc_host *host = mmc_priv(mmc);
  1057. if (host->stat_irq)
  1058. disable_irq(host->stat_irq);
  1059. if (mmc->card && mmc->card->type != MMC_TYPE_SDIO)
  1060. rc = mmc_suspend_host(mmc, state);
  1061. if (!rc) {
  1062. msmsdcc_writel(host, 0, MMCIMASK0);
  1063. if (host->clks_on)
  1064. msmsdcc_enable_clocks(host, 0);
  1065. }
  1066. }
  1067. return rc;
  1068. }
  1069. static int
  1070. msmsdcc_resume(struct platform_device *dev)
  1071. {
  1072. struct mmc_host *mmc = mmc_get_drvdata(dev);
  1073. unsigned long flags;
  1074. if (mmc) {
  1075. struct msmsdcc_host *host = mmc_priv(mmc);
  1076. spin_lock_irqsave(&host->lock, flags);
  1077. if (!host->clks_on)
  1078. msmsdcc_enable_clocks(host, 1);
  1079. msmsdcc_writel(host, host->saved_irq0mask, MMCIMASK0);
  1080. spin_unlock_irqrestore(&host->lock, flags);
  1081. if (mmc->card && mmc->card->type != MMC_TYPE_SDIO)
  1082. mmc_resume_host(mmc);
  1083. if (host->stat_irq)
  1084. enable_irq(host->stat_irq);
  1085. }
  1086. return 0;
  1087. }
  1088. static struct platform_driver msmsdcc_driver = {
  1089. .probe = msmsdcc_probe,
  1090. .suspend = msmsdcc_suspend,
  1091. .resume = msmsdcc_resume,
  1092. .driver = {
  1093. .name = "msm_sdcc",
  1094. },
  1095. };
  1096. static int __init msmsdcc_init(void)
  1097. {
  1098. return platform_driver_register(&msmsdcc_driver);
  1099. }
  1100. static void __exit msmsdcc_exit(void)
  1101. {
  1102. platform_driver_unregister(&msmsdcc_driver);
  1103. }
  1104. module_init(msmsdcc_init);
  1105. module_exit(msmsdcc_exit);
  1106. MODULE_DESCRIPTION("Qualcomm MSM 7X00A Multimedia Card Interface driver");
  1107. MODULE_LICENSE("GPL");