Skip to contentSkip to conversation

pinctrl: samsung: Allow grouping multiple pinmux/pinconf nodes

PATCH In review Tomasz Figa 4 participants 5 messages Nov 19, 2013 – Nov 26, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: samsung: Allow grouping multiple pinmux/pinconf nodes

One of remaining limitations of current pinctrl-samsung driver was the inability to parse multiple pinmux/pinconf group nodes grouped inside a single device tree node. It made defining groups of pins for single purpose, but with different parameters very inconvenient.

This patch implements Tegra-like support for grouping multiple pinctrl groups inside one device tree node, by completely changing the way pin groups and functions are parsed from device tree. The code creating pinctrl maps from DT nodes has been borrowed from pinctrl-tegra, while the initial creation of groups and functions has been completely rewritten with following assumptions:
- each group consists of just one pin and does not depend on data from device tree,
- each function is represented by a device tree child node of the pin controller, which in turn can contain multiple child nodes for pins that need to have different configuration values.

Device Tree bindings are fully backwards compatible. New functionality can be used by defining a new pinctrl group consisting of several child nodes, as on following example:

	sd4_bus8: sd4-bus-width8 {
		part-1 {
			samsung,pins = "gpk0-3", "gpk0-4",
					"gpk0-5", "gpk0-6";
			samsung,pin-function = <3>;
			samsung,pin-pud = <3>;
			samsung,pin-drv = <3>;
		};
		part-2 {
			samsung,pins = "gpk1-3", "gpk1-4",
					"gpk1-5", "gpk1-6";
			samsung,pin-function = <4>;
			samsung,pin-pud = <4>;
			samsung,pin-drv = <3>;
		};
	};

Tested on Exynos4210-Trats board and a custom Exynos4212-based one.

---
 .../bindings/pinctrl/samsung-pinctrl.txt           |  23 +-
 drivers/pinctrl/pinctrl-samsung.c                  | 619 ++++++++++++---------
 drivers/pinctrl/pinctrl-samsung.h                  |   1 +
 3 files changed, 392 insertions(+), 251 deletions(-)
Documentation/devicetree/bindings/pinctrl/samsung-pinctrl.txt +22 -1
index 257677d..fe34cbb 100644
@@ -43,7 +43,11 @@ Required Properties:
 - Pin mux/config groups as child nodes: The pin mux (selecting pin function
   mode) and pin config (pull up/down, driver strength) settings are represented
   as child nodes of the pin-controller node. There should be atleast one
-  child node and there is no limit on the count of these child nodes.
+  child node and there is no limit on the count of these child nodes. It is
+  also possible for a child node to consist of several further child nodes
+  to allow grouping multiple pinctrl groups into one. The format of second
+  level child nodes is exactly the same as for first level ones and is
+  described below.
 
   The child node should contain a list of pin(s) on which a particular pin
   function selection or pin configuration (or both) have to applied. This
@@ -248,6 +252,23 @@ Example 1: A pin-controller node with pin groups.
 			samsung,pin-pud = <3>;
 			samsung,pin-drv = <0>;
 		};
+
+		sd4_bus8: sd4-bus-width8 {
+			part-1 {
+				samsung,pins = "gpk0-3", "gpk0-4",
+						"gpk0-5", "gpk0-6";
+				samsung,pin-function = <3>;
+				samsung,pin-pud = <3>;
+				samsung,pin-drv = <3>;
+			};
+			part-2 {
+				samsung,pins = "gpk1-3", "gpk1-4",
+						"gpk1-5", "gpk1-6";
+				samsung,pin-function = <4>;
+				samsung,pin-pud = <4>;
+				samsung,pin-drv = <3>;
+			};
+		};
 	};
 
 Example 2: A pin-controller node with external wakeup interrupt controller node.
drivers/pinctrl/pinctrl-samsung.c +369 -250

732 lines not on this page · raw message

drivers/pinctrl/pinctrl-samsung.h +1 -0
index 30622d9..a7488d5 100644
@@ -248,6 +248,7 @@ struct samsung_pmx_func {
 	const char		*name;
 	const char		**groups;
 	u8			num_groups;
+	u32			val;
 };
 
 /* list of all exported SoC specific data */
Signature · 1 line
1.8.4.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Tomasz Figa

One of remaining limitations of current pinctrl-samsung driver was the inability to parse multiple pinmux/pinconf group nodes grouped inside a single device tree node. It made defining groups of pins for single purpose, but with different parameters very inconvenient.

