Module Name:    src
Committed By:   kiyohara
Date:           Sun Sep  1 04:51:24 UTC 2013

Modified Files:
        src/sys/dev/ic: com.c comreg.h comvar.h ns16550reg.h
        src/sys/dev/marvell: com_mv.c

Log Message:
Move the Marvell extension to com_mv.c.


To generate a diff of this commit:
cvs rdiff -u -r1.312 -r1.313 src/sys/dev/ic/com.c
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/ic/comreg.h
cvs rdiff -u -r1.75 -r1.76 src/sys/dev/ic/comvar.h
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/ic/ns16550reg.h
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/marvell/com_mv.c

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.312 src/sys/dev/ic/com.c:1.313
--- src/sys/dev/ic/com.c:1.312	Sat Jul 27 06:54:35 2013
+++ src/sys/dev/ic/com.c	Sun Sep  1 04:51:24 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: com.c,v 1.312 2013/07/27 06:54:35 kiyohara Exp $ */
+/* $NetBSD: com.c,v 1.313 2013/09/01 04:51:24 kiyohara 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.312 2013/07/27 06:54:35 kiyohara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.313 2013/09/01 04:51:24 kiyohara Exp $");
 
 #include "opt_com.h"
 #include "opt_ddb.h"
@@ -246,17 +246,7 @@ void	com_kgdb_putc(void *, int);
 #define	COM_REG_16550	{ \
 	com_data, com_data, com_dlbl, com_dlbh, com_ier, com_iir, com_fifo, \
 	com_efr, com_lcr, com_mcr, com_lsr, com_msr }
-/* 16750-specific register set, additional UART status register */
-#define	COM_REG_16750	{ \
-	com_data, com_data, com_dlbl, com_dlbh, com_ier, com_iir, com_fifo, \
-	com_efr, com_lcr, com_mcr, com_lsr, com_msr, 0, 0, 0, 0, 0, 0, 0, 0, \
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, com_usr }
-
-#ifdef COM_16750
-const bus_size_t com_std_map[32] = COM_REG_16750;
-#else
 const bus_size_t com_std_map[16] = COM_REG_16550;
-#endif /* COM_16750 */
 #endif /* COM_REGMAP */
 
 #define	COMUNIT_MASK	0x7ffff
@@ -416,10 +406,7 @@ com_attach_subr(struct com_softc *sc)
 			    (u_long)comcons_info.regs.cr_iobase);
 		}
 
-#ifdef COM_16750
-		/* Use in comintr(). */
 		sc->sc_lcr = cflag2lcr(comcons_info.cflag);
-#endif
 
 		/* Make sure the console is always "hardwired". */
 		delay(10000);			/* wait for output to finish */
@@ -1479,19 +1466,19 @@ com_iflush(struct com_softc *sc)
 		aprint_error_dev(sc->sc_dev, "com_iflush timeout %02x\n", reg);
 #endif
 
-#ifdef COM_16750
-	uint8_t fifo;
-	/*
-	 * Reset all Rx/Tx FIFO, preserve current FIFO length.
-	 * This should prevent triggering busy interrupt while
-	 * manipulating divisors.
-	 */
-	fifo = CSR_READ_1(regsp, COM_REG_FIFO) & (FIFO_TRIGGER_1 |
-	    FIFO_TRIGGER_4 | FIFO_TRIGGER_8 | FIFO_TRIGGER_14);
-	CSR_WRITE_1(regsp, COM_REG_FIFO, fifo | FIFO_ENABLE | FIFO_RCV_RST |
-	    FIFO_XMT_RST);
-	delay(100);
-#endif
+	if (sc->sc_type == COM_TYPE_ARMADAXP) {
+		uint8_t fifo;
+		/*
+		 * Reset all Rx/Tx FIFO, preserve current FIFO length.
+		 * This should prevent triggering busy interrupt while
+		 * manipulating divisors.
+		 */
+		fifo = CSR_READ_1(regsp, COM_REG_FIFO) & (FIFO_TRIGGER_1 |
+		    FIFO_TRIGGER_4 | FIFO_TRIGGER_8 | FIFO_TRIGGER_14);
+		CSR_WRITE_1(regsp, COM_REG_FIFO,
+		    fifo | FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST);
+		delay(100);
+	}
 }
 
 void
@@ -1919,26 +1906,6 @@ comintr(void *arg)
 	mutex_spin_enter(&sc->sc_lock);
 	iir = CSR_READ_1(regsp, COM_REG_IIR);
 
