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