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.

Modified files:

Index: src/sys/dev/fdt/fdt_subr.c
diff -u src/sys/dev/fdt/fdt_subr.c:1.30 src/sys/dev/fdt/fdt_subr.c:1.31
--- src/sys/dev/fdt/fdt_subr.c:1.30	Fri Jun 14 11:08:18 2019
+++ src/sys/dev/fdt/fdt_subr.c	Tue Sep 24 15:23:34 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_subr.c,v 1.30 2019/06/14 11:08:18 hkenken Exp $ */
+/* $NetBSD: fdt_subr.c,v 1.31 2019/09/24 15:23:34 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.30 2019/06/14 11:08:18 hkenken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.31 2019/09/24 15:23:34 jmcneill Exp $");
 
 #include "opt_fdt.h"
 
@@ -224,7 +224,7 @@ fdtbus_decode_range(int phandle, uint64_
 
 	const int addr_cells = fdtbus_get_addr_cells(phandle);
 	const int size_cells = fdtbus_get_size_cells(phandle);
-	const int paddr_cells = fdtbus_get_addr_cells(OF_parent(parent));
+	const int paddr_cells = fdtbus_get_addr_cells(parent);
 	if (addr_cells == -1 || size_cells == -1 || paddr_cells == -1)
 		return paddr;
 
@@ -237,6 +237,10 @@ fdtbus_decode_range(int phandle, uint64_
 		cl = fdtbus_get_cells(buf, size_cells);
 		buf += size_cells * 4;
 
+#ifdef FDTBUS_DEBUG
+		printf("%s: %s: cba=0x%#" PRIx64 ", pba=0x%#" PRIx64 ", cl=0x%#" PRIx64 "\n", __func__, fdt_get_name(fdtbus_get_data(), fdtbus_phandle2offset(phandle), NULL), cba, pba, cl);
+#endif
+
 		if (paddr >= cba && paddr < cba + cl)
 			return fdtbus_decode_range(parent, pba) + (paddr - cba);
 



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;
 }



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.



CVS commit: src/sys/dev/fdt

2019-05-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue May 21 22:15:26 UTC 2019

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

Log Message:
opp-v2 table seems to list opps from lowest to highest, so swap the order to 
ensure the highest frequency is first


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 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.7 src/sys/dev/fdt/cpufreq_dt.c:1.8
--- src/sys/dev/fdt/cpufreq_dt.c:1.7	Thu Nov  1 14:47:36 2018
+++ src/sys/dev/fdt/cpufreq_dt.c	Tue May 21 22:15:26 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufreq_dt.c,v 1.7 2018/11/01 14:47:36 jmcneill Exp $ */
+/* $NetBSD: cpufreq_dt.c,v 1.8 2019/05/21 22:15:26 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.7 2018/11/01 14:47:36 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.8 2019/05/21 22:15:26 jmcneill Exp $");
 
 #include 
 #include 
@@ -377,9 +377,11 @@ cpufreq_dt_parse_opp_v2(struct cpufreq_d
 		opp_uv = fdtbus_get_prop(opp_node, "opp-microvolt", );
 		if (opp_uv == NULL || len < 1)
 			return EINVAL;
-		sc->sc_opp[i].freq_khz = (u_int)(opp_hz / 1000);
-		sc->sc_opp[i].voltage_uv = be32toh(opp_uv[0]);
-		of_getprop_uint32(opp_node, "clock-latency-ns", >sc_opp[i].latency_ns);
+		/* 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);
 	}
 
 	return 0;



CVS commit: src/sys/dev/fdt

2019-05-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue May 21 22:15:26 UTC 2019

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

Log Message:
opp-v2 table seems to list opps from lowest to highest, so swap the order to 
ensure the highest frequency is first


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 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-05-20 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon May 20 11:12:11 UTC 2019

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

Log Message:
Reduce the number of times we need to call driver match functions. Makes
a noticeable difference in boot time on an ODROID-XU4.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 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.27 src/sys/dev/fdt/fdtbus.c:1.28
--- src/sys/dev/fdt/fdtbus.c:1.27	Mon Feb 25 19:28:36 2019
+++ src/sys/dev/fdt/fdtbus.c	Mon May 20 11:12:10 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtbus.c,v 1.27 2019/02/25 19:28:36 jmcneill Exp $ */
+/* $NetBSD: fdtbus.c,v 1.28 2019/05/20 11:12:10 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.27 2019/02/25 19:28:36 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.28 2019/05/20 11:12:10 jmcneill Exp $");
 
 #include 
 #include 
@@ -52,6 +52,7 @@ struct fdt_node {
 	int		n_phandle;
 	const char	*n_name;
 	struct fdt_attach_args n_faa;
+	cfdata_t	n_cf;
 
 	u_int		n_order;
 
@@ -74,6 +75,7 @@ static int	fdt_rescan(device_t, const ch
 static void	fdt_childdet(device_t, device_t);
 
 static int	fdt_scan_submatch(device_t, cfdata_t, const int *, void *);
+static cfdata_t	fdt_scan_best(struct fdt_softc *, struct fdt_node *);
 static void	fdt_scan(struct fdt_softc *, int);
 static void	fdt_add_node(struct fdt_node *);
 static u_int	fdt_get_order(int);
@@ -143,14 +145,22 @@ static int
 fdt_rescan(device_t self, const char *ifattr, const int *locs)
 {
 	struct fdt_softc *sc = device_private(self);
+	struct fdt_node *node;
 	int pass;
 
+	TAILQ_FOREACH(node, _nodes, n_nodes)
+		node->n_cf = fdt_scan_best(sc, node);
+
 	pass = 0;
 	fdt_need_rescan = false;
 	do {
 		fdt_scan(sc, pass);
 		if (fdt_need_rescan == true) {
 			pass = 0;
+			TAILQ_FOREACH(node, _nodes, n_nodes) {
+if (node->n_dev == NULL)
+	node->n_cf = fdt_scan_best(sc, node);
+			}
 			fdt_need_rescan = false;
 		} else {
 			pass++;
@@ -280,7 +290,7 @@ fdt_scan(struct fdt_softc *sc, int pass)
 	char buf[FDT_MAX_PATH];
 
 	TAILQ_FOREACH(node, _nodes, n_nodes) {
-		if (node->n_dev != NULL)
+		if (node->n_dev != NULL || node->n_cf == NULL)
 			continue;
 
 		fdt_init_attach_args(>sc_faa, node, quiet, );
@@ -288,17 +298,16 @@ fdt_scan(struct fdt_softc *sc, int pass)
 		/*
 		 * Make sure we don't attach before a better match in a later pass.
 		 */
