summaryrefslogtreecommitdiff
path: root/bsp/allwinner/libraries/sunxi-hal/hal/source/intc/intc_manager.c
blob: b29a0d852c2064d5298d793f5ac1310167b75210 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
*********************************************************************************************************
*                                                AR100 SYSTEM
*                                     AR100 Software System Develop Kits
*                                               interrupt manager
*
*                                    (c) Copyright 2012-2016, Sunny China
*                                             All Rights Reserved
*
* File    : interrupt_manager.c
* By      : Sunny
* Version : v1.0
* Date    : 2012-5-3
* Descript: the manager of interrupt.
* Update  : date                auther      ver     notes
*           2012-5-3 10:45:15   Sunny       1.0     Create this file.
*********************************************************************************************************
*/

#include <irqs.h>

#include "intc_i.h"
#include "platform-intc.h"

s32 interrupt_clear_pending(u32 intno);

struct int_isr_node isr_table[SUNXI_RINTC_IRQ_SOURCE_MAX];

/*
*********************************************************************************************************
*                                       INIT INTERRUPT MANAGER
*
* Description:  initialize interrupt manager.
*
* Arguments  :  none.
*
* Returns    :  OK if initialize interrupt manager succeeded, others if failed.
*********************************************************************************************************
*/
s32 interrupt_init(void)
{
    s32 index;

    /*initialize interrupt controller */
    intc_init();

    /*initialize ISR table */
    for (index = 0; index < SUNXI_RINTC_IRQ_SOURCE_MAX; index++) {
        isr_table[index].pisr = isr_default;
        isr_table[index].parg = NULL;
    }

    /*interrupt manager initialize succeeded */
    return OK;
}

/*
*********************************************************************************************************
*                                       EXIT INTERRUPT MANAGER
*
* Description:  exit interrupt manager.
*
* Arguments  :  none.
*
* Returns    :  OK if exit interrupt manager succeeded, others if failed.
*********************************************************************************************************
*/
s32 interrupt_exit(void)
{
    intc_exit();

    return OK;
}

/*
*********************************************************************************************************
*                                           ENABLE INTERRUPT
*
* Description:  enable a specific interrupt.
*
* Arguments  :  intno : the number of interrupt which we want to enable.
*
* Returns    :  OK if enable interrupt succeeded, others if failed.
*********************************************************************************************************
*/
s32 interrupt_enable(u32 intno)
{
    return intc_enable_interrupt(intno);
}

/*
*********************************************************************************************************
*                                           DISABLE INTERRUPT
*
* Description:  disable a specific interrupt.
*
* Arguments  :  intno : the number of interrupt which we want to disable.
*
* Returns    :  OK if disable interrupt succeeded, others if failed.
*********************************************************************************************************
*/
s32 interrupt_disable(u32 intno)
{
    return intc_disable_interrupt(intno);
}

/*
*********************************************************************************************************
*                                           SET NMI TRIGGER
*
* Description:  set nmi trigger.
*
* Arguments  :  type : the trigger type.
*
* Returns    :  OK if set trigger type succeeded, others if failed.
*********************************************************************************************************
*/
s32 interrupt_set_nmi_trigger(u32 type)
{
    u32 value;

    pintc_regs->control = type;

    /*mask cpus nmi irq */
    value = pintc_regs->mask;
    value |= 0x1;
    pintc_regs->mask = value;

    return OK;
}

s32 interrupt_set_mask(u32 intno, u32 mask)
{
    return intc_set_mask(intno, mask);
}

s32 interrupt_set_group_config(u32 grp_irq_num, u32 mask)
{
    return intc_set_group_config(grp_irq_num, mask);
}

/*
*********************************************************************************************************
*                                           INSTALL ISR
*
* Description:  install ISR for a specific interrupt.
*
* Arguments  :  intno   : the number of interrupt which we want to install ISR.
*       pisr    : the ISR which to been install.
*       parg    : the argument for the ISR.
*
* Returns    :  OK if install ISR succeeded, others if failed.
*
* Note       :  the ISR execute entironment : CPU disable interrupt response.
*********************************************************************************************************
*/
s32 install_isr(u32 intno, __pISR_hdle_t pisr, void *parg)
{
    /*intno can't beyond then IRQ_SOURCE_MAX */
    /* ASSERT(intno < IRQ_SOUCE_MAX); */

    /*default isr, install directly */
    isr_table[intno].pisr = pisr;
    isr_table[intno].parg = parg;

    return OK;
}

