ftsdc010_esdhc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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. debug("%s: size: %08x\n", __func__, size);
  82. if (status & FTSDC010_STATUS_FIFO_ORUN) {
  83. debug("%s: FIFO OVERRUN: sta: %08x\n",
  84. __func__, status);
  85. fifo = host->fifo_len > size ?
  86. size : host->fifo_len;
  87. size -= fifo;
  88. fifo_words = fifo >> 2;
  89. while (fifo_words--)
  90. *ptr++ = readl(&host->reg->dwr);
  91. /*
  92. * for adding some delays for SD card to put
  93. * data into FIFO again
  94. */
  95. udelay(4*FTSDC010_DELAY_UNIT);
  96. #ifdef CONFIG_FTSDC010_SDIO
  97. /* sdio allow non-power-of-2 blksz */
  98. if (fifo & 3) {
  99. unsigned int n = fifo & 3;
  100. unsigned int data = readl(&host->reg->dwr);
  101. unsigned char *p = (unsigned char *)ptr;
  102. while (n--) {
  103. *p++ = data;
  104. data >>= 8;
  105. }
  106. }
  107. #endif
  108. } else {
  109. udelay(1);
  110. if (++retry >= FTSDC010_PIO_RETRY) {
  111. debug("%s: PIO_RETRY timeout\n", __func__);
  112. return;
  113. }
  114. }
  115. }
  116. }
  117. static void ftsdc010_pio_write(struct mmc_host *host, const char *buf,
  118. unsigned int size)
  119. {
  120. unsigned int fifo;
  121. unsigned int *ptr;
  122. unsigned int status;
  123. unsigned int retry = 0;
  124. /* get data buffer */
  125. ptr = (unsigned int *)buf;
  126. while (size) {
  127. status = readl(&host->reg->status);
  128. if (status & FTSDC010_STATUS_FIFO_URUN) {
  129. fifo = host->fifo_len > size ?
  130. size : host->fifo_len;
  131. size -= fifo;
  132. fifo = (fifo + 3) >> 2;
  133. while (fifo--) {
  134. writel(*ptr, &host->reg->dwr);
  135. ptr++;
  136. }
  137. } else {
  138. udelay(1);
  139. if (++retry >= FTSDC010_PIO_RETRY) {
  140. debug("%s: PIO_RETRY timeout\n", __func__);
  141. return;
  142. }
  143. }
  144. }
  145. }
  146. static int ftsdc010_check_rsp(struct mmc *mmc, struct mmc_cmd *cmd,
  147. struct mmc_data *data)
  148. {
  149. struct mmc_host *host = mmc->priv;
  150. unsigned int sta, clear;
  151. sta = readl(&host->reg->status);
  152. debug("%s: sta: %08x cmd %d\n", __func__, sta, cmd->cmdidx);
  153. /* check RSP TIMEOUT or FAIL */
  154. if (sta & FTSDC010_STATUS_RSP_TIMEOUT) {
  155. /* RSP TIMEOUT */
  156. debug("%s: RSP timeout: sta: %08x\n", __func__, sta);
  157. clear |= FTSDC010_CLR_RSP_TIMEOUT;
  158. writel(clear, &host->reg->clr);
  159. return TIMEOUT;
  160. } else if (sta & FTSDC010_STATUS_RSP_CRC_FAIL) {
  161. /* clear response fail bit */
  162. debug("%s: RSP CRC FAIL: sta: %08x\n", __func__, sta);
  163. clear |= FTSDC010_CLR_RSP_CRC_FAIL;
  164. writel(clear, &host->reg->clr);
  165. return COMM_ERR;
  166. } else if (sta & FTSDC010_STATUS_RSP_CRC_OK) {
  167. /* clear response CRC OK bit */
  168. clear |= FTSDC010_CLR_RSP_CRC_OK;
  169. }
  170. writel(clear, &host->reg->clr);
  171. return 0;
  172. }
  173. static int ftsdc010_check_data(struct mmc *mmc, struct mmc_cmd *cmd,
  174. struct mmc_data *data)
  175. {
  176. struct mmc_host *host = mmc->priv;
  177. unsigned int sta, clear;
  178. sta = readl(&host->reg->status);
  179. debug("%s: sta: %08x cmd %d\n", __func__, sta, cmd->cmdidx);
  180. /* check DATA TIMEOUT or FAIL */
  181. if (data) {
  182. /* Transfer Complete */
  183. if (sta & FTSDC010_STATUS_DATA_END)
  184. clear |= FTSDC010_STATUS_DATA_END;
  185. /* Data CRC_OK */
  186. if (sta & FTSDC010_STATUS_DATA_CRC_OK)
  187. clear |= FTSDC010_STATUS_DATA_CRC_OK;
  188. /* DATA TIMEOUT or DATA CRC FAIL */
  189. if (sta & FTSDC010_STATUS_DATA_TIMEOUT) {
  190. /* DATA TIMEOUT */
  191. debug("%s: DATA TIMEOUT: sta: %08x\n", __func__, sta);
  192. clear |= FTSDC010_STATUS_DATA_TIMEOUT;
  193. writel(clear, &host->reg->clr);
  194. return TIMEOUT;
  195. } else if (sta & FTSDC010_STATUS_DATA_CRC_FAIL) {
  196. /* DATA CRC FAIL */
  197. debug("%s: DATA CRC FAIL: sta: %08x\n", __func__, sta);
  198. clear |= FTSDC010_STATUS_DATA_CRC_FAIL;
  199. writel(clear, &host->reg->clr);
  200. return COMM_ERR;
  201. }
  202. writel(clear, &host->reg->clr);
  203. }
  204. return 0;
  205. }
  206. static int ftsdc010_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
  207. struct mmc_data *data)
  208. {
  209. struct mmc_host *host = mmc->priv;
  210. #ifdef CONFIG_FTSDC010_SDIO
  211. unsigned int scon;
  212. #endif
  213. unsigned int ccon;
  214. unsigned int mask, tmpmask;
  215. unsigned int ret;
  216. unsigned int sta, i;
  217. ret = 0;
  218. if (data)
  219. mask = FTSDC010_INT_MASK_RSP_TIMEOUT;
  220. else if (cmd->resp_type & MMC_RSP_PRESENT)
  221. mask = FTSDC010_INT_MASK_RSP_TIMEOUT;
  222. else
  223. mask = FTSDC010_INT_MASK_CMD_SEND;
  224. /* write argu reg */
  225. debug("%s: argu: %08x\n", __func__, host->reg->argu);
  226. writel(cmd->cmdarg, &host->reg->argu);
  227. /* setup commnad */
  228. ccon = FTSDC010_CMD_IDX(cmd->cmdidx);
  229. /* setup command flags */
  230. ccon |= FTSDC010_CMD_CMD_EN;
  231. /*
  232. * This hardware didn't support specific commands for mapping
  233. * MMC_RSP_BUSY and MMC_RSP_OPCODE. Hence we don't deal with it.
  234. */
  235. if (cmd->resp_type & MMC_RSP_PRESENT) {
  236. ccon |= FTSDC010_CMD_NEED_RSP;
  237. mask |= FTSDC010_INT_MASK_RSP_CRC_OK |
  238. FTSDC010_INT_MASK_RSP_CRC_FAIL;
  239. }
  240. if (cmd->resp_type & MMC_RSP_136)
  241. ccon |= FTSDC010_CMD_LONG_RSP;
  242. /* In Linux driver, MMC_CMD_APP_CMD is checked in last_opcode */
  243. if (host->last_opcode == MMC_CMD_APP_CMD)
  244. ccon |= FTSDC010_CMD_APP_CMD;
  245. #ifdef CONFIG_FTSDC010_SDIO
  246. scon = readl(&host->reg->sdio_ctrl1);
  247. if (host->card_type == MMC_TYPE_SDIO)
  248. scon |= FTSDC010_SDIO_CTRL1_SDIO_ENABLE;
  249. else
  250. scon &= ~FTSDC010_SDIO_CTRL1_SDIO_ENABLE;
  251. writel(scon, &host->reg->sdio_ctrl1);
  252. #endif
  253. /* record last opcode for specifing the command type to hardware */
  254. host->last_opcode = cmd->cmdidx;
  255. /* write int_mask reg */
  256. tmpmask = readl(&host->reg->int_mask);
  257. tmpmask |= mask;
  258. writel(tmpmask, &host->reg->int_mask);
  259. /* write cmd reg */
  260. debug("%s: ccon: %08x\n", __func__, ccon);
  261. writel(ccon, &host->reg->cmd);
  262. /* check CMD_SEND */
  263. for (i = 0; i < FTSDC010_CMD_RETRY; i++) {
  264. /*
  265. * If we read status register too fast
  266. * will lead hardware error and the RSP_TIMEOUT
  267. * flag will be raised incorrectly.
  268. */
  269. udelay(16*FTSDC010_DELAY_UNIT);
  270. sta = readl(&host->reg->status);
  271. /* Command Complete */
  272. /*
  273. * Note:
  274. * Do not clear FTSDC010_CLR_CMD_SEND flag.
  275. * (by writing FTSDC010_CLR_CMD_SEND bit to clear register)
  276. * It will make the driver becomes very slow.
  277. * If the operation hasn't been finished, hardware will
  278. * clear this bit automatically.
  279. * In origin, the driver will clear this flag if there is
  280. * no data need to be read.
  281. */
  282. if (sta & FTSDC010_STATUS_CMD_SEND)
  283. break;
  284. }
  285. if (i > FTSDC010_CMD_RETRY) {
  286. printf("%s: send command timeout\n", __func__);
  287. return TIMEOUT;
  288. }
  289. /* check rsp status */
  290. ret = ftsdc010_check_rsp(mmc, cmd, data);
  291. if (ret)
  292. return ret;
  293. /* read response if we have RSP_OK */
  294. if (ccon & FTSDC010_CMD_LONG_RSP) {
  295. cmd->response[0] = readl(&host->reg->rsp3);
  296. cmd->response[1] = readl(&host->reg->rsp2);
  297. cmd->response[2] = readl(&host->reg->rsp1);
  298. cmd->response[3] = readl(&host->reg->rsp0);
  299. } else {
  300. cmd->response[0] = readl(&host->reg->rsp0);
  301. }
  302. /* read/write data */
  303. if (data && (data->flags & MMC_DATA_READ)) {
  304. ftsdc010_pio_read(host, data->dest,
  305. data->blocksize * data->blocks);
  306. } else if (data && (data->flags & MMC_DATA_WRITE)) {
  307. ftsdc010_pio_write(host, data->src,
  308. data->blocksize * data->blocks);
  309. }
  310. /* check data status */
  311. if (data) {
  312. ret = ftsdc010_check_data(mmc, cmd, data);
  313. if (ret)
  314. return ret;
  315. }
  316. udelay(FTSDC010_DELAY_UNIT);
  317. return ret;
  318. }
  319. static unsigned int cal_blksz(unsigned int blksz)
  320. {
  321. unsigned int blksztwo = 0;
  322. while (blksz >>= 1)
  323. blksztwo++;
  324. return blksztwo;
  325. }
  326. static int ftsdc010_setup_data(struct mmc *mmc, struct mmc_data *data)
  327. {
  328. struct mmc_host *host = mmc->priv;
  329. unsigned int dcon, newmask;
  330. /* configure data transfer paramter */
  331. if (!data)
  332. return 0;
  333. if (((data->blocksize - 1) & data->blocksize) != 0) {
  334. printf("%s: can't do non-power-of 2 sized block transfers"
  335. " (blksz %d)\n", __func__, data->blocksize);
  336. return -1;
  337. }
  338. /*
  339. * We cannot deal with unaligned blocks with more than
  340. * one block being transfered.
  341. */
  342. if ((data->blocksize <= 2) && (data->blocks > 1)) {
  343. printf("%s: can't do non-word sized block transfers"
  344. " (blksz %d)\n", __func__, data->blocksize);
  345. return -1;
  346. }
  347. /* data length */
  348. dcon = data->blocksize * data->blocks;
  349. writel(dcon, &host->reg->dlr);
  350. /* write data control */
  351. dcon = cal_blksz(data->blocksize);
  352. /* add to IMASK register */
  353. newmask = (FTSDC010_STATUS_RSP_CRC_FAIL | FTSDC010_STATUS_DATA_TIMEOUT);
  354. /*
  355. * enable UNDERRUN will trigger interrupt immediatedly
  356. * So setup it when rsp is received successfully
  357. */
  358. if (data->flags & MMC_DATA_WRITE) {
  359. dcon |= FTSDC010_DCR_DATA_WRITE;
  360. } else {
  361. dcon &= ~FTSDC010_DCR_DATA_WRITE;
  362. newmask |= FTSDC010_STATUS_FIFO_ORUN;
  363. }
  364. enable_imask(host->reg, newmask);
  365. #ifdef CONFIG_FTSDC010_SDIO
  366. /* always reset fifo since last transfer may fail */
  367. dcon |= FTSDC010_DCR_FIFO_RST;
  368. if (data->blocks > 1)
  369. dcon |= FTSDC010_SDIO_CTRL1_SDIO_BLK_MODE;
  370. #endif
  371. /* enable data transfer which will be pended until cmd is send */
  372. dcon |= FTSDC010_DCR_DATA_EN;
  373. writel(dcon, &host->reg->dcr);
  374. return 0;
  375. }
  376. static int ftsdc010_send_request(struct mmc *mmc, struct mmc_cmd *cmd,
  377. struct mmc_data *data)
  378. {
  379. int ret;
  380. if (data) {
  381. ret = ftsdc010_setup_data(mmc, data);
  382. if (ret) {
  383. printf("%s: setup data error\n", __func__);
  384. return -1;
  385. }
  386. if ((data->flags & MMC_DATA_BOTH_DIR) == MMC_DATA_BOTH_DIR) {
  387. printf("%s: data is both direction\n", __func__);
  388. return -1;
  389. }
  390. }
  391. /* Send command */
  392. ret = ftsdc010_send_cmd(mmc, cmd, data);
  393. return ret;
  394. }
  395. static int ftsdc010_card_detect(struct mmc *mmc)
  396. {
  397. struct mmc_host *host = mmc->priv;
  398. unsigned int sta;
  399. sta = readl(&host->reg->status);
  400. debug("%s: card status: %08x\n", __func__, sta);
  401. return (sta & FTSDC010_STATUS_CARD_DETECT) ? 0 : 1;
  402. }
  403. static int ftsdc010_request(struct mmc *mmc, struct mmc_cmd *cmd,
  404. struct mmc_data *data)
  405. {
  406. int ret;
  407. if (ftsdc010_card_detect(mmc) == 0) {
  408. printf("%s: no medium present\n", __func__);
  409. return -1;
  410. } else {
  411. ret = ftsdc010_send_request(mmc, cmd, data);
  412. return ret;
  413. }
  414. }
  415. static void ftsdc010_set_clk(struct mmc *mmc)
  416. {
  417. struct mmc_host *host = mmc->priv;
  418. unsigned char clk_div;
  419. unsigned int real_rate;
  420. unsigned int clock;
  421. debug("%s: mmc_set_clock: %x\n", __func__, mmc->clock);
  422. clock = readl(&host->reg->ccr);
  423. if (mmc->clock == 0) {
  424. real_rate = 0;
  425. clock |= FTSDC010_CCR_CLK_DIS;
  426. } else {
  427. debug("%s, mmc->clock: %08x, origin clock: %08x\n",
  428. __func__, mmc->clock, clock);
  429. for (clk_div = 0; clk_div <= 127; clk_div++) {
  430. real_rate = (CONFIG_SYS_CLK_FREQ / 2) /
  431. (2 * (clk_div + 1));
  432. if (real_rate <= mmc->clock)
  433. break;
  434. }
  435. debug("%s: computed real_rate: %x, clk_div: %x\n",
  436. __func__, real_rate, clk_div);
  437. if (clk_div > 127)
  438. debug("%s: no match clock rate, %x\n",
  439. __func__, mmc->clock);
  440. clock = (clock & ~FTSDC010_CCR_CLK_DIV(0x7f)) |
  441. FTSDC010_CCR_CLK_DIV(clk_div);
  442. clock &= ~FTSDC010_CCR_CLK_DIS;
  443. }
  444. debug("%s, set clock: %08x\n", __func__, clock);
  445. writel(clock, &host->reg->ccr);
  446. }
  447. static void ftsdc010_set_ios(struct mmc *mmc)
  448. {
  449. struct mmc_host *host = mmc->priv;
  450. unsigned int power;
  451. unsigned long val;
  452. unsigned int bus_width;
  453. debug("%s: bus_width: %x, clock: %d\n",
  454. __func__, mmc->bus_width, mmc->clock);
  455. /* set pcr: power on */
  456. power = readl(&host->reg->pcr);
  457. power |= FTSDC010_PCR_POWER_ON;
  458. writel(power, &host->reg->pcr);
  459. if (mmc->clock)
  460. ftsdc010_set_clk(mmc);
  461. /* set bwr: bus width reg */
  462. bus_width = readl(&host->reg->bwr);
  463. bus_width &= ~(FTSDC010_BWR_WIDE_8_BUS | FTSDC010_BWR_WIDE_4_BUS |
  464. FTSDC010_BWR_SINGLE_BUS);
  465. if (mmc->bus_width == 8)
  466. bus_width |= FTSDC010_BWR_WIDE_8_BUS;
  467. else if (mmc->bus_width == 4)
  468. bus_width |= FTSDC010_BWR_WIDE_4_BUS;
  469. else
  470. bus_width |= FTSDC010_BWR_SINGLE_BUS;
  471. writel(bus_width, &host->reg->bwr);
  472. /* set fifo depth */
  473. val = readl(&host->reg->feature);
  474. host->fifo_len = FTSDC010_FEATURE_FIFO_DEPTH(val) * 4; /* 4 bytes */
  475. /* set data timeout register */
  476. val = -1;
  477. writel(val, &host->reg->dtr);
  478. }
  479. static void ftsdc010_reset(struct mmc_host *host)
  480. {
  481. unsigned int timeout;
  482. unsigned int sta;
  483. /* Do SDC_RST: Software reset for all register */
  484. writel(FTSDC010_CMD_SDC_RST, &host->reg->cmd);
  485. host->clock = 0;
  486. /* this hardware has no reset finish flag to read */
  487. /* wait 100ms maximum */
  488. timeout = 100;
  489. /* hw clears the bit when it's done */
  490. while (readl(&host->reg->dtr) != 0) {
  491. if (timeout == 0) {
  492. printf("%s: reset timeout error\n", __func__);
  493. return;
  494. }
  495. timeout--;
  496. udelay(10*FTSDC010_DELAY_UNIT);
  497. }
  498. sta = readl(&host->reg->status);
  499. if (sta & FTSDC010_STATUS_CARD_CHANGE)
  500. writel(FTSDC010_CLR_CARD_CHANGE, &host->reg->clr);
  501. }
  502. static int ftsdc010_core_init(struct mmc *mmc)
  503. {
  504. struct mmc_host *host = mmc->priv;
  505. unsigned int mask;
  506. unsigned int major, minor, revision;
  507. /* get hardware version */
  508. host->version = readl(&host->reg->rev);
  509. major = FTSDC010_REV_MAJOR(host->version);
  510. minor = FTSDC010_REV_MINOR(host->version);
  511. revision = FTSDC010_REV_REVISION(host->version);
  512. printf("ftsdc010 hardware ver: %d_%d_r%d\n", major, minor, revision);
  513. /* Interrupt MASK register init - mask all */
  514. writel(0x0, &host->reg->int_mask);
  515. mask = FTSDC010_INT_MASK_CMD_SEND |
  516. FTSDC010_INT_MASK_DATA_END |
  517. FTSDC010_INT_MASK_CARD_CHANGE;
  518. #ifdef CONFIG_FTSDC010_SDIO
  519. mask |= FTSDC010_INT_MASK_CP_READY |
  520. FTSDC010_INT_MASK_CP_BUF_READY |
  521. FTSDC010_INT_MASK_PLAIN_TEXT_READY |
  522. FTSDC010_INT_MASK_SDIO_IRPT;
  523. #endif
  524. writel(mask, &host->reg->int_mask);
  525. return 0;
  526. }
  527. int ftsdc010_mmc_init(int dev_index)
  528. {
  529. struct mmc *mmc;
  530. struct mmc_host *host;
  531. mmc = &ftsdc010_dev[dev_index];
  532. sprintf(mmc->name, "FTSDC010 SD/MMC");
  533. mmc->priv = &ftsdc010_host[dev_index];
  534. mmc->send_cmd = ftsdc010_request;
  535. mmc->set_ios = ftsdc010_set_ios;
  536. mmc->init = ftsdc010_core_init;
  537. mmc->getcd = NULL;
  538. mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
  539. mmc->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT;
  540. mmc->f_min = CONFIG_SYS_CLK_FREQ / 2 / (2*128);
  541. mmc->f_max = CONFIG_SYS_CLK_FREQ / 2 / 2;
  542. ftsdc010_host[dev_index].clock = 0;
  543. ftsdc010_host[dev_index].reg = ftsdc010_get_base_mmc(dev_index);
  544. mmc_register(mmc);
  545. /* reset mmc */
  546. host = (struct mmc_host *)mmc->priv;
  547. ftsdc010_reset(host);
  548. return 0;
  549. }