Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/thorpej-i2c-spi-conf2]: src/sys/dev/i2c Move the i2c enumeration helpers...



details:   https://anonhg.NetBSD.org/src/rev/d325138b1ad4
branches:  thorpej-i2c-spi-conf2
changeset: 985908:d325138b1ad4
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Sep 13 14:47:28 2021 +0000

description:
Move the i2c enumeration helpers to their own header file to detangle
it from reliance on "iic" being configured into the kernel.

diffstat:

 sys/arch/macppc/dev/cuda.c              |   5 +-
 sys/arch/sandpoint/sandpoint/autoconf.c |   7 +-
 sys/arch/sparc64/sparc64/ofw_patch.c    |   7 +-
 sys/dev/i2c/i2c.c                       |  39 +----------------
 sys/dev/i2c/i2c_enum.h                  |  76 +++++++++++++++++++++++++++++++++
 sys/dev/i2c/i2cvar.h                    |  15 +------
 6 files changed, 90 insertions(+), 59 deletions(-)

diffs (248 lines):

diff -r 59b28007e410 -r d325138b1ad4 sys/arch/macppc/dev/cuda.c
--- a/sys/arch/macppc/dev/cuda.c        Sun Sep 12 23:13:02 2021 +0000
+++ b/sys/arch/macppc/dev/cuda.c        Mon Sep 13 14:47:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cuda.c,v 1.29.2.5 2021/09/11 17:22:35 thorpej Exp $ */
+/*     $NetBSD: cuda.c,v 1.29.2.6 2021/09/13 14:47:28 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2006 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cuda.c,v 1.29.2.5 2021/09/11 17:22:35 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cuda.c,v 1.29.2.6 2021/09/13 14:47:28 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -41,6 +41,7 @@
 #include <machine/pio.h>
 #include <dev/clock_subr.h>
 #include <dev/i2c/i2cvar.h>
+#include <dev/i2c/i2c_enum.h>
 
 #include <macppc/dev/viareg.h>
 #include <macppc/dev/cudavar.h>
diff -r 59b28007e410 -r d325138b1ad4 sys/arch/sandpoint/sandpoint/autoconf.c
--- a/sys/arch/sandpoint/sandpoint/autoconf.c   Sun Sep 12 23:13:02 2021 +0000
+++ b/sys/arch/sandpoint/sandpoint/autoconf.c   Mon Sep 13 14:47:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: autoconf.c,v 1.29.16.4 2021/09/11 01:03:18 thorpej Exp $       */
+/*     $NetBSD: autoconf.c,v 1.29.16.5 2021/09/13 14:47:28 thorpej Exp $       */
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.29.16.4 2021/09/11 01:03:18 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.29.16.5 2021/09/13 14:47:28 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -44,7 +44,8 @@
 
 #include <dev/cons.h>
 #include <dev/pci/pcivar.h>
-#include <dev/i2c/i2cvar.h>
+
+#include <dev/i2c/i2c_enum.h>
 
 #include <net/if.h>
 #include <net/if_ether.h>
diff -r 59b28007e410 -r d325138b1ad4 sys/arch/sparc64/sparc64/ofw_patch.c
--- a/sys/arch/sparc64/sparc64/ofw_patch.c      Sun Sep 12 23:13:02 2021 +0000
+++ b/sys/arch/sparc64/sparc64/ofw_patch.c      Mon Sep 13 14:47:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ofw_patch.c,v 1.7.14.7 2021/09/12 19:23:27 thorpej Exp $ */
+/*     $NetBSD: ofw_patch.c,v 1.7.14.8 2021/09/13 14:47:28 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020, 2021 The NetBSD Foundation, Inc.
@@ -29,12 +29,13 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_patch.c,v 1.7.14.7 2021/09/12 19:23:27 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_patch.c,v 1.7.14.8 2021/09/13 14:47:28 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
 
-#include <dev/i2c/i2cvar.h>
+#include <dev/i2c/i2c_enum.h>
+
 #include <dev/scsipi/scsipiconf.h>
 
 #include <machine/autoconf.h>
diff -r 59b28007e410 -r d325138b1ad4 sys/dev/i2c/i2c.c
--- a/sys/dev/i2c/i2c.c Sun Sep 12 23:13:02 2021 +0000
+++ b/sys/dev/i2c/i2c.c Mon Sep 13 14:47:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i2c.c,v 1.80.2.7 2021/09/12 22:02:19 thorpej Exp $     */
+/*     $NetBSD: i2c.c,v 1.80.2.8 2021/09/13 14:47:28 thorpej Exp $     */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.80.2.7 2021/09/12 22:02:19 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.80.2.8 2021/09/13 14:47:28 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -631,41 +631,6 @@
        return true;                            /* keep enumerating */
 }
 
-/*
- * i2c_enumerate_deventries:
- *
- *     Helper for enumerating known i2c devices that can be used
- *     by a platform's i2c-emumerate-devices device call if needed.
- */
-int
-i2c_enumerate_deventries(device_t dev, devhandle_t call_handle,
-    struct i2c_enumerate_devices_args *args,
-    const struct i2c_deventry *entries, unsigned int nentries)
-{
-       unsigned int i;
-       bool cbrv;
-
-       for (i = 0; i < nentries; i++) {
-               args->ia->ia_addr = entries[i].addr;
-               args->ia->ia_name = entries[i].name;
-               args->ia->ia_clist = entries[i].compat;
-               args->ia->ia_clist_size =
-                   entries[i].compat != NULL ? strlen(entries[i].compat) + 1
-                                             : 0;
-
-               /* no devhandle for child devices. */
-               devhandle_invalidate(&args->ia->ia_devhandle);
-
-               cbrv = args->callback(dev, args);
-
-               if (!cbrv) {
-                       break;
-               }
-       }
-
-       return 0;
-}
-
 static int
 iic_match(device_t parent, cfdata_t cf, void *aux)
 {
diff -r 59b28007e410 -r d325138b1ad4 sys/dev/i2c/i2c_enum.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/i2c/i2c_enum.h    Mon Sep 13 14:47:28 2021 +0000
@@ -0,0 +1,76 @@
+/*     $NetBSD: i2c_enum.h,v 1.1.2.1 2021/09/13 14:47:28 thorpej Exp $ */
+
+/*-             
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved. 
+ *       
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *  
+ * 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.
+ */             
+
+#ifndef _DEV_I2C_I2C_ENUM_H_
+#define        _DEV_I2C_I2C_ENUM_H_
+
+#include <dev/i2c/i2cvar.h>
+
+/*
+ * Helpers for enumerating known i2c devices, that can be used from
+ * the i2c-enumerate-devices device call.
+ */
+struct i2c_deventry {
+       const char *name;
+       const char *compat;
+       i2c_addr_t addr;
+};
+
+static inline int __unused
+i2c_enumerate_deventries(device_t dev, devhandle_t call_handle,
+    struct i2c_enumerate_devices_args *args,
+    const struct i2c_deventry *entries, unsigned int nentries)
+{
+       unsigned int i;
+       bool cbrv;
+
+       for (i = 0; i < nentries; i++) {
+               args->ia->ia_addr = entries[i].addr;
+               args->ia->ia_name = entries[i].name;
+               args->ia->ia_clist = entries[i].compat;
+               args->ia->ia_clist_size =
+                   entries[i].compat != NULL ? strlen(entries[i].compat) + 1
+                                             : 0;
+
+               /* no devhandle for child devices. */
+               devhandle_invalidate(&args->ia->ia_devhandle);
+
+               cbrv = args->callback(dev, args);
+
+               if (!cbrv) {
+                       break;
+               }
+       }
+
+       return 0;
+}
+
+#endif /* _DEV_I2C_I2C_ENUM_H_ */
diff -r 59b28007e410 -r d325138b1ad4 sys/dev/i2c/i2cvar.h
--- a/sys/dev/i2c/i2cvar.h      Sun Sep 12 23:13:02 2021 +0000
+++ b/sys/dev/i2c/i2cvar.h      Mon Sep 13 14:47:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i2cvar.h,v 1.24.12.3 2021/09/11 01:03:18 thorpej Exp $ */
+/*     $NetBSD: i2cvar.h,v 1.24.12.4 2021/09/13 14:47:28 thorpej Exp $ */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -175,19 +175,6 @@
 };
 
 /*
- * Helpers for enumerating known i2c devices, that can be used from
- * the i2c-enumerate-devices device call.
- */
-struct i2c_deventry {
-       const char *name;
-       const char *compat;
-       i2c_addr_t addr;
-};
-int    i2c_enumerate_deventries(device_t, devhandle_t,
-           struct i2c_enumerate_devices_args *,
-           const struct i2c_deventry *, unsigned int);
-
-/*
  * API presented to i2c controllers.
  */
 int    iicbus_print(void *, const char *);



Home | Main Index | Thread Index | Old Index