Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm/sunxi sunxi: ccu: add support for basic "mux" c...



details:   https://anonhg.NetBSD.org/src/rev/5ff08093576d
branches:  trunk
changeset: 1024865:5ff08093576d
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Nov 07 17:13:12 2021 +0000

description:
sunxi: ccu: add support for basic "mux" clocks

diffstat:

 sys/arch/arm/sunxi/files.sunxi     |   3 +-
 sys/arch/arm/sunxi/sunxi_ccu.c     |   5 +-
 sys/arch/arm/sunxi/sunxi_ccu.h     |  32 ++++++++++++++-
 sys/arch/arm/sunxi/sunxi_ccu_mux.c |  82 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 118 insertions(+), 4 deletions(-)

diffs (189 lines):

diff -r 400dfcf3d10c -r 5ff08093576d sys/arch/arm/sunxi/files.sunxi
--- a/sys/arch/arm/sunxi/files.sunxi    Sun Nov 07 17:12:55 2021 +0000
+++ b/sys/arch/arm/sunxi/files.sunxi    Sun Nov 07 17:13:12 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.sunxi,v 1.69 2021/05/05 10:24:04 jmcneill Exp $
+#      $NetBSD: files.sunxi,v 1.70 2021/11/07 17:13:12 jmcneill Exp $
 #
 # Configuration info for Allwinner sunxi family SoCs
 #
@@ -16,6 +16,7 @@
 file   arch/arm/sunxi/sunxi_ccu_fixed_factor.c sunxi_ccu
 file   arch/arm/sunxi/sunxi_ccu_fractional.c   sunxi_ccu
 file   arch/arm/sunxi/sunxi_ccu_gate.c         sunxi_ccu
+file   arch/arm/sunxi/sunxi_ccu_mux.c          sunxi_ccu
 file   arch/arm/sunxi/sunxi_ccu_nm.c           sunxi_ccu
 file   arch/arm/sunxi/sunxi_ccu_nkmp.c         sunxi_ccu
 file   arch/arm/sunxi/sunxi_ccu_phase.c        sunxi_ccu
