Home | History | Annotate | Line # | Download | only in gsc
lpt_gsc.c revision 1.1
      1  1.1  skrll /*	$NetBSD: lpt_gsc.c,v 1.1 2014/02/24 07:23:43 skrll Exp $	*/
      2  1.1  skrll 
      3  1.1  skrll /*	$OpenBSD: lpt_gsc.c,v 1.6 2000/07/21 17:41:06 mickey Exp $	*/
      4  1.1  skrll 
      5  1.1  skrll /*
      6  1.1  skrll  * Copyright (c) 1998 Michael Shalayeff
      7  1.1  skrll  * Copyright (c) 1993, 1994 Charles Hannum.
      8  1.1  skrll  * Copyright (c) 1990 William F. Jolitz, TeleMuse
      9  1.1  skrll  * All rights reserved.
     10  1.1  skrll  *
     11  1.1  skrll  * Redistribution and use in source and binary forms, with or without
     12  1.1  skrll  * modification, are permitted provided that the following conditions
     13  1.1  skrll  * are met:
     14  1.1  skrll  * 1. Redistributions of source code must retain the above copyright
     15  1.1  skrll  *    notice, this list of conditions and the following disclaimer.
     16  1.1  skrll  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  skrll  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  skrll  *    documentation and/or other materials provided with the distribution.
     19  1.1  skrll  * 3. All advertising materials mentioning features or use of this software
     20  1.1  skrll  *    must display the following acknowledgement:
     21  1.1  skrll  *	This software is a component of "386BSD" developed by
     22  1.1  skrll  *	William F. Jolitz, TeleMuse.
     23  1.1  skrll  * 4. Neither the name of the developer nor the name "386BSD"
     24  1.1  skrll  *    may be used to endorse or promote products derived from this software
     25  1.1  skrll  *    without specific prior written permission.
     26  1.1  skrll  *
     27  1.1  skrll  * THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ
     28  1.1  skrll  * AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS
     29  1.1  skrll  * SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT.
     30  1.1  skrll  * THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT
     31  1.1  skrll  * NOT MAKE USE OF THIS WORK.
     32  1.1  skrll  *
     33  1.1  skrll  * FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED
     34  1.1  skrll  * BY WILLIAM F. JOLITZ, WE RECOMMEND THE USER STUDY WRITTEN
     35  1.1  skrll  * REFERENCES SUCH AS THE  "PORTING UNIX TO THE 386" SERIES
     36  1.1  skrll  * (BEGINNING JANUARY 1991 "DR. DOBBS JOURNAL", USA AND BEGINNING
     37  1.1  skrll  * JUNE 1991 "UNIX MAGAZIN", GERMANY) BY WILLIAM F. JOLITZ AND
     38  1.1  skrll  * LYNNE GREER JOLITZ, AS WELL AS OTHER BOOKS ON UNIX AND THE
     39  1.1  skrll  * ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS
     40  1.1  skrll  * OF 386BSD ENTITLED "386BSD FROM THE INSIDE OUT" WILL BE AVAILABLE LATE 1992.
     41  1.1  skrll  *
     42  1.1  skrll  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
     43  1.1  skrll  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     44  1.1  skrll  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     45  1.1  skrll  * ARE DISCLAIMED.  IN NO EVENT SHALL THE DEVELOPER BE LIABLE
     46  1.1  skrll  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     47  1.1  skrll  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     48  1.1  skrll  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     49  1.1  skrll  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     50  1.1  skrll  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     51  1.1  skrll  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     52  1.1  skrll  * SUCH DAMAGE.
     53  1.1  skrll  */
     54  1.1  skrll 
     55  1.1  skrll #include <sys/cdefs.h>
     56  1.1  skrll __KERNEL_RCSID(0, "$NetBSD: lpt_gsc.c,v 1.1 2014/02/24 07:23:43 skrll Exp $");
     57  1.1  skrll 
     58  1.1  skrll #include <sys/param.h>
     59  1.1  skrll #include <sys/systm.h>
     60  1.1  skrll #include <sys/device.h>
     61  1.1  skrll 
     62  1.1  skrll #include <sys/bus.h>
     63  1.1  skrll #include <machine/intr.h>
     64  1.1  skrll #include <machine/iomod.h>
     65  1.1  skrll #include <machine/autoconf.h>
     66  1.1  skrll 
     67  1.1  skrll #include <dev/ic/lptreg.h>
     68  1.1  skrll #include <dev/ic/lptvar.h>
     69  1.1  skrll 
     70  1.1  skrll #include <hppa/dev/cpudevs.h>
     71  1.1  skrll 
     72  1.1  skrll #include <hppa/gsc/gscbusvar.h>
     73  1.1  skrll 
     74  1.1  skrll #define	LPTGSC_OFFSET	0x800
     75  1.1  skrll 
     76  1.1  skrll #ifndef	LPTDEBUG
     77  1.1  skrll #define	LPRINTF(a)
     78  1.1  skrll #else
     79  1.1  skrll #define	LPRINTF(a)	if (lpt_isa_debug) printf a
     80  1.1  skrll int lpt_isa_debug = 0;
     81  1.1  skrll #endif
     82  1.1  skrll 
     83  1.1  skrll int	lpt_gsc_probe(device_t, cfdata_t , void *);
     84  1.1  skrll void	lpt_gsc_attach(device_t, device_t, void *);
     85  1.1  skrll 
     86  1.1  skrll CFATTACH_DECL_NEW(lpt_gsc, sizeof(struct lpt_softc),
     87  1.1  skrll     lpt_gsc_probe, lpt_gsc_attach, NULL, NULL);
     88  1.1  skrll 
     89  1.1  skrll int	lpt_port_test(bus_space_tag_t, bus_space_handle_t, bus_addr_t,
     90  1.1  skrll 	    bus_size_t, u_char, u_char);
     91  1.1  skrll 
     92  1.1  skrll /*
     93  1.1  skrll  * Internal routine to lptprobe to do port tests of one byte value.
     94  1.1  skrll  */
     95  1.1  skrll int
     96  1.1  skrll lpt_port_test(bus_space_tag_t iot, bus_space_handle_t ioh, bus_addr_t base,
     97  1.1  skrll     bus_size_t off, u_char data, u_char mask)
     98  1.1  skrll {
     99  1.1  skrll 	int timeout;
    100  1.1  skrll 	u_char temp;
    101  1.1  skrll 
    102  1.1  skrll 	data &= mask;
    103  1.1  skrll 	bus_space_write_1(iot, ioh, off, data);
    104  1.1  skrll 	timeout = 1000;
    105  1.1  skrll 	do {
    106  1.1  skrll 		delay(10);
    107  1.1  skrll 		temp = bus_space_read_1(iot, ioh, off) & mask;
    108  1.1  skrll 	} while (temp != data && --timeout);
    109  1.1  skrll 	LPRINTF(("lpt: port=0x%x out=0x%x in=0x%x timeout=%d\n",
    110  1.1  skrll 	    (unsigned)(base + off), (unsigned)data, (unsigned)temp, timeout));
    111  1.1  skrll 	return (temp == data);
    112  1.1  skrll }
    113  1.1  skrll 
    114  1.1  skrll /*
    115  1.1  skrll  * Logic:
    116  1.1  skrll  *	1) You should be able to write to and read back the same value
    117  1.1  skrll  *	   to the data port.  Do an alternating zeros, alternating ones,
    118  1.1  skrll  *	   walking zero, and walking one test to check for stuck bits.
    119  1.1  skrll  *
    120  1.1  skrll  *	2) You should be able to write to and read back the same value
    121  1.1  skrll  *	   to the control port lower 5 bits, the upper 3 bits are reserved
    122  1.1  skrll  *	   per the IBM PC technical reference manauls and different boards
    123  1.1  skrll  *	   do different things with them.  Do an alternating zeros, alternating
    124  1.1  skrll  *	   ones, walking zero, and walking one test to check for stuck bits.
    125  1.1  skrll  *
    126  1.1  skrll  *	   Some printers drag the strobe line down when the are powered off
    127  1.1  skrll  * 	   so this bit has been masked out of the control port test.
    128  1.1  skrll  *
    129  1.1  skrll  *	   XXX Some printers may not like a fast pulse on init or strobe, I
    130  1.1  skrll  *	   don't know at this point, if that becomes a problem these bits
    131  1.1  skrll  *	   should be turned off in the mask byte for the control port test.
    132  1.1  skrll  *
    133  1.1  skrll  *	3) Set the data and control ports to a value of 0
    134  1.1  skrll  */
    135  1.1  skrll int
    136  1.1  skrll lpt_gsc_probe(device_t parent, cfdata_t match, void *aux)
    137  1.1  skrll {
    138  1.1  skrll 	struct gsc_attach_args *ga = aux;
    139  1.1  skrll 	bus_space_handle_t ioh;
    140  1.1  skrll 	bus_addr_t base;
    141  1.1  skrll 	uint8_t mask, data;
    142  1.1  skrll 	int i;
    143  1.1  skrll 
    144  1.1  skrll 	if (ga->ga_type.iodc_type != HPPA_TYPE_FIO ||
    145  1.1  skrll 	    ga->ga_type.iodc_sv_model != HPPA_FIO_CENT)
    146  1.1  skrll 		return 0;
    147  1.1  skrll 
    148  1.1  skrll #ifdef DEBUG
    149  1.1  skrll #define	ABORT								     \
    150  1.1  skrll 	do {								     \
    151  1.1  skrll 		printf("lpt_gsc_probe: mask %x data %x failed\n", mask,	     \
    152  1.1  skrll 		    data);						     \
    153  1.1  skrll 		bus_space_unmap(ga->ga_iot, ioh, LPT_NPORTS);		     \
    154  1.1  skrll 		return 0;						     \
    155  1.1  skrll 	} while (0)
    156  1.1  skrll #else
    157  1.1  skrll #define	ABORT								     \
    158  1.1  skrll 	do {								     \
    159  1.1  skrll 		bus_space_unmap(ga->ga_iot, ioh, LPT_NPORTS);		     \
    160  1.1  skrll 		return 0;						     \
    161  1.1  skrll 	} while (0)
    162  1.1  skrll #endif
    163  1.1  skrll 
    164  1.1  skrll 	base = ga->ga_hpa + LPTGSC_OFFSET;
    165  1.1  skrll 	if (bus_space_map(ga->ga_iot, base, LPT_NPORTS, 0, &ioh))
    166  1.1  skrll 		return 0;
    167  1.1  skrll 
    168  1.1  skrll 	mask = 0xff;
    169  1.1  skrll 
    170  1.1  skrll 	data = 0x55;				/* Alternating zeros */
    171  1.1  skrll 	if (!lpt_port_test(ga->ga_iot, ioh, base, lpt_data, data, mask))
    172  1.1  skrll 		ABORT;
    173  1.1  skrll 
    174  1.1  skrll 	data = 0xaa;				/* Alternating ones */
    175  1.1  skrll 	if (!lpt_port_test(ga->ga_iot, ioh, base, lpt_data, data, mask))
    176  1.1  skrll 		ABORT;
    177  1.1  skrll 
    178  1.1  skrll 	for (i = 0; i < CHAR_BIT; i++) {	/* Walking zero */
    179  1.1  skrll 		data = ~(1 << i);
    180  1.1  skrll 		if (!lpt_port_test(ga->ga_iot, ioh, base, lpt_data, data, mask))
    181  1.1  skrll 			ABORT;
    182  1.1  skrll 	}
    183  1.1  skrll 
    184  1.1  skrll 	for (i = 0; i < CHAR_BIT; i++) {	/* Walking one */
    185  1.1  skrll 		data = (1 << i);
    186  1.1  skrll 		if (!lpt_port_test(ga->ga_iot, ioh, base, lpt_data, data, mask))
    187  1.1  skrll 			ABORT;
    188  1.1  skrll 	}
    189  1.1  skrll 
    190  1.1  skrll 	bus_space_write_1(ga->ga_iot, ioh, lpt_data, 0);
    191  1.1  skrll 	bus_space_write_1(ga->ga_iot, ioh, lpt_control, 0);
    192  1.1  skrll 	bus_space_unmap(ga->ga_iot, ioh, LPT_NPORTS);
    193  1.1  skrll 
    194  1.1  skrll 	return 1;
    195  1.1  skrll }
    196  1.1  skrll 
    197  1.1  skrll void
    198  1.1  skrll lpt_gsc_attach(device_t parent, device_t self, void *aux)
    199  1.1  skrll {
    200  1.1  skrll 	struct lpt_softc *sc = device_private(self);
    201  1.1  skrll 	struct gsc_attach_args *ga = aux;
    202  1.1  skrll 
    203  1.1  skrll 	/* sc->sc_flags |= LPT_POLLED; */
    204  1.1  skrll 
    205  1.1  skrll 	sc->sc_dev = self;
    206  1.1  skrll 	sc->sc_state = 0;
    207  1.1  skrll 	sc->sc_iot = ga->ga_iot;
    208  1.1  skrll 	if (bus_space_map(sc->sc_iot, ga->ga_hpa + LPTGSC_OFFSET,
    209  1.1  skrll 			  LPT_NPORTS, 0, &sc->sc_ioh)) {
    210  1.1  skrll 		aprint_error(": can't map i/o ports\n");
    211  1.1  skrll 		return;
    212  1.1  skrll 	}
    213  1.1  skrll 
    214  1.1  skrll 	lpt_attach_subr(sc);
    215  1.1  skrll 
    216  1.1  skrll 	sc->sc_ih = hppa_intr_establish(IPL_TTY, lptintr, sc, ga->ga_ir,
    217  1.1  skrll 	     ga->ga_irq);
    218  1.1  skrll 	aprint_normal("\n");
    219  1.1  skrll }
    220