All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] pci: imx: use reset-gpios if defined by device-tree
@ 2021-07-06 17:19 Tim Harvey
  2021-07-10 15:53 ` sbabic
  2021-07-10 19:36 ` sbabic
  0 siblings, 2 replies; 3+ messages in thread
From: Tim Harvey @ 2021-07-06 17:19 UTC (permalink / raw)
  To: Ian Ray, Sebastian Reichel, Fabio Estevam, Marek Vasut,
	Soeren Moch, Silvio Fricke, Stefano Babic,
	NXP i . MX U-Boot Team, u-boot
  Cc: Tim Harvey

If reset-gpio is defined by device-tree use that if
CONFIG_PCIE_IMX_PERST_GPIO is not defined.

Note that after this the following boards which define
CONFIG_PCIE_IMX_PERST_GPIO in their board header file as well as their
device-tree should be able to remove CONFIG_PCIE_IMX_PERST_GPIO without
consequence:
 - mx6sabresd
 - mx6sxsabresd
 - novena
 - tbs2910
 - vining_2000

Note that the ge_bx50v3 board uses CONFIG_PCIE_IMX_PERST_GPIO and does
not have reset-gpios defined it it's pcie node in the dt thus removing
CONFIG_PCIE_IMX_PERST_GPIO globally can't be done until that board adds
reset-gpios.

Cc: Ian Ray <ian.ray@ge.com> (maintainer:GE BX50V3 BOARD)
Cc: Sebastian Reichel <sebastian.reichel@collabora.com> (maintainer:GE BX50V3 BOARD)
Cc: Fabio Estevam <festevam@gmail.com> (maintainer:MX6SABRESD BOARD)
Cc: Marek Vasut <marex@denx.de> (maintainer:NOVENA BOARD)
Cc: Soeren Moch <smoch@web.de> (maintainer:TBS2910 BOARD)
Cc: Silvio Fricke <open-source@softing.de> (maintainer:VINING_2000 BOARD)
Signed-off-by: Tim Harvey <tharvey@gateworks.com>
---
v2:
 - pass gpio_desc and active_high to imx6_pcie_toggle_reset to
   imx6_pcie_toggle_reset
 - move reset logic to imx6_pcie_toggle_reset to avoid code change for
   boards using CONFIG_PCIE_IMX_PERST_GPIO
 - rename gpio_active_high to reset_active_high
 - change assertion delay and post delay to match use of
   CONFIG_PCIE_IMX_PERST_GPIO codepath
---
 arch/arm/include/asm/arch-mx6/sys_proto.h |  3 ++-
 board/gateworks/gw_ventana/gw_ventana.c   |  2 +-
 drivers/pci/pcie_imx.c                    | 29 +++++++++++++++++++----
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/arch/arm/include/asm/arch-mx6/sys_proto.h b/arch/arm/include/asm/arch-mx6/sys_proto.h
index 1e5fa1a75e..c49759af92 100644
--- a/arch/arm/include/asm/arch-mx6/sys_proto.h
+++ b/arch/arm/include/asm/arch-mx6/sys_proto.h
@@ -7,6 +7,7 @@
 #ifndef __SYS_PROTO_IMX6_
 #define __SYS_PROTO_IMX6_
 
+#include <asm/gpio.h>
 #include <asm/mach-imx/sys_proto.h>
 #include <asm/arch/iomux.h>
 
@@ -18,7 +19,7 @@
 				   USBPHY_PWD_RXPWDRX))
 
 int imx6_pcie_toggle_power(void);
-int imx6_pcie_toggle_reset(void);
+int imx6_pcie_toggle_reset(struct gpio_desc *gpio, bool active_high);
 
 enum ldo_reg {
 	LDO_ARM,
diff --git a/board/gateworks/gw_ventana/gw_ventana.c b/board/gateworks/gw_ventana/gw_ventana.c
index 5d47ca4537..47cce497fe 100644
--- a/board/gateworks/gw_ventana/gw_ventana.c
+++ b/board/gateworks/gw_ventana/gw_ventana.c
@@ -372,7 +372,7 @@ int power_init_board(void)
 	return 0;
 }
 
