From patchwork Sat Jun 23 00:32:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 9586 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 409E124024 for ; Sat, 23 Jun 2012 00:33:19 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id DF5B1A1821B for ; Sat, 23 Jun 2012 00:33:18 +0000 (UTC) Received: by ggnf1 with SMTP id f1so2171348ggn.11 for ; Fri, 22 Jun 2012 17:33:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-content-scanned:x-cbid :x-gm-message-state; bh=Zm/ObtChVtg36AOufwS10Zt1x/h4XMXx7zfVm1hrasY=; b=fhWR6ARx+CmiGAJp/MKSaOvUZOKB5sL1PYip5C8JtDJwdA2MArzPl0PYPcTLwzMUct stOeDS6ac3AQIwCQBS6G/WQFIchP/Eysd2hzYrsSsA6rmTh2o3j8f6cXc5YcdYu0UGyO R3a2nVqpMdUo1rLMK4kQwsG7HRqTtPDwzpwjg1s6HuDd8BaRYXPuG4XUJUHQDZLsy7Jo 23RuGtVEA2feCPX9riuOaOYZ105EodnuJ4NQlaqfgl0KWpnYG5CzdXDI/rK01pwyMybZ ildrRlDqZPatg5mJNNOcI9YE5bKXg8gm5LE77JUm48f8pxNMlw2+gyf/ez0yIll3rPnM oerw== Received: by 10.50.57.167 with SMTP id j7mr3264929igq.53.1340411598271; Fri, 22 Jun 2012 17:33:18 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.24.148 with SMTP id v20csp90781ibb; Fri, 22 Jun 2012 17:33:17 -0700 (PDT) Received: by 10.50.237.9 with SMTP id uy9mr3242658igc.40.1340411597227; Fri, 22 Jun 2012 17:33:17 -0700 (PDT) Received: from e33.co.us.ibm.com (e33.co.us.ibm.com. [32.97.110.151]) by mx.google.com with ESMTPS id eu10si863557igc.55.2012.06.22.17.33.16 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 22 Jun 2012 17:33:17 -0700 (PDT) Received-SPF: neutral (google.com: 32.97.110.151 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=32.97.110.151; Authentication-Results: mx.google.com; spf=neutral (google.com: 32.97.110.151 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) smtp.mail=john.stultz@linaro.org Received: from /spool/local by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 22 Jun 2012 18:33:16 -0600 Received: from d01dlp03.pok.ibm.com (9.56.224.17) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 22 Jun 2012 18:33:06 -0600 Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 06F6AC9005C; Fri, 22 Jun 2012 20:33:04 -0400 (EDT) Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay02.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q5N0X5Kw172966; Fri, 22 Jun 2012 20:33:05 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q5N0X4U9006687; Fri, 22 Jun 2012 21:33:05 -0300 Received: from kernel.stglabs.ibm.com (kernel.stglabs.ibm.com [9.114.214.19]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q5N0X4TE006684; Fri, 22 Jun 2012 21:33:04 -0300 From: John Stultz To: San Mehat Cc: John Stultz , Colin Cross Subject: [PATCH] mmc: Enable wakeup_sources for mmc core Date: Fri, 22 Jun 2012 20:32:50 -0400 Message-Id: <1340411570-63361-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12062300-2398-0000-0000-000007CB4CC7 X-Gm-Message-State: ALoCoQnUzJSDHMzUnA6ArIeKF7okxnhqdjQVb3FFrjeAU3jKC4ag0s9/lNe3QN8Byl4aExvWYr8f Hey San, Colin, I just wanted to send this your way for comment before possibly sending it to the mmc maintainer & lkml. Let me know if you have any objections. thanks -john This is a reworked implementation using wakeup_sources of two patches by San Mehat and Colin Cross that enabled wakelocks for the mmc core. CC: San Mehat CC: Colin Cross Signed-off-by: John Stultz --- drivers/mmc/core/core.c | 26 +++++++++++++++++++++----- drivers/mmc/core/host.c | 4 ++++ include/linux/mmc/host.h | 2 ++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 0b6141d..6e86f3d 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -1358,6 +1359,8 @@ void mmc_detect_change(struct mmc_host *host, unsigned long delay) spin_unlock_irqrestore(&host->lock, flags); #endif host->detect_change = 1; + + __pm_stay_awake(&host->detect_wakeup_source); mmc_schedule_delayed_work(&host->detect, delay); } @@ -2016,6 +2019,7 @@ void mmc_rescan(struct work_struct *work) struct mmc_host *host = container_of(work, struct mmc_host, detect.work); int i; + bool extend_wakeup = false; if (host->rescan_disable) return; @@ -2060,16 +2064,25 @@ void mmc_rescan(struct work_struct *work) mmc_claim_host(host); for (i = 0; i < ARRAY_SIZE(freqs); i++) { - if (!mmc_rescan_try_freq(host, max(freqs[i], host->f_min))) + if (!mmc_rescan_try_freq(host, max(freqs[i], host->f_min))) { + extend_wakeup = true; break; + } if (freqs[i] <= host->f_min) break; } mmc_release_host(host); out: - if (host->caps & MMC_CAP_NEEDS_POLL) + if (extend_wakeup) + __pm_wakeup_event(&host->detect_wakeup_source, 500); + else + __pm_relax(&host->detect_wakeup_source); + + if (host->caps & MMC_CAP_NEEDS_POLL) { + __pm_stay_awake(&host->detect_wakeup_source); mmc_schedule_delayed_work(&host->detect, HZ); + } } void mmc_start_host(struct mmc_host *host) @@ -2088,7 +2101,8 @@ void mmc_stop_host(struct mmc_host *host) spin_unlock_irqrestore(&host->lock, flags); #endif - cancel_delayed_work_sync(&host->detect); + if (cancel_delayed_work_sync(&host->detect)) + __pm_relax(&host->detect_wakeup_source); mmc_flush_scheduled_work(); /* clear pm flags now and let card drivers set them as needed */ @@ -2284,7 +2298,8 @@ int mmc_suspend_host(struct mmc_host *host) { int err = 0; - cancel_delayed_work(&host->detect); + if (cancel_delayed_work(&host->detect)) + __pm_relax(&host->detect_wakeup_source); mmc_flush_scheduled_work(); err = mmc_cache_ctrl(host, 0); @@ -2387,7 +2402,8 @@ int mmc_pm_notify(struct notifier_block *notify_block, host->rescan_disable = 1; host->power_notify_type = MMC_HOST_PW_NOTIFY_SHORT; spin_unlock_irqrestore(&host->lock, flags); - cancel_delayed_work_sync(&host->detect); + if (cancel_delayed_work_sync(&host->detect)) + __pm_relax(&host->detect_wakeup_source); if (!host->bus_ops || host->bus_ops->suspend) break; diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index 91c84c7..3117d35 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -329,6 +329,9 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) spin_lock_init(&host->lock); init_waitqueue_head(&host->wq); + wakeup_source_init(&host->detect_wakeup_source, + kasprintf(GFP_KERNEL, "%s_detect", + mmc_hostname(host))); INIT_DELAYED_WORK(&host->detect, mmc_rescan); #ifdef CONFIG_PM host->pm_notify.notifier_call = mmc_pm_notify; @@ -425,6 +428,7 @@ void mmc_free_host(struct mmc_host *host) spin_lock(&mmc_host_lock); idr_remove(&mmc_host_idr, host->index); spin_unlock(&mmc_host_lock); + wakeup_source_trash(&host->detect_wakeup_source); put_device(&host->class_dev); } diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 0707d22..a3c75d8 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -289,6 +290,7 @@ struct mmc_host { int claim_cnt; /* "claim" nesting count */ struct delayed_work detect; + struct wakeup_source detect_wakeup_source; int detect_change; /* card detect flag */ struct mmc_hotplug hotplug;