kernel: bump 4.14 to 4.14.43 for 18.06
[openwrt/openwrt.git] / target / linux / ath79 / patches-4.14 / 0019-MIPS-ath79-get-PCIe-controller-out-of-reset.patch
1 From 308c2ef9c4f1be2e1cee699042671eb973b51803 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 19/27] 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 ---
25 arch/mips/pci/pci-ar724x.c | 42 ++++++++++++++++++++++++++++++++++++++++++
26 1 file changed, 42 insertions(+)
27
28 --- a/arch/mips/pci/pci-ar724x.c
29 +++ b/arch/mips/pci/pci-ar724x.c
30 @@ -12,14 +12,18 @@
31 #include <linux/irq.h>
32 #include <linux/pci.h>
33 #include <linux/init.h>
34 +#include <linux/delay.h>
35 #include <linux/platform_device.h>
36 #include <asm/mach-ath79/ath79.h>
37 #include <asm/mach-ath79/ar71xx_regs.h>
38
39 +#define AR724X_PCI_REG_APP 0x00
40 #define AR724X_PCI_REG_RESET 0x18
41 #define AR724X_PCI_REG_INT_STATUS 0x4c
42 #define AR724X_PCI_REG_INT_MASK 0x50
43
44 +#define AR724X_PCI_APP_LTSSM_ENABLE BIT(0)
45 +
46 #define AR724X_PCI_RESET_LINK_UP BIT(0)
47
48 #define AR724X_PCI_INT_DEV0 BIT(14)
49 @@ -325,6 +329,37 @@ static void ar724x_pci_irq_init(struct a
50 apc);
51 }
52
53 +static void ar724x_pci_hw_init(struct ar724x_pci_controller *apc)
54 +{
55 + u32 ppl, app;
56 + int wait = 0;
57 +
58 + /* deassert PCIe host controller and PCIe PHY reset */
59 + ath79_device_reset_clear(AR724X_RESET_PCIE);
60 + ath79_device_reset_clear(AR724X_RESET_PCIE_PHY);
61 +
62 + /* remove the reset of the PCIE PLL */
63 + ppl = ath79_pll_rr(AR724X_PLL_REG_PCIE_CONFIG);
64 + ppl &= ~AR724X_PLL_REG_PCIE_CONFIG_PPL_RESET;
65 + ath79_pll_wr(AR724X_PLL_REG_PCIE_CONFIG, ppl);
66 +
67 + /* deassert bypass for the PCIE PLL */
68 + ppl = ath79_pll_rr(AR724X_PLL_REG_PCIE_CONFIG);
69 + ppl &= ~AR724X_PLL_REG_PCIE_CONFIG_PPL_BYPASS;
70 + ath79_pll_wr(AR724X_PLL_REG_PCIE_CONFIG, ppl);
71 +
72 + /* set PCIE Application Control to ready */
73 + app = __raw_readl(apc->ctrl_base + AR724X_PCI_REG_APP);
74 + app |= AR724X_PCI_APP_LTSSM_ENABLE;
75 + __raw_writel(app, apc->ctrl_base + AR724X_PCI_REG_APP);
76 +
77 + /* wait up to 100ms for PHY link up */
78 + do {
79 + mdelay(10);
80 + wait++;
81 + } while (wait < 10 && !ar724x_pci_check_link(apc));
82 +}
83 +
84 static int ar724x_pci_probe(struct platform_device *pdev)
85 {
86 struct ar724x_pci_controller *apc;
87 @@ -383,6 +418,13 @@ static int ar724x_pci_probe(struct platf
88 apc->pci_controller.io_resource = &apc->io_res;
89 apc->pci_controller.mem_resource = &apc->mem_res;
90
91 + /*
92 + * Do the full PCIE Root Complex Initialization Sequence if the PCIe
93 + * host controller is in reset.
94 + */
95 + if (ath79_reset_rr(AR724X_RESET_REG_RESET_MODULE) & AR724X_RESET_PCIE)
96 + ar724x_pci_hw_init(apc);
97 +
98 apc->link_up = ar724x_pci_check_link(apc);
99 if (!apc->link_up)
100 dev_warn(&pdev->dev, "PCIe link is down\n");