Home | History | Annotate | Line # | Download | only in isa
ast.c revision 1.2
      1  1.1      cgd /*
      2  1.1      cgd  * Multi-port serial card interrupt demuxing support.
      3  1.1      cgd  * Roland McGrath 3/20/94
      4  1.2  mycroft  * Charles Hannum 3/22/94
      5  1.1      cgd  *
      6  1.2  mycroft  *	$Id: ast.c,v 1.2 1994/03/23 03:01:50 mycroft Exp $
      7  1.1      cgd  */
      8  1.1      cgd 
      9  1.1      cgd #include "ast.h"
     10  1.1      cgd 
     11  1.1      cgd #include <sys/types.h>
     12  1.2  mycroft #include <sys/device.h>
     13  1.1      cgd 
     14  1.1      cgd #include <machine/pio.h>
     15  1.1      cgd #include <i386/isa/isa_device.h>
     16  1.1      cgd 
     17  1.1      cgd int astprobe __P((struct isa_device *));
     18  1.1      cgd int astattach __P((struct isa_device *));
     19  1.1      cgd 
     20  1.1      cgd struct	isa_driver astdriver = {
     21  1.1      cgd 	astprobe, astattach, "ast"
     22  1.1      cgd };
     23  1.1      cgd 
     24  1.2  mycroft struct ast_softc {
     25  1.2  mycroft 	struct device sc_dev;
     26  1.2  mycroft 	u_short sc_iobase;
     27  1.2  mycroft 	int sc_alive;		/* Mask of slave units attached. */
     28  1.2  mycroft 	int sc_slaves[8];	/* com device unit numbers. XXX - softc ptrs */
     29  1.2  mycroft } ast_softc[NAST];
     30  1.1      cgd 
     31  1.1      cgd int
     32  1.2  mycroft astprobe(dev)
     33  1.2  mycroft 	struct isa_device *dev;
     34  1.1      cgd {
     35  1.2  mycroft 
     36  1.1      cgd 	/*
     37  1.1      cgd 	 * Do the normal com probe for the first UART and assume
     38  1.1      cgd 	 * its presence means there is a multiport board there.
     39  1.1      cgd 	 * XXX needs more robustness.
     40  1.1      cgd 	 */
     41  1.2  mycroft 	return comprobe1(dev->id_iobase);
     42  1.1      cgd }
     43  1.1      cgd 
     44  1.1      cgd int
     45  1.2  mycroft astattach(dev)
     46  1.2  mycroft 	struct isa_device *dev;
     47  1.1      cgd {
     48  1.2  mycroft 	struct ast_softc *sc = &ast_softc[dev->id_unit];
     49  1.2  mycroft   	u_short iobase = dev->id_iobase;
     50  1.1      cgd 	unsigned int x;
     51  1.2  mycroft 
     52  1.2  mycroft 	/* XXX HACK */
     53  1.2  mycroft 	sprintf(sc->sc_dev.dv_xname, "%s%d", astdriver.name, dev->id_unit);
     54  1.2  mycroft 	sc->sc_dev.dv_unit = dev->id_unit;
     55  1.2  mycroft 
     56  1.2  mycroft 	sc->sc_iobase = iobase;
     57  1.1      cgd 
     58  1.1      cgd 	/*
     59  1.2  mycroft 	 * Enable the master interrupt.
     60  1.1      cgd 	 */
     61  1.2  mycroft 	outb(iobase | 0x1f, 0x80);
     62  1.2  mycroft 	x = inb(iobase | 0x1f);
     63  1.1      cgd 	/*
     64  1.1      cgd 	 * My guess is this bitmask tells you how many ports are there.
     65  1.1      cgd 	 * I only have a 4-port board to try (returns 0xf). --roland
     66  1.2  mycroft 	 *
     67  1.2  mycroft 	 * It's also not clear that it would be correct to rely on this, since
     68  1.2  mycroft 	 * there might be an interrupt pending on one of the ports, and thus
     69  1.2  mycroft 	 * its bit wouldn't be set.  - mycroft
     70  1.1      cgd 	 */
     71  1.2  mycroft 	printf("%s: 0x%x\n", sc->sc_dev.dv_xname, x);
     72  1.1      cgd }
     73  1.1      cgd 
     74  1.1      cgd void
     75  1.2  mycroft astslave(dev)
     76  1.2  mycroft 	struct isa_device *dev;
     77  1.1      cgd {
     78  1.2  mycroft 	struct ast_softc *sc = &ast_softc[dev->id_parent->id_unit];
     79  1.1      cgd 
     80  1.2  mycroft 	sc->sc_slaves[dev->id_physid] = dev->id_unit;
     81  1.2  mycroft 	sc->sc_alive |= 1 << dev->id_physid;
     82  1.1      cgd }
     83  1.1      cgd 
     84  1.1      cgd int
     85  1.2  mycroft astintr(unit)
     86  1.2  mycroft 	int unit;
     87  1.1      cgd {
     88  1.2  mycroft 	struct ast_softc *sc = &ast_softc[unit];
     89  1.2  mycroft 	u_short iobase = sc->sc_iobase;
     90  1.2  mycroft 	int alive = sc->sc_alive;
     91  1.1      cgd 	int bits;
     92  1.1      cgd 
     93  1.2  mycroft 	bits = inb(iobase | 0x1f) & alive;
     94  1.2  mycroft 	if (bits == alive)
     95  1.2  mycroft 		return 0;
     96  1.2  mycroft 
     97  1.1      cgd 	do {
     98  1.2  mycroft #define	TRY(n) \
     99  1.2  mycroft 		if ((bits & (1 << (n))) == 0) \
    100  1.2  mycroft 			comintr(sc->sc_slaves[n]);	/* XXX softc ptr */
    101  1.2  mycroft 		TRY(0);
    102  1.2  mycroft 		TRY(1);
    103  1.2  mycroft 		TRY(2);
    104  1.2  mycroft 		TRY(3);
    105  1.2  mycroft 		TRY(4);
    106  1.2  mycroft 		TRY(5);
    107  1.2  mycroft 		TRY(6);
    108  1.2  mycroft 		TRY(7);
    109  1.2  mycroft 		bits = inb(iobase | 0x1f) & alive;
    110  1.1      cgd  	} while (bits != alive);
    111  1.1      cgd 
    112  1.1      cgd 	return 1;
    113  1.1      cgd }
    114