sh_mmcif.c 29 KB

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