blob: 0510bf02f41bbf28d2b93ed0ae4f958da358d230 [file] [log] [blame]
Andy Fleming50586ef2008-10-30 16:47:16 -05001/*
Jerry Huangd621da02011-01-06 23:42:19 -06002 * Copyright 2007, 2010-2011 Freescale Semiconductor, Inc
Andy Fleming50586ef2008-10-30 16:47:16 -05003 * 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 Denk1a459662013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Andy Fleming50586ef2008-10-30 16:47:16 -050010 */
11
12#include <config.h>
13#include <common.h>
14#include <command.h>
Anton Vorontsovb33433a2009-06-10 00:25:29 +040015#include <hwconfig.h>
Andy Fleming50586ef2008-10-30 16:47:16 -050016#include <mmc.h>
17#include <part.h>
18#include <malloc.h>
19#include <mmc.h>
20#include <fsl_esdhc.h>
Anton Vorontsovb33433a2009-06-10 00:25:29 +040021#include <fdt_support.h>
Andy Fleming50586ef2008-10-30 16:47:16 -050022#include <asm/io.h>
23
Andy Fleming50586ef2008-10-30 16:47:16 -050024DECLARE_GLOBAL_DATA_PTR;
25
Ye.Lia3d6e382014-11-04 15:35:49 +080026#define SDHCI_IRQ_EN_BITS (IRQSTATEN_CC | IRQSTATEN_TC | \
27 IRQSTATEN_CINT | \
28 IRQSTATEN_CTOE | IRQSTATEN_CCE | IRQSTATEN_CEBE | \
29 IRQSTATEN_CIE | IRQSTATEN_DTOE | IRQSTATEN_DCE | \
30 IRQSTATEN_DEBE | IRQSTATEN_BRR | IRQSTATEN_BWR | \
31 IRQSTATEN_DINT)
32
Andy Fleming50586ef2008-10-30 16:47:16 -050033struct fsl_esdhc {
Haijun.Zhang511948b2013-10-30 11:37:55 +080034 uint dsaddr; /* SDMA system address register */
35 uint blkattr; /* Block attributes register */
36 uint cmdarg; /* Command argument register */
37 uint xfertyp; /* Transfer type register */
38 uint cmdrsp0; /* Command response 0 register */
39 uint cmdrsp1; /* Command response 1 register */
40 uint cmdrsp2; /* Command response 2 register */
41 uint cmdrsp3; /* Command response 3 register */
42 uint datport; /* Buffer data port register */
43 uint prsstat; /* Present state register */
44 uint proctl; /* Protocol control register */
45 uint sysctl; /* System Control Register */
46 uint irqstat; /* Interrupt status register */
47 uint irqstaten; /* Interrupt status enable register */
48 uint irqsigen; /* Interrupt signal enable register */
49 uint autoc12err; /* Auto CMD error status register */
50 uint hostcapblt; /* Host controller capabilities register */
51 uint wml; /* Watermark level register */
52 uint mixctrl; /* For USDHC */
53 char reserved1[4]; /* reserved */
54 uint fevt; /* Force event register */
55 uint admaes; /* ADMA error status register */
56 uint adsaddr; /* ADMA system address register */
Otavio Salvadorf022d362015-02-17 10:42:43 -020057 char reserved2[100]; /* reserved */
58 uint vendorspec; /* Vendor Specific register */
Peng Fan323aaaa2015-03-10 15:35:46 +080059 char reserved3[56]; /* reserved */
Haijun.Zhang511948b2013-10-30 11:37:55 +080060 uint hostver; /* Host controller version register */
Haijun.Zhang511948b2013-10-30 11:37:55 +080061 char reserved4[4]; /* reserved */
Otavio Salvadorf022d362015-02-17 10:42:43 -020062 uint dmaerraddr; /* DMA error address register */
Haijun.Zhang511948b2013-10-30 11:37:55 +080063 char reserved5[4]; /* reserved */
Otavio Salvadorf022d362015-02-17 10:42:43 -020064 uint dmaerrattr; /* DMA error attribute register */
65 char reserved6[4]; /* reserved */
Haijun.Zhang511948b2013-10-30 11:37:55 +080066 uint hostcapblt2; /* Host controller capabilities register 2 */
Otavio Salvadorf022d362015-02-17 10:42:43 -020067 char reserved7[8]; /* reserved */
Haijun.Zhang511948b2013-10-30 11:37:55 +080068 uint tcr; /* Tuning control register */
Otavio Salvadorf022d362015-02-17 10:42:43 -020069 char reserved8[28]; /* reserved */
Haijun.Zhang511948b2013-10-30 11:37:55 +080070 uint sddirctl; /* SD direction control register */
Otavio Salvadorf022d362015-02-17 10:42:43 -020071 char reserved9[712]; /* reserved */
Haijun.Zhang511948b2013-10-30 11:37:55 +080072 uint scr; /* eSDHC control register */
Andy Fleming50586ef2008-10-30 16:47:16 -050073};
74
75/* Return the XFERTYP flags for a given command and data packet */
Kim Phillipseafa90a2012-10-29 13:34:44 +000076static uint esdhc_xfertyp(struct mmc_cmd *cmd, struct mmc_data *data)
Andy Fleming50586ef2008-10-30 16:47:16 -050077{
78 uint xfertyp = 0;
79
80 if (data) {
Dipen Dudhat77c14582009-10-05 15:41:58 +053081 xfertyp |= XFERTYP_DPSEL;
82#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
83 xfertyp |= XFERTYP_DMAEN;
84#endif
Andy Fleming50586ef2008-10-30 16:47:16 -050085 if (data->blocks > 1) {
86 xfertyp |= XFERTYP_MSBSEL;
87 xfertyp |= XFERTYP_BCEN;
Jerry Huangd621da02011-01-06 23:42:19 -060088#ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
89 xfertyp |= XFERTYP_AC12EN;
90#endif
Andy Fleming50586ef2008-10-30 16:47:16 -050091 }
92
93 if (data->flags & MMC_DATA_READ)
94 xfertyp |= XFERTYP_DTDSEL;
95 }
96
97 if (cmd->resp_type & MMC_RSP_CRC)
98 xfertyp |= XFERTYP_CCCEN;
99 if (cmd->resp_type & MMC_RSP_OPCODE)
100 xfertyp |= XFERTYP_CICEN;
101 if (cmd->resp_type & MMC_RSP_136)
102 xfertyp |= XFERTYP_RSPTYP_136;
103 else if (cmd->resp_type & MMC_RSP_BUSY)
104 xfertyp |= XFERTYP_RSPTYP_48_BUSY;
105 else if (cmd->resp_type & MMC_RSP_PRESENT)
106 xfertyp |= XFERTYP_RSPTYP_48;
107
Yangbo Lu8b064602015-03-20 19:28:31 -0700108#if defined(CONFIG_MX53) || defined(CONFIG_PPC_T4240) || \
109 defined(CONFIG_LS102XA) || defined(CONFIG_LS2085A)
Jason Liu4571de32011-03-22 01:32:31 +0000110 if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
111 xfertyp |= XFERTYP_CMDTYP_ABORT;
112#endif
Andy Fleming50586ef2008-10-30 16:47:16 -0500113 return XFERTYP_CMD(cmd->cmdidx) | xfertyp;
114}
115
Dipen Dudhat77c14582009-10-05 15:41:58 +0530116#ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO
117/*
118 * PIO Read/Write Mode reduce the performace as DMA is not used in this mode.
119 */
Wolfgang Denk7b43db92010-05-09 23:52:59 +0200120static void
Dipen Dudhat77c14582009-10-05 15:41:58 +0530121esdhc_pio_read_write(struct mmc *mmc, struct mmc_data *data)
122{
Ira Snyder8eee2bd2011-12-23 08:30:40 +0000123 struct fsl_esdhc_cfg *cfg = mmc->priv;
124 struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
Dipen Dudhat77c14582009-10-05 15:41:58 +0530125 uint blocks;
126 char *buffer;
127 uint databuf;
128 uint size;
129 uint irqstat;
130 uint timeout;
131
132 if (data->flags & MMC_DATA_READ) {
133 blocks = data->blocks;
134 buffer = data->dest;
135 while (blocks) {
136 timeout = PIO_TIMEOUT;
137 size = data->blocksize;
138 irqstat = esdhc_read32(&regs->irqstat);
139 while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BREN)
140 && --timeout);
141 if (timeout <= 0) {
142 printf("\nData Read Failed in PIO Mode.");
Wolfgang Denk7b43db92010-05-09 23:52:59 +0200143 return;
Dipen Dudhat77c14582009-10-05 15:41:58 +0530144 }
145 while (size && (!(irqstat & IRQSTAT_TC))) {
146 udelay(100); /* Wait before last byte transfer complete */
147 irqstat = esdhc_read32(&regs->irqstat);
148 databuf = in_le32(&regs->datport);
149 *((uint *)buffer) = databuf;
150 buffer += 4;
151 size -= 4;
152 }
153 blocks--;
154 }
155 } else {
156 blocks = data->blocks;
Wolfgang Denk7b43db92010-05-09 23:52:59 +0200157 buffer = (char *)data->src;
Dipen Dudhat77c14582009-10-05 15:41:58 +0530158 while (blocks) {
159 timeout = PIO_TIMEOUT;
160 size = data->blocksize;
161 irqstat = esdhc_read32(&regs->irqstat);
162 while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BWEN)
163 && --timeout);
164 if (timeout <= 0) {
165 printf("\nData Write Failed in PIO Mode.");
Wolfgang Denk7b43db92010-05-09 23:52:59 +0200166 return;
Dipen Dudhat77c14582009-10-05 15:41:58 +0530167 }
168 while (size && (!(irqstat & IRQSTAT_TC))) {
169 udelay(100); /* Wait before last byte transfer complete */
170 databuf = *((uint *)buffer);
171 buffer += 4;
172 size -= 4;
173 irqstat = esdhc_read32(&regs->irqstat);
174 out_le32(&regs->datport, databuf);
175 }
176 blocks--;
177 }
178 }
179}
180#endif
181
Andy Fleming50586ef2008-10-30 16:47:16 -0500182static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
183{
Andy Fleming50586ef2008-10-30 16:47:16 -0500184 int timeout;
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200185 struct fsl_esdhc_cfg *cfg = mmc->priv;
Stefano Babicc67bee12010-02-05 15:11:27 +0100186 struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
Yangbo Lu8b064602015-03-20 19:28:31 -0700187#ifdef CONFIG_LS2085A
188 dma_addr_t addr;
189#endif
Wolfgang Denk7b43db92010-05-09 23:52:59 +0200190 uint wml_value;
Andy Fleming50586ef2008-10-30 16:47:16 -0500191
192 wml_value = data->blocksize/4;
193
194 if (data->flags & MMC_DATA_READ) {
Priyanka Jain32c8cfb2011-02-09 09:24:10 +0530195 if (wml_value > WML_RD_WML_MAX)
196 wml_value = WML_RD_WML_MAX_VAL;
Andy Fleming50586ef2008-10-30 16:47:16 -0500197
Roy Zangab467c52010-02-09 18:23:33 +0800198 esdhc_clrsetbits32(&regs->wml, WML_RD_WML_MASK, wml_value);
Ye.Li71689772014-02-20 18:00:57 +0800199#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
Yangbo Lu8b064602015-03-20 19:28:31 -0700200#ifdef CONFIG_LS2085A
201 addr = virt_to_phys((void *)(data->dest));
202 if (upper_32_bits(addr))
203 printf("Error found for upper 32 bits\n");
204 else
205 esdhc_write32(&regs->dsaddr, lower_32_bits(addr));
206#else
Stefano Babicc67bee12010-02-05 15:11:27 +0100207 esdhc_write32(&regs->dsaddr, (u32)data->dest);
Ye.Li71689772014-02-20 18:00:57 +0800208#endif
Yangbo Lu8b064602015-03-20 19:28:31 -0700209#endif
Andy Fleming50586ef2008-10-30 16:47:16 -0500210 } else {
Ye.Li71689772014-02-20 18:00:57 +0800211#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
Eric Nelsone576bd92012-04-25 14:28:48 +0000212 flush_dcache_range((ulong)data->src,
213 (ulong)data->src+data->blocks
214 *data->blocksize);
Ye.Li71689772014-02-20 18:00:57 +0800215#endif
Priyanka Jain32c8cfb2011-02-09 09:24:10 +0530216 if (wml_value > WML_WR_WML_MAX)
217 wml_value = WML_WR_WML_MAX_VAL;
Stefano Babicc67bee12010-02-05 15:11:27 +0100218 if ((esdhc_read32(&regs->prsstat) & PRSSTAT_WPSPL) == 0) {
Andy Fleming50586ef2008-10-30 16:47:16 -0500219 printf("\nThe SD card is locked. Can not write to a locked card.\n\n");
220 return TIMEOUT;
221 }
Roy Zangab467c52010-02-09 18:23:33 +0800222
223 esdhc_clrsetbits32(&regs->wml, WML_WR_WML_MASK,
224 wml_value << 16);
Ye.Li71689772014-02-20 18:00:57 +0800225#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
Yangbo Lu8b064602015-03-20 19:28:31 -0700226#ifdef CONFIG_LS2085A
227 addr = virt_to_phys((void *)(data->src));
228 if (upper_32_bits(addr))
229 printf("Error found for upper 32 bits\n");
230 else
231 esdhc_write32(&regs->dsaddr, lower_32_bits(addr));
232#else
Stefano Babicc67bee12010-02-05 15:11:27 +0100233 esdhc_write32(&regs->dsaddr, (u32)data->src);
Ye.Li71689772014-02-20 18:00:57 +0800234#endif
Yangbo Lu8b064602015-03-20 19:28:31 -0700235#endif
Andy Fleming50586ef2008-10-30 16:47:16 -0500236 }
237
Stefano Babicc67bee12010-02-05 15:11:27 +0100238 esdhc_write32(&regs->blkattr, data->blocks << 16 | data->blocksize);
Andy Fleming50586ef2008-10-30 16:47:16 -0500239
240 /* Calculate the timeout period for data transactions */
Priyanka Jainb71ea332011-03-03 09:18:56 +0530241 /*
242 * 1)Timeout period = (2^(timeout+13)) SD Clock cycles
243 * 2)Timeout period should be minimum 0.250sec as per SD Card spec
244 * So, Number of SD Clock cycles for 0.25sec should be minimum
245 * (SD Clock/sec * 0.25 sec) SD Clock cycles
Andrew Gabbasovfb823982014-03-24 02:40:41 -0500246 * = (mmc->clock * 1/4) SD Clock cycles
Priyanka Jainb71ea332011-03-03 09:18:56 +0530247 * As 1) >= 2)
Andrew Gabbasovfb823982014-03-24 02:40:41 -0500248 * => (2^(timeout+13)) >= mmc->clock * 1/4
Priyanka Jainb71ea332011-03-03 09:18:56 +0530249 * Taking log2 both the sides
Andrew Gabbasovfb823982014-03-24 02:40:41 -0500250 * => timeout + 13 >= log2(mmc->clock/4)
Priyanka Jainb71ea332011-03-03 09:18:56 +0530251 * Rounding up to next power of 2
Andrew Gabbasovfb823982014-03-24 02:40:41 -0500252 * => timeout + 13 = log2(mmc->clock/4) + 1
253 * => timeout + 13 = fls(mmc->clock/4)
Priyanka Jainb71ea332011-03-03 09:18:56 +0530254 */
Andrew Gabbasovfb823982014-03-24 02:40:41 -0500255 timeout = fls(mmc->clock/4);
Andy Fleming50586ef2008-10-30 16:47:16 -0500256 timeout -= 13;
257
258 if (timeout > 14)
259 timeout = 14;
260
261 if (timeout < 0)
262 timeout = 0;
263
Kumar Gala5103a032011-01-29 15:36:10 -0600264#ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC_A001
265 if ((timeout == 4) || (timeout == 8) || (timeout == 12))
266 timeout++;
267#endif
268
Haijun.Zhang1336e2d2014-03-18 17:04:23 +0800269#ifdef ESDHCI_QUIRK_BROKEN_TIMEOUT_VALUE
270 timeout = 0xE;
271#endif
Stefano Babicc67bee12010-02-05 15:11:27 +0100272 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, timeout << 16);
Andy Fleming50586ef2008-10-30 16:47:16 -0500273
274 return 0;
275}
276
Tom Rini10dc7772014-05-23 09:19:05 -0400277#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
Eric Nelsone576bd92012-04-25 14:28:48 +0000278static void check_and_invalidate_dcache_range
279 (struct mmc_cmd *cmd,
280 struct mmc_data *data) {
Yangbo Lu8b064602015-03-20 19:28:31 -0700281#ifdef CONFIG_LS2085A
282 unsigned start = 0;
283#else
Eric Nelsone576bd92012-04-25 14:28:48 +0000284 unsigned start = (unsigned)data->dest ;
Yangbo Lu8b064602015-03-20 19:28:31 -0700285#endif
Eric Nelsone576bd92012-04-25 14:28:48 +0000286 unsigned size = roundup(ARCH_DMA_MINALIGN,
287 data->blocks*data->blocksize);
288 unsigned end = start+size ;
Yangbo Lu8b064602015-03-20 19:28:31 -0700289#ifdef CONFIG_LS2085A
290 dma_addr_t addr;
291
292 addr = virt_to_phys((void *)(data->dest));
293 if (upper_32_bits(addr))
294 printf("Error found for upper 32 bits\n");
295 else
296 start = lower_32_bits(addr);
297#endif
Eric Nelsone576bd92012-04-25 14:28:48 +0000298 invalidate_dcache_range(start, end);
299}
Tom Rini10dc7772014-05-23 09:19:05 -0400300#endif
301
Andy Fleming50586ef2008-10-30 16:47:16 -0500302/*
303 * Sends a command out on the bus. Takes the mmc pointer,
304 * a command pointer, and an optional data pointer.
305 */
306static int
307esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
308{
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500309 int err = 0;
Andy Fleming50586ef2008-10-30 16:47:16 -0500310 uint xfertyp;
311 uint irqstat;
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200312 struct fsl_esdhc_cfg *cfg = mmc->priv;
Stefano Babicc67bee12010-02-05 15:11:27 +0100313 volatile struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
Andy Fleming50586ef2008-10-30 16:47:16 -0500314
Jerry Huangd621da02011-01-06 23:42:19 -0600315#ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
316 if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
317 return 0;
318#endif
319
Stefano Babicc67bee12010-02-05 15:11:27 +0100320 esdhc_write32(&regs->irqstat, -1);
Andy Fleming50586ef2008-10-30 16:47:16 -0500321
322 sync();
323
324 /* Wait for the bus to be idle */
Stefano Babicc67bee12010-02-05 15:11:27 +0100325 while ((esdhc_read32(&regs->prsstat) & PRSSTAT_CICHB) ||
326 (esdhc_read32(&regs->prsstat) & PRSSTAT_CIDHB))
327 ;
Andy Fleming50586ef2008-10-30 16:47:16 -0500328
Stefano Babicc67bee12010-02-05 15:11:27 +0100329 while (esdhc_read32(&regs->prsstat) & PRSSTAT_DLA)
330 ;
Andy Fleming50586ef2008-10-30 16:47:16 -0500331
332 /* Wait at least 8 SD clock cycles before the next command */
333 /*
334 * Note: This is way more than 8 cycles, but 1ms seems to
335 * resolve timing issues with some cards
336 */
337 udelay(1000);
338
339 /* Set up for a data transfer if we have one */
340 if (data) {
Andy Fleming50586ef2008-10-30 16:47:16 -0500341 err = esdhc_setup_data(mmc, data);
342 if(err)
343 return err;
Peng Fan4683b222015-06-25 10:32:26 +0800344
345 if (data->flags & MMC_DATA_READ)
346 check_and_invalidate_dcache_range(cmd, data);
Andy Fleming50586ef2008-10-30 16:47:16 -0500347 }
348
349 /* Figure out the transfer arguments */
350 xfertyp = esdhc_xfertyp(cmd, data);
351
Andrew Gabbasov01b77352013-06-11 10:34:22 -0500352 /* Mask all irqs */
353 esdhc_write32(&regs->irqsigen, 0);
354
Andy Fleming50586ef2008-10-30 16:47:16 -0500355 /* Send the command */
Stefano Babicc67bee12010-02-05 15:11:27 +0100356 esdhc_write32(&regs->cmdarg, cmd->cmdarg);
Jason Liu46927082011-11-25 00:18:04 +0000357#if defined(CONFIG_FSL_USDHC)
358 esdhc_write32(&regs->mixctrl,
Volodymyr Riazantsev0e1bf612015-01-20 10:16:44 -0500359 (esdhc_read32(&regs->mixctrl) & 0xFFFFFF80) | (xfertyp & 0x7F)
360 | (mmc->ddr_mode ? XFERTYP_DDREN : 0));
Jason Liu46927082011-11-25 00:18:04 +0000361 esdhc_write32(&regs->xfertyp, xfertyp & 0xFFFF0000);
362#else
Stefano Babicc67bee12010-02-05 15:11:27 +0100363 esdhc_write32(&regs->xfertyp, xfertyp);
Jason Liu46927082011-11-25 00:18:04 +0000364#endif
Dirk Behme7a5b8022012-03-26 03:13:05 +0000365
Andy Fleming50586ef2008-10-30 16:47:16 -0500366 /* Wait for the command to complete */
Dirk Behme7a5b8022012-03-26 03:13:05 +0000367 while (!(esdhc_read32(&regs->irqstat) & (IRQSTAT_CC | IRQSTAT_CTOE)))
Stefano Babicc67bee12010-02-05 15:11:27 +0100368 ;
Andy Fleming50586ef2008-10-30 16:47:16 -0500369
Stefano Babicc67bee12010-02-05 15:11:27 +0100370 irqstat = esdhc_read32(&regs->irqstat);
Andy Fleming50586ef2008-10-30 16:47:16 -0500371
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500372 if (irqstat & CMD_ERR) {
373 err = COMM_ERR;
374 goto out;
Dirk Behme7a5b8022012-03-26 03:13:05 +0000375 }
376
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500377 if (irqstat & IRQSTAT_CTOE) {
378 err = TIMEOUT;
379 goto out;
380 }
Andy Fleming50586ef2008-10-30 16:47:16 -0500381
Otavio Salvadorf022d362015-02-17 10:42:43 -0200382 /* Switch voltage to 1.8V if CMD11 succeeded */
383 if (cmd->cmdidx == SD_CMD_SWITCH_UHS18V) {
384 esdhc_setbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
385
386 printf("Run CMD11 1.8V switch\n");
387 /* Sleep for 5 ms - max time for card to switch to 1.8V */
388 udelay(5000);
389 }
390
Dirk Behme7a5b8022012-03-26 03:13:05 +0000391 /* Workaround for ESDHC errata ENGcm03648 */
392 if (!data && (cmd->resp_type & MMC_RSP_BUSY)) {
Yangbo Lu253d5bd2015-04-15 10:13:12 +0800393 int timeout = 6000;
Dirk Behme7a5b8022012-03-26 03:13:05 +0000394
Yangbo Lu253d5bd2015-04-15 10:13:12 +0800395 /* Poll on DATA0 line for cmd with busy signal for 600 ms */
Dirk Behme7a5b8022012-03-26 03:13:05 +0000396 while (timeout > 0 && !(esdhc_read32(&regs->prsstat) &
397 PRSSTAT_DAT0)) {
398 udelay(100);
399 timeout--;
400 }
401
402 if (timeout <= 0) {
403 printf("Timeout waiting for DAT0 to go high!\n");
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500404 err = TIMEOUT;
405 goto out;
Dirk Behme7a5b8022012-03-26 03:13:05 +0000406 }
407 }
408
Andy Fleming50586ef2008-10-30 16:47:16 -0500409 /* Copy the response to the response buffer */
410 if (cmd->resp_type & MMC_RSP_136) {
411 u32 cmdrsp3, cmdrsp2, cmdrsp1, cmdrsp0;
412
Stefano Babicc67bee12010-02-05 15:11:27 +0100413 cmdrsp3 = esdhc_read32(&regs->cmdrsp3);
414 cmdrsp2 = esdhc_read32(&regs->cmdrsp2);
415 cmdrsp1 = esdhc_read32(&regs->cmdrsp1);
416 cmdrsp0 = esdhc_read32(&regs->cmdrsp0);
Rabin Vincent998be3d2009-04-05 13:30:56 +0530417 cmd->response[0] = (cmdrsp3 << 8) | (cmdrsp2 >> 24);
418 cmd->response[1] = (cmdrsp2 << 8) | (cmdrsp1 >> 24);
419 cmd->response[2] = (cmdrsp1 << 8) | (cmdrsp0 >> 24);
420 cmd->response[3] = (cmdrsp0 << 8);
Andy Fleming50586ef2008-10-30 16:47:16 -0500421 } else
Stefano Babicc67bee12010-02-05 15:11:27 +0100422 cmd->response[0] = esdhc_read32(&regs->cmdrsp0);
Andy Fleming50586ef2008-10-30 16:47:16 -0500423
424 /* Wait until all of the blocks are transferred */
425 if (data) {
Dipen Dudhat77c14582009-10-05 15:41:58 +0530426#ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO
427 esdhc_pio_read_write(mmc, data);
428#else
Andy Fleming50586ef2008-10-30 16:47:16 -0500429 do {
Stefano Babicc67bee12010-02-05 15:11:27 +0100430 irqstat = esdhc_read32(&regs->irqstat);
Andy Fleming50586ef2008-10-30 16:47:16 -0500431
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500432 if (irqstat & IRQSTAT_DTOE) {
433 err = TIMEOUT;
434 goto out;
435 }
Frans Meulenbroeks63fb5a72010-07-31 04:45:18 +0000436
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500437 if (irqstat & DATA_ERR) {
438 err = COMM_ERR;
439 goto out;
440 }
Andrew Gabbasov9b74dc52013-04-07 23:06:08 +0000441 } while ((irqstat & DATA_COMPLETE) != DATA_COMPLETE);
Ye.Li71689772014-02-20 18:00:57 +0800442
Peng Fan4683b222015-06-25 10:32:26 +0800443 /*
444 * Need invalidate the dcache here again to avoid any
445 * cache-fill during the DMA operations such as the
446 * speculative pre-fetching etc.
447 */
Eric Nelson54899fc2013-04-03 12:31:56 +0000448 if (data->flags & MMC_DATA_READ)
449 check_and_invalidate_dcache_range(cmd, data);
Ye.Li71689772014-02-20 18:00:57 +0800450#endif
Andy Fleming50586ef2008-10-30 16:47:16 -0500451 }
452
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500453out:
454 /* Reset CMD and DATA portions on error */
455 if (err) {
456 esdhc_write32(&regs->sysctl, esdhc_read32(&regs->sysctl) |
457 SYSCTL_RSTC);
458 while (esdhc_read32(&regs->sysctl) & SYSCTL_RSTC)
459 ;
460
461 if (data) {
462 esdhc_write32(&regs->sysctl,
463 esdhc_read32(&regs->sysctl) |
464 SYSCTL_RSTD);
465 while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTD))
466 ;
467 }
Otavio Salvadorf022d362015-02-17 10:42:43 -0200468
469 /* If this was CMD11, then notify that power cycle is needed */
470 if (cmd->cmdidx == SD_CMD_SWITCH_UHS18V)
471 printf("CMD11 to switch to 1.8V mode failed, card requires power cycle.\n");
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500472 }
473
Stefano Babicc67bee12010-02-05 15:11:27 +0100474 esdhc_write32(&regs->irqstat, -1);
Andy Fleming50586ef2008-10-30 16:47:16 -0500475
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500476 return err;
Andy Fleming50586ef2008-10-30 16:47:16 -0500477}
478
Kim Phillipseafa90a2012-10-29 13:34:44 +0000479static void set_sysctl(struct mmc *mmc, uint clock)
Andy Fleming50586ef2008-10-30 16:47:16 -0500480{
Andy Fleming50586ef2008-10-30 16:47:16 -0500481 int div, pre_div;
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200482 struct fsl_esdhc_cfg *cfg = mmc->priv;
Stefano Babicc67bee12010-02-05 15:11:27 +0100483 volatile struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
Benoît Thébaudeaua2ac1b32012-10-01 08:36:25 +0000484 int sdhc_clk = cfg->sdhc_clk;
Andy Fleming50586ef2008-10-30 16:47:16 -0500485 uint clk;
486
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200487 if (clock < mmc->cfg->f_min)
488 clock = mmc->cfg->f_min;
Stefano Babicc67bee12010-02-05 15:11:27 +0100489
Andy Fleming50586ef2008-10-30 16:47:16 -0500490 if (sdhc_clk / 16 > clock) {
491 for (pre_div = 2; pre_div < 256; pre_div *= 2)
492 if ((sdhc_clk / pre_div) <= (clock * 16))
493 break;
494 } else
495 pre_div = 2;
496
497 for (div = 1; div <= 16; div++)
498 if ((sdhc_clk / (div * pre_div)) <= clock)
499 break;
500
Volodymyr Riazantsev0e1bf612015-01-20 10:16:44 -0500501 pre_div >>= mmc->ddr_mode ? 2 : 1;
Andy Fleming50586ef2008-10-30 16:47:16 -0500502 div -= 1;
503
504 clk = (pre_div << 8) | (div << 4);
505
Kumar Galacc4d1222010-03-18 15:51:05 -0500506 esdhc_clrbits32(&regs->sysctl, SYSCTL_CKEN);
Stefano Babicc67bee12010-02-05 15:11:27 +0100507
508 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_CLOCK_MASK, clk);
Andy Fleming50586ef2008-10-30 16:47:16 -0500509
510 udelay(10000);
511
Kumar Galacc4d1222010-03-18 15:51:05 -0500512 clk = SYSCTL_PEREN | SYSCTL_CKEN;
Stefano Babicc67bee12010-02-05 15:11:27 +0100513
514 esdhc_setbits32(&regs->sysctl, clk);
Andy Fleming50586ef2008-10-30 16:47:16 -0500515}
516
Yangbo Lu2d9ca2c2015-04-22 13:57:40 +0800517#ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
518static void esdhc_clock_control(struct mmc *mmc, bool enable)
519{
520 struct fsl_esdhc_cfg *cfg = mmc->priv;
521 struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
522 u32 value;
523 u32 time_out;
524
525 value = esdhc_read32(&regs->sysctl);
526
527 if (enable)
528 value |= SYSCTL_CKEN;
529 else
530 value &= ~SYSCTL_CKEN;
531
532 esdhc_write32(&regs->sysctl, value);
533
534 time_out = 20;
535 value = PRSSTAT_SDSTB;
536 while (!(esdhc_read32(&regs->prsstat) & value)) {
537 if (time_out == 0) {
538 printf("fsl_esdhc: Internal clock never stabilised.\n");
539 break;
540 }
541 time_out--;
542 mdelay(1);
543 }
544}
545#endif
546
Andy Fleming50586ef2008-10-30 16:47:16 -0500547static void esdhc_set_ios(struct mmc *mmc)
548{
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200549 struct fsl_esdhc_cfg *cfg = mmc->priv;
Stefano Babicc67bee12010-02-05 15:11:27 +0100550 struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
Andy Fleming50586ef2008-10-30 16:47:16 -0500551
Yangbo Lu2d9ca2c2015-04-22 13:57:40 +0800552#ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
553 /* Select to use peripheral clock */
554 esdhc_clock_control(mmc, false);
555 esdhc_setbits32(&regs->scr, ESDHCCTL_PCS);
556 esdhc_clock_control(mmc, true);
557#endif
Andy Fleming50586ef2008-10-30 16:47:16 -0500558 /* Set the clock speed */
559 set_sysctl(mmc, mmc->clock);
560
561 /* Set the bus width */
Stefano Babicc67bee12010-02-05 15:11:27 +0100562 esdhc_clrbits32(&regs->proctl, PROCTL_DTW_4 | PROCTL_DTW_8);
Andy Fleming50586ef2008-10-30 16:47:16 -0500563
564 if (mmc->bus_width == 4)
Stefano Babicc67bee12010-02-05 15:11:27 +0100565 esdhc_setbits32(&regs->proctl, PROCTL_DTW_4);
Andy Fleming50586ef2008-10-30 16:47:16 -0500566 else if (mmc->bus_width == 8)
Stefano Babicc67bee12010-02-05 15:11:27 +0100567 esdhc_setbits32(&regs->proctl, PROCTL_DTW_8);
568
Andy Fleming50586ef2008-10-30 16:47:16 -0500569}
570
571static int esdhc_init(struct mmc *mmc)
572{
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200573 struct fsl_esdhc_cfg *cfg = mmc->priv;
Stefano Babicc67bee12010-02-05 15:11:27 +0100574 struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
Andy Fleming50586ef2008-10-30 16:47:16 -0500575 int timeout = 1000;
576
Stefano Babicc67bee12010-02-05 15:11:27 +0100577 /* Reset the entire host controller */
Dirk Behmea61da722013-07-15 15:44:29 +0200578 esdhc_setbits32(&regs->sysctl, SYSCTL_RSTA);
Stefano Babicc67bee12010-02-05 15:11:27 +0100579
580 /* Wait until the controller is available */
581 while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA) && --timeout)
582 udelay(1000);
583
Benoît Thébaudeau16e43f32012-08-13 07:28:16 +0000584#ifndef ARCH_MXC
P.V.Suresh2c1764e2010-12-04 10:37:23 +0530585 /* Enable cache snooping */
Benoît Thébaudeau16e43f32012-08-13 07:28:16 +0000586 esdhc_write32(&regs->scr, 0x00000040);
587#endif
P.V.Suresh2c1764e2010-12-04 10:37:23 +0530588
Dirk Behmea61da722013-07-15 15:44:29 +0200589 esdhc_setbits32(&regs->sysctl, SYSCTL_HCKEN | SYSCTL_IPGEN);
Andy Fleming50586ef2008-10-30 16:47:16 -0500590
591 /* Set the initial clock speed */
Jerry Huang4a6ee172010-11-25 17:06:07 +0000592 mmc_set_clock(mmc, 400000);
Andy Fleming50586ef2008-10-30 16:47:16 -0500593
594 /* Disable the BRR and BWR bits in IRQSTAT */
Stefano Babicc67bee12010-02-05 15:11:27 +0100595 esdhc_clrbits32(&regs->irqstaten, IRQSTATEN_BRR | IRQSTATEN_BWR);
Andy Fleming50586ef2008-10-30 16:47:16 -0500596
597 /* Put the PROCTL reg back to the default */
Stefano Babicc67bee12010-02-05 15:11:27 +0100598 esdhc_write32(&regs->proctl, PROCTL_INIT);
Andy Fleming50586ef2008-10-30 16:47:16 -0500599
Stefano Babicc67bee12010-02-05 15:11:27 +0100600 /* Set timout to the maximum value */
601 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
Andy Fleming50586ef2008-10-30 16:47:16 -0500602
Otavio Salvadoree0c5382015-02-17 10:42:44 -0200603#ifdef CONFIG_SYS_FSL_ESDHC_FORCE_VSELECT
604 esdhc_setbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
605#endif
606
Thierry Redingd48d2e22012-01-02 01:15:38 +0000607 return 0;
608}
Andy Fleming50586ef2008-10-30 16:47:16 -0500609
Thierry Redingd48d2e22012-01-02 01:15:38 +0000610static int esdhc_getcd(struct mmc *mmc)
611{
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200612 struct fsl_esdhc_cfg *cfg = mmc->priv;
Thierry Redingd48d2e22012-01-02 01:15:38 +0000613 struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
614 int timeout = 1000;
Stefano Babicc67bee12010-02-05 15:11:27 +0100615
Haijun.Zhangf7e27cc2014-01-10 13:52:17 +0800616#ifdef CONFIG_ESDHC_DETECT_QUIRK
617 if (CONFIG_ESDHC_DETECT_QUIRK)
618 return 1;
619#endif
Thierry Redingd48d2e22012-01-02 01:15:38 +0000620 while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
621 udelay(1000);
622
623 return timeout > 0;
Andy Fleming50586ef2008-10-30 16:47:16 -0500624}
625
Jerry Huang48bb3bb2010-03-18 15:57:06 -0500626static void esdhc_reset(struct fsl_esdhc *regs)
627{
628 unsigned long timeout = 100; /* wait max 100 ms */
629
630 /* reset the controller */
Dirk Behmea61da722013-07-15 15:44:29 +0200631 esdhc_setbits32(&regs->sysctl, SYSCTL_RSTA);
Jerry Huang48bb3bb2010-03-18 15:57:06 -0500632
633 /* hardware clears the bit when it is done */
634 while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA) && --timeout)
635 udelay(1000);
636 if (!timeout)
637 printf("MMC/SD: Reset never completed.\n");
638}
639
Pantelis Antoniouab769f22014-02-26 19:28:45 +0200640static const struct mmc_ops esdhc_ops = {
641 .send_cmd = esdhc_send_cmd,
642 .set_ios = esdhc_set_ios,
643 .init = esdhc_init,
644 .getcd = esdhc_getcd,
645};
646
Stefano Babicc67bee12010-02-05 15:11:27 +0100647int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
Andy Fleming50586ef2008-10-30 16:47:16 -0500648{
Stefano Babicc67bee12010-02-05 15:11:27 +0100649 struct fsl_esdhc *regs;
Andy Fleming50586ef2008-10-30 16:47:16 -0500650 struct mmc *mmc;
Li Yang030955c2010-11-25 17:06:09 +0000651 u32 caps, voltage_caps;
Andy Fleming50586ef2008-10-30 16:47:16 -0500652
Stefano Babicc67bee12010-02-05 15:11:27 +0100653 if (!cfg)
654 return -1;
655
Stefano Babicc67bee12010-02-05 15:11:27 +0100656 regs = (struct fsl_esdhc *)cfg->esdhc_base;
657
Jerry Huang48bb3bb2010-03-18 15:57:06 -0500658 /* First reset the eSDHC controller */
659 esdhc_reset(regs);
660
Jerry Huang975324a2012-05-17 23:57:02 +0000661 esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_HCKEN
662 | SYSCTL_IPGEN | SYSCTL_CKEN);
663
Ye.Lia3d6e382014-11-04 15:35:49 +0800664 writel(SDHCI_IRQ_EN_BITS, &regs->irqstaten);
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200665 memset(&cfg->cfg, 0, sizeof(cfg->cfg));
666
Li Yang030955c2010-11-25 17:06:09 +0000667 voltage_caps = 0;
Wang Huan19060bd2014-09-05 13:52:40 +0800668 caps = esdhc_read32(&regs->hostcapblt);
Roy Zang3b4456e2011-01-07 00:06:47 -0600669
670#ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC135
671 caps = caps & ~(ESDHC_HOSTCAPBLT_SRS |
672 ESDHC_HOSTCAPBLT_VS18 | ESDHC_HOSTCAPBLT_VS30);
673#endif
Haijun.Zhangef38f3f2013-10-31 09:38:19 +0800674
675/* T4240 host controller capabilities register should have VS33 bit */
676#ifdef CONFIG_SYS_FSL_MMC_HAS_CAPBLT_VS33
677 caps = caps | ESDHC_HOSTCAPBLT_VS33;
678#endif
679
Andy Fleming50586ef2008-10-30 16:47:16 -0500680 if (caps & ESDHC_HOSTCAPBLT_VS18)
Li Yang030955c2010-11-25 17:06:09 +0000681 voltage_caps |= MMC_VDD_165_195;
Andy Fleming50586ef2008-10-30 16:47:16 -0500682 if (caps & ESDHC_HOSTCAPBLT_VS30)
Li Yang030955c2010-11-25 17:06:09 +0000683 voltage_caps |= MMC_VDD_29_30 | MMC_VDD_30_31;
Andy Fleming50586ef2008-10-30 16:47:16 -0500684 if (caps & ESDHC_HOSTCAPBLT_VS33)
Li Yang030955c2010-11-25 17:06:09 +0000685 voltage_caps |= MMC_VDD_32_33 | MMC_VDD_33_34;
686
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200687 cfg->cfg.name = "FSL_SDHC";
688 cfg->cfg.ops = &esdhc_ops;
Li Yang030955c2010-11-25 17:06:09 +0000689#ifdef CONFIG_SYS_SD_VOLTAGE
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200690 cfg->cfg.voltages = CONFIG_SYS_SD_VOLTAGE;
Li Yang030955c2010-11-25 17:06:09 +0000691#else
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200692 cfg->cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
Li Yang030955c2010-11-25 17:06:09 +0000693#endif
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200694 if ((cfg->cfg.voltages & voltage_caps) == 0) {
Li Yang030955c2010-11-25 17:06:09 +0000695 printf("voltage not supported by controller\n");
696 return -1;
697 }
Andy Fleming50586ef2008-10-30 16:47:16 -0500698
Rob Herring5a203972015-03-23 17:56:59 -0500699 cfg->cfg.host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT;
Volodymyr Riazantsev0e1bf612015-01-20 10:16:44 -0500700#ifdef CONFIG_SYS_FSL_ESDHC_HAS_DDR_MODE
701 cfg->cfg.host_caps |= MMC_MODE_DDR_52MHz;
702#endif
Andy Fleming50586ef2008-10-30 16:47:16 -0500703
Abbas Razaaad46592013-03-25 09:13:34 +0000704 if (cfg->max_bus_width > 0) {
705 if (cfg->max_bus_width < 8)
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200706 cfg->cfg.host_caps &= ~MMC_MODE_8BIT;
Abbas Razaaad46592013-03-25 09:13:34 +0000707 if (cfg->max_bus_width < 4)
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200708 cfg->cfg.host_caps &= ~MMC_MODE_4BIT;
Abbas Razaaad46592013-03-25 09:13:34 +0000709 }
710
Andy Fleming50586ef2008-10-30 16:47:16 -0500711 if (caps & ESDHC_HOSTCAPBLT_HSS)
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200712 cfg->cfg.host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
Andy Fleming50586ef2008-10-30 16:47:16 -0500713
Haijun.Zhangd47e3d22014-01-10 13:52:18 +0800714#ifdef CONFIG_ESDHC_DETECT_8_BIT_QUIRK
715 if (CONFIG_ESDHC_DETECT_8_BIT_QUIRK)
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200716 cfg->cfg.host_caps &= ~MMC_MODE_8BIT;
Haijun.Zhangd47e3d22014-01-10 13:52:18 +0800717#endif
718
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200719 cfg->cfg.f_min = 400000;
Tom Rini21008ad2014-11-26 11:22:29 -0500720 cfg->cfg.f_max = min(cfg->sdhc_clk, (u32)52000000);
Andy Fleming50586ef2008-10-30 16:47:16 -0500721
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200722 cfg->cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
723
724 mmc = mmc_create(&cfg->cfg, cfg);
725 if (mmc == NULL)
726 return -1;
Andy Fleming50586ef2008-10-30 16:47:16 -0500727
728 return 0;
729}
730
731int fsl_esdhc_mmc_init(bd_t *bis)
732{
Stefano Babicc67bee12010-02-05 15:11:27 +0100733 struct fsl_esdhc_cfg *cfg;
734
Fabio Estevam88227a12012-12-27 08:51:08 +0000735 cfg = calloc(sizeof(struct fsl_esdhc_cfg), 1);
Stefano Babicc67bee12010-02-05 15:11:27 +0100736 cfg->esdhc_base = CONFIG_SYS_FSL_ESDHC_ADDR;
Simon Glasse9adeca2012-12-13 20:49:05 +0000737 cfg->sdhc_clk = gd->arch.sdhc_clk;
Stefano Babicc67bee12010-02-05 15:11:27 +0100738 return fsl_esdhc_initialize(bis, cfg);
Andy Fleming50586ef2008-10-30 16:47:16 -0500739}
Anton Vorontsovb33433a2009-06-10 00:25:29 +0400740
Yangbo Lu5a8dbdc2015-04-22 13:57:00 +0800741#ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
742void mmc_adapter_card_type_ident(void)
743{
744 u8 card_id;
745 u8 value;
746
747 card_id = QIXIS_READ(present) & QIXIS_SDID_MASK;
748 gd->arch.sdhc_adapter = card_id;
749
750 switch (card_id) {
751 case QIXIS_ESDHC_ADAPTER_TYPE_EMMC45:
752 break;
753 case QIXIS_ESDHC_ADAPTER_TYPE_SDMMC_LEGACY:
754 break;
755 case QIXIS_ESDHC_ADAPTER_TYPE_EMMC44:
756 value = QIXIS_READ(brdcfg[5]);
757 value |= (QIXIS_SDCLKIN | QIXIS_SDCLKOUT);
758 QIXIS_WRITE(brdcfg[5], value);
759 break;
760 case QIXIS_ESDHC_ADAPTER_TYPE_RSV:
761 break;
762 case QIXIS_ESDHC_ADAPTER_TYPE_MMC:
763 break;
764 case QIXIS_ESDHC_ADAPTER_TYPE_SD:
765 break;
766 case QIXIS_ESDHC_NO_ADAPTER:
767 break;
768 default:
769 break;
770 }
771}
772#endif
773
Stefano Babicc67bee12010-02-05 15:11:27 +0100774#ifdef CONFIG_OF_LIBFDT
Anton Vorontsovb33433a2009-06-10 00:25:29 +0400775void fdt_fixup_esdhc(void *blob, bd_t *bd)
776{
777 const char *compat = "fsl,esdhc";
Anton Vorontsovb33433a2009-06-10 00:25:29 +0400778
Chenhui Zhaoa6da8b82011-01-04 17:23:05 +0800779#ifdef CONFIG_FSL_ESDHC_PIN_MUX
Anton Vorontsovb33433a2009-06-10 00:25:29 +0400780 if (!hwconfig("esdhc")) {
Chenhui Zhaoa6da8b82011-01-04 17:23:05 +0800781 do_fixup_by_compat(blob, compat, "status", "disabled",
782 8 + 1, 1);
783 return;
Anton Vorontsovb33433a2009-06-10 00:25:29 +0400784 }
Chenhui Zhaoa6da8b82011-01-04 17:23:05 +0800785#endif
Anton Vorontsovb33433a2009-06-10 00:25:29 +0400786
Yangbo Lu2d9ca2c2015-04-22 13:57:40 +0800787#ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
788 do_fixup_by_compat_u32(blob, compat, "peripheral-frequency",
789 gd->arch.sdhc_clk, 1);
790#else
Anton Vorontsovb33433a2009-06-10 00:25:29 +0400791 do_fixup_by_compat_u32(blob, compat, "clock-frequency",
Simon Glasse9adeca2012-12-13 20:49:05 +0000792 gd->arch.sdhc_clk, 1);
Yangbo Lu2d9ca2c2015-04-22 13:57:40 +0800793#endif
Yangbo Lu5a8dbdc2015-04-22 13:57:00 +0800794#ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
795 do_fixup_by_compat_u32(blob, compat, "adapter-type",
796 (u32)(gd->arch.sdhc_adapter), 1);
797#endif
Chenhui Zhaoa6da8b82011-01-04 17:23:05 +0800798 do_fixup_by_compat(blob, compat, "status", "okay",
799 4 + 1, 1);
Anton Vorontsovb33433a2009-06-10 00:25:29 +0400800}
Stefano Babicc67bee12010-02-05 15:11:27 +0100801#endif