-		cfdata_t cf_best = fdt_scan_best(sc, node);
 		cfdata_t cf_pass =
 		config_search_loc(fdt_scan_submatch, node->n_bus, "fdt", locs, );
-		if (cf_best != cf_pass)
+		if (node->n_cf != cf_pass)
 			continue;
 
 		/*
 		 * Attach the device.
 		 */
-		node->n_dev = config_found_sm_loc(node->n_bus, "fdt", locs,
-		, fdtbus_print, fdt_scan_submatch);
+		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-20 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon May 20 11:12:11 UTC 2019

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

Log Message:
Reduce the number of times we need to call driver match functions. Makes
a noticeable difference in boot time on an ODROID-XU4.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 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.



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

2018-06-20 Thread Jason Thorpe


> On Jun 20, 2018, at 12:29 PM, Jared McNeill  wrote:
>> Sure, but where is the code for the brcm2835 platform that *processes* it?  
>> I see stuff for parsing console / fb options, but not for standard boot 
>> flags.
> 
> Firmware puts the string in /chosen/bootargs and we pick it up here: 
> https://nxr.netbsd.org/xref/src/sys/arch/evbarm/fdt/fdt_machdep.c#378 
> 
> 
> The standard args are then processed here: 
> https://nxr.netbsd.org/xref/src/sys/arch/evbarm/fdt/fdt_machdep.c#491 
> 
Ok, got it, thanks.

-- thorpej



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

2018-06-20 Thread Jared McNeill

