Project

General

Profile

Download (3.58 KB) Statistics
| Branch: | Tag: | Revision:
1
/* 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
#include <errno.h>
21
#include <sys/types.h>
22
#include <lib_AT91SAM7.h>
23
#include <os/pio_irq.h>
24
#include <os/dbgu.h>
25
#include <os/req_ctx.h>
26
#include <openpcd.h>
27

    
28
struct pioirq_state {
29
	irq_handler_t *handlers[NR_PIO];
30
	uint32_t usbmask;
31
	uint32_t usb_throttled; /* atomic? */
32
};
33

    
34
static struct pioirq_state pirqs;
35

    
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(uint32_t pio)
39
{
40
	uint8_t send_usb = 0;
41
	int i;
42

    
43
	//DEBUGPCRF("PIO_ISR_STATUS = 0x%08x", pio);
44

    
45
	for (i = 0; i < NR_PIO; i++) {
46
		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
		irq_rctx = req_ctx_find_get(0, RCTX_STATE_FREE,
55
					    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
			uint32_t *regmask;
63
			opcdh = (struct openpcd_hdr *) irq_rctx->data;
64
			regmask = (uint32_t *) (irq_rctx->data + sizeof(*opcdh));
65
			opcdh->cmd = OPENPCD_CMD_PIO_IRQ;
66
			opcdh->reg = 0x00;
67
			opcdh->flags = 0x00;
68
			opcdh->val = 0x00;
69

    
70
			irq_rctx->tot_len = sizeof(*opcdh) + sizeof(uint32_t);
71
			req_ctx_set_state(irq_rctx, RCTX_STATE_UDP_EP3_PENDING);
72
		}
73
	}
74

    
75
	AT91F_AIC_ClearIt(AT91C_BASE_AIC, AT91C_ID_PIOA);
76
}
77

    
78
/* regular interrupt handler, in case fast forcing for PIOA disabled */
79
static void pio_irq_demux(void)
80
{
81
	uint32_t pio = AT91F_PIO_GetInterruptStatus(AT91C_BASE_PIOA);
82
	__pio_irq_demux(pio);
83
}
84

    
85
void pio_irq_enable(uint32_t pio)
86
{
87
	AT91F_PIO_InterruptEnable(AT91C_BASE_PIOA, pio);
88
}
89

    
90
void pio_irq_disable(uint32_t pio)
91
{
92
	AT91F_PIO_InterruptDisable(AT91C_BASE_PIOA, pio);
93
}
94

    
95
int pio_irq_register(uint32_t pio, irq_handler_t *handler)
96
{
97
	uint8_t num = ffs(pio);
98

    
99
	if (num == 0)
100
		return -EINVAL;
101
	num--;
102

    
103
	if (pirqs.handlers[num])
104
		return -EBUSY;
105

    
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);
110

    
111
	return 0;
112
}
113

    
114
void pio_irq_unregister(uint32_t pio)
115
{
116
	uint8_t num = ffs(pio);
117

    
118
	if (num == 0)
119
		return;
120
	num--;
121

    
122
	pio_irq_disable(pio);
123
	pirqs.handlers[num] = NULL;
124
}
125

    
126
static int pio_irq_usb_in(struct req_ctx *rctx)
127
{
128
	struct openpcd_hdr *poh = (struct openpcd_hdr *) rctx->data;
129

    
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
}
141

    
142
void pio_irq_init(void)
143
{
144
	AT91F_PIOA_CfgPMC();
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);
149
}
(15-15/40)
Add picture from clipboard (Maximum size: 48.8 MB)