-	/* Handle ns16750-specific busy interrupt. */
-#ifdef COM_16750
-	int timeout;
-	if ((iir & IIR_BUSY) == IIR_BUSY) {
-		for (timeout = 10000;
-		    (CSR_READ_1(regsp, COM_REG_USR) & 0x1) != 0; timeout--)
-			if (timeout <= 0) {
-				aprint_error_dev(sc->sc_dev,
-				    "timeout while waiting for BUSY interrupt "
-				    "acknowledge\n");
-				mutex_spin_exit(&sc->sc_lock);
-				return (0);
-			}
-
-		CSR_WRITE_1(regsp, COM_REG_LCR, sc->sc_lcr);
-		iir = CSR_READ_1(regsp, COM_REG_IIR);
-	}
-#endif /* COM_16750 */
-
-
 	if (ISSET(iir, IIR_NOPEND)) {
 		mutex_spin_exit(&sc->sc_lock);
 		return (0);

Index: src/sys/dev/ic/comreg.h
diff -u src/sys/dev/ic/comreg.h:1.18 src/sys/dev/ic/comreg.h:1.19
--- src/sys/dev/ic/comreg.h:1.18	Sat Apr 20 11:52:41 2013
+++ src/sys/dev/ic/comreg.h	Sun Sep  1 04:51:24 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: comreg.h,v 1.18 2013/04/20 11:52:41 rkujawa Exp $	*/
+/*	$NetBSD: comreg.h,v 1.19 2013/09/01 04:51:24 kiyohara Exp $	*/
 
 /*-
  * Copyright (c) 1991 The Regents of the University of California.
@@ -56,15 +56,14 @@
 /* interrupt identification register */
 #define	IIR_IMASK	0xf
 #define	IIR_RXTOUT	0xc
+/* ARMADAXP's ns16550 ports have extra value in this register */
+#define IIR_BUSY	0x7	/* Busy indicator */
 #define	IIR_RLS		0x6	/* Line status change */
 #define	IIR_RXRDY	0x4	/* Receiver ready */
 #define	IIR_TXRDY	0x2	/* Transmitter ready */
 #define	IIR_MLSC	0x0	/* Modem status */
 #define	IIR_NOPEND	0x1	/* No pending interrupts */
 #define	IIR_FIFO_MASK	0xc0	/* set if FIFOs are enabled */
-#ifdef COM_16750
-#define IIR_BUSY	0x7	/* Busy indicator */
-#endif
 
 /* fifo control register */
 #define	FIFO_ENABLE	0x01	/* Turn the FIFO on */

Index: src/sys/dev/ic/comvar.h
diff -u src/sys/dev/ic/comvar.h:1.75 src/sys/dev/ic/comvar.h:1.76
--- src/sys/dev/ic/comvar.h:1.75	Wed Jul 17 19:51:56 2013
+++ src/sys/dev/ic/comvar.h	Sun Sep  1 04:51:24 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: comvar.h,v 1.75 2013/07/17 19:51:56 soren Exp $	*/
+/*	$NetBSD: comvar.h,v 1.76 2013/09/01 04:51:24 kiyohara Exp $	*/
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -91,27 +91,16 @@ int com_is_console(bus_space_tag_t, bus_
 #define	COM_REG_MCR		9
 #define	COM_REG_LSR		10
 #define	COM_REG_MSR		11
-#ifdef	COM_16750
-#define	COM_REG_USR		31
-#endif
 
 struct com_regs {
 	bus_space_tag_t		cr_iot;
 	bus_space_handle_t	cr_ioh;
 	bus_addr_t		cr_iobase;
 	bus_size_t		cr_nports;
-#ifdef COM_16750
-	bus_size_t		cr_map[32];
-#else
 	bus_size_t		cr_map[16];
-#endif
 };
 
-#ifdef COM_16750
-extern const bus_size_t com_std_map[32];
-#else
 extern const bus_size_t com_std_map[16];
-#endif
 
 #define	COM_INIT_REGS(regs, tag, hdl, addr)				\
 	do {								\
@@ -138,9 +127,6 @@ extern const bus_size_t com_std_map[16];
 #define	COM_REG_TCR		com_msr
 #define	COM_REG_TLR		com_scratch
 #define	COM_REG_MDR1		8
-#ifdef	COM_16750
-#define COM_REG_USR		com_usr
-#endif
 
 struct com_regs {
 	bus_space_tag_t		cr_iot;
@@ -233,6 +219,7 @@ struct com_softc {
 #define	COM_TYPE_AU1x00		3	/* AMD/Alchemy Au1x000 proc. built-in */
 #define	COM_TYPE_OMAP		4	/* TI OMAP processor built-in */
 #define	COM_TYPE_16550_NOERS	5	/* like a 16550, no ERS */
+#define	COM_TYPE_ARMADAXP	6	/* Marvell ARMADA XP proc. built-in */
 
 	/* power management hooks */
 	int (*enable)(struct com_softc *);

Index: src/sys/dev/ic/ns16550reg.h
diff -u src/sys/dev/ic/ns16550reg.h:1.8 src/sys/dev/ic/ns16550reg.h:1.9
--- src/sys/dev/ic/ns16550reg.h:1.8	Sat Apr 20 11:52:41 2013
+++ src/sys/dev/ic/ns16550reg.h	Sun Sep  1 04:51:24 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ns16550reg.h,v 1.8 2013/04/20 11:52:41 rkujawa Exp $	*/
+/*	$NetBSD: ns16550reg.h,v 1.9 2013/09/01 04:51:24 kiyohara Exp $	*/
 
 /*-
  * Copyright (c) 1991 The Regents of the University of California.
@@ -47,11 +47,3 @@
 #define	com_lsr		5	/* line status register (R/W) */
 #define	com_msr		6	/* modem status register (R/W) */
 #define	com_scratch	7	/* scratch register (R/W) */
-
-/*
- * Additional register present in NS16750 
- */
-#ifdef COM_16750
-#define com_usr		31	/* status register (R) */
-#endif
-

Index: src/sys/dev/marvell/com_mv.c
diff -u src/sys/dev/marvell/com_mv.c:1.5 src/sys/dev/marvell/com_mv.c:1.6
--- src/sys/dev/marvell/com_mv.c:1.5	Fri Jan 28 16:12:22 2011
+++ src/sys/dev/marvell/com_mv.c	Sun Sep  1 04:51:24 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: com_mv.c,v 1.5 2011/01/28 16:12:22 jakllsch Exp $	*/
+/*	$NetBSD: com_mv.c,v 1.6 2013/09/01 04:51:24 kiyohara Exp $	*/
 /*
  * Copyright (c) 2007, 2010 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: com_mv.c,v 1.5 2011/01/28 16:12:22 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com_mv.c,v 1.6 2013/09/01 04:51:24 kiyohara Exp $");
 
 #include "opt_com.h"
 
@@ -34,6 +34,7 @@ __KERNEL_RCSID(0, "$NetBSD: com_mv.c,v 1
 #include <sys/bus.h>
 #include <sys/device.h>
 #include <sys/errno.h>
+#include <sys/mutex.h>
 #include <sys/termios.h>
 
 #include <dev/marvell/gtvar.h>
@@ -44,34 +45,56 @@ __KERNEL_RCSID(0, "$NetBSD: com_mv.c,v 1
 
 #include <prop/proplib.h>
 
-#define MVUART_SIZE		0x20
+#define MVUART_SIZE		0x80
+
+#define MVUART_REG_USR		0x7c	/* XXXX: What is this??? */
 
 
 static int mvuart_match(device_t, struct cfdata *, void *);
 static void mvuart_attach(device_t, device_t, void *);
 
+static int mvuart_intr(void *);
+
 CFATTACH_DECL_NEW(mvuart_gt, sizeof(struct com_softc),
     mvuart_match, mvuart_attach, NULL, NULL);
 CFATTACH_DECL_NEW(mvuart_mbus, sizeof(struct com_softc),
     mvuart_match, mvuart_attach, NULL, NULL);
 
 #ifdef COM_REGMAP
-#define MVUART_INIT_REGS(regs, tag, hdl, addr, size)		\
-	do {							\
-		int i;						\
-								\
-		regs.cr_iot = tag;				\
-		regs.cr_ioh = hdl;				\
-		regs.cr_iobase = addr;				\
-		regs.cr_nports = size;				\
-		for (i = 0; i < __arraycount(regs.cr_map); i++)	\
-			regs.cr_map[i] = com_std_map[i] << 2;	\
+#define MVUART_INIT_REGS(regs, tag, hdl, addr, size)			\
+	do {								\
+		int _i;							\
+									\
+		regs.cr_iot = tag;					\
+		regs.cr_ioh = hdl;					\
+		regs.cr_iobase = addr;					\
+		regs.cr_nports = size;					\
+		for (_i = 0; _i < __arraycount(regs.cr_map); _i++)	\
+			regs.cr_map[_i] = com_std_map[_i] << 2;		\
 	} while (0)
+#define CSR_WRITE_1(r, o, v)    \
+	bus_space_write_1((r)->cr_iot, (r)->cr_ioh, (r)->cr_map[o], v)
+#define CSR_READ_1(r, o)        \
+	bus_space_read_1((r)->cr_iot, (r)->cr_ioh, (r)->cr_map[o])
 #else
 #define MVUART_INIT_REGS(regs, tag, hdl, addr, size) \
 	COM_INIT_REGS(regs, tag, hdl, addr)
+#define CSR_WRITE_1(r, o, v)    \
+        bus_space_write_1((r)->cr_iot, (r)->cr_ioh, o, v)
+#define CSR_READ_1(r, o)        \
+	bus_space_read_1((r)->cr_iot, (r)->cr_ioh, o)
 #endif
 
+struct {
+	int model;
+	int type;
+} mvuart_extensions[] = {
+	{ MARVELL_ARMADAXP_MV78130,	COM_TYPE_ARMADAXP },
+	{ MARVELL_ARMADAXP_MV78160,	COM_TYPE_ARMADAXP },
+	{ MARVELL_ARMADAXP_MV78230,	COM_TYPE_ARMADAXP },
+	{ MARVELL_ARMADAXP_MV78260,	COM_TYPE_ARMADAXP },
+	{ MARVELL_ARMADAXP_MV78460,	COM_TYPE_ARMADAXP },
+};
 
 /* ARGSUSED */
 static int
@@ -111,6 +134,7 @@ mvuart_attach(device_t parent, device_t 
 	bus_space_tag_t iot;
 	bus_space_handle_t ioh;
 	prop_dictionary_t dict = device_properties(self);
+	int i;
 
 	sc->sc_dev = self;
 
@@ -130,9 +154,59 @@ mvuart_attach(device_t parent, device_t 
 	MVUART_INIT_REGS(sc->sc_regs,
 	    iot, ioh, mva->mva_addr + mva->mva_offset, mva->mva_size);
 
+	for (i = 0; i < __arraycount(mvuart_extensions); i++)
+		if (mva->mva_model == mvuart_extensions[i].model) {
+			sc->sc_type = mvuart_extensions[i].type;
+			break;
+		}
+
 	com_attach_subr(sc);
 
-	marvell_intr_establish(mva->mva_irq, IPL_SERIAL, comintr, sc);
+	if (sc->sc_type == COM_TYPE_ARMADAXP)
+		marvell_intr_establish(mva->mva_irq, IPL_SERIAL,
+		    mvuart_intr, sc);
+	else
+		marvell_intr_establish(mva->mva_irq, IPL_SERIAL, comintr, sc);
+}
+
+static int
+mvuart_intr(void *arg)
+{
+	struct com_softc *sc = arg;
+	struct com_regs *regsp = &sc->sc_regs;
+	int timeout;
+	uint8_t iir, v;
+
+	if (!device_is_active(sc->sc_dev))
+		return 0;
+
+	KASSERT(regsp != NULL);
+
+	mutex_spin_enter(&sc->sc_lock);
+	iir = CSR_READ_1(regsp, COM_REG_IIR);
+	if ((iir & IIR_BUSY) == IIR_BUSY) {
+		/*
+		 * XXXXX: What is this?  I don't found in Marvell datasheet.
+		 *        Maybe workaround for BUG in UART.
+		 */
+		v = bus_space_read_1(regsp->cr_iot, regsp->cr_ioh,
+		    MVUART_REG_USR);
+		for (timeout = 10000; (v & 0x1) != 0; timeout--) {
+			if (timeout <= 0) {
+				aprint_error_dev(sc->sc_dev,
+				    "timeout while waiting for BUSY interrupt "
+				    "acknowledge\n");
+				mutex_spin_exit(&sc->sc_lock);
+				return 0;
+			}
+			v = bus_space_read_1(regsp->cr_iot, regsp->cr_ioh,
+			    MVUART_REG_USR);
+		}
+		CSR_WRITE_1(regsp, COM_REG_LCR, sc->sc_lcr);
+	}
+	mutex_spin_exit(&sc->sc_lock);
+
+	return comintr(arg);
 }
 
 #ifdef COM_REGMAP

Reply via email to