1 // SPDX-License-Identifier: GPL-2.0-only
3 * PQ2 ADS-style PCI interrupt controller
5 * Copyright 2007 Freescale Semiconductor, Inc.
6 * Author: Scott Wood <scottwood@freescale.com>
8 * Loosely based on mpc82xx ADS support by Vitaly Bordug <vbordug@ru.mvista.com>
9 * Copyright (c) 2006 MontaVista Software, Inc.
12 #include <linux/init.h>
13 #include <linux/spinlock.h>
14 #include <linux/irq.h>
15 #include <linux/types.h>
16 #include <linux/slab.h>
24 static DEFINE_RAW_SPINLOCK(pci_pic_lock);
26 struct pq2ads_pci_pic {
27 struct device_node *node;
28 struct irq_domain *host;
38 static void pq2ads_pci_mask_irq(struct irq_data *d)
40 struct pq2ads_pci_pic *priv = irq_data_get_irq_chip_data(d);
41 int irq = NUM_IRQS - irqd_to_hwirq(d) - 1;
45 raw_spin_lock_irqsave(&pci_pic_lock, flags);
47 setbits32(&priv->regs->mask, 1 << irq);
50 raw_spin_unlock_irqrestore(&pci_pic_lock, flags);
54 static void pq2ads_pci_unmask_irq(struct irq_data *d)
56 struct pq2ads_pci_pic *priv = irq_data_get_irq_chip_data(d);
57 int irq = NUM_IRQS - irqd_to_hwirq(d) - 1;
62 raw_spin_lock_irqsave(&pci_pic_lock, flags);
63 clrbits32(&priv->regs->mask, 1 << irq);
64 raw_spin_unlock_irqrestore(&pci_pic_lock, flags);
68 static struct irq_chip pq2ads_pci_ic = {
69 .name = "PQ2 ADS PCI",
70 .irq_mask = pq2ads_pci_mask_irq,
71 .irq_mask_ack = pq2ads_pci_mask_irq,
72 .irq_ack = pq2ads_pci_mask_irq,
73 .irq_unmask = pq2ads_pci_unmask_irq,
74 .irq_enable = pq2ads_pci_unmask_irq,
75 .irq_disable = pq2ads_pci_mask_irq
78 static void pq2ads_pci_irq_demux(struct irq_desc *desc)
80 struct pq2ads_pci_pic *priv = irq_desc_get_handler_data(desc);
85 stat = in_be32(&priv->regs->stat);
86 mask = in_be32(&priv->regs->mask);
93 for (bit = 0; pend != 0; ++bit, pend <<= 1) {
94 if (pend & 0x80000000) {
95 int virq = irq_linear_revmap(priv->host, bit);
96 generic_handle_irq(virq);
102 static int pci_pic_host_map(struct irq_domain *h, unsigned int virq,
105 irq_set_status_flags(virq, IRQ_LEVEL);
106 irq_set_chip_data(virq, h->host_data);
107 irq_set_chip_and_handler(virq, &pq2ads_pci_ic, handle_level_irq);
111 static const struct irq_domain_ops pci_pic_host_ops = {
112 .map = pci_pic_host_map,
115 int __init pq2ads_pci_init_irq(void)
117 struct pq2ads_pci_pic *priv;
118 struct irq_domain *host;
119 struct device_node *np;
123 np = of_find_compatible_node(NULL, NULL, "fsl,pq2ads-pci-pic");
125 printk(KERN_ERR "No pci pic node in device tree.\n");
130 irq = irq_of_parse_and_map(np, 0);
132 printk(KERN_ERR "No interrupt in pci pic node.\n");
137 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
144 /* PCI interrupt controller registers: status and mask */
145 priv->regs = of_iomap(np, 0);
147 printk(KERN_ERR "Cannot map PCI PIC registers.\n");
148 goto out_free_kmalloc;
151 /* mask all PCI interrupts */
152 out_be32(&priv->regs->mask, ~0);
155 host = irq_domain_add_linear(np, NUM_IRQS, &pci_pic_host_ops, priv);
162 irq_set_handler_data(irq, priv);
163 irq_set_chained_handler(irq, pq2ads_pci_irq_demux);
174 irq_dispose_mapping(irq);