bae5a1fdf8ffa8e1b7732dadaaf826c4e47a010c
[openwrt.git] / target / linux / imx6 / patches-3.14 / 0055-pci_imx6_fix-boot-hang-when-link-already-enabled.patch
1 This fixes a boot hang observed when the bootloader
2 already enabled the PCIe link for it's own use. The
3 fundamental problem is that Freescale forgot to wire
4 up the core reset, so software doesn't have a sane way
5 to get the core into a defined state.
6
7 According to the DW PCIe core reference manual configuration
8 of the core may only happen when the LTSSM is disabled, so
9 this is one of the first things we need to do. Apparently
10 this isn't safe to do when the LTSSM is in any other state
11 than "detect" as we observe an instant machine hang when
12 trying to do so while the link is already up.
13
14 As a workaround force LTSSM into detect state right before
15 hitting the disable switch.
16
17 Reported-by: Fabio Estevam <fabio.estevam <at> freescale.com>
18 Signed-off-by: Lucas Stach <l.stach <at> pengutronix.de>
19 Acked-by: Tim Harvey <tharvey <at> gateworks.com>
20 --- a/drivers/pci/host/pci-imx6.c
21 +++ b/drivers/pci/host/pci-imx6.c
22 @@ -52,6 +52,9 @@ struct imx6_pcie {
23  
24  /* PCIe Port Logic registers (memory-mapped) */
25  #define PL_OFFSET 0x700
26 +#define PCIE_PL_PFLR (PL_OFFSET + 0x08)
27 +#define PCIE_PL_PFLR_LINK_STATE_MASK           (0x3f << 16)
28 +#define PCIE_PL_PFLR_FORCE_LINK                        (1 << 15)
29  #define PCIE_PHY_DEBUG_R0 (PL_OFFSET + 0x28)
30  #define PCIE_PHY_DEBUG_R1 (PL_OFFSET + 0x2c)
31  #define PCIE_PHY_DEBUG_R1_XMLH_LINK_IN_TRAINING        (1 << 29)
32 @@ -217,6 +220,31 @@ static int imx6q_pcie_abort_handler(unsi
33  static int imx6_pcie_assert_core_reset(struct pcie_port *pp)
34  {
35         struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp);
36 +       u32 val, gpr1, gpr12;
37 +
38 +       /*
39 +        * If the bootloader already enabled the link we need some special
40 +        * handling to get the core back into a state where it is safe to
41 +        * touch it for configuration. As there is no dedicated reset signal
42 +        * wired up for MX6QDL, we need to manually force LTSSM into "detect"
43 +        * state before completely disabling LTSSM, which is a prerequisite
44 +        * for core configuration.
45 +        * If both LTSSM_ENABLE and REF_SSP_ENABLE are active we have a strong
46 +        * indication that the bootloader activated the link.
47 +        */
48 +       regmap_read(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1, &gpr1);
49 +       regmap_read(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, &gpr12);
50 +
51 +       if ((gpr1 & IMX6Q_GPR1_PCIE_REF_CLK_EN) &&
52 +           (gpr12 & IMX6Q_GPR12_PCIE_CTL_2)) {
53 +               val = readl(pp->dbi_base + PCIE_PL_PFLR);
54 +               val &= ~PCIE_PL_PFLR_LINK_STATE_MASK;
55 +               val |= PCIE_PL_PFLR_FORCE_LINK;
56 +               writel(val, pp->dbi_base + PCIE_PL_PFLR);
57 +
58 +               regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
59 +                               IMX6Q_GPR12_PCIE_CTL_2, 0 << 10);
60 +       }
61  
62         regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
63                         IMX6Q_GPR1_PCIE_TEST_PD, 1 << 18);
64 @@ -627,6 +655,14 @@ static int __init imx6_pcie_probe(struct
65         return 0;
66  }
67  
68 +static void imx6_pcie_shutdown(struct platform_device *pdev)
69 +{
70 +       struct imx6_pcie *imx6_pcie = platform_get_drvdata(pdev);
71 +
72 +       /* bring down link, so bootloader gets clean state in case of reboot */
73 +       imx6_pcie_assert_core_reset(&imx6_pcie->pp);
74 +}
75 +
76  static const struct of_device_id imx6_pcie_of_match[] = {
77         { .compatible = "fsl,imx6q-pcie", },
78         {},
79 @@ -639,6 +675,7 @@ static struct platform_driver imx6_pcie_
80                 .owner  = THIS_MODULE,
81                 .of_match_table = imx6_pcie_of_match,
82         },
83 +       .shutdown = imx6_pcie_shutdown,
84  };
85  
86  /* Freescale PCIe driver does not allow module unload */