From: Rob Herring <robh@kernel.org>
To: "Pali Rohár" <pali@kernel.org>
Cc: PCI <linux-pci@vger.kernel.org>,
"Jason Cooper" <jason@lakedaemon.net>,
"Andrew Lunn" <andrew@lunn.ch>,
"Gregory Clement" <gregory.clement@bootlin.com>,
"Sebastian Hesselbarth" <sebastian.hesselbarth@gmail.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
"Andrew Murray" <amurray@thegoodpenguin.co.uk>,
"Remi Pommarel" <repk@triplefau.lt>,
"Tomasz Maciej Nowak" <tmn505@gmail.com>,
Xogium <contact@xogium.me>, "Marek Behún" <marek.behun@nic.cz>,
"Bjorn Helgaas" <helgaas@kernel.org>
Subject: Re: [PATCH v3 05/12] PCI: aardvark: Issue PERST via GPIO
Date: Fri, 24 Apr 2020 12:05:29 -0500 [thread overview]
Message-ID: <CAL_Jsq+nmYMZQOUDQVO4FSU_3qg9hSJ8dOPQBymR8b-NMiAyuQ@mail.gmail.com> (raw)
In-Reply-To: <20200424153858.29744-6-pali@kernel.org>
On Fri, Apr 24, 2020 at 10:39 AM Pali Rohár <pali@kernel.org> wrote:
>
> Add support for issuing PERST via GPIO specified in 'reset-gpios'
> property (as described in PCI device tree bindings).
>
> Some buggy cards (e.g. Compex WLE900VX or WLE1216) are not detected
> after reboot when PERST is not issued during driver initialization.
>
> If bootloader already enabled link training then issuing PERST has no
> effect for some buggy cards (e.g. Compex WLE900VX) and these cards are
> not detected. We therefore clear the LINK_TRAINING_EN register before.
>
> It was observed that Compex WLE900VX card needs to be in PERST reset
> for at least 10ms if bootloader enabled link training.
>
> Tested on Turris MOX.
>
> Signed-off-by: Pali Rohár <pali@kernel.org>
> ---
> drivers/pci/controller/pci-aardvark.c | 43 ++++++++++++++++++++++++++-
> 1 file changed, 42 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
> index a6c4d4d52631..9e2f44213b5e 100644
> --- a/drivers/pci/controller/pci-aardvark.c
> +++ b/drivers/pci/controller/pci-aardvark.c
> @@ -9,6 +9,7 @@
> */
>
> #include <linux/delay.h>
> +#include <linux/gpio.h>
> #include <linux/interrupt.h>
> #include <linux/irq.h>
> #include <linux/irqdomain.h>
> @@ -18,6 +19,7 @@
> #include <linux/platform_device.h>
> #include <linux/msi.h>
> #include <linux/of_address.h>
> +#include <linux/of_gpio.h>
> #include <linux/of_pci.h>
>
> #include "../pci.h"
> @@ -204,6 +206,7 @@ struct advk_pcie {
> int root_bus_nr;
> int link_gen;
> struct pci_bridge_emul bridge;
> + struct gpio_desc *reset_gpio;
> };
>
> static inline void advk_writel(struct advk_pcie *pcie, u32 val, u64 reg)
> @@ -330,10 +333,31 @@ static void advk_pcie_train_link(struct advk_pcie *pcie)
> dev_err(dev, "link never came up\n");
> }
>
> +static void advk_pcie_issue_perst(struct advk_pcie *pcie)
> +{
> + u32 reg;
> +
> + if (!pcie->reset_gpio)
> + return;
> +
> + /* PERST does not work for some cards when link training is enabled */
> + reg = advk_readl(pcie, PCIE_CORE_CTRL0_REG);
> + reg &= ~LINK_TRAINING_EN;
> + advk_writel(pcie, reg, PCIE_CORE_CTRL0_REG);
> +
> + /* 10ms delay is needed for some cards */
> + dev_info(&pcie->pdev->dev, "issuing PERST via reset GPIO for 10ms\n");
> + gpiod_set_value_cansleep(pcie->reset_gpio, 1);
> + usleep_range(10000, 11000);
> + gpiod_set_value_cansleep(pcie->reset_gpio, 0);
> +}
> +
> static void advk_pcie_setup_hw(struct advk_pcie *pcie)
> {
> u32 reg;
>
> + advk_pcie_issue_perst(pcie);
> +
> /* Set to Direct mode */
> reg = advk_readl(pcie, CTRL_CONFIG_REG);
> reg &= ~(CTRL_MODE_MASK << CTRL_MODE_SHIFT);
> @@ -406,7 +430,8 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie)
>
> /*
> * PERST# signal could have been asserted by pinctrl subsystem before
> - * probe() callback has been called, making the endpoint going into
> + * probe() callback has been called or issued explicitly by reset gpio
> + * function advk_pcie_issue_perst(), making the endpoint going into
> * fundamental reset. As required by PCI Express spec a delay for at
> * least 100ms after such a reset before link training is needed.
> */
> @@ -1046,6 +1071,22 @@ static int advk_pcie_probe(struct platform_device *pdev)
> }
> pcie->root_bus_nr = bus->start;
>
> + pcie->reset_gpio = devm_gpiod_get_from_of_node(dev, dev->of_node,
> + "reset-gpios", 0,
> + GPIOD_OUT_LOW,
> + "pcie1-reset");
> + ret = PTR_ERR_OR_ZERO(pcie->reset_gpio);
> + if (ret) {
> + if (ret == -ENOENT) {
> + pcie->reset_gpio = NULL;
> + } else {
> + if (ret != -EPROBE_DEFER)
> + dev_err(dev, "Failed to get reset-gpio: %i\n",
> + ret);
> + return ret;
> + }
> + }
I believe all this can be replaced with devm_gpiod_get_optional.
Rob
next prev parent reply other threads:[~2020-04-24 17:05 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-24 15:38 [PATCH v3 00/12] PCI: aardvark: Fix support for Turris MOX and Compex wifi cards Pali Rohár
2020-04-24 15:38 ` [PATCH v3 01/12] PCI: aardvark: Train link immediately after enabling training Pali Rohár
2020-04-24 15:38 ` [PATCH v3 02/12] PCI: aardvark: Don't blindly enable ASPM L0s and don't write to read-only register Pali Rohár
2020-04-24 15:38 ` [PATCH v3 03/12] PCI: of: Return -ENOENT if max-link-speed property is not found Pali Rohár
2020-04-24 16:47 ` Rob Herring
2020-04-27 9:00 ` Pali Rohár
2020-04-28 15:52 ` Rob Herring
2020-04-28 16:01 ` Pali Rohár
2020-04-28 23:55 ` Marek Behun
2020-04-28 16:23 ` Bjorn Helgaas
2020-04-24 15:38 ` [PATCH v3 04/12] PCI: aardvark: Improve link training Pali Rohár
2020-04-24 17:00 ` Rob Herring
2020-04-24 18:55 ` Pali Rohár
2020-04-27 9:30 ` Pali Rohár
2020-04-24 15:38 ` [PATCH v3 05/12] PCI: aardvark: Issue PERST via GPIO Pali Rohár
2020-04-24 17:05 ` Rob Herring [this message]
2020-04-27 9:22 ` Pali Rohár
2020-04-24 15:38 ` [PATCH v3 06/12] PCI: aardvark: Add FIXME comment for PCIE_CORE_CMD_STATUS_REG access Pali Rohár
2020-04-24 15:38 ` [PATCH v3 07/12] PCI: aardvark: Add PHY support Pali Rohár
2020-04-24 15:38 ` [PATCH v3 08/12] PCI: aardvark: Replace custom macros by standard linux/pci_regs.h macros Pali Rohár
2020-04-24 18:52 ` Bjorn Helgaas
2020-04-24 15:38 ` [PATCH v3 09/12] dt-bindings: PCI: aardvark: Describe new properties Pali Rohár
2020-04-24 15:38 ` [PATCH v3 10/12] arm64: dts: marvell: armada-37xx: Set pcie_reset_pin to gpio function Pali Rohár
2020-04-24 15:38 ` [PATCH v3 11/12] arm64: dts: marvell: armada-37xx: Move PCIe comphy handle property Pali Rohár
2020-04-24 15:38 ` [PATCH v3 12/12] arm64: dts: marvell: armada-37xx: Move PCIe max-link-speed property Pali Rohár
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAL_Jsq+nmYMZQOUDQVO4FSU_3qg9hSJ8dOPQBymR8b-NMiAyuQ@mail.gmail.com \
--to=robh@kernel.org \
--cc=amurray@thegoodpenguin.co.uk \
--cc=andrew@lunn.ch \
--cc=contact@xogium.me \
--cc=gregory.clement@bootlin.com \
--cc=helgaas@kernel.org \
--cc=jason@lakedaemon.net \
--cc=linux-pci@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=marek.behun@nic.cz \
--cc=pali@kernel.org \
--cc=repk@triplefau.lt \
--cc=sebastian.hesselbarth@gmail.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=tmn505@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).