Source-Changes-HG archive

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

[src/trunk]: src add a driver for BCM2835 obio gpio



details:   https://anonhg.NetBSD.org/src/rev/920c868e73b1
branches:  trunk
changeset: 328893:920c868e73b1
user:      kardel <kardel%NetBSD.org@localhost>
date:      Tue Apr 22 18:51:35 2014 +0000

description:
add a driver for BCM2835 obio gpio

diffstat:

 distrib/sets/lists/man/mi                 |    5 +-
 doc/CHANGES                               |    6 +-
 share/man/man4/bcmgpio.4                  |   63 +++++++
 sys/arch/arm/broadcom/bcm2835_gpio.c      |  265 ++++++++++++++++++++++++++++++
 sys/arch/arm/broadcom/bcm2835_gpio_subr.c |   21 ++-
 sys/arch/arm/broadcom/bcm2835_gpio_subr.h |    5 +-
 sys/arch/arm/broadcom/bcm2835_gpioreg.h   |   22 ++-
 sys/arch/arm/broadcom/bcm2835_obio.c      |   20 +-
 sys/arch/arm/broadcom/files.bcm2835       |    7 +-
 sys/arch/evbarm/conf/RPI                  |   10 +-
 10 files changed, 408 insertions(+), 16 deletions(-)

diffs (truncated from 586 to 300 lines):

diff -r 71dd798df18a -r 920c868e73b1 distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Tue Apr 22 16:10:48 2014 +0000
+++ b/distrib/sets/lists/man/mi Tue Apr 22 18:51:35 2014 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1469 2014/04/15 22:09:27 ginsbach Exp $
+# $NetBSD: mi,v 1.1470 2014/04/22 18:51:35 kardel Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -901,6 +901,7 @@
 ./usr/share/man/cat4/battery_pmu.0             man-sys-catman          .cat
 ./usr/share/man/cat4/bba.0                     man-sys-catman          .cat
 ./usr/share/man/cat4/bce.0                     man-sys-catman          .cat
+./usr/share/man/cat4/bcmgpio.0                 man-sys-catman          .cat
 ./usr/share/man/cat4/bcsp.0                    man-sys-catman          .cat
 ./usr/share/man/cat4/be.0                      man-sys-catman          .cat
 ./usr/share/man/cat4/bge.0                     man-sys-catman          .cat
@@ -3941,6 +3942,7 @@
 ./usr/share/man/html4/battery_pmu.html         man-sys-htmlman         html
 ./usr/share/man/html4/bba.html                 man-sys-htmlman         html
 ./usr/share/man/html4/bce.html                 man-sys-htmlman         html
+./usr/share/man/html4/bcmgpio.html             man-sys-htmlman         html
 ./usr/share/man/html4/bcsp.html                        man-sys-htmlman         html
 ./usr/share/man/html4/be.html                  man-sys-htmlman         html
 ./usr/share/man/html4/bge.html                 man-sys-htmlman         html
@@ -6745,6 +6747,7 @@
 ./usr/share/man/man4/battery_pmu.4             man-sys-man             .man
 ./usr/share/man/man4/bba.4                     man-sys-man             .man
 ./usr/share/man/man4/bce.4                     man-sys-man             .man
+./usr/share/man/man4/bcmgpio.4                 man-sys-man             .man
 ./usr/share/man/man4/bcsp.4                    man-sys-man             .man
 ./usr/share/man/man4/be.4                      man-sys-man             .man
 ./usr/share/man/man4/bge.4                     man-sys-man             .man
diff -r 71dd798df18a -r 920c868e73b1 doc/CHANGES
--- a/doc/CHANGES       Tue Apr 22 16:10:48 2014 +0000
+++ b/doc/CHANGES       Tue Apr 22 18:51:35 2014 +0000
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:                   <$Revision: 1.1918 $>
+# LIST OF CHANGES FROM LAST RELEASE:                   <$Revision: 1.1919 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -401,7 +401,7 @@
        ptyfs: Allow multiple mounts and support proper device visibility
                in chroots (Ilya Zykov) [christos 20140404]
        i386: Switched to GCC 4.8.  [christos 20140404]
