From patchwork Wed Oct 5 20:31:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 9363391 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 2EBCF6077E for ; Wed, 5 Oct 2016 20:35:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FE77285F7 for ; Wed, 5 Oct 2016 20:35:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1341028CE7; Wed, 5 Oct 2016 20:35:01 +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 F19D0285F7 for ; Wed, 5 Oct 2016 20:34:59 +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 1brssk-0007uS-EP; Wed, 05 Oct 2016 20:33:38 +0000 Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1brsrg-0007Ok-Am for linux-arm-kernel@lists.infradead.org; Wed, 05 Oct 2016 20:32:33 +0000 Received: by mail-pa0-x22c.google.com with SMTP id ik13so36266872pac.2 for ; Wed, 05 Oct 2016 13:32:11 -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=DgUBRf30PqLDMkLAPCIj1TkwxBAiC+sdb7QkpGTjjMM=; b=bj4dPJN5LFEqVVONsUTuA84VbAXB349yMLXFVyW00O9YA6v/S1U65R7GSNMCog45um 98N+dLUrOhD/qUQ5wd7OVbyqJsn9cJPvQLUm80Pk+wIZKa+YJ0P8CeWZ13OF8fy4dEu4 WhVJ0iGzKAIR9umJNVrA8lvWj9293S+KgXGRU= 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=DgUBRf30PqLDMkLAPCIj1TkwxBAiC+sdb7QkpGTjjMM=; b=Pu4GeGxIFExxjXhNJZzkzcaBaSYC4dFhVG93VpZDjBo1g9Ntww6y2cfBFA59EWkZ+B NsEGYxUvCcdJIKWgbRp72xAt1JzsatycEXjW5KNN/SHxAoGA5xAi5e9B+XCgoyHe/Nr7 iX2/992fbd3w3BzsNOr2r1H0Qi/zVcuhhB3VEBaiBt6CkTaFWpdrivVLUF65/nXE1zsn Hcg89VafX7HnEMInIUwxlBVfmwNsP3d8KTm6nmIue8+0BH7YN2GFCnGXz5q7+PGILyCJ dYHbLgrpmUyxAnsHCFUyOqwy4vmaSuX0Kim/2lg8FaZeAzlH6HhR29PJKKCc4HziYVw6 YxIA== X-Gm-Message-State: AA6/9RnlDJTFoDFlW+6bqLGnRvDuFjG/W5kUcqHqVcNVZS6ahZY7dEtrEbX4ptq5YVMUFhF6 X-Received: by 10.66.163.227 with SMTP id yl3mr16452346pab.0.1475699531320; Wed, 05 Oct 2016 13:32:11 -0700 (PDT) Received: from ubuntu.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id s80sm42999467pfd.10.2016.10.05.13.32.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 05 Oct 2016 13:32:10 -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 3/8] PM / Domains: Allow domain power states to be read from DT Date: Wed, 5 Oct 2016 14:31:54 -0600 Message-Id: <1475699519-109623-4-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1475699519-109623-1-git-send-email-lina.iyer@linaro.org> References: <1475699519-109623-1-git-send-email-lina.iyer@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161005_133232_455258_1E0B997B X-CRM114-Status: GOOD ( 18.25 ) 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: lorenzo.pieralisi@arm.com, Juri.Lelli@arm.com, linux-arm-msm@vger.kernel.org, sboyd@codeaurora.org, Marc Titinger , brendan.jackman@arm.com, sudeep.holla@arm.com, andy.gross@linaro.org, Lina Iyer 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 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. This patch is based on the original patch by Marc Titinger. Signed-off-by: Marc Titinger Signed-off-by: Ulf Hansson Signed-off-by: Lina Iyer --- drivers/base/power/domain.c | 103 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 8 ++++ 2 files changed, 111 insertions(+) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 740afa9..368a5b8 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1895,6 +1895,109 @@ out: return ret ? -EPROBE_DEFER : 0; } EXPORT_SYMBOL_GPL(genpd_dev_pm_attach); + +static const struct of_device_id idle_state_match[] = { + { .compatible = "arm,idle-state", }, + { } +}; + +static int read_genpd_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(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; + + return 0; +} + +/** + * of_genpd_parse_idle_states: Return array of idle states for the genpd. + * + * @dn: The genpd device node + * @states: The pointer to which the state array will be saved. + * @n: The count of elements in the array returned from this function. + * + * Returns the device states parsed from the OF node. The memory for the states + * is allocated by this function and is the responsibility of the caller to + * free the memory after use. + */ +int of_genpd_parse_idle_states(struct device_node *dn, + struct genpd_power_state **states, int *n) +{ + struct genpd_power_state *st; + struct device_node *np; + int i, ret = 0; + int count; + + for (count = 0; ; count++) + if (!of_parse_phandle(dn, "domain-idle-states", count)) + break; + + st = kcalloc(count, sizeof(*st), GFP_KERNEL); + if (!st) + return -ENOMEM; + + for (i = 0; i < count; i++) { + np = of_parse_phandle(dn, "domain-idle-states", i); + if (!np) { + ret = -EFAULT; + break; + } + + ret = read_genpd_state(&st[i], np); + if (ret) { + pr_err + ("Parsing idle state node %s failed with err %d\n", + np->full_name, ret); + of_node_put(np); + break; + } + of_node_put(np); + } + + if (ret) { + kfree(st); + return ret; + } + + *n = count; + *states = st; + + return 0; +} +EXPORT_SYMBOL(of_genpd_parse_idle_states); + #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */ diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index c113713..4c9152d 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -204,6 +204,8 @@ extern int of_genpd_add_device(struct of_phandle_args *args, extern int of_genpd_add_subdomain(struct of_phandle_args *parent, struct of_phandle_args *new_subdomain); extern struct generic_pm_domain *of_genpd_remove_last(struct device_node *np); +extern int of_genpd_parse_idle_states(struct device_node *dn, + struct genpd_power_state **states, int *n); int genpd_dev_pm_attach(struct device *dev); #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ @@ -233,6 +235,12 @@ static inline int of_genpd_add_subdomain(struct of_phandle_args *parent, return -ENODEV; } +static inline int of_genpd_parse_idle_states(struct device_node *dn, + struct genpd_power_state **states, int *n) +{ + return -ENODEV; +} + static inline int genpd_dev_pm_attach(struct device *dev) { return -ENODEV;