tegra_mmc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /*
  2. * (C) Copyright 2009 SAMSUNG Electronics
  3. * Minkyu Kang <mk7.kang@samsung.com>
  4. * Jaehoon Chung <jh80.chung@samsung.com>
  5. * Portions Copyright 2011-2013 NVIDIA Corporation
  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, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <bouncebuf.h>
  22. #include <common.h>
  23. #include <fdtdec.h>
  24. #include <asm/gpio.h>
  25. #include <asm/io.h>
  26. #include <asm/arch/clock.h>
  27. #include <asm/arch-tegra/clk_rst.h>
  28. #include <asm/arch-tegra/tegra_mmc.h>
  29. #include <mmc.h>
  30. DECLARE_GLOBAL_DATA_PTR;
  31. struct mmc mmc_dev[MAX_HOSTS];
  32. struct mmc_host mmc_host[MAX_HOSTS];
  33. #ifndef CONFIG_OF_CONTROL
  34. #error "Please enable device tree support to use this driver"
  35. #endif
  36. static void mmc_prepare_data(struct mmc_host *host, struct mmc_data *data,
  37. struct bounce_buffer *bbstate)
  38. {
  39. unsigned char ctrl;
  40. debug("buf: %p (%p), data->blocks: %u, data->blocksize: %u\n",
  41. bbstate->bounce_buffer, bbstate->user_buffer, data->blocks,
  42. data->blocksize);
  43. writel((u32)bbstate->bounce_buffer, &host->reg->sysad);
  44. /*
  45. * DMASEL[4:3]
  46. * 00 = Selects SDMA
  47. * 01 = Reserved
  48. * 10 = Selects 32-bit Address ADMA2
  49. * 11 = Selects 64-bit Address ADMA2
  50. */
  51. ctrl = readb(&host->reg->hostctl);
  52. ctrl &= ~TEGRA_MMC_HOSTCTL_DMASEL_MASK;
  53. ctrl |= TEGRA_MMC_HOSTCTL_DMASEL_SDMA;
  54. writeb(ctrl, &host->reg->hostctl);
  55. /* We do not handle DMA boundaries, so set it to max (512 KiB) */
  56. writew((7 << 12) | (data->blocksize & 0xFFF), &host->reg->blksize);
  57. writew(data->blocks, &host->reg->blkcnt);
  58. }
  59. static void mmc_set_transfer_mode(struct mmc_host *host, struct mmc_data *data)
  60. {
  61. unsigned short mode;
  62. debug(" mmc_set_transfer_mode called\n");
  63. /*
  64. * TRNMOD
  65. * MUL1SIN0[5] : Multi/Single Block Select
  66. * RD1WT0[4] : Data Transfer Direction Select
  67. * 1 = read
  68. * 0 = write
  69. * ENACMD12[2] : Auto CMD12 Enable
  70. * ENBLKCNT[1] : Block Count Enable
  71. * ENDMA[0] : DMA Enable
  72. */
  73. mode = (TEGRA_MMC_TRNMOD_DMA_ENABLE |
  74. TEGRA_MMC_TRNMOD_BLOCK_COUNT_ENABLE);
  75. if (data->blocks > 1)
  76. mode |= TEGRA_MMC_TRNMOD_MULTI_BLOCK_SELECT;
  77. if (data->flags & MMC_DATA_READ)
  78. mode |= TEGRA_MMC_TRNMOD_DATA_XFER_DIR_SEL_READ;
  79. writew(mode, &host->reg->trnmod);
  80. }
  81. static int mmc_wait_inhibit(struct mmc_host *host,
  82. struct mmc_cmd *cmd,
  83. struct mmc_data *data,
  84. unsigned int timeout)
  85. {
  86. /*
  87. * PRNSTS
  88. * CMDINHDAT[1] : Command Inhibit (DAT)
  89. * CMDINHCMD[0] : Command Inhibit (CMD)
  90. */
  91. unsigned int mask = TEGRA_MMC_PRNSTS_CMD_INHIBIT_CMD;
  92. /*
  93. * We shouldn't wait for data inhibit for stop commands, even
  94. * though they might use busy signaling
  95. */
  96. if ((data == NULL) && (cmd->resp_type & MMC_RSP_BUSY))
  97. mask |= TEGRA_MMC_PRNSTS_CMD_INHIBIT_DAT;
  98. while (readl(&host->reg->prnsts) & mask) {
  99. if (timeout == 0) {
  100. printf("%s: timeout error\n", __func__);
  101. return -1;
  102. }
  103. timeout--;
  104. udelay(1000);
  105. }
  106. return 0;
  107. }
  108. static int mmc_send_cmd_bounced(struct mmc *mmc, struct mmc_cmd *cmd,
  109. struct mmc_data *data, struct bounce_buffer *bbstate)
  110. {
  111. struct mmc_host *host = (struct mmc_host *)mmc->priv;
  112. int flags, i;
  113. int result;
  114. unsigned int mask = 0;
  115. unsigned int retry = 0x100000;
  116. debug(" mmc_send_cmd called\n");
  117. result = mmc_wait_inhibit(host, cmd, data, 10 /* ms */);
  118. if (result < 0)
  119. return result;
  120. if (data)
  121. mmc_prepare_data(host, data, bbstate);
  122. debug("cmd->arg: %08x\n", cmd->cmdarg);
  123. writel(cmd->cmdarg, &host->reg->argument);
  124. if (data)
  125. mmc_set_transfer_mode(host, data);
  126. if ((cmd->resp_type & MMC_RSP_136) && (cmd->resp_type & MMC_RSP_BUSY))
  127. return -1;
  128. /*
  129. * CMDREG
  130. * CMDIDX[13:8] : Command index
  131. * DATAPRNT[5] : Data Present Select
  132. * ENCMDIDX[4] : Command Index Check Enable
  133. * ENCMDCRC[3] : Command CRC Check Enable
  134. * RSPTYP[1:0]
  135. * 00 = No Response
  136. * 01 = Length 136
  137. * 10 = Length 48
  138. * 11 = Length 48 Check busy after response
  139. */
  140. if (!(cmd->resp_type & MMC_RSP_PRESENT))
  141. flags = TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_NO_RESPONSE;
  142. else if (cmd->resp_type & MMC_RSP_136)
  143. flags = TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_LENGTH_136;
  144. else if (cmd->resp_type & MMC_RSP_BUSY)
  145. flags = TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_LENGTH_48_BUSY;
  146. else
  147. flags = TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_LENGTH_48;
  148. if (cmd->resp_type & MMC_RSP_CRC)
  149. flags |= TEGRA_MMC_TRNMOD_CMD_CRC_CHECK;
  150. if (cmd->resp_type & MMC_RSP_OPCODE)
  151. flags |= TEGRA_MMC_TRNMOD_CMD_INDEX_CHECK;
  152. if (data)
  153. flags |= TEGRA_MMC_TRNMOD_DATA_PRESENT_SELECT_DATA_TRANSFER;
  154. debug("cmd: %d\n", cmd->cmdidx);
  155. writew((cmd->cmdidx << 8) | flags, &host->reg->cmdreg);
  156. for (i = 0; i < retry; i++) {
  157. mask = readl(&host->reg->norintsts);
  158. /* Command Complete */
  159. if (mask & TEGRA_MMC_NORINTSTS_CMD_COMPLETE) {
  160. if (!data)
  161. writel(mask, &host->reg->norintsts);
  162. break;
  163. }
  164. }
  165. if (i == retry) {
  166. printf("%s: waiting for status update\n", __func__);
  167. writel(mask, &host->reg->norintsts);
  168. return TIMEOUT;
  169. }
  170. if (mask & TEGRA_MMC_NORINTSTS_CMD_TIMEOUT) {
  171. /* Timeout Error */
  172. debug("timeout: %08x cmd %d\n", mask, cmd->cmdidx);
  173. writel(mask, &host->reg->norintsts);
  174. return TIMEOUT;
  175. } else if (mask & TEGRA_MMC_NORINTSTS_ERR_INTERRUPT) {
  176. /* Error Interrupt */
  177. debug("error: %08x cmd %d\n", mask, cmd->cmdidx);
  178. writel(mask, &host->reg->norintsts);
  179. return -1;
  180. }
  181. if (cmd->resp_type & MMC_RSP_PRESENT) {
  182. if (cmd->resp_type & MMC_RSP_136) {
  183. /* CRC is stripped so we need to do some shifting. */
  184. for (i = 0; i < 4; i++) {
  185. unsigned int offset =
  186. (unsigned int)(&host->reg->rspreg3 - i);
  187. cmd->response[i] = readl(offset) << 8;
  188. if (i != 3) {
  189. cmd->response[i] |=
  190. readb(offset - 1);
  191. }
  192. debug("cmd->resp[%d]: %08x\n",
  193. i, cmd->response[i]);
  194. }
  195. } else if (cmd->resp_type & MMC_RSP_BUSY) {
  196. for (i = 0; i < retry; i++) {
  197. /* PRNTDATA[23:20] : DAT[3:0] Line Signal */
  198. if (readl(&host->reg->prnsts)
  199. & (1 << 20)) /* DAT[0] */
  200. break;
  201. }
  202. if (i == retry) {
  203. printf("%s: card is still busy\n", __func__);
  204. writel(mask, &host->reg->norintsts);
  205. return TIMEOUT;
  206. }
  207. cmd->response[0] = readl(&host->reg->rspreg0);
  208. debug("cmd->resp[0]: %08x\n", cmd->response[0]);
  209. } else {
  210. cmd->response[0] = readl(&host->reg->rspreg0);
  211. debug("cmd->resp[0]: %08x\n", cmd->response[0]);
  212. }
  213. }
  214. if (data) {
  215. unsigned long start = get_timer(0);
  216. while (1) {
  217. mask = readl(&host->reg->norintsts);
  218. if (mask & TEGRA_MMC_NORINTSTS_ERR_INTERRUPT) {
  219. /* Error Interrupt */
  220. writel(mask, &host->reg->norintsts);
  221. printf("%s: error during transfer: 0x%08x\n",
  222. __func__, mask);
  223. return -1;
  224. } else if (mask & TEGRA_MMC_NORINTSTS_DMA_INTERRUPT) {
  225. /*
  226. * DMA Interrupt, restart the transfer where
  227. * it was interrupted.
  228. */
  229. unsigned int address = readl(&host->reg->sysad);
  230. debug("DMA end\n");
  231. writel(TEGRA_MMC_NORINTSTS_DMA_INTERRUPT,
  232. &host->reg->norintsts);
  233. writel(address, &host->reg->sysad);
  234. } else if (mask & TEGRA_MMC_NORINTSTS_XFER_COMPLETE) {
  235. /* Transfer Complete */
  236. debug("r/w is done\n");
  237. break;
  238. } else if (get_timer(start) > 2000UL) {
  239. writel(mask, &host->reg->norintsts);
  240. printf("%s: MMC Timeout\n"
  241. " Interrupt status 0x%08x\n"
  242. " Interrupt status enable 0x%08x\n"
  243. " Interrupt signal enable 0x%08x\n"
  244. " Present status 0x%08x\n",
  245. __func__, mask,
  246. readl(&host->reg->norintstsen),
  247. readl(&host->reg->norintsigen),
  248. readl(&host->reg->prnsts));
  249. return -1;
  250. }
  251. }
  252. writel(mask, &host->reg->norintsts);
  253. }
  254. udelay(1000);
  255. return 0;
  256. }
  257. static int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
  258. struct mmc_data *data)
  259. {
  260. void *buf;
  261. unsigned int bbflags;
  262. size_t len;
  263. struct bounce_buffer bbstate;
  264. int ret;
  265. if (data) {
  266. if (data->flags & MMC_DATA_READ) {
  267. buf = data->dest;
  268. bbflags = GEN_BB_WRITE;
  269. } else {
  270. buf = (void *)data->src;
  271. bbflags = GEN_BB_READ;
  272. }
  273. len = data->blocks * data->blocksize;
  274. bounce_buffer_start(&bbstate, buf, len, bbflags);
  275. }
  276. ret = mmc_send_cmd_bounced(mmc, cmd, data, &bbstate);
  277. if (data)
  278. bounce_buffer_stop(&bbstate);
  279. return ret;
  280. }
  281. static void mmc_change_clock(struct mmc_host *host, uint clock)
  282. {
  283. int div;
  284. unsigned short clk;
  285. unsigned long timeout;
  286. debug(" mmc_change_clock called\n");
  287. /*
  288. * Change Tegra SDMMCx clock divisor here. Source is 216MHz,
  289. * PLLP_OUT0
  290. */
  291. if (clock == 0)
  292. goto out;
  293. clock_adjust_periph_pll_div(host->mmc_id, CLOCK_ID_PERIPH, clock,
  294. &div);
  295. debug("div = %d\n", div);
  296. writew(0, &host->reg->clkcon);
  297. /*
  298. * CLKCON
  299. * SELFREQ[15:8] : base clock divided by value
  300. * ENSDCLK[2] : SD Clock Enable
  301. * STBLINTCLK[1] : Internal Clock Stable
  302. * ENINTCLK[0] : Internal Clock Enable
  303. */
  304. div >>= 1;
  305. clk = ((div << TEGRA_MMC_CLKCON_SDCLK_FREQ_SEL_SHIFT) |
  306. TEGRA_MMC_CLKCON_INTERNAL_CLOCK_ENABLE);
  307. writew(clk, &host->reg->clkcon);
  308. /* Wait max 10 ms */
  309. timeout = 10;
  310. while (!(readw(&host->reg->clkcon) &
  311. TEGRA_MMC_CLKCON_INTERNAL_CLOCK_STABLE)) {
  312. if (timeout == 0) {
  313. printf("%s: timeout error\n", __func__);
  314. return;
  315. }
  316. timeout--;
  317. udelay(1000);
  318. }
  319. clk |= TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE;
  320. writew(clk, &host->reg->clkcon);
  321. debug("mmc_change_clock: clkcon = %08X\n", clk);
  322. out:
  323. host->clock = clock;
  324. }
  325. static void mmc_set_ios(struct mmc *mmc)
  326. {
  327. struct mmc_host *host = mmc->priv;
  328. unsigned char ctrl;
  329. debug(" mmc_set_ios called\n");
  330. debug("bus_width: %x, clock: %d\n", mmc->bus_width, mmc->clock);
  331. /* Change clock first */
  332. mmc_change_clock(host, mmc->clock);
  333. ctrl = readb(&host->reg->hostctl);
  334. /*
  335. * WIDE8[5]
  336. * 0 = Depend on WIDE4
  337. * 1 = 8-bit mode
  338. * WIDE4[1]
  339. * 1 = 4-bit mode
  340. * 0 = 1-bit mode
  341. */
  342. if (mmc->bus_width == 8)
  343. ctrl |= (1 << 5);
  344. else if (mmc->bus_width == 4)
  345. ctrl |= (1 << 1);
  346. else
  347. ctrl &= ~(1 << 1);
  348. writeb(ctrl, &host->reg->hostctl);
  349. debug("mmc_set_ios: hostctl = %08X\n", ctrl);
  350. }
  351. static void mmc_reset(struct mmc_host *host)
  352. {
  353. unsigned int timeout;
  354. debug(" mmc_reset called\n");
  355. /*
  356. * RSTALL[0] : Software reset for all
  357. * 1 = reset
  358. * 0 = work
  359. */
  360. writeb(TEGRA_MMC_SWRST_SW_RESET_FOR_ALL, &host->reg->swrst);
  361. host->clock = 0;
  362. /* Wait max 100 ms */
  363. timeout = 100;
  364. /* hw clears the bit when it's done */
  365. while (readb(&host->reg->swrst) & TEGRA_MMC_SWRST_SW_RESET_FOR_ALL) {
  366. if (timeout == 0) {
  367. printf("%s: timeout error\n", __func__);
  368. return;
  369. }
  370. timeout--;
  371. udelay(1000);
  372. }
  373. }
  374. static int mmc_core_init(struct mmc *mmc)
  375. {
  376. struct mmc_host *host = (struct mmc_host *)mmc->priv;
  377. unsigned int mask;
  378. debug(" mmc_core_init called\n");
  379. mmc_reset(host);
  380. host->version = readw(&host->reg->hcver);
  381. debug("host version = %x\n", host->version);
  382. /* mask all */
  383. writel(0xffffffff, &host->reg->norintstsen);
  384. writel(0xffffffff, &host->reg->norintsigen);
  385. writeb(0xe, &host->reg->timeoutcon); /* TMCLK * 2^27 */
  386. /*
  387. * NORMAL Interrupt Status Enable Register init
  388. * [5] ENSTABUFRDRDY : Buffer Read Ready Status Enable
  389. * [4] ENSTABUFWTRDY : Buffer write Ready Status Enable
  390. * [3] ENSTADMAINT : DMA boundary interrupt
  391. * [1] ENSTASTANSCMPLT : Transfre Complete Status Enable
  392. * [0] ENSTACMDCMPLT : Command Complete Status Enable
  393. */
  394. mask = readl(&host->reg->norintstsen);
  395. mask &= ~(0xffff);
  396. mask |= (TEGRA_MMC_NORINTSTSEN_CMD_COMPLETE |
  397. TEGRA_MMC_NORINTSTSEN_XFER_COMPLETE |
  398. TEGRA_MMC_NORINTSTSEN_DMA_INTERRUPT |
  399. TEGRA_MMC_NORINTSTSEN_BUFFER_WRITE_READY |
  400. TEGRA_MMC_NORINTSTSEN_BUFFER_READ_READY);
  401. writel(mask, &host->reg->norintstsen);
  402. /*
  403. * NORMAL Interrupt Signal Enable Register init
  404. * [1] ENSTACMDCMPLT : Transfer Complete Signal Enable
  405. */
  406. mask = readl(&host->reg->norintsigen);
  407. mask &= ~(0xffff);
  408. mask |= TEGRA_MMC_NORINTSIGEN_XFER_COMPLETE;
  409. writel(mask, &host->reg->norintsigen);
  410. return 0;
  411. }
  412. int tegra_mmc_getcd(struct mmc *mmc)
  413. {
  414. struct mmc_host *host = (struct mmc_host *)mmc->priv;
  415. debug("tegra_mmc_getcd called\n");
  416. if (fdt_gpio_isvalid(&host->cd_gpio))
  417. return fdtdec_get_gpio(&host->cd_gpio);
  418. return 1;
  419. }
  420. static int do_mmc_init(int dev_index)
  421. {
  422. struct mmc_host *host;
  423. char gpusage[12]; /* "SD/MMCn PWR" or "SD/MMCn CD" */
  424. struct mmc *mmc;
  425. /* DT should have been read & host config filled in */
  426. host = &mmc_host[dev_index];
  427. if (!host->enabled)
  428. return -1;
  429. debug(" do_mmc_init: index %d, bus width %d "
  430. "pwr_gpio %d cd_gpio %d\n",
  431. dev_index, host->width,
  432. host->pwr_gpio.gpio, host->cd_gpio.gpio);
  433. host->clock = 0;
  434. clock_start_periph_pll(host->mmc_id, CLOCK_ID_PERIPH, 20000000);
  435. if (fdt_gpio_isvalid(&host->pwr_gpio)) {
  436. sprintf(gpusage, "SD/MMC%d PWR", dev_index);
  437. gpio_request(host->pwr_gpio.gpio, gpusage);
  438. gpio_direction_output(host->pwr_gpio.gpio, 1);
  439. debug(" Power GPIO name = %s\n", host->pwr_gpio.name);
  440. }
  441. if (fdt_gpio_isvalid(&host->cd_gpio)) {
  442. sprintf(gpusage, "SD/MMC%d CD", dev_index);
  443. gpio_request(host->cd_gpio.gpio, gpusage);
  444. gpio_direction_input(host->cd_gpio.gpio);
  445. debug(" CD GPIO name = %s\n", host->cd_gpio.name);
  446. }
  447. mmc = &mmc_dev[dev_index];
  448. sprintf(mmc->name, "Tegra SD/MMC");
  449. mmc->priv = host;
  450. mmc->send_cmd = mmc_send_cmd;
  451. mmc->set_ios = mmc_set_ios;
  452. mmc->init = mmc_core_init;
  453. mmc->getcd = tegra_mmc_getcd;
  454. mmc->getwp = NULL;
  455. mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
  456. mmc->host_caps = 0;
  457. if (host->width == 8)
  458. mmc->host_caps |= MMC_MODE_8BIT;
  459. if (host->width >= 4)
  460. mmc->host_caps |= MMC_MODE_4BIT;
  461. mmc->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_HC;
  462. /*
  463. * min freq is for card identification, and is the highest
  464. * low-speed SDIO card frequency (actually 400KHz)
  465. * max freq is highest HS eMMC clock as per the SD/MMC spec
  466. * (actually 52MHz)
  467. */
  468. mmc->f_min = 375000;
  469. mmc->f_max = 48000000;
  470. mmc_register(mmc);
  471. return 0;
  472. }
  473. /**
  474. * Get the host address and peripheral ID for a node.
  475. *
  476. * @param blob fdt blob
  477. * @param node Device index (0-3)
  478. * @param host Structure to fill in (reg, width, mmc_id)
  479. */
  480. static int mmc_get_config(const void *blob, int node, struct mmc_host *host)
  481. {
  482. debug("%s: node = %d\n", __func__, node);
  483. host->enabled = fdtdec_get_is_enabled(blob, node);
  484. host->reg = (struct tegra_mmc *)fdtdec_get_addr(blob, node, "reg");
  485. if ((fdt_addr_t)host->reg == FDT_ADDR_T_NONE) {
  486. debug("%s: no sdmmc base reg info found\n", __func__);
  487. return -FDT_ERR_NOTFOUND;
  488. }
  489. host->mmc_id = clock_decode_periph_id(blob, node);
  490. if (host->mmc_id == PERIPH_ID_NONE) {
  491. debug("%s: could not decode periph id\n", __func__);
  492. return -FDT_ERR_NOTFOUND;
  493. }
  494. /*
  495. * NOTE: mmc->bus_width is determined by mmc.c dynamically.
  496. * TBD: Override it with this value?
  497. */
  498. host->width = fdtdec_get_int(blob, node, "bus-width", 0);
  499. if (!host->width)
  500. debug("%s: no sdmmc width found\n", __func__);
  501. /* These GPIOs are optional */
  502. fdtdec_decode_gpio(blob, node, "cd-gpios", &host->cd_gpio);
  503. fdtdec_decode_gpio(blob, node, "wp-gpios", &host->wp_gpio);
  504. fdtdec_decode_gpio(blob, node, "power-gpios", &host->pwr_gpio);
  505. debug("%s: found controller at %p, width = %d, periph_id = %d\n",
  506. __func__, host->reg, host->width, host->mmc_id);
  507. return 0;
  508. }
  509. /*
  510. * Process a list of nodes, adding them to our list of SDMMC ports.
  511. *
  512. * @param blob fdt blob
  513. * @param node_list list of nodes to process (any <=0 are ignored)
  514. * @param count number of nodes to process
  515. * @return 0 if ok, -1 on error
  516. */
  517. static int process_nodes(const void *blob, int node_list[], int count)
  518. {
  519. struct mmc_host *host;
  520. int i, node;
  521. debug("%s: count = %d\n", __func__, count);
  522. /* build mmc_host[] for each controller */
  523. for (i = 0; i < count; i++) {
  524. node = node_list[i];
  525. if (node <= 0)
  526. continue;
  527. host = &mmc_host[i];
  528. host->id = i;
  529. if (mmc_get_config(blob, node, host)) {
  530. printf("%s: failed to decode dev %d\n", __func__, i);
  531. return -1;
  532. }
  533. do_mmc_init(i);
  534. }
  535. return 0;
  536. }
  537. void tegra_mmc_init(void)
  538. {
  539. int node_list[MAX_HOSTS], count;
  540. const void *blob = gd->fdt_blob;
  541. debug("%s entry\n", __func__);
  542. count = fdtdec_find_aliases_for_id(blob, "sdhci",
  543. COMPAT_NVIDIA_TEGRA20_SDMMC, node_list, MAX_HOSTS);
  544. debug("%s: count of sdhci nodes is %d\n", __func__, count);
  545. if (process_nodes(blob, node_list, count)) {
  546. printf("%s: Error processing mmc node(s)!\n", __func__);
  547. return;
  548. }
  549. }