Module Name: src
Committed By: jmcneill
Date: Fri Feb 27 17:35:08 UTC 2015
Modified Files:
src/sys/arch/arm/amlogic: amlogic_com.c amlogic_comreg.h files.amlogic
src/sys/arch/evbarm/amlogic: amlogic_machdep.c
src/sys/arch/evbarm/conf: ODROID-C1
Added Files:
src/sys/arch/arm/amlogic: amlogic_comvar.h
Log Message:
Add basic serial console support.
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/amlogic/amlogic_com.c \
src/sys/arch/arm/amlogic/amlogic_comreg.h \
src/sys/arch/arm/amlogic/files.amlogic
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/amlogic/amlogic_comvar.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbarm/amlogic/amlogic_machdep.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbarm/conf/ODROID-C1
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/arm/amlogic/amlogic_com.c
diff -u src/sys/arch/arm/amlogic/amlogic_com.c:1.1 src/sys/arch/arm/amlogic/amlogic_com.c:1.2
--- src/sys/arch/arm/amlogic/amlogic_com.c:1.1 Sat Feb 7 17:20:17 2015
+++ src/sys/arch/arm/amlogic/amlogic_com.c Fri Feb 27 17:35:08 2015
@@ -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 @@ __KERNEL_RCSID(1, "$NetBSD: amlogic_com.
#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)
{
+ return 1;
+}
+
+static void
+amlogic_com_attach(device_t parent, device_t self, void *aux)
+{
+ 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;
- bus_space_handle_t bsh;
+ const bus_addr_t iobase = AMLOGIC_CORE_BASE + loc->loc_offset;
- 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);
+ sc->sc_dev = self;
+ sc->sc_bst = aio->aio_core_bst;
+ sc->sc_bsh = aio->aio_bsh;
- if (com_is_console(iot, AMLOGIC_CORE_BASE + loc->loc_offset, NULL))
- return 1;
+ aprint_naive("\n");
+ if (amlogic_com_is_console(iobase)) {
+ aprint_normal(": (console)\n");
+ } else {
+ aprint_normal("\n");
+ }
+}
- bus_space_subregion(iot, aio->aio_bsh,
- loc->loc_offset, loc->loc_size, &bsh);
+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();
+
+ status = bus_space_read_4(bst, bsh, UART_STATUS_REG);
+ if (status & UART_STATUS_RX_EMPTY) {
+ splx(s);
+ return -1;
+ }
- const int rv = comprobe1(iot, bsh);
+ 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 rv;
+ return c & 0xff;
}
static void
-amlogic_com_attach(device_t parent, device_t self, void *aux)
+amlogic_com_cnputc(dev_t dev, int c)
{
- struct amlogic_com_softc * const asc = device_private(self);
- struct com_softc * const sc = &asc->asc_sc;
- 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;
+ bus_space_tag_t bst = amlogic_com_cnsc.sc_bst;
+ bus_space_handle_t bsh = amlogic_com_cnsc.sc_bsh;
+ int s;
- amlogic_com_ports |= __BIT(loc->loc_port);
+ s = splserial();
- sc->sc_dev = self;
- sc->sc_frequency = AMLOGIC_UART_FREQ;
- sc->sc_type = COM_TYPE_NORMAL;
+ while ((bus_space_read_4(bst, bsh, UART_STATUS_REG) & UART_STATUS_TX_EMPTY) == 0)
+ ;
- 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");
- }
- COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
+ bus_space_write_4(bst, bsh, UART_WFIFO_REG, c);
- com_attach_subr(sc);
- aprint_naive("\n");
+ splx(s);
+}
+
- 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);
+static void
+amlogic_com_cnpollc(dev_t dev, int on)
+{
+}
+
+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;
}
Index: src/sys/arch/arm/amlogic/amlogic_comreg.h
diff -u src/sys/arch/arm/amlogic/amlogic_comreg.h:1.1 src/sys/arch/arm/amlogic/amlogic_comreg.h:1.2
--- src/sys/arch/arm/amlogic/amlogic_comreg.h:1.1 Sat Feb 7 17:20:17 2015
+++ src/sys/arch/arm/amlogic/amlogic_comreg.h Fri Feb 27 17:35:08 2015
@@ -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 <[email protected]>
@@ -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 */
Index: src/sys/arch/arm/amlogic/files.amlogic
diff -u src/sys/arch/arm/amlogic/files.amlogic:1.1 src/sys/arch/arm/amlogic/files.amlogic:1.2
--- src/sys/arch/arm/amlogic/files.amlogic:1.1 Sat Feb 7 17:20:17 2015
+++ src/sys/arch/arm/amlogic/files.amlogic Fri Feb 27 17:35:08 2015
@@ -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 @@ attach amlogicio at mainbus with amlogic
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
Index: src/sys/arch/evbarm/amlogic/amlogic_machdep.c
diff -u src/sys/arch/evbarm/amlogic/amlogic_machdep.c:1.1 src/sys/arch/evbarm/amlogic/amlogic_machdep.c:1.2
--- src/sys/arch/evbarm/amlogic/amlogic_machdep.c:1.1 Sat Feb 7 17:20:16 2015
+++ src/sys/arch/evbarm/amlogic/amlogic_machdep.c Fri Feb 27 17:35:08 2015
@@ -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 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amlogic_machdep.c,v 1.1 2015/02/07 17:20:16 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amlogic_machdep.c,v 1.2 2015/02/27 17:35:08 jmcneill Exp $");
#include "opt_machdep.h"
#include "opt_ddb.h"
#include "opt_kgdb.h"
#include "opt_ipkdb.h"
#include "opt_md.h"
-#include "opt_com.h"
#include "opt_amlogic.h"
#include "opt_arm_debug.h"
-#include "com.h"
+#include "amlogic_com.h"
#if 0
#include "prcm.h"
#include "sdhc.h"
@@ -184,6 +183,7 @@ __KERNEL_RCSID(0, "$NetBSD: amlogic_mach
#include <arm/amlogic/amlogic_reg.h>
#include <arm/amlogic/amlogic_var.h>
#include <arm/amlogic/amlogic_comreg.h>
+#include <arm/amlogic/amlogic_comvar.h>
#include <arm/cortex/pl310_reg.h>
#include <arm/cortex/scu_reg.h>
@@ -220,12 +220,6 @@ u_int uboot_args[4] = { 0 }; /* filled i
extern char KERNEL_BASE_phys[];
extern char _end[];
-#if NCOM > 0
-int use_fb_console = false;
-#else
-int use_fb_console = true;
-#endif
-
/*
* Macros to translate between physical and virtual for a subset of the
* kernel address space. *Not* for general use.
@@ -245,11 +239,6 @@ static void amlogic_reset(void);
bs_protos(bs_notimpl);
-#if NCOM > 0
-#include <dev/ic/comreg.h>
-#include <dev/ic/comvar.h>
-#endif
-
/*
* Static device mappings. These peripheral registers are mapped at
* fixed virtual addresses very early in initarm() so that we can use
@@ -297,14 +286,14 @@ amlogic_putchar(char c)
volatile uint32_t *uartaddr = (volatile uint32_t *)CONSADDR_VA;
int timo = 150000;
- while ((uartaddr[UART_STATUS_REG] & UART_STATUS_TX_EMPTY) == 0) {
+ while ((uartaddr[UART_STATUS_REG/4] & UART_STATUS_TX_EMPTY) == 0) {
if (--timo == 0)
break;
}
- uartaddr[UART_WFIFO_REG] = c;
+ uartaddr[UART_WFIFO_REG/4] = c;
- while ((uartaddr[UART_STATUS_REG] & UART_STATUS_TX_EMPTY) == 0) {
+ while ((uartaddr[UART_STATUS_REG/4] & UART_STATUS_TX_EMPTY) == 0) {
if (--timo == 0)
break;
}
@@ -327,15 +316,14 @@ u_int
initarm(void *arg)
{
psize_t ram_size = 0;
- char *ptr;
*(volatile int *)CONSADDR_VA = 0x40; /* output '@' */
-#if 1
- amlogic_putchar('d');
-#endif
+ amlogic_putchar('d');
pmap_devmap_register(devmap);
+
amlogic_putchar('b');
amlogic_bootstrap();
+
amlogic_putchar('!');
#ifdef MULTIPROCESSOR
@@ -434,7 +422,7 @@ initarm(void *arg)
arm32_bootmem_init(bootconfig.dram[0].address, ram_size,
KERNEL_BASE_PHYS);
- arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_LOW, 0, devmap,
+ arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0, devmap,
mapallmem_p);
printf("bootargs: %s\n", bootargs);
@@ -447,11 +435,6 @@ initarm(void *arg)
db_trap_callback = amlogic_db_trap;
- if (get_bootconf_option(boot_args, "console",
- BOOTOPT_TYPE_STRING, &ptr) && strncmp(ptr, "fb", 2) == 0) {
- use_fb_console = true;
- }
-
#if notyet
curcpu()->ci_data.cpu_cc_freq = amlogic_cpu_get_rate();
#else
@@ -468,7 +451,7 @@ init_clocks(void)
/* NOT YET */
}
-#if NCOM > 0
+#if NAMLOGIC_COM > 0
#ifndef CONSADDR
#error Specify the address of the console UART with the CONSADDR option.
#endif
@@ -487,8 +470,8 @@ static const int conmode = CONMODE;
void
consinit(void)
{
-#if NCOM > 0
- bus_space_handle_t bh;
+#if NAMLOGIC_COM > 0
+ bus_space_handle_t bsh;
#endif
static int consinit_called = 0;
@@ -499,18 +482,12 @@ consinit(void)
amlogic_putchar('e');
-#if NCOM > 0
- if (bus_space_map(&amlogic_a4x_bs_tag, consaddr, AMLOGIC_UART_SIZE, 0, &bh))
- panic("Serial console can not be mapped.");
-
- if (comcnattach(&amlogic_a4x_bs_tag, consaddr, conspeed,
- AMLOGIC_UART_FREQ, COM_TYPE_NORMAL, conmode))
- panic("Serial console can not be initialized.");
-
- bus_space_unmap(&amlogic_a4x_bs_tag, bh, AMLOGIC_UART_SIZE);
+#if NAMLOGIC_COM > 0
+ bus_space_subregion(&amlogic_bs_tag, amlogic_core_bsh,
+ consaddr - AMLOGIC_CORE_BASE, AMLOGIC_UART_SIZE, &bsh);
+ amlogic_com_cnattach(&amlogic_bs_tag, consaddr, conspeed, conmode);
#endif
-
#if NUKBD > 0
ukbd_cnattach(); /* allow USB keyboard to become console */
#endif
Index: src/sys/arch/evbarm/conf/ODROID-C1
diff -u src/sys/arch/evbarm/conf/ODROID-C1:1.1 src/sys/arch/evbarm/conf/ODROID-C1:1.2
--- src/sys/arch/evbarm/conf/ODROID-C1:1.1 Sat Feb 7 17:20:16 2015
+++ src/sys/arch/evbarm/conf/ODROID-C1 Fri Feb 27 17:35:08 2015
@@ -1,5 +1,5 @@
#
-# $NetBSD: ODROID-C1,v 1.1 2015/02/07 17:20:16 jmcneill Exp $
+# $NetBSD: ODROID-C1,v 1.2 2015/02/27 17:35:08 jmcneill Exp $
#
# Odroid-C1 (Amlogic S805) based SBC (Single Board Computer)
#
@@ -171,8 +171,8 @@ options MEMSIZE=1024
# On-board I/O
amlogicio0 at mainbus?
-# On-board 16550 UARTs
-com0 at amlogicio0 port 0
+# On-board UARTs
+amlogiccom0 at amlogicio0 port 0
options CONSADDR=0xc81004c0, CONSPEED=115200
# Pseudo-Devices
Added files:
Index: src/sys/arch/arm/amlogic/amlogic_comvar.h
diff -u /dev/null src/sys/arch/arm/amlogic/amlogic_comvar.h:1.1
--- /dev/null Fri Feb 27 17:35:08 2015
+++ src/sys/arch/arm/amlogic/amlogic_comvar.h Fri Feb 27 17:35:08 2015
@@ -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 <[email protected]>
+ * 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 */