Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/thorpej-i2c-spi-conf]: src/sys/dev/i2c - Add an optional bus number to i...
details: https://anonhg.NetBSD.org/src/rev/039620c53f9a
branches: thorpej-i2c-spi-conf
changeset: 378755:039620c53f9a
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sat May 08 14:23:15 2021 +0000
description:
- 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.
diffstat:
sys/dev/i2c/files.i2c | 4 +-
sys/dev/i2c/i2c_subr.c | 17 ++++++++++++++-
sys/dev/i2c/i2cmux.c | 53 ++++++++++++++++---------------------------------
sys/dev/i2c/i2cvar.h | 4 ++-
4 files changed, 38 insertions(+), 40 deletions(-)
diffs (173 lines):
diff -r 3e42cb34a41e -r 039620c53f9a sys/dev/i2c/files.i2c
--- a/sys/dev/i2c/files.i2c Sat May 08 11:40:02 2021 +0000
+++ b/sys/dev/i2c/files.i2c Sat May 08 14:23:15 2021 +0000
@@ -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
diff -r 3e42cb34a41e -r 039620c53f9a sys/dev/i2c/i2c_subr.c
--- a/sys/dev/i2c/i2c_subr.c Sat May 08 11:40:02 2021 +0000
+++ b/sys/dev/i2c/i2c_subr.c Sat May 08 14:23:15 2021 +0000
@@ -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 @@
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;
+}
diff -r 3e42cb34a41e -r 039620c53f9a sys/dev/i2c/i2cmux.c
--- a/sys/dev/i2c/i2cmux.c Sat May 08 11:40:02 2021 +0000
+++ b/sys/dev/i2c/i2cmux.c Sat May 08 14:23:15 2021 +0000
@@ -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 @@
#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;
+ struct i2cbus_attach_args iba = {
+ .iba_tag = &bus->controller,
+ .iba_bus = bus->busidx,
+ };
- default: {
- struct i2cbus_attach_args iba = {
- .iba_tag = &bus->controller,
- };
- config_found(sc->sc_dev, &iba, iicmux_print,
- CFARG_DEVHANDLE, devhandle,
- CFARG_EOL);
- break;
- }
- }
+ 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)
diff -r 3e42cb34a41e -r 039620c53f9a sys/dev/i2c/i2cvar.h
--- a/sys/dev/i2c/i2cvar.h Sat May 08 11:40:02 2021 +0000
+++ b/sys/dev/i2c/i2cvar.h Sat May 08 14:23:15 2021 +0000
@@ -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);
Home |
Main Index |
Thread Index |
Old Index