1 // SPDX-License-Identifier: GPL-2.0
3 * Interrupt controller for the
4 * Communication Processor Module.
5 * Copyright (c) 1997 Dan error_act (dmalek@jlc.net)
7 #include <linux/kernel.h>
8 #include <linux/interrupt.h>
9 #include <linux/irqdomain.h>
10 #include <linux/platform_device.h>
14 cpic8xx_t __iomem *reg;
15 struct irq_domain *host;
18 static void cpm_mask_irq(struct irq_data *d)
20 struct cpm_pic_data *data = irq_data_get_irq_chip_data(d);
21 unsigned int cpm_vec = (unsigned int)irqd_to_hwirq(d);
23 clrbits32(&data->reg->cpic_cimr, (1 << cpm_vec));
26 static void cpm_unmask_irq(struct irq_data *d)
28 struct cpm_pic_data *data = irq_data_get_irq_chip_data(d);
29 unsigned int cpm_vec = (unsigned int)irqd_to_hwirq(d);
31 setbits32(&data->reg->cpic_cimr, (1 << cpm_vec));
34 static void cpm_end_irq(struct irq_data *d)
36 struct cpm_pic_data *data = irq_data_get_irq_chip_data(d);
37 unsigned int cpm_vec = (unsigned int)irqd_to_hwirq(d);
39 out_be32(&data->reg->cpic_cisr, (1 << cpm_vec));
42 static struct irq_chip cpm_pic = {
44 .irq_mask = cpm_mask_irq,
45 .irq_unmask = cpm_unmask_irq,
46 .irq_eoi = cpm_end_irq,
49 static int cpm_get_irq(struct irq_desc *desc)
51 struct cpm_pic_data *data = irq_desc_get_handler_data(desc);
55 * Get the vector by setting the ACK bit and then reading
58 out_be16(&data->reg->cpic_civr, 1);
59 cpm_vec = in_be16(&data->reg->cpic_civr);
62 return irq_linear_revmap(data->host, cpm_vec);
65 static void cpm_cascade(struct irq_desc *desc)
67 generic_handle_irq(cpm_get_irq(desc));
70 static int cpm_pic_host_map(struct irq_domain *h, unsigned int virq,
73 irq_set_chip_data(virq, h->host_data);
74 irq_set_status_flags(virq, IRQ_LEVEL);
75 irq_set_chip_and_handler(virq, &cpm_pic, handle_fasteoi_irq);
79 static const struct irq_domain_ops cpm_pic_host_ops = {
80 .map = cpm_pic_host_map,
83 static int cpm_pic_probe(struct platform_device *pdev)
85 struct device *dev = &pdev->dev;
88 struct cpm_pic_data *data;
90 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
94 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
98 data->reg = devm_ioremap(dev, res->start, resource_size(res));
102 irq = platform_get_irq(pdev, 0);
106 /* Initialize the CPM interrupt controller. */
107 out_be32(&data->reg->cpic_cicr,
108 (CICR_SCD_SCC4 | CICR_SCC_SCC3 | CICR_SCB_SCC2 | CICR_SCA_SCC1) |
109 ((virq_to_hw(irq) / 2) << 13) | CICR_HP_MASK);
111 out_be32(&data->reg->cpic_cimr, 0);
113 data->host = irq_domain_add_linear(dev->of_node, 64, &cpm_pic_host_ops, data);
117 irq_set_handler_data(irq, data);
118 irq_set_chained_handler(irq, cpm_cascade);
120 setbits32(&data->reg->cpic_cicr, CICR_IEN);
125 static const struct of_device_id cpm_pic_match[] = {
127 .compatible = "fsl,cpm1-pic",
134 static struct platform_driver cpm_pic_driver = {
137 .of_match_table = cpm_pic_match,
139 .probe = cpm_pic_probe,
142 static int __init cpm_pic_init(void)
144 return platform_driver_register(&cpm_pic_driver);
146 arch_initcall(cpm_pic_init);
149 * The CPM can generate the error interrupt when there is a race condition
150 * between generating and masking interrupts. All we have to do is ACK it
151 * and return. This is a no-op function so we don't need any special
152 * tests in the interrupt handler.
154 static irqreturn_t cpm_error_interrupt(int irq, void *dev)
159 static int cpm_error_probe(struct platform_device *pdev)
163 irq = platform_get_irq(pdev, 0);
167 return request_irq(irq, cpm_error_interrupt, IRQF_NO_THREAD, "error", NULL);
170 static const struct of_device_id cpm_error_ids[] = {
171 { .compatible = "fsl,cpm1" },
176 static struct platform_driver cpm_error_driver = {
179 .of_match_table = cpm_error_ids,
181 .probe = cpm_error_probe,
184 static int __init cpm_error_init(void)
186 return platform_driver_register(&cpm_error_driver);
188 subsys_initcall(cpm_error_init);