aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/pci/Kconfig6
-rw-r--r--drivers/pci/controller/dwc/Kconfig24
-rw-r--r--drivers/pci/controller/dwc/Makefile2
-rw-r--r--drivers/pci/controller/dwc/pci-imx6.c92
-rw-r--r--drivers/pci/controller/dwc/pci-layerscape.c10
-rw-r--r--drivers/pci/controller/dwc/pci-meson.c592
-rw-r--r--drivers/pci/controller/dwc/pcie-armada8k.c16
-rw-r--r--drivers/pci/controller/dwc/pcie-designware-ep.c4
-rw-r--r--drivers/pci/controller/dwc/pcie-designware-host.c40
-rw-r--r--drivers/pci/controller/dwc/pcie-designware.c8
-rw-r--r--drivers/pci/controller/dwc/pcie-designware.h28
-rw-r--r--drivers/pci/controller/dwc/pcie-histb.c2
-rw-r--r--drivers/pci/controller/dwc/pcie-uniphier.c471
-rw-r--r--drivers/pci/controller/pcie-mediatek.c109
-rw-r--r--drivers/pci/iov.c48
-rw-r--r--drivers/pci/p2pdma.c14
-rw-r--r--drivers/pci/pci-driver.c27
-rw-r--r--drivers/pci/pci.h2
-rw-r--r--drivers/pci/pcie/aspm.c6
-rw-r--r--drivers/pci/pcie/portdrv.h16
-rw-r--r--drivers/pci/quirks.c24
-rw-r--r--drivers/pci/switch/switchtec.c154
-rw-r--r--drivers/usb/dwc3/dwc3-haps.c4
23 files changed, 1511 insertions, 188 deletions
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 2dcc30429e8b..ffe7895aa880 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -73,9 +73,9 @@ config PCI_PF_STUB
73 depends on PCI_IOV 73 depends on PCI_IOV
74 help 74 help
75 Say Y or M here if you want to enable support for devices that 75 Say Y or M here if you want to enable support for devices that
76 require SR-IOV support, while at the same time the PF itself is 76 require SR-IOV support, while at the same time the PF (Physical
77 not providing any actual services on the host itself such as 77 Function) itself is not providing any actual services on the
78 storage or networking. 78 host itself such as storage or networking.
79 79
80 When in doubt, say N. 80 When in doubt, say N.
81 81
diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig
index 91b0194240a5..548c58223868 100644
--- a/drivers/pci/controller/dwc/Kconfig
+++ b/drivers/pci/controller/dwc/Kconfig
@@ -89,8 +89,8 @@ config PCI_EXYNOS
89 select PCIE_DW_HOST 89 select PCIE_DW_HOST
90 90
91config PCI_IMX6 91config PCI_IMX6
92 bool "Freescale i.MX6 PCIe controller" 92 bool "Freescale i.MX6/7 PCIe controller"
93 depends on SOC_IMX6Q || (ARM && COMPILE_TEST) 93 depends on SOC_IMX6Q || SOC_IMX7D || (ARM && COMPILE_TEST)
94 depends on PCI_MSI_IRQ_DOMAIN 94 depends on PCI_MSI_IRQ_DOMAIN
95 select PCIE_DW_HOST 95 select PCIE_DW_HOST
96 96
@@ -193,4 +193,24 @@ config PCIE_HISI_STB
193 help 193 help
194 Say Y here if you want PCIe controller support on HiSilicon STB SoCs 194 Say Y here if you want PCIe controller support on HiSilicon STB SoCs
195 195
196config PCI_MESON
197 bool "MESON PCIe controller"
198 depends on PCI_MSI_IRQ_DOMAIN
199 select PCIE_DW_HOST
200 help
201 Say Y here if you want to enable PCI controller support on Amlogic
202 SoCs. The PCI controller on Amlogic is based on DesignWare hardware
203 and therefore the driver re-uses the DesignWare core functions to
204 implement the driver.
205
206config PCIE_UNIPHIER
207 bool "Socionext UniPhier PCIe controllers"
208 depends on ARCH_UNIPHIER || COMPILE_TEST
209 depends on OF && HAS_IOMEM
210 depends on PCI_MSI_IRQ_DOMAIN
211 select PCIE_DW_HOST
212 help
213 Say Y here if you want PCIe controller support on UniPhier SoCs.
214 This driver supports LD20 and PXs3 SoCs.
215
196endmenu 216endmenu
diff --git a/drivers/pci/controller/dwc/Makefile b/drivers/pci/controller/dwc/Makefile
index fcf91eacfc63..7bcdcdf5024e 100644
--- a/drivers/pci/controller/dwc/Makefile
+++ b/drivers/pci/controller/dwc/Makefile
@@ -14,6 +14,8 @@ obj-$(CONFIG_PCIE_ARMADA_8K) += pcie-armada8k.o
14obj-$(CONFIG_PCIE_ARTPEC6) += pcie-artpec6.o 14obj-$(CONFIG_PCIE_ARTPEC6) += pcie-artpec6.o
15obj-$(CONFIG_PCIE_KIRIN) += pcie-kirin.o 15obj-$(CONFIG_PCIE_KIRIN) += pcie-kirin.o
16obj-$(CONFIG_PCIE_HISI_STB) += pcie-histb.o 16obj-$(CONFIG_PCIE_HISI_STB) += pcie-histb.o
17obj-$(CONFIG_PCI_MESON) += pci-meson.o
18obj-$(CONFIG_PCIE_UNIPHIER) += pcie-uniphier.o
17 19
18# The following drivers are for devices that use the generic ACPI 20# The following drivers are for devices that use the generic ACPI
19# pci_root.c driver but don't support standard ECAM config access. 21# pci_root.c driver but don't support standard ECAM config access.
diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index bd02760257e5..03107cc25dfc 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -27,6 +27,8 @@
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/interrupt.h> 28#include <linux/interrupt.h>
29#include <linux/reset.h> 29#include <linux/reset.h>
30#include <linux/pm_domain.h>
31#include <linux/pm_runtime.h>
30 32
31#include "pcie-designware.h" 33#include "pcie-designware.h"
32 34
@@ -59,6 +61,11 @@ struct imx6_pcie {
59 u32 tx_swing_low; 61 u32 tx_swing_low;
60 int link_gen; 62 int link_gen;
61 struct regulator *vpcie; 63 struct regulator *vpcie;
64
65 /* power domain for pcie */
66 struct device *pd_pcie;
67 /* power domain for pcie phy */
68 struct device *pd_pcie_phy;
62}; 69};
63 70
64/* Parameters for the waiting for PCIe PHY PLL to lock on i.MX7 */ 71/* Parameters for the waiting for PCIe PHY PLL to lock on i.MX7 */
@@ -293,6 +300,43 @@ static int imx6q_pcie_abort_handler(unsigned long addr,
293 return 1; 300 return 1;
294} 301}
295 302
303static int imx6_pcie_attach_pd(struct device *dev)
304{
305 struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev);
306 struct device_link *link;
307
308 /* Do nothing when in a single power domain */
309 if (dev->pm_domain)
310 return 0;
311
312 imx6_pcie->pd_pcie = dev_pm_domain_attach_by_name(dev, "pcie");
313 if (IS_ERR(imx6_pcie->pd_pcie))
314 return PTR_ERR(imx6_pcie->pd_pcie);
315 link = device_link_add(dev, imx6_pcie->pd_pcie,
316 DL_FLAG_STATELESS |
317 DL_FLAG_PM_RUNTIME |
318 DL_FLAG_RPM_ACTIVE);
319 if (!link) {
320 dev_err(dev, "Failed to add device_link to pcie pd.\n");
321 return -EINVAL;
322 }
323
324 imx6_pcie->pd_pcie_phy = dev_pm_domain_attach_by_name(dev, "pcie_phy");
325 if (IS_ERR(imx6_pcie->pd_pcie_phy))
326 return PTR_ERR(imx6_pcie->pd_pcie_phy);
327
328 device_link_add(dev, imx6_pcie->pd_pcie_phy,
329 DL_FLAG_STATELESS |
330 DL_FLAG_PM_RUNTIME |
331 DL_FLAG_RPM_ACTIVE);
332 if (IS_ERR(link)) {
333 dev_err(dev, "Failed to add device_link to pcie_phy pd: %ld\n", PTR_ERR(link));
334 return PTR_ERR(link);
335 }
336
337 return 0;
338}
339
296static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie) 340static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie)
297{ 341{
298 struct device *dev = imx6_pcie->pci->dev; 342 struct device *dev = imx6_pcie->pci->dev;
@@ -774,8 +818,28 @@ static void imx6_pcie_ltssm_disable(struct device *dev)
774 818
775static void imx6_pcie_pm_turnoff(struct imx6_pcie *imx6_pcie) 819static void imx6_pcie_pm_turnoff(struct imx6_pcie *imx6_pcie)
776{ 820{
777 reset_control_assert(imx6_pcie->turnoff_reset); 821 struct device *dev = imx6_pcie->pci->dev;
778 reset_control_deassert(imx6_pcie->turnoff_reset); 822
823 /* Some variants have a turnoff reset in DT */
824 if (imx6_pcie->turnoff_reset) {
825 reset_control_assert(imx6_pcie->turnoff_reset);
826 reset_control_deassert(imx6_pcie->turnoff_reset);
827 goto pm_turnoff_sleep;
828 }
829
830 /* Others poke directly at IOMUXC registers */
831 switch (imx6_pcie->variant) {
832 case IMX6SX:
833 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
834 IMX6SX_GPR12_PCIE_PM_TURN_OFF,
835 IMX6SX_GPR12_PCIE_PM_TURN_OFF);
836 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
837 IMX6SX_GPR12_PCIE_PM_TURN_OFF, 0);
838 break;
839 default:
840 dev_err(dev, "PME_Turn_Off not implemented\n");
841 return;
842 }
779 843
780 /* 844 /*
781 * Components with an upstream port must respond to 845 * Components with an upstream port must respond to
@@ -784,6 +848,7 @@ static void imx6_pcie_pm_turnoff(struct imx6_pcie *imx6_pcie)
784 * The standard recommends a 1-10ms timeout after which to 848 * The standard recommends a 1-10ms timeout after which to
785 * proceed anyway as if acks were received. 849 * proceed anyway as if acks were received.
786 */ 850 */
851pm_turnoff_sleep:
787 usleep_range(1000, 10000); 852 usleep_range(1000, 10000);
788} 853}
789 854
@@ -793,18 +858,31 @@ static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie)
793 clk_disable_unprepare(imx6_pcie->pcie_phy); 858 clk_disable_unprepare(imx6_pcie->pcie_phy);
794 clk_disable_unprepare(imx6_pcie->pcie_bus); 859 clk_disable_unprepare(imx6_pcie->pcie_bus);
795 860
796 if (imx6_pcie->variant == IMX7D) { 861 switch (imx6_pcie->variant) {
862 case IMX6SX:
863 clk_disable_unprepare(imx6_pcie->pcie_inbound_axi);
864 break;
865 case IMX7D:
797 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, 866 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
798 IMX7D_GPR12_PCIE_PHY_REFCLK_SEL, 867 IMX7D_GPR12_PCIE_PHY_REFCLK_SEL,
799 IMX7D_GPR12_PCIE_PHY_REFCLK_SEL); 868 IMX7D_GPR12_PCIE_PHY_REFCLK_SEL);
869 break;
870 default:
871 break;
800 } 872 }
801} 873}
802 874
875static inline bool imx6_pcie_supports_suspend(struct imx6_pcie *imx6_pcie)
876{
877 return (imx6_pcie->variant == IMX7D ||
878 imx6_pcie->variant == IMX6SX);
879}
880
803static int imx6_pcie_suspend_noirq(struct device *dev) 881static int imx6_pcie_suspend_noirq(struct device *dev)
804{ 882{
805 struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); 883 struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev);
806 884
807 if (imx6_pcie->variant != IMX7D) 885 if (!imx6_pcie_supports_suspend(imx6_pcie))
808 return 0; 886 return 0;
809 887
810 imx6_pcie_pm_turnoff(imx6_pcie); 888 imx6_pcie_pm_turnoff(imx6_pcie);
@@ -820,7 +898,7 @@ static int imx6_pcie_resume_noirq(struct device *dev)
820 struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); 898 struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev);
821 struct pcie_port *pp = &imx6_pcie->pci->pp; 899 struct pcie_port *pp = &imx6_pcie->pci->pp;
822 900
823 if (imx6_pcie->variant != IMX7D) 901 if (!imx6_pcie_supports_suspend(imx6_pcie))
824 return 0; 902 return 0;
825 903
826 imx6_pcie_assert_core_reset(imx6_pcie); 904 imx6_pcie_assert_core_reset(imx6_pcie);
@@ -987,6 +1065,10 @@ static int imx6_pcie_probe(struct platform_device *pdev)
987 1065
988 platform_set_drvdata(pdev, imx6_pcie); 1066 platform_set_drvdata(pdev, imx6_pcie);
989 1067
1068 ret = imx6_pcie_attach_pd(dev);
1069 if (ret)
1070 return ret;
1071
990 ret = imx6_add_pcie_port(imx6_pcie, pdev); 1072 ret = imx6_add_pcie_port(imx6_pcie, pdev);
991 if (ret < 0) 1073 if (ret < 0)
992 return ret; 1074 return ret;
diff --git a/drivers/pci/controller/dwc/pci-layerscape.c b/drivers/pci/controller/dwc/pci-layerscape.c
index 3724d3ef7008..905a0ab0e6fa 100644
--- a/drivers/pci/controller/dwc/pci-layerscape.c
+++ b/drivers/pci/controller/dwc/pci-layerscape.c
@@ -222,12 +222,12 @@ static const struct dw_pcie_ops dw_ls_pcie_ops = {
222 .link_up = ls_pcie_link_up, 222 .link_up = ls_pcie_link_up,
223}; 223};
224 224
225static struct ls_pcie_drvdata ls1021_drvdata = { 225static const struct ls_pcie_drvdata ls1021_drvdata = {
226 .ops = &ls1021_pcie_host_ops, 226 .ops = &ls1021_pcie_host_ops,
227 .dw_pcie_ops = &dw_ls1021_pcie_ops, 227 .dw_pcie_ops = &dw_ls1021_pcie_ops,
228}; 228};
229 229
230static struct ls_pcie_drvdata ls1043_drvdata = { 230static const struct ls_pcie_drvdata ls1043_drvdata = {
231 .lut_offset = 0x10000, 231 .lut_offset = 0x10000,
232 .ltssm_shift = 24, 232 .ltssm_shift = 24,
233 .lut_dbg = 0x7fc, 233 .lut_dbg = 0x7fc,
@@ -235,7 +235,7 @@ static struct ls_pcie_drvdata ls1043_drvdata = {
235 .dw_pcie_ops = &dw_ls_pcie_ops, 235 .dw_pcie_ops = &dw_ls_pcie_ops,
236}; 236};
237 237
238static struct ls_pcie_drvdata ls1046_drvdata = { 238static const struct ls_pcie_drvdata ls1046_drvdata = {
239 .lut_offset = 0x80000, 239 .lut_offset = 0x80000,
240 .ltssm_shift = 24, 240 .ltssm_shift = 24,
241 .lut_dbg = 0x407fc, 241 .lut_dbg = 0x407fc,
@@ -243,7 +243,7 @@ static struct ls_pcie_drvdata ls1046_drvdata = {
243 .dw_pcie_ops = &dw_ls_pcie_ops, 243 .dw_pcie_ops = &dw_ls_pcie_ops,
244}; 244};
245 245
246static struct ls_pcie_drvdata ls2080_drvdata = { 246static const struct ls_pcie_drvdata ls2080_drvdata = {
247 .lut_offset = 0x80000, 247 .lut_offset = 0x80000,
248 .ltssm_shift = 0, 248 .ltssm_shift = 0,
249 .lut_dbg = 0x7fc, 249 .lut_dbg = 0x7fc,
@@ -251,7 +251,7 @@ static struct ls_pcie_drvdata ls2080_drvdata = {
251 .dw_pcie_ops = &dw_ls_pcie_ops, 251 .dw_pcie_ops = &dw_ls_pcie_ops,
252}; 252};
253 253
254static struct ls_pcie_drvdata ls2088_drvdata = { 254static const struct ls_pcie_drvdata ls2088_drvdata = {
255 .lut_offset = 0x80000, 255 .lut_offset = 0x80000,
256 .ltssm_shift = 0, 256 .ltssm_shift = 0,
257 .lut_dbg = 0x407fc, 257 .lut_dbg = 0x407fc,
diff --git a/drivers/pci/controller/dwc/pci-meson.c b/drivers/pci/controller/dwc/pci-meson.c
new file mode 100644
index 000000000000..241ebe0c4505
--- /dev/null
+++ b/drivers/pci/controller/dwc/pci-meson.c
@@ -0,0 +1,592 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * PCIe host controller driver for Amlogic MESON SoCs
4 *
5 * Copyright (c) 2018 Amlogic, inc.
6 * Author: Yue Wang <yue.wang@amlogic.com>
7 */
8
9#include <linux/clk.h>
10#include <linux/delay.h>
11#include <linux/of_device.h>
12#include <linux/of_gpio.h>
13#include <linux/pci.h>
14#include <linux/platform_device.h>
15#include <linux/reset.h>
16#include <linux/resource.h>
17#include <linux/types.h>
18
19#include "pcie-designware.h"
20
21#define to_meson_pcie(x) dev_get_drvdata((x)->dev)
22
23/* External local bus interface registers */
24#define PLR_OFFSET 0x700
25#define PCIE_PORT_LINK_CTRL_OFF (PLR_OFFSET + 0x10)
26#define FAST_LINK_MODE BIT(7)
27#define LINK_CAPABLE_MASK GENMASK(21, 16)
28#define LINK_CAPABLE_X1 BIT(16)
29
30#define PCIE_GEN2_CTRL_OFF (PLR_OFFSET + 0x10c)
31#define NUM_OF_LANES_MASK GENMASK(12, 8)
32#define NUM_OF_LANES_X1 BIT(8)
33#define DIRECT_SPEED_CHANGE BIT(17)
34
35#define TYPE1_HDR_OFFSET 0x0
36#define PCIE_STATUS_COMMAND (TYPE1_HDR_OFFSET + 0x04)
37#define PCI_IO_EN BIT(0)
38#define PCI_MEM_SPACE_EN BIT(1)
39#define PCI_BUS_MASTER_EN BIT(2)
40
41#define PCIE_BASE_ADDR0 (TYPE1_HDR_OFFSET + 0x10)
42#define PCIE_BASE_ADDR1 (TYPE1_HDR_OFFSET + 0x14)
43
44#define PCIE_CAP_OFFSET 0x70
45#define PCIE_DEV_CTRL_DEV_STUS (PCIE_CAP_OFFSET + 0x08)
46#define PCIE_CAP_MAX_PAYLOAD_MASK GENMASK(7, 5)
47#define PCIE_CAP_MAX_PAYLOAD_SIZE(x) ((x) << 5)
48#define PCIE_CAP_MAX_READ_REQ_MASK GENMASK(14, 12)
49#define PCIE_CAP_MAX_READ_REQ_SIZE(x) ((x) << 12)
50
51/* PCIe specific config registers */
52#define PCIE_CFG0 0x0
53#define APP_LTSSM_ENABLE BIT(7)
54
55#define PCIE_CFG_STATUS12 0x30
56#define IS_SMLH_LINK_UP(x) ((x) & (1 << 6))
57#define IS_RDLH_LINK_UP(x) ((x) & (1 << 16))
58#define IS_LTSSM_UP(x) ((((x) >> 10) & 0x1f) == 0x11)
59
60#define PCIE_CFG_STATUS17 0x44
61#define PM_CURRENT_STATE(x) (((x) >> 7) & 0x1)
62
63#define WAIT_LINKUP_TIMEOUT 4000
64#define PORT_CLK_RATE 100000000UL
65#define MAX_PAYLOAD_SIZE 256
66#define MAX_READ_REQ_SIZE 256
67#define MESON_PCIE_PHY_POWERUP 0x1c
68#define PCIE_RESET_DELAY 500
69#define PCIE_SHARED_RESET 1
70#define PCIE_NORMAL_RESET 0
71
72enum pcie_data_rate {
73 PCIE_GEN1,
74 PCIE_GEN2,
75 PCIE_GEN3,
76 PCIE_GEN4
77};
78
79struct meson_pcie_mem_res {
80 void __iomem *elbi_base;
81 void __iomem *cfg_base;
82 void __iomem *phy_base;
83};
84
85struct meson_pcie_clk_res {
86 struct clk *clk;
87 struct clk *mipi_gate;
88 struct clk *port_clk;
89 struct clk *general_clk;
90};
91
92struct meson_pcie_rc_reset {
93 struct reset_control *phy;
94 struct reset_control *port;
95 struct reset_control *apb;
96};
97
98struct meson_pcie {
99 struct dw_pcie pci;
100 struct meson_pcie_mem_res mem_res;
101 struct meson_pcie_clk_res clk_res;
102 struct meson_pcie_rc_reset mrst;
103 struct gpio_desc *reset_gpio;
104};
105
106static struct reset_control *meson_pcie_get_reset(struct meson_pcie *mp,
107 const char *id,
108 u32 reset_type)
109{
110 struct device *dev = mp->pci.dev;
111 struct reset_control *reset;
112
113 if (reset_type == PCIE_SHARED_RESET)
114 reset = devm_reset_control_get_shared(dev, id);
115 else
116 reset = devm_reset_control_get(dev, id);
117
118 return reset;
119}
120
121static int meson_pcie_get_resets(struct meson_pcie *mp)
122{
123 struct meson_pcie_rc_reset *mrst = &mp->mrst;
124
125 mrst->phy = meson_pcie_get_reset(mp, "phy", PCIE_SHARED_RESET);
126 if (IS_ERR(mrst->phy))
127 return PTR_ERR(mrst->phy);
128 reset_control_deassert(mrst->phy);
129
130 mrst->port = meson_pcie_get_reset(mp, "port", PCIE_NORMAL_RESET);
131 if (IS_ERR(mrst->port))
132 return PTR_ERR(mrst->port);
133 reset_control_deassert(mrst->port);
134
135 mrst->apb = meson_pcie_get_reset(mp, "apb", PCIE_SHARED_RESET);
136 if (IS_ERR(mrst->apb))
137 return PTR_ERR(mrst->apb);
138 reset_control_deassert(mrst->apb);
139
140 return 0;
141}
142
143static void __iomem *meson_pcie_get_mem(struct platform_device *pdev,
144 struct meson_pcie *mp,
145 const char *id)
146{
147 struct device *dev = mp->pci.dev;
148 struct resource *res;
149
150 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, id);
151
152 return devm_ioremap_resource(dev, res);
153}
154
155static void __iomem *meson_pcie_get_mem_shared(struct platform_device *pdev,
156 struct meson_pcie *mp,
157 const char *id)
158{
159 struct device *dev = mp->pci.dev;
160 struct resource *res;
161
162 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, id);
163 if (!res) {
164 dev_err(dev, "No REG resource %s\n", id);
165 return ERR_PTR(-ENXIO);
166 }
167
168 return devm_ioremap(dev, res->start, resource_size(res));
169}
170
171static int meson_pcie_get_mems(struct platform_device *pdev,
172 struct meson_pcie *mp)
173{
174 mp->mem_res.elbi_base = meson_pcie_get_mem(pdev, mp, "elbi");
175 if (IS_ERR(mp->mem_res.elbi_base))
176 return PTR_ERR(mp->mem_res.elbi_base);
177
178 mp->mem_res.cfg_base = meson_pcie_get_mem(pdev, mp, "cfg");
179 if (IS_ERR(mp->mem_res.cfg_base))
180 return PTR_ERR(mp->mem_res.cfg_base);
181
182 /* Meson SoC has two PCI controllers use same phy register*/
183 mp->mem_res.phy_base = meson_pcie_get_mem_shared(pdev, mp, "phy");
184 if (IS_ERR(mp->mem_res.phy_base))
185 return PTR_ERR(mp->mem_res.phy_base);
186
187 return 0;
188}
189
190static void meson_pcie_power_on(struct meson_pcie *mp)
191{
192 writel(MESON_PCIE_PHY_POWERUP, mp->mem_res.phy_base);
193}
194
195static void meson_pcie_reset(struct meson_pcie *mp)
196{
197 struct meson_pcie_rc_reset *mrst = &mp->mrst;
198
199 reset_control_assert(mrst->phy);
200 udelay(PCIE_RESET_DELAY);
201 reset_control_deassert(mrst->phy);
202 udelay(PCIE_RESET_DELAY);
203
204 reset_control_assert(mrst->port);
205 reset_control_assert(mrst->apb);
206 udelay(PCIE_RESET_DELAY);
207 reset_control_deassert(mrst->port);
208 reset_control_deassert(mrst->apb);
209 udelay(PCIE_RESET_DELAY);
210}
211
212static inline struct clk *meson_pcie_probe_clock(struct device *dev,
213 const char *id, u64 rate)
214{
215 struct clk *clk;
216 int ret;
217
218 clk = devm_clk_get(dev, id);
219 if (IS_ERR(clk))
220 return clk;
221
222 if (rate) {
223 ret = clk_set_rate(clk, rate);
224 if (ret) {
225 dev_err(dev, "set clk rate failed, ret = %d\n", ret);
226 return ERR_PTR(ret);
227 }
228 }
229
230 ret = clk_prepare_enable(clk);
231 if (ret) {
232 dev_err(dev, "couldn't enable clk\n");
233 return ERR_PTR(ret);
234 }
235
236 devm_add_action_or_reset(dev,
237 (void (*) (void *))clk_disable_unprepare,
238 clk);
239
240 return clk;
241}
242
243static int meson_pcie_probe_clocks(struct meson_pcie *mp)
244{
245 struct device *dev = mp->pci.dev;
246 struct meson_pcie_clk_res *res = &mp->clk_res;
247
248 res->port_clk = meson_pcie_probe_clock(dev, "port", PORT_CLK_RATE);
249 if (IS_ERR(res->port_clk))
250 return PTR_ERR(res->port_clk);
251
252 res->mipi_gate = meson_pcie_probe_clock(dev, "pcie_mipi_en", 0);
253 if (IS_ERR(res->mipi_gate))
254 return PTR_ERR(res->mipi_gate);
255
256 res->general_clk = meson_pcie_probe_clock(dev, "pcie_general", 0);
257 if (IS_ERR(res->general_clk))
258 return PTR_ERR(res->general_clk);
259
260 res->clk = meson_pcie_probe_clock(dev, "pcie", 0);
261 if (IS_ERR(res->clk))
262 return PTR_ERR(res->clk);
263
264 return 0;
265}
266
267static inline void meson_elb_writel(struct meson_pcie *mp, u32 val, u32 reg)
268{
269 writel(val, mp->mem_res.elbi_base + reg);
270}
271
272static inline u32 meson_elb_readl(struct meson_pcie *mp, u32 reg)
273{
274 return readl(mp->mem_res.elbi_base + reg);
275}
276
277static inline u32 meson_cfg_readl(struct meson_pcie *mp, u32 reg)
278{
279 return readl(mp->mem_res.cfg_base + reg);
280}
281
282static inline void meson_cfg_writel(struct meson_pcie *mp, u32 val, u32 reg)
283{
284 writel(val, mp->mem_res.cfg_base + reg);
285}
286
287static void meson_pcie_assert_reset(struct meson_pcie *mp)
288{
289 gpiod_set_value_cansleep(mp->reset_gpio, 0);
290 udelay(500);
291 gpiod_set_value_cansleep(mp->reset_gpio, 1);
292}
293
294static void meson_pcie_init_dw(struct meson_pcie *mp)
295{
296 u32 val;
297
298 val = meson_cfg_readl(mp, PCIE_CFG0);
299 val |= APP_LTSSM_ENABLE;
300 meson_cfg_writel(mp, val, PCIE_CFG0);
301
302 val = meson_elb_readl(mp, PCIE_PORT_LINK_CTRL_OFF);
303 val &= ~LINK_CAPABLE_MASK;
304 meson_elb_writel(mp, val, PCIE_PORT_LINK_CTRL_OFF);
305
306 val = meson_elb_readl(mp, PCIE_PORT_LINK_CTRL_OFF);
307 val |= LINK_CAPABLE_X1 | FAST_LINK_MODE;
308 meson_elb_writel(mp, val, PCIE_PORT_LINK_CTRL_OFF);
309
310 val = meson_elb_readl(mp, PCIE_GEN2_CTRL_OFF);
311 val &= ~NUM_OF_LANES_MASK;
312 meson_elb_writel(mp, val, PCIE_GEN2_CTRL_OFF);
313
314 val = meson_elb_readl(mp, PCIE_GEN2_CTRL_OFF);
315 val |= NUM_OF_LANES_X1 | DIRECT_SPEED_CHANGE;
316 meson_elb_writel(mp, val, PCIE_GEN2_CTRL_OFF);
317
318 meson_elb_writel(mp, 0x0, PCIE_BASE_ADDR0);
319 meson_elb_writel(mp, 0x0, PCIE_BASE_ADDR1);
320}
321
322static int meson_size_to_payload(struct meson_pcie *mp, int size)
323{
324 struct device *dev = mp->pci.dev;
325
326 /*
327 * dwc supports 2^(val+7) payload size, which val is 0~5 default to 1.
328 * So if input size is not 2^order alignment or less than 2^7 or bigger
329 * than 2^12, just set to default size 2^(1+7).
330 */
331 if (!is_power_of_2(size) || size < 128 || size > 4096) {
332 dev_warn(dev, "payload size %d, set to default 256\n", size);
333 return 1;
334 }
335
336 return fls(size) - 8;
337}
338
339static void meson_set_max_payload(struct meson_pcie *mp, int size)
340{
341 u32 val;
342 int max_payload_size = meson_size_to_payload(mp, size);
343
344 val = meson_elb_readl(mp, PCIE_DEV_CTRL_DEV_STUS);
345 val &= ~PCIE_CAP_MAX_PAYLOAD_MASK;
346 meson_elb_writel(mp, val, PCIE_DEV_CTRL_DEV_STUS);
347
348 val = meson_elb_readl(mp, PCIE_DEV_CTRL_DEV_STUS);
349 val |= PCIE_CAP_MAX_PAYLOAD_SIZE(max_payload_size);
350 meson_elb_writel(mp, val, PCIE_DEV_CTRL_DEV_STUS);
351}
352
353static void meson_set_max_rd_req_size(struct meson_pcie *mp, int size)
354{
355 u32 val;
356 int max_rd_req_size = meson_size_to_payload(mp, size);
357
358 val = meson_elb_readl(mp, PCIE_DEV_CTRL_DEV_STUS);
359 val &= ~PCIE_CAP_MAX_READ_REQ_MASK;
360 meson_elb_writel(mp, val, PCIE_DEV_CTRL_DEV_STUS);
361
362 val = meson_elb_readl(mp, PCIE_DEV_CTRL_DEV_STUS);
363 val |= PCIE_CAP_MAX_READ_REQ_SIZE(max_rd_req_size);
364 meson_elb_writel(mp, val, PCIE_DEV_CTRL_DEV_STUS);
365}
366
367static inline void meson_enable_memory_space(struct meson_pcie *mp)
368{
369 /* Set the RC Bus Master, Memory Space and I/O Space enables */
370 meson_elb_writel(mp, PCI_IO_EN | PCI_MEM_SPACE_EN | PCI_BUS_MASTER_EN,
371 PCIE_STATUS_COMMAND);
372}
373
374static int meson_pcie_establish_link(struct meson_pcie *mp)
375{
376 struct dw_pcie *pci = &mp->pci;
377 struct pcie_port *pp = &pci->pp;
378
379 meson_pcie_init_dw(mp);
380 meson_set_max_payload(mp, MAX_PAYLOAD_SIZE);
381 meson_set_max_rd_req_size(mp, MAX_READ_REQ_SIZE);
382
383 dw_pcie_setup_rc(pp);
384 meson_enable_memory_space(mp);
385
386 meson_pcie_assert_reset(mp);
387
388 return dw_pcie_wait_for_link(pci);
389}
390
391static void meson_pcie_enable_interrupts(struct meson_pcie *mp)
392{
393 if (IS_ENABLED(CONFIG_PCI_MSI))
394 dw_pcie_msi_init(&mp->pci.pp);
395}
396
397static int meson_pcie_rd_own_conf(struct pcie_port *pp, int where, int size,
398 u32 *val)
399{
400 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
401 int ret;
402
403 ret = dw_pcie_read(pci->dbi_base + where, size, val);
404 if (ret != PCIBIOS_SUCCESSFUL)
405 return ret;
406
407 /*
408 * There is a bug in the MESON AXG PCIe controller whereby software
409 * cannot program the PCI_CLASS_DEVICE register, so we must fabricate
410 * the return value in the config accessors.
411 */
412 if (where == PCI_CLASS_REVISION && size == 4)
413 *val = (PCI_CLASS_BRIDGE_PCI << 16) | (*val & 0xffff);
414 else if (where == PCI_CLASS_DEVICE && size == 2)
415 *val = PCI_CLASS_BRIDGE_PCI;
416 else if (where == PCI_CLASS_DEVICE && size == 1)
417 *val = PCI_CLASS_BRIDGE_PCI & 0xff;
418 else if (where == PCI_CLASS_DEVICE + 1 && size == 1)
419 *val = (PCI_CLASS_BRIDGE_PCI >> 8) & 0xff;
420
421 return PCIBIOS_SUCCESSFUL;
422}
423
424static int meson_pcie_wr_own_conf(struct pcie_port *pp, int where,
425 int size, u32 val)
426{
427 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
428
429 return dw_pcie_write(pci->dbi_base + where, size, val);
430}
431
432static int meson_pcie_link_up(struct dw_pcie *pci)
433{
434 struct meson_pcie *mp = to_meson_pcie(pci);
435 struct device *dev = pci->dev;
436 u32 speed_okay = 0;
437 u32 cnt = 0;
438 u32 state12, state17, smlh_up, ltssm_up, rdlh_up;
439
440 do {
441 state12 = meson_cfg_readl(mp, PCIE_CFG_STATUS12);
442 state17 = meson_cfg_readl(mp, PCIE_CFG_STATUS17);
443 smlh_up = IS_SMLH_LINK_UP(state12);
444 rdlh_up = IS_RDLH_LINK_UP(state12);
445 ltssm_up = IS_LTSSM_UP(state12);
446
447 if (PM_CURRENT_STATE(state17) < PCIE_GEN3)
448 speed_okay = 1;
449
450 if (smlh_up)
451 dev_dbg(dev, "smlh_link_up is on\n");
452 if (rdlh_up)
453 dev_dbg(dev, "rdlh_link_up is on\n");
454 if (ltssm_up)
455 dev_dbg(dev, "ltssm_up is on\n");
456 if (speed_okay)
457 dev_dbg(dev, "speed_okay\n");
458
459 if (smlh_up && rdlh_up && ltssm_up && speed_okay)
460 return 1;
461
462 cnt++;
463
464 udelay(10);
465 } while (cnt < WAIT_LINKUP_TIMEOUT);
466
467 dev_err(dev, "error: wait linkup timeout\n");
468 return 0;
469}
470
471static int meson_pcie_host_init(struct pcie_port *pp)
472{
473 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
474 struct meson_pcie *mp = to_meson_pcie(pci);
475 int ret;
476
477 ret = meson_pcie_establish_link(mp);
478 if (ret)
479 return ret;
480
481 meson_pcie_enable_interrupts(mp);
482
483 return 0;
484}
485
486static const struct dw_pcie_host_ops meson_pcie_host_ops = {
487 .rd_own_conf = meson_pcie_rd_own_conf,
488 .wr_own_conf = meson_pcie_wr_own_conf,
489 .host_init = meson_pcie_host_init,
490};
491
492static int meson_add_pcie_port(struct meson_pcie *mp,
493 struct platform_device *pdev)
494{
495 struct dw_pcie *pci = &mp->pci;
496 struct pcie_port *pp = &pci->pp;
497 struct device *dev = &pdev->dev;
498 int ret;
499
500 if (IS_ENABLED(CONFIG_PCI_MSI)) {
501 pp->msi_irq = platform_get_irq(pdev, 0);
502 if (pp->msi_irq < 0) {
503 dev_err(dev, "failed to get MSI IRQ\n");
504 return pp->msi_irq;
505 }
506 }
507
508 pp->ops = &meson_pcie_host_ops;
509 pci->dbi_base = mp->mem_res.elbi_base;
510
511 ret = dw_pcie_host_init(pp);
512 if (ret) {
513 dev_err(dev, "failed to initialize host\n");
514 return ret;
515 }
516
517 return 0;
518}
519
520static const struct dw_pcie_ops dw_pcie_ops = {
521 .link_up = meson_pcie_link_up,
522};
523
524static int meson_pcie_probe(struct platform_device *pdev)
525{
526 struct device *dev = &pdev->dev;
527 struct dw_pcie *pci;
528 struct meson_pcie *mp;
529 int ret;
530
531 mp = devm_kzalloc(dev, sizeof(*mp), GFP_KERNEL);
532 if (!mp)
533 return -ENOMEM;
534
535 pci = &mp->pci;
536 pci->dev = dev;
537 pci->ops = &dw_pcie_ops;
538
539 mp->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
540 if (IS_ERR(mp->reset_gpio)) {
541 dev_err(dev, "get reset gpio failed\n");
542 return PTR_ERR(mp->reset_gpio);
543 }
544
545 ret = meson_pcie_get_resets(mp);
546 if (ret) {
547 dev_err(dev, "get reset resource failed, %d\n", ret);
548 return ret;
549 }
550
551 ret = meson_pcie_get_mems(pdev, mp);
552 if (ret) {
553 dev_err(dev, "get memory resource failed, %d\n", ret);
554 return ret;
555 }
556
557 meson_pcie_power_on(mp);
558 meson_pcie_reset(mp);
559
560 ret = meson_pcie_probe_clocks(mp);
561 if (ret) {
562 dev_err(dev, "init clock resources failed, %d\n", ret);
563 return ret;
564 }
565
566 platform_set_drvdata(pdev, mp);
567
568 ret = meson_add_pcie_port(mp, pdev);
569 if (ret < 0) {
570 dev_err(dev, "Add PCIe port failed, %d\n", ret);
571 return ret;
572 }
573
574 return 0;
575}
576
577static const struct of_device_id meson_pcie_of_match[] = {
578 {
579 .compatible = "amlogic,axg-pcie",
580 },
581 {},
582};
583
584static struct platform_driver meson_pcie_driver = {
585 .probe = meson_pcie_probe,
586 .driver = {
587 .name = "meson-pcie",
588 .of_match_table = meson_pcie_of_match,
589 },
590};
591
592builtin_platform_driver(meson_pcie_driver);
diff --git a/drivers/pci/controller/dwc/pcie-armada8k.c b/drivers/pci/controller/dwc/pcie-armada8k.c
index 0c389a30ef5d..b171b6bc15c8 100644
--- a/drivers/pci/controller/dwc/pcie-armada8k.c
+++ b/drivers/pci/controller/dwc/pcie-armada8k.c
@@ -22,6 +22,7 @@
22#include <linux/resource.h> 22#include <linux/resource.h>
23#include <linux/of_pci.h> 23#include <linux/of_pci.h>
24#include <linux/of_irq.h> 24#include <linux/of_irq.h>
25#include <linux/gpio/consumer.h>
25 26
26#include "pcie-designware.h" 27#include "pcie-designware.h"
27 28
@@ -29,6 +30,7 @@ struct armada8k_pcie {
29 struct dw_pcie *pci; 30 struct dw_pcie *pci;
30 struct clk *clk; 31 struct clk *clk;
31 struct clk *clk_reg; 32 struct clk *clk_reg;
33 struct gpio_desc *reset_gpio;
32}; 34};
33 35
34#define PCIE_VENDOR_REGS_OFFSET 0x8000 36#define PCIE_VENDOR_REGS_OFFSET 0x8000
@@ -137,6 +139,12 @@ static int armada8k_pcie_host_init(struct pcie_port *pp)
137 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); 139 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
138 struct armada8k_pcie *pcie = to_armada8k_pcie(pci); 140 struct armada8k_pcie *pcie = to_armada8k_pcie(pci);
139 141
142 if (pcie->reset_gpio) {
143 /* assert and then deassert the reset signal */
144 gpiod_set_value_cansleep(pcie->reset_gpio, 1);
145 msleep(100);
146 gpiod_set_value_cansleep(pcie->reset_gpio, 0);
147 }
140 dw_pcie_setup_rc(pp); 148 dw_pcie_setup_rc(pp);
141 armada8k_pcie_establish_link(pcie); 149 armada8k_pcie_establish_link(pcie);
142 150
@@ -249,6 +257,14 @@ static int armada8k_pcie_probe(struct platform_device *pdev)
249 goto fail_clkreg; 257 goto fail_clkreg;
250 } 258 }
251 259
260 /* Get reset gpio signal and hold asserted (logically high) */
261 pcie->reset_gpio = devm_gpiod_get_optional(dev, "reset",
262 GPIOD_OUT_HIGH);
263 if (IS_ERR(pcie->reset_gpio)) {
264 ret = PTR_ERR(pcie->reset_gpio);
265 goto fail_clkreg;
266 }
267
252 platform_set_drvdata(pdev, pcie); 268 platform_set_drvdata(pdev, pcie);
253 269
254 ret = armada8k_add_pcie_port(pcie, pdev); 270 ret = armada8k_add_pcie_port(pcie, pdev);
diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c
index 1e7b02221eac..880210366e71 100644
--- a/drivers/pci/controller/dwc/pcie-designware-ep.c
+++ b/drivers/pci/controller/dwc/pcie-designware-ep.c
@@ -504,6 +504,10 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
504 dev_err(dev, "dbi_base/dbi_base2 is not populated\n"); 504 dev_err(dev, "dbi_base/dbi_base2 is not populated\n");
505 return -EINVAL; 505 return -EINVAL;
506 } 506 }
507 if (pci->iatu_unroll_enabled && !pci->atu_base) {
508 dev_err(dev, "atu_base is not populated\n");
509 return -EINVAL;
510 }
507 511
508 ret = of_property_read_u32(np, "num-ib-windows", &ep->num_ib_windows); 512 ret = of_property_read_u32(np, "num-ib-windows", &ep->num_ib_windows);
509 if (ret < 0) { 513 if (ret < 0) {
diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index 29a05759a294..721d60a5d9e4 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -99,9 +99,6 @@ irqreturn_t dw_handle_msi_irq(struct pcie_port *pp)
99 (i * MAX_MSI_IRQS_PER_CTRL) + 99 (i * MAX_MSI_IRQS_PER_CTRL) +
100 pos); 100 pos);
101 generic_handle_irq(irq); 101 generic_handle_irq(irq);
102 dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_STATUS +
103 (i * MSI_REG_CTRL_BLOCK_SIZE),
104 4, 1 << pos);
105 pos++; 102 pos++;
106 } 103 }
107 } 104 }
@@ -168,8 +165,8 @@ static void dw_pci_bottom_mask(struct irq_data *data)
168 bit = data->hwirq % MAX_MSI_IRQS_PER_CTRL; 165 bit = data->hwirq % MAX_MSI_IRQS_PER_CTRL;
169 166
170 pp->irq_status[ctrl] &= ~(1 << bit); 167 pp->irq_status[ctrl] &= ~(1 << bit);
171 dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_ENABLE + res, 4, 168 dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
172 pp->irq_status[ctrl]); 169 ~pp->irq_status[ctrl]);
173 } 170 }
174 171
175 raw_spin_unlock_irqrestore(&pp->lock, flags); 172 raw_spin_unlock_irqrestore(&pp->lock, flags);
@@ -191,8 +188,8 @@ static void dw_pci_bottom_unmask(struct irq_data *data)
191 bit = data->hwirq % MAX_MSI_IRQS_PER_CTRL; 188 bit = data->hwirq % MAX_MSI_IRQS_PER_CTRL;
192 189
193 pp->irq_status[ctrl] |= 1 << bit; 190 pp->irq_status[ctrl] |= 1 << bit;
194 dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_ENABLE + res, 4, 191 dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
195 pp->irq_status[ctrl]); 192 ~pp->irq_status[ctrl]);
196 } 193 }
197 194
198 raw_spin_unlock_irqrestore(&pp->lock, flags); 195 raw_spin_unlock_irqrestore(&pp->lock, flags);
@@ -200,13 +197,22 @@ static void dw_pci_bottom_unmask(struct irq_data *data)
200 197
201static void dw_pci_bottom_ack(struct irq_data *d) 198static void dw_pci_bottom_ack(struct irq_data *d)
202{ 199{
203 struct msi_desc *msi = irq_data_get_msi_desc(d); 200 struct pcie_port *pp = irq_data_get_irq_chip_data(d);
204 struct pcie_port *pp; 201 unsigned int res, bit, ctrl;
202 unsigned long flags;
203
204 ctrl = d->hwirq / MAX_MSI_IRQS_PER_CTRL;
205 res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
206 bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
207
208 raw_spin_lock_irqsave(&pp->lock, flags);
205 209
206 pp = msi_desc_to_pci_sysdata(msi); 210 dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_STATUS + res, 4, 1 << bit);
207 211
208 if (pp->ops->msi_irq_ack) 212 if (pp->ops->msi_irq_ack)
209 pp->ops->msi_irq_ack(d->hwirq, pp); 213 pp->ops->msi_irq_ack(d->hwirq, pp);
214
215 raw_spin_unlock_irqrestore(&pp->lock, flags);
210} 216}
211 217
212static struct irq_chip dw_pci_msi_bottom_irq_chip = { 218static struct irq_chip dw_pci_msi_bottom_irq_chip = {
@@ -658,10 +664,15 @@ void dw_pcie_setup_rc(struct pcie_port *pp)
658 num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL; 664 num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
659 665
660 /* Initialize IRQ Status array */ 666 /* Initialize IRQ Status array */
661 for (ctrl = 0; ctrl < num_ctrls; ctrl++) 667 for (ctrl = 0; ctrl < num_ctrls; ctrl++) {
662 dw_pcie_rd_own_conf(pp, PCIE_MSI_INTR0_ENABLE + 668 dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK +
669 (ctrl * MSI_REG_CTRL_BLOCK_SIZE),
670 4, ~0);
671 dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_ENABLE +
663 (ctrl * MSI_REG_CTRL_BLOCK_SIZE), 672 (ctrl * MSI_REG_CTRL_BLOCK_SIZE),
664 4, &pp->irq_status[ctrl]); 673 4, ~0);
674 pp->irq_status[ctrl] = 0;
675 }
665 676
666 /* Setup RC BARs */ 677 /* Setup RC BARs */
667 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 0x00000004); 678 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 0x00000004);
@@ -699,6 +710,9 @@ void dw_pcie_setup_rc(struct pcie_port *pp)
699 dev_dbg(pci->dev, "iATU unroll: %s\n", 710 dev_dbg(pci->dev, "iATU unroll: %s\n",
700 pci->iatu_unroll_enabled ? "enabled" : "disabled"); 711 pci->iatu_unroll_enabled ? "enabled" : "disabled");
701 712
713 if (pci->iatu_unroll_enabled && !pci->atu_base)
714 pci->atu_base = pci->dbi_base + DEFAULT_DBI_ATU_OFFSET;
715
702 dw_pcie_prog_outbound_atu(pci, PCIE_ATU_REGION_INDEX0, 716 dw_pcie_prog_outbound_atu(pci, PCIE_ATU_REGION_INDEX0,
703 PCIE_ATU_TYPE_MEM, pp->mem_base, 717 PCIE_ATU_TYPE_MEM, pp->mem_base,
704 pp->mem_bus_addr, pp->mem_size); 718 pp->mem_bus_addr, pp->mem_size);
diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c
index 2153956a0b20..93ef8c31fb39 100644
--- a/drivers/pci/controller/dwc/pcie-designware.c
+++ b/drivers/pci/controller/dwc/pcie-designware.c
@@ -93,7 +93,7 @@ static u32 dw_pcie_readl_ob_unroll(struct dw_pcie *pci, u32 index, u32 reg)
93{ 93{
94 u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(index); 94 u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(index);
95 95
96 return dw_pcie_readl_dbi(pci, offset + reg); 96 return dw_pcie_readl_atu(pci, offset + reg);
97} 97}
98 98
99static void dw_pcie_writel_ob_unroll(struct dw_pcie *pci, u32 index, u32 reg, 99static void dw_pcie_writel_ob_unroll(struct dw_pcie *pci, u32 index, u32 reg,
@@ -101,7 +101,7 @@ static void dw_pcie_writel_ob_unroll(struct dw_pcie *pci, u32 index, u32 reg,
101{ 101{
102 u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(index); 102 u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(index);
103 103
104 dw_pcie_writel_dbi(pci, offset + reg, val); 104 dw_pcie_writel_atu(pci, offset + reg, val);
105} 105}
106 106
107static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index, 107static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index,
@@ -187,7 +187,7 @@ static u32 dw_pcie_readl_ib_unroll(struct dw_pcie *pci, u32 index, u32 reg)
187{ 187{
188 u32 offset = PCIE_GET_ATU_INB_UNR_REG_OFFSET(index); 188 u32 offset = PCIE_GET_ATU_INB_UNR_REG_OFFSET(index);
189 189
190 return dw_pcie_readl_dbi(pci, offset + reg); 190 return dw_pcie_readl_atu(pci, offset + reg);
191} 191}
192 192
193static void dw_pcie_writel_ib_unroll(struct dw_pcie *pci, u32 index, u32 reg, 193static void dw_pcie_writel_ib_unroll(struct dw_pcie *pci, u32 index, u32 reg,
@@ -195,7 +195,7 @@ static void dw_pcie_writel_ib_unroll(struct dw_pcie *pci, u32 index, u32 reg,
195{ 195{
196 u32 offset = PCIE_GET_ATU_INB_UNR_REG_OFFSET(index); 196 u32 offset = PCIE_GET_ATU_INB_UNR_REG_OFFSET(index);
197 197
198 dw_pcie_writel_dbi(pci, offset + reg, val); 198 dw_pcie_writel_atu(pci, offset + reg, val);
199} 199}
200 200
201static int dw_pcie_prog_inbound_atu_unroll(struct dw_pcie *pci, int index, 201static int dw_pcie_prog_inbound_atu_unroll(struct dw_pcie *pci, int index,
diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
index 0989d880ac46..9943d8c68335 100644
--- a/drivers/pci/controller/dwc/pcie-designware.h
+++ b/drivers/pci/controller/dwc/pcie-designware.h
@@ -92,12 +92,20 @@
92#define PCIE_ATU_UNR_LOWER_TARGET 0x14 92#define PCIE_ATU_UNR_LOWER_TARGET 0x14
93#define PCIE_ATU_UNR_UPPER_TARGET 0x18 93#define PCIE_ATU_UNR_UPPER_TARGET 0x18
94 94
95/*
96 * The default address offset between dbi_base and atu_base. Root controller
97 * drivers are not required to initialize atu_base if the offset matches this
98 * default; the driver core automatically derives atu_base from dbi_base using
99 * this offset, if atu_base not set.
100 */
101#define DEFAULT_DBI_ATU_OFFSET (0x3 << 20)
102
95/* Register address builder */ 103/* Register address builder */
96#define PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(region) \ 104#define PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(region) \
97 ((0x3 << 20) | ((region) << 9)) 105 ((region) << 9)
98 106
99#define PCIE_GET_ATU_INB_UNR_REG_OFFSET(region) \ 107#define PCIE_GET_ATU_INB_UNR_REG_OFFSET(region) \
100 ((0x3 << 20) | ((region) << 9) | (0x1 << 8)) 108 (((region) << 9) | (0x1 << 8))
101 109
102#define MAX_MSI_IRQS 256 110#define MAX_MSI_IRQS 256
103#define MAX_MSI_IRQS_PER_CTRL 32 111#define MAX_MSI_IRQS_PER_CTRL 32
@@ -219,6 +227,8 @@ struct dw_pcie {
219 struct device *dev; 227 struct device *dev;
220 void __iomem *dbi_base; 228 void __iomem *dbi_base;
221 void __iomem *dbi_base2; 229 void __iomem *dbi_base2;
230 /* Used when iatu_unroll_enabled is true */
231 void __iomem *atu_base;
222 u32 num_viewport; 232 u32 num_viewport;
223 u8 iatu_unroll_enabled; 233 u8 iatu_unroll_enabled;
224 struct pcie_port pp; 234 struct pcie_port pp;
@@ -289,6 +299,16 @@ static inline u32 dw_pcie_readl_dbi2(struct dw_pcie *pci, u32 reg)
289 return __dw_pcie_read_dbi(pci, pci->dbi_base2, reg, 0x4); 299 return __dw_pcie_read_dbi(pci, pci->dbi_base2, reg, 0x4);
290} 300}
291 301
302static inline void dw_pcie_writel_atu(struct dw_pcie *pci, u32 reg, u32 val)
303{
304 __dw_pcie_write_dbi(pci, pci->atu_base, reg, 0x4, val);
305}
306
307static inline u32 dw_pcie_readl_atu(struct dw_pcie *pci, u32 reg)
308{
309 return __dw_pcie_read_dbi(pci, pci->atu_base, reg, 0x4);
310}
311
292static inline void dw_pcie_dbi_ro_wr_en(struct dw_pcie *pci) 312static inline void dw_pcie_dbi_ro_wr_en(struct dw_pcie *pci)
293{ 313{
294 u32 reg; 314 u32 reg;
diff --git a/drivers/pci/controller/dwc/pcie-histb.c b/drivers/pci/controller/dwc/pcie-histb.c
index 7b32e619b959..954bc2b74bbc 100644
--- a/drivers/pci/controller/dwc/pcie-histb.c
+++ b/drivers/pci/controller/dwc/pcie-histb.c
@@ -202,7 +202,7 @@ static int histb_pcie_host_init(struct pcie_port *pp)
202 return 0; 202 return 0;
203} 203}
204 204
205static struct dw_pcie_host_ops histb_pcie_host_ops = { 205static const struct dw_pcie_host_ops histb_pcie_host_ops = {
206 .rd_own_conf = histb_pcie_rd_own_conf, 206 .rd_own_conf = histb_pcie_rd_own_conf,
207 .wr_own_conf = histb_pcie_wr_own_conf, 207 .wr_own_conf = histb_pcie_wr_own_conf,
208 .host_init = histb_pcie_host_init, 208 .host_init = histb_pcie_host_init,
diff --git a/drivers/pci/controller/dwc/pcie-uniphier.c b/drivers/pci/controller/dwc/pcie-uniphier.c
new file mode 100644
index 000000000000..d5dc40289cce
--- /dev/null
+++ b/drivers/pci/controller/dwc/pcie-uniphier.c
@@ -0,0 +1,471 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * PCIe host controller driver for UniPhier SoCs
4 * Copyright 2018 Socionext Inc.
5 * Author: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
6 */
7
8#include <linux/bitops.h>
9#include <linux/bitfield.h>
10#include <linux/clk.h>
11#include <linux/delay.h>
12#include <linux/interrupt.h>
13#include <linux/iopoll.h>
14#include <linux/irqchip/chained_irq.h>
15#include <linux/irqdomain.h>
16#include <linux/module.h>
17#include <linux/of_irq.h>
18#include <linux/pci.h>
19#include <linux/phy/phy.h>
20#include <linux/platform_device.h>
21#include <linux/reset.h>
22
23#include "pcie-designware.h"
24
25#define PCL_PINCTRL0 0x002c
26#define PCL_PERST_PLDN_REGEN BIT(12)
27#define PCL_PERST_NOE_REGEN BIT(11)
28#define PCL_PERST_OUT_REGEN BIT(8)
29#define PCL_PERST_PLDN_REGVAL BIT(4)
30#define PCL_PERST_NOE_REGVAL BIT(3)
31#define PCL_PERST_OUT_REGVAL BIT(0)
32
33#define PCL_PIPEMON 0x0044
34#define PCL_PCLK_ALIVE BIT(15)
35
36#define PCL_APP_READY_CTRL 0x8008
37#define PCL_APP_LTSSM_ENABLE BIT(0)
38
39#define PCL_APP_PM0 0x8078
40#define PCL_SYS_AUX_PWR_DET BIT(8)
41
42#define PCL_RCV_INT 0x8108
43#define PCL_RCV_INT_ALL_ENABLE GENMASK(20, 17)
44#define PCL_CFG_BW_MGT_STATUS BIT(4)
45#define PCL_CFG_LINK_AUTO_BW_STATUS BIT(3)
46#define PCL_CFG_AER_RC_ERR_MSI_STATUS BIT(2)
47#define PCL_CFG_PME_MSI_STATUS BIT(1)
48
49#define PCL_RCV_INTX 0x810c
50#define PCL_RCV_INTX_ALL_ENABLE GENMASK(19, 16)
51#define PCL_RCV_INTX_ALL_MASK GENMASK(11, 8)
52#define PCL_RCV_INTX_MASK_SHIFT 8
53#define PCL_RCV_INTX_ALL_STATUS GENMASK(3, 0)
54#define PCL_RCV_INTX_STATUS_SHIFT 0
55
56#define PCL_STATUS_LINK 0x8140
57#define PCL_RDLH_LINK_UP BIT(1)
58#define PCL_XMLH_LINK_UP BIT(0)
59
60struct uniphier_pcie_priv {
61 void __iomem *base;
62 struct dw_pcie pci;
63 struct clk *clk;
64 struct reset_control *rst;
65 struct phy *phy;
66 struct irq_domain *legacy_irq_domain;
67};
68
69#define to_uniphier_pcie(x) dev_get_drvdata((x)->dev)
70
71static void uniphier_pcie_ltssm_enable(struct uniphier_pcie_priv *priv,
72 bool enable)
73{
74 u32 val;
75
76 val = readl(priv->base + PCL_APP_READY_CTRL);
77 if (enable)
78 val |= PCL_APP_LTSSM_ENABLE;
79 else
80 val &= ~PCL_APP_LTSSM_ENABLE;
81 writel(val, priv->base + PCL_APP_READY_CTRL);
82}
83
84static void uniphier_pcie_init_rc(struct uniphier_pcie_priv *priv)
85{
86 u32 val;
87
88 /* use auxiliary power detection */
89 val = readl(priv->base + PCL_APP_PM0);
90 val |= PCL_SYS_AUX_PWR_DET;
91 writel(val, priv->base + PCL_APP_PM0);
92
93 /* assert PERST# */
94 val = readl(priv->base + PCL_PINCTRL0);
95 val &= ~(PCL_PERST_NOE_REGVAL | PCL_PERST_OUT_REGVAL
96 | PCL_PERST_PLDN_REGVAL);
97 val |= PCL_PERST_NOE_REGEN | PCL_PERST_OUT_REGEN
98 | PCL_PERST_PLDN_REGEN;
99 writel(val, priv->base + PCL_PINCTRL0);
100
101 uniphier_pcie_ltssm_enable(priv, false);
102
103 usleep_range(100000, 200000);
104
105 /* deassert PERST# */
106 val = readl(priv->base + PCL_PINCTRL0);
107 val |= PCL_PERST_OUT_REGVAL | PCL_PERST_OUT_REGEN;
108 writel(val, priv->base + PCL_PINCTRL0);
109}
110
111static int uniphier_pcie_wait_rc(struct uniphier_pcie_priv *priv)
112{
113 u32 status;
114 int ret;
115
116 /* wait PIPE clock */
117 ret = readl_poll_timeout(priv->base + PCL_PIPEMON, status,
118 status & PCL_PCLK_ALIVE, 100000, 1000000);
119 if (ret) {
120 dev_err(priv->pci.dev,
121 "Failed to initialize controller in RC mode\n");
122 return ret;
123 }
124
125 return 0;
126}
127
128static int uniphier_pcie_link_up(struct dw_pcie *pci)
129{
130 struct uniphier_pcie_priv *priv = to_uniphier_pcie(pci);
131 u32 val, mask;
132
133 val = readl(priv->base + PCL_STATUS_LINK);
134 mask = PCL_RDLH_LINK_UP | PCL_XMLH_LINK_UP;
135
136 return (val & mask) == mask;
137}
138
139static int uniphier_pcie_establish_link(struct dw_pcie *pci)
140{
141 struct uniphier_pcie_priv *priv = to_uniphier_pcie(pci);
142
143 if (dw_pcie_link_up(pci))
144 return 0;
145
146 uniphier_pcie_ltssm_enable(priv, true);
147
148 return dw_pcie_wait_for_link(pci);
149}
150
151static void uniphier_pcie_stop_link(struct dw_pcie *pci)
152{
153 struct uniphier_pcie_priv *priv = to_uniphier_pcie(pci);
154
155 uniphier_pcie_ltssm_enable(priv, false);
156}
157
158static void uniphier_pcie_irq_enable(struct uniphier_pcie_priv *priv)
159{
160 writel(PCL_RCV_INT_ALL_ENABLE, priv->base + PCL_RCV_INT);
161 writel(PCL_RCV_INTX_ALL_ENABLE, priv->base + PCL_RCV_INTX);
162}
163
164static void uniphier_pcie_irq_disable(struct uniphier_pcie_priv *priv)
165{
166 writel(0, priv->base + PCL_RCV_INT);
167 writel(0, priv->base + PCL_RCV_INTX);
168}
169
170static void uniphier_pcie_irq_ack(struct irq_data *d)
171{
172 struct pcie_port *pp = irq_data_get_irq_chip_data(d);
173 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
174 struct uniphier_pcie_priv *priv = to_uniphier_pcie(pci);
175 u32 val;
176
177 val = readl(priv->base + PCL_RCV_INTX);
178 val &= ~PCL_RCV_INTX_ALL_STATUS;
179 val |= BIT(irqd_to_hwirq(d) + PCL_RCV_INTX_STATUS_SHIFT);
180 writel(val, priv->base + PCL_RCV_INTX);
181}
182
183static void uniphier_pcie_irq_mask(struct irq_data *d)
184{
185 struct pcie_port *pp = irq_data_get_irq_chip_data(d);
186 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
187 struct uniphier_pcie_priv *priv = to_uniphier_pcie(pci);
188 u32 val;
189
190 val = readl(priv->base + PCL_RCV_INTX);
191 val &= ~PCL_RCV_INTX_ALL_MASK;
192 val |= BIT(irqd_to_hwirq(d) + PCL_RCV_INTX_MASK_SHIFT);
193 writel(val, priv->base + PCL_RCV_INTX);
194}
195
196static void uniphier_pcie_irq_unmask(struct irq_data *d)
197{
198 struct pcie_port *pp = irq_data_get_irq_chip_data(d);
199 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
200 struct uniphier_pcie_priv *priv = to_uniphier_pcie(pci);
201 u32 val;
202
203 val = readl(priv->base + PCL_RCV_INTX);
204 val &= ~PCL_RCV_INTX_ALL_MASK;
205 val &= ~BIT(irqd_to_hwirq(d) + PCL_RCV_INTX_MASK_SHIFT);
206 writel(val, priv->base + PCL_RCV_INTX);
207}
208
209static struct irq_chip uniphier_pcie_irq_chip = {
210 .name = "PCI",
211 .irq_ack = uniphier_pcie_irq_ack,
212 .irq_mask = uniphier_pcie_irq_mask,
213 .irq_unmask = uniphier_pcie_irq_unmask,
214};
215
216static int uniphier_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
217 irq_hw_number_t hwirq)
218{
219 irq_set_chip_and_handler(irq, &uniphier_pcie_irq_chip,
220 handle_level_irq);
221 irq_set_chip_data(irq, domain->host_data);
222
223 return 0;
224}
225
226static const struct irq_domain_ops uniphier_intx_domain_ops = {
227 .map = uniphier_pcie_intx_map,
228};
229
230static void uniphier_pcie_irq_handler(struct irq_desc *desc)
231{
232 struct pcie_port *pp = irq_desc_get_handler_data(desc);
233 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
234 struct uniphier_pcie_priv *priv = to_uniphier_pcie(pci);
235 struct irq_chip *chip = irq_desc_get_chip(desc);
236 unsigned long reg;
237 u32 val, bit, virq;
238
239 /* INT for debug */
240 val = readl(priv->base + PCL_RCV_INT);
241
242 if (val & PCL_CFG_BW_MGT_STATUS)
243 dev_dbg(pci->dev, "Link Bandwidth Management Event\n");
244 if (val & PCL_CFG_LINK_AUTO_BW_STATUS)
245 dev_dbg(pci->dev, "Link Autonomous Bandwidth Event\n");
246 if (val & PCL_CFG_AER_RC_ERR_MSI_STATUS)
247 dev_dbg(pci->dev, "Root Error\n");
248 if (val & PCL_CFG_PME_MSI_STATUS)
249 dev_dbg(pci->dev, "PME Interrupt\n");
250
251 writel(val, priv->base + PCL_RCV_INT);
252
253 /* INTx */
254 chained_irq_enter(chip, desc);
255
256 val = readl(priv->base + PCL_RCV_INTX);
257 reg = FIELD_GET(PCL_RCV_INTX_ALL_STATUS, val);
258
259 for_each_set_bit(bit, &reg, PCI_NUM_INTX) {
260 virq = irq_linear_revmap(priv->legacy_irq_domain, bit);
261 generic_handle_irq(virq);
262 }
263
264 chained_irq_exit(chip, desc);
265}
266
267static int uniphier_pcie_config_legacy_irq(struct pcie_port *pp)
268{
269 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
270 struct uniphier_pcie_priv *priv = to_uniphier_pcie(pci);
271 struct device_node *np = pci->dev->of_node;
272 struct device_node *np_intc;
273
274 np_intc = of_get_child_by_name(np, "legacy-interrupt-controller");
275 if (!np_intc) {
276 dev_err(pci->dev, "Failed to get legacy-interrupt-controller node\n");
277 return -EINVAL;
278 }
279
280 pp->irq = irq_of_parse_and_map(np_intc, 0);
281 if (!pp->irq) {
282 dev_err(pci->dev, "Failed to get an IRQ entry in legacy-interrupt-controller\n");
283 return -EINVAL;
284 }
285
286 priv->legacy_irq_domain = irq_domain_add_linear(np_intc, PCI_NUM_INTX,
287 &uniphier_intx_domain_ops, pp);
288 if (!priv->legacy_irq_domain) {
289 dev_err(pci->dev, "Failed to get INTx domain\n");
290 return -ENODEV;
291 }
292
293 irq_set_chained_handler_and_data(pp->irq, uniphier_pcie_irq_handler,
294 pp);
295
296 return 0;
297}
298
299static int uniphier_pcie_host_init(struct pcie_port *pp)
300{
301 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
302 struct uniphier_pcie_priv *priv = to_uniphier_pcie(pci);
303 int ret;
304
305 ret = uniphier_pcie_config_legacy_irq(pp);
306 if (ret)
307 return ret;
308
309 uniphier_pcie_irq_enable(priv);
310
311 dw_pcie_setup_rc(pp);
312 ret = uniphier_pcie_establish_link(pci);
313 if (ret)
314 return ret;
315
316 if (IS_ENABLED(CONFIG_PCI_MSI))
317 dw_pcie_msi_init(pp);
318
319 return 0;
320}
321
322static const struct dw_pcie_host_ops uniphier_pcie_host_ops = {
323 .host_init = uniphier_pcie_host_init,
324};
325
326static int uniphier_add_pcie_port(struct uniphier_pcie_priv *priv,
327 struct platform_device *pdev)
328{
329 struct dw_pcie *pci = &priv->pci;
330 struct pcie_port *pp = &pci->pp;
331 struct device *dev = &pdev->dev;
332 int ret;
333
334 pp->ops = &uniphier_pcie_host_ops;
335
336 if (IS_ENABLED(CONFIG_PCI_MSI)) {
337 pp->msi_irq = platform_get_irq_byname(pdev, "msi");
338 if (pp->msi_irq < 0)
339 return pp->msi_irq;
340 }
341
342 ret = dw_pcie_host_init(pp);
343 if (ret) {
344 dev_err(dev, "Failed to initialize host (%d)\n", ret);
345 return ret;
346 }
347
348 return 0;
349}
350
351static int uniphier_pcie_host_enable(struct uniphier_pcie_priv *priv)
352{
353 int ret;
354
355 ret = clk_prepare_enable(priv->clk);
356 if (ret)
357 return ret;
358
359 ret = reset_control_deassert(priv->rst);
360 if (ret)
361 goto out_clk_disable;
362
363 uniphier_pcie_init_rc(priv);
364
365 ret = phy_init(priv->phy);
366 if (ret)
367 goto out_rst_assert;
368
369 ret = uniphier_pcie_wait_rc(priv);
370 if (ret)
371 goto out_phy_exit;
372
373 return 0;
374
375out_phy_exit:
376 phy_exit(priv->phy);
377out_rst_assert:
378 reset_control_assert(priv->rst);
379out_clk_disable:
380 clk_disable_unprepare(priv->clk);
381
382 return ret;
383}
384
385static void uniphier_pcie_host_disable(struct uniphier_pcie_priv *priv)
386{
387 uniphier_pcie_irq_disable(priv);
388 phy_exit(priv->phy);
389 reset_control_assert(priv->rst);
390 clk_disable_unprepare(priv->clk);
391}
392
393static const struct dw_pcie_ops dw_pcie_ops = {
394 .start_link = uniphier_pcie_establish_link,
395 .stop_link = uniphier_pcie_stop_link,
396 .link_up = uniphier_pcie_link_up,
397};
398
399static int uniphier_pcie_probe(struct platform_device *pdev)
400{
401 struct device *dev = &pdev->dev;
402 struct uniphier_pcie_priv *priv;
403 struct resource *res;
404 int ret;
405
406 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
407 if (!priv)
408 return -ENOMEM;
409
410 priv->pci.dev = dev;
411 priv->pci.ops = &dw_pcie_ops;
412
413 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi");
414 priv->pci.dbi_base = devm_pci_remap_cfg_resource(dev, res);
415 if (IS_ERR(priv->pci.dbi_base))
416 return PTR_ERR(priv->pci.dbi_base);
417
418 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "link");
419 priv->base = devm_ioremap_resource(dev, res);
420 if (IS_ERR(priv->base))
421 return PTR_ERR(priv->base);
422
423 priv->clk = devm_clk_get(dev, NULL);
424 if (IS_ERR(priv->clk))
425 return PTR_ERR(priv->clk);
426
427 priv->rst = devm_reset_control_get_shared(dev, NULL);
428 if (IS_ERR(priv->rst))
429 return PTR_ERR(priv->rst);
430
431 priv->phy = devm_phy_optional_get(dev, "pcie-phy");
432 if (IS_ERR(priv->phy))
433 return PTR_ERR(priv->phy);
434
435 platform_set_drvdata(pdev, priv);
436
437 ret = uniphier_pcie_host_enable(priv);
438 if (ret)
439 return ret;
440
441 return uniphier_add_pcie_port(priv, pdev);
442}
443
444static int uniphier_pcie_remove(struct platform_device *pdev)
445{
446 struct uniphier_pcie_priv *priv = platform_get_drvdata(pdev);
447
448 uniphier_pcie_host_disable(priv);
449
450 return 0;
451}
452
453static const struct of_device_id uniphier_pcie_match[] = {
454 { .compatible = "socionext,uniphier-pcie", },
455 { /* sentinel */ },
456};
457MODULE_DEVICE_TABLE(of, uniphier_pcie_match);
458
459static struct platform_driver uniphier_pcie_driver = {
460 .probe = uniphier_pcie_probe,
461 .remove = uniphier_pcie_remove,
462 .driver = {
463 .name = "uniphier-pcie",
464 .of_match_table = uniphier_pcie_match,
465 },
466};
467builtin_platform_driver(uniphier_pcie_driver);
468
469MODULE_AUTHOR("Kunihiko Hayashi <hayashi.kunihiko@socionext.com>");
470MODULE_DESCRIPTION("UniPhier PCIe host controller driver");
471MODULE_LICENSE("GPL v2");
diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
index d069a76cbb95..55e471c18e8d 100644
--- a/drivers/pci/controller/pcie-mediatek.c
+++ b/drivers/pci/controller/pcie-mediatek.c
@@ -161,7 +161,6 @@ struct mtk_pcie_soc {
161 * @obff_ck: pointer to OBFF functional block operating clock 161 * @obff_ck: pointer to OBFF functional block operating clock
162 * @pipe_ck: pointer to LTSSM and PHY/MAC layer operating clock 162 * @pipe_ck: pointer to LTSSM and PHY/MAC layer operating clock
163 * @phy: pointer to PHY control block 163 * @phy: pointer to PHY control block
164 * @lane: lane count
165 * @slot: port slot 164 * @slot: port slot
166 * @irq: GIC irq 165 * @irq: GIC irq
167 * @irq_domain: legacy INTx IRQ domain 166 * @irq_domain: legacy INTx IRQ domain
@@ -182,7 +181,6 @@ struct mtk_pcie_port {
182 struct clk *obff_ck; 181 struct clk *obff_ck;
183 struct clk *pipe_ck; 182 struct clk *pipe_ck;
184 struct phy *phy; 183 struct phy *phy;
185 u32 lane;
186 u32 slot; 184 u32 slot;
187 int irq; 185 int irq;
188 struct irq_domain *irq_domain; 186 struct irq_domain *irq_domain;
@@ -197,29 +195,20 @@ struct mtk_pcie_port {
197 * @dev: pointer to PCIe device 195 * @dev: pointer to PCIe device
198 * @base: IO mapped register base 196 * @base: IO mapped register base
199 * @free_ck: free-run reference clock 197 * @free_ck: free-run reference clock
200 * @io: IO resource
201 * @pio: PIO resource
202 * @mem: non-prefetchable memory resource 198 * @mem: non-prefetchable memory resource
203 * @busn: bus range
204 * @offset: IO / Memory offset
205 * @ports: pointer to PCIe port information 199 * @ports: pointer to PCIe port information
206 * @soc: pointer to SoC-dependent operations 200 * @soc: pointer to SoC-dependent operations
201 * @busnr: root bus number
207 */ 202 */
208struct mtk_pcie { 203struct mtk_pcie {
209 struct device *dev; 204 struct device *dev;
210 void __iomem *base; 205 void __iomem *base;
211 struct clk *free_ck; 206 struct clk *free_ck;
212 207
213 struct resource io;
214 struct resource pio;
215 struct resource mem; 208 struct resource mem;
216 struct resource busn;
217 struct {
218 resource_size_t mem;
219 resource_size_t io;
220 } offset;
221 struct list_head ports; 209 struct list_head ports;
222 const struct mtk_pcie_soc *soc; 210 const struct mtk_pcie_soc *soc;
211 unsigned int busnr;
223}; 212};
224 213
225static void mtk_pcie_subsys_powerdown(struct mtk_pcie *pcie) 214static void mtk_pcie_subsys_powerdown(struct mtk_pcie *pcie)
@@ -904,12 +893,6 @@ static int mtk_pcie_parse_port(struct mtk_pcie *pcie,
904 if (!port) 893 if (!port)
905 return -ENOMEM; 894 return -ENOMEM;
906 895
907 err = of_property_read_u32(node, "num-lanes", &port->lane);
908 if (err) {
909 dev_err(dev, "missing num-lanes property\n");
910 return err;
911 }
912
913 snprintf(name, sizeof(name), "port%d", slot); 896 snprintf(name, sizeof(name), "port%d", slot);
914 regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, name); 897 regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
915 port->base = devm_ioremap_resource(dev, regs); 898 port->base = devm_ioremap_resource(dev, regs);
@@ -1045,55 +1028,43 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)
1045{ 1028{
1046 struct device *dev = pcie->dev; 1029 struct device *dev = pcie->dev;
1047 struct device_node *node = dev->of_node, *child; 1030 struct device_node *node = dev->of_node, *child;
1048 struct of_pci_range_parser parser;
1049 struct of_pci_range range;
1050 struct resource res;
1051 struct mtk_pcie_port *port, *tmp; 1031 struct mtk_pcie_port *port, *tmp;
1032 struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
1033 struct list_head *windows = &host->windows;
1034 struct resource_entry *win, *tmp_win;
1035 resource_size_t io_base;
1052 int err; 1036 int err;
1053 1037
1054 if (of_pci_range_parser_init(&parser, node)) { 1038 err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
1055 dev_err(dev, "missing \"ranges\" property\n"); 1039 windows, &io_base);
1056 return -EINVAL; 1040 if (err)
1057 } 1041 return err;
1058 1042
1059 for_each_of_pci_range(&parser, &range) { 1043 err = devm_request_pci_bus_resources(dev, windows);
1060 err = of_pci_range_to_resource(&range, node, &res); 1044 if (err < 0)
1061 if (err < 0) 1045 return err;
1062 return err;
1063 1046
1064 switch (res.flags & IORESOURCE_TYPE_BITS) { 1047 /* Get the I/O and memory ranges from DT */
1048 resource_list_for_each_entry_safe(win, tmp_win, windows) {
1049 switch (resource_type(win->res)) {
1065 case IORESOURCE_IO: 1050 case IORESOURCE_IO:
1066 pcie->offset.io = res.start - range.pci_addr; 1051 err = devm_pci_remap_iospace(dev, win->res, io_base);
1067 1052 if (err) {
1068 memcpy(&pcie->pio, &res, sizeof(res)); 1053 dev_warn(dev, "error %d: failed to map resource %pR\n",
1069 pcie->pio.name = node->full_name; 1054 err, win->res);
1070 1055 resource_list_destroy_entry(win);
1071 pcie->io.start = range.cpu_addr; 1056 }
1072 pcie->io.end = range.cpu_addr + range.size - 1;
1073 pcie->io.flags = IORESOURCE_MEM;
1074 pcie->io.name = "I/O";
1075
1076 memcpy(&res, &pcie->io, sizeof(res));
1077 break; 1057 break;
1078
1079 case IORESOURCE_MEM: 1058 case IORESOURCE_MEM:
1080 pcie->offset.mem = res.start - range.pci_addr; 1059 memcpy(&pcie->mem, win->res, sizeof(*win->res));
1081
1082 memcpy(&pcie->mem, &res, sizeof(res));
1083 pcie->mem.name = "non-prefetchable"; 1060 pcie->mem.name = "non-prefetchable";
1084 break; 1061 break;
1062 case IORESOURCE_BUS:
1063 pcie->busnr = win->res->start;
1064 break;
1085 } 1065 }
1086 } 1066 }
1087 1067
1088 err = of_pci_parse_bus_range(node, &pcie->busn);
1089 if (err < 0) {
1090 dev_err(dev, "failed to parse bus ranges property: %d\n", err);
1091 pcie->busn.name = node->name;
1092 pcie->busn.start = 0;
1093 pcie->busn.end = 0xff;
1094 pcie->busn.flags = IORESOURCE_BUS;
1095 }
1096
1097 for_each_available_child_of_node(node, child) { 1068 for_each_available_child_of_node(node, child) {
1098 int slot; 1069 int slot;
1099 1070
@@ -1125,28 +1096,6 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)
1125 return 0; 1096 return 0;
1126} 1097}
1127 1098
1128static int mtk_pcie_request_resources(struct mtk_pcie *pcie)
1129{
1130 struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
1131 struct list_head *windows = &host->windows;
1132 struct device *dev = pcie->dev;
1133 int err;
1134
1135 pci_add_resource_offset(windows, &pcie->pio, pcie->offset.io);
1136 pci_add_resource_offset(windows, &pcie->mem, pcie->offset.mem);
1137 pci_add_resource(windows, &pcie->busn);
1138
1139 err = devm_request_pci_bus_resources(dev, windows);
1140 if (err < 0)
1141 return err;
1142
1143 err = devm_pci_remap_iospace(dev, &pcie->pio, pcie->io.start);
1144 if (err)
1145 return err;
1146
1147 return 0;
1148}
1149
1150static int mtk_pcie_probe(struct platform_device *pdev) 1099static int mtk_pcie_probe(struct platform_device *pdev)
1151{ 1100{
1152 struct device *dev = &pdev->dev; 1101 struct device *dev = &pdev->dev;
@@ -1169,11 +1118,7 @@ static int mtk_pcie_probe(struct platform_device *pdev)
1169 if (err) 1118 if (err)
1170 return err; 1119 return err;
1171 1120
1172 err = mtk_pcie_request_resources(pcie); 1121 host->busnr = pcie->busnr;
1173 if (err)
1174 goto put_resources;
1175
1176 host->busnr = pcie->busn.start;
1177 host->dev.parent = pcie->dev; 1122 host->dev.parent = pcie->dev;
1178 host->ops = pcie->soc->ops; 1123 host->ops = pcie->soc->ops;
1179 host->map_irq = of_irq_parse_and_map_pci; 1124 host->map_irq = of_irq_parse_and_map_pci;
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 9616eca3182f..3aa115ed3a65 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -252,6 +252,27 @@ int __weak pcibios_sriov_disable(struct pci_dev *pdev)
252 return 0; 252 return 0;
253} 253}
254 254
255static int sriov_add_vfs(struct pci_dev *dev, u16 num_vfs)
256{
257 unsigned int i;
258 int rc;
259
260 if (dev->no_vf_scan)
261 return 0;
262
263 for (i = 0; i < num_vfs; i++) {
264 rc = pci_iov_add_virtfn(dev, i);
265 if (rc)
266 goto failed;
267 }
268 return 0;
269failed:
270 while (i--)
271 pci_iov_remove_virtfn(dev, i);
272
273 return rc;
274}
275
255static int sriov_enable(struct pci_dev *dev, int nr_virtfn) 276static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
256{ 277{
257 int rc; 278 int rc;
@@ -337,21 +358,15 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
337 msleep(100); 358 msleep(100);
338 pci_cfg_access_unlock(dev); 359 pci_cfg_access_unlock(dev);
339 360
340 for (i = 0; i < initial; i++) { 361 rc = sriov_add_vfs(dev, initial);
341 rc = pci_iov_add_virtfn(dev, i); 362 if (rc)
342 if (rc) 363 goto err_pcibios;
343 goto failed;
344 }
345 364
346 kobject_uevent(&dev->dev.kobj, KOBJ_CHANGE); 365 kobject_uevent(&dev->dev.kobj, KOBJ_CHANGE);
347 iov->num_VFs = nr_virtfn; 366 iov->num_VFs = nr_virtfn;
348 367
349 return 0; 368 return 0;
350 369
351failed:
352 while (i--)
353 pci_iov_remove_virtfn(dev, i);
354
355err_pcibios: 370err_pcibios:
356 iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE); 371 iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE);
357 pci_cfg_access_lock(dev); 372 pci_cfg_access_lock(dev);
@@ -368,17 +383,26 @@ err_pcibios:
368 return rc; 383 return rc;
369} 384}
370 385
371static void sriov_disable(struct pci_dev *dev) 386static void sriov_del_vfs(struct pci_dev *dev)
372{ 387{
373 int i;
374 struct pci_sriov *iov = dev->sriov; 388 struct pci_sriov *iov = dev->sriov;
389 int i;
375 390
376 if (!iov->num_VFs) 391 if (dev->no_vf_scan)
377 return; 392 return;
378 393
379 for (i = 0; i < iov->num_VFs; i++) 394 for (i = 0; i < iov->num_VFs; i++)
380 pci_iov_remove_virtfn(dev, i); 395 pci_iov_remove_virtfn(dev, i);
396}
397
398static void sriov_disable(struct pci_dev *dev)
399{
400 struct pci_sriov *iov = dev->sriov;
401
402 if (!iov->num_VFs)
403 return;
381 404
405 sriov_del_vfs(dev);
382 iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE); 406 iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE);
383 pci_cfg_access_lock(dev); 407 pci_cfg_access_lock(dev);
384 pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); 408 pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl);
diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
index ae3c5b25dcc7..c25a69fc4fc7 100644
--- a/drivers/pci/p2pdma.c
+++ b/drivers/pci/p2pdma.c
@@ -422,7 +422,7 @@ static int upstream_bridge_distance_warn(struct pci_dev *provider,
422 * 422 *
423 * Returns -1 if any of the clients are not compatible (behind the same 423 * Returns -1 if any of the clients are not compatible (behind the same
424 * root port as the provider), otherwise returns a positive number where 424 * root port as the provider), otherwise returns a positive number where
425 * a lower number is the preferrable choice. (If there's one client 425 * a lower number is the preferable choice. (If there's one client
426 * that's the same as the provider it will return 0, which is best choice). 426 * that's the same as the provider it will return 0, which is best choice).
427 * 427 *
428 * For now, "compatible" means the provider and the clients are all behind 428 * For now, "compatible" means the provider and the clients are all behind
@@ -493,7 +493,7 @@ EXPORT_SYMBOL_GPL(pci_has_p2pmem);
493 * @num_clients: number of client devices in the list 493 * @num_clients: number of client devices in the list
494 * 494 *
495 * If multiple devices are behind the same switch, the one "closest" to the 495 * If multiple devices are behind the same switch, the one "closest" to the
496 * client devices in use will be chosen first. (So if one of the providers are 496 * client devices in use will be chosen first. (So if one of the providers is
497 * the same as one of the clients, that provider will be used ahead of any 497 * the same as one of the clients, that provider will be used ahead of any
498 * other providers that are unrelated). If multiple providers are an equal 498 * other providers that are unrelated). If multiple providers are an equal
499 * distance away, one will be chosen at random. 499 * distance away, one will be chosen at random.
@@ -580,7 +580,7 @@ EXPORT_SYMBOL_GPL(pci_alloc_p2pmem);
580 * pci_free_p2pmem - free peer-to-peer DMA memory 580 * pci_free_p2pmem - free peer-to-peer DMA memory
581 * @pdev: the device the memory was allocated from 581 * @pdev: the device the memory was allocated from
582 * @addr: address of the memory that was allocated 582 * @addr: address of the memory that was allocated
583 * @size: number of bytes that was allocated 583 * @size: number of bytes that were allocated
584 */ 584 */
585void pci_free_p2pmem(struct pci_dev *pdev, void *addr, size_t size) 585void pci_free_p2pmem(struct pci_dev *pdev, void *addr, size_t size)
586{ 586{
@@ -617,7 +617,7 @@ EXPORT_SYMBOL_GPL(pci_p2pmem_virt_to_bus);
617 * @nents: the number of SG entries in the list 617 * @nents: the number of SG entries in the list
618 * @length: number of bytes to allocate 618 * @length: number of bytes to allocate
619 * 619 *
620 * Returns 0 on success 620 * Return: %NULL on error or &struct scatterlist pointer and @nents on success
621 */ 621 */
622struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev, 622struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev,
623 unsigned int *nents, u32 length) 623 unsigned int *nents, u32 length)
@@ -673,7 +673,7 @@ EXPORT_SYMBOL_GPL(pci_p2pmem_free_sgl);
673 * 673 *
674 * Published memory can be used by other PCI device drivers for 674 * Published memory can be used by other PCI device drivers for
675 * peer-2-peer DMA operations. Non-published memory is reserved for 675 * peer-2-peer DMA operations. Non-published memory is reserved for
676 * exlusive use of the device driver that registers the peer-to-peer 676 * exclusive use of the device driver that registers the peer-to-peer
677 * memory. 677 * memory.
678 */ 678 */
679void pci_p2pmem_publish(struct pci_dev *pdev, bool publish) 679void pci_p2pmem_publish(struct pci_dev *pdev, bool publish)
@@ -733,7 +733,7 @@ EXPORT_SYMBOL_GPL(pci_p2pdma_map_sg);
733 * @use_p2pdma: returns whether to enable p2pdma or not 733 * @use_p2pdma: returns whether to enable p2pdma or not
734 * 734 *
735 * Parses an attribute value to decide whether to enable p2pdma. 735 * Parses an attribute value to decide whether to enable p2pdma.
736 * The value can select a PCI device (using it's full BDF device 736 * The value can select a PCI device (using its full BDF device
737 * name) or a boolean (in any format strtobool() accepts). A false 737 * name) or a boolean (in any format strtobool() accepts). A false
738 * value disables p2pdma, a true value expects the caller 738 * value disables p2pdma, a true value expects the caller
739 * to automatically find a compatible device and specifying a PCI device 739 * to automatically find a compatible device and specifying a PCI device
@@ -784,7 +784,7 @@ EXPORT_SYMBOL_GPL(pci_p2pdma_enable_store);
784 * whether p2pdma is enabled 784 * whether p2pdma is enabled
785 * @page: contents of the stored value 785 * @page: contents of the stored value
786 * @p2p_dev: the selected p2p device (NULL if no device is selected) 786 * @p2p_dev: the selected p2p device (NULL if no device is selected)
787 * @use_p2pdma: whether p2pdme has been enabled 787 * @use_p2pdma: whether p2pdma has been enabled
788 * 788 *
789 * Attributes that use pci_p2pdma_enable_store() should use this function 789 * Attributes that use pci_p2pdma_enable_store() should use this function
790 * to show the value of the attribute. 790 * to show the value of the attribute.
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index bef17c3fca67..33f3f475e5c6 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -1251,30 +1251,29 @@ static int pci_pm_runtime_suspend(struct device *dev)
1251 return 0; 1251 return 0;
1252 } 1252 }
1253 1253
1254 if (!pm || !pm->runtime_suspend)
1255 return -ENOSYS;
1256
1257 pci_dev->state_saved = false; 1254 pci_dev->state_saved = false;
1258 error = pm->runtime_suspend(dev); 1255 if (pm && pm->runtime_suspend) {
1259 if (error) { 1256 error = pm->runtime_suspend(dev);
1260 /* 1257 /*
1261 * -EBUSY and -EAGAIN is used to request the runtime PM core 1258 * -EBUSY and -EAGAIN is used to request the runtime PM core
1262 * to schedule a new suspend, so log the event only with debug 1259 * to schedule a new suspend, so log the event only with debug
1263 * log level. 1260 * log level.
1264 */ 1261 */
1265 if (error == -EBUSY || error == -EAGAIN) 1262 if (error == -EBUSY || error == -EAGAIN) {
1266 dev_dbg(dev, "can't suspend now (%pf returned %d)\n", 1263 dev_dbg(dev, "can't suspend now (%pf returned %d)\n",
1267 pm->runtime_suspend, error); 1264 pm->runtime_suspend, error);
1268 else 1265 return error;
1266 } else if (error) {
1269 dev_err(dev, "can't suspend (%pf returned %d)\n", 1267 dev_err(dev, "can't suspend (%pf returned %d)\n",
1270 pm->runtime_suspend, error); 1268 pm->runtime_suspend, error);
1271 1269 return error;
1272 return error; 1270 }
1273 } 1271 }
1274 1272
1275 pci_fixup_device(pci_fixup_suspend, pci_dev); 1273 pci_fixup_device(pci_fixup_suspend, pci_dev);
1276 1274
1277 if (!pci_dev->state_saved && pci_dev->current_state != PCI_D0 1275 if (pm && pm->runtime_suspend
1276 && !pci_dev->state_saved && pci_dev->current_state != PCI_D0
1278 && pci_dev->current_state != PCI_UNKNOWN) { 1277 && pci_dev->current_state != PCI_UNKNOWN) {
1279 WARN_ONCE(pci_dev->current_state != prev, 1278 WARN_ONCE(pci_dev->current_state != prev,
1280 "PCI PM: State of device not saved by %pF\n", 1279 "PCI PM: State of device not saved by %pF\n",
@@ -1292,7 +1291,7 @@ static int pci_pm_runtime_suspend(struct device *dev)
1292 1291
1293static int pci_pm_runtime_resume(struct device *dev) 1292static int pci_pm_runtime_resume(struct device *dev)
1294{ 1293{
1295 int rc; 1294 int rc = 0;
1296 struct pci_dev *pci_dev = to_pci_dev(dev); 1295 struct pci_dev *pci_dev = to_pci_dev(dev);
1297 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 1296 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1298 1297
@@ -1306,14 +1305,12 @@ static int pci_pm_runtime_resume(struct device *dev)
1306 if (!pci_dev->driver) 1305 if (!pci_dev->driver)
1307 return 0; 1306 return 0;
1308 1307
1309 if (!pm || !pm->runtime_resume)
1310 return -ENOSYS;
1311
1312 pci_fixup_device(pci_fixup_resume_early, pci_dev); 1308 pci_fixup_device(pci_fixup_resume_early, pci_dev);
1313 pci_enable_wake(pci_dev, PCI_D0, false); 1309 pci_enable_wake(pci_dev, PCI_D0, false);
1314 pci_fixup_device(pci_fixup_resume, pci_dev); 1310 pci_fixup_device(pci_fixup_resume, pci_dev);
1315 1311
1316 rc = pm->runtime_resume(dev); 1312 if (pm && pm->runtime_resume)
1313 rc = pm->runtime_resume(dev);
1317 1314
1318 pci_dev->runtime_d3cold = false; 1315 pci_dev->runtime_d3cold = false;
1319 1316
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 662b7457db23..224d88634115 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -2,6 +2,8 @@
2#ifndef DRIVERS_PCI_H 2#ifndef DRIVERS_PCI_H
3#define DRIVERS_PCI_H 3#define DRIVERS_PCI_H
4 4
5#include <linux/pci.h>
6
5#define PCI_FIND_CAP_TTL 48 7#define PCI_FIND_CAP_TTL 48
6 8
7#define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */ 9#define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */
diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index dcb29cb76dc6..2330ebf6df72 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -53,8 +53,6 @@ struct pcie_link_state {
53 struct pcie_link_state *root; /* pointer to the root port link */ 53 struct pcie_link_state *root; /* pointer to the root port link */
54 struct pcie_link_state *parent; /* pointer to the parent Link state */ 54 struct pcie_link_state *parent; /* pointer to the parent Link state */
55 struct list_head sibling; /* node in link_list */ 55 struct list_head sibling; /* node in link_list */
56 struct list_head children; /* list of child link states */
57 struct list_head link; /* node in parent's children list */
58 56
59 /* ASPM state */ 57 /* ASPM state */
60 u32 aspm_support:7; /* Supported ASPM state */ 58 u32 aspm_support:7; /* Supported ASPM state */
@@ -850,8 +848,6 @@ static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev)
850 return NULL; 848 return NULL;
851 849
852 INIT_LIST_HEAD(&link->sibling); 850 INIT_LIST_HEAD(&link->sibling);
853 INIT_LIST_HEAD(&link->children);
854 INIT_LIST_HEAD(&link->link);
855 link->pdev = pdev; 851 link->pdev = pdev;
856 link->downstream = pci_function_0(pdev->subordinate); 852 link->downstream = pci_function_0(pdev->subordinate);
857 853
@@ -877,7 +873,6 @@ static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev)
877 873
878 link->parent = parent; 874 link->parent = parent;
879 link->root = link->parent->root; 875 link->root = link->parent->root;
880 list_add(&link->link, &parent->children);
881 } 876 }
882 877
883 list_add(&link->sibling, &link_list); 878 list_add(&link->sibling, &link_list);
@@ -1001,7 +996,6 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev)
1001 /* All functions are removed, so just disable ASPM for the link */ 996 /* All functions are removed, so just disable ASPM for the link */
1002 pcie_config_aspm_link(link, 0); 997 pcie_config_aspm_link(link, 0);
1003 list_del(&link->sibling); 998 list_del(&link->sibling);
1004 list_del(&link->link);
1005 /* Clock PM is for endpoint device */ 999 /* Clock PM is for endpoint device */
1006 free_link_state(link); 1000 free_link_state(link);
1007 1001
diff --git a/drivers/pci/pcie/portdrv.h b/drivers/pci/pcie/portdrv.h
index e495f04394d0..fbbf00b0992e 100644
--- a/drivers/pci/pcie/portdrv.h
+++ b/drivers/pci/pcie/portdrv.h
@@ -71,19 +71,19 @@ static inline void *get_service_data(struct pcie_device *dev)
71 71
72struct pcie_port_service_driver { 72struct pcie_port_service_driver {
73 const char *name; 73 const char *name;
74 int (*probe) (struct pcie_device *dev); 74 int (*probe)(struct pcie_device *dev);
75 void (*remove) (struct pcie_device *dev); 75 void (*remove)(struct pcie_device *dev);
76 int (*suspend) (struct pcie_device *dev); 76 int (*suspend)(struct pcie_device *dev);
77 int (*resume_noirq) (struct pcie_device *dev); 77 int (*resume_noirq)(struct pcie_device *dev);
78 int (*resume) (struct pcie_device *dev); 78 int (*resume)(struct pcie_device *dev);
79 int (*runtime_suspend) (struct pcie_device *dev); 79 int (*runtime_suspend)(struct pcie_device *dev);
80 int (*runtime_resume) (struct pcie_device *dev); 80 int (*runtime_resume)(struct pcie_device *dev);
81 81
82 /* Device driver may resume normal operations */ 82 /* Device driver may resume normal operations */
83 void (*error_resume)(struct pci_dev *dev); 83 void (*error_resume)(struct pci_dev *dev);
84 84
85 /* Link Reset Capability - AER service driver specific */ 85 /* Link Reset Capability - AER service driver specific */
86 pci_ers_result_t (*reset_link) (struct pci_dev *dev); 86 pci_ers_result_t (*reset_link)(struct pci_dev *dev);
87 87
88 int port_type; /* Type of the port this driver can handle */ 88 int port_type; /* Type of the port this driver can handle */
89 u32 service; /* Port service this device represents */ 89 u32 service; /* Port service this device represents */
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 4700d24e5d55..b0a413f3f7ca 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -619,6 +619,30 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB,
619 quirk_amd_nl_class); 619 quirk_amd_nl_class);
620 620
621/* 621/*
622 * Synopsys USB 3.x host HAPS platform has a class code of
623 * PCI_CLASS_SERIAL_USB_XHCI, and xhci driver can claim it. However, these
624 * devices should use dwc3-haps driver. Change these devices' class code to
625 * PCI_CLASS_SERIAL_USB_DEVICE to prevent the xhci-pci driver from claiming
626 * them.
627 */
628static void quirk_synopsys_haps(struct pci_dev *pdev)
629{
630 u32 class = pdev->class;
631
632 switch (pdev->device) {
633 case PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3:
634 case PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI:
635 case PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31:
636 pdev->class = PCI_CLASS_SERIAL_USB_DEVICE;
637 pci_info(pdev, "PCI class overridden (%#08x -> %#08x) so dwc3 driver can claim this instead of xhci\n",
638 class, pdev->class);
639 break;
640 }
641}
642DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SYNOPSYS, PCI_ANY_ID,
643 quirk_synopsys_haps);
644
645/*
622 * Let's make the southbridge information explicit instead of having to 646 * Let's make the southbridge information explicit instead of having to
623 * worry about people probing the ACPI areas, for example.. (Yes, it 647 * worry about people probing the ACPI areas, for example.. (Yes, it
624 * happens, and if you read the wrong ACPI register it will put the machine 648 * happens, and if you read the wrong ACPI register it will put the machine
diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c
index 54a8b30dda38..6c5536d3d42a 100644
--- a/drivers/pci/switch/switchtec.c
+++ b/drivers/pci/switch/switchtec.c
@@ -13,7 +13,7 @@
13#include <linux/uaccess.h> 13#include <linux/uaccess.h>
14#include <linux/poll.h> 14#include <linux/poll.h>
15#include <linux/wait.h> 15#include <linux/wait.h>
16 16#include <linux/io-64-nonatomic-lo-hi.h>
17#include <linux/nospec.h> 17#include <linux/nospec.h>
18 18
19MODULE_DESCRIPTION("Microsemi Switchtec(tm) PCIe Management Driver"); 19MODULE_DESCRIPTION("Microsemi Switchtec(tm) PCIe Management Driver");
@@ -25,6 +25,11 @@ static int max_devices = 16;
25module_param(max_devices, int, 0644); 25module_param(max_devices, int, 0644);
26MODULE_PARM_DESC(max_devices, "max number of switchtec device instances"); 26MODULE_PARM_DESC(max_devices, "max number of switchtec device instances");
27 27
28static bool use_dma_mrpc = 1;
29module_param(use_dma_mrpc, bool, 0644);
30MODULE_PARM_DESC(use_dma_mrpc,
31 "Enable the use of the DMA MRPC feature");
32
28static dev_t switchtec_devt; 33static dev_t switchtec_devt;
29static DEFINE_IDA(switchtec_minor_ida); 34static DEFINE_IDA(switchtec_minor_ida);
30 35
@@ -113,6 +118,19 @@ static void stuser_set_state(struct switchtec_user *stuser,
113 118
114static void mrpc_complete_cmd(struct switchtec_dev *stdev); 119static void mrpc_complete_cmd(struct switchtec_dev *stdev);
115 120
121static void flush_wc_buf(struct switchtec_dev *stdev)
122{
123 struct ntb_dbmsg_regs __iomem *mmio_dbmsg;
124
125 /*
126 * odb (outbound doorbell) register is processed by low latency
127 * hardware and w/o side effect
128 */
129 mmio_dbmsg = (void __iomem *)stdev->mmio_ntb +
130 SWITCHTEC_NTB_REG_DBMSG_OFFSET;
131 ioread32(&mmio_dbmsg->odb);
132}
133
116static void mrpc_cmd_submit(struct switchtec_dev *stdev) 134static void mrpc_cmd_submit(struct switchtec_dev *stdev)
117{ 135{
118 /* requires the mrpc_mutex to already be held when called */ 136 /* requires the mrpc_mutex to already be held when called */
@@ -128,16 +146,18 @@ static void mrpc_cmd_submit(struct switchtec_dev *stdev)
128 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user, 146 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user,
129 list); 147 list);
130 148
149 if (stdev->dma_mrpc) {
150 stdev->dma_mrpc->status = SWITCHTEC_MRPC_STATUS_INPROGRESS;
151 memset(stdev->dma_mrpc->data, 0xFF, SWITCHTEC_MRPC_PAYLOAD_SIZE);
152 }
153
131 stuser_set_state(stuser, MRPC_RUNNING); 154 stuser_set_state(stuser, MRPC_RUNNING);
132 stdev->mrpc_busy = 1; 155 stdev->mrpc_busy = 1;
133 memcpy_toio(&stdev->mmio_mrpc->input_data, 156 memcpy_toio(&stdev->mmio_mrpc->input_data,
134 stuser->data, stuser->data_len); 157 stuser->data, stuser->data_len);
158 flush_wc_buf(stdev);
135 iowrite32(stuser->cmd, &stdev->mmio_mrpc->cmd); 159 iowrite32(stuser->cmd, &stdev->mmio_mrpc->cmd);
136 160
137 stuser->status = ioread32(&stdev->mmio_mrpc->status);
138 if (stuser->status != SWITCHTEC_MRPC_STATUS_INPROGRESS)
139 mrpc_complete_cmd(stdev);
140
141 schedule_delayed_work(&stdev->mrpc_timeout, 161 schedule_delayed_work(&stdev->mrpc_timeout,
142 msecs_to_jiffies(500)); 162 msecs_to_jiffies(500));
143} 163}
@@ -170,7 +190,11 @@ static void mrpc_complete_cmd(struct switchtec_dev *stdev)
170 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user, 190 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user,
171 list); 191 list);
172 192
173 stuser->status = ioread32(&stdev->mmio_mrpc->status); 193 if (stdev->dma_mrpc)
194 stuser->status = stdev->dma_mrpc->status;
195 else
196 stuser->status = ioread32(&stdev->mmio_mrpc->status);
197
174 if (stuser->status == SWITCHTEC_MRPC_STATUS_INPROGRESS) 198 if (stuser->status == SWITCHTEC_MRPC_STATUS_INPROGRESS)
175 return; 199 return;
176 200
@@ -180,13 +204,19 @@ static void mrpc_complete_cmd(struct switchtec_dev *stdev)
180 if (stuser->status != SWITCHTEC_MRPC_STATUS_DONE) 204 if (stuser->status != SWITCHTEC_MRPC_STATUS_DONE)
181 goto out; 205 goto out;
182 206
183 stuser->return_code = ioread32(&stdev->mmio_mrpc->ret_value); 207 if (stdev->dma_mrpc)
208 stuser->return_code = stdev->dma_mrpc->rtn_code;
209 else
210 stuser->return_code = ioread32(&stdev->mmio_mrpc->ret_value);
184 if (stuser->return_code != 0) 211 if (stuser->return_code != 0)
185 goto out; 212 goto out;
186 213
187 memcpy_fromio(stuser->data, &stdev->mmio_mrpc->output_data, 214 if (stdev->dma_mrpc)
188 stuser->read_len); 215 memcpy(stuser->data, &stdev->dma_mrpc->data,
189 216 stuser->read_len);
217 else
218 memcpy_fromio(stuser->data, &stdev->mmio_mrpc->output_data,
219 stuser->read_len);
190out: 220out:
191 complete_all(&stuser->comp); 221 complete_all(&stuser->comp);
192 list_del_init(&stuser->list); 222 list_del_init(&stuser->list);
@@ -221,7 +251,10 @@ static void mrpc_timeout_work(struct work_struct *work)
221 251
222 mutex_lock(&stdev->mrpc_mutex); 252 mutex_lock(&stdev->mrpc_mutex);
223 253
224 status = ioread32(&stdev->mmio_mrpc->status); 254 if (stdev->dma_mrpc)
255 status = stdev->dma_mrpc->status;
256 else
257 status = ioread32(&stdev->mmio_mrpc->status);
225 if (status == SWITCHTEC_MRPC_STATUS_INPROGRESS) { 258 if (status == SWITCHTEC_MRPC_STATUS_INPROGRESS) {
226 schedule_delayed_work(&stdev->mrpc_timeout, 259 schedule_delayed_work(&stdev->mrpc_timeout,
227 msecs_to_jiffies(500)); 260 msecs_to_jiffies(500));
@@ -229,7 +262,6 @@ static void mrpc_timeout_work(struct work_struct *work)
229 } 262 }
230 263
231 mrpc_complete_cmd(stdev); 264 mrpc_complete_cmd(stdev);
232
233out: 265out:
234 mutex_unlock(&stdev->mrpc_mutex); 266 mutex_unlock(&stdev->mrpc_mutex);
235} 267}
@@ -800,6 +832,7 @@ static int ioctl_event_ctl(struct switchtec_dev *stdev,
800{ 832{
801 int ret; 833 int ret;
802 int nr_idxs; 834 int nr_idxs;
835 unsigned int event_flags;
803 struct switchtec_ioctl_event_ctl ctl; 836 struct switchtec_ioctl_event_ctl ctl;
804 837
805 if (copy_from_user(&ctl, uctl, sizeof(ctl))) 838 if (copy_from_user(&ctl, uctl, sizeof(ctl)))
@@ -821,7 +854,9 @@ static int ioctl_event_ctl(struct switchtec_dev *stdev,
821 else 854 else
822 return -EINVAL; 855 return -EINVAL;
823 856
857 event_flags = ctl.flags;
824 for (ctl.index = 0; ctl.index < nr_idxs; ctl.index++) { 858 for (ctl.index = 0; ctl.index < nr_idxs; ctl.index++) {
859 ctl.flags = event_flags;
825 ret = event_ctl(stdev, &ctl); 860 ret = event_ctl(stdev, &ctl);
826 if (ret < 0) 861 if (ret < 0)
827 return ret; 862 return ret;
@@ -1017,10 +1052,24 @@ static void enable_link_state_events(struct switchtec_dev *stdev)
1017 } 1052 }
1018} 1053}
1019 1054
1055static void enable_dma_mrpc(struct switchtec_dev *stdev)
1056{
1057 writeq(stdev->dma_mrpc_dma_addr, &stdev->mmio_mrpc->dma_addr);
1058 flush_wc_buf(stdev);
1059 iowrite32(SWITCHTEC_DMA_MRPC_EN, &stdev->mmio_mrpc->dma_en);
1060}
1061
1020static void stdev_release(struct device *dev) 1062static void stdev_release(struct device *dev)
1021{ 1063{
1022 struct switchtec_dev *stdev = to_stdev(dev); 1064 struct switchtec_dev *stdev = to_stdev(dev);
1023 1065
1066 if (stdev->dma_mrpc) {
1067 iowrite32(0, &stdev->mmio_mrpc->dma_en);
1068 flush_wc_buf(stdev);
1069 writeq(0, &stdev->mmio_mrpc->dma_addr);
1070 dma_free_coherent(&stdev->pdev->dev, sizeof(*stdev->dma_mrpc),
1071 stdev->dma_mrpc, stdev->dma_mrpc_dma_addr);
1072 }
1024 kfree(stdev); 1073 kfree(stdev);
1025} 1074}
1026 1075
@@ -1176,10 +1225,27 @@ static irqreturn_t switchtec_event_isr(int irq, void *dev)
1176 return ret; 1225 return ret;
1177} 1226}
1178 1227
1228
1229static irqreturn_t switchtec_dma_mrpc_isr(int irq, void *dev)
1230{
1231 struct switchtec_dev *stdev = dev;
1232 irqreturn_t ret = IRQ_NONE;
1233
1234 iowrite32(SWITCHTEC_EVENT_CLEAR |
1235 SWITCHTEC_EVENT_EN_IRQ,
1236 &stdev->mmio_part_cfg->mrpc_comp_hdr);
1237 schedule_work(&stdev->mrpc_work);
1238
1239 ret = IRQ_HANDLED;
1240 return ret;
1241}
1242
1179static int switchtec_init_isr(struct switchtec_dev *stdev) 1243static int switchtec_init_isr(struct switchtec_dev *stdev)
1180{ 1244{
1181 int nvecs; 1245 int nvecs;
1182 int event_irq; 1246 int event_irq;
1247 int dma_mrpc_irq;
1248 int rc;
1183 1249
1184 nvecs = pci_alloc_irq_vectors(stdev->pdev, 1, 4, 1250 nvecs = pci_alloc_irq_vectors(stdev->pdev, 1, 4,
1185 PCI_IRQ_MSIX | PCI_IRQ_MSI); 1251 PCI_IRQ_MSIX | PCI_IRQ_MSI);
@@ -1194,9 +1260,29 @@ static int switchtec_init_isr(struct switchtec_dev *stdev)
1194 if (event_irq < 0) 1260 if (event_irq < 0)
1195 return event_irq; 1261 return event_irq;
1196 1262
1197 return devm_request_irq(&stdev->pdev->dev, event_irq, 1263 rc = devm_request_irq(&stdev->pdev->dev, event_irq,
1198 switchtec_event_isr, 0, 1264 switchtec_event_isr, 0,
1199 KBUILD_MODNAME, stdev); 1265 KBUILD_MODNAME, stdev);
1266
1267 if (rc)
1268 return rc;
1269
1270 if (!stdev->dma_mrpc)
1271 return rc;
1272
1273 dma_mrpc_irq = ioread32(&stdev->mmio_mrpc->dma_vector);
1274 if (dma_mrpc_irq < 0 || dma_mrpc_irq >= nvecs)
1275 return -EFAULT;
1276
1277 dma_mrpc_irq = pci_irq_vector(stdev->pdev, dma_mrpc_irq);
1278 if (dma_mrpc_irq < 0)
1279 return dma_mrpc_irq;
1280
1281 rc = devm_request_irq(&stdev->pdev->dev, dma_mrpc_irq,
1282 switchtec_dma_mrpc_isr, 0,
1283 KBUILD_MODNAME, stdev);
1284
1285 return rc;
1200} 1286}
1201 1287
1202static void init_pff(struct switchtec_dev *stdev) 1288static void init_pff(struct switchtec_dev *stdev)
@@ -1232,19 +1318,38 @@ static int switchtec_init_pci(struct switchtec_dev *stdev,
1232 struct pci_dev *pdev) 1318 struct pci_dev *pdev)
1233{ 1319{
1234 int rc; 1320 int rc;
1321 void __iomem *map;
1322 unsigned long res_start, res_len;
1235 1323
1236 rc = pcim_enable_device(pdev); 1324 rc = pcim_enable_device(pdev);
1237 if (rc) 1325 if (rc)
1238 return rc; 1326 return rc;
1239 1327
1240 rc = pcim_iomap_regions(pdev, 0x1, KBUILD_MODNAME); 1328 rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
1241 if (rc) 1329 if (rc)
1242 return rc; 1330 return rc;
1243 1331
1244 pci_set_master(pdev); 1332 pci_set_master(pdev);
1245 1333
1246 stdev->mmio = pcim_iomap_table(pdev)[0]; 1334 res_start = pci_resource_start(pdev, 0);
1247 stdev->mmio_mrpc = stdev->mmio + SWITCHTEC_GAS_MRPC_OFFSET; 1335 res_len = pci_resource_len(pdev, 0);
1336
1337 if (!devm_request_mem_region(&pdev->dev, res_start,
1338 res_len, KBUILD_MODNAME))
1339 return -EBUSY;
1340
1341 stdev->mmio_mrpc = devm_ioremap_wc(&pdev->dev, res_start,
1342 SWITCHTEC_GAS_TOP_CFG_OFFSET);
1343 if (!stdev->mmio_mrpc)
1344 return -ENOMEM;
1345
1346 map = devm_ioremap(&pdev->dev,
1347 res_start + SWITCHTEC_GAS_TOP_CFG_OFFSET,
1348 res_len - SWITCHTEC_GAS_TOP_CFG_OFFSET);
1349 if (!map)
1350 return -ENOMEM;
1351
1352 stdev->mmio = map - SWITCHTEC_GAS_TOP_CFG_OFFSET;
1248 stdev->mmio_sw_event = stdev->mmio + SWITCHTEC_GAS_SW_EVENT_OFFSET; 1353 stdev->mmio_sw_event = stdev->mmio + SWITCHTEC_GAS_SW_EVENT_OFFSET;
1249 stdev->mmio_sys_info = stdev->mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET; 1354 stdev->mmio_sys_info = stdev->mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET;
1250 stdev->mmio_flash_info = stdev->mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET; 1355 stdev->mmio_flash_info = stdev->mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET;
@@ -1262,6 +1367,19 @@ static int switchtec_init_pci(struct switchtec_dev *stdev,
1262 1367
1263 pci_set_drvdata(pdev, stdev); 1368 pci_set_drvdata(pdev, stdev);
1264 1369
1370 if (!use_dma_mrpc)
1371 return 0;
1372
1373 if (ioread32(&stdev->mmio_mrpc->dma_ver) == 0)
1374 return 0;
1375
1376 stdev->dma_mrpc = dma_zalloc_coherent(&stdev->pdev->dev,
1377 sizeof(*stdev->dma_mrpc),
1378 &stdev->dma_mrpc_dma_addr,
1379 GFP_KERNEL);
1380 if (stdev->dma_mrpc == NULL)
1381 return -ENOMEM;
1382
1265 return 0; 1383 return 0;
1266} 1384}
1267 1385
@@ -1293,6 +1411,9 @@ static int switchtec_pci_probe(struct pci_dev *pdev,
1293 &stdev->mmio_part_cfg->mrpc_comp_hdr); 1411 &stdev->mmio_part_cfg->mrpc_comp_hdr);
1294 enable_link_state_events(stdev); 1412 enable_link_state_events(stdev);
1295 1413
1414 if (stdev->dma_mrpc)
1415 enable_dma_mrpc(stdev);
1416
1296 rc = cdev_device_add(&stdev->cdev, &stdev->dev); 1417 rc = cdev_device_add(&stdev->cdev, &stdev->dev);
1297 if (rc) 1418 if (rc)
1298 goto err_devadd; 1419 goto err_devadd;
@@ -1318,7 +1439,6 @@ static void switchtec_pci_remove(struct pci_dev *pdev)
1318 cdev_device_del(&stdev->cdev, &stdev->dev); 1439 cdev_device_del(&stdev->cdev, &stdev->dev);
1319 ida_simple_remove(&switchtec_minor_ida, MINOR(stdev->dev.devt)); 1440 ida_simple_remove(&switchtec_minor_ida, MINOR(stdev->dev.devt));
1320 dev_info(&stdev->dev, "unregistered.\n"); 1441 dev_info(&stdev->dev, "unregistered.\n");
1321
1322 stdev_kill(stdev); 1442 stdev_kill(stdev);
1323 put_device(&stdev->dev); 1443 put_device(&stdev->dev);
1324} 1444}
diff --git a/drivers/usb/dwc3/dwc3-haps.c b/drivers/usb/dwc3/dwc3-haps.c
index c9cc33881bef..02d57d98ef9b 100644
--- a/drivers/usb/dwc3/dwc3-haps.c
+++ b/drivers/usb/dwc3/dwc3-haps.c
@@ -15,10 +15,6 @@
15#include <linux/platform_device.h> 15#include <linux/platform_device.h>
16#include <linux/property.h> 16#include <linux/property.h>
17 17
18#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd
19#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI 0xabce
20#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31 0xabcf
21
22/** 18/**
23 * struct dwc3_haps - Driver private structure 19 * struct dwc3_haps - Driver private structure
24 * @dwc3: child dwc3 platform_device 20 * @dwc3: child dwc3 platform_device