1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Marek Vasut <marek.vasut@gmail.com>
11 #include <linux/compat.h>
12 #include <linux/dma-direction.h>
14 #include <linux/sizes.h>
15 #include <power/regulator.h>
16 #include <asm/unaligned.h>
18 #include "tmio-common.h"
20 #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
21 CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
22 CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
25 #define RENESAS_SDHI_SCC_DTCNTL 0x800
26 #define RENESAS_SDHI_SCC_DTCNTL_TAPEN BIT(0)
27 #define RENESAS_SDHI_SCC_DTCNTL_TAPNUM_SHIFT 16
28 #define RENESAS_SDHI_SCC_DTCNTL_TAPNUM_MASK 0xff
29 #define RENESAS_SDHI_SCC_TAPSET 0x804
30 #define RENESAS_SDHI_SCC_DT2FF 0x808
31 #define RENESAS_SDHI_SCC_CKSEL 0x80c
32 #define RENESAS_SDHI_SCC_CKSEL_DTSEL BIT(0)
33 #define RENESAS_SDHI_SCC_RVSCNTL 0x810
34 #define RENESAS_SDHI_SCC_RVSCNTL_RVSEN BIT(0)
35 #define RENESAS_SDHI_SCC_RVSREQ 0x814
36 #define RENESAS_SDHI_SCC_RVSREQ_RVSERR BIT(2)
37 #define RENESAS_SDHI_SCC_SMPCMP 0x818
38 #define RENESAS_SDHI_SCC_TMPPORT2 0x81c
39 #define RENESAS_SDHI_SCC_TMPPORT2_HS400EN BIT(31)
40 #define RENESAS_SDHI_SCC_TMPPORT2_HS400OSEL BIT(4)
41 #define RENESAS_SDHI_SCC_TMPPORT3 0x828
42 #define RENESAS_SDHI_SCC_TMPPORT3_OFFSET_0 3
43 #define RENESAS_SDHI_SCC_TMPPORT3_OFFSET_1 2
44 #define RENESAS_SDHI_SCC_TMPPORT3_OFFSET_2 1
45 #define RENESAS_SDHI_SCC_TMPPORT3_OFFSET_3 0
46 #define RENESAS_SDHI_SCC_TMPPORT3_OFFSET_MASK 0x3
47 #define RENESAS_SDHI_SCC_TMPPORT4 0x82c
48 #define RENESAS_SDHI_SCC_TMPPORT4_DLL_ACC_START BIT(0)
49 #define RENESAS_SDHI_SCC_TMPPORT5 0x830
50 #define RENESAS_SDHI_SCC_TMPPORT5_DLL_RW_SEL_R BIT(8)
51 #define RENESAS_SDHI_SCC_TMPPORT5_DLL_RW_SEL_W (0 << 8)
52 #define RENESAS_SDHI_SCC_TMPPORT5_DLL_ADR_MASK 0x3F
53 #define RENESAS_SDHI_SCC_TMPPORT6 0x834
54 #define RENESAS_SDHI_SCC_TMPPORT7 0x838
55 #define RENESAS_SDHI_SCC_TMPPORT_DISABLE_WP_CODE 0xa5000000
56 #define RENESAS_SDHI_SCC_TMPPORT_CALIB_CODE_MASK 0x1f
57 #define RENESAS_SDHI_SCC_TMPPORT_MANUAL_MODE BIT(7)
59 #define RENESAS_SDHI_MAX_TAP 3
61 static u32 sd_scc_tmpport_read32(struct tmio_sd_priv *priv, u32 addr)
64 tmio_sd_writel(priv, RENESAS_SDHI_SCC_TMPPORT5_DLL_RW_SEL_R |
65 (RENESAS_SDHI_SCC_TMPPORT5_DLL_ADR_MASK & addr),
66 RENESAS_SDHI_SCC_TMPPORT5);
68 /* access start and stop */
69 tmio_sd_writel(priv, RENESAS_SDHI_SCC_TMPPORT4_DLL_ACC_START,
70 RENESAS_SDHI_SCC_TMPPORT4);
71 tmio_sd_writel(priv, 0, RENESAS_SDHI_SCC_TMPPORT4);
73 return tmio_sd_readl(priv, RENESAS_SDHI_SCC_TMPPORT7);
76 static void sd_scc_tmpport_write32(struct tmio_sd_priv *priv, u32 addr, u32 val)
79 tmio_sd_writel(priv, RENESAS_SDHI_SCC_TMPPORT5_DLL_RW_SEL_W |
80 (RENESAS_SDHI_SCC_TMPPORT5_DLL_ADR_MASK & addr),
81 RENESAS_SDHI_SCC_TMPPORT5);
82 tmio_sd_writel(priv, val, RENESAS_SDHI_SCC_TMPPORT6);
84 /* access start and stop */
85 tmio_sd_writel(priv, RENESAS_SDHI_SCC_TMPPORT4_DLL_ACC_START,
86 RENESAS_SDHI_SCC_TMPPORT4);
87 tmio_sd_writel(priv, 0, RENESAS_SDHI_SCC_TMPPORT4);
90 static void renesas_sdhi_adjust_hs400_mode_enable(struct tmio_sd_priv *priv)
94 if (!priv->adjust_hs400_enable)
97 if (!priv->needs_adjust_hs400)
101 * Enabled Manual adjust HS400 mode
103 * 1) Disabled Write Protect
104 * W(addr=0x00, WP_DISABLE_CODE)
105 * 2) Read Calibration code and adjust
106 * R(addr=0x26) - adjust value
107 * 3) Enabled Manual Calibration
108 * W(addr=0x22, manual mode | Calibration code)
109 * 4) Set Offset value to TMPPORT3 Reg
111 sd_scc_tmpport_write32(priv, 0x00,
112 RENESAS_SDHI_SCC_TMPPORT_DISABLE_WP_CODE);
113 calib_code = sd_scc_tmpport_read32(priv, 0x26);
114 calib_code &= RENESAS_SDHI_SCC_TMPPORT_CALIB_CODE_MASK;
115 if (calib_code > priv->adjust_hs400_calibrate)
116 calib_code -= priv->adjust_hs400_calibrate;
119 sd_scc_tmpport_write32(priv, 0x22,
120 RENESAS_SDHI_SCC_TMPPORT_MANUAL_MODE |
122 tmio_sd_writel(priv, priv->adjust_hs400_offset,
123 RENESAS_SDHI_SCC_TMPPORT3);
126 priv->needs_adjust_hs400 = false;
129 static void renesas_sdhi_adjust_hs400_mode_disable(struct tmio_sd_priv *priv)
132 /* Disabled Manual adjust HS400 mode
134 * 1) Disabled Write Protect
135 * W(addr=0x00, WP_DISABLE_CODE)
136 * 2) Disabled Manual Calibration
138 * 3) Clear offset value to TMPPORT3 Reg
140 sd_scc_tmpport_write32(priv, 0x00,
141 RENESAS_SDHI_SCC_TMPPORT_DISABLE_WP_CODE);
142 sd_scc_tmpport_write32(priv, 0x22, 0);
143 tmio_sd_writel(priv, 0, RENESAS_SDHI_SCC_TMPPORT3);
146 static unsigned int renesas_sdhi_init_tuning(struct tmio_sd_priv *priv)
151 tmio_sd_writel(priv, 0, TMIO_SD_INFO1);
153 reg = tmio_sd_readl(priv, TMIO_SD_CLKCTL);
154 reg &= ~TMIO_SD_CLKCTL_SCLKEN;
155 tmio_sd_writel(priv, reg, TMIO_SD_CLKCTL);
157 /* Set sampling clock selection range */
158 tmio_sd_writel(priv, (0x8 << RENESAS_SDHI_SCC_DTCNTL_TAPNUM_SHIFT) |
159 RENESAS_SDHI_SCC_DTCNTL_TAPEN,
160 RENESAS_SDHI_SCC_DTCNTL);
162 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_CKSEL);
163 reg |= RENESAS_SDHI_SCC_CKSEL_DTSEL;
164 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_CKSEL);
166 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL);
167 reg &= ~RENESAS_SDHI_SCC_RVSCNTL_RVSEN;
168 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_RVSCNTL);
170 tmio_sd_writel(priv, 0x300 /* scc_tappos */,
171 RENESAS_SDHI_SCC_DT2FF);
173 reg = tmio_sd_readl(priv, TMIO_SD_CLKCTL);
174 reg |= TMIO_SD_CLKCTL_SCLKEN;
175 tmio_sd_writel(priv, reg, TMIO_SD_CLKCTL);
178 return (tmio_sd_readl(priv, RENESAS_SDHI_SCC_DTCNTL) >>
179 RENESAS_SDHI_SCC_DTCNTL_TAPNUM_SHIFT) &
180 RENESAS_SDHI_SCC_DTCNTL_TAPNUM_MASK;
183 static void renesas_sdhi_reset_tuning(struct tmio_sd_priv *priv)
188 reg = tmio_sd_readl(priv, TMIO_SD_CLKCTL);
189 reg &= ~TMIO_SD_CLKCTL_SCLKEN;
190 tmio_sd_writel(priv, reg, TMIO_SD_CLKCTL);
192 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_CKSEL);
193 reg &= ~RENESAS_SDHI_SCC_CKSEL_DTSEL;
194 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_CKSEL);
196 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_TMPPORT2);
197 reg &= ~(RENESAS_SDHI_SCC_TMPPORT2_HS400EN |
198 RENESAS_SDHI_SCC_TMPPORT2_HS400OSEL);
199 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_TMPPORT2);
201 /* Disable HS400 mode adjustment */
202 renesas_sdhi_adjust_hs400_mode_disable(priv);
204 reg = tmio_sd_readl(priv, TMIO_SD_CLKCTL);
205 reg |= TMIO_SD_CLKCTL_SCLKEN;
206 tmio_sd_writel(priv, reg, TMIO_SD_CLKCTL);
208 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL);
209 reg &= ~RENESAS_SDHI_SCC_RVSCNTL_RVSEN;
210 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_RVSCNTL);
212 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL);
213 reg &= ~RENESAS_SDHI_SCC_RVSCNTL_RVSEN;
214 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_RVSCNTL);
217 static int renesas_sdhi_hs400(struct udevice *dev)
219 struct tmio_sd_priv *priv = dev_get_priv(dev);
220 struct mmc *mmc = mmc_get_mmc_dev(dev);
221 bool hs400 = (mmc->selected_mode == MMC_HS_400);
222 int ret, taps = hs400 ? priv->nrtaps : 8;
225 if (taps == 4) /* HS400 on 4tap SoC needs different clock */
226 ret = clk_set_rate(&priv->clk, 400000000);
228 ret = clk_set_rate(&priv->clk, 200000000);
232 tmio_sd_writel(priv, 0, RENESAS_SDHI_SCC_RVSREQ);
234 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_TMPPORT2);
236 reg |= RENESAS_SDHI_SCC_TMPPORT2_HS400EN |
237 RENESAS_SDHI_SCC_TMPPORT2_HS400OSEL;
239 reg &= ~(RENESAS_SDHI_SCC_TMPPORT2_HS400EN |
240 RENESAS_SDHI_SCC_TMPPORT2_HS400OSEL);
243 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_TMPPORT2);
245 /* Disable HS400 mode adjustment */
247 renesas_sdhi_adjust_hs400_mode_disable(priv);
249 tmio_sd_writel(priv, (0x8 << RENESAS_SDHI_SCC_DTCNTL_TAPNUM_SHIFT) |
250 RENESAS_SDHI_SCC_DTCNTL_TAPEN,
251 RENESAS_SDHI_SCC_DTCNTL);
254 tmio_sd_writel(priv, priv->tap_set >> 1,
255 RENESAS_SDHI_SCC_TAPSET);
257 tmio_sd_writel(priv, priv->tap_set, RENESAS_SDHI_SCC_TAPSET);
260 tmio_sd_writel(priv, hs400 ? 0x704 : 0x300,
261 RENESAS_SDHI_SCC_DT2FF);
263 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_CKSEL);
264 reg |= RENESAS_SDHI_SCC_CKSEL_DTSEL;
265 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_CKSEL);
267 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL);
268 reg |= RENESAS_SDHI_SCC_RVSCNTL_RVSEN;
269 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_RVSCNTL);
271 /* Execute adjust hs400 offset after setting to HS400 mode */
273 priv->needs_adjust_hs400 = true;
278 static void renesas_sdhi_prepare_tuning(struct tmio_sd_priv *priv,
281 /* Set sampling clock position */
282 tmio_sd_writel(priv, tap, RENESAS_SDHI_SCC_TAPSET);
285 static unsigned int renesas_sdhi_compare_scc_data(struct tmio_sd_priv *priv)
287 /* Get comparison of sampling data */
288 return tmio_sd_readl(priv, RENESAS_SDHI_SCC_SMPCMP);
291 static int renesas_sdhi_select_tuning(struct tmio_sd_priv *priv,
292 unsigned int taps, unsigned int smpcmp)
294 unsigned long tap_cnt; /* counter of tuning success */
295 unsigned long tap_start;/* start position of tuning success */
296 unsigned long tap_end; /* end position of tuning success */
297 unsigned long ntap; /* temporary counter of tuning success */
298 unsigned long match_cnt;/* counter of matching data */
303 priv->needs_adjust_hs400 = false;
305 /* Clear SCC_RVSREQ */
306 tmio_sd_writel(priv, 0, RENESAS_SDHI_SCC_RVSREQ);
308 /* Merge the results */
309 for (i = 0; i < priv->tap_num * 2; i++) {
310 if (!(taps & BIT(i))) {
311 taps &= ~BIT(i % priv->tap_num);
312 taps &= ~BIT((i % priv->tap_num) + priv->tap_num);
314 if (!(smpcmp & BIT(i))) {
315 smpcmp &= ~BIT(i % priv->tap_num);
316 smpcmp &= ~BIT((i % priv->tap_num) + priv->tap_num);
321 * Find the longest consecutive run of successful probes. If that
322 * is more than RENESAS_SDHI_MAX_TAP probes long then use the
323 * center index as the tap.
329 for (i = 0; i < priv->tap_num * 2; i++) {
333 if (ntap > tap_cnt) {
334 tap_start = i - ntap;
342 if (ntap > tap_cnt) {
343 tap_start = i - ntap;
349 * If all of the TAP is OK, the sampling clock position is selected by
350 * identifying the change point of data.
352 if (tap_cnt == priv->tap_num * 2) {
357 for (i = 0; i < priv->tap_num * 2; i++) {
361 if (ntap > match_cnt) {
362 tap_start = i - ntap;
369 if (ntap > match_cnt) {
370 tap_start = i - ntap;
376 } else if (tap_cnt >= RENESAS_SDHI_MAX_TAP)
380 priv->tap_set = ((tap_start + tap_end) / 2) % priv->tap_num;
385 tmio_sd_writel(priv, priv->tap_set, RENESAS_SDHI_SCC_TAPSET);
387 /* Enable auto re-tuning */
388 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL);
389 reg |= RENESAS_SDHI_SCC_RVSCNTL_RVSEN;
390 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_RVSCNTL);
395 int renesas_sdhi_execute_tuning(struct udevice *dev, uint opcode)
397 struct tmio_sd_priv *priv = dev_get_priv(dev);
398 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
399 struct mmc *mmc = upriv->mmc;
400 unsigned int tap_num;
401 unsigned int taps = 0, smpcmp = 0;
405 /* Only supported on Renesas RCar */
406 if (!(priv->caps & TMIO_SD_CAP_RCAR_UHS))
409 /* clock tuning is not needed for upto 52MHz */
410 if (!((mmc->selected_mode == MMC_HS_200) ||
411 (mmc->selected_mode == MMC_HS_400) ||
412 (mmc->selected_mode == UHS_SDR104) ||
413 (mmc->selected_mode == UHS_SDR50)))
416 tap_num = renesas_sdhi_init_tuning(priv);
418 /* Tuning is not supported */
421 priv->tap_num = tap_num;
423 if (priv->tap_num * 2 >= sizeof(taps) * 8) {
425 "Too many taps, skipping tuning. Please consider updating size of taps field of tmio_mmc_host\n");
429 /* Issue CMD19 twice for each tap */
430 for (i = 0; i < 2 * priv->tap_num; i++) {
431 renesas_sdhi_prepare_tuning(priv, i % priv->tap_num);
433 /* Force PIO for the tuning */
435 priv->caps &= ~TMIO_SD_CAP_DMA_INTERNAL;
437 ret = mmc_send_tuning(mmc, opcode, NULL);
444 ret = renesas_sdhi_compare_scc_data(priv);
451 ret = renesas_sdhi_select_tuning(priv, taps, smpcmp);
455 dev_warn(dev, "Tuning procedure failed\n");
456 renesas_sdhi_reset_tuning(priv);
462 static int renesas_sdhi_hs400(struct udevice *dev)
468 static int renesas_sdhi_set_ios(struct udevice *dev)
470 struct tmio_sd_priv *priv = dev_get_priv(dev);
474 /* Stop the clock before changing its rate to avoid a glitch signal */
475 tmp = tmio_sd_readl(priv, TMIO_SD_CLKCTL);
476 tmp &= ~TMIO_SD_CLKCTL_SCLKEN;
477 tmio_sd_writel(priv, tmp, TMIO_SD_CLKCTL);
479 ret = renesas_sdhi_hs400(dev);
483 ret = tmio_sd_set_ios(dev);
487 #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
488 CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
489 CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
490 struct mmc *mmc = mmc_get_mmc_dev(dev);
491 if ((priv->caps & TMIO_SD_CAP_RCAR_UHS) &&
492 (mmc->selected_mode != UHS_SDR104) &&
493 (mmc->selected_mode != MMC_HS_200) &&
494 (mmc->selected_mode != MMC_HS_400)) {
495 renesas_sdhi_reset_tuning(priv);
502 #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
503 static int renesas_sdhi_wait_dat0(struct udevice *dev, int state,
506 int ret = -ETIMEDOUT;
508 bool target_dat0_high = !!state;
509 struct tmio_sd_priv *priv = dev_get_priv(dev);
511 timeout_us = DIV_ROUND_UP(timeout_us, 10); /* check every 10 us. */
512 while (timeout_us--) {
513 dat0_high = !!(tmio_sd_readl(priv, TMIO_SD_INFO2) & TMIO_SD_INFO2_DAT0);
514 if (dat0_high == target_dat0_high) {
525 static int renesas_sdhi_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
526 struct mmc_data *data)
530 ret = tmio_sd_send_cmd(dev, cmd, data);
534 #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
535 CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
536 CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
537 struct tmio_sd_priv *priv = dev_get_priv(dev);
539 if (cmd->cmdidx == MMC_CMD_SEND_STATUS)
540 renesas_sdhi_adjust_hs400_mode_enable(priv);
546 static const struct dm_mmc_ops renesas_sdhi_ops = {
547 .send_cmd = renesas_sdhi_send_cmd,
548 .set_ios = renesas_sdhi_set_ios,
549 .get_cd = tmio_sd_get_cd,
550 #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
551 CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
552 CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
553 .execute_tuning = renesas_sdhi_execute_tuning,
555 #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
556 .wait_dat0 = renesas_sdhi_wait_dat0,
560 #define RENESAS_GEN2_QUIRKS TMIO_SD_CAP_RCAR_GEN2
561 #define RENESAS_GEN3_QUIRKS \
562 TMIO_SD_CAP_64BIT | TMIO_SD_CAP_RCAR_GEN3 | TMIO_SD_CAP_RCAR_UHS
564 static const struct udevice_id renesas_sdhi_match[] = {
565 { .compatible = "renesas,sdhi-r8a7790", .data = RENESAS_GEN2_QUIRKS },
566 { .compatible = "renesas,sdhi-r8a7791", .data = RENESAS_GEN2_QUIRKS },
567 { .compatible = "renesas,sdhi-r8a7792", .data = RENESAS_GEN2_QUIRKS },
568 { .compatible = "renesas,sdhi-r8a7793", .data = RENESAS_GEN2_QUIRKS },
569 { .compatible = "renesas,sdhi-r8a7794", .data = RENESAS_GEN2_QUIRKS },
570 { .compatible = "renesas,sdhi-r8a7795", .data = RENESAS_GEN3_QUIRKS },
571 { .compatible = "renesas,sdhi-r8a7796", .data = RENESAS_GEN3_QUIRKS },
572 { .compatible = "renesas,sdhi-r8a77965", .data = RENESAS_GEN3_QUIRKS },
573 { .compatible = "renesas,sdhi-r8a77970", .data = RENESAS_GEN3_QUIRKS },
574 { .compatible = "renesas,sdhi-r8a77990", .data = RENESAS_GEN3_QUIRKS },
575 { .compatible = "renesas,sdhi-r8a77995", .data = RENESAS_GEN3_QUIRKS },
579 static ulong renesas_sdhi_clk_get_rate(struct tmio_sd_priv *priv)
581 return clk_get_rate(&priv->clk);
584 static void renesas_sdhi_filter_caps(struct udevice *dev)
586 struct tmio_sd_plat *plat = dev_get_platdata(dev);
587 struct tmio_sd_priv *priv = dev_get_priv(dev);
589 if (!(priv->caps & TMIO_SD_CAP_RCAR_GEN3))
592 /* HS400 is not supported on H3 ES1.x and M3W ES1.0,ES1.1,ES1.2 */
593 if (((rmobile_get_cpu_type() == RMOBILE_CPU_TYPE_R8A7795) &&
594 (rmobile_get_cpu_rev_integer() <= 1)) ||
595 ((rmobile_get_cpu_type() == RMOBILE_CPU_TYPE_R8A7796) &&
596 (rmobile_get_cpu_rev_integer() == 1) &&
597 (rmobile_get_cpu_rev_fraction() <= 2)))
598 plat->cfg.host_caps &= ~MMC_MODE_HS400;
600 /* M3W ES1.x for x>2 can use HS400 with manual adjustment */
601 if ((rmobile_get_cpu_type() == RMOBILE_CPU_TYPE_R8A7796) &&
602 (rmobile_get_cpu_rev_integer() == 1) &&
603 (rmobile_get_cpu_rev_fraction() > 2)) {
604 priv->adjust_hs400_enable = true;
605 priv->adjust_hs400_offset = 0;
606 priv->adjust_hs400_calibrate = 0x9;
609 /* M3N can use HS400 with manual adjustment */
610 if (rmobile_get_cpu_type() == RMOBILE_CPU_TYPE_R8A77965) {
611 priv->adjust_hs400_enable = true;
612 priv->adjust_hs400_offset = 0;
613 priv->adjust_hs400_calibrate = 0x0;
616 /* E3 can use HS400 with manual adjustment */
617 if (rmobile_get_cpu_type() == RMOBILE_CPU_TYPE_R8A77990) {
618 priv->adjust_hs400_enable = true;
619 priv->adjust_hs400_offset = 0;
620 priv->adjust_hs400_calibrate = 0x2;
623 /* H3 ES2.0 uses 4 tuning taps */
624 if ((rmobile_get_cpu_type() == RMOBILE_CPU_TYPE_R8A7795) &&
625 (rmobile_get_cpu_rev_integer() == 2))
630 /* H3 ES1.x and M3W ES1.0 uses bit 17 for DTRAEND */
631 if (((rmobile_get_cpu_type() == RMOBILE_CPU_TYPE_R8A7795) &&
632 (rmobile_get_cpu_rev_integer() <= 1)) ||
633 ((rmobile_get_cpu_type() == RMOBILE_CPU_TYPE_R8A7796) &&
634 (rmobile_get_cpu_rev_integer() == 1) &&
635 (rmobile_get_cpu_rev_fraction() == 0)))
636 priv->read_poll_flag = TMIO_SD_DMA_INFO1_END_RD;
638 priv->read_poll_flag = TMIO_SD_DMA_INFO1_END_RD2;
641 static int renesas_sdhi_probe(struct udevice *dev)
643 struct tmio_sd_priv *priv = dev_get_priv(dev);
644 u32 quirks = dev_get_driver_data(dev);
645 struct fdt_resource reg_res;
646 DECLARE_GLOBAL_DATA_PTR;
649 priv->clk_get_rate = renesas_sdhi_clk_get_rate;
651 if (quirks == RENESAS_GEN2_QUIRKS) {
652 ret = fdt_get_resource(gd->fdt_blob, dev_of_offset(dev),
655 dev_err(dev, "\"reg\" resource not found, ret=%i\n",
660 if (fdt_resource_size(®_res) == 0x100)
661 quirks |= TMIO_SD_CAP_16BIT;
664 ret = clk_get_by_index(dev, 0, &priv->clk);
666 dev_err(dev, "failed to get host clock\n");
670 /* set to max rate */
671 ret = clk_set_rate(&priv->clk, 200000000);
673 dev_err(dev, "failed to set rate for host clock\n");
674 clk_free(&priv->clk);
678 ret = clk_enable(&priv->clk);
680 dev_err(dev, "failed to enable host clock\n");
684 ret = tmio_sd_probe(dev, quirks);
686 renesas_sdhi_filter_caps(dev);
688 #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
689 CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
690 CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
691 if (!ret && (priv->caps & TMIO_SD_CAP_RCAR_UHS))
692 renesas_sdhi_reset_tuning(priv);
697 U_BOOT_DRIVER(renesas_sdhi) = {
698 .name = "renesas-sdhi",
700 .of_match = renesas_sdhi_match,
701 .bind = tmio_sd_bind,
702 .probe = renesas_sdhi_probe,
703 .priv_auto_alloc_size = sizeof(struct tmio_sd_priv),
704 .platdata_auto_alloc_size = sizeof(struct tmio_sd_plat),
705 .ops = &renesas_sdhi_ops,