Module Name:    src
Committed By:   thorpej
Date:           Sat May  8 14:23:15 UTC 2021

Modified Files:
        src/sys/dev/i2c [thorpej-i2c-spi-conf]: files.i2c i2c_subr.c i2cmux.c
            i2cvar.h

Log Message:
- Add an optional bus number to i2cbus_attach_args, and a corresponding
  optional "bus" locator to the i2cbus interface attribute.
- Add a iicbus_print_multi() routine, which is like iicbus_print(),
  but also prints the bus number.
- Use these new features in the iicmux driver rather than winging it.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.115.4.1 src/sys/dev/i2c/files.i2c
cvs rdiff -u -r1.1 -r1.1.72.1 src/sys/dev/i2c/i2c_subr.c
cvs rdiff -u -r1.5.2.1 -r1.5.2.2 src/sys/dev/i2c/i2cmux.c
cvs rdiff -u -r1.24.2.1 -r1.24.2.2 src/sys/dev/i2c/i2cvar.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/i2c/files.i2c
diff -u src/sys/dev/i2c/files.i2c:1.115 src/sys/dev/i2c/files.i2c:1.115.4.1
--- src/sys/dev/i2c/files.i2c:1.115	Mon Jan  4 22:09:35 2021
+++ src/sys/dev/i2c/files.i2c	Sat May  8 14:23:15 2021
@@ -1,7 +1,7 @@
-#	$NetBSD: files.i2c,v 1.115 2021/01/04 22:09:35 thorpej Exp $
+#	$NetBSD: files.i2c,v 1.115.4.1 2021/05/08 14:23:15 thorpej Exp $
 
 obsolete defflag	opt_i2cbus.h		I2C_SCAN
-define	i2cbus { }
+define	i2cbus { [bus = -1] }
 define	i2cexec
 
 device	iic { [addr = -1] } : i2c_bitbang

Index: src/sys/dev/i2c/i2c_subr.c
diff -u src/sys/dev/i2c/i2c_subr.c:1.1 src/sys/dev/i2c/i2c_subr.c:1.1.72.1
--- src/sys/dev/i2c/i2c_subr.c:1.1	Mon Oct  3 22:27:23 2011
+++ src/sys/dev/i2c/i2c_subr.c	Sat May  8 14:23:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2c_subr.c,v 1.1 2011/10/03 22:27:23 jmcneill Exp $	*/
+/*	$NetBSD: i2c_subr.c,v 1.1.72.1 2021/05/08 14:23:15 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i2c_subr.c,v 1.1 2011/10/03 22:27:23 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c_subr.c,v 1.1.72.1 2021/05/08 14:23:15 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -46,9 +46,22 @@ __KERNEL_RCSID(0, "$NetBSD: i2c_subr.c,v
 int
 iicbus_print(void *aux, const char *pnp)
 {
+	/* struct i2cbus_attach_args * const iba = aux; */
 
 	if (pnp != NULL)
 		aprint_normal("iic at %s", pnp);
 
 	return UNCONF;
 }
+
+int
+iicbus_print_multi(void *aux, const char *pnp)
+{
+	struct i2cbus_attach_args * const iba = aux;
+
+	if (pnp != NULL)
+		aprint_normal("iic at %s", pnp);
+	aprint_normal(" bus %d", iba->iba_bus);
+
+	return UNCONF;
+}

Index: src/sys/dev/i2c/i2cmux.c
diff -u src/sys/dev/i2c/i2cmux.c:1.5.2.1 src/sys/dev/i2c/i2cmux.c:1.5.2.2
--- src/sys/dev/i2c/i2cmux.c:1.5.2.1	Sat May  8 02:44:22 2021
+++ src/sys/dev/i2c/i2cmux.c	Sat May  8 14:23:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2cmux.c,v 1.5.2.1 2021/05/08 02:44:22 thorpej Exp $	*/
+/*	$NetBSD: i2cmux.c,v 1.5.2.2 2021/05/08 14:23:15 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i2cmux.c,v 1.5.2.1 2021/05/08 02:44:22 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2cmux.c,v 1.5.2.2 2021/05/08 14:23:15 thorpej Exp $");
 
 #include <sys/types.h>
 #include <sys/device.h>
@@ -40,6 +40,8 @@ __KERNEL_RCSID(0, "$NetBSD: i2cmux.c,v 1
 #include <dev/i2c/i2cvar.h>
 #include <dev/i2c/i2cmuxvar.h>
 
+#include "locators.h"
+
 /*
  * i2c mux
  *
@@ -110,20 +112,6 @@ iicmux_exec(void * const v, i2c_op_t con
 
 /*****************************************************************************/
 
