Home | History | Annotate | Line # | Download | only in s3c2xx0
s3c2800_intr.c revision 1.9.50.1
      1  1.9.50.1  chris /* $NetBSD: s3c2800_intr.c,v 1.9.50.1 2008/01/20 16:04:05 chris Exp $ */
      2       1.1    bsh 
      3       1.1    bsh /*
      4       1.1    bsh  * Copyright (c) 2002 Fujitsu Component Limited
      5       1.1    bsh  * Copyright (c) 2002 Genetec Corporation
      6       1.1    bsh  * All rights reserved.
      7       1.1    bsh  *
      8       1.1    bsh  * Redistribution and use in source and binary forms, with or without
      9       1.1    bsh  * modification, are permitted provided that the following conditions
     10       1.1    bsh  * are met:
     11       1.1    bsh  * 1. Redistributions of source code must retain the above copyright
     12       1.1    bsh  *    notice, this list of conditions and the following disclaimer.
     13       1.1    bsh  * 2. Redistributions in binary form must reproduce the above copyright
     14       1.1    bsh  *    notice, this list of conditions and the following disclaimer in the
     15       1.1    bsh  *    documentation and/or other materials provided with the distribution.
     16       1.1    bsh  * 3. Neither the name of The Fujitsu Component Limited nor the name of
     17       1.1    bsh  *    Genetec corporation may not be used to endorse or promote products
     18       1.1    bsh  *    derived from this software without specific prior written permission.
     19       1.1    bsh  *
     20       1.1    bsh  * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
     21       1.1    bsh  * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     22       1.1    bsh  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     23       1.1    bsh  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     24       1.1    bsh  * DISCLAIMED.  IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
     25       1.1    bsh  * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26       1.1    bsh  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     27       1.1    bsh  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
     28       1.1    bsh  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     29       1.1    bsh  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     30       1.1    bsh  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     31       1.1    bsh  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32       1.1    bsh  * SUCH DAMAGE.
     33       1.1    bsh  */
     34       1.1    bsh 
     35       1.1    bsh /*
     36       1.1    bsh  * IRQ handler for Samsung S3C2800 processor.
     37       1.1    bsh  * It has integrated interrupt controller.
     38       1.1    bsh  */
     39       1.5  lukem 
     40       1.5  lukem #include <sys/cdefs.h>
     41  1.9.50.1  chris __KERNEL_RCSID(0, "$NetBSD: s3c2800_intr.c,v 1.9.50.1 2008/01/20 16:04:05 chris Exp $");
     42       1.5  lukem 
     43       1.1    bsh #include <sys/param.h>
     44       1.1    bsh #include <sys/systm.h>
     45       1.1    bsh #include <sys/malloc.h>
     46       1.1    bsh #include <uvm/uvm_extern.h>
     47       1.1    bsh #include <machine/bus.h>
     48       1.1    bsh #include <machine/intr.h>
     49       1.1    bsh #include <arm/cpufunc.h>
     50       1.1    bsh 
     51       1.1    bsh #include <arm/s3c2xx0/s3c2800reg.h>
     52       1.1    bsh #include <arm/s3c2xx0/s3c2800var.h>
     53       1.1    bsh 
     54       1.1    bsh /*
     55       1.1    bsh  * interrupt dispatch table.
     56       1.1    bsh  */
     57       1.1    bsh 
     58       1.1    bsh struct s3c2xx0_intr_dispatch handler[ICU_LEN];
     59       1.1    bsh 
     60  1.9.50.1  chris #ifdef __HAVE_FAST_SOFTINTS
     61       1.9  perry volatile int softint_pending;
     62  1.9.50.1  chris #endif
     63       1.1    bsh 
     64       1.9  perry volatile int current_spl_level;
     65       1.9  perry volatile int intr_mask;    /* XXX: does this need to be volatile? */
     66       1.9  perry volatile int global_intr_mask = 0; /* mask some interrupts at all spl level */
     67       1.1    bsh 
     68       1.1    bsh /* interrupt masks for each level */
     69       1.1    bsh int s3c2xx0_imask[NIPL];
     70       1.1    bsh int s3c2xx0_ilevel[ICU_LEN];
     71       1.1    bsh 
     72       1.1    bsh vaddr_t intctl_base;		/* interrupt controller registers */
     73       1.1    bsh #define icreg(offset) \
     74       1.1    bsh 	(*(volatile uint32_t *)(intctl_base+(offset)))
     75       1.1    bsh 
     76  1.9.50.1  chris #ifdef __HAVE_FAST_SOFTINTS
     77       1.1    bsh /*
     78       1.1    bsh  * Map a software interrupt queue to an interrupt priority level.
     79       1.1    bsh  */
     80  1.9.50.1  chris static const int si_to_ipl[] = {
     81  1.9.50.1  chris 	[SI_SOFTBIO]	= IPL_SOFTBIO,
     82  1.9.50.1  chris 	[SI_SOFTCLOCK]	= IPL_SOFTCLOCK,
     83  1.9.50.1  chris 	[SI_SOFTNET]	= IPL_SOFTNET,
     84  1.9.50.1  chris 	[SI_SOFTSERIAL] = IPL_SOFTSERIAL,
     85       1.1    bsh };
     86  1.9.50.1  chris #endif
     87       1.4    bsh 
     88       1.4    bsh /*
     89       1.4    bsh  *   Clearing interrupt pending bits affects some built-in
     90       1.4    bsh  * peripherals.  For example, IIC starts transmitting next data when
     91       1.4    bsh  * its interrupt pending bit is cleared.
     92       1.4    bsh  *   We need to leave those bits to peripheral handlers.
     93       1.4    bsh  */
     94       1.4    bsh #define PENDING_CLEAR_MASK	(~((1<<S3C2800_INT_IIC0)|(1<<S3C2800_INT_IIC1)))
     95       1.4    bsh 
     96       1.1    bsh /*
     97       1.1    bsh  * called from irq_entry.
     98       1.1    bsh  */
     99       1.1    bsh void s3c2800_irq_handler(struct clockframe *);
    100       1.1    bsh void
    101       1.1    bsh s3c2800_irq_handler(struct clockframe *frame)
    102       1.1    bsh {
    103       1.1    bsh 	uint32_t irqbits;
    104       1.1    bsh 	int irqno;
    105       1.1    bsh 	int saved_spl_level;
    106       1.1    bsh 
    107       1.1    bsh 	saved_spl_level = current_spl_level;
    108       1.1    bsh 
    109       1.6    bsh 	while ((irqbits = icreg(INTCTL_IRQPND) & ICU_INT_HWMASK) != 0) {
    110       1.6    bsh 
    111       1.6    bsh 		for (irqno = ICU_LEN-1; irqno >= 0; --irqno)
    112       1.6    bsh 			if (irqbits & (1<<irqno))
    113       1.6    bsh 				break;
    114       1.6    bsh 
    115       1.6    bsh 		if (irqno < 0)
    116       1.6    bsh 			break;
    117       1.1    bsh 
    118       1.1    bsh 		/* raise spl to stop interrupts of lower priorities */
    119       1.1    bsh 		if (saved_spl_level < handler[irqno].level)
    120       1.1    bsh 			s3c2xx0_setipl(handler[irqno].level);
    121       1.1    bsh 
    122       1.1    bsh 		/* clear pending bit */
    123       1.4    bsh 		icreg(INTCTL_SRCPND) = PENDING_CLEAR_MASK & (1 << irqno);
    124       1.6    bsh 
    125       1.6    bsh 		enable_interrupts(I32_bit); /* allow nested interrupts */
    126       1.6    bsh 
    127       1.1    bsh 		(*handler[irqno].func) (
    128       1.1    bsh 		    handler[irqno].cookie == 0
    129       1.1    bsh 		    ? frame : handler[irqno].cookie);
    130       1.1    bsh 
    131       1.6    bsh 		disable_interrupts(I32_bit);
    132       1.6    bsh 
    133       1.6    bsh 		/* restore spl to that was when this interrupt happen */
    134       1.6    bsh 		s3c2xx0_setipl(saved_spl_level);
    135       1.1    bsh 	}
    136       1.1    bsh 
    137  1.9.50.1  chris #ifdef __HAVE_FAST_SOFTINTS
    138       1.1    bsh 	if (softint_pending & intr_mask)
    139       1.6    bsh 		s3c2xx0_do_pending(1);
    140  1.9.50.1  chris #endif
    141       1.1    bsh }
    142       1.1    bsh 
    143       1.4    bsh static const u_char s3c2800_ist[] = {
    144       1.4    bsh 	EXTINTR_LOW,		/* NONE */
    145       1.4    bsh 	EXTINTR_FALLING,	/* PULSE */
    146       1.4    bsh 	EXTINTR_FALLING,	/* EDGE */
    147       1.4    bsh 	EXTINTR_LOW,		/* LEVEL */
    148       1.4    bsh 	EXTINTR_HIGH,
    149       1.4    bsh 	EXTINTR_RISING,
    150       1.4    bsh 	EXTINTR_BOTH,
    151       1.4    bsh };
    152       1.1    bsh 
    153       1.1    bsh void *
    154       1.4    bsh s3c2800_intr_establish(int irqno, int level, int type,
    155       1.1    bsh     int (* func) (void *), void *cookie)
    156       1.1    bsh {
    157       1.1    bsh 	int save;
    158       1.1    bsh 
    159       1.4    bsh 	if (irqno < 0 || irqno >= ICU_LEN ||
    160       1.4    bsh 	    type < IST_NONE || IST_EDGE_BOTH < type)
    161       1.1    bsh 		panic("intr_establish: bogus irq or type");
    162       1.1    bsh 
    163       1.1    bsh 	save = disable_interrupts(I32_bit);
    164       1.1    bsh 
    165       1.1    bsh 	handler[irqno].cookie = cookie;
    166       1.1    bsh 	handler[irqno].func = func;
    167       1.1    bsh 	handler[irqno].level = level;
    168       1.1    bsh 
    169       1.1    bsh 	s3c2xx0_update_intr_masks(irqno, level);
    170       1.1    bsh 
    171       1.4    bsh 	if (irqno <= S3C2800_INT_EXT(7)) {
    172       1.4    bsh 		/*
    173       1.4    bsh 		 * Update external interrupt control
    174       1.4    bsh 		 */
    175       1.4    bsh 		uint32_t reg;
    176       1.4    bsh 		u_int 	trig;
    177       1.4    bsh 
    178       1.4    bsh 		trig = s3c2800_ist[type];
    179       1.4    bsh 
    180       1.4    bsh 		reg = bus_space_read_4(s3c2xx0_softc->sc_iot,
    181       1.4    bsh 				       s3c2xx0_softc->sc_gpio_ioh,
    182       1.4    bsh 				       GPIO_EXTINTR);
    183       1.4    bsh 
    184       1.4    bsh 		reg = reg & ~(0x0f << (4*irqno));
    185       1.4    bsh 		reg |= trig << (4*irqno);
    186       1.4    bsh 
    187       1.4    bsh 		bus_space_write_4(s3c2xx0_softc->sc_iot, s3c2xx0_softc->sc_gpio_ioh,
    188       1.4    bsh 				  GPIO_EXTINTR, reg);
    189       1.4    bsh 	}
    190       1.4    bsh 
    191       1.6    bsh 	s3c2xx0_setipl(current_spl_level);
    192       1.1    bsh 
    193       1.1    bsh 	restore_interrupts(save);
    194       1.1    bsh 
    195       1.1    bsh 	return (&handler[irqno]);
    196       1.1    bsh }
    197       1.1    bsh 
    198       1.1    bsh 
    199       1.7    bsh static void
    200       1.7    bsh init_interrupt_masks(void)
    201       1.7    bsh {
    202  1.9.50.1  chris 	int i = 0;
    203       1.7    bsh 
    204  1.9.50.1  chris #ifdef __HAVE_FAST_SOFTINTS
    205       1.7    bsh 	s3c2xx0_imask[IPL_NONE] = SI_TO_IRQBIT(SI_SOFTSERIAL) |
    206       1.7    bsh 		SI_TO_IRQBIT(SI_SOFTNET) | SI_TO_IRQBIT(SI_SOFTCLOCK) |
    207  1.9.50.1  chris 		SI_TO_IRQBIT(SI_SOFTBIO);
    208       1.7    bsh 
    209  1.9.50.1  chris 	s3c2xx0_imask[IPL_SOFTBIO] = SI_TO_IRQBIT(SI_SOFTSERIAL) |
    210       1.7    bsh 		SI_TO_IRQBIT(SI_SOFTNET) | SI_TO_IRQBIT(SI_SOFTCLOCK);
    211       1.7    bsh 
    212       1.7    bsh 	/*
    213       1.7    bsh 	 * splsoftclock() is the only interface that users of the
    214       1.7    bsh 	 * generic software interrupt facility have to block their
    215       1.7    bsh 	 * soft intrs, so splsoftclock() must also block IPL_SOFT.
    216       1.7    bsh 	 */
    217       1.7    bsh 	s3c2xx0_imask[IPL_SOFTCLOCK] = SI_TO_IRQBIT(SI_SOFTSERIAL) |
    218       1.7    bsh 		SI_TO_IRQBIT(SI_SOFTNET);
    219       1.7    bsh 
    220       1.7    bsh 	/*
    221       1.7    bsh 	 * splsoftnet() must also block splsoftclock(), since we don't
    222       1.7    bsh 	 * want timer-driven network events to occur while we're
    223       1.7    bsh 	 * processing incoming packets.
    224       1.7    bsh 	 */
    225       1.7    bsh 	s3c2xx0_imask[IPL_SOFTNET] = SI_TO_IRQBIT(SI_SOFTSERIAL);
    226       1.7    bsh 
    227       1.7    bsh 	for (i = IPL_BIO; i < IPL_SOFTSERIAL; ++i)
    228       1.7    bsh 		s3c2xx0_imask[i] = SI_TO_IRQBIT(SI_SOFTSERIAL);
    229  1.9.50.1  chris #endif
    230       1.7    bsh 	for (; i < NIPL; ++i)
    231       1.7    bsh 		s3c2xx0_imask[i] = 0;
    232       1.7    bsh }
    233       1.7    bsh 
    234       1.1    bsh void
    235       1.1    bsh s3c2800_intr_init(struct s3c2800_softc *sc)
    236       1.1    bsh {
    237       1.1    bsh 	intctl_base = (vaddr_t) bus_space_vaddr(sc->sc_sx.sc_iot,
    238       1.1    bsh 	    sc->sc_sx.sc_intctl_ioh);
    239       1.1    bsh 
    240       1.1    bsh 	s3c2xx0_intr_mask_reg = (uint32_t *)(intctl_base + INTCTL_INTMSK);
    241       1.1    bsh 
    242       1.1    bsh 	/* clear all pending interrupt */
    243       1.1    bsh 	icreg(INTCTL_SRCPND) = 0xffffffff;
    244       1.7    bsh 
    245       1.7    bsh 	init_interrupt_masks();
    246       1.1    bsh 
    247       1.1    bsh 	s3c2xx0_intr_init(handler, ICU_LEN);
    248       1.4    bsh 
    249       1.1    bsh }
    250