This patch implements Tegra-like support for grouping multiple pinctrl groups inside one device tree node, by completely changing the way pin groups and functions are parsed from device tree.

The code creating
pinctrl maps from DT nodes has been borrowed from pinctrl-tegra,

A lot of the Tegra code has been slightly generalized and put into pinconf-generic.c. Can the Samsung driver be converted to use that core code rather than adding another copy of it? Perhaps this isn't possible given the backwards-compatibility requirements that allow either 1- or 2-level nodes though, although I imagine that could be added to the core code. One thing you'd certainly need to do is enhance the code in pinconf-generic.c so that you could substitute your own pinconf_generic_parse_dt_config() function or dt_params[] table, to allow for the SoC-specific property names, but I doubt that's too hard. Tegra could be converted then too:-)

Quoted 8 lines

while
the initial creation of groups and functions has been completely rewritten with following assumptions:
- each group consists of just one pin and does not depend on data from device tree,
- each function is represented by a device tree child node of the pin controller, which in turn can contain multiple child nodes for pins that need to have different configuration values.

OK, I think that sounds reasonable.

Quoted 4 lines

Device Tree bindings are fully backwards compatible. New functionality can be used by defining a new pinctrl group consisting of several child nodes, as on following example:

Quoted 16 lines
	sd4_bus8: sd4-bus-width8 {
		part-1 {
			samsung,pins = "gpk0-3", "gpk0-4",
					"gpk0-5", "gpk0-6";
			samsung,pin-function = <3>;
			samsung,pin-pud = <3>;
			samsung,pin-drv = <3>;
		};
		part-2 {
			samsung,pins = "gpk1-3", "gpk1-4",
					"gpk1-5", "gpk1-6";
			samsung,pin-function = <4>;
			samsung,pin-pud = <4>;
			samsung,pin-drv = <3>;
		};
	};

OK, that all looks great!

Documentation/devicetree/bindings/pinctrl/samsung-pinctrl.txt

Quoted 1 line
Documentation/devicetree/bindings/pinctrl/samsung-pinctrl.txt +0 -0

The DT changes fully, and the code a little briefly,

Just a minor comment below,

Quoted 6 lines
drivers/pinctrl/pinctrl-samsung.c +4 -0
 
+static int samsung_pinctrl_create_function(struct device *dev,
+				struct samsung_pinctrl_drv_data *drvdata,
+				struct device_node *func_np,
+				struct samsung_pmx_func *func)

...