-int imx6_pcie_toggle_reset(void)
+int imx6_pcie_toggle_reset(struct gpio_desc *gpio, bool active_high)
 {
 	if (board_type < GW_UNKNOWN) {
 		uint pin = gpio_cfg[board_type].pcie_rst;
diff --git a/drivers/pci/pcie_imx.c b/drivers/pci/pcie_imx.c
index 73875e00db..7b46fdb89a 100644
--- a/drivers/pci/pcie_imx.c
+++ b/drivers/pci/pcie_imx.c
@@ -100,6 +100,8 @@
 struct imx_pcie_priv {
 	void __iomem		*dbi_base;
 	void __iomem		*cfg_base;
+	struct gpio_desc	reset_gpio;
+	bool			reset_active_high;
 };
 
 /*
@@ -541,7 +543,7 @@ __weak int imx6_pcie_toggle_power(void)
 	return 0;
 }
 
-__weak int imx6_pcie_toggle_reset(void)
+__weak int imx6_pcie_toggle_reset(struct gpio_desc *gpio, bool active_high)
 {
 	/*
 	 * See 'PCI EXPRESS BASE SPECIFICATION, REV 3.0, SECTION 6.6.1'
@@ -579,12 +581,20 @@ __weak int imx6_pcie_toggle_reset(void)
 	mdelay(20);
 	gpio_free(CONFIG_PCIE_IMX_PERST_GPIO);
 #else
-	puts("WARNING: Make sure the PCIe #PERST line is connected!\n");
+	if (dm_gpio_is_valid(gpio)) {
+		/* Assert PERST# for 20ms then de-assert */
+		dm_gpio_set_value(gpio, active_high ? 0 : 1);
+		mdelay(20);
+		dm_gpio_set_value(gpio, active_high ? 1 : 0);
+		mdelay(20);
+	} else {
+		puts("WARNING: Make sure the PCIe #PERST line is connected!\n");
+	}
 #endif
 	return 0;
 }
 
-static int imx6_pcie_deassert_core_reset(void)
+static int imx6_pcie_deassert_core_reset(struct imx_pcie_priv *priv)
 {
 	struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
 
@@ -612,7 +622,7 @@ static int imx6_pcie_deassert_core_reset(void)
 	setbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_REF_SSP_EN);
 #endif
 
-	imx6_pcie_toggle_reset();
+	imx6_pcie_toggle_reset(&priv->reset_gpio, priv->reset_active_high);
 
 	return 0;
 }
@@ -625,7 +635,7 @@ static int imx_pcie_link_up(struct imx_pcie_priv *priv)
 
 	imx6_pcie_assert_core_reset(priv, false);
 	imx6_pcie_init_phy();
-	imx6_pcie_deassert_core_reset();
+	imx6_pcie_deassert_core_reset(priv);
 
 	imx_pcie_regions_setup(priv);
 
@@ -787,6 +797,15 @@ static int imx_pcie_dm_probe(struct udevice *dev)
 {
 	struct imx_pcie_priv *priv = dev_get_priv(dev);
 
+	/* if PERST# valid from dt then assert it */
+	gpio_request_by_name(dev, "reset-gpio", 0, &priv->reset_gpio,
+			     GPIOD_IS_OUT);
+	priv->reset_active_high = dev_read_bool(dev, "reset-gpio-active-high");
+	if (dm_gpio_is_valid(&priv->reset_gpio)) {
+		dm_gpio_set_value(&priv->reset_gpio,
+				  priv->reset_active_high ? 0 : 1);
+	}
+
 	return imx_pcie_link_up(priv);
 }
 
-- 
2.17.1


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

* [PATCH v2] pci: imx: use reset-gpios if defined by device-tree
  2021-07-06 17:19 [PATCH v2] pci: imx: use reset-gpios if defined by device-tree Tim Harvey
