Skip to content

Commit a436ef4

Browse files
Saravana Kannangregkh
authored andcommitted
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 <[email protected]> Reviewed-by: Rob Herring <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ba861f8 commit a436ef4

File tree

1 file changed

+47
-15
lines changed

1 file changed

+47
-15
lines changed

drivers/of/property.c

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,17 +1101,11 @@ static struct device_node *parse_prop_cells(struct device_node *np,
11011101
return sup_args.np;
11021102
}
11031103

1104-
static struct device_node *parse_clocks(struct device_node *np,
1105-
const char *prop_name, int index)
1106-
{
1107-
return parse_prop_cells(np, prop_name, index, "clocks", "#clock-cells");
1108-
}
1109-
1110-
static struct device_node *parse_interconnects(struct device_node *np,
1111-
const char *prop_name, int index)
1112-
{
1113-
return parse_prop_cells(np, prop_name, index, "interconnects",
1114-
"#interconnect-cells");
1104+
#define DEFINE_SIMPLE_PROP(fname, name, cells) \
1105+
static struct device_node *parse_##fname(struct device_node *np, \
1106+
const char *prop_name, int index) \
1107+
{ \
1108+
return parse_prop_cells(np, prop_name, index, name, cells); \
11151109
}
11161110

11171111
static int strcmp_suffix(const char *str, const char *suffix)
@@ -1125,13 +1119,47 @@ static int strcmp_suffix(const char *str, const char *suffix)
11251119
return strcmp(str + len - suffix_len, suffix);
11261120
}
11271121

1128-
static struct device_node *parse_regulators(struct device_node *np,
1129-
const char *prop_name, int index)
1122+
/**
1123+
* parse_suffix_prop_cells - Suffix property parsing function for suppliers
1124+
*
1125+
* @np: Pointer to device tree node containing a list
1126+
* @prop_name: Name of property to be parsed. Expected to hold phandle values
1127+
* @index: For properties holding a list of phandles, this is the index
1128+
* into the list.
1129+
* @suffix: Property suffix that is known to contain list of phandle(s) to
1130+
* supplier(s)
1131+
* @cells_name: property name that specifies phandles' arguments count
1132+
*
1133+
* This is a helper function to parse properties that have a known fixed suffix
1134+
* and are a list of phandles and phandle arguments.
1135+
*
1136+
* Returns:
1137+
* - phandle node pointer with refcount incremented. Caller must of_node_put()
1138+
* on it when done.
1139+
* - NULL if no phandle found at index
1140+
*/
1141+
static struct device_node *parse_suffix_prop_cells(struct device_node *np,
1142+
const char *prop_name, int index,
1143+
const char *suffix,
1144+
const char *cells_name)
11301145
{
1131-
if (index || strcmp_suffix(prop_name, "-supply"))
1146+
struct of_phandle_args sup_args;
1147+
1148+
if (strcmp_suffix(prop_name, suffix))
11321149
return NULL;
11331150

1134-
return of_parse_phandle(np, prop_name, 0);
1151+
if (of_parse_phandle_with_args(np, prop_name, cells_name, index,
1152+
&sup_args))
1153+
return NULL;
1154+
1155+
return sup_args.np;
1156+
}
1157+
1158+
#define DEFINE_SUFFIX_PROP(fname, suffix, cells) \
1159+
static struct device_node *parse_##fname(struct device_node *np, \
1160+
const char *prop_name, int index) \
1161+
{ \
1162+
return parse_suffix_prop_cells(np, prop_name, index, suffix, cells); \
11351163
}
11361164

11371165
/**
@@ -1155,6 +1183,10 @@ struct supplier_bindings {
11551183
const char *prop_name, int index);
11561184
};
11571185

1186+
DEFINE_SIMPLE_PROP(clocks, "clocks", "#clock-cells")
1187+
DEFINE_SIMPLE_PROP(interconnects, "interconnects", "#interconnect-cells")
1188+
DEFINE_SUFFIX_PROP(regulators, "-supply", NULL)
1189+
11581190
static const struct supplier_bindings of_supplier_bindings[] = {
11591191
{ .parse_prop = parse_clocks, },
11601192
{ .parse_prop = parse_interconnects, },

0 commit comments

Comments
 (0)