fbed9cc5069efa9bfb168622a5d817c268359144
[openwrt/staging/wigyori.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 diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
25 index e68773527171..01dfe70d9c2c 100644
26 --- a/drivers/pci/controller/pci-aardvark.c
27 +++ b/drivers/pci/controller/pci-aardvark.c
28 @@ -275,6 +275,7 @@ struct advk_pcie {
29 u32 actions;
30 } wins[OB_WIN_COUNT];
31 u8 wins_count;
32 + int irq;
33 struct irq_domain *irq_domain;
34 struct irq_chip irq_chip;
35 raw_spinlock_t irq_lock;
36 @@ -1440,21 +1441,26 @@ static void advk_pcie_handle_int(struct advk_pcie *pcie)
37 }
38 }
39
40 -static irqreturn_t advk_pcie_irq_handler(int irq, void *arg)
41 +static void advk_pcie_irq_handler(struct irq_desc *desc)
42 {
43 - struct advk_pcie *pcie = arg;
44 - u32 status;
45 + struct advk_pcie *pcie = irq_desc_get_handler_data(desc);
46 + struct irq_chip *chip = irq_desc_get_chip(desc);
47 + u32 val, mask, status;
48
49 - status = advk_readl(pcie, HOST_CTRL_INT_STATUS_REG);
50 - if (!(status & PCIE_IRQ_CORE_INT))
51 - return IRQ_NONE;
52 + chained_irq_enter(chip, desc);
53
54 - advk_pcie_handle_int(pcie);
55 + val = advk_readl(pcie, HOST_CTRL_INT_STATUS_REG);
56 + mask = advk_readl(pcie, HOST_CTRL_INT_MASK_REG);
57 + status = val & ((~mask) & PCIE_IRQ_ALL_MASK);
58
59 - /* Clear interrupt */
60 - advk_writel(pcie, PCIE_IRQ_CORE_INT, HOST_CTRL_INT_STATUS_REG);
61 + if (status & PCIE_IRQ_CORE_INT) {
62 + advk_pcie_handle_int(pcie);
63
64 - return IRQ_HANDLED;
65 + /* Clear interrupt */
66 + advk_writel(pcie, PCIE_IRQ_CORE_INT, HOST_CTRL_INT_STATUS_REG);
67 + }
68 +
69 + chained_irq_exit(chip, desc);
70 }
71
72 static void __maybe_unused advk_pcie_disable_phy(struct advk_pcie *pcie)
73 @@ -1521,7 +1527,7 @@ static int advk_pcie_probe(struct platform_device *pdev)
74 struct advk_pcie *pcie;
75 struct pci_host_bridge *bridge;
76 struct resource_entry *entry;
77 - int ret, irq;
78 + int ret;
79
80 bridge = devm_pci_alloc_host_bridge(dev, sizeof(struct advk_pcie));
81 if (!bridge)
82 @@ -1609,17 +1615,9 @@ static int advk_pcie_probe(struct platform_device *pdev)
83 if (IS_ERR(pcie->base))
84 return PTR_ERR(pcie->base);
85
86 - irq = platform_get_irq(pdev, 0);
87 - if (irq < 0)
88 - return irq;
89 -
90 - ret = devm_request_irq(dev, irq, advk_pcie_irq_handler,
91 - IRQF_SHARED | IRQF_NO_THREAD, "advk-pcie",
92 - pcie);
93 - if (ret) {
94 - dev_err(dev, "Failed to register interrupt\n");
95 - return ret;
96 - }
97 + pcie->irq = platform_get_irq(pdev, 0);
98 + if (pcie->irq < 0)
99 + return pcie->irq;
100
101 pcie->reset_gpio = devm_gpiod_get_from_of_node(dev, dev->of_node,
102 "reset-gpios", 0,
103 @@ -1668,11 +1666,14 @@ static int advk_pcie_probe(struct platform_device *pdev)
104 return ret;
105 }
106
107 + irq_set_chained_handler_and_data(pcie->irq, advk_pcie_irq_handler, pcie);
108 +
109 bridge->sysdata = pcie;
110 bridge->ops = &advk_pcie_ops;
111
112 ret = pci_host_probe(bridge);
113 if (ret < 0) {
114 + irq_set_chained_handler_and_data(pcie->irq, NULL, NULL);
115 advk_pcie_remove_msi_irq_domain(pcie);
116 advk_pcie_remove_irq_domain(pcie);
117 return ret;
118 @@ -1720,6 +1721,9 @@ static int advk_pcie_remove(struct platform_device *pdev)
119 advk_writel(pcie, PCIE_ISR1_ALL_MASK, PCIE_ISR1_REG);
120 advk_writel(pcie, PCIE_IRQ_ALL_MASK, HOST_CTRL_INT_STATUS_REG);
121
122 + /* Remove IRQ handler */
123 + irq_set_chained_handler_and_data(pcie->irq, NULL, NULL);
124 +
125 /* Remove IRQ domains */
126 advk_pcie_remove_msi_irq_domain(pcie);
127 advk_pcie_remove_irq_domain(pcie);
128 --
129 2.34.1
130