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 |
Kishon Vijay Abraham I | 48a2f11 | 2018-01-30 16:01:31 +0100 | [diff] [blame] | 65 | uint bus_width; |
Jean-Jacques Hiblot | 5baf543 | 2018-01-30 16:01:30 +0100 | [diff] [blame] | 66 | uint clock; |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 67 | #ifdef OMAP_HSMMC_USE_GPIO |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 68 | #if CONFIG_IS_ENABLED(DM_MMC) |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 69 | struct gpio_desc cd_gpio; /* Change Detect GPIO */ |
| 70 | struct gpio_desc wp_gpio; /* Write Protect GPIO */ |
| 71 | bool cd_inverted; |
| 72 | #else |
Nikita Kiryanov | e874d5b | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 73 | int cd_gpio; |
Nikita Kiryanov | e3913f5 | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 74 | int wp_gpio; |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 75 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 76 | #endif |
Kishon Vijay Abraham I | b594481 | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 77 | #if CONFIG_IS_ENABLED(DM_MMC) |
| 78 | uint iov; |
Jean-Jacques Hiblot | 8fc238b | 2018-01-30 16:01:33 +0100 | [diff] [blame] | 79 | enum bus_mode mode; |
Kishon Vijay Abraham I | b594481 | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 80 | #endif |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 81 | u8 controller_flags; |
| 82 | #ifndef CONFIG_OMAP34XX |
| 83 | struct omap_hsmmc_adma_desc *adma_desc_table; |
| 84 | uint desc_slot; |
| 85 | #endif |
Nikita Kiryanov | cc22b0c | 2012-12-03 02:19:43 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 88 | #ifndef CONFIG_OMAP34XX |
| 89 | struct omap_hsmmc_adma_desc { |
| 90 | u8 attr; |
| 91 | u8 reserved; |
| 92 | u16 len; |
| 93 | u32 addr; |
| 94 | }; |
| 95 | |
| 96 | #define ADMA_MAX_LEN 63488 |
| 97 | |
| 98 | /* Decriptor table defines */ |
| 99 | #define ADMA_DESC_ATTR_VALID BIT(0) |
| 100 | #define ADMA_DESC_ATTR_END BIT(1) |
| 101 | #define ADMA_DESC_ATTR_INT BIT(2) |
| 102 | #define ADMA_DESC_ATTR_ACT1 BIT(4) |
| 103 | #define ADMA_DESC_ATTR_ACT2 BIT(5) |
| 104 | |
| 105 | #define ADMA_DESC_TRANSFER_DATA ADMA_DESC_ATTR_ACT2 |
| 106 | #define ADMA_DESC_LINK_DESC (ADMA_DESC_ATTR_ACT1 | ADMA_DESC_ATTR_ACT2) |
| 107 | #endif |
| 108 | |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 109 | /* If we fail after 1 second wait, something is really bad */ |
| 110 | #define MAX_RETRY_MS 1000 |
| 111 | |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 112 | /* DMA transfers can take a long time if a lot a data is transferred. |
| 113 | * The timeout must take in account the amount of data. Let's assume |
| 114 | * that the time will never exceed 333 ms per MB (in other word we assume |
| 115 | * that the bandwidth is always above 3MB/s). |
| 116 | */ |
| 117 | #define DMA_TIMEOUT_PER_MB 333 |
Kishon Vijay Abraham I | b594481 | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 118 | #define OMAP_HSMMC_SUPPORTS_DUAL_VOLT BIT(0) |
| 119 | #define OMAP_HSMMC_NO_1_8_V BIT(1) |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 120 | #define OMAP_HSMMC_USE_ADMA BIT(2) |
| 121 | |
Sricharan | 933efe6 | 2011-11-15 09:49:53 -0500 | [diff] [blame] | 122 | static int mmc_read_data(struct hsmmc *mmc_base, char *buf, unsigned int size); |
| 123 | static int mmc_write_data(struct hsmmc *mmc_base, const char *buf, |
| 124 | unsigned int siz); |
Jean-Jacques Hiblot | 5baf543 | 2018-01-30 16:01:30 +0100 | [diff] [blame] | 125 | static void omap_hsmmc_start_clock(struct hsmmc *mmc_base); |
| 126 | static void omap_hsmmc_stop_clock(struct hsmmc *mmc_base); |
Jean-Jacques Hiblot | 14761ca | 2018-01-30 16:01:35 +0100 | [diff] [blame] | 127 | static void mmc_reset_controller_fsm(struct hsmmc *mmc_base, u32 bit); |
Balaji T K | 14fa2dd | 2011-09-08 06:34:57 +0000 | [diff] [blame] | 128 | |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 129 | static inline struct omap_hsmmc_data *omap_hsmmc_get_data(struct mmc *mmc) |
| 130 | { |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 131 | #if CONFIG_IS_ENABLED(DM_MMC) |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 132 | return dev_get_priv(mmc->dev); |
| 133 | #else |
| 134 | return (struct omap_hsmmc_data *)mmc->priv; |
| 135 | #endif |
| 136 | } |
Jean-Jacques Hiblot | 3d673ff | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 137 | static inline struct mmc_config *omap_hsmmc_get_cfg(struct mmc *mmc) |
| 138 | { |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 139 | #if CONFIG_IS_ENABLED(DM_MMC) |
Jean-Jacques Hiblot | 3d673ff | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 140 | struct omap_hsmmc_plat *plat = dev_get_platdata(mmc->dev); |
| 141 | return &plat->cfg; |
| 142 | #else |
| 143 | return &((struct omap_hsmmc_data *)mmc->priv)->cfg; |
| 144 | #endif |
| 145 | } |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 146 | |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 147 | #if defined(OMAP_HSMMC_USE_GPIO) && !CONFIG_IS_ENABLED(DM_MMC) |
Nikita Kiryanov | e874d5b | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 148 | static int omap_mmc_setup_gpio_in(int gpio, const char *label) |
| 149 | { |
Simon Glass | 5915a2a | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 150 | int ret; |
| 151 | |
| 152 | #ifndef CONFIG_DM_GPIO |
Nikita Kiryanov | e874d5b | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 153 | if (!gpio_is_valid(gpio)) |
| 154 | return -1; |
Simon Glass | 5915a2a | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 155 | #endif |
| 156 | ret = gpio_request(gpio, label); |
| 157 | if (ret) |
| 158 | return ret; |
Nikita Kiryanov | e874d5b | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 159 | |
Simon Glass | 5915a2a | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 160 | ret = gpio_direction_input(gpio); |
| 161 | if (ret) |
| 162 | return ret; |
Nikita Kiryanov | e874d5b | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 163 | |
| 164 | return gpio; |
| 165 | } |
Nikita Kiryanov | e874d5b | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 166 | #endif |
| 167 | |
Jeroen Hofstee | 750121c | 2014-07-12 21:24:08 +0200 | [diff] [blame] | 168 | static unsigned char mmc_board_init(struct mmc *mmc) |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 169 | { |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 170 | #if defined(CONFIG_OMAP34XX) |
Jean-Jacques Hiblot | 3d673ff | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 171 | struct mmc_config *cfg = omap_hsmmc_get_cfg(mmc); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 172 | t2_t *t2_base = (t2_t *)T2_BASE; |
| 173 | struct prcm *prcm_base = (struct prcm *)PRCM_BASE; |
Grazvydas Ignotas | b1e725f | 2012-03-19 03:50:53 +0000 | [diff] [blame] | 174 | u32 pbias_lite; |
Adam Ford | 6aca17c | 2017-02-06 11:31:43 -0600 | [diff] [blame] | 175 | #ifdef CONFIG_MMC_OMAP36XX_PINS |
| 176 | u32 wkup_ctrl = readl(OMAP34XX_CTRL_WKUP_CTRL); |
| 177 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 178 | |
Grazvydas Ignotas | b1e725f | 2012-03-19 03:50:53 +0000 | [diff] [blame] | 179 | pbias_lite = readl(&t2_base->pbias_lite); |
| 180 | pbias_lite &= ~(PBIASLITEPWRDNZ1 | PBIASLITEPWRDNZ0); |
Albert ARIBAUD \(3ADEV\) | 5bfdd1f | 2015-01-16 09:09:50 +0100 | [diff] [blame] | 181 | #ifdef CONFIG_TARGET_OMAP3_CAIRO |
| 182 | /* for cairo board, we need to set up 1.8 Volt bias level on MMC1 */ |
| 183 | pbias_lite &= ~PBIASLITEVMODE0; |
| 184 | #endif |
Adam Ford | 6aca17c | 2017-02-06 11:31:43 -0600 | [diff] [blame] | 185 | #ifdef CONFIG_MMC_OMAP36XX_PINS |
| 186 | if (get_cpu_family() == CPU_OMAP36XX) { |
| 187 | /* Disable extended drain IO before changing PBIAS */ |
| 188 | wkup_ctrl &= ~OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ; |
| 189 | writel(wkup_ctrl, OMAP34XX_CTRL_WKUP_CTRL); |
| 190 | } |
| 191 | #endif |
Grazvydas Ignotas | b1e725f | 2012-03-19 03:50:53 +0000 | [diff] [blame] | 192 | writel(pbias_lite, &t2_base->pbias_lite); |
Paul Kocialkowski | aac5450 | 2014-11-08 20:55:47 +0100 | [diff] [blame] | 193 | |
Grazvydas Ignotas | b1e725f | 2012-03-19 03:50:53 +0000 | [diff] [blame] | 194 | writel(pbias_lite | PBIASLITEPWRDNZ1 | |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 195 | PBIASSPEEDCTRL0 | PBIASLITEPWRDNZ0, |
| 196 | &t2_base->pbias_lite); |
| 197 | |
Adam Ford | 6aca17c | 2017-02-06 11:31:43 -0600 | [diff] [blame] | 198 | #ifdef CONFIG_MMC_OMAP36XX_PINS |
| 199 | if (get_cpu_family() == CPU_OMAP36XX) |
| 200 | /* Enable extended drain IO after changing PBIAS */ |
| 201 | writel(wkup_ctrl | |
| 202 | OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ, |
| 203 | OMAP34XX_CTRL_WKUP_CTRL); |
| 204 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 205 | writel(readl(&t2_base->devconf0) | MMCSDIO1ADPCLKISEL, |
| 206 | &t2_base->devconf0); |
| 207 | |
| 208 | writel(readl(&t2_base->devconf1) | MMCSDIO2ADPCLKISEL, |
| 209 | &t2_base->devconf1); |
| 210 | |
Jonathan Solnit | bbbc1ae | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 211 | /* Change from default of 52MHz to 26MHz if necessary */ |
Jean-Jacques Hiblot | 3d673ff | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 212 | if (!(cfg->host_caps & MMC_MODE_HS_52MHz)) |
Jonathan Solnit | bbbc1ae | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 213 | writel(readl(&t2_base->ctl_prog_io1) & ~CTLPROGIO1SPEEDCTRL, |
| 214 | &t2_base->ctl_prog_io1); |
| 215 | |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 216 | writel(readl(&prcm_base->fclken1_core) | |
| 217 | EN_MMC1 | EN_MMC2 | EN_MMC3, |
| 218 | &prcm_base->fclken1_core); |
| 219 | |
| 220 | writel(readl(&prcm_base->iclken1_core) | |
| 221 | EN_MMC1 | EN_MMC2 | EN_MMC3, |
| 222 | &prcm_base->iclken1_core); |
| 223 | #endif |
| 224 | |
Lokesh Vutla | b4b0600 | 2016-11-23 13:25:28 +0530 | [diff] [blame] | 225 | #if defined(CONFIG_OMAP54XX) || defined(CONFIG_OMAP44XX) |
Balaji T K | 14fa2dd | 2011-09-08 06:34:57 +0000 | [diff] [blame] | 226 | /* PBIAS config needed for MMC1 only */ |
Jean-Jacques Hiblot | dc09127 | 2017-03-22 16:00:32 +0100 | [diff] [blame] | 227 | if (mmc_get_blk_desc(mmc)->devnum == 0) |
Lokesh Vutla | b4b0600 | 2016-11-23 13:25:28 +0530 | [diff] [blame] | 228 | vmmc_pbias_config(LDO_VOLT_3V0); |
Balaji T K | dd23e59 | 2012-03-12 02:25:49 +0000 | [diff] [blame] | 229 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | |
Sricharan | 933efe6 | 2011-11-15 09:49:53 -0500 | [diff] [blame] | 234 | void mmc_init_stream(struct hsmmc *mmc_base) |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 235 | { |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 236 | ulong start; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 237 | |
| 238 | writel(readl(&mmc_base->con) | INIT_INITSTREAM, &mmc_base->con); |
| 239 | |
| 240 | writel(MMC_CMD0, &mmc_base->cmd); |
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 cc!\n", __func__); |
| 245 | return; |
| 246 | } |
| 247 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 248 | writel(CC_MASK, &mmc_base->stat) |
| 249 | ; |
| 250 | writel(MMC_CMD0, &mmc_base->cmd) |
| 251 | ; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 252 | start = get_timer(0); |
| 253 | while (!(readl(&mmc_base->stat) & CC_MASK)) { |
| 254 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 255 | printf("%s: timedout waiting for cc2!\n", __func__); |
| 256 | return; |
| 257 | } |
| 258 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 259 | writel(readl(&mmc_base->con) & ~INIT_INITSTREAM, &mmc_base->con); |
| 260 | } |
| 261 | |
Kishon Vijay Abraham I | b594481 | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 262 | #if CONFIG_IS_ENABLED(DM_MMC) |
Jean-Jacques Hiblot | 8fc238b | 2018-01-30 16:01:33 +0100 | [diff] [blame] | 263 | static void omap_hsmmc_set_timing(struct mmc *mmc) |
| 264 | { |
| 265 | u32 val; |
| 266 | struct hsmmc *mmc_base; |
| 267 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 268 | |
| 269 | mmc_base = priv->base_addr; |
| 270 | |
| 271 | val = readl(&mmc_base->ac12); |
| 272 | val &= ~AC12_UHSMC_MASK; |
| 273 | priv->mode = mmc->selected_mode; |
| 274 | |
Kishon Vijay Abraham I | 9b3fc21 | 2018-01-30 16:01:34 +0100 | [diff] [blame] | 275 | if (mmc_is_mode_ddr(priv->mode)) |
| 276 | writel(readl(&mmc_base->con) | DDR, &mmc_base->con); |
| 277 | else |
| 278 | writel(readl(&mmc_base->con) & ~DDR, &mmc_base->con); |
| 279 | |
Jean-Jacques Hiblot | 8fc238b | 2018-01-30 16:01:33 +0100 | [diff] [blame] | 280 | switch (priv->mode) { |
| 281 | case MMC_HS_200: |
| 282 | case UHS_SDR104: |
| 283 | val |= AC12_UHSMC_SDR104; |
| 284 | break; |
| 285 | case UHS_SDR50: |
| 286 | val |= AC12_UHSMC_SDR50; |
| 287 | break; |
| 288 | case MMC_DDR_52: |
| 289 | case UHS_DDR50: |
| 290 | val |= AC12_UHSMC_DDR50; |
| 291 | break; |
| 292 | case SD_HS: |
| 293 | case MMC_HS_52: |
| 294 | case UHS_SDR25: |
| 295 | val |= AC12_UHSMC_SDR25; |
| 296 | break; |
| 297 | case MMC_LEGACY: |
| 298 | case MMC_HS: |
| 299 | case SD_LEGACY: |
| 300 | case UHS_SDR12: |
| 301 | val |= AC12_UHSMC_SDR12; |
| 302 | break; |
| 303 | default: |
| 304 | val |= AC12_UHSMC_RES; |
| 305 | break; |
| 306 | } |
| 307 | writel(val, &mmc_base->ac12); |
| 308 | } |
| 309 | |
Kishon Vijay Abraham I | b594481 | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 310 | static void omap_hsmmc_conf_bus_power(struct mmc *mmc) |
| 311 | { |
| 312 | struct hsmmc *mmc_base; |
| 313 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 314 | u32 val; |
| 315 | |
| 316 | mmc_base = priv->base_addr; |
| 317 | |
| 318 | val = readl(&mmc_base->hctl) & ~SDVS_MASK; |
| 319 | |
| 320 | switch (priv->iov) { |
| 321 | case IOV_3V3: |
| 322 | val |= SDVS_3V3; |
| 323 | break; |
| 324 | case IOV_3V0: |
| 325 | val |= SDVS_3V0; |
| 326 | break; |
| 327 | case IOV_1V8: |
| 328 | val |= SDVS_1V8; |
| 329 | break; |
| 330 | } |
| 331 | |
| 332 | writel(val, &mmc_base->hctl); |
| 333 | } |
| 334 | |
| 335 | static void omap_hsmmc_set_capabilities(struct mmc *mmc) |
| 336 | { |
| 337 | struct hsmmc *mmc_base; |
| 338 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 339 | u32 val; |
| 340 | |
| 341 | mmc_base = priv->base_addr; |
| 342 | val = readl(&mmc_base->capa); |
| 343 | |
| 344 | if (priv->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) { |
| 345 | val |= (VS30_3V0SUP | VS18_1V8SUP); |
| 346 | priv->iov = IOV_3V0; |
| 347 | } else if (priv->controller_flags & OMAP_HSMMC_NO_1_8_V) { |
| 348 | val |= VS30_3V0SUP; |
| 349 | val &= ~VS18_1V8SUP; |
| 350 | priv->iov = IOV_3V0; |
| 351 | } else { |
| 352 | val |= VS18_1V8SUP; |
| 353 | val &= ~VS30_3V0SUP; |
| 354 | priv->iov = IOV_1V8; |
| 355 | } |
| 356 | |
| 357 | writel(val, &mmc_base->capa); |
| 358 | } |
Jean-Jacques Hiblot | 14761ca | 2018-01-30 16:01:35 +0100 | [diff] [blame] | 359 | |
| 360 | #ifdef MMC_SUPPORTS_TUNING |
| 361 | static void omap_hsmmc_disable_tuning(struct mmc *mmc) |
| 362 | { |
| 363 | struct hsmmc *mmc_base; |
| 364 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 365 | u32 val; |
| 366 | |
| 367 | mmc_base = priv->base_addr; |
| 368 | val = readl(&mmc_base->ac12); |
| 369 | val &= ~(AC12_SCLK_SEL); |
| 370 | writel(val, &mmc_base->ac12); |
| 371 | |
| 372 | val = readl(&mmc_base->dll); |
| 373 | val &= ~(DLL_FORCE_VALUE | DLL_SWT); |
| 374 | writel(val, &mmc_base->dll); |
| 375 | } |
| 376 | |
| 377 | static void omap_hsmmc_set_dll(struct mmc *mmc, int count) |
| 378 | { |
| 379 | int i; |
| 380 | struct hsmmc *mmc_base; |
| 381 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 382 | u32 val; |
| 383 | |
| 384 | mmc_base = priv->base_addr; |
| 385 | val = readl(&mmc_base->dll); |
| 386 | val |= DLL_FORCE_VALUE; |
| 387 | val &= ~(DLL_FORCE_SR_C_MASK << DLL_FORCE_SR_C_SHIFT); |
| 388 | val |= (count << DLL_FORCE_SR_C_SHIFT); |
| 389 | writel(val, &mmc_base->dll); |
| 390 | |
| 391 | val |= DLL_CALIB; |
| 392 | writel(val, &mmc_base->dll); |
| 393 | for (i = 0; i < 1000; i++) { |
| 394 | if (readl(&mmc_base->dll) & DLL_CALIB) |
| 395 | break; |
| 396 | } |
| 397 | val &= ~DLL_CALIB; |
| 398 | writel(val, &mmc_base->dll); |
| 399 | } |
| 400 | |
| 401 | static int omap_hsmmc_execute_tuning(struct udevice *dev, uint opcode) |
| 402 | { |
| 403 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
| 404 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 405 | struct mmc *mmc = upriv->mmc; |
| 406 | struct hsmmc *mmc_base; |
| 407 | u32 val; |
| 408 | u8 cur_match, prev_match = 0; |
| 409 | int ret; |
| 410 | u32 phase_delay = 0; |
| 411 | u32 start_window = 0, max_window = 0; |
| 412 | u32 length = 0, max_len = 0; |
| 413 | |
| 414 | mmc_base = priv->base_addr; |
| 415 | val = readl(&mmc_base->capa2); |
| 416 | |
| 417 | /* clock tuning is not needed for upto 52MHz */ |
| 418 | if (!((mmc->selected_mode == MMC_HS_200) || |
| 419 | (mmc->selected_mode == UHS_SDR104) || |
| 420 | ((mmc->selected_mode == UHS_SDR50) && (val & CAPA2_TSDR50)))) |
| 421 | return 0; |
| 422 | |
| 423 | val = readl(&mmc_base->dll); |
| 424 | val |= DLL_SWT; |
| 425 | writel(val, &mmc_base->dll); |
| 426 | while (phase_delay <= MAX_PHASE_DELAY) { |
| 427 | omap_hsmmc_set_dll(mmc, phase_delay); |
| 428 | |
| 429 | cur_match = !mmc_send_tuning(mmc, opcode, NULL); |
| 430 | |
| 431 | if (cur_match) { |
| 432 | if (prev_match) { |
| 433 | length++; |
| 434 | } else { |
| 435 | start_window = phase_delay; |
| 436 | length = 1; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | if (length > max_len) { |
| 441 | max_window = start_window; |
| 442 | max_len = length; |
| 443 | } |
| 444 | |
| 445 | prev_match = cur_match; |
| 446 | phase_delay += 4; |
| 447 | } |
| 448 | |
| 449 | if (!max_len) { |
| 450 | ret = -EIO; |
| 451 | goto tuning_error; |
| 452 | } |
| 453 | |
| 454 | val = readl(&mmc_base->ac12); |
| 455 | if (!(val & AC12_SCLK_SEL)) { |
| 456 | ret = -EIO; |
| 457 | goto tuning_error; |
| 458 | } |
| 459 | |
| 460 | phase_delay = max_window + 4 * ((3 * max_len) >> 2); |
| 461 | omap_hsmmc_set_dll(mmc, phase_delay); |
| 462 | |
| 463 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD); |
| 464 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRC); |
| 465 | |
| 466 | return 0; |
| 467 | |
| 468 | tuning_error: |
| 469 | |
| 470 | omap_hsmmc_disable_tuning(mmc); |
| 471 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD); |
| 472 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRC); |
| 473 | |
| 474 | return ret; |
| 475 | } |
| 476 | #endif |
Kishon Vijay Abraham I | b594481 | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 477 | #endif |
| 478 | |
Jean-Jacques Hiblot | 2faa1a3 | 2018-01-30 16:01:36 +0100 | [diff] [blame^] | 479 | static void mmc_enable_irq(struct mmc *mmc, struct mmc_cmd *cmd) |
| 480 | { |
| 481 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 482 | struct hsmmc *mmc_base = priv->base_addr; |
| 483 | u32 irq_mask = INT_EN_MASK; |
| 484 | |
| 485 | /* |
| 486 | * TODO: Errata i802 indicates only DCRC interrupts can occur during |
| 487 | * tuning procedure and DCRC should be disabled. But see occurences |
| 488 | * of DEB, CIE, CEB, CCRC interupts during tuning procedure. These |
| 489 | * interrupts occur along with BRR, so the data is actually in the |
| 490 | * buffer. It has to be debugged why these interrutps occur |
| 491 | */ |
| 492 | if (cmd && mmc_is_tuning_cmd(cmd->cmdidx)) |
| 493 | irq_mask &= ~(IE_DEB | IE_DCRC | IE_CIE | IE_CEB | IE_CCRC); |
| 494 | |
| 495 | writel(irq_mask, &mmc_base->ie); |
| 496 | } |
| 497 | |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 498 | static int omap_hsmmc_init_setup(struct mmc *mmc) |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 499 | { |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 500 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Nikita Kiryanov | cc22b0c | 2012-12-03 02:19:43 +0000 | [diff] [blame] | 501 | struct hsmmc *mmc_base; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 502 | unsigned int reg_val; |
| 503 | unsigned int dsor; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 504 | ulong start; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 505 | |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 506 | mmc_base = priv->base_addr; |
Balaji T K | 14fa2dd | 2011-09-08 06:34:57 +0000 | [diff] [blame] | 507 | mmc_board_init(mmc); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 508 | |
| 509 | writel(readl(&mmc_base->sysconfig) | MMC_SOFTRESET, |
| 510 | &mmc_base->sysconfig); |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 511 | start = get_timer(0); |
| 512 | while ((readl(&mmc_base->sysstatus) & RESETDONE) == 0) { |
| 513 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 514 | printf("%s: timedout waiting for cc2!\n", __func__); |
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 | writel(readl(&mmc_base->sysctl) | SOFTRESETALL, &mmc_base->sysctl); |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 519 | start = get_timer(0); |
| 520 | while ((readl(&mmc_base->sysctl) & SOFTRESETALL) != 0x0) { |
| 521 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 522 | printf("%s: timedout waiting for softresetall!\n", |
| 523 | __func__); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 524 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 525 | } |
| 526 | } |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 527 | #ifndef CONFIG_OMAP34XX |
| 528 | reg_val = readl(&mmc_base->hl_hwinfo); |
| 529 | if (reg_val & MADMA_EN) |
| 530 | priv->controller_flags |= OMAP_HSMMC_USE_ADMA; |
| 531 | #endif |
Kishon Vijay Abraham I | b594481 | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 532 | |
| 533 | #if CONFIG_IS_ENABLED(DM_MMC) |
| 534 | omap_hsmmc_set_capabilities(mmc); |
| 535 | omap_hsmmc_conf_bus_power(mmc); |
| 536 | #else |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 537 | writel(DTW_1_BITMODE | SDBP_PWROFF | SDVS_3V0, &mmc_base->hctl); |
| 538 | writel(readl(&mmc_base->capa) | VS30_3V0SUP | VS18_1V8SUP, |
| 539 | &mmc_base->capa); |
Kishon Vijay Abraham I | b594481 | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 540 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 541 | |
| 542 | reg_val = readl(&mmc_base->con) & RESERVED_MASK; |
| 543 | |
| 544 | writel(CTPL_MMC_SD | reg_val | WPP_ACTIVEHIGH | CDP_ACTIVEHIGH | |
| 545 | MIT_CTO | DW8_1_4BITMODE | MODE_FUNC | STR_BLOCK | |
| 546 | HR_NOHOSTRESP | INIT_NOINIT | NOOPENDRAIN, &mmc_base->con); |
| 547 | |
| 548 | dsor = 240; |
| 549 | 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] | 550 | (ICE_STOP | DTO_15THDTO)); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 551 | mmc_reg_out(&mmc_base->sysctl, ICE_MASK | CLKD_MASK, |
| 552 | (dsor << CLKD_OFFSET) | ICE_OSCILLATE); |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 553 | start = get_timer(0); |
| 554 | while ((readl(&mmc_base->sysctl) & ICS_MASK) == ICS_NOTREADY) { |
| 555 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 556 | printf("%s: timedout waiting for ics!\n", __func__); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 557 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 558 | } |
| 559 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 560 | writel(readl(&mmc_base->sysctl) | CEN_ENABLE, &mmc_base->sysctl); |
| 561 | |
| 562 | writel(readl(&mmc_base->hctl) | SDBP_PWRON, &mmc_base->hctl); |
| 563 | |
Jean-Jacques Hiblot | 2faa1a3 | 2018-01-30 16:01:36 +0100 | [diff] [blame^] | 564 | mmc_enable_irq(mmc, NULL); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 565 | mmc_init_stream(mmc_base); |
| 566 | |
| 567 | return 0; |
| 568 | } |
| 569 | |
Grazvydas Ignotas | 25c719e | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 570 | /* |
| 571 | * MMC controller internal finite state machine reset |
| 572 | * |
| 573 | * Used to reset command or data internal state machines, using respectively |
| 574 | * SRC or SRD bit of SYSCTL register |
| 575 | */ |
| 576 | static void mmc_reset_controller_fsm(struct hsmmc *mmc_base, u32 bit) |
| 577 | { |
| 578 | ulong start; |
| 579 | |
| 580 | mmc_reg_out(&mmc_base->sysctl, bit, bit); |
| 581 | |
Oleksandr Tyshchenko | 61a6cc2 | 2013-08-06 13:44:16 +0300 | [diff] [blame] | 582 | /* |
| 583 | * CMD(DAT) lines reset procedures are slightly different |
| 584 | * for OMAP3 and OMAP4(AM335x,OMAP5,DRA7xx). |
| 585 | * According to OMAP3 TRM: |
| 586 | * Set SRC(SRD) bit in MMCHS_SYSCTL register to 0x1 and wait until it |
| 587 | * returns to 0x0. |
| 588 | * According to OMAP4(AM335x,OMAP5,DRA7xx) TRMs, CMD(DATA) lines reset |
| 589 | * procedure steps must be as follows: |
| 590 | * 1. Initiate CMD(DAT) line reset by writing 0x1 to SRC(SRD) bit in |
| 591 | * MMCHS_SYSCTL register (SD_SYSCTL for AM335x). |
| 592 | * 2. Poll the SRC(SRD) bit until it is set to 0x1. |
| 593 | * 3. Wait until the SRC (SRD) bit returns to 0x0 |
| 594 | * (reset procedure is completed). |
| 595 | */ |
| 596 | #if defined(CONFIG_OMAP44XX) || defined(CONFIG_OMAP54XX) || \ |
Nikita Kiryanov | dce55b9 | 2015-07-30 23:56:20 +0300 | [diff] [blame] | 597 | defined(CONFIG_AM33XX) || defined(CONFIG_AM43XX) |
Oleksandr Tyshchenko | 61a6cc2 | 2013-08-06 13:44:16 +0300 | [diff] [blame] | 598 | if (!(readl(&mmc_base->sysctl) & bit)) { |
| 599 | start = get_timer(0); |
| 600 | while (!(readl(&mmc_base->sysctl) & bit)) { |
| 601 | if (get_timer(0) - start > MAX_RETRY_MS) |
| 602 | return; |
| 603 | } |
| 604 | } |
| 605 | #endif |
Grazvydas Ignotas | 25c719e | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 606 | start = get_timer(0); |
| 607 | while ((readl(&mmc_base->sysctl) & bit) != 0) { |
| 608 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 609 | printf("%s: timedout waiting for sysctl %x to clear\n", |
| 610 | __func__, bit); |
| 611 | return; |
| 612 | } |
| 613 | } |
| 614 | } |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 615 | |
| 616 | #ifndef CONFIG_OMAP34XX |
| 617 | static void omap_hsmmc_adma_desc(struct mmc *mmc, char *buf, u16 len, bool end) |
| 618 | { |
| 619 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 620 | struct omap_hsmmc_adma_desc *desc; |
| 621 | u8 attr; |
| 622 | |
| 623 | desc = &priv->adma_desc_table[priv->desc_slot]; |
| 624 | |
| 625 | attr = ADMA_DESC_ATTR_VALID | ADMA_DESC_TRANSFER_DATA; |
| 626 | if (!end) |
| 627 | priv->desc_slot++; |
| 628 | else |
| 629 | attr |= ADMA_DESC_ATTR_END; |
| 630 | |
| 631 | desc->len = len; |
| 632 | desc->addr = (u32)buf; |
| 633 | desc->reserved = 0; |
| 634 | desc->attr = attr; |
| 635 | } |
| 636 | |
| 637 | static void omap_hsmmc_prepare_adma_table(struct mmc *mmc, |
| 638 | struct mmc_data *data) |
| 639 | { |
| 640 | uint total_len = data->blocksize * data->blocks; |
| 641 | uint desc_count = DIV_ROUND_UP(total_len, ADMA_MAX_LEN); |
| 642 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 643 | int i = desc_count; |
| 644 | char *buf; |
| 645 | |
| 646 | priv->desc_slot = 0; |
| 647 | priv->adma_desc_table = (struct omap_hsmmc_adma_desc *) |
| 648 | memalign(ARCH_DMA_MINALIGN, desc_count * |
| 649 | sizeof(struct omap_hsmmc_adma_desc)); |
| 650 | |
| 651 | if (data->flags & MMC_DATA_READ) |
| 652 | buf = data->dest; |
| 653 | else |
| 654 | buf = (char *)data->src; |
| 655 | |
| 656 | while (--i) { |
| 657 | omap_hsmmc_adma_desc(mmc, buf, ADMA_MAX_LEN, false); |
| 658 | buf += ADMA_MAX_LEN; |
| 659 | total_len -= ADMA_MAX_LEN; |
| 660 | } |
| 661 | |
| 662 | omap_hsmmc_adma_desc(mmc, buf, total_len, true); |
| 663 | |
| 664 | flush_dcache_range((long)priv->adma_desc_table, |
| 665 | (long)priv->adma_desc_table + |
| 666 | ROUND(desc_count * |
| 667 | sizeof(struct omap_hsmmc_adma_desc), |
| 668 | ARCH_DMA_MINALIGN)); |
| 669 | } |
| 670 | |
| 671 | static void omap_hsmmc_prepare_data(struct mmc *mmc, struct mmc_data *data) |
| 672 | { |
| 673 | struct hsmmc *mmc_base; |
| 674 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 675 | u32 val; |
| 676 | char *buf; |
| 677 | |
| 678 | mmc_base = priv->base_addr; |
| 679 | omap_hsmmc_prepare_adma_table(mmc, data); |
| 680 | |
| 681 | if (data->flags & MMC_DATA_READ) |
| 682 | buf = data->dest; |
| 683 | else |
| 684 | buf = (char *)data->src; |
| 685 | |
| 686 | val = readl(&mmc_base->hctl); |
| 687 | val |= DMA_SELECT; |
| 688 | writel(val, &mmc_base->hctl); |
| 689 | |
| 690 | val = readl(&mmc_base->con); |
| 691 | val |= DMA_MASTER; |
| 692 | writel(val, &mmc_base->con); |
| 693 | |
| 694 | writel((u32)priv->adma_desc_table, &mmc_base->admasal); |
| 695 | |
| 696 | flush_dcache_range((u32)buf, |
| 697 | (u32)buf + |
| 698 | ROUND(data->blocksize * data->blocks, |
| 699 | ARCH_DMA_MINALIGN)); |
| 700 | } |
| 701 | |
| 702 | static void omap_hsmmc_dma_cleanup(struct mmc *mmc) |
| 703 | { |
| 704 | struct hsmmc *mmc_base; |
| 705 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 706 | u32 val; |
| 707 | |
| 708 | mmc_base = priv->base_addr; |
| 709 | |
| 710 | val = readl(&mmc_base->con); |
| 711 | val &= ~DMA_MASTER; |
| 712 | writel(val, &mmc_base->con); |
| 713 | |
| 714 | val = readl(&mmc_base->hctl); |
| 715 | val &= ~DMA_SELECT; |
| 716 | writel(val, &mmc_base->hctl); |
| 717 | |
| 718 | kfree(priv->adma_desc_table); |
| 719 | } |
| 720 | #else |
| 721 | #define omap_hsmmc_adma_desc |
| 722 | #define omap_hsmmc_prepare_adma_table |
| 723 | #define omap_hsmmc_prepare_data |
| 724 | #define omap_hsmmc_dma_cleanup |
| 725 | #endif |
| 726 | |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 727 | #if !CONFIG_IS_ENABLED(DM_MMC) |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 728 | 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] | 729 | struct mmc_data *data) |
| 730 | { |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 731 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 732 | #else |
| 733 | static int omap_hsmmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd, |
| 734 | struct mmc_data *data) |
| 735 | { |
| 736 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 737 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 738 | struct mmc *mmc = upriv->mmc; |
| 739 | #endif |
Nikita Kiryanov | cc22b0c | 2012-12-03 02:19:43 +0000 | [diff] [blame] | 740 | struct hsmmc *mmc_base; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 741 | unsigned int flags, mmc_stat; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 742 | ulong start; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 743 | |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 744 | mmc_base = priv->base_addr; |
Kishon Vijay Abraham I | 866bb98 | 2017-09-21 16:51:35 +0200 | [diff] [blame] | 745 | |
| 746 | if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION) |
| 747 | return 0; |
| 748 | |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 749 | start = get_timer(0); |
Tom Rini | a7778f8 | 2012-01-30 11:22:25 +0000 | [diff] [blame] | 750 | while ((readl(&mmc_base->pstate) & (DATI_MASK | CMDI_MASK)) != 0) { |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 751 | if (get_timer(0) - start > MAX_RETRY_MS) { |
Tom Rini | a7778f8 | 2012-01-30 11:22:25 +0000 | [diff] [blame] | 752 | printf("%s: timedout waiting on cmd inhibit to clear\n", |
| 753 | __func__); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 754 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 755 | } |
| 756 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 757 | writel(0xFFFFFFFF, &mmc_base->stat); |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 758 | start = get_timer(0); |
| 759 | while (readl(&mmc_base->stat)) { |
| 760 | if (get_timer(0) - start > MAX_RETRY_MS) { |
Grazvydas Ignotas | 15ceb1d | 2012-03-19 12:11:43 +0000 | [diff] [blame] | 761 | printf("%s: timedout waiting for STAT (%x) to clear\n", |
| 762 | __func__, readl(&mmc_base->stat)); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 763 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 764 | } |
| 765 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 766 | /* |
| 767 | * CMDREG |
| 768 | * CMDIDX[13:8] : Command index |
| 769 | * DATAPRNT[5] : Data Present Select |
| 770 | * ENCMDIDX[4] : Command Index Check Enable |
| 771 | * ENCMDCRC[3] : Command CRC Check Enable |
| 772 | * RSPTYP[1:0] |
| 773 | * 00 = No Response |
| 774 | * 01 = Length 136 |
| 775 | * 10 = Length 48 |
| 776 | * 11 = Length 48 Check busy after response |
| 777 | */ |
| 778 | /* Delay added before checking the status of frq change |
| 779 | * retry not supported by mmc.c(core file) |
| 780 | */ |
| 781 | if (cmd->cmdidx == SD_CMD_APP_SEND_SCR) |
| 782 | udelay(50000); /* wait 50 ms */ |
| 783 | |
| 784 | if (!(cmd->resp_type & MMC_RSP_PRESENT)) |
| 785 | flags = 0; |
| 786 | else if (cmd->resp_type & MMC_RSP_136) |
| 787 | flags = RSP_TYPE_LGHT136 | CICE_NOCHECK; |
| 788 | else if (cmd->resp_type & MMC_RSP_BUSY) |
| 789 | flags = RSP_TYPE_LGHT48B; |
| 790 | else |
| 791 | flags = RSP_TYPE_LGHT48; |
| 792 | |
| 793 | /* enable default flags */ |
| 794 | flags = flags | (CMD_TYPE_NORMAL | CICE_NOCHECK | CCCE_NOCHECK | |
Kishon Vijay Abraham I | 29171dc | 2017-09-21 16:51:36 +0200 | [diff] [blame] | 795 | MSBS_SGLEBLK); |
| 796 | flags &= ~(ACEN_ENABLE | BCE_ENABLE | DE_ENABLE); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 797 | |
| 798 | if (cmd->resp_type & MMC_RSP_CRC) |
| 799 | flags |= CCCE_CHECK; |
| 800 | if (cmd->resp_type & MMC_RSP_OPCODE) |
| 801 | flags |= CICE_CHECK; |
| 802 | |
| 803 | if (data) { |
| 804 | if ((cmd->cmdidx == MMC_CMD_READ_MULTIPLE_BLOCK) || |
| 805 | (cmd->cmdidx == MMC_CMD_WRITE_MULTIPLE_BLOCK)) { |
Kishon Vijay Abraham I | 866bb98 | 2017-09-21 16:51:35 +0200 | [diff] [blame] | 806 | flags |= (MSBS_MULTIBLK | BCE_ENABLE | ACEN_ENABLE); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 807 | data->blocksize = 512; |
| 808 | writel(data->blocksize | (data->blocks << 16), |
| 809 | &mmc_base->blk); |
| 810 | } else |
| 811 | writel(data->blocksize | NBLK_STPCNT, &mmc_base->blk); |
| 812 | |
| 813 | if (data->flags & MMC_DATA_READ) |
| 814 | flags |= (DP_DATA | DDIR_READ); |
| 815 | else |
| 816 | flags |= (DP_DATA | DDIR_WRITE); |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 817 | |
| 818 | #ifndef CONFIG_OMAP34XX |
| 819 | if ((priv->controller_flags & OMAP_HSMMC_USE_ADMA) && |
| 820 | !mmc_is_tuning_cmd(cmd->cmdidx)) { |
| 821 | omap_hsmmc_prepare_data(mmc, data); |
| 822 | flags |= DE_ENABLE; |
| 823 | } |
| 824 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Jean-Jacques Hiblot | 2faa1a3 | 2018-01-30 16:01:36 +0100 | [diff] [blame^] | 827 | mmc_enable_irq(mmc, cmd); |
| 828 | |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 829 | writel(cmd->cmdarg, &mmc_base->arg); |
Lubomir Popov | 152ba36 | 2013-08-14 18:59:18 +0300 | [diff] [blame] | 830 | udelay(20); /* To fix "No status update" error on eMMC */ |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 831 | writel((cmd->cmdidx << 24) | flags, &mmc_base->cmd); |
| 832 | |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 833 | start = get_timer(0); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 834 | do { |
| 835 | mmc_stat = readl(&mmc_base->stat); |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 836 | if (get_timer(start) > MAX_RETRY_MS) { |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 837 | printf("%s : timeout: No status update\n", __func__); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 838 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 839 | } |
| 840 | } while (!mmc_stat); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 841 | |
Grazvydas Ignotas | 25c719e | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 842 | if ((mmc_stat & IE_CTO) != 0) { |
| 843 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRC); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 844 | return -ETIMEDOUT; |
Grazvydas Ignotas | 25c719e | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 845 | } else if ((mmc_stat & ERRI_MASK) != 0) |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 846 | return -1; |
| 847 | |
| 848 | if (mmc_stat & CC_MASK) { |
| 849 | writel(CC_MASK, &mmc_base->stat); |
| 850 | if (cmd->resp_type & MMC_RSP_PRESENT) { |
| 851 | if (cmd->resp_type & MMC_RSP_136) { |
| 852 | /* response type 2 */ |
| 853 | cmd->response[3] = readl(&mmc_base->rsp10); |
| 854 | cmd->response[2] = readl(&mmc_base->rsp32); |
| 855 | cmd->response[1] = readl(&mmc_base->rsp54); |
| 856 | cmd->response[0] = readl(&mmc_base->rsp76); |
| 857 | } else |
| 858 | /* response types 1, 1b, 3, 4, 5, 6 */ |
| 859 | cmd->response[0] = readl(&mmc_base->rsp10); |
| 860 | } |
| 861 | } |
| 862 | |
Kishon Vijay Abraham I | f0d53e8 | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 863 | #ifndef CONFIG_OMAP34XX |
| 864 | if ((priv->controller_flags & OMAP_HSMMC_USE_ADMA) && data && |
| 865 | !mmc_is_tuning_cmd(cmd->cmdidx)) { |
| 866 | u32 sz_mb, timeout; |
| 867 | |
| 868 | if (mmc_stat & IE_ADMAE) { |
| 869 | omap_hsmmc_dma_cleanup(mmc); |
| 870 | return -EIO; |
| 871 | } |
| 872 | |
| 873 | sz_mb = DIV_ROUND_UP(data->blocksize * data->blocks, 1 << 20); |
| 874 | timeout = sz_mb * DMA_TIMEOUT_PER_MB; |
| 875 | if (timeout < MAX_RETRY_MS) |
| 876 | timeout = MAX_RETRY_MS; |
| 877 | |
| 878 | start = get_timer(0); |
| 879 | do { |
| 880 | mmc_stat = readl(&mmc_base->stat); |
| 881 | if (mmc_stat & TC_MASK) { |
| 882 | writel(readl(&mmc_base->stat) | TC_MASK, |
| 883 | &mmc_base->stat); |
| 884 | break; |
| 885 | } |
| 886 | if (get_timer(start) > timeout) { |
| 887 | printf("%s : DMA timeout: No status update\n", |
| 888 | __func__); |
| 889 | return -ETIMEDOUT; |
| 890 | } |
| 891 | } while (1); |
| 892 | |
| 893 | omap_hsmmc_dma_cleanup(mmc); |
| 894 | return 0; |
| 895 | } |
| 896 | #endif |
| 897 | |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 898 | if (data && (data->flags & MMC_DATA_READ)) { |
| 899 | mmc_read_data(mmc_base, data->dest, |
| 900 | data->blocksize * data->blocks); |
| 901 | } else if (data && (data->flags & MMC_DATA_WRITE)) { |
| 902 | mmc_write_data(mmc_base, data->src, |
| 903 | data->blocksize * data->blocks); |
| 904 | } |
| 905 | return 0; |
| 906 | } |
| 907 | |
Sricharan | 933efe6 | 2011-11-15 09:49:53 -0500 | [diff] [blame] | 908 | 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] | 909 | { |
| 910 | unsigned int *output_buf = (unsigned int *)buf; |
| 911 | unsigned int mmc_stat; |
| 912 | unsigned int count; |
| 913 | |
| 914 | /* |
| 915 | * Start Polled Read |
| 916 | */ |
| 917 | count = (size > MMCSD_SECTOR_SIZE) ? MMCSD_SECTOR_SIZE : size; |
| 918 | count /= 4; |
| 919 | |
| 920 | while (size) { |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 921 | ulong start = get_timer(0); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 922 | do { |
| 923 | mmc_stat = readl(&mmc_base->stat); |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 924 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 925 | printf("%s: timedout waiting for status!\n", |
| 926 | __func__); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 927 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 928 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 929 | } while (mmc_stat == 0); |
| 930 | |
Grazvydas Ignotas | 25c719e | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 931 | if ((mmc_stat & (IE_DTO | IE_DCRC | IE_DEB)) != 0) |
| 932 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD); |
| 933 | |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 934 | if ((mmc_stat & ERRI_MASK) != 0) |
| 935 | return 1; |
| 936 | |
| 937 | if (mmc_stat & BRR_MASK) { |
| 938 | unsigned int k; |
| 939 | |
| 940 | writel(readl(&mmc_base->stat) | BRR_MASK, |
| 941 | &mmc_base->stat); |
| 942 | for (k = 0; k < count; k++) { |
| 943 | *output_buf = readl(&mmc_base->data); |
| 944 | output_buf++; |
| 945 | } |
| 946 | size -= (count*4); |
| 947 | } |
| 948 | |
| 949 | if (mmc_stat & BWR_MASK) |
| 950 | writel(readl(&mmc_base->stat) | BWR_MASK, |
| 951 | &mmc_base->stat); |
| 952 | |
| 953 | if (mmc_stat & TC_MASK) { |
| 954 | writel(readl(&mmc_base->stat) | TC_MASK, |
| 955 | &mmc_base->stat); |
| 956 | break; |
| 957 | } |
| 958 | } |
| 959 | return 0; |
| 960 | } |
| 961 | |
Sricharan | 933efe6 | 2011-11-15 09:49:53 -0500 | [diff] [blame] | 962 | static int mmc_write_data(struct hsmmc *mmc_base, const char *buf, |
| 963 | unsigned int size) |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 964 | { |
| 965 | unsigned int *input_buf = (unsigned int *)buf; |
| 966 | unsigned int mmc_stat; |
| 967 | unsigned int count; |
| 968 | |
| 969 | /* |
Lubomir Popov | 152ba36 | 2013-08-14 18:59:18 +0300 | [diff] [blame] | 970 | * Start Polled Write |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 971 | */ |
| 972 | count = (size > MMCSD_SECTOR_SIZE) ? MMCSD_SECTOR_SIZE : size; |
| 973 | count /= 4; |
| 974 | |
| 975 | while (size) { |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 976 | ulong start = get_timer(0); |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 977 | do { |
| 978 | mmc_stat = readl(&mmc_base->stat); |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 979 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 980 | printf("%s: timedout waiting for status!\n", |
| 981 | __func__); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 982 | return -ETIMEDOUT; |
Nishanth Menon | eb9a28f | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 983 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 984 | } while (mmc_stat == 0); |
| 985 | |
Grazvydas Ignotas | 25c719e | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 986 | if ((mmc_stat & (IE_DTO | IE_DCRC | IE_DEB)) != 0) |
| 987 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD); |
| 988 | |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 989 | if ((mmc_stat & ERRI_MASK) != 0) |
| 990 | return 1; |
| 991 | |
| 992 | if (mmc_stat & BWR_MASK) { |
| 993 | unsigned int k; |
| 994 | |
| 995 | writel(readl(&mmc_base->stat) | BWR_MASK, |
| 996 | &mmc_base->stat); |
| 997 | for (k = 0; k < count; k++) { |
| 998 | writel(*input_buf, &mmc_base->data); |
| 999 | input_buf++; |
| 1000 | } |
| 1001 | size -= (count*4); |
| 1002 | } |
| 1003 | |
| 1004 | if (mmc_stat & BRR_MASK) |
| 1005 | writel(readl(&mmc_base->stat) | BRR_MASK, |
| 1006 | &mmc_base->stat); |
| 1007 | |
| 1008 | if (mmc_stat & TC_MASK) { |
| 1009 | writel(readl(&mmc_base->stat) | TC_MASK, |
| 1010 | &mmc_base->stat); |
| 1011 | break; |
| 1012 | } |
| 1013 | } |
| 1014 | return 0; |
| 1015 | } |
| 1016 | |
Jean-Jacques Hiblot | 5baf543 | 2018-01-30 16:01:30 +0100 | [diff] [blame] | 1017 | static void omap_hsmmc_stop_clock(struct hsmmc *mmc_base) |
| 1018 | { |
| 1019 | writel(readl(&mmc_base->sysctl) & ~CEN_ENABLE, &mmc_base->sysctl); |
| 1020 | } |
| 1021 | |
| 1022 | static void omap_hsmmc_start_clock(struct hsmmc *mmc_base) |
| 1023 | { |
| 1024 | writel(readl(&mmc_base->sysctl) | CEN_ENABLE, &mmc_base->sysctl); |
| 1025 | } |
| 1026 | |
| 1027 | static void omap_hsmmc_set_clock(struct mmc *mmc) |
| 1028 | { |
| 1029 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 1030 | struct hsmmc *mmc_base; |
| 1031 | unsigned int dsor = 0; |
| 1032 | ulong start; |
| 1033 | |
| 1034 | mmc_base = priv->base_addr; |
| 1035 | omap_hsmmc_stop_clock(mmc_base); |
| 1036 | |
| 1037 | /* TODO: Is setting DTO required here? */ |
| 1038 | mmc_reg_out(&mmc_base->sysctl, (ICE_MASK | DTO_MASK), |
| 1039 | (ICE_STOP | DTO_15THDTO)); |
| 1040 | |
| 1041 | if (mmc->clock != 0) { |
| 1042 | dsor = DIV_ROUND_UP(MMC_CLOCK_REFERENCE * 1000000, mmc->clock); |
| 1043 | if (dsor > CLKD_MAX) |
| 1044 | dsor = CLKD_MAX; |
| 1045 | } else { |
| 1046 | dsor = CLKD_MAX; |
| 1047 | } |
| 1048 | |
| 1049 | mmc_reg_out(&mmc_base->sysctl, ICE_MASK | CLKD_MASK, |
| 1050 | (dsor << CLKD_OFFSET) | ICE_OSCILLATE); |
| 1051 | |
| 1052 | start = get_timer(0); |
| 1053 | while ((readl(&mmc_base->sysctl) & ICS_MASK) == ICS_NOTREADY) { |
| 1054 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 1055 | printf("%s: timedout waiting for ics!\n", __func__); |
| 1056 | return; |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | priv->clock = mmc->clock; |
| 1061 | omap_hsmmc_start_clock(mmc_base); |
| 1062 | } |
| 1063 | |
Kishon Vijay Abraham I | 48a2f11 | 2018-01-30 16:01:31 +0100 | [diff] [blame] | 1064 | static void omap_hsmmc_set_bus_width(struct mmc *mmc) |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1065 | { |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1066 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Nikita Kiryanov | cc22b0c | 2012-12-03 02:19:43 +0000 | [diff] [blame] | 1067 | struct hsmmc *mmc_base; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1068 | |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1069 | mmc_base = priv->base_addr; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1070 | /* configue bus width */ |
| 1071 | switch (mmc->bus_width) { |
| 1072 | case 8: |
| 1073 | writel(readl(&mmc_base->con) | DTW_8_BITMODE, |
| 1074 | &mmc_base->con); |
| 1075 | break; |
| 1076 | |
| 1077 | case 4: |
| 1078 | writel(readl(&mmc_base->con) & ~DTW_8_BITMODE, |
| 1079 | &mmc_base->con); |
| 1080 | writel(readl(&mmc_base->hctl) | DTW_4_BITMODE, |
| 1081 | &mmc_base->hctl); |
| 1082 | break; |
| 1083 | |
| 1084 | case 1: |
| 1085 | default: |
| 1086 | writel(readl(&mmc_base->con) & ~DTW_8_BITMODE, |
| 1087 | &mmc_base->con); |
| 1088 | writel(readl(&mmc_base->hctl) & ~DTW_4_BITMODE, |
| 1089 | &mmc_base->hctl); |
| 1090 | break; |
| 1091 | } |
| 1092 | |
Kishon Vijay Abraham I | 48a2f11 | 2018-01-30 16:01:31 +0100 | [diff] [blame] | 1093 | priv->bus_width = mmc->bus_width; |
| 1094 | } |
| 1095 | |
| 1096 | #if !CONFIG_IS_ENABLED(DM_MMC) |
| 1097 | static int omap_hsmmc_set_ios(struct mmc *mmc) |
| 1098 | { |
| 1099 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 1100 | #else |
| 1101 | static int omap_hsmmc_set_ios(struct udevice *dev) |
| 1102 | { |
| 1103 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
| 1104 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 1105 | struct mmc *mmc = upriv->mmc; |
| 1106 | #endif |
| 1107 | |
| 1108 | if (priv->bus_width != mmc->bus_width) |
| 1109 | omap_hsmmc_set_bus_width(mmc); |
| 1110 | |
Jean-Jacques Hiblot | 5baf543 | 2018-01-30 16:01:30 +0100 | [diff] [blame] | 1111 | if (priv->clock != mmc->clock) |
| 1112 | omap_hsmmc_set_clock(mmc); |
Jaehoon Chung | 07b0b9c | 2016-12-30 15:30:16 +0900 | [diff] [blame] | 1113 | |
Jean-Jacques Hiblot | 8fc238b | 2018-01-30 16:01:33 +0100 | [diff] [blame] | 1114 | #if CONFIG_IS_ENABLED(DM_MMC) |
| 1115 | if (priv->mode != mmc->selected_mode) |
| 1116 | omap_hsmmc_set_timing(mmc); |
| 1117 | #endif |
Jaehoon Chung | 07b0b9c | 2016-12-30 15:30:16 +0900 | [diff] [blame] | 1118 | return 0; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1121 | #ifdef OMAP_HSMMC_USE_GPIO |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 1122 | #if CONFIG_IS_ENABLED(DM_MMC) |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1123 | static int omap_hsmmc_getcd(struct udevice *dev) |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1124 | { |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1125 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1126 | int value; |
| 1127 | |
| 1128 | value = dm_gpio_get_value(&priv->cd_gpio); |
| 1129 | /* if no CD return as 1 */ |
| 1130 | if (value < 0) |
| 1131 | return 1; |
| 1132 | |
| 1133 | if (priv->cd_inverted) |
| 1134 | return !value; |
| 1135 | return value; |
| 1136 | } |
| 1137 | |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1138 | static int omap_hsmmc_getwp(struct udevice *dev) |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1139 | { |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1140 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1141 | int value; |
| 1142 | |
| 1143 | value = dm_gpio_get_value(&priv->wp_gpio); |
| 1144 | /* if no WP return as 0 */ |
| 1145 | if (value < 0) |
| 1146 | return 0; |
| 1147 | return value; |
| 1148 | } |
| 1149 | #else |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1150 | static int omap_hsmmc_getcd(struct mmc *mmc) |
| 1151 | { |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1152 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1153 | int cd_gpio; |
| 1154 | |
| 1155 | /* if no CD return as 1 */ |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1156 | cd_gpio = priv->cd_gpio; |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1157 | if (cd_gpio < 0) |
| 1158 | return 1; |
| 1159 | |
Igor Grinberg | 0b03a93 | 2014-11-03 11:32:23 +0200 | [diff] [blame] | 1160 | /* NOTE: assumes card detect signal is active-low */ |
| 1161 | return !gpio_get_value(cd_gpio); |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | static int omap_hsmmc_getwp(struct mmc *mmc) |
| 1165 | { |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1166 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1167 | int wp_gpio; |
| 1168 | |
| 1169 | /* if no WP return as 0 */ |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1170 | wp_gpio = priv->wp_gpio; |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1171 | if (wp_gpio < 0) |
| 1172 | return 0; |
| 1173 | |
Igor Grinberg | 0b03a93 | 2014-11-03 11:32:23 +0200 | [diff] [blame] | 1174 | /* NOTE: assumes write protect signal is active-high */ |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1175 | return gpio_get_value(wp_gpio); |
| 1176 | } |
| 1177 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1178 | #endif |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1179 | |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 1180 | #if CONFIG_IS_ENABLED(DM_MMC) |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1181 | static const struct dm_mmc_ops omap_hsmmc_ops = { |
| 1182 | .send_cmd = omap_hsmmc_send_cmd, |
| 1183 | .set_ios = omap_hsmmc_set_ios, |
| 1184 | #ifdef OMAP_HSMMC_USE_GPIO |
| 1185 | .get_cd = omap_hsmmc_getcd, |
| 1186 | .get_wp = omap_hsmmc_getwp, |
| 1187 | #endif |
Jean-Jacques Hiblot | 14761ca | 2018-01-30 16:01:35 +0100 | [diff] [blame] | 1188 | #ifdef MMC_SUPPORTS_TUNING |
| 1189 | .execute_tuning = omap_hsmmc_execute_tuning, |
| 1190 | #endif |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1191 | }; |
| 1192 | #else |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1193 | static const struct mmc_ops omap_hsmmc_ops = { |
| 1194 | .send_cmd = omap_hsmmc_send_cmd, |
| 1195 | .set_ios = omap_hsmmc_set_ios, |
| 1196 | .init = omap_hsmmc_init_setup, |
| 1197 | #ifdef OMAP_HSMMC_USE_GPIO |
| 1198 | .getcd = omap_hsmmc_getcd, |
| 1199 | .getwp = omap_hsmmc_getwp, |
| 1200 | #endif |
| 1201 | }; |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1202 | #endif |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1203 | |
Simon Glass | c4d660d | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 1204 | #if !CONFIG_IS_ENABLED(DM_MMC) |
Nikita Kiryanov | e3913f5 | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 1205 | int omap_mmc_init(int dev_index, uint host_caps_mask, uint f_max, int cd_gpio, |
| 1206 | int wp_gpio) |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1207 | { |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1208 | struct mmc *mmc; |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1209 | struct omap_hsmmc_data *priv; |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1210 | struct mmc_config *cfg; |
| 1211 | uint host_caps_val; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1212 | |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1213 | priv = malloc(sizeof(*priv)); |
| 1214 | if (priv == NULL) |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1215 | return -1; |
| 1216 | |
Rob Herring | 5a20397 | 2015-03-23 17:56:59 -0500 | [diff] [blame] | 1217 | 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] | 1218 | |
| 1219 | switch (dev_index) { |
| 1220 | case 0: |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1221 | priv->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1222 | break; |
Tom Rini | 1037d58 | 2011-10-12 06:20:50 +0000 | [diff] [blame] | 1223 | #ifdef OMAP_HSMMC2_BASE |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1224 | case 1: |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1225 | priv->base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE; |
Lubomir Popov | 152ba36 | 2013-08-14 18:59:18 +0300 | [diff] [blame] | 1226 | #if (defined(CONFIG_OMAP44XX) || defined(CONFIG_OMAP54XX) || \ |
Nishanth Menon | 3891a54 | 2016-11-29 15:22:00 +0530 | [diff] [blame] | 1227 | defined(CONFIG_DRA7XX) || defined(CONFIG_AM33XX) || \ |
Roger Quadros | 3b68939 | 2015-09-19 16:26:53 +0530 | [diff] [blame] | 1228 | defined(CONFIG_AM43XX) || defined(CONFIG_SOC_KEYSTONE)) && \ |
| 1229 | defined(CONFIG_HSMMC2_8BIT) |
Lubomir Popov | 152ba36 | 2013-08-14 18:59:18 +0300 | [diff] [blame] | 1230 | /* Enable 8-bit interface for eMMC on OMAP4/5 or DRA7XX */ |
| 1231 | host_caps_val |= MMC_MODE_8BIT; |
| 1232 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1233 | break; |
Tom Rini | 1037d58 | 2011-10-12 06:20:50 +0000 | [diff] [blame] | 1234 | #endif |
| 1235 | #ifdef OMAP_HSMMC3_BASE |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1236 | case 2: |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1237 | priv->base_addr = (struct hsmmc *)OMAP_HSMMC3_BASE; |
Nishanth Menon | 3891a54 | 2016-11-29 15:22:00 +0530 | [diff] [blame] | 1238 | #if defined(CONFIG_DRA7XX) && defined(CONFIG_HSMMC3_8BIT) |
Lubomir Popov | 152ba36 | 2013-08-14 18:59:18 +0300 | [diff] [blame] | 1239 | /* Enable 8-bit interface for eMMC on DRA7XX */ |
| 1240 | host_caps_val |= MMC_MODE_8BIT; |
| 1241 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1242 | break; |
Tom Rini | 1037d58 | 2011-10-12 06:20:50 +0000 | [diff] [blame] | 1243 | #endif |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1244 | default: |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1245 | priv->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1246 | return 1; |
| 1247 | } |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1248 | #ifdef OMAP_HSMMC_USE_GPIO |
| 1249 | /* 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] | 1250 | priv->cd_gpio = omap_mmc_setup_gpio_in(cd_gpio, "mmc_cd"); |
| 1251 | priv->wp_gpio = omap_mmc_setup_gpio_in(wp_gpio, "mmc_wp"); |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1252 | #endif |
Peter Korsgaard | 173ddc5 | 2013-03-21 04:00:04 +0000 | [diff] [blame] | 1253 | |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1254 | cfg = &priv->cfg; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1255 | |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1256 | cfg->name = "OMAP SD/MMC"; |
| 1257 | cfg->ops = &omap_hsmmc_ops; |
| 1258 | |
| 1259 | cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195; |
| 1260 | cfg->host_caps = host_caps_val & ~host_caps_mask; |
| 1261 | |
| 1262 | cfg->f_min = 400000; |
Jonathan Solnit | bbbc1ae | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 1263 | |
| 1264 | if (f_max != 0) |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1265 | cfg->f_max = f_max; |
Jonathan Solnit | bbbc1ae | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 1266 | else { |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1267 | if (cfg->host_caps & MMC_MODE_HS) { |
| 1268 | if (cfg->host_caps & MMC_MODE_HS_52MHz) |
| 1269 | cfg->f_max = 52000000; |
Jonathan Solnit | bbbc1ae | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 1270 | else |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1271 | cfg->f_max = 26000000; |
Jonathan Solnit | bbbc1ae | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 1272 | } else |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1273 | cfg->f_max = 20000000; |
Jonathan Solnit | bbbc1ae | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 1274 | } |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1275 | |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1276 | cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; |
John Rigby | 8feafcc | 2011-04-18 05:50:08 +0000 | [diff] [blame] | 1277 | |
John Rigby | 4ca9244 | 2011-04-19 05:48:14 +0000 | [diff] [blame] | 1278 | #if defined(CONFIG_OMAP34XX) |
| 1279 | /* |
| 1280 | * Silicon revs 2.1 and older do not support multiblock transfers. |
| 1281 | */ |
| 1282 | if ((get_cpu_family() == CPU_OMAP34XX) && (get_cpu_rev() <= CPU_3XX_ES21)) |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1283 | cfg->b_max = 1; |
John Rigby | 4ca9244 | 2011-04-19 05:48:14 +0000 | [diff] [blame] | 1284 | #endif |
Jean-Jacques Hiblot | ae000e2 | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1285 | mmc = mmc_create(cfg, priv); |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1286 | if (mmc == NULL) |
| 1287 | return -1; |
Sukumar Ghorai | de94124 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1288 | |
| 1289 | return 0; |
| 1290 | } |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1291 | #else |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1292 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1293 | static int omap_hsmmc_ofdata_to_platdata(struct udevice *dev) |
| 1294 | { |
Jean-Jacques Hiblot | 3d673ff | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 1295 | struct omap_hsmmc_plat *plat = dev_get_platdata(dev); |
| 1296 | struct mmc_config *cfg = &plat->cfg; |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1297 | const void *fdt = gd->fdt_blob; |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 1298 | int node = dev_of_offset(dev); |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1299 | int val; |
| 1300 | |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 1301 | plat->base_addr = map_physmem(devfdt_get_addr(dev), |
| 1302 | sizeof(struct hsmmc *), |
Jean-Jacques Hiblot | 741726a | 2017-09-21 16:51:32 +0200 | [diff] [blame] | 1303 | MAP_NOCACHE); |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1304 | |
| 1305 | cfg->host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS; |
| 1306 | val = fdtdec_get_int(fdt, node, "bus-width", -1); |
| 1307 | if (val < 0) { |
| 1308 | printf("error: bus-width property missing\n"); |
| 1309 | return -ENOENT; |
| 1310 | } |
| 1311 | |
| 1312 | switch (val) { |
| 1313 | case 0x8: |
| 1314 | cfg->host_caps |= MMC_MODE_8BIT; |
| 1315 | case 0x4: |
| 1316 | cfg->host_caps |= MMC_MODE_4BIT; |
| 1317 | break; |
| 1318 | default: |
| 1319 | printf("error: invalid bus-width property\n"); |
| 1320 | return -ENOENT; |
| 1321 | } |
| 1322 | |
| 1323 | cfg->f_min = 400000; |
| 1324 | cfg->f_max = fdtdec_get_int(fdt, node, "max-frequency", 52000000); |
| 1325 | cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195; |
| 1326 | cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; |
Kishon Vijay Abraham I | b594481 | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 1327 | if (fdtdec_get_bool(fdt, node, "ti,dual-volt")) |
| 1328 | plat->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT; |
| 1329 | if (fdtdec_get_bool(fdt, node, "no-1-8-v")) |
| 1330 | plat->controller_flags |= OMAP_HSMMC_NO_1_8_V; |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1331 | |
Sekhar Nori | 4de2de5 | 2016-08-10 19:24:03 +0530 | [diff] [blame] | 1332 | #ifdef OMAP_HSMMC_USE_GPIO |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1333 | plat->cd_inverted = fdtdec_get_bool(fdt, node, "cd-inverted"); |
Sekhar Nori | 4de2de5 | 2016-08-10 19:24:03 +0530 | [diff] [blame] | 1334 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1335 | |
| 1336 | return 0; |
| 1337 | } |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1338 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1339 | |
Jean-Jacques Hiblot | 17c9a1c | 2017-03-22 16:00:34 +0100 | [diff] [blame] | 1340 | #ifdef CONFIG_BLK |
| 1341 | |
| 1342 | static int omap_hsmmc_bind(struct udevice *dev) |
| 1343 | { |
| 1344 | struct omap_hsmmc_plat *plat = dev_get_platdata(dev); |
| 1345 | |
| 1346 | return mmc_bind(dev, &plat->mmc, &plat->cfg); |
| 1347 | } |
| 1348 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1349 | static int omap_hsmmc_probe(struct udevice *dev) |
| 1350 | { |
Jean-Jacques Hiblot | 3d673ff | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 1351 | struct omap_hsmmc_plat *plat = dev_get_platdata(dev); |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1352 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 1353 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
Jean-Jacques Hiblot | 3d673ff | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 1354 | struct mmc_config *cfg = &plat->cfg; |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1355 | struct mmc *mmc; |
| 1356 | |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1357 | cfg->name = "OMAP SD/MMC"; |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1358 | priv->base_addr = plat->base_addr; |
| 1359 | #ifdef OMAP_HSMMC_USE_GPIO |
| 1360 | priv->cd_inverted = plat->cd_inverted; |
| 1361 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1362 | |
Jean-Jacques Hiblot | 17c9a1c | 2017-03-22 16:00:34 +0100 | [diff] [blame] | 1363 | #ifdef CONFIG_BLK |
| 1364 | mmc = &plat->mmc; |
| 1365 | #else |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1366 | mmc = mmc_create(cfg, priv); |
| 1367 | if (mmc == NULL) |
| 1368 | return -1; |
Jean-Jacques Hiblot | 17c9a1c | 2017-03-22 16:00:34 +0100 | [diff] [blame] | 1369 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1370 | |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1371 | #if defined(OMAP_HSMMC_USE_GPIO) && CONFIG_IS_ENABLED(OF_CONTROL) |
Mugunthan V N | 5cc6a24 | 2016-04-04 17:28:01 +0530 | [diff] [blame] | 1372 | gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio, GPIOD_IS_IN); |
| 1373 | gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio, GPIOD_IS_IN); |
| 1374 | #endif |
| 1375 | |
Simon Glass | cffe5d8 | 2016-05-01 13:52:34 -0600 | [diff] [blame] | 1376 | mmc->dev = dev; |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1377 | upriv->mmc = mmc; |
| 1378 | |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1379 | return omap_hsmmc_init_setup(mmc); |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1380 | } |
| 1381 | |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1382 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1383 | static const struct udevice_id omap_hsmmc_ids[] = { |
Jean-Jacques Hiblot | 741726a | 2017-09-21 16:51:32 +0200 | [diff] [blame] | 1384 | { .compatible = "ti,omap3-hsmmc" }, |
| 1385 | { .compatible = "ti,omap4-hsmmc" }, |
| 1386 | { .compatible = "ti,am33xx-hsmmc" }, |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1387 | { } |
| 1388 | }; |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1389 | #endif |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1390 | |
| 1391 | U_BOOT_DRIVER(omap_hsmmc) = { |
| 1392 | .name = "omap_hsmmc", |
| 1393 | .id = UCLASS_MMC, |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1394 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1395 | .of_match = omap_hsmmc_ids, |
| 1396 | .ofdata_to_platdata = omap_hsmmc_ofdata_to_platdata, |
Lokesh Vutla | 2558c04 | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1397 | .platdata_auto_alloc_size = sizeof(struct omap_hsmmc_plat), |
| 1398 | #endif |
Jean-Jacques Hiblot | 17c9a1c | 2017-03-22 16:00:34 +0100 | [diff] [blame] | 1399 | #ifdef CONFIG_BLK |
| 1400 | .bind = omap_hsmmc_bind, |
| 1401 | #endif |
Jean-Jacques Hiblot | b5511d6 | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1402 | .ops = &omap_hsmmc_ops, |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1403 | .probe = omap_hsmmc_probe, |
| 1404 | .priv_auto_alloc_size = sizeof(struct omap_hsmmc_data), |
Lokesh Vutla | cbcb170 | 2017-04-26 13:37:06 +0530 | [diff] [blame] | 1405 | .flags = DM_FLAG_PRE_RELOC, |
Mugunthan V N | a9d6a7e | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1406 | }; |
| 1407 | #endif |