Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Add drivers for DE2 bus and clock controllers.



details:   https://anonhg.NetBSD.org/src/rev/acac29551e6f
branches:  trunk
changeset: 447742:acac29551e6f
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Tue Jan 22 20:17:36 2019 +0000

description:
Add drivers for DE2 bus and clock controllers.

diffstat:

 sys/arch/arm/sunxi/files.sunxi     |   12 +++-
 sys/arch/arm/sunxi/sunxi_de2.c     |   72 +++++++++++++++++++++
 sys/arch/arm/sunxi/sunxi_de2_ccu.c |  126 +++++++++++++++++++++++++++++++++++++
 sys/arch/arm/sunxi/sunxi_de2_ccu.h |   46 +++++++++++++
 sys/arch/evbarm/conf/GENERIC64     |    4 +-
 5 files changed, 258 insertions(+), 2 deletions(-)

diffs (truncated from 308 to 300 lines):

diff -r 7933ea85b4d5 -r acac29551e6f sys/arch/arm/sunxi/files.sunxi
--- a/sys/arch/arm/sunxi/files.sunxi    Tue Jan 22 18:39:49 2019 +0000
+++ b/sys/arch/arm/sunxi/files.sunxi    Tue Jan 22 20:17:36 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.sunxi,v 1.59 2019/01/03 14:44:21 jmcneill Exp $
+#      $NetBSD: files.sunxi,v 1.60 2019/01/22 20:17:36 jmcneill Exp $
 #
 # Configuration info for Allwinner sunxi family SoCs
 #
@@ -297,6 +297,16 @@
 attach sunxilradc at fdt with sunxi_lradc
 file   arch/arm/sunxi/sunxi_lradc.c            sunxi_lradc
 
+# DE2 bus
+device sunxide2bus { }: fdt, sunxi_sramc
+attach sunxide2bus at fdt with sunxi_de2bus
+file   arch/arm/sunxi/sunxi_de2.c              sunxi_de2bus
+
+# DE2 clocks
+device sunxide2ccu: sunxi_ccu
+attach sunxide2ccu at fdt with sunxi_de2ccu
+file   arch/arm/sunxi/sunxi_de2_ccu.c          sunxi_de2ccu
+
 # SOC parameters
 defflag        opt_soc.h                       SOC_SUNXI
 defflag        opt_soc.h                       SOC_SUNXI_MC
