Module Name:    src
Committed By:   thorpej
Date:           Mon Jan 17 19:34:31 UTC 2022

Modified Files:
        src/sys/dev/i2c: i2c.c

Log Message:
Minimal hack to pass child devices a devhandle created from the OF
or ACPI "cookie".  Temporary measure until the i2c autoconfiguration
overhaul is merged (which fixes this in a more generic way).


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/dev/i2c/i2c.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/i2c/i2c.c
diff -u src/sys/dev/i2c/i2c.c:1.80 src/sys/dev/i2c/i2c.c:1.81
--- src/sys/dev/i2c/i2c.c:1.80	Sat Aug  7 16:19:11 2021
+++ src/sys/dev/i2c/i2c.c	Mon Jan 17 19:34:31 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2c.c,v 1.80 2021/08/07 16:19:11 thorpej Exp $	*/
+/*	$NetBSD: i2c.c,v 1.81 2022/01/17 19:34:31 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -37,10 +37,23 @@
 
 #ifdef _KERNEL_OPT
 #include "opt_i2c.h"
-#endif
+
+#include "opt_fdt.h"
+#ifdef FDT
+#define	I2C_USE_FDT
+#endif /* FDT */
+
+#if defined(__aarch64__) || defined(__amd64__)
+#include "acpica.h"
+#if NACPICA > 0
+#define	I2C_USE_ACPI
+#endif /* NACPICA > 0 */
+#endif /* __aarch64__ || __amd64__ */
+
+#endif /* _KERNEL_OPT */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.80 2021/08/07 16:19:11 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.81 2022/01/17 19:34:31 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -57,6 +70,14 @@ __KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.80
 #include <sys/once.h>
 #include <sys/mutex.h>
 
+#ifdef I2C_USE_ACPI
+#include <dev/acpi/acpivar.h>
+#endif /* I2C_USE_ACPI */
+
+#ifdef I2C_USE_FDT
+#include <dev/fdt/fdtvar.h>
+#endif /* I2C_USE_FDT */
+
 #include <dev/i2c/i2cvar.h>
 
 #include "ioconf.h"
@@ -444,6 +465,7 @@ iic_attach(device_t parent, device_t sel
 		uint32_t cookietype;
 		const char *name;
 		struct i2c_attach_args ia;
+		devhandle_t devhandle;
 		int loc[IICCF_NLOCS];
 
 		memset(loc, 0, sizeof loc);
@@ -473,6 +495,19 @@ iic_attach(device_t parent, device_t sel
 			ia.ia_cookietype = cookietype;
 			ia.ia_prop = dev;
 
+			devhandle_invalidate(&devhandle);
+#ifdef I2C_USE_FDT
+			if (cookietype == I2C_COOKIE_OF) {
+				devhandle = devhandle_from_of((int)cookie);
+			}
+#endif /* I2C_USE_FDT */
+#ifdef I2C_USE_ACPI
+			if (cookietype == I2C_COOKIE_ACPI) {
+				devhandle =
+				    devhandle_from_acpi((ACPI_HANDLE)cookie);
+			}
+#endif /* I2C_USE_ACPI */
+
 			buf = NULL;
 			cdata = prop_dictionary_get(dev, "compatible");
 			if (cdata)
@@ -493,7 +528,8 @@ iic_attach(device_t parent, device_t sel
 					sc->sc_devices[addr] =
 					    config_found(self, &ia,
 					    iic_print_direct,
-					    CFARGS(.locators = loc));
+					    CFARGS(.locators = loc,
+						   .devhandle = devhandle));
 				}
 			}
 

Reply via email to