1 From 8a7013f47196abed7e6a40e93d1de1639cd46228 Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Fri, 10 Jul 2015 17:03:03 +0200
4 Subject: [PATCH] mmc: sunxi: Don't start commands while the card is busy
6 Some sdio wifi modules have not been working reliable with the sunxi-mmc
7 host code. This turns out to be caused by it starting new commands while
8 the card signals that it is still busy processing a previous command.
10 This commit fixes this, thereby fixing the wifi reliability issues on
11 the Cubietruck and other sunxi boards using sdio wifi.
13 Reported-by: Eugene K <sigintmailru@gmail.com>
14 Suggested-by: Eugene K <sigintmailru@gmail.com>
15 Cc: Eugene K <sigintmailru@gmail.com>
16 Cc: Arend van Spriel <arend@broadcom.com>
17 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
20 -Properly accredit Eugene K for coming up with the fix for this
22 drivers/mmc/host/sunxi-mmc.c | 32 ++++++++++++++++++++++++++++++++
23 1 file changed, 32 insertions(+)
25 --- a/drivers/mmc/host/sunxi-mmc.c
26 +++ b/drivers/mmc/host/sunxi-mmc.c
27 @@ -289,6 +289,24 @@ static int sunxi_mmc_init_host(struct mm
31 +/* Wait for card to report ready before starting a new cmd */
32 +static int sunxi_mmc_wait_card_ready(struct sunxi_mmc_host *host)
34 + unsigned long expire = jiffies + msecs_to_jiffies(500);
38 + rval = mmc_readl(host, REG_STAS);
39 + } while (time_before(jiffies, expire) && (rval & SDXC_CARD_DATA_BUSY));
41 + if (rval & SDXC_CARD_DATA_BUSY) {
42 + dev_err(mmc_dev(host->mmc), "Error R1 ready timeout\n");
49 static void sunxi_mmc_init_idma_des(struct sunxi_mmc_host *host,
50 struct mmc_data *data)
52 @@ -383,6 +401,8 @@ static void sunxi_mmc_send_manual_stop(s
54 unsigned long expire = jiffies + msecs_to_jiffies(1000);
56 + sunxi_mmc_wait_card_ready(host);
58 cmd_val = SDXC_START | SDXC_RESP_EXPIRE |
59 SDXC_STOP_ABORT_CMD | SDXC_CHECK_RESPONSE_CRC;
61 @@ -597,6 +617,11 @@ static int sunxi_mmc_oclk_onoff(struct s
63 unsigned long expire = jiffies + msecs_to_jiffies(250);
67 + ret = sunxi_mmc_wait_card_ready(host);
71 rval = mmc_readl(host, REG_CLKCR);
72 rval &= ~(SDXC_CARD_CLOCK_ON | SDXC_LOW_POWER_ON);
73 @@ -784,6 +809,13 @@ static void sunxi_mmc_request(struct mmc
74 mmc_request_done(mmc, mrq);
78 + ret = sunxi_mmc_wait_card_ready(host);
80 + mrq->cmd->error = ret;
81 + mmc_request_done(mmc, mrq);
86 ret = sunxi_mmc_map_dma(host, data);