diff -r 400dfcf3d10c -r 5ff08093576d sys/arch/arm/sunxi/sunxi_ccu.c
--- a/sys/arch/arm/sunxi/sunxi_ccu.c    Sun Nov 07 17:12:55 2021 +0000
+++ b/sys/arch/arm/sunxi/sunxi_ccu.c    Sun Nov 07 17:13:12 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_ccu.c,v 1.13 2018/11/29 20:33:09 jakllsch Exp $ */
+/* $NetBSD: sunxi_ccu.c,v 1.14 2021/11/07 17:13:12 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -31,7 +31,7 @@
 #include "opt_console.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunxi_ccu.c,v 1.13 2018/11/29 20:33:09 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_ccu.c,v 1.14 2021/11/07 17:13:12 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -359,6 +359,7 @@
                case SUNXI_CCU_PHASE:           type = "phase"; break;
                case SUNXI_CCU_FIXED_FACTOR:    type = "fixed-factor"; break;
                case SUNXI_CCU_FRACTIONAL:      type = "fractional"; break;
+               case SUNXI_CCU_MUX:             type = "mux"; break;
                default:                        type = "???"; break;
                }
 
diff -r 400dfcf3d10c -r 5ff08093576d sys/arch/arm/sunxi/sunxi_ccu.h
--- a/sys/arch/arm/sunxi/sunxi_ccu.h    Sun Nov 07 17:12:55 2021 +0000
+++ b/sys/arch/arm/sunxi/sunxi_ccu.h    Sun Nov 07 17:13:12 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_ccu.h,v 1.22 2019/11/23 03:59:39 jakllsch Exp $ */
+/* $NetBSD: sunxi_ccu.h,v 1.23 2021/11/07 17:13:12 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -64,6 +64,7 @@
        SUNXI_CCU_PHASE,
        SUNXI_CCU_FIXED_FACTOR,
        SUNXI_CCU_FRACTIONAL,
+       SUNXI_CCU_MUX,
 };
 
 struct sunxi_ccu_gate {
@@ -413,6 +414,34 @@
                .get_parent = sunxi_ccu_fractional_get_parent,          \
        }
 
+struct sunxi_ccu_mux {
+       bus_size_t      reg;
+       const char      **parents;
+       u_int           nparents;
+       uint32_t        sel;
+       uint32_t        flags;
+};
+
+int    sunxi_ccu_mux_set_parent(struct sunxi_ccu_softc *,
+                                struct sunxi_ccu_clk *,
+                                const char *);
+const char *sunxi_ccu_mux_get_parent(struct sunxi_ccu_softc *,
+                                    struct sunxi_ccu_clk *);
+
+#define        SUNXI_CCU_MUX(_id, _name, _parents, _reg, _sel, _flags) \
+       [_id] = {                                               \
+               .type = SUNXI_CCU_MUX,                          \
+               .base.name = (_name),                           \
+               .u.mux.reg = (_reg),                            \
+               .u.mux.parents = (_parents),                    \
+               .u.mux.nparents = __arraycount(_parents),       \
+               .u.mux.sel = (_sel),                            \
+               .u.mux.flags = (_flags),                        \
+               .set_parent = sunxi_ccu_mux_set_parent,         \
+               .get_parent = sunxi_ccu_mux_get_parent,         \
+       }
+
+
 struct sunxi_ccu_clk {
        struct clk      base;
        enum sunxi_ccu_clktype type;
@@ -425,6 +454,7 @@
                struct sunxi_ccu_phase phase;
                struct sunxi_ccu_fixed_factor fixed_factor;
                struct sunxi_ccu_fractional fractional;
+               struct sunxi_ccu_mux mux;
        } u;
 
        int             (*enable)(struct sunxi_ccu_softc *,
diff -r 400dfcf3d10c -r 5ff08093576d sys/arch/arm/sunxi/sunxi_ccu_mux.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/sunxi/sunxi_ccu_mux.c        Sun Nov 07 17:13:12 2021 +0000
@@ -0,0 +1,82 @@
+/* $NetBSD: sunxi_ccu_mux.c,v 1.1 2021/11/07 17:13:12 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2021 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_ccu_mux.c,v 1.1 2021/11/07 17:13:12 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+
+#include <dev/clk/clk_backend.h>
+
+#include <arm/sunxi/sunxi_ccu.h>
+
+int
+sunxi_ccu_mux_set_parent(struct sunxi_ccu_softc *sc,
+    struct sunxi_ccu_clk *clk, const char *name)
+{
+       struct sunxi_ccu_mux *mux = &clk->u.mux;
+       uint32_t val;
+       u_int index;
+
+       KASSERT(clk->type == SUNXI_CCU_MUX);
+
+       if (mux->sel == 0)
+               return ENODEV;
+
+       for (index = 0; index < mux->nparents; index++) {
+               if (mux->parents[index] != NULL &&
+                   strcmp(mux->parents[index], name) == 0)
+                       break;
+       }
+       if (index == mux->nparents)
+               return EINVAL;
+
+       val = CCU_READ(sc, mux->reg);
+       val &= ~mux->sel;
+       val |= __SHIFTIN(index, mux->sel);
+       CCU_WRITE(sc, mux->reg, val);
+
+       return 0;
+}
+
+const char *
+sunxi_ccu_mux_get_parent(struct sunxi_ccu_softc *sc,
+    struct sunxi_ccu_clk *clk)
+{
+       struct sunxi_ccu_mux *mux = &clk->u.mux;
+       u_int index;
+       uint32_t val;
+
+       KASSERT(clk->type == SUNXI_CCU_MUX);
+
+       val = CCU_READ(sc, mux->reg);
+       index = __SHIFTOUT(val, mux->sel);
+
+       return mux->parents[index];
+}



Home | Main Index | Thread Index | Old Index