bind pinconf with pinctrl single
Subsystems (4)
Haojian Zhuang
maintainerv8 cover bind pinconf with pinctrl single
Changelog:
v8:
1. Update allocate irq dynamically in gpio-pl061.
2. Update bias-pullup/bias-pulldown as 4 parameters.
3. Remove bias-disable.
4. Add bias-autopull.
5. Rename input-schmitt-disable to input-schmitt-enable.
6. Discard allocating global gpio number in ascending order.
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.
Haojian Zhuang
maintainerPATCH 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v8 1/12 gpio: add gpio offset in gpio range cells property
Quoted 5 lines · Haojian Zhuang
Add gpio offset into "gpio-range-cells" property. It's used to support sparse pinctrl range in gpio chip.
Signed-off-by Haojian Zhuang <[email protected]>Acked-by Viresh Kumar <[email protected]>
Seems reasonable to me:
However I want Grant to have the final say on this patch.
Yours,
Linus Walleij
Haojian Zhuang
maintainerPATCH v8 2/12 gpio: fix wrong checking condition for gpio range
In reply to Haojian ZhuangIf 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
@@ -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
PATCH v8 2/12 gpio: fix wrong checking condition for gpio range
Quoted 9 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.
Signed-off-by Haojian Zhuang <[email protected]>Reviewed-by Linus Walleij <[email protected]>
Grant can you pick this patch (and the other one, 01/12)?
I would stack them in my tree unless there was such deep-core OF business involved, which makes me insecure.
Yours,
Linus Walleij
Haojian Zhuang
maintainerPATCH v8 3/12 gpio: pl061: allocate irq dynamically
In reply to Haojian ZhuangIn 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 | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/gpio/gpio-pl061.c +13 -3
@@ -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,15 @@ 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 =-1 ; + } + chip->irq_base =irq_alloc_descs (chip->irq_base,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
PATCH v8 3/12 gpio: pl061: allocate irq dynamically
On Mon, Feb 11, 2013 at 6:10 PM, Haojian Zhuang
<[email protected]> wrote:
We don't convert drivers to irqdomain without actually *using* the irqdomain. I don't know where this pattern comes from, but I'm suspicious about patch sets that just focus on enabling DT functionality without considering irqdomain stuff as a concept of its own.
The biggest problem with this patch is what is missing from it:
- irq_base shall be *deleted* from struct pl061_gpio
- instead a struct irqdomain * shall be stored for offsetting IRQs
- everywhere chip->irq_base is referenced, use irq_find_mapping()
- In pl061_to_irq, irq_create_mapping() shall be used, so it will allocate a descriptor even if we're using the driver with SPARSE_IRQ and a linear domain.
Look at e.g. gpio-langwell.c for guidance.
drivers/gpio/gpio-pl061.c static int pl061_probe(struct amba_device *adev, const struct amba_id *id) · line 242
Quoted 6 lines
drivers/gpio/gpio-pl061.c +5
-0+ chip->irq_base =irq_alloc_descs (chip->irq_base,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 ;
Instead of the above, please use:
chip->irqdomain = irq_domain_add_simple(adev->dev.of_node,
PL061_GPIO_NR,
chip->irq_base,
&pl061_domain_ops,
chip);Notice that I don't throw the domain away after creation either...
This call will allocate descriptors for you as long as the irq_base > 0, which it should be, since 0 is NO_IRQ.
It make things easier the day you start using a purely dynamic approach.
Yours,
Linus Walleij
Haojian Zhuang
maintainerPATCH v8 3/12 gpio: pl061: allocate irq dynamically
Quoted 37 lines · Linus Walleij
On Mon, Feb 11, 2013 at 6:10 PM, Haojian Zhuang
<[email protected]> wrote:We don't convert drivers to irqdomain without actually *using* the irqdomain. I don't know where this pattern comes from, but I'm suspicious about patch sets that just focus on enabling DT functionality without considering irqdomain stuff as a concept of its own.
The biggest problem with this patch is what is missing from it:
-
irq_baseshall be *deleted* from structpl061_gpio
- instead a struct irqdomain * shall be stored for offsetting IRQs
- everywherechip->irq_baseis referenced, useirq_find_mapping()
- Inpl061_to_irq,irq_create_mapping()shall be used, so it will allocate a descriptor even if we're using the driver withSPARSE_IRQand a linear domain.Look at e.g.
gpio-langwell.cfor guidance.drivers/gpio/gpio-pl061.c static int pl061_probe(struct amba_device *adev, const struct amba_id *id) · line 242
Quoted 6 lines
drivers/gpio/gpio-pl061.c +5
-0+ chip->irq_base =irq_alloc_descs (chip->irq_base,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 ;Instead of the above, please use:
chip->irqdomain= irq_domain_add_simple(adev->dev.of_node,PL061_GPIO_NR, chip->irq_base, &pl061_domain_ops, chip);Notice that I don't throw the domain away after creation either...
Quoted 8 lines
This call will allocate descriptors for you as long as the
irq_base> 0, which it should be, since 0 isNO_IRQ.It make things easier the day you start using a purely dynamic approach.
Yours,
Linus Walleij
Thank you. I'll update it.
Regards
Haojian
Haojian Zhuang
maintainerPATCH v8 4/12 pinctrl: verify whether gpio chip overlapps range
In reply to Haojian Zhuangpinctrl_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
@@ -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
PATCH v8 4/12 pinctrl: verify whether gpio chip overlapps range
Quoted 6 lines · Haojian Zhuang
/**
+ *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 ofpinctrl_match_gpio_range(). If the return
Quoted 8 lines
+ * 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 boolpinctrl_overlapped_gpio_range(unsigned gpio)
The name of this function confuses me, can we name it something like:
pinctrl_gpio_is_in_some_chip_but_no_range()
Which is actually what you test, right?
drivers/pinctrl/core.c pinctrl_match_gpio_range(struct pinctrl_dev *pctldev, unsigned gpio) · line 313
Quoted 4 lines
drivers/pinctrl/core.c +4
-0+{ +struct pinctrl_dev *pctldev; +struct pinctrl_gpio_range *range =NULL ; +struct gpio_chip *chip =gpio_to_chip (gpio);
Handle if chip happens to become NULL here.
Quoted 19 lines
drivers/pinctrl/core.c +15
-0+/* 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
drivers/pinctrl/core.c int pinctrl_request_gpio(unsigned gpio) · line 497
Quoted 5 lines
drivers/pinctrl/core.c +2
-0@@ -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 ;
If you change the name of the function like above this call can be understood, but maybe also add a comment above this call explaining the situation.
Yours,
Linus Walleij
Haojian Zhuang
maintainerPATCH v8 4/12 pinctrl: verify whether gpio chip overlapps range
Quoted 18 lines · Linus Walleij
Quoted 6 lines · Haojian Zhuang
/**
+ *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 ofpinctrl_match_gpio_range(). If the returnQuoted 8 lines
+ * 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 boolpinctrl_overlapped_gpio_range(unsigned gpio)
Quoted 7 lines
The name of this function confuses me, can we name it something like:
pinctrl_gpio_is_in_some_chip_but_no_range()Which is actually what you test, right?
How about pinctrl_match_gpio_range_exclude_some_pins()?
Quoted 37 lines
drivers/pinctrl/core.c pinctrl_match_gpio_range(struct pinctrl_dev *pctldev, unsigned gpio) · line 313
Quoted 4 lines
drivers/pinctrl/core.c +4
-0+{ +struct pinctrl_dev *pctldev; +struct pinctrl_gpio_range *range =NULL ; +struct gpio_chip *chip =gpio_to_chip (gpio);Handle if chip happens to become NULL here.
Quoted 19 lines
drivers/pinctrl/core.c +15
-0+/* 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 drivers/pinctrl/core.c int pinctrl_request_gpio(unsigned gpio) · line 497
Quoted 5 lines
drivers/pinctrl/core.c +2
-0@@ -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 ;If you change the name of the function like above this call can be understood, but maybe also add a comment above this call explaining the situation.
Yours,
Linus Walleij
PATCH v8 4/12 pinctrl: verify whether gpio chip overlapps range
Quoted 19 lines · Haojian Zhuang
Quoted 18 lines · Linus Walleij
Quoted 14 lines · Haojian Zhuang
/**
+ *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 ofpinctrl_match_gpio_range(). If the return
+ * value ofpinctrl_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 boolpinctrl_overlapped_gpio_range(unsigned gpio)
Quoted 8 lines
Quoted 7 lines
The name of this function confuses me, can we name it something like:
pinctrl_gpio_is_in_some_chip_but_no_range()Which is actually what you test, right?
How about
pinctrl_match_gpio_range_exclude_some_pins()?
Actually I get ever more confused by this patch, I just don't understand it. :-(
Something will need to be expanded on here or I will be unable to maintaine the code, sorry for being a slow learner...
By the way:
Nowaday the recommended practice is to register a GPIO chip, then add ranges using gpiochip_add_pin_range() in the non-DT case. Doesn't that create a race window when the above code will not behave as expected, e.g. between registration of the gpio chip, the pin controller and the ranges? I guess the code assumes that *all* initialization is complete?
Yours,
Linus Walleij
Haojian Zhuang
maintainerPATCH v8 4/12 pinctrl: verify whether gpio chip overlapps range
Quoted 44 lines · Linus Walleij
Quoted 19 lines · Haojian Zhuang
Quoted 18 lines · Linus Walleij
Quoted 14 lines · Haojian Zhuang
/**
+ *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 ofpinctrl_match_gpio_range(). If the return
+ * value ofpinctrl_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 boolpinctrl_overlapped_gpio_range(unsigned gpio)Quoted 8 lines
Quoted 7 lines
The name of this function confuses me, can we name it something like:
pinctrl_gpio_is_in_some_chip_but_no_range()Which is actually what you test, right?
How about
pinctrl_match_gpio_range_exclude_some_pins()?Actually I get ever more confused by this patch, I just don't understand it. :-(
Something will need to be expanded on here or I will be unable to maintaine the code, sorry for being a slow learner...
By the way:
Nowaday the recommended practice is to register a GPIO chip, then add ranges usinggpiochip_add_pin_range()in the non-DT case. Doesn't that create a race window when the above code will not behave as expected, e.g. between registration of the gpio chip, the pin controller and the ranges? I guess the code assumes that *all* initialization is complete?
Quoted 2 lines
Yours,
Linus Walleij
The implementation is a little tricky at here. Let me explain the case.
We have a back-end pinctrl-single device & pl061 gpio devices. So we need to define gpio range in DT. But there's no related pinmux registers on some special pins, like gpio159. Although we initialized pinctrl-single driver, we still get failure from pinctrl_match_gpio_range() because it doesn't exist in DT.
I implement it to double check for the failure case. If match_gpio_range() return failure, we need to check whether the pinctrl device isn't ready or the special pins like gpio159 don't exist in gpio range. So if the pinctrl device
isn't ready, it return EPROBE_DEFERED. If the special pins doesn't exist in gpio range, it's not the error case & return 0 (sucessful).
Regards
Haojian
Haojian Zhuang
maintainerPATCH v8 5/12 gpio: pl061: bind pinctrl by gpio request
In reply to Haojian ZhuangAdd 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
@@ -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);
@@ -252,6 +264,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
PATCH v8 5/12 gpio: pl061: bind pinctrl by gpio request
Quoted 8 lines · 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.Signed-off-by Haojian Zhuang <[email protected]>
(...)
drivers/gpio/gpio-pl061.c struct pl061_gpio { · line 74
Quoted 10 lines
drivers/gpio/gpio-pl061.c +10
-0+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); +}
So this will work find if the platform supports pinctrl, and either the pin controller can do something with this, or (after the other patch) if the GPIO is in some range, but not handled by some
pin controller.
But what about the case where there is a pin controller on the system, but no range matching this pin?
What will happen then? Eternal deferral?
Yours,
Linus Walleij
Haojian Zhuang
maintainerPATCH v8 5/12 gpio: pl061: bind pinctrl by gpio request
Quoted 28 lines · Linus Walleij
Quoted 8 lines · 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.Signed-off-by Haojian Zhuang <[email protected]>(...)
drivers/gpio/gpio-pl061.c struct pl061_gpio { · line 74
Quoted 10 lines
drivers/gpio/gpio-pl061.c +10
-0+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); +}So this will work find if the platform supports pinctrl, and either the pin controller can do something with this, or (after the other patch) if the GPIO is in some range, but not handled by some
pin controller.
Quoted 7 lines
But what about the case where there is a pin controller on the system, but no range matching this pin?
What will happen then? Eternal deferral?
Yours,
Linus Walleij
If there's a back-end pin controller ready, but no range matching this pin, it will return 0, not error. This is the purpose that I want to add pinctrl_overlapped_gpio_range().
Yes, the name is so confusing. Let's figure out a clear name.
Regards
Haojian
Haojian Zhuang
maintainerPATCH v8 6/12 pinctrl: single: create new gpio function range
In reply to Haojian ZhuangSince 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 gpio-ranges property is used in gpio driver and the pinctrl-single,gpio-range property is used 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
@@ -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
Tony Lindgren
maintainerPATCH v8 6/12 pinctrl: single: create new gpio function range
Quoted 3 lines · 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.
Minor typo above: s/invokes/invoke/
Quoted 8 lines
A new gpio function range should be created in DTS file in below.
pinctrl-single,gpio-range = <phandle
pin_offsetnr_pinsgpio_func>;range: gpio-range { #pinctrl-single,gpio-range-cells = <3>; };
Quoted 6 lines
The gpio-ranges property is used in gpio driver and the pinctrl-single,gpio-range property is used in pinctrl-single driver.
1. gpio-ranges = <phandle
gpio_offset_in_chippin_offsetnr_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>;
I think the second gpio-ranges above should be really pinctr-single,gpio-range instead of gpio-ranges?
Quoted 5 lines
2. gpio driver could get pin offset from gpio-ranges property. pinctrl-single driver could get gpio function mode from
gpio_functhat is stored in @gpiofuncs list in structpcs_device. This new pinctrl-single,gpio-range is used as complement for gpio-ranges property in gpio driver.
Other than that looks OK to me. Assuming the other related GPIO patches are fine and don't cause changes to this:
Haojian Zhuang
maintainerPATCH v8 6/12 pinctrl: single: create new gpio function range
Quoted 7 lines · Tony Lindgren
Quoted 3 lines · 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.Minor typo above: s/invokes/invoke/
I'll fix it.
Quoted 11 lines
Quoted 11 lines
A new gpio function range should be created in DTS file in below.
pinctrl-single,gpio-range = <phandle
pin_offsetnr_pinsgpio_func>;range: gpio-range { #pinctrl-single,gpio-range-cells = <3>; };The gpio-ranges property is used in gpio driver and the pinctrl-single,gpio-range property is used in pinctrl-single driver.
Quoted 7 lines
Quoted 3 lines
1. gpio-ranges = <phandle
gpio_offset_in_chippin_offsetnr_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>;I think the second gpio-ranges above should be really pinctr-single,gpio-range instead of gpio-ranges?
No, it's not pinctrl-single,gpio-range property. I list both two properties are here, since I need to explain the difference between gpio-ranges & pinctrl-single,gpio-range.
Thanks
Haojian
Quoted 10 lines
Quoted 5 lines
2. gpio driver could get pin offset from gpio-ranges property. pinctrl-single driver could get gpio function mode from
gpio_functhat is stored in @gpiofuncs list in structpcs_device. This new pinctrl-single,gpio-range is used as complement for gpio-ranges property in gpio driver.Other than that looks OK to me. Assuming the other related GPIO patches are fine and don't cause changes to this:
Acked-by Tony Lindgren <[email protected]>
PATCH v8 6/12 pinctrl: single: create new gpio function range
In reply to Haojian ZhuangQuoted 3 lines · 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.
Is it OK if I wait with patches 6-12 while we sort out the first 5?
Yours,
Linus Walleij
Haojian Zhuang
maintainerPATCH v8 6/12 pinctrl: single: create new gpio function range
Quoted 7 lines · Linus Walleij
Quoted 3 lines · 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.
Quoted 5 lines
Is it OK if I wait with patches 6-12 while we sort out the first 5?
Yours,
Linus Walleij
Since Tony has some comments on dropping BIAS_AUTO_PULL, I'll send the v9 including your comments.
Regards
Haojian
Haojian Zhuang
maintainerPATCH v8 7/12 pinctrl: generic: dump pin configuration
In reply to Haojian ZhuangAdd the support of dumping pin configuration.
--- drivers/pinctrl/pinconf-generic.c | 14 ++++++++++++++ drivers/pinctrl/pinconf.h | 8 ++++++++ 2 files changed, 22 insertions(+)
drivers/pinctrl/pinconf-generic.c +14 -0
@@ -12,6 +12,7 @@#define pr_fmt (fmt) "generic pinconfig core: " fmt#include <linux/kernel.h> +#include <linux/module.h> #include <linux/init.h> #include <linux/device.h> #include <linux/slab.h>
@@ -120,4 +121,17 @@ 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)); + } +} +EXPORT_SYMBOL_GPL (pinconf_generic_dump_config);#endif
drivers/pinctrl/pinconf.h +8 -0
@@ -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 inline 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
Haojian Zhuang
maintainerPATCH v8 8/12 pinctrl: single: set function mask as optional
In reply to Haojian ZhuangSince 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
@@ -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
Tony Lindgren
maintainerPATCH v8 8/12 pinctrl: single: set function mask as optional
Quoted 5 lines · 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.
Looks OK to me:
Haojian Zhuang
maintainerPATCH v8 9/12 pinctrl: generic: add auto pull config parameter
In reply to Haojian ZhuangThere's only one bit to control pin bias as enabled or disabled for some pins in OMAP SoC. So append PIN_CONFIG_BIAS_AUTO_PULL for this case. User shouldn't switch pin state between AUTO_PULL and PULL_UP/PULL_DOWN, since they're similiar concepts.
--- drivers/pinctrl/pinconf-generic.c | 1 + include/linux/pinctrl/pinconf-generic.h | 3 +++ 2 files changed, 4 insertions(+)
drivers/pinctrl/pinconf-generic.c +1 -0
@@ -37,6 +37,7 @@ struct pin_config_item {struct pin_config_item conf_items[] = {PCONFDUMP (PIN_CONFIG_BIAS_DISABLE ,"input bias disabled" ,NULL ),PCONFDUMP (PIN_CONFIG_BIAS_HIGH_IMPEDANCE ,"input bias high impedance" ,NULL ), +PCONFDUMP (PIN_CONFIG_BIAS_AUTO_PULL ,"input bias auto pull" ,NULL ),PCONFDUMP (PIN_CONFIG_BIAS_PULL_UP ,"input bias pull up" ,NULL ),PCONFDUMP (PIN_CONFIG_BIAS_PULL_DOWN ,"input bias pull down" ,NULL ),PCONFDUMP (PIN_CONFIG_DRIVE_PUSH_PULL ,"output drive push pull" ,NULL ),
include/linux/pinctrl/pinconf-generic.h +3 -0
@@ -29,6 +29,8 @@* if for example some other pin is going to drive the signal connected * to it for a while. Pins used for input are usually always high * impedance. +* @PIN_CONFIG_BIAS_AUTO_PULL: the pin will be pulled without specifying +* pull-up or pull-down. * @PIN_CONFIG_BIAS_PULL_UP: the pin will be pulled up (usually with high * impedance to VDD). If the argument is != 0 pull-up is enabled, * if it is 0, pull-up is disabled.
@@ -76,6 +78,7 @@enum pin_config_param {PIN_CONFIG_BIAS_DISABLE ,PIN_CONFIG_BIAS_HIGH_IMPEDANCE , +PIN_CONFIG_BIAS_AUTO_PULL ,PIN_CONFIG_BIAS_PULL_UP ,PIN_CONFIG_BIAS_PULL_DOWN ,PIN_CONFIG_DRIVE_PUSH_PULL ,
Signature · 1 line
1.7.10.4
Tony Lindgren
maintainerPATCH v8 9/12 pinctrl: generic: add auto pull config parameter
Quoted 4 lines · Haojian Zhuang
There's only one bit to control pin bias as enabled or disabled for some pins in OMAP SoC. So append
PIN_CONFIG_BIAS_AUTO_PULLfor this case. User shouldn't switch pin state betweenAUTO_PULLand PULL_UP/PULL_DOWN, since they're similiar concepts.
Please just drop patch from the series for now. This needs further research on what the hardware is actually doing. I suspect we can replace this with just either PIN_CONFIG_BIAS_PULL_UP or PIN_CONFIG_BIAS_PULL_DOWN.
Regards,
Tony
Quoted 42 lines
Signed-off-by Haojian Zhuang <[email protected]>--- drivers/pinctrl/pinconf-generic.c | 1 + include/linux/pinctrl/pinconf-generic.h | 3 +++ 2 files changed, 4 insertions(+)drivers/pinctrl/pinconf-generic.c +1
-0@@ -37,6 +37,7 @@ struct pin_config_item {struct pin_config_item conf_items[] = {PCONFDUMP (PIN_CONFIG_BIAS_DISABLE ,"input bias disabled" ,NULL ),PCONFDUMP (PIN_CONFIG_BIAS_HIGH_IMPEDANCE ,"input bias high impedance" ,NULL ), +PCONFDUMP (PIN_CONFIG_BIAS_AUTO_PULL ,"input bias auto pull" ,NULL ),PCONFDUMP (PIN_CONFIG_BIAS_PULL_UP ,"input bias pull up" ,NULL ),PCONFDUMP (PIN_CONFIG_BIAS_PULL_DOWN ,"input bias pull down" ,NULL ),PCONFDUMP (PIN_CONFIG_DRIVE_PUSH_PULL ,"output drive push pull" ,NULL ),include/linux/pinctrl/pinconf-generic.h +3
-0@@ -29,6 +29,8 @@* if for example some other pin is going to drive the signal connected * to it for a while. Pins used for input are usually always high * impedance. +* @PIN_CONFIG_BIAS_AUTO_PULL: the pin will be pulled without specifying +* pull-up or pull-down. * @PIN_CONFIG_BIAS_PULL_UP: the pin will be pulled up (usually with high * impedance to VDD). If the argument is != 0 pull-up is enabled, * if it is 0, pull-up is disabled. @@ -76,6 +78,7 @@enum pin_config_param {PIN_CONFIG_BIAS_DISABLE ,PIN_CONFIG_BIAS_HIGH_IMPEDANCE , +PIN_CONFIG_BIAS_AUTO_PULL ,PIN_CONFIG_BIAS_PULL_UP ,PIN_CONFIG_BIAS_PULL_DOWN ,PIN_CONFIG_DRIVE_PUSH_PULL ,Signature · 1 line
1.7.10.4
PATCH v8 9/12 pinctrl: generic: add auto pull config parameter
In reply to Haojian ZhuangQuoted 6 lines · Haojian Zhuang
There's only one bit to control pin bias as enabled or disabled for some pins in OMAP SoC. So append
PIN_CONFIG_BIAS_AUTO_PULLfor this case. User shouldn't switch pin state betweenAUTO_PULLand PULL_UP/PULL_DOWN, since they're similiar concepts.Signed-off-by Haojian Zhuang <[email protected]>
Makes perfect sense.
Patch applied with Tony's ACK!
Yours,
Linus Walleij
Tony Lindgren
maintainerPATCH v8 9/12 pinctrl: generic: add auto pull config parameter
Quoted 8 lines · Linus Walleij
Quoted 5 lines · Haojian Zhuang
There's only one bit to control pin bias as enabled or disabled for some pins in OMAP SoC. So append
PIN_CONFIG_BIAS_AUTO_PULLfor this case. User shouldn't switch pin state betweenAUTO_PULLand PULL_UP/PULL_DOWN, since they're similiar concepts.
Quoted 4 lines
Quoted 1 line
Signed-off-by Haojian Zhuang <[email protected]>Makes perfect sense.
Patch applied with Tony's ACK!
Sorry the conclusion was that this probably won't be needed and can probably be done with just PULL_UP/PULL_DOWN.
So can you please drop or revert this AUTO_PULL one?
Regards,
Tony
PATCH v8 9/12 pinctrl: generic: add auto pull config parameter
Quoted 11 lines · Tony Lindgren
Quoted 10 lines · Linus Walleij
Quoted 6 lines · Haojian Zhuang
There's only one bit to control pin bias as enabled or disabled for some pins in OMAP SoC. So append
PIN_CONFIG_BIAS_AUTO_PULLfor this case. User shouldn't switch pin state betweenAUTO_PULLand PULL_UP/PULL_DOWN, since they're similiar concepts.Signed-off-by Haojian Zhuang <[email protected]>
Quoted 7 lines
Quoted 2 lines
Makes perfect sense.
Patch applied with Tony's ACK!Sorry the conclusion was that this probably won't be needed and can probably be done with just PULL_UP/PULL_DOWN.
So can you please drop or revert this
AUTO_PULLone?
Sorry I was drunk or something.
I never applied this patch, I applied the other one, with the title "pinctrl: generic: rename input schmitt disable".
This one stays out.
Yours,
Linus Walleij
Tony Lindgren
maintainerPATCH v8 9/12 pinctrl: generic: add auto pull config parameter
Quoted 18 lines · Linus Walleij
Quoted 17 lines · Tony Lindgren
Quoted 8 lines · Linus Walleij
Quoted 5 lines · Haojian Zhuang
There's only one bit to control pin bias as enabled or disabled for some pins in OMAP SoC. So append
PIN_CONFIG_BIAS_AUTO_PULLfor this case. User shouldn't switch pin state betweenAUTO_PULLand PULL_UP/PULL_DOWN, since they're similiar concepts.Quoted 4 lines
Quoted 1 line
Signed-off-by Haojian Zhuang <[email protected]>Makes perfect sense.
Patch applied with Tony's ACK!Sorry the conclusion was that this probably won't be needed and can probably be done with just PULL_UP/PULL_DOWN.
Quoted 8 lines
Quoted 1 line
So can you please drop or revert this
AUTO_PULLone?Sorry I was drunk or something.
I never applied this patch, I applied the other one, with the title "pinctrl: generic: rename input schmitt disable".
This one stays out.
OK thanks for clarifying it :)
Tony
Haojian Zhuang
maintainerPATCH v8 10/12 pinctrl: generic: rename input schmitt disable
In reply to Haojian ZhuangRename PIN_CONFIG_INPUT_SCHMITT_DISABLE to PIN_CONFIG_INPUT_SCHMITT_ENABLE. It's used to make it more generialize.
--- drivers/pinctrl/pinconf-generic.c | 2 +- include/linux/pinctrl/pinconf-generic.h | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/pinctrl/pinconf-generic.c +1 -1
@@ -43,7 +43,7 @@ struct pin_config_item conf_items[] = {PCONFDUMP (PIN_CONFIG_DRIVE_PUSH_PULL ,"output drive push pull" ,NULL ),PCONFDUMP (PIN_CONFIG_DRIVE_OPEN_DRAIN ,"output drive open drain" ,NULL ),PCONFDUMP (PIN_CONFIG_DRIVE_OPEN_SOURCE ,"output drive open source" ,NULL ), -PCONFDUMP (PIN_CONFIG_INPUT_SCHMITT_DISABLE ,"input schmitt disabled" ,NULL ), +PCONFDUMP (PIN_CONFIG_INPUT_SCHMITT_ENABLE ,"input schmitt enabled" ,NULL ),PCONFDUMP (PIN_CONFIG_INPUT_SCHMITT ,"input schmitt trigger" ,NULL ),PCONFDUMP (PIN_CONFIG_INPUT_DEBOUNCE ,"input debounce" ,"time units" ), PCONFDUMP(PIN_CONFIG_POWER_SOURCE, "pin power source", "selector"),
include/linux/pinctrl/pinconf-generic.h +4 -2
@@ -50,7 +50,9 @@* argument is ignored. * @PIN_CONFIG_DRIVE_STRENGTH: the pin will output the current passed as * argument. The argument is in mA. -* @PIN_CONFIG_INPUT_SCHMITT_DISABLE: disable schmitt-trigger mode on the pin. +* @PIN_CONFIG_INPUT_SCHMITT_ENABLE: control schmitt-trigger mode on the pin. +* If the argument != 0, schmitt-trigger mode is enabled. If it's 0, +* schmitt-trigger mode is disabled. * @PIN_CONFIG_INPUT_SCHMITT: this will configure an input pin to run in * schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis, * the threshold value is given on a custom format as argument when
@@ -85,7 +87,7 @@ enum pin_config_param {PIN_CONFIG_DRIVE_OPEN_DRAIN ,PIN_CONFIG_DRIVE_OPEN_SOURCE ,PIN_CONFIG_DRIVE_STRENGTH , -PIN_CONFIG_INPUT_SCHMITT_DISABLE , +PIN_CONFIG_INPUT_SCHMITT_ENABLE ,PIN_CONFIG_INPUT_SCHMITT ,PIN_CONFIG_INPUT_DEBOUNCE , PIN_CONFIG_POWER_SOURCE,
Signature · 1 line
1.7.10.4
Tony Lindgren
maintainerPATCH v8 10/12 pinctrl: generic: rename input schmitt disable
Quoted 4 lines · Haojian Zhuang
Rename
PIN_CONFIG_INPUT_SCHMITT_DISABLEtoPIN_CONFIG_INPUT_SCHMITT_ENABLE. It's used to make it more generialize.Signed-off-by Haojian Zhuang <[email protected]>
Makes sense to me for future naming of things:
Quoted 45 lines
--- drivers/pinctrl/pinconf-generic.c | 2 +- include/linux/pinctrl/pinconf-generic.h | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-)drivers/pinctrl/pinconf-generic.c +1
-1@@ -43,7 +43,7 @@ struct pin_config_item conf_items[] = {PCONFDUMP (PIN_CONFIG_DRIVE_PUSH_PULL ,"output drive push pull" ,NULL ),PCONFDUMP (PIN_CONFIG_DRIVE_OPEN_DRAIN ,"output drive open drain" ,NULL ),PCONFDUMP (PIN_CONFIG_DRIVE_OPEN_SOURCE ,"output drive open source" ,NULL ), -PCONFDUMP (PIN_CONFIG_INPUT_SCHMITT_DISABLE ,"input schmitt disabled" ,NULL ), +PCONFDUMP (PIN_CONFIG_INPUT_SCHMITT_ENABLE ,"input schmitt enabled" ,NULL ),PCONFDUMP (PIN_CONFIG_INPUT_SCHMITT ,"input schmitt trigger" ,NULL ),PCONFDUMP (PIN_CONFIG_INPUT_DEBOUNCE ,"input debounce" ,"time units" ), PCONFDUMP(PIN_CONFIG_POWER_SOURCE, "pin power source", "selector"),include/linux/pinctrl/pinconf-generic.h +4
-2@@ -50,7 +50,9 @@* argument is ignored. * @PIN_CONFIG_DRIVE_STRENGTH: the pin will output the current passed as * argument. The argument is in mA. -* @PIN_CONFIG_INPUT_SCHMITT_DISABLE: disable schmitt-trigger mode on the pin. +* @PIN_CONFIG_INPUT_SCHMITT_ENABLE: control schmitt-trigger mode on the pin. +* If the argument != 0, schmitt-trigger mode is enabled. If it's 0, +* schmitt-trigger mode is disabled. * @PIN_CONFIG_INPUT_SCHMITT: this will configure an input pin to run in * schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis, * the threshold value is given on a custom format as argument when @@ -85,7 +87,7 @@ enum pin_config_param {PIN_CONFIG_DRIVE_OPEN_DRAIN ,PIN_CONFIG_DRIVE_OPEN_SOURCE ,PIN_CONFIG_DRIVE_STRENGTH , -PIN_CONFIG_INPUT_SCHMITT_DISABLE , +PIN_CONFIG_INPUT_SCHMITT_ENABLE ,PIN_CONFIG_INPUT_SCHMITT ,PIN_CONFIG_INPUT_DEBOUNCE , PIN_CONFIG_POWER_SOURCE,Signature · 1 line
1.7.10.4
Haojian Zhuang
maintainerPATCH v8 11/12 pinctrl: single: support generic pinconf
In reply to Haojian ZhuangSupport the operation of generic pinconf. The supported config arguments are INPUT_SCHMITT, INPUT_SCHMITT_ENABLE, DRIVE_STRENGHT, BIAS_DISABLE, BIAS_AUTOPULL, BIAS_PULLUP, BIAS_PULLDOWN, SLEW_RATE.
--- drivers/pinctrl/Kconfig | 1 + drivers/pinctrl/pinctrl-single.c | 411 +++++++++++++++++++++++++++++++++++++- 2 files changed, 405 insertions(+), 7 deletions(-)
drivers/pinctrl/Kconfig +1 -0
@@ -166,6 +166,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 +404 -7
556 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Tony Lindgren
maintainerPATCH v8 11/12 pinctrl: single: support generic pinconf
Quoted 3 lines · Haojian Zhuang
Support the operation of generic pinconf. The supported config arguments are
INPUT_SCHMITT,INPUT_SCHMITT_ENABLE,DRIVE_STRENGHT,BIAS_DISABLE,BIAS_AUTOPULL,BIAS_PULLUP,BIAS_PULLDOWN,SLEW_RATE.
I suggest you leave out BIAS_AUTOPULL here too. And then maybe check the naming above for better search results :) It should BIAS_PULL_UP etc I guess?
Other than that this works good for me, thanks for all the effort!
Haojian Zhuang
maintainerPATCH v8 12/12 document: devicetree: bind pinconf with pin single
In reply to Haojian ZhuangFrom: Haojian Zhuang <[email protected]>
Add comments with pinconf & gpio range in the document of pinctrl-single.
--- .../devicetree/bindings/pinctrl/pinctrl-single.txt | 118 +++++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt +117 -1
@@ -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,72 @@ 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-pullup : array of value that are used to configure the + input bias pullup in the pinmux register. + + /* input, enabled pullup bits, disabled pullup bits, mask */ + pinctrl-single,bias-pullup = <0 1 0 1>; + +- pinctrl-single,bias-pulldown : array of value that are used to configure the + input bias pulldown in the pinmux register. + + /* input, enabled pulldown bits, disabled pulldown bits, mask */ + pinctrl-single,bias-pulldown = <2 2 0 2>; + +- pinctrl-single,bias-autopull : array of value that are used to configure the + input bias autopull. + + /* input, enabled autopull bits, disabled autopull bits, mask */ + pinctrl-single,bias-autopull = <1 1 0 1>; + + bias-pullup & bias-pulldown should be used together without bias-autoupll, + vice visa. + + * Only one bit to control input bias enable or disable: User should use + pinctrl-single,bias-autoupll property at here. + * Two bits to control input bias pullup and pulldown: User should use + pinctrl-single,bias-pullup & pinctrl-single,bias-pulldown. One bit means + pullup, and the other one bit means pulldown. + * Three bits to control input bias enable, pullup and pulldown. User should + use pinctrl-single,bias-pullup & pinctrl-single,bias-pulldown. Input bias + enable bit should be included in pullup or pulldown bits. + * Although driver could set PIN_CONFIG_BIAS_DISABLE, there's no property as + pinctrl-single,bias-disable. Because pinctrl single driver could implement + it by calling pulldown, pullup, autopull disabled. + +- 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-enable : array of value that are used to + configure input schmitt enable or disable in the pinmux register. + + /* input, enable bits, disable bits, mask */ + pinctrl-single,input-schmitt-enable = <0x30 0x40 0 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 +107,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 +155,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 +198,15 @@ 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>; + }; + /* map uart2 pins */ uart2_pins: pinmux_uart2_pins { pinctrl-single,pins = <
@@ -122,6 +233,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
Tony Lindgren
maintainerPATCH v8 12/12 document: devicetree: bind pinconf with pin single
Quoted 4 lines · Haojian Zhuang
From: Haojian Zhuang <[email protected]>
Add comments with pinconf & gpio range in the document of pinctrl-single.
Other than leaving out BIAS_AUTO_PULL, looks good to me:
v8 cover bind pinconf with pinctrl single
In reply to Haojian ZhuangQuoted 2 lines · Haojian Zhuang
Changelog:
v8:
I just want to take the opportunity to also state that I am *very* *impressed* with the patch set and your perseverance on making this pin controller reusable for HiSilicon.
Even if I make grumpy comments on things I want to stress that the patch set is in general very good.
Yours,
Linus Walleij