Skip to contentSkip to conversation

pci: pci_mvebu: Add support for reset-gpios

PATCH Superseded Pali Rohár 3 participants 15 messages Jul 28, 2022 – Aug 9, 2022 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci: pci_mvebu: Add support for reset-gpios

Release PERST# signal via GPIO when "reset-gpios" is defined in device tree.

---
 drivers/pci/pci_mvebu.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/pci/pci_mvebu.c +14 -0
index d80f87e0cfc6..269c027db204 100644
@@ -22,6 +22,7 @@
 #include <asm/io.h>
 #include <asm/arch/cpu.h>
 #include <asm/arch/soc.h>
+#include <asm-generic/gpio.h>
 #include <linux/bitops.h>
 #include <linux/delay.h>
 #include <linux/errno.h>
@@ -60,6 +61,7 @@ struct mvebu_pcie {
 	struct resource mem;
 	void __iomem *iobase;
 	struct resource io;
+	struct gpio_desc reset_gpio;
 	u32 intregs;
 	u32 port;
 	u32 lane;
@@ -416,6 +418,14 @@ static int mvebu_pcie_probe(struct udevice *dev)
 	struct udevice *ctlr = pci_get_controller(dev);
 	struct pci_controller *hose = dev_get_uclass_priv(ctlr);
 	u32 reg;
+	int ret;
+
+	/* Request for optional PERST# GPIO */
+	ret = gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT);
+	if (ret && ret != -ENOENT) {
+		printf("%s: unable to request reset-gpios: %d\n", pcie->name, ret);
+		return ret;
+	}
 
 	/*
 	 * Change Class Code of PCI Bridge device to PCI Bridge (0x600400)
@@ -537,6 +547,10 @@ static int mvebu_pcie_probe(struct udevice *dev)
 	pcie->cfgcache[(PCI_PREF_MEMORY_BASE - 0x10) / 4] =
 		PCI_PREF_RANGE_TYPE_64 | (PCI_PREF_RANGE_TYPE_64 << 16);
 
+	/* Release PERST# via GPIO when it was defined */
+	if (dm_gpio_is_valid(&pcie->reset_gpio))
+		dm_gpio_set_value(&pcie->reset_gpio, 0);
+
 	mvebu_pcie_wait_for_link(pcie);
 
 	return 0;
Signature · 1 line
2.20.1
#1 lore raw
Quoted 43 lines · Pali Rohár

Release PERST# signal via GPIO when "reset-gpios" is defined in device tree.

---
  drivers/pci/pci_mvebu.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
drivers/pci/pci_mvebu.c +10 -0
index d80f87e0cfc6..269c027db204 100644
@@ -22,6 +22,7 @@
  #include <asm/io.h>
  #include <asm/arch/cpu.h>
  #include <asm/arch/soc.h>
+#include <asm-generic/gpio.h>
  #include <linux/bitops.h>
  #include <linux/delay.h>
  #include <linux/errno.h>
@@ -60,6 +61,7 @@ struct mvebu_pcie {
  	struct resource mem;
  	void __iomem *iobase;
  	struct resource io;
+	struct gpio_desc reset_gpio;
  	u32 intregs;
  	u32 port;
  	u32 lane;
@@ -416,6 +418,14 @@ static int mvebu_pcie_probe(struct udevice *dev)
  	struct udevice *ctlr = pci_get_controller(dev);
  	struct pci_controller *hose = dev_get_uclass_priv(ctlr);
  	u32 reg;
+	int ret;
+
+	/* Request for optional PERST# GPIO */
+	ret = gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT);
+	if (ret && ret != -ENOENT) {
+		printf("%s: unable to request reset-gpios: %d\n", pcie->name, ret);
+		return ret;
+	}
 
  	/*
  	 * Change Class Code of PCI Bridge device to PCI Bridge (0x600400)

drivers/pci/pci_mvebu.c static int mvebu_pcie_probe(struct udevice *dev) · line 553

Quoted 7 lines
drivers/pci/pci_mvebu.c +4 -0
@@ -537,6 +547,10 @@ static int mvebu_pcie_probe(struct udevice *dev)
  	pcie->cfgcache[(PCI_PREF_MEMORY_BASE - 0x10) / 4] =
  		PCI_PREF_RANGE_TYPE_64 | (PCI_PREF_RANGE_TYPE_64 << 16);
 
+	/* Release PERST# via GPIO when it was defined */
+	if (dm_gpio_is_valid(&pcie->reset_gpio))
+		dm_gpio_set_value(&pcie->reset_gpio, 0);
+

So you're only releasing the GPIO (setting to inactive) here. Wouldn't it make sense to first use the GPIO (if available via DT) to actually reset the PCI device? How is this done in the Kernel driver(s)?

Thanks,
Stefan

#2 lore raw
Quoted 54 lines · On Thursday 28 July 2022 17:05:38 Stefan Roese wrote:
Quoted 42 lines · Pali Rohár

Release PERST# signal via GPIO when "reset-gpios" is defined in device tree.

---
  drivers/pci/pci_mvebu.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
drivers/pci/pci_mvebu.c +10 -0
index d80f87e0cfc6..269c027db204 100644
@@ -22,6 +22,7 @@
  #include <asm/io.h>
  #include <asm/arch/cpu.h>
  #include <asm/arch/soc.h>
+#include <asm-generic/gpio.h>
  #include <linux/bitops.h>
  #include <linux/delay.h>
  #include <linux/errno.h>
@@ -60,6 +61,7 @@ struct mvebu_pcie {
  	struct resource mem;
  	void __iomem *iobase;
  	struct resource io;
+	struct gpio_desc reset_gpio;
  	u32 intregs;
  	u32 port;
  	u32 lane;
@@ -416,6 +418,14 @@ static int mvebu_pcie_probe(struct udevice *dev)
  	struct udevice *ctlr = pci_get_controller(dev);
  	struct pci_controller *hose = dev_get_uclass_priv(ctlr);
  	u32 reg;
+	int ret;
+
+	/* Request for optional PERST# GPIO */
+	ret = gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT);
+	if (ret && ret != -ENOENT) {
+		printf("%s: unable to request reset-gpios: %d\n", pcie->name, ret);
+		return ret;
+	}
  	/*
  	 * Change Class Code of PCI Bridge device to PCI Bridge (0x600400)

drivers/pci/pci_mvebu.c static int mvebu_pcie_probe(struct udevice *dev) · line 552

Quoted 6 lines
drivers/pci/pci_mvebu.c +4 -0
@@ -537,6 +547,10 @@ static int mvebu_pcie_probe(struct udevice *dev)
  	pcie->cfgcache[(PCI_PREF_MEMORY_BASE - 0x10) / 4] =
  		PCI_PREF_RANGE_TYPE_64 | (PCI_PREF_RANGE_TYPE_64 << 16);
+	/* Release PERST# via GPIO when it was defined */
+	if (dm_gpio_is_valid(&pcie->reset_gpio))
+		dm_gpio_set_value(&pcie->reset_gpio, 0);
+

So you're only releasing the GPIO (setting to inactive) here. Wouldn't it make sense to first use the GPIO (if available via DT) to actually reset the PCI device? How is this done in the Kernel driver(s)?

Quoted 2 lines

Thanks,
Stefan

This is something which I do not know what is the best. Kernel driver pci-mvebu.c has same logic - just release from reset at startup.

#3 lore raw
Quoted 55 lines · Pali Rohár
Quoted 54 lines · On Thursday 28 July 2022 17:05:38 Stefan Roese wrote:
Quoted 42 lines · Pali Rohár

Release PERST# signal via GPIO when "reset-gpios" is defined in device tree.

---
   drivers/pci/pci_mvebu.c | 14 ++++++++++++++
   1 file changed, 14 insertions(+)
drivers/pci/pci_mvebu.c +10 -0
index d80f87e0cfc6..269c027db204 100644
@@ -22,6 +22,7 @@
   #include <asm/io.h>
   #include <asm/arch/cpu.h>
   #include <asm/arch/soc.h>
+#include <asm-generic/gpio.h>
   #include <linux/bitops.h>
   #include <linux/delay.h>
   #include <linux/errno.h>
@@ -60,6 +61,7 @@ struct mvebu_pcie {
   	struct resource mem;
   	void __iomem *iobase;
   	struct resource io;
+	struct gpio_desc reset_gpio;
   	u32 intregs;
   	u32 port;
   	u32 lane;
@@ -416,6 +418,14 @@ static int mvebu_pcie_probe(struct udevice *dev)
   	struct udevice *ctlr = pci_get_controller(dev);
   	struct pci_controller *hose = dev_get_uclass_priv(ctlr);
   	u32 reg;
+	int ret;
+
+	/* Request for optional PERST# GPIO */
+	ret = gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT);
+	if (ret && ret != -ENOENT) {
+		printf("%s: unable to request reset-gpios: %d\n", pcie->name, ret);
+		return ret;
+	}
   	/*
   	 * Change Class Code of PCI Bridge device to PCI Bridge (0x600400)

drivers/pci/pci_mvebu.c static int mvebu_pcie_probe(struct udevice *dev) · line 552

Quoted 6 lines
drivers/pci/pci_mvebu.c +4 -0
@@ -537,6 +547,10 @@ static int mvebu_pcie_probe(struct udevice *dev)
   	pcie->cfgcache[(PCI_PREF_MEMORY_BASE - 0x10) / 4] =
   		PCI_PREF_RANGE_TYPE_64 | (PCI_PREF_RANGE_TYPE_64 << 16);
+	/* Release PERST# via GPIO when it was defined */
+	if (dm_gpio_is_valid(&pcie->reset_gpio))
+		dm_gpio_set_value(&pcie->reset_gpio, 0);
+

So you're only releasing the GPIO (setting to inactive) here. Wouldn't it make sense to first use the GPIO (if available via DT) to actually reset the PCI device? How is this done in the Kernel driver(s)?

Quoted 5 lines
Quoted 2 lines

Thanks,
Stefan

This is something which I do not know what is the best. Kernel driver pci-mvebu.c has same logic - just release from reset at startup.

I see. Could you please check some other PCI Kernel drivers, how they handle reset-gpios signalling?

Thanks,
Stefan

#4 lore raw
Quoted 59 lines · On Thursday 28 July 2022 17:13:12 Stefan Roese wrote:
Quoted 58 lines · Pali Rohár
Quoted 56 lines · On Thursday 28 July 2022 17:05:38 Stefan Roese wrote:
Quoted 42 lines · Pali Rohár

Release PERST# signal via GPIO when "reset-gpios" is defined in device tree.

---
   drivers/pci/pci_mvebu.c | 14 ++++++++++++++
   1 file changed, 14 insertions(+)
drivers/pci/pci_mvebu.c +10 -0
index d80f87e0cfc6..269c027db204 100644
@@ -22,6 +22,7 @@
   #include <asm/io.h>
   #include <asm/arch/cpu.h>
   #include <asm/arch/soc.h>
+#include <asm-generic/gpio.h>
   #include <linux/bitops.h>
   #include <linux/delay.h>
   #include <linux/errno.h>
@@ -60,6 +61,7 @@ struct mvebu_pcie {
   	struct resource mem;
   	void __iomem *iobase;
   	struct resource io;
+	struct gpio_desc reset_gpio;
   	u32 intregs;
   	u32 port;
   	u32 lane;
@@ -416,6 +418,14 @@ static int mvebu_pcie_probe(struct udevice *dev)
   	struct udevice *ctlr = pci_get_controller(dev);
   	struct pci_controller *hose = dev_get_uclass_priv(ctlr);
   	u32 reg;
+	int ret;
+
+	/* Request for optional PERST# GPIO */
+	ret = gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT);
+	if (ret && ret != -ENOENT) {
+		printf("%s: unable to request reset-gpios: %d\n", pcie->name, ret);
+		return ret;
+	}
   	/*
   	 * Change Class Code of PCI Bridge device to PCI Bridge (0x600400)

drivers/pci/pci_mvebu.c static int mvebu_pcie_probe(struct udevice *dev) · line 552

Quoted 6 lines
drivers/pci/pci_mvebu.c +4 -0
@@ -537,6 +547,10 @@ static int mvebu_pcie_probe(struct udevice *dev)
   	pcie->cfgcache[(PCI_PREF_MEMORY_BASE - 0x10) / 4] =
   		PCI_PREF_RANGE_TYPE_64 | (PCI_PREF_RANGE_TYPE_64 << 16);
+	/* Release PERST# via GPIO when it was defined */
+	if (dm_gpio_is_valid(&pcie->reset_gpio))
+		dm_gpio_set_value(&pcie->reset_gpio, 0);
+

So you're only releasing the GPIO (setting to inactive) here. Wouldn't it make sense to first use the GPIO (if available via DT) to actually reset the PCI device? How is this done in the Kernel driver(s)?