Quoted 7 lines
drivers/pinctrl/pinctrl-samsung.c +7 -0
+	for (i = 0; i < npins; ++i) {
+		const char *gname;
+		char *gname_copy;
+
+		ret = of_property_read_string_index(func_np, "samsung,pins",
+							i, &gname);
+		if (ret) {

drivers/pinctrl/pinctrl-samsung.c static int samsung_gpio_to_irq(struct gpio_chip *gc, unsigned offset) · line 726

Quoted 10 lines
drivers/pinctrl/pinctrl-samsung.c +9 -0
+			dev_err(dev,
+				"failed to read pin name %d from %s node\n",
+				i, func_np->name);
+			return ret;
 		}
+
+		gname_copy = devm_kzalloc(dev, strlen(gname) + 1, GFP_KERNEL);
+		if (!gname_copy)
+			return -ENOMEM;
+		strcpy(gname_copy, gname);

Is the lifetime of the string "returned" by of_property_read_string_index() really so short that you must copy the string? I'd be tempted just to store the pointer, although perhaps you need to get() the node so that's safe.

#2 lore raw

Hi Stephen,

Quoted 13 lines · On Tuesday 19 of November 2013 12:10:01 Stephen Warren wrote:
Quoted 11 lines · Tomasz Figa

One of remaining limitations of current pinctrl-samsung driver was the inability to parse multiple pinmux/pinconf group nodes grouped inside a single device tree node. It made defining groups of pins for single purpose, but with different parameters very inconvenient.

This patch implements Tegra-like support for grouping multiple pinctrl groups inside one device tree node, by completely changing the way pin groups and functions are parsed from device tree.

The code creating
pinctrl maps from DT nodes has been borrowed from pinctrl-tegra,

Quoted 10 lines

A lot of the Tegra code has been slightly generalized and put into pinconf-generic.c. Can the Samsung driver be converted to use that core code rather than adding another copy of it? Perhaps this isn't possible given the backwards-compatibility requirements that allow either 1- or 2-level nodes though, although I imagine that could be added to the core code. One thing you'd certainly need to do is enhance the code in pinconf-generic.c so that you could substitute your own pinconf_generic_parse_dt_config() function or dt_params[] table, to allow for the SoC-specific property names, but I doubt that's too hard. Tegra could be converted then too:-)

I can't say that it's not a good idea, but I would prefer this to be merged first as an Exynos-specific patch and only then somehow try to figure out how to remove code duplication. This is due to the fact that I won't have too much time to work on this in very near future, but this feature itself is rather convenient and it would be nice to have it anyway.

Quoted 63 lines
Quoted 9 lines

while
the initial creation of groups and functions has been completely rewritten with following assumptions:
- each group consists of just one pin and does not depend on data from device tree,
- each function is represented by a device tree child node of the pin controller, which in turn can contain multiple child nodes for pins that need to have different configuration values.

OK, I think that sounds reasonable.

Quoted 4 lines

Device Tree bindings are fully backwards compatible. New functionality can be used by defining a new pinctrl group consisting of several child nodes, as on following example:

Quoted 16 lines
	sd4_bus8: sd4-bus-width8 {
		part-1 {
			samsung,pins = "gpk0-3", "gpk0-4",
					"gpk0-5", "gpk0-6";
			samsung,pin-function = <3>;
			samsung,pin-pud = <3>;
			samsung,pin-drv = <3>;
		};
		part-2 {
			samsung,pins = "gpk1-3", "gpk1-4",
					"gpk1-5", "gpk1-6";
			samsung,pin-function = <4>;
			samsung,pin-pud = <4>;
			samsung,pin-drv = <3>;
		};
	};

OK, that all looks great!

Documentation/devicetree/bindings/pinctrl/samsung-pinctrl.txt

Quoted 1 line
Documentation/devicetree/bindings/pinctrl/samsung-pinctrl.txt +0 -0

The DT changes fully, and the code a little briefly,

Just a minor comment below,

Quoted 6 lines
drivers/pinctrl/pinctrl-samsung.c +4 -0
 
+static int samsung_pinctrl_create_function(struct device *dev,
+				struct samsung_pinctrl_drv_data *drvdata,
+				struct device_node *func_np,
+				struct samsung_pmx_func *func)

...

Quoted 14 lines
drivers/pinctrl/pinctrl-samsung.c +13 -0
+	for (i = 0; i < npins; ++i) {
+		const char *gname;
+		char *gname_copy;
+
+		ret = of_property_read_string_index(func_np, "samsung,pins",
+							i, &gname);
+		if (ret) {
+			dev_err(dev,
+				"failed to read pin name %d from %s node\n",
+				i, func_np->name);
+			return ret;
 		}
+
+		gname_copy = devm_kzalloc(dev, strlen(gname) + 1, GFP_KERNEL);
Quoted 8 lines

drivers/pinctrl/pinctrl-samsung.c static int samsung_gpio_to_irq(struct gpio_chip *gc, unsigned offset) · line 726

Quoted 3 lines
drivers/pinctrl/pinctrl-samsung.c +3 -0
+		if (!gname_copy)
+			return -ENOMEM;
+		strcpy(gname_copy, gname);

Is the lifetime of the string "returned" by of_property_read_string_index() really so short that you must copy the string? I'd be tempted just to store the pointer, although perhaps you need to get() the node so that's safe.

Right. I have done it the copy-less way in other places, but missed this one. Thanks.

Best regards,
Tomasz

#3 lore raw
Quoted 8 lines · Tomasz Figa

Stephen:

Quoted 4 lines

Is the lifetime of the string "returned" by of_property_read_string_index() really so short that you must copy the string? I'd be tempted just to store the pointer, although perhaps you need to get() the node so that's safe.

Right. I have done it the copy-less way in other places, but missed this one. Thanks.

So I guess I'm waiting for a new version of this patch, right?

Yours,
Linus Walleij

#4 lore raw
Quoted 11 lines · On Monday 25 of November 2013 15:46:12 Linus Walleij wrote:
Quoted 8 lines · Tomasz Figa

Stephen:

Quoted 4 lines

Is the lifetime of the string "returned" by of_property_read_string_index() really so short that you must copy the string? I'd be tempted just to store the pointer, although perhaps you need to get() the node so that's safe.

Right. I have done it the copy-less way in other places, but missed this one. Thanks.

So I guess I'm waiting for a new version of this patch, right?

Right.

Best regards,
Tomasz