Subject: kern/3699: support 230k or more speed with Hayes ESP serial card.
To: None <gnats-bugs@gnats.netbsd.org>
From: None <enami@ba2.so-net.or.jp>
List: netbsd-bugs
Date: 06/03/1997 00:04:51
>Number:         3699
>Category:       kern
>Synopsis:       support 230k or more speed with Hayes ESP serial card.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Jun  2 08:20:01 1997
>Last-Modified:
>Originator:     enami tsugutomo
>Organization:
>Release:        NetBSD-current 1997 May 31
>Environment:
System: NetBSD pavlov.enami.ba2.so-net.or.jp 1.2E NetBSD 1.2E (PAVLOV) #275: Sat May 31 22:21:28 JST 1997 enami@pavlov.enami.ba2.so-net.or.jp:/b/netbsd/kernel/compile/PAVLOV i386


>Description:
	Hayes ESP can communicate with 230kbps or higher speed even if
	in 16650 compatible mode, but current NetBSD doesn't support it.

>How-To-Repeat:
	Try to use 230kbps or higher speed with Hayes ESP under NetBSD;
	probably you can't.

>Fix:
	Here is minimal patch to support the speed of 230kbps or higher.
	Since I intended to keep diffs small, this patch is not perfect;
	for example, you can't use the high speed if Hayes ESP is console.
	But it is enough for normal use.

	I've tested two ESP card connected each together and setup slip
	with 921600bps, and got about 70KB/sec when transering 16Mbytes
	of data by ttcp.

Index: ic/hayespreg.h
===================================================================
RCS file: /a/cvsroot/NetBSD/src/sys/dev/ic/hayespreg.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 hayespreg.h
--- hayespreg.h	1996/11/16 10:55:22	1.1.1.1
+++ hayespreg.h	1997/04/15 12:35:36
@@ -57,6 +57,7 @@
 #define	HAYESP_SETFLOWTYPE	0x08	/* set type of flow-control (2b) */
 #define	HAYESP_SETRXFLOW	0x0a	/* set Rx FIFO " levels (4b) */
 #define	HAYESP_SETMODE		0x10	/* set board mode (1b) */
+#define	HAYESP_SETPRESCALER	0x23	/* set UART clock prescaler (1b) */
 
 /* Mode bits (HAYESP_SETMODE). */
 #define	HAYESP_MODE_FIFO	0x02	/* act like a 16550 (compat mode) */
Index: isa/com.c
===================================================================
RCS file: /a/cvsroot/NetBSD/src/sys/dev/isa/com.c,v
retrieving revision 1.1.1.8
diff -u -r1.1.1.8 com.c
--- com.c	1997/05/27 13:44:09	1.1.1.8
+++ com.c	1997/06/02 14:51:02
@@ -365,6 +365,8 @@
 	}
 
 #ifdef COM_HAYESP
+	sc->sc_prescaler = 0;			/* set prescaler to x1. */
+
 	/* Look for a Hayes ESP board. */
 	for (hayespp = hayesp_ports; *hayespp != 0; hayespp++) {
 		bus_space_handle_t hayespioh;
@@ -768,10 +770,30 @@
 	struct termios *t;
 {
 	struct com_softc *sc = com_cd.cd_devs[COMUNIT(tp->t_dev)];
-	int ospeed = comspeed(t->c_ospeed);
+	int ospeed;
 	u_char lcr;
 	int s;
 
+#ifdef COM_HAYESP
+	if (ISSET(sc->sc_hwflags, COM_HW_HAYESP)) {
+		int prescaler, speed;
+
+		/*
+		 * Calculate UART clock prescaler.  It should be in
+		 * range of 0 .. 3.
+		 */
+		for (prescaler = 0, speed = t->c_ospeed; prescaler < 4;
+		    prescaler++, speed /= 2)
+			if ((ospeed = comspeed(speed)) > 0)
+				break;
+
+		if (prescaler == 4)
+			return (EINVAL);
+		sc->sc_prescaler = prescaler;
+	} else
+#endif
+	ospeed = comspeed(t->c_ospeed);
+
 	/* check requested parameters */
 	if (ospeed < 0)
 		return (EINVAL);
@@ -964,6 +986,14 @@
 	bus_space_write_1(iot, ioh, com_lcr, sc->sc_lcr);
 	bus_space_write_1(iot, ioh, com_mcr, sc->sc_mcr_active = sc->sc_mcr);
 	bus_space_write_1(iot, ioh, com_fifo, sc->sc_fifo);
+#ifdef COM_HAYESP
+	if (ISSET(sc->sc_hwflags, COM_HW_HAYESP)) {
+		bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD1,
+		    HAYESP_SETPRESCALER);
+		bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD2,
+		    sc->sc_prescaler);
+	}
+#endif
 
 	bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
 }
Index: isa/comvar.h
===================================================================
RCS file: /a/cvsroot/NetBSD/src/sys/dev/isa/comvar.h,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 comvar.h
--- comvar.h	1997/05/24 14:47:02	1.1.1.4
+++ comvar.h	1997/05/31 13:39:09
@@ -70,6 +70,9 @@
 	u_char sc_msr, sc_msr_delta, sc_msr_mask, sc_mcr, sc_mcr_active, sc_lcr,
 	       sc_ier, sc_fifo, sc_dlbl, sc_dlbh;
 	u_char sc_mcr_dtr, sc_mcr_rts, sc_msr_cts, sc_msr_dcd;
+#ifdef COM_HAYESP
+	u_char sc_prescaler;
+#endif
 
 	int sc_r_hiwat;
  	volatile u_int sc_rbget;
>Audit-Trail:
>Unformatted: