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> |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 15 | #include <errno.h> |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 16 | #include <hwconfig.h> |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 17 | #include <mmc.h> |
| 18 | #include <part.h> |
Peng Fan | 5eb8b43 | 2017-06-12 17:50:54 +0800 | [diff] [blame] | 19 | #include <power/regulator.h> |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 20 | #include <malloc.h> |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 21 | #include <fsl_esdhc.h> |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 22 | #include <fdt_support.h> |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 23 | #include <asm/io.h> |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 24 | #include <dm.h> |
| 25 | #include <asm-generic/gpio.h> |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 26 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
Ye.Li | 3d46c31 | 2014-11-04 15:35:49 +0800 | [diff] [blame] | 29 | #define SDHCI_IRQ_EN_BITS (IRQSTATEN_CC | IRQSTATEN_TC | \ |
| 30 | IRQSTATEN_CINT | \ |
| 31 | IRQSTATEN_CTOE | IRQSTATEN_CCE | IRQSTATEN_CEBE | \ |
| 32 | IRQSTATEN_CIE | IRQSTATEN_DTOE | IRQSTATEN_DCE | \ |
| 33 | IRQSTATEN_DEBE | IRQSTATEN_BRR | IRQSTATEN_BWR | \ |
| 34 | IRQSTATEN_DINT) |
| 35 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 36 | struct fsl_esdhc { |
Haijun.Zhang | d49eb9e | 2013-10-30 11:37:55 +0800 | [diff] [blame] | 37 | uint dsaddr; /* SDMA system address register */ |
| 38 | uint blkattr; /* Block attributes register */ |
| 39 | uint cmdarg; /* Command argument register */ |
| 40 | uint xfertyp; /* Transfer type register */ |
| 41 | uint cmdrsp0; /* Command response 0 register */ |
| 42 | uint cmdrsp1; /* Command response 1 register */ |
| 43 | uint cmdrsp2; /* Command response 2 register */ |
| 44 | uint cmdrsp3; /* Command response 3 register */ |
| 45 | uint datport; /* Buffer data port register */ |
| 46 | uint prsstat; /* Present state register */ |
| 47 | uint proctl; /* Protocol control register */ |
| 48 | uint sysctl; /* System Control Register */ |
| 49 | uint irqstat; /* Interrupt status register */ |
| 50 | uint irqstaten; /* Interrupt status enable register */ |
| 51 | uint irqsigen; /* Interrupt signal enable register */ |
| 52 | uint autoc12err; /* Auto CMD error status register */ |
| 53 | uint hostcapblt; /* Host controller capabilities register */ |
| 54 | uint wml; /* Watermark level register */ |
| 55 | uint mixctrl; /* For USDHC */ |
| 56 | char reserved1[4]; /* reserved */ |
| 57 | uint fevt; /* Force event register */ |
| 58 | uint admaes; /* ADMA error status register */ |
| 59 | uint adsaddr; /* ADMA system address register */ |
Peng Fan | a6eadd5 | 2016-06-15 10:53:00 +0800 | [diff] [blame] | 60 | char reserved2[4]; |
| 61 | uint dllctrl; |
| 62 | uint dllstat; |
| 63 | uint clktunectrlstatus; |
| 64 | char reserved3[84]; |
| 65 | uint vendorspec; |
| 66 | uint mmcboot; |
| 67 | uint vendorspec2; |
| 68 | char reserved4[48]; |
Haijun.Zhang | d49eb9e | 2013-10-30 11:37:55 +0800 | [diff] [blame] | 69 | uint hostver; /* Host controller version register */ |
Haijun.Zhang | d49eb9e | 2013-10-30 11:37:55 +0800 | [diff] [blame] | 70 | char reserved5[4]; /* reserved */ |
Peng Fan | a6eadd5 | 2016-06-15 10:53:00 +0800 | [diff] [blame] | 71 | uint dmaerraddr; /* DMA error address register */ |
Otavio Salvador | fad3e06 | 2015-02-17 10:42:43 -0200 | [diff] [blame] | 72 | char reserved6[4]; /* reserved */ |
Peng Fan | a6eadd5 | 2016-06-15 10:53:00 +0800 | [diff] [blame] | 73 | uint dmaerrattr; /* DMA error attribute register */ |
| 74 | char reserved7[4]; /* reserved */ |
Haijun.Zhang | d49eb9e | 2013-10-30 11:37:55 +0800 | [diff] [blame] | 75 | uint hostcapblt2; /* Host controller capabilities register 2 */ |
Peng Fan | a6eadd5 | 2016-06-15 10:53:00 +0800 | [diff] [blame] | 76 | char reserved8[8]; /* reserved */ |
Haijun.Zhang | d49eb9e | 2013-10-30 11:37:55 +0800 | [diff] [blame] | 77 | uint tcr; /* Tuning control register */ |
Peng Fan | a6eadd5 | 2016-06-15 10:53:00 +0800 | [diff] [blame] | 78 | char reserved9[28]; /* reserved */ |
Haijun.Zhang | d49eb9e | 2013-10-30 11:37:55 +0800 | [diff] [blame] | 79 | uint sddirctl; /* SD direction control register */ |
Peng Fan | a6eadd5 | 2016-06-15 10:53:00 +0800 | [diff] [blame] | 80 | char reserved10[712];/* reserved */ |
Haijun.Zhang | d49eb9e | 2013-10-30 11:37:55 +0800 | [diff] [blame] | 81 | uint scr; /* eSDHC control register */ |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 82 | }; |
| 83 | |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 84 | /** |
| 85 | * struct fsl_esdhc_priv |
| 86 | * |
| 87 | * @esdhc_regs: registers of the sdhc controller |
| 88 | * @sdhc_clk: Current clk of the sdhc controller |
| 89 | * @bus_width: bus width, 1bit, 4bit or 8bit |
| 90 | * @cfg: mmc config |
| 91 | * @mmc: mmc |
| 92 | * Following is used when Driver Model is enabled for MMC |
| 93 | * @dev: pointer for the device |
| 94 | * @non_removable: 0: removable; 1: non-removable |
Peng Fan | 01eb1c4 | 2016-06-15 10:53:02 +0800 | [diff] [blame] | 95 | * @wp_enable: 1: enable checking wp; 0: no check |
Peng Fan | aee7858 | 2017-06-12 17:50:53 +0800 | [diff] [blame] | 96 | * @vs18_enable: 1: use 1.8V voltage; 0: use 3.3V |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 97 | * @cd_gpio: gpio for card detection |
Peng Fan | 01eb1c4 | 2016-06-15 10:53:02 +0800 | [diff] [blame] | 98 | * @wp_gpio: gpio for write protection |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 99 | */ |
| 100 | struct fsl_esdhc_priv { |
| 101 | struct fsl_esdhc *esdhc_regs; |
| 102 | unsigned int sdhc_clk; |
| 103 | unsigned int bus_width; |
| 104 | struct mmc_config cfg; |
| 105 | struct mmc *mmc; |
| 106 | struct udevice *dev; |
| 107 | int non_removable; |
Peng Fan | 01eb1c4 | 2016-06-15 10:53:02 +0800 | [diff] [blame] | 108 | int wp_enable; |
Peng Fan | aee7858 | 2017-06-12 17:50:53 +0800 | [diff] [blame] | 109 | int vs18_enable; |
Yangbo Lu | b99647c | 2016-12-07 11:54:30 +0800 | [diff] [blame] | 110 | #ifdef CONFIG_DM_GPIO |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 111 | struct gpio_desc cd_gpio; |
Peng Fan | 01eb1c4 | 2016-06-15 10:53:02 +0800 | [diff] [blame] | 112 | struct gpio_desc wp_gpio; |
Yangbo Lu | b99647c | 2016-12-07 11:54:30 +0800 | [diff] [blame] | 113 | #endif |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 114 | }; |
| 115 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 116 | /* Return the XFERTYP flags for a given command and data packet */ |
Kim Phillips | f9e0b60 | 2012-10-29 13:34:44 +0000 | [diff] [blame] | 117 | static uint esdhc_xfertyp(struct mmc_cmd *cmd, struct mmc_data *data) |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 118 | { |
| 119 | uint xfertyp = 0; |
| 120 | |
| 121 | if (data) { |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 122 | xfertyp |= XFERTYP_DPSEL; |
| 123 | #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO |
| 124 | xfertyp |= XFERTYP_DMAEN; |
| 125 | #endif |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 126 | if (data->blocks > 1) { |
| 127 | xfertyp |= XFERTYP_MSBSEL; |
| 128 | xfertyp |= XFERTYP_BCEN; |
Jerry Huang | ed41367 | 2011-01-06 23:42:19 -0600 | [diff] [blame] | 129 | #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111 |
| 130 | xfertyp |= XFERTYP_AC12EN; |
| 131 | #endif |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | if (data->flags & MMC_DATA_READ) |
| 135 | xfertyp |= XFERTYP_DTDSEL; |
| 136 | } |
| 137 | |
| 138 | if (cmd->resp_type & MMC_RSP_CRC) |
| 139 | xfertyp |= XFERTYP_CCCEN; |
| 140 | if (cmd->resp_type & MMC_RSP_OPCODE) |
| 141 | xfertyp |= XFERTYP_CICEN; |
| 142 | if (cmd->resp_type & MMC_RSP_136) |
| 143 | xfertyp |= XFERTYP_RSPTYP_136; |
| 144 | else if (cmd->resp_type & MMC_RSP_BUSY) |
| 145 | xfertyp |= XFERTYP_RSPTYP_48_BUSY; |
| 146 | else if (cmd->resp_type & MMC_RSP_PRESENT) |
| 147 | xfertyp |= XFERTYP_RSPTYP_48; |
| 148 | |
Jason Liu | bef0ff0 | 2011-03-22 01:32:31 +0000 | [diff] [blame] | 149 | if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION) |
| 150 | xfertyp |= XFERTYP_CMDTYP_ABORT; |
Yangbo Lu | b73a3d6 | 2016-01-21 17:33:19 +0800 | [diff] [blame] | 151 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 152 | return XFERTYP_CMD(cmd->cmdidx) | xfertyp; |
| 153 | } |
| 154 | |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 155 | #ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO |
| 156 | /* |
| 157 | * PIO Read/Write Mode reduce the performace as DMA is not used in this mode. |
| 158 | */ |
Simon Glass | 1d177d4 | 2017-07-29 11:35:17 -0600 | [diff] [blame] | 159 | static void esdhc_pio_read_write(struct fsl_esdhc_priv *priv, |
| 160 | struct mmc_data *data) |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 161 | { |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 162 | struct fsl_esdhc *regs = priv->esdhc_regs; |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 163 | uint blocks; |
| 164 | char *buffer; |
| 165 | uint databuf; |
| 166 | uint size; |
| 167 | uint irqstat; |
| 168 | uint timeout; |
| 169 | |
| 170 | if (data->flags & MMC_DATA_READ) { |
| 171 | blocks = data->blocks; |
| 172 | buffer = data->dest; |
| 173 | while (blocks) { |
| 174 | timeout = PIO_TIMEOUT; |
| 175 | size = data->blocksize; |
| 176 | irqstat = esdhc_read32(®s->irqstat); |
| 177 | while (!(esdhc_read32(®s->prsstat) & PRSSTAT_BREN) |
| 178 | && --timeout); |
| 179 | if (timeout <= 0) { |
| 180 | printf("\nData Read Failed in PIO Mode."); |
Wolfgang Denk | a40545c | 2010-05-09 23:52:59 +0200 | [diff] [blame] | 181 | return; |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 182 | } |
| 183 | while (size && (!(irqstat & IRQSTAT_TC))) { |
| 184 | udelay(100); /* Wait before last byte transfer complete */ |
| 185 | irqstat = esdhc_read32(®s->irqstat); |
| 186 | databuf = in_le32(®s->datport); |
| 187 | *((uint *)buffer) = databuf; |
| 188 | buffer += 4; |
| 189 | size -= 4; |
| 190 | } |
| 191 | blocks--; |
| 192 | } |
| 193 | } else { |
| 194 | blocks = data->blocks; |
Wolfgang Denk | a40545c | 2010-05-09 23:52:59 +0200 | [diff] [blame] | 195 | buffer = (char *)data->src; |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 196 | while (blocks) { |
| 197 | timeout = PIO_TIMEOUT; |
| 198 | size = data->blocksize; |
| 199 | irqstat = esdhc_read32(®s->irqstat); |
| 200 | while (!(esdhc_read32(®s->prsstat) & PRSSTAT_BWEN) |
| 201 | && --timeout); |
| 202 | if (timeout <= 0) { |
| 203 | printf("\nData Write Failed in PIO Mode."); |
Wolfgang Denk | a40545c | 2010-05-09 23:52:59 +0200 | [diff] [blame] | 204 | return; |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 205 | } |
| 206 | while (size && (!(irqstat & IRQSTAT_TC))) { |
| 207 | udelay(100); /* Wait before last byte transfer complete */ |
| 208 | databuf = *((uint *)buffer); |
| 209 | buffer += 4; |
| 210 | size -= 4; |
| 211 | irqstat = esdhc_read32(®s->irqstat); |
| 212 | out_le32(®s->datport, databuf); |
| 213 | } |
| 214 | blocks--; |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | #endif |
| 219 | |
Simon Glass | 1d177d4 | 2017-07-29 11:35:17 -0600 | [diff] [blame] | 220 | static int esdhc_setup_data(struct fsl_esdhc_priv *priv, struct mmc *mmc, |
| 221 | struct mmc_data *data) |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 222 | { |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 223 | int timeout; |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 224 | struct fsl_esdhc *regs = priv->esdhc_regs; |
Eddy Petrișor | 5178dc1 | 2016-06-05 03:43:00 +0300 | [diff] [blame] | 225 | #if defined(CONFIG_FSL_LAYERSCAPE) || defined(CONFIG_S32V234) |
Yangbo Lu | d0e295d | 2015-03-20 19:28:31 -0700 | [diff] [blame] | 226 | dma_addr_t addr; |
| 227 | #endif |
Wolfgang Denk | a40545c | 2010-05-09 23:52:59 +0200 | [diff] [blame] | 228 | uint wml_value; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 229 | |
| 230 | wml_value = data->blocksize/4; |
| 231 | |
| 232 | if (data->flags & MMC_DATA_READ) { |
Priyanka Jain | 0244963 | 2011-02-09 09:24:10 +0530 | [diff] [blame] | 233 | if (wml_value > WML_RD_WML_MAX) |
| 234 | wml_value = WML_RD_WML_MAX_VAL; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 235 | |
Roy Zang | e5853af | 2010-02-09 18:23:33 +0800 | [diff] [blame] | 236 | esdhc_clrsetbits32(®s->wml, WML_RD_WML_MASK, wml_value); |
Ye.Li | 33a56b1 | 2014-02-20 18:00:57 +0800 | [diff] [blame] | 237 | #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO |
Eddy Petrișor | 5178dc1 | 2016-06-05 03:43:00 +0300 | [diff] [blame] | 238 | #if defined(CONFIG_FSL_LAYERSCAPE) || defined(CONFIG_S32V234) |
Yangbo Lu | d0e295d | 2015-03-20 19:28:31 -0700 | [diff] [blame] | 239 | addr = virt_to_phys((void *)(data->dest)); |
| 240 | if (upper_32_bits(addr)) |
| 241 | printf("Error found for upper 32 bits\n"); |
| 242 | else |
| 243 | esdhc_write32(®s->dsaddr, lower_32_bits(addr)); |
| 244 | #else |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 245 | esdhc_write32(®s->dsaddr, (u32)data->dest); |
Ye.Li | 33a56b1 | 2014-02-20 18:00:57 +0800 | [diff] [blame] | 246 | #endif |
Yangbo Lu | d0e295d | 2015-03-20 19:28:31 -0700 | [diff] [blame] | 247 | #endif |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 248 | } else { |
Ye.Li | 33a56b1 | 2014-02-20 18:00:57 +0800 | [diff] [blame] | 249 | #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO |
Eric Nelson | 30e9cad | 2012-04-25 14:28:48 +0000 | [diff] [blame] | 250 | flush_dcache_range((ulong)data->src, |
| 251 | (ulong)data->src+data->blocks |
| 252 | *data->blocksize); |
Ye.Li | 33a56b1 | 2014-02-20 18:00:57 +0800 | [diff] [blame] | 253 | #endif |
Priyanka Jain | 0244963 | 2011-02-09 09:24:10 +0530 | [diff] [blame] | 254 | if (wml_value > WML_WR_WML_MAX) |
| 255 | wml_value = WML_WR_WML_MAX_VAL; |
Peng Fan | 01eb1c4 | 2016-06-15 10:53:02 +0800 | [diff] [blame] | 256 | if (priv->wp_enable) { |
| 257 | if ((esdhc_read32(®s->prsstat) & |
| 258 | PRSSTAT_WPSPL) == 0) { |
| 259 | printf("\nThe SD card is locked. Can not write to a locked card.\n\n"); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 260 | return -ETIMEDOUT; |
Peng Fan | 01eb1c4 | 2016-06-15 10:53:02 +0800 | [diff] [blame] | 261 | } |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 262 | } |
Roy Zang | e5853af | 2010-02-09 18:23:33 +0800 | [diff] [blame] | 263 | |
| 264 | esdhc_clrsetbits32(®s->wml, WML_WR_WML_MASK, |
| 265 | wml_value << 16); |
Ye.Li | 33a56b1 | 2014-02-20 18:00:57 +0800 | [diff] [blame] | 266 | #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO |
Eddy Petrișor | 5178dc1 | 2016-06-05 03:43:00 +0300 | [diff] [blame] | 267 | #if defined(CONFIG_FSL_LAYERSCAPE) || defined(CONFIG_S32V234) |
Yangbo Lu | d0e295d | 2015-03-20 19:28:31 -0700 | [diff] [blame] | 268 | addr = virt_to_phys((void *)(data->src)); |
| 269 | if (upper_32_bits(addr)) |
| 270 | printf("Error found for upper 32 bits\n"); |
| 271 | else |
| 272 | esdhc_write32(®s->dsaddr, lower_32_bits(addr)); |
| 273 | #else |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 274 | esdhc_write32(®s->dsaddr, (u32)data->src); |
Ye.Li | 33a56b1 | 2014-02-20 18:00:57 +0800 | [diff] [blame] | 275 | #endif |
Yangbo Lu | d0e295d | 2015-03-20 19:28:31 -0700 | [diff] [blame] | 276 | #endif |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 277 | } |
| 278 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 279 | esdhc_write32(®s->blkattr, data->blocks << 16 | data->blocksize); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 280 | |
| 281 | /* Calculate the timeout period for data transactions */ |
Priyanka Jain | c51b40d | 2011-03-03 09:18:56 +0530 | [diff] [blame] | 282 | /* |
| 283 | * 1)Timeout period = (2^(timeout+13)) SD Clock cycles |
| 284 | * 2)Timeout period should be minimum 0.250sec as per SD Card spec |
| 285 | * So, Number of SD Clock cycles for 0.25sec should be minimum |
| 286 | * (SD Clock/sec * 0.25 sec) SD Clock cycles |
Andrew Gabbasov | d5b4866 | 2014-03-24 02:40:41 -0500 | [diff] [blame] | 287 | * = (mmc->clock * 1/4) SD Clock cycles |
Priyanka Jain | c51b40d | 2011-03-03 09:18:56 +0530 | [diff] [blame] | 288 | * As 1) >= 2) |
Andrew Gabbasov | d5b4866 | 2014-03-24 02:40:41 -0500 | [diff] [blame] | 289 | * => (2^(timeout+13)) >= mmc->clock * 1/4 |
Priyanka Jain | c51b40d | 2011-03-03 09:18:56 +0530 | [diff] [blame] | 290 | * Taking log2 both the sides |
Andrew Gabbasov | d5b4866 | 2014-03-24 02:40:41 -0500 | [diff] [blame] | 291 | * => timeout + 13 >= log2(mmc->clock/4) |
Priyanka Jain | c51b40d | 2011-03-03 09:18:56 +0530 | [diff] [blame] | 292 | * Rounding up to next power of 2 |
Andrew Gabbasov | d5b4866 | 2014-03-24 02:40:41 -0500 | [diff] [blame] | 293 | * => timeout + 13 = log2(mmc->clock/4) + 1 |
| 294 | * => timeout + 13 = fls(mmc->clock/4) |
Yangbo Lu | 9d7f321 | 2015-12-30 14:19:30 +0800 | [diff] [blame] | 295 | * |
| 296 | * However, the MMC spec "It is strongly recommended for hosts to |
| 297 | * implement more than 500ms timeout value even if the card |
| 298 | * indicates the 250ms maximum busy length." Even the previous |
| 299 | * value of 300ms is known to be insufficient for some cards. |
| 300 | * So, we use |
| 301 | * => timeout + 13 = fls(mmc->clock/2) |
Priyanka Jain | c51b40d | 2011-03-03 09:18:56 +0530 | [diff] [blame] | 302 | */ |
Yangbo Lu | 9d7f321 | 2015-12-30 14:19:30 +0800 | [diff] [blame] | 303 | timeout = fls(mmc->clock/2); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 304 | timeout -= 13; |
| 305 | |
| 306 | if (timeout > 14) |
| 307 | timeout = 14; |
| 308 | |
| 309 | if (timeout < 0) |
| 310 | timeout = 0; |
| 311 | |
Kumar Gala | 9a878d5 | 2011-01-29 15:36:10 -0600 | [diff] [blame] | 312 | #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC_A001 |
| 313 | if ((timeout == 4) || (timeout == 8) || (timeout == 12)) |
| 314 | timeout++; |
| 315 | #endif |
| 316 | |
Haijun.Zhang | edeb83a | 2014-03-18 17:04:23 +0800 | [diff] [blame] | 317 | #ifdef ESDHCI_QUIRK_BROKEN_TIMEOUT_VALUE |
| 318 | timeout = 0xE; |
| 319 | #endif |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 320 | esdhc_clrsetbits32(®s->sysctl, SYSCTL_TIMEOUT_MASK, timeout << 16); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 321 | |
| 322 | return 0; |
| 323 | } |
| 324 | |
Eric Nelson | 30e9cad | 2012-04-25 14:28:48 +0000 | [diff] [blame] | 325 | static void check_and_invalidate_dcache_range |
| 326 | (struct mmc_cmd *cmd, |
| 327 | struct mmc_data *data) { |
Yangbo Lu | d0e295d | 2015-03-20 19:28:31 -0700 | [diff] [blame] | 328 | unsigned start = 0; |
Yangbo Lu | e7702c6 | 2016-05-12 19:12:58 +0800 | [diff] [blame] | 329 | unsigned end = 0; |
Eric Nelson | 30e9cad | 2012-04-25 14:28:48 +0000 | [diff] [blame] | 330 | unsigned size = roundup(ARCH_DMA_MINALIGN, |
| 331 | data->blocks*data->blocksize); |
Eddy Petrișor | 5178dc1 | 2016-06-05 03:43:00 +0300 | [diff] [blame] | 332 | #if defined(CONFIG_FSL_LAYERSCAPE) || defined(CONFIG_S32V234) |
Yangbo Lu | d0e295d | 2015-03-20 19:28:31 -0700 | [diff] [blame] | 333 | dma_addr_t addr; |
| 334 | |
| 335 | addr = virt_to_phys((void *)(data->dest)); |
| 336 | if (upper_32_bits(addr)) |
| 337 | printf("Error found for upper 32 bits\n"); |
| 338 | else |
| 339 | start = lower_32_bits(addr); |
Yangbo Lu | e7702c6 | 2016-05-12 19:12:58 +0800 | [diff] [blame] | 340 | #else |
| 341 | start = (unsigned)data->dest; |
Yangbo Lu | d0e295d | 2015-03-20 19:28:31 -0700 | [diff] [blame] | 342 | #endif |
Yangbo Lu | e7702c6 | 2016-05-12 19:12:58 +0800 | [diff] [blame] | 343 | end = start + size; |
Eric Nelson | 30e9cad | 2012-04-25 14:28:48 +0000 | [diff] [blame] | 344 | invalidate_dcache_range(start, end); |
| 345 | } |
Tom Rini | 239dd25 | 2014-05-23 09:19:05 -0400 | [diff] [blame] | 346 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 347 | /* |
| 348 | * Sends a command out on the bus. Takes the mmc pointer, |
| 349 | * a command pointer, and an optional data pointer. |
| 350 | */ |
Simon Glass | 6aa55dc | 2017-07-29 11:35:18 -0600 | [diff] [blame] | 351 | static int esdhc_send_cmd_common(struct fsl_esdhc_priv *priv, struct mmc *mmc, |
| 352 | struct mmc_cmd *cmd, struct mmc_data *data) |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 353 | { |
Andrew Gabbasov | a04a6e0 | 2014-03-24 02:41:06 -0500 | [diff] [blame] | 354 | int err = 0; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 355 | uint xfertyp; |
| 356 | uint irqstat; |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 357 | struct fsl_esdhc *regs = priv->esdhc_regs; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 358 | |
Jerry Huang | ed41367 | 2011-01-06 23:42:19 -0600 | [diff] [blame] | 359 | #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111 |
| 360 | if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION) |
| 361 | return 0; |
| 362 | #endif |
| 363 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 364 | esdhc_write32(®s->irqstat, -1); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 365 | |
| 366 | sync(); |
| 367 | |
| 368 | /* Wait for the bus to be idle */ |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 369 | while ((esdhc_read32(®s->prsstat) & PRSSTAT_CICHB) || |
| 370 | (esdhc_read32(®s->prsstat) & PRSSTAT_CIDHB)) |
| 371 | ; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 372 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 373 | while (esdhc_read32(®s->prsstat) & PRSSTAT_DLA) |
| 374 | ; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 375 | |
| 376 | /* Wait at least 8 SD clock cycles before the next command */ |
| 377 | /* |
| 378 | * Note: This is way more than 8 cycles, but 1ms seems to |
| 379 | * resolve timing issues with some cards |
| 380 | */ |
| 381 | udelay(1000); |
| 382 | |
| 383 | /* Set up for a data transfer if we have one */ |
| 384 | if (data) { |
Simon Glass | 1d177d4 | 2017-07-29 11:35:17 -0600 | [diff] [blame] | 385 | err = esdhc_setup_data(priv, mmc, data); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 386 | if(err) |
| 387 | return err; |
Peng Fan | 9cb5e99 | 2015-06-25 10:32:26 +0800 | [diff] [blame] | 388 | |
| 389 | if (data->flags & MMC_DATA_READ) |
| 390 | check_and_invalidate_dcache_range(cmd, data); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | /* Figure out the transfer arguments */ |
| 394 | xfertyp = esdhc_xfertyp(cmd, data); |
| 395 | |
Andrew Gabbasov | 4816b7a | 2013-06-11 10:34:22 -0500 | [diff] [blame] | 396 | /* Mask all irqs */ |
| 397 | esdhc_write32(®s->irqsigen, 0); |
| 398 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 399 | /* Send the command */ |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 400 | esdhc_write32(®s->cmdarg, cmd->cmdarg); |
Jason Liu | 9919d64 | 2011-11-25 00:18:04 +0000 | [diff] [blame] | 401 | #if defined(CONFIG_FSL_USDHC) |
| 402 | esdhc_write32(®s->mixctrl, |
Volodymyr Riazantsev | d251e11 | 2015-01-20 10:16:44 -0500 | [diff] [blame] | 403 | (esdhc_read32(®s->mixctrl) & 0xFFFFFF80) | (xfertyp & 0x7F) |
| 404 | | (mmc->ddr_mode ? XFERTYP_DDREN : 0)); |
Jason Liu | 9919d64 | 2011-11-25 00:18:04 +0000 | [diff] [blame] | 405 | esdhc_write32(®s->xfertyp, xfertyp & 0xFFFF0000); |
| 406 | #else |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 407 | esdhc_write32(®s->xfertyp, xfertyp); |
Jason Liu | 9919d64 | 2011-11-25 00:18:04 +0000 | [diff] [blame] | 408 | #endif |
Dirk Behme | d8552d6 | 2012-03-26 03:13:05 +0000 | [diff] [blame] | 409 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 410 | /* Wait for the command to complete */ |
Dirk Behme | d8552d6 | 2012-03-26 03:13:05 +0000 | [diff] [blame] | 411 | while (!(esdhc_read32(®s->irqstat) & (IRQSTAT_CC | IRQSTAT_CTOE))) |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 412 | ; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 413 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 414 | irqstat = esdhc_read32(®s->irqstat); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 415 | |
Andrew Gabbasov | a04a6e0 | 2014-03-24 02:41:06 -0500 | [diff] [blame] | 416 | if (irqstat & CMD_ERR) { |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 417 | err = -ECOMM; |
Andrew Gabbasov | a04a6e0 | 2014-03-24 02:41:06 -0500 | [diff] [blame] | 418 | goto out; |
Dirk Behme | d8552d6 | 2012-03-26 03:13:05 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Andrew Gabbasov | a04a6e0 | 2014-03-24 02:41:06 -0500 | [diff] [blame] | 421 | if (irqstat & IRQSTAT_CTOE) { |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 422 | err = -ETIMEDOUT; |
Andrew Gabbasov | a04a6e0 | 2014-03-24 02:41:06 -0500 | [diff] [blame] | 423 | goto out; |
| 424 | } |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 425 | |
Otavio Salvador | fad3e06 | 2015-02-17 10:42:43 -0200 | [diff] [blame] | 426 | /* Switch voltage to 1.8V if CMD11 succeeded */ |
| 427 | if (cmd->cmdidx == SD_CMD_SWITCH_UHS18V) { |
| 428 | esdhc_setbits32(®s->vendorspec, ESDHC_VENDORSPEC_VSELECT); |
| 429 | |
| 430 | printf("Run CMD11 1.8V switch\n"); |
| 431 | /* Sleep for 5 ms - max time for card to switch to 1.8V */ |
| 432 | udelay(5000); |
| 433 | } |
| 434 | |
Dirk Behme | d8552d6 | 2012-03-26 03:13:05 +0000 | [diff] [blame] | 435 | /* Workaround for ESDHC errata ENGcm03648 */ |
| 436 | if (!data && (cmd->resp_type & MMC_RSP_BUSY)) { |
Yangbo Lu | 3ffa851 | 2015-04-15 10:13:12 +0800 | [diff] [blame] | 437 | int timeout = 6000; |
Dirk Behme | d8552d6 | 2012-03-26 03:13:05 +0000 | [diff] [blame] | 438 | |
Yangbo Lu | 3ffa851 | 2015-04-15 10:13:12 +0800 | [diff] [blame] | 439 | /* Poll on DATA0 line for cmd with busy signal for 600 ms */ |
Dirk Behme | d8552d6 | 2012-03-26 03:13:05 +0000 | [diff] [blame] | 440 | while (timeout > 0 && !(esdhc_read32(®s->prsstat) & |
| 441 | PRSSTAT_DAT0)) { |
| 442 | udelay(100); |
| 443 | timeout--; |
| 444 | } |
| 445 | |
| 446 | if (timeout <= 0) { |
| 447 | printf("Timeout waiting for DAT0 to go high!\n"); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 448 | err = -ETIMEDOUT; |
Andrew Gabbasov | a04a6e0 | 2014-03-24 02:41:06 -0500 | [diff] [blame] | 449 | goto out; |
Dirk Behme | d8552d6 | 2012-03-26 03:13:05 +0000 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 453 | /* Copy the response to the response buffer */ |
| 454 | if (cmd->resp_type & MMC_RSP_136) { |
| 455 | u32 cmdrsp3, cmdrsp2, cmdrsp1, cmdrsp0; |
| 456 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 457 | cmdrsp3 = esdhc_read32(®s->cmdrsp3); |
| 458 | cmdrsp2 = esdhc_read32(®s->cmdrsp2); |
| 459 | cmdrsp1 = esdhc_read32(®s->cmdrsp1); |
| 460 | cmdrsp0 = esdhc_read32(®s->cmdrsp0); |
Rabin Vincent | b6eed94 | 2009-04-05 13:30:56 +0530 | [diff] [blame] | 461 | cmd->response[0] = (cmdrsp3 << 8) | (cmdrsp2 >> 24); |
| 462 | cmd->response[1] = (cmdrsp2 << 8) | (cmdrsp1 >> 24); |
| 463 | cmd->response[2] = (cmdrsp1 << 8) | (cmdrsp0 >> 24); |
| 464 | cmd->response[3] = (cmdrsp0 << 8); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 465 | } else |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 466 | cmd->response[0] = esdhc_read32(®s->cmdrsp0); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 467 | |
| 468 | /* Wait until all of the blocks are transferred */ |
| 469 | if (data) { |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 470 | #ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO |
Simon Glass | 1d177d4 | 2017-07-29 11:35:17 -0600 | [diff] [blame] | 471 | esdhc_pio_read_write(priv, data); |
Dipen Dudhat | 5c72f35 | 2009-10-05 15:41:58 +0530 | [diff] [blame] | 472 | #else |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 473 | do { |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 474 | irqstat = esdhc_read32(®s->irqstat); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 475 | |
Andrew Gabbasov | a04a6e0 | 2014-03-24 02:41:06 -0500 | [diff] [blame] | 476 | if (irqstat & IRQSTAT_DTOE) { |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 477 | err = -ETIMEDOUT; |
Andrew Gabbasov | a04a6e0 | 2014-03-24 02:41:06 -0500 | [diff] [blame] | 478 | goto out; |
| 479 | } |
Frans Meulenbroeks | 010ba98 | 2010-07-31 04:45:18 +0000 | [diff] [blame] | 480 | |
Andrew Gabbasov | a04a6e0 | 2014-03-24 02:41:06 -0500 | [diff] [blame] | 481 | if (irqstat & DATA_ERR) { |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 482 | err = -ECOMM; |
Andrew Gabbasov | a04a6e0 | 2014-03-24 02:41:06 -0500 | [diff] [blame] | 483 | goto out; |
| 484 | } |
Andrew Gabbasov | 4a92962 | 2013-04-07 23:06:08 +0000 | [diff] [blame] | 485 | } while ((irqstat & DATA_COMPLETE) != DATA_COMPLETE); |
Ye.Li | 33a56b1 | 2014-02-20 18:00:57 +0800 | [diff] [blame] | 486 | |
Peng Fan | 9cb5e99 | 2015-06-25 10:32:26 +0800 | [diff] [blame] | 487 | /* |
| 488 | * Need invalidate the dcache here again to avoid any |
| 489 | * cache-fill during the DMA operations such as the |
| 490 | * speculative pre-fetching etc. |
| 491 | */ |
Eric Nelson | 70e6869 | 2013-04-03 12:31:56 +0000 | [diff] [blame] | 492 | if (data->flags & MMC_DATA_READ) |
| 493 | check_and_invalidate_dcache_range(cmd, data); |
Ye.Li | 33a56b1 | 2014-02-20 18:00:57 +0800 | [diff] [blame] | 494 | #endif |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 495 | } |
| 496 | |
Andrew Gabbasov | a04a6e0 | 2014-03-24 02:41:06 -0500 | [diff] [blame] | 497 | out: |
| 498 | /* Reset CMD and DATA portions on error */ |
| 499 | if (err) { |
| 500 | esdhc_write32(®s->sysctl, esdhc_read32(®s->sysctl) | |
| 501 | SYSCTL_RSTC); |
| 502 | while (esdhc_read32(®s->sysctl) & SYSCTL_RSTC) |
| 503 | ; |
| 504 | |
| 505 | if (data) { |
| 506 | esdhc_write32(®s->sysctl, |
| 507 | esdhc_read32(®s->sysctl) | |
| 508 | SYSCTL_RSTD); |
| 509 | while ((esdhc_read32(®s->sysctl) & SYSCTL_RSTD)) |
| 510 | ; |
| 511 | } |
Otavio Salvador | fad3e06 | 2015-02-17 10:42:43 -0200 | [diff] [blame] | 512 | |
| 513 | /* If this was CMD11, then notify that power cycle is needed */ |
| 514 | if (cmd->cmdidx == SD_CMD_SWITCH_UHS18V) |
| 515 | printf("CMD11 to switch to 1.8V mode failed, card requires power cycle.\n"); |
Andrew Gabbasov | a04a6e0 | 2014-03-24 02:41:06 -0500 | [diff] [blame] | 516 | } |
| 517 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 518 | esdhc_write32(®s->irqstat, -1); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 519 | |
Andrew Gabbasov | a04a6e0 | 2014-03-24 02:41:06 -0500 | [diff] [blame] | 520 | return err; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 521 | } |
| 522 | |
Simon Glass | 1d177d4 | 2017-07-29 11:35:17 -0600 | [diff] [blame] | 523 | static void set_sysctl(struct fsl_esdhc_priv *priv, struct mmc *mmc, uint clock) |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 524 | { |
Benoît Thébaudeau | e16e922 | 2017-05-03 11:59:03 +0200 | [diff] [blame] | 525 | int div = 1; |
| 526 | #ifdef ARCH_MXC |
| 527 | int pre_div = 1; |
| 528 | #else |
| 529 | int pre_div = 2; |
| 530 | #endif |
| 531 | int ddr_pre_div = mmc->ddr_mode ? 2 : 1; |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 532 | struct fsl_esdhc *regs = priv->esdhc_regs; |
| 533 | int sdhc_clk = priv->sdhc_clk; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 534 | uint clk; |
| 535 | |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 536 | if (clock < mmc->cfg->f_min) |
| 537 | clock = mmc->cfg->f_min; |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 538 | |
Benoît Thébaudeau | e16e922 | 2017-05-03 11:59:03 +0200 | [diff] [blame] | 539 | while (sdhc_clk / (16 * pre_div * ddr_pre_div) > clock && pre_div < 256) |
| 540 | pre_div *= 2; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 541 | |
Benoît Thébaudeau | e16e922 | 2017-05-03 11:59:03 +0200 | [diff] [blame] | 542 | while (sdhc_clk / (div * pre_div * ddr_pre_div) > clock && div < 16) |
| 543 | div++; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 544 | |
Benoît Thébaudeau | e16e922 | 2017-05-03 11:59:03 +0200 | [diff] [blame] | 545 | pre_div >>= 1; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 546 | div -= 1; |
| 547 | |
| 548 | clk = (pre_div << 8) | (div << 4); |
| 549 | |
Eric Nelson | c8e615c | 2015-12-04 12:32:48 -0700 | [diff] [blame] | 550 | #ifdef CONFIG_FSL_USDHC |
Ye Li | 5a24f29 | 2016-06-15 10:53:01 +0800 | [diff] [blame] | 551 | esdhc_clrbits32(®s->vendorspec, VENDORSPEC_CKEN); |
Eric Nelson | c8e615c | 2015-12-04 12:32:48 -0700 | [diff] [blame] | 552 | #else |
Kumar Gala | 09876a3 | 2010-03-18 15:51:05 -0500 | [diff] [blame] | 553 | esdhc_clrbits32(®s->sysctl, SYSCTL_CKEN); |
Eric Nelson | c8e615c | 2015-12-04 12:32:48 -0700 | [diff] [blame] | 554 | #endif |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 555 | |
| 556 | esdhc_clrsetbits32(®s->sysctl, SYSCTL_CLOCK_MASK, clk); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 557 | |
| 558 | udelay(10000); |
| 559 | |
Eric Nelson | c8e615c | 2015-12-04 12:32:48 -0700 | [diff] [blame] | 560 | #ifdef CONFIG_FSL_USDHC |
Ye Li | 5a24f29 | 2016-06-15 10:53:01 +0800 | [diff] [blame] | 561 | esdhc_setbits32(®s->vendorspec, VENDORSPEC_PEREN | VENDORSPEC_CKEN); |
Eric Nelson | c8e615c | 2015-12-04 12:32:48 -0700 | [diff] [blame] | 562 | #else |
| 563 | esdhc_setbits32(®s->sysctl, SYSCTL_PEREN | SYSCTL_CKEN); |
| 564 | #endif |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 565 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 566 | } |
| 567 | |
Yangbo Lu | 163beec | 2015-04-22 13:57:40 +0800 | [diff] [blame] | 568 | #ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK |
Simon Glass | 1d177d4 | 2017-07-29 11:35:17 -0600 | [diff] [blame] | 569 | static void esdhc_clock_control(struct fsl_esdhc_priv *priv, bool enable) |
Yangbo Lu | 163beec | 2015-04-22 13:57:40 +0800 | [diff] [blame] | 570 | { |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 571 | struct fsl_esdhc *regs = priv->esdhc_regs; |
Yangbo Lu | 163beec | 2015-04-22 13:57:40 +0800 | [diff] [blame] | 572 | u32 value; |
| 573 | u32 time_out; |
| 574 | |
| 575 | value = esdhc_read32(®s->sysctl); |
| 576 | |
| 577 | if (enable) |
| 578 | value |= SYSCTL_CKEN; |
| 579 | else |
| 580 | value &= ~SYSCTL_CKEN; |
| 581 | |
| 582 | esdhc_write32(®s->sysctl, value); |
| 583 | |
| 584 | time_out = 20; |
| 585 | value = PRSSTAT_SDSTB; |
| 586 | while (!(esdhc_read32(®s->prsstat) & value)) { |
| 587 | if (time_out == 0) { |
| 588 | printf("fsl_esdhc: Internal clock never stabilised.\n"); |
| 589 | break; |
| 590 | } |
| 591 | time_out--; |
| 592 | mdelay(1); |
| 593 | } |
| 594 | } |
| 595 | #endif |
| 596 | |
Simon Glass | 6aa55dc | 2017-07-29 11:35:18 -0600 | [diff] [blame] | 597 | static int esdhc_set_ios_common(struct fsl_esdhc_priv *priv, struct mmc *mmc) |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 598 | { |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 599 | struct fsl_esdhc *regs = priv->esdhc_regs; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 600 | |
Yangbo Lu | 163beec | 2015-04-22 13:57:40 +0800 | [diff] [blame] | 601 | #ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK |
| 602 | /* Select to use peripheral clock */ |
Simon Glass | 1d177d4 | 2017-07-29 11:35:17 -0600 | [diff] [blame] | 603 | esdhc_clock_control(priv, false); |
Yangbo Lu | 163beec | 2015-04-22 13:57:40 +0800 | [diff] [blame] | 604 | esdhc_setbits32(®s->scr, ESDHCCTL_PCS); |
Simon Glass | 1d177d4 | 2017-07-29 11:35:17 -0600 | [diff] [blame] | 605 | esdhc_clock_control(priv, true); |
Yangbo Lu | 163beec | 2015-04-22 13:57:40 +0800 | [diff] [blame] | 606 | #endif |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 607 | /* Set the clock speed */ |
Simon Glass | 1d177d4 | 2017-07-29 11:35:17 -0600 | [diff] [blame] | 608 | set_sysctl(priv, mmc, mmc->clock); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 609 | |
| 610 | /* Set the bus width */ |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 611 | esdhc_clrbits32(®s->proctl, PROCTL_DTW_4 | PROCTL_DTW_8); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 612 | |
| 613 | if (mmc->bus_width == 4) |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 614 | esdhc_setbits32(®s->proctl, PROCTL_DTW_4); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 615 | else if (mmc->bus_width == 8) |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 616 | esdhc_setbits32(®s->proctl, PROCTL_DTW_8); |
| 617 | |
Jaehoon Chung | b6cd1d3 | 2016-12-30 15:30:16 +0900 | [diff] [blame] | 618 | return 0; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 619 | } |
| 620 | |
Simon Glass | 6aa55dc | 2017-07-29 11:35:18 -0600 | [diff] [blame] | 621 | static int esdhc_init_common(struct fsl_esdhc_priv *priv, struct mmc *mmc) |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 622 | { |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 623 | struct fsl_esdhc *regs = priv->esdhc_regs; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 624 | int timeout = 1000; |
| 625 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 626 | /* Reset the entire host controller */ |
Dirk Behme | dbe6725 | 2013-07-15 15:44:29 +0200 | [diff] [blame] | 627 | esdhc_setbits32(®s->sysctl, SYSCTL_RSTA); |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 628 | |
| 629 | /* Wait until the controller is available */ |
| 630 | while ((esdhc_read32(®s->sysctl) & SYSCTL_RSTA) && --timeout) |
| 631 | udelay(1000); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 632 | |
Peng Fan | a6eadd5 | 2016-06-15 10:53:00 +0800 | [diff] [blame] | 633 | #if defined(CONFIG_FSL_USDHC) |
| 634 | /* RSTA doesn't reset MMC_BOOT register, so manually reset it */ |
| 635 | esdhc_write32(®s->mmcboot, 0x0); |
| 636 | /* Reset MIX_CTRL and CLK_TUNE_CTRL_STATUS regs to 0 */ |
| 637 | esdhc_write32(®s->mixctrl, 0x0); |
| 638 | esdhc_write32(®s->clktunectrlstatus, 0x0); |
| 639 | |
| 640 | /* Put VEND_SPEC to default value */ |
| 641 | esdhc_write32(®s->vendorspec, VENDORSPEC_INIT); |
| 642 | |
| 643 | /* Disable DLL_CTRL delay line */ |
| 644 | esdhc_write32(®s->dllctrl, 0x0); |
| 645 | #endif |
| 646 | |
Benoît Thébaudeau | c08d11c | 2012-08-13 07:28:16 +0000 | [diff] [blame] | 647 | #ifndef ARCH_MXC |
P.V.Suresh | 7b1868b | 2010-12-04 10:37:23 +0530 | [diff] [blame] | 648 | /* Enable cache snooping */ |
Benoît Thébaudeau | c08d11c | 2012-08-13 07:28:16 +0000 | [diff] [blame] | 649 | esdhc_write32(®s->scr, 0x00000040); |
| 650 | #endif |
P.V.Suresh | 7b1868b | 2010-12-04 10:37:23 +0530 | [diff] [blame] | 651 | |
Eric Nelson | c8e615c | 2015-12-04 12:32:48 -0700 | [diff] [blame] | 652 | #ifndef CONFIG_FSL_USDHC |
Dirk Behme | dbe6725 | 2013-07-15 15:44:29 +0200 | [diff] [blame] | 653 | esdhc_setbits32(®s->sysctl, SYSCTL_HCKEN | SYSCTL_IPGEN); |
Ye Li | 5a24f29 | 2016-06-15 10:53:01 +0800 | [diff] [blame] | 654 | #else |
| 655 | esdhc_setbits32(®s->vendorspec, VENDORSPEC_HCKEN | VENDORSPEC_IPGEN); |
Eric Nelson | c8e615c | 2015-12-04 12:32:48 -0700 | [diff] [blame] | 656 | #endif |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 657 | |
| 658 | /* Set the initial clock speed */ |
Jerry Huang | 0caea1a | 2010-11-25 17:06:07 +0000 | [diff] [blame] | 659 | mmc_set_clock(mmc, 400000); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 660 | |
| 661 | /* Disable the BRR and BWR bits in IRQSTAT */ |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 662 | esdhc_clrbits32(®s->irqstaten, IRQSTATEN_BRR | IRQSTATEN_BWR); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 663 | |
| 664 | /* Put the PROCTL reg back to the default */ |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 665 | esdhc_write32(®s->proctl, PROCTL_INIT); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 666 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 667 | /* Set timout to the maximum value */ |
| 668 | esdhc_clrsetbits32(®s->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 669 | |
Peng Fan | aee7858 | 2017-06-12 17:50:53 +0800 | [diff] [blame] | 670 | if (priv->vs18_enable) |
| 671 | esdhc_setbits32(®s->vendorspec, ESDHC_VENDORSPEC_VSELECT); |
| 672 | |
Thierry Reding | 8cee4c98 | 2012-01-02 01:15:38 +0000 | [diff] [blame] | 673 | return 0; |
| 674 | } |
| 675 | |
Simon Glass | 6aa55dc | 2017-07-29 11:35:18 -0600 | [diff] [blame] | 676 | static int esdhc_getcd_common(struct fsl_esdhc_priv *priv) |
Thierry Reding | 8cee4c98 | 2012-01-02 01:15:38 +0000 | [diff] [blame] | 677 | { |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 678 | struct fsl_esdhc *regs = priv->esdhc_regs; |
Thierry Reding | 8cee4c98 | 2012-01-02 01:15:38 +0000 | [diff] [blame] | 679 | int timeout = 1000; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 680 | |
Haijun.Zhang | 05f5854 | 2014-01-10 13:52:17 +0800 | [diff] [blame] | 681 | #ifdef CONFIG_ESDHC_DETECT_QUIRK |
| 682 | if (CONFIG_ESDHC_DETECT_QUIRK) |
| 683 | return 1; |
| 684 | #endif |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 685 | |
| 686 | #ifdef CONFIG_DM_MMC |
| 687 | if (priv->non_removable) |
| 688 | return 1; |
Yangbo Lu | b99647c | 2016-12-07 11:54:30 +0800 | [diff] [blame] | 689 | #ifdef CONFIG_DM_GPIO |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 690 | if (dm_gpio_is_valid(&priv->cd_gpio)) |
| 691 | return dm_gpio_get_value(&priv->cd_gpio); |
| 692 | #endif |
Yangbo Lu | b99647c | 2016-12-07 11:54:30 +0800 | [diff] [blame] | 693 | #endif |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 694 | |
Thierry Reding | 8cee4c98 | 2012-01-02 01:15:38 +0000 | [diff] [blame] | 695 | while (!(esdhc_read32(®s->prsstat) & PRSSTAT_CINS) && --timeout) |
| 696 | udelay(1000); |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 697 | |
Thierry Reding | 8cee4c98 | 2012-01-02 01:15:38 +0000 | [diff] [blame] | 698 | return timeout > 0; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 699 | } |
| 700 | |
Simon Glass | 81357b5 | 2017-07-29 11:35:19 -0600 | [diff] [blame^] | 701 | static int esdhc_reset(struct fsl_esdhc *regs) |
Jerry Huang | b7ef756 | 2010-03-18 15:57:06 -0500 | [diff] [blame] | 702 | { |
Simon Glass | 81357b5 | 2017-07-29 11:35:19 -0600 | [diff] [blame^] | 703 | ulong start; |
Jerry Huang | b7ef756 | 2010-03-18 15:57:06 -0500 | [diff] [blame] | 704 | |
| 705 | /* reset the controller */ |
Dirk Behme | dbe6725 | 2013-07-15 15:44:29 +0200 | [diff] [blame] | 706 | esdhc_setbits32(®s->sysctl, SYSCTL_RSTA); |
Jerry Huang | b7ef756 | 2010-03-18 15:57:06 -0500 | [diff] [blame] | 707 | |
| 708 | /* hardware clears the bit when it is done */ |
Simon Glass | 81357b5 | 2017-07-29 11:35:19 -0600 | [diff] [blame^] | 709 | start = get_timer(0); |
| 710 | while ((esdhc_read32(®s->sysctl) & SYSCTL_RSTA)) { |
| 711 | if (get_timer(start) > 100) { |
| 712 | printf("MMC/SD: Reset never completed.\n"); |
| 713 | return -ETIMEDOUT; |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | return 0; |
Jerry Huang | b7ef756 | 2010-03-18 15:57:06 -0500 | [diff] [blame] | 718 | } |
| 719 | |
Simon Glass | 6aa55dc | 2017-07-29 11:35:18 -0600 | [diff] [blame] | 720 | static int esdhc_getcd(struct mmc *mmc) |
| 721 | { |
| 722 | struct fsl_esdhc_priv *priv = mmc->priv; |
| 723 | |
| 724 | return esdhc_getcd_common(priv); |
| 725 | } |
| 726 | |
| 727 | static int esdhc_init(struct mmc *mmc) |
| 728 | { |
| 729 | struct fsl_esdhc_priv *priv = mmc->priv; |
| 730 | |
| 731 | return esdhc_init_common(priv, mmc); |
| 732 | } |
| 733 | |
| 734 | static int esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, |
| 735 | struct mmc_data *data) |
| 736 | { |
| 737 | struct fsl_esdhc_priv *priv = mmc->priv; |
| 738 | |
| 739 | return esdhc_send_cmd_common(priv, mmc, cmd, data); |
| 740 | } |
| 741 | |
| 742 | static int esdhc_set_ios(struct mmc *mmc) |
| 743 | { |
| 744 | struct fsl_esdhc_priv *priv = mmc->priv; |
| 745 | |
| 746 | return esdhc_set_ios_common(priv, mmc); |
| 747 | } |
| 748 | |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 749 | static const struct mmc_ops esdhc_ops = { |
Simon Glass | 6aa55dc | 2017-07-29 11:35:18 -0600 | [diff] [blame] | 750 | .getcd = esdhc_getcd, |
| 751 | .init = esdhc_init, |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 752 | .send_cmd = esdhc_send_cmd, |
| 753 | .set_ios = esdhc_set_ios, |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 754 | }; |
| 755 | |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 756 | static int fsl_esdhc_init(struct fsl_esdhc_priv *priv) |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 757 | { |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 758 | struct fsl_esdhc *regs; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 759 | struct mmc *mmc; |
Li Yang | d4933f2 | 2010-11-25 17:06:09 +0000 | [diff] [blame] | 760 | u32 caps, voltage_caps; |
Simon Glass | 81357b5 | 2017-07-29 11:35:19 -0600 | [diff] [blame^] | 761 | int ret; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 762 | |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 763 | if (!priv) |
| 764 | return -EINVAL; |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 765 | |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 766 | regs = priv->esdhc_regs; |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 767 | |
Jerry Huang | b7ef756 | 2010-03-18 15:57:06 -0500 | [diff] [blame] | 768 | /* First reset the eSDHC controller */ |
Simon Glass | 81357b5 | 2017-07-29 11:35:19 -0600 | [diff] [blame^] | 769 | ret = esdhc_reset(regs); |
| 770 | if (ret) |
| 771 | return ret; |
Jerry Huang | b7ef756 | 2010-03-18 15:57:06 -0500 | [diff] [blame] | 772 | |
Eric Nelson | c8e615c | 2015-12-04 12:32:48 -0700 | [diff] [blame] | 773 | #ifndef CONFIG_FSL_USDHC |
Jerry Huang | 4e3bfa0 | 2012-05-17 23:57:02 +0000 | [diff] [blame] | 774 | esdhc_setbits32(®s->sysctl, SYSCTL_PEREN | SYSCTL_HCKEN |
| 775 | | SYSCTL_IPGEN | SYSCTL_CKEN); |
Ye Li | 5a24f29 | 2016-06-15 10:53:01 +0800 | [diff] [blame] | 776 | #else |
| 777 | esdhc_setbits32(®s->vendorspec, VENDORSPEC_PEREN | |
| 778 | VENDORSPEC_HCKEN | VENDORSPEC_IPGEN | VENDORSPEC_CKEN); |
Eric Nelson | c8e615c | 2015-12-04 12:32:48 -0700 | [diff] [blame] | 779 | #endif |
Jerry Huang | 4e3bfa0 | 2012-05-17 23:57:02 +0000 | [diff] [blame] | 780 | |
Peng Fan | aee7858 | 2017-06-12 17:50:53 +0800 | [diff] [blame] | 781 | if (priv->vs18_enable) |
| 782 | esdhc_setbits32(®s->vendorspec, ESDHC_VENDORSPEC_VSELECT); |
| 783 | |
Ye.Li | 3d46c31 | 2014-11-04 15:35:49 +0800 | [diff] [blame] | 784 | writel(SDHCI_IRQ_EN_BITS, ®s->irqstaten); |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 785 | memset(&priv->cfg, 0, sizeof(priv->cfg)); |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 786 | |
Li Yang | d4933f2 | 2010-11-25 17:06:09 +0000 | [diff] [blame] | 787 | voltage_caps = 0; |
Wang Huan | c929213 | 2014-09-05 13:52:40 +0800 | [diff] [blame] | 788 | caps = esdhc_read32(®s->hostcapblt); |
Roy Zang | 3935661 | 2011-01-07 00:06:47 -0600 | [diff] [blame] | 789 | |
| 790 | #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC135 |
| 791 | caps = caps & ~(ESDHC_HOSTCAPBLT_SRS | |
| 792 | ESDHC_HOSTCAPBLT_VS18 | ESDHC_HOSTCAPBLT_VS30); |
| 793 | #endif |
Haijun.Zhang | 8a065e9 | 2013-10-31 09:38:19 +0800 | [diff] [blame] | 794 | |
| 795 | /* T4240 host controller capabilities register should have VS33 bit */ |
| 796 | #ifdef CONFIG_SYS_FSL_MMC_HAS_CAPBLT_VS33 |
| 797 | caps = caps | ESDHC_HOSTCAPBLT_VS33; |
| 798 | #endif |
| 799 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 800 | if (caps & ESDHC_HOSTCAPBLT_VS18) |
Li Yang | d4933f2 | 2010-11-25 17:06:09 +0000 | [diff] [blame] | 801 | voltage_caps |= MMC_VDD_165_195; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 802 | if (caps & ESDHC_HOSTCAPBLT_VS30) |
Li Yang | d4933f2 | 2010-11-25 17:06:09 +0000 | [diff] [blame] | 803 | voltage_caps |= MMC_VDD_29_30 | MMC_VDD_30_31; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 804 | if (caps & ESDHC_HOSTCAPBLT_VS33) |
Li Yang | d4933f2 | 2010-11-25 17:06:09 +0000 | [diff] [blame] | 805 | voltage_caps |= MMC_VDD_32_33 | MMC_VDD_33_34; |
| 806 | |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 807 | priv->cfg.name = "FSL_SDHC"; |
| 808 | priv->cfg.ops = &esdhc_ops; |
Li Yang | d4933f2 | 2010-11-25 17:06:09 +0000 | [diff] [blame] | 809 | #ifdef CONFIG_SYS_SD_VOLTAGE |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 810 | priv->cfg.voltages = CONFIG_SYS_SD_VOLTAGE; |
Li Yang | d4933f2 | 2010-11-25 17:06:09 +0000 | [diff] [blame] | 811 | #else |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 812 | priv->cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34; |
Li Yang | d4933f2 | 2010-11-25 17:06:09 +0000 | [diff] [blame] | 813 | #endif |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 814 | if ((priv->cfg.voltages & voltage_caps) == 0) { |
Li Yang | d4933f2 | 2010-11-25 17:06:09 +0000 | [diff] [blame] | 815 | printf("voltage not supported by controller\n"); |
| 816 | return -1; |
| 817 | } |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 818 | |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 819 | if (priv->bus_width == 8) |
| 820 | priv->cfg.host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT; |
| 821 | else if (priv->bus_width == 4) |
| 822 | priv->cfg.host_caps = MMC_MODE_4BIT; |
| 823 | |
| 824 | priv->cfg.host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT; |
Volodymyr Riazantsev | d251e11 | 2015-01-20 10:16:44 -0500 | [diff] [blame] | 825 | #ifdef CONFIG_SYS_FSL_ESDHC_HAS_DDR_MODE |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 826 | priv->cfg.host_caps |= MMC_MODE_DDR_52MHz; |
Volodymyr Riazantsev | d251e11 | 2015-01-20 10:16:44 -0500 | [diff] [blame] | 827 | #endif |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 828 | |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 829 | if (priv->bus_width > 0) { |
| 830 | if (priv->bus_width < 8) |
| 831 | priv->cfg.host_caps &= ~MMC_MODE_8BIT; |
| 832 | if (priv->bus_width < 4) |
| 833 | priv->cfg.host_caps &= ~MMC_MODE_4BIT; |
Abbas Raza | e6bf977 | 2013-03-25 09:13:34 +0000 | [diff] [blame] | 834 | } |
| 835 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 836 | if (caps & ESDHC_HOSTCAPBLT_HSS) |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 837 | priv->cfg.host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 838 | |
Haijun.Zhang | f0fe8ad | 2014-01-10 13:52:18 +0800 | [diff] [blame] | 839 | #ifdef CONFIG_ESDHC_DETECT_8_BIT_QUIRK |
| 840 | if (CONFIG_ESDHC_DETECT_8_BIT_QUIRK) |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 841 | priv->cfg.host_caps &= ~MMC_MODE_8BIT; |
Haijun.Zhang | f0fe8ad | 2014-01-10 13:52:18 +0800 | [diff] [blame] | 842 | #endif |
| 843 | |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 844 | priv->cfg.f_min = 400000; |
| 845 | priv->cfg.f_max = min(priv->sdhc_clk, (u32)52000000); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 846 | |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 847 | priv->cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 848 | |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 849 | mmc = mmc_create(&priv->cfg, priv); |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 850 | if (mmc == NULL) |
| 851 | return -1; |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 852 | |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 853 | priv->mmc = mmc; |
| 854 | |
| 855 | return 0; |
| 856 | } |
| 857 | |
Jagan Teki | 3c2cc6d | 2017-05-12 17:18:20 +0530 | [diff] [blame] | 858 | #ifndef CONFIG_DM_MMC |
| 859 | static int fsl_esdhc_cfg_to_priv(struct fsl_esdhc_cfg *cfg, |
| 860 | struct fsl_esdhc_priv *priv) |
| 861 | { |
| 862 | if (!cfg || !priv) |
| 863 | return -EINVAL; |
| 864 | |
| 865 | priv->esdhc_regs = (struct fsl_esdhc *)(unsigned long)(cfg->esdhc_base); |
| 866 | priv->bus_width = cfg->max_bus_width; |
| 867 | priv->sdhc_clk = cfg->sdhc_clk; |
| 868 | priv->wp_enable = cfg->wp_enable; |
Peng Fan | aee7858 | 2017-06-12 17:50:53 +0800 | [diff] [blame] | 869 | priv->vs18_enable = cfg->vs18_enable; |
Jagan Teki | 3c2cc6d | 2017-05-12 17:18:20 +0530 | [diff] [blame] | 870 | |
| 871 | return 0; |
| 872 | }; |
| 873 | |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 874 | int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg) |
| 875 | { |
| 876 | struct fsl_esdhc_priv *priv; |
| 877 | int ret; |
| 878 | |
| 879 | if (!cfg) |
| 880 | return -EINVAL; |
| 881 | |
| 882 | priv = calloc(sizeof(struct fsl_esdhc_priv), 1); |
| 883 | if (!priv) |
| 884 | return -ENOMEM; |
| 885 | |
| 886 | ret = fsl_esdhc_cfg_to_priv(cfg, priv); |
| 887 | if (ret) { |
| 888 | debug("%s xlate failure\n", __func__); |
| 889 | free(priv); |
| 890 | return ret; |
| 891 | } |
| 892 | |
| 893 | ret = fsl_esdhc_init(priv); |
| 894 | if (ret) { |
| 895 | debug("%s init failure\n", __func__); |
| 896 | free(priv); |
| 897 | return ret; |
| 898 | } |
| 899 | |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | int fsl_esdhc_mmc_init(bd_t *bis) |
| 904 | { |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 905 | struct fsl_esdhc_cfg *cfg; |
| 906 | |
Fabio Estevam | 6592a99 | 2012-12-27 08:51:08 +0000 | [diff] [blame] | 907 | cfg = calloc(sizeof(struct fsl_esdhc_cfg), 1); |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 908 | cfg->esdhc_base = CONFIG_SYS_FSL_ESDHC_ADDR; |
Simon Glass | 9e247d1 | 2012-12-13 20:49:05 +0000 | [diff] [blame] | 909 | cfg->sdhc_clk = gd->arch.sdhc_clk; |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 910 | return fsl_esdhc_initialize(bis, cfg); |
Andy Fleming | e52ffb8 | 2008-10-30 16:47:16 -0500 | [diff] [blame] | 911 | } |
Jagan Teki | 3c2cc6d | 2017-05-12 17:18:20 +0530 | [diff] [blame] | 912 | #endif |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 913 | |
Yangbo Lu | b124f8a | 2015-04-22 13:57:00 +0800 | [diff] [blame] | 914 | #ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT |
| 915 | void mmc_adapter_card_type_ident(void) |
| 916 | { |
| 917 | u8 card_id; |
| 918 | u8 value; |
| 919 | |
| 920 | card_id = QIXIS_READ(present) & QIXIS_SDID_MASK; |
| 921 | gd->arch.sdhc_adapter = card_id; |
| 922 | |
| 923 | switch (card_id) { |
| 924 | case QIXIS_ESDHC_ADAPTER_TYPE_EMMC45: |
Yangbo Lu | 81eacd6 | 2015-09-17 10:27:12 +0800 | [diff] [blame] | 925 | value = QIXIS_READ(brdcfg[5]); |
| 926 | value |= (QIXIS_DAT4 | QIXIS_DAT5_6_7); |
| 927 | QIXIS_WRITE(brdcfg[5], value); |
Yangbo Lu | b124f8a | 2015-04-22 13:57:00 +0800 | [diff] [blame] | 928 | break; |
| 929 | case QIXIS_ESDHC_ADAPTER_TYPE_SDMMC_LEGACY: |
Yangbo Lu | c6799ce | 2015-09-17 10:27:48 +0800 | [diff] [blame] | 930 | value = QIXIS_READ(pwr_ctl[1]); |
| 931 | value |= QIXIS_EVDD_BY_SDHC_VS; |
| 932 | QIXIS_WRITE(pwr_ctl[1], value); |
Yangbo Lu | b124f8a | 2015-04-22 13:57:00 +0800 | [diff] [blame] | 933 | break; |
| 934 | case QIXIS_ESDHC_ADAPTER_TYPE_EMMC44: |
| 935 | value = QIXIS_READ(brdcfg[5]); |
| 936 | value |= (QIXIS_SDCLKIN | QIXIS_SDCLKOUT); |
| 937 | QIXIS_WRITE(brdcfg[5], value); |
| 938 | break; |
| 939 | case QIXIS_ESDHC_ADAPTER_TYPE_RSV: |
| 940 | break; |
| 941 | case QIXIS_ESDHC_ADAPTER_TYPE_MMC: |
| 942 | break; |
| 943 | case QIXIS_ESDHC_ADAPTER_TYPE_SD: |
| 944 | break; |
| 945 | case QIXIS_ESDHC_NO_ADAPTER: |
| 946 | break; |
| 947 | default: |
| 948 | break; |
| 949 | } |
| 950 | } |
| 951 | #endif |
| 952 | |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 953 | #ifdef CONFIG_OF_LIBFDT |
Yangbo Lu | d84139c | 2017-01-17 10:43:54 +0800 | [diff] [blame] | 954 | __weak int esdhc_status_fixup(void *blob, const char *compat) |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 955 | { |
Chenhui Zhao | 025eab0 | 2011-01-04 17:23:05 +0800 | [diff] [blame] | 956 | #ifdef CONFIG_FSL_ESDHC_PIN_MUX |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 957 | if (!hwconfig("esdhc")) { |
Chenhui Zhao | 025eab0 | 2011-01-04 17:23:05 +0800 | [diff] [blame] | 958 | do_fixup_by_compat(blob, compat, "status", "disabled", |
Yangbo Lu | d84139c | 2017-01-17 10:43:54 +0800 | [diff] [blame] | 959 | sizeof("disabled"), 1); |
| 960 | return 1; |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 961 | } |
Chenhui Zhao | 025eab0 | 2011-01-04 17:23:05 +0800 | [diff] [blame] | 962 | #endif |
Yangbo Lu | d84139c | 2017-01-17 10:43:54 +0800 | [diff] [blame] | 963 | return 0; |
| 964 | } |
| 965 | |
| 966 | void fdt_fixup_esdhc(void *blob, bd_t *bd) |
| 967 | { |
| 968 | const char *compat = "fsl,esdhc"; |
| 969 | |
| 970 | if (esdhc_status_fixup(blob, compat)) |
| 971 | return; |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 972 | |
Yangbo Lu | 163beec | 2015-04-22 13:57:40 +0800 | [diff] [blame] | 973 | #ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK |
| 974 | do_fixup_by_compat_u32(blob, compat, "peripheral-frequency", |
| 975 | gd->arch.sdhc_clk, 1); |
| 976 | #else |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 977 | do_fixup_by_compat_u32(blob, compat, "clock-frequency", |
Simon Glass | 9e247d1 | 2012-12-13 20:49:05 +0000 | [diff] [blame] | 978 | gd->arch.sdhc_clk, 1); |
Yangbo Lu | 163beec | 2015-04-22 13:57:40 +0800 | [diff] [blame] | 979 | #endif |
Yangbo Lu | b124f8a | 2015-04-22 13:57:00 +0800 | [diff] [blame] | 980 | #ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT |
| 981 | do_fixup_by_compat_u32(blob, compat, "adapter-type", |
| 982 | (u32)(gd->arch.sdhc_adapter), 1); |
| 983 | #endif |
Anton Vorontsov | f751a3c | 2009-06-10 00:25:29 +0400 | [diff] [blame] | 984 | } |
Stefano Babic | ff7a5ca | 2010-02-05 15:11:27 +0100 | [diff] [blame] | 985 | #endif |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 986 | |
| 987 | #ifdef CONFIG_DM_MMC |
| 988 | #include <asm/arch/clock.h> |
Peng Fan | af6dbc0 | 2017-02-22 16:21:55 +0800 | [diff] [blame] | 989 | __weak void init_clk_usdhc(u32 index) |
| 990 | { |
| 991 | } |
| 992 | |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 993 | static int fsl_esdhc_probe(struct udevice *dev) |
| 994 | { |
| 995 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 996 | struct fsl_esdhc_priv *priv = dev_get_priv(dev); |
| 997 | const void *fdt = gd->fdt_blob; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 998 | int node = dev_of_offset(dev); |
York Sun | 107a5e4 | 2017-08-08 15:45:13 -0700 | [diff] [blame] | 999 | #ifdef CONFIG_DM_REGULATOR |
Peng Fan | 5eb8b43 | 2017-06-12 17:50:54 +0800 | [diff] [blame] | 1000 | struct udevice *vqmmc_dev; |
York Sun | 107a5e4 | 2017-08-08 15:45:13 -0700 | [diff] [blame] | 1001 | #endif |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 1002 | fdt_addr_t addr; |
| 1003 | unsigned int val; |
| 1004 | int ret; |
| 1005 | |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 1006 | addr = devfdt_get_addr(dev); |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 1007 | if (addr == FDT_ADDR_T_NONE) |
| 1008 | return -EINVAL; |
| 1009 | |
| 1010 | priv->esdhc_regs = (struct fsl_esdhc *)addr; |
| 1011 | priv->dev = dev; |
| 1012 | |
| 1013 | val = fdtdec_get_int(fdt, node, "bus-width", -1); |
| 1014 | if (val == 8) |
| 1015 | priv->bus_width = 8; |
| 1016 | else if (val == 4) |
| 1017 | priv->bus_width = 4; |
| 1018 | else |
| 1019 | priv->bus_width = 1; |
| 1020 | |
| 1021 | if (fdt_get_property(fdt, node, "non-removable", NULL)) { |
| 1022 | priv->non_removable = 1; |
| 1023 | } else { |
| 1024 | priv->non_removable = 0; |
Yangbo Lu | b99647c | 2016-12-07 11:54:30 +0800 | [diff] [blame] | 1025 | #ifdef CONFIG_DM_GPIO |
Simon Glass | 1d9af1f | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 1026 | gpio_request_by_name_nodev(offset_to_ofnode(node), "cd-gpios", |
| 1027 | 0, &priv->cd_gpio, GPIOD_IS_IN); |
Yangbo Lu | b99647c | 2016-12-07 11:54:30 +0800 | [diff] [blame] | 1028 | #endif |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 1029 | } |
| 1030 | |
Peng Fan | 01eb1c4 | 2016-06-15 10:53:02 +0800 | [diff] [blame] | 1031 | priv->wp_enable = 1; |
| 1032 | |
Yangbo Lu | b99647c | 2016-12-07 11:54:30 +0800 | [diff] [blame] | 1033 | #ifdef CONFIG_DM_GPIO |
Simon Glass | 1d9af1f | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 1034 | ret = gpio_request_by_name_nodev(offset_to_ofnode(node), "wp-gpios", 0, |
Peng Fan | 01eb1c4 | 2016-06-15 10:53:02 +0800 | [diff] [blame] | 1035 | &priv->wp_gpio, GPIOD_IS_IN); |
| 1036 | if (ret) |
| 1037 | priv->wp_enable = 0; |
Yangbo Lu | b99647c | 2016-12-07 11:54:30 +0800 | [diff] [blame] | 1038 | #endif |
Peng Fan | 5eb8b43 | 2017-06-12 17:50:54 +0800 | [diff] [blame] | 1039 | |
| 1040 | priv->vs18_enable = 0; |
| 1041 | |
| 1042 | #ifdef CONFIG_DM_REGULATOR |
| 1043 | /* |
| 1044 | * If emmc I/O has a fixed voltage at 1.8V, this must be provided, |
| 1045 | * otherwise, emmc will work abnormally. |
| 1046 | */ |
| 1047 | ret = device_get_supply_regulator(dev, "vqmmc-supply", &vqmmc_dev); |
| 1048 | if (ret) { |
| 1049 | dev_dbg(dev, "no vqmmc-supply\n"); |
| 1050 | } else { |
| 1051 | ret = regulator_set_enable(vqmmc_dev, true); |
| 1052 | if (ret) { |
| 1053 | dev_err(dev, "fail to enable vqmmc-supply\n"); |
| 1054 | return ret; |
| 1055 | } |
| 1056 | |
| 1057 | if (regulator_get_value(vqmmc_dev) == 1800000) |
| 1058 | priv->vs18_enable = 1; |
| 1059 | } |
| 1060 | #endif |
| 1061 | |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 1062 | /* |
| 1063 | * TODO: |
| 1064 | * Because lack of clk driver, if SDHC clk is not enabled, |
| 1065 | * need to enable it first before this driver is invoked. |
| 1066 | * |
| 1067 | * we use MXC_ESDHC_CLK to get clk freq. |
| 1068 | * If one would like to make this function work, |
| 1069 | * the aliases should be provided in dts as this: |
| 1070 | * |
| 1071 | * aliases { |
| 1072 | * mmc0 = &usdhc1; |
| 1073 | * mmc1 = &usdhc2; |
| 1074 | * mmc2 = &usdhc3; |
| 1075 | * mmc3 = &usdhc4; |
| 1076 | * }; |
| 1077 | * Then if your board only supports mmc2 and mmc3, but we can |
| 1078 | * correctly get the seq as 2 and 3, then let mxc_get_clock |
| 1079 | * work as expected. |
| 1080 | */ |
Peng Fan | af6dbc0 | 2017-02-22 16:21:55 +0800 | [diff] [blame] | 1081 | |
| 1082 | init_clk_usdhc(dev->seq); |
| 1083 | |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 1084 | priv->sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK + dev->seq); |
| 1085 | if (priv->sdhc_clk <= 0) { |
| 1086 | dev_err(dev, "Unable to get clk for %s\n", dev->name); |
| 1087 | return -EINVAL; |
| 1088 | } |
| 1089 | |
| 1090 | ret = fsl_esdhc_init(priv); |
| 1091 | if (ret) { |
| 1092 | dev_err(dev, "fsl_esdhc_init failure\n"); |
| 1093 | return ret; |
| 1094 | } |
| 1095 | |
| 1096 | upriv->mmc = priv->mmc; |
Peng Fan | d0a0c1d | 2016-08-11 14:02:56 +0800 | [diff] [blame] | 1097 | priv->mmc->dev = dev; |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 1098 | |
| 1099 | return 0; |
| 1100 | } |
| 1101 | |
| 1102 | static const struct udevice_id fsl_esdhc_ids[] = { |
| 1103 | { .compatible = "fsl,imx6ul-usdhc", }, |
| 1104 | { .compatible = "fsl,imx6sx-usdhc", }, |
| 1105 | { .compatible = "fsl,imx6sl-usdhc", }, |
| 1106 | { .compatible = "fsl,imx6q-usdhc", }, |
| 1107 | { .compatible = "fsl,imx7d-usdhc", }, |
Peng Fan | af6dbc0 | 2017-02-22 16:21:55 +0800 | [diff] [blame] | 1108 | { .compatible = "fsl,imx7ulp-usdhc", }, |
Yangbo Lu | 2a99b60 | 2016-12-07 11:54:31 +0800 | [diff] [blame] | 1109 | { .compatible = "fsl,esdhc", }, |
Peng Fan | a4d36f7 | 2016-03-25 14:16:56 +0800 | [diff] [blame] | 1110 | { /* sentinel */ } |
| 1111 | }; |
| 1112 | |
| 1113 | U_BOOT_DRIVER(fsl_esdhc) = { |
| 1114 | .name = "fsl-esdhc-mmc", |
| 1115 | .id = UCLASS_MMC, |
| 1116 | .of_match = fsl_esdhc_ids, |
| 1117 | .probe = fsl_esdhc_probe, |
| 1118 | .priv_auto_alloc_size = sizeof(struct fsl_esdhc_priv), |
| 1119 | }; |
| 1120 | #endif |