CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/ofw

2021-08-07 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Aug  8 01:06:57 UTC 2021

Modified Files:
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_i2c_subr.c

Log Message:
If OFW_I2C_ALLOW_MISSING_COMPATIBLE_PROPERTY, ensure that clist_size
is not negative for the call to kmem_tmpbuf_alloc().


To generate a diff of this commit:
cvs rdiff -u -r1.1.6.8 -r1.1.6.9 src/sys/dev/ofw/ofw_i2c_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/ofw/ofw_i2c_subr.c
diff -u src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.8 src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.9
--- src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.8	Tue May 18 01:24:39 2021
+++ src/sys/dev/ofw/ofw_i2c_subr.c	Sun Aug  8 01:06:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.8 2021/05/18 01:24:39 thorpej Exp $	*/
+/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.9 2021/08/08 01:06:57 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.8 2021/05/18 01:24:39 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.9 2021/08/08 01:06:57 thorpej Exp $");
 
 #include 
 #include 
@@ -149,11 +149,13 @@ of_i2c_enumerate_devices(device_t dev, d
 		}
 
 		clist_size = OF_getproplen(node, "compatible");
-#ifndef OFW_I2C_ALLOW_MISSING_COMPATIBLE_PROPERTY
 		if (clist_size <= 0) {
+#ifndef OFW_I2C_ALLOW_MISSING_COMPATIBLE_PROPERTY
 			continue;
-		}
+#else
+			clist_size = 0;
 #endif
+		}
 		clist = kmem_tmpbuf_alloc(clist_size,
 		compat_buf, sizeof(compat_buf), KM_SLEEP);
 		if (OF_getprop(node, "compatible", clist, clist_size) <



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/ofw

2021-05-17 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Tue May 18 01:24:39 UTC 2021

Modified Files:
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_i2c_subr.c

Log Message:
There is no code of DEC lineage in this file.


To generate a diff of this commit:
cvs rdiff -u -r1.1.6.7 -r1.1.6.8 src/sys/dev/ofw/ofw_i2c_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/ofw/ofw_i2c_subr.c
diff -u src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.7 src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.8
--- src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.7	Fri May 14 03:05:52 2021
+++ src/sys/dev/ofw/ofw_i2c_subr.c	Tue May 18 01:24:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.7 2021/05/14 03:05:52 thorpej Exp $	*/
+/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.8 2021/05/18 01:24:39 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -26,41 +26,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*
- * Copyright 1998
- * Digital Equipment Corporation. All rights reserved.
- *
- * This software is furnished under license and may be used and
- * copied only in accordance with the following terms and conditions.
- * Subject to these conditions, you may download, copy, install,
- * use, modify and distribute this software in source and/or binary
- * form. No title or ownership is transferred hereby.
- *
- * 1) Any source code used, modified or distributed must reproduce
- *and retain this copyright notice and list of conditions as
- *they appear in the source file.
- *
- * 2) No right is granted to use any trade name, trademark, or logo of
- *Digital Equipment Corporation. Neither the "Digital Equipment
- *Corporation" name nor any trademark or logo of Digital Equipment
- *Corporation may be used to endorse or promote products derived
- *from this software without the prior written permission of
- *Digital Equipment Corporation.
- *
- * 3) This software is provided "AS-IS" and any express or implied
- *warranties, including but not limited to, any implied warranties
- *of merchantability, fitness for a particular purpose, or
- *non-infringement are disclaimed. In no event shall DIGITAL be
- *liable for any damages whatsoever, and in particular, DIGITAL
- *shall not be liable for special, indirect, consequential, or
- *incidental damages or damages for lost profits, loss of
- *revenue or loss of use, whether such damages arise in contract,
- *negligence, tort, under statute, in equity, at law or otherwise,
- *even if advised of the possibility of such damage.
- */
-
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.7 2021/05/14 03:05:52 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.8 2021/05/18 01:24:39 thorpej Exp $");
 
 #include 
 #include 



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/ofw

2021-05-13 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri May 14 03:05:52 UTC 2021

Modified Files:
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_i2c_subr.c

Log Message:
Do that again, but slightly differently: a "compatible" property is
required by the Device Tree i2c bindings, and is present on all of
the Sun i2c device nodes that are useful (the notable exception being
the i2c "idprom" nodes, which are actually duplicates of a regular
serial eeprom node).  However, Apple's older OpenFirmware implementations
are rife with i2c nodes that lack a "compatible" property.  So, define
a OFW_I2C_ALLOW_MISSING_COMPATIBLE_PROPERTY quirk, and enable it in
the __HAVE_OPENFIRMWARE_VARIANT_AAPL case.


