[PATCH 3/4] pinctrl: add a generic way to map node to map for group based drivers

From: Antoine Tenart
Date: Mon Oct 20 2014 - 04:10:23 EST


This patch add a generic function to use a standard callback to
.dt_node_to_map for group based pinctrl drivers.

It parses nodes of the form:

foo_pmux: foo-pmux {
function = "foo";
groups = "g0", "g1", "g2";
}

Signed-off-by: Antoine Tenart <antoine.tenart@xxxxxxxxxxxxxxxxxx>
---
drivers/pinctrl/pinconf-generic.c | 36 +++++++++++++++++++++++++++++++++
include/linux/pinctrl/pinconf-generic.h | 3 +++
2 files changed, 39 insertions(+)

diff --git a/drivers/pinctrl/pinconf-generic.c b/drivers/pinctrl/pinconf-generic.c
index 29ff77f90fcb..456902150226 100644
--- a/drivers/pinctrl/pinconf-generic.c
+++ b/drivers/pinctrl/pinconf-generic.c
@@ -336,4 +336,40 @@ int pinconf_generic_dt_node_to_map(struct pinctrl_dev *pctldev,
}
EXPORT_SYMBOL_GPL(pinconf_generic_dt_node_to_map);

+int pinconf_generic_function_groups_dt_node_to_map(struct pinctrl_dev *pctldev,
+ struct device_node *node, struct pinctrl_map **map,
+ unsigned *num_maps)
+{
+ struct property *prop;
+ unsigned reserved_maps = 0;
+ const char *function_name, *group_name;
+ int ngroups, ret;
+
+ *map = NULL;
+ *num_maps = 0;
+
+ ret = of_pinctrl_utils_read_function(pctldev, node, &function_name,
+ &ngroups);
+ if (ret)
+ return ret;
+
+ ret = pinctrl_utils_reserve_map(pctldev, map, &reserved_maps, num_maps,
+ ngroups);
+ if (ret)
+ return ret;
+
+ of_pinctrl_for_each_function_group(node, prop, group_name) {
+ ret = pinctrl_utils_add_map_mux(pctldev, map, &reserved_maps,
+ num_maps, group_name,
+ function_name);
+ if (ret) {
+ dev_err(pctldev->dev, "cannot add map: %d\n", ret);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(pinconf_generic_function_groups_dt_node_to_map);
+
#endif
diff --git a/include/linux/pinctrl/pinconf-generic.h b/include/linux/pinctrl/pinconf-generic.h
index a15f10727eb8..acda4b89596d 100644
--- a/include/linux/pinctrl/pinconf-generic.h
+++ b/include/linux/pinctrl/pinconf-generic.h
@@ -157,6 +157,9 @@ int pinconf_generic_dt_subnode_to_map(struct pinctrl_dev *pctldev,
int pinconf_generic_dt_node_to_map(struct pinctrl_dev *pctldev,
struct device_node *np_config, struct pinctrl_map **map,
unsigned *num_maps, enum pinctrl_map_type type);
+int pinconf_generic_function_groups_dt_node_to_map(struct pinctrl_dev *pctldev,
+ struct device_node *node, struct pinctrl_map **map,
+ unsigned *num_maps);

static inline int pinconf_generic_dt_node_to_map_group(
struct pinctrl_dev *pctldev, struct device_node *np_config,
--
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/