1 |
32985a29
|
laforge
|
/* PIO IRQ Implementation for OpenPCD
|
2 |
|
|
* (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
|
3 |
|
|
*
|
4 |
|
|
* This program is free software; you can redistribute it and/or modify
|
5 |
|
|
* it under the terms of the GNU General Public License as published by
|
6 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
7 |
|
|
* (at your option) any later version.
|
8 |
|
|
*
|
9 |
|
|
* This program is distributed in the hope that it will be useful,
|
10 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
|
|
* GNU General Public License for more details.
|
13 |
|
|
*
|
14 |
|
|
* You should have received a copy of the GNU General Public License
|
15 |
|
|
* along with this program; if not, write to the Free Software
|
16 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17 |
|
|
*
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
7237fbce
|
(no author)
|
#include <errno.h>
|
21 |
|
|
#include <sys/types.h>
|
22 |
|
|
#include <lib_AT91SAM7.h>
|
23 |
|
|
#include <os/pio_irq.h>
|
24 |
22239346
|
(no author)
|
#include <os/dbgu.h>
|
25 |
|
|
#include <os/req_ctx.h>
|
26 |
|
|
#include <openpcd.h>
|
27 |
872a81da
|
(no author)
|
|
28 |
22239346
|
(no author)
|
struct pioirq_state {
|
29 |
|
|
irq_handler_t *handlers[NR_PIO];
|
30 |
373c172a
|
Harald Welte
|
uint32_t usbmask;
|
31 |
|
|
uint32_t usb_throttled; /* atomic? */
|
32 |
22239346
|
(no author)
|
};
|
33 |
872a81da
|
(no author)
|
|
34 |
22239346
|
(no author)
|
static struct pioirq_state pirqs;
|
35 |
872a81da
|
(no author)
|
|
36 |
fabe00c6
|
laforge
|
/* low-level handler, used by Cstartup_app.S PIOA fast forcing and
|
37 |
|
|
* by regular interrupt handler below */
|
38 |
373c172a
|
Harald Welte
|
void __ramfunc __pio_irq_demux(uint32_t pio)
|
39 |
872a81da
|
(no author)
|
{
|
40 |
373c172a
|
Harald Welte
|
uint8_t send_usb = 0;
|
41 |
7237fbce
|
(no author)
|
int i;
|
42 |
872a81da
|
(no author)
|
|
43 |
94143382
|
Harald Welte
|
//DEBUGPCRF("PIO_ISR_STATUS = 0x%08x", pio);
|
44 |
22239346
|
(no author)
|
|
45 |
7bdd2635
|
laforge
|
for (i = 0; i < NR_PIO; i++) {
|
46 |
22239346
|
(no author)
|
if (pio & (1 << i) && pirqs.handlers[i])
|
47 |
|
|
pirqs.handlers[i](i);
|
48 |
|
|
if (pirqs.usbmask & (1 << i))
|
49 |
|
|
send_usb = 1;
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
if (send_usb && !pirqs.usb_throttled) {
|
53 |
|
|
struct req_ctx *irq_rctx;
|
54 |
514b0f72
|
laforge
|
irq_rctx = req_ctx_find_get(0, RCTX_STATE_FREE,
|
55 |
22239346
|
(no author)
|
RCTX_STATE_PIOIRQ_BUSY);
|
56 |
|
|
if (!irq_rctx) {
|
57 |
|
|
/* we cannot disable the interrupt, since we have
|
58 |
|
|
* non-usb listeners */
|
59 |
|
|
pirqs.usb_throttled = 1;
|
60 |
|
|
} else {
|
61 |
|
|
struct openpcd_hdr *opcdh;
|
62 |
373c172a
|
Harald Welte
|
uint32_t *regmask;
|
63 |
514b0f72
|
laforge
|
opcdh = (struct openpcd_hdr *) irq_rctx->data;
|
64 |
373c172a
|
Harald Welte
|
regmask = (uint32_t *) (irq_rctx->data + sizeof(*opcdh));
|
65 |
22239346
|
(no author)
|
opcdh->cmd = OPENPCD_CMD_PIO_IRQ;
|
66 |
|
|
opcdh->reg = 0x00;
|
67 |
|
|
opcdh->flags = 0x00;
|
68 |
|
|
opcdh->val = 0x00;
|
69 |
|
|
|
70 |
373c172a
|
Harald Welte
|
irq_rctx->tot_len = sizeof(*opcdh) + sizeof(uint32_t);
|
71 |
22239346
|
(no author)
|
req_ctx_set_state(irq_rctx, RCTX_STATE_UDP_EP3_PENDING);
|
72 |
|
|
}
|
73 |
872a81da
|
(no author)
|
}
|
74 |
22239346
|
(no author)
|
|
75 |
|
|
AT91F_AIC_ClearIt(AT91C_BASE_AIC, AT91C_ID_PIOA);
|
76 |
872a81da
|
(no author)
|
}
|
77 |
|
|
|
78 |
fabe00c6
|
laforge
|
/* regular interrupt handler, in case fast forcing for PIOA disabled */
|
79 |
|
|
static void pio_irq_demux(void)
|
80 |
|
|
{
|
81 |
373c172a
|
Harald Welte
|
uint32_t pio = AT91F_PIO_GetInterruptStatus(AT91C_BASE_PIOA);
|
82 |
fabe00c6
|
laforge
|
__pio_irq_demux(pio);
|
83 |
|
|
}
|
84 |
|
|
|
85 |
373c172a
|
Harald Welte
|
void pio_irq_enable(uint32_t pio)
|
86 |
872a81da
|
(no author)
|
{
|
87 |
|
|
AT91F_PIO_InterruptEnable(AT91C_BASE_PIOA, pio);
|
88 |
|
|
}
|
89 |
|
|
|
90 |
373c172a
|
Harald Welte
|
void pio_irq_disable(uint32_t pio)
|
91 |
872a81da
|
(no author)
|
{
|
92 |
|
|
AT91F_PIO_InterruptDisable(AT91C_BASE_PIOA, pio);
|
93 |
|
|
}
|
94 |
|
|
|
95 |
373c172a
|
Harald Welte
|
int pio_irq_register(uint32_t pio, irq_handler_t *handler)
|
96 |
872a81da
|
(no author)
|
{
|
97 |
373c172a
|
Harald Welte
|
uint8_t num = ffs(pio);
|
98 |
872a81da
|
(no author)
|
|
99 |
|
|
if (num == 0)
|
100 |
|
|
return -EINVAL;
|
101 |
|
|
num--;
|
102 |
|
|
|
103 |
22239346
|
(no author)
|
if (pirqs.handlers[num])
|
104 |
872a81da
|
(no author)
|
return -EBUSY;
|
105 |
|
|
|
106 |
|
|
pio_irq_disable(pio);
|
107 |
|
|
AT91F_PIO_CfgInput(AT91C_BASE_PIOA, pio);
|
108 |
22239346
|
(no author)
|
pirqs.handlers[num] = handler;
|
109 |
7bdd2635
|
laforge
|
DEBUGPCRF("registering handler %p for PIOA %u", handler, num);
|
110 |
872a81da
|
(no author)
|
|
111 |
|
|
return 0;
|
112 |
|
|
}
|
113 |
|
|
|
114 |
373c172a
|
Harald Welte
|
void pio_irq_unregister(uint32_t pio)
|
115 |
872a81da
|
(no author)
|
{
|
116 |
373c172a
|
Harald Welte
|
uint8_t num = ffs(pio);
|
117 |
872a81da
|
(no author)
|
|
118 |
|
|
if (num == 0)
|
119 |
|
|
return;
|
120 |
|
|
num--;
|
121 |
|
|
|
122 |
|
|
pio_irq_disable(pio);
|
123 |
22239346
|
(no author)
|
pirqs.handlers[num] = NULL;
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
static int pio_irq_usb_in(struct req_ctx *rctx)
|
127 |
|
|
{
|
128 |
514b0f72
|
laforge
|
struct openpcd_hdr *poh = (struct openpcd_hdr *) rctx->data;
|
129 |
22239346
|
(no author)
|
|
130 |
|
|
switch (poh->cmd) {
|
131 |
|
|
case OPENPCD_CMD_PIO_IRQ:
|
132 |
|
|
pirqs.usbmask = poh->val;
|
133 |
|
|
break;
|
134 |
|
|
default:
|
135 |
|
|
DEBUGP("UNKNOWN ");
|
136 |
|
|
return -EINVAL;
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
return 0;
|
140 |
872a81da
|
(no author)
|
}
|
141 |
7237fbce
|
(no author)
|
|
142 |
|
|
void pio_irq_init(void)
|
143 |
|
|
{
|
144 |
22239346
|
(no author)
|
AT91F_PIOA_CfgPMC();
|
145 |
7237fbce
|
(no author)
|
AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, AT91C_ID_PIOA,
|
146 |
|
|
AT91C_AIC_PRIOR_LOWEST,
|
147 |
|
|
AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, &pio_irq_demux);
|
148 |
|
|
AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_PIOA);
|
149 |
|
|
}
|