lkml.org 
[lkml]   [2014]   [Oct]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/4] pinctrl: add helpers for group based drivers
Date
Since the group based drivers have their dt properties documented in the
generic pinctrl documentation, add generic helpers to avoid duplicating
code and to be sure new drivers won't use specific bindings for a known
purpose.

This patch add two functions to help group based drivers map their
nodes:
- of_pinctrl_utils_read_function(): reads the function name of a
specified node, and gets the number of groups it should be
applied to.
- of_pinctrl_for_each_function_group(): navigates through the groups of
a specified node, reading at each iteration the name of the current
group.

Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
---
drivers/pinctrl/pinctrl-utils.c | 26 ++++++++++++++++++++++++++
drivers/pinctrl/pinctrl-utils.h | 9 +++++++++
2 files changed, 35 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-utils.c b/drivers/pinctrl/pinctrl-utils.c
index d77693f2cc1b..0ce44ff70197 100644
--- a/drivers/pinctrl/pinctrl-utils.c
+++ b/drivers/pinctrl/pinctrl-utils.c
@@ -140,3 +140,29 @@ void pinctrl_utils_dt_free_map(struct pinctrl_dev *pctldev,
kfree(map);
}
EXPORT_SYMBOL_GPL(pinctrl_utils_dt_free_map);
+
+#ifdef CONFIG_OF
+int of_pinctrl_utils_read_function(struct pinctrl_dev *pctldev,
+ struct device_node *node, const char **function_name,
+ int *ngroups)
+{
+ int ret;
+
+ ret = of_property_read_string(node, "function", function_name);
+ if (ret) {
+ dev_err(pctldev->dev, "missing function property in node %s\n",
+ node->name);
+ return -EINVAL;
+ }
+
+ *ngroups = of_property_count_strings(node, "groups");
+ if (ngroups <= 0) {
+ dev_err(pctldev->dev, "missing groups property in node %s\n",
+ node->name);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_pinctrl_utils_read_function);
+#endif
diff --git a/drivers/pinctrl/pinctrl-utils.h b/drivers/pinctrl/pinctrl-utils.h
index d0ffe1ce200f..d768dfe5daee 100644
--- a/drivers/pinctrl/pinctrl-utils.h
+++ b/drivers/pinctrl/pinctrl-utils.h
@@ -40,4 +40,13 @@ int pinctrl_utils_add_config(struct pinctrl_dev *pctldev,
void pinctrl_utils_dt_free_map(struct pinctrl_dev *pctldev,
struct pinctrl_map *map, unsigned num_maps);

+#ifdef CONFIG_OF
+int of_pinctrl_utils_read_function(struct pinctrl_dev *pctrldev,
+ struct device_node *node, const char **function_name,
+ int *ngroups);
+
+#define of_pinctrl_for_each_function_group(node, prop, group_name) \
+ of_property_for_each_string(node, "groups", prop, group_name)
+#endif
+
#endif /* __PINCTRL_UTILS_H__ */
--
1.9.1


\
 
 \ /
  Last update: 2014-10-20 10:21    [W:0.136 / U:0.264 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site