Raise the SDHCI timeout to 10 seconds and add a sysctl to allow changing

this value at runtime.

The SD card specification says that a block write or a block erase can take
up to 250ms to complete and thus, under some circumstances, the existent 2
seconds timeout was triggering with normal usage.

This change fixes the sporadic controller timeout that happens on RPi and
RPi 2.

Discussed with:		ian (some time ago)
This commit is contained in:
Luiz Otavio O Souza 2015-05-21 20:09:36 +00:00
parent 9cf4cabed7
commit ba6fc1c73c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=283263
2 changed files with 10 additions and 2 deletions

View File

@ -615,10 +615,16 @@ sdhci_init_slot(device_t dev, struct sdhci_slot *slot, int num)
(slot->opt & SDHCI_HAVE_DMA) ? "DMA" : "PIO");
sdhci_dumpregs(slot);
}
slot->timeout = 10;
SYSCTL_ADD_INT(device_get_sysctl_ctx(slot->bus),
SYSCTL_CHILDREN(device_get_sysctl_tree(slot->bus)), OID_AUTO,
"timeout", CTLFLAG_RW, &slot->timeout, 0,
"Maximum timeout for SDHCI transfers (in secs)");
TASK_INIT(&slot->card_task, 0, sdhci_card_task, slot);
callout_init(&slot->card_callout, 1);
callout_init_mtx(&slot->timeout_callout, &slot->mtx, 0);
return (0);
}
@ -872,7 +878,8 @@ sdhci_start_command(struct sdhci_slot *slot, struct mmc_command *cmd)
/* Start command. */
WR2(slot, SDHCI_COMMAND_FLAGS, (cmd->opcode << 8) | (flags & 0xff));
/* Start timeout callout. */
callout_reset(&slot->timeout_callout, 2*hz, sdhci_timeout, slot);
callout_reset(&slot->timeout_callout, slot->timeout * hz,
sdhci_timeout, slot);
}
static void

View File

@ -271,6 +271,7 @@ struct sdhci_slot {
#define SDHCI_HAVE_DMA 1
#define SDHCI_PLATFORM_TRANSFER 2
u_char version;
int timeout; /* Transfer timeout */
uint32_t max_clk; /* Max possible freq */
uint32_t timeout_clk; /* Timeout freq */
bus_dma_tag_t dmatag;