Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2008 |
| 3 | * Texas Instruments, <www.ti.com> |
| 4 | * Sukumar Ghorai <s-ghorai@ti.com> |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation's version 2 of |
| 12 | * the License. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include <config.h> |
| 26 | #include <common.h> |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 27 | #include <malloc.h> |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 28 | #include <memalign.h> |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 29 | #include <mmc.h> |
| 30 | #include <part.h> |
| 31 | #include <i2c.h> |
Felix Brack | 339d578 | 2017-10-11 17:05:28 +0200 | [diff] [blame] | 32 | #if defined(CONFIG_OMAP54XX) || defined(CONFIG_OMAP44XX) |
Nishanth Menon | cb19910 | 2013-03-26 05:20:54 +0000 | [diff] [blame] | 33 | #include <palmas.h> |
Felix Brack | 339d578 | 2017-10-11 17:05:28 +0200 | [diff] [blame] | 34 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 35 | #include <asm/io.h> |
| 36 | #include <asm/arch/mmc_host_def.h> |
Roger Quadros | 3b68939 | 2015-09-19 16:26:53 +0530 | [diff] [blame] | 37 | #if !defined(CONFIG_SOC_KEYSTONE) |
| 38 | #include <asm/gpio.h> |
Dirk Behme | 96e0e7b | 2011-05-15 09:04:47 +0000 | [diff] [blame] | 39 | #include <asm/arch/sys_proto.h> |
Roger Quadros | 3b68939 | 2015-09-19 16:26:53 +0530 | [diff] [blame] | 40 | #endif |
Tom Rini | 2a48b3a | 2017-02-09 13:41:28 -0500 | [diff] [blame] | 41 | #ifdef CONFIG_MMC_OMAP36XX_PINS |
| 42 | #include <asm/arch/mux.h> |
| 43 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 44 | #include <dm.h> |
| 45 | |
| 46 | DECLARE_GLOBAL_DATA_PTR; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 47 | |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 48 | /* simplify defines to OMAP_HSMMC_USE_GPIO */ |
| 49 | #if (defined(CONFIG_OMAP_GPIO) && !defined(CONFIG_SPL_BUILD)) || \ |
| 50 | (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_GPIO_SUPPORT)) |
| 51 | #define OMAP_HSMMC_USE_GPIO |
| 52 | #else |
| 53 | #undef OMAP_HSMMC_USE_GPIO |
| 54 | #endif |
| 55 | |
Grazvydas Ignotas | 25c719e | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 56 | /* common definitions for all OMAPs */ |
| 57 | #define SYSCTL_SRC (1 << 25) |
| 58 | #define SYSCTL_SRD (1 << 26) |
| 59 | |
Nikita Kiryanov | cc22b0c | 2012-12-03 02:19:43 +0000 | [diff] [blame] | 60 | struct omap_hsmmc_data { |
| 61 | struct hsmmc *base_addr; |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 62 | #if !CONFIG_IS_ENABLED(DM_MMC) |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 63 | struct mmc_config cfg; |
Jean-Jacques Hiblot | 3d673ff | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 64 | #endif |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 65 | #ifdef OMAP_HSMMC_USE_GPIO |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 66 | #if CONFIG_IS_ENABLED(DM_MMC) |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 67 | struct gpio_desc cd_gpio; /* Change Detect GPIO */ |
| 68 | struct gpio_desc wp_gpio; /* Write Protect GPIO */ |
| 69 | bool cd_inverted; |
| 70 | #else |
Nikita Kiryanov | e874d5b | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 71 | int cd_gpio; |
Nikita Kiryanov | e3913f5 | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 72 | int wp_gpio; |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 73 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 74 | #endif |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 75 | u8 controller_flags; |
| 76 | #ifndef CONFIG_OMAP34XX |
| 77 | struct omap_hsmmc_adma_desc *adma_desc_table; |
| 78 | uint desc_slot; |
| 79 | #endif |
Nikita Kiryanov | cc22b0c | 2012-12-03 02:19:43 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 82 | #ifndef CONFIG_OMAP34XX |
| 83 | struct omap_hsmmc_adma_desc { |
| 84 | u8 attr; |
| 85 | u8 reserved; |
| 86 | u16 len; |
| 87 | u32 addr; |
| 88 | }; |
| 89 | |
| 90 | #define ADMA_MAX_LEN 63488 |
| 91 | |
| 92 | /* Decriptor table defines */ |
| 93 | #define ADMA_DESC_ATTR_VALID BIT(0) |
| 94 | #define ADMA_DESC_ATTR_END BIT(1) |
| 95 | #define ADMA_DESC_ATTR_INT BIT(2) |
| 96 | #define ADMA_DESC_ATTR_ACT1 BIT(4) |
| 97 | #define ADMA_DESC_ATTR_ACT2 BIT(5) |
| 98 | |
| 99 | #define ADMA_DESC_TRANSFER_DATA ADMA_DESC_ATTR_ACT2 |
| 100 | #define ADMA_DESC_LINK_DESC (ADMA_DESC_ATTR_ACT1 | ADMA_DESC_ATTR_ACT2) |
| 101 | #endif |
| 102 | |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 103 | /* If we fail after 1 second wait, something is really bad */ |
| 104 | #define MAX_RETRY_MS 1000 |
| 105 | |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 106 | /* DMA transfers can take a long time if a lot a data is transferred. |
| 107 | * The timeout must take in account the amount of data. Let's assume |
| 108 | * that the time will never exceed 333 ms per MB (in other word we assume |
| 109 | * that the bandwidth is always above 3MB/s). |
| 110 | */ |
| 111 | #define DMA_TIMEOUT_PER_MB 333 |
| 112 | #define OMAP_HSMMC_USE_ADMA BIT(2) |
| 113 | |
Sricharan | 933efe6 | 2011-11-15 09:49:53 -0500 | [diff] [blame] | 114 | static int mmc_read_data(struct hsmmc *mmc_base, char *buf, unsigned int size); |
| 115 | static int mmc_write_data(struct hsmmc *mmc_base, const char *buf, |
| 116 | unsigned int siz); |
Balaji T K | 14fa2dd | 2011-09-08 06:34:57 +0000 | [diff] [blame] | 117 | |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 118 | static inline struct omap_hsmmc_data *omap_hsmmc_get_data(struct mmc *mmc) |
| 119 | { |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 120 | #if CONFIG_IS_ENABLED(DM_MMC) |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 121 | return dev_get_priv(mmc->dev); |
| 122 | #else |
| 123 | return (struct omap_hsmmc_data *)mmc->priv; |
| 124 | #endif |
| 125 | } |
Jean-Jacques Hiblot | 3d673ff | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 126 | static inline struct mmc_config *omap_hsmmc_get_cfg(struct mmc *mmc) |
| 127 | { |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 128 | #if CONFIG_IS_ENABLED(DM_MMC) |
Jean-Jacques Hiblot | 3d673ff | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 129 | struct omap_hsmmc_plat *plat = dev_get_platdata(mmc->dev); |
| 130 | return &plat->cfg; |
| 131 | #else |
| 132 | return &((struct omap_hsmmc_data *)mmc->priv)->cfg; |
| 133 | #endif |
| 134 | } |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 135 | |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 136 | #if defined(OMAP_HSMMC_USE_GPIO) && !CONFIG_IS_ENABLED(DM_MMC) |
Nikita Kiryanov | e874d5b | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 137 | static int omap_mmc_setup_gpio_in(int gpio, const char *label) |
| 138 | { |
Simon Glass | 5915a2a | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 139 | int ret; |
| 140 | |
| 141 | #ifndef CONFIG_DM_GPIO |
Nikita Kiryanov | e874d5b | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 142 | if (!gpio_is_valid(gpio)) |
| 143 | return -1; |
Simon Glass | 5915a2a | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 144 | #endif |
| 145 | ret = gpio_request(gpio, label); |
| 146 | if (ret) |
| 147 | return ret; |
Nikita Kiryanov | e874d5b | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 148 | |
Simon Glass | 5915a2a | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 149 | ret = gpio_direction_input(gpio); |
| 150 | if (ret) |
| 151 | return ret; |
Nikita Kiryanov | e874d5b | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 152 | |
| 153 | return gpio; |
| 154 | } |
Nikita Kiryanov | e874d5b | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 155 | #endif |
| 156 | |
Jeroen Hofstee | 750121c | 2014-07-12 21:24:08 +0200 | [diff] [blame] | 157 | static unsigned char mmc_board_init(struct mmc *mmc) |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 158 | { |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 159 | #if defined(CONFIG_OMAP34XX) |
Jean-Jacques Hiblot | 3d673ff | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 160 | struct mmc_config *cfg = omap_hsmmc_get_cfg(mmc); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 161 | t2_t *t2_base = (t2_t *)T2_BASE; |
| 162 | struct prcm *prcm_base = (struct prcm *)PRCM_BASE; |
Grazvydas Ignotas | b1e725f | 2012-03-19 03:50:53 +0000 | [diff] [blame] | 163 | u32 pbias_lite; |
Adam Ford | 6aca17c | 2017-02-06 11:31:43 -0600 | [diff] [blame] | 164 | #ifdef CONFIG_MMC_OMAP36XX_PINS |
| 165 | u32 wkup_ctrl = readl(OMAP34XX_CTRL_WKUP_CTRL); |
| 166 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 167 | |
Grazvydas Ignotas | b1e725f | 2012-03-19 03:50:53 +0000 | [diff] [blame] | 168 | pbias_lite = readl(&t2_base->pbias_lite); |
| 169 | pbias_lite &= ~(PBIASLITEPWRDNZ1 | PBIASLITEPWRDNZ0); |
Albert ARIBAUD \(3ADEV\) | 5bfdd1f | 2015-01-16 09:09:50 +0100 | [diff] [blame] | 170 | #ifdef CONFIG_TARGET_OMAP3_CAIRO |
| 171 | /* for cairo board, we need to set up 1.8 Volt bias level on MMC1 */ |
| 172 | pbias_lite &= ~PBIASLITEVMODE0; |
| 173 | #endif |
Adam Ford | 6aca17c | 2017-02-06 11:31:43 -0600 | [diff] [blame] | 174 | #ifdef CONFIG_MMC_OMAP36XX_PINS |
| 175 | if (get_cpu_family() == CPU_OMAP36XX) { |
| 176 | /* Disable extended drain IO before changing PBIAS */ |
| 177 | wkup_ctrl &= ~OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ; |
| 178 | writel(wkup_ctrl, OMAP34XX_CTRL_WKUP_CTRL); |
| 179 | } |
| 180 | #endif |
Grazvydas Ignotas | b1e725f | 2012-03-19 03:50:53 +0000 | [diff] [blame] | 181 | writel(pbias_lite, &t2_base->pbias_lite); |
Paul Kocialkowski | aac5450 | 2014-11-08 20:55:47 +0100 | [diff] [blame] | 182 | |
Grazvydas Ignotas | b1e725f | 2012-03-19 03:50:53 +0000 | [diff] [blame] | 183 | writel(pbias_lite | PBIASLITEPWRDNZ1 | |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 184 | PBIASSPEEDCTRL0 | PBIASLITEPWRDNZ0, |
| 185 | &t2_base->pbias_lite); |
| 186 | |
Adam Ford | 6aca17c | 2017-02-06 11:31:43 -0600 | [diff] [blame] | 187 | #ifdef CONFIG_MMC_OMAP36XX_PINS |
| 188 | if (get_cpu_family() == CPU_OMAP36XX) |
| 189 | /* Enable extended drain IO after changing PBIAS */ |
| 190 | writel(wkup_ctrl | |
| 191 | OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ, |
| 192 | OMAP34XX_CTRL_WKUP_CTRL); |
| 193 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 194 | writel(readl(&t2_base->devconf0) | MMCSDIO1ADPCLKISEL, |
| 195 | &t2_base->devconf0); |
| 196 | |
| 197 | writel(readl(&t2_base->devconf1) | MMCSDIO2ADPCLKISEL, |
| 198 | &t2_base->devconf1); |
| 199 | |
Jonathan Solnit | bbbc1ae | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 200 | /* Change from default of 52MHz to 26MHz if necessary */ |
Jean-Jacques Hiblot | 3d673ff | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 201 | if (!(cfg->host_caps & MMC_MODE_HS_52MHz)) |
Jonathan Solnit | bbbc1ae | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 202 | writel(readl(&t2_base->ctl_prog_io1) & ~CTLPROGIO1SPEEDCTRL, |
| 203 | &t2_base->ctl_prog_io1); |
| 204 | |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 205 | writel(readl(&prcm_base->fclken1_core) | |
| 206 | EN_MMC1 | EN_MMC2 | EN_MMC3, |
| 207 | &prcm_base->fclken1_core); |
| 208 | |
| 209 | writel(readl(&prcm_base->iclken1_core) | |
| 210 | EN_MMC1 | EN_MMC2 | EN_MMC3, |
| 211 | &prcm_base->iclken1_core); |
| 212 | #endif |
| 213 | |
Lokesh Vutla | b4b0600 | 2016-11-23 13:25:28 +0530 | [diff] [blame] | 214 | #if defined(CONFIG_OMAP54XX) || defined(CONFIG_OMAP44XX) |
Balaji T K | 14fa2dd | 2011-09-08 06:34:57 +0000 | [diff] [blame] | 215 | /* PBIAS config needed for MMC1 only */ |
Jean-Jacques Hiblot | dc09127 | 2017-03-22 16:00:32 +0100 | [diff] [blame] | 216 | if (mmc_get_blk_desc(mmc)->devnum == 0) |
Lokesh Vutla | b4b0600 | 2016-11-23 13:25:28 +0530 | [diff] [blame] | 217 | vmmc_pbias_config(LDO_VOLT_3V0); |
Balaji T K | dd23e59 | 2012-03-12 02:25:49 +0000 | [diff] [blame] | 218 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 219 | |
| 220 | return 0; |
| 221 | } |
| 222 | |
Sricharan | 933efe6 | 2011-11-15 09:49:53 -0500 | [diff] [blame] | 223 | void mmc_init_stream(struct hsmmc *mmc_base) |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 224 | { |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 225 | ulong start; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 226 | |
| 227 | writel(readl(&mmc_base->con) | INIT_INITSTREAM, &mmc_base->con); |
| 228 | |
| 229 | writel(MMC_CMD0, &mmc_base->cmd); |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 230 | start = get_timer(0); |
| 231 | while (!(readl(&mmc_base->stat) & CC_MASK)) { |
| 232 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 233 | printf("%s: timedout waiting for cc!\n", __func__); |
| 234 | return; |
| 235 | } |
| 236 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 237 | writel(CC_MASK, &mmc_base->stat) |
| 238 | ; |
| 239 | writel(MMC_CMD0, &mmc_base->cmd) |
| 240 | ; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 241 | start = get_timer(0); |
| 242 | while (!(readl(&mmc_base->stat) & CC_MASK)) { |
| 243 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 244 | printf("%s: timedout waiting for cc2!\n", __func__); |
| 245 | return; |
| 246 | } |
| 247 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 248 | writel(readl(&mmc_base->con) & ~INIT_INITSTREAM, &mmc_base->con); |
| 249 | } |
| 250 | |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 251 | static int omap_hsmmc_init_setup(struct mmc *mmc) |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 252 | { |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 253 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Nikita Kiryanov | cc22b0c | 2012-12-03 02:19:43 +0000 | [diff] [blame] | 254 | struct hsmmc *mmc_base; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 255 | unsigned int reg_val; |
| 256 | unsigned int dsor; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 257 | ulong start; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 258 | |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 259 | mmc_base = priv->base_addr; |
Balaji T K | 14fa2dd | 2011-09-08 06:34:57 +0000 | [diff] [blame] | 260 | mmc_board_init(mmc); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 261 | |
| 262 | writel(readl(&mmc_base->sysconfig) | MMC_SOFTRESET, |
| 263 | &mmc_base->sysconfig); |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 264 | start = get_timer(0); |
| 265 | while ((readl(&mmc_base->sysstatus) & RESETDONE) == 0) { |
| 266 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 267 | printf("%s: timedout waiting for cc2!\n", __func__); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 268 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 269 | } |
| 270 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 271 | writel(readl(&mmc_base->sysctl) | SOFTRESETALL, &mmc_base->sysctl); |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 272 | start = get_timer(0); |
| 273 | while ((readl(&mmc_base->sysctl) & SOFTRESETALL) != 0x0) { |
| 274 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 275 | printf("%s: timedout waiting for softresetall!\n", |
| 276 | __func__); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 277 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 278 | } |
| 279 | } |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 280 | #ifndef CONFIG_OMAP34XX |
| 281 | reg_val = readl(&mmc_base->hl_hwinfo); |
| 282 | if (reg_val & MADMA_EN) |
| 283 | priv->controller_flags |= OMAP_HSMMC_USE_ADMA; |
| 284 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 285 | writel(DTW_1_BITMODE | SDBP_PWROFF | SDVS_3V0, &mmc_base->hctl); |
| 286 | writel(readl(&mmc_base->capa) | VS30_3V0SUP | VS18_1V8SUP, |
| 287 | &mmc_base->capa); |
| 288 | |
| 289 | reg_val = readl(&mmc_base->con) & RESERVED_MASK; |
| 290 | |
| 291 | writel(CTPL_MMC_SD | reg_val | WPP_ACTIVEHIGH | CDP_ACTIVEHIGH | |
| 292 | MIT_CTO | DW8_1_4BITMODE | MODE_FUNC | STR_BLOCK | |
| 293 | HR_NOHOSTRESP | INIT_NOINIT | NOOPENDRAIN, &mmc_base->con); |
| 294 | |
| 295 | dsor = 240; |
| 296 | mmc_reg_out(&mmc_base->sysctl, (ICE_MASK | DTO_MASK | CEN_MASK), |
Kishon Vijay Abraham I | 29171dc | 2017-09-21 16:51:36 +0200 | [diff] [blame] | 297 | (ICE_STOP | DTO_15THDTO)); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 298 | mmc_reg_out(&mmc_base->sysctl, ICE_MASK | CLKD_MASK, |
| 299 | (dsor << CLKD_OFFSET) | ICE_OSCILLATE); |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 300 | start = get_timer(0); |
| 301 | while ((readl(&mmc_base->sysctl) & ICS_MASK) == ICS_NOTREADY) { |
| 302 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 303 | printf("%s: timedout waiting for ics!\n", __func__); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 304 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 305 | } |
| 306 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 307 | writel(readl(&mmc_base->sysctl) | CEN_ENABLE, &mmc_base->sysctl); |
| 308 | |
| 309 | writel(readl(&mmc_base->hctl) | SDBP_PWRON, &mmc_base->hctl); |
| 310 | |
| 311 | writel(IE_BADA | IE_CERR | IE_DEB | IE_DCRC | IE_DTO | IE_CIE | |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 312 | IE_CEB | IE_CCRC | IE_ADMAE | IE_CTO | IE_BRR | IE_BWR | IE_TC | |
| 313 | IE_CC, &mmc_base->ie); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 314 | |
| 315 | mmc_init_stream(mmc_base); |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
Grazvydas Ignotas | 25c719e | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 320 | /* |
| 321 | * MMC controller internal finite state machine reset |
| 322 | * |
| 323 | * Used to reset command or data internal state machines, using respectively |
| 324 | * SRC or SRD bit of SYSCTL register |
| 325 | */ |
| 326 | static void mmc_reset_controller_fsm(struct hsmmc *mmc_base, u32 bit) |
| 327 | { |
| 328 | ulong start; |
| 329 | |
| 330 | mmc_reg_out(&mmc_base->sysctl, bit, bit); |
| 331 | |
Oleksandr Tyshchenko | 61a6cc2 | 2013-08-06 13:44:16 +0300 | [diff] [blame] | 332 | /* |
| 333 | * CMD(DAT) lines reset procedures are slightly different |
| 334 | * for OMAP3 and OMAP4(AM335x,OMAP5,DRA7xx). |
| 335 | * According to OMAP3 TRM: |
| 336 | * Set SRC(SRD) bit in MMCHS_SYSCTL register to 0x1 and wait until it |
| 337 | * returns to 0x0. |
| 338 | * According to OMAP4(AM335x,OMAP5,DRA7xx) TRMs, CMD(DATA) lines reset |
| 339 | * procedure steps must be as follows: |
| 340 | * 1. Initiate CMD(DAT) line reset by writing 0x1 to SRC(SRD) bit in |
| 341 | * MMCHS_SYSCTL register (SD_SYSCTL for AM335x). |
| 342 | * 2. Poll the SRC(SRD) bit until it is set to 0x1. |
| 343 | * 3. Wait until the SRC (SRD) bit returns to 0x0 |
| 344 | * (reset procedure is completed). |
| 345 | */ |
| 346 | #if defined(CONFIG_OMAP44XX) || defined(CONFIG_OMAP54XX) || \ |
Nikita Kiryanov | dce55b9 | 2015-07-30 23:56:20 +0300 | [diff] [blame] | 347 | defined(CONFIG_AM33XX) || defined(CONFIG_AM43XX) |
Oleksandr Tyshchenko | 61a6cc2 | 2013-08-06 13:44:16 +0300 | [diff] [blame] | 348 | if (!(readl(&mmc_base->sysctl) & bit)) { |
| 349 | start = get_timer(0); |
| 350 | while (!(readl(&mmc_base->sysctl) & bit)) { |
| 351 | if (get_timer(0) - start > MAX_RETRY_MS) |
| 352 | return; |
| 353 | } |
| 354 | } |
| 355 | #endif |
Grazvydas Ignotas | 25c719e | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 356 | start = get_timer(0); |
| 357 | while ((readl(&mmc_base->sysctl) & bit) != 0) { |
| 358 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 359 | printf("%s: timedout waiting for sysctl %x to clear\n", |
| 360 | __func__, bit); |
| 361 | return; |
| 362 | } |
| 363 | } |
| 364 | } |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 365 | |
| 366 | #ifndef CONFIG_OMAP34XX |
| 367 | static void omap_hsmmc_adma_desc(struct mmc *mmc, char *buf, u16 len, bool end) |
| 368 | { |
| 369 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 370 | struct omap_hsmmc_adma_desc *desc; |
| 371 | u8 attr; |
| 372 | |
| 373 | desc = &priv->adma_desc_table[priv->desc_slot]; |
| 374 | |
| 375 | attr = ADMA_DESC_ATTR_VALID | ADMA_DESC_TRANSFER_DATA; |
| 376 | if (!end) |
| 377 | priv->desc_slot++; |
| 378 | else |
| 379 | attr |= ADMA_DESC_ATTR_END; |
| 380 | |
| 381 | desc->len = len; |
| 382 | desc->addr = (u32)buf; |
| 383 | desc->reserved = 0; |
| 384 | desc->attr = attr; |
| 385 | } |
| 386 | |
| 387 | static void omap_hsmmc_prepare_adma_table(struct mmc *mmc, |
| 388 | struct mmc_data *data) |
| 389 | { |
| 390 | uint total_len = data->blocksize * data->blocks; |
| 391 | uint desc_count = DIV_ROUND_UP(total_len, ADMA_MAX_LEN); |
| 392 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 393 | int i = desc_count; |
| 394 | char *buf; |
| 395 | |
| 396 | priv->desc_slot = 0; |
| 397 | priv->adma_desc_table = (struct omap_hsmmc_adma_desc *) |
| 398 | memalign(ARCH_DMA_MINALIGN, desc_count * |
| 399 | sizeof(struct omap_hsmmc_adma_desc)); |
| 400 | |
| 401 | if (data->flags & MMC_DATA_READ) |
| 402 | buf = data->dest; |
| 403 | else |
| 404 | buf = (char *)data->src; |
| 405 | |
| 406 | while (--i) { |
| 407 | omap_hsmmc_adma_desc(mmc, buf, ADMA_MAX_LEN, false); |
| 408 | buf += ADMA_MAX_LEN; |
| 409 | total_len -= ADMA_MAX_LEN; |
| 410 | } |
| 411 | |
| 412 | omap_hsmmc_adma_desc(mmc, buf, total_len, true); |
| 413 | |
| 414 | flush_dcache_range((long)priv->adma_desc_table, |
| 415 | (long)priv->adma_desc_table + |
| 416 | ROUND(desc_count * |
| 417 | sizeof(struct omap_hsmmc_adma_desc), |
| 418 | ARCH_DMA_MINALIGN)); |
| 419 | } |
| 420 | |
| 421 | static void omap_hsmmc_prepare_data(struct mmc *mmc, struct mmc_data *data) |
| 422 | { |
| 423 | struct hsmmc *mmc_base; |
| 424 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 425 | u32 val; |
| 426 | char *buf; |
| 427 | |
| 428 | mmc_base = priv->base_addr; |
| 429 | omap_hsmmc_prepare_adma_table(mmc, data); |
| 430 | |
| 431 | if (data->flags & MMC_DATA_READ) |
| 432 | buf = data->dest; |
| 433 | else |
| 434 | buf = (char *)data->src; |
| 435 | |
| 436 | val = readl(&mmc_base->hctl); |
| 437 | val |= DMA_SELECT; |
| 438 | writel(val, &mmc_base->hctl); |
| 439 | |
| 440 | val = readl(&mmc_base->con); |
| 441 | val |= DMA_MASTER; |
| 442 | writel(val, &mmc_base->con); |
| 443 | |
| 444 | writel((u32)priv->adma_desc_table, &mmc_base->admasal); |
| 445 | |
| 446 | flush_dcache_range((u32)buf, |
| 447 | (u32)buf + |
| 448 | ROUND(data->blocksize * data->blocks, |
| 449 | ARCH_DMA_MINALIGN)); |
| 450 | } |
| 451 | |
| 452 | static void omap_hsmmc_dma_cleanup(struct mmc *mmc) |
| 453 | { |
| 454 | struct hsmmc *mmc_base; |
| 455 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 456 | u32 val; |
| 457 | |
| 458 | mmc_base = priv->base_addr; |
| 459 | |
| 460 | val = readl(&mmc_base->con); |
| 461 | val &= ~DMA_MASTER; |
| 462 | writel(val, &mmc_base->con); |
| 463 | |
| 464 | val = readl(&mmc_base->hctl); |
| 465 | val &= ~DMA_SELECT; |
| 466 | writel(val, &mmc_base->hctl); |
| 467 | |
| 468 | kfree(priv->adma_desc_table); |
| 469 | } |
| 470 | #else |
| 471 | #define omap_hsmmc_adma_desc |
| 472 | #define omap_hsmmc_prepare_adma_table |
| 473 | #define omap_hsmmc_prepare_data |
| 474 | #define omap_hsmmc_dma_cleanup |
| 475 | #endif |
| 476 | |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 477 | #if !CONFIG_IS_ENABLED(DM_MMC) |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 478 | static int omap_hsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 479 | struct mmc_data *data) |
| 480 | { |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 481 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 482 | #else |
| 483 | static int omap_hsmmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd, |
| 484 | struct mmc_data *data) |
| 485 | { |
| 486 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 487 | #ifndef CONFIG_OMAP34XX |
| 488 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 489 | struct mmc *mmc = upriv->mmc; |
| 490 | #endif |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 491 | #endif |
Nikita Kiryanov | cc22b0c | 2012-12-03 02:19:43 +0000 | [diff] [blame] | 492 | struct hsmmc *mmc_base; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 493 | unsigned int flags, mmc_stat; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 494 | ulong start; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 495 | |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 496 | mmc_base = priv->base_addr; |
Kishon Vijay Abraham I | 866bb98 | 2017-09-21 16:51:35 +0200 | [diff] [blame] | 497 | |
| 498 | if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION) |
| 499 | return 0; |
| 500 | |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 501 | start = get_timer(0); |
Tom Rini | a7778f8 | 2012-01-30 11:22:25 +0000 | [diff] [blame] | 502 | while ((readl(&mmc_base->pstate) & (DATI_MASK | CMDI_MASK)) != 0) { |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 503 | if (get_timer(0) - start > MAX_RETRY_MS) { |
Tom Rini | a7778f8 | 2012-01-30 11:22:25 +0000 | [diff] [blame] | 504 | printf("%s: timedout waiting on cmd inhibit to clear\n", |
| 505 | __func__); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 506 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 507 | } |
| 508 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 509 | writel(0xFFFFFFFF, &mmc_base->stat); |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 510 | start = get_timer(0); |
| 511 | while (readl(&mmc_base->stat)) { |
| 512 | if (get_timer(0) - start > MAX_RETRY_MS) { |
Grazvydas Ignotas | 15ceb1d | 2012-03-19 12:11:43 +0000 | [diff] [blame] | 513 | printf("%s: timedout waiting for STAT (%x) to clear\n", |
| 514 | __func__, readl(&mmc_base->stat)); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 515 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 516 | } |
| 517 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 518 | /* |
| 519 | * CMDREG |
| 520 | * CMDIDX[13:8] : Command index |
| 521 | * DATAPRNT[5] : Data Present Select |
| 522 | * ENCMDIDX[4] : Command Index Check Enable |
| 523 | * ENCMDCRC[3] : Command CRC Check Enable |
| 524 | * RSPTYP[1:0] |
| 525 | * 00 = No Response |
| 526 | * 01 = Length 136 |
| 527 | * 10 = Length 48 |
| 528 | * 11 = Length 48 Check busy after response |
| 529 | */ |
| 530 | /* Delay added before checking the status of frq change |
| 531 | * retry not supported by mmc.c(core file) |
| 532 | */ |
| 533 | if (cmd->cmdidx == SD_CMD_APP_SEND_SCR) |
| 534 | udelay(50000); /* wait 50 ms */ |
| 535 | |
| 536 | if (!(cmd->resp_type & MMC_RSP_PRESENT)) |
| 537 | flags = 0; |
| 538 | else if (cmd->resp_type & MMC_RSP_136) |
| 539 | flags = RSP_TYPE_LGHT136 | CICE_NOCHECK; |
| 540 | else if (cmd->resp_type & MMC_RSP_BUSY) |
| 541 | flags = RSP_TYPE_LGHT48B; |
| 542 | else |
| 543 | flags = RSP_TYPE_LGHT48; |
| 544 | |
| 545 | /* enable default flags */ |
| 546 | flags = flags | (CMD_TYPE_NORMAL | CICE_NOCHECK | CCCE_NOCHECK | |
Kishon Vijay Abraham I | 29171dc | 2017-09-21 16:51:36 +0200 | [diff] [blame] | 547 | MSBS_SGLEBLK); |
| 548 | flags &= ~(ACEN_ENABLE | BCE_ENABLE | DE_ENABLE); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 549 | |
| 550 | if (cmd->resp_type & MMC_RSP_CRC) |
| 551 | flags |= CCCE_CHECK; |
| 552 | if (cmd->resp_type & MMC_RSP_OPCODE) |
| 553 | flags |= CICE_CHECK; |
| 554 | |
| 555 | if (data) { |
| 556 | if ((cmd->cmdidx == MMC_CMD_READ_MULTIPLE_BLOCK) || |
| 557 | (cmd->cmdidx == MMC_CMD_WRITE_MULTIPLE_BLOCK)) { |
Kishon Vijay Abraham I | 866bb98 | 2017-09-21 16:51:35 +0200 | [diff] [blame] | 558 | flags |= (MSBS_MULTIBLK | BCE_ENABLE | ACEN_ENABLE); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 559 | data->blocksize = 512; |
| 560 | writel(data->blocksize | (data->blocks << 16), |
| 561 | &mmc_base->blk); |
| 562 | } else |
| 563 | writel(data->blocksize | NBLK_STPCNT, &mmc_base->blk); |
| 564 | |
| 565 | if (data->flags & MMC_DATA_READ) |
| 566 | flags |= (DP_DATA | DDIR_READ); |
| 567 | else |
| 568 | flags |= (DP_DATA | DDIR_WRITE); |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 569 | |
| 570 | #ifndef CONFIG_OMAP34XX |
| 571 | if ((priv->controller_flags & OMAP_HSMMC_USE_ADMA) && |
| 572 | !mmc_is_tuning_cmd(cmd->cmdidx)) { |
| 573 | omap_hsmmc_prepare_data(mmc, data); |
| 574 | flags |= DE_ENABLE; |
| 575 | } |
| 576 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | writel(cmd->cmdarg, &mmc_base->arg); |
Lubomir Popov | 152ba36 | 2013-08-14 18:59:18 +0300 | [diff] [blame] | 580 | udelay(20); /* To fix "No status update" error on eMMC */ |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 581 | writel((cmd->cmdidx << 24) | flags, &mmc_base->cmd); |
| 582 | |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 583 | start = get_timer(0); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 584 | do { |
| 585 | mmc_stat = readl(&mmc_base->stat); |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 586 | if (get_timer(start) > MAX_RETRY_MS) { |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 587 | printf("%s : timeout: No status update\n", __func__); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 588 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 589 | } |
| 590 | } while (!mmc_stat); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 591 | |
Grazvydas Ignotas | 25c719e | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 592 | if ((mmc_stat & IE_CTO) != 0) { |
| 593 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRC); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 594 | return -ETIMEDOUT; |
Grazvydas Ignotas | 25c719e | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 595 | } else if ((mmc_stat & ERRI_MASK) != 0) |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 596 | return -1; |
| 597 | |
| 598 | if (mmc_stat & CC_MASK) { |
| 599 | writel(CC_MASK, &mmc_base->stat); |
| 600 | if (cmd->resp_type & MMC_RSP_PRESENT) { |
| 601 | if (cmd->resp_type & MMC_RSP_136) { |
| 602 | /* response type 2 */ |
| 603 | cmd->response[3] = readl(&mmc_base->rsp10); |
| 604 | cmd->response[2] = readl(&mmc_base->rsp32); |
| 605 | cmd->response[1] = readl(&mmc_base->rsp54); |
| 606 | cmd->response[0] = readl(&mmc_base->rsp76); |
| 607 | } else |
| 608 | /* response types 1, 1b, 3, 4, 5, 6 */ |
| 609 | cmd->response[0] = readl(&mmc_base->rsp10); |
| 610 | } |
| 611 | } |
| 612 | |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 613 | #ifndef CONFIG_OMAP34XX |
| 614 | if ((priv->controller_flags & OMAP_HSMMC_USE_ADMA) && data && |
| 615 | !mmc_is_tuning_cmd(cmd->cmdidx)) { |
| 616 | u32 sz_mb, timeout; |
| 617 | |
| 618 | if (mmc_stat & IE_ADMAE) { |
| 619 | omap_hsmmc_dma_cleanup(mmc); |
| 620 | return -EIO; |
| 621 | } |
| 622 | |
| 623 | sz_mb = DIV_ROUND_UP(data->blocksize * data->blocks, 1 << 20); |
| 624 | timeout = sz_mb * DMA_TIMEOUT_PER_MB; |
| 625 | if (timeout < MAX_RETRY_MS) |
| 626 | timeout = MAX_RETRY_MS; |
| 627 | |
| 628 | start = get_timer(0); |
| 629 | do { |
| 630 | mmc_stat = readl(&mmc_base->stat); |
| 631 | if (mmc_stat & TC_MASK) { |
| 632 | writel(readl(&mmc_base->stat) | TC_MASK, |
| 633 | &mmc_base->stat); |
| 634 | break; |
| 635 | } |
| 636 | if (get_timer(start) > timeout) { |
| 637 | printf("%s : DMA timeout: No status update\n", |
| 638 | __func__); |
| 639 | return -ETIMEDOUT; |
| 640 | } |
| 641 | } while (1); |
| 642 | |
| 643 | omap_hsmmc_dma_cleanup(mmc); |
| 644 | return 0; |
| 645 | } |
| 646 | #endif |
| 647 | |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 648 | if (data && (data->flags & MMC_DATA_READ)) { |
| 649 | mmc_read_data(mmc_base, data->dest, |
| 650 | data->blocksize * data->blocks); |
| 651 | } else if (data && (data->flags & MMC_DATA_WRITE)) { |
| 652 | mmc_write_data(mmc_base, data->src, |
| 653 | data->blocksize * data->blocks); |
| 654 | } |
| 655 | return 0; |
| 656 | } |
| 657 | |
Sricharan | 933efe6 | 2011-11-15 09:49:53 -0500 | [diff] [blame] | 658 | static int mmc_read_data(struct hsmmc *mmc_base, char *buf, unsigned int size) |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 659 | { |
| 660 | unsigned int *output_buf = (unsigned int *)buf; |
| 661 | unsigned int mmc_stat; |
| 662 | unsigned int count; |
| 663 | |
| 664 | /* |
| 665 | * Start Polled Read |
| 666 | */ |
| 667 | count = (size > MMCSD_SECTOR_SIZE) ? MMCSD_SECTOR_SIZE : size; |
| 668 | count /= 4; |
| 669 | |
| 670 | while (size) { |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 671 | ulong start = get_timer(0); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 672 | do { |
| 673 | mmc_stat = readl(&mmc_base->stat); |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 674 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 675 | printf("%s: timedout waiting for status!\n", |
| 676 | __func__); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 677 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 678 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 679 | } while (mmc_stat == 0); |
| 680 | |
Grazvydas Ignotas | 25c719e | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 681 | if ((mmc_stat & (IE_DTO | IE_DCRC | IE_DEB)) != 0) |
| 682 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD); |
| 683 | |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 684 | if ((mmc_stat & ERRI_MASK) != 0) |
| 685 | return 1; |
| 686 | |
| 687 | if (mmc_stat & BRR_MASK) { |
| 688 | unsigned int k; |
| 689 | |
| 690 | writel(readl(&mmc_base->stat) | BRR_MASK, |
| 691 | &mmc_base->stat); |
| 692 | for (k = 0; k < count; k++) { |
| 693 | *output_buf = readl(&mmc_base->data); |
| 694 | output_buf++; |
| 695 | } |
| 696 | size -= (count*4); |
| 697 | } |
| 698 | |
| 699 | if (mmc_stat & BWR_MASK) |
| 700 | writel(readl(&mmc_base->stat) | BWR_MASK, |
| 701 | &mmc_base->stat); |
| 702 | |
| 703 | if (mmc_stat & TC_MASK) { |
| 704 | writel(readl(&mmc_base->stat) | TC_MASK, |
| 705 | &mmc_base->stat); |
| 706 | break; |
| 707 | } |
| 708 | } |
| 709 | return 0; |
| 710 | } |
| 711 | |
Sricharan | 933efe6 | 2011-11-15 09:49:53 -0500 | [diff] [blame] | 712 | static int mmc_write_data(struct hsmmc *mmc_base, const char *buf, |
| 713 | unsigned int size) |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 714 | { |
| 715 | unsigned int *input_buf = (unsigned int *)buf; |
| 716 | unsigned int mmc_stat; |
| 717 | unsigned int count; |
| 718 | |
| 719 | /* |
Lubomir Popov | 152ba36 | 2013-08-14 18:59:18 +0300 | [diff] [blame] | 720 | * Start Polled Write |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 721 | */ |
| 722 | count = (size > MMCSD_SECTOR_SIZE) ? MMCSD_SECTOR_SIZE : size; |
| 723 | count /= 4; |
| 724 | |
| 725 | while (size) { |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 726 | ulong start = get_timer(0); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 727 | do { |
| 728 | mmc_stat = readl(&mmc_base->stat); |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 729 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 730 | printf("%s: timedout waiting for status!\n", |
| 731 | __func__); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 732 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 733 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 734 | } while (mmc_stat == 0); |
| 735 | |
Grazvydas Ignotas | 25c719e | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 736 | if ((mmc_stat & (IE_DTO | IE_DCRC | IE_DEB)) != 0) |
| 737 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD); |
| 738 | |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 739 | if ((mmc_stat & ERRI_MASK) != 0) |
| 740 | return 1; |
| 741 | |
| 742 | if (mmc_stat & BWR_MASK) { |
| 743 | unsigned int k; |
| 744 | |
| 745 | writel(readl(&mmc_base->stat) | BWR_MASK, |
| 746 | &mmc_base->stat); |
| 747 | for (k = 0; k < count; k++) { |
| 748 | writel(*input_buf, &mmc_base->data); |
| 749 | input_buf++; |
| 750 | } |
| 751 | size -= (count*4); |
| 752 | } |
| 753 | |
| 754 | if (mmc_stat & BRR_MASK) |
| 755 | writel(readl(&mmc_base->stat) | BRR_MASK, |
| 756 | &mmc_base->stat); |
| 757 | |
| 758 | if (mmc_stat & TC_MASK) { |
| 759 | writel(readl(&mmc_base->stat) | TC_MASK, |
| 760 | &mmc_base->stat); |
| 761 | break; |
| 762 | } |
| 763 | } |
| 764 | return 0; |
| 765 | } |
| 766 | |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 767 | #if !CONFIG_IS_ENABLED(DM_MMC) |
Jaehoon Chung | 07b0b9c | 2016-12-30 15:30:16 +0900 | [diff] [blame] | 768 | static int omap_hsmmc_set_ios(struct mmc *mmc) |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 769 | { |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 770 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 771 | #else |
| 772 | static int omap_hsmmc_set_ios(struct udevice *dev) |
| 773 | { |
| 774 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
| 775 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 776 | struct mmc *mmc = upriv->mmc; |
| 777 | #endif |
Nikita Kiryanov | cc22b0c | 2012-12-03 02:19:43 +0000 | [diff] [blame] | 778 | struct hsmmc *mmc_base; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 779 | unsigned int dsor = 0; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 780 | ulong start; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 781 | |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 782 | mmc_base = priv->base_addr; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 783 | /* configue bus width */ |
| 784 | switch (mmc->bus_width) { |
| 785 | case 8: |
| 786 | writel(readl(&mmc_base->con) | DTW_8_BITMODE, |
| 787 | &mmc_base->con); |
| 788 | break; |
| 789 | |
| 790 | case 4: |
| 791 | writel(readl(&mmc_base->con) & ~DTW_8_BITMODE, |
| 792 | &mmc_base->con); |
| 793 | writel(readl(&mmc_base->hctl) | DTW_4_BITMODE, |
| 794 | &mmc_base->hctl); |
| 795 | break; |
| 796 | |
| 797 | case 1: |
| 798 | default: |
| 799 | writel(readl(&mmc_base->con) & ~DTW_8_BITMODE, |
| 800 | &mmc_base->con); |
| 801 | writel(readl(&mmc_base->hctl) & ~DTW_4_BITMODE, |
| 802 | &mmc_base->hctl); |
| 803 | break; |
| 804 | } |
| 805 | |
| 806 | /* configure clock with 96Mhz system clock. |
| 807 | */ |
| 808 | if (mmc->clock != 0) { |
| 809 | dsor = (MMC_CLOCK_REFERENCE * 1000000 / mmc->clock); |
| 810 | if ((MMC_CLOCK_REFERENCE * 1000000) / dsor > mmc->clock) |
| 811 | dsor++; |
| 812 | } |
| 813 | |
| 814 | mmc_reg_out(&mmc_base->sysctl, (ICE_MASK | DTO_MASK | CEN_MASK), |
Kishon Vijay Abraham I | 29171dc | 2017-09-21 16:51:36 +0200 | [diff] [blame] | 815 | (ICE_STOP | DTO_15THDTO)); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 816 | |
| 817 | mmc_reg_out(&mmc_base->sysctl, ICE_MASK | CLKD_MASK, |
| 818 | (dsor << CLKD_OFFSET) | ICE_OSCILLATE); |
| 819 | |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 820 | start = get_timer(0); |
| 821 | while ((readl(&mmc_base->sysctl) & ICS_MASK) == ICS_NOTREADY) { |
| 822 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 823 | printf("%s: timedout waiting for ics!\n", __func__); |
Jaehoon Chung | 07b0b9c | 2016-12-30 15:30:16 +0900 | [diff] [blame] | 824 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 825 | } |
| 826 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 827 | writel(readl(&mmc_base->sysctl) | CEN_ENABLE, &mmc_base->sysctl); |
Jaehoon Chung | 07b0b9c | 2016-12-30 15:30:16 +0900 | [diff] [blame] | 828 | |
| 829 | return 0; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 832 | #ifdef OMAP_HSMMC_USE_GPIO |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 833 | #if CONFIG_IS_ENABLED(DM_MMC) |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 834 | static int omap_hsmmc_getcd(struct udevice *dev) |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 835 | { |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 836 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 837 | int value; |
| 838 | |
| 839 | value = dm_gpio_get_value(&priv->cd_gpio); |
| 840 | /* if no CD return as 1 */ |
| 841 | if (value < 0) |
| 842 | return 1; |
| 843 | |
| 844 | if (priv->cd_inverted) |
| 845 | return !value; |
| 846 | return value; |
| 847 | } |
| 848 | |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 849 | static int omap_hsmmc_getwp(struct udevice *dev) |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 850 | { |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 851 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 852 | int value; |
| 853 | |
| 854 | value = dm_gpio_get_value(&priv->wp_gpio); |
| 855 | /* if no WP return as 0 */ |
| 856 | if (value < 0) |
| 857 | return 0; |
| 858 | return value; |
| 859 | } |
| 860 | #else |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 861 | static int omap_hsmmc_getcd(struct mmc *mmc) |
| 862 | { |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 863 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 864 | int cd_gpio; |
| 865 | |
| 866 | /* if no CD return as 1 */ |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 867 | cd_gpio = priv->cd_gpio; |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 868 | if (cd_gpio < 0) |
| 869 | return 1; |
| 870 | |
Igor Grinberg | 0b03a93 | 2014-11-03 11:32:23 +0200 | [diff] [blame] | 871 | /* NOTE: assumes card detect signal is active-low */ |
| 872 | return !gpio_get_value(cd_gpio); |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | static int omap_hsmmc_getwp(struct mmc *mmc) |
| 876 | { |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 877 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 878 | int wp_gpio; |
| 879 | |
| 880 | /* if no WP return as 0 */ |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 881 | wp_gpio = priv->wp_gpio; |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 882 | if (wp_gpio < 0) |
| 883 | return 0; |
| 884 | |
Igor Grinberg | 0b03a93 | 2014-11-03 11:32:23 +0200 | [diff] [blame] | 885 | /* NOTE: assumes write protect signal is active-high */ |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 886 | return gpio_get_value(wp_gpio); |
| 887 | } |
| 888 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 889 | #endif |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 890 | |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 891 | #if CONFIG_IS_ENABLED(DM_MMC) |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 892 | static const struct dm_mmc_ops omap_hsmmc_ops = { |
| 893 | .send_cmd = omap_hsmmc_send_cmd, |
| 894 | .set_ios = omap_hsmmc_set_ios, |
| 895 | #ifdef OMAP_HSMMC_USE_GPIO |
| 896 | .get_cd = omap_hsmmc_getcd, |
| 897 | .get_wp = omap_hsmmc_getwp, |
| 898 | #endif |
| 899 | }; |
| 900 | #else |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 901 | static const struct mmc_ops omap_hsmmc_ops = { |
| 902 | .send_cmd = omap_hsmmc_send_cmd, |
| 903 | .set_ios = omap_hsmmc_set_ios, |
| 904 | .init = omap_hsmmc_init_setup, |
| 905 | #ifdef OMAP_HSMMC_USE_GPIO |
| 906 | .getcd = omap_hsmmc_getcd, |
| 907 | .getwp = omap_hsmmc_getwp, |
| 908 | #endif |
| 909 | }; |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 910 | #endif |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 911 | |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 912 | #if !CONFIG_IS_ENABLED(DM_MMC) |
Nikita Kiryanov | e3913f5 | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 913 | int omap_mmc_init(int dev_index, uint host_caps_mask, uint f_max, int cd_gpio, |
| 914 | int wp_gpio) |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 915 | { |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 916 | struct mmc *mmc; |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 917 | struct omap_hsmmc_data *priv; |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 918 | struct mmc_config *cfg; |
| 919 | uint host_caps_val; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 920 | |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 921 | priv = malloc(sizeof(*priv)); |
| 922 | if (priv == NULL) |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 923 | return -1; |
| 924 | |
Rob Herring | 5a20397 | 2015-03-23 17:56:59 -0500 | [diff] [blame] | 925 | host_caps_val = MMC_MODE_4BIT | MMC_MODE_HS_52MHz | MMC_MODE_HS; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 926 | |
| 927 | switch (dev_index) { |
| 928 | case 0: |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 929 | priv->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 930 | break; |
Tom Rini | 1037d58 | 2011-10-12 06:20:50 +0000 | [diff] [blame] | 931 | #ifdef OMAP_HSMMC2_BASE |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 932 | case 1: |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 933 | priv->base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE; |
Lubomir Popov | 152ba36 | 2013-08-14 18:59:18 +0300 | [diff] [blame] | 934 | #if (defined(CONFIG_OMAP44XX) || defined(CONFIG_OMAP54XX) || \ |
Nishanth Menon | 3891a54 | 2016-11-29 15:22:00 +0530 | [diff] [blame] | 935 | defined(CONFIG_DRA7XX) || defined(CONFIG_AM33XX) || \ |
Roger Quadros | 3b68939 | 2015-09-19 16:26:53 +0530 | [diff] [blame] | 936 | defined(CONFIG_AM43XX) || defined(CONFIG_SOC_KEYSTONE)) && \ |
| 937 | defined(CONFIG_HSMMC2_8BIT) |
Lubomir Popov | 152ba36 | 2013-08-14 18:59:18 +0300 | [diff] [blame] | 938 | /* Enable 8-bit interface for eMMC on OMAP4/5 or DRA7XX */ |
| 939 | host_caps_val |= MMC_MODE_8BIT; |
| 940 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 941 | break; |
Tom Rini | 1037d58 | 2011-10-12 06:20:50 +0000 | [diff] [blame] | 942 | #endif |
| 943 | #ifdef OMAP_HSMMC3_BASE |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 944 | case 2: |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 945 | priv->base_addr = (struct hsmmc *)OMAP_HSMMC3_BASE; |
Nishanth Menon | 3891a54 | 2016-11-29 15:22:00 +0530 | [diff] [blame] | 946 | #if defined(CONFIG_DRA7XX) && defined(CONFIG_HSMMC3_8BIT) |
Lubomir Popov | 152ba36 | 2013-08-14 18:59:18 +0300 | [diff] [blame] | 947 | /* Enable 8-bit interface for eMMC on DRA7XX */ |
| 948 | host_caps_val |= MMC_MODE_8BIT; |
| 949 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 950 | break; |
Tom Rini | 1037d58 | 2011-10-12 06:20:50 +0000 | [diff] [blame] | 951 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 952 | default: |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 953 | priv->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 954 | return 1; |
| 955 | } |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 956 | #ifdef OMAP_HSMMC_USE_GPIO |
| 957 | /* on error gpio values are set to -1, which is what we want */ |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 958 | priv->cd_gpio = omap_mmc_setup_gpio_in(cd_gpio, "mmc_cd"); |
| 959 | priv->wp_gpio = omap_mmc_setup_gpio_in(wp_gpio, "mmc_wp"); |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 960 | #endif |
Peter Korsgaard | 173ddc5 | 2013-03-21 04:00:04 +0000 | [diff] [blame] | 961 | |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 962 | cfg = &priv->cfg; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 963 | |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 964 | cfg->name = "OMAP SD/MMC"; |
| 965 | cfg->ops = &omap_hsmmc_ops; |
| 966 | |
| 967 | cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195; |
| 968 | cfg->host_caps = host_caps_val & ~host_caps_mask; |
| 969 | |
| 970 | cfg->f_min = 400000; |
Jonathan Solnit | bbbc1ae | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 971 | |
| 972 | if (f_max != 0) |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 973 | cfg->f_max = f_max; |
Jonathan Solnit | bbbc1ae | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 974 | else { |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 975 | if (cfg->host_caps & MMC_MODE_HS) { |
| 976 | if (cfg->host_caps & MMC_MODE_HS_52MHz) |
| 977 | cfg->f_max = 52000000; |
Jonathan Solnit | bbbc1ae | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 978 | else |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 979 | cfg->f_max = 26000000; |
Jonathan Solnit | bbbc1ae | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 980 | } else |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 981 | cfg->f_max = 20000000; |
Jonathan Solnit | bbbc1ae | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 982 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 983 | |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 984 | cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; |
John Rigby | 8feafcc | 2011-04-18 05:50:08 +0000 | [diff] [blame] | 985 | |
John Rigby | 4ca9244 | 2011-04-19 05:48:14 +0000 | [diff] [blame] | 986 | #if defined(CONFIG_OMAP34XX) |
| 987 | /* |
| 988 | * Silicon revs 2.1 and older do not support multiblock transfers. |
| 989 | */ |
| 990 | if ((get_cpu_family() == CPU_OMAP34XX) && (get_cpu_rev() <= CPU_3XX_ES21)) |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 991 | cfg->b_max = 1; |
John Rigby | 4ca9244 | 2011-04-19 05:48:14 +0000 | [diff] [blame] | 992 | #endif |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 993 | mmc = mmc_create(cfg, priv); |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 994 | if (mmc == NULL) |
| 995 | return -1; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 996 | |
| 997 | return 0; |
| 998 | } |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 999 | #else |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1000 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1001 | static int omap_hsmmc_ofdata_to_platdata(struct udevice *dev) |
| 1002 | { |
Jean-Jacques Hiblot | 3d673ff | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 1003 | struct omap_hsmmc_plat *plat = dev_get_platdata(dev); |
| 1004 | struct mmc_config *cfg = &plat->cfg; |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1005 | const void *fdt = gd->fdt_blob; |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 1006 | int node = dev_of_offset(dev); |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1007 | int val; |
| 1008 | |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 1009 | plat->base_addr = map_physmem(devfdt_get_addr(dev), |
| 1010 | sizeof(struct hsmmc *), |
Jean-Jacques Hiblot | 741726a | 2017-09-21 16:51:32 +0200 | [diff] [blame] | 1011 | MAP_NOCACHE); |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1012 | |
| 1013 | cfg->host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS; |
| 1014 | val = fdtdec_get_int(fdt, node, "bus-width", -1); |
| 1015 | if (val < 0) { |
| 1016 | printf("error: bus-width property missing\n"); |
| 1017 | return -ENOENT; |
| 1018 | } |
| 1019 | |
| 1020 | switch (val) { |
| 1021 | case 0x8: |
| 1022 | cfg->host_caps |= MMC_MODE_8BIT; |
| 1023 | case 0x4: |
| 1024 | cfg->host_caps |= MMC_MODE_4BIT; |
| 1025 | break; |
| 1026 | default: |
| 1027 | printf("error: invalid bus-width property\n"); |
| 1028 | return -ENOENT; |
| 1029 | } |
| 1030 | |
| 1031 | cfg->f_min = 400000; |
| 1032 | cfg->f_max = fdtdec_get_int(fdt, node, "max-frequency", 52000000); |
| 1033 | cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195; |
| 1034 | cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; |
| 1035 | |
Sekhar Nori | 4de2de5 | 2016-08-10 19:24:03 +0530 | [diff] [blame] | 1036 | #ifdef OMAP_HSMMC_USE_GPIO |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1037 | plat->cd_inverted = fdtdec_get_bool(fdt, node, "cd-inverted"); |
Sekhar Nori | 4de2de5 | 2016-08-10 19:24:03 +0530 | [diff] [blame] | 1038 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1039 | |
| 1040 | return 0; |
| 1041 | } |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1042 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1043 | |
Jean-Jacques Hiblot | 17c9a1c | 2017-03-22 16:00:34 +0100 | [diff] [blame] | 1044 | #ifdef CONFIG_BLK |
| 1045 | |
| 1046 | static int omap_hsmmc_bind(struct udevice *dev) |
| 1047 | { |
| 1048 | struct omap_hsmmc_plat *plat = dev_get_platdata(dev); |
| 1049 | |
| 1050 | return mmc_bind(dev, &plat->mmc, &plat->cfg); |
| 1051 | } |
| 1052 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1053 | static int omap_hsmmc_probe(struct udevice *dev) |
| 1054 | { |
Jean-Jacques Hiblot | 3d673ff | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 1055 | struct omap_hsmmc_plat *plat = dev_get_platdata(dev); |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1056 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 1057 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
Jean-Jacques Hiblot | 3d673ff | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 1058 | struct mmc_config *cfg = &plat->cfg; |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1059 | struct mmc *mmc; |
| 1060 | |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1061 | cfg->name = "OMAP SD/MMC"; |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1062 | priv->base_addr = plat->base_addr; |
| 1063 | #ifdef OMAP_HSMMC_USE_GPIO |
| 1064 | priv->cd_inverted = plat->cd_inverted; |
| 1065 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1066 | |
Jean-Jacques Hiblot | 17c9a1c | 2017-03-22 16:00:34 +0100 | [diff] [blame] | 1067 | #ifdef CONFIG_BLK |
| 1068 | mmc = &plat->mmc; |
| 1069 | #else |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1070 | mmc = mmc_create(cfg, priv); |
| 1071 | if (mmc == NULL) |
| 1072 | return -1; |
Jean-Jacques Hiblot | 17c9a1c | 2017-03-22 16:00:34 +0100 | [diff] [blame] | 1073 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1074 | |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1075 | #if defined(OMAP_HSMMC_USE_GPIO) && CONFIG_IS_ENABLED(OF_CONTROL) |
Mugunthan V N | 5cc6a24 | 2016-04-04 17:28:01 +0530 | [diff] [blame] | 1076 | gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio, GPIOD_IS_IN); |
| 1077 | gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio, GPIOD_IS_IN); |
| 1078 | #endif |
| 1079 | |
Simon Glass | cffe5d8 | 2016-05-01 13:52:34 -0600 | [diff] [blame] | 1080 | mmc->dev = dev; |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1081 | upriv->mmc = mmc; |
| 1082 | |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1083 | return omap_hsmmc_init_setup(mmc); |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1084 | } |
| 1085 | |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1086 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1087 | static const struct udevice_id omap_hsmmc_ids[] = { |
Jean-Jacques Hiblot | 741726a | 2017-09-21 16:51:32 +0200 | [diff] [blame] | 1088 | { .compatible = "ti,omap3-hsmmc" }, |
| 1089 | { .compatible = "ti,omap4-hsmmc" }, |
| 1090 | { .compatible = "ti,am33xx-hsmmc" }, |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1091 | { } |
| 1092 | }; |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1093 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1094 | |
| 1095 | U_BOOT_DRIVER(omap_hsmmc) = { |
| 1096 | .name = "omap_hsmmc", |
| 1097 | .id = UCLASS_MMC, |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1098 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1099 | .of_match = omap_hsmmc_ids, |
| 1100 | .ofdata_to_platdata = omap_hsmmc_ofdata_to_platdata, |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1101 | .platdata_auto_alloc_size = sizeof(struct omap_hsmmc_plat), |
| 1102 | #endif |
Jean-Jacques Hiblot | 17c9a1c | 2017-03-22 16:00:34 +0100 | [diff] [blame] | 1103 | #ifdef CONFIG_BLK |
| 1104 | .bind = omap_hsmmc_bind, |
| 1105 | #endif |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1106 | .ops = &omap_hsmmc_ops, |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1107 | .probe = omap_hsmmc_probe, |
| 1108 | .priv_auto_alloc_size = sizeof(struct omap_hsmmc_data), |
Lokesh Vutla | cbcb170 | 2017-04-26 13:37:06 +0530 | [diff] [blame] | 1109 | .flags = DM_FLAG_PRE_RELOC, |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1110 | }; |
| 1111 | #endif |