Module Name: src Committed By: thorpej Date: Fri Jan 11 23:10:41 UTC 2019
Modified Files: src/sys/arch/mips/alchemy/dev: com_aubus.c src/sys/arch/mips/ralink: ralink_com.c src/sys/dev/ic: com.c comvar.h ns16550reg.h Log Message: Simplify regmap initialization, and fix an regmap issue that affected TI OMAP (LCR register would get clobbered due to using the wrong offset for the MDR1 register) reported by Lwazi Dube (who also found the root cause). To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/sys/arch/mips/alchemy/dev/com_aubus.c cvs rdiff -u -r1.7 -r1.8 src/sys/arch/mips/ralink/ralink_com.c cvs rdiff -u -r1.354 -r1.355 src/sys/dev/ic/com.c cvs rdiff -u -r1.91 -r1.92 src/sys/dev/ic/comvar.h cvs rdiff -u -r1.12 -r1.13 src/sys/dev/ic/ns16550reg.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/arch/mips/alchemy/dev/com_aubus.c diff -u src/sys/arch/mips/alchemy/dev/com_aubus.c:1.8 src/sys/arch/mips/alchemy/dev/com_aubus.c:1.9 --- src/sys/arch/mips/alchemy/dev/com_aubus.c:1.8 Sat Dec 8 21:14:36 2018 +++ src/sys/arch/mips/alchemy/dev/com_aubus.c Fri Jan 11 23:10:40 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: com_aubus.c,v 1.8 2018/12/08 21:14:36 thorpej Exp $ */ +/* $NetBSD: com_aubus.c,v 1.9 2019/01/11 23:10:40 thorpej Exp $ */ /* * Copyright 2001 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: com_aubus.c,v 1.8 2018/12/08 21:14:36 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: com_aubus.c,v 1.9 2019/01/11 23:10:40 thorpej Exp $"); #include <sys/param.h> #include <sys/device.h> @@ -172,6 +172,21 @@ com_aubus_disable(struct com_softc *sc) AUCOM_MODCTL, 0); } +static const bus_size_t com_aubus_regmap[COM_REGMAP_NENTRIES] = { + [COM_REG_RXDATA] = AUCOM_RXDATA, + [COM_REG_TXDATA] = AUCOM_TXDATA, + [COM_REG_DLBL] = AUCOM_DLB, + [COM_REG_DLBH] = AUCOM_DLB, + [COM_REG_IER] = AUCOM_IER, + [COM_REG_IIR] = AUCOM_IIR, + [COM_REG_FIFO] = AUCOM_FIFO, + [COM_REG_TCR] = AUCOM_FIFO, + [COM_REG_LCR] = AUCOM_LCTL, + [COM_REG_MCR] = AUCOM_MCR, + [COM_REG_LSR] = AUCOM_LSR, + [COM_REG_MSR] = AUCOM_MSR, +}; + void com_aubus_init_regs(struct com_regs *regsp, bus_space_tag_t bst, bus_space_handle_t bsh, bus_addr_t addr) @@ -179,19 +194,8 @@ com_aubus_init_regs(struct com_regs *reg com_init_regs(regsp, bst, bsh, addr); + memcpy(regsp->cr_map, com_aubus_regmap, sizeof(regsp->cr_map)); regsp->cr_nports = AUCOM_NPORTS; - regsp->cr_map[COM_REG_RXDATA] = AUCOM_RXDATA; - regsp->cr_map[COM_REG_TXDATA] = AUCOM_TXDATA; - regsp->cr_map[COM_REG_DLBL] = AUCOM_DLB; - regsp->cr_map[COM_REG_DLBH] = AUCOM_DLB; - regsp->cr_map[COM_REG_IER] = AUCOM_IER; - regsp->cr_map[COM_REG_IIR] = AUCOM_IIR; - regsp->cr_map[COM_REG_FIFO] = AUCOM_FIFO; - regsp->cr_map[COM_REG_EFR] = 0; - regsp->cr_map[COM_REG_LCR] = AUCOM_LCTL; - regsp->cr_map[COM_REG_MCR] = AUCOM_MCR; - regsp->cr_map[COM_REG_LSR] = AUCOM_LSR; - regsp->cr_map[COM_REG_MSR] = AUCOM_MSR; } int Index: src/sys/arch/mips/ralink/ralink_com.c diff -u src/sys/arch/mips/ralink/ralink_com.c:1.7 src/sys/arch/mips/ralink/ralink_com.c:1.8 --- src/sys/arch/mips/ralink/ralink_com.c:1.7 Sat Dec 8 21:14:36 2018 +++ src/sys/arch/mips/ralink/ralink_com.c Fri Jan 11 23:10:40 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: ralink_com.c,v 1.7 2018/12/08 21:14:36 thorpej Exp $ */ +/* $NetBSD: ralink_com.c,v 1.8 2019/01/11 23:10:40 thorpej Exp $ */ /*- * Copyright (c) 2011 CradlePoint Technology, Inc. * All rights reserved. @@ -130,7 +130,7 @@ /* ralink_com.c -- Ralink 3052 uart console driver */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ralink_com.c,v 1.7 2018/12/08 21:14:36 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ralink_com.c,v 1.8 2019/01/11 23:10:40 thorpej Exp $"); #include "locators.h" #include <sys/param.h> @@ -367,6 +367,23 @@ ralink_com_attach(device_t parent, devic com_attach_subr(sc); } +static const bus_size_t ralink_com_regmap[] = { + [COM_REG_RXDATA] = RA_UART_RBR, + [COM_REG_TXDATA] = RA_UART_TBR, + [COM_REG_DLBL] = RA_UART_DLL, +#if defined(MT7628) + [COM_REG_DLBH] = RA_UART_DLM, +#endif + [COM_REG_IER] = RA_UART_IER, + [COM_REG_IIR] = RA_UART_IIR, + [COM_REG_FIFO] = RA_UART_FCR, + [COM_REG_TCR] = RA_UART_FCR, + [COM_REG_LCR] = RA_UART_LCR, + [COM_REG_MCR] = RA_UART_MCR, + [COM_REG_LSR] = RA_UART_LSR, + [COM_REG_MSR] = RA_UART_MSR, +}; + static void ralink_com_init_regs(struct com_regs *regsp, bus_space_tag_t st, bus_space_handle_t sh, bus_addr_t addr) @@ -374,20 +391,7 @@ ralink_com_init_regs(struct com_regs *re com_init_regs(regsp, st, sh, addr); - regsp->cr_map[COM_REG_RXDATA] = RA_UART_RBR; - regsp->cr_map[COM_REG_TXDATA] = RA_UART_TBR; - regsp->cr_map[COM_REG_DLBL] = RA_UART_DLL; -#if defined(MT7628) - regsp->cr_map[COM_REG_DLBH] = RA_UART_DLM; -#endif - regsp->cr_map[COM_REG_IER] = RA_UART_IER; - regsp->cr_map[COM_REG_IIR] = RA_UART_IIR; - regsp->cr_map[COM_REG_FIFO] = RA_UART_FCR; - regsp->cr_map[COM_REG_LCR] = RA_UART_LCR; - regsp->cr_map[COM_REG_MCR] = RA_UART_MCR; - regsp->cr_map[COM_REG_LSR] = RA_UART_LSR; - regsp->cr_map[COM_REG_MSR] = RA_UART_MSR; - + memcpy(regsp->cr_map, ralink_com_regmap, sizeof(regsp->cr_map)); regsp->cr_nports = 32; } Index: src/sys/dev/ic/com.c diff -u src/sys/dev/ic/com.c:1.354 src/sys/dev/ic/com.c:1.355 --- src/sys/dev/ic/com.c:1.354 Tue Dec 11 06:34:00 2018 +++ src/sys/dev/ic/com.c Fri Jan 11 23:10:40 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: com.c,v 1.354 2018/12/11 06:34:00 thorpej Exp $ */ +/* $NetBSD: com.c,v 1.355 2019/01/11 23:10:40 thorpej 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.354 2018/12/11 06:34:00 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.355 2019/01/11 23:10:40 thorpej Exp $"); #include "opt_com.h" #include "opt_ddb.h" @@ -236,13 +236,27 @@ void com_kgdb_putc(void *, int); #endif /* KGDB */ /* initializer for typical 16550-ish hardware */ -#define COM_REG_STD { \ - 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, com_tfl, com_rfl, \ - 0, 0, 0, 0, 0, 0, 0, com_halt } - -static const bus_size_t com_std_map[42] = COM_REG_STD; +static const bus_size_t com_std_map[COM_REGMAP_NENTRIES] = { + [COM_REG_RXDATA] = com_data, + [COM_REG_TXDATA] = com_data, + [COM_REG_DLBL] = com_dlbl, + [COM_REG_DLBH] = com_dlbh, + [COM_REG_IER] = com_ier, + [COM_REG_IIR] = com_iir, + [COM_REG_FIFO] = com_fifo, + [COM_REG_TCR] = com_fifo, + [COM_REG_EFR] = com_efr, + [COM_REG_TLR] = com_efr, + [COM_REG_LCR] = com_lcr, + [COM_REG_MCR] = com_mcr, + [COM_REG_LSR] = com_lsr, + [COM_REG_MSR] = com_msr, + [COM_REG_USR] = com_usr, + [COM_REG_TFL] = com_tfl, + [COM_REG_RFL] = com_rfl, + [COM_REG_HALT] = com_halt, + [COM_REG_MDR1] = com_mdr1, +}; #define COMDIALOUT_MASK TTDIALOUT_MASK Index: src/sys/dev/ic/comvar.h diff -u src/sys/dev/ic/comvar.h:1.91 src/sys/dev/ic/comvar.h:1.92 --- src/sys/dev/ic/comvar.h:1.91 Tue Dec 11 06:34:00 2018 +++ src/sys/dev/ic/comvar.h Fri Jan 11 23:10:41 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: comvar.h,v 1.91 2018/12/11 06:34:00 thorpej Exp $ */ +/* $NetBSD: comvar.h,v 1.92 2019/01/11 23:10:41 thorpej Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. @@ -83,25 +83,27 @@ int com_is_console(bus_space_tag_t, bus_ #define COM_REG_IER 4 #define COM_REG_IIR 5 #define COM_REG_FIFO 6 -#define COM_REG_TCR 6 -#define COM_REG_EFR 7 -#define COM_REG_TLR 7 -#define COM_REG_LCR 8 -#define COM_REG_MDR1 8 -#define COM_REG_MCR 9 -#define COM_REG_LSR 10 -#define COM_REG_MSR 11 -#define COM_REG_USR 31 /* 16750/DW APB */ -#define COM_REG_TFL com_tfl /* DW APB */ -#define COM_REG_RFL com_rfl /* DW APB */ -#define COM_REG_HALT com_halt /* DW APB */ +#define COM_REG_TCR 7 +#define COM_REG_EFR 8 +#define COM_REG_TLR 9 +#define COM_REG_LCR 10 +#define COM_REG_MCR 11 +#define COM_REG_LSR 12 +#define COM_REG_MSR 13 +#define COM_REG_MDR1 14 /* TI OMAP */ +#define COM_REG_USR 15 /* 16750/DW APB */ +#define COM_REG_TFL 16 /* DW APB */ +#define COM_REG_RFL 17 /* DW APB */ +#define COM_REG_HALT 18 /* DW APB */ + +#define COM_REGMAP_NENTRIES 19 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; - bus_size_t cr_map[42]; + bus_size_t cr_map[COM_REGMAP_NENTRIES]; }; void com_init_regs(struct com_regs *, bus_space_tag_t, bus_space_handle_t, Index: src/sys/dev/ic/ns16550reg.h diff -u src/sys/dev/ic/ns16550reg.h:1.12 src/sys/dev/ic/ns16550reg.h:1.13 --- src/sys/dev/ic/ns16550reg.h:1.12 Sun Oct 29 14:06:08 2017 +++ src/sys/dev/ic/ns16550reg.h Fri Jan 11 23:10:41 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: ns16550reg.h,v 1.12 2017/10/29 14:06:08 jmcneill Exp $ */ +/* $NetBSD: ns16550reg.h,v 1.13 2019/01/11 23:10:41 thorpej Exp $ */ /*- * Copyright (c) 1991 The Regents of the University of California. @@ -43,12 +43,18 @@ #define com_fifo 2 /* FIFO control (W) */ #define com_lctl 3 /* line control register (R/W) */ #define com_cfcr 3 /* line control register (R/W) */ +#define com_lcr com_cfcr #define com_mcr 4 /* modem control register (R/W) */ #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 registers present on TI OMAP hardware + */ +#define com_mdr1 8 /* mode definition register 1 (OMAP) */ + +/* * Additional register present in NS16750 */ #define com_usr 31 /* status register (R) (16750/SUNXI) */