Skip to contentSkip to conversation

support pinconf in pinctrl single

PATCH New Haojian Zhuang 7 participants 40 messages Feb 2, 2013 – Apr 29, 2013

Subsystems (5)
lore
Share & tools
lore

Haojian Zhuang

author maintainer
#0 lore raw

v8 cover support pinconf in pinctrl single

Changelog:
v8:
1. Always to check return value of pinctrl_request_gpio().
2. Add pinctrl_overlapped_gpio_range() to handle the case that special GPIO pins don't have back-end pinctrl interface.
3. Add document of pinctrl single.
4. Replace power source property by drive strength property in pinctrl single driver since current should be drive strength property.
5. Rebase all the patches.

v7:
1. Discard the method of adding gpio range from pinctrl-single driver. Use gpiolib driver to support gpio range from DTS instead.
2. Add gpio request function to claim pin in gpio pl061 driver.
3. Adjust the initcall level in gpio pl061 driver.
4. Allocate gpio number from lowest gpio number to highest. The original implementation is inverted. It's hard to use since it inverted the sequence of gpio number.
5. Remove the support of pxa910 temporarily since gpio pxa driver need to be updated for supporting this solution.

v6:
1. Two configuration array will be created for each pin group. This first array is stored in pcs_function structure. The 32-bit configruation argument is stored in this array. Driver stores data while parsing DTS file, and loads these config array if function selector is indicated.
The second array is stored in pinctrl_map structure. Driver won't use it directly. So we could avoid to append lookup pinctrl map method that is introduced in v5.

v5:
1. Move the properties of pinconf into pin group. So those mask properties could be merged with other pinconf properties.
2. Append lookup pinctrl map method.
3. Append input schmitt disable config parameter.
4. Clean code.

v4:
1. Define gpio range as sub-node, not label. And remove pinctrl-single,gpio-ranges property.
2. Use new two properties in sub-node, reg & pinctrl-single,gpio. GPIO number & GPIO function are listed in the pinctrl-single,gpio property.
3. Reference the names like pinctrl-single,bias.
4. Add compatible name "pinconf-single". If the compatible name is "pinctrl-single", there's no pinconf. If the compatible name is "pinconf-single", there's the generic pinconf in pinctrl-single.
5. Update documents.

v3:
1. Add more comments in document.
2. Replace pcs_readl() & pcs_writel() by pcs->read() & pcs->write().
3. Clean code.

v2:
1. Remove "pinctrl-single,gpio-mask". Since GPIO function is one of the mux function in the pinmux register of both OMAP and PXA/MMP silicons. Use "pinctrl-single,function-mask" instead.
2. Remove "pinctrl-single,gpio-enable" & "pinctrl-single,gpio-disable". Use "pinctrl-single,gpio-func" instead. Because GPIO mode is only one of the mux functions in the pinmux register. Defining "gpio-enable" & "gpio-disable" are redundant.
3. Define register with __iomem, not u32 type.
4. Remove "pinctrl-single,input-schmit-shift", "pinctrl-single,power-source-shift", "pinctrl-single,bias-shift". All these properties could be calculated by mask fields.
5. Return -EPROBE_DEFER if pinmux could be got in device driver. And the device driver would be probed again deferred.

author maintainer
#1 lore raw

PATCH v8 1/12 gpio: add gpio offset in gpio range cells property

Add gpio offset into "gpio-range-cells" property. It's used to support sparse pinctrl range in gpio chip.

---
 Documentation/devicetree/bindings/gpio/gpio.txt |    6 +++---
 arch/arm/boot/dts/spear1310.dtsi                |    4 ++--
 arch/arm/boot/dts/spear1340.dtsi                |    4 ++--
 arch/arm/boot/dts/spear310.dtsi                 |    4 ++--
 arch/arm/boot/dts/spear320.dtsi                 |    4 ++--
 drivers/gpio/gpiolib-of.c                       |   15 ++-------------
 6 files changed, 13 insertions(+), 24 deletions(-)
Documentation/devicetree/bindings/gpio/gpio.txt +3 -3
index a336287..d933af3 100644
@@ -98,7 +98,7 @@ announce the pinrange to the pin ctrl subsystem. For example,
 		compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
 		reg = <0x1460 0x18>;
 		gpio-controller;
-		gpio-ranges = <&pinctrl1 20 10>, <&pinctrl2 50 20>;
+		gpio-ranges = <&pinctrl1 0 20 10>, <&pinctrl2 10 50 20>;
 
     }
 
@@ -107,8 +107,8 @@ where,
 
    Next values specify the base pin and number of pins for the range
    handled by 'qe_pio_e' gpio. In the given example from base pin 20 to
-   pin 29 under pinctrl1 and pin 50 to pin 69 under pinctrl2 is handled
-   by this gpio controller.
+   pin 29 under pinctrl1 with gpio offset 0 and pin 50 to pin 69 under
+   pinctrl2 with gpio offset 10 is handled by this gpio controller.
 
 The pinctrl node must have "#gpio-range-cells" property to show number of
 arguments to pass with phandle from gpio controllers node.
