1 /* $NetBSD: sio16.c,v 1.4 2002/03/20 20:39:15 eeh Exp $ */ 2 3 /* 4 * Copyright (c) 1998, 2001 Matthew R. Green 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. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 /* 32 * aurora technologies nova16 driver. this board is an sbus card with 33 * an external 16 port serial box. there are two cirrus logic cd180 34 * 8 port serial chips used in the implementation. 35 * 36 * thanks go to Oliver Aldulea <oli@morcov.bv.ro> for writing the 37 * linux driver of this that helped clear up a couple of issues. 38 */ 39 40 #include <sys/cdefs.h> 41 __KERNEL_RCSID(0, "$NetBSD: sio16.c,v 1.4 2002/03/20 20:39:15 eeh Exp $"); 42 43 #include <sys/param.h> 44 #include <sys/conf.h> 45 #include <sys/device.h> 46 #include <sys/systm.h> 47 48 #include <machine/autoconf.h> 49 #include <machine/conf.h> 50 51 #include <dev/ic/cd18xxvar.h> 52 #include <dev/ic/cd18xxreg.h> 53 54 #include "ioconf.h" 55 #include "locators.h" 56 57 /* 1600se configuration register bits */ 58 #define SIO16_CONFIGREG_ENABLE_IO 8 59 #define SIO16_CONFIGREG_ENABLE_IRQ 4 60 61 /* 1600se interrupt ackknowledge register bytes */ 62 #define SIO16_MINT_ACK 1 /* modem interrupt acknowledge */ 63 #define SIO16_TINT_ACK 2 /* tx interrupt acknowledge */ 64 #define SIO16_RINT_ACK 3 /* rx interrupt acknowledge */ 65 66 /* 67 * device cfattach and cfdriver definitions, plus the routine we pass 68 * to the cd18xx code or interrupt acknowledgement. 69 */ 70 static int sio16_match __P((struct device *, struct cfdata *, void *)); 71 static void sio16_attach __P((struct device *, struct device *, void *)); 72 static u_char sio16_ackfunc(void *, int who); 73 74 /* 75 * define the sio16 per-device softc. 76 */ 77 struct sio16_softc { 78 struct device sc_dev; /* must be first */ 79 struct sbusdev sc_sd; /* for sbus drivers */ 80 81 /* sbus information */ 82 bus_space_tag_t sc_tag; /* bus tag for below */ 83 bus_space_handle_t sc_configreg; /* configuration register */ 84 bus_space_handle_t sc_reg[2]; /* cd180 register sets */ 85 bus_space_handle_t sc_ack; /* interrupt acknowledgement */ 86 #define SIO16_1600SE 0x00000001 87 88 u_int sc_clk; 89 90 /* cd180 information */ 91 int sc_ncd180; 92 93 }; 94 95 struct cfattach siosixteen_ca = { 96 sizeof(struct sio16_softc), sio16_match, sio16_attach 97 }; 98 99 struct sio16_attach_args { 100 bus_space_tag_t cd_tag; 101 bus_space_handle_t cd_handle; 102 u_char (*cd_ackfunc)(void *, int); 103 void *cd_ackfunc_arg; 104 u_int cd_osc; 105 }; 106 107 /* 108 * device match routine: is there an sio16 present? 109 * 110 * note that we can not put "sio16" in the cfdriver, as this is an 111 * illegal name, so we have to hard code it here. 112 */ 113 #define SIO16_ROM_NAME "sio16" 114 int 115 sio16_match(parent, cf, aux) 116 struct device *parent; 117 struct cfdata *cf; 118 void *aux; 119 { 120 struct sbus_attach_args *sa = aux; 121 122 /* does the prom think i'm an sio16? */ 123 if (strcmp(SIO16_ROM_NAME, sa->sa_name) != 0) 124 return (0); 125 126 return (1); 127 } 128 129 /* 130 * device attach routine: go attach all sub devices. 131 */ 132 void 133 sio16_attach(parent, self, aux) 134 struct device *parent, *self; 135 void *aux; 136 { 137 struct sbus_attach_args *sa = aux; 138 struct sio16_softc *sc = (struct sio16_softc *)self; 139 bus_space_handle_t h; 140 char *mode, *model; 141 int i; 142 143 if (sa->sa_nreg != 4) 144 panic("sio16_attach: got %d registers intead of 4\n", 145 sa->sa_nreg); 146 147 /* copy our bus tag, we will need it */ 148 sc->sc_tag = sa->sa_bustag; 149 150 /* 151 * sio16 has 4 register mappings. a single byte configuration 152 * register, 2 128 byte regions for the cd180 registers, and 153 * a 4 byte region for interrupt acknowledgement. 154 */ 155 if (sbus_bus_map(sa->sa_bustag, 156 sa->sa_reg[0].sbr_slot, 157 sa->sa_reg[0].sbr_offset, 158 sa->sa_reg[0].sbr_size, 159 0, &h) != 0) { 160 printf("%s at sbus: can not map registers 0\n", 161 self->dv_xname); 162 return; 163 } 164 sc->sc_configreg = h; 165 if (sbus_bus_map(sa->sa_bustag, 166 sa->sa_reg[1].sbr_slot, 167 sa->sa_reg[1].sbr_offset, 168 sa->sa_reg[1].sbr_size, 169 0, &h) != 0) { 170 printf("%s at sbus: can not map registers 1\n", 171 self->dv_xname); 172 return; 173 } 174 sc->sc_reg[0] = h; 175 if (sbus_bus_map(sa->sa_bustag, 176 sa->sa_reg[2].sbr_slot, 177 sa->sa_reg[2].sbr_offset, 178 sa->sa_reg[2].sbr_size, 179 0, &h) != 0) { 180 printf("%s at sbus: can not map registers 2\n", 181 self->dv_xname); 182 return; 183 } 184 sc->sc_reg[1] = h; 185 if (sbus_bus_map(sa->sa_bustag, 186 sa->sa_reg[3].sbr_slot, 187 sa->sa_reg[3].sbr_offset, 188 sa->sa_reg[3].sbr_size, 189 0, &h) != 0) { 190 printf("%s at sbus: can not map registers 3\n", 191 self->dv_xname); 192 return; 193 } 194 sc->sc_ack = h; 195 196 mode = PROM_getpropstring(sa->sa_node, "mode"); 197 if (mode) 198 printf(", %s mode", mode); 199 200 /* get the clock frequency */ 201 sc->sc_clk = PROM_getpropint(sa->sa_node, "clk", 24000); 202 203 model = PROM_getpropstring(sa->sa_node, "model"); 204 if (model == 0) { 205 printf(", no model property, bailing\n"); 206 return; 207 } 208 209 /* are we an 1600se? */ 210 if (strcmp(model, "1600se") == 0) { 211 printf(", 16 channels"); 212 sc->sc_ncd180 = 2; 213 } else { 214 printf(", don't know model %s, bailing\n", model); 215 return; 216 } 217 218 /* set up our sbus connections */ 219 sbus_establish(&sc->sc_sd, &sc->sc_dev); 220 221 /* establish interrupt channel */ 222 (void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_TTY, 0, 223 cd18xx_hardintr, sc); 224 225 /* reset the board, and turn on interrupts and I/O */ 226 bus_space_write_1(sa->sa_bustag, sc->sc_configreg, 0, 0); 227 delay(100); 228 bus_space_write_1(sa->sa_bustag, sc->sc_configreg, 0, 229 SIO16_CONFIGREG_ENABLE_IO | SIO16_CONFIGREG_ENABLE_IRQ | 230 (((sa->sa_pri) & 0x0f) >> 2)); 231 delay(10000); 232 233 printf("\n"); 234 235 /* finally, configure the clcd's underneath */ 236 for (i = 0; i < sc->sc_ncd180; i++) { 237 struct sio16_attach_args cd; 238 239 cd.cd_tag = sa->sa_bustag; 240 cd.cd_osc = sc->sc_clk * 100; 241 cd.cd_handle = (bus_space_handle_t)sc->sc_reg[i]; 242 cd.cd_ackfunc = sio16_ackfunc; 243 cd.cd_ackfunc_arg = sc; 244 (void)config_found(self, (void *)&cd, NULL); 245 } 246 } 247 248 /* 249 * note that the addresses used in this function match those assigned 250 * in clcd_attach() below, or the various service match routines. 251 */ 252 u_char 253 sio16_ackfunc(v, who) 254 void *v; 255 int who; 256 { 257 struct sio16_softc *sc = v; 258 bus_size_t addr; 259 260 switch (who) { 261 case CD18xx_INTRACK_RxINT: 262 case CD18xx_INTRACK_REINT: 263 addr = SIO16_RINT_ACK; 264 break; 265 case CD18xx_INTRACK_TxINT: 266 addr = SIO16_TINT_ACK; 267 break; 268 case CD18xx_INTRACK_MxINT: 269 addr = SIO16_MINT_ACK; 270 break; 271 default: 272 panic("%s: sio16_ackfunc: unknown ackfunc %d", 273 sc->sc_dev.dv_xname, who); 274 } 275 return (bus_space_read_1(sc->sc_tag, sc->sc_ack, addr)); 276 } 277 278 /* 279 * we attach two `clcd' instances per 1600se, that each call the 280 * backend cd18xx driver for help. 281 */ 282 static int clcd_match(struct device *, struct cfdata *, void *); 283 static void clcd_attach(struct device *, struct device *, void *); 284 285 struct cfattach clcd_ca = { 286 sizeof(struct cd18xx_softc), clcd_match, clcd_attach 287 }; 288 289 static int 290 clcd_match(parent, cf, aux) 291 struct device *parent; 292 struct cfdata *cf; 293 void *aux; 294 { 295 296 /* XXX */ 297 return 1; 298 } 299 300 static void 301 clcd_attach(parent, self, aux) 302 struct device *parent, *self; 303 void *aux; 304 { 305 struct cd18xx_softc *sc = (struct cd18xx_softc *)self; 306 struct sio16_attach_args *args = aux; 307 308 sc->sc_tag = args->cd_tag; 309 sc->sc_handle = args->cd_handle; 310 sc->sc_osc = args->cd_osc; 311 sc->sc_ackfunc = args->cd_ackfunc; 312 sc->sc_ackfunc_arg = args->cd_ackfunc_arg; 313 sc->sc_msmr = SIO16_MINT_ACK; 314 sc->sc_tsmr = SIO16_TINT_ACK; 315 sc->sc_rsmr = SIO16_RINT_ACK; 316 317 /* call the common code */ 318 cd18xx_attach(sc); 319 } 320