> On Jun 20, 2018, at 4:25 PM, Jason Thorpe  wrote:
> 
>> On Jun 20, 2018, at 9:56 AM, Jared McNeill  wrote:
>> 
>> On Wed, 20 Jun 2018, Jason Thorpe wrote:
>> 
>>> ofctl(8) is pretty useless for this purpose because it doesn't show you 
>>> which driver instance has attached to a given device tree node.  As for 
>>> passing generic boot args, it's not obvious how one does that on the RPI 
>>> (and I don't even see the hook that processes the generic boot args 
>>> bcm283x_platform).
>> 
>> https://www.raspberrypi.org/documentation/configuration/cmdline-txt.md
> 
> Sure, but where is the code for the brcm2835 platform that *processes* it?  I 
> see stuff for parsing console / fb options, but not for standard boot flags.

Firmware puts the string in /chosen/bootargs and we pick it up here: 
https://nxr.netbsd.org/xref/src/sys/arch/evbarm/fdt/fdt_machdep.c#378 


The standard args are then processed here: 
https://nxr.netbsd.org/xref/src/sys/arch/evbarm/fdt/fdt_machdep.c#491 





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

2018-06-20 Thread Jason Thorpe



> On Jun 20, 2018, at 9:56 AM, Jared McNeill  wrote:
> 
> On Wed, 20 Jun 2018, Jason Thorpe wrote:
> 
>> ofctl(8) is pretty useless for this purpose because it doesn't show you 
>> which driver instance has attached to a given device tree node.  As for 
>> passing generic boot args, it's not obvious how one does that on the RPI 
>> (and I don't even see the hook that processes the generic boot args 
>> bcm283x_platform).
> 
> https://www.raspberrypi.org/documentation/configuration/cmdline-txt.md


Sure, but where is the code for the brcm2835 platform that *processes* it?  I 
see stuff for parsing console / fb options, but not for standard boot flags.

-- thorpej



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

2018-06-20 Thread Jared McNeill

On Wed, 20 Jun 2018, Jason Thorpe wrote:


ofctl(8) is pretty useless for this purpose because it doesn't show you which 
driver instance has attached to a given device tree node.  As for passing 
generic boot args, it's not obvious how one does that on the RPI (and I don't 
even see the hook that processes the generic boot args bcm283x_platform).


https://www.raspberrypi.org/documentation/configuration/cmdline-txt.md


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

2018-06-20 Thread Jason Thorpe



> On Jun 20, 2018, at 2:06 AM, Jared McNeill  wrote:
> 
> Not a fan of this, some of these paths can get fairly long (boot the 
> VEXPRESS_A15 kernel to see for yourself) and the path is only really useful 
> if you are debugging something.

Sigh.

> If you want to see the debugging information we already have a way to do that 
> with boot -x. You can also inspect the whole tree at runtime with ofctl(8).

ofctl(8) is pretty useless for this purpose because it doesn't show you which 
driver instance has attached to a given device tree node.  As for passing 
generic boot args, it's not obvious how one does that on the RPI (and I don't 
even see the hook that processes the generic boot args bcm283x_platform).


> 
> 
> On Wed, 20 Jun 2018, Jason R Thorpe wrote:
> 
>> Module Name: src
>> Committed By:thorpej
>> Date:Wed Jun 20 05:59:18 UTC 2018
>> 
>> Modified Files:
>>  src/sys/dev/fdt: fdtbus.c
>> 
>> Log Message:
>> In fdtbus_print(), aprint_normal the path to the device (rather than
>> aprint_debug).  This info is every bit as useful as, say, PCI device
>> locations.
>> 
>> 
>> To generate a diff of this commit:
>> cvs rdiff -u -r1.17 -r1.18 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.
>> 
>> 

-- thorpej



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

2018-06-20 Thread Jared McNeill
Not a fan of this, some of these paths can get fairly long (boot the 
VEXPRESS_A15 kernel to see for yourself) and the path is 
only really useful if you are debugging something.


If you want to see the debugging information we already have a way to 
do that with boot -x. You can also inspect the whole tree at runtime with 
ofctl(8).



On Wed, 20 Jun 2018, Jason R Thorpe wrote:


Module Name:src
Committed By:   thorpej
Date:   Wed Jun 20 05:59:18 UTC 2018

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

Log Message:
In fdtbus_print(), aprint_normal the path to the device (rather than
aprint_debug).  This info is every bit as useful as, say, PCI device
locations.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 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.