LCOV - code coverage report
Current view: top level - dev/isa - lpt_isa.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 45 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*      $OpenBSD: lpt_isa.c,v 1.15 2015/03/14 03:38:47 jsg 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/bus.h>
      61             : 
      62             : #include <dev/isa/isavar.h>
      63             : #include <dev/ic/lptreg.h>
      64             : #include <dev/ic/lptvar.h>
      65             : 
      66             : int     lpt_isa_probe(struct device *, void *, void *);
      67             : void    lpt_isa_attach(struct device *, struct device *, void *);
      68             : 
      69             : struct cfattach lpt_isa_ca = {
      70             :         sizeof(struct lpt_softc), lpt_isa_probe, lpt_isa_attach, NULL,
      71             :         lpt_activate
      72             : };
      73             : 
      74             : /*
      75             :  * Logic:
      76             :  *      1) You should be able to write to and read back the same value
      77             :  *         to the data port.  Do an alternating zeros, alternating ones,
      78             :  *         walking zero, and walking one test to check for stuck bits.
      79             :  *
      80             :  *      2) You should be able to write to and read back the same value
      81             :  *         to the control port lower 5 bits, the upper 3 bits are reserved
      82             :  *         per the IBM PC technical reference manuals and different boards
      83             :  *         do different things with them.  Do an alternating zeros, alternating
      84             :  *         ones, walking zero, and walking one test to check for stuck bits.
      85             :  *
      86             :  *         Some printers drag the strobe line down when the are powered off
      87             :  *         so this bit has been masked out of the control port test.
      88             :  *
      89             :  *         XXX Some printers may not like a fast pulse on init or strobe, I
      90             :  *         don't know at this point, if that becomes a problem these bits
      91             :  *         should be turned off in the mask byte for the control port test.
      92             :  *
      93             :  *      3) Set the data and control ports to a value of 0
      94             :  */
      95             : int
      96           0 : lpt_isa_probe(parent, match, aux)
      97             :         struct device *parent;
      98             :         void *match, *aux;
      99             : {
     100             : #if !defined(__NO_ISA_INTR_CHECK)
     101           0 :         struct isa_softc *sc = (struct isa_softc *)parent;
     102             : #endif
     103           0 :         struct isa_attach_args *ia = aux;
     104             :         bus_space_tag_t iot;
     105           0 :         bus_space_handle_t ioh;
     106             :         bus_addr_t base;
     107             :         u_int8_t mask, data;
     108             :         int i, rv, iosz;
     109             : 
     110             : #ifdef DEBUG
     111             : #define ABORT                                                                \
     112             :         do {                                                                 \
     113             :                 printf("lpt_isa_probe: mask %x data %x failed\n", mask,            \
     114             :                     data);                                                   \
     115             :                 goto out;                                                    \
     116             :         } while (0)
     117             : #else
     118             : #define ABORT   goto out
     119             : #endif
     120             : 
     121           0 :         iot = ia->ia_iot;
     122           0 :         base = ia->ia_iobase;
     123           0 :         iosz = (ia->ia_iosize == 0x666) ? LPT_NPORTS : ia->ia_iosize;
     124           0 :         if (bus_space_map(iot, base, iosz, 0, &ioh))
     125           0 :                 return 0;
     126             : 
     127             :         rv = 0;
     128             :         mask = 0xff;
     129             : 
     130             :         data = 0x55;                            /* Alternating zeros */
     131           0 :         if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask))
     132             :                 ABORT;
     133             : 
     134             :         data = 0xaa;                            /* Alternating ones */
     135           0 :         if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask))
     136             :                 ABORT;
     137             : 
     138           0 :         for (i = 0; i < CHAR_BIT; i++) {     /* Walking zero */
     139           0 :                 data = ~(1 << i);
     140           0 :                 if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask))
     141             :                         ABORT;
     142             :         }
     143             : 
     144           0 :         for (i = 0; i < CHAR_BIT; i++) {     /* Walking one */
     145           0 :                 data = (1 << i);
     146           0 :                 if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask))
     147             :                         ABORT;
     148             :         }
     149             : 
     150           0 :         bus_space_write_1(iot, ioh, lpt_data, 0);
     151           0 :         bus_space_write_1(iot, ioh, lpt_control, 0);
     152             : 
     153             :         /*
     154             :          * Check if the specified IRQ is available.  If not revert to
     155             :          * polled mode.
     156             :          */
     157             : #if !defined(__NO_ISA_INTR_CHECK)
     158           0 :         if (ia->ia_irq != IRQUNK &&
     159           0 :             !isa_intr_check(sc->sc_ic, ia->ia_irq, IST_EDGE))
     160           0 :                 ia->ia_irq = IRQUNK;
     161             : #endif
     162           0 :         ia->ia_msize = 0;
     163           0 :         ia->ia_iosize = iosz;
     164             : 
     165           0 :         rv = 1;
     166             : 
     167             : out:
     168           0 :         bus_space_unmap(iot, ioh, iosz);
     169           0 :         return rv;
     170           0 : }
     171             : 
     172             : void
     173           0 : lpt_isa_attach(parent, self, aux)
     174             :         struct device *parent, *self;
     175             :         void *aux;
     176             : {
     177           0 :         struct lpt_softc *sc = (void *)self;
     178           0 :         struct isa_attach_args *ia = aux;
     179             : 
     180           0 :         sc->sc_state = 0;
     181           0 :         sc->sc_iot = ia->ia_iot;
     182           0 :         if (bus_space_map(sc->sc_iot, ia->ia_iobase, ia->ia_iosize, 0,
     183           0 :             &sc->sc_ioh))
     184           0 :                 panic("lpt_isa_attach: couldn't map I/O ports");
     185             : 
     186           0 :         if (ia->ia_irq == IRQUNK) {
     187           0 :                 sc->sc_flags |= LPT_POLLED;
     188           0 :                 printf(": polled");
     189           0 :         }
     190             : 
     191           0 :         lpt_attach_common(sc);
     192             : 
     193           0 :         if (ia->ia_irq != IRQUNK)
     194           0 :                 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
     195           0 :                     IPL_TTY, lptintr, sc, sc->sc_dev.dv_xname);
     196           0 : }

Generated by: LCOV version 1.13