21 #define SOCRATES_FPGA_NUM_IRQS 9
23 #define FPGA_PIC_IRQCFG (0x0)
24 #define FPGA_PIC_IRQMASK(n) (0x4 + 0x4 * (n))
26 #define SOCRATES_FPGA_IRQ_MASK ((1 << SOCRATES_FPGA_NUM_IRQS) - 1)
53 static void __iomem *socrates_fpga_pic_iobase;
54 static struct irq_domain *socrates_fpga_pic_irq_host;
55 static unsigned int socrates_fpga_irqs[3];
57 static inline uint32_t socrates_fpga_pic_read(
int reg)
59 return in_be32(socrates_fpga_pic_iobase + reg);
64 out_be32(socrates_fpga_pic_iobase + reg, val);
67 static inline unsigned int socrates_fpga_pic_get_irq(
unsigned int irq)
74 for (i = 0; i < 3; i++) {
75 if (irq == socrates_fpga_irqs[i])
85 if (cause >> (i + 16))
101 cascade_irq = socrates_fpga_pic_get_irq(irq);
103 if (cascade_irq !=
NO_IRQ)
108 static void socrates_fpga_pic_ack(
struct irq_data *
d)
111 unsigned int irq_line, hwirq = irqd_to_hwirq(d);
114 irq_line = fpga_irqs[hwirq].
irq_line;
118 mask |= (1 << (hwirq + 16));
123 static void socrates_fpga_pic_mask(
struct irq_data *d)
126 unsigned int hwirq = irqd_to_hwirq(d);
130 irq_line = fpga_irqs[hwirq].
irq_line;
134 mask &= ~(1 << hwirq);
139 static void socrates_fpga_pic_mask_ack(
struct irq_data *d)
142 unsigned int hwirq = irqd_to_hwirq(d);
146 irq_line = fpga_irqs[hwirq].
irq_line;
150 mask &= ~(1 << hwirq);
151 mask |= (1 << (hwirq + 16));
156 static void socrates_fpga_pic_unmask(
struct irq_data *d)
159 unsigned int hwirq = irqd_to_hwirq(d);
163 irq_line = fpga_irqs[hwirq].
irq_line;
167 mask |= (1 << hwirq);
172 static void socrates_fpga_pic_eoi(
struct irq_data *d)
175 unsigned int hwirq = irqd_to_hwirq(d);
179 irq_line = fpga_irqs[hwirq].
irq_line;
183 mask |= (1 << (hwirq + 16));
188 static int socrates_fpga_pic_set_type(
struct irq_data *d,
189 unsigned int flow_type)
192 unsigned int hwirq = irqd_to_hwirq(d);
212 mask |= (1 << hwirq);
214 mask &= ~(1 << hwirq);
220 static struct irq_chip socrates_fpga_pic_chip = {
222 .irq_ack = socrates_fpga_pic_ack,
223 .irq_mask = socrates_fpga_pic_mask,
224 .irq_mask_ack = socrates_fpga_pic_mask_ack,
225 .irq_unmask = socrates_fpga_pic_unmask,
226 .irq_eoi = socrates_fpga_pic_eoi,
227 .irq_set_type = socrates_fpga_pic_set_type,
230 static int socrates_fpga_pic_host_map(
struct irq_domain *
h,
unsigned int virq,
235 irq_set_chip_and_handler(virq, &socrates_fpga_pic_chip,
241 static int socrates_fpga_pic_host_xlate(
struct irq_domain *
h,
247 *out_hwirq = intspec[0];
253 "setting default active low\n");
256 *out_flags = intspec[1];
260 *out_flags = fpga_irq->
type;
267 pr_warning(
"FPGA PIC: invalid irq routing\n");
273 .map = socrates_fpga_pic_host_map,
274 .xlate = socrates_fpga_pic_host_xlate,
285 if (socrates_fpga_pic_irq_host ==
NULL) {
286 pr_err(
"FPGA PIC: Unable to allocate host\n");
290 for (i = 0; i < 3; i++) {
292 if (socrates_fpga_irqs[i] ==
NO_IRQ) {
293 pr_warning(
"FPGA PIC: can't get irq%d.\n", i);
296 irq_set_chained_handler(socrates_fpga_irqs[i],
300 socrates_fpga_pic_iobase =
of_iomap(pic, 0);
311 pr_info(
"FPGA PIC: Setting up Socrates FPGA PIC\n");