Thanks,
Stefan

Quoted 8 lines
Quoted 2 lines

This is something which I do not know what is the best. Kernel driver pci-mvebu.c has same logic - just release from reset at startup.

I see. Could you please check some other PCI Kernel drivers, how they handle reset-gpios signalling?

Thanks,
Stefan

Every kernel driver is doing it differently. Touching PERST# in bootloader is for two different purposes (which is board specific):

1) Board is designed in a way that PCIe stays in reset after CPU starts and it is up to the SW to release PCIe reset, including reset of endpoint cards.

I think that this is recommended design due to how are PCIe requirements for timings and dependences on other stuff (like PCIe clock stabilization, power on, etc...).

This is also what I prefer for designing new boards.

2) Board is designed in a way that endpoint PCIe card is after CPU reset immediately released from the reset or maybe that PCIe card is not reset at all after CPU reset.

In this case lot of "broken" cards do not work until they are manually reset from software, which requires flipping PERST# pin manually (via GPIO).

Bootloader / U-Boot starts as the first SW and depends on specific state of CPU reset. So it can expects that nothing release PERST# from 1) before it.

In operating system it is harder as kernel cannot do this assumption.

And to make it even harder, there is important question: How long should be PERST# signal active to ensure that endpoint card is correctly reset?

Without knowing answer to this question, we do not know and cannot implement 2) properly.

I was not able to find answer for this question in PCIe specs, so I have asked it on mailing linux-pci mailing list:
https://lore.kernel.org/linux-pci/20210310110535.zh4pnn4vpmvzwl5q@pali/
(and it is still without clear answer)

And if we go deeper to the PCIe initialization (as PERST# signal is part of it) I described some proposal for Linux kernel how it should be implemented correctly:
https://lore.kernel.org/linux-pci/20211022183808.jdeo7vntnagqkg7g@pali/

So all this stuff needs to be rewritten, ideally into some common framework. Until that happens, every driver would continue doing it by its own -- and differently.

Yes, it is a mess, but I do not know what we can do with it.

Btw, in past I did also investigation of those resets and delays, and really every kernel driver is doing it differently:
https://lore.kernel.org/linux-pci/20200424092546.25p3hdtkehohe3xw@pali/

#5 lore raw
Quoted 28 lines · Pali Rohár
Quoted 8 lines · On Thursday 28 July 2022 17:13:12 Stefan Roese wrote:
Quoted 7 lines · Pali Rohár
Quoted 5 lines · On Thursday 28 July 2022 17:05:38 Stefan Roese wrote:
Quoted 1 line · Pali Rohár

Release PERST# signal via GPIO when "reset-gpios" is defined in device tree.

So you're only releasing the GPIO (setting to inactive) here. Wouldn't it make sense to first use the GPIO (if available via DT) to actually reset the PCI device? How is this done in the Kernel driver(s)?

Quoted 5 lines
Quoted 2 lines

This is something which I do not know what is the best. Kernel driver pci-mvebu.c has same logic - just release from reset at startup.

I see. Could you please check some other PCI Kernel drivers, how they handle reset-gpios signalling?

Every kernel driver is doing it differently. Touching PERST# in bootloader is for two different purposes (which is board specific):

1) Board is designed in a way that PCIe stays in reset after CPU starts and it is up to the SW to release PCIe reset, including reset of endpoint cards.

I think that this is recommended design due to how are PCIe requirements for timings and dependences on other stuff (like PCIe clock stabilization, power on, etc...).

This is also what I prefer for designing new boards.

Quoted 7 lines

2) Board is designed in a way that endpoint PCIe card is after CPU reset immediately released from the reset or maybe that PCIe card is not reset at all after CPU reset.

In this case lot of "broken" cards do not work until they are manually reset from software, which requires flipping PERST# pin manually (via GPIO).

Those card that you mention as broken are often just fine, from the standard point, they are just a pain ...

Quoted 4 lines

Bootloader / U-Boot starts as the first SW and depends on specific state of CPU reset. So it can expects that nothing release PERST# from 1) before it.

I think in general this last one is not a correct assumption, reset could just not be asserted at that point because of the hardware design.

I recently had issue because of that (Linux Kernel, not U-Boot), and this is the fix that was merged:

a6809941c1f1 ("PCI: imx6: Fix PERST# start-up sequence")

(and I also had myself similar issue while working on Intel platform firmware, e.g. UEFI).

Said that I agree that the topic is way more complicated than it should be :-/

Quoted 29 lines

In operating system it is harder as kernel cannot do this assumption.

And to make it even harder, there is important question: How long should be PERST# signal active to ensure that endpoint card is correctly reset?

Without knowing answer to this question, we do not know and cannot implement 2) properly.

I was not able to find answer for this question in PCIe specs, so I have asked it on mailing linux-pci mailing list:
https://lore.kernel.org/linux-pci/20210310110535.zh4pnn4vpmvzwl5q@pali/
(and it is still without clear answer)

And if we go deeper to the PCIe initialization (as PERST# signal is part of it) I described some proposal for Linux kernel how it should be implemented correctly:
https://lore.kernel.org/linux-pci/20211022183808.jdeo7vntnagqkg7g@pali/

So all this stuff needs to be rewritten, ideally into some common framework. Until that happens, every driver would continue doing it by its own -- and differently.

Yes, it is a mess, but I do not know what we can do with it.

Btw, in past I did also investigation of those resets and delays, and really every kernel driver is doing it differently:
https://lore.kernel.org/linux-pci/20200424092546.25p3hdtkehohe3xw@pali/

#6 lore raw
Quoted 41 lines · On Friday 29 July 2022 10:09:52 Francesco Dolcini wrote:
Quoted 28 lines · Pali Rohár
Quoted 8 lines · On Thursday 28 July 2022 17:13:12 Stefan Roese wrote:
Quoted 7 lines · Pali Rohár
Quoted 5 lines · On Thursday 28 July 2022 17:05:38 Stefan Roese wrote:
Quoted 1 line · Pali Rohár

Release PERST# signal via GPIO when "reset-gpios" is defined in device tree.

So you're only releasing the GPIO (setting to inactive) here. Wouldn't it make sense to first use the GPIO (if available via DT) to actually reset the PCI device? How is this done in the Kernel driver(s)?

Quoted 5 lines
Quoted 2 lines

This is something which I do not know what is the best. Kernel driver pci-mvebu.c has same logic - just release from reset at startup.

I see. Could you please check some other PCI Kernel drivers, how they handle reset-gpios signalling?

Every kernel driver is doing it differently. Touching PERST# in bootloader is for two different purposes (which is board specific):

1) Board is designed in a way that PCIe stays in reset after CPU starts and it is up to the SW to release PCIe reset, including reset of endpoint cards.

I think that this is recommended design due to how are PCIe requirements for timings and dependences on other stuff (like PCIe clock stabilization, power on, etc...).

This is also what I prefer for designing new boards.

Quoted 7 lines

2) Board is designed in a way that endpoint PCIe card is after CPU reset immediately released from the reset or maybe that PCIe card is not reset at all after CPU reset.

In this case lot of "broken" cards do not work until they are manually reset from software, which requires flipping PERST# pin manually (via GPIO).

Those card that you mention as broken are often just fine, from the standard point, they are just a pain ...

Quoted 1 line
Quoted 6 lines
Quoted 3 lines

Bootloader / U-Boot starts as the first SW and depends on specific state of CPU reset. So it can expects that nothing release PERST# from 1) before it.

I think in general this last one is not a correct assumption, reset could just not be asserted at that point because of the hardware design.

Yes, that is why I marked the last part that applies only for hardware design from option 1) mentioned above.

Quoted 10 lines

I recently had issue because of that (Linux Kernel, not U-Boot), and this is the fix that was merged:

a6809941c1f1 ("PCI: imx6: Fix PERST# start-up sequence")

(and I also had myself similar issue while working on Intel platform firmware, e.g. UEFI).

Said that I agree that the topic is way more complicated than it should be :-/

Yes, it is :-( I proposed some options for kernel but it is lot of work for which probably nobody has time...

Quoted 30 lines
Quoted 29 lines

In operating system it is harder as kernel cannot do this assumption.

And to make it even harder, there is important question: How long should be PERST# signal active to ensure that endpoint card is correctly reset?

Without knowing answer to this question, we do not know and cannot implement 2) properly.

I was not able to find answer for this question in PCIe specs, so I have asked it on mailing linux-pci mailing list:
https://lore.kernel.org/linux-pci/20210310110535.zh4pnn4vpmvzwl5q@pali/
(and it is still without clear answer)

And if we go deeper to the PCIe initialization (as PERST# signal is part of it) I described some proposal for Linux kernel how it should be implemented correctly:
https://lore.kernel.org/linux-pci/20211022183808.jdeo7vntnagqkg7g@pali/

So all this stuff needs to be rewritten, ideally into some common framework. Until that happens, every driver would continue doing it by its own -- and differently.

Yes, it is a mess, but I do not know what we can do with it.

Btw, in past I did also investigation of those resets and delays, and really every kernel driver is doing it differently:
https://lore.kernel.org/linux-pci/20200424092546.25p3hdtkehohe3xw@pali/

Reviewed-by
#7 lore raw
In reply to Pali Rohár
Quoted 116 lines · Pali Rohár
Quoted 59 lines · On Thursday 28 July 2022 17:13:12 Stefan Roese wrote:
Quoted 58 lines · Pali Rohár
Quoted 56 lines · On Thursday 28 July 2022 17:05:38 Stefan Roese wrote:
Quoted 42 lines · Pali Rohár

Release PERST# signal via GPIO when "reset-gpios" is defined in device tree.

---
    drivers/pci/pci_mvebu.c | 14 ++++++++++++++
    1 file changed, 14 insertions(+)
drivers/pci/pci_mvebu.c +10 -0
index d80f87e0cfc6..269c027db204 100644
@@ -22,6 +22,7 @@
    #include <asm/io.h>
    #include <asm/arch/cpu.h>
    #include <asm/arch/soc.h>
+#include <asm-generic/gpio.h>
    #include <linux/bitops.h>
    #include <linux/delay.h>
    #include <linux/errno.h>
@@ -60,6 +61,7 @@ struct mvebu_pcie {
    	struct resource mem;
    	void __iomem *iobase;
    	struct resource io;
+	struct gpio_desc reset_gpio;
    	u32 intregs;
    	u32 port;
    	u32 lane;
@@ -416,6 +418,14 @@ static int mvebu_pcie_probe(struct udevice *dev)
    	struct udevice *ctlr = pci_get_controller(dev);
    	struct pci_controller *hose = dev_get_uclass_priv(ctlr);
    	u32 reg;
+	int ret;
+
+	/* Request for optional PERST# GPIO */
+	ret = gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT);
+	if (ret && ret != -ENOENT) {
+		printf("%s: unable to request reset-gpios: %d\n", pcie->name, ret);
+		return ret;
+	}
    	/*
    	 * Change Class Code of PCI Bridge device to PCI Bridge (0x600400)

drivers/pci/pci_mvebu.c static int mvebu_pcie_probe(struct udevice *dev) · line 552

Quoted 6 lines
drivers/pci/pci_mvebu.c +4 -0
@@ -537,6 +547,10 @@ static int mvebu_pcie_probe(struct udevice *dev)
    	pcie->cfgcache[(PCI_PREF_MEMORY_BASE - 0x10) / 4] =
    		PCI_PREF_RANGE_TYPE_64 | (PCI_PREF_RANGE_TYPE_64 << 16);
+	/* Release PERST# via GPIO when it was defined */
+	if (dm_gpio_is_valid(&pcie->reset_gpio))
+		dm_gpio_set_value(&pcie->reset_gpio, 0);
+

So you're only releasing the GPIO (setting to inactive) here. Wouldn't it make sense to first use the GPIO (if available via DT) to actually reset the PCI device? How is this done in the Kernel driver(s)?

Thanks,
Stefan

Quoted 8 lines
Quoted 2 lines

This is something which I do not know what is the best. Kernel driver pci-mvebu.c has same logic - just release from reset at startup.

I see. Could you please check some other PCI Kernel drivers, how they handle reset-gpios signalling?

Thanks,
Stefan

Every kernel driver is doing it differently. Touching PERST# in bootloader is for two different purposes (which is board specific):

1) Board is designed in a way that PCIe stays in reset after CPU starts and it is up to the SW to release PCIe reset, including reset of endpoint cards.

I think that this is recommended design due to how are PCIe requirements for timings and dependences on other stuff (like PCIe clock stabilization, power on, etc...).

This is also what I prefer for designing new boards.

2) Board is designed in a way that endpoint PCIe card is after CPU reset immediately released from the reset or maybe that PCIe card is not reset at all after CPU reset.

In this case lot of "broken" cards do not work until they are manually reset from software, which requires flipping PERST# pin manually (via GPIO).

