]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/mmc/fsl_esdhc.c
TX6 Release 2013-04-22
[karo-tx-uboot.git] / drivers / mmc / fsl_esdhc.c
1 /*
2  * Copyright 2007, 2010-2011 Freescale Semiconductor, Inc
3  * Andy Fleming
4  *
5  * Based vaguely on the pxa mmc code:
6  * (C) Copyright 2003
7  * Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  */
27
28 #include <config.h>
29 #include <common.h>
30 #include <command.h>
31 #include <hwconfig.h>
32 #include <mmc.h>
33 #include <part.h>
34 #include <malloc.h>
35 #include <mmc.h>
36 #include <fsl_esdhc.h>
37 #include <fdt_support.h>
38 #include <asm/io.h>
39
40 DECLARE_GLOBAL_DATA_PTR;
41
42 struct fsl_esdhc {
43         uint    dsaddr;
44         uint    blkattr;
45         uint    cmdarg;
46         uint    xfertyp;
47         uint    cmdrsp0;
48         uint    cmdrsp1;
49         uint    cmdrsp2;
50         uint    cmdrsp3;
51         uint    datport;
52         uint    prsstat;
53         uint    proctl;
54         uint    sysctl;
55         uint    irqstat;
56         uint    irqstaten;
57         uint    irqsigen;
58         uint    autoc12err;
59         uint    hostcapblt;
60         uint    wml;
61         uint    mixctrl;
62         char    reserved1[4];
63         uint    fevt;
64         char    reserved2[168];
65         uint    hostver;
66         char    reserved3[780];
67         uint    scr;
68 };
69
70 /* Return the XFERTYP flags for a given command and data packet */
71 static uint esdhc_xfertyp(struct mmc_cmd *cmd, struct mmc_data *data)
72 {
73         uint xfertyp = 0;
74
75         if (data) {
76                 xfertyp |= XFERTYP_DPSEL;
77 #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
78                 xfertyp |= XFERTYP_DMAEN;
79 #endif
80                 if (data->blocks > 1) {
81                         xfertyp |= XFERTYP_MSBSEL;
82                         xfertyp |= XFERTYP_BCEN;
83 #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
84                         xfertyp |= XFERTYP_AC12EN;
85 #endif
86                 }
87
88                 if (data->flags & MMC_DATA_READ)
89                         xfertyp |= XFERTYP_DTDSEL;
90         }
91
92         if (cmd->resp_type & MMC_RSP_CRC)
93                 xfertyp |= XFERTYP_CCCEN;
94         if (cmd->resp_type & MMC_RSP_OPCODE)
95                 xfertyp |= XFERTYP_CICEN;
96         if (cmd->resp_type & MMC_RSP_136)
97                 xfertyp |= XFERTYP_RSPTYP_136;
98         else if (cmd->resp_type & MMC_RSP_BUSY)
99                 xfertyp |= XFERTYP_RSPTYP_48_BUSY;
100         else if (cmd->resp_type & MMC_RSP_PRESENT)
101                 xfertyp |= XFERTYP_RSPTYP_48;
102
103 #ifdef CONFIG_MX53
104         if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
105                 xfertyp |= XFERTYP_CMDTYP_ABORT;
106 #endif
107         return XFERTYP_CMD(cmd->cmdidx) | xfertyp;
108 }
109
110 #ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO
111 /*
112  * PIO Read/Write Mode reduce the performace as DMA is not used in this mode.
113  */
114 static void
115 esdhc_pio_read_write(struct mmc *mmc, struct mmc_data *data)
116 {
117         struct fsl_esdhc_cfg *cfg = mmc->priv;
118         struct fsl_esdhc *regs = cfg->esdhc_base;
119         uint blocks;
120         char *buffer;
121         uint databuf;
122         uint size;
123         uint timeout;
124         int wml = esdhc_read32(&regs->wml);
125
126         if (data->flags & MMC_DATA_READ) {
127                 wml &= WML_RD_WML_MASK;
128                 blocks = data->blocks;
129                 buffer = data->dest;
130                 while (blocks) {
131                         timeout = PIO_TIMEOUT;
132                         size = data->blocksize;
133                         while (size &&
134                                 !(esdhc_read32(&regs->irqstat) & IRQSTAT_TC)) {
135                                 int i;
136                                 u32 prsstat;
137
138                                 while (!((prsstat = esdhc_read32(&regs->prsstat)) &
139                                                 PRSSTAT_BREN) && --timeout)
140                                         /* NOP */;
141                                 if (!(prsstat & PRSSTAT_BREN)) {
142                                         printf("%s: Data Read Failed in PIO Mode\n",
143                                                 __func__);
144                                         return;
145                                 }
146                                 for (i = 0; i < wml && size; i++) {
147                                         databuf = in_le32(&regs->datport);
148                                         memcpy(buffer, &databuf, sizeof(databuf));
149                                         buffer += 4;
150                                         size -= 4;
151                                 }
152                         }
153                         blocks--;
154                 }
155         } else {
156                 wml = (wml & WML_WR_WML_MASK) >> 16;
157                 blocks = data->blocks;
158                 buffer = (char *)data->src; /* cast away 'const' */
159                 while (blocks) {
160                         timeout = PIO_TIMEOUT;
161                         size = data->blocksize;
162                         while (size &&
163                                 !(esdhc_read32(&regs->irqstat) & IRQSTAT_TC)) {
164                                 int i;
165                                 u32 prsstat;
166
167                                 while (!((prsstat = esdhc_read32(&regs->prsstat)) &
168                                                 PRSSTAT_BWEN) && --timeout)
169                                         /* NOP */;
170                                 if (!(prsstat & PRSSTAT_BWEN)) {
171                                         printf("%s: Data Write Failed in PIO Mode\n",
172                                                 __func__);
173                                         return;
174                                 }
175                                 for (i = 0; i < wml && size; i++) {
176                                         memcpy(&databuf, buffer, sizeof(databuf));
177                                         out_le32(&regs->datport, databuf);
178                                         buffer += 4;
179                                         size -= 4;
180                                 }
181                         }
182                         blocks--;
183                 }
184         }
185 }
186 #endif
187
188 static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
189 {
190         int timeout;
191         struct fsl_esdhc_cfg *cfg = mmc->priv;
192         struct fsl_esdhc *regs = cfg->esdhc_base;
193 #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
194         uint wml_value;
195
196         wml_value = data->blocksize / 4;
197
198         if (data->flags & MMC_DATA_READ) {
199                 if (wml_value > WML_RD_WML_MAX)
200                         wml_value = WML_RD_WML_MAX_VAL;
201
202                 esdhc_clrsetbits32(&regs->wml, WML_RD_WML_MASK, wml_value);
203                 esdhc_write32(&regs->dsaddr, (u32)data->dest);
204         } else {
205                 if (wml_value > WML_WR_WML_MAX)
206                         wml_value = WML_WR_WML_MAX_VAL;
207                 if ((esdhc_read32(&regs->prsstat) & PRSSTAT_WPSPL) == 0) {
208                         printf("The SD card is locked. Can not write to a locked card.\n");
209                         return UNUSABLE_ERR;
210                 }
211
212                 flush_dcache_range((unsigned long)data->src,
213                                 (unsigned long)data->src + data->blocks * data->blocksize);
214                 esdhc_clrsetbits32(&regs->wml, WML_WR_WML_MASK,
215                                         wml_value << 16);
216                 esdhc_write32(&regs->dsaddr, (u32)data->src);
217         }
218 #else   /* CONFIG_SYS_FSL_ESDHC_USE_PIO */
219         if (!(data->flags & MMC_DATA_READ)) {
220                 if ((esdhc_read32(&regs->prsstat) & PRSSTAT_WPSPL) == 0) {
221                         printf("The SD card is locked. Can not write to a locked card.\n");
222                         return UNUSABLE_ERR;
223                 }
224                 esdhc_write32(&regs->dsaddr, (u32)data->src);
225         } else {
226                 esdhc_write32(&regs->dsaddr, (u32)data->dest);
227         }
228 #endif  /* CONFIG_SYS_FSL_ESDHC_USE_PIO */
229
230         esdhc_write32(&regs->blkattr, (data->blocks << 16) | data->blocksize);
231
232         /* Calculate the timeout period for data transactions */
233         /*
234          * 1)Timeout period = (2^(timeout+13)) SD Clock cycles
235          * 2)Timeout period should be minimum 0.250sec as per SD Card spec
236          *  So, Number of SD Clock cycles for 0.25sec should be minimum
237          *              (SD Clock/sec * 0.25 sec) SD Clock cycles
238          *              = (mmc->tran_speed * 1/4) SD Clock cycles
239          * As 1) >=  2)
240          * => (2^(timeout+13)) >= mmc->tran_speed * 1/4
241          * Taking log2 both the sides
242          * => timeout + 13 >= log2(mmc->tran_speed/4)
243          * Rounding up to next power of 2
244          * => timeout + 13 = log2(mmc->tran_speed/4) + 1
245          * => timeout + 13 = fls(mmc->tran_speed/4)
246          */
247         timeout = fls(mmc->tran_speed / 4);
248         timeout -= 13;
249
250         if (timeout > 14)
251                 timeout = 14;
252         else if (timeout < 0)
253                 timeout = 0;
254
255 #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC_A001
256         if ((timeout == 4) || (timeout == 8) || (timeout == 12))
257                 timeout++;
258 #endif
259         esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, timeout << 16);
260
261         return 0;
262 }
263
264 static void check_and_invalidate_dcache_range(struct mmc_cmd *cmd,
265                                         struct mmc_data *data)
266 {
267         unsigned start = (unsigned)data->dest;
268         unsigned size = roundup(ARCH_DMA_MINALIGN,
269                                 data->blocks * data->blocksize);
270         unsigned end = start + size;
271
272         invalidate_dcache_range(start, end);
273 }
274
275 /*
276  * Sends a command out on the bus.  Takes the mmc pointer,
277  * a command pointer, and an optional data pointer.
278  */
279 static int
280 esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
281 {
282         uint    xfertyp;
283         uint    irqstat;
284         struct fsl_esdhc_cfg *cfg = mmc->priv;
285         volatile struct fsl_esdhc *regs = cfg->esdhc_base;
286         unsigned long start;
287
288 #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
289         if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
290                 return 0;
291 #endif
292         esdhc_write32(&regs->irqstat, -1);
293
294         sync();
295
296         start = get_timer_masked();
297         /* Wait for the bus to be idle */
298         while ((esdhc_read32(&regs->prsstat) & PRSSTAT_CICHB) ||
299                 (esdhc_read32(&regs->prsstat) & PRSSTAT_CIDHB)) {
300                 if (get_timer(start) > CONFIG_SYS_HZ) {
301                         printf("%s: Timeout waiting for bus idle\n", __func__);
302                         return TIMEOUT;
303                 }
304         }
305
306         start = get_timer_masked();
307         while (esdhc_read32(&regs->prsstat) & PRSSTAT_DLA) {
308                 if (get_timer(start) > CONFIG_SYS_HZ)
309                         return TIMEOUT;
310         }
311
312         /* Wait at least 8 SD clock cycles before the next command */
313         /*
314          * Note: This is way more than 8 cycles, but 1ms seems to
315          * resolve timing issues with some cards
316          */
317         udelay(1000);
318
319         /* Set up for a data transfer if we have one */
320         if (data) {
321                 int err;
322
323                 err = esdhc_setup_data(mmc, data);
324                 if (err)
325                         return err;
326         }
327
328         /* Figure out the transfer arguments */
329         xfertyp = esdhc_xfertyp(cmd, data);
330
331         /* Send the command */
332         esdhc_write32(&regs->cmdarg, cmd->cmdarg);
333 #if defined(CONFIG_FSL_USDHC)
334         esdhc_write32(&regs->mixctrl,
335         (esdhc_read32(&regs->mixctrl) & ~0x7f) | (xfertyp & 0x7F));
336         esdhc_write32(&regs->xfertyp, xfertyp & 0xFFFF0000);
337 #else
338         esdhc_write32(&regs->xfertyp, xfertyp);
339 #endif
340
341         /* Mask all irqs */
342         esdhc_write32(&regs->irqsigen, 0);
343
344         start = get_timer_masked();
345         /* Wait for the command to complete */
346         while (!(esdhc_read32(&regs->irqstat) & (IRQSTAT_CC | IRQSTAT_CTOE))) {
347                 if (get_timer(start) > CONFIG_SYS_HZ) {
348                         printf("%s: Timeout waiting for cmd completion\n", __func__);
349                         return TIMEOUT;
350                 }
351         }
352
353         if (data && (data->flags & MMC_DATA_READ))
354                 check_and_invalidate_dcache_range(cmd, data);
355
356         irqstat = esdhc_read32(&regs->irqstat);
357         esdhc_write32(&regs->irqstat, irqstat);
358
359         /* Reset CMD and DATA portions on error */
360         if (irqstat & (CMD_ERR | IRQSTAT_CTOE)) {
361                 esdhc_write32(&regs->sysctl, esdhc_read32(&regs->sysctl) |
362                               SYSCTL_RSTC);
363                 start = get_timer_masked();
364                 while (esdhc_read32(&regs->sysctl) & SYSCTL_RSTC) {
365                         if (get_timer(start) > CONFIG_SYS_HZ)
366                                 return TIMEOUT;
367                 }
368
369                 if (data) {
370                         esdhc_write32(&regs->sysctl,
371                                       esdhc_read32(&regs->sysctl) |
372                                       SYSCTL_RSTD);
373                         start = get_timer_masked();
374                         while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTD)) {
375                                 if (get_timer(start) > CONFIG_SYS_HZ)
376                                         return TIMEOUT;
377                         }
378                 }
379         }
380
381         if (irqstat & CMD_ERR)
382                 return COMM_ERR;
383
384         if (irqstat & IRQSTAT_CTOE)
385                 return TIMEOUT;
386
387         /* Workaround for ESDHC errata ENGcm03648 */
388         if (!data && (cmd->resp_type & MMC_RSP_BUSY)) {
389                 int timeout = 2500;
390
391                 /* Poll on DATA0 line for cmd with busy signal for 250 ms */
392                 while (timeout > 0 && !(esdhc_read32(&regs->prsstat) &
393                                         PRSSTAT_DAT0)) {
394                         udelay(100);
395                         timeout--;
396                 }
397
398                 if (timeout <= 0) {
399                         printf("Timeout waiting for DAT0 to go high!\n");
400                         return TIMEOUT;
401                 }
402         }
403
404         /* Copy the response to the response buffer */
405         if (cmd->resp_type & MMC_RSP_136) {
406                 u32 cmdrsp3, cmdrsp2, cmdrsp1, cmdrsp0;
407
408                 cmdrsp3 = esdhc_read32(&regs->cmdrsp3);
409                 cmdrsp2 = esdhc_read32(&regs->cmdrsp2);
410                 cmdrsp1 = esdhc_read32(&regs->cmdrsp1);
411                 cmdrsp0 = esdhc_read32(&regs->cmdrsp0);
412                 cmd->response[0] = (cmdrsp3 << 8) | (cmdrsp2 >> 24);
413                 cmd->response[1] = (cmdrsp2 << 8) | (cmdrsp1 >> 24);
414                 cmd->response[2] = (cmdrsp1 << 8) | (cmdrsp0 >> 24);
415                 cmd->response[3] = (cmdrsp0 << 8);
416         } else
417                 cmd->response[0] = esdhc_read32(&regs->cmdrsp0);
418
419         /* Wait until all of the blocks are transferred */
420         if (data) {
421 #ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO
422                 esdhc_pio_read_write(mmc, data);
423 #else
424                 unsigned long start = get_timer_masked();
425                 unsigned long data_timeout = data->blocks *
426                         data->blocksize * 100 / mmc->bus_width /
427                         (mmc->tran_speed / CONFIG_SYS_HZ) + CONFIG_SYS_HZ;
428
429                 do {
430                         irqstat = esdhc_read32(&regs->irqstat);
431
432                         if (irqstat & IRQSTAT_DTOE) {
433                                 printf("MMC/SD data %s timeout\n",
434                                         data->flags & MMC_DATA_READ ?
435                                         "read" : "write");
436                                 return TIMEOUT;
437                         }
438
439                         if (irqstat & DATA_ERR) {
440                                 printf("MMC/SD data error\n");
441                                 return COMM_ERR;
442                         }
443
444                         if (get_timer(start) > data_timeout) {
445                                 printf("MMC/SD timeout waiting for %s xfer completion\n",
446                                                 data->flags & MMC_DATA_READ ?
447                                                 "read" : "write");
448                                 return TIMEOUT;
449                         }
450                 } while (!(irqstat & IRQSTAT_TC) &&
451                         (esdhc_read32(&regs->prsstat) & PRSSTAT_DLA));
452
453                 check_and_invalidate_dcache_range(cmd, data);
454 #endif
455         }
456
457         esdhc_write32(&regs->irqstat, irqstat);
458
459         return 0;
460 }
461
462 static void set_sysctl(struct mmc *mmc, uint clock)
463 {
464         int div, pre_div;
465         struct fsl_esdhc_cfg *cfg = mmc->priv;
466         volatile struct fsl_esdhc *regs = cfg->esdhc_base;
467         int sdhc_clk = cfg->sdhc_clk;
468         uint clk;
469
470         if (clock < mmc->f_min)
471                 clock = mmc->f_min;
472
473         if (sdhc_clk / 16 > clock) {
474                 for (pre_div = 2; pre_div < 256; pre_div *= 2)
475                         if ((sdhc_clk / pre_div) <= (clock * 16))
476                                 break;
477         } else
478                 pre_div = 2;
479
480         for (div = 1; div <= 16; div++)
481                 if ((sdhc_clk / (div * pre_div)) <= clock)
482                         break;
483
484         pre_div >>= 1;
485         div -= 1;
486
487         clk = (pre_div << 8) | (div << 4);
488
489         esdhc_clrbits32(&regs->sysctl, SYSCTL_CKEN);
490
491         esdhc_clrsetbits32(&regs->sysctl, SYSCTL_CLOCK_MASK, clk);
492
493         udelay(10000);
494
495         clk = SYSCTL_PEREN | SYSCTL_CKEN;
496
497         esdhc_setbits32(&regs->sysctl, clk);
498 }
499
500 static void esdhc_set_ios(struct mmc *mmc)
501 {
502         struct fsl_esdhc_cfg *cfg = mmc->priv;
503         struct fsl_esdhc *regs = cfg->esdhc_base;
504
505         /* Set the clock speed */
506         set_sysctl(mmc, mmc->clock);
507
508         /* Set the bus width */
509         esdhc_clrbits32(&regs->proctl, PROCTL_DTW_4 | PROCTL_DTW_8);
510
511         if (mmc->bus_width == 4)
512                 esdhc_setbits32(&regs->proctl, PROCTL_DTW_4);
513         else if (mmc->bus_width == 8)
514                 esdhc_setbits32(&regs->proctl, PROCTL_DTW_8);
515
516 }
517
518 static int esdhc_init(struct mmc *mmc)
519 {
520         struct fsl_esdhc_cfg *cfg = mmc->priv;
521         struct fsl_esdhc *regs = cfg->esdhc_base;
522         int timeout = 1000;
523
524         /* Reset the entire host controller */
525         esdhc_write32(&regs->sysctl, SYSCTL_RSTA);
526
527         /* Wait until the controller is available */
528         while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA) && --timeout)
529                 udelay(1000);
530
531 #ifndef ARCH_MXC
532         /* Enable cache snooping */
533         esdhc_write32(&regs->scr, 0x00000040);
534 #endif
535
536         esdhc_write32(&regs->sysctl, SYSCTL_HCKEN | SYSCTL_IPGEN);
537
538         /* Set the initial clock speed */
539         mmc_set_clock(mmc, 400000);
540
541         /* Disable the BRR and BWR bits in IRQSTAT */
542         esdhc_clrbits32(&regs->irqstaten, IRQSTATEN_BRR | IRQSTATEN_BWR);
543
544         /* Put the PROCTL reg back to the default */
545         esdhc_write32(&regs->proctl, PROCTL_INIT);
546
547         /* Set timout to the maximum value */
548         esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
549
550         return 0;
551 }
552
553 static int esdhc_getcd(struct mmc *mmc)
554 {
555         struct fsl_esdhc_cfg *cfg = mmc->priv;
556         struct fsl_esdhc *regs = cfg->esdhc_base;
557         int timeout = 1000;
558
559         while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
560                 udelay(1000);
561
562         return timeout > 0;
563 }
564
565 static void esdhc_reset(struct fsl_esdhc *regs)
566 {
567         unsigned long timeout = 100; /* wait max 100 ms */
568
569         /* reset the controller */
570         esdhc_write32(&regs->sysctl, SYSCTL_RSTA);
571
572         /* hardware clears the bit when it is done */
573         while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA) && --timeout)
574                 udelay(1000);
575         if (!timeout)
576                 printf("MMC/SD: Reset never completed.\n");
577 }
578
579 int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
580 {
581         struct fsl_esdhc *regs;
582         struct mmc *mmc;
583         u32 caps, voltage_caps;
584
585         if (!cfg)
586                 return -EINVAL;
587
588         mmc = kzalloc(sizeof(struct mmc), GFP_KERNEL);
589         if (!mmc)
590                 return -ENOMEM;
591
592         sprintf(mmc->name, "FSL_SDHC");
593         regs = cfg->esdhc_base;
594
595         /* First reset the eSDHC controller */
596         esdhc_reset(regs);
597
598         esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_HCKEN
599                                 | SYSCTL_IPGEN | SYSCTL_CKEN);
600
601         mmc->priv = cfg;
602         mmc->send_cmd = esdhc_send_cmd;
603         mmc->set_ios = esdhc_set_ios;
604         mmc->init = esdhc_init;
605         mmc->getcd = esdhc_getcd;
606
607         voltage_caps = 0;
608         caps = regs->hostcapblt;
609
610 #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC135
611         caps = caps & ~(ESDHC_HOSTCAPBLT_SRS |
612                         ESDHC_HOSTCAPBLT_VS18 | ESDHC_HOSTCAPBLT_VS30);
613 #endif
614         if (caps & ESDHC_HOSTCAPBLT_VS18)
615                 voltage_caps |= MMC_VDD_165_195;
616         if (caps & ESDHC_HOSTCAPBLT_VS30)
617                 voltage_caps |= MMC_VDD_29_30 | MMC_VDD_30_31;
618         if (caps & ESDHC_HOSTCAPBLT_VS33)
619                 voltage_caps |= MMC_VDD_32_33 | MMC_VDD_33_34;
620
621 #ifdef CONFIG_SYS_SD_VOLTAGE
622         mmc->voltages = CONFIG_SYS_SD_VOLTAGE;
623 #else
624         mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
625 #endif
626         if ((mmc->voltages & voltage_caps) == 0) {
627                 printf("voltage not supported by controller\n");
628                 return -EINVAL;
629         }
630
631         mmc->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT | MMC_MODE_HC;
632
633         if (caps & ESDHC_HOSTCAPBLT_HSS)
634                 mmc->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
635
636         mmc->f_min = 400000;
637         mmc->f_max = MIN(cfg->sdhc_clk, 52000000);
638
639         mmc->b_max = 0;
640         mmc_register(mmc);
641
642         return 0;
643 }
644
645 int fsl_esdhc_mmc_init(bd_t *bis)
646 {
647         struct fsl_esdhc_cfg *cfg;
648
649         cfg = kzalloc(sizeof(struct fsl_esdhc_cfg), GFP_KERNEL);
650         if (!cfg)
651                 return -ENOMEM;
652         cfg->esdhc_base = (void __iomem *)CONFIG_SYS_FSL_ESDHC_ADDR;
653         cfg->sdhc_clk = gd->arch.sdhc_clk;
654         return fsl_esdhc_initialize(bis, cfg);
655 }
656
657 #ifdef CONFIG_OF_LIBFDT
658 void fdt_fixup_esdhc(void *blob, bd_t *bd)
659 {
660         const char *compat = "fsl,esdhc";
661
662 #ifdef CONFIG_FSL_ESDHC_PIN_MUX
663         if (!hwconfig("esdhc")) {
664                 do_fixup_by_compat(blob, compat, "status", "disabled",
665                                 8 + 1, 1);
666                 return;
667         }
668 #endif
669
670         do_fixup_by_compat_u32(blob, compat, "clock-frequency",
671                                gd->arch.sdhc_clk, 1);
672
673         do_fixup_by_compat(blob, compat, "status", "okay",
674                            4 + 1, 1);
675 }
676 #endif