kernel: update 4.1 to 4.1.5
[openwrt/svn-archive/archive.git] / target / linux / sunxi / patches-4.1 / 140-mmc-sdio-reliability-fix.patch
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
5
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.
9
10 This commit fixes this, thereby fixing the wifi reliability issues on
11 the Cubietruck and other sunxi boards using sdio wifi.
12
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>
18 ---
19 Changes in v2:
20 -Properly accredit Eugene K for coming up with the fix for this
21 ---
22 drivers/mmc/host/sunxi-mmc.c | 32 ++++++++++++++++++++++++++++++++
23 1 file changed, 32 insertions(+)
24
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
28 return 0;
29 }
30
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)
33 +{
34 + unsigned long expire = jiffies + msecs_to_jiffies(500);
35 + u32 rval;
36 +
37 + do {
38 + rval = mmc_readl(host, REG_STAS);
39 + } while (time_before(jiffies, expire) && (rval & SDXC_CARD_DATA_BUSY));
40 +
41 + if (rval & SDXC_CARD_DATA_BUSY) {
42 + dev_err(mmc_dev(host->mmc), "Error R1 ready timeout\n");
43 + return -EIO;
44 + }
45 +
46 + return 0;
47 +}
48 +
49 static void sunxi_mmc_init_idma_des(struct sunxi_mmc_host *host,
50 struct mmc_data *data)
51 {
52 @@ -383,6 +401,8 @@ static void sunxi_mmc_send_manual_stop(s
53 u32 arg, cmd_val, ri;
54 unsigned long expire = jiffies + msecs_to_jiffies(1000);
55
56 + sunxi_mmc_wait_card_ready(host);
57 +
58 cmd_val = SDXC_START | SDXC_RESP_EXPIRE |
59 SDXC_STOP_ABORT_CMD | SDXC_CHECK_RESPONSE_CRC;
60
61 @@ -597,6 +617,11 @@ static int sunxi_mmc_oclk_onoff(struct s
62 {
63 unsigned long expire = jiffies + msecs_to_jiffies(250);
64 u32 rval;
65 + int ret;
66 +
67 + ret = sunxi_mmc_wait_card_ready(host);
68 + if (ret)
69 + return ret;
70
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);
75 return;
76 }
77 +
78 + ret = sunxi_mmc_wait_card_ready(host);
79 + if (ret) {
80 + mrq->cmd->error = ret;
81 + mmc_request_done(mmc, mrq);
82 + return;
83 + }
84
85 if (data) {
86 ret = sunxi_mmc_map_dma(host, data);