Module Name: src Committed By: jmcneill Date: Sun Jul 30 23:48:32 UTC 2017
Modified Files: src/sys/arch/arm/broadcom: bcm2835_obio.c bcm2835reg.h files.bcm2835 src/sys/arch/evbarm/conf: RPI src/sys/arch/evbarm/rpi: rpi_machdep.c Added Files: src/sys/arch/arm/broadcom: bcm2835_com.c Log Message: Add support for BCM2835 AUX UART. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/broadcom/bcm2835_com.c cvs rdiff -u -r1.27 -r1.28 src/sys/arch/arm/broadcom/bcm2835_obio.c \ src/sys/arch/arm/broadcom/files.bcm2835 cvs rdiff -u -r1.19 -r1.20 src/sys/arch/arm/broadcom/bcm2835reg.h cvs rdiff -u -r1.73 -r1.74 src/sys/arch/evbarm/conf/RPI cvs rdiff -u -r1.74 -r1.75 src/sys/arch/evbarm/rpi/rpi_machdep.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/arch/arm/broadcom/bcm2835_obio.c diff -u src/sys/arch/arm/broadcom/bcm2835_obio.c:1.27 src/sys/arch/arm/broadcom/bcm2835_obio.c:1.28 --- src/sys/arch/arm/broadcom/bcm2835_obio.c:1.27 Sun Jul 30 16:54:36 2017 +++ src/sys/arch/arm/broadcom/bcm2835_obio.c Sun Jul 30 23:48:32 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: bcm2835_obio.c,v 1.27 2017/07/30 16:54:36 jmcneill Exp $ */ +/* $NetBSD: bcm2835_obio.c,v 1.28 2017/07/30 23:48:32 jmcneill Exp $ */ /*- * Copyright (c) 2012, 2014 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: bcm2835_obio.c,v 1.27 2017/07/30 16:54:36 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bcm2835_obio.c,v 1.28 2017/07/30 23:48:32 jmcneill Exp $"); #include "locators.h" #include "obio.h" @@ -141,6 +141,13 @@ static const struct ambadev_locators bcm .ad_intr = BCM2835_INT_UART0, }, { + /* AUX UART */ + .ad_name = "com", + .ad_addr = BCM2835_AUX_UART_BASE, + .ad_size = BCM2835_AUX_UART_SIZE, + .ad_intr = BCM2835_INT_AUX, + }, + { /* Framebuffer */ .ad_name = "fb", .ad_addr = 0, Index: src/sys/arch/arm/broadcom/files.bcm2835 diff -u src/sys/arch/arm/broadcom/files.bcm2835:1.27 src/sys/arch/arm/broadcom/files.bcm2835:1.28 --- src/sys/arch/arm/broadcom/files.bcm2835:1.27 Sun Jul 30 16:54:36 2017 +++ src/sys/arch/arm/broadcom/files.bcm2835 Sun Jul 30 23:48:32 2017 @@ -1,4 +1,4 @@ -# $NetBSD: files.bcm2835,v 1.27 2017/07/30 16:54:36 jmcneill Exp $ +# $NetBSD: files.bcm2835,v 1.28 2017/07/30 23:48:32 jmcneill Exp $ # # Configuration info for Broadcom BCM2835 ARM Peripherals # @@ -57,6 +57,10 @@ file arch/arm/broadcom/bcm2835_rng.c bc attach plcom at obio with bcmplcom file arch/arm/broadcom/bcm2835_plcom.c bcmplcom +# AUX UART (BCM2835_AUX_UART_BASE) +attach com at obio with bcmcom +file arch/arm/broadcom/bcm2835_com.c bcmcom + # External Mass Media Controller (BCM2835_EMMC_BASE) attach sdhc at obio with bcmemmc file arch/arm/broadcom/bcm2835_emmc.c bcmemmc Index: src/sys/arch/arm/broadcom/bcm2835reg.h diff -u src/sys/arch/arm/broadcom/bcm2835reg.h:1.19 src/sys/arch/arm/broadcom/bcm2835reg.h:1.20 --- src/sys/arch/arm/broadcom/bcm2835reg.h:1.19 Sun Jul 30 16:54:36 2017 +++ src/sys/arch/arm/broadcom/bcm2835reg.h Sun Jul 30 23:48:32 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: bcm2835reg.h,v 1.19 2017/07/30 16:54:36 jmcneill Exp $ */ +/* $NetBSD: bcm2835reg.h,v 1.20 2017/07/30 23:48:32 jmcneill Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -68,6 +68,7 @@ #define BCM2835_PWM_BASE (BCM2835_PERIPHERALS_BASE_BUS + 0x0020C000) #define BCM2835_BSCSPISLV_BASE (BCM2835_PERIPHERALS_BASE_BUS + 0x00214000) #define BCM2835_AUX_BASE (BCM2835_PERIPHERALS_BASE_BUS + 0x00215000) +#define BCM2835_AUX_UART_BASE (BCM2835_PERIPHERALS_BASE_BUS + 0x00215040) #define BCM2835_EMMC_BASE (BCM2835_PERIPHERALS_BASE_BUS + 0x00300000) #define BCM2835_BSC1_BASE (BCM2835_PERIPHERALS_BASE_BUS + 0x00804000) #define BCM2835_BSC2_BASE (BCM2835_PERIPHERALS_BASE_BUS + 0x00805000) @@ -86,7 +87,8 @@ #define BCM2835_SPI0_SIZE 0x1000 #define BCM2835_BSC_SIZE 0x1000 #define BCM2835_PWM_SIZE 0x28 -#define BCM2835_AUX_SIZE 0x1000 +#define BCM2835_AUX_SIZE 0x8 +#define BCM2835_AUX_UART_SIZE 0x40 #define BCM2835_SDHOST_SIZE 0x1000 #define BCM2835_EMMC_SIZE 0x1000 #define BCM2835_USB_SIZE 0x20000 Index: src/sys/arch/evbarm/conf/RPI diff -u src/sys/arch/evbarm/conf/RPI:1.73 src/sys/arch/evbarm/conf/RPI:1.74 --- src/sys/arch/evbarm/conf/RPI:1.73 Sun Jul 30 17:01:27 2017 +++ src/sys/arch/evbarm/conf/RPI Sun Jul 30 23:48:32 2017 @@ -1,5 +1,5 @@ # -# $NetBSD: RPI,v 1.73 2017/07/30 17:01:27 jmcneill Exp $ +# $NetBSD: RPI,v 1.74 2017/07/30 23:48:32 jmcneill Exp $ # # RPi -- Raspberry Pi # @@ -73,6 +73,9 @@ spkr* at audio? # PC speaker (synthesi # PL011 uart plcom0 at obio? +# AUX UART +com0 at obio? + # Framebuffer console genfb0 at obio? wsdisplay* at genfb? Index: src/sys/arch/evbarm/rpi/rpi_machdep.c diff -u src/sys/arch/evbarm/rpi/rpi_machdep.c:1.74 src/sys/arch/evbarm/rpi/rpi_machdep.c:1.75 --- src/sys/arch/evbarm/rpi/rpi_machdep.c:1.74 Sun Jul 30 17:32:59 2017 +++ src/sys/arch/evbarm/rpi/rpi_machdep.c Sun Jul 30 23:48:32 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: rpi_machdep.c,v 1.74 2017/07/30 17:32:59 jmcneill Exp $ */ +/* $NetBSD: rpi_machdep.c,v 1.75 2017/07/30 23:48:32 jmcneill Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rpi_machdep.c,v 1.74 2017/07/30 17:32:59 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rpi_machdep.c,v 1.75 2017/07/30 23:48:32 jmcneill Exp $"); #include "opt_arm_debug.h" #include "opt_bcm283x.h" @@ -1206,6 +1206,12 @@ rpi_device_register(device_t dev, void * prop_dictionary_set_uint32(dict, "frequency", vb_uart.vbt_uartclockrate.rate); } + if (device_is_a(dev, "com") && + vcprop_tag_success_p(&vb.vbt_coreclockrate.tag) && + vb.vbt_coreclockrate.rate > 0) { + prop_dictionary_set_uint32(dict, + "frequency", vb.vbt_coreclockrate.rate); + } if (device_is_a(dev, "bcmdmac") && vcprop_tag_success_p(&vb.vbt_dmachan.tag)) { prop_dictionary_set_uint32(dict, Added files: Index: src/sys/arch/arm/broadcom/bcm2835_com.c diff -u /dev/null src/sys/arch/arm/broadcom/bcm2835_com.c:1.1 --- /dev/null Sun Jul 30 23:48:32 2017 +++ src/sys/arch/arm/broadcom/bcm2835_com.c Sun Jul 30 23:48:32 2017 @@ -0,0 +1,97 @@ +/* $NetBSD: bcm2835_com.c,v 1.1 2017/07/30 23:48:32 jmcneill Exp $ */ + +/*- + * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca> + * 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. + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: bcm2835_com.c,v 1.1 2017/07/30 23:48:32 jmcneill Exp $"); + +#include <sys/param.h> +#include <sys/bus.h> +#include <sys/device.h> +#include <sys/intr.h> +#include <sys/systm.h> +#include <sys/termios.h> + +#include <arm/broadcom/bcm_amba.h> +#include <arm/broadcom/bcm2835reg.h> +#include <arm/broadcom/bcm2835var.h> +#include <arm/broadcom/bcm2835_intr.h> + +#include <dev/ic/comvar.h> + +static int bcm_com_match(device_t, cfdata_t, void *); +static void bcm_com_attach(device_t, device_t, void *); + +CFATTACH_DECL_NEW(bcmcom, sizeof(struct com_softc), + bcm_com_match, bcm_com_attach, NULL, NULL); + +static int +bcm_com_match(device_t parent, cfdata_t cf, void *aux) +{ + struct amba_attach_args *aaa = aux; + + return strcmp(aaa->aaa_name, "com") == 0; +} + +static void +bcm_com_attach(device_t parent, device_t self, void *aux) +{ + struct com_softc * const sc = device_private(self); + struct amba_attach_args * const aaa = aux; + const prop_dictionary_t dict = device_properties(self); + bus_space_tag_t bst = &bcm2835_a4x_bs_tag; + bus_space_handle_t bsh; + void *ih; + + sc->sc_dev = self; + sc->sc_type = COM_TYPE_NORMAL; + + prop_dictionary_get_uint32(dict, "frequency", &sc->sc_frequency); + if (sc->sc_frequency == 0) { + aprint_error(": couldn't get frequency\n"); + return; + } + sc->sc_frequency *= 2; + + if (bus_space_map(bst, aaa->aaa_addr, aaa->aaa_size, 0, &bsh) != 0) { + aprint_error(": can't map device\n"); + return; + } + + COM_INIT_REGS(sc->sc_regs, bst, bsh, aaa->aaa_addr); + + com_attach_subr(sc); + aprint_naive("\n"); + + ih = intr_establish(aaa->aaa_intr, IPL_SERIAL, IST_LEVEL, comintr, sc); + if (ih == NULL) { + aprint_error_dev(self, "failed to establish interrupt %d\n", + aaa->aaa_intr); + return; + } + aprint_normal_dev(self, "interrupting on intr %d\n", aaa->aaa_intr); +}