Source-Changes-HG archive

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

[src/trunk]: src/sys/sys Change the device_compatible_match() function to onl...



details:   https://anonhg.NetBSD.org/src/rev/71cdacae46df
branches:  trunk
changeset: 949852:71cdacae46df
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Jan 18 15:28:21 2021 +0000

description:
Change the device_compatible_match() function to only perform the match.
Introduce a device_compatible_lookup() function to return an entry based
on the same matching criteria (a'la of_search_compatible()).

Update iic_compatible_match() to reflect the above change, and introduce
iic_compatible_lookup().  This pattern is less awkward to use.

diffstat:

 sys/dev/i2c/at24cxx.c    |   6 +++---
 sys/dev/i2c/axppmic.c    |   6 +++---
 sys/dev/i2c/ds1307.c     |   6 +++---
 sys/dev/i2c/fan53555.c   |   6 +++---
 sys/dev/i2c/i2c.c        |  24 ++++++++++++++++++------
 sys/dev/i2c/i2cvar.h     |   8 +++++---
 sys/dev/i2c/m41st84.c    |  10 +++++-----
 sys/dev/i2c/pcagpio.c    |   6 +++---
 sys/dev/i2c/pcai2cmux.c  |   6 +++---
 sys/dev/i2c/rkpmic.c     |   7 ++++---
 sys/dev/spi/spi.c        |   6 +++---
 sys/kern/subr_autoconf.c |  40 ++++++++++++++++++++++++++++++++++------
 sys/sys/device.h         |   8 +++++---
 13 files changed, 92 insertions(+), 47 deletions(-)

diffs (truncated from 432 to 300 lines):

diff -r 0344a09858a6 -r 71cdacae46df sys/dev/i2c/at24cxx.c
--- a/sys/dev/i2c/at24cxx.c     Mon Jan 18 13:29:37 2021 +0000
+++ b/sys/dev/i2c/at24cxx.c     Mon Jan 18 15:28:21 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: at24cxx.c,v 1.37 2021/01/17 21:56:20 thorpej Exp $     */
+/*     $NetBSD: at24cxx.c,v 1.38 2021/01/18 15:28:21 thorpej Exp $     */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.37 2021/01/17 21:56:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.38 2021/01/18 15:28:21 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -182,7 +182,7 @@
                sc->sc_size = (device_cfdata(self)->cf_flags << 7);
 
        if (sc->sc_size <= 0 && ia->ia_ncompat > 0) {
-               if (iic_compatible_match(ia, compat_data, &dce))
+               if ((dce = iic_compatible_lookup(ia, compat_data)) != NULL)
                        sc->sc_size = dce->value;
        }
 
diff -r 0344a09858a6 -r 71cdacae46df sys/dev/i2c/axppmic.c
--- a/sys/dev/i2c/axppmic.c     Mon Jan 18 13:29:37 2021 +0000
+++ b/sys/dev/i2c/axppmic.c     Mon Jan 18 15:28:21 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: axppmic.c,v 1.30 2021/01/17 21:56:20 thorpej Exp $ */
+/* $NetBSD: axppmic.c,v 1.31 2021/01/18 15:28:21 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2014-2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.30 2021/01/17 21:56:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.31 2021/01/18 15:28:21 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -949,7 +949,7 @@
        uint8_t irq_mask, val;
        int error;
 
-       (void) iic_compatible_match(ia, compat_data, &dce);
+       dce = iic_compatible_lookup(ia, compat_data);
        KASSERT(dce != NULL);
        c = dce->data;
 
diff -r 0344a09858a6 -r 71cdacae46df sys/dev/i2c/ds1307.c
--- a/sys/dev/i2c/ds1307.c      Mon Jan 18 13:29:37 2021 +0000
+++ b/sys/dev/i2c/ds1307.c      Mon Jan 18 15:28:21 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ds1307.c,v 1.35 2021/01/17 21:56:20 thorpej Exp $      */
+/*     $NetBSD: ds1307.c,v 1.36 2021/01/18 15:28:21 thorpej Exp $      */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.35 2021/01/17 21:56:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.36 2021/01/18 15:28:21 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -255,7 +255,7 @@
        const struct dsrtc_model *dm = NULL;
        const struct device_compatible_entry *dce;
 
-       if (iic_compatible_match(ia, compat_data, &dce))
+       if ((dce = iic_compatible_lookup(ia, compat_data)) != NULL)
                dm = dce->data;
 
        return dm;
diff -r 0344a09858a6 -r 71cdacae46df sys/dev/i2c/fan53555.c
--- a/sys/dev/i2c/fan53555.c    Mon Jan 18 13:29:37 2021 +0000
+++ b/sys/dev/i2c/fan53555.c    Mon Jan 18 15:28:21 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fan53555.c,v 1.6 2021/01/17 21:56:20 thorpej Exp $ */
+/* $NetBSD: fan53555.c,v 1.7 2021/01/18 15:28:21 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fan53555.c,v 1.6 2021/01/17 21:56:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fan53555.c,v 1.7 2021/01/18 15:28:21 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -310,7 +310,7 @@
        sc->sc_addr = ia->ia_addr;
        sc->sc_phandle = ia->ia_cookie;
 
-       iic_compatible_match(ia, compat_data, &compat);
+       compat = iic_compatible_lookup(ia, compat_data);
        KASSERT(compat != NULL);
 
        if (fan53555_init(sc, compat->value) != 0)
diff -r 0344a09858a6 -r 71cdacae46df sys/dev/i2c/i2c.c
--- a/sys/dev/i2c/i2c.c Mon Jan 18 13:29:37 2021 +0000
+++ b/sys/dev/i2c/i2c.c Mon Jan 18 15:28:21 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i2c.c,v 1.75 2020/07/07 16:14:23 thorpej Exp $ */
+/*     $NetBSD: i2c.c,v 1.76 2021/01/18 15:28:21 thorpej Exp $ */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.75 2020/07/07 16:14:23 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.76 2021/01/18 15:28:21 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -687,13 +687,12 @@
  */
 int
 iic_compatible_match(const struct i2c_attach_args *ia,
-                    const struct device_compatible_entry *compats,
-                    const struct device_compatible_entry **matching_entryp)
+                    const struct device_compatible_entry *compats)
 {
        int match_result;
 
        match_result = device_compatible_match(ia->ia_compat, ia->ia_ncompat,
-                                              compats, matching_entryp);
+                                              compats);
        if (match_result) {
                match_result =
                    MIN(I2C_MATCH_DIRECT_COMPATIBLE + match_result - 1,
@@ -704,6 +703,19 @@
 }
 
 /*
+ * iic_compatible_lookup --
+ *     Look the compatible entry that matches one of the driver's
+ *     "compatible" strings.  The first match is returned.
+ */
+const struct device_compatible_entry *
+iic_compatible_lookup(const struct i2c_attach_args *ia,
+                     const struct device_compatible_entry *compats)
+{
+       return device_compatible_lookup(ia->ia_compat, ia->ia_ncompat,
+                                       compats);
+}
+
+/*
  * iic_use_direct_match --
  *     Helper for direct-config of i2c.  Returns true if this is
  *     a direct-config situation, along with with match result.
@@ -724,7 +736,7 @@
        }
 
        if (ia->ia_ncompat > 0 && ia->ia_compat != NULL) {
-               *match_resultp = iic_compatible_match(ia, compats, NULL);
+               *match_resultp = iic_compatible_match(ia, compats);
                return true;
        }
 
diff -r 0344a09858a6 -r 71cdacae46df sys/dev/i2c/i2cvar.h
--- a/sys/dev/i2c/i2cvar.h      Mon Jan 18 13:29:37 2021 +0000
+++ b/sys/dev/i2c/i2cvar.h      Mon Jan 18 15:28:21 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i2cvar.h,v 1.21 2020/12/29 00:26:51 thorpej Exp $      */
+/*     $NetBSD: i2cvar.h,v 1.22 2021/01/18 15:28:21 thorpej Exp $      */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -171,10 +171,12 @@
  * API presented to i2c devices.
  */
 int    iic_compatible_match(const struct i2c_attach_args *,
-                            const struct device_compatible_entry *,
-                            const struct device_compatible_entry **);
+                            const struct device_compatible_entry *);
 bool   iic_use_direct_match(const struct i2c_attach_args *, const cfdata_t,
                             const struct device_compatible_entry *, int *);
