CVS commit: src/sys/dev/fdt

2022-08-06 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Sat Aug  6 20:16:43 UTC 2022

Modified Files:
src/sys/dev/fdt: fdt_memory.c

Log Message:
In my previous change, it was necessary to consider the case where the first 
block size is zero.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/fdt/fdt_memory.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/dev/fdt/fdt_memory.c
diff -u src/sys/dev/fdt/fdt_memory.c:1.5 src/sys/dev/fdt/fdt_memory.c:1.6
--- src/sys/dev/fdt/fdt_memory.c:1.5	Thu Aug  4 11:58:55 2022
+++ src/sys/dev/fdt/fdt_memory.c	Sat Aug  6 20:16:42 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_memory.c,v 1.5 2022/08/04 11:58:55 ryo Exp $ */
+/* $NetBSD: fdt_memory.c,v 1.6 2022/08/06 20:16:42 ryo Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include "opt_fdt.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_memory.c,v 1.5 2022/08/04 11:58:55 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_memory.c,v 1.6 2022/08/06 20:16:42 ryo Exp $");
 
 #include 
 #include 
@@ -83,16 +83,16 @@ fdt_memory_get(uint64_t *pstart, uint64_
 {
 	const int memory = OF_finddevice("/memory");
 	uint64_t cur_addr, cur_size;
-	int index;
+	int index, nadd;
 
-	for (index = 0;
+	for (index = 0, nadd = 0;
 	 fdtbus_get_reg64(memory, index, _addr, _size) == 0;
 	 index++) {
 		if (cur_size == 0)
 			continue;
 		fdt_memory_add_range(cur_addr, cur_size);
 
-		if (index == 0) {
+		if (nadd++ == 0) {
 			*pstart = cur_addr;
 			*pend = cur_addr + cur_size;
 			continue;
@@ -102,7 +102,7 @@ fdt_memory_get(uint64_t *pstart, uint64_
 		if (cur_addr + cur_size > *pend)
 			*pend = cur_addr + cur_size;
 	}
-	if (index == 0)
+	if (nadd == 0)
 		panic("Cannot determine memory size");
 }
 



CVS commit: src/sys/dev/fdt

2022-08-06 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Sat Aug  6 20:16:43 UTC 2022

Modified Files:
src/sys/dev/fdt: fdt_memory.c

Log Message:
In my previous change, it was necessary to consider the case where the first 
block size is zero.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/fdt/fdt_memory.c

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



CVS commit: src/sys/dev/fdt

2022-08-04 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Aug  4 11:58:55 UTC 2022

Modified Files:
src/sys/dev/fdt: fdt_memory.c

Log Message:
Don't pass a block of size 0 to fdt_memory_add_range().

There are some environments where size 0 blocks are passed from the loader.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/fdt/fdt_memory.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/dev/fdt/fdt_memory.c
diff -u src/sys/dev/fdt/fdt_memory.c:1.4 src/sys/dev/fdt/fdt_memory.c:1.5
--- src/sys/dev/fdt/fdt_memory.c:1.4	Fri Jan  7 07:25:37 2022
+++ src/sys/dev/fdt/fdt_memory.c	Thu Aug  4 11:58:55 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_memory.c,v 1.4 2022/01/07 07:25:37 mlelstv Exp $ */
+/* $NetBSD: fdt_memory.c,v 1.5 2022/08/04 11:58:55 ryo Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include "opt_fdt.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_memory.c,v 1.4 2022/01/07 07:25:37 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_memory.c,v 1.5 2022/08/04 11:58:55 ryo Exp $");
 
 #include 
 #include 
@@ -88,6 +88,8 @@ fdt_memory_get(uint64_t *pstart, uint64_
 	for (index = 0;
 	 fdtbus_get_reg64(memory, index, _addr, _size) == 0;
 	 index++) {
+		if (cur_size == 0)
+			continue;
 		fdt_memory_add_range(cur_addr, cur_size);
 
 		if (index == 0) {



CVS commit: src/sys/dev/fdt

2022-08-04 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Aug  4 11:58:55 UTC 2022

Modified Files:
src/sys/dev/fdt: fdt_memory.c

Log Message:
Don't pass a block of size 0 to fdt_memory_add_range().

There are some environments where size 0 blocks are passed from the loader.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/fdt/fdt_memory.c

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



CVS commit: src/sys/dev/fdt

2022-06-12 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Jun 12 08:04:07 UTC 2022

Modified Files:
src/sys/dev/fdt: dwc3_fdt.c

Log Message:
Attach when dr_mode is "otg" and the controller has the "usb-role-switch" and
"role-switch-default-mode" as seen in the Apple M1 dts.

This assumes the controller is properly setup for host mode already.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/fdt/dwc3_fdt.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/dev/fdt/dwc3_fdt.c
diff -u src/sys/dev/fdt/dwc3_fdt.c:1.19 src/sys/dev/fdt/dwc3_fdt.c:1.20
--- src/sys/dev/fdt/dwc3_fdt.c:1.19	Sun Nov  7 17:14:20 2021
+++ src/sys/dev/fdt/dwc3_fdt.c	Sun Jun 12 08:04:07 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc3_fdt.c,v 1.19 2021/11/07 17:14:20 jmcneill Exp $ */
+/* $NetBSD: dwc3_fdt.c,v 1.20 2022/06/12 08:04:07 skrll Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwc3_fdt.c,v 1.19 2021/11/07 17:14:20 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwc3_fdt.c,v 1.20 2022/06/12 08:04:07 skrll Exp $");
 
 #include 
 #include 
@@ -256,9 +256,30 @@ dwc3_fdt_attach(device_t parent, device_
 		return;
 	}
 
-	/* Only host mode is supported */
+	/*
+	 * Only host mode is supported, but this includes otg devices
+	 * that have 'usb-role-switch' and 'role-switch-default-mode' of
+	 * 'host'
+	 */
 	const char *dr_mode = fdtbus_get_string(dwc3_phandle, "dr_mode");
-	if (dr_mode == NULL || strcmp(dr_mode, "host") != 0) {
+	if (dr_mode == NULL || strcmp(dr_mode, "otg") == 0) {
+		bool ok = false;
+		if (of_hasprop(dwc3_phandle, "usb-role-switch")) {
+			const char *rsdm = fdtbus_get_string(dwc3_phandle,
+			"role-switch-default-mode");
+			if (rsdm != NULL && strcmp(rsdm, "host") == 0)
+ok = true;
+
+			if (!ok) {
+aprint_error(": host is not default mode\n");
+return;
+			}
+		}
+		if (!ok) {
+			aprint_error(": cannot switch 'otg' mode to host\n");
+			return;
+		}
+	} else if (strcmp(dr_mode, "host") != 0) {
 		aprint_error(": '%s' not supported\n", dr_mode);
 		return;
 	}



CVS commit: src/sys/dev/fdt

2022-06-12 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Jun 12 08:04:07 UTC 2022

Modified Files:
src/sys/dev/fdt: dwc3_fdt.c

Log Message:
Attach when dr_mode is "otg" and the controller has the "usb-role-switch" and
"role-switch-default-mode" as seen in the Apple M1 dts.

This assumes the controller is properly setup for host mode already.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/fdt/dwc3_fdt.c

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



CVS commit: src/sys/dev/fdt

2022-03-25 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Mar 25 21:23:51 UTC 2022

Modified Files:
src/sys/dev/fdt: files.fdt
Added Files:
src/sys/dev/fdt: fdt_userconf.c

Log Message:
fdt: add support for USERCONF option


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/fdt_userconf.c
cvs rdiff -u -r1.63 -r1.64 src/sys/dev/fdt/files.fdt

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

Modified files:

Index: src/sys/dev/fdt/files.fdt
diff -u src/sys/dev/fdt/files.fdt:1.63 src/sys/dev/fdt/files.fdt:1.64
--- src/sys/dev/fdt/files.fdt:1.63	Fri Mar  4 08:19:06 2022
+++ src/sys/dev/fdt/files.fdt	Fri Mar 25 21:23:51 2022
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.63 2022/03/04 08:19:06 skrll Exp $
+# $NetBSD: files.fdt,v 1.64 2022/03/25 21:23:51 jmcneill Exp $
 
 include	"external/bsd/libfdt/conf/files.libfdt"
 
@@ -13,6 +13,8 @@ device	simplebus: fdt
 attach	simplebus at fdt
 file	dev/fdt/fdtbus.c			fdt
 
+file	dev/fdt/fdt_userconf.c			fdt & userconf
+
 device	fregulator
 attach	fregulator at fdt
 file	dev/fdt/fixedregulator.c		fregulator

Added files:

Index: src/sys/dev/fdt/fdt_userconf.c
diff -u /dev/null src/sys/dev/fdt/fdt_userconf.c:1.1
--- /dev/null	Fri Mar 25 21:23:51 2022
+++ src/sys/dev/fdt/fdt_userconf.c	Fri Mar 25 21:23:51 2022
@@ -0,0 +1,67 @@
+/* $NetBSD: fdt_userconf.c,v 1.1 2022/03/25 21:23:51 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2022 Jared McNeill 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: fdt_userconf.c,v 1.1 2022/03/25 21:23:51 jmcneill Exp $");
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#define	FDT_CHOSEN_PATH			"/chosen"
+#define	FDT_CHOSEN_USERCONF_PROP	"netbsd,userconf"
+
+void
+userconf_bootinfo(void)
+{
+	const void *fdt = fdtbus_get_data();
+	const char *cmd;
+	int chosen, index;
+
+	if (fdt == NULL) {
+		return;
+	}
+
+	chosen = fdt_path_offset(fdt, FDT_CHOSEN_PATH);
+	if (chosen < 0) {
+		return;
+	}
+
+	index = 0;
+	do {
+		cmd = fdt_stringlist_get(fdt, chosen, FDT_CHOSEN_USERCONF_PROP,
+		index++, NULL);
+		if (cmd != NULL) {
+			aprint_debug("Processing userconf command: %s\n", cmd);
+			userconf_parse(__UNCONST(cmd));
+		}
+	} while (cmd != NULL);
+}



CVS commit: src/sys/dev/fdt

2022-03-25 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Mar 25 21:23:51 UTC 2022

Modified Files:
src/sys/dev/fdt: files.fdt
Added Files:
src/sys/dev/fdt: fdt_userconf.c

Log Message:
fdt: add support for USERCONF option


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/fdt_userconf.c
cvs rdiff -u -r1.63 -r1.64 src/sys/dev/fdt/files.fdt

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



CVS commit: src/sys/dev/fdt

2022-03-04 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Mar  4 08:19:07 UTC 2022

Modified Files:
src/sys/dev/fdt: fdtbus.c fdtvar.h files.fdt
Added Files:
src/sys/dev/fdt: fdt_mbox.c fdt_powerdomain.c

Log Message:
Add mailbox and power-domain support.

power-domain support is very rudimentary.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/fdt_mbox.c \
src/sys/dev/fdt/fdt_powerdomain.c
cvs rdiff -u -r1.45 -r1.46 src/sys/dev/fdt/fdtbus.c
cvs rdiff -u -r1.76 -r1.77 src/sys/dev/fdt/fdtvar.h
cvs rdiff -u -r1.62 -r1.63 src/sys/dev/fdt/files.fdt

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



CVS commit: src/sys/dev/fdt

2022-03-04 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Mar  4 08:19:07 UTC 2022

Modified Files:
src/sys/dev/fdt: fdtbus.c fdtvar.h files.fdt
Added Files:
src/sys/dev/fdt: fdt_mbox.c fdt_powerdomain.c

Log Message:
Add mailbox and power-domain support.

power-domain support is very rudimentary.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/fdt_mbox.c \
src/sys/dev/fdt/fdt_powerdomain.c
cvs rdiff -u -r1.45 -r1.46 src/sys/dev/fdt/fdtbus.c
cvs rdiff -u -r1.76 -r1.77 src/sys/dev/fdt/fdtvar.h
cvs rdiff -u -r1.62 -r1.63 src/sys/dev/fdt/files.fdt

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

Modified files:

Index: src/sys/dev/fdt/fdtbus.c
diff -u src/sys/dev/fdt/fdtbus.c:1.45 src/sys/dev/fdt/fdtbus.c:1.46
--- src/sys/dev/fdt/fdtbus.c:1.45	Sat Jan 22 11:49:17 2022
+++ src/sys/dev/fdt/fdtbus.c	Fri Mar  4 08:19:06 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtbus.c,v 1.45 2022/01/22 11:49:17 thorpej Exp $ */
+/* $NetBSD: fdtbus.c,v 1.46 2022/03/04 08:19:06 skrll Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.45 2022/01/22 11:49:17 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.46 2022/03/04 08:19:06 skrll Exp $");
 
 #include 
 #include 
@@ -468,6 +468,8 @@ fdt_pre_attach(struct fdt_node *node)
 		aprint_debug_dev(node->n_bus,
 		"failed to set %s config on %s: %d\n",
 		cfgname, node->n_name, error);
+
+	fdtbus_powerdomain_enable(node->n_phandle);
 }
 
 static void

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.76 src/sys/dev/fdt/fdtvar.h:1.77
--- src/sys/dev/fdt/fdtvar.h:1.76	Wed Feb 23 08:56:11 2022
+++ src/sys/dev/fdt/fdtvar.h	Fri Mar  4 08:19:06 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.76 2022/02/23 08:56:11 skrll Exp $ */
+/* $NetBSD: fdtvar.h,v 1.77 2022/03/04 08:19:06 skrll Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -157,6 +157,20 @@ struct fdtbus_iommu_func {
 };
 
 
+struct fdtbus_mbox_channel {
+	struct fdtbus_mbox_controller *mb_ctlr;
+	void *mb_priv;
+};
+
+struct fdtbus_mbox_controller_func {
+	void *	(*mc_acquire)(device_t, const void *, size_t, void (*)(void *),
+			  void *);
+	void	(*mc_release)(device_t, void *);
+	int	(*mc_recv)(device_t, void *, void *, size_t);
+	int	(*mc_send)(device_t, void *, const void *, size_t);
+};
+
+
 struct fdtbus_mmc_pwrseq;
 
 struct fdtbus_mmc_pwrseq_func {
@@ -201,6 +215,13 @@ struct fdtbus_power_controller_func {
 };
 
 
+struct fdtbus_powerdomain_controller;
+
+struct fdtbus_powerdomain_controller_func {
+	void 	(*pdc_enable)(device_t, const uint32_t *, bool);
+};
+
+
 struct fdtbus_pwm_controller_func {
 	pwm_tag_t (*get_tag)(device_t, const void *, size_t);
 };
@@ -306,12 +327,16 @@ int		fdtbus_register_interrupt_controlle
 		const struct fdtbus_interrupt_controller_func *);
 int		fdtbus_register_iommu(device_t, int,
 		const struct fdtbus_iommu_func *);
+int		fdtbus_register_mbox_controller(device_t, int,
+		const struct fdtbus_mbox_controller_func *);
 int		fdtbus_register_mmc_pwrseq(device_t, int,
 		const struct fdtbus_mmc_pwrseq_func *);
 int		fdtbus_register_pinctrl_config(device_t, int,
 		const struct fdtbus_pinctrl_controller_func *);
 int		fdtbus_register_power_controller(device_t, int,
 		const struct fdtbus_power_controller_func *);
+int		fdtbus_register_powerdomain_controller(device_t, int,
+		const struct fdtbus_powerdomain_controller_func *);
 int		fdtbus_register_phy_controller(device_t, int,
 		const struct fdtbus_phy_controller_func *);
 int		fdtbus_register_pwm_controller(device_t, int,
@@ -392,6 +417,15 @@ int		fdtbus_intr_parent(int);
 bus_dma_tag_t	fdtbus_iommu_map(int, u_int, bus_dma_tag_t);
 bus_dma_tag_t	fdtbus_iommu_map_pci(int, uint32_t, bus_dma_tag_t);
 
+struct fdtbus_mbox_channel *
+		fdtbus_mbox_get(int, const char *, void (*)(void *), void *);
+struct fdtbus_mbox_channel *
+		fdtbus_mbox_get_index(int, u_int, void (*)(void *),
+		void *);
+int		fdtbus_mbox_send(struct fdtbus_mbox_channel *, const void *, size_t);
+int		fdtbus_mbox_recv(struct fdtbus_mbox_channel *, void *, size_t);
+void		fdtbus_mbox_put(struct fdtbus_mbox_channel *);
+
 struct fdtbus_mmc_pwrseq *
 		fdtbus_mmc_pwrseq_get(int);
 void		fdtbus_mmc_pwrseq_pre_power_on(struct fdtbus_mmc_pwrseq *);
@@ -447,6 +481,11 @@ int		fdtbus_todr_attach(device_t, int, t
 void		fdtbus_power_reset(void);
 void		fdtbus_power_poweroff(void);
 
+int		fdtbus_powerdomain_enable(int);
+int		fdtbus_powerdomain_enable_index(int, int);
+int		fdtbus_powerdomain_disable(int);
+int		fdtbus_powerdomain_disable_index(int, int);
+
 struct syscon *	fdtbus_syscon_acquire(int, const char *);
 struct syscon *	fdtbus_syscon_lookup(int);
 

Index: src/sys/dev/fdt/files.fdt
diff -u src/sys/dev/fdt/files.fdt:1.62 src/sys/dev/fdt/files.fdt:1.63
--- src/sys/dev/fdt/files.fdt:1.62	Sat Sep  4 12:34:39 

CVS commit: src/sys/dev/fdt

2022-02-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Feb 23 08:56:11 UTC 2022

Modified Files:
src/sys/dev/fdt: fdtvar.h

Log Message:
Sort a bit. NFC


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sys/dev/fdt/fdtvar.h

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



CVS commit: src/sys/dev/fdt

2022-02-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Feb 23 08:56:11 UTC 2022

Modified Files:
src/sys/dev/fdt: fdtvar.h

Log Message:
Sort a bit. NFC


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sys/dev/fdt/fdtvar.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/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.75 src/sys/dev/fdt/fdtvar.h:1.76
--- src/sys/dev/fdt/fdtvar.h:1.75	Wed Feb 23 07:55:55 2022
+++ src/sys/dev/fdt/fdtvar.h	Wed Feb 23 08:56:11 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.75 2022/02/23 07:55:55 skrll Exp $ */
+/* $NetBSD: fdtvar.h,v 1.76 2022/02/23 08:56:11 skrll Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -59,95 +59,17 @@ struct fdt_attach_args {
 	int faa_quiet;
 };
 
-/* flags for fdtbus_intr_establish */
-#define FDT_INTR_MPSAFE			__BIT(0)
-
-/* Interrupt trigger types defined by the FDT "interrupts" bindings. */
-#define	FDT_INTR_TYPE_POS_EDGE		__BIT(0)
-#define	FDT_INTR_TYPE_NEG_EDGE		__BIT(1)
-#define	FDT_INTR_TYPE_DOUBLE_EDGE	(FDT_INTR_TYPE_POS_EDGE | \
-	 FDT_INTR_TYPE_NEG_EDGE)
-#define	FDT_INTR_TYPE_HIGH_LEVEL	__BIT(2)
-#define	FDT_INTR_TYPE_LOW_LEVEL		__BIT(3)
-
-struct fdtbus_interrupt_controller_func {
-	void *	(*establish)(device_t, u_int *, int, int,
-			 int (*)(void *), void *, const char *);
-	void	(*disestablish)(device_t, void *);
-	bool	(*intrstr)(device_t, u_int *, char *, size_t);
-	void	(*mask)(device_t, void *);
-	void	(*unmask)(device_t, void *);
-};
-
-struct fdtbus_spi_controller_func {
-	struct spi_controller *	(*get_controller)(device_t);
-};
-
-struct fdtbus_gpio_controller;
-
-struct fdtbus_gpio_pin {
-	struct fdtbus_gpio_controller *gp_gc;
-	void *gp_priv;
-};
-
-struct fdtbus_gpio_controller_func {
-	void *	(*acquire)(device_t, const void *, size_t, int);
-	void	(*release)(device_t, void *);
-	int	(*read)(device_t, void *, bool);
-	void	(*write)(device_t, void *, int, bool);
-};
-
-struct fdtbus_pinctrl_controller;
-
-struct fdtbus_pinctrl_pin {
-	struct fdtbus_pinctrl_controller *pp_pc;
-	void *pp_priv;
-};
-
-struct fdtbus_pinctrl_controller_func {
-	int (*set_config)(device_t, const void *, size_t);
-};
-
-struct fdtbus_iommu_func {
-	bus_dma_tag_t (*map)(device_t, const u_int *, bus_dma_tag_t);
-};
-
-struct fdtbus_regulator_controller;
-
-struct fdtbus_regulator {
-	struct fdtbus_regulator_controller *reg_rc;
-};
-
-struct fdtbus_regulator_controller_func {
-	int	(*acquire)(device_t);
-	void	(*release)(device_t);
-	int	(*enable)(device_t, bool);
-	int	(*set_voltage)(device_t, u_int, u_int);
-	int	(*get_voltage)(device_t, u_int *);
-};
 
 struct fdtbus_clock_controller_func {
 	struct clk *	(*decode)(device_t, int, const void *, size_t);
 };
 
