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