Re: [PATCH] pinctrl: Fix pinctrl_gpio_get_pinctrl_and_offset()

2024-05-17 Thread Tom Rini
On Fri, 10 May 2024 19:35:51 +, Jonas Karlman wrote:

> Linux kernel Documentation/devicetree/bindings/gpio/gpio.txt define the
> format of the gpio-ranges prop as:
> 
>   The format is: <[pin controller phandle], [GPIO controller offset],
>   [pin controller offset], [number of pins]>;
> 
>   Example:
> 
> [...]

Applied to u-boot/master, thanks!

-- 
Tom




Re: [PATCH] pinctrl: Fix pinctrl_gpio_get_pinctrl_and_offset()

2024-05-11 Thread Quanyang Wang



On 5/11/24 03:35, Jonas Karlman wrote:

Linux kernel Documentation/devicetree/bindings/gpio/gpio.txt define the
format of the gpio-ranges prop as:

   The format is: <[pin controller phandle], [GPIO controller offset],
   [pin controller offset], [number of pins]>;

   Example:

   gpio-ranges = < 0 20 10>, < 10 50 20>;

   This means:
   - pins 20..29 on pin controller "foo" is mapped to GPIO line 0..9 and
   - pins 50..69 on pin controller "bar" is mapped to GPIO line 10..29

For this example, a call to pinctrl_gpio_get_pinctrl_and_offset() using
offset 10 incorrectly return pin controller "foo" instead of "bar".

Fix this by using an exclusive range check.

