Subject: Re: nextkbd.c cngetc patches
To: Darrin B. Jewell <jewell@MIT.EDU>
From: matt debergalis <deberg@MIT.EDU>
List: port-next68k
Date: 03/25/1999 11:38:02
    Darrin>   I looked at the NeXT keyboard polling problem this morning
    Darrin> briefly.  Have you tried polling by looping on
    Darrin> "INTR_OCCURRED(NEXT_I_KYBD_MOUSE)" ? This is similar to what
    Darrin> the bootloader does to poll the ethernet and scsi devices.

    Darrin> Below are patches where i've implemented such an idea.  They
    Darrin> have not been tested because my machine is busy building a
    Darrin> snapshot and I haven't had the time to set up a second one
    Darrin> for development yet.  What do you think?

yup, looks good!

here's an slightly modified version of that patch that cleans a couple
things up...

Index: nextkbd.c
===================================================================
RCS file: /src/cvsroot-netbsd/netbsd/src/sys/arch/next68k/dev/nextkbd.c,v
retrieving revision 1.6
diff -c -c -r1.6 nextkbd.c
*** nextkbd.c	1999/03/24 15:48:18	1.6
--- nextkbd.c	1999/03/25 16:24:13
***************
*** 105,111 ****
  	KB_US,
  };
  
! static int nextkbd_poll_data __P((bus_space_tag_t, bus_space_handle_t));
  static int nextkbd_decode __P((struct nextkbd_internal *, int, u_int *, int *));
  
  static struct nextkbd_internal nextkbd_consdata;
--- 105,111 ----
  	KB_US,
  };
  
! static int nextkbd_read_data __P((struct nextkbd_internal *));
  static int nextkbd_decode __P((struct nextkbd_internal *, int, u_int *, int *));
  
  static struct nextkbd_internal nextkbd_consdata;
***************
*** 184,190 ****
  	int on;
  {
  	/* XXX not sure if this should do anything */
! 	printf("nextkbd_enable %d\n", on);
  	return 0;
  }
  
--- 184,190 ----
  	int on;
  {
  	/* XXX not sure if this should do anything */
! 	/* printf("nextkbd_enable %d\n", on); */
  	return 0;
  }
  
***************
*** 228,236 ****
  	void *arg;
  {
  	register struct nextkbd_softc *sc = arg;
! 	struct mon_regs stat;
! 	unsigned char device;
! 	int type, key;
  
  	if (!INTR_OCCURRED(NEXT_I_KYBD_MOUSE)) return 0;
  
--- 228,234 ----
  	void *arg;
  {
  	register struct nextkbd_softc *sc = arg;
! 	int type, key, val;
  
  	if (!INTR_OCCURRED(NEXT_I_KYBD_MOUSE)) return 0;
  
***************
*** 249,271 ****
  #define KD_VALID				0x8000 /* only set for scancode keys ? */
  #define KD_MODS					0x4f00
  
! 	bus_space_read_region_4(sc->id->iot, sc->id->ioh, 0, &stat, 3);
! 	if (stat.mon_csr & CSR_INT) {
!                 if (stat.mon_csr & CSR_DATA) {
!                         stat.mon_csr &= ~CSR_INT;
! 			sc->id->num_ints++;
! 			bus_space_write_4(sc->id->iot, sc->id->ioh, 0, stat.mon_csr);
! 			device = stat.mon_data >> 28;
! 			if (device != 1) return(1); /* XXX: mouse */
! 			if (nextkbd_decode(sc->id, stat.mon_data & 0xffff, &type, &key)) {
! 				wskbd_input(sc->sc_wskbddev, type, key);
! 			}
! 		} else {
!                         printf("nextkbd: int but no data\n");
!                         return(1);
!                 }
  	}
- 
  	return(1);
  }
  
--- 247,256 ----
  #define KD_VALID				0x8000 /* only set for scancode keys ? */
  #define KD_MODS					0x4f00
  
! 	val = nextkbd_read_data(sc->id);
! 	if ((val != -1) && nextkbd_decode(sc->id, val, &type, &key)) {
! 		wskbd_input(sc->sc_wskbddev, type, key);
  	}
  	return(1);
  }
  
***************
*** 301,312 ****
  	struct nextkbd_internal *t = v;
  	int val;
  
- 	/* printf("cngetc: data at %08x (%08x)\n", t, v); */
  	for (;;) {
! 		val = nextkbd_poll_data(t->iot, t->ioh);
! 		/* printf("%08x\n", val); */
! 		if ((val != -1) && nextkbd_decode(t, val, type, data))
! 			return;
  	}
  }
  
--- 286,297 ----
  	struct nextkbd_internal *t = v;
  	int val;
  
  	for (;;) {
! 		if (INTR_OCCURRED(NEXT_I_KYBD_MOUSE)) {
! 			val = nextkbd_read_data(t);
! 			if ((val != -1) && nextkbd_decode(t, val, type, data))
! 				return;
! 		}
  	}
  }
  
***************
*** 317,323 ****
  {
  	struct nextkbd_internal *t = v;
  
- 	printf("cnpollc %d\n", on);
  	t->polling = on;
  	if (on) {
  		INTR_DISABLE(NEXT_I_KYBD_MOUSE);
--- 302,307 ----
***************
*** 328,353 ****
  }
  
  static int
! nextkbd_poll_data(iot, ioh)
! 	bus_space_tag_t iot;
! 	bus_space_handle_t ioh;
  {
! 	int i;
  	struct mon_regs stat;
  				
! 	/* printf("cnstart\n"); */
! 	for (i=100000; i; i--) {
! 		bus_space_read_region_4(iot, ioh, 0, &stat, 3);
!                 stat.mon_csr &= ~CSR_INT;
!                 if ( (stat.mon_csr & CSR_DATA) ) {
! 			if ( (stat.mon_data >> 28) == 1) {
!                           /* printf("cnkey %08x %08x\n", stat.mon_csr, stat.mon_data); */
! 				bus_space_write_4(iot, ioh, 0, stat.mon_csr);
! 				return (stat.mon_data & 0xffff);
! 			}
! 		}
  	}
- 	/* printf("cnend %08x %08x\n", stat.mon_csr, stat.mon_data); */
  	return (-1);
  }
  
--- 312,331 ----
  }
  
  static int
! nextkbd_read_data(struct nextkbd_internal *id)
  {
! 	unsigned char device;
  	struct mon_regs stat;
  				
! 	bus_space_read_region_4(id->iot, id->ioh, 0, &stat, 3);
! 	if ((stat.mon_csr & CSR_INT) && (stat.mon_csr & CSR_DATA)) {
! 		stat.mon_csr &= ~CSR_INT;
! 		id->num_ints++;
! 		bus_space_write_4(id->iot, id->ioh, 0, stat.mon_csr);
! 		device = stat.mon_data >> 28;
! 		if (device != 1) return (-1); /* XXX: mouse */
! 		return (stat.mon_data & 0xffff);
  	}
  	return (-1);
  }
  


matt
-- 
matt debergalis <deberg@mit.edu> KB1CTH
finger deberg@ai.mit.edu for PGP key