From patchwork Wed Apr 19 21:17:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 97680 Delivered-To: patches@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp447932obc; Wed, 19 Apr 2017 14:17:20 -0700 (PDT) X-Received: by 10.129.173.23 with SMTP id l23mr4473504ywh.28.1492636640839; Wed, 19 Apr 2017 14:17:20 -0700 (PDT) Return-Path: Received: from mail-wr0-x229.google.com (mail-wr0-x229.google.com. [2a00:1450:400c:c0c::229]) by mx.google.com with ESMTPS id 140si2343509wmf.2.2017.04.19.14.17.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Apr 2017 14:17:20 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:400c:c0c::229 as permitted sender) client-ip=2a00:1450:400c:c0c::229; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:400c:c0c::229 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-wr0-x229.google.com with SMTP id w50so368505wrc.0 for ; Wed, 19 Apr 2017 14:17:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IXSnM+4er9wPlSZ/9ETuGeD2BvJcmvaPhzrMcdIumSE=; b=QN2wRk4pXGyii8Nrjl24z2Y5hMlcnJXPBKEGIrlcTLOTEhsMrjHr3QKwO/rWKUKqGO hYyu/CcI3VaSVpX3Dt7rPeyM/4TLrhx3b3LAKnt+sa3crKAnu3Ip644IcLqewjtas+gr b5HE2PvjWcAbqCJkdWKGnR4vlZsKGUCGjguPw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IXSnM+4er9wPlSZ/9ETuGeD2BvJcmvaPhzrMcdIumSE=; b=AokaBmgz+YM3MI7jnW6HpOdW8CuNZcmtZnkBagpNQeFCoQh/1Of9o4n9kVs033dmzf eEXkeEdyYBnLD+/DI78sxcS/oyvqXVENUmTMA5MGzlolXhHC5FlNIjpww2/757b4CE/i ETo2L226S7hcVDh29lLslan8bBpWpHIAMsPBzGAEzQNy5TDx1obIcF0HMQIkd/Z8FOZ8 XzMQVTqyEg1ZQtXKkO4xnb4oc0cN3p4iXRSgW/rs4m0I1rqHBn5vmnEqI1nmxcfyovPp eVM8SmdXq80SXicbujOR20wYOvNYwiRAAzg30ElXnXPAFVRjG8+hZeKsiODq4Z4MNDP8 RtVA== X-Gm-Message-State: AN3rC/777PXdZqPOuB0LDgblNJAlPGSRwEE+aSJod6n/nKZtdl3I04wo zI6vrjpa/YuwWDqQKxDZH4os X-Received: by 10.223.149.33 with SMTP id 30mr2015193wrs.20.1492636640475; Wed, 19 Apr 2017 14:17:20 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-221-67.na.cust.bahnhof.se. [155.4.221.67]) by smtp.gmail.com with ESMTPSA id g53sm4837747wrg.22.2017.04.19.14.17.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Apr 2017 14:17:19 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Jaehoon Chung , Adrian Hunter , Brian Norris , Shawn Lin , Doug Anderson Subject: [PATCH v2 1/5] mmc: core: Prevent processing SDIO IRQs when none is claimed Date: Wed, 19 Apr 2017 23:17:07 +0200 Message-Id: <1492636631-28254-2-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492636631-28254-1-git-send-email-ulf.hansson@linaro.org> References: <1492636631-28254-1-git-send-email-ulf.hansson@linaro.org> In cases when MMC_CAP2_SDIO_IRQ_NOTHREAD is set, there is a minor window for when the mmc host could call sdio_run_irqs(), while in fact an SDIO func driver could have decided to released the SDIO IRQ via a call to sdio_release_irq(). In this scenario, processing of the SDIO IRQs are done even if there is none IRQ claimed, which is not what we want. To prevent this from happen, close the window by validating that at least one SDIO IRQs is claimed, before deciding to process them. Signed-off-by: Ulf Hansson --- drivers/mmc/core/sdio_irq.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/mmc/core/sdio_irq.c b/drivers/mmc/core/sdio_irq.c index 6d4b720..44d9c86 100644 --- a/drivers/mmc/core/sdio_irq.c +++ b/drivers/mmc/core/sdio_irq.c @@ -95,8 +95,10 @@ static int process_sdio_pending_irqs(struct mmc_host *host) void sdio_run_irqs(struct mmc_host *host) { mmc_claim_host(host); - host->sdio_irq_pending = true; - process_sdio_pending_irqs(host); + if (host->sdio_irqs) { + host->sdio_irq_pending = true; + process_sdio_pending_irqs(host); + } mmc_release_host(host); } EXPORT_SYMBOL_GPL(sdio_run_irqs); From patchwork Wed Apr 19 21:17:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 97681 Delivered-To: patches@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp447943obc; Wed, 19 Apr 2017 14:17:22 -0700 (PDT) X-Received: by 10.223.163.212 with SMTP id m20mr4451261wrb.29.1492636642180; Wed, 19 Apr 2017 14:17:22 -0700 (PDT) Return-Path: Received: from mail-wm0-x236.google.com (mail-wm0-x236.google.com. [2a00:1450:400c:c09::236]) by mx.google.com with ESMTPS id k64si22760427wmb.93.2017.04.19.14.17.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Apr 2017 14:17:22 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:400c:c09::236 as permitted sender) client-ip=2a00:1450:400c:c09::236; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:400c:c09::236 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-wm0-x236.google.com with SMTP id o81so89660040wmb.1 for ; Wed, 19 Apr 2017 14:17:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=L9VMm4QILzZzp06NVBxVibZjxFgFWCacB3wMl8w2CzA=; b=KSEhtJEUOeXsNsgBg+82dX1brTxADb0INVtNgL4haJRzo5J+VMMt88+yBc3/qtNliu IdQfVozq5RYYwwsTmmGuiP1az+tZCs4re6b6SkQrjwMo1pZKlCwj4P/qRbe9C7SeM5oT wGiSoQKd1JO8ZY04zmRU9qnUIfF+vtkIDnBZU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=L9VMm4QILzZzp06NVBxVibZjxFgFWCacB3wMl8w2CzA=; b=o+j6zENJmdsHMSd3iQrJZomEMix5fqqbGSg48hl6ekthWVuPmN41Hxu/3vm2QGrwK/ /mIfG8DmReX0J1FoqgCdVcm2X940EVPyFHygyjTS2wL+67J+DUV86HE1y2DFgnikHhL9 m/M0sH6pJTMCa9LbvgTCC9yuQqZ+L18ztbXqOLjjirvOPbseqYkhAci3CZZKNjGkZCvu vdFBMtdFGYsMpp0nT3O7feSE1tMfi3grKxafyfMXLBloTfpTCg7F4sS+zMGo5Q6skT6v vQDfEz9b+XOcZCBNNIHbej3rKOaYQ3tdpEBNIdKqbuU6cufDVREWEjHn84QaZeYUBvFc +8gA== X-Gm-Message-State: AN3rC/6VNN3frkl9ErHZe/rCqd1rCD4+yja2BJZPg99stHyOUcMp5EIi TljicmMPi+S/OUmNThM= X-Received: by 10.28.24.71 with SMTP id 68mr34721wmy.64.1492636641751; Wed, 19 Apr 2017 14:17:21 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-221-67.na.cust.bahnhof.se. [155.4.221.67]) by smtp.gmail.com with ESMTPSA id g53sm4837747wrg.22.2017.04.19.14.17.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Apr 2017 14:17:21 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Jaehoon Chung , Adrian Hunter , Brian Norris , Shawn Lin , Doug Anderson Subject: [PATCH v2 2/5] mmc: sdio: Add API to manage SDIO IRQs from a workqueue Date: Wed, 19 Apr 2017 23:17:08 +0200 Message-Id: <1492636631-28254-3-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492636631-28254-1-git-send-email-ulf.hansson@linaro.org> References: <1492636631-28254-1-git-send-email-ulf.hansson@linaro.org> For hosts not supporting MMC_CAP2_SDIO_IRQ_NOTHREAD but MMC_CAP_SDIO_IRQ, the SDIO IRQs are processed from a dedicated kernel thread. For these cases, the host calls mmc_signal_sdio_irq() from its ISR to signal a new SDIO IRQ. Signaling an SDIO IRQ makes the host's ->enable_sdio_irq() callback to be invoked to temporary disable the IRQs, before the kernel thread is woken up to process it. When processing of the IRQs are completed, they are re-enabled by the kernel thread, again via invoking the host's ->enable_sdio_irq(). The observation from this, is that the execution path is being unnecessary complex, as the host driver already knows that it needs to temporary disable the IRQs before signaling a new one. Moreover, replacing the kernel thread with a work/workqueue would greatly simplify the code. To address the above problems, let's continue to build upon the support for MMC_CAP2_SDIO_IRQ_NOTHREAD, as it already implements SDIO IRQs to be processed without using the clumsy kernel thread, but it also avoids the ping-ponging calls of the host's ->enable_sdio_irq() callback for each processed IRQ. Therefore, let's add new API sdio_signal_irq(), which enables hosts to signal/process SDIO IRQs by using a work/workqueue, rather than using the kernel thread. Add also a new host callback ->ack_sdio_irq(), which the work invokes when the SDIO IRQs are processed. This informs the host about when it can re-enable the SDIO IRQs. Potentially, we could re-use the existing ->enable_sdio_irq() callback for this matter, however it has turned out that it's more convenient for hosts to get this information via a separate callback. Hosts needs to enable MMC_CAP2_SDIO_IRQ_NOTHREAD to use the work/workqueue to process SDIO IRQs, however implementing the ->ack_sdio_irq() is optional. Signed-off-by: Ulf Hansson --- drivers/mmc/core/host.c | 2 ++ drivers/mmc/core/sdio_irq.c | 21 +++++++++++++++++++++ drivers/mmc/core/sdio_ops.h | 2 ++ include/linux/mmc/host.h | 3 +++ 4 files changed, 28 insertions(+) -- 2.7.4 diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index 3f8c85d..77058cb 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -30,6 +30,7 @@ #include "host.h" #include "slot-gpio.h" #include "pwrseq.h" +#include "sdio_ops.h" #define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev) @@ -379,6 +380,7 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) spin_lock_init(&host->lock); init_waitqueue_head(&host->wq); INIT_DELAYED_WORK(&host->detect, mmc_rescan); + INIT_WORK(&host->sdio_irq_work, sdio_irq_work); setup_timer(&host->retune_timer, mmc_retune_timer, (unsigned long)host); /* diff --git a/drivers/mmc/core/sdio_irq.c b/drivers/mmc/core/sdio_irq.c index 44d9c86..8e28759 100644 --- a/drivers/mmc/core/sdio_irq.c +++ b/drivers/mmc/core/sdio_irq.c @@ -98,11 +98,32 @@ void sdio_run_irqs(struct mmc_host *host) if (host->sdio_irqs) { host->sdio_irq_pending = true; process_sdio_pending_irqs(host); + if (host->ops->ack_sdio_irq) + host->ops->ack_sdio_irq(host); } mmc_release_host(host); } EXPORT_SYMBOL_GPL(sdio_run_irqs); +void sdio_irq_work(struct work_struct *work) +{ + struct mmc_host *host = + container_of(work, struct mmc_host, sdio_irq_work); + + sdio_run_irqs(host); +} + +void sdio_signal_irq(struct mmc_host *host) +{ + /* + * The system_freezable_wq helps us to avoid processing IRQs while being + * system PM suspended. Instead these IRQs becomes deferred and managed + * when userspace is unfrozen. + */ + queue_work(system_freezable_wq, &host->sdio_irq_work); +} +EXPORT_SYMBOL_GPL(sdio_signal_irq); + static int sdio_irq_thread(void *_host) { struct mmc_host *host = _host; diff --git a/drivers/mmc/core/sdio_ops.h b/drivers/mmc/core/sdio_ops.h index bed8a83..836e405 100644 --- a/drivers/mmc/core/sdio_ops.h +++ b/drivers/mmc/core/sdio_ops.h @@ -17,6 +17,7 @@ struct mmc_host; struct mmc_card; +struct work_struct; int mmc_send_io_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr); int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn, @@ -25,6 +26,7 @@ int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn, unsigned addr, int incr_addr, u8 *buf, unsigned blocks, unsigned blksz); int sdio_reset(struct mmc_host *host); unsigned int mmc_align_data_size(struct mmc_card *card, unsigned int sz); +void sdio_irq_work(struct work_struct *work); static inline bool mmc_is_io_op(u32 opcode) { diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 21385ac..f03df539 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -130,6 +130,7 @@ struct mmc_host_ops { int (*get_cd)(struct mmc_host *host); void (*enable_sdio_irq)(struct mmc_host *host, int enable); + void (*ack_sdio_irq)(struct mmc_host *host); /* optional callback for HC quirks */ void (*init_card)(struct mmc_host *host, struct mmc_card *card); @@ -358,6 +359,7 @@ struct mmc_host { unsigned int sdio_irqs; struct task_struct *sdio_irq_thread; + struct work_struct sdio_irq_work; bool sdio_irq_pending; atomic_t sdio_irq_thread_abort; @@ -428,6 +430,7 @@ static inline void mmc_signal_sdio_irq(struct mmc_host *host) } void sdio_run_irqs(struct mmc_host *host); +void sdio_signal_irq(struct mmc_host *host); #ifdef CONFIG_REGULATOR int mmc_regulator_get_ocrmask(struct regulator *supply); From patchwork Wed Apr 19 21:17:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 97682 Delivered-To: patches@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp447951obc; Wed, 19 Apr 2017 14:17:23 -0700 (PDT) X-Received: by 10.223.178.225 with SMTP id g88mr4385210wrd.126.1492636643459; Wed, 19 Apr 2017 14:17:23 -0700 (PDT) Return-Path: Received: from mail-wm0-x22d.google.com (mail-wm0-x22d.google.com. [2a00:1450:400c:c09::22d]) by mx.google.com with ESMTPS id 33si5572849wrp.148.2017.04.19.14.17.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Apr 2017 14:17:23 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:400c:c09::22d as permitted sender) client-ip=2a00:1450:400c:c09::22d; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:400c:c09::22d as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-wm0-x22d.google.com with SMTP id m123so22019500wma.0 for ; Wed, 19 Apr 2017 14:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gySLns3vLVf/aJbNIac7vXTxSoqPQkXp2l2GYkzRHqM=; b=ITjd0rNTTgDhzHAQ8I9YKD3wUgvsUh1UDtLbqsVcV047ilXh0070X+XPDUAnPgauc+ wv2qsgHM5ReQIV62EY+8qTlWndqRIr7eIKjbo/IcOfg+foibDKAD7aAw58+HYj4eS/v8 EM9HBY+Q69/MnJQBSjGzOeBsVdgW8OEVaOVEE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gySLns3vLVf/aJbNIac7vXTxSoqPQkXp2l2GYkzRHqM=; b=nVxguJKar3QJwX73HLQdG1XJ2zd+xwwrkb/PEt0xRiGnj4+rat3sWSm23bC6cse1hw gPxttcIjpfKiYvR1mL3V3wO4srumeM8usMvCHrMngoqfEFkgmUNbFsG3aFC8ZnGj0TBf 8xzPlLmVg+JNHFTi9ovcgY5NC1RBUwQ3eF3X4p+TjMos/Ao4DGdRLG6oyWF7XdVIcq3E UakZYF+LJnl4D7VWpkY30949YzuCQcM7dtJRLT5cefPfGeBgUmDQxymp8UxyNwMsH6z0 zp5+1ObjB/gd034ENkRvat3rsfihFEu7YOYW1EruKHfL1/Z0phyU7ZjHuOctQGqZPMCK 5fCA== X-Gm-Message-State: AN3rC/6yY9my44jhbDXqwx26tQWSzECxZQbrjUCvTbSJPwhkysctGGmn pwgQS7HLRJaaH3Xtz0E= X-Received: by 10.28.60.6 with SMTP id j6mr20536wma.19.1492636643006; Wed, 19 Apr 2017 14:17:23 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-221-67.na.cust.bahnhof.se. [155.4.221.67]) by smtp.gmail.com with ESMTPSA id g53sm4837747wrg.22.2017.04.19.14.17.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Apr 2017 14:17:22 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Jaehoon Chung , Adrian Hunter , Brian Norris , Shawn Lin , Doug Anderson Subject: [PATCH v2 3/5] mmc: dw_mmc: Convert to use MMC_CAP2_SDIO_IRQ_NOTHREAD for SDIO IRQs Date: Wed, 19 Apr 2017 23:17:09 +0200 Message-Id: <1492636631-28254-4-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492636631-28254-1-git-send-email-ulf.hansson@linaro.org> References: <1492636631-28254-1-git-send-email-ulf.hansson@linaro.org> Convert to use the more lightweight method for processing SDIO IRQs, which involves the following changes: - Enable MMC_CAP2_SDIO_IRQ_NOTHREAD when SDIO IRQ is supported. - Mask SDIO IRQ when signaling it for processing. - Re-enable (unmask) the SDIO IRQ from the ->ack_sdio_irq() callback. Signed-off-by: Ulf Hansson --- drivers/mmc/host/dw_mmc.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index e45129f..635d76c 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -1642,9 +1642,8 @@ static void dw_mci_init_card(struct mmc_host *mmc, struct mmc_card *card) } } -static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb) +static void __dw_mci_enable_sdio_irq(struct dw_mci_slot *slot, int enb) { - struct dw_mci_slot *slot = mmc_priv(mmc); struct dw_mci *host = slot->host; unsigned long irqflags; u32 int_mask; @@ -1662,6 +1661,20 @@ static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb) spin_unlock_irqrestore(&host->irq_lock, irqflags); } +static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb) +{ + struct dw_mci_slot *slot = mmc_priv(mmc); + + __dw_mci_enable_sdio_irq(slot, enb); +} + +static void dw_mci_ack_sdio_irq(struct mmc_host *mmc) +{ + struct dw_mci_slot *slot = mmc_priv(mmc); + + __dw_mci_enable_sdio_irq(slot, 1); +} + static int dw_mci_execute_tuning(struct mmc_host *mmc, u32 opcode) { struct dw_mci_slot *slot = mmc_priv(mmc); @@ -1763,6 +1776,7 @@ static const struct mmc_host_ops dw_mci_ops = { .get_cd = dw_mci_get_cd, .hw_reset = dw_mci_hw_reset, .enable_sdio_irq = dw_mci_enable_sdio_irq, + .ack_sdio_irq = dw_mci_ack_sdio_irq, .execute_tuning = dw_mci_execute_tuning, .card_busy = dw_mci_card_busy, .start_signal_voltage_switch = dw_mci_switch_voltage, @@ -2654,7 +2668,8 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id) if (pending & SDMMC_INT_SDIO(slot->sdio_id)) { mci_writel(host, RINTSTS, SDMMC_INT_SDIO(slot->sdio_id)); - mmc_signal_sdio_irq(slot->mmc); + __dw_mci_enable_sdio_irq(slot, 0); + sdio_signal_irq(slot->mmc); } } @@ -2755,6 +2770,10 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id) if (ret) goto err_host_allocated; + /* Process SDIO IRQs through the sdio_irq_work. */ + if (mmc->caps & MMC_CAP_SDIO_IRQ) + mmc->caps2 |= MMC_CAP2_SDIO_IRQ_NOTHREAD; + /* Useful defaults if platform data is unset. */ if (host->use_dma == TRANS_MODE_IDMAC) { mmc->max_segs = host->ring_size; From patchwork Wed Apr 19 21:17:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 97683 Delivered-To: patches@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp447957obc; Wed, 19 Apr 2017 14:17:24 -0700 (PDT) X-Received: by 10.28.7.137 with SMTP id 131mr13797wmh.49.1492636644411; Wed, 19 Apr 2017 14:17:24 -0700 (PDT) Return-Path: Received: from mail-wm0-x229.google.com (mail-wm0-x229.google.com. [2a00:1450:400c:c09::229]) by mx.google.com with ESMTPS id p2si22792026wmb.77.2017.04.19.14.17.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Apr 2017 14:17:24 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:400c:c09::229 as permitted sender) client-ip=2a00:1450:400c:c09::229; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:400c:c09::229 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-wm0-x229.google.com with SMTP id o81so89660605wmb.1 for ; Wed, 19 Apr 2017 14:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=W0zODX+ZOkx8Ics0RZBXIB1u0sTg4+bKtV9E32eORY4=; b=U4yQzVljLB2usL9om4g73/bowuV0aHNib4+jAg4ObF1aAKuF7S5kWvp2ZsvsXzl7SB XDx5WXiwMUdEkis0AWs69+V7cWnJcfMgm46NNjopii7gKwdTb8bUQ94XbrF6bJHEId++ yqZjoo262WJHti9dYGXeLscOWjCVRcai9fG9c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=W0zODX+ZOkx8Ics0RZBXIB1u0sTg4+bKtV9E32eORY4=; b=Y+/3darhNYfP3B2K7Gtz/wOmyqVW9MAWCZ3qZLPcAFG1miwUeQKSkeiq/g6Gr51ZgV E/jaztx1l9cgETlcwHlOJC8BBi4DJa6zUwWvjP1sLJgbJpDoYmkmElmDhebYLe55cHcO RMZMsZDg4IsWbk5Am7i7kGYQcRDyTxe0IfvzCN4JKjc/pGulq1vllX316ZRv0WXrJlSu 7hwFEcOdTNsR20FE/ggYPIn3iT2t6v2AUxWwlEYmzuQ0XamEmq+kUklGX9nZfO3wYUlb U2LU1mtD/l6MIwfj5MsRBAsu78s3q2Ak1kktrp8G/o95Msom6CNOdKQx1SLoI3UQPCDt ED1Q== X-Gm-Message-State: AN3rC/58c+peoYlGCpl3wFw1HxhDXqgzoD9J6eh7sSGxr/mMovZDshMu 4Rs2mR1rnO1Tmyne2+8= X-Received: by 10.28.91.82 with SMTP id p79mr24440wmb.130.1492636643999; Wed, 19 Apr 2017 14:17:23 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-221-67.na.cust.bahnhof.se. [155.4.221.67]) by smtp.gmail.com with ESMTPSA id g53sm4837747wrg.22.2017.04.19.14.17.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Apr 2017 14:17:23 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Jaehoon Chung , Adrian Hunter , Brian Norris , Shawn Lin , Doug Anderson Subject: [PATCH v2 4/5] mmc: dw_mmc: Prevent runtime PM suspend when SDIO IRQs are enabled Date: Wed, 19 Apr 2017 23:17:10 +0200 Message-Id: <1492636631-28254-5-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492636631-28254-1-git-send-email-ulf.hansson@linaro.org> References: <1492636631-28254-1-git-send-email-ulf.hansson@linaro.org> To be able to handle SDIO IRQs the dw_mmc device needs to be powered and providing clock to the SDIO card. Therefore, we must not allow the device to be runtime PM suspended while SDIO IRQs are enabled. To fix this, let's increase the runtime PM usage count while the mmc core enables SDIO IRQs. Later when the mmc core tells dw_mmc to disable SDIO IRQs, we drop the usage count to again allow runtime PM suspend. This now becomes the default behaviour for dw_mmc. In cases where SDIO IRQs can be re-routed as GPIO wake-ups during runtime PM suspend, one could potentially allow runtime PM suspend. However, that will have to be addressed as a separate change on top of this one. Signed-off-by: Ulf Hansson --- drivers/mmc/host/dw_mmc.c | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.7.4 diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 635d76c..c14a36b 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -39,6 +39,7 @@ #include #include #include +#include #include "dw_mmc.h" @@ -1664,8 +1665,15 @@ static void __dw_mci_enable_sdio_irq(struct dw_mci_slot *slot, int enb) static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb) { struct dw_mci_slot *slot = mmc_priv(mmc); + struct dw_mci *host = slot->host; __dw_mci_enable_sdio_irq(slot, enb); + + /* Avoid runtime suspending the device when SDIO IRQ is enabled */ + if (enb) + pm_runtime_get_noresume(host->dev); + else + pm_runtime_put_noidle(host->dev); } static void dw_mci_ack_sdio_irq(struct mmc_host *mmc) From patchwork Wed Apr 19 21:17:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 97684 Delivered-To: patches@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp447964obc; Wed, 19 Apr 2017 14:17:25 -0700 (PDT) X-Received: by 10.28.191.145 with SMTP id o17mr50133wmi.20.1492636645434; Wed, 19 Apr 2017 14:17:25 -0700 (PDT) Return-Path: Received: from mail-wm0-x22b.google.com (mail-wm0-x22b.google.com. [2a00:1450:400c:c09::22b]) by mx.google.com with ESMTPS id t75si5587964wrc.41.2017.04.19.14.17.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Apr 2017 14:17:25 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:400c:c09::22b as permitted sender) client-ip=2a00:1450:400c:c09::22b; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:400c:c09::22b as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-wm0-x22b.google.com with SMTP id w64so89942955wma.0 for ; Wed, 19 Apr 2017 14:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6hxCabfxbCBaswrq5NyVtg+BI2F0J0gVrrYL7w1LQeQ=; b=fwZ54P6DyqDi0xE0BwwAGjO74k5JwUIdjBGfNls1QICqzrWBrNj+WVqWxlcB1UURKx O3xgAxDXc3WeSCYY/+ftFbLz254H2L9svxpGaigmRta0/lfEfSJrfkFte19yzoW3IHb0 xDINBiy9MSD0Qf56hCfy789/7D8vLkth84KDY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6hxCabfxbCBaswrq5NyVtg+BI2F0J0gVrrYL7w1LQeQ=; b=Hd9L/70b96Ykey/MROoSQeAi2j1dVUhUS0MT1edKb7vEkWrC4BPf3T5+bjoeUfrIYa quKKGb6CDukMexNzYzODiGDur/ewmT6d1Uxkqd1tbMK2Aed81kDMMkmw/W8fp6fdh9lN m4Rw99kHR0fjpjaRLZs6oBbrXo9FNzL8OkiDCBH3M/f19vzLtCQxB7KvtKDwNPvTh3fB sK9hu3NUMJmK7NdLiGwb0MbXF4Yc5cx6TcsmWfUY+bJDhMIRh0s+3/EESdn/bf9H+JMk 6bHZ7P9NsR1KZxStukmz3yxTGYl5fIDeTIzW45AbwtS/AWtX1awiL7N60Th1/NaJZ9Jx UNWQ== X-Gm-Message-State: AN3rC/4M7b7CvwtPVuVaSvqWWzoLam6TqkQr4K7ivvT84Wx1cGWF2x+4 k88hYN0Re+HZhoNxSqs= X-Received: by 10.28.69.68 with SMTP id s65mr22683wma.13.1492636645073; Wed, 19 Apr 2017 14:17:25 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-221-67.na.cust.bahnhof.se. [155.4.221.67]) by smtp.gmail.com with ESMTPSA id g53sm4837747wrg.22.2017.04.19.14.17.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Apr 2017 14:17:24 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Jaehoon Chung , Adrian Hunter , Brian Norris , Shawn Lin , Doug Anderson Subject: [PATCH v2 5/5] Revert "mmc: dw_mmc: Don't allow Runtime PM for SDIO cards" Date: Wed, 19 Apr 2017 23:17:11 +0200 Message-Id: <1492636631-28254-6-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492636631-28254-1-git-send-email-ulf.hansson@linaro.org> References: <1492636631-28254-1-git-send-email-ulf.hansson@linaro.org> This reverts commit a6db2c86033bc41329770e90c20d4f1fec3824e4. As dw_mmc now is capable of preventing runtime PM suspend while SDIO IRQs are enabled, let's drop the less fine-grained approach of preventing runtime PM suspend for all SDIO cards. In this way we wont keep the host runtime PM resumed, unless really needed and thus avoiding to waste power. Signed-off-by: Ulf Hansson --- drivers/mmc/host/dw_mmc.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) -- 2.7.4 diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index c14a36b..c95dc9b 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -1622,16 +1621,10 @@ static void dw_mci_init_card(struct mmc_host *mmc, struct mmc_card *card) if (card->type == MMC_TYPE_SDIO || card->type == MMC_TYPE_SD_COMBO) { - if (!test_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags)) { - pm_runtime_get_noresume(mmc->parent); - set_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags); - } + set_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags); clk_en_a = clk_en_a_old & ~clken_low_pwr; } else { - if (test_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags)) { - pm_runtime_put_noidle(mmc->parent); - clear_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags); - } + clear_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags); clk_en_a = clk_en_a_old | clken_low_pwr; }