Fixes: d0bb00adccb8 ("pinctrl: fix pinctrl_gpio_get_pinctrl_and_offset for 
gpio-ranges array")
Signed-off-by: Jonas Karlman 


Thanks for your patch.

Reviewed-by: Quanyang Wang 


---
  drivers/pinctrl/pinctrl-uclass.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c
index 245510a96312..6f10150b2a42 100644
--- a/drivers/pinctrl/pinctrl-uclass.c
+++ b/drivers/pinctrl/pinctrl-uclass.c
@@ -210,7 +210,7 @@ pinctrl_gpio_get_pinctrl_and_offset(struct udevice *dev, 
unsigned offset,
pfc_base = args.args[1];
pfc_pins = args.args[2];
  
-		if (offset >= gpio_offset && offset <= gpio_offset + pfc_pins)

+   if (offset >= gpio_offset && offset < gpio_offset + pfc_pins)
break;
}
  


[PATCH] pinctrl: Fix pinctrl_gpio_get_pinctrl_and_offset()

2024-05-10 Thread Jonas Karlman
Linux kernel Documentation/devicetree/bindings/gpio/gpio.txt define the
format of the gpio-ranges prop as:

  The format is: <[pin controller phandle], [GPIO controller offset],
  [pin controller offset], [number of pins]>;

  Example:

  gpio-ranges = < 0 20 10>, < 10 50 20>;

  This means:
  - pins 20..29 on pin controller "foo" is mapped to GPIO line 0..9 and
  - pins 50..69 on pin controller "bar" is mapped to GPIO line 10..29

For this example, a call to pinctrl_gpio_get_pinctrl_and_offset() using
offset 10 incorrectly return pin controller "foo" instead of "bar".

Fix this by using an exclusive range check.

Fixes: d0bb00adccb8 ("pinctrl: fix pinctrl_gpio_get_pinctrl_and_offset for 
gpio-ranges array")
Signed-off-by: Jonas Karlman 
---
 drivers/pinctrl/pinctrl-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c
index 245510a96312..6f10150b2a42 100644
--- a/drivers/pinctrl/pinctrl-uclass.c
+++ b/drivers/pinctrl/pinctrl-uclass.c
@@ -210,7 +210,7 @@ pinctrl_gpio_get_pinctrl_and_offset(struct udevice *dev, 
unsigned offset,
pfc_base = args.args[1];
pfc_pins = args.args[2];
 
-   if (offset >= gpio_offset && offset <= gpio_offset + pfc_pins)
+   if (offset >= gpio_offset && offset < gpio_offset + pfc_pins)
break;
}
 
-- 
2.43.2



Re: [PATCH] pinctrl: fix pinctrl_gpio_get_pinctrl_and_offset for gpio-ranges array

2023-04-02 Thread Simon Glass
From: Quanyang Wang 

Sometimes a multi-element array is used for "gpio-ranges" property in
dts file:

qe_pio_e: gpio-controller@1460 {
..
gpio-ranges = < 0 20 10>, < 10 50 20>;
..
};

But the function pinctrl_gpio_get_pinctrl_and_offset can't handle this
case because the "index" argument passed to dev_read_phandle_with_args
is fixed to be "0". Use a loop to traverse the array to fix it.

Signed-off-by: Quanyang Wang 
---
 drivers/pinctrl/pinctrl-uclass.c | 47 
 1 file changed, 23 insertions(+), 24 deletions(-)

Applied to u-boot-dm/next, thanks!


[PATCH] pinctrl: fix pinctrl_gpio_get_pinctrl_and_offset for gpio-ranges array

2023-03-16 Thread quanyang . wang
From: Quanyang Wang 

Sometimes a multi-element array is used for "gpio-ranges" property in
dts file:

qe_pio_e: gpio-controller@1460 {
..
gpio-ranges = < 0 20 10>, < 10 50 20>;
..
};

But the function pinctrl_gpio_get_pinctrl_and_offset can't handle this
case because the "index" argument passed to dev_read_phandle_with_args
is fixed to be "0". Use a loop to traverse the array to fix it.

Signed-off-by: Quanyang Wang 
---
 drivers/pinctrl/pinctrl-uclass.c | 47 
 1 file changed, 23 insertions(+), 24 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c
index 8837726cc1..73dd7b1038 100644
--- a/drivers/pinctrl/pinctrl-uclass.c
+++ b/drivers/pinctrl/pinctrl-uclass.c
@@ -169,34 +169,33 @@ pinctrl_gpio_get_pinctrl_and_offset(struct udevice *dev, 
unsigned offset,
 {
struct ofnode_phandle_args args;
unsigned gpio_offset, pfc_base, pfc_pins;
-   int ret;
+   int ret = 0;
+   int i = 0;
 
-   ret = dev_read_phandle_with_args(dev, "gpio-ranges", NULL, 3,
-0, );
-   if (ret) {
-   dev_dbg(dev, "%s: dev_read_phandle_with_args: err=%d\n",
-   __func__, ret);
-   return ret;
-   }
+   while (ret == 0) {
+   ret = dev_read_phandle_with_args(dev, "gpio-ranges", NULL, 3,
+i++, );
+   if (ret) {
+   dev_dbg(dev, "%s: dev_read_phandle_with_args: err=%d\n",
+   __func__, ret);
+   return ret;
+   }
 
-   ret = uclass_get_device_by_ofnode(UCLASS_PINCTRL,
- args.node, pctldev);
-   if (ret) {
-   dev_dbg(dev,
-   "%s: uclass_get_device_by_of_offset failed: err=%d\n",
-   __func__, ret);
-   return ret;
-   }
+   ret = uclass_get_device_by_ofnode(UCLASS_PINCTRL,
+ args.node, pctldev);
+   if (ret) {
+   dev_dbg(dev,
+   "%s: uclass_get_device_by_of_offset failed: 
err=%d\n",
+   __func__, ret);
+   return ret;
+   }
 
-   gpio_offset = args.args[0];
-   pfc_base = args.args[1];
-   pfc_pins = args.args[2];
+   gpio_offset = args.args[0];
+   pfc_base = args.args[1];
+   pfc_pins = args.args[2];
 
-   if (offset < gpio_offset || offset > gpio_offset + pfc_pins) {
-   dev_dbg(dev,
-   "%s: GPIO can not be mapped to pincontrol pin\n",
-   __func__);
-   return -EINVAL;
+   if (offset >= gpio_offset && offset <= gpio_offset + pfc_pins)
+   break;
}
 
offset -= gpio_offset;
-- 
2.36.1