Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Add support for BCM2835 AUX UART.



details:   https://anonhg.NetBSD.org/src/rev/c24b50474c8f
branches:  trunk
changeset: 825794:c24b50474c8f
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Jul 30 23:48:32 2017 +0000

description:
Add support for BCM2835 AUX UART.

diffstat:

 sys/arch/arm/broadcom/bcm2835_com.c  |  97 ++++++++++++++++++++++++++++++++++++
 sys/arch/arm/broadcom/bcm2835_obio.c |  11 +++-
 sys/arch/arm/broadcom/bcm2835reg.h   |   6 +-
 sys/arch/arm/broadcom/files.bcm2835  |   6 +-
 sys/arch/evbarm/conf/RPI             |   5 +-
 sys/arch/evbarm/rpi/rpi_machdep.c    |  10 ++-
 6 files changed, 127 insertions(+), 8 deletions(-)

diffs (231 lines):

diff -r 04de1f6fbed1 -r c24b50474c8f sys/arch/arm/broadcom/bcm2835_com.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_com.c       Sun Jul 30 23:48:32 2017 +0000
@@ -0,0 +1,97 @@
+/* $NetBSD: bcm2835_com.c,v 1.1 2017/07/30 23:48:32 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2017 Jared 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.
+ */
+
+#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);
+}
diff -r 04de1f6fbed1 -r c24b50474c8f sys/arch/arm/broadcom/bcm2835_obio.c
--- a/sys/arch/arm/broadcom/bcm2835_obio.c      Sun Jul 30 23:47:58 2017 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_obio.c      Sun Jul 30 23:48:32 2017 +0000
@@ -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 @@
                .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,
diff -r 04de1f6fbed1 -r c24b50474c8f sys/arch/arm/broadcom/bcm2835reg.h
--- a/sys/arch/arm/broadcom/bcm2835reg.h        Sun Jul 30 23:47:58 2017 +0000
+++ b/sys/arch/arm/broadcom/bcm2835reg.h        Sun Jul 30 23:48:32 2017 +0000
@@ -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
diff -r 04de1f6fbed1 -r c24b50474c8f sys/arch/arm/broadcom/files.bcm2835
--- a/sys/arch/arm/broadcom/files.bcm2835       Sun Jul 30 23:47:58 2017 +0000
+++ b/sys/arch/arm/broadcom/files.bcm2835       Sun Jul 30 23:48:32 2017 +0000
@@ -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 @@
 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
diff -r 04de1f6fbed1 -r c24b50474c8f sys/arch/evbarm/conf/RPI
--- a/sys/arch/evbarm/conf/RPI  Sun Jul 30 23:47:58 2017 +0000
+++ b/sys/arch/evbarm/conf/RPI  Sun Jul 30 23:48:32 2017 +0000
@@ -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 @@
 # PL011 uart
 plcom0         at obio?
 
+# AUX UART
+com0           at obio?
+
 # Framebuffer console
 genfb0         at obio?
 wsdisplay*     at genfb?
diff -r 04de1f6fbed1 -r c24b50474c8f sys/arch/evbarm/rpi/rpi_machdep.c
--- a/sys/arch/evbarm/rpi/rpi_machdep.c Sun Jul 30 23:47:58 2017 +0000
+++ b/sys/arch/evbarm/rpi/rpi_machdep.c Sun Jul 30 23:48:32 2017 +0000
@@ -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 @@
                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,



Home | Main Index | Thread Index | Old Index