Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2009 SAMSUNG Electronics |
| 3 | * Minkyu Kang <mk7.kang@samsung.com> |
| 4 | * Jaehoon Chung <jh80.chung@samsung.com> |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 5 | * Portions Copyright 2011-2015 NVIDIA Corporation |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 6 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Stephen Warren | f227e45 | 2012-11-06 11:27:30 +0000 | [diff] [blame] | 10 | #include <bouncebuf.h> |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 11 | #include <common.h> |
Stephen Warren | d26e24d | 2016-08-05 16:10:33 -0600 | [diff] [blame] | 12 | #include <dm/device.h> |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 13 | #include <errno.h> |
Stephen Warren | fba8754 | 2011-10-31 06:51:36 +0000 | [diff] [blame] | 14 | #include <asm/gpio.h> |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 15 | #include <asm/io.h> |
Stephen Warren | dfbdc12 | 2016-05-12 12:11:23 -0600 | [diff] [blame] | 16 | #ifndef CONFIG_TEGRA186 |
Simon Glass | c2ea5e4 | 2011-09-21 12:40:04 +0000 | [diff] [blame] | 17 | #include <asm/arch/clock.h> |
Tom Warren | ab37196 | 2012-09-19 15:50:56 -0700 | [diff] [blame] | 18 | #include <asm/arch-tegra/clk_rst.h> |
Stephen Warren | dfbdc12 | 2016-05-12 12:11:23 -0600 | [diff] [blame] | 19 | #endif |
Jeroen Hofstee | 93dfae7 | 2014-10-08 22:57:46 +0200 | [diff] [blame] | 20 | #include <asm/arch-tegra/mmc.h> |
Tom Warren | ab37196 | 2012-09-19 15:50:56 -0700 | [diff] [blame] | 21 | #include <asm/arch-tegra/tegra_mmc.h> |
| 22 | #include <mmc.h> |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 23 | |
Stephen Warren | d26e24d | 2016-08-05 16:10:33 -0600 | [diff] [blame] | 24 | /* |
| 25 | * FIXME: TODO: This driver contains a number of ifdef CONFIG_TEGRA186 that |
| 26 | * should not be present. These are needed because newer Tegra SoCs support |
| 27 | * only the standard clock/reset APIs, whereas older Tegra SoCs support only |
| 28 | * a custom Tegra-specific API. ASAP the older Tegra SoCs' code should be |
| 29 | * fixed to implement the standard APIs, and all drivers converted to solely |
| 30 | * use the new standard APIs, with no ifdefs. |
| 31 | */ |
| 32 | |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 34 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 35 | struct tegra_mmc_priv { |
| 36 | struct tegra_mmc *reg; |
| 37 | int id; /* device id/number, 0-3 */ |
| 38 | int enabled; /* 1 to enable, 0 to disable */ |
| 39 | int width; /* Bus Width, 1, 4 or 8 */ |
| 40 | #ifdef CONFIG_TEGRA186 |
| 41 | struct reset_ctl reset_ctl; |
| 42 | struct clk clk; |
| 43 | #else |
| 44 | enum periph_id mmc_id; /* Peripheral ID: PERIPH_ID_... */ |
| 45 | #endif |
| 46 | struct gpio_desc cd_gpio; /* Change Detect GPIO */ |
| 47 | struct gpio_desc pwr_gpio; /* Power GPIO */ |
| 48 | struct gpio_desc wp_gpio; /* Write Protect GPIO */ |
| 49 | unsigned int version; /* SDHCI spec. version */ |
| 50 | unsigned int clock; /* Current clock (MHz) */ |
| 51 | struct mmc_config cfg; /* mmc configuration */ |
| 52 | }; |
| 53 | |
| 54 | struct tegra_mmc_priv mmc_host[CONFIG_SYS_MMC_MAX_DEVICE]; |
Simon Glass | c2ea5e4 | 2011-09-21 12:40:04 +0000 | [diff] [blame] | 55 | |
Masahiro Yamada | 366b24f | 2015-08-12 07:31:55 +0900 | [diff] [blame] | 56 | #if !CONFIG_IS_ENABLED(OF_CONTROL) |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 57 | #error "Please enable device tree support to use this driver" |
| 58 | #endif |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 59 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 60 | static void tegra_mmc_set_power(struct tegra_mmc_priv *priv, |
| 61 | unsigned short power) |
Tom Warren | 35ae07b | 2013-02-26 12:31:26 -0700 | [diff] [blame] | 62 | { |
| 63 | u8 pwr = 0; |
| 64 | debug("%s: power = %x\n", __func__, power); |
| 65 | |
| 66 | if (power != (unsigned short)-1) { |
| 67 | switch (1 << power) { |
| 68 | case MMC_VDD_165_195: |
| 69 | pwr = TEGRA_MMC_PWRCTL_SD_BUS_VOLTAGE_V1_8; |
| 70 | break; |
| 71 | case MMC_VDD_29_30: |
| 72 | case MMC_VDD_30_31: |
| 73 | pwr = TEGRA_MMC_PWRCTL_SD_BUS_VOLTAGE_V3_0; |
| 74 | break; |
| 75 | case MMC_VDD_32_33: |
| 76 | case MMC_VDD_33_34: |
| 77 | pwr = TEGRA_MMC_PWRCTL_SD_BUS_VOLTAGE_V3_3; |
| 78 | break; |
| 79 | } |
| 80 | } |
| 81 | debug("%s: pwr = %X\n", __func__, pwr); |
| 82 | |
| 83 | /* Set the bus voltage first (if any) */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 84 | writeb(pwr, &priv->reg->pwrcon); |
Tom Warren | 35ae07b | 2013-02-26 12:31:26 -0700 | [diff] [blame] | 85 | if (pwr == 0) |
| 86 | return; |
| 87 | |
| 88 | /* Now enable bus power */ |
| 89 | pwr |= TEGRA_MMC_PWRCTL_SD_BUS_POWER; |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 90 | writeb(pwr, &priv->reg->pwrcon); |
Tom Warren | 35ae07b | 2013-02-26 12:31:26 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 93 | static void tegra_mmc_prepare_data(struct tegra_mmc_priv *priv, |
| 94 | struct mmc_data *data, |
| 95 | struct bounce_buffer *bbstate) |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 96 | { |
| 97 | unsigned char ctrl; |
| 98 | |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 99 | |
Stephen Warren | f227e45 | 2012-11-06 11:27:30 +0000 | [diff] [blame] | 100 | debug("buf: %p (%p), data->blocks: %u, data->blocksize: %u\n", |
| 101 | bbstate->bounce_buffer, bbstate->user_buffer, data->blocks, |
| 102 | data->blocksize); |
| 103 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 104 | writel((u32)(unsigned long)bbstate->bounce_buffer, &priv->reg->sysad); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 105 | /* |
| 106 | * DMASEL[4:3] |
| 107 | * 00 = Selects SDMA |
| 108 | * 01 = Reserved |
| 109 | * 10 = Selects 32-bit Address ADMA2 |
| 110 | * 11 = Selects 64-bit Address ADMA2 |
| 111 | */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 112 | ctrl = readb(&priv->reg->hostctl); |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 113 | ctrl &= ~TEGRA_MMC_HOSTCTL_DMASEL_MASK; |
| 114 | ctrl |= TEGRA_MMC_HOSTCTL_DMASEL_SDMA; |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 115 | writeb(ctrl, &priv->reg->hostctl); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 116 | |
| 117 | /* We do not handle DMA boundaries, so set it to max (512 KiB) */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 118 | writew((7 << 12) | (data->blocksize & 0xFFF), &priv->reg->blksize); |
| 119 | writew(data->blocks, &priv->reg->blkcnt); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 122 | static void tegra_mmc_set_transfer_mode(struct tegra_mmc_priv *priv, |
| 123 | struct mmc_data *data) |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 124 | { |
| 125 | unsigned short mode; |
| 126 | debug(" mmc_set_transfer_mode called\n"); |
| 127 | /* |
| 128 | * TRNMOD |
| 129 | * MUL1SIN0[5] : Multi/Single Block Select |
| 130 | * RD1WT0[4] : Data Transfer Direction Select |
| 131 | * 1 = read |
| 132 | * 0 = write |
| 133 | * ENACMD12[2] : Auto CMD12 Enable |
| 134 | * ENBLKCNT[1] : Block Count Enable |
| 135 | * ENDMA[0] : DMA Enable |
| 136 | */ |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 137 | mode = (TEGRA_MMC_TRNMOD_DMA_ENABLE | |
| 138 | TEGRA_MMC_TRNMOD_BLOCK_COUNT_ENABLE); |
| 139 | |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 140 | if (data->blocks > 1) |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 141 | mode |= TEGRA_MMC_TRNMOD_MULTI_BLOCK_SELECT; |
| 142 | |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 143 | if (data->flags & MMC_DATA_READ) |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 144 | mode |= TEGRA_MMC_TRNMOD_DATA_XFER_DIR_SEL_READ; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 145 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 146 | writew(mode, &priv->reg->trnmod); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 149 | static int tegra_mmc_wait_inhibit(struct tegra_mmc_priv *priv, |
| 150 | struct mmc_cmd *cmd, |
| 151 | struct mmc_data *data, |
| 152 | unsigned int timeout) |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 153 | { |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 154 | /* |
| 155 | * PRNSTS |
Anton staaf | 5ab3fba | 2011-11-10 11:56:52 +0000 | [diff] [blame] | 156 | * CMDINHDAT[1] : Command Inhibit (DAT) |
| 157 | * CMDINHCMD[0] : Command Inhibit (CMD) |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 158 | */ |
Anton staaf | 5ab3fba | 2011-11-10 11:56:52 +0000 | [diff] [blame] | 159 | unsigned int mask = TEGRA_MMC_PRNSTS_CMD_INHIBIT_CMD; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 160 | |
| 161 | /* |
| 162 | * We shouldn't wait for data inhibit for stop commands, even |
| 163 | * though they might use busy signaling |
| 164 | */ |
Anton staaf | 5ab3fba | 2011-11-10 11:56:52 +0000 | [diff] [blame] | 165 | if ((data == NULL) && (cmd->resp_type & MMC_RSP_BUSY)) |
| 166 | mask |= TEGRA_MMC_PRNSTS_CMD_INHIBIT_DAT; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 167 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 168 | while (readl(&priv->reg->prnsts) & mask) { |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 169 | if (timeout == 0) { |
| 170 | printf("%s: timeout error\n", __func__); |
| 171 | return -1; |
| 172 | } |
| 173 | timeout--; |
| 174 | udelay(1000); |
| 175 | } |
| 176 | |
Anton staaf | 5ab3fba | 2011-11-10 11:56:52 +0000 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 180 | static int tegra_mmc_send_cmd_bounced(struct mmc *mmc, struct mmc_cmd *cmd, |
| 181 | struct mmc_data *data, |
| 182 | struct bounce_buffer *bbstate) |
Anton staaf | 5ab3fba | 2011-11-10 11:56:52 +0000 | [diff] [blame] | 183 | { |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 184 | struct tegra_mmc_priv *priv = mmc->priv; |
Anton staaf | 5ab3fba | 2011-11-10 11:56:52 +0000 | [diff] [blame] | 185 | int flags, i; |
| 186 | int result; |
Anatolij Gustschin | e1f5341 | 2012-03-28 03:40:00 +0000 | [diff] [blame] | 187 | unsigned int mask = 0; |
Anton staaf | 5ab3fba | 2011-11-10 11:56:52 +0000 | [diff] [blame] | 188 | unsigned int retry = 0x100000; |
| 189 | debug(" mmc_send_cmd called\n"); |
| 190 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 191 | result = tegra_mmc_wait_inhibit(priv, cmd, data, 10 /* ms */); |
Anton staaf | 5ab3fba | 2011-11-10 11:56:52 +0000 | [diff] [blame] | 192 | |
| 193 | if (result < 0) |
| 194 | return result; |
| 195 | |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 196 | if (data) |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 197 | tegra_mmc_prepare_data(priv, data, bbstate); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 198 | |
| 199 | debug("cmd->arg: %08x\n", cmd->cmdarg); |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 200 | writel(cmd->cmdarg, &priv->reg->argument); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 201 | |
| 202 | if (data) |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 203 | tegra_mmc_set_transfer_mode(priv, data); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 204 | |
| 205 | if ((cmd->resp_type & MMC_RSP_136) && (cmd->resp_type & MMC_RSP_BUSY)) |
| 206 | return -1; |
| 207 | |
| 208 | /* |
| 209 | * CMDREG |
| 210 | * CMDIDX[13:8] : Command index |
| 211 | * DATAPRNT[5] : Data Present Select |
| 212 | * ENCMDIDX[4] : Command Index Check Enable |
| 213 | * ENCMDCRC[3] : Command CRC Check Enable |
| 214 | * RSPTYP[1:0] |
| 215 | * 00 = No Response |
| 216 | * 01 = Length 136 |
| 217 | * 10 = Length 48 |
| 218 | * 11 = Length 48 Check busy after response |
| 219 | */ |
| 220 | if (!(cmd->resp_type & MMC_RSP_PRESENT)) |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 221 | flags = TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_NO_RESPONSE; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 222 | else if (cmd->resp_type & MMC_RSP_136) |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 223 | flags = TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_LENGTH_136; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 224 | else if (cmd->resp_type & MMC_RSP_BUSY) |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 225 | flags = TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_LENGTH_48_BUSY; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 226 | else |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 227 | flags = TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_LENGTH_48; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 228 | |
| 229 | if (cmd->resp_type & MMC_RSP_CRC) |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 230 | flags |= TEGRA_MMC_TRNMOD_CMD_CRC_CHECK; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 231 | if (cmd->resp_type & MMC_RSP_OPCODE) |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 232 | flags |= TEGRA_MMC_TRNMOD_CMD_INDEX_CHECK; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 233 | if (data) |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 234 | flags |= TEGRA_MMC_TRNMOD_DATA_PRESENT_SELECT_DATA_TRANSFER; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 235 | |
| 236 | debug("cmd: %d\n", cmd->cmdidx); |
| 237 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 238 | writew((cmd->cmdidx << 8) | flags, &priv->reg->cmdreg); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 239 | |
| 240 | for (i = 0; i < retry; i++) { |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 241 | mask = readl(&priv->reg->norintsts); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 242 | /* Command Complete */ |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 243 | if (mask & TEGRA_MMC_NORINTSTS_CMD_COMPLETE) { |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 244 | if (!data) |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 245 | writel(mask, &priv->reg->norintsts); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 246 | break; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | if (i == retry) { |
| 251 | printf("%s: waiting for status update\n", __func__); |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 252 | writel(mask, &priv->reg->norintsts); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 253 | return -ETIMEDOUT; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 256 | if (mask & TEGRA_MMC_NORINTSTS_CMD_TIMEOUT) { |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 257 | /* Timeout Error */ |
| 258 | debug("timeout: %08x cmd %d\n", mask, cmd->cmdidx); |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 259 | writel(mask, &priv->reg->norintsts); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 260 | return -ETIMEDOUT; |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 261 | } else if (mask & TEGRA_MMC_NORINTSTS_ERR_INTERRUPT) { |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 262 | /* Error Interrupt */ |
| 263 | debug("error: %08x cmd %d\n", mask, cmd->cmdidx); |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 264 | writel(mask, &priv->reg->norintsts); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 265 | return -1; |
| 266 | } |
| 267 | |
| 268 | if (cmd->resp_type & MMC_RSP_PRESENT) { |
| 269 | if (cmd->resp_type & MMC_RSP_136) { |
| 270 | /* CRC is stripped so we need to do some shifting. */ |
| 271 | for (i = 0; i < 4; i++) { |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 272 | unsigned long offset = (unsigned long) |
| 273 | (&priv->reg->rspreg3 - i); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 274 | cmd->response[i] = readl(offset) << 8; |
| 275 | |
| 276 | if (i != 3) { |
| 277 | cmd->response[i] |= |
| 278 | readb(offset - 1); |
| 279 | } |
| 280 | debug("cmd->resp[%d]: %08x\n", |
| 281 | i, cmd->response[i]); |
| 282 | } |
| 283 | } else if (cmd->resp_type & MMC_RSP_BUSY) { |
| 284 | for (i = 0; i < retry; i++) { |
| 285 | /* PRNTDATA[23:20] : DAT[3:0] Line Signal */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 286 | if (readl(&priv->reg->prnsts) |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 287 | & (1 << 20)) /* DAT[0] */ |
| 288 | break; |
| 289 | } |
| 290 | |
| 291 | if (i == retry) { |
| 292 | printf("%s: card is still busy\n", __func__); |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 293 | writel(mask, &priv->reg->norintsts); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 294 | return -ETIMEDOUT; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 297 | cmd->response[0] = readl(&priv->reg->rspreg0); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 298 | debug("cmd->resp[0]: %08x\n", cmd->response[0]); |
| 299 | } else { |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 300 | cmd->response[0] = readl(&priv->reg->rspreg0); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 301 | debug("cmd->resp[0]: %08x\n", cmd->response[0]); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | if (data) { |
Anton staaf | bd34842 | 2011-11-10 11:56:51 +0000 | [diff] [blame] | 306 | unsigned long start = get_timer(0); |
| 307 | |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 308 | while (1) { |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 309 | mask = readl(&priv->reg->norintsts); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 310 | |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 311 | if (mask & TEGRA_MMC_NORINTSTS_ERR_INTERRUPT) { |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 312 | /* Error Interrupt */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 313 | writel(mask, &priv->reg->norintsts); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 314 | printf("%s: error during transfer: 0x%08x\n", |
| 315 | __func__, mask); |
| 316 | return -1; |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 317 | } else if (mask & TEGRA_MMC_NORINTSTS_DMA_INTERRUPT) { |
Anton staaf | 3ade210 | 2011-11-10 11:56:50 +0000 | [diff] [blame] | 318 | /* |
| 319 | * DMA Interrupt, restart the transfer where |
| 320 | * it was interrupted. |
| 321 | */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 322 | unsigned int address = readl(&priv->reg->sysad); |
Anton staaf | 3ade210 | 2011-11-10 11:56:50 +0000 | [diff] [blame] | 323 | |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 324 | debug("DMA end\n"); |
Anton staaf | 3ade210 | 2011-11-10 11:56:50 +0000 | [diff] [blame] | 325 | writel(TEGRA_MMC_NORINTSTS_DMA_INTERRUPT, |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 326 | &priv->reg->norintsts); |
| 327 | writel(address, &priv->reg->sysad); |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 328 | } else if (mask & TEGRA_MMC_NORINTSTS_XFER_COMPLETE) { |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 329 | /* Transfer Complete */ |
| 330 | debug("r/w is done\n"); |
| 331 | break; |
Marcel Ziswiler | e1207e9 | 2014-10-04 01:48:53 +0200 | [diff] [blame] | 332 | } else if (get_timer(start) > 8000UL) { |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 333 | writel(mask, &priv->reg->norintsts); |
Anton staaf | bd34842 | 2011-11-10 11:56:51 +0000 | [diff] [blame] | 334 | printf("%s: MMC Timeout\n" |
| 335 | " Interrupt status 0x%08x\n" |
| 336 | " Interrupt status enable 0x%08x\n" |
| 337 | " Interrupt signal enable 0x%08x\n" |
| 338 | " Present status 0x%08x\n", |
| 339 | __func__, mask, |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 340 | readl(&priv->reg->norintstsen), |
| 341 | readl(&priv->reg->norintsigen), |
| 342 | readl(&priv->reg->prnsts)); |
Anton staaf | bd34842 | 2011-11-10 11:56:51 +0000 | [diff] [blame] | 343 | return -1; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 344 | } |
| 345 | } |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 346 | writel(mask, &priv->reg->norintsts); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | udelay(1000); |
| 350 | return 0; |
| 351 | } |
| 352 | |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 353 | static int tegra_mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 354 | struct mmc_data *data) |
Stephen Warren | f227e45 | 2012-11-06 11:27:30 +0000 | [diff] [blame] | 355 | { |
| 356 | void *buf; |
| 357 | unsigned int bbflags; |
| 358 | size_t len; |
| 359 | struct bounce_buffer bbstate; |
| 360 | int ret; |
| 361 | |
| 362 | if (data) { |
| 363 | if (data->flags & MMC_DATA_READ) { |
| 364 | buf = data->dest; |
| 365 | bbflags = GEN_BB_WRITE; |
| 366 | } else { |
| 367 | buf = (void *)data->src; |
| 368 | bbflags = GEN_BB_READ; |
| 369 | } |
| 370 | len = data->blocks * data->blocksize; |
| 371 | |
| 372 | bounce_buffer_start(&bbstate, buf, len, bbflags); |
| 373 | } |
| 374 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 375 | ret = tegra_mmc_send_cmd_bounced(mmc, cmd, data, &bbstate); |
Stephen Warren | f227e45 | 2012-11-06 11:27:30 +0000 | [diff] [blame] | 376 | |
| 377 | if (data) |
| 378 | bounce_buffer_stop(&bbstate); |
| 379 | |
| 380 | return ret; |
| 381 | } |
| 382 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 383 | static void tegra_mmc_change_clock(struct tegra_mmc_priv *priv, uint clock) |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 384 | { |
Simon Glass | c2ea5e4 | 2011-09-21 12:40:04 +0000 | [diff] [blame] | 385 | int div; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 386 | unsigned short clk; |
| 387 | unsigned long timeout; |
Simon Glass | c2ea5e4 | 2011-09-21 12:40:04 +0000 | [diff] [blame] | 388 | |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 389 | debug(" mmc_change_clock called\n"); |
| 390 | |
Simon Glass | c2ea5e4 | 2011-09-21 12:40:04 +0000 | [diff] [blame] | 391 | /* |
Tom Warren | 35ae07b | 2013-02-26 12:31:26 -0700 | [diff] [blame] | 392 | * Change Tegra SDMMCx clock divisor here. Source is PLLP_OUT0 |
Simon Glass | c2ea5e4 | 2011-09-21 12:40:04 +0000 | [diff] [blame] | 393 | */ |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 394 | if (clock == 0) |
| 395 | goto out; |
Stephen Warren | d26e24d | 2016-08-05 16:10:33 -0600 | [diff] [blame] | 396 | #ifdef CONFIG_TEGRA186 |
| 397 | { |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 398 | ulong rate = clk_set_rate(&priv->clk, clock); |
Stephen Warren | d26e24d | 2016-08-05 16:10:33 -0600 | [diff] [blame] | 399 | div = (rate + clock - 1) / clock; |
| 400 | } |
| 401 | #else |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 402 | clock_adjust_periph_pll_div(priv->mmc_id, CLOCK_ID_PERIPH, clock, |
Simon Glass | c2ea5e4 | 2011-09-21 12:40:04 +0000 | [diff] [blame] | 403 | &div); |
Stephen Warren | dfbdc12 | 2016-05-12 12:11:23 -0600 | [diff] [blame] | 404 | #endif |
Simon Glass | c2ea5e4 | 2011-09-21 12:40:04 +0000 | [diff] [blame] | 405 | debug("div = %d\n", div); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 406 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 407 | writew(0, &priv->reg->clkcon); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 408 | |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 409 | /* |
| 410 | * CLKCON |
| 411 | * SELFREQ[15:8] : base clock divided by value |
| 412 | * ENSDCLK[2] : SD Clock Enable |
| 413 | * STBLINTCLK[1] : Internal Clock Stable |
| 414 | * ENINTCLK[0] : Internal Clock Enable |
| 415 | */ |
Simon Glass | c2ea5e4 | 2011-09-21 12:40:04 +0000 | [diff] [blame] | 416 | div >>= 1; |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 417 | clk = ((div << TEGRA_MMC_CLKCON_SDCLK_FREQ_SEL_SHIFT) | |
| 418 | TEGRA_MMC_CLKCON_INTERNAL_CLOCK_ENABLE); |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 419 | writew(clk, &priv->reg->clkcon); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 420 | |
| 421 | /* Wait max 10 ms */ |
| 422 | timeout = 10; |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 423 | while (!(readw(&priv->reg->clkcon) & |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 424 | TEGRA_MMC_CLKCON_INTERNAL_CLOCK_STABLE)) { |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 425 | if (timeout == 0) { |
| 426 | printf("%s: timeout error\n", __func__); |
| 427 | return; |
| 428 | } |
| 429 | timeout--; |
| 430 | udelay(1000); |
| 431 | } |
| 432 | |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 433 | clk |= TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 434 | writew(clk, &priv->reg->clkcon); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 435 | |
| 436 | debug("mmc_change_clock: clkcon = %08X\n", clk); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 437 | |
| 438 | out: |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 439 | priv->clock = clock; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 440 | } |
| 441 | |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 442 | static void tegra_mmc_set_ios(struct mmc *mmc) |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 443 | { |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 444 | struct tegra_mmc_priv *priv = mmc->priv; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 445 | unsigned char ctrl; |
| 446 | debug(" mmc_set_ios called\n"); |
| 447 | |
| 448 | debug("bus_width: %x, clock: %d\n", mmc->bus_width, mmc->clock); |
| 449 | |
| 450 | /* Change clock first */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 451 | tegra_mmc_change_clock(priv, mmc->clock); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 452 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 453 | ctrl = readb(&priv->reg->hostctl); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 454 | |
| 455 | /* |
| 456 | * WIDE8[5] |
| 457 | * 0 = Depend on WIDE4 |
| 458 | * 1 = 8-bit mode |
| 459 | * WIDE4[1] |
| 460 | * 1 = 4-bit mode |
| 461 | * 0 = 1-bit mode |
| 462 | */ |
| 463 | if (mmc->bus_width == 8) |
| 464 | ctrl |= (1 << 5); |
| 465 | else if (mmc->bus_width == 4) |
| 466 | ctrl |= (1 << 1); |
| 467 | else |
| 468 | ctrl &= ~(1 << 1); |
| 469 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 470 | writeb(ctrl, &priv->reg->hostctl); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 471 | debug("mmc_set_ios: hostctl = %08X\n", ctrl); |
| 472 | } |
| 473 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 474 | static void tegra_mmc_pad_init(struct tegra_mmc_priv *priv) |
Stephen Warren | c76e936 | 2016-09-13 10:45:44 -0600 | [diff] [blame] | 475 | { |
| 476 | #if defined(CONFIG_TEGRA30) |
Stephen Warren | c76e936 | 2016-09-13 10:45:44 -0600 | [diff] [blame] | 477 | u32 val; |
| 478 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 479 | debug("%s: sdmmc address = %08x\n", __func__, (unsigned int)priv->reg); |
Stephen Warren | c76e936 | 2016-09-13 10:45:44 -0600 | [diff] [blame] | 480 | |
| 481 | /* Set the pad drive strength for SDMMC1 or 3 only */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 482 | if (priv->reg != (void *)0x78000000 && |
| 483 | priv->reg != (void *)0x78000400) { |
Stephen Warren | c76e936 | 2016-09-13 10:45:44 -0600 | [diff] [blame] | 484 | debug("%s: settings are only valid for SDMMC1/SDMMC3!\n", |
| 485 | __func__); |
| 486 | return; |
| 487 | } |
| 488 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 489 | val = readl(&priv->reg->sdmemcmppadctl); |
Stephen Warren | c76e936 | 2016-09-13 10:45:44 -0600 | [diff] [blame] | 490 | val &= 0xFFFFFFF0; |
| 491 | val |= MEMCOMP_PADCTRL_VREF; |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 492 | writel(val, &priv->reg->sdmemcmppadctl); |
Stephen Warren | c76e936 | 2016-09-13 10:45:44 -0600 | [diff] [blame] | 493 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 494 | val = readl(&priv->reg->autocalcfg); |
Stephen Warren | c76e936 | 2016-09-13 10:45:44 -0600 | [diff] [blame] | 495 | val &= 0xFFFF0000; |
| 496 | val |= AUTO_CAL_PU_OFFSET | AUTO_CAL_PD_OFFSET | AUTO_CAL_ENABLED; |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 497 | writel(val, &priv->reg->autocalcfg); |
Stephen Warren | c76e936 | 2016-09-13 10:45:44 -0600 | [diff] [blame] | 498 | #endif |
| 499 | } |
| 500 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 501 | static void tegra_mmc_reset(struct tegra_mmc_priv *priv, struct mmc *mmc) |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 502 | { |
| 503 | unsigned int timeout; |
| 504 | debug(" mmc_reset called\n"); |
| 505 | |
| 506 | /* |
| 507 | * RSTALL[0] : Software reset for all |
| 508 | * 1 = reset |
| 509 | * 0 = work |
| 510 | */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 511 | writeb(TEGRA_MMC_SWRST_SW_RESET_FOR_ALL, &priv->reg->swrst); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 512 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 513 | priv->clock = 0; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 514 | |
| 515 | /* Wait max 100 ms */ |
| 516 | timeout = 100; |
| 517 | |
| 518 | /* hw clears the bit when it's done */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 519 | while (readb(&priv->reg->swrst) & TEGRA_MMC_SWRST_SW_RESET_FOR_ALL) { |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 520 | if (timeout == 0) { |
| 521 | printf("%s: timeout error\n", __func__); |
| 522 | return; |
| 523 | } |
| 524 | timeout--; |
| 525 | udelay(1000); |
| 526 | } |
Tom Warren | 35ae07b | 2013-02-26 12:31:26 -0700 | [diff] [blame] | 527 | |
| 528 | /* Set SD bus voltage & enable bus power */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 529 | tegra_mmc_set_power(priv, fls(mmc->cfg->voltages) - 1); |
Tom Warren | 35ae07b | 2013-02-26 12:31:26 -0700 | [diff] [blame] | 530 | debug("%s: power control = %02X, host control = %02X\n", __func__, |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 531 | readb(&priv->reg->pwrcon), readb(&priv->reg->hostctl)); |
Tom Warren | 35ae07b | 2013-02-26 12:31:26 -0700 | [diff] [blame] | 532 | |
| 533 | /* Make sure SDIO pads are set up */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 534 | tegra_mmc_pad_init(priv); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 535 | } |
| 536 | |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 537 | static int tegra_mmc_core_init(struct mmc *mmc) |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 538 | { |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 539 | struct tegra_mmc_priv *priv = mmc->priv; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 540 | unsigned int mask; |
| 541 | debug(" mmc_core_init called\n"); |
| 542 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 543 | tegra_mmc_reset(priv, mmc); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 544 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 545 | priv->version = readw(&priv->reg->hcver); |
| 546 | debug("host version = %x\n", priv->version); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 547 | |
| 548 | /* mask all */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 549 | writel(0xffffffff, &priv->reg->norintstsen); |
| 550 | writel(0xffffffff, &priv->reg->norintsigen); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 551 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 552 | writeb(0xe, &priv->reg->timeoutcon); /* TMCLK * 2^27 */ |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 553 | /* |
| 554 | * NORMAL Interrupt Status Enable Register init |
| 555 | * [5] ENSTABUFRDRDY : Buffer Read Ready Status Enable |
| 556 | * [4] ENSTABUFWTRDY : Buffer write Ready Status Enable |
Anton staaf | 3ade210 | 2011-11-10 11:56:50 +0000 | [diff] [blame] | 557 | * [3] ENSTADMAINT : DMA boundary interrupt |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 558 | * [1] ENSTASTANSCMPLT : Transfre Complete Status Enable |
| 559 | * [0] ENSTACMDCMPLT : Command Complete Status Enable |
| 560 | */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 561 | mask = readl(&priv->reg->norintstsen); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 562 | mask &= ~(0xffff); |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 563 | mask |= (TEGRA_MMC_NORINTSTSEN_CMD_COMPLETE | |
| 564 | TEGRA_MMC_NORINTSTSEN_XFER_COMPLETE | |
Anton staaf | 3ade210 | 2011-11-10 11:56:50 +0000 | [diff] [blame] | 565 | TEGRA_MMC_NORINTSTSEN_DMA_INTERRUPT | |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 566 | TEGRA_MMC_NORINTSTSEN_BUFFER_WRITE_READY | |
| 567 | TEGRA_MMC_NORINTSTSEN_BUFFER_READ_READY); |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 568 | writel(mask, &priv->reg->norintstsen); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 569 | |
| 570 | /* |
| 571 | * NORMAL Interrupt Signal Enable Register init |
| 572 | * [1] ENSTACMDCMPLT : Transfer Complete Signal Enable |
| 573 | */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 574 | mask = readl(&priv->reg->norintsigen); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 575 | mask &= ~(0xffff); |
Anton staaf | 0dfb31c | 2011-11-10 11:56:49 +0000 | [diff] [blame] | 576 | mask |= TEGRA_MMC_NORINTSIGEN_XFER_COMPLETE; |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 577 | writel(mask, &priv->reg->norintsigen); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 578 | |
| 579 | return 0; |
| 580 | } |
| 581 | |
Jeroen Hofstee | 93dfae7 | 2014-10-08 22:57:46 +0200 | [diff] [blame] | 582 | static int tegra_mmc_getcd(struct mmc *mmc) |
Thierry Reding | f149411 | 2012-01-02 01:15:39 +0000 | [diff] [blame] | 583 | { |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 584 | struct tegra_mmc_priv *priv = mmc->priv; |
Thierry Reding | f149411 | 2012-01-02 01:15:39 +0000 | [diff] [blame] | 585 | |
Tom Warren | 22562a4 | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 586 | debug("tegra_mmc_getcd called\n"); |
Thierry Reding | f149411 | 2012-01-02 01:15:39 +0000 | [diff] [blame] | 587 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 588 | if (dm_gpio_is_valid(&priv->cd_gpio)) |
| 589 | return dm_gpio_get_value(&priv->cd_gpio); |
Thierry Reding | f149411 | 2012-01-02 01:15:39 +0000 | [diff] [blame] | 590 | |
| 591 | return 1; |
| 592 | } |
| 593 | |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 594 | static const struct mmc_ops tegra_mmc_ops = { |
| 595 | .send_cmd = tegra_mmc_send_cmd, |
| 596 | .set_ios = tegra_mmc_set_ios, |
| 597 | .init = tegra_mmc_core_init, |
| 598 | .getcd = tegra_mmc_getcd, |
| 599 | }; |
| 600 | |
Simon Glass | 7bcaf2a | 2015-05-04 11:31:16 -0600 | [diff] [blame] | 601 | static int do_mmc_init(int dev_index, bool removable) |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 602 | { |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 603 | struct tegra_mmc_priv *priv; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 604 | struct mmc *mmc; |
Stephen Warren | d26e24d | 2016-08-05 16:10:33 -0600 | [diff] [blame] | 605 | #ifdef CONFIG_TEGRA186 |
| 606 | int ret; |
| 607 | #endif |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 608 | |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 609 | /* DT should have been read & host config filled in */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 610 | priv = &mmc_host[dev_index]; |
| 611 | if (!priv->enabled) |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 612 | return -1; |
Stephen Warren | 85a6c07 | 2011-10-31 06:51:34 +0000 | [diff] [blame] | 613 | |
Simon Glass | a30d4ba | 2015-01-05 20:05:38 -0700 | [diff] [blame] | 614 | debug(" do_mmc_init: index %d, bus width %d pwr_gpio %d cd_gpio %d\n", |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 615 | dev_index, priv->width, gpio_get_number(&priv->pwr_gpio), |
| 616 | gpio_get_number(&priv->cd_gpio)); |
Stephen Warren | 85a6c07 | 2011-10-31 06:51:34 +0000 | [diff] [blame] | 617 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 618 | priv->clock = 0; |
Stephen Warren | d26e24d | 2016-08-05 16:10:33 -0600 | [diff] [blame] | 619 | |
| 620 | #ifdef CONFIG_TEGRA186 |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 621 | ret = reset_assert(&priv->reset_ctl); |
Stephen Warren | d26e24d | 2016-08-05 16:10:33 -0600 | [diff] [blame] | 622 | if (ret) |
| 623 | return ret; |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 624 | ret = clk_enable(&priv->clk); |
Stephen Warren | d26e24d | 2016-08-05 16:10:33 -0600 | [diff] [blame] | 625 | if (ret) |
| 626 | return ret; |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 627 | ret = clk_set_rate(&priv->clk, 20000000); |
Stephen Warren | d26e24d | 2016-08-05 16:10:33 -0600 | [diff] [blame] | 628 | if (IS_ERR_VALUE(ret)) |
| 629 | return ret; |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 630 | ret = reset_deassert(&priv->reset_ctl); |
Stephen Warren | d26e24d | 2016-08-05 16:10:33 -0600 | [diff] [blame] | 631 | if (ret) |
| 632 | return ret; |
| 633 | #else |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 634 | clock_start_periph_pll(priv->mmc_id, CLOCK_ID_PERIPH, 20000000); |
Stephen Warren | dfbdc12 | 2016-05-12 12:11:23 -0600 | [diff] [blame] | 635 | #endif |
Stephen Warren | 85a6c07 | 2011-10-31 06:51:34 +0000 | [diff] [blame] | 636 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 637 | if (dm_gpio_is_valid(&priv->pwr_gpio)) |
| 638 | dm_gpio_set_value(&priv->pwr_gpio, 1); |
Stephen Warren | fba8754 | 2011-10-31 06:51:36 +0000 | [diff] [blame] | 639 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 640 | memset(&priv->cfg, 0, sizeof(priv->cfg)); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 641 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 642 | priv->cfg.name = "Tegra SD/MMC"; |
| 643 | priv->cfg.ops = &tegra_mmc_ops; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 644 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 645 | priv->cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195; |
| 646 | priv->cfg.host_caps = 0; |
| 647 | if (priv->width == 8) |
| 648 | priv->cfg.host_caps |= MMC_MODE_8BIT; |
| 649 | if (priv->width >= 4) |
| 650 | priv->cfg.host_caps |= MMC_MODE_4BIT; |
| 651 | priv->cfg.host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 652 | |
| 653 | /* |
| 654 | * min freq is for card identification, and is the highest |
| 655 | * low-speed SDIO card frequency (actually 400KHz) |
| 656 | * max freq is highest HS eMMC clock as per the SD/MMC spec |
| 657 | * (actually 52MHz) |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 658 | */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 659 | priv->cfg.f_min = 375000; |
| 660 | priv->cfg.f_max = 48000000; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 661 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 662 | priv->cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 663 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 664 | mmc = mmc_create(&priv->cfg, priv); |
Simon Glass | 7bcaf2a | 2015-05-04 11:31:16 -0600 | [diff] [blame] | 665 | mmc->block_dev.removable = removable; |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 666 | if (mmc == NULL) |
| 667 | return -1; |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 668 | |
| 669 | return 0; |
| 670 | } |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 671 | |
| 672 | /** |
| 673 | * Get the host address and peripheral ID for a node. |
| 674 | * |
| 675 | * @param blob fdt blob |
| 676 | * @param node Device index (0-3) |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 677 | * @param priv Structure to fill in (reg, width, mmc_id) |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 678 | */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 679 | static int mmc_get_config(const void *blob, int node, |
| 680 | struct tegra_mmc_priv *priv, bool *removablep) |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 681 | { |
| 682 | debug("%s: node = %d\n", __func__, node); |
| 683 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 684 | priv->enabled = fdtdec_get_is_enabled(blob, node); |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 685 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 686 | priv->reg = (struct tegra_mmc *)fdtdec_get_addr(blob, node, "reg"); |
| 687 | if ((fdt_addr_t)priv->reg == FDT_ADDR_T_NONE) { |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 688 | debug("%s: no sdmmc base reg info found\n", __func__); |
| 689 | return -FDT_ERR_NOTFOUND; |
| 690 | } |
| 691 | |
Stephen Warren | d26e24d | 2016-08-05 16:10:33 -0600 | [diff] [blame] | 692 | #ifdef CONFIG_TEGRA186 |
| 693 | { |
| 694 | /* |
| 695 | * FIXME: This variable should go away when the MMC device |
| 696 | * actually is a udevice. |
| 697 | */ |
| 698 | struct udevice dev; |
| 699 | int ret; |
| 700 | dev.of_offset = node; |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 701 | ret = reset_get_by_name(&dev, "sdhci", &priv->reset_ctl); |
Stephen Warren | d26e24d | 2016-08-05 16:10:33 -0600 | [diff] [blame] | 702 | if (ret) { |
Stephen Warren | 0a81e58 | 2016-08-18 11:08:44 -0600 | [diff] [blame] | 703 | debug("reset_get_by_name() failed: %d\n", ret); |
Stephen Warren | d26e24d | 2016-08-05 16:10:33 -0600 | [diff] [blame] | 704 | return ret; |
| 705 | } |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 706 | ret = clk_get_by_index(&dev, 0, &priv->clk); |
Stephen Warren | d26e24d | 2016-08-05 16:10:33 -0600 | [diff] [blame] | 707 | if (ret) { |
| 708 | debug("clk_get_by_index() failed: %d\n", ret); |
| 709 | return ret; |
| 710 | } |
| 711 | } |
| 712 | #else |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 713 | priv->mmc_id = clock_decode_periph_id(blob, node); |
| 714 | if (priv->mmc_id == PERIPH_ID_NONE) { |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 715 | debug("%s: could not decode periph id\n", __func__); |
| 716 | return -FDT_ERR_NOTFOUND; |
| 717 | } |
Stephen Warren | dfbdc12 | 2016-05-12 12:11:23 -0600 | [diff] [blame] | 718 | #endif |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 719 | |
| 720 | /* |
| 721 | * NOTE: mmc->bus_width is determined by mmc.c dynamically. |
| 722 | * TBD: Override it with this value? |
| 723 | */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 724 | priv->width = fdtdec_get_int(blob, node, "bus-width", 0); |
| 725 | if (!priv->width) |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 726 | debug("%s: no sdmmc width found\n", __func__); |
| 727 | |
| 728 | /* These GPIOs are optional */ |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 729 | gpio_request_by_name_nodev(blob, node, "cd-gpios", 0, &priv->cd_gpio, |
Simon Glass | a30d4ba | 2015-01-05 20:05:38 -0700 | [diff] [blame] | 730 | GPIOD_IS_IN); |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 731 | gpio_request_by_name_nodev(blob, node, "wp-gpios", 0, &priv->wp_gpio, |
Simon Glass | a30d4ba | 2015-01-05 20:05:38 -0700 | [diff] [blame] | 732 | GPIOD_IS_IN); |
| 733 | gpio_request_by_name_nodev(blob, node, "power-gpios", 0, |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 734 | &priv->pwr_gpio, GPIOD_IS_OUT); |
Simon Glass | 7bcaf2a | 2015-05-04 11:31:16 -0600 | [diff] [blame] | 735 | *removablep = !fdtdec_get_bool(blob, node, "non-removable"); |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 736 | |
| 737 | debug("%s: found controller at %p, width = %d, periph_id = %d\n", |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 738 | __func__, priv->reg, priv->width, |
Stephen Warren | dfbdc12 | 2016-05-12 12:11:23 -0600 | [diff] [blame] | 739 | #ifndef CONFIG_TEGRA186 |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 740 | priv->mmc_id |
Stephen Warren | dfbdc12 | 2016-05-12 12:11:23 -0600 | [diff] [blame] | 741 | #else |
| 742 | -1 |
| 743 | #endif |
| 744 | ); |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | /* |
| 749 | * Process a list of nodes, adding them to our list of SDMMC ports. |
| 750 | * |
| 751 | * @param blob fdt blob |
| 752 | * @param node_list list of nodes to process (any <=0 are ignored) |
| 753 | * @param count number of nodes to process |
| 754 | * @return 0 if ok, -1 on error |
| 755 | */ |
| 756 | static int process_nodes(const void *blob, int node_list[], int count) |
| 757 | { |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 758 | struct tegra_mmc_priv *priv; |
Simon Glass | 7bcaf2a | 2015-05-04 11:31:16 -0600 | [diff] [blame] | 759 | bool removable; |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 760 | int i, node; |
| 761 | |
| 762 | debug("%s: count = %d\n", __func__, count); |
| 763 | |
| 764 | /* build mmc_host[] for each controller */ |
| 765 | for (i = 0; i < count; i++) { |
| 766 | node = node_list[i]; |
| 767 | if (node <= 0) |
| 768 | continue; |
| 769 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 770 | priv = &mmc_host[i]; |
| 771 | priv->id = i; |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 772 | |
Stephen Warren | 6d9ccbb | 2016-09-13 10:45:46 -0600 | [diff] [blame^] | 773 | if (mmc_get_config(blob, node, priv, &removable)) { |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 774 | printf("%s: failed to decode dev %d\n", __func__, i); |
| 775 | return -1; |
| 776 | } |
Simon Glass | 7bcaf2a | 2015-05-04 11:31:16 -0600 | [diff] [blame] | 777 | do_mmc_init(i, removable); |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 778 | } |
| 779 | return 0; |
| 780 | } |
| 781 | |
| 782 | void tegra_mmc_init(void) |
| 783 | { |
Stephen Warren | 2c0ea60 | 2014-04-18 10:56:11 -0600 | [diff] [blame] | 784 | int node_list[CONFIG_SYS_MMC_MAX_DEVICE], count; |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 785 | const void *blob = gd->fdt_blob; |
| 786 | debug("%s entry\n", __func__); |
| 787 | |
Stephen Warren | dfbdc12 | 2016-05-12 12:11:23 -0600 | [diff] [blame] | 788 | /* See if any Tegra186 MMC controllers are present */ |
Stephen Warren | d55aadc | 2016-09-13 10:45:43 -0600 | [diff] [blame] | 789 | count = fdtdec_find_aliases_for_id(blob, "mmc", |
Stephen Warren | dfbdc12 | 2016-05-12 12:11:23 -0600 | [diff] [blame] | 790 | COMPAT_NVIDIA_TEGRA186_SDMMC, node_list, |
| 791 | CONFIG_SYS_MMC_MAX_DEVICE); |
| 792 | debug("%s: count of Tegra186 sdhci nodes is %d\n", __func__, count); |
| 793 | if (process_nodes(blob, node_list, count)) { |
| 794 | printf("%s: Error processing T186 mmc node(s)!\n", __func__); |
| 795 | return; |
| 796 | } |
| 797 | |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 798 | /* See if any Tegra210 MMC controllers are present */ |
Stephen Warren | d55aadc | 2016-09-13 10:45:43 -0600 | [diff] [blame] | 799 | count = fdtdec_find_aliases_for_id(blob, "mmc", |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 800 | COMPAT_NVIDIA_TEGRA210_SDMMC, node_list, |
| 801 | CONFIG_SYS_MMC_MAX_DEVICE); |
| 802 | debug("%s: count of Tegra210 sdhci nodes is %d\n", __func__, count); |
| 803 | if (process_nodes(blob, node_list, count)) { |
Simon Glass | a40f7a2 | 2016-01-30 16:37:42 -0700 | [diff] [blame] | 804 | printf("%s: Error processing T210 mmc node(s)!\n", __func__); |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 805 | return; |
| 806 | } |
| 807 | |
Stephen Warren | 65e0eb1 | 2014-01-24 12:46:06 -0700 | [diff] [blame] | 808 | /* See if any Tegra124 MMC controllers are present */ |
Stephen Warren | d55aadc | 2016-09-13 10:45:43 -0600 | [diff] [blame] | 809 | count = fdtdec_find_aliases_for_id(blob, "mmc", |
Stephen Warren | 2c0ea60 | 2014-04-18 10:56:11 -0600 | [diff] [blame] | 810 | COMPAT_NVIDIA_TEGRA124_SDMMC, node_list, |
| 811 | CONFIG_SYS_MMC_MAX_DEVICE); |
Stephen Warren | 65e0eb1 | 2014-01-24 12:46:06 -0700 | [diff] [blame] | 812 | debug("%s: count of Tegra124 sdhci nodes is %d\n", __func__, count); |
| 813 | if (process_nodes(blob, node_list, count)) { |
Simon Glass | a40f7a2 | 2016-01-30 16:37:42 -0700 | [diff] [blame] | 814 | printf("%s: Error processing T124 mmc node(s)!\n", __func__); |
Stephen Warren | 65e0eb1 | 2014-01-24 12:46:06 -0700 | [diff] [blame] | 815 | return; |
| 816 | } |
| 817 | |
Tom Warren | 35ae07b | 2013-02-26 12:31:26 -0700 | [diff] [blame] | 818 | /* See if any Tegra30 MMC controllers are present */ |
Stephen Warren | d55aadc | 2016-09-13 10:45:43 -0600 | [diff] [blame] | 819 | count = fdtdec_find_aliases_for_id(blob, "mmc", |
Stephen Warren | 2c0ea60 | 2014-04-18 10:56:11 -0600 | [diff] [blame] | 820 | COMPAT_NVIDIA_TEGRA30_SDMMC, node_list, |
| 821 | CONFIG_SYS_MMC_MAX_DEVICE); |
Tom Warren | 35ae07b | 2013-02-26 12:31:26 -0700 | [diff] [blame] | 822 | debug("%s: count of T30 sdhci nodes is %d\n", __func__, count); |
| 823 | if (process_nodes(blob, node_list, count)) { |
| 824 | printf("%s: Error processing T30 mmc node(s)!\n", __func__); |
| 825 | return; |
| 826 | } |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 827 | |
Tom Warren | 35ae07b | 2013-02-26 12:31:26 -0700 | [diff] [blame] | 828 | /* Now look for any Tegra20 MMC controllers */ |
Stephen Warren | d55aadc | 2016-09-13 10:45:43 -0600 | [diff] [blame] | 829 | count = fdtdec_find_aliases_for_id(blob, "mmc", |
Stephen Warren | 2c0ea60 | 2014-04-18 10:56:11 -0600 | [diff] [blame] | 830 | COMPAT_NVIDIA_TEGRA20_SDMMC, node_list, |
| 831 | CONFIG_SYS_MMC_MAX_DEVICE); |
Tom Warren | 35ae07b | 2013-02-26 12:31:26 -0700 | [diff] [blame] | 832 | debug("%s: count of T20 sdhci nodes is %d\n", __func__, count); |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 833 | if (process_nodes(blob, node_list, count)) { |
Tom Warren | 35ae07b | 2013-02-26 12:31:26 -0700 | [diff] [blame] | 834 | printf("%s: Error processing T20 mmc node(s)!\n", __func__); |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 835 | return; |
| 836 | } |
| 837 | } |