arch/arm/boot/dts/spear1310.dtsi +2 -2
index 1513c19..122ae94 100644
@@ -89,7 +89,7 @@
 		pinmux: pinmux at e0700000 {
 			compatible = "st,spear1310-pinmux";
 			reg = <0xe0700000 0x1000>;
-			#gpio-range-cells = <2>;
+			#gpio-range-cells = <3>;
 		};
 
 		apb {
@@ -212,7 +212,7 @@
 				interrupt-controller;
 				gpio-controller;
 				#gpio-cells = <2>;
-				gpio-ranges = <&pinmux 0 246>;
+				gpio-ranges = <&pinmux 0 0 246>;
 				status = "disabled";
 
 				st-plgpio,ngpio = <246>;
arch/arm/boot/dts/spear1340.dtsi +2 -2
index b2d41b7..7ec1eb8 100644
@@ -63,7 +63,7 @@
 		pinmux: pinmux at e0700000 {
 			compatible = "st,spear1340-pinmux";
 			reg = <0xe0700000 0x1000>;
-			#gpio-range-cells = <2>;
+			#gpio-range-cells = <3>;
 		};
 
 		pwm: pwm at e0180000 {
@@ -146,7 +146,7 @@
 				interrupt-controller;
 				gpio-controller;
 				#gpio-cells = <2>;
-				gpio-ranges = <&pinmux 0 252>;
+				gpio-ranges = <&pinmux 0 0 252>;
 				status = "disabled";
 
 				st-plgpio,ngpio = <250>;
arch/arm/boot/dts/spear310.dtsi +2 -2
index ab45b8c..9537208 100644
@@ -25,7 +25,7 @@
 		pinmux: pinmux at b4000000 {
 			compatible = "st,spear310-pinmux";
 			reg = <0xb4000000 0x1000>;
-			#gpio-range-cells = <2>;
+			#gpio-range-cells = <3>;
 		};
 
 		fsmc: flash at 44000000 {
@@ -102,7 +102,7 @@
 				interrupt-controller;
 				gpio-controller;
 				#gpio-cells = <2>;
-				gpio-ranges = <&pinmux 0 102>;
+				gpio-ranges = <&pinmux 0 0 102>;
 				status = "disabled";
 
 				st-plgpio,ngpio = <102>;
arch/arm/boot/dts/spear320.dtsi +2 -2
index caa5520..ffea342 100644
@@ -24,7 +24,7 @@
 		pinmux: pinmux at b3000000 {
 			compatible = "st,spear320-pinmux";
 			reg = <0xb3000000 0x1000>;
-			#gpio-range-cells = <2>;
+			#gpio-range-cells = <3>;
 		};
 
 		clcd at 90000000 {
@@ -130,7 +130,7 @@
 				interrupt-controller;
 				gpio-controller;
 				#gpio-cells = <2>;
-				gpio-ranges = <&pinmux 0 102>;
+				gpio-ranges = <&pinmux 0 0 102>;
 				status = "disabled";
 
 				st-plgpio,ngpio = <102>;
drivers/gpio/gpiolib-of.c +2 -13
index 25b1dbe..380f84e 100644
@@ -238,22 +238,11 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
 		if (!pctldev)
 			break;
 
-		/*
-		 * This assumes that the n GPIO pins are consecutive in the
-		 * GPIO number space, and that the pins are also consecutive
-		 * in their local number space. Currently it is not possible
-		 * to add different ranges for one and the same GPIO chip,
-		 * as the code assumes that we have one consecutive range
-		 * on both, mapping 1-to-1.
-		 *
-		 * TODO: make the OF bindings handle multiple sparse ranges
-		 * on the same GPIO chip.
-		 */
 		ret = gpiochip_add_pin_range(chip,
 					     pinctrl_dev_get_devname(pctldev),
-					     0, /* offset in gpiochip */
 					     pinspec.args[0],
-					     pinspec.args[1]);
+					     pinspec.args[1],
+					     pinspec.args[2]);
 
 		if (ret)
 			break;
Signature · 1 line
1.7.10.4
maintainer
#2 lore raw

PATCH v8 1/12 gpio: add gpio offset in gpio range cells property

Quoted 42 lines · Haojian Zhuang

Add gpio offset into "gpio-range-cells" property. It's used to support sparse pinctrl range in gpio chip.

---
 Documentation/devicetree/bindings/gpio/gpio.txt |    6 +++---
 arch/arm/boot/dts/spear1310.dtsi                |    4 ++--
 arch/arm/boot/dts/spear1340.dtsi                |    4 ++--
 arch/arm/boot/dts/spear310.dtsi                 |    4 ++--
 arch/arm/boot/dts/spear320.dtsi                 |    4 ++--
 drivers/gpio/gpiolib-of.c                       |   15 ++-------------
 6 files changed, 13 insertions(+), 24 deletions(-)
Documentation/devicetree/bindings/gpio/gpio.txt +3 -3
index a336287..d933af3 100644
@@ -98,7 +98,7 @@ announce the pinrange to the pin ctrl subsystem. For example,
 		compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
 		reg = <0x1460 0x18>;
 		gpio-controller;
-		gpio-ranges = <&pinctrl1 20 10>, <&pinctrl2 50 20>;
+		gpio-ranges = <&pinctrl1 0 20 10>, <&pinctrl2 10 50 20>;
 
     }
 
@@ -107,8 +107,8 @@ where,
 
    Next values specify the base pin and number of pins for the range
    handled by 'qe_pio_e' gpio. In the given example from base pin 20 to
-   pin 29 under pinctrl1 and pin 50 to pin 69 under pinctrl2 is handled
-   by this gpio controller.
+   pin 29 under pinctrl1 with gpio offset 0 and pin 50 to pin 69 under
+   pinctrl2 with gpio offset 10 is handled by this gpio controller.
 
 The pinctrl node must have "#gpio-range-cells" property to show number of
 arguments to pass with phandle from gpio controllers node.
arch/arm/boot/dts/spear1310.dtsi +0 -0
index 1513c19..122ae94 100644

arch/arm/boot/dts/spear1310.dtsi line 95

Quoted 8 lines
arch/arm/boot/dts/spear1310.dtsi +1 -1
@@ -89,7 +89,7 @@
 		pinmux: pinmux at e0700000 {
 			compatible = "st,spear1310-pinmux";
 			reg = <0xe0700000 0x1000>;
-			#gpio-range-cells = <2>;
+			#gpio-range-cells = <3>;
 		};
 
 		apb {

Hmm is this safe to do if there are bootloaders using the old binding? Maybe we should support both #gpio-range-cells = <2> and <3> bindings instead?

Regards,

Tony

author maintainer
#3 lore raw

PATCH v8 1/12 gpio: add gpio offset in gpio range cells property

Quoted 56 lines · Tony Lindgren
Quoted 42 lines · Haojian Zhuang

Add gpio offset into "gpio-range-cells" property. It's used to support sparse pinctrl range in gpio chip.

---
 Documentation/devicetree/bindings/gpio/gpio.txt |    6 +++---
 arch/arm/boot/dts/spear1310.dtsi                |    4 ++--
 arch/arm/boot/dts/spear1340.dtsi                |    4 ++--
 arch/arm/boot/dts/spear310.dtsi                 |    4 ++--
 arch/arm/boot/dts/spear320.dtsi                 |    4 ++--
 drivers/gpio/gpiolib-of.c                       |   15 ++-------------
 6 files changed, 13 insertions(+), 24 deletions(-)
Documentation/devicetree/bindings/gpio/gpio.txt +3 -3
index a336287..d933af3 100644
@@ -98,7 +98,7 @@ announce the pinrange to the pin ctrl subsystem. For example,
              compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
              reg = <0x1460 0x18>;
              gpio-controller;
-             gpio-ranges = <&pinctrl1 20 10>, <&pinctrl2 50 20>;
+             gpio-ranges = <&pinctrl1 0 20 10>, <&pinctrl2 10 50 20>;
 
     }
 
@@ -107,8 +107,8 @@ where,
 
    Next values specify the base pin and number of pins for the range
    handled by 'qe_pio_e' gpio. In the given example from base pin 20 to
-   pin 29 under pinctrl1 and pin 50 to pin 69 under pinctrl2 is handled
-   by this gpio controller.
+   pin 29 under pinctrl1 with gpio offset 0 and pin 50 to pin 69 under
+   pinctrl2 with gpio offset 10 is handled by this gpio controller.
 
 The pinctrl node must have "#gpio-range-cells" property to show number of
 arguments to pass with phandle from gpio controllers node.
arch/arm/boot/dts/spear1310.dtsi +0 -0
index 1513c19..122ae94 100644

arch/arm/boot/dts/spear1310.dtsi line 95

Quoted 8 lines
arch/arm/boot/dts/spear1310.dtsi +1 -1
@@ -89,7 +89,7 @@
              pinmux: pinmux at e0700000 {
                      compatible = "st,spear1310-pinmux";
                      reg = <0xe0700000 0x1000>;
-                     #gpio-range-cells = <2>;
+                     #gpio-range-cells = <3>;
              };
 
              apb {

Hmm is this safe to do if there are bootloaders using the old binding? Maybe we should support both #gpio-range-cells = <2> and <3> bindings instead?

Quoted 3 lines

Regards,

Tony

I think that bootloader aren't using the old binding. I always Cc Shiraz. If it can't work, he would speak loudly.

And I don't want to add complexity in this function. So I force the number of parameters is three.

Regards
Haojian

#4 lore raw

PATCH v8 1/12 gpio: add gpio offset in gpio range cells property

In reply to Haojian Zhuang
Quoted 4 lines · Haojian Zhuang

Add gpio offset into "gpio-range-cells" property. It's used to support sparse pinctrl range in gpio chip.

Can't decide on this thing, no reply from Shiraz.

Viresh, what is your opinion?

Yours,
Linus Walleij

#5 lore raw

PATCH v8 1/12 gpio: add gpio offset in gpio range cells property

Quoted 11 lines · Linus Walleij
Quoted 4 lines · Haojian Zhuang

Add gpio offset into "gpio-range-cells" property. It's used to support sparse pinctrl range in gpio chip.

Can't decide on this thing, no reply from Shiraz.

Viresh, what is your opinion?

Sorry for missing this thread earlier. Looks fine to me:

#6 lore raw

PATCH v8 1/12 gpio: add gpio offset in gpio range cells property

In reply to Haojian Zhuang
Quoted 5 lines · Haojian Zhuang

Add gpio offset into "gpio-range-cells" property. It's used to support sparse pinctrl range in gpio chip.

This is an ABI breakage. I've been using the #gpio-range-cells = <2> since around October. Please can we try and maintain backward compatibility in future, even if it's only temporary.

Thanks
James

author maintainer
#7 lore raw

PATCH v8 1/12 gpio: add gpio offset in gpio range cells property

Quoted 7 lines · James Hogan
Quoted 5 lines · Haojian Zhuang

Add gpio offset into "gpio-range-cells" property. It's used to support sparse pinctrl range in gpio chip.

Quoted 7 lines

This is an ABI breakage. I've been using the #gpio-range-cells = <2> since around October. Please can we try and maintain backward compatibility in future, even if it's only temporary.

Thanks
James

I've updated all code with #gpio-range-cells = <3> in kernel. If you change this back to <2>, you'll break current pinctrl-single driver. I appended this because there may be not 1-to-1 mapping between gpio pins & pinmux pins in some SoC. So the new parameter is used to specify the gpio pin offset.

So it's not temporary.

Regards
Haojian

#8 lore raw

PATCH v8 1/12 gpio: add gpio offset in gpio range cells property

Quoted 12 lines · Haojian Zhuang
Quoted 11 lines · James Hogan
Quoted 5 lines · Haojian Zhuang

Add gpio offset into "gpio-range-cells" property. It's used to support sparse pinctrl range in gpio chip.

This is an ABI breakage. I've been using the #gpio-range-cells = <2> since around October. Please can we try and maintain backward compatibility in future, even if it's only temporary.

Quoted 8 lines
Quoted 3 lines

Thanks
James

I've updated all code with #gpio-range-cells = <3> in kernel. If you change this back to <2>, you'll break current pinctrl-single driver. I appended this because there may be not 1-to-1 mapping between gpio pins & pinmux pins in some SoC. So the new parameter is used to specify the gpio pin offset.

Yes, I agree having 3 cells is useful, and I wasn't suggesting reverting your patch, but it's an ABI now so the change should really be done in a backwards compatible way so that device tree files that still have #gpio-range-cells = <2> continue to work.

At the moment in -next, if you use an old device tree then the gpio ranges are muddled up, with npins set apparently to a random (in my case very large) number, I'm guessing this is just uninitialised data at the end of the array. Even if you didn't have to maintain backwards compatibility, it should at least check the number of cells matches what it expects before reading all 3 entries.

Quoted 2 lines

So it's not temporary.

Sorry, what I meant was "even if maintaining the backwards compatibility (supporting both <2> and <3>) is only temporary".

Cheers
James

author maintainer
#9 lore raw

PATCH v8 2/12 gpio: fix wrong checking condition for gpio range

In reply to Haojian Zhuang

If index++ calculates from 0, the checking condition of "while (index++)" fails & it doesn't check any more. It doesn't follow the loop that used at here.

Replace it by endless loop at here. Then it keeps parsing "gpio-ranges" property until it ends.

---
 drivers/gpio/gpiolib-of.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpio/gpiolib-of.c +2 -3
index 380f84e..dae24c0 100644
@@ -228,7 +228,7 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
 	if (!np)
 		return;
 
-	do {
+	for (;; index++) {
 		ret = of_parse_phandle_with_args(np, "gpio-ranges",
 				"#gpio-range-cells", index, &pinspec);
 		if (ret)
@@ -246,8 +246,7 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
 
 		if (ret)
 			break;
-
-	} while (index++);
+	}
 }
 
 #else
Signature · 1 line
1.7.10.4
#10 lore raw

PATCH v8 2/12 gpio: fix wrong checking condition for gpio range

Quoted 8 lines · Haojian Zhuang

If index++ calculates from 0, the checking condition of "while (index++)" fails & it doesn't check any more. It doesn't follow the loop that used at here.

Replace it by endless loop at here. Then it keeps parsing "gpio-ranges" property until it ends.

Yours,
Linus Walleij

author maintainer
#11 lore raw

PATCH v8 3/12 gpio: find gpio base by ascend order

In reply to Haojian Zhuang

gpiochip_find_base() always tries to find valid gpio with descend order. It's inconvient if gpio information is passing from DTS. Now try to find valid gpio with ascend order.

---
 drivers/gpio/gpiolib.c |   19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/gpio/gpiolib.c +10 -9
index 199fca1..8af57e7 100644
@@ -128,20 +128,21 @@ static int gpiochip_find_base(int ngpio)
 	int spare = 0;
 	int base = -ENOSPC;
 
-	for (i = ARCH_NR_GPIOS - 1; i >= 0 ; i--) {
+	for (i = 0, base = 0; i < ARCH_NR_GPIOS; i++) {
 		struct gpio_desc *desc = &gpio_desc[i];
 		struct gpio_chip *chip = desc->chip;
 
-		if (!chip && !test_bit(FLAG_RESERVED, &desc->flags)) {
+		if (chip) {
+			spare = 0;
+			i += chip->ngpio - 1;
+			base = i + 1;
+		} else if (test_bit(FLAG_RESERVED, &desc->flags)) {
+			spare = 0;
+			base = i + 1;
+		} else {
 			spare++;
-			if (spare == ngpio) {
-				base = i;
+			if (spare == ngpio)
 				break;
-			}
-		} else {
-			spare = 0;
-			if (chip)
-				i -= chip->ngpio - 1;
 		}
 	}
 
Signature · 1 line
1.7.10.4
#12 lore raw

PATCH v8 3/12 gpio: find gpio base by ascend order

Quoted 5 lines · Haojian Zhuang

gpiochip_find_base() always tries to find valid gpio with descend order. It's inconvient if gpio information is passing from DTS. Now try to find valid gpio with ascend order.

This is more scary stuff.

As you know GPIO numbers are exposed to userspace.

Systems with this change risk having their dynamically added GPIO controller enumerated in a different fashion. And userspace clients may be relying on these numbers.

And we do not break userspace.

I know this is not elegant but I'm afraid the descending search needs to be kept for compatibibility reasons.

BTW: please CC Grant likely on all patches.

Yours,
Linus Walleij

author maintainer
#13 lore raw

PATCH v8 3/12 gpio: find gpio base by ascend order

Quoted 19 lines · Linus Walleij
Quoted 5 lines · Haojian Zhuang

gpiochip_find_base() always tries to find valid gpio with descend order. It's inconvient if gpio information is passing from DTS. Now try to find valid gpio with ascend order.

This is more scary stuff.

As you know GPIO numbers are exposed to userspace.

Systems with this change risk having their dynamically added GPIO controller enumerated in a different fashion. And userspace clients may be relying on these numbers.

And we do not break userspace.

Quoted 7 lines

I know this is not elegant but I'm afraid the descending search needs to be kept for compatibibility reasons.

BTW: please CC Grant likely on all patches.

Yours,
Linus Walleij

But descending search isn't good for reading.

I try to allocate all gpio numbers in Hi3620 from gpiochip_find_base(). If it's descending search, GPIO0~7 is mapped to gpio248~255; GPIO8~GPIO15 is mapped to gpio240~gpio247. It's not easy to read, and it breaks the knowledge of gpio number on schematic & datasheet.

Unless we don't use allocating gpio numbers dynamically and add a common property to parse gpio base of each chip in DTS file. It's also OK to me add a common property.

Regards
Haojian

#14 lore raw

PATCH v8 3/12 gpio: find gpio base by ascend order

Quoted 7 lines · Haojian Zhuang
Quoted 6 lines · Linus Walleij
Quoted 3 lines · Haojian Zhuang

gpiochip_find_base() always tries to find valid gpio with descend order. It's inconvient if gpio information is passing from DTS. Now try to find valid gpio with ascend order.

GPIOs in the device tree are typically referenced by a phandle which include the controller and relative HW number. Are there cases where we must use absolute GPIO numbers in the DT?

Quoted 23 lines
Quoted 13 lines
Quoted 2 lines

This is more scary stuff.

As you know GPIO numbers are exposed to userspace.

Systems with this change risk having their dynamically added GPIO controller enumerated in a different fashion. And userspace clients may be relying on these numbers.

And we do not break userspace.

Quoted 7 lines

I know this is not elegant but I'm afraid the descending search needs to be kept for compatibibility reasons.

BTW: please CC Grant likely on all patches.

Yours,
Linus Walleij

But descending search isn't good for reading.

Quoted 8 lines

I try to allocate all gpio numbers in Hi3620 from gpiochip_find_base(). If it's descending search, GPIO0~7 is mapped to gpio248~255; GPIO8~GPIO15 is mapped to gpio240~gpio247. It's not easy to read, and it breaks the knowledge of gpio number on schematic & datasheet.

Unless we don't use allocating gpio numbers dynamically and add a common property to parse gpio base of each chip in DTS file. It's also OK to me add a common property.

There is also one more problem with this reordering: if a GPIO chip with a base GPIO set gets probed *after* a bunch of chips without a proper base, its range in the number space is likely to have been stolen by one of the "dynamic" chips.

Ideally all chips would come with a base GPIO, but we cannot rule out hotplugable interfaces. Even more ideally the integer numberspace would go away altogether with the new gpiod interface and the sysfs interface would be replaced with one where exported GPIOs would be under their chip node, and referenced by their hw number. But that would break userspace even more. Or maybe there could be a config option to choose between the "legacy" integer-space user interface and this new scheme. Eventually, the number space could be deprecated.

Alex.

author maintainer
#15 lore raw

PATCH v8 3/12 gpio: find gpio base by ascend order

Quoted 7 lines · Alex Courbot
Quoted 6 lines · Haojian Zhuang
Quoted 4 lines · Linus Walleij

On Sat, Feb 2, 2013 at 6:25 PM, Haojian Zhuang
<[email protected]> wrote:

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

gpiochip_find_base() always tries to find valid gpio with descend order. It's inconvient if gpio information is passing from DTS. Now try to find valid gpio with ascend order.

GPIOs in the device tree are typically referenced by a phandle which include the controller and relative HW number. Are there cases where we must use absolute GPIO numbers in the DT?

At first, you only consider SoC GPIO pins are in the same GPIO controllers. ARM pl061 is a gpio controller with only 8 GPIO pins. So there're a lot of pl061 controllers in one SoC.

In the second, all GPIO pins in one SoC are counter by ascending order. It's also
same in the schematic. And there's sysfs interface for GPIO debugging in kernel. With the descending order, gpio248 is real GPIO0 in SoC. It's crazy for develop debugging.

Quoted 50 lines
Quoted 26 lines
Quoted 15 lines
Quoted 3 lines

This is more scary stuff.

As you know GPIO numbers are exposed to userspace.

Systems with this change risk having their dynamically added GPIO controller enumerated in a different fashion. And userspace clients may be relying on these numbers.

And we do not break userspace.

Quoted 7 lines

I know this is not elegant but I'm afraid the descending search needs to be kept for compatibibility reasons.

BTW: please CC Grant likely on all patches.

Yours,
Linus Walleij

But descending search isn't good for reading.

Quoted 8 lines

I try to allocate all gpio numbers in Hi3620 from gpiochip_find_base(). If it's descending search, GPIO0~7 is mapped to gpio248~255; GPIO8~GPIO15 is mapped to gpio240~gpio247. It's not easy to read, and it breaks the knowledge of gpio number on schematic & datasheet.

Unless we don't use allocating gpio numbers dynamically and add a common property to parse gpio base of each chip in DTS file. It's also OK to me add a common property.

There is also one more problem with this reordering: if a GPIO chip with a base GPIO set gets probed *after* a bunch of chips without a proper base, its range in the number space is likely to have been stolen by one of the "dynamic" chips.

Ideally all chips would come with a base GPIO, but we cannot rule out hotplugable interfaces. Even more ideally the integer numberspace would go away altogether with the new gpiod interface and the sysfs interface would be replaced with one where exported GPIOs would be under their chip node, and referenced by their hw number. But that would break userspace even more. Or maybe there could be a config option to choose between the "legacy" integer-space user interface and this new scheme. Eventually, the number space could be deprecated.

Quoted 2 lines

Alex.

How about adding one property on declaring that the GPIO number space is in ascending order? Then it won't break the "legacy" decreasing order.

Regards
Haojian

#16 lore raw

PATCH v8 3/12 gpio: find gpio base by ascend order

In reply to Haojian Zhuang
Quoted 15 lines · Haojian Zhuang
Quoted 13 lines · Linus Walleij

This is more scary stuff.

As you know GPIO numbers are exposed to userspace.

Systems with this change risk having their dynamically added GPIO controller enumerated in a different fashion. And userspace clients may be relying on these numbers.

And we do not break userspace.

I know this is not elegant but I'm afraid the descending search needs to be kept for compatibibility reasons.

Quoted 6 lines
Quoted 4 lines

BTW: please CC Grant likely on all patches.

Yours,
Linus Walleij

But descending search isn't good for reading.

But you may be breaking userspace.

When I, as a subsystem maintainer merge a patch that break userspace interfaces, things like this happen:

https://lkml.org/lkml/2012/12/23/75
http://developers.slashdot.org/story/12/12/29/018234/linus-chews-up-kernel-maintainer-for-introducing-userspace-bug

You can argue all you want about wanting to change things that affect userspace for internal kernel refactoring or fit with device tree or whatever, it's just not going to happen, because the Big Penguin has installed a culture of fear around breaking userspace.

If you want the policy changed you can talk to Torvalds.

Quoted 4 lines

I try to allocate all gpio numbers in Hi3620 from gpiochip_find_base(). If it's descending search, GPIO0~7 is mapped to gpio248~255; GPIO8~GPIO15 is mapped to gpio240~gpio247. It's not easy to read, and it breaks the knowledge of gpio number on schematic & datasheet.

It may make things elegant and nice on your (new) system but break everyone else's, and they were first in the kernel, they may have userspace clients and so, we cannot change this.

Quoted 3 lines

Unless we don't use allocating gpio numbers dynamically and add a common property to parse gpio base of each chip in DTS file. It's also OK to me add a common property.

As explained elsewhere, global GPIO numbers don't belong in the device tree, as it is a Linux-specific pecularity. If this approach was chosen anyway, it would be named something like linux,gpio-base-offset

One compromise would be to add global setting like gpio_add_dynamic_gpios_ascendingly() that will change the behaviour on a *specific* system, or maybe on all device tree systems, and keep both code paths. Yes, it is ugly and unelegant, but with the userspace contract, what can we do? We do all sort of ugliness for userspace.

After reading this you may be on the clear why I am so hesitant about Roland Stigge's blocked GPIOs as well, that will become one more userspace ABI set in stone FOREVER.

I'd like Grant's input on this... he has the big view on GPIO plus device tree.

Yours,
Linus Walleij

author maintainer
#17 lore raw

PATCH v8 3/12 gpio: find gpio base by ascend order

Quoted 71 lines · Linus Walleij
Quoted 15 lines · Haojian Zhuang
Quoted 13 lines · Linus Walleij

This is more scary stuff.

As you know GPIO numbers are exposed to userspace.

Systems with this change risk having their dynamically added GPIO controller enumerated in a different fashion. And userspace clients may be relying on these numbers.

And we do not break userspace.

I know this is not elegant but I'm afraid the descending search needs to be kept for compatibibility reasons.

Quoted 6 lines
Quoted 4 lines

BTW: please CC Grant likely on all patches.

Yours,
Linus Walleij

But descending search isn't good for reading.

But you may be breaking userspace.

When I, as a subsystem maintainer merge a patch that break userspace interfaces, things like this happen:

https://lkml.org/lkml/2012/12/23/75
http://developers.slashdot.org/story/12/12/29/018234/linus-chews-up-kernel-maintainer-for-introducing-userspace-bug

You can argue all you want about wanting to change things that affect userspace for internal kernel refactoring or fit with device tree or whatever, it's just not going to happen, because the Big Penguin has installed a culture of fear around breaking userspace.

If you want the policy changed you can talk to Torvalds.

Quoted 4 lines

I try to allocate all gpio numbers in Hi3620 from gpiochip_find_base(). If it's descending search, GPIO0~7 is mapped to gpio248~255; GPIO8~GPIO15 is mapped to gpio240~gpio247. It's not easy to read, and it breaks the knowledge of gpio number on schematic & datasheet.

It may make things elegant and nice on your (new) system but break everyone else's, and they were first in the kernel, they may have userspace clients and so, we cannot change this.

Quoted 3 lines

Unless we don't use allocating gpio numbers dynamically and add a common property to parse gpio base of each chip in DTS file. It's also OK to me add a common property.

As explained elsewhere, global GPIO numbers don't belong in the device tree, as it is a Linux-specific pecularity. If this approach was chosen anyway, it would be named something like linux,gpio-base-offset

One compromise would be to add global setting like gpio_add_dynamic_gpios_ascendingly() that will change the behaviour on a *specific* system, or maybe on all device tree systems, and keep both code paths. Yes, it is ugly and unelegant, but with the userspace contract, what can we do? We do all sort of ugliness for userspace.

After reading this you may be on the clear why I am so hesitant about Roland Stigge's blocked GPIOs as well, that will become one more userspace ABI set in stone FOREVER.

Quoted 5 lines

I'd like Grant's input on this... he has the big view on GPIO plus device tree.

Yours,
Linus Walleij

Since it may break the userspace ABI, I agree that we shouldn't change current solution. Thanks for your kindly illustration.

In this patch series, I'll initialize pdata->gpio_base first and use aux structure in machine driver.

Then I'll try to something like "linux,gpio-base-offset" in GPIO system, and drop aux structure from machine driver. Since I'm expecting GPIO/PINCTRL could be similar as IRQ that everything could be parsed from DT, it could make driver simpler.

Best Regards
Haojian

author maintainer
#18 lore raw

PATCH v8 4/12 gpio: pl061: allocate irq dynamically

In reply to Haojian Zhuang

In original implementation, irq base is always specified in platform data. If it's not specified, pl061 gpio driver can't pass the probe() function since irq base is missing. While moving to device tree, everything should be parsed from DTS file. So allocate irq dynamically for irq base.

---
 drivers/gpio/gpio-pl061.c |   15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/gpio/gpio-pl061.c +12 -3
index b820869..fd26f63 100644
@@ -15,6 +15,7 @@
 #include <linux/io.h>
 #include <linux/ioport.h>
 #include <linux/irq.h>
+#include <linux/irqdomain.h>
 #include <linux/bitops.h>
 #include <linux/workqueue.h>
 #include <linux/gpio.h>
@@ -211,6 +212,10 @@ static void __init pl061_init_gc(struct pl061_gpio *chip, int irq_base)
 			       IRQ_GC_INIT_NESTED_LOCK, IRQ_NOREQUEST, 0);
 }
 
+static const struct irq_domain_ops pl061_domain_ops = {
+	.xlate	= irq_domain_xlate_twocell,
+};
+
 static int pl061_probe(struct amba_device *adev, const struct amba_id *id)
 {
 	struct device *dev = &adev->dev;
@@ -225,10 +230,14 @@ static int pl061_probe(struct amba_device *adev, const struct amba_id *id)
 	if (pdata) {
 		chip->gc.base = pdata->gpio_base;
 		chip->irq_base = pdata->irq_base;
-	} else if (adev->dev.of_node) {
+	} else {
 		chip->gc.base = -1;
-		chip->irq_base = 0;
-	} else
+		chip->irq_base = irq_alloc_descs(-1, 0, PL061_GPIO_NR, 0);
+		if (chip->irq_base < 0)
+			return chip->irq_base;
+	}
+	if (!irq_domain_add_legacy(adev->dev.of_node, PL061_GPIO_NR,
+				   chip->irq_base, 0, &pl061_domain_ops, chip))
 		return -ENODEV;
 
 	if (!devm_request_mem_region(dev, adev->res.start,
Signature · 1 line
1.7.10.4
author maintainer
#19 lore raw

PATCH v8 5/12 pinctrl: verify whether gpio chip overlapps range

In reply to Haojian Zhuang

pinctrl_get_device_gpio_range() only checks whether a certain GPIO pin is in gpio range. But maybe some GPIO pins don't have back-end pinctrl interface, it means that these pins are always configured as GPIO function.

Append pinctrl_overlapped_gpio_range() that is used to check whether the pins of GPIO chip are overlapped with pins in the GPIO range. This function will be called after pinctrl_get_device_gpio_range() fails.

If overlapped GPIO pins are found, it means that pinctrl device is already launched and a certain GPIO pin don't have back-end pinctrl interface. Then pinctrl_request_gpio() shouldn't return -EPROBE_DEFER in this case.

---
 drivers/pinctrl/core.c |   36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/pinctrl/core.c +36 -0
index 5a2fe9a..f5814cf 100644
@@ -27,6 +27,7 @@
 #include <linux/pinctrl/consumer.h>
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/machine.h>
+#include <asm-generic/gpio.h>
 #include "core.h"
 #include "devicetree.h"
 #include "pinmux.h"
@@ -293,6 +294,39 @@ pinctrl_match_gpio_range(struct pinctrl_dev *pctldev, unsigned gpio)
 }
 
 /**
+ * pinctrl_overlapped_gpio_range() - check if the GPIO chip of a certain GPIO
+ * pin is overlapped with gpio range.
+ * @gpio: gpio pin to check taken from the global GPIO pin space
+ *
+ * This function is complement of pinctrl_match_gpio_range(). If the return
+ * value of pinctrl_match_gpio_range() is NULL, this function could be used
+ * to check whether pinctrl device is ready or not. Maybe some GPIO pins
+ * don't have back-end pinctrl interface.
+ * If the return value is true, it means that pinctrl device is ready & the
+ * certain GPIO pin doesn't have back-end pinctrl device. If the return value
+ * is false, it means that pinctrl device may not be ready.
+ */
+static bool pinctrl_overlapped_gpio_range(unsigned gpio)
+{
+	struct pinctrl_dev *pctldev;
+	struct pinctrl_gpio_range *range = NULL;
+	struct gpio_chip *chip = gpio_to_chip(gpio);
+
+	/* Loop over the pin controllers */
+	list_for_each_entry(pctldev, &pinctrldev_list, node) {
+		/* Loop over the ranges */
+		list_for_each_entry(range, &pctldev->gpio_ranges, node) {
+			/* Check if any gpio range overlapped with gpio chip */
+			if (range->base + range->npins - 1 < chip->base ||
+			    range->base > chip->base + chip->ngpio - 1)
+				continue;
+			return true;
+		}
+	}
+	return false;
+}
+
+/**
  * pinctrl_get_device_gpio_range() - find device for GPIO range
  * @gpio: the pin to locate the pin controller for
  * @outdev: the pin control device if found
@@ -459,6 +493,8 @@ int pinctrl_request_gpio(unsigned gpio)
 
 	ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
 	if (ret) {
+		if (pinctrl_overlapped_gpio_range(gpio))
+			ret = 0;
 		mutex_unlock(&pinctrl_mutex);
 		return ret;
 	}
Signature · 1 line
1.7.10.4
author maintainer
#20 lore raw

PATCH v8 6/12 gpio: pl061: bind pinctrl by gpio request

In reply to Haojian Zhuang

Add the pl061_gpio_request() to request pinctrl. Create the logic between pl061 gpio driver and pinctrl (pinctrl-single) driver.

While a gpio pin is requested, it will request pinctrl driver to set that pin with gpio function mode. So pinctrl driver should append .gpio_request_enable() in pinmux_ops.

---
 drivers/gpio/gpio-pl061.c |   13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/gpio/gpio-pl061.c +13 -0
index fd26f63..292620c 100644
@@ -23,6 +23,7 @@
 #include <linux/amba/bus.h>
 #include <linux/amba/pl061.h>
 #include <linux/slab.h>
+#include <linux/pinctrl/consumer.h>
 #include <linux/pm.h>
 #include <asm/mach/irq.h>
 
@@ -61,6 +62,17 @@ struct pl061_gpio {
 #endif
 };
 
+static int pl061_gpio_request(struct gpio_chip *chip, unsigned offset)
+{
+	/*
+	 * Map back to global GPIO space and request muxing, the direction
+	 * parameter does not matter for this controller.
+	 */
+	int gpio = chip->base + offset;
+
+	return pinctrl_request_gpio(gpio);
+}
+
 static int pl061_direction_input(struct gpio_chip *gc, unsigned offset)
 {
 	struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
@@ -251,6 +263,7 @@ static int pl061_probe(struct amba_device *adev, const struct amba_id *id)
 
 	spin_lock_init(&chip->lock);
 
+	chip->gc.request = pl061_gpio_request;
 	chip->gc.direction_input = pl061_direction_input;
 	chip->gc.direction_output = pl061_direction_output;
 	chip->gc.get = pl061_get_value;
Signature · 1 line
1.7.10.4
author maintainer
#21 lore raw

PATCH v8 7/12 pinctrl: single: create new gpio function range

In reply to Haojian Zhuang

Since gpio driver could create gpio range in DTS, it could invokes pinctrl_request_gpio(). In the pinctrl-single driver, it needs to configure pins with gpio function mode.

A new gpio function range should be created in DTS file in below.

pinctrl-single,gpio-range = <phandle pin_offset nr_pins gpio_func>;

range: gpio-range {
	#pinctrl-single,gpio-range-cells = <3>;
};

The difference between gpio-ranges property in gpio driver and pinctrl-single,gpio-range property in pinctrl-single driver.

1. gpio-ranges = <phandle gpio_offset_in_chip pin_offset nr_pins>

	gpio-ranges = < &pmx0 0 89 1 &pmx0 1 89 1 &pmx0 2 90 1
			&pmx0 3 90 1 &pmx0 4 91 1 &pmx0 5 92 1>;

2. gpio driver could get pin offset from gpio-ranges property. pinctrl-single driver could get gpio function mode from gpio_func that is stored in @gpiofuncs list in struct pcs_device. This new pinctrl-single,gpio-range is used as complement for gpio-ranges property in gpio driver.

---
 drivers/pinctrl/pinctrl-single.c |   73 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 71 insertions(+), 2 deletions(-)
drivers/pinctrl/pinctrl-single.c +71 -2
index 5c32e88..8b9dd95 100644
@@ -77,6 +77,20 @@ struct pcs_function {
 };
 
 /**
+ * struct pcs_gpiofunc_range - pin ranges with same mux value of gpio function
+ * @offset:	offset base of pins
+ * @npins:	number pins with the same mux value of gpio function
+ * @gpiofunc:	mux value of gpio function
+ * @node:	list node
+ */
+struct pcs_gpiofunc_range {
+	unsigned offset;
+	unsigned npins;
+	unsigned gpiofunc;
+	struct list_head node;
+};
+
+/**
  * struct pcs_data - wrapper for data needed by pinctrl framework
  * @pa:		pindesc array
  * @cur:	index to current element
@@ -123,6 +137,7 @@ struct pcs_name {
  * @ftree:	function index radix tree
  * @pingroups:	list of pingroups
  * @functions:	list of functions
+ * @gpiofuncs:	list of gpio functions
  * @ngroups:	number of pingroups
  * @nfuncs:	number of functions
  * @desc:	pin controller descriptor
@@ -148,6 +163,7 @@ struct pcs_device {
 	struct radix_tree_root ftree;
 	struct list_head pingroups;
 	struct list_head functions;
+	struct list_head gpiofuncs;
 	unsigned ngroups;
 	unsigned nfuncs;
 	struct pinctrl_desc desc;
@@ -403,9 +419,26 @@ static void pcs_disable(struct pinctrl_dev *pctldev, unsigned fselector,
 }
 
 static int pcs_request_gpio(struct pinctrl_dev *pctldev,
-			struct pinctrl_gpio_range *range, unsigned offset)
+			    struct pinctrl_gpio_range *range, unsigned pin)
 {
-	return -ENOTSUPP;
+	struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev);
+	struct pcs_gpiofunc_range *frange = NULL;
+	struct list_head *pos, *tmp;
+	int mux_bytes = 0;
+	unsigned data;
+
+	list_for_each_safe(pos, tmp, &pcs->gpiofuncs) {
+		frange = list_entry(pos, struct pcs_gpiofunc_range, node);
+		if (pin >= frange->offset + frange->npins
+			|| pin < frange->offset)
+			continue;
+		mux_bytes = pcs->width / BITS_PER_BYTE;
+		data = pcs->read(pcs->base + pin * mux_bytes) & ~pcs->fmask;
+		data |= frange->gpiofunc;
+		pcs->write(data, pcs->base + pin * mux_bytes);
+		break;
+	}
+	return 0;
 }
 
 static struct pinmux_ops pcs_pinmux_ops = {
@@ -879,6 +912,37 @@ static void pcs_free_resources(struct pcs_device *pcs)
 
 static struct of_device_id pcs_of_match[];
 
+static int pcs_add_gpio_func(struct device_node *node, struct pcs_device *pcs)
+{
+	const char *propname = "pinctrl-single,gpio-range";
+	const char *cellname = "#pinctrl-single,gpio-range-cells";
+	struct of_phandle_args gpiospec;
+	struct pcs_gpiofunc_range *range;
+	int ret, i;
+
+	for (i = 0; ; i++) {
+		ret = of_parse_phandle_with_args(node, propname, cellname,
+						 i, &gpiospec);
+		/* Do not treat it as error. Only treat it as end condition. */
+		if (ret) {
+			ret = 0;
+			break;
+		}
+		range = devm_kzalloc(pcs->dev, sizeof(*range), GFP_KERNEL);
+		if (!range) {
+			ret = -ENOMEM;
+			break;
+		}
+		range->offset = gpiospec.args[0];
+		range->npins = gpiospec.args[1];
+		range->gpiofunc = gpiospec.args[2];
+		mutex_lock(&pcs->mutex);
+		list_add_tail(&range->node, &pcs->gpiofuncs);
+		mutex_unlock(&pcs->mutex);
+	}
+	return ret;
+}
+
 static int pcs_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
@@ -900,6 +964,7 @@ static int pcs_probe(struct platform_device *pdev)
 	mutex_init(&pcs->mutex);
 	INIT_LIST_HEAD(&pcs->pingroups);
 	INIT_LIST_HEAD(&pcs->functions);
+	INIT_LIST_HEAD(&pcs->gpiofuncs);
 
 	PCS_GET_PROP_U32("pinctrl-single,register-width", &pcs->width,
 			 "register width not specified\n");
@@ -975,6 +1040,10 @@ static int pcs_probe(struct platform_device *pdev)
 		goto free;
 	}
 
