From: "Pali Rohár" <pali@kernel.org> To: "Jason Cooper" <jason@lakedaemon.net>, "Andrew Lunn" <andrew@lunn.ch>, "Gregory Clement" <gregory.clement@bootlin.com>, "Sebastian Hesselbarth" <sebastian.hesselbarth@gmail.com>, "Rob Herring" <robh+dt@kernel.org>, "Thomas Petazzoni" <thomas.petazzoni@bootlin.com>, "Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>, "Andrew Murray" <amurray@thegoodpenguin.co.uk>, "Bjorn Helgaas" <bhelgaas@google.com>, "Remi Pommarel" <repk@triplefau.lt>, "Marek Behún" <marek.behun@nic.cz>, "Tomasz Maciej Nowak" <tmn505@gmail.com>, Xogium <contact@xogium.me> Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: [PATCH 6/8] PCI: aardvark: Add support for issuing PERST via GPIO Date: Wed, 15 Apr 2020 18:03:46 +0200 [thread overview] Message-ID: <20200415160348.1146-2-pali@kernel.org> (raw) In-Reply-To: <20200415160054.951-1-pali@kernel.org> bindings/pci/pci.txt defines standard DT property reset-gpios for specifying PERST GPIO. Read this property from Device Tree via devm_gpiod_get_from_of_node() function. As this property is optional, function may return -ENOENT. During initialization of aardvark PCI controller toggle supplied GPIO to issue PERST. Some Compex ath10k cards (e.g. WLE900VX or WLE1216) are not detected after reboot when PERST is not issued during driver initialization. And Compex WLE1216 cards need to be in reset state for at least 1ms otherwise they are not detected too. Tested on Turris MOX and after this change Compex cards are detected also after rebooting board. Signed-off-by: Pali Rohár <pali@kernel.org> --- drivers/pci/controller/pci-aardvark.c | 30 ++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index a83bbc86e428..6a97a3838098 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" @@ -203,6 +205,7 @@ struct advk_pcie { u16 msi_msg; int root_bus_nr; struct pci_bridge_emul bridge; + struct gpio_desc *reset_gpio; }; static inline void advk_writel(struct advk_pcie *pcie, u32 val, u64 reg) @@ -280,6 +283,14 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie) int max_link_speed, neg_link_speed; u32 reg; + if (pcie->reset_gpio) { + dev_info(dev, "issuing PERST via reset GPIO for 1ms\n"); + gpiod_set_value_cansleep(pcie->reset_gpio, 1); + /* Detection of some Compex WLE1216 cards needs at least 1ms */ + mdelay(1); + gpiod_set_value_cansleep(pcie->reset_gpio, 0); + } + /* Set to Direct mode */ reg = advk_readl(pcie, CTRL_CONFIG_REG); reg &= ~(CTRL_MODE_MASK << CTRL_MODE_SHIFT); @@ -358,7 +369,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 + * routine at beginning of this function, 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. */ @@ -1043,6 +1055,22 @@ static int advk_pcie_probe(struct platform_device *pdev) } pcie->root_bus_nr = bus->start; + /* Returns -ENOENT if reset-gpios property is not populated */ + pcie->reset_gpio = devm_gpiod_get_from_of_node(dev, dev->of_node, + "reset-gpios", 0, + GPIOD_OUT_LOW, + "pcie1-reset"); + if (IS_ERR(pcie->reset_gpio)) { + if (PTR_ERR(pcie->reset_gpio) == -ENOENT) { + pcie->reset_gpio = NULL; + } else { + if (PTR_ERR(pcie->reset_gpio) != -EPROBE_DEFER) + dev_err(dev, "Failed to retrieve reset GPIO (%ld)\n", + PTR_ERR(pcie->reset_gpio)); + return PTR_ERR(pcie->reset_gpio); + } + } + advk_pcie_setup_hw(pcie); advk_sw_pci_bridge_init(pcie); -- 2.20.1
next prev parent reply other threads:[~2020-04-15 16:04 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-04-15 16:00 [PATCH 0/8] PCI: aardvark: Fix support for Turris MOX and Compex wifi cards Pali Rohár 2020-04-15 16:00 ` [PATCH 1/8] PCI: aardvark: Set controller speed from Device Tree max-link-speed Pali Rohár 2020-04-15 16:00 ` [PATCH 2/8] dts: espressobin: Define max-link-speed for pcie0 Pali Rohár 2020-04-19 3:19 ` Marek Behun 2020-04-15 16:00 ` [PATCH 3/8] PCI: aardvark: Start link training immediately after enabling link training Pali Rohár 2020-04-15 16:00 ` [PATCH 4/8] PCI: aardvark: Do not overwrite Link Status register and ASPM Control bits in Link Control register Pali Rohár 2020-04-15 16:03 ` [PATCH 5/8] PCI: aardvark: Set final controller speed based on negotiated link speed Pali Rohár 2020-04-19 3:17 ` Marek Behun 2020-04-15 16:03 ` Pali Rohár [this message] 2020-04-19 3:23 ` [PATCH 6/8] PCI: aardvark: Add support for issuing PERST via GPIO Marek Behun 2020-04-15 16:03 ` [PATCH 7/8] dts: aardvark: Route pcie reset pin to gpio function and define reset-gpios for pcie Pali Rohár 2020-04-19 3:54 ` Marek Behun 2020-04-15 16:03 ` [PATCH 8/8] PCI: aardvark: Add FIXME for code which access PCIE_CORE_CMD_STATUS_REG Pali Rohár 2020-04-15 16:18 ` Pali Rohár 2020-04-16 15:50 ` [PATCH 0/8] PCI: aardvark: Fix support for Turris MOX and Compex wifi cards Tomasz Maciej Nowak 2020-04-19 4:01 ` Marek Behun
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=20200415160348.1146-2-pali@kernel.org \ --to=pali@kernel.org \ --cc=amurray@thegoodpenguin.co.uk \ --cc=andrew@lunn.ch \ --cc=bhelgaas@google.com \ --cc=contact@xogium.me \ --cc=devicetree@vger.kernel.org \ --cc=gregory.clement@bootlin.com \ --cc=jason@lakedaemon.net \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-pci@vger.kernel.org \ --cc=lorenzo.pieralisi@arm.com \ --cc=marek.behun@nic.cz \ --cc=repk@triplefau.lt \ --cc=robh+dt@kernel.org \ --cc=sebastian.hesselbarth@gmail.com \ --cc=thomas.petazzoni@bootlin.com \ --cc=tmn505@gmail.com \ --subject='Re: [PATCH 6/8] PCI: aardvark: Add support for issuing PERST via GPIO' \ /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
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).