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