linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 RESEND] PCI: imx6: Replace legacy gpio interface for gpiod interface
@ 2021-11-01 14:03 Maíra Canal
  2021-11-01 14:21 ` Lucas Stach
  0 siblings, 1 reply; 5+ messages in thread
From: Maíra Canal @ 2021-11-01 14:03 UTC (permalink / raw)
  To: hongxing.zhu, l.stach, lorenzo.pieralisi, robh, bhelgaas,
	helgaas, shawnguo, s.hauer
  Cc: kernel, linux-imx, linux-pci, linux-arm-kernel, linux-kernel

Considering the current transition of the GPIO subsystem, remove all
dependencies of the legacy GPIO interface (linux/gpio.h and linux
/of_gpio.h) and replace it with the descriptor-based GPIO approach.

Signed-off-by: Maíra Canal <maira.canal@usp.br>
---
V1 -> V2: Rewrite commit log and subject line to match PCI subsystem standard
---
 drivers/pci/controller/dwc/pci-imx6.c | 30 +++++++++------------------
 1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index 80fc98acf097..589cbd600d17 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -11,13 +11,12 @@
 #include <linux/bitfield.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/kernel.h>
 #include <linux/mfd/syscon.h>
 #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
 #include <linux/mfd/syscon/imx7-iomuxc-gpr.h>
 #include <linux/module.h>
-#include <linux/of_gpio.h>
 #include <linux/of_device.h>
 #include <linux/of_address.h>
 #include <linux/pci.h>
@@ -63,7 +62,7 @@ struct imx6_pcie_drvdata {
 
 struct imx6_pcie {
 	struct dw_pcie		*pci;
-	int			reset_gpio;
+	struct gpio_desc	*reset_gpio;
 	bool			gpio_active_high;
 	struct clk		*pcie_bus;
 	struct clk		*pcie_phy;
@@ -526,11 +525,11 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
 	usleep_range(200, 500);
 
 	/* Some boards don't have PCIe reset GPIO. */
-	if (gpio_is_valid(imx6_pcie->reset_gpio)) {
-		gpio_set_value_cansleep(imx6_pcie->reset_gpio,
+	if (imx6_pcie->reset_gpio) {
+		gpiod_set_value_cansleep(imx6_pcie->reset_gpio,
 					imx6_pcie->gpio_active_high);
 		msleep(100);
-		gpio_set_value_cansleep(imx6_pcie->reset_gpio,
+		gpiod_set_value_cansleep(imx6_pcie->reset_gpio,
 					!imx6_pcie->gpio_active_high);
 	}
 
@@ -1025,22 +1024,13 @@ static int imx6_pcie_probe(struct platform_device *pdev)
 		return PTR_ERR(pci->dbi_base);
 
 	/* Fetch GPIOs */
-	imx6_pcie->reset_gpio = of_get_named_gpio(node, "reset-gpio", 0);
 	imx6_pcie->gpio_active_high = of_property_read_bool(node,
 						"reset-gpio-active-high");
-	if (gpio_is_valid(imx6_pcie->reset_gpio)) {
-		ret = devm_gpio_request_one(dev, imx6_pcie->reset_gpio,
-				imx6_pcie->gpio_active_high ?
-					GPIOF_OUT_INIT_HIGH :
-					GPIOF_OUT_INIT_LOW,
-				"PCIe reset");
-		if (ret) {
-			dev_err(dev, "unable to get reset gpio\n");
-			return ret;
-		}
-	} else if (imx6_pcie->reset_gpio == -EPROBE_DEFER) {
-		return imx6_pcie->reset_gpio;
-	}
+	imx6_pcie->reset_gpio = devm_gpiod_get_optional(dev, "reset",
+			imx6_pcie->gpio_active_high ?  GPIOD_OUT_HIGH : GPIOD_OUT_LOW);
+	if (IS_ERR(imx6_pcie->reset_gpio))
+		return dev_err_probe(dev, PTR_ERR(imx6_pcie->reset_gpio),
+				"unable to get reset gpio\n");
 
 	/* Fetch clocks */
 	imx6_pcie->pcie_phy = devm_clk_get(dev, "pcie_phy");
-- 
2.31.1


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

* Re: [PATCH v2 RESEND] PCI: imx6: Replace legacy gpio interface for gpiod interface
  2021-11-01 14:03 [PATCH v2 RESEND] PCI: imx6: Replace legacy gpio interface for gpiod interface Maíra Canal
@ 2021-11-01 14:21 ` Lucas Stach
  2021-11-01 14:44   ` Maíra Canal
  0 siblings, 1 reply; 5+ messages in thread
From: Lucas Stach @ 2021-11-01 14:21 UTC (permalink / raw)
  To: Maíra Canal, hongxing.zhu, lorenzo.pieralisi, robh,
	bhelgaas, helgaas, shawnguo, s.hauer
  Cc: kernel, linux-imx, linux-pci, linux-arm-kernel, linux-kernel

Am Montag, dem 01.11.2021 um 11:03 -0300 schrieb Maíra Canal:
> Considering the current transition of the GPIO subsystem, remove all
> dependencies of the legacy GPIO interface (linux/gpio.h and linux
> /of_gpio.h) and replace it with the descriptor-based GPIO approach.
> 
> Signed-off-by: Maíra Canal <maira.canal@usp.br>
> ---
> V1 -> V2: Rewrite commit log and subject line to match PCI subsystem standard
> ---
>  drivers/pci/controller/dwc/pci-imx6.c | 30 +++++++++------------------
>  1 file changed, 10 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> index 80fc98acf097..589cbd600d17 100644
> --- a/drivers/pci/controller/dwc/pci-imx6.c
> +++ b/drivers/pci/controller/dwc/pci-imx6.c
> @@ -11,13 +11,12 @@
>  #include <linux/bitfield.h>
>  #include <linux/clk.h>
>  #include <linux/delay.h>
> -#include <linux/gpio.h>
> +#include <linux/gpio/consumer.h>
>  #include <linux/kernel.h>
>  #include <linux/mfd/syscon.h>
>  #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
>  #include <linux/mfd/syscon/imx7-iomuxc-gpr.h>
>  #include <linux/module.h>
> -#include <linux/of_gpio.h>
>  #include <linux/of_device.h>
>  #include <linux/of_address.h>
>  #include <linux/pci.h>
> @@ -63,7 +62,7 @@ struct imx6_pcie_drvdata {
>  
>  struct imx6_pcie {
>  	struct dw_pcie		*pci;
> -	int			reset_gpio;
> +	struct gpio_desc	*reset_gpio;
>  	bool			gpio_active_high;
>  	struct clk		*pcie_bus;
>  	struct clk		*pcie_phy;
> @@ -526,11 +525,11 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
>  	usleep_range(200, 500);
>  
>  	/* Some boards don't have PCIe reset GPIO. */
> -	if (gpio_is_valid(imx6_pcie->reset_gpio)) {
> -		gpio_set_value_cansleep(imx6_pcie->reset_gpio,
> +	if (imx6_pcie->reset_gpio) {
> +		gpiod_set_value_cansleep(imx6_pcie->reset_gpio,
>  					imx6_pcie->gpio_active_high);
>  		msleep(100);
> -		gpio_set_value_cansleep(imx6_pcie->reset_gpio,
> +		gpiod_set_value_cansleep(imx6_pcie->reset_gpio,
>  					!imx6_pcie->gpio_active_high);

I don't think this is correct. gpiod_set_value sets the logical line
state, so if the GPIO is specified as active-low in the DT, the real
line state will be negated. The only reason why the reset-gpio-active-
high property even exists is that old DTs might specify the wrong GPIO
polarity in the reset-gpio DT description. I think you need to use to
gpiod_set_raw_value API here to get the expected real line state even
with a broken DT description.

Regards,
Lucas

>  	}
>  
> @@ -1025,22 +1024,13 @@ static int imx6_pcie_probe(struct platform_device *pdev)
>  		return PTR_ERR(pci->dbi_base);
>  
>  	/* Fetch GPIOs */
> -	imx6_pcie->reset_gpio = of_get_named_gpio(node, "reset-gpio", 0);
>  	imx6_pcie->gpio_active_high = of_property_read_bool(node,
>  						"reset-gpio-active-high");
> -	if (gpio_is_valid(imx6_pcie->reset_gpio)) {
> -		ret = devm_gpio_request_one(dev, imx6_pcie->reset_gpio,
> -				imx6_pcie->gpio_active_high ?
> -					GPIOF_OUT_INIT_HIGH :
> -					GPIOF_OUT_INIT_LOW,
> -				"PCIe reset");
> -		if (ret) {
> -			dev_err(dev, "unable to get reset gpio\n");
> -			return ret;
> -		}
> -	} else if (imx6_pcie->reset_gpio == -EPROBE_DEFER) {
> -		return imx6_pcie->reset_gpio;
> -	}
> +	imx6_pcie->reset_gpio = devm_gpiod_get_optional(dev, "reset",
> +			imx6_pcie->gpio_active_high ?  GPIOD_OUT_HIGH : GPIOD_OUT_LOW);
> +	if (IS_ERR(imx6_pcie->reset_gpio))
> +		return dev_err_probe(dev, PTR_ERR(imx6_pcie->reset_gpio),
> +				"unable to get reset gpio\n");
>  
>  	/* Fetch clocks */
>  	imx6_pcie->pcie_phy = devm_clk_get(dev, "pcie_phy");



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

* Re: [PATCH v2 RESEND] PCI: imx6: Replace legacy gpio interface for gpiod interface
  2021-11-01 14:21 ` Lucas Stach
@ 2021-11-01 14:44   ` Maíra Canal
  2021-11-01 14:58     ` Lucas Stach
  0 siblings, 1 reply; 5+ messages in thread
From: Maíra Canal @ 2021-11-01 14:44 UTC (permalink / raw)
  To: Lucas Stach
  Cc: hongxing.zhu, lorenzo.pieralisi, robh, Bjorn Helgaas,
	Bjorn Helgaas, shawnguo, s.hauer, kernel, linux-imx, linux-pci,
	linux-arm-kernel, linux-kernel

?
> >       /* Some boards don't have PCIe reset GPIO. */
> > -     if (gpio_is_valid(imx6_pcie->reset_gpio)) {
> > -             gpio_set_value_cansleep(imx6_pcie->reset_gpio,
> > +     if (imx6_pcie->reset_gpio) {
> > +             gpiod_set_value_cansleep(imx6_pcie->reset_gpio,
> >                                       imx6_pcie->gpio_active_high);
> >               msleep(100);
> > -             gpio_set_value_cansleep(imx6_pcie->reset_gpio,
> > +             gpiod_set_value_cansleep(imx6_pcie->reset_gpio,
> >                                       !imx6_pcie->gpio_active_high);
>
> I don't think this is correct. gpiod_set_value sets the logical line
> state, so if the GPIO is specified as active-low in the DT, the real
> line state will be negated. The only reason why the reset-gpio-active-
> high property even exists is that old DTs might specify the wrong GPIO
> polarity in the reset-gpio DT description. I think you need to use to
> gpiod_set_raw_value API here to get the expected real line state even
> with a broken DT description.
>
> Regards,
> Lucas
>

I'm a beginner in kernel development, so I'm sorry for the question.
If I change gpiod_set_value_cansleep for gpiod_set_raw_value, wouldn't
I change the behavior of the driver? I replaced
gpio_set_value_cansleep for gpiod_set_value_cansleep because they have
the same behavior and I didn't change the logic states. Thank you for
the feedback!

Regards,
Maíra

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

* Re: [PATCH v2 RESEND] PCI: imx6: Replace legacy gpio interface for gpiod interface
  2021-11-01 14:44   ` Maíra Canal
@ 2021-11-01 14:58     ` Lucas Stach
  2021-11-02  0:45       ` Maíra Canal
  0 siblings, 1 reply; 5+ messages in thread
From: Lucas Stach @ 2021-11-01 14:58 UTC (permalink / raw)
  To: Maíra Canal
  Cc: hongxing.zhu, lorenzo.pieralisi, robh, Bjorn Helgaas,
	Bjorn Helgaas, shawnguo, s.hauer, kernel, linux-imx, linux-pci,
	linux-arm-kernel, linux-kernel

Am Montag, dem 01.11.2021 um 11:44 -0300 schrieb Maíra Canal:
> ?
> > >       /* Some boards don't have PCIe reset GPIO. */
> > > -     if (gpio_is_valid(imx6_pcie->reset_gpio)) {
> > > -             gpio_set_value_cansleep(imx6_pcie->reset_gpio,
> > > +     if (imx6_pcie->reset_gpio) {
> > > +             gpiod_set_value_cansleep(imx6_pcie->reset_gpio,
> > >                                       imx6_pcie->gpio_active_high);
> > >               msleep(100);
> > > -             gpio_set_value_cansleep(imx6_pcie->reset_gpio,
> > > +             gpiod_set_value_cansleep(imx6_pcie->reset_gpio,
> > >                                       !imx6_pcie->gpio_active_high);
> > 
> > I don't think this is correct. gpiod_set_value sets the logical line
> > state, so if the GPIO is specified as active-low in the DT, the real
> > line state will be negated. The only reason why the reset-gpio-active-
> > high property even exists is that old DTs might specify the wrong GPIO
> > polarity in the reset-gpio DT description. I think you need to use to
> > gpiod_set_raw_value API here to get the expected real line state even
> > with a broken DT description.
> > 
> > Regards,
> > Lucas
> > 
> 
> I'm a beginner in kernel development, so I'm sorry for the question.
> If I change gpiod_set_value_cansleep for gpiod_set_raw_value, wouldn't
> I change the behavior of the driver? I replaced
> gpio_set_value_cansleep for gpiod_set_value_cansleep because they have
> the same behavior and I didn't change the logic states. Thank you for
> the feedback!

Yes, you need to use the _cansleep variant of the API to keep the
context information. The point I was trying to make was that you
probably (please double check, that's just an assumption on my side)
need to use the _raw variant of the gpiod API to keep the current
behavior of the driver, as we are setting the physical line state
purely depending on the reset-gpio-active-high property presence, not
the logical line state, which would take into account the polarity
specified in the DT gpio descriptor.

I guess the right API call here would be
gpiod_set_raw_value_cansleep().

Regards,
Lucas


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

* Re: [PATCH v2 RESEND] PCI: imx6: Replace legacy gpio interface for gpiod interface
  2021-11-01 14:58     ` Lucas Stach
@ 2021-11-02  0:45       ` Maíra Canal
  0 siblings, 0 replies; 5+ messages in thread
From: Maíra Canal @ 2021-11-02  0:45 UTC (permalink / raw)
  To: Lucas Stach
  Cc: hongxing.zhu, lorenzo.pieralisi, robh, Bjorn Helgaas,
	Bjorn Helgaas, shawnguo, s.hauer, kernel, linux-imx, linux-pci,
	linux-arm-kernel, linux-kernel

Em seg., 1 de nov. de 2021 às 11:58, Lucas Stach
<l.stach@pengutronix.de> escreveu:
>
> Am Montag, dem 01.11.2021 um 11:44 -0300 schrieb Maíra Canal:
> > ?
> > > >       /* Some boards don't have PCIe reset GPIO. */
> > > > -     if (gpio_is_valid(imx6_pcie->reset_gpio)) {
> > > > -             gpio_set_value_cansleep(imx6_pcie->reset_gpio,
> > > > +     if (imx6_pcie->reset_gpio) {
> > > > +             gpiod_set_value_cansleep(imx6_pcie->reset_gpio,
> > > >                                       imx6_pcie->gpio_active_high);
> > > >               msleep(100);
> > > > -             gpio_set_value_cansleep(imx6_pcie->reset_gpio,
> > > > +             gpiod_set_value_cansleep(imx6_pcie->reset_gpio,
> > > >                                       !imx6_pcie->gpio_active_high);
> > >
> > > I don't think this is correct. gpiod_set_value sets the logical line
> > > state, so if the GPIO is specified as active-low in the DT, the real
> > > line state will be negated. The only reason why the reset-gpio-active-
> > > high property even exists is that old DTs might specify the wrong GPIO
> > > polarity in the reset-gpio DT description. I think you need to use to
> > > gpiod_set_raw_value API here to get the expected real line state even
> > > with a broken DT description.
> > >
> > > Regards,
> > > Lucas
> > >
> >
> > I'm a beginner in kernel development, so I'm sorry for the question.
> > If I change gpiod_set_value_cansleep for gpiod_set_raw_value, wouldn't
> > I change the behavior of the driver? I replaced
> > gpio_set_value_cansleep for gpiod_set_value_cansleep because they have
> > the same behavior and I didn't change the logic states. Thank you for
> > the feedback!
>
> Yes, you need to use the _cansleep variant of the API to keep the
> context information. The point I was trying to make was that you
> probably (please double check, that's just an assumption on my side)
> need to use the _raw variant of the gpiod API to keep the current
> behavior of the driver, as we are setting the physical line state
> purely depending on the reset-gpio-active-high property presence, not
> the logical line state, which would take into account the polarity
> specified in the DT gpio descriptor.
>
> I guess the right API call here would be
> gpiod_set_raw_value_cansleep().

I got it now. Thank you for your attention! I will send the v3 with
the correction.

>
> Regards,
> Lucas
>

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

end of thread, other threads:[~2021-11-02  0:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-01 14:03 [PATCH v2 RESEND] PCI: imx6: Replace legacy gpio interface for gpiod interface Maíra Canal
2021-11-01 14:21 ` Lucas Stach
2021-11-01 14:44   ` Maíra Canal
2021-11-01 14:58     ` Lucas Stach
2021-11-02  0:45       ` Maíra Canal

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).