msm_sdcc.c 33 KB

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