Messages in this thread | | | Date | Tue, 28 Oct 2014 16:38:27 +0100 | Subject | Re: [PATCH 2/4] pinctrl: add helpers for group based drivers | From | Linus Walleij <> |
| |
On Mon, Oct 20, 2014 at 10:04 AM, Antoine Tenart <antoine.tenart@free-electrons.com> wrote:
> 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>
GOOD IDEA!
Let's work from this and change a few drivers.
Some comments:
> +#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
Isn't it nasty to print dev_err() here if you maybe just want to check if this node has a "function" element and proceed to see if it's a pin config group in case it hasn't?
Or should we add of_pinctrl_utils_node_is_mux() and of_pinctrl_utils_node_is_config() to check this?
> +#define of_pinctrl_for_each_function_group(node, prop, group_name) \ > + of_property_for_each_string(node, "groups", prop, group_name)
I *really* like this macro.
Yours, Linus Walleij
| |