From patchwork Mon Jan 23 20:48:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 92276 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1408612qgi; Mon, 23 Jan 2017 12:49:46 -0800 (PST) X-Received: by 10.98.153.25 with SMTP id d25mr34822689pfe.15.1485204586130; Mon, 23 Jan 2017 12:49:46 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t12si16730390pfj.24.2017.01.23.12.49.44; Mon, 23 Jan 2017 12:49:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751792AbdAWUtf (ORCPT + 25 others); Mon, 23 Jan 2017 15:49:35 -0500 Received: from mail-pg0-f54.google.com ([74.125.83.54]:33285 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751337AbdAWUsz (ORCPT ); Mon, 23 Jan 2017 15:48:55 -0500 Received: by mail-pg0-f54.google.com with SMTP id 204so47879588pge.0 for ; Mon, 23 Jan 2017 12:48:55 -0800 (PST) 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=sccGS+5KK7RROrkKvBjJ/ZbI7VzLF0k+9ZfiAzFqfgA=; b=Yyk7Xbqa/KiA7Y47N9Ct5xURFUQiLQwsO8QJpYgTElbYRrmd0WKPAFvN5saWkpfSHQ EAuKL91ppYmOEcbliQl+78+zl3dTpi46n0FLq1s2F5Ku0xLz1XploMF/SaxgjSrFxLc3 JWLiLhF6uIWKtiCmQtQLqnk9vYArKmHo1Nfrk= 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=sccGS+5KK7RROrkKvBjJ/ZbI7VzLF0k+9ZfiAzFqfgA=; b=pgctBNSuyTqAv93shoOAnFi0I7sC82qVHKjxoNzhrzjFKpyo0pU2LDmxwpP4waChrc FZgfqRourX7eEDP9gRGDjobipDNw3N62RUKoY6e422EfOF0jp5pr6RP3XSP5s1/T4oP5 wPZJySeM06OO03TS+0WXdRTuYcHgHHWfRy0QDdez3znTaOuRwA3/8qUrle8abQCDV/dW 3LQ1pjTNBCZ47pGE2xDuB6CRWm6FvXrRfK2N0+acPv12RlVFfi/hwbvirAy3CKMAFfuH blynfCEhqElm7b3jueKHnYztMUIYxCMn956I2yP3RatgltZieK65q3c6LGn97rJI5bx9 VFOg== X-Gm-Message-State: AIkVDXKRlWe1ZTporsXC9jpPbklreAVBp7GdecgeAW1qU4YsJkEUcQH1rAe4EVvRi7nygmOn X-Received: by 10.98.103.195 with SMTP id t64mr34170370pfj.106.1485204534259; Mon, 23 Jan 2017 12:48:54 -0800 (PST) Received: from localhost.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id l12sm38935728pfj.37.2017.01.23.12.48.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Jan 2017 12:48:53 -0800 (PST) From: Stephen Boyd To: Rob Herring , Frank Rowand Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, Pantelis Antoniou , Linus Walleij , Mark Brown Subject: [PATCH v3 1/3] of: Support parsing phandle argument lists through a nexus node Date: Mon, 23 Jan 2017 12:48:49 -0800 Message-Id: <20170123204851.12808-2-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.10.0.297.gf6727b0 In-Reply-To: <20170123204851.12808-1-stephen.boyd@linaro.org> References: <20170123204851.12808-1-stephen.boyd@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Platforms like 96boards have a standardized connector/expansion slot that exposes signals like GPIOs to expansion boards in an SoC agnostic way. We'd like the DT overlays for the expansion boards to be written once without knowledge of the SoC on the other side of the connector. This avoids the unscalable combinatorial explosion of a different DT overlay for each expansion board and SoC pair. We need a way to describe the GPIOs routed through the connector in an SoC agnostic way. Let's introduce nexus property parsing into the OF core to do this. This is largely based on the interrupt nexus support we already have. This allows us to remap a phandle list in a consumer node (e.g. reset-gpios) through a connector in a generic way (e.g. via gpio-map). Do this in a generic routine so that we can remap any sort of variable length phandle list. Taking GPIOs as an example, the connector would be a GPIO nexus, supporting the remapping of a GPIO specifier space to multiple GPIO providers on the SoC. DT would look as shown below, where 'soc_gpio1' and 'soc_gpio2' are inside the SoC, 'connector' is an expansion port where boards can be plugged in, and 'expansion_device' is a device on the expansion board. soc { soc_gpio1: gpio-controller1 { #gpio-cells = <2>; }; soc_gpio2: gpio-controller2 { #gpio-cells = <2>; }; }; connector: connector { #gpio-cells = <2>; gpio-map = <0 0 &soc_gpio1 1 0>, <1 0 &soc_gpio2 4 0>, <2 0 &soc_gpio1 3 0>, <3 0 &soc_gpio2 2 0>; gpio-map-mask = <0xf 0x0>; gpio-map-pass-thru = <0x0 0x1> }; expansion_device { reset-gpios = <&connector 2 GPIO_ACTIVE_LOW>; }; The GPIO core would use of_parse_phandle_with_args_map() instead of of_parse_phandle_with_args() and arrive at the same type of result, a phandle and argument list. The difference is that the phandle and arguments will be remapped through the nexus node to the underlying SoC GPIO controller node. In the example above, we would remap 'reset-gpios' from <&connector 2 GPIO_ACTIVE_LOW> to <&soc_gpio1 3 GPIO_ACTIVE_LOW>. Cc: Pantelis Antoniou Cc: Linus Walleij Cc: Mark Brown Signed-off-by: Stephen Boyd --- drivers/of/base.c | 184 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 12 ++++ 2 files changed, 196 insertions(+) -- 2.10.0.297.gf6727b0 diff --git a/drivers/of/base.c b/drivers/of/base.c index d4bea3c797d6..fb6bb855714e 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1775,6 +1775,190 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na EXPORT_SYMBOL(of_parse_phandle_with_args); /** + * of_parse_phandle_with_args_map() - Find a node pointed by phandle in a list and remap it + * @np: pointer to a device tree node containing a list + * @list_name: property name that contains a list + * @stem_name: stem of property names that specify phandles' arguments count + * @index: index of a phandle to parse out + * @out_args: optional pointer to output arguments structure (will be filled) + * + * This function is useful to parse lists of phandles and their arguments. + * Returns 0 on success and fills out_args, on error returns appropriate errno + * value. The difference between this function and of_parse_phandle_with_args() + * is that this API remaps a phandle if the node the phandle points to has + * a <@stem_name>-map property. + * + * Caller is responsible to call of_node_put() on the returned out_args->np + * pointer. + * + * Example: + * + * phandle1: node1 { + * #list-cells = <2>; + * } + * + * phandle2: node2 { + * #list-cells = <1>; + * } + * + * phandle3: node3 { + * #list-cells = <1>; + * list-map = <0 &phandle2 3>, + * <1 &phandle2 2>, + * <2 &phandle1 5 1>; + * list-map-mask = <0x3>; + * }; + * + * node4 { + * list = <&phandle1 1 2 &phandle3 0>; + * } + * + * To get a device_node of the `node2' node you may call this: + * of_parse_phandle_with_args(node4, "list", "list", 1, &args); + */ +int of_parse_phandle_with_args_map(const struct device_node *np, + const char *list_name, + const char *stem_name, + int index, struct of_phandle_args *out_args) +{ + char *cells_name, *map_name = NULL, *mask_name = NULL; + char *pass_name = NULL; + struct device_node *cur, *new = NULL; + const __be32 *map, *mask, *pass; + static const __be32 dummy_mask[] = { [0 ... MAX_PHANDLE_ARGS] = ~0 }; + static const __be32 dummy_pass[] = { [0 ... MAX_PHANDLE_ARGS] = 0 }; + __be32 initial_match_array[MAX_PHANDLE_ARGS]; + const __be32 *match_array = initial_match_array; + int i, ret, map_len, match; + u32 list_size, new_size; + + if (index < 0) + return -EINVAL; + + cells_name = kasprintf(GFP_KERNEL, "#%s-cells", stem_name); + if (!cells_name) + return -ENOMEM; + + ret = -ENOMEM; + map_name = kasprintf(GFP_KERNEL, "%s-map", stem_name); + if (!map_name) + goto free; + + mask_name = kasprintf(GFP_KERNEL, "%s-map-mask", stem_name); + if (!mask_name) + goto free; + + pass_name = kasprintf(GFP_KERNEL, "%s-map-pass-thru", stem_name); + if (!pass_name) + goto free; + + ret = __of_parse_phandle_with_args(np, list_name, cells_name, 0, index, + out_args); + if (ret) + goto free; + + /* Get the #-cells property */ + cur = out_args->np; + ret = of_property_read_u32(cur, cells_name, &list_size); + if (ret < 0) + goto put; + + /* Precalculate the match array - this simplifies match loop */ + for (i = 0; i < list_size; i++) + initial_match_array[i] = cpu_to_be32(out_args->args[i]); + + ret = -EINVAL; + while (cur) { + /* Get the -map property */ + map = of_get_property(cur, map_name, &map_len); + if (!map) { + ret = 0; + goto free; + } + map_len /= sizeof(u32); + + /* Get the -map-mask property (optional) */ + mask = of_get_property(cur, mask_name, NULL); + if (!mask) + mask = dummy_mask; + /* Iterate through -map property */ + match = 0; + while (map_len > (list_size + 1) && !match) { + /* Compare specifiers */ + match = 1; + for (i = 0; i < list_size; i++, map_len--) + match &= !((match_array[i] ^ *map++) & mask[i]); + + of_node_put(new); + new = of_find_node_by_phandle(be32_to_cpup(map)); + map++; + map_len--; + + /* Check if not found */ + if (!new) + goto put; + + if (!of_device_is_available(new)) + match = 0; + + ret = of_property_read_u32(new, cells_name, &new_size); + if (ret) + goto put; + + /* Check for malformed properties */ + if (WARN_ON(new_size > MAX_PHANDLE_ARGS)) + goto put; + if (map_len < new_size) + goto put; + + /* Move forward by new node's #-cells amount */ + map += new_size; + map_len -= new_size; + } + if (!match) + goto put; + + /* Get the -map-pass-thru property (optional) */ + pass = of_get_property(cur, pass_name, NULL); + if (!pass) + pass = dummy_pass; + + /* + * Successfully parsed a -map translation; copy new + * specifier into the out_args structure, keeping the + * bits specified in -map-pass-thru. + */ + match_array = map - new_size; + for (i = 0; i < new_size; i++) { + __be32 val = *(map - new_size + i); + + if (i < list_size) { + val &= ~pass[i]; + val |= cpu_to_be32(out_args->args[i]) & pass[i]; + } + + out_args->args[i] = be32_to_cpu(val); + } + out_args->args_count = list_size = new_size; + /* Iterate again with new provider */ + out_args->np = new; + of_node_put(cur); + cur = new; + } +put: + of_node_put(cur); + of_node_put(new); +free: + kfree(mask_name); + kfree(map_name); + kfree(cells_name); + kfree(pass_name); + + return ret; +} +EXPORT_SYMBOL(of_parse_phandle_with_args_map); + +/** * of_parse_phandle_with_fixed_args() - Find a node pointed by phandle in a list * @np: pointer to a device tree node containing a list * @list_name: property name that contains a list diff --git a/include/linux/of.h b/include/linux/of.h index 011c4984cdf5..f22d4a83ca07 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -344,6 +344,9 @@ extern struct device_node *of_parse_phandle(const struct device_node *np, extern int of_parse_phandle_with_args(const struct device_node *np, const char *list_name, const char *cells_name, int index, struct of_phandle_args *out_args); +extern int of_parse_phandle_with_args_map(const struct device_node *np, + const char *list_name, const char *stem_name, int index, + struct of_phandle_args *out_args); extern int of_parse_phandle_with_fixed_args(const struct device_node *np, const char *list_name, int cells_count, int index, struct of_phandle_args *out_args); @@ -738,6 +741,15 @@ static inline int of_parse_phandle_with_args(const struct device_node *np, return -ENOSYS; } +static inline int of_parse_phandle_with_args_map(const struct device_node *np, + const char *list_name, + const char *stem_name, + int index, + struct of_phandle_args *out_args) +{ + return -ENOSYS; +} + static inline int of_parse_phandle_with_fixed_args(const struct device_node *np, const char *list_name, int cells_count, int index, struct of_phandle_args *out_args) From patchwork Mon Jan 23 20:48:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 92275 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1408596qgi; Mon, 23 Jan 2017 12:49:43 -0800 (PST) X-Received: by 10.84.231.203 with SMTP id g11mr46050221pln.165.1485204583731; Mon, 23 Jan 2017 12:49:43 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t12si16730390pfj.24.2017.01.23.12.49.43; Mon, 23 Jan 2017 12:49:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751770AbdAWUtP (ORCPT + 25 others); Mon, 23 Jan 2017 15:49:15 -0500 Received: from mail-pf0-f180.google.com ([209.85.192.180]:35154 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751497AbdAWUs4 (ORCPT ); Mon, 23 Jan 2017 15:48:56 -0500 Received: by mail-pf0-f180.google.com with SMTP id f144so43813082pfa.2 for ; Mon, 23 Jan 2017 12:48:56 -0800 (PST) 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=zwfKuzSY3qii9/LghxrYRbMXc9WB/0oMPxooXMLftcw=; b=bbWv5w4EPvY0YSeEhDfkgsW8GCw8vg9Qlga50p7EhQMtHnV5JYGx7cUNu9CJJJ4a5T 13VrHaToMkOlhdNSzjUhqk+ZvqYsAaFBtfDntxfKYK64DN/899+RibSZr0SSP7zVgj79 5EyM9zfYuSl9wRT2CoyEQbtoZxcZcLu08I+H4= 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=zwfKuzSY3qii9/LghxrYRbMXc9WB/0oMPxooXMLftcw=; b=GjOW2bEswpY8D6zf0hKPsJSldKx1XGRfU6tKVaSIuH25imTJnCAm4KOKwvampdmWj9 1dlR9Wvkc62ztknOm6fY5FmJo/z8leQJ+HbKEFQRN8hVAHOvgB0C8p6yFaCFegxLtGeD QOlKQDpe9csPCC78jZshRjMKXEpOvc+Jci26tQf1piYFQek1yTI23gVnfsAy5cJRQ+7C m29DbBaP5Pc+l+XPyD67yA/4qMmt17s6CBhib1DwfGHfTKLlI/S2VQu+jFkqT+r6h/cE 4cvD1Os4JPCB7c5A1uGP4yWVsmIAaUfBxnQDKL6NPGV2YJOzSUox+uZnWN6wEKdr8+oe cUrA== X-Gm-Message-State: AIkVDXLMETJ6d90u4/pVgMtQWgosBkwMbfZG6R+11+U5CSJvXxR8ui2k2gprX7SbtAaBj4G/ X-Received: by 10.98.18.217 with SMTP id 86mr34306133pfs.90.1485204535518; Mon, 23 Jan 2017 12:48:55 -0800 (PST) Received: from localhost.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id l12sm38935728pfj.37.2017.01.23.12.48.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Jan 2017 12:48:54 -0800 (PST) From: Stephen Boyd To: Rob Herring , Frank Rowand Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, Pantelis Antoniou , Linus Walleij , Mark Brown Subject: [PATCH v3 2/3] of: unittest: Add phandle remapping test Date: Mon, 23 Jan 2017 12:48:50 -0800 Message-Id: <20170123204851.12808-3-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.10.0.297.gf6727b0 In-Reply-To: <20170123204851.12808-1-stephen.boyd@linaro.org> References: <20170123204851.12808-1-stephen.boyd@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Test the functionality of of_parse_phandle_with_args_map(). Cc: Pantelis Antoniou Cc: Linus Walleij Cc: Mark Brown Signed-off-by: Stephen Boyd --- drivers/of/unittest-data/testcases.dts | 11 +++ drivers/of/unittest-data/tests-phandle.dtsi | 25 ++++++ drivers/of/unittest.c | 120 ++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+) -- 2.10.0.297.gf6727b0 diff --git a/drivers/of/unittest-data/testcases.dts b/drivers/of/unittest-data/testcases.dts index 12f7c3d649c8..173b96f39cd0 100644 --- a/drivers/of/unittest-data/testcases.dts +++ b/drivers/of/unittest-data/testcases.dts @@ -26,12 +26,23 @@ / { __local_fixups__ { testcase-data { phandle-tests { + provider4 { + phandle-map = <0x00000008 0x00000018 + 0x00000024 0x0000003c + 0x00000050 0x00000064>; + }; consumer-a { phandle-list = <0x00000000 0x00000008 0x00000018 0x00000028 0x00000034 0x00000038>; phandle-list-bad-args = <0x00000000 0x0000000c>; }; + consumer-b { + phandle-list = <0x00000000 0x00000008 + 0x00000018 0x00000024 + 0x00000030 0x00000034>; + phandle-list-bad-args = <0x00000000 0x0000000c>; + }; }; interrupts { intmap0 { diff --git a/drivers/of/unittest-data/tests-phandle.dtsi b/drivers/of/unittest-data/tests-phandle.dtsi index 5b1527e8a7fb..59e297f497d1 100644 --- a/drivers/of/unittest-data/tests-phandle.dtsi +++ b/drivers/of/unittest-data/tests-phandle.dtsi @@ -25,6 +25,18 @@ #phandle-cells = <3>; }; + provider4: provider4 { + #phandle-cells = <2>; + phandle-map = <0 1 &provider1 3>, + <4 0 &provider0>, + <16 5 &provider3 3 5 0>, + <200 8 &provider2 23 6>, + <19 0 &provider2 15 0>, + <2 3 &provider3 2 5 3>; + phandle-map-mask = <0xff 0xf>; + phandle-map-pass-thru = <0x0 0xf0>; + }; + consumer-a { phandle-list = <&provider1 1>, <&provider2 2 0>, @@ -43,6 +55,19 @@ unterminated-string = [40 41 42 43]; unterminated-string-list = "first", "second", [40 41 42 43]; }; + + consumer-b { + phandle-list = <&provider1 1>, + <&provider4 2 3>, + <0>, + <&provider4 4 0x100>, + <&provider4 0 0x61>, + <&provider0>, + <&provider4 19 0x20>; + phandle-list-bad-phandle = <12345678 0 0>; + phandle-list-bad-args = <&provider2 1 0>, + <&provider4 0>; + }; }; }; }; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 53c83d66eb7e..5baa40d0d83b 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -386,6 +386,125 @@ static void __init of_unittest_parse_phandle_with_args(void) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); } +static void __init of_unittest_parse_phandle_with_args_map(void) +{ + struct device_node *np, *p0, *p1, *p2, *p3; + struct of_phandle_args args; + int i, rc; + + np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-b"); + if (!np) { + pr_err("missing testcase data\n"); + return; + } + + p0 = of_find_node_by_path("/testcase-data/phandle-tests/provider0"); + if (!p0) { + pr_err("missing testcase data\n"); + return; + } + + p1 = of_find_node_by_path("/testcase-data/phandle-tests/provider1"); + if (!p1) { + pr_err("missing testcase data\n"); + return; + } + + p2 = of_find_node_by_path("/testcase-data/phandle-tests/provider2"); + if (!p2) { + pr_err("missing testcase data\n"); + return; + } + + p3 = of_find_node_by_path("/testcase-data/phandle-tests/provider3"); + if (!p3) { + pr_err("missing testcase data\n"); + return; + } + + rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells"); + unittest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc); + + for (i = 0; i < 8; i++) { + bool passed = true; + + rc = of_parse_phandle_with_args_map(np, "phandle-list", + "phandle", i, &args); + + /* Test the values from tests-phandle.dtsi */ + switch (i) { + case 0: + passed &= !rc; + passed &= (args.np == p1); + passed &= (args.args_count == 1); + passed &= (args.args[0] == 1); + break; + case 1: + passed &= !rc; + passed &= (args.np == p3); + passed &= (args.args_count == 3); + passed &= (args.args[0] == 2); + passed &= (args.args[1] == 5); + passed &= (args.args[2] == 3); + break; + case 2: + passed &= (rc == -ENOENT); + break; + case 3: + passed &= !rc; + passed &= (args.np == p0); + passed &= (args.args_count == 0); + break; + case 4: + passed &= !rc; + passed &= (args.np == p1); + passed &= (args.args_count == 1); + passed &= (args.args[0] == 3); + break; + case 5: + passed &= !rc; + passed &= (args.np == p0); + passed &= (args.args_count == 0); + break; + case 6: + passed &= !rc; + passed &= (args.np == p2); + passed &= (args.args_count == 2); + passed &= (args.args[0] == 15); + passed &= (args.args[1] == 0x20); + break; + case 7: + passed &= (rc == -ENOENT); + break; + default: + passed = false; + } + + unittest(passed, "index %i - data error on node %s rc=%i\n", + i, args.np->full_name, rc); + } + + /* Check for missing list property */ + rc = of_parse_phandle_with_args_map(np, "phandle-list-missing", + "phandle", 0, &args); + unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); + + /* Check for missing cells,map,mask property */ + rc = of_parse_phandle_with_args_map(np, "phandle-list", + "phandle-missing", 0, &args); + unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); + + /* Check for bad phandle in list */ + rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle", + "phandle", 0, &args); + unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); + + /* Check for incorrectly formed argument list */ + rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args", + "phandle", 1, &args); + unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); +} + static void __init of_unittest_property_string(void) { const char *strings[4]; @@ -1951,6 +2070,7 @@ static int __init of_unittest(void) of_unittest_find_node_by_name(); of_unittest_dynamic(); of_unittest_parse_phandle_with_args(); + of_unittest_parse_phandle_with_args_map(); of_unittest_property_string(); of_unittest_property_copy(); of_unittest_changeset(); From patchwork Mon Jan 23 20:48:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 92274 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1408419qgi; Mon, 23 Jan 2017 12:49:04 -0800 (PST) X-Received: by 10.84.171.195 with SMTP id l61mr45557083plb.84.1485204544566; Mon, 23 Jan 2017 12:49:04 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h5si16680513pgf.209.2017.01.23.12.49.04; Mon, 23 Jan 2017 12:49:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751691AbdAWUs7 (ORCPT + 7 others); Mon, 23 Jan 2017 15:48:59 -0500 Received: from mail-pg0-f54.google.com ([74.125.83.54]:33289 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751678AbdAWUs5 (ORCPT ); Mon, 23 Jan 2017 15:48:57 -0500 Received: by mail-pg0-f54.google.com with SMTP id 204so47879804pge.0 for ; Mon, 23 Jan 2017 12:48:57 -0800 (PST) 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=jN9uW6vO7fZgpUrj/RYCqT5gzW41hafz/MKcIK4IrVY=; b=F+iU4jAaHiikxvp5neoKdfO5JeP7Xs6MSjzQA2BR56fV8OzdTjeRaDgRSqhB3IS1tK XxKELwvVApc+1nozDomQiPllAZ2w7LrpPmxIGeBY7h8fdWA2Bvzjbry2udOf2XGo67Ej w2moRdRC/BNdPdqai9P/R965rerJzd+mnvrQ8= 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=jN9uW6vO7fZgpUrj/RYCqT5gzW41hafz/MKcIK4IrVY=; b=HwVygpt+cAxvwrGrB3/DFGWxKvdWQQbjDjJspzV6EGi12zQvQ62K61wfPuDH67j/mn PA2ckD7kK8fG/b/gPqnFUaXKnPxMuh7sSrYIxOB0xo8jnMkBYqGS3GdUAbnE28EKMC/E /M2okJbgZDCG/d9tj7vzmBXUXcS9qylj5D08FpchHlkZqXOYkS3ZeWBbfNoEdB85eJYT B2iqZ113zIAXQ55F907UK+t+oRF5HgnOqqUiRHR6JZpB5b4xu5B0B4J49PHzAG/XHS6K cbA8hSzIQ6Gmv5gdiiAt+cty/3nYgd6F/s6fxuOMdHBtn6pA7nN5X41T+CNrwOowOF80 mEKA== X-Gm-Message-State: AIkVDXLjleWBPKmQX0u8GhbpSVU4EnrKeXzQtaBybIg1Y6QKm3R1TIqwXAIF9IUW6Bb0oVTK X-Received: by 10.98.152.218 with SMTP id d87mr33824265pfk.17.1485204536659; Mon, 23 Jan 2017 12:48:56 -0800 (PST) Received: from localhost.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id l12sm38935728pfj.37.2017.01.23.12.48.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Jan 2017 12:48:56 -0800 (PST) From: Stephen Boyd To: Rob Herring , Frank Rowand Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, Pantelis Antoniou , Mark Brown Subject: [PATCH v3 3/3] gpio: Support gpio nexus dt bindings Date: Mon, 23 Jan 2017 12:48:51 -0800 Message-Id: <20170123204851.12808-4-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.10.0.297.gf6727b0 In-Reply-To: <20170123204851.12808-1-stephen.boyd@linaro.org> References: <20170123204851.12808-1-stephen.boyd@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Platforms like 96boards have a standardized connector/expansion slot that exposes signals like GPIOs to expansion boards in an SoC agnostic way. We'd like the DT overlays for the expansion boards to be written once without knowledge of the SoC on the other side of the connector. This avoids the unscalable combinatorial explosion of a different DT overlay for each expansion board and SoC pair. Now that we have nexus support in the OF core let's change the function call here that parses the phandle lists of gpios to use the nexus variant. This allows us to remap phandles and their arguments through any number of nexus nodes and end up with the actual gpio provider being used. Cc: Pantelis Antoniou Acked-by: Linus Walleij Cc: Mark Brown Signed-off-by: Stephen Boyd --- drivers/gpio/gpiolib-of.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.10.0.297.gf6727b0 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 92b185f19232..17bca36d4ebb 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -75,8 +75,8 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, struct gpio_desc *desc; int ret; - ret = of_parse_phandle_with_args(np, propname, "#gpio-cells", index, - &gpiospec); + ret = of_parse_phandle_with_args_map(np, propname, "gpio", index, + &gpiospec); if (ret) { pr_debug("%s: can't parse '%s' property of node '%s[%d]'\n", __func__, propname, np->full_name, index);