1 /* PIO IRQ Implementation for OpenPCD
2 * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
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.
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.
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
21 #include <sys/types.h>
22 #include <lib_AT91SAM7.h>
23 #include <os/pio_irq.h>
25 #include <os/req_ctx.h>
29 irq_handler_t *handlers[NR_PIO];
31 u_int32_t usb_throttled; /* atomic? */
34 static struct pioirq_state pirqs;
36 /* low-level handler, used by Cstartup_app.S PIOA fast forcing and
37 * by regular interrupt handler below */
38 void __ramfunc __pio_irq_demux(u_int32_t pio)
40 u_int8_t send_usb = 0;
43 DEBUGPCRF("PIO_ISR_STATUS = 0x%08x", pio);
45 for (i = 0; i < NR_PIO; i++) {
46 if (pio & (1 << i) && pirqs.handlers[i])
48 if (pirqs.usbmask & (1 << i))
52 if (send_usb && !pirqs.usb_throttled) {
53 struct req_ctx *irq_rctx;
54 irq_rctx = req_ctx_find_get(0, RCTX_STATE_FREE,
55 RCTX_STATE_PIOIRQ_BUSY);
57 /* we cannot disable the interrupt, since we have
58 * non-usb listeners */
59 pirqs.usb_throttled = 1;
61 struct openpcd_hdr *opcdh;
63 opcdh = (struct openpcd_hdr *) irq_rctx->data;
64 regmask = (u_int32_t *) (irq_rctx->data + sizeof(*opcdh));
65 opcdh->cmd = OPENPCD_CMD_PIO_IRQ;
70 irq_rctx->tot_len = sizeof(*opcdh) + sizeof(u_int32_t);
71 req_ctx_set_state(irq_rctx, RCTX_STATE_UDP_EP3_PENDING);
75 AT91F_AIC_ClearIt(AT91C_BASE_AIC, AT91C_ID_PIOA);
78 /* regular interrupt handler, in case fast forcing for PIOA disabled */
79 static void pio_irq_demux(void)
81 u_int32_t pio = AT91F_PIO_GetInterruptStatus(AT91C_BASE_PIOA);
85 void pio_irq_enable(u_int32_t pio)
87 AT91F_PIO_InterruptEnable(AT91C_BASE_PIOA, pio);
90 void pio_irq_disable(u_int32_t pio)
92 AT91F_PIO_InterruptDisable(AT91C_BASE_PIOA, pio);
95 int pio_irq_register(u_int32_t pio, irq_handler_t *handler)
97 u_int8_t num = ffs(pio);
103 if (pirqs.handlers[num])
106 pio_irq_disable(pio);
107 AT91F_PIO_CfgInput(AT91C_BASE_PIOA, pio);
108 pirqs.handlers[num] = handler;
109 DEBUGPCRF("registering handler %p for PIOA %u", handler, num);
114 void pio_irq_unregister(u_int32_t pio)
116 u_int8_t num = ffs(pio);
122 pio_irq_disable(pio);
123 pirqs.handlers[num] = NULL;
126 static int pio_irq_usb_in(struct req_ctx *rctx)
128 struct openpcd_hdr *poh = (struct openpcd_hdr *) rctx->data;
131 case OPENPCD_CMD_PIO_IRQ:
132 pirqs.usbmask = poh->val;
142 void pio_irq_init(void)
145 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);