0016-MIPS-ath79-get-PCIe-controller-out-of-reset.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. From d3fa9694bc71338161ae2b9c7ee08b57b8140f93 Mon Sep 17 00:00:00 2001
  2. From: Mathias Kresin <dev@kresin.me>
  3. Date: Tue, 6 Mar 2018 08:37:43 +0100
  4. Subject: [PATCH 16/33] MIPS: ath79: get PCIe controller out of reset
  5. The ar724x pci driver expects the PCIe controller to be brought out of
  6. reset by the bootloader.
  7. At least the AVM Fritz 300E bootloader doesn't take care of releasing
  8. the different PCIe controller related resets which causes an endless
  9. hang as soon as either the PCIE Reset register (0x180f0018) or the PCI
  10. Application Control register (0x180f0000) is read from.
  11. Do the full "PCIE Root Complex Initialization Sequence" if the PCIe
  12. host controller is still in reset during probing.
  13. The QCA u-boot sleeps 10ms after the PCIE Application Control bit is
  14. set to ready. It has been shown that 10ms might not be enough time if
  15. PCIe should be used right after setting the bit. During my tests it
  16. took up to 20ms till the link was up. Giving the link up to 100ms
  17. should work for all cases.
  18. Signed-off-by: Mathias Kresin <dev@kresin.me>
  19. Signed-off-by: John Crispin <john@phrozen.org>
  20. ---
  21. arch/mips/pci/pci-ar724x.c | 42 ++++++++++++++++++++++++++++++++++++++++++
  22. 1 file changed, 42 insertions(+)
  23. --- a/arch/mips/pci/pci-ar724x.c
  24. +++ b/arch/mips/pci/pci-ar724x.c
  25. @@ -12,14 +12,18 @@
  26. #include <linux/irq.h>
  27. #include <linux/pci.h>
  28. #include <linux/init.h>
  29. +#include <linux/delay.h>
  30. #include <linux/platform_device.h>
  31. #include <asm/mach-ath79/ath79.h>
  32. #include <asm/mach-ath79/ar71xx_regs.h>
  33. +#define AR724X_PCI_REG_APP 0x00
  34. #define AR724X_PCI_REG_RESET 0x18
  35. #define AR724X_PCI_REG_INT_STATUS 0x4c
  36. #define AR724X_PCI_REG_INT_MASK 0x50
  37. +#define AR724X_PCI_APP_LTSSM_ENABLE BIT(0)
  38. +
  39. #define AR724X_PCI_RESET_LINK_UP BIT(0)
  40. #define AR724X_PCI_INT_DEV0 BIT(14)
  41. @@ -325,6 +329,37 @@ static void ar724x_pci_irq_init(struct a
  42. apc);
  43. }
  44. +static void ar724x_pci_hw_init(struct ar724x_pci_controller *apc)
  45. +{
  46. + u32 ppl, app;
  47. + int wait = 0;
  48. +
  49. + /* deassert PCIe host controller and PCIe PHY reset */
  50. + ath79_device_reset_clear(AR724X_RESET_PCIE);
  51. + ath79_device_reset_clear(AR724X_RESET_PCIE_PHY);
  52. +
  53. + /* remove the reset of the PCIE PLL */
  54. + ppl = ath79_pll_rr(AR724X_PLL_REG_PCIE_CONFIG);
  55. + ppl &= ~AR724X_PLL_REG_PCIE_CONFIG_PPL_RESET;
  56. + ath79_pll_wr(AR724X_PLL_REG_PCIE_CONFIG, ppl);
  57. +
  58. + /* deassert bypass for the PCIE PLL */
  59. + ppl = ath79_pll_rr(AR724X_PLL_REG_PCIE_CONFIG);
  60. + ppl &= ~AR724X_PLL_REG_PCIE_CONFIG_PPL_BYPASS;
  61. + ath79_pll_wr(AR724X_PLL_REG_PCIE_CONFIG, ppl);
  62. +
  63. + /* set PCIE Application Control to ready */
  64. + app = __raw_readl(apc->ctrl_base + AR724X_PCI_REG_APP);
  65. + app |= AR724X_PCI_APP_LTSSM_ENABLE;
  66. + __raw_writel(app, apc->ctrl_base + AR724X_PCI_REG_APP);
  67. +
  68. + /* wait up to 100ms for PHY link up */
  69. + do {
  70. + mdelay(10);
  71. + wait++;
  72. + } while (wait < 10 && !ar724x_pci_check_link(apc));
  73. +}
  74. +
  75. static int ar724x_pci_probe(struct platform_device *pdev)
  76. {
  77. struct ar724x_pci_controller *apc;
  78. @@ -383,6 +418,13 @@ static int ar724x_pci_probe(struct platf
  79. apc->pci_controller.io_resource = &apc->io_res;
  80. apc->pci_controller.mem_resource = &apc->mem_res;
  81. + /*
  82. + * Do the full PCIE Root Complex Initialization Sequence if the PCIe
  83. + * host controller is in reset.
  84. + */
  85. + if (ath79_reset_rr(AR724X_RESET_REG_RESET_MODULE) & AR724X_RESET_PCIE)
  86. + ar724x_pci_hw_init(apc);
  87. +
  88. apc->link_up = ar724x_pci_check_link(apc);
  89. if (!apc->link_up)
  90. dev_warn(&pdev->dev, "PCIe link is down\n");