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_entry struct to have a ...



details:   https://anonhg.NetBSD.org/src/rev/9ab2936acf1e
branches:  trunk
changeset: 979957:9ab2936acf1e
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Jan 17 21:56:20 2021 +0000

description:
Change the device_compatible_entry struct to have a union of
a scalar value (uintptr_t value) and a pointer value (const void *data),
rather than just "uintptr_t data".  This eliminates the need for drivers
to cast this value, and doesn't lose const'ness of pointers assigned
to the field.

Update all of the users of this field to use the correct set of
designated initialisers for each specific case.

diffstat:

 sys/dev/i2c/at24cxx.c   |  37 +++++++++++++++++++------------------
 sys/dev/i2c/axppmic.c   |  19 ++++++++++---------
 sys/dev/i2c/ds1307.c    |  38 +++++++++++++++++++-------------------
 sys/dev/i2c/fan53555.c  |  14 ++++++++------
 sys/dev/i2c/m41st84.c   |  13 +++++++------
 sys/dev/i2c/pcagpio.c   |  17 +++++++++--------
 sys/dev/i2c/pcai2cmux.c |  32 ++++++++++++++++----------------
 sys/dev/i2c/rkpmic.c    |  15 ++++++++-------
 sys/sys/device.h        |   7 +++++--
 9 files changed, 101 insertions(+), 91 deletions(-)

diffs (truncated from 479 to 300 lines):

diff -r 1ba78e56e82c -r 9ab2936acf1e sys/dev/i2c/at24cxx.c
--- a/sys/dev/i2c/at24cxx.c     Sun Jan 17 21:42:35 2021 +0000
+++ b/sys/dev/i2c/at24cxx.c     Sun Jan 17 21:56:20 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: at24cxx.c,v 1.36 2020/01/15 06:09:36 thorpej Exp $     */
+/*     $NetBSD: at24cxx.c,v 1.37 2021/01/17 21:56:20 thorpej Exp $     */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.36 2020/01/15 06:09:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.37 2021/01/17 21:56:20 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -112,21 +112,22 @@
 static int seeprom_wait_idle(struct seeprom_softc *);
 
 static const struct device_compatible_entry compat_data[] = {
-       { "i2c-at24c01",                128 },
-       { "i2c-at24c02",                256 },
-       { "i2c-at24c04",                512 },
-       { "i2c-at24c08",                1024 },
-       { "i2c-at24c16",                2048 },
-       { "i2c-at24c32",                4096 },
-       { "i2c-at24c64",                8192 },
-       { "i2c-at24c128",               16384 },
-       { "i2c-at24c256",               32768 },
-       { "i2c-at24c512",               65536 },
-       { "i2c-at34c02",                256 },
-       { "atmel,24c02",                256 },
-       { "atmel,24c16",                2048 },
-       { "atmel,24c256",               32768 },
-       { NULL,                         0 }
+       { .compat = "i2c-at24c01",              .value = 128 },
+       { .compat = "i2c-at24c02",              .value = 256 },
+       { .compat = "i2c-at24c04",              .value = 512 },
+       { .compat = "i2c-at24c08",              .value = 1024 },
+       { .compat = "i2c-at24c16",              .value = 2048 },
+       { .compat = "i2c-at24c32",              .value = 4096 },
+       { .compat = "i2c-at24c64",              .value = 8192 },
+       { .compat = "i2c-at24c128",             .value = 16384 },
+       { .compat = "i2c-at24c256",             .value = 32768 },
+       { .compat = "i2c-at24c512",             .value = 65536 },
+       { .compat = "i2c-at34c02",              .value = 256 },
+       { .compat = "atmel,24c02",              .value = 256 },
+       { .compat = "atmel,24c16",              .value = 2048 },
+       { .compat = "atmel,24c256",             .value = 32768 },
+
+       { 0 }
 };
 
 static int
