2 * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
4 * Author: John Rigby, <jrigby@freescale.com>
7 * MPC5121ADS CPLD irq handling
9 * This is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
17 #include <linux/kernel.h>
18 #include <linux/interrupt.h>
19 #include <linux/irq.h>
23 static struct device_node *cpld_pic_node;
24 static struct irq_host *cpld_pic_host;
27 * Bits to ignore in the misc_status register
28 * 0x10 touch screen pendown is hard routed to irq1
29 * 0x02 pci status is read from pci status register
31 #define MISC_IGNORE 0x12
34 * Nothing to ignore in pci status register
36 #define PCI_IGNORE 0x00
47 static struct cpld_pic __iomem *cpld_regs;
50 irq_to_pic_mask(unsigned int irq)
52 return irq <= 7 ? &cpld_regs->pci_mask : &cpld_regs->misc_mask;
56 irq_to_pic_bit(unsigned int irq)
58 return 1 << (irq & 0x7);
62 cpld_mask_irq(unsigned int irq)
64 unsigned int cpld_irq = (unsigned int)irq_map[irq].hwirq;
65 void __iomem *pic_mask = irq_to_pic_mask(cpld_irq);
68 in_8(pic_mask) | irq_to_pic_bit(cpld_irq));
72 cpld_unmask_irq(unsigned int irq)
74 unsigned int cpld_irq = (unsigned int)irq_map[irq].hwirq;
75 void __iomem *pic_mask = irq_to_pic_mask(cpld_irq);
78 in_8(pic_mask) & ~irq_to_pic_bit(cpld_irq));
81 static struct irq_chip cpld_pic = {
83 .mask = cpld_mask_irq,
85 .unmask = cpld_unmask_irq,
89 cpld_pic_get_irq(int offset, u8 ignore, u8 __iomem *statusp,
93 u8 status = in_8(statusp);
94 u8 mask = in_8(maskp);
96 /* ignore don't cares and masked irqs */
97 status |= (ignore | mask);
100 return NO_IRQ_IGNORE;
102 cpld_irq = ffz(status) + offset;
104 return irq_linear_revmap(cpld_pic_host, cpld_irq);
108 cpld_pic_cascade(unsigned int irq, struct irq_desc *desc)
110 irq = cpld_pic_get_irq(0, PCI_IGNORE, &cpld_regs->pci_status,
111 &cpld_regs->pci_mask);
112 if (irq != NO_IRQ && irq != NO_IRQ_IGNORE) {
113 generic_handle_irq(irq);
117 irq = cpld_pic_get_irq(8, MISC_IGNORE, &cpld_regs->misc_status,
118 &cpld_regs->misc_mask);
119 if (irq != NO_IRQ && irq != NO_IRQ_IGNORE) {
120 generic_handle_irq(irq);
126 cpld_pic_host_match(struct irq_host *h, struct device_node *node)
128 return cpld_pic_node == node;
132 cpld_pic_host_map(struct irq_host *h, unsigned int virq,
135 irq_to_desc(virq)->status |= IRQ_LEVEL;
136 set_irq_chip_and_handler(virq, &cpld_pic, handle_level_irq);
141 irq_host_ops cpld_pic_host_ops = {
142 .match = cpld_pic_host_match,
143 .map = cpld_pic_host_map,
147 mpc5121_ads_cpld_map(void)
149 struct device_node *np = NULL;
151 np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121ads-cpld-pic");
153 printk(KERN_ERR "CPLD PIC init: can not find cpld-pic node\n");
157 cpld_regs = of_iomap(np, 0);
162 mpc5121_ads_cpld_pic_init(void)
164 unsigned int cascade_irq;
165 struct device_node *np = NULL;
167 pr_debug("cpld_ic_init\n");
169 np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121ads-cpld-pic");
171 printk(KERN_ERR "CPLD PIC init: can not find cpld-pic node\n");
178 cascade_irq = irq_of_parse_and_map(np, 0);
179 if (cascade_irq == NO_IRQ)
183 * statically route touch screen pendown through 1
185 * route all others through our cascade irq
187 out_8(&cpld_regs->route, 0xfd);
188 out_8(&cpld_regs->pci_mask, 0xff);
189 /* unmask pci ints in misc mask */
190 out_8(&cpld_regs->misc_mask, ~(MISC_IGNORE));
192 cpld_pic_node = of_node_get(np);
195 irq_alloc_host(np, IRQ_HOST_MAP_LINEAR, 16, &cpld_pic_host_ops, 16);
196 if (!cpld_pic_host) {
197 printk(KERN_ERR "CPLD PIC: failed to allocate irq host!\n");
201 set_irq_chained_handler(cascade_irq, cpld_pic_cascade);