1 From a522ee0199d5d3ea114ca2e211f6ac398d3e8e0b Mon Sep 17 00:00:00 2001
2 From: John Crispin <john@phrozen.org>
3 Date: Sat, 23 Jun 2018 15:07:37 +0200
4 Subject: [PATCH 20/33] MIPS: pci-ar724x: convert to OF
6 With the ath79 target getting converted to pure OF, we can drop all the
7 platform data code and add the missing OF bits to the driver. We also add
8 a irq domain for the PCI/e controllers cascade, thus making it usable from
11 Signed-off-by: John Crispin <john@phrozen.org>
13 arch/mips/pci/pci-ar724x.c | 88 ++++++++++++++++++++++------------------------
14 1 file changed, 42 insertions(+), 46 deletions(-)
16 --- a/arch/mips/pci/pci-ar724x.c
17 +++ b/arch/mips/pci/pci-ar724x.c
19 #include <linux/init.h>
20 #include <linux/delay.h>
21 #include <linux/platform_device.h>
22 +#include <linux/irqchip/chained_irq.h>
23 #include <asm/mach-ath79/ath79.h>
24 #include <asm/mach-ath79/ar71xx_regs.h>
25 +#include <linux/of_irq.h>
26 +#include <linux/of_pci.h>
28 #define AR724X_PCI_REG_APP 0x00
29 #define AR724X_PCI_REG_RESET 0x18
30 @@ -42,17 +45,20 @@ struct ar724x_pci_controller {
31 void __iomem *crp_base;
40 + struct device_node *np;
41 struct pci_controller pci_controller;
42 + struct irq_domain *domain;
43 struct resource io_res;
44 struct resource mem_res;
47 +static struct irq_chip ar724x_pci_irq_chip;
49 static inline bool ar724x_pci_check_link(struct ar724x_pci_controller *apc)
52 @@ -228,35 +234,31 @@ static struct pci_ops ar724x_pci_ops = {
54 static void ar724x_pci_irq_handler(struct irq_desc *desc)
56 - struct ar724x_pci_controller *apc;
58 + struct irq_chip *chip = irq_desc_get_chip(desc);
59 + struct ar724x_pci_controller *apc = irq_desc_get_handler_data(desc);
62 - apc = irq_desc_get_handler_data(desc);
63 - base = apc->ctrl_base;
65 - pending = __raw_readl(base + AR724X_PCI_REG_INT_STATUS) &
66 - __raw_readl(base + AR724X_PCI_REG_INT_MASK);
67 + chained_irq_enter(chip, desc);
68 + pending = __raw_readl(apc->ctrl_base + AR724X_PCI_REG_INT_STATUS) &
69 + __raw_readl(apc->ctrl_base + AR724X_PCI_REG_INT_MASK);
71 if (pending & AR724X_PCI_INT_DEV0)
72 - generic_handle_irq(apc->irq_base + 0);
74 + generic_handle_irq(irq_linear_revmap(apc->domain, 1));
77 + chained_irq_exit(chip, desc);
80 static void ar724x_pci_irq_unmask(struct irq_data *d)
82 struct ar724x_pci_controller *apc;
87 apc = irq_data_get_irq_chip_data(d);
88 base = apc->ctrl_base;
89 - offset = apc->irq_base - d->irq;
92 + switch (irq_linear_revmap(apc->domain, d->irq)) {
94 t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
95 __raw_writel(t | AR724X_PCI_INT_DEV0,
96 @@ -270,14 +272,12 @@ static void ar724x_pci_irq_mask(struct i
98 struct ar724x_pci_controller *apc;
103 apc = irq_data_get_irq_chip_data(d);
104 base = apc->ctrl_base;
105 - offset = apc->irq_base - d->irq;
108 + switch (irq_linear_revmap(apc->domain, d->irq)) {
110 t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
111 __raw_writel(t & ~AR724X_PCI_INT_DEV0,
112 @@ -302,26 +302,34 @@ static struct irq_chip ar724x_pci_irq_ch
113 .irq_mask_ack = ar724x_pci_irq_mask,
116 +static int ar724x_pci_irq_map(struct irq_domain *d,
117 + unsigned int irq, irq_hw_number_t hw)
119 + struct ar724x_pci_controller *apc = d->host_data;
121 + irq_set_chip_and_handler(irq, &ar724x_pci_irq_chip, handle_level_irq);
122 + irq_set_chip_data(irq, apc);
127 +static const struct irq_domain_ops ar724x_pci_domain_ops = {
128 + .xlate = irq_domain_xlate_onecell,
129 + .map = ar724x_pci_irq_map,
132 static void ar724x_pci_irq_init(struct ar724x_pci_controller *apc,
138 base = apc->ctrl_base;
140 __raw_writel(0, base + AR724X_PCI_REG_INT_MASK);
141 __raw_writel(0, base + AR724X_PCI_REG_INT_STATUS);
143 - apc->irq_base = ATH79_PCI_IRQ_BASE + (id * AR724X_PCI_IRQ_COUNT);
145 - for (i = apc->irq_base;
146 - i < apc->irq_base + AR724X_PCI_IRQ_COUNT; i++) {
147 - irq_set_chip_and_handler(i, &ar724x_pci_irq_chip,
149 - irq_set_chip_data(i, apc);
152 + apc->domain = irq_domain_add_linear(apc->np, 2,
153 + &ar724x_pci_domain_ops, apc);
154 irq_set_chained_handler_and_data(apc->irq, ar724x_pci_irq_handler,
157 @@ -388,29 +396,11 @@ static int ar724x_pci_probe(struct platf
161 - res = platform_get_resource_byname(pdev, IORESOURCE_IO, "io_base");
165 - apc->io_res.parent = res;
166 - apc->io_res.name = "PCI IO space";
167 - apc->io_res.start = res->start;
168 - apc->io_res.end = res->end;
169 - apc->io_res.flags = IORESOURCE_IO;
171 - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem_base");
175 - apc->mem_res.parent = res;
176 - apc->mem_res.name = "PCI memory space";
177 - apc->mem_res.start = res->start;
178 - apc->mem_res.end = res->end;
179 - apc->mem_res.flags = IORESOURCE_MEM;
181 + apc->np = pdev->dev.of_node;
182 apc->pci_controller.pci_ops = &ar724x_pci_ops;
183 apc->pci_controller.io_resource = &apc->io_res;
184 apc->pci_controller.mem_resource = &apc->mem_res;
185 + pci_load_of_ranges(&apc->pci_controller, pdev->dev.of_node);
188 * Do the full PCIE Root Complex Initialization Sequence if the PCIe
189 @@ -432,10 +422,16 @@ static int ar724x_pci_probe(struct platf
193 +static const struct of_device_id ar724x_pci_ids[] = {
194 + { .compatible = "qcom,ar7240-pci" },
198 static struct platform_driver ar724x_pci_driver = {
199 .probe = ar724x_pci_probe,
201 .name = "ar724x-pci",
202 + .of_match_table = of_match_ptr(ar724x_pci_ids),