diff options
author | Simon Glass <sjg@chromium.org> | 2015-01-05 20:05:26 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2015-01-29 17:09:50 -0700 |
commit | 57068a7aeb19fee06933986926eaea3cf0128f16 (patch) | |
tree | 68335b90c13258ce3b87c4efeb0eba992d83b281 /include/fdtdec.h | |
parent | 5cfc662c496a0e52301a9379f91755b1f8fbf368 (diff) | |
download | u-boot-57068a7aeb19fee06933986926eaea3cf0128f16.tar.gz u-boot-57068a7aeb19fee06933986926eaea3cf0128f16.tar.bz2 u-boot-57068a7aeb19fee06933986926eaea3cf0128f16.zip |
dm: fdt: Add a function to decode phandles with arguments
For GPIOs and other functions we want to look up a phandle and then decode
a list of arguments for that phandle. Each phandle can have a different
number of arguments, specified by a property in the target node. This is
the "#gpio-cells" property for GPIOs.
Add a function to provide this feature, taken modified from Linux 3.18.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/fdtdec.h')
-rw-r--r-- | include/fdtdec.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/include/fdtdec.h b/include/fdtdec.h index 8c2bd21b2d..8cf88dd10b 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -178,6 +178,59 @@ enum fdt_compat_id { COMPAT_COUNT, }; +#define MAX_PHANDLE_ARGS 16 +struct fdtdec_phandle_args { + int node; + int args_count; + uint32_t args[MAX_PHANDLE_ARGS]; +}; + +/** + * fdtdec_parse_phandle_with_args() - Find a node pointed by phandle in a list + * + * This function is useful to parse lists of phandles and their arguments. + * + * Example: + * + * phandle1: node1 { + * #list-cells = <2>; + * } + * + * phandle2: node2 { + * #list-cells = <1>; + * } + * + * node3 { + * list = <&phandle1 1 2 &phandle2 3>; + * } + * + * To get a device_node of the `node2' node you may call this: + * fdtdec_parse_phandle_with_args(blob, node3, "list", "#list-cells", 0, 1, + * &args); + * + * (This function is a modified version of __of_parse_phandle_with_args() from + * Linux 3.18) + * + * @blob: Pointer to device tree + * @src_node: Offset of device tree node containing a list + * @list_name: property name that contains a list + * @cells_name: property name that specifies the phandles' arguments count, + * or NULL to use @cells_count + * @cells_count: Cell count to use if @cells_name is NULL + * @index: index of a phandle to parse out + * @out_args: optional pointer to output arguments structure (will be filled) + * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if + * @list_name does not exist, a phandle was not found, @cells_name + * could not be found, the arguments were truncated or there were too + * many arguments. + * + */ +int fdtdec_parse_phandle_with_args(const void *blob, int src_node, + const char *list_name, + const char *cells_name, + int cell_count, int index, + struct fdtdec_phandle_args *out_args); + /* GPIOs are numbered from 0 */ enum { FDT_GPIO_NONE = -1U, /* an invalid GPIO used to end our list */ |