Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 3 | * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/ |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 4 | * |
| 5 | * Texas Instruments' K3 SD Host Controller Interface |
| 6 | */ |
| 7 | |
| 8 | #include <clk.h> |
| 9 | #include <common.h> |
| 10 | #include <dm.h> |
| 11 | #include <malloc.h> |
Faiz Abbas | 7a7e2c7 | 2021-02-04 15:10:53 +0530 | [diff] [blame] | 12 | #include <mmc.h> |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 13 | #include <power-domain.h> |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 14 | #include <regmap.h> |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 15 | #include <sdhci.h> |
Faiz Abbas | 2c2fc96 | 2021-02-04 15:10:50 +0530 | [diff] [blame] | 16 | #include <soc.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 17 | #include <dm/device_compat.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 18 | #include <linux/bitops.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 19 | #include <linux/err.h> |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 20 | |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 21 | /* CTL_CFG Registers */ |
| 22 | #define CTL_CFG_2 0x14 |
| 23 | |
| 24 | #define SLOTTYPE_MASK GENMASK(31, 30) |
| 25 | #define SLOTTYPE_EMBEDDED BIT(30) |
| 26 | |
| 27 | /* PHY Registers */ |
| 28 | #define PHY_CTRL1 0x100 |
| 29 | #define PHY_CTRL2 0x104 |
| 30 | #define PHY_CTRL3 0x108 |
| 31 | #define PHY_CTRL4 0x10C |
| 32 | #define PHY_CTRL5 0x110 |
| 33 | #define PHY_CTRL6 0x114 |
| 34 | #define PHY_STAT1 0x130 |
| 35 | #define PHY_STAT2 0x134 |
| 36 | |
| 37 | #define IOMUX_ENABLE_SHIFT 31 |
| 38 | #define IOMUX_ENABLE_MASK BIT(IOMUX_ENABLE_SHIFT) |
| 39 | #define OTAPDLYENA_SHIFT 20 |
| 40 | #define OTAPDLYENA_MASK BIT(OTAPDLYENA_SHIFT) |
| 41 | #define OTAPDLYSEL_SHIFT 12 |
| 42 | #define OTAPDLYSEL_MASK GENMASK(15, 12) |
| 43 | #define STRBSEL_SHIFT 24 |
Faiz Abbas | 8cc051e | 2020-01-16 19:42:19 +0530 | [diff] [blame] | 44 | #define STRBSEL_4BIT_MASK GENMASK(27, 24) |
| 45 | #define STRBSEL_8BIT_MASK GENMASK(31, 24) |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 46 | #define SEL50_SHIFT 8 |
| 47 | #define SEL50_MASK BIT(SEL50_SHIFT) |
| 48 | #define SEL100_SHIFT 9 |
| 49 | #define SEL100_MASK BIT(SEL100_SHIFT) |
Faiz Abbas | 8cc051e | 2020-01-16 19:42:19 +0530 | [diff] [blame] | 50 | #define FREQSEL_SHIFT 8 |
| 51 | #define FREQSEL_MASK GENMASK(10, 8) |
Faiz Abbas | c73f04e | 2021-02-04 15:10:52 +0530 | [diff] [blame] | 52 | #define CLKBUFSEL_SHIFT 0 |
| 53 | #define CLKBUFSEL_MASK GENMASK(2, 0) |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 54 | #define DLL_TRIM_ICP_SHIFT 4 |
| 55 | #define DLL_TRIM_ICP_MASK GENMASK(7, 4) |
| 56 | #define DR_TY_SHIFT 20 |
| 57 | #define DR_TY_MASK GENMASK(22, 20) |
| 58 | #define ENDLL_SHIFT 1 |
| 59 | #define ENDLL_MASK BIT(ENDLL_SHIFT) |
| 60 | #define DLLRDY_SHIFT 0 |
| 61 | #define DLLRDY_MASK BIT(DLLRDY_SHIFT) |
| 62 | #define PDB_SHIFT 0 |
| 63 | #define PDB_MASK BIT(PDB_SHIFT) |
| 64 | #define CALDONE_SHIFT 1 |
| 65 | #define CALDONE_MASK BIT(CALDONE_SHIFT) |
| 66 | #define RETRIM_SHIFT 17 |
| 67 | #define RETRIM_MASK BIT(RETRIM_SHIFT) |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 68 | #define SELDLYTXCLK_SHIFT 17 |
| 69 | #define SELDLYTXCLK_MASK BIT(SELDLYTXCLK_SHIFT) |
| 70 | #define SELDLYRXCLK_SHIFT 16 |
| 71 | #define SELDLYRXCLK_MASK BIT(SELDLYRXCLK_SHIFT) |
| 72 | #define ITAPDLYSEL_SHIFT 0 |
| 73 | #define ITAPDLYSEL_MASK GENMASK(4, 0) |
| 74 | #define ITAPDLYENA_SHIFT 8 |
| 75 | #define ITAPDLYENA_MASK BIT(ITAPDLYENA_SHIFT) |
| 76 | #define ITAPCHGWIN_SHIFT 9 |
| 77 | #define ITAPCHGWIN_MASK BIT(ITAPCHGWIN_SHIFT) |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 78 | |
| 79 | #define DRIVER_STRENGTH_50_OHM 0x0 |
| 80 | #define DRIVER_STRENGTH_33_OHM 0x1 |
| 81 | #define DRIVER_STRENGTH_66_OHM 0x2 |
| 82 | #define DRIVER_STRENGTH_100_OHM 0x3 |
| 83 | #define DRIVER_STRENGTH_40_OHM 0x4 |
| 84 | |
Faiz Abbas | d8fb309 | 2019-06-11 00:43:31 +0530 | [diff] [blame] | 85 | #define AM654_SDHCI_MIN_FREQ 400000 |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 86 | #define CLOCK_TOO_SLOW_HZ 50000000 |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 87 | |
Faiz Abbas | d8fb309 | 2019-06-11 00:43:31 +0530 | [diff] [blame] | 88 | struct am654_sdhci_plat { |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 89 | struct mmc_config cfg; |
| 90 | struct mmc mmc; |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 91 | struct regmap *base; |
| 92 | bool non_removable; |
Faiz Abbas | 7101e12 | 2020-07-29 07:03:41 +0530 | [diff] [blame] | 93 | u32 otap_del_sel[MMC_MODES_END]; |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 94 | u32 itap_del_sel[MMC_MODES_END]; |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 95 | u32 trm_icp; |
| 96 | u32 drv_strength; |
Faiz Abbas | 8cc051e | 2020-01-16 19:42:19 +0530 | [diff] [blame] | 97 | u32 strb_sel; |
Faiz Abbas | c73f04e | 2021-02-04 15:10:52 +0530 | [diff] [blame] | 98 | u32 clkbuf_sel; |
Faiz Abbas | fd8be70 | 2019-06-13 10:29:51 +0530 | [diff] [blame] | 99 | u32 flags; |
Judith Mendez | 81c1d44 | 2024-04-18 14:00:56 -0500 | [diff] [blame^] | 100 | bool dll_enable; |
Faiz Abbas | b7f57bb | 2021-02-04 15:10:48 +0530 | [diff] [blame] | 101 | #define DLL_PRESENT BIT(0) |
| 102 | #define IOMUX_PRESENT BIT(1) |
| 103 | #define FREQSEL_2_BIT BIT(2) |
| 104 | #define STRBSEL_4_BIT BIT(3) |
Faiz Abbas | 947e8f3 | 2021-02-04 15:10:49 +0530 | [diff] [blame] | 105 | #define DLL_CALIB BIT(4) |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 106 | }; |
| 107 | |
Faiz Abbas | c6eb9e7 | 2020-02-26 13:44:33 +0530 | [diff] [blame] | 108 | struct timing_data { |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 109 | const char *otap_binding; |
| 110 | const char *itap_binding; |
Faiz Abbas | c6eb9e7 | 2020-02-26 13:44:33 +0530 | [diff] [blame] | 111 | u32 capability; |
| 112 | }; |
| 113 | |
Judith Mendez | 81c1d44 | 2024-04-18 14:00:56 -0500 | [diff] [blame^] | 114 | struct window { |
| 115 | u8 start; |
| 116 | u8 end; |
| 117 | u8 length; |
| 118 | }; |
| 119 | |
Faiz Abbas | c6eb9e7 | 2020-02-26 13:44:33 +0530 | [diff] [blame] | 120 | static const struct timing_data td[] = { |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 121 | [MMC_LEGACY] = {"ti,otap-del-sel-legacy", |
| 122 | "ti,itap-del-sel-legacy", |
| 123 | 0}, |
| 124 | [MMC_HS] = {"ti,otap-del-sel-mmc-hs", |
| 125 | "ti,itap-del-sel-mms-hs", |
| 126 | MMC_CAP(MMC_HS)}, |
| 127 | [SD_HS] = {"ti,otap-del-sel-sd-hs", |
| 128 | "ti,itap-del-sel-sd-hs", |
| 129 | MMC_CAP(SD_HS)}, |
| 130 | [UHS_SDR12] = {"ti,otap-del-sel-sdr12", |
| 131 | "ti,itap-del-sel-sdr12", |
| 132 | MMC_CAP(UHS_SDR12)}, |
| 133 | [UHS_SDR25] = {"ti,otap-del-sel-sdr25", |
| 134 | "ti,itap-del-sel-sdr25", |
| 135 | MMC_CAP(UHS_SDR25)}, |
| 136 | [UHS_SDR50] = {"ti,otap-del-sel-sdr50", |
| 137 | NULL, |
| 138 | MMC_CAP(UHS_SDR50)}, |
| 139 | [UHS_SDR104] = {"ti,otap-del-sel-sdr104", |
| 140 | NULL, |
| 141 | MMC_CAP(UHS_SDR104)}, |
| 142 | [UHS_DDR50] = {"ti,otap-del-sel-ddr50", |
| 143 | NULL, |
| 144 | MMC_CAP(UHS_DDR50)}, |
| 145 | [MMC_DDR_52] = {"ti,otap-del-sel-ddr52", |
| 146 | "ti,itap-del-sel-ddr52", |
| 147 | MMC_CAP(MMC_DDR_52)}, |
| 148 | [MMC_HS_200] = {"ti,otap-del-sel-hs200", |
| 149 | NULL, |
| 150 | MMC_CAP(MMC_HS_200)}, |
| 151 | [MMC_HS_400] = {"ti,otap-del-sel-hs400", |
| 152 | NULL, |
| 153 | MMC_CAP(MMC_HS_400)}, |
Faiz Abbas | c6eb9e7 | 2020-02-26 13:44:33 +0530 | [diff] [blame] | 154 | }; |
| 155 | |
Faiz Abbas | 8cc051e | 2020-01-16 19:42:19 +0530 | [diff] [blame] | 156 | struct am654_driver_data { |
| 157 | const struct sdhci_ops *ops; |
| 158 | u32 flags; |
| 159 | }; |
| 160 | |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 161 | static int am654_sdhci_setup_dll(struct am654_sdhci_plat *plat, |
| 162 | unsigned int speed) |
| 163 | { |
| 164 | int sel50, sel100, freqsel; |
| 165 | u32 mask, val; |
| 166 | int ret; |
| 167 | |
| 168 | /* Disable delay chain mode */ |
| 169 | regmap_update_bits(plat->base, PHY_CTRL5, |
| 170 | SELDLYTXCLK_MASK | SELDLYRXCLK_MASK, 0); |
| 171 | |
| 172 | if (plat->flags & FREQSEL_2_BIT) { |
| 173 | switch (speed) { |
| 174 | case 200000000: |
| 175 | sel50 = 0; |
| 176 | sel100 = 0; |
| 177 | break; |
| 178 | case 100000000: |
| 179 | sel50 = 0; |
| 180 | sel100 = 1; |
| 181 | break; |
| 182 | default: |
| 183 | sel50 = 1; |
| 184 | sel100 = 0; |
| 185 | } |
| 186 | |
| 187 | /* Configure PHY DLL frequency */ |
| 188 | mask = SEL50_MASK | SEL100_MASK; |
| 189 | val = (sel50 << SEL50_SHIFT) | (sel100 << SEL100_SHIFT); |
| 190 | regmap_update_bits(plat->base, PHY_CTRL5, mask, val); |
| 191 | } else { |
| 192 | switch (speed) { |
| 193 | case 200000000: |
| 194 | freqsel = 0x0; |
| 195 | break; |
| 196 | default: |
| 197 | freqsel = 0x4; |
| 198 | } |
| 199 | regmap_update_bits(plat->base, PHY_CTRL5, FREQSEL_MASK, |
| 200 | freqsel << FREQSEL_SHIFT); |
| 201 | } |
| 202 | |
| 203 | /* Configure DLL TRIM */ |
| 204 | mask = DLL_TRIM_ICP_MASK; |
| 205 | val = plat->trm_icp << DLL_TRIM_ICP_SHIFT; |
| 206 | |
| 207 | /* Configure DLL driver strength */ |
| 208 | mask |= DR_TY_MASK; |
| 209 | val |= plat->drv_strength << DR_TY_SHIFT; |
| 210 | regmap_update_bits(plat->base, PHY_CTRL1, mask, val); |
| 211 | |
| 212 | /* Enable DLL */ |
| 213 | regmap_update_bits(plat->base, PHY_CTRL1, ENDLL_MASK, |
| 214 | 0x1 << ENDLL_SHIFT); |
| 215 | /* |
| 216 | * Poll for DLL ready. Use a one second timeout. |
| 217 | * Works in all experiments done so far |
| 218 | */ |
| 219 | ret = regmap_read_poll_timeout(plat->base, PHY_STAT1, val, |
| 220 | val & DLLRDY_MASK, 1000, 1000000); |
| 221 | |
| 222 | return ret; |
| 223 | } |
| 224 | |
| 225 | static void am654_sdhci_write_itapdly(struct am654_sdhci_plat *plat, |
| 226 | u32 itapdly) |
| 227 | { |
| 228 | /* Set ITAPCHGWIN before writing to ITAPDLY */ |
| 229 | regmap_update_bits(plat->base, PHY_CTRL4, ITAPCHGWIN_MASK, |
| 230 | 1 << ITAPCHGWIN_SHIFT); |
| 231 | regmap_update_bits(plat->base, PHY_CTRL4, ITAPDLYSEL_MASK, |
| 232 | itapdly << ITAPDLYSEL_SHIFT); |
| 233 | regmap_update_bits(plat->base, PHY_CTRL4, ITAPCHGWIN_MASK, 0); |
| 234 | } |
| 235 | |
| 236 | static void am654_sdhci_setup_delay_chain(struct am654_sdhci_plat *plat, |
| 237 | int mode) |
| 238 | { |
| 239 | u32 mask, val; |
| 240 | |
| 241 | val = 1 << SELDLYTXCLK_SHIFT | 1 << SELDLYRXCLK_SHIFT; |
| 242 | mask = SELDLYTXCLK_MASK | SELDLYRXCLK_MASK; |
| 243 | regmap_update_bits(plat->base, PHY_CTRL5, mask, val); |
| 244 | |
| 245 | am654_sdhci_write_itapdly(plat, plat->itap_del_sel[mode]); |
| 246 | } |
| 247 | |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 248 | static int am654_sdhci_set_ios_post(struct sdhci_host *host) |
| 249 | { |
| 250 | struct udevice *dev = host->mmc->dev; |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 251 | struct am654_sdhci_plat *plat = dev_get_plat(dev); |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 252 | unsigned int speed = host->mmc->clock; |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 253 | int mode = host->mmc->selected_mode; |
Faiz Abbas | c6eb9e7 | 2020-02-26 13:44:33 +0530 | [diff] [blame] | 254 | u32 otap_del_sel; |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 255 | u32 mask, val; |
| 256 | int ret; |
| 257 | |
| 258 | /* Reset SD Clock Enable */ |
| 259 | val = sdhci_readw(host, SDHCI_CLOCK_CONTROL); |
| 260 | val &= ~SDHCI_CLOCK_CARD_EN; |
| 261 | sdhci_writew(host, val, SDHCI_CLOCK_CONTROL); |
| 262 | |
Faiz Abbas | 2c45a2c | 2021-02-04 15:10:47 +0530 | [diff] [blame] | 263 | regmap_update_bits(plat->base, PHY_CTRL1, ENDLL_MASK, 0); |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 264 | |
| 265 | /* restart clock */ |
| 266 | sdhci_set_clock(host->mmc, speed); |
| 267 | |
| 268 | /* switch phy back on */ |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 269 | otap_del_sel = plat->otap_del_sel[mode]; |
| 270 | mask = OTAPDLYENA_MASK | OTAPDLYSEL_MASK; |
| 271 | val = (1 << OTAPDLYENA_SHIFT) | |
| 272 | (otap_del_sel << OTAPDLYSEL_SHIFT); |
Faiz Abbas | 8cc051e | 2020-01-16 19:42:19 +0530 | [diff] [blame] | 273 | |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 274 | /* Write to STRBSEL for HS400 speed mode */ |
| 275 | if (host->mmc->selected_mode == MMC_HS_400) { |
| 276 | if (plat->flags & STRBSEL_4_BIT) |
| 277 | mask |= STRBSEL_4BIT_MASK; |
| 278 | else |
| 279 | mask |= STRBSEL_8BIT_MASK; |
Faiz Abbas | 8cc051e | 2020-01-16 19:42:19 +0530 | [diff] [blame] | 280 | |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 281 | val |= plat->strb_sel << STRBSEL_SHIFT; |
| 282 | } |
Faiz Abbas | 947e8f3 | 2021-02-04 15:10:49 +0530 | [diff] [blame] | 283 | |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 284 | regmap_update_bits(plat->base, PHY_CTRL4, mask, val); |
Faiz Abbas | 947e8f3 | 2021-02-04 15:10:49 +0530 | [diff] [blame] | 285 | |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 286 | if (mode > UHS_SDR25 && speed >= CLOCK_TOO_SLOW_HZ) { |
| 287 | ret = am654_sdhci_setup_dll(plat, speed); |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 288 | if (ret) |
| 289 | return ret; |
Judith Mendez | 81c1d44 | 2024-04-18 14:00:56 -0500 | [diff] [blame^] | 290 | |
| 291 | plat->dll_enable = true; |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 292 | } else { |
| 293 | am654_sdhci_setup_delay_chain(plat, mode); |
Judith Mendez | 81c1d44 | 2024-04-18 14:00:56 -0500 | [diff] [blame^] | 294 | plat->dll_enable = false; |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 295 | } |
| 296 | |
Faiz Abbas | c73f04e | 2021-02-04 15:10:52 +0530 | [diff] [blame] | 297 | regmap_update_bits(plat->base, PHY_CTRL5, CLKBUFSEL_MASK, |
| 298 | plat->clkbuf_sel); |
| 299 | |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 300 | return 0; |
| 301 | } |
| 302 | |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 303 | int am654_sdhci_init(struct am654_sdhci_plat *plat) |
| 304 | { |
| 305 | u32 ctl_cfg_2 = 0; |
| 306 | u32 mask, val; |
| 307 | int ret; |
| 308 | |
| 309 | /* Reset OTAP to default value */ |
| 310 | mask = OTAPDLYENA_MASK | OTAPDLYSEL_MASK; |
| 311 | regmap_update_bits(plat->base, PHY_CTRL4, mask, 0x0); |
| 312 | |
Faiz Abbas | 947e8f3 | 2021-02-04 15:10:49 +0530 | [diff] [blame] | 313 | if (plat->flags & DLL_CALIB) { |
Faiz Abbas | fd8be70 | 2019-06-13 10:29:51 +0530 | [diff] [blame] | 314 | regmap_read(plat->base, PHY_STAT1, &val); |
| 315 | if (~val & CALDONE_MASK) { |
| 316 | /* Calibrate IO lines */ |
| 317 | regmap_update_bits(plat->base, PHY_CTRL1, PDB_MASK, |
| 318 | PDB_MASK); |
| 319 | ret = regmap_read_poll_timeout(plat->base, PHY_STAT1, |
| 320 | val, val & CALDONE_MASK, |
| 321 | 1, 20); |
| 322 | if (ret) |
| 323 | return ret; |
| 324 | } |
Faiz Abbas | fd8be70 | 2019-06-13 10:29:51 +0530 | [diff] [blame] | 325 | } |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 326 | |
| 327 | /* Enable pins by setting IO mux to 0 */ |
Faiz Abbas | 8cc051e | 2020-01-16 19:42:19 +0530 | [diff] [blame] | 328 | if (plat->flags & IOMUX_PRESENT) |
| 329 | regmap_update_bits(plat->base, PHY_CTRL1, IOMUX_ENABLE_MASK, 0); |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 330 | |
| 331 | /* Set slot type based on SD or eMMC */ |
| 332 | if (plat->non_removable) |
| 333 | ctl_cfg_2 = SLOTTYPE_EMBEDDED; |
| 334 | |
| 335 | regmap_update_bits(plat->base, CTL_CFG_2, SLOTTYPE_MASK, ctl_cfg_2); |
| 336 | |
| 337 | return 0; |
| 338 | } |
| 339 | |
Faiz Abbas | e4425cb | 2020-02-26 13:44:34 +0530 | [diff] [blame] | 340 | #define MAX_SDCD_DEBOUNCE_TIME 2000 |
| 341 | static int am654_sdhci_deferred_probe(struct sdhci_host *host) |
| 342 | { |
| 343 | struct udevice *dev = host->mmc->dev; |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 344 | struct am654_sdhci_plat *plat = dev_get_plat(dev); |
Faiz Abbas | e4425cb | 2020-02-26 13:44:34 +0530 | [diff] [blame] | 345 | unsigned long start; |
| 346 | int val; |
| 347 | |
| 348 | /* |
| 349 | * The controller takes about 1 second to debounce the card detect line |
| 350 | * and doesn't let us power on until that time is up. Instead of waiting |
| 351 | * for 1 second at every stage, poll on the CARD_PRESENT bit upto a |
| 352 | * maximum of 2 seconds to be safe.. |
| 353 | */ |
| 354 | start = get_timer(0); |
| 355 | do { |
| 356 | if (get_timer(start) > MAX_SDCD_DEBOUNCE_TIME) |
| 357 | return -ENOMEDIUM; |
| 358 | |
| 359 | val = mmc_getcd(host->mmc); |
| 360 | } while (!val); |
| 361 | |
| 362 | am654_sdhci_init(plat); |
| 363 | |
| 364 | return sdhci_probe(dev); |
| 365 | } |
| 366 | |
Faiz Abbas | 36c8c5c | 2021-02-04 15:10:54 +0530 | [diff] [blame] | 367 | static void am654_sdhci_write_b(struct sdhci_host *host, u8 val, int reg) |
| 368 | { |
| 369 | if (reg == SDHCI_HOST_CONTROL) { |
| 370 | switch (host->mmc->selected_mode) { |
| 371 | /* |
| 372 | * According to the data manual, HISPD bit |
| 373 | * should not be set in these speed modes. |
| 374 | */ |
| 375 | case SD_HS: |
| 376 | case MMC_HS: |
| 377 | case UHS_SDR12: |
| 378 | case UHS_SDR25: |
| 379 | val &= ~SDHCI_CTRL_HISPD; |
| 380 | default: |
| 381 | break; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | writeb(val, host->ioaddr + reg); |
| 386 | } |
Faiz Abbas | 7a7e2c7 | 2021-02-04 15:10:53 +0530 | [diff] [blame] | 387 | #ifdef MMC_SUPPORTS_TUNING |
Judith Mendez | 81c1d44 | 2024-04-18 14:00:56 -0500 | [diff] [blame^] | 388 | #define ITAPDLY_LENGTH 32 |
| 389 | #define ITAPDLY_LAST_INDEX (ITAPDLY_LENGTH - 1) |
| 390 | |
| 391 | static u32 am654_sdhci_calculate_itap(struct udevice *dev, struct window |
| 392 | *fail_window, u8 num_fails, bool circular_buffer) |
| 393 | { |
| 394 | u8 itap = 0, start_fail = 0, end_fail = 0, pass_length = 0; |
| 395 | u8 first_fail_start = 0, last_fail_end = 0; |
| 396 | struct window pass_window = {0, 0, 0}; |
| 397 | int prev_fail_end = -1; |
| 398 | u8 i; |
| 399 | |
| 400 | if (!num_fails) |
| 401 | return ITAPDLY_LAST_INDEX >> 1; |
| 402 | |
| 403 | if (fail_window->length == ITAPDLY_LENGTH) { |
| 404 | dev_err(dev, "No passing ITAPDLY, return 0\n"); |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | first_fail_start = fail_window->start; |
| 409 | last_fail_end = fail_window[num_fails - 1].end; |
| 410 | |
| 411 | for (i = 0; i < num_fails; i++) { |
| 412 | start_fail = fail_window[i].start; |
| 413 | end_fail = fail_window[i].end; |
| 414 | pass_length = start_fail - (prev_fail_end + 1); |
| 415 | |
| 416 | if (pass_length > pass_window.length) { |
| 417 | pass_window.start = prev_fail_end + 1; |
| 418 | pass_window.length = pass_length; |
| 419 | } |
| 420 | prev_fail_end = end_fail; |
| 421 | } |
| 422 | |
| 423 | if (!circular_buffer) |
| 424 | pass_length = ITAPDLY_LAST_INDEX - last_fail_end; |
| 425 | else |
| 426 | pass_length = ITAPDLY_LAST_INDEX - last_fail_end + first_fail_start; |
| 427 | |
| 428 | if (pass_length > pass_window.length) { |
| 429 | pass_window.start = last_fail_end + 1; |
| 430 | pass_window.length = pass_length; |
| 431 | } |
| 432 | |
| 433 | if (!circular_buffer) |
| 434 | itap = pass_window.start + (pass_window.length >> 1); |
| 435 | else |
| 436 | itap = (pass_window.start + (pass_window.length >> 1)) % ITAPDLY_LENGTH; |
| 437 | |
| 438 | return (itap > ITAPDLY_LAST_INDEX) ? ITAPDLY_LAST_INDEX >> 1 : itap; |
| 439 | } |
| 440 | |
Faiz Abbas | 7a7e2c7 | 2021-02-04 15:10:53 +0530 | [diff] [blame] | 441 | static int am654_sdhci_execute_tuning(struct mmc *mmc, u8 opcode) |
| 442 | { |
| 443 | struct udevice *dev = mmc->dev; |
| 444 | struct am654_sdhci_plat *plat = dev_get_plat(dev); |
Judith Mendez | 81c1d44 | 2024-04-18 14:00:56 -0500 | [diff] [blame^] | 445 | struct window fail_window[ITAPDLY_LENGTH]; |
| 446 | u8 curr_pass, itap; |
| 447 | u8 fail_index = 0; |
| 448 | u8 prev_pass = 1; |
| 449 | |
| 450 | memset(fail_window, 0, sizeof(fail_window)); |
Faiz Abbas | 7a7e2c7 | 2021-02-04 15:10:53 +0530 | [diff] [blame] | 451 | |
| 452 | /* Enable ITAPDLY */ |
| 453 | regmap_update_bits(plat->base, PHY_CTRL4, ITAPDLYENA_MASK, |
| 454 | 1 << ITAPDLYENA_SHIFT); |
| 455 | |
Judith Mendez | 81c1d44 | 2024-04-18 14:00:56 -0500 | [diff] [blame^] | 456 | for (itap = 0; itap < ITAPDLY_LENGTH; itap++) { |
Faiz Abbas | 7a7e2c7 | 2021-02-04 15:10:53 +0530 | [diff] [blame] | 457 | am654_sdhci_write_itapdly(plat, itap); |
| 458 | |
Judith Mendez | 81c1d44 | 2024-04-18 14:00:56 -0500 | [diff] [blame^] | 459 | curr_pass = !mmc_send_tuning(mmc, opcode); |
| 460 | |
| 461 | if (!curr_pass && prev_pass) |
| 462 | fail_window[fail_index].start = itap; |
Faiz Abbas | 7a7e2c7 | 2021-02-04 15:10:53 +0530 | [diff] [blame] | 463 | |
Judith Mendez | 81c1d44 | 2024-04-18 14:00:56 -0500 | [diff] [blame^] | 464 | if (!curr_pass) { |
| 465 | fail_window[fail_index].end = itap; |
| 466 | fail_window[fail_index].length++; |
| 467 | } |
| 468 | |
| 469 | if (curr_pass && !prev_pass) |
| 470 | fail_index++; |
Faiz Abbas | 7a7e2c7 | 2021-02-04 15:10:53 +0530 | [diff] [blame] | 471 | |
Judith Mendez | 81c1d44 | 2024-04-18 14:00:56 -0500 | [diff] [blame^] | 472 | prev_pass = curr_pass; |
Faiz Abbas | 7a7e2c7 | 2021-02-04 15:10:53 +0530 | [diff] [blame] | 473 | } |
Judith Mendez | 81c1d44 | 2024-04-18 14:00:56 -0500 | [diff] [blame^] | 474 | |
| 475 | if (fail_window[fail_index].length != 0) |
| 476 | fail_index++; |
| 477 | |
| 478 | itap = am654_sdhci_calculate_itap(dev, fail_window, fail_index, |
| 479 | plat->dll_enable); |
| 480 | |
Faiz Abbas | 7a7e2c7 | 2021-02-04 15:10:53 +0530 | [diff] [blame] | 481 | am654_sdhci_write_itapdly(plat, itap); |
| 482 | |
| 483 | return 0; |
| 484 | } |
| 485 | #endif |
Faiz Abbas | e4425cb | 2020-02-26 13:44:34 +0530 | [diff] [blame] | 486 | const struct sdhci_ops am654_sdhci_ops = { |
Faiz Abbas | 7a7e2c7 | 2021-02-04 15:10:53 +0530 | [diff] [blame] | 487 | #ifdef MMC_SUPPORTS_TUNING |
| 488 | .platform_execute_tuning = am654_sdhci_execute_tuning, |
| 489 | #endif |
Faiz Abbas | e4425cb | 2020-02-26 13:44:34 +0530 | [diff] [blame] | 490 | .deferred_probe = am654_sdhci_deferred_probe, |
| 491 | .set_ios_post = &am654_sdhci_set_ios_post, |
Faiz Abbas | 9c10cfe | 2021-02-04 15:10:55 +0530 | [diff] [blame] | 492 | .set_control_reg = sdhci_set_control_reg, |
Faiz Abbas | 36c8c5c | 2021-02-04 15:10:54 +0530 | [diff] [blame] | 493 | .write_b = am654_sdhci_write_b, |
Faiz Abbas | e4425cb | 2020-02-26 13:44:34 +0530 | [diff] [blame] | 494 | }; |
| 495 | |
| 496 | const struct am654_driver_data am654_drv_data = { |
| 497 | .ops = &am654_sdhci_ops, |
Faiz Abbas | 2c2fc96 | 2021-02-04 15:10:50 +0530 | [diff] [blame] | 498 | .flags = DLL_PRESENT | IOMUX_PRESENT | FREQSEL_2_BIT | STRBSEL_4_BIT, |
| 499 | }; |
| 500 | |
| 501 | const struct am654_driver_data am654_sr1_drv_data = { |
| 502 | .ops = &am654_sdhci_ops, |
Faiz Abbas | 947e8f3 | 2021-02-04 15:10:49 +0530 | [diff] [blame] | 503 | .flags = IOMUX_PRESENT | FREQSEL_2_BIT | DLL_PRESENT | DLL_CALIB | |
| 504 | STRBSEL_4_BIT, |
Faiz Abbas | e4425cb | 2020-02-26 13:44:34 +0530 | [diff] [blame] | 505 | }; |
| 506 | |
| 507 | const struct am654_driver_data j721e_8bit_drv_data = { |
| 508 | .ops = &am654_sdhci_ops, |
Faiz Abbas | 947e8f3 | 2021-02-04 15:10:49 +0530 | [diff] [blame] | 509 | .flags = DLL_PRESENT | DLL_CALIB, |
Faiz Abbas | e4425cb | 2020-02-26 13:44:34 +0530 | [diff] [blame] | 510 | }; |
| 511 | |
| 512 | static int j721e_4bit_sdhci_set_ios_post(struct sdhci_host *host) |
| 513 | { |
| 514 | struct udevice *dev = host->mmc->dev; |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 515 | struct am654_sdhci_plat *plat = dev_get_plat(dev); |
Faiz Abbas | e4425cb | 2020-02-26 13:44:34 +0530 | [diff] [blame] | 516 | u32 otap_del_sel, mask, val; |
| 517 | |
| 518 | otap_del_sel = plat->otap_del_sel[host->mmc->selected_mode]; |
| 519 | mask = OTAPDLYENA_MASK | OTAPDLYSEL_MASK; |
| 520 | val = (1 << OTAPDLYENA_SHIFT) | (otap_del_sel << OTAPDLYSEL_SHIFT); |
| 521 | regmap_update_bits(plat->base, PHY_CTRL4, mask, val); |
| 522 | |
Faiz Abbas | c73f04e | 2021-02-04 15:10:52 +0530 | [diff] [blame] | 523 | regmap_update_bits(plat->base, PHY_CTRL5, CLKBUFSEL_MASK, |
| 524 | plat->clkbuf_sel); |
| 525 | |
Faiz Abbas | e4425cb | 2020-02-26 13:44:34 +0530 | [diff] [blame] | 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | const struct sdhci_ops j721e_4bit_sdhci_ops = { |
Faiz Abbas | 7a7e2c7 | 2021-02-04 15:10:53 +0530 | [diff] [blame] | 530 | #ifdef MMC_SUPPORTS_TUNING |
| 531 | .platform_execute_tuning = am654_sdhci_execute_tuning, |
| 532 | #endif |
Faiz Abbas | e4425cb | 2020-02-26 13:44:34 +0530 | [diff] [blame] | 533 | .deferred_probe = am654_sdhci_deferred_probe, |
| 534 | .set_ios_post = &j721e_4bit_sdhci_set_ios_post, |
Faiz Abbas | 9c10cfe | 2021-02-04 15:10:55 +0530 | [diff] [blame] | 535 | .set_control_reg = sdhci_set_control_reg, |
Faiz Abbas | 36c8c5c | 2021-02-04 15:10:54 +0530 | [diff] [blame] | 536 | .write_b = am654_sdhci_write_b, |
Faiz Abbas | e4425cb | 2020-02-26 13:44:34 +0530 | [diff] [blame] | 537 | }; |
| 538 | |
| 539 | const struct am654_driver_data j721e_4bit_drv_data = { |
| 540 | .ops = &j721e_4bit_sdhci_ops, |
| 541 | .flags = IOMUX_PRESENT, |
| 542 | }; |
| 543 | |
Dave Gerlach | 057d6af | 2021-04-23 11:27:40 -0500 | [diff] [blame] | 544 | static const struct am654_driver_data sdhci_am64_8bit_drvdata = { |
| 545 | .ops = &am654_sdhci_ops, |
| 546 | .flags = DLL_PRESENT | DLL_CALIB, |
| 547 | }; |
| 548 | |
| 549 | static const struct am654_driver_data sdhci_am64_4bit_drvdata = { |
| 550 | .ops = &j721e_4bit_sdhci_ops, |
| 551 | .flags = IOMUX_PRESENT, |
| 552 | }; |
| 553 | |
Faiz Abbas | 2c2fc96 | 2021-02-04 15:10:50 +0530 | [diff] [blame] | 554 | const struct soc_attr am654_sdhci_soc_attr[] = { |
| 555 | { .family = "AM65X", .revision = "SR1.0", .data = &am654_sr1_drv_data}, |
| 556 | {/* sentinel */} |
| 557 | }; |
| 558 | |
Faiz Abbas | c6eb9e7 | 2020-02-26 13:44:33 +0530 | [diff] [blame] | 559 | static int sdhci_am654_get_otap_delay(struct udevice *dev, |
| 560 | struct mmc_config *cfg) |
| 561 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 562 | struct am654_sdhci_plat *plat = dev_get_plat(dev); |
Faiz Abbas | c6eb9e7 | 2020-02-26 13:44:33 +0530 | [diff] [blame] | 563 | int ret; |
| 564 | int i; |
| 565 | |
| 566 | /* ti,otap-del-sel-legacy is mandatory */ |
| 567 | ret = dev_read_u32(dev, "ti,otap-del-sel-legacy", |
| 568 | &plat->otap_del_sel[0]); |
| 569 | if (ret) |
| 570 | return ret; |
| 571 | /* |
| 572 | * Remove the corresponding capability if an otap-del-sel |
| 573 | * value is not found |
| 574 | */ |
| 575 | for (i = MMC_HS; i <= MMC_HS_400; i++) { |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 576 | ret = dev_read_u32(dev, td[i].otap_binding, |
| 577 | &plat->otap_del_sel[i]); |
Faiz Abbas | c6eb9e7 | 2020-02-26 13:44:33 +0530 | [diff] [blame] | 578 | if (ret) { |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 579 | dev_dbg(dev, "Couldn't find %s\n", td[i].otap_binding); |
Faiz Abbas | c6eb9e7 | 2020-02-26 13:44:33 +0530 | [diff] [blame] | 580 | /* |
| 581 | * Remove the corresponding capability |
| 582 | * if an otap-del-sel value is not found |
| 583 | */ |
| 584 | cfg->host_caps &= ~td[i].capability; |
| 585 | } |
Faiz Abbas | def2a0f | 2021-02-04 15:10:51 +0530 | [diff] [blame] | 586 | |
| 587 | if (td[i].itap_binding) |
| 588 | dev_read_u32(dev, td[i].itap_binding, |
| 589 | &plat->itap_del_sel[i]); |
Faiz Abbas | c6eb9e7 | 2020-02-26 13:44:33 +0530 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | return 0; |
| 593 | } |
| 594 | |
Faiz Abbas | d8fb309 | 2019-06-11 00:43:31 +0530 | [diff] [blame] | 595 | static int am654_sdhci_probe(struct udevice *dev) |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 596 | { |
Faiz Abbas | 8cc051e | 2020-01-16 19:42:19 +0530 | [diff] [blame] | 597 | struct am654_driver_data *drv_data = |
| 598 | (struct am654_driver_data *)dev_get_driver_data(dev); |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 599 | struct am654_sdhci_plat *plat = dev_get_plat(dev); |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 600 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 601 | struct sdhci_host *host = dev_get_priv(dev); |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 602 | struct mmc_config *cfg = &plat->cfg; |
Faiz Abbas | 2c2fc96 | 2021-02-04 15:10:50 +0530 | [diff] [blame] | 603 | const struct soc_attr *soc; |
| 604 | const struct am654_driver_data *soc_drv_data; |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 605 | struct clk clk; |
| 606 | unsigned long clock; |
| 607 | int ret; |
| 608 | |
Faiz Abbas | dc2bcc2 | 2020-01-16 19:42:18 +0530 | [diff] [blame] | 609 | ret = clk_get_by_name(dev, "clk_xin", &clk); |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 610 | if (ret) { |
| 611 | dev_err(dev, "failed to get clock\n"); |
| 612 | return ret; |
| 613 | } |
| 614 | |
| 615 | clock = clk_get_rate(&clk); |
| 616 | if (IS_ERR_VALUE(clock)) { |
| 617 | dev_err(dev, "failed to get rate\n"); |
| 618 | return clock; |
| 619 | } |
| 620 | |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 621 | host->max_clk = clock; |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 622 | host->mmc = &plat->mmc; |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 623 | host->mmc->dev = dev; |
Faiz Abbas | 36c8c5c | 2021-02-04 15:10:54 +0530 | [diff] [blame] | 624 | host->ops = drv_data->ops; |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 625 | ret = sdhci_setup_cfg(cfg, host, cfg->f_max, |
| 626 | AM654_SDHCI_MIN_FREQ); |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 627 | if (ret) |
| 628 | return ret; |
Faiz Abbas | 8cc051e | 2020-01-16 19:42:19 +0530 | [diff] [blame] | 629 | |
Faiz Abbas | c6eb9e7 | 2020-02-26 13:44:33 +0530 | [diff] [blame] | 630 | ret = sdhci_am654_get_otap_delay(dev, cfg); |
| 631 | if (ret) |
| 632 | return ret; |
| 633 | |
Faiz Abbas | 2c2fc96 | 2021-02-04 15:10:50 +0530 | [diff] [blame] | 634 | /* Update ops based on SoC revision */ |
| 635 | soc = soc_device_match(am654_sdhci_soc_attr); |
| 636 | if (soc && soc->data) { |
| 637 | soc_drv_data = soc->data; |
| 638 | host->ops = soc_drv_data->ops; |
| 639 | } |
| 640 | |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 641 | host->mmc->priv = host; |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 642 | upriv->mmc = host->mmc; |
| 643 | |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 644 | regmap_init_mem_index(dev_ofnode(dev), &plat->base, 1); |
| 645 | |
Faiz Abbas | e4425cb | 2020-02-26 13:44:34 +0530 | [diff] [blame] | 646 | return 0; |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 647 | } |
| 648 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 649 | static int am654_sdhci_of_to_plat(struct udevice *dev) |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 650 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 651 | struct am654_sdhci_plat *plat = dev_get_plat(dev); |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 652 | struct sdhci_host *host = dev_get_priv(dev); |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 653 | struct mmc_config *cfg = &plat->cfg; |
| 654 | u32 drv_strength; |
| 655 | int ret; |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 656 | |
| 657 | host->name = dev->name; |
Johan Jonker | 8d5d8e0 | 2023-03-13 01:32:04 +0100 | [diff] [blame] | 658 | host->ioaddr = dev_read_addr_ptr(dev); |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 659 | plat->non_removable = dev_read_bool(dev, "non-removable"); |
| 660 | |
Faiz Abbas | fd8be70 | 2019-06-13 10:29:51 +0530 | [diff] [blame] | 661 | if (plat->flags & DLL_PRESENT) { |
| 662 | ret = dev_read_u32(dev, "ti,trm-icp", &plat->trm_icp); |
| 663 | if (ret) |
| 664 | return ret; |
| 665 | |
| 666 | ret = dev_read_u32(dev, "ti,driver-strength-ohm", |
| 667 | &drv_strength); |
| 668 | if (ret) |
| 669 | return ret; |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 670 | |
Faiz Abbas | fd8be70 | 2019-06-13 10:29:51 +0530 | [diff] [blame] | 671 | switch (drv_strength) { |
| 672 | case 50: |
| 673 | plat->drv_strength = DRIVER_STRENGTH_50_OHM; |
| 674 | break; |
| 675 | case 33: |
| 676 | plat->drv_strength = DRIVER_STRENGTH_33_OHM; |
| 677 | break; |
| 678 | case 66: |
| 679 | plat->drv_strength = DRIVER_STRENGTH_66_OHM; |
| 680 | break; |
| 681 | case 100: |
| 682 | plat->drv_strength = DRIVER_STRENGTH_100_OHM; |
| 683 | break; |
| 684 | case 40: |
| 685 | plat->drv_strength = DRIVER_STRENGTH_40_OHM; |
| 686 | break; |
| 687 | default: |
| 688 | dev_err(dev, "Invalid driver strength\n"); |
| 689 | return -EINVAL; |
| 690 | } |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 691 | } |
| 692 | |
Aswath Govindraju | 4509fb6 | 2021-05-25 15:08:23 +0530 | [diff] [blame] | 693 | dev_read_u32(dev, "ti,strobe-sel", &plat->strb_sel); |
Faiz Abbas | c73f04e | 2021-02-04 15:10:52 +0530 | [diff] [blame] | 694 | dev_read_u32(dev, "ti,clkbuf-sel", &plat->clkbuf_sel); |
| 695 | |
Faiz Abbas | e9aed58 | 2019-06-11 00:43:38 +0530 | [diff] [blame] | 696 | ret = mmc_of_parse(dev, cfg); |
| 697 | if (ret) |
| 698 | return ret; |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 699 | |
| 700 | return 0; |
| 701 | } |
| 702 | |
Faiz Abbas | d8fb309 | 2019-06-11 00:43:31 +0530 | [diff] [blame] | 703 | static int am654_sdhci_bind(struct udevice *dev) |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 704 | { |
Faiz Abbas | 8cc051e | 2020-01-16 19:42:19 +0530 | [diff] [blame] | 705 | struct am654_driver_data *drv_data = |
| 706 | (struct am654_driver_data *)dev_get_driver_data(dev); |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 707 | struct am654_sdhci_plat *plat = dev_get_plat(dev); |
Faiz Abbas | 2c2fc96 | 2021-02-04 15:10:50 +0530 | [diff] [blame] | 708 | const struct soc_attr *soc; |
| 709 | const struct am654_driver_data *soc_drv_data; |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 710 | |
Faiz Abbas | 8cc051e | 2020-01-16 19:42:19 +0530 | [diff] [blame] | 711 | plat->flags = drv_data->flags; |
| 712 | |
Faiz Abbas | 2c2fc96 | 2021-02-04 15:10:50 +0530 | [diff] [blame] | 713 | /* Update flags based on SoC revision */ |
| 714 | soc = soc_device_match(am654_sdhci_soc_attr); |
| 715 | if (soc && soc->data) { |
| 716 | soc_drv_data = soc->data; |
| 717 | plat->flags = soc_drv_data->flags; |
| 718 | } |
| 719 | |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 720 | return sdhci_bind(dev, &plat->mmc, &plat->cfg); |
| 721 | } |
| 722 | |
Faiz Abbas | d8fb309 | 2019-06-11 00:43:31 +0530 | [diff] [blame] | 723 | static const struct udevice_id am654_sdhci_ids[] = { |
Faiz Abbas | fd8be70 | 2019-06-13 10:29:51 +0530 | [diff] [blame] | 724 | { |
| 725 | .compatible = "ti,am654-sdhci-5.1", |
Faiz Abbas | 8cc051e | 2020-01-16 19:42:19 +0530 | [diff] [blame] | 726 | .data = (ulong)&am654_drv_data, |
Faiz Abbas | fd8be70 | 2019-06-13 10:29:51 +0530 | [diff] [blame] | 727 | }, |
| 728 | { |
| 729 | .compatible = "ti,j721e-sdhci-8bit", |
Faiz Abbas | 8cc051e | 2020-01-16 19:42:19 +0530 | [diff] [blame] | 730 | .data = (ulong)&j721e_8bit_drv_data, |
Faiz Abbas | fd8be70 | 2019-06-13 10:29:51 +0530 | [diff] [blame] | 731 | }, |
| 732 | { |
| 733 | .compatible = "ti,j721e-sdhci-4bit", |
Faiz Abbas | 8cc051e | 2020-01-16 19:42:19 +0530 | [diff] [blame] | 734 | .data = (ulong)&j721e_4bit_drv_data, |
Faiz Abbas | fd8be70 | 2019-06-13 10:29:51 +0530 | [diff] [blame] | 735 | }, |
Dave Gerlach | 057d6af | 2021-04-23 11:27:40 -0500 | [diff] [blame] | 736 | { |
| 737 | .compatible = "ti,am64-sdhci-8bit", |
| 738 | .data = (ulong)&sdhci_am64_8bit_drvdata, |
| 739 | }, |
| 740 | { |
| 741 | .compatible = "ti,am64-sdhci-4bit", |
| 742 | .data = (ulong)&sdhci_am64_4bit_drvdata, |
| 743 | }, |
Aswath Govindraju | 71b9a7b | 2022-05-25 13:38:39 +0530 | [diff] [blame] | 744 | { |
| 745 | .compatible = "ti,am62-sdhci", |
| 746 | .data = (ulong)&sdhci_am64_4bit_drvdata, |
| 747 | }, |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 748 | { } |
| 749 | }; |
| 750 | |
Faiz Abbas | d8fb309 | 2019-06-11 00:43:31 +0530 | [diff] [blame] | 751 | U_BOOT_DRIVER(am654_sdhci_drv) = { |
| 752 | .name = "am654_sdhci", |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 753 | .id = UCLASS_MMC, |
Faiz Abbas | d8fb309 | 2019-06-11 00:43:31 +0530 | [diff] [blame] | 754 | .of_match = am654_sdhci_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 755 | .of_to_plat = am654_sdhci_of_to_plat, |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 756 | .ops = &sdhci_ops, |
Faiz Abbas | d8fb309 | 2019-06-11 00:43:31 +0530 | [diff] [blame] | 757 | .bind = am654_sdhci_bind, |
| 758 | .probe = am654_sdhci_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 759 | .priv_auto = sizeof(struct sdhci_host), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 760 | .plat_auto = sizeof(struct am654_sdhci_plat), |
Lokesh Vutla | bc9979f | 2018-08-27 15:57:54 +0530 | [diff] [blame] | 761 | }; |