1de941241SSukumar Ghorai /* 2de941241SSukumar Ghorai * (C) Copyright 2008 3de941241SSukumar Ghorai * Texas Instruments, <www.ti.com> 4de941241SSukumar Ghorai * Sukumar Ghorai <s-ghorai@ti.com> 5de941241SSukumar Ghorai * 6de941241SSukumar Ghorai * See file CREDITS for list of people who contributed to this 7de941241SSukumar Ghorai * project. 8de941241SSukumar Ghorai * 9de941241SSukumar Ghorai * This program is free software; you can redistribute it and/or 10de941241SSukumar Ghorai * modify it under the terms of the GNU General Public License as 11de941241SSukumar Ghorai * published by the Free Software Foundation's version 2 of 12de941241SSukumar Ghorai * the License. 13de941241SSukumar Ghorai * 14de941241SSukumar Ghorai * This program is distributed in the hope that it will be useful, 15de941241SSukumar Ghorai * but WITHOUT ANY WARRANTY; without even the implied warranty of 16de941241SSukumar Ghorai * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17de941241SSukumar Ghorai * GNU General Public License for more details. 18de941241SSukumar Ghorai * 19de941241SSukumar Ghorai * You should have received a copy of the GNU General Public License 20de941241SSukumar Ghorai * along with this program; if not, write to the Free Software 21de941241SSukumar Ghorai * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 22de941241SSukumar Ghorai * MA 02111-1307 USA 23de941241SSukumar Ghorai */ 24de941241SSukumar Ghorai 25de941241SSukumar Ghorai #include <config.h> 26de941241SSukumar Ghorai #include <common.h> 2793bfd616SPantelis Antoniou #include <malloc.h> 28de941241SSukumar Ghorai #include <mmc.h> 29de941241SSukumar Ghorai #include <part.h> 30de941241SSukumar Ghorai #include <i2c.h> 31de941241SSukumar Ghorai #include <twl4030.h> 3214fa2dd0SBalaji T K #include <twl6030.h> 33cb199102SNishanth Menon #include <palmas.h> 34e874d5b0SNikita Kiryanov #include <asm/gpio.h> 35de941241SSukumar Ghorai #include <asm/io.h> 36de941241SSukumar Ghorai #include <asm/arch/mmc_host_def.h> 3796e0e7b3SDirk Behme #include <asm/arch/sys_proto.h> 38de941241SSukumar Ghorai 39ab769f22SPantelis Antoniou /* simplify defines to OMAP_HSMMC_USE_GPIO */ 40ab769f22SPantelis Antoniou #if (defined(CONFIG_OMAP_GPIO) && !defined(CONFIG_SPL_BUILD)) || \ 41ab769f22SPantelis Antoniou (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_GPIO_SUPPORT)) 42ab769f22SPantelis Antoniou #define OMAP_HSMMC_USE_GPIO 43ab769f22SPantelis Antoniou #else 44ab769f22SPantelis Antoniou #undef OMAP_HSMMC_USE_GPIO 45ab769f22SPantelis Antoniou #endif 46ab769f22SPantelis Antoniou 4725c719e2SGrazvydas Ignotas /* common definitions for all OMAPs */ 4825c719e2SGrazvydas Ignotas #define SYSCTL_SRC (1 << 25) 4925c719e2SGrazvydas Ignotas #define SYSCTL_SRD (1 << 26) 5025c719e2SGrazvydas Ignotas 51cc22b0c0SNikita Kiryanov struct omap_hsmmc_data { 52cc22b0c0SNikita Kiryanov struct hsmmc *base_addr; 5393bfd616SPantelis Antoniou struct mmc_config cfg; 54ab769f22SPantelis Antoniou #ifdef OMAP_HSMMC_USE_GPIO 55e874d5b0SNikita Kiryanov int cd_gpio; 56e3913f56SNikita Kiryanov int wp_gpio; 57ab769f22SPantelis Antoniou #endif 58cc22b0c0SNikita Kiryanov }; 59cc22b0c0SNikita Kiryanov 60eb9a28f6SNishanth Menon /* If we fail after 1 second wait, something is really bad */ 61eb9a28f6SNishanth Menon #define MAX_RETRY_MS 1000 62eb9a28f6SNishanth Menon 63933efe64SSricharan static int mmc_read_data(struct hsmmc *mmc_base, char *buf, unsigned int size); 64933efe64SSricharan static int mmc_write_data(struct hsmmc *mmc_base, const char *buf, 65933efe64SSricharan unsigned int siz); 6614fa2dd0SBalaji T K 67ab769f22SPantelis Antoniou #ifdef OMAP_HSMMC_USE_GPIO 68e874d5b0SNikita Kiryanov static int omap_mmc_setup_gpio_in(int gpio, const char *label) 69e874d5b0SNikita Kiryanov { 705915a2adSSimon Glass int ret; 715915a2adSSimon Glass 725915a2adSSimon Glass #ifndef CONFIG_DM_GPIO 73e874d5b0SNikita Kiryanov if (!gpio_is_valid(gpio)) 74e874d5b0SNikita Kiryanov return -1; 755915a2adSSimon Glass #endif 765915a2adSSimon Glass ret = gpio_request(gpio, label); 775915a2adSSimon Glass if (ret) 785915a2adSSimon Glass return ret; 79e874d5b0SNikita Kiryanov 805915a2adSSimon Glass ret = gpio_direction_input(gpio); 815915a2adSSimon Glass if (ret) 825915a2adSSimon Glass return ret; 83e874d5b0SNikita Kiryanov 84e874d5b0SNikita Kiryanov return gpio; 85e874d5b0SNikita Kiryanov } 86e874d5b0SNikita Kiryanov #endif 87e874d5b0SNikita Kiryanov 8814fa2dd0SBalaji T K #if defined(CONFIG_OMAP44XX) && defined(CONFIG_TWL6030_POWER) 8914fa2dd0SBalaji T K static void omap4_vmmc_pbias_config(struct mmc *mmc) 9014fa2dd0SBalaji T K { 9114fa2dd0SBalaji T K u32 value = 0; 9214fa2dd0SBalaji T K 93c43c8339SLokesh Vutla value = readl((*ctrl)->control_pbiaslite); 9414fa2dd0SBalaji T K value &= ~(MMC1_PBIASLITE_PWRDNZ | MMC1_PWRDNZ); 95c43c8339SLokesh Vutla writel(value, (*ctrl)->control_pbiaslite); 9614fa2dd0SBalaji T K /* set VMMC to 3V */ 9714fa2dd0SBalaji T K twl6030_power_mmc_init(); 98c43c8339SLokesh Vutla value = readl((*ctrl)->control_pbiaslite); 9914fa2dd0SBalaji T K value |= MMC1_PBIASLITE_VMODE | MMC1_PBIASLITE_PWRDNZ | MMC1_PWRDNZ; 100c43c8339SLokesh Vutla writel(value, (*ctrl)->control_pbiaslite); 10114fa2dd0SBalaji T K } 10214fa2dd0SBalaji T K #endif 10314fa2dd0SBalaji T K 104cb199102SNishanth Menon #if defined(CONFIG_OMAP54XX) && defined(CONFIG_PALMAS_POWER) 105dd23e59dSBalaji T K static void omap5_pbias_config(struct mmc *mmc) 106dd23e59dSBalaji T K { 107dd23e59dSBalaji T K u32 value = 0; 108dd23e59dSBalaji T K 109c43c8339SLokesh Vutla value = readl((*ctrl)->control_pbias); 110a5d439c2SBalaji T K value &= ~SDCARD_PWRDNZ; 111a5d439c2SBalaji T K writel(value, (*ctrl)->control_pbias); 112a5d439c2SBalaji T K udelay(10); /* wait 10 us */ 113a5d439c2SBalaji T K value &= ~SDCARD_BIAS_PWRDNZ; 114c43c8339SLokesh Vutla writel(value, (*ctrl)->control_pbias); 115dd23e59dSBalaji T K 116384bcae0SNishanth Menon palmas_mmc1_poweron_ldo(); 117dd23e59dSBalaji T K 118c43c8339SLokesh Vutla value = readl((*ctrl)->control_pbias); 119a5d439c2SBalaji T K value |= SDCARD_BIAS_PWRDNZ; 120c43c8339SLokesh Vutla writel(value, (*ctrl)->control_pbias); 121a5d439c2SBalaji T K udelay(150); /* wait 150 us */ 122a5d439c2SBalaji T K value |= SDCARD_PWRDNZ; 123c43c8339SLokesh Vutla writel(value, (*ctrl)->control_pbias); 124a5d439c2SBalaji T K udelay(150); /* wait 150 us */ 125dd23e59dSBalaji T K } 126dd23e59dSBalaji T K #endif 127dd23e59dSBalaji T K 128750121c3SJeroen Hofstee static unsigned char mmc_board_init(struct mmc *mmc) 129de941241SSukumar Ghorai { 130de941241SSukumar Ghorai #if defined(CONFIG_OMAP34XX) 131de941241SSukumar Ghorai t2_t *t2_base = (t2_t *)T2_BASE; 132de941241SSukumar Ghorai struct prcm *prcm_base = (struct prcm *)PRCM_BASE; 133b1e725f2SGrazvydas Ignotas u32 pbias_lite; 134de941241SSukumar Ghorai 135b1e725f2SGrazvydas Ignotas pbias_lite = readl(&t2_base->pbias_lite); 136b1e725f2SGrazvydas Ignotas pbias_lite &= ~(PBIASLITEPWRDNZ1 | PBIASLITEPWRDNZ0); 1375bfdd1fcSAlbert ARIBAUD \(3ADEV\) #ifdef CONFIG_TARGET_OMAP3_CAIRO 1385bfdd1fcSAlbert ARIBAUD \(3ADEV\) /* for cairo board, we need to set up 1.8 Volt bias level on MMC1 */ 1395bfdd1fcSAlbert ARIBAUD \(3ADEV\) pbias_lite &= ~PBIASLITEVMODE0; 1405bfdd1fcSAlbert ARIBAUD \(3ADEV\) #endif 141b1e725f2SGrazvydas Ignotas writel(pbias_lite, &t2_base->pbias_lite); 142aac5450eSPaul Kocialkowski 143b1e725f2SGrazvydas Ignotas writel(pbias_lite | PBIASLITEPWRDNZ1 | 144de941241SSukumar Ghorai PBIASSPEEDCTRL0 | PBIASLITEPWRDNZ0, 145de941241SSukumar Ghorai &t2_base->pbias_lite); 146de941241SSukumar Ghorai 147de941241SSukumar Ghorai writel(readl(&t2_base->devconf0) | MMCSDIO1ADPCLKISEL, 148de941241SSukumar Ghorai &t2_base->devconf0); 149de941241SSukumar Ghorai 150de941241SSukumar Ghorai writel(readl(&t2_base->devconf1) | MMCSDIO2ADPCLKISEL, 151de941241SSukumar Ghorai &t2_base->devconf1); 152de941241SSukumar Ghorai 153bbbc1ae9SJonathan Solnit /* Change from default of 52MHz to 26MHz if necessary */ 15493bfd616SPantelis Antoniou if (!(mmc->cfg->host_caps & MMC_MODE_HS_52MHz)) 155bbbc1ae9SJonathan Solnit writel(readl(&t2_base->ctl_prog_io1) & ~CTLPROGIO1SPEEDCTRL, 156bbbc1ae9SJonathan Solnit &t2_base->ctl_prog_io1); 157bbbc1ae9SJonathan Solnit 158de941241SSukumar Ghorai writel(readl(&prcm_base->fclken1_core) | 159de941241SSukumar Ghorai EN_MMC1 | EN_MMC2 | EN_MMC3, 160de941241SSukumar Ghorai &prcm_base->fclken1_core); 161de941241SSukumar Ghorai 162de941241SSukumar Ghorai writel(readl(&prcm_base->iclken1_core) | 163de941241SSukumar Ghorai EN_MMC1 | EN_MMC2 | EN_MMC3, 164de941241SSukumar Ghorai &prcm_base->iclken1_core); 165de941241SSukumar Ghorai #endif 166de941241SSukumar Ghorai 16714fa2dd0SBalaji T K #if defined(CONFIG_OMAP44XX) && defined(CONFIG_TWL6030_POWER) 16814fa2dd0SBalaji T K /* PBIAS config needed for MMC1 only */ 16914fa2dd0SBalaji T K if (mmc->block_dev.dev == 0) 17014fa2dd0SBalaji T K omap4_vmmc_pbias_config(mmc); 17114fa2dd0SBalaji T K #endif 172cb199102SNishanth Menon #if defined(CONFIG_OMAP54XX) && defined(CONFIG_PALMAS_POWER) 173dd23e59dSBalaji T K if (mmc->block_dev.dev == 0) 174dd23e59dSBalaji T K omap5_pbias_config(mmc); 175dd23e59dSBalaji T K #endif 176de941241SSukumar Ghorai 177de941241SSukumar Ghorai return 0; 178de941241SSukumar Ghorai } 179de941241SSukumar Ghorai 180933efe64SSricharan void mmc_init_stream(struct hsmmc *mmc_base) 181de941241SSukumar Ghorai { 182eb9a28f6SNishanth Menon ulong start; 183de941241SSukumar Ghorai 184de941241SSukumar Ghorai writel(readl(&mmc_base->con) | INIT_INITSTREAM, &mmc_base->con); 185de941241SSukumar Ghorai 186de941241SSukumar Ghorai writel(MMC_CMD0, &mmc_base->cmd); 187eb9a28f6SNishanth Menon start = get_timer(0); 188eb9a28f6SNishanth Menon while (!(readl(&mmc_base->stat) & CC_MASK)) { 189eb9a28f6SNishanth Menon if (get_timer(0) - start > MAX_RETRY_MS) { 190eb9a28f6SNishanth Menon printf("%s: timedout waiting for cc!\n", __func__); 191eb9a28f6SNishanth Menon return; 192eb9a28f6SNishanth Menon } 193eb9a28f6SNishanth Menon } 194de941241SSukumar Ghorai writel(CC_MASK, &mmc_base->stat) 195de941241SSukumar Ghorai ; 196de941241SSukumar Ghorai writel(MMC_CMD0, &mmc_base->cmd) 197de941241SSukumar Ghorai ; 198eb9a28f6SNishanth Menon start = get_timer(0); 199eb9a28f6SNishanth Menon while (!(readl(&mmc_base->stat) & CC_MASK)) { 200eb9a28f6SNishanth Menon if (get_timer(0) - start > MAX_RETRY_MS) { 201eb9a28f6SNishanth Menon printf("%s: timedout waiting for cc2!\n", __func__); 202eb9a28f6SNishanth Menon return; 203eb9a28f6SNishanth Menon } 204eb9a28f6SNishanth Menon } 205de941241SSukumar Ghorai writel(readl(&mmc_base->con) & ~INIT_INITSTREAM, &mmc_base->con); 206de941241SSukumar Ghorai } 207de941241SSukumar Ghorai 208de941241SSukumar Ghorai 209ab769f22SPantelis Antoniou static int omap_hsmmc_init_setup(struct mmc *mmc) 210de941241SSukumar Ghorai { 211cc22b0c0SNikita Kiryanov struct hsmmc *mmc_base; 212de941241SSukumar Ghorai unsigned int reg_val; 213de941241SSukumar Ghorai unsigned int dsor; 214eb9a28f6SNishanth Menon ulong start; 215de941241SSukumar Ghorai 216cc22b0c0SNikita Kiryanov mmc_base = ((struct omap_hsmmc_data *)mmc->priv)->base_addr; 21714fa2dd0SBalaji T K mmc_board_init(mmc); 218de941241SSukumar Ghorai 219de941241SSukumar Ghorai writel(readl(&mmc_base->sysconfig) | MMC_SOFTRESET, 220de941241SSukumar Ghorai &mmc_base->sysconfig); 221eb9a28f6SNishanth Menon start = get_timer(0); 222eb9a28f6SNishanth Menon while ((readl(&mmc_base->sysstatus) & RESETDONE) == 0) { 223eb9a28f6SNishanth Menon if (get_timer(0) - start > MAX_RETRY_MS) { 224eb9a28f6SNishanth Menon printf("%s: timedout waiting for cc2!\n", __func__); 225eb9a28f6SNishanth Menon return TIMEOUT; 226eb9a28f6SNishanth Menon } 227eb9a28f6SNishanth Menon } 228de941241SSukumar Ghorai writel(readl(&mmc_base->sysctl) | SOFTRESETALL, &mmc_base->sysctl); 229eb9a28f6SNishanth Menon start = get_timer(0); 230eb9a28f6SNishanth Menon while ((readl(&mmc_base->sysctl) & SOFTRESETALL) != 0x0) { 231eb9a28f6SNishanth Menon if (get_timer(0) - start > MAX_RETRY_MS) { 232eb9a28f6SNishanth Menon printf("%s: timedout waiting for softresetall!\n", 233eb9a28f6SNishanth Menon __func__); 234eb9a28f6SNishanth Menon return TIMEOUT; 235eb9a28f6SNishanth Menon } 236eb9a28f6SNishanth Menon } 237de941241SSukumar Ghorai writel(DTW_1_BITMODE | SDBP_PWROFF | SDVS_3V0, &mmc_base->hctl); 238de941241SSukumar Ghorai writel(readl(&mmc_base->capa) | VS30_3V0SUP | VS18_1V8SUP, 239de941241SSukumar Ghorai &mmc_base->capa); 240de941241SSukumar Ghorai 241de941241SSukumar Ghorai reg_val = readl(&mmc_base->con) & RESERVED_MASK; 242de941241SSukumar Ghorai 243de941241SSukumar Ghorai writel(CTPL_MMC_SD | reg_val | WPP_ACTIVEHIGH | CDP_ACTIVEHIGH | 244de941241SSukumar Ghorai MIT_CTO | DW8_1_4BITMODE | MODE_FUNC | STR_BLOCK | 245de941241SSukumar Ghorai HR_NOHOSTRESP | INIT_NOINIT | NOOPENDRAIN, &mmc_base->con); 246de941241SSukumar Ghorai 247de941241SSukumar Ghorai dsor = 240; 248de941241SSukumar Ghorai mmc_reg_out(&mmc_base->sysctl, (ICE_MASK | DTO_MASK | CEN_MASK), 249de941241SSukumar Ghorai (ICE_STOP | DTO_15THDTO | CEN_DISABLE)); 250de941241SSukumar Ghorai mmc_reg_out(&mmc_base->sysctl, ICE_MASK | CLKD_MASK, 251de941241SSukumar Ghorai (dsor << CLKD_OFFSET) | ICE_OSCILLATE); 252eb9a28f6SNishanth Menon start = get_timer(0); 253eb9a28f6SNishanth Menon while ((readl(&mmc_base->sysctl) & ICS_MASK) == ICS_NOTREADY) { 254eb9a28f6SNishanth Menon if (get_timer(0) - start > MAX_RETRY_MS) { 255eb9a28f6SNishanth Menon printf("%s: timedout waiting for ics!\n", __func__); 256eb9a28f6SNishanth Menon return TIMEOUT; 257eb9a28f6SNishanth Menon } 258eb9a28f6SNishanth Menon } 259de941241SSukumar Ghorai writel(readl(&mmc_base->sysctl) | CEN_ENABLE, &mmc_base->sysctl); 260de941241SSukumar Ghorai 261de941241SSukumar Ghorai writel(readl(&mmc_base->hctl) | SDBP_PWRON, &mmc_base->hctl); 262de941241SSukumar Ghorai 263de941241SSukumar Ghorai writel(IE_BADA | IE_CERR | IE_DEB | IE_DCRC | IE_DTO | IE_CIE | 264de941241SSukumar Ghorai IE_CEB | IE_CCRC | IE_CTO | IE_BRR | IE_BWR | IE_TC | IE_CC, 265de941241SSukumar Ghorai &mmc_base->ie); 266de941241SSukumar Ghorai 267de941241SSukumar Ghorai mmc_init_stream(mmc_base); 268de941241SSukumar Ghorai 269de941241SSukumar Ghorai return 0; 270de941241SSukumar Ghorai } 271de941241SSukumar Ghorai 27225c719e2SGrazvydas Ignotas /* 27325c719e2SGrazvydas Ignotas * MMC controller internal finite state machine reset 27425c719e2SGrazvydas Ignotas * 27525c719e2SGrazvydas Ignotas * Used to reset command or data internal state machines, using respectively 27625c719e2SGrazvydas Ignotas * SRC or SRD bit of SYSCTL register 27725c719e2SGrazvydas Ignotas */ 27825c719e2SGrazvydas Ignotas static void mmc_reset_controller_fsm(struct hsmmc *mmc_base, u32 bit) 27925c719e2SGrazvydas Ignotas { 28025c719e2SGrazvydas Ignotas ulong start; 28125c719e2SGrazvydas Ignotas 28225c719e2SGrazvydas Ignotas mmc_reg_out(&mmc_base->sysctl, bit, bit); 28325c719e2SGrazvydas Ignotas 28461a6cc27SOleksandr Tyshchenko /* 28561a6cc27SOleksandr Tyshchenko * CMD(DAT) lines reset procedures are slightly different 28661a6cc27SOleksandr Tyshchenko * for OMAP3 and OMAP4(AM335x,OMAP5,DRA7xx). 28761a6cc27SOleksandr Tyshchenko * According to OMAP3 TRM: 28861a6cc27SOleksandr Tyshchenko * Set SRC(SRD) bit in MMCHS_SYSCTL register to 0x1 and wait until it 28961a6cc27SOleksandr Tyshchenko * returns to 0x0. 29061a6cc27SOleksandr Tyshchenko * According to OMAP4(AM335x,OMAP5,DRA7xx) TRMs, CMD(DATA) lines reset 29161a6cc27SOleksandr Tyshchenko * procedure steps must be as follows: 29261a6cc27SOleksandr Tyshchenko * 1. Initiate CMD(DAT) line reset by writing 0x1 to SRC(SRD) bit in 29361a6cc27SOleksandr Tyshchenko * MMCHS_SYSCTL register (SD_SYSCTL for AM335x). 29461a6cc27SOleksandr Tyshchenko * 2. Poll the SRC(SRD) bit until it is set to 0x1. 29561a6cc27SOleksandr Tyshchenko * 3. Wait until the SRC (SRD) bit returns to 0x0 29661a6cc27SOleksandr Tyshchenko * (reset procedure is completed). 29761a6cc27SOleksandr Tyshchenko */ 29861a6cc27SOleksandr Tyshchenko #if defined(CONFIG_OMAP44XX) || defined(CONFIG_OMAP54XX) || \ 299*dce55b93SNikita Kiryanov defined(CONFIG_AM33XX) || defined(CONFIG_AM43XX) 30061a6cc27SOleksandr Tyshchenko if (!(readl(&mmc_base->sysctl) & bit)) { 30161a6cc27SOleksandr Tyshchenko start = get_timer(0); 30261a6cc27SOleksandr Tyshchenko while (!(readl(&mmc_base->sysctl) & bit)) { 30361a6cc27SOleksandr Tyshchenko if (get_timer(0) - start > MAX_RETRY_MS) 30461a6cc27SOleksandr Tyshchenko return; 30561a6cc27SOleksandr Tyshchenko } 30661a6cc27SOleksandr Tyshchenko } 30761a6cc27SOleksandr Tyshchenko #endif 30825c719e2SGrazvydas Ignotas start = get_timer(0); 30925c719e2SGrazvydas Ignotas while ((readl(&mmc_base->sysctl) & bit) != 0) { 31025c719e2SGrazvydas Ignotas if (get_timer(0) - start > MAX_RETRY_MS) { 31125c719e2SGrazvydas Ignotas printf("%s: timedout waiting for sysctl %x to clear\n", 31225c719e2SGrazvydas Ignotas __func__, bit); 31325c719e2SGrazvydas Ignotas return; 31425c719e2SGrazvydas Ignotas } 31525c719e2SGrazvydas Ignotas } 31625c719e2SGrazvydas Ignotas } 317de941241SSukumar Ghorai 318ab769f22SPantelis Antoniou static int omap_hsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, 319de941241SSukumar Ghorai struct mmc_data *data) 320de941241SSukumar Ghorai { 321cc22b0c0SNikita Kiryanov struct hsmmc *mmc_base; 322de941241SSukumar Ghorai unsigned int flags, mmc_stat; 323eb9a28f6SNishanth Menon ulong start; 324de941241SSukumar Ghorai 325cc22b0c0SNikita Kiryanov mmc_base = ((struct omap_hsmmc_data *)mmc->priv)->base_addr; 326eb9a28f6SNishanth Menon start = get_timer(0); 327a7778f8fSTom Rini while ((readl(&mmc_base->pstate) & (DATI_MASK | CMDI_MASK)) != 0) { 328eb9a28f6SNishanth Menon if (get_timer(0) - start > MAX_RETRY_MS) { 329a7778f8fSTom Rini printf("%s: timedout waiting on cmd inhibit to clear\n", 330a7778f8fSTom Rini __func__); 331eb9a28f6SNishanth Menon return TIMEOUT; 332eb9a28f6SNishanth Menon } 333eb9a28f6SNishanth Menon } 334de941241SSukumar Ghorai writel(0xFFFFFFFF, &mmc_base->stat); 335eb9a28f6SNishanth Menon start = get_timer(0); 336eb9a28f6SNishanth Menon while (readl(&mmc_base->stat)) { 337eb9a28f6SNishanth Menon if (get_timer(0) - start > MAX_RETRY_MS) { 33815ceb1deSGrazvydas Ignotas printf("%s: timedout waiting for STAT (%x) to clear\n", 33915ceb1deSGrazvydas Ignotas __func__, readl(&mmc_base->stat)); 340eb9a28f6SNishanth Menon return TIMEOUT; 341eb9a28f6SNishanth Menon } 342eb9a28f6SNishanth Menon } 343de941241SSukumar Ghorai /* 344de941241SSukumar Ghorai * CMDREG 345de941241SSukumar Ghorai * CMDIDX[13:8] : Command index 346de941241SSukumar Ghorai * DATAPRNT[5] : Data Present Select 347de941241SSukumar Ghorai * ENCMDIDX[4] : Command Index Check Enable 348de941241SSukumar Ghorai * ENCMDCRC[3] : Command CRC Check Enable 349de941241SSukumar Ghorai * RSPTYP[1:0] 350de941241SSukumar Ghorai * 00 = No Response 351de941241SSukumar Ghorai * 01 = Length 136 352de941241SSukumar Ghorai * 10 = Length 48 353de941241SSukumar Ghorai * 11 = Length 48 Check busy after response 354de941241SSukumar Ghorai */ 355de941241SSukumar Ghorai /* Delay added before checking the status of frq change 356de941241SSukumar Ghorai * retry not supported by mmc.c(core file) 357de941241SSukumar Ghorai */ 358de941241SSukumar Ghorai if (cmd->cmdidx == SD_CMD_APP_SEND_SCR) 359de941241SSukumar Ghorai udelay(50000); /* wait 50 ms */ 360de941241SSukumar Ghorai 361de941241SSukumar Ghorai if (!(cmd->resp_type & MMC_RSP_PRESENT)) 362de941241SSukumar Ghorai flags = 0; 363de941241SSukumar Ghorai else if (cmd->resp_type & MMC_RSP_136) 364de941241SSukumar Ghorai flags = RSP_TYPE_LGHT136 | CICE_NOCHECK; 365de941241SSukumar Ghorai else if (cmd->resp_type & MMC_RSP_BUSY) 366de941241SSukumar Ghorai flags = RSP_TYPE_LGHT48B; 367de941241SSukumar Ghorai else 368de941241SSukumar Ghorai flags = RSP_TYPE_LGHT48; 369de941241SSukumar Ghorai 370de941241SSukumar Ghorai /* enable default flags */ 371de941241SSukumar Ghorai flags = flags | (CMD_TYPE_NORMAL | CICE_NOCHECK | CCCE_NOCHECK | 372de941241SSukumar Ghorai MSBS_SGLEBLK | ACEN_DISABLE | BCE_DISABLE | DE_DISABLE); 373de941241SSukumar Ghorai 374de941241SSukumar Ghorai if (cmd->resp_type & MMC_RSP_CRC) 375de941241SSukumar Ghorai flags |= CCCE_CHECK; 376de941241SSukumar Ghorai if (cmd->resp_type & MMC_RSP_OPCODE) 377de941241SSukumar Ghorai flags |= CICE_CHECK; 378de941241SSukumar Ghorai 379de941241SSukumar Ghorai if (data) { 380de941241SSukumar Ghorai if ((cmd->cmdidx == MMC_CMD_READ_MULTIPLE_BLOCK) || 381de941241SSukumar Ghorai (cmd->cmdidx == MMC_CMD_WRITE_MULTIPLE_BLOCK)) { 382de941241SSukumar Ghorai flags |= (MSBS_MULTIBLK | BCE_ENABLE); 383de941241SSukumar Ghorai data->blocksize = 512; 384de941241SSukumar Ghorai writel(data->blocksize | (data->blocks << 16), 385de941241SSukumar Ghorai &mmc_base->blk); 386de941241SSukumar Ghorai } else 387de941241SSukumar Ghorai writel(data->blocksize | NBLK_STPCNT, &mmc_base->blk); 388de941241SSukumar Ghorai 389de941241SSukumar Ghorai if (data->flags & MMC_DATA_READ) 390de941241SSukumar Ghorai flags |= (DP_DATA | DDIR_READ); 391de941241SSukumar Ghorai else 392de941241SSukumar Ghorai flags |= (DP_DATA | DDIR_WRITE); 393de941241SSukumar Ghorai } 394de941241SSukumar Ghorai 395de941241SSukumar Ghorai writel(cmd->cmdarg, &mmc_base->arg); 396152ba363SLubomir Popov udelay(20); /* To fix "No status update" error on eMMC */ 397de941241SSukumar Ghorai writel((cmd->cmdidx << 24) | flags, &mmc_base->cmd); 398de941241SSukumar Ghorai 399eb9a28f6SNishanth Menon start = get_timer(0); 400de941241SSukumar Ghorai do { 401de941241SSukumar Ghorai mmc_stat = readl(&mmc_base->stat); 402eb9a28f6SNishanth Menon if (get_timer(0) - start > MAX_RETRY_MS) { 403de941241SSukumar Ghorai printf("%s : timeout: No status update\n", __func__); 404de941241SSukumar Ghorai return TIMEOUT; 405de941241SSukumar Ghorai } 406eb9a28f6SNishanth Menon } while (!mmc_stat); 407de941241SSukumar Ghorai 40825c719e2SGrazvydas Ignotas if ((mmc_stat & IE_CTO) != 0) { 40925c719e2SGrazvydas Ignotas mmc_reset_controller_fsm(mmc_base, SYSCTL_SRC); 410de941241SSukumar Ghorai return TIMEOUT; 41125c719e2SGrazvydas Ignotas } else if ((mmc_stat & ERRI_MASK) != 0) 412de941241SSukumar Ghorai return -1; 413de941241SSukumar Ghorai 414de941241SSukumar Ghorai if (mmc_stat & CC_MASK) { 415de941241SSukumar Ghorai writel(CC_MASK, &mmc_base->stat); 416de941241SSukumar Ghorai if (cmd->resp_type & MMC_RSP_PRESENT) { 417de941241SSukumar Ghorai if (cmd->resp_type & MMC_RSP_136) { 418de941241SSukumar Ghorai /* response type 2 */ 419de941241SSukumar Ghorai cmd->response[3] = readl(&mmc_base->rsp10); 420de941241SSukumar Ghorai cmd->response[2] = readl(&mmc_base->rsp32); 421de941241SSukumar Ghorai cmd->response[1] = readl(&mmc_base->rsp54); 422de941241SSukumar Ghorai cmd->response[0] = readl(&mmc_base->rsp76); 423de941241SSukumar Ghorai } else 424de941241SSukumar Ghorai /* response types 1, 1b, 3, 4, 5, 6 */ 425de941241SSukumar Ghorai cmd->response[0] = readl(&mmc_base->rsp10); 426de941241SSukumar Ghorai } 427de941241SSukumar Ghorai } 428de941241SSukumar Ghorai 429de941241SSukumar Ghorai if (data && (data->flags & MMC_DATA_READ)) { 430de941241SSukumar Ghorai mmc_read_data(mmc_base, data->dest, 431de941241SSukumar Ghorai data->blocksize * data->blocks); 432de941241SSukumar Ghorai } else if (data && (data->flags & MMC_DATA_WRITE)) { 433de941241SSukumar Ghorai mmc_write_data(mmc_base, data->src, 434de941241SSukumar Ghorai data->blocksize * data->blocks); 435de941241SSukumar Ghorai } 436de941241SSukumar Ghorai return 0; 437de941241SSukumar Ghorai } 438de941241SSukumar Ghorai 439933efe64SSricharan static int mmc_read_data(struct hsmmc *mmc_base, char *buf, unsigned int size) 440de941241SSukumar Ghorai { 441de941241SSukumar Ghorai unsigned int *output_buf = (unsigned int *)buf; 442de941241SSukumar Ghorai unsigned int mmc_stat; 443de941241SSukumar Ghorai unsigned int count; 444de941241SSukumar Ghorai 445de941241SSukumar Ghorai /* 446de941241SSukumar Ghorai * Start Polled Read 447de941241SSukumar Ghorai */ 448de941241SSukumar Ghorai count = (size > MMCSD_SECTOR_SIZE) ? MMCSD_SECTOR_SIZE : size; 449de941241SSukumar Ghorai count /= 4; 450de941241SSukumar Ghorai 451de941241SSukumar Ghorai while (size) { 452eb9a28f6SNishanth Menon ulong start = get_timer(0); 453de941241SSukumar Ghorai do { 454de941241SSukumar Ghorai mmc_stat = readl(&mmc_base->stat); 455eb9a28f6SNishanth Menon if (get_timer(0) - start > MAX_RETRY_MS) { 456eb9a28f6SNishanth Menon printf("%s: timedout waiting for status!\n", 457eb9a28f6SNishanth Menon __func__); 458eb9a28f6SNishanth Menon return TIMEOUT; 459eb9a28f6SNishanth Menon } 460de941241SSukumar Ghorai } while (mmc_stat == 0); 461de941241SSukumar Ghorai 46225c719e2SGrazvydas Ignotas if ((mmc_stat & (IE_DTO | IE_DCRC | IE_DEB)) != 0) 46325c719e2SGrazvydas Ignotas mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD); 46425c719e2SGrazvydas Ignotas 465de941241SSukumar Ghorai if ((mmc_stat & ERRI_MASK) != 0) 466de941241SSukumar Ghorai return 1; 467de941241SSukumar Ghorai 468de941241SSukumar Ghorai if (mmc_stat & BRR_MASK) { 469de941241SSukumar Ghorai unsigned int k; 470de941241SSukumar Ghorai 471de941241SSukumar Ghorai writel(readl(&mmc_base->stat) | BRR_MASK, 472de941241SSukumar Ghorai &mmc_base->stat); 473de941241SSukumar Ghorai for (k = 0; k < count; k++) { 474de941241SSukumar Ghorai *output_buf = readl(&mmc_base->data); 475de941241SSukumar Ghorai output_buf++; 476de941241SSukumar Ghorai } 477de941241SSukumar Ghorai size -= (count*4); 478de941241SSukumar Ghorai } 479de941241SSukumar Ghorai 480de941241SSukumar Ghorai if (mmc_stat & BWR_MASK) 481de941241SSukumar Ghorai writel(readl(&mmc_base->stat) | BWR_MASK, 482de941241SSukumar Ghorai &mmc_base->stat); 483de941241SSukumar Ghorai 484de941241SSukumar Ghorai if (mmc_stat & TC_MASK) { 485de941241SSukumar Ghorai writel(readl(&mmc_base->stat) | TC_MASK, 486de941241SSukumar Ghorai &mmc_base->stat); 487de941241SSukumar Ghorai break; 488de941241SSukumar Ghorai } 489de941241SSukumar Ghorai } 490de941241SSukumar Ghorai return 0; 491de941241SSukumar Ghorai } 492de941241SSukumar Ghorai 493933efe64SSricharan static int mmc_write_data(struct hsmmc *mmc_base, const char *buf, 494933efe64SSricharan unsigned int size) 495de941241SSukumar Ghorai { 496de941241SSukumar Ghorai unsigned int *input_buf = (unsigned int *)buf; 497de941241SSukumar Ghorai unsigned int mmc_stat; 498de941241SSukumar Ghorai unsigned int count; 499de941241SSukumar Ghorai 500de941241SSukumar Ghorai /* 501152ba363SLubomir Popov * Start Polled Write 502de941241SSukumar Ghorai */ 503de941241SSukumar Ghorai count = (size > MMCSD_SECTOR_SIZE) ? MMCSD_SECTOR_SIZE : size; 504de941241SSukumar Ghorai count /= 4; 505de941241SSukumar Ghorai 506de941241SSukumar Ghorai while (size) { 507eb9a28f6SNishanth Menon ulong start = get_timer(0); 508de941241SSukumar Ghorai do { 509de941241SSukumar Ghorai mmc_stat = readl(&mmc_base->stat); 510eb9a28f6SNishanth Menon if (get_timer(0) - start > MAX_RETRY_MS) { 511eb9a28f6SNishanth Menon printf("%s: timedout waiting for status!\n", 512eb9a28f6SNishanth Menon __func__); 513eb9a28f6SNishanth Menon return TIMEOUT; 514eb9a28f6SNishanth Menon } 515de941241SSukumar Ghorai } while (mmc_stat == 0); 516de941241SSukumar Ghorai 51725c719e2SGrazvydas Ignotas if ((mmc_stat & (IE_DTO | IE_DCRC | IE_DEB)) != 0) 51825c719e2SGrazvydas Ignotas mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD); 51925c719e2SGrazvydas Ignotas 520de941241SSukumar Ghorai if ((mmc_stat & ERRI_MASK) != 0) 521de941241SSukumar Ghorai return 1; 522de941241SSukumar Ghorai 523de941241SSukumar Ghorai if (mmc_stat & BWR_MASK) { 524de941241SSukumar Ghorai unsigned int k; 525de941241SSukumar Ghorai 526de941241SSukumar Ghorai writel(readl(&mmc_base->stat) | BWR_MASK, 527de941241SSukumar Ghorai &mmc_base->stat); 528de941241SSukumar Ghorai for (k = 0; k < count; k++) { 529de941241SSukumar Ghorai writel(*input_buf, &mmc_base->data); 530de941241SSukumar Ghorai input_buf++; 531de941241SSukumar Ghorai } 532de941241SSukumar Ghorai size -= (count*4); 533de941241SSukumar Ghorai } 534de941241SSukumar Ghorai 535de941241SSukumar Ghorai if (mmc_stat & BRR_MASK) 536de941241SSukumar Ghorai writel(readl(&mmc_base->stat) | BRR_MASK, 537de941241SSukumar Ghorai &mmc_base->stat); 538de941241SSukumar Ghorai 539de941241SSukumar Ghorai if (mmc_stat & TC_MASK) { 540de941241SSukumar Ghorai writel(readl(&mmc_base->stat) | TC_MASK, 541de941241SSukumar Ghorai &mmc_base->stat); 542de941241SSukumar Ghorai break; 543de941241SSukumar Ghorai } 544de941241SSukumar Ghorai } 545de941241SSukumar Ghorai return 0; 546de941241SSukumar Ghorai } 547de941241SSukumar Ghorai 548ab769f22SPantelis Antoniou static void omap_hsmmc_set_ios(struct mmc *mmc) 549de941241SSukumar Ghorai { 550cc22b0c0SNikita Kiryanov struct hsmmc *mmc_base; 551de941241SSukumar Ghorai unsigned int dsor = 0; 552eb9a28f6SNishanth Menon ulong start; 553de941241SSukumar Ghorai 554cc22b0c0SNikita Kiryanov mmc_base = ((struct omap_hsmmc_data *)mmc->priv)->base_addr; 555de941241SSukumar Ghorai /* configue bus width */ 556de941241SSukumar Ghorai switch (mmc->bus_width) { 557de941241SSukumar Ghorai case 8: 558de941241SSukumar Ghorai writel(readl(&mmc_base->con) | DTW_8_BITMODE, 559de941241SSukumar Ghorai &mmc_base->con); 560de941241SSukumar Ghorai break; 561de941241SSukumar Ghorai 562de941241SSukumar Ghorai case 4: 563de941241SSukumar Ghorai writel(readl(&mmc_base->con) & ~DTW_8_BITMODE, 564de941241SSukumar Ghorai &mmc_base->con); 565de941241SSukumar Ghorai writel(readl(&mmc_base->hctl) | DTW_4_BITMODE, 566de941241SSukumar Ghorai &mmc_base->hctl); 567de941241SSukumar Ghorai break; 568de941241SSukumar Ghorai 569de941241SSukumar Ghorai case 1: 570de941241SSukumar Ghorai default: 571de941241SSukumar Ghorai writel(readl(&mmc_base->con) & ~DTW_8_BITMODE, 572de941241SSukumar Ghorai &mmc_base->con); 573de941241SSukumar Ghorai writel(readl(&mmc_base->hctl) & ~DTW_4_BITMODE, 574de941241SSukumar Ghorai &mmc_base->hctl); 575de941241SSukumar Ghorai break; 576de941241SSukumar Ghorai } 577de941241SSukumar Ghorai 578de941241SSukumar Ghorai /* configure clock with 96Mhz system clock. 579de941241SSukumar Ghorai */ 580de941241SSukumar Ghorai if (mmc->clock != 0) { 581de941241SSukumar Ghorai dsor = (MMC_CLOCK_REFERENCE * 1000000 / mmc->clock); 582de941241SSukumar Ghorai if ((MMC_CLOCK_REFERENCE * 1000000) / dsor > mmc->clock) 583de941241SSukumar Ghorai dsor++; 584de941241SSukumar Ghorai } 585de941241SSukumar Ghorai 586de941241SSukumar Ghorai mmc_reg_out(&mmc_base->sysctl, (ICE_MASK | DTO_MASK | CEN_MASK), 587de941241SSukumar Ghorai (ICE_STOP | DTO_15THDTO | CEN_DISABLE)); 588de941241SSukumar Ghorai 589de941241SSukumar Ghorai mmc_reg_out(&mmc_base->sysctl, ICE_MASK | CLKD_MASK, 590de941241SSukumar Ghorai (dsor << CLKD_OFFSET) | ICE_OSCILLATE); 591de941241SSukumar Ghorai 592eb9a28f6SNishanth Menon start = get_timer(0); 593eb9a28f6SNishanth Menon while ((readl(&mmc_base->sysctl) & ICS_MASK) == ICS_NOTREADY) { 594eb9a28f6SNishanth Menon if (get_timer(0) - start > MAX_RETRY_MS) { 595eb9a28f6SNishanth Menon printf("%s: timedout waiting for ics!\n", __func__); 596eb9a28f6SNishanth Menon return; 597eb9a28f6SNishanth Menon } 598eb9a28f6SNishanth Menon } 599de941241SSukumar Ghorai writel(readl(&mmc_base->sysctl) | CEN_ENABLE, &mmc_base->sysctl); 600de941241SSukumar Ghorai } 601de941241SSukumar Ghorai 602ab769f22SPantelis Antoniou #ifdef OMAP_HSMMC_USE_GPIO 603ab769f22SPantelis Antoniou static int omap_hsmmc_getcd(struct mmc *mmc) 604ab769f22SPantelis Antoniou { 605ab769f22SPantelis Antoniou struct omap_hsmmc_data *priv_data = mmc->priv; 606ab769f22SPantelis Antoniou int cd_gpio; 607ab769f22SPantelis Antoniou 608ab769f22SPantelis Antoniou /* if no CD return as 1 */ 609ab769f22SPantelis Antoniou cd_gpio = priv_data->cd_gpio; 610ab769f22SPantelis Antoniou if (cd_gpio < 0) 611ab769f22SPantelis Antoniou return 1; 612ab769f22SPantelis Antoniou 6130b03a931SIgor Grinberg /* NOTE: assumes card detect signal is active-low */ 6140b03a931SIgor Grinberg return !gpio_get_value(cd_gpio); 615ab769f22SPantelis Antoniou } 616ab769f22SPantelis Antoniou 617ab769f22SPantelis Antoniou static int omap_hsmmc_getwp(struct mmc *mmc) 618ab769f22SPantelis Antoniou { 619ab769f22SPantelis Antoniou struct omap_hsmmc_data *priv_data = mmc->priv; 620ab769f22SPantelis Antoniou int wp_gpio; 621ab769f22SPantelis Antoniou 622ab769f22SPantelis Antoniou /* if no WP return as 0 */ 623ab769f22SPantelis Antoniou wp_gpio = priv_data->wp_gpio; 624ab769f22SPantelis Antoniou if (wp_gpio < 0) 625ab769f22SPantelis Antoniou return 0; 626ab769f22SPantelis Antoniou 6270b03a931SIgor Grinberg /* NOTE: assumes write protect signal is active-high */ 628ab769f22SPantelis Antoniou return gpio_get_value(wp_gpio); 629ab769f22SPantelis Antoniou } 630ab769f22SPantelis Antoniou #endif 631ab769f22SPantelis Antoniou 632ab769f22SPantelis Antoniou static const struct mmc_ops omap_hsmmc_ops = { 633ab769f22SPantelis Antoniou .send_cmd = omap_hsmmc_send_cmd, 634ab769f22SPantelis Antoniou .set_ios = omap_hsmmc_set_ios, 635ab769f22SPantelis Antoniou .init = omap_hsmmc_init_setup, 636ab769f22SPantelis Antoniou #ifdef OMAP_HSMMC_USE_GPIO 637ab769f22SPantelis Antoniou .getcd = omap_hsmmc_getcd, 638ab769f22SPantelis Antoniou .getwp = omap_hsmmc_getwp, 639ab769f22SPantelis Antoniou #endif 640ab769f22SPantelis Antoniou }; 641ab769f22SPantelis Antoniou 642e3913f56SNikita Kiryanov int omap_mmc_init(int dev_index, uint host_caps_mask, uint f_max, int cd_gpio, 643e3913f56SNikita Kiryanov int wp_gpio) 644de941241SSukumar Ghorai { 64593bfd616SPantelis Antoniou struct mmc *mmc; 64693bfd616SPantelis Antoniou struct omap_hsmmc_data *priv_data; 64793bfd616SPantelis Antoniou struct mmc_config *cfg; 64893bfd616SPantelis Antoniou uint host_caps_val; 649de941241SSukumar Ghorai 65093bfd616SPantelis Antoniou priv_data = malloc(sizeof(*priv_data)); 65193bfd616SPantelis Antoniou if (priv_data == NULL) 65293bfd616SPantelis Antoniou return -1; 65393bfd616SPantelis Antoniou 6545a20397bSRob Herring host_caps_val = MMC_MODE_4BIT | MMC_MODE_HS_52MHz | MMC_MODE_HS; 655de941241SSukumar Ghorai 656de941241SSukumar Ghorai switch (dev_index) { 657de941241SSukumar Ghorai case 0: 658cc22b0c0SNikita Kiryanov priv_data->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE; 659de941241SSukumar Ghorai break; 6601037d585STom Rini #ifdef OMAP_HSMMC2_BASE 661de941241SSukumar Ghorai case 1: 662cc22b0c0SNikita Kiryanov priv_data->base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE; 663152ba363SLubomir Popov #if (defined(CONFIG_OMAP44XX) || defined(CONFIG_OMAP54XX) || \ 664d11ac4b5SFelipe Balbi defined(CONFIG_DRA7XX) || defined(CONFIG_AM57XX)) && \ 665d11ac4b5SFelipe Balbi defined(CONFIG_HSMMC2_8BIT) 666152ba363SLubomir Popov /* Enable 8-bit interface for eMMC on OMAP4/5 or DRA7XX */ 667152ba363SLubomir Popov host_caps_val |= MMC_MODE_8BIT; 668152ba363SLubomir Popov #endif 669de941241SSukumar Ghorai break; 6701037d585STom Rini #endif 6711037d585STom Rini #ifdef OMAP_HSMMC3_BASE 672de941241SSukumar Ghorai case 2: 673cc22b0c0SNikita Kiryanov priv_data->base_addr = (struct hsmmc *)OMAP_HSMMC3_BASE; 674d11ac4b5SFelipe Balbi #if (defined(CONFIG_DRA7XX) || defined(CONFIG_AM57XX)) && defined(CONFIG_HSMMC3_8BIT) 675152ba363SLubomir Popov /* Enable 8-bit interface for eMMC on DRA7XX */ 676152ba363SLubomir Popov host_caps_val |= MMC_MODE_8BIT; 677152ba363SLubomir Popov #endif 678de941241SSukumar Ghorai break; 6791037d585STom Rini #endif 680de941241SSukumar Ghorai default: 681cc22b0c0SNikita Kiryanov priv_data->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE; 682de941241SSukumar Ghorai return 1; 683de941241SSukumar Ghorai } 684ab769f22SPantelis Antoniou #ifdef OMAP_HSMMC_USE_GPIO 685ab769f22SPantelis Antoniou /* on error gpio values are set to -1, which is what we want */ 686e874d5b0SNikita Kiryanov priv_data->cd_gpio = omap_mmc_setup_gpio_in(cd_gpio, "mmc_cd"); 687e3913f56SNikita Kiryanov priv_data->wp_gpio = omap_mmc_setup_gpio_in(wp_gpio, "mmc_wp"); 688ab769f22SPantelis Antoniou #endif 689173ddc5bSPeter Korsgaard 69093bfd616SPantelis Antoniou cfg = &priv_data->cfg; 691de941241SSukumar Ghorai 69293bfd616SPantelis Antoniou cfg->name = "OMAP SD/MMC"; 69393bfd616SPantelis Antoniou cfg->ops = &omap_hsmmc_ops; 69493bfd616SPantelis Antoniou 69593bfd616SPantelis Antoniou cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195; 69693bfd616SPantelis Antoniou cfg->host_caps = host_caps_val & ~host_caps_mask; 69793bfd616SPantelis Antoniou 69893bfd616SPantelis Antoniou cfg->f_min = 400000; 699bbbc1ae9SJonathan Solnit 700bbbc1ae9SJonathan Solnit if (f_max != 0) 70193bfd616SPantelis Antoniou cfg->f_max = f_max; 702bbbc1ae9SJonathan Solnit else { 70393bfd616SPantelis Antoniou if (cfg->host_caps & MMC_MODE_HS) { 70493bfd616SPantelis Antoniou if (cfg->host_caps & MMC_MODE_HS_52MHz) 70593bfd616SPantelis Antoniou cfg->f_max = 52000000; 706bbbc1ae9SJonathan Solnit else 70793bfd616SPantelis Antoniou cfg->f_max = 26000000; 708bbbc1ae9SJonathan Solnit } else 70993bfd616SPantelis Antoniou cfg->f_max = 20000000; 710bbbc1ae9SJonathan Solnit } 711de941241SSukumar Ghorai 71293bfd616SPantelis Antoniou cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; 7138feafcc4SJohn Rigby 7144ca9244dSJohn Rigby #if defined(CONFIG_OMAP34XX) 7154ca9244dSJohn Rigby /* 7164ca9244dSJohn Rigby * Silicon revs 2.1 and older do not support multiblock transfers. 7174ca9244dSJohn Rigby */ 7184ca9244dSJohn Rigby if ((get_cpu_family() == CPU_OMAP34XX) && (get_cpu_rev() <= CPU_3XX_ES21)) 71993bfd616SPantelis Antoniou cfg->b_max = 1; 7204ca9244dSJohn Rigby #endif 72193bfd616SPantelis Antoniou mmc = mmc_create(cfg, priv_data); 72293bfd616SPantelis Antoniou if (mmc == NULL) 72393bfd616SPantelis Antoniou return -1; 724de941241SSukumar Ghorai 725de941241SSukumar Ghorai return 0; 726de941241SSukumar Ghorai } 727