mxcmmc.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  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/highmem.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/irq.h>
  26. #include <linux/blkdev.h>
  27. #include <linux/dma-mapping.h>
  28. #include <linux/mmc/host.h>
  29. #include <linux/mmc/card.h>
  30. #include <linux/delay.h>
  31. #include <linux/clk.h>
  32. #include <linux/io.h>
  33. #include <linux/gpio.h>
  34. #include <linux/regulator/consumer.h>
  35. #include <linux/dmaengine.h>
  36. #include <linux/types.h>
  37. #include <linux/of.h>
  38. #include <linux/of_device.h>
  39. #include <linux/of_dma.h>
  40. #include <linux/of_gpio.h>
  41. #include <linux/mmc/slot-gpio.h>
  42. #include <asm/dma.h>
  43. #include <asm/irq.h>
  44. #include <linux/platform_data/mmc-mxcmmc.h>
  45. #include <linux/platform_data/dma-imx.h>
  46. #define DRIVER_NAME "mxc-mmc"
  47. #define MXCMCI_TIMEOUT_MS 10000
  48. #define MMC_REG_STR_STP_CLK 0x00
  49. #define MMC_REG_STATUS 0x04
  50. #define MMC_REG_CLK_RATE 0x08
  51. #define MMC_REG_CMD_DAT_CONT 0x0C
  52. #define MMC_REG_RES_TO 0x10
  53. #define MMC_REG_READ_TO 0x14
  54. #define MMC_REG_BLK_LEN 0x18
  55. #define MMC_REG_NOB 0x1C
  56. #define MMC_REG_REV_NO 0x20
  57. #define MMC_REG_INT_CNTR 0x24
  58. #define MMC_REG_CMD 0x28
  59. #define MMC_REG_ARG 0x2C
  60. #define MMC_REG_RES_FIFO 0x34
  61. #define MMC_REG_BUFFER_ACCESS 0x38
  62. #define STR_STP_CLK_RESET (1 << 3)
  63. #define STR_STP_CLK_START_CLK (1 << 1)
  64. #define STR_STP_CLK_STOP_CLK (1 << 0)
  65. #define STATUS_CARD_INSERTION (1 << 31)
  66. #define STATUS_CARD_REMOVAL (1 << 30)
  67. #define STATUS_YBUF_EMPTY (1 << 29)
  68. #define STATUS_XBUF_EMPTY (1 << 28)
  69. #define STATUS_YBUF_FULL (1 << 27)
  70. #define STATUS_XBUF_FULL (1 << 26)
  71. #define STATUS_BUF_UND_RUN (1 << 25)
  72. #define STATUS_BUF_OVFL (1 << 24)
  73. #define STATUS_SDIO_INT_ACTIVE (1 << 14)
  74. #define STATUS_END_CMD_RESP (1 << 13)
  75. #define STATUS_WRITE_OP_DONE (1 << 12)
  76. #define STATUS_DATA_TRANS_DONE (1 << 11)
  77. #define STATUS_READ_OP_DONE (1 << 11)
  78. #define STATUS_WR_CRC_ERROR_CODE_MASK (3 << 10)
  79. #define STATUS_CARD_BUS_CLK_RUN (1 << 8)
  80. #define STATUS_BUF_READ_RDY (1 << 7)
  81. #define STATUS_BUF_WRITE_RDY (1 << 6)
  82. #define STATUS_RESP_CRC_ERR (1 << 5)
  83. #define STATUS_CRC_READ_ERR (1 << 3)
  84. #define STATUS_CRC_WRITE_ERR (1 << 2)
  85. #define STATUS_TIME_OUT_RESP (1 << 1)
  86. #define STATUS_TIME_OUT_READ (1 << 0)
  87. #define STATUS_ERR_MASK 0x2f
  88. #define CMD_DAT_CONT_CMD_RESP_LONG_OFF (1 << 12)
  89. #define CMD_DAT_CONT_STOP_READWAIT (1 << 11)
  90. #define CMD_DAT_CONT_START_READWAIT (1 << 10)
  91. #define CMD_DAT_CONT_BUS_WIDTH_4 (2 << 8)
  92. #define CMD_DAT_CONT_INIT (1 << 7)
  93. #define CMD_DAT_CONT_WRITE (1 << 4)
  94. #define CMD_DAT_CONT_DATA_ENABLE (1 << 3)
  95. #define CMD_DAT_CONT_RESPONSE_48BIT_CRC (1 << 0)
  96. #define CMD_DAT_CONT_RESPONSE_136BIT (2 << 0)
  97. #define CMD_DAT_CONT_RESPONSE_48BIT (3 << 0)
  98. #define INT_SDIO_INT_WKP_EN (1 << 18)
  99. #define INT_CARD_INSERTION_WKP_EN (1 << 17)
  100. #define INT_CARD_REMOVAL_WKP_EN (1 << 16)
  101. #define INT_CARD_INSERTION_EN (1 << 15)
  102. #define INT_CARD_REMOVAL_EN (1 << 14)
  103. #define INT_SDIO_IRQ_EN (1 << 13)
  104. #define INT_DAT0_EN (1 << 12)
  105. #define INT_BUF_READ_EN (1 << 4)
  106. #define INT_BUF_WRITE_EN (1 << 3)
  107. #define INT_END_CMD_RES_EN (1 << 2)
  108. #define INT_WRITE_OP_DONE_EN (1 << 1)
  109. #define INT_READ_OP_EN (1 << 0)
  110. enum mxcmci_type {
  111. IMX21_MMC,
  112. IMX31_MMC,
  113. MPC512X_MMC,
  114. };
  115. struct mxcmci_host {
  116. struct mmc_host *mmc;
  117. void __iomem *base;
  118. dma_addr_t phys_base;
  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. int burstlen;
  140. int dmareq;
  141. struct dma_slave_config dma_slave_config;
  142. struct imx_dma_data dma_data;
  143. struct timer_list watchdog;
  144. enum mxcmci_type devtype;
  145. };
  146. static const struct platform_device_id mxcmci_devtype[] = {
  147. {
  148. .name = "imx21-mmc",
  149. .driver_data = IMX21_MMC,
  150. }, {
  151. .name = "imx31-mmc",
  152. .driver_data = IMX31_MMC,
  153. }, {
  154. .name = "mpc512x-sdhc",
  155. .driver_data = MPC512X_MMC,
  156. }, {
  157. /* sentinel */
  158. }
  159. };
  160. MODULE_DEVICE_TABLE(platform, mxcmci_devtype);
  161. static const struct of_device_id mxcmci_of_match[] = {
  162. {
  163. .compatible = "fsl,imx21-mmc",
  164. .data = &mxcmci_devtype[IMX21_MMC],
  165. }, {
  166. .compatible = "fsl,imx31-mmc",
  167. .data = &mxcmci_devtype[IMX31_MMC],
  168. }, {
  169. .compatible = "fsl,mpc5121-sdhc",
  170. .data = &mxcmci_devtype[MPC512X_MMC],
  171. }, {
  172. /* sentinel */
  173. }
  174. };
  175. MODULE_DEVICE_TABLE(of, mxcmci_of_match);
  176. static inline int is_imx31_mmc(struct mxcmci_host *host)
  177. {
  178. return host->devtype == IMX31_MMC;
  179. }
  180. static inline int is_mpc512x_mmc(struct mxcmci_host *host)
  181. {
  182. return host->devtype == MPC512X_MMC;
  183. }
  184. static inline u32 mxcmci_readl(struct mxcmci_host *host, int reg)
  185. {
  186. if (IS_ENABLED(CONFIG_PPC_MPC512x))
  187. return ioread32be(host->base + reg);
  188. else
  189. return readl(host->base + reg);
  190. }
  191. static inline void mxcmci_writel(struct mxcmci_host *host, u32 val, int reg)
  192. {
  193. if (IS_ENABLED(CONFIG_PPC_MPC512x))
  194. iowrite32be(val, host->base + reg);
  195. else
  196. writel(val, host->base + reg);
  197. }
  198. static inline u16 mxcmci_readw(struct mxcmci_host *host, int reg)
  199. {
  200. if (IS_ENABLED(CONFIG_PPC_MPC512x))
  201. return ioread32be(host->base + reg);
  202. else
  203. return readw(host->base + reg);
  204. }
  205. static inline void mxcmci_writew(struct mxcmci_host *host, u16 val, int reg)
  206. {
  207. if (IS_ENABLED(CONFIG_PPC_MPC512x))
  208. iowrite32be(val, host->base + reg);
  209. else
  210. writew(val, host->base + reg);
  211. }
  212. static void mxcmci_set_clk_rate(struct mxcmci_host *host, unsigned int clk_ios);
  213. static void mxcmci_set_power(struct mxcmci_host *host, unsigned int vdd)
  214. {
  215. if (!IS_ERR(host->mmc->supply.vmmc)) {
  216. if (host->power_mode == MMC_POWER_UP)
  217. mmc_regulator_set_ocr(host->mmc,
  218. host->mmc->supply.vmmc, vdd);
  219. else if (host->power_mode == MMC_POWER_OFF)
  220. mmc_regulator_set_ocr(host->mmc,
  221. host->mmc->supply.vmmc, 0);
  222. }
  223. if (host->pdata && host->pdata->setpower)
  224. host->pdata->setpower(mmc_dev(host->mmc), vdd);
  225. }
  226. static inline int mxcmci_use_dma(struct mxcmci_host *host)
  227. {
  228. return host->do_dma;
  229. }
  230. static void mxcmci_softreset(struct mxcmci_host *host)
  231. {
  232. int i;
  233. dev_dbg(mmc_dev(host->mmc), "mxcmci_softreset\n");
  234. /* reset sequence */
  235. mxcmci_writew(host, STR_STP_CLK_RESET, MMC_REG_STR_STP_CLK);
  236. mxcmci_writew(host, STR_STP_CLK_RESET | STR_STP_CLK_START_CLK,
  237. MMC_REG_STR_STP_CLK);
  238. for (i = 0; i < 8; i++)
  239. mxcmci_writew(host, STR_STP_CLK_START_CLK, MMC_REG_STR_STP_CLK);
  240. mxcmci_writew(host, 0xff, MMC_REG_RES_TO);
  241. }
  242. #if IS_ENABLED(CONFIG_PPC_MPC512x)
  243. static inline void buffer_swap32(u32 *buf, int len)
  244. {
  245. int i;
  246. for (i = 0; i < ((len + 3) / 4); i++) {
  247. *buf = swab32(*buf);
  248. buf++;
  249. }
  250. }
  251. static void mxcmci_swap_buffers(struct mmc_data *data)
  252. {
  253. struct scatterlist *sg;
  254. int i;
  255. for_each_sg(data->sg, sg, data->sg_len, i) {
  256. void *buf = kmap_atomic(sg_page(sg) + sg->offset);
  257. buffer_swap32(buf, sg->length);
  258. kunmap_atomic(buf);
  259. }
  260. }
  261. #else
  262. static inline void mxcmci_swap_buffers(struct mmc_data *data) {}
  263. #endif
  264. static int mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data)
  265. {
  266. unsigned int nob = data->blocks;
  267. unsigned int blksz = data->blksz;
  268. unsigned int datasize = nob * blksz;
  269. struct scatterlist *sg;
  270. enum dma_transfer_direction slave_dirn;
  271. int i, nents;
  272. host->data = data;
  273. data->bytes_xfered = 0;
  274. mxcmci_writew(host, nob, MMC_REG_NOB);
  275. mxcmci_writew(host, blksz, MMC_REG_BLK_LEN);
  276. host->datasize = datasize;
  277. if (!mxcmci_use_dma(host))
  278. return 0;
  279. for_each_sg(data->sg, sg, data->sg_len, i) {
  280. if (sg->offset & 3 || sg->length & 3 || sg->length < 512) {
  281. host->do_dma = 0;
  282. return 0;
  283. }
  284. }
  285. if (data->flags & MMC_DATA_READ) {
  286. host->dma_dir = DMA_FROM_DEVICE;
  287. slave_dirn = DMA_DEV_TO_MEM;
  288. } else {
  289. host->dma_dir = DMA_TO_DEVICE;
  290. slave_dirn = DMA_MEM_TO_DEV;
  291. mxcmci_swap_buffers(data);
  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. dev_dbg(mmc_dev(host->mmc), "%s: 0x%08x\n", __func__, stat);
  321. mxcmci_data_done(host, stat);
  322. }
  323. static int mxcmci_start_cmd(struct mxcmci_host *host, struct mmc_command *cmd,
  324. unsigned int cmdat)
  325. {
  326. u32 int_cntr = host->default_irq_mask;
  327. unsigned long flags;
  328. WARN_ON(host->cmd != NULL);
  329. host->cmd = cmd;
  330. switch (mmc_resp_type(cmd)) {
  331. case MMC_RSP_R1: /* short CRC, OPCODE */
  332. case MMC_RSP_R1B:/* short CRC, OPCODE, BUSY */
  333. cmdat |= CMD_DAT_CONT_RESPONSE_48BIT_CRC;
  334. break;
  335. case MMC_RSP_R2: /* long 136 bit + CRC */
  336. cmdat |= CMD_DAT_CONT_RESPONSE_136BIT;
  337. break;
  338. case MMC_RSP_R3: /* short */
  339. cmdat |= CMD_DAT_CONT_RESPONSE_48BIT;
  340. break;
  341. case MMC_RSP_NONE:
  342. break;
  343. default:
  344. dev_err(mmc_dev(host->mmc), "unhandled response type 0x%x\n",
  345. mmc_resp_type(cmd));
  346. cmd->error = -EINVAL;
  347. return -EINVAL;
  348. }
  349. int_cntr = INT_END_CMD_RES_EN;
  350. if (mxcmci_use_dma(host)) {
  351. if (host->dma_dir == DMA_FROM_DEVICE) {
  352. host->desc->callback = mxcmci_dma_callback;
  353. host->desc->callback_param = host;
  354. } else {
  355. int_cntr |= INT_WRITE_OP_DONE_EN;
  356. }
  357. }
  358. spin_lock_irqsave(&host->lock, flags);
  359. if (host->use_sdio)
  360. int_cntr |= INT_SDIO_IRQ_EN;
  361. mxcmci_writel(host, int_cntr, MMC_REG_INT_CNTR);
  362. spin_unlock_irqrestore(&host->lock, flags);
  363. mxcmci_writew(host, cmd->opcode, MMC_REG_CMD);
  364. mxcmci_writel(host, cmd->arg, MMC_REG_ARG);
  365. mxcmci_writew(host, cmdat, MMC_REG_CMD_DAT_CONT);
  366. return 0;
  367. }
  368. static void mxcmci_finish_request(struct mxcmci_host *host,
  369. struct mmc_request *req)
  370. {
  371. u32 int_cntr = host->default_irq_mask;
  372. unsigned long flags;
  373. spin_lock_irqsave(&host->lock, flags);
  374. if (host->use_sdio)
  375. int_cntr |= INT_SDIO_IRQ_EN;
  376. mxcmci_writel(host, int_cntr, MMC_REG_INT_CNTR);
  377. spin_unlock_irqrestore(&host->lock, flags);
  378. host->req = NULL;
  379. host->cmd = NULL;
  380. host->data = NULL;
  381. mmc_request_done(host->mmc, req);
  382. }
  383. static int mxcmci_finish_data(struct mxcmci_host *host, unsigned int stat)
  384. {
  385. struct mmc_data *data = host->data;
  386. int data_error;
  387. if (mxcmci_use_dma(host)) {
  388. dma_unmap_sg(host->dma->device->dev, data->sg, data->sg_len,
  389. host->dma_dir);
  390. mxcmci_swap_buffers(data);
  391. }
  392. if (stat & STATUS_ERR_MASK) {
  393. dev_dbg(mmc_dev(host->mmc), "request failed. status: 0x%08x\n",
  394. stat);
  395. if (stat & STATUS_CRC_READ_ERR) {
  396. dev_err(mmc_dev(host->mmc), "%s: -EILSEQ\n", __func__);
  397. data->error = -EILSEQ;
  398. } else if (stat & STATUS_CRC_WRITE_ERR) {
  399. u32 err_code = (stat >> 9) & 0x3;
  400. if (err_code == 2) { /* No CRC response */
  401. dev_err(mmc_dev(host->mmc),
  402. "%s: No CRC -ETIMEDOUT\n", __func__);
  403. data->error = -ETIMEDOUT;
  404. } else {
  405. dev_err(mmc_dev(host->mmc),
  406. "%s: -EILSEQ\n", __func__);
  407. data->error = -EILSEQ;
  408. }
  409. } else if (stat & STATUS_TIME_OUT_READ) {
  410. dev_err(mmc_dev(host->mmc),
  411. "%s: read -ETIMEDOUT\n", __func__);
  412. data->error = -ETIMEDOUT;
  413. } else {
  414. dev_err(mmc_dev(host->mmc), "%s: -EIO\n", __func__);
  415. data->error = -EIO;
  416. }
  417. } else {
  418. data->bytes_xfered = host->datasize;
  419. }
  420. data_error = data->error;
  421. host->data = NULL;
  422. return data_error;
  423. }
  424. static void mxcmci_read_response(struct mxcmci_host *host, unsigned int stat)
  425. {
  426. struct mmc_command *cmd = host->cmd;
  427. int i;
  428. u32 a, b, c;
  429. if (!cmd)
  430. return;
  431. if (stat & STATUS_TIME_OUT_RESP) {
  432. dev_dbg(mmc_dev(host->mmc), "CMD TIMEOUT\n");
  433. cmd->error = -ETIMEDOUT;
  434. } else if (stat & STATUS_RESP_CRC_ERR && cmd->flags & MMC_RSP_CRC) {
  435. dev_dbg(mmc_dev(host->mmc), "cmd crc error\n");
  436. cmd->error = -EILSEQ;
  437. }
  438. if (cmd->flags & MMC_RSP_PRESENT) {
  439. if (cmd->flags & MMC_RSP_136) {
  440. for (i = 0; i < 4; i++) {
  441. a = mxcmci_readw(host, MMC_REG_RES_FIFO);
  442. b = mxcmci_readw(host, MMC_REG_RES_FIFO);
  443. cmd->resp[i] = a << 16 | b;
  444. }
  445. } else {
  446. a = mxcmci_readw(host, MMC_REG_RES_FIFO);
  447. b = mxcmci_readw(host, MMC_REG_RES_FIFO);
  448. c = mxcmci_readw(host, MMC_REG_RES_FIFO);
  449. cmd->resp[0] = a << 24 | b << 8 | c >> 8;
  450. }
  451. }
  452. }
  453. static int mxcmci_poll_status(struct mxcmci_host *host, u32 mask)
  454. {
  455. u32 stat;
  456. unsigned long timeout = jiffies + HZ;
  457. do {
  458. stat = mxcmci_readl(host, MMC_REG_STATUS);
  459. if (stat & STATUS_ERR_MASK)
  460. return stat;
  461. if (time_after(jiffies, timeout)) {
  462. mxcmci_softreset(host);
  463. mxcmci_set_clk_rate(host, host->clock);
  464. return STATUS_TIME_OUT_READ;
  465. }
  466. if (stat & mask)
  467. return 0;
  468. cpu_relax();
  469. } while (1);
  470. }
  471. static int mxcmci_pull(struct mxcmci_host *host, void *_buf, int bytes)
  472. {
  473. unsigned int stat;
  474. u32 *buf = _buf;
  475. while (bytes > 3) {
  476. stat = mxcmci_poll_status(host,
  477. STATUS_BUF_READ_RDY | STATUS_READ_OP_DONE);
  478. if (stat)
  479. return stat;
  480. *buf++ = cpu_to_le32(mxcmci_readl(host, MMC_REG_BUFFER_ACCESS));
  481. bytes -= 4;
  482. }
  483. if (bytes) {
  484. u8 *b = (u8 *)buf;
  485. u32 tmp;
  486. stat = mxcmci_poll_status(host,
  487. STATUS_BUF_READ_RDY | STATUS_READ_OP_DONE);
  488. if (stat)
  489. return stat;
  490. tmp = cpu_to_le32(mxcmci_readl(host, MMC_REG_BUFFER_ACCESS));
  491. memcpy(b, &tmp, bytes);
  492. }
  493. return 0;
  494. }
  495. static int mxcmci_push(struct mxcmci_host *host, void *_buf, int bytes)
  496. {
  497. unsigned int stat;
  498. u32 *buf = _buf;
  499. while (bytes > 3) {
  500. stat = mxcmci_poll_status(host, STATUS_BUF_WRITE_RDY);
  501. if (stat)
  502. return stat;
  503. mxcmci_writel(host, cpu_to_le32(*buf++), MMC_REG_BUFFER_ACCESS);
  504. bytes -= 4;
  505. }
  506. if (bytes) {
  507. u8 *b = (u8 *)buf;
  508. u32 tmp;
  509. stat = mxcmci_poll_status(host, STATUS_BUF_WRITE_RDY);
  510. if (stat)
  511. return stat;
  512. memcpy(&tmp, b, bytes);
  513. mxcmci_writel(host, cpu_to_le32(tmp), MMC_REG_BUFFER_ACCESS);
  514. }
  515. return mxcmci_poll_status(host, STATUS_BUF_WRITE_RDY);
  516. }
  517. static int mxcmci_transfer_data(struct mxcmci_host *host)
  518. {
  519. struct mmc_data *data = host->req->data;
  520. struct scatterlist *sg;
  521. void *buf;
  522. int stat, i;
  523. host->data = data;
  524. host->datasize = 0;
  525. if (data->flags & MMC_DATA_READ) {
  526. for_each_sg(data->sg, sg, data->sg_len, i) {
  527. buf = kmap_atomic(sg_page(sg) + sg->offset);
  528. stat = mxcmci_pull(host, buf, sg->length);
  529. kunmap(buf);
  530. if (stat)
  531. return stat;
  532. host->datasize += sg->length;
  533. }
  534. } else {
  535. for_each_sg(data->sg, sg, data->sg_len, i) {
  536. buf = kmap_atomic(sg_page(sg) + sg->offset);
  537. stat = mxcmci_push(host, buf, sg->length);
  538. kunmap(buf);
  539. if (stat)
  540. return stat;
  541. host->datasize += sg->length;
  542. }
  543. stat = mxcmci_poll_status(host, STATUS_WRITE_OP_DONE);
  544. if (stat)
  545. return stat;
  546. }
  547. return 0;
  548. }
  549. static void mxcmci_datawork(struct work_struct *work)
  550. {
  551. struct mxcmci_host *host = container_of(work, struct mxcmci_host,
  552. datawork);
  553. int datastat = mxcmci_transfer_data(host);
  554. mxcmci_writel(host, STATUS_READ_OP_DONE | STATUS_WRITE_OP_DONE,
  555. MMC_REG_STATUS);
  556. mxcmci_finish_data(host, datastat);
  557. if (host->req->stop) {
  558. if (mxcmci_start_cmd(host, host->req->stop, 0)) {
  559. mxcmci_finish_request(host, host->req);
  560. return;
  561. }
  562. } else {
  563. mxcmci_finish_request(host, host->req);
  564. }
  565. }
  566. static void mxcmci_data_done(struct mxcmci_host *host, unsigned int stat)
  567. {
  568. struct mmc_request *req;
  569. int data_error;
  570. unsigned long flags;
  571. spin_lock_irqsave(&host->lock, flags);
  572. if (!host->data) {
  573. spin_unlock_irqrestore(&host->lock, flags);
  574. return;
  575. }
  576. if (!host->req) {
  577. spin_unlock_irqrestore(&host->lock, flags);
  578. return;
  579. }
  580. req = host->req;
  581. if (!req->stop)
  582. host->req = NULL; /* we will handle finish req below */
  583. data_error = mxcmci_finish_data(host, stat);
  584. spin_unlock_irqrestore(&host->lock, flags);
  585. if (data_error)
  586. return;
  587. mxcmci_read_response(host, stat);
  588. host->cmd = NULL;
  589. if (req->stop) {
  590. if (mxcmci_start_cmd(host, req->stop, 0)) {
  591. mxcmci_finish_request(host, req);
  592. return;
  593. }
  594. } else {
  595. mxcmci_finish_request(host, req);
  596. }
  597. }
  598. static void mxcmci_cmd_done(struct mxcmci_host *host, unsigned int stat)
  599. {
  600. mxcmci_read_response(host, stat);
  601. host->cmd = NULL;
  602. if (!host->data && host->req) {
  603. mxcmci_finish_request(host, host->req);
  604. return;
  605. }
  606. /* For the DMA case the DMA engine handles the data transfer
  607. * automatically. For non DMA we have to do it ourselves.
  608. * Don't do it in interrupt context though.
  609. */
  610. if (!mxcmci_use_dma(host) && host->data)
  611. schedule_work(&host->datawork);
  612. }
  613. static irqreturn_t mxcmci_irq(int irq, void *devid)
  614. {
  615. struct mxcmci_host *host = devid;
  616. unsigned long flags;
  617. bool sdio_irq;
  618. u32 stat;
  619. stat = mxcmci_readl(host, MMC_REG_STATUS);
  620. mxcmci_writel(host,
  621. stat & ~(STATUS_SDIO_INT_ACTIVE | STATUS_DATA_TRANS_DONE |
  622. STATUS_WRITE_OP_DONE),
  623. MMC_REG_STATUS);
  624. dev_dbg(mmc_dev(host->mmc), "%s: 0x%08x\n", __func__, stat);
  625. spin_lock_irqsave(&host->lock, flags);
  626. sdio_irq = (stat & STATUS_SDIO_INT_ACTIVE) && host->use_sdio;
  627. spin_unlock_irqrestore(&host->lock, flags);
  628. if (mxcmci_use_dma(host) && (stat & (STATUS_WRITE_OP_DONE)))
  629. mxcmci_writel(host, STATUS_WRITE_OP_DONE, MMC_REG_STATUS);
  630. if (sdio_irq) {
  631. mxcmci_writel(host, STATUS_SDIO_INT_ACTIVE, MMC_REG_STATUS);
  632. mmc_signal_sdio_irq(host->mmc);
  633. }
  634. if (stat & STATUS_END_CMD_RESP)
  635. mxcmci_cmd_done(host, stat);
  636. if (mxcmci_use_dma(host) && (stat & 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->phys_base + MMC_REG_BUFFER_ACCESS;
  700. config->src_addr = host->phys_base + 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. host->power_mode = ios->power_mode;
  737. mxcmci_set_power(host, ios->vdd);
  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(struct timer_list *t)
  806. {
  807. struct mxcmci_host *host = from_timer(host, t, watchdog);
  808. struct mmc_request *req = host->req;
  809. unsigned int stat = mxcmci_readl(host, MMC_REG_STATUS);
  810. if (host->dma_dir == DMA_FROM_DEVICE) {
  811. dmaengine_terminate_all(host->dma);
  812. dev_err(mmc_dev(host->mmc),
  813. "%s: read time out (status = 0x%08x)\n",
  814. __func__, stat);
  815. } else {
  816. dev_err(mmc_dev(host->mmc),
  817. "%s: write time out (status = 0x%08x)\n",
  818. __func__, stat);
  819. mxcmci_softreset(host);
  820. }
  821. /* Mark transfer as erroneus and inform the upper layers */
  822. if (host->data)
  823. host->data->error = -ETIMEDOUT;
  824. host->req = NULL;
  825. host->cmd = NULL;
  826. host->data = NULL;
  827. mmc_request_done(host->mmc, req);
  828. }
  829. static const struct mmc_host_ops mxcmci_ops = {
  830. .request = mxcmci_request,
  831. .set_ios = mxcmci_set_ios,
  832. .get_ro = mxcmci_get_ro,
  833. .enable_sdio_irq = mxcmci_enable_sdio_irq,
  834. .init_card = mxcmci_init_card,
  835. };
  836. static int mxcmci_probe(struct platform_device *pdev)
  837. {
  838. struct mmc_host *mmc;
  839. struct mxcmci_host *host;
  840. struct resource *res;
  841. int ret = 0, irq;
  842. bool dat3_card_detect = false;
  843. dma_cap_mask_t mask;
  844. const struct of_device_id *of_id;
  845. struct imxmmc_platform_data *pdata = pdev->dev.platform_data;
  846. pr_info("i.MX/MPC512x SDHC driver\n");
  847. of_id = of_match_device(mxcmci_of_match, &pdev->dev);
  848. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  849. irq = platform_get_irq(pdev, 0);
  850. if (irq < 0) {
  851. dev_err(&pdev->dev, "failed to get IRQ: %d\n", irq);
  852. return irq;
  853. }
  854. mmc = mmc_alloc_host(sizeof(*host), &pdev->dev);
  855. if (!mmc)
  856. return -ENOMEM;
  857. host = mmc_priv(mmc);
  858. host->base = devm_ioremap_resource(&pdev->dev, res);
  859. if (IS_ERR(host->base)) {
  860. ret = PTR_ERR(host->base);
  861. goto out_free;
  862. }
  863. host->phys_base = res->start;
  864. ret = mmc_of_parse(mmc);
  865. if (ret)
  866. goto out_free;
  867. mmc->ops = &mxcmci_ops;
  868. /* For devicetree parsing, the bus width is read from devicetree */
  869. if (pdata)
  870. mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ;
  871. else
  872. mmc->caps |= MMC_CAP_SDIO_IRQ;
  873. /* MMC core transfer sizes tunable parameters */
  874. mmc->max_blk_size = 2048;
  875. mmc->max_blk_count = 65535;
  876. mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
  877. mmc->max_seg_size = mmc->max_req_size;
  878. if (of_id) {
  879. const struct platform_device_id *id_entry = of_id->data;
  880. host->devtype = id_entry->driver_data;
  881. } else {
  882. host->devtype = pdev->id_entry->driver_data;
  883. }
  884. /* adjust max_segs after devtype detection */
  885. if (!is_mpc512x_mmc(host))
  886. mmc->max_segs = 64;
  887. host->mmc = mmc;
  888. host->pdata = pdata;
  889. spin_lock_init(&host->lock);
  890. if (pdata)
  891. dat3_card_detect = pdata->dat3_card_detect;
  892. else if (mmc_card_is_removable(mmc)
  893. && !of_property_read_bool(pdev->dev.of_node, "cd-gpios"))
  894. dat3_card_detect = true;
  895. ret = mmc_regulator_get_supply(mmc);
  896. if (ret)
  897. goto out_free;
  898. if (!mmc->ocr_avail) {
  899. if (pdata && pdata->ocr_avail)
  900. mmc->ocr_avail = pdata->ocr_avail;
  901. else
  902. mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
  903. }
  904. if (dat3_card_detect)
  905. host->default_irq_mask =
  906. INT_CARD_INSERTION_EN | INT_CARD_REMOVAL_EN;
  907. else
  908. host->default_irq_mask = 0;
  909. host->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
  910. if (IS_ERR(host->clk_ipg)) {
  911. ret = PTR_ERR(host->clk_ipg);
  912. goto out_free;
  913. }
  914. host->clk_per = devm_clk_get(&pdev->dev, "per");
  915. if (IS_ERR(host->clk_per)) {
  916. ret = PTR_ERR(host->clk_per);
  917. goto out_free;
  918. }
  919. ret = clk_prepare_enable(host->clk_per);
  920. if (ret)
  921. goto out_free;
  922. ret = clk_prepare_enable(host->clk_ipg);
  923. if (ret)
  924. goto out_clk_per_put;
  925. mxcmci_softreset(host);
  926. host->rev_no = mxcmci_readw(host, MMC_REG_REV_NO);
  927. if (host->rev_no != 0x400) {
  928. ret = -ENODEV;
  929. dev_err(mmc_dev(host->mmc), "wrong rev.no. 0x%08x. aborting.\n",
  930. host->rev_no);
  931. goto out_clk_put;
  932. }
  933. mmc->f_min = clk_get_rate(host->clk_per) >> 16;
  934. mmc->f_max = clk_get_rate(host->clk_per) >> 1;
  935. /* recommended in data sheet */
  936. mxcmci_writew(host, 0x2db4, MMC_REG_READ_TO);
  937. mxcmci_writel(host, host->default_irq_mask, MMC_REG_INT_CNTR);
  938. if (!host->pdata) {
  939. host->dma = dma_request_slave_channel(&pdev->dev, "rx-tx");
  940. } else {
  941. res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  942. if (res) {
  943. host->dmareq = res->start;
  944. host->dma_data.peripheral_type = IMX_DMATYPE_SDHC;
  945. host->dma_data.priority = DMA_PRIO_LOW;
  946. host->dma_data.dma_request = host->dmareq;
  947. dma_cap_zero(mask);
  948. dma_cap_set(DMA_SLAVE, mask);
  949. host->dma = dma_request_channel(mask, filter, host);
  950. }
  951. }
  952. if (host->dma)
  953. mmc->max_seg_size = dma_get_max_seg_size(
  954. host->dma->device->dev);
  955. else
  956. dev_info(mmc_dev(host->mmc), "dma not available. Using PIO\n");
  957. INIT_WORK(&host->datawork, mxcmci_datawork);
  958. ret = devm_request_irq(&pdev->dev, irq, mxcmci_irq, 0,
  959. dev_name(&pdev->dev), host);
  960. if (ret)
  961. goto out_free_dma;
  962. platform_set_drvdata(pdev, mmc);
  963. if (host->pdata && host->pdata->init) {
  964. ret = host->pdata->init(&pdev->dev, mxcmci_detect_irq,
  965. host->mmc);
  966. if (ret)
  967. goto out_free_dma;
  968. }
  969. timer_setup(&host->watchdog, mxcmci_watchdog, 0);
  970. mmc_add_host(mmc);
  971. return 0;
  972. out_free_dma:
  973. if (host->dma)
  974. dma_release_channel(host->dma);
  975. out_clk_put:
  976. clk_disable_unprepare(host->clk_ipg);
  977. out_clk_per_put:
  978. clk_disable_unprepare(host->clk_per);
  979. out_free:
  980. mmc_free_host(mmc);
  981. return ret;
  982. }
  983. static int mxcmci_remove(struct platform_device *pdev)
  984. {
  985. struct mmc_host *mmc = platform_get_drvdata(pdev);
  986. struct mxcmci_host *host = mmc_priv(mmc);
  987. mmc_remove_host(mmc);
  988. if (host->pdata && host->pdata->exit)
  989. host->pdata->exit(&pdev->dev, mmc);
  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. mmc_free_host(mmc);
  995. return 0;
  996. }
  997. #ifdef CONFIG_PM_SLEEP
  998. static int mxcmci_suspend(struct device *dev)
  999. {
  1000. struct mmc_host *mmc = dev_get_drvdata(dev);
  1001. struct mxcmci_host *host = mmc_priv(mmc);
  1002. clk_disable_unprepare(host->clk_per);
  1003. clk_disable_unprepare(host->clk_ipg);
  1004. return 0;
  1005. }
  1006. static int mxcmci_resume(struct device *dev)
  1007. {
  1008. struct mmc_host *mmc = dev_get_drvdata(dev);
  1009. struct mxcmci_host *host = mmc_priv(mmc);
  1010. int ret;
  1011. ret = clk_prepare_enable(host->clk_per);
  1012. if (ret)
  1013. return ret;
  1014. ret = clk_prepare_enable(host->clk_ipg);
  1015. if (ret)
  1016. clk_disable_unprepare(host->clk_per);
  1017. return ret;
  1018. }
  1019. #endif
  1020. static SIMPLE_DEV_PM_OPS(mxcmci_pm_ops, mxcmci_suspend, mxcmci_resume);
  1021. static struct platform_driver mxcmci_driver = {
  1022. .probe = mxcmci_probe,
  1023. .remove = mxcmci_remove,
  1024. .id_table = mxcmci_devtype,
  1025. .driver = {
  1026. .name = DRIVER_NAME,
  1027. .pm = &mxcmci_pm_ops,
  1028. .of_match_table = mxcmci_of_match,
  1029. }
  1030. };
  1031. module_platform_driver(mxcmci_driver);
  1032. MODULE_DESCRIPTION("i.MX Multimedia Card Interface Driver");
  1033. MODULE_AUTHOR("Sascha Hauer, Pengutronix");
  1034. MODULE_LICENSE("GPL");
  1035. MODULE_ALIAS("platform:mxc-mmc");