sio16.c revision 1.7
11.7Sprovos/* $NetBSD: sio16.c,v 1.7 2002/09/27 15:37:32 provos Exp $ */ 21.1Smrg 31.1Smrg/* 41.1Smrg * Copyright (c) 1998, 2001 Matthew R. Green 51.1Smrg * All rights reserved. 61.1Smrg * 71.1Smrg * Redistribution and use in source and binary forms, with or without 81.1Smrg * modification, are permitted provided that the following conditions 91.1Smrg * are met: 101.1Smrg * 1. Redistributions of source code must retain the above copyright 111.1Smrg * notice, this list of conditions and the following disclaimer. 121.1Smrg * 2. Redistributions in binary form must reproduce the above copyright 131.1Smrg * notice, this list of conditions and the following disclaimer in the 141.1Smrg * documentation and/or other materials provided with the distribution. 151.1Smrg * 3. The name of the author may not be used to endorse or promote products 161.1Smrg * derived from this software without specific prior written permission. 171.1Smrg * 181.1Smrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 191.1Smrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 201.1Smrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 211.1Smrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 221.1Smrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 231.1Smrg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 241.1Smrg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 251.1Smrg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 261.1Smrg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 271.1Smrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 281.1Smrg * SUCH DAMAGE. 291.1Smrg */ 301.1Smrg 311.1Smrg/* 321.1Smrg * aurora technologies nova16 driver. this board is an sbus card with 331.1Smrg * an external 16 port serial box. there are two cirrus logic cd180 341.1Smrg * 8 port serial chips used in the implementation. 351.1Smrg * 361.1Smrg * thanks go to Oliver Aldulea <oli@morcov.bv.ro> for writing the 371.1Smrg * linux driver of this that helped clear up a couple of issues. 381.1Smrg */ 391.2Slukem 401.2Slukem#include <sys/cdefs.h> 411.7Sprovos__KERNEL_RCSID(0, "$NetBSD: sio16.c,v 1.7 2002/09/27 15:37:32 provos Exp $"); 421.1Smrg 431.1Smrg#include <sys/param.h> 441.1Smrg#include <sys/conf.h> 451.1Smrg#include <sys/device.h> 461.1Smrg#include <sys/systm.h> 471.1Smrg 481.1Smrg#include <machine/autoconf.h> 491.1Smrg 501.1Smrg#include <dev/ic/cd18xxvar.h> 511.1Smrg#include <dev/ic/cd18xxreg.h> 521.1Smrg 531.1Smrg#include "ioconf.h" 541.1Smrg#include "locators.h" 551.1Smrg 561.1Smrg/* 1600se configuration register bits */ 571.1Smrg#define SIO16_CONFIGREG_ENABLE_IO 8 581.1Smrg#define SIO16_CONFIGREG_ENABLE_IRQ 4 591.1Smrg 601.1Smrg/* 1600se interrupt ackknowledge register bytes */ 611.1Smrg#define SIO16_MINT_ACK 1 /* modem interrupt acknowledge */ 621.1Smrg#define SIO16_TINT_ACK 2 /* tx interrupt acknowledge */ 631.1Smrg#define SIO16_RINT_ACK 3 /* rx interrupt acknowledge */ 641.1Smrg 651.1Smrg/* 661.1Smrg * device cfattach and cfdriver definitions, plus the routine we pass 671.1Smrg * to the cd18xx code or interrupt acknowledgement. 681.1Smrg */ 691.1Smrgstatic int sio16_match __P((struct device *, struct cfdata *, void *)); 701.1Smrgstatic void sio16_attach __P((struct device *, struct device *, void *)); 711.1Smrgstatic u_char sio16_ackfunc(void *, int who); 721.1Smrg 731.1Smrg/* 741.1Smrg * define the sio16 per-device softc. 751.1Smrg */ 761.1Smrgstruct sio16_softc { 771.1Smrg struct device sc_dev; /* must be first */ 781.1Smrg struct sbusdev sc_sd; /* for sbus drivers */ 791.1Smrg 801.1Smrg /* sbus information */ 811.1Smrg bus_space_tag_t sc_tag; /* bus tag for below */ 821.1Smrg bus_space_handle_t sc_configreg; /* configuration register */ 831.1Smrg bus_space_handle_t sc_reg[2]; /* cd180 register sets */ 841.1Smrg bus_space_handle_t sc_ack; /* interrupt acknowledgement */ 851.1Smrg#define SIO16_1600SE 0x00000001 861.1Smrg 871.1Smrg u_int sc_clk; 881.1Smrg 891.1Smrg /* cd180 information */ 901.1Smrg int sc_ncd180; 911.1Smrg 921.1Smrg}; 931.1Smrg 941.1Smrgstruct cfattach siosixteen_ca = { 951.1Smrg sizeof(struct sio16_softc), sio16_match, sio16_attach 961.1Smrg}; 971.1Smrg 981.1Smrgstruct sio16_attach_args { 991.1Smrg bus_space_tag_t cd_tag; 1001.1Smrg bus_space_handle_t cd_handle; 1011.1Smrg u_char (*cd_ackfunc)(void *, int); 1021.1Smrg void *cd_ackfunc_arg; 1031.1Smrg u_int cd_osc; 1041.1Smrg}; 1051.1Smrg 1061.1Smrg/* 1071.1Smrg * device match routine: is there an sio16 present? 1081.1Smrg * 1091.1Smrg * note that we can not put "sio16" in the cfdriver, as this is an 1101.1Smrg * illegal name, so we have to hard code it here. 1111.1Smrg */ 1121.1Smrg#define SIO16_ROM_NAME "sio16" 1131.1Smrgint 1141.1Smrgsio16_match(parent, cf, aux) 1151.1Smrg struct device *parent; 1161.1Smrg struct cfdata *cf; 1171.1Smrg void *aux; 1181.1Smrg{ 1191.1Smrg struct sbus_attach_args *sa = aux; 1201.1Smrg 1211.1Smrg /* does the prom think i'm an sio16? */ 1221.1Smrg if (strcmp(SIO16_ROM_NAME, sa->sa_name) != 0) 1231.1Smrg return (0); 1241.1Smrg 1251.1Smrg return (1); 1261.1Smrg} 1271.1Smrg 1281.1Smrg/* 1291.1Smrg * device attach routine: go attach all sub devices. 1301.1Smrg */ 1311.1Smrgvoid 1321.1Smrgsio16_attach(parent, self, aux) 1331.1Smrg struct device *parent, *self; 1341.1Smrg void *aux; 1351.1Smrg{ 1361.1Smrg struct sbus_attach_args *sa = aux; 1371.1Smrg struct sio16_softc *sc = (struct sio16_softc *)self; 1381.1Smrg bus_space_handle_t h; 1391.1Smrg char *mode, *model; 1401.1Smrg int i; 1411.1Smrg 1421.1Smrg if (sa->sa_nreg != 4) 1431.7Sprovos panic("sio16_attach: got %d registers intead of 4", 1441.1Smrg sa->sa_nreg); 1451.1Smrg 1461.1Smrg /* copy our bus tag, we will need it */ 1471.1Smrg sc->sc_tag = sa->sa_bustag; 1481.1Smrg 1491.1Smrg /* 1501.1Smrg * sio16 has 4 register mappings. a single byte configuration 1511.1Smrg * register, 2 128 byte regions for the cd180 registers, and 1521.1Smrg * a 4 byte region for interrupt acknowledgement. 1531.1Smrg */ 1541.1Smrg if (sbus_bus_map(sa->sa_bustag, 1551.5Smartin sa->sa_reg[0].oa_space, 1561.5Smartin sa->sa_reg[0].oa_base, 1571.5Smartin sa->sa_reg[0].oa_size, 1581.4Seeh 0, &h) != 0) { 1591.1Smrg printf("%s at sbus: can not map registers 0\n", 1601.1Smrg self->dv_xname); 1611.1Smrg return; 1621.1Smrg } 1631.1Smrg sc->sc_configreg = h; 1641.1Smrg if (sbus_bus_map(sa->sa_bustag, 1651.1Smrg sa->sa_reg[1].sbr_slot, 1661.1Smrg sa->sa_reg[1].sbr_offset, 1671.1Smrg sa->sa_reg[1].sbr_size, 1681.4Seeh 0, &h) != 0) { 1691.1Smrg printf("%s at sbus: can not map registers 1\n", 1701.1Smrg self->dv_xname); 1711.1Smrg return; 1721.1Smrg } 1731.1Smrg sc->sc_reg[0] = h; 1741.1Smrg if (sbus_bus_map(sa->sa_bustag, 1751.1Smrg sa->sa_reg[2].sbr_slot, 1761.1Smrg sa->sa_reg[2].sbr_offset, 1771.1Smrg sa->sa_reg[2].sbr_size, 1781.4Seeh 0, &h) != 0) { 1791.1Smrg printf("%s at sbus: can not map registers 2\n", 1801.1Smrg self->dv_xname); 1811.1Smrg return; 1821.1Smrg } 1831.1Smrg sc->sc_reg[1] = h; 1841.1Smrg if (sbus_bus_map(sa->sa_bustag, 1851.1Smrg sa->sa_reg[3].sbr_slot, 1861.1Smrg sa->sa_reg[3].sbr_offset, 1871.1Smrg sa->sa_reg[3].sbr_size, 1881.4Seeh 0, &h) != 0) { 1891.1Smrg printf("%s at sbus: can not map registers 3\n", 1901.1Smrg self->dv_xname); 1911.1Smrg return; 1921.1Smrg } 1931.1Smrg sc->sc_ack = h; 1941.1Smrg 1951.1Smrg mode = PROM_getpropstring(sa->sa_node, "mode"); 1961.1Smrg if (mode) 1971.1Smrg printf(", %s mode", mode); 1981.1Smrg 1991.1Smrg /* get the clock frequency */ 2001.1Smrg sc->sc_clk = PROM_getpropint(sa->sa_node, "clk", 24000); 2011.1Smrg 2021.1Smrg model = PROM_getpropstring(sa->sa_node, "model"); 2031.1Smrg if (model == 0) { 2041.1Smrg printf(", no model property, bailing\n"); 2051.1Smrg return; 2061.1Smrg } 2071.1Smrg 2081.1Smrg /* are we an 1600se? */ 2091.1Smrg if (strcmp(model, "1600se") == 0) { 2101.1Smrg printf(", 16 channels"); 2111.1Smrg sc->sc_ncd180 = 2; 2121.1Smrg } else { 2131.1Smrg printf(", don't know model %s, bailing\n", model); 2141.1Smrg return; 2151.1Smrg } 2161.1Smrg 2171.1Smrg /* set up our sbus connections */ 2181.1Smrg sbus_establish(&sc->sc_sd, &sc->sc_dev); 2191.1Smrg 2201.1Smrg /* establish interrupt channel */ 2211.1Smrg (void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_TTY, 0, 2221.1Smrg cd18xx_hardintr, sc); 2231.1Smrg 2241.1Smrg /* reset the board, and turn on interrupts and I/O */ 2251.1Smrg bus_space_write_1(sa->sa_bustag, sc->sc_configreg, 0, 0); 2261.1Smrg delay(100); 2271.1Smrg bus_space_write_1(sa->sa_bustag, sc->sc_configreg, 0, 2281.1Smrg SIO16_CONFIGREG_ENABLE_IO | SIO16_CONFIGREG_ENABLE_IRQ | 2291.1Smrg (((sa->sa_pri) & 0x0f) >> 2)); 2301.1Smrg delay(10000); 2311.1Smrg 2321.1Smrg printf("\n"); 2331.1Smrg 2341.1Smrg /* finally, configure the clcd's underneath */ 2351.1Smrg for (i = 0; i < sc->sc_ncd180; i++) { 2361.1Smrg struct sio16_attach_args cd; 2371.1Smrg 2381.1Smrg cd.cd_tag = sa->sa_bustag; 2391.1Smrg cd.cd_osc = sc->sc_clk * 100; 2401.1Smrg cd.cd_handle = (bus_space_handle_t)sc->sc_reg[i]; 2411.1Smrg cd.cd_ackfunc = sio16_ackfunc; 2421.1Smrg cd.cd_ackfunc_arg = sc; 2431.1Smrg (void)config_found(self, (void *)&cd, NULL); 2441.1Smrg } 2451.1Smrg} 2461.1Smrg 2471.1Smrg/* 2481.1Smrg * note that the addresses used in this function match those assigned 2491.1Smrg * in clcd_attach() below, or the various service match routines. 2501.1Smrg */ 2511.1Smrgu_char 2521.1Smrgsio16_ackfunc(v, who) 2531.1Smrg void *v; 2541.1Smrg int who; 2551.1Smrg{ 2561.1Smrg struct sio16_softc *sc = v; 2571.1Smrg bus_size_t addr; 2581.1Smrg 2591.1Smrg switch (who) { 2601.1Smrg case CD18xx_INTRACK_RxINT: 2611.1Smrg case CD18xx_INTRACK_REINT: 2621.1Smrg addr = SIO16_RINT_ACK; 2631.1Smrg break; 2641.1Smrg case CD18xx_INTRACK_TxINT: 2651.1Smrg addr = SIO16_TINT_ACK; 2661.1Smrg break; 2671.1Smrg case CD18xx_INTRACK_MxINT: 2681.1Smrg addr = SIO16_MINT_ACK; 2691.1Smrg break; 2701.1Smrg default: 2711.1Smrg panic("%s: sio16_ackfunc: unknown ackfunc %d", 2721.1Smrg sc->sc_dev.dv_xname, who); 2731.1Smrg } 2741.1Smrg return (bus_space_read_1(sc->sc_tag, sc->sc_ack, addr)); 2751.1Smrg} 2761.1Smrg 2771.1Smrg/* 2781.1Smrg * we attach two `clcd' instances per 1600se, that each call the 2791.1Smrg * backend cd18xx driver for help. 2801.1Smrg */ 2811.1Smrgstatic int clcd_match(struct device *, struct cfdata *, void *); 2821.1Smrgstatic void clcd_attach(struct device *, struct device *, void *); 2831.1Smrg 2841.1Smrgstruct cfattach clcd_ca = { 2851.1Smrg sizeof(struct cd18xx_softc), clcd_match, clcd_attach 2861.1Smrg}; 2871.1Smrg 2881.1Smrgstatic int 2891.1Smrgclcd_match(parent, cf, aux) 2901.1Smrg struct device *parent; 2911.1Smrg struct cfdata *cf; 2921.1Smrg void *aux; 2931.1Smrg{ 2941.1Smrg 2951.1Smrg /* XXX */ 2961.1Smrg return 1; 2971.1Smrg} 2981.1Smrg 2991.1Smrgstatic void 3001.1Smrgclcd_attach(parent, self, aux) 3011.1Smrg struct device *parent, *self; 3021.1Smrg void *aux; 3031.1Smrg{ 3041.1Smrg struct cd18xx_softc *sc = (struct cd18xx_softc *)self; 3051.1Smrg struct sio16_attach_args *args = aux; 3061.1Smrg 3071.1Smrg sc->sc_tag = args->cd_tag; 3081.1Smrg sc->sc_handle = args->cd_handle; 3091.1Smrg sc->sc_osc = args->cd_osc; 3101.1Smrg sc->sc_ackfunc = args->cd_ackfunc; 3111.1Smrg sc->sc_ackfunc_arg = args->cd_ackfunc_arg; 3121.1Smrg sc->sc_msmr = SIO16_MINT_ACK; 3131.1Smrg sc->sc_tsmr = SIO16_TINT_ACK; 3141.1Smrg sc->sc_rsmr = SIO16_RINT_ACK; 3151.1Smrg 3161.1Smrg /* call the common code */ 3171.1Smrg cd18xx_attach(sc); 3181.1Smrg} 319