sh_mmcif.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. /*
  2. * MMCIF eMMC driver.
  3. *
  4. * Copyright (C) 2010 Renesas Solutions Corp.
  5. * Yusuke Goda <yusuke.goda.sx@renesas.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License.
  10. *
  11. *
  12. * TODO
  13. * 1. DMA
  14. * 2. Power management
  15. * 3. Handle MMC errors better
  16. *
  17. */
  18. #include <linux/clk.h>
  19. #include <linux/completion.h>
  20. #include <linux/delay.h>
  21. #include <linux/dma-mapping.h>
  22. #include <linux/dmaengine.h>
  23. #include <linux/mmc/card.h>
  24. #include <linux/mmc/core.h>
  25. #include <linux/mmc/host.h>
  26. #include <linux/mmc/mmc.h>
  27. #include <linux/mmc/sdio.h>
  28. #include <linux/mmc/sh_mmcif.h>
  29. #include <linux/pagemap.h>
  30. #include <linux/platform_device.h>
  31. #define DRIVER_NAME "sh_mmcif"
  32. #define DRIVER_VERSION "2010-04-28"
  33. /* CE_CMD_SET */
  34. #define CMD_MASK 0x3f000000
  35. #define CMD_SET_RTYP_NO ((0 << 23) | (0 << 22))
  36. #define CMD_SET_RTYP_6B ((0 << 23) | (1 << 22)) /* R1/R1b/R3/R4/R5 */
  37. #define CMD_SET_RTYP_17B ((1 << 23) | (0 << 22)) /* R2 */
  38. #define CMD_SET_RBSY (1 << 21) /* R1b */
  39. #define CMD_SET_CCSEN (1 << 20)
  40. #define CMD_SET_WDAT (1 << 19) /* 1: on data, 0: no data */
  41. #define CMD_SET_DWEN (1 << 18) /* 1: write, 0: read */
  42. #define CMD_SET_CMLTE (1 << 17) /* 1: multi block trans, 0: single */
  43. #define CMD_SET_CMD12EN (1 << 16) /* 1: CMD12 auto issue */
  44. #define CMD_SET_RIDXC_INDEX ((0 << 15) | (0 << 14)) /* index check */
  45. #define CMD_SET_RIDXC_BITS ((0 << 15) | (1 << 14)) /* check bits check */
  46. #define CMD_SET_RIDXC_NO ((1 << 15) | (0 << 14)) /* no check */
  47. #define CMD_SET_CRC7C ((0 << 13) | (0 << 12)) /* CRC7 check*/
  48. #define CMD_SET_CRC7C_BITS ((0 << 13) | (1 << 12)) /* check bits check*/
  49. #define CMD_SET_CRC7C_INTERNAL ((1 << 13) | (0 << 12)) /* internal CRC7 check*/
  50. #define CMD_SET_CRC16C (1 << 10) /* 0: CRC16 check*/
  51. #define CMD_SET_CRCSTE (1 << 8) /* 1: not receive CRC status */
  52. #define CMD_SET_TBIT (1 << 7) /* 1: tran mission bit "Low" */
  53. #define CMD_SET_OPDM (1 << 6) /* 1: open/drain */
  54. #define CMD_SET_CCSH (1 << 5)
  55. #define CMD_SET_DATW_1 ((0 << 1) | (0 << 0)) /* 1bit */
  56. #define CMD_SET_DATW_4 ((0 << 1) | (1 << 0)) /* 4bit */
  57. #define CMD_SET_DATW_8 ((1 << 1) | (0 << 0)) /* 8bit */
  58. /* CE_CMD_CTRL */
  59. #define CMD_CTRL_BREAK (1 << 0)
  60. /* CE_BLOCK_SET */
  61. #define BLOCK_SIZE_MASK 0x0000ffff
  62. /* CE_INT */
  63. #define INT_CCSDE (1 << 29)
  64. #define INT_CMD12DRE (1 << 26)
  65. #define INT_CMD12RBE (1 << 25)
  66. #define INT_CMD12CRE (1 << 24)
  67. #define INT_DTRANE (1 << 23)
  68. #define INT_BUFRE (1 << 22)
  69. #define INT_BUFWEN (1 << 21)
  70. #define INT_BUFREN (1 << 20)
  71. #define INT_CCSRCV (1 << 19)
  72. #define INT_RBSYE (1 << 17)
  73. #define INT_CRSPE (1 << 16)
  74. #define INT_CMDVIO (1 << 15)
  75. #define INT_BUFVIO (1 << 14)
  76. #define INT_WDATERR (1 << 11)
  77. #define INT_RDATERR (1 << 10)
  78. #define INT_RIDXERR (1 << 9)
  79. #define INT_RSPERR (1 << 8)
  80. #define INT_CCSTO (1 << 5)
  81. #define INT_CRCSTO (1 << 4)
  82. #define INT_WDATTO (1 << 3)
  83. #define INT_RDATTO (1 << 2)
  84. #define INT_RBSYTO (1 << 1)
  85. #define INT_RSPTO (1 << 0)
  86. #define INT_ERR_STS (INT_CMDVIO | INT_BUFVIO | INT_WDATERR | \
  87. INT_RDATERR | INT_RIDXERR | INT_RSPERR | \
  88. INT_CCSTO | INT_CRCSTO | INT_WDATTO | \
  89. INT_RDATTO | INT_RBSYTO | INT_RSPTO)
  90. /* CE_INT_MASK */
  91. #define MASK_ALL 0x00000000
  92. #define MASK_MCCSDE (1 << 29)
  93. #define MASK_MCMD12DRE (1 << 26)
  94. #define MASK_MCMD12RBE (1 << 25)
  95. #define MASK_MCMD12CRE (1 << 24)
  96. #define MASK_MDTRANE (1 << 23)
  97. #define MASK_MBUFRE (1 << 22)
  98. #define MASK_MBUFWEN (1 << 21)
  99. #define MASK_MBUFREN (1 << 20)
  100. #define MASK_MCCSRCV (1 << 19)
  101. #define MASK_MRBSYE (1 << 17)
  102. #define MASK_MCRSPE (1 << 16)
  103. #define MASK_MCMDVIO (1 << 15)
  104. #define MASK_MBUFVIO (1 << 14)
  105. #define MASK_MWDATERR (1 << 11)
  106. #define MASK_MRDATERR (1 << 10)
  107. #define MASK_MRIDXERR (1 << 9)
  108. #define MASK_MRSPERR (1 << 8)
  109. #define MASK_MCCSTO (1 << 5)
  110. #define MASK_MCRCSTO (1 << 4)
  111. #define MASK_MWDATTO (1 << 3)
  112. #define MASK_MRDATTO (1 << 2)
  113. #define MASK_MRBSYTO (1 << 1)
  114. #define MASK_MRSPTO (1 << 0)
  115. /* CE_HOST_STS1 */
  116. #define STS1_CMDSEQ (1 << 31)
  117. /* CE_HOST_STS2 */
  118. #define STS2_CRCSTE (1 << 31)
  119. #define STS2_CRC16E (1 << 30)
  120. #define STS2_AC12CRCE (1 << 29)
  121. #define STS2_RSPCRC7E (1 << 28)
  122. #define STS2_CRCSTEBE (1 << 27)
  123. #define STS2_RDATEBE (1 << 26)
  124. #define STS2_AC12REBE (1 << 25)
  125. #define STS2_RSPEBE (1 << 24)
  126. #define STS2_AC12IDXE (1 << 23)
  127. #define STS2_RSPIDXE (1 << 22)
  128. #define STS2_CCSTO (1 << 15)
  129. #define STS2_RDATTO (1 << 14)
  130. #define STS2_DATBSYTO (1 << 13)
  131. #define STS2_CRCSTTO (1 << 12)
  132. #define STS2_AC12BSYTO (1 << 11)
  133. #define STS2_RSPBSYTO (1 << 10)
  134. #define STS2_AC12RSPTO (1 << 9)
  135. #define STS2_RSPTO (1 << 8)
  136. #define STS2_CRC_ERR (STS2_CRCSTE | STS2_CRC16E | \
  137. STS2_AC12CRCE | STS2_RSPCRC7E | STS2_CRCSTEBE)
  138. #define STS2_TIMEOUT_ERR (STS2_CCSTO | STS2_RDATTO | \
  139. STS2_DATBSYTO | STS2_CRCSTTO | \
  140. STS2_AC12BSYTO | STS2_RSPBSYTO | \
  141. STS2_AC12RSPTO | STS2_RSPTO)
  142. #define CLKDEV_EMMC_DATA 52000000 /* 52MHz */
  143. #define CLKDEV_MMC_DATA 20000000 /* 20MHz */
  144. #define CLKDEV_INIT 400000 /* 400 KHz */
  145. struct sh_mmcif_host {
  146. struct mmc_host *mmc;
  147. struct mmc_data *data;
  148. struct platform_device *pd;
  149. struct clk *hclk;
  150. unsigned int clk;
  151. int bus_width;
  152. bool sd_error;
  153. long timeout;
  154. void __iomem *addr;
  155. struct completion intr_wait;
  156. /* DMA support */
  157. struct dma_chan *chan_rx;
  158. struct dma_chan *chan_tx;
  159. struct completion dma_complete;
  160. unsigned int dma_sglen;
  161. };
  162. static inline void sh_mmcif_bitset(struct sh_mmcif_host *host,
  163. unsigned int reg, u32 val)
  164. {
  165. writel(val | readl(host->addr + reg), host->addr + reg);
  166. }
  167. static inline void sh_mmcif_bitclr(struct sh_mmcif_host *host,
  168. unsigned int reg, u32 val)
  169. {
  170. writel(~val & readl(host->addr + reg), host->addr + reg);
  171. }
  172. static void mmcif_dma_complete(void *arg)
  173. {
  174. struct sh_mmcif_host *host = arg;
  175. dev_dbg(&host->pd->dev, "Command completed\n");
  176. if (WARN(!host->data, "%s: NULL data in DMA completion!\n",
  177. dev_name(&host->pd->dev)))
  178. return;
  179. if (host->data->flags & MMC_DATA_READ)
  180. dma_unmap_sg(&host->pd->dev, host->data->sg, host->dma_sglen,
  181. DMA_FROM_DEVICE);
  182. else
  183. dma_unmap_sg(&host->pd->dev, host->data->sg, host->dma_sglen,
  184. DMA_TO_DEVICE);
  185. complete(&host->dma_complete);
  186. }
  187. static void sh_mmcif_start_dma_rx(struct sh_mmcif_host *host)
  188. {
  189. struct scatterlist *sg = host->data->sg;
  190. struct dma_async_tx_descriptor *desc = NULL;
  191. struct dma_chan *chan = host->chan_rx;
  192. dma_cookie_t cookie = -EINVAL;
  193. int ret;
  194. ret = dma_map_sg(&host->pd->dev, sg, host->data->sg_len, DMA_FROM_DEVICE);
  195. if (ret > 0) {
  196. host->dma_sglen = ret;
  197. desc = chan->device->device_prep_slave_sg(chan, sg, ret,
  198. DMA_FROM_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  199. }
  200. if (desc) {
  201. desc->callback = mmcif_dma_complete;
  202. desc->callback_param = host;
  203. cookie = desc->tx_submit(desc);
  204. if (cookie < 0) {
  205. desc = NULL;
  206. ret = cookie;
  207. } else {
  208. sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN);
  209. chan->device->device_issue_pending(chan);
  210. }
  211. }
  212. dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n",
  213. __func__, host->data->sg_len, ret, cookie);
  214. if (!desc) {
  215. /* DMA failed, fall back to PIO */
  216. if (ret >= 0)
  217. ret = -EIO;
  218. host->chan_rx = NULL;
  219. host->dma_sglen = 0;
  220. dma_release_channel(chan);
  221. /* Free the Tx channel too */
  222. chan = host->chan_tx;
  223. if (chan) {
  224. host->chan_tx = NULL;
  225. dma_release_channel(chan);
  226. }
  227. dev_warn(&host->pd->dev,
  228. "DMA failed: %d, falling back to PIO\n", ret);
  229. sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
  230. }
  231. dev_dbg(&host->pd->dev, "%s(): desc %p, cookie %d, sg[%d]\n", __func__,
  232. desc, cookie, host->data->sg_len);
  233. }
  234. static void sh_mmcif_start_dma_tx(struct sh_mmcif_host *host)
  235. {
  236. struct scatterlist *sg = host->data->sg;
  237. struct dma_async_tx_descriptor *desc = NULL;
  238. struct dma_chan *chan = host->chan_tx;
  239. dma_cookie_t cookie = -EINVAL;
  240. int ret;
  241. ret = dma_map_sg(&host->pd->dev, sg, host->data->sg_len, DMA_TO_DEVICE);
  242. if (ret > 0) {
  243. host->dma_sglen = ret;
  244. desc = chan->device->device_prep_slave_sg(chan, sg, ret,
  245. DMA_TO_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  246. }
  247. if (desc) {
  248. desc->callback = mmcif_dma_complete;
  249. desc->callback_param = host;
  250. cookie = desc->tx_submit(desc);
  251. if (cookie < 0) {
  252. desc = NULL;
  253. ret = cookie;
  254. } else {
  255. sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAWEN);
  256. chan->device->device_issue_pending(chan);
  257. }
  258. }
  259. dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n",
  260. __func__, host->data->sg_len, ret, cookie);
  261. if (!desc) {
  262. /* DMA failed, fall back to PIO */
  263. if (ret >= 0)
  264. ret = -EIO;
  265. host->chan_tx = NULL;
  266. host->dma_sglen = 0;
  267. dma_release_channel(chan);
  268. /* Free the Rx channel too */
  269. chan = host->chan_rx;
  270. if (chan) {
  271. host->chan_rx = NULL;
  272. dma_release_channel(chan);
  273. }
  274. dev_warn(&host->pd->dev,
  275. "DMA failed: %d, falling back to PIO\n", ret);
  276. sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
  277. }
  278. dev_dbg(&host->pd->dev, "%s(): desc %p, cookie %d\n", __func__,
  279. desc, cookie);
  280. }
  281. static bool sh_mmcif_filter(struct dma_chan *chan, void *arg)
  282. {
  283. dev_dbg(chan->device->dev, "%s: slave data %p\n", __func__, arg);
  284. chan->private = arg;
  285. return true;
  286. }
  287. static void sh_mmcif_request_dma(struct sh_mmcif_host *host,
  288. struct sh_mmcif_plat_data *pdata)
  289. {
  290. host->dma_sglen = 0;
  291. /* We can only either use DMA for both Tx and Rx or not use it at all */
  292. if (pdata->dma) {
  293. dma_cap_mask_t mask;
  294. dma_cap_zero(mask);
  295. dma_cap_set(DMA_SLAVE, mask);
  296. host->chan_tx = dma_request_channel(mask, sh_mmcif_filter,
  297. &pdata->dma->chan_priv_tx);
  298. dev_dbg(&host->pd->dev, "%s: TX: got channel %p\n", __func__,
  299. host->chan_tx);
  300. if (!host->chan_tx)
  301. return;
  302. host->chan_rx = dma_request_channel(mask, sh_mmcif_filter,
  303. &pdata->dma->chan_priv_rx);
  304. dev_dbg(&host->pd->dev, "%s: RX: got channel %p\n", __func__,
  305. host->chan_rx);
  306. if (!host->chan_rx) {
  307. dma_release_channel(host->chan_tx);
  308. host->chan_tx = NULL;
  309. return;
  310. }
  311. init_completion(&host->dma_complete);
  312. }
  313. }
  314. static void sh_mmcif_release_dma(struct sh_mmcif_host *host)
  315. {
  316. sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
  317. /* Descriptors are freed automatically */
  318. if (host->chan_tx) {
  319. struct dma_chan *chan = host->chan_tx;
  320. host->chan_tx = NULL;
  321. dma_release_channel(chan);
  322. }
  323. if (host->chan_rx) {
  324. struct dma_chan *chan = host->chan_rx;
  325. host->chan_rx = NULL;
  326. dma_release_channel(chan);
  327. }
  328. host->dma_sglen = 0;
  329. }
  330. static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk)
  331. {
  332. struct sh_mmcif_plat_data *p = host->pd->dev.platform_data;
  333. sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE);
  334. sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR);
  335. if (!clk)
  336. return;
  337. if (p->sup_pclk && clk == host->clk)
  338. sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK);
  339. else
  340. sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR &
  341. (ilog2(__rounddown_pow_of_two(host->clk / clk)) << 16));
  342. sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE);
  343. }
  344. static void sh_mmcif_sync_reset(struct sh_mmcif_host *host)
  345. {
  346. u32 tmp;
  347. tmp = 0x010f0000 & sh_mmcif_readl(host->addr, MMCIF_CE_CLK_CTRL);
  348. sh_mmcif_writel(host->addr, MMCIF_CE_VERSION, SOFT_RST_ON);
  349. sh_mmcif_writel(host->addr, MMCIF_CE_VERSION, SOFT_RST_OFF);
  350. sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, tmp |
  351. SRSPTO_256 | SRBSYTO_29 | SRWDTO_29 | SCCSTO_29);
  352. /* byte swap on */
  353. sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_ATYP);
  354. }
  355. static int sh_mmcif_error_manage(struct sh_mmcif_host *host)
  356. {
  357. u32 state1, state2;
  358. int ret, timeout = 10000000;
  359. host->sd_error = false;
  360. state1 = sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS1);
  361. state2 = sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS2);
  362. dev_dbg(&host->pd->dev, "ERR HOST_STS1 = %08x\n", state1);
  363. dev_dbg(&host->pd->dev, "ERR HOST_STS2 = %08x\n", state2);
  364. if (state1 & STS1_CMDSEQ) {
  365. sh_mmcif_bitset(host, MMCIF_CE_CMD_CTRL, CMD_CTRL_BREAK);
  366. sh_mmcif_bitset(host, MMCIF_CE_CMD_CTRL, ~CMD_CTRL_BREAK);
  367. while (1) {
  368. timeout--;
  369. if (timeout < 0) {
  370. dev_err(&host->pd->dev,
  371. "Forceed end of command sequence timeout err\n");
  372. return -EIO;
  373. }
  374. if (!(sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS1)
  375. & STS1_CMDSEQ))
  376. break;
  377. mdelay(1);
  378. }
  379. sh_mmcif_sync_reset(host);
  380. dev_dbg(&host->pd->dev, "Forced end of command sequence\n");
  381. return -EIO;
  382. }
  383. if (state2 & STS2_CRC_ERR) {
  384. dev_dbg(&host->pd->dev, ": Happened CRC error\n");
  385. ret = -EIO;
  386. } else if (state2 & STS2_TIMEOUT_ERR) {
  387. dev_dbg(&host->pd->dev, ": Happened Timeout error\n");
  388. ret = -ETIMEDOUT;
  389. } else {
  390. dev_dbg(&host->pd->dev, ": Happened End/Index error\n");
  391. ret = -EIO;
  392. }
  393. return ret;
  394. }
  395. static int sh_mmcif_single_read(struct sh_mmcif_host *host,
  396. struct mmc_request *mrq)
  397. {
  398. struct mmc_data *data = mrq->data;
  399. long time;
  400. u32 blocksize, i, *p = sg_virt(data->sg);
  401. /* buf read enable */
  402. sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN);
  403. time = wait_for_completion_interruptible_timeout(&host->intr_wait,
  404. host->timeout);
  405. if (time <= 0 || host->sd_error)
  406. return sh_mmcif_error_manage(host);
  407. blocksize = (BLOCK_SIZE_MASK &
  408. sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET)) + 3;
  409. for (i = 0; i < blocksize / 4; i++)
  410. *p++ = sh_mmcif_readl(host->addr, MMCIF_CE_DATA);
  411. /* buffer read end */
  412. sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFRE);
  413. time = wait_for_completion_interruptible_timeout(&host->intr_wait,
  414. host->timeout);
  415. if (time <= 0 || host->sd_error)
  416. return sh_mmcif_error_manage(host);
  417. return 0;
  418. }
  419. static int sh_mmcif_multi_read(struct sh_mmcif_host *host,
  420. struct mmc_request *mrq)
  421. {
  422. struct mmc_data *data = mrq->data;
  423. long time;
  424. u32 blocksize, i, j, sec, *p;
  425. blocksize = BLOCK_SIZE_MASK & sh_mmcif_readl(host->addr,
  426. MMCIF_CE_BLOCK_SET);
  427. for (j = 0; j < data->sg_len; j++) {
  428. p = sg_virt(data->sg);
  429. for (sec = 0; sec < data->sg->length / blocksize; sec++) {
  430. sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN);
  431. /* buf read enable */
  432. time = wait_for_completion_interruptible_timeout(&host->intr_wait,
  433. host->timeout);
  434. if (time <= 0 || host->sd_error)
  435. return sh_mmcif_error_manage(host);
  436. for (i = 0; i < blocksize / 4; i++)
  437. *p++ = sh_mmcif_readl(host->addr,
  438. MMCIF_CE_DATA);
  439. }
  440. if (j < data->sg_len - 1)
  441. data->sg++;
  442. }
  443. return 0;
  444. }
  445. static int sh_mmcif_single_write(struct sh_mmcif_host *host,
  446. struct mmc_request *mrq)
  447. {
  448. struct mmc_data *data = mrq->data;
  449. long time;
  450. u32 blocksize, i, *p = sg_virt(data->sg);
  451. sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
  452. /* buf write enable */
  453. time = wait_for_completion_interruptible_timeout(&host->intr_wait,
  454. host->timeout);
  455. if (time <= 0 || host->sd_error)
  456. return sh_mmcif_error_manage(host);
  457. blocksize = (BLOCK_SIZE_MASK &
  458. sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET)) + 3;
  459. for (i = 0; i < blocksize / 4; i++)
  460. sh_mmcif_writel(host->addr, MMCIF_CE_DATA, *p++);
  461. /* buffer write end */
  462. sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MDTRANE);
  463. time = wait_for_completion_interruptible_timeout(&host->intr_wait,
  464. host->timeout);
  465. if (time <= 0 || host->sd_error)
  466. return sh_mmcif_error_manage(host);
  467. return 0;
  468. }
  469. static int sh_mmcif_multi_write(struct sh_mmcif_host *host,
  470. struct mmc_request *mrq)
  471. {
  472. struct mmc_data *data = mrq->data;
  473. long time;
  474. u32 i, sec, j, blocksize, *p;
  475. blocksize = BLOCK_SIZE_MASK & sh_mmcif_readl(host->addr,
  476. MMCIF_CE_BLOCK_SET);
  477. for (j = 0; j < data->sg_len; j++) {
  478. p = sg_virt(data->sg);
  479. for (sec = 0; sec < data->sg->length / blocksize; sec++) {
  480. sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
  481. /* buf write enable*/
  482. time = wait_for_completion_interruptible_timeout(&host->intr_wait,
  483. host->timeout);
  484. if (time <= 0 || host->sd_error)
  485. return sh_mmcif_error_manage(host);
  486. for (i = 0; i < blocksize / 4; i++)
  487. sh_mmcif_writel(host->addr,
  488. MMCIF_CE_DATA, *p++);
  489. }
  490. if (j < data->sg_len - 1)
  491. data->sg++;
  492. }
  493. return 0;
  494. }
  495. static void sh_mmcif_get_response(struct sh_mmcif_host *host,
  496. struct mmc_command *cmd)
  497. {
  498. if (cmd->flags & MMC_RSP_136) {
  499. cmd->resp[0] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP3);
  500. cmd->resp[1] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP2);
  501. cmd->resp[2] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP1);
  502. cmd->resp[3] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP0);
  503. } else
  504. cmd->resp[0] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP0);
  505. }
  506. static void sh_mmcif_get_cmd12response(struct sh_mmcif_host *host,
  507. struct mmc_command *cmd)
  508. {
  509. cmd->resp[0] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP_CMD12);
  510. }
  511. static u32 sh_mmcif_set_cmd(struct sh_mmcif_host *host,
  512. struct mmc_request *mrq, struct mmc_command *cmd, u32 opc)
  513. {
  514. u32 tmp = 0;
  515. /* Response Type check */
  516. switch (mmc_resp_type(cmd)) {
  517. case MMC_RSP_NONE:
  518. tmp |= CMD_SET_RTYP_NO;
  519. break;
  520. case MMC_RSP_R1:
  521. case MMC_RSP_R1B:
  522. case MMC_RSP_R3:
  523. tmp |= CMD_SET_RTYP_6B;
  524. break;
  525. case MMC_RSP_R2:
  526. tmp |= CMD_SET_RTYP_17B;
  527. break;
  528. default:
  529. dev_err(&host->pd->dev, "Unsupported response type.\n");
  530. break;
  531. }
  532. switch (opc) {
  533. /* RBSY */
  534. case MMC_SWITCH:
  535. case MMC_STOP_TRANSMISSION:
  536. case MMC_SET_WRITE_PROT:
  537. case MMC_CLR_WRITE_PROT:
  538. case MMC_ERASE:
  539. case MMC_GEN_CMD:
  540. tmp |= CMD_SET_RBSY;
  541. break;
  542. }
  543. /* WDAT / DATW */
  544. if (host->data) {
  545. tmp |= CMD_SET_WDAT;
  546. switch (host->bus_width) {
  547. case MMC_BUS_WIDTH_1:
  548. tmp |= CMD_SET_DATW_1;
  549. break;
  550. case MMC_BUS_WIDTH_4:
  551. tmp |= CMD_SET_DATW_4;
  552. break;
  553. case MMC_BUS_WIDTH_8:
  554. tmp |= CMD_SET_DATW_8;
  555. break;
  556. default:
  557. dev_err(&host->pd->dev, "Unsupported bus width.\n");
  558. break;
  559. }
  560. }
  561. /* DWEN */
  562. if (opc == MMC_WRITE_BLOCK || opc == MMC_WRITE_MULTIPLE_BLOCK)
  563. tmp |= CMD_SET_DWEN;
  564. /* CMLTE/CMD12EN */
  565. if (opc == MMC_READ_MULTIPLE_BLOCK || opc == MMC_WRITE_MULTIPLE_BLOCK) {
  566. tmp |= CMD_SET_CMLTE | CMD_SET_CMD12EN;
  567. sh_mmcif_bitset(host, MMCIF_CE_BLOCK_SET,
  568. mrq->data->blocks << 16);
  569. }
  570. /* RIDXC[1:0] check bits */
  571. if (opc == MMC_SEND_OP_COND || opc == MMC_ALL_SEND_CID ||
  572. opc == MMC_SEND_CSD || opc == MMC_SEND_CID)
  573. tmp |= CMD_SET_RIDXC_BITS;
  574. /* RCRC7C[1:0] check bits */
  575. if (opc == MMC_SEND_OP_COND)
  576. tmp |= CMD_SET_CRC7C_BITS;
  577. /* RCRC7C[1:0] internal CRC7 */
  578. if (opc == MMC_ALL_SEND_CID ||
  579. opc == MMC_SEND_CSD || opc == MMC_SEND_CID)
  580. tmp |= CMD_SET_CRC7C_INTERNAL;
  581. return opc = ((opc << 24) | tmp);
  582. }
  583. static int sh_mmcif_data_trans(struct sh_mmcif_host *host,
  584. struct mmc_request *mrq, u32 opc)
  585. {
  586. int ret;
  587. switch (opc) {
  588. case MMC_READ_MULTIPLE_BLOCK:
  589. ret = sh_mmcif_multi_read(host, mrq);
  590. break;
  591. case MMC_WRITE_MULTIPLE_BLOCK:
  592. ret = sh_mmcif_multi_write(host, mrq);
  593. break;
  594. case MMC_WRITE_BLOCK:
  595. ret = sh_mmcif_single_write(host, mrq);
  596. break;
  597. case MMC_READ_SINGLE_BLOCK:
  598. case MMC_SEND_EXT_CSD:
  599. ret = sh_mmcif_single_read(host, mrq);
  600. break;
  601. default:
  602. dev_err(&host->pd->dev, "UNSUPPORTED CMD = d'%08d\n", opc);
  603. ret = -EINVAL;
  604. break;
  605. }
  606. return ret;
  607. }
  608. static void sh_mmcif_start_cmd(struct sh_mmcif_host *host,
  609. struct mmc_request *mrq, struct mmc_command *cmd)
  610. {
  611. long time;
  612. int ret = 0, mask = 0;
  613. u32 opc = cmd->opcode;
  614. switch (opc) {
  615. /* respons busy check */
  616. case MMC_SWITCH:
  617. case MMC_STOP_TRANSMISSION:
  618. case MMC_SET_WRITE_PROT:
  619. case MMC_CLR_WRITE_PROT:
  620. case MMC_ERASE:
  621. case MMC_GEN_CMD:
  622. mask = MASK_MRBSYE;
  623. break;
  624. default:
  625. mask = MASK_MCRSPE;
  626. break;
  627. }
  628. mask |= MASK_MCMDVIO | MASK_MBUFVIO | MASK_MWDATERR |
  629. MASK_MRDATERR | MASK_MRIDXERR | MASK_MRSPERR |
  630. MASK_MCCSTO | MASK_MCRCSTO | MASK_MWDATTO |
  631. MASK_MRDATTO | MASK_MRBSYTO | MASK_MRSPTO;
  632. if (host->data) {
  633. sh_mmcif_writel(host->addr, MMCIF_CE_BLOCK_SET, 0);
  634. sh_mmcif_writel(host->addr, MMCIF_CE_BLOCK_SET,
  635. mrq->data->blksz);
  636. }
  637. opc = sh_mmcif_set_cmd(host, mrq, cmd, opc);
  638. sh_mmcif_writel(host->addr, MMCIF_CE_INT, 0xD80430C0);
  639. sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, mask);
  640. /* set arg */
  641. sh_mmcif_writel(host->addr, MMCIF_CE_ARG, cmd->arg);
  642. /* set cmd */
  643. sh_mmcif_writel(host->addr, MMCIF_CE_CMD_SET, opc);
  644. time = wait_for_completion_interruptible_timeout(&host->intr_wait,
  645. host->timeout);
  646. if (time <= 0) {
  647. cmd->error = sh_mmcif_error_manage(host);
  648. return;
  649. }
  650. if (host->sd_error) {
  651. switch (cmd->opcode) {
  652. case MMC_ALL_SEND_CID:
  653. case MMC_SELECT_CARD:
  654. case MMC_APP_CMD:
  655. cmd->error = -ETIMEDOUT;
  656. break;
  657. default:
  658. dev_dbg(&host->pd->dev, "Cmd(d'%d) err\n",
  659. cmd->opcode);
  660. cmd->error = sh_mmcif_error_manage(host);
  661. break;
  662. }
  663. host->sd_error = false;
  664. return;
  665. }
  666. if (!(cmd->flags & MMC_RSP_PRESENT)) {
  667. cmd->error = 0;
  668. return;
  669. }
  670. sh_mmcif_get_response(host, cmd);
  671. if (host->data) {
  672. if (!host->dma_sglen) {
  673. ret = sh_mmcif_data_trans(host, mrq, cmd->opcode);
  674. } else {
  675. long time =
  676. wait_for_completion_interruptible_timeout(&host->dma_complete,
  677. host->timeout);
  678. if (!time)
  679. ret = -ETIMEDOUT;
  680. else if (time < 0)
  681. ret = time;
  682. sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC,
  683. BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
  684. host->dma_sglen = 0;
  685. }
  686. if (ret < 0)
  687. mrq->data->bytes_xfered = 0;
  688. else
  689. mrq->data->bytes_xfered =
  690. mrq->data->blocks * mrq->data->blksz;
  691. }
  692. cmd->error = ret;
  693. }
  694. static void sh_mmcif_stop_cmd(struct sh_mmcif_host *host,
  695. struct mmc_request *mrq, struct mmc_command *cmd)
  696. {
  697. long time;
  698. if (mrq->cmd->opcode == MMC_READ_MULTIPLE_BLOCK)
  699. sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MCMD12DRE);
  700. else if (mrq->cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK)
  701. sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MCMD12RBE);
  702. else {
  703. dev_err(&host->pd->dev, "unsupported stop cmd\n");
  704. cmd->error = sh_mmcif_error_manage(host);
  705. return;
  706. }
  707. time = wait_for_completion_interruptible_timeout(&host->intr_wait,
  708. host->timeout);
  709. if (time <= 0 || host->sd_error) {
  710. cmd->error = sh_mmcif_error_manage(host);
  711. return;
  712. }
  713. sh_mmcif_get_cmd12response(host, cmd);
  714. cmd->error = 0;
  715. }
  716. static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq)
  717. {
  718. struct sh_mmcif_host *host = mmc_priv(mmc);
  719. switch (mrq->cmd->opcode) {
  720. /* MMCIF does not support SD/SDIO command */
  721. case SD_IO_SEND_OP_COND:
  722. case MMC_APP_CMD:
  723. mrq->cmd->error = -ETIMEDOUT;
  724. mmc_request_done(mmc, mrq);
  725. return;
  726. case MMC_SEND_EXT_CSD: /* = SD_SEND_IF_COND (8) */
  727. if (!mrq->data) {
  728. /* send_if_cond cmd (not support) */
  729. mrq->cmd->error = -ETIMEDOUT;
  730. mmc_request_done(mmc, mrq);
  731. return;
  732. }
  733. break;
  734. default:
  735. break;
  736. }
  737. host->data = mrq->data;
  738. if (mrq->data) {
  739. if (mrq->data->flags & MMC_DATA_READ) {
  740. if (host->chan_rx)
  741. sh_mmcif_start_dma_rx(host);
  742. } else {
  743. if (host->chan_tx)
  744. sh_mmcif_start_dma_tx(host);
  745. }
  746. }
  747. sh_mmcif_start_cmd(host, mrq, mrq->cmd);
  748. host->data = NULL;
  749. if (mrq->cmd->error != 0) {
  750. mmc_request_done(mmc, mrq);
  751. return;
  752. }
  753. if (mrq->stop)
  754. sh_mmcif_stop_cmd(host, mrq, mrq->stop);
  755. mmc_request_done(mmc, mrq);
  756. }
  757. static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  758. {
  759. struct sh_mmcif_host *host = mmc_priv(mmc);
  760. struct sh_mmcif_plat_data *p = host->pd->dev.platform_data;
  761. if (ios->power_mode == MMC_POWER_OFF) {
  762. /* clock stop */
  763. sh_mmcif_clock_control(host, 0);
  764. if (p->down_pwr)
  765. p->down_pwr(host->pd);
  766. return;
  767. } else if (ios->power_mode == MMC_POWER_UP) {
  768. if (p->set_pwr)
  769. p->set_pwr(host->pd, ios->power_mode);
  770. }
  771. if (ios->clock)
  772. sh_mmcif_clock_control(host, ios->clock);
  773. host->bus_width = ios->bus_width;
  774. }
  775. static int sh_mmcif_get_cd(struct mmc_host *mmc)
  776. {
  777. struct sh_mmcif_host *host = mmc_priv(mmc);
  778. struct sh_mmcif_plat_data *p = host->pd->dev.platform_data;
  779. if (!p->get_cd)
  780. return -ENOSYS;
  781. else
  782. return p->get_cd(host->pd);
  783. }
  784. static struct mmc_host_ops sh_mmcif_ops = {
  785. .request = sh_mmcif_request,
  786. .set_ios = sh_mmcif_set_ios,
  787. .get_cd = sh_mmcif_get_cd,
  788. };
  789. static void sh_mmcif_detect(struct mmc_host *mmc)
  790. {
  791. mmc_detect_change(mmc, 0);
  792. }
  793. static irqreturn_t sh_mmcif_intr(int irq, void *dev_id)
  794. {
  795. struct sh_mmcif_host *host = dev_id;
  796. u32 state;
  797. int err = 0;
  798. state = sh_mmcif_readl(host->addr, MMCIF_CE_INT);
  799. if (state & INT_RBSYE) {
  800. sh_mmcif_writel(host->addr, MMCIF_CE_INT,
  801. ~(INT_RBSYE | INT_CRSPE));
  802. sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MRBSYE);
  803. } else if (state & INT_CRSPE) {
  804. sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_CRSPE);
  805. sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MCRSPE);
  806. } else if (state & INT_BUFREN) {
  807. sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_BUFREN);
  808. sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MBUFREN);
  809. } else if (state & INT_BUFWEN) {
  810. sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_BUFWEN);
  811. sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
  812. } else if (state & INT_CMD12DRE) {
  813. sh_mmcif_writel(host->addr, MMCIF_CE_INT,
  814. ~(INT_CMD12DRE | INT_CMD12RBE |
  815. INT_CMD12CRE | INT_BUFRE));
  816. sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MCMD12DRE);
  817. } else if (state & INT_BUFRE) {
  818. sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_BUFRE);
  819. sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MBUFRE);
  820. } else if (state & INT_DTRANE) {
  821. sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_DTRANE);
  822. sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MDTRANE);
  823. } else if (state & INT_CMD12RBE) {
  824. sh_mmcif_writel(host->addr, MMCIF_CE_INT,
  825. ~(INT_CMD12RBE | INT_CMD12CRE));
  826. sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MCMD12RBE);
  827. } else if (state & INT_ERR_STS) {
  828. /* err interrupts */
  829. sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~state);
  830. sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, state);
  831. err = 1;
  832. } else {
  833. dev_dbg(&host->pd->dev, "Not support int\n");
  834. sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~state);
  835. sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, state);
  836. err = 1;
  837. }
  838. if (err) {
  839. host->sd_error = true;
  840. dev_dbg(&host->pd->dev, "int err state = %08x\n", state);
  841. }
  842. if (state & ~(INT_CMD12RBE | INT_CMD12CRE))
  843. complete(&host->intr_wait);
  844. else
  845. dev_dbg(&host->pd->dev, "Unexpected IRQ 0x%x\n", state);
  846. return IRQ_HANDLED;
  847. }
  848. static int __devinit sh_mmcif_probe(struct platform_device *pdev)
  849. {
  850. int ret = 0, irq[2];
  851. struct mmc_host *mmc;
  852. struct sh_mmcif_host *host;
  853. struct sh_mmcif_plat_data *pd;
  854. struct resource *res;
  855. void __iomem *reg;
  856. char clk_name[8];
  857. irq[0] = platform_get_irq(pdev, 0);
  858. irq[1] = platform_get_irq(pdev, 1);
  859. if (irq[0] < 0 || irq[1] < 0) {
  860. dev_err(&pdev->dev, "Get irq error\n");
  861. return -ENXIO;
  862. }
  863. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  864. if (!res) {
  865. dev_err(&pdev->dev, "platform_get_resource error.\n");
  866. return -ENXIO;
  867. }
  868. reg = ioremap(res->start, resource_size(res));
  869. if (!reg) {
  870. dev_err(&pdev->dev, "ioremap error.\n");
  871. return -ENOMEM;
  872. }
  873. pd = pdev->dev.platform_data;
  874. if (!pd) {
  875. dev_err(&pdev->dev, "sh_mmcif plat data error.\n");
  876. ret = -ENXIO;
  877. goto clean_up;
  878. }
  879. mmc = mmc_alloc_host(sizeof(struct sh_mmcif_host), &pdev->dev);
  880. if (!mmc) {
  881. ret = -ENOMEM;
  882. goto clean_up;
  883. }
  884. host = mmc_priv(mmc);
  885. host->mmc = mmc;
  886. host->addr = reg;
  887. host->timeout = 1000;
  888. snprintf(clk_name, sizeof(clk_name), "mmc%d", pdev->id);
  889. host->hclk = clk_get(&pdev->dev, clk_name);
  890. if (IS_ERR(host->hclk)) {
  891. dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name);
  892. ret = PTR_ERR(host->hclk);
  893. goto clean_up1;
  894. }
  895. clk_enable(host->hclk);
  896. host->clk = clk_get_rate(host->hclk);
  897. host->pd = pdev;
  898. init_completion(&host->intr_wait);
  899. mmc->ops = &sh_mmcif_ops;
  900. mmc->f_max = host->clk;
  901. /* close to 400KHz */
  902. if (mmc->f_max < 51200000)
  903. mmc->f_min = mmc->f_max / 128;
  904. else if (mmc->f_max < 102400000)
  905. mmc->f_min = mmc->f_max / 256;
  906. else
  907. mmc->f_min = mmc->f_max / 512;
  908. if (pd->ocr)
  909. mmc->ocr_avail = pd->ocr;
  910. mmc->caps = MMC_CAP_MMC_HIGHSPEED;
  911. if (pd->caps)
  912. mmc->caps |= pd->caps;
  913. mmc->max_segs = 32;
  914. mmc->max_blk_size = 512;
  915. mmc->max_req_size = PAGE_CACHE_SIZE * mmc->max_segs;
  916. mmc->max_blk_count = mmc->max_req_size / mmc->max_blk_size;
  917. mmc->max_seg_size = mmc->max_req_size;
  918. sh_mmcif_sync_reset(host);
  919. platform_set_drvdata(pdev, host);
  920. /* See if we also get DMA */
  921. sh_mmcif_request_dma(host, pd);
  922. mmc_add_host(mmc);
  923. ret = request_irq(irq[0], sh_mmcif_intr, 0, "sh_mmc:error", host);
  924. if (ret) {
  925. dev_err(&pdev->dev, "request_irq error (sh_mmc:error)\n");
  926. goto clean_up2;
  927. }
  928. ret = request_irq(irq[1], sh_mmcif_intr, 0, "sh_mmc:int", host);
  929. if (ret) {
  930. free_irq(irq[0], host);
  931. dev_err(&pdev->dev, "request_irq error (sh_mmc:int)\n");
  932. goto clean_up2;
  933. }
  934. sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
  935. sh_mmcif_detect(host->mmc);
  936. dev_info(&pdev->dev, "driver version %s\n", DRIVER_VERSION);
  937. dev_dbg(&pdev->dev, "chip ver H'%04x\n",
  938. sh_mmcif_readl(host->addr, MMCIF_CE_VERSION) & 0x0000ffff);
  939. return ret;
  940. clean_up2:
  941. clk_disable(host->hclk);
  942. clean_up1:
  943. mmc_free_host(mmc);
  944. clean_up:
  945. if (reg)
  946. iounmap(reg);
  947. return ret;
  948. }
  949. static int __devexit sh_mmcif_remove(struct platform_device *pdev)
  950. {
  951. struct sh_mmcif_host *host = platform_get_drvdata(pdev);
  952. int irq[2];
  953. mmc_remove_host(host->mmc);
  954. sh_mmcif_release_dma(host);
  955. if (host->addr)
  956. iounmap(host->addr);
  957. sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
  958. irq[0] = platform_get_irq(pdev, 0);
  959. irq[1] = platform_get_irq(pdev, 1);
  960. free_irq(irq[0], host);
  961. free_irq(irq[1], host);
  962. platform_set_drvdata(pdev, NULL);
  963. clk_disable(host->hclk);
  964. mmc_free_host(host->mmc);
  965. return 0;
  966. }
  967. static struct platform_driver sh_mmcif_driver = {
  968. .probe = sh_mmcif_probe,
  969. .remove = sh_mmcif_remove,
  970. .driver = {
  971. .name = DRIVER_NAME,
  972. },
  973. };
  974. static int __init sh_mmcif_init(void)
  975. {
  976. return platform_driver_register(&sh_mmcif_driver);
  977. }
  978. static void __exit sh_mmcif_exit(void)
  979. {
  980. platform_driver_unregister(&sh_mmcif_driver);
  981. }
  982. module_init(sh_mmcif_init);
  983. module_exit(sh_mmcif_exit);
  984. MODULE_DESCRIPTION("SuperH on-chip MMC/eMMC interface driver");
  985. MODULE_LICENSE("GPL");
  986. MODULE_ALIAS("platform:" DRIVER_NAME);
  987. MODULE_AUTHOR("Yusuke Goda <yusuke.goda.sx@renesas.com>");