Skip to content

Commit 3eea697

Browse files
committed
mmc: sdricoh_cs: Throttle polling rate for commands
Rather than to poll in a busy-loop, let's convert into using read_poll_timeout() and insert a small delay between each polling attempts. In particular, this avoids hogging the CPU. Additionally, to convert to read_poll_timeout() we also need to switch from using a specific number of polling attempts, into a specific timeout in us instead. The previous 100000 attempts, is translated into a total timeout of total 1s, as that seemed like reasonable value to pick. Cc: Sascha Sommer <[email protected]> Signed-off-by: Ulf Hansson <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent eadb789 commit 3eea697

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

drivers/mmc/host/sdricoh_cs.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static unsigned int switchlocked;
5959
#define STATUS_BUSY 0x40000000
6060

6161
/* timeouts */
62-
#define CMD_TIMEOUT 100000
62+
#define SDRICOH_CMD_TIMEOUT_US 1000000
6363
#define SDRICOH_DATA_TIMEOUT_US 1000000
6464

6565
/* list of supported pcmcia devices */
@@ -158,8 +158,7 @@ static int sdricoh_query_status(struct sdricoh_host *host, unsigned int wanted)
158158
static int sdricoh_mmc_cmd(struct sdricoh_host *host, struct mmc_command *cmd)
159159
{
160160
unsigned int status;
161-
int result = 0;
162-
unsigned int loop = 0;
161+
int ret;
163162
unsigned char opcode = cmd->opcode;
164163

165164
/* reset status reg? */
@@ -175,24 +174,24 @@ static int sdricoh_mmc_cmd(struct sdricoh_host *host, struct mmc_command *cmd)
175174
/* fill parameters */
176175
sdricoh_writel(host, R204_CMD_ARG, cmd->arg);
177176
sdricoh_writel(host, R200_CMD, (0x10000 << 8) | opcode);
177+
178178
/* wait for command completion */
179-
if (opcode) {
180-
for (loop = 0; loop < CMD_TIMEOUT; loop++) {
181-
status = sdricoh_readl(host, R21C_STATUS);
182-
sdricoh_writel(host, R2E4_STATUS_RESP, status);
183-
if (status & STATUS_CMD_FINISHED)
184-
break;
185-
}
186-
/* don't check for timeout in the loop it is not always
187-
reset correctly
188-
*/
189-
if (loop == CMD_TIMEOUT || status & STATUS_CMD_TIMEOUT)
190-
result = -ETIMEDOUT;
179+
if (!opcode)
180+
return 0;
191181

192-
}
182+
ret = read_poll_timeout(sdricoh_readl, status,
183+
sdricoh_status_ok(host, status, STATUS_CMD_FINISHED),
184+
32, SDRICOH_CMD_TIMEOUT_US, false,
185+
host, R21C_STATUS);
193186

194-
return result;
187+
/*
188+
* Don't check for timeout status in the loop, as it's not always reset
189+
* correctly.
190+
*/
191+
if (ret || status & STATUS_CMD_TIMEOUT)
192+
return -ETIMEDOUT;
195193

194+
return 0;
196195
}
197196

198197
static int sdricoh_reset(struct sdricoh_host *host)

0 commit comments

Comments
 (0)