summaryrefslogtreecommitdiff
path: root/drivers/of
diff options
context:
space:
mode:
authorSaravana Kannan <saravanak@google.com>2019-11-04 22:49:59 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-11-07 09:42:04 +0100
commita436ef4aba1f011fa25f35fe7922d577ecde6c7c (patch)
tree56c59cd601cc8351a8a64d68d365bed281a15957 /drivers/of
parentba861f8e07bf38c457b98e1abf6ecd9fd8c4ee92 (diff)
of: property: Make it easy to add device links from DT properties
Add a DEFINE_SIMPLE_PROP macro to make it easy to add support for simple properties with fixed names that just list phandles and phandle args. Add a DEFINE_SUFFIX_PROP macro to make it easy to add support for properties with fixes suffix that just list phandles and phandle args. Signed-off-by: Saravana Kannan <saravanak@google.com> Reviewed-by: Rob Herring <robh@kernel.org> Link: https://lore.kernel.org/r/20191105065000.50407-3-saravanak@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/property.c62
1 files changed, 47 insertions, 15 deletions
diff --git a/drivers/of/property.c b/drivers/of/property.c
index fbc201330ba0..812b69a029d1 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -1101,17 +1101,11 @@ static struct device_node *parse_prop_cells(struct device_node *np,
return sup_args.np;
}
-static struct device_node *parse_clocks(struct device_node *np,
- const char *prop_name, int index)
-{
- return parse_prop_cells(np, prop_name, index, "clocks", "#clock-cells");
-}
-
-static struct device_node *parse_interconnects(struct device_node *np,
- const char *prop_name, int index)
-{
- return parse_prop_cells(np, prop_name, index, "interconnects",
- "#interconnect-cells");
+#define DEFINE_SIMPLE_PROP(fname, name, cells) \
+static struct device_node *parse_##fname(struct device_node *np, \
+ const char *prop_name, int index) \
+{ \
+ return parse_prop_cells(np, prop_name, index, name, cells); \
}
static int strcmp_suffix(const char *str, const char *suffix)
@@ -1125,13 +1119,47 @@ static int strcmp_suffix(const char *str, const char *suffix)
return strcmp(str + len - suffix_len, suffix);
}
-static struct device_node *parse_regulators(struct device_node *np,
- const char *prop_name, int index)
+/**
+ * parse_suffix_prop_cells - Suffix property parsing function for suppliers
+ *
+ * @np: Pointer to device tree node containing a list
+ * @prop_name: Name of property to be parsed. Expected to hold phandle values
+ * @index: For properties holding a list of phandles, this is the index
+ * into the list.
+ * @suffix: Property suffix that is known to contain list of phandle(s) to
+ * supplier(s)
+ * @cells_name: property name that specifies phandles' arguments count
+ *
+ * This is a helper function to parse properties that have a known fixed suffix
+ * and are a list of phandles and phandle arguments.
+ *
+ * Returns:
+ * - phandle node pointer with refcount incremented. Caller must of_node_put()
+ * on it when done.
+ * - NULL if no phandle found at index
+ */
+static struct device_node *parse_suffix_prop_cells(struct device_node *np,
+ const char *prop_name, int index,
+ const char *suffix,
+ const char *cells_name)
{
- if (index || strcmp_suffix(prop_name, "-supply"))
+ struct of_phandle_args sup_args;
+
+ if (strcmp_suffix(prop_name, suffix))
return NULL;
- return of_parse_phandle(np, prop_name, 0);
+ if (of_parse_phandle_with_args(np, prop_name, cells_name, index,
+ &sup_args))
+ return NULL;
+
+ return sup_args.np;
+}
+
+#define DEFINE_SUFFIX_PROP(fname, suffix, cells) \
+static struct device_node *parse_##fname(struct device_node *np, \
+ const char *prop_name, int index) \
+{ \
+ return parse_suffix_prop_cells(np, prop_name, index, suffix, cells); \
}
/**
@@ -1155,6 +1183,10 @@ struct supplier_bindings {
const char *prop_name, int index);
};
+DEFINE_SIMPLE_PROP(clocks, "clocks", "#clock-cells")
+DEFINE_SIMPLE_PROP(interconnects, "interconnects", "#interconnect-cells")
+DEFINE_SUFFIX_PROP(regulators, "-supply", NULL)
+
static const struct supplier_bindings of_supplier_bindings[] = {
{ .parse_prop = parse_clocks, },
{ .parse_prop = parse_interconnects, },