CVS commit: src/sys/arch/arm/sunxi

2021-08-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug  7 15:41:01 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c

Log Message:
sun8icrypto(4): Call crypto_unblock when a task completes.

Otherwise under load this would presumably just hang after returning
ERESTART to opencrypto.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/arm/sunxi/sun8i_crypto.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/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.25 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.26
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.25	Wed Apr 28 16:57:05 2021
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Sat Aug  7 15:41:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.25 2021/04/28 16:57:05 bad Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.26 2021/08/07 15:41:00 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.25 2021/04/28 16:57:05 bad Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.26 2021/08/07 15:41:00 riastradh Exp $");
 
 #include 
 #include 
@@ -211,7 +211,7 @@ static void	sun8i_crypto_timeout(void *)
 static int	sun8i_crypto_intr(void *);
 static void	sun8i_crypto_schedule_worker(struct sun8i_crypto_softc *);
 static void	sun8i_crypto_worker(struct work *, void *);
-static void	sun8i_crypto_chan_done(struct sun8i_crypto_softc *, unsigned,
+static bool	sun8i_crypto_chan_done(struct sun8i_crypto_softc *, unsigned,
 		int);
 
 static int	sun8i_crypto_allocbuf(struct sun8i_crypto_softc *, size_t,
@@ -1051,6 +1051,7 @@ sun8i_crypto_worker(struct work *wk, voi
 	struct sun8i_crypto_softc *sc = cookie;
 	uint32_t done, esr, esr_chan;
 	unsigned i, now;
+	bool unblock = false;
 	int error;
 
 	/*
@@ -1084,7 +1085,8 @@ sun8i_crypto_worker(struct work *wk, voi
 			if ((sc->sc_chan[i].cc_task != NULL) &&
 			((now - sc->sc_chan[i].cc_starttime) >=
 SUN8I_CRYPTO_TIMEOUT))
-sun8i_crypto_chan_done(sc, i, ETIMEDOUT);
+unblock |= sun8i_crypto_chan_done(sc, i,
+ETIMEDOUT);
 			continue;
 		}
 
@@ -1112,11 +1114,23 @@ sun8i_crypto_worker(struct work *wk, voi
 		 * Notify the task of completion.  May release the lock
 		 * to invoke a callback.
 		 */
-		sun8i_crypto_chan_done(sc, i, error);
+		unblock |= sun8i_crypto_chan_done(sc, i, error);
 	}
 
 	/* All one; release the lock one last time.  */
 	mutex_exit(>sc_lock);
+
+	/*
+	 * If we cleared any channels, it is time to allow opencrypto
+	 * to issue new operations.  Asymmetric operations (which we
+	 * don't support, at the moment, but we could) and symmetric
+	 * operations (which we do) use the same task channels, so we
+	 * unblock both kinds.
+	 */
+	if (unblock) {
+		crypto_unblock(sc->sc_opencrypto.co_driverid,
+		CRYPTO_SYMQ|CRYPTO_ASYMQ);
+	}
 }
 
 /*
@@ -1125,7 +1139,7 @@ sun8i_crypto_worker(struct work *wk, voi
  *	Notify the callback for the task on channel i, if there is one,
  *	of the specified error, or 0 for success.
  */
-static void
+static bool
 sun8i_crypto_chan_done(struct sun8i_crypto_softc *sc, unsigned i, int error)
 {
 	struct sun8i_crypto_task *task;
@@ -1140,7 +1154,8 @@ sun8i_crypto_chan_done(struct sun8i_cryp
 	if ((task = sc->sc_chan[i].cc_task) == NULL) {
 		device_printf(sc->sc_dev, "channel %u: no task but error=%d\n",
 		i, error);
-		return;
+		/* We did not clear a channel.  */
+		return false;
 	}
 	sc->sc_chan[i].cc_task = NULL;
 
@@ -1183,6 +1198,9 @@ sun8i_crypto_chan_done(struct sun8i_cryp
 	SDT_PROBE2(sdt, sun8i_crypto, task, done,  task, error);
 	(*task->ct_callback)(sc, task, task->ct_cookie, error);
 	mutex_enter(>sc_lock);
+
+	/* We cleared a channel.  */
+	return true;
 }
 
 /*
@@ -1811,7 +1829,7 @@ sun8i_crypto_register1(struct sun8i_cryp
  *	Called by opencrypto to allocate a new session.  We don't keep
  *	track of sessions, since there are no persistent keys in the
  *	hardware that we take advantage of, so this only validates the
- *	crypto operations and returns a zero session id.
+ *	crypto operations and returns a dummy session id of 1.
  */
 static int
 sun8i_crypto_newsession(void *cookie, uint32_t *sidp, struct cryptoini *cri)
@@ -1823,7 +1841,7 @@ sun8i_crypto_newsession(void *cookie, ui
 
 	/*
 	 * No variation of rounds is supported here.  (XXX Unused and
-	 * unimplemented in opencrypto(9) altogether?
+	 * unimplemented in opencrypto(9) altogether?)
 	 */
 	if (cri->cri_rnd)
 		return EINVAL;



CVS commit: src/sys/arch/arm/sunxi

2021-07-31 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Jul 31 11:34:40 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sunxi_platform.c

Log Message:
sunxi_platform: declare UART FIFO sizes for SoCs we support


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/arm/sunxi/sunxi_platform.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/sunxi_platform.c
diff -u src/sys/arch/arm/sunxi/sunxi_platform.c:1.44 src/sys/arch/arm/sunxi/sunxi_platform.c:1.45
--- src/sys/arch/arm/sunxi/sunxi_platform.c:1.44	Fri Jul 30 12:46:46 2021
+++ src/sys/arch/arm/sunxi/sunxi_platform.c	Sat Jul 31 11:34:40 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_platform.c,v 1.44 2021/07/30 12:46:46 tnn Exp $ */
+/* $NetBSD: sunxi_platform.c,v 1.45 2021/07/31 11:34:40 tnn Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -31,7 +31,7 @@
 #include "opt_console.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_platform.c,v 1.44 2021/07/30 12:46:46 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_platform.c,v 1.45 2021/07/31 11:34:40 tnn Exp $");
 
 #include 
 #include 
@@ -241,11 +241,23 @@ sunxi_platform_device_register(device_t 
 
 	if (device_is_a(self, "com")) {
 		static const struct device_compatible_entry compat_data[] = {
-			{ .compat = "allwinner,sun7i-a20" },
+			{ .compat = "allwinner,sun4i-a10",	.value = 64 },
+			{ .compat = "allwinner,sun5i-a13",	.value = 64 },
+			{ .compat = "allwinner,sun6i-a31",	.value = 64 },
+			{ .compat = "allwinner,sun7i-a20",	.value = 64 },
+			{ .compat = "allwinner,sun8i-h2-plus",	.value = 64 },
+			{ .compat = "allwinner,sun8i-h3",	.value = 64 },
+			{ .compat = "allwinner,sun8i-a83t",	.value = 64 },
+			{ .compat = "allwinner,sun9i-a80",	.value = 64 },
+			{ .compat = "allwinner,sun50i-a64",	.value = 64 },
+			{ .compat = "allwinner,sun50i-h5",	.value = 64 },
+			{ .compat = "allwinner,sun50i-h6",	.value = 256 },
 			DEVICE_COMPAT_EOL
 		};
-		if (of_compatible_match(OF_finddevice("/"), compat_data))
-			prop_dictionary_set_uint(prop, "fifolen", 64);
+		const struct device_compatible_entry *dce =
+		of_compatible_lookup(OF_finddevice("/"), compat_data);
+		if (dce != NULL)
+			prop_dictionary_set_uint(prop, "fifolen", dce->value);
 	}
 }
 



CVS commit: src/sys/arch/arm/sunxi

2021-05-05 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed May  5 20:58:03 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sunxi_codec.c sunxi_codec.h

Log Message:
Fix GENERIC64 build


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/arm/sunxi/sunxi_codec.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sunxi/sunxi_codec.h

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/sunxi_codec.c
diff -u src/sys/arch/arm/sunxi/sunxi_codec.c:1.13 src/sys/arch/arm/sunxi/sunxi_codec.c:1.14
--- src/sys/arch/arm/sunxi/sunxi_codec.c:1.13	Wed May  5 10:24:04 2021
+++ src/sys/arch/arm/sunxi/sunxi_codec.c	Wed May  5 20:58:03 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_codec.c,v 1.13 2021/05/05 10:24:04 jmcneill Exp $ */
+/* $NetBSD: sunxi_codec.c,v 1.14 2021/05/05 20:58:03 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_codec.c,v 1.13 2021/05/05 10:24:04 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_codec.c,v 1.14 2021/05/05 20:58:03 jmcneill Exp $");
 
 #include 
 #include 
@@ -89,10 +89,10 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_codec.
 #define	AC_ADC_CNT(_sc)		((_sc)->sc_cfg->ADC_CNT)
 
 static const struct device_compatible_entry compat_data[] = {
-	A10_CODEC_COMPATDATA,
-	A31_CODEC_COMPATDATA,
-	H3_CODEC_COMPATDATA,
-	V3S_CODEC_COMPATDATA,
+	A10_CODEC_COMPATDATA
+	A31_CODEC_COMPATDATA
+	H3_CODEC_COMPATDATA
+	V3S_CODEC_COMPATDATA
 
 	DEVICE_COMPAT_EOL
 };

Index: src/sys/arch/arm/sunxi/sunxi_codec.h
diff -u src/sys/arch/arm/sunxi/sunxi_codec.h:1.7 src/sys/arch/arm/sunxi/sunxi_codec.h:1.8
--- src/sys/arch/arm/sunxi/sunxi_codec.h:1.7	Wed May  5 10:24:04 2021
+++ src/sys/arch/arm/sunxi/sunxi_codec.h	Wed May  5 20:58:03 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_codec.h,v 1.7 2021/05/05 10:24:04 jmcneill Exp $ */
+/* $NetBSD: sunxi_codec.h,v 1.8 2021/05/05 20:58:03 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -121,7 +121,7 @@ struct sunxi_codec_softc {
 extern const struct sunxi_codec_conf sun8i_h3_codecconf;
 #define	H3_CODEC_COMPATDATA		\
 	{ .compat = "allwinner,sun8i-h3-codec",\
-	  .data = _h3_codecconf }
+	  .data = _h3_codecconf },
 #else
 #define	H3_CODEC_COMPATDATA
 #endif
@@ -130,7 +130,7 @@ extern const struct sunxi_codec_conf sun
 extern const struct sunxi_codec_conf sun8i_v3s_codecconf;
 #define V3S_CODEC_COMPATDATA		\
 	{ .compat = "allwinner,sun8i-v3s-codec",			\
-	  .data = _v3s_codecconf }
+	  .data = _v3s_codecconf },
 #else
 #define V3S_CODEC_COMPATDATA
 #endif
@@ -140,11 +140,11 @@ extern const struct sunxi_codec_conf sun
 	{ .compat = "allwinner,sun4i-a10-codec",			\
 	  .data = _a10_codecconf }, \
 	{ .compat = "allwinner,sun7i-a20-codec",			\
-	  .data = _a10_codecconf }
+	  .data = _a10_codecconf },
 
 extern const struct sunxi_codec_conf sun6i_a31_codecconf;
 #define	A31_CODEC_COMPATDATA		\
 	{ .compat = "allwinner,sun6i-a31-codec",			\
-	  .data = _a31_codecconf }
+	  .data = _a31_codecconf },
 
 #endif /* !_ARM_SUNXI_CODEC_H */



CVS commit: src/sys/arch/arm/sunxi

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 16:07:43 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sunxi_emac.h

Log Message:
Align descriptors to 64 bytes instead of CACHE_LINE_SIZE (128) as all known
Allwinner SoCs with this part use 64-byte cache lines.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sunxi/sunxi_emac.h

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/sunxi_emac.h
diff -u src/sys/arch/arm/sunxi/sunxi_emac.h:1.4 src/sys/arch/arm/sunxi/sunxi_emac.h:1.5
--- src/sys/arch/arm/sunxi/sunxi_emac.h:1.4	Sun Oct  1 15:05:09 2017
+++ src/sys/arch/arm/sunxi/sunxi_emac.h	Sun Feb 21 16:07:43 2021
@@ -203,8 +203,8 @@ struct sunxi_emac_desc {
 	uint32_t	addr;
 
 	uint32_t	next;
-} __packed __aligned(CACHE_LINE_SIZE);
+} __packed __aligned(64);
 
-__CTASSERT(sizeof(struct sunxi_emac_desc) == CACHE_LINE_SIZE);
+__CTASSERT(sizeof(struct sunxi_emac_desc) == 64);
 
 #endif /* !__SUNXI_EMAC_H__ */



CVS commit: src/sys/arch/arm/sunxi

2021-01-28 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Jan 29 06:24:19 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sunxi_drm.c

Log Message:
Fix previous; sunxidrm(4) couldn't be probed on Allwinner A64 due to
trailing whitespace in compat string.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/sunxi/sunxi_drm.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/sunxi_drm.c
diff -u src/sys/arch/arm/sunxi/sunxi_drm.c:1.12 src/sys/arch/arm/sunxi/sunxi_drm.c:1.13
--- src/sys/arch/arm/sunxi/sunxi_drm.c:1.12	Wed Jan 27 03:10:20 2021
+++ src/sys/arch/arm/sunxi/sunxi_drm.c	Fri Jan 29 06:24:18 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_drm.c,v 1.12 2021/01/27 03:10:20 thorpej Exp $ */
+/* $NetBSD: sunxi_drm.c,v 1.13 2021/01/29 06:24:18 rin Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.12 2021/01/27 03:10:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.13 2021/01/29 06:24:18 rin Exp $");
 
 #include 
 #include 
@@ -66,7 +66,7 @@ static TAILQ_HEAD(, sunxi_drm_endpoint) 
 
 static const struct device_compatible_entry compat_data[] = {
 	{ .compat = "allwinner,sun8i-h3-display-engine" },
-	{ .compat = "allwinner,sun50i-a64-display-engine " },
+	{ .compat = "allwinner,sun50i-a64-display-engine" },
 	DEVICE_COMPAT_EOL
 };
 



CVS commit: src/sys/arch/arm/sunxi

2021-01-26 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 27 02:09:39 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sun4i_a10_ccu.c sun4i_dma.c sun6i_dma.c
sun8i_crypto.c sunxi_can.c sunxi_codec.c sunxi_de2_ccu.c
sunxi_dep.c sunxi_emac.c sunxi_gpio.c sunxi_hdmi.c sunxi_hdmiphy.c
sunxi_i2s.c sunxi_lcdc.c sunxi_lradc.c sunxi_mixer.c sunxi_mmc.c
sunxi_musb.c sunxi_nmi.c sunxi_pwm.c sunxi_rsb.c sunxi_rtc.c
sunxi_sid.c sunxi_sramc.c sunxi_tcon.c sunxi_thermal.c sunxi_ts.c
sunxi_twi.c sunxi_usb3phy.c sunxi_usbphy.c sunxi_wdt.c

Log Message:
Use DEVICE_COMPAT_EOL.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/arm/sunxi/sun4i_a10_ccu.c \
src/sys/arch/arm/sunxi/sunxi_mixer.c \
src/sys/arch/arm/sunxi/sunxi_usbphy.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sunxi/sun4i_dma.c \
src/sys/arch/arm/sunxi/sunxi_can.c src/sys/arch/arm/sunxi/sunxi_hdmiphy.c \
src/sys/arch/arm/sunxi/sunxi_ts.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/sunxi/sun6i_dma.c \
src/sys/arch/arm/sunxi/sunxi_hdmi.c src/sys/arch/arm/sunxi/sunxi_rsb.c
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/arm/sunxi/sun8i_crypto.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/arm/sunxi/sunxi_codec.c \
src/sys/arch/arm/sunxi/sunxi_i2s.c src/sys/arch/arm/sunxi/sunxi_lcdc.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sunxi/sunxi_de2_ccu.c \
src/sys/arch/arm/sunxi/sunxi_dep.c src/sys/arch/arm/sunxi/sunxi_pwm.c \
src/sys/arch/arm/sunxi/sunxi_sid.c
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/arm/sunxi/sunxi_emac.c
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/arm/sunxi/sunxi_gpio.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sunxi/sunxi_lradc.c \
src/sys/arch/arm/sunxi/sunxi_wdt.c
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/arm/sunxi/sunxi_mmc.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/arm/sunxi/sunxi_musb.c \
src/sys/arch/arm/sunxi/sunxi_rtc.c
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/arm/sunxi/sunxi_nmi.c \
src/sys/arch/arm/sunxi/sunxi_sramc.c src/sys/arch/arm/sunxi/sunxi_tcon.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/arm/sunxi/sunxi_thermal.c
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/arm/sunxi/sunxi_twi.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sunxi/sunxi_usb3phy.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/sun4i_a10_ccu.c
diff -u src/sys/arch/arm/sunxi/sun4i_a10_ccu.c:1.14 src/sys/arch/arm/sunxi/sun4i_a10_ccu.c:1.15
--- src/sys/arch/arm/sunxi/sun4i_a10_ccu.c:1.14	Mon Jan 25 14:20:39 2021
+++ src/sys/arch/arm/sunxi/sun4i_a10_ccu.c	Wed Jan 27 02:09:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sun4i_a10_ccu.c,v 1.14 2021/01/25 14:20:39 thorpej Exp $ */
+/* $NetBSD: sun4i_a10_ccu.c,v 1.15 2021/01/27 02:09:39 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sun4i_a10_ccu.c,v 1.14 2021/01/25 14:20:39 thorpej Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun4i_a10_ccu.c,v 1.15 2021/01/27 02:09:39 thorpej Exp $");
 
 #include 
 #include 
@@ -96,7 +96,7 @@ enum sun4i_a10_ccu_type {
 static const struct device_compatible_entry compat_data[] = {
 	{ .compat = "allwinner,sun4i-a10-ccu",	.value = CCU_A10 },
 	{ .compat = "allwinner,sun7i-a20-ccu",	.value = CCU_A20 },
-	{ }
+	DEVICE_COMPAT_EOL
 };
 
 CFATTACH_DECL_NEW(sunxi_a10_ccu, sizeof(struct sunxi_ccu_softc),
Index: src/sys/arch/arm/sunxi/sunxi_mixer.c
diff -u src/sys/arch/arm/sunxi/sunxi_mixer.c:1.14 src/sys/arch/arm/sunxi/sunxi_mixer.c:1.15
--- src/sys/arch/arm/sunxi/sunxi_mixer.c:1.14	Mon Jan 25 14:20:39 2021
+++ src/sys/arch/arm/sunxi/sunxi_mixer.c	Wed Jan 27 02:09:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mixer.c,v 1.14 2021/01/25 14:20:39 thorpej Exp $ */
+/* $NetBSD: sunxi_mixer.c,v 1.15 2021/01/27 02:09:39 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.c,v 1.14 2021/01/25 14:20:39 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.c,v 1.15 2021/01/27 02:09:39 thorpej Exp $");
 
 #include 
 #include 
@@ -206,7 +206,7 @@ static const struct device_compatible_en
 	{ .compat = "allwinner,sun50i-a64-de2-mixer-1",
 	  .data = _data },
 
-	{ }
+	DEVICE_COMPAT_EOL
 };
 
 struct sunxi_mixer_softc;
Index: src/sys/arch/arm/sunxi/sunxi_usbphy.c
diff -u src/sys/arch/arm/sunxi/sunxi_usbphy.c:1.14 src/sys/arch/arm/sunxi/sunxi_usbphy.c:1.15
--- src/sys/arch/arm/sunxi/sunxi_usbphy.c:1.14	Mon Jan 25 14:20:39 2021
+++ src/sys/arch/arm/sunxi/sunxi_usbphy.c	Wed Jan 27 02:09:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_usbphy.c,v 1.14 2021/01/25 14:20:39 thorpej Exp $ */
+/* $NetBSD: sunxi_usbphy.c,v 1.15 2021/01/27 02:09:39 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_usbphy.c,v 1.14 2021/01/25 14:20:39 thorpej Exp $");
+__KERNEL_RCSID(0, 

CVS commit: src/sys/arch/arm/sunxi

2021-01-19 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jan 20 00:48:49 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sunxi_sramc.c

Log Message:
Fix previous; of_search_compatible returns the sentinel when there is no
match, so we need to test ->data for NULL, not the return value.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sunxi/sunxi_sramc.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/sunxi_sramc.c
diff -u src/sys/arch/arm/sunxi/sunxi_sramc.c:1.6 src/sys/arch/arm/sunxi/sunxi_sramc.c:1.7
--- src/sys/arch/arm/sunxi/sunxi_sramc.c:1.6	Tue Jan 19 00:35:10 2021
+++ src/sys/arch/arm/sunxi/sunxi_sramc.c	Wed Jan 20 00:48:49 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_sramc.c,v 1.6 2021/01/19 00:35:10 thorpej Exp $ */
+/* $NetBSD: sunxi_sramc.c,v 1.7 2021/01/20 00:48:49 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_sramc.c,v 1.6 2021/01/19 00:35:10 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_sramc.c,v 1.7 2021/01/20 00:48:49 jmcneill Exp $");
 
 #include 
 #include 
@@ -127,7 +127,7 @@ sunxi_sramc_init_mmio(struct sunxi_sramc
 
 	for (child = OF_child(phandle); child; child = OF_peer(child)) {
 		dce = of_search_compatible(child, sunxi_sramc_areas);
-		if (dce != NULL) {
+		if (dce->data != NULL) {
 			node = kmem_alloc(sizeof(*node), KM_SLEEP);
 			node->phandle = child;
 			node->area = dce->data;



CVS commit: src/sys/arch/arm/sunxi

2021-01-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Tue Jan 19 00:35:10 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sunxi_sramc.c

Log Message:
Use device_compatible_entry / of_search_compatible() rather than matching
against multiple sets of compatibility strings.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sunxi/sunxi_sramc.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/sunxi_sramc.c
diff -u src/sys/arch/arm/sunxi/sunxi_sramc.c:1.5 src/sys/arch/arm/sunxi/sunxi_sramc.c:1.6
--- src/sys/arch/arm/sunxi/sunxi_sramc.c:1.5	Thu Jul 11 18:22:14 2019
+++ src/sys/arch/arm/sunxi/sunxi_sramc.c	Tue Jan 19 00:35:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_sramc.c,v 1.5 2019/07/11 18:22:14 macallan Exp $ */
+/* $NetBSD: sunxi_sramc.c,v 1.6 2021/01/19 00:35:10 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_sramc.c,v 1.5 2019/07/11 18:22:14 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_sramc.c,v 1.6 2021/01/19 00:35:10 thorpej Exp $");
 
 #include 
 #include 
@@ -42,33 +42,57 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_sramc.
 
 #include 
 
-static const char * compatible[] = {
-	"allwinner,sun4i-a10-sram-controller",	/* old compat string */
-	"allwinner,sun4i-a10-system-control",
-	"allwinner,sun8i-h3-system-control",
-	"allwinner,sun50i-a64-system-control",
-	"allwinner,sun50i-h5-system-control",
-	"allwinner,sun50i-h6-system-control",
-	NULL
+static const struct device_compatible_entry compat_data[] = {
+		/* old compat string */
+	{ .compat = "allwinner,sun4i-a10-sram-controller" },
+	{ .compat = "allwinner,sun4i-a10-system-control" },
+	{ .compat = "allwinner,sun8i-h3-system-control" },
+	{ .compat = "allwinner,sun50i-a64-system-control" },
+	{ .compat = "allwinner,sun50i-h5-system-control" },
+	{ .compat = "allwinner,sun50i-h6-system-control" },
+	{ 0 }
 };
 
-static const struct sunxi_sramc_area {
-	const char			*compatible;
+struct sunxi_sramc_area {
 	const char			*desc;
 	bus_size_t			reg;
 	uint32_t			mask;
 	u_intflags;
 #define	SUNXI_SRAMC_F_SWAP		__BIT(0)
-} sunxi_sramc_areas[] = {
-	{ "allwinner,sun4i-a10-sram-a3-a4",
-	  "SRAM A3/A4",
-	  0x04, __BITS(5,4), 0 },
-	{ "allwinner,sun4i-a10-sram-d",
-	  "SRAM D",
-	  0x04, __BIT(0), 0 },
-	{ "allwinner,sun50i-a64-sram-c",
-	  "SRAM C",
-	  0x04, __BIT(24), SUNXI_SRAMC_F_SWAP },
+};
+
+static const struct sunxi_sramc_area sunxi_sramc_area_a3_a4 = {
+	.desc = "SRAM A3/A4",
+	.reg = 0x04,
+	.mask = __BITS(5,4),
+	.flags = 0,
+};
+
+static const struct sunxi_sramc_area sunxi_sramc_area_d = {
+	.desc = "SRAM D",
+	.reg = 0x04,
+	.mask = __BIT(0),
+	.flags = 0,
+};
+
+static const struct sunxi_sramc_area sunxi_sramc_area_c = {
+	.desc = "SRAM C",
+	.reg = 0x04,
+	.mask = __BIT(24),
+	.flags = SUNXI_SRAMC_F_SWAP,
+};
+
+static const struct device_compatible_entry sunxi_sramc_areas[] = {
+	{ .compat = "allwinner,sun4i-a10-sram-a3-a4",
+	  .data = _sramc_area_a3_a4 },
+
+	{ .compat = "allwinner,sun4i-a10-sram-d",
+	  .data = _sramc_area_d },
+
+	{ .compat = "allwinner,sun50i-a64-sram-c",
+	  .data = _sramc_area_c },
+
+	{ 0 }
 };
 
 struct sunxi_sramc_node {
@@ -97,31 +121,34 @@ static struct sunxi_sramc_softc *sramc_s
 static void
 sunxi_sramc_init_mmio(struct sunxi_sramc_softc *sc, int phandle)
 {
+	const struct device_compatible_entry *dce;
 	struct sunxi_sramc_node *node;
-	int child, i;
+	int child;
 
-	for (child = OF_child(phandle); child; child = OF_peer(child))
-		for (i = 0; i < __arraycount(sunxi_sramc_areas); i++) {
-			const char * area_compatible[] = { sunxi_sramc_areas[i].compatible, NULL };
-			if (of_match_compatible(child, area_compatible)) {
-node = kmem_alloc(sizeof(*node), KM_SLEEP);
-node->phandle = child;
-node->area = _sramc_areas[i];
-TAILQ_INSERT_TAIL(>sc_nodes, node, nodes);
-aprint_verbose_dev(sc->sc_dev, "area: %s\n", node->area->desc);
-break;
-			}
+	for (child = OF_child(phandle); child; child = OF_peer(child)) {
+		dce = of_search_compatible(child, sunxi_sramc_areas);
+		if (dce != NULL) {
+			node = kmem_alloc(sizeof(*node), KM_SLEEP);
+			node->phandle = child;
+			node->area = dce->data;
+			TAILQ_INSERT_TAIL(>sc_nodes, node, nodes);
+			aprint_verbose_dev(sc->sc_dev, "area: %s\n",
+			node->area->desc);
 		}
+	}
 }
 
 static void
 sunxi_sramc_init(struct sunxi_sramc_softc *sc)
 {
-	const char * mmio_compatible[] = { "mmio-sram", NULL };
+	const struct device_compatible_entry mmio_compat_data[] = {
+		{ .compat = "mmio-sram" },
+		{ 0 }
+	};
 	int child;
 
 	for (child = OF_child(sc->sc_phandle); child; child = OF_peer(child)) {
-		if (!of_match_compatible(child, mmio_compatible))
+		if (!of_match_compat_data(child, mmio_compat_data))
 			continue;
 		sunxi_sramc_init_mmio(sc, child);
 	}
@@ -168,7 +195,7 @@ sunxi_sramc_match(device_t parent, cfdat
 

CVS commit: src/sys/arch/arm/sunxi

2021-01-18 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Jan 18 13:29:37 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sunxi_gpio.c

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/arm/sunxi/sunxi_gpio.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/sunxi_gpio.c
diff -u src/sys/arch/arm/sunxi/sunxi_gpio.c:1.31 src/sys/arch/arm/sunxi/sunxi_gpio.c:1.32
--- src/sys/arch/arm/sunxi/sunxi_gpio.c:1.31	Mon Jan 18 02:35:49 2021
+++ src/sys/arch/arm/sunxi/sunxi_gpio.c	Mon Jan 18 13:29:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_gpio.c,v 1.31 2021/01/18 02:35:49 thorpej Exp $ */
+/* $NetBSD: sunxi_gpio.c,v 1.32 2021/01/18 13:29:37 skrll Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_soc.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_gpio.c,v 1.31 2021/01/18 02:35:49 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_gpio.c,v 1.32 2021/01/18 13:29:37 skrll Exp $");
 
 #include 
 #include 
@@ -86,7 +86,7 @@ static const struct device_compatible_en
 #ifdef SOC_SUN5I_A13
 	{ .compat = "allwinner,sun5i-a13-pinctrl",
 	  .data = _a13_padconf },
-	{ .compat = "nextthing,gr8-pinctrl",	
+	{ .compat = "nextthing,gr8-pinctrl",
 	  .data = _a13_padconf },
 #endif
 #ifdef SOC_SUN6I_A31
@@ -469,7 +469,7 @@ sunxi_intr_enable(struct sunxi_gpio_soft
 {
 	uint32_t val;
 	struct sunxi_gpio_eint *eint;
-	
+
 	if (pin_def->functions[pin_def->eint_func] == NULL ||
 	strcmp(pin_def->functions[pin_def->eint_func], "irq") != 0)
 		return NULL;



CVS commit: src/sys/arch/arm/sunxi

2021-01-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Jan 15 23:02:38 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sun6i_spi.c

Log Message:
trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sunxi/sun6i_spi.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/sun6i_spi.c
diff -u src/sys/arch/arm/sunxi/sun6i_spi.c:1.6 src/sys/arch/arm/sunxi/sun6i_spi.c:1.7
--- src/sys/arch/arm/sunxi/sun6i_spi.c:1.6	Fri Jan 15 23:02:07 2021
+++ src/sys/arch/arm/sunxi/sun6i_spi.c	Fri Jan 15 23:02:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun6i_spi.c,v 1.6 2021/01/15 23:02:07 jmcneill Exp $	*/
+/*	$NetBSD: sun6i_spi.c,v 1.7 2021/01/15 23:02:38 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2019 Tobias Nygren
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sun6i_spi.c,v 1.6 2021/01/15 23:02:07 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun6i_spi.c,v 1.7 2021/01/15 23:02:38 jmcneill Exp $");
 
 #include 
 #include 
@@ -158,7 +158,7 @@ sun6ispi_attach(device_t parent, device_
 
 	aprint_naive("\n");
 	aprint_normal(": SPI\n");
-	
+
 	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
 
 	gcr = SPI_GCR_SRST;
@@ -205,7 +205,7 @@ sun6ispi_configure(void *cookie, int sla
 
 	if (slave >= sc->sc_spi.sct_nslaves)
 		return EINVAL;
-	
+
 	tcr = SPI_TCR_SS_LEVEL | SPI_TCR_SPOL;
 
 	switch (mode) {



CVS commit: src/sys/arch/arm/sunxi

2021-01-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Jan 15 23:02:07 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sun6i_spi.c

Log Message:
use fdtbus_intr_establish_xname


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sunxi/sun6i_spi.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/sun6i_spi.c
diff -u src/sys/arch/arm/sunxi/sun6i_spi.c:1.5 src/sys/arch/arm/sunxi/sun6i_spi.c:1.6
--- src/sys/arch/arm/sunxi/sun6i_spi.c:1.5	Tue Aug 13 17:03:10 2019
+++ src/sys/arch/arm/sunxi/sun6i_spi.c	Fri Jan 15 23:02:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun6i_spi.c,v 1.5 2019/08/13 17:03:10 tnn Exp $	*/
+/*	$NetBSD: sun6i_spi.c,v 1.6 2021/01/15 23:02:07 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2019 Tobias Nygren
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sun6i_spi.c,v 1.5 2019/08/13 17:03:10 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun6i_spi.c,v 1.6 2021/01/15 23:02:07 jmcneill Exp $");
 
 #include 
 #include 
@@ -149,8 +149,8 @@ sun6ispi_attach(device_t parent, device_
 		return;
 	}
 
-	sc->sc_intrh = fdtbus_intr_establish(phandle, 0, IPL_VM, 0,
-	sun6ispi_intr, sc);
+	sc->sc_intrh = fdtbus_intr_establish_xname(phandle, 0, IPL_VM, 0,
+	sun6ispi_intr, sc, device_xname(self));
 	if (sc->sc_intrh == NULL) {
 		aprint_error(": unable to establish interrupt\n");
 		return;



CVS commit: src/sys/arch/arm/sunxi

2021-01-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Jan 15 22:47:33 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sun4i_dma.c sun4i_emac.c sun4i_spi.c
sun6i_dma.c sun8i_codec.c sun8i_crypto.c sunxi_can.c sunxi_emac.c
sunxi_gmac.c sunxi_gpio.c sunxi_hstimer.c sunxi_lcdc.c
sunxi_lradc.c sunxi_mmc.c sunxi_musb.c sunxi_nand.c sunxi_nmi.c
sunxi_rsb.c sunxi_sata.c sunxi_thermal.c sunxi_timer.c sunxi_ts.c
sunxi_twi.c

Log Message:
use fdtbus_intr_establish_xname


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sunxi/sun4i_dma.c \
src/sys/arch/arm/sunxi/sunxi_can.c src/sys/arch/arm/sunxi/sunxi_ts.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/sunxi/sun4i_emac.c \
src/sys/arch/arm/sunxi/sunxi_twi.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sunxi/sun4i_spi.c \
src/sys/arch/arm/sunxi/sunxi_musb.c
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/arm/sunxi/sun6i_dma.c \
src/sys/arch/arm/sunxi/sunxi_rsb.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sunxi/sun8i_codec.c \
src/sys/arch/arm/sunxi/sunxi_gmac.c src/sys/arch/arm/sunxi/sunxi_lcdc.c \
src/sys/arch/arm/sunxi/sunxi_timer.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/arm/sunxi/sun8i_crypto.c
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/arm/sunxi/sunxi_emac.c \
src/sys/arch/arm/sunxi/sunxi_gpio.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sunxi_hstimer.c \
src/sys/arch/arm/sunxi/sunxi_sata.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/sunxi/sunxi_lradc.c
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/arm/sunxi/sunxi_mmc.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/arm/sunxi/sunxi_nand.c \
src/sys/arch/arm/sunxi/sunxi_thermal.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sunxi/sunxi_nmi.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/sun4i_dma.c
diff -u src/sys/arch/arm/sunxi/sun4i_dma.c:1.3 src/sys/arch/arm/sunxi/sun4i_dma.c:1.4
--- src/sys/arch/arm/sunxi/sun4i_dma.c:1.3	Fri Apr 20 18:04:12 2018
+++ src/sys/arch/arm/sunxi/sun4i_dma.c	Fri Jan 15 22:47:32 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sun4i_dma.c,v 1.3 2018/04/20 18:04:12 bouyer Exp $ */
+/* $NetBSD: sun4i_dma.c,v 1.4 2021/01/15 22:47:32 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sun4i_dma.c,v 1.3 2018/04/20 18:04:12 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun4i_dma.c,v 1.4 2021/01/15 22:47:32 jmcneill Exp $");
 
 #include 
 #include 
@@ -408,8 +408,8 @@ sun4idma_attach(device_t parent, device_
 		}
 	}
 
-	sc->sc_ih = fdtbus_intr_establish(phandle, 0, IPL_SCHED,
-	FDT_INTR_MPSAFE, sun4idma_intr, sc);
+	sc->sc_ih = fdtbus_intr_establish_xname(phandle, 0, IPL_SCHED,
+	FDT_INTR_MPSAFE, sun4idma_intr, sc, device_xname(sc->sc_dev));
 	if (sc->sc_ih == NULL) {
 		aprint_error_dev(sc->sc_dev,
 		"couldn't establish interrupt on %s\n", intrstr);
Index: src/sys/arch/arm/sunxi/sunxi_can.c
diff -u src/sys/arch/arm/sunxi/sunxi_can.c:1.3 src/sys/arch/arm/sunxi/sunxi_can.c:1.4
--- src/sys/arch/arm/sunxi/sunxi_can.c:1.3	Wed Jan 29 06:05:31 2020
+++ src/sys/arch/arm/sunxi/sunxi_can.c	Fri Jan 15 22:47:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sunxi_can.c,v 1.3 2020/01/29 06:05:31 thorpej Exp $	*/
+/*	$NetBSD: sunxi_can.c,v 1.4 2021/01/15 22:47:32 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2017,2018 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sunxi_can.c,v 1.3 2020/01/29 06:05:31 thorpej Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sunxi_can.c,v 1.4 2021/01/15 22:47:32 jmcneill Exp $");
 
 #include 
 #include 
@@ -202,8 +202,8 @@ sunxi_can_attach(device_t parent, device
 	sunxi_can_write(sc, SUNXI_CAN_INT_REG,
 	sunxi_can_read(sc, SUNXI_CAN_INT_REG));
 
-	sc->sc_ih = fdtbus_intr_establish(phandle, 0, IPL_NET, 0,
-	sunxi_can_intr, sc);
+	sc->sc_ih = fdtbus_intr_establish_xname(phandle, 0, IPL_NET, 0,
+	sunxi_can_intr, sc, device_xname(self));
 	if (sc->sc_ih == NULL) {
 		aprint_error_dev(self, "failed to establish interrupt on %s\n",
 		intrstr);
Index: src/sys/arch/arm/sunxi/sunxi_ts.c
diff -u src/sys/arch/arm/sunxi/sunxi_ts.c:1.3 src/sys/arch/arm/sunxi/sunxi_ts.c:1.4
--- src/sys/arch/arm/sunxi/sunxi_ts.c:1.3	Tue Jun  4 03:03:34 2019
+++ src/sys/arch/arm/sunxi/sunxi_ts.c	Fri Jan 15 22:47:32 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_ts.c,v 1.3 2019/06/04 03:03:34 thorpej Exp $ */
+/* $NetBSD: sunxi_ts.c,v 1.4 2021/01/15 22:47:32 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_ts.c,v 1.3 2019/06/04 03:03:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_ts.c,v 1.4 2021/01/15 22:47:32 jmcneill Exp $");
 
 #include 
 #include 
@@ -388,7 +388,8 @@ sunxi_ts_attach(device_t parent, device_
 
 	sunxi_ts_init(sc);
 
-	ih = fdtbus_intr_establish(phandle, 0, 

CVS commit: src/sys/arch/arm/sunxi

2020-10-18 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Oct 19 01:13:41 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sunxi_debe.c

Log Message:
sunxi_debe_set_videomode(): As byte-swapped framebuffer is now handled by
FDT override, do not configure FB to little-endian format for __ARMEB__.

XXX
This function is not actually called at the moment. IIRC, it worked in
the pre-FDT era. Something went wrong since then...


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/arm/sunxi/sunxi_debe.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/sunxi_debe.c
diff -u src/sys/arch/arm/sunxi/sunxi_debe.c:1.9 src/sys/arch/arm/sunxi/sunxi_debe.c:1.10
--- src/sys/arch/arm/sunxi/sunxi_debe.c:1.9	Fri Jun  1 17:18:44 2018
+++ src/sys/arch/arm/sunxi/sunxi_debe.c	Mon Oct 19 01:13:41 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_debe.c,v 1.9 2018/06/01 17:18:44 bouyer Exp $ */
+/* $NetBSD: sunxi_debe.c,v 1.10 2020/10/19 01:13:41 rin Exp $ */
 
 /*-
  * Copyright (c) 2018 Manuel Bouyer 
@@ -38,7 +38,7 @@
 #define SUNXI_DEBE_CURMAX	64
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_debe.c,v 1.9 2018/06/01 17:18:44 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_debe.c,v 1.10 2020/10/19 01:13:41 rin Exp $");
 
 #include 
 #include 
@@ -560,6 +560,10 @@ sunxi_debe_ep_enable(device_t dev, struc
 	return 0;
 }
 
+/*
+ * FIXME 2020/10/19
+ * This function is not called actually at the moment.
+ */
 void
 sunxi_debe_set_videomode(device_t dev, const struct videomode *mode)
 {
@@ -613,7 +617,12 @@ sunxi_debe_set_videomode(device_t dev, c
  SUNXI_DEBE_ATTCTL1_LAY_FBFMT);
 		val &= ~SUNXI_DEBE_ATTCTL1_LAY_BRSWAPEN;
 		val &= ~SUNXI_DEBE_ATTCTL1_LAY_FBPS;
-#if __ARMEB__
+#if 0 /* __ARMEB__ */
+		/*
+		 * For big endian, we dynamically override FDT to let
+		 * genfb(4) know that framebuffer is byte-swapped.
+		 * See fdt_update_fb_format() in fdt_machdep.c.
+		 */
 		val |= __SHIFTIN(SUNXI_DEBE_ATTCTL1_LAY_FBPS_32BPP_BGRA,
  SUNXI_DEBE_ATTCTL1_LAY_FBPS);
 #else



CVS commit: src/sys/arch/arm/sunxi

2020-10-18 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Oct 18 14:00:08 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sunxi_mixer.c

Log Message:
Treat ARGB/XRGB as BGRA/BGRX on big endian kernels.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/arm/sunxi/sunxi_mixer.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/sunxi_mixer.c
diff -u src/sys/arch/arm/sunxi/sunxi_mixer.c:1.11 src/sys/arch/arm/sunxi/sunxi_mixer.c:1.12
--- src/sys/arch/arm/sunxi/sunxi_mixer.c:1.11	Sun Feb  9 15:22:25 2020
+++ src/sys/arch/arm/sunxi/sunxi_mixer.c	Sun Oct 18 14:00:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mixer.c,v 1.11 2020/02/09 15:22:25 jakllsch Exp $ */
+/* $NetBSD: sunxi_mixer.c,v 1.12 2020/10/18 14:00:08 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.c,v 1.11 2020/02/09 15:22:25 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.c,v 1.12 2020/10/18 14:00:08 jmcneill Exp $");
 
 #include 
 #include 
@@ -99,8 +99,13 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.
 #define	  OVL_V_ATTCTL_LAY_FBFMT_YUV422		0x06
 #define	  OVL_V_ATTCTL_LAY_FBFMT_YUV420		0x0a
 #define	  OVL_V_ATTCTL_LAY_FBFMT_YUV411		0x0e
+#if BYTE_ORDER == BIG_ENDIAN
+#define	  OVL_V_ATTCTL_LAY_FBFMT_ARGB_	0x03
+#define	  OVL_V_ATTCTL_LAY_FBFMT_XRGB_	0x07
+#else
 #define	  OVL_V_ATTCTL_LAY_FBFMT_ARGB_	0x00
 #define	  OVL_V_ATTCTL_LAY_FBFMT_XRGB_	0x04
+#endif
 #define	 OVL_V_ATTCTL_LAY0_EN			__BIT(0)
 #define	OVL_V_MBSIZE(n)		(0x004 + (n) * 0x30)
 #define	OVL_V_COOR(n)		(0x008 + (n) * 0x30)
@@ -124,8 +129,13 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.
 /* OVL_UI registers */
 #define	OVL_UI_ATTR_CTL(n)	(0x000 + (n) * 0x20)
 #define	 OVL_UI_ATTR_CTL_LAY_FBFMT		__BITS(12,8)
+#if BYTE_ORDER == BIG_ENDIAN
+#define	  OVL_UI_ATTR_CTL_LAY_FBFMT_ARGB_	0x03
+#define	  OVL_UI_ATTR_CTL_LAY_FBFMT_XRGB_	0x07
+#else
 #define	  OVL_UI_ATTR_CTL_LAY_FBFMT_ARGB_	0x00
 #define	  OVL_UI_ATTR_CTL_LAY_FBFMT_XRGB_	0x04
+#endif
 #define	 OVL_UI_ATTR_CTL_LAY_EN			__BIT(0)
 #define	OVL_UI_MBSIZE(n)	(0x004 + (n) * 0x20)
 #define	OVL_UI_COOR(n)		(0x008 + (n) * 0x20)



CVS commit: src/sys/arch/arm/sunxi

2020-08-27 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Aug 27 16:35:13 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sunxi_gpio.c

Log Message:
Avoid undefined behaviour as detected by KUBSAN


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/arm/sunxi/sunxi_gpio.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/sunxi_gpio.c
diff -u src/sys/arch/arm/sunxi/sunxi_gpio.c:1.27 src/sys/arch/arm/sunxi/sunxi_gpio.c:1.28
--- src/sys/arch/arm/sunxi/sunxi_gpio.c:1.27	Tue Oct  1 23:32:52 2019
+++ src/sys/arch/arm/sunxi/sunxi_gpio.c	Thu Aug 27 16:35:13 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_gpio.c,v 1.27 2019/10/01 23:32:52 jmcneill Exp $ */
+/* $NetBSD: sunxi_gpio.c,v 1.28 2020/08/27 16:35:13 skrll Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_soc.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_gpio.c,v 1.27 2019/10/01 23:32:52 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_gpio.c,v 1.28 2020/08/27 16:35:13 skrll Exp $");
 
 #include 
 #include 
@@ -54,17 +54,17 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_gpio.c
 
 #define	SUNXI_GPIO_PORT(port)		(0x24 * (port))
 #define SUNXI_GPIO_CFG(port, pin)	(SUNXI_GPIO_PORT(port) + 0x00 + (0x4 * ((pin) / 8)))
-#define  SUNXI_GPIO_CFG_PINMASK(pin)	(0x7 << (((pin) % 8) * 4))
+#define  SUNXI_GPIO_CFG_PINMASK(pin)	(0x7U << (((pin) % 8) * 4))
 #define	SUNXI_GPIO_DATA(port)		(SUNXI_GPIO_PORT(port) + 0x10)
 #define	SUNXI_GPIO_DRV(port, pin)	(SUNXI_GPIO_PORT(port) + 0x14 + (0x4 * ((pin) / 16)))
-#define  SUNXI_GPIO_DRV_PINMASK(pin)	(0x3 << (((pin) % 16) * 2))
+#define  SUNXI_GPIO_DRV_PINMASK(pin)	(0x3U << (((pin) % 16) * 2))
 #define	SUNXI_GPIO_PULL(port, pin)	(SUNXI_GPIO_PORT(port) + 0x1c + (0x4 * ((pin) / 16)))
 #define	 SUNXI_GPIO_PULL_DISABLE	0
 #define	 SUNXI_GPIO_PULL_UP		1
 #define	 SUNXI_GPIO_PULL_DOWN		2
-#define  SUNXI_GPIO_PULL_PINMASK(pin)	(0x3 << (((pin) % 16) * 2))
+#define  SUNXI_GPIO_PULL_PINMASK(pin)	(0x3U << (((pin) % 16) * 2))
 #define	SUNXI_GPIO_INT_CFG(bank, eint)	(0x200 + (0x20 * (bank)) + (0x4 * ((eint) / 8)))
-#define	 SUNXI_GPIO_INT_MODEMASK(eint)	(0xf << (((eint) % 8) * 4))
+#define	 SUNXI_GPIO_INT_MODEMASK(eint)	(0xfU << (((eint) % 8) * 4))
 #define	  SUNXI_GPIO_INT_MODE_POS_EDGE		0x0
 #define	  SUNXI_GPIO_INT_MODE_NEG_EDGE		0x1
 #define	  SUNXI_GPIO_INT_MODE_HIGH_LEVEL	0x2



CVS commit: src/sys/arch/arm/sunxi

2020-08-24 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Aug 24 07:42:02 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sunxi_nand.c

Log Message:
Appease gcc when building with KASAN which gave this error before

error: stack usage might be unbounded [-Werror=stack-usage=]


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sunxi/sunxi_nand.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/sunxi_nand.c
diff -u src/sys/arch/arm/sunxi/sunxi_nand.c:1.7 src/sys/arch/arm/sunxi/sunxi_nand.c:1.8
--- src/sys/arch/arm/sunxi/sunxi_nand.c:1.7	Sun Jul  5 05:16:50 2020
+++ src/sys/arch/arm/sunxi/sunxi_nand.c	Mon Aug 24 07:42:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_nand.c,v 1.7 2020/07/05 05:16:50 skrll Exp $ */
+/* $NetBSD: sunxi_nand.c,v 1.8 2020/08/24 07:42:02 skrll Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_nand.c,v 1.7 2020/07/05 05:16:50 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_nand.c,v 1.8 2020/08/24 07:42:02 skrll Exp $");
 
 #include 
 #include 
@@ -592,7 +592,7 @@ sunxi_nand_attach_chip(struct sunxi_nand
 
 	mtdparts = get_bootconf_string(boot_args, "mtdparts");
 	if (mtdparts != NULL) {
-		char mtd_id[strlen("sunxi-nand.X") + 1];
+		char mtd_id[] = "sunxi-nand.XX";
 		snprintf(mtd_id, sizeof(mtd_id), "sunxi-nand.%u",
 		device_unit(sc->sc_dev));
 



CVS commit: src/sys/arch/arm/sunxi

2020-07-04 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Jul  5 05:16:51 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sunxi_nand.c

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sunxi/sunxi_nand.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/sunxi_nand.c
diff -u src/sys/arch/arm/sunxi/sunxi_nand.c:1.6 src/sys/arch/arm/sunxi/sunxi_nand.c:1.7
--- src/sys/arch/arm/sunxi/sunxi_nand.c:1.6	Mon Sep  3 16:29:24 2018
+++ src/sys/arch/arm/sunxi/sunxi_nand.c	Sun Jul  5 05:16:50 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_nand.c,v 1.6 2018/09/03 16:29:24 riastradh Exp $ */
+/* $NetBSD: sunxi_nand.c,v 1.7 2020/07/05 05:16:50 skrll Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_nand.c,v 1.6 2018/09/03 16:29:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_nand.c,v 1.7 2020/07/05 05:16:50 skrll Exp $");
 
 #include 
 #include 
@@ -688,7 +688,7 @@ sunxi_nand_attach(device_t parent, devic
 
 	sunxi_nand_attach_chip(sc, >sc_chip, child);
 }
-	
+
 CFATTACH_DECL_NEW(sunxi_nand, sizeof(struct sunxi_nand_softc),
 	sunxi_nand_match, sunxi_nand_attach, NULL, NULL);
 



CVS commit: src/sys/arch/arm/sunxi

2020-06-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Jun 14 16:29:47 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c

Log Message:
Fix !DIAGNOSTIC compile.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/arm/sunxi/sun8i_crypto.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/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.17 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.18
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.17	Sat Jun 13 18:58:26 2020
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Sun Jun 14 16:29:47 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.17 2020/06/13 18:58:26 riastradh Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.18 2020/06/14 16:29:47 ad Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.17 2020/06/13 18:58:26 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.18 2020/06/14 16:29:47 ad Exp $");
 
 #include 
 #include 
@@ -2393,7 +2393,7 @@ sun8i_crypto_callback(struct sun8i_crypt
 struct sun8i_crypto_task *task, void *cookie, int error)
 {
 	struct cryptop *crp = cookie;
-	struct cryptodesc *crd = crp->crp_desc;
+	struct cryptodesc *crd __diagused = crp->crp_desc;
 
 	KASSERT(error != ERESTART);
 	KASSERT(crd != NULL);



CVS commit: src/sys/arch/arm/sunxi

2020-06-13 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 13 18:58:26 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c

Log Message:
Draft opencrypto support for Allwinner Crypto Engine.

XXX Can't handle nonzero crd_skip yet.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/arm/sunxi/sun8i_crypto.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/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.16 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.17
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.16	Sat Jun 13 18:57:54 2020
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Sat Jun 13 18:58:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.16 2020/06/13 18:57:54 riastradh Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.17 2020/06/13 18:58:26 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.16 2020/06/13 18:57:54 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.17 2020/06/13 18:58:26 riastradh Exp $");
 
 #include 
 #include 
@@ -51,16 +51,21 @@ __KERNEL_RCSID(1, "$NetBSD: sun8i_crypto
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
 #include 
 
+#include 
+
 #include 
 
 #define	SUN8I_CRYPTO_TIMEOUT	hz
@@ -110,15 +115,22 @@ struct sun8i_crypto_softc {
 		const struct sysctlnode		*cy_root_node;
 		const struct sysctlnode		*cy_trng_node;
 	}sc_sysctl;
+	struct sun8i_crypto_opencrypto {
+		uint32_t			co_driverid;
+	}sc_opencrypto;
 };
 
 struct sun8i_crypto_task {
 	struct sun8i_crypto_buf	ct_descbuf;
 	struct sun8i_crypto_taskdesc *ct_desc;
+	struct sun8i_crypto_buf	ct_ivbuf;
+	void			*ct_iv;
+	struct sun8i_crypto_buf	ct_ctrbuf;
+	void			*ct_ctr;
 	bus_dmamap_t		ct_descmap;
 	bus_dmamap_t		ct_keymap;
-	bus_dmamap_t		ct_ivmap;
-	bus_dmamap_t		ct_ctrmap;
+	bus_dmamap_t		ct_ivmap;	/* IV input */
+	bus_dmamap_t		ct_ctrmap;	/* updated IV output */
 	bus_dmamap_t		ct_srcmap;
 	bus_dmamap_t		ct_dstmap;
 	uint32_t		ct_nbytes;
@@ -159,8 +171,8 @@ static void	sun8i_crypto_task_put(struct
 static int	sun8i_crypto_task_load(struct sun8i_crypto_softc *,
 		struct sun8i_crypto_task *, uint32_t,
 		uint32_t, uint32_t, uint32_t);
-static int	sun8i_crypto_task_scatter(struct sun8i_crypto_adrlen *,
-		bus_dmamap_t, uint32_t);
+static int	sun8i_crypto_task_scatter(struct sun8i_crypto_task *,
+		struct sun8i_crypto_adrlen *, bus_dmamap_t, uint32_t);
 
 static int	sun8i_crypto_task_load_trng(struct sun8i_crypto_softc *,
 		struct sun8i_crypto_task *, uint32_t);
@@ -196,19 +208,106 @@ static int	sun8i_crypto_sysctl_rng(SYSCT
 static void	sun8i_crypto_sysctl_rng_done(struct sun8i_crypto_softc *,
 		struct sun8i_crypto_task *, void *, int);
 
+static void	sun8i_crypto_register(struct sun8i_crypto_softc *);
+static void	sun8i_crypto_register1(struct sun8i_crypto_softc *, uint32_t);
+static int	sun8i_crypto_newsession(void *, uint32_t *,
+		struct cryptoini *);
+static int	sun8i_crypto_freesession(void *, uint64_t);
+static u_int	sun8i_crypto_ivlen(const struct cryptodesc *);
+static int	sun8i_crypto_process(void *, struct cryptop *, int);
+static void	sun8i_crypto_callback(struct sun8i_crypto_softc *,
+		struct sun8i_crypto_task *, void *, int);
+
+/*
+ * Probes
+ */
+
+SDT_PROBE_DEFINE2(sdt, sun8i_crypto, register, read,
+"bus_size_t"/*reg*/,
+"uint32_t"/*value*/);
+SDT_PROBE_DEFINE2(sdt, sun8i_crypto, register, write,
+"bus_size_t"/*reg*/,
+"uint32_t"/*write*/);
+
+SDT_PROBE_DEFINE1(sdt, sun8i_crypto, task, ctor__success,
+"struct sun8i_crypto_task *"/*task*/);
+SDT_PROBE_DEFINE1(sdt, sun8i_crypto, task, ctor__failure,
+"int"/*error*/);
+SDT_PROBE_DEFINE1(sdt, sun8i_crypto, task, dtor,
+"struct sun8i_crypto_task *"/*task*/);
+SDT_PROBE_DEFINE1(sdt, sun8i_crypto, task, get,
+"struct sun8i_crypto_task *"/*task*/);
+SDT_PROBE_DEFINE1(sdt, sun8i_crypto, task, put,
+"struct sun8i_crypto_task *"/*task*/);
+
+SDT_PROBE_DEFINE6(sdt, sun8i_crypto, task, load,
+"struct sun8i_crypto_task *"/*task*/,
+"uint32_t"/*tdqc*/,
+"uint32_t"/*tdqs*/,
+"uint32_t"/*tdqa*/,
+"struct sun8i_crypto_taskdesc *"/*desc*/,
+"int"/*error*/);
+SDT_PROBE_DEFINE3(sdt, sun8i_crypto, task, misaligned,
+"struct sun8i_crypto_task *"/*task*/,
+"bus_addr_t"/*ds_addr*/,
+"bus_size_t"/*ds_len*/);
+SDT_PROBE_DEFINE2(sdt, sun8i_crypto, task, done,
+"struct sun8i_crypto_task *"/*task*/,
+"int"/*error*/);
+
+SDT_PROBE_DEFINE3(sdt, sun8i_crypto, engine, submit__failure,
+"struct sun8i_crypto_softc *"/*sc*/,
+"struct sun8i_crypto_task *"/*task*/,
+"int"/*error*/);
+SDT_PROBE_DEFINE3(sdt, sun8i_crypto, engine, submit__success,
+"struct sun8i_crypto_softc 

CVS commit: src/sys/arch/arm/sunxi

2020-06-13 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 13 18:57:54 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c sun8i_crypto.h

Log Message:
Rework sun8i crypto.

- Preallocate tasks and DMA maps together for now, for 4k transfers.
- Confine setup of the task descriptor to a single function, without
  bus_dmamap_t as an input; just use the preallocated DMA maps.
- Take the DMA map part out of sun8i_crypto_buf.
  => Not much left here, just a dmamem segment and kva mapping.

This should make it easier to use with opencrypto.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/arm/sunxi/sun8i_crypto.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/sunxi/sun8i_crypto.h

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/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.15 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.16
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.15	Sat Jun 13 18:54:38 2020
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Sat Jun 13 18:57:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.15 2020/06/13 18:54:38 riastradh Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.16 2020/06/13 18:57:54 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.15 2020/06/13 18:54:38 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.16 2020/06/13 18:57:54 riastradh Exp $");
 
 #include 
 #include 
@@ -72,7 +72,6 @@ struct sun8i_crypto_task;
 struct sun8i_crypto_buf {
 	bus_dma_segment_t	cb_seg[1];
 	int			cb_nsegs;
-	bus_dmamap_t		cb_map;
 	void			*cb_kva;
 };
 
@@ -81,6 +80,7 @@ struct sun8i_crypto_softc {
 	bus_space_tag_t			sc_bst;
 	bus_space_handle_t		sc_bsh;
 	bus_dma_tag_t			sc_dmat;
+	struct pool_cache		*sc_taskpool;
 	kmutex_t			sc_lock;
 	struct sun8i_crypto_chan {
 		struct sun8i_crypto_task	*cc_task;
@@ -113,13 +113,32 @@ struct sun8i_crypto_softc {
 };
 
 struct sun8i_crypto_task {
-	struct sun8i_crypto_buf	ct_buf;
+	struct sun8i_crypto_buf	ct_descbuf;
 	struct sun8i_crypto_taskdesc *ct_desc;
+	bus_dmamap_t		ct_descmap;
+	bus_dmamap_t		ct_keymap;
+	bus_dmamap_t		ct_ivmap;
+	bus_dmamap_t		ct_ctrmap;
+	bus_dmamap_t		ct_srcmap;
+	bus_dmamap_t		ct_dstmap;
+	uint32_t		ct_nbytes;
+	int			ct_flags;
+#define	TASK_KEY		__BIT(0)
+#define	TASK_IV			__BIT(1)
+#define	TASK_CTR		__BIT(2)
+#define	TASK_SRC		__BIT(3)
+#define	TASK_BYTES		__BIT(4) /* datalen is in bytes, not words */
 	void			(*ct_callback)(struct sun8i_crypto_softc *,
 struct sun8i_crypto_task *, void *, int);
 	void			*ct_cookie;
 };
 
+#define	SUN8I_CRYPTO_MAXDMASIZE		PAGE_SIZE
+#define	SUN8I_CRYPTO_MAXDMASEGSIZE	PAGE_SIZE
+
+CTASSERT(SUN8I_CRYPTO_MAXDMASIZE <= SUN8I_CRYPTO_MAXDATALEN);
+CTASSERT(SUN8I_CRYPTO_MAXDMASEGSIZE <= SUN8I_CRYPTO_MAXSEGLEN);
+
 /*
  * Forward declarations
  */
@@ -127,33 +146,27 @@ struct sun8i_crypto_task {
 static int	sun8i_crypto_match(device_t, cfdata_t, void *);
 static void	sun8i_crypto_attach(device_t, device_t, void *);
 
+static int	sun8i_crypto_task_ctor(void *, void *, int);
+static void	sun8i_crypto_task_dtor(void *, void *);
 static struct sun8i_crypto_task *
 		sun8i_crypto_task_get(struct sun8i_crypto_softc *,
 		void (*)(struct sun8i_crypto_softc *,
 			struct sun8i_crypto_task *, void *, int),
-		void *);
+		void *, int);
 static void	sun8i_crypto_task_put(struct sun8i_crypto_softc *,
 		struct sun8i_crypto_task *);
-static void	sun8i_crypto_task_reset(struct sun8i_crypto_task *);
 
-static void	sun8i_crypto_task_set_key(struct sun8i_crypto_task *,
-		bus_dmamap_t);
-static void	sun8i_crypto_task_set_iv(struct sun8i_crypto_task *,
-		bus_dmamap_t);
-static void	sun8i_crypto_task_set_ctr(struct sun8i_crypto_task *,
-		bus_dmamap_t);
-static void	sun8i_crypto_task_set_input(struct sun8i_crypto_task *,
-		bus_dmamap_t);
-static void	sun8i_crypto_task_set_output(struct sun8i_crypto_task *,
-		bus_dmamap_t);
+static int	sun8i_crypto_task_load(struct sun8i_crypto_softc *,
+		struct sun8i_crypto_task *, uint32_t,
+		uint32_t, uint32_t, uint32_t);
+static int	sun8i_crypto_task_scatter(struct sun8i_crypto_adrlen *,
+		bus_dmamap_t, uint32_t);
 
-static void	sun8i_crypto_task_scatter(struct sun8i_crypto_adrlen *,
-		bus_dmamap_t);
-
-static int	sun8i_crypto_submit_trng(struct sun8i_crypto_softc *,
+static int	sun8i_crypto_task_load_trng(struct sun8i_crypto_softc *,
 		struct sun8i_crypto_task *, uint32_t);
-static int	sun8i_crypto_submit_aesecb(struct sun8i_crypto_softc *,
+static int	sun8i_crypto_task_load_aesecb(struct sun8i_crypto_softc *,
 		struct sun8i_crypto_task *, uint32_t, uint32_t, uint32_t);
+
 static int	sun8i_crypto_submit(struct sun8i_crypto_softc *,
 		struct sun8i_crypto_task *);
 
@@ -165,7 +178,7 @@ static void	

CVS commit: src/sys/arch/arm/sunxi

2020-06-13 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 13 18:54:38 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c

Log Message:
Truncate hw.sun8icryptoN.rng queries to 4096 bytes.

...rather than fail entirely.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/arm/sunxi/sun8i_crypto.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/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.14 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.15
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.14	Fri May 15 19:28:09 2020
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Sat Jun 13 18:54:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.14 2020/05/15 19:28:09 maxv Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.15 2020/06/13 18:54:38 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.14 2020/05/15 19:28:09 maxv Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.15 2020/06/13 18:54:38 riastradh Exp $");
 
 #include 
 #include 
@@ -1203,10 +1203,8 @@ sun8i_crypto_sysctl_rng(SYSCTLFN_ARGS)
 		return 0;
 	}
 
-	/* Verify the output buffer size is reasonable.  */
-	size = *oldlenp;
-	if (size > 4096)	/* size_t, so never negative */
-		return E2BIG;
+	/* Truncate to 4096 bytes.  */
+	size = MIN(4096, *oldlenp);
 	if (size == 0)
 		return 0;	/* nothing to do */
 



CVS commit: src/sys/arch/arm/sunxi

2020-05-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu May  7 11:24:47 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sun4i_a10_ccu.c

Log Message:
Add A20 CLK_OUT_A and CLK_OUT_B clocks


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/arm/sunxi/sun4i_a10_ccu.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/sun4i_a10_ccu.c
diff -u src/sys/arch/arm/sunxi/sun4i_a10_ccu.c:1.11 src/sys/arch/arm/sunxi/sun4i_a10_ccu.c:1.12
--- src/sys/arch/arm/sunxi/sun4i_a10_ccu.c:1.11	Thu Aug  1 22:23:16 2019
+++ src/sys/arch/arm/sunxi/sun4i_a10_ccu.c	Thu May  7 11:24:47 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sun4i_a10_ccu.c,v 1.11 2019/08/01 22:23:16 tnn Exp $ */
+/* $NetBSD: sun4i_a10_ccu.c,v 1.12 2020/05/07 11:24:47 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sun4i_a10_ccu.c,v 1.11 2019/08/01 22:23:16 tnn Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun4i_a10_ccu.c,v 1.12 2020/05/07 11:24:47 jmcneill Exp $");
 
 #include 
 #include 
@@ -82,6 +82,8 @@ __KERNEL_RCSID(1, "$NetBSD: sun4i_a10_cc
 #define	HDMI_CLOCK_CFG_REG	0x150
 #define	MALI_CLOCK_CFG_REG	0x154
 #define	IEP_SCLK_CFG_REG	0x160
+#define	CLK_OUTA_REG		0x1f0
+#define	CLK_OUTB_REG		0x1f4
 
 static int sun4i_a10_ccu_match(device_t, cfdata_t, void *);
 static void sun4i_a10_ccu_attach(device_t, device_t, void *);
@@ -123,6 +125,7 @@ static const char *mod_parents[] = { "os
 static const char *sata_parents[] = { "pll6_periph_sata", "external" };
 static const char *de_parents[] = { "pll_video0", "pll_video1", "pll_ddr_other" };
 static const char *lcd_parents[] = { "pll_video0", "pll_video1", "pll_video0x2", "pll_video1x2" };
+static const char *out_parents[] = { "losc" /* really OSC24MHz/750 */, "losc", "osc24m" };
 
 static const struct sunxi_ccu_nkmp_tbl sun4i_a10_pll1_table[] = {
 	{ 100800, 21, 1, 0, 0 },
@@ -484,6 +487,23 @@ static struct sunxi_ccu_clk sun4i_a10_cc
 	0/* flags */
 	),
 
+	/* A20 specific */
+	SUNXI_CCU_NM(A20_CLK_OUT_A, "outa", out_parents,
+	CLK_OUTA_REG,		/* reg */
+	__BITS(21,20),		/* n */
+	__BITS(12,8),		/* m */
+	__BITS(25,24),		/* sel */
+	__BIT(31),			/* enable */
+	SUNXI_CCU_NM_POWER_OF_TWO),
+
+	SUNXI_CCU_NM(A20_CLK_OUT_B, "outb", out_parents,
+	CLK_OUTB_REG,		/* reg */
+	__BITS(21,20),		/* n */
+	__BITS(12,8),		/* m */
+	__BITS(25,24),		/* sel */
+	__BIT(31),			/* enable */
+	SUNXI_CCU_NM_POWER_OF_TWO),
+
 	/* AHB_GATING_REG0 */
 	SUNXI_CCU_GATE(A10_CLK_AHB_OTG, "ahb-otg", "ahb",
 	AHB_GATING_REG0, 0),



CVS commit: src/sys/arch/arm/sunxi

2020-03-26 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Mar 27 01:42:11 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sunxi_rtc.c

Log Message:
Add the clock providers for the sun6i_a31, sun8i_a23, sun8i_r40, sun8i_v3,
sun8i_h3, sun50i_h5 (same as H3), and sun50i_h6 RTC blocks.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sunxi/sunxi_rtc.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/sunxi_rtc.c
diff -u src/sys/arch/arm/sunxi/sunxi_rtc.c:1.5 src/sys/arch/arm/sunxi/sunxi_rtc.c:1.6
--- src/sys/arch/arm/sunxi/sunxi_rtc.c:1.5	Thu Sep  5 23:42:26 2019
+++ src/sys/arch/arm/sunxi/sunxi_rtc.c	Fri Mar 27 01:42:10 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_rtc.c,v 1.5 2019/09/05 23:42:26 thorpej Exp $ */
+/* $NetBSD: sunxi_rtc.c,v 1.6 2020/03/27 01:42:10 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_rtc.c,v 1.5 2019/09/05 23:42:26 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_rtc.c,v 1.6 2020/03/27 01:42:10 thorpej Exp $");
 
 #include 
 #include 
@@ -37,6 +37,7 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_rtc.c,
 #include 
 
 #include 
+#include 
 
 #include 
 
@@ -64,6 +65,18 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_rtc.c,
 #define	 SUN7I_RTC_SECOND	__BITS(5,0)
 #define	SUN7I_RTC_BASE_YEAR	1970
 
+#define	SUN6I_LOSC_CTRL_REG	0x00
+#define	 SUN6I_LOSC_CTRL_KEY		(0x16aa << 16)
+#define	 SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS __BIT(15)
+#define	 SUN6I_LOSC_CTRL_ALM_DHMS_ACC	__BIT(9)
+#define	 SUN6I_LOSC_CTRL_RTC_HMS_ACC	__BIT(8)
+#define	 SUN6I_LOSC_CTRL_RTC_YMD_ACC	__BIT(7)
+#define	 SUN6I_LOSC_CTRL_EXT_LOSC_EN	__BIT(4)
+#define	 SUN6I_LOSC_CTRL_EXT_OSC	__BIT(0)
+
+#define	SUN6I_INTOSC_CLK_PRESCAL_REG 0x08
+#define	 SUN6I_INTOSC_CLK_PRESCAL	__BITS(0,4)
+
 #define	SUN6I_RTC_YY_MM_DD_REG	0x10
 #define	 SUN6I_RTC_LEAP		__BIT(22)
 #define	 SUN6I_RTC_YEAR		__BITS(21,16)
@@ -76,14 +89,25 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_rtc.c,
 #define	 SUN6I_RTC_SECOND	__BITS(5,0)
 #define	SUN6I_RTC_BASE_YEAR	2000
 
+#define	SUN6I_RTC_LOSC_OUT_GATING_REG 0x60
+#define	 SUN6I_RTC_LOSC_OUT_EN	__BIT(0)
+
 struct sunxi_rtc_config {
 	bus_size_t	yy_mm_dd_reg;
 	uint32_t	leap, year, month, day;
 	bus_size_t	hh_mm_ss_reg;
 	uint32_t	wk_no, hour, minute, second;
 	u_int		base_year;
+
+	u_int		iosc_rate;
+	u_int		fixed_prescaler;
+	uint32_t	ext_losc_en;
+	uint32_t	auto_swt_bypass;
+	u_int		flags;
 };
 
+#define	SUNXI_RTC_F_HAS_VAR_PRESCALER	__BIT(0)
+
 static const struct sunxi_rtc_config sun4i_rtc_config = {
 	.yy_mm_dd_reg = SUN4I_RTC_YY_MM_DD_REG,
 	.leap = SUN4I_RTC_LEAP,
@@ -98,7 +122,7 @@ static const struct sunxi_rtc_config sun
 	.base_year = SUN4I_RTC_BASE_YEAR,
 };
 
-static const struct sunxi_rtc_config sun6i_rtc_config = {
+static const struct sunxi_rtc_config sun6i_a31_rtc_config = {
 	.yy_mm_dd_reg = SUN6I_RTC_YY_MM_DD_REG,
 	.leap = SUN6I_RTC_LEAP,
 	.year = SUN6I_RTC_YEAR,
@@ -110,6 +134,9 @@ static const struct sunxi_rtc_config sun
 	.minute = SUN6I_RTC_MINUTE,
 	.second = SUN6I_RTC_SECOND,
 	.base_year = SUN6I_RTC_BASE_YEAR,
+
+	.iosc_rate = 667000,
+	.flags = SUNXI_RTC_F_HAS_VAR_PRESCALER,
 };
 
 static const struct sunxi_rtc_config sun7i_rtc_config = {
@@ -126,21 +153,142 @@ static const struct sunxi_rtc_config sun
 	.base_year = SUN7I_RTC_BASE_YEAR,
 };
 
+static const struct sunxi_rtc_config sun8i_a23_rtc_config = {
+	.yy_mm_dd_reg = SUN6I_RTC_YY_MM_DD_REG,
+	.leap = SUN6I_RTC_LEAP,
+	.year = SUN6I_RTC_YEAR,
+	.month = SUN6I_RTC_MONTH,
+	.day = SUN6I_RTC_DAY,
+	.hh_mm_ss_reg = SUN6I_RTC_HH_MM_SS_REG,
+	.wk_no = SUN6I_RTC_WK_NO,
+	.hour = SUN6I_RTC_HOUR,
+	.minute = SUN6I_RTC_MINUTE,
+	.second = SUN6I_RTC_SECOND,
+	.base_year = SUN6I_RTC_BASE_YEAR,
+
+	.iosc_rate = 667000,
+	.flags = SUNXI_RTC_F_HAS_VAR_PRESCALER,
+};
+
+static const struct sunxi_rtc_config sun8i_r40_rtc_config = {
+	.yy_mm_dd_reg = SUN6I_RTC_YY_MM_DD_REG,
+	.leap = SUN6I_RTC_LEAP,
+	.year = SUN6I_RTC_YEAR,
+	.month = SUN6I_RTC_MONTH,
+	.day = SUN6I_RTC_DAY,
+	.hh_mm_ss_reg = SUN6I_RTC_HH_MM_SS_REG,
+	.wk_no = SUN6I_RTC_WK_NO,
+	.hour = SUN6I_RTC_HOUR,
+	.minute = SUN6I_RTC_MINUTE,
+	.second = SUN6I_RTC_SECOND,
+	.base_year = SUN6I_RTC_BASE_YEAR,
+
+	.iosc_rate = 1600,
+	.fixed_prescaler = 512,
+};
+
+static const struct sunxi_rtc_config sun8i_v3_rtc_config = {
+	.yy_mm_dd_reg = SUN6I_RTC_YY_MM_DD_REG,
+	.leap = SUN6I_RTC_LEAP,
+	.year = SUN6I_RTC_YEAR,
+	.month = SUN6I_RTC_MONTH,
+	.day = SUN6I_RTC_DAY,
+	.hh_mm_ss_reg = SUN6I_RTC_HH_MM_SS_REG,
+	.wk_no = SUN6I_RTC_WK_NO,
+	.hour = SUN6I_RTC_HOUR,
+	.minute = SUN6I_RTC_MINUTE,
+	.second = SUN6I_RTC_SECOND,
+	.base_year = SUN6I_RTC_BASE_YEAR,
+
+	.iosc_rate = 32000,
+};
+
+static const struct sunxi_rtc_config sun8i_h3_rtc_config = {
+	.yy_mm_dd_reg = SUN6I_RTC_YY_MM_DD_REG,
+	.leap = SUN6I_RTC_LEAP,
+	.year = SUN6I_RTC_YEAR,
+	.month = SUN6I_RTC_MONTH,
+	.day = 

CVS commit: src/sys/arch/arm/sunxi

2020-03-06 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Sat Mar  7 00:51:10 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sunxi_mmc.c

Log Message:
enable DDR and HS200 modes only on boards which claim to support them
with this eMMC works on libretech,all-h3-cc-h5
also tested on pinebook
ok jmcneill@


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/arm/sunxi/sunxi_mmc.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/sunxi_mmc.c
diff -u src/sys/arch/arm/sunxi/sunxi_mmc.c:1.40 src/sys/arch/arm/sunxi/sunxi_mmc.c:1.41
--- src/sys/arch/arm/sunxi/sunxi_mmc.c:1.40	Sat Oct  5 12:09:01 2019
+++ src/sys/arch/arm/sunxi/sunxi_mmc.c	Sat Mar  7 00:51:10 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mmc.c,v 1.40 2019/10/05 12:09:01 jmcneill Exp $ */
+/* $NetBSD: sunxi_mmc.c,v 1.41 2020/03/07 00:51:10 macallan Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_sunximmc.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mmc.c,v 1.40 2019/10/05 12:09:01 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mmc.c,v 1.41 2020/03/07 00:51:10 macallan Exp $");
 
 #include 
 #include 
@@ -547,6 +547,14 @@ sunxi_mmc_attach_i(device_t self)
 	const u_int flags = sc->sc_config->flags;
 	struct sdmmcbus_attach_args saa;
 	uint32_t width;
+	const bool supports_hs200 =
+		of_hasprop(sc->sc_phandle, "mmc-hs200-1_2v") |
+		of_hasprop(sc->sc_phandle, "mmc-hs200-1_8v");
+
+	const bool supports_ddr =
+		of_hasprop(sc->sc_phandle, "mmc-ddr-1_2v") |
+		of_hasprop(sc->sc_phandle, "mmc-ddr-1_8v") |
+		of_hasprop(sc->sc_phandle, "mmc-ddr-3_3v");
 
 	if (sc->sc_pwrseq)
 		fdtbus_mmc_pwrseq_pre_power_on(sc->sc_pwrseq);
@@ -577,10 +585,11 @@ sunxi_mmc_attach_i(device_t self)
 		   SMC_CAPS_SD_HIGHSPEED |
 		   SMC_CAPS_MMC_HIGHSPEED;
 
-	if (sc->sc_config->delays || (flags & SUNXI_MMC_FLAG_NEW_TIMINGS))
+	if ((sc->sc_config->delays || (flags & SUNXI_MMC_FLAG_NEW_TIMINGS)) &&
+	 supports_ddr)
 		saa.saa_caps |= SMC_CAPS_MMC_DDR52;
 
-	if (flags & SUNXI_MMC_FLAG_HS200)
+	if ((flags & SUNXI_MMC_FLAG_HS200) != 0 && supports_hs200)
 		saa.saa_caps |= SMC_CAPS_MMC_HS200;
 
 	if (width == 4)



CVS commit: src/sys/arch/arm/sunxi

2020-02-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Feb 16 20:29:36 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sunxi_nmi.c

Log Message:
Provide a back-end for fdt_intr_mask() / fdt_intr_unmask().


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sunxi/sunxi_nmi.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/sunxi_nmi.c
diff -u src/sys/arch/arm/sunxi/sunxi_nmi.c:1.4 src/sys/arch/arm/sunxi/sunxi_nmi.c:1.5
--- src/sys/arch/arm/sunxi/sunxi_nmi.c:1.4	Tue Jan  7 10:20:07 2020
+++ src/sys/arch/arm/sunxi/sunxi_nmi.c	Sun Feb 16 20:29:36 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_nmi.c,v 1.4 2020/01/07 10:20:07 skrll Exp $ */
+/* $NetBSD: sunxi_nmi.c,v 1.5 2020/02/16 20:29:36 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -29,7 +29,7 @@
 #define	_INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_nmi.c,v 1.4 2020/01/07 10:20:07 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_nmi.c,v 1.5 2020/02/16 20:29:36 thorpej Exp $");
 
 #include 
 #include 
@@ -37,6 +37,8 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_nmi.c,
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 #include 
@@ -99,10 +101,12 @@ struct sunxi_nmi_softc {
 	bus_space_handle_t sc_bsh;
 	int sc_phandle;
 
+	kmutex_t sc_intr_lock;
+
 	const struct sunxi_nmi_config *sc_config;
 
-	int (*sc_func)(void *);
-	void *sc_arg;
+	struct intrsource sc_is;
+	void	*sc_ih;
 };
 
 #define NMI_READ(sc, reg) \
@@ -148,11 +152,17 @@ static int
 sunxi_nmi_intr(void *priv)
 {
 	struct sunxi_nmi_softc * const sc = priv;
+	int (*func)(void *);
 	int rv = 0;
 
-	if (sc->sc_func)
-		rv = sc->sc_func(sc->sc_arg);
-
+	func = atomic_load_acquire(>sc_is.is_func);
+	if (func)
+		rv = func(sc->sc_is.is_arg);
+
+	/*
+	 * We don't serialize access to this register because we're the
+	 * only thing fiddling wth it.
+	 */
 	sunxi_nmi_irq_ack(sc);
 
 	return rv;
@@ -164,19 +174,13 @@ sunxi_nmi_fdt_establish(device_t dev, u_
 {
 	struct sunxi_nmi_softc * const sc = device_private(dev);
 	u_int irq_type;
+	int ist;
 
 	/* 1st cell is the interrupt number */
 	const u_int irq = be32toh(specifier[0]);
 	/* 2nd cell is polarity */
 	const u_int pol = be32toh(specifier[1]);
 
-	if (sc->sc_func != NULL) {
-#ifdef DIAGNOSTIC
-		device_printf(dev, "%s in use\n", sc->sc_config->name);
-#endif
-		return NULL;
-	}
-
 	if (irq != 0) {
 #ifdef DIAGNOSTIC
 		device_printf(dev, "IRQ %u is invalid\n", irq);
@@ -187,42 +191,100 @@ sunxi_nmi_fdt_establish(device_t dev, u_
 	switch (pol & 0x7) {
 	case 1:	/* IRQ_TYPE_EDGE_RISING */
 		irq_type = NMI_CTRL_IRQ_HIGH_EDGE;
+		ist = IST_EDGE;
 		break;
 	case 2:	/* IRQ_TYPE_EDGE_FALLING */
 		irq_type = NMI_CTRL_IRQ_LOW_EDGE;
+		ist = IST_EDGE;
 		break;
 	case 3:	/* IRQ_TYPE_LEVEL_HIGH */
 		irq_type = NMI_CTRL_IRQ_HIGH_LEVEL;
+		ist = IST_LEVEL;
 		break;
 	case 4:	/* IRQ_TYPE_LEVEL_LOW */
 		irq_type = NMI_CTRL_IRQ_LOW_LEVEL;
+		ist = IST_LEVEL;
 		break;
 	default:
 		irq_type = NMI_CTRL_IRQ_LOW_LEVEL;
+		ist = IST_LEVEL;
 		break;
 	}
 
-	sc->sc_func = func;
-	sc->sc_arg = arg;
+	mutex_enter(>sc_intr_lock);
+
+	if (atomic_load_relaxed(>sc_is.is_func) != NULL) {
+		mutex_exit(>sc_intr_lock);
+#ifdef DIAGNOSTIC
+		device_printf(dev, "%s in use\n", sc->sc_config->name);
+#endif
+		return NULL;
+	}
+
+	sc->sc_is.is_arg = arg;
+	atomic_store_release(>sc_is.is_func, func);
+
+	sc->sc_is.is_type = ist;
+	sc->sc_is.is_ipl = ipl;
+	sc->sc_is.is_mpsafe = (flags & FDT_INTR_MPSAFE) ? true : false;
+
+	mutex_exit(>sc_intr_lock);
+
+	sc->sc_ih = fdtbus_intr_establish(sc->sc_phandle, 0, ipl, flags,
+	sunxi_nmi_intr, sc);
 
+	mutex_enter(>sc_intr_lock);
 	sunxi_nmi_irq_set_type(sc, irq_type);
 	sunxi_nmi_irq_enable(sc, true);
+	mutex_exit(>sc_intr_lock);
 
-	return fdtbus_intr_establish(sc->sc_phandle, 0, ipl, flags,
-	sunxi_nmi_intr, sc);
+	return >sc_is;
+}
+
+static void
+sunxi_nmi_fdt_mask(device_t dev, void *ih __unused)
+{
+	struct sunxi_nmi_softc * const sc = device_private(dev);
+
+	mutex_enter(>sc_intr_lock);
+	if (sc->sc_is.is_mask_count++ == 0) {
+		sunxi_nmi_irq_enable(sc, false);
+	}
+	mutex_exit(>sc_intr_lock);
+}
+
+static void
+sunxi_nmi_fdt_unmask(device_t dev, void *ih __unused)
+{
+	struct sunxi_nmi_softc * const sc = device_private(dev);
+
+	mutex_enter(>sc_intr_lock);
+	if (sc->sc_is.is_mask_count-- == 1) {
+		sunxi_nmi_irq_enable(sc, true);
+	}
+	mutex_exit(>sc_intr_lock);
 }
 
 static void
 sunxi_nmi_fdt_disestablish(device_t dev, void *ih)
 {
 	struct sunxi_nmi_softc * const sc = device_private(dev);
+	struct intrsource * const is = ih;
+
+	KASSERT(is == >sc_is);
 
+	mutex_enter(>sc_intr_lock);
 	sunxi_nmi_irq_enable(sc, false);
+	is->is_mask_count = 0;
+	mutex_exit(>sc_intr_lock);
 
-	fdtbus_intr_disestablish(sc->sc_phandle, ih);
+	fdtbus_intr_disestablish(sc->sc_phandle, sc->sc_ih);
+	sc->sc_ih = NULL;
 
-	sc->sc_func = NULL;
-	

CVS commit: src/sys/arch/arm/sunxi

2020-02-09 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sun Feb  9 15:22:25 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sunxi_mixer.c

Log Message:
Improve compatibility with newer A64 DE2 DTB endpoint numbers.

Should fix video output with new Linux 5.5rc DTBs on A64/H2/H3/H5-based SoCs.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/arm/sunxi/sunxi_mixer.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/sunxi_mixer.c
diff -u src/sys/arch/arm/sunxi/sunxi_mixer.c:1.10 src/sys/arch/arm/sunxi/sunxi_mixer.c:1.11
--- src/sys/arch/arm/sunxi/sunxi_mixer.c:1.10	Sat Nov 23 23:47:57 2019
+++ src/sys/arch/arm/sunxi/sunxi_mixer.c	Sun Feb  9 15:22:25 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mixer.c,v 1.10 2019/11/23 23:47:57 jmcneill Exp $ */
+/* $NetBSD: sunxi_mixer.c,v 1.11 2020/02/09 15:22:25 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.c,v 1.10 2019/11/23 23:47:57 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.c,v 1.11 2020/02/09 15:22:25 jakllsch Exp $");
 
 #include 
 #include 
@@ -173,10 +173,25 @@ enum {
 	MIXER_PORT_OUTPUT = 1,
 };
 
+struct sunxi_mixer_compat_data {
+	uint8_t ovl_ui_count;
+	uint8_t mixer_index;
+};
+
+struct sunxi_mixer_compat_data mixer0_data = {
+	.ovl_ui_count = 3,
+	.mixer_index = 0,
+};
+
+struct sunxi_mixer_compat_data mixer1_data = {
+	.ovl_ui_count = 1,
+	.mixer_index = 1,
+};
+
 static const struct of_compat_data compat_data[] = {
-	{ "allwinner,sun8i-h3-de2-mixer-0",	3 },
-	{ "allwinner,sun50i-a64-de2-mixer-0",	3 },
-	{ "allwinner,sun50i-a64-de2-mixer-1",	1 },
+	{ "allwinner,sun8i-h3-de2-mixer-0",	(uintptr_t)_data },
+	{ "allwinner,sun50i-a64-de2-mixer-0",	(uintptr_t)_data },
+	{ "allwinner,sun50i-a64-de2-mixer-1",	(uintptr_t)_data },
 	{ NULL }
 };
 
@@ -1230,6 +1245,8 @@ sunxi_mixer_attach(device_t parent, devi
 	struct fdt_attach_args * const faa = aux;
 	struct fdt_endpoint *out_ep;
 	const int phandle = faa->faa_phandle;
+	const struct sunxi_mixer_compat_data * const cd =
+	(const void *)of_search_compatible(phandle, compat_data)->data;
 	struct clk *clk_bus, *clk_mod;
 	struct fdtbus_reset *rst;
 	bus_addr_t addr;
@@ -1267,7 +1284,7 @@ sunxi_mixer_attach(device_t parent, devi
 		return;
 	}
 	sc->sc_phandle = faa->faa_phandle;
-	sc->sc_ovl_ui_count = of_search_compatible(phandle, compat_data)->data;
+	sc->sc_ovl_ui_count = cd->ovl_ui_count;
 
 	aprint_naive("\n");
 	aprint_normal(": Display Engine Mixer\n");
@@ -1276,7 +1293,14 @@ sunxi_mixer_attach(device_t parent, devi
 	sc->sc_ports.dp_ep_get_data = sunxi_mixer_ep_get_data;
 	fdt_ports_register(>sc_ports, self, phandle, EP_DRM_CRTC);
 
-	out_ep = fdt_endpoint_get_from_index(>sc_ports, MIXER_PORT_OUTPUT, 0);
+	out_ep = fdt_endpoint_get_from_index(>sc_ports,
+	MIXER_PORT_OUTPUT, cd->mixer_index);
+	if (out_ep == NULL) {
+		/* Couldn't find new-style DE2 endpoint, try old style. */
+		out_ep = fdt_endpoint_get_from_index(>sc_ports,
+		MIXER_PORT_OUTPUT, 0);
+	}
+
 	if (out_ep != NULL)
 		sunxi_drm_register_endpoint(phandle, out_ep);
 }



CVS commit: src/sys/arch/arm/sunxi

2020-02-06 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Feb  6 19:52:09 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c

Log Message:
Fix previous brainfart.

Don't use the uninitialized trng node as the root node -- derp.
Instead, use the root node as the root node, and initialize the trng
node here.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/arm/sunxi/sun8i_crypto.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/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.11 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.12
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.11	Mon Jan 20 16:29:38 2020
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Thu Feb  6 19:52:09 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.11 2020/01/20 16:29:38 riastradh Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.12 2020/02/06 19:52:09 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.11 2020/01/20 16:29:38 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.12 2020/02/06 19:52:09 riastradh Exp $");
 
 #include 
 #include 
@@ -1177,7 +1177,7 @@ sun8i_crypto_sysctl_attach(struct sun8i_
 	}
 
 	/* hw.sun8icryptoN.rng (`struct', 4096-byte array) */
-	sysctl_createv(>cy_log, 0, >cy_trng_node, NULL,
+	sysctl_createv(>cy_log, 0, >cy_root_node, >cy_trng_node,
 	CTLFLAG_PERMANENT|CTLFLAG_READONLY|CTLFLAG_PRIVATE, CTLTYPE_STRUCT,
 	"rng", SYSCTL_DESCR("Read up to 4096 bytes out of the TRNG"),
 	_crypto_sysctl_rng, 0, sc, 0, CTL_CREATE, CTL_EOL);



CVS commit: src/sys/arch/arm/sunxi

2020-01-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jan 20 16:29:38 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c

Log Message:
Fix (presently harmless) psato.

Don't overwrite cy_root_node; use cy_trng_node as intended.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/arm/sunxi/sun8i_crypto.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/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.10 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.11
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.10	Sun Jan 12 21:52:36 2020
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Mon Jan 20 16:29:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.10 2020/01/12 21:52:36 riastradh Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.11 2020/01/20 16:29:38 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.10 2020/01/12 21:52:36 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.11 2020/01/20 16:29:38 riastradh Exp $");
 
 #include 
 #include 
@@ -1177,7 +1177,7 @@ sun8i_crypto_sysctl_attach(struct sun8i_
 	}
 
 	/* hw.sun8icryptoN.rng (`struct', 4096-byte array) */
-	sysctl_createv(>cy_log, 0, >cy_root_node, NULL,
+	sysctl_createv(>cy_log, 0, >cy_trng_node, NULL,
 	CTLFLAG_PERMANENT|CTLFLAG_READONLY|CTLFLAG_PRIVATE, CTLTYPE_STRUCT,
 	"rng", SYSCTL_DESCR("Read up to 4096 bytes out of the TRNG"),
 	_crypto_sysctl_rng, 0, sc, 0, CTL_CREATE, CTL_EOL);



CVS commit: src/sys/arch/arm/sunxi

2019-12-23 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Dec 23 18:20:02 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_hdmi.c

Log Message:
No need to use I2C_F_POLL here.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/arm/sunxi/sunxi_hdmi.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/sunxi_hdmi.c
diff -u src/sys/arch/arm/sunxi/sunxi_hdmi.c:1.9 src/sys/arch/arm/sunxi/sunxi_hdmi.c:1.10
--- src/sys/arch/arm/sunxi/sunxi_hdmi.c:1.9	Mon Dec 23 00:24:02 2019
+++ src/sys/arch/arm/sunxi/sunxi_hdmi.c	Mon Dec 23 18:20:02 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_hdmi.c,v 1.9 2019/12/23 00:24:02 thorpej Exp $ */
+/* $NetBSD: sunxi_hdmi.c,v 1.10 2019/12/23 18:20:02 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2014 Jared D. McNeill 
@@ -29,7 +29,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_hdmi.c,v 1.9 2019/12/23 00:24:02 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_hdmi.c,v 1.10 2019/12/23 18:20:02 thorpej Exp $");
 
 #include 
 #include 
@@ -637,14 +637,14 @@ sunxi_hdmi_read_edid_block(struct sunxi_
 	uint8_t wbuf[2];
 	int error;
 
-	if ((error = iic_acquire_bus(tag, I2C_F_POLL)) != 0)
+	if ((error = iic_acquire_bus(tag, 0)) != 0)
 		return error;
 
 	wbuf[0] = block;	/* start address */
 
 	error = iic_exec(tag, I2C_OP_READ_WITH_STOP, DDC_ADDR, wbuf, 1,
-	data, EDID_BLOCK_SIZE, I2C_F_POLL);
-	iic_release_bus(tag, I2C_F_POLL);
+	data, EDID_BLOCK_SIZE, 0);
+	iic_release_bus(tag, 0);
 	return error;
 }
 



CVS commit: src/sys/arch/arm/sunxi

2019-12-22 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Dec 23 00:24:02 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_hdmi.c

Log Message:
When deciding to delay (rather than kpause), pay attention to
I2C_F_POLL, not 'cold'.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/arm/sunxi/sunxi_hdmi.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/sunxi_hdmi.c
diff -u src/sys/arch/arm/sunxi/sunxi_hdmi.c:1.8 src/sys/arch/arm/sunxi/sunxi_hdmi.c:1.9
--- src/sys/arch/arm/sunxi/sunxi_hdmi.c:1.8	Sun Dec 22 23:23:30 2019
+++ src/sys/arch/arm/sunxi/sunxi_hdmi.c	Mon Dec 23 00:24:02 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_hdmi.c,v 1.8 2019/12/22 23:23:30 thorpej Exp $ */
+/* $NetBSD: sunxi_hdmi.c,v 1.9 2019/12/23 00:24:02 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2014 Jared D. McNeill 
@@ -29,7 +29,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_hdmi.c,v 1.8 2019/12/22 23:23:30 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_hdmi.c,v 1.9 2019/12/23 00:24:02 thorpej Exp $");
 
 #include 
 #include 
@@ -408,7 +408,7 @@ sunxi_hdmi_i2c_xfer_1_4(void *priv, i2c_
 		val = HDMI_READ(sc, SUNXI_A31_HDMI_DDC_CTRL_REG);
 		if ((val & SUNXI_A31_HDMI_DDC_CTRL_ACCESS_CMD_START) == 0)
 			break;
-		if (cold)
+		if (flags & I2C_F_POLL)
 			delay(1000);
 		else
 			kpause("hdmiddc", false, mstohz(10), >sc_exec_lock);



CVS commit: src/sys/arch/arm/sunxi

2019-12-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Dec 18 02:26:48 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c

Log Message:
Reduce entropy estimate for sun8icrypto TRNG.

NIST's SP800-90B entropy estimation tools put it at no more than .08
bits of entropy per byte of data(!), so estimate 100 bits of data per
bit of entropy.  This is probably not conservative enough -- the NIST
tools were written without knowledge of how this alleged TRNG works!
Knowledge of the physics of how the TRNG is supposed to work could
probably enable a better job at predicting the outputs.

While here, bump the size of data we can sample directly with sysctl
to 4096 bytes.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/arm/sunxi/sun8i_crypto.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/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.8 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.9
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.8	Sun Dec 15 01:16:33 2019
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Wed Dec 18 02:26:48 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.8 2019/12/15 01:16:33 riastradh Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.9 2019/12/18 02:26:48 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.8 2019/12/15 01:16:33 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.9 2019/12/18 02:26:48 riastradh Exp $");
 
 #include 
 #include 
@@ -65,9 +65,8 @@ __KERNEL_RCSID(1, "$NetBSD: sun8i_crypto
 #include 
 
 #define	SUN8I_CRYPTO_TIMEOUT	hz
-#define	SUN8I_CRYPTO_RNGENTROPY	8 /* estimated bits per bit of entropy */
-#define	SUN8I_CRYPTO_RNGBYTES		  \
-	(SUN8I_CRYPTO_RNGENTROPY*howmany(RND_POOLBITS, NBBY))
+#define	SUN8I_CRYPTO_RNGENTROPY	100 /* estimated bits per bit of entropy */
+#define	SUN8I_CRYPTO_RNGBYTES	PAGE_SIZE
 
 struct sun8i_crypto_task;
 
@@ -964,8 +963,8 @@ sun8i_crypto_rng_done(struct sun8i_crypt
 	 * This TRNG has quite low entropy at best.  But if it fails a
 	 * repeated output test, then assume it's busted.
 	 */
-	CTASSERT((SUN8I_CRYPTO_RNGBYTES % SUN8I_CRYPTO_RNGENTROPY) == 0);
-	entropybits = NBBY * (SUN8I_CRYPTO_RNGBYTES/SUN8I_CRYPTO_RNGENTROPY);
+	CTASSERT(SUN8I_CRYPTO_RNGBYTES <= UINT32_MAX/NBBY);
+	entropybits = (NBBY*SUN8I_CRYPTO_RNGBYTES)/SUN8I_CRYPTO_RNGENTROPY;
 	if (consttime_memequal(buf, buf + SUN8I_CRYPTO_RNGBYTES/2,
 		SUN8I_CRYPTO_RNGBYTES/2)) {
 		device_printf(sc->sc_dev, "failed repeated output test\n");
@@ -1171,10 +1170,10 @@ sun8i_crypto_sysctl_attach(struct sun8i_
 		return;
 	}
 
-	/* hw.sun8icryptoN.rng (`struct', 1024-byte array) */
+	/* hw.sun8icryptoN.rng (`struct', 4096-byte array) */
 	sysctl_createv(>cy_log, 0, >cy_root_node, NULL,
 	CTLFLAG_PERMANENT|CTLFLAG_READONLY|CTLFLAG_PRIVATE, CTLTYPE_STRUCT,
-	"rng", SYSCTL_DESCR("Read up to 1024 bytes out of the TRNG"),
+	"rng", SYSCTL_DESCR("Read up to 4096 bytes out of the TRNG"),
 	_crypto_sysctl_rng, 0, sc, 0, CTL_CREATE, CTL_EOL);
 	if (error) {
 		aprint_error_dev(sc->sc_dev,
@@ -1195,13 +1194,13 @@ sun8i_crypto_sysctl_rng(SYSCTLFN_ARGS)
 
 	/* If oldp == NULL, the caller wants to learn the size.  */
 	if (oldp == NULL) {
-		*oldlenp = 1024;
+		*oldlenp = 4096;
 		return 0;
 	}
 
 	/* Verify the output buffer size is reasonable.  */
 	size = *oldlenp;
-	if (size > 1024)	/* size_t, so never negative */
+	if (size > 4096)	/* size_t, so never negative */
 		return E2BIG;
 	if (size == 0)
 		return 0;	/* nothing to do */



CVS commit: src/sys/arch/arm/sunxi

2019-12-16 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Dec 16 12:40:17 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_drm.c

Log Message:
Make sure memory stolen from simplefb is page aligned.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/arm/sunxi/sunxi_drm.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/sunxi_drm.c
diff -u src/sys/arch/arm/sunxi/sunxi_drm.c:1.10 src/sys/arch/arm/sunxi/sunxi_drm.c:1.11
--- src/sys/arch/arm/sunxi/sunxi_drm.c:1.10	Sun Dec 15 01:00:58 2019
+++ src/sys/arch/arm/sunxi/sunxi_drm.c	Mon Dec 16 12:40:17 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_drm.c,v 1.10 2019/12/15 01:00:58 mrg Exp $ */
+/* $NetBSD: sunxi_drm.c,v 1.11 2019/12/16 12:40:17 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.10 2019/12/15 01:00:58 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.11 2019/12/16 12:40:17 jmcneill Exp $");
 
 #include 
 #include 
@@ -53,6 +53,14 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,
 #define	SUNXI_DRM_MAX_WIDTH	3840
 #define	SUNXI_DRM_MAX_HEIGHT	2160
 
+/*
+ * The DRM headers break trunc_page/round_page macros with a redefinition
+ * of PAGE_MASK. Use our own macros instead.
+ */
+#define	SUNXI_PAGE_MASK		(PAGE_SIZE - 1)
+#define	SUNXI_TRUNC_PAGE(x)	((x) & ~SUNXI_PAGE_MASK)
+#define	SUNXI_ROUND_PAGE(x)	(((x) + SUNXI_PAGE_MASK) & ~SUNXI_PAGE_MASK)
+
 static TAILQ_HEAD(, sunxi_drm_endpoint) sunxi_drm_endpoints =
 TAILQ_HEAD_INITIALIZER(sunxi_drm_endpoints);
 
@@ -299,7 +307,8 @@ static int
 sunxi_drm_simplefb_lookup(bus_addr_t *paddr, bus_size_t *psize)
 {
 	static const char * compat[] = { "simple-framebuffer", NULL };
-	int chosen, child;
+	int chosen, child, error;
+	bus_addr_t addr_end;
 
 	chosen = OF_finddevice("/chosen");
 	if (chosen == -1)
@@ -310,7 +319,15 @@ sunxi_drm_simplefb_lookup(bus_addr_t *pa
 			continue;
 		if (!of_match_compatible(child, compat))
 			continue;
-		return fdtbus_get_reg(child, 0, paddr, psize);
+		error = fdtbus_get_reg(child, 0, paddr, psize);
+		if (error != 0)
+			return error;
+
+		/* Reclaim entire pages used by the simplefb */
+		addr_end = *paddr + *psize;
+		*paddr = SUNXI_TRUNC_PAGE(*paddr);
+		*psize = SUNXI_ROUND_PAGE(addr_end - *paddr);
+		return 0;
 	}
 
 	return ENOENT;



CVS commit: src/sys/arch/arm/sunxi

2019-12-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 15 01:16:33 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c

Log Message:
Fix typo -- acknowledge interrupts _and_ errors.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sunxi/sun8i_crypto.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/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.7 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.8
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.7	Tue Dec 10 22:30:34 2019
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Sun Dec 15 01:16:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.7 2019/12/10 22:30:34 riastradh Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.8 2019/12/15 01:16:33 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.7 2019/12/10 22:30:34 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.8 2019/12/15 01:16:33 riastradh Exp $");
 
 #include 
 #include 
@@ -671,7 +671,7 @@ sun8i_crypto_intr(void *cookie)
 	isr = sun8i_crypto_read(sc, SUN8I_CRYPTO_ISR);
 	esr = sun8i_crypto_read(sc, SUN8I_CRYPTO_ESR);
 	sun8i_crypto_write(sc, SUN8I_CRYPTO_ISR, isr);
-	sun8i_crypto_write(sc, SUN8I_CRYPTO_ISR, esr);
+	sun8i_crypto_write(sc, SUN8I_CRYPTO_ESR, esr);
 
 	/* Start the worker if necessary.  */
 	sun8i_crypto_schedule_worker(sc);



CVS commit: src/sys/arch/arm/sunxi

2019-12-10 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Dec 10 22:30:34 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c

Log Message:
Oops -- forgot to kmem_free.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sunxi/sun8i_crypto.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/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.6 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.7
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.6	Mon Dec  9 14:56:44 2019
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Tue Dec 10 22:30:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.6 2019/12/09 14:56:44 riastradh Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.7 2019/12/10 22:30:34 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.6 2019/12/09 14:56:44 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.7 2019/12/10 22:30:34 riastradh Exp $");
 
 #include 
 #include 
@@ -1295,6 +1295,7 @@ out2:	sun8i_crypto_task_put(sc, req->cu_
 out1:	sun8i_crypto_freebuf(sc, req->cu_size, >cu_buf);
 out0:	cv_destroy(>cu_cv);
 	mutex_destroy(>cu_lock);
+	kmem_free(req, sizeof(*req));
 	return error;
 }
 
@@ -1328,4 +1329,5 @@ sun8i_crypto_sysctl_rng_done(struct sun8
 	sun8i_crypto_freebuf(sc, req->cu_size, >cu_buf);
 	cv_destroy(>cu_cv);
 	mutex_destroy(>cu_lock);
+	kmem_free(req, sizeof(*req));
 }



CVS commit: src/sys/arch/arm/sunxi

2019-12-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Dec  9 14:55:52 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c

Log Message:
Reduce some duplicated bus_dma clutter.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/sunxi/sun8i_crypto.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/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.1 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.2
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.1	Mon Dec  9 04:51:03 2019
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Mon Dec  9 14:55:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.1 2019/12/09 04:51:03 riastradh Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.2 2019/12/09 14:55:52 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.1 2019/12/09 04:51:03 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.2 2019/12/09 14:55:52 riastradh Exp $");
 
 #include 
 #include 
@@ -115,10 +115,7 @@ struct sun8i_crypto_softc {
 };
 
 struct sun8i_crypto_task {
-	bus_dma_segment_t	ct_desc_seg[1];
-	int			ct_desc_nseg;
-	bus_dmamap_t		ct_desc_map;
-	void			*ct_desc_kva;
+	struct sun8i_crypto_buf	ct_buf;
 	struct sun8i_crypto_taskdesc *ct_desc;
 	void			(*ct_callback)(struct sun8i_crypto_softc *,
 struct sun8i_crypto_task *, void *, int);
@@ -329,48 +326,25 @@ sun8i_crypto_task_get(struct sun8i_crypt
 void *cookie)
 {
 	struct sun8i_crypto_task *task;
-	const size_t desc_size = sizeof(*task->ct_desc);
 	int error;
 
+	/* Allocate a task.  */
 	task = kmem_zalloc(sizeof(*task), KM_SLEEP);
 
-	/* Allocate DMA-safe memory for the descriptor.  */
-	error = bus_dmamem_alloc(sc->sc_dmat, desc_size, 0, 0,
-	task->ct_desc_seg, __arraycount(task->ct_desc_seg),
-	>ct_desc_nseg, BUS_DMA_NOWAIT);
+	/* Allocate a buffer for the descriptor.  */
+	error = sun8i_crypto_allocbuf(sc, sizeof(*task->ct_desc),
+	>ct_buf);
 	if (error)
 		goto fail0;
 
-	/* Map the descriptor into kernel virtual address space.  */
-	error = bus_dmamem_map(sc->sc_dmat, task->ct_desc_seg,
-	task->ct_desc_nseg, desc_size, >ct_desc_kva, BUS_DMA_NOWAIT);
-	if (error)
-		goto fail1;
-	task->ct_desc = task->ct_desc_kva;
-
-	/* Create a map for exposing the descriptor to DMA.  */
-	error = bus_dmamap_create(sc->sc_dmat, desc_size, 1, desc_size, 0,
-	BUS_DMA_NOWAIT, >ct_desc_map);
-	if (error)
-		goto fail2;
-
-	/* Load the descriptor into the DMA map.  */
-	error = bus_dmamap_load(sc->sc_dmat, task->ct_desc_map,
-	task->ct_desc_kva, desc_size, NULL, BUS_DMA_NOWAIT);
-	if (error)
-		goto fail3;
-
+	/* Initialize the task object and return it.  */
+	task->ct_desc = task->ct_buf.cb_kva;
 	task->ct_callback = callback;
 	task->ct_cookie = cookie;
-
 	return task;
 
-fail4: __unused
-	bus_dmamap_unload(sc->sc_dmat, task->ct_desc_map);
-fail3:	bus_dmamap_destroy(sc->sc_dmat, task->ct_desc_map);
-fail2:	bus_dmamem_unmap(sc->sc_dmat, task->ct_desc_kva,
-	sizeof(*task->ct_desc));
-fail1:	bus_dmamem_free(sc->sc_dmat, task->ct_desc_seg, task->ct_desc_nseg);
+fail1: __unused
+	sun8i_crypto_freebuf(sc, sizeof(*task->ct_desc), >ct_buf);
 fail0:	kmem_free(task, sizeof(*task));
 	return NULL;
 }
@@ -380,11 +354,7 @@ sun8i_crypto_task_put(struct sun8i_crypt
 struct sun8i_crypto_task *task)
 {
 
-	bus_dmamap_unload(sc->sc_dmat, task->ct_desc_map);
-	bus_dmamap_destroy(sc->sc_dmat, task->ct_desc_map);
-	bus_dmamem_unmap(sc->sc_dmat, task->ct_desc_kva,
-	sizeof(*task->ct_desc));
-	bus_dmamem_free(sc->sc_dmat, task->ct_desc_seg, task->ct_desc_nseg);
+	sun8i_crypto_freebuf(sc, sizeof(*task->ct_desc), >ct_buf);
 	kmem_free(task, sizeof(*task));
 }
 
@@ -604,7 +574,7 @@ sun8i_crypto_submit(struct sun8i_crypto_
 	task->ct_desc->td_cid = htole32(i);
 
 	/* Prepare to send the descriptor to the device by DMA.  */
-	bus_dmamap_sync(sc->sc_dmat, task->ct_desc_map, 0,
+	bus_dmamap_sync(sc->sc_dmat, task->ct_buf.cb_map, 0,
 	sizeof(*task->ct_desc), BUS_DMASYNC_PREWRITE);
 
 	/* Confirm we're ready to go.  */
@@ -622,7 +592,7 @@ sun8i_crypto_submit(struct sun8i_crypto_
 
 	/* Set the task descriptor queue address.  */
 	sun8i_crypto_write(sc, SUN8I_CRYPTO_TDQ,
-	task->ct_desc_map->dm_segs[0].ds_addr);
+	task->ct_buf.cb_map->dm_segs[0].ds_addr);
 
 	/* Notify the engine to load it, and wait for acknowledgement.  */
 	sun8i_crypto_write(sc, SUN8I_CRYPTO_TLR, SUN8I_CRYPTO_TLR_LOAD);
@@ -819,7 +789,7 @@ sun8i_crypto_chan_done(struct sun8i_cryp
 	sun8i_crypto_write(sc, SUN8I_CRYPTO_ICR, icr);
 
 	/* Finished sending the descriptor to the device by DMA.  */
-	bus_dmamap_sync(sc->sc_dmat, task->ct_desc_map, 0,
+	bus_dmamap_sync(sc->sc_dmat, task->ct_buf.cb_map, 0,
 	sizeof(*task->ct_desc), BUS_DMASYNC_POSTWRITE);
 
 	/* Temporarily release the lock to 

CVS commit: src/sys/arch/arm/sunxi

2019-12-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Dec  9 14:56:06 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c

Log Message:
Factor out some of the self-test logic used for debugging.

Add missing bus_dmamap_sync(POSTWRITE) while here.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sun8i_crypto.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/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.2 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.3
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.2	Mon Dec  9 14:55:52 2019
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Mon Dec  9 14:56:06 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.2 2019/12/09 14:55:52 riastradh Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.3 2019/12/09 14:56:06 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.2 2019/12/09 14:55:52 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.3 2019/12/09 14:56:06 riastradh Exp $");
 
 #include 
 #include 
@@ -981,9 +981,9 @@ out:	/* Done -- clear the RNG-pending fl
  * Self-test
  */
 
-static uint8_t selftest_input[16];
-static uint8_t selftest_key[16];
-static uint8_t selftest_output[16] = {
+static const uint8_t selftest_input[16];
+static const uint8_t selftest_key[16];
+static const uint8_t selftest_output[16] = {
 	0x66,0xe9,0x4b,0xd4,0xef,0x8a,0x2c,0x3b,
 	0x88,0x4c,0xfa,0x59,0xca,0x34,0x2b,0x2e,
 };
@@ -1061,70 +1061,65 @@ fail1:	sun8i_crypto_freebuf(sc, sizeof s
 fail0:	aprint_error_dev(self, "failed to run self-test, error=%d\n", error);
 }
 
+static bool
+sun8i_crypto_selftest_check(struct sun8i_crypto_softc *sc, const char *title,
+size_t n, const void *expected, const void *actual)
+{
+	const uint8_t *e = expected;
+	const uint8_t *a = actual;
+	size_t i;
+
+	if (memcmp(e, a, n) == 0)
+		return true;
+
+	device_printf(sc->sc_dev, "self-test: %s\n", title);
+	printf("expected: ");
+	for (i = 0; i < n; i++)
+		printf("%02hhx", e[i]);
+	printf("\n");
+	printf("actual:   ");
+	for (i = 0; i < n; i++)
+		printf("%02hhx", a[i]);
+	printf("\n");
+	return false;
+}
+
 static void
 sun8i_crypto_selftest_done(struct sun8i_crypto_softc *sc,
 struct sun8i_crypto_task *task, void *cookie, int error)
 {
 	struct sun8i_crypto_selftest *selftest = cookie;
-	unsigned i;
 	bool ok = true;
 
 	KASSERT(selftest == >sc_selftest);
 
+	/*
+	 * Finished the DMA read into the output buffer, and finished
+	 * the DMA writes from the key buffer and input buffer.
+	 */
 	bus_dmamap_sync(sc->sc_dmat, selftest->cs_out.cb_map, 0,
 	sizeof selftest_output, BUS_DMASYNC_POSTREAD);
+	bus_dmamap_sync(sc->sc_dmat, selftest->cs_key.cb_map, 0,
+	sizeof selftest_key, BUS_DMASYNC_POSTWRITE);
 	bus_dmamap_sync(sc->sc_dmat, selftest->cs_in.cb_map, 0,
 	sizeof selftest_input, BUS_DMASYNC_POSTWRITE);
 
+	/* If anything went wrong, fail now.  */
 	if (error) {
 		device_printf(sc->sc_dev, "self-test error=%d\n", error);
 		goto out;
 	}
 
-	if (memcmp(selftest_input, selftest->cs_in.cb_kva,
-		sizeof selftest_input) != 0) {
-		device_printf(sc->sc_dev, "self-test: input clobbered\n");
-		printf("expected: ");
-		for (i = 0; i < sizeof selftest_input; i++)
-			printf("%02hhx", selftest_input[i]);
-		printf("\n");
-		printf("actual:   ");
-		for (i = 0; i < sizeof selftest_input; i++)
-			printf("%02hhx",
-			((const uint8_t *)selftest->cs_in.cb_kva)[i]);
-		printf("\n");
-		ok = false;
-	}
-
-	if (memcmp(selftest_key, selftest->cs_key.cb_kva,
-		sizeof selftest_key) != 0) {
-		device_printf(sc->sc_dev, "self-test: key clobbered\n");
-		printf("expected: ");
-		for (i = 0; i < sizeof selftest_key; i++)
-			printf("%02hhx", selftest_key[i]);
-		printf("\n");
-		printf("actual:   ");
-		for (i = 0; i < sizeof selftest_key; i++)
-			printf("%02hhx",
-			((const uint8_t *)selftest->cs_key.cb_kva)[i]);
-		printf("\n");
-		ok = false;
-	}
-
-	if (memcmp(selftest_output, selftest->cs_out.cb_kva,
-		sizeof selftest_output) != 0) {
-		device_printf(sc->sc_dev, "self-test: output mismatch\n");
-		printf("expected: ");
-		for (i = 0; i < sizeof selftest_output; i++)
-			printf("%02hhx", selftest_output[i]);
-		printf("\n");
-		printf("actual:   ");
-		for (i = 0; i < sizeof selftest_output; i++)
-			printf("%02hhx",
-			((const uint8_t *)selftest->cs_out.cb_kva)[i]);
-		printf("\n");
-		ok = false;
-	}
+	/*
+	 * Verify the input and key weren't clobbered, and verify the
+	 * output matches what we expect.
+	 */
+	ok &= sun8i_crypto_selftest_check(sc, "input clobbered",
+	sizeof selftest_input, selftest_input, selftest->cs_in.cb_kva);
+	ok &= sun8i_crypto_selftest_check(sc, "key clobbered",
+	sizeof selftest_key, selftest_key, selftest->cs_key.cb_kva);
+	ok &= sun8i_crypto_selftest_check(sc, 

CVS commit: src/sys/arch/arm/sunxi

2019-12-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Dec  9 14:56:18 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c

Log Message:
Make sure ERESTART doesn't come flying out to userland.

I picked ERESTART to mean `all channels are occupied' because that's
what opencrypto(9) uses to decide whether to queue a request, but
it's not appropriate for sysctl(2) to return that.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sunxi/sun8i_crypto.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/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.3 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.4
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.3	Mon Dec  9 14:56:06 2019
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Mon Dec  9 14:56:18 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.3 2019/12/09 14:56:06 riastradh Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.4 2019/12/09 14:56:18 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.3 2019/12/09 14:56:06 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.4 2019/12/09 14:56:18 riastradh Exp $");
 
 #include 
 #include 
@@ -1232,8 +1232,11 @@ sun8i_crypto_sysctl_rng(SYSCTLFN_ARGS)
 
 	/* Submit the TRNG task.  */
 	error = sun8i_crypto_submit_trng(sc, req->cu_task, size);
-	if (error)
+	if (error) {
+		if (error == ERESTART)
+			error = EBUSY;
 		goto out2;
+	}
 
 	/* Wait for the request to complete.  */
 	mutex_enter(>cu_lock);



CVS commit: src/sys/arch/arm/sunxi

2019-12-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Dec  9 14:56:44 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c

Log Message:
Tidy up comments.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sunxi/sun8i_crypto.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/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.5 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.6
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.5	Mon Dec  9 14:56:30 2019
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Mon Dec  9 14:56:44 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.5 2019/12/09 14:56:30 riastradh Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.6 2019/12/09 14:56:44 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.5 2019/12/09 14:56:30 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.6 2019/12/09 14:56:44 riastradh Exp $");
 
 #include 
 #include 
@@ -731,14 +731,17 @@ sun8i_crypto_worker(struct work *wk, voi
 
 	/* Process the channels.  */
 	for (i = 0; i < SUN8I_CRYPTO_NCHAN; i++) {
+		/* Check whether the channel is done.  */
 		if (!ISSET(done, SUN8I_CRYPTO_ISR_DONE_CHAN(i))) {
-			/* Check to see if we have a task that timed out.  */
+			/* Nope.  Do we have a task to time out?  */
 			if ((sc->sc_chan[i].cc_task != NULL) &&
 			((now - sc->sc_chan[i].cc_starttime) >=
 SUN8I_CRYPTO_TIMEOUT))
 sun8i_crypto_chan_done(sc, i, ETIMEDOUT);
 			continue;
 		}
+
+		/* Channel is done.  Interpret the error if any.  */
 		esr_chan = __SHIFTOUT(esr, SUN8I_CRYPTO_ESR_CHAN(i));
 		if (esr_chan & SUN8I_CRYPTO_ESR_CHAN_ALGNOTSUP) {
 			device_printf(sc->sc_dev, "channel %u:"
@@ -758,7 +761,10 @@ sun8i_crypto_worker(struct work *wk, voi
 			error = 0;
 		}
 
-		/* May release the lock to invoke a callback.  */
+		/*
+		 * Notify the task of completion.  May release the lock
+		 * to invoke a callback.
+		 */
 		sun8i_crypto_chan_done(sc, i, error);
 	}
 
@@ -1152,6 +1158,7 @@ sun8i_crypto_sysctl_attach(struct sun8i_
 	struct sun8i_crypto_sysctl *cy = >sc_sysctl;
 	int error;
 
+	/* hw.sun8icryptoN (node) */
 	error = sysctl_createv(>cy_log, 0, NULL, >cy_root_node,
 	CTLFLAG_PERMANENT, CTLTYPE_NODE, device_xname(sc->sc_dev),
 	SYSCTL_DESCR("sun8i crypto engine knobs"),
@@ -1164,6 +1171,7 @@ sun8i_crypto_sysctl_attach(struct sun8i_
 		return;
 	}
 
+	/* hw.sun8icryptoN.rng (`struct', 1024-byte array) */
 	sysctl_createv(>cy_log, 0, >cy_root_node, NULL,
 	CTLFLAG_PERMANENT|CTLFLAG_READONLY|CTLFLAG_PRIVATE, CTLTYPE_STRUCT,
 	"rng", SYSCTL_DESCR("Read up to 1024 bytes out of the TRNG"),



CVS commit: src/sys/arch/arm/sunxi

2019-12-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Dec  9 14:56:30 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c

Log Message:
Avoid a race between interruption and reacquisition of lock.

Otherwise, we would have leaked the memory in this case.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sunxi/sun8i_crypto.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/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.4 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.5
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.4	Mon Dec  9 14:56:18 2019
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Mon Dec  9 14:56:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.4 2019/12/09 14:56:18 riastradh Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.5 2019/12/09 14:56:30 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.4 2019/12/09 14:56:18 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.5 2019/12/09 14:56:30 riastradh Exp $");
 
 #include 
 #include 
@@ -1244,10 +1244,15 @@ sun8i_crypto_sysctl_rng(SYSCTLFN_ARGS)
 		error = cv_wait_sig(>cu_cv, >cu_lock);
 		if (error) {
 			/*
-			 * Never mind -- notify the callback that it
-			 * has to clean up after itself.
+			 * If we finished while waiting to acquire the
+			 * lock, ignore the error and just return now.
+			 * Otherwise, notify the callback that it has
+			 * to clean up after us.
 			 */
-			req->cu_cancel = true;
+			if (req->cu_done)
+error = 0;
+			else
+req->cu_cancel = true;
 			break;
 		}
 	}
@@ -1277,6 +1282,7 @@ sun8i_crypto_sysctl_rng(SYSCTLFN_ARGS)
 	/* Clear the buffer.  */
 	explicit_memset(req->cu_buf.cb_kva, 0, size);
 
+	/* Clean up.  */
 out2:	sun8i_crypto_task_put(sc, req->cu_task);
 out1:	sun8i_crypto_freebuf(sc, req->cu_size, >cu_buf);
 out0:	cv_destroy(>cu_cv);
@@ -1309,7 +1315,7 @@ sun8i_crypto_sysctl_rng_done(struct sun8
 	if (!cancel)
 		return;
 
-	/* Clean up.  */
+	/* Clean up after the main thread cancelled.  */
 	sun8i_crypto_task_put(sc, req->cu_task);
 	sun8i_crypto_freebuf(sc, req->cu_size, >cu_buf);
 	cv_destroy(>cu_cv);



CVS commit: src/sys/arch/arm/sunxi

2019-12-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec  8 18:13:24 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun50i_a64_ccu.c

Log Message:
Add SUNXI_CCU_NM_ROUND_DOWN to CE clock, fix pll parents to use 2X outputs


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/arm/sunxi/sun50i_a64_ccu.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/sun50i_a64_ccu.c
diff -u src/sys/arch/arm/sunxi/sun50i_a64_ccu.c:1.21 src/sys/arch/arm/sunxi/sun50i_a64_ccu.c:1.22
--- src/sys/arch/arm/sunxi/sun50i_a64_ccu.c:1.21	Sun Dec  8 00:12:20 2019
+++ src/sys/arch/arm/sunxi/sun50i_a64_ccu.c	Sun Dec  8 18:13:24 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun50i_a64_ccu.c,v 1.21 2019/12/08 00:12:20 jmcneill Exp $ */
+/* $NetBSD: sun50i_a64_ccu.c,v 1.22 2019/12/08 18:13:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sun50i_a64_ccu.c,v 1.21 2019/12/08 00:12:20 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun50i_a64_ccu.c,v 1.22 2019/12/08 18:13:24 jmcneill Exp $");
 
 #include 
 #include 
@@ -157,7 +157,7 @@ static const char *ahb1_parents[] = { "l
 static const char *ahb2_parents[] = { "ahb1", "pll_periph0" };
 static const char *apb1_parents[] = { "ahb1" };
 static const char *apb2_parents[] = { "losc", "hosc", "pll_periph0" };
-static const char *ce_parents[] = { "hosc", "pll_periph0", "pll_periph1", NULL };
+static const char *ce_parents[] = { "hosc", "pll_periph0_2x", "pll_periph1_2x" };
 static const char *mmc_parents[] = { "hosc", "pll_periph0_2x", "pll_periph1_2x" };
 static const char *ths_parents[] = { "hosc", NULL, NULL, NULL };
 static const char *de_parents[] = { "pll_periph0_2x", "pll_de" };
@@ -405,7 +405,7 @@ static struct sunxi_ccu_clk sun50i_a64_c
 	__BITS(3,0),	/* m */
 	__BITS(25,24),	/* sel */
 	__BIT(31),		/* enable */
-	SUNXI_CCU_NM_POWER_OF_TWO),
+	SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN),
 
 	SUNXI_CCU_DIV_GATE(A64_CLK_THS, "ths", ths_parents,
 	THS_CLK_REG,	/* reg */



CVS commit: src/sys/arch/arm/sunxi

2019-12-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec  8 00:12:20 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun50i_a64_ccu.c

Log Message:
Add crypto engine clock


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/arm/sunxi/sun50i_a64_ccu.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/sun50i_a64_ccu.c
diff -u src/sys/arch/arm/sunxi/sun50i_a64_ccu.c:1.20 src/sys/arch/arm/sunxi/sun50i_a64_ccu.c:1.21
--- src/sys/arch/arm/sunxi/sun50i_a64_ccu.c:1.20	Sun Nov 24 10:27:37 2019
+++ src/sys/arch/arm/sunxi/sun50i_a64_ccu.c	Sun Dec  8 00:12:20 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun50i_a64_ccu.c,v 1.20 2019/11/24 10:27:37 jmcneill Exp $ */
+/* $NetBSD: sun50i_a64_ccu.c,v 1.21 2019/12/08 00:12:20 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sun50i_a64_ccu.c,v 1.20 2019/11/24 10:27:37 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun50i_a64_ccu.c,v 1.21 2019/12/08 00:12:20 jmcneill Exp $");
 
 #include 
 #include 
@@ -60,6 +60,7 @@ __KERNEL_RCSID(1, "$NetBSD: sun50i_a64_c
 #define	SDMMC0_CLK_REG		0x088
 #define	SDMMC1_CLK_REG		0x08c
 #define	SDMMC2_CLK_REG		0x090
+#define	CE_CLK_REG		0x09c
 #define	SPI0_CLK_REG		0x0a0
 #define	SPI1_CLK_REG		0x0a4
 #define	I2SPCM0_CLK_REG		0x0b0
@@ -156,6 +157,7 @@ static const char *ahb1_parents[] = { "l
 static const char *ahb2_parents[] = { "ahb1", "pll_periph0" };
 static const char *apb1_parents[] = { "ahb1" };
 static const char *apb2_parents[] = { "losc", "hosc", "pll_periph0" };
+static const char *ce_parents[] = { "hosc", "pll_periph0", "pll_periph1", NULL };
 static const char *mmc_parents[] = { "hosc", "pll_periph0_2x", "pll_periph1_2x" };
 static const char *ths_parents[] = { "hosc", NULL, NULL, NULL };
 static const char *de_parents[] = { "pll_periph0_2x", "pll_de" };
@@ -397,6 +399,14 @@ static struct sunxi_ccu_clk sun50i_a64_c
 	__BIT(31),		/* enable */
 	SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN|SUNXI_CCU_NM_DIVIDE_BY_TWO),
 
+	SUNXI_CCU_NM(A64_CLK_CE, "ce", ce_parents,
+	CE_CLK_REG,		/* reg */
+	__BITS(17,16),	/* n */
+	__BITS(3,0),	/* m */
+	__BITS(25,24),	/* sel */
+	__BIT(31),		/* enable */
+	SUNXI_CCU_NM_POWER_OF_TWO),
+
 	SUNXI_CCU_DIV_GATE(A64_CLK_THS, "ths", ths_parents,
 	THS_CLK_REG,	/* reg */
 	__BITS(1,0),	/* div */



CVS commit: src/sys/arch/arm/sunxi

2019-05-08 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu May  9 01:46:37 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_emac.c

Log Message:
Protect ether_multi list

The list can be racy if NET_MPSAFE is enabled and the driver is executed without
KERNEL_LOCK.

Fix PR 54153


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/arm/sunxi/sunxi_emac.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/sunxi_emac.c
diff -u src/sys/arch/arm/sunxi/sunxi_emac.c:1.25 src/sys/arch/arm/sunxi/sunxi_emac.c:1.26
--- src/sys/arch/arm/sunxi/sunxi_emac.c:1.25	Mon Apr 22 14:53:51 2019
+++ src/sys/arch/arm/sunxi/sunxi_emac.c	Thu May  9 01:46:37 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_emac.c,v 1.25 2019/04/22 14:53:51 maya Exp $ */
+/* $NetBSD: sunxi_emac.c,v 1.26 2019/05/09 01:46:37 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 2016-2017 Jared McNeill 
@@ -33,7 +33,7 @@
 #include "opt_net_mpsafe.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.25 2019/04/22 14:53:51 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.26 2019/05/09 01:46:37 ozaki-r Exp $");
 
 #include 
 #include 
@@ -543,6 +543,7 @@ sunxi_emac_setup_rxfilter(struct sunxi_e
 		hash[0] = hash[1] = ~0;
 	} else {
 		val |= HASH_MULTICAST;
+		ETHER_LOCK(>ec);
 		ETHER_FIRST_MULTI(step, >ec, enm);
 		while (enm != NULL) {
 			crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN);
@@ -553,6 +554,7 @@ sunxi_emac_setup_rxfilter(struct sunxi_e
 			hash[hashreg] |= (1 << hashbit);
 			ETHER_NEXT_MULTI(step, enm);
 		}
+		ETHER_UNLOCK(>ec);
 	}
 
 	/* Write our unicast address */



CVS commit: src/sys/arch/arm/sunxi

2019-05-08 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed May  8 09:53:43 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun4i_emac.c

Log Message:
Protect ether_multi list

PR 54153


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sunxi/sun4i_emac.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/sun4i_emac.c
diff -u src/sys/arch/arm/sunxi/sun4i_emac.c:1.7 src/sys/arch/arm/sunxi/sun4i_emac.c:1.8
--- src/sys/arch/arm/sunxi/sun4i_emac.c:1.7	Mon Apr 22 07:51:16 2019
+++ src/sys/arch/arm/sunxi/sun4i_emac.c	Wed May  8 09:53:43 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun4i_emac.c,v 1.7 2019/04/22 07:51:16 msaitoh Exp $ */
+/* $NetBSD: sun4i_emac.c,v 1.8 2019/05/08 09:53:43 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 2013-2017 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sun4i_emac.c,v 1.7 2019/04/22 07:51:16 msaitoh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun4i_emac.c,v 1.8 2019/05/08 09:53:43 ozaki-r Exp $");
 
 #include 
 #include 
@@ -864,9 +864,11 @@ sun4i_emac_rx_hash(struct sun4i_emac_sof
 	if ((ifp->if_flags & IFF_PROMISC) == 0) {
 		hash[0] = hash[1] = 0;
 
+		ETHER_LOCK(>sc_ec);
 		ETHER_FIRST_MULTI(step, >sc_ec, enm);
 		while (enm != NULL) {
 			if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
+ETHER_UNLOCK(>sc_ec);
 /*
  * We must listen to a range of multicast addresses.
  * For now, just accept all multicasts, rather than
@@ -889,6 +891,7 @@ sun4i_emac_rx_hash(struct sun4i_emac_sof
 			hash[crc >> 5] |= __BIT(crc & 31);
 	ETHER_NEXT_MULTI(step, enm);
 		}
+		ETHER_UNLOCK(>sc_ec);
 		ifp->if_flags &= ~IFF_ALLMULTI;
 		rxctl |= EMAC_RX_CTL_MHF;
 	}



CVS commit: src/sys/arch/arm/sunxi

2019-04-30 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Apr 30 10:10:45 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_platform.c

Log Message:
turn on the "sun50i-a64-unstable-timer" workaround on "allwinner,sun8i-a83t"
compatible CPUs.  avoids triggering the KASSERT() on cubietruck plus.

idea from jmcneill.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/arm/sunxi/sunxi_platform.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/sunxi_platform.c
diff -u src/sys/arch/arm/sunxi/sunxi_platform.c:1.35 src/sys/arch/arm/sunxi/sunxi_platform.c:1.36
--- src/sys/arch/arm/sunxi/sunxi_platform.c:1.35	Sun Feb  3 15:43:57 2019
+++ src/sys/arch/arm/sunxi/sunxi_platform.c	Tue Apr 30 10:10:45 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_platform.c,v 1.35 2019/02/03 15:43:57 jmcneill Exp $ */
+/* $NetBSD: sunxi_platform.c,v 1.36 2019/04/30 10:10:45 mrg Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -31,7 +31,7 @@
 #include "opt_console.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_platform.c,v 1.35 2019/02/03 15:43:57 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_platform.c,v 1.36 2019/04/30 10:10:45 mrg Exp $");
 
 #include 
 #include 
@@ -219,6 +219,8 @@ sunxi_platform_device_register(device_t 
 		/* Allwinner A64 has an unstable architectural timer */
 		const char * compat[] = {
 			"allwinner,sun50i-a64",
+			/* Cubietruck Plus triggers this problem as well. */
+			"allwinner,sun8i-a83t",
 			NULL
 		};
 		if (of_match_compatible(OF_finddevice("/"), compat)) {



CVS commit: src/sys/arch/arm/sunxi

2019-04-22 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Mon Apr 22 14:53:51 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_emac.c

Log Message:
remove unused mii to fix the build


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/arm/sunxi/sunxi_emac.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/sunxi_emac.c
diff -u src/sys/arch/arm/sunxi/sunxi_emac.c:1.24 src/sys/arch/arm/sunxi/sunxi_emac.c:1.25
--- src/sys/arch/arm/sunxi/sunxi_emac.c:1.24	Mon Apr 22 08:05:01 2019
+++ src/sys/arch/arm/sunxi/sunxi_emac.c	Mon Apr 22 14:53:51 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_emac.c,v 1.24 2019/04/22 08:05:01 msaitoh Exp $ */
+/* $NetBSD: sunxi_emac.c,v 1.25 2019/04/22 14:53:51 maya Exp $ */
 
 /*-
  * Copyright (c) 2016-2017 Jared McNeill 
@@ -33,7 +33,7 @@
 #include "opt_net_mpsafe.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.24 2019/04/22 08:05:01 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.25 2019/04/22 14:53:51 maya Exp $");
 
 #include 
 #include 
@@ -908,7 +908,6 @@ static int
 sunxi_emac_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct sunxi_emac_softc *sc = ifp->if_softc;
-	struct mii_data *mii = >mii;
 	int error, s;
 
 #ifndef EMAC_MPSAFE



CVS commit: src/sys/arch/arm/sunxi

2019-03-27 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Wed Mar 27 16:38:50 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_timer.c

Log Message:
ensure LOSC is configured for external clock


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sunxi/sunxi_timer.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/sunxi_timer.c
diff -u src/sys/arch/arm/sunxi/sunxi_timer.c:1.5 src/sys/arch/arm/sunxi/sunxi_timer.c:1.6
--- src/sys/arch/arm/sunxi/sunxi_timer.c:1.5	Wed Mar 27 06:56:19 2019
+++ src/sys/arch/arm/sunxi/sunxi_timer.c	Wed Mar 27 16:38:49 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_timer.c,v 1.5 2019/03/27 06:56:19 tnn Exp $ */
+/* $NetBSD: sunxi_timer.c,v 1.6 2019/03/27 16:38:49 tnn Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_timer.c,v 1.5 2019/03/27 06:56:19 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_timer.c,v 1.6 2019/03/27 16:38:49 tnn Exp $");
 
 #include 
 #include 
@@ -78,6 +78,19 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_timer.
 #define	TMR4_INTV_VALUE_REG	0x54
 #define	TMR4_CURNT_VALUE_REG	0x58
 
+/* Control registers */
+#define	AVS_CNT_CTL_REG		0x80
+#define	AVS_CNT0_REG		0x84
+#define	AVS_CNT1_REG		0x88
+#define	AVS_CNT_DIV_REG		0x8c
+#define	WDOG_CTRL_REG		0x90
+#define	WDOG_MODE_REG		0x94
+#define	LOSC_CTRL_REG		0x100
+#define	 LOSC_CTRL_KEY_FIELD	__BITS(31,16)
+#define	 LOSC_CTRL_KEY_FIELD_V	0x16aa
+#define  LOSC_CTRL_OSC32K_AUTO_SWT_EN	__BIT(14)
+#define	 LOSC_CTRL_OSC32K_SEL	__BIT(0)
+
 static const char * const compatible[] = {
 	"allwinner,sun4i-a10-timer",
 	NULL
@@ -179,6 +192,7 @@ sunxi_timer_attach(device_t parent, devi
 	bus_addr_t addr;
 	bus_size_t size;
 	u_int ticks;
+	u_int reg;
 
 	if (fdtbus_get_reg(phandle, 0, , ) != 0) {
 		aprint_error(": couldn't get registers\n");
@@ -238,10 +252,16 @@ sunxi_timer_attach(device_t parent, devi
 	 * LOSC is optional to implement in hardware.
 	 * Make sure it ticks before registering it.
 	 */
+	reg = __SHIFTIN(LOSC_CTRL_KEY_FIELD_V, LOSC_CTRL_KEY_FIELD) |
+	LOSC_CTRL_OSC32K_AUTO_SWT_EN |
+	LOSC_CTRL_OSC32K_SEL;
+	TIMER_WRITE(sc, LOSC_CTRL_REG, reg);
 	ticks = sunxi_timer_get_timecount_losc(tc_losc);
 	delay(100);
 	if (ticks != sunxi_timer_get_timecount_losc(tc_losc))
 		tc_init(tc_losc);
+	else
+		TIMER_WRITE(sc, LOSC_CTRL_REG, reg & ~LOSC_CTRL_OSC32K_SEL);
 
 	/* Use this as the OS timer in UP configurations */
 	if (!arm_has_mpext_p) {



CVS commit: src/sys/arch/arm/sunxi

2019-03-27 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Wed Mar 27 06:56:19 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_timer.c

Log Message:
fix wrong counter_mask assignment due to typo in previous


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sunxi/sunxi_timer.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/sunxi_timer.c
diff -u src/sys/arch/arm/sunxi/sunxi_timer.c:1.4 src/sys/arch/arm/sunxi/sunxi_timer.c:1.5
--- src/sys/arch/arm/sunxi/sunxi_timer.c:1.4	Tue Mar 26 23:26:03 2019
+++ src/sys/arch/arm/sunxi/sunxi_timer.c	Wed Mar 27 06:56:19 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_timer.c,v 1.4 2019/03/26 23:26:03 tnn Exp $ */
+/* $NetBSD: sunxi_timer.c,v 1.5 2019/03/27 06:56:19 tnn Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_timer.c,v 1.4 2019/03/26 23:26:03 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_timer.c,v 1.5 2019/03/27 06:56:19 tnn Exp $");
 
 #include 
 #include 
@@ -229,7 +229,7 @@ sunxi_timer_attach(device_t parent, devi
 	tc->tc_priv = sc;
 	tc_init(tc);
 	tc_losc->tc_get_timecount = sunxi_timer_get_timecount_losc;
-	tc_losc->tc_counter_mask = ~0u,
+	tc_losc->tc_counter_mask = ~0u;
 	tc_losc->tc_frequency = 32768;
 	tc_losc->tc_name = "LOSC";
 	tc_losc->tc_quality = 150;



CVS commit: src/sys/arch/arm/sunxi

2019-03-26 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Tue Mar 26 23:26:03 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_timer.c

Log Message:
Register a timecounter source for the 32.768kHz low-power oscillator,
if it is physically present. It is preferable for timekeeping in
offline scenarios because it generally has much better long-term
frequency stability than the platform XO.

XXX: should it have higher quality rating than the 24MOSC?
I made it lower quality for now to avoid surprises for users.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sunxi/sunxi_timer.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/sunxi_timer.c
diff -u src/sys/arch/arm/sunxi/sunxi_timer.c:1.3 src/sys/arch/arm/sunxi/sunxi_timer.c:1.4
--- src/sys/arch/arm/sunxi/sunxi_timer.c:1.3	Sat Dec 16 20:04:38 2017
+++ src/sys/arch/arm/sunxi/sunxi_timer.c	Tue Mar 26 23:26:03 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_timer.c,v 1.3 2017/12/16 20:04:38 jmcneill Exp $ */
+/* $NetBSD: sunxi_timer.c,v 1.4 2019/03/26 23:26:03 tnn Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_timer.c,v 1.3 2017/12/16 20:04:38 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_timer.c,v 1.4 2019/03/26 23:26:03 tnn Exp $");
 
 #include 
 #include 
@@ -71,6 +71,13 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_timer.
 #define	TMR2_INTV_VALUE_REG	0x34
 #define	TMR2_CURNT_VALUE_REG	0x38
 
+/* Timer 4 registers */
+#define	TMR4_CTRL_REG		0x50
+#define	 TMR4_CTRL_RELOAD	__BIT(1)
+#define	 TMR4_CTRL_EN		__BIT(0)
+#define	TMR4_INTV_VALUE_REG	0x54
+#define	TMR4_CURNT_VALUE_REG	0x58
+
 static const char * const compatible[] = {
 	"allwinner,sun4i-a10-timer",
 	NULL
@@ -84,6 +91,7 @@ struct sunxi_timer_softc {
 	struct clk *sc_clk;
 
 	struct timecounter sc_tc;
+	struct timecounter sc_tc_losc;
 };
 
 #define TIMER_READ(sc, reg) \
@@ -144,6 +152,14 @@ sunxi_timer_get_timecount(struct timecou
 	return ~TIMER_READ(sc, TMR2_CURNT_VALUE_REG);
 }
 
+static u_int
+sunxi_timer_get_timecount_losc(struct timecounter *tc)
+{
+	struct sunxi_timer_softc * const sc = tc->tc_priv;
+
+	return ~TIMER_READ(sc, TMR4_CURNT_VALUE_REG);
+}
+
 static int
 sunxi_timer_match(device_t parent, cfdata_t cf, void *aux)
 {
@@ -158,9 +174,11 @@ sunxi_timer_attach(device_t parent, devi
 	struct sunxi_timer_softc * const sc = device_private(self);
 	struct fdt_attach_args * const faa = aux;
 	struct timecounter *tc = >sc_tc;
+	struct timecounter *tc_losc = >sc_tc_losc;
 	const int phandle = faa->faa_phandle;
 	bus_addr_t addr;
 	bus_size_t size;
+	u_int ticks;
 
 	if (fdtbus_get_reg(phandle, 0, , ) != 0) {
 		aprint_error(": couldn't get registers\n");
@@ -198,15 +216,32 @@ sunxi_timer_attach(device_t parent, devi
 	TIMER_WRITE(sc, TMR2_CTRL_REG,
 	__SHIFTIN(TMR2_CTRL_CLK_SRC_OSC24M, TMR2_CTRL_CLK_SRC) |
 	TMR2_CTRL_RELOAD | TMR2_CTRL_EN);
+	/* Enable Timer 4 (timecounter for LOSC) */
+	TIMER_WRITE(sc, TMR4_INTV_VALUE_REG, ~0u);
+	TIMER_WRITE(sc, TMR4_CTRL_REG, TMR4_CTRL_RELOAD | TMR4_CTRL_EN);
 
 	/* Timecounter setup */
 	tc->tc_get_timecount = sunxi_timer_get_timecount;
 	tc->tc_counter_mask = ~0u,
-	tc->tc_frequency = clk_get_rate(sc->sc_clk);
+	tc->tc_frequency = rate;
 	tc->tc_name = "Timer 2";
 	tc->tc_quality = 200;
 	tc->tc_priv = sc;
 	tc_init(tc);
+	tc_losc->tc_get_timecount = sunxi_timer_get_timecount_losc;
+	tc_losc->tc_counter_mask = ~0u,
+	tc_losc->tc_frequency = 32768;
+	tc_losc->tc_name = "LOSC";
+	tc_losc->tc_quality = 150;
+	tc_losc->tc_priv = sc;
+	/*
+	 * LOSC is optional to implement in hardware.
+	 * Make sure it ticks before registering it.
+	 */
+	ticks = sunxi_timer_get_timecount_losc(tc_losc);
+	delay(100);
+	if (ticks != sunxi_timer_get_timecount_losc(tc_losc))
+		tc_init(tc_losc);
 
 	/* Use this as the OS timer in UP configurations */
 	if (!arm_has_mpext_p) {



CVS commit: src/sys/arch/arm/sunxi

2019-03-06 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Wed Mar  6 19:16:53 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun6i_dma.c

Log Message:
Hint more strongly that "#if maybenever" is also "#if notyet".


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/arm/sunxi/sun6i_dma.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/sun6i_dma.c
diff -u src/sys/arch/arm/sunxi/sun6i_dma.c:1.8 src/sys/arch/arm/sunxi/sun6i_dma.c:1.9
--- src/sys/arch/arm/sunxi/sun6i_dma.c:1.8	Sat Mar  2 16:55:13 2019
+++ src/sys/arch/arm/sunxi/sun6i_dma.c	Wed Mar  6 19:16:53 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun6i_dma.c,v 1.8 2019/03/02 16:55:13 jakllsch Exp $ */
+/* $NetBSD: sun6i_dma.c,v 1.9 2019/03/06 19:16:53 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sun6i_dma.c,v 1.8 2019/03/02 16:55:13 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun6i_dma.c,v 1.9 2019/03/06 19:16:53 jakllsch Exp $");
 
 #include 
 #include 
@@ -335,7 +335,7 @@ sun6idma_transfer(device_t dev, void *pr
 			desc[j].dma_next = htole32(DMA_NULL);
 	}
 
-#if maybenever
+#if notyet && maybenever
 	DMA_WRITE(sc, DMA_MODE_REG(ch->ch_index),
 	DMA_MODE_DST(MODE_HANDSHAKE)|DMA_MODE_SRC(MODE_HANDSHAKE));
 #endif



CVS commit: src/sys/arch/arm/sunxi

2019-03-04 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Mar  4 11:35:38 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_emac.c

Log Message:
Enable hw csum offload by default


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/arm/sunxi/sunxi_emac.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/sunxi_emac.c
diff -u src/sys/arch/arm/sunxi/sunxi_emac.c:1.21 src/sys/arch/arm/sunxi/sunxi_emac.c:1.22
--- src/sys/arch/arm/sunxi/sunxi_emac.c:1.21	Tue Jan 22 03:42:25 2019
+++ src/sys/arch/arm/sunxi/sunxi_emac.c	Mon Mar  4 11:35:38 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_emac.c,v 1.21 2019/01/22 03:42:25 msaitoh Exp $ */
+/* $NetBSD: sunxi_emac.c,v 1.22 2019/03/04 11:35:38 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016-2017 Jared McNeill 
@@ -33,7 +33,7 @@
 #include "opt_net_mpsafe.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.21 2019/01/22 03:42:25 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.22 2019/03/04 11:35:38 jmcneill Exp $");
 
 #include 
 #include 
@@ -1440,6 +1440,7 @@ sunxi_emac_attach(device_t parent, devic
 			   IFCAP_CSUM_TCPv4_Tx |
 			   IFCAP_CSUM_UDPv4_Rx |
 			   IFCAP_CSUM_UDPv4_Tx;
+	ifp->if_capenable = ifp->if_capabilities;
 	IFQ_SET_MAXLEN(>if_snd, IFQ_MAXLEN);
 	IFQ_SET_READY(>if_snd);
 



CVS commit: src/sys/arch/arm/sunxi

2019-03-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Mar  3 17:09:24 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun8i_a83t_gpio.c

Log Message:
"s_cir" function is now named "s_cir_rx"


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sunxi/sun8i_a83t_gpio.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/sun8i_a83t_gpio.c
diff -u src/sys/arch/arm/sunxi/sun8i_a83t_gpio.c:1.4 src/sys/arch/arm/sunxi/sun8i_a83t_gpio.c:1.5
--- src/sys/arch/arm/sunxi/sun8i_a83t_gpio.c:1.4	Mon Dec 31 19:07:21 2018
+++ src/sys/arch/arm/sunxi/sun8i_a83t_gpio.c	Sun Mar  3 17:09:24 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun8i_a83t_gpio.c,v 1.4 2018/12/31 19:07:21 jmcneill Exp $ */
+/* $NetBSD: sun8i_a83t_gpio.c,v 1.5 2019/03/03 17:09:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016-2017 Jared McNeill 
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sun8i_a83t_gpio.c,v 1.4 2018/12/31 19:07:21 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun8i_a83t_gpio.c,v 1.5 2019/03/03 17:09:24 jmcneill Exp $");
 
 #include 
 #include 
@@ -167,7 +167,7 @@ static const struct sunxi_gpio_pins a83t
 	{ "PL9",   0, 9,  { "gpio_in", "gpio_out", "s_i2c", NULL, NULL, NULL, "irq" } },
 	{ "PL10",  0, 10, { "gpio_in", "gpio_out", "s_pwm", NULL, NULL, NULL, "irq" } },
 	{ "PL11",  0, 11, { "gpio_in", "gpio_out", NULL, NULL, NULL, "irq" } },
-	{ "PL12",  0, 12, { "gpio_in", "gpio_out", "s_cir", NULL, NULL, NULL, "irq" } },
+	{ "PL12",  0, 12, { "gpio_in", "gpio_out", "s_cir_rx", NULL, NULL, NULL, "irq" } },
 };
 
 const struct sunxi_gpio_padconf sun8i_a83t_padconf = {



CVS commit: src/sys/arch/arm/sunxi

2019-03-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Mar  3 17:00:22 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_mc_smp.c

Log Message:
Fix A83T AP startup


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sunxi/sunxi_mc_smp.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/sunxi_mc_smp.c
diff -u src/sys/arch/arm/sunxi/sunxi_mc_smp.c:1.3 src/sys/arch/arm/sunxi/sunxi_mc_smp.c:1.4
--- src/sys/arch/arm/sunxi/sunxi_mc_smp.c:1.3	Thu Jan  3 14:44:21 2019
+++ src/sys/arch/arm/sunxi/sunxi_mc_smp.c	Sun Mar  3 17:00:22 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mc_smp.c,v 1.3 2019/01/03 14:44:21 jmcneill Exp $ */
+/* $NetBSD: sunxi_mc_smp.c,v 1.4 2019/03/03 17:00:22 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mc_smp.c,v 1.3 2019/01/03 14:44:21 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mc_smp.c,v 1.4 2019/03/03 17:00:22 jmcneill Exp $");
 
 #include 
 #include 
@@ -156,6 +156,8 @@ sunxi_mc_smp_start(bus_space_tag_t bst, 
 	if (soc == MC_SOC_A83T) {
 		if (cpu == 0)
 			val &= ~__BIT(4);
+		else
+			val &= ~__BIT(cpu);
 		val &= ~__BIT(0);	/* cluster power gate */
 	} else {
 		val &= ~__BIT(cpu);



CVS commit: src/sys/arch/arm/sunxi

2019-03-02 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sat Mar  2 16:55:13 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun6i_dma.c

Log Message:
Validate burst and width arguments.

Also add some more register definitions, and a (disabled) example of
how to set the DMA flow control mode.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sunxi/sun6i_dma.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/sun6i_dma.c
diff -u src/sys/arch/arm/sunxi/sun6i_dma.c:1.7 src/sys/arch/arm/sunxi/sun6i_dma.c:1.8
--- src/sys/arch/arm/sunxi/sun6i_dma.c:1.7	Sat Mar  2 03:21:17 2019
+++ src/sys/arch/arm/sunxi/sun6i_dma.c	Sat Mar  2 16:55:13 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun6i_dma.c,v 1.7 2019/03/02 03:21:17 jakllsch Exp $ */
+/* $NetBSD: sun6i_dma.c,v 1.8 2019/03/02 16:55:13 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sun6i_dma.c,v 1.7 2019/03/02 03:21:17 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun6i_dma.c,v 1.8 2019/03/02 16:55:13 jakllsch Exp $");
 
 #include 
 #include 
@@ -79,6 +79,13 @@ __KERNEL_RCSID(0, "$NetBSD: sun6i_dma.c,
 #define DMA_PARA_REG(n)			(0x0100 + (n) * 0x40 + 0x1C)
 #define  DMA_PARA_DATA_BLK_SIZE			__BITS(15,8)
 #define  DMA_PARA_WAIT_CYC			__BITS(7,0)
+#define DMA_MODE_REG(n)			(0x0100 + (n) * 0x40 + 0x28)
+#define  MODE_WAIT0b0
+#define  MODE_HANDSHAKE0b1
+#define  DMA_MODE_DST(m)			__SHIFTIN((m), __BIT(3))
+#define  DMA_MODE_SRC(m)			__SHIFTIN((m), __BIT(2))
+#define DMA_FDESC_ADDR_REG(n)		(0x0100 + (n) * 0x40 + 0x2C)
+#define DMA_PKG_NUM_REG(n)		(0x0100 + (n) * 0x40 + 0x30)
 
 struct sun6idma_desc {
 	uint32_t	dma_config;
@@ -93,14 +100,25 @@ struct sun6idma_desc {
 struct sun6idma_config {
 	u_int		num_channels;
 	bool		autogate;
+	uint8_t		bursts;
+	uint8_t		widths;
 	bus_size_t	autogate_reg;
 	uint32_t	autogate_mask;
 	uint32_t	burst_mask;
 };
 
+#define IL2B(x)			__BIT(ilog2(x))
+#define IL2B_RANGE(x, y)	__BITS(ilog2(x), ilog2(y))
+#define WIDTHS_1_2_4		IL2B_RANGE(4, 1)
+#define WIDTHS_1_2_4_8		IL2B_RANGE(8, 1)
+#define BURSTS_1_8		(IL2B(8)|IL2B(1))
+#define BURSTS_1_4_8_16		(IL2B(16)|IL2B(8)|IL2B(4)|IL2B(1))
+
 static const struct sun6idma_config sun6i_a31_dma_config = {
 	.num_channels = 16,
 	.burst_mask = __BITS(8,7),
+	.bursts = BURSTS_1_8,
+	.widths = WIDTHS_1_2_4,
 };
 
 static const struct sun6idma_config sun8i_a83t_dma_config = {
@@ -109,6 +127,8 @@ static const struct sun6idma_config sun8
 	.autogate_reg = 0x20,
 	.autogate_mask = 0x4,
 	.burst_mask = __BITS(8,7),
+	.bursts = BURSTS_1_8,
+	.widths = WIDTHS_1_2_4,
 };
 
 static const struct sun6idma_config sun8i_h3_dma_config = {
@@ -117,6 +137,8 @@ static const struct sun6idma_config sun8
 	.autogate_reg = 0x28,
 	.autogate_mask = 0x4,
 	.burst_mask = __BITS(7,6),
+	.bursts = BURSTS_1_4_8_16,
+	.widths = WIDTHS_1_2_4_8,
 };
 
 static const struct sun6idma_config sun50i_a64_dma_config = {
@@ -125,6 +147,8 @@ static const struct sun6idma_config sun5
 	.autogate_reg = 0x28,
 	.autogate_mask = 0x4,
 	.burst_mask = __BITS(7,6),
+	.bursts = BURSTS_1_4_8_16,
+	.widths = WIDTHS_1_2_4_8,
 };
 
 static const struct of_compat_data compat_data[] = {
@@ -158,6 +182,8 @@ struct sun6idma_softc {
 	struct sun6idma_channel	*sc_chan;
 	u_int			sc_nchan;
 	u_int			sc_ndesc_ch;
+	uint8_t			sc_widths;
+	uint8_t			sc_bursts;
 
 	bus_dma_segment_t	sc_dmasegs[1];
 	bus_dmamap_t		sc_dmamap;
@@ -259,6 +285,19 @@ sun6idma_transfer(device_t dev, void *pr
 	if (req->dreq_nsegs > sc->sc_ndesc_ch)
 		return EINVAL;
 
+	if ((sc->sc_widths &
+	IL2B(req->dreq_mem_opt.opt_bus_width/NBBY)) == 0)
+		return EINVAL;
+	if ((sc->sc_widths &
+	IL2B(req->dreq_dev_opt.opt_bus_width/NBBY)) == 0)
+		return EINVAL;
+	if ((sc->sc_bursts &
+	IL2B(req->dreq_mem_opt.opt_burst_len)) == 0)
+		return EINVAL;
+	if ((sc->sc_bursts &
+	IL2B(req->dreq_dev_opt.opt_burst_len)) == 0)
+		return EINVAL;
+
 	mem_width = DMA_CFG_DATA_WIDTH(req->dreq_mem_opt.opt_bus_width);
 	dev_width = DMA_CFG_DATA_WIDTH(req->dreq_dev_opt.opt_bus_width);
 	mem_burst = DMA_CFG_BST_LEN(req->dreq_mem_opt.opt_burst_len);
@@ -296,6 +335,11 @@ sun6idma_transfer(device_t dev, void *pr
 			desc[j].dma_next = htole32(DMA_NULL);
 	}
 
+#if maybenever
+	DMA_WRITE(sc, DMA_MODE_REG(ch->ch_index),
+	DMA_MODE_DST(MODE_HANDSHAKE)|DMA_MODE_SRC(MODE_HANDSHAKE));
+#endif
+
 	bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, DESC_OFFS(ch->ch_index, 0),
 	DESC_LEN(req->dreq_nsegs), BUS_DMASYNC_PREWRITE);
 
@@ -419,6 +463,8 @@ sun6idma_attach(device_t parent, device_
 
 	sc->sc_burst_mask = conf->burst_mask;
 	sc->sc_nchan = conf->num_channels;
+	sc->sc_widths = conf->widths;
+	sc->sc_bursts = conf->bursts;
 	sc->sc_chan = kmem_alloc(sizeof(*sc->sc_chan) * sc->sc_nchan, KM_SLEEP);
 	desclen = DESC_OFFS(sc->sc_nchan, 0);
 	

CVS commit: src/sys/arch/arm/sunxi

2019-03-01 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sat Mar  2 03:21:17 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun6i_dma.c

Log Message:
Implement support for multi-segment transfers.
Make more efficent use of DMA descriptor table memory.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sunxi/sun6i_dma.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/sun6i_dma.c
diff -u src/sys/arch/arm/sunxi/sun6i_dma.c:1.6 src/sys/arch/arm/sunxi/sun6i_dma.c:1.7
--- src/sys/arch/arm/sunxi/sun6i_dma.c:1.6	Sat Nov 17 20:35:41 2018
+++ src/sys/arch/arm/sunxi/sun6i_dma.c	Sat Mar  2 03:21:17 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun6i_dma.c,v 1.6 2018/11/17 20:35:41 jmcneill Exp $ */
+/* $NetBSD: sun6i_dma.c,v 1.7 2019/03/02 03:21:17 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sun6i_dma.c,v 1.6 2018/11/17 20:35:41 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun6i_dma.c,v 1.7 2019/03/02 03:21:17 jakllsch Exp $");
 
 #include 
 #include 
@@ -140,11 +140,7 @@ struct sun6idma_channel {
 	void			(*ch_callback)(void *);
 	void			*ch_callbackarg;
 	u_int			ch_portid;
-
-	bus_dma_segment_t	ch_dmasegs[1];
-	bus_dmamap_t		ch_dmamap;
 	void			*ch_dmadesc;
-	bus_size_t		ch_dmadesclen;
 };
 
 struct sun6idma_softc {
@@ -161,6 +157,11 @@ struct sun6idma_softc {
 
 	struct sun6idma_channel	*sc_chan;
 	u_int			sc_nchan;
+	u_int			sc_ndesc_ch;
+
+	bus_dma_segment_t	sc_dmasegs[1];
+	bus_dmamap_t		sc_dmamap;
+	void			*sc_dmadescs;
 };
 
 #define DMA_READ(sc, reg)		\
@@ -168,6 +169,14 @@ struct sun6idma_softc {
 #define DMA_WRITE(sc, reg, val)		\
 bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
 
+#define DESC_NUM			((MAXPHYS / MIN_PAGE_SIZE + 1) + 1)
+#define DESC_LEN(n)			\
+(sizeof(struct sun6idma_desc) * (n))
+#define DESC_OFFS(ch, n)		\
+((ch) * roundup2(DESC_LEN(DESC_NUM), COHERENCY_UNIT) + DESC_LEN(n))
+#define DESC_ADDR(sc, chp, n)		\
+((sc)->sc_dmamap->dm_segs[0].ds_addr + DESC_OFFS((chp)->ch_index, (n)))
+
 static void *
 sun6idma_acquire(device_t dev, const void *data, size_t len,
 void (*cb)(void *), void *cbarg)
@@ -247,7 +256,7 @@ sun6idma_transfer(device_t dev, void *pr
 	uint32_t src, dst, len, cfg, mem_cfg, dev_cfg;
 	uint32_t mem_width, dev_width, mem_burst, dev_burst;
 
-	if (req->dreq_nsegs != 1)
+	if (req->dreq_nsegs > sc->sc_ndesc_ch)
 		return EINVAL;
 
 	mem_width = DMA_CFG_DATA_WIDTH(req->dreq_mem_opt.opt_bus_width);
@@ -264,29 +273,34 @@ sun6idma_transfer(device_t dev, void *pr
 	__SHIFTIN(DMA_CFG_ADDR_MODE_IO, DMA_CFG_SRC_ADDR_MODE) |
 	__SHIFTIN(ch->ch_portid, DMA_CFG_SRC_DRQ_TYPE);
 
-	if (req->dreq_dir == FDT_DMA_READ) {
-		src = req->dreq_dev_phys;
-		dst = req->dreq_segs[0].ds_addr;
-		cfg = mem_cfg << 16 | dev_cfg;
-	} else {
-		src = req->dreq_segs[0].ds_addr;
-		dst = req->dreq_dev_phys;
-		cfg = dev_cfg << 16 | mem_cfg;
-	}
-	len = req->dreq_segs[0].ds_len;
-
-	desc->dma_config = htole32(cfg);
-	desc->dma_srcaddr = htole32(src);
-	desc->dma_dstaddr = htole32(dst);
-	desc->dma_bcnt = htole32(len);
-	desc->dma_para = htole32(0);
-	desc->dma_next = htole32(DMA_NULL);
+	for (size_t j = 0; j < req->dreq_nsegs; j++) {
+		if (req->dreq_dir == FDT_DMA_READ) {
+			src = req->dreq_dev_phys;
+			dst = req->dreq_segs[j].ds_addr;
+			cfg = mem_cfg << 16 | dev_cfg;
+		} else {
+			src = req->dreq_segs[j].ds_addr;
+			dst = req->dreq_dev_phys;
+			cfg = dev_cfg << 16 | mem_cfg;
+		}
+		len = req->dreq_segs[j].ds_len;
+
+		desc[j].dma_config = htole32(cfg);
+		desc[j].dma_srcaddr = htole32(src);
+		desc[j].dma_dstaddr = htole32(dst);
+		desc[j].dma_bcnt = htole32(len);
+		desc[j].dma_para = htole32(0);
+		if (j < req->dreq_nsegs - 1)
+			desc[j].dma_next = htole32(DESC_ADDR(sc, ch, j + 1));
+		else
+			desc[j].dma_next = htole32(DMA_NULL);
+	}
 
-	bus_dmamap_sync(sc->sc_dmat, ch->ch_dmamap, 0, ch->ch_dmadesclen,
-	BUS_DMASYNC_PREWRITE);
+	bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, DESC_OFFS(ch->ch_index, 0),
+	DESC_LEN(req->dreq_nsegs), BUS_DMASYNC_PREWRITE);
 
 	DMA_WRITE(sc, DMA_START_ADDR_REG(ch->ch_index),
-	ch->ch_dmamap->dm_segs[0].ds_addr);
+	DESC_ADDR(sc, ch, 0));
 	DMA_WRITE(sc, DMA_EN_REG(ch->ch_index), DMA_EN_EN);
 
 	if ((DMA_READ(sc, DMA_EN_REG(ch->ch_index)) & DMA_EN_EN) == 0) {
@@ -360,7 +374,7 @@ sun6idma_attach(device_t parent, device_
 	struct sun6idma_softc * const sc = device_private(self);
 	struct fdt_attach_args * const faa = aux;
 	const int phandle = faa->faa_phandle;
-	const size_t desclen = sizeof(struct sun6idma_desc);
+	size_t desclen;
 	const struct sun6idma_config *conf;
 	struct fdtbus_reset *rst;
 	struct clk *clk;
@@ -406,6 +420,8 @@ sun6idma_attach(device_t parent, device_
 	sc->sc_burst_mask = conf->burst_mask;
 	sc->sc_nchan = conf->num_channels;
 	sc->sc_chan = 

CVS commit: src/sys/arch/arm/sunxi

2019-02-17 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Feb 18 02:42:27 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_lcdc.c

Log Message:
Fix copy/paste issue that resulted in tcon0 ch0/ch1 crtc clk mixup.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sunxi/sunxi_lcdc.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/sunxi_lcdc.c
diff -u src/sys/arch/arm/sunxi/sunxi_lcdc.c:1.4 src/sys/arch/arm/sunxi/sunxi_lcdc.c:1.5
--- src/sys/arch/arm/sunxi/sunxi_lcdc.c:1.4	Mon Feb  4 12:10:13 2019
+++ src/sys/arch/arm/sunxi/sunxi_lcdc.c	Mon Feb 18 02:42:27 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_lcdc.c,v 1.4 2019/02/04 12:10:13 jmcneill Exp $ */
+/* $NetBSD: sunxi_lcdc.c,v 1.5 2019/02/18 02:42:27 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_lcdc.c,v 1.4 2019/02/04 12:10:13 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_lcdc.c,v 1.5 2019/02/18 02:42:27 jakllsch Exp $");
 
 #include 
 #include 
@@ -244,13 +244,13 @@ sunxi_lcdc_tcon0_commit(struct drm_encod
 	TCON_WRITE(sc, TCON0_IO_POL_REG, val);
 
 	if (sc->sc_clk_ch[0] != NULL) {
-		error = clk_set_rate(sc->sc_clk_ch[1], mode->crtc_clock * 1000);
+		error = clk_set_rate(sc->sc_clk_ch[0], mode->crtc_clock * 1000);
 		if (error != 0) {
 			device_printf(sc->sc_dev, "failed to set CH0 PLL rate to %u Hz: %d\n",
 			mode->crtc_clock * 1000, error);
 			return;
 		}
-		error = clk_enable(sc->sc_clk_ch[1]);
+		error = clk_enable(sc->sc_clk_ch[0]);
 		if (error != 0) {
 			device_printf(sc->sc_dev, "failed to enable CH0 PLL: %d\n", error);
 			return;



CVS commit: src/sys/arch/arm/sunxi

2019-02-16 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Feb 16 16:20:50 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_mixer.c

Log Message:
Fix HDMI output; only install cursor_set/cursor_move funcs if hardware cursor 
is available.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sunxi/sunxi_mixer.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/sunxi_mixer.c
diff -u src/sys/arch/arm/sunxi/sunxi_mixer.c:1.6 src/sys/arch/arm/sunxi/sunxi_mixer.c:1.7
--- src/sys/arch/arm/sunxi/sunxi_mixer.c:1.6	Wed Feb  6 03:07:08 2019
+++ src/sys/arch/arm/sunxi/sunxi_mixer.c	Sat Feb 16 16:20:50 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mixer.c,v 1.6 2019/02/06 03:07:08 jmcneill Exp $ */
+/* $NetBSD: sunxi_mixer.c,v 1.7 2019/02/16 16:20:50 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.c,v 1.6 2019/02/06 03:07:08 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.c,v 1.7 2019/02/16 16:20:50 jmcneill Exp $");
 
 #include 
 #include 
@@ -420,7 +420,7 @@ sunxi_mixer_cursor_move(struct drm_crtc 
 	return 0;
 }
 
-static const struct drm_crtc_funcs sunxi_mixer_crtc_funcs = {
+static const struct drm_crtc_funcs sunxi_mixer0_crtc_funcs = {
 	.set_config = drm_crtc_helper_set_config,
 	.destroy = sunxi_mixer_destroy,
 	.page_flip = sunxi_mixer_page_flip,
@@ -428,6 +428,12 @@ static const struct drm_crtc_funcs sunxi
 	.cursor_move = sunxi_mixer_cursor_move,
 };
 
+static const struct drm_crtc_funcs sunxi_mixer1_crtc_funcs = {
+	.set_config = drm_crtc_helper_set_config,
+	.destroy = sunxi_mixer_destroy,
+	.page_flip = sunxi_mixer_page_flip,
+};
+
 static void
 sunxi_mixer_dpms(struct drm_crtc *crtc, int mode)
 {
@@ -1184,7 +1190,10 @@ sunxi_mixer_ep_activate(device_t dev, st
 	BLD_WRITE(sc, BLD_CTL(2), 0x03010301);
 	BLD_WRITE(sc, BLD_CTL(3), 0x03010301);
 
-	drm_crtc_init(ddev, >sc_crtc.base, _mixer_crtc_funcs);
+	if (sc->sc_ovl_ui_count > 1)
+		drm_crtc_init(ddev, >sc_crtc.base, _mixer0_crtc_funcs);
+	else
+		drm_crtc_init(ddev, >sc_crtc.base, _mixer1_crtc_funcs);
 	drm_crtc_helper_add(>sc_crtc.base, _mixer_crtc_helper_funcs);
 
 	drm_universal_plane_init(ddev, >sc_overlay.base,



CVS commit: src/sys/arch/arm/sunxi

2019-02-13 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Wed Feb 13 18:31:11 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun50i_h6_ccu.c

Log Message:
sun50i_h6_ccu: add PCIe clocks


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sun50i_h6_ccu.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/sun50i_h6_ccu.c
diff -u src/sys/arch/arm/sunxi/sun50i_h6_ccu.c:1.2 src/sys/arch/arm/sunxi/sun50i_h6_ccu.c:1.3
--- src/sys/arch/arm/sunxi/sun50i_h6_ccu.c:1.2	Wed Feb 13 18:18:38 2019
+++ src/sys/arch/arm/sunxi/sun50i_h6_ccu.c	Wed Feb 13 18:31:11 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun50i_h6_ccu.c,v 1.2 2019/02/13 18:18:38 jakllsch Exp $ */
+/* $NetBSD: sun50i_h6_ccu.c,v 1.3 2019/02/13 18:31:11 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sun50i_h6_ccu.c,v 1.2 2019/02/13 18:18:38 jakllsch Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun50i_h6_ccu.c,v 1.3 2019/02/13 18:31:11 jakllsch Exp $");
 
 #include 
 #include 
@@ -42,6 +42,7 @@ __KERNEL_RCSID(1, "$NetBSD: sun50i_h6_cc
 
 #define	PLL_CPUX_CTRL_REG	0x000
 #define	PLL_PERI0_CTRL_REG	0x020
+#define	PSI_AHB1_AHB2_CFG_REG	0x510
 #define	AHB3_CFG_REG		0x51c
 #define	APB2_CFG_REG		0x524
 #define	MBUS_CFG_REG		0x540
@@ -81,6 +82,9 @@ __KERNEL_RCSID(1, "$NetBSD: sun50i_h6_cc
 #define	USB1_CLK_REG		0xa74
 #define	USB3_CLK_REG		0xa7c
 #define	USB_BGR_REG		0xa8c
+#define	PCIE_REF_CLK_REG	0xab0
+#define	PCIE_AXI_CLK_REG	0xab4
+#define	PCIE_AUX_CLK_REG	0xab8
 #define	PCIE_BGR_REG		0xabc
 #define	HDMI_BGR_REG		0xb1c
 #define	DISPLAY_IF_TOP_BGR_REG	0xb5c
@@ -210,6 +214,9 @@ static struct sunxi_ccu_reset sun50i_h6_
 static const char *ahb3_parents[] = { "hosc", "losc", "psi", "pll_periph0" };
 static const char *apb2_parents[] = { "hosc", "losc", "psi", "pll_periph0" };
 static const char *mod_parents[] = { "hosc", "pll_periph0_2x", "pll_periph1_2x" };
+static const char *hosc_parent[] = { "hosc" };
+static const char *pll_periph0_parent[] = { "pll_periph0" };
+static const char *psi_ahb1_ahb2_parents[] = { "hosc", "losc", "iosc", "pll_periph0" };
 
 static struct sunxi_ccu_clk sun50i_h6_ccu_clks[] = {
 	SUNXI_CCU_FIXED_FACTOR(H6_CLK_OSC12M, "osc12m", "hosc", 2, 1),
@@ -330,6 +337,37 @@ static struct sunxi_ccu_clk sun50i_h6_cc
 
 	SUNXI_CCU_GATE(H6_CLK_BUS_EMAC, "bus-emac", "ahb3",
 	EMAC_BGR_REG, 0),
+
+	SUNXI_CCU_FIXED_FACTOR(H6_CLK_PCIE_REF_100M, "pcie_ref_100M",
+	"pll_periph0_4x", 24, 1),
+	SUNXI_CCU_GATE(H6_CLK_PCIE_REF, "pcie_ref", "pcie_ref_100M",
+	PCIE_REF_CLK_REG, 31),
+	SUNXI_CCU_GATE(H6_CLK_PCIE_REF_OUT, "pcie_ref_out", "pcie_ref",
+	PCIE_REF_CLK_REG, 30),
+
+	SUNXI_CCU_NM(H6_CLK_PSI_AHB1_AHB2, "psi_ahb1_ahb2",
+	psi_ahb1_ahb2_parents,
+	PSI_AHB1_AHB2_CFG_REG,	/* reg */
+	__BITS(9,8),	/* n */
+	__BITS(1,0),	/* m */
+	__BITS(25,24),	/* sel */
+	0,			/* enable */
+	SUNXI_CCU_NM_POWER_OF_TWO),
+	SUNXI_CCU_DIV_GATE(H6_CLK_PCIE_MAXI, "pcie_maxi", pll_periph0_parent,
+	PCIE_AXI_CLK_REG,	/* reg */
+	__BITS(3,0),	/* div */
+	0,			/* sel */
+	__BIT(31),		/* enable */
+	SUNXI_CCU_DIV_ZERO_IS_ONE),
+	SUNXI_CCU_DIV_GATE(H6_CLK_PCIE_AUX, "pcie_aux", hosc_parent,
+	PCIE_AUX_CLK_REG,	/* reg */
+	__BITS(4,0),	/* div */
+	0,			/* sel */
+	__BIT(31),		/* enable */
+	SUNXI_CCU_DIV_ZERO_IS_ONE),
+
+	SUNXI_CCU_GATE(H6_CLK_BUS_PCIE, "bus_pcie", "psi_ahb1_ahb2",
+	PCIE_BGR_REG, 0),
 };
 
 static int



CVS commit: src/sys/arch/arm/sunxi

2019-02-13 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Wed Feb 13 18:18:38 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun50i_h6_ccu.c

Log Message:
sun50i_h6_ccu: add "pll_cpux"

Currently intended for display of existing clock rate via the sysctl
tree, and not yet for DVFS.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/sunxi/sun50i_h6_ccu.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/sun50i_h6_ccu.c
diff -u src/sys/arch/arm/sunxi/sun50i_h6_ccu.c:1.1 src/sys/arch/arm/sunxi/sun50i_h6_ccu.c:1.2
--- src/sys/arch/arm/sunxi/sun50i_h6_ccu.c:1.1	Tue May  1 19:53:14 2018
+++ src/sys/arch/arm/sunxi/sun50i_h6_ccu.c	Wed Feb 13 18:18:38 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun50i_h6_ccu.c,v 1.1 2018/05/01 19:53:14 jmcneill Exp $ */
+/* $NetBSD: sun50i_h6_ccu.c,v 1.2 2019/02/13 18:18:38 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sun50i_h6_ccu.c,v 1.1 2018/05/01 19:53:14 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun50i_h6_ccu.c,v 1.2 2019/02/13 18:18:38 jakllsch Exp $");
 
 #include 
 #include 
@@ -40,6 +40,7 @@ __KERNEL_RCSID(1, "$NetBSD: sun50i_h6_cc
 #include 
 #include 
 
+#define	PLL_CPUX_CTRL_REG	0x000
 #define	PLL_PERI0_CTRL_REG	0x020
 #define	AHB3_CFG_REG		0x51c
 #define	APB2_CFG_REG		0x524
@@ -213,6 +214,17 @@ static const char *mod_parents[] = { "ho
 static struct sunxi_ccu_clk sun50i_h6_ccu_clks[] = {
 	SUNXI_CCU_FIXED_FACTOR(H6_CLK_OSC12M, "osc12m", "hosc", 2, 1),
 
+	SUNXI_CCU_NKMP_TABLE(H6_CLK_PLL_CPUX, "pll_cpux", "hosc",
+	PLL_CPUX_CTRL_REG,		/* reg */
+	__BITS(15,8),		/* n */
+	0,/* k */
+	__BITS(1,0),		/* m */
+	__BITS(17,16),		/* p */
+	__BIT(31),			/* enable */
+	__BIT(28),			/* lock */
+	NULL,			/* table */
+	SUNXI_CCU_NKMP_SCALE_CLOCK | SUNXI_CCU_NKMP_FACTOR_P_POW2),
+
 	SUNXI_CCU_NKMP(H6_CLK_PLL_PERIPH0_4X, "pll_periph0_4x", "hosc",
 	PLL_PERI0_CTRL_REG,		/* reg */
 	__BITS(15,8),		/* n */



CVS commit: src/sys/arch/arm/sunxi

2019-02-06 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Feb  6 22:50:36 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_sramc.c

Log Message:
Match new sun4i-a10 compat string (allwinner,sun4i-a10-system-control)


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sunxi/sunxi_sramc.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/sunxi_sramc.c
diff -u src/sys/arch/arm/sunxi/sunxi_sramc.c:1.3 src/sys/arch/arm/sunxi/sunxi_sramc.c:1.4
--- src/sys/arch/arm/sunxi/sunxi_sramc.c:1.3	Thu Jan 31 01:49:12 2019
+++ src/sys/arch/arm/sunxi/sunxi_sramc.c	Wed Feb  6 22:50:35 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_sramc.c,v 1.3 2019/01/31 01:49:12 jmcneill Exp $ */
+/* $NetBSD: sunxi_sramc.c,v 1.4 2019/02/06 22:50:35 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_sramc.c,v 1.3 2019/01/31 01:49:12 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_sramc.c,v 1.4 2019/02/06 22:50:35 jmcneill Exp $");
 
 #include 
 #include 
@@ -43,7 +43,8 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_sramc.
 #include 
 
 static const char * compatible[] = {
-	"allwinner,sun4i-a10-sram-controller",
+	"allwinner,sun4i-a10-sram-controller",	/* old compat string */
+	"allwinner,sun4i-a10-system-control",
 	"allwinner,sun8i-h3-system-control",
 	"allwinner,sun50i-a64-system-control",
 	"allwinner,sun50i-h6-system-control",



CVS commit: src/sys/arch/arm/sunxi

2019-02-06 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Feb  6 13:15:59 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_mc_mpstart.S

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/sunxi/sunxi_mc_mpstart.S

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/sunxi_mc_mpstart.S
diff -u src/sys/arch/arm/sunxi/sunxi_mc_mpstart.S:1.1 src/sys/arch/arm/sunxi/sunxi_mc_mpstart.S:1.2
--- src/sys/arch/arm/sunxi/sunxi_mc_mpstart.S:1.1	Thu Jan  3 11:01:59 2019
+++ src/sys/arch/arm/sunxi/sunxi_mc_mpstart.S	Wed Feb  6 13:15:59 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mc_mpstart.S,v 1.1 2019/01/03 11:01:59 jmcneill Exp $ */
+/* $NetBSD: sunxi_mc_mpstart.S,v 1.2 2019/02/06 13:15:59 skrll Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -42,7 +42,7 @@
 	.global _C_LABEL(sunxi_mc_mpstart)
 _C_LABEL(sunxi_mc_mpstart):
 
-	adr R_TMP1, sunxi_mc_mpstart 
+	adr R_TMP1, sunxi_mc_mpstart
 	ldr R_VTOPDIFF, =sunxi_mc_mpstart
 	sub R_VTOPDIFF, R_VTOPDIFF, R_TMP1
 



CVS commit: src/sys/arch/arm/sunxi

2019-02-05 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Feb  6 03:07:08 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_drm.c sunxi_mixer.c

Log Message:
Add support for hardware cursors where we can.

As far as I can tell, alpha blending only works between overlay channels,
and not between layers on a channel. Unfortunately, RT-Mixer1 only has
a single UI channel, so this feature is limited to RT-Mixer0.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sunxi/sunxi_drm.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sunxi/sunxi_mixer.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/sunxi_drm.c
diff -u src/sys/arch/arm/sunxi/sunxi_drm.c:1.6 src/sys/arch/arm/sunxi/sunxi_drm.c:1.7
--- src/sys/arch/arm/sunxi/sunxi_drm.c:1.6	Mon Feb  4 12:10:13 2019
+++ src/sys/arch/arm/sunxi/sunxi_drm.c	Wed Feb  6 03:07:08 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_drm.c,v 1.6 2019/02/04 12:10:13 jmcneill Exp $ */
+/* $NetBSD: sunxi_drm.c,v 1.7 2019/02/06 03:07:08 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.6 2019/02/04 12:10:13 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.7 2019/02/06 03:07:08 jmcneill Exp $");
 
 #include 
 #include 
@@ -247,6 +247,7 @@ sunxi_drm_fb_create(struct drm_device *d
 
 	switch (fb->base.pixel_format) {
 	case DRM_FORMAT_XRGB:
+	case DRM_FORMAT_ARGB:
 		fb->base.depth = 32;
 		break;
 	default:

Index: src/sys/arch/arm/sunxi/sunxi_mixer.c
diff -u src/sys/arch/arm/sunxi/sunxi_mixer.c:1.5 src/sys/arch/arm/sunxi/sunxi_mixer.c:1.6
--- src/sys/arch/arm/sunxi/sunxi_mixer.c:1.5	Tue Feb  5 21:01:38 2019
+++ src/sys/arch/arm/sunxi/sunxi_mixer.c	Wed Feb  6 03:07:08 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mixer.c,v 1.5 2019/02/05 21:01:38 jmcneill Exp $ */
+/* $NetBSD: sunxi_mixer.c,v 1.6 2019/02/06 03:07:08 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.c,v 1.5 2019/02/05 21:01:38 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.c,v 1.6 2019/02/06 03:07:08 jmcneill Exp $");
 
 #include 
 #include 
@@ -36,6 +36,7 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -47,13 +48,14 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.
 
 #include 
 
+#define	MIXER_CURSOR_MAXWIDTH	256
+#define	MIXER_CURSOR_MAXHEIGHT	256
+
 #define	SUNXI_MIXER_FREQ	43200
 
 #define	GLB_BASE		0x0
 #define	BLD_BASE		0x01000
 #define	OVL_BASE(n)		(0x02000 + (n) * 0x1000)
-#define	OVL_V_BASE		OVL_BASE(0)
-#define	OVL_UI_BASE		OVL_BASE(1)
 #define	VSU_BASE		0x2
 #define	CSC_BASE(n)		((n) == 0 ? 0xaa050 : 0xa)
 
@@ -67,11 +69,20 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.
 
 /* BLD registers */
 #define	BLD_FILL_COLOR_CTL	0x000
+#define	 BLD_FILL_COLOR_CTL_P3_EN		__BIT(11)
+#define	 BLD_FILL_COLOR_CTL_P2_EN		__BIT(10)
 #define	 BLD_FILL_COLOR_CTL_P1_EN		__BIT(9)
 #define	 BLD_FILL_COLOR_CTL_P0_EN		__BIT(8)
+#define	 BLD_FILL_COLOR_CTL_P3_FCEN		__BIT(3)
+#define	 BLD_FILL_COLOR_CTL_P2_FCEN		__BIT(2)
+#define	 BLD_FILL_COLOR_CTL_P1_FCEN		__BIT(1)
+#define	 BLD_FILL_COLOR_CTL_P0_FCEN		__BIT(0)
+#define	BLD_FILL_COLOR(n)	(0x004 + (n) * 0x10)
 #define	BLD_CH_ISIZE(n)		(0x008 + (n) * 0x10)
 #define	BLD_CH_OFFSET(n)	(0x00c + (n) * 0x10)
 #define	BLD_CH_RTCTL		0x080
+#define	 BLD_CH_RTCTL_P3			__BITS(15,12)
+#define	 BLD_CH_RTCTL_P2			__BITS(11,8)
 #define	 BLD_CH_RTCTL_P1			__BITS(7,4)
 #define	 BLD_CH_RTCTL_P0			__BITS(3,0)
 #define	BLD_SIZE		0x08c
@@ -88,6 +99,7 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.
 #define	  OVL_V_ATTCTL_LAY_FBFMT_YUV422		0x06
 #define	  OVL_V_ATTCTL_LAY_FBFMT_YUV420		0x0a
 #define	  OVL_V_ATTCTL_LAY_FBFMT_YUV411		0x0e
+#define	  OVL_V_ATTCTL_LAY_FBFMT_ARGB_	0x00
 #define	  OVL_V_ATTCTL_LAY_FBFMT_XRGB_	0x04
 #define	 OVL_V_ATTCTL_LAY0_EN			__BIT(0)
 #define	OVL_V_MBSIZE(n)		(0x004 + (n) * 0x30)
@@ -112,13 +124,16 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.
 /* OVL_UI registers */
 #define	OVL_UI_ATTR_CTL(n)	(0x000 + (n) * 0x20)
 #define	 OVL_UI_ATTR_CTL_LAY_FBFMT		__BITS(12,8)
+#define	  OVL_UI_ATTR_CTL_LAY_FBFMT_ARGB_	0x00
 #define	  OVL_UI_ATTR_CTL_LAY_FBFMT_XRGB_	0x04
 #define	 OVL_UI_ATTR_CTL_LAY_EN			__BIT(0)
 #define	OVL_UI_MBSIZE(n)	(0x004 + (n) * 0x20)
 #define	OVL_UI_COOR(n)		(0x008 + (n) * 0x20)
 #define	OVL_UI_PITCH(n)		(0x00c + (n) * 0x20)
 #define	OVL_UI_TOP_LADD(n)	(0x010 + (n) * 0x20)
+#define	OVL_UI_FILL_COLOR(n)	(0x018 + (n) * 0x20)
 #define	OVL_UI_TOP_HADD		0x080
+#define	 OVL_UI_TOP_HADD_LAYER1	__BITS(15,8)
 #define	 OVL_UI_TOP_HADD_LAYER0	__BITS(7,0)
 #define	OVL_UI_SIZE		0x088
 
@@ -158,11 +173,11 @@ enum {
 	MIXER_PORT_OUTPUT = 1,
 };
 
-static const char * const compatible[] = {
-	"allwinner,sun8i-h3-de2-mixer-0",
-	

CVS commit: src/sys/arch/arm/sunxi

2019-02-05 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Feb  5 21:01:38 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_mixer.c

Log Message:
Implement page flip API


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sunxi/sunxi_mixer.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/sunxi_mixer.c
diff -u src/sys/arch/arm/sunxi/sunxi_mixer.c:1.4 src/sys/arch/arm/sunxi/sunxi_mixer.c:1.5
--- src/sys/arch/arm/sunxi/sunxi_mixer.c:1.4	Tue Feb  5 00:21:35 2019
+++ src/sys/arch/arm/sunxi/sunxi_mixer.c	Tue Feb  5 21:01:38 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mixer.c,v 1.4 2019/02/05 00:21:35 jmcneill Exp $ */
+/* $NetBSD: sunxi_mixer.c,v 1.5 2019/02/05 21:01:38 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.c,v 1.4 2019/02/05 00:21:35 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.c,v 1.5 2019/02/05 21:01:38 jmcneill Exp $");
 
 #include 
 #include 
@@ -222,14 +222,61 @@ struct sunxi_mixer_softc {
 #define	to_sunxi_mixer_crtc(x)		container_of(x, struct sunxi_mixer_crtc, base)
 #define	to_sunxi_mixer_overlay(x)	container_of(x, struct sunxi_mixer_overlay, base)
 
+static int
+sunxi_mixer_mode_do_set_base(struct drm_crtc *crtc, struct drm_framebuffer *fb,
+int x, int y, int atomic)
+{
+	struct sunxi_mixer_crtc *mixer_crtc = to_sunxi_mixer_crtc(crtc);
+	struct sunxi_mixer_softc * const sc = mixer_crtc->sc;
+	struct sunxi_drm_framebuffer *sfb = atomic?
+	to_sunxi_drm_framebuffer(fb) :
+	to_sunxi_drm_framebuffer(crtc->primary->fb);
+
+	uint64_t paddr = (uint64_t)sfb->obj->dmamap->dm_segs[0].ds_addr;
+
+	uint32_t haddr = (paddr >> 32) & OVL_UI_TOP_HADD_LAYER0;
+	uint32_t laddr = paddr & 0x;
+
+	/* Framebuffer start address */
+	OVL_UI_WRITE(sc, OVL_UI_TOP_HADD, haddr);
+	OVL_UI_WRITE(sc, OVL_UI_TOP_LADD(0), laddr);
+
+	return 0;
+}
+
 static void
 sunxi_mixer_destroy(struct drm_crtc *crtc)
 {
 	drm_crtc_cleanup(crtc);
 }
 
+static int
+sunxi_mixer_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
+struct drm_pending_vblank_event *event, uint32_t flags)
+{
+	struct sunxi_mixer_crtc *mixer_crtc = to_sunxi_mixer_crtc(crtc);
+	struct sunxi_mixer_softc * const sc = mixer_crtc->sc;
+	unsigned long irqflags;
+
+	drm_crtc_wait_one_vblank(crtc);
+
+	sunxi_mixer_mode_do_set_base(crtc, fb, 0, 0, true);
+
+	/* Commit settings */
+	GLB_WRITE(sc, GLB_DBUFFER, GLB_DBUFFER_DOUBLE_BUFFER_RDY);
+
+	if (event) {
+		spin_lock_irqsave(>dev->event_lock, irqflags);
+		drm_send_vblank_event(crtc->dev, drm_crtc_index(crtc), event);
+		spin_unlock_irqrestore(>dev->event_lock, irqflags);
+	}
+
+	return 0;
+}
+
 static const struct drm_crtc_funcs sunxi_mixer_crtc_funcs = {
 	.set_config = drm_crtc_helper_set_config,
+	.page_flip = sunxi_mixer_page_flip,
 	.destroy = sunxi_mixer_destroy,
 };
 
@@ -246,28 +293,6 @@ sunxi_mixer_mode_fixup(struct drm_crtc *
 }
 
 static int
-sunxi_mixer_mode_do_set_base(struct drm_crtc *crtc, struct drm_framebuffer *fb,
-int x, int y, int atomic)
-{
-	struct sunxi_mixer_crtc *mixer_crtc = to_sunxi_mixer_crtc(crtc);
-	struct sunxi_mixer_softc * const sc = mixer_crtc->sc;
-	struct sunxi_drm_framebuffer *sfb = atomic?
-	to_sunxi_drm_framebuffer(fb) :
-	to_sunxi_drm_framebuffer(crtc->primary->fb);
-
-	uint64_t paddr = (uint64_t)sfb->obj->dmamap->dm_segs[0].ds_addr;
-
-	uint32_t haddr = (paddr >> 32) & OVL_UI_TOP_HADD_LAYER0;
-	uint32_t laddr = paddr & 0x;
-
-	/* Framebuffer start address */
-	OVL_UI_WRITE(sc, OVL_UI_TOP_HADD, haddr);
-	OVL_UI_WRITE(sc, OVL_UI_TOP_LADD(0), laddr);
-
-	return 0;
-}
-
-static int
 sunxi_mixer_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode,
 struct drm_display_mode *adjusted_mode, int x, int y,
 struct drm_framebuffer *old_fb)



CVS commit: src/sys/arch/arm/sunxi

2019-02-04 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Feb  5 00:21:35 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_mixer.c

Log Message:
Add support for video layer scaling and colour space conversion.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sunxi/sunxi_mixer.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/sunxi_mixer.c
diff -u src/sys/arch/arm/sunxi/sunxi_mixer.c:1.3 src/sys/arch/arm/sunxi/sunxi_mixer.c:1.4
--- src/sys/arch/arm/sunxi/sunxi_mixer.c:1.3	Mon Feb  4 12:10:13 2019
+++ src/sys/arch/arm/sunxi/sunxi_mixer.c	Tue Feb  5 00:21:35 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mixer.c,v 1.3 2019/02/04 12:10:13 jmcneill Exp $ */
+/* $NetBSD: sunxi_mixer.c,v 1.4 2019/02/05 00:21:35 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.c,v 1.3 2019/02/04 12:10:13 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.c,v 1.4 2019/02/05 00:21:35 jmcneill Exp $");
 
 #include 
 #include 
@@ -54,6 +54,8 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.
 #define	OVL_BASE(n)		(0x02000 + (n) * 0x1000)
 #define	OVL_V_BASE		OVL_BASE(0)
 #define	OVL_UI_BASE		OVL_BASE(1)
+#define	VSU_BASE		0x2
+#define	CSC_BASE(n)		((n) == 0 ? 0xaa050 : 0xa)
 
 /* GLB registers */
 #define	GLB_CTL			0x000
@@ -120,6 +122,38 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_mixer.
 #define	 OVL_UI_TOP_HADD_LAYER0	__BITS(7,0)
 #define	OVL_UI_SIZE		0x088
 
+/* VSU registers */
+#define	VS_CTRL_REG		0x000
+#define	 VS_CTRL_COEF_SWITCH_EN			__BIT(4)
+#define	 VS_CTRL_EN__BIT(0)
+#define	VS_STATUS_REG		0x008
+#define	VS_FIELD_CTRL_REG	0x00c
+#define	VS_OUT_SIZE_REG		0x040
+#define	VS_Y_SIZE_REG		0x080
+#define	VS_Y_HSTEP_REG		0x088
+#define	VS_Y_VSTEP_REG		0x08c
+#define	VS_Y_HPHASE_REG		0x090
+#define	VS_Y_VPHASE0_REG	0x098
+#define	VS_Y_VPHASE1_REG	0x09c
+#define	VS_C_SIZE_REG		0x0c0
+#define	VS_C_HSTEP_REG		0x0c8
+#define	VS_C_VSTEP_REG		0x0cc
+#define	VS_C_HPHASE_REG		0x0d0
+#define	VS_C_VPHASE0_REG	0x0d8
+#define	VS_C_VPHASE1_REG	0x0dc
+#define	VS_Y_HCOEF0_REG(n)	(0x200 + (n) * 0x4)
+#define	VS_Y_HCOEF1_REG(n)	(0x300 + (n) * 0x4)
+#define	VS_Y_VCOEF_REG(n)	(0x400 + (n) * 0x4)
+#define	VS_C_HCOEF0_REG(n)	(0x600 + (n) * 0x4)
+#define	VS_C_HCOEF1_REG(n)	(0x700 + (n) * 0x4)
+#define	VS_C_VCOEF_REG(n)	(0x800 + (n) * 0x4)
+
+/* CSC registers */
+#define	CSC_BYPASS_REG		0x000
+#define	 CSC_BYPASS_DISABLE			__BIT(0)
+#define	CSC_COEFF0_REG(n)	(0x10 + 0x10 * (n))
+#define	GLB_ALPHA_REG		0x040
+
 enum {
 	MIXER_PORT_OUTPUT = 1,
 };
@@ -175,6 +209,16 @@ struct sunxi_mixer_softc {
 #define	OVL_UI_WRITE(sc, reg, val)			\
 	bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, OVL_UI_BASE + (reg), (val))
 
+#define	VSU_READ(sc, reg)\
+	bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, VSU_BASE + (reg))
+#define	VSU_WRITE(sc, reg, val)			\
+	bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, VSU_BASE + (reg), (val))
+
+#define	CSC_READ(sc, n, reg)\
+	bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, CSC_BASE(n) + (reg))
+#define	CSC_WRITE(sc, n, reg, val)			\
+	bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, CSC_BASE(n) + (reg), (val))
+
 #define	to_sunxi_mixer_crtc(x)		container_of(x, struct sunxi_mixer_crtc, base)
 #define	to_sunxi_mixer_overlay(x)	container_of(x, struct sunxi_mixer_overlay, base)
 
@@ -346,7 +390,7 @@ sunxi_mixer_overlay_destroy(struct drm_p
 }
 
 static bool
-sunxi_mixer_overlay_ui(uint32_t drm_format)
+sunxi_mixer_overlay_rgb(uint32_t drm_format)
 {
 	switch (drm_format) {
 	case DRM_FORMAT_XRGB:
@@ -372,6 +416,448 @@ sunxi_mixer_overlay_format(uint32_t drm_
 	}
 }
 
+static const uint32_t lan3coefftab32_left[512] = {
+	0x4000, 0x40fe, 0x3ffd0100, 0x3efc0100,
+	0x3efb0100, 0x3dfa0200, 0x3cf90200, 0x3bf80200,
+	0x39f70200, 0x37f70200, 0x35f70200, 0x33f70200,
+	0x31f70200, 0x2ef70200, 0x2cf70200, 0x2af70200,
+	0x27f70200, 0x24f80100, 0x22f80100, 0x1ef90100,
+	0x1cf90100, 0x19fa0100, 0x17fa0100, 0x14fb0100,
+	0x11fc, 0x0ffc, 0x0cfd, 0x0afd,
+	0x08fe, 0x05ff, 0x03ff, 0x0200,
+
+	0x4000, 0x40fe, 0x3ffd0100, 0x3efc0100,
+	0x3efb0100, 0x3dfa0200, 0x3cf90200, 0x3bf80200,
+	0x39f70200, 0x37f70200, 0x35f70200, 0x33f70200,
+	0x31f70200, 0x2ef70200, 0x2cf70200, 0x2af70200,
+	0x27f70200, 0x24f80100, 0x22f80100, 0x1ef90100,
+	0x1cf90100, 0x19fa0100, 0x17fa0100, 0x14fb0100,
+	0x11fc, 0x0ffc, 0x0cfd, 0x0afd,
+	0x08fe, 0x05ff, 0x03ff, 0x0200,
+
+	0x3806fc02, 0x3805fc02, 0x3803fd01, 0x3801fe01,
+	0x3700fe01, 0x3501, 0x35fdff01, 0x34fc0001,
+	0x34fb, 0x33fa, 0x31fa0100, 0x2ff90100,
+	0x2df80200, 0x2bf80200, 0x2af70200, 0x28f70200,
+	0x27f70200, 0x24f70300, 0x22f70300, 0x1ff70300,
+	0x1ef70300, 0x1cf70300, 0x1af70300, 0x18f70300,
+	0x16f80300, 0x13f80300, 0x11f90300, 0x0ef90300,
+	0x0efa0200, 0x0cfa0200, 

CVS commit: src/sys/arch/arm/sunxi

2019-02-04 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Feb  4 12:10:13 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_drm.c sunxi_drm.h sunxi_lcdc.c
sunxi_mixer.c

Log Message:
Add support for vblank irq and RGB overlay planes.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sunxi/sunxi_drm.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/sunxi/sunxi_drm.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sunxi/sunxi_lcdc.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sunxi_mixer.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/sunxi_drm.c
diff -u src/sys/arch/arm/sunxi/sunxi_drm.c:1.5 src/sys/arch/arm/sunxi/sunxi_drm.c:1.6
--- src/sys/arch/arm/sunxi/sunxi_drm.c:1.5	Sun Feb  3 15:43:57 2019
+++ src/sys/arch/arm/sunxi/sunxi_drm.c	Mon Feb  4 12:10:13 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_drm.c,v 1.5 2019/02/03 15:43:57 jmcneill Exp $ */
+/* $NetBSD: sunxi_drm.c,v 1.6 2019/02/04 12:10:13 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.5 2019/02/03 15:43:57 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.6 2019/02/04 12:10:13 jmcneill Exp $");
 
 #include 
 #include 
@@ -71,6 +71,10 @@ static void	sunxi_drm_init(device_t);
 
 static int	sunxi_drm_set_busid(struct drm_device *, struct drm_master *);
 
+static uint32_t	sunxi_drm_get_vblank_counter(struct drm_device *, unsigned int);
+static int	sunxi_drm_enable_vblank(struct drm_device *, unsigned int);
+static void	sunxi_drm_disable_vblank(struct drm_device *, unsigned int);
+
 static int	sunxi_drm_load(struct drm_device *, unsigned long);
 static int	sunxi_drm_unload(struct drm_device *);
 
@@ -88,11 +92,9 @@ static struct drm_driver sunxi_drm_drive
 	.dumb_map_offset = drm_gem_cma_dumb_map_offset,
 	.dumb_destroy = drm_gem_dumb_destroy,
 
-#if notyet
 	.get_vblank_counter = sunxi_drm_get_vblank_counter,
 	.enable_vblank = sunxi_drm_enable_vblank,
 	.disable_vblank = sunxi_drm_disable_vblank,
-#endif
 
 	.name = DRIVER_NAME,
 	.desc = DRIVER_DESC,
@@ -233,12 +235,23 @@ sunxi_drm_fb_create(struct drm_device *d
 	fb = kmem_zalloc(sizeof(*fb), KM_SLEEP);
 	fb->obj = to_drm_gem_cma_obj(gem_obj);
 	fb->base.pitches[0] = cmd->pitches[0];
+	fb->base.pitches[1] = cmd->pitches[1];
+	fb->base.pitches[2] = cmd->pitches[2];
 	fb->base.offsets[0] = cmd->offsets[0];
+	fb->base.offsets[1] = cmd->offsets[2];
+	fb->base.offsets[2] = cmd->offsets[1];
 	fb->base.width = cmd->width;
 	fb->base.height = cmd->height;
 	fb->base.pixel_format = cmd->pixel_format;
-	drm_fb_get_bpp_depth(cmd->pixel_format, >base.depth,
-	>base.bits_per_pixel);
+	fb->base.bits_per_pixel = drm_format_plane_cpp(fb->base.pixel_format, 0) * 8;
+
+	switch (fb->base.pixel_format) {
+	case DRM_FORMAT_XRGB:
+		fb->base.depth = 32;
+		break;
+	default:
+		break;
+	}
 
 	error = drm_framebuffer_init(ddev, >base, _drm_framebuffer_funcs);
 	if (error != 0)
@@ -372,6 +385,10 @@ sunxi_drm_load(struct drm_device *ddev, 
 
 	drm_fb_helper_initial_config(>helper, 32);
 
+	/* XXX */
+	ddev->irq_enabled = true;
+	drm_vblank_init(ddev, num_crtc);
+
 	return 0;
 
 drmerr:
@@ -381,6 +398,50 @@ drmerr:
 	return error;
 }
 
+static uint32_t
+sunxi_drm_get_vblank_counter(struct drm_device *ddev, unsigned int crtc)
+{
+	struct sunxi_drm_softc * const sc = sunxi_drm_private(ddev);
+
+	if (crtc >= __arraycount(sc->sc_vbl))
+		return 0;
+
+	if (sc->sc_vbl[crtc].get_vblank_counter == NULL)
+		return 0;
+
+	return sc->sc_vbl[crtc].get_vblank_counter(sc->sc_vbl[crtc].priv);
+}
+
+static int
+sunxi_drm_enable_vblank(struct drm_device *ddev, unsigned int crtc)
+{
+	struct sunxi_drm_softc * const sc = sunxi_drm_private(ddev);
+
+	if (crtc >= __arraycount(sc->sc_vbl))
+		return 0;
+
+	if (sc->sc_vbl[crtc].enable_vblank == NULL)
+		return 0;
+
+	sc->sc_vbl[crtc].enable_vblank(sc->sc_vbl[crtc].priv);
+
+	return 0;
+}
+
+static void
+sunxi_drm_disable_vblank(struct drm_device *ddev, unsigned int crtc)
+{
+	struct sunxi_drm_softc * const sc = sunxi_drm_private(ddev);
+
+	if (crtc >= __arraycount(sc->sc_vbl))
+		return;
+
+	if (sc->sc_vbl[crtc].disable_vblank == NULL)
+		return;
+
+	sc->sc_vbl[crtc].disable_vblank(sc->sc_vbl[crtc].priv);
+}
+
 static int
 sunxi_drm_unload(struct drm_device *ddev)
 {

Index: src/sys/arch/arm/sunxi/sunxi_drm.h
diff -u src/sys/arch/arm/sunxi/sunxi_drm.h:1.1 src/sys/arch/arm/sunxi/sunxi_drm.h:1.2
--- src/sys/arch/arm/sunxi/sunxi_drm.h:1.1	Wed Jan 30 01:24:00 2019
+++ src/sys/arch/arm/sunxi/sunxi_drm.h	Mon Feb  4 12:10:13 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_drm.h,v 1.1 2019/01/30 01:24:00 jmcneill Exp $ */
+/* $NetBSD: sunxi_drm.h,v 1.2 2019/02/04 12:10:13 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -44,6 +44,15 @@
 
 struct sunxi_framebuffer;
 
+#define	SUNXI_DRM_MAX_CRTC	2
+
+struct 

CVS commit: src/sys/arch/arm/sunxi

2019-02-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb  3 15:43:57 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_drm.c sunxi_platform.c

Log Message:
Support "nomodeset" kernel cmdline flag to disable sunxidrm


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sunxi/sunxi_drm.c
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/arm/sunxi/sunxi_platform.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/sunxi_drm.c
diff -u src/sys/arch/arm/sunxi/sunxi_drm.c:1.4 src/sys/arch/arm/sunxi/sunxi_drm.c:1.5
--- src/sys/arch/arm/sunxi/sunxi_drm.c:1.4	Thu Jan 31 01:49:28 2019
+++ src/sys/arch/arm/sunxi/sunxi_drm.c	Sun Feb  3 15:43:57 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_drm.c,v 1.4 2019/01/31 01:49:28 jmcneill Exp $ */
+/* $NetBSD: sunxi_drm.c,v 1.5 2019/02/03 15:43:57 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.4 2019/01/31 01:49:28 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.5 2019/02/03 15:43:57 jmcneill Exp $");
 
 #include 
 #include 
@@ -121,6 +121,8 @@ sunxi_drm_attach(device_t parent, device
 	struct sunxi_drm_softc * const sc = device_private(self);
 	struct fdt_attach_args * const faa = aux;
 	struct drm_driver * const driver = _drm_driver;
+	prop_dictionary_t dict = device_properties(self);
+	bool is_disabled;
 
 	sc->sc_dev = self;
 	sc->sc_dmat = faa->faa_dmat;
@@ -128,6 +130,12 @@ sunxi_drm_attach(device_t parent, device
 	sc->sc_phandle = faa->faa_phandle;
 
 	aprint_naive("\n");
+
+	if (prop_dictionary_get_bool(dict, "disabled", _disabled) && is_disabled) {
+		aprint_normal(": Display Engine Pipeline (disabled)\n");
+		return;
+	}
+
 	aprint_normal(": Display Engine Pipeline\n");
 
 	sc->sc_ddev = drm_dev_alloc(driver, sc->sc_dev);

Index: src/sys/arch/arm/sunxi/sunxi_platform.c
diff -u src/sys/arch/arm/sunxi/sunxi_platform.c:1.34 src/sys/arch/arm/sunxi/sunxi_platform.c:1.35
--- src/sys/arch/arm/sunxi/sunxi_platform.c:1.34	Thu Jan  3 14:44:21 2019
+++ src/sys/arch/arm/sunxi/sunxi_platform.c	Sun Feb  3 15:43:57 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_platform.c,v 1.34 2019/01/03 14:44:21 jmcneill Exp $ */
+/* $NetBSD: sunxi_platform.c,v 1.35 2019/02/03 15:43:57 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -31,7 +31,7 @@
 #include "opt_console.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_platform.c,v 1.34 2019/01/03 14:44:21 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_platform.c,v 1.35 2019/02/03 15:43:57 jmcneill Exp $");
 
 #include 
 #include 
@@ -201,6 +201,7 @@ static void
 sunxi_platform_device_register(device_t self, void *aux)
 {
 	prop_dictionary_t prop = device_properties(self);
+	int val;
 
 	if (device_is_a(self, "rgephy")) {
 		/* Pine64+ and NanoPi NEO Plus2 gigabit ethernet workaround */
@@ -224,6 +225,12 @@ sunxi_platform_device_register(device_t 
 			prop_dictionary_set_bool(prop, "sun50i-a64-unstable-timer", true);
 		}
 	}
+
+	if (device_is_a(self, "sunxidrm")) {
+		if (get_bootconf_option(boot_args, "nomodeset", BOOTOPT_TYPE_BOOLEAN, ))
+			if (val)
+prop_dictionary_set_bool(prop, "disabled", true);
+	}
 }
 
 static u_int



CVS commit: src/sys/arch/arm/sunxi

2019-02-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb  3 13:15:19 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_lcdc.c

Log Message:
Add TCON0 support


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sunxi_lcdc.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/sunxi_lcdc.c
diff -u src/sys/arch/arm/sunxi/sunxi_lcdc.c:1.2 src/sys/arch/arm/sunxi/sunxi_lcdc.c:1.3
--- src/sys/arch/arm/sunxi/sunxi_lcdc.c:1.2	Thu Jan 31 01:49:28 2019
+++ src/sys/arch/arm/sunxi/sunxi_lcdc.c	Sun Feb  3 13:15:19 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_lcdc.c,v 1.2 2019/01/31 01:49:28 jmcneill Exp $ */
+/* $NetBSD: sunxi_lcdc.c,v 1.3 2019/02/03 13:15:19 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_lcdc.c,v 1.2 2019/01/31 01:49:28 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_lcdc.c,v 1.3 2019/02/03 13:15:19 jmcneill Exp $");
 
 #include 
 #include 
@@ -47,11 +47,31 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_lcdc.c
 #define	 TCON_GCTL_TCON_EN			__BIT(31)
 #define	 TCON_GCTL_GAMMA_EN			__BIT(30)
 #define	 TCON_GCTL_IO_MAP_SEL			__BIT(0)
-
 #define	TCON_GINT0_REG		0x004
 #define	TCON_GINT1_REG		0x008
 #define	 TCON_GINT1_TCON1_LINE_INT_NUM		__BITS(11,0)
 
+#define	TCON0_CTL_REG		0x040
+#define	 TCON0_CTL_TCON0_EN			__BIT(31)
+#define	 TCON0_CTL_START_DELAY			__BITS(8,4)
+#define	 TCON0_CTL_TCON0_SRC_SEL		__BITS(2,0)
+#define	TCON0_DCLK_REG		0x044
+#define	 TCON0_DCLK_EN__BITS(31,28)
+#define	 TCON0_DCLK_DIV__BITS(6,0)
+#define	TCON0_BASIC0_REG	0x048
+#define	TCON0_BASIC1_REG	0x04c
+#define	TCON0_BASIC2_REG	0x050
+#define	TCON0_BASIC3_REG	0x054
+#define	TCON0_IO_POL_REG	0x088
+#define	 TCON0_IO_POL_IO_OUTPUT_SEL		__BIT(31)
+#define	 TCON0_IO_POL_DCLK_SEL			__BITS(30,28)
+#define	 TCON0_IO_POL_IO3_INV			__BIT(27)
+#define	 TCON0_IO_POL_IO2_INV			__BIT(26)
+#define	 TCON0_IO_POL_IO1_INV			__BIT(25)
+#define	 TCON0_IO_POL_IO0_INV			__BIT(24)
+#define	 TCON0_IO_POL_DATA_INV			__BITS(23,0)
+#define	TCON0_IO_TRI_REG	0x08c
+
 #define	TCON1_CTL_REG		0x090
 #define	 TCON1_CTL_TCON1_EN			__BIT(31)
 #define	 TCON1_CTL_START_DELAY			__BITS(8,4)
@@ -62,7 +82,6 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_lcdc.c
 #define	TCON1_BASIC3_REG	0x0a0
 #define	TCON1_BASIC4_REG	0x0a4
 #define	TCON1_BASIC5_REG	0x0a8
-
 #define	TCON1_IO_POL_REG	0x0f0
 #define	 TCON1_IO_POL_IO3_INV			__BIT(27)
 #define	 TCON1_IO_POL_IO2_INV			__BIT(26)
@@ -72,15 +91,20 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_lcdc.c
 #define	TCON1_IO_TRI_REG	0x0f4
 
 enum {
-	MIXER_PORT_INPUT = 0,
-	MIXER_PORT_OUTPUT = 1,
+	TCON_PORT_INPUT = 0,
+	TCON_PORT_OUTPUT = 1,
+};
+
+enum tcon_type {
+	TYPE_TCON0,
+	TYPE_TCON1,
 };
 
-static const char * const compatible[] = {
-	"allwinner,sun8i-h3-tcon-tv",
-	"allwinner,sun50i-a64-tcon-lcd",
-	"allwinner,sun50i-a64-tcon-tv",
-	NULL
+static const struct of_compat_data compat_data[] = {
+	{ "allwinner,sun8i-h3-tcon-tv",		TYPE_TCON1 },
+	{ "allwinner,sun50i-a64-tcon-lcd",	TYPE_TCON0 },
+	{ "allwinner,sun50i-a64-tcon-tv",	TYPE_TCON1 },
+	{ NULL }
 };
 
 struct sunxi_lcdc_softc;
@@ -97,6 +121,8 @@ struct sunxi_lcdc_softc {
 	bus_space_handle_t	sc_bsh;
 	int			sc_phandle;
 
+	enum tcon_type		sc_type;
+
 	struct clk		*sc_clk_ch[2];
 
 	struct sunxi_lcdc_encoder sc_encoder;
@@ -122,19 +148,19 @@ static const struct drm_encoder_funcs su
 };
 
 static void
-sunxi_lcdc_tcon1_dpms(struct drm_encoder *encoder, int mode)
+sunxi_lcdc_tcon_dpms(struct drm_encoder *encoder, int mode)
 {
 }
 
 static bool
-sunxi_lcdc_tcon1_mode_fixup(struct drm_encoder *encoder,
+sunxi_lcdc_tcon_mode_fixup(struct drm_encoder *encoder,
 const struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode)
 {
 	return true;
 }
 
 static void
-sunxi_lcdc_tcon1_mode_set(struct drm_encoder *encoder,
+sunxi_lcdc_tcon_mode_set(struct drm_encoder *encoder,
 struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode)
 {
 	struct sunxi_lcdc_encoder *lcdc_encoder = to_sunxi_lcdc_encoder(encoder);
@@ -143,6 +169,20 @@ sunxi_lcdc_tcon1_mode_set(struct drm_enc
 }
 
 static void
+sunxi_lcdc_tcon0_prepare(struct drm_encoder *encoder)
+{
+	struct sunxi_lcdc_encoder *lcdc_encoder = to_sunxi_lcdc_encoder(encoder);
+	struct sunxi_lcdc_softc * const sc = lcdc_encoder->sc;
+	uint32_t val;
+
+	val = TCON_READ(sc, TCON_GCTL_REG);
+	val |= TCON_GCTL_TCON_EN;
+	TCON_WRITE(sc, TCON_GCTL_REG, val);
+
+	TCON_WRITE(sc, TCON0_IO_TRI_REG, 0);
+}
+
+static void
 sunxi_lcdc_tcon1_prepare(struct drm_encoder *encoder)
 {
 	struct sunxi_lcdc_encoder *lcdc_encoder = to_sunxi_lcdc_encoder(encoder);
@@ -158,6 +198,61 @@ sunxi_lcdc_tcon1_prepare(struct drm_enco
 }
 
 static void
+sunxi_lcdc_tcon0_commit(struct drm_encoder *encoder)
+{
+	struct sunxi_lcdc_encoder *lcdc_encoder = to_sunxi_lcdc_encoder(encoder);
+	struct sunxi_lcdc_softc * 

CVS commit: src/sys/arch/arm/sunxi

2019-02-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Feb  2 17:35:16 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_dwhdmi.c

Log Message:
Enable regulator if present


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sunxi_dwhdmi.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/sunxi_dwhdmi.c
diff -u src/sys/arch/arm/sunxi/sunxi_dwhdmi.c:1.2 src/sys/arch/arm/sunxi/sunxi_dwhdmi.c:1.3
--- src/sys/arch/arm/sunxi/sunxi_dwhdmi.c:1.2	Thu Jan 31 01:49:28 2019
+++ src/sys/arch/arm/sunxi/sunxi_dwhdmi.c	Sat Feb  2 17:35:16 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_dwhdmi.c,v 1.2 2019/01/31 01:49:28 jmcneill Exp $ */
+/* $NetBSD: sunxi_dwhdmi.c,v 1.3 2019/02/02 17:35:16 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_dwhdmi.c,v 1.2 2019/01/31 01:49:28 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_dwhdmi.c,v 1.3 2019/02/02 17:35:16 jmcneill Exp $");
 
 #include 
 #include 
@@ -61,6 +61,7 @@ struct sunxi_dwhdmi_softc {
 	struct dwhdmi_softc	sc_base;
 	int			sc_phandle;
 	struct fdtbus_phy	*sc_phy;
+	struct fdtbus_regulator	*sc_regulator;
 
 	struct fdt_device_ports	sc_ports;
 	struct drm_display_mode	sc_curmode;
@@ -106,6 +107,15 @@ sunxi_dwhdmi_ep_activate(device_t dev, s
 		return ENXIO;
 	}
 
+	sc->sc_regulator = fdtbus_regulator_acquire(sc->sc_phandle, "hvcc-supply");
+	if (sc->sc_regulator != NULL) {
+		error = fdtbus_regulator_enable(sc->sc_regulator);
+		if (error != 0) {
+			device_printf(dev, "couldn't enable supply\n");
+			return error;
+		}
+	}
+
 	error = dwhdmi_bind(>sc_base, encoder);
 	if (error != 0)
 		return error;



CVS commit: src/sys/arch/arm/sunxi

2019-02-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Feb  2 17:26:38 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun50i_a64_gpio.c

Log Message:
Rename lcd function to lcd0


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sunxi/sun50i_a64_gpio.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/sun50i_a64_gpio.c
diff -u src/sys/arch/arm/sunxi/sun50i_a64_gpio.c:1.3 src/sys/arch/arm/sunxi/sun50i_a64_gpio.c:1.4
--- src/sys/arch/arm/sunxi/sun50i_a64_gpio.c:1.3	Sun May  6 10:34:23 2018
+++ src/sys/arch/arm/sunxi/sun50i_a64_gpio.c	Sat Feb  2 17:26:38 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun50i_a64_gpio.c,v 1.3 2018/05/06 10:34:23 jmcneill Exp $ */
+/* $NetBSD: sun50i_a64_gpio.c,v 1.4 2019/02/02 17:26:38 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sun50i_a64_gpio.c,v 1.3 2018/05/06 10:34:23 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun50i_a64_gpio.c,v 1.4 2019/02/02 17:26:38 jmcneill Exp $");
 
 #include 
 #include 
@@ -66,28 +66,28 @@ static const struct sunxi_gpio_pins a64_
 	{ "PC15", 2, 15,  { "gpio_in", "gpio_out", "nand", "mmc2" } },
 	{ "PC16", 2, 16,  { "gpio_in", "gpio_out", "nand", "mmc2" } },
 
-	{ "PD0",  3, 0,   { "gpio_in", "gpio_out", "lcd", "uart3", "spi1", "ccir" } },
-	{ "PD1",  3, 1,   { "gpio_in", "gpio_out", "lcd", "uart3", "spi1", "ccir" } },
-	{ "PD2",  3, 2,   { "gpio_in", "gpio_out", "lcd", "uart4", "spi1", "ccir" } },
-	{ "PD3",  3, 3,   { "gpio_in", "gpio_out", "lcd", "uart4", "spi1", "ccir" } },
-	{ "PD4",  3, 4,   { "gpio_in", "gpio_out", "lcd", "uart4", "spi1", "ccir" } },
-	{ "PD5",  3, 5,   { "gpio_in", "gpio_out", "lcd", "uart4", "spi1", "ccir" } },
-	{ "PD6",  3, 6,   { "gpio_in", "gpio_out", "lcd", NULL, NULL, "ccir" } },
-	{ "PD7",  3, 7,   { "gpio_in", "gpio_out", "lcd", NULL, NULL, "ccir" } },
-	{ "PD8",  3, 8,   { "gpio_in", "gpio_out", "lcd", NULL, "emac", "ccir" } },
-	{ "PD9",  3, 9,   { "gpio_in", "gpio_out", "lcd", NULL, "emac", "ccir" } },
-	{ "PD10", 3, 10,  { "gpio_in", "gpio_out", "lcd", NULL, "emac" } },
-	{ "PD11", 3, 11,  { "gpio_in", "gpio_out", "lcd", NULL, "emac" } },
-	{ "PD12", 3, 12,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac" } },
-	{ "PD13", 3, 13,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac" } },
-	{ "PD14", 3, 14,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac" } },
-	{ "PD15", 3, 15,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac", "ccir" } },
-	{ "PD16", 3, 16,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac", "ccir" } },
-	{ "PD17", 3, 17,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac" } },
-	{ "PD18", 3, 18,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac" } },
-	{ "PD19", 3, 19,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac" } },
-	{ "PD20", 3, 20,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac" } },
-	{ "PD21", 3, 21,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac" } },
+	{ "PD0",  3, 0,   { "gpio_in", "gpio_out", "lcd0", "uart3", "spi1", "ccir" } },
+	{ "PD1",  3, 1,   { "gpio_in", "gpio_out", "lcd0", "uart3", "spi1", "ccir" } },
+	{ "PD2",  3, 2,   { "gpio_in", "gpio_out", "lcd0", "uart4", "spi1", "ccir" } },
+	{ "PD3",  3, 3,   { "gpio_in", "gpio_out", "lcd0", "uart4", "spi1", "ccir" } },
+	{ "PD4",  3, 4,   { "gpio_in", "gpio_out", "lcd0", "uart4", "spi1", "ccir" } },
+	{ "PD5",  3, 5,   { "gpio_in", "gpio_out", "lcd0", "uart4", "spi1", "ccir" } },
+	{ "PD6",  3, 6,   { "gpio_in", "gpio_out", "lcd0", NULL, NULL, "ccir" } },
+	{ "PD7",  3, 7,   { "gpio_in", "gpio_out", "lcd0", NULL, NULL, "ccir" } },
+	{ "PD8",  3, 8,   { "gpio_in", "gpio_out", "lcd0", NULL, "emac", "ccir" } },
+	{ "PD9",  3, 9,   { "gpio_in", "gpio_out", "lcd0", NULL, "emac", "ccir" } },
+	{ "PD10", 3, 10,  { "gpio_in", "gpio_out", "lcd0", NULL, "emac" } },
+	{ "PD11", 3, 11,  { "gpio_in", "gpio_out", "lcd0", NULL, "emac" } },
+	{ "PD12", 3, 12,  { "gpio_in", "gpio_out", "lcd0", "lvds", "emac" } },
+	{ "PD13", 3, 13,  { "gpio_in", "gpio_out", "lcd0", "lvds", "emac" } },
+	{ "PD14", 3, 14,  { "gpio_in", "gpio_out", "lcd0", "lvds", "emac" } },
+	{ "PD15", 3, 15,  { "gpio_in", "gpio_out", "lcd0", "lvds", "emac", "ccir" } },
+	{ "PD16", 3, 16,  { "gpio_in", "gpio_out", "lcd0", "lvds", "emac", "ccir" } },
+	{ "PD17", 3, 17,  { "gpio_in", "gpio_out", "lcd0", "lvds", "emac" } },
+	{ "PD18", 3, 18,  { "gpio_in", "gpio_out", "lcd0", "lvds", "emac" } },
+	{ "PD19", 3, 19,  { "gpio_in", "gpio_out", "lcd0", "lvds", "emac" } },
+	{ "PD20", 3, 20,  { "gpio_in", "gpio_out", "lcd0", "lvds", "emac" } },
+	{ "PD21", 3, 21,  { "gpio_in", "gpio_out", "lcd0", "lvds", "emac" } },
 	{ "PD22", 3, 22,  { "gpio_in", "gpio_out", "pwm", NULL, "emac" } },
 	{ "PD23", 3, 23,  { "gpio_in", "gpio_out", NULL, NULL, "emac" } },
 	{ "PD24", 3, 24,  { "gpio_in", "gpio_out" } },



CVS commit: src/sys/arch/arm/sunxi

2019-01-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Jan 31 01:49:28 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun8i_h3_ccu.c sunxi_de2_ccu.c sunxi_drm.c
sunxi_dwhdmi.c sunxi_hdmiphy.c sunxi_lcdc.c sunxi_mixer.c

Log Message:
Add support for Allwinner H3/H5 display pipeline.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/arm/sunxi/sun8i_h3_ccu.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sunxi_de2_ccu.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sunxi/sunxi_drm.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/sunxi/sunxi_dwhdmi.c \
src/sys/arch/arm/sunxi/sunxi_hdmiphy.c \
src/sys/arch/arm/sunxi/sunxi_lcdc.c src/sys/arch/arm/sunxi/sunxi_mixer.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/sun8i_h3_ccu.c
diff -u src/sys/arch/arm/sunxi/sun8i_h3_ccu.c:1.15 src/sys/arch/arm/sunxi/sun8i_h3_ccu.c:1.16
--- src/sys/arch/arm/sunxi/sun8i_h3_ccu.c:1.15	Fri Jan 12 18:22:35 2018
+++ src/sys/arch/arm/sunxi/sun8i_h3_ccu.c	Thu Jan 31 01:49:28 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun8i_h3_ccu.c,v 1.15 2018/01/12 18:22:35 jakllsch Exp $ */
+/* $NetBSD: sun8i_h3_ccu.c,v 1.16 2019/01/31 01:49:28 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -29,7 +29,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_h3_ccu.c,v 1.15 2018/01/12 18:22:35 jakllsch Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_h3_ccu.c,v 1.16 2019/01/31 01:49:28 jmcneill Exp $");
 
 #include 
 #include 
@@ -43,13 +43,16 @@ __KERNEL_RCSID(1, "$NetBSD: sun8i_h3_ccu
 
 #define	PLL_CPUX_CTRL_REG	0x000
 #define	PLL_AUDIO_CTRL_REG	0x008
+#define	PLL_VIDEO_CTRL_REG	0x010
 #define	PLL_PERIPH0_CTRL_REG	0x028
+#define	PLL_DE_CTRL_REG		0x048
 #define	AHB1_APB1_CFG_REG	0x054
 #define	APB2_CFG_REG		0x058
 #define	AHB2_CFG_REG		0x05c
 #define	 AHB2_CLK_CFG		__BITS(1,0)
 #define	 AHB2_CLK_CFG_PLL_PERIPH0_2	1
 #define	BUS_CLK_GATING_REG0	0x060
+#define	BUS_CLK_GATING_REG1	0x064
 #define	BUS_CLK_GATING_REG2	0x068
 #define	BUS_CLK_GATING_REG3	0x06c
 #define	BUS_CLK_GATING_REG4	0x070
@@ -61,7 +64,11 @@ __KERNEL_RCSID(1, "$NetBSD: sun8i_h3_ccu
 #define	SPI1_CLK_REG		0x0a4
 #define	USBPHY_CFG_REG		0x0cc
 #define	MBUS_RST_REG		0x0fc
+#define	DE_CLK_REG		0x104
+#define	TCON0_CLK_REG		0x118
 #define	AC_DIG_CLK_REG		0x140
+#define	HDMI_CLK_REG		0x150
+#define	HDMI_SLOW_CLK_REG	0x154
 #define	BUS_SOFT_RST_REG0	0x2c0
 #define	BUS_SOFT_RST_REG1	0x2c4
 #define	BUS_SOFT_RST_REG2	0x2c8
@@ -149,6 +156,9 @@ static const char *apb1_parents[] = { "a
 static const char *apb2_parents[] = { "losc", "hosc", "pll_periph0" };
 static const char *mod_parents[] = { "hosc", "pll_periph0", "pll_periph1" };
 static const char *ths_parents[] = { "hosc" };
+static const char *de_parents[] = { "pll_periph0_2x", "pll_de" };
+static const char *hdmi_parents[] = { "pll_video" };
+static const char *tcon0_parents[] = { "pll_video" };
 
 static const struct sunxi_ccu_nkmp_tbl sun8i_h3_cpux_table[] = {
 	{ 6000, 9, 0, 0, 2 },
@@ -250,6 +260,21 @@ static struct sunxi_ccu_clk sun8i_h3_ccu
 	__BIT(31),			/* enable */
 	SUNXI_CCU_NKMP_DIVIDE_BY_TWO),
 
+	SUNXI_CCU_FIXED_FACTOR(H3_CLK_PLL_PERIPH0_2X, "pll_periph0_2x", "pll_periph0", 1, 2),
+
+	SUNXI_CCU_FRACTIONAL(H3_CLK_PLL_VIDEO, "pll_video", "hosc",
+	PLL_VIDEO_CTRL_REG,		/* reg */
+	__BITS(14,8),		/* m */
+	16,/* m_min */
+	50,/* m_max */
+	__BIT(24),			/* div_en */
+	__BIT(25),			/* frac_sel */
+	27000, 29700,	/* frac values */
+	__BITS(3,0),		/* prediv */
+	4,/* prediv_val */
+	__BIT(31),			/* enable */
+	SUNXI_CCU_FRACTIONAL_PLUSONE | SUNXI_CCU_FRACTIONAL_SET_ENABLE),
+
 	SUNXI_CCU_NKMP_TABLE(H3_CLK_PLL_AUDIO_BASE, "pll_audio", "hosc",
 	PLL_AUDIO_CTRL_REG,		/* reg */
 	__BITS(14,8),		/* n */
@@ -261,6 +286,19 @@ static struct sunxi_ccu_clk sun8i_h3_ccu
 	sun8i_h3_ac_dig_table,	/* table */
 	0),
 
+	SUNXI_CCU_FRACTIONAL(H3_CLK_PLL_DE, "pll_de", "hosc",
+	PLL_DE_CTRL_REG,		/* reg */
+	__BITS(14,8),		/* m */
+	16,/* m_min */
+	50,/* m_max */
+	__BIT(24),			/* div_en */
+	__BIT(25),			/* frac_sel */
+	27000, 29700,	/* frac values */
+	__BITS(3,0),		/* prediv */
+	2,/* prediv_val */
+	__BIT(31),			/* enable */
+	SUNXI_CCU_FRACTIONAL_PLUSONE | SUNXI_CCU_FRACTIONAL_SET_ENABLE),
+
 	SUNXI_CCU_PREDIV(H3_CLK_AHB1, "ahb1", ahb1_parents,
 	AHB1_APB1_CFG_REG,	/* reg */
 	__BITS(7,6),	/* prediv */
@@ -298,6 +336,13 @@ static struct sunxi_ccu_clk sun8i_h3_ccu
 	__BIT(31),		/* enable */
 	SUNXI_CCU_DIV_TIMES_TWO),
 
+	SUNXI_CCU_DIV_GATE(H3_CLK_DE, "de", de_parents,
+	DE_CLK_REG,		/* reg */
+	__BITS(3,0),	/* div */
+	__BITS(26,24),	/* sel */
+	__BIT(31),		/* enable */
+	0),
+
 	SUNXI_CCU_NM(H3_CLK_MMC0, "mmc0", mod_parents,
 	SDMMC0_CLK_REG, __BITS(17, 16), __BITS(3,0), __BITS(25, 

CVS commit: src/sys/arch/arm/sunxi

2019-01-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Jan 31 01:49:12 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_sramc.c

Log Message:
Match H3 system control


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sunxi_sramc.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/sunxi_sramc.c
diff -u src/sys/arch/arm/sunxi/sunxi_sramc.c:1.2 src/sys/arch/arm/sunxi/sunxi_sramc.c:1.3
--- src/sys/arch/arm/sunxi/sunxi_sramc.c:1.2	Tue Jan 22 16:35:48 2019
+++ src/sys/arch/arm/sunxi/sunxi_sramc.c	Thu Jan 31 01:49:12 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_sramc.c,v 1.2 2019/01/22 16:35:48 jmcneill Exp $ */
+/* $NetBSD: sunxi_sramc.c,v 1.3 2019/01/31 01:49:12 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_sramc.c,v 1.2 2019/01/22 16:35:48 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_sramc.c,v 1.3 2019/01/31 01:49:12 jmcneill Exp $");
 
 #include 
 #include 
@@ -44,6 +44,7 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_sramc.
 
 static const char * compatible[] = {
 	"allwinner,sun4i-a10-sram-controller",
+	"allwinner,sun8i-h3-system-control",
 	"allwinner,sun50i-a64-system-control",
 	"allwinner,sun50i-h6-system-control",
 	NULL



CVS commit: src/sys/arch/arm/sunxi

2019-01-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Jan 31 00:27:52 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun8i_h3_gpio.c

Log Message:
Update function name s_twi to s_i2c


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sun8i_h3_gpio.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/sun8i_h3_gpio.c
diff -u src/sys/arch/arm/sunxi/sun8i_h3_gpio.c:1.2 src/sys/arch/arm/sunxi/sun8i_h3_gpio.c:1.3
--- src/sys/arch/arm/sunxi/sun8i_h3_gpio.c:1.2	Tue Apr  3 16:01:25 2018
+++ src/sys/arch/arm/sunxi/sun8i_h3_gpio.c	Thu Jan 31 00:27:52 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun8i_h3_gpio.c,v 1.2 2018/04/03 16:01:25 bouyer Exp $ */
+/* $NetBSD: sun8i_h3_gpio.c,v 1.3 2019/01/31 00:27:52 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Emmanuel Vadot 
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sun8i_h3_gpio.c,v 1.2 2018/04/03 16:01:25 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun8i_h3_gpio.c,v 1.3 2019/01/31 00:27:52 jmcneill Exp $");
 
 #include 
 #include 
@@ -140,8 +140,8 @@ static const struct sunxi_gpio_pins h3_p
 };
 
 static const struct sunxi_gpio_pins h3_r_pins[] = {
-	{"PL0",  0, 0,  {"gpio_in", "gpio_out", "s_twi", NULL, NULL, NULL, "irq", NULL}, 6, 0},
-	{"PL1",  0, 1,  {"gpio_in", "gpio_out", "s_twi", NULL, NULL, NULL, "irq", NULL}, 6, 1},
+	{"PL0",  0, 0,  {"gpio_in", "gpio_out", "s_i2c", NULL, NULL, NULL, "irq", NULL}, 6, 0},
+	{"PL1",  0, 1,  {"gpio_in", "gpio_out", "s_i2c", NULL, NULL, NULL, "irq", NULL}, 6, 1},
 	{"PL2",  0, 2,  {"gpio_in", "gpio_out", "s_uart", NULL, NULL, NULL, "irq", NULL}, 6, 2},
 	{"PL3",  0, 3,  {"gpio_in", "gpio_out", "s_uart", NULL, NULL, NULL, "irq", NULL}, 6, 3},
 	{"PL4",  0, 4,  {"gpio_in", "gpio_out", "s_jtag", NULL, NULL, NULL, "irq", NULL}, 6, 4},



CVS commit: src/sys/arch/arm/sunxi

2019-01-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jan 30 11:36:42 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_sid.c

Log Message:
Match allwinner,sun50i-a64-sid


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sunxi_sid.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/sunxi_sid.c
diff -u src/sys/arch/arm/sunxi/sunxi_sid.c:1.2 src/sys/arch/arm/sunxi/sunxi_sid.c:1.3
--- src/sys/arch/arm/sunxi/sunxi_sid.c:1.2	Wed Jan  2 19:32:18 2019
+++ src/sys/arch/arm/sunxi/sunxi_sid.c	Wed Jan 30 11:36:42 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_sid.c,v 1.2 2019/01/02 19:32:18 jmcneill Exp $ */
+/* $NetBSD: sunxi_sid.c,v 1.3 2019/01/30 11:36:42 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_sid.c,v 1.2 2019/01/02 19:32:18 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_sid.c,v 1.3 2019/01/30 11:36:42 jmcneill Exp $");
 
 #include 
 #include 
@@ -59,6 +59,7 @@ static const struct of_compat_data compa
 	{ "allwinner,sun7i-a20-sid",	(uintptr_t)_a10_sid_config },
 	{ "allwinner,sun8i-h3-sid",	(uintptr_t)_h3_sid_config },
 	{ "allwinner,sun8i-a83t-sid",	(uintptr_t)_h3_sid_config },
+	{ "allwinner,sun50i-a64-sid",	(uintptr_t)_h3_sid_config },
 	{ NULL }
 };
 



CVS commit: src/sys/arch/arm/sunxi

2019-01-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jan 30 10:55:44 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_drm.c sunxi_fb.c

Log Message:
Revert previous


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sunxi_drm.c \
src/sys/arch/arm/sunxi/sunxi_fb.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/sunxi_drm.c
diff -u src/sys/arch/arm/sunxi/sunxi_drm.c:1.2 src/sys/arch/arm/sunxi/sunxi_drm.c:1.3
--- src/sys/arch/arm/sunxi/sunxi_drm.c:1.2	Wed Jan 30 02:44:19 2019
+++ src/sys/arch/arm/sunxi/sunxi_drm.c	Wed Jan 30 10:55:44 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_drm.c,v 1.2 2019/01/30 02:44:19 jmcneill Exp $ */
+/* $NetBSD: sunxi_drm.c,v 1.3 2019/01/30 10:55:44 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.2 2019/01/30 02:44:19 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.3 2019/01/30 10:55:44 jmcneill Exp $");
 
 #include 
 #include 
@@ -58,6 +58,11 @@ static const char * const compatible[] =
 	NULL
 };
 
+static const char * fb_compatible[] = {
+	"allwinner,simple-framebuffer",
+	NULL
+};
+
 static int	sunxi_drm_match(device_t, cfdata_t, void *);
 static void	sunxi_drm_attach(device_t, device_t, void *);
 
@@ -135,6 +140,8 @@ sunxi_drm_attach(device_t parent, device
 	sc->sc_ddev->dmat = sc->sc_ddev->bus_dmat;
 	sc->sc_ddev->dmat_subregion_p = false;
 
+	fdt_remove_bycompat(fb_compatible);
+
 	config_defer(self, sunxi_drm_init);
 }
 
Index: src/sys/arch/arm/sunxi/sunxi_fb.c
diff -u src/sys/arch/arm/sunxi/sunxi_fb.c:1.2 src/sys/arch/arm/sunxi/sunxi_fb.c:1.3
--- src/sys/arch/arm/sunxi/sunxi_fb.c:1.2	Wed Jan 30 02:44:19 2019
+++ src/sys/arch/arm/sunxi/sunxi_fb.c	Wed Jan 30 10:55:44 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_fb.c,v 1.2 2019/01/30 02:44:19 jmcneill Exp $ */
+/* $NetBSD: sunxi_fb.c,v 1.3 2019/01/30 10:55:44 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2019 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_wsdisplay_compat.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_fb.c,v 1.2 2019/01/30 02:44:19 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_fb.c,v 1.3 2019/01/30 10:55:44 jmcneill Exp $");
 
 #include 
 #include 
@@ -37,8 +37,6 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_fb.c,v
 
 #include 
 
-#include 
-
 #include 
 #include 
 
@@ -96,7 +94,6 @@ sunxi_fb_attach(device_t parent, device_
 	prop_dictionary_t dict = device_properties(self);
 	const bool is_console = true;
 	prop_dictionary_set_bool(dict, "is_console", is_console);
-	wsdisplay_cndetach();
 #endif
 
 	const struct drmfb_attach_args da = {



CVS commit: src/sys/arch/arm/sunxi

2019-01-29 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jan 30 02:44:20 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_drm.c sunxi_fb.c

Log Message:
Detach previous console device before attaching drmfb instead of relying on 
fdt_remove_bycompat hack


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/sunxi/sunxi_drm.c \
src/sys/arch/arm/sunxi/sunxi_fb.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/sunxi_drm.c
diff -u src/sys/arch/arm/sunxi/sunxi_drm.c:1.1 src/sys/arch/arm/sunxi/sunxi_drm.c:1.2
--- src/sys/arch/arm/sunxi/sunxi_drm.c:1.1	Wed Jan 30 01:24:00 2019
+++ src/sys/arch/arm/sunxi/sunxi_drm.c	Wed Jan 30 02:44:19 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_drm.c,v 1.1 2019/01/30 01:24:00 jmcneill Exp $ */
+/* $NetBSD: sunxi_drm.c,v 1.2 2019/01/30 02:44:19 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.1 2019/01/30 01:24:00 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.2 2019/01/30 02:44:19 jmcneill Exp $");
 
 #include 
 #include 
@@ -58,11 +58,6 @@ static const char * const compatible[] =
 	NULL
 };
 
-static const char * fb_compatible[] = {
-	"allwinner,simple-framebuffer",
-	NULL
-};
-
 static int	sunxi_drm_match(device_t, cfdata_t, void *);
 static void	sunxi_drm_attach(device_t, device_t, void *);
 
@@ -140,8 +135,6 @@ sunxi_drm_attach(device_t parent, device
 	sc->sc_ddev->dmat = sc->sc_ddev->bus_dmat;
 	sc->sc_ddev->dmat_subregion_p = false;
 
-	fdt_remove_bycompat(fb_compatible);
-
 	config_defer(self, sunxi_drm_init);
 }
 
Index: src/sys/arch/arm/sunxi/sunxi_fb.c
diff -u src/sys/arch/arm/sunxi/sunxi_fb.c:1.1 src/sys/arch/arm/sunxi/sunxi_fb.c:1.2
--- src/sys/arch/arm/sunxi/sunxi_fb.c:1.1	Wed Jan 30 01:24:00 2019
+++ src/sys/arch/arm/sunxi/sunxi_fb.c	Wed Jan 30 02:44:19 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_fb.c,v 1.1 2019/01/30 01:24:00 jmcneill Exp $ */
+/* $NetBSD: sunxi_fb.c,v 1.2 2019/01/30 02:44:19 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2019 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_wsdisplay_compat.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_fb.c,v 1.1 2019/01/30 01:24:00 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_fb.c,v 1.2 2019/01/30 02:44:19 jmcneill Exp $");
 
 #include 
 #include 
@@ -37,6 +37,8 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_fb.c,v
 
 #include 
 
+#include 
+
 #include 
 #include 
 
@@ -94,6 +96,7 @@ sunxi_fb_attach(device_t parent, device_
 	prop_dictionary_t dict = device_properties(self);
 	const bool is_console = true;
 	prop_dictionary_set_bool(dict, "is_console", is_console);
+	wsdisplay_cndetach();
 #endif
 
 	const struct drmfb_attach_args da = {



CVS commit: src/sys/arch/arm/sunxi

2019-01-22 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Jan 22 23:06:49 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun4i_a10_ccu.c sun50i_a64_ccu.c sunxi_ccu.h
sunxi_ccu_fractional.c

Log Message:
Add sun50i DE clocks.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/arm/sunxi/sun4i_a10_ccu.c \
src/sys/arch/arm/sunxi/sun50i_a64_ccu.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/arm/sunxi/sunxi_ccu.h
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sunxi_ccu_fractional.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/sun4i_a10_ccu.c
diff -u src/sys/arch/arm/sunxi/sun4i_a10_ccu.c:1.9 src/sys/arch/arm/sunxi/sun4i_a10_ccu.c:1.10
--- src/sys/arch/arm/sunxi/sun4i_a10_ccu.c:1.9	Mon Apr  2 20:57:18 2018
+++ src/sys/arch/arm/sunxi/sun4i_a10_ccu.c	Tue Jan 22 23:06:49 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun4i_a10_ccu.c,v 1.9 2018/04/02 20:57:18 bouyer Exp $ */
+/* $NetBSD: sun4i_a10_ccu.c,v 1.10 2019/01/22 23:06:49 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sun4i_a10_ccu.c,v 1.9 2018/04/02 20:57:18 bouyer Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun4i_a10_ccu.c,v 1.10 2019/01/22 23:06:49 jmcneill Exp $");
 
 #include 
 #include 
@@ -323,9 +323,10 @@ static struct sunxi_ccu_clk sun4i_a10_cc
 	__BIT(15),			/* div_en */
 	__BIT(14),			/* frac_sel */
 	27000, 29700,	/* frac values */
-	8,/* prediv */
-	__BIT(31)			/* enable */
-	),
+	0,/* prediv */
+	8,/* prediv_val */
+	__BIT(31),			/* enable */
+	0),
 	SUNXI_CCU_FRACTIONAL(A10_CLK_PLL_VIDEO1, "pll_video1", "osc24m",
 	PLL7_CFG_REG,		/* reg */
 	__BITS(7,0),		/* m */
@@ -334,9 +335,10 @@ static struct sunxi_ccu_clk sun4i_a10_cc
 	__BIT(15),			/* div_en */
 	__BIT(14),			/* frac_sel */
 	27000, 29700,	/* frac values */
-	8,/* prediv */
-	__BIT(31)			/* enable */
-	),
+	0,/* prediv */
+	8,/* prediv_val */
+	__BIT(31),			/* enable */
+	0),
 	SUNXI_CCU_FIXED_FACTOR(A10_CLK_PLL_VIDEO0_2X,
 	"pll_video0x2", "pll_video0",
 	1, 2),
Index: src/sys/arch/arm/sunxi/sun50i_a64_ccu.c
diff -u src/sys/arch/arm/sunxi/sun50i_a64_ccu.c:1.9 src/sys/arch/arm/sunxi/sun50i_a64_ccu.c:1.10
--- src/sys/arch/arm/sunxi/sun50i_a64_ccu.c:1.9	Fri May 18 02:03:00 2018
+++ src/sys/arch/arm/sunxi/sun50i_a64_ccu.c	Tue Jan 22 23:06:49 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun50i_a64_ccu.c,v 1.9 2018/05/18 02:03:00 jmcneill Exp $ */
+/* $NetBSD: sun50i_a64_ccu.c,v 1.10 2019/01/22 23:06:49 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sun50i_a64_ccu.c,v 1.9 2018/05/18 02:03:00 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun50i_a64_ccu.c,v 1.10 2019/01/22 23:06:49 jmcneill Exp $");
 
 #include 
 #include 
@@ -44,6 +44,7 @@ __KERNEL_RCSID(1, "$NetBSD: sun50i_a64_c
 #define	PLL_AUDIO_CTRL_REG	0x008
 #define	PLL_PERIPH0_CTRL_REG	0x028
 #define	PLL_PERIPH1_CTRL_REG	0x02c
+#define	PLL_DE_CTRL_REG		0x048
 #define	AHB1_APB1_CFG_REG	0x054
 #define	APB2_CFG_REG		0x058
 #define	AHB2_CFG_REG		0x05c
@@ -59,6 +60,7 @@ __KERNEL_RCSID(1, "$NetBSD: sun50i_a64_c
 #define	USBPHY_CFG_REG		0x0cc
 #define	DRAM_CFG_REG		0x0f4
 #define	MBUS_RST_REG		0x0fc
+#define	DE_CLK_REG		0x104
 #define	AC_DIG_CLK_REG		0x140
 #define	BUS_SOFT_RST_REG0	0x2c0
 #define	BUS_SOFT_RST_REG1	0x2c4
@@ -143,6 +145,7 @@ static const char *apb1_parents[] = { "a
 static const char *apb2_parents[] = { "losc", "hosc", "pll_periph0" };
 static const char *mmc_parents[] = { "hosc", "pll_periph0_2x", "pll_periph1_2x" };
 static const char *ths_parents[] = { "hosc", NULL, NULL, NULL };
+static const char *de_parents[] = { "pll_periph0_2x", "pll_de" };
 
 static const struct sunxi_ccu_nkmp_tbl sun50i_a64_cpux_table[] = {
 	{ 6000, 9, 0, 0, 2 },
@@ -259,6 +262,19 @@ static struct sunxi_ccu_clk sun50i_a64_c
 	SUNXI_CCU_FIXED_FACTOR(A64_CLK_PLL_AUDIO_4X, "pll_audio_4x", "pll_audio_base", 1, 4),
 	SUNXI_CCU_FIXED_FACTOR(A64_CLK_PLL_AUDIO_8X, "pll_audio_8x", "pll_audio_base", 1, 8),
 
+	SUNXI_CCU_FRACTIONAL(A64_CLK_PLL_DE, "pll_de", "hosc",
+	DE_CLK_REG,			/* reg */
+	__BITS(14,8),		/* m */
+	16,/* m_min */
+	50,/* m_max */
+	__BIT(24),			/* div_en */
+	__BIT(25),			/* frac_sel */
+	27000, 29700,	/* frac values */
+	__BITS(3,0),		/* prediv */
+	2,/* prediv_val */
+	__BIT(31),			/* enable */
+	SUNXI_CCU_FRACTIONAL_PLUSONE),
+
 	SUNXI_CCU_PREDIV(A64_CLK_AHB1, "ahb1", ahb1_parents,
 	AHB1_APB1_CFG_REG,	/* reg */
 	__BITS(7,6),	/* prediv */
@@ -318,6 +334,13 @@ static struct sunxi_ccu_clk sun50i_a64_c
 	__BIT(31),		/* enable */
 	SUNXI_CCU_DIV_TIMES_TWO),
 
+	SUNXI_CCU_DIV_GATE(A64_CLK_DE, "de", de_parents,
+	DE_CLK_REG,		/* reg 

CVS commit: src/sys/arch/arm/sunxi

2019-01-22 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Jan 22 21:45:39 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_de2_ccu.c

Log Message:
Enable parent clocks and de-assert resets


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/sunxi/sunxi_de2_ccu.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/sunxi_de2_ccu.c
diff -u src/sys/arch/arm/sunxi/sunxi_de2_ccu.c:1.1 src/sys/arch/arm/sunxi/sunxi_de2_ccu.c:1.2
--- src/sys/arch/arm/sunxi/sunxi_de2_ccu.c:1.1	Tue Jan 22 20:17:36 2019
+++ src/sys/arch/arm/sunxi/sunxi_de2_ccu.c	Tue Jan 22 21:45:39 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_de2_ccu.c,v 1.1 2019/01/22 20:17:36 jmcneill Exp $ */
+/* $NetBSD: sunxi_de2_ccu.c,v 1.2 2019/01/22 21:45:39 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sunxi_de2_ccu.c,v 1.1 2019/01/22 20:17:36 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sunxi_de2_ccu.c,v 1.2 2019/01/22 21:45:39 jmcneill Exp $");
 
 #include 
 #include 
@@ -103,19 +103,38 @@ sunxi_de2_ccu_attach(device_t parent, de
 {
 	struct sunxi_ccu_softc * const sc = device_private(self);
 	struct fdt_attach_args * const faa = aux;
+	const int phandle = faa->faa_phandle;
 	const struct sunxi_de2_ccu_config *conf;
+	struct clk *clk_bus, *clk_mod;
+	struct fdtbus_reset *rst;
 
 	sc->sc_dev = self;
-	sc->sc_phandle = faa->faa_phandle;
+	sc->sc_phandle = phandle;
 	sc->sc_bst = faa->faa_bst;
 
-	conf = (void *)of_search_compatible(faa->faa_phandle, compat_data)->data;
+	conf = (void *)of_search_compatible(phandle, compat_data)->data;
 
 	sc->sc_resets = conf->resets;
 	sc->sc_nresets = conf->nresets;
 	sc->sc_clks = conf->clks;
 	sc->sc_nclks = conf->nclks;
 
+	clk_bus = fdtbus_clock_get(phandle, "bus");
+	if (clk_bus == NULL || clk_enable(clk_bus) != 0) {
+		aprint_error(": couldn't enable bus clock\n");
+		return;
+	}
+	clk_mod = fdtbus_clock_get(phandle, "mod");
+	if (clk_mod == NULL || clk_enable(clk_mod) != 0) {
+		aprint_error(": couldn't enable mod clock\n");
+		return;
+	}
+	rst = fdtbus_reset_get_index(phandle, 0);
+	if (rst == NULL || fdtbus_reset_deassert(rst) != 0) {
+		aprint_error(": couldn't de-assert reset\n");
+		return;
+	}
+
 	if (sunxi_ccu_attach(sc) != 0)
 		return;
 



CVS commit: src/sys/arch/arm/sunxi

2019-01-22 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Jan 22 16:35:48 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_sramc.c

Log Message:
Add support for A64 and H6, and register self as a syscon


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/sunxi/sunxi_sramc.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/sunxi_sramc.c
diff -u src/sys/arch/arm/sunxi/sunxi_sramc.c:1.1 src/sys/arch/arm/sunxi/sunxi_sramc.c:1.2
--- src/sys/arch/arm/sunxi/sunxi_sramc.c:1.1	Mon Oct  9 15:53:28 2017
+++ src/sys/arch/arm/sunxi/sunxi_sramc.c	Tue Jan 22 16:35:48 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_sramc.c,v 1.1 2017/10/09 15:53:28 jmcneill Exp $ */
+/* $NetBSD: sunxi_sramc.c,v 1.2 2019/01/22 16:35:48 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_sramc.c,v 1.1 2017/10/09 15:53:28 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_sramc.c,v 1.2 2019/01/22 16:35:48 jmcneill Exp $");
 
 #include 
 #include 
@@ -35,13 +35,17 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_sramc.
 #include 
 #include 
 #include 
+#include 
 
 #include 
+#include 
 
 #include 
 
 static const char * compatible[] = {
 	"allwinner,sun4i-a10-sram-controller",
+	"allwinner,sun50i-a64-system-control",
+	"allwinner,sun50i-h6-system-control",
 	NULL
 };
 
@@ -50,13 +54,18 @@ static const struct sunxi_sramc_area {
 	const char			*desc;
 	bus_size_t			reg;
 	uint32_t			mask;
+	u_intflags;
+#define	SUNXI_SRAMC_F_SWAP		__BIT(0)
 } sunxi_sramc_areas[] = {
 	{ "allwinner,sun4i-a10-sram-a3-a4",
 	  "SRAM A3/A4",
-	  0x04, __BITS(5,4) },
+	  0x04, __BITS(5,4), 0 },
 	{ "allwinner,sun4i-a10-sram-d",
 	  "SRAM D",
-	  0x04, __BIT(0) }
+	  0x04, __BIT(0), 0 },
+	{ "allwinner,sun50i-a64-sram-c",
+	  "SRAM C",
+	  0x04, __BIT(24), SUNXI_SRAMC_F_SWAP },
 };
 
 struct sunxi_sramc_node {
@@ -70,6 +79,8 @@ struct sunxi_sramc_softc {
 	intsc_phandle;
 	bus_space_tag_t			sc_bst;
 	bus_space_handle_t		sc_bsh;
+	kmutex_t			sc_lock;
+	struct syscon			sc_syscon;
 	TAILQ_HEAD(, sunxi_sramc_node)	sc_nodes;
 };
 
@@ -113,6 +124,42 @@ sunxi_sramc_init(struct sunxi_sramc_soft
 	}
 }
 
+static void
+sunxi_sramc_lock(void *priv)
+{
+	struct sunxi_sramc_softc * const sc = priv;
+
+	mutex_enter(>sc_lock);
+}
+
+static void
+sunxi_sramc_unlock(void *priv)
+{
+	struct sunxi_sramc_softc * const sc = priv;
+
+	mutex_exit(>sc_lock);
+}
+
+static uint32_t
+sunxi_sramc_read_4(void *priv, bus_size_t reg)
+{
+	struct sunxi_sramc_softc * const sc = priv;
+
+	KASSERT(mutex_owned(>sc_lock));
+
+	return SRAMC_READ(sc, reg);
+}
+
+static void
+sunxi_sramc_write_4(void *priv, bus_size_t reg, uint32_t val)
+{
+	struct sunxi_sramc_softc * const sc = priv;
+
+	KASSERT(mutex_owned(>sc_lock));
+
+	SRAMC_WRITE(sc, reg, val);
+}
+
 static int
 sunxi_sramc_match(device_t parent, cfdata_t cf, void *aux)
 {
@@ -142,6 +189,7 @@ sunxi_sramc_attach(device_t parent, devi
 		aprint_error(": couldn't map registers\n");
 		return;
 	}
+	mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_VM);
 	TAILQ_INIT(>sc_nodes);
 
 	aprint_naive("\n");
@@ -151,6 +199,13 @@ sunxi_sramc_attach(device_t parent, devi
 
 	KASSERT(sramc_softc == NULL);
 	sramc_softc = sc;
+
+	sc->sc_syscon.priv = sc;
+	sc->sc_syscon.lock = sunxi_sramc_lock;
+	sc->sc_syscon.unlock = sunxi_sramc_unlock;
+	sc->sc_syscon.read_4 = sunxi_sramc_read_4;
+	sc->sc_syscon.write_4 = sunxi_sramc_write_4;
+	fdtbus_register_syscon(self, phandle, >sc_syscon);
 }
 
 CFATTACH_DECL_NEW(sunxi_sramc, sizeof(struct sunxi_sramc_softc),
@@ -170,6 +225,8 @@ sunxi_sramc_map(const int node_phandle, 
 		if (node->phandle == node_phandle) {
 			if (config > __SHIFTOUT_MASK(node->area->mask))
 return ERANGE;
+			if ((node->area->flags & SUNXI_SRAMC_F_SWAP) != 0)
+config = !config;
 			val = SRAMC_READ(sc, node->area->reg);
 			val &= ~node->area->mask;
 			val |= __SHIFTIN(config, node->area->mask);



CVS commit: src/sys/arch/arm/sunxi

2019-01-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Jan  3 15:49:09 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun9i_a80_ccu.c

Log Message:
Add c0cpux and c1cpux clocks


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/sunxi/sun9i_a80_ccu.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/sun9i_a80_ccu.c
diff -u src/sys/arch/arm/sunxi/sun9i_a80_ccu.c:1.1 src/sys/arch/arm/sunxi/sun9i_a80_ccu.c:1.2
--- src/sys/arch/arm/sunxi/sun9i_a80_ccu.c:1.1	Sun Oct  8 18:00:36 2017
+++ src/sys/arch/arm/sunxi/sun9i_a80_ccu.c	Thu Jan  3 15:49:09 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun9i_a80_ccu.c,v 1.1 2017/10/08 18:00:36 jmcneill Exp $ */
+/* $NetBSD: sun9i_a80_ccu.c,v 1.2 2019/01/03 15:49:09 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sun9i_a80_ccu.c,v 1.1 2017/10/08 18:00:36 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun9i_a80_ccu.c,v 1.2 2019/01/03 15:49:09 jmcneill Exp $");
 
 #include 
 #include 
@@ -41,14 +41,19 @@ __KERNEL_RCSID(1, "$NetBSD: sun9i_a80_cc
 #include 
 
 /* CCU */
+#define	PLL_C0CPUX_CTRL_REG	0x000
+#define	PLL_C1CPUX_CTRL_REG	0x004
 #define	PLL_PERIPH0_CTRL_REG	0x00c
 #define	PLL_PERIPH1_CTRL_REG	0x02c
+#define	CPU_CLK_SRC_REG		0x050
+#define	 CPU_CLK_SRC_SELECT(cluster)	__BIT((cluster) * 8)
 #define	GTBUS_CLK_CFG_REG	0x05c
 #define	AHB0_CLK_CFG_REG	0x060
 #define	AHB1_CLK_CFG_REG	0x064
 #define	AHB2_CLK_CFG_REG	0x068
 #define	APB0_CLK_CFG_REG	0x070
 #define	APB1_CLK_CFG_REG	0x074
+#define	PLL_STABLE_STATUS_REG	0x09c
 
 /* CCU_SCLK */
 #define	SDMMC0_CLK_REG		0x410
@@ -125,7 +130,91 @@ static const char *ahb2_parents[] = { "h
 static const char *apb_parents[] = { "hosc", "pll_periph0" };
 static const char *mmc_parents[] = { "hosc", "pll_periph0" };
 
+static kmutex_t cpux_axi_cfg_lock;
+
+static int
+sun9i_a80_ccu_cpux_set_rate(struct sunxi_ccu_softc *sc,
+struct sunxi_ccu_clk *clk, u_int rate)
+{   
+	const int cluster = clk->u.nkmp.reg == PLL_C0CPUX_CTRL_REG ? 0 : 1;
+	struct sunxi_ccu_nkmp *nkmp = >u.nkmp;
+	uint32_t val;
+	u_int n;
+
+	n = rate / 2400;
+	if (n < 0x11 || n > 0xff)
+		return EINVAL;
+
+	/* Switch cluster to OSC24M clock */
+	mutex_enter(_axi_cfg_lock);
+	val = CCU_READ(sc, CPU_CLK_SRC_REG);
+	val &= ~CPU_CLK_SRC_SELECT(cluster);
+	CCU_WRITE(sc, CPU_CLK_SRC_REG, val);
+	mutex_exit(_axi_cfg_lock);
+
+	/* Set new PLL rate */
+	val = CCU_READ(sc, nkmp->reg);
+	val &= ~nkmp->n;
+	val |= __SHIFTIN(n, nkmp->n);
+	CCU_WRITE(sc, nkmp->reg, val);
+
+	/* Wait for PLL lock */
+	while ((CCU_READ(sc, PLL_STABLE_STATUS_REG) & nkmp->lock) == 0)
+		;
+
+	/* Switch cluster back to CPUX PLL */
+	mutex_enter(_axi_cfg_lock);
+	val = CCU_READ(sc, CPU_CLK_SRC_REG);
+	val |= CPU_CLK_SRC_SELECT(cluster);
+	CCU_WRITE(sc, CPU_CLK_SRC_SELECT(cluster), val);
+	mutex_exit(_axi_cfg_lock);
+
+	return 0;
+}
+
 static struct sunxi_ccu_clk sun9i_a80_ccu_clks[] = {
+	[A80_CLK_C0CPUX] = {
+		.type = SUNXI_CCU_NKMP,
+		.base.name = "pll_c0cpux",
+		.u.nkmp.reg = PLL_C0CPUX_CTRL_REG,
+		.u.nkmp.parent = "hosc",
+		.u.nkmp.n = __BITS(15,8),
+		.u.nkmp.k = 0,
+		.u.nkmp.m = __BITS(1,0),
+		.u.nkmp.p = __BIT(16),
+		.u.nkmp.enable = __BIT(31),
+		.u.nkmp.flags = SUNXI_CCU_NKMP_SCALE_CLOCK |
+			SUNXI_CCU_NKMP_FACTOR_N_EXACT |
+			SUNXI_CCU_NKMP_FACTOR_P_X4,
+		.u.nkmp.lock = __BIT(1),/* PLL_STABLE_STATUS_REG */
+		.u.nkmp.table = NULL,
+		.enable = sunxi_ccu_nkmp_enable,
+		.get_rate = sunxi_ccu_nkmp_get_rate,
+		.set_rate = sun9i_a80_ccu_cpux_set_rate,
+		.get_parent = sunxi_ccu_nkmp_get_parent,
+	},
+
+	[A80_CLK_C1CPUX] = {
+		.type = SUNXI_CCU_NKMP,
+		.base.name = "pll_c1cpux",
+		.u.nkmp.reg = PLL_C1CPUX_CTRL_REG,
+		.u.nkmp.parent = "hosc",
+		.u.nkmp.n = __BITS(15,8),
+		.u.nkmp.k = 0,
+		.u.nkmp.m = __BITS(1,0),
+		.u.nkmp.p = __BIT(16),
+		.u.nkmp.enable = __BIT(31),
+		.u.nkmp.flags = SUNXI_CCU_NKMP_SCALE_CLOCK |
+			SUNXI_CCU_NKMP_FACTOR_N_EXACT |
+			SUNXI_CCU_NKMP_FACTOR_P_X4,
+		.u.nkmp.lock = __BIT(1),/* PLL_STABLE_STATUS_REG */
+		.u.nkmp.table = NULL,
+		.enable = sunxi_ccu_nkmp_enable,
+		.get_rate = sunxi_ccu_nkmp_get_rate,
+		.set_rate = sun9i_a80_ccu_cpux_set_rate,
+		.get_parent = sunxi_ccu_nkmp_get_parent,
+	},
+
 	SUNXI_CCU_NKMP(A80_CLK_PLL_PERIPH0, "pll_periph0", "hosc",
 	PLL_PERIPH0_CTRL_REG,	/* reg */
 	__BITS(15,8),		/* n */
@@ -315,6 +404,8 @@ sun9i_a80_ccu_attach(device_t parent, de
 	sc->sc_clks = sun9i_a80_ccu_clks;
 	sc->sc_nclks = __arraycount(sun9i_a80_ccu_clks);
 
+	mutex_init(_axi_cfg_lock, MUTEX_DEFAULT, IPL_HIGH);
+
 	if (sunxi_ccu_attach(sc) != 0)
 		return;
 



CVS commit: src/sys/arch/arm/sunxi

2019-01-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Jan  3 15:34:41 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_mmc.c

Log Message:
Reduce timeouts and add hw reset support


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/arm/sunxi/sunxi_mmc.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/sunxi_mmc.c
diff -u src/sys/arch/arm/sunxi/sunxi_mmc.c:1.31 src/sys/arch/arm/sunxi/sunxi_mmc.c:1.32
--- src/sys/arch/arm/sunxi/sunxi_mmc.c:1.31	Thu Jan  3 14:49:05 2019
+++ src/sys/arch/arm/sunxi/sunxi_mmc.c	Thu Jan  3 15:34:41 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mmc.c,v 1.31 2019/01/03 14:49:05 jmcneill Exp $ */
+/* $NetBSD: sunxi_mmc.c,v 1.32 2019/01/03 15:34:41 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_sunximmc.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mmc.c,v 1.31 2019/01/03 14:49:05 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mmc.c,v 1.32 2019/01/03 15:34:41 jmcneill Exp $");
 
 #include 
 #include 
@@ -525,6 +525,15 @@ sunxi_mmc_set_clock(struct sunxi_mmc_sof
 }
 
 static void
+sunxi_mmc_hw_reset(struct sunxi_mmc_softc *sc)
+{
+	MMC_WRITE(sc, SUNXI_MMC_HWRST, 0);
+	delay(1000);
+	MMC_WRITE(sc, SUNXI_MMC_HWRST, 1);
+	delay(1000);
+}
+
+static void
 sunxi_mmc_attach_i(device_t self)
 {
 	struct sunxi_mmc_softc *sc = device_private(self);
@@ -535,6 +544,9 @@ sunxi_mmc_attach_i(device_t self)
 	if (sc->sc_pwrseq)
 		fdtbus_mmc_pwrseq_pre_power_on(sc->sc_pwrseq);
 
+	if (of_hasprop(sc->sc_phandle, "cap-mmc-hw-reset"))
+		sunxi_mmc_hw_reset(sc);
+
 	sunxi_mmc_host_reset(sc);
 	sunxi_mmc_bus_width(sc, 1);
 	sunxi_mmc_set_clock(sc, 400, false);
@@ -1144,7 +1156,7 @@ sunxi_mmc_exec_command(sdmmc_chipset_han
 	}
 
 	cmd->c_error = sunxi_mmc_wait_rint(sc,
-	SUNXI_MMC_INT_ERROR|SUNXI_MMC_INT_CMD_DONE, hz * 10, poll);
+	SUNXI_MMC_INT_ERROR|SUNXI_MMC_INT_CMD_DONE, hz * 3, poll);
 	if (cmd->c_error == 0 && (sc->sc_intr_rint & SUNXI_MMC_INT_ERROR)) {
 		if (sc->sc_intr_rint & SUNXI_MMC_INT_RESP_TIMEOUT) {
 			cmd->c_error = ETIMEDOUT;
@@ -1165,7 +1177,7 @@ sunxi_mmc_exec_command(sdmmc_chipset_han
 		SUNXI_MMC_INT_ERROR|
 		SUNXI_MMC_INT_AUTO_CMD_DONE|
 		SUNXI_MMC_INT_DATA_OVER,
-		hz*10, poll);
+		hz*3, poll);
 		if (cmd->c_error == 0 &&
 		(sc->sc_intr_rint & SUNXI_MMC_INT_ERROR)) {
 			cmd->c_error = ETIMEDOUT;



CVS commit: src/sys/arch/arm/sunxi

2019-01-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Jan  3 14:49:05 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_mmc.c

Log Message:
Reduce sunxi_mmc_update_clock timeout from 10s to 1s


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/arm/sunxi/sunxi_mmc.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/sunxi_mmc.c
diff -u src/sys/arch/arm/sunxi/sunxi_mmc.c:1.30 src/sys/arch/arm/sunxi/sunxi_mmc.c:1.31
--- src/sys/arch/arm/sunxi/sunxi_mmc.c:1.30	Wed Jan  2 18:39:01 2019
+++ src/sys/arch/arm/sunxi/sunxi_mmc.c	Thu Jan  3 14:49:05 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mmc.c,v 1.30 2019/01/02 18:39:01 jmcneill Exp $ */
+/* $NetBSD: sunxi_mmc.c,v 1.31 2019/01/03 14:49:05 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_sunximmc.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mmc.c,v 1.30 2019/01/02 18:39:01 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mmc.c,v 1.31 2019/01/03 14:49:05 jmcneill Exp $");
 
 #include 
 #include 
@@ -761,7 +761,7 @@ sunxi_mmc_update_clock(struct sunxi_mmc_
 	  SUNXI_MMC_CMD_UPCLK_ONLY |
 	  SUNXI_MMC_CMD_WAIT_PRE_OVER;
 	MMC_WRITE(sc, SUNXI_MMC_CMD, cmd);
-	retry = 0xf;
+	retry = 10;
 	while (--retry > 0) {
 		if (!(MMC_READ(sc, SUNXI_MMC_CMD) & SUNXI_MMC_CMD_START))
 			break;



CVS commit: src/sys/arch/arm/sunxi

2019-01-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Jan  3 14:44:21 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: files.sunxi sunxi_mc_smp.c sunxi_mc_smp.h
sunxi_platform.c

Log Message:
Add Allwinner A80 SMP support.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/arm/sunxi/files.sunxi
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sunxi_mc_smp.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/sunxi/sunxi_mc_smp.h
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/arm/sunxi/sunxi_platform.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.58 src/sys/arch/arm/sunxi/files.sunxi:1.59
--- src/sys/arch/arm/sunxi/files.sunxi:1.58	Thu Jan  3 11:01:59 2019
+++ src/sys/arch/arm/sunxi/files.sunxi	Thu Jan  3 14:44:21 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: files.sunxi,v 1.58 2019/01/03 11:01:59 jmcneill Exp $
+#	$NetBSD: files.sunxi,v 1.59 2019/01/03 14:44:21 jmcneill Exp $
 #
 # Configuration info for Allwinner sunxi family SoCs
 #
@@ -312,7 +312,7 @@ defflag	opt_soc.h			SOC_SUN8I: SOC_SUNXI
 defflag	opt_soc.h			SOC_SUN8I_A83T: SOC_SUN8I, SOC_SUNXI_MC
 defflag	opt_soc.h			SOC_SUN8I_H3: SOC_SUN8I
 defflag	opt_soc.h			SOC_SUN9I: SOC_SUNXI
-defflag	opt_soc.h			SOC_SUN9I_A80: SOC_SUN9I
+defflag	opt_soc.h			SOC_SUN9I_A80: SOC_SUN9I, SOC_SUNXI_MC
 defflag	opt_soc.h			SOC_SUN50I: SOC_SUNXI
 defflag	opt_soc.h			SOC_SUN50I_A64: SOC_SUN50I
 defflag	opt_soc.h			SOC_SUN50I_H5: SOC_SUN50I, SOC_SUN8I_H3

Index: src/sys/arch/arm/sunxi/sunxi_mc_smp.c
diff -u src/sys/arch/arm/sunxi/sunxi_mc_smp.c:1.2 src/sys/arch/arm/sunxi/sunxi_mc_smp.c:1.3
--- src/sys/arch/arm/sunxi/sunxi_mc_smp.c:1.2	Thu Jan  3 12:52:40 2019
+++ src/sys/arch/arm/sunxi/sunxi_mc_smp.c	Thu Jan  3 14:44:21 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mc_smp.c,v 1.2 2019/01/03 12:52:40 jmcneill Exp $ */
+/* $NetBSD: sunxi_mc_smp.c,v 1.3 2019/01/03 14:44:21 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mc_smp.c,v 1.2 2019/01/03 12:52:40 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mc_smp.c,v 1.3 2019/01/03 14:44:21 jmcneill Exp $");
 
 #include 
 #include 
@@ -46,14 +46,16 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_mc_smp
 
 #include 
 
-#define	A83T_SMP_ENABLE_METHOD	"allwinner,sun8i-a83t-smp"
+#define	A80_PRCM_BASE		0x08001400
+#define	A80_PRCM_SIZE		0x200
 
-#define	PRCM_BASE		0x01f01400
-#define	PRCM_SIZE		0x800
+#define	A83T_PRCM_BASE		0x01f01400
+#define	A83T_PRCM_SIZE		0x800
 
 #define	 PRCM_CL_RST_CTRL(cluster)	(0x4 + (cluster) * 0x4)
 #define	 PRCM_CL_PWROFF(cluster)	(0x100 + (cluster) * 0x4)
 #define	 PRCM_CL_PWR_CLAMP(cluster, cpu) (0x140 + (cluster) * 0x10 + (cpu) * 0x4)
+#define	 PRCM_CPU_SOFT_ENTRY		0x164
 
 #define	CPUCFG_BASE	0x01f01c00
 #define	CPUCFG_SIZE	0x400
@@ -70,27 +72,31 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_mc_smp
 #define	  CPUXCFG_CL_RST_DBG_RST(cpu)	__BIT(16 + (cpu))
 #define	  CPUXCFG_CL_RST_H_RST		__BIT(12)
 #define	  CPUXCFG_CL_RST_L2_RST		__BIT(8)
+#define	  CPUXCFG_CL_RST_CX_RST(cpu)	__BIT(4 + (cpu))
 #define	 CPUXCFG_CL_CTRL0(cluster)	(0x0 + (cluster) * 0x10)
 #define	 CPUXCFG_CL_CTRL1(cluster)	(0x4 + (cluster) * 0x10)
 #define	  CPUXCFG_CL_CTRL1_ACINACTM	__BIT(0)
 
-#define	CCI_BASE		0x0179
-#define	CCI_SLAVEIF3_BASE	(CCI_BASE + 0x4000)
-#define	CCI_SLAVEIF4_BASE	(CCI_BASE + 0x5000)
+#define	A80_CCI_BASE		0x01c9
+#define	A83T_CCI_BASE		0x0179
+
+#define	CCI_SLAVEIF3_OFFSET	0x4000
+#define	CCI_SLAVEIF4_OFFSET	0x5000
 
 extern struct bus_space arm_generic_bs_tag;
 
-uint32_t sunxi_mc_cci_port[MAXCPUS] = {
-	CCI_SLAVEIF3_BASE,
-	CCI_SLAVEIF3_BASE,
-	CCI_SLAVEIF3_BASE,
-	CCI_SLAVEIF3_BASE,
-	CCI_SLAVEIF4_BASE,
-	CCI_SLAVEIF4_BASE,
-	CCI_SLAVEIF4_BASE,
-	CCI_SLAVEIF4_BASE,
+enum sunxi_mc_soc {
+	MC_SOC_A80,
+	MC_SOC_A83T
+};
+
+enum sunxi_mc_cpu {
+	MC_CORE_CA7,
+	MC_CORE_CA15
 };
 
+uint32_t sunxi_mc_cci_port[MAXCPUS];
+
 static uint32_t
 sunxi_mc_smp_pa(void)
 {
@@ -106,28 +112,30 @@ sunxi_mc_smp_pa(void)
 
 static int
 sunxi_mc_smp_start(bus_space_tag_t bst, bus_space_handle_t prcm, bus_space_handle_t cpucfg,
-bus_space_handle_t cpuxcfg, u_int cluster, u_int cpu)
+bus_space_handle_t cpuxcfg, u_int cluster, u_int cpu, enum sunxi_mc_soc soc,
+enum sunxi_mc_cpu core)
 {
 	uint32_t val;
 	int i;
 
-	/* Set start vector */
-	bus_space_write_4(bst, cpucfg, CPUCFG_P_REG0, sunxi_mc_smp_pa());
-
 	/* Assert core reset */
 	val = bus_space_read_4(bst, cpuxcfg, CPUXCFG_CL_RST(cluster));
 	val &= ~__BIT(cpu);
 	bus_space_write_4(bst, cpuxcfg, CPUXCFG_CL_RST(cluster), val);
 
-	/* Assert power-on reset */
-	val = bus_space_read_4(bst, cpucfg, CPUCFG_CL_RST(cluster));
-	val &= ~__BIT(cpu);
-	bus_space_write_4(bst, cpucfg, CPUCFG_CL_RST(cluster), val);
+	if (soc == MC_SOC_A83T) {
+		/* Assert power-on reset */
+		val = 

CVS commit: src/sys/arch/arm/sunxi

2019-01-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Jan  3 11:01:59 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: files.sunxi sunxi_platform.c
Added Files:
src/sys/arch/arm/sunxi: sunxi_mc_mpstart.S sunxi_mc_smp.c
sunxi_mc_smp.h

Log Message:
Add Allwinner A83T SMP support.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/arch/arm/sunxi/files.sunxi
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/sunxi/sunxi_mc_mpstart.S \
src/sys/arch/arm/sunxi/sunxi_mc_smp.c \
src/sys/arch/arm/sunxi/sunxi_mc_smp.h
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/arm/sunxi/sunxi_platform.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.57 src/sys/arch/arm/sunxi/files.sunxi:1.58
--- src/sys/arch/arm/sunxi/files.sunxi:1.57	Fri Jun  1 22:11:54 2018
+++ src/sys/arch/arm/sunxi/files.sunxi	Thu Jan  3 11:01:59 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: files.sunxi,v 1.57 2018/06/01 22:11:54 jmcneill Exp $
+#	$NetBSD: files.sunxi,v 1.58 2019/01/03 11:01:59 jmcneill Exp $
 #
 # Configuration info for Allwinner sunxi family SoCs
 #
@@ -6,6 +6,9 @@
 
 file	arch/arm/sunxi/sunxi_platform.c		soc_sunxi
 
+file	arch/arm/sunxi/sunxi_mc_smp.c		soc_sunxi_mc
+file	arch/arm/sunxi/sunxi_mc_mpstart.S	soc_sunxi_mc
+
 # CCU
 define	sunxi_ccu
 file	arch/arm/sunxi/sunxi_ccu.c		sunxi_ccu
@@ -293,8 +296,10 @@ file	arch/arm/sunxi/sunxi_can.c		sunxi_c
 device	sunxilradc
 attach	sunxilradc at fdt with sunxi_lradc
 file	arch/arm/sunxi/sunxi_lradc.c		sunxi_lradc
+
 # SOC parameters
 defflag	opt_soc.h			SOC_SUNXI
+defflag	opt_soc.h			SOC_SUNXI_MC
 defflag	opt_soc.h			SOC_SUN4I: SOC_SUNXI
 defflag	opt_soc.h			SOC_SUN4I_A10: SOC_SUN4I
 defflag	opt_soc.h			SOC_SUN5I: SOC_SUNXI
@@ -304,7 +309,7 @@ defflag	opt_soc.h			SOC_SUN6I_A31: SOC_S
 defflag	opt_soc.h			SOC_SUN7I: SOC_SUNXI
 defflag	opt_soc.h			SOC_SUN7I_A20: SOC_SUN7I
 defflag	opt_soc.h			SOC_SUN8I: SOC_SUNXI
-defflag	opt_soc.h			SOC_SUN8I_A83T: SOC_SUN8I
+defflag	opt_soc.h			SOC_SUN8I_A83T: SOC_SUN8I, SOC_SUNXI_MC
 defflag	opt_soc.h			SOC_SUN8I_H3: SOC_SUN8I
 defflag	opt_soc.h			SOC_SUN9I: SOC_SUNXI
 defflag	opt_soc.h			SOC_SUN9I_A80: SOC_SUN9I

Index: src/sys/arch/arm/sunxi/sunxi_platform.c
diff -u src/sys/arch/arm/sunxi/sunxi_platform.c:1.31 src/sys/arch/arm/sunxi/sunxi_platform.c:1.32
--- src/sys/arch/arm/sunxi/sunxi_platform.c:1.31	Tue Oct 30 16:41:52 2018
+++ src/sys/arch/arm/sunxi/sunxi_platform.c	Thu Jan  3 11:01:59 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_platform.c,v 1.31 2018/10/30 16:41:52 skrll Exp $ */
+/* $NetBSD: sunxi_platform.c,v 1.32 2019/01/03 11:01:59 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -31,7 +31,7 @@
 #include "opt_console.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_platform.c,v 1.31 2018/10/30 16:41:52 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_platform.c,v 1.32 2019/01/03 11:01:59 jmcneill Exp $");
 
 #include 
 #include 
@@ -58,6 +58,10 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_platfo
 
 #include 
 
+#if defined(SOC_SUNXI_MC)
+#include 
+#endif
+
 #include 
 
 #define	SUNXI_REF_FREQ	2400
@@ -123,6 +127,26 @@ sunxi_platform_devmap(void)
 	return devmap;
 }
 
+#define	SUN8I_A83T_CPU_VBASE	(SUNXI_CORE_VBASE + SUNXI_CORE_SIZE)
+#define	SUN8I_A83T_CPU_PBASE	0x0170
+#define	SUN8I_A83T_CPU_SIZE	0x0010
+
+static const struct pmap_devmap *
+sun8i_a83t_platform_devmap(void)
+{
+	static const struct pmap_devmap devmap[] = {
+		DEVMAP_ENTRY(SUNXI_CORE_VBASE,
+			 SUNXI_CORE_PBASE,
+			 SUNXI_CORE_SIZE),
+		DEVMAP_ENTRY(SUN8I_A83T_CPU_VBASE,
+			 SUN8I_A83T_CPU_PBASE,
+			 SUN8I_A83T_CPU_SIZE),
+		DEVMAP_ENTRY_END
+	};
+
+	return devmap;
+}
+
 static void
 sunxi_platform_init_attach_args(struct fdt_attach_args *faa)
 {
@@ -211,6 +235,55 @@ sunxi_platform_bootstrap(void)
 	}
 }
 
+static void
+sunxi_mc_platform_mpstart(void)
+{
+	uint32_t started = 0;
+
+#if defined(MULTIPROCESSOR) && defined(SOC_SUNXI_MC)
+	const char *method;
+	uint64_t mpidr, bp_mpidr;
+	u_int cpuindex;
+	int child;
+
+	const int cpus = OF_finddevice("/cpus");
+	if (cpus == -1)
+		return;
+
+	/* MPIDR affinity levels of boot processor. */
+	bp_mpidr = cpu_mpidr_aff_read();
+
+	cpuindex = 1;
+	for (child = OF_child(cpus); child; child = OF_peer(child)) {
+		if (fdtbus_get_reg64(child, 0, , NULL) != 0)
+			continue;
+		if (mpidr == bp_mpidr)
+			continue;
+
+		method = fdtbus_get_string(child, "enable-method");
+		if (method == NULL)
+			method = fdtbus_get_string(cpus, "enable-method");
+		if (method == NULL)
+			continue;
+
+		if (sunxi_mc_smp_match(method) != 0) {
+			if (sunxi_mc_smp_enable(mpidr) != 0)
+continue;
+
+			started |= __BIT(cpuindex);
+			cpuindex++;
+			for (u_int i = 0x10; i > 0; i--) {
+membar_consumer();
+if (arm_cpu_hatched & __BIT(cpuindex))
+	break;
+			}
+		}
+	}
+#endif
+
+	if (started == 0)
+		

CVS commit: src/sys/arch/arm/sunxi

2019-01-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jan  2 19:33:06 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_ccu_nkmp.c

Log Message:
Support SUNXI_CCU_NKMP_FACTOR_P_X4 flag


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sunxi/sunxi_ccu_nkmp.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/sunxi_ccu_nkmp.c
diff -u src/sys/arch/arm/sunxi/sunxi_ccu_nkmp.c:1.7 src/sys/arch/arm/sunxi/sunxi_ccu_nkmp.c:1.8
--- src/sys/arch/arm/sunxi/sunxi_ccu_nkmp.c:1.7	Fri Oct  6 21:09:21 2017
+++ src/sys/arch/arm/sunxi/sunxi_ccu_nkmp.c	Wed Jan  2 19:33:06 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_ccu_nkmp.c,v 1.7 2017/10/06 21:09:21 jmcneill Exp $ */
+/* $NetBSD: sunxi_ccu_nkmp.c,v 1.8 2019/01/02 19:33:06 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_ccu_nkmp.c,v 1.7 2017/10/06 21:09:21 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_ccu_nkmp.c,v 1.8 2019/01/02 19:33:06 jmcneill Exp $");
 
 #include 
 #include 
@@ -121,6 +121,8 @@ sunxi_ccu_nkmp_get_rate(struct sunxi_ccu
 
 	if ((nkmp->flags & SUNXI_CCU_NKMP_FACTOR_P_POW2) != 0)
 		p = 1 << p;
+	else if ((nkmp->flags & SUNXI_CCU_NKMP_FACTOR_P_X4) != 0)
+		p = p ? 4 : 1;
 	else
 		p++;
 



CVS commit: src/sys/arch/arm/sunxi

2019-01-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jan  2 19:32:41 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_thermal.c

Log Message:
Clocks and resets are not present on all SoCs


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sunxi/sunxi_thermal.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/sunxi_thermal.c
diff -u src/sys/arch/arm/sunxi/sunxi_thermal.c:1.6 src/sys/arch/arm/sunxi/sunxi_thermal.c:1.7
--- src/sys/arch/arm/sunxi/sunxi_thermal.c:1.6	Tue Aug 21 14:09:41 2018
+++ src/sys/arch/arm/sunxi/sunxi_thermal.c	Wed Jan  2 19:32:41 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_thermal.c,v 1.6 2018/08/21 14:09:41 bsiegert Exp $ */
+/* $NetBSD: sunxi_thermal.c,v 1.7 2019/01/02 19:32:41 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016-2017 Jared McNeill 
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_thermal.c,v 1.6 2018/08/21 14:09:41 bsiegert Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_thermal.c,v 1.7 2019/01/02 19:32:41 jmcneill Exp $");
 
 #include 
 #include 
@@ -513,28 +513,28 @@ sunxi_thermal_init_clocks(struct sunxi_t
 	int error;
 
 	clk = fdtbus_clock_get(sc->phandle, "ahb");
-	if (clk == NULL)
-		return ENXIO;
-	error = clk_enable(clk);
-	if (error != 0)
-		return error;
+	if (clk) {
+		error = clk_enable(clk);
+		if (error != 0)
+			return error;
+	}
 
 	clk = fdtbus_clock_get(sc->phandle, "ths");
-	if (clk == NULL)
-		return ENXIO;
-	error = clk_set_rate(clk, sc->conf->clk_rate);
-	if (error != 0)
-		return error;
-	error = clk_enable(clk);
-	if (error != 0)
-		return error;
+	if (clk) {
+		error = clk_set_rate(clk, sc->conf->clk_rate);
+		if (error != 0)
+			return error;
+		error = clk_enable(clk);
+		if (error != 0)
+			return error;
+	}
 
 	rst = fdtbus_reset_get_index(sc->phandle, 0);
-	if (rst == NULL)
-		return ENXIO;
-	error = fdtbus_reset_deassert(rst);
-	if (error != 0)
-		return error;
+	if (rst) {
+		error = fdtbus_reset_deassert(rst);
+		if (error != 0)
+			return error;
+	}
 
 	return 0;
 }



CVS commit: src/sys/arch/arm/sunxi

2019-01-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jan  2 19:32:18 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_sid.c

Log Message:
Support A83T


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/sunxi/sunxi_sid.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/sunxi_sid.c
diff -u src/sys/arch/arm/sunxi/sunxi_sid.c:1.1 src/sys/arch/arm/sunxi/sunxi_sid.c:1.2
--- src/sys/arch/arm/sunxi/sunxi_sid.c:1.1	Tue Oct  3 23:42:17 2017
+++ src/sys/arch/arm/sunxi/sunxi_sid.c	Wed Jan  2 19:32:18 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_sid.c,v 1.1 2017/10/03 23:42:17 jmcneill Exp $ */
+/* $NetBSD: sunxi_sid.c,v 1.2 2019/01/02 19:32:18 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_sid.c,v 1.1 2017/10/03 23:42:17 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_sid.c,v 1.2 2019/01/02 19:32:18 jmcneill Exp $");
 
 #include 
 #include 
@@ -58,6 +58,7 @@ static const struct of_compat_data compa
 	{ "allwinner,sun4i-a10-sid",	(uintptr_t)_a10_sid_config },
 	{ "allwinner,sun7i-a20-sid",	(uintptr_t)_a10_sid_config },
 	{ "allwinner,sun8i-h3-sid",	(uintptr_t)_h3_sid_config },
+	{ "allwinner,sun8i-a83t-sid",	(uintptr_t)_h3_sid_config },
 	{ NULL }
 };
 



CVS commit: src/sys/arch/arm/sunxi

2019-01-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jan  2 18:39:01 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_mmc.c

Log Message:
Only set signal voltage if the regulator can handle it


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/arm/sunxi/sunxi_mmc.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/sunxi_mmc.c
diff -u src/sys/arch/arm/sunxi/sunxi_mmc.c:1.29 src/sys/arch/arm/sunxi/sunxi_mmc.c:1.30
--- src/sys/arch/arm/sunxi/sunxi_mmc.c:1.29	Wed Jan  2 17:28:18 2019
+++ src/sys/arch/arm/sunxi/sunxi_mmc.c	Wed Jan  2 18:39:01 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mmc.c,v 1.29 2019/01/02 17:28:18 jmcneill Exp $ */
+/* $NetBSD: sunxi_mmc.c,v 1.30 2019/01/02 18:39:01 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_sunximmc.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mmc.c,v 1.29 2019/01/02 17:28:18 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mmc.c,v 1.30 2019/01/02 18:39:01 jmcneill Exp $");
 
 #include 
 #include 
@@ -911,6 +911,10 @@ sunxi_mmc_signal_voltage(sdmmc_chipset_h
 		return EINVAL;
 	}
 
+	error = fdtbus_regulator_supports_voltage(sc->sc_reg_vqmmc, uvol, uvol);
+	if (error != 0)
+		return 0;
+
 	error = fdtbus_regulator_set_voltage(sc->sc_reg_vqmmc, uvol, uvol);
 	if (error != 0)
 		return error;



CVS commit: src/sys/arch/arm/sunxi

2019-01-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jan  2 17:29:58 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun8i_a83t_ccu.c sunxi_ccu.h

Log Message:
Add support for cluster 0 and 1 CPUX PLLs.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sunxi/sun8i_a83t_ccu.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/arm/sunxi/sunxi_ccu.h

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/sun8i_a83t_ccu.c
diff -u src/sys/arch/arm/sunxi/sun8i_a83t_ccu.c:1.5 src/sys/arch/arm/sunxi/sun8i_a83t_ccu.c:1.6
--- src/sys/arch/arm/sunxi/sun8i_a83t_ccu.c:1.5	Sat Oct 28 22:59:27 2017
+++ src/sys/arch/arm/sunxi/sun8i_a83t_ccu.c	Wed Jan  2 17:29:58 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun8i_a83t_ccu.c,v 1.5 2017/10/28 22:59:27 jmcneill Exp $ */
+/* $NetBSD: sun8i_a83t_ccu.c,v 1.6 2019/01/02 17:29:58 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -29,7 +29,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_a83t_ccu.c,v 1.5 2017/10/28 22:59:27 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_a83t_ccu.c,v 1.6 2019/01/02 17:29:58 jmcneill Exp $");
 
 #include 
 #include 
@@ -41,7 +41,12 @@ __KERNEL_RCSID(1, "$NetBSD: sun8i_a83t_c
 #include 
 #include 
 
+#define	PLL_C0CPUX_CTRL_REG	0x000
+#define	PLL_C1CPUX_CTRL_REG	0x004
+#define	 PLL_CxCPUX_CTRL_PLL_FACTOR_N	__BITS(15,8)
 #define	PLL_PERIPH_CTRL_REG	0x028
+#define	CPUX_AXI_CFG_REG	0x050
+#define	 Cx_CPUX_CLK_SRC_SEL(cluster)	__BIT(12 + (cluster) * 16)
 #define	AHB1_APB1_CFG_REG	0x054
 #define	APB2_CFG_REG		0x058
 #define	BUS_CLK_GATING_REG0	0x060
@@ -54,6 +59,7 @@ __KERNEL_RCSID(1, "$NetBSD: sun8i_a83t_c
 #define	 SDMMC2_CLK_MODE_SELECT	__BIT(30)
 #define	USBPHY_CFG_REG		0x0cc
 #define	MBUS_RST_REG		0x0fc
+#define	PLL_STABLE_STATUS_REG	0x20c
 #define	BUS_SOFT_RST_REG0	0x2c0
 #define	BUS_SOFT_RST_REG1	0x2c4
 #define	BUS_SOFT_RST_REG2	0x2c8
@@ -123,7 +129,91 @@ static const char *apb1_parents[] = { "a
 static const char *apb2_parents[] = { "losc", "hosc", "pll_periph" };
 static const char *mod_parents[] = { "hosc", "pll_periph" };
 
+static kmutex_t cpux_axi_cfg_lock;
+
+static int
+sun8i_a83t_ccu_cpux_set_rate(struct sunxi_ccu_softc *sc,
+struct sunxi_ccu_clk *clk, u_int rate)
+{
+	const int cluster = clk->u.nkmp.reg == PLL_C0CPUX_CTRL_REG ? 0 : 1;
+	struct sunxi_ccu_nkmp *nkmp = >u.nkmp;
+	uint32_t val;
+	u_int n;
+
+	n = rate / 2400;
+	if (n < 0x11 || n > 0xff)
+		return EINVAL;
+
+	/* Switch cluster to OSC24M clock */
+	mutex_enter(_axi_cfg_lock);
+	val = CCU_READ(sc, CPUX_AXI_CFG_REG);
+	val &= ~Cx_CPUX_CLK_SRC_SEL(cluster);
+	CCU_WRITE(sc, CPUX_AXI_CFG_REG, val);
+	mutex_exit(_axi_cfg_lock);
+
+	/* Set new PLL rate */
+	val = CCU_READ(sc, nkmp->reg);
+	val &= ~PLL_CxCPUX_CTRL_PLL_FACTOR_N;
+	val |= __SHIFTIN(n, PLL_CxCPUX_CTRL_PLL_FACTOR_N);
+	CCU_WRITE(sc, nkmp->reg, val);
+
+	/* Wait for PLL lock */
+	while ((CCU_READ(sc, PLL_STABLE_STATUS_REG) & nkmp->lock) == 0)
+		;
+
+	/* Switch cluster back to CPUX PLL */
+	mutex_enter(_axi_cfg_lock);
+	val = CCU_READ(sc, CPUX_AXI_CFG_REG);
+	val |= Cx_CPUX_CLK_SRC_SEL(cluster);
+	CCU_WRITE(sc, CPUX_AXI_CFG_REG, val);
+	mutex_exit(_axi_cfg_lock);
+
+	return 0;
+}
+
 static struct sunxi_ccu_clk sun8i_a83t_ccu_clks[] = {
+	[A83T_CLK_C0CPUX] = {
+		.type = SUNXI_CCU_NKMP,
+		.base.name = "pll_c0cpux",
+		.u.nkmp.reg = PLL_C0CPUX_CTRL_REG,
+		.u.nkmp.parent = "hosc",
+		.u.nkmp.n = __BITS(15,8),
+		.u.nkmp.k = 0,
+		.u.nkmp.m = __BITS(1,0),
+		.u.nkmp.p = __BIT(16),
+		.u.nkmp.enable = __BIT(31),
+		.u.nkmp.flags = SUNXI_CCU_NKMP_SCALE_CLOCK |
+SUNXI_CCU_NKMP_FACTOR_N_EXACT |
+SUNXI_CCU_NKMP_FACTOR_P_X4,
+		.u.nkmp.lock = __BIT(0),	/* PLL_STABLE_STATUS_REG */
+		.u.nkmp.table = NULL,
+		.enable = sunxi_ccu_nkmp_enable,
+		.get_rate = sunxi_ccu_nkmp_get_rate,
+		.set_rate = sun8i_a83t_ccu_cpux_set_rate,
+		.get_parent = sunxi_ccu_nkmp_get_parent,
+	},
+
+	[A83T_CLK_C1CPUX] = {
+		.type = SUNXI_CCU_NKMP,
+		.base.name = "pll_c1cpux",
+		.u.nkmp.reg = PLL_C1CPUX_CTRL_REG,
+		.u.nkmp.parent = "hosc",
+		.u.nkmp.n = __BITS(15,8),
+		.u.nkmp.k = 0,
+		.u.nkmp.m = __BITS(1,0),
+		.u.nkmp.p = __BIT(16),
+		.u.nkmp.enable = __BIT(31),
+		.u.nkmp.flags = SUNXI_CCU_NKMP_SCALE_CLOCK |
+SUNXI_CCU_NKMP_FACTOR_N_EXACT |
+SUNXI_CCU_NKMP_FACTOR_P_X4,
+		.u.nkmp.lock = __BIT(1),	/* PLL_STABLE_STATUS_REG */
+		.u.nkmp.table = NULL,
+		.enable = sunxi_ccu_nkmp_enable,
+		.get_rate = sunxi_ccu_nkmp_get_rate,
+		.set_rate = sun8i_a83t_ccu_cpux_set_rate,
+		.get_parent = sunxi_ccu_nkmp_get_parent,
+	},
+
 	SUNXI_CCU_NKMP(A83T_CLK_PLL_PERIPH, "pll_periph", "hosc",
 	PLL_PERIPH_CTRL_REG,	/* reg */
 	__BITS(15,8),		/* n */
@@ -298,6 +388,8 @@ sun8i_a83t_ccu_attach(device_t parent, d
 	sc->sc_clks = sun8i_a83t_ccu_clks;
 	sc->sc_nclks = __arraycount(sun8i_a83t_ccu_clks);
 
+	mutex_init(_axi_cfg_lock, MUTEX_DEFAULT, IPL_HIGH);
+
 	if 

CVS commit: src/sys/arch/arm/sunxi

2019-01-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jan  2 17:28:18 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_mmc.c

Log Message:
Try to acquire vmmc-supply if present


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/arm/sunxi/sunxi_mmc.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/sunxi_mmc.c
diff -u src/sys/arch/arm/sunxi/sunxi_mmc.c:1.28 src/sys/arch/arm/sunxi/sunxi_mmc.c:1.29
--- src/sys/arch/arm/sunxi/sunxi_mmc.c:1.28	Fri Nov  9 14:39:51 2018
+++ src/sys/arch/arm/sunxi/sunxi_mmc.c	Wed Jan  2 17:28:18 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mmc.c,v 1.28 2018/11/09 14:39:51 jmcneill Exp $ */
+/* $NetBSD: sunxi_mmc.c,v 1.29 2019/01/02 17:28:18 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_sunximmc.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mmc.c,v 1.28 2018/11/09 14:39:51 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mmc.c,v 1.29 2019/01/02 17:28:18 jmcneill Exp $");
 
 #include 
 #include 
@@ -190,6 +190,7 @@ struct sunxi_mmc_softc {
 	struct fdtbus_gpio_pin *sc_gpio_wp;
 	int sc_gpio_wp_inverted;
 
+	struct fdtbus_regulator *sc_reg_vmmc;
 	struct fdtbus_regulator *sc_reg_vqmmc;
 
 	struct fdtbus_mmc_pwrseq *sc_pwrseq;
@@ -328,8 +329,6 @@ sunxi_mmc_attach(device_t parent, device
 
 	sc->sc_rst_ahb = fdtbus_reset_get(phandle, "ahb");
 
-	sc->sc_reg_vqmmc = fdtbus_regulator_acquire(phandle, "vqmmc-supply");
-
 	sc->sc_pwrseq = fdtbus_mmc_pwrseq_get(phandle);
 
 	if (clk_enable(sc->sc_clk_ahb) != 0 ||
@@ -362,6 +361,9 @@ sunxi_mmc_attach(device_t parent, device
 	aprint_naive("\n");
 	aprint_normal(": SD/MMC controller\n");
 
+	sc->sc_reg_vmmc = fdtbus_regulator_acquire(phandle, "vmmc-supply");
+	sc->sc_reg_vqmmc = fdtbus_regulator_acquire(phandle, "vqmmc-supply");
+
 	sc->sc_gpio_cd = fdtbus_gpio_acquire(phandle, "cd-gpios",
 	GPIO_PIN_INPUT);
 	sc->sc_gpio_wp = fdtbus_gpio_acquire(phandle, "wp-gpios",



CVS commit: src/sys/arch/arm/sunxi

2018-12-31 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Dec 31 19:07:21 UTC 2018

Modified Files:
src/sys/arch/arm/sunxi: sun8i_a83t_gpio.c

Log Message:
"emac" function is now "gmac" in the dts


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sunxi/sun8i_a83t_gpio.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/sun8i_a83t_gpio.c
diff -u src/sys/arch/arm/sunxi/sun8i_a83t_gpio.c:1.3 src/sys/arch/arm/sunxi/sun8i_a83t_gpio.c:1.4
--- src/sys/arch/arm/sunxi/sun8i_a83t_gpio.c:1.3	Fri May 25 19:56:47 2018
+++ src/sys/arch/arm/sunxi/sun8i_a83t_gpio.c	Mon Dec 31 19:07:21 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sun8i_a83t_gpio.c,v 1.3 2018/05/25 19:56:47 jmcneill Exp $ */
+/* $NetBSD: sun8i_a83t_gpio.c,v 1.4 2018/12/31 19:07:21 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016-2017 Jared McNeill 
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sun8i_a83t_gpio.c,v 1.3 2018/05/25 19:56:47 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun8i_a83t_gpio.c,v 1.4 2018/12/31 19:07:21 jmcneill Exp $");
 
 #include 
 #include 
@@ -71,24 +71,24 @@ static const struct sunxi_gpio_pins a83t
 	{ "PC17", 2, 17,  { "gpio_in", "gpio_out", "nand" } },
 	{ "PC18", 2, 18,  { "gpio_in", "gpio_out", "nand" } },
 
-	{ "PD2",  3, 2,   { "gpio_in", "gpio_out", "lcd", NULL, "emac" } },
-	{ "PD3",  3, 3,   { "gpio_in", "gpio_out", "lcd", NULL, "emac" } },
-	{ "PD4",  3, 4,   { "gpio_in", "gpio_out", "lcd", NULL, "emac" } },
-	{ "PD5",  3, 5,   { "gpio_in", "gpio_out", "lcd", NULL, "emac" } },
-	{ "PD6",  3, 6,   { "gpio_in", "gpio_out", "lcd", NULL, "emac" } },
-	{ "PD7",  3, 7,   { "gpio_in", "gpio_out", "lcd", NULL, "emac" } },
-	{ "PD10", 3, 10,  { "gpio_in", "gpio_out", "lcd", NULL, "emac" } },
-	{ "PD11", 3, 11,  { "gpio_in", "gpio_out", "lcd", NULL, "emac" } },
-	{ "PD12", 3, 12,  { "gpio_in", "gpio_out", "lcd", NULL, "emac" } },
-	{ "PD13", 3, 13,  { "gpio_in", "gpio_out", "lcd", NULL, "emac" } },
-	{ "PD14", 3, 14,  { "gpio_in", "gpio_out", "lcd", NULL, "emac" } },
-	{ "PD15", 3, 15,  { "gpio_in", "gpio_out", "lcd", NULL, "emac" } },
-	{ "PD18", 3, 18,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac" } },
-	{ "PD19", 3, 19,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac" } },
-	{ "PD20", 3, 20,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac" } },
-	{ "PD21", 3, 21,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac" } },
-	{ "PD22", 3, 22,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac" } },
-	{ "PD23", 3, 23,  { "gpio_in", "gpio_out", "lcd", "lvds", "emac" } },
+	{ "PD2",  3, 2,   { "gpio_in", "gpio_out", "lcd", NULL, "gmac" } },
+	{ "PD3",  3, 3,   { "gpio_in", "gpio_out", "lcd", NULL, "gmac" } },
+	{ "PD4",  3, 4,   { "gpio_in", "gpio_out", "lcd", NULL, "gmac" } },
+	{ "PD5",  3, 5,   { "gpio_in", "gpio_out", "lcd", NULL, "gmac" } },
+	{ "PD6",  3, 6,   { "gpio_in", "gpio_out", "lcd", NULL, "gmac" } },
+	{ "PD7",  3, 7,   { "gpio_in", "gpio_out", "lcd", NULL, "gmac" } },
+	{ "PD10", 3, 10,  { "gpio_in", "gpio_out", "lcd", NULL, "gmac" } },
+	{ "PD11", 3, 11,  { "gpio_in", "gpio_out", "lcd", NULL, "gmac" } },
+	{ "PD12", 3, 12,  { "gpio_in", "gpio_out", "lcd", NULL, "gmac" } },
+	{ "PD13", 3, 13,  { "gpio_in", "gpio_out", "lcd", NULL, "gmac" } },
+	{ "PD14", 3, 14,  { "gpio_in", "gpio_out", "lcd", NULL, "gmac" } },
+	{ "PD15", 3, 15,  { "gpio_in", "gpio_out", "lcd", NULL, "gmac" } },
+	{ "PD18", 3, 18,  { "gpio_in", "gpio_out", "lcd", "lvds", "gmac" } },
+	{ "PD19", 3, 19,  { "gpio_in", "gpio_out", "lcd", "lvds", "gmac" } },
+	{ "PD20", 3, 20,  { "gpio_in", "gpio_out", "lcd", "lvds", "gmac" } },
+	{ "PD21", 3, 21,  { "gpio_in", "gpio_out", "lcd", "lvds", "gmac" } },
+	{ "PD22", 3, 22,  { "gpio_in", "gpio_out", "lcd", "lvds", "gmac" } },
+	{ "PD23", 3, 23,  { "gpio_in", "gpio_out", "lcd", "lvds", "gmac" } },
 	{ "PD24", 3, 24,  { "gpio_in", "gpio_out", "lcd", "lvds" } },
 	{ "PD25", 3, 25,  { "gpio_in", "gpio_out", "lcd", "lvds" } },
 	{ "PD26", 3, 26,  { "gpio_in", "gpio_out", "lcd", "lvds" } },



CVS commit: src/sys/arch/arm/sunxi

2018-11-29 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Thu Nov 29 20:33:09 UTC 2018

Modified Files:
src/sys/arch/arm/sunxi: sunxi_ccu.c

Log Message:
use %u for u_int, rather than %d; corrects printing of frequencies at or above 
2**31 Hz


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/sunxi/sunxi_ccu.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/sunxi_ccu.c
diff -u src/sys/arch/arm/sunxi/sunxi_ccu.c:1.12 src/sys/arch/arm/sunxi/sunxi_ccu.c:1.13
--- src/sys/arch/arm/sunxi/sunxi_ccu.c:1.12	Fri Sep 21 12:04:07 2018
+++ src/sys/arch/arm/sunxi/sunxi_ccu.c	Thu Nov 29 20:33:09 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_ccu.c,v 1.12 2018/09/21 12:04:07 skrll Exp $ */
+/* $NetBSD: sunxi_ccu.c,v 1.13 2018/11/29 20:33:09 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -31,7 +31,7 @@
 #include "opt_console.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_ccu.c,v 1.12 2018/09/21 12:04:07 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_ccu.c,v 1.13 2018/11/29 20:33:09 jakllsch Exp $");
 
 #include 
 #include 
@@ -369,6 +369,6 @@ sunxi_ccu_print(struct sunxi_ccu_softc *
 	clkp_parent ? "<-" : "",
 	clkp_parent ? clkp_parent->name : "",
 	type);
-		aprint_debug("%10d Hz\n", clk_get_rate(>base));
+		aprint_debug("%10u Hz\n", clk_get_rate(>base));
 	}
 }



CVS commit: src/sys/arch/arm/sunxi

2018-11-17 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Nov 17 20:36:23 UTC 2018

Modified Files:
src/sys/arch/arm/sunxi: sunxi_i2s.c

Log Message:
TX/RX FIFO are looking for 32-bit samples, so add play/rec filters.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sunxi_i2s.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/sunxi_i2s.c
diff -u src/sys/arch/arm/sunxi/sunxi_i2s.c:1.2 src/sys/arch/arm/sunxi/sunxi_i2s.c:1.3
--- src/sys/arch/arm/sunxi/sunxi_i2s.c:1.2	Wed May 16 10:15:20 2018
+++ src/sys/arch/arm/sunxi/sunxi_i2s.c	Sat Nov 17 20:36:23 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_i2s.c,v 1.2 2018/05/16 10:15:20 jmcneill Exp $ */
+/* $NetBSD: sunxi_i2s.c,v 1.3 2018/11/17 20:36:23 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_i2s.c,v 1.2 2018/05/16 10:15:20 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_i2s.c,v 1.3 2018/11/17 20:36:23 jmcneill Exp $");
 
 #include 
 #include 
@@ -71,6 +71,8 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_i2s.c,
 #define	 DA_FCTL_HUB_EN	__BIT(31)
 #define	 DA_FCTL_FTX	__BIT(25)
 #define	 DA_FCTL_FRX	__BIT(24)
+#define	 DA_FCTL_TXIM	__BIT(2)
+#define	 DA_FCTL_RXIM	__BITS(1,0)
 #define	DA_FSTA		0x18
 #define	DA_INT		0x1c
 #define	 DA_INT_TX_DRQ	__BIT(7)
@@ -79,6 +81,7 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_i2s.c,
 #define	DA_CLKD		0x24
 #define	 DA_CLKD_MCLKO_EN __BIT(7)
 #define	 DA_CLKD_BCLKDIV __BITS(6,4)
+#define	  DA_CLKD_BCLKDIV_8	3
 #define	  DA_CLKD_BCLKDIV_16	5
 #define	 DA_CLKD_MCLKDIV __BITS(3,0)
 #define	  DA_CLKD_MCLKDIV_1	0
@@ -264,6 +267,8 @@ sunxi_i2s_set_params(void *priv, int set
 			return EINVAL;
 		sc->sc_pchan.ch_params = pfil->req_size > 0 ?
 		pfil->filters[0].param : *play;
+		pfil->prepend(pfil, linear16_16_to_linear32,
+		>sc_pchan.ch_params);
 	}
 	if (rec && (setmode & AUMODE_RECORD)) {
 		index = auconv_set_converter(>sc_format, 1,
@@ -272,6 +277,8 @@ sunxi_i2s_set_params(void *priv, int set
 			return EINVAL;
 		sc->sc_rchan.ch_params = rfil->req_size > 0 ?
 		rfil->filters[0].param : *rec;
+		rfil->prepend(rfil, linear32_32_to_linear16,
+		>sc_rchan.ch_params);
 	}
 
 	return 0;
@@ -600,7 +607,7 @@ sunxi_i2s_dai_set_sysclk(audio_dai_tag_t
 	/* XXX */
 
 	val = DA_CLKD_MCLKO_EN;
-	val |= __SHIFTIN(DA_CLKD_BCLKDIV_16, DA_CLKD_BCLKDIV);
+	val |= __SHIFTIN(DA_CLKD_BCLKDIV_8, DA_CLKD_BCLKDIV);
 	val |= __SHIFTIN(DA_CLKD_MCLKDIV_1, DA_CLKD_MCLKDIV);
 
 	I2S_WRITE(sc, DA_CLKD, val);



CVS commit: src/sys/arch/arm/sunxi

2018-11-17 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Nov 17 20:35:41 UTC 2018

Modified Files:
src/sys/arch/arm/sunxi: sun6i_dma.c

Log Message:
Handle different burst bits for h3/a64


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sunxi/sun6i_dma.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/sun6i_dma.c
diff -u src/sys/arch/arm/sunxi/sun6i_dma.c:1.5 src/sys/arch/arm/sunxi/sun6i_dma.c:1.6
--- src/sys/arch/arm/sunxi/sun6i_dma.c:1.5	Thu May 10 00:07:08 2018
+++ src/sys/arch/arm/sunxi/sun6i_dma.c	Sat Nov 17 20:35:41 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sun6i_dma.c,v 1.5 2018/05/10 00:07:08 jmcneill Exp $ */
+/* $NetBSD: sun6i_dma.c,v 1.6 2018/11/17 20:35:41 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sun6i_dma.c,v 1.5 2018/05/10 00:07:08 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun6i_dma.c,v 1.6 2018/11/17 20:35:41 jmcneill Exp $");
 
 #include 
 #include 
@@ -64,7 +64,6 @@ __KERNEL_RCSID(0, "$NetBSD: sun6i_dma.c,
 #define DMA_CFG_REG(n)			(0x0100 + (n) * 0x40 + 0x0C)
 #define  DMA_CFG_DEST_DATA_WIDTH		__BITS(26,25)
 #define   DMA_CFG_DATA_WIDTH(n)			((n) >> 4)
-#define  DMA_CFG_DEST_BST_LEN			__BITS(24,23)
 #define	  DMA_CFG_BST_LEN(n)			((n) == 1 ? 0 : (((n) >> 3) + 1))
 #define  DMA_CFG_DEST_ADDR_MODE			__BITS(22,21)
 #define   DMA_CFG_ADDR_MODE_LINEAR		0
@@ -72,7 +71,6 @@ __KERNEL_RCSID(0, "$NetBSD: sun6i_dma.c,
 #define  DMA_CFG_DEST_DRQ_TYPE			__BITS(20,16)
 #define	  DMA_CFG_DRQ_TYPE_SDRAM		1
 #define  DMA_CFG_SRC_DATA_WIDTH			__BITS(10,9)
-#define  DMA_CFG_SRC_BST_LEN			__BITS(8,7)
 #define  DMA_CFG_SRC_ADDR_MODE			__BITS(6,5)
 #define  DMA_CFG_SRC_DRQ_TYPE			__BITS(4,0)
 #define DMA_CUR_SRC_REG(n)		(0x0100 + (n) * 0x40 + 0x10)
@@ -97,10 +95,12 @@ struct sun6idma_config {
 	bool		autogate;
 	bus_size_t	autogate_reg;
 	uint32_t	autogate_mask;
+	uint32_t	burst_mask;
 };
 
 static const struct sun6idma_config sun6i_a31_dma_config = {
-	.num_channels = 16
+	.num_channels = 16,
+	.burst_mask = __BITS(8,7),
 };
 
 static const struct sun6idma_config sun8i_a83t_dma_config = {
@@ -108,6 +108,7 @@ static const struct sun6idma_config sun8
 	.autogate = true,
 	.autogate_reg = 0x20,
 	.autogate_mask = 0x4,
+	.burst_mask = __BITS(8,7),
 };
 
 static const struct sun6idma_config sun8i_h3_dma_config = {
@@ -115,6 +116,7 @@ static const struct sun6idma_config sun8
 	.autogate = true,
 	.autogate_reg = 0x28,
 	.autogate_mask = 0x4,
+	.burst_mask = __BITS(7,6),
 };
 
 static const struct sun6idma_config sun50i_a64_dma_config = {
@@ -122,6 +124,7 @@ static const struct sun6idma_config sun5
 	.autogate = true,
 	.autogate_reg = 0x28,
 	.autogate_mask = 0x4,
+	.burst_mask = __BITS(7,6),
 };
 
 static const struct of_compat_data compat_data[] = {
@@ -152,6 +155,8 @@ struct sun6idma_softc {
 	int			sc_phandle;
 	void			*sc_ih;
 
+	uint32_t		sc_burst_mask;
+
 	kmutex_t		sc_lock;
 
 	struct sun6idma_channel	*sc_chan;
@@ -251,11 +256,11 @@ sun6idma_transfer(device_t dev, void *pr
 	dev_burst = DMA_CFG_BST_LEN(req->dreq_dev_opt.opt_burst_len);
 
 	mem_cfg = __SHIFTIN(mem_width, DMA_CFG_SRC_DATA_WIDTH) |
-	__SHIFTIN(mem_burst, DMA_CFG_SRC_BST_LEN) |
+	__SHIFTIN(mem_burst, sc->sc_burst_mask) |
 	__SHIFTIN(DMA_CFG_ADDR_MODE_LINEAR, DMA_CFG_SRC_ADDR_MODE) |
 	__SHIFTIN(DMA_CFG_DRQ_TYPE_SDRAM, DMA_CFG_SRC_DRQ_TYPE);
 	dev_cfg = __SHIFTIN(dev_width, DMA_CFG_SRC_DATA_WIDTH) |
-	__SHIFTIN(dev_burst, DMA_CFG_SRC_BST_LEN) |
+	__SHIFTIN(dev_burst, sc->sc_burst_mask) |
 	__SHIFTIN(DMA_CFG_ADDR_MODE_IO, DMA_CFG_SRC_ADDR_MODE) |
 	__SHIFTIN(ch->ch_portid, DMA_CFG_SRC_DRQ_TYPE);
 
@@ -398,6 +403,7 @@ sun6idma_attach(device_t parent, device_
 
 	conf = (void *)of_search_compatible(phandle, compat_data)->data;
 
+	sc->sc_burst_mask = conf->burst_mask;
 	sc->sc_nchan = conf->num_channels;
 	sc->sc_chan = kmem_alloc(sizeof(*sc->sc_chan) * sc->sc_nchan, KM_SLEEP);
 



CVS commit: src/sys/arch/arm/sunxi

2018-11-17 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Nov 17 19:30:51 UTC 2018

Modified Files:
src/sys/arch/arm/sunxi: sunxi_rsb.c

Log Message:
Serialize RSB requests.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sunxi/sunxi_rsb.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/sunxi_rsb.c
diff -u src/sys/arch/arm/sunxi/sunxi_rsb.c:1.5 src/sys/arch/arm/sunxi/sunxi_rsb.c:1.6
--- src/sys/arch/arm/sunxi/sunxi_rsb.c:1.5	Mon Jul 16 23:11:47 2018
+++ src/sys/arch/arm/sunxi/sunxi_rsb.c	Sat Nov 17 19:30:51 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_rsb.c,v 1.5 2018/07/16 23:11:47 christos Exp $ */
+/* $NetBSD: sunxi_rsb.c,v 1.6 2018/11/17 19:30:51 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_rsb.c,v 1.5 2018/07/16 23:11:47 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_rsb.c,v 1.6 2018/11/17 19:30:51 jmcneill Exp $");
 
 #include 
 #include 
@@ -90,6 +90,7 @@ struct sunxi_rsb_softc {
 	device_t sc_i2cdev;
 	void *sc_ih;
 	uint32_t sc_stat;
+	bool sc_busy;
 
 	uint16_t sc_rsb_last_da;
 };
@@ -326,7 +327,13 @@ sunxi_rsb_acquire_bus(void *priv, int fl
 {
 	struct sunxi_rsb_softc *sc = priv;
 
-	mutex_enter(>sc_lock);
+	for (;;) {
+		mutex_enter(>sc_lock);
+		if (sc->sc_busy == false)
+			break;
+		mutex_exit(>sc_lock);
+	}
+	sc->sc_busy = true;
 
 	return 0;
 }
@@ -336,6 +343,7 @@ sunxi_rsb_release_bus(void *priv, int fl
 {
 	struct sunxi_rsb_softc *sc = priv;
 
+	sc->sc_busy = false;
 	mutex_exit(>sc_lock);
 }
 
@@ -349,6 +357,7 @@ sunxi_rsb_exec(void *priv, i2c_op_t op, 
 	int error, i;
 
 	KASSERT(mutex_owned(>sc_lock));
+	KASSERT(sc->sc_busy == true);
 
 	if (cmdlen != 1 || (len != 1 && len != 2 && len != 4))
 		return EINVAL;



CVS commit: src/sys/arch/arm/sunxi

2018-11-09 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Nov  9 14:39:51 UTC 2018

Modified Files:
src/sys/arch/arm/sunxi: sunxi_mmc.c

Log Message:
Enable new timings and HS200 mode on A64 eMMC


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/arm/sunxi/sunxi_mmc.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/sunxi_mmc.c
diff -u src/sys/arch/arm/sunxi/sunxi_mmc.c:1.27 src/sys/arch/arm/sunxi/sunxi_mmc.c:1.28
--- src/sys/arch/arm/sunxi/sunxi_mmc.c:1.27	Mon Sep  3 16:29:24 2018
+++ src/sys/arch/arm/sunxi/sunxi_mmc.c	Fri Nov  9 14:39:51 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mmc.c,v 1.27 2018/09/03 16:29:24 riastradh Exp $ */
+/* $NetBSD: sunxi_mmc.c,v 1.28 2018/11/09 14:39:51 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_sunximmc.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mmc.c,v 1.27 2018/09/03 16:29:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mmc.c,v 1.28 2018/11/09 14:39:51 jmcneill Exp $");
 
 #include 
 #include 
@@ -254,7 +254,9 @@ static const struct sunxi_mmc_config sun
 	.idma_xferlen = 0x2000,
 	.dma_ftrglevel = 0x20070008,
 	.delays = NULL,
-	.flags = SUNXI_MMC_FLAG_CALIB_REG,
+	.flags = SUNXI_MMC_FLAG_CALIB_REG |
+		 SUNXI_MMC_FLAG_NEW_TIMINGS |
+		 SUNXI_MMC_FLAG_HS200,
 };
 
 static const struct sunxi_mmc_config sun50i_h6_mmc_config = {



CVS commit: src/sys/arch/arm/sunxi

2018-10-28 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Oct 28 13:56:21 UTC 2018

Modified Files:
src/sys/arch/arm/sunxi: sunxi_platform.c

Log Message:
Restore pre-generic arm commit bootstrap behaviour.

Always call arm_fdt_cpu_bootstrap, i.e. don't depend on "/chosen" existing
in the FDT


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/arm/sunxi/sunxi_platform.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/sunxi_platform.c
diff -u src/sys/arch/arm/sunxi/sunxi_platform.c:1.29 src/sys/arch/arm/sunxi/sunxi_platform.c:1.30
--- src/sys/arch/arm/sunxi/sunxi_platform.c:1.29	Thu Oct 18 09:01:53 2018
+++ src/sys/arch/arm/sunxi/sunxi_platform.c	Sun Oct 28 13:56:21 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_platform.c,v 1.29 2018/10/18 09:01:53 skrll Exp $ */
+/* $NetBSD: sunxi_platform.c,v 1.30 2018/10/28 13:56:21 skrll Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -31,7 +31,7 @@
 #include "opt_console.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_platform.c,v 1.29 2018/10/18 09:01:53 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_platform.c,v 1.30 2018/10/28 13:56:21 skrll Exp $");
 
 #include 
 #include 
@@ -187,6 +187,8 @@ sunxi_platform_uart_freq(void)
 static void
 sunxi_platform_bootstrap(void)
 {
+	arm_fdt_cpu_bootstrap();
+
 	void *fdt_data = __UNCONST(fdtbus_get_data());
 	const int chosen_off = fdt_path_offset(fdt_data, "/chosen");
 	if (chosen_off < 0)
@@ -207,8 +209,6 @@ sunxi_platform_bootstrap(void)
 		fdt_setprop_string(fdt_data, chosen_off,
 		"stdout-path", "serial0:115200n8");
 	}
-
-	arm_fdt_cpu_bootstrap();
 }
 
 



CVS commit: src/sys/arch/arm/sunxi

2018-10-18 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Oct 18 13:33:10 UTC 2018

Modified Files:
src/sys/arch/arm/sunxi: sunxi_emac.c

Log Message:
Make it compile with debugging enabled


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/arm/sunxi/sunxi_emac.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/sunxi_emac.c
diff -u src/sys/arch/arm/sunxi/sunxi_emac.c:1.19 src/sys/arch/arm/sunxi/sunxi_emac.c:1.20
--- src/sys/arch/arm/sunxi/sunxi_emac.c:1.19	Thu Oct 18 12:58:19 2018
+++ src/sys/arch/arm/sunxi/sunxi_emac.c	Thu Oct 18 13:33:10 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_emac.c,v 1.19 2018/10/18 12:58:19 jmcneill Exp $ */
+/* $NetBSD: sunxi_emac.c,v 1.20 2018/10/18 13:33:10 martin Exp $ */
 
 /*-
  * Copyright (c) 2016-2017 Jared McNeill 
@@ -33,7 +33,7 @@
 #include "opt_net_mpsafe.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.19 2018/10/18 12:58:19 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.20 2018/10/18 13:33:10 martin Exp $");
 
 #include 
 #include 
@@ -583,6 +583,47 @@ sunxi_emac_disable_intr(struct sunxi_ema
 	WR4(sc, EMAC_INT_EN, 0);
 }
 
+#ifdef SUNXI_EMAC_DEBUG
+static void
+sunxi_emac_dump_regs(struct sunxi_emac_softc *sc)
+{
+	static const struct {
+		const char *name;
+		u_int reg;
+	} regs[] = {
+		{ "BASIC_CTL_0", EMAC_BASIC_CTL_0 },
+		{ "BASIC_CTL_1", EMAC_BASIC_CTL_1 },
+		{ "INT_STA", EMAC_INT_STA },
+		{ "INT_EN", EMAC_INT_EN },
+		{ "TX_CTL_0", EMAC_TX_CTL_0 },
+		{ "TX_CTL_1", EMAC_TX_CTL_1 },
+		{ "TX_FLOW_CTL", EMAC_TX_FLOW_CTL },
+		{ "TX_DMA_LIST", EMAC_TX_DMA_LIST },
+		{ "RX_CTL_0", EMAC_RX_CTL_0 },
+		{ "RX_CTL_1", EMAC_RX_CTL_1 },
+		{ "RX_DMA_LIST", EMAC_RX_DMA_LIST },
+		{ "RX_FRM_FLT", EMAC_RX_FRM_FLT },
+		{ "RX_HASH_0", EMAC_RX_HASH_0 },
+		{ "RX_HASH_1", EMAC_RX_HASH_1 },
+		{ "MII_CMD", EMAC_MII_CMD },
+		{ "ADDR_HIGH0", EMAC_ADDR_HIGH(0) },
+		{ "ADDR_LOW0", EMAC_ADDR_LOW(0) },
+		{ "TX_DMA_STA", EMAC_TX_DMA_STA },
+		{ "TX_DMA_CUR_DESC", EMAC_TX_DMA_CUR_DESC },
+		{ "TX_DMA_CUR_BUF", EMAC_TX_DMA_CUR_BUF },
+		{ "RX_DMA_STA", EMAC_RX_DMA_STA },
+		{ "RX_DMA_CUR_DESC", EMAC_RX_DMA_CUR_DESC },
+		{ "RX_DMA_CUR_BUF", EMAC_RX_DMA_CUR_BUF },
+		{ "RGMII_STA", EMAC_RGMII_STA },
+	};
+	u_int n;
+
+	for (n = 0; n < __arraycount(regs); n++)
+		device_printf(sc->dev, "  %-20s %08x\n", regs[n].name,
+		RD4(sc, regs[n].reg));
+}
+#endif
+
 static int
 sunxi_emac_reset(struct sunxi_emac_softc *sc)
 {
@@ -1119,47 +1160,6 @@ sunxi_emac_get_eaddr(struct sunxi_emac_s
 	eaddr[5] = (machi >> 8) & 0xff;
 }
 
-#ifdef SUNXI_EMAC_DEBUG
-static void
-sunxi_emac_dump_regs(struct sunxi_emac_softc *sc)
-{
-	static const struct {
-		const char *name;
-		u_int reg;
-	} regs[] = {
-		{ "BASIC_CTL_0", EMAC_BASIC_CTL_0 },
-		{ "BASIC_CTL_1", EMAC_BASIC_CTL_1 },
-		{ "INT_STA", EMAC_INT_STA },
-		{ "INT_EN", EMAC_INT_EN },
-		{ "TX_CTL_0", EMAC_TX_CTL_0 },
-		{ "TX_CTL_1", EMAC_TX_CTL_1 },
-		{ "TX_FLOW_CTL", EMAC_TX_FLOW_CTL },
-		{ "TX_DMA_LIST", EMAC_TX_DMA_LIST },
-		{ "RX_CTL_0", EMAC_RX_CTL_0 },
-		{ "RX_CTL_1", EMAC_RX_CTL_1 },
-		{ "RX_DMA_LIST", EMAC_RX_DMA_LIST },
-		{ "RX_FRM_FLT", EMAC_RX_FRM_FLT },
-		{ "RX_HASH_0", EMAC_RX_HASH_0 },
-		{ "RX_HASH_1", EMAC_RX_HASH_1 },
-		{ "MII_CMD", EMAC_MII_CMD },
-		{ "ADDR_HIGH0", EMAC_ADDR_HIGH(0) },
-		{ "ADDR_LOW0", EMAC_ADDR_LOW(0) },
-		{ "TX_DMA_STA", EMAC_TX_DMA_STA },
-		{ "TX_DMA_CUR_DESC", EMAC_TX_DMA_CUR_DESC },
-		{ "TX_DMA_CUR_BUF", EMAC_TX_DMA_CUR_BUF },
-		{ "RX_DMA_STA", EMAC_RX_DMA_STA },
-		{ "RX_DMA_CUR_DESC", EMAC_RX_DMA_CUR_DESC },
-		{ "RX_DMA_CUR_BUF", EMAC_RX_DMA_CUR_BUF },
-		{ "RGMII_STA", EMAC_RGMII_STA },
-	};
-	u_int n;
-
-	for (n = 0; n < __arraycount(regs); n++)
-		device_printf(sc->dev, "  %-20s %08x\n", regs[n].name,
-		RD4(sc, regs[n].reg));
-}
-#endif
-
 static int
 sunxi_emac_phy_reset(struct sunxi_emac_softc *sc)
 {



CVS commit: src/sys/arch/arm/sunxi

2018-10-18 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Oct 18 12:58:19 UTC 2018

Modified Files:
src/sys/arch/arm/sunxi: sunxi_emac.c

Log Message:
Move MAC soft reset to sunxi_emac_init_locked. Since the MAC can get stuck
in reset state with no link, ignore reset timeouts and continue with
initializing the device.

Fixes "soft reset timeout" issue at boot with no network cable plugged in.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/arm/sunxi/sunxi_emac.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/sunxi_emac.c
diff -u src/sys/arch/arm/sunxi/sunxi_emac.c:1.18 src/sys/arch/arm/sunxi/sunxi_emac.c:1.19
--- src/sys/arch/arm/sunxi/sunxi_emac.c:1.18	Sun Oct 14 14:09:53 2018
+++ src/sys/arch/arm/sunxi/sunxi_emac.c	Thu Oct 18 12:58:19 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_emac.c,v 1.18 2018/10/14 14:09:53 martin Exp $ */
+/* $NetBSD: sunxi_emac.c,v 1.19 2018/10/18 12:58:19 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016-2017 Jared McNeill 
@@ -33,7 +33,7 @@
 #include "opt_net_mpsafe.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.18 2018/10/14 14:09:53 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.19 2018/10/18 12:58:19 jmcneill Exp $");
 
 #include 
 #include 
@@ -584,6 +584,31 @@ sunxi_emac_disable_intr(struct sunxi_ema
 }
 
 static int
+sunxi_emac_reset(struct sunxi_emac_softc *sc)
+{
+	int retry;
+
+	/* Soft reset all registers and logic */
+	WR4(sc, EMAC_BASIC_CTL_1, BASIC_CTL_SOFT_RST);
+
+	/* Wait for soft reset bit to self-clear */
+	for (retry = SOFT_RST_RETRY; retry > 0; retry--) {
+		if ((RD4(sc, EMAC_BASIC_CTL_1) & BASIC_CTL_SOFT_RST) == 0)
+			break;
+		delay(10);
+	}
+	if (retry == 0) {
+		aprint_debug_dev(sc->dev, "soft reset timed out\n");
+#ifdef SUNXI_EMAC_DEBUG
+		sunxi_emac_dump_regs(sc);
+#endif
+		return ETIMEDOUT;
+	}
+
+	return 0;
+}
+
+static int
 sunxi_emac_init_locked(struct sunxi_emac_softc *sc)
 {
 	struct ifnet *ifp = >ec.ec_if;
@@ -595,6 +620,13 @@ sunxi_emac_init_locked(struct sunxi_emac
 	if ((ifp->if_flags & IFF_RUNNING) != 0)
 		return 0;
 
+	/* Soft reset EMAC core */
+	sunxi_emac_reset(sc);
+
+	/* Write transmit and receive descriptor base address registers */
+	WR4(sc, EMAC_TX_DMA_LIST, sc->tx.desc_ring_paddr);
+	WR4(sc, EMAC_RX_DMA_LIST, sc->rx.desc_ring_paddr);
+
 	sunxi_emac_setup_rxfilter(sc);
 
 	/* Configure DMA burst length and priorities */
@@ -1154,37 +1186,6 @@ sunxi_emac_phy_reset(struct sunxi_emac_s
 }
 
 static int
-sunxi_emac_reset(struct sunxi_emac_softc *sc)
-{
-	int retry;
-
-	/* Reset PHY if necessary */
-	if (sunxi_emac_phy_reset(sc) != 0) {
-		aprint_error_dev(sc->dev, "failed to reset PHY\n");
-		return ENXIO;
-	}
-
-	/* Soft reset all registers and logic */
-	WR4(sc, EMAC_BASIC_CTL_1, BASIC_CTL_SOFT_RST);
-
-	/* Wait for soft reset bit to self-clear */
-	for (retry = SOFT_RST_RETRY; retry > 0; retry--) {
-		if ((RD4(sc, EMAC_BASIC_CTL_1) & BASIC_CTL_SOFT_RST) == 0)
-			break;
-		delay(10);
-	}
-	if (retry == 0) {
-		aprint_error_dev(sc->dev, "soft reset timed out\n");
-#ifdef SUNXI_EMAC_DEBUG
-		sunxi_emac_dump_regs(sc);
-#endif
-		return ETIMEDOUT;
-	}
-
-	return 0;
-}
-
-static int
 sunxi_emac_setup_dma(struct sunxi_emac_softc *sc)
 {
 	struct mbuf *m;
@@ -1276,10 +1277,6 @@ sunxi_emac_setup_dma(struct sunxi_emac_s
 	0, sc->rx.desc_map->dm_mapsize,
 	BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
 
-	/* Write transmit and receive descriptor base address registers */
-	WR4(sc, EMAC_TX_DMA_LIST, sc->tx.desc_ring_paddr);
-	WR4(sc, EMAC_RX_DMA_LIST, sc->rx.desc_ring_paddr);
-
 	return 0;
 }
 
@@ -1400,9 +1397,11 @@ sunxi_emac_attach(device_t parent, devic
 	sunxi_emac_get_eaddr(sc, eaddr);
 	aprint_normal_dev(self, "Ethernet address %s\n", ether_sprintf(eaddr));
 
-	/* Soft reset EMAC core */
-	if (sunxi_emac_reset(sc) != 0)
+	/* Reset PHY if necessary */
+	if (sunxi_emac_phy_reset(sc) != 0) {
+		aprint_error_dev(self, "failed to reset PHY\n");
 		return;
+	}
 
 	/* Setup DMA descriptors */
 	if (sunxi_emac_setup_dma(sc) != 0) {



CVS commit: src/sys/arch/arm/sunxi

2018-10-14 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Oct 14 14:09:53 UTC 2018

Modified Files:
src/sys/arch/arm/sunxi: sunxi_emac.c

Log Message:
Make debug code compile again


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/arm/sunxi/sunxi_emac.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/sunxi_emac.c
diff -u src/sys/arch/arm/sunxi/sunxi_emac.c:1.17 src/sys/arch/arm/sunxi/sunxi_emac.c:1.18
--- src/sys/arch/arm/sunxi/sunxi_emac.c:1.17	Thu Jul 19 19:52:00 2018
+++ src/sys/arch/arm/sunxi/sunxi_emac.c	Sun Oct 14 14:09:53 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_emac.c,v 1.17 2018/07/19 19:52:00 jmcneill Exp $ */
+/* $NetBSD: sunxi_emac.c,v 1.18 2018/10/14 14:09:53 martin Exp $ */
 
 /*-
  * Copyright (c) 2016-2017 Jared McNeill 
@@ -33,7 +33,7 @@
 #include "opt_net_mpsafe.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.17 2018/07/19 19:52:00 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.18 2018/10/14 14:09:53 martin Exp $");
 
 #include 
 #include 
@@ -1123,7 +1123,7 @@ sunxi_emac_dump_regs(struct sunxi_emac_s
 	u_int n;
 
 	for (n = 0; n < __arraycount(regs); n++)
-		device_printf(dev, "  %-20s %08x\n", regs[n].name,
+		device_printf(sc->dev, "  %-20s %08x\n", regs[n].name,
 		RD4(sc, regs[n].reg));
 }
 #endif



CVS commit: src/sys/arch/arm/sunxi

2018-08-21 Thread Benny Siegert
Module Name:src
Committed By:   bsiegert
Date:   Tue Aug 21 14:09:41 UTC 2018

Modified Files:
src/sys/arch/arm/sunxi: sunxi_thermal.c

Log Message:
Fix two typos in the Sunxi thermal driver.

Noticed by rudolf in PR port-arm/53537.

ok jmcneill@


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sunxi/sunxi_thermal.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/sunxi_thermal.c
diff -u src/sys/arch/arm/sunxi/sunxi_thermal.c:1.5 src/sys/arch/arm/sunxi/sunxi_thermal.c:1.6
--- src/sys/arch/arm/sunxi/sunxi_thermal.c:1.5	Sun Jan 28 18:24:50 2018
+++ src/sys/arch/arm/sunxi/sunxi_thermal.c	Tue Aug 21 14:09:41 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_thermal.c,v 1.5 2018/01/28 18:24:50 jmcneill Exp $ */
+/* $NetBSD: sunxi_thermal.c,v 1.6 2018/08/21 14:09:41 bsiegert Exp $ */
 
 /*-
  * Copyright (c) 2016-2017 Jared McNeill 
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_thermal.c,v 1.5 2018/01/28 18:24:50 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_thermal.c,v 1.6 2018/08/21 14:09:41 bsiegert Exp $");
 
 #include 
 #include 
@@ -259,7 +259,7 @@ h5_to_temp(u_int sensor, uint32_t val)
 		mul = H5_TEMP_MUL_L;
 	} else {
 		base = sensor == 0 ? H5_TEMP_BASE_H_0 : H5_TEMP_BASE_H_1;
-		mul = sensor == 0 ? H5_TEMP_MUL_H_1 : H5_TEMP_MUL_H_1;
+		mul = sensor == 0 ? H5_TEMP_MUL_H_0 : H5_TEMP_MUL_H_1;
 	}
 
 	return (base - val * mul) >> H5_TEMP_DIV;
@@ -275,7 +275,7 @@ h5_to_reg(u_int sensor, int val)
 		mul = H5_TEMP_MUL_L;
 	} else {
 		base = sensor == 0 ? H5_TEMP_BASE_H_0 : H5_TEMP_BASE_H_1;
-		mul = sensor == 0 ? H5_TEMP_MUL_H_1 : H5_TEMP_MUL_H_1;
+		mul = sensor == 0 ? H5_TEMP_MUL_H_0 : H5_TEMP_MUL_H_1;
 	}
 
 	return (base - (val << H5_TEMP_DIV)) / mul;



CVS commit: src/sys/arch/arm/sunxi

2018-07-19 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Jul 19 19:52:00 UTC 2018

Modified Files:
src/sys/arch/arm/sunxi: sunxi_emac.c

Log Message:
Print ethernet address at attach


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/arm/sunxi/sunxi_emac.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/sunxi_emac.c
diff -u src/sys/arch/arm/sunxi/sunxi_emac.c:1.16 src/sys/arch/arm/sunxi/sunxi_emac.c:1.17
--- src/sys/arch/arm/sunxi/sunxi_emac.c:1.16	Sat Jun 30 12:36:13 2018
+++ src/sys/arch/arm/sunxi/sunxi_emac.c	Thu Jul 19 19:52:00 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_emac.c,v 1.16 2018/06/30 12:36:13 jmcneill Exp $ */
+/* $NetBSD: sunxi_emac.c,v 1.17 2018/07/19 19:52:00 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016-2017 Jared McNeill 
@@ -33,7 +33,7 @@
 #include "opt_net_mpsafe.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.16 2018/06/30 12:36:13 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.17 2018/07/19 19:52:00 jmcneill Exp $");
 
 #include 
 #include 
@@ -1398,6 +1398,7 @@ sunxi_emac_attach(device_t parent, devic
 
 	/* Read MAC address before resetting the chip */
 	sunxi_emac_get_eaddr(sc, eaddr);
+	aprint_normal_dev(self, "Ethernet address %s\n", ether_sprintf(eaddr));
 
 	/* Soft reset EMAC core */
 	if (sunxi_emac_reset(sc) != 0)



  1   2   3   4   >