diff mbox series

[v1,1/3] PCI: imx6: Add a function to deassert the reset gpio

Message ID 20240819090428.17349-2-eichest@gmail.com (mailing list archive)
State New
Headers show
Series PCI: imx6: reset link after suspend/resume | expand

Commit Message

Stefan Eichenberger Aug. 19, 2024, 9:03 a.m. UTC
From: Stefan Eichenberger <stefan.eichenberger@toradex.com>

To avoid code duplication, move the code to disable the reset GPIO to a
separate function.

Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
---
 drivers/pci/controller/dwc/pci-imx6.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

Comments

Frank Li Aug. 19, 2024, 2:49 p.m. UTC | #1
On Mon, Aug 19, 2024 at 11:03:17AM +0200, Stefan Eichenberger wrote:
> From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
>
> To avoid code duplication, move the code to disable the reset GPIO to a
> separate function.

Add help function imx6_pcie_deassert_reset_gpio() to handle reset GPIO.

>
> Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> ---
>  drivers/pci/controller/dwc/pci-imx6.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> index 964d67756eb2b..fda704d82431f 100644
> --- a/drivers/pci/controller/dwc/pci-imx6.c
> +++ b/drivers/pci/controller/dwc/pci-imx6.c
> @@ -722,6 +722,17 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie)
>  	gpiod_set_value_cansleep(imx6_pcie->reset_gpiod, 1);
>  }
>
> +static void imx6_pcie_deassert_reset_gpio(struct imx6_pcie *imx6_pcie)
> +{
> +	/* Some boards don't have PCIe reset GPIO. */
> +	if (imx6_pcie->reset_gpiod) {
> +		msleep(100);
> +		gpiod_set_value_cansleep(imx6_pcie->reset_gpiod, 0);
> +		/* Wait for 100ms after PERST# deassertion (PCIe r5.0, 6.6.1) */
> +		msleep(100);
> +	}
> +}
> +
>  static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
>  {
>  	struct dw_pcie *pci = imx6_pcie->pci;
> @@ -766,13 +777,7 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
>  		break;
>  	}
>
> -	/* Some boards don't have PCIe reset GPIO. */
> -	if (imx6_pcie->reset_gpiod) {
> -		msleep(100);
> -		gpiod_set_value_cansleep(imx6_pcie->reset_gpiod, 0);
> -		/* Wait for 100ms after PERST# deassertion (PCIe r5.0, 6.6.1) */
> -		msleep(100);
> -	}
> +	imx6_pcie_deassert_reset_gpio(imx6_pcie);
>
>  	return 0;
>  }
> --
> 2.43.0
>
Stefan Eichenberger Aug. 20, 2024, 7:07 a.m. UTC | #2
On Mon, Aug 19, 2024 at 10:49:14AM -0400, Frank Li wrote:
> On Mon, Aug 19, 2024 at 11:03:17AM +0200, Stefan Eichenberger wrote:
> > From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> >
> > To avoid code duplication, move the code to disable the reset GPIO to a
> > separate function.
> 
> Add help function imx6_pcie_deassert_reset_gpio() to handle reset GPIO.
> 

Sounds good, thanks for the suggestion.
diff mbox series

Patch

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index 964d67756eb2b..fda704d82431f 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -722,6 +722,17 @@  static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie)
 	gpiod_set_value_cansleep(imx6_pcie->reset_gpiod, 1);
 }
 
+static void imx6_pcie_deassert_reset_gpio(struct imx6_pcie *imx6_pcie)
+{
+	/* Some boards don't have PCIe reset GPIO. */
+	if (imx6_pcie->reset_gpiod) {
+		msleep(100);
+		gpiod_set_value_cansleep(imx6_pcie->reset_gpiod, 0);
+		/* Wait for 100ms after PERST# deassertion (PCIe r5.0, 6.6.1) */
+		msleep(100);
+	}
+}
+
 static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
 {
 	struct dw_pcie *pci = imx6_pcie->pci;
@@ -766,13 +777,7 @@  static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
 		break;
 	}
 
-	/* Some boards don't have PCIe reset GPIO. */
-	if (imx6_pcie->reset_gpiod) {
-		msleep(100);
-		gpiod_set_value_cansleep(imx6_pcie->reset_gpiod, 0);
-		/* Wait for 100ms after PERST# deassertion (PCIe r5.0, 6.6.1) */
-		msleep(100);
-	}
+	imx6_pcie_deassert_reset_gpio(imx6_pcie);
 
 	return 0;
 }