Home | History | Annotate | Line # | Download | only in sa11x0
sa1111.c revision 1.15
      1  1.15     peter /*      $NetBSD: sa1111.c,v 1.15 2006/01/03 23:14:23 peter Exp $	*/
      2   1.1       rjs 
      3   1.1       rjs /*-
      4   1.1       rjs  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5   1.1       rjs  * All rights reserved.
      6   1.1       rjs  *
      7   1.1       rjs  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1       rjs  * by IWAMOTO Toshihiro.
      9   1.1       rjs  *
     10   1.1       rjs  * Redistribution and use in source and binary forms, with or without
     11   1.1       rjs  * modification, are permitted provided that the following conditions
     12   1.1       rjs  * are met:
     13   1.1       rjs  * 1. Redistributions of source code must retain the above copyright
     14   1.1       rjs  *    notice, this list of conditions and the following disclaimer.
     15   1.1       rjs  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1       rjs  *    notice, this list of conditions and the following disclaimer in the
     17   1.1       rjs  *    documentation and/or other materials provided with the distribution.
     18   1.1       rjs  * 3. All advertising materials mentioning features or use of this software
     19   1.1       rjs  *    must display the following acknowledgement:
     20   1.1       rjs  *        This product includes software developed by the NetBSD
     21   1.1       rjs  *        Foundation, Inc. and its contributors.
     22   1.1       rjs  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1       rjs  *    contributors may be used to endorse or promote products derived
     24   1.1       rjs  *    from this software without specific prior written permission.
     25   1.1       rjs  *
     26   1.1       rjs  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1       rjs  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1       rjs  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1       rjs  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1       rjs  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1       rjs  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1       rjs  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1       rjs  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1       rjs  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1       rjs  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1       rjs  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1       rjs  */
     38   1.1       rjs 
     39   1.1       rjs /*
     40   1.1       rjs  * TODO:
     41   1.1       rjs  *   - introduce bus abstraction to support SA1101
     42   1.1       rjs  */
     43  1.10     lukem 
     44  1.10     lukem #include <sys/cdefs.h>
     45  1.15     peter __KERNEL_RCSID(0, "$NetBSD: sa1111.c,v 1.15 2006/01/03 23:14:23 peter Exp $");
     46   1.1       rjs 
     47   1.1       rjs #include <sys/param.h>
     48   1.1       rjs #include <sys/systm.h>
     49   1.1       rjs #include <sys/types.h>
     50   1.1       rjs #include <sys/conf.h>
     51   1.1       rjs #include <sys/device.h>
     52   1.1       rjs #include <sys/kernel.h>
     53   1.1       rjs #include <sys/malloc.h>
     54   1.1       rjs #include <sys/uio.h>
     55   1.1       rjs 
     56   1.1       rjs #include <machine/bus.h>
     57   1.1       rjs 
     58   1.1       rjs #include <arm/sa11x0/sa11x0_reg.h>
     59   1.1       rjs #include <arm/sa11x0/sa11x0_var.h>
     60   1.1       rjs #include <arm/sa11x0/sa11x0_gpioreg.h>
     61   1.1       rjs #include <arm/sa11x0/sa1111_reg.h>
     62   1.1       rjs #include <arm/sa11x0/sa1111_var.h>
     63   1.1       rjs 
     64  1.11       bsh #include "locators.h"
     65  1.11       bsh 
     66   1.1       rjs static	int	sa1111_print(void *, const char *);
     67   1.1       rjs 
     68   1.1       rjs static void	sacc_intr_calculatemasks(struct sacc_softc *);
     69   1.1       rjs static void	sacc_intr_setpolarity(sacc_chipset_tag_t *, int , int);
     70   1.1       rjs int		sacc_intr(void *);
     71   1.1       rjs 
     72  1.11       bsh #if !defined(__HAVE_GENERIC_SOFT_INTERRUPTS)
     73   1.1       rjs void *softintr_establish(int, int (*)(void *), void *);
     74   1.1       rjs void softintr_schedule(void *);
     75   1.1       rjs #endif
     76   1.1       rjs 
     77   1.1       rjs #ifdef INTR_DEBUG
     78   1.1       rjs #define DPRINTF(arg)	printf arg
     79   1.1       rjs #else
     80   1.1       rjs #define DPRINTF(arg)
     81   1.1       rjs #endif
     82   1.1       rjs 
     83  1.11       bsh int
     84   1.2       rjs sacc_probe(parent, match, aux)
     85   1.1       rjs 	struct device *parent;
     86   1.1       rjs 	struct cfdata *match;
     87   1.1       rjs 	void *aux;
     88   1.1       rjs {
     89   1.2       rjs 	struct sa11x0_attach_args *sa = aux;
     90   1.2       rjs 	bus_space_handle_t ioh;
     91   1.2       rjs 	u_int32_t skid;
     92   1.2       rjs 
     93   1.2       rjs 	if (bus_space_map(sa->sa_iot, sa->sa_addr, sa->sa_size, 0, &ioh))
     94   1.2       rjs 		return (0);
     95   1.2       rjs 
     96   1.2       rjs 	skid = bus_space_read_4(sa->sa_iot, ioh, SACCSBI_SKID);
     97   1.2       rjs 	bus_space_unmap(sa->sa_iot, ioh, sa->sa_size);
     98   1.2       rjs 
     99   1.2       rjs 	if ((skid & 0xffffff00) != 0x690cc200)
    100   1.2       rjs 		return (0);
    101   1.2       rjs 
    102   1.1       rjs 	return (1);
    103   1.1       rjs }
    104   1.1       rjs 
    105  1.11       bsh 
    106  1.11       bsh int
    107  1.12  drochner sa1111_search(parent, cf, ldesc, aux)
    108   1.1       rjs 	struct device *parent;
    109  1.11       bsh 	struct cfdata *cf;
    110  1.13  drochner 	const int *ldesc;
    111   1.1       rjs 	void *aux;
    112   1.1       rjs {
    113  1.11       bsh 	struct sa1111_attach_args aa;
    114   1.2       rjs 
    115  1.11       bsh 	aa.sa_addr = cf->cf_loc[SACCCF_ADDR];
    116  1.11       bsh 	aa.sa_size = cf->cf_loc[SACCCF_SIZE];
    117  1.11       bsh 	aa.sa_intr = cf->cf_loc[SACCCF_INTR];
    118  1.11       bsh #if 0
    119  1.11       bsh 	aa.sa_membase = cf->cf_loc[SACCCF_MEMBASE];
    120  1.11       bsh 	aa.sa_memsize = cf->cf_loc[SACCCF_MEMSIZE];
    121   1.1       rjs #endif
    122   1.1       rjs 
    123  1.11       bsh         if (config_match(parent, cf, &aa) > 0)
    124  1.11       bsh                 config_attach(parent, cf, &aa, sa1111_print);
    125   1.1       rjs 
    126   1.1       rjs         return 0;
    127   1.1       rjs }
    128   1.1       rjs 
    129   1.1       rjs static int
    130   1.1       rjs sa1111_print(aux, name)
    131   1.1       rjs 	void *aux;
    132   1.1       rjs 	const char *name;
    133   1.1       rjs {
    134   1.1       rjs 	return (UNCONF);
    135   1.1       rjs }
    136   1.1       rjs 
    137   1.1       rjs 
    138   1.1       rjs void *
    139   1.1       rjs sacc_intr_establish(ic, irq, type, level, ih_fun, ih_arg)
    140   1.1       rjs 	sacc_chipset_tag_t *ic;
    141   1.1       rjs 	int irq, type, level;
    142   1.1       rjs 	int (*ih_fun)(void *);
    143   1.1       rjs 	void *ih_arg;
    144   1.1       rjs {
    145   1.1       rjs 	int s;
    146   1.1       rjs 	struct sacc_softc *sc = (struct sacc_softc *)ic;
    147   1.1       rjs 	struct sacc_intrhand **p, *ih;
    148   1.1       rjs 
    149   1.1       rjs 	/* no point in sleeping unless someone can free memory. */
    150   1.1       rjs 	ih = malloc(sizeof *ih, M_DEVBUF, cold ? M_NOWAIT : M_WAITOK);
    151   1.1       rjs 	if (ih == NULL)
    152   1.1       rjs 		panic("sacc_intr_establish: can't malloc handler info");
    153   1.1       rjs 
    154   1.1       rjs 	if (irq < 0 || irq > SACCIC_LEN ||
    155   1.1       rjs 	    ! (type == IST_EDGE_RAISE || type == IST_EDGE_FALL))
    156   1.1       rjs 		panic("sacc_intr_establish: bogus irq or type");
    157   1.1       rjs 
    158   1.1       rjs 	if (sc->sc_intrhand[irq] == NULL) {
    159   1.1       rjs 		sacc_intr_setpolarity(ic, irq, type);
    160   1.1       rjs 		sc->sc_intrtype[irq] = type;
    161   1.1       rjs 	} else if (sc->sc_intrtype[irq] != type)
    162   1.1       rjs 		/* XXX we should be able to share raising and
    163   1.1       rjs 		 * falling edge intrs */
    164   1.7    provos 		panic("sacc_intr_establish: type must be unique");
    165   1.1       rjs 
    166   1.1       rjs 	/* install intr handler */
    167  1.11       bsh #if defined(__GENERIC_SOFT_INTERRUPTS_ALL_LEVELS) || \
    168  1.11       bsh 	!defined(__HAVE_GENERIC_SOFT_INTERRUPTS)
    169  1.11       bsh 
    170  1.11       bsh 	ih->ih_soft = softintr_establish(level, (void (*)(void *)) ih_fun,
    171  1.11       bsh 					 ih_arg);
    172  1.11       bsh #else
    173  1.11       bsh 	/* map interrupt level to appropriate softinterrupt level */
    174  1.11       bsh 	if (level >= IPL_SOFTSERIAL)
    175  1.11       bsh 		level = IPL_SOFTSERIAL;
    176  1.11       bsh 	else if(level >= IPL_SOFTNET)
    177  1.11       bsh 		level = IPL_SOFTNET;
    178   1.1       rjs 	ih->ih_soft = softintr_establish(level, (void (*)(void *)) ih_fun,
    179   1.1       rjs 					 ih_arg);
    180   1.1       rjs #endif
    181   1.1       rjs 	ih->ih_irq = irq;
    182   1.1       rjs 	ih->ih_next = NULL;
    183   1.1       rjs 
    184   1.1       rjs 	s = splhigh();
    185   1.1       rjs 	for(p = &sc->sc_intrhand[irq]; *p; p = &(*p)->ih_next)
    186   1.1       rjs 		;
    187   1.1       rjs 
    188   1.1       rjs 	*p = ih;
    189   1.1       rjs 
    190   1.1       rjs 	sacc_intr_calculatemasks(sc);
    191   1.1       rjs 	splx(s);
    192   1.1       rjs 
    193   1.1       rjs 	return(ih);
    194   1.1       rjs }
    195   1.1       rjs 
    196   1.1       rjs void
    197   1.1       rjs sacc_intr_disestablish(ic, arg)
    198   1.1       rjs 	sacc_chipset_tag_t *ic;
    199   1.1       rjs 	void *arg;
    200   1.1       rjs {
    201   1.1       rjs 	int irq, s;
    202   1.1       rjs 	struct sacc_softc *sc = (struct sacc_softc *)ic;
    203   1.1       rjs 	struct sacc_intrhand *ih, **p;
    204   1.1       rjs 
    205   1.1       rjs 	ih = (struct sacc_intrhand *)arg;
    206   1.1       rjs 	irq = ih->ih_irq;
    207   1.1       rjs 
    208   1.1       rjs #ifdef DIAGNOSTIC
    209   1.1       rjs 	if (irq < 0 || irq > SACCIC_LEN)
    210   1.1       rjs 		panic("sacc_intr_disestablish: bogus irq");
    211   1.1       rjs #endif
    212   1.1       rjs 
    213   1.1       rjs 	s = splhigh();
    214   1.1       rjs 
    215   1.1       rjs 	for(p = &sc->sc_intrhand[irq];; p = &(*p)->ih_next) {
    216   1.1       rjs 		if (*p == NULL)
    217   1.1       rjs 			panic("sacc_intr_disestablish: handler not registered");
    218   1.1       rjs 		if (*p == ih)
    219   1.1       rjs 			break;
    220   1.1       rjs 	}
    221   1.1       rjs 	*p = (*p)->ih_next;
    222   1.1       rjs 
    223   1.1       rjs 	sacc_intr_calculatemasks(sc);
    224   1.1       rjs 	splx(s);
    225   1.1       rjs 
    226   1.1       rjs 	free(ih, M_DEVBUF);
    227   1.1       rjs }
    228   1.1       rjs 
    229   1.1       rjs void
    230   1.1       rjs sacc_intr_setpolarity(ic, irq, type)
    231   1.1       rjs 	sacc_chipset_tag_t *ic;
    232   1.1       rjs 	int irq;
    233   1.1       rjs 	int type;
    234   1.1       rjs {
    235   1.1       rjs 	struct sacc_softc *sc = (struct sacc_softc *)ic;
    236   1.1       rjs 	int s;
    237   1.1       rjs 	u_int32_t pol, mask;
    238   1.1       rjs 	int addr;
    239   1.1       rjs 
    240   1.1       rjs 	if (irq >= 32) {
    241   1.1       rjs 		addr = SACCIC_INTPOL1;
    242   1.1       rjs 		irq -= 32;
    243   1.1       rjs 	} else
    244   1.1       rjs 		addr = SACCIC_INTPOL0;
    245   1.1       rjs 
    246   1.1       rjs 	mask = (1 << irq);
    247   1.1       rjs 
    248   1.1       rjs 	s = splhigh();
    249   1.1       rjs 	pol = bus_space_read_4(sc->sc_iot, sc->sc_ioh, addr);
    250   1.1       rjs 	if (type == IST_EDGE_RAISE)
    251   1.1       rjs 		pol &= ~mask;
    252   1.1       rjs 	else
    253   1.1       rjs 		pol |= mask;
    254   1.1       rjs 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, addr, pol);
    255   1.1       rjs 	splx(s);
    256   1.1       rjs }
    257   1.1       rjs 
    258   1.1       rjs void
    259   1.1       rjs sacc_intr_calculatemasks(sc)
    260   1.1       rjs 	struct sacc_softc *sc;
    261   1.1       rjs {
    262   1.1       rjs 	int irq;
    263   1.1       rjs 
    264   1.1       rjs 	sc->sc_imask.lo = 0;
    265   1.1       rjs 	sc->sc_imask.hi = 0;
    266   1.1       rjs 	for(irq = 0; irq < 32; irq++)
    267   1.1       rjs 		if (sc->sc_intrhand[irq])
    268   1.1       rjs 			sc->sc_imask.lo |= (1 << irq);
    269   1.1       rjs 	for(irq = 0; irq < SACCIC_LEN - 32; irq++)
    270   1.1       rjs 		if (sc->sc_intrhand[irq + 32])
    271   1.1       rjs 			sc->sc_imask.hi |= (1 << irq);
    272   1.1       rjs 
    273   1.1       rjs 
    274   1.1       rjs 	/* XXX this should not be done here */
    275   1.1       rjs 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTEN0,
    276   1.1       rjs 			  sc->sc_imask.lo);
    277   1.1       rjs 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTEN1,
    278   1.1       rjs 			  sc->sc_imask.hi);
    279   1.1       rjs 	DPRINTF(("sacc_intr_calculatemasks: %x %x\n", sc->sc_imask.lo,
    280   1.1       rjs 	    sc->sc_imask.hi));
    281   1.1       rjs }
    282