msm_sdcc.c 32 KB

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