Annotation of sys/arch/sgi/dev/lpt_lbus.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: lpt_lbus.c,v 1.4 2005/01/31 21:35:50 grange Exp $ */
! 2:
! 3: /*
! 4: * Copyright (c) 1993, 1994 Charles Hannum.
! 5: * Copyright (c) 1990 William F. Jolitz, TeleMuse
! 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. All advertising materials mentioning features or use of this software
! 17: * must display the following acknowledgement:
! 18: * This software is a component of "386BSD" developed by
! 19: * William F. Jolitz, TeleMuse.
! 20: * 4. Neither the name of the developer nor the name "386BSD"
! 21: * may be used to endorse or promote products derived from this software
! 22: * without specific prior written permission.
! 23: *
! 24: * THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ
! 25: * AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS
! 26: * SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT.
! 27: * THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT
! 28: * NOT MAKE USE OF THIS WORK.
! 29: *
! 30: * FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED
! 31: * BY WILLIAM F. JOLITZ, WE RECOMMEND THE USER STUDY WRITTEN
! 32: * REFERENCES SUCH AS THE "PORTING UNIX TO THE 386" SERIES
! 33: * (BEGINNING JANUARY 1991 "DR. DOBBS JOURNAL", USA AND BEGINNING
! 34: * JUNE 1991 "UNIX MAGAZIN", GERMANY) BY WILLIAM F. JOLITZ AND
! 35: * LYNNE GREER JOLITZ, AS WELL AS OTHER BOOKS ON UNIX AND THE
! 36: * ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS
! 37: * OF 386BSD ENTITLED "386BSD FROM THE INSIDE OUT" WILL BE AVAILABLE LATE 1992.
! 38: *
! 39: * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
! 40: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 41: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 42: * ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER BE LIABLE
! 43: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 44: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 45: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 46: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 47: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 48: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 49: * SUCH DAMAGE.
! 50: */
! 51:
! 52: /*
! 53: * Device Driver for AT parallel printer port
! 54: */
! 55:
! 56: #include <sys/param.h>
! 57: #include <sys/systm.h>
! 58: #include <sys/device.h>
! 59:
! 60: #include <machine/autoconf.h>
! 61: #include <machine/bus.h>
! 62: #include <machine/intr.h>
! 63:
! 64: #include <dev/ic/lptreg.h>
! 65: #include <dev/ic/lptvar.h>
! 66:
! 67: int lpt_localbus_probe(struct device *, void *, void *);
! 68: void lpt_localbus_attach(struct device *, struct device *, void *);
! 69:
! 70: struct cfattach lpt_pica_ca = {
! 71: sizeof(struct lpt_softc), lpt_localbus_probe, lpt_localbus_attach
! 72: };
! 73:
! 74: struct cfattach lpt_algor_ca = {
! 75: sizeof(struct lpt_softc), lpt_localbus_probe, lpt_localbus_attach
! 76: };
! 77:
! 78: int
! 79: lpt_localbus_probe(parent, match, aux)
! 80: struct device *parent;
! 81: void *match, *aux;
! 82: {
! 83: struct confargs *ca = aux;
! 84: bus_space_tag_t iot;
! 85: bus_space_handle_t ioh;
! 86: bus_addr_t base;
! 87: u_int8_t mask, data;
! 88: int i;
! 89:
! 90: #ifdef DEBUG
! 91: #define ABORT \
! 92: do { \
! 93: printf("lpt_localbus_probe: mask %x data %x failed\n", mask, \
! 94: data); \
! 95: return 0; \
! 96: } while (0)
! 97: #else
! 98: #define ABORT return 0
! 99: #endif
! 100:
! 101: if (!BUS_MATCHNAME(ca, "lpt"))
! 102: return(0);
! 103:
! 104: /*XXX need to check where to pick up iotag when porting this */
! 105: iot = sys_config.localbus_iot;
! 106: base = (bus_addr_t)BUS_CVTADDR(ca);
! 107: if (bus_space_map(iot, base, LPT_NPORTS, 0, &ioh)) {
! 108: return 0;
! 109: }
! 110:
! 111: mask = 0xff;
! 112:
! 113: data = 0x55; /* Alternating zeros */
! 114: if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask))
! 115: ABORT;
! 116:
! 117: data = 0xaa; /* Alternating ones */
! 118: if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask))
! 119: ABORT;
! 120:
! 121: for (i = 0; i < CHAR_BIT; i++) { /* Walking zero */
! 122: data = ~(1 << i);
! 123: if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask))
! 124: ABORT;
! 125: }
! 126:
! 127: for (i = 0; i < CHAR_BIT; i++) { /* Walking one */
! 128: data = (1 << i);
! 129: if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask))
! 130: ABORT;
! 131: }
! 132:
! 133: bus_space_write_1(iot, ioh, lpt_data, 0);
! 134: bus_space_write_1(iot, ioh, lpt_control, 0);
! 135:
! 136: return 1;
! 137: }
! 138:
! 139: void
! 140: lpt_localbus_attach(parent, self, aux)
! 141: struct device *parent, *self;
! 142: void *aux;
! 143: {
! 144: struct lpt_softc *sc = (void *)self;
! 145: struct confargs *ca = aux;
! 146: bus_space_tag_t iot;
! 147: bus_space_handle_t ioh;
! 148: bus_addr_t base;
! 149:
! 150: printf("\n");
! 151:
! 152: sc->sc_state = 0;
! 153: iot = sc->sc_iot = &pmonmips_bus_io;
! 154: base = (bus_space_handle_t)BUS_CVTADDR(ca);
! 155: if (bus_space_map(iot, base, LPT_NPORTS, 0, &ioh)) {
! 156: panic("unexpected bus_space_map error");
! 157: }
! 158: sc->sc_ioh = ioh;
! 159:
! 160: bus_space_write_1(iot, ioh, lpt_control, LPC_NINIT);
! 161:
! 162: BUS_INTR_ESTABLISH(ca, lptintr, sc);
! 163: }
CVSweb