[BACK]Return to asio.c CVS log [TXT][DIR] Up to [local] / sys / dev / sbus

Annotation of sys/dev/sbus/asio.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: asio.c,v 1.10 2003/06/27 01:50:52 jason Exp $ */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 2002 Jason L. Wright (jason@thought.net)
        !             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
        !            18:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        !            19:  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
        !            20:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
        !            21:  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        !            22:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            23:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
        !            24:  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
        !            25:  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        !            26:  * POSSIBILITY OF SUCH DAMAGE.
        !            27:  *
        !            28:  * Effort sponsored in part by the Defense Advanced Research Projects
        !            29:  * Agency (DARPA) and Air Force Research Laboratory, Air Force
        !            30:  * Materiel Command, USAF, under agreement number F30602-01-2-0537.
        !            31:  *
        !            32:  */
        !            33:
        !            34: /*
        !            35:  * Driver for Aurora 210SJ serial ports.
        !            36:  */
        !            37:
        !            38: #include <sys/types.h>
        !            39: #include <sys/param.h>
        !            40: #include <sys/systm.h>
        !            41: #include <sys/kernel.h>
        !            42: #include <sys/device.h>
        !            43: #include <sys/conf.h>
        !            44: #include <sys/timeout.h>
        !            45: #include <sys/tty.h>
        !            46:
        !            47: #include <machine/bus.h>
        !            48: #include <machine/autoconf.h>
        !            49: #include <machine/openfirm.h>
        !            50:
        !            51: #include <dev/sbus/sbusvar.h>
        !            52: #include <dev/sbus/asioreg.h>
        !            53: #include <dev/ic/comvar.h>
        !            54:
        !            55: #include "asio.h"
        !            56:
        !            57: #define BAUD_BASE       (1843200)
        !            58:
        !            59: struct asio_port {
        !            60:        u_int8_t                ap_inten;
        !            61:        bus_space_handle_t      ap_bh;
        !            62:        struct device           *ap_dev;
        !            63: };
        !            64:
        !            65: struct asio_softc {
        !            66:        struct device           sc_dev;
        !            67:        bus_space_tag_t         sc_bt;
        !            68:        bus_space_handle_t      sc_csr_h;
        !            69:        void                    *sc_ih;
        !            70:        struct asio_port        sc_ports[2];
        !            71:        int                     sc_nports;
        !            72: };
        !            73:
        !            74: struct asio_attach_args {
        !            75:        char *aaa_name;
        !            76:        int aaa_port;
        !            77:        bus_space_tag_t aaa_iot;
        !            78:        bus_space_handle_t aaa_ioh;
        !            79:        u_int32_t aaa_pri;
        !            80:        u_int8_t aaa_inten;
        !            81: };
        !            82:
        !            83: int    asio_match(struct device *, void *, void *);
        !            84: void   asio_attach(struct device *, struct device *, void *);
        !            85: int    asio_print(void *, const char *);
        !            86: void   asio_intr_enable(struct device *, u_int8_t);
        !            87:
        !            88: struct cfattach asio_ca = {
        !            89:        sizeof(struct asio_softc), asio_match, asio_attach
        !            90: };
        !            91:
        !            92: struct cfdriver asio_cd = {
        !            93:        NULL, "asio", DV_DULL
        !            94: };
        !            95:
        !            96: int
        !            97: asio_match(struct device *parent, void *match, void *aux)
        !            98: {
        !            99:        struct sbus_attach_args *sa = aux;
        !           100:
        !           101:        if (strcmp(sa->sa_name, "sio2") == 0)
        !           102:                return (1);
        !           103:        return (0);
        !           104: }
        !           105:
        !           106: void
        !           107: asio_attach(struct device *parent, struct device *self, void *aux)
        !           108: {
        !           109:        struct asio_softc *sc = (void *)self;
        !           110:        struct sbus_attach_args *sa = aux;
        !           111:        struct asio_attach_args aaa;
        !           112:        int i;
        !           113:        char *model;
        !           114:
        !           115:        sc->sc_bt = sa->sa_bustag;
        !           116:        sc->sc_nports = 2;
        !           117:
        !           118:        model = getpropstring(sa->sa_node, "model");
        !           119:        if (model == NULL) {
        !           120:                printf(": empty model, unsupported\n");
        !           121:                return;
        !           122:        }
        !           123:        if (strcmp(model, "210sj") != 0) {
        !           124:                printf(": unsupported model %s\n", model);
        !           125:                return;
        !           126:        }
        !           127:
        !           128:        if (sa->sa_nreg < 3) {
        !           129:                printf(": %d registers expected, got %d\n",
        !           130:                    3, sa->sa_nreg);
        !           131:                return;
        !           132:        }
        !           133:
        !           134:        if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot,
        !           135:            sa->sa_reg[0].sbr_offset, sa->sa_reg[0].sbr_size,
        !           136:            0, 0, &sc->sc_csr_h)) {
        !           137:                printf(": couldn't map csr\n");
        !           138:                return;
        !           139:        }
        !           140:
        !           141:        for (i = 0; i < sc->sc_nports; i++) {
        !           142:                if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[i + 1].sbr_slot,
        !           143:                    sa->sa_reg[i + 1].sbr_offset, sa->sa_reg[i + 1].sbr_size,
        !           144:                    0, 0, &sc->sc_ports[i].ap_bh)) {
        !           145:                        printf(": couldn't map uart%d\n", i);
        !           146:                        return;
        !           147:                }
        !           148:        }
        !           149:
        !           150:        sc->sc_ports[0].ap_inten = ASIO_CSR_SJ_UART0_INTEN;
        !           151:        sc->sc_ports[1].ap_inten = ASIO_CSR_UART1_INTEN;
        !           152:
        !           153:        printf(": %s\n", model);
        !           154:
        !           155:        for (i = 0; i < sc->sc_nports; i++) {
        !           156:                aaa.aaa_name = "com";
        !           157:                aaa.aaa_port = i;
        !           158:                aaa.aaa_iot = sc->sc_bt;
        !           159:                aaa.aaa_ioh = sc->sc_ports[i].ap_bh;
        !           160:                aaa.aaa_inten = sc->sc_ports[i].ap_inten;
        !           161:                aaa.aaa_pri = sa->sa_intr[0].sbi_pri;
        !           162:                sc->sc_ports[i].ap_dev = config_found(self, &aaa, asio_print);
        !           163:        }
        !           164: }
        !           165:
        !           166: int
        !           167: asio_print(void *aux, const char *name)
        !           168: {
        !           169:        struct asio_attach_args *aaa = aux;
        !           170:
        !           171:        if (name != NULL)
        !           172:                printf("%s at %s", aaa->aaa_name, name);
        !           173:        printf(" port %d", aaa->aaa_port);
        !           174:        return (UNCONF);
        !           175: }
        !           176:
        !           177: #if NCOM_ASIO > 0
        !           178: int    com_asio_match(struct device *, void *, void *);
        !           179: void   com_asio_attach(struct device *, struct device *, void *);
        !           180:
        !           181: struct cfattach com_asio_ca = {
        !           182:        sizeof(struct com_softc), com_asio_match, com_asio_attach
        !           183: };
        !           184:
        !           185: void
        !           186: asio_intr_enable(struct device *dv, u_int8_t en)
        !           187: {
        !           188:        struct asio_softc *sc = (struct asio_softc *)dv;
        !           189:        u_int8_t csr;
        !           190:
        !           191:        csr = bus_space_read_1(sc->sc_bt, sc->sc_csr_h, 0);
        !           192:        csr &= ~(ASIO_CSR_SBUS_INT7 | ASIO_CSR_SBUS_INT6);
        !           193:        csr |= ASIO_CSR_SBUS_INT5 | en;
        !           194:        bus_space_write_1(sc->sc_bt, sc->sc_csr_h, 0, csr);
        !           195: }
        !           196:
        !           197: int
        !           198: com_asio_match(struct device *parent, void *match, void *aux)
        !           199: {
        !           200:        return (1);
        !           201: }
        !           202:
        !           203: void
        !           204: com_asio_attach(struct device *parent, struct device *self, void *aux)
        !           205: {
        !           206:        struct com_softc *sc = (struct com_softc *)self;
        !           207:        struct asio_attach_args *aaa = aux;
        !           208:
        !           209:        sc->sc_iot = aaa->aaa_iot;
        !           210:        sc->sc_ioh = aaa->aaa_ioh;
        !           211:        sc->sc_iobase = 0;   /* XXX WTF is iobase for? It used to be the lower 32 bits of ioh's vaddr... */
        !           212:        sc->sc_hwflags = 0;
        !           213:        sc->sc_swflags = 0;
        !           214:        sc->sc_frequency = BAUD_BASE;
        !           215:
        !           216:        sc->sc_ih = bus_intr_establish(aaa->aaa_iot, aaa->aaa_pri,
        !           217:            IPL_TTY, 0, comintr, sc, self->dv_xname);
        !           218:        if (sc->sc_ih == NULL) {
        !           219:                printf(": cannot allocate intr\n");
        !           220:                return;
        !           221:        }
        !           222:        asio_intr_enable(parent, aaa->aaa_inten);
        !           223:
        !           224:        com_attach_subr(sc);
        !           225: }
        !           226: #endif

CVSweb