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