Message ID | 1499043558-9336-4-git-send-email-andre.przywara@arm.com |
---|---|
State | Superseded |
Delegated to: | Jagannadha Sutradharudu Teki |
Headers | show |
Hi Andre, On 2 July 2017 at 18:59, Andre Przywara <andre.przywara@arm.com> wrote: > In some bindings a property points to multiple nodes, using a list of > phandles. A prominent example are UART pinctrl nodes, which use one node > to contain the RX/TX pins and another node to describe the lines used > for the hardware handshake. > The current fdtdec_lookup_phandle() helper function to chase a phandle > is quite convienent, but can only lookup the first of those handles. > > Introduce an extra function fdtdec_lookup_phandle_index() to take an > index parameter and implement fdtdec_lookup_phandle() as a special case > of that. > > Signed-off-by: Andre Przywara <andre.przywara@arm.com> > --- > include/fdtdec.h | 12 ++++++++++++ > lib/fdtdec.c | 16 ++++++++++++---- > 2 files changed, 24 insertions(+), 4 deletions(-) Can you please: - Add a dev_read... version of this API - Also ofnode_... so that we can support livetree. Regards, Simon
On 07/07/17 04:58, Simon Glass wrote: Hi Simon, > On 2 July 2017 at 18:59, Andre Przywara <andre.przywara@arm.com> wrote: >> In some bindings a property points to multiple nodes, using a list of >> phandles. A prominent example are UART pinctrl nodes, which use one node >> to contain the RX/TX pins and another node to describe the lines used >> for the hardware handshake. >> The current fdtdec_lookup_phandle() helper function to chase a phandle >> is quite convienent, but can only lookup the first of those handles. >> >> Introduce an extra function fdtdec_lookup_phandle_index() to take an >> index parameter and implement fdtdec_lookup_phandle() as a special case >> of that. >> >> Signed-off-by: Andre Przywara <andre.przywara@arm.com> >> --- >> include/fdtdec.h | 12 ++++++++++++ >> lib/fdtdec.c | 16 ++++++++++++---- >> 2 files changed, 24 insertions(+), 4 deletions(-) > > Can you please: > > - Add a dev_read... version of this API > - Also ofnode_... Mmmh, I am not sure I follow here. I find that both dev_read_phandle_with_args() and ofnode_parse_phandle_with_args() take an index parameter already and from briefly looking at the code seem to do the right thing already. So I guess that's not what you meant? What am I missing? Cheers, Andre.
diff --git a/include/fdtdec.h b/include/fdtdec.h index eda2ffa..529e0fe 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -650,6 +650,18 @@ int fdtdec_get_chosen_node(const void *blob, const char *name); */ const char *fdtdec_get_compatible(enum fdt_compat_id id); +/* Look up a phandle with a given index and follow it to its node. + * Then return the offset of that node. + * + * @param blob FDT blob + * @param node node to examine + * @param prop_name name of property to find + * @param index index of the desired phandle in the list + * @return node offset if found, -ve error code on error + */ +int fdtdec_lookup_phandle_index(const void *blob, int node, + const char *prop_name, int index); + /* Look up a phandle and follow it to its node. Then return the offset * of that node. * diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 91503b8..e028a09 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -617,20 +617,28 @@ int fdtdec_prepare_fdt(void) return 0; } -int fdtdec_lookup_phandle(const void *blob, int node, const char *prop_name) +int fdtdec_lookup_phandle_index(const void *blob, int node, + const char *prop_name, int index) { const u32 *phandle; int lookup; + int length; debug("%s: %s\n", __func__, prop_name); - phandle = fdt_getprop(blob, node, prop_name, NULL); - if (!phandle) + phandle = fdt_getprop(blob, node, prop_name, &length); + if (!phandle || index * 4 >= length) return -FDT_ERR_NOTFOUND; - lookup = fdt_node_offset_by_phandle(blob, fdt32_to_cpu(*phandle)); + lookup = fdt_node_offset_by_phandle(blob, + fdt32_to_cpu(phandle[index])); return lookup; } +int fdtdec_lookup_phandle(const void *blob, int node, const char *prop_name) +{ + return fdtdec_lookup_phandle_index(blob, node, prop_name, 0); +} + /** * Look up a property in a node and check that it has a minimum length. *
In some bindings a property points to multiple nodes, using a list of phandles. A prominent example are UART pinctrl nodes, which use one node to contain the RX/TX pins and another node to describe the lines used for the hardware handshake. The current fdtdec_lookup_phandle() helper function to chase a phandle is quite convienent, but can only lookup the first of those handles. Introduce an extra function fdtdec_lookup_phandle_index() to take an index parameter and implement fdtdec_lookup_phandle() as a special case of that. Signed-off-by: Andre Przywara <andre.przywara@arm.com> --- include/fdtdec.h | 12 ++++++++++++ lib/fdtdec.c | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-)