+	ret = pcs_add_gpio_func(np, pcs);
+	if (ret < 0)
+		goto free;
+
 	dev_info(pcs->dev, "%i pins at pa %p size %u\n",
 		 pcs->desc.npins, pcs->base, pcs->size);
 
Signature · 1 line
1.7.10.4
author maintainer
#22 lore raw

PATCH v8 8/12 pinctrl: generic: dump pin configuration

In reply to Haojian Zhuang

Add the support of dumping pin configuration.

---
 drivers/pinctrl/pinconf-generic.c |   12 ++++++++++++
 drivers/pinctrl/pinconf.h         |    8 ++++++++
 2 files changed, 20 insertions(+)
drivers/pinctrl/pinconf-generic.c +12 -0
index e5948f8..66e4ae5 100644
@@ -120,4 +120,16 @@ void pinconf_generic_dump_group(struct pinctrl_dev *pctldev,
 	}
 }
 
+void pinconf_generic_dump_config(struct pinctrl_dev *pctldev,
+				 struct seq_file *s, unsigned long config)
+{
+	int i;
+
+	for(i = 0; i < ARRAY_SIZE(conf_items); i++) {
+		if (pinconf_to_config_param(config) != conf_items[i].param)
+			continue;
+		seq_printf(s, "%s: 0x%x", conf_items[i].display,
+			   pinconf_to_config_argument(config));
+	}
+}
 #endif
