Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Add basic serial console support.
details: https://anonhg.NetBSD.org/src/rev/15b5ab906661
branches: trunk
changeset: 336378:15b5ab906661
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Fri Feb 27 17:35:08 2015 +0000
description:
Add basic serial console support.
diffstat:
sys/arch/arm/amlogic/amlogic_com.c | 159 ++++++++++++++++++++---------
sys/arch/arm/amlogic/amlogic_comreg.h | 4 +-
sys/arch/arm/amlogic/amlogic_comvar.h | 37 ++++++
sys/arch/arm/amlogic/files.amlogic | 7 +-
sys/arch/evbarm/amlogic/amlogic_machdep.c | 59 +++-------
sys/arch/evbarm/conf/ODROID-C1 | 6 +-
6 files changed, 176 insertions(+), 96 deletions(-)
diffs (truncated from 473 to 300 lines):
diff -r 932b721e6e50 -r 15b5ab906661 sys/arch/arm/amlogic/amlogic_com.c
--- a/sys/arch/arm/amlogic/amlogic_com.c Fri Feb 27 17:33:31 2015 +0000
+++ b/sys/arch/arm/amlogic/amlogic_com.c Fri Feb 27 17:35:08 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_com.c,v 1.1 2015/02/07 17:20:17 jmcneill Exp $ */
+/* $NetBSD: amlogic_com.c,v 1.2 2015/02/27 17:35:08 jmcneill Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: amlogic_com.c,v 1.1 2015/02/07 17:20:17 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: amlogic_com.c,v 1.2 2015/02/27 17:35:08 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -43,79 +43,142 @@
#include <sys/time.h>
#include <sys/termios.h>
+#include <dev/cons.h>
+
#include <arm/amlogic/amlogic_reg.h>
#include <arm/amlogic/amlogic_var.h>
-
-#include <dev/ic/comvar.h>
+#include <arm/amlogic/amlogic_comreg.h>
+#include <arm/amlogic/amlogic_comvar.h>
static int amlogic_com_match(device_t, cfdata_t, void *);
static void amlogic_com_attach(device_t, device_t, void *);
struct amlogic_com_softc {
- struct com_softc asc_sc;
- void *asc_ih;
+ device_t sc_dev;
+ bus_space_tag_t sc_bst;
+ bus_space_handle_t sc_bsh;
+
+ int sc_ospeed;
+ tcflag_t sc_cflag;
+};
+
+static struct amlogic_com_softc amlogic_com_cnsc;
+
+static struct cnm_state amlogic_com_cnm_state;
+
+static int amlogic_com_cngetc(dev_t);
+static void amlogic_com_cnputc(dev_t, int);
+static void amlogic_com_cnpollc(dev_t, int);
+
+struct consdev amlogic_com_consdev = {
+ .cn_getc = amlogic_com_cngetc,
+ .cn_putc = amlogic_com_cnputc,
+ .cn_pollc = amlogic_com_cnpollc,
};
CFATTACH_DECL_NEW(amlogic_com, sizeof(struct amlogic_com_softc),
amlogic_com_match, amlogic_com_attach, NULL, NULL);
-static int amlogic_com_ports;
-
static int
amlogic_com_match(device_t parent, cfdata_t cf, void *aux)
{
- struct amlogicio_attach_args * const aio = aux;
- const struct amlogic_locators * const loc = &aio->aio_loc;
- bus_space_tag_t iot = aio->aio_core_a4x_bst;
- bus_space_handle_t bsh;
-
- KASSERT(!strcmp(cf->cf_name, loc->loc_name));
- KASSERT((amlogic_com_ports & __BIT(loc->loc_port)) == 0);
- KASSERT(cf->cf_loc[AMLOGICIOCF_PORT] == AMLOGICIOCF_PORT_DEFAULT
- || cf->cf_loc[AMLOGICIOCF_PORT] == loc->loc_port);
-
- if (com_is_console(iot, AMLOGIC_CORE_BASE + loc->loc_offset, NULL))
- return 1;
-
- bus_space_subregion(iot, aio->aio_bsh,
- loc->loc_offset, loc->loc_size, &bsh);
-
- const int rv = comprobe1(iot, bsh);
-
- return rv;
+ return 1;
}
static void
amlogic_com_attach(device_t parent, device_t self, void *aux)
{
- struct amlogic_com_softc * const asc = device_private(self);
- struct com_softc * const sc = &asc->asc_sc;
+ struct amlogic_com_softc * const sc = device_private(self);
struct amlogicio_attach_args * const aio = aux;
const struct amlogic_locators * const loc = &aio->aio_loc;
- bus_space_tag_t iot = aio->aio_core_a4x_bst;
const bus_addr_t iobase = AMLOGIC_CORE_BASE + loc->loc_offset;
- bus_space_handle_t ioh;
-
- amlogic_com_ports |= __BIT(loc->loc_port);
sc->sc_dev = self;
- sc->sc_frequency = AMLOGIC_UART_FREQ;
- sc->sc_type = COM_TYPE_NORMAL;
+ sc->sc_bst = aio->aio_core_bst;
+ sc->sc_bsh = aio->aio_bsh;
+
+ aprint_naive("\n");
+ if (amlogic_com_is_console(iobase)) {
+ aprint_normal(": (console)\n");
+ } else {
+ aprint_normal("\n");
+ }
+}
+
+static int
+amlogic_com_cngetc(dev_t dev)
+{
+ bus_space_tag_t bst = amlogic_com_cnsc.sc_bst;
+ bus_space_handle_t bsh = amlogic_com_cnsc.sc_bsh;
+ uint32_t status;
+ int s, c;
+
+ s = splserial();
- if (com_is_console(iot, iobase, &ioh) == 0
- && bus_space_subregion(iot, aio->aio_bsh,
- loc->loc_offset / 4, loc->loc_size, &ioh)) {
- panic(": can't map registers");
+ status = bus_space_read_4(bst, bsh, UART_STATUS_REG);
+ if (status & UART_STATUS_RX_EMPTY) {
+ splx(s);
+ return -1;
}
- COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
+
+ c = bus_space_read_4(bst, bsh, UART_RFIFO_REG);
+#if defined(DDB)
+ extern int db_active;
+ if (!db_active)
+#endif
+ {
+ int cn_trapped __unused = 0;
+ cn_check_magic(dev, c, amlogic_com_cnm_state);
+ }
+
+ splx(s);
+
+ return c & 0xff;
+}
- com_attach_subr(sc);
- aprint_naive("\n");
+static void
+amlogic_com_cnputc(dev_t dev, int c)
+{
+ bus_space_tag_t bst = amlogic_com_cnsc.sc_bst;
+ bus_space_handle_t bsh = amlogic_com_cnsc.sc_bsh;
+ int s;
+
+ s = splserial();
+
+ while ((bus_space_read_4(bst, bsh, UART_STATUS_REG) & UART_STATUS_TX_EMPTY) == 0)
+ ;
+
+ bus_space_write_4(bst, bsh, UART_WFIFO_REG, c);
+
+ splx(s);
+}
+
+
+static void
+amlogic_com_cnpollc(dev_t dev, int on)
+{
+}
- KASSERT(loc->loc_intr != AMLOGICIO_INTR_DEFAULT);
- asc->asc_ih = intr_establish(loc->loc_intr, IPL_SERIAL,
- IST_EDGE | IST_MPSAFE, comintr, sc);
- if (asc->asc_ih == NULL)
- panic("%s: failed to establish interrupt %d",
- device_xname(self), loc->loc_intr);
+bool
+amlogic_com_cnattach(bus_space_tag_t bst, bus_space_handle_t bsh,
+ int ospeed, tcflag_t cflag)
+{
+ struct amlogic_com_softc *sc = &amlogic_com_cnsc;
+
+ cn_tab = &amlogic_com_consdev;
+ cn_init_magic(&amlogic_com_cnm_state);
+ cn_set_magic("\047\001");
+
+ sc->sc_bst = bst;
+ sc->sc_bsh = bsh;
+ sc->sc_ospeed = ospeed;
+ sc->sc_cflag = cflag;
+
+ return true;
}
+
+bool
+amlogic_com_is_console(bus_addr_t iobase)
+{
+ return iobase == CONSADDR;
+}
diff -r 932b721e6e50 -r 15b5ab906661 sys/arch/arm/amlogic/amlogic_comreg.h
--- a/sys/arch/arm/amlogic/amlogic_comreg.h Fri Feb 27 17:33:31 2015 +0000
+++ b/sys/arch/arm/amlogic/amlogic_comreg.h Fri Feb 27 17:35:08 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_comreg.h,v 1.1 2015/02/07 17:20:17 jmcneill Exp $ */
+/* $NetBSD: amlogic_comreg.h,v 1.2 2015/02/27 17:35:08 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -36,7 +36,9 @@
#define UART_MISC_REG 0x10
#define UART_REG5_REG 0x14
+#define UART_STATUS_RX_BUSY __BIT(26)
#define UART_STATUS_TX_BUSY __BIT(25)
#define UART_STATUS_TX_EMPTY __BIT(22)
+#define UART_STATUS_RX_EMPTY __BIT(20)
#endif /* _ARM_AMLOGIC_COMREG_H */
diff -r 932b721e6e50 -r 15b5ab906661 sys/arch/arm/amlogic/amlogic_comvar.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/amlogic/amlogic_comvar.h Fri Feb 27 17:35:08 2015 +0000
@@ -0,0 +1,37 @@
+/* $NetBSD: amlogic_comvar.h,v 1.1 2015/02/27 17:35:08 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _ARM_AMLOGIC_COVMAR_H
+#define _ARM_AMLOGIC_COVMAR_H
+
+#include <dev/cons.h>
+
+bool amlogic_com_cnattach(bus_space_tag_t, bus_space_handle_t, int, tcflag_t);
+bool amlogic_com_is_console(bus_addr_t);
+
+#endif /* _ARM_AMLOGIC_COVMAR_H */
diff -r 932b721e6e50 -r 15b5ab906661 sys/arch/arm/amlogic/files.amlogic
--- a/sys/arch/arm/amlogic/files.amlogic Fri Feb 27 17:33:31 2015 +0000
+++ b/sys/arch/arm/amlogic/files.amlogic Fri Feb 27 17:35:08 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.amlogic,v 1.1 2015/02/07 17:20:17 jmcneill Exp $
+# $NetBSD: files.amlogic,v 1.2 2015/02/27 17:35:08 jmcneill Exp $
#
# Configuration info for Amlogic ARM Peripherals
#
@@ -21,8 +21,9 @@
file arch/arm/amlogic/amlogic_io.c amlogic_io
# serial
-attach com at amlogicio with amlogic_com
-file arch/arm/amlogic/amlogic_com.c amlogic_com
+device amlogiccom { } : bus_space_generic
+attach amlogiccom at amlogicio with amlogic_com
+file arch/arm/amlogic/amlogic_com.c amlogic_com needs-flag
# Console parameters
defparam opt_amlogic.h CONADDR
diff -r 932b721e6e50 -r 15b5ab906661 sys/arch/evbarm/amlogic/amlogic_machdep.c
--- a/sys/arch/evbarm/amlogic/amlogic_machdep.c Fri Feb 27 17:33:31 2015 +0000
+++ b/sys/arch/evbarm/amlogic/amlogic_machdep.c Fri Feb 27 17:35:08 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_machdep.c,v 1.1 2015/02/07 17:20:16 jmcneill Exp $ */
+/* $NetBSD: amlogic_machdep.c,v 1.2 2015/02/27 17:35:08 jmcneill Exp $ */
/*
* Machine dependent functions for kernel setup for TI OSK5912 board.
@@ -125,18 +125,17 @@
*/
Home |
Main Index |
Thread Index |
Old Index