Source-Changes-HG archive

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

[src/netbsd-6]: src/sys/arch sys/arch/arm/broadcom/bcm2835_emmc.c patch



details:   https://anonhg.NetBSD.org/src/rev/b47f4a4cb277
branches:  netbsd-6
changeset: 775460:b47f4a4cb277
user:      riz <riz%NetBSD.org@localhost>
date:      Mon Nov 19 19:12:57 2012 +0000

description:
sys/arch/arm/broadcom/bcm2835_emmc.c            patch
sys/arch/arm/broadcom/bcm2835reg.h              patch
sys/arch/arm/broadcom/bcm2835_mbox.h            1.1-1.3 via patch
sys/arch/arm/broadcom/bcm2835_mbox_subr.c       1.1-1.3 via patch
sys/arch/arm/broadcom/bcm2835_mboxreg.h         1.1 via patch
sys/arch/arm/broadcom/files.bcm2835             patch
sys/arch/evbarm/rpi/rpi_machdep.c               patch
sys/arch/evbarm/rpi/rpi_start.S                 patch
sys/arch/evbarm/rpi/vcio.h                      1.1 via patch
sys/arch/evbarm/rpi/vcprop.h                    1.1-1.2 via patch

        Improve Raspberry PI support: memory layout and clock for the
        sdhc(4) controller are queried via the mailbox properties
        channel.
        [skrll, ticket #660]

diffstat:

 sys/arch/arm/broadcom/bcm2835_emmc.c      |   16 +-
 sys/arch/arm/broadcom/bcm2835_mbox.h      |   45 ++++++
 sys/arch/arm/broadcom/bcm2835_mbox_subr.c |  107 ++++++++++++++++
 sys/arch/arm/broadcom/bcm2835_mboxreg.h   |   75 +++++++++++
 sys/arch/arm/broadcom/bcm2835reg.h        |    5 +-
 sys/arch/arm/broadcom/files.bcm2835       |    3 +-
 sys/arch/evbarm/rpi/rpi_machdep.c         |  194 +++++++++++++++++++++++++++--
 sys/arch/evbarm/rpi/rpi_start.S           |   15 +-
 sys/arch/evbarm/rpi/vcio.h                |   45 ++++++
 sys/arch/evbarm/rpi/vcprop.h              |  178 +++++++++++++++++++++++++++
 10 files changed, 657 insertions(+), 26 deletions(-)

diffs (truncated from 891 to 300 lines):

diff -r 989aa3894388 -r b47f4a4cb277 sys/arch/arm/broadcom/bcm2835_emmc.c
--- a/sys/arch/arm/broadcom/bcm2835_emmc.c      Mon Nov 19 18:46:12 2012 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_emmc.c      Mon Nov 19 19:12:57 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bcm2835_emmc.c,v 1.1.2.2 2012/08/09 06:36:49 jdc Exp $ */
+/*     $NetBSD: bcm2835_emmc.c,v 1.1.2.3 2012/11/19 19:12:57 riz Exp $ */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_emmc.c,v 1.1.2.2 2012/08/09 06:36:49 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_emmc.c,v 1.1.2.3 2012/11/19 19:12:57 riz Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -77,7 +77,9 @@
 bcmemmc_attach(device_t parent, device_t self, void *aux)
 {
        struct bcmemmc_softc *sc = device_private(self);
+       prop_dictionary_t dict = device_properties(self);
        struct amba_attach_args *aaa = aux;
+       prop_number_t frequency;
        int error;
 
        sc->sc.sc_dev = self;
@@ -88,9 +90,15 @@
        sc->sc.sc_flags |= SDHC_FLAG_HOSTCAPS;
        sc->sc.sc_caps = SDHC_VOLTAGE_SUPP_3_3V;
        sc->sc.sc_host = sc->sc_hosts;
-       sc->sc.sc_clkbase = 50000;      /* 50MHz */
+       sc->sc.sc_clkbase = 50000;      /* Default to 50MHz */
        sc->sc_iot = aaa->aaa_iot;
 
+       /* Fetch the EMMC clock frequency from property if set. */
+       frequency = prop_dictionary_get(dict, "frequency");
+       if (frequency != NULL) {
+               sc->sc.sc_clkbase = prop_number_integer_value(frequency) / 1000;
+       }    
+       
        error = bus_space_map(sc->sc_iot, aaa->aaa_addr, aaa->aaa_size, 0,
            &sc->sc_ioh);
        if (error) {
@@ -107,7 +115,7 @@
 
        if (sc->sc_ih == NULL) {
                aprint_error_dev(self, "failed to establish interrupt %d\n",
-                    aaa->aaa_intr);
+                   aaa->aaa_intr);
                goto fail;
        }
        aprint_normal_dev(self, "interrupting on intr %d\n", aaa->aaa_intr);
diff -r 989aa3894388 -r b47f4a4cb277 sys/arch/arm/broadcom/bcm2835_mbox.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_mbox.h      Mon Nov 19 19:12:57 2012 +0000
@@ -0,0 +1,45 @@
+/*     $NetBSD: bcm2835_mbox.h,v 1.3.4.2 2012/11/19 19:12:58 riz Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nick Hudson
+ *
+ * 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 NETBSD FOUNDATION, INC. 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.
+ */
+
+#ifndef _BCM2835_MBOX_H_
+#define        _BCM2835_MBOX_H_
+
+#include <sys/bus.h>
+
+void bcm2835_mbox_read(bus_space_tag_t, bus_space_handle_t, uint8_t,
+    uint32_t *);
+void bcm2835_mbox_write(bus_space_tag_t, bus_space_handle_t, uint8_t,
+    uint32_t);
+
+void bcmmbox_read(uint8_t, uint32_t *);
+void bcmmbox_write(uint8_t, uint32_t);
+
+#endif /* _BCM2835_MBOX_H_ */
diff -r 989aa3894388 -r b47f4a4cb277 sys/arch/arm/broadcom/bcm2835_mbox_subr.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_mbox_subr.c Mon Nov 19 19:12:57 2012 +0000
@@ -0,0 +1,107 @@
+/*     $NetBSD: bcm2835_mbox_subr.c,v 1.3.4.2 2012/11/19 19:12:58 riz Exp $    */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nick Hudson
+ *
+ * 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 NETBSD FOUNDATION, INC. 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_mbox_subr.c,v 1.3.4.2 2012/11/19 19:12:58 riz Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/kernel.h>
+#include <sys/timetc.h>
+#include <sys/bus.h>
+
+#include <arm/broadcom/bcm_amba.h>
+#include <arm/broadcom/bcm2835_mbox.h>
+#include <arm/broadcom/bcm2835_mboxreg.h>
+#include <arm/broadcom/bcm2835reg.h>
+
+
+#define        BCM2835_MBOX_CHAN(chan) ((chan) & 0xf)
+#define        BCM2835_MBOX_DATA(data) ((data) & ~0xf)
+
+#define        BCM2835_MBOX_MSG(chan, data) (((chan) & 0xf) | ((data) & ~0xf))
+
+void
+bcm2835_mbox_read(bus_space_tag_t iot, bus_space_handle_t ioh, uint8_t chan,
+    uint32_t *data)
+{
+       uint32_t mbox;
+
+       KASSERT((chan & 0xf) == chan);
+
+       for (;;) {
+               uint8_t rchan;
+               uint32_t rdata;
+
+               bus_space_barrier(iot, ioh, 0, BCM2835_MBOX_SIZE,
+                   BUS_SPACE_BARRIER_READ);
+
+               if ((bus_space_read_4(iot, ioh,
+                   BCM2835_MBOX0_STATUS) & BCM2835_MBOX_STATUS_EMPTY) != 0)
+                       continue;
+
+               mbox = bus_space_read_4(iot, ioh, BCM2835_MBOX0_READ);
+
+               rchan = BCM2835_MBOX_CHAN(mbox);
+               rdata = BCM2835_MBOX_DATA(mbox);
+
+               if (rchan == chan) {
+                       *data = rdata;
+                       return;
+               }
+       }
+}
+
+void
+bcm2835_mbox_write(bus_space_tag_t iot, bus_space_handle_t ioh, uint8_t chan,
+    uint32_t data)
+{
+       uint32_t rdata;
+
+       KASSERT((chan & 0xf) == chan);
+       KASSERT((data & 0xf) == 0);
+       for (;;) {
+
+               bus_space_barrier(iot, ioh, 0, BCM2835_MBOX_SIZE,
+                   BUS_SPACE_BARRIER_READ);
+
+               if ((rdata = bus_space_read_4(iot, ioh,
+                   BCM2835_MBOX0_STATUS) & BCM2835_MBOX_STATUS_FULL) == 0)
+                       break;
+       }
+
+       bus_space_write_4(iot, ioh, BCM2835_MBOX1_WRITE,
+           BCM2835_MBOX_MSG(chan, data));
+
+       bus_space_barrier(iot, ioh, 0, BCM2835_MBOX_SIZE,
+           BUS_SPACE_BARRIER_WRITE);
+}
diff -r 989aa3894388 -r b47f4a4cb277 sys/arch/arm/broadcom/bcm2835_mboxreg.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_mboxreg.h   Mon Nov 19 19:12:57 2012 +0000
@@ -0,0 +1,75 @@
+/*     $NetBSD: bcm2835_mboxreg.h,v 1.1.6.2 2012/11/19 19:12:59 riz Exp $      */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nick Hudson
+ *
+ * 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 NETBSD FOUNDATION, INC. 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.
+ */
+
+#ifndef _BCM2835_MBOXREG_H_
+#define        _BCM2835_MBOXREG_H_
+
+/* mailbox 0 (from VC) and mailbox 1 (to VC) */
+#define        BCM2835_MBOX_SIZE       0x80
+
+#define        BCM2835_MBOX_READ       0x00
+#define        BCM2835_MBOX_WRITE      0x00
+#define        BCM2835_MBOX_POLL       0x10    /* read without popping the fifo */
+#define        BCM2835_MBOX_ID         0x14    /* sender ID (bottom two bits) */
+#define        BCM2835_MBOX_STATUS     0x18    /* status */
+#define         BCM2835_MBOX_STATUS_FULL       0x80000000
+#define         BCM2835_MBOX_STATUS_EMPTY      0x40000000
+#define         BCM2835_MBOX_STATUS_LEVEL      0x400000FF
+#define        BCM2835_MBOX_CFG        0x1C    /* configuration */
+#define         BCM2835_MBOX_CFG_DATAIRQEN             0x00000001
+#define         BCM2835_MBOX_CFG_SPACEIRQEN            0x00000002
+#define         BCM2835_MBOX_CFG_EMPTYOPIRQEN          0x00000004
+#define         BCM2835_MBOX_CFG_MAILCLEAR             0x00000008
+#define         BCM2835_MBOX_CFG_DATAPENDING           0x00000010
+#define         BCM2835_MBOX_CFG_SPACEPENDING          0x00000020
+#define         BCM2835_MBOX_CFG_EMPTYOPPENDING        0x00000040
+#define         BCM2835_MBOX_CFG_ENOOWN                0x00000100
+#define         BCM2835_MBOX_CFG_EOVERFLOW             0x00000200
+#define         BCM2835_MBOX_CFG_EUNDERFLOW            0x00000400
+
+#define        BCM2835_MBOX0_BASE      0x00
+#define        BCM2835_MBOX1_BASE      0x20
+
+#define        BCM2835_MBOX0_READ      (BCM2835_MBOX0_BASE + BCM2835_MBOX_READ)
+#define        BCM2835_MBOX0_WRITE     (BCM2835_MBOX0_BASE + BCM2835_MBOX_WRITE)
+#define        BCM2835_MBOX0_POLL      (BCM2835_MBOX0_BASE + BCM2835_MBOX_POLL)
+#define        BCM2835_MBOX0_ID        (BCM2835_MBOX0_BASE + BCM2835_MBOX_ID)
+#define        BCM2835_MBOX0_STATUS    (BCM2835_MBOX0_BASE + BCM2835_MBOX_STATUS)
+#define        BCM2835_MBOX0_CFG       (BCM2835_MBOX0_BASE + BCM2835_MBOX_READ)
+
+#define        BCM2835_MBOX1_READ      (BCM2835_MBOX1_BASE + BCM2835_MBOX_READ)
+#define        BCM2835_MBOX1_WRITE     (BCM2835_MBOX1_BASE + BCM2835_MBOX_WRITE)
+#define        BCM2835_MBOX1_POLL      (BCM2835_MBOX1_BASE + BCM2835_MBOX_POLL)
+#define        BCM2835_MBOX1_ID        (BCM2835_MBOX1_BASE + BCM2835_MBOX_ID)
+#define        BCM2835_MBOX1_STATUS    (BCM2835_MBOX1_BASE + BCM2835_MBOX_STATUS)
+#define        BCM2835_MBOX1_CFG       (BCM2835_MBOX1_BASE + BCM2835_MBOX_READ)
+
+#endif /* _BCM2835_MBOXREG_H_ */
diff -r 989aa3894388 -r b47f4a4cb277 sys/arch/arm/broadcom/bcm2835reg.h
--- a/sys/arch/arm/broadcom/bcm2835reg.h        Mon Nov 19 18:46:12 2012 +0000
+++ b/sys/arch/arm/broadcom/bcm2835reg.h        Mon Nov 19 19:12:57 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bcm2835reg.h,v 1.1.2.2 2012/08/09 06:36:50 jdc Exp $   */
+/*     $NetBSD: bcm2835reg.h,v 1.1.2.3 2012/11/19 19:12:59 riz Exp $   */
 



Home | Main Index | Thread Index | Old Index