drivers/pinctrl/pinconf.h +8 -0
index e3ed8cb..8023421 100644
@@ -98,6 +98,8 @@ void pinconf_generic_dump_pin(struct pinctrl_dev *pctldev,
 void pinconf_generic_dump_group(struct pinctrl_dev *pctldev,
 			      struct seq_file *s, const char *gname);
 
+void pinconf_generic_dump_config(struct pinctrl_dev *pctldev,
+				 struct seq_file *s, unsigned long config);
 #else
 
 static inline void pinconf_generic_dump_pin(struct pinctrl_dev *pctldev,
@@ -114,4 +116,10 @@ static inline void pinconf_generic_dump_group(struct pinctrl_dev *pctldev,
 	return;
 }
 
+static void pinconf_generic_dump_config(struct pinctrl_dev *pctldev,
+					struct seq_file *s,
+					unsigned long config)
+{
+	return;
+}
 #endif
Signature · 1 line
1.7.10.4
maintainer
#23 lore raw

PATCH v8 8/12 pinctrl: generic: dump pin configuration

drivers/pinctrl/pinconf.h static inline void pinconf_generic_dump_group(struct pinctrl_dev *pctldev, · line 125

Quoted 11 lines · Haojian Zhuang
drivers/pinctrl/pinconf.h +6 -0
@@ -114,4 +116,10 @@ static inline void pinconf_generic_dump_group(struct pinctrl_dev *pctldev,
 	return;
 }
 
+static void pinconf_generic_dump_config(struct pinctrl_dev *pctldev,
+					struct seq_file *s,
+					unsigned long config)
+{
+	return;
+}
 #endif

This needs to be static inline void to avoid the following warning:

drivers/pinctrl/pinconf.h:122: warning: ?pinconf_generic_dump_config? defined but not used

Regards,

Tony

maintainer
#24 lore raw

PATCH v8 8/12 pinctrl: generic: dump pin configuration

Quoted 15 lines · Tony Lindgren

Review static inline void pinconf_generic_dump_group(struct pinctrl_dev *pctldev, · line 125

Quoted 11 lines · Haojian Zhuang
(quoted diff) +6 -0
@@ -114,4 +116,10 @@ static inline void pinconf_generic_dump_group(struct pinctrl_dev *pctldev,
 	return;
 }
 
+static void pinconf_generic_dump_config(struct pinctrl_dev *pctldev,
+					struct seq_file *s,
+					unsigned long config)
+{
+	return;
+}
 #endif

This needs to be static inline void to avoid the following warning:

Quoted 1 line

drivers/pinctrl/pinconf.h:122: warning: ?pinconf_generic_dump_config? defined but not used

Actually this patch needs few other changes to export it and compile, here's the version that worked for me with pinctlr-single as a module:

drivers/pinctrl/pinconf-generic.c +16 -0
@@ -16,6 +16,7 @@
 #include <linux/device.h>
 #include <linux/slab.h>
 #include <linux/debugfs.h>
+#include <linux/module.h>
 #include <linux/seq_file.h>
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/pinconf.h>
@@ -120,4 +121,19 @@ void pinconf_generic_dump_group(struct pinctrl_dev *pctldev,
 	}
 }
 
+int pinconf_generic_dump_config(struct pinctrl_dev *pctldev,
+				 struct seq_file *s, unsigned long config)
+{
+	int i;
+
+	for(i = 0; i < ARRAY_SIZE(conf_items); i++) {
+		if (pinconf_to_config_param(config) != conf_items[i].param)
+			continue;
+		seq_printf(s, "%s: 0x%x", conf_items[i].display,
+			   pinconf_to_config_argument(config));
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(pinconf_generic_dump_config);
 #endif
drivers/pinctrl/pinconf.h +8 -0
index e3ed8cb..c91ea3e 100644
@@ -98,6 +98,8 @@ void pinconf_generic_dump_pin(struct pinctrl_dev *pctldev,
 void pinconf_generic_dump_group(struct pinctrl_dev *pctldev,
 			      struct seq_file *s, const char *gname);
 
+int pinconf_generic_dump_config(struct pinctrl_dev *pctldev,
+				 struct seq_file *s, unsigned long config);
 #else
 
 static inline void pinconf_generic_dump_pin(struct pinctrl_dev *pctldev,
@@ -114,4 +116,10 @@ static inline void pinconf_generic_dump_group(struct pinctrl_dev *pctldev,
 	return;
 }
 
+static inline int pinconf_generic_dump_config(struct pinctrl_dev *pctldev,
+					struct seq_file *s,
+					unsigned long config)
+{
+	return;
+}
 #endif
author maintainer
#25 lore raw

PATCH v8 8/12 pinctrl: generic: dump pin configuration

Quoted 16 lines · Tony Lindgren
Quoted 15 lines · Tony Lindgren

drivers/pinctrl/pinconf.h static inline void pinconf_generic_dump_group(struct pinctrl_dev *pctldev, · line 125

Quoted 11 lines · Haojian Zhuang
drivers/pinctrl/pinconf.h +6 -0
@@ -114,4 +116,10 @@ static inline void pinconf_generic_dump_group(struct pinctrl_dev *pctldev,
    return;
 }
 
+static void pinconf_generic_dump_config(struct pinctrl_dev *pctldev,
+                                   struct seq_file *s,
+                                   unsigned long config)
+{
+   return;
+}
 #endif

This needs to be static inline void to avoid the following warning:

Quoted 5 lines
Quoted 1 line

drivers/pinctrl/pinconf.h:122: warning: ?pinconf_generic_dump_config? defined but not used

Actually this patch needs few other changes to export it and compile, here's the version that worked for me with pinctlr-single as a module:

Thanks. I'll follow your changes.

Regards
Haojian

Quoted 54 lines
drivers/pinctrl/pinconf-generic.c +16 -0
@@ -16,6 +16,7 @@
 #include <linux/device.h>
 #include <linux/slab.h>
 #include <linux/debugfs.h>
+#include <linux/module.h>
 #include <linux/seq_file.h>
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/pinconf.h>
@@ -120,4 +121,19 @@ void pinconf_generic_dump_group(struct pinctrl_dev *pctldev,
        }
 }
 
+int pinconf_generic_dump_config(struct pinctrl_dev *pctldev,
+                                struct seq_file *s, unsigned long config)
+{
+       int i;
+
+       for(i = 0; i < ARRAY_SIZE(conf_items); i++) {
+               if (pinconf_to_config_param(config) != conf_items[i].param)
+                       continue;
+               seq_printf(s, "%s: 0x%x", conf_items[i].display,
+                          pinconf_to_config_argument(config));
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL(pinconf_generic_dump_config);
 #endif
drivers/pinctrl/pinconf.h +8 -0
index e3ed8cb..c91ea3e 100644
@@ -98,6 +98,8 @@ void pinconf_generic_dump_pin(struct pinctrl_dev *pctldev,
 void pinconf_generic_dump_group(struct pinctrl_dev *pctldev,
                              struct seq_file *s, const char *gname);
 
+int pinconf_generic_dump_config(struct pinctrl_dev *pctldev,
+                                struct seq_file *s, unsigned long config);
 #else
 
 static inline void pinconf_generic_dump_pin(struct pinctrl_dev *pctldev,
@@ -114,4 +116,10 @@ static inline void pinconf_generic_dump_group(struct pinctrl_dev *pctldev,
        return;
 }
 
+static inline int pinconf_generic_dump_config(struct pinctrl_dev *pctldev,
+                                       struct seq_file *s,
+                                       unsigned long config)
+{
+       return;
+}
 #endif
author maintainer
#26 lore raw

PATCH v8 8/12 pinctrl: generic: dump pin configuration

In reply to Tony Lindgren
Quoted 15 lines · Tony Lindgren

drivers/pinctrl/pinconf.h static inline void pinconf_generic_dump_group(struct pinctrl_dev *pctldev, · line 125

Quoted 11 lines · Haojian Zhuang
drivers/pinctrl/pinconf.h +6 -0
@@ -114,4 +116,10 @@ static inline void pinconf_generic_dump_group(struct pinctrl_dev *pctldev,
      return;
 }
 
+static void pinconf_generic_dump_config(struct pinctrl_dev *pctldev,
+                                     struct seq_file *s,
+                                     unsigned long config)
+{
+     return;
+}
 #endif

This needs to be static inline void to avoid the following warning:

Quoted 5 lines

drivers/pinctrl/pinconf.h:122: warning: ?pinconf_generic_dump_config? defined but not used

Regards,

Tony

Thanks. I'll update it.

Regards
Haojian

author maintainer
#27 lore raw

PATCH v8 9/12 pinctrl: single: set function mask as optional

In reply to Haojian Zhuang

Since Hisilicon's pin controller is divided into two parts. One is the function mux, and the other is pin configuration. These two parts are in the different memory regions. So make pinctrl-single,function-mask as optional property. Then we can define pingroups without valid function mux that is only used for pin configuration.

---
 drivers/pinctrl/pinctrl-single.c |   26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/pinctrl/pinctrl-single.c +22 -4
index 8b9dd95..fe8f321 100644
@@ -350,6 +350,9 @@ static int pcs_enable(struct pinctrl_dev *pctldev, unsigned fselector,
 	int i;
 
 	pcs = pinctrl_dev_get_drvdata(pctldev);
+	/* If function mask is null, needn't enable it. */
+	if (!pcs->fmask)
+		return 0;
 	func = radix_tree_lookup(&pcs->ftree, fselector);
 	if (!func)
 		return -EINVAL;
@@ -384,6 +387,10 @@ static void pcs_disable(struct pinctrl_dev *pctldev, unsigned fselector,
 	int i;
 
 	pcs = pinctrl_dev_get_drvdata(pctldev);
+	/* If function mask is null, needn't disable it. */
+	if (!pcs->fmask)
+		return;
+
 	func = radix_tree_lookup(&pcs->ftree, fselector);
 	if (!func) {
 		dev_err(pcs->dev, "%s could not find function%i\n",
@@ -427,6 +434,10 @@ static int pcs_request_gpio(struct pinctrl_dev *pctldev,
 	int mux_bytes = 0;
 	unsigned data;
 
+	/* If function mask is null, return directly. */
+	if (!pcs->fmask)
+		return -ENOTSUPP;
+
 	list_for_each_safe(pos, tmp, &pcs->gpiofuncs) {
 		frange = list_entry(pos, struct pcs_gpiofunc_range, node);
 		if (pin >= frange->offset + frange->npins
@@ -969,10 +980,17 @@ static int pcs_probe(struct platform_device *pdev)
 	PCS_GET_PROP_U32("pinctrl-single,register-width", &pcs->width,
 			 "register width not specified\n");
 
-	PCS_GET_PROP_U32("pinctrl-single,function-mask", &pcs->fmask,
-			 "function register mask not specified\n");
-	pcs->fshift = ffs(pcs->fmask) - 1;
-	pcs->fmax = pcs->fmask >> pcs->fshift;
+	ret = of_property_read_u32(np, "pinctrl-single,function-mask",
+				   &pcs->fmask);
+	if (!ret) {
+		pcs->fshift = ffs(pcs->fmask) - 1;
+		pcs->fmax = pcs->fmask >> pcs->fshift;
+	} else {
+		/* If mask property doesn't exist, function mux is invalid. */
+		pcs->fmask = 0;
+		pcs->fshift = 0;
+		pcs->fmax = 0;
+	}
 
 	ret = of_property_read_u32(np, "pinctrl-single,function-off",
 					&pcs->foff);
Signature · 1 line
1.7.10.4
author maintainer
#28 lore raw

PATCH v8 10/12 pinctrl: single: support generic pinconf

In reply to Haojian Zhuang

Support the operation of generic pinconf. The supported config arguments are INPUT_SCHMITT, INPUT_SCHMITT_DISABLE, POWER_SOURCE, BIAS_DISABLE, BIAS_PULLUP, BIAS_PULLDOWN, SLEW_RATE.

---
 drivers/pinctrl/Kconfig          |    1 +
 drivers/pinctrl/pinctrl-single.c |  339 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 333 insertions(+), 7 deletions(-)
drivers/pinctrl/Kconfig +1 -0
index 9db3497..066581c 100644
@@ -154,6 +154,7 @@ config PINCTRL_SINGLE
 	depends on OF
 	select PINMUX
 	select PINCONF
+	select GENERIC_PINCONF
 	help
 	  This selects the device tree based generic pinctrl driver.
 
drivers/pinctrl/pinctrl-single.c +332 -7

475 lines not on this page · raw message

Signature · 1 line
1.7.10.4
maintainer
#29 lore raw

PATCH v8 10/12 pinctrl: single: support generic pinconf

drivers/pinctrl/pinctrl-single.c line 31

Quoted 13 lines · Haojian Zhuang
drivers/pinctrl/pinctrl-single.c +2 -0
@@ -22,8 +22,10 @@
 
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/pinmux.h>
+#include <linux/pinctrl/pinconf-generic.h>
 
 #include "core.h"
+#include "pinconf.h"
 
 #define DRIVER_NAME			"pinctrl-single"
 #define PCS_MUX_PINS_NAME		"pinctrl-single,pins"

I'm getting the following with this patch applied:

"pinconf_generic_dump_config" [drivers/pinctrl/pinctrl-single.ko] undefined!

This is with the following options:

CONFIG_PINCTRL=y
CONFIG_PINMUX=y
CONFIG_PINCONF=y
CONFIG_GENERIC_PINCONF=y
CONFIG_DEBUG_PINCTRL=y
CONFIG_PINCTRL_SINGLE=m

The includes look right, probably you're just missing EXPORT_SYMBOL(pinconf_generic_dump_config) in the patch adding pinconf_generic_dump_config?

Regards,

Tony

author maintainer
#30 lore raw

PATCH v8 10/12 pinctrl: single: support generic pinconf

Quoted 28 lines · Tony Lindgren

drivers/pinctrl/pinctrl-single.c line 31

Quoted 13 lines · Haojian Zhuang
drivers/pinctrl/pinctrl-single.c +2 -0
@@ -22,8 +22,10 @@
 
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/pinmux.h>
+#include <linux/pinctrl/pinconf-generic.h>
 
 #include "core.h"
+#include "pinconf.h"
 
 #define DRIVER_NAME                  "pinctrl-single"
 #define PCS_MUX_PINS_NAME            "pinctrl-single,pins"

I'm getting the following with this patch applied:

"pinconf_generic_dump_config" [drivers/pinctrl/pinctrl-single.ko] undefined!

This is with the following options:

CONFIG_PINCTRL=y
CONFIG_PINMUX=y
CONFIG_PINCONF=y
CONFIG_GENERIC_PINCONF=y
CONFIG_DEBUG_PINCTRL=y
CONFIG_PINCTRL_SINGLE=m

Quoted 7 lines

The includes look right, probably you're just missing EXPORT_SYMBOL(pinconf_generic_dump_config) in the patch adding pinconf_generic_dump_config?

Regards,

Tony

Thanks for your catch. I'll fix it right now.

Regards
Haojian

author maintainer
#31 lore raw

PATCH v8 11/12 ARM: hs: enable hi4511 with device tree

In reply to Haojian Zhuang

Enable Hisilicon Hi4511 development platform with device tree support.

---
 arch/arm/boot/dts/Makefile    |    1 +
 arch/arm/boot/dts/hi3620.dtsi |  556 +++++++++++++++++++++++++++++
 arch/arm/boot/dts/hi4511.dts  |  772 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1329 insertions(+)
 create mode 100644 arch/arm/boot/dts/hi3620.dtsi
 create mode 100644 arch/arm/boot/dts/hi4511.dts
arch/arm/boot/dts/Makefile +1 -0
index ea2c272..2a22336 100644
@@ -50,6 +50,7 @@ dtb-$(CONFIG_ARCH_EXYNOS) += exynos4210-origen.dtb \
 	exynos5440-ssdk5440.dtb
 dtb-$(CONFIG_ARCH_HIGHBANK) += highbank.dtb \
 	ecx-2000.dtb
+dtb-$(CONFIG_ARCH_HS) += hi4511.dtb
 dtb-$(CONFIG_ARCH_INTEGRATOR) += integratorap.dtb \
 	integratorcp.dtb
 dtb-$(CONFIG_ARCH_LPC32XX) += ea3250.dtb phy3250.dtb
arch/arm/boot/dts/hi3620.dtsi new file +556 -0

556 lines not on this page · raw message

arch/arm/boot/dts/hi4511.dts new file +772 -0

772 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author maintainer
#32 lore raw

PATCH v8 12/12 document: devicetree: bind pinconf with pin single

In reply to Haojian Zhuang

From: Haojian Zhuang <[email protected]>

Add comments with pinconf & gpio range in the document of pinctrl-single.

---
 .../devicetree/bindings/pinctrl/pinctrl-single.txt |  108 +++++++++++++++++++-
 1 file changed, 107 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt +107 -1
index 2c81e45..eeb2e93 100644
@@ -1,7 +1,9 @@
 One-register-per-pin type device tree based pinctrl driver
 
 Required properties:
-- compatible : "pinctrl-single"
+- compatible : "pinctrl-single" or "pinconf-single".
+  "pinctrl-single" means that pinconf isn't supported.
+  "pinconf-single" means that generic pinconf is supported.
 
 - reg : offset and length of the register set for the mux registers
 
@@ -14,9 +16,61 @@ Optional properties:
 - pinctrl-single,function-off : function off mode for disabled state if
   available and same for all registers; if not specified, disabling of
   pin functions is ignored
+
 - pinctrl-single,bit-per-mux : boolean to indicate that one register controls
   more than one pin
 
+- pinctrl-single,drive-strength : array of value that are used to configure
+  drive strength in the pinmux register. They're value of drive strength
+  current and drive strength mask.
+
+		/* drive strength current, mask */
+		pinctrl-single,power-source = <0x30 0xf0>;
+
+- pinctrl-single,bias-disable : array of value that are used to configure the
+  input bias disabled in the pinmux register. They're value of bias value,
+  match bias disabled value and bias disabled mask.
+
+		/* bias value, match bias disabled value, mask */
+		pinctrl-single,bias-disable = <2 0 3>;
+
+- pinctrl-single,bias-pullup : array of value that are used to configure the
+  input bias pullup in the pinmux register. They're value of bias value,
+  match bias pullup value and bias pullup mask.
+
+		/* bias value, match bias pullup value, mask */
+		pinctrl-single,bias-pullup = <0 1 1>;
+
+- pinctrl-single,bias-pulldown : array of value that are used to configure the
+  input bias pulldown in the pinmux register. They're value of bias value,
+  match bias pulldown value and bias pulldown mask.
+
+		/* bias value, match bias pulldown value, mask */
+		pinctrl-single,bias-pulldown = <2 2 2>;
+
+- pinctrl-single,input-schmitt : array of value that are used to configure
+  input schmitt in the pinmux register. In some silicons, there're two input
+  schmitt value (rising-edge & falling-edge) in the pinmux register.
+
+		/* input schmitt value, mask */
+		pinctrl-single,input-schmitt = <0x30 0x70>;
+
+- pinctrl-single,input-schmitt-disable : array of value that are used to
+  configure input schmitt disabled in the pinmux register. They're value of
+  input schmitt field, match disable value & mask.
+
+		/* input schmitt value, match disable value, mask */
+		pinctrl-single,input-schmitt-disable = <0x30 0x40 0x70>;
+
+- pinctrl-single,gpio-range : list of value that are used to configure a GPIO
+  range. They're value of subnode phandle, pin base in pinctrl device, pin
+  number in this range, GPIO function value of this GPIO range.
+  The number of parameters is depend on #pinctrl-single,gpio-range-cells
+  property.
+
+		/* pin base, nr pins & gpio function */
+		pinctrl-single,gpio-range = <&range 0 3 0 &range 3 9 1>;
+
 This driver assumes that there is only one register for each pin (unless the
 pinctrl-single,bit-per-mux is set), and uses the common pinctrl bindings as
 specified in the pinctrl-bindings.txt document in this directory.
@@ -42,6 +96,20 @@ Where 0xdc is the offset from the pinctrl register base address for the
 device pinctrl register, 0x18 is the desired value, and 0xff is the sub mask to
 be used when applying this change to the register.
 
+
+Optional sub-node: In case some pins could be configured as GPIO in the pinmux
+register, those pins could be defined as a GPIO range. This sub-node is required
+by pinctrl-single,gpio-range property.
+
+Required properties in sub-node:
+- #pinctrl-single,gpio-range-cells : the number of parameters after phandle in
+  pinctrl-single,gpio-range property.
+
+	range: gpio-range {
+		#pinctrl-single,gpio-range-cells = <3>;
+	};
+
+
 Example:
 
 /* SoC common file */
@@ -76,6 +144,29 @@ control_devconf0: pinmux at 48002274 {
 	pinctrl-single,function-mask = <0x5F>;
 };
 
+/* third controller instance for pins in gpio domain */
+pmx_gpio: pinmux at d401e000 {
+	compatible = "pinconf-single";
+	reg = <0xd401e000 0x0330>;
+	#address-cells = <1>;
+	#size-cells = <1>;
+	ranges;
+
+	pinctrl-single,register-width = <32>;
+	pinctrl-single,function-mask = <7>;
+
+	/* sparse GPIO range could be supported */
+	pinctrl-single,gpio-range = <&range 0 3 0 &range 3 9 1
+				&range 12 1 0 &range 13 29 1
+				&range 43 1 0 &range 44 49 1
+				&range 94 1 1 &range 96 2 1>;
+
+	range: gpio-range {
+		#pinctrl-single,gpio-range-cells = <3>;
+	};
+};
+
+
 /* board specific .dts file */
 
 &pmx_core {
@@ -96,6 +187,16 @@ control_devconf0: pinmux at 48002274 {
 		>;
 	};
 
+	uart0_pins: pinmux_uart0_pins {
+		pinctrl-single,pins = <
+			0x208 0		/* UART0_RXD (IOCFG138) */
+			0x20c 0		/* UART0_TXD (IOCFG139) */
+		>;
+		pinctrl-single,bias-pulldown = <0 2 2>;
+		pinctrl-single,bias-pullup = <0 1 1>;
+		pinctrl-single,bias-disable = <0 0 3>;
+	};
+
 	/* map uart2 pins */
 	uart2_pins: pinmux_uart2_pins {
 		pinctrl-single,pins = <
@@ -122,6 +223,11 @@ control_devconf0: pinmux@48002274 {
 
 };
 
+&uart1 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&uart0_pins>;
+};
+
 &uart2 {
        pinctrl-names = "default";
        pinctrl-0 = <&uart2_pins>;
Signature · 1 line
1.7.10.4
maintainer
#33 lore raw

PATCH v8 12/12 document: devicetree: bind pinconf with pin single

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt Optional properties: · line 29

Quoted 7 lines · Haojian Zhuang

+- pinctrl-single,drive-strength : array of value that are used to configure

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt +6 -0
+  drive strength in the pinmux register. They're value of drive strength
+  current and drive strength mask.
+
+		/* drive strength current, mask */
+		pinctrl-single,power-source = <0x30 0xf0>;
+

Looks like a typo, this should probably say pinctrl-single,drive-strength here instead of power-source?

For the cases where there's a value to be set I'm still wondering how does a client driver change the value if that needs to be changed dynamically? Can the value be passed as value + PIN_CONFIG_END?

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt Optional properties: · line 36

Quoted 7 lines

+- pinctrl-single,bias-disable : array of value that are used to configure the

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt +6 -0
+  input bias disabled in the pinmux register. They're value of bias value,
+  match bias disabled value and bias disabled mask.
+
+		/* bias value, match bias disabled value, mask */
+		pinctrl-single,bias-disable = <2 0 3>;
+

I still suggest we use "enable" naming instead of "disable" naming. So pinctrl-single,bias-enable instead of pinctrl-single,bias-disable.

Then let's change the binding slightly to make it more readable:

		/* enable value, disable value, mask */
		pinctrl-single,bias-enable = <2 0 3>;

For example, I have bit 22 cleared to enable MMC PBIAS, or bit 22 set to disable PBIAS:

		                             /* enable disable  mask */
		pinctrl-single,bias-enable = <0x000000 0x400000 0x400000>;

Then I think pretty much the only change to pinconf_get() would be:

	data = pcs->read(pcs->base + offset) & func->conf[i].mask;

	switch (func->conf[i].param) {
	/* 3 parameters */
	case PIN_CONFIG_BIAS_ENABLE:
	case PIN_CONFIG_BIAS_PULL_DOWN:
	case PIN_CONFIG_BIAS_PULL_UP:
	case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
	*config = data;
	if (data == func->conf[i].enable)
		res = 0;
	else
		res = -ENOTSUPP;
	break;
	...

And then the client driver can always assume that if the return value is 0, the ENABLE value in question is set. And if -ENOTSUPP (or how about -ENOTSET :) is returned, the ENABLE value is not set?

Then regarding pinconf_set(), don't we also need pinconf_clear() in addition to pinconf_set()?

Otherwise we need both ENABLE and DISABLE enumeration, which seems unnecessary to me. So rather than have both PIN_CONFIG_BIAS_ENABLE and PIN_CONFIG_BIAS_DISABLE, we just need PIN_CONFIG_BIAS_ENABLE.

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt Optional properties: · line 42

Quoted 6 lines

+- pinctrl-single,bias-pullup : array of value that are used to configure the

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt +5 -0
+  input bias pullup in the pinmux register. They're value of bias value,
+  match bias pullup value and bias pullup mask.
+
+		/* bias value, match bias pullup value, mask */
+		pinctrl-single,bias-pullup = <0 1 1>;

It seems that you could then use same generic comment in all places then to make it a bit easier to read:

		/* enable value, disable value, mask */
		pinctrl-single,bias-pullup = <0 1 1>;

...

Regards,

Tony

#34 lore raw

PATCH v8 12/12 document: devicetree: bind pinconf with pin single

Quoted 12 lines · Tony Lindgren

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt Optional properties: · line 29

Quoted 7 lines · Haojian Zhuang

+- pinctrl-single,drive-strength : array of value that are used to configure

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt +6 -0
+  drive strength in the pinmux register. They're value of drive strength
+  current and drive strength mask.
+
+             /* drive strength current, mask */
+             pinctrl-single,power-source = <0x30 0xf0>;
+

Looks like a typo, this should probably say pinctrl-single,drive-strength here instead of power-source?

Yes, I should update it to drive strength.

Quoted 4 lines

For the cases where there's a value to be set I'm still wondering how does a client driver change the value if that needs to be changed dynamically? Can the value be passed as value + PIN_CONFIG_END?

pinconf_to_config_packed() can help to bind param & argument into config variable.

Quoted 13 lines

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt Optional properties: · line 36

Quoted 7 lines

+- pinctrl-single,bias-disable : array of value that are used to configure the

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt +6 -0
+  input bias disabled in the pinmux register. They're value of bias value,
+  match bias disabled value and bias disabled mask.
+
+             /* bias value, match bias disabled value, mask */
+             pinctrl-single,bias-disable = <2 0 3>;
+

I still suggest we use "enable" naming instead of "disable" naming. So pinctrl-single,bias-enable instead of pinctrl-single,bias-disable.

Then let's change the binding slightly to make it more readable:

Quoted 9 lines
                /* enable value, disable value, mask */
                pinctrl-single,bias-enable = <2 0 3>;

For example, I have bit 22 cleared to enable MMC PBIAS, or bit 22 set to disable PBIAS:

                                             /* enable disable  mask */
                pinctrl-single,bias-enable = <0x000000 0x400000 0x400000>;

In Hi3620 SoC, the bias could only be configured pull up or pull down. There's no any bit for controlling bias enable or bias disable. But user may need to remove both pullup and pulldown at runtime. In this case, I set bias disable if there's no pullup & pulldown.

* Without bias enable/disable bit.

            bias-disable = <user input value, expected disable value, mask>;
            bias-pullup = <user input value, expected pullup value, mask>;
      "expected disable value" is the set of not pullup bit and not

pull down bit.
"expected pullup value" is the set of pullup bit.

* With bias enable/disable bit.
"expected disable value" is the set of disable bit, NOT pullup
bit and NOT pulldown bit.
"expected pullup value" is the set of NOT disable bit & pullup bit.

PULLUP --> DISABLE: only need to set the expected disable value in bias-disable property.
DISABLE --> PULLUP: only need to set the expected pullup value in bias-pullup property.
PULLUP --> PULLDOWN: set the expected pulldown value. So both pullup and pulldown
bits are enabled unless user call DISABLE first.. Maybe it's not right. I can fix it and keep
either pullup or pulldown enabled. It's ok to add pinconf_clear() for bias as you mentioned.

And I think that we need four parameters with your format.
<user setting on bias enable/disable, expected enable value,
expected disable value, mask */
Otherwise, how could we know user's setting? Especially, we need to configure pullup.
In your case, expected pullup enable & expected pullup disable are set in bias-pullup property.

Quoted 2 lines
                /* enable value, disable value, mask */
                pinctrl-single,bias-pullup = <0 1 1>;

Actually, I'm OK to use enable value. And it needs 4 parameters since disable value may not be zero.

By the way, bias property would be the format in below with 4 parameters.
* Without bias enable/disable bit.

          bias-enable = <0, 0, 0, set of both pullup and pulldown mask>;

* With bias enable/disable bit.
bias-enable = <user setting, expected enable, expected
disable, mask of only enable/disable bit>;

Behavior of pinconf_clear():
- call bias-disable
- call the expected bias setting.

DISABLE --> PULLUP, user call config BIAS_PULLUP without additional argument. PULLUP --> PULLDOWN, user call with config BIAS_PULLDOWN without additional argument.
PULLUP --> DISABLE, user call with config BIAS_ENABLE and 0 for argument.

The switch from PULLUP to DISABLE is a little strange since we have to call BIAS_ENABLE.
Is it good for you?

Quoted 18 lines

Then I think pretty much the only change to pinconf_get() would be:

        data = pcs->read(pcs->base + offset) & func->conf[i].mask;

        switch (func->conf[i].param) {
        /* 3 parameters */
        case PIN_CONFIG_BIAS_ENABLE:
        case PIN_CONFIG_BIAS_PULL_DOWN:
        case PIN_CONFIG_BIAS_PULL_UP:
        case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
        *config = data;
        if (data == func->conf[i].enable)
                res = 0;
        else
                res = -ENOTSUPP;
        break;
        ...
Quoted 4 lines

And then the client driver can always assume that if the return value is 0, the ENABLE value in question is set. And if -ENOTSUPP (or how about -ENOTSET :) is returned, the ENABLE value is not set?

Return constant value 0 is better. I'll update.

Quoted 6 lines

Then regarding pinconf_set(), don't we also need pinconf_clear() in addition to pinconf_set()?

Otherwise we need both ENABLE and DISABLE enumeration, which seems unnecessary to me. So rather than have both PIN_CONFIG_BIAS_ENABLE and PIN_CONFIG_BIAS_DISABLE, we just need PIN_CONFIG_BIAS_ENABLE.

I can append pinconf_clear() to handle it.

Quoted 8 lines

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt Optional properties: · line 42

Quoted 7 lines

+- pinctrl-single,bias-pullup : array of value that are used to configure the

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt +5 -0
+  input bias pullup in the pinmux register. They're value of bias value,
+  match bias pullup value and bias pullup mask.
+
+             /* bias value, match bias pullup value, mask */
+             pinctrl-single,bias-pullup = <0 1 1>;
Quoted 5 lines

It seems that you could then use same generic comment in all places then to make it a bit easier to read:

                /* enable value, disable value, mask */
                pinctrl-single,bias-pullup = <0 1 1>;

Discussed above.

#35 lore raw

PATCH v8 12/12 document: devicetree: bind pinconf with pin single

Quoted 97 lines · Haojian Zhuang
Quoted 12 lines · Tony Lindgren

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt Optional properties: · line 29

Quoted 7 lines · Haojian Zhuang

+- pinctrl-single,drive-strength : array of value that are used to configure

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt +6 -0
+  drive strength in the pinmux register. They're value of drive strength
+  current and drive strength mask.
+
+             /* drive strength current, mask */
+             pinctrl-single,power-source = <0x30 0xf0>;
+

Looks like a typo, this should probably say pinctrl-single,drive-strength here instead of power-source?

Yes, I should update it to drive strength.

Quoted 4 lines

For the cases where there's a value to be set I'm still wondering how does a client driver change the value if that needs to be changed dynamically? Can the value be passed as value + PIN_CONFIG_END?

pinconf_to_config_packed() can help to bind param & argument into config variable.

Quoted 13 lines

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt Optional properties: · line 36

Quoted 7 lines

+- pinctrl-single,bias-disable : array of value that are used to configure the

Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt +6 -0
+  input bias disabled in the pinmux register. They're value of bias value,
+  match bias disabled value and bias disabled mask.
+
+             /* bias value, match bias disabled value, mask */
+             pinctrl-single,bias-disable = <2 0 3>;
+

I still suggest we use "enable" naming instead of "disable" naming. So pinctrl-single,bias-enable instead of pinctrl-single,bias-disable.

Then let's change the binding slightly to make it more readable:

Quoted 9 lines
                /* enable value, disable value, mask */
                pinctrl-single,bias-enable = <2 0 3>;

For example, I have bit 22 cleared to enable MMC PBIAS, or bit 22 set to disable PBIAS:

                                             /* enable disable  mask */
                pinctrl-single,bias-enable = <0x000000 0x400000 0x400000>;

In Hi3620 SoC, the bias could only be configured pull up or pull down. There's no any bit for controlling bias enable or bias disable. But user may need to remove both pullup and pulldown at runtime. In this case, I set bias disable if there's no pullup & pulldown.

* Without bias enable/disable bit.

            bias-disable = <user input value, expected disable value, mask>;
            bias-pullup = <user input value, expected pullup value, mask>;
      "expected disable value" is the set of not pullup bit and not

pull down bit.
"expected pullup value" is the set of pullup bit.

* With bias enable/disable bit.
"expected disable value" is the set of disable bit, NOT pullup
bit and NOT pulldown bit.
"expected pullup value" is the set of NOT disable bit & pullup bit.

PULLUP --> DISABLE: only need to set the expected disable value in bias-disable property.
DISABLE --> PULLUP: only need to set the expected pullup value in bias-pullup property.
PULLUP --> PULLDOWN: set the expected pulldown value. So both pullup and pulldown
bits are enabled unless user call DISABLE first.. Maybe it's not right. I can fix it and keep
either pullup or pulldown enabled. It's ok to add pinconf_clear() for bias as you mentioned.

And I think that we need four parameters with your format.
<user setting on bias enable/disable, expected enable value,
expected disable value, mask */
Otherwise, how could we know user's setting? Especially, we need to configure pullup.
In your case, expected pullup enable & expected pullup disable are set in bias-pullup property.

Quoted 2 lines
                /* enable value, disable value, mask */
                pinctrl-single,bias-pullup = <0 1 1>;

Actually, I'm OK to use enable value. And it needs 4 parameters since disable value may not be zero.

By the way, bias property would be the format in below with 4 parameters.
* Without bias enable/disable bit.

          bias-enable = <0, 0, 0, set of both pullup and pulldown mask>;

* With bias enable/disable bit.
bias-enable = <user setting, expected enable, expected
disable, mask of only enable/disable bit>;

Behavior of pinconf_clear():
- call bias-disable
- call the expected bias setting.

Quoted 9 lines

DISABLE --> PULLUP, user call config BIAS_PULLUP without additional argument. PULLUP --> PULLDOWN, user call with config BIAS_PULLDOWN without additional argument.
PULLUP --> DISABLE, user call with config BIAS_ENABLE and 0 for argument.

The switch from PULLUP to DISABLE is a little strange since we have to call BIAS_ENABLE.
Is it good for you?

Maybe it didn't cover your case. It seems that there's only one bit for bias in your case.
You can control MMC BIAS enable or disable. And there's neither pullup nor pulldown.
Is it right?

If so, how about this?

* Without pullup & pulldown bias. With bias enable & disable bit. (Your MMC bias)
1) 3 params
bias-disable = <user setting of bias value, expected bias
disable value, mask>;
bias-enable = <user setting of bias value, expected bias
enable value, mask>;
or 2) 4 params
bias-enable = <user setting of bias value, expected bias
enable value, expected bias disable value, mask>;

So I will need both config BIAS_ENABLE & config BIAS_DISABLE.
Driver switches between BIAS_ENABLE & BIAS_DISABLE.

* Without bias enable & disable bit. With bias pullup & pulldown bit. (Hi3620 bias)
1) 3 params
bias-disable = <user setting of bias value, expected
disable value (w/o pullup & pulldown), mask (pullup & pulldown)>;
bias-pullup = <user setting of bias value, expected bias
pullup value, mask of pullup>;
bias-pulldown ...
or 2) 4 params
bias-enable = <user setting of bias value, expected enable
value (w pullup & pulldown), expected disable value (w/o pullup & pulldown), mask (pullup & pulldown)>;
bias-pullup = <user setting of bias value, expected bias
pullup value, expected bias pullup disable value, mask of pullup>;
bias-pulldown ...
Driver switches among BIAS_DISABLE, BIAS_PULLDOWN, BIAS_PULLUP.
It seems that BIAS_ENABLE is redundant operation at here.

* With bias enable & disable bit. With bias pullup & pulldown bit. (MMP/PXA bias)
1) 3 params
bias-disable = <user setting of bias value, expected disable
value (single bit), mask (enable/disable)>;
bias-pullup = <user setting of bias value, expected pullup
value, mask (pullup)>;
bias-pulldown ...
or 2) 4 params
bias-enable = <user setting of bias value, expected enable
value, expected disable value, mask>;
bias-pullup = <user setting of bias value, expected bias
pullup value, expected bias pullup disable value, mask of pullup>;
bias-pulldown ...
Driver switches among BIAS_DISABLE, BIAS_PULLDOWN, BIAS_PULLUP.
It seems that BIAS_ENABLE is redundant operation at here. Because user won't only enable bias without pullup or pulldown.

There're two usage for all three cases. Which one do you like?

Best Regards
Haojian

maintainer
#36 lore raw

PATCH v8 12/12 document: devicetree: bind pinconf with pin single

Quoted 6 lines · Haojian Zhuang

Maybe it didn't cover your case. It seems that there's only one bit for bias in your case.
You can control MMC BIAS enable or disable. And there's neither pullup nor pulldown.
Is it right?

Yes for this register there are no pulls. But I there are others that have pull bits.

Quoted 2 lines

So I will need both config BIAS_ENABLE & config BIAS_DISABLE.
Driver switches between BIAS_ENABLE & BIAS_DISABLE.

I'd like to avoid mapping both enable and disable for everything which seems bloated..

Quoted 9 lines

or 2) 4 params
bias-enable = <user setting of bias value, expected enable
value (w pullup & pulldown), expected disable value (w/o pullup & pulldown), mask (pullup & pulldown)>;
bias-pullup = <user setting of bias value, expected bias
pullup value, expected bias pullup disable value, mask of pullup>;
bias-pulldown ...
Driver switches among BIAS_DISABLE, BIAS_PULLDOWN, BIAS_PULLUP.
It seems that BIAS_ENABLE is redundant operation at here.

..so this 4 params option makes sense to me assuming it works for your case.

Quoted 1 line

There're two usage for all three cases. Which one do you like?

It seems that the 4 params option is most generic to me.

Regards,

Tony

author maintainer
#37 lore raw

PATCH v8 12/12 document: devicetree: bind pinconf with pin single

Quoted 8 lines · Tony Lindgren
Quoted 6 lines · Haojian Zhuang

Maybe it didn't cover your case. It seems that there's only one bit for bias in your case.
You can control MMC BIAS enable or disable. And there's neither pullup nor pulldown.
Is it right?

Quoted 9 lines

Yes for this register there are no pulls. But I there are others that have pull bits.

Quoted 2 lines

So I will need both config BIAS_ENABLE & config BIAS_DISABLE.
Driver switches between BIAS_ENABLE & BIAS_DISABLE.

I'd like to avoid mapping both enable and disable for everything which seems bloated..

pinctrl-coh901 driver already uses PIN_CONFIG_BIAS_DISABLE without argument.

I think that it's better to use both BIAS_ENABLE & BIAS_DISABLE. Otherwise, I need to update pinctrl-coh901 driver with updating the interface. The work is a little
large.

Maybe we can use another name, PIN_CONFIG_BIAS_AUTOPULL. Then we can distinguish it from PULL_UP & PULL_DOWN without any confusion. What's your opinion?

Regards
Haojian

maintainer
#38 lore raw

PATCH v8 12/12 document: devicetree: bind pinconf with pin single

Quoted 19 lines · Haojian Zhuang
Quoted 8 lines · Tony Lindgren
Quoted 6 lines · Haojian Zhuang

Maybe it didn't cover your case. It seems that there's only one bit for bias in your case.
You can control MMC BIAS enable or disable. And there's neither pullup nor pulldown.
Is it right?

Quoted 9 lines

Yes for this register there are no pulls. But I there are others that have pull bits.

Quoted 2 lines

So I will need both config BIAS_ENABLE & config BIAS_DISABLE.
Driver switches between BIAS_ENABLE & BIAS_DISABLE.

I'd like to avoid mapping both enable and disable for everything which seems bloated..

Quoted 6 lines

pinctrl-coh901 driver already uses PIN_CONFIG_BIAS_DISABLE without argument.

I think that it's better to use both BIAS_ENABLE & BIAS_DISABLE. Otherwise, I need to update pinctrl-coh901 driver with updating the interface. The work is a little
large.

Well how about just let's keep the existing PIN_CONFIG_BIAS_DISABLE and PIN_CONFIG_BIAS_ENABLE for compability, but let's still standardize on PIN_CONFIG_XXX_ENABLE for all the new ones to avoid bloat?

Quoted 3 lines

Maybe we can use another name, PIN_CONFIG_BIAS_AUTOPULL. Then we can distinguish it from PULL_UP & PULL_DOWN without any confusion. What's your opinion?

Sounds OK to me if you need that.

Regards,

Tony

maintainer
#39 lore raw

PATCH v8 12/12 document: devicetree: bind pinconf with pin single

In reply to Haojian Zhuang
Quoted 8 lines · Haojian Zhuang
Quoted 4 lines · Tony Lindgren

For the cases where there's a value to be set I'm still wondering how does a client driver change the value if that needs to be changed dynamically? Can the value be passed as value + PIN_CONFIG_END?

pinconf_to_config_packed() can help to bind param & argument into config variable.

OK good to hear you've looked into that.
...

Quoted 7 lines

And I think that we need four parameters with your format.
<user setting on bias enable/disable, expected enable value,
expected disable value, mask */
Otherwise, how could we know user's setting? Especially, we need to configure pullup.
In your case, expected pullup enable & expected pullup disable are set in bias-pullup property.

Quoted 5 lines
Quoted 2 lines
                /* enable value, disable value, mask */
                pinctrl-single,bias-pullup = <0 1 1>;

Actually, I'm OK to use enable value. And it needs 4 parameters since disable value may not be zero.

OK. Four values makes sense to me so we can configure the default pinconf value like we already do for pinmux.

Quoted 11 lines

By the way, bias property would be the format in below with 4 parameters.
* Without bias enable/disable bit.

          bias-enable = <0, 0, 0, set of both pullup and pulldown mask>;

* With bias enable/disable bit.
bias-enable = <user setting, expected enable, expected
disable, mask of only enable/disable bit>;

Behavior of pinconf_clear():
- call bias-disable
- call the expected bias setting.

Hmm I was thinking pinconf_clear() would get passed the same parameters as pinconf_set() except it just does the opposite. But maybe I'm not following you here.

Quoted 8 lines

DISABLE --> PULLUP, user call config BIAS_PULLUP without additional argument. PULLUP --> PULLDOWN, user call with config BIAS_PULLDOWN without additional argument.
PULLUP --> DISABLE, user call with config BIAS_ENABLE and 0 for argument.

The switch from PULLUP to DISABLE is a little strange since we have to call BIAS_ENABLE.
Is it good for you?

I'm not sure I follow your example here, but sounds like the PULLUP to DISABLE case can be maybe handled by covering both bits in the mask?

Quoted 7 lines
Quoted 6 lines

Then regarding pinconf_set(), don't we also need pinconf_clear() in addition to pinconf_set()?

Otherwise we need both ENABLE and DISABLE enumeration, which seems unnecessary to me. So rather than have both PIN_CONFIG_BIAS_ENABLE and PIN_CONFIG_BIAS_DISABLE, we just need PIN_CONFIG_BIAS_ENABLE.

I can append pinconf_clear() to handle it.

OK great, I guess then we should have everything in place to make it usable from client drivers also.

Regards,

Tony