From patchwork Wed Mar 14 16:58:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 885936 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="WElXkpgU"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 401dNy1xdmz9s9y for ; Thu, 15 Mar 2018 04:04:18 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751776AbeCNRED (ORCPT ); Wed, 14 Mar 2018 13:04:03 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:44477 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752279AbeCNQ7Y (ORCPT ); Wed, 14 Mar 2018 12:59:24 -0400 Received: by mail-lf0-f66.google.com with SMTP id v9-v6so5855157lfa.11 for ; Wed, 14 Mar 2018 09:59:23 -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=9Hut8uxV9o4+GGyqitzbiLTfPeq/ETjSQ3OWzL2xcrU=; b=WElXkpgUTZAj1q/q8hJkarTQaWXBTIn6m4bJPQvq9DZ0jV+LgukZJkC8ywZYn4JvJU 8OirnsnOr6P3fPBzjn7r2Ddj3xUmZ4dwSTw7k2CaHeGztQMA/fiRBl7bYacBueZOzCGS xaR99wLurWuYcnDSzS7qnhmjEzz1sZS/hcPAs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9Hut8uxV9o4+GGyqitzbiLTfPeq/ETjSQ3OWzL2xcrU=; b=DADxwG2tKGYmGHWYZHiGqjyQdQUlLygFDtcRPqxp8bSjiIkIgCMQzAmw8PI+Kwv0/a lOsIfD+WBJ3xZP7sggWKlIiMOJru7Sfn1osaM5nBEYu8bRFPEi+xbgo2jTIuoPiwVP8g gIF9SbZ9FQrnIOfzRexQH+bcsr58/fayPo8YetPjCyvL+gMR46i1QF+CF+afy0XyvKCJ h6RwZBGmH0r/x/cgTagP8jnjXo023ad3p9NsLE8UT184eokZqS0thp6sLOMy9i7P2ge3 uYHZMv2awxQdoBHZKMoYEvH4VcMBjZVpMWvA2x9r+10goodSRdRoJJ7sKEe2lf0Ptb3H +sjA== X-Gm-Message-State: AElRT7Fz9BKoUtwPoCUm4+XK3fQhGZdtFkyk3GewXmYWH/7pgfeZkLlO 93IlIc1tAxPrmMzMETN9tOgT0g== X-Google-Smtp-Source: AG47ELuyhOyJV0EL2V4Xan2c19SvKeNx8mqwbPpPCZuAvuXLzemjeIFlI3fpdg0W1IBJ0ucW26IQXg== X-Received: by 2002:a19:d744:: with SMTP id o65-v6mr4080626lfg.90.1521046762802; Wed, 14 Mar 2018 09:59:22 -0700 (PDT) Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t24-v6sm724849lfi.30.2018.03.14.09.59.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Mar 2018 09:59:21 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , linux-pm@vger.kernel.org Cc: Kevin Hilman , Lina Iyer , Lina Iyer , Ulf Hansson , Rob Herring , Daniel Lezcano , Thomas Gleixner , Vincent Guittot , Stephen Boyd , Juri Lelli , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v6 11/25] of: base: Add of_get_cpu_state_node() to get idle states for a CPU node Date: Wed, 14 Mar 2018 17:58:21 +0100 Message-Id: <1521046715-30683-12-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521046715-30683-1-git-send-email-ulf.hansson@linaro.org> References: <1521046715-30683-1-git-send-email-ulf.hansson@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The CPU's idle state nodes are currently parsed at the common cpuidle DT library, but also when initializing back-end data for the arch specific CPU operations, as in the PSCI driver case. To avoid open-coding, let's introduce of_get_cpu_state_node(), which takes the device node for the CPU and the index to the requested idle state node, as in-parameters. In case a corresponding idle state node is found, it returns the node with the refcount incremented for it, else it returns NULL. Moreover, for ARM, there are two generic methods, to describe the CPU's idle states, either via the flattened description through the "cpu-idle-states" binding [1] or via the hierarchical layout, using the "power-domains" and the "domain-idle-states" bindings [2]. Hence, let's take both options into account. [1] Documentation/devicetree/bindings/arm/idle-states.txt [2] Documentation/devicetree/bindings/arm/psci.txt Cc: Rob Herring Cc: devicetree@vger.kernel.org Cc: Lina Iyer Suggested-by: Sudeep Holla Co-developed-by: Lina Iyer Signed-off-by: Ulf Hansson Reviewed-by: Rob Herring --- drivers/of/base.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/of.h | 8 ++++++++ 2 files changed, 43 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index ad28de9..88d36a3 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -338,6 +338,41 @@ int of_cpu_node_to_id(struct device_node *cpu_node) EXPORT_SYMBOL(of_cpu_node_to_id); /** + * of_get_cpu_state_node - Get CPU's idle state node at the given index + * + * @cpu_node: The device node for the CPU + * @index: The index in the list of the idle states + * + * Two generic methods can be used to describe a CPU's idle states, either via + * a flattened description through the "cpu-idle-states" binding or via the + * hierarchical layout, using the "power-domains" and the "domain-idle-states" + * bindings. This function check for both and returns the idle state node for + * the requested index. + * + * In case and idle state node is found at index, the refcount incremented for + * it, so call of_node_put() on it when done. Returns NULL if not found. + */ +struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, + int index) +{ + struct of_phandle_args args; + int err; + + err = of_parse_phandle_with_args(cpu_node, "power-domains", + "#power-domain-cells", 0, &args); + if (!err) { + struct device_node *state_node = + of_parse_phandle(args.np, "domain-idle-states", index); + + of_node_put(args.np); + return state_node; + } + + return of_parse_phandle(cpu_node, "cpu-idle-states", index); +} +EXPORT_SYMBOL(of_get_cpu_state_node); + +/** * __of_device_is_compatible() - Check if the node matches given constraints * @device: pointer to node * @compat: required compatible string, NULL or "" for any match diff --git a/include/linux/of.h b/include/linux/of.h index da1ee95..288233c 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -348,6 +348,8 @@ extern const void *of_get_property(const struct device_node *node, const char *name, int *lenp); extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); +extern struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, + int index); #define for_each_property_of_node(dn, pp) \ for (pp = dn->properties; pp != NULL; pp = pp->next) @@ -730,6 +732,12 @@ static inline struct device_node *of_get_cpu_node(int cpu, return NULL; } +static inline struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, + int index) +{ + return NULL; +} + static inline int of_n_addr_cells(struct device_node *np) { return 0;