Module Name:    src
Committed By:   jmcneill
Date:           Mon Sep 28 11:33:15 UTC 2020

Modified Files:
        src/sys/dev/ic: com.c comreg.h

Log Message:
Auto-detect DW APB UART FIFO length and print the FIFO length when enabled
instead of just "working fifo".


To generate a diff of this commit:
cvs rdiff -u -r1.359 -r1.360 src/sys/dev/ic/com.c
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/ic/comreg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/ic/com.c
diff -u src/sys/dev/ic/com.c:1.359 src/sys/dev/ic/com.c:1.360
--- src/sys/dev/ic/com.c:1.359	Tue May 26 13:24:52 2020
+++ src/sys/dev/ic/com.c	Mon Sep 28 11:33:15 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: com.c,v 1.359 2020/05/26 13:24:52 martin Exp $ */
+/* $NetBSD: com.c,v 1.360 2020/09/28 11:33:15 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2004, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.359 2020/05/26 13:24:52 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.360 2020/09/28 11:33:15 jmcneill Exp $");
 
 #include "opt_com.h"
 #include "opt_ddb.h"
@@ -428,9 +428,10 @@ com_attach_subr(struct com_softc *sc)
 {
 	struct com_regs *regsp = &sc->sc_regs;
 	struct tty *tp;
-	u_int8_t lcr;
+	uint32_t cpr;
+	uint8_t lcr;
 	const char *fifo_msg = NULL;
-	prop_dictionary_t	dict;
+	prop_dictionary_t dict;
 	bool is_console = true;
 	bool force_console = false;
 
@@ -498,32 +499,32 @@ com_attach_subr(struct com_softc *sc)
 
 	case COM_TYPE_AU1x00:
 		sc->sc_fifolen = 16;
-		fifo_msg = "Au1X00 UART, working fifo";
+		fifo_msg = "Au1X00 UART";
 		SET(sc->sc_hwflags, COM_HW_FIFO);
 		goto fifodelay;
 
 	case COM_TYPE_16550_NOERS:
 		sc->sc_fifolen = 16;
-		fifo_msg = "ns16650, no ERS, working fifo";
+		fifo_msg = "ns16650, no ERS";
 		SET(sc->sc_hwflags, COM_HW_FIFO);
 		goto fifodelay;
 
 	case COM_TYPE_OMAP:
 		sc->sc_fifolen = 64;
-		fifo_msg = "OMAP UART, working fifo";
+		fifo_msg = "OMAP UART";
 		SET(sc->sc_hwflags, COM_HW_FIFO);
 		goto fifodelay;
 
 	case COM_TYPE_INGENIC:
 		sc->sc_fifolen = 16;
-		fifo_msg = "Ingenic UART, working fifo";
+		fifo_msg = "Ingenic UART";
 		SET(sc->sc_hwflags, COM_HW_FIFO);
 		SET(sc->sc_hwflags, COM_HW_NOIEN);
 		goto fifodelay;
 
 	case COM_TYPE_TEGRA:
 		sc->sc_fifolen = 8;
-		fifo_msg = "Tegra UART, working fifo";
+		fifo_msg = "Tegra UART";
 		SET(sc->sc_hwflags, COM_HW_FIFO);
 		CSR_WRITE_1(regsp, COM_REG_FIFO,
 		    FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1);
@@ -531,11 +532,26 @@ com_attach_subr(struct com_softc *sc)
 
 	case COM_TYPE_BCMAUXUART:
 		sc->sc_fifolen = 1;
-		fifo_msg = "BCM AUX UART, working fifo";
+		fifo_msg = "BCM AUX UART";
 		SET(sc->sc_hwflags, COM_HW_FIFO);
 		CSR_WRITE_1(regsp, COM_REG_FIFO,
 		    FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1);
 		goto fifodelay;
+
+	case COM_TYPE_DW_APB:
+		cpr = bus_space_read_4(sc->sc_regs.cr_iot, sc->sc_regs.cr_ioh,
+		    DW_APB_UART_CPR);
+		sc->sc_fifolen = __SHIFTOUT(cpr, UART_CPR_FIFO_MODE) * 16;
+		if (sc->sc_fifolen == 0) {
+			fifo_msg = "DesignWare APB UART, no fifo";
+			CSR_WRITE_1(regsp, COM_REG_FIFO, 0);
+		} else {
+			fifo_msg = "DesignWare APB UART";
+			SET(sc->sc_hwflags, COM_HW_FIFO);
+			CSR_WRITE_1(regsp, COM_REG_FIFO,
+			    FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1);
+		}
+		goto fifodelay;
 	}
 
 	sc->sc_fifolen = 1;
@@ -554,7 +570,7 @@ com_attach_subr(struct com_softc *sc)
 		    == FIFO_TRIGGER_14) {
 			SET(sc->sc_hwflags, COM_HW_FIFO);
 
-			fifo_msg = "ns16550a, working fifo";
+			fifo_msg = "ns16550a";
 
 			/*
 			 * IIR changes into the EFR if LCR is set to LCR_EERS
@@ -588,9 +604,9 @@ com_attach_subr(struct com_softc *sc)
 				if (sc->sc_fifolen == 0)
 					fifo_msg = "st16650, broken fifo";
 				else if (sc->sc_fifolen == 32)
-					fifo_msg = "st16650a, working fifo";
+					fifo_msg = "st16650a";
 				else
-					fifo_msg = "ns16550a, working fifo";
+					fifo_msg = "ns16550a";
 			}
 
 			/*
@@ -629,9 +645,9 @@ com_attach_subr(struct com_softc *sc)
 					CSR_WRITE_1(regsp, COM_REG_FIFO, fcr);
 
 				if (sc->sc_fifolen == 64)
-					fifo_msg = "tl16c750, working fifo";
+					fifo_msg = "tl16c750";
 				else
-					fifo_msg = "ns16750, working fifo";
+					fifo_msg = "ns16750";
 			}
 		} else
 			fifo_msg = "ns16550, broken fifo";
@@ -647,7 +663,11 @@ fifodelay:
 	 * printing it until now.
 	 */
 	delay(10);
-	aprint_normal(": %s\n", fifo_msg);
+	if (ISSET(sc->sc_hwflags, COM_HW_FIFO)) {
+		aprint_normal(": %s, %d-byte FIFO\n", fifo_msg, sc->sc_fifolen);
+	} else {
+		aprint_normal(": %s\n", fifo_msg);
+	}
 	if (ISSET(sc->sc_hwflags, COM_HW_TXFIFO_DISABLE)) {
 		sc->sc_fifolen = 1;
 		aprint_normal_dev(sc->sc_dev, "txfifo disabled\n");

Index: src/sys/dev/ic/comreg.h
diff -u src/sys/dev/ic/comreg.h:1.26 src/sys/dev/ic/comreg.h:1.27
--- src/sys/dev/ic/comreg.h:1.26	Sun Oct 29 14:06:08 2017
+++ src/sys/dev/ic/comreg.h	Mon Sep 28 11:33:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: comreg.h,v 1.26 2017/10/29 14:06:08 jmcneill Exp $	*/
+/*	$NetBSD: comreg.h,v 1.27 2020/09/28 11:33:15 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 1991 The Regents of the University of California.
@@ -162,6 +162,9 @@
 #define HALT_CHCFG_UD			0x04 /* apply updates to LCR/dividors */
 #define HALT_CHCFG_EN			0x02 /* enable change while busy */
 
+/* DesignWare-specific registers */
+#define	DW_APB_UART_CPR			0xf4
+#define	 UART_CPR_FIFO_MODE		__BITS(23,16)
 
 /* XXX ISA-specific. */
 #define	COM_NPORTS	8

Reply via email to