From patchwork Thu Sep 10 07:10:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Hiremath X-Patchwork-Id: 7151281 Return-Path: X-Original-To: patchwork-linux-arm@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 C6941BEEC1 for ; Thu, 10 Sep 2015 07:13:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E7D55208E1 for ; Thu, 10 Sep 2015 07:13:19 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 14A40208D6 for ; Thu, 10 Sep 2015 07:13:19 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZZw0u-0005sq-7a; Thu, 10 Sep 2015 07:11:20 +0000 Received: from mail-pa0-f41.google.com ([209.85.220.41]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZZw0p-0005pc-NJ for linux-arm-kernel@lists.infradead.org; Thu, 10 Sep 2015 07:11:17 +0000 Received: by pacex6 with SMTP id ex6so34873307pac.0 for ; Thu, 10 Sep 2015 00:10:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-type:content-transfer-encoding; bh=kDunAu6VX4RwAyGmNjtX/GoE3/eXB7NmPDb+DSUF30E=; b=jI+55ztVGXBT8yhe75AKo37D9PPLGG/V8jSwHOPBp8ev02J09fG8HnfocgRE4cs9uB QO/II7WFGivHV0lUbViNrx/xSmdSsucfW+avMkxfOcPijFeNm9ynrKJIOxvMeBEg8+BZ 0PKFUvbXdyXN8PfwKFszaB4LeFcym6/NqwHlFsmqrqiAoNZTDY1cfBDDWMlHLzB7zW+v 182PyH3b51RJ6C5LWdBdUgzRTYj2F4JpZHGi7vZSVWMGwplFwMWBQqaJw9MlNbLwcFDy tuwEz8HquoH+PlecoZTGeLDVLbyp6Sd5Hhbvy09oY+Ao9R/EO7j0bEgzO5Syl795W9eN fQDQ== X-Gm-Message-State: ALoCoQnm61OZZKOYMHyNXiFeDFDbyCIaRWaAt8JGehXovbSU4CGGQXMc+bAseE9lD8OrYv07T+1V X-Received: by 10.66.163.227 with SMTP id yl3mr70679640pab.10.1441869053510; Thu, 10 Sep 2015 00:10:53 -0700 (PDT) Received: from [192.168.0.100] ([202.62.93.141]) by smtp.googlemail.com with ESMTPSA id td5sm1327327pab.1.2015.09.10.00.10.50 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2015 00:10:52 -0700 (PDT) To: "linux-mmc@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , nico@fluxnic.net, ulf.hansson@linaro.org From: Vaibhav Hiremath Subject: sdhci: runtime suspend/resume on card insert/removal Message-ID: <55F12CF8.50003@linaro.org> Date: Thu, 10 Sep 2015 12:40:48 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150910_001115_788419_E92FE5C8 X-CRM114-Status: GOOD ( 16.96 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_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 Hi, During my testing of SDHCI-PXAV3 driver on Marvell's pxa1928 based platform, I observed that runtime PM suspend/resume is having issues with card insertion and removal. Let me try to explain it using execution sequence - During boot: MMC SD card gets detected as expected. [ 2.431012] mmc1: new high speed SDHC card at address 1234 [ 2.437235] mmcblk1: mmc1:1234 SA04G 3.63 GiB [ 2.444841] mmcblk1: p1 Now after coming to the linux prompt, if card removal event occurs then the call sequence is - sdhci_irq() --> -> sdhci_thread_irq(): host->thread_isr - 0x80 -> sdhci_card_event() -> mmc_detect_change() --> _mmc_detect_change() ---> mmc_sd_detect() mmc_sd_remove() mmc_remove_card() mmc_bus_remove() mmc_power_off() mmc_set_initial_state() sdhci_set_ios() ... sdhci_pxav3_runtime_suspend() sdhci_runtime_suspend_host() Till here everything looks perfect :) (if I got it right) Now on card insertion again, the expectation is, runtime resume should get called as part of interrupt trigger from the SDHCI controller on card insertion. But what I am observing here is, no interrupt is generated, as it is not enabled at all. And the reason being sdhci_runtime_suspend_host() int sdhci_runtime_suspend_host(struct sdhci_host *host) { .... spin_lock_irqsave(&host->lock, flags); host->ier &= SDHCI_INT_CARD_INT; sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); spin_unlock_irqrestore(&host->lock, flags); ... } In my case, I see SDHCI_INT_CARD_INT is not ON and with above step we are not ensuring that it is enabled either. Also we are not enabling card insertion and removal interrupts. I have done following change to the code - synchronize_hardirq(host->irq); And things started working as expected. The execution sequence of irq and sdhci_runtime_resume both looks ok to me. Card insertion event = sdhci_irq() --> -> sdhci_thread_irq: host->thread_isr - 40 --> sdhci_card_event() --> mmc_detect_change() ---> _mmc_detect_change() ... -> sdhci_pxav3_runtime_resume() --> sdhci_do_set_ios:1438 I see card getting enumerated as expected - [ 15.116098] mmc1: mmc_rescan_try_freq: trying to init card at 400000 Hz [ 15.356473] mmc1: new high speed SDHC card at address 1234 [ 15.363962] mmcblk1: mmc1:1234 SA04G 3.63 GiB [ 15.371043] sdhci_thread_irq:2642 host->thread_isr - 100 [ 15.376492] mmcblk1: p1 I believe (based on my understanding) the change I have done is right. I am not sure how other platforms using sdhci.c working so far, probably no runtime_pm support? Not sure though Please let me know if I am missing something here. And not, and everyone is ok with this, I will submit the patch fixing this issue. Thanks, Vaibhav diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 418f381..3129292 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -2783,9 +2783,12 @@ int sdhci_runtime_suspend_host(struct sdhci_host *host) mmc_retune_needed(host->mmc); spin_lock_irqsave(&host->lock, flags); - host->ier &= SDHCI_INT_CARD_INT; + + host->flags |= SDHCI_SDIO_IRQ_ENABLED; + host->ier |= SDHCI_INT_CARD_INT; sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); + spin_unlock_irqrestore(&host->lock, flags);