This commit is contained in:
Tom Rini 2022-06-15 23:10:17 -04:00
commit 488d30a1e9
5 changed files with 45 additions and 21 deletions

View file

@ -1060,6 +1060,30 @@ static int esdhc_getcd_common(struct fsl_esdhc_priv *priv)
return timeout > 0;
}
static int esdhc_wait_dat0_common(struct fsl_esdhc_priv *priv, int state,
int timeout_us)
{
struct fsl_esdhc *regs = priv->esdhc_regs;
int ret, err;
u32 tmp;
/* make sure the card clock keep on */
esdhc_setbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
ret = readx_poll_timeout(esdhc_read32, &regs->prsstat, tmp,
!!(tmp & PRSSTAT_DAT0) == !!state,
timeout_us);
/* change to default setting, let host control the card clock */
esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
err = readx_poll_timeout(esdhc_read32, &regs->prsstat, tmp, tmp & PRSSTAT_SDOFF, 100);
if (err)
pr_warn("card clock not gate off as expect.\n");
return ret;
}
static int esdhc_reset(struct fsl_esdhc *regs)
{
ulong start;
@ -1109,11 +1133,19 @@ static int esdhc_set_ios(struct mmc *mmc)
return esdhc_set_ios_common(priv, mmc);
}
static int esdhc_wait_dat0(struct mmc *mmc, int state, int timeout_us)
{
struct fsl_esdhc_priv *priv = mmc->priv;
return esdhc_wait_dat0_common(priv, state, timeout_us);
}
static const struct mmc_ops esdhc_ops = {
.getcd = esdhc_getcd,
.init = esdhc_init,
.send_cmd = esdhc_send_cmd,
.set_ios = esdhc_set_ios,
.wait_dat0 = esdhc_wait_dat0,
};
#endif
@ -1576,25 +1608,9 @@ static int __maybe_unused fsl_esdhc_set_enhanced_strobe(struct udevice *dev)
static int fsl_esdhc_wait_dat0(struct udevice *dev, int state,
int timeout_us)
{
int ret, err;
u32 tmp;
struct fsl_esdhc_priv *priv = dev_get_priv(dev);
struct fsl_esdhc *regs = priv->esdhc_regs;
/* make sure the card clock keep on */
esdhc_setbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
ret = readx_poll_timeout(esdhc_read32, &regs->prsstat, tmp,
!!(tmp & PRSSTAT_DAT0) == !!state,
timeout_us);
/* change to default setting, let host control the card clock */
esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
err = readx_poll_timeout(esdhc_read32, &regs->prsstat, tmp, tmp & PRSSTAT_SDOFF, 100);
if (err)
dev_warn(dev, "card clock not gate off as expect.\n");
return ret;
return esdhc_wait_dat0_common(priv, state, timeout_us);
}
static const struct dm_mmc_ops fsl_esdhc_ops = {

View file

@ -34,6 +34,9 @@ static int mmc_set_signal_voltage(struct mmc *mmc, uint signal_voltage);
static int mmc_wait_dat0(struct mmc *mmc, int state, int timeout_us)
{
if (mmc->cfg->ops->wait_dat0)
return mmc->cfg->ops->wait_dat0(mmc, state, timeout_us);
return -ENOSYS;
}

View file

@ -102,7 +102,7 @@ ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt)
"The erase range would be change to "
"0x" LBAF "~0x" LBAF "\n\n",
mmc->erase_grp_size, start & ~(mmc->erase_grp_size - 1),
((start + blkcnt + mmc->erase_grp_size)
((start + blkcnt + mmc->erase_grp_size - 1)
& ~(mmc->erase_grp_size - 1)) - 1);
while (blk < blkcnt) {

10
env/mmc.c vendored
View file

@ -257,12 +257,15 @@ static inline int erase_env(struct mmc *mmc, unsigned long size,
{
uint blk_start, blk_cnt, n;
struct blk_desc *desc = mmc_get_blk_desc(mmc);
u32 erase_size;
blk_start = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
blk_cnt = ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len;
erase_size = mmc->erase_grp_size * desc->blksz;
blk_start = ALIGN_DOWN(offset, erase_size) / desc->blksz;
blk_cnt = ALIGN(size, erase_size) / desc->blksz;
n = blk_derase(desc, blk_start, blk_cnt);
printf("%d blocks erased: %s\n", n, (n == blk_cnt) ? "OK" : "ERROR");
printf("%d blocks erased at 0x%x: %s\n", n, blk_start,
(n == blk_cnt) ? "OK" : "ERROR");
return (n == blk_cnt) ? 0 : 1;
}
@ -286,6 +289,7 @@ static int env_mmc_erase(void)
goto fini;
}
printf("\n");
ret = erase_env(mmc, CONFIG_ENV_SIZE, offset);
#ifdef CONFIG_ENV_OFFSET_REDUND

View file

@ -561,6 +561,7 @@ struct mmc_ops {
int (*getwp)(struct mmc *mmc);
int (*host_power_cycle)(struct mmc *mmc);
int (*get_b_max)(struct mmc *mmc, void *dst, lbaint_t blkcnt);
int (*wait_dat0)(struct mmc *mmc, int state, int timeout_us);
};
static inline int mmc_hs400_prepare_ddr(struct mmc *mmc)