-       mcp23s17gpio: Add Microchip MCP23S17 16-bit GPIO chip driver.
+       mcp23s17gpio(4): Add Microchip MCP23S17 16-bit GPIO chip driver.
                e.g. Raspberry Pi interface boards [kardel 20140406]
        OpenSSL: Imported 1.0.1g [christos 20140407]
        sparc64: Switched to TOPDOWN_VM [martin 20140414]
@@ -411,3 +411,5 @@
        hp300: Add HP9000/425e RTC support. [tsutsui 20140419]
        ubsec(4): Add support for AES-CBC modes and BCM586x chips.
                [bad 20140419]
+       bcmgpio(4): Add BCM2835 GPIO obio driver.
+               [kardel 20140422]
diff -r 71dd798df18a -r 920c868e73b1 share/man/man4/bcmgpio.4
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man4/bcmgpio.4  Tue Apr 22 18:51:35 2014 +0000
@@ -0,0 +1,63 @@
+.\"    $NetBSD: bcmgpio.4,v 1.1 2014/04/22 18:51:35 kardel Exp $
+.\"
+.\"Copyright (c) 2014 Frank Kardel
+.\"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 AND CONTRIBUTORS
+.\"``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 FOUNDATION OR CONTRIBUTORS
+.\"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.
+.\"
+.Dd April 21, 2014
+.Dt BCMGPIO 4
+.Os
+.Sh NAME
+.Nm bcmgpio
+.Nd Driver for BCM2835 onboard gpio 
+.Sh SYNOPSIS
+.Cd "bcmgpio0 at obio?"
+.Cd "bcmgpio1 at obio?"
+.Cd "gpio* at gpiobus?"
+.Sh DESCRIPTION
+The
+.Nm
+driver supports up to two instances.
+Access to the pins is provided by the
+.Xr gpio 4
+interface.
+The
+.Nm
+.Ar unitnumber
+argument selects the pin range. Unit 0 covers GPIO pins 0 through 31 and
+unit 1 covers pins 32 through 53. GPIO pins being used in alternate configurations
+are not available for GPIO operations.
+.Sh SEE ALSO
+.Xr gpio 4 ,
+.Xr intro 4
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Nx 7.0 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Frank Kardel Aq Mt kardel%NetBSD.org@localhost .
diff -r 71dd798df18a -r 920c868e73b1 sys/arch/arm/broadcom/bcm2835_gpio.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_gpio.c      Tue Apr 22 18:51:35 2014 +0000
@@ -0,0 +1,265 @@
+/*     $NetBSD: bcm2835_gpio.c,v 1.1 2014/04/22 18:51:35 kardel Exp $  */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Frank Kardel.
+ *
+ * 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 COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 COPYRIGHT HOLDER OR
+ * CONTRIBUTORS 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_gpio.c,v 1.1 2014/04/22 18:51:35 kardel Exp $");
+
+/*
+ * Driver for BCM2835 GPIO
+ *
+ * see: http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf
+ */
+
+#include "gpio.h"
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/systm.h>
+#include <sys/mutex.h>
+#include <sys/bus.h>
+#include <sys/intr.h>
+#include <sys/kernel.h>
+#include <sys/gpio.h>
+#include <dev/gpio/gpiovar.h>
+
+#include <sys/bitops.h>
+
+#include <arm/broadcom/bcm_amba.h>
+#include <arm/broadcom/bcm2835reg.h>
+#include <arm/broadcom/bcm2835_gpioreg.h>
+#include <arm/broadcom/bcm2835_gpio_subr.h>
+
+/* #define BCM2835_GPIO_DEBUG */
+#ifdef BCM2835_GPIO_DEBUG
+int bcm2835gpiodebug = 3;
+#define DPRINTF(l, x)  do { if (l <= bcm2835gpiodebug) { printf x; } } while (0)
+#else
+#define DPRINTF(l, x)
+#endif
+
+struct bcmgpio_softc {
+       device_t                sc_dev;
+       bus_space_tag_t         sc_iot;
+       bus_space_handle_t      sc_ioh;
+       struct gpio_chipset_tag sc_gpio_gc;
+       gpio_pin_t              sc_gpio_pins[32];
+};
+
+static int     bcmgpio_match(device_t, cfdata_t, void *);
+static void    bcmgpio_attach(device_t, device_t, void *);
+
+#if NGPIO > 0
+static int      bcm2835gpio_gpio_pin_read(void *, int);
+static void     bcm2835gpio_gpio_pin_write(void *, int, int);
+static void     bcm2835gpio_gpio_pin_ctl(void *, int, int);
+#endif
+
+CFATTACH_DECL_NEW(bcmgpio, sizeof(struct bcmgpio_softc),
+    bcmgpio_match, bcmgpio_attach, NULL, NULL);
+
+static int
+bcmgpio_match(device_t parent, cfdata_t cf, void *aux)
+{
+       struct amba_attach_args * const aaa = aux;
+
+       if (strcmp(aaa->aaa_name, "bcmgpio") != 0)
+               return 0;
+
+       return 1;
+}
+
+static void
+bcmgpio_attach(device_t parent, device_t self, void *aux)
+{
+       struct bcmgpio_softc * const sc = device_private(self);
+#if NGPIO > 0
+       int pin, minpin, maxpin;
+       u_int func;
+       struct gpiobus_attach_args gba;
+#endif
+       
+       sc->sc_dev = self;
+       
+       if (device_unit(sc->sc_dev) > 1) {
+               aprint_naive(" NO GPIO\n");     
+               aprint_normal(": NO GPIO\n");
+               return;
+       } else if (device_unit(sc->sc_dev) == 1) {
+               maxpin = 53;
+               minpin = 32;
+       } else {
+               maxpin = 31;
+               minpin = 0;
+       }
+       
+       aprint_naive("\n");     
+       aprint_normal(": GPIO [%d...%d]\n", minpin, maxpin);
+
+       /* already mapped - nothing to gain from struct amba_attach_args */
+       sc->sc_iot = &bcm2835_bs_tag;
+       sc->sc_ioh = BCM2835_IOPHYSTOVIRT(BCM2835_GPIO_BASE);
+       
+#if NGPIO > 0
+       for (pin = minpin; pin <= maxpin; pin++) {
+               int epin = pin - minpin;
+       
+               sc->sc_gpio_pins[epin].pin_num = epin;
+               /*
+                * find out pins still available for GPIO
+                */
+               func = bcm2835gpio_function_read(pin);
+               
+               if (func == BCM2835_GPIO_IN ||
+                   func == BCM2835_GPIO_OUT) {
+                       sc->sc_gpio_pins[epin].pin_caps = GPIO_PIN_INPUT |
+                               GPIO_PIN_OUTPUT |
+                               GPIO_PIN_PUSHPULL | GPIO_PIN_TRISTATE |
+                               GPIO_PIN_PULLUP | GPIO_PIN_PULLDOWN;
+                       /* read initial state */
+                       sc->sc_gpio_pins[epin].pin_state =
+                               bcm2835gpio_gpio_pin_read(sc, epin);
+                       DPRINTF(1, ("%s: attach pin %d\n", device_xname(sc->sc_dev), pin));
+                } else {
+                       sc->sc_gpio_pins[epin].pin_caps = 0;
+                       sc->sc_gpio_pins[epin].pin_state = 0;
+                       DPRINTF(1, ("%s: skip pin %d - func = 0x%x\n", device_xname(sc->sc_dev), pin, func));
+                }
+        }
+       
+       /* create controller tag */
+       sc->sc_gpio_gc.gp_cookie = sc;
+       sc->sc_gpio_gc.gp_pin_read = bcm2835gpio_gpio_pin_read;
+       sc->sc_gpio_gc.gp_pin_write = bcm2835gpio_gpio_pin_write;
+       sc->sc_gpio_gc.gp_pin_ctl = bcm2835gpio_gpio_pin_ctl;
+       
+       gba.gba_gc = &sc->sc_gpio_gc;
+       gba.gba_pins = sc->sc_gpio_pins;
+       gba.gba_npins = maxpin - minpin + 1;
+
+       config_found_ia(self, "gpiobus", &gba, gpiobus_print);
+#else
+       aprint_normal_dev(sc->sc_dev, "no GPIO configured in kernel");
+#endif
+}
+



Home | Main Index | Thread Index | Old Index