ftsdc010_esdhc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /*
  2. * Copyright (C) 2011 Andes Technology Corporation
  3. * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <config.h>
  24. #include <common.h>
  25. #include <mmc.h>
  26. #include <asm/io.h>
  27. #include <faraday/ftsdc010.h>
  28. /*
  29. * supported mmc hosts
  30. * setting the number CONFIG_FTSDC010_NUMBER in your configuration file.
  31. */
  32. static struct mmc ftsdc010_dev[CONFIG_FTSDC010_NUMBER];
  33. static struct mmc_host ftsdc010_host[CONFIG_FTSDC010_NUMBER];
  34. static struct ftsdc010_mmc *ftsdc010_get_base_mmc(int dev_index)
  35. {
  36. return (struct ftsdc010_mmc *)CONFIG_FTSDC010_BASE + dev_index;
  37. }
  38. #ifdef DEBUG
  39. static void ftsdc010_dump_reg(struct mmc_host *host)
  40. {
  41. debug("cmd: %08x\n", readl(&host->reg->cmd));
  42. debug("argu: %08x\n", readl(&host->reg->argu));
  43. debug("rsp0: %08x\n", readl(&host->reg->rsp0));
  44. debug("rsp1: %08x\n", readl(&host->reg->rsp1));
  45. debug("rsp2: %08x\n", readl(&host->reg->rsp2));
  46. debug("rsp3: %08x\n", readl(&host->reg->rsp3));
  47. debug("rsp_cmd: %08x\n", readl(&host->reg->rsp_cmd));
  48. debug("dcr: %08x\n", readl(&host->reg->dcr));
  49. debug("dtr: %08x\n", readl(&host->reg->dtr));
  50. debug("dlr: %08x\n", readl(&host->reg->dlr));
  51. debug("status: %08x\n", readl(&host->reg->status));
  52. debug("clr: %08x\n", readl(&host->reg->clr));
  53. debug("int_mask: %08x\n", readl(&host->reg->int_mask));
  54. debug("pcr: %08x\n", readl(&host->reg->pcr));
  55. debug("ccr: %08x\n", readl(&host->reg->ccr));
  56. debug("bwr: %08x\n", readl(&host->reg->bwr));
  57. debug("dwr: %08x\n", readl(&host->reg->dwr));
  58. debug("feature: %08x\n", readl(&host->reg->feature));
  59. debug("rev: %08x\n", readl(&host->reg->rev));
  60. }
  61. #endif
  62. static unsigned int enable_imask(struct ftsdc010_mmc *reg, unsigned int imask)
  63. {
  64. unsigned int newmask;
  65. newmask = readl(&reg->int_mask);
  66. newmask |= imask;
  67. writel(newmask, &reg->int_mask);
  68. return newmask;
  69. }
  70. static void ftsdc010_pio_read(struct mmc_host *host, char *buf, unsigned int size)
  71. {
  72. unsigned int fifo;
  73. unsigned int fifo_words;
  74. unsigned int *ptr;
  75. unsigned int status;
  76. unsigned int retry = 0;
  77. /* get_data_buffer */
  78. ptr = (unsigned int *)buf;
  79. while (size) {
  80. status = readl(&host->reg->status);
  81. if (status & FTSDC010_STATUS_FIFO_ORUN) {
  82. fifo = host->fifo_len > size ?
  83. size : host->fifo_len;
  84. size -= fifo;
  85. fifo_words = fifo >> 2;
  86. while (fifo_words--)
  87. *ptr++ = readl(&host->reg->dwr);
  88. /*
  89. * for adding some delays for SD card to put
  90. * data into FIFO again
  91. */
  92. udelay(4*FTSDC010_DELAY_UNIT);
  93. #ifdef CONFIG_FTSDC010_SDIO
  94. /* sdio allow non-power-of-2 blksz */
  95. if (fifo & 3) {
  96. unsigned int n = fifo & 3;
  97. unsigned int data = readl(&host->reg->dwr);
  98. unsigned char *p = (unsigned char *)ptr;
  99. while (n--) {
  100. *p++ = data;
  101. data >>= 8;
  102. }
  103. }
  104. #endif
  105. } else {
  106. udelay(1);
  107. if (++retry >= FTSDC010_PIO_RETRY) {
  108. debug("%s: PIO_RETRY timeout\n", __func__);
  109. return;
  110. }
  111. }
  112. }
  113. }
  114. static void ftsdc010_pio_write(struct mmc_host *host, const char *buf,
  115. unsigned int size)
  116. {
  117. unsigned int fifo;
  118. unsigned int *ptr;
  119. unsigned int status;
  120. unsigned int retry = 0;
  121. /* get data buffer */
  122. ptr = (unsigned int *)buf;
  123. while (size) {
  124. status = readl(&host->reg->status);
  125. if (status & FTSDC010_STATUS_FIFO_ORUN) {
  126. fifo = host->fifo_len > size ?
  127. size : host->fifo_len;
  128. size -= fifo;
  129. fifo = (fifo + 3) >> 2;
  130. while (fifo--) {
  131. writel(*ptr, &host->reg->dwr);
  132. ptr++;
  133. }
  134. } else {
  135. udelay(1);
  136. if (++retry >= FTSDC010_PIO_RETRY) {
  137. debug("%s: PIO_RETRY timeout\n", __func__);
  138. return;
  139. }
  140. }
  141. }
  142. }
  143. static int ftsdc010_pio_check_status(struct mmc *mmc, struct mmc_cmd *cmd,
  144. struct mmc_data *data)
  145. {
  146. struct mmc_host *host = mmc->priv;
  147. unsigned int sta, clear;
  148. unsigned int i;
  149. /* check response and hardware status */
  150. clear = 0;
  151. /* chech CMD_SEND */
  152. for (i = 0; i < FTSDC010_CMD_RETRY; i++) {
  153. sta = readl(&host->reg->status);
  154. /* Command Complete */
  155. if (sta & FTSDC010_STATUS_CMD_SEND) {
  156. if (!data)
  157. clear |= FTSDC010_CLR_CMD_SEND;
  158. break;
  159. }
  160. }
  161. if (i > FTSDC010_CMD_RETRY) {
  162. printf("%s: send command timeout\n", __func__);
  163. return TIMEOUT;
  164. }
  165. /* debug: print status register and command index*/
  166. debug("sta: %08x cmd %d\n", sta, cmd->cmdidx);
  167. /* handle data FIFO */
  168. if ((sta & FTSDC010_STATUS_FIFO_ORUN) ||
  169. (sta & FTSDC010_STATUS_FIFO_URUN)) {
  170. /* Wrong DATA FIFO Flag */
  171. if (data == NULL)
  172. printf("%s, data fifo wrong: sta: %08x cmd %d\n",
  173. __func__, sta, cmd->cmdidx);
  174. if (sta & FTSDC010_STATUS_FIFO_ORUN)
  175. clear |= FTSDC010_STATUS_FIFO_ORUN;
  176. if (sta & FTSDC010_STATUS_FIFO_URUN)
  177. clear |= FTSDC010_STATUS_FIFO_URUN;
  178. }
  179. /* check RSP TIMEOUT or FAIL */
  180. if (sta & FTSDC010_STATUS_RSP_TIMEOUT) {
  181. /* RSP TIMEOUT */
  182. debug("%s: RSP timeout: sta: %08x cmd %d\n",
  183. __func__, sta, cmd->cmdidx);
  184. clear |= FTSDC010_CLR_RSP_TIMEOUT;
  185. writel(clear, &host->reg->clr);
  186. return TIMEOUT;
  187. } else if (sta & FTSDC010_STATUS_RSP_CRC_FAIL) {
  188. /* clear response fail bit */
  189. debug("%s: RSP CRC FAIL: sta: %08x cmd %d\n",
  190. __func__, sta, cmd->cmdidx);
  191. clear |= FTSDC010_CLR_RSP_CRC_FAIL;
  192. writel(clear, &host->reg->clr);
  193. return 0;
  194. } else if (sta & FTSDC010_STATUS_RSP_CRC_OK) {
  195. /* clear response CRC OK bit */
  196. clear |= FTSDC010_CLR_RSP_CRC_OK;
  197. }
  198. /* check DATA TIMEOUT or FAIL */
  199. if (data) {
  200. if (sta & FTSDC010_STATUS_DATA_TIMEOUT) {
  201. /* DATA TIMEOUT */
  202. debug("%s: DATA TIMEOUT: sta: %08x\n",
  203. __func__, sta);
  204. clear |= FTSDC010_STATUS_DATA_TIMEOUT;
  205. writel(sta, &host->reg->clr);
  206. return TIMEOUT;
  207. } else if (sta & FTSDC010_STATUS_DATA_CRC_FAIL) {
  208. /* Error Interrupt */
  209. debug("%s: DATA CRC FAIL: sta: %08x\n",
  210. __func__, sta);
  211. clear |= FTSDC010_STATUS_DATA_CRC_FAIL;
  212. writel(clear, &host->reg->clr);
  213. return 0;
  214. } else if (sta & FTSDC010_STATUS_DATA_END) {
  215. /* Transfer Complete */
  216. clear |= FTSDC010_STATUS_DATA_END;
  217. }
  218. }
  219. /* transaction is success and clear status register */
  220. writel(clear, &host->reg->clr);
  221. return 0;
  222. }
  223. static int ftsdc010_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
  224. struct mmc_data *data)
  225. {
  226. struct mmc_host *host = mmc->priv;
  227. #ifdef CONFIG_FTSDC010_SDIO
  228. unsigned int scon;
  229. #endif
  230. unsigned int ccon;
  231. unsigned int mask, tmpmask;
  232. unsigned int ret;
  233. if (data)
  234. mask = FTSDC010_INT_MASK_RSP_TIMEOUT;
  235. else if (cmd->resp_type & MMC_RSP_PRESENT)
  236. mask = FTSDC010_INT_MASK_RSP_TIMEOUT;
  237. else
  238. mask = FTSDC010_INT_MASK_CMD_SEND;
  239. /* write argu reg */
  240. debug("%s: cmd->arg: %08x\n", __func__, cmd->cmdarg);
  241. writel(cmd->cmdarg, &host->reg->argu);
  242. /* setup cmd reg */
  243. debug("cmd: %d\n", cmd->cmdidx);
  244. debug("resp: %08x\n", cmd->resp_type);
  245. /* setup commnad */
  246. ccon = FTSDC010_CMD_IDX(cmd->cmdidx);
  247. /* setup command flags */
  248. ccon |= FTSDC010_CMD_CMD_EN;
  249. /*
  250. * This hardware didn't support specific commands for mapping
  251. * MMC_RSP_BUSY and MMC_RSP_OPCODE. Hence we don't deal with it.
  252. */
  253. if (cmd->resp_type & MMC_RSP_PRESENT) {
  254. ccon |= FTSDC010_CMD_NEED_RSP;
  255. mask |= FTSDC010_INT_MASK_RSP_CRC_OK |
  256. FTSDC010_INT_MASK_RSP_CRC_FAIL;
  257. }
  258. if (cmd->resp_type & MMC_RSP_136)
  259. ccon |= FTSDC010_CMD_LONG_RSP;
  260. /* In Linux driver, MMC_CMD_APP_CMD is checked in last_opcode */
  261. if (host->last_opcode == MMC_CMD_APP_CMD)
  262. ccon |= FTSDC010_CMD_APP_CMD;
  263. #ifdef CONFIG_FTSDC010_SDIO
  264. scon = readl(&host->reg->sdio_ctrl1);
  265. if (host->card_type == MMC_TYPE_SDIO)
  266. scon |= FTSDC010_SDIO_CTRL1_SDIO_ENABLE;
  267. else
  268. scon &= ~FTSDC010_SDIO_CTRL1_SDIO_ENABLE;
  269. writel(scon, &host->reg->sdio_ctrl1);
  270. #endif
  271. /* record last opcode for specifing the command type to hardware */
  272. host->last_opcode = cmd->cmdidx;
  273. /* write int_mask reg */
  274. tmpmask = readl(&host->reg->int_mask);
  275. tmpmask |= mask;
  276. writel(tmpmask, &host->reg->int_mask);
  277. /* write cmd reg */
  278. debug("%s: ccon: %08x\n", __func__, ccon);
  279. writel(ccon, &host->reg->cmd);
  280. udelay(4*FTSDC010_DELAY_UNIT);
  281. /* read/write data */
  282. if (data && (data->flags & MMC_DATA_READ)) {
  283. ftsdc010_pio_read(host, data->dest,
  284. data->blocksize * data->blocks);
  285. } else if (data && (data->flags & MMC_DATA_WRITE)) {
  286. ftsdc010_pio_write(host, data->src,
  287. data->blocksize * data->blocks);
  288. }
  289. /* pio check response status */
  290. ret = ftsdc010_pio_check_status(mmc, cmd, data);
  291. if (!ret) {
  292. /* if it is long response */
  293. if (ccon & FTSDC010_CMD_LONG_RSP) {
  294. cmd->response[0] = readl(&host->reg->rsp3);
  295. cmd->response[1] = readl(&host->reg->rsp2);
  296. cmd->response[2] = readl(&host->reg->rsp1);
  297. cmd->response[3] = readl(&host->reg->rsp0);
  298. } else {
  299. cmd->response[0] = readl(&host->reg->rsp0);
  300. }
  301. }
  302. udelay(FTSDC010_DELAY_UNIT);
  303. return ret;
  304. }
  305. static unsigned int cal_blksz(unsigned int blksz)
  306. {
  307. unsigned int blksztwo = 0;
  308. while (blksz >>= 1)
  309. blksztwo++;
  310. return blksztwo;
  311. }
  312. static int ftsdc010_setup_data(struct mmc *mmc, struct mmc_data *data)
  313. {
  314. struct mmc_host *host = mmc->priv;
  315. unsigned int dcon, newmask;
  316. /* configure data transfer paramter */
  317. if (!data)
  318. return 0;
  319. if (((data->blocksize - 1) & data->blocksize) != 0) {
  320. printf("%s: can't do non-power-of 2 sized block transfers"
  321. " (blksz %d)\n", __func__, data->blocksize);
  322. return -1;
  323. }
  324. /*
  325. * We cannot deal with unaligned blocks with more than
  326. * one block being transfered.
  327. */
  328. if ((data->blocksize <= 2) && (data->blocks > 1)) {
  329. printf("%s: can't do non-word sized block transfers"
  330. " (blksz %d)\n", __func__, data->blocksize);
  331. return -1;
  332. }
  333. /* data length */
  334. dcon = data->blocksize * data->blocks;
  335. writel(dcon, &host->reg->dlr);
  336. /* write data control */
  337. dcon = cal_blksz(data->blocksize);
  338. /* add to IMASK register */
  339. newmask = (FTSDC010_STATUS_RSP_CRC_FAIL | FTSDC010_STATUS_DATA_TIMEOUT);
  340. /*
  341. * enable UNDERRUN will trigger interrupt immediatedly
  342. * So setup it when rsp is received successfully
  343. */
  344. if (data->flags & MMC_DATA_WRITE) {
  345. dcon |= FTSDC010_DCR_DATA_WRITE;
  346. } else {
  347. dcon &= ~FTSDC010_DCR_DATA_WRITE;
  348. newmask |= FTSDC010_STATUS_FIFO_ORUN;
  349. }
  350. enable_imask(host->reg, newmask);
  351. #ifdef CONFIG_FTSDC010_SDIO
  352. /* always reset fifo since last transfer may fail */
  353. dcon |= FTSDC010_DCR_FIFO_RST;
  354. /* handle sdio */
  355. dcon = data->blocksize | data->blocks << 15;
  356. if (data->blocks > 1)
  357. dcon |= FTSDC010_SDIO_CTRL1_SDIO_BLK_MODE;
  358. #endif
  359. /* enable data transfer which will be pended until cmd is send */
  360. dcon |= FTSDC010_DCR_DATA_EN;
  361. writel(dcon, &host->reg->dcr);
  362. return 0;
  363. }
  364. static int ftsdc010_send_request(struct mmc *mmc, struct mmc_cmd *cmd,
  365. struct mmc_data *data)
  366. {
  367. int ret;
  368. if (data) {
  369. ret = ftsdc010_setup_data(mmc, data);
  370. if (ret) {
  371. printf("%s: setup data error\n", __func__);
  372. return -1;
  373. }
  374. if ((data->flags & MMC_DATA_BOTH_DIR) == MMC_DATA_BOTH_DIR) {
  375. printf("%s: data is both direction\n", __func__);
  376. return -1;
  377. }
  378. }
  379. /* Send command */
  380. ret = ftsdc010_send_cmd(mmc, cmd, data);
  381. return ret;
  382. }
  383. static int ftsdc010_card_detect(struct mmc *mmc)
  384. {
  385. struct mmc_host *host = mmc->priv;
  386. unsigned int sta;
  387. sta = readl(&host->reg->status);
  388. debug("%s: card status: %08x\n", __func__, sta);
  389. return (sta & FTSDC010_STATUS_CARD_DETECT) ? 0 : 1;
  390. }
  391. static int ftsdc010_request(struct mmc *mmc, struct mmc_cmd *cmd,
  392. struct mmc_data *data)
  393. {
  394. int ret;
  395. if (ftsdc010_card_detect(mmc) == 0) {
  396. printf("%s: no medium present\n", __func__);
  397. return -1;
  398. } else {
  399. ret = ftsdc010_send_request(mmc, cmd, data);
  400. return ret;
  401. }
  402. }
  403. static void ftsdc010_set_clk(struct mmc *mmc)
  404. {
  405. struct mmc_host *host = mmc->priv;
  406. unsigned char clk_div;
  407. unsigned char real_rate;
  408. unsigned int clock;
  409. debug("%s: mmc_set_clock: %x\n", __func__, mmc->clock);
  410. clock = readl(&host->reg->ccr);
  411. if (mmc->clock == 0) {
  412. real_rate = 0;
  413. clock |= FTSDC010_CCR_CLK_DIS;
  414. } else {
  415. debug("%s, mmc->clock: %08x, origin clock: %08x\n",
  416. __func__, mmc->clock, clock);
  417. for (clk_div = 0; clk_div <= 127; clk_div++) {
  418. real_rate = (CONFIG_SYS_CLK_FREQ / 2) /
  419. (2 * (clk_div + 1));
  420. if (real_rate <= mmc->clock)
  421. break;
  422. }
  423. debug("%s: computed real_rete: %x, clk_div: %x\n",
  424. __func__, real_rate, clk_div);
  425. if (clk_div > 127)
  426. debug("%s: no match clock rate, %x\n",
  427. __func__, mmc->clock);
  428. clock = (clock & ~FTSDC010_CCR_CLK_DIV(0x7f)) |
  429. FTSDC010_CCR_CLK_DIV(clk_div);
  430. clock &= ~FTSDC010_CCR_CLK_DIS;
  431. }
  432. debug("%s, set clock: %08x\n", __func__, clock);
  433. writel(clock, &host->reg->ccr);
  434. }
  435. static void ftsdc010_set_ios(struct mmc *mmc)
  436. {
  437. struct mmc_host *host = mmc->priv;
  438. unsigned int power;
  439. unsigned long val;
  440. unsigned int bus_width;
  441. debug("%s: bus_width: %x, clock: %d\n",
  442. __func__, mmc->bus_width, mmc->clock);
  443. /* set pcr: power on */
  444. power = readl(&host->reg->pcr);
  445. power |= FTSDC010_PCR_POWER_ON;
  446. writel(power, &host->reg->pcr);
  447. if (mmc->clock)
  448. ftsdc010_set_clk(mmc);
  449. /* set bwr: bus width reg */
  450. bus_width = readl(&host->reg->bwr);
  451. bus_width &= ~(FTSDC010_BWR_WIDE_8_BUS | FTSDC010_BWR_WIDE_4_BUS |
  452. FTSDC010_BWR_SINGLE_BUS);
  453. if (mmc->bus_width == 8)
  454. bus_width |= FTSDC010_BWR_WIDE_8_BUS;
  455. else if (mmc->bus_width == 4)
  456. bus_width |= FTSDC010_BWR_WIDE_4_BUS;
  457. else
  458. bus_width |= FTSDC010_BWR_SINGLE_BUS;
  459. writel(bus_width, &host->reg->bwr);
  460. /* set fifo depth */
  461. val = readl(&host->reg->feature);
  462. host->fifo_len = FTSDC010_FEATURE_FIFO_DEPTH(val) * 4; /* 4 bytes */
  463. /* set data timeout register */
  464. val = -1;
  465. writel(val, &host->reg->dtr);
  466. }
  467. static void ftsdc010_reset(struct mmc_host *host)
  468. {
  469. unsigned int timeout;
  470. /* Do SDC_RST: Software reset for all register */
  471. writel(FTSDC010_CMD_SDC_RST, &host->reg->cmd);
  472. host->clock = 0;
  473. /* this hardware has no reset finish flag to read */
  474. /* wait 100ms maximum */
  475. timeout = 100;
  476. /* hw clears the bit when it's done */
  477. while (readl(&host->reg->dtr) != 0) {
  478. if (timeout == 0) {
  479. printf("%s: reset timeout error\n", __func__);
  480. return;
  481. }
  482. timeout--;
  483. udelay(10*FTSDC010_DELAY_UNIT);
  484. }
  485. }
  486. static int ftsdc010_core_init(struct mmc *mmc)
  487. {
  488. struct mmc_host *host = mmc->priv;
  489. unsigned int mask;
  490. unsigned int major, minor, revision;
  491. /* get hardware version */
  492. host->version = readl(&host->reg->rev);
  493. major = FTSDC010_REV_MAJOR(host->version);
  494. minor = FTSDC010_REV_MINOR(host->version);
  495. revision = FTSDC010_REV_REVISION(host->version);
  496. printf("ftsdc010 hardware ver: %d_%d_r%d\n", major, minor, revision);
  497. /* Interrupt MASK register init - mask all */
  498. writel(0x0, &host->reg->int_mask);
  499. mask = FTSDC010_INT_MASK_CMD_SEND |
  500. FTSDC010_INT_MASK_DATA_END |
  501. FTSDC010_INT_MASK_CARD_CHANGE;
  502. #ifdef CONFIG_FTSDC010_SDIO
  503. mask |= FTSDC010_INT_MASK_CP_READY |
  504. FTSDC010_INT_MASK_CP_BUF_READY |
  505. FTSDC010_INT_MASK_PLAIN_TEXT_READY |
  506. FTSDC010_INT_MASK_SDIO_IRPT;
  507. #endif
  508. writel(mask, &host->reg->int_mask);
  509. return 0;
  510. }
  511. int ftsdc010_mmc_init(int dev_index)
  512. {
  513. struct mmc *mmc;
  514. struct mmc_host *host;
  515. mmc = &ftsdc010_dev[dev_index];
  516. sprintf(mmc->name, "FTSDC010 SD/MMC");
  517. mmc->priv = &ftsdc010_host[dev_index];
  518. mmc->send_cmd = ftsdc010_request;
  519. mmc->set_ios = ftsdc010_set_ios;
  520. mmc->init = ftsdc010_core_init;
  521. mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
  522. mmc->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT;
  523. mmc->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
  524. mmc->f_min = CONFIG_SYS_CLK_FREQ / 2 / (2*128);
  525. mmc->f_max = CONFIG_SYS_CLK_FREQ / 2 / 2;
  526. ftsdc010_host[dev_index].clock = 0;
  527. ftsdc010_host[dev_index].reg = ftsdc010_get_base_mmc(dev_index);
  528. mmc_register(mmc);
  529. /* reset mmc */
  530. host = (struct mmc_host *)mmc->priv;
  531. ftsdc010_reset(host);
  532. return 0;
  533. }