diff options
author | Stephen Warren <swarren@nvidia.com> | 2013-08-14 17:27:10 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@linaro.org> | 2013-08-29 16:40:22 -0400 |
commit | 035fd9482274bf43858b00e0ff95179af66df8e8 (patch) | |
tree | 10a583399952ff1cd821e464f409ac1b0f16f650 /drivers/of/base.c | |
parent | 5fba49e3a8c22a7bb71c3526ec32b373b3ef32b8 (diff) |
of: introduce of_parse_phandle_with_fixed_args
This is identical to of_parse_phandle_with_args(), except that the
number of argument cells is fixed, rather than being parsed out of the
node referenced by each phandle.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Grant Likely <grant.likely@linaro.org>
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r-- | drivers/of/base.c | 66 |
1 files changed, 58 insertions, 8 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index ef2f1d0dd80a..1f80acf4c16a 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -1082,7 +1082,8 @@ EXPORT_SYMBOL_GPL(of_property_count_strings); | |||
1082 | 1082 | ||
1083 | static int __of_parse_phandle_with_args(const struct device_node *np, | 1083 | static int __of_parse_phandle_with_args(const struct device_node *np, |
1084 | const char *list_name, | 1084 | const char *list_name, |
1085 | const char *cells_name, int index, | 1085 | const char *cells_name, |
1086 | int cell_count, int index, | ||
1086 | struct of_phandle_args *out_args) | 1087 | struct of_phandle_args *out_args) |
1087 | { | 1088 | { |
1088 | const __be32 *list, *list_end; | 1089 | const __be32 *list, *list_end; |
@@ -1118,11 +1119,17 @@ static int __of_parse_phandle_with_args(const struct device_node *np, | |||
1118 | np->full_name); | 1119 | np->full_name); |
1119 | goto err; | 1120 | goto err; |
1120 | } | 1121 | } |
1121 | if (of_property_read_u32(node, cells_name, &count)) { | 1122 | |
1122 | pr_err("%s: could not get %s for %s\n", | 1123 | if (cells_name) { |
1123 | np->full_name, cells_name, | 1124 | if (of_property_read_u32(node, cells_name, |
1124 | node->full_name); | 1125 | &count)) { |
1125 | goto err; | 1126 | pr_err("%s: could not get %s for %s\n", |
1127 | np->full_name, cells_name, | ||
1128 | node->full_name); | ||
1129 | goto err; | ||
1130 | } | ||
1131 | } else { | ||
1132 | count = cell_count; | ||
1126 | } | 1133 | } |
1127 | 1134 | ||
1128 | /* | 1135 | /* |
@@ -1244,11 +1251,53 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na | |||
1244 | { | 1251 | { |
1245 | if (index < 0) | 1252 | if (index < 0) |
1246 | return -EINVAL; | 1253 | return -EINVAL; |
1247 | return __of_parse_phandle_with_args(np, list_name, cells_name, index, out_args); | 1254 | return __of_parse_phandle_with_args(np, list_name, cells_name, 0, |
1255 | index, out_args); | ||
1248 | } | 1256 | } |
1249 | EXPORT_SYMBOL(of_parse_phandle_with_args); | 1257 | EXPORT_SYMBOL(of_parse_phandle_with_args); |
1250 | 1258 | ||
1251 | /** | 1259 | /** |
1260 | * of_parse_phandle_with_fixed_args() - Find a node pointed by phandle in a list | ||
1261 | * @np: pointer to a device tree node containing a list | ||
1262 | * @list_name: property name that contains a list | ||
1263 | * @cell_count: number of argument cells following the phandle | ||
1264 | * @index: index of a phandle to parse out | ||
1265 | * @out_args: optional pointer to output arguments structure (will be filled) | ||
1266 | * | ||
1267 | * This function is useful to parse lists of phandles and their arguments. | ||
1268 | * Returns 0 on success and fills out_args, on error returns appropriate | ||
1269 | * errno value. | ||
1270 | * | ||
1271 | * Caller is responsible to call of_node_put() on the returned out_args->node | ||
1272 | * pointer. | ||
1273 | * | ||
1274 | * Example: | ||
1275 | * | ||
1276 | * phandle1: node1 { | ||
1277 | * } | ||
1278 | * | ||
1279 | * phandle2: node2 { | ||
1280 | * } | ||
1281 | * | ||
1282 | * node3 { | ||
1283 | * list = <&phandle1 0 2 &phandle2 2 3>; | ||
1284 | * } | ||
1285 | * | ||
1286 | * To get a device_node of the `node2' node you may call this: | ||
1287 | * of_parse_phandle_with_fixed_args(node3, "list", 2, 1, &args); | ||
1288 | */ | ||
1289 | int of_parse_phandle_with_fixed_args(const struct device_node *np, | ||
1290 | const char *list_name, int cell_count, | ||
1291 | int index, struct of_phandle_args *out_args) | ||
1292 | { | ||
1293 | if (index < 0) | ||
1294 | return -EINVAL; | ||
1295 | return __of_parse_phandle_with_args(np, list_name, NULL, cell_count, | ||
1296 | index, out_args); | ||
1297 | } | ||
1298 | EXPORT_SYMBOL(of_parse_phandle_with_fixed_args); | ||
1299 | |||
1300 | /** | ||
1252 | * of_count_phandle_with_args() - Find the number of phandles references in a property | 1301 | * of_count_phandle_with_args() - Find the number of phandles references in a property |
1253 | * @np: pointer to a device tree node containing a list | 1302 | * @np: pointer to a device tree node containing a list |
1254 | * @list_name: property name that contains a list | 1303 | * @list_name: property name that contains a list |
@@ -1266,7 +1315,8 @@ EXPORT_SYMBOL(of_parse_phandle_with_args); | |||
1266 | int of_count_phandle_with_args(const struct device_node *np, const char *list_name, | 1315 | int of_count_phandle_with_args(const struct device_node *np, const char *list_name, |
1267 | const char *cells_name) | 1316 | const char *cells_name) |
1268 | { | 1317 | { |
1269 | return __of_parse_phandle_with_args(np, list_name, cells_name, -1, NULL); | 1318 | return __of_parse_phandle_with_args(np, list_name, cells_name, 0, -1, |
1319 | NULL); | ||
1270 | } | 1320 | } |
1271 | EXPORT_SYMBOL(of_count_phandle_with_args); | 1321 | EXPORT_SYMBOL(of_count_phandle_with_args); |
1272 | 1322 | ||