-struct fdtbus_reset_controller;
-
-struct fdtbus_reset {
-	struct fdtbus_reset_controller *rst_rc;
-	void *rst_priv;
-};
-
-struct fdtbus_reset_controller_func {
-	void *	(*acquire)(device_t, const void *, size_t);
-	void	(*release)(device_t, void *);
-	int	(*reset_assert)(device_t, void *);
-	int	(*reset_deassert)(device_t, void *);
-};
 
 struct fdtbus_dai_controller_func {
 	audio_dai_tag_t (*get_tag)(device_t, const void *, size_t);
 };
 
+
 struct fdtbus_dma_controller;
 
 struct fdtbus_dma {
@@ -193,13 +115,58 @@ struct fdtbus_dma_controller_func {
 	void	(*halt)(device_t, void *);
 };
 
-struct fdtbus_power_controller;
 
-struct fdtbus_power_controller_func {
-	void 	(*reset)(device_t);
-	void	(*poweroff)(device_t);
+struct fdtbus_gpio_controller;
+
+struct fdtbus_gpio_pin {
+	struct fdtbus_gpio_controller *gp_gc;
+	void *gp_priv;
+};
+
+struct fdtbus_gpio_controller_func {
+	void *	(*acquire)(device_t, const void *, size_t, int);
+	void	(*release)(device_t, void *);
+	int	(*read)(device_t, void *, bool);
+	void	(*write)(device_t, void *, int, bool);
+};
+
+
+/* flags for fdtbus_intr_establish */
+#define FDT_INTR_MPSAFE			__BIT(0)
+
+/* Interrupt trigger types defined by the FDT "interrupts" bindings. */
+#define	FDT_INTR_TYPE_POS_EDGE		__BIT(0)
+#define	FDT_INTR_TYPE_NEG_EDGE		__BIT(1)
+#define	FDT_INTR_TYPE_DOUBLE_EDGE	(FDT_INTR_TYPE_POS_EDGE | \
+	 FDT_INTR_TYPE_NEG_EDGE)
+#define	FDT_INTR_TYPE_HIGH_LEVEL	__BIT(2)
+#define	FDT_INTR_TYPE_LOW_LEVEL		__BIT(3)
+
+struct fdtbus_interrupt_controller_func {
+	void *	(*establish)(device_t, u_int *, int, int,
+			 int (*)(void *), void *, const char *);
+	void	(*disestablish)(device_t, void *);
+	bool	(*intrstr)(device_t, u_int *, char *, size_t);
+	void	(*mask)(device_t, void *);
+	void	(*unmask)(device_t, void *);
+};
+
+
+struct fdtbus_iommu_func {
+	bus_dma_tag_t (*map)(device_t, const u_int *, bus_dma_tag_t);
+};
+
+
+struct fdtbus_mmc_pwrseq;
+
+struct fdtbus_mmc_pwrseq_func {
+	void	(*pre_power_on)(device_t);
+	void	(*post_power_on)(device_t);
+	void	(*power_off)(device_t);
+	void	(*reset)(device_t);
 };
 
+
 struct fdtbus_phy_controller;
 
 struct fdtbus_phy {
@@ -213,21 

CVS commit: src/sys/dev/fdt

2022-02-06 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb  6 15:47:06 UTC 2022

Modified Files:
src/sys/dev/fdt: dwcmmc_fdt.c

Log Message:
fdt: dwcmmc: Honour broken-cd and non-removable DT properties


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/fdt/dwcmmc_fdt.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/dev/fdt/dwcmmc_fdt.c
diff -u src/sys/dev/fdt/dwcmmc_fdt.c:1.18 src/sys/dev/fdt/dwcmmc_fdt.c:1.19
--- src/sys/dev/fdt/dwcmmc_fdt.c:1.18	Wed Mar 24 18:19:31 2021
+++ src/sys/dev/fdt/dwcmmc_fdt.c	Sun Feb  6 15:47:06 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: dwcmmc_fdt.c,v 1.18 2021/03/24 18:19:31 skrll Exp $ */
+/* $NetBSD: dwcmmc_fdt.c,v 1.19 2022/02/06 15:47:06 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwcmmc_fdt.c,v 1.18 2021/03/24 18:19:31 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwcmmc_fdt.c,v 1.19 2022/02/06 15:47:06 jmcneill Exp $");
 
 #include 
 #include 
@@ -167,6 +167,12 @@ dwcmmc_fdt_attach(device_t parent, devic
 	sc->sc_intr_cardmask = esc->sc_conf->intr_cardmask;
 	sc->sc_ciu_div = esc->sc_conf->ciu_div;
 	sc->sc_flags = esc->sc_conf->flags;
+	if (of_getprop_bool(phandle, "non-removable")) {
+		sc->sc_flags |= DWC_MMC_F_NON_REMOVABLE;
+	}
+	if (of_getprop_bool(phandle, "broken-cd")) {
+		sc->sc_flags |= DWC_MMC_F_BROKEN_CD;
+	}
 	sc->sc_pre_power_on = dwcmmc_fdt_pre_power_on;
 	sc->sc_post_power_on = dwcmmc_fdt_post_power_on;
 	sc->sc_bus_clock = dwcmmc_fdt_bus_clock;



CVS commit: src/sys/dev/fdt

2022-02-06 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb  6 15:47:06 UTC 2022

Modified Files:
src/sys/dev/fdt: dwcmmc_fdt.c

Log Message:
fdt: dwcmmc: Honour broken-cd and non-removable DT properties


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/fdt/dwcmmc_fdt.c

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



CVS commit: src/sys/dev/fdt

2022-01-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Jan 23 08:01:33 UTC 2022

Modified Files:
src/sys/dev/fdt: arasan_sdhc_fdt.c

Log Message:
Use __MASK(4) in bus_dmatag_subregion.  NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/fdt/arasan_sdhc_fdt.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/dev/fdt/arasan_sdhc_fdt.c
diff -u src/sys/dev/fdt/arasan_sdhc_fdt.c:1.7 src/sys/dev/fdt/arasan_sdhc_fdt.c:1.8
--- src/sys/dev/fdt/arasan_sdhc_fdt.c:1.7	Mon Jan 17 14:00:47 2022
+++ src/sys/dev/fdt/arasan_sdhc_fdt.c	Sun Jan 23 08:01:33 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: arasan_sdhc_fdt.c,v 1.7 2022/01/17 14:00:47 skrll Exp $ */
+/* $NetBSD: arasan_sdhc_fdt.c,v 1.8 2022/01/23 08:01:33 skrll Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: arasan_sdhc_fdt.c,v 1.7 2022/01/17 14:00:47 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arasan_sdhc_fdt.c,v 1.8 2022/01/23 08:01:33 skrll Exp $");
 
 #include 
 #include 
@@ -272,7 +272,7 @@ arasan_sdhc_attach(device_t parent, devi
 
 	const uint32_t caps = bus_space_read_4(sc->sc_bst, sc->sc_bsh, SDHC_CAPABILITIES);
 	if ((caps & (SDHC_ADMA2_SUPP|SDHC_64BIT_SYS_BUS)) == SDHC_ADMA2_SUPP) {
-		error = bus_dmatag_subregion(faa->faa_dmat, 0, UINT32_MAX,
+		error = bus_dmatag_subregion(faa->faa_dmat, 0, __MASK(32),
 		>sc_base.sc_dmat, BUS_DMA_WAITOK);
 		if (error != 0) {
 			aprint_error(": couldn't create DMA tag: %d\n", error);



CVS commit: src/sys/dev/fdt

2022-01-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Jan 23 08:01:33 UTC 2022

Modified Files:
src/sys/dev/fdt: arasan_sdhc_fdt.c

Log Message:
Use __MASK(4) in bus_dmatag_subregion.  NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/fdt/arasan_sdhc_fdt.c

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



Re: CVS commit: src/sys/dev/fdt

2022-01-21 Thread Michael
Should fix PR 56650

> Module Name:  src
> Committed By: macallan
> Date: Fri Jan 21 21:00:26 UTC 2022
> 
> Modified Files:
>   src/sys/dev/fdt: fdt_port.c
> 
> Log Message:
> when enumerating ports and endpoints treat missing 'reg' properties as zero
> ok jmcneill:
> Looking at Linux. If port or endpoint are missing a 'reg' property it 
> defaults to 0.
> Please make our code do the same.
> 
> see 
> https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/graph.yaml
> 
> with this my pinebook has a usable console again
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.6 -r1.7 src/sys/dev/fdt/fdt_port.c
> 
> Please note that diffs are not public domain; they are subject to the
> copyright notices on the relevant files.
> 


CVS commit: src/sys/dev/fdt

2022-01-21 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Fri Jan 21 21:00:26 UTC 2022

Modified Files:
src/sys/dev/fdt: fdt_port.c

Log Message:
when enumerating ports and endpoints treat missing 'reg' properties as zero
ok jmcneill:
Looking at Linux. If port or endpoint are missing a 'reg' property it defaults 
to 0.
Please make our code do the same.

see 
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/graph.yaml

with this my pinebook has a usable console again


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/fdt/fdt_port.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/dev/fdt/fdt_port.c
diff -u src/sys/dev/fdt/fdt_port.c:1.6 src/sys/dev/fdt/fdt_port.c:1.7
--- src/sys/dev/fdt/fdt_port.c:1.6	Wed Jan  1 12:46:44 2020
+++ src/sys/dev/fdt/fdt_port.c	Fri Jan 21 21:00:26 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdt_port.c,v 1.6 2020/01/01 12:46:44 jmcneill Exp $	*/
+/*	$NetBSD: fdt_port.c,v 1.7 2022/01/21 21:00:26 macallan Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: fdt_port.c,v 1.6 2020/01/01 12:46:44 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: fdt_port.c,v 1.7 2022/01/21 21:00:26 macallan Exp $");
 
 #include 
 #include 
@@ -298,10 +298,10 @@ again:
 			continue;
 		if (fdtbus_get_reg(child, 0, , NULL) != 0) {
 			if (ports->dp_nports > 1)
-aprint_error_dev(self,
+aprint_debug_dev(self,
 "%s: missing reg property",
 fdtbus_get_string(child, "name"));
-			id = i;
+			id = 0;
 		}
 		ports->dp_port[i].port_id = id;
 		ports->dp_port[i].port_phandle = child;
@@ -349,10 +349,10 @@ fdt_endpoints_register(int phandle, stru
 			continue;
 		if (fdtbus_get_reg64(child, 0, , NULL) != 0) {
 			if (port->port_nep > 1)
-aprint_error_dev(port->port_dp->dp_dev,
+aprint_debug_dev(port->port_dp->dp_dev,
 "%s: missing reg property",
 fdtbus_get_string(child, "name"));
-			id = i;
+			id = 0;
 		}
 		ep = >port_ep[i];
 		ep->ep_id = id;



CVS commit: src/sys/dev/fdt

2022-01-21 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Fri Jan 21 21:00:26 UTC 2022

Modified Files:
src/sys/dev/fdt: fdt_port.c

Log Message:
when enumerating ports and endpoints treat missing 'reg' properties as zero
ok jmcneill:
Looking at Linux. If port or endpoint are missing a 'reg' property it defaults 
to 0.
Please make our code do the same.

see 
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/graph.yaml

with this my pinebook has a usable console again


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/fdt/fdt_port.c

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



CVS commit: src/sys/dev/fdt

2022-01-17 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Jan 17 14:00:47 UTC 2022

Modified Files:
src/sys/dev/fdt: arasan_sdhc_fdt.c

Log Message:
s/0x/UINT32_MAX/ in bus_dmatag_subregion call


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/fdt/arasan_sdhc_fdt.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/dev/fdt/arasan_sdhc_fdt.c
diff -u src/sys/dev/fdt/arasan_sdhc_fdt.c:1.6 src/sys/dev/fdt/arasan_sdhc_fdt.c:1.7
--- src/sys/dev/fdt/arasan_sdhc_fdt.c:1.6	Wed Jan 27 03:10:21 2021
+++ src/sys/dev/fdt/arasan_sdhc_fdt.c	Mon Jan 17 14:00:47 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: arasan_sdhc_fdt.c,v 1.6 2021/01/27 03:10:21 thorpej Exp $ */
+/* $NetBSD: arasan_sdhc_fdt.c,v 1.7 2022/01/17 14:00:47 skrll Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: arasan_sdhc_fdt.c,v 1.6 2021/01/27 03:10:21 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arasan_sdhc_fdt.c,v 1.7 2022/01/17 14:00:47 skrll Exp $");
 
 #include 
 #include 
@@ -272,7 +272,7 @@ arasan_sdhc_attach(device_t parent, devi
 
 	const uint32_t caps = bus_space_read_4(sc->sc_bst, sc->sc_bsh, SDHC_CAPABILITIES);
 	if ((caps & (SDHC_ADMA2_SUPP|SDHC_64BIT_SYS_BUS)) == SDHC_ADMA2_SUPP) {
-		error = bus_dmatag_subregion(faa->faa_dmat, 0, 0x,
+		error = bus_dmatag_subregion(faa->faa_dmat, 0, UINT32_MAX,
 		>sc_base.sc_dmat, BUS_DMA_WAITOK);
 		if (error != 0) {
 			aprint_error(": couldn't create DMA tag: %d\n", error);



CVS commit: src/sys/dev/fdt

2022-01-17 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Jan 17 14:00:47 UTC 2022

Modified Files:
src/sys/dev/fdt: arasan_sdhc_fdt.c

Log Message:
s/0x/UINT32_MAX/ in bus_dmatag_subregion call


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/fdt/arasan_sdhc_fdt.c

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



CVS commit: src/sys/dev/fdt

2022-01-13 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Jan 14 07:40:52 UTC 2022

Modified Files:
src/sys/dev/fdt: fdtvar.h

Log Message:
Formatting. NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sys/dev/fdt/fdtvar.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/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.73 src/sys/dev/fdt/fdtvar.h:1.74
--- src/sys/dev/fdt/fdtvar.h:1.73	Sun Nov  7 17:13:53 2021
+++ src/sys/dev/fdt/fdtvar.h	Fri Jan 14 07:40:52 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.73 2021/11/07 17:13:53 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.74 2022/01/14 07:40:52 skrll Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -60,7 +60,7 @@ struct fdt_attach_args {
 };
 
 /* flags for fdtbus_intr_establish */
-#define FDT_INTR_MPSAFE	__BIT(0)
+#define FDT_INTR_MPSAFE			__BIT(0)
 
 /* Interrupt trigger types defined by the FDT "interrupts" bindings. */
 #define	FDT_INTR_TYPE_POS_EDGE		__BIT(0)
@@ -321,8 +321,10 @@ int		fdtbus_get_phandle(int, const char 
 int		fdtbus_get_phandle_with_data(int, const char *, const char *,
 		int, struct fdt_phandle_data *);
 int		fdtbus_get_phandle_from_native(int);
+
 i2c_tag_t	fdtbus_get_i2c_tag(int);
 i2c_tag_t	fdtbus_i2c_acquire(int, const char *);
+
 void *		fdtbus_intr_establish(int, u_int, int, int,
 		int (*func)(void *), void *arg);
 void *		fdtbus_intr_establish_xname(int, u_int, int, int,
@@ -337,18 +339,24 @@ void		fdtbus_intr_disestablish(int, void
 bool		fdtbus_intr_str(int, u_int, char *, size_t);
 bool		fdtbus_intr_str_raw(int, const u_int *, char *, size_t);
 int		fdtbus_intr_parent(int);
+
 int		fdtbus_gpio_count(int, const char *);
-struct fdtbus_gpio_pin *fdtbus_gpio_acquire(int, const char *, int);
-struct fdtbus_gpio_pin *fdtbus_gpio_acquire_index(int, const char *, int, int);
+struct fdtbus_gpio_pin *
+		fdtbus_gpio_acquire(int, const char *, int);
+struct fdtbus_gpio_pin *
+		fdtbus_gpio_acquire_index(int, const char *, int, int);
 void		fdtbus_gpio_release(struct fdtbus_gpio_pin *);
 int		fdtbus_gpio_read(struct fdtbus_gpio_pin *);
 void		fdtbus_gpio_write(struct fdtbus_gpio_pin *, int);
 int		fdtbus_gpio_read_raw(struct fdtbus_gpio_pin *);
 void		fdtbus_gpio_write_raw(struct fdtbus_gpio_pin *, int);
+
 audio_dai_tag_t	fdtbus_dai_acquire(int, const char *);
 audio_dai_tag_t	fdtbus_dai_acquire_index(int, const char *, int);
+
 pwm_tag_t	fdtbus_pwm_acquire(int, const char *);
 pwm_tag_t	fdtbus_pwm_acquire_index(int, const char *, int);
+
 int		fdtbus_pinctrl_set_config_index(int, u_int);
 int		fdtbus_pinctrl_set_config(int, const char *);
 bool		fdtbus_pinctrl_has_config(int, const char *);
@@ -360,7 +368,9 @@ int		fdtbus_pinctrl_parse_bias(int, int 
 int		fdtbus_pinctrl_parse_drive(int);
 int		fdtbus_pinctrl_parse_drive_strength(int);
 int		fdtbus_pinctrl_parse_input_output(int, int *);
-struct fdtbus_regulator *fdtbus_regulator_acquire(int, const char *);
+
+struct fdtbus_regulator *
+		fdtbus_regulator_acquire(int, const char *);
 void		fdtbus_regulator_release(struct fdtbus_regulator *);
 int		fdtbus_regulator_enable(struct fdtbus_regulator *);
 int		fdtbus_regulator_disable(struct fdtbus_regulator *);
@@ -370,13 +380,17 @@ int		fdtbus_regulator_get_voltage(struct
 		u_int *);
 int		fdtbus_regulator_supports_voltage(struct fdtbus_regulator *,
 		u_int, u_int);
+
 struct syscon *	fdtbus_syscon_acquire(int, const char *);
 struct syscon *	fdtbus_syscon_lookup(int);
+
 bus_dma_tag_t	fdtbus_iommu_map(int, u_int, bus_dma_tag_t);
 bus_dma_tag_t	fdtbus_iommu_map_pci(int, uint32_t, bus_dma_tag_t);
 
-struct fdtbus_dma *fdtbus_dma_get(int, const char *, void (*)(void *), void *);
-struct fdtbus_dma *fdtbus_dma_get_index(int, u_int, void (*)(void *),
+struct fdtbus_dma *
+		fdtbus_dma_get(int, const char *, void (*)(void *), void *);
+struct fdtbus_dma *
+		fdtbus_dma_get_index(int, u_int, void (*)(void *),
 		void *);
 void		fdtbus_dma_put(struct fdtbus_dma *);
 int		fdtbus_dma_transfer(struct fdtbus_dma *,
@@ -391,19 +405,24 @@ u_int		fdtbus_clock_count(int, const cha
 int		fdtbus_clock_enable(int, const char *, bool);
 int		fdtbus_clock_enable_index(int, u_int, bool);
 
-struct fdtbus_reset *fdtbus_reset_get(int, const char *);
-struct fdtbus_reset *fdtbus_reset_get_index(int, u_int);
+struct fdtbus_reset *
+		fdtbus_reset_get(int, const char *);
+struct fdtbus_reset *
+		fdtbus_reset_get_index(int, u_int);
 void		fdtbus_reset_put(struct fdtbus_reset *);
 int		fdtbus_reset_assert(struct fdtbus_reset *);
 int		fdtbus_reset_deassert(struct fdtbus_reset *);
 
-struct fdtbus_phy *fdtbus_phy_get(int, const char *);
-struct fdtbus_phy *fdtbus_phy_get_index(int, u_int);
+struct fdtbus_phy *
+		fdtbus_phy_get(int, const char *);
+struct fdtbus_phy *
+		fdtbus_phy_get_index(int, u_int);
 void		fdtbus_phy_put(struct fdtbus_phy *);
 device_t	fdtbus_phy_device(struct fdtbus_phy *);
 

CVS commit: src/sys/dev/fdt

2022-01-13 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Jan 14 07:40:52 UTC 2022

Modified Files:
src/sys/dev/fdt: fdtvar.h

Log Message:
Formatting. NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sys/dev/fdt/fdtvar.h

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



CVS commit: src/sys/dev/fdt

2022-01-06 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Jan  7 07:25:37 UTC 2022

Modified Files:
src/sys/dev/fdt: fdt_memory.c

Log Message:
Calculate the minimum address, don't assume the first entry is the start.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/fdt/fdt_memory.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/dev/fdt/fdt_memory.c
diff -u src/sys/dev/fdt/fdt_memory.c:1.3 src/sys/dev/fdt/fdt_memory.c:1.4
--- src/sys/dev/fdt/fdt_memory.c:1.3	Sat Jun 26 10:43:52 2021
+++ src/sys/dev/fdt/fdt_memory.c	Fri Jan  7 07:25:37 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_memory.c,v 1.3 2021/06/26 10:43:52 jmcneill Exp $ */
+/* $NetBSD: fdt_memory.c,v 1.4 2022/01/07 07:25:37 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include "opt_fdt.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_memory.c,v 1.3 2021/06/26 10:43:52 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_memory.c,v 1.4 2022/01/07 07:25:37 mlelstv Exp $");
 
 #include 
 #include 
@@ -90,12 +90,13 @@ fdt_memory_get(uint64_t *pstart, uint64_
 	 index++) {
 		fdt_memory_add_range(cur_addr, cur_size);
 
-		/* Assume the first entry is the start of memory */
 		if (index == 0) {
 			*pstart = cur_addr;
 			*pend = cur_addr + cur_size;
 			continue;
 		}
+		if (cur_addr < *pstart)
+			*pstart = cur_addr;
 		if (cur_addr + cur_size > *pend)
 			*pend = cur_addr + cur_size;
 	}



CVS commit: src/sys/dev/fdt

2022-01-06 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Jan  7 07:25:37 UTC 2022

Modified Files:
src/sys/dev/fdt: fdt_memory.c

Log Message:
Calculate the minimum address, don't assume the first entry is the start.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/fdt/fdt_memory.c

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



CVS commit: src/sys/dev/fdt

2021-11-12 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Nov 12 21:57:44 UTC 2021

Modified Files:
src/sys/dev/fdt: dw_apb_uart.c

Log Message:
dw_apb_uart: Honour reg-io-width property


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/fdt/dw_apb_uart.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/dev/fdt/dw_apb_uart.c
diff -u src/sys/dev/fdt/dw_apb_uart.c:1.10 src/sys/dev/fdt/dw_apb_uart.c:1.11
--- src/sys/dev/fdt/dw_apb_uart.c:1.10	Wed Jan 27 03:10:21 2021
+++ src/sys/dev/fdt/dw_apb_uart.c	Fri Nov 12 21:57:44 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dw_apb_uart.c,v 1.10 2021/01/27 03:10:21 thorpej Exp $ */
+/* $NetBSD: dw_apb_uart.c,v 1.11 2021/11/12 21:57:44 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: dw_apb_uart.c,v 1.10 2021/01/27 03:10:21 thorpej Exp $");
+__KERNEL_RCSID(1, "$NetBSD: dw_apb_uart.c,v 1.11 2021/11/12 21:57:44 jmcneill Exp $");
 
 #include 
 #include 
@@ -76,27 +76,32 @@ dw_apb_uart_attach(device_t parent, devi
 	struct dw_apb_uart_softc * const ssc = device_private(self);
 	struct com_softc * const sc = >ssc_sc;
 	struct fdt_attach_args * const faa = aux;
+	const int phandle = faa->faa_phandle;
 	bus_space_tag_t bst = faa->faa_bst;
 	bus_space_handle_t bsh;
 	char intrstr[128];
 	bus_addr_t addr;
 	bus_size_t size;
-	u_int reg_shift;
+	u_int reg_shift, reg_iowidth;
 	int error;
 
-	if (fdtbus_get_reg(faa->faa_phandle, 0, , ) != 0) {
+	if (fdtbus_get_reg(phandle, 0, , ) != 0) {
 		aprint_error(": couldn't get registers\n");
 		return;
 	}
 
-	if (of_getprop_uint32(faa->faa_phandle, "reg-shift", _shift)) {
+	if (of_getprop_uint32(phandle, "reg-shift", _shift)) {
 		/* missing or bad reg-shift property, assume 2 */
 		reg_shift = 2;
 	}
+	if (of_getprop_uint32(phandle, "reg-io-width", _iowidth)) {
+		/* missing or bad reg-io-width propery, assume 1 */
+		reg_iowidth = 1;
+	}
 
 	sc->sc_dev = self;
 
-	ssc->ssc_clk = fdtbus_clock_get_index(faa->faa_phandle, 0);
+	ssc->ssc_clk = fdtbus_clock_get_index(phandle, 0);
 	if (ssc->ssc_clk == NULL) {
 		aprint_error(": couldn't get clock\n");
 		return;
@@ -106,13 +111,13 @@ dw_apb_uart_attach(device_t parent, devi
 		return;
 	}
 
-	ssc->ssc_pclk = fdtbus_clock_get(faa->faa_phandle, "apb_pclk");
+	ssc->ssc_pclk = fdtbus_clock_get(phandle, "apb_pclk");
 	if (ssc->ssc_pclk != NULL && clk_enable(ssc->ssc_pclk) != 0) {
 		aprint_error(": couldn't enable peripheral clock\n");
 		return;
 	}
 
-	ssc->ssc_rst = fdtbus_reset_get_index(faa->faa_phandle, 0);
+	ssc->ssc_rst = fdtbus_reset_get_index(phandle, 0);
 	if (ssc->ssc_rst && fdtbus_reset_deassert(ssc->ssc_rst) != 0) {
 		aprint_error(": couldn't de-assert reset\n");
 		return;
@@ -127,16 +132,16 @@ dw_apb_uart_attach(device_t parent, devi
 		return;
 	}
 
-	com_init_regs_stride(>sc_regs, bst, bsh, addr, reg_shift);
+	com_init_regs_stride_width(>sc_regs, bst, bsh, addr, reg_shift, reg_iowidth);
 
 	com_attach_subr(sc);
 
-	if (!fdtbus_intr_str(faa->faa_phandle, 0, intrstr, sizeof(intrstr))) {
+	if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
 		aprint_error_dev(self, "failed to decode interrupt\n");
 		return;
 	}
 
-	ssc->ssc_ih = fdtbus_intr_establish_xname(faa->faa_phandle, 0,
+	ssc->ssc_ih = fdtbus_intr_establish_xname(phandle, 0,
 	IPL_SERIAL, FDT_INTR_MPSAFE, comintr, sc, device_xname(self));
 	if (ssc->ssc_ih == NULL) {
 		aprint_error_dev(self, "failed to establish interrupt on %s\n",
@@ -164,7 +169,7 @@ dw_apb_uart_console_consinit(struct fdt_
 	struct com_regs regs;
 	bus_addr_t addr;
 	tcflag_t flags;
-	u_int reg_shift;
+	u_int reg_shift, reg_iowidth;
 	int speed;
 
 	fdtbus_get_reg(phandle, 0, , NULL);
@@ -177,9 +182,13 @@ dw_apb_uart_console_consinit(struct fdt_
 		/* missing or bad reg-shift property, assume 2 */
 		reg_shift = 2;
 	}
+	if (of_getprop_uint32(phandle, "reg-io-width", _iowidth)) {
+		/* missing or bad reg-io-width propery, assume 1 */
+		reg_iowidth = 1;
+	}
 
 	memset(_bsh, 0, sizeof(dummy_bsh));
-	com_init_regs_stride(, bst, dummy_bsh, addr, reg_shift);
+	com_init_regs_stride_width(, bst, dummy_bsh, addr, reg_shift, reg_iowidth);
 
 	if (comcnattach1(, speed, uart_freq, COM_TYPE_DW_APB, flags))
 		panic("Cannot initialize dw-apb-uart console");



CVS commit: src/sys/dev/fdt

2021-11-12 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Nov 12 21:57:44 UTC 2021

Modified Files:
src/sys/dev/fdt: dw_apb_uart.c

Log Message:
dw_apb_uart: Honour reg-io-width property


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/fdt/dw_apb_uart.c

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



CVS commit: src/sys/dev/fdt

2021-11-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Nov  7 17:14:20 UTC 2021

Modified Files:
src/sys/dev/fdt: dwc3_fdt.c

Log Message:
Look for child node by compat string snps,dwc3 instead of by name.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/fdt/dwc3_fdt.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/dev/fdt/dwc3_fdt.c
diff -u src/sys/dev/fdt/dwc3_fdt.c:1.18 src/sys/dev/fdt/dwc3_fdt.c:1.19
--- src/sys/dev/fdt/dwc3_fdt.c:1.18	Tue Sep 14 22:00:11 2021
+++ src/sys/dev/fdt/dwc3_fdt.c	Sun Nov  7 17:14:20 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc3_fdt.c,v 1.18 2021/09/14 22:00:11 jmcneill Exp $ */
+/* $NetBSD: dwc3_fdt.c,v 1.19 2021/11/07 17:14:20 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwc3_fdt.c,v 1.18 2021/09/14 22:00:11 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwc3_fdt.c,v 1.19 2021/11/07 17:14:20 jmcneill Exp $");
 
 #include 
 #include 
@@ -244,7 +244,10 @@ dwc3_fdt_attach(device_t parent, device_
 
 	/* Find dwc3 sub-node */
 	if (of_compatible_lookup(phandle, compat_data_dwc3) == NULL) {
-		dwc3_phandle = of_find_firstchild_byname(phandle, "dwc3");
+		dwc3_phandle = of_find_bycompat(phandle, "snps,dwc3");
+		if (dwc3_phandle <= 0) {
+			dwc3_phandle = of_find_firstchild_byname(phandle, "dwc3");
+		}
 	} else {
 		dwc3_phandle = phandle;
 	}



CVS commit: src/sys/dev/fdt

2021-11-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Nov  7 17:14:20 UTC 2021

Modified Files:
src/sys/dev/fdt: dwc3_fdt.c

Log Message:
Look for child node by compat string snps,dwc3 instead of by name.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/fdt/dwc3_fdt.c

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



CVS commit: src/sys/dev/fdt

2021-11-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Nov  7 17:14:09 UTC 2021

Modified Files:
src/sys/dev/fdt: pwm_backlight.c

Log Message:
pwm_backlight: pick defaults if none are provided


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/fdt/pwm_backlight.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/dev/fdt/pwm_backlight.c
diff -u src/sys/dev/fdt/pwm_backlight.c:1.9 src/sys/dev/fdt/pwm_backlight.c:1.10
--- src/sys/dev/fdt/pwm_backlight.c:1.9	Wed Jan 27 03:10:21 2021
+++ src/sys/dev/fdt/pwm_backlight.c	Sun Nov  7 17:14:09 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pwm_backlight.c,v 1.9 2021/01/27 03:10:21 thorpej Exp $ */
+/* $NetBSD: pwm_backlight.c,v 1.10 2021/11/07 17:14:09 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pwm_backlight.c,v 1.9 2021/01/27 03:10:21 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pwm_backlight.c,v 1.10 2021/11/07 17:14:09 jmcneill Exp $");
 
 #include 
 #include 
@@ -86,7 +86,7 @@ pwm_backlight_attach(device_t parent, de
 	struct fdt_attach_args * const faa = aux;
 	const int phandle = faa->faa_phandle;
 	const u_int *levels;
-	u_int default_level;
+	u_int default_level = 0;
 	u_int n;
 	int len;
 
@@ -107,14 +107,18 @@ pwm_backlight_attach(device_t parent, de
 	}
 
 	levels = fdtbus_get_prop(phandle, "brightness-levels", );
-	if (len < 4) {
-		aprint_error(": couldn't get 'brightness-levels' property\n");
-		return;
+	if (levels != NULL) {
+		sc->sc_nlevels = len / 4;
+		sc->sc_levels = kmem_alloc(len, KM_SLEEP);
+		for (n = 0; n < sc->sc_nlevels; n++)
+			sc->sc_levels[n] = be32toh(levels[n]);
+	} else {
+		sc->sc_nlevels = 256;
+		sc->sc_levels = kmem_alloc(sc->sc_nlevels * 4, KM_SLEEP);
+		for (n = 0; n < sc->sc_nlevels; n++)
+			sc->sc_levels[n] = n;
+		default_level = 200;
 	}
-	sc->sc_levels = kmem_alloc(len, KM_SLEEP);
-	sc->sc_nlevels = len / 4;
-	for (n = 0; n < sc->sc_nlevels; n++)
-		sc->sc_levels[n] = be32toh(levels[n]);
 
 	aprint_naive("\n");
 	aprint_normal(": PWM Backlight");
@@ -127,7 +131,8 @@ pwm_backlight_attach(device_t parent, de
 
 	sc->sc_lid_state = true;
 
-	if (of_getprop_uint32(phandle, "default-brightness-level", _level) == 0) {
+	of_getprop_uint32(phandle, "default-brightness-level", _level);
+	if (default_level != 0) {
 		/* set the default level now */
 		pwm_backlight_set(sc, default_level, true);
 	}



CVS commit: src/sys/dev/fdt

2021-11-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Nov  7 17:14:09 UTC 2021

Modified Files:
src/sys/dev/fdt: pwm_backlight.c

Log Message:
pwm_backlight: pick defaults if none are provided


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/fdt/pwm_backlight.c

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



CVS commit: src/sys/dev/fdt

2021-11-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Nov  7 17:13:53 UTC 2021

Modified Files:
src/sys/dev/fdt: fdt_intr.c fdtvar.h

Log Message:
fdt: add helper for finding intr parent phandle


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/fdt/fdt_intr.c
cvs rdiff -u -r1.72 -r1.73 src/sys/dev/fdt/fdtvar.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/dev/fdt/fdt_intr.c
diff -u src/sys/dev/fdt/fdt_intr.c:1.29 src/sys/dev/fdt/fdt_intr.c:1.30
--- src/sys/dev/fdt/fdt_intr.c:1.29	Fri Jan 15 22:59:49 2021
+++ src/sys/dev/fdt/fdt_intr.c	Sun Nov  7 17:13:53 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_intr.c,v 1.29 2021/01/15 22:59:49 jmcneill Exp $ */
+/* $NetBSD: fdt_intr.c,v 1.30 2021/11/07 17:13:53 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_intr.c,v 1.29 2021/01/15 22:59:49 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_intr.c,v 1.30 2021/11/07 17:13:53 jmcneill Exp $");
 
 #include 
 #include 
@@ -177,6 +177,12 @@ fdtbus_put_interrupt_cookie(struct fdtbu
 	mutex_exit(_interrupt_cookie_mutex);
 }
 
+int
+fdtbus_intr_parent(int phandle)
+{
+	return fdtbus_get_interrupt_parent(phandle);
+}
+
 void *
 fdtbus_intr_establish(int phandle, u_int index, int ipl, int flags,
 int (*func)(void *), void *arg)

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.72 src/sys/dev/fdt/fdtvar.h:1.73
--- src/sys/dev/fdt/fdtvar.h:1.72	Mon Sep  6 14:03:18 2021
+++ src/sys/dev/fdt/fdtvar.h	Sun Nov  7 17:13:53 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.72 2021/09/06 14:03:18 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.73 2021/11/07 17:13:53 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -336,6 +336,7 @@ void		fdtbus_intr_unmask(int, void *);
 void		fdtbus_intr_disestablish(int, void *);
 bool		fdtbus_intr_str(int, u_int, char *, size_t);
 bool		fdtbus_intr_str_raw(int, const u_int *, char *, size_t);
+int		fdtbus_intr_parent(int);
 int		fdtbus_gpio_count(int, const char *);
 struct fdtbus_gpio_pin *fdtbus_gpio_acquire(int, const char *, int);
 struct fdtbus_gpio_pin *fdtbus_gpio_acquire_index(int, const char *, int, int);



CVS commit: src/sys/dev/fdt

2021-11-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Nov  7 17:13:53 UTC 2021

Modified Files:
src/sys/dev/fdt: fdt_intr.c fdtvar.h

Log Message:
fdt: add helper for finding intr parent phandle


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/fdt/fdt_intr.c
cvs rdiff -u -r1.72 -r1.73 src/sys/dev/fdt/fdtvar.h

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



CVS commit: src/sys/dev/fdt

2021-11-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Nov  7 17:12:26 UTC 2021

Modified Files:
src/sys/dev/fdt: pinctrl_single.c

Log Message:
pinctrl-single: support #pinctrl-cells 2


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/fdt/pinctrl_single.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/dev/fdt/pinctrl_single.c
diff -u src/sys/dev/fdt/pinctrl_single.c:1.5 src/sys/dev/fdt/pinctrl_single.c:1.6
--- src/sys/dev/fdt/pinctrl_single.c:1.5	Wed Jan 27 03:10:21 2021
+++ src/sys/dev/fdt/pinctrl_single.c	Sun Nov  7 17:12:25 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pinctrl_single.c,v 1.5 2021/01/27 03:10:21 thorpej Exp $ */
+/* $NetBSD: pinctrl_single.c,v 1.6 2021/11/07 17:12:25 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pinctrl_single.c,v 1.5 2021/01/27 03:10:21 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pinctrl_single.c,v 1.6 2021/11/07 17:12:25 jmcneill Exp $");
 
 #include 
 #include 
@@ -110,7 +110,7 @@ pinctrl_single_pins_set_config(device_t 
 	const u_int *pins;
 	int pinslen;
 
-	if (len != 4)
+	if (len != 4 && len != 8)
 		return -1;
 
 	const int phandle = fdtbus_get_phandle_from_native(be32dec(data));
@@ -119,13 +119,14 @@ pinctrl_single_pins_set_config(device_t 
 	if (pins == NULL)
 		return -1;
 
-	while (pinslen >= 8) {
+	while (pinslen >= 4 + len) {
 		const int off = be32toh(pins[0]);
 		const int val = be32toh(pins[1]);
+		const int mux = len == 4 ? 0 : be32toh(pins[2]);
 
-		pinctrl_single_pins_write(sc, off, val);
-		pins += 2;
-		pinslen -= 8;
+		pinctrl_single_pins_write(sc, off, val | mux);
+		pins += 1 + (len / 4);
+		pinslen -= (4 + len);
 	}
 
 	return 0;



CVS commit: src/sys/dev/fdt

2021-11-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Nov  7 17:12:26 UTC 2021

Modified Files:
src/sys/dev/fdt: pinctrl_single.c

Log Message:
pinctrl-single: support #pinctrl-cells 2


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/fdt/pinctrl_single.c

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



CVS commit: src/sys/dev/fdt

2021-11-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Nov  7 17:12:16 UTC 2021

Modified Files:
src/sys/dev/fdt: fdtbus.c

Log Message:
fdtbus: match simple-pm-bus


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/dev/fdt/fdtbus.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/dev/fdt/fdtbus.c
diff -u src/sys/dev/fdt/fdtbus.c:1.43 src/sys/dev/fdt/fdtbus.c:1.44
--- src/sys/dev/fdt/fdtbus.c:1.43	Mon Sep  6 14:03:18 2021
+++ src/sys/dev/fdt/fdtbus.c	Sun Nov  7 17:12:15 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtbus.c,v 1.43 2021/09/06 14:03:18 jmcneill Exp $ */
+/* $NetBSD: fdtbus.c,v 1.44 2021/11/07 17:12:15 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.43 2021/09/06 14:03:18 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.44 2021/11/07 17:12:15 jmcneill Exp $");
 
 #include 
 #include 
@@ -89,6 +89,7 @@ static void	fdt_post_attach(struct fdt_n
 
 static const struct device_compatible_entry compat_data[] = {
 	{ .compat = "simple-bus" },
+	{ .compat = "simple-pm-bus" },
 	DEVICE_COMPAT_EOL
 };
 



CVS commit: src/sys/dev/fdt

2021-11-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Nov  7 17:12:16 UTC 2021

Modified Files:
src/sys/dev/fdt: fdtbus.c

Log Message:
fdtbus: match simple-pm-bus


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/dev/fdt/fdtbus.c

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



CVS commit: src/sys/dev/fdt

2021-09-14 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Sep 14 22:00:11 UTC 2021

Modified Files:
src/sys/dev/fdt: dwc3_fdt.c

Log Message:
Remove "no IOMMU" hack.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/fdt/dwc3_fdt.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/dev/fdt/dwc3_fdt.c
diff -u src/sys/dev/fdt/dwc3_fdt.c:1.17 src/sys/dev/fdt/dwc3_fdt.c:1.18
--- src/sys/dev/fdt/dwc3_fdt.c:1.17	Mon Aug 30 22:49:42 2021
+++ src/sys/dev/fdt/dwc3_fdt.c	Tue Sep 14 22:00:11 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc3_fdt.c,v 1.17 2021/08/30 22:49:42 jmcneill Exp $ */
+/* $NetBSD: dwc3_fdt.c,v 1.18 2021/09/14 22:00:11 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwc3_fdt.c,v 1.17 2021/08/30 22:49:42 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwc3_fdt.c,v 1.18 2021/09/14 22:00:11 jmcneill Exp $");
 
 #include 
 #include 
@@ -242,12 +242,6 @@ dwc3_fdt_attach(device_t parent, device_
 	void *ih;
 	u_int n;
 
-	/* XXX IOMMUs not supported yet */
-	if (of_hasprop(phandle, "iommus")) {
-		aprint_error(": devices behind IOMMUs not supported\n");
-		return;
-	}
-
 	/* Find dwc3 sub-node */
 	if (of_compatible_lookup(phandle, compat_data_dwc3) == NULL) {
 		dwc3_phandle = of_find_firstchild_byname(phandle, "dwc3");



CVS commit: src/sys/dev/fdt

2021-09-14 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Sep 14 22:00:11 UTC 2021

Modified Files:
src/sys/dev/fdt: dwc3_fdt.c

Log Message:
Remove "no IOMMU" hack.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/fdt/dwc3_fdt.c

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



CVS commit: src/sys/dev/fdt

2021-09-04 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Sep  4 12:34:39 UTC 2021

Modified Files:
src/sys/dev/fdt: fdtvar.h files.fdt
Added Files:
src/sys/dev/fdt: fdt_iommu.c

Log Message:
Add facility for registering iommus.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/fdt_iommu.c
cvs rdiff -u -r1.70 -r1.71 src/sys/dev/fdt/fdtvar.h
cvs rdiff -u -r1.61 -r1.62 src/sys/dev/fdt/files.fdt

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

Modified files:

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.70 src/sys/dev/fdt/fdtvar.h:1.71
--- src/sys/dev/fdt/fdtvar.h:1.70	Sat Apr 24 23:36:53 2021
+++ src/sys/dev/fdt/fdtvar.h	Sat Sep  4 12:34:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.70 2021/04/24 23:36:53 thorpej Exp $ */
+/* $NetBSD: fdtvar.h,v 1.71 2021/09/04 12:34:39 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -108,6 +108,10 @@ struct fdtbus_pinctrl_controller_func {
 	int (*set_config)(device_t, const void *, size_t);
 };
 
+struct fdtbus_iommu_func {
+	bus_dma_tag_t (*map)(device_t, const u_int *, bus_dma_tag_t);
+};
+
 struct fdtbus_regulator_controller;
 
 struct fdtbus_regulator {
@@ -299,6 +303,8 @@ int		fdtbus_register_pwm_controller(devi
 int		fdtbus_register_mmc_pwrseq(device_t, int,
 		const struct fdtbus_mmc_pwrseq_func *);
 int		fdtbus_register_syscon(device_t, int, struct syscon *);
+int		fdtbus_register_iommu(device_t, int,
+		const struct fdtbus_iommu_func *);
 
 void		fdtbus_set_decoderegprop(bool);
 
@@ -363,6 +369,8 @@ int		fdtbus_regulator_supports_voltage(s
 		u_int, u_int);
 struct syscon *	fdtbus_syscon_acquire(int, const char *);
 struct syscon *	fdtbus_syscon_lookup(int);
+bus_dma_tag_t	fdtbus_iommu_map(int, u_int, bus_dma_tag_t);
+bus_dma_tag_t	fdtbus_iommu_map_pci(int, uint32_t, bus_dma_tag_t);
 
 struct fdtbus_dma *fdtbus_dma_get(int, const char *, void (*)(void *), void *);
 struct fdtbus_dma *fdtbus_dma_get_index(int, u_int, void (*)(void *),

Index: src/sys/dev/fdt/files.fdt
diff -u src/sys/dev/fdt/files.fdt:1.61 src/sys/dev/fdt/files.fdt:1.62
--- src/sys/dev/fdt/files.fdt:1.61	Mon Apr 26 15:02:29 2021
+++ src/sys/dev/fdt/files.fdt	Sat Sep  4 12:34:39 2021
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.61 2021/04/26 15:02:29 thorpej Exp $
+# $NetBSD: files.fdt,v 1.62 2021/09/04 12:34:39 jmcneill Exp $
 
 include	"external/bsd/libfdt/conf/files.libfdt"
 
@@ -72,6 +72,7 @@ file	dev/fdt/fdt_dma.c			fdt
 file	dev/fdt/fdt_ddb.c			fdt & ddb
 file	dev/fdt/fdt_gpio.c			fdt
 file	dev/fdt/fdt_i2c.c			fdt
+file	dev/fdt/fdt_iommu.c			fdt
 file	dev/fdt/fdt_intr.c			fdt
 file	dev/fdt/fdt_mmc_pwrseq.c		fdt
 file	dev/fdt/fdt_phy.c			fdt

Added files:

Index: src/sys/dev/fdt/fdt_iommu.c
diff -u /dev/null src/sys/dev/fdt/fdt_iommu.c:1.1
--- /dev/null	Sat Sep  4 12:34:39 2021
+++ src/sys/dev/fdt/fdt_iommu.c	Sat Sep  4 12:34:39 2021
@@ -0,0 +1,206 @@
+/* $NetBSD: fdt_iommu.c,v 1.1 2021/09/04 12:34:39 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2021 Jared McNeill 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: fdt_iommu.c,v 1.1 2021/09/04 12:34:39 jmcneill Exp $");
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+struct fdtbus_iommu {
+	device_t			iommu_dev;
+	intiommu_phandle;
+	const struct fdtbus_iommu_func	*iommu_funcs;
+	u_intiommu_cells;
+	LIST_ENTRY(fdtbus_iommu)	iommu_next;
+};
+
+static LIST_HEAD(, fdtbus_iommu) fdtbus_iommus =
+LIST_HEAD_INITIALIZER(fdtbus_iommus);
+
+/*
+ * fdtbus_get_iommu --
+ *
+ *	Return the iommu registered with the specified node, or NULL if
+ *	not found.
+ */
+static struct 

CVS commit: src/sys/dev/fdt

2021-09-04 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Sep  4 12:34:39 UTC 2021

Modified Files:
src/sys/dev/fdt: fdtvar.h files.fdt
Added Files:
src/sys/dev/fdt: fdt_iommu.c

Log Message:
Add facility for registering iommus.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/fdt_iommu.c
cvs rdiff -u -r1.70 -r1.71 src/sys/dev/fdt/fdtvar.h
cvs rdiff -u -r1.61 -r1.62 src/sys/dev/fdt/files.fdt

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



CVS commit: src/sys/dev/fdt

2021-08-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Aug 30 22:49:42 UTC 2021

Modified Files:
src/sys/dev/fdt: dwc3_fdt.c

Log Message:
Until we have proper FDT iommu support, refuse to attach when an iommu
is required.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/fdt/dwc3_fdt.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/dev/fdt/dwc3_fdt.c
diff -u src/sys/dev/fdt/dwc3_fdt.c:1.16 src/sys/dev/fdt/dwc3_fdt.c:1.17
--- src/sys/dev/fdt/dwc3_fdt.c:1.16	Sat Aug  7 16:19:10 2021
+++ src/sys/dev/fdt/dwc3_fdt.c	Mon Aug 30 22:49:42 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc3_fdt.c,v 1.16 2021/08/07 16:19:10 thorpej Exp $ */
+/* $NetBSD: dwc3_fdt.c,v 1.17 2021/08/30 22:49:42 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwc3_fdt.c,v 1.16 2021/08/07 16:19:10 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwc3_fdt.c,v 1.17 2021/08/30 22:49:42 jmcneill Exp $");
 
 #include 
 #include 
@@ -242,6 +242,12 @@ dwc3_fdt_attach(device_t parent, device_
 	void *ih;
 	u_int n;
 
+	/* XXX IOMMUs not supported yet */
+	if (of_hasprop(phandle, "iommus")) {
+		aprint_error(": devices behind IOMMUs not supported\n");
+		return;
+	}
+
 	/* Find dwc3 sub-node */
 	if (of_compatible_lookup(phandle, compat_data_dwc3) == NULL) {
 		dwc3_phandle = of_find_firstchild_byname(phandle, "dwc3");



CVS commit: src/sys/dev/fdt

2021-08-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Aug 30 22:49:42 UTC 2021

Modified Files:
src/sys/dev/fdt: dwc3_fdt.c

Log Message:
Until we have proper FDT iommu support, refuse to attach when an iommu
is required.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/fdt/dwc3_fdt.c

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



Re: CVS commit: src/sys/dev/fdt

2020-10-02 Thread Rin Okuyama

On 2020/10/02 22:42, Jonathan A. Kollasch wrote:

On Sun, Jul 21, 2019 at 03:57:24PM +, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Sun Jul 21 15:57:24 UTC 2019

Modified Files:
src/sys/dev/fdt: dw_apb_uart.c

Log Message:
The device cannot recognize break signal. Use + (five plus signs) as
cnmagic in the same manner with bcm2835_com.c.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/fdt/dw_apb_uart.c



This does not appear to be needed on at least one SoC (Allwinner H5).
Which SoC did you have this problem on?


Oops, you are right.

It seems that my device (Allwinner A20) did not accept break signal
because of WSDISPLAY_MULTICONS option. At that time, kernel just
ignored break signal, but today it panics instead. Anyway, by
disabling wsdisplay, I can enter DDB from console by break signal.

I will revert this commit, and request pullup to netbsd-9.

Thank you for finding it out, and I'm sorry for bothering you.

rin


Re: CVS commit: src/sys/dev/fdt

2020-10-02 Thread Jonathan A. Kollasch
On Sun, Jul 21, 2019 at 03:57:24PM +, Rin Okuyama wrote:
> Module Name:  src
> Committed By: rin
> Date: Sun Jul 21 15:57:24 UTC 2019
> 
> Modified Files:
>   src/sys/dev/fdt: dw_apb_uart.c
> 
> Log Message:
> The device cannot recognize break signal. Use + (five plus signs) as
> cnmagic in the same manner with bcm2835_com.c.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.4 -r1.5 src/sys/dev/fdt/dw_apb_uart.c
> 

This does not appear to be needed on at least one SoC (Allwinner H5).
Which SoC did you have this problem on?

Jonathan


CVS commit: src/sys/dev/fdt

2019-11-24 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Nov 24 09:34:38 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_port.c

Log Message:
Fix build


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/fdt/fdt_port.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/dev/fdt/fdt_port.c
diff -u src/sys/dev/fdt/fdt_port.c:1.3 src/sys/dev/fdt/fdt_port.c:1.4
--- src/sys/dev/fdt/fdt_port.c:1.3	Sat Nov 23 18:53:05 2019
+++ src/sys/dev/fdt/fdt_port.c	Sun Nov 24 09:34:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdt_port.c,v 1.3 2019/11/23 18:53:05 jmcneill Exp $	*/
+/*	$NetBSD: fdt_port.c,v 1.4 2019/11/24 09:34:38 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: fdt_port.c,v 1.3 2019/11/23 18:53:05 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: fdt_port.c,v 1.4 2019/11/24 09:34:38 skrll Exp $");
 
 #include 
 #include 
@@ -257,7 +257,7 @@ fdt_ports_register(struct fdt_device_por
 	int port_phandle, child;
 	int i;
 	char buf[20];
-	uint64_t id;
+	bus_addr_t id;
 
 	ports->dp_dev = self;
 	SLIST_INSERT_HEAD(_port_devices, ports, dp_list);



CVS commit: src/sys/dev/fdt

2019-11-24 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Nov 24 09:34:38 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_port.c

Log Message:
Fix build


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/fdt/fdt_port.c

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



Re: CVS commit: src/sys/dev/fdt

2019-11-23 Thread Herbert J. Skuhra
On Sat, 23 Nov 2019 19:53:05 +0100, "Jared D. McNeill" wrote:
> 
> Module Name:  src
> Committed By: jmcneill
> Date: Sat Nov 23 18:53:05 UTC 2019
> 
> Modified Files:
>   src/sys/dev/fdt: fdt_port.c
> 
> Log Message:
> Use fdtbus_get_reg to read "reg" property

Hi,

this change breaks the build (of earmv7hf) on FreeBSD:

/usr/home/herbert/source/netbsd/current/src/sys/dev/fdt/fdt_port.c: In function 
'fdt_ports_register':
/usr/home/herbert/source/netbsd/current/src/sys/dev/fdt/fdt_port.c:299:32: 
error: passing argument 3 of
 'fdtbus_get_reg' from incompatible pointer type 
[-Werror=incompatible-pointer-types]
if (fdtbus_get_reg(child, 0, , NULL) != 0) {
^~~
In file included from 
/usr/home/herbert/source/netbsd/current/src/sys/dev/fdt/fdt_port.c:49:
/usr/home/herbert/source/netbsd/current/src/sys/dev/fdt/fdtvar.h:303:33: note: 
expected 'bus_addr_t *'
{aka 'long unsigned int *'} but argument is of type 'uint64_t *' {aka 'long 
long unsigned int *'}
 int  fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *);
  ^~~~

--
Herbert


CVS commit: src/sys/dev/fdt

2019-11-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Nov 23 18:53:05 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_port.c

Log Message:
Use fdtbus_get_reg to read "reg" property


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/fdt/fdt_port.c

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



CVS commit: src/sys/dev/fdt

2019-11-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Nov 23 18:53:05 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_port.c

Log Message:
Use fdtbus_get_reg to read "reg" property


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/fdt/fdt_port.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/dev/fdt/fdt_port.c
diff -u src/sys/dev/fdt/fdt_port.c:1.2 src/sys/dev/fdt/fdt_port.c:1.3
--- src/sys/dev/fdt/fdt_port.c:1.2	Wed Jan 30 01:24:00 2019
+++ src/sys/dev/fdt/fdt_port.c	Sat Nov 23 18:53:05 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdt_port.c,v 1.2 2019/01/30 01:24:00 jmcneill Exp $	*/
+/*	$NetBSD: fdt_port.c,v 1.3 2019/11/23 18:53:05 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: fdt_port.c,v 1.2 2019/01/30 01:24:00 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: fdt_port.c,v 1.3 2019/11/23 18:53:05 jmcneill Exp $");
 
 #include 
 #include 
@@ -296,7 +296,7 @@ again:
 		}
 		if (strcmp(buf, "port") != 0)
 			continue;
-		if (fdtbus_get_reg64(child, 0, , NULL) != 0) {
+		if (fdtbus_get_reg(child, 0, , NULL) != 0) {
 			if (ports->dp_nports > 1)
 aprint_error_dev(self,
 "%s: missing reg property",



CVS commit: src/sys/dev/fdt

2019-11-17 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Nov 17 19:30:43 UTC 2019

Modified Files:
src/sys/dev/fdt: files.fdt
Added Files:
src/sys/dev/fdt: spdif_tx.c

Log Message:
Add driver for dummy spdif transmitter bindings.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/dev/fdt/files.fdt
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/spdif_tx.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/dev/fdt/files.fdt
diff -u src/sys/dev/fdt/files.fdt:1.47 src/sys/dev/fdt/files.fdt:1.48
--- src/sys/dev/fdt/files.fdt:1.47	Wed Oct 30 21:37:56 2019
+++ src/sys/dev/fdt/files.fdt	Sun Nov 17 19:30:42 2019
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.47 2019/10/30 21:37:56 jmcneill Exp $
+# $NetBSD: files.fdt,v 1.48 2019/11/17 19:30:42 jmcneill Exp $
 
 include	"external/bsd/libfdt/conf/files.libfdt"
 
@@ -98,6 +98,10 @@ device	ausoc: audiobus
 attach	ausoc at fdt
 file	dev/fdt/ausoc.causoc
 
+device	spdiftx
+attach	spdiftx at fdt
+file	dev/fdt/spdif_tx.c			spdiftx
+
 define	fdt_display_timing
 file	dev/fdt/display_timing.c		fdt_display_timing
 

Added files:

Index: src/sys/dev/fdt/spdif_tx.c
diff -u /dev/null src/sys/dev/fdt/spdif_tx.c:1.1
--- /dev/null	Sun Nov 17 19:30:43 2019
+++ src/sys/dev/fdt/spdif_tx.c	Sun Nov 17 19:30:42 2019
@@ -0,0 +1,114 @@
+/* $NetBSD: spdif_tx.c,v 1.1 2019/11/17 19:30:42 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2019 Jared McNeill 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: spdif_tx.c,v 1.1 2019/11/17 19:30:42 jmcneill Exp $");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+
+struct spdif_tx_softc {
+	device_t		sc_dev;
+	struct audio_dai_device	sc_dai;
+};
+
+static int	spdif_tx_match(device_t, cfdata_t, void *);
+static void	spdif_tx_attach(device_t, device_t, void *);
+
+static const char *compatible[] = {
+	"linux,spdif-dit",
+	NULL
+};
+
+CFATTACH_DECL_NEW(spdiftx, sizeof(struct spdif_tx_softc),
+	spdif_tx_match, spdif_tx_attach, NULL, NULL);
+
+static int
+spdif_tx_set_format(audio_dai_tag_t dai, u_int format)
+{
+	return 0;
+}
+
+static int
+spdif_tx_add_device(audio_dai_tag_t dai, audio_dai_tag_t aux)
+{
+	return 0;
+}
+
+static const struct audio_hw_if spdif_tx_hw_if = { };
+
+static audio_dai_tag_t
+spdif_tx_dai_get_tag(device_t dev, const void *data, size_t len)
+{
+	struct spdif_tx_softc * const sc = device_private(dev);
+
+	if (len != 4)
+		return NULL;
+
+	return >sc_dai;
+}
+
+static struct fdtbus_dai_controller_func spdif_tx_dai_funcs = {
+	.get_tag = spdif_tx_dai_get_tag
+};
+
+static int
+spdif_tx_match(device_t parent, cfdata_t cf, void *aux)
+{
+	struct fdt_attach_args * const faa = aux;
+
+	return of_match_compatible(faa->faa_phandle, compatible);
+}
+
+static void
+spdif_tx_attach(device_t parent, device_t self, void *aux)
+{
+	struct spdif_tx_softc * const sc = device_private(self);
+	struct fdt_attach_args * const faa = aux;
+	const int phandle = faa->faa_phandle;
+
+	sc->sc_dev = self;
+
+	aprint_naive("\n");
+	aprint_normal(": SPDIF transmitter\n");
+
+	sc->sc_dai.dai_set_format = spdif_tx_set_format;
+	sc->sc_dai.dai_add_device = spdif_tx_add_device;
+	sc->sc_dai.dai_hw_if = _tx_hw_if;
+	sc->sc_dai.dai_dev = self;
+	sc->sc_dai.dai_priv = sc;
+	fdtbus_register_dai_controller(self, phandle, _tx_dai_funcs);
+}



CVS commit: src/sys/dev/fdt

2019-11-17 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Nov 17 19:30:43 UTC 2019

Modified Files:
src/sys/dev/fdt: files.fdt
Added Files:
src/sys/dev/fdt: spdif_tx.c

Log Message:
Add driver for dummy spdif transmitter bindings.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/dev/fdt/files.fdt
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/spdif_tx.c

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



CVS commit: src/sys/dev/fdt

2019-11-16 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Nov 16 21:53:38 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_intr.c

Log Message:
be more verbose about errors.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/fdt/fdt_intr.c

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



CVS commit: src/sys/dev/fdt

2019-11-16 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Nov 16 21:53:38 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_intr.c

Log Message:
be more verbose about errors.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/fdt/fdt_intr.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/dev/fdt/fdt_intr.c
diff -u src/sys/dev/fdt/fdt_intr.c:1.22 src/sys/dev/fdt/fdt_intr.c:1.23
--- src/sys/dev/fdt/fdt_intr.c:1.22	Fri Jun 14 11:08:18 2019
+++ src/sys/dev/fdt/fdt_intr.c	Sat Nov 16 21:53:38 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_intr.c,v 1.22 2019/06/14 11:08:18 hkenken Exp $ */
+/* $NetBSD: fdt_intr.c,v 1.23 2019/11/16 21:53:38 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2015-2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_intr.c,v 1.22 2019/06/14 11:08:18 hkenken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_intr.c,v 1.23 2019/11/16 21:53:38 mlelstv Exp $");
 
 #include 
 #include 
@@ -138,8 +138,10 @@ fdtbus_intr_establish(int phandle, u_int
 	int ihandle;
 
 	specifier = get_specifier_by_index(phandle, index, );
-	if (specifier == NULL)
+	if (specifier == NULL) {
+		printf("%s: handle not found %u@%x\n",__func__,index,phandle);
 		return NULL;
+	}
 
 	return fdtbus_intr_establish_raw(ihandle, specifier, ipl,
 	flags, func, arg);
@@ -168,8 +170,10 @@ fdtbus_intr_establish_raw(int ihandle, c
 	void *ih;
 
 	ic = fdtbus_get_interrupt_controller(ihandle);
-	if (ic == NULL)
+	if (ic == NULL) {
+		printf("%s: ihandle %d is not a controller\n",__func__,ihandle);
 		return NULL;
+	}
 
 	ih = ic->ic_funcs->establish(ic->ic_dev, __UNCONST(specifier),
 	ipl, flags, func, arg);



CVS commit: src/sys/dev/fdt

2019-11-16 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Nov 16 12:47:47 UTC 2019

Modified Files:
src/sys/dev/fdt: ausoc.c

Log Message:
Set sysclk rate at set_format time, so the link set_format callback can read 
the new sysclk


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/fdt/ausoc.c

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



CVS commit: src/sys/dev/fdt

2019-11-16 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Nov 16 12:47:47 UTC 2019

Modified Files:
src/sys/dev/fdt: ausoc.c

Log Message:
Set sysclk rate at set_format time, so the link set_format callback can read 
the new sysclk


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/fdt/ausoc.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/dev/fdt/ausoc.c
diff -u src/sys/dev/fdt/ausoc.c:1.4 src/sys/dev/fdt/ausoc.c:1.5
--- src/sys/dev/fdt/ausoc.c:1.4	Wed May  8 13:40:18 2019
+++ src/sys/dev/fdt/ausoc.c	Sat Nov 16 12:47:47 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ausoc.c,v 1.4 2019/05/08 13:40:18 isaki Exp $ */
+/* $NetBSD: ausoc.c,v 1.5 2019/11/16 12:47:47 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ausoc.c,v 1.4 2019/05/08 13:40:18 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ausoc.c,v 1.5 2019/11/16 12:47:47 jmcneill Exp $");
 
 #include 
 #include 
@@ -121,8 +121,22 @@ ausoc_set_format(void *priv, int setmode
 audio_filter_reg_t *pfil, audio_filter_reg_t *rfil)
 {
 	struct ausoc_link * const link = priv;
+	const audio_params_t *params = (setmode & AUMODE_PLAY) != 0 ?
+	play : rec;
 	int error;
 
+	if (link->link_mclk_fs) {
+		const u_int rate = params->sample_rate * link->link_mclk_fs;
+		error = audio_dai_set_sysclk(link->link_codec, rate,
+		AUDIO_DAI_CLOCK_IN);
+		if (error)
+			return error;
+		error = audio_dai_set_sysclk(link->link_cpu, rate,
+		AUDIO_DAI_CLOCK_OUT);
+		if (error)
+			return error;
+	}
+
 	error = audio_dai_mi_set_format(link->link_cpu, setmode,
 	play, rec, pfil, rfil);
 	if (error)
@@ -246,20 +260,8 @@ ausoc_trigger_output(void *priv, void *s
 void (*intr)(void *), void *intrarg, const audio_params_t *params)
 {
 	struct ausoc_link * const link = priv;
-	u_int n, rate;
 	int error;
-
-	if (link->link_mclk_fs) {
-		rate = params->sample_rate * link->link_mclk_fs;
-		error = audio_dai_set_sysclk(link->link_codec, rate,
-		AUDIO_DAI_CLOCK_IN);
-		if (error)
-			goto failed;
-		error = audio_dai_set_sysclk(link->link_cpu, rate,
-		AUDIO_DAI_CLOCK_OUT);
-		if (error)
-			goto failed;
-	}
+	u_int n;
 
 	for (n = 0; n < link->link_naux; n++) {
 		error = audio_dai_trigger(link->link_aux[n], start, end,
@@ -285,20 +287,8 @@ ausoc_trigger_input(void *priv, void *st
 void (*intr)(void *), void *intrarg, const audio_params_t *params)
 {
 	struct ausoc_link * const link = priv;
-	u_int n, rate;
 	int error;
-
-	if (link->link_mclk_fs) {
-		rate = params->sample_rate * link->link_mclk_fs;
-		error = audio_dai_set_sysclk(link->link_codec, rate,
-		AUDIO_DAI_CLOCK_IN);
-		if (error)
-			goto failed;
-		error = audio_dai_set_sysclk(link->link_cpu, rate,
-		AUDIO_DAI_CLOCK_OUT);
-		if (error)
-			goto failed;
-	}
+	u_int n;
 
 	for (n = 0; n < link->link_naux; n++) {
 		error = audio_dai_trigger(link->link_aux[n], start, end,



CVS commit: src/sys/dev/fdt

2019-11-09 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Nov  9 23:28:26 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_clock.c fdtvar.h

Log Message:
Add fdtbus_clock_enable and fdtbus_clock_enable_index shortcuts


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/fdt/fdt_clock.c
cvs rdiff -u -r1.56 -r1.57 src/sys/dev/fdt/fdtvar.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/dev/fdt/fdt_clock.c
diff -u src/sys/dev/fdt/fdt_clock.c:1.9 src/sys/dev/fdt/fdt_clock.c:1.10
--- src/sys/dev/fdt/fdt_clock.c:1.9	Mon Oct 28 21:15:34 2019
+++ src/sys/dev/fdt/fdt_clock.c	Sat Nov  9 23:28:26 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_clock.c,v 1.9 2019/10/28 21:15:34 jmcneill Exp $ */
+/* $NetBSD: fdt_clock.c,v 1.10 2019/11/09 23:28:26 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_clock.c,v 1.9 2019/10/28 21:15:34 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_clock.c,v 1.10 2019/11/09 23:28:26 jmcneill Exp $");
 
 #include 
 #include 
@@ -161,6 +161,30 @@ fdtbus_clock_get(int phandle, const char
 	return fdtbus_clock_get_prop(phandle, clkname, "clock-names");
 }
 
+int
+fdtbus_clock_enable(int phandle, const char *clkname, bool required)
+{
+	struct clk *clk;
+
+	clk = fdtbus_clock_get(phandle, clkname);
+	if (clk == NULL)
+		return required ? ENOENT : 0;
+
+	return clk_enable(clk);
+}
+
+int
+fdtbus_clock_enable_index(int phandle, u_int index, bool required)
+{
+	struct clk *clk;
+
+	clk = fdtbus_clock_get_index(phandle, index);
+	if (clk == NULL)
+		return required ? ENOENT : 0;
+
+	return clk_enable(clk);
+}
+
 /*
  * Search the DT for a clock by "clock-output-names" property.
  *

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.56 src/sys/dev/fdt/fdtvar.h:1.57
--- src/sys/dev/fdt/fdtvar.h:1.56	Mon Oct 28 21:15:34 2019
+++ src/sys/dev/fdt/fdtvar.h	Sat Nov  9 23:28:26 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.56 2019/10/28 21:15:34 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.57 2019/11/09 23:28:26 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -367,6 +367,8 @@ struct clk *	fdtbus_clock_get_index(int,
 struct clk *	fdtbus_clock_byname(const char *);
 void		fdtbus_clock_assign(int);
 u_int		fdtbus_clock_count(int, const char *);
+int		fdtbus_clock_enable(int, const char *, bool);
+int		fdtbus_clock_enable_index(int, u_int, bool);
 
 struct fdtbus_reset *fdtbus_reset_get(int, const char *);
 struct fdtbus_reset *fdtbus_reset_get_index(int, u_int);



CVS commit: src/sys/dev/fdt

2019-11-09 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Nov  9 23:28:26 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_clock.c fdtvar.h

Log Message:
Add fdtbus_clock_enable and fdtbus_clock_enable_index shortcuts


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/fdt/fdt_clock.c
cvs rdiff -u -r1.56 -r1.57 src/sys/dev/fdt/fdtvar.h

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



CVS commit: src/sys/dev/fdt

2019-10-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Oct 30 21:37:56 UTC 2019

Modified Files:
src/sys/dev/fdt: files.fdt
Added Files:
src/sys/dev/fdt: usbnopphy.c

Log Message:
Add generic USB PHY driver


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/dev/fdt/files.fdt
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/usbnopphy.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/dev/fdt/files.fdt
diff -u src/sys/dev/fdt/files.fdt:1.46 src/sys/dev/fdt/files.fdt:1.47
--- src/sys/dev/fdt/files.fdt:1.46	Sun Oct 27 15:31:15 2019
+++ src/sys/dev/fdt/files.fdt	Wed Oct 30 21:37:56 2019
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.46 2019/10/27 15:31:15 jmcneill Exp $
+# $NetBSD: files.fdt,v 1.47 2019/10/30 21:37:56 jmcneill Exp $
 
 include	"external/bsd/libfdt/conf/files.libfdt"
 
@@ -153,3 +153,8 @@ file	dev/fdt/amdccp_fdt.c			amdccp_fdt
 # Arasan SDHCI controller
 attach	sdhc at fdt with arasan_sdhc_fdt
 file	dev/fdt/arasan_sdhc_fdt.c		arasan_sdhc_fdt
+
+# Generic USB PHY
+device	usbnopphy
+attach	usbnopphy at fdt
+file	dev/fdt/usbnopphy.c			usbnopphy

Added files:

Index: src/sys/dev/fdt/usbnopphy.c
diff -u /dev/null src/sys/dev/fdt/usbnopphy.c:1.1
--- /dev/null	Wed Oct 30 21:37:56 2019
+++ src/sys/dev/fdt/usbnopphy.c	Wed Oct 30 21:37:56 2019
@@ -0,0 +1,140 @@
+/* $NetBSD: usbnopphy.c,v 1.1 2019/10/30 21:37:56 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2019 Jared McNeill 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+
+__KERNEL_RCSID(0, "$NetBSD: usbnopphy.c,v 1.1 2019/10/30 21:37:56 jmcneill Exp $");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+static int usbnopphy_match(device_t, cfdata_t, void *);
+static void usbnopphy_attach(device_t, device_t, void *);
+
+static const char * const compatible[] = {
+	"usb-nop-xceiv",
+	NULL
+};
+
+struct usbnopphy_softc {
+	device_t		sc_dev;
+
+	struct clk		*sc_clk;
+	struct fdtbus_regulator *sc_reg;
+	struct fdtbus_gpio_pin	*sc_pin_reset;
+	struct fdtbus_gpio_pin	*sc_pin_vbus_det;
+};
+
+CFATTACH_DECL_NEW(usbnopphy, sizeof(struct usbnopphy_softc),
+	usbnopphy_match, usbnopphy_attach, NULL, NULL);
+
+static void *
+usbnopphy_acquire(device_t dev, const void *data, size_t len)
+{
+	struct usbnopphy_softc * const sc = device_private(dev);
+
+	return sc;
+}
+
+static void
+usbnopphy_release(device_t dev, void *priv)
+{
+}
+
+static int
+usbnopphy_enable(device_t dev, void *priv, bool enable)
+{
+	struct usbnopphy_softc * const sc = device_private(dev);
+	int error;
+
+	if (enable) {
+		if (sc->sc_reg != NULL) {
+			error = fdtbus_regulator_enable(sc->sc_reg);
+			if (error != 0)
+return error;
+		}
+		if (sc->sc_clk != NULL) {
+			error = clk_enable(sc->sc_clk);
+			if (error != 0)
+return error;
+		}
+		if (sc->sc_pin_reset != NULL) {
+			fdtbus_gpio_write(sc->sc_pin_reset, 1);
+			delay(2);
+			fdtbus_gpio_write(sc->sc_pin_reset, 0);
+		}
+	} else {
+		if (sc->sc_pin_reset != NULL)
+			fdtbus_gpio_write(sc->sc_pin_reset, 1);
+		if (sc->sc_reg != NULL)
+			fdtbus_regulator_disable(sc->sc_reg);
+		if (sc->sc_clk != NULL)
+			clk_disable(sc->sc_clk);
+	}
+
+	return 0;
+}
+
+const struct fdtbus_phy_controller_func usbnopphy_funcs = {
+	.acquire = usbnopphy_acquire,
+	.release = usbnopphy_release,
+	.enable = usbnopphy_enable,
+};
+
+static int
+usbnopphy_match(device_t parent, cfdata_t cf, void *aux)
+{
+	struct fdt_attach_args * const faa = aux;
+
+	return of_match_compatible(faa->faa_phandle, compatible);
+}
+
+static void
+usbnopphy_attach(device_t parent, device_t self, void *aux)
+{
+	

CVS commit: src/sys/dev/fdt

2019-10-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Oct 30 21:37:36 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_phy.c

Log Message:
Skip xref if it is 0


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/fdt/fdt_phy.c

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



CVS commit: src/sys/dev/fdt

2019-10-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Oct 30 21:37:56 UTC 2019

Modified Files:
src/sys/dev/fdt: files.fdt
Added Files:
src/sys/dev/fdt: usbnopphy.c

Log Message:
Add generic USB PHY driver


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/dev/fdt/files.fdt
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/usbnopphy.c

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



CVS commit: src/sys/dev/fdt

2019-10-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Oct 30 21:37:36 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_phy.c

Log Message:
Skip xref if it is 0


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/fdt/fdt_phy.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/dev/fdt/fdt_phy.c
diff -u src/sys/dev/fdt/fdt_phy.c:1.5 src/sys/dev/fdt/fdt_phy.c:1.6
--- src/sys/dev/fdt/fdt_phy.c:1.5	Wed Feb 27 16:56:00 2019
+++ src/sys/dev/fdt/fdt_phy.c	Wed Oct 30 21:37:36 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_phy.c,v 1.5 2019/02/27 16:56:00 jakllsch Exp $ */
+/* $NetBSD: fdt_phy.c,v 1.6 2019/10/30 21:37:36 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_phy.c,v 1.5 2019/02/27 16:56:00 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_phy.c,v 1.6 2019/10/30 21:37:36 jmcneill Exp $");
 
 #include 
 #include 
@@ -100,6 +100,10 @@ fdtbus_phy_get_index(int phandle, u_int 
 
 	p = phys;
 	for (n = 0, resid = len; resid > 0; n++) {
+		if (p[0] == 0) {
+			phy_cells = 0;
+			goto next;
+		}
 		const int pc_phandle =
 		fdtbus_get_phandle_from_native(be32toh(p[0]));
 		if (of_getprop_uint32(pc_phandle, "#phy-cells", _cells))
@@ -117,6 +121,7 @@ fdtbus_phy_get_index(int phandle, u_int 
 			}
 			break;
 		}
+next:
 		resid -= (phy_cells + 1) * 4;
 		p += phy_cells + 1;
 	}



CVS commit: src/sys/dev/fdt

2019-10-29 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Oct 29 10:52:22 UTC 2019

Modified Files:
src/sys/dev/fdt: cpufreq_dt.c

Log Message:
Add explicit FDT_OPP for operating-points-v2 so the link set won't be empty


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/fdt/cpufreq_dt.c

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



CVS commit: src/sys/dev/fdt

2019-10-29 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Oct 29 10:52:22 UTC 2019

Modified Files:
src/sys/dev/fdt: cpufreq_dt.c

Log Message:
Add explicit FDT_OPP for operating-points-v2 so the link set won't be empty


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/fdt/cpufreq_dt.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/dev/fdt/cpufreq_dt.c
diff -u src/sys/dev/fdt/cpufreq_dt.c:1.12 src/sys/dev/fdt/cpufreq_dt.c:1.13
--- src/sys/dev/fdt/cpufreq_dt.c:1.12	Mon Oct 28 21:14:58 2019
+++ src/sys/dev/fdt/cpufreq_dt.c	Tue Oct 29 10:52:22 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufreq_dt.c,v 1.12 2019/10/28 21:14:58 jmcneill Exp $ */
+/* $NetBSD: cpufreq_dt.c,v 1.13 2019/10/29 10:52:22 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.12 2019/10/28 21:14:58 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.13 2019/10/29 10:52:22 jmcneill Exp $");
 
 #include 
 #include 
@@ -377,6 +377,14 @@ cpufreq_dt_lookup_opp_info(const int opp
 }
 
 static bool
+cpufreq_dt_opp_v2_supported(const int opp_table, const int opp_node)
+{
+	return true;
+}
+
+FDT_OPP(opp_v2, "operating-points-v2", cpufreq_dt_opp_v2_supported);
+
+static bool
 cpufreq_dt_node_supported(const struct fdt_opp_info *opp_info, const int opp_table, const int opp_node)
 {
 	if (!fdtbus_status_okay(opp_node))
@@ -387,7 +395,7 @@ cpufreq_dt_node_supported(const struct f
 	if (opp_info != NULL)
 		return opp_info->opp_supported(opp_table, opp_node);
 
-	return true;
+	return false;
 }
 
 static int



CVS commit: src/sys/dev/fdt

2019-10-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Oct 28 21:15:34 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_clock.c fdtvar.h

Log Message:
Add fdtbus_clock_count to count the number of clock references on a given node


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/fdt/fdt_clock.c
cvs rdiff -u -r1.55 -r1.56 src/sys/dev/fdt/fdtvar.h

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



CVS commit: src/sys/dev/fdt

2019-10-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Oct 28 21:15:34 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_clock.c fdtvar.h

Log Message:
Add fdtbus_clock_count to count the number of clock references on a given node


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/fdt/fdt_clock.c
cvs rdiff -u -r1.55 -r1.56 src/sys/dev/fdt/fdtvar.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/dev/fdt/fdt_clock.c
diff -u src/sys/dev/fdt/fdt_clock.c:1.8 src/sys/dev/fdt/fdt_clock.c:1.9
--- src/sys/dev/fdt/fdt_clock.c:1.8	Wed Feb 27 16:56:00 2019
+++ src/sys/dev/fdt/fdt_clock.c	Mon Oct 28 21:15:34 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_clock.c,v 1.8 2019/02/27 16:56:00 jakllsch Exp $ */
+/* $NetBSD: fdt_clock.c,v 1.9 2019/10/28 21:15:34 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_clock.c,v 1.8 2019/02/27 16:56:00 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_clock.c,v 1.9 2019/10/28 21:15:34 jmcneill Exp $");
 
 #include 
 #include 
@@ -133,8 +133,8 @@ fdtbus_clock_get_prop(int phandle, const
 	return fdtbus_clock_get_index(phandle, index);
 }
 
-static u_int
-fdtbus_clock_count_prop(int phandle, const char *prop)
+u_int
+fdtbus_clock_count(int phandle, const char *prop)
 {
 	u_int n, clock_cells;
 	int len, resid;
@@ -207,8 +207,8 @@ fdtbus_clock_assign(int phandle)
 	if (rates == NULL)
 		rates_len = 0;
 
-	const u_int nclocks = fdtbus_clock_count_prop(phandle, "assigned-clocks");
-	const u_int nparents = fdtbus_clock_count_prop(phandle, "assigned-clock-parents");
+	const u_int nclocks = fdtbus_clock_count(phandle, "assigned-clocks");
+	const u_int nparents = fdtbus_clock_count(phandle, "assigned-clock-parents");
 	const u_int nrates = rates_len / sizeof(*rates);
 
 	for (index = 0; index < nclocks; index++) {

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.55 src/sys/dev/fdt/fdtvar.h:1.56
--- src/sys/dev/fdt/fdtvar.h:1.55	Mon Oct 28 21:14:58 2019
+++ src/sys/dev/fdt/fdtvar.h	Mon Oct 28 21:15:34 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.55 2019/10/28 21:14:58 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.56 2019/10/28 21:15:34 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -366,6 +366,7 @@ struct clk *	fdtbus_clock_get(int, const
 struct clk *	fdtbus_clock_get_index(int, u_int);
 struct clk *	fdtbus_clock_byname(const char *);
 void		fdtbus_clock_assign(int);
+u_int		fdtbus_clock_count(int, const char *);
 
 struct fdtbus_reset *fdtbus_reset_get(int, const char *);
 struct fdtbus_reset *fdtbus_reset_get_index(int, u_int);



CVS commit: src/sys/dev/fdt

2019-10-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Oct 28 21:14:58 UTC 2019

Modified Files:
src/sys/dev/fdt: cpufreq_dt.c fdtvar.h

Log Message:
Add support for platform specific opp table filters.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/fdt/cpufreq_dt.c
cvs rdiff -u -r1.54 -r1.55 src/sys/dev/fdt/fdtvar.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/dev/fdt/cpufreq_dt.c
diff -u src/sys/dev/fdt/cpufreq_dt.c:1.11 src/sys/dev/fdt/cpufreq_dt.c:1.12
--- src/sys/dev/fdt/cpufreq_dt.c:1.11	Mon Oct 28 10:43:08 2019
+++ src/sys/dev/fdt/cpufreq_dt.c	Mon Oct 28 21:14:58 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufreq_dt.c,v 1.11 2019/10/28 10:43:08 jmcneill Exp $ */
+/* $NetBSD: cpufreq_dt.c,v 1.12 2019/10/28 21:14:58 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.11 2019/10/28 10:43:08 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.12 2019/10/28 21:14:58 jmcneill Exp $");
 
 #include 
 #include 
@@ -356,11 +356,46 @@ cpufreq_dt_parse_opp(struct cpufreq_dt_s
 	return 0;
 }
 
+static const struct fdt_opp_info *
+cpufreq_dt_lookup_opp_info(const int opp_table)
+{
+	__link_set_decl(fdt_opps, struct fdt_opp_info);
+	struct fdt_opp_info * const *opp;
+	const struct fdt_opp_info *best_opp = NULL;
+	int match, best_match = 0;
+
+	__link_set_foreach(opp, fdt_opps) {
+		const char * const compat[] = { (*opp)->opp_compat, NULL };
+		match = of_match_compatible(opp_table, compat);
+		if (match > best_match) {
+			best_match = match;
+			best_opp = *opp;
+		}
+	}
+
+	return best_opp;
+}
+
+static bool
+cpufreq_dt_node_supported(const struct fdt_opp_info *opp_info, const int opp_table, const int opp_node)
+{
+	if (!fdtbus_status_okay(opp_node))
+		return false;
+	if (of_hasprop(opp_node, "opp-suspend"))
+		return false;
+
+	if (opp_info != NULL)
+		return opp_info->opp_supported(opp_table, opp_node);
+
+	return true;
+}
+
 static int
 cpufreq_dt_parse_opp_v2(struct cpufreq_dt_softc *sc)
 {
 	const int phandle = sc->sc_phandle;
 	struct cpufreq_dt_table *table;
+	const struct fdt_opp_info *opp_info;
 	const u_int *opp_uv;
 	uint64_t opp_hz;
 	int opp_node, len, i, index;
@@ -378,10 +413,10 @@ cpufreq_dt_parse_opp_v2(struct cpufreq_d
 		TAILQ_INSERT_TAIL(_dt_tables, >sc_table, next);
 	}
 
+	opp_info = cpufreq_dt_lookup_opp_info(opp_table);
+
 	for (opp_node = OF_child(opp_table); opp_node; opp_node = OF_peer(opp_node)) {
-		if (!fdtbus_status_okay(opp_node))
-			continue;
-		if (of_hasprop(opp_node, "opp-suspend"))
+		if (!cpufreq_dt_node_supported(opp_info, opp_table, opp_node))
 			continue;
 		sc->sc_nopp++;
 	}
@@ -392,9 +427,7 @@ cpufreq_dt_parse_opp_v2(struct cpufreq_d
 	sc->sc_opp = kmem_zalloc(sizeof(*sc->sc_opp) * sc->sc_nopp, KM_SLEEP);
 	index = sc->sc_nopp - 1;
 	for (opp_node = OF_child(opp_table), i = 0; opp_node; opp_node = OF_peer(opp_node), i++) {
-		if (!fdtbus_status_okay(opp_node))
-			continue;
-		if (of_hasprop(opp_node, "opp-suspend"))
+		if (!cpufreq_dt_node_supported(opp_info, opp_table, opp_node))
 			continue;
 		if (of_getprop_uint64(opp_node, "opp-hz", _hz) != 0)
 			return EINVAL;

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.54 src/sys/dev/fdt/fdtvar.h:1.55
--- src/sys/dev/fdt/fdtvar.h:1.54	Tue Oct  1 23:32:52 2019
+++ src/sys/dev/fdt/fdtvar.h	Mon Oct 28 21:14:58 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.54 2019/10/01 23:32:52 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.55 2019/10/28 21:14:58 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -251,6 +251,21 @@ static const struct fdt_console_info __C
 };	\
 _FDT_CONSOLE_REGISTER(_name)
 
+struct fdt_opp_info {
+	const char *	opp_compat;
+	bool		(*opp_supported)(const int, const int);
+};
+
+#define	_FDT_OPP_REGISTER(name)		\
+	__link_set_add_rodata(fdt_opps, __CONCAT(name,_oppinfo));
+
+#define	FDT_OPP(_name, _compat, _suppfn)\
+static const struct fdt_opp_info __CONCAT(_name,_oppinfo) = {		\
+	.opp_compat = (_compat),	\
+	.opp_supported = (_suppfn)	\
+};	\
+_FDT_OPP_REGISTER(_name)
+
 TAILQ_HEAD(fdt_conslist, fdt_console_info);
 
 int		fdtbus_register_interrupt_controller(device_t, int,



CVS commit: src/sys/dev/fdt

2019-10-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Oct 28 21:14:58 UTC 2019

Modified Files:
src/sys/dev/fdt: cpufreq_dt.c fdtvar.h

Log Message:
Add support for platform specific opp table filters.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/fdt/cpufreq_dt.c
cvs rdiff -u -r1.54 -r1.55 src/sys/dev/fdt/fdtvar.h

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



CVS commit: src/sys/dev/fdt

2019-10-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Oct 28 21:13:48 UTC 2019

Modified Files:
src/sys/dev/fdt: syscon.c

Log Message:
enumerate devices under child "clocks" node


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/fdt/syscon.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/dev/fdt/syscon.c
diff -u src/sys/dev/fdt/syscon.c:1.3 src/sys/dev/fdt/syscon.c:1.4
--- src/sys/dev/fdt/syscon.c:1.3	Mon Feb 25 19:28:36 2019
+++ src/sys/dev/fdt/syscon.c	Mon Oct 28 21:13:48 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: syscon.c,v 1.3 2019/02/25 19:28:36 jmcneill Exp $ */
+/* $NetBSD: syscon.c,v 1.4 2019/10/28 21:13:48 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: syscon.c,v 1.3 2019/02/25 19:28:36 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: syscon.c,v 1.4 2019/10/28 21:13:48 jmcneill Exp $");
 
 #include 
 #include 
@@ -113,6 +113,7 @@ syscon_attach(device_t parent, device_t 
 	const int phandle = faa->faa_phandle;
 	bus_addr_t addr;
 	bus_size_t size;
+	int child;
 
 	if (fdtbus_get_reg(phandle, 0, , ) != 0) {
 		aprint_error(": couldn't get registers\n");
@@ -138,4 +139,8 @@ syscon_attach(device_t parent, device_t 
 	fdtbus_register_syscon(self, phandle, >sc_syscon);
 
 	fdt_add_bus(self, phandle, faa);
+
+	child = of_find_firstchild_byname(phandle, "clocks");
+	if (child > 0)
+		fdt_add_bus(self, child, faa);
 }



CVS commit: src/sys/dev/fdt

2019-10-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Oct 28 21:13:48 UTC 2019

Modified Files:
src/sys/dev/fdt: syscon.c

Log Message:
enumerate devices under child "clocks" node


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/fdt/syscon.c

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



CVS commit: src/sys/dev/fdt

2019-10-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Oct 28 10:43:09 UTC 2019

Modified Files:
src/sys/dev/fdt: cpufreq_dt.c

Log Message:
Skip nodes with an "opp-suspend" property and fix tables that have disabled
nodes in the middle.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/fdt/cpufreq_dt.c

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



CVS commit: src/sys/dev/fdt

2019-10-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Oct 28 10:43:09 UTC 2019

Modified Files:
src/sys/dev/fdt: cpufreq_dt.c

Log Message:
Skip nodes with an "opp-suspend" property and fix tables that have disabled
nodes in the middle.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/fdt/cpufreq_dt.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/dev/fdt/cpufreq_dt.c
diff -u src/sys/dev/fdt/cpufreq_dt.c:1.10 src/sys/dev/fdt/cpufreq_dt.c:1.11
--- src/sys/dev/fdt/cpufreq_dt.c:1.10	Mon Oct  7 13:54:59 2019
+++ src/sys/dev/fdt/cpufreq_dt.c	Mon Oct 28 10:43:08 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufreq_dt.c,v 1.10 2019/10/07 13:54:59 martin Exp $ */
+/* $NetBSD: cpufreq_dt.c,v 1.11 2019/10/28 10:43:08 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.10 2019/10/07 13:54:59 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.11 2019/10/28 10:43:08 jmcneill Exp $");
 
 #include 
 #include 
@@ -363,7 +363,7 @@ cpufreq_dt_parse_opp_v2(struct cpufreq_d
 	struct cpufreq_dt_table *table;
 	const u_int *opp_uv;
 	uint64_t opp_hz;
-	int opp_node, len, i;
+	int opp_node, len, i, index;
 
 	const int opp_table = fdtbus_get_phandle(phandle, "operating-points-v2");
 	if (opp_table < 0)
@@ -379,27 +379,33 @@ cpufreq_dt_parse_opp_v2(struct cpufreq_d
 	}
 
 	for (opp_node = OF_child(opp_table); opp_node; opp_node = OF_peer(opp_node)) {
-		if (fdtbus_status_okay(opp_node))
-			sc->sc_nopp++;
+		if (!fdtbus_status_okay(opp_node))
+			continue;
+		if (of_hasprop(opp_node, "opp-suspend"))
+			continue;
+		sc->sc_nopp++;
 	}
 
 	if (sc->sc_nopp == 0)
 		return EINVAL;
 
 	sc->sc_opp = kmem_zalloc(sizeof(*sc->sc_opp) * sc->sc_nopp, KM_SLEEP);
+	index = sc->sc_nopp - 1;
 	for (opp_node = OF_child(opp_table), i = 0; opp_node; opp_node = OF_peer(opp_node), i++) {
 		if (!fdtbus_status_okay(opp_node))
 			continue;
+		if (of_hasprop(opp_node, "opp-suspend"))
+			continue;
 		if (of_getprop_uint64(opp_node, "opp-hz", _hz) != 0)
 			return EINVAL;
 		opp_uv = fdtbus_get_prop(opp_node, "opp-microvolt", );
 		if (opp_uv == NULL || len < 1)
 			return EINVAL;
 		/* Table is in reverse order */
-		const int index = sc->sc_nopp - i - 1;
 		sc->sc_opp[index].freq_khz = (u_int)(opp_hz / 1000);
 		sc->sc_opp[index].voltage_uv = be32toh(opp_uv[0]);
 		of_getprop_uint32(opp_node, "clock-latency-ns", >sc_opp[index].latency_ns);
+		--index;
 	}
 
 	return 0;



CVS commit: src/sys/dev/fdt

2019-10-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Oct 27 15:31:15 UTC 2019

Modified Files:
src/sys/dev/fdt: files.fdt
Added Files:
src/sys/dev/fdt: pinctrl_single.c

Log Message:
Add driver for one-register-per-pin type pinctrl devices.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/dev/fdt/files.fdt
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/pinctrl_single.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/dev/fdt/files.fdt
diff -u src/sys/dev/fdt/files.fdt:1.45 src/sys/dev/fdt/files.fdt:1.46
--- src/sys/dev/fdt/files.fdt:1.45	Tue Aug 13 16:46:49 2019
+++ src/sys/dev/fdt/files.fdt	Sun Oct 27 15:31:15 2019
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.45 2019/08/13 16:46:49 tnn Exp $
+# $NetBSD: files.fdt,v 1.46 2019/10/27 15:31:15 jmcneill Exp $
 
 include	"external/bsd/libfdt/conf/files.libfdt"
 
@@ -82,6 +82,10 @@ device	syscon { } : fdt
 attach	syscon at fdt
 file	dev/fdt/syscon.c			syscon
 
+device	pinctrl
+attach	pinctrl at fdt with pinctrl_single
+file	dev/fdt/pinctrl_single.c		pinctrl_single
+
 device	pwmbacklight
 attach	pwmbacklight at fdt
 file	dev/fdt/pwm_backlight.c			pwmbacklight

Added files:

Index: src/sys/dev/fdt/pinctrl_single.c
diff -u /dev/null src/sys/dev/fdt/pinctrl_single.c:1.1
--- /dev/null	Sun Oct 27 15:31:15 2019
+++ src/sys/dev/fdt/pinctrl_single.c	Sun Oct 27 15:31:15 2019
@@ -0,0 +1,204 @@
+/* $NetBSD: pinctrl_single.c,v 1.1 2019/10/27 15:31:15 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2019 Jared McNeill 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: pinctrl_single.c,v 1.1 2019/10/27 15:31:15 jmcneill Exp $");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define	PINCTRL_FLAG_PINCONF	__BIT(0)	/* supports generic pinconf */
+
+struct pinctrl_single_config {
+	uint32_t	flags;
+};
+
+static const struct pinctrl_single_config pinctrl_config = {
+};
+
+static const struct pinctrl_single_config pinconf_config = {
+	.flags = PINCTRL_FLAG_PINCONF
+};
+
+static const struct of_compat_data compat_data[] = {
+	{ "pinctrl-single",		(uintptr_t)_config },
+	{ "pinconf-single",		(uintptr_t)_config },
+	{ NULL }
+};
+
+struct pinctrl_single_softc {
+	device_t			sc_dev;
+	intsc_phandle;
+	bus_space_tag_t			sc_bst;
+	bus_space_handle_t		sc_bsh;
+	uint32_t			sc_flags;
+	u_intsc_regwidth;
+	u_intsc_funcmask;
+};
+
+static void
+pinctrl_single_pins_write(struct pinctrl_single_softc *sc, u_int off, u_int val)
+{
+	union {
+		uint32_t reg32;
+		uint16_t reg16;
+		uint8_t reg8;
+	} u;
+
+	aprint_debug_dev(sc->sc_dev, "writing %#x with %#x\n", off, val);
+
+	switch (sc->sc_regwidth) {
+	case 8:
+		u.reg8 = bus_space_read_1(sc->sc_bst, sc->sc_bsh, off);
+		u.reg8 &= ~sc->sc_funcmask;
+		u.reg8 |= val;
+		bus_space_write_1(sc->sc_bst, sc->sc_bsh, off, u.reg8);
+		break;
+	case 16:
+		u.reg16 = bus_space_read_2(sc->sc_bst, sc->sc_bsh, off);
+		u.reg16 &= ~sc->sc_funcmask;
+		u.reg16 |= val;
+		bus_space_write_2(sc->sc_bst, sc->sc_bsh, off, u.reg16);
+		break;
+	case 32:
+		u.reg32 = bus_space_read_4(sc->sc_bst, sc->sc_bsh, off);
+		u.reg32 &= ~sc->sc_funcmask;
+		u.reg32 |= val;
+		bus_space_write_4(sc->sc_bst, sc->sc_bsh, off, u.reg32);
+		break;
+	default:
+		device_printf(sc->sc_dev, "%s: unsupported reg width %d\n",
+		__func__, sc->sc_regwidth);
+		break;
+	}
+}
+
+static int
+pinctrl_single_pins_set_config(device_t dev, const void *data, size_t len)
+{
+	struct pinctrl_single_softc * const sc = device_private(dev);
+	const u_int *pins;
+	int pinslen;
+
+	if (len != 4)
+		return -1;
+
+	const int phandle = 

CVS commit: src/sys/dev/fdt

2019-10-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Oct 27 15:31:15 UTC 2019

Modified Files:
src/sys/dev/fdt: files.fdt
Added Files:
src/sys/dev/fdt: pinctrl_single.c

Log Message:
Add driver for one-register-per-pin type pinctrl devices.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/dev/fdt/files.fdt
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/pinctrl_single.c

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



CVS commit: src/sys/dev/fdt

2019-10-19 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Oct 19 13:08:52 UTC 2019

Modified Files:
src/sys/dev/fdt: dwcwdt_fdt.c

Log Message:
dwcwdt: make this work correctly

- sysmon_wdog.smw_period is seconds, not milliseconds
- tickle the watchdog before enabling it


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/fdt/dwcwdt_fdt.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/dev/fdt/dwcwdt_fdt.c
diff -u src/sys/dev/fdt/dwcwdt_fdt.c:1.3 src/sys/dev/fdt/dwcwdt_fdt.c:1.4
--- src/sys/dev/fdt/dwcwdt_fdt.c:1.3	Sun Oct 28 15:06:10 2018
+++ src/sys/dev/fdt/dwcwdt_fdt.c	Sat Oct 19 13:08:52 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: dwcwdt_fdt.c,v 1.3 2018/10/28 15:06:10 aymeric Exp $ */
+/* $NetBSD: dwcwdt_fdt.c,v 1.4 2019/10/19 13:08:52 tnn Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwcwdt_fdt.c,v 1.3 2018/10/28 15:06:10 aymeric Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwcwdt_fdt.c,v 1.4 2019/10/19 13:08:52 tnn Exp $");
 
 #include 
 #include 
@@ -111,8 +111,8 @@ dwcwdt_map_period(struct dwcwdt_softc *s
 
 	for (i = 0; i < __arraycount(wdt_torr); i++) {
 		const u_int ms = (u_int)uint64_t)wdt_torr[i] + 1) * 1000) / sc->sc_clkrate);
-		if (ms >= period) {
-			*aperiod = ms;
+		if (ms >= period * 1000) {
+			*aperiod = ms / 1000;
 			return i;
 		}
 	}
@@ -121,14 +121,28 @@ dwcwdt_map_period(struct dwcwdt_softc *s
 }
 
 static int
+dwcwdt_tickle(struct sysmon_wdog *smw)
+{
+	struct dwcwdt_softc * const sc = smw->smw_cookie;
+	const uint32_t crr =
+	__SHIFTIN(WDT_CRR_CNT_RESTART_MAGIC, WDT_CRR_CNT_RESTART);
+
+	WR4(sc, WDT_CRR, crr);
+
+	return 0;
+}
+
+static int
 dwcwdt_setmode(struct sysmon_wdog *smw)
 {
 	struct dwcwdt_softc * const sc = smw->smw_cookie;
 	uint32_t cr, torr;
 	int intv;
 
-	if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED)
+	if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
+		/* Watchdog can only be disarmed by a reset */
 		return EIO;
+	}
 
 	if (smw->smw_period == WDOG_PERIOD_DEFAULT)
 		smw->smw_period = DWCWDT_PERIOD_DEFAULT;
@@ -140,7 +154,7 @@ dwcwdt_setmode(struct sysmon_wdog *smw)
 
 	torr = __SHIFTIN(intv, WDT_TORR_TIMEOUT_PERIOD);
 	WR4(sc, WDT_TORR, torr);
-
+	dwcwdt_tickle(smw);
 	cr = RD4(sc, WDT_CR);
 	cr &= ~WDT_CR_RESP_MODE;
 	cr |= WDT_CR_WDT_EN;
@@ -150,18 +164,6 @@ dwcwdt_setmode(struct sysmon_wdog *smw)
 }
 
 static int
-dwcwdt_tickle(struct sysmon_wdog *smw)
-{
-	struct dwcwdt_softc * const sc = smw->smw_cookie;
-	const uint32_t crr =
-	__SHIFTIN(WDT_CRR_CNT_RESTART_MAGIC, WDT_CRR_CNT_RESTART);
-
-	WR4(sc, WDT_CRR, crr);
-
-	return 0;
-}
-
-static int
 dwcwdt_match(device_t parent, cfdata_t cf, void *aux)
 {
 	struct fdt_attach_args * const faa = aux;



CVS commit: src/sys/dev/fdt

2019-10-19 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Oct 19 13:08:52 UTC 2019

Modified Files:
src/sys/dev/fdt: dwcwdt_fdt.c

Log Message:
dwcwdt: make this work correctly

- sysmon_wdog.smw_period is seconds, not milliseconds
- tickle the watchdog before enabling it


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/fdt/dwcwdt_fdt.c

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



CVS commit: src/sys/dev/fdt

2019-10-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Oct  7 13:54:59 UTC 2019

Modified Files:
src/sys/dev/fdt: cpufreq_dt.c

Log Message:
Fix argument to fdtbus_get_reg, from Jared.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/fdt/cpufreq_dt.c

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



CVS commit: src/sys/dev/fdt

2019-10-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Oct  7 13:54:59 UTC 2019

Modified Files:
src/sys/dev/fdt: cpufreq_dt.c

Log Message:
Fix argument to fdtbus_get_reg, from Jared.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/fdt/cpufreq_dt.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/dev/fdt/cpufreq_dt.c
diff -u src/sys/dev/fdt/cpufreq_dt.c:1.9 src/sys/dev/fdt/cpufreq_dt.c:1.10
--- src/sys/dev/fdt/cpufreq_dt.c:1.9	Sun Oct  6 11:28:24 2019
+++ src/sys/dev/fdt/cpufreq_dt.c	Mon Oct  7 13:54:59 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufreq_dt.c,v 1.9 2019/10/06 11:28:24 jmcneill Exp $ */
+/* $NetBSD: cpufreq_dt.c,v 1.10 2019/10/07 13:54:59 martin Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.9 2019/10/06 11:28:24 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.10 2019/10/07 13:54:59 martin Exp $");
 
 #include 
 #include 
@@ -271,7 +271,7 @@ cpufreq_dt_init_sysctl(struct cpufreq_dt
 	const struct sysctlnode *node, *cpunode;
 	struct sysctllog *cpufreq_log = NULL;
 	struct cpu_info *ci;
-	uint64_t mpidr;
+	bus_addr_t mpidr;
 	int error, i;
 
 	if (fdtbus_get_reg(sc->sc_phandle, 0, , 0) != 0)



CVS commit: src/sys/dev/fdt

2019-10-06 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Oct  6 11:28:24 UTC 2019

Modified Files:
src/sys/dev/fdt: cpufreq_dt.c

Log Message:
Change sysctl to be named after the first CPU in the DVFS domain.

  old: machdep.cpu.frequency.*, machdep.cpufreqdt4.frequency.*
  new: machdep.cpufreq.cpu0.*, machdep.cpufreq.cpu4.*


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/fdt/cpufreq_dt.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/dev/fdt/cpufreq_dt.c
diff -u src/sys/dev/fdt/cpufreq_dt.c:1.8 src/sys/dev/fdt/cpufreq_dt.c:1.9
--- src/sys/dev/fdt/cpufreq_dt.c:1.8	Tue May 21 22:15:26 2019
+++ src/sys/dev/fdt/cpufreq_dt.c	Sun Oct  6 11:28:24 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufreq_dt.c,v 1.8 2019/05/21 22:15:26 jmcneill Exp $ */
+/* $NetBSD: cpufreq_dt.c,v 1.9 2019/10/06 11:28:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.8 2019/05/21 22:15:26 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.9 2019/10/06 11:28:24 jmcneill Exp $");
 
 #include 
 #include 
@@ -39,6 +39,7 @@ __KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -250,14 +251,36 @@ cpufreq_dt_sysctl_helper(SYSCTLFN_ARGS)
 	return error;
 }
 
+static struct cpu_info *
+cpufreq_dt_cpu_lookup(cpuid_t mpidr)
+{
+	CPU_INFO_ITERATOR cii;
+	struct cpu_info *ci;
+
+	for (CPU_INFO_FOREACH(cii, ci)) {
+		if (ci->ci_cpuid == mpidr)
+			return ci;
+	}
+
+	return NULL;
+}
+
 static void
 cpufreq_dt_init_sysctl(struct cpufreq_dt_softc *sc)
 {
-	const struct sysctlnode *node, *cpunode, *freqnode;
+	const struct sysctlnode *node, *cpunode;
 	struct sysctllog *cpufreq_log = NULL;
-	const char *cpunodename;
+	struct cpu_info *ci;
+	uint64_t mpidr;
 	int error, i;
 
+	if (fdtbus_get_reg(sc->sc_phandle, 0, , 0) != 0)
+		return;
+
+	ci = cpufreq_dt_cpu_lookup(mpidr);
+	if (ci == NULL)
+		return;
+
 	sc->sc_freq_available = kmem_zalloc(strlen(" ") * sc->sc_nopp, KM_SLEEP);
 	for (i = 0; i < sc->sc_nopp; i++) {
 		char buf[6];
@@ -265,28 +288,23 @@ cpufreq_dt_init_sysctl(struct cpufreq_dt
 		strcat(sc->sc_freq_available, buf);
 	}
 
-	if (device_unit(sc->sc_dev) == 0)
-		cpunodename = "cpu";
-	else
-		cpunodename = device_xname(sc->sc_dev);
-
 	error = sysctl_createv(_log, 0, NULL, ,
 	CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
 	NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL);
 	if (error)
 		goto sysctl_failed;
-	error = sysctl_createv(_log, 0, , ,
-	0, CTLTYPE_NODE, cpunodename, NULL,
+	error = sysctl_createv(_log, 0, , ,
+	0, CTLTYPE_NODE, "cpufreq", NULL,
 	NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
 	if (error)
 		goto sysctl_failed;
-	error = sysctl_createv(_log, 0, , ,
-	0, CTLTYPE_NODE, "frequency", NULL,
+	error = sysctl_createv(_log, 0, , ,
+	0, CTLTYPE_NODE, cpu_name(ci), NULL,
 	NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
 	if (error)
 		goto sysctl_failed;
 
-	error = sysctl_createv(_log, 0, , ,
+	error = sysctl_createv(_log, 0, , ,
 	CTLFLAG_READWRITE, CTLTYPE_INT, "target", NULL,
 	cpufreq_dt_sysctl_helper, 0, (void *)sc, 0,
 	CTL_CREATE, CTL_EOL);
@@ -294,7 +312,7 @@ cpufreq_dt_init_sysctl(struct cpufreq_dt
 		goto sysctl_failed;
 	sc->sc_node_target = node->sysctl_num;
 
-	error = sysctl_createv(_log, 0, , ,
+	error = sysctl_createv(_log, 0, , ,
 	CTLFLAG_READWRITE, CTLTYPE_INT, "current", NULL,
 	cpufreq_dt_sysctl_helper, 0, (void *)sc, 0,
 	CTL_CREATE, CTL_EOL);
@@ -302,7 +320,7 @@ cpufreq_dt_init_sysctl(struct cpufreq_dt
 		goto sysctl_failed;
 	sc->sc_node_current = node->sysctl_num;
 
-	error = sysctl_createv(_log, 0, , ,
+	error = sysctl_createv(_log, 0, , ,
 	0, CTLTYPE_STRING, "available", NULL,
 	NULL, 0, sc->sc_freq_available, 0,
 	CTL_CREATE, CTL_EOL);



CVS commit: src/sys/dev/fdt

2019-10-06 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Oct  6 11:28:24 UTC 2019

Modified Files:
src/sys/dev/fdt: cpufreq_dt.c

Log Message:
Change sysctl to be named after the first CPU in the DVFS domain.

  old: machdep.cpu.frequency.*, machdep.cpufreqdt4.frequency.*
  new: machdep.cpufreq.cpu0.*, machdep.cpufreq.cpu4.*


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/fdt/cpufreq_dt.c

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



CVS commit: src/sys/dev/fdt

2019-09-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Sep 27 20:05:53 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_pinctrl.c

Log Message:
Don't assume pinctrl-0 is the default configuration.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/fdt/fdt_pinctrl.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/dev/fdt/fdt_pinctrl.c
diff -u src/sys/dev/fdt/fdt_pinctrl.c:1.8 src/sys/dev/fdt/fdt_pinctrl.c:1.9
--- src/sys/dev/fdt/fdt_pinctrl.c:1.8	Wed Feb 27 16:56:00 2019
+++ src/sys/dev/fdt/fdt_pinctrl.c	Fri Sep 27 20:05:53 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_pinctrl.c,v 1.8 2019/02/27 16:56:00 jakllsch Exp $ */
+/* $NetBSD: fdt_pinctrl.c,v 1.9 2019/09/27 20:05:53 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_pinctrl.c,v 1.8 2019/02/27 16:56:00 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_pinctrl.c,v 1.9 2019/09/27 20:05:53 jmcneill Exp $");
 
 #include 
 #include 
@@ -142,16 +142,16 @@ fdtbus_pinctrl_configure_node(int phandl
 		fdtbus_pinctrl_configure_node(child);
 
 		/*
-		 * Set configuration 0 for this node. This may fail if the
+		 * Set default configuration for this node. This may fail if the
 		 * pinctrl provider is missing; that's OK, we will re-configure
 		 * when that provider attaches.
 		 */
 		fdtbus_get_path(child, buf, sizeof(buf));
-		error = fdtbus_pinctrl_set_config_index(child, 0);
+		error = fdtbus_pinctrl_set_config(child, "default");
 		if (error == 0)
-			aprint_debug("pinctrl: set config pinctrl-0 for %s\n", buf);
+			aprint_debug("pinctrl: set default config for %s\n", buf);
 		else if (error != ENOENT)
-			aprint_debug("pinctrl: failed to set config pinctrl-0 for %s: %d\n", buf, error);
+			aprint_debug("pinctrl: failed to set default config for %s: %d\n", buf, error);
 	}
 }
 



CVS commit: src/sys/dev/fdt

2019-09-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Sep 27 20:05:53 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_pinctrl.c

Log Message:
Don't assume pinctrl-0 is the default configuration.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/fdt/fdt_pinctrl.c

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



CVS commit: src/sys/dev/fdt

2019-09-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Sep 24 15:23:34 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_subr.c

Log Message:
Use correct #cells for parent address when decoding ranges


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/dev/fdt/fdt_subr.c

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



CVS commit: src/sys/dev/fdt

2019-08-13 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Tue Aug 13 16:46:49 UTC 2019

Modified Files:
src/sys/dev/fdt: fdtvar.h files.fdt
Added Files:
src/sys/dev/fdt: fdt_spi.c

Log Message:
fdt: add SPI controller frontend


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/fdt_spi.c
cvs rdiff -u -r1.52 -r1.53 src/sys/dev/fdt/fdtvar.h
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/fdt/files.fdt

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



CVS commit: src/sys/dev/fdt

2019-08-13 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Tue Aug 13 16:46:49 UTC 2019

Modified Files:
src/sys/dev/fdt: fdtvar.h files.fdt
Added Files:
src/sys/dev/fdt: fdt_spi.c

Log Message:
fdt: add SPI controller frontend


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/fdt_spi.c
cvs rdiff -u -r1.52 -r1.53 src/sys/dev/fdt/fdtvar.h
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/fdt/files.fdt

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

Modified files:

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.52 src/sys/dev/fdt/fdtvar.h:1.53
--- src/sys/dev/fdt/fdtvar.h:1.52	Fri Jun 14 11:08:18 2019
+++ src/sys/dev/fdt/fdtvar.h	Tue Aug 13 16:46:49 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.52 2019/06/14 11:08:18 hkenken Exp $ */
+/* $NetBSD: fdtvar.h,v 1.53 2019/08/13 16:46:49 tnn Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -82,6 +82,10 @@ struct fdtbus_i2c_controller_func {
 	i2c_tag_t (*get_tag)(device_t);
 };
 
+struct fdtbus_spi_controller_func {
+	struct spi_controller *	(*get_controller)(device_t);
+};
+
 struct fdtbus_gpio_controller;
 
 struct fdtbus_gpio_pin {
@@ -253,6 +257,8 @@ int		fdtbus_register_interrupt_controlle
 		const struct fdtbus_interrupt_controller_func *);
 int		fdtbus_register_i2c_controller(device_t, int,
 		const struct fdtbus_i2c_controller_func *);
+int		fdtbus_register_spi_controller(device_t, int,
+		const struct fdtbus_spi_controller_func *);
 int		fdtbus_register_gpio_controller(device_t, int,
 		const struct fdtbus_gpio_controller_func *);
 int		fdtbus_register_pinctrl_config(device_t, int,
@@ -370,6 +376,7 @@ void		fdtbus_power_reset(void);
 void		fdtbus_power_poweroff(void);
 
 device_t	fdtbus_attach_i2cbus(device_t, int, i2c_tag_t, cfprint_t);
+device_t	fdtbus_attach_spibus(device_t, int, cfprint_t);
 
 bool		fdtbus_set_data(const void *);
 const void *	fdtbus_get_data(void);

Index: src/sys/dev/fdt/files.fdt
diff -u src/sys/dev/fdt/files.fdt:1.44 src/sys/dev/fdt/files.fdt:1.45
--- src/sys/dev/fdt/files.fdt:1.44	Wed Mar 13 12:17:45 2019
+++ src/sys/dev/fdt/files.fdt	Tue Aug 13 16:46:49 2019
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.44 2019/03/13 12:17:45 jmcneill Exp $
+# $NetBSD: files.fdt,v 1.45 2019/08/13 16:46:49 tnn Exp $
 
 include	"external/bsd/libfdt/conf/files.libfdt"
 
@@ -64,6 +64,7 @@ file	dev/fdt/fdt_pwm.c			fdt
 file	dev/fdt/fdt_regulator.c			fdt
 file	dev/fdt/fdt_reset.c			fdt
 file	dev/fdt/fdt_rtc.c			fdt
+file	dev/fdt/fdt_spi.c			fdt
 file	dev/fdt/fdt_syscon.c			fdt
 file	dev/fdt/fdt_pinctrl.c			fdt
 

Added files:

Index: src/sys/dev/fdt/fdt_spi.c
diff -u /dev/null src/sys/dev/fdt/fdt_spi.c:1.1
--- /dev/null	Tue Aug 13 16:46:50 2019
+++ src/sys/dev/fdt/fdt_spi.c	Tue Aug 13 16:46:49 2019
@@ -0,0 +1,114 @@
+/* $NetBSD: fdt_spi.c,v 1.1 2019/08/13 16:46:49 tnn Exp $ */
+
+/*
+ * Copyright (c) 2019 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Tobias Nygren.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: fdt_spi.c,v 1.1 2019/08/13 16:46:49 tnn Exp $");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct fdtbus_spi_controller {
+	device_t spi_dev;
+	int spi_phandle;
+	const struct fdtbus_spi_controller_func *spi_funcs;
+	LIST_ENTRY(fdtbus_spi_controller) spi_next;
+};
+
+static LIST_HEAD(, fdtbus_spi_controller) fdtbus_spi_controllers =
+LIST_HEAD_INITIALIZER(fdtbus_spi_controllers);
+
+int
+fdtbus_register_spi_controller(device_t dev, int phandle,
+const 

CVS commit: src/sys/dev/fdt

2019-07-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Jul 21 15:57:24 UTC 2019

Modified Files:
src/sys/dev/fdt: dw_apb_uart.c

Log Message:
The device cannot recognize break signal. Use + (five plus signs) as
cnmagic in the same manner with bcm2835_com.c.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/fdt/dw_apb_uart.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/dev/fdt/dw_apb_uart.c
diff -u src/sys/dev/fdt/dw_apb_uart.c:1.4 src/sys/dev/fdt/dw_apb_uart.c:1.5
--- src/sys/dev/fdt/dw_apb_uart.c:1.4	Sat Dec  8 17:46:13 2018
+++ src/sys/dev/fdt/dw_apb_uart.c	Sun Jul 21 15:57:23 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: dw_apb_uart.c,v 1.4 2018/12/08 17:46:13 thorpej Exp $ */
+/* $NetBSD: dw_apb_uart.c,v 1.5 2019/07/21 15:57:23 rin Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: dw_apb_uart.c,v 1.4 2018/12/08 17:46:13 thorpej Exp $");
+__KERNEL_RCSID(1, "$NetBSD: dw_apb_uart.c,v 1.5 2019/07/21 15:57:23 rin Exp $");
 
 #include 
 #include 
@@ -182,6 +182,8 @@ dw_apb_uart_console_consinit(struct fdt_
 
 	if (comcnattach(bst, addr, speed, uart_freq, COM_TYPE_DW_APB, flags))
 		panic("Cannot initialize dw-apb-uart console");
+
+	cn_set_magic("+");
 }
 
 static const struct fdt_console dw_apb_uart_console = {



CVS commit: src/sys/dev/fdt

2019-07-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Jul 21 15:57:24 UTC 2019

Modified Files:
src/sys/dev/fdt: dw_apb_uart.c

Log Message:
The device cannot recognize break signal. Use + (five plus signs) as
cnmagic in the same manner with bcm2835_com.c.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/fdt/dw_apb_uart.c

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



CVS commit: src/sys/dev/fdt

2019-07-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jul  3 23:10:43 UTC 2019

Modified Files:
src/sys/dev/fdt: arasan_sdhc_fdt.c

Log Message:
Add SDHC_FLAG_SINGLE_POWER_WRITE and SDHC_FLAG_32BIT_ACCESS flags


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/fdt/arasan_sdhc_fdt.c

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



CVS commit: src/sys/dev/fdt

2019-07-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jul  3 23:10:43 UTC 2019

Modified Files:
src/sys/dev/fdt: arasan_sdhc_fdt.c

Log Message:
Add SDHC_FLAG_SINGLE_POWER_WRITE and SDHC_FLAG_32BIT_ACCESS flags


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/fdt/arasan_sdhc_fdt.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/dev/fdt/arasan_sdhc_fdt.c
diff -u src/sys/dev/fdt/arasan_sdhc_fdt.c:1.2 src/sys/dev/fdt/arasan_sdhc_fdt.c:1.3
--- src/sys/dev/fdt/arasan_sdhc_fdt.c:1.2	Wed Jul  3 19:46:02 2019
+++ src/sys/dev/fdt/arasan_sdhc_fdt.c	Wed Jul  3 23:10:43 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: arasan_sdhc_fdt.c,v 1.2 2019/07/03 19:46:02 jmcneill Exp $ */
+/* $NetBSD: arasan_sdhc_fdt.c,v 1.3 2019/07/03 23:10:43 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: arasan_sdhc_fdt.c,v 1.2 2019/07/03 19:46:02 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arasan_sdhc_fdt.c,v 1.3 2019/07/03 23:10:43 jmcneill Exp $");
 
 #include 
 #include 
@@ -279,6 +279,8 @@ arasan_sdhc_attach(device_t parent, devi
 	sc->sc_base.sc_dev = self;
 	sc->sc_base.sc_host = sc->sc_host;
 	sc->sc_base.sc_flags = SDHC_FLAG_NO_CLKBASE |
+			   SDHC_FLAG_SINGLE_POWER_WRITE |
+			   SDHC_FLAG_32BIT_ACCESS |
 			   SDHC_FLAG_USE_DMA |
 			   SDHC_FLAG_USE_ADMA2 |
 			   SDHC_FLAG_STOP_WITH_TC;



CVS commit: src/sys/dev/fdt

2019-07-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jul  3 19:46:02 UTC 2019

Modified Files:
src/sys/dev/fdt: arasan_sdhc_fdt.c

Log Message:
Enforce 32-bit limits on ADMA2 capable controllers that do not support 64-bit 
descriptors


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/fdt/arasan_sdhc_fdt.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/dev/fdt/arasan_sdhc_fdt.c
diff -u src/sys/dev/fdt/arasan_sdhc_fdt.c:1.1 src/sys/dev/fdt/arasan_sdhc_fdt.c:1.2
--- src/sys/dev/fdt/arasan_sdhc_fdt.c:1.1	Wed Mar 13 12:17:45 2019
+++ src/sys/dev/fdt/arasan_sdhc_fdt.c	Wed Jul  3 19:46:02 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: arasan_sdhc_fdt.c,v 1.1 2019/03/13 12:17:45 jmcneill Exp $ */
+/* $NetBSD: arasan_sdhc_fdt.c,v 1.2 2019/07/03 19:46:02 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: arasan_sdhc_fdt.c,v 1.1 2019/03/13 12:17:45 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arasan_sdhc_fdt.c,v 1.2 2019/07/03 19:46:02 jmcneill Exp $");
 
 #include 
 #include 
@@ -224,6 +224,7 @@ arasan_sdhc_attach(device_t parent, devi
 	bus_addr_t addr;
 	bus_size_t size;
 	u_int bus_width;
+	int error;
 	void *ih;
 
 	fdtbus_clock_assign(phandle);
@@ -263,8 +264,19 @@ arasan_sdhc_attach(device_t parent, devi
 	sc->sc_bsz = size;
 	sc->sc_type = of_search_compatible(phandle, compat_data)->data;
 
+	const uint32_t caps = bus_space_read_4(sc->sc_bst, sc->sc_bsh, SDHC_CAPABILITIES);
+	if ((caps & (SDHC_ADMA2_SUPP|SDHC_64BIT_SYS_BUS)) == SDHC_ADMA2_SUPP) {
+		error = bus_dmatag_subregion(faa->faa_dmat, 0, 0x,
+		>sc_base.sc_dmat, BUS_DMA_WAITOK);
+		if (error != 0) {
+			aprint_error(": couldn't create DMA tag: %d\n", error);
+			return;
+		}
+	} else {
+		sc->sc_base.sc_dmat = faa->faa_dmat;
+	}
+
 	sc->sc_base.sc_dev = self;
-	sc->sc_base.sc_dmat = faa->faa_dmat;
 	sc->sc_base.sc_host = sc->sc_host;
 	sc->sc_base.sc_flags = SDHC_FLAG_NO_CLKBASE |
 			   SDHC_FLAG_USE_DMA |



CVS commit: src/sys/dev/fdt

2019-07-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jul  3 19:46:02 UTC 2019

Modified Files:
src/sys/dev/fdt: arasan_sdhc_fdt.c

Log Message:
Enforce 32-bit limits on ADMA2 capable controllers that do not support 64-bit 
descriptors


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/fdt/arasan_sdhc_fdt.c

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



CVS commit: src/sys/dev/fdt

2019-06-14 Thread Kenichi Hashimoto
Module Name:src
Committed By:   hkenken
Date:   Fri Jun 14 11:08:18 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_intr.c fdt_subr.c fdtvar.h

Log Message:
Add support "interrupts-extended".

* fdtbus_get_phandle_with_data().
  Add utility subroutine to get phandle with data.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/fdt/fdt_intr.c
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/fdt/fdt_subr.c
cvs rdiff -u -r1.51 -r1.52 src/sys/dev/fdt/fdtvar.h

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



CVS commit: src/sys/dev/fdt

2019-06-14 Thread Kenichi Hashimoto
Module Name:src
Committed By:   hkenken
Date:   Fri Jun 14 11:08:18 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_intr.c fdt_subr.c fdtvar.h

Log Message:
Add support "interrupts-extended".

* fdtbus_get_phandle_with_data().
  Add utility subroutine to get phandle with data.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/fdt/fdt_intr.c
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/fdt/fdt_subr.c
cvs rdiff -u -r1.51 -r1.52 src/sys/dev/fdt/fdtvar.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/dev/fdt/fdt_intr.c
diff -u src/sys/dev/fdt/fdt_intr.c:1.21 src/sys/dev/fdt/fdt_intr.c:1.22
--- src/sys/dev/fdt/fdt_intr.c:1.21	Wed Feb 27 17:01:57 2019
+++ src/sys/dev/fdt/fdt_intr.c	Fri Jun 14 11:08:18 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_intr.c,v 1.21 2019/02/27 17:01:57 jakllsch Exp $ */
+/* $NetBSD: fdt_intr.c,v 1.22 2019/06/14 11:08:18 hkenken Exp $ */
 
 /*-
  * Copyright (c) 2015-2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_intr.c,v 1.21 2019/02/27 17:01:57 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_intr.c,v 1.22 2019/06/14 11:08:18 hkenken Exp $");
 
 #include 
 #include 
@@ -322,12 +322,31 @@ done:
 	return result;
 }
 
+
+static const u_int *
+get_specifier_from_extended(int phandle, int pindex, int *piphandle)
+{
+	const u_int *result = NULL;
+	struct fdt_phandle_data data;
+
+	if (fdtbus_get_phandle_with_data(phandle, "interrupts-extended",
+		"#interrupt-cells", pindex, ) == 0) {
+		*piphandle = data.phandle;
+		result = data.values;
+	}
+
+	return result;
+}
+
 static const u_int *
 get_specifier_by_index(int phandle, int pindex, int *piphandle)
 {
 	const u_int *node_specifier;
 	int interrupt_parent, interrupt_cells, len;
 
+	if (of_hasprop(phandle, "interrupts-extended"))
+		return get_specifier_from_extended(phandle, pindex, piphandle);
+
 	interrupt_parent = fdtbus_get_interrupt_parent(phandle);
 	if (interrupt_parent <= 0)
 		return NULL;

Index: src/sys/dev/fdt/fdt_subr.c
diff -u src/sys/dev/fdt/fdt_subr.c:1.29 src/sys/dev/fdt/fdt_subr.c:1.30
--- src/sys/dev/fdt/fdt_subr.c:1.29	Wed Feb 27 16:56:00 2019
+++ src/sys/dev/fdt/fdt_subr.c	Fri Jun 14 11:08:18 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_subr.c,v 1.29 2019/02/27 16:56:00 jakllsch Exp $ */
+/* $NetBSD: fdt_subr.c,v 1.30 2019/06/14 11:08:18 hkenken Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.29 2019/02/27 16:56:00 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.30 2019/06/14 11:08:18 hkenken Exp $");
 
 #include "opt_fdt.h"
 
@@ -130,6 +130,42 @@ fdtbus_get_phandle(int phandle, const ch
 }
 
 int
+fdtbus_get_phandle_with_data(int phandle, const char *prop, const char *cells,
+int index, struct fdt_phandle_data *data)
+{
+	int len;
+	const int offset = 1;
+
+	const u_int *p = fdtbus_get_prop(phandle, prop, );
+	if (p == NULL || len <= 0)
+		return EINVAL;
+
+	for (int i = 0; len > 0; i++) {
+		u_int phandle_ref = be32toh(*p);
+		const u_int iparent = fdtbus_get_phandle_from_native(phandle_ref);
+		uint32_t cells_num;
+		of_getprop_uint32(iparent, cells, _num);
+
+		if (index == i) {
+			if (data != NULL) {
+data->phandle = iparent;
+data->count = cells_num;
+data->values = p + offset;
+			}
+			goto done;
+		}
+
+		const u_int reclen = offset + cells_num;
+		len -= reclen * sizeof(u_int);
+		p += reclen;
+	}
+	return EINVAL;
+
+done:
+	return 0;
+}
+
+int
 fdtbus_get_phandle_from_native(int phandle)
 {
 	const int off = fdt_node_offset_by_phandle(fdt_data, phandle);

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.51 src/sys/dev/fdt/fdtvar.h:1.52
--- src/sys/dev/fdt/fdtvar.h:1.51	Wed May  8 13:40:18 2019
+++ src/sys/dev/fdt/fdtvar.h	Fri Jun 14 11:08:18 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.51 2019/05/08 13:40:18 isaki Exp $ */
+/* $NetBSD: fdtvar.h,v 1.52 2019/06/14 11:08:18 hkenken Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -232,6 +232,12 @@ struct fdt_console_info {
 	const struct fdt_console *ops;
 };
 
+struct fdt_phandle_data {
+	int phandle;
+	int count;
+	const u_int *values;
+};
+
 #define	_FDT_CONSOLE_REGISTER(name)	\
 	__link_set_add_rodata(fdt_consoles, __CONCAT(name,_consinfo));
 
@@ -278,6 +284,8 @@ int		fdtbus_get_reg_byname(int, const ch
 		bus_size_t *);
 int		fdtbus_get_reg64(int, u_int, uint64_t *, uint64_t *);
 int		fdtbus_get_phandle(int, const char *);
+int		fdtbus_get_phandle_with_data(int, const char *, const char *,
+		int, struct fdt_phandle_data *);
 int		fdtbus_get_phandle_from_native(int);
 i2c_tag_t	fdtbus_get_i2c_tag(int);
 i2c_tag_t	fdtbus_i2c_acquire(int, const char *);



CVS commit: src/sys/dev/fdt

2019-05-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon May 27 23:18:33 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_regulator.c

Log Message:
Honour regulator-enable-ramp-delay


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/fdt/fdt_regulator.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/dev/fdt/fdt_regulator.c
diff -u src/sys/dev/fdt/fdt_regulator.c:1.7 src/sys/dev/fdt/fdt_regulator.c:1.8
--- src/sys/dev/fdt/fdt_regulator.c:1.7	Wed Jan  2 18:38:43 2019
+++ src/sys/dev/fdt/fdt_regulator.c	Mon May 27 23:18:33 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_regulator.c,v 1.7 2019/01/02 18:38:43 jmcneill Exp $ */
+/* $NetBSD: fdt_regulator.c,v 1.8 2019/05/27 23:18:33 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_regulator.c,v 1.7 2019/01/02 18:38:43 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_regulator.c,v 1.8 2019/05/27 23:18:33 jmcneill Exp $");
 
 #include 
 #include 
@@ -42,6 +42,8 @@ struct fdtbus_regulator_controller {
 	int rc_phandle;
 	const struct fdtbus_regulator_controller_func *rc_funcs;
 
+	u_int rc_enable_ramp_delay;
+
 	LIST_ENTRY(fdtbus_regulator_controller) rc_next;
 };
 
@@ -54,11 +56,13 @@ fdtbus_register_regulator_controller(dev
 {
 	struct fdtbus_regulator_controller *rc;
 
-	rc = kmem_alloc(sizeof(*rc), KM_SLEEP);
+	rc = kmem_zalloc(sizeof(*rc), KM_SLEEP);
 	rc->rc_dev = dev;
 	rc->rc_phandle = phandle;
 	rc->rc_funcs = funcs;
 
+	of_getprop_uint32(phandle, "regulator-enable-ramp-delay", >rc_enable_ramp_delay);
+
 	LIST_INSERT_HEAD(_regulator_controllers, rc, rc_next);
 
 	return 0;
@@ -121,8 +125,16 @@ int
 fdtbus_regulator_enable(struct fdtbus_regulator *reg)
 {
 	struct fdtbus_regulator_controller *rc = reg->reg_rc;
+	int error;
 
-	return rc->rc_funcs->enable(rc->rc_dev, true);
+	error = rc->rc_funcs->enable(rc->rc_dev, true);
+	if (error != 0)
+		return error;
+
+	if (rc->rc_enable_ramp_delay != 0)
+		delay(rc->rc_enable_ramp_delay);
+
+	return 0;
 }
 
 int



CVS commit: src/sys/dev/fdt

2019-05-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon May 27 23:18:33 UTC 2019

Modified Files:
src/sys/dev/fdt: fdt_regulator.c

Log Message:
Honour regulator-enable-ramp-delay


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/fdt/fdt_regulator.c

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



CVS commit: src/sys/dev/fdt

2019-05-25 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat May 25 19:21:34 UTC 2019

Modified Files:
src/sys/dev/fdt: fdtbus.c

Log Message:
Restore "not configured" autoconfiguration prints by using config_found_sm_loc 
on the default pass


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/fdt/fdtbus.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/dev/fdt/fdtbus.c
diff -u src/sys/dev/fdt/fdtbus.c:1.28 src/sys/dev/fdt/fdtbus.c:1.29
--- src/sys/dev/fdt/fdtbus.c:1.28	Mon May 20 11:12:10 2019
+++ src/sys/dev/fdt/fdtbus.c	Sat May 25 19:21:34 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtbus.c,v 1.28 2019/05/20 11:12:10 jmcneill Exp $ */
+/* $NetBSD: fdtbus.c,v 1.29 2019/05/25 19:21:34 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.28 2019/05/20 11:12:10 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.29 2019/05/25 19:21:34 jmcneill Exp $");
 
 #include 
 #include 
@@ -290,24 +290,39 @@ fdt_scan(struct fdt_softc *sc, int pass)
 	char buf[FDT_MAX_PATH];
 
 	TAILQ_FOREACH(node, _nodes, n_nodes) {
-		if (node->n_dev != NULL || node->n_cf == NULL)
+		if (node->n_dev != NULL)
 			continue;
 
 		fdt_init_attach_args(>sc_faa, node, quiet, );
 
-		/*
-		 * Make sure we don't attach before a better match in a later pass.
-		 */
-		cfdata_t cf_pass =
-		config_search_loc(fdt_scan_submatch, node->n_bus, "fdt", locs, );
-		if (node->n_cf != cf_pass)
-			continue;
+		if (quiet) {
+			/*
+			 * No match for this device, skip it.
+			 */
+			if (node->n_cf == NULL)
+continue;
+
+			/*
+			 * Make sure we don't attach before a better match in a later pass.
+			 */
+			cfdata_t cf_pass =
+			config_search_loc(fdt_scan_submatch, node->n_bus, "fdt", locs, );
+			if (node->n_cf != cf_pass)
+continue;
+
+			/*
+			 * Attach the device.
+			 */
+			node->n_dev = config_attach_loc(node->n_bus, cf_pass, locs,
+			, fdtbus_print);
+		} else {
+			/*
+			 * Default pass.
+			 */
+			node->n_dev = config_found_sm_loc(node->n_bus, "fdt", locs,
+			, fdtbus_print, fdt_scan_submatch);
+		}
 
-		/*
-		 * Attach the device.
-		 */
-		node->n_dev = config_attach_loc(node->n_bus, cf_pass, locs,
-		, fdtbus_print);
 		if (node->n_dev) {
 			dict = device_properties(node->n_dev);
 			if (fdtbus_get_path(node->n_phandle, buf, sizeof(buf)))



CVS commit: src/sys/dev/fdt

2019-05-25 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat May 25 19:21:34 UTC 2019

Modified Files:
src/sys/dev/fdt: fdtbus.c

Log Message:
Restore "not configured" autoconfiguration prints by using config_found_sm_loc 
on the default pass


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/fdt/fdtbus.c

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



CVS commit: src/sys/dev/fdt

2019-05-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu May 23 21:36:26 UTC 2019

Modified Files:
src/sys/dev/fdt: fixedregulator.c

Log Message:
Revert previous


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/fdt/fixedregulator.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/dev/fdt/fixedregulator.c
diff -u src/sys/dev/fdt/fixedregulator.c:1.7 src/sys/dev/fdt/fixedregulator.c:1.8
--- src/sys/dev/fdt/fixedregulator.c:1.7	Thu May 23 20:49:44 2019
+++ src/sys/dev/fdt/fixedregulator.c	Thu May 23 21:36:26 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fixedregulator.c,v 1.7 2019/05/23 20:49:44 jmcneill Exp $ */
+/* $NetBSD: fixedregulator.c,v 1.8 2019/05/23 21:36:26 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fixedregulator.c,v 1.7 2019/05/23 20:49:44 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fixedregulator.c,v 1.8 2019/05/23 21:36:26 jmcneill Exp $");
 
 #include 
 #include 
@@ -164,13 +164,13 @@ fixedregulator_enable(device_t dev, bool
 
 	if (enable) {
 		if (sc->sc_pin != NULL)
-			fdtbus_gpio_write(sc->sc_pin, sc->sc_enable_val);
+			fdtbus_gpio_write_raw(sc->sc_pin, sc->sc_enable_val);
 		if (sc->sc_delay > 0)
 			delay(sc->sc_delay);
 	} else {
 		if (sc->sc_always_on)
 			return EIO;
-		fdtbus_gpio_write(sc->sc_pin, !sc->sc_enable_val);
+		fdtbus_gpio_write_raw(sc->sc_pin, !sc->sc_enable_val);
 	}
 	return 0;
 }



CVS commit: src/sys/dev/fdt

2019-05-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu May 23 21:36:26 UTC 2019

Modified Files:
src/sys/dev/fdt: fixedregulator.c

Log Message:
Revert previous


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/fdt/fixedregulator.c

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



CVS commit: src/sys/dev/fdt

2019-05-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu May 23 20:49:44 UTC 2019

Modified Files:
src/sys/dev/fdt: fixedregulator.c

Log Message:
Honour the polarity of the pin xref


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/fdt/fixedregulator.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/dev/fdt/fixedregulator.c
diff -u src/sys/dev/fdt/fixedregulator.c:1.6 src/sys/dev/fdt/fixedregulator.c:1.7
--- src/sys/dev/fdt/fixedregulator.c:1.6	Sun Jan 28 18:21:52 2018
+++ src/sys/dev/fdt/fixedregulator.c	Thu May 23 20:49:44 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fixedregulator.c,v 1.6 2018/01/28 18:21:52 jmcneill Exp $ */
+/* $NetBSD: fixedregulator.c,v 1.7 2019/05/23 20:49:44 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fixedregulator.c,v 1.6 2018/01/28 18:21:52 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fixedregulator.c,v 1.7 2019/05/23 20:49:44 jmcneill Exp $");
 
 #include 
 #include 
@@ -164,13 +164,13 @@ fixedregulator_enable(device_t dev, bool
 
 	if (enable) {
 		if (sc->sc_pin != NULL)
-			fdtbus_gpio_write_raw(sc->sc_pin, sc->sc_enable_val);
+			fdtbus_gpio_write(sc->sc_pin, sc->sc_enable_val);
 		if (sc->sc_delay > 0)
 			delay(sc->sc_delay);
 	} else {
 		if (sc->sc_always_on)
 			return EIO;
-		fdtbus_gpio_write_raw(sc->sc_pin, !sc->sc_enable_val);
+		fdtbus_gpio_write(sc->sc_pin, !sc->sc_enable_val);
 	}
 	return 0;
 }



  1   2   >