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