2 * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
3 * Copyright (C) 2014 Stefan Kristansson <stefan.kristiansson@saunalahti.fi>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
11 #include <linux/irq.h>
13 #include <linux/of_irq.h>
14 #include <linux/of_address.h>
18 /* OR1K PIC implementation */
22 irq_flow_handler_t handle
;
27 * We're a couple of cycles faster than the generic implementations with
28 * these 'fast' versions.
31 static void or1k_pic_mask(struct irq_data
*data
)
33 mtspr(SPR_PICMR
, mfspr(SPR_PICMR
) & ~(1UL << data
->hwirq
));
36 static void or1k_pic_unmask(struct irq_data
*data
)
38 mtspr(SPR_PICMR
, mfspr(SPR_PICMR
) | (1UL << data
->hwirq
));
41 static void or1k_pic_ack(struct irq_data
*data
)
43 mtspr(SPR_PICSR
, (1UL << data
->hwirq
));
46 static void or1k_pic_mask_ack(struct irq_data
*data
)
48 mtspr(SPR_PICMR
, mfspr(SPR_PICMR
) & ~(1UL << data
->hwirq
));
49 mtspr(SPR_PICSR
, (1UL << data
->hwirq
));
53 * There are two oddities with the OR1200 PIC implementation:
54 * i) LEVEL-triggered interrupts are latched and need to be cleared
55 * ii) the interrupt latch is cleared by writing a 0 to the bit,
56 * as opposed to a 1 as mandated by the spec
58 static void or1k_pic_or1200_ack(struct irq_data
*data
)
60 mtspr(SPR_PICSR
, mfspr(SPR_PICSR
) & ~(1UL << data
->hwirq
));
63 static void or1k_pic_or1200_mask_ack(struct irq_data
*data
)
65 mtspr(SPR_PICMR
, mfspr(SPR_PICMR
) & ~(1UL << data
->hwirq
));
66 mtspr(SPR_PICSR
, mfspr(SPR_PICSR
) & ~(1UL << data
->hwirq
));
69 static struct or1k_pic_dev or1k_pic_level
= {
71 .name
= "or1k-PIC-level",
72 .irq_unmask
= or1k_pic_unmask
,
73 .irq_mask
= or1k_pic_mask
,
74 .irq_mask_ack
= or1k_pic_mask
,
76 .handle
= handle_level_irq
,
77 .flags
= IRQ_LEVEL
| IRQ_NOPROBE
,
80 static struct or1k_pic_dev or1k_pic_edge
= {
82 .name
= "or1k-PIC-edge",
83 .irq_unmask
= or1k_pic_unmask
,
84 .irq_mask
= or1k_pic_mask
,
85 .irq_ack
= or1k_pic_ack
,
86 .irq_mask_ack
= or1k_pic_mask_ack
,
88 .handle
= handle_edge_irq
,
89 .flags
= IRQ_LEVEL
| IRQ_NOPROBE
,
92 static struct or1k_pic_dev or1k_pic_or1200
= {
95 .irq_unmask
= or1k_pic_unmask
,
96 .irq_mask
= or1k_pic_mask
,
97 .irq_ack
= or1k_pic_or1200_ack
,
98 .irq_mask_ack
= or1k_pic_or1200_mask_ack
,
100 .handle
= handle_level_irq
,
101 .flags
= IRQ_LEVEL
| IRQ_NOPROBE
,
104 static struct irq_domain
*root_domain
;
106 static inline int pic_get_irq(int first
)
110 hwirq
= ffs(mfspr(SPR_PICSR
) >> first
);
114 hwirq
= hwirq
+ first
- 1;
119 static void or1k_pic_handle_irq(struct pt_regs
*regs
)
123 while ((irq
= pic_get_irq(irq
+ 1)) != NO_IRQ
)
124 handle_domain_irq(root_domain
, irq
, regs
);
127 static int or1k_map(struct irq_domain
*d
, unsigned int irq
, irq_hw_number_t hw
)
129 struct or1k_pic_dev
*pic
= d
->host_data
;
131 irq_set_chip_and_handler(irq
, &pic
->chip
, pic
->handle
);
132 irq_set_status_flags(irq
, pic
->flags
);
137 static const struct irq_domain_ops or1k_irq_domain_ops
= {
138 .xlate
= irq_domain_xlate_onecell
,
143 * This sets up the IRQ domain for the PIC built in to the OpenRISC
144 * 1000 CPU. This is the "root" domain as these are the interrupts
145 * that directly trigger an exception in the CPU.
147 static int __init
or1k_pic_init(struct device_node
*node
,
148 struct or1k_pic_dev
*pic
)
150 /* Disable all interrupts until explicitly requested */
151 mtspr(SPR_PICMR
, (0UL));
153 root_domain
= irq_domain_add_linear(node
, 32, &or1k_irq_domain_ops
,
156 set_handle_irq(or1k_pic_handle_irq
);
161 static int __init
or1k_pic_or1200_init(struct device_node
*node
,
162 struct device_node
*parent
)
164 return or1k_pic_init(node
, &or1k_pic_or1200
);
166 IRQCHIP_DECLARE(or1k_pic_or1200
, "opencores,or1200-pic", or1k_pic_or1200_init
);
167 IRQCHIP_DECLARE(or1k_pic
, "opencores,or1k-pic", or1k_pic_or1200_init
);
169 static int __init
or1k_pic_level_init(struct device_node
*node
,
170 struct device_node
*parent
)
172 return or1k_pic_init(node
, &or1k_pic_level
);
174 IRQCHIP_DECLARE(or1k_pic_level
, "opencores,or1k-pic-level",
175 or1k_pic_level_init
);
177 static int __init
or1k_pic_edge_init(struct device_node
*node
,
178 struct device_node
*parent
)
180 return or1k_pic_init(node
, &or1k_pic_edge
);
182 IRQCHIP_DECLARE(or1k_pic_edge
, "opencores,or1k-pic-edge", or1k_pic_edge_init
);