PCI: armada8k: add device reset to link-down handle
PATCH 1/1 PCI: armada8k: add device reset to link-down handle
Added pcie reset via gpio support as described in the designware-pcie.txt DT binding document.
In cases link down cause still exist in device.
The device need to be reset to reestablish the link. If reset-gpio pin provided in the device tree, then the linkdown handle resets the device before reestablishing link.
--- drivers/pci/controller/dwc/pcie-armada8k.c | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/pci/controller/dwc/pcie-armada8k.c +22 -2
@@ -23,6 +23,7 @@#include <linux/of_pci.h> #include <linux/mfd/syscon.h> #include <linux/regmap.h> +#include <linux/of_gpio.h> #include "pcie-designware.h"
@@ -37,6 +38,8 @@ struct armada8k_pcie {struct regmap *sysctrl_base;u32 mac_rest_bitmask;struct work_struct recover_link_work; +enum of_gpio_flags flags; +struct gpio_desc *reset_gpio; };#define PCIE_VENDOR_REGS_OFFSET 0x8000
@@ -238,9 +241,18 @@ static void armada8k_pcie_recover_link(struct work_struct *ws) }pci_lock_rescan_remove ();pci_stop_and_remove_bus_device (root_port); +/* Reset device if reset gpio is set */ +if (pcie->reset_gpio) { +/* assert and then deassert the reset signal */ +gpiod_set_value_cansleep (pcie->reset_gpio,0 ); +msleep (100 ); +gpiod_set_value_cansleep (pcie->reset_gpio, + (pcie->flags &OF_GPIO_ACTIVE_LOW ) ?0 :1 ); + }/* -* Sleep needed to make sure all pcie transactions and access -* are flushed before resetting the mac +* Sleep used for two reasons. +* First make sure all pcie transactions and access are flushed before resetting the mac +* and second to make sure pci device is ready in case we reset the device */ msleep (100 );
@@ -376,6 +388,7 @@ static int armada8k_pcie_probe(struct platform_device *pdev)struct armada8k_pcie *pcie;struct device *dev = &pdev->dev;struct resource *base; +int reset_gpio;int ret; pcie =devm_kzalloc (dev,sizeof (*pcie),GFP_KERNEL );
@@ -420,6 +433,13 @@ static int armada8k_pcie_probe(struct platform_device *pdev) goto fail_clkreg; } +/* Config reset gpio for pcie if the reset connected to gpio */ + reset_gpio =of_get_named_gpio_flags (pdev->dev.of_node, +"reset-gpios" ,0 , + &pcie->flags); +if (gpio_is_valid (reset_gpio)) + pcie->reset_gpio =gpio_to_desc (reset_gpio); + pcie->sysctrl_base =syscon_regmap_lookup_by_phandle (pdev->dev.of_node,"marvell,system-controller" );if (IS_ERR (pcie->sysctrl_base)) {
Signature · 1 line
2.25.1
Quoted 22 lines · Jenishkumar Maheshbhai Patel
drivers/pci/controller/dwc/pcie-armada8k.c +3
-0@@ -23,6 +23,7 @@#include <linux/of_pci.h> #include <linux/mfd/syscon.h> #include <linux/regmap.h> +#include <linux/of_gpio.h> #include "pcie-designware.h" @@ -37,6 +38,8 @@ struct armada8k_pcie {struct regmap *sysctrl_base;u32 mac_rest_bitmask;struct work_struct recover_link_work; +enum of_gpio_flags flags; +struct gpio_desc *reset_gpio; };#define PCIE_VENDOR_REGS_OFFSET 0x8000
drivers/pci/controller/dwc/pcie-armada8k.c static void armada8k_pcie_recover_link(struct work_struct *ws) · line 250
Quoted 10 lines
drivers/pci/controller/dwc/pcie-armada8k.c +7
-0@@ -238,9 +241,18 @@ static void armada8k_pcie_recover_link(struct work_struct *ws) }pci_lock_rescan_remove ();pci_stop_and_remove_bus_device (root_port); +/* Reset device if reset gpio is set */ +if (pcie->reset_gpio) { +/* assert and then deassert the reset signal */ +gpiod_set_value_cansleep (pcie->reset_gpio,0 ); +msleep (100 ); +gpiod_set_value_cansleep (pcie->reset_gpio, + (pcie->flags &OF_GPIO_ACTIVE_LOW ) ?0 :1 );
This looks wrong. resets are normally active-low. gpiod_set_value_cansleep() should be called with '1' to indicate active state, and '0' to indicate de-active state. DT should specify whether the signal is active high or active low.
drivers/pci/controller/dwc/pcie-armada8k.c static int armada8k_pcie_probe(struct platform_device *pdev) · line 442
Quoted 7 lines
drivers/pci/controller/dwc/pcie-armada8k.c +7
-0+/* Config reset gpio for pcie if the reset connected to gpio */ + reset_gpio =of_get_named_gpio_flags (pdev->dev.of_node, +"reset-gpios" ,0 , + &pcie->flags); +if (gpio_is_valid (reset_gpio)) + pcie->reset_gpio =gpio_to_desc (reset_gpio); +
Just use devm_fwnode_gpiod_get() here, which will also handle the cleanup.
To see how this should be done, look at drivers/pci/controller/pci-mvebu.c which gets the polarity settings correct too, as mentioned above.
Lastly, as this patch is related to the breaking DT change, it _should_ have been sent as a patch series (which means the same Cc list on each patch) so that reviewers can see the full story and comments on the other patches.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
In subject, follow capitalization convention. Use "git log --oneline".
Quoted 6 lines · Jenishkumar Maheshbhai Patel
Added pcie reset via gpio support as described in the designware-pcie.txt DT binding document.
In cases link down cause still exist in device.
The device need to be reset to reestablish the link. If reset-gpio pin provided in the device tree, then the linkdown handle resets the device before reestablishing link.
s/pcie/PCIe/
s/gpio/GPIO/
Add blank lines between paragraphs. Rewrap to fill 75 columns.
Quoted 10 lines
Signed-off-by Jenishkumar Maheshbhai Patel <[email protected]>--- drivers/pci/controller/dwc/pcie-armada8k.c | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)drivers/pci/controller/dwc/pcie-armada8k.c +0
-0
drivers/pci/controller/dwc/pcie-armada8k.c line 26
Quoted 4 lines
drivers/pci/controller/dwc/pcie-armada8k.c +1
-0@@ -23,6 +23,7 @@#include <linux/of_pci.h> #include <linux/mfd/syscon.h> #include <linux/regmap.h> +#include <linux/of_gpio.h>
Preserve (mostly) alpha sorted list of includes.
Quoted 12 lines
drivers/pci/controller/dwc/pcie-armada8k.c +2
-0#include "pcie-designware.h" @@ -37,6 +38,8 @@ struct armada8k_pcie {struct regmap *sysctrl_base;u32 mac_rest_bitmask;struct work_struct recover_link_work; +enum of_gpio_flags flags; +struct gpio_desc *reset_gpio; };#define PCIE_VENDOR_REGS_OFFSET 0x8000
drivers/pci/controller/dwc/pcie-armada8k.c static void armada8k_pcie_recover_link(struct work_struct *ws) · line 248
Quoted 8 lines
drivers/pci/controller/dwc/pcie-armada8k.c +5
-0@@ -238,9 +241,18 @@ static void armada8k_pcie_recover_link(struct work_struct *ws) }pci_lock_rescan_remove ();pci_stop_and_remove_bus_device (root_port); +/* Reset device if reset gpio is set */ +if (pcie->reset_gpio) { +/* assert and then deassert the reset signal */ +gpiod_set_value_cansleep (pcie->reset_gpio,0 ); +msleep (100 );
Needs some sort of #define for this 100 ms.
drivers/pci/controller/dwc/pcie-armada8k.c static void armada8k_pcie_recover_link(struct work_struct *ws) · line 257
Quoted 11 lines
drivers/pci/controller/dwc/pcie-armada8k.c +6
-2+gpiod_set_value_cansleep (pcie->reset_gpio, + (pcie->flags &OF_GPIO_ACTIVE_LOW ) ?0 :1 ); + }/* -* Sleep needed to make sure all pcie transactions and access -* are flushed before resetting the mac +* Sleep used for two reasons. +* First make sure all pcie transactions and access are flushed before resetting the mac +* and second to make sure pci device is ready in case we reset the device */ msleep (100 );
s/pcie/PCIe/ (throughout)
s/mac/MAC/
Explain the 100ms. Hopefully this is something defined by PCIe base or CEM spec. Use or add #define as needed.
Quoted 25 lines
drivers/pci/controller/dwc/pcie-armada8k.c +8
-0@@ -376,6 +388,7 @@ static int armada8k_pcie_probe(struct platform_device *pdev)struct armada8k_pcie *pcie;struct device *dev = &pdev->dev;struct resource *base; +int reset_gpio;int ret; pcie =devm_kzalloc (dev,sizeof (*pcie),GFP_KERNEL );@@ -420,6 +433,13 @@ static int armada8k_pcie_probe(struct platform_device *pdev) goto fail_clkreg; } +/* Config reset gpio for pcie if the reset connected to gpio */ + reset_gpio =of_get_named_gpio_flags (pdev->dev.of_node, +"reset-gpios" ,0 , + &pcie->flags); +if (gpio_is_valid (reset_gpio)) + pcie->reset_gpio =gpio_to_desc (reset_gpio); + pcie->sysctrl_base =syscon_regmap_lookup_by_phandle (pdev->dev.of_node,"marvell,system-controller" );if (IS_ERR (pcie->sysctrl_base)) {Signature · 1 line
2.25.1
A message that is not in the archive (sent off-list or not yet received): BY3PR18MB46731FD9009EC4A2443C41F8A7F52@BY3PR18MB4673.namprd18.prod.outlook.com
Quoted 78 lines
In subject, follow capitalization convention. Use "git log --oneline".
Quoted 6 lines · Jenishkumar Maheshbhai Patel
Added pcie reset via gpio support as described in the designware-pcie.txt DT binding document.
In cases link down cause still exist in device.
The device need to be reset to reestablish the link. If reset-gpio pin provided in the device tree, then the linkdown handle resets the device before reestablishing link.s/pcie/PCIe/
s/gpio/GPIO/Add blank lines between paragraphs. Rewrap to fill 75 columns.
Quoted 13 lines
Signed-off-by: Jenishkumar Maheshbhai Patel
<mailto:[email protected]>--- drivers/pci/controller/dwc/pcie-armada8k.c | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)drivers/pci/controller/dwc/pcie-armada8k.c +0
-0drivers/pci/controller/dwc/pcie-armada8k.c line 26
Quoted 4 lines
drivers/pci/controller/dwc/pcie-armada8k.c +1
-0@@ -23,6 +23,7 @@#include <linux/of_pci.h> #include <linux/mfd/syscon.h> #include <linux/regmap.h> +#include <linux/of_gpio.h> Preserve (mostly) alpha sorted list of includes.
drivers/pci/controller/dwc/pcie-armada8k.c static void armada8k_pcie_recover_link(struct
Quoted 12 lines
drivers/pci/controller/dwc/pcie-armada8k.c +2
-0#include "pcie-designware.h" @@ -37,6 +38,8 @@ struct armada8k_pcie {struct regmap *sysctrl_base;u32 mac_rest_bitmask;struct work_struct recover_link_work; +enum of_gpio_flags flags; +struct gpio_desc *reset_gpio; };#define PCIE_VENDOR_REGS_OFFSET 0x8000@@ -238,9 +241,18 @@ static void armada8k_pcie_recover_link(struct
work_struct*ws)drivers/pci/controller/dwc/pcie-armada8k.c static void armada8k_pcie_recover_link(struct work_struct *ws) · line 248
Quoted 8 lines
drivers/pci/controller/dwc/pcie-armada8k.c +5
-0}pci_lock_rescan_remove ();pci_stop_and_remove_bus_device (root_port); +/* Reset device if reset gpio is set */ +if (pcie->reset_gpio) { +/* assert and then deassert the reset signal */ +gpiod_set_value_cansleep (pcie->reset_gpio,0 ); +msleep (100 );Needs some sort of #define for this 100 ms.
drivers/pci/controller/dwc/pcie-armada8k.c static void armada8k_pcie_recover_link(struct · line 250
Quoted 2 lines
drivers/pci/controller/dwc/pcie-armada8k.c +2
-0+ gpiod_set_value_cansleep(pcie->reset_gpio, + (pcie->flags &
OF_GPIO_ACTIVE_LOW) ? 0 : 1);drivers/pci/controller/dwc/pcie-armada8k.c static void armada8k_pcie_recover_link(struct work_struct *ws)
Quoted 6 lines
drivers/pci/controller/dwc/pcie-armada8k.c +3
-2+ }/* -* Sleep needed to make sure all pcie transactions and access -* are flushed before resetting the mac +* Sleep used for two reasons. +* First make sure all pcie transactions and access are flushed before resetting the mac
drivers/pci/controller/dwc/pcie-armada8k.c static void armada8k_pcie_recover_link(struct work_struct *ws) · line 257
Quoted 4 lines
drivers/pci/controller/dwc/pcie-armada8k.c +2
-0+* and second to make sure pci device is ready in case we reset the +device */ msleep (100 );s/pcie/PCIe/ (throughout)
s/mac/MAC/
Quoted 3 lines
Explain the 100ms. Hopefully this is something defined by PCIe base or CEM spec. Use or add #define as needed.
I will double check if this delay is necessary or not.
Quoted 28 lines
drivers/pci/controller/dwc/pcie-armada8k.c static int armada8k_pcie_probe(struct
Quoted 1 line
drivers/pci/controller/dwc/pcie-armada8k.c +0
-0@@ -376,6 +388,7 @@ static int armada8k_pcie_probe(struct
platform_device*pdev)Quoted 19 lines
drivers/pci/controller/dwc/pcie-armada8k.c +9
-0struct armada8k_pcie *pcie;struct device *dev = &pdev->dev;struct resource *base; +int reset_gpio;int ret; pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); @@ -420,6 +433,13 @@ static int armada8k_pcie_probe(struct platform_device *pdev) goto fail_clkreg; } +/* Config reset gpio for pcie if the reset connected to gpio */ + reset_gpio =of_get_named_gpio_flags (pdev->dev.of_node, +"reset-gpios" ,0 , + &pcie->flags); +if (gpio_is_valid (reset_gpio)) + pcie->reset_gpio =gpio_to_desc (reset_gpio); + pcie->sysctrl_base = syscon_regmap_lookup_by_phandle(pdev-Quoted 2 lines
dev.of_node,
"marvell,system-controller");
Quoted 4 lines
if (
IS_ERR(pcie->sysctrl_base)) {
--
2.25.1