#define SDHI_VER_GEN2_SDR50 0x490c #define SDHI_VER_RZ_A1 0x820b /* very old datasheets said 0x490c for SDR104, too. They are wrong! */ #define SDHI_VER_GEN2_SDR104 0xcb0d #define SDHI_VER_GEN3_SD 0xcc10 #define SDHI_VER_GEN3_SDMMC 0xcd10
#define SDHI_GEN3_MMC0_ADDR 0xee140000
staticvoid renesas_sdhi_sdbuf_width(struct tmio_mmc_host *host, int width)
{
u32 val;
/* * see also * renesas_sdhi_of_data :: dma_buswidth
*/ switch (sd_ctrl_read16(host, CTL_VERSION)) { case SDHI_VER_GEN2_SDR50:
val = (width == 32) ? HOST_MODE_GEN2_SDR50_WMODE : 0; break; case SDHI_VER_GEN2_SDR104:
val = (width == 32) ? 0 : HOST_MODE_GEN2_SDR104_WMODE; break; case SDHI_VER_GEN3_SD: case SDHI_VER_GEN3_SDMMC: if (width == 64)
val = HOST_MODE_GEN3_64BIT; elseif (width == 32)
val = HOST_MODE_GEN3_32BIT; else
val = HOST_MODE_GEN3_16BIT; break; default: /* nothing to do */ return;
}
ret = clk_prepare_enable(priv->clk_cd); if (ret < 0) return ret;
/* * The clock driver may not know what maximum frequency * actually works, so it should be set with the max-frequency * property which will already have been read to f_max. If it * was missing, assume the current frequency is the maximum.
*/ if (!mmc->f_max)
mmc->f_max = clk_get_rate(priv->clk);
/* * Minimum frequency is the minimum input clock frequency * divided by our maximum divider.
*/
mmc->f_min = max(clk_round_rate(priv->clk, 1) / 512, 1L);
/* enable 16bit data access on SDBUF as default */
renesas_sdhi_sdbuf_width(host, 16);
/* * We simply return the current rate if a) we are not on a R-Car Gen2+ * SoC (may work for others, but untested) or b) if the SCC needs its * clock during tuning, so we don't change the external clock setup.
*/ if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2) || mmc_doing_tune(host->mmc)) return clk_get_rate(priv->clk);
/* * We want the bus clock to be as close as possible to, but no * greater than, new_clock. As we can divide by 1 << i for * any i in [0, 9] we want the input clock to be as close as * possible, but no greater than, new_clock << i. * * Add an upper limit of 1/1024 rate higher to the clock rate to fix * clk rate jumping to lower rate due to rounding error (eg: RZ/G2L has * 3 clk sources 533.333333 MHz, 400 MHz and 266.666666 MHz. The request * for 533.333333 MHz will selects a slower 400 MHz due to rounding * error (533333333 Hz / 4 * 4 = 533333332 Hz < 533333333 Hz)).
*/ for (i = min(9, ilog2(UINT_MAX / new_clock)); i >= 0; i--) {
freq = clk_round_rate(ref_clk, new_clock << i);
new_upper_limit = (new_clock << i) + ((new_clock << i) >> 10); if (freq > new_upper_limit) { /* Too fast; look for a slightly slower option */
freq = clk_round_rate(ref_clk, (new_clock << i) / 4 * 3); if (freq > new_upper_limit) continue;
}
/* * Add a margin of 1/1024 rate higher to the clock rate in order * to avoid clk variable setting a value of 0 due to the margin * provided for actual_clock in renesas_sdhi_clk_update().
*/
clk_margin = new_clock >> 10; for (clk = 0x80000080; new_clock + clk_margin >= (clock << 1); clk >>= 1)
clock <<= 1;
/* 1/1 clock is option */ if ((host->pdata->flags & TMIO_MMC_CLK_ACTUAL) && ((clk >> 22) & 0x1)) { if (!(host->mmc->ios.timing == MMC_TIMING_MMC_HS400))
clk |= 0xff; else
clk &= ~0xff;
}
switch (ios->signal_voltage) { case MMC_SIGNAL_VOLTAGE_330:
pin_state = priv->pins_default; break; case MMC_SIGNAL_VOLTAGE_180:
pin_state = priv->pins_uhs; break; default: return -EINVAL;
}
/* * If anything is missing, assume signal voltage is fixed at * 3.3V and succeed/fail accordingly.
*/ if (IS_ERR(priv->pinctrl) || IS_ERR(pin_state)) return ios->signal_voltage ==
MMC_SIGNAL_VOLTAGE_330 ? 0 : -EINVAL;
ret = mmc_regulator_set_vqmmc(host->mmc, ios); if (ret < 0) return ret;
/* only populated for TMIO_MMC_MIN_RCAR2 */ staticvoid renesas_sdhi_reset(struct tmio_mmc_host *host, bool preserve)
{ struct renesas_sdhi *priv = host_to_priv(host); int ret;
u16 val;
if (!preserve) { if (priv->rstc) {
u32 sd_status; /* * HW reset might have toggled the regulator state in * HW which regulator core might be unaware of so save * and restore the regulator state during HW reset.
*/ if (priv->rdev)
sd_status = sd_ctrl_read32(host, CTL_SD_STATUS);
reset_control_reset(priv->rstc); /* Unknown why but without polling reset status, it will hang */
read_poll_timeout(reset_control_status, ret, ret == 0, 1, 100, false, priv->rstc); /* At least SDHI_VER_GEN2_SDR50 needs manual release of reset */
sd_ctrl_write16(host, CTL_RESET_SD, 0x0001); if (priv->rdev)
sd_ctrl_write32(host, CTL_SD_STATUS, sd_status);
/* * When tuning CMD19 is issued twice for each tap, merge the * result requiring the tap to be good in both runs before * considering it for tuning selection.
*/ for (i = 0; i < taps_size; i++) { int offset = priv->tap_num * (i < priv->tap_num ? 1 : -1);
if (!test_bit(i, priv->taps))
clear_bit(i + offset, priv->taps);
if (!test_bit(i, priv->smpcmp))
clear_bit(i + offset, priv->smpcmp);
}
/* * If all TAP are OK, the sampling clock position is selected by * identifying the change point of data.
*/ if (bitmap_full(priv->taps, taps_size)) {
bitmap = priv->smpcmp;
min_tap_row = 1;
} else {
bitmap = priv->taps;
min_tap_row = SH_MOBILE_SDHI_MIN_TAP_ROW;
}
/* * Find the longest consecutive run of successful probes. If that * is at least SH_MOBILE_SDHI_MIN_TAP_ROW probes long then use the * center index as the tap, otherwise bail out.
*/
for_each_set_bitrange(rs, re, bitmap, taps_size) { if (re - rs > tap_cnt) {
tap_end = re;
tap_start = rs;
tap_cnt = tap_end - tap_start;
}
}
/* Change TAP position according to correction status */ if (sdhi_has_quirk(priv, manual_tap_correction) &&
host->mmc->ios.timing == MMC_TIMING_MMC_HS400) {
u32 bad_taps = priv->quirks ? priv->quirks->hs400_bad_taps : 0; /* * With HS400, the DAT signal is based on DS, not CLK. * Therefore, use only CMD status.
*/
u32 smpcmp = sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_SMPCMP) &
SH_MOBILE_SDHI_SCC_SMPCMP_CMD_ERR; if (!smpcmp) { returnfalse; /* no error in CMD signal */
} elseif (smpcmp == SH_MOBILE_SDHI_SCC_SMPCMP_CMD_REQUP) {
new_tap++;
error_tap--;
} elseif (smpcmp == SH_MOBILE_SDHI_SCC_SMPCMP_CMD_REQDOWN) {
new_tap--;
error_tap++;
} else { returntrue; /* need retune */
}
/* * When new_tap is a bad tap, we cannot change. Then, we compare * with the HS200 tuning result. When smpcmp[error_tap] is OK, * we can at least retune.
*/ if (bad_taps & BIT(new_tap % priv->tap_num)) return test_bit(error_tap % priv->tap_num, priv->smpcmp);
} else { if (!priv->card_is_sdio &&
!(val & SH_MOBILE_SDHI_SCC_RVSREQ_RVSERR)) {
u32 smpcmp = sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_SMPCMP);
/* DAT1 is unmatched because of an SDIO irq */ if (smpcmp & (BIT(17) | BIT(1))) returnfalse;
} if (val & SH_MOBILE_SDHI_SCC_RVSREQ_RVSERR) returntrue; /* need retune */ elseif (val & SH_MOBILE_SDHI_SCC_RVSREQ_REQTAPUP)
new_tap++; elseif (val & SH_MOBILE_SDHI_SCC_RVSREQ_REQTAPDOWN)
new_tap--; else returnfalse;
}
/* * Skip checking SCC errors when running on 4 taps in HS400 mode as * any retuning would still result in the same 4 taps being used.
*/ if (!(host->mmc->ios.timing == MMC_TIMING_UHS_SDR104) &&
!(host->mmc->ios.timing == MMC_TIMING_MMC_HS200) &&
!(host->mmc->ios.timing == MMC_TIMING_MMC_HS400 && !use_4tap)) returnfalse;
if (mmc_doing_tune(host->mmc)) returnfalse;
/* mrq can be NULL to check SCC error on SDIO irq without any request */ if (mrq) { if (((mrq->cmd->error == -ETIMEDOUT) ||
(mrq->data && mrq->data->error == -ETIMEDOUT)) &&
((host->mmc->caps & MMC_CAP_NONREMOVABLE) ||
(host->ops.get_cd && host->ops.get_cd(host->mmc))))
ret |= true;
}
if (sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL) &
SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN)
ret |= renesas_sdhi_auto_correction(host); else
ret |= renesas_sdhi_manual_correction(host, use_4tap);
/* * This controller cannot do auto-retune with SDIO irqs, so we * then need to enforce manual correction. However, when tuning, * mmc->card is not populated yet, so we don't know if the card * is SDIO. init_card provides this information earlier, so we * keep a copy of it.
*/
priv->card_is_sdio = mmc_card_sdio(card);
}
staticvoid renesas_sdhi_sdio_irq(struct tmio_mmc_host *host)
{ /* This controller requires retune when an SDIO irq occurs */ if (renesas_sdhi_check_scc_error(host, NULL))
mmc_retune_needed(host->mmc);
}
staticint renesas_sdhi_wait_idle(struct tmio_mmc_host *host, u32 bit)
{ int timeout = 1000; /* CBSY is set when busy, SCLKDIVEN is cleared when busy */
u32 wait_state = (bit == TMIO_STAT_CMD_BUSY ? TMIO_STAT_CMD_BUSY : 0);
while (--timeout && (sd_ctrl_read16_and_16_as_32(host, CTL_STATUS)
& bit) == wait_state)
udelay(1);
if (!timeout) {
dev_warn(&host->pdev->dev, "timeout waiting for SD bus idle\n"); return -EBUSY;
}
return 0;
}
staticint renesas_sdhi_write16_hook(struct tmio_mmc_host *host, int addr)
{
u32 bit = TMIO_STAT_SCLKDIVEN;
switch (addr) { case CTL_SD_CMD: case CTL_STOP_INTERNAL_ACTION: case CTL_XFER_BLK_COUNT: case CTL_SD_XFER_LEN: case CTL_SD_MEM_CARD_OPT: case CTL_TRANSACTION_CTL: case CTL_DMA_ENABLE: case CTL_HOST_MODE: if (host->pdata->flags & TMIO_MMC_HAVE_CBSY)
bit = TMIO_STAT_CMD_BUSY;
fallthrough; case CTL_SD_CARD_CLK_CTL: return renesas_sdhi_wait_idle(host, bit);
}
return 0;
}
staticint renesas_sdhi_multi_io_quirk(struct mmc_card *card, unsignedint direction, int blk_size)
{ /* * In Renesas controllers, when performing a * multiple block read of one or two blocks, * depending on the timing with which the * response register is read, the response * value may not be read properly. * Use single block read for this HW bug
*/ if ((direction == MMC_DATA_READ) &&
blk_size == 2) return 1;
priv->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(priv->clk)) return dev_err_probe(&pdev->dev, PTR_ERR(priv->clk), "cannot get clock");
priv->clkh = devm_clk_get_optional(&pdev->dev, "clkh"); if (IS_ERR(priv->clkh)) return dev_err_probe(&pdev->dev, PTR_ERR(priv->clkh), "cannot get clkh");
/* * Some controllers provide a 2nd clock just to run the internal card * detection logic. Unfortunately, the existing driver architecture does * not support a separation of clocks for runtime PM usage. When * native hotplug is used, the tmio driver assumes that the core * must continue to run for card detect to stay active, so we cannot * disable it. * Additionally, it is prohibited to supply a clock to the core but not * to the card detect circuit. That leaves us with if separate clocks * are presented, we must treat them both as virtually 1 clock.
*/
priv->clk_cd = devm_clk_get_optional(&pdev->dev, "cd"); if (IS_ERR(priv->clk_cd)) return dev_err_probe(&pdev->dev, PTR_ERR(priv->clk_cd), "cannot get cd clock");
priv->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL); if (IS_ERR(priv->rstc)) return PTR_ERR(priv->rstc);
if (sdhi_has_quirk(priv, hs400_disabled))
host->mmc->caps2 &= ~(MMC_CAP2_HS400 | MMC_CAP2_HS400_ES);
/* For some SoC, we disable internal WP. GPIO may override this */ if (mmc_host_can_gpio_ro(host->mmc))
mmc_data->capabilities2 &= ~MMC_CAP2_NO_WRITE_PROTECT;
/* SDR speeds are only available on Gen2+ */ if (mmc_data->flags & TMIO_MMC_MIN_RCAR2) { /* card_busy caused issues on r8a73a4 (pre-Gen2) CD-less SDHI */
host->ops.card_busy = renesas_sdhi_card_busy;
host->ops.start_signal_voltage_switch =
renesas_sdhi_start_signal_voltage_switch;
host->sdcard_irq_setbit_mask = TMIO_STAT_ALWAYS_SET_27;
host->sdcard_irq_mask_all = TMIO_MASK_ALL_RCAR2;
host->reset = renesas_sdhi_reset;
} else {
host->sdcard_irq_mask_all = TMIO_MASK_ALL;
}
/* Orginally registers were 16 bit apart, could be 32 or 64 nowadays */ if (!host->bus_shift && resource_size(res) > 0x100) /* old way to determine the shift */
host->bus_shift = 1;
ver = sd_ctrl_read16(host, CTL_VERSION); /* GEN2_SDR104 is first known SDHI to use 32bit block count */ if (ver < SDHI_VER_GEN2_SDR104 && mmc_data->max_blk_count > U16_MAX)
mmc_data->max_blk_count = U16_MAX;
/* One Gen2 SDHI incarnation does NOT have a CBSY bit */ if (ver == SDHI_VER_GEN2_SDR50)
mmc_data->flags &= ~TMIO_MMC_HAVE_CBSY;
/* these have an EXTOP bit */ if (ver >= SDHI_VER_GEN3_SD)
host->get_timeout_cycles = renesas_sdhi_gen3_get_cycles;
/* Check for SCC so we can reset it if needed */ if (of_data && of_data->scc_offset && ver >= SDHI_VER_GEN2_SDR104)
priv->scc_ctl = host->ctl + of_data->scc_offset;
/* Enable tuning iff we have an SCC and a supported mode */ if (priv->scc_ctl && (host->mmc->caps & MMC_CAP_UHS_SDR104 ||
host->mmc->caps2 & MMC_CAP2_HSX00_1_8V)) { conststruct renesas_sdhi_scc *taps = of_data->taps; bool use_4tap = sdhi_has_quirk(priv, hs400_4taps); bool hit = false;
for (i = 0; i < of_data->taps_num; i++) { if (taps[i].clk_rate == 0 ||
taps[i].clk_rate == host->mmc->f_max) {
priv->scc_tappos = taps->tap;
priv->scc_tappos_hs400 = use_4tap ?
taps->tap_hs400_4tap :
taps->tap;
hit = true; break;
}
}
if (!hit)
dev_warn(&host->pdev->dev, "Unknown clock rate for tuning\n");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.