1 // SPDX-License-Identifier: GPL-2.0
3 * pcie-dra7xx - PCIe controller driver for TI DRA7xx SoCs
5 * Copyright (C) 2013-2014 Texas Instruments Incorporated - http://www.ti.com
7 * Authors: Kishon Vijay Abraham I <kishon@ti.com>
10 #include <linux/delay.h>
11 #include <linux/device.h>
12 #include <linux/err.h>
13 #include <linux/interrupt.h>
14 #include <linux/irq.h>
15 #include <linux/irqdomain.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/of_device.h>
19 #include <linux/of_gpio.h>
20 #include <linux/of_pci.h>
21 #include <linux/pci.h>
22 #include <linux/phy/phy.h>
23 #include <linux/platform_device.h>
24 #include <linux/pm_runtime.h>
25 #include <linux/resource.h>
26 #include <linux/types.h>
27 #include <linux/mfd/syscon.h>
28 #include <linux/regmap.h>
30 #include "pcie-designware.h"
32 /* PCIe controller wrapper DRA7XX configuration registers */
34 #define PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN 0x0024
35 #define PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MAIN 0x0028
36 #define ERR_SYS BIT(0)
37 #define ERR_FATAL BIT(1)
38 #define ERR_NONFATAL BIT(2)
39 #define ERR_COR BIT(3)
40 #define ERR_AXI BIT(4)
41 #define ERR_ECRC BIT(5)
42 #define PME_TURN_OFF BIT(8)
43 #define PME_TO_ACK BIT(9)
44 #define PM_PME BIT(10)
45 #define LINK_REQ_RST BIT(11)
46 #define LINK_UP_EVT BIT(12)
47 #define CFG_BME_EVT BIT(13)
48 #define CFG_MSE_EVT BIT(14)
49 #define INTERRUPTS (ERR_SYS | ERR_FATAL | ERR_NONFATAL | ERR_COR | ERR_AXI | \
50 ERR_ECRC | PME_TURN_OFF | PME_TO_ACK | PM_PME | \
51 LINK_REQ_RST | LINK_UP_EVT | CFG_BME_EVT | CFG_MSE_EVT)
53 #define PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI 0x0034
54 #define PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI 0x0038
60 #define LEG_EP_INTERRUPTS (INTA | INTB | INTC | INTD)
62 #define PCIECTRL_TI_CONF_DEVICE_TYPE 0x0100
63 #define DEVICE_TYPE_EP 0x0
64 #define DEVICE_TYPE_LEG_EP 0x1
65 #define DEVICE_TYPE_RC 0x4
67 #define PCIECTRL_DRA7XX_CONF_DEVICE_CMD 0x0104
70 #define PCIECTRL_DRA7XX_CONF_PHY_CS 0x010C
71 #define LINK_UP BIT(16)
72 #define DRA7XX_CPU_TO_BUS_ADDR 0x0FFFFFFF
74 #define EXP_CAP_ID_OFFSET 0x70
76 #define PCIECTRL_TI_CONF_INTX_ASSERT 0x0124
77 #define PCIECTRL_TI_CONF_INTX_DEASSERT 0x0128
79 #define PCIECTRL_TI_CONF_MSI_XMT 0x012c
80 #define MSI_REQ_GRANT BIT(0)
81 #define MSI_VECTOR_SHIFT 7
85 void __iomem
*base
; /* DT ti_conf */
86 int phy_count
; /* DT phy-names count */
89 struct irq_domain
*irq_domain
;
90 enum dw_pcie_device_mode mode
;
93 struct dra7xx_pcie_of_data
{
94 enum dw_pcie_device_mode mode
;
97 #define to_dra7xx_pcie(x) dev_get_drvdata((x)->dev)
99 static inline u32
dra7xx_pcie_readl(struct dra7xx_pcie
*pcie
, u32 offset
)
101 return readl(pcie
->base
+ offset
);
104 static inline void dra7xx_pcie_writel(struct dra7xx_pcie
*pcie
, u32 offset
,
107 writel(value
, pcie
->base
+ offset
);
110 static u64
dra7xx_pcie_cpu_addr_fixup(struct dw_pcie
*pci
, u64 pci_addr
)
112 return pci_addr
& DRA7XX_CPU_TO_BUS_ADDR
;
115 static int dra7xx_pcie_link_up(struct dw_pcie
*pci
)
117 struct dra7xx_pcie
*dra7xx
= to_dra7xx_pcie(pci
);
118 u32 reg
= dra7xx_pcie_readl(dra7xx
, PCIECTRL_DRA7XX_CONF_PHY_CS
);
120 return !!(reg
& LINK_UP
);
123 static void dra7xx_pcie_stop_link(struct dw_pcie
*pci
)
125 struct dra7xx_pcie
*dra7xx
= to_dra7xx_pcie(pci
);
128 reg
= dra7xx_pcie_readl(dra7xx
, PCIECTRL_DRA7XX_CONF_DEVICE_CMD
);
130 dra7xx_pcie_writel(dra7xx
, PCIECTRL_DRA7XX_CONF_DEVICE_CMD
, reg
);
133 static int dra7xx_pcie_establish_link(struct dw_pcie
*pci
)
135 struct dra7xx_pcie
*dra7xx
= to_dra7xx_pcie(pci
);
136 struct device
*dev
= pci
->dev
;
138 u32 exp_cap_off
= EXP_CAP_ID_OFFSET
;
140 if (dw_pcie_link_up(pci
)) {
141 dev_err(dev
, "link is already up\n");
145 if (dra7xx
->link_gen
== 1) {
146 dw_pcie_read(pci
->dbi_base
+ exp_cap_off
+ PCI_EXP_LNKCAP
,
148 if ((reg
& PCI_EXP_LNKCAP_SLS
) != PCI_EXP_LNKCAP_SLS_2_5GB
) {
149 reg
&= ~((u32
)PCI_EXP_LNKCAP_SLS
);
150 reg
|= PCI_EXP_LNKCAP_SLS_2_5GB
;
151 dw_pcie_write(pci
->dbi_base
+ exp_cap_off
+
152 PCI_EXP_LNKCAP
, 4, reg
);
155 dw_pcie_read(pci
->dbi_base
+ exp_cap_off
+ PCI_EXP_LNKCTL2
,
157 if ((reg
& PCI_EXP_LNKCAP_SLS
) != PCI_EXP_LNKCAP_SLS_2_5GB
) {
158 reg
&= ~((u32
)PCI_EXP_LNKCAP_SLS
);
159 reg
|= PCI_EXP_LNKCAP_SLS_2_5GB
;
160 dw_pcie_write(pci
->dbi_base
+ exp_cap_off
+
161 PCI_EXP_LNKCTL2
, 2, reg
);
165 reg
= dra7xx_pcie_readl(dra7xx
, PCIECTRL_DRA7XX_CONF_DEVICE_CMD
);
167 dra7xx_pcie_writel(dra7xx
, PCIECTRL_DRA7XX_CONF_DEVICE_CMD
, reg
);
172 static void dra7xx_pcie_enable_msi_interrupts(struct dra7xx_pcie
*dra7xx
)
174 dra7xx_pcie_writel(dra7xx
, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI
,
175 LEG_EP_INTERRUPTS
| MSI
);
177 dra7xx_pcie_writel(dra7xx
,
178 PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI
,
179 MSI
| LEG_EP_INTERRUPTS
);
182 static void dra7xx_pcie_enable_wrapper_interrupts(struct dra7xx_pcie
*dra7xx
)
184 dra7xx_pcie_writel(dra7xx
, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN
,
186 dra7xx_pcie_writel(dra7xx
, PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MAIN
,
190 static void dra7xx_pcie_enable_interrupts(struct dra7xx_pcie
*dra7xx
)
192 dra7xx_pcie_enable_wrapper_interrupts(dra7xx
);
193 dra7xx_pcie_enable_msi_interrupts(dra7xx
);
196 static int dra7xx_pcie_host_init(struct pcie_port
*pp
)
198 struct dw_pcie
*pci
= to_dw_pcie_from_pp(pp
);
199 struct dra7xx_pcie
*dra7xx
= to_dra7xx_pcie(pci
);
201 dw_pcie_setup_rc(pp
);
203 dra7xx_pcie_establish_link(pci
);
204 dw_pcie_wait_for_link(pci
);
205 dw_pcie_msi_init(pp
);
206 dra7xx_pcie_enable_interrupts(dra7xx
);
211 static const struct dw_pcie_host_ops dra7xx_pcie_host_ops
= {
212 .host_init
= dra7xx_pcie_host_init
,
215 static int dra7xx_pcie_intx_map(struct irq_domain
*domain
, unsigned int irq
,
216 irq_hw_number_t hwirq
)
218 irq_set_chip_and_handler(irq
, &dummy_irq_chip
, handle_simple_irq
);
219 irq_set_chip_data(irq
, domain
->host_data
);
224 static const struct irq_domain_ops intx_domain_ops
= {
225 .map
= dra7xx_pcie_intx_map
,
226 .xlate
= pci_irqd_intx_xlate
,
229 static int dra7xx_pcie_init_irq_domain(struct pcie_port
*pp
)
231 struct dw_pcie
*pci
= to_dw_pcie_from_pp(pp
);
232 struct device
*dev
= pci
->dev
;
233 struct dra7xx_pcie
*dra7xx
= to_dra7xx_pcie(pci
);
234 struct device_node
*node
= dev
->of_node
;
235 struct device_node
*pcie_intc_node
= of_get_next_child(node
, NULL
);
237 if (!pcie_intc_node
) {
238 dev_err(dev
, "No PCIe Intc node found\n");
242 dra7xx
->irq_domain
= irq_domain_add_linear(pcie_intc_node
, PCI_NUM_INTX
,
243 &intx_domain_ops
, pp
);
244 if (!dra7xx
->irq_domain
) {
245 dev_err(dev
, "Failed to get a INTx IRQ domain\n");
252 static irqreturn_t
dra7xx_pcie_msi_irq_handler(int irq
, void *arg
)
254 struct dra7xx_pcie
*dra7xx
= arg
;
255 struct dw_pcie
*pci
= dra7xx
->pci
;
256 struct pcie_port
*pp
= &pci
->pp
;
260 reg
= dra7xx_pcie_readl(dra7xx
, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI
);
264 dw_handle_msi_irq(pp
);
270 for_each_set_bit(bit
, ®
, PCI_NUM_INTX
) {
271 virq
= irq_find_mapping(dra7xx
->irq_domain
, bit
);
273 generic_handle_irq(virq
);
278 dra7xx_pcie_writel(dra7xx
, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI
, reg
);
283 static irqreturn_t
dra7xx_pcie_irq_handler(int irq
, void *arg
)
285 struct dra7xx_pcie
*dra7xx
= arg
;
286 struct dw_pcie
*pci
= dra7xx
->pci
;
287 struct device
*dev
= pci
->dev
;
288 struct dw_pcie_ep
*ep
= &pci
->ep
;
291 reg
= dra7xx_pcie_readl(dra7xx
, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN
);
294 dev_dbg(dev
, "System Error\n");
297 dev_dbg(dev
, "Fatal Error\n");
299 if (reg
& ERR_NONFATAL
)
300 dev_dbg(dev
, "Non Fatal Error\n");
303 dev_dbg(dev
, "Correctable Error\n");
306 dev_dbg(dev
, "AXI tag lookup fatal Error\n");
309 dev_dbg(dev
, "ECRC Error\n");
311 if (reg
& PME_TURN_OFF
)
313 "Power Management Event Turn-Off message received\n");
315 if (reg
& PME_TO_ACK
)
317 "Power Management Turn-Off Ack message received\n");
320 dev_dbg(dev
, "PM Power Management Event message received\n");
322 if (reg
& LINK_REQ_RST
)
323 dev_dbg(dev
, "Link Request Reset\n");
325 if (reg
& LINK_UP_EVT
) {
326 if (dra7xx
->mode
== DW_PCIE_EP_TYPE
)
327 dw_pcie_ep_linkup(ep
);
328 dev_dbg(dev
, "Link-up state change\n");
331 if (reg
& CFG_BME_EVT
)
332 dev_dbg(dev
, "CFG 'Bus Master Enable' change\n");
334 if (reg
& CFG_MSE_EVT
)
335 dev_dbg(dev
, "CFG 'Memory Space Enable' change\n");
337 dra7xx_pcie_writel(dra7xx
, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN
, reg
);
342 static void dra7xx_pcie_ep_init(struct dw_pcie_ep
*ep
)
344 struct dw_pcie
*pci
= to_dw_pcie_from_ep(ep
);
345 struct dra7xx_pcie
*dra7xx
= to_dra7xx_pcie(pci
);
348 for (bar
= BAR_0
; bar
<= BAR_5
; bar
++)
349 dw_pcie_ep_reset_bar(pci
, bar
);
351 dra7xx_pcie_enable_wrapper_interrupts(dra7xx
);
354 static void dra7xx_pcie_raise_legacy_irq(struct dra7xx_pcie
*dra7xx
)
356 dra7xx_pcie_writel(dra7xx
, PCIECTRL_TI_CONF_INTX_ASSERT
, 0x1);
358 dra7xx_pcie_writel(dra7xx
, PCIECTRL_TI_CONF_INTX_DEASSERT
, 0x1);
361 static void dra7xx_pcie_raise_msi_irq(struct dra7xx_pcie
*dra7xx
,
366 reg
= (interrupt_num
- 1) << MSI_VECTOR_SHIFT
;
367 reg
|= MSI_REQ_GRANT
;
368 dra7xx_pcie_writel(dra7xx
, PCIECTRL_TI_CONF_MSI_XMT
, reg
);
371 static int dra7xx_pcie_raise_irq(struct dw_pcie_ep
*ep
, u8 func_no
,
372 enum pci_epc_irq_type type
, u8 interrupt_num
)
374 struct dw_pcie
*pci
= to_dw_pcie_from_ep(ep
);
375 struct dra7xx_pcie
*dra7xx
= to_dra7xx_pcie(pci
);
378 case PCI_EPC_IRQ_LEGACY
:
379 dra7xx_pcie_raise_legacy_irq(dra7xx
);
381 case PCI_EPC_IRQ_MSI
:
382 dra7xx_pcie_raise_msi_irq(dra7xx
, interrupt_num
);
385 dev_err(pci
->dev
, "UNKNOWN IRQ type\n");
391 static struct dw_pcie_ep_ops pcie_ep_ops
= {
392 .ep_init
= dra7xx_pcie_ep_init
,
393 .raise_irq
= dra7xx_pcie_raise_irq
,
396 static int __init
dra7xx_add_pcie_ep(struct dra7xx_pcie
*dra7xx
,
397 struct platform_device
*pdev
)
400 struct dw_pcie_ep
*ep
;
401 struct resource
*res
;
402 struct device
*dev
= &pdev
->dev
;
403 struct dw_pcie
*pci
= dra7xx
->pci
;
406 ep
->ops
= &pcie_ep_ops
;
408 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "ep_dbics");
409 pci
->dbi_base
= devm_ioremap(dev
, res
->start
, resource_size(res
));
413 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "ep_dbics2");
414 pci
->dbi_base2
= devm_ioremap(dev
, res
->start
, resource_size(res
));
418 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "addr_space");
422 ep
->phys_base
= res
->start
;
423 ep
->addr_size
= resource_size(res
);
425 ret
= dw_pcie_ep_init(ep
);
427 dev_err(dev
, "failed to initialize endpoint\n");
434 static int __init
dra7xx_add_pcie_port(struct dra7xx_pcie
*dra7xx
,
435 struct platform_device
*pdev
)
438 struct dw_pcie
*pci
= dra7xx
->pci
;
439 struct pcie_port
*pp
= &pci
->pp
;
440 struct device
*dev
= pci
->dev
;
441 struct resource
*res
;
443 pp
->irq
= platform_get_irq(pdev
, 1);
445 dev_err(dev
, "missing IRQ resource\n");
449 ret
= devm_request_irq(dev
, pp
->irq
, dra7xx_pcie_msi_irq_handler
,
450 IRQF_SHARED
| IRQF_NO_THREAD
,
451 "dra7-pcie-msi", dra7xx
);
453 dev_err(dev
, "failed to request irq\n");
457 ret
= dra7xx_pcie_init_irq_domain(pp
);
461 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "rc_dbics");
462 pci
->dbi_base
= devm_ioremap(dev
, res
->start
, resource_size(res
));
466 pp
->ops
= &dra7xx_pcie_host_ops
;
468 ret
= dw_pcie_host_init(pp
);
470 dev_err(dev
, "failed to initialize host\n");
477 static const struct dw_pcie_ops dw_pcie_ops
= {
478 .cpu_addr_fixup
= dra7xx_pcie_cpu_addr_fixup
,
479 .start_link
= dra7xx_pcie_establish_link
,
480 .stop_link
= dra7xx_pcie_stop_link
,
481 .link_up
= dra7xx_pcie_link_up
,
484 static void dra7xx_pcie_disable_phy(struct dra7xx_pcie
*dra7xx
)
486 int phy_count
= dra7xx
->phy_count
;
488 while (phy_count
--) {
489 phy_power_off(dra7xx
->phy
[phy_count
]);
490 phy_exit(dra7xx
->phy
[phy_count
]);
494 static int dra7xx_pcie_enable_phy(struct dra7xx_pcie
*dra7xx
)
496 int phy_count
= dra7xx
->phy_count
;
500 for (i
= 0; i
< phy_count
; i
++) {
501 ret
= phy_init(dra7xx
->phy
[i
]);
505 ret
= phy_power_on(dra7xx
->phy
[i
]);
507 phy_exit(dra7xx
->phy
[i
]);
516 phy_power_off(dra7xx
->phy
[i
]);
517 phy_exit(dra7xx
->phy
[i
]);
523 static const struct dra7xx_pcie_of_data dra7xx_pcie_rc_of_data
= {
524 .mode
= DW_PCIE_RC_TYPE
,
527 static const struct dra7xx_pcie_of_data dra7xx_pcie_ep_of_data
= {
528 .mode
= DW_PCIE_EP_TYPE
,
531 static const struct of_device_id of_dra7xx_pcie_match
[] = {
533 .compatible
= "ti,dra7-pcie",
534 .data
= &dra7xx_pcie_rc_of_data
,
537 .compatible
= "ti,dra7-pcie-ep",
538 .data
= &dra7xx_pcie_ep_of_data
,
544 * dra7xx_pcie_ep_unaligned_memaccess: workaround for AM572x/AM571x Errata i870
545 * @dra7xx: the dra7xx device where the workaround should be applied
547 * Access to the PCIe slave port that are not 32-bit aligned will result
548 * in incorrect mapping to TLP Address and Byte enable fields. Therefore,
549 * byte and half-word accesses are not possible to byte offset 0x1, 0x2, or
552 * To avoid this issue set PCIE_SS1_AXI2OCP_LEGACY_MODE_ENABLE to 1.
554 static int dra7xx_pcie_ep_unaligned_memaccess(struct device
*dev
)
557 struct device_node
*np
= dev
->of_node
;
558 struct of_phandle_args args
;
559 struct regmap
*regmap
;
561 regmap
= syscon_regmap_lookup_by_phandle(np
,
562 "ti,syscon-unaligned-access");
563 if (IS_ERR(regmap
)) {
564 dev_dbg(dev
, "can't get ti,syscon-unaligned-access\n");
568 ret
= of_parse_phandle_with_fixed_args(np
, "ti,syscon-unaligned-access",
571 dev_err(dev
, "failed to parse ti,syscon-unaligned-access\n");
575 ret
= regmap_update_bits(regmap
, args
.args
[0], args
.args
[1],
578 dev_err(dev
, "failed to enable unaligned access\n");
580 of_node_put(args
.np
);
585 static int __init
dra7xx_pcie_probe(struct platform_device
*pdev
)
593 struct device_link
**link
;
595 struct resource
*res
;
597 struct dra7xx_pcie
*dra7xx
;
598 struct device
*dev
= &pdev
->dev
;
599 struct device_node
*np
= dev
->of_node
;
601 struct gpio_desc
*reset
;
602 const struct of_device_id
*match
;
603 const struct dra7xx_pcie_of_data
*data
;
604 enum dw_pcie_device_mode mode
;
606 match
= of_match_device(of_match_ptr(of_dra7xx_pcie_match
), dev
);
610 data
= (struct dra7xx_pcie_of_data
*)match
->data
;
611 mode
= (enum dw_pcie_device_mode
)data
->mode
;
613 dra7xx
= devm_kzalloc(dev
, sizeof(*dra7xx
), GFP_KERNEL
);
617 pci
= devm_kzalloc(dev
, sizeof(*pci
), GFP_KERNEL
);
622 pci
->ops
= &dw_pcie_ops
;
624 irq
= platform_get_irq(pdev
, 0);
626 dev_err(dev
, "missing IRQ resource: %d\n", irq
);
630 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "ti_conf");
631 base
= devm_ioremap_nocache(dev
, res
->start
, resource_size(res
));
635 phy_count
= of_property_count_strings(np
, "phy-names");
637 dev_err(dev
, "unable to find the strings\n");
641 phy
= devm_kzalloc(dev
, sizeof(*phy
) * phy_count
, GFP_KERNEL
);
645 link
= devm_kzalloc(dev
, sizeof(*link
) * phy_count
, GFP_KERNEL
);
649 for (i
= 0; i
< phy_count
; i
++) {
650 snprintf(name
, sizeof(name
), "pcie-phy%d", i
);
651 phy
[i
] = devm_phy_get(dev
, name
);
653 return PTR_ERR(phy
[i
]);
655 link
[i
] = device_link_add(dev
, &phy
[i
]->dev
, DL_FLAG_STATELESS
);
665 dra7xx
->phy_count
= phy_count
;
667 ret
= dra7xx_pcie_enable_phy(dra7xx
);
669 dev_err(dev
, "failed to enable phy\n");
673 platform_set_drvdata(pdev
, dra7xx
);
675 pm_runtime_enable(dev
);
676 ret
= pm_runtime_get_sync(dev
);
678 dev_err(dev
, "pm_runtime_get_sync failed\n");
682 reset
= devm_gpiod_get_optional(dev
, NULL
, GPIOD_OUT_HIGH
);
684 ret
= PTR_ERR(reset
);
685 dev_err(&pdev
->dev
, "gpio request failed, ret %d\n", ret
);
689 reg
= dra7xx_pcie_readl(dra7xx
, PCIECTRL_DRA7XX_CONF_DEVICE_CMD
);
691 dra7xx_pcie_writel(dra7xx
, PCIECTRL_DRA7XX_CONF_DEVICE_CMD
, reg
);
693 dra7xx
->link_gen
= of_pci_get_max_link_speed(np
);
694 if (dra7xx
->link_gen
< 0 || dra7xx
->link_gen
> 2)
695 dra7xx
->link_gen
= 2;
698 case DW_PCIE_RC_TYPE
:
699 if (!IS_ENABLED(CONFIG_PCI_DRA7XX_HOST
)) {
704 dra7xx_pcie_writel(dra7xx
, PCIECTRL_TI_CONF_DEVICE_TYPE
,
706 ret
= dra7xx_add_pcie_port(dra7xx
, pdev
);
710 case DW_PCIE_EP_TYPE
:
711 if (!IS_ENABLED(CONFIG_PCI_DRA7XX_EP
)) {
716 dra7xx_pcie_writel(dra7xx
, PCIECTRL_TI_CONF_DEVICE_TYPE
,
719 ret
= dra7xx_pcie_ep_unaligned_memaccess(dev
);
723 ret
= dra7xx_add_pcie_ep(dra7xx
, pdev
);
728 dev_err(dev
, "INVALID device type %d\n", mode
);
732 ret
= devm_request_irq(dev
, irq
, dra7xx_pcie_irq_handler
,
733 IRQF_SHARED
, "dra7xx-pcie-main", dra7xx
);
735 dev_err(dev
, "failed to request irq\n");
745 pm_runtime_disable(dev
);
746 dra7xx_pcie_disable_phy(dra7xx
);
750 device_link_del(link
[i
]);
755 #ifdef CONFIG_PM_SLEEP
756 static int dra7xx_pcie_suspend(struct device
*dev
)
758 struct dra7xx_pcie
*dra7xx
= dev_get_drvdata(dev
);
759 struct dw_pcie
*pci
= dra7xx
->pci
;
762 if (dra7xx
->mode
!= DW_PCIE_RC_TYPE
)
766 val
= dw_pcie_readl_dbi(pci
, PCI_COMMAND
);
767 val
&= ~PCI_COMMAND_MEMORY
;
768 dw_pcie_writel_dbi(pci
, PCI_COMMAND
, val
);
773 static int dra7xx_pcie_resume(struct device
*dev
)
775 struct dra7xx_pcie
*dra7xx
= dev_get_drvdata(dev
);
776 struct dw_pcie
*pci
= dra7xx
->pci
;
779 if (dra7xx
->mode
!= DW_PCIE_RC_TYPE
)
783 val
= dw_pcie_readl_dbi(pci
, PCI_COMMAND
);
784 val
|= PCI_COMMAND_MEMORY
;
785 dw_pcie_writel_dbi(pci
, PCI_COMMAND
, val
);
790 static int dra7xx_pcie_suspend_noirq(struct device
*dev
)
792 struct dra7xx_pcie
*dra7xx
= dev_get_drvdata(dev
);
794 dra7xx_pcie_disable_phy(dra7xx
);
799 static int dra7xx_pcie_resume_noirq(struct device
*dev
)
801 struct dra7xx_pcie
*dra7xx
= dev_get_drvdata(dev
);
804 ret
= dra7xx_pcie_enable_phy(dra7xx
);
806 dev_err(dev
, "failed to enable phy\n");
814 static void dra7xx_pcie_shutdown(struct platform_device
*pdev
)
816 struct device
*dev
= &pdev
->dev
;
817 struct dra7xx_pcie
*dra7xx
= dev_get_drvdata(dev
);
820 dra7xx_pcie_stop_link(dra7xx
->pci
);
822 ret
= pm_runtime_put_sync(dev
);
824 dev_dbg(dev
, "pm_runtime_put_sync failed\n");
826 pm_runtime_disable(dev
);
827 dra7xx_pcie_disable_phy(dra7xx
);
830 static const struct dev_pm_ops dra7xx_pcie_pm_ops
= {
831 SET_SYSTEM_SLEEP_PM_OPS(dra7xx_pcie_suspend
, dra7xx_pcie_resume
)
832 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(dra7xx_pcie_suspend_noirq
,
833 dra7xx_pcie_resume_noirq
)
836 static struct platform_driver dra7xx_pcie_driver
= {
839 .of_match_table
= of_dra7xx_pcie_match
,
840 .suppress_bind_attrs
= true,
841 .pm
= &dra7xx_pcie_pm_ops
,
843 .shutdown
= dra7xx_pcie_shutdown
,
845 builtin_platform_driver_probe(dra7xx_pcie_driver
, dra7xx_pcie_probe
);