From vak@crox.net.kiae.su  Tue May  6 12:35:58 1997
Received: from crox.net.kiae.su (crox.net.kiae.su [144.206.130.72])
          by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id MAA00342
          for <FreeBSD-gnats-submit@freebsd.org>; Tue, 6 May 1997 12:35:56 -0700 (PDT)
Received: by crox.net.kiae.su id XAA00455;
  (8.8.5/vak/1.8a) Tue, 6 May 1997 23:35:48 +0400 (MSD)
Message-Id: <199705061935.XAA00455@crox.net.kiae.su>
Date: Tue, 6 May 1997 23:35:48 +0400 (MSD)
From: vak@cronyx.ru
Reply-To: vak@cronyx.ru
To: FreeBSD-gnats-submit@freebsd.org
Subject: [patch] sio: automatic detection of 16550/16750 controllers
X-Send-Pr-Version: 3.2

>Number:         3523
>Category:       i386
>Synopsis:       sio driver: added automatic detection of 16650/16750 UARTs
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue May  6 12:40:01 PDT 1997
>Closed-Date:    Sun May 18 14:00:17 PDT 1997
>Last-Modified:  Sun May 18 14:00:35 PDT 1997
>Originator:     Serge V.Vakulenko
>Release:        FreeBSD 2.2.1-RELEASE i386
>Organization:
Cronyx Engineering Ltd.
>Environment:

	FreeBSD 2.2.1 with Cronyx-Omega multiport serial card
	(Based on Startech 16c654 UARTs).
	Or any other serial adapter with 16650 or 16750 chips.

>Description:

	The driver detects UARTs as 16550A which is not correct.

>How-To-Repeat:
>Fix:
	
	Apply the following patch:

--- sio221.c	Sat Feb  1 19:19:05 1997
+++ sio.c	Tue May  6 23:28:37 1997
@@ -856,12 +856,46 @@
 		printf(" 16550?");
 		break;
 	case FIFO_RX_HIGH:
-		printf(" 16550A");
 		if (COM_NOFIFO(isdp)) {
-			printf(" fifo disabled");
+			printf(" 16550A fifo disabled");
 		} else {
+			/* Detect the fifo size. */
+			int i, n;
+
+			/* Enable and reset the FIFO. */
+			outb (iobase+com_fifo, FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST);
+
+			/* Set the loopback mode, 57600 baud. */
+			outb (iobase+com_cfcr, CFCR_DLAB);
+			outb (iobase+com_dlbh, 0);
+			outb (iobase+com_dlbl, 2);
+			outb (iobase+com_cfcr, CFCR_8BITS);
+			outb (iobase+com_mcr, MCR_LOOPBACK);
+			inb (iobase+com_lsr);
+
+			/* Put data into transmit FIFO and wait until overrun. */
+			for (i=n=0; i<20000; ++i) {
+				unsigned char lsr = inb (iobase+com_lsr);
+				if (lsr & LSR_OE)
+					break;
+				if (lsr & LSR_TXRDY) {
+					outb (iobase+com_data, 0x5A);
+					++n;
+				}
+			}
+			outb (iobase+com_mcr, 0);
+			outb (iobase+com_fifo, 0);
+
 			com->hasfifo = TRUE;
-			com->tx_fifo_size = 16;
+			if (n > 40) {
+				com->tx_fifo_size = 64;
+				printf(" 16750");
+			} else if (n > 24) {
+				com->tx_fifo_size = 32;
+				printf(" 16650");
+			} else
+				com->tx_fifo_size = 16;
+				printf(" 16550A");
 #ifdef COM_ESP
 			for (espp = likely_esp_ports; *espp != 0; espp++)
 				if (espattach(isdp, com, *espp)) {


>Release-Note:
>Audit-Trail:

From: Poul-Henning Kamp <phk@dk.tfs.com>
To: vak@cronyx.ru
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: i386/3523: [patch] sio: automatic detection of 16550/16750 controllers 
Date: Tue, 06 May 1997 23:16:33 +0200

 I applied this to my -current system, and it correctly identifies
 my 650 chips, but I don't like that it also says 550 on those lines:
 
 sio0 at 0x3f8-0x3ff irq 4 on isa
 sio0: type 16550A
 sio1 at 0x2f8-0x2ff irq 3 on isa
 sio1: type 16550A
 sio2 at 0x2a0-0x2a7 irq 10 flags 0x285 on isa
 sio2: type 16650 16550A (multiport master)
 sio3 at 0x2a8-0x2af flags 0x285 on isa
 sio3: type 16650 16550A (multiport)
 sio4 at 0x2b0-0x2b7 flags 0x285 on isa
 sio4: type 16650 16550A (multiport)
 sio5 at 0x2b8-0x2bf flags 0x285 on isa
 sio5: type 16550A (multiport)
 
 (sio5 is correct, I swapped that chip with an 550A some time ago.)
 
 I guess we should report the fifo depth too ?
 
 --
 Poul-Henning Kamp           | phk@FreeBSD.ORG       FreeBSD Core-team.
 http://www.freebsd.org/~phk | phk@login.dknet.dk    Private mailbox.
 whois: [PHK]                | phk@tfs.com           TRW Financial Systems, Inc.
 Power and ignorance is a disgusting cocktail.

From: "Serge V.Vakulenko" <vak@crox.net.kiae.su>
To: Poul-Henning Kamp <phk@dk.tfs.com>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: i386/3523: [patch] sio: automatic detection of 16550/16750 controllers 
Date: Wed, 7 May 1997 12:13:14 +0400 (MSD)

 On Tue, 6 May 1997, Poul-Henning Kamp wrote:
 
 > 
 > I applied this to my -current system, and it correctly identifies
 > my 650 chips, but I don't like that it also says 550 on those lines:
 > 
 > sio0 at 0x3f8-0x3ff irq 4 on isa
 > sio0: type 16550A
 > sio1 at 0x2f8-0x2ff irq 3 on isa
 > sio1: type 16550A
 > sio2 at 0x2a0-0x2a7 irq 10 flags 0x285 on isa
 > sio2: type 16650 16550A (multiport master)
 > sio3 at 0x2a8-0x2af flags 0x285 on isa
 > sio3: type 16650 16550A (multiport)
 > sio4 at 0x2b0-0x2b7 flags 0x285 on isa
 > sio4: type 16650 16550A (multiport)
 > sio5 at 0x2b8-0x2bf flags 0x285 on isa
 > sio5: type 16550A (multiport)
 > 
 > (sio5 is correct, I swapped that chip with an 550A some time ago.)
 
 Sorry, just a mistype...
 See the patch below.
  
 > I guess we should report the fifo depth too ?
 
 I am not sure this makes sense.
 
 Serge
 
 --- sio.c.b	Tue May  6 23:28:37 1997
 +++ sio.c	Wed May  7 12:09:09 1997
 @@ -893,9 +893,10 @@
  			} else if (n > 24) {
  				com->tx_fifo_size = 32;
  				printf(" 16650");
 -			} else
 +			} else {
  				com->tx_fifo_size = 16;
  				printf(" 16550A");
 +			}
  #ifdef COM_ESP
  			for (espp = likely_esp_ports; *espp != 0; espp++)
  				if (espattach(isdp, com, *espp)) {
 
 ___
 Serge Vakulenko                    <vak@cronyx.ru>
 Cronyx Engineering Ltd., Moscow    Digital communication hardware development,
 phone/fax: +7 (095) 196-40-53      Internet services, FreeBSD support
 
 
 
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Sun May 18 14:00:17 PDT 1997 
State-Changed-Why:  

committed, thanks! 
>Unformatted:
