Module Name: src Committed By: kiyohara Date: Thu Oct 3 13:23:03 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: Revirt 'Move the Marvell extension to com_mv.c' at Sun Sep 1 04:51:24 UTC 2013. build test only. To generate a diff of this commit: cvs rdiff -u -r1.316 -r1.317 src/sys/dev/ic/com.c cvs rdiff -u -r1.21 -r1.22 src/sys/dev/ic/comreg.h cvs rdiff -u -r1.77 -r1.78 src/sys/dev/ic/comvar.h cvs rdiff -u -r1.9 -r1.10 src/sys/dev/ic/ns16550reg.h cvs rdiff -u -r1.6 -r1.7 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.316 src/sys/dev/ic/com.c:1.317 --- src/sys/dev/ic/com.c:1.316 Thu Sep 12 12:54:39 2013 +++ src/sys/dev/ic/com.c Thu Oct 3 13:23:03 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: com.c,v 1.316 2013/09/12 12:54:39 martin Exp $ */ +/* $NetBSD: com.c,v 1.317 2013/10/03 13:23:03 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.316 2013/09/12 12:54:39 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.317 2013/10/03 13:23:03 kiyohara Exp $"); #include "opt_com.h" #include "opt_ddb.h" @@ -247,7 +247,17 @@ 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 @@ -405,7 +415,10 @@ com_attach_subr(struct com_softc *sc) (u_long)comcons_info.regs.cr_iobase); } - sc->sc_lcr = cflag2lcr(comcons_info.cflag); +#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 */ @@ -1511,19 +1524,19 @@ com_iflush(struct com_softc *sc) aprint_error_dev(sc->sc_dev, "com_iflush timeout %02x\n", reg); #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); - } +#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 } void @@ -1951,6 +1964,26 @@ 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.21 src/sys/dev/ic/comreg.h:1.22 --- src/sys/dev/ic/comreg.h:1.21 Tue Sep 3 15:32:55 2013 +++ src/sys/dev/ic/comreg.h Thu Oct 3 13:23:03 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: comreg.h,v 1.21 2013/09/03 15:32:55 jmcneill Exp $ */ +/* $NetBSD: comreg.h,v 1.22 2013/10/03 13:23:03 kiyohara Exp $ */ /*- * Copyright (c) 1991 The Regents of the University of California. @@ -56,8 +56,6 @@ /* 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 */ @@ -65,6 +63,9 @@ #define IIR_NOPEND 0x1 /* No pending interrupts */ #define IIR_64B_FIFO 0x20 /* 64byte FIFO Enabled (16750) */ #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.77 src/sys/dev/ic/comvar.h:1.78 --- src/sys/dev/ic/comvar.h:1.77 Tue Sep 3 15:32:55 2013 +++ src/sys/dev/ic/comvar.h Thu Oct 3 13:23:03 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: comvar.h,v 1.77 2013/09/03 15:32:55 jmcneill Exp $ */ +/* $NetBSD: comvar.h,v 1.78 2013/10/03 13:23:03 kiyohara Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. @@ -92,16 +92,27 @@ 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 { \ @@ -128,6 +139,9 @@ 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; @@ -220,13 +234,15 @@ 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 *); void (*disable)(struct com_softc *); int enabled; + /* XXXX: vendor workaround functions */ + int (*sc_vendor_workaround)(struct com_softc *); + struct pps_state sc_pps_state; /* pps state */ #ifdef RND_COM Index: src/sys/dev/ic/ns16550reg.h diff -u src/sys/dev/ic/ns16550reg.h:1.9 src/sys/dev/ic/ns16550reg.h:1.10 --- src/sys/dev/ic/ns16550reg.h:1.9 Sun Sep 1 04:51:24 2013 +++ src/sys/dev/ic/ns16550reg.h Thu Oct 3 13:23:03 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ns16550reg.h,v 1.9 2013/09/01 04:51:24 kiyohara Exp $ */ +/* $NetBSD: ns16550reg.h,v 1.10 2013/10/03 13:23:03 kiyohara Exp $ */ /*- * Copyright (c) 1991 The Regents of the University of California. @@ -47,3 +47,11 @@ #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.6 src/sys/dev/marvell/com_mv.c:1.7 --- src/sys/dev/marvell/com_mv.c:1.6 Sun Sep 1 04:51:24 2013 +++ src/sys/dev/marvell/com_mv.c Thu Oct 3 13:23:03 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: com_mv.c,v 1.6 2013/09/01 04:51:24 kiyohara Exp $ */ +/* $NetBSD: com_mv.c,v 1.7 2013/10/03 13:23:03 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.6 2013/09/01 04:51:24 kiyohara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: com_mv.c,v 1.7 2013/10/03 13:23:03 kiyohara Exp $"); #include "opt_com.h" @@ -34,7 +34,6 @@ __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> @@ -45,56 +44,34 @@ __KERNEL_RCSID(0, "$NetBSD: com_mv.c,v 1 #include <prop/proplib.h> -#define MVUART_SIZE 0x80 - -#define MVUART_REG_USR 0x7c /* XXXX: What is this??? */ +#define MVUART_SIZE 0x20 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 @@ -134,7 +111,6 @@ 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; @@ -154,59 +130,9 @@ 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); - 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); + marvell_intr_establish(mva->mva_irq, IPL_SERIAL, comintr, sc); } #ifdef COM_REGMAP