Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37ABBC11F64 for ; Thu, 1 Jul 2021 17:35:13 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E7A406044F for ; Thu, 1 Jul 2021 17:35:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E7A406044F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=gateworks.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5B8EF82C25; Thu, 1 Jul 2021 19:35:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gateworks.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 0E4AA82C25; Thu, 1 Jul 2021 19:35:07 +0200 (CEST) Received: from finn.localdomain (finn.gateworks.com [108.161.129.64]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 99CF482C28 for ; Thu, 1 Jul 2021 19:35:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gateworks.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=tharvey@gateworks.com Received: from 068-189-091-139.biz.spectrum.com ([68.189.91.139] helo=tharvey.pdc.gateworks.com) by finn.localdomain with esmtp (Exim 4.93) (envelope-from ) id 1lz0aT-004Qyg-Rw; Thu, 01 Jul 2021 17:34:53 +0000 From: Tim Harvey To: Ian Ray , Sebastian Reichel , Fabio Estevam , Marek Vasut , Soeren Moch , Silvio Fricke , Stefano Babic , "NXP i . MX U-Boot Team" , u-boot@lists.denx.de Cc: Tim Harvey Subject: [PATCH] pci: imx: use reset-gpios if defined by device-tree Date: Thu, 1 Jul 2021 10:34:51 -0700 Message-Id: <20210701173451.473-1-tharvey@gateworks.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean If reset-gpio is defined by device-tree use that instead of a board-specific function to toggle PCI reset. The presense of 'reset-gpio' in the device-tree will override calling the weak imx6_pcie_toggle_reset function therefore I've Cc'd all the board maintainers who rely on that function here as I would like to remove that function completely. The only user of a board-specific weak imx6_pcie_toggle_reset is gwventana which I am the maintainer for and once this patch is accepted I will be able to remove that use case and would then like to remove the use of CONFIG_PCIE_IMX_PERST_GPIO completely. I would have preferred implementing this without changing the codepath for the users of CONFIG_PCIE_IMX_PERST_GPIO but that would require passing in the imx_pcie_priv struct to imx6_pcie_toggle_reset which creates a chicken-and-egg scenario as that's currently a weak function for boards to override. Cc: Ian Ray (maintainer:GE BX50V3 BOARD) Cc: Sebastian Reichel (maintainer:GE BX50V3 BOARD) Cc: Fabio Estevam (maintainer:MX6SABRESD BOARD) Cc: Marek Vasut (maintainer:NOVENA BOARD) Cc: Soeren Moch (maintainer:TBS2910 BOARD) Cc: Silvio Fricke (maintainer:VINING_2000 BOARD) Signed-off-by: Tim Harvey --- drivers/pci/pcie_imx.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/pci/pcie_imx.c b/drivers/pci/pcie_imx.c index 73875e00db..c28951655d 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 gpio_active_high; }; /* @@ -584,7 +586,7 @@ __weak int imx6_pcie_toggle_reset(void) 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 +614,14 @@ static int imx6_pcie_deassert_core_reset(void) setbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_REF_SSP_EN); #endif - imx6_pcie_toggle_reset(); + if (dm_gpio_is_valid(&priv->reset_gpio)) { + /* Assert PERST# for 50ms then de-assert */ + dm_gpio_set_value(&priv->reset_gpio, priv->gpio_active_high ? 0 : 1); + mdelay(50); + dm_gpio_set_value(&priv->reset_gpio, priv->gpio_active_high ? 1 : 0); + } else { + imx6_pcie_toggle_reset(); + } return 0; } @@ -625,7 +634,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 +796,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->gpio_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->gpio_active_high ? 0 : 1); + } + return imx_pcie_link_up(priv); } -- 2.17.1