blob: 5812fefbcedf1ac2685760c1d40fff52076cf054 [file] [log] [blame]
Paul Mundtbbfbd8b2008-10-01 16:13:54 +09001#ifndef __SH_INTC_H
2#define __SH_INTC_H
3
Magnus Dammdec710b2010-03-19 16:48:01 +09004#include <linux/ioport.h>
5
Paul Mundtbbfbd8b2008-10-01 16:13:54 +09006typedef unsigned char intc_enum;
7
8struct intc_vect {
9 intc_enum enum_id;
10 unsigned short vect;
11};
12
13#define INTC_VECT(enum_id, vect) { enum_id, vect }
14#define INTC_IRQ(enum_id, irq) INTC_VECT(enum_id, irq2evt(irq))
15
16struct intc_group {
17 intc_enum enum_id;
18 intc_enum enum_ids[32];
19};
20
21#define INTC_GROUP(enum_id, ids...) { enum_id, { ids } }
22
Paul Mundtc1e30ad2010-10-05 04:47:03 +090023struct intc_subgroup {
24 unsigned long reg, reg_width;
25 intc_enum parent_id;
26 intc_enum enum_ids[32];
27};
28
Paul Mundtbbfbd8b2008-10-01 16:13:54 +090029struct intc_mask_reg {
30 unsigned long set_reg, clr_reg, reg_width;
31 intc_enum enum_ids[32];
Paul Mundtdc825b12010-04-15 13:13:52 +090032#ifdef CONFIG_INTC_BALANCING
33 unsigned long dist_reg;
34#endif
Paul Mundtbbfbd8b2008-10-01 16:13:54 +090035#ifdef CONFIG_SMP
36 unsigned long smp;
37#endif
38};
39
40struct intc_prio_reg {
41 unsigned long set_reg, clr_reg, reg_width, field_width;
42 intc_enum enum_ids[16];
43#ifdef CONFIG_SMP
44 unsigned long smp;
45#endif
46};
47
48struct intc_sense_reg {
49 unsigned long reg, reg_width, field_width;
50 intc_enum enum_ids[16];
51};
52
Paul Mundtdc825b12010-04-15 13:13:52 +090053#ifdef CONFIG_INTC_BALANCING
54#define INTC_SMP_BALANCING(reg) .dist_reg = (reg)
55#else
56#define INTC_SMP_BALANCING(reg)
57#endif
58
Paul Mundtbbfbd8b2008-10-01 16:13:54 +090059#ifdef CONFIG_SMP
Paul Mundtdc825b12010-04-15 13:13:52 +090060#define INTC_SMP(stride, nr) .smp = (stride) | ((nr) << 8)
Paul Mundtbbfbd8b2008-10-01 16:13:54 +090061#else
62#define INTC_SMP(stride, nr)
63#endif
64
Magnus Damm577cd752010-02-09 04:24:46 +000065struct intc_hw_desc {
Paul Mundtbbfbd8b2008-10-01 16:13:54 +090066 struct intc_vect *vectors;
67 unsigned int nr_vectors;
68 struct intc_group *groups;
69 unsigned int nr_groups;
70 struct intc_mask_reg *mask_regs;
71 unsigned int nr_mask_regs;
72 struct intc_prio_reg *prio_regs;
73 unsigned int nr_prio_regs;
74 struct intc_sense_reg *sense_regs;
75 unsigned int nr_sense_regs;
Paul Mundtbbfbd8b2008-10-01 16:13:54 +090076 struct intc_mask_reg *ack_regs;
77 unsigned int nr_ack_regs;
Paul Mundtc1e30ad2010-10-05 04:47:03 +090078 struct intc_subgroup *subgroups;
79 unsigned int nr_subgroups;
Paul Mundtbbfbd8b2008-10-01 16:13:54 +090080};
81
Paul Mundt99870bd2010-11-08 17:02:26 +090082#define _INTC_ARRAY(a) a, __same_type(a, NULL) ? 0 : sizeof(a)/sizeof(*a)
Paul Mundtc1e30ad2010-10-05 04:47:03 +090083
Magnus Damm577cd752010-02-09 04:24:46 +000084#define INTC_HW_DESC(vectors, groups, mask_regs, \
85 prio_regs, sense_regs, ack_regs) \
86{ \
87 _INTC_ARRAY(vectors), _INTC_ARRAY(groups), \
88 _INTC_ARRAY(mask_regs), _INTC_ARRAY(prio_regs), \
89 _INTC_ARRAY(sense_regs), _INTC_ARRAY(ack_regs), \
90}
91
92struct intc_desc {
93 char *name;
Magnus Dammdec710b2010-03-19 16:48:01 +090094 struct resource *resource;
95 unsigned int num_resources;
Magnus Dammd5190952010-02-09 04:29:22 +000096 intc_enum force_enable;
Magnus Dammd85429a2010-02-15 11:40:25 +000097 intc_enum force_disable;
Magnus Damm577cd752010-02-09 04:24:46 +000098 struct intc_hw_desc hw;
99};
100
Paul Mundtbbfbd8b2008-10-01 16:13:54 +0900101#define DECLARE_INTC_DESC(symbol, chipname, vectors, groups, \
102 mask_regs, prio_regs, sense_regs) \
103struct intc_desc symbol __initdata = { \
Magnus Damm577cd752010-02-09 04:24:46 +0000104 .name = chipname, \
105 .hw = INTC_HW_DESC(vectors, groups, mask_regs, \
106 prio_regs, sense_regs, NULL), \
Paul Mundtbbfbd8b2008-10-01 16:13:54 +0900107}
108
Paul Mundtbbfbd8b2008-10-01 16:13:54 +0900109#define DECLARE_INTC_DESC_ACK(symbol, chipname, vectors, groups, \
110 mask_regs, prio_regs, sense_regs, ack_regs) \
111struct intc_desc symbol __initdata = { \
Magnus Damm577cd752010-02-09 04:24:46 +0000112 .name = chipname, \
113 .hw = INTC_HW_DESC(vectors, groups, mask_regs, \
114 prio_regs, sense_regs, ack_regs), \
Paul Mundtbbfbd8b2008-10-01 16:13:54 +0900115}
Paul Mundtbbfbd8b2008-10-01 16:13:54 +0900116
Paul Mundt2be6bb0c2010-10-05 22:10:30 +0900117int register_intc_controller(struct intc_desc *desc);
Paul Mundt4bacd792010-10-02 22:02:07 +0900118void reserve_intc_vectors(struct intc_vect *vectors, unsigned int nr_vecs);
Paul Mundtbbfbd8b2008-10-01 16:13:54 +0900119int intc_set_priority(unsigned int irq, unsigned int prio);
Paul Mundtd74310d2010-10-05 18:13:23 +0900120int intc_irq_lookup(const char *chipname, intc_enum enum_id);
Paul Mundtc1e30ad2010-10-05 04:47:03 +0900121void intc_finalize(void);
Paul Mundtbbfbd8b2008-10-01 16:13:54 +0900122
Paul Mundt43b87742010-04-13 14:43:03 +0900123#ifdef CONFIG_INTC_USERIMASK
124int register_intc_userimask(unsigned long addr);
125#else
126static inline int register_intc_userimask(unsigned long addr)
127{
128 return 0;
129}
130#endif
131
Paul Mundtbbfbd8b2008-10-01 16:13:54 +0900132#endif /* __SH_INTC_H */