pinctrl: pinconf-generic: scan also referenced phandle node

Make pinconf_generic_dt_node_to_map() also scan the dt pin configuration node
directly referenced by phandle, not only its child nodes.

The "parent scan" feature needs a few other changes:

   * Move the pinconf_generic_dt_node_to_map() error handling code to a common
     place, under the 'exit' label.

   * Move the pins/groups strings count earlier in
     pinconf_generic_dt_subnode_to_map(), to allow us to bail out early when
     these properties are missing or wrong

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
This commit is contained in:
Baruch Siach 2015-03-19 22:17:41 +02:00 коммит произвёл Linus Walleij
Родитель 12149a20b8
Коммит c7289500e2
1 изменённых файлов: 28 добавлений и 20 удалений

Просмотреть файл

@ -283,11 +283,26 @@ int pinconf_generic_dt_subnode_to_map(struct pinctrl_dev *pctldev,
struct device *dev = pctldev->dev; struct device *dev = pctldev->dev;
unsigned long *configs = NULL; unsigned long *configs = NULL;
unsigned num_configs = 0; unsigned num_configs = 0;
unsigned reserve; unsigned reserve, strings_count;
struct property *prop; struct property *prop;
const char *group; const char *group;
const char *subnode_target_type = "pins"; const char *subnode_target_type = "pins";
ret = of_property_count_strings(np, "pins");
if (ret < 0) {
ret = of_property_count_strings(np, "groups");
if (ret < 0)
/* skip this node; may contain config child nodes */
return 0;
if (type == PIN_MAP_TYPE_INVALID)
type = PIN_MAP_TYPE_CONFIGS_GROUP;
subnode_target_type = "groups";
} else {
if (type == PIN_MAP_TYPE_INVALID)
type = PIN_MAP_TYPE_CONFIGS_PIN;
}
strings_count = ret;
ret = of_property_read_string(np, "function", &function); ret = of_property_read_string(np, "function", &function);
if (ret < 0) { if (ret < 0) {
/* EINVAL=missing, which is fine since it's optional */ /* EINVAL=missing, which is fine since it's optional */
@ -309,21 +324,7 @@ int pinconf_generic_dt_subnode_to_map(struct pinctrl_dev *pctldev,
if (num_configs) if (num_configs)
reserve++; reserve++;
ret = of_property_count_strings(np, "pins"); reserve *= strings_count;
if (ret < 0) {
ret = of_property_count_strings(np, "groups");
if (ret < 0) {
dev_err(dev, "could not parse property pins/groups\n");
goto exit;
}
if (type == PIN_MAP_TYPE_INVALID)
type = PIN_MAP_TYPE_CONFIGS_GROUP;
subnode_target_type = "groups";
} else {
if (type == PIN_MAP_TYPE_INVALID)
type = PIN_MAP_TYPE_CONFIGS_PIN;
}
reserve *= ret;
ret = pinctrl_utils_reserve_map(pctldev, map, reserved_maps, ret = pinctrl_utils_reserve_map(pctldev, map, reserved_maps,
num_maps, reserve); num_maps, reserve);
@ -367,15 +368,22 @@ int pinconf_generic_dt_node_to_map(struct pinctrl_dev *pctldev,
*map = NULL; *map = NULL;
*num_maps = 0; *num_maps = 0;
ret = pinconf_generic_dt_subnode_to_map(pctldev, np_config, map,
&reserved_maps, num_maps, type);
if (ret < 0)
goto exit;
for_each_child_of_node(np_config, np) { for_each_child_of_node(np_config, np) {
ret = pinconf_generic_dt_subnode_to_map(pctldev, np, map, ret = pinconf_generic_dt_subnode_to_map(pctldev, np, map,
&reserved_maps, num_maps, type); &reserved_maps, num_maps, type);
if (ret < 0) { if (ret < 0)
pinctrl_utils_dt_free_map(pctldev, *map, *num_maps); goto exit;
return ret;
}
} }
return 0; return 0;
exit:
pinctrl_utils_dt_free_map(pctldev, *map, *num_maps);
return ret;
} }
EXPORT_SYMBOL_GPL(pinconf_generic_dt_node_to_map); EXPORT_SYMBOL_GPL(pinconf_generic_dt_node_to_map);