1 // SPDX-License-Identifier: GPL-2.0
3 * Qualcomm PCIe root complex driver
5 * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
6 * Copyright 2015 Linaro Limited.
8 * Author: Stanimir Varbanov <svarbanov@mm-sol.com>
11 #include <linux/clk.h>
12 #include <linux/delay.h>
13 #include <linux/gpio/consumer.h>
14 #include <linux/interrupt.h>
16 #include <linux/iopoll.h>
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/of_device.h>
20 #include <linux/of_gpio.h>
21 #include <linux/pci.h>
22 #include <linux/pm_runtime.h>
23 #include <linux/platform_device.h>
24 #include <linux/phy/phy.h>
25 #include <linux/regulator/consumer.h>
26 #include <linux/reset.h>
27 #include <linux/slab.h>
28 #include <linux/types.h>
30 #include "pcie-designware.h"
32 #define PCIE20_PARF_SYS_CTRL 0x00
33 #define MST_WAKEUP_EN BIT(13)
34 #define SLV_WAKEUP_EN BIT(12)
35 #define MSTR_ACLK_CGC_DIS BIT(10)
36 #define SLV_ACLK_CGC_DIS BIT(9)
37 #define CORE_CLK_CGC_DIS BIT(6)
38 #define AUX_PWR_DET BIT(4)
39 #define L23_CLK_RMV_DIS BIT(2)
40 #define L1_CLK_RMV_DIS BIT(1)
42 #define PCIE20_COMMAND_STATUS 0x04
43 #define CMD_BME_VAL 0x4
44 #define PCIE20_DEVICE_CONTROL2_STATUS2 0x98
45 #define PCIE_CAP_CPL_TIMEOUT_DISABLE 0x10
47 #define PCIE20_PARF_PHY_CTRL 0x40
48 #define PCIE20_PARF_PHY_REFCLK 0x4C
49 #define PCIE20_PARF_DBI_BASE_ADDR 0x168
50 #define PCIE20_PARF_SLV_ADDR_SPACE_SIZE 0x16C
51 #define PCIE20_PARF_MHI_CLOCK_RESET_CTRL 0x174
52 #define PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT 0x178
53 #define PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT_V2 0x1A8
54 #define PCIE20_PARF_LTSSM 0x1B0
55 #define PCIE20_PARF_SID_OFFSET 0x234
56 #define PCIE20_PARF_BDF_TRANSLATE_CFG 0x24C
57 #define PCIE20_PARF_DEVICE_TYPE 0x1000
59 #define PCIE20_ELBI_SYS_CTRL 0x04
60 #define PCIE20_ELBI_SYS_CTRL_LT_ENABLE BIT(0)
62 #define PCIE20_AXI_MSTR_RESP_COMP_CTRL0 0x818
63 #define CFG_REMOTE_RD_REQ_BRIDGE_SIZE_2K 0x4
64 #define CFG_REMOTE_RD_REQ_BRIDGE_SIZE_4K 0x5
65 #define PCIE20_AXI_MSTR_RESP_COMP_CTRL1 0x81c
66 #define CFG_BRIDGE_SB_INIT BIT(0)
68 #define PCIE20_CAP 0x70
69 #define PCIE20_CAP_LINK_CAPABILITIES (PCIE20_CAP + 0xC)
70 #define PCIE20_CAP_ACTIVE_STATE_LINK_PM_SUPPORT (BIT(10) | BIT(11))
71 #define PCIE20_CAP_LINK_1 (PCIE20_CAP + 0x14)
72 #define PCIE_CAP_LINK1_VAL 0x2FD7F
74 #define PCIE20_PARF_Q2A_FLUSH 0x1AC
76 #define PCIE20_MISC_CONTROL_1_REG 0x8BC
77 #define DBI_RO_WR_EN 1
79 #define PERST_DELAY_US 1000
81 #define PCIE20_v3_PARF_SLV_ADDR_SPACE_SIZE 0x358
82 #define SLV_ADDR_SPACE_SZ 0x10000000
84 #define DEVICE_TYPE_RC 0x4
86 #define QCOM_PCIE_2_1_0_MAX_SUPPLY 3
87 struct qcom_pcie_resources_2_1_0
{
88 struct clk
*iface_clk
;
91 struct reset_control
*pci_reset
;
92 struct reset_control
*axi_reset
;
93 struct reset_control
*ahb_reset
;
94 struct reset_control
*por_reset
;
95 struct reset_control
*phy_reset
;
96 struct regulator_bulk_data supplies
[QCOM_PCIE_2_1_0_MAX_SUPPLY
];
99 struct qcom_pcie_resources_1_0_0
{
102 struct clk
*master_bus
;
103 struct clk
*slave_bus
;
104 struct reset_control
*core
;
105 struct regulator
*vdda
;
108 #define QCOM_PCIE_2_3_2_MAX_SUPPLY 2
109 struct qcom_pcie_resources_2_3_2
{
111 struct clk
*master_clk
;
112 struct clk
*slave_clk
;
114 struct clk
*pipe_clk
;
115 struct regulator_bulk_data supplies
[QCOM_PCIE_2_3_2_MAX_SUPPLY
];
118 #define QCOM_PCIE_2_4_0_MAX_CLOCKS 4
119 struct qcom_pcie_resources_2_4_0
{
120 struct clk_bulk_data clks
[QCOM_PCIE_2_4_0_MAX_CLOCKS
];
122 struct reset_control
*axi_m_reset
;
123 struct reset_control
*axi_s_reset
;
124 struct reset_control
*pipe_reset
;
125 struct reset_control
*axi_m_vmid_reset
;
126 struct reset_control
*axi_s_xpu_reset
;
127 struct reset_control
*parf_reset
;
128 struct reset_control
*phy_reset
;
129 struct reset_control
*axi_m_sticky_reset
;
130 struct reset_control
*pipe_sticky_reset
;
131 struct reset_control
*pwr_reset
;
132 struct reset_control
*ahb_reset
;
133 struct reset_control
*phy_ahb_reset
;
136 struct qcom_pcie_resources_2_3_3
{
138 struct clk
*axi_m_clk
;
139 struct clk
*axi_s_clk
;
142 struct reset_control
*rst
[7];
145 struct qcom_pcie_resources_2_7_0
{
146 struct clk_bulk_data clks
[6];
147 struct regulator_bulk_data supplies
[2];
148 struct reset_control
*pci_reset
;
149 struct clk
*pipe_clk
;
152 union qcom_pcie_resources
{
153 struct qcom_pcie_resources_1_0_0 v1_0_0
;
154 struct qcom_pcie_resources_2_1_0 v2_1_0
;
155 struct qcom_pcie_resources_2_3_2 v2_3_2
;
156 struct qcom_pcie_resources_2_3_3 v2_3_3
;
157 struct qcom_pcie_resources_2_4_0 v2_4_0
;
158 struct qcom_pcie_resources_2_7_0 v2_7_0
;
163 struct qcom_pcie_ops
{
164 int (*get_resources
)(struct qcom_pcie
*pcie
);
165 int (*init
)(struct qcom_pcie
*pcie
);
166 int (*post_init
)(struct qcom_pcie
*pcie
);
167 void (*deinit
)(struct qcom_pcie
*pcie
);
168 void (*post_deinit
)(struct qcom_pcie
*pcie
);
169 void (*ltssm_enable
)(struct qcom_pcie
*pcie
);
174 void __iomem
*parf
; /* DT parf */
175 void __iomem
*elbi
; /* DT elbi */
176 union qcom_pcie_resources res
;
178 struct gpio_desc
*reset
;
179 const struct qcom_pcie_ops
*ops
;
182 #define to_qcom_pcie(x) dev_get_drvdata((x)->dev)
184 static void qcom_ep_reset_assert(struct qcom_pcie
*pcie
)
186 gpiod_set_value_cansleep(pcie
->reset
, 1);
187 usleep_range(PERST_DELAY_US
, PERST_DELAY_US
+ 500);
190 static void qcom_ep_reset_deassert(struct qcom_pcie
*pcie
)
192 /* Ensure that PERST has been asserted for at least 100 ms */
194 gpiod_set_value_cansleep(pcie
->reset
, 0);
195 usleep_range(PERST_DELAY_US
, PERST_DELAY_US
+ 500);
198 static int qcom_pcie_establish_link(struct qcom_pcie
*pcie
)
200 struct dw_pcie
*pci
= pcie
->pci
;
202 if (dw_pcie_link_up(pci
))
205 /* Enable Link Training state machine */
206 if (pcie
->ops
->ltssm_enable
)
207 pcie
->ops
->ltssm_enable(pcie
);
209 return dw_pcie_wait_for_link(pci
);
212 static void qcom_pcie_2_1_0_ltssm_enable(struct qcom_pcie
*pcie
)
216 /* enable link training */
217 val
= readl(pcie
->elbi
+ PCIE20_ELBI_SYS_CTRL
);
218 val
|= PCIE20_ELBI_SYS_CTRL_LT_ENABLE
;
219 writel(val
, pcie
->elbi
+ PCIE20_ELBI_SYS_CTRL
);
222 static int qcom_pcie_get_resources_2_1_0(struct qcom_pcie
*pcie
)
224 struct qcom_pcie_resources_2_1_0
*res
= &pcie
->res
.v2_1_0
;
225 struct dw_pcie
*pci
= pcie
->pci
;
226 struct device
*dev
= pci
->dev
;
229 res
->supplies
[0].supply
= "vdda";
230 res
->supplies
[1].supply
= "vdda_phy";
231 res
->supplies
[2].supply
= "vdda_refclk";
232 ret
= devm_regulator_bulk_get(dev
, ARRAY_SIZE(res
->supplies
),
237 res
->iface_clk
= devm_clk_get(dev
, "iface");
238 if (IS_ERR(res
->iface_clk
))
239 return PTR_ERR(res
->iface_clk
);
241 res
->core_clk
= devm_clk_get(dev
, "core");
242 if (IS_ERR(res
->core_clk
))
243 return PTR_ERR(res
->core_clk
);
245 res
->phy_clk
= devm_clk_get(dev
, "phy");
246 if (IS_ERR(res
->phy_clk
))
247 return PTR_ERR(res
->phy_clk
);
249 res
->pci_reset
= devm_reset_control_get_exclusive(dev
, "pci");
250 if (IS_ERR(res
->pci_reset
))
251 return PTR_ERR(res
->pci_reset
);
253 res
->axi_reset
= devm_reset_control_get_exclusive(dev
, "axi");
254 if (IS_ERR(res
->axi_reset
))
255 return PTR_ERR(res
->axi_reset
);
257 res
->ahb_reset
= devm_reset_control_get_exclusive(dev
, "ahb");
258 if (IS_ERR(res
->ahb_reset
))
259 return PTR_ERR(res
->ahb_reset
);
261 res
->por_reset
= devm_reset_control_get_exclusive(dev
, "por");
262 if (IS_ERR(res
->por_reset
))
263 return PTR_ERR(res
->por_reset
);
265 res
->phy_reset
= devm_reset_control_get_exclusive(dev
, "phy");
266 return PTR_ERR_OR_ZERO(res
->phy_reset
);
269 static void qcom_pcie_deinit_2_1_0(struct qcom_pcie
*pcie
)
271 struct qcom_pcie_resources_2_1_0
*res
= &pcie
->res
.v2_1_0
;
273 reset_control_assert(res
->pci_reset
);
274 reset_control_assert(res
->axi_reset
);
275 reset_control_assert(res
->ahb_reset
);
276 reset_control_assert(res
->por_reset
);
277 reset_control_assert(res
->pci_reset
);
278 clk_disable_unprepare(res
->iface_clk
);
279 clk_disable_unprepare(res
->core_clk
);
280 clk_disable_unprepare(res
->phy_clk
);
281 regulator_bulk_disable(ARRAY_SIZE(res
->supplies
), res
->supplies
);
284 static int qcom_pcie_init_2_1_0(struct qcom_pcie
*pcie
)
286 struct qcom_pcie_resources_2_1_0
*res
= &pcie
->res
.v2_1_0
;
287 struct dw_pcie
*pci
= pcie
->pci
;
288 struct device
*dev
= pci
->dev
;
292 ret
= regulator_bulk_enable(ARRAY_SIZE(res
->supplies
), res
->supplies
);
294 dev_err(dev
, "cannot enable regulators\n");
298 ret
= reset_control_assert(res
->ahb_reset
);
300 dev_err(dev
, "cannot assert ahb reset\n");
304 ret
= clk_prepare_enable(res
->iface_clk
);
306 dev_err(dev
, "cannot prepare/enable iface clock\n");
310 ret
= clk_prepare_enable(res
->phy_clk
);
312 dev_err(dev
, "cannot prepare/enable phy clock\n");
316 ret
= clk_prepare_enable(res
->core_clk
);
318 dev_err(dev
, "cannot prepare/enable core clock\n");
322 ret
= reset_control_deassert(res
->ahb_reset
);
324 dev_err(dev
, "cannot deassert ahb reset\n");
325 goto err_deassert_ahb
;
328 /* enable PCIe clocks and resets */
329 val
= readl(pcie
->parf
+ PCIE20_PARF_PHY_CTRL
);
331 writel(val
, pcie
->parf
+ PCIE20_PARF_PHY_CTRL
);
333 /* enable external reference clock */
334 val
= readl(pcie
->parf
+ PCIE20_PARF_PHY_REFCLK
);
336 writel(val
, pcie
->parf
+ PCIE20_PARF_PHY_REFCLK
);
338 ret
= reset_control_deassert(res
->phy_reset
);
340 dev_err(dev
, "cannot deassert phy reset\n");
344 ret
= reset_control_deassert(res
->pci_reset
);
346 dev_err(dev
, "cannot deassert pci reset\n");
350 ret
= reset_control_deassert(res
->por_reset
);
352 dev_err(dev
, "cannot deassert por reset\n");
356 ret
= reset_control_deassert(res
->axi_reset
);
358 dev_err(dev
, "cannot deassert axi reset\n");
362 /* wait for clock acquisition */
363 usleep_range(1000, 1500);
366 /* Set the Max TLP size to 2K, instead of using default of 4K */
367 writel(CFG_REMOTE_RD_REQ_BRIDGE_SIZE_2K
,
368 pci
->dbi_base
+ PCIE20_AXI_MSTR_RESP_COMP_CTRL0
);
369 writel(CFG_BRIDGE_SB_INIT
,
370 pci
->dbi_base
+ PCIE20_AXI_MSTR_RESP_COMP_CTRL1
);
375 clk_disable_unprepare(res
->core_clk
);
377 clk_disable_unprepare(res
->phy_clk
);
379 clk_disable_unprepare(res
->iface_clk
);
381 regulator_bulk_disable(ARRAY_SIZE(res
->supplies
), res
->supplies
);
386 static int qcom_pcie_get_resources_1_0_0(struct qcom_pcie
*pcie
)
388 struct qcom_pcie_resources_1_0_0
*res
= &pcie
->res
.v1_0_0
;
389 struct dw_pcie
*pci
= pcie
->pci
;
390 struct device
*dev
= pci
->dev
;
392 res
->vdda
= devm_regulator_get(dev
, "vdda");
393 if (IS_ERR(res
->vdda
))
394 return PTR_ERR(res
->vdda
);
396 res
->iface
= devm_clk_get(dev
, "iface");
397 if (IS_ERR(res
->iface
))
398 return PTR_ERR(res
->iface
);
400 res
->aux
= devm_clk_get(dev
, "aux");
401 if (IS_ERR(res
->aux
))
402 return PTR_ERR(res
->aux
);
404 res
->master_bus
= devm_clk_get(dev
, "master_bus");
405 if (IS_ERR(res
->master_bus
))
406 return PTR_ERR(res
->master_bus
);
408 res
->slave_bus
= devm_clk_get(dev
, "slave_bus");
409 if (IS_ERR(res
->slave_bus
))
410 return PTR_ERR(res
->slave_bus
);
412 res
->core
= devm_reset_control_get_exclusive(dev
, "core");
413 return PTR_ERR_OR_ZERO(res
->core
);
416 static void qcom_pcie_deinit_1_0_0(struct qcom_pcie
*pcie
)
418 struct qcom_pcie_resources_1_0_0
*res
= &pcie
->res
.v1_0_0
;
420 reset_control_assert(res
->core
);
421 clk_disable_unprepare(res
->slave_bus
);
422 clk_disable_unprepare(res
->master_bus
);
423 clk_disable_unprepare(res
->iface
);
424 clk_disable_unprepare(res
->aux
);
425 regulator_disable(res
->vdda
);
428 static int qcom_pcie_init_1_0_0(struct qcom_pcie
*pcie
)
430 struct qcom_pcie_resources_1_0_0
*res
= &pcie
->res
.v1_0_0
;
431 struct dw_pcie
*pci
= pcie
->pci
;
432 struct device
*dev
= pci
->dev
;
435 ret
= reset_control_deassert(res
->core
);
437 dev_err(dev
, "cannot deassert core reset\n");
441 ret
= clk_prepare_enable(res
->aux
);
443 dev_err(dev
, "cannot prepare/enable aux clock\n");
447 ret
= clk_prepare_enable(res
->iface
);
449 dev_err(dev
, "cannot prepare/enable iface clock\n");
453 ret
= clk_prepare_enable(res
->master_bus
);
455 dev_err(dev
, "cannot prepare/enable master_bus clock\n");
459 ret
= clk_prepare_enable(res
->slave_bus
);
461 dev_err(dev
, "cannot prepare/enable slave_bus clock\n");
465 ret
= regulator_enable(res
->vdda
);
467 dev_err(dev
, "cannot enable vdda regulator\n");
471 /* change DBI base address */
472 writel(0, pcie
->parf
+ PCIE20_PARF_DBI_BASE_ADDR
);
474 if (IS_ENABLED(CONFIG_PCI_MSI
)) {
475 u32 val
= readl(pcie
->parf
+ PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT
);
478 writel(val
, pcie
->parf
+ PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT
);
483 clk_disable_unprepare(res
->slave_bus
);
485 clk_disable_unprepare(res
->master_bus
);
487 clk_disable_unprepare(res
->iface
);
489 clk_disable_unprepare(res
->aux
);
491 reset_control_assert(res
->core
);
496 static void qcom_pcie_2_3_2_ltssm_enable(struct qcom_pcie
*pcie
)
500 /* enable link training */
501 val
= readl(pcie
->parf
+ PCIE20_PARF_LTSSM
);
503 writel(val
, pcie
->parf
+ PCIE20_PARF_LTSSM
);
506 static int qcom_pcie_get_resources_2_3_2(struct qcom_pcie
*pcie
)
508 struct qcom_pcie_resources_2_3_2
*res
= &pcie
->res
.v2_3_2
;
509 struct dw_pcie
*pci
= pcie
->pci
;
510 struct device
*dev
= pci
->dev
;
513 res
->supplies
[0].supply
= "vdda";
514 res
->supplies
[1].supply
= "vddpe-3v3";
515 ret
= devm_regulator_bulk_get(dev
, ARRAY_SIZE(res
->supplies
),
520 res
->aux_clk
= devm_clk_get(dev
, "aux");
521 if (IS_ERR(res
->aux_clk
))
522 return PTR_ERR(res
->aux_clk
);
524 res
->cfg_clk
= devm_clk_get(dev
, "cfg");
525 if (IS_ERR(res
->cfg_clk
))
526 return PTR_ERR(res
->cfg_clk
);
528 res
->master_clk
= devm_clk_get(dev
, "bus_master");
529 if (IS_ERR(res
->master_clk
))
530 return PTR_ERR(res
->master_clk
);
532 res
->slave_clk
= devm_clk_get(dev
, "bus_slave");
533 if (IS_ERR(res
->slave_clk
))
534 return PTR_ERR(res
->slave_clk
);
536 res
->pipe_clk
= devm_clk_get(dev
, "pipe");
537 return PTR_ERR_OR_ZERO(res
->pipe_clk
);
540 static void qcom_pcie_deinit_2_3_2(struct qcom_pcie
*pcie
)
542 struct qcom_pcie_resources_2_3_2
*res
= &pcie
->res
.v2_3_2
;
544 clk_disable_unprepare(res
->slave_clk
);
545 clk_disable_unprepare(res
->master_clk
);
546 clk_disable_unprepare(res
->cfg_clk
);
547 clk_disable_unprepare(res
->aux_clk
);
549 regulator_bulk_disable(ARRAY_SIZE(res
->supplies
), res
->supplies
);
552 static void qcom_pcie_post_deinit_2_3_2(struct qcom_pcie
*pcie
)
554 struct qcom_pcie_resources_2_3_2
*res
= &pcie
->res
.v2_3_2
;
556 clk_disable_unprepare(res
->pipe_clk
);
559 static int qcom_pcie_init_2_3_2(struct qcom_pcie
*pcie
)
561 struct qcom_pcie_resources_2_3_2
*res
= &pcie
->res
.v2_3_2
;
562 struct dw_pcie
*pci
= pcie
->pci
;
563 struct device
*dev
= pci
->dev
;
567 ret
= regulator_bulk_enable(ARRAY_SIZE(res
->supplies
), res
->supplies
);
569 dev_err(dev
, "cannot enable regulators\n");
573 ret
= clk_prepare_enable(res
->aux_clk
);
575 dev_err(dev
, "cannot prepare/enable aux clock\n");
579 ret
= clk_prepare_enable(res
->cfg_clk
);
581 dev_err(dev
, "cannot prepare/enable cfg clock\n");
585 ret
= clk_prepare_enable(res
->master_clk
);
587 dev_err(dev
, "cannot prepare/enable master clock\n");
591 ret
= clk_prepare_enable(res
->slave_clk
);
593 dev_err(dev
, "cannot prepare/enable slave clock\n");
597 /* enable PCIe clocks and resets */
598 val
= readl(pcie
->parf
+ PCIE20_PARF_PHY_CTRL
);
600 writel(val
, pcie
->parf
+ PCIE20_PARF_PHY_CTRL
);
602 /* change DBI base address */
603 writel(0, pcie
->parf
+ PCIE20_PARF_DBI_BASE_ADDR
);
605 /* MAC PHY_POWERDOWN MUX DISABLE */
606 val
= readl(pcie
->parf
+ PCIE20_PARF_SYS_CTRL
);
608 writel(val
, pcie
->parf
+ PCIE20_PARF_SYS_CTRL
);
610 val
= readl(pcie
->parf
+ PCIE20_PARF_MHI_CLOCK_RESET_CTRL
);
612 writel(val
, pcie
->parf
+ PCIE20_PARF_MHI_CLOCK_RESET_CTRL
);
614 val
= readl(pcie
->parf
+ PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT_V2
);
616 writel(val
, pcie
->parf
+ PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT_V2
);
621 clk_disable_unprepare(res
->master_clk
);
623 clk_disable_unprepare(res
->cfg_clk
);
625 clk_disable_unprepare(res
->aux_clk
);
628 regulator_bulk_disable(ARRAY_SIZE(res
->supplies
), res
->supplies
);
633 static int qcom_pcie_post_init_2_3_2(struct qcom_pcie
*pcie
)
635 struct qcom_pcie_resources_2_3_2
*res
= &pcie
->res
.v2_3_2
;
636 struct dw_pcie
*pci
= pcie
->pci
;
637 struct device
*dev
= pci
->dev
;
640 ret
= clk_prepare_enable(res
->pipe_clk
);
642 dev_err(dev
, "cannot prepare/enable pipe clock\n");
649 static int qcom_pcie_get_resources_2_4_0(struct qcom_pcie
*pcie
)
651 struct qcom_pcie_resources_2_4_0
*res
= &pcie
->res
.v2_4_0
;
652 struct dw_pcie
*pci
= pcie
->pci
;
653 struct device
*dev
= pci
->dev
;
654 bool is_ipq
= of_device_is_compatible(dev
->of_node
, "qcom,pcie-ipq4019");
657 res
->clks
[0].id
= "aux";
658 res
->clks
[1].id
= "master_bus";
659 res
->clks
[2].id
= "slave_bus";
660 res
->clks
[3].id
= "iface";
662 /* qcom,pcie-ipq4019 is defined without "iface" */
663 res
->num_clks
= is_ipq
? 3 : 4;
665 ret
= devm_clk_bulk_get(dev
, res
->num_clks
, res
->clks
);
669 res
->axi_m_reset
= devm_reset_control_get_exclusive(dev
, "axi_m");
670 if (IS_ERR(res
->axi_m_reset
))
671 return PTR_ERR(res
->axi_m_reset
);
673 res
->axi_s_reset
= devm_reset_control_get_exclusive(dev
, "axi_s");
674 if (IS_ERR(res
->axi_s_reset
))
675 return PTR_ERR(res
->axi_s_reset
);
679 * These resources relates to the PHY or are secure clocks, but
680 * are controlled here for IPQ4019
682 res
->pipe_reset
= devm_reset_control_get_exclusive(dev
, "pipe");
683 if (IS_ERR(res
->pipe_reset
))
684 return PTR_ERR(res
->pipe_reset
);
686 res
->axi_m_vmid_reset
= devm_reset_control_get_exclusive(dev
,
688 if (IS_ERR(res
->axi_m_vmid_reset
))
689 return PTR_ERR(res
->axi_m_vmid_reset
);
691 res
->axi_s_xpu_reset
= devm_reset_control_get_exclusive(dev
,
693 if (IS_ERR(res
->axi_s_xpu_reset
))
694 return PTR_ERR(res
->axi_s_xpu_reset
);
696 res
->parf_reset
= devm_reset_control_get_exclusive(dev
, "parf");
697 if (IS_ERR(res
->parf_reset
))
698 return PTR_ERR(res
->parf_reset
);
700 res
->phy_reset
= devm_reset_control_get_exclusive(dev
, "phy");
701 if (IS_ERR(res
->phy_reset
))
702 return PTR_ERR(res
->phy_reset
);
705 res
->axi_m_sticky_reset
= devm_reset_control_get_exclusive(dev
,
707 if (IS_ERR(res
->axi_m_sticky_reset
))
708 return PTR_ERR(res
->axi_m_sticky_reset
);
710 res
->pipe_sticky_reset
= devm_reset_control_get_exclusive(dev
,
712 if (IS_ERR(res
->pipe_sticky_reset
))
713 return PTR_ERR(res
->pipe_sticky_reset
);
715 res
->pwr_reset
= devm_reset_control_get_exclusive(dev
, "pwr");
716 if (IS_ERR(res
->pwr_reset
))
717 return PTR_ERR(res
->pwr_reset
);
719 res
->ahb_reset
= devm_reset_control_get_exclusive(dev
, "ahb");
720 if (IS_ERR(res
->ahb_reset
))
721 return PTR_ERR(res
->ahb_reset
);
724 res
->phy_ahb_reset
= devm_reset_control_get_exclusive(dev
, "phy_ahb");
725 if (IS_ERR(res
->phy_ahb_reset
))
726 return PTR_ERR(res
->phy_ahb_reset
);
732 static void qcom_pcie_deinit_2_4_0(struct qcom_pcie
*pcie
)
734 struct qcom_pcie_resources_2_4_0
*res
= &pcie
->res
.v2_4_0
;
736 reset_control_assert(res
->axi_m_reset
);
737 reset_control_assert(res
->axi_s_reset
);
738 reset_control_assert(res
->pipe_reset
);
739 reset_control_assert(res
->pipe_sticky_reset
);
740 reset_control_assert(res
->phy_reset
);
741 reset_control_assert(res
->phy_ahb_reset
);
742 reset_control_assert(res
->axi_m_sticky_reset
);
743 reset_control_assert(res
->pwr_reset
);
744 reset_control_assert(res
->ahb_reset
);
745 clk_bulk_disable_unprepare(res
->num_clks
, res
->clks
);
748 static int qcom_pcie_init_2_4_0(struct qcom_pcie
*pcie
)
750 struct qcom_pcie_resources_2_4_0
*res
= &pcie
->res
.v2_4_0
;
751 struct dw_pcie
*pci
= pcie
->pci
;
752 struct device
*dev
= pci
->dev
;
756 ret
= reset_control_assert(res
->axi_m_reset
);
758 dev_err(dev
, "cannot assert axi master reset\n");
762 ret
= reset_control_assert(res
->axi_s_reset
);
764 dev_err(dev
, "cannot assert axi slave reset\n");
768 usleep_range(10000, 12000);
770 ret
= reset_control_assert(res
->pipe_reset
);
772 dev_err(dev
, "cannot assert pipe reset\n");
776 ret
= reset_control_assert(res
->pipe_sticky_reset
);
778 dev_err(dev
, "cannot assert pipe sticky reset\n");
782 ret
= reset_control_assert(res
->phy_reset
);
784 dev_err(dev
, "cannot assert phy reset\n");
788 ret
= reset_control_assert(res
->phy_ahb_reset
);
790 dev_err(dev
, "cannot assert phy ahb reset\n");
794 usleep_range(10000, 12000);
796 ret
= reset_control_assert(res
->axi_m_sticky_reset
);
798 dev_err(dev
, "cannot assert axi master sticky reset\n");
802 ret
= reset_control_assert(res
->pwr_reset
);
804 dev_err(dev
, "cannot assert power reset\n");
808 ret
= reset_control_assert(res
->ahb_reset
);
810 dev_err(dev
, "cannot assert ahb reset\n");
814 usleep_range(10000, 12000);
816 ret
= reset_control_deassert(res
->phy_ahb_reset
);
818 dev_err(dev
, "cannot deassert phy ahb reset\n");
822 ret
= reset_control_deassert(res
->phy_reset
);
824 dev_err(dev
, "cannot deassert phy reset\n");
828 ret
= reset_control_deassert(res
->pipe_reset
);
830 dev_err(dev
, "cannot deassert pipe reset\n");
834 ret
= reset_control_deassert(res
->pipe_sticky_reset
);
836 dev_err(dev
, "cannot deassert pipe sticky reset\n");
837 goto err_rst_pipe_sticky
;
840 usleep_range(10000, 12000);
842 ret
= reset_control_deassert(res
->axi_m_reset
);
844 dev_err(dev
, "cannot deassert axi master reset\n");
848 ret
= reset_control_deassert(res
->axi_m_sticky_reset
);
850 dev_err(dev
, "cannot deassert axi master sticky reset\n");
851 goto err_rst_axi_m_sticky
;
854 ret
= reset_control_deassert(res
->axi_s_reset
);
856 dev_err(dev
, "cannot deassert axi slave reset\n");
860 ret
= reset_control_deassert(res
->pwr_reset
);
862 dev_err(dev
, "cannot deassert power reset\n");
866 ret
= reset_control_deassert(res
->ahb_reset
);
868 dev_err(dev
, "cannot deassert ahb reset\n");
872 usleep_range(10000, 12000);
874 ret
= clk_bulk_prepare_enable(res
->num_clks
, res
->clks
);
878 /* enable PCIe clocks and resets */
879 val
= readl(pcie
->parf
+ PCIE20_PARF_PHY_CTRL
);
881 writel(val
, pcie
->parf
+ PCIE20_PARF_PHY_CTRL
);
883 /* change DBI base address */
884 writel(0, pcie
->parf
+ PCIE20_PARF_DBI_BASE_ADDR
);
886 /* MAC PHY_POWERDOWN MUX DISABLE */
887 val
= readl(pcie
->parf
+ PCIE20_PARF_SYS_CTRL
);
889 writel(val
, pcie
->parf
+ PCIE20_PARF_SYS_CTRL
);
891 val
= readl(pcie
->parf
+ PCIE20_PARF_MHI_CLOCK_RESET_CTRL
);
893 writel(val
, pcie
->parf
+ PCIE20_PARF_MHI_CLOCK_RESET_CTRL
);
895 val
= readl(pcie
->parf
+ PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT_V2
);
897 writel(val
, pcie
->parf
+ PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT_V2
);
902 reset_control_assert(res
->ahb_reset
);
904 reset_control_assert(res
->pwr_reset
);
906 reset_control_assert(res
->axi_s_reset
);
908 reset_control_assert(res
->axi_m_sticky_reset
);
909 err_rst_axi_m_sticky
:
910 reset_control_assert(res
->axi_m_reset
);
912 reset_control_assert(res
->pipe_sticky_reset
);
914 reset_control_assert(res
->pipe_reset
);
916 reset_control_assert(res
->phy_reset
);
918 reset_control_assert(res
->phy_ahb_reset
);
922 static int qcom_pcie_get_resources_2_3_3(struct qcom_pcie
*pcie
)
924 struct qcom_pcie_resources_2_3_3
*res
= &pcie
->res
.v2_3_3
;
925 struct dw_pcie
*pci
= pcie
->pci
;
926 struct device
*dev
= pci
->dev
;
928 const char *rst_names
[] = { "axi_m", "axi_s", "pipe",
929 "axi_m_sticky", "sticky",
932 res
->iface
= devm_clk_get(dev
, "iface");
933 if (IS_ERR(res
->iface
))
934 return PTR_ERR(res
->iface
);
936 res
->axi_m_clk
= devm_clk_get(dev
, "axi_m");
937 if (IS_ERR(res
->axi_m_clk
))
938 return PTR_ERR(res
->axi_m_clk
);
940 res
->axi_s_clk
= devm_clk_get(dev
, "axi_s");
941 if (IS_ERR(res
->axi_s_clk
))
942 return PTR_ERR(res
->axi_s_clk
);
944 res
->ahb_clk
= devm_clk_get(dev
, "ahb");
945 if (IS_ERR(res
->ahb_clk
))
946 return PTR_ERR(res
->ahb_clk
);
948 res
->aux_clk
= devm_clk_get(dev
, "aux");
949 if (IS_ERR(res
->aux_clk
))
950 return PTR_ERR(res
->aux_clk
);
952 for (i
= 0; i
< ARRAY_SIZE(rst_names
); i
++) {
953 res
->rst
[i
] = devm_reset_control_get(dev
, rst_names
[i
]);
954 if (IS_ERR(res
->rst
[i
]))
955 return PTR_ERR(res
->rst
[i
]);
961 static void qcom_pcie_deinit_2_3_3(struct qcom_pcie
*pcie
)
963 struct qcom_pcie_resources_2_3_3
*res
= &pcie
->res
.v2_3_3
;
965 clk_disable_unprepare(res
->iface
);
966 clk_disable_unprepare(res
->axi_m_clk
);
967 clk_disable_unprepare(res
->axi_s_clk
);
968 clk_disable_unprepare(res
->ahb_clk
);
969 clk_disable_unprepare(res
->aux_clk
);
972 static int qcom_pcie_init_2_3_3(struct qcom_pcie
*pcie
)
974 struct qcom_pcie_resources_2_3_3
*res
= &pcie
->res
.v2_3_3
;
975 struct dw_pcie
*pci
= pcie
->pci
;
976 struct device
*dev
= pci
->dev
;
980 for (i
= 0; i
< ARRAY_SIZE(res
->rst
); i
++) {
981 ret
= reset_control_assert(res
->rst
[i
]);
983 dev_err(dev
, "reset #%d assert failed (%d)\n", i
, ret
);
988 usleep_range(2000, 2500);
990 for (i
= 0; i
< ARRAY_SIZE(res
->rst
); i
++) {
991 ret
= reset_control_deassert(res
->rst
[i
]);
993 dev_err(dev
, "reset #%d deassert failed (%d)\n", i
,
1000 * Don't have a way to see if the reset has completed.
1001 * Wait for some time.
1003 usleep_range(2000, 2500);
1005 ret
= clk_prepare_enable(res
->iface
);
1007 dev_err(dev
, "cannot prepare/enable core clock\n");
1011 ret
= clk_prepare_enable(res
->axi_m_clk
);
1013 dev_err(dev
, "cannot prepare/enable core clock\n");
1017 ret
= clk_prepare_enable(res
->axi_s_clk
);
1019 dev_err(dev
, "cannot prepare/enable axi slave clock\n");
1023 ret
= clk_prepare_enable(res
->ahb_clk
);
1025 dev_err(dev
, "cannot prepare/enable ahb clock\n");
1029 ret
= clk_prepare_enable(res
->aux_clk
);
1031 dev_err(dev
, "cannot prepare/enable aux clock\n");
1035 writel(SLV_ADDR_SPACE_SZ
,
1036 pcie
->parf
+ PCIE20_v3_PARF_SLV_ADDR_SPACE_SIZE
);
1038 val
= readl(pcie
->parf
+ PCIE20_PARF_PHY_CTRL
);
1040 writel(val
, pcie
->parf
+ PCIE20_PARF_PHY_CTRL
);
1042 writel(0, pcie
->parf
+ PCIE20_PARF_DBI_BASE_ADDR
);
1044 writel(MST_WAKEUP_EN
| SLV_WAKEUP_EN
| MSTR_ACLK_CGC_DIS
1045 | SLV_ACLK_CGC_DIS
| CORE_CLK_CGC_DIS
|
1046 AUX_PWR_DET
| L23_CLK_RMV_DIS
| L1_CLK_RMV_DIS
,
1047 pcie
->parf
+ PCIE20_PARF_SYS_CTRL
);
1048 writel(0, pcie
->parf
+ PCIE20_PARF_Q2A_FLUSH
);
1050 writel(CMD_BME_VAL
, pci
->dbi_base
+ PCIE20_COMMAND_STATUS
);
1051 writel(DBI_RO_WR_EN
, pci
->dbi_base
+ PCIE20_MISC_CONTROL_1_REG
);
1052 writel(PCIE_CAP_LINK1_VAL
, pci
->dbi_base
+ PCIE20_CAP_LINK_1
);
1054 val
= readl(pci
->dbi_base
+ PCIE20_CAP_LINK_CAPABILITIES
);
1055 val
&= ~PCIE20_CAP_ACTIVE_STATE_LINK_PM_SUPPORT
;
1056 writel(val
, pci
->dbi_base
+ PCIE20_CAP_LINK_CAPABILITIES
);
1058 writel(PCIE_CAP_CPL_TIMEOUT_DISABLE
, pci
->dbi_base
+
1059 PCIE20_DEVICE_CONTROL2_STATUS2
);
1064 clk_disable_unprepare(res
->ahb_clk
);
1066 clk_disable_unprepare(res
->axi_s_clk
);
1068 clk_disable_unprepare(res
->axi_m_clk
);
1070 clk_disable_unprepare(res
->iface
);
1073 * Not checking for failure, will anyway return
1074 * the original failure in 'ret'.
1076 for (i
= 0; i
< ARRAY_SIZE(res
->rst
); i
++)
1077 reset_control_assert(res
->rst
[i
]);
1082 static int qcom_pcie_get_resources_2_7_0(struct qcom_pcie
*pcie
)
1084 struct qcom_pcie_resources_2_7_0
*res
= &pcie
->res
.v2_7_0
;
1085 struct dw_pcie
*pci
= pcie
->pci
;
1086 struct device
*dev
= pci
->dev
;
1089 res
->pci_reset
= devm_reset_control_get_exclusive(dev
, "pci");
1090 if (IS_ERR(res
->pci_reset
))
1091 return PTR_ERR(res
->pci_reset
);
1093 res
->supplies
[0].supply
= "vdda";
1094 res
->supplies
[1].supply
= "vddpe-3v3";
1095 ret
= devm_regulator_bulk_get(dev
, ARRAY_SIZE(res
->supplies
),
1100 res
->clks
[0].id
= "aux";
1101 res
->clks
[1].id
= "cfg";
1102 res
->clks
[2].id
= "bus_master";
1103 res
->clks
[3].id
= "bus_slave";
1104 res
->clks
[4].id
= "slave_q2a";
1105 res
->clks
[5].id
= "tbu";
1107 ret
= devm_clk_bulk_get(dev
, ARRAY_SIZE(res
->clks
), res
->clks
);
1111 res
->pipe_clk
= devm_clk_get(dev
, "pipe");
1112 return PTR_ERR_OR_ZERO(res
->pipe_clk
);
1115 static int qcom_pcie_init_2_7_0(struct qcom_pcie
*pcie
)
1117 struct qcom_pcie_resources_2_7_0
*res
= &pcie
->res
.v2_7_0
;
1118 struct dw_pcie
*pci
= pcie
->pci
;
1119 struct device
*dev
= pci
->dev
;
1123 ret
= regulator_bulk_enable(ARRAY_SIZE(res
->supplies
), res
->supplies
);
1125 dev_err(dev
, "cannot enable regulators\n");
1129 ret
= clk_bulk_prepare_enable(ARRAY_SIZE(res
->clks
), res
->clks
);
1131 goto err_disable_regulators
;
1133 ret
= reset_control_assert(res
->pci_reset
);
1135 dev_err(dev
, "cannot deassert pci reset\n");
1136 goto err_disable_clocks
;
1139 usleep_range(1000, 1500);
1141 ret
= reset_control_deassert(res
->pci_reset
);
1143 dev_err(dev
, "cannot deassert pci reset\n");
1144 goto err_disable_clocks
;
1147 ret
= clk_prepare_enable(res
->pipe_clk
);
1149 dev_err(dev
, "cannot prepare/enable pipe clock\n");
1150 goto err_disable_clocks
;
1153 /* configure PCIe to RC mode */
1154 writel(DEVICE_TYPE_RC
, pcie
->parf
+ PCIE20_PARF_DEVICE_TYPE
);
1156 /* enable PCIe clocks and resets */
1157 val
= readl(pcie
->parf
+ PCIE20_PARF_PHY_CTRL
);
1159 writel(val
, pcie
->parf
+ PCIE20_PARF_PHY_CTRL
);
1161 /* change DBI base address */
1162 writel(0, pcie
->parf
+ PCIE20_PARF_DBI_BASE_ADDR
);
1164 /* MAC PHY_POWERDOWN MUX DISABLE */
1165 val
= readl(pcie
->parf
+ PCIE20_PARF_SYS_CTRL
);
1167 writel(val
, pcie
->parf
+ PCIE20_PARF_SYS_CTRL
);
1169 val
= readl(pcie
->parf
+ PCIE20_PARF_MHI_CLOCK_RESET_CTRL
);
1171 writel(val
, pcie
->parf
+ PCIE20_PARF_MHI_CLOCK_RESET_CTRL
);
1173 if (IS_ENABLED(CONFIG_PCI_MSI
)) {
1174 val
= readl(pcie
->parf
+ PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT
);
1176 writel(val
, pcie
->parf
+ PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT
);
1181 clk_bulk_disable_unprepare(ARRAY_SIZE(res
->clks
), res
->clks
);
1182 err_disable_regulators
:
1183 regulator_bulk_disable(ARRAY_SIZE(res
->supplies
), res
->supplies
);
1188 static void qcom_pcie_deinit_2_7_0(struct qcom_pcie
*pcie
)
1190 struct qcom_pcie_resources_2_7_0
*res
= &pcie
->res
.v2_7_0
;
1192 clk_bulk_disable_unprepare(ARRAY_SIZE(res
->clks
), res
->clks
);
1193 regulator_bulk_disable(ARRAY_SIZE(res
->supplies
), res
->supplies
);
1196 static int qcom_pcie_post_init_2_7_0(struct qcom_pcie
*pcie
)
1198 struct qcom_pcie_resources_2_7_0
*res
= &pcie
->res
.v2_7_0
;
1200 return clk_prepare_enable(res
->pipe_clk
);
1203 static void qcom_pcie_post_deinit_2_7_0(struct qcom_pcie
*pcie
)
1205 struct qcom_pcie_resources_2_7_0
*res
= &pcie
->res
.v2_7_0
;
1207 clk_disable_unprepare(res
->pipe_clk
);
1210 static int qcom_pcie_link_up(struct dw_pcie
*pci
)
1212 u16 val
= readw(pci
->dbi_base
+ PCIE20_CAP
+ PCI_EXP_LNKSTA
);
1214 return !!(val
& PCI_EXP_LNKSTA_DLLLA
);
1217 static int qcom_pcie_host_init(struct pcie_port
*pp
)
1219 struct dw_pcie
*pci
= to_dw_pcie_from_pp(pp
);
1220 struct qcom_pcie
*pcie
= to_qcom_pcie(pci
);
1223 qcom_ep_reset_assert(pcie
);
1225 ret
= pcie
->ops
->init(pcie
);
1229 ret
= phy_power_on(pcie
->phy
);
1233 if (pcie
->ops
->post_init
) {
1234 ret
= pcie
->ops
->post_init(pcie
);
1236 goto err_disable_phy
;
1239 dw_pcie_setup_rc(pp
);
1241 if (IS_ENABLED(CONFIG_PCI_MSI
))
1242 dw_pcie_msi_init(pp
);
1244 qcom_ep_reset_deassert(pcie
);
1246 ret
= qcom_pcie_establish_link(pcie
);
1252 qcom_ep_reset_assert(pcie
);
1253 if (pcie
->ops
->post_deinit
)
1254 pcie
->ops
->post_deinit(pcie
);
1256 phy_power_off(pcie
->phy
);
1258 pcie
->ops
->deinit(pcie
);
1263 static const struct dw_pcie_host_ops qcom_pcie_dw_ops
= {
1264 .host_init
= qcom_pcie_host_init
,
1267 /* Qcom IP rev.: 2.1.0 Synopsys IP rev.: 4.01a */
1268 static const struct qcom_pcie_ops ops_2_1_0
= {
1269 .get_resources
= qcom_pcie_get_resources_2_1_0
,
1270 .init
= qcom_pcie_init_2_1_0
,
1271 .deinit
= qcom_pcie_deinit_2_1_0
,
1272 .ltssm_enable
= qcom_pcie_2_1_0_ltssm_enable
,
1275 /* Qcom IP rev.: 1.0.0 Synopsys IP rev.: 4.11a */
1276 static const struct qcom_pcie_ops ops_1_0_0
= {
1277 .get_resources
= qcom_pcie_get_resources_1_0_0
,
1278 .init
= qcom_pcie_init_1_0_0
,
1279 .deinit
= qcom_pcie_deinit_1_0_0
,
1280 .ltssm_enable
= qcom_pcie_2_1_0_ltssm_enable
,
1283 /* Qcom IP rev.: 2.3.2 Synopsys IP rev.: 4.21a */
1284 static const struct qcom_pcie_ops ops_2_3_2
= {
1285 .get_resources
= qcom_pcie_get_resources_2_3_2
,
1286 .init
= qcom_pcie_init_2_3_2
,
1287 .post_init
= qcom_pcie_post_init_2_3_2
,
1288 .deinit
= qcom_pcie_deinit_2_3_2
,
1289 .post_deinit
= qcom_pcie_post_deinit_2_3_2
,
1290 .ltssm_enable
= qcom_pcie_2_3_2_ltssm_enable
,
1293 /* Qcom IP rev.: 2.4.0 Synopsys IP rev.: 4.20a */
1294 static const struct qcom_pcie_ops ops_2_4_0
= {
1295 .get_resources
= qcom_pcie_get_resources_2_4_0
,
1296 .init
= qcom_pcie_init_2_4_0
,
1297 .deinit
= qcom_pcie_deinit_2_4_0
,
1298 .ltssm_enable
= qcom_pcie_2_3_2_ltssm_enable
,
1301 /* Qcom IP rev.: 2.3.3 Synopsys IP rev.: 4.30a */
1302 static const struct qcom_pcie_ops ops_2_3_3
= {
1303 .get_resources
= qcom_pcie_get_resources_2_3_3
,
1304 .init
= qcom_pcie_init_2_3_3
,
1305 .deinit
= qcom_pcie_deinit_2_3_3
,
1306 .ltssm_enable
= qcom_pcie_2_3_2_ltssm_enable
,
1309 /* Qcom IP rev.: 2.7.0 Synopsys IP rev.: 4.30a */
1310 static const struct qcom_pcie_ops ops_2_7_0
= {
1311 .get_resources
= qcom_pcie_get_resources_2_7_0
,
1312 .init
= qcom_pcie_init_2_7_0
,
1313 .deinit
= qcom_pcie_deinit_2_7_0
,
1314 .ltssm_enable
= qcom_pcie_2_3_2_ltssm_enable
,
1315 .post_init
= qcom_pcie_post_init_2_7_0
,
1316 .post_deinit
= qcom_pcie_post_deinit_2_7_0
,
1319 static const struct dw_pcie_ops dw_pcie_ops
= {
1320 .link_up
= qcom_pcie_link_up
,
1323 static int qcom_pcie_probe(struct platform_device
*pdev
)
1325 struct device
*dev
= &pdev
->dev
;
1326 struct resource
*res
;
1327 struct pcie_port
*pp
;
1328 struct dw_pcie
*pci
;
1329 struct qcom_pcie
*pcie
;
1332 pcie
= devm_kzalloc(dev
, sizeof(*pcie
), GFP_KERNEL
);
1336 pci
= devm_kzalloc(dev
, sizeof(*pci
), GFP_KERNEL
);
1340 pm_runtime_enable(dev
);
1341 ret
= pm_runtime_get_sync(dev
);
1343 pm_runtime_disable(dev
);
1348 pci
->ops
= &dw_pcie_ops
;
1353 pcie
->ops
= of_device_get_match_data(dev
);
1355 pcie
->reset
= devm_gpiod_get_optional(dev
, "perst", GPIOD_OUT_HIGH
);
1356 if (IS_ERR(pcie
->reset
)) {
1357 ret
= PTR_ERR(pcie
->reset
);
1358 goto err_pm_runtime_put
;
1361 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "parf");
1362 pcie
->parf
= devm_ioremap_resource(dev
, res
);
1363 if (IS_ERR(pcie
->parf
)) {
1364 ret
= PTR_ERR(pcie
->parf
);
1365 goto err_pm_runtime_put
;
1368 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "dbi");
1369 pci
->dbi_base
= devm_pci_remap_cfg_resource(dev
, res
);
1370 if (IS_ERR(pci
->dbi_base
)) {
1371 ret
= PTR_ERR(pci
->dbi_base
);
1372 goto err_pm_runtime_put
;
1375 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "elbi");
1376 pcie
->elbi
= devm_ioremap_resource(dev
, res
);
1377 if (IS_ERR(pcie
->elbi
)) {
1378 ret
= PTR_ERR(pcie
->elbi
);
1379 goto err_pm_runtime_put
;
1382 pcie
->phy
= devm_phy_optional_get(dev
, "pciephy");
1383 if (IS_ERR(pcie
->phy
)) {
1384 ret
= PTR_ERR(pcie
->phy
);
1385 goto err_pm_runtime_put
;
1388 ret
= pcie
->ops
->get_resources(pcie
);
1390 goto err_pm_runtime_put
;
1392 pp
->ops
= &qcom_pcie_dw_ops
;
1394 if (IS_ENABLED(CONFIG_PCI_MSI
)) {
1395 pp
->msi_irq
= platform_get_irq_byname(pdev
, "msi");
1396 if (pp
->msi_irq
< 0) {
1398 goto err_pm_runtime_put
;
1402 ret
= phy_init(pcie
->phy
);
1404 pm_runtime_disable(&pdev
->dev
);
1405 goto err_pm_runtime_put
;
1408 platform_set_drvdata(pdev
, pcie
);
1410 ret
= dw_pcie_host_init(pp
);
1412 dev_err(dev
, "cannot initialize host\n");
1413 pm_runtime_disable(&pdev
->dev
);
1414 goto err_pm_runtime_put
;
1420 pm_runtime_put(dev
);
1421 pm_runtime_disable(dev
);
1426 static const struct of_device_id qcom_pcie_match
[] = {
1427 { .compatible
= "qcom,pcie-apq8084", .data
= &ops_1_0_0
},
1428 { .compatible
= "qcom,pcie-ipq8064", .data
= &ops_2_1_0
},
1429 { .compatible
= "qcom,pcie-apq8064", .data
= &ops_2_1_0
},
1430 { .compatible
= "qcom,pcie-msm8996", .data
= &ops_2_3_2
},
1431 { .compatible
= "qcom,pcie-ipq8074", .data
= &ops_2_3_3
},
1432 { .compatible
= "qcom,pcie-ipq4019", .data
= &ops_2_4_0
},
1433 { .compatible
= "qcom,pcie-qcs404", .data
= &ops_2_4_0
},
1434 { .compatible
= "qcom,pcie-sdm845", .data
= &ops_2_7_0
},
1438 static void qcom_fixup_class(struct pci_dev
*dev
)
1440 dev
->class = PCI_CLASS_BRIDGE_PCI
<< 8;
1442 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM
, PCI_ANY_ID
, qcom_fixup_class
);
1444 static struct platform_driver qcom_pcie_driver
= {
1445 .probe
= qcom_pcie_probe
,
1447 .name
= "qcom-pcie",
1448 .suppress_bind_attrs
= true,
1449 .of_match_table
= qcom_pcie_match
,
1452 builtin_platform_driver(qcom_pcie_driver
);