linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: st: stop abusing of_get_named_gpio()
@ 2022-09-28 20:20 Dmitry Torokhov
  2022-09-29  8:49 ` Patrice CHOTARD
  2022-10-04  7:59 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2022-09-28 20:20 UTC (permalink / raw)
  To: Patrice Chotard, Linus Walleij
  Cc: Andy Shevchenko, linux-arm-kernel, linux-gpio, linux-kernel

Pin descriptions for this chip only look like standard GPIO device tree
descriptions, while in fact they contain additional data (in excess of
number of cells specified in description of gpio controllers). They also
refer to only pins/gpios belonging to the driver and not to arbitrary
gpio in the system.

Because we want to stop exporting OF-specific handlers from gpiolib-of,
let's parse the pin reference ourself instead of trying to call
of_get_named_gpio().

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

Just compiled, not tested on real hardware.

 drivers/pinctrl/pinctrl-st.c | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-st.c b/drivers/pinctrl/pinctrl-st.c
index 0fea71fd9a00..cf7f9cbe6044 100644
--- a/drivers/pinctrl/pinctrl-st.c
+++ b/drivers/pinctrl/pinctrl-st.c
@@ -12,7 +12,6 @@
 #include <linux/io.h>
 #include <linux/of.h>
 #include <linux/of_irq.h>
-#include <linux/of_gpio.h> /* of_get_named_gpio() */
 #include <linux/of_address.h>
 #include <linux/gpio/driver.h>
 #include <linux/regmap.h>
@@ -1162,6 +1161,31 @@ static void st_parse_syscfgs(struct st_pinctrl *info, int bank,
 	return;
 }
 
+static int st_pctl_dt_calculate_pin(struct st_pinctrl *info,
+				    phandle bank, unsigned int offset)
+{
+	struct device_node *np;
+	struct gpio_chip *chip;
+	int retval = -EINVAL;
+	int i;
+
+	np = of_find_node_by_phandle(bank);
+	if (!np)
+		return -EINVAL;
+
+	for (i = 0; i < info->nbanks; i++) {
+		chip = &info->banks[i].gpio_chip;
+		if (chip->of_node == np) {
+			if (offset < chip->ngpio)
+				retval = chip->base + offset;
+			break;
+		}
+	}
+
+	of_node_put(np);
+	return retval;
+}
+
 /*
  * Each pin is represented in of the below forms.
  * <bank offset mux direction rt_type rt_delay rt_clk>
@@ -1175,6 +1199,8 @@ static int st_pctl_dt_parse_groups(struct device_node *np,
 	struct device *dev = info->dev;
 	struct st_pinconf *conf;
 	struct device_node *pins;
+	phandle bank;
+	unsigned int offset;
 	int i = 0, npins = 0, nr_props, ret = 0;
 
 	pins = of_get_child_by_name(np, "st,pins");
@@ -1214,9 +1240,9 @@ static int st_pctl_dt_parse_groups(struct device_node *np,
 		conf = &grp->pin_conf[i];
 
 		/* bank & offset */
-		be32_to_cpup(list++);
-		be32_to_cpup(list++);
-		conf->pin = of_get_named_gpio(pins, pp->name, 0);
+		bank = be32_to_cpup(list++);
+		offset = be32_to_cpup(list++);
+		conf->pin = st_pctl_dt_calculate_pin(info, bank, offset);
 		conf->name = pp->name;
 		grp->pins[i] = conf->pin;
 		/* mux */
-- 
2.38.0.rc1.362.ged0d419d3c-goog


-- 
Dmitry

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: st: stop abusing of_get_named_gpio()
  2022-09-28 20:20 [PATCH] pinctrl: st: stop abusing of_get_named_gpio() Dmitry Torokhov
@ 2022-09-29  8:49 ` Patrice CHOTARD
  2022-10-04  7:59 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Patrice CHOTARD @ 2022-09-29  8:49 UTC (permalink / raw)
  To: Dmitry Torokhov, Linus Walleij
  Cc: Andy Shevchenko, linux-arm-kernel, linux-gpio, linux-kernel

Hi Dmitry

