f568c3f6ce5886a1f89b7d4f5ea43c00b5254d47
[openwrt/staging/xback.git] /
1 From c5d264d4b527c96ae8903376a4b195df47b05203 Mon Sep 17 00:00:00 2001
2 From: Michael Walle <michael@walle.cc>
3 Date: Mon, 6 Feb 2023 13:43:43 +0000
4 Subject: [PATCH] of: base: add of_parse_phandle_with_optional_args()
5
6 Add a new variant of the of_parse_phandle_with_args() which treats the
7 cells name as optional. If it's missing, it is assumed that the phandle
8 has no arguments.
9
10 Up until now, a nvmem node didn't have any arguments, so all the device
11 trees haven't any '#*-cells' property. But there is a need for an
12 additional argument for the phandle, for which we need a '#*-cells'
13 property. Therefore, we need to support nvmem nodes with and without
14 this property.
15
16 Signed-off-by: Michael Walle <michael@walle.cc>
17 Reviewed-by: Rob Herring <robh@kernel.org>
18 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
19 Link: https://lore.kernel.org/r/20230206134356.839737-10-srinivas.kandagatla@linaro.org
20 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21 ---
22 include/linux/of.h | 25 +++++++++++++++++++++++++
23 1 file changed, 25 insertions(+)
24
25 --- a/include/linux/of.h
26 +++ b/include/linux/of.h
27 @@ -1009,6 +1009,31 @@ static inline int of_parse_phandle_with_
28 }
29
30 /**
31 + * of_parse_phandle_with_optional_args() - Find a node pointed by phandle in a list
32 + * @np: pointer to a device tree node containing a list
33 + * @list_name: property name that contains a list
34 + * @cells_name: property name that specifies phandles' arguments count
35 + * @index: index of a phandle to parse out
36 + * @out_args: optional pointer to output arguments structure (will be filled)
37 + *
38 + * Same as of_parse_phandle_with_args() except that if the cells_name property
39 + * is not found, cell_count of 0 is assumed.
40 + *
41 + * This is used to useful, if you have a phandle which didn't have arguments
42 + * before and thus doesn't have a '#*-cells' property but is now migrated to
43 + * having arguments while retaining backwards compatibility.
44 + */
45 +static inline int of_parse_phandle_with_optional_args(const struct device_node *np,
46 + const char *list_name,
47 + const char *cells_name,
48 + int index,
49 + struct of_phandle_args *out_args)
50 +{
51 + return __of_parse_phandle_with_args(np, list_name, cells_name,
52 + 0, index, out_args);
53 +}
54 +
55 +/**
56 * of_property_count_u8_elems - Count the number of u8 elements in a property
57 *
58 * @np: device node from which the property value is to be read.