asp.c revision 1.1
1/* $OpenBSD: asp.c,v 1.1 1998/11/23 02:55:43 mickey Exp $ */ 2 3/* 4 * Copyright (c) 1998 Michael Shalayeff 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Michael Shalayeff. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/device.h> 36#include <sys/reboot.h> 37 38#include <machine/bus.h> 39#include <machine/iomod.h> 40#include <machine/autoconf.h> 41 42#include <hppa/dev/cpudevs.h> 43 44#include <hppa/gsc/gscbusvar.h> 45 46struct asp_softc { 47 struct device sc_dv; 48 49 bus_space_tag_t sc_iot; 50 bus_space_handle_t sc_ioh; 51 bus_space_handle_t sc_cioh; 52 53 struct gscbus_ic sc_ic; 54 55 u_int8_t sc_leds; 56}; 57 58/* ASP "Primary Controller" definitions */ 59#define ASP_CHPA 0xF0800000 60#define ASP_IRR 0x000 61#define ASP_IMR 0x004 62#define ASP_IPR 0x008 63#define ASP_LEDS 0x020 64#define ASP_LED_DATA 0x01 65#define ASP_LED_STROBE 0x02 66#define ASP_LED_PULSE 0x08 67 68/* ASP registers definitions */ 69#define ASP_RESET 0x000 70#define ASP_VERSION 0x020 71#define ASP_DSYNC 0x030 72#define ASP_ERROR 0x040 73 74int aspmatch __P((struct device *, void *, void *)); 75void aspattach __P((struct device *, struct device *, void *)); 76 77struct cfattach asp_ca = { 78 sizeof(struct asp_softc), aspmatch, aspattach 79}; 80 81struct cfdriver asp_cd = { 82 NULL, "asp", DV_DULL 83}; 84 85void asp_intr_attach __P((void *v, u_int in)); 86void asp_intr_establish __P((void *v, u_int32_t mask)); 87void asp_intr_disestablish __P((void *v, u_int32_t mask)); 88u_int32_t asp_intr_check __P((void *v)); 89void asp_intr_ack __P((void *v, u_int32_t mask)); 90 91int 92aspmatch(parent, cfdata, aux) 93 struct device *parent; 94 void *cfdata; 95 void *aux; 96{ 97 struct confargs *ca = aux; 98 /* struct cfdata *cf = cfdata; */ 99 bus_space_handle_t ioh; 100 101 if (ca->ca_type.iodc_type != HPPA_TYPE_BHA || 102 ca->ca_type.iodc_sv_model != HPPA_BHA_ASP) 103 return 0; 104 105 if (bus_space_map(ca->ca_iot, ca->ca_hpa, IOMOD_HPASIZE, 0, &ioh)) 106 return 0; 107 108 bus_space_unmap(ca->ca_iot, ioh, IOMOD_HPASIZE); 109 110 return 1; 111} 112 113void 114aspattach(parent, self, aux) 115 struct device *parent; 116 struct device *self; 117 void *aux; 118{ 119 register struct confargs *ca = aux; 120 register struct asp_softc *sc = (struct asp_softc *)self; 121 struct gsc_attach_args ga; 122 u_int ver; 123 124 sc->sc_leds = 0; 125 sc->sc_iot = ca->ca_iot; 126 if (bus_space_map(sc->sc_iot, ca->ca_hpa, IOMOD_HPASIZE, 0, 127 &sc->sc_ioh)) 128 panic("aspattach: unable to map bus space"); 129 130 if (bus_space_map(sc->sc_iot, ASP_CHPA, IOMOD_HPASIZE, 0, 131 &sc->sc_cioh)) 132 panic("aspattach: unable to map bus space"); 133 134 /* reset ASP */ 135 bus_space_write_1(sc->sc_iot, sc->sc_ioh, ASP_RESET, 1); 136 137 ver = bus_space_read_4(sc->sc_iot, sc->sc_ioh, ASP_VERSION); 138 printf(": hpa 0x%x, rev %d\n", ca->ca_hpa, 139 (ver & 0xf0) >> 4, ver & 0xf); 140 141 sc->sc_ic.gsc_type = gsc_asp; 142 sc->sc_ic.gsc_dv = sc; 143 sc->sc_ic.gsc_intr_attach = asp_intr_attach; 144 sc->sc_ic.gsc_intr_establish = asp_intr_establish; 145 sc->sc_ic.gsc_intr_disestablish = asp_intr_disestablish; 146 sc->sc_ic.gsc_intr_check = asp_intr_check; 147 sc->sc_ic.gsc_intr_ack = asp_intr_ack; 148 149 ga.ga_ca = *ca; /* clone from us */ 150 ga.ga_name = "gsc"; 151 ga.ga_ic = &sc->sc_ic; 152 config_found(self, &ga, gscprint); 153} 154 155#ifdef USELEDS 156void 157heartbeat(int on) 158{ 159 register struct asp_softc *sc; 160 161 sc = asp_cd.cd_devs[0]; 162 if (sc) { 163 register u_int8_t r = sc->sc_leds ^= ASP_LED_PULSE, b; 164 for (b = 0x80; b; b >>= 1) { 165 bus_space_write_1(sc->sc_iot, sc->sc_cioh, ASP_LEDS, 166 (r & b)? 1 : 0); 167 bus_space_write_1(sc->sc_iot, sc->sc_cioh, ASP_LEDS, 168 ASP_LED_STROBE | ((r & b)? 1 : 0)); 169 } 170 } 171} 172#endif 173 174void 175asp_intr_attach(v, irq) 176 void *v; 177 u_int irq; 178{ 179 register struct asp_softc *sc = v; 180 int s; 181 182 s = splhigh(); 183 cpu_setintrwnd(1 << irq); 184 185 bus_space_write_4(sc->sc_iot, sc->sc_cioh, ASP_IMR, ~0); 186 bus_space_read_4 (sc->sc_iot, sc->sc_cioh, ASP_IRR); 187 bus_space_write_4(sc->sc_iot, sc->sc_cioh, ASP_IMR, 0); 188 splx(s); 189} 190 191void 192asp_intr_establish(v, mask) 193 void *v; 194 u_int32_t mask; 195{ 196 register struct asp_softc *sc = v; 197 198 mask |= bus_space_read_4(sc->sc_iot, sc->sc_cioh, ASP_IMR); 199 bus_space_write_4(sc->sc_iot, sc->sc_cioh, ASP_IMR, mask); 200} 201 202void 203asp_intr_disestablish(v, mask) 204 void *v; 205 u_int32_t mask; 206{ 207 register struct asp_softc *sc = v; 208 209 mask &= ~bus_space_read_4(sc->sc_iot, sc->sc_cioh, ASP_IMR); 210 bus_space_write_4(sc->sc_iot, sc->sc_cioh, ASP_IMR, mask); 211} 212 213u_int32_t 214asp_intr_check(v) 215 void *v; 216{ 217 register struct asp_softc *sc = v; 218 register u_int32_t mask, imr; 219 220 imr = bus_space_read_4(sc->sc_iot, sc->sc_cioh, ASP_IMR); 221 mask = bus_space_read_4(sc->sc_iot, sc->sc_cioh, ASP_IRR); 222 bus_space_write_4(sc->sc_iot, sc->sc_cioh, ASP_IMR, imr & ~mask); 223 224 return mask; 225} 226 227void 228asp_intr_ack(v, mask) 229 void *v; 230 u_int32_t mask; 231{ 232 register struct asp_softc *sc = v; 233 234 mask |= bus_space_read_4(sc->sc_iot, sc->sc_cioh, ASP_IMR); 235 bus_space_write_4(sc->sc_iot, sc->sc_cioh, ASP_IMR, mask); 236} 237