On 9/28/22 22:20, Dmitry Torokhov wrote:
> Pin descriptions for this chip only look like standard GPIO device tree
> descriptions, while in fact they contain additional data (in excess of
> number of cells specified in description of gpio controllers). They also
> refer to only pins/gpios belonging to the driver and not to arbitrary
> gpio in the system.
> 
> Because we want to stop exporting OF-specific handlers from gpiolib-of,
> let's parse the pin reference ourself instead of trying to call
> of_get_named_gpio().
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> 
> Just compiled, not tested on real hardware.
> 
>  drivers/pinctrl/pinctrl-st.c | 34 ++++++++++++++++++++++++++++++----
>  1 file changed, 30 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pinctrl/pinctrl-st.c b/drivers/pinctrl/pinctrl-st.c
> index 0fea71fd9a00..cf7f9cbe6044 100644
> --- a/drivers/pinctrl/pinctrl-st.c
> +++ b/drivers/pinctrl/pinctrl-st.c
> @@ -12,7 +12,6 @@
>  #include <linux/io.h>
>  #include <linux/of.h>
>  #include <linux/of_irq.h>
> -#include <linux/of_gpio.h> /* of_get_named_gpio() */
>  #include <linux/of_address.h>
>  #include <linux/gpio/driver.h>
>  #include <linux/regmap.h>
> @@ -1162,6 +1161,31 @@ static void st_parse_syscfgs(struct st_pinctrl *info, int bank,
>  	return;
>  }
>  
> +static int st_pctl_dt_calculate_pin(struct st_pinctrl *info,
> +				    phandle bank, unsigned int offset)
> +{
> +	struct device_node *np;
> +	struct gpio_chip *chip;
> +	int retval = -EINVAL;
> +	int i;
> +
> +	np = of_find_node_by_phandle(bank);
> +	if (!np)
> +		return -EINVAL;
> +
> +	for (i = 0; i < info->nbanks; i++) {
> +		chip = &info->banks[i].gpio_chip;
> +		if (chip->of_node == np) {
> +			if (offset < chip->ngpio)
> +				retval = chip->base + offset;
> +			break;
> +		}
> +	}
> +
> +	of_node_put(np);
> +	return retval;
> +}
> +
>  /*
>   * Each pin is represented in of the below forms.
>   * <bank offset mux direction rt_type rt_delay rt_clk>
> @@ -1175,6 +1199,8 @@ static int st_pctl_dt_parse_groups(struct device_node *np,
>  	struct device *dev = info->dev;
>  	struct st_pinconf *conf;
>  	struct device_node *pins;
> +	phandle bank;
> +	unsigned int offset;
>  	int i = 0, npins = 0, nr_props, ret = 0;
>  
>  	pins = of_get_child_by_name(np, "st,pins");
> @@ -1214,9 +1240,9 @@ static int st_pctl_dt_parse_groups(struct device_node *np,
>  		conf = &grp->pin_conf[i];
>  
>  		/* bank & offset */
> -		be32_to_cpup(list++);
> -		be32_to_cpup(list++);
> -		conf->pin = of_get_named_gpio(pins, pp->name, 0);
> +		bank = be32_to_cpup(list++);
> +		offset = be32_to_cpup(list++);
> +		conf->pin = st_pctl_dt_calculate_pin(info, bank, offset);
>  		conf->name = pp->name;
>  		grp->pins[i] = conf->pin;
>  		/* mux */

I tested it on stih410-b2260 board

Tested-by: Patrice Chotard <patrice.chotard@foss.st.com>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: st: stop abusing of_get_named_gpio()
  2022-09-28 20:20 [PATCH] pinctrl: st: stop abusing of_get_named_gpio() Dmitry Torokhov
  2022-09-29  8:49 ` Patrice CHOTARD
@ 2022-10-04  7:59 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2022-10-04  7:59 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Patrice Chotard, Andy Shevchenko, linux-arm-kernel, linux-gpio,
	linux-kernel

On Wed, Sep 28, 2022 at 10:20 PM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:

> Pin descriptions for this chip only look like standard GPIO device tree
> descriptions, while in fact they contain additional data (in excess of
> number of cells specified in description of gpio controllers). They also
> refer to only pins/gpios belonging to the driver and not to arbitrary
> gpio in the system.
>
> Because we want to stop exporting OF-specific handlers from gpiolib-of,
> let's parse the pin reference ourself instead of trying to call
> of_get_named_gpio().
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Excellent work as usual, patch applied.

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-04  8:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-28 20:20 [PATCH] pinctrl: st: stop abusing of_get_named_gpio() Dmitry Torokhov
2022-09-29  8:49 ` Patrice CHOTARD
2022-10-04  7:59 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).