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