msm_sdcc.c 33 KB

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