Bootloader / U-Boot starts as the first SW and depends on specific state of CPU reset. So it can expects that nothing release PERST# from 1) before it.

In operating system it is harder as kernel cannot do this assumption.

And to make it even harder, there is important question: How long should be PERST# signal active to ensure that endpoint card is correctly reset?

Without knowing answer to this question, we do not know and cannot implement 2) properly.

I was not able to find answer for this question in PCIe specs, so I have asked it on mailing linux-pci mailing list:
https://lore.kernel.org/linux-pci/20210310110535.zh4pnn4vpmvzwl5q@pali/
(and it is still without clear answer)

And if we go deeper to the PCIe initialization (as PERST# signal is part of it) I described some proposal for Linux kernel how it should be implemented correctly:
https://lore.kernel.org/linux-pci/20211022183808.jdeo7vntnagqkg7g@pali/

So all this stuff needs to be rewritten, ideally into some common framework. Until that happens, every driver would continue doing it by its own -- and differently.

Quoted 5 lines

Yes, it is a mess, but I do not know what we can do with it.

Btw, in past I did also investigation of those resets and delays, and really every kernel driver is doing it differently:
https://lore.kernel.org/linux-pci/20200424092546.25p3hdtkehohe3xw@pali/

Pali, thanks for the detailed explanation.

With this in mind, I think it's best right now to accept your patch as-is, as this does minimal change (risk of breakage) in this GPIO area.

Thank,
Stefan

#8 lore raw
In reply to Pali Rohár
Quoted 43 lines · Pali Rohár

Release PERST# signal via GPIO when "reset-gpios" is defined in device tree.

---
  drivers/pci/pci_mvebu.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
drivers/pci/pci_mvebu.c +10 -0
index d80f87e0cfc6..269c027db204 100644
@@ -22,6 +22,7 @@
  #include <asm/io.h>
  #include <asm/arch/cpu.h>
  #include <asm/arch/soc.h>
+#include <asm-generic/gpio.h>
  #include <linux/bitops.h>
  #include <linux/delay.h>
  #include <linux/errno.h>
@@ -60,6 +61,7 @@ struct mvebu_pcie {
  	struct resource mem;
  	void __iomem *iobase;
  	struct resource io;
+	struct gpio_desc reset_gpio;
  	u32 intregs;
  	u32 port;
  	u32 lane;
@@ -416,6 +418,14 @@ static int mvebu_pcie_probe(struct udevice *dev)
  	struct udevice *ctlr = pci_get_controller(dev);
  	struct pci_controller *hose = dev_get_uclass_priv(ctlr);
  	u32 reg;
+	int ret;
+
+	/* Request for optional PERST# GPIO */
+	ret = gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT);
+	if (ret && ret != -ENOENT) {
+		printf("%s: unable to request reset-gpios: %d\n", pcie->name, ret);
+		return ret;
+	}
 
  	/*
  	 * Change Class Code of PCI Bridge device to PCI Bridge (0x600400)

drivers/pci/pci_mvebu.c static int mvebu_pcie_probe(struct udevice *dev) · line 556

Quoted 10 lines
drivers/pci/pci_mvebu.c +4 -0
@@ -537,6 +547,10 @@ static int mvebu_pcie_probe(struct udevice *dev)
  	pcie->cfgcache[(PCI_PREF_MEMORY_BASE - 0x10) / 4] =
  		PCI_PREF_RANGE_TYPE_64 | (PCI_PREF_RANGE_TYPE_64 << 16);
 
+	/* Release PERST# via GPIO when it was defined */
+	if (dm_gpio_is_valid(&pcie->reset_gpio))
+		dm_gpio_set_value(&pcie->reset_gpio, 0);
+
  	mvebu_pcie_wait_for_link(pcie);
 
  	return 0;

While running some build tests, this error shows on some Kirkwood boards:

$ make pogo_v4_defconfig
$ make -s -j20
===================== WARNING ======================
This board does not use CONFIG_TIMER (Driver Model
for Timer drivers). Please update the board to use
CONFIG_TIMER before the v2023.01 release. Failure to
update by the deadline may result in board removal.
See doc/develop/driver-model/migration.rst for more info.
====================================================
===================== WARNING ======================
This board does not use CONFIG_DM_SERIAL (Driver Model
for Serial drivers). Please update the board to use
CONFIG_DM_SERIAL before the v2023.04 release. Failure to
update by the deadline may result in board removal.
See doc/develop/driver-model/migration.rst for more info.
====================================================
/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-ld.bfd: drivers/pci/pci_mvebu.o: in function `mvebu_pcie_probe':
/home/stefan/git/u-boot/u-boot-marvell/drivers/pci/pci_mvebu.c:424: undefined reference to `gpio_request_by_name'
/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-ld.bfd: /home/stefan/git/u-boot/u-boot-marvell/drivers/pci/pci_mvebu.c:552: undefined reference to `dm_gpio_set_value'
make: *** [Makefile:1818: u-boot] Error 1

Could you please take a look and make sure, that world build succeeds?

Thanks,
Stefan

#9 lore raw
Quoted 80 lines · On Friday 05 August 2022 13:01:27 Stefan Roese wrote:
Quoted 42 lines · Pali Rohár

Release PERST# signal via GPIO when "reset-gpios" is defined in device tree.

---
  drivers/pci/pci_mvebu.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
drivers/pci/pci_mvebu.c +10 -0
index d80f87e0cfc6..269c027db204 100644
@@ -22,6 +22,7 @@
  #include <asm/io.h>
  #include <asm/arch/cpu.h>
  #include <asm/arch/soc.h>
+#include <asm-generic/gpio.h>
  #include <linux/bitops.h>
  #include <linux/delay.h>
  #include <linux/errno.h>
@@ -60,6 +61,7 @@ struct mvebu_pcie {
  	struct resource mem;
  	void __iomem *iobase;
  	struct resource io;
+	struct gpio_desc reset_gpio;
  	u32 intregs;
  	u32 port;
  	u32 lane;
@@ -416,6 +418,14 @@ static int mvebu_pcie_probe(struct udevice *dev)
  	struct udevice *ctlr = pci_get_controller(dev);
  	struct pci_controller *hose = dev_get_uclass_priv(ctlr);
  	u32 reg;
+	int ret;
+
+	/* Request for optional PERST# GPIO */
+	ret = gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT);
+	if (ret && ret != -ENOENT) {
+		printf("%s: unable to request reset-gpios: %d\n", pcie->name, ret);
+		return ret;
+	}
  	/*
  	 * Change Class Code of PCI Bridge device to PCI Bridge (0x600400)

drivers/pci/pci_mvebu.c static int mvebu_pcie_probe(struct udevice *dev) · line 554

Quoted 8 lines
drivers/pci/pci_mvebu.c +4 -0
@@ -537,6 +547,10 @@ static int mvebu_pcie_probe(struct udevice *dev)
  	pcie->cfgcache[(PCI_PREF_MEMORY_BASE - 0x10) / 4] =
  		PCI_PREF_RANGE_TYPE_64 | (PCI_PREF_RANGE_TYPE_64 << 16);
+	/* Release PERST# via GPIO when it was defined */
+	if (dm_gpio_is_valid(&pcie->reset_gpio))
+		dm_gpio_set_value(&pcie->reset_gpio, 0);
+
  	mvebu_pcie_wait_for_link(pcie);
  	return 0;

While running some build tests, this error shows on some Kirkwood boards:

$ make pogo_v4_defconfig
$ make -s -j20
===================== WARNING ======================
This board does not use CONFIG_TIMER (Driver Model
for Timer drivers). Please update the board to use
CONFIG_TIMER before the v2023.01 release. Failure to
update by the deadline may result in board removal.
See doc/develop/driver-model/migration.rst for more info.
====================================================
===================== WARNING ======================
This board does not use CONFIG_DM_SERIAL (Driver Model
for Serial drivers). Please update the board to use
CONFIG_DM_SERIAL before the v2023.04 release. Failure to
update by the deadline may result in board removal.
See doc/develop/driver-model/migration.rst for more info.
====================================================
/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-ld.bfd:
drivers/pci/pci_mvebu.o: in function `mvebu_pcie_probe':
/home/stefan/git/u-boot/u-boot-marvell/drivers/pci/pci_mvebu.c:424:
undefined reference to `gpio_request_by_name'
/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-ld.bfd:
/home/stefan/git/u-boot/u-boot-marvell/drivers/pci/pci_mvebu.c:552:
undefined reference to `dm_gpio_set_value'
make: *** [Makefile:1818: u-boot] Error 1
Quoted 4 lines

Could you please take a look and make sure, that world build succeeds?

Thanks,
Stefan

There is probably missing DM_GPIO. Now I started CI test on github:
https://github.com/u-boot/u-boot/pull/204
After that I will send v2.

#10 lore raw
Quoted 81 lines · Pali Rohár
Quoted 80 lines · On Friday 05 August 2022 13:01:27 Stefan Roese wrote:
Quoted 42 lines · Pali Rohár

Release PERST# signal via GPIO when "reset-gpios" is defined in device tree.

---
   drivers/pci/pci_mvebu.c | 14 ++++++++++++++
   1 file changed, 14 insertions(+)
drivers/pci/pci_mvebu.c +10 -0
index d80f87e0cfc6..269c027db204 100644
@@ -22,6 +22,7 @@
   #include <asm/io.h>
   #include <asm/arch/cpu.h>
   #include <asm/arch/soc.h>
+#include <asm-generic/gpio.h>
   #include <linux/bitops.h>
   #include <linux/delay.h>
   #include <linux/errno.h>
@@ -60,6 +61,7 @@ struct mvebu_pcie {
   	struct resource mem;
   	void __iomem *iobase;
   	struct resource io;
+	struct gpio_desc reset_gpio;
   	u32 intregs;
   	u32 port;
   	u32 lane;
@@ -416,6 +418,14 @@ static int mvebu_pcie_probe(struct udevice *dev)
   	struct udevice *ctlr = pci_get_controller(dev);
   	struct pci_controller *hose = dev_get_uclass_priv(ctlr);
   	u32 reg;
+	int ret;
+
+	/* Request for optional PERST# GPIO */
+	ret = gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT);
+	if (ret && ret != -ENOENT) {
+		printf("%s: unable to request reset-gpios: %d\n", pcie->name, ret);
+		return ret;
+	}
   	/*
   	 * Change Class Code of PCI Bridge device to PCI Bridge (0x600400)

drivers/pci/pci_mvebu.c static int mvebu_pcie_probe(struct udevice *dev) · line 554

Quoted 8 lines
drivers/pci/pci_mvebu.c +4 -0
@@ -537,6 +547,10 @@ static int mvebu_pcie_probe(struct udevice *dev)
   	pcie->cfgcache[(PCI_PREF_MEMORY_BASE - 0x10) / 4] =
   		PCI_PREF_RANGE_TYPE_64 | (PCI_PREF_RANGE_TYPE_64 << 16);
+	/* Release PERST# via GPIO when it was defined */
+	if (dm_gpio_is_valid(&pcie->reset_gpio))
+		dm_gpio_set_value(&pcie->reset_gpio, 0);
+
   	mvebu_pcie_wait_for_link(pcie);
   	return 0;

While running some build tests, this error shows on some Kirkwood boards:

$ make pogo_v4_defconfig
$ make -s -j20
===================== WARNING ======================
This board does not use CONFIG_TIMER (Driver Model
for Timer drivers). Please update the board to use
CONFIG_TIMER before the v2023.01 release. Failure to
update by the deadline may result in board removal.
See doc/develop/driver-model/migration.rst for more info.
====================================================
===================== WARNING ======================
This board does not use CONFIG_DM_SERIAL (Driver Model
for Serial drivers). Please update the board to use
CONFIG_DM_SERIAL before the v2023.04 release. Failure to
update by the deadline may result in board removal.
See doc/develop/driver-model/migration.rst for more info.
====================================================
/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-ld.bfd:
drivers/pci/pci_mvebu.o: in function `mvebu_pcie_probe':
/home/stefan/git/u-boot/u-boot-marvell/drivers/pci/pci_mvebu.c:424:
undefined reference to `gpio_request_by_name'
/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-ld.bfd:
/home/stefan/git/u-boot/u-boot-marvell/drivers/pci/pci_mvebu.c:552:
undefined reference to `dm_gpio_set_value'
make: *** [Makefile:1818: u-boot] Error 1
Quoted 8 lines
Quoted 4 lines

Could you please take a look and make sure, that world build succeeds?

Thanks,
Stefan

There is probably missing DM_GPIO. Now I started CI test on github:
https://github.com/u-boot/u-boot/pull/204
After that I will send v2.

Perfect. Thanks.

Thanks,
Stefan

#11 lore raw
Quoted 87 lines · On Friday 05 August 2022 13:48:36 Stefan Roese wrote:
Quoted 86 lines · Pali Rohár
Quoted 84 lines · On Friday 05 August 2022 13:01:27 Stefan Roese wrote:
Quoted 42 lines · Pali Rohár

Release PERST# signal via GPIO when "reset-gpios" is defined in device tree.

---
   drivers/pci/pci_mvebu.c | 14 ++++++++++++++
   1 file changed, 14 insertions(+)
drivers/pci/pci_mvebu.c +10 -0
index d80f87e0cfc6..269c027db204 100644
@@ -22,6 +22,7 @@
   #include <asm/io.h>
   #include <asm/arch/cpu.h>
   #include <asm/arch/soc.h>
+#include <asm-generic/gpio.h>
   #include <linux/bitops.h>
   #include <linux/delay.h>
   #include <linux/errno.h>
@@ -60,6 +61,7 @@ struct mvebu_pcie {
   	struct resource mem;
   	void __iomem *iobase;
   	struct resource io;
+	struct gpio_desc reset_gpio;
   	u32 intregs;
   	u32 port;
   	u32 lane;
@@ -416,6 +418,14 @@ static int mvebu_pcie_probe(struct udevice *dev)
   	struct udevice *ctlr = pci_get_controller(dev);
   	struct pci_controller *hose = dev_get_uclass_priv(ctlr);
   	u32 reg;
+	int ret;
+
+	/* Request for optional PERST# GPIO */
+	ret = gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT);
+	if (ret && ret != -ENOENT) {
+		printf("%s: unable to request reset-gpios: %d\n", pcie->name, ret);
+		return ret;
+	}
   	/*
   	 * Change Class Code of PCI Bridge device to PCI Bridge (0x600400)

drivers/pci/pci_mvebu.c static int mvebu_pcie_probe(struct udevice *dev) · line 554

Quoted 8 lines
drivers/pci/pci_mvebu.c +4 -0
@@ -537,6 +547,10 @@ static int mvebu_pcie_probe(struct udevice *dev)
   	pcie->cfgcache[(PCI_PREF_MEMORY_BASE - 0x10) / 4] =
   		PCI_PREF_RANGE_TYPE_64 | (PCI_PREF_RANGE_TYPE_64 << 16);
+	/* Release PERST# via GPIO when it was defined */
+	if (dm_gpio_is_valid(&pcie->reset_gpio))
+		dm_gpio_set_value(&pcie->reset_gpio, 0);
+
   	mvebu_pcie_wait_for_link(pcie);
   	return 0;

While running some build tests, this error shows on some Kirkwood boards:

$ make pogo_v4_defconfig
$ make -s -j20
===================== WARNING ======================
This board does not use CONFIG_TIMER (Driver Model
for Timer drivers). Please update the board to use
CONFIG_TIMER before the v2023.01 release. Failure to
update by the deadline may result in board removal.
See doc/develop/driver-model/migration.rst for more info.
====================================================
===================== WARNING ======================
This board does not use CONFIG_DM_SERIAL (Driver Model
for Serial drivers). Please update the board to use
CONFIG_DM_SERIAL before the v2023.04 release. Failure to
update by the deadline may result in board removal.
See doc/develop/driver-model/migration.rst for more info.
====================================================
/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-ld.bfd:
drivers/pci/pci_mvebu.o: in function `mvebu_pcie_probe':
/home/stefan/git/u-boot/u-boot-marvell/drivers/pci/pci_mvebu.c:424:
undefined reference to `gpio_request_by_name'
/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-ld.bfd:
/home/stefan/git/u-boot/u-boot-marvell/drivers/pci/pci_mvebu.c:552:
undefined reference to `dm_gpio_set_value'
make: *** [Makefile:1818: u-boot] Error 1

Could you please take a look and make sure, that world build succeeds?

Thanks,
Stefan

Quoted 8 lines
Quoted 3 lines

There is probably missing DM_GPIO. Now I started CI test on github:
https://github.com/u-boot/u-boot/pull/204
After that I will send v2.

Perfect. Thanks.

Thanks,
Stefan

CI tests passed, now sending v2.

#12 lore raw

PATCH v2 1/1 pci: pci_mvebu: Add support for reset-gpios

In reply to Pali Rohár

Release PERST# signal via GPIO when "reset-gpios" is defined in device tree.

---
Changes in v2:
* select DM_GPIO
* use asm/gpio.h

---
 drivers/pci/Kconfig     |  1 +
 drivers/pci/pci_mvebu.c | 14 ++++++++++++++
 2 files changed, 15 insertions(+)
drivers/pci/Kconfig +1 -0
index 436acca898e4..22f4995453ed 100644
@@ -301,6 +301,7 @@ config PCI_MVEBU
 	depends on (ARCH_KIRKWOOD || ARCH_MVEBU)
 	select MISC
 	select DM_RESET
+	select DM_GPIO
 	help
 	  Say Y here if you want to enable PCIe controller support on
 	  Kirkwood and Armada 370/XP/375/38x SoCs.
drivers/pci/pci_mvebu.c +14 -0
index d80f87e0cfc6..5bd340a421b8 100644
@@ -22,6 +22,7 @@
 #include <asm/io.h>
 #include <asm/arch/cpu.h>
 #include <asm/arch/soc.h>
+#include <asm/gpio.h>
 #include <linux/bitops.h>
 #include <linux/delay.h>
 #include <linux/errno.h>
@@ -60,6 +61,7 @@ struct mvebu_pcie {
 	struct resource mem;
 	void __iomem *iobase;
 	struct resource io;
+	struct gpio_desc reset_gpio;
 	u32 intregs;
 	u32 port;
 	u32 lane;
@@ -416,6 +418,14 @@ static int mvebu_pcie_probe(struct udevice *dev)
 	struct udevice *ctlr = pci_get_controller(dev);
 	struct pci_controller *hose = dev_get_uclass_priv(ctlr);
 	u32 reg;
+	int ret;
+
+	/* Request for optional PERST# GPIO */
+	ret = gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT);
+	if (ret && ret != -ENOENT) {
+		printf("%s: unable to request reset-gpios: %d\n", pcie->name, ret);
+		return ret;
+	}
 
 	/*
 	 * Change Class Code of PCI Bridge device to PCI Bridge (0x600400)
@@ -537,6 +547,10 @@ static int mvebu_pcie_probe(struct udevice *dev)
 	pcie->cfgcache[(PCI_PREF_MEMORY_BASE - 0x10) / 4] =
 		PCI_PREF_RANGE_TYPE_64 | (PCI_PREF_RANGE_TYPE_64 << 16);
 
+	/* Release PERST# via GPIO when it was defined */
+	if (dm_gpio_is_valid(&pcie->reset_gpio))
+		dm_gpio_set_value(&pcie->reset_gpio, 0);
+
 	mvebu_pcie_wait_for_link(pcie);
 
 	return 0;
Signature · 1 line
2.20.1
Reviewed-by on v2 1/1
#13 lore raw
Quoted 8 lines · Pali Rohár

Release PERST# signal via GPIO when "reset-gpios" is defined in device tree.

---
Changes in v2:
* select DM_GPIO
* use asm/gpio.h

Thanks,
Stefan

Quoted 53 lines
---
  drivers/pci/Kconfig     |  1 +
  drivers/pci/pci_mvebu.c | 14 ++++++++++++++
  2 files changed, 15 insertions(+)
drivers/pci/Kconfig +1 -0
index 436acca898e4..22f4995453ed 100644
@@ -301,6 +301,7 @@ config PCI_MVEBU
  	depends on (ARCH_KIRKWOOD || ARCH_MVEBU)
  	select MISC
  	select DM_RESET
+	select DM_GPIO
  	help
  	  Say Y here if you want to enable PCIe controller support on
  	  Kirkwood and Armada 370/XP/375/38x SoCs.
drivers/pci/pci_mvebu.c +10 -0
index d80f87e0cfc6..5bd340a421b8 100644
@@ -22,6 +22,7 @@
  #include <asm/io.h>
  #include <asm/arch/cpu.h>
  #include <asm/arch/soc.h>
+#include <asm/gpio.h>
  #include <linux/bitops.h>
  #include <linux/delay.h>
  #include <linux/errno.h>
@@ -60,6 +61,7 @@ struct mvebu_pcie {
  	struct resource mem;
  	void __iomem *iobase;
  	struct resource io;
+	struct gpio_desc reset_gpio;
  	u32 intregs;
  	u32 port;
  	u32 lane;
@@ -416,6 +418,14 @@ static int mvebu_pcie_probe(struct udevice *dev)
  	struct udevice *ctlr = pci_get_controller(dev);
  	struct pci_controller *hose = dev_get_uclass_priv(ctlr);
  	u32 reg;
+	int ret;
+
+	/* Request for optional PERST# GPIO */
+	ret = gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT);
+	if (ret && ret != -ENOENT) {
+		printf("%s: unable to request reset-gpios: %d\n", pcie->name, ret);
+		return ret;
+	}
 
  	/*
  	 * Change Class Code of PCI Bridge device to PCI Bridge (0x600400)

drivers/pci/pci_mvebu.c static int mvebu_pcie_probe(struct udevice *dev) · line 556

Quoted 10 lines
drivers/pci/pci_mvebu.c +4 -0
@@ -537,6 +547,10 @@ static int mvebu_pcie_probe(struct udevice *dev)
  	pcie->cfgcache[(PCI_PREF_MEMORY_BASE - 0x10) / 4] =
  		PCI_PREF_RANGE_TYPE_64 | (PCI_PREF_RANGE_TYPE_64 << 16);
 
+	/* Release PERST# via GPIO when it was defined */
+	if (dm_gpio_is_valid(&pcie->reset_gpio))
+		dm_gpio_set_value(&pcie->reset_gpio, 0);
+
  	mvebu_pcie_wait_for_link(pcie);
 
  	return 0;

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
#14 lore raw
In reply to Pali Rohár
Quoted 4 lines · Pali Rohár

Release PERST# signal via GPIO when "reset-gpios" is defined in device tree.

Applied to u-boot-marvell/master

Thanks,
Stefan

Quoted 57 lines

---
Changes in v2:
* select DM_GPIO
* use asm/gpio.h

---
  drivers/pci/Kconfig     |  1 +
  drivers/pci/pci_mvebu.c | 14 ++++++++++++++
  2 files changed, 15 insertions(+)
drivers/pci/Kconfig +1 -0
index 436acca898e4..22f4995453ed 100644
@@ -301,6 +301,7 @@ config PCI_MVEBU
  	depends on (ARCH_KIRKWOOD || ARCH_MVEBU)
  	select MISC
  	select DM_RESET
+	select DM_GPIO
  	help
  	  Say Y here if you want to enable PCIe controller support on
  	  Kirkwood and Armada 370/XP/375/38x SoCs.
drivers/pci/pci_mvebu.c +10 -0
index d80f87e0cfc6..5bd340a421b8 100644
@@ -22,6 +22,7 @@
  #include <asm/io.h>
  #include <asm/arch/cpu.h>
  #include <asm/arch/soc.h>
+#include <asm/gpio.h>
  #include <linux/bitops.h>
  #include <linux/delay.h>
  #include <linux/errno.h>
@@ -60,6 +61,7 @@ struct mvebu_pcie {
  	struct resource mem;
  	void __iomem *iobase;
  	struct resource io;
+	struct gpio_desc reset_gpio;
  	u32 intregs;
  	u32 port;
  	u32 lane;
@@ -416,6 +418,14 @@ static int mvebu_pcie_probe(struct udevice *dev)
  	struct udevice *ctlr = pci_get_controller(dev);
  	struct pci_controller *hose = dev_get_uclass_priv(ctlr);
  	u32 reg;
+	int ret;
+
+	/* Request for optional PERST# GPIO */
+	ret = gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT);
+	if (ret && ret != -ENOENT) {
+		printf("%s: unable to request reset-gpios: %d\n", pcie->name, ret);
+		return ret;
+	}
 
  	/*
  	 * Change Class Code of PCI Bridge device to PCI Bridge (0x600400)

drivers/pci/pci_mvebu.c static int mvebu_pcie_probe(struct udevice *dev) · line 556

Quoted 10 lines
drivers/pci/pci_mvebu.c +4 -0
@@ -537,6 +547,10 @@ static int mvebu_pcie_probe(struct udevice *dev)
  	pcie->cfgcache[(PCI_PREF_MEMORY_BASE - 0x10) / 4] =
  		PCI_PREF_RANGE_TYPE_64 | (PCI_PREF_RANGE_TYPE_64 << 16);
 
+	/* Release PERST# via GPIO when it was defined */
+	if (dm_gpio_is_valid(&pcie->reset_gpio))
+		dm_gpio_set_value(&pcie->reset_gpio, 0);
+
  	mvebu_pcie_wait_for_link(pcie);
 
  	return 0;

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]