msm_sdcc.c 32 KB

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