Home | History | Annotate | Line # | Download | only in isa
ast.c revision 1.1
      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.1  cgd  *
      5  1.1  cgd  *	$Id: ast.c,v 1.1 1994/03/23 01:26:14 cgd Exp $
      6  1.1  cgd  */
      7  1.1  cgd 
      8  1.1  cgd #include "ast.h"
      9  1.1  cgd 
     10  1.1  cgd #include <sys/types.h>
     11  1.1  cgd 
     12  1.1  cgd #include <machine/pio.h>
     13  1.1  cgd #include <i386/isa/isa_device.h>
     14  1.1  cgd 
     15  1.1  cgd int astprobe __P((struct isa_device *));
     16  1.1  cgd int astattach __P((struct isa_device *));
     17  1.1  cgd 
     18  1.1  cgd struct	isa_driver astdriver = {
     19  1.1  cgd 	astprobe, astattach, "ast"
     20  1.1  cgd };
     21  1.1  cgd 
     22  1.1  cgd struct astunit			/* XXX ast_softc? */
     23  1.1  cgd {
     24  1.1  cgd 	u_short iobase;
     25  1.1  cgd 	int alive;		/* Mask of slave units attached. */
     26  1.1  cgd 	int slaveunits[8];	/* com device unit numbers. XXX - softc ptrs */
     27  1.1  cgd } astunits[NAST];
     28  1.1  cgd 
     29  1.1  cgd int
     30  1.1  cgd astprobe(struct isa_device *isa_dev)
     31  1.1  cgd {
     32  1.1  cgd 	/*
     33  1.1  cgd 	 * Do the normal com probe for the first UART and assume
     34  1.1  cgd 	 * its presence means there is a multiport board there.
     35  1.1  cgd 	 * XXX needs more robustness.
     36  1.1  cgd 	 */
     37  1.1  cgd 	return comprobe1(isa_dev->id_iobase);
     38  1.1  cgd }
     39  1.1  cgd 
     40  1.1  cgd int
     41  1.1  cgd astattach(struct isa_device *isa_dev)
     42  1.1  cgd {
     43  1.1  cgd 	int unit = isa_dev->id_unit;
     44  1.1  cgd   	u_short iobase = isa_dev->id_iobase;
     45  1.1  cgd 	unsigned int x;
     46  1.1  cgd 
     47  1.1  cgd 	astunits[unit].iobase = iobase;
     48  1.1  cgd 
     49  1.1  cgd 	/*
     50  1.1  cgd 	 * XXX calculation of master address is a bit hazy --
     51  1.1  cgd 	 * what if > 4 ports, etc.
     52  1.1  cgd 	 */
     53  1.1  cgd 	outb (iobase | 0x1f, 0x80);
     54  1.1  cgd 	x = inb (iobase | 0x1f);
     55  1.1  cgd 	/*
     56  1.1  cgd 	 * My guess is this bitmask tells you how many ports are there.
     57  1.1  cgd 	 * I only have a 4-port board to try (returns 0xf). --roland
     58  1.1  cgd 	 */
     59  1.1  cgd 	printf ("ast%d: 0x%x\n", unit, x);
     60  1.1  cgd }
     61  1.1  cgd 
     62  1.1  cgd void
     63  1.1  cgd astslave(struct isa_device *slave, int comunit)
     64  1.1  cgd {
     65  1.1  cgd 	struct astunit *a = &astunits[slave->id_parent->id_unit];
     66  1.1  cgd 
     67  1.1  cgd 	a->slaveunits[slave->id_physid] = comunit;
     68  1.1  cgd 	a->alive |= 1 << slave->id_physid;
     69  1.1  cgd }
     70  1.1  cgd 
     71  1.1  cgd int
     72  1.1  cgd astintr(int unit)
     73  1.1  cgd {
     74  1.1  cgd 	struct astunit *a = &astunits[unit];
     75  1.1  cgd 	u_short iobase = a->iobase;
     76  1.1  cgd 	int alive = a->alive;
     77  1.1  cgd 	int bits;
     78  1.1  cgd 
     79  1.1  cgd 	do {
     80  1.1  cgd 		bits = inb (iobase | 0x1f) & alive;
     81  1.1  cgd #define TRY(I)	((bits & (1 << (I))) ? 0 : comintr (a->slaveunits[I]))
     82  1.1  cgd 		TRY (0), TRY (1), TRY (2), TRY (3);
     83  1.1  cgd 		/* XXX -- i think the next 4 are bogus, see above -- cgd */
     84  1.1  cgd 		TRY (4), TRY (5), TRY (6), TRY (7);
     85  1.1  cgd #undef TRY
     86  1.1  cgd  	} while (bits != alive);
     87  1.1  cgd 
     88  1.1  cgd 	return 1;
     89  1.1  cgd }
     90