Skip to content

Commit 7168977

Browse files
Ye.Lipantoniou
Ye.Li
authored andcommitted
esdhc/usdhc: Fix PIO mode bug in fsl_esdhc driver
When configure the fsl_esdhc driver to PIO mode by defining "CONFIG_SYS_FSL_ESDHC_USE_PIO", the SD/MMC read and write will fail. Two bugs in the driver to cause the issue: 1. The read buffer was invalidated after reading from DATAPORT register, which should be only applied to DMA mode. The valid data in cache was overwritten by physical memory. 2. The watermarks are not set in PIO mode, will cause according state not be set. Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com> Signed-off-by: Ye.Li <B37916@freescale.com>
1 parent d7782d0 commit 7168977

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

drivers/mmc/fsl_esdhc.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
174174
int timeout;
175175
struct fsl_esdhc_cfg *cfg = mmc->priv;
176176
struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
177-
#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
177+
178178
uint wml_value;
179179

180180
wml_value = data->blocksize/4;
@@ -184,12 +184,15 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
184184
wml_value = WML_RD_WML_MAX_VAL;
185185

186186
esdhc_clrsetbits32(&regs->wml, WML_RD_WML_MASK, wml_value);
187+
#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
187188
esdhc_write32(&regs->dsaddr, (u32)data->dest);
189+
#endif
188190
} else {
191+
#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
189192
flush_dcache_range((ulong)data->src,
190193
(ulong)data->src+data->blocks
191194
*data->blocksize);
192-
195+
#endif
193196
if (wml_value > WML_WR_WML_MAX)
194197
wml_value = WML_WR_WML_MAX_VAL;
195198
if ((esdhc_read32(&regs->prsstat) & PRSSTAT_WPSPL) == 0) {
@@ -199,19 +202,10 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
199202

200203
esdhc_clrsetbits32(&regs->wml, WML_WR_WML_MASK,
201204
wml_value << 16);
205+
#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
202206
esdhc_write32(&regs->dsaddr, (u32)data->src);
207+
#endif
203208
}
204-
#else /* CONFIG_SYS_FSL_ESDHC_USE_PIO */
205-
if (!(data->flags & MMC_DATA_READ)) {
206-
if ((esdhc_read32(&regs->prsstat) & PRSSTAT_WPSPL) == 0) {
207-
printf("\nThe SD card is locked. "
208-
"Can not write to a locked card.\n\n");
209-
return TIMEOUT;
210-
}
211-
esdhc_write32(&regs->dsaddr, (u32)data->src);
212-
} else
213-
esdhc_write32(&regs->dsaddr, (u32)data->dest);
214-
#endif /* CONFIG_SYS_FSL_ESDHC_USE_PIO */
215209

216210
esdhc_write32(&regs->blkattr, data->blocks << 16 | data->blocksize);
217211

@@ -388,9 +382,10 @@ esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
388382
goto out;
389383
}
390384
} while ((irqstat & DATA_COMPLETE) != DATA_COMPLETE);
391-
#endif
385+
392386
if (data->flags & MMC_DATA_READ)
393387
check_and_invalidate_dcache_range(cmd, data);
388+
#endif
394389
}
395390

396391
out:

0 commit comments

Comments
 (0)