From patchwork Wed Jun 22 19:36:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 9193649 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 E1AF860890 for ; Wed, 22 Jun 2016 19:39:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CECD62841B for ; Wed, 22 Jun 2016 19:39:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2AEF28409; Wed, 22 Jun 2016 19:39:06 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id D60D528409 for ; Wed, 22 Jun 2016 19:39:05 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bFnyE-0001e6-Qd; Wed, 22 Jun 2016 19:37:54 +0000 Received: from mail-pa0-x22f.google.com ([2607:f8b0:400e:c03::22f]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bFny2-0001YB-9Q for linux-arm-kernel@lists.infradead.org; Wed, 22 Jun 2016 19:37:43 +0000 Received: by mail-pa0-x22f.google.com with SMTP id bz2so19564024pad.1 for ; Wed, 22 Jun 2016 12:37:21 -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=ybtNPdyfuwkc1V+OIdR7WeFwbyprxquvdhTxmGszxeM=; b=EURLQjD6y9J/uDEDCPUK7SXsSrZ3any1YsKqSA5glpOQWtAP09LwBSbD3ihdiT27nl x+B3DJiMFHRgIpSEr19+HfvLHwA6xjuhfGNOTyZFqj7fPTiu+eISq/bwbgjyzIdKnsH/ 80Zdv5M9UZhJiZu21E1J+VtZHWEZrMiAmdUc8= 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=ybtNPdyfuwkc1V+OIdR7WeFwbyprxquvdhTxmGszxeM=; b=cmzBVp3ZF4V87nyopiEzESbhQ5ZMNAXK8SjZy4Aw9d/T/sLNz5gkj924sCN5J8xTq1 UP846CWhXfo6fc42fcBTPYfLbUNaF6HPdcxI0fCRo5pDAEMKKRF/5LqjsBJtoTdHZ/Xc hkb6+aObf2EKiQOoESl2buh5kJiAKFotrxJEWq0VeVV/U1oW+YkYtyTR8M5PYWmRT5h7 7rRoOOHwjFruy0E3za7qtyui6gnMUR7JIIolFeTed2Y8M6m+6Jo3VXhHbmllYQvI1aNg AJz0u9owceB8ikKPwG8O/qkVHrLbM6G0/TBNtLcyHWbkoiNEJINDvKq0me5QxI6v9q9L UXQA== X-Gm-Message-State: ALyK8tK+Ouhf/PuQhcWjP11lSRQGgauOaCtJ6t0sn+H7Z95Xef+YoQeJVf4K2WF+M1woW/+6 X-Received: by 10.66.139.230 with SMTP id rb6mr36777264pab.101.1466624241495; Wed, 22 Jun 2016 12:37:21 -0700 (PDT) Received: from ubuntu.localdomain ([172.56.9.151]) by smtp.gmail.com with ESMTPSA id t4sm1563368paw.32.2016.06.22.12.37.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Jun 2016 12:37:19 -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 Subject: [PATCH 01/14] PM / Domains: Allow domain power states to be read from DT Date: Wed, 22 Jun 2016 13:36:36 -0600 Message-Id: <1466624209-27432-2-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1466624209-27432-1-git-send-email-lina.iyer@linaro.org> References: <1466624209-27432-1-git-send-email-lina.iyer@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160622_123742_477582_C1A827C6 X-CRM114-Status: GOOD ( 16.14 ) 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: , Cc: k.kozlowski@samsung.com, lorenzo.pieralisi@arm.com, ahaslam@baylibre.com, linux-arm-msm@vger.kernel.org, sboyd@codeaurora.org, Axel Haslam , Marc Titinger , geert@linux-m68k.org, Lina Iyer , andy.gross@linaro.org, mtitinger@baylibre.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 "power-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 and state-param properties. 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 state-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 | 84 ++++++++++++++++++++++++++++++++++++++++++++- include/linux/pm_domain.h | 3 ++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index a1f2aff..62ffabd 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1253,6 +1253,82 @@ out: } EXPORT_SYMBOL_GPL(pm_genpd_remove_subdomain); +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 param; + u32 entry_latency, exit_latency; + + 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, "residency-us", &residency); + if (!err) + genpd_state->residency_ns = 1000 * residency; + + err = of_property_read_u32(state_node, "state-param", ¶m); + if (!err) + genpd_state->param = param; + + latency = entry_latency + exit_latency; + genpd_state->power_on_latency_ns = 1000 * latency; + genpd_state->power_off_latency_ns = 1000 * entry_latency; + + return 0; +} + +static int 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, "power-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; + break; + } + of_node_put(np); + } + + if (err) + return err; + + genpd->state_count = i; + return 0; +} + +static int genpd_of_parse(struct generic_pm_domain *genpd) +{ + if (!genpd->of_node) + return 0; + + return 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 +1338,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 +1384,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..a3ac52d 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -40,6 +40,8 @@ struct gpd_dev_ops { struct genpd_power_state { s64 power_off_latency_ns; s64 power_on_latency_ns; + s64 residency_ns; + u32 param; }; struct generic_pm_domain { @@ -51,6 +53,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 */