From patchwork Wed Feb 27 03:36:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Lin X-Patchwork-Id: 10831015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DA9341880 for ; Wed, 27 Feb 2019 03:38:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C39A72ABDF for ; Wed, 27 Feb 2019 03:38:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7C552D83E; Wed, 27 Feb 2019 03:38:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_WEB autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8D9052ABDF for ; Wed, 27 Feb 2019 03:38:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=6IjYt4chbDetNrhaYp73Xy/uMQGz6Yw14UN0gVnet3g=; b=gc/S/Cilr3iJxX7hKRW/xzvoyZ s0is2OFNKxVr9G2y/PwP8CrKD0nBZelXnzAeD1vbtyq9l/f0rVveFE1ejYVjSDX/9rAzkTdQegb9g Viev+2nuo1igd3vjmXjKLHaMfUXjwGCoobImVTQ+hodnU1w1hc4v4Ty0geEs8v6yTbHpQd+vGCUMz JKgfH2AaQZx5sbCpVQdTt7FvM2+oC8y8y1rfN2xYZEn5k7oXBuMxzrVM5N2aioZ3z96tgpsfGiVqI KOp3l6O/1VT963XnDeUy+bf2MKp/2b55fMx3ahsI/F3KNwKNoKC5JZPHW2lnZpjt5bqh6H6P9FCjW dupZvQeQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gyq33-0001c4-0F; Wed, 27 Feb 2019 03:38:21 +0000 Received: from lucky1.263xmail.com ([211.157.147.130]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gyq2y-0001aY-Ox for linux-rockchip@lists.infradead.org; Wed, 27 Feb 2019 03:38:18 +0000 Received: from shawn.lin?rock-chips.com (unknown [192.168.167.110]) by lucky1.263xmail.com (Postfix) with ESMTP id 179874E66; Wed, 27 Feb 2019 11:38:08 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P24029T140137178584832S1551238684445785_; Wed, 27 Feb 2019 11:38:07 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <4a4c17db7002f9eb3bddb51c00b59f1f> X-RL-SENDER: shawn.lin@rock-chips.com X-SENDER: lintao@rock-chips.com X-LOGIN-NAME: shawn.lin@rock-chips.com X-FST-TO: jh80.chung@samsung.com X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 From: Shawn Lin To: Jaehoon Chung , Ulf Hansson Subject: [PATCH 1/3] mmc: dw_mmc: Check busy state in dw_mci_request() Date: Wed, 27 Feb 2019 11:36:41 +0800 Message-Id: <1551238603-82412-2-git-send-email-shawn.lin@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1551238603-82412-1-git-send-email-shawn.lin@rock-chips.com> References: <1551238603-82412-1-git-send-email-shawn.lin@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190226_193817_014936_02D0C452 X-CRM114-Status: GOOD ( 13.78 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , Shawn Lin , Ziyuan Xu , linux-mmc@vger.kernel.org, Douglas Anderson , linux-rockchip@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Move it from dw_mci_start_command() to dw_mci_request(). Then dw_mci_wait_while_busy() isn't called with host's lock hold. Signed-off-by: Shawn Lin --- drivers/mmc/host/dw_mmc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 80dc2fd..703dedf 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -426,7 +426,6 @@ static void dw_mci_start_command(struct dw_mci *host, mci_writel(host, CMDARG, cmd->arg); wmb(); /* drain writebuffer */ - dw_mci_wait_while_busy(host, cmd_flags); mci_writel(host, CMD, cmd_flags | SDMMC_CMD_START); @@ -1419,6 +1418,10 @@ static void dw_mci_request(struct mmc_host *mmc, struct mmc_request *mrq) return; } + if ((mrq->cmd->opcode != MMC_SEND_STATUS && mrq->cmd->data) && + !(mrq->cmd->opcode == SD_SWITCH_VOLTAGE)) + dw_mci_wait_while_busy(host, SDMMC_CMD_PRV_DAT_WAIT); + spin_lock_bh(&host->lock); dw_mci_queue_request(host, slot, mrq); From patchwork Wed Feb 27 03:36:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Lin X-Patchwork-Id: 10831017 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC1E1922 for ; Wed, 27 Feb 2019 03:38:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A55572ABDF for ; Wed, 27 Feb 2019 03:38:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 99AF02D83E; Wed, 27 Feb 2019 03:38:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_WEB autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 22F5F2ABDF for ; Wed, 27 Feb 2019 03:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=6J57NlY+1B1q9xIAUw2z5OKpSt5iCkXNDZw8gqxwRPI=; b=V1L/F3Ck1Iuexa3dfgykMQPDE9 gR0fNjm3BGXeVASF/MVc+AIG1NBBUMM5juwABA4hIeybGexVX3n7weTvt+W/+RrKDQg0rLFavB1IS ehyYDxJe6K33Xw83sv5WyrChz6bB83h0WNSq5hX9ojfn3sC6aeJbVyj0AxGWhFKGVicXuZ8G1M2hQ JdcOygD9mwIkLTVcxlq2UF70C9LeND71BlkNj/TZyYGswZ9OsStOlVwcihS11d3TN4k36HRAENFPp U4KkpZOvhhlztRtXQaBiqhrSJ81+uuRE+yjnDdBHOf/Nu7shGajprGslA6OZDK3QgHVOy08cYrRHy BB15U8eA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gyq34-0001dK-Kq; Wed, 27 Feb 2019 03:38:22 +0000 Received: from lucky1.263xmail.com ([211.157.147.133]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gyq2z-0001aa-Au for linux-rockchip@lists.infradead.org; Wed, 27 Feb 2019 03:38:19 +0000 Received: from shawn.lin?rock-chips.com (unknown [192.168.167.110]) by lucky1.263xmail.com (Postfix) with ESMTP id 847F64239; Wed, 27 Feb 2019 11:38:13 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P24029T140137178584832S1551238684445785_; Wed, 27 Feb 2019 11:38:13 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <778743af09251c50871dac8721ab77b1> X-RL-SENDER: shawn.lin@rock-chips.com X-SENDER: lintao@rock-chips.com X-LOGIN-NAME: shawn.lin@rock-chips.com X-FST-TO: jh80.chung@samsung.com X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 From: Shawn Lin To: Jaehoon Chung , Ulf Hansson Subject: [PATCH 2/3] mmc: dw_mmc: Add hardware unbusy interrupt support Date: Wed, 27 Feb 2019 11:36:42 +0800 Message-Id: <1551238603-82412-3-git-send-email-shawn.lin@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1551238603-82412-1-git-send-email-shawn.lin@rock-chips.com> References: <1551238603-82412-1-git-send-email-shawn.lin@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190226_193817_760778_33510FB9 X-CRM114-Status: GOOD ( 19.67 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , Shawn Lin , Ziyuan Xu , linux-mmc@vger.kernel.org, Douglas Anderson , linux-rockchip@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP So that we don't need to busy checking the busy state, but relinguish the CPU and rely on the hareware interrupt if available. Signed-off-by: Shawn Lin --- drivers/mmc/host/dw_mmc.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/mmc/host/dw_mmc.h | 6 ++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 703dedf..b8f0ed9 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -107,6 +107,8 @@ struct idmac_desc { /* Each descriptor can transfer up to 4KB of data in chained mode */ #define DW_MCI_DESC_DATA_LENGTH 0x1000 +DECLARE_WAIT_QUEUE_HEAD(unbusy_waiter); + #if defined(CONFIG_DEBUG_FS) static int dw_mci_req_show(struct seq_file *s, void *v) { @@ -231,9 +233,36 @@ static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset) return true; } +static inline int dw_mci_wait_hw_unbusy(struct dw_mci *host, + unsigned long timeout) +{ + unsigned long irqflags; + int err; + + set_bit(EVENT_UNBUSY_COMPLETE, &host->pending_events); + err = host->drv_data->prepare_hw_unbusy(host, true); + if (err) + return err; + + wait_event_interruptible_timeout(unbusy_waiter, + !test_bit(EVENT_UNBUSY_COMPLETE, + &host->pending_events), + timeout); + + spin_lock_irqsave(&host->irq_lock, irqflags); + if (test_and_clear_bit(EVENT_UNBUSY_COMPLETE, + &host->pending_events)) { + dev_err(host->dev, "Busy; trying anyway\n"); + host->drv_data->prepare_hw_unbusy(host, false); + } + spin_unlock_irqrestore(&host->irq_lock, irqflags); + return 0; +} + static void dw_mci_wait_while_busy(struct dw_mci *host, u32 cmd_flags) { u32 status; + int err; /* * Databook says that before issuing a new data transfer command @@ -245,6 +274,15 @@ static void dw_mci_wait_while_busy(struct dw_mci *host, u32 cmd_flags) */ if ((cmd_flags & SDMMC_CMD_PRV_DAT_WAIT) && !(cmd_flags & SDMMC_CMD_VOLT_SWITCH)) { + /* Resort to hw unbusy interrupt first */ + if (host->drv_data->prepare_hw_unbusy) { + err = dw_mci_wait_hw_unbusy(host, + jiffies + msecs_to_jiffies(500)); + if (!err) + return; + /* Otherwise we fallback to busy checking */ + } + if (readl_poll_timeout_atomic(host->regs + SDMMC_STATUS, status, !(status & SDMMC_STATUS_BUSY), @@ -2734,6 +2772,16 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id) dw_mci_handle_cd(host); } + /* Check hardware unbusy interrupt */ + if (host->hw_unbusy_int != -EINVAL && + pending & BIT(host->hw_unbusy_int)) { + mci_writel(host, RINTSTS, BIT(host->hw_unbusy_int)); + spin_lock_irqsave(&host->irq_lock, irqflags); + clear_bit(EVENT_UNBUSY_COMPLETE, &host->pending_events); + spin_unlock_irqrestore(&host->irq_lock, irqflags); + wake_up_interruptible(&unbusy_waiter); + } + if (pending & SDMMC_INT_SDIO(slot->sdio_id)) { mci_writel(host, RINTSTS, SDMMC_INT_SDIO(slot->sdio_id)); @@ -3249,6 +3297,8 @@ int dw_mci_probe(struct dw_mci *host) reset_control_deassert(host->pdata->rstc); } + host->hw_unbusy_int = -EINVAL; + if (drv_data && drv_data->init) { ret = drv_data->init(host); if (ret) { @@ -3360,6 +3410,11 @@ int dw_mci_probe(struct dw_mci *host) mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER | SDMMC_INT_TXDR | SDMMC_INT_RXDR | DW_MCI_ERROR_FLAGS); + + if (host->hw_unbusy_int != -EINVAL) + mci_writel(host, INTMASK, + mci_readl(host, INTMASK) | BIT(host->hw_unbusy_int)); + /* Enable mci interrupt */ mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h index 46e9f8e..fb4c173 100644 --- a/drivers/mmc/host/dw_mmc.h +++ b/drivers/mmc/host/dw_mmc.h @@ -33,6 +33,7 @@ enum dw_mci_state { enum { EVENT_CMD_COMPLETE = 0, + EVENT_UNBUSY_COMPLETE, EVENT_XFER_COMPLETE, EVENT_DATA_COMPLETE, EVENT_DATA_ERROR, @@ -124,6 +125,7 @@ struct dw_mci_dma_slave { * @irq_flags: The flags to be passed to request_irq. * @irq: The irq value to be passed to request_irq. * @sdio_id0: Number of slot0 in the SDIO interrupt registers. + * @hw_unbusy_int: Number of unbusy interrupt in the interrupt registers. * @cmd11_timer: Timer for SD3.0 voltage switch over scheme. * @cto_timer: Timer for broken command transfer over scheme. * @dto_timer: Timer for broken data transfer over scheme. @@ -230,6 +232,7 @@ struct dw_mci { int irq; int sdio_id0; + int hw_unbusy_int; struct timer_list cmd11_timer; struct timer_list cto_timer; @@ -551,6 +554,8 @@ struct dw_mci_slot { * @set_ios: handle bus specific extensions. * @parse_dt: parse implementation specific device tree properties. * @execute_tuning: implementation specific tuning procedure. + * @prepare_hw_unbusy: implementation specific procedure for + * controlling hw unbusy interrupt. * * Provide controller implementation specific extensions. The usage of this * data structure is fully optional and usage of each member in this structure @@ -565,6 +570,7 @@ struct dw_mci_drv_data { int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode); int (*prepare_hs400_tuning)(struct dw_mci *host, struct mmc_ios *ios); + int (*prepare_hw_unbusy)(struct dw_mci *host, bool enable); int (*switch_voltage)(struct mmc_host *mmc, struct mmc_ios *ios); }; From patchwork Wed Feb 27 03:36:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Lin X-Patchwork-Id: 10831019 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 66757922 for ; Wed, 27 Feb 2019 03:38:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F9B22ABDF for ; Wed, 27 Feb 2019 03:38:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43BF02D861; Wed, 27 Feb 2019 03:38:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_WEB autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D89132ABDF for ; Wed, 27 Feb 2019 03:38:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=pD1nLNvg5R66koxxTyziNdIafPArPYw2Pc8htCeVjVQ=; b=VI/fQtz5+wF8lBp5T/jQb8JtyU XR5gKYq2wQ/+qXP983jaEi4KriwWm24nAtspPHJKBJDg8QyvwPiB5R5vfbKOaciZ6lAfBwuJdjGlS Nfi1WXc3j9PMoN49uknitawz7iQd0etdx0+zlX9qMic+Nnr/VGdxmNH81SP93dI9Fol0wJSPRfwGt bGpY+BCbRdKLvPMrAOt/wLMQ18KZpARylq1SFfeYKoNvYxWzVB7aC6QCoUzjIN9lW4LSPnb4uNTD4 Cc6U6MhdUrFp8eCMUo8zaOOGeL9Osc/gBui5ElRwWEyNu0n0oxQ1J7h7C/uqoSR0x4gUYplOXJLnL pP4cTwig==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gyq36-0001fS-Jb; Wed, 27 Feb 2019 03:38:24 +0000 Received: from lucky1.263xmail.com ([211.157.147.135]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gyq32-0001b3-98 for linux-rockchip@lists.infradead.org; Wed, 27 Feb 2019 03:38:22 +0000 Received: from shawn.lin?rock-chips.com (unknown [192.168.167.110]) by lucky1.263xmail.com (Postfix) with ESMTP id 882AB3340; Wed, 27 Feb 2019 11:38:15 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P24029T140137178584832S1551238684445785_; Wed, 27 Feb 2019 11:38:15 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <95cc6d6d804c82dce6071110337a9cf0> X-RL-SENDER: shawn.lin@rock-chips.com X-SENDER: lintao@rock-chips.com X-LOGIN-NAME: shawn.lin@rock-chips.com X-FST-TO: jh80.chung@samsung.com X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 From: Shawn Lin To: Jaehoon Chung , Ulf Hansson Subject: [PATCH 3/3] mmc: dw_mmc-rockchip: Enable hardware unbusy interrupt support Date: Wed, 27 Feb 2019 11:36:43 +0800 Message-Id: <1551238603-82412-4-git-send-email-shawn.lin@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1551238603-82412-1-git-send-email-shawn.lin@rock-chips.com> References: <1551238603-82412-1-git-send-email-shawn.lin@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190226_193820_844528_EEF8F45F X-CRM114-Status: GOOD ( 17.58 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , Shawn Lin , Ziyuan Xu , linux-mmc@vger.kernel.org, Douglas Anderson , linux-rockchip@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The new register for controlling hardware unbusy interrupt is in 0x120. It looks like: |------------------------------------------------------------| |Bit | Attribute | Reset Value | Description | |------------------------------------------------------------| |31:25 | RO | 0x0 | reserved | |------------------------------------------------------------| |24 | RO | 0x0 | rdyint_cnt_finish | | | | |When high, it indicates| | | | |that the rdyint counter| | | | |is finished. | |------------------------------------------------------------| |23:16 | RO | 0x0 | rdyint_cnt_status | | | | |Couner status, reflect | | | | |internal counter value.| |------------------------------------------------------------| |15:9 | RO | 0x0 | reserved | |------------------------------------------------------------| |8 | RW | 0x0 | rdyint_gen_working | | | | |When set, IP starts to | | | | |count and generate one | | | | |rdyint trigger. After | | | | |the rdyint trigger is | | | | |generated, it will be | | | | |cleaned automatically. | | | | |Software should set it | | | | |again next time. | |------------------------------------------------------------| |7:0 | RW | 0xff | rdyint_gen_maxval | | | | |Max counter value for | | | | |the IP to count when | | | | |rdyint_gen_working is | | | | |set. This counter is | | | | |based on biu_clk. | |------------------------------------------------------------| Signed-off-by: Shawn Lin --- drivers/mmc/host/dw_mmc-rockchip.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/mmc/host/dw_mmc-rockchip.c b/drivers/mmc/host/dw_mmc-rockchip.c index 8c86a80..85b1e42 100644 --- a/drivers/mmc/host/dw_mmc-rockchip.c +++ b/drivers/mmc/host/dw_mmc-rockchip.c @@ -20,6 +20,9 @@ #include "dw_mmc-pltfm.h" #define RK3288_CLKGEN_DIV 2 +#define RKMMC_RDYINT_GEN 0x120 +#define RKMMC_RDYINT_GEN_WORKING BIT(8) +#define RKMMC_RDYINT_GEN_MAXVAL GENMASK(7, 0) struct dw_mci_rockchip_priv_data { struct clk *drv_clk; @@ -28,6 +31,23 @@ struct dw_mci_rockchip_priv_data { int num_phases; }; +static int dw_mci_rockchip_prepare_hw_unbusy(struct dw_mci *host, + bool enable) +{ + u32 reg = readl(host->regs + RKMMC_RDYINT_GEN); + + if (enable) + /* Self-clean when generating unbusy int */ + reg |= RKMMC_RDYINT_GEN_WORKING; + else + /* Otherwise do it manually to avoid racing condition */ + reg &= ~RKMMC_RDYINT_GEN_WORKING; + + writel(reg, host->regs + RKMMC_RDYINT_GEN); + + return 0; +} + static void dw_mci_rk3288_set_ios(struct dw_mci *host, struct mmc_ios *ios) { struct dw_mci_rockchip_priv_data *priv = host->priv; @@ -301,6 +321,15 @@ static int dw_mci_rockchip_init(struct dw_mci *host) "rockchip,rk3288-dw-mshc")) host->bus_hz /= RK3288_CLKGEN_DIV; + /* Some Rockchip SoCs use hw unbusy int */ + if (of_device_is_compatible(host->dev->of_node, + "rockchip,rk1808-dw-mshc")) { + host->hw_unbusy_int = 16; + writel(~(RKMMC_RDYINT_GEN_WORKING | + RKMMC_RDYINT_GEN_MAXVAL), + host->regs + RKMMC_RDYINT_GEN); + } + return 0; } @@ -322,6 +351,7 @@ static int dw_mci_rockchip_init(struct dw_mci *host) .set_ios = dw_mci_rk3288_set_ios, .execute_tuning = dw_mci_rk3288_execute_tuning, .parse_dt = dw_mci_rk3288_parse_dt, + .prepare_hw_unbusy = dw_mci_rockchip_prepare_hw_unbusy, .init = dw_mci_rockchip_init, };