From patchwork Fri Jul 10 15:14:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 6766851 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BE599C05AC for ; Fri, 10 Jul 2015 15:14:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DEF9220701 for ; Fri, 10 Jul 2015 15:14:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EE51F20688 for ; Fri, 10 Jul 2015 15:14:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933057AbbGJPOs (ORCPT ); Fri, 10 Jul 2015 11:14:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57446 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932747AbbGJPOs (ORCPT ); Fri, 10 Jul 2015 11:14:48 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 7686E388B97; Fri, 10 Jul 2015 15:14:47 +0000 (UTC) Received: from shalem.localdomain.com (vpn1-7-193.ams2.redhat.com [10.36.7.193]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6AFEi95018512; Fri, 10 Jul 2015 11:14:45 -0400 From: Hans de Goede To: Chris Ball , Ulf Hansson , Mike Turquette , Maxime Ripard Cc: Arend van Spriel , Sascha Hauer , linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree , linux-sunxi@googlegroups.com, Hans de Goede , Eugene K Subject: [PATCH v2] mmc: sunxi: Don't start commands while the card is busy Date: Fri, 10 Jul 2015 17:14:44 +0200 Message-Id: <1436541284-11800-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some sdio wifi modules have not been working reliable with the sunxi-mmc host code. This turns out to be caused by it starting new commands while the card signals that it is still busy processing a previous command. This commit fixes this, thereby fixing the wifi reliability issues on the Cubietruck and other sunxi boards using sdio wifi. Reported-by: Eugene K Suggested-by: Eugene K Cc: Eugene K Cc: Arend van Spriel Signed-off-by: Hans de Goede --- Changes in v2: -Properly accredit Eugene K for coming up with the fix for this --- drivers/mmc/host/sunxi-mmc.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c index 4d3e1ff..daa90b7 100644 --- a/drivers/mmc/host/sunxi-mmc.c +++ b/drivers/mmc/host/sunxi-mmc.c @@ -289,6 +289,24 @@ static int sunxi_mmc_init_host(struct mmc_host *mmc) return 0; } +/* Wait for card to report ready before starting a new cmd */ +static int sunxi_mmc_wait_card_ready(struct sunxi_mmc_host *host) +{ + unsigned long expire = jiffies + msecs_to_jiffies(500); + u32 rval; + + do { + rval = mmc_readl(host, REG_STAS); + } while (time_before(jiffies, expire) && (rval & SDXC_CARD_DATA_BUSY)); + + if (rval & SDXC_CARD_DATA_BUSY) { + dev_err(mmc_dev(host->mmc), "Error R1 ready timeout\n"); + return -EIO; + } + + return 0; +} + static void sunxi_mmc_init_idma_des(struct sunxi_mmc_host *host, struct mmc_data *data) { @@ -383,6 +401,8 @@ static void sunxi_mmc_send_manual_stop(struct sunxi_mmc_host *host, u32 arg, cmd_val, ri; unsigned long expire = jiffies + msecs_to_jiffies(1000); + sunxi_mmc_wait_card_ready(host); + cmd_val = SDXC_START | SDXC_RESP_EXPIRE | SDXC_STOP_ABORT_CMD | SDXC_CHECK_RESPONSE_CRC; @@ -597,6 +617,11 @@ static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host *host, u32 oclk_en) { unsigned long expire = jiffies + msecs_to_jiffies(250); u32 rval; + int ret; + + ret = sunxi_mmc_wait_card_ready(host); + if (ret) + return ret; rval = mmc_readl(host, REG_CLKCR); rval &= ~(SDXC_CARD_CLOCK_ON | SDXC_LOW_POWER_ON); @@ -785,6 +810,13 @@ static void sunxi_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq) return; } + ret = sunxi_mmc_wait_card_ready(host); + if (ret) { + mrq->cmd->error = ret; + mmc_request_done(mmc, mrq); + return; + } + if (data) { ret = sunxi_mmc_map_dma(host, data); if (ret < 0) {