Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 1 | /* |
Jerry Huang | ed41367 | 2011-01-06 23:42:19 -0600 | [diff] [blame] | 2 | * Copyright 2007, 2010-2011 Freescale Semiconductor, Inc |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 3 | * Andy Fleming |
| 4 | * |
| 5 | * Based vaguely on the pxa mmc code: |
| 6 | * (C) Copyright 2003 |
| 7 | * Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net |
| 8 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <config.h> |
| 13 | #include <common.h> |
| 14 | #include <command.h> |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 15 | #include <hwconfig.h> |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 16 | #include <mmc.h> |
| 17 | #include <part.h> |
| 18 | #include <malloc.h> |
| 19 | #include <mmc.h> |
| 20 | #include <fsl_esdhc.h> |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 21 | #include <fdt_support.h> |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 22 | #include <asm/io.h> |
| 23 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
| 26 | struct fsl_esdhc { |
| 27 | uint dsaddr; |
| 28 | uint blkattr; |
| 29 | uint cmdarg; |
| 30 | uint xfertyp; |
| 31 | uint cmdrsp0; |
| 32 | uint cmdrsp1; |
| 33 | uint cmdrsp2; |
| 34 | uint cmdrsp3; |
| 35 | uint datport; |
| 36 | uint prsstat; |
| 37 | uint proctl; |
| 38 | uint sysctl; |
| 39 | uint irqstat; |
| 40 | uint irqstaten; |
| 41 | uint irqsigen; |
| 42 | uint autoc12err; |
| 43 | uint hostcapblt; |
| 44 | uint wml; |
Jason Liu | 9919d64 | 2011-11-25 00:18:04 +0000 | [diff] [blame] | 45 | uint mixctrl; |
| 46 | char reserved1[4]; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 47 | uint fevt; |
| 48 | char reserved2[168]; |
| 49 | uint hostver; |
| 50 | char reserved3[780]; |
| 51 | uint scr; |
| 52 | }; |
| 53 | |
| 54 | /* Return the XFERTYP flags for a given command and data packet */ |
Kim Phillips | f9e0b60 | 2012-10-29 13:34:44 +0000 | [diff] [blame] | 55 | static uint esdhc_xfertyp(struct mmc_cmd *cmd, struct mmc_data *data) |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 56 | { |
| 57 | uint xfertyp = 0; |
| 58 | |
| 59 | if (data) { |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 60 | xfertyp |= XFERTYP_DPSEL; |
| 61 | #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO |
| 62 | xfertyp |= XFERTYP_DMAEN; |
| 63 | #endif |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 64 | if (data->blocks > 1) { |
| 65 | xfertyp |= XFERTYP_MSBSEL; |
| 66 | xfertyp |= XFERTYP_BCEN; |
Jerry Huang | ed41367 | 2011-01-06 23:42:19 -0600 | [diff] [blame] | 67 | #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111 |
| 68 | xfertyp |= XFERTYP_AC12EN; |
| 69 | #endif |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | if (data->flags & MMC_DATA_READ) |
| 73 | xfertyp |= XFERTYP_DTDSEL; |
| 74 | } |
| 75 | |
| 76 | if (cmd->resp_type & MMC_RSP_CRC) |
| 77 | xfertyp |= XFERTYP_CCCEN; |
| 78 | if (cmd->resp_type & MMC_RSP_OPCODE) |
| 79 | xfertyp |= XFERTYP_CICEN; |
| 80 | if (cmd->resp_type & MMC_RSP_136) |
| 81 | xfertyp |= XFERTYP_RSPTYP_136; |
| 82 | else if (cmd->resp_type & MMC_RSP_BUSY) |
| 83 | xfertyp |= XFERTYP_RSPTYP_48_BUSY; |
| 84 | else if (cmd->resp_type & MMC_RSP_PRESENT) |
| 85 | xfertyp |= XFERTYP_RSPTYP_48; |
| 86 | |
Haijun.Zhang | 203fa4d | 2013-07-01 14:26:01 +0800 | [diff] [blame] | 87 | #if defined(CONFIG_MX53) || defined(CONFIG_T4240QDS) |
Jason Liu | bef0ff0 | 2011-03-22 01:32:31 +0000 | [diff] [blame] | 88 | if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION) |
| 89 | xfertyp |= XFERTYP_CMDTYP_ABORT; |
| 90 | #endif |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 91 | return XFERTYP_CMD(cmd->cmdidx) | xfertyp; |
| 92 | } |
| 93 | |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 94 | #ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO |
| 95 | /* |
| 96 | * PIO Read/Write Mode reduce the performace as DMA is not used in this mode. |
| 97 | */ |
Wolfgang Denk | a40545c | 2010-05-09 23:52:59 +0200 | [diff] [blame] | 98 | static void |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 99 | esdhc_pio_read_write(struct mmc *mmc, struct mmc_data *data) |
| 100 | { |
Ira Snyder | 66a722e | 2011-12-23 08:30:40 +0000 | [diff] [blame] | 101 | struct fsl_esdhc_cfg *cfg = mmc->priv; |
| 102 | struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base; |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 103 | uint blocks; |
| 104 | char *buffer; |
| 105 | uint databuf; |
| 106 | uint size; |
| 107 | uint irqstat; |
| 108 | uint timeout; |
| 109 | |
| 110 | if (data->flags & MMC_DATA_READ) { |
| 111 | blocks = data->blocks; |
| 112 | buffer = data->dest; |
| 113 | while (blocks) { |
| 114 | timeout = PIO_TIMEOUT; |
| 115 | size = data->blocksize; |
| 116 | irqstat = esdhc_read32(®s->irqstat); |
| 117 | while (!(esdhc_read32(®s->prsstat) & PRSSTAT_BREN) |
| 118 | && --timeout); |
| 119 | if (timeout <= 0) { |
| 120 | printf("\nData Read Failed in PIO Mode."); |
Wolfgang Denk | a40545c | 2010-05-09 23:52:59 +0200 | [diff] [blame] | 121 | return; |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 122 | } |
| 123 | while (size && (!(irqstat & IRQSTAT_TC))) { |
| 124 | udelay(100); /* Wait before last byte transfer complete */ |
| 125 | irqstat = esdhc_read32(®s->irqstat); |
| 126 | databuf = in_le32(®s->datport); |
| 127 | *((uint *)buffer) = databuf; |
| 128 | buffer += 4; |
| 129 | size -= 4; |
| 130 | } |
| 131 | blocks--; |
| 132 | } |
| 133 | } else { |
| 134 | blocks = data->blocks; |
Wolfgang Denk | a40545c | 2010-05-09 23:52:59 +0200 | [diff] [blame] | 135 | buffer = (char *)data->src; |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 136 | while (blocks) { |
| 137 | timeout = PIO_TIMEOUT; |
| 138 | size = data->blocksize; |
| 139 | irqstat = esdhc_read32(®s->irqstat); |
| 140 | while (!(esdhc_read32(®s->prsstat) & PRSSTAT_BWEN) |
| 141 | && --timeout); |
| 142 | if (timeout <= 0) { |
| 143 | printf("\nData Write Failed in PIO Mode."); |
Wolfgang Denk | a40545c | 2010-05-09 23:52:59 +0200 | [diff] [blame] | 144 | return; |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 145 | } |
| 146 | while (size && (!(irqstat & IRQSTAT_TC))) { |
| 147 | udelay(100); /* Wait before last byte transfer complete */ |
| 148 | databuf = *((uint *)buffer); |
| 149 | buffer += 4; |
| 150 | size -= 4; |
| 151 | irqstat = esdhc_read32(®s->irqstat); |
| 152 | out_le32(®s->datport, databuf); |
| 153 | } |
| 154 | blocks--; |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | #endif |
| 159 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 160 | static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data) |
| 161 | { |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 162 | int timeout; |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 163 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
| 164 | struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base; |
Fabio Estevam | 88525ed | 2013-05-28 15:09:42 -0300 | [diff] [blame] | 165 | #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO |
Wolfgang Denk | a40545c | 2010-05-09 23:52:59 +0200 | [diff] [blame] | 166 | uint wml_value; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 167 | |
| 168 | wml_value = data->blocksize/4; |
| 169 | |
| 170 | if (data->flags & MMC_DATA_READ) { |
Priyanka Jain | 0244963 | 2011-02-09 09:24:10 +0530 | [diff] [blame] | 171 | if (wml_value > WML_RD_WML_MAX) |
| 172 | wml_value = WML_RD_WML_MAX_VAL; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 173 | |
Roy Zang | e5853af | 2010-02-09 18:23:33 +0800 | [diff] [blame] | 174 | esdhc_clrsetbits32(®s->wml, WML_RD_WML_MASK, wml_value); |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 175 | esdhc_write32(®s->dsaddr, (u32)data->dest); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 176 | } else { |
Eric Nelson | 30e9cad | 2012-04-25 14:28:48 +0000 | [diff] [blame] | 177 | flush_dcache_range((ulong)data->src, |
| 178 | (ulong)data->src+data->blocks |
| 179 | *data->blocksize); |
| 180 | |
Priyanka Jain | 0244963 | 2011-02-09 09:24:10 +0530 | [diff] [blame] | 181 | if (wml_value > WML_WR_WML_MAX) |
| 182 | wml_value = WML_WR_WML_MAX_VAL; |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 183 | if ((esdhc_read32(®s->prsstat) & PRSSTAT_WPSPL) == 0) { |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 184 | printf("\nThe SD card is locked. Can not write to a locked card.\n\n"); |
| 185 | return TIMEOUT; |
| 186 | } |
Roy Zang | e5853af | 2010-02-09 18:23:33 +0800 | [diff] [blame] | 187 | |
| 188 | esdhc_clrsetbits32(®s->wml, WML_WR_WML_MASK, |
| 189 | wml_value << 16); |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 190 | esdhc_write32(®s->dsaddr, (u32)data->src); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 191 | } |
Wolfgang Denk | a40545c | 2010-05-09 23:52:59 +0200 | [diff] [blame] | 192 | #else /* CONFIG_SYS_FSL_ESDHC_USE_PIO */ |
| 193 | if (!(data->flags & MMC_DATA_READ)) { |
| 194 | if ((esdhc_read32(®s->prsstat) & PRSSTAT_WPSPL) == 0) { |
| 195 | printf("\nThe SD card is locked. " |
| 196 | "Can not write to a locked card.\n\n"); |
| 197 | return TIMEOUT; |
| 198 | } |
| 199 | esdhc_write32(®s->dsaddr, (u32)data->src); |
| 200 | } else |
| 201 | esdhc_write32(®s->dsaddr, (u32)data->dest); |
| 202 | #endif /* CONFIG_SYS_FSL_ESDHC_USE_PIO */ |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 203 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 204 | esdhc_write32(®s->blkattr, data->blocks << 16 | data->blocksize); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 205 | |
| 206 | /* Calculate the timeout period for data transactions */ |
Priyanka Jain | c51b40d | 2011-03-03 09:18:56 +0530 | [diff] [blame] | 207 | /* |
| 208 | * 1)Timeout period = (2^(timeout+13)) SD Clock cycles |
| 209 | * 2)Timeout period should be minimum 0.250sec as per SD Card spec |
| 210 | * So, Number of SD Clock cycles for 0.25sec should be minimum |
| 211 | * (SD Clock/sec * 0.25 sec) SD Clock cycles |
| 212 | * = (mmc->tran_speed * 1/4) SD Clock cycles |
| 213 | * As 1) >= 2) |
| 214 | * => (2^(timeout+13)) >= mmc->tran_speed * 1/4 |
| 215 | * Taking log2 both the sides |
| 216 | * => timeout + 13 >= log2(mmc->tran_speed/4) |
| 217 | * Rounding up to next power of 2 |
| 218 | * => timeout + 13 = log2(mmc->tran_speed/4) + 1 |
| 219 | * => timeout + 13 = fls(mmc->tran_speed/4) |
| 220 | */ |
| 221 | timeout = fls(mmc->tran_speed/4); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 222 | timeout -= 13; |
| 223 | |
| 224 | if (timeout > 14) |
| 225 | timeout = 14; |
| 226 | |
| 227 | if (timeout < 0) |
| 228 | timeout = 0; |
| 229 | |
Kumar Gala | 9a878d5 | 2011-01-29 15:36:10 -0600 | [diff] [blame] | 230 | #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC_A001 |
| 231 | if ((timeout == 4) || (timeout == 8) || (timeout == 12)) |
| 232 | timeout++; |
| 233 | #endif |
| 234 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 235 | esdhc_clrsetbits32(®s->sysctl, SYSCTL_TIMEOUT_MASK, timeout << 16); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
Eric Nelson | 30e9cad | 2012-04-25 14:28:48 +0000 | [diff] [blame] | 240 | static void check_and_invalidate_dcache_range |
| 241 | (struct mmc_cmd *cmd, |
| 242 | struct mmc_data *data) { |
| 243 | unsigned start = (unsigned)data->dest ; |
| 244 | unsigned size = roundup(ARCH_DMA_MINALIGN, |
| 245 | data->blocks*data->blocksize); |
| 246 | unsigned end = start+size ; |
| 247 | invalidate_dcache_range(start, end); |
| 248 | } |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 249 | /* |
| 250 | * Sends a command out on the bus. Takes the mmc pointer, |
| 251 | * a command pointer, and an optional data pointer. |
| 252 | */ |
| 253 | static int |
| 254 | esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data) |
| 255 | { |
| 256 | uint xfertyp; |
| 257 | uint irqstat; |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 258 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
| 259 | volatile struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 260 | |
Jerry Huang | ed41367 | 2011-01-06 23:42:19 -0600 | [diff] [blame] | 261 | #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111 |
| 262 | if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION) |
| 263 | return 0; |
| 264 | #endif |
| 265 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 266 | esdhc_write32(®s->irqstat, -1); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 267 | |
| 268 | sync(); |
| 269 | |
| 270 | /* Wait for the bus to be idle */ |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 271 | while ((esdhc_read32(®s->prsstat) & PRSSTAT_CICHB) || |
| 272 | (esdhc_read32(®s->prsstat) & PRSSTAT_CIDHB)) |
| 273 | ; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 274 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 275 | while (esdhc_read32(®s->prsstat) & PRSSTAT_DLA) |
| 276 | ; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 277 | |
| 278 | /* Wait at least 8 SD clock cycles before the next command */ |
| 279 | /* |
| 280 | * Note: This is way more than 8 cycles, but 1ms seems to |
| 281 | * resolve timing issues with some cards |
| 282 | */ |
| 283 | udelay(1000); |
| 284 | |
| 285 | /* Set up for a data transfer if we have one */ |
| 286 | if (data) { |
| 287 | int err; |
| 288 | |
| 289 | err = esdhc_setup_data(mmc, data); |
| 290 | if(err) |
| 291 | return err; |
| 292 | } |
| 293 | |
| 294 | /* Figure out the transfer arguments */ |
| 295 | xfertyp = esdhc_xfertyp(cmd, data); |
| 296 | |
Andrew Gabbasov | 4816b7a | 2013-06-11 10:34:22 -0500 | [diff] [blame] | 297 | /* Mask all irqs */ |
| 298 | esdhc_write32(®s->irqsigen, 0); |
| 299 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 300 | /* Send the command */ |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 301 | esdhc_write32(®s->cmdarg, cmd->cmdarg); |
Jason Liu | 9919d64 | 2011-11-25 00:18:04 +0000 | [diff] [blame] | 302 | #if defined(CONFIG_FSL_USDHC) |
| 303 | esdhc_write32(®s->mixctrl, |
| 304 | (esdhc_read32(®s->mixctrl) & 0xFFFFFF80) | (xfertyp & 0x7F)); |
| 305 | esdhc_write32(®s->xfertyp, xfertyp & 0xFFFF0000); |
| 306 | #else |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 307 | esdhc_write32(®s->xfertyp, xfertyp); |
Jason Liu | 9919d64 | 2011-11-25 00:18:04 +0000 | [diff] [blame] | 308 | #endif |
Dirk Behme | d8552d6 | 2012-03-26 03:13:05 +0000 | [diff] [blame] | 309 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 310 | /* Wait for the command to complete */ |
Dirk Behme | d8552d6 | 2012-03-26 03:13:05 +0000 | [diff] [blame] | 311 | while (!(esdhc_read32(®s->irqstat) & (IRQSTAT_CC | IRQSTAT_CTOE))) |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 312 | ; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 313 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 314 | irqstat = esdhc_read32(®s->irqstat); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 315 | |
Dirk Behme | d8552d6 | 2012-03-26 03:13:05 +0000 | [diff] [blame] | 316 | /* Reset CMD and DATA portions on error */ |
| 317 | if (irqstat & (CMD_ERR | IRQSTAT_CTOE)) { |
| 318 | esdhc_write32(®s->sysctl, esdhc_read32(®s->sysctl) | |
| 319 | SYSCTL_RSTC); |
| 320 | while (esdhc_read32(®s->sysctl) & SYSCTL_RSTC) |
| 321 | ; |
| 322 | |
| 323 | if (data) { |
| 324 | esdhc_write32(®s->sysctl, |
| 325 | esdhc_read32(®s->sysctl) | |
| 326 | SYSCTL_RSTD); |
| 327 | while ((esdhc_read32(®s->sysctl) & SYSCTL_RSTD)) |
| 328 | ; |
| 329 | } |
| 330 | } |
| 331 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 332 | if (irqstat & CMD_ERR) |
| 333 | return COMM_ERR; |
| 334 | |
| 335 | if (irqstat & IRQSTAT_CTOE) |
| 336 | return TIMEOUT; |
| 337 | |
Dirk Behme | d8552d6 | 2012-03-26 03:13:05 +0000 | [diff] [blame] | 338 | /* Workaround for ESDHC errata ENGcm03648 */ |
| 339 | if (!data && (cmd->resp_type & MMC_RSP_BUSY)) { |
| 340 | int timeout = 2500; |
| 341 | |
| 342 | /* Poll on DATA0 line for cmd with busy signal for 250 ms */ |
| 343 | while (timeout > 0 && !(esdhc_read32(®s->prsstat) & |
| 344 | PRSSTAT_DAT0)) { |
| 345 | udelay(100); |
| 346 | timeout--; |
| 347 | } |
| 348 | |
| 349 | if (timeout <= 0) { |
| 350 | printf("Timeout waiting for DAT0 to go high!\n"); |
| 351 | return TIMEOUT; |
| 352 | } |
| 353 | } |
| 354 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 355 | /* Copy the response to the response buffer */ |
| 356 | if (cmd->resp_type & MMC_RSP_136) { |
| 357 | u32 cmdrsp3, cmdrsp2, cmdrsp1, cmdrsp0; |
| 358 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 359 | cmdrsp3 = esdhc_read32(®s->cmdrsp3); |
| 360 | cmdrsp2 = esdhc_read32(®s->cmdrsp2); |
| 361 | cmdrsp1 = esdhc_read32(®s->cmdrsp1); |
| 362 | cmdrsp0 = esdhc_read32(®s->cmdrsp0); |
Rabin Vincent | b6eed94 | 2009-04-05 13:30:56 +0530 | [diff] [blame] | 363 | cmd->response[0] = (cmdrsp3 << 8) | (cmdrsp2 >> 24); |
| 364 | cmd->response[1] = (cmdrsp2 << 8) | (cmdrsp1 >> 24); |
| 365 | cmd->response[2] = (cmdrsp1 << 8) | (cmdrsp0 >> 24); |
| 366 | cmd->response[3] = (cmdrsp0 << 8); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 367 | } else |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 368 | cmd->response[0] = esdhc_read32(®s->cmdrsp0); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 369 | |
| 370 | /* Wait until all of the blocks are transferred */ |
| 371 | if (data) { |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 372 | #ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO |
| 373 | esdhc_pio_read_write(mmc, data); |
| 374 | #else |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 375 | do { |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 376 | irqstat = esdhc_read32(®s->irqstat); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 377 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 378 | if (irqstat & IRQSTAT_DTOE) |
| 379 | return TIMEOUT; |
Frans Meulenbroeks | 010ba98 | 2010-07-31 04:45:18 +0000 | [diff] [blame] | 380 | |
| 381 | if (irqstat & DATA_ERR) |
| 382 | return COMM_ERR; |
Andrew Gabbasov | 4a92962 | 2013-04-07 23:06:08 +0000 | [diff] [blame] | 383 | } while ((irqstat & DATA_COMPLETE) != DATA_COMPLETE); |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 384 | #endif |
Eric Nelson | 70e6869 | 2013-04-03 12:31:56 +0000 | [diff] [blame] | 385 | if (data->flags & MMC_DATA_READ) |
| 386 | check_and_invalidate_dcache_range(cmd, data); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 387 | } |
| 388 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 389 | esdhc_write32(®s->irqstat, -1); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | |
Kim Phillips | f9e0b60 | 2012-10-29 13:34:44 +0000 | [diff] [blame] | 394 | static void set_sysctl(struct mmc *mmc, uint clock) |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 395 | { |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 396 | int div, pre_div; |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 397 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
| 398 | volatile struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base; |
Benoît Thébaudeau | c58ff34 | 2012-10-01 08:36:25 +0000 | [diff] [blame] | 399 | int sdhc_clk = cfg->sdhc_clk; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 400 | uint clk; |
| 401 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 402 | if (clock < mmc->f_min) |
| 403 | clock = mmc->f_min; |
| 404 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 405 | if (sdhc_clk / 16 > clock) { |
| 406 | for (pre_div = 2; pre_div < 256; pre_div *= 2) |
| 407 | if ((sdhc_clk / pre_div) <= (clock * 16)) |
| 408 | break; |
| 409 | } else |
| 410 | pre_div = 2; |
| 411 | |
| 412 | for (div = 1; div <= 16; div++) |
| 413 | if ((sdhc_clk / (div * pre_div)) <= clock) |
| 414 | break; |
| 415 | |
| 416 | pre_div >>= 1; |
| 417 | div -= 1; |
| 418 | |
| 419 | clk = (pre_div << 8) | (div << 4); |
| 420 | |
Kumar Gala | 09876a3 | 2010-03-18 15:51:05 -0500 | [diff] [blame] | 421 | esdhc_clrbits32(®s->sysctl, SYSCTL_CKEN); |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 422 | |
| 423 | esdhc_clrsetbits32(®s->sysctl, SYSCTL_CLOCK_MASK, clk); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 424 | |
| 425 | udelay(10000); |
| 426 | |
Kumar Gala | 09876a3 | 2010-03-18 15:51:05 -0500 | [diff] [blame] | 427 | clk = SYSCTL_PEREN | SYSCTL_CKEN; |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 428 | |
| 429 | esdhc_setbits32(®s->sysctl, clk); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | static void esdhc_set_ios(struct mmc *mmc) |
| 433 | { |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 434 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
| 435 | struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 436 | |
| 437 | /* Set the clock speed */ |
| 438 | set_sysctl(mmc, mmc->clock); |
| 439 | |
| 440 | /* Set the bus width */ |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 441 | esdhc_clrbits32(®s->proctl, PROCTL_DTW_4 | PROCTL_DTW_8); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 442 | |
| 443 | if (mmc->bus_width == 4) |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 444 | esdhc_setbits32(®s->proctl, PROCTL_DTW_4); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 445 | else if (mmc->bus_width == 8) |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 446 | esdhc_setbits32(®s->proctl, PROCTL_DTW_8); |
| 447 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | static int esdhc_init(struct mmc *mmc) |
| 451 | { |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 452 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
| 453 | struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 454 | int timeout = 1000; |
| 455 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 456 | /* Reset the entire host controller */ |
Dirk Behme | dbe6725 | 2013-07-15 15:44:29 +0200 | [diff] [blame] | 457 | esdhc_setbits32(®s->sysctl, SYSCTL_RSTA); |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 458 | |
| 459 | /* Wait until the controller is available */ |
| 460 | while ((esdhc_read32(®s->sysctl) & SYSCTL_RSTA) && --timeout) |
| 461 | udelay(1000); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 462 | |
Benoît Thébaudeau | c08d11c | 2012-08-13 07:28:16 +0000 | [diff] [blame] | 463 | #ifndef ARCH_MXC |
P.V.Suresh | 7b1868b | 2010-12-04 10:37:23 +0530 | [diff] [blame] | 464 | /* Enable cache snooping */ |
Benoît Thébaudeau | c08d11c | 2012-08-13 07:28:16 +0000 | [diff] [blame] | 465 | esdhc_write32(®s->scr, 0x00000040); |
| 466 | #endif |
P.V.Suresh | 7b1868b | 2010-12-04 10:37:23 +0530 | [diff] [blame] | 467 | |
Dirk Behme | dbe6725 | 2013-07-15 15:44:29 +0200 | [diff] [blame] | 468 | esdhc_setbits32(®s->sysctl, SYSCTL_HCKEN | SYSCTL_IPGEN); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 469 | |
| 470 | /* Set the initial clock speed */ |
Jerry Huang | 0caea1a | 2010-11-25 17:06:07 +0000 | [diff] [blame] | 471 | mmc_set_clock(mmc, 400000); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 472 | |
| 473 | /* Disable the BRR and BWR bits in IRQSTAT */ |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 474 | esdhc_clrbits32(®s->irqstaten, IRQSTATEN_BRR | IRQSTATEN_BWR); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 475 | |
| 476 | /* Put the PROCTL reg back to the default */ |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 477 | esdhc_write32(®s->proctl, PROCTL_INIT); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 478 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 479 | /* Set timout to the maximum value */ |
| 480 | esdhc_clrsetbits32(®s->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 481 | |
Thierry Reding | 8cee4c98 | 2012-01-02 01:15:38 +0000 | [diff] [blame] | 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | static int esdhc_getcd(struct mmc *mmc) |
| 486 | { |
| 487 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
| 488 | struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base; |
| 489 | int timeout = 1000; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 490 | |
Thierry Reding | 8cee4c98 | 2012-01-02 01:15:38 +0000 | [diff] [blame] | 491 | while (!(esdhc_read32(®s->prsstat) & PRSSTAT_CINS) && --timeout) |
| 492 | udelay(1000); |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 493 | |
Thierry Reding | 8cee4c98 | 2012-01-02 01:15:38 +0000 | [diff] [blame] | 494 | return timeout > 0; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 495 | } |
| 496 | |
Jerry Huang | b7ef756 | 2010-03-18 15:57:06 -0500 | [diff] [blame] | 497 | static void esdhc_reset(struct fsl_esdhc *regs) |
| 498 | { |
| 499 | unsigned long timeout = 100; /* wait max 100 ms */ |
| 500 | |
| 501 | /* reset the controller */ |
Dirk Behme | dbe6725 | 2013-07-15 15:44:29 +0200 | [diff] [blame] | 502 | esdhc_setbits32(®s->sysctl, SYSCTL_RSTA); |
Jerry Huang | b7ef756 | 2010-03-18 15:57:06 -0500 | [diff] [blame] | 503 | |
| 504 | /* hardware clears the bit when it is done */ |
| 505 | while ((esdhc_read32(®s->sysctl) & SYSCTL_RSTA) && --timeout) |
| 506 | udelay(1000); |
| 507 | if (!timeout) |
| 508 | printf("MMC/SD: Reset never completed.\n"); |
| 509 | } |
| 510 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 511 | int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg) |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 512 | { |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 513 | struct fsl_esdhc *regs; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 514 | struct mmc *mmc; |
Li Yang | d4933f2 | 2010-11-25 17:06:09 +0000 | [diff] [blame] | 515 | u32 caps, voltage_caps; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 516 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 517 | if (!cfg) |
| 518 | return -1; |
| 519 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 520 | mmc = malloc(sizeof(struct mmc)); |
| 521 | |
Jason Liu | 9919d64 | 2011-11-25 00:18:04 +0000 | [diff] [blame] | 522 | sprintf(mmc->name, "FSL_SDHC"); |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 523 | regs = (struct fsl_esdhc *)cfg->esdhc_base; |
| 524 | |
Jerry Huang | b7ef756 | 2010-03-18 15:57:06 -0500 | [diff] [blame] | 525 | /* First reset the eSDHC controller */ |
| 526 | esdhc_reset(regs); |
| 527 | |
Jerry Huang | 4e3bfa0 | 2012-05-17 23:57:02 +0000 | [diff] [blame] | 528 | esdhc_setbits32(®s->sysctl, SYSCTL_PEREN | SYSCTL_HCKEN |
| 529 | | SYSCTL_IPGEN | SYSCTL_CKEN); |
| 530 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 531 | mmc->priv = cfg; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 532 | mmc->send_cmd = esdhc_send_cmd; |
| 533 | mmc->set_ios = esdhc_set_ios; |
| 534 | mmc->init = esdhc_init; |
Thierry Reding | 8cee4c98 | 2012-01-02 01:15:38 +0000 | [diff] [blame] | 535 | mmc->getcd = esdhc_getcd; |
Nikita Kiryanov | 020f261 | 2012-12-03 02:19:46 +0000 | [diff] [blame] | 536 | mmc->getwp = NULL; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 537 | |
Li Yang | d4933f2 | 2010-11-25 17:06:09 +0000 | [diff] [blame] | 538 | voltage_caps = 0; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 539 | caps = regs->hostcapblt; |
Roy Zang | 3935661 | 2011-01-07 00:06:47 -0600 | [diff] [blame] | 540 | |
| 541 | #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC135 |
| 542 | caps = caps & ~(ESDHC_HOSTCAPBLT_SRS | |
| 543 | ESDHC_HOSTCAPBLT_VS18 | ESDHC_HOSTCAPBLT_VS30); |
| 544 | #endif |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 545 | if (caps & ESDHC_HOSTCAPBLT_VS18) |
Li Yang | d4933f2 | 2010-11-25 17:06:09 +0000 | [diff] [blame] | 546 | voltage_caps |= MMC_VDD_165_195; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 547 | if (caps & ESDHC_HOSTCAPBLT_VS30) |
Li Yang | d4933f2 | 2010-11-25 17:06:09 +0000 | [diff] [blame] | 548 | voltage_caps |= MMC_VDD_29_30 | MMC_VDD_30_31; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 549 | if (caps & ESDHC_HOSTCAPBLT_VS33) |
Li Yang | d4933f2 | 2010-11-25 17:06:09 +0000 | [diff] [blame] | 550 | voltage_caps |= MMC_VDD_32_33 | MMC_VDD_33_34; |
| 551 | |
| 552 | #ifdef CONFIG_SYS_SD_VOLTAGE |
| 553 | mmc->voltages = CONFIG_SYS_SD_VOLTAGE; |
| 554 | #else |
| 555 | mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34; |
| 556 | #endif |
| 557 | if ((mmc->voltages & voltage_caps) == 0) { |
| 558 | printf("voltage not supported by controller\n"); |
| 559 | return -1; |
| 560 | } |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 561 | |
Shawn Guo | 7567076 | 2012-12-30 14:14:58 +0000 | [diff] [blame] | 562 | mmc->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT | MMC_MODE_HC; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 563 | |
Abbas Raza | e6bf977 | 2013-03-25 09:13:34 +0000 | [diff] [blame] | 564 | if (cfg->max_bus_width > 0) { |
| 565 | if (cfg->max_bus_width < 8) |
| 566 | mmc->host_caps &= ~MMC_MODE_8BIT; |
| 567 | if (cfg->max_bus_width < 4) |
| 568 | mmc->host_caps &= ~MMC_MODE_4BIT; |
| 569 | } |
| 570 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 571 | if (caps & ESDHC_HOSTCAPBLT_HSS) |
| 572 | mmc->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS; |
| 573 | |
| 574 | mmc->f_min = 400000; |
Simon Glass | 9e247d1 | 2012-12-13 20:49:05 +0000 | [diff] [blame] | 575 | mmc->f_max = MIN(gd->arch.sdhc_clk, 52000000); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 576 | |
Fabio Estevam | 1be94b7 | 2011-05-12 09:33:27 +0000 | [diff] [blame] | 577 | mmc->b_max = 0; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 578 | mmc_register(mmc); |
| 579 | |
| 580 | return 0; |
| 581 | } |
| 582 | |
| 583 | int fsl_esdhc_mmc_init(bd_t *bis) |
| 584 | { |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 585 | struct fsl_esdhc_cfg *cfg; |
| 586 | |
Fabio Estevam | 6592a99 | 2012-12-27 08:51:08 +0000 | [diff] [blame] | 587 | cfg = calloc(sizeof(struct fsl_esdhc_cfg), 1); |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 588 | cfg->esdhc_base = CONFIG_SYS_FSL_ESDHC_ADDR; |
Simon Glass | 9e247d1 | 2012-12-13 20:49:05 +0000 | [diff] [blame] | 589 | cfg->sdhc_clk = gd->arch.sdhc_clk; |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 590 | return fsl_esdhc_initialize(bis, cfg); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 591 | } |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 592 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 593 | #ifdef CONFIG_OF_LIBFDT |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 594 | void fdt_fixup_esdhc(void *blob, bd_t *bd) |
| 595 | { |
| 596 | const char *compat = "fsl,esdhc"; |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 597 | |
Chenhui Zhao | 025eab0 | 2011-01-04 17:23:05 +0800 | [diff] [blame] | 598 | #ifdef CONFIG_FSL_ESDHC_PIN_MUX |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 599 | if (!hwconfig("esdhc")) { |
Chenhui Zhao | 025eab0 | 2011-01-04 17:23:05 +0800 | [diff] [blame] | 600 | do_fixup_by_compat(blob, compat, "status", "disabled", |
| 601 | 8 + 1, 1); |
| 602 | return; |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 603 | } |
Chenhui Zhao | 025eab0 | 2011-01-04 17:23:05 +0800 | [diff] [blame] | 604 | #endif |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 605 | |
| 606 | do_fixup_by_compat_u32(blob, compat, "clock-frequency", |
Simon Glass | 9e247d1 | 2012-12-13 20:49:05 +0000 | [diff] [blame] | 607 | gd->arch.sdhc_clk, 1); |
Chenhui Zhao | 025eab0 | 2011-01-04 17:23:05 +0800 | [diff] [blame] | 608 | |
| 609 | do_fixup_by_compat(blob, compat, "status", "okay", |
| 610 | 4 + 1, 1); |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 611 | } |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 612 | #endif |