@@ -182,7 +183,7 @@
 
        if (sc->sc_size <= 0 && ia->ia_ncompat > 0) {
                if (iic_compatible_match(ia, compat_data, &dce))
-                       sc->sc_size = dce->data;
+                       sc->sc_size = dce->value;
        }
 
        switch (sc->sc_size) {
diff -r 1ba78e56e82c -r 9ab2936acf1e sys/dev/i2c/axppmic.c
--- a/sys/dev/i2c/axppmic.c     Sun Jan 17 21:42:35 2021 +0000
+++ b/sys/dev/i2c/axppmic.c     Sun Jan 17 21:56:20 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: axppmic.c,v 1.29 2020/02/16 20:32:29 thorpej Exp $ */
+/* $NetBSD: axppmic.c,v 1.30 2021/01/17 21:56:20 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.29 2020/02/16 20:32:29 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.30 2021/01/17 21:56:20 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -466,12 +466,13 @@
 };
 
 static const struct device_compatible_entry compat_data[] = {
-       { "x-powers,axp803",            (uintptr_t)&axp803_config },
-       { "x-powers,axp805",            (uintptr_t)&axp805_config },
-       { "x-powers,axp806",            (uintptr_t)&axp806_config },
-       { "x-powers,axp809",            (uintptr_t)&axp809_config },
-       { "x-powers,axp813",            (uintptr_t)&axp813_config },
-       { NULL,                         0 }
+       { .compat = "x-powers,axp803",          .data = &axp803_config },
+       { .compat = "x-powers,axp805",          .data = &axp805_config },
+       { .compat = "x-powers,axp806",          .data = &axp806_config },
+       { .compat = "x-powers,axp809",          .data = &axp809_config },
+       { .compat = "x-powers,axp813",          .data = &axp813_config },
+
+       { 0 }
 };
 
 static int
@@ -950,7 +951,7 @@
 
        (void) iic_compatible_match(ia, compat_data, &dce);
        KASSERT(dce != NULL);
-       c = (void *)dce->data;
+       c = dce->data;
 
        sc->sc_dev = self;
        sc->sc_i2c = ia->ia_tag;
diff -r 1ba78e56e82c -r 9ab2936acf1e sys/dev/i2c/ds1307.c
--- a/sys/dev/i2c/ds1307.c      Sun Jan 17 21:42:35 2021 +0000
+++ b/sys/dev/i2c/ds1307.c      Sun Jan 17 21:56:20 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ds1307.c,v 1.34 2020/01/02 16:24:51 thorpej Exp $      */
+/*     $NetBSD: ds1307.c,v 1.35 2021/01/17 21:56:20 thorpej Exp $      */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.34 2020/01/02 16:24:51 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.35 2021/01/17 21:56:20 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -157,28 +157,28 @@
 };
 
 static const struct device_compatible_entry compat_data[] = {
-       { "dallas,ds1307",              (uintptr_t)&ds1307_model },
-       { "maxim,ds1307",               (uintptr_t)&ds1307_model },
-       { "i2c-ds1307",                 (uintptr_t)&ds1307_model },
+       { .compat = "dallas,ds1307",            .data = &ds1307_model },
+       { .compat = "maxim,ds1307",             .data = &ds1307_model },
+       { .compat = "i2c-ds1307",               .data = &ds1307_model },
 
-       { "dallas,ds1339",              (uintptr_t)&ds1339_model },
-       { "maxim,ds1339",               (uintptr_t)&ds1339_model },
+       { .compat = "dallas,ds1339",            .data = &ds1339_model },
+       { .compat = "maxim,ds1339",             .data = &ds1339_model },
 
-       { "dallas,ds1340",              (uintptr_t)&ds1340_model },
-       { "maxim,ds1340",               (uintptr_t)&ds1340_model },
+       { .compat = "dallas,ds1340",            .data = &ds1340_model },
+       { .compat = "maxim,ds1340",             .data = &ds1340_model },
 
-       { "dallas,ds1672",              (uintptr_t)&ds1672_model },
-       { "maxim,ds1672",               (uintptr_t)&ds1672_model },
+       { .compat = "dallas,ds1672",            .data = &ds1672_model },
+       { .compat = "maxim,ds1672",             .data = &ds1672_model },
 
-       { "dallas,ds3231",              (uintptr_t)&ds3231_model },
-       { "maxim,ds3231",               (uintptr_t)&ds3231_model },
+       { .compat = "dallas,ds3231",            .data = &ds3231_model },
+       { .compat = "maxim,ds3231",             .data = &ds3231_model },
 
-       { "dallas,ds3232",              (uintptr_t)&ds3232_model },
-       { "maxim,ds3232",               (uintptr_t)&ds3232_model },
+       { .compat = "dallas,ds3232",            .data = &ds3232_model },
+       { .compat = "maxim,ds3232",             .data = &ds3232_model },
 
-       { "microchip,mcp7940",          (uintptr_t)&mcp7940_model },
+       { .compat = "microchip,mcp7940",        .data = &mcp7940_model },
 
-       { NULL,                         0 }
+       { 0 }
 };
 
 struct dsrtc_softc {
@@ -242,7 +242,7 @@
                return &ds1307_model;
 
        for (dce = compat_data; dce->compat != NULL; dce++) {
-               dm = (void *)dce->data;
+               dm = dce->data;
                if (dm->dm_model == model)
                        return dm;
        }
@@ -256,7 +256,7 @@
        const struct device_compatible_entry *dce;
 
        if (iic_compatible_match(ia, compat_data, &dce))
-               dm = (void *)dce->data;
+               dm = dce->data;
 
        return dm;
 }
