1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/stddef.h>
4 #include <linux/init.h>
5 #include <linux/sched.h>
6 #include <linux/signal.h>
8 #include <linux/dma-mapping.h>
12 #include <asm/8xx_immap.h>
14 #include "mpc8xx_pic.h"
17 #define PIC_VEC_SPURRIOUS 15
19 extern int cpm_get_irq(struct pt_regs
*regs
);
21 static struct irq_host
*mpc8xx_pic_host
;
22 #define NR_MASK_WORDS ((NR_IRQS + 31) / 32)
23 static unsigned long ppc_cached_irq_mask
[NR_MASK_WORDS
];
24 static sysconf8xx_t __iomem
*siu_reg
;
26 int cpm_get_irq(struct pt_regs
*regs
);
28 static void mpc8xx_unmask_irq(struct irq_data
*d
)
31 unsigned int irq_nr
= (unsigned int)irqd_to_hwirq(d
);
36 ppc_cached_irq_mask
[word
] |= (1 << (31-bit
));
37 out_be32(&siu_reg
->sc_simask
, ppc_cached_irq_mask
[word
]);
40 static void mpc8xx_mask_irq(struct irq_data
*d
)
43 unsigned int irq_nr
= (unsigned int)irqd_to_hwirq(d
);
48 ppc_cached_irq_mask
[word
] &= ~(1 << (31-bit
));
49 out_be32(&siu_reg
->sc_simask
, ppc_cached_irq_mask
[word
]);
52 static void mpc8xx_ack(struct irq_data
*d
)
55 unsigned int irq_nr
= (unsigned int)irqd_to_hwirq(d
);
58 out_be32(&siu_reg
->sc_sipend
, 1 << (31-bit
));
61 static void mpc8xx_end_irq(struct irq_data
*d
)
64 unsigned int irq_nr
= (unsigned int)irqd_to_hwirq(d
);
69 ppc_cached_irq_mask
[word
] |= (1 << (31-bit
));
70 out_be32(&siu_reg
->sc_simask
, ppc_cached_irq_mask
[word
]);
73 static int mpc8xx_set_irq_type(struct irq_data
*d
, unsigned int flow_type
)
75 if (flow_type
& IRQ_TYPE_EDGE_FALLING
) {
76 irq_hw_number_t hw
= (unsigned int)irqd_to_hwirq(d
);
77 unsigned int siel
= in_be32(&siu_reg
->sc_siel
);
79 /* only external IRQ senses are programmable */
81 siel
|= (0x80000000 >> hw
);
82 out_be32(&siu_reg
->sc_siel
, siel
);
83 __irq_set_handler_locked(d
->irq
, handle_edge_irq
);
89 static struct irq_chip mpc8xx_pic
= {
91 .irq_unmask
= mpc8xx_unmask_irq
,
92 .irq_mask
= mpc8xx_mask_irq
,
93 .irq_ack
= mpc8xx_ack
,
94 .irq_eoi
= mpc8xx_end_irq
,
95 .irq_set_type
= mpc8xx_set_irq_type
,
98 unsigned int mpc8xx_get_irq(void)
102 /* For MPC8xx, read the SIVEC register and shift the bits down
103 * to get the irq number.
105 irq
= in_be32(&siu_reg
->sc_sivec
) >> 26;
107 if (irq
== PIC_VEC_SPURRIOUS
)
110 return irq_linear_revmap(mpc8xx_pic_host
, irq
);
114 static int mpc8xx_pic_host_map(struct irq_host
*h
, unsigned int virq
,
117 pr_debug("mpc8xx_pic_host_map(%d, 0x%lx)\n", virq
, hw
);
119 /* Set default irq handle */
120 irq_set_chip_and_handler(virq
, &mpc8xx_pic
, handle_level_irq
);
125 static int mpc8xx_pic_host_xlate(struct irq_host
*h
, struct device_node
*ct
,
126 const u32
*intspec
, unsigned int intsize
,
127 irq_hw_number_t
*out_hwirq
, unsigned int *out_flags
)
129 static unsigned char map_pic_senses
[4] = {
130 IRQ_TYPE_EDGE_RISING
,
133 IRQ_TYPE_EDGE_FALLING
,
136 *out_hwirq
= intspec
[0];
137 if (intsize
> 1 && intspec
[1] < 4)
138 *out_flags
= map_pic_senses
[intspec
[1]];
140 *out_flags
= IRQ_TYPE_NONE
;
146 static struct irq_host_ops mpc8xx_pic_host_ops
= {
147 .map
= mpc8xx_pic_host_map
,
148 .xlate
= mpc8xx_pic_host_xlate
,
151 int mpc8xx_pic_init(void)
154 struct device_node
*np
;
157 np
= of_find_compatible_node(NULL
, NULL
, "fsl,pq1-pic");
159 np
= of_find_node_by_type(NULL
, "mpc8xx-pic");
161 printk(KERN_ERR
"Could not find fsl,pq1-pic node\n");
165 ret
= of_address_to_resource(np
, 0, &res
);
169 siu_reg
= ioremap(res
.start
, res
.end
- res
.start
+ 1);
170 if (siu_reg
== NULL
) {
175 mpc8xx_pic_host
= irq_alloc_host(np
, IRQ_HOST_MAP_LINEAR
,
176 64, &mpc8xx_pic_host_ops
, 64);
177 if (mpc8xx_pic_host
== NULL
) {
178 printk(KERN_ERR
"MPC8xx PIC: failed to allocate irq host!\n");