mxcmmc.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  1. /*
  2. * linux/drivers/mmc/host/mxcmmc.c - Freescale i.MX MMCI driver
  3. *
  4. * This is a driver for the SDHC controller found in Freescale MX2/MX3
  5. * SoCs. It is basically the same hardware as found on MX1 (imxmmc.c).
  6. * Unlike the hardware found on MX1, this hardware just works and does
  7. * not need all the quirks found in imxmmc.c, hence the separate driver.
  8. *
  9. * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
  10. * Copyright (C) 2006 Pavel Pisa, PiKRON <ppisa@pikron.com>
  11. *
  12. * derived from pxamci.c by Russell King
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2 as
  16. * published by the Free Software Foundation.
  17. *
  18. */
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/ioport.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/irq.h>
  25. #include <linux/blkdev.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/mmc/host.h>
  28. #include <linux/mmc/card.h>
  29. #include <linux/delay.h>
  30. #include <linux/clk.h>
  31. #include <linux/io.h>
  32. #include <linux/gpio.h>
  33. #include <linux/regulator/consumer.h>
  34. #include <linux/dmaengine.h>
  35. #include <linux/types.h>
  36. #include <linux/of.h>
  37. #include <linux/of_device.h>
  38. #include <linux/of_dma.h>
  39. #include <linux/of_gpio.h>
  40. #include <linux/mmc/slot-gpio.h>
  41. #include <asm/dma.h>
  42. #include <asm/irq.h>
  43. #include <linux/platform_data/mmc-mxcmmc.h>
  44. #include <linux/platform_data/dma-imx.h>
  45. #define DRIVER_NAME "mxc-mmc"
  46. #define MXCMCI_TIMEOUT_MS 10000
  47. #define MMC_REG_STR_STP_CLK 0x00
  48. #define MMC_REG_STATUS 0x04
  49. #define MMC_REG_CLK_RATE 0x08
  50. #define MMC_REG_CMD_DAT_CONT 0x0C
  51. #define MMC_REG_RES_TO 0x10
  52. #define MMC_REG_READ_TO 0x14
  53. #define MMC_REG_BLK_LEN 0x18
  54. #define MMC_REG_NOB 0x1C
  55. #define MMC_REG_REV_NO 0x20
  56. #define MMC_REG_INT_CNTR 0x24
  57. #define MMC_REG_CMD 0x28
  58. #define MMC_REG_ARG 0x2C
  59. #define MMC_REG_RES_FIFO 0x34
  60. #define MMC_REG_BUFFER_ACCESS 0x38
  61. #define STR_STP_CLK_RESET (1 << 3)
  62. #define STR_STP_CLK_START_CLK (1 << 1)
  63. #define STR_STP_CLK_STOP_CLK (1 << 0)
  64. #define STATUS_CARD_INSERTION (1 << 31)
  65. #define STATUS_CARD_REMOVAL (1 << 30)
  66. #define STATUS_YBUF_EMPTY (1 << 29)
  67. #define STATUS_XBUF_EMPTY (1 << 28)
  68. #define STATUS_YBUF_FULL (1 << 27)
  69. #define STATUS_XBUF_FULL (1 << 26)
  70. #define STATUS_BUF_UND_RUN (1 << 25)
  71. #define STATUS_BUF_OVFL (1 << 24)
  72. #define STATUS_SDIO_INT_ACTIVE (1 << 14)
  73. #define STATUS_END_CMD_RESP (1 << 13)
  74. #define STATUS_WRITE_OP_DONE (1 << 12)
  75. #define STATUS_DATA_TRANS_DONE (1 << 11)
  76. #define STATUS_READ_OP_DONE (1 << 11)
  77. #define STATUS_WR_CRC_ERROR_CODE_MASK (3 << 10)
  78. #define STATUS_CARD_BUS_CLK_RUN (1 << 8)
  79. #define STATUS_BUF_READ_RDY (1 << 7)
  80. #define STATUS_BUF_WRITE_RDY (1 << 6)
  81. #define STATUS_RESP_CRC_ERR (1 << 5)
  82. #define STATUS_CRC_READ_ERR (1 << 3)
  83. #define STATUS_CRC_WRITE_ERR (1 << 2)
  84. #define STATUS_TIME_OUT_RESP (1 << 1)
  85. #define STATUS_TIME_OUT_READ (1 << 0)
  86. #define STATUS_ERR_MASK 0x2f
  87. #define CMD_DAT_CONT_CMD_RESP_LONG_OFF (1 << 12)
  88. #define CMD_DAT_CONT_STOP_READWAIT (1 << 11)
  89. #define CMD_DAT_CONT_START_READWAIT (1 << 10)
  90. #define CMD_DAT_CONT_BUS_WIDTH_4 (2 << 8)
  91. #define CMD_DAT_CONT_INIT (1 << 7)
  92. #define CMD_DAT_CONT_WRITE (1 << 4)
  93. #define CMD_DAT_CONT_DATA_ENABLE (1 << 3)
  94. #define CMD_DAT_CONT_RESPONSE_48BIT_CRC (1 << 0)
  95. #define CMD_DAT_CONT_RESPONSE_136BIT (2 << 0)
  96. #define CMD_DAT_CONT_RESPONSE_48BIT (3 << 0)
  97. #define INT_SDIO_INT_WKP_EN (1 << 18)
  98. #define INT_CARD_INSERTION_WKP_EN (1 << 17)
  99. #define INT_CARD_REMOVAL_WKP_EN (1 << 16)
  100. #define INT_CARD_INSERTION_EN (1 << 15)
  101. #define INT_CARD_REMOVAL_EN (1 << 14)
  102. #define INT_SDIO_IRQ_EN (1 << 13)
  103. #define INT_DAT0_EN (1 << 12)
  104. #define INT_BUF_READ_EN (1 << 4)
  105. #define INT_BUF_WRITE_EN (1 << 3)
  106. #define INT_END_CMD_RES_EN (1 << 2)
  107. #define INT_WRITE_OP_DONE_EN (1 << 1)
  108. #define INT_READ_OP_EN (1 << 0)
  109. enum mxcmci_type {
  110. IMX21_MMC,
  111. IMX31_MMC,
  112. MPC512X_MMC,
  113. };
  114. struct mxcmci_host {
  115. struct mmc_host *mmc;
  116. struct resource *res;
  117. void __iomem *base;
  118. int irq;
  119. int detect_irq;
  120. struct dma_chan *dma;
  121. struct dma_async_tx_descriptor *desc;
  122. int do_dma;
  123. int default_irq_mask;
  124. int use_sdio;
  125. unsigned int power_mode;
  126. struct imxmmc_platform_data *pdata;
  127. struct mmc_request *req;
  128. struct mmc_command *cmd;
  129. struct mmc_data *data;
  130. unsigned int datasize;
  131. unsigned int dma_dir;
  132. u16 rev_no;
  133. unsigned int cmdat;
  134. struct clk *clk_ipg;
  135. struct clk *clk_per;
  136. int clock;
  137. struct work_struct datawork;
  138. spinlock_t lock;
  139. struct regulator *vcc;
  140. int burstlen;
  141. int dmareq;
  142. struct dma_slave_config dma_slave_config;
  143. struct imx_dma_data dma_data;
  144. struct timer_list watchdog;
  145. enum mxcmci_type devtype;
  146. };
  147. static const struct platform_device_id mxcmci_devtype[] = {
  148. {
  149. .name = "imx21-mmc",
  150. .driver_data = IMX21_MMC,
  151. }, {
  152. .name = "imx31-mmc",
  153. .driver_data = IMX31_MMC,
  154. }, {
  155. .name = "mpc512x-sdhc",
  156. .driver_data = MPC512X_MMC,
  157. }, {
  158. /* sentinel */
  159. }
  160. };
  161. MODULE_DEVICE_TABLE(platform, mxcmci_devtype);
  162. static const struct of_device_id mxcmci_of_match[] = {
  163. {
  164. .compatible = "fsl,imx21-mmc",
  165. .data = &mxcmci_devtype[IMX21_MMC],
  166. }, {
  167. .compatible = "fsl,imx31-mmc",
  168. .data = &mxcmci_devtype[IMX31_MMC],
  169. }, {
  170. .compatible = "fsl,mpc5121-sdhc",
  171. .data = &mxcmci_devtype[MPC512X_MMC],
  172. }, {
  173. /* sentinel */
  174. }
  175. };
  176. MODULE_DEVICE_TABLE(of, mxcmci_of_match);
  177. static inline int is_imx31_mmc(struct mxcmci_host *host)
  178. {
  179. return host->devtype == IMX31_MMC;
  180. }
  181. static inline int is_mpc512x_mmc(struct mxcmci_host *host)
  182. {
  183. return host->devtype == MPC512X_MMC;
  184. }
  185. static inline u32 mxcmci_readl(struct mxcmci_host *host, int reg)
  186. {
  187. if (IS_ENABLED(CONFIG_PPC_MPC512x))
  188. return ioread32be(host->base + reg);
  189. else
  190. return readl(host->base + reg);
  191. }
  192. static inline void mxcmci_writel(struct mxcmci_host *host, u32 val, int reg)
  193. {
  194. if (IS_ENABLED(CONFIG_PPC_MPC512x))
  195. iowrite32be(val, host->base + reg);
  196. else
  197. writel(val, host->base + reg);
  198. }
  199. static inline u16 mxcmci_readw(struct mxcmci_host *host, int reg)
  200. {
  201. if (IS_ENABLED(CONFIG_PPC_MPC512x))
  202. return ioread32be(host->base + reg);
  203. else
  204. return readw(host->base + reg);
  205. }
  206. static inline void mxcmci_writew(struct mxcmci_host *host, u16 val, int reg)
  207. {
  208. if (IS_ENABLED(CONFIG_PPC_MPC512x))
  209. iowrite32be(val, host->base + reg);
  210. else
  211. writew(val, host->base + reg);
  212. }
  213. static void mxcmci_set_clk_rate(struct mxcmci_host *host, unsigned int clk_ios);
  214. static inline void mxcmci_init_ocr(struct mxcmci_host *host)
  215. {
  216. host->vcc = regulator_get(mmc_dev(host->mmc), "vmmc");
  217. if (IS_ERR(host->vcc)) {
  218. host->vcc = NULL;
  219. } else {
  220. host->mmc->ocr_avail = mmc_regulator_get_ocrmask(host->vcc);
  221. if (host->pdata && host->pdata->ocr_avail)
  222. dev_warn(mmc_dev(host->mmc),
  223. "pdata->ocr_avail will not be used\n");
  224. }
  225. if (host->vcc == NULL) {
  226. /* fall-back to platform data */
  227. if (host->pdata && host->pdata->ocr_avail)
  228. host->mmc->ocr_avail = host->pdata->ocr_avail;
  229. else
  230. host->mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
  231. }
  232. }
  233. static inline void mxcmci_set_power(struct mxcmci_host *host,
  234. unsigned char power_mode,
  235. unsigned int vdd)
  236. {
  237. if (host->vcc) {
  238. if (power_mode == MMC_POWER_UP)
  239. mmc_regulator_set_ocr(host->mmc, host->vcc, vdd);
  240. else if (power_mode == MMC_POWER_OFF)
  241. mmc_regulator_set_ocr(host->mmc, host->vcc, 0);
  242. }
  243. if (host->pdata && host->pdata->setpower)
  244. host->pdata->setpower(mmc_dev(host->mmc), vdd);
  245. }
  246. static inline int mxcmci_use_dma(struct mxcmci_host *host)
  247. {
  248. return host->do_dma;
  249. }
  250. static void mxcmci_softreset(struct mxcmci_host *host)
  251. {
  252. int i;
  253. dev_dbg(mmc_dev(host->mmc), "mxcmci_softreset\n");
  254. /* reset sequence */
  255. mxcmci_writew(host, STR_STP_CLK_RESET, MMC_REG_STR_STP_CLK);
  256. mxcmci_writew(host, STR_STP_CLK_RESET | STR_STP_CLK_START_CLK,
  257. MMC_REG_STR_STP_CLK);
  258. for (i = 0; i < 8; i++)
  259. mxcmci_writew(host, STR_STP_CLK_START_CLK, MMC_REG_STR_STP_CLK);
  260. mxcmci_writew(host, 0xff, MMC_REG_RES_TO);
  261. }
  262. static int mxcmci_setup_dma(struct mmc_host *mmc);
  263. static int mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data)
  264. {
  265. unsigned int nob = data->blocks;
  266. unsigned int blksz = data->blksz;
  267. unsigned int datasize = nob * blksz;
  268. struct scatterlist *sg;
  269. enum dma_transfer_direction slave_dirn;
  270. int i, nents;
  271. if (data->flags & MMC_DATA_STREAM)
  272. nob = 0xffff;
  273. host->data = data;
  274. data->bytes_xfered = 0;
  275. mxcmci_writew(host, nob, MMC_REG_NOB);
  276. mxcmci_writew(host, blksz, MMC_REG_BLK_LEN);
  277. host->datasize = datasize;
  278. if (!mxcmci_use_dma(host))
  279. return 0;
  280. for_each_sg(data->sg, sg, data->sg_len, i) {
  281. if (sg->offset & 3 || sg->length & 3 || sg->length < 512) {
  282. host->do_dma = 0;
  283. return 0;
  284. }
  285. }
  286. if (data->flags & MMC_DATA_READ) {
  287. host->dma_dir = DMA_FROM_DEVICE;
  288. slave_dirn = DMA_DEV_TO_MEM;
  289. } else {
  290. host->dma_dir = DMA_TO_DEVICE;
  291. slave_dirn = DMA_MEM_TO_DEV;
  292. }
  293. nents = dma_map_sg(host->dma->device->dev, data->sg,
  294. data->sg_len, host->dma_dir);
  295. if (nents != data->sg_len)
  296. return -EINVAL;
  297. host->desc = dmaengine_prep_slave_sg(host->dma,
  298. data->sg, data->sg_len, slave_dirn,
  299. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  300. if (!host->desc) {
  301. dma_unmap_sg(host->dma->device->dev, data->sg, data->sg_len,
  302. host->dma_dir);
  303. host->do_dma = 0;
  304. return 0; /* Fall back to PIO */
  305. }
  306. wmb();
  307. dmaengine_submit(host->desc);
  308. dma_async_issue_pending(host->dma);
  309. mod_timer(&host->watchdog, jiffies + msecs_to_jiffies(MXCMCI_TIMEOUT_MS));
  310. return 0;
  311. }
  312. static void mxcmci_cmd_done(struct mxcmci_host *host, unsigned int stat);
  313. static void mxcmci_data_done(struct mxcmci_host *host, unsigned int stat);
  314. static void mxcmci_dma_callback(void *data)
  315. {
  316. struct mxcmci_host *host = data;
  317. u32 stat;
  318. del_timer(&host->watchdog);
  319. stat = mxcmci_readl(host, MMC_REG_STATUS);
  320. mxcmci_writel(host, stat & ~STATUS_DATA_TRANS_DONE, MMC_REG_STATUS);
  321. dev_dbg(mmc_dev(host->mmc), "%s: 0x%08x\n", __func__, stat);
  322. if (stat & STATUS_READ_OP_DONE)
  323. mxcmci_writel(host, STATUS_READ_OP_DONE, MMC_REG_STATUS);
  324. mxcmci_data_done(host, stat);
  325. }
  326. static int mxcmci_start_cmd(struct mxcmci_host *host, struct mmc_command *cmd,
  327. unsigned int cmdat)
  328. {
  329. u32 int_cntr = host->default_irq_mask;
  330. unsigned long flags;
  331. WARN_ON(host->cmd != NULL);
  332. host->cmd = cmd;
  333. switch (mmc_resp_type(cmd)) {
  334. case MMC_RSP_R1: /* short CRC, OPCODE */
  335. case MMC_RSP_R1B:/* short CRC, OPCODE, BUSY */
  336. cmdat |= CMD_DAT_CONT_RESPONSE_48BIT_CRC;
  337. break;
  338. case MMC_RSP_R2: /* long 136 bit + CRC */
  339. cmdat |= CMD_DAT_CONT_RESPONSE_136BIT;
  340. break;
  341. case MMC_RSP_R3: /* short */
  342. cmdat |= CMD_DAT_CONT_RESPONSE_48BIT;
  343. break;
  344. case MMC_RSP_NONE:
  345. break;
  346. default:
  347. dev_err(mmc_dev(host->mmc), "unhandled response type 0x%x\n",
  348. mmc_resp_type(cmd));
  349. cmd->error = -EINVAL;
  350. return -EINVAL;
  351. }
  352. int_cntr = INT_END_CMD_RES_EN;
  353. if (mxcmci_use_dma(host)) {
  354. if (host->dma_dir == DMA_FROM_DEVICE) {
  355. host->desc->callback = mxcmci_dma_callback;
  356. host->desc->callback_param = host;
  357. } else {
  358. int_cntr |= INT_WRITE_OP_DONE_EN;
  359. }
  360. }
  361. spin_lock_irqsave(&host->lock, flags);
  362. if (host->use_sdio)
  363. int_cntr |= INT_SDIO_IRQ_EN;
  364. mxcmci_writel(host, int_cntr, MMC_REG_INT_CNTR);
  365. spin_unlock_irqrestore(&host->lock, flags);
  366. mxcmci_writew(host, cmd->opcode, MMC_REG_CMD);
  367. mxcmci_writel(host, cmd->arg, MMC_REG_ARG);
  368. mxcmci_writew(host, cmdat, MMC_REG_CMD_DAT_CONT);
  369. return 0;
  370. }
  371. static void mxcmci_finish_request(struct mxcmci_host *host,
  372. struct mmc_request *req)
  373. {
  374. u32 int_cntr = host->default_irq_mask;
  375. unsigned long flags;
  376. spin_lock_irqsave(&host->lock, flags);
  377. if (host->use_sdio)
  378. int_cntr |= INT_SDIO_IRQ_EN;
  379. mxcmci_writel(host, int_cntr, MMC_REG_INT_CNTR);
  380. spin_unlock_irqrestore(&host->lock, flags);
  381. host->req = NULL;
  382. host->cmd = NULL;
  383. host->data = NULL;
  384. mmc_request_done(host->mmc, req);
  385. }
  386. static int mxcmci_finish_data(struct mxcmci_host *host, unsigned int stat)
  387. {
  388. struct mmc_data *data = host->data;
  389. int data_error;
  390. if (mxcmci_use_dma(host))
  391. dma_unmap_sg(host->dma->device->dev, data->sg, data->sg_len,
  392. host->dma_dir);
  393. if (stat & STATUS_ERR_MASK) {
  394. dev_dbg(mmc_dev(host->mmc), "request failed. status: 0x%08x\n",
  395. stat);
  396. if (stat & STATUS_CRC_READ_ERR) {
  397. dev_err(mmc_dev(host->mmc), "%s: -EILSEQ\n", __func__);
  398. data->error = -EILSEQ;
  399. } else if (stat & STATUS_CRC_WRITE_ERR) {
  400. u32 err_code = (stat >> 9) & 0x3;
  401. if (err_code == 2) { /* No CRC response */
  402. dev_err(mmc_dev(host->mmc),
  403. "%s: No CRC -ETIMEDOUT\n", __func__);
  404. data->error = -ETIMEDOUT;
  405. } else {
  406. dev_err(mmc_dev(host->mmc),
  407. "%s: -EILSEQ\n", __func__);
  408. data->error = -EILSEQ;
  409. }
  410. } else if (stat & STATUS_TIME_OUT_READ) {
  411. dev_err(mmc_dev(host->mmc),
  412. "%s: read -ETIMEDOUT\n", __func__);
  413. data->error = -ETIMEDOUT;
  414. } else {
  415. dev_err(mmc_dev(host->mmc), "%s: -EIO\n", __func__);
  416. data->error = -EIO;
  417. }
  418. } else {
  419. data->bytes_xfered = host->datasize;
  420. }
  421. data_error = data->error;
  422. host->data = NULL;
  423. return data_error;
  424. }
  425. static void mxcmci_read_response(struct mxcmci_host *host, unsigned int stat)
  426. {
  427. struct mmc_command *cmd = host->cmd;
  428. int i;
  429. u32 a, b, c;
  430. if (!cmd)
  431. return;
  432. if (stat & STATUS_TIME_OUT_RESP) {
  433. dev_dbg(mmc_dev(host->mmc), "CMD TIMEOUT\n");
  434. cmd->error = -ETIMEDOUT;
  435. } else if (stat & STATUS_RESP_CRC_ERR && cmd->flags & MMC_RSP_CRC) {
  436. dev_dbg(mmc_dev(host->mmc), "cmd crc error\n");
  437. cmd->error = -EILSEQ;
  438. }
  439. if (cmd->flags & MMC_RSP_PRESENT) {
  440. if (cmd->flags & MMC_RSP_136) {
  441. for (i = 0; i < 4; i++) {
  442. a = mxcmci_readw(host, MMC_REG_RES_FIFO);
  443. b = mxcmci_readw(host, MMC_REG_RES_FIFO);
  444. cmd->resp[i] = a << 16 | b;
  445. }
  446. } else {
  447. a = mxcmci_readw(host, MMC_REG_RES_FIFO);
  448. b = mxcmci_readw(host, MMC_REG_RES_FIFO);
  449. c = mxcmci_readw(host, MMC_REG_RES_FIFO);
  450. cmd->resp[0] = a << 24 | b << 8 | c >> 8;
  451. }
  452. }
  453. }
  454. static int mxcmci_poll_status(struct mxcmci_host *host, u32 mask)
  455. {
  456. u32 stat;
  457. unsigned long timeout = jiffies + HZ;
  458. do {
  459. stat = mxcmci_readl(host, MMC_REG_STATUS);
  460. if (stat & STATUS_ERR_MASK)
  461. return stat;
  462. if (time_after(jiffies, timeout)) {
  463. mxcmci_softreset(host);
  464. mxcmci_set_clk_rate(host, host->clock);
  465. return STATUS_TIME_OUT_READ;
  466. }
  467. if (stat & mask)
  468. return 0;
  469. cpu_relax();
  470. } while (1);
  471. }
  472. static int mxcmci_pull(struct mxcmci_host *host, void *_buf, int bytes)
  473. {
  474. unsigned int stat;
  475. u32 *buf = _buf;
  476. while (bytes > 3) {
  477. stat = mxcmci_poll_status(host,
  478. STATUS_BUF_READ_RDY | STATUS_READ_OP_DONE);
  479. if (stat)
  480. return stat;
  481. *buf++ = cpu_to_le32(mxcmci_readl(host, MMC_REG_BUFFER_ACCESS));
  482. bytes -= 4;
  483. }
  484. if (bytes) {
  485. u8 *b = (u8 *)buf;
  486. u32 tmp;
  487. stat = mxcmci_poll_status(host,
  488. STATUS_BUF_READ_RDY | STATUS_READ_OP_DONE);
  489. if (stat)
  490. return stat;
  491. tmp = cpu_to_le32(mxcmci_readl(host, MMC_REG_BUFFER_ACCESS));
  492. memcpy(b, &tmp, bytes);
  493. }
  494. return 0;
  495. }
  496. static int mxcmci_push(struct mxcmci_host *host, void *_buf, int bytes)
  497. {
  498. unsigned int stat;
  499. u32 *buf = _buf;
  500. while (bytes > 3) {
  501. stat = mxcmci_poll_status(host, STATUS_BUF_WRITE_RDY);
  502. if (stat)
  503. return stat;
  504. mxcmci_writel(host, cpu_to_le32(*buf++), MMC_REG_BUFFER_ACCESS);
  505. bytes -= 4;
  506. }
  507. if (bytes) {
  508. u8 *b = (u8 *)buf;
  509. u32 tmp;
  510. stat = mxcmci_poll_status(host, STATUS_BUF_WRITE_RDY);
  511. if (stat)
  512. return stat;
  513. memcpy(&tmp, b, bytes);
  514. mxcmci_writel(host, cpu_to_le32(tmp), MMC_REG_BUFFER_ACCESS);
  515. }
  516. stat = mxcmci_poll_status(host, STATUS_BUF_WRITE_RDY);
  517. if (stat)
  518. return stat;
  519. return 0;
  520. }
  521. static int mxcmci_transfer_data(struct mxcmci_host *host)
  522. {
  523. struct mmc_data *data = host->req->data;
  524. struct scatterlist *sg;
  525. int stat, i;
  526. host->data = data;
  527. host->datasize = 0;
  528. if (data->flags & MMC_DATA_READ) {
  529. for_each_sg(data->sg, sg, data->sg_len, i) {
  530. stat = mxcmci_pull(host, sg_virt(sg), sg->length);
  531. if (stat)
  532. return stat;
  533. host->datasize += sg->length;
  534. }
  535. } else {
  536. for_each_sg(data->sg, sg, data->sg_len, i) {
  537. stat = mxcmci_push(host, sg_virt(sg), sg->length);
  538. if (stat)
  539. return stat;
  540. host->datasize += sg->length;
  541. }
  542. stat = mxcmci_poll_status(host, STATUS_WRITE_OP_DONE);
  543. if (stat)
  544. return stat;
  545. }
  546. return 0;
  547. }
  548. static void mxcmci_datawork(struct work_struct *work)
  549. {
  550. struct mxcmci_host *host = container_of(work, struct mxcmci_host,
  551. datawork);
  552. int datastat = mxcmci_transfer_data(host);
  553. mxcmci_writel(host, STATUS_READ_OP_DONE | STATUS_WRITE_OP_DONE,
  554. MMC_REG_STATUS);
  555. mxcmci_finish_data(host, datastat);
  556. if (host->req->stop) {
  557. if (mxcmci_start_cmd(host, host->req->stop, 0)) {
  558. mxcmci_finish_request(host, host->req);
  559. return;
  560. }
  561. } else {
  562. mxcmci_finish_request(host, host->req);
  563. }
  564. }
  565. static void mxcmci_data_done(struct mxcmci_host *host, unsigned int stat)
  566. {
  567. struct mmc_request *req;
  568. int data_error;
  569. unsigned long flags;
  570. spin_lock_irqsave(&host->lock, flags);
  571. if (!host->data) {
  572. spin_unlock_irqrestore(&host->lock, flags);
  573. return;
  574. }
  575. if (!host->req) {
  576. spin_unlock_irqrestore(&host->lock, flags);
  577. return;
  578. }
  579. req = host->req;
  580. if (!req->stop)
  581. host->req = NULL; /* we will handle finish req below */
  582. data_error = mxcmci_finish_data(host, stat);
  583. spin_unlock_irqrestore(&host->lock, flags);
  584. mxcmci_read_response(host, stat);
  585. host->cmd = NULL;
  586. if (req->stop) {
  587. if (mxcmci_start_cmd(host, req->stop, 0)) {
  588. mxcmci_finish_request(host, req);
  589. return;
  590. }
  591. } else {
  592. mxcmci_finish_request(host, req);
  593. }
  594. }
  595. static void mxcmci_cmd_done(struct mxcmci_host *host, unsigned int stat)
  596. {
  597. mxcmci_read_response(host, stat);
  598. host->cmd = NULL;
  599. if (!host->data && host->req) {
  600. mxcmci_finish_request(host, host->req);
  601. return;
  602. }
  603. /* For the DMA case the DMA engine handles the data transfer
  604. * automatically. For non DMA we have to do it ourselves.
  605. * Don't do it in interrupt context though.
  606. */
  607. if (!mxcmci_use_dma(host) && host->data)
  608. schedule_work(&host->datawork);
  609. }
  610. static irqreturn_t mxcmci_irq(int irq, void *devid)
  611. {
  612. struct mxcmci_host *host = devid;
  613. unsigned long flags;
  614. bool sdio_irq;
  615. u32 stat;
  616. stat = mxcmci_readl(host, MMC_REG_STATUS);
  617. mxcmci_writel(host,
  618. stat & ~(STATUS_SDIO_INT_ACTIVE | STATUS_DATA_TRANS_DONE |
  619. STATUS_WRITE_OP_DONE),
  620. MMC_REG_STATUS);
  621. dev_dbg(mmc_dev(host->mmc), "%s: 0x%08x\n", __func__, stat);
  622. spin_lock_irqsave(&host->lock, flags);
  623. sdio_irq = (stat & STATUS_SDIO_INT_ACTIVE) && host->use_sdio;
  624. spin_unlock_irqrestore(&host->lock, flags);
  625. if (mxcmci_use_dma(host) &&
  626. (stat & (STATUS_READ_OP_DONE | STATUS_WRITE_OP_DONE)))
  627. mxcmci_writel(host, STATUS_READ_OP_DONE | STATUS_WRITE_OP_DONE,
  628. MMC_REG_STATUS);
  629. if (sdio_irq) {
  630. mxcmci_writel(host, STATUS_SDIO_INT_ACTIVE, MMC_REG_STATUS);
  631. mmc_signal_sdio_irq(host->mmc);
  632. }
  633. if (stat & STATUS_END_CMD_RESP)
  634. mxcmci_cmd_done(host, stat);
  635. if (mxcmci_use_dma(host) &&
  636. (stat & (STATUS_DATA_TRANS_DONE | STATUS_WRITE_OP_DONE))) {
  637. del_timer(&host->watchdog);
  638. mxcmci_data_done(host, stat);
  639. }
  640. if (host->default_irq_mask &&
  641. (stat & (STATUS_CARD_INSERTION | STATUS_CARD_REMOVAL)))
  642. mmc_detect_change(host->mmc, msecs_to_jiffies(200));
  643. return IRQ_HANDLED;
  644. }
  645. static void mxcmci_request(struct mmc_host *mmc, struct mmc_request *req)
  646. {
  647. struct mxcmci_host *host = mmc_priv(mmc);
  648. unsigned int cmdat = host->cmdat;
  649. int error;
  650. WARN_ON(host->req != NULL);
  651. host->req = req;
  652. host->cmdat &= ~CMD_DAT_CONT_INIT;
  653. if (host->dma)
  654. host->do_dma = 1;
  655. if (req->data) {
  656. error = mxcmci_setup_data(host, req->data);
  657. if (error) {
  658. req->cmd->error = error;
  659. goto out;
  660. }
  661. cmdat |= CMD_DAT_CONT_DATA_ENABLE;
  662. if (req->data->flags & MMC_DATA_WRITE)
  663. cmdat |= CMD_DAT_CONT_WRITE;
  664. }
  665. error = mxcmci_start_cmd(host, req->cmd, cmdat);
  666. out:
  667. if (error)
  668. mxcmci_finish_request(host, req);
  669. }
  670. static void mxcmci_set_clk_rate(struct mxcmci_host *host, unsigned int clk_ios)
  671. {
  672. unsigned int divider;
  673. int prescaler = 0;
  674. unsigned int clk_in = clk_get_rate(host->clk_per);
  675. while (prescaler <= 0x800) {
  676. for (divider = 1; divider <= 0xF; divider++) {
  677. int x;
  678. x = (clk_in / (divider + 1));
  679. if (prescaler)
  680. x /= (prescaler * 2);
  681. if (x <= clk_ios)
  682. break;
  683. }
  684. if (divider < 0x10)
  685. break;
  686. if (prescaler == 0)
  687. prescaler = 1;
  688. else
  689. prescaler <<= 1;
  690. }
  691. mxcmci_writew(host, (prescaler << 4) | divider, MMC_REG_CLK_RATE);
  692. dev_dbg(mmc_dev(host->mmc), "scaler: %d divider: %d in: %d out: %d\n",
  693. prescaler, divider, clk_in, clk_ios);
  694. }
  695. static int mxcmci_setup_dma(struct mmc_host *mmc)
  696. {
  697. struct mxcmci_host *host = mmc_priv(mmc);
  698. struct dma_slave_config *config = &host->dma_slave_config;
  699. config->dst_addr = host->res->start + MMC_REG_BUFFER_ACCESS;
  700. config->src_addr = host->res->start + MMC_REG_BUFFER_ACCESS;
  701. config->dst_addr_width = 4;
  702. config->src_addr_width = 4;
  703. config->dst_maxburst = host->burstlen;
  704. config->src_maxburst = host->burstlen;
  705. config->device_fc = false;
  706. return dmaengine_slave_config(host->dma, config);
  707. }
  708. static void mxcmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  709. {
  710. struct mxcmci_host *host = mmc_priv(mmc);
  711. int burstlen, ret;
  712. /*
  713. * use burstlen of 64 (16 words) in 4 bit mode (--> reg value 0)
  714. * use burstlen of 16 (4 words) in 1 bit mode (--> reg value 16)
  715. */
  716. if (ios->bus_width == MMC_BUS_WIDTH_4)
  717. burstlen = 16;
  718. else
  719. burstlen = 4;
  720. if (mxcmci_use_dma(host) && burstlen != host->burstlen) {
  721. host->burstlen = burstlen;
  722. ret = mxcmci_setup_dma(mmc);
  723. if (ret) {
  724. dev_err(mmc_dev(host->mmc),
  725. "failed to config DMA channel. Falling back to PIO\n");
  726. dma_release_channel(host->dma);
  727. host->do_dma = 0;
  728. host->dma = NULL;
  729. }
  730. }
  731. if (ios->bus_width == MMC_BUS_WIDTH_4)
  732. host->cmdat |= CMD_DAT_CONT_BUS_WIDTH_4;
  733. else
  734. host->cmdat &= ~CMD_DAT_CONT_BUS_WIDTH_4;
  735. if (host->power_mode != ios->power_mode) {
  736. mxcmci_set_power(host, ios->power_mode, ios->vdd);
  737. host->power_mode = ios->power_mode;
  738. if (ios->power_mode == MMC_POWER_ON)
  739. host->cmdat |= CMD_DAT_CONT_INIT;
  740. }
  741. if (ios->clock) {
  742. mxcmci_set_clk_rate(host, ios->clock);
  743. mxcmci_writew(host, STR_STP_CLK_START_CLK, MMC_REG_STR_STP_CLK);
  744. } else {
  745. mxcmci_writew(host, STR_STP_CLK_STOP_CLK, MMC_REG_STR_STP_CLK);
  746. }
  747. host->clock = ios->clock;
  748. }
  749. static irqreturn_t mxcmci_detect_irq(int irq, void *data)
  750. {
  751. struct mmc_host *mmc = data;
  752. dev_dbg(mmc_dev(mmc), "%s\n", __func__);
  753. mmc_detect_change(mmc, msecs_to_jiffies(250));
  754. return IRQ_HANDLED;
  755. }
  756. static int mxcmci_get_ro(struct mmc_host *mmc)
  757. {
  758. struct mxcmci_host *host = mmc_priv(mmc);
  759. if (host->pdata && host->pdata->get_ro)
  760. return !!host->pdata->get_ro(mmc_dev(mmc));
  761. /*
  762. * If board doesn't support read only detection (no mmc_gpio
  763. * context or gpio is invalid), then let the mmc core decide
  764. * what to do.
  765. */
  766. return mmc_gpio_get_ro(mmc);
  767. }
  768. static void mxcmci_enable_sdio_irq(struct mmc_host *mmc, int enable)
  769. {
  770. struct mxcmci_host *host = mmc_priv(mmc);
  771. unsigned long flags;
  772. u32 int_cntr;
  773. spin_lock_irqsave(&host->lock, flags);
  774. host->use_sdio = enable;
  775. int_cntr = mxcmci_readl(host, MMC_REG_INT_CNTR);
  776. if (enable)
  777. int_cntr |= INT_SDIO_IRQ_EN;
  778. else
  779. int_cntr &= ~INT_SDIO_IRQ_EN;
  780. mxcmci_writel(host, int_cntr, MMC_REG_INT_CNTR);
  781. spin_unlock_irqrestore(&host->lock, flags);
  782. }
  783. static void mxcmci_init_card(struct mmc_host *host, struct mmc_card *card)
  784. {
  785. struct mxcmci_host *mxcmci = mmc_priv(host);
  786. /*
  787. * MX3 SoCs have a silicon bug which corrupts CRC calculation of
  788. * multi-block transfers when connected SDIO peripheral doesn't
  789. * drive the BUSY line as required by the specs.
  790. * One way to prevent this is to only allow 1-bit transfers.
  791. */
  792. if (is_imx31_mmc(mxcmci) && card->type == MMC_TYPE_SDIO)
  793. host->caps &= ~MMC_CAP_4_BIT_DATA;
  794. else
  795. host->caps |= MMC_CAP_4_BIT_DATA;
  796. }
  797. static bool filter(struct dma_chan *chan, void *param)
  798. {
  799. struct mxcmci_host *host = param;
  800. if (!imx_dma_is_general_purpose(chan))
  801. return false;
  802. chan->private = &host->dma_data;
  803. return true;
  804. }
  805. static void mxcmci_watchdog(unsigned long data)
  806. {
  807. struct mmc_host *mmc = (struct mmc_host *)data;
  808. struct mxcmci_host *host = mmc_priv(mmc);
  809. struct mmc_request *req = host->req;
  810. unsigned int stat = mxcmci_readl(host, MMC_REG_STATUS);
  811. if (host->dma_dir == DMA_FROM_DEVICE) {
  812. dmaengine_terminate_all(host->dma);
  813. dev_err(mmc_dev(host->mmc),
  814. "%s: read time out (status = 0x%08x)\n",
  815. __func__, stat);
  816. } else {
  817. dev_err(mmc_dev(host->mmc),
  818. "%s: write time out (status = 0x%08x)\n",
  819. __func__, stat);
  820. mxcmci_softreset(host);
  821. }
  822. /* Mark transfer as erroneus and inform the upper layers */
  823. if (host->data)
  824. host->data->error = -ETIMEDOUT;
  825. host->req = NULL;
  826. host->cmd = NULL;
  827. host->data = NULL;
  828. mmc_request_done(host->mmc, req);
  829. }
  830. static const struct mmc_host_ops mxcmci_ops = {
  831. .request = mxcmci_request,
  832. .set_ios = mxcmci_set_ios,
  833. .get_ro = mxcmci_get_ro,
  834. .enable_sdio_irq = mxcmci_enable_sdio_irq,
  835. .init_card = mxcmci_init_card,
  836. };
  837. static int mxcmci_probe(struct platform_device *pdev)
  838. {
  839. struct mmc_host *mmc;
  840. struct mxcmci_host *host = NULL;
  841. struct resource *iores, *r;
  842. int ret = 0, irq;
  843. bool dat3_card_detect = false;
  844. dma_cap_mask_t mask;
  845. const struct of_device_id *of_id;
  846. struct imxmmc_platform_data *pdata = pdev->dev.platform_data;
  847. pr_info("i.MX/MPC512x SDHC driver\n");
  848. of_id = of_match_device(mxcmci_of_match, &pdev->dev);
  849. iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  850. irq = platform_get_irq(pdev, 0);
  851. if (!iores || irq < 0)
  852. return -EINVAL;
  853. r = request_mem_region(iores->start, resource_size(iores), pdev->name);
  854. if (!r)
  855. return -EBUSY;
  856. mmc = mmc_alloc_host(sizeof(struct mxcmci_host), &pdev->dev);
  857. if (!mmc) {
  858. ret = -ENOMEM;
  859. goto out_release_mem;
  860. }
  861. mmc_of_parse(mmc);
  862. mmc->ops = &mxcmci_ops;
  863. /* For devicetree parsing, the bus width is read from devicetree */
  864. if (pdata)
  865. mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ;
  866. else
  867. mmc->caps |= MMC_CAP_SDIO_IRQ;
  868. /* MMC core transfer sizes tunable parameters */
  869. mmc->max_segs = 64;
  870. mmc->max_blk_size = 2048;
  871. mmc->max_blk_count = 65535;
  872. mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
  873. mmc->max_seg_size = mmc->max_req_size;
  874. host = mmc_priv(mmc);
  875. host->base = ioremap(r->start, resource_size(r));
  876. if (!host->base) {
  877. ret = -ENOMEM;
  878. goto out_free;
  879. }
  880. if (of_id) {
  881. const struct platform_device_id *id_entry = of_id->data;
  882. host->devtype = id_entry->driver_data;
  883. } else {
  884. host->devtype = pdev->id_entry->driver_data;
  885. }
  886. host->mmc = mmc;
  887. host->pdata = pdata;
  888. spin_lock_init(&host->lock);
  889. if (pdata)
  890. dat3_card_detect = pdata->dat3_card_detect;
  891. else if (!(mmc->caps & MMC_CAP_NONREMOVABLE)
  892. && !of_property_read_bool(pdev->dev.of_node, "cd-gpios"))
  893. dat3_card_detect = true;
  894. mxcmci_init_ocr(host);
  895. if (dat3_card_detect)
  896. host->default_irq_mask =
  897. INT_CARD_INSERTION_EN | INT_CARD_REMOVAL_EN;
  898. else
  899. host->default_irq_mask = 0;
  900. host->res = r;
  901. host->irq = irq;
  902. host->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
  903. if (IS_ERR(host->clk_ipg)) {
  904. ret = PTR_ERR(host->clk_ipg);
  905. goto out_iounmap;
  906. }
  907. host->clk_per = devm_clk_get(&pdev->dev, "per");
  908. if (IS_ERR(host->clk_per)) {
  909. ret = PTR_ERR(host->clk_per);
  910. goto out_iounmap;
  911. }
  912. clk_prepare_enable(host->clk_per);
  913. clk_prepare_enable(host->clk_ipg);
  914. mxcmci_softreset(host);
  915. host->rev_no = mxcmci_readw(host, MMC_REG_REV_NO);
  916. if (host->rev_no != 0x400) {
  917. ret = -ENODEV;
  918. dev_err(mmc_dev(host->mmc), "wrong rev.no. 0x%08x. aborting.\n",
  919. host->rev_no);
  920. goto out_clk_put;
  921. }
  922. mmc->f_min = clk_get_rate(host->clk_per) >> 16;
  923. mmc->f_max = clk_get_rate(host->clk_per) >> 1;
  924. /* recommended in data sheet */
  925. mxcmci_writew(host, 0x2db4, MMC_REG_READ_TO);
  926. mxcmci_writel(host, host->default_irq_mask, MMC_REG_INT_CNTR);
  927. if (!host->pdata) {
  928. host->dma = dma_request_slave_channel(&pdev->dev, "rx-tx");
  929. } else {
  930. r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  931. if (r) {
  932. host->dmareq = r->start;
  933. host->dma_data.peripheral_type = IMX_DMATYPE_SDHC;
  934. host->dma_data.priority = DMA_PRIO_LOW;
  935. host->dma_data.dma_request = host->dmareq;
  936. dma_cap_zero(mask);
  937. dma_cap_set(DMA_SLAVE, mask);
  938. host->dma = dma_request_channel(mask, filter, host);
  939. }
  940. }
  941. if (host->dma)
  942. mmc->max_seg_size = dma_get_max_seg_size(
  943. host->dma->device->dev);
  944. else
  945. dev_info(mmc_dev(host->mmc), "dma not available. Using PIO\n");
  946. INIT_WORK(&host->datawork, mxcmci_datawork);
  947. ret = request_irq(host->irq, mxcmci_irq, 0, DRIVER_NAME, host);
  948. if (ret)
  949. goto out_free_dma;
  950. platform_set_drvdata(pdev, mmc);
  951. if (host->pdata && host->pdata->init) {
  952. ret = host->pdata->init(&pdev->dev, mxcmci_detect_irq,
  953. host->mmc);
  954. if (ret)
  955. goto out_free_irq;
  956. }
  957. init_timer(&host->watchdog);
  958. host->watchdog.function = &mxcmci_watchdog;
  959. host->watchdog.data = (unsigned long)mmc;
  960. mmc_add_host(mmc);
  961. return 0;
  962. out_free_irq:
  963. free_irq(host->irq, host);
  964. out_free_dma:
  965. if (host->dma)
  966. dma_release_channel(host->dma);
  967. out_clk_put:
  968. clk_disable_unprepare(host->clk_per);
  969. clk_disable_unprepare(host->clk_ipg);
  970. out_iounmap:
  971. iounmap(host->base);
  972. out_free:
  973. mmc_free_host(mmc);
  974. out_release_mem:
  975. release_mem_region(iores->start, resource_size(iores));
  976. return ret;
  977. }
  978. static int mxcmci_remove(struct platform_device *pdev)
  979. {
  980. struct mmc_host *mmc = platform_get_drvdata(pdev);
  981. struct mxcmci_host *host = mmc_priv(mmc);
  982. platform_set_drvdata(pdev, NULL);
  983. mmc_remove_host(mmc);
  984. if (host->vcc)
  985. regulator_put(host->vcc);
  986. if (host->pdata && host->pdata->exit)
  987. host->pdata->exit(&pdev->dev, mmc);
  988. free_irq(host->irq, host);
  989. iounmap(host->base);
  990. if (host->dma)
  991. dma_release_channel(host->dma);
  992. clk_disable_unprepare(host->clk_per);
  993. clk_disable_unprepare(host->clk_ipg);
  994. release_mem_region(host->res->start, resource_size(host->res));
  995. mmc_free_host(mmc);
  996. return 0;
  997. }
  998. #ifdef CONFIG_PM
  999. static int mxcmci_suspend(struct device *dev)
  1000. {
  1001. struct mmc_host *mmc = dev_get_drvdata(dev);
  1002. struct mxcmci_host *host = mmc_priv(mmc);
  1003. int ret = 0;
  1004. if (mmc)
  1005. ret = mmc_suspend_host(mmc);
  1006. clk_disable_unprepare(host->clk_per);
  1007. clk_disable_unprepare(host->clk_ipg);
  1008. return ret;
  1009. }
  1010. static int mxcmci_resume(struct device *dev)
  1011. {
  1012. struct mmc_host *mmc = dev_get_drvdata(dev);
  1013. struct mxcmci_host *host = mmc_priv(mmc);
  1014. int ret = 0;
  1015. clk_prepare_enable(host->clk_per);
  1016. clk_prepare_enable(host->clk_ipg);
  1017. if (mmc)
  1018. ret = mmc_resume_host(mmc);
  1019. return ret;
  1020. }
  1021. static const struct dev_pm_ops mxcmci_pm_ops = {
  1022. .suspend = mxcmci_suspend,
  1023. .resume = mxcmci_resume,
  1024. };
  1025. #endif
  1026. static struct platform_driver mxcmci_driver = {
  1027. .probe = mxcmci_probe,
  1028. .remove = mxcmci_remove,
  1029. .id_table = mxcmci_devtype,
  1030. .driver = {
  1031. .name = DRIVER_NAME,
  1032. .owner = THIS_MODULE,
  1033. #ifdef CONFIG_PM
  1034. .pm = &mxcmci_pm_ops,
  1035. #endif
  1036. .of_match_table = mxcmci_of_match,
  1037. }
  1038. };
  1039. module_platform_driver(mxcmci_driver);
  1040. MODULE_DESCRIPTION("i.MX Multimedia Card Interface Driver");
  1041. MODULE_AUTHOR("Sascha Hauer, Pengutronix");
  1042. MODULE_LICENSE("GPL");
  1043. MODULE_ALIAS("platform:mxc-mmc");