Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | 06485cf | 2018-04-08 15:22:58 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2018 Marek Vasut <marek.vasut@gmail.com> |
Marek Vasut | 06485cf | 2018-04-08 15:22:58 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
Marek Vasut | 9f7baeb | 2020-04-04 12:45:04 +0200 | [diff] [blame] | 6 | #include <bouncebuf.h> |
Marek Vasut | 06485cf | 2018-04-08 15:22:58 +0200 | [diff] [blame] | 7 | #include <clk.h> |
| 8 | #include <fdtdec.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 10 | #include <malloc.h> |
Marek Vasut | 06485cf | 2018-04-08 15:22:58 +0200 | [diff] [blame] | 11 | #include <mmc.h> |
| 12 | #include <dm.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 14 | #include <dm/device_compat.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 15 | #include <linux/bitops.h> |
Marek Vasut | 06485cf | 2018-04-08 15:22:58 +0200 | [diff] [blame] | 16 | #include <linux/compat.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 17 | #include <linux/delay.h> |
Marek Vasut | 06485cf | 2018-04-08 15:22:58 +0200 | [diff] [blame] | 18 | #include <linux/dma-direction.h> |
| 19 | #include <linux/io.h> |
| 20 | #include <linux/sizes.h> |
| 21 | #include <power/regulator.h> |
Paul Barker | e22d1a0 | 2023-10-16 10:25:38 +0100 | [diff] [blame] | 22 | #include <reset.h> |
Marek Vasut | 06485cf | 2018-04-08 15:22:58 +0200 | [diff] [blame] | 23 | #include <asm/unaligned.h> |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 24 | #include "tmio-common.h" |
Marek Vasut | 06485cf | 2018-04-08 15:22:58 +0200 | [diff] [blame] | 25 | |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 26 | #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \ |
| 27 | CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \ |
| 28 | CONFIG_IS_ENABLED(MMC_HS400_SUPPORT) |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 29 | |
| 30 | /* SCC registers */ |
| 31 | #define RENESAS_SDHI_SCC_DTCNTL 0x800 |
Marek Vasut | b1d442b | 2019-05-19 02:33:06 +0200 | [diff] [blame] | 32 | #define RENESAS_SDHI_SCC_DTCNTL_TAPEN BIT(0) |
| 33 | #define RENESAS_SDHI_SCC_DTCNTL_TAPNUM_SHIFT 16 |
| 34 | #define RENESAS_SDHI_SCC_DTCNTL_TAPNUM_MASK 0xff |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 35 | #define RENESAS_SDHI_SCC_TAPSET 0x804 |
| 36 | #define RENESAS_SDHI_SCC_DT2FF 0x808 |
| 37 | #define RENESAS_SDHI_SCC_CKSEL 0x80c |
Marek Vasut | b1d442b | 2019-05-19 02:33:06 +0200 | [diff] [blame] | 38 | #define RENESAS_SDHI_SCC_CKSEL_DTSEL BIT(0) |
| 39 | #define RENESAS_SDHI_SCC_RVSCNTL 0x810 |
| 40 | #define RENESAS_SDHI_SCC_RVSCNTL_RVSEN BIT(0) |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 41 | #define RENESAS_SDHI_SCC_RVSREQ 0x814 |
Marek Vasut | b1d442b | 2019-05-19 02:33:06 +0200 | [diff] [blame] | 42 | #define RENESAS_SDHI_SCC_RVSREQ_RVSERR BIT(2) |
Marek Vasut | 52647a0 | 2019-11-23 13:36:23 +0100 | [diff] [blame] | 43 | #define RENESAS_SDHI_SCC_RVSREQ_REQTAPUP BIT(1) |
| 44 | #define RENESAS_SDHI_SCC_RVSREQ_REQTAPDOWN BIT(0) |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 45 | #define RENESAS_SDHI_SCC_SMPCMP 0x818 |
Marek Vasut | 52647a0 | 2019-11-23 13:36:23 +0100 | [diff] [blame] | 46 | #define RENESAS_SDHI_SCC_SMPCMP_CMD_ERR (BIT(24) | BIT(8)) |
| 47 | #define RENESAS_SDHI_SCC_SMPCMP_CMD_REQUP BIT(24) |
| 48 | #define RENESAS_SDHI_SCC_SMPCMP_CMD_REQDOWN BIT(8) |
Marek Vasut | b1d442b | 2019-05-19 02:33:06 +0200 | [diff] [blame] | 49 | #define RENESAS_SDHI_SCC_TMPPORT2 0x81c |
| 50 | #define RENESAS_SDHI_SCC_TMPPORT2_HS400EN BIT(31) |
| 51 | #define RENESAS_SDHI_SCC_TMPPORT2_HS400OSEL BIT(4) |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 52 | #define RENESAS_SDHI_SCC_TMPPORT3 0x828 |
| 53 | #define RENESAS_SDHI_SCC_TMPPORT3_OFFSET_0 3 |
| 54 | #define RENESAS_SDHI_SCC_TMPPORT3_OFFSET_1 2 |
| 55 | #define RENESAS_SDHI_SCC_TMPPORT3_OFFSET_2 1 |
| 56 | #define RENESAS_SDHI_SCC_TMPPORT3_OFFSET_3 0 |
| 57 | #define RENESAS_SDHI_SCC_TMPPORT3_OFFSET_MASK 0x3 |
| 58 | #define RENESAS_SDHI_SCC_TMPPORT4 0x82c |
| 59 | #define RENESAS_SDHI_SCC_TMPPORT4_DLL_ACC_START BIT(0) |
| 60 | #define RENESAS_SDHI_SCC_TMPPORT5 0x830 |
| 61 | #define RENESAS_SDHI_SCC_TMPPORT5_DLL_RW_SEL_R BIT(8) |
| 62 | #define RENESAS_SDHI_SCC_TMPPORT5_DLL_RW_SEL_W (0 << 8) |
| 63 | #define RENESAS_SDHI_SCC_TMPPORT5_DLL_ADR_MASK 0x3F |
| 64 | #define RENESAS_SDHI_SCC_TMPPORT6 0x834 |
| 65 | #define RENESAS_SDHI_SCC_TMPPORT7 0x838 |
| 66 | #define RENESAS_SDHI_SCC_TMPPORT_DISABLE_WP_CODE 0xa5000000 |
| 67 | #define RENESAS_SDHI_SCC_TMPPORT_CALIB_CODE_MASK 0x1f |
| 68 | #define RENESAS_SDHI_SCC_TMPPORT_MANUAL_MODE BIT(7) |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 69 | |
| 70 | #define RENESAS_SDHI_MAX_TAP 3 |
| 71 | |
Marek Vasut | 7b46176 | 2019-11-23 13:36:25 +0100 | [diff] [blame] | 72 | #define CALIB_TABLE_MAX (RENESAS_SDHI_SCC_TMPPORT_CALIB_CODE_MASK + 1) |
| 73 | |
Hai Pham | f0d3c07 | 2023-01-26 21:05:56 +0100 | [diff] [blame] | 74 | static const u8 r8a7796_rev13_calib_table[2][CALIB_TABLE_MAX] = { |
Hai Pham | a12185f | 2023-01-26 21:05:57 +0100 | [diff] [blame] | 75 | { 3, 3, 3, 3, 3, 3, 3, 4, 4, 5, 6, 7, 8, 9, 10, 15, |
| 76 | 16, 16, 16, 16, 16, 16, 17, 18, 18, 19, 20, 21, 22, 23, 24, 25 }, |
| 77 | { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 7, 8, 11, |
| 78 | 12, 17, 18, 18, 18, 18, 18, 18, 18, 19, 20, 21, 22, 23, 25, 25 } |
Marek Vasut | 7b46176 | 2019-11-23 13:36:25 +0100 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | static const u8 r8a77965_calib_table[2][CALIB_TABLE_MAX] = { |
Hai Pham | a12185f | 2023-01-26 21:05:57 +0100 | [diff] [blame] | 82 | { 1, 2, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15, 15, 16, |
| 83 | 17, 18, 19, 20, 21, 22, 23, 24, 25, 25, 26, 27, 28, 29, 30, 31 }, |
| 84 | { 2, 3, 4, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, |
| 85 | 17, 17, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31, 31, 31, 31 } |
Marek Vasut | 7b46176 | 2019-11-23 13:36:25 +0100 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | static const u8 r8a77990_calib_table[2][CALIB_TABLE_MAX] = { |
| 89 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 90 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
Hai Pham | a12185f | 2023-01-26 21:05:57 +0100 | [diff] [blame] | 91 | { 0, 0, 0, 1, 2, 3, 3, 4, 4, 4, 5, 5, 6, 8, 9, 10, |
| 92 | 11, 12, 13, 15, 16, 17, 17, 18, 18, 19, 20, 22, 24, 25, 26, 26 } |
Marek Vasut | 7b46176 | 2019-11-23 13:36:25 +0100 | [diff] [blame] | 93 | }; |
| 94 | |
Marek Vasut | 691c0b6 | 2024-02-27 17:05:58 +0100 | [diff] [blame] | 95 | static int rcar_is_gen3_mmc0(struct tmio_sd_priv *priv) |
Marek Vasut | 7b46176 | 2019-11-23 13:36:25 +0100 | [diff] [blame] | 96 | { |
| 97 | /* On R-Car Gen3, MMC0 is at 0xee140000 */ |
| 98 | return (uintptr_t)(priv->regbase) == 0xee140000; |
| 99 | } |
| 100 | |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 101 | static u32 sd_scc_tmpport_read32(struct tmio_sd_priv *priv, u32 addr) |
| 102 | { |
| 103 | /* read mode */ |
| 104 | tmio_sd_writel(priv, RENESAS_SDHI_SCC_TMPPORT5_DLL_RW_SEL_R | |
| 105 | (RENESAS_SDHI_SCC_TMPPORT5_DLL_ADR_MASK & addr), |
| 106 | RENESAS_SDHI_SCC_TMPPORT5); |
| 107 | |
| 108 | /* access start and stop */ |
| 109 | tmio_sd_writel(priv, RENESAS_SDHI_SCC_TMPPORT4_DLL_ACC_START, |
| 110 | RENESAS_SDHI_SCC_TMPPORT4); |
| 111 | tmio_sd_writel(priv, 0, RENESAS_SDHI_SCC_TMPPORT4); |
| 112 | |
| 113 | return tmio_sd_readl(priv, RENESAS_SDHI_SCC_TMPPORT7); |
| 114 | } |
| 115 | |
| 116 | static void sd_scc_tmpport_write32(struct tmio_sd_priv *priv, u32 addr, u32 val) |
| 117 | { |
| 118 | /* write mode */ |
| 119 | tmio_sd_writel(priv, RENESAS_SDHI_SCC_TMPPORT5_DLL_RW_SEL_W | |
| 120 | (RENESAS_SDHI_SCC_TMPPORT5_DLL_ADR_MASK & addr), |
| 121 | RENESAS_SDHI_SCC_TMPPORT5); |
| 122 | tmio_sd_writel(priv, val, RENESAS_SDHI_SCC_TMPPORT6); |
| 123 | |
| 124 | /* access start and stop */ |
| 125 | tmio_sd_writel(priv, RENESAS_SDHI_SCC_TMPPORT4_DLL_ACC_START, |
| 126 | RENESAS_SDHI_SCC_TMPPORT4); |
| 127 | tmio_sd_writel(priv, 0, RENESAS_SDHI_SCC_TMPPORT4); |
| 128 | } |
| 129 | |
Marek Vasut | 52647a0 | 2019-11-23 13:36:23 +0100 | [diff] [blame] | 130 | static bool renesas_sdhi_check_scc_error(struct udevice *dev) |
| 131 | { |
| 132 | struct tmio_sd_priv *priv = dev_get_priv(dev); |
| 133 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
| 134 | unsigned long new_tap = priv->tap_set; |
Marek Vasut | 531fc99 | 2019-11-23 13:36:24 +0100 | [diff] [blame] | 135 | unsigned long error_tap = priv->tap_set; |
Marek Vasut | 52647a0 | 2019-11-23 13:36:23 +0100 | [diff] [blame] | 136 | u32 reg, smpcmp; |
| 137 | |
| 138 | if ((priv->caps & TMIO_SD_CAP_RCAR_UHS) && |
| 139 | (mmc->selected_mode != UHS_SDR104) && |
| 140 | (mmc->selected_mode != MMC_HS_200) && |
| 141 | (mmc->selected_mode != MMC_HS_400) && |
| 142 | (priv->nrtaps != 4)) |
| 143 | return false; |
| 144 | |
| 145 | reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL); |
| 146 | /* Handle automatic tuning correction */ |
| 147 | if (reg & RENESAS_SDHI_SCC_RVSCNTL_RVSEN) { |
| 148 | reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSREQ); |
| 149 | if (reg & RENESAS_SDHI_SCC_RVSREQ_RVSERR) { |
| 150 | tmio_sd_writel(priv, 0, RENESAS_SDHI_SCC_RVSREQ); |
| 151 | return true; |
| 152 | } |
| 153 | |
| 154 | return false; |
| 155 | } |
| 156 | |
| 157 | /* Handle manual tuning correction */ |
| 158 | reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSREQ); |
| 159 | if (!reg) /* No error */ |
| 160 | return false; |
| 161 | |
| 162 | tmio_sd_writel(priv, 0, RENESAS_SDHI_SCC_RVSREQ); |
| 163 | |
| 164 | if (mmc->selected_mode == MMC_HS_400) { |
| 165 | /* |
| 166 | * Correction Error Status contains CMD and DAT signal status. |
| 167 | * In HS400, DAT signal based on DS signal, not CLK. |
| 168 | * Therefore, use only CMD status. |
| 169 | */ |
| 170 | smpcmp = tmio_sd_readl(priv, RENESAS_SDHI_SCC_SMPCMP) & |
| 171 | RENESAS_SDHI_SCC_SMPCMP_CMD_ERR; |
| 172 | |
| 173 | switch (smpcmp) { |
| 174 | case 0: |
| 175 | return false; /* No error in CMD signal */ |
| 176 | case RENESAS_SDHI_SCC_SMPCMP_CMD_REQUP: |
| 177 | new_tap = (priv->tap_set + |
| 178 | priv->tap_num + 1) % priv->tap_num; |
Marek Vasut | 531fc99 | 2019-11-23 13:36:24 +0100 | [diff] [blame] | 179 | error_tap = (priv->tap_set + |
| 180 | priv->tap_num - 1) % priv->tap_num; |
Marek Vasut | 52647a0 | 2019-11-23 13:36:23 +0100 | [diff] [blame] | 181 | break; |
| 182 | case RENESAS_SDHI_SCC_SMPCMP_CMD_REQDOWN: |
| 183 | new_tap = (priv->tap_set + |
| 184 | priv->tap_num - 1) % priv->tap_num; |
Marek Vasut | 531fc99 | 2019-11-23 13:36:24 +0100 | [diff] [blame] | 185 | error_tap = (priv->tap_set + |
| 186 | priv->tap_num + 1) % priv->tap_num; |
Marek Vasut | 52647a0 | 2019-11-23 13:36:23 +0100 | [diff] [blame] | 187 | break; |
| 188 | default: |
| 189 | return true; /* Need re-tune */ |
| 190 | } |
| 191 | |
Marek Vasut | 531fc99 | 2019-11-23 13:36:24 +0100 | [diff] [blame] | 192 | if (priv->hs400_bad_tap & BIT(new_tap)) { |
| 193 | /* |
| 194 | * New tap is bad tap (cannot change). |
| 195 | * Compare with HS200 tuning result. |
| 196 | * In HS200 tuning, when smpcmp[error_tap] |
| 197 | * is OK, retune is executed. |
| 198 | */ |
| 199 | if (priv->smpcmp & BIT(error_tap)) |
| 200 | return true; /* Need retune */ |
| 201 | |
| 202 | return false; /* cannot change */ |
| 203 | } |
| 204 | |
Marek Vasut | 52647a0 | 2019-11-23 13:36:23 +0100 | [diff] [blame] | 205 | priv->tap_set = new_tap; |
| 206 | } else { |
| 207 | if (reg & RENESAS_SDHI_SCC_RVSREQ_RVSERR) |
| 208 | return true; /* Need re-tune */ |
| 209 | else if (reg & RENESAS_SDHI_SCC_RVSREQ_REQTAPUP) |
| 210 | priv->tap_set = (priv->tap_set + |
| 211 | priv->tap_num + 1) % priv->tap_num; |
| 212 | else if (reg & RENESAS_SDHI_SCC_RVSREQ_REQTAPDOWN) |
| 213 | priv->tap_set = (priv->tap_set + |
| 214 | priv->tap_num - 1) % priv->tap_num; |
| 215 | else |
| 216 | return false; |
| 217 | } |
| 218 | |
| 219 | /* Set TAP position */ |
| 220 | tmio_sd_writel(priv, priv->tap_set >> ((priv->nrtaps == 4) ? 1 : 0), |
| 221 | RENESAS_SDHI_SCC_TAPSET); |
| 222 | |
| 223 | return false; |
| 224 | } |
| 225 | |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 226 | static void renesas_sdhi_adjust_hs400_mode_enable(struct tmio_sd_priv *priv) |
| 227 | { |
| 228 | u32 calib_code; |
| 229 | |
| 230 | if (!priv->adjust_hs400_enable) |
| 231 | return; |
| 232 | |
| 233 | if (!priv->needs_adjust_hs400) |
| 234 | return; |
| 235 | |
Marek Vasut | 7b46176 | 2019-11-23 13:36:25 +0100 | [diff] [blame] | 236 | if (!priv->adjust_hs400_calib_table) |
| 237 | return; |
| 238 | |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 239 | /* |
| 240 | * Enabled Manual adjust HS400 mode |
| 241 | * |
| 242 | * 1) Disabled Write Protect |
| 243 | * W(addr=0x00, WP_DISABLE_CODE) |
Marek Vasut | 7b46176 | 2019-11-23 13:36:25 +0100 | [diff] [blame] | 244 | * |
| 245 | * 2) Read Calibration code |
| 246 | * read_value = R(addr=0x26) |
| 247 | * 3) Refer to calibration table |
| 248 | * Calibration code = table[read_value] |
| 249 | * 4) Enabled Manual Calibration |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 250 | * W(addr=0x22, manual mode | Calibration code) |
Marek Vasut | 7b46176 | 2019-11-23 13:36:25 +0100 | [diff] [blame] | 251 | * 5) Set Offset value to TMPPORT3 Reg |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 252 | */ |
| 253 | sd_scc_tmpport_write32(priv, 0x00, |
| 254 | RENESAS_SDHI_SCC_TMPPORT_DISABLE_WP_CODE); |
| 255 | calib_code = sd_scc_tmpport_read32(priv, 0x26); |
| 256 | calib_code &= RENESAS_SDHI_SCC_TMPPORT_CALIB_CODE_MASK; |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 257 | sd_scc_tmpport_write32(priv, 0x22, |
| 258 | RENESAS_SDHI_SCC_TMPPORT_MANUAL_MODE | |
Marek Vasut | 7b46176 | 2019-11-23 13:36:25 +0100 | [diff] [blame] | 259 | priv->adjust_hs400_calib_table[calib_code]); |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 260 | tmio_sd_writel(priv, priv->adjust_hs400_offset, |
| 261 | RENESAS_SDHI_SCC_TMPPORT3); |
| 262 | |
| 263 | /* Clear flag */ |
| 264 | priv->needs_adjust_hs400 = false; |
| 265 | } |
| 266 | |
| 267 | static void renesas_sdhi_adjust_hs400_mode_disable(struct tmio_sd_priv *priv) |
| 268 | { |
| 269 | |
| 270 | /* Disabled Manual adjust HS400 mode |
| 271 | * |
| 272 | * 1) Disabled Write Protect |
| 273 | * W(addr=0x00, WP_DISABLE_CODE) |
| 274 | * 2) Disabled Manual Calibration |
| 275 | * W(addr=0x22, 0) |
| 276 | * 3) Clear offset value to TMPPORT3 Reg |
| 277 | */ |
| 278 | sd_scc_tmpport_write32(priv, 0x00, |
| 279 | RENESAS_SDHI_SCC_TMPPORT_DISABLE_WP_CODE); |
| 280 | sd_scc_tmpport_write32(priv, 0x22, 0); |
| 281 | tmio_sd_writel(priv, 0, RENESAS_SDHI_SCC_TMPPORT3); |
| 282 | } |
| 283 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 284 | static unsigned int renesas_sdhi_init_tuning(struct tmio_sd_priv *priv) |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 285 | { |
| 286 | u32 reg; |
| 287 | |
| 288 | /* Initialize SCC */ |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 289 | tmio_sd_writel(priv, 0, TMIO_SD_INFO1); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 290 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 291 | reg = tmio_sd_readl(priv, TMIO_SD_CLKCTL); |
| 292 | reg &= ~TMIO_SD_CLKCTL_SCLKEN; |
| 293 | tmio_sd_writel(priv, reg, TMIO_SD_CLKCTL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 294 | |
| 295 | /* Set sampling clock selection range */ |
Marek Vasut | da4873d | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 296 | tmio_sd_writel(priv, (0x8 << RENESAS_SDHI_SCC_DTCNTL_TAPNUM_SHIFT) | |
| 297 | RENESAS_SDHI_SCC_DTCNTL_TAPEN, |
| 298 | RENESAS_SDHI_SCC_DTCNTL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 299 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 300 | reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_CKSEL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 301 | reg |= RENESAS_SDHI_SCC_CKSEL_DTSEL; |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 302 | tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_CKSEL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 303 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 304 | reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 305 | reg &= ~RENESAS_SDHI_SCC_RVSCNTL_RVSEN; |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 306 | tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_RVSCNTL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 307 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 308 | tmio_sd_writel(priv, 0x300 /* scc_tappos */, |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 309 | RENESAS_SDHI_SCC_DT2FF); |
| 310 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 311 | reg = tmio_sd_readl(priv, TMIO_SD_CLKCTL); |
| 312 | reg |= TMIO_SD_CLKCTL_SCLKEN; |
| 313 | tmio_sd_writel(priv, reg, TMIO_SD_CLKCTL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 314 | |
| 315 | /* Read TAPNUM */ |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 316 | return (tmio_sd_readl(priv, RENESAS_SDHI_SCC_DTCNTL) >> |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 317 | RENESAS_SDHI_SCC_DTCNTL_TAPNUM_SHIFT) & |
| 318 | RENESAS_SDHI_SCC_DTCNTL_TAPNUM_MASK; |
| 319 | } |
| 320 | |
Marek Vasut | cfb65b4 | 2023-11-05 23:42:45 +0100 | [diff] [blame] | 321 | static void renesas_sdhi_reset_tuning(struct tmio_sd_priv *priv, bool clk_disable) |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 322 | { |
| 323 | u32 reg; |
| 324 | |
| 325 | /* Reset SCC */ |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 326 | reg = tmio_sd_readl(priv, TMIO_SD_CLKCTL); |
| 327 | reg &= ~TMIO_SD_CLKCTL_SCLKEN; |
| 328 | tmio_sd_writel(priv, reg, TMIO_SD_CLKCTL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 329 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 330 | reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_CKSEL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 331 | reg &= ~RENESAS_SDHI_SCC_CKSEL_DTSEL; |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 332 | tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_CKSEL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 333 | |
Marek Vasut | efea7a8 | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 334 | reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_TMPPORT2); |
| 335 | reg &= ~(RENESAS_SDHI_SCC_TMPPORT2_HS400EN | |
| 336 | RENESAS_SDHI_SCC_TMPPORT2_HS400OSEL); |
| 337 | tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_TMPPORT2); |
| 338 | |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 339 | /* Disable HS400 mode adjustment */ |
| 340 | renesas_sdhi_adjust_hs400_mode_disable(priv); |
| 341 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 342 | reg = tmio_sd_readl(priv, TMIO_SD_CLKCTL); |
| 343 | reg |= TMIO_SD_CLKCTL_SCLKEN; |
| 344 | tmio_sd_writel(priv, reg, TMIO_SD_CLKCTL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 345 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 346 | reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 347 | reg &= ~RENESAS_SDHI_SCC_RVSCNTL_RVSEN; |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 348 | tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_RVSCNTL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 349 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 350 | reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 351 | reg &= ~RENESAS_SDHI_SCC_RVSCNTL_RVSEN; |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 352 | tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_RVSCNTL); |
Marek Vasut | cfb65b4 | 2023-11-05 23:42:45 +0100 | [diff] [blame] | 353 | |
| 354 | if (clk_disable) { |
| 355 | reg = tmio_sd_readl(priv, TMIO_SD_CLKCTL); |
| 356 | reg &= ~TMIO_SD_CLKCTL_SCLKEN; |
| 357 | tmio_sd_writel(priv, reg, TMIO_SD_CLKCTL); |
| 358 | } |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 361 | static int renesas_sdhi_hs400(struct udevice *dev) |
| 362 | { |
| 363 | struct tmio_sd_priv *priv = dev_get_priv(dev); |
| 364 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
| 365 | bool hs400 = (mmc->selected_mode == MMC_HS_400); |
| 366 | int ret, taps = hs400 ? priv->nrtaps : 8; |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 367 | const u32 sdn_rate = 200000000; |
| 368 | u32 sdnh_rate = 800000000; |
Marek Vasut | 531fc99 | 2019-11-23 13:36:24 +0100 | [diff] [blame] | 369 | unsigned long new_tap; |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 370 | u32 reg; |
| 371 | |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 372 | if (clk_valid(&priv->clkh) && !priv->needs_clkh_fallback) { |
| 373 | /* HS400 on 4tap SoC => SDnH=400 MHz, SDn=200 MHz */ |
| 374 | if (taps == 4) |
| 375 | sdnh_rate /= 2; |
| 376 | ret = clk_set_rate(&priv->clkh, sdnh_rate); |
| 377 | if (ret < 0) |
| 378 | return ret; |
| 379 | } |
| 380 | |
| 381 | ret = clk_set_rate(&priv->clk, sdn_rate); |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 382 | if (ret < 0) |
| 383 | return ret; |
| 384 | |
Marek Vasut | 242c63d | 2019-11-23 13:36:22 +0100 | [diff] [blame] | 385 | reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL); |
| 386 | reg &= ~RENESAS_SDHI_SCC_RVSCNTL_RVSEN; |
| 387 | tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_RVSCNTL); |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 388 | |
| 389 | reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_TMPPORT2); |
| 390 | if (hs400) { |
| 391 | reg |= RENESAS_SDHI_SCC_TMPPORT2_HS400EN | |
| 392 | RENESAS_SDHI_SCC_TMPPORT2_HS400OSEL; |
| 393 | } else { |
| 394 | reg &= ~(RENESAS_SDHI_SCC_TMPPORT2_HS400EN | |
| 395 | RENESAS_SDHI_SCC_TMPPORT2_HS400OSEL); |
| 396 | } |
| 397 | |
| 398 | tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_TMPPORT2); |
| 399 | |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 400 | /* Disable HS400 mode adjustment */ |
| 401 | if (!hs400) |
| 402 | renesas_sdhi_adjust_hs400_mode_disable(priv); |
| 403 | |
Marek Vasut | 3d42a07 | 2019-02-19 19:32:28 +0100 | [diff] [blame] | 404 | tmio_sd_writel(priv, (0x8 << RENESAS_SDHI_SCC_DTCNTL_TAPNUM_SHIFT) | |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 405 | RENESAS_SDHI_SCC_DTCNTL_TAPEN, |
| 406 | RENESAS_SDHI_SCC_DTCNTL); |
| 407 | |
Marek Vasut | 531fc99 | 2019-11-23 13:36:24 +0100 | [diff] [blame] | 408 | /* Avoid bad TAP */ |
| 409 | if (priv->hs400_bad_tap & BIT(priv->tap_set)) { |
| 410 | new_tap = (priv->tap_set + |
| 411 | priv->tap_num + 1) % priv->tap_num; |
| 412 | |
| 413 | if (priv->hs400_bad_tap & BIT(new_tap)) |
| 414 | new_tap = (priv->tap_set + |
| 415 | priv->tap_num - 1) % priv->tap_num; |
| 416 | |
| 417 | if (priv->hs400_bad_tap & BIT(new_tap)) { |
| 418 | new_tap = priv->tap_set; |
| 419 | debug("Three consecutive bad tap is prohibited\n"); |
| 420 | } |
| 421 | |
| 422 | priv->tap_set = new_tap; |
| 423 | tmio_sd_writel(priv, priv->tap_set, RENESAS_SDHI_SCC_TAPSET); |
| 424 | } |
| 425 | |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 426 | if (taps == 4) { |
| 427 | tmio_sd_writel(priv, priv->tap_set >> 1, |
| 428 | RENESAS_SDHI_SCC_TAPSET); |
Marek Vasut | 1a95303 | 2019-11-23 13:36:20 +0100 | [diff] [blame] | 429 | tmio_sd_writel(priv, hs400 ? 0x100 : 0x300, |
| 430 | RENESAS_SDHI_SCC_DT2FF); |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 431 | } else { |
| 432 | tmio_sd_writel(priv, priv->tap_set, RENESAS_SDHI_SCC_TAPSET); |
Marek Vasut | 1a95303 | 2019-11-23 13:36:20 +0100 | [diff] [blame] | 433 | tmio_sd_writel(priv, 0x300, RENESAS_SDHI_SCC_DT2FF); |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_CKSEL); |
| 437 | reg |= RENESAS_SDHI_SCC_CKSEL_DTSEL; |
| 438 | tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_CKSEL); |
| 439 | |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 440 | /* Execute adjust hs400 offset after setting to HS400 mode */ |
| 441 | if (hs400) |
| 442 | priv->needs_adjust_hs400 = true; |
| 443 | |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 444 | return 0; |
| 445 | } |
| 446 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 447 | static void renesas_sdhi_prepare_tuning(struct tmio_sd_priv *priv, |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 448 | unsigned long tap) |
| 449 | { |
| 450 | /* Set sampling clock position */ |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 451 | tmio_sd_writel(priv, tap, RENESAS_SDHI_SCC_TAPSET); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 452 | } |
| 453 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 454 | static unsigned int renesas_sdhi_compare_scc_data(struct tmio_sd_priv *priv) |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 455 | { |
| 456 | /* Get comparison of sampling data */ |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 457 | return tmio_sd_readl(priv, RENESAS_SDHI_SCC_SMPCMP); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 458 | } |
| 459 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 460 | static int renesas_sdhi_select_tuning(struct tmio_sd_priv *priv, |
Marek Vasut | 0555dc6 | 2019-11-23 13:36:18 +0100 | [diff] [blame] | 461 | unsigned int taps) |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 462 | { |
| 463 | unsigned long tap_cnt; /* counter of tuning success */ |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 464 | unsigned long tap_start;/* start position of tuning success */ |
| 465 | unsigned long tap_end; /* end position of tuning success */ |
| 466 | unsigned long ntap; /* temporary counter of tuning success */ |
| 467 | unsigned long match_cnt;/* counter of matching data */ |
| 468 | unsigned long i; |
| 469 | bool select = false; |
| 470 | u32 reg; |
| 471 | |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 472 | priv->needs_adjust_hs400 = false; |
| 473 | |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 474 | /* Clear SCC_RVSREQ */ |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 475 | tmio_sd_writel(priv, 0, RENESAS_SDHI_SCC_RVSREQ); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 476 | |
| 477 | /* Merge the results */ |
Marek Vasut | d9d09e3 | 2019-11-23 13:36:17 +0100 | [diff] [blame] | 478 | for (i = 0; i < priv->tap_num * 2; i++) { |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 479 | if (!(taps & BIT(i))) { |
Marek Vasut | d9d09e3 | 2019-11-23 13:36:17 +0100 | [diff] [blame] | 480 | taps &= ~BIT(i % priv->tap_num); |
| 481 | taps &= ~BIT((i % priv->tap_num) + priv->tap_num); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 482 | } |
Marek Vasut | 0555dc6 | 2019-11-23 13:36:18 +0100 | [diff] [blame] | 483 | if (!(priv->smpcmp & BIT(i))) { |
| 484 | priv->smpcmp &= ~BIT(i % priv->tap_num); |
| 485 | priv->smpcmp &= ~BIT((i % priv->tap_num) + priv->tap_num); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | |
| 489 | /* |
| 490 | * Find the longest consecutive run of successful probes. If that |
| 491 | * is more than RENESAS_SDHI_MAX_TAP probes long then use the |
| 492 | * center index as the tap. |
| 493 | */ |
| 494 | tap_cnt = 0; |
| 495 | ntap = 0; |
| 496 | tap_start = 0; |
| 497 | tap_end = 0; |
Marek Vasut | d9d09e3 | 2019-11-23 13:36:17 +0100 | [diff] [blame] | 498 | for (i = 0; i < priv->tap_num * 2; i++) { |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 499 | if (taps & BIT(i)) |
| 500 | ntap++; |
| 501 | else { |
| 502 | if (ntap > tap_cnt) { |
| 503 | tap_start = i - ntap; |
| 504 | tap_end = i - 1; |
| 505 | tap_cnt = ntap; |
| 506 | } |
| 507 | ntap = 0; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | if (ntap > tap_cnt) { |
| 512 | tap_start = i - ntap; |
| 513 | tap_end = i - 1; |
| 514 | tap_cnt = ntap; |
| 515 | } |
| 516 | |
| 517 | /* |
| 518 | * If all of the TAP is OK, the sampling clock position is selected by |
| 519 | * identifying the change point of data. |
| 520 | */ |
Marek Vasut | d9d09e3 | 2019-11-23 13:36:17 +0100 | [diff] [blame] | 521 | if (tap_cnt == priv->tap_num * 2) { |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 522 | match_cnt = 0; |
| 523 | ntap = 0; |
| 524 | tap_start = 0; |
| 525 | tap_end = 0; |
Marek Vasut | d9d09e3 | 2019-11-23 13:36:17 +0100 | [diff] [blame] | 526 | for (i = 0; i < priv->tap_num * 2; i++) { |
Marek Vasut | 0555dc6 | 2019-11-23 13:36:18 +0100 | [diff] [blame] | 527 | if (priv->smpcmp & BIT(i)) |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 528 | ntap++; |
| 529 | else { |
| 530 | if (ntap > match_cnt) { |
| 531 | tap_start = i - ntap; |
| 532 | tap_end = i - 1; |
| 533 | match_cnt = ntap; |
| 534 | } |
| 535 | ntap = 0; |
| 536 | } |
| 537 | } |
| 538 | if (ntap > match_cnt) { |
| 539 | tap_start = i - ntap; |
| 540 | tap_end = i - 1; |
| 541 | match_cnt = ntap; |
| 542 | } |
| 543 | if (match_cnt) |
| 544 | select = true; |
| 545 | } else if (tap_cnt >= RENESAS_SDHI_MAX_TAP) |
| 546 | select = true; |
| 547 | |
| 548 | if (select) |
Marek Vasut | d9d09e3 | 2019-11-23 13:36:17 +0100 | [diff] [blame] | 549 | priv->tap_set = ((tap_start + tap_end) / 2) % priv->tap_num; |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 550 | else |
| 551 | return -EIO; |
| 552 | |
| 553 | /* Set SCC */ |
Marek Vasut | 1ebb9d6 | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 554 | tmio_sd_writel(priv, priv->tap_set, RENESAS_SDHI_SCC_TAPSET); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 555 | |
| 556 | /* Enable auto re-tuning */ |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 557 | reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 558 | reg |= RENESAS_SDHI_SCC_RVSCNTL_RVSEN; |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 559 | tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_RVSCNTL); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 560 | |
| 561 | return 0; |
| 562 | } |
| 563 | |
| 564 | int renesas_sdhi_execute_tuning(struct udevice *dev, uint opcode) |
| 565 | { |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 566 | struct tmio_sd_priv *priv = dev_get_priv(dev); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 567 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 568 | struct mmc *mmc = upriv->mmc; |
| 569 | unsigned int tap_num; |
Marek Vasut | 0555dc6 | 2019-11-23 13:36:18 +0100 | [diff] [blame] | 570 | unsigned int taps = 0; |
Marek Vasut | aaf5927 | 2024-02-20 09:38:45 +0100 | [diff] [blame] | 571 | int i, ret = 0, sret; |
| 572 | u32 caps, reg; |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 573 | |
| 574 | /* Only supported on Renesas RCar */ |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 575 | if (!(priv->caps & TMIO_SD_CAP_RCAR_UHS)) |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 576 | return -EINVAL; |
| 577 | |
| 578 | /* clock tuning is not needed for upto 52MHz */ |
| 579 | if (!((mmc->selected_mode == MMC_HS_200) || |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 580 | (mmc->selected_mode == MMC_HS_400) || |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 581 | (mmc->selected_mode == UHS_SDR104) || |
| 582 | (mmc->selected_mode == UHS_SDR50))) |
| 583 | return 0; |
| 584 | |
| 585 | tap_num = renesas_sdhi_init_tuning(priv); |
| 586 | if (!tap_num) |
| 587 | /* Tuning is not supported */ |
| 588 | goto out; |
| 589 | |
Marek Vasut | d9d09e3 | 2019-11-23 13:36:17 +0100 | [diff] [blame] | 590 | priv->tap_num = tap_num; |
| 591 | |
| 592 | if (priv->tap_num * 2 >= sizeof(taps) * 8) { |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 593 | dev_err(dev, |
| 594 | "Too many taps, skipping tuning. Please consider updating size of taps field of tmio_mmc_host\n"); |
| 595 | goto out; |
| 596 | } |
| 597 | |
Marek Vasut | 0555dc6 | 2019-11-23 13:36:18 +0100 | [diff] [blame] | 598 | priv->smpcmp = 0; |
| 599 | |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 600 | /* Issue CMD19 twice for each tap */ |
Marek Vasut | d9d09e3 | 2019-11-23 13:36:17 +0100 | [diff] [blame] | 601 | for (i = 0; i < 2 * priv->tap_num; i++) { |
| 602 | renesas_sdhi_prepare_tuning(priv, i % priv->tap_num); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 603 | |
| 604 | /* Force PIO for the tuning */ |
| 605 | caps = priv->caps; |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 606 | priv->caps &= ~TMIO_SD_CAP_DMA_INTERNAL; |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 607 | |
Marek Vasut | dad81fb | 2024-02-20 09:36:23 +0100 | [diff] [blame] | 608 | ret = mmc_send_tuning(mmc, opcode); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 609 | |
| 610 | priv->caps = caps; |
| 611 | |
| 612 | if (ret == 0) |
| 613 | taps |= BIT(i); |
| 614 | |
Marek Vasut | aaf5927 | 2024-02-20 09:38:45 +0100 | [diff] [blame] | 615 | reg = renesas_sdhi_compare_scc_data(priv); |
| 616 | if (reg == 0) |
Marek Vasut | 0555dc6 | 2019-11-23 13:36:18 +0100 | [diff] [blame] | 617 | priv->smpcmp |= BIT(i); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 618 | |
| 619 | mdelay(1); |
Hai Pham | 021f7f7 | 2023-06-20 00:38:25 +0200 | [diff] [blame] | 620 | |
| 621 | /* |
| 622 | * eMMC specification specifies that CMD12 can be used to stop a tuning |
| 623 | * command, but SD specification does not, so do nothing unless it is |
| 624 | * eMMC. |
| 625 | */ |
| 626 | if (ret && (opcode == MMC_CMD_SEND_TUNING_BLOCK_HS200)) { |
Marek Vasut | aaf5927 | 2024-02-20 09:38:45 +0100 | [diff] [blame] | 627 | sret = mmc_send_stop_transmission(mmc, false); |
| 628 | if (sret < 0) |
| 629 | dev_dbg(dev, "Tuning abort fail (%d)\n", sret); |
Hai Pham | 021f7f7 | 2023-06-20 00:38:25 +0200 | [diff] [blame] | 630 | } |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 631 | } |
| 632 | |
Marek Vasut | 0555dc6 | 2019-11-23 13:36:18 +0100 | [diff] [blame] | 633 | ret = renesas_sdhi_select_tuning(priv, taps); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 634 | |
| 635 | out: |
| 636 | if (ret < 0) { |
| 637 | dev_warn(dev, "Tuning procedure failed\n"); |
Marek Vasut | cfb65b4 | 2023-11-05 23:42:45 +0100 | [diff] [blame] | 638 | renesas_sdhi_reset_tuning(priv, true); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | return ret; |
| 642 | } |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 643 | #else |
| 644 | static int renesas_sdhi_hs400(struct udevice *dev) |
| 645 | { |
| 646 | return 0; |
| 647 | } |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 648 | #endif |
| 649 | |
| 650 | static int renesas_sdhi_set_ios(struct udevice *dev) |
| 651 | { |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 652 | struct tmio_sd_priv *priv = dev_get_priv(dev); |
| 653 | u32 tmp; |
| 654 | int ret; |
Marek Vasut | 33d3818 | 2018-04-09 20:47:31 +0200 | [diff] [blame] | 655 | |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 656 | /* Stop the clock before changing its rate to avoid a glitch signal */ |
| 657 | tmp = tmio_sd_readl(priv, TMIO_SD_CLKCTL); |
| 658 | tmp &= ~TMIO_SD_CLKCTL_SCLKEN; |
| 659 | tmio_sd_writel(priv, tmp, TMIO_SD_CLKCTL); |
Marek Vasut | 33d3818 | 2018-04-09 20:47:31 +0200 | [diff] [blame] | 660 | |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 661 | ret = renesas_sdhi_hs400(dev); |
| 662 | if (ret) |
| 663 | return ret; |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 664 | |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 665 | ret = tmio_sd_set_ios(dev); |
| 666 | |
| 667 | mdelay(10); |
| 668 | |
| 669 | #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \ |
| 670 | CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \ |
| 671 | CONFIG_IS_ENABLED(MMC_HS400_SUPPORT) |
| 672 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
| 673 | if ((priv->caps & TMIO_SD_CAP_RCAR_UHS) && |
| 674 | (mmc->selected_mode != UHS_SDR104) && |
| 675 | (mmc->selected_mode != MMC_HS_200) && |
| 676 | (mmc->selected_mode != MMC_HS_400)) { |
Marek Vasut | cfb65b4 | 2023-11-05 23:42:45 +0100 | [diff] [blame] | 677 | renesas_sdhi_reset_tuning(priv, mmc->clk_disable); |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 678 | } |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 679 | #endif |
| 680 | |
| 681 | return ret; |
| 682 | } |
| 683 | |
Marek Vasut | 576a6d9 | 2018-10-28 19:28:56 +0100 | [diff] [blame] | 684 | #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) |
Sam Protsenko | db174c6 | 2019-08-14 22:52:51 +0300 | [diff] [blame] | 685 | static int renesas_sdhi_wait_dat0(struct udevice *dev, int state, |
| 686 | int timeout_us) |
Marek Vasut | 576a6d9 | 2018-10-28 19:28:56 +0100 | [diff] [blame] | 687 | { |
| 688 | int ret = -ETIMEDOUT; |
| 689 | bool dat0_high; |
| 690 | bool target_dat0_high = !!state; |
| 691 | struct tmio_sd_priv *priv = dev_get_priv(dev); |
| 692 | |
Sam Protsenko | db174c6 | 2019-08-14 22:52:51 +0300 | [diff] [blame] | 693 | timeout_us = DIV_ROUND_UP(timeout_us, 10); /* check every 10 us. */ |
| 694 | while (timeout_us--) { |
Marek Vasut | 576a6d9 | 2018-10-28 19:28:56 +0100 | [diff] [blame] | 695 | dat0_high = !!(tmio_sd_readl(priv, TMIO_SD_INFO2) & TMIO_SD_INFO2_DAT0); |
| 696 | if (dat0_high == target_dat0_high) { |
| 697 | ret = 0; |
| 698 | break; |
| 699 | } |
| 700 | udelay(10); |
| 701 | } |
| 702 | |
| 703 | return ret; |
| 704 | } |
| 705 | #endif |
| 706 | |
Marek Vasut | 9f7baeb | 2020-04-04 12:45:04 +0200 | [diff] [blame] | 707 | #define RENESAS_SDHI_DMA_ALIGNMENT 128 |
| 708 | |
Marek Vasut | 3d5256e | 2020-04-04 12:45:06 +0200 | [diff] [blame] | 709 | static int renesas_sdhi_addr_aligned_gen(uintptr_t ubuf, |
| 710 | size_t len, size_t len_aligned) |
Marek Vasut | 9f7baeb | 2020-04-04 12:45:04 +0200 | [diff] [blame] | 711 | { |
Marek Vasut | 9f7baeb | 2020-04-04 12:45:04 +0200 | [diff] [blame] | 712 | /* Check if start is aligned */ |
| 713 | if (!IS_ALIGNED(ubuf, RENESAS_SDHI_DMA_ALIGNMENT)) { |
Marek Vasut | 3d5256e | 2020-04-04 12:45:06 +0200 | [diff] [blame] | 714 | debug("Unaligned buffer address %lx\n", ubuf); |
Marek Vasut | 9f7baeb | 2020-04-04 12:45:04 +0200 | [diff] [blame] | 715 | return 0; |
| 716 | } |
| 717 | |
| 718 | /* Check if length is aligned */ |
Marek Vasut | 3d5256e | 2020-04-04 12:45:06 +0200 | [diff] [blame] | 719 | if (len != len_aligned) { |
| 720 | debug("Unaligned buffer length %zu\n", len); |
Marek Vasut | 9f7baeb | 2020-04-04 12:45:04 +0200 | [diff] [blame] | 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | #ifdef CONFIG_PHYS_64BIT |
| 725 | /* Check if below 32bit boundary */ |
Marek Vasut | 3d5256e | 2020-04-04 12:45:06 +0200 | [diff] [blame] | 726 | if ((ubuf >> 32) || (ubuf + len_aligned) >> 32) { |
| 727 | debug("Buffer above 32bit boundary %lx-%lx\n", |
| 728 | ubuf, ubuf + len_aligned); |
Marek Vasut | 9f7baeb | 2020-04-04 12:45:04 +0200 | [diff] [blame] | 729 | return 0; |
| 730 | } |
| 731 | #endif |
| 732 | |
| 733 | /* Aligned */ |
| 734 | return 1; |
| 735 | } |
| 736 | |
Marek Vasut | 3d5256e | 2020-04-04 12:45:06 +0200 | [diff] [blame] | 737 | static int renesas_sdhi_addr_aligned(struct bounce_buffer *state) |
| 738 | { |
| 739 | uintptr_t ubuf = (uintptr_t)state->user_buffer; |
| 740 | |
| 741 | return renesas_sdhi_addr_aligned_gen(ubuf, state->len, |
| 742 | state->len_aligned); |
| 743 | } |
| 744 | |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 745 | static int renesas_sdhi_send_cmd(struct udevice *dev, struct mmc_cmd *cmd, |
| 746 | struct mmc_data *data) |
| 747 | { |
Marek Vasut | 9f7baeb | 2020-04-04 12:45:04 +0200 | [diff] [blame] | 748 | struct bounce_buffer bbstate; |
| 749 | unsigned int bbflags; |
| 750 | bool bbok = false; |
| 751 | size_t len; |
| 752 | void *buf; |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 753 | int ret; |
| 754 | |
Marek Vasut | 9f7baeb | 2020-04-04 12:45:04 +0200 | [diff] [blame] | 755 | if (data) { |
| 756 | if (data->flags & MMC_DATA_READ) { |
| 757 | buf = data->dest; |
| 758 | bbflags = GEN_BB_WRITE; |
| 759 | } else { |
| 760 | buf = (void *)data->src; |
| 761 | bbflags = GEN_BB_READ; |
| 762 | } |
| 763 | len = data->blocks * data->blocksize; |
| 764 | |
| 765 | ret = bounce_buffer_start_extalign(&bbstate, buf, len, bbflags, |
| 766 | RENESAS_SDHI_DMA_ALIGNMENT, |
| 767 | renesas_sdhi_addr_aligned); |
| 768 | /* |
| 769 | * If the amount of data to transfer is too large, we can get |
| 770 | * -ENOMEM when starting the bounce buffer. If that happens, |
| 771 | * fall back to PIO as it was before, otherwise use the BB. |
| 772 | */ |
| 773 | if (!ret) { |
| 774 | bbok = true; |
| 775 | if (data->flags & MMC_DATA_READ) |
| 776 | data->dest = bbstate.bounce_buffer; |
| 777 | else |
| 778 | data->src = bbstate.bounce_buffer; |
| 779 | } |
| 780 | } |
| 781 | |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 782 | ret = tmio_sd_send_cmd(dev, cmd, data); |
Marek Vasut | 9f7baeb | 2020-04-04 12:45:04 +0200 | [diff] [blame] | 783 | |
| 784 | if (data && bbok) { |
| 785 | buf = bbstate.user_buffer; |
| 786 | |
| 787 | bounce_buffer_stop(&bbstate); |
| 788 | |
| 789 | if (data->flags & MMC_DATA_READ) |
| 790 | data->dest = buf; |
| 791 | else |
| 792 | data->src = buf; |
| 793 | } |
| 794 | |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 795 | if (ret) |
| 796 | return ret; |
| 797 | |
| 798 | #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \ |
| 799 | CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \ |
| 800 | CONFIG_IS_ENABLED(MMC_HS400_SUPPORT) |
Marek Vasut | 0e05fa3 | 2024-02-24 23:32:11 +0100 | [diff] [blame] | 801 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 802 | struct tmio_sd_priv *priv = dev_get_priv(dev); |
Marek Vasut | 0e05fa3 | 2024-02-24 23:32:11 +0100 | [diff] [blame] | 803 | struct mmc *mmc = upriv->mmc; |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 804 | |
Marek Vasut | 0e05fa3 | 2024-02-24 23:32:11 +0100 | [diff] [blame] | 805 | if (!mmc->tuning) |
| 806 | renesas_sdhi_check_scc_error(dev); |
Marek Vasut | 52647a0 | 2019-11-23 13:36:23 +0100 | [diff] [blame] | 807 | |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 808 | if (cmd->cmdidx == MMC_CMD_SEND_STATUS) |
| 809 | renesas_sdhi_adjust_hs400_mode_enable(priv); |
| 810 | #endif |
| 811 | |
| 812 | return 0; |
| 813 | } |
| 814 | |
Marek Vasut | 3d5256e | 2020-04-04 12:45:06 +0200 | [diff] [blame] | 815 | int renesas_sdhi_get_b_max(struct udevice *dev, void *dst, lbaint_t blkcnt) |
| 816 | { |
| 817 | struct tmio_sd_priv *priv = dev_get_priv(dev); |
| 818 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 819 | struct mmc *mmc = upriv->mmc; |
| 820 | size_t len = blkcnt * mmc->read_bl_len; |
| 821 | size_t len_align = roundup(len, RENESAS_SDHI_DMA_ALIGNMENT); |
| 822 | |
| 823 | if (renesas_sdhi_addr_aligned_gen((uintptr_t)dst, len, len_align)) { |
| 824 | if (priv->quirks & TMIO_SD_CAP_16BIT) |
| 825 | return U16_MAX; |
| 826 | else |
| 827 | return U32_MAX; |
| 828 | } else { |
| 829 | return (CONFIG_SYS_MALLOC_LEN / 4) / mmc->read_bl_len; |
| 830 | } |
| 831 | } |
| 832 | |
Marek Vasut | 06485cf | 2018-04-08 15:22:58 +0200 | [diff] [blame] | 833 | static const struct dm_mmc_ops renesas_sdhi_ops = { |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 834 | .send_cmd = renesas_sdhi_send_cmd, |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 835 | .set_ios = renesas_sdhi_set_ios, |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 836 | .get_cd = tmio_sd_get_cd, |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 837 | #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \ |
| 838 | CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \ |
| 839 | CONFIG_IS_ENABLED(MMC_HS400_SUPPORT) |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 840 | .execute_tuning = renesas_sdhi_execute_tuning, |
| 841 | #endif |
Marek Vasut | 576a6d9 | 2018-10-28 19:28:56 +0100 | [diff] [blame] | 842 | #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) |
| 843 | .wait_dat0 = renesas_sdhi_wait_dat0, |
| 844 | #endif |
Marek Vasut | 3d5256e | 2020-04-04 12:45:06 +0200 | [diff] [blame] | 845 | .get_b_max = renesas_sdhi_get_b_max, |
Marek Vasut | 06485cf | 2018-04-08 15:22:58 +0200 | [diff] [blame] | 846 | }; |
| 847 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 848 | #define RENESAS_GEN2_QUIRKS TMIO_SD_CAP_RCAR_GEN2 |
Marek Vasut | 9db9e6a | 2018-04-08 18:49:52 +0200 | [diff] [blame] | 849 | #define RENESAS_GEN3_QUIRKS \ |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 850 | TMIO_SD_CAP_64BIT | TMIO_SD_CAP_RCAR_GEN3 | TMIO_SD_CAP_RCAR_UHS |
Marek Vasut | 9db9e6a | 2018-04-08 18:49:52 +0200 | [diff] [blame] | 851 | |
Marek Vasut | 06485cf | 2018-04-08 15:22:58 +0200 | [diff] [blame] | 852 | static const struct udevice_id renesas_sdhi_match[] = { |
Marek Vasut | 9db9e6a | 2018-04-08 18:49:52 +0200 | [diff] [blame] | 853 | { .compatible = "renesas,sdhi-r8a7790", .data = RENESAS_GEN2_QUIRKS }, |
| 854 | { .compatible = "renesas,sdhi-r8a7791", .data = RENESAS_GEN2_QUIRKS }, |
| 855 | { .compatible = "renesas,sdhi-r8a7792", .data = RENESAS_GEN2_QUIRKS }, |
| 856 | { .compatible = "renesas,sdhi-r8a7793", .data = RENESAS_GEN2_QUIRKS }, |
| 857 | { .compatible = "renesas,sdhi-r8a7794", .data = RENESAS_GEN2_QUIRKS }, |
| 858 | { .compatible = "renesas,sdhi-r8a7795", .data = RENESAS_GEN3_QUIRKS }, |
| 859 | { .compatible = "renesas,sdhi-r8a7796", .data = RENESAS_GEN3_QUIRKS }, |
Hai Pham | 7e631b0 | 2023-01-26 21:05:59 +0100 | [diff] [blame] | 860 | { .compatible = "renesas,sdhi-r8a77961", .data = RENESAS_GEN3_QUIRKS }, |
Adam Ford | 7128361 | 2020-06-30 09:30:10 -0500 | [diff] [blame] | 861 | { .compatible = "renesas,rcar-gen3-sdhi", .data = RENESAS_GEN3_QUIRKS }, |
Marek Vasut | 9db9e6a | 2018-04-08 18:49:52 +0200 | [diff] [blame] | 862 | { .compatible = "renesas,sdhi-r8a77965", .data = RENESAS_GEN3_QUIRKS }, |
| 863 | { .compatible = "renesas,sdhi-r8a77970", .data = RENESAS_GEN3_QUIRKS }, |
Marek Vasut | 8b2ae7d | 2018-04-26 13:19:29 +0200 | [diff] [blame] | 864 | { .compatible = "renesas,sdhi-r8a77990", .data = RENESAS_GEN3_QUIRKS }, |
Marek Vasut | 9db9e6a | 2018-04-08 18:49:52 +0200 | [diff] [blame] | 865 | { .compatible = "renesas,sdhi-r8a77995", .data = RENESAS_GEN3_QUIRKS }, |
Hai Pham | 206dc91 | 2023-02-28 22:24:06 +0100 | [diff] [blame] | 866 | { .compatible = "renesas,rcar-gen4-sdhi", .data = RENESAS_GEN3_QUIRKS }, |
Marek Vasut | 06485cf | 2018-04-08 15:22:58 +0200 | [diff] [blame] | 867 | { /* sentinel */ } |
| 868 | }; |
| 869 | |
Marek Vasut | da90a1b | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 870 | static ulong renesas_sdhi_clk_get_rate(struct tmio_sd_priv *priv) |
| 871 | { |
| 872 | return clk_get_rate(&priv->clk); |
| 873 | } |
| 874 | |
Marek Vasut | b59180a | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 875 | static void renesas_sdhi_filter_caps(struct udevice *dev) |
| 876 | { |
Marek Vasut | b59180a | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 877 | struct tmio_sd_priv *priv = dev_get_priv(dev); |
| 878 | |
| 879 | if (!(priv->caps & TMIO_SD_CAP_RCAR_GEN3)) |
| 880 | return; |
| 881 | |
Marek Vasut | d6e2f87 | 2021-01-03 11:38:25 +0100 | [diff] [blame] | 882 | if (priv->caps & TMIO_SD_CAP_DMA_INTERNAL) |
| 883 | priv->idma_bus_width = TMIO_SD_DMA_MODE_BUS_WIDTH; |
| 884 | |
Marek Vasut | 7b46176 | 2019-11-23 13:36:25 +0100 | [diff] [blame] | 885 | #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \ |
| 886 | CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \ |
| 887 | CONFIG_IS_ENABLED(MMC_HS400_SUPPORT) |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 888 | struct tmio_sd_plat *plat = dev_get_plat(dev); |
Marek Vasut | 7b46176 | 2019-11-23 13:36:25 +0100 | [diff] [blame] | 889 | |
Hai Pham | f0d3c07 | 2023-01-26 21:05:56 +0100 | [diff] [blame] | 890 | /* HS400 is not supported on H3 ES1.x, M3W ES1.[012], V3M, V3H ES1.x, D3 */ |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 891 | if (((renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A7795) && |
Marek Vasut | 1760232 | 2024-02-27 17:05:46 +0100 | [diff] [blame] | 892 | (renesas_get_cpu_rev_integer() <= 1)) || |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 893 | ((renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A7796) && |
Marek Vasut | 1760232 | 2024-02-27 17:05:46 +0100 | [diff] [blame] | 894 | (renesas_get_cpu_rev_integer() == 1) && |
| 895 | (renesas_get_cpu_rev_fraction() <= 2)) || |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 896 | (renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A77970) || |
| 897 | ((renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A77980) && |
Marek Vasut | 1760232 | 2024-02-27 17:05:46 +0100 | [diff] [blame] | 898 | (renesas_get_cpu_rev_integer() <= 1)) || |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 899 | (renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A77995)) |
Marek Vasut | b59180a | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 900 | plat->cfg.host_caps &= ~MMC_MODE_HS400; |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 901 | |
Marek Vasut | 531fc99 | 2019-11-23 13:36:24 +0100 | [diff] [blame] | 902 | /* H3 ES2.0, ES3.0 and M3W ES1.2 and M3N bad taps */ |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 903 | if (((renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A7795) && |
Marek Vasut | 1760232 | 2024-02-27 17:05:46 +0100 | [diff] [blame] | 904 | (renesas_get_cpu_rev_integer() >= 2)) || |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 905 | ((renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A7796) && |
Marek Vasut | 1760232 | 2024-02-27 17:05:46 +0100 | [diff] [blame] | 906 | (renesas_get_cpu_rev_integer() == 1) && |
| 907 | (renesas_get_cpu_rev_fraction() == 2)) || |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 908 | (renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A77965)) |
Marek Vasut | 531fc99 | 2019-11-23 13:36:24 +0100 | [diff] [blame] | 909 | priv->hs400_bad_tap = BIT(2) | BIT(3) | BIT(6) | BIT(7); |
| 910 | |
| 911 | /* M3W ES1.x for x>2 can use HS400 with manual adjustment and taps */ |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 912 | if ((renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A7796) && |
Marek Vasut | 1760232 | 2024-02-27 17:05:46 +0100 | [diff] [blame] | 913 | (renesas_get_cpu_rev_integer() == 1) && |
| 914 | (renesas_get_cpu_rev_fraction() > 2)) { |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 915 | priv->adjust_hs400_enable = true; |
Hai Pham | e4eaa82 | 2023-01-26 21:05:58 +0100 | [diff] [blame] | 916 | priv->adjust_hs400_offset = 3; |
Marek Vasut | 531fc99 | 2019-11-23 13:36:24 +0100 | [diff] [blame] | 917 | priv->hs400_bad_tap = BIT(1) | BIT(3) | BIT(5) | BIT(7); |
Marek Vasut | 7b46176 | 2019-11-23 13:36:25 +0100 | [diff] [blame] | 918 | priv->adjust_hs400_calib_table = |
Marek Vasut | 691c0b6 | 2024-02-27 17:05:58 +0100 | [diff] [blame] | 919 | r8a7796_rev13_calib_table[!rcar_is_gen3_mmc0(priv)]; |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 920 | } |
| 921 | |
Hai Pham | 7e631b0 | 2023-01-26 21:05:59 +0100 | [diff] [blame] | 922 | /* M3W+ bad taps */ |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 923 | if ((renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A7796) && |
Marek Vasut | 1760232 | 2024-02-27 17:05:46 +0100 | [diff] [blame] | 924 | (renesas_get_cpu_rev_integer() == 3)) |
Hai Pham | 7e631b0 | 2023-01-26 21:05:59 +0100 | [diff] [blame] | 925 | priv->hs400_bad_tap = BIT(1) | BIT(3) | BIT(5) | BIT(7); |
| 926 | |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 927 | /* M3N can use HS400 with manual adjustment */ |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 928 | if (renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A77965) { |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 929 | priv->adjust_hs400_enable = true; |
Marek Vasut | cf643b0 | 2019-11-23 13:36:21 +0100 | [diff] [blame] | 930 | priv->adjust_hs400_offset = 3; |
Marek Vasut | 7b46176 | 2019-11-23 13:36:25 +0100 | [diff] [blame] | 931 | priv->adjust_hs400_calib_table = |
Marek Vasut | 691c0b6 | 2024-02-27 17:05:58 +0100 | [diff] [blame] | 932 | r8a77965_calib_table[!rcar_is_gen3_mmc0(priv)]; |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | /* E3 can use HS400 with manual adjustment */ |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 936 | if (renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A77990) { |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 937 | priv->adjust_hs400_enable = true; |
Marek Vasut | cf643b0 | 2019-11-23 13:36:21 +0100 | [diff] [blame] | 938 | priv->adjust_hs400_offset = 3; |
Marek Vasut | 7b46176 | 2019-11-23 13:36:25 +0100 | [diff] [blame] | 939 | priv->adjust_hs400_calib_table = |
Marek Vasut | 691c0b6 | 2024-02-27 17:05:58 +0100 | [diff] [blame] | 940 | r8a77990_calib_table[!rcar_is_gen3_mmc0(priv)]; |
Marek Vasut | fee0c68 | 2019-05-19 03:47:07 +0200 | [diff] [blame] | 941 | } |
| 942 | |
Hai Pham | 5c86e06 | 2023-01-26 21:05:55 +0100 | [diff] [blame] | 943 | /* H3 ES1.x, ES2.0 and M3W ES1.[0123] uses 4 tuning taps */ |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 944 | if (((renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A7795) && |
Marek Vasut | 1760232 | 2024-02-27 17:05:46 +0100 | [diff] [blame] | 945 | (renesas_get_cpu_rev_integer() <= 2)) || |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 946 | ((renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A7796) && |
Marek Vasut | 1760232 | 2024-02-27 17:05:46 +0100 | [diff] [blame] | 947 | (renesas_get_cpu_rev_integer() == 1) && |
| 948 | (renesas_get_cpu_rev_fraction() <= 3))) |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 949 | priv->nrtaps = 4; |
| 950 | else |
| 951 | priv->nrtaps = 8; |
Marek Vasut | 7b46176 | 2019-11-23 13:36:25 +0100 | [diff] [blame] | 952 | #endif |
Marek Vasut | e9a2822 | 2019-01-11 23:45:54 +0100 | [diff] [blame] | 953 | /* H3 ES1.x and M3W ES1.0 uses bit 17 for DTRAEND */ |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 954 | if (((renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A7795) && |
Marek Vasut | 1760232 | 2024-02-27 17:05:46 +0100 | [diff] [blame] | 955 | (renesas_get_cpu_rev_integer() <= 1)) || |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 956 | ((renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A7796) && |
Marek Vasut | 1760232 | 2024-02-27 17:05:46 +0100 | [diff] [blame] | 957 | (renesas_get_cpu_rev_integer() == 1) && |
| 958 | (renesas_get_cpu_rev_fraction() == 0))) |
Marek Vasut | e9a2822 | 2019-01-11 23:45:54 +0100 | [diff] [blame] | 959 | priv->read_poll_flag = TMIO_SD_DMA_INFO1_END_RD; |
| 960 | else |
| 961 | priv->read_poll_flag = TMIO_SD_DMA_INFO1_END_RD2; |
Hai Pham | 5587caa | 2023-01-26 21:06:01 +0100 | [diff] [blame] | 962 | |
| 963 | /* V3M handles SD0H differently than other Gen3 SoCs */ |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 964 | if (renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A77970) |
Hai Pham | 5587caa | 2023-01-26 21:06:01 +0100 | [diff] [blame] | 965 | priv->needs_clkh_fallback = true; |
| 966 | else |
| 967 | priv->needs_clkh_fallback = false; |
Marek Vasut | b59180a | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 968 | } |
| 969 | |
Paul Barker | e22d1a0 | 2023-10-16 10:25:38 +0100 | [diff] [blame] | 970 | static int rzg2l_sdhi_setup(struct udevice *dev) |
| 971 | { |
| 972 | struct tmio_sd_priv *priv = dev_get_priv(dev); |
| 973 | struct clk imclk2, aclk; |
| 974 | struct reset_ctl rst; |
| 975 | int ret; |
| 976 | |
| 977 | /* |
| 978 | * On members of the RZ/G2L SoC family, we need to enable |
| 979 | * additional chip detect and bus clocks, then release the SDHI |
| 980 | * module from reset. |
| 981 | */ |
| 982 | ret = clk_get_by_name(dev, "cd", &imclk2); |
| 983 | if (ret < 0) { |
| 984 | dev_err(dev, "failed to get imclk2 (chip detect clk)\n"); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 985 | return ret; |
Paul Barker | e22d1a0 | 2023-10-16 10:25:38 +0100 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | ret = clk_get_by_name(dev, "aclk", &aclk); |
| 989 | if (ret < 0) { |
| 990 | dev_err(dev, "failed to get aclk\n"); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 991 | return ret; |
Paul Barker | e22d1a0 | 2023-10-16 10:25:38 +0100 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | ret = clk_enable(&imclk2); |
| 995 | if (ret < 0) { |
| 996 | dev_err(dev, "failed to enable imclk2 (chip detect clk)\n"); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 997 | return ret; |
Paul Barker | e22d1a0 | 2023-10-16 10:25:38 +0100 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | ret = clk_enable(&aclk); |
| 1001 | if (ret < 0) { |
| 1002 | dev_err(dev, "failed to enable aclk\n"); |
| 1003 | goto err_aclk; |
| 1004 | } |
| 1005 | |
| 1006 | ret = reset_get_by_index(dev, 0, &rst); |
| 1007 | if (ret < 0) { |
| 1008 | dev_err(dev, "failed to get reset line\n"); |
Paul Barker | 0b4d1db | 2023-10-19 15:50:38 +0100 | [diff] [blame] | 1009 | goto err_get_reset; |
Paul Barker | e22d1a0 | 2023-10-16 10:25:38 +0100 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | ret = reset_deassert(&rst); |
| 1013 | if (ret < 0) { |
| 1014 | dev_err(dev, "failed to de-assert reset line\n"); |
| 1015 | goto err_reset; |
| 1016 | } |
| 1017 | |
| 1018 | ret = tmio_sd_probe(dev, priv->quirks); |
| 1019 | if (ret) |
| 1020 | goto err_tmio_probe; |
| 1021 | |
| 1022 | return 0; |
| 1023 | |
| 1024 | err_tmio_probe: |
| 1025 | reset_assert(&rst); |
| 1026 | err_reset: |
Paul Barker | 0b4d1db | 2023-10-19 15:50:38 +0100 | [diff] [blame] | 1027 | reset_free(&rst); |
| 1028 | err_get_reset: |
Paul Barker | e22d1a0 | 2023-10-16 10:25:38 +0100 | [diff] [blame] | 1029 | clk_disable(&aclk); |
| 1030 | err_aclk: |
| 1031 | clk_disable(&imclk2); |
Paul Barker | e22d1a0 | 2023-10-16 10:25:38 +0100 | [diff] [blame] | 1032 | return ret; |
| 1033 | } |
| 1034 | |
Marek Vasut | abe3e95 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 1035 | static int renesas_sdhi_probe(struct udevice *dev) |
| 1036 | { |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 1037 | struct tmio_sd_priv *priv = dev_get_priv(dev); |
Marek Vasut | 1949d48 | 2018-04-08 18:14:22 +0200 | [diff] [blame] | 1038 | struct fdt_resource reg_res; |
| 1039 | DECLARE_GLOBAL_DATA_PTR; |
| 1040 | int ret; |
| 1041 | |
Marek Vasut | da90a1b | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 1042 | priv->clk_get_rate = renesas_sdhi_clk_get_rate; |
| 1043 | |
Paul Barker | 110f32d | 2023-10-16 10:25:37 +0100 | [diff] [blame] | 1044 | priv->quirks = dev_get_driver_data(dev); |
| 1045 | if (priv->quirks == RENESAS_GEN2_QUIRKS) { |
Marek Vasut | 9db9e6a | 2018-04-08 18:49:52 +0200 | [diff] [blame] | 1046 | ret = fdt_get_resource(gd->fdt_blob, dev_of_offset(dev), |
| 1047 | "reg", 0, ®_res); |
| 1048 | if (ret < 0) { |
| 1049 | dev_err(dev, "\"reg\" resource not found, ret=%i\n", |
| 1050 | ret); |
| 1051 | return ret; |
| 1052 | } |
Marek Vasut | 1949d48 | 2018-04-08 18:14:22 +0200 | [diff] [blame] | 1053 | |
Marek Vasut | 9db9e6a | 2018-04-08 18:49:52 +0200 | [diff] [blame] | 1054 | if (fdt_resource_size(®_res) == 0x100) |
Paul Barker | 110f32d | 2023-10-16 10:25:37 +0100 | [diff] [blame] | 1055 | priv->quirks |= TMIO_SD_CAP_16BIT; |
Marek Vasut | 9db9e6a | 2018-04-08 18:49:52 +0200 | [diff] [blame] | 1056 | } |
Marek Vasut | abe3e95 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 1057 | |
Marek Vasut | da90a1b | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 1058 | ret = clk_get_by_index(dev, 0, &priv->clk); |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 1059 | if (ret < 0) { |
| 1060 | dev_err(dev, "failed to get host clock\n"); |
| 1061 | return ret; |
| 1062 | } |
| 1063 | |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 1064 | /* optional SDnH clock */ |
| 1065 | ret = clk_get_by_name(dev, "clkh", &priv->clkh); |
Marek Vasut | dcfa1ad | 2023-02-27 23:49:27 +0100 | [diff] [blame] | 1066 | if (ret < 0) { |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 1067 | dev_dbg(dev, "failed to get clkh\n"); |
Marek Vasut | dcfa1ad | 2023-02-27 23:49:27 +0100 | [diff] [blame] | 1068 | } else { |
| 1069 | ret = clk_set_rate(&priv->clkh, 800000000); |
| 1070 | if (ret < 0) { |
Marek Vasut | 3ce4993 | 2023-02-27 23:49:28 +0100 | [diff] [blame] | 1071 | dev_err(dev, "failed to set rate for SDnH clock (%d)\n", ret); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 1072 | return ret; |
Marek Vasut | dcfa1ad | 2023-02-27 23:49:27 +0100 | [diff] [blame] | 1073 | } |
| 1074 | } |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 1075 | |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 1076 | /* set to max rate */ |
Marek Vasut | da90a1b | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 1077 | ret = clk_set_rate(&priv->clk, 200000000); |
| 1078 | if (ret < 0) { |
Marek Vasut | 3ce4993 | 2023-02-27 23:49:28 +0100 | [diff] [blame] | 1079 | dev_err(dev, "failed to set rate for SDn clock (%d)\n", ret); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 1080 | return ret; |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 1081 | } |
| 1082 | |
Marek Vasut | da90a1b | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 1083 | ret = clk_enable(&priv->clk); |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 1084 | if (ret) { |
Marek Vasut | 3ce4993 | 2023-02-27 23:49:28 +0100 | [diff] [blame] | 1085 | dev_err(dev, "failed to enable SDn clock (%d)\n", ret); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 1086 | return ret; |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 1087 | } |
| 1088 | |
Paul Barker | e22d1a0 | 2023-10-16 10:25:38 +0100 | [diff] [blame] | 1089 | if (device_is_compatible(dev, "renesas,sdhi-r9a07g044")) |
| 1090 | ret = rzg2l_sdhi_setup(dev); |
| 1091 | else |
| 1092 | ret = tmio_sd_probe(dev, priv->quirks); |
Marek Vasut | 3ce4993 | 2023-02-27 23:49:28 +0100 | [diff] [blame] | 1093 | if (ret) |
| 1094 | goto err_tmio_probe; |
Marek Vasut | b59180a | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 1095 | |
| 1096 | renesas_sdhi_filter_caps(dev); |
| 1097 | |
Marek Vasut | 10d77ed | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 1098 | #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \ |
| 1099 | CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \ |
| 1100 | CONFIG_IS_ENABLED(MMC_HS400_SUPPORT) |
Marek Vasut | 3ce4993 | 2023-02-27 23:49:28 +0100 | [diff] [blame] | 1101 | if (priv->caps & TMIO_SD_CAP_RCAR_UHS) |
Marek Vasut | cfb65b4 | 2023-11-05 23:42:45 +0100 | [diff] [blame] | 1102 | renesas_sdhi_reset_tuning(priv, true); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 1103 | #endif |
Marek Vasut | 3ce4993 | 2023-02-27 23:49:28 +0100 | [diff] [blame] | 1104 | return 0; |
| 1105 | |
| 1106 | err_tmio_probe: |
| 1107 | clk_disable(&priv->clk); |
Marek Vasut | e0781e4 | 2018-04-08 19:09:17 +0200 | [diff] [blame] | 1108 | return ret; |
Marek Vasut | abe3e95 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 1109 | } |
| 1110 | |
Marek Vasut | 06485cf | 2018-04-08 15:22:58 +0200 | [diff] [blame] | 1111 | U_BOOT_DRIVER(renesas_sdhi) = { |
| 1112 | .name = "renesas-sdhi", |
| 1113 | .id = UCLASS_MMC, |
| 1114 | .of_match = renesas_sdhi_match, |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 1115 | .bind = tmio_sd_bind, |
Marek Vasut | abe3e95 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 1116 | .probe = renesas_sdhi_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 1117 | .priv_auto = sizeof(struct tmio_sd_priv), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1118 | .plat_auto = sizeof(struct tmio_sd_plat), |
Marek Vasut | 06485cf | 2018-04-08 15:22:58 +0200 | [diff] [blame] | 1119 | .ops = &renesas_sdhi_ops, |
| 1120 | }; |