msm_sdcc.c 33 KB

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