@@ -1101,17 +1101,11 @@ static struct device_node *parse_prop_cells(struct device_node *np,
1101
1101
return sup_args .np ;
1102
1102
}
1103
1103
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); \
1115
1109
}
1116
1110
1117
1111
static int strcmp_suffix (const char * str , const char * suffix )
@@ -1125,13 +1119,47 @@ static int strcmp_suffix(const char *str, const char *suffix)
1125
1119
return strcmp (str + len - suffix_len , suffix );
1126
1120
}
1127
1121
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 )
1130
1145
{
1131
- if (index || strcmp_suffix (prop_name , "-supply" ))
1146
+ struct of_phandle_args sup_args ;
1147
+
1148
+ if (strcmp_suffix (prop_name , suffix ))
1132
1149
return NULL ;
1133
1150
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); \
1135
1163
}
1136
1164
1137
1165
/**
@@ -1155,6 +1183,10 @@ struct supplier_bindings {
1155
1183
const char * prop_name , int index );
1156
1184
};
1157
1185
1186
+ DEFINE_SIMPLE_PROP (clocks , "clocks" , "#clock-cells" )
1187
+ DEFINE_SIMPLE_PROP (interconnects , "interconnects" , "#interconnect-cells" )
1188
+ DEFINE_SUFFIX_PROP (regulators , "-supply" , NULL )
1189
+
1158
1190
static const struct supplier_bindings of_supplier_bindings [] = {
1159
1191
{ .parse_prop = parse_clocks , },
1160
1192
{ .parse_prop = parse_interconnects , },
0 commit comments