Module Name:    src
Committed By:   jmcneill
Date:           Sun Nov  7 17:13:12 UTC 2021

Modified Files:
        src/sys/arch/arm/sunxi: files.sunxi sunxi_ccu.c sunxi_ccu.h
Added Files:
        src/sys/arch/arm/sunxi: sunxi_ccu_mux.c

Log Message:
sunxi: ccu: add support for basic "mux" clocks


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/arm/sunxi/files.sunxi
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/arm/sunxi/sunxi_ccu.c
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/arm/sunxi/sunxi_ccu.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/sunxi/sunxi_ccu_mux.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/sunxi/files.sunxi
diff -u src/sys/arch/arm/sunxi/files.sunxi:1.69 src/sys/arch/arm/sunxi/files.sunxi:1.70
--- src/sys/arch/arm/sunxi/files.sunxi:1.69	Wed May  5 10:24:04 2021
+++ src/sys/arch/arm/sunxi/files.sunxi	Sun Nov  7 17:13:12 2021
@@ -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_div.c		sun
 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

Index: src/sys/arch/arm/sunxi/sunxi_ccu.c
diff -u src/sys/arch/arm/sunxi/sunxi_ccu.c:1.13 src/sys/arch/arm/sunxi/sunxi_ccu.c:1.14
--- src/sys/arch/arm/sunxi/sunxi_ccu.c:1.13	Thu Nov 29 20:33:09 2018
+++ src/sys/arch/arm/sunxi/sunxi_ccu.c	Sun Nov  7 17:13:12 2021
@@ -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 <jmcne...@invisible.ca>
@@ -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 @@ sunxi_ccu_print(struct sunxi_ccu_softc *
 		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;
 		}
 

Index: src/sys/arch/arm/sunxi/sunxi_ccu.h
diff -u src/sys/arch/arm/sunxi/sunxi_ccu.h:1.22 src/sys/arch/arm/sunxi/sunxi_ccu.h:1.23
--- src/sys/arch/arm/sunxi/sunxi_ccu.h:1.22	Sat Nov 23 03:59:39 2019
+++ src/sys/arch/arm/sunxi/sunxi_ccu.h	Sun Nov  7 17:13:12 2021
@@ -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 <jmcne...@invisible.ca>
@@ -64,6 +64,7 @@ enum sunxi_ccu_clktype {
 	SUNXI_CCU_PHASE,
 	SUNXI_CCU_FIXED_FACTOR,
 	SUNXI_CCU_FRACTIONAL,
+	SUNXI_CCU_MUX,
 };
 
 struct sunxi_ccu_gate {
@@ -413,6 +414,34 @@ const char *sunxi_ccu_fractional_get_par
 		.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_clk {
 		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 *,

Added files:

Index: src/sys/arch/arm/sunxi/sunxi_ccu_mux.c
diff -u /dev/null src/sys/arch/arm/sunxi/sunxi_ccu_mux.c:1.1
--- /dev/null	Sun Nov  7 17:13:12 2021
+++ src/sys/arch/arm/sunxi/sunxi_ccu_mux.c	Sun Nov  7 17:13:12 2021
@@ -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 <jmcne...@invisible.ca>
+ * 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];
+}

Reply via email to