diff -r 1ba78e56e82c -r 9ab2936acf1e sys/dev/i2c/fan53555.c
--- a/sys/dev/i2c/fan53555.c    Sun Jan 17 21:42:35 2021 +0000
+++ b/sys/dev/i2c/fan53555.c    Sun Jan 17 21:56:20 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fan53555.c,v 1.5 2019/12/23 19:22:46 thorpej Exp $ */
+/* $NetBSD: fan53555.c,v 1.6 2021/01/17 21:56:20 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.5 2019/12/23 19:22:46 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fan53555.c,v 1.6 2021/01/17 21:56:20 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -90,9 +90,10 @@
 };
 
 static const struct device_compatible_entry compat_data[] = {
-       { "silergy,syr827",             FAN_VENDOR_SILERGY },
-       { "silergy,syr828",             FAN_VENDOR_SILERGY },
-       { NULL,                         0 }
+       { .compat = "silergy,syr827",   .value = FAN_VENDOR_SILERGY },
+       { .compat = "silergy,syr828",   .value = FAN_VENDOR_SILERGY },
+
+       { 0 }
 };
 
 static uint8_t
@@ -310,8 +311,9 @@
        sc->sc_phandle = ia->ia_cookie;
 
        iic_compatible_match(ia, compat_data, &compat);
+       KASSERT(compat != NULL);
 
-       if (fan53555_init(sc, compat->data) != 0)
+       if (fan53555_init(sc, compat->value) != 0)
                return;
 
        fdtbus_register_regulator_controller(self, sc->sc_phandle,
diff -r 1ba78e56e82c -r 9ab2936acf1e sys/dev/i2c/m41st84.c
--- a/sys/dev/i2c/m41st84.c     Sun Jan 17 21:42:35 2021 +0000
+++ b/sys/dev/i2c/m41st84.c     Sun Jan 17 21:56:20 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: m41st84.c,v 1.27 2020/01/03 03:44:42 thorpej Exp $     */
+/*     $NetBSD: m41st84.c,v 1.28 2021/01/17 21:56:20 thorpej Exp $     */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: m41st84.c,v 1.27 2020/01/03 03:44:42 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m41st84.c,v 1.28 2021/01/17 21:56:20 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -81,10 +81,11 @@
 };
 
 static const struct device_compatible_entry compat_data[] = {
-       { "st,m41t80",          (uintptr_t)&m41t80_model },
-       { "st,m41t81",          (uintptr_t)&m41t81_model },
-       { "st,m41t84",          (uintptr_t)&m48t84_model },
-       { NULL,                 0 },
+       { .compat = "st,m41t80",        .data = &m41t80_model },
+       { .compat = "st,m41t81",        .data = &m41t81_model },
+       { .compat = "st,m41t84",        .data = &m48t84_model },
+
+       { 0 }
 };
 
 struct strtc_softc {
diff -r 1ba78e56e82c -r 9ab2936acf1e sys/dev/i2c/pcagpio.c
--- a/sys/dev/i2c/pcagpio.c     Sun Jan 17 21:42:35 2021 +0000
+++ b/sys/dev/i2c/pcagpio.c     Sun Jan 17 21:56:20 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pcagpio.c,v 1.6 2020/10/31 14:38:54 jdc Exp $ */
+/* $NetBSD: pcagpio.c,v 1.7 2021/01/17 21:56:20 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020 Michael Lorenz
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.6 2020/10/31 14:38:54 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.7 2021/01/17 21:56:20 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -99,11 +99,12 @@
     pcagpio_match, pcagpio_attach, pcagpio_detach, NULL);
 
 static const struct device_compatible_entry compat_data[] = {
-       { "i2c-pca9555",        1 },
-       { "pca9555",            1 },
-       { "i2c-pca9556",        0 },
-       { "pca9556",            0 },
-       { NULL,                 0 }
+       { .compat = "i2c-pca9555",      .value = 1 },
+       { .compat = "pca9555",          .value = 1 },
+       { .compat = "i2c-pca9556",      .value = 0 },
+       { .compat = "pca9556",          .value = 0 },



Home | Main Index | Thread Index | Old Index