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> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 27 | #include <cpu_func.h> |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 28 | #include <malloc.h> |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 29 | #include <memalign.h> |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 30 | #include <mmc.h> |
| 31 | #include <part.h> |
| 32 | #include <i2c.h> |
Felix Brack | 419eed2 | 2017-10-11 17:05:28 +0200 | [diff] [blame] | 33 | #if defined(CONFIG_OMAP54XX) || defined(CONFIG_OMAP44XX) |
Nishanth Menon | 627612c | 2013-03-26 05:20:54 +0000 | [diff] [blame] | 34 | #include <palmas.h> |
Felix Brack | 419eed2 | 2017-10-11 17:05:28 +0200 | [diff] [blame] | 35 | #endif |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 36 | #include <asm/io.h> |
| 37 | #include <asm/arch/mmc_host_def.h> |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 38 | #ifdef CONFIG_OMAP54XX |
| 39 | #include <asm/arch/mux_dra7xx.h> |
| 40 | #include <asm/arch/dra7xx_iodelay.h> |
| 41 | #endif |
Roger Quadros | 44157de | 2015-09-19 16:26:53 +0530 | [diff] [blame] | 42 | #if !defined(CONFIG_SOC_KEYSTONE) |
| 43 | #include <asm/gpio.h> |
Dirk Behme | 7414023 | 2011-05-15 09:04:47 +0000 | [diff] [blame] | 44 | #include <asm/arch/sys_proto.h> |
Roger Quadros | 44157de | 2015-09-19 16:26:53 +0530 | [diff] [blame] | 45 | #endif |
Tom Rini | df5338c | 2017-02-09 13:41:28 -0500 | [diff] [blame] | 46 | #ifdef CONFIG_MMC_OMAP36XX_PINS |
| 47 | #include <asm/arch/mux.h> |
| 48 | #endif |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 49 | #include <dm.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 50 | #include <dm/devres.h> |
| 51 | #include <linux/err.h> |
Jean-Jacques Hiblot | 20157d4 | 2018-01-30 16:01:44 +0100 | [diff] [blame] | 52 | #include <power/regulator.h> |
Faiz Abbas | e4d3056 | 2019-01-30 18:08:42 +0530 | [diff] [blame] | 53 | #include <thermal.h> |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 54 | |
| 55 | DECLARE_GLOBAL_DATA_PTR; |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 56 | |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 57 | /* simplify defines to OMAP_HSMMC_USE_GPIO */ |
| 58 | #if (defined(CONFIG_OMAP_GPIO) && !defined(CONFIG_SPL_BUILD)) || \ |
| 59 | (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_GPIO_SUPPORT)) |
| 60 | #define OMAP_HSMMC_USE_GPIO |
| 61 | #else |
| 62 | #undef OMAP_HSMMC_USE_GPIO |
| 63 | #endif |
| 64 | |
Grazvydas Ignotas | ddde188 | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 65 | /* common definitions for all OMAPs */ |
| 66 | #define SYSCTL_SRC (1 << 25) |
| 67 | #define SYSCTL_SRD (1 << 26) |
| 68 | |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 69 | #ifdef CONFIG_IODELAY_RECALIBRATION |
| 70 | struct omap_hsmmc_pinctrl_state { |
| 71 | struct pad_conf_entry *padconf; |
| 72 | int npads; |
| 73 | struct iodelay_cfg_entry *iodelay; |
| 74 | int niodelays; |
| 75 | }; |
| 76 | #endif |
| 77 | |
Nikita Kiryanov | 1382286 | 2012-12-03 02:19:43 +0000 | [diff] [blame] | 78 | struct omap_hsmmc_data { |
| 79 | struct hsmmc *base_addr; |
Simon Glass | 5f4bd8c | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 80 | #if !CONFIG_IS_ENABLED(DM_MMC) |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 81 | struct mmc_config cfg; |
Jean-Jacques Hiblot | ae51a66 | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 82 | #endif |
Kishon Vijay Abraham I | 2e18c9b | 2018-01-30 16:01:31 +0100 | [diff] [blame] | 83 | uint bus_width; |
Jean-Jacques Hiblot | 7fe2f19 | 2018-01-30 16:01:30 +0100 | [diff] [blame] | 84 | uint clock; |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 85 | ushort last_cmd; |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 86 | #ifdef OMAP_HSMMC_USE_GPIO |
Simon Glass | 5f4bd8c | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 87 | #if CONFIG_IS_ENABLED(DM_MMC) |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 88 | struct gpio_desc cd_gpio; /* Change Detect GPIO */ |
| 89 | struct gpio_desc wp_gpio; /* Write Protect GPIO */ |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 90 | #else |
Nikita Kiryanov | 4eae05c | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 91 | int cd_gpio; |
Nikita Kiryanov | 4be9dbc | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 92 | int wp_gpio; |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 93 | #endif |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 94 | #endif |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 95 | #if CONFIG_IS_ENABLED(DM_MMC) |
Jean-Jacques Hiblot | cf38d4e | 2018-01-30 16:01:33 +0100 | [diff] [blame] | 96 | enum bus_mode mode; |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 97 | #endif |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 98 | u8 controller_flags; |
Jean-Jacques Hiblot | cebf059 | 2018-02-23 10:40:18 +0100 | [diff] [blame] | 99 | #ifdef CONFIG_MMC_OMAP_HS_ADMA |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 100 | struct omap_hsmmc_adma_desc *adma_desc_table; |
| 101 | uint desc_slot; |
| 102 | #endif |
Kishon Vijay Abraham I | 8c2efe9 | 2018-01-30 16:01:41 +0100 | [diff] [blame] | 103 | const char *hw_rev; |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 104 | struct udevice *pbias_supply; |
| 105 | uint signal_voltage; |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 106 | #ifdef CONFIG_IODELAY_RECALIBRATION |
| 107 | struct omap_hsmmc_pinctrl_state *default_pinctrl_state; |
| 108 | struct omap_hsmmc_pinctrl_state *hs_pinctrl_state; |
| 109 | struct omap_hsmmc_pinctrl_state *hs200_1_8v_pinctrl_state; |
| 110 | struct omap_hsmmc_pinctrl_state *ddr_1_8v_pinctrl_state; |
| 111 | struct omap_hsmmc_pinctrl_state *sdr12_pinctrl_state; |
| 112 | struct omap_hsmmc_pinctrl_state *sdr25_pinctrl_state; |
| 113 | struct omap_hsmmc_pinctrl_state *ddr50_pinctrl_state; |
| 114 | struct omap_hsmmc_pinctrl_state *sdr50_pinctrl_state; |
| 115 | struct omap_hsmmc_pinctrl_state *sdr104_pinctrl_state; |
| 116 | #endif |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 117 | }; |
| 118 | |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 119 | struct omap_mmc_of_data { |
| 120 | u8 controller_flags; |
| 121 | }; |
| 122 | |
Jean-Jacques Hiblot | cebf059 | 2018-02-23 10:40:18 +0100 | [diff] [blame] | 123 | #ifdef CONFIG_MMC_OMAP_HS_ADMA |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 124 | struct omap_hsmmc_adma_desc { |
| 125 | u8 attr; |
| 126 | u8 reserved; |
| 127 | u16 len; |
| 128 | u32 addr; |
Nikita Kiryanov | 1382286 | 2012-12-03 02:19:43 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 131 | #define ADMA_MAX_LEN 63488 |
| 132 | |
| 133 | /* Decriptor table defines */ |
| 134 | #define ADMA_DESC_ATTR_VALID BIT(0) |
| 135 | #define ADMA_DESC_ATTR_END BIT(1) |
| 136 | #define ADMA_DESC_ATTR_INT BIT(2) |
| 137 | #define ADMA_DESC_ATTR_ACT1 BIT(4) |
| 138 | #define ADMA_DESC_ATTR_ACT2 BIT(5) |
| 139 | |
| 140 | #define ADMA_DESC_TRANSFER_DATA ADMA_DESC_ATTR_ACT2 |
| 141 | #define ADMA_DESC_LINK_DESC (ADMA_DESC_ATTR_ACT1 | ADMA_DESC_ATTR_ACT2) |
| 142 | #endif |
| 143 | |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 144 | /* If we fail after 1 second wait, something is really bad */ |
| 145 | #define MAX_RETRY_MS 1000 |
Jean-Jacques Hiblot | 192e430 | 2018-01-30 16:01:37 +0100 | [diff] [blame] | 146 | #define MMC_TIMEOUT_MS 20 |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 147 | |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 148 | /* DMA transfers can take a long time if a lot a data is transferred. |
| 149 | * The timeout must take in account the amount of data. Let's assume |
| 150 | * that the time will never exceed 333 ms per MB (in other word we assume |
| 151 | * that the bandwidth is always above 3MB/s). |
| 152 | */ |
| 153 | #define DMA_TIMEOUT_PER_MB 333 |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 154 | #define OMAP_HSMMC_SUPPORTS_DUAL_VOLT BIT(0) |
| 155 | #define OMAP_HSMMC_NO_1_8_V BIT(1) |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 156 | #define OMAP_HSMMC_USE_ADMA BIT(2) |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 157 | #define OMAP_HSMMC_REQUIRE_IODELAY BIT(3) |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 158 | |
Sricharan | f72611f | 2011-11-15 09:49:53 -0500 | [diff] [blame] | 159 | static int mmc_read_data(struct hsmmc *mmc_base, char *buf, unsigned int size); |
| 160 | static int mmc_write_data(struct hsmmc *mmc_base, const char *buf, |
| 161 | unsigned int siz); |
Jean-Jacques Hiblot | 7fe2f19 | 2018-01-30 16:01:30 +0100 | [diff] [blame] | 162 | static void omap_hsmmc_start_clock(struct hsmmc *mmc_base); |
| 163 | static void omap_hsmmc_stop_clock(struct hsmmc *mmc_base); |
Jean-Jacques Hiblot | f0f821b | 2018-01-30 16:01:35 +0100 | [diff] [blame] | 164 | static void mmc_reset_controller_fsm(struct hsmmc *mmc_base, u32 bit); |
Balaji T K | f843d33 | 2011-09-08 06:34:57 +0000 | [diff] [blame] | 165 | |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 166 | static inline struct omap_hsmmc_data *omap_hsmmc_get_data(struct mmc *mmc) |
| 167 | { |
Simon Glass | 5f4bd8c | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 168 | #if CONFIG_IS_ENABLED(DM_MMC) |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 169 | return dev_get_priv(mmc->dev); |
| 170 | #else |
| 171 | return (struct omap_hsmmc_data *)mmc->priv; |
| 172 | #endif |
| 173 | } |
Jean-Jacques Hiblot | ae51a66 | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 174 | static inline struct mmc_config *omap_hsmmc_get_cfg(struct mmc *mmc) |
| 175 | { |
Simon Glass | 5f4bd8c | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 176 | #if CONFIG_IS_ENABLED(DM_MMC) |
Jean-Jacques Hiblot | ae51a66 | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 177 | struct omap_hsmmc_plat *plat = dev_get_platdata(mmc->dev); |
| 178 | return &plat->cfg; |
| 179 | #else |
| 180 | return &((struct omap_hsmmc_data *)mmc->priv)->cfg; |
| 181 | #endif |
| 182 | } |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 183 | |
Simon Glass | 5f4bd8c | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 184 | #if defined(OMAP_HSMMC_USE_GPIO) && !CONFIG_IS_ENABLED(DM_MMC) |
Nikita Kiryanov | 4eae05c | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 185 | static int omap_mmc_setup_gpio_in(int gpio, const char *label) |
| 186 | { |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 187 | int ret; |
Nikita Kiryanov | 4eae05c | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 188 | |
Simon Glass | fa4689a | 2019-12-06 21:41:35 -0700 | [diff] [blame] | 189 | #if !CONFIG_IS_ENABLED(DM_GPIO) |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 190 | if (!gpio_is_valid(gpio)) |
Nikita Kiryanov | 4eae05c | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 191 | return -1; |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 192 | #endif |
| 193 | ret = gpio_request(gpio, label); |
| 194 | if (ret) |
| 195 | return ret; |
Nikita Kiryanov | 4eae05c | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 196 | |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 197 | ret = gpio_direction_input(gpio); |
| 198 | if (ret) |
| 199 | return ret; |
Nikita Kiryanov | 4eae05c | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 200 | |
| 201 | return gpio; |
| 202 | } |
Nikita Kiryanov | 4eae05c | 2012-12-03 02:19:44 +0000 | [diff] [blame] | 203 | #endif |
| 204 | |
Jeroen Hofstee | aedeeaa | 2014-07-12 21:24:08 +0200 | [diff] [blame] | 205 | static unsigned char mmc_board_init(struct mmc *mmc) |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 206 | { |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 207 | #if defined(CONFIG_OMAP34XX) |
Jean-Jacques Hiblot | ae51a66 | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 208 | struct mmc_config *cfg = omap_hsmmc_get_cfg(mmc); |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 209 | t2_t *t2_base = (t2_t *)T2_BASE; |
| 210 | struct prcm *prcm_base = (struct prcm *)PRCM_BASE; |
Grazvydas Ignotas | ef2b729 | 2012-03-19 03:50:53 +0000 | [diff] [blame] | 211 | u32 pbias_lite; |
Adam Ford | ef35496 | 2017-02-06 11:31:43 -0600 | [diff] [blame] | 212 | #ifdef CONFIG_MMC_OMAP36XX_PINS |
| 213 | u32 wkup_ctrl = readl(OMAP34XX_CTRL_WKUP_CTRL); |
| 214 | #endif |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 215 | |
Grazvydas Ignotas | ef2b729 | 2012-03-19 03:50:53 +0000 | [diff] [blame] | 216 | pbias_lite = readl(&t2_base->pbias_lite); |
| 217 | pbias_lite &= ~(PBIASLITEPWRDNZ1 | PBIASLITEPWRDNZ0); |
Albert ARIBAUD \(3ADEV\) | 6ad0981 | 2015-01-16 09:09:50 +0100 | [diff] [blame] | 218 | #ifdef CONFIG_TARGET_OMAP3_CAIRO |
| 219 | /* for cairo board, we need to set up 1.8 Volt bias level on MMC1 */ |
| 220 | pbias_lite &= ~PBIASLITEVMODE0; |
| 221 | #endif |
Adam Ford | f2eb432 | 2018-09-05 04:11:08 -0500 | [diff] [blame] | 222 | #ifdef CONFIG_TARGET_OMAP3_LOGIC |
| 223 | /* For Logic PD board, 1.8V bias to go enable gpio127 for mmc_cd */ |
| 224 | pbias_lite &= ~PBIASLITEVMODE1; |
| 225 | #endif |
Adam Ford | ef35496 | 2017-02-06 11:31:43 -0600 | [diff] [blame] | 226 | #ifdef CONFIG_MMC_OMAP36XX_PINS |
| 227 | if (get_cpu_family() == CPU_OMAP36XX) { |
| 228 | /* Disable extended drain IO before changing PBIAS */ |
| 229 | wkup_ctrl &= ~OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ; |
| 230 | writel(wkup_ctrl, OMAP34XX_CTRL_WKUP_CTRL); |
| 231 | } |
| 232 | #endif |
Grazvydas Ignotas | ef2b729 | 2012-03-19 03:50:53 +0000 | [diff] [blame] | 233 | writel(pbias_lite, &t2_base->pbias_lite); |
Paul Kocialkowski | 6955989 | 2014-11-08 20:55:47 +0100 | [diff] [blame] | 234 | |
Grazvydas Ignotas | ef2b729 | 2012-03-19 03:50:53 +0000 | [diff] [blame] | 235 | writel(pbias_lite | PBIASLITEPWRDNZ1 | |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 236 | PBIASSPEEDCTRL0 | PBIASLITEPWRDNZ0, |
| 237 | &t2_base->pbias_lite); |
| 238 | |
Adam Ford | ef35496 | 2017-02-06 11:31:43 -0600 | [diff] [blame] | 239 | #ifdef CONFIG_MMC_OMAP36XX_PINS |
| 240 | if (get_cpu_family() == CPU_OMAP36XX) |
| 241 | /* Enable extended drain IO after changing PBIAS */ |
| 242 | writel(wkup_ctrl | |
| 243 | OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ, |
| 244 | OMAP34XX_CTRL_WKUP_CTRL); |
| 245 | #endif |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 246 | writel(readl(&t2_base->devconf0) | MMCSDIO1ADPCLKISEL, |
| 247 | &t2_base->devconf0); |
| 248 | |
| 249 | writel(readl(&t2_base->devconf1) | MMCSDIO2ADPCLKISEL, |
| 250 | &t2_base->devconf1); |
| 251 | |
Jonathan Solnit | a9b0556 | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 252 | /* Change from default of 52MHz to 26MHz if necessary */ |
Jean-Jacques Hiblot | ae51a66 | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 253 | if (!(cfg->host_caps & MMC_MODE_HS_52MHz)) |
Jonathan Solnit | a9b0556 | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 254 | writel(readl(&t2_base->ctl_prog_io1) & ~CTLPROGIO1SPEEDCTRL, |
| 255 | &t2_base->ctl_prog_io1); |
| 256 | |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 257 | writel(readl(&prcm_base->fclken1_core) | |
| 258 | EN_MMC1 | EN_MMC2 | EN_MMC3, |
| 259 | &prcm_base->fclken1_core); |
| 260 | |
| 261 | writel(readl(&prcm_base->iclken1_core) | |
| 262 | EN_MMC1 | EN_MMC2 | EN_MMC3, |
| 263 | &prcm_base->iclken1_core); |
| 264 | #endif |
| 265 | |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 266 | #if (defined(CONFIG_OMAP54XX) || defined(CONFIG_OMAP44XX)) &&\ |
| 267 | !CONFIG_IS_ENABLED(DM_REGULATOR) |
Balaji T K | f843d33 | 2011-09-08 06:34:57 +0000 | [diff] [blame] | 268 | /* PBIAS config needed for MMC1 only */ |
Jean-Jacques Hiblot | 26319b1 | 2017-03-22 16:00:32 +0100 | [diff] [blame] | 269 | if (mmc_get_blk_desc(mmc)->devnum == 0) |
Faiz Abbas | fc1ad62 | 2019-04-05 14:18:46 +0530 | [diff] [blame] | 270 | vmmc_pbias_config(LDO_VOLT_3V3); |
Balaji T K | d9cf836 | 2012-03-12 02:25:49 +0000 | [diff] [blame] | 271 | #endif |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
Sricharan | f72611f | 2011-11-15 09:49:53 -0500 | [diff] [blame] | 276 | void mmc_init_stream(struct hsmmc *mmc_base) |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 277 | { |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 278 | ulong start; |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 279 | |
| 280 | writel(readl(&mmc_base->con) | INIT_INITSTREAM, &mmc_base->con); |
| 281 | |
| 282 | writel(MMC_CMD0, &mmc_base->cmd); |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 283 | start = get_timer(0); |
| 284 | while (!(readl(&mmc_base->stat) & CC_MASK)) { |
| 285 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 286 | printf("%s: timedout waiting for cc!\n", __func__); |
| 287 | return; |
| 288 | } |
| 289 | } |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 290 | writel(CC_MASK, &mmc_base->stat) |
| 291 | ; |
| 292 | writel(MMC_CMD0, &mmc_base->cmd) |
| 293 | ; |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 294 | start = get_timer(0); |
| 295 | while (!(readl(&mmc_base->stat) & CC_MASK)) { |
| 296 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 297 | printf("%s: timedout waiting for cc2!\n", __func__); |
| 298 | return; |
| 299 | } |
| 300 | } |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 301 | writel(readl(&mmc_base->con) & ~INIT_INITSTREAM, &mmc_base->con); |
| 302 | } |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 303 | |
| 304 | #if CONFIG_IS_ENABLED(DM_MMC) |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 305 | #ifdef CONFIG_IODELAY_RECALIBRATION |
| 306 | static void omap_hsmmc_io_recalibrate(struct mmc *mmc) |
| 307 | { |
| 308 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 309 | struct omap_hsmmc_pinctrl_state *pinctrl_state; |
| 310 | |
| 311 | switch (priv->mode) { |
| 312 | case MMC_HS_200: |
| 313 | pinctrl_state = priv->hs200_1_8v_pinctrl_state; |
| 314 | break; |
| 315 | case UHS_SDR104: |
| 316 | pinctrl_state = priv->sdr104_pinctrl_state; |
| 317 | break; |
| 318 | case UHS_SDR50: |
| 319 | pinctrl_state = priv->sdr50_pinctrl_state; |
| 320 | break; |
| 321 | case UHS_DDR50: |
| 322 | pinctrl_state = priv->ddr50_pinctrl_state; |
| 323 | break; |
| 324 | case UHS_SDR25: |
| 325 | pinctrl_state = priv->sdr25_pinctrl_state; |
| 326 | break; |
| 327 | case UHS_SDR12: |
| 328 | pinctrl_state = priv->sdr12_pinctrl_state; |
| 329 | break; |
| 330 | case SD_HS: |
| 331 | case MMC_HS: |
| 332 | case MMC_HS_52: |
| 333 | pinctrl_state = priv->hs_pinctrl_state; |
| 334 | break; |
| 335 | case MMC_DDR_52: |
| 336 | pinctrl_state = priv->ddr_1_8v_pinctrl_state; |
| 337 | default: |
| 338 | pinctrl_state = priv->default_pinctrl_state; |
| 339 | break; |
| 340 | } |
| 341 | |
Jean-Jacques Hiblot | dae1ad4 | 2018-01-30 16:01:42 +0100 | [diff] [blame] | 342 | if (!pinctrl_state) |
| 343 | pinctrl_state = priv->default_pinctrl_state; |
| 344 | |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 345 | if (priv->controller_flags & OMAP_HSMMC_REQUIRE_IODELAY) { |
| 346 | if (pinctrl_state->iodelay) |
| 347 | late_recalibrate_iodelay(pinctrl_state->padconf, |
| 348 | pinctrl_state->npads, |
| 349 | pinctrl_state->iodelay, |
| 350 | pinctrl_state->niodelays); |
| 351 | else |
| 352 | do_set_mux32((*ctrl)->control_padconf_core_base, |
| 353 | pinctrl_state->padconf, |
| 354 | pinctrl_state->npads); |
| 355 | } |
| 356 | } |
| 357 | #endif |
Jean-Jacques Hiblot | cf38d4e | 2018-01-30 16:01:33 +0100 | [diff] [blame] | 358 | static void omap_hsmmc_set_timing(struct mmc *mmc) |
| 359 | { |
| 360 | u32 val; |
| 361 | struct hsmmc *mmc_base; |
| 362 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 363 | |
| 364 | mmc_base = priv->base_addr; |
| 365 | |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 366 | omap_hsmmc_stop_clock(mmc_base); |
Jean-Jacques Hiblot | cf38d4e | 2018-01-30 16:01:33 +0100 | [diff] [blame] | 367 | val = readl(&mmc_base->ac12); |
| 368 | val &= ~AC12_UHSMC_MASK; |
| 369 | priv->mode = mmc->selected_mode; |
| 370 | |
Kishon Vijay Abraham I | 0c1f3d0 | 2018-01-30 16:01:34 +0100 | [diff] [blame] | 371 | if (mmc_is_mode_ddr(priv->mode)) |
| 372 | writel(readl(&mmc_base->con) | DDR, &mmc_base->con); |
| 373 | else |
| 374 | writel(readl(&mmc_base->con) & ~DDR, &mmc_base->con); |
| 375 | |
Jean-Jacques Hiblot | cf38d4e | 2018-01-30 16:01:33 +0100 | [diff] [blame] | 376 | switch (priv->mode) { |
| 377 | case MMC_HS_200: |
| 378 | case UHS_SDR104: |
| 379 | val |= AC12_UHSMC_SDR104; |
| 380 | break; |
| 381 | case UHS_SDR50: |
| 382 | val |= AC12_UHSMC_SDR50; |
| 383 | break; |
| 384 | case MMC_DDR_52: |
| 385 | case UHS_DDR50: |
| 386 | val |= AC12_UHSMC_DDR50; |
| 387 | break; |
| 388 | case SD_HS: |
| 389 | case MMC_HS_52: |
| 390 | case UHS_SDR25: |
| 391 | val |= AC12_UHSMC_SDR25; |
| 392 | break; |
| 393 | case MMC_LEGACY: |
| 394 | case MMC_HS: |
Jean-Jacques Hiblot | cf38d4e | 2018-01-30 16:01:33 +0100 | [diff] [blame] | 395 | case UHS_SDR12: |
| 396 | val |= AC12_UHSMC_SDR12; |
| 397 | break; |
| 398 | default: |
| 399 | val |= AC12_UHSMC_RES; |
| 400 | break; |
| 401 | } |
| 402 | writel(val, &mmc_base->ac12); |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 403 | |
| 404 | #ifdef CONFIG_IODELAY_RECALIBRATION |
| 405 | omap_hsmmc_io_recalibrate(mmc); |
| 406 | #endif |
| 407 | omap_hsmmc_start_clock(mmc_base); |
Jean-Jacques Hiblot | cf38d4e | 2018-01-30 16:01:33 +0100 | [diff] [blame] | 408 | } |
| 409 | |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 410 | static void omap_hsmmc_conf_bus_power(struct mmc *mmc, uint signal_voltage) |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 411 | { |
| 412 | struct hsmmc *mmc_base; |
| 413 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 414 | u32 hctl, ac12; |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 415 | |
| 416 | mmc_base = priv->base_addr; |
| 417 | |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 418 | hctl = readl(&mmc_base->hctl) & ~SDVS_MASK; |
| 419 | ac12 = readl(&mmc_base->ac12) & ~AC12_V1V8_SIGEN; |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 420 | |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 421 | switch (signal_voltage) { |
| 422 | case MMC_SIGNAL_VOLTAGE_330: |
Faiz Abbas | fc1ad62 | 2019-04-05 14:18:46 +0530 | [diff] [blame] | 423 | hctl |= SDVS_3V3; |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 424 | break; |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 425 | case MMC_SIGNAL_VOLTAGE_180: |
| 426 | hctl |= SDVS_1V8; |
| 427 | ac12 |= AC12_V1V8_SIGEN; |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 428 | break; |
| 429 | } |
| 430 | |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 431 | writel(hctl, &mmc_base->hctl); |
| 432 | writel(ac12, &mmc_base->ac12); |
| 433 | } |
| 434 | |
Sam Protsenko | db174c6 | 2019-08-14 22:52:51 +0300 | [diff] [blame] | 435 | static int omap_hsmmc_wait_dat0(struct udevice *dev, int state, int timeout_us) |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 436 | { |
| 437 | int ret = -ETIMEDOUT; |
| 438 | u32 con; |
| 439 | bool dat0_high; |
| 440 | bool target_dat0_high = !!state; |
| 441 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
| 442 | struct hsmmc *mmc_base = priv->base_addr; |
| 443 | |
| 444 | con = readl(&mmc_base->con); |
| 445 | writel(con | CON_CLKEXTFREE | CON_PADEN, &mmc_base->con); |
| 446 | |
Sam Protsenko | db174c6 | 2019-08-14 22:52:51 +0300 | [diff] [blame] | 447 | timeout_us = DIV_ROUND_UP(timeout_us, 10); /* check every 10 us. */ |
| 448 | while (timeout_us--) { |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 449 | dat0_high = !!(readl(&mmc_base->pstate) & PSTATE_DLEV_DAT0); |
| 450 | if (dat0_high == target_dat0_high) { |
| 451 | ret = 0; |
| 452 | break; |
| 453 | } |
| 454 | udelay(10); |
| 455 | } |
| 456 | writel(con, &mmc_base->con); |
| 457 | |
| 458 | return ret; |
| 459 | } |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 460 | |
| 461 | #if CONFIG_IS_ENABLED(MMC_IO_VOLTAGE) |
| 462 | #if CONFIG_IS_ENABLED(DM_REGULATOR) |
| 463 | static int omap_hsmmc_set_io_regulator(struct mmc *mmc, int mV) |
| 464 | { |
| 465 | int ret = 0; |
| 466 | int uV = mV * 1000; |
| 467 | |
| 468 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 469 | |
| 470 | if (!mmc->vqmmc_supply) |
| 471 | return 0; |
| 472 | |
| 473 | /* Disable PBIAS */ |
Lokesh Vutla | b269197 | 2019-01-11 15:15:52 +0530 | [diff] [blame] | 474 | ret = regulator_set_enable_if_allowed(priv->pbias_supply, false); |
| 475 | if (ret) |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 476 | return ret; |
| 477 | |
| 478 | /* Turn off IO voltage */ |
Lokesh Vutla | b269197 | 2019-01-11 15:15:52 +0530 | [diff] [blame] | 479 | ret = regulator_set_enable_if_allowed(mmc->vqmmc_supply, false); |
| 480 | if (ret) |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 481 | return ret; |
| 482 | /* Program a new IO voltage value */ |
| 483 | ret = regulator_set_value(mmc->vqmmc_supply, uV); |
| 484 | if (ret) |
| 485 | return ret; |
| 486 | /* Turn on IO voltage */ |
Lokesh Vutla | b269197 | 2019-01-11 15:15:52 +0530 | [diff] [blame] | 487 | ret = regulator_set_enable_if_allowed(mmc->vqmmc_supply, true); |
| 488 | if (ret) |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 489 | return ret; |
| 490 | |
| 491 | /* Program PBIAS voltage*/ |
| 492 | ret = regulator_set_value(priv->pbias_supply, uV); |
| 493 | if (ret && ret != -ENOSYS) |
| 494 | return ret; |
| 495 | /* Enable PBIAS */ |
Lokesh Vutla | b269197 | 2019-01-11 15:15:52 +0530 | [diff] [blame] | 496 | ret = regulator_set_enable_if_allowed(priv->pbias_supply, true); |
| 497 | if (ret) |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 498 | return ret; |
| 499 | |
| 500 | return 0; |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 501 | } |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 502 | #endif |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 503 | |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 504 | static int omap_hsmmc_set_signal_voltage(struct mmc *mmc) |
| 505 | { |
| 506 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 507 | struct hsmmc *mmc_base = priv->base_addr; |
| 508 | int mv = mmc_voltage_to_mv(mmc->signal_voltage); |
| 509 | u32 capa_mask; |
| 510 | __maybe_unused u8 palmas_ldo_volt; |
| 511 | u32 val; |
| 512 | |
| 513 | if (mv < 0) |
| 514 | return -EINVAL; |
| 515 | |
| 516 | if (mmc->signal_voltage == MMC_SIGNAL_VOLTAGE_330) { |
Faiz Abbas | fc1ad62 | 2019-04-05 14:18:46 +0530 | [diff] [blame] | 517 | mv = 3300; |
| 518 | capa_mask = VS33_3V3SUP; |
| 519 | palmas_ldo_volt = LDO_VOLT_3V3; |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 520 | } else if (mmc->signal_voltage == MMC_SIGNAL_VOLTAGE_180) { |
| 521 | capa_mask = VS18_1V8SUP; |
| 522 | palmas_ldo_volt = LDO_VOLT_1V8; |
| 523 | } else { |
| 524 | return -EOPNOTSUPP; |
| 525 | } |
| 526 | |
| 527 | val = readl(&mmc_base->capa); |
| 528 | if (!(val & capa_mask)) |
| 529 | return -EOPNOTSUPP; |
| 530 | |
| 531 | priv->signal_voltage = mmc->signal_voltage; |
| 532 | |
| 533 | omap_hsmmc_conf_bus_power(mmc, mmc->signal_voltage); |
| 534 | |
| 535 | #if CONFIG_IS_ENABLED(DM_REGULATOR) |
| 536 | return omap_hsmmc_set_io_regulator(mmc, mv); |
| 537 | #elif (defined(CONFIG_OMAP54XX) || defined(CONFIG_OMAP44XX)) && \ |
| 538 | defined(CONFIG_PALMAS_POWER) |
| 539 | if (mmc_get_blk_desc(mmc)->devnum == 0) |
| 540 | vmmc_pbias_config(palmas_ldo_volt); |
| 541 | return 0; |
| 542 | #else |
| 543 | return 0; |
| 544 | #endif |
| 545 | } |
| 546 | #endif |
| 547 | |
| 548 | static uint32_t omap_hsmmc_set_capabilities(struct mmc *mmc) |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 549 | { |
| 550 | struct hsmmc *mmc_base; |
| 551 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 552 | u32 val; |
| 553 | |
| 554 | mmc_base = priv->base_addr; |
| 555 | val = readl(&mmc_base->capa); |
| 556 | |
| 557 | if (priv->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) { |
Faiz Abbas | fc1ad62 | 2019-04-05 14:18:46 +0530 | [diff] [blame] | 558 | val |= (VS33_3V3SUP | VS18_1V8SUP); |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 559 | } else if (priv->controller_flags & OMAP_HSMMC_NO_1_8_V) { |
Faiz Abbas | fc1ad62 | 2019-04-05 14:18:46 +0530 | [diff] [blame] | 560 | val |= VS33_3V3SUP; |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 561 | val &= ~VS18_1V8SUP; |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 562 | } else { |
| 563 | val |= VS18_1V8SUP; |
Faiz Abbas | fc1ad62 | 2019-04-05 14:18:46 +0530 | [diff] [blame] | 564 | val &= ~VS33_3V3SUP; |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | writel(val, &mmc_base->capa); |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 568 | |
| 569 | return val; |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 570 | } |
Jean-Jacques Hiblot | f0f821b | 2018-01-30 16:01:35 +0100 | [diff] [blame] | 571 | |
| 572 | #ifdef MMC_SUPPORTS_TUNING |
| 573 | static void omap_hsmmc_disable_tuning(struct mmc *mmc) |
| 574 | { |
| 575 | struct hsmmc *mmc_base; |
| 576 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 577 | u32 val; |
| 578 | |
| 579 | mmc_base = priv->base_addr; |
| 580 | val = readl(&mmc_base->ac12); |
| 581 | val &= ~(AC12_SCLK_SEL); |
| 582 | writel(val, &mmc_base->ac12); |
| 583 | |
| 584 | val = readl(&mmc_base->dll); |
| 585 | val &= ~(DLL_FORCE_VALUE | DLL_SWT); |
| 586 | writel(val, &mmc_base->dll); |
| 587 | } |
| 588 | |
| 589 | static void omap_hsmmc_set_dll(struct mmc *mmc, int count) |
| 590 | { |
| 591 | int i; |
| 592 | struct hsmmc *mmc_base; |
| 593 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 594 | u32 val; |
| 595 | |
| 596 | mmc_base = priv->base_addr; |
| 597 | val = readl(&mmc_base->dll); |
| 598 | val |= DLL_FORCE_VALUE; |
| 599 | val &= ~(DLL_FORCE_SR_C_MASK << DLL_FORCE_SR_C_SHIFT); |
| 600 | val |= (count << DLL_FORCE_SR_C_SHIFT); |
| 601 | writel(val, &mmc_base->dll); |
| 602 | |
| 603 | val |= DLL_CALIB; |
| 604 | writel(val, &mmc_base->dll); |
| 605 | for (i = 0; i < 1000; i++) { |
| 606 | if (readl(&mmc_base->dll) & DLL_CALIB) |
| 607 | break; |
| 608 | } |
| 609 | val &= ~DLL_CALIB; |
| 610 | writel(val, &mmc_base->dll); |
| 611 | } |
| 612 | |
| 613 | static int omap_hsmmc_execute_tuning(struct udevice *dev, uint opcode) |
| 614 | { |
| 615 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
| 616 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 617 | struct mmc *mmc = upriv->mmc; |
| 618 | struct hsmmc *mmc_base; |
| 619 | u32 val; |
| 620 | u8 cur_match, prev_match = 0; |
| 621 | int ret; |
| 622 | u32 phase_delay = 0; |
| 623 | u32 start_window = 0, max_window = 0; |
| 624 | u32 length = 0, max_len = 0; |
Faiz Abbas | e4d3056 | 2019-01-30 18:08:42 +0530 | [diff] [blame] | 625 | bool single_point_failure = false; |
| 626 | struct udevice *thermal_dev; |
| 627 | int temperature; |
| 628 | int i; |
Jean-Jacques Hiblot | f0f821b | 2018-01-30 16:01:35 +0100 | [diff] [blame] | 629 | |
| 630 | mmc_base = priv->base_addr; |
| 631 | val = readl(&mmc_base->capa2); |
| 632 | |
| 633 | /* clock tuning is not needed for upto 52MHz */ |
| 634 | if (!((mmc->selected_mode == MMC_HS_200) || |
| 635 | (mmc->selected_mode == UHS_SDR104) || |
| 636 | ((mmc->selected_mode == UHS_SDR50) && (val & CAPA2_TSDR50)))) |
| 637 | return 0; |
| 638 | |
Faiz Abbas | e4d3056 | 2019-01-30 18:08:42 +0530 | [diff] [blame] | 639 | ret = uclass_first_device(UCLASS_THERMAL, &thermal_dev); |
| 640 | if (ret) { |
| 641 | printf("Couldn't get thermal device for tuning\n"); |
| 642 | return ret; |
| 643 | } |
| 644 | ret = thermal_get_temp(thermal_dev, &temperature); |
| 645 | if (ret) { |
| 646 | printf("Couldn't get temperature for tuning\n"); |
| 647 | return ret; |
| 648 | } |
Jean-Jacques Hiblot | f0f821b | 2018-01-30 16:01:35 +0100 | [diff] [blame] | 649 | val = readl(&mmc_base->dll); |
| 650 | val |= DLL_SWT; |
| 651 | writel(val, &mmc_base->dll); |
Faiz Abbas | e4d3056 | 2019-01-30 18:08:42 +0530 | [diff] [blame] | 652 | |
| 653 | /* |
| 654 | * Stage 1: Search for a maximum pass window ignoring any |
| 655 | * any single point failures. If the tuning value ends up |
| 656 | * near it, move away from it in stage 2 below |
| 657 | */ |
Jean-Jacques Hiblot | f0f821b | 2018-01-30 16:01:35 +0100 | [diff] [blame] | 658 | while (phase_delay <= MAX_PHASE_DELAY) { |
| 659 | omap_hsmmc_set_dll(mmc, phase_delay); |
| 660 | |
| 661 | cur_match = !mmc_send_tuning(mmc, opcode, NULL); |
| 662 | |
| 663 | if (cur_match) { |
| 664 | if (prev_match) { |
| 665 | length++; |
Faiz Abbas | e4d3056 | 2019-01-30 18:08:42 +0530 | [diff] [blame] | 666 | } else if (single_point_failure) { |
| 667 | /* ignore single point failure */ |
| 668 | length++; |
| 669 | single_point_failure = false; |
Jean-Jacques Hiblot | f0f821b | 2018-01-30 16:01:35 +0100 | [diff] [blame] | 670 | } else { |
| 671 | start_window = phase_delay; |
| 672 | length = 1; |
| 673 | } |
Faiz Abbas | e4d3056 | 2019-01-30 18:08:42 +0530 | [diff] [blame] | 674 | } else { |
| 675 | single_point_failure = prev_match; |
Jean-Jacques Hiblot | f0f821b | 2018-01-30 16:01:35 +0100 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | if (length > max_len) { |
| 679 | max_window = start_window; |
| 680 | max_len = length; |
| 681 | } |
| 682 | |
| 683 | prev_match = cur_match; |
| 684 | phase_delay += 4; |
| 685 | } |
| 686 | |
| 687 | if (!max_len) { |
| 688 | ret = -EIO; |
| 689 | goto tuning_error; |
| 690 | } |
| 691 | |
| 692 | val = readl(&mmc_base->ac12); |
| 693 | if (!(val & AC12_SCLK_SEL)) { |
| 694 | ret = -EIO; |
| 695 | goto tuning_error; |
| 696 | } |
Faiz Abbas | e4d3056 | 2019-01-30 18:08:42 +0530 | [diff] [blame] | 697 | /* |
| 698 | * Assign tuning value as a ratio of maximum pass window based |
| 699 | * on temperature |
| 700 | */ |
| 701 | if (temperature < -20000) |
| 702 | phase_delay = min(max_window + 4 * max_len - 24, |
| 703 | max_window + |
| 704 | DIV_ROUND_UP(13 * max_len, 16) * 4); |
| 705 | else if (temperature < 20000) |
| 706 | phase_delay = max_window + DIV_ROUND_UP(9 * max_len, 16) * 4; |
| 707 | else if (temperature < 40000) |
| 708 | phase_delay = max_window + DIV_ROUND_UP(8 * max_len, 16) * 4; |
| 709 | else if (temperature < 70000) |
| 710 | phase_delay = max_window + DIV_ROUND_UP(7 * max_len, 16) * 4; |
| 711 | else if (temperature < 90000) |
| 712 | phase_delay = max_window + DIV_ROUND_UP(5 * max_len, 16) * 4; |
| 713 | else if (temperature < 120000) |
| 714 | phase_delay = max_window + DIV_ROUND_UP(4 * max_len, 16) * 4; |
| 715 | else |
| 716 | phase_delay = max_window + DIV_ROUND_UP(3 * max_len, 16) * 4; |
| 717 | |
| 718 | /* |
| 719 | * Stage 2: Search for a single point failure near the chosen tuning |
| 720 | * value in two steps. First in the +3 to +10 range and then in the |
| 721 | * +2 to -10 range. If found, move away from it in the appropriate |
| 722 | * direction by the appropriate amount depending on the temperature. |
| 723 | */ |
| 724 | for (i = 3; i <= 10; i++) { |
| 725 | omap_hsmmc_set_dll(mmc, phase_delay + i); |
| 726 | if (mmc_send_tuning(mmc, opcode, NULL)) { |
| 727 | if (temperature < 10000) |
| 728 | phase_delay += i + 6; |
| 729 | else if (temperature < 20000) |
| 730 | phase_delay += i - 12; |
| 731 | else if (temperature < 70000) |
| 732 | phase_delay += i - 8; |
| 733 | else if (temperature < 90000) |
| 734 | phase_delay += i - 6; |
| 735 | else |
| 736 | phase_delay += i - 6; |
| 737 | |
| 738 | goto single_failure_found; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | for (i = 2; i >= -10; i--) { |
| 743 | omap_hsmmc_set_dll(mmc, phase_delay + i); |
| 744 | if (mmc_send_tuning(mmc, opcode, NULL)) { |
| 745 | if (temperature < 10000) |
| 746 | phase_delay += i + 12; |
| 747 | else if (temperature < 20000) |
| 748 | phase_delay += i + 8; |
| 749 | else if (temperature < 70000) |
| 750 | phase_delay += i + 8; |
| 751 | else if (temperature < 90000) |
| 752 | phase_delay += i + 10; |
| 753 | else |
| 754 | phase_delay += i + 12; |
| 755 | |
| 756 | goto single_failure_found; |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | single_failure_found: |
Jean-Jacques Hiblot | f0f821b | 2018-01-30 16:01:35 +0100 | [diff] [blame] | 761 | |
Jean-Jacques Hiblot | f0f821b | 2018-01-30 16:01:35 +0100 | [diff] [blame] | 762 | omap_hsmmc_set_dll(mmc, phase_delay); |
| 763 | |
| 764 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD); |
| 765 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRC); |
| 766 | |
| 767 | return 0; |
| 768 | |
| 769 | tuning_error: |
| 770 | |
| 771 | omap_hsmmc_disable_tuning(mmc); |
| 772 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD); |
| 773 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRC); |
| 774 | |
| 775 | return ret; |
| 776 | } |
| 777 | #endif |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 778 | #endif |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 779 | |
Jean-Jacques Hiblot | a420d7d | 2018-01-30 16:01:36 +0100 | [diff] [blame] | 780 | static void mmc_enable_irq(struct mmc *mmc, struct mmc_cmd *cmd) |
| 781 | { |
| 782 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 783 | struct hsmmc *mmc_base = priv->base_addr; |
| 784 | u32 irq_mask = INT_EN_MASK; |
| 785 | |
| 786 | /* |
| 787 | * TODO: Errata i802 indicates only DCRC interrupts can occur during |
| 788 | * tuning procedure and DCRC should be disabled. But see occurences |
| 789 | * of DEB, CIE, CEB, CCRC interupts during tuning procedure. These |
| 790 | * interrupts occur along with BRR, so the data is actually in the |
| 791 | * buffer. It has to be debugged why these interrutps occur |
| 792 | */ |
| 793 | if (cmd && mmc_is_tuning_cmd(cmd->cmdidx)) |
| 794 | irq_mask &= ~(IE_DEB | IE_DCRC | IE_CIE | IE_CEB | IE_CCRC); |
| 795 | |
| 796 | writel(irq_mask, &mmc_base->ie); |
| 797 | } |
| 798 | |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 799 | static int omap_hsmmc_init_setup(struct mmc *mmc) |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 800 | { |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 801 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Nikita Kiryanov | 1382286 | 2012-12-03 02:19:43 +0000 | [diff] [blame] | 802 | struct hsmmc *mmc_base; |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 803 | unsigned int reg_val; |
| 804 | unsigned int dsor; |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 805 | ulong start; |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 806 | |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 807 | mmc_base = priv->base_addr; |
Balaji T K | f843d33 | 2011-09-08 06:34:57 +0000 | [diff] [blame] | 808 | mmc_board_init(mmc); |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 809 | |
| 810 | writel(readl(&mmc_base->sysconfig) | MMC_SOFTRESET, |
| 811 | &mmc_base->sysconfig); |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 812 | start = get_timer(0); |
| 813 | while ((readl(&mmc_base->sysstatus) & RESETDONE) == 0) { |
| 814 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 815 | printf("%s: timedout waiting for cc2!\n", __func__); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 816 | return -ETIMEDOUT; |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 817 | } |
| 818 | } |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 819 | writel(readl(&mmc_base->sysctl) | SOFTRESETALL, &mmc_base->sysctl); |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 820 | start = get_timer(0); |
| 821 | while ((readl(&mmc_base->sysctl) & SOFTRESETALL) != 0x0) { |
| 822 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 823 | printf("%s: timedout waiting for softresetall!\n", |
| 824 | __func__); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 825 | return -ETIMEDOUT; |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 826 | } |
| 827 | } |
Jean-Jacques Hiblot | cebf059 | 2018-02-23 10:40:18 +0100 | [diff] [blame] | 828 | #ifdef CONFIG_MMC_OMAP_HS_ADMA |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 829 | reg_val = readl(&mmc_base->hl_hwinfo); |
| 830 | if (reg_val & MADMA_EN) |
| 831 | priv->controller_flags |= OMAP_HSMMC_USE_ADMA; |
| 832 | #endif |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 833 | |
| 834 | #if CONFIG_IS_ENABLED(DM_MMC) |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 835 | reg_val = omap_hsmmc_set_capabilities(mmc); |
Faiz Abbas | fc1ad62 | 2019-04-05 14:18:46 +0530 | [diff] [blame] | 836 | omap_hsmmc_conf_bus_power(mmc, (reg_val & VS33_3V3SUP) ? |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 837 | MMC_SIGNAL_VOLTAGE_330 : MMC_SIGNAL_VOLTAGE_180); |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 838 | #else |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 839 | writel(DTW_1_BITMODE | SDBP_PWROFF | SDVS_3V0, &mmc_base->hctl); |
Faiz Abbas | fc1ad62 | 2019-04-05 14:18:46 +0530 | [diff] [blame] | 840 | writel(readl(&mmc_base->capa) | VS33_3V3SUP | VS18_1V8SUP, |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 841 | &mmc_base->capa); |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 842 | #endif |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 843 | |
| 844 | reg_val = readl(&mmc_base->con) & RESERVED_MASK; |
| 845 | |
| 846 | writel(CTPL_MMC_SD | reg_val | WPP_ACTIVEHIGH | CDP_ACTIVEHIGH | |
| 847 | MIT_CTO | DW8_1_4BITMODE | MODE_FUNC | STR_BLOCK | |
| 848 | HR_NOHOSTRESP | INIT_NOINIT | NOOPENDRAIN, &mmc_base->con); |
| 849 | |
| 850 | dsor = 240; |
| 851 | 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] | 852 | (ICE_STOP | DTO_15THDTO)); |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 853 | mmc_reg_out(&mmc_base->sysctl, ICE_MASK | CLKD_MASK, |
| 854 | (dsor << CLKD_OFFSET) | ICE_OSCILLATE); |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 855 | start = get_timer(0); |
| 856 | while ((readl(&mmc_base->sysctl) & ICS_MASK) == ICS_NOTREADY) { |
| 857 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 858 | printf("%s: timedout waiting for ics!\n", __func__); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 859 | return -ETIMEDOUT; |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 860 | } |
| 861 | } |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 862 | writel(readl(&mmc_base->sysctl) | CEN_ENABLE, &mmc_base->sysctl); |
| 863 | |
| 864 | writel(readl(&mmc_base->hctl) | SDBP_PWRON, &mmc_base->hctl); |
| 865 | |
Jean-Jacques Hiblot | a420d7d | 2018-01-30 16:01:36 +0100 | [diff] [blame] | 866 | mmc_enable_irq(mmc, NULL); |
Jean-Jacques Hiblot | 20157d4 | 2018-01-30 16:01:44 +0100 | [diff] [blame] | 867 | |
| 868 | #if !CONFIG_IS_ENABLED(DM_MMC) |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 869 | mmc_init_stream(mmc_base); |
Jean-Jacques Hiblot | 20157d4 | 2018-01-30 16:01:44 +0100 | [diff] [blame] | 870 | #endif |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 871 | |
| 872 | return 0; |
| 873 | } |
| 874 | |
Grazvydas Ignotas | ddde188 | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 875 | /* |
| 876 | * MMC controller internal finite state machine reset |
| 877 | * |
| 878 | * Used to reset command or data internal state machines, using respectively |
| 879 | * SRC or SRD bit of SYSCTL register |
| 880 | */ |
| 881 | static void mmc_reset_controller_fsm(struct hsmmc *mmc_base, u32 bit) |
| 882 | { |
| 883 | ulong start; |
| 884 | |
| 885 | mmc_reg_out(&mmc_base->sysctl, bit, bit); |
| 886 | |
Oleksandr Tyshchenko | 06640ca | 2013-08-06 13:44:16 +0300 | [diff] [blame] | 887 | /* |
| 888 | * CMD(DAT) lines reset procedures are slightly different |
| 889 | * for OMAP3 and OMAP4(AM335x,OMAP5,DRA7xx). |
| 890 | * According to OMAP3 TRM: |
| 891 | * Set SRC(SRD) bit in MMCHS_SYSCTL register to 0x1 and wait until it |
| 892 | * returns to 0x0. |
| 893 | * According to OMAP4(AM335x,OMAP5,DRA7xx) TRMs, CMD(DATA) lines reset |
| 894 | * procedure steps must be as follows: |
| 895 | * 1. Initiate CMD(DAT) line reset by writing 0x1 to SRC(SRD) bit in |
| 896 | * MMCHS_SYSCTL register (SD_SYSCTL for AM335x). |
| 897 | * 2. Poll the SRC(SRD) bit until it is set to 0x1. |
| 898 | * 3. Wait until the SRC (SRD) bit returns to 0x0 |
| 899 | * (reset procedure is completed). |
| 900 | */ |
| 901 | #if defined(CONFIG_OMAP44XX) || defined(CONFIG_OMAP54XX) || \ |
Nikita Kiryanov | 5ffdd85 | 2015-07-30 23:56:20 +0300 | [diff] [blame] | 902 | defined(CONFIG_AM33XX) || defined(CONFIG_AM43XX) |
Oleksandr Tyshchenko | 06640ca | 2013-08-06 13:44:16 +0300 | [diff] [blame] | 903 | if (!(readl(&mmc_base->sysctl) & bit)) { |
| 904 | start = get_timer(0); |
| 905 | while (!(readl(&mmc_base->sysctl) & bit)) { |
Jean-Jacques Hiblot | 192e430 | 2018-01-30 16:01:37 +0100 | [diff] [blame] | 906 | if (get_timer(0) - start > MMC_TIMEOUT_MS) |
Oleksandr Tyshchenko | 06640ca | 2013-08-06 13:44:16 +0300 | [diff] [blame] | 907 | return; |
| 908 | } |
| 909 | } |
| 910 | #endif |
Grazvydas Ignotas | ddde188 | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 911 | start = get_timer(0); |
| 912 | while ((readl(&mmc_base->sysctl) & bit) != 0) { |
| 913 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 914 | printf("%s: timedout waiting for sysctl %x to clear\n", |
| 915 | __func__, bit); |
| 916 | return; |
| 917 | } |
| 918 | } |
| 919 | } |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 920 | |
Jean-Jacques Hiblot | cebf059 | 2018-02-23 10:40:18 +0100 | [diff] [blame] | 921 | #ifdef CONFIG_MMC_OMAP_HS_ADMA |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 922 | static void omap_hsmmc_adma_desc(struct mmc *mmc, char *buf, u16 len, bool end) |
| 923 | { |
| 924 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 925 | struct omap_hsmmc_adma_desc *desc; |
| 926 | u8 attr; |
| 927 | |
| 928 | desc = &priv->adma_desc_table[priv->desc_slot]; |
| 929 | |
| 930 | attr = ADMA_DESC_ATTR_VALID | ADMA_DESC_TRANSFER_DATA; |
| 931 | if (!end) |
| 932 | priv->desc_slot++; |
| 933 | else |
| 934 | attr |= ADMA_DESC_ATTR_END; |
| 935 | |
| 936 | desc->len = len; |
| 937 | desc->addr = (u32)buf; |
| 938 | desc->reserved = 0; |
| 939 | desc->attr = attr; |
| 940 | } |
| 941 | |
| 942 | static void omap_hsmmc_prepare_adma_table(struct mmc *mmc, |
| 943 | struct mmc_data *data) |
| 944 | { |
| 945 | uint total_len = data->blocksize * data->blocks; |
| 946 | uint desc_count = DIV_ROUND_UP(total_len, ADMA_MAX_LEN); |
| 947 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 948 | int i = desc_count; |
| 949 | char *buf; |
| 950 | |
| 951 | priv->desc_slot = 0; |
| 952 | priv->adma_desc_table = (struct omap_hsmmc_adma_desc *) |
| 953 | memalign(ARCH_DMA_MINALIGN, desc_count * |
| 954 | sizeof(struct omap_hsmmc_adma_desc)); |
| 955 | |
| 956 | if (data->flags & MMC_DATA_READ) |
| 957 | buf = data->dest; |
| 958 | else |
| 959 | buf = (char *)data->src; |
| 960 | |
| 961 | while (--i) { |
| 962 | omap_hsmmc_adma_desc(mmc, buf, ADMA_MAX_LEN, false); |
| 963 | buf += ADMA_MAX_LEN; |
| 964 | total_len -= ADMA_MAX_LEN; |
| 965 | } |
| 966 | |
| 967 | omap_hsmmc_adma_desc(mmc, buf, total_len, true); |
| 968 | |
| 969 | flush_dcache_range((long)priv->adma_desc_table, |
| 970 | (long)priv->adma_desc_table + |
| 971 | ROUND(desc_count * |
| 972 | sizeof(struct omap_hsmmc_adma_desc), |
| 973 | ARCH_DMA_MINALIGN)); |
| 974 | } |
| 975 | |
| 976 | static void omap_hsmmc_prepare_data(struct mmc *mmc, struct mmc_data *data) |
| 977 | { |
| 978 | struct hsmmc *mmc_base; |
| 979 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 980 | u32 val; |
| 981 | char *buf; |
| 982 | |
| 983 | mmc_base = priv->base_addr; |
| 984 | omap_hsmmc_prepare_adma_table(mmc, data); |
| 985 | |
| 986 | if (data->flags & MMC_DATA_READ) |
| 987 | buf = data->dest; |
| 988 | else |
| 989 | buf = (char *)data->src; |
| 990 | |
| 991 | val = readl(&mmc_base->hctl); |
| 992 | val |= DMA_SELECT; |
| 993 | writel(val, &mmc_base->hctl); |
| 994 | |
| 995 | val = readl(&mmc_base->con); |
| 996 | val |= DMA_MASTER; |
| 997 | writel(val, &mmc_base->con); |
| 998 | |
| 999 | writel((u32)priv->adma_desc_table, &mmc_base->admasal); |
| 1000 | |
| 1001 | flush_dcache_range((u32)buf, |
| 1002 | (u32)buf + |
| 1003 | ROUND(data->blocksize * data->blocks, |
| 1004 | ARCH_DMA_MINALIGN)); |
| 1005 | } |
| 1006 | |
| 1007 | static void omap_hsmmc_dma_cleanup(struct mmc *mmc) |
| 1008 | { |
| 1009 | struct hsmmc *mmc_base; |
| 1010 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 1011 | u32 val; |
| 1012 | |
| 1013 | mmc_base = priv->base_addr; |
| 1014 | |
| 1015 | val = readl(&mmc_base->con); |
| 1016 | val &= ~DMA_MASTER; |
| 1017 | writel(val, &mmc_base->con); |
| 1018 | |
| 1019 | val = readl(&mmc_base->hctl); |
| 1020 | val &= ~DMA_SELECT; |
| 1021 | writel(val, &mmc_base->hctl); |
| 1022 | |
| 1023 | kfree(priv->adma_desc_table); |
| 1024 | } |
| 1025 | #else |
| 1026 | #define omap_hsmmc_adma_desc |
| 1027 | #define omap_hsmmc_prepare_adma_table |
| 1028 | #define omap_hsmmc_prepare_data |
| 1029 | #define omap_hsmmc_dma_cleanup |
| 1030 | #endif |
| 1031 | |
Simon Glass | 5f4bd8c | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 1032 | #if !CONFIG_IS_ENABLED(DM_MMC) |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1033 | 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] | 1034 | struct mmc_data *data) |
| 1035 | { |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1036 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Jean-Jacques Hiblot | 8fc9d3a | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1037 | #else |
| 1038 | static int omap_hsmmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd, |
| 1039 | struct mmc_data *data) |
| 1040 | { |
| 1041 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 1042 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 1043 | struct mmc *mmc = upriv->mmc; |
| 1044 | #endif |
Nikita Kiryanov | 1382286 | 2012-12-03 02:19:43 +0000 | [diff] [blame] | 1045 | struct hsmmc *mmc_base; |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1046 | unsigned int flags, mmc_stat; |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 1047 | ulong start; |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 1048 | priv->last_cmd = cmd->cmdidx; |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1049 | |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1050 | mmc_base = priv->base_addr; |
Kishon Vijay Abraham I | 316e7ae | 2017-09-21 16:51:35 +0200 | [diff] [blame] | 1051 | |
| 1052 | if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION) |
| 1053 | return 0; |
| 1054 | |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 1055 | start = get_timer(0); |
Tom Rini | 32ec325 | 2012-01-30 11:22:25 +0000 | [diff] [blame] | 1056 | while ((readl(&mmc_base->pstate) & (DATI_MASK | CMDI_MASK)) != 0) { |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 1057 | if (get_timer(0) - start > MAX_RETRY_MS) { |
Tom Rini | 32ec325 | 2012-01-30 11:22:25 +0000 | [diff] [blame] | 1058 | printf("%s: timedout waiting on cmd inhibit to clear\n", |
| 1059 | __func__); |
Jean-Jacques Hiblot | a1e7a4d | 2019-07-02 10:53:48 +0200 | [diff] [blame] | 1060 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD); |
| 1061 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRC); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 1062 | return -ETIMEDOUT; |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 1063 | } |
| 1064 | } |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1065 | writel(0xFFFFFFFF, &mmc_base->stat); |
Jean-Jacques Hiblot | a1e7a4d | 2019-07-02 10:53:48 +0200 | [diff] [blame] | 1066 | if (readl(&mmc_base->stat)) { |
| 1067 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD); |
| 1068 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRC); |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 1069 | } |
Jean-Jacques Hiblot | a1e7a4d | 2019-07-02 10:53:48 +0200 | [diff] [blame] | 1070 | |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1071 | /* |
| 1072 | * CMDREG |
| 1073 | * CMDIDX[13:8] : Command index |
| 1074 | * DATAPRNT[5] : Data Present Select |
| 1075 | * ENCMDIDX[4] : Command Index Check Enable |
| 1076 | * ENCMDCRC[3] : Command CRC Check Enable |
| 1077 | * RSPTYP[1:0] |
| 1078 | * 00 = No Response |
| 1079 | * 01 = Length 136 |
| 1080 | * 10 = Length 48 |
| 1081 | * 11 = Length 48 Check busy after response |
| 1082 | */ |
| 1083 | /* Delay added before checking the status of frq change |
| 1084 | * retry not supported by mmc.c(core file) |
| 1085 | */ |
| 1086 | if (cmd->cmdidx == SD_CMD_APP_SEND_SCR) |
| 1087 | udelay(50000); /* wait 50 ms */ |
| 1088 | |
| 1089 | if (!(cmd->resp_type & MMC_RSP_PRESENT)) |
| 1090 | flags = 0; |
| 1091 | else if (cmd->resp_type & MMC_RSP_136) |
| 1092 | flags = RSP_TYPE_LGHT136 | CICE_NOCHECK; |
| 1093 | else if (cmd->resp_type & MMC_RSP_BUSY) |
| 1094 | flags = RSP_TYPE_LGHT48B; |
| 1095 | else |
| 1096 | flags = RSP_TYPE_LGHT48; |
| 1097 | |
| 1098 | /* enable default flags */ |
| 1099 | flags = flags | (CMD_TYPE_NORMAL | CICE_NOCHECK | CCCE_NOCHECK | |
Kishon Vijay Abraham I | 6e54381 | 2017-09-21 16:51:36 +0200 | [diff] [blame] | 1100 | MSBS_SGLEBLK); |
| 1101 | flags &= ~(ACEN_ENABLE | BCE_ENABLE | DE_ENABLE); |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1102 | |
| 1103 | if (cmd->resp_type & MMC_RSP_CRC) |
| 1104 | flags |= CCCE_CHECK; |
| 1105 | if (cmd->resp_type & MMC_RSP_OPCODE) |
| 1106 | flags |= CICE_CHECK; |
| 1107 | |
| 1108 | if (data) { |
| 1109 | if ((cmd->cmdidx == MMC_CMD_READ_MULTIPLE_BLOCK) || |
| 1110 | (cmd->cmdidx == MMC_CMD_WRITE_MULTIPLE_BLOCK)) { |
Kishon Vijay Abraham I | 316e7ae | 2017-09-21 16:51:35 +0200 | [diff] [blame] | 1111 | flags |= (MSBS_MULTIBLK | BCE_ENABLE | ACEN_ENABLE); |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1112 | data->blocksize = 512; |
| 1113 | writel(data->blocksize | (data->blocks << 16), |
| 1114 | &mmc_base->blk); |
| 1115 | } else |
| 1116 | writel(data->blocksize | NBLK_STPCNT, &mmc_base->blk); |
| 1117 | |
| 1118 | if (data->flags & MMC_DATA_READ) |
| 1119 | flags |= (DP_DATA | DDIR_READ); |
| 1120 | else |
| 1121 | flags |= (DP_DATA | DDIR_WRITE); |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 1122 | |
Jean-Jacques Hiblot | cebf059 | 2018-02-23 10:40:18 +0100 | [diff] [blame] | 1123 | #ifdef CONFIG_MMC_OMAP_HS_ADMA |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 1124 | if ((priv->controller_flags & OMAP_HSMMC_USE_ADMA) && |
| 1125 | !mmc_is_tuning_cmd(cmd->cmdidx)) { |
| 1126 | omap_hsmmc_prepare_data(mmc, data); |
| 1127 | flags |= DE_ENABLE; |
| 1128 | } |
| 1129 | #endif |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
Jean-Jacques Hiblot | a420d7d | 2018-01-30 16:01:36 +0100 | [diff] [blame] | 1132 | mmc_enable_irq(mmc, cmd); |
| 1133 | |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1134 | writel(cmd->cmdarg, &mmc_base->arg); |
Lubomir Popov | 19df412 | 2013-08-14 18:59:18 +0300 | [diff] [blame] | 1135 | udelay(20); /* To fix "No status update" error on eMMC */ |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1136 | writel((cmd->cmdidx << 24) | flags, &mmc_base->cmd); |
| 1137 | |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 1138 | start = get_timer(0); |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1139 | do { |
| 1140 | mmc_stat = readl(&mmc_base->stat); |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 1141 | if (get_timer(start) > MAX_RETRY_MS) { |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 1142 | printf("%s : timeout: No status update\n", __func__); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 1143 | return -ETIMEDOUT; |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 1144 | } |
| 1145 | } while (!mmc_stat); |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1146 | |
Grazvydas Ignotas | ddde188 | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 1147 | if ((mmc_stat & IE_CTO) != 0) { |
| 1148 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRC); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 1149 | return -ETIMEDOUT; |
Grazvydas Ignotas | ddde188 | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 1150 | } else if ((mmc_stat & ERRI_MASK) != 0) |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1151 | return -1; |
| 1152 | |
| 1153 | if (mmc_stat & CC_MASK) { |
| 1154 | writel(CC_MASK, &mmc_base->stat); |
| 1155 | if (cmd->resp_type & MMC_RSP_PRESENT) { |
| 1156 | if (cmd->resp_type & MMC_RSP_136) { |
| 1157 | /* response type 2 */ |
| 1158 | cmd->response[3] = readl(&mmc_base->rsp10); |
| 1159 | cmd->response[2] = readl(&mmc_base->rsp32); |
| 1160 | cmd->response[1] = readl(&mmc_base->rsp54); |
| 1161 | cmd->response[0] = readl(&mmc_base->rsp76); |
| 1162 | } else |
| 1163 | /* response types 1, 1b, 3, 4, 5, 6 */ |
| 1164 | cmd->response[0] = readl(&mmc_base->rsp10); |
| 1165 | } |
| 1166 | } |
| 1167 | |
Jean-Jacques Hiblot | cebf059 | 2018-02-23 10:40:18 +0100 | [diff] [blame] | 1168 | #ifdef CONFIG_MMC_OMAP_HS_ADMA |
Kishon Vijay Abraham I | 826be2a | 2017-09-21 16:51:34 +0200 | [diff] [blame] | 1169 | if ((priv->controller_flags & OMAP_HSMMC_USE_ADMA) && data && |
| 1170 | !mmc_is_tuning_cmd(cmd->cmdidx)) { |
| 1171 | u32 sz_mb, timeout; |
| 1172 | |
| 1173 | if (mmc_stat & IE_ADMAE) { |
| 1174 | omap_hsmmc_dma_cleanup(mmc); |
| 1175 | return -EIO; |
| 1176 | } |
| 1177 | |
| 1178 | sz_mb = DIV_ROUND_UP(data->blocksize * data->blocks, 1 << 20); |
| 1179 | timeout = sz_mb * DMA_TIMEOUT_PER_MB; |
| 1180 | if (timeout < MAX_RETRY_MS) |
| 1181 | timeout = MAX_RETRY_MS; |
| 1182 | |
| 1183 | start = get_timer(0); |
| 1184 | do { |
| 1185 | mmc_stat = readl(&mmc_base->stat); |
| 1186 | if (mmc_stat & TC_MASK) { |
| 1187 | writel(readl(&mmc_base->stat) | TC_MASK, |
| 1188 | &mmc_base->stat); |
| 1189 | break; |
| 1190 | } |
| 1191 | if (get_timer(start) > timeout) { |
| 1192 | printf("%s : DMA timeout: No status update\n", |
| 1193 | __func__); |
| 1194 | return -ETIMEDOUT; |
| 1195 | } |
| 1196 | } while (1); |
| 1197 | |
| 1198 | omap_hsmmc_dma_cleanup(mmc); |
| 1199 | return 0; |
| 1200 | } |
| 1201 | #endif |
| 1202 | |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1203 | if (data && (data->flags & MMC_DATA_READ)) { |
| 1204 | mmc_read_data(mmc_base, data->dest, |
| 1205 | data->blocksize * data->blocks); |
| 1206 | } else if (data && (data->flags & MMC_DATA_WRITE)) { |
| 1207 | mmc_write_data(mmc_base, data->src, |
| 1208 | data->blocksize * data->blocks); |
| 1209 | } |
| 1210 | return 0; |
| 1211 | } |
| 1212 | |
Sricharan | f72611f | 2011-11-15 09:49:53 -0500 | [diff] [blame] | 1213 | 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] | 1214 | { |
| 1215 | unsigned int *output_buf = (unsigned int *)buf; |
| 1216 | unsigned int mmc_stat; |
| 1217 | unsigned int count; |
| 1218 | |
| 1219 | /* |
| 1220 | * Start Polled Read |
| 1221 | */ |
| 1222 | count = (size > MMCSD_SECTOR_SIZE) ? MMCSD_SECTOR_SIZE : size; |
| 1223 | count /= 4; |
| 1224 | |
| 1225 | while (size) { |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 1226 | ulong start = get_timer(0); |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1227 | do { |
| 1228 | mmc_stat = readl(&mmc_base->stat); |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 1229 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 1230 | printf("%s: timedout waiting for status!\n", |
| 1231 | __func__); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 1232 | return -ETIMEDOUT; |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 1233 | } |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1234 | } while (mmc_stat == 0); |
| 1235 | |
Grazvydas Ignotas | ddde188 | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 1236 | if ((mmc_stat & (IE_DTO | IE_DCRC | IE_DEB)) != 0) |
| 1237 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD); |
| 1238 | |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1239 | if ((mmc_stat & ERRI_MASK) != 0) |
| 1240 | return 1; |
| 1241 | |
| 1242 | if (mmc_stat & BRR_MASK) { |
| 1243 | unsigned int k; |
| 1244 | |
| 1245 | writel(readl(&mmc_base->stat) | BRR_MASK, |
| 1246 | &mmc_base->stat); |
| 1247 | for (k = 0; k < count; k++) { |
| 1248 | *output_buf = readl(&mmc_base->data); |
| 1249 | output_buf++; |
| 1250 | } |
| 1251 | size -= (count*4); |
| 1252 | } |
| 1253 | |
| 1254 | if (mmc_stat & BWR_MASK) |
| 1255 | writel(readl(&mmc_base->stat) | BWR_MASK, |
| 1256 | &mmc_base->stat); |
| 1257 | |
| 1258 | if (mmc_stat & TC_MASK) { |
| 1259 | writel(readl(&mmc_base->stat) | TC_MASK, |
| 1260 | &mmc_base->stat); |
| 1261 | break; |
| 1262 | } |
| 1263 | } |
| 1264 | return 0; |
| 1265 | } |
| 1266 | |
Jean-Jacques Hiblot | 9882155 | 2018-02-23 10:40:17 +0100 | [diff] [blame] | 1267 | #if CONFIG_IS_ENABLED(MMC_WRITE) |
Sricharan | f72611f | 2011-11-15 09:49:53 -0500 | [diff] [blame] | 1268 | static int mmc_write_data(struct hsmmc *mmc_base, const char *buf, |
Jean-Jacques Hiblot | 9882155 | 2018-02-23 10:40:17 +0100 | [diff] [blame] | 1269 | unsigned int size) |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1270 | { |
| 1271 | unsigned int *input_buf = (unsigned int *)buf; |
| 1272 | unsigned int mmc_stat; |
| 1273 | unsigned int count; |
| 1274 | |
| 1275 | /* |
Lubomir Popov | 19df412 | 2013-08-14 18:59:18 +0300 | [diff] [blame] | 1276 | * Start Polled Write |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1277 | */ |
| 1278 | count = (size > MMCSD_SECTOR_SIZE) ? MMCSD_SECTOR_SIZE : size; |
| 1279 | count /= 4; |
| 1280 | |
| 1281 | while (size) { |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 1282 | ulong start = get_timer(0); |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1283 | do { |
| 1284 | mmc_stat = readl(&mmc_base->stat); |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 1285 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 1286 | printf("%s: timedout waiting for status!\n", |
| 1287 | __func__); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 1288 | return -ETIMEDOUT; |
Nishanth Menon | d3bfaac | 2010-11-19 11:18:12 -0500 | [diff] [blame] | 1289 | } |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1290 | } while (mmc_stat == 0); |
| 1291 | |
Grazvydas Ignotas | ddde188 | 2012-03-19 12:12:06 +0000 | [diff] [blame] | 1292 | if ((mmc_stat & (IE_DTO | IE_DCRC | IE_DEB)) != 0) |
| 1293 | mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD); |
| 1294 | |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1295 | if ((mmc_stat & ERRI_MASK) != 0) |
| 1296 | return 1; |
| 1297 | |
| 1298 | if (mmc_stat & BWR_MASK) { |
| 1299 | unsigned int k; |
| 1300 | |
| 1301 | writel(readl(&mmc_base->stat) | BWR_MASK, |
| 1302 | &mmc_base->stat); |
| 1303 | for (k = 0; k < count; k++) { |
| 1304 | writel(*input_buf, &mmc_base->data); |
| 1305 | input_buf++; |
| 1306 | } |
| 1307 | size -= (count*4); |
| 1308 | } |
| 1309 | |
| 1310 | if (mmc_stat & BRR_MASK) |
| 1311 | writel(readl(&mmc_base->stat) | BRR_MASK, |
| 1312 | &mmc_base->stat); |
| 1313 | |
| 1314 | if (mmc_stat & TC_MASK) { |
| 1315 | writel(readl(&mmc_base->stat) | TC_MASK, |
| 1316 | &mmc_base->stat); |
| 1317 | break; |
| 1318 | } |
| 1319 | } |
| 1320 | return 0; |
| 1321 | } |
Jean-Jacques Hiblot | 9882155 | 2018-02-23 10:40:17 +0100 | [diff] [blame] | 1322 | #else |
| 1323 | static int mmc_write_data(struct hsmmc *mmc_base, const char *buf, |
| 1324 | unsigned int size) |
| 1325 | { |
| 1326 | return -ENOTSUPP; |
| 1327 | } |
| 1328 | #endif |
Jean-Jacques Hiblot | 7fe2f19 | 2018-01-30 16:01:30 +0100 | [diff] [blame] | 1329 | static void omap_hsmmc_stop_clock(struct hsmmc *mmc_base) |
| 1330 | { |
| 1331 | writel(readl(&mmc_base->sysctl) & ~CEN_ENABLE, &mmc_base->sysctl); |
| 1332 | } |
| 1333 | |
| 1334 | static void omap_hsmmc_start_clock(struct hsmmc *mmc_base) |
| 1335 | { |
| 1336 | writel(readl(&mmc_base->sysctl) | CEN_ENABLE, &mmc_base->sysctl); |
| 1337 | } |
| 1338 | |
| 1339 | static void omap_hsmmc_set_clock(struct mmc *mmc) |
| 1340 | { |
| 1341 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 1342 | struct hsmmc *mmc_base; |
| 1343 | unsigned int dsor = 0; |
| 1344 | ulong start; |
| 1345 | |
| 1346 | mmc_base = priv->base_addr; |
| 1347 | omap_hsmmc_stop_clock(mmc_base); |
| 1348 | |
| 1349 | /* TODO: Is setting DTO required here? */ |
| 1350 | mmc_reg_out(&mmc_base->sysctl, (ICE_MASK | DTO_MASK), |
| 1351 | (ICE_STOP | DTO_15THDTO)); |
| 1352 | |
| 1353 | if (mmc->clock != 0) { |
| 1354 | dsor = DIV_ROUND_UP(MMC_CLOCK_REFERENCE * 1000000, mmc->clock); |
| 1355 | if (dsor > CLKD_MAX) |
| 1356 | dsor = CLKD_MAX; |
| 1357 | } else { |
| 1358 | dsor = CLKD_MAX; |
| 1359 | } |
| 1360 | |
| 1361 | mmc_reg_out(&mmc_base->sysctl, ICE_MASK | CLKD_MASK, |
| 1362 | (dsor << CLKD_OFFSET) | ICE_OSCILLATE); |
| 1363 | |
| 1364 | start = get_timer(0); |
| 1365 | while ((readl(&mmc_base->sysctl) & ICS_MASK) == ICS_NOTREADY) { |
| 1366 | if (get_timer(0) - start > MAX_RETRY_MS) { |
| 1367 | printf("%s: timedout waiting for ics!\n", __func__); |
| 1368 | return; |
| 1369 | } |
| 1370 | } |
| 1371 | |
Jean-Jacques Hiblot | 6ce31e4 | 2018-01-30 16:01:43 +0100 | [diff] [blame] | 1372 | priv->clock = MMC_CLOCK_REFERENCE * 1000000 / dsor; |
| 1373 | mmc->clock = priv->clock; |
Jean-Jacques Hiblot | 7fe2f19 | 2018-01-30 16:01:30 +0100 | [diff] [blame] | 1374 | omap_hsmmc_start_clock(mmc_base); |
| 1375 | } |
| 1376 | |
Kishon Vijay Abraham I | 2e18c9b | 2018-01-30 16:01:31 +0100 | [diff] [blame] | 1377 | static void omap_hsmmc_set_bus_width(struct mmc *mmc) |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1378 | { |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1379 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Nikita Kiryanov | 1382286 | 2012-12-03 02:19:43 +0000 | [diff] [blame] | 1380 | struct hsmmc *mmc_base; |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1381 | |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1382 | mmc_base = priv->base_addr; |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1383 | /* configue bus width */ |
| 1384 | switch (mmc->bus_width) { |
| 1385 | case 8: |
| 1386 | writel(readl(&mmc_base->con) | DTW_8_BITMODE, |
| 1387 | &mmc_base->con); |
| 1388 | break; |
| 1389 | |
| 1390 | case 4: |
| 1391 | writel(readl(&mmc_base->con) & ~DTW_8_BITMODE, |
| 1392 | &mmc_base->con); |
| 1393 | writel(readl(&mmc_base->hctl) | DTW_4_BITMODE, |
| 1394 | &mmc_base->hctl); |
| 1395 | break; |
| 1396 | |
| 1397 | case 1: |
| 1398 | default: |
| 1399 | writel(readl(&mmc_base->con) & ~DTW_8_BITMODE, |
| 1400 | &mmc_base->con); |
| 1401 | writel(readl(&mmc_base->hctl) & ~DTW_4_BITMODE, |
| 1402 | &mmc_base->hctl); |
| 1403 | break; |
| 1404 | } |
| 1405 | |
Kishon Vijay Abraham I | 2e18c9b | 2018-01-30 16:01:31 +0100 | [diff] [blame] | 1406 | priv->bus_width = mmc->bus_width; |
| 1407 | } |
| 1408 | |
| 1409 | #if !CONFIG_IS_ENABLED(DM_MMC) |
| 1410 | static int omap_hsmmc_set_ios(struct mmc *mmc) |
| 1411 | { |
| 1412 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 1413 | #else |
| 1414 | static int omap_hsmmc_set_ios(struct udevice *dev) |
| 1415 | { |
| 1416 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
| 1417 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 1418 | struct mmc *mmc = upriv->mmc; |
| 1419 | #endif |
Kishon Vijay Abraham I | e1f25c0 | 2018-01-30 16:01:45 +0100 | [diff] [blame] | 1420 | struct hsmmc *mmc_base = priv->base_addr; |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 1421 | int ret = 0; |
Kishon Vijay Abraham I | 2e18c9b | 2018-01-30 16:01:31 +0100 | [diff] [blame] | 1422 | |
| 1423 | if (priv->bus_width != mmc->bus_width) |
| 1424 | omap_hsmmc_set_bus_width(mmc); |
| 1425 | |
Jean-Jacques Hiblot | 7fe2f19 | 2018-01-30 16:01:30 +0100 | [diff] [blame] | 1426 | if (priv->clock != mmc->clock) |
| 1427 | omap_hsmmc_set_clock(mmc); |
Jaehoon Chung | b6cd1d3 | 2016-12-30 15:30:16 +0900 | [diff] [blame] | 1428 | |
Kishon Vijay Abraham I | e1f25c0 | 2018-01-30 16:01:45 +0100 | [diff] [blame] | 1429 | if (mmc->clk_disable) |
| 1430 | omap_hsmmc_stop_clock(mmc_base); |
| 1431 | else |
| 1432 | omap_hsmmc_start_clock(mmc_base); |
| 1433 | |
Jean-Jacques Hiblot | cf38d4e | 2018-01-30 16:01:33 +0100 | [diff] [blame] | 1434 | #if CONFIG_IS_ENABLED(DM_MMC) |
| 1435 | if (priv->mode != mmc->selected_mode) |
| 1436 | omap_hsmmc_set_timing(mmc); |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 1437 | |
| 1438 | #if CONFIG_IS_ENABLED(MMC_IO_VOLTAGE) |
| 1439 | if (priv->signal_voltage != mmc->signal_voltage) |
| 1440 | ret = omap_hsmmc_set_signal_voltage(mmc); |
Jean-Jacques Hiblot | cf38d4e | 2018-01-30 16:01:33 +0100 | [diff] [blame] | 1441 | #endif |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 1442 | #endif |
| 1443 | return ret; |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1446 | #ifdef OMAP_HSMMC_USE_GPIO |
Simon Glass | 5f4bd8c | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 1447 | #if CONFIG_IS_ENABLED(DM_MMC) |
Jean-Jacques Hiblot | 8fc9d3a | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1448 | static int omap_hsmmc_getcd(struct udevice *dev) |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1449 | { |
Adam Ford | 6122af4 | 2018-08-21 07:16:56 -0500 | [diff] [blame] | 1450 | int value = -1; |
| 1451 | #if CONFIG_IS_ENABLED(DM_GPIO) |
Adam Ford | ac740ff | 2018-09-08 08:16:23 -0500 | [diff] [blame] | 1452 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1453 | value = dm_gpio_get_value(&priv->cd_gpio); |
Adam Ford | 6122af4 | 2018-08-21 07:16:56 -0500 | [diff] [blame] | 1454 | #endif |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1455 | /* if no CD return as 1 */ |
| 1456 | if (value < 0) |
| 1457 | return 1; |
| 1458 | |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1459 | return value; |
| 1460 | } |
| 1461 | |
Jean-Jacques Hiblot | 8fc9d3a | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1462 | static int omap_hsmmc_getwp(struct udevice *dev) |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1463 | { |
Adam Ford | 6122af4 | 2018-08-21 07:16:56 -0500 | [diff] [blame] | 1464 | int value = 0; |
| 1465 | #if CONFIG_IS_ENABLED(DM_GPIO) |
Jean-Jacques Hiblot | 8fc9d3a | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1466 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1467 | value = dm_gpio_get_value(&priv->wp_gpio); |
Adam Ford | 6122af4 | 2018-08-21 07:16:56 -0500 | [diff] [blame] | 1468 | #endif |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1469 | /* if no WP return as 0 */ |
| 1470 | if (value < 0) |
| 1471 | return 0; |
| 1472 | return value; |
| 1473 | } |
| 1474 | #else |
| 1475 | static int omap_hsmmc_getcd(struct mmc *mmc) |
| 1476 | { |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1477 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1478 | int cd_gpio; |
| 1479 | |
| 1480 | /* if no CD return as 1 */ |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1481 | cd_gpio = priv->cd_gpio; |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1482 | if (cd_gpio < 0) |
| 1483 | return 1; |
| 1484 | |
Igor Grinberg | 2f4e095 | 2014-11-03 11:32:23 +0200 | [diff] [blame] | 1485 | /* NOTE: assumes card detect signal is active-low */ |
| 1486 | return !gpio_get_value(cd_gpio); |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | static int omap_hsmmc_getwp(struct mmc *mmc) |
| 1490 | { |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1491 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1492 | int wp_gpio; |
| 1493 | |
| 1494 | /* if no WP return as 0 */ |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1495 | wp_gpio = priv->wp_gpio; |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1496 | if (wp_gpio < 0) |
| 1497 | return 0; |
| 1498 | |
Igor Grinberg | 2f4e095 | 2014-11-03 11:32:23 +0200 | [diff] [blame] | 1499 | /* NOTE: assumes write protect signal is active-high */ |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1500 | return gpio_get_value(wp_gpio); |
| 1501 | } |
| 1502 | #endif |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1503 | #endif |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1504 | |
Simon Glass | 5f4bd8c | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 1505 | #if CONFIG_IS_ENABLED(DM_MMC) |
Jean-Jacques Hiblot | 8fc9d3a | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1506 | static const struct dm_mmc_ops omap_hsmmc_ops = { |
| 1507 | .send_cmd = omap_hsmmc_send_cmd, |
| 1508 | .set_ios = omap_hsmmc_set_ios, |
| 1509 | #ifdef OMAP_HSMMC_USE_GPIO |
| 1510 | .get_cd = omap_hsmmc_getcd, |
| 1511 | .get_wp = omap_hsmmc_getwp, |
| 1512 | #endif |
Jean-Jacques Hiblot | f0f821b | 2018-01-30 16:01:35 +0100 | [diff] [blame] | 1513 | #ifdef MMC_SUPPORTS_TUNING |
| 1514 | .execute_tuning = omap_hsmmc_execute_tuning, |
| 1515 | #endif |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 1516 | .wait_dat0 = omap_hsmmc_wait_dat0, |
Jean-Jacques Hiblot | 8fc9d3a | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1517 | }; |
| 1518 | #else |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1519 | static const struct mmc_ops omap_hsmmc_ops = { |
| 1520 | .send_cmd = omap_hsmmc_send_cmd, |
| 1521 | .set_ios = omap_hsmmc_set_ios, |
| 1522 | .init = omap_hsmmc_init_setup, |
| 1523 | #ifdef OMAP_HSMMC_USE_GPIO |
| 1524 | .getcd = omap_hsmmc_getcd, |
| 1525 | .getwp = omap_hsmmc_getwp, |
| 1526 | #endif |
| 1527 | }; |
Jean-Jacques Hiblot | 8fc9d3a | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 1528 | #endif |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1529 | |
Simon Glass | 5f4bd8c | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 1530 | #if !CONFIG_IS_ENABLED(DM_MMC) |
Nikita Kiryanov | 4be9dbc | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 1531 | int omap_mmc_init(int dev_index, uint host_caps_mask, uint f_max, int cd_gpio, |
| 1532 | int wp_gpio) |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1533 | { |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1534 | struct mmc *mmc; |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1535 | struct omap_hsmmc_data *priv; |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1536 | struct mmc_config *cfg; |
| 1537 | uint host_caps_val; |
| 1538 | |
Alex Kiernan | 4b9cb77 | 2018-02-09 15:24:38 +0000 | [diff] [blame] | 1539 | priv = calloc(1, sizeof(*priv)); |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1540 | if (priv == NULL) |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1541 | return -1; |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1542 | |
Rob Herring | 5fd3edd | 2015-03-23 17:56:59 -0500 | [diff] [blame] | 1543 | 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] | 1544 | |
| 1545 | switch (dev_index) { |
| 1546 | case 0: |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1547 | priv->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE; |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1548 | break; |
Tom Rini | fd6e294 | 2011-10-12 06:20:50 +0000 | [diff] [blame] | 1549 | #ifdef OMAP_HSMMC2_BASE |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1550 | case 1: |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1551 | priv->base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE; |
Lubomir Popov | 19df412 | 2013-08-14 18:59:18 +0300 | [diff] [blame] | 1552 | #if (defined(CONFIG_OMAP44XX) || defined(CONFIG_OMAP54XX) || \ |
Nishanth Menon | 813fe9d | 2016-11-29 15:22:00 +0530 | [diff] [blame] | 1553 | defined(CONFIG_DRA7XX) || defined(CONFIG_AM33XX) || \ |
Roger Quadros | 44157de | 2015-09-19 16:26:53 +0530 | [diff] [blame] | 1554 | defined(CONFIG_AM43XX) || defined(CONFIG_SOC_KEYSTONE)) && \ |
| 1555 | defined(CONFIG_HSMMC2_8BIT) |
Lubomir Popov | 19df412 | 2013-08-14 18:59:18 +0300 | [diff] [blame] | 1556 | /* Enable 8-bit interface for eMMC on OMAP4/5 or DRA7XX */ |
| 1557 | host_caps_val |= MMC_MODE_8BIT; |
| 1558 | #endif |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1559 | break; |
Tom Rini | fd6e294 | 2011-10-12 06:20:50 +0000 | [diff] [blame] | 1560 | #endif |
| 1561 | #ifdef OMAP_HSMMC3_BASE |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1562 | case 2: |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1563 | priv->base_addr = (struct hsmmc *)OMAP_HSMMC3_BASE; |
Nishanth Menon | 813fe9d | 2016-11-29 15:22:00 +0530 | [diff] [blame] | 1564 | #if defined(CONFIG_DRA7XX) && defined(CONFIG_HSMMC3_8BIT) |
Lubomir Popov | 19df412 | 2013-08-14 18:59:18 +0300 | [diff] [blame] | 1565 | /* Enable 8-bit interface for eMMC on DRA7XX */ |
| 1566 | host_caps_val |= MMC_MODE_8BIT; |
| 1567 | #endif |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1568 | break; |
Tom Rini | fd6e294 | 2011-10-12 06:20:50 +0000 | [diff] [blame] | 1569 | #endif |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1570 | default: |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1571 | priv->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE; |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1572 | return 1; |
| 1573 | } |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1574 | #ifdef OMAP_HSMMC_USE_GPIO |
| 1575 | /* 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] | 1576 | priv->cd_gpio = omap_mmc_setup_gpio_in(cd_gpio, "mmc_cd"); |
| 1577 | priv->wp_gpio = omap_mmc_setup_gpio_in(wp_gpio, "mmc_wp"); |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 1578 | #endif |
Peter Korsgaard | 47c6b2a | 2013-03-21 04:00:04 +0000 | [diff] [blame] | 1579 | |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1580 | cfg = &priv->cfg; |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1581 | |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1582 | cfg->name = "OMAP SD/MMC"; |
| 1583 | cfg->ops = &omap_hsmmc_ops; |
| 1584 | |
| 1585 | cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195; |
| 1586 | cfg->host_caps = host_caps_val & ~host_caps_mask; |
| 1587 | |
| 1588 | cfg->f_min = 400000; |
Jonathan Solnit | a9b0556 | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 1589 | |
| 1590 | if (f_max != 0) |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1591 | cfg->f_max = f_max; |
Jonathan Solnit | a9b0556 | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 1592 | else { |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1593 | if (cfg->host_caps & MMC_MODE_HS) { |
| 1594 | if (cfg->host_caps & MMC_MODE_HS_52MHz) |
| 1595 | cfg->f_max = 52000000; |
Jonathan Solnit | a9b0556 | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 1596 | else |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1597 | cfg->f_max = 26000000; |
Jonathan Solnit | a9b0556 | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 1598 | } else |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1599 | cfg->f_max = 20000000; |
Jonathan Solnit | a9b0556 | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 1600 | } |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1601 | |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1602 | cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; |
John Rigby | f2f4366 | 2011-04-18 05:50:08 +0000 | [diff] [blame] | 1603 | |
John Rigby | 91fcc4b | 2011-04-19 05:48:14 +0000 | [diff] [blame] | 1604 | #if defined(CONFIG_OMAP34XX) |
| 1605 | /* |
| 1606 | * Silicon revs 2.1 and older do not support multiblock transfers. |
| 1607 | */ |
| 1608 | if ((get_cpu_family() == CPU_OMAP34XX) && (get_cpu_rev() <= CPU_3XX_ES21)) |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1609 | cfg->b_max = 1; |
John Rigby | 91fcc4b | 2011-04-19 05:48:14 +0000 | [diff] [blame] | 1610 | #endif |
Kishon Vijay Abraham I | 8c2efe9 | 2018-01-30 16:01:41 +0100 | [diff] [blame] | 1611 | |
Jean-Jacques Hiblot | d58ef8e | 2017-03-22 16:00:31 +0100 | [diff] [blame] | 1612 | mmc = mmc_create(cfg, priv); |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 1613 | if (mmc == NULL) |
| 1614 | return -1; |
Sukumar Ghorai | c53f5e5 | 2010-09-18 20:32:33 -0700 | [diff] [blame] | 1615 | |
| 1616 | return 0; |
| 1617 | } |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1618 | #else |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 1619 | |
| 1620 | #ifdef CONFIG_IODELAY_RECALIBRATION |
| 1621 | static struct pad_conf_entry * |
| 1622 | omap_hsmmc_get_pad_conf_entry(const fdt32_t *pinctrl, int count) |
| 1623 | { |
| 1624 | int index = 0; |
| 1625 | struct pad_conf_entry *padconf; |
| 1626 | |
| 1627 | padconf = (struct pad_conf_entry *)malloc(sizeof(*padconf) * count); |
| 1628 | if (!padconf) { |
| 1629 | debug("failed to allocate memory\n"); |
| 1630 | return 0; |
| 1631 | } |
| 1632 | |
| 1633 | while (index < count) { |
| 1634 | padconf[index].offset = fdt32_to_cpu(pinctrl[2 * index]); |
| 1635 | padconf[index].val = fdt32_to_cpu(pinctrl[2 * index + 1]); |
| 1636 | index++; |
| 1637 | } |
| 1638 | |
| 1639 | return padconf; |
| 1640 | } |
| 1641 | |
| 1642 | static struct iodelay_cfg_entry * |
| 1643 | omap_hsmmc_get_iodelay_cfg_entry(const fdt32_t *pinctrl, int count) |
| 1644 | { |
| 1645 | int index = 0; |
| 1646 | struct iodelay_cfg_entry *iodelay; |
| 1647 | |
| 1648 | iodelay = (struct iodelay_cfg_entry *)malloc(sizeof(*iodelay) * count); |
| 1649 | if (!iodelay) { |
| 1650 | debug("failed to allocate memory\n"); |
| 1651 | return 0; |
| 1652 | } |
| 1653 | |
| 1654 | while (index < count) { |
| 1655 | iodelay[index].offset = fdt32_to_cpu(pinctrl[3 * index]); |
| 1656 | iodelay[index].a_delay = fdt32_to_cpu(pinctrl[3 * index + 1]); |
| 1657 | iodelay[index].g_delay = fdt32_to_cpu(pinctrl[3 * index + 2]); |
| 1658 | index++; |
| 1659 | } |
| 1660 | |
| 1661 | return iodelay; |
| 1662 | } |
| 1663 | |
| 1664 | static const fdt32_t *omap_hsmmc_get_pinctrl_entry(u32 phandle, |
| 1665 | const char *name, int *len) |
| 1666 | { |
| 1667 | const void *fdt = gd->fdt_blob; |
| 1668 | int offset; |
| 1669 | const fdt32_t *pinctrl; |
| 1670 | |
| 1671 | offset = fdt_node_offset_by_phandle(fdt, phandle); |
| 1672 | if (offset < 0) { |
| 1673 | debug("failed to get pinctrl node %s.\n", |
| 1674 | fdt_strerror(offset)); |
| 1675 | return 0; |
| 1676 | } |
| 1677 | |
| 1678 | pinctrl = fdt_getprop(fdt, offset, name, len); |
| 1679 | if (!pinctrl) { |
| 1680 | debug("failed to get property %s\n", name); |
| 1681 | return 0; |
| 1682 | } |
| 1683 | |
| 1684 | return pinctrl; |
| 1685 | } |
| 1686 | |
| 1687 | static uint32_t omap_hsmmc_get_pad_conf_phandle(struct mmc *mmc, |
| 1688 | char *prop_name) |
| 1689 | { |
| 1690 | const void *fdt = gd->fdt_blob; |
| 1691 | const __be32 *phandle; |
| 1692 | int node = dev_of_offset(mmc->dev); |
| 1693 | |
| 1694 | phandle = fdt_getprop(fdt, node, prop_name, NULL); |
| 1695 | if (!phandle) { |
| 1696 | debug("failed to get property %s\n", prop_name); |
| 1697 | return 0; |
| 1698 | } |
| 1699 | |
| 1700 | return fdt32_to_cpu(*phandle); |
| 1701 | } |
| 1702 | |
| 1703 | static uint32_t omap_hsmmc_get_iodelay_phandle(struct mmc *mmc, |
| 1704 | char *prop_name) |
| 1705 | { |
| 1706 | const void *fdt = gd->fdt_blob; |
| 1707 | const __be32 *phandle; |
| 1708 | int len; |
| 1709 | int count; |
| 1710 | int node = dev_of_offset(mmc->dev); |
| 1711 | |
| 1712 | phandle = fdt_getprop(fdt, node, prop_name, &len); |
| 1713 | if (!phandle) { |
| 1714 | debug("failed to get property %s\n", prop_name); |
| 1715 | return 0; |
| 1716 | } |
| 1717 | |
| 1718 | /* No manual mode iodelay values if count < 2 */ |
| 1719 | count = len / sizeof(*phandle); |
| 1720 | if (count < 2) |
| 1721 | return 0; |
| 1722 | |
| 1723 | return fdt32_to_cpu(*(phandle + 1)); |
| 1724 | } |
| 1725 | |
| 1726 | static struct pad_conf_entry * |
| 1727 | omap_hsmmc_get_pad_conf(struct mmc *mmc, char *prop_name, int *npads) |
| 1728 | { |
| 1729 | int len; |
| 1730 | int count; |
| 1731 | struct pad_conf_entry *padconf; |
| 1732 | u32 phandle; |
| 1733 | const fdt32_t *pinctrl; |
| 1734 | |
| 1735 | phandle = omap_hsmmc_get_pad_conf_phandle(mmc, prop_name); |
| 1736 | if (!phandle) |
| 1737 | return ERR_PTR(-EINVAL); |
| 1738 | |
| 1739 | pinctrl = omap_hsmmc_get_pinctrl_entry(phandle, "pinctrl-single,pins", |
| 1740 | &len); |
| 1741 | if (!pinctrl) |
| 1742 | return ERR_PTR(-EINVAL); |
| 1743 | |
| 1744 | count = (len / sizeof(*pinctrl)) / 2; |
| 1745 | padconf = omap_hsmmc_get_pad_conf_entry(pinctrl, count); |
| 1746 | if (!padconf) |
| 1747 | return ERR_PTR(-EINVAL); |
| 1748 | |
| 1749 | *npads = count; |
| 1750 | |
| 1751 | return padconf; |
| 1752 | } |
| 1753 | |
| 1754 | static struct iodelay_cfg_entry * |
| 1755 | omap_hsmmc_get_iodelay(struct mmc *mmc, char *prop_name, int *niodelay) |
| 1756 | { |
| 1757 | int len; |
| 1758 | int count; |
| 1759 | struct iodelay_cfg_entry *iodelay; |
| 1760 | u32 phandle; |
| 1761 | const fdt32_t *pinctrl; |
| 1762 | |
| 1763 | phandle = omap_hsmmc_get_iodelay_phandle(mmc, prop_name); |
| 1764 | /* Not all modes have manual mode iodelay values. So its not fatal */ |
| 1765 | if (!phandle) |
| 1766 | return 0; |
| 1767 | |
| 1768 | pinctrl = omap_hsmmc_get_pinctrl_entry(phandle, "pinctrl-pin-array", |
| 1769 | &len); |
| 1770 | if (!pinctrl) |
| 1771 | return ERR_PTR(-EINVAL); |
| 1772 | |
| 1773 | count = (len / sizeof(*pinctrl)) / 3; |
| 1774 | iodelay = omap_hsmmc_get_iodelay_cfg_entry(pinctrl, count); |
| 1775 | if (!iodelay) |
| 1776 | return ERR_PTR(-EINVAL); |
| 1777 | |
| 1778 | *niodelay = count; |
| 1779 | |
| 1780 | return iodelay; |
| 1781 | } |
| 1782 | |
| 1783 | static struct omap_hsmmc_pinctrl_state * |
| 1784 | omap_hsmmc_get_pinctrl_by_mode(struct mmc *mmc, char *mode) |
| 1785 | { |
| 1786 | int index; |
| 1787 | int npads = 0; |
| 1788 | int niodelays = 0; |
| 1789 | const void *fdt = gd->fdt_blob; |
| 1790 | int node = dev_of_offset(mmc->dev); |
| 1791 | char prop_name[11]; |
| 1792 | struct omap_hsmmc_pinctrl_state *pinctrl_state; |
| 1793 | |
| 1794 | pinctrl_state = (struct omap_hsmmc_pinctrl_state *) |
| 1795 | malloc(sizeof(*pinctrl_state)); |
| 1796 | if (!pinctrl_state) { |
| 1797 | debug("failed to allocate memory\n"); |
| 1798 | return 0; |
| 1799 | } |
| 1800 | |
| 1801 | index = fdt_stringlist_search(fdt, node, "pinctrl-names", mode); |
| 1802 | if (index < 0) { |
| 1803 | debug("fail to find %s mode %s\n", mode, fdt_strerror(index)); |
| 1804 | goto err_pinctrl_state; |
| 1805 | } |
| 1806 | |
| 1807 | sprintf(prop_name, "pinctrl-%d", index); |
| 1808 | |
| 1809 | pinctrl_state->padconf = omap_hsmmc_get_pad_conf(mmc, prop_name, |
| 1810 | &npads); |
| 1811 | if (IS_ERR(pinctrl_state->padconf)) |
| 1812 | goto err_pinctrl_state; |
| 1813 | pinctrl_state->npads = npads; |
| 1814 | |
| 1815 | pinctrl_state->iodelay = omap_hsmmc_get_iodelay(mmc, prop_name, |
| 1816 | &niodelays); |
| 1817 | if (IS_ERR(pinctrl_state->iodelay)) |
| 1818 | goto err_padconf; |
| 1819 | pinctrl_state->niodelays = niodelays; |
| 1820 | |
| 1821 | return pinctrl_state; |
| 1822 | |
| 1823 | err_padconf: |
| 1824 | kfree(pinctrl_state->padconf); |
| 1825 | |
| 1826 | err_pinctrl_state: |
| 1827 | kfree(pinctrl_state); |
| 1828 | return 0; |
| 1829 | } |
| 1830 | |
Jean-Jacques Hiblot | dae1ad4 | 2018-01-30 16:01:42 +0100 | [diff] [blame] | 1831 | #define OMAP_HSMMC_SETUP_PINCTRL(capmask, mode, optional) \ |
Kishon Vijay Abraham I | 8c2efe9 | 2018-01-30 16:01:41 +0100 | [diff] [blame] | 1832 | do { \ |
| 1833 | struct omap_hsmmc_pinctrl_state *s = NULL; \ |
| 1834 | char str[20]; \ |
| 1835 | if (!(cfg->host_caps & capmask)) \ |
| 1836 | break; \ |
| 1837 | \ |
| 1838 | if (priv->hw_rev) { \ |
| 1839 | sprintf(str, "%s-%s", #mode, priv->hw_rev); \ |
| 1840 | s = omap_hsmmc_get_pinctrl_by_mode(mmc, str); \ |
| 1841 | } \ |
| 1842 | \ |
| 1843 | if (!s) \ |
| 1844 | s = omap_hsmmc_get_pinctrl_by_mode(mmc, #mode); \ |
| 1845 | \ |
Jean-Jacques Hiblot | dae1ad4 | 2018-01-30 16:01:42 +0100 | [diff] [blame] | 1846 | if (!s && !optional) { \ |
Kishon Vijay Abraham I | 8c2efe9 | 2018-01-30 16:01:41 +0100 | [diff] [blame] | 1847 | debug("%s: no pinctrl for %s\n", \ |
| 1848 | mmc->dev->name, #mode); \ |
| 1849 | cfg->host_caps &= ~(capmask); \ |
| 1850 | } else { \ |
| 1851 | priv->mode##_pinctrl_state = s; \ |
| 1852 | } \ |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 1853 | } while (0) |
| 1854 | |
| 1855 | static int omap_hsmmc_get_pinctrl_state(struct mmc *mmc) |
| 1856 | { |
| 1857 | struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); |
| 1858 | struct mmc_config *cfg = omap_hsmmc_get_cfg(mmc); |
| 1859 | struct omap_hsmmc_pinctrl_state *default_pinctrl; |
| 1860 | |
| 1861 | if (!(priv->controller_flags & OMAP_HSMMC_REQUIRE_IODELAY)) |
| 1862 | return 0; |
| 1863 | |
| 1864 | default_pinctrl = omap_hsmmc_get_pinctrl_by_mode(mmc, "default"); |
| 1865 | if (!default_pinctrl) { |
| 1866 | printf("no pinctrl state for default mode\n"); |
| 1867 | return -EINVAL; |
| 1868 | } |
| 1869 | |
| 1870 | priv->default_pinctrl_state = default_pinctrl; |
| 1871 | |
Jean-Jacques Hiblot | dae1ad4 | 2018-01-30 16:01:42 +0100 | [diff] [blame] | 1872 | OMAP_HSMMC_SETUP_PINCTRL(MMC_CAP(UHS_SDR104), sdr104, false); |
| 1873 | OMAP_HSMMC_SETUP_PINCTRL(MMC_CAP(UHS_SDR50), sdr50, false); |
| 1874 | OMAP_HSMMC_SETUP_PINCTRL(MMC_CAP(UHS_DDR50), ddr50, false); |
| 1875 | OMAP_HSMMC_SETUP_PINCTRL(MMC_CAP(UHS_SDR25), sdr25, false); |
| 1876 | OMAP_HSMMC_SETUP_PINCTRL(MMC_CAP(UHS_SDR12), sdr12, false); |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 1877 | |
Jean-Jacques Hiblot | dae1ad4 | 2018-01-30 16:01:42 +0100 | [diff] [blame] | 1878 | OMAP_HSMMC_SETUP_PINCTRL(MMC_CAP(MMC_HS_200), hs200_1_8v, false); |
| 1879 | OMAP_HSMMC_SETUP_PINCTRL(MMC_CAP(MMC_DDR_52), ddr_1_8v, false); |
| 1880 | OMAP_HSMMC_SETUP_PINCTRL(MMC_MODE_HS, hs, true); |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 1881 | |
| 1882 | return 0; |
| 1883 | } |
| 1884 | #endif |
| 1885 | |
Lokesh Vutla | 9a696fb | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1886 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Kishon Vijay Abraham I | 8c2efe9 | 2018-01-30 16:01:41 +0100 | [diff] [blame] | 1887 | #ifdef CONFIG_OMAP54XX |
| 1888 | __weak const struct mmc_platform_fixups *platform_fixups_mmc(uint32_t addr) |
| 1889 | { |
| 1890 | return NULL; |
| 1891 | } |
| 1892 | #endif |
| 1893 | |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1894 | static int omap_hsmmc_ofdata_to_platdata(struct udevice *dev) |
| 1895 | { |
Jean-Jacques Hiblot | ae51a66 | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 1896 | struct omap_hsmmc_plat *plat = dev_get_platdata(dev); |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 1897 | struct omap_mmc_of_data *of_data = (void *)dev_get_driver_data(dev); |
| 1898 | |
Jean-Jacques Hiblot | ae51a66 | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 1899 | struct mmc_config *cfg = &plat->cfg; |
Kishon Vijay Abraham I | 8c2efe9 | 2018-01-30 16:01:41 +0100 | [diff] [blame] | 1900 | #ifdef CONFIG_OMAP54XX |
| 1901 | const struct mmc_platform_fixups *fixups; |
| 1902 | #endif |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1903 | const void *fdt = gd->fdt_blob; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 1904 | int node = dev_of_offset(dev); |
Kishon Vijay Abraham I | 569c3d5 | 2018-01-30 16:01:38 +0100 | [diff] [blame] | 1905 | int ret; |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1906 | |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 1907 | plat->base_addr = map_physmem(devfdt_get_addr(dev), |
| 1908 | sizeof(struct hsmmc *), |
Jean-Jacques Hiblot | 3d45bb4 | 2017-09-21 16:51:32 +0200 | [diff] [blame] | 1909 | MAP_NOCACHE); |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1910 | |
Kishon Vijay Abraham I | 569c3d5 | 2018-01-30 16:01:38 +0100 | [diff] [blame] | 1911 | ret = mmc_of_parse(dev, cfg); |
| 1912 | if (ret < 0) |
| 1913 | return ret; |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1914 | |
Jean-Jacques Hiblot | 8e2bdbd | 2018-02-23 10:40:19 +0100 | [diff] [blame] | 1915 | if (!cfg->f_max) |
| 1916 | cfg->f_max = 52000000; |
Kishon Vijay Abraham I | 569c3d5 | 2018-01-30 16:01:38 +0100 | [diff] [blame] | 1917 | cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS; |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1918 | cfg->f_min = 400000; |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1919 | cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195; |
| 1920 | cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; |
Kishon Vijay Abraham I | 73897ed | 2018-01-30 16:01:32 +0100 | [diff] [blame] | 1921 | if (fdtdec_get_bool(fdt, node, "ti,dual-volt")) |
| 1922 | plat->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT; |
| 1923 | if (fdtdec_get_bool(fdt, node, "no-1-8-v")) |
| 1924 | plat->controller_flags |= OMAP_HSMMC_NO_1_8_V; |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 1925 | if (of_data) |
| 1926 | plat->controller_flags |= of_data->controller_flags; |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1927 | |
Kishon Vijay Abraham I | 8c2efe9 | 2018-01-30 16:01:41 +0100 | [diff] [blame] | 1928 | #ifdef CONFIG_OMAP54XX |
| 1929 | fixups = platform_fixups_mmc(devfdt_get_addr(dev)); |
| 1930 | if (fixups) { |
| 1931 | plat->hw_rev = fixups->hw_rev; |
| 1932 | cfg->host_caps &= ~fixups->unsupported_caps; |
| 1933 | cfg->f_max = fixups->max_freq; |
| 1934 | } |
| 1935 | #endif |
| 1936 | |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1937 | return 0; |
| 1938 | } |
Lokesh Vutla | 9a696fb | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1939 | #endif |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1940 | |
Jean-Jacques Hiblot | a3c556c | 2017-03-22 16:00:34 +0100 | [diff] [blame] | 1941 | #ifdef CONFIG_BLK |
| 1942 | |
| 1943 | static int omap_hsmmc_bind(struct udevice *dev) |
| 1944 | { |
| 1945 | struct omap_hsmmc_plat *plat = dev_get_platdata(dev); |
Jean-Jacques Hiblot | 4cb36a2 | 2018-02-23 10:40:16 +0100 | [diff] [blame] | 1946 | plat->mmc = calloc(1, sizeof(struct mmc)); |
| 1947 | return mmc_bind(dev, plat->mmc, &plat->cfg); |
Jean-Jacques Hiblot | a3c556c | 2017-03-22 16:00:34 +0100 | [diff] [blame] | 1948 | } |
| 1949 | #endif |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1950 | static int omap_hsmmc_probe(struct udevice *dev) |
| 1951 | { |
Jean-Jacques Hiblot | ae51a66 | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 1952 | struct omap_hsmmc_plat *plat = dev_get_platdata(dev); |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1953 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 1954 | struct omap_hsmmc_data *priv = dev_get_priv(dev); |
Jean-Jacques Hiblot | ae51a66 | 2017-03-22 16:00:33 +0100 | [diff] [blame] | 1955 | struct mmc_config *cfg = &plat->cfg; |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1956 | struct mmc *mmc; |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 1957 | #ifdef CONFIG_IODELAY_RECALIBRATION |
| 1958 | int ret; |
| 1959 | #endif |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1960 | |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1961 | cfg->name = "OMAP SD/MMC"; |
Lokesh Vutla | 9a696fb | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 1962 | priv->base_addr = plat->base_addr; |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 1963 | priv->controller_flags = plat->controller_flags; |
Kishon Vijay Abraham I | 8c2efe9 | 2018-01-30 16:01:41 +0100 | [diff] [blame] | 1964 | priv->hw_rev = plat->hw_rev; |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1965 | |
Jean-Jacques Hiblot | a3c556c | 2017-03-22 16:00:34 +0100 | [diff] [blame] | 1966 | #ifdef CONFIG_BLK |
Jean-Jacques Hiblot | 4cb36a2 | 2018-02-23 10:40:16 +0100 | [diff] [blame] | 1967 | mmc = plat->mmc; |
Jean-Jacques Hiblot | a3c556c | 2017-03-22 16:00:34 +0100 | [diff] [blame] | 1968 | #else |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1969 | mmc = mmc_create(cfg, priv); |
| 1970 | if (mmc == NULL) |
| 1971 | return -1; |
Jean-Jacques Hiblot | a3c556c | 2017-03-22 16:00:34 +0100 | [diff] [blame] | 1972 | #endif |
Jean-Jacques Hiblot | 7a41bb4 | 2018-01-30 16:01:46 +0100 | [diff] [blame] | 1973 | #if CONFIG_IS_ENABLED(DM_REGULATOR) |
| 1974 | device_get_supply_regulator(dev, "pbias-supply", |
| 1975 | &priv->pbias_supply); |
| 1976 | #endif |
Adam Ford | 6122af4 | 2018-08-21 07:16:56 -0500 | [diff] [blame] | 1977 | #if defined(OMAP_HSMMC_USE_GPIO) |
| 1978 | #if CONFIG_IS_ENABLED(OF_CONTROL) && CONFIG_IS_ENABLED(DM_GPIO) |
Mugunthan V N | a9a0aa7 | 2016-04-04 17:28:01 +0530 | [diff] [blame] | 1979 | gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio, GPIOD_IS_IN); |
| 1980 | gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio, GPIOD_IS_IN); |
| 1981 | #endif |
Adam Ford | 6122af4 | 2018-08-21 07:16:56 -0500 | [diff] [blame] | 1982 | #endif |
Mugunthan V N | a9a0aa7 | 2016-04-04 17:28:01 +0530 | [diff] [blame] | 1983 | |
Simon Glass | 77ca42b | 2016-05-01 13:52:34 -0600 | [diff] [blame] | 1984 | mmc->dev = dev; |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 1985 | upriv->mmc = mmc; |
| 1986 | |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 1987 | #ifdef CONFIG_IODELAY_RECALIBRATION |
| 1988 | ret = omap_hsmmc_get_pinctrl_state(mmc); |
| 1989 | /* |
| 1990 | * disable high speed modes for the platforms that require IO delay |
| 1991 | * and for which we don't have this information |
| 1992 | */ |
| 1993 | if ((ret < 0) && |
| 1994 | (priv->controller_flags & OMAP_HSMMC_REQUIRE_IODELAY)) { |
| 1995 | priv->controller_flags &= ~OMAP_HSMMC_REQUIRE_IODELAY; |
| 1996 | cfg->host_caps &= ~(MMC_CAP(MMC_HS_200) | MMC_CAP(MMC_DDR_52) | |
| 1997 | UHS_CAPS); |
| 1998 | } |
| 1999 | #endif |
| 2000 | |
Jean-Jacques Hiblot | 8fc9d3a | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 2001 | return omap_hsmmc_init_setup(mmc); |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 2002 | } |
| 2003 | |
Lokesh Vutla | 9a696fb | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 2004 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 2005 | |
| 2006 | static const struct omap_mmc_of_data dra7_mmc_of_data = { |
| 2007 | .controller_flags = OMAP_HSMMC_REQUIRE_IODELAY, |
| 2008 | }; |
| 2009 | |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 2010 | static const struct udevice_id omap_hsmmc_ids[] = { |
Jean-Jacques Hiblot | 3d45bb4 | 2017-09-21 16:51:32 +0200 | [diff] [blame] | 2011 | { .compatible = "ti,omap3-hsmmc" }, |
| 2012 | { .compatible = "ti,omap4-hsmmc" }, |
| 2013 | { .compatible = "ti,am33xx-hsmmc" }, |
Kishon Vijay Abraham I | e7da6ac | 2018-01-30 16:01:40 +0100 | [diff] [blame] | 2014 | { .compatible = "ti,dra7-hsmmc", .data = (ulong)&dra7_mmc_of_data }, |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 2015 | { } |
| 2016 | }; |
Lokesh Vutla | 9a696fb | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 2017 | #endif |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 2018 | |
| 2019 | U_BOOT_DRIVER(omap_hsmmc) = { |
| 2020 | .name = "omap_hsmmc", |
| 2021 | .id = UCLASS_MMC, |
Lokesh Vutla | 9a696fb | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 2022 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 2023 | .of_match = omap_hsmmc_ids, |
| 2024 | .ofdata_to_platdata = omap_hsmmc_ofdata_to_platdata, |
Lokesh Vutla | 9a696fb | 2017-04-26 13:37:05 +0530 | [diff] [blame] | 2025 | .platdata_auto_alloc_size = sizeof(struct omap_hsmmc_plat), |
| 2026 | #endif |
Jean-Jacques Hiblot | a3c556c | 2017-03-22 16:00:34 +0100 | [diff] [blame] | 2027 | #ifdef CONFIG_BLK |
| 2028 | .bind = omap_hsmmc_bind, |
| 2029 | #endif |
Jean-Jacques Hiblot | 8fc9d3a | 2017-04-14 19:50:02 +0200 | [diff] [blame] | 2030 | .ops = &omap_hsmmc_ops, |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 2031 | .probe = omap_hsmmc_probe, |
| 2032 | .priv_auto_alloc_size = sizeof(struct omap_hsmmc_data), |
Bin Meng | 793260a | 2018-10-24 06:36:32 -0700 | [diff] [blame] | 2033 | #if !CONFIG_IS_ENABLED(OF_CONTROL) |
Lokesh Vutla | c38e645 | 2017-04-26 13:37:06 +0530 | [diff] [blame] | 2034 | .flags = DM_FLAG_PRE_RELOC, |
Bin Meng | 793260a | 2018-10-24 06:36:32 -0700 | [diff] [blame] | 2035 | #endif |
Mugunthan V N | d97631a | 2015-09-28 12:56:30 +0530 | [diff] [blame] | 2036 | }; |
| 2037 | #endif |