47a26ceeb80077a371b6e475a100502ae73110e0
[openwrt/staging/pepe2k.git] /
1 From 0cd5141d1866afb23286fe90cd846441fe7aeb39 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali@kernel.org>
3 Date: Sat, 27 Mar 2021 14:44:11 +0100
4 Subject: [PATCH] PCI: aardvark: Rewrite IRQ code to chained IRQ handler
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Rewrite the code to use irq_set_chained_handler_and_data() handler with
10 chained_irq_enter() and chained_irq_exit() processing instead of using
11 devm_request_irq().
12
13 advk_pcie_irq_handler() reads IRQ status bits and calls other functions
14 based on which bits are set. These functions then read its own IRQ status
15 bits and calls other aardvark functions based on these bits. Finally
16 generic_handle_domain_irq() with translated linux IRQ numbers are called.
17
18 Signed-off-by: Pali Rohár <pali@kernel.org>
19 Signed-off-by: Marek Behún <kabel@kernel.org>
20 ---
21 drivers/pci/controller/pci-aardvark.c | 48 +++++++++++++++------------
22 1 file changed, 26 insertions(+), 22 deletions(-)
23
24 --- a/drivers/pci/controller/pci-aardvark.c
25 +++ b/drivers/pci/controller/pci-aardvark.c
26 @@ -275,6 +275,7 @@ struct advk_pcie {
27 u32 actions;
28 } wins[OB_WIN_COUNT];
29 u8 wins_count;
30 + int irq;
31 struct irq_domain *irq_domain;
32 struct irq_chip irq_chip;
33 raw_spinlock_t irq_lock;
34 @@ -1442,21 +1443,26 @@ static void advk_pcie_handle_int(struct
35 }
36 }
37
38 -static irqreturn_t advk_pcie_irq_handler(int irq, void *arg)
39 +static void advk_pcie_irq_handler(struct irq_desc *desc)
40 {
41 - struct advk_pcie *pcie = arg;
42 - u32 status;
43 + struct advk_pcie *pcie = irq_desc_get_handler_data(desc);
44 + struct irq_chip *chip = irq_desc_get_chip(desc);
45 + u32 val, mask, status;
46
47 - status = advk_readl(pcie, HOST_CTRL_INT_STATUS_REG);
48 - if (!(status & PCIE_IRQ_CORE_INT))
49 - return IRQ_NONE;
50 + chained_irq_enter(chip, desc);
51
52 - advk_pcie_handle_int(pcie);
53 + val = advk_readl(pcie, HOST_CTRL_INT_STATUS_REG);
54 + mask = advk_readl(pcie, HOST_CTRL_INT_MASK_REG);
55 + status = val & ((~mask) & PCIE_IRQ_ALL_MASK);
56
57 - /* Clear interrupt */
58 - advk_writel(pcie, PCIE_IRQ_CORE_INT, HOST_CTRL_INT_STATUS_REG);
59 + if (status & PCIE_IRQ_CORE_INT) {
60 + advk_pcie_handle_int(pcie);
61
62 - return IRQ_HANDLED;
63 + /* Clear interrupt */
64 + advk_writel(pcie, PCIE_IRQ_CORE_INT, HOST_CTRL_INT_STATUS_REG);
65 + }
66 +
67 + chained_irq_exit(chip, desc);
68 }
69
70 static void __maybe_unused advk_pcie_disable_phy(struct advk_pcie *pcie)
71 @@ -1523,7 +1529,7 @@ static int advk_pcie_probe(struct platfo
72 struct advk_pcie *pcie;
73 struct pci_host_bridge *bridge;
74 struct resource_entry *entry;
75 - int ret, irq;
76 + int ret;
77
78 bridge = devm_pci_alloc_host_bridge(dev, sizeof(struct advk_pcie));
79 if (!bridge)
80 @@ -1611,17 +1617,9 @@ static int advk_pcie_probe(struct platfo
81 if (IS_ERR(pcie->base))
82 return PTR_ERR(pcie->base);
83
84 - irq = platform_get_irq(pdev, 0);
85 - if (irq < 0)
86 - return irq;
87 -
88 - ret = devm_request_irq(dev, irq, advk_pcie_irq_handler,
89 - IRQF_SHARED | IRQF_NO_THREAD, "advk-pcie",
90 - pcie);
91 - if (ret) {
92 - dev_err(dev, "Failed to register interrupt\n");
93 - return ret;
94 - }
95 + pcie->irq = platform_get_irq(pdev, 0);
96 + if (pcie->irq < 0)
97 + return pcie->irq;
98
99 pcie->reset_gpio = devm_gpiod_get_from_of_node(dev, dev->of_node,
100 "reset-gpios", 0,
101 @@ -1670,11 +1668,14 @@ static int advk_pcie_probe(struct platfo
102 return ret;
103 }
104
105 + irq_set_chained_handler_and_data(pcie->irq, advk_pcie_irq_handler, pcie);
106 +
107 bridge->sysdata = pcie;
108 bridge->ops = &advk_pcie_ops;
109
110 ret = pci_host_probe(bridge);
111 if (ret < 0) {
112 + irq_set_chained_handler_and_data(pcie->irq, NULL, NULL);
113 advk_pcie_remove_msi_irq_domain(pcie);
114 advk_pcie_remove_irq_domain(pcie);
115 return ret;
116 @@ -1722,6 +1723,9 @@ static int advk_pcie_remove(struct platf
117 advk_writel(pcie, PCIE_ISR1_ALL_MASK, PCIE_ISR1_REG);
118 advk_writel(pcie, PCIE_IRQ_ALL_MASK, HOST_CTRL_INT_STATUS_REG);
119
120 + /* Remove IRQ handler */
121 + irq_set_chained_handler_and_data(pcie->irq, NULL, NULL);
122 +
123 /* Remove IRQ domains */
124 advk_pcie_remove_msi_irq_domain(pcie);
125 advk_pcie_remove_irq_domain(pcie);