b829f21cfacf2b2aa07b06eb2fa6eee98902a24e
[openwrt/staging/jogo.git] /
1 From 8eddceb280f5deb8046fcb660de9f9f683b408b9 Mon Sep 17 00:00:00 2001
2 From: Michael Walle <michael@walle.cc>
3 Date: Tue, 6 Dec 2022 21:07:21 +0100
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 ---
20 include/linux/of.h | 25 +++++++++++++++++++++++++
21 1 file changed, 25 insertions(+)
22
23 --- a/include/linux/of.h
24 +++ b/include/linux/of.h
25 @@ -1169,6 +1169,31 @@ static inline int of_parse_phandle_with_
26 }
27
28 /**
29 + * of_parse_phandle_with_optional_args() - Find a node pointed by phandle in a list
30 + * @np: pointer to a device tree node containing a list
31 + * @list_name: property name that contains a list
32 + * @cells_name: property name that specifies phandles' arguments count
33 + * @index: index of a phandle to parse out
34 + * @out_args: optional pointer to output arguments structure (will be filled)
35 + *
36 + * Same as of_parse_phandle_with_args() except that if the cells_name property
37 + * is not found, cell_count of 0 is assumed.
38 + *
39 + * This is used to useful, if you have a phandle which didn't have arguments
40 + * before and thus doesn't have a '#*-cells' property but is now migrated to
41 + * having arguments while retaining backwards compatibility.
42 + */
43 +static inline int of_parse_phandle_with_optional_args(const struct device_node *np,
44 + const char *list_name,
45 + const char *cells_name,
46 + int index,
47 + struct of_phandle_args *out_args)
48 +{
49 + return __of_parse_phandle_with_args(np, list_name, cells_name,
50 + 0, index, out_args);
51 +}
52 +
53 +/**
54 * of_property_count_u8_elems - Count the number of u8 elements in a property
55 *
56 * @np: device node from which the property value is to be read.