From patchwork Thu Mar 28 16:11:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rickard Andersson X-Patchwork-Id: 2357611 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 7FF683FD40 for ; Thu, 28 Mar 2013 16:16:55 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ULFSV-0006G8-DI; Thu, 28 Mar 2013 16:13:47 +0000 Received: from eu1sys200aog103.obsmtp.com ([207.126.144.115]) by merlin.infradead.org with smtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ULFQv-0005nM-TP for linux-arm-kernel@lists.infradead.org; Thu, 28 Mar 2013 16:12:16 +0000 Received: from beta.dmz-ap.st.com ([138.198.100.35]) (using TLSv1) by eu1sys200aob103.postini.com ([207.126.147.11]) with SMTP ID DSNKUVRrzfPYG1IupmXZs0Bye2rfFdk4w67E@postini.com; Thu, 28 Mar 2013 16:12:09 UTC Received: from zeta.dmz-ap.st.com (ns6.st.com [138.198.234.13]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 07ACAE2; Thu, 28 Mar 2013 16:03:44 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 58E20157D; Thu, 28 Mar 2013 16:11:51 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id 48A0DA8074; Thu, 28 Mar 2013 17:11:44 +0100 (CET) Received: from steludxu2826.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.30) with Microsoft SMTP Server (TLS) id 8.3.279.5; Thu, 28 Mar 2013 17:11:50 +0100 From: Rickard Andersson To: , , Subject: [PATCH V2 03/12] PM / Domains: Add on-off notifiers Date: Thu, 28 Mar 2013 17:11:29 +0100 Message-ID: <1364487098-10319-4-git-send-email-rickard.andersson@stericsson.com> X-Mailer: git-send-email 1.8.2 In-Reply-To: <1364487098-10319-1-git-send-email-rickard.andersson@stericsson.com> References: <1364487098-10319-1-git-send-email-rickard.andersson@stericsson.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130328_121210_304774_F326E09F X-CRM114-Status: GOOD ( 20.14 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [207.126.144.115 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: hongbo.zhang@linaro.org, ulf.hansson@linaro.org, khilman@linaro.org, linus.walleij@stericsson.com, daniel.lezcano@linaro.org, rickard.andersson@stericsson.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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 Some drivers needs to restore their context directly when a power domain is activated. For example a driver handling system bus settings must be able to restore context before the bus is being used for the first time. Other examples could be clock settings hardware blocks and special debugging hardware blocks which should be restored as early as possible in order to be able to debug direcly from waking up. Typically these notifers are needed in systems with CPU coupled power domains. The notifiers are intended to be trigged by cpuidle driver or the suspend ops hooks. The drivers that needs to use these notifiers are some special cases. Most drivers should not use this method and instead control their context via the pm_runtime interface. Signed-off-by: Rickard Andersson --- I believe notifiers are the best solution to the problem of restoring context early when waking up after sleep. It is similar to what is done in /kernel/cpu_pm.c but but for a generic power domain instead. An alternative solution could be to try to call the drivers runtime_resume/runtime_suspend callbacks instead via genpd from cpuidle or suspend/resume. I do not recommend that solution for the following reasons: * Altered use of runtime PM. As it is today the driver itself controls when to runtime-suspend/runtime-resume. * Runtime PM is disabled during late stages of suspend. * Complicates runtime PM for a few special cases. --- drivers/base/power/domain.c | 63 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 22 ++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index acc3a8d..91e3b7d 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1956,6 +1956,68 @@ int pm_genpd_name_detach_cpuidle(const char *name) return pm_genpd_detach_cpuidle(pm_genpd_lookup_name(name)); } +/** + * pm_genpd_register_on_off_notifier - Register to early power on / + * late power off notifications. + * Only use this function if absolutly needed. It is only intended to be + * used for power domains that are coupled with the CPU, that is, power + * domains being controlled from cpuidle and the platform suspend ops hooks. + * Also only devices that needs their context to be restored directly when + * leaving a sleep state should use this method. Most devices should be + * fine handling their context and power domains via pm_runtime. + * @dev: Device to register. + * @nb: Notifier block to be registered. + */ +int pm_genpd_register_on_off_notifier(struct device *dev, + struct notifier_block *nb) +{ + struct generic_pm_domain *genpd; + + dev_dbg(dev, "%s()\n", __func__); + + genpd = dev_to_genpd(dev); + + return atomic_notifier_chain_register(&genpd->on_off_notifier, nb); +} + +/** + * pm_genpd_unregister_on_off_notifier - Unregister to early power on / + * late power off notification. + * @dev: Device to unregister. + * @nb: Notifier block to be unregistered. + */ +int pm_genpd_unregister_on_off_notifier(struct device *dev, + struct notifier_block *nb) +{ + struct generic_pm_domain *genpd; + + dev_dbg(dev, "%s()\n", __func__); + + genpd = dev_to_genpd(dev); + + return atomic_notifier_chain_unregister(&genpd->on_off_notifier, nb); +} + +/** + * pm_genpd_notify_power_on_off - Notify that the CPU coupled power + * domain is going to be powered off or has been powered on.5D + * Intended users of this function are cpuidle drivers and the platform + * suspend operations implementation. + * @genpd: pm domain that will change state. + * @power_on_off: true = has been powered on, false = will power off. + */ +int pm_genpd_notify_power_on_off(struct generic_pm_domain *genpd, + bool power_on_off) +{ + if (IS_ERR_OR_NULL(genpd)) + return -EINVAL; + + atomic_notifier_call_chain((&genpd->on_off_notifier), + power_on_off, NULL); + + return 0; +} + /* Default device callbacks for generic PM domains. */ /** @@ -2137,6 +2199,7 @@ void pm_genpd_init(struct generic_pm_domain *genpd, atomic_set(&genpd->sd_count, 0); genpd->status = is_off ? GPD_STATE_POWER_OFF : GPD_STATE_ACTIVE; init_waitqueue_head(&genpd->status_wait_queue); + ATOMIC_INIT_NOTIFIER_HEAD(&genpd->on_off_notifier); genpd->poweroff_task = NULL; genpd->resume_count = 0; genpd->device_count = 0; diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 7c1d252..bf5e7d514 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -82,6 +82,7 @@ struct generic_pm_domain { bool cached_power_down_ok; struct device_node *of_node; /* Node in device tree */ struct gpd_cpu_data *cpu_data; + struct atomic_notifier_head on_off_notifier; }; static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd) @@ -159,6 +160,12 @@ extern int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state); extern int pm_genpd_name_attach_cpuidle(const char *name, int state); extern int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd); extern int pm_genpd_name_detach_cpuidle(const char *name); +extern int pm_genpd_register_on_off_notifier(struct device *dev, + struct notifier_block *nb); +extern int pm_genpd_unregister_on_off_notifier(struct device *dev, + struct notifier_block *nb); +extern int pm_genpd_notify_power_on_off(struct generic_pm_domain *genpd, + bool power_on_off); extern void pm_genpd_init(struct generic_pm_domain *genpd, struct dev_power_governor *gov, bool is_off); @@ -243,6 +250,21 @@ static inline int pm_genpd_name_detach_cpuidle(const char *name) { return -ENOSYS; } +static inline int pm_genpd_register_on_off_notifier(struct device *dev, + struct notifier_block *nb) +{ + return -ENOSYS; +} +static inline int pm_genpd_unregister_on_off_notifier(struct device *dev, + struct notifier_block *nb) +{ + return -ENOSYS; +} +static inline int pm_genpd_notify_power_on_off(struct generic_pm_domain *genpd, + bool power_on_off) +{ + return -ENOSYS; +} static inline void pm_genpd_init(struct generic_pm_domain *genpd, struct dev_power_governor *gov, bool is_off) {