/*
*********************************************************************************************************
*                                           UNINSTALL ISR
*
* Description:  uninstall ISR for a specific interrupt.
*
* Arguments  :  intno   : the number of interrupt which we want to uninstall ISR.
*               pisr    : the ISR which to been uninstall.
*
* Returns    :  OK if uninstall ISR succeeded, others if failed.
*********************************************************************************************************
*/
s32 uninstall_isr(u32 intno, __pISR_hdle_t pisr)
{
    /*intno can't beyond then IRQ_SOURCE_MAX */
    /* ASSERT(intno < IRQ_SOUCE_MAX); */

    if (isr_table[intno].pisr == pisr) {
        /*uninstall isr */
        isr_table[intno].pisr = isr_default;
        isr_table[intno].parg = NULL;
    } else {
        /*
         * don't support shared interrupt now,
         * by sunny at 2012-5-3 11:20:28.
         */
        return -1;
    }

    return OK;
}

/*
*********************************************************************************************************
*                                           INTERRUPT ENTRY
*
* Description:  the entry of CPU IRQ, mainly for CPU IRQ exception.
*
* Arguments  :  none.
*
* Returns    :  OK if process CPU IRQ succeeded, others if failed.
*********************************************************************************************************
*/
s32 interrupt_entry(void)
{
    u32 intno = intc_get_current_interrupt();

    /*intno can't beyond then IRQ_SOURCE_MAX */
    /* ASSERT(intno < IRQ_SOUCE_MAX); */

    /*
     * process interrupt by call isr,
     * not support shared intterrupt.
     */
    (isr_table[intno].pisr) (0, isr_table[intno].parg);

    return OK;
}

s32 interrupt_query_pending(u32 intno)
{
    volatile u32 pending;

    if (intno <= 31)
        pending = pintc_regs->pending & (1 << intno);
    else if (intno > 31 && intno <= 63)
        pending = pintc_regs->pending1 & (1 << (intno - 32));
    else
        pending = pintc_regs->pending2 & (1 << (intno - 64));
    return pending;
}

s32 interrupt_clear_pending(u32 intno)
{
    if (intno <= 31)
        pintc_regs->pending = (1 << intno);
    else if (intno > 31 && intno <= 63)
        pintc_regs->pending = (1 << (intno - 32));
    else
        pintc_regs->pending = (1 << (intno - 64));
    return OK;
}

s32 isr_default(int dummy, void *arg)
{
    return true;
}

u32 interrupt_get_current_intno(void)
{
    return intc_get_current_interrupt();
}

/*the backup of enable and mask register*/
u32 intc_enable[3];
u32 intc_mask[3];

s32 interrupt_standby_enter(void)
{
    /*backup registers */
    intc_enable[0] = pintc_regs->enable;
    intc_enable[1] = pintc_regs->enable1;
    intc_enable[2] = pintc_regs->enable2;
    intc_mask[0] = pintc_regs->mask;
    intc_mask[1] = pintc_regs->mask1;
    intc_mask[2] = pintc_regs->mask2;

    /*disable all interrupt */
    pintc_regs->enable = 0;
    pintc_regs->enable1 = 0;
    pintc_regs->enable2 = 0;
    pintc_regs->mask = 0;
    pintc_regs->mask1 = 0;
    pintc_regs->mask2 = 0;

    return OK;
}

s32 interrupt_standby_exit(void)
{
    /*clear standby pendings */
    pintc_regs->pending = 0xffffffff;
    pintc_regs->pending1 = 0xffffffff;
    pintc_regs->pending2 = 0xffffffff;

    /*restore registers */
    pintc_regs->enable = intc_enable[0];
    pintc_regs->enable1 = intc_enable[1];
    pintc_regs->enable2 = intc_enable[2];
    pintc_regs->mask = intc_mask[0];
    pintc_regs->mask1 = intc_mask[1];
    pintc_regs->mask2 = intc_mask[2];

    return OK;
}