diff -r 7933ea85b4d5 -r acac29551e6f sys/arch/arm/sunxi/sunxi_de2.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/sunxi/sunxi_de2.c    Tue Jan 22 20:17:36 2019 +0000
@@ -0,0 +1,72 @@
+/* $NetBSD: sunxi_de2.c,v 1.1 2019/01/22 20:17:36 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2019 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: sunxi_de2.c,v 1.1 2019/01/22 20:17:36 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/cpu.h>
+#include <sys/device.h>
+#include <sys/kmem.h>
+
+#include <dev/fdt/fdtvar.h>
+
+#include <arm/sunxi/sunxi_sramc.h>
+
+static const char * compatible[] = {
+       "allwinner,sun50i-a64-de2",
+       NULL
+};
+
+static int
+sunxi_de2_match(device_t parent, cfdata_t cf, void *aux)
+{
+       struct fdt_attach_args * const faa = aux;
+
+       return of_match_compatible(faa->faa_phandle, compatible);
+}
+
+static void
+sunxi_de2_attach(device_t parent, device_t self, void *aux)
+{
+       struct fdt_attach_args * const faa = aux;
+       const int phandle = faa->faa_phandle;
+
+       if (sunxi_sramc_claim(phandle) != 0) {
+               aprint_error(": cannot map SRAM to DE2\n");
+               return;
+       }
+
+       aprint_naive("\n");
+       aprint_normal(": DE2 Bus\n");
+
+       fdt_add_bus(self, phandle, faa);
+}
+
+CFATTACH_DECL_NEW(sunxi_de2bus, 0, sunxi_de2_match, sunxi_de2_attach, NULL, NULL);
diff -r 7933ea85b4d5 -r acac29551e6f sys/arch/arm/sunxi/sunxi_de2_ccu.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/sunxi/sunxi_de2_ccu.c        Tue Jan 22 20:17:36 2019 +0000
@@ -0,0 +1,126 @@
+/* $NetBSD: sunxi_de2_ccu.c,v 1.1 2019/01/22 20:17:36 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2019 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(1, "$NetBSD: sunxi_de2_ccu.c,v 1.1 2019/01/22 20:17:36 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/device.h>
+#include <sys/systm.h>
+
+#include <dev/fdt/fdtvar.h>
+
+#include <arm/sunxi/sunxi_ccu.h>
+#include <arm/sunxi/sunxi_de2_ccu.h>
+
+static int sunxi_de2_ccu_match(device_t, cfdata_t, void *);
+static void sunxi_de2_ccu_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(sunxi_de2ccu, sizeof(struct sunxi_ccu_softc),
+       sunxi_de2_ccu_match, sunxi_de2_ccu_attach, NULL, NULL);
+
+static struct sunxi_ccu_reset sun50i_a64_de2_ccu_resets[] = {
+       SUNXI_CCU_RESET(DE2_RST_MIXER0, 0x08, 0),
+       SUNXI_CCU_RESET(DE2_RST_MIXER1, 0x08, 1),
+       SUNXI_CCU_RESET(DE2_RST_WB, 0x08, 2),
+};
+
+static const char *mod_parents[] = { "mod" };
+
+static struct sunxi_ccu_clk sun50i_a64_de2_ccu_clks[] = {
+       SUNXI_CCU_GATE(DE2_CLK_BUS_MIXER0, "bus-mixer0", "bus", 0x04, 0),
+       SUNXI_CCU_GATE(DE2_CLK_BUS_MIXER1, "bus-mixer1", "bus", 0x04, 1),
+       SUNXI_CCU_GATE(DE2_CLK_BUS_WB, "bus-wb", "bus", 0x04, 2),
+
+       SUNXI_CCU_DIV(DE2_CLK_MIXER0_DIV, "mixer0-div", mod_parents,
+           0x0c, __BITS(3,0), 0, SUNXI_CCU_DIV_SET_RATE_PARENT),
+       SUNXI_CCU_DIV(DE2_CLK_MIXER1_DIV, "mixer1-div", mod_parents,
+           0x0c, __BITS(7,4), 0, SUNXI_CCU_DIV_SET_RATE_PARENT),
+       SUNXI_CCU_DIV(DE2_CLK_WB_DIV, "wb-div", mod_parents,
+           0x0c, __BITS(11,8), 0, SUNXI_CCU_DIV_SET_RATE_PARENT),
+
+       SUNXI_CCU_GATE(DE2_CLK_MIXER0, "mixer0", "mixer0-div", 0x00, 0),
+       SUNXI_CCU_GATE(DE2_CLK_MIXER1, "mixer1", "mixer1-div", 0x00, 1),
+       SUNXI_CCU_GATE(DE2_CLK_WB, "wb", "wb-div", 0x00, 2),
+};
+
+struct sunxi_de2_ccu_config {
+       struct sunxi_ccu_reset  *resets;
+       u_int                   nresets;
+       struct sunxi_ccu_clk    *clks;
+       u_int                   nclks;
+};
+
+static const struct sunxi_de2_ccu_config sun50i_a64_de2_config = {
+       .resets = sun50i_a64_de2_ccu_resets,
+       .nresets = __arraycount(sun50i_a64_de2_ccu_resets),
+       .clks = sun50i_a64_de2_ccu_clks,
+       .nclks = __arraycount(sun50i_a64_de2_ccu_clks),
+};
+
+static const struct of_compat_data compat_data[] = {
+       { "allwinner,sun50i-a64-de2-clk",       (uintptr_t)&sun50i_a64_de2_config },
+       { NULL }
+};
+
+static int
+sunxi_de2_ccu_match(device_t parent, cfdata_t cf, void *aux)
+{
+       struct fdt_attach_args * const faa = aux;
+
+       return of_match_compat_data(faa->faa_phandle, compat_data);
+}
+
+static void
+sunxi_de2_ccu_attach(device_t parent, device_t self, void *aux)
+{
+       struct sunxi_ccu_softc * const sc = device_private(self);
+       struct fdt_attach_args * const faa = aux;
+       const struct sunxi_de2_ccu_config *conf;
+
+       sc->sc_dev = self;
+       sc->sc_phandle = faa->faa_phandle;
+       sc->sc_bst = faa->faa_bst;
+
+       conf = (void *)of_search_compatible(faa->faa_phandle, compat_data)->data;
+
+       sc->sc_resets = conf->resets;
+       sc->sc_nresets = conf->nresets;
+       sc->sc_clks = conf->clks;
+       sc->sc_nclks = conf->nclks;
+
+       if (sunxi_ccu_attach(sc) != 0)
+               return;
+
+       aprint_naive("\n");
+       aprint_normal(": DE2 CCU\n");
+
+       sunxi_ccu_print(sc);
+}
diff -r 7933ea85b4d5 -r acac29551e6f sys/arch/arm/sunxi/sunxi_de2_ccu.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/sunxi/sunxi_de2_ccu.h        Tue Jan 22 20:17:36 2019 +0000
@@ -0,0 +1,46 @@
+/* $NetBSD: sunxi_de2_ccu.h,v 1.1 2019/01/22 20:17:36 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2019 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.
+ */
+
+#ifndef _ARM_SUNXI_DE2_CCU_H
+#define _ARM_SUNXI_DE2_CCU_H
+
+#define        DE2_RST_MIXER0                  0
+#define        DE2_RST_MIXER1                  1
+#define        DE2_RST_WB                      2
+
+#define        DE2_CLK_BUS_MIXER0              0
+#define        DE2_CLK_BUS_MIXER1              1
+#define        DE2_CLK_BUS_WB                  2
+#define        DE2_CLK_MIXER0_DIV              3
+#define        DE2_CLK_MIXER1_DIV              4
+#define        DE2_CLK_WB_DIV                  5
+#define        DE2_CLK_MIXER0                  6
+#define        DE2_CLK_MIXER1                  7
+#define        DE2_CLK_WB                      8
+
+#endif /* _ARM_SUNXI_DE2_CCU_H */
diff -r 7933ea85b4d5 -r acac29551e6f sys/arch/evbarm/conf/GENERIC64
--- a/sys/arch/evbarm/conf/GENERIC64    Tue Jan 22 18:39:49 2019 +0000
+++ b/sys/arch/evbarm/conf/GENERIC64    Tue Jan 22 20:17:36 2019 +0000
@@ -1,5 +1,5 @@
 #
-#      $NetBSD: GENERIC64,v 1.74 2019/01/22 16:36:07 jmcneill Exp $
+#      $NetBSD: GENERIC64,v 1.75 2019/01/22 20:17:36 jmcneill Exp $
 #
 #      GENERIC ARM (aarch64) kernel
 #
@@ -192,6 +192,7 @@
 sun50ia64rccu* at fdt? pass 2          # Allwinner A64 CCU (PRCM)
 sun50ih6ccu*   at fdt? pass 2          # Allwinner H6 CCU
 sun50ih6rccu*  at fdt? pass 2          # Allwinner H6 CCU (PRCM)
+sunxide2ccu*   at fdt? pass 2          # Allwinner DE2 clock controller
 sunxiresets*   at fdt? pass 1          # Allwinner misc. resets
 sunxigates*    at fdt? pass 1          # Allwinner misc. gates
 sunxigmacclk*  at fdt? pass 2          # Allwinner GMAC MII/RGMII clock mux



Home | Main Index | Thread Index | Old Index