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