/*
* Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved.
* Written by Hiroyuki Bessho for Genetec Corporation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of Genetec Corporation may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* TODO: dispatch interrupt to SOFTSERIAL or SOFTNET according to requested
* interrupt level.
*/
static int
obio_spurious(void *arg)
{
int irqno = (int)arg;
aprint_normal("Spurious interrupt %d on On-board peripheral", irqno);
return 1;
}
/*
* interrupt handler for GPIO0 (on-board peripherals)
*
* On Lubbock, 8 interrupts are ORed through on-board logic,
* and routed to GPIO0 of PXA250 processor.
*/
static int
obio_intr(void *arg)
{
int irqno, pending, mask;
struct obio_softc *sc = (struct obio_softc *)arg;
int psw;
mask = sc->sc_obio_intr_mask; /* real irq mask for obio */
psw = disable_interrupts(I32_bit|F32_bit);
pending = bus_space_read_2(sc->sc_iot, sc->sc_obioreg_ioh,
LUBBOCK_INTRCTL);
/* Here is a chance to lose some interrupts.
* You need to modify FPGA program to avoid it
*/
bus_space_write_2(sc->sc_iot, sc->sc_obioreg_ioh, LUBBOCK_INTRCTL, 0);
restore_interrupts(psw);
pending &= mask;
while (pending) {
irqno = 0;
for ( ;pending; ++irqno) {
if (0 == (pending & (1U<<irqno)))
continue;
pending &= ~(1U<<irqno);
#ifdef notyet
/* if ipl of this irq is higher than current spl level,
call the handler directly instead of dispatching it to
software interrupt. */
if (sc->sc_handler[irqno].level > curcpl()) {
(* sc->sc_handler[irqno].func)(
sc->sc_handler[irqno].arg );
}
else
#endif
{
/* mask this interrupt until software
interrupt is handled. */
sc->sc_obio_intr_pending |= (1U<<irqno);
mask &= ~(1U<<irqno);
bus_space_write_4(sc->sc_iot, sc->sc_obioreg_ioh,
LUBBOCK_INTRMASK, mask);
/* handle it later */
softint_schedule(sc->sc_si);
}
}
/* GPIO interrupt is edge triggered. make a pulse
to let Cotulla notice when other interrupts are
still pending */
bus_space_write_2(sc->sc_iot, sc->sc_obioreg_ioh, LUBBOCK_INTRMASK, 0);
bus_space_write_2(sc->sc_iot, sc->sc_obioreg_ioh, LUBBOCK_INTRMASK, mask);
return 1;
}
static void
obio_softintr(void *arg)
{
struct obio_softc *sc = (struct obio_softc *)arg;
int irqno;
int psw;
int spl_save = curcpl();
/*
* Mask all interrupts.
* They are later unmasked at each device's attach routine.
*/
bus_space_write_4(sc->sc_iot, sc->sc_obioreg_ioh,
LUBBOCK_INTRMASK,0);
sc->sc_intr = sa->pxa_intr; /* irq no. on ICU. */
sc->sc_obio_intr_mask = 0; /* No interrupt used */
sc->sc_obio_intr_pending = 0;
sc->sc_ipl = IPL_BIO;
for (i=0; i < N_OBIO_IRQ; ++i) {
sc->sc_handler[i].func = obio_spurious;
sc->sc_handler[i].arg = (void *)i;
}
/*
* establish interrupt handler.
*/
#if 0
/*
* level is lowest at first, and changed when
* sub-interrupt handlers are established
*/
sc->sc_ipl = IPL_BIO;
#else
/*
* level is very high to allow high priority sub-interrupts.
*/
sc->sc_ipl = IPL_AUDIO;
#endif
sc->sc_ih = pxa2x0_gpio_intr_establish(0, IST_EDGE_FALLING, sc->sc_ipl,
obio_intr, sc);
sc->sc_si = softint_establish(SOFTINT_NET, obio_softintr, sc);