sh_mmcif.c 29 KB

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