@ 2021-07-10 15:53 ` sbabic
  2021-07-10 19:36 ` sbabic
  1 sibling, 0 replies; 3+ messages in thread
From: sbabic @ 2021-07-10 15:53 UTC (permalink / raw)
  To: Tim Harvey, u-boot

> If reset-gpio is defined by device-tree use that if
> CONFIG_PCIE_IMX_PERST_GPIO is not defined.
> Note that after this the following boards which define
> CONFIG_PCIE_IMX_PERST_GPIO in their board header file as well as their
> device-tree should be able to remove CONFIG_PCIE_IMX_PERST_GPIO without
> consequence:
>  - mx6sabresd
>  - mx6sxsabresd
>  - novena
>  - tbs2910
>  - vining_2000
> Note that the ge_bx50v3 board uses CONFIG_PCIE_IMX_PERST_GPIO and does
> not have reset-gpios defined it it's pcie node in the dt thus removing
> CONFIG_PCIE_IMX_PERST_GPIO globally can't be done until that board adds
> reset-gpios.
> Cc: Ian Ray <ian.ray@ge.com> (maintainer:GE BX50V3 BOARD)
> Cc: Sebastian Reichel <sebastian.reichel@collabora.com> (maintainer:GE BX50V3 BOARD)
> Cc: Fabio Estevam <festevam@gmail.com> (maintainer:MX6SABRESD BOARD)
> Cc: Marek Vasut <marex@denx.de> (maintainer:NOVENA BOARD)
> Cc: Soeren Moch <smoch@web.de> (maintainer:TBS2910 BOARD)
> Cc: Silvio Fricke <open-source@softing.de> (maintainer:VINING_2000 BOARD)
> Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de
=====================================================================

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

* [PATCH v2] pci: imx: use reset-gpios if defined by device-tree
  2021-07-06 17:19 [PATCH v2] pci: imx: use reset-gpios if defined by device-tree Tim Harvey
  2021-07-10 15:53 ` sbabic
@ 2021-07-10 19:36 ` sbabic
  1 sibling, 0 replies; 3+ messages in thread
From: sbabic @ 2021-07-10 19:36 UTC (permalink / raw)
  To: Tim Harvey, u-boot

> If reset-gpio is defined by device-tree use that if
> CONFIG_PCIE_IMX_PERST_GPIO is not defined.
> Note that after this the following boards which define
> CONFIG_PCIE_IMX_PERST_GPIO in their board header file as well as their
> device-tree should be able to remove CONFIG_PCIE_IMX_PERST_GPIO without
> consequence:
>  - mx6sabresd
>  - mx6sxsabresd
>  - novena
>  - tbs2910
>  - vining_2000
> Note that the ge_bx50v3 board uses CONFIG_PCIE_IMX_PERST_GPIO and does
> not have reset-gpios defined it it's pcie node in the dt thus removing
> CONFIG_PCIE_IMX_PERST_GPIO globally can't be done until that board adds
> reset-gpios.
> Cc: Ian Ray <ian.ray@ge.com> (maintainer:GE BX50V3 BOARD)
> Cc: Sebastian Reichel <sebastian.reichel@collabora.com> (maintainer:GE BX50V3 BOARD)
> Cc: Fabio Estevam <festevam@gmail.com> (maintainer:MX6SABRESD BOARD)
> Cc: Marek Vasut <marex@denx.de> (maintainer:NOVENA BOARD)
> Cc: Soeren Moch <smoch@web.de> (maintainer:TBS2910 BOARD)
> Cc: Silvio Fricke <open-source@softing.de> (maintainer:VINING_2000 BOARD)
> Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de
=====================================================================

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

end of thread, other threads:[~2021-07-10 19:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06 17:19 [PATCH v2] pci: imx: use reset-gpios if defined by device-tree Tim Harvey
2021-07-10 15:53 ` sbabic
2021-07-10 19:36 ` sbabic

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.