[BACK]Return to com_ebus.c CVS log [TXT][DIR] Up to [local] / sys / arch / sparc64 / dev

Annotation of sys/arch/sparc64/dev/com_ebus.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: com_ebus.c,v 1.12 2007/04/03 23:17:42 kettenis Exp $  */
                      2: /*     $NetBSD: com_ebus.c,v 1.6 2001/07/24 19:27:10 eeh Exp $ */
                      3:
                      4: /*
                      5:  * Copyright (c) 1999, 2000 Matthew R. Green
                      6:  * All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. The name of the author may not be used to endorse or promote products
                     17:  *    derived from this software without specific prior written permission.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     20:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     21:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     22:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     23:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
                     24:  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
                     25:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
                     26:  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
                     27:  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     28:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     29:  * SUCH DAMAGE.
                     30:  */
                     31:
                     32: /*
                     33:  * NS Super I/O PC87332VLJ "com" to ebus attachment
                     34:  */
                     35:
                     36: #include <sys/types.h>
                     37: #include <sys/param.h>
                     38: #include <sys/systm.h>
                     39: #include <sys/device.h>
                     40: #include <sys/tty.h>
                     41: #include <sys/conf.h>
                     42:
                     43: #include <machine/bus.h>
                     44: #include <machine/autoconf.h>
                     45: #include <machine/openfirm.h>
                     46:
                     47: #include <sparc64/dev/ebusreg.h>
                     48: #include <sparc64/dev/ebusvar.h>
                     49:
                     50: #include <dev/cons.h>
                     51: #include <dev/ic/comvar.h>
                     52:
                     53: cdev_decl(com); /* XXX this belongs elsewhere */
                     54:
                     55: int    com_ebus_match(struct device *, void *, void *);
                     56: void   com_ebus_attach(struct device *, struct device *, void *);
                     57:
                     58: struct cfattach com_ebus_ca = {
                     59:        sizeof(struct com_softc), com_ebus_match, com_ebus_attach
                     60: };
                     61:
                     62: static char *com_names[] = {
                     63:        "su",
                     64:        "su_pnp",
                     65:        NULL
                     66: };
                     67:
                     68: int
                     69: com_ebus_match(parent, match, aux)
                     70:        struct device *parent;
                     71:        void *match;
                     72:        void *aux;
                     73: {
                     74:        struct ebus_attach_args *ea = aux;
                     75:        int i;
                     76:
                     77:        for (i=0; com_names[i]; i++)
                     78:                if (strcmp(ea->ea_name, com_names[i]) == 0)
                     79:                        return (1);
                     80:
                     81:        if (strcmp(ea->ea_name, "serial") == 0) {
                     82:                char compat[80];
                     83:
                     84:                /* Could be anything. */
                     85:                if ((i = OF_getproplen(ea->ea_node, "compatible")) &&
                     86:                        OF_getprop(ea->ea_node, "compatible", compat,
                     87:                                sizeof(compat)) == i) {
                     88:                        if (strcmp(compat, "su16552") == 0 ||
                     89:                            strcmp(compat, "su16550") == 0 ||
                     90:                            strcmp(compat, "su") == 0) {
                     91:                                return (1);
                     92:                        }
                     93:                }
                     94:        }
                     95:        return (0);
                     96: }
                     97:
                     98: /* XXXART - was 1846200 */
                     99: #define BAUD_BASE       (1843200)
                    100:
                    101: void
                    102: com_ebus_attach(parent, self, aux)
                    103:        struct device *parent, *self;
                    104:        void *aux;
                    105: {
                    106:        struct com_softc *sc = (void *)self;
                    107:        struct ebus_attach_args *ea = aux;
                    108:        int i, com_is_input, com_is_output;
                    109:
                    110:        sc->sc_iobase = EBUS_PADDR_FROM_REG(&ea->ea_regs[0]);
                    111:        /*
                    112:         * Addresses that should be supplied by the prom:
                    113:         *      - normal com registers
                    114:         *      - ns873xx configuration registers
                    115:         *      - DMA space
                    116:         * The `com' driver does not use DMA accesses, so we can
                    117:         * ignore that for now.  We should enable the com port in
                    118:         * the ns873xx registers here. XXX
                    119:         *
                    120:         * Use the prom address if there.
                    121:         */
                    122:        if (ea->ea_nvaddrs) {
                    123:                if (bus_space_map(ea->ea_memtag, ea->ea_vaddrs[0], 0,
                    124:                    BUS_SPACE_MAP_PROMADDRESS, &sc->sc_ioh) != 0) {
                    125:                        printf(": can't map register space\n");
                    126:                        return;
                    127:                }
                    128:                sc->sc_iot = ea->ea_memtag;
                    129:        } else if (ebus_bus_map(ea->ea_memtag, 0,
                    130:            EBUS_PADDR_FROM_REG(&ea->ea_regs[0]),
                    131:            ea->ea_regs[0].size, 0, 0, &sc->sc_ioh) == 0) {
                    132:                sc->sc_iot = ea->ea_memtag;
                    133:        } else if (ebus_bus_map(ea->ea_iotag, 0,
                    134:            EBUS_PADDR_FROM_REG(&ea->ea_regs[0]),
                    135:            ea->ea_regs[0].size, 0, 0, &sc->sc_ioh) == 0) {
                    136:                sc->sc_iot = ea->ea_iotag;
                    137:        } else {
                    138:                printf(": can't map register space\n");
                    139:                        return;
                    140:        }
                    141:        sc->sc_hwflags = 0;
                    142:        sc->sc_swflags = 0;
                    143:        sc->sc_frequency = BAUD_BASE;
                    144:
                    145:        for (i = 0; i < ea->ea_nintrs; i++)
                    146:                bus_intr_establish(sc->sc_iot, ea->ea_intrs[i],
                    147:                    IPL_TTY, 0, comintr, sc, self->dv_xname);
                    148:
                    149:        /* Figure out if we're the console. */
                    150:        com_is_input = (ea->ea_node == OF_instance_to_package(OF_stdin()));
                    151:        com_is_output = (ea->ea_node == OF_instance_to_package(OF_stdout()));
                    152:
                    153:        if (com_is_input || com_is_output) {
                    154:                struct consdev *cn_orig;
                    155:
                    156:                comconsioh = sc->sc_ioh;
                    157:                cn_orig = cn_tab;
                    158:                /* Attach com as the console. */
                    159:                if (comcnattach(sc->sc_iot, sc->sc_iobase, 9600,
                    160:                    sc->sc_frequency,
                    161:                    ((TTYDEF_CFLAG & ~(CSIZE | PARENB))|CREAD | CS8 | HUPCL))) {
                    162:                        printf("Error: comcnattach failed\n");
                    163:                }
                    164:                cn_tab = cn_orig;
                    165:                if (com_is_input) {
                    166:                        cn_tab->cn_dev = /*XXX*/makedev(36, sc->sc_dev.dv_unit);
                    167:                        cn_tab->cn_probe = comcnprobe;
                    168:                        cn_tab->cn_init = comcninit;
                    169:                        cn_tab->cn_getc = comcngetc;
                    170:                        cn_tab->cn_pollc = comcnpollc;
                    171:                }
                    172:                if (com_is_output)
                    173:                        cn_tab->cn_putc = comcnputc;
                    174:        }
                    175:
                    176:         if (OF_getproplen(ea->ea_node, "keyboard") == 0)
                    177:                printf(": keyboard");
                    178:        else if (OF_getproplen(ea->ea_node, "mouse") == 0)
                    179:                printf(": mouse");
                    180:
                    181:        /* Now attach the driver */
                    182:        com_attach_subr(sc);
                    183: }

CVSweb