1 // SPDX-License-Identifier: GPL-2.0-only
3 * PCIe controller driver for Renesas R-Car Gen4 Series SoCs
4 * Copyright (C) 2022-2023 Renesas Electronics Corporation
6 * The r8a779g0 (R-Car V4H) controller requires a specific firmware to be
7 * provided, to initialize the PHY. Otherwise, the PCIe controller will not
11 #include <linux/delay.h>
12 #include <linux/firmware.h>
13 #include <linux/interrupt.h>
15 #include <linux/iopoll.h>
16 #include <linux/module.h>
18 #include <linux/pci.h>
19 #include <linux/platform_device.h>
20 #include <linux/pm_runtime.h>
21 #include <linux/reset.h>
23 #include "../../pci.h"
24 #include "pcie-designware.h"
26 /* Renesas-specific */
27 /* PCIe Mode Setting Register 0 */
28 #define PCIEMSR0 0x0000
29 #define APP_SRIS_MODE BIT(6)
30 #define DEVICE_TYPE_EP 0
31 #define DEVICE_TYPE_RC BIT(4)
32 #define BIFUR_MOD_SET_ON BIT(0)
34 /* PCIe Interrupt Status 0 */
35 #define PCIEINTSTS0 0x0084
37 /* PCIe Interrupt Status 0 Enable */
38 #define PCIEINTSTS0EN 0x0310
39 #define MSI_CTRL_INT BIT(26)
40 #define SMLH_LINK_UP BIT(7)
41 #define RDLH_LINK_UP BIT(6)
43 /* PCIe DMA Interrupt Status Enable */
44 #define PCIEDMAINTSTSEN 0x0314
45 #define PCIEDMAINTSTSEN_INIT GENMASK(15, 0)
47 /* Port Logic Registers 89 */
48 #define PRTLGC89 0x0b70
50 /* Port Logic Registers 90 */
51 #define PRTLGC90 0x0b74
53 /* PCIe Reset Control Register 1 */
54 #define PCIERSTCTRL1 0x0014
55 #define APP_HOLD_PHY_RST BIT(16)
56 #define APP_LTSSM_ENABLE BIT(0)
58 /* PCIe Power Management Control */
59 #define PCIEPWRMNGCTRL 0x0070
60 #define APP_CLK_REQ_N BIT(11)
61 #define APP_CLK_PM_EN BIT(10)
63 #define RCAR_NUM_SPEED_CHANGE_RETRIES 10
64 #define RCAR_MAX_LINK_SPEED 4
66 #define RCAR_GEN4_PCIE_EP_FUNC_DBI_OFFSET 0x1000
67 #define RCAR_GEN4_PCIE_EP_FUNC_DBI2_OFFSET 0x800
69 #define RCAR_GEN4_PCIE_FIRMWARE_NAME "rcar_gen4_pcie.bin"
70 #define RCAR_GEN4_PCIE_FIRMWARE_BASE_ADDR 0xc000
71 MODULE_FIRMWARE(RCAR_GEN4_PCIE_FIRMWARE_NAME
);
73 struct rcar_gen4_pcie
;
74 struct rcar_gen4_pcie_drvdata
{
75 void (*additional_common_init
)(struct rcar_gen4_pcie
*rcar
);
76 int (*ltssm_control
)(struct rcar_gen4_pcie
*rcar
, bool enable
);
77 enum dw_pcie_device_mode mode
;
80 struct rcar_gen4_pcie
{
83 void __iomem
*phy_base
;
84 struct platform_device
*pdev
;
85 const struct rcar_gen4_pcie_drvdata
*drvdata
;
87 #define to_rcar_gen4_pcie(_dw) container_of(_dw, struct rcar_gen4_pcie, dw)
90 static int rcar_gen4_pcie_link_up(struct dw_pcie
*dw
)
92 struct rcar_gen4_pcie
*rcar
= to_rcar_gen4_pcie(dw
);
95 val
= readl(rcar
->base
+ PCIEINTSTS0
);
96 mask
= RDLH_LINK_UP
| SMLH_LINK_UP
;
98 return (val
& mask
) == mask
;
102 * Manually initiate the speed change. Return 0 if change succeeded; otherwise
105 static int rcar_gen4_pcie_speed_change(struct dw_pcie
*dw
)
110 val
= dw_pcie_readl_dbi(dw
, PCIE_LINK_WIDTH_SPEED_CONTROL
);
111 val
&= ~PORT_LOGIC_SPEED_CHANGE
;
112 dw_pcie_writel_dbi(dw
, PCIE_LINK_WIDTH_SPEED_CONTROL
, val
);
114 val
= dw_pcie_readl_dbi(dw
, PCIE_LINK_WIDTH_SPEED_CONTROL
);
115 val
|= PORT_LOGIC_SPEED_CHANGE
;
116 dw_pcie_writel_dbi(dw
, PCIE_LINK_WIDTH_SPEED_CONTROL
, val
);
118 for (i
= 0; i
< RCAR_NUM_SPEED_CHANGE_RETRIES
; i
++) {
119 val
= dw_pcie_readl_dbi(dw
, PCIE_LINK_WIDTH_SPEED_CONTROL
);
120 if (!(val
& PORT_LOGIC_SPEED_CHANGE
))
122 usleep_range(10000, 11000);
129 * Enable LTSSM of this controller and manually initiate the speed change.
132 static int rcar_gen4_pcie_start_link(struct dw_pcie
*dw
)
134 struct rcar_gen4_pcie
*rcar
= to_rcar_gen4_pcie(dw
);
137 if (rcar
->drvdata
->ltssm_control
) {
138 ret
= rcar
->drvdata
->ltssm_control(rcar
, true);
144 * Require direct speed change with retrying here if the max_link_speed
145 * is PCIe Gen2 or higher.
147 changes
= min_not_zero(dw
->max_link_speed
, RCAR_MAX_LINK_SPEED
) - 1;
150 * Since dw_pcie_setup_rc() sets it once, PCIe Gen2 will be trained.
151 * So, this needs remaining times for up to PCIe Gen4 if RC mode.
153 if (changes
&& rcar
->drvdata
->mode
== DW_PCIE_RC_TYPE
)
156 for (i
= 0; i
< changes
; i
++) {
157 /* It may not be connected in EP mode yet. So, break the loop */
158 if (rcar_gen4_pcie_speed_change(dw
))
165 static void rcar_gen4_pcie_stop_link(struct dw_pcie
*dw
)
167 struct rcar_gen4_pcie
*rcar
= to_rcar_gen4_pcie(dw
);
169 if (rcar
->drvdata
->ltssm_control
)
170 rcar
->drvdata
->ltssm_control(rcar
, false);
173 static int rcar_gen4_pcie_common_init(struct rcar_gen4_pcie
*rcar
)
175 struct dw_pcie
*dw
= &rcar
->dw
;
179 ret
= clk_bulk_prepare_enable(DW_PCIE_NUM_CORE_CLKS
, dw
->core_clks
);
181 dev_err(dw
->dev
, "Enabling core clocks failed\n");
185 if (!reset_control_status(dw
->core_rsts
[DW_PCIE_PWR_RST
].rstc
))
186 reset_control_assert(dw
->core_rsts
[DW_PCIE_PWR_RST
].rstc
);
188 val
= readl(rcar
->base
+ PCIEMSR0
);
189 if (rcar
->drvdata
->mode
== DW_PCIE_RC_TYPE
) {
190 val
|= DEVICE_TYPE_RC
;
191 } else if (rcar
->drvdata
->mode
== DW_PCIE_EP_TYPE
) {
192 val
|= DEVICE_TYPE_EP
;
198 if (dw
->num_lanes
< 4)
199 val
|= BIFUR_MOD_SET_ON
;
201 writel(val
, rcar
->base
+ PCIEMSR0
);
203 ret
= reset_control_deassert(dw
->core_rsts
[DW_PCIE_PWR_RST
].rstc
);
207 if (rcar
->drvdata
->additional_common_init
)
208 rcar
->drvdata
->additional_common_init(rcar
);
213 clk_bulk_disable_unprepare(DW_PCIE_NUM_CORE_CLKS
, dw
->core_clks
);
218 static void rcar_gen4_pcie_common_deinit(struct rcar_gen4_pcie
*rcar
)
220 struct dw_pcie
*dw
= &rcar
->dw
;
222 reset_control_assert(dw
->core_rsts
[DW_PCIE_PWR_RST
].rstc
);
223 clk_bulk_disable_unprepare(DW_PCIE_NUM_CORE_CLKS
, dw
->core_clks
);
226 static int rcar_gen4_pcie_prepare(struct rcar_gen4_pcie
*rcar
)
228 struct device
*dev
= rcar
->dw
.dev
;
231 pm_runtime_enable(dev
);
232 err
= pm_runtime_resume_and_get(dev
);
234 dev_err(dev
, "Runtime resume failed\n");
235 pm_runtime_disable(dev
);
241 static void rcar_gen4_pcie_unprepare(struct rcar_gen4_pcie
*rcar
)
243 struct device
*dev
= rcar
->dw
.dev
;
246 pm_runtime_disable(dev
);
249 static int rcar_gen4_pcie_get_resources(struct rcar_gen4_pcie
*rcar
)
251 rcar
->phy_base
= devm_platform_ioremap_resource_byname(rcar
->pdev
, "phy");
252 if (IS_ERR(rcar
->phy_base
))
253 return PTR_ERR(rcar
->phy_base
);
255 /* Renesas-specific registers */
256 rcar
->base
= devm_platform_ioremap_resource_byname(rcar
->pdev
, "app");
258 return PTR_ERR_OR_ZERO(rcar
->base
);
261 static const struct dw_pcie_ops dw_pcie_ops
= {
262 .start_link
= rcar_gen4_pcie_start_link
,
263 .stop_link
= rcar_gen4_pcie_stop_link
,
264 .link_up
= rcar_gen4_pcie_link_up
,
267 static struct rcar_gen4_pcie
*rcar_gen4_pcie_alloc(struct platform_device
*pdev
)
269 struct device
*dev
= &pdev
->dev
;
270 struct rcar_gen4_pcie
*rcar
;
272 rcar
= devm_kzalloc(dev
, sizeof(*rcar
), GFP_KERNEL
);
274 return ERR_PTR(-ENOMEM
);
276 rcar
->dw
.ops
= &dw_pcie_ops
;
279 rcar
->dw
.edma
.mf
= EDMA_MF_EDMA_UNROLL
;
280 dw_pcie_cap_set(&rcar
->dw
, REQ_RES
);
281 platform_set_drvdata(pdev
, rcar
);
287 static int rcar_gen4_pcie_host_init(struct dw_pcie_rp
*pp
)
289 struct dw_pcie
*dw
= to_dw_pcie_from_pp(pp
);
290 struct rcar_gen4_pcie
*rcar
= to_rcar_gen4_pcie(dw
);
294 gpiod_set_value_cansleep(dw
->pe_rst
, 1);
296 ret
= rcar_gen4_pcie_common_init(rcar
);
301 * According to the section 3.5.7.2 "RC Mode" in DWC PCIe Dual Mode
302 * Rev.5.20a and 3.5.6.1 "RC mode" in DWC PCIe RC databook v5.20a, we
303 * should disable two BARs to avoid unnecessary memory assignment
304 * during device enumeration.
306 dw_pcie_writel_dbi2(dw
, PCI_BASE_ADDRESS_0
, 0x0);
307 dw_pcie_writel_dbi2(dw
, PCI_BASE_ADDRESS_1
, 0x0);
309 /* Enable MSI interrupt signal */
310 val
= readl(rcar
->base
+ PCIEINTSTS0EN
);
312 writel(val
, rcar
->base
+ PCIEINTSTS0EN
);
314 msleep(PCIE_T_PVPERL_MS
); /* pe_rst requires 100msec delay */
316 gpiod_set_value_cansleep(dw
->pe_rst
, 0);
321 static void rcar_gen4_pcie_host_deinit(struct dw_pcie_rp
*pp
)
323 struct dw_pcie
*dw
= to_dw_pcie_from_pp(pp
);
324 struct rcar_gen4_pcie
*rcar
= to_rcar_gen4_pcie(dw
);
326 gpiod_set_value_cansleep(dw
->pe_rst
, 1);
327 rcar_gen4_pcie_common_deinit(rcar
);
330 static const struct dw_pcie_host_ops rcar_gen4_pcie_host_ops
= {
331 .init
= rcar_gen4_pcie_host_init
,
332 .deinit
= rcar_gen4_pcie_host_deinit
,
335 static int rcar_gen4_add_dw_pcie_rp(struct rcar_gen4_pcie
*rcar
)
337 struct dw_pcie_rp
*pp
= &rcar
->dw
.pp
;
339 if (!IS_ENABLED(CONFIG_PCIE_RCAR_GEN4_HOST
))
342 pp
->num_vectors
= MAX_MSI_IRQS
;
343 pp
->ops
= &rcar_gen4_pcie_host_ops
;
345 return dw_pcie_host_init(pp
);
348 static void rcar_gen4_remove_dw_pcie_rp(struct rcar_gen4_pcie
*rcar
)
350 dw_pcie_host_deinit(&rcar
->dw
.pp
);
354 static void rcar_gen4_pcie_ep_pre_init(struct dw_pcie_ep
*ep
)
356 struct dw_pcie
*dw
= to_dw_pcie_from_ep(ep
);
357 struct rcar_gen4_pcie
*rcar
= to_rcar_gen4_pcie(dw
);
360 ret
= rcar_gen4_pcie_common_init(rcar
);
364 writel(PCIEDMAINTSTSEN_INIT
, rcar
->base
+ PCIEDMAINTSTSEN
);
367 static void rcar_gen4_pcie_ep_init(struct dw_pcie_ep
*ep
)
369 struct dw_pcie
*pci
= to_dw_pcie_from_ep(ep
);
372 for (bar
= 0; bar
< PCI_STD_NUM_BARS
; bar
++)
373 dw_pcie_ep_reset_bar(pci
, bar
);
376 static void rcar_gen4_pcie_ep_deinit(struct rcar_gen4_pcie
*rcar
)
378 writel(0, rcar
->base
+ PCIEDMAINTSTSEN
);
379 rcar_gen4_pcie_common_deinit(rcar
);
382 static int rcar_gen4_pcie_ep_raise_irq(struct dw_pcie_ep
*ep
, u8 func_no
,
383 unsigned int type
, u16 interrupt_num
)
385 struct dw_pcie
*dw
= to_dw_pcie_from_ep(ep
);
389 return dw_pcie_ep_raise_intx_irq(ep
, func_no
);
391 return dw_pcie_ep_raise_msi_irq(ep
, func_no
, interrupt_num
);
393 dev_err(dw
->dev
, "Unknown IRQ type\n");
400 static const struct pci_epc_features rcar_gen4_pcie_epc_features
= {
401 .linkup_notifier
= false,
403 .msix_capable
= false,
404 .bar
[BAR_1
] = { .type
= BAR_RESERVED
, },
405 .bar
[BAR_3
] = { .type
= BAR_RESERVED
, },
406 .bar
[BAR_5
] = { .type
= BAR_RESERVED
, },
410 static const struct pci_epc_features
*
411 rcar_gen4_pcie_ep_get_features(struct dw_pcie_ep
*ep
)
413 return &rcar_gen4_pcie_epc_features
;
416 static unsigned int rcar_gen4_pcie_ep_get_dbi_offset(struct dw_pcie_ep
*ep
,
419 return func_no
* RCAR_GEN4_PCIE_EP_FUNC_DBI_OFFSET
;
422 static unsigned int rcar_gen4_pcie_ep_get_dbi2_offset(struct dw_pcie_ep
*ep
,
425 return func_no
* RCAR_GEN4_PCIE_EP_FUNC_DBI2_OFFSET
;
428 static const struct dw_pcie_ep_ops pcie_ep_ops
= {
429 .pre_init
= rcar_gen4_pcie_ep_pre_init
,
430 .init
= rcar_gen4_pcie_ep_init
,
431 .raise_irq
= rcar_gen4_pcie_ep_raise_irq
,
432 .get_features
= rcar_gen4_pcie_ep_get_features
,
433 .get_dbi_offset
= rcar_gen4_pcie_ep_get_dbi_offset
,
434 .get_dbi2_offset
= rcar_gen4_pcie_ep_get_dbi2_offset
,
437 static int rcar_gen4_add_dw_pcie_ep(struct rcar_gen4_pcie
*rcar
)
439 struct dw_pcie_ep
*ep
= &rcar
->dw
.ep
;
440 struct device
*dev
= rcar
->dw
.dev
;
443 if (!IS_ENABLED(CONFIG_PCIE_RCAR_GEN4_EP
))
446 ep
->ops
= &pcie_ep_ops
;
448 ret
= dw_pcie_ep_init(ep
);
450 rcar_gen4_pcie_ep_deinit(rcar
);
454 ret
= dw_pcie_ep_init_registers(ep
);
456 dev_err(dev
, "Failed to initialize DWC endpoint registers\n");
457 dw_pcie_ep_deinit(ep
);
458 rcar_gen4_pcie_ep_deinit(rcar
);
461 pci_epc_init_notify(ep
->epc
);
466 static void rcar_gen4_remove_dw_pcie_ep(struct rcar_gen4_pcie
*rcar
)
468 dw_pcie_ep_deinit(&rcar
->dw
.ep
);
469 rcar_gen4_pcie_ep_deinit(rcar
);
473 static int rcar_gen4_add_dw_pcie(struct rcar_gen4_pcie
*rcar
)
475 rcar
->drvdata
= of_device_get_match_data(&rcar
->pdev
->dev
);
479 switch (rcar
->drvdata
->mode
) {
480 case DW_PCIE_RC_TYPE
:
481 return rcar_gen4_add_dw_pcie_rp(rcar
);
482 case DW_PCIE_EP_TYPE
:
483 return rcar_gen4_add_dw_pcie_ep(rcar
);
489 static int rcar_gen4_pcie_probe(struct platform_device
*pdev
)
491 struct rcar_gen4_pcie
*rcar
;
494 rcar
= rcar_gen4_pcie_alloc(pdev
);
496 return PTR_ERR(rcar
);
498 err
= rcar_gen4_pcie_get_resources(rcar
);
502 err
= rcar_gen4_pcie_prepare(rcar
);
506 err
= rcar_gen4_add_dw_pcie(rcar
);
513 rcar_gen4_pcie_unprepare(rcar
);
518 static void rcar_gen4_remove_dw_pcie(struct rcar_gen4_pcie
*rcar
)
520 switch (rcar
->drvdata
->mode
) {
521 case DW_PCIE_RC_TYPE
:
522 rcar_gen4_remove_dw_pcie_rp(rcar
);
524 case DW_PCIE_EP_TYPE
:
525 rcar_gen4_remove_dw_pcie_ep(rcar
);
532 static void rcar_gen4_pcie_remove(struct platform_device
*pdev
)
534 struct rcar_gen4_pcie
*rcar
= platform_get_drvdata(pdev
);
536 rcar_gen4_remove_dw_pcie(rcar
);
537 rcar_gen4_pcie_unprepare(rcar
);
540 static int r8a779f0_pcie_ltssm_control(struct rcar_gen4_pcie
*rcar
, bool enable
)
544 val
= readl(rcar
->base
+ PCIERSTCTRL1
);
546 val
|= APP_LTSSM_ENABLE
;
547 val
&= ~APP_HOLD_PHY_RST
;
550 * Since the datasheet of R-Car doesn't mention how to assert
551 * the APP_HOLD_PHY_RST, don't assert it again. Otherwise,
552 * hang-up issue happened in the dw_edma_core_off() when
553 * the controller didn't detect a PCI device.
555 val
&= ~APP_LTSSM_ENABLE
;
557 writel(val
, rcar
->base
+ PCIERSTCTRL1
);
562 static void rcar_gen4_pcie_additional_common_init(struct rcar_gen4_pcie
*rcar
)
564 struct dw_pcie
*dw
= &rcar
->dw
;
567 val
= dw_pcie_readl_dbi(dw
, PCIE_PORT_LANE_SKEW
);
568 val
&= ~PORT_LANE_SKEW_INSERT_MASK
;
569 if (dw
->num_lanes
< 4)
571 dw_pcie_writel_dbi(dw
, PCIE_PORT_LANE_SKEW
, val
);
573 val
= readl(rcar
->base
+ PCIEPWRMNGCTRL
);
574 val
|= APP_CLK_REQ_N
| APP_CLK_PM_EN
;
575 writel(val
, rcar
->base
+ PCIEPWRMNGCTRL
);
578 static void rcar_gen4_pcie_phy_reg_update_bits(struct rcar_gen4_pcie
*rcar
,
579 u32 offset
, u32 mask
, u32 val
)
583 tmp
= readl(rcar
->phy_base
+ offset
);
586 writel(tmp
, rcar
->phy_base
+ offset
);
590 * SoC datasheet suggests checking port logic register bits during firmware
591 * write. If read returns non-zero value, then this function returns -EAGAIN
592 * indicating that the write needs to be done again. If read returns zero,
593 * then return 0 to indicate success.
595 static int rcar_gen4_pcie_reg_test_bit(struct rcar_gen4_pcie
*rcar
,
596 u32 offset
, u32 mask
)
598 struct dw_pcie
*dw
= &rcar
->dw
;
600 if (dw_pcie_readl_dbi(dw
, offset
) & mask
)
606 static int rcar_gen4_pcie_download_phy_firmware(struct rcar_gen4_pcie
*rcar
)
608 /* The check_addr values are magical numbers in the datasheet */
609 static const u32 check_addr
[] = {
615 struct dw_pcie
*dw
= &rcar
->dw
;
616 const struct firmware
*fw
;
617 unsigned int i
, timeout
;
621 ret
= request_firmware(&fw
, RCAR_GEN4_PCIE_FIRMWARE_NAME
, dw
->dev
);
623 dev_err(dw
->dev
, "Failed to load firmware (%s): %d\n",
624 RCAR_GEN4_PCIE_FIRMWARE_NAME
, ret
);
628 for (i
= 0; i
< (fw
->size
/ 2); i
++) {
629 data
= fw
->data
[(i
* 2) + 1] << 8 | fw
->data
[i
* 2];
632 dw_pcie_writel_dbi(dw
, PRTLGC89
, RCAR_GEN4_PCIE_FIRMWARE_BASE_ADDR
+ i
);
633 dw_pcie_writel_dbi(dw
, PRTLGC90
, data
);
634 if (!rcar_gen4_pcie_reg_test_bit(rcar
, PRTLGC89
, BIT(30)))
640 usleep_range(100, 200);
644 rcar_gen4_pcie_phy_reg_update_bits(rcar
, 0x0f8, BIT(17), BIT(17));
646 for (i
= 0; i
< ARRAY_SIZE(check_addr
); i
++) {
649 dw_pcie_writel_dbi(dw
, PRTLGC89
, check_addr
[i
]);
650 ret
= rcar_gen4_pcie_reg_test_bit(rcar
, PRTLGC89
, BIT(30));
651 ret
|= rcar_gen4_pcie_reg_test_bit(rcar
, PRTLGC90
, BIT(0));
658 usleep_range(100, 200);
663 release_firmware(fw
);
668 static int rcar_gen4_pcie_ltssm_control(struct rcar_gen4_pcie
*rcar
, bool enable
)
670 struct dw_pcie
*dw
= &rcar
->dw
;
675 val
= readl(rcar
->base
+ PCIERSTCTRL1
);
676 val
&= ~APP_LTSSM_ENABLE
;
677 writel(val
, rcar
->base
+ PCIERSTCTRL1
);
682 val
= dw_pcie_readl_dbi(dw
, PCIE_PORT_FORCE
);
683 val
|= PORT_FORCE_DO_DESKEW_FOR_SRIS
;
684 dw_pcie_writel_dbi(dw
, PCIE_PORT_FORCE
, val
);
686 val
= readl(rcar
->base
+ PCIEMSR0
);
687 val
|= APP_SRIS_MODE
;
688 writel(val
, rcar
->base
+ PCIEMSR0
);
691 * The R-Car Gen4 datasheet doesn't describe the PHY registers' name.
692 * But, the initialization procedure describes these offsets. So,
693 * this driver has magical offset numbers.
695 rcar_gen4_pcie_phy_reg_update_bits(rcar
, 0x700, BIT(28), 0);
696 rcar_gen4_pcie_phy_reg_update_bits(rcar
, 0x700, BIT(20), 0);
697 rcar_gen4_pcie_phy_reg_update_bits(rcar
, 0x700, BIT(12), 0);
698 rcar_gen4_pcie_phy_reg_update_bits(rcar
, 0x700, BIT(4), 0);
700 rcar_gen4_pcie_phy_reg_update_bits(rcar
, 0x148, GENMASK(23, 22), BIT(22));
701 rcar_gen4_pcie_phy_reg_update_bits(rcar
, 0x148, GENMASK(18, 16), GENMASK(17, 16));
702 rcar_gen4_pcie_phy_reg_update_bits(rcar
, 0x148, GENMASK(7, 6), BIT(6));
703 rcar_gen4_pcie_phy_reg_update_bits(rcar
, 0x148, GENMASK(2, 0), GENMASK(11, 0));
704 rcar_gen4_pcie_phy_reg_update_bits(rcar
, 0x1d4, GENMASK(16, 15), GENMASK(16, 15));
705 rcar_gen4_pcie_phy_reg_update_bits(rcar
, 0x514, BIT(26), BIT(26));
706 rcar_gen4_pcie_phy_reg_update_bits(rcar
, 0x0f8, BIT(16), 0);
707 rcar_gen4_pcie_phy_reg_update_bits(rcar
, 0x0f8, BIT(19), BIT(19));
709 val
= readl(rcar
->base
+ PCIERSTCTRL1
);
710 val
&= ~APP_HOLD_PHY_RST
;
711 writel(val
, rcar
->base
+ PCIERSTCTRL1
);
713 ret
= readl_poll_timeout(rcar
->phy_base
+ 0x0f8, val
, !(val
& BIT(18)), 100, 10000);
717 ret
= rcar_gen4_pcie_download_phy_firmware(rcar
);
721 val
= readl(rcar
->base
+ PCIERSTCTRL1
);
722 val
|= APP_LTSSM_ENABLE
;
723 writel(val
, rcar
->base
+ PCIERSTCTRL1
);
728 static struct rcar_gen4_pcie_drvdata drvdata_r8a779f0_pcie
= {
729 .ltssm_control
= r8a779f0_pcie_ltssm_control
,
730 .mode
= DW_PCIE_RC_TYPE
,
733 static struct rcar_gen4_pcie_drvdata drvdata_r8a779f0_pcie_ep
= {
734 .ltssm_control
= r8a779f0_pcie_ltssm_control
,
735 .mode
= DW_PCIE_EP_TYPE
,
738 static struct rcar_gen4_pcie_drvdata drvdata_rcar_gen4_pcie
= {
739 .additional_common_init
= rcar_gen4_pcie_additional_common_init
,
740 .ltssm_control
= rcar_gen4_pcie_ltssm_control
,
741 .mode
= DW_PCIE_RC_TYPE
,
744 static struct rcar_gen4_pcie_drvdata drvdata_rcar_gen4_pcie_ep
= {
745 .additional_common_init
= rcar_gen4_pcie_additional_common_init
,
746 .ltssm_control
= rcar_gen4_pcie_ltssm_control
,
747 .mode
= DW_PCIE_EP_TYPE
,
750 static const struct of_device_id rcar_gen4_pcie_of_match
[] = {
752 .compatible
= "renesas,r8a779f0-pcie",
753 .data
= &drvdata_r8a779f0_pcie
,
756 .compatible
= "renesas,r8a779f0-pcie-ep",
757 .data
= &drvdata_r8a779f0_pcie_ep
,
760 .compatible
= "renesas,rcar-gen4-pcie",
761 .data
= &drvdata_rcar_gen4_pcie
,
764 .compatible
= "renesas,rcar-gen4-pcie-ep",
765 .data
= &drvdata_rcar_gen4_pcie_ep
,
769 MODULE_DEVICE_TABLE(of
, rcar_gen4_pcie_of_match
);
771 static struct platform_driver rcar_gen4_pcie_driver
= {
773 .name
= "pcie-rcar-gen4",
774 .of_match_table
= rcar_gen4_pcie_of_match
,
775 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
777 .probe
= rcar_gen4_pcie_probe
,
778 .remove
= rcar_gen4_pcie_remove
,
780 module_platform_driver(rcar_gen4_pcie_driver
);
782 MODULE_DESCRIPTION("Renesas R-Car Gen4 PCIe controller driver");
783 MODULE_LICENSE("GPL");