To generate a diff of this commit:
cvs rdiff -u -r1.1.6.6 -r1.1.6.7 src/sys/dev/ofw/ofw_i2c_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/ofw/ofw_i2c_subr.c
diff -u src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.6 src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.7
--- src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.6	Fri May 14 02:51:43 2021
+++ src/sys/dev/ofw/ofw_i2c_subr.c	Fri May 14 03:05:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.6 2021/05/14 02:51:43 thorpej Exp $	*/
+/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.7 2021/05/14 03:05:52 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.6 2021/05/14 02:51:43 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.7 2021/05/14 03:05:52 thorpej Exp $");
 
 #include 
 #include 
@@ -79,6 +79,12 @@ __KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr
  */
 #define	OFW_I2C_ADDRESS_MASK	__BITS(0,7)
 #define	OFW_I2C_ADDRESS_SHIFT	1
+
+/*
+ * Some of Apple's older OpenFirmware implementations are rife with
+ * nodes lacking "compatible" properties.
+ */
+#define	OFW_I2C_ALLOW_MISSING_COMPATIBLE_PROPERTY
 #endif /* __HAVE_OPENFIRMWARE_VARIANT_AAPL */
 
 #ifdef __HAVE_OPENFIRMWARE_VARIANT_SUNW
@@ -176,6 +182,11 @@ of_i2c_enumerate_devices(device_t dev, d
 		}
 
 		clist_size = OF_getproplen(node, "compatible");
+#ifndef OFW_I2C_ALLOW_MISSING_COMPATIBLE_PROPERTY
+		if (clist_size <= 0) {
+			continue;
+		}
+#endif
 		clist = kmem_tmpbuf_alloc(clist_size,
 		compat_buf, sizeof(compat_buf), KM_SLEEP);
 		if (OF_getprop(node, "compatible", clist, clist_size) <



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/ofw

2021-05-13 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri May 14 02:51:43 UTC 2021

Modified Files:
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_i2c_subr.c

Log Message:
Ooops, no, revert that.


To generate a diff of this commit:
cvs rdiff -u -r1.1.6.5 -r1.1.6.6 src/sys/dev/ofw/ofw_i2c_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/ofw/ofw_i2c_subr.c
diff -u src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.5 src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.6
--- src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.5	Fri May 14 02:48:43 2021
+++ src/sys/dev/ofw/ofw_i2c_subr.c	Fri May 14 02:51:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.5 2021/05/14 02:48:43 thorpej Exp $	*/
+/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.6 2021/05/14 02:51:43 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.5 2021/05/14 02:48:43 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.6 2021/05/14 02:51:43 thorpej Exp $");
 
 #include 
 #include 
@@ -176,9 +176,6 @@ of_i2c_enumerate_devices(device_t dev, d
 		}
 
 		clist_size = OF_getproplen(node, "compatible");
-		if (clist_size <= 0) {
-			continue;
-		}
 		clist = kmem_tmpbuf_alloc(clist_size,
 		compat_buf, sizeof(compat_buf), KM_SLEEP);
 		if (OF_getprop(node, "compatible", clist, clist_size) <



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/ofw

2021-05-13 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri May 14 02:48:43 UTC 2021

Modified Files:
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_i2c_subr.c

Log Message:
Skip nodes without a "compatible" property.


To generate a diff of this commit:
cvs rdiff -u -r1.1.6.4 -r1.1.6.5 src/sys/dev/ofw/ofw_i2c_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/ofw/ofw_i2c_subr.c
diff -u src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.4 src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.5
--- src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.4	Fri May 14 01:52:36 2021
+++ src/sys/dev/ofw/ofw_i2c_subr.c	Fri May 14 02:48:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.4 2021/05/14 01:52:36 thorpej Exp $	*/
+/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.5 2021/05/14 02:48:43 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.4 2021/05/14 01:52:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.5 2021/05/14 02:48:43 thorpej Exp $");
 
 #include 
 #include 
@@ -176,6 +176,9 @@ of_i2c_enumerate_devices(device_t dev, d
 		}
 
 		clist_size = OF_getproplen(node, "compatible");
+		if (clist_size <= 0) {
+			continue;
+		}
 		clist = kmem_tmpbuf_alloc(clist_size,
 		compat_buf, sizeof(compat_buf), KM_SLEEP);
 		if (OF_getprop(node, "compatible", clist, clist_size) <



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/ofw

2021-04-25 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Apr 25 22:16:05 UTC 2021

Modified Files:
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_i2c_subr.c openfirm.h

Log Message:
Implement "i2c-enumerate-devices" for OFW / FDT.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.1.6.1 src/sys/dev/ofw/ofw_i2c_subr.c
cvs rdiff -u -r1.47 -r1.47.2.1 src/sys/dev/ofw/openfirm.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/ofw/ofw_i2c_subr.c
diff -u src/sys/dev/ofw/ofw_i2c_subr.c:1.1 src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.1
--- src/sys/dev/ofw/ofw_i2c_subr.c:1.1	Thu Feb  4 20:19:09 2021
+++ src/sys/dev/ofw/ofw_i2c_subr.c	Sun Apr 25 22:16:05 2021
@@ -1,4 +1,30 @@
-/*	$NetBSD: ofw_i2c_subr.c,v 1.1 2021/02/04 20:19:09 thorpej Exp $	*/
+/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.1 2021/04/25 22:16:05 thorpej Exp $	*/
+
+/*
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * 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.
+ */
 
 /*
  * Copyright 1998
@@ -34,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1 2021/02/04 20:19:09 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.1 2021/04/25 22:16:05 thorpej Exp $");
 
 #include 
 #include 
@@ -44,66 +70,81 @@ __KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr
 #include 
 
 /*
- * Iterate over the subtree of a i2c controller node.
- * Add all sub-devices into an array as part of the controller's
- * device properties.
- * This is used by the i2c bus attach code to do direct configuration.
+ * Standard routine for fetching an i2c device address, according
+ * to the standard OpenFirmware / Device Tree bindings.
  */
-void
-of_enter_i2c_devs(prop_dictionary_t props, int ofnode, size_t cell_size,
-int addr_shift)
+static bool
+of_i2c_get_address(int node, uint32_t *addrp)
+{
+	uint32_t reg;
+
+	if (of_getprop_uint32(node, "reg", ®) == -1) {
+		return false;
+	}
+
+	*addrp = reg;
+	return true;
+}
+
+static int
+of_i2c_enumerate_devices(device_t dev, devhandle_t call_handle, void *v)
 {
-	int node, len;
-	char name[32];
-	uint64_t reg64;
-	uint32_t reg32;
-	uint64_t addr;
-	prop_array_t array = NULL;
-	prop_dictionary_t dev;
+	return of_i2c_enumerate_devices_ext(dev, call_handle, v,
+	of_i2c_get_address);
+}
+OF_DEVICE_CALL_REGISTER("i2c-enumerate-devices", of_i2c_enumerate_devices);
 
-	for (node = OF_child(ofnode); node; node = OF_peer(node)) {
-		if (OF_getprop(node, "name", name, sizeof(name)) <= 0)
+int
+of_i2c_enumerate_devices_ext(device_t dev, devhandle_t call_handle, void *v,
+bool (*get_address)(int, uint32_t *))
+{
+	struct i2c_enumerate_devices_args *args = v;
+	int i2c_node, node;
+	char name[32], compat_buf[32];
+	prop_dictionary_t props;
+	uint32_t addr;
+	char *clist;
+	int clist_size;
+	bool cbrv;
+
+	i2c_node = devhandle_to_of(call_handle);
+
+	for (node = OF_child(i2c_node); node != 0; node = OF_peer(node)) {
+		if (OF_getprop(node, "name", name, sizeof(name)) <= 0) {
 			continue;
-		len = OF_getproplen(node, "reg");
-		addr = 0;
-		if (cell_size == 8 && len >= sizeof(reg64)) {
-			if (OF_getprop(node, "reg", ®64, sizeof(reg64))
-			< sizeof(reg64))
-continue;
-			addr = be64toh(reg64);
-			/*
-			 * The i2c bus number (0 or 1) is encoded in bit 33
-			 * of the register, but we encode it in bit 8 of
-			 * i2c_addr_t.
-			 */
-			if (addr & 0x1)
-addr = (addr & 0xff) | 0x100;
-		} else if (cell_size == 4 && len >= sizeof(reg32)) {
-			if (OF_getprop(node, "reg", ®32, sizeof(reg32))
-			< sizeof(reg32))
-continue;
-			addr = be32toh(reg32);
-		} else {
+		}
+		if (!get_address(node, &