From patchwork Fri Sep 20 09:48:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 2915811 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 17F4A9F1BF for ; Fri, 20 Sep 2013 09:48:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E3DA620300 for ; Fri, 20 Sep 2013 09:48:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F0398202E6 for ; Fri, 20 Sep 2013 09:48:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754282Ab3ITJsw (ORCPT ); Fri, 20 Sep 2013 05:48:52 -0400 Received: from mail-lb0-f169.google.com ([209.85.217.169]:40882 "EHLO mail-lb0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754221Ab3ITJsv (ORCPT ); Fri, 20 Sep 2013 05:48:51 -0400 Received: by mail-lb0-f169.google.com with SMTP id z5so405284lbh.28 for ; Fri, 20 Sep 2013 02:48:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BTRQWjZX1nQcB04BWfatzadzRwwpdQvBjMvr9y7jPk0=; b=d2s+ShfIx0RMe3ZSd7gJqbEbFRyiFYWe9pKLBKNEX/moYhQBtBwqwnaWIVlhOBtpr2 tmLJr3L9tEyul2ElK7PtgMXDjNm6Nk62cjGQfo6hAmsOLKeoqPG9xH6q8tc3K4FR23jC 3+7QbWekRtffMwc0u5cH0DuS81SEM5PBKmTOzEMCgYysFrfxSS9PdXqEYZplWqRvZH3w fv4f7td9f/BA4bwS2lYZyJ3bX5YzwfsFoG8GOV63FCjeB9hkiARAk082S9pv2KTX49eH Q+Xa/fPflQO2PBxXxoQwje8lXd0kdV5jyREwz6xhy8LLGajWmotshMC3RLwEjwO+NFES 3reg== X-Gm-Message-State: ALoCoQkGWlHW4giJfd+q024bVRgRPBCgEAcJTKO7tgEhT8mGET/Mbecz2PlJZfK4I9KfvTi3Awbc X-Received: by 10.152.3.201 with SMTP id e9mr5534281lae.24.1379670529926; Fri, 20 Sep 2013 02:48:49 -0700 (PDT) Received: from linaro-ulf.lan (90-231-160-185-no158.tbcn.telia.com. [90.231.160.185]) by mx.google.com with ESMTPSA id u20sm5736956lbh.7.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Sep 2013 02:48:49 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Chris Ball Cc: Ulf Hansson , San Mehat , Colin Cross , John Stultz , Zoran Markovic Subject: [RFC/PATCH] mmc: core: Signal wakeup event at card insert/removal Date: Fri, 20 Sep 2013 11:48:43 +0200 Message-Id: <1379670523-13229-1-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.7.9.5 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.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 We want to give user space provision to fully consume a card insert/remove event, when the event was caused by a wakeup irq. By signaling the wakeup event for a time of 5 s for devices configured as wakeup capable, we likely will be prevent a sleep long enough to let user space consume the event. To enable this feature, host drivers must thus configure their devices as wakeup capable. This is a reworked implementation of the old wakelocks for the mmc subsystem, originally authored by Colin Cross and San Mehat for the Android kernel. Zoran Markovic shall also be given cred for recently re-trying to upstream this feature. Cc: San Mehat Cc: Colin Cross Cc: John Stultz Cc: Zoran Markovic Signed-off-by: Ulf Hansson Reviewed-by: Zoran Markovic --- This patch has just been compile tested, since I at very moment did not have a good board to test it on. I am working on that. Any help in testing this patch is thus greatly appreciated. While testing also don't forget to enable the host device as wakeup capable. Use "device_init_wakeup" from the host probe function. --- drivers/mmc/core/core.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index bf18b6b..3e8229e 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -1723,6 +1724,28 @@ void mmc_detach_bus(struct mmc_host *host) mmc_bus_put(host); } +static void _mmc_detect_change(struct mmc_host *host, unsigned long delay, + bool cd_irq) +{ +#ifdef CONFIG_MMC_DEBUG + unsigned long flags; + spin_lock_irqsave(&host->lock, flags); + WARN_ON(host->removed); + spin_unlock_irqrestore(&host->lock, flags); +#endif + + /* + * If the device is configured as wakeup, we prevent a new sleep for + * 5 s to give provision for user space to consume the event. + */ + if (cd_irq && !(host->caps & MMC_CAP_NEEDS_POLL) && + device_can_wakeup(mmc_dev(host))) + pm_wakeup_event(mmc_dev(host), 5000); + + host->detect_change = 1; + mmc_schedule_delayed_work(&host->detect, delay); +} + /** * mmc_detect_change - process change of state on a MMC socket * @host: host which changed state. @@ -1735,16 +1758,8 @@ void mmc_detach_bus(struct mmc_host *host) */ void mmc_detect_change(struct mmc_host *host, unsigned long delay) { -#ifdef CONFIG_MMC_DEBUG - unsigned long flags; - spin_lock_irqsave(&host->lock, flags); - WARN_ON(host->removed); - spin_unlock_irqrestore(&host->lock, flags); -#endif - host->detect_change = 1; - mmc_schedule_delayed_work(&host->detect, delay); + _mmc_detect_change(host, delay, true); } - EXPORT_SYMBOL(mmc_detect_change); void mmc_init_erase(struct mmc_card *card) @@ -2423,7 +2438,7 @@ int mmc_detect_card_removed(struct mmc_host *host) * rescan handle the card removal. */ cancel_delayed_work(&host->detect); - mmc_detect_change(host, 0); + _mmc_detect_change(host, 0, false); } } @@ -2505,7 +2520,7 @@ void mmc_start_host(struct mmc_host *host) mmc_power_off(host); else mmc_power_up(host); - mmc_detect_change(host, 0); + _mmc_detect_change(host, 0, false); } void mmc_stop_host(struct mmc_host *host) @@ -2724,7 +2739,7 @@ int mmc_pm_notify(struct notifier_block *notify_block, spin_lock_irqsave(&host->lock, flags); host->rescan_disable = 0; spin_unlock_irqrestore(&host->lock, flags); - mmc_detect_change(host, 0); + _mmc_detect_change(host, 0, false); }