lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 20 Oct 2014 10:04:18 +0200
From:	Antoine Tenart <antoine.tenart@...e-electrons.com>
To:	linus.walleij@...aro.org, sebastian.hesselbarth@...il.com
Cc:	Antoine Tenart <antoine.tenart@...e-electrons.com>,
	linux-kernel@...r.kernel.org
Subject: [PATCH 2/4] pinctrl: add helpers for group based drivers

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@...e-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

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

Powered by blists - more mailing lists