106-02-MIPS-ath79-do-AR724x-PCIe-root-complex-init.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. From 460f382c278fe66059a773c41cbcd0db86d53983 Mon Sep 17 00:00:00 2001
  2. From: Mathias Kresin <dev@kresin.me>
  3. Date: Thu, 13 Apr 2017 09:47:42 +0200
  4. Subject: [PATCH] MIPS: pci-ar724x: 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. ---
  20. arch/mips/include/asm/mach-ath79/ar71xx_regs.h | 3 ++
  21. arch/mips/pci/pci-ar724x.c | 42 ++++++++++++++++++++++++++
  22. 2 files changed, 45 insertions(+)
  23. --- a/arch/mips/include/asm/mach-ath79/ar71xx_regs.h
  24. +++ b/arch/mips/include/asm/mach-ath79/ar71xx_regs.h
  25. @@ -169,6 +169,9 @@
  26. #define AR724X_PLL_REG_CPU_CONFIG 0x00
  27. #define AR724X_PLL_REG_PCIE_CONFIG 0x10
  28. +#define AR724X_PLL_REG_PCIE_CONFIG_PPL_BYPASS BIT(16)
  29. +#define AR724X_PLL_REG_PCIE_CONFIG_PPL_RESET BIT(25)
  30. +
  31. #define AR724X_PLL_FB_SHIFT 0
  32. #define AR724X_PLL_FB_MASK 0x3ff
  33. #define AR724X_PLL_REF_DIV_SHIFT 10
  34. --- a/arch/mips/pci/pci-ar724x.c
  35. +++ b/arch/mips/pci/pci-ar724x.c
  36. @@ -12,14 +12,18 @@
  37. #include <linux/irq.h>
  38. #include <linux/pci.h>
  39. #include <linux/init.h>
  40. +#include <linux/delay.h>
  41. #include <linux/platform_device.h>
  42. #include <asm/mach-ath79/ath79.h>
  43. #include <asm/mach-ath79/ar71xx_regs.h>
  44. +#define AR724X_PCI_REG_APP 0x0
  45. #define AR724X_PCI_REG_RESET 0x18
  46. #define AR724X_PCI_REG_INT_STATUS 0x4c
  47. #define AR724X_PCI_REG_INT_MASK 0x50
  48. +#define AR724X_PCI_APP_LTSSM_ENABLE BIT(0)
  49. +
  50. #define AR724X_PCI_RESET_LINK_UP BIT(0)
  51. #define AR724X_PCI_INT_DEV0 BIT(14)
  52. @@ -325,6 +329,37 @@ static void ar724x_pci_irq_init(struct a
  53. apc);
  54. }
  55. +static void ar724x_pci_hw_init(struct ar724x_pci_controller *apc)
  56. +{
  57. + u32 ppl, app;
  58. + int wait = 0;
  59. +
  60. + /* deassert PCIe host controller and PCIe PHY reset */
  61. + ath79_device_reset_clear(AR724X_RESET_PCIE);
  62. + ath79_device_reset_clear(AR724X_RESET_PCIE_PHY);
  63. +
  64. + /* remove the reset of the PCIE PLL */
  65. + ppl = ath79_pll_rr(AR724X_PLL_REG_PCIE_CONFIG);
  66. + ppl &= ~AR724X_PLL_REG_PCIE_CONFIG_PPL_RESET;
  67. + ath79_pll_wr(AR724X_PLL_REG_PCIE_CONFIG, ppl);
  68. +
  69. + /* deassert bypass for the PCIE PLL */
  70. + ppl = ath79_pll_rr(AR724X_PLL_REG_PCIE_CONFIG);
  71. + ppl &= ~AR724X_PLL_REG_PCIE_CONFIG_PPL_BYPASS;
  72. + ath79_pll_wr(AR724X_PLL_REG_PCIE_CONFIG, ppl);
  73. +
  74. + /* set PCIE Application Control to ready */
  75. + app = __raw_readl(apc->ctrl_base + AR724X_PCI_REG_APP);
  76. + app |= AR724X_PCI_APP_LTSSM_ENABLE;
  77. + __raw_writel(app, apc->ctrl_base + AR724X_PCI_REG_APP);
  78. +
  79. + /* wait up to 100ms for PHY link up */
  80. + do {
  81. + mdelay(10);
  82. + wait++;
  83. + } while (wait < 10 && !ar724x_pci_check_link(apc));
  84. +}
  85. +
  86. static int ar724x_pci_probe(struct platform_device *pdev)
  87. {
  88. struct ar724x_pci_controller *apc;
  89. @@ -383,6 +418,13 @@ static int ar724x_pci_probe(struct platf
  90. apc->pci_controller.io_resource = &apc->io_res;
  91. apc->pci_controller.mem_resource = &apc->mem_res;
  92. + /*
  93. + * Do the full PCIE Root Complex Initialization Sequence if the PCIe
  94. + * host controller is in reset.
  95. + */
  96. + if (ath79_reset_rr(AR724X_RESET_REG_RESET_MODULE) & AR724X_RESET_PCIE)
  97. + ar724x_pci_hw_init(apc);
  98. +
  99. apc->link_up = ar724x_pci_check_link(apc);
  100. if (!apc->link_up)
  101. dev_warn(&pdev->dev, "PCIe link is down\n");