-/* XXX iicbus_print() should be able to do this. */
-static int
-iicmux_print(void * const aux, const char * const pnp)
-{
-	i2c_tag_t const tag = aux;
-	struct iicmux_bus * const bus = tag->ic_cookie;
-	int rv;
-
-	rv = iicbus_print(aux, pnp);
-	aprint_normal(" bus %d", bus->busidx);
-
-	return rv;
-}
-
 static void
 iicmux_attach_bus(struct iicmux_softc * const sc, devhandle_t devhandle,
     int const busidx)
@@ -147,31 +135,26 @@ iicmux_attach_bus(struct iicmux_softc * 
 	bus->controller.ic_release_bus = iicmux_release_bus;
 	bus->controller.ic_exec = iicmux_exec;
 
-	switch (devhandle_type(devhandle)) {
 #if defined(I2CMUX_USE_FDT)
-	case DEVHANDLE_TYPE_OF:
+	if (devhandle_type(devhandle) == DEVHANDLE_TYPE_OF) {
 		fdtbus_register_i2c_controller(&bus->controller,
 		    devhandle_to_of(devhandle));
-
-		fdtbus_attach_i2cbus(sc->sc_dev, devhandle_to_of(devhandle),
-		    &bus->controller, iicmux_print);
-		break;
+	}
 #endif /* I2CMUX_USE_FDT */
 
-	case DEVHANDLE_TYPE_INVALID:
-		aprint_error_dev(sc->sc_dev, "invalid bus device handle\n");
-		return;
-
-	default: {
-		struct i2cbus_attach_args iba = {
-			.iba_tag = &bus->controller,
-		};
-		config_found(sc->sc_dev, &iba, iicmux_print,
-		    CFARG_DEVHANDLE, devhandle,
-		    CFARG_EOL);
-		break;
-	    }
-	}
+	struct i2cbus_attach_args iba = {
+		.iba_tag = &bus->controller,
+		.iba_bus = bus->busidx,
+	};
+
+	int locs[I2CBUSCF_NLOCS];
+	locs[I2CBUSCF_BUS] = bus->busidx;
+
+	config_found(sc->sc_dev, &iba, iicbus_print_multi,
+	    CFARG_SUBMATCH, config_stdsubmatch,
+	    CFARG_LOCATORS, locs,
+	    CFARG_DEVHANDLE, devhandle,
+	    CFARG_EOL);
 }
 
 #if defined(I2CMUX_USE_FDT)

Index: src/sys/dev/i2c/i2cvar.h
diff -u src/sys/dev/i2c/i2cvar.h:1.24.2.1 src/sys/dev/i2c/i2cvar.h:1.24.2.2
--- src/sys/dev/i2c/i2cvar.h:1.24.2.1	Sun Apr 25 21:45:15 2021
+++ src/sys/dev/i2c/i2cvar.h	Sat May  8 14:23:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2cvar.h,v 1.24.2.1 2021/04/25 21:45:15 thorpej Exp $	*/
+/*	$NetBSD: i2cvar.h,v 1.24.2.2 2021/05/08 14:23:15 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -131,6 +131,7 @@ typedef struct i2c_controller {
 /* Used to attach the i2c framework to the controller. */
 struct i2cbus_attach_args {
 	i2c_tag_t iba_tag;		/* the controller */
+	int iba_bus;			/* bus number (optional) */
 };
 
 /* Type of value stored in "ia_cookie" */
@@ -187,6 +188,7 @@ struct i2c_enumerate_devices_args {
  * API presented to i2c controllers.
  */
 int	iicbus_print(void *, const char *);
+int	iicbus_print_multi(void *, const char *);
 void	iic_tag_init(i2c_tag_t);
 void	iic_tag_fini(i2c_tag_t);
 

Reply via email to