+const struct device_compatible_entry *
+       iic_compatible_lookup(const struct i2c_attach_args *,
+                             const struct device_compatible_entry *);
 
 /*
  * Constants to indicate the quality of a match made by a driver's
diff -r 0344a09858a6 -r 71cdacae46df sys/dev/i2c/m41st84.c
--- a/sys/dev/i2c/m41st84.c     Mon Jan 18 13:29:37 2021 +0000
+++ b/sys/dev/i2c/m41st84.c     Mon Jan 18 15:28:21 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: m41st84.c,v 1.28 2021/01/17 21:56:20 thorpej Exp $     */
+/*     $NetBSD: m41st84.c,v 1.29 2021/01/18 15:28:21 thorpej Exp $     */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: m41st84.c,v 1.28 2021/01/17 21:56:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m41st84.c,v 1.29 2021/01/18 15:28:21 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -140,7 +140,7 @@
                return &m41t80_model;
        
        for (dce = compat_data; dce->compat != NULL; dce++) {
-               sm = (void *)dce->data;
+               sm = dce->data;
                if (sm->sm_model == model)
                        return sm;
        }
@@ -153,8 +153,8 @@
        const struct device_compatible_entry *dce;
        const struct strtc_model *sm = NULL;
 
-       if (iic_compatible_match(ia, compat_data, &dce))
-               sm = (void *)dce->data;
+       if ((dce = iic_compatible_lookup(ia, compat_data)) != NULL)
+               sm = dce->data;
        
        return sm;
 }
diff -r 0344a09858a6 -r 71cdacae46df sys/dev/i2c/pcagpio.c
--- a/sys/dev/i2c/pcagpio.c     Mon Jan 18 13:29:37 2021 +0000
+++ b/sys/dev/i2c/pcagpio.c     Mon Jan 18 15:28:21 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pcagpio.c,v 1.7 2021/01/17 21:56:20 thorpej Exp $ */
+/* $NetBSD: pcagpio.c,v 1.8 2021/01/18 15:28:21 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020 Michael Lorenz
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.7 2021/01/17 21:56:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.8 2021/01/18 15:28:21 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -157,7 +157,7 @@
 
        aprint_naive("\n");
        sc->sc_is_16bit = 0;
-       if (iic_compatible_match(ia, compat_data, &dce))
+       if ((dce = iic_compatible_lookup(ia, compat_data)) != NULL)
                sc->sc_is_16bit = dce->value;
 
        aprint_normal(": %s\n", sc->sc_is_16bit ? "PCA9555" : "PCA9556");
diff -r 0344a09858a6 -r 71cdacae46df sys/dev/i2c/pcai2cmux.c
--- a/sys/dev/i2c/pcai2cmux.c   Mon Jan 18 13:29:37 2021 +0000
+++ b/sys/dev/i2c/pcai2cmux.c   Mon Jan 18 15:28:21 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcai2cmux.c,v 1.2 2021/01/17 21:56:20 thorpej Exp $    */
+/*     $NetBSD: pcai2cmux.c,v 1.3 2021/01/18 15:28:21 thorpej Exp $    */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pcai2cmux.c,v 1.2 2021/01/17 21:56:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcai2cmux.c,v 1.3 2021/01/18 15:28:21 thorpej Exp $");
 
 /*
  * Driver for NXP PCA954x / PCA984x I2C switches and multiplexers.
@@ -276,7 +276,7 @@
        const struct pcaiicmux_type *type = NULL;
        const struct device_compatible_entry *dce;
 
-       if (iic_compatible_match(ia, compat_data, &dce))
+       if ((dce = iic_compatible_lookup(ia, compat_data)) != NULL)
                type = dce->data;
 
        return type;
diff -r 0344a09858a6 -r 71cdacae46df sys/dev/i2c/rkpmic.c
--- a/sys/dev/i2c/rkpmic.c      Mon Jan 18 13:29:37 2021 +0000
+++ b/sys/dev/i2c/rkpmic.c      Mon Jan 18 15:28:21 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rkpmic.c,v 1.9 2021/01/17 21:56:20 thorpej Exp $ */
+/* $NetBSD: rkpmic.c,v 1.10 2021/01/18 15:28:21 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>



Home | Main Index | Thread Index | Old Index