From patchwork Thu Aug 25 20:03:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 9299801 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9CD2460757 for ; Thu, 25 Aug 2016 20:04:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D869292B1 for ; Thu, 25 Aug 2016 20:04:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81DAB29384; Thu, 25 Aug 2016 20:04:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF918292B1 for ; Thu, 25 Aug 2016 20:04:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757675AbcHYUEZ (ORCPT ); Thu, 25 Aug 2016 16:04:25 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:36417 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754757AbcHYUEX (ORCPT ); Thu, 25 Aug 2016 16:04:23 -0400 Received: by mail-pa0-f50.google.com with SMTP id di2so19720964pad.3 for ; Thu, 25 Aug 2016 13:03:33 -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=iUWVchUS3SlUaeN9mQkI74+iRMR5oYX1BDxk/eenDOE=; b=G8muZ9pZYLgp2N/OoLrTEUdR6qdNDWw54hDOGAk6Q1s9x1e3elBrBN1PaM2JdlofX2 5nJx5FU1+1rNOOWm/cK8hud18jBesad643IRZgzOUrRBUkWI2gPXKSn8cGAYNp+dX+k3 dX2l1z28Vu1SO1Mma8nYSk0nlFd6/jO47XiD4= 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:in-reply-to :references; bh=iUWVchUS3SlUaeN9mQkI74+iRMR5oYX1BDxk/eenDOE=; b=GhCThFfJMTCvTa3DvHPC504yGAQJPqEyIypLqkPiiYdxtrl949u6oUN5LpmoIcQkdt Ajy0igmbkWWAx5VQuJ5nKSJyfKFNVLIz51TSOCXJd/Vbn5dA5+rwYvSUcpNR6tXm/c/4 HRdUvRLP9x6imEtPWO62MtSIAOJ2nLnjHHgFsS4Bv18ZvPwX6fL0GJ77jsSYOfWYDozc tBzZu6n7CiNc2rM1puQdRLrHuoxIAOzS4dR/smyCKjOz0Riig0fV6zVkGB1SBOT9qwU0 nurKPnDEQJIG3QfO6gPcn2pCEDFvEYoQ3bj9P/epvRvQYmXa+He7MUoG5a7RIgR1/7MR HKVQ== X-Gm-Message-State: AE9vXwNgU9UJQB8ArUWEhaE4HsyZviciDUGxZYEC6bqMp0e/ZcTTbxtDBhyCBAzScnLVfFJj X-Received: by 10.66.119.11 with SMTP id kq11mr19574330pab.14.1472155412729; Thu, 25 Aug 2016 13:03:32 -0700 (PDT) Received: from ubuntu.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id u1sm22841644pfu.12.2016.08.25.13.03.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Aug 2016 13:03:31 -0700 (PDT) From: Lina Iyer To: ulf.hansson@linaro.org, khilman@kernel.org, rjw@rjwysocki.net, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: andy.gross@linaro.org, sboyd@codeaurora.org, linux-arm-msm@vger.kernel.org, brendan.jackman@arm.com, lorenzo.pieralisi@arm.com, sudeep.holla@arm.com, Juri.Lelli@arm.com, Axel Haslam , Marc Titinger , Lina Iyer Subject: [PATCH v4 01/16] PM / Domains: Allow domain power states to be read from DT Date: Thu, 25 Aug 2016 14:03:10 -0600 Message-Id: <1472155405-41841-2-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472155405-41841-1-git-send-email-lina.iyer@linaro.org> References: <1472155405-41841-1-git-send-email-lina.iyer@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Axel Haslam This patch allows domains to define idle states in the DT. SoC's can define domain idle states in DT using the "domain-idle-states" property of the domain provider. Calling of_pm_genpd_init() will read the idle states and initialize the genpd for the domain. In addition to the entry and exit latency for idle state, also add residency_ns, param and of_node property to each state. A domain idling in a state is only power effecient if it stays idle for a certain period in that state. The residency provides this minimum time for the idle state to provide power benefits. The param is a state specific u32 value that the platform may use for that idle state. Signed-off-by: Marc Titinger Signed-off-by: Lina Iyer [Lina: Added state properties, removed state names, wakeup-latency, added of_pm_genpd_init() API, pruned commit text] Signed-off-by: Ulf Hansson [Ulf: Moved around code to make it compile properly, rebased on top of multiple state support,changed to use pm_genpd_init()] --- drivers/base/power/domain.c | 92 ++++++++++++++++++++++++++++++++++++++++++++- include/linux/pm_domain.h | 11 +++++- 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index a1f2aff..3aecac3 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1253,6 +1253,90 @@ out: } EXPORT_SYMBOL_GPL(pm_genpd_remove_subdomain); +static const struct of_device_id arm_idle_state_match[] = { + { .compatible = "arm,idle-state", }, + { } +}; + +static int genpd_of_get_power_state(struct genpd_power_state *genpd_state, + struct device_node *state_node) +{ + int err = 0; + u32 latency; + u32 residency; + u32 entry_latency, exit_latency; + const struct of_device_id *match_id; + + match_id = of_match_node(arm_idle_state_match, state_node); + if (!match_id) + return -EINVAL; + + err = of_property_read_u32(state_node, "entry-latency-us", + &entry_latency); + if (err) { + pr_debug(" * %s missing entry-latency-us property\n", + state_node->full_name); + return -EINVAL; + } + + err = of_property_read_u32(state_node, "exit-latency-us", + &exit_latency); + if (err) { + pr_debug(" * %s missing exit-latency-us property\n", + state_node->full_name); + return -EINVAL; + } + + err = of_property_read_u32(state_node, "min-residency-us", &residency); + if (!err) + genpd_state->residency_ns = 1000 * residency; + + latency = entry_latency + exit_latency; + genpd_state->power_on_latency_ns = 1000 * latency; + genpd_state->power_off_latency_ns = 1000 * entry_latency; + genpd_state->of_node = state_node; + + return 0; +} + +int pm_genpd_of_parse_power_states(struct generic_pm_domain *genpd) +{ + struct device_node *np; + int i, err = 0; + + for (i = 0; i < GENPD_MAX_NUM_STATES; i++) { + np = of_parse_phandle(genpd->of_node, "domain-idle-states", i); + if (!np) + break; + + err = genpd_of_get_power_state(&genpd->states[i], np); + if (err) { + pr_err + ("Parsing idle state node %s failed with err %d\n", + np->full_name, err); + err = -EINVAL; + of_node_put(np); + break; + } + of_node_put(np); + } + + if (err) + return err; + + genpd->state_count = i; + return 0; +} +EXPORT_SYMBOL(pm_genpd_of_parse_power_states); + +static int genpd_of_parse(struct generic_pm_domain *genpd) +{ + if (!genpd->of_node || (genpd->state_count > 0)) + return 0; + + return pm_genpd_of_parse_power_states(genpd); +} + /** * pm_genpd_init - Initialize a generic I/O PM domain object. * @genpd: PM domain object to initialize. @@ -1262,8 +1346,10 @@ EXPORT_SYMBOL_GPL(pm_genpd_remove_subdomain); * Returns 0 on successful initialization, else a negative error code. */ int pm_genpd_init(struct generic_pm_domain *genpd, - struct dev_power_governor *gov, bool is_off) + struct dev_power_governor *gov, bool is_off) { + int ret; + if (IS_ERR_OR_NULL(genpd)) return -EINVAL; @@ -1306,6 +1392,10 @@ int pm_genpd_init(struct generic_pm_domain *genpd, genpd->dev_ops.start = pm_clk_resume; } + ret = genpd_of_parse(genpd); + if (ret) + return ret; + if (genpd->state_idx >= GENPD_MAX_NUM_STATES) { pr_warn("Initial state index out of bounds.\n"); genpd->state_idx = GENPD_MAX_NUM_STATES - 1; diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 31fec85..c5d14b9 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -40,6 +40,9 @@ struct gpd_dev_ops { struct genpd_power_state { s64 power_off_latency_ns; s64 power_on_latency_ns; + s64 residency_ns; + u32 param; + struct device_node *of_node; }; struct generic_pm_domain { @@ -51,6 +54,7 @@ struct generic_pm_domain { struct mutex lock; struct dev_power_governor *gov; struct work_struct power_off_work; + struct device_node *of_node; /* Device node of the PM domain */ const char *name; atomic_t sd_count; /* Number of subdomains with power "on" */ enum gpd_status status; /* Current state of the domain */ @@ -129,7 +133,7 @@ extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, struct generic_pm_domain *target); extern int pm_genpd_init(struct generic_pm_domain *genpd, struct dev_power_governor *gov, bool is_off); - +extern int pm_genpd_of_parse_power_states(struct generic_pm_domain *genpd); extern struct dev_power_governor simple_qos_governor; extern struct dev_power_governor pm_domain_always_on_gov; #else @@ -168,6 +172,11 @@ static inline int pm_genpd_init(struct generic_pm_domain *genpd, { return -ENOSYS; } +static inline int pm_genpd_of_parse_power_states( + struct generic_pm_domain *genpd) +{ + return -ENODEV; +} #endif static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,