While everyone is looking at com(4)...

Some systems use reserved (and sometimes not) bits of the MCR register
for extra features. In particular, on some systems, clearing the DCS bit
in the MCR is not a good idea (kudos if you can guess what historical
machine I am thinking of).

It makes sense for com(4) to know better what bits to set in the MCR.

What about the following diff?

Index: sys/arch/arm/xscale/pxa2x0_com.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/arm/xscale/pxa2x0_com.c,v
retrieving revision 1.12
diff -u -p -r1.12 pxa2x0_com.c
--- sys/arch/arm/xscale/pxa2x0_com.c    7 Sep 2010 16:21:35 -0000       1.12
+++ sys/arch/arm/xscale/pxa2x0_com.c    18 Aug 2016 09:59:56 -0000
@@ -129,6 +129,7 @@ pxauart_attach(struct device *parent, st
        sc->sc_iobase = pxa->pxa_addr;
        sc->sc_frequency = PXA2X0_COM_FREQ;
        sc->sc_uarttype = COM_UART_PXA2X0;
+       sc->sc_mcr_out = MCR_IENABLE;
 
 #if 0
        if (com_is_console(sc->sc_iot, sc->sc_iobase, &sc->sc_ioh) == 0 &&
Index: sys/arch/armv7/broadcom/bcm2835_muart.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/armv7/broadcom/bcm2835_muart.c,v
retrieving revision 1.1
diff -u -p -r1.1 bcm2835_muart.c
--- sys/arch/armv7/broadcom/bcm2835_muart.c     7 Aug 2016 17:46:36 -0000       
1.1
+++ sys/arch/armv7/broadcom/bcm2835_muart.c     18 Aug 2016 09:59:56 -0000
@@ -68,6 +68,7 @@ bcmmuart_attach(struct device *parent, s
 
        sc->sc_frequency = 500000000;
        sc->sc_uarttype = COM_UART_16550;
+       sc->sc_mcr_out = MCR_IENABLE;
 
        if (faa->fa_reg[0].addr == comconsaddr + 0x3f000000) {
                sc->sc_iobase = comconsaddr;
Index: sys/arch/armv7/dev/com_fdt.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/armv7/dev/com_fdt.c,v
retrieving revision 1.6
diff -u -p -r1.6 com_fdt.c
--- sys/arch/armv7/dev/com_fdt.c        17 Aug 2016 13:44:48 -0000      1.6
+++ sys/arch/armv7/dev/com_fdt.c        18 Aug 2016 09:59:56 -0000
@@ -114,6 +114,7 @@ com_fdt_attach(struct device *parent, st
        sc->sc.sc_iobase = faa->fa_reg[0].addr;
        sc->sc.sc_frequency = 48000000;
        sc->sc.sc_uarttype = COM_UART_TI16750;
+       sc->sc_mcr_out = MCR_IENABLE;
 
        if (OF_is_compatible(faa->fa_node, "snps,dw-apb-uart")) {
                sc->sc.sc_uarttype = COM_UART_16550;
Index: sys/arch/hppa/dev/com_dino.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/hppa/dev/com_dino.c,v
retrieving revision 1.4
diff -u -p -r1.4 com_dino.c
--- sys/arch/hppa/dev/com_dino.c        15 Jul 2007 19:25:49 -0000      1.4
+++ sys/arch/hppa/dev/com_dino.c        18 Aug 2016 09:59:56 -0000
@@ -108,6 +108,7 @@ com_dino_attach(parent, self, aux)
        /* select clock freq */
        regs->test = COM_DINO_CLK_SEL;
        sc->sc_frequency = COM_DINO_FREQ;
+       sc->sc_mcr_out = MCR_IENABLE;
 
        com_attach_subr(sc);
 
Index: sys/arch/hppa/dev/com_ssio.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/hppa/dev/com_ssio.c,v
retrieving revision 1.2
diff -u -p -r1.2 com_ssio.c
--- sys/arch/hppa/dev/com_ssio.c        24 Jun 2007 16:28:39 -0000      1.2
+++ sys/arch/hppa/dev/com_ssio.c        18 Aug 2016 09:59:56 -0000
@@ -76,6 +76,7 @@ com_ssio_attach(struct device *parent, s
        }
 
        sc->sc_frequency = COM_SSIO_FREQ;
+       sc->sc_mcr_out = MCR_IENABLE;
        com_attach_subr(sc);
 
        sc->sc_ih = ssio_intr_establish(IPL_TTY, saa->saa_irq,
Index: sys/arch/hppa/gsc/com_gsc.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/hppa/gsc/com_gsc.c,v
retrieving revision 1.21
diff -u -p -r1.21 com_gsc.c
--- sys/arch/hppa/gsc/com_gsc.c 15 Jul 2007 19:25:49 -0000      1.21
+++ sys/arch/hppa/gsc/com_gsc.c 18 Aug 2016 09:59:56 -0000
@@ -99,6 +99,7 @@ com_gsc_attach(parent, self, aux)
        }
 
        sc->sc_frequency = COM_GSC_FREQ;
+       sc->sc_mcr_out = MCR_IENABLE;
        com_attach_subr(sc);
 
        sc->sc_ih = gsc_intr_establish((struct gsc_softc *)parent,
Index: sys/arch/octeon/dev/cn30xxuart.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/octeon/dev/cn30xxuart.c,v
retrieving revision 1.9
diff -u -p -r1.9 cn30xxuart.c
--- sys/arch/octeon/dev/cn30xxuart.c    14 Apr 2016 13:51:58 -0000      1.9
+++ sys/arch/octeon/dev/cn30xxuart.c    18 Aug 2016 09:59:56 -0000
@@ -112,6 +112,7 @@ cn30xxuart_attach(struct device *parent,
        sc->sc_frequency = octeon_ioclock_speed();
        sc->sc_uarttype = COM_UART_16550A;
        sc->sc_fifolen = OCTEON_UART_FIFO_SIZE;
+       sc->sc_mcr_out = MCR_IENABLE;
 
        /* if it's in use as console, it's there. */
        if (bus_space_map(sc->sc_iot, sc->sc_iobase, COM_NPORTS, 0, 
&sc->sc_ioh)) {
Index: sys/arch/sgi/dev/com_ioc.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/sgi/dev/com_ioc.c,v
retrieving revision 1.9
diff -u -p -r1.9 com_ioc.c
--- sys/arch/sgi/dev/com_ioc.c  3 Oct 2012 22:46:09 -0000       1.9
+++ sys/arch/sgi/dev/com_ioc.c  18 Aug 2016 09:59:56 -0000
@@ -96,6 +96,7 @@ com_ioc_attach(struct device *parent, st
        sc->sc_hwflags = 0;
        sc->sc_swflags = 0;
        sc->sc_frequency = 22000000 / 3;
+       sc->sc_mcr_out = MCR_IENABLE;
 
        /* if it's in use as console, it's there. */
        if (!(console && !comconsattached)) {
Index: sys/arch/sgi/dev/com_iof.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/sgi/dev/com_iof.c,v
retrieving revision 1.5
diff -u -p -r1.5 com_iof.c
--- sys/arch/sgi/dev/com_iof.c  16 Oct 2009 00:15:46 -0000      1.5
+++ sys/arch/sgi/dev/com_iof.c  18 Aug 2016 09:59:56 -0000
@@ -93,6 +93,7 @@ com_iof_attach(struct device *parent, st
        sc->sc_hwflags = 0;
        sc->sc_swflags = 0;
        sc->sc_frequency = iaa->iaa_clock;
+       sc->sc_mcr_out = MCR_IENABLE;
 
        /* if it's in use as console, it's there. */
        if (!(console && !comconsattached)) {
Index: sys/arch/sgi/localbus/com_lbus.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/sgi/localbus/com_lbus.c,v
retrieving revision 1.12
diff -u -p -r1.12 com_lbus.c
--- sys/arch/sgi/localbus/com_lbus.c    3 Oct 2012 22:46:09 -0000       1.12
+++ sys/arch/sgi/localbus/com_lbus.c    18 Aug 2016 09:59:56 -0000
@@ -78,6 +78,7 @@ com_macebus_attach(struct device *parent
        sc->sc_swflags = 0;
        sc->sc_iobase = maa->maa_baseaddr;
        sc->sc_frequency = 1843200;
+       sc->sc_mcr_out = MCR_IENABLE;
 
        /* If it's in use as the console, then it's there. */
        if (maa->maa_baseaddr == comconsaddr && !comconsattached) {
Index: sys/arch/socppc/dev/com_obio.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/socppc/dev/com_obio.c,v
retrieving revision 1.3
diff -u -p -r1.3 com_obio.c
--- sys/arch/socppc/dev/com_obio.c      6 Sep 2009 20:09:34 -0000       1.3
+++ sys/arch/socppc/dev/com_obio.c      18 Aug 2016 09:59:56 -0000
@@ -72,6 +72,7 @@ com_obio_attach(struct device *parent, s
        sc->sc_iot = oa->oa_iot;
        sc->sc_iobase = oa->oa_offset;
        sc->sc_frequency = freq;
+       sc->sc_mcr_out = MCR_IENABLE;
 
        if (sc->sc_iobase != comconsaddr) {
                if (bus_space_map(sc->sc_iot, sc->sc_iobase,
Index: sys/arch/sparc/dev/com_obio.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/sparc/dev/com_obio.c,v
retrieving revision 1.1
diff -u -p -r1.1 com_obio.c
--- sys/arch/sparc/dev/com_obio.c       17 Jul 2005 12:22:42 -0000      1.1
+++ sys/arch/sparc/dev/com_obio.c       18 Aug 2016 09:59:56 -0000
@@ -102,6 +102,7 @@ com_obio_attach(struct device *parent, s
        sc->enabled = 1;
 
        sc->sc_frequency = COM_FREQ;
+       sc->sc_mcr_out = MCR_IENABLE;
        com_attach_subr(sc);
 }
 
Index: sys/arch/sparc64/dev/com_ebus.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/sparc64/dev/com_ebus.c,v
retrieving revision 1.21
diff -u -p -r1.21 com_ebus.c
--- sys/arch/sparc64/dev/com_ebus.c     28 Sep 2011 11:02:37 -0000      1.21
+++ sys/arch/sparc64/dev/com_ebus.c     18 Aug 2016 09:59:56 -0000
@@ -142,6 +142,7 @@ com_ebus_attach(struct device *parent, s
        sc->sc_hwflags = 0;
        sc->sc_swflags = 0;
        sc->sc_frequency = BAUD_BASE;
+       sc->sc_mcr_out = MCR_IENABLE;
 
        for (i = 0; i < ea->ea_nintrs; i++)
                bus_intr_establish(sc->sc_iot, ea->ea_intrs[i],
Index: sys/dev/cardbus/com_cardbus.c
===================================================================
RCS file: /OpenBSD/src/sys/dev/cardbus/com_cardbus.c,v
retrieving revision 1.43
diff -u -p -r1.43 com_cardbus.c
--- sys/dev/cardbus/com_cardbus.c       14 Nov 2015 14:47:56 -0000      1.43
+++ sys/dev/cardbus/com_cardbus.c       18 Aug 2016 09:59:56 -0000
@@ -280,6 +280,7 @@ com_cardbus_attach(struct device *parent
 
        sc->sc_hwflags = 0;
        sc->sc_swflags = 0;
+       sc->sc_mcr_out = MCR_IENABLE;
 
        if (csc->cc_bug & BUG_BROADCOM)
                sc->sc_fifolen = 15;
Index: sys/dev/ic/com.c
===================================================================
RCS file: /OpenBSD/src/sys/dev/ic/com.c,v
retrieving revision 1.159
diff -u -p -r1.159 com.c
--- sys/dev/ic/com.c    16 Aug 2016 08:15:04 -0000      1.159
+++ sys/dev/ic/com.c    18 Aug 2016 09:59:56 -0000
@@ -405,9 +405,7 @@ comopen(dev_t dev, int flag, int mode, s
                        (void) bus_space_read_1(iot, ioh, com_data);
 
                /* You turn me on, baby! */
-               sc->sc_mcr = MCR_DTR | MCR_RTS;
-               if (!ISSET(sc->sc_hwflags, COM_HW_NOIEN))
-                       SET(sc->sc_mcr, MCR_IENABLE);
+               sc->sc_mcr = MCR_DTR | MCR_RTS | sc->sc_mcr_out;
                bus_space_write_1(iot, ioh, com_mcr, sc->sc_mcr);
                sc->sc_ier = IER_ERXRDY | IER_ERLS | IER_EMSC;
 #ifdef COM_PXA2X0
@@ -536,7 +534,7 @@ compwroff(struct com_softc *sc)
        if (ISSET(tp->t_cflag, HUPCL) &&
            !ISSET(sc->sc_swflags, COM_SW_SOFTCAR)) {
                /* XXX perhaps only clear DTR */
-               sc->sc_mcr = 0;
+               sc->sc_mcr = sc->sc_mcr_out;
                bus_space_write_1(iot, ioh, com_mcr, sc->sc_mcr);
        }
 
@@ -1202,7 +1200,8 @@ kgdbintr(void *arg)
                        if (ISSET(delta, MSR_DCD)) {
                                if (!ISSET(sc->sc_swflags, COM_SW_SOFTCAR)) {
                                        CLR(sc->sc_mcr, sc->sc_dtr);
-                                       bus_space_write_1(iot, ioh, com_mcr, 
sc->sc_mcr);
+                                       bus_space_write_1(iot, ioh, com_mcr,
+                                           sc->sc_mcr);
                                }
                        }
                }
@@ -1260,8 +1259,8 @@ comintr(void *arg)
                                            ISSET(tp->t_cflag, CRTSCTS)) {
                                                /* XXX */
                                                CLR(sc->sc_mcr, MCR_RTS);
-                                               bus_space_write_1(iot, ioh, 
com_mcr,
-                                                   sc->sc_mcr);
+                                               bus_space_write_1(iot, ioh,
+                                                   com_mcr, sc->sc_mcr);
                                        }
                                }
 #if defined(COM_CONSOLE) && defined(DDB)
@@ -1285,7 +1284,8 @@ comintr(void *arg)
                                if (!ISSET(sc->sc_swflags, COM_SW_SOFTCAR) &&
                                    (*linesw[tp->t_line].l_modem)(tp, 
ISSET(msr, MSR_DCD)) == 0) {
                                        CLR(sc->sc_mcr, sc->sc_dtr);
-                                       bus_space_write_1(iot, ioh, com_mcr, 
sc->sc_mcr);
+                                       bus_space_write_1(iot, ioh, com_mcr,
+                                           sc->sc_mcr);
                                }
                        }
                        if (ISSET(delta & msr, MSR_CTS) &&
@@ -1571,7 +1571,7 @@ com_enable_debugport(struct com_softc *s
 #endif
        bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_ier, sc->sc_ier);
 #endif
-       SET(sc->sc_mcr, MCR_DTR | MCR_RTS | MCR_IENABLE);
+       SET(sc->sc_mcr, MCR_DTR | MCR_RTS | sc->sc_mcr_out);
        bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_mcr, sc->sc_mcr);
 
        splx(s);
Index: sys/dev/ic/comvar.h
===================================================================
RCS file: /OpenBSD/src/sys/dev/ic/comvar.h,v
retrieving revision 1.51
diff -u -p -r1.51 comvar.h
--- sys/dev/ic/comvar.h 12 May 2012 18:02:33 -0000      1.51
+++ sys/dev/ic/comvar.h 18 Aug 2016 09:59:56 -0000
@@ -104,7 +104,6 @@ struct com_softc {
 #define        COM_UART_OX16C950       0x12            /* 128 byte fifo */
 
        u_char sc_hwflags;
-#define        COM_HW_NOIEN    0x01
 #define        COM_HW_FIFO     0x02
 #define        COM_HW_SIR      0x20
 #define        COM_HW_CONSOLE  0x40
@@ -117,8 +116,10 @@ struct com_softc {
 #define        COM_SW_PPS      0x10
 #define        COM_SW_DEAD     0x20
        int     sc_fifolen;
-       u_char sc_msr, sc_mcr, sc_lcr, sc_ier;
-       u_char sc_dtr;
+       u_char  sc_msr, sc_mcr, sc_lcr, sc_ier;
+       u_char  sc_dtr;
+
+       u_char  sc_mcr_out;     /* value of OUT bits to be forced in mcr */
 
        u_char  sc_cua;
 
Index: sys/dev/isa/com_commulti.c
===================================================================
RCS file: /OpenBSD/src/sys/dev/isa/com_commulti.c,v
retrieving revision 1.4
diff -u -p -r1.4 com_commulti.c
--- sys/dev/isa/com_commulti.c  27 Apr 2008 09:25:26 -0000      1.4
+++ sys/dev/isa/com_commulti.c  18 Aug 2016 09:59:56 -0000
@@ -119,7 +119,9 @@ com_commulti_attach(struct device *paren
        sc->sc_iobase = ca->ca_iobase;
        sc->sc_frequency = COM_FREQ;
        if (ca->ca_noien)
-               SET(sc->sc_hwflags, COM_HW_NOIEN);
+               sc->sc_mcr_out = 0;
+       else
+               sc->sc_mcr_out = MCR_IENABLE;
 
        com_attach_subr(sc);
 }
Index: sys/dev/isa/com_isa.c
===================================================================
RCS file: /OpenBSD/src/sys/dev/isa/com_isa.c,v
retrieving revision 1.8
diff -u -p -r1.8 com_isa.c
--- sys/dev/isa/com_isa.c       14 Mar 2015 03:38:47 -0000      1.8
+++ sys/dev/isa/com_isa.c       18 Aug 2016 09:59:56 -0000
@@ -152,6 +152,7 @@ com_isa_attach(struct device *parent, st
        sc->sc_ioh = ioh;
        sc->sc_iobase = iobase;
        sc->sc_frequency = COM_FREQ;
+       sc->sc_mcr_out = MCR_IENABLE;
 
        com_attach_subr(sc);
 
Index: sys/dev/isa/com_isapnp.c
===================================================================
RCS file: /OpenBSD/src/sys/dev/isa/com_isapnp.c,v
retrieving revision 1.4
diff -u -p -r1.4 com_isapnp.c
--- sys/dev/isa/com_isapnp.c    27 Apr 2008 09:29:40 -0000      1.4
+++ sys/dev/isa/com_isapnp.c    18 Aug 2016 09:59:56 -0000
@@ -132,6 +132,7 @@ com_isapnp_attach(struct device *parent,
        sc->sc_ioh = ioh;
        sc->sc_iobase = iobase;
        sc->sc_frequency = COM_FREQ;
+       sc->sc_mcr_out = MCR_IENABLE;
 
        com_attach_subr(sc);
 
Index: sys/dev/pcmcia/com_pcmcia.c
===================================================================
RCS file: /OpenBSD/src/sys/dev/pcmcia/com_pcmcia.c,v
retrieving revision 1.55
diff -u -p -r1.55 com_pcmcia.c
--- sys/dev/pcmcia/com_pcmcia.c 14 Mar 2015 03:38:49 -0000      1.55
+++ sys/dev/pcmcia/com_pcmcia.c 18 Aug 2016 09:59:56 -0000
@@ -306,6 +306,7 @@ found:
 
        sc->sc_hwflags = 0;
        sc->sc_swflags = 0;
+       sc->sc_mcr_out = MCR_IENABLE;
 
        if (psc->sc_pf->sc->card.manufacturer == PCMCIA_VENDOR_AUDIOVOX &&
            psc->sc_pf->sc->card.product == PCMCIA_PRODUCT_AUDIOVOX_RTM8000)
Index: sys/dev/puc/com_puc.c
===================================================================
RCS file: /OpenBSD/src/sys/dev/puc/com_puc.c,v
retrieving revision 1.22
diff -u -p -r1.22 com_puc.c
--- sys/dev/puc/com_puc.c       14 Sep 2014 14:17:25 -0000      1.22
+++ sys/dev/puc/com_puc.c       18 Aug 2016 09:59:56 -0000
@@ -104,6 +104,7 @@ com_puc_attach(parent, self, aux)
                sc->sc_frequency = COM_FREQ * PUC_COM_GET_MUL(pa->type);
        else
                sc->sc_frequency = COM_FREQ * (1 << PUC_COM_GET_POW2(pa->type));
+       sc->sc_mcr_out = MCR_IENABLE;
 
        com_attach_subr(sc);
 }
Index: sys/dev/sbus/asio.c
===================================================================
RCS file: /OpenBSD/src/sys/dev/sbus/asio.c,v
retrieving revision 1.10
diff -u -p -r1.10 asio.c
--- sys/dev/sbus/asio.c 27 Jun 2003 01:50:52 -0000      1.10
+++ sys/dev/sbus/asio.c 18 Aug 2016 09:59:56 -0000
@@ -212,6 +212,7 @@ com_asio_attach(struct device *parent, s
        sc->sc_hwflags = 0;
        sc->sc_swflags = 0;
        sc->sc_frequency = BAUD_BASE;
+       sc->sc_mcr_out = MCR_IENABLE;
 
        sc->sc_ih = bus_intr_establish(aaa->aaa_iot, aaa->aaa_pri,
            IPL_TTY, 0, comintr, sc, self->dv_xname);

Reply via email to