Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c Use the device_compatible_entry mechanism rather...



details:   https://anonhg.NetBSD.org/src/rev/fea79c1f34fc
branches:  trunk
changeset: 320004:fea79c1f34fc
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Tue Jun 19 02:08:12 2018 +0000

description:
Use the device_compatible_entry mechanism rather than of_compat_data;
all of the OF / FDT data we need is already in the i2c_attach_args.

diffstat:

 sys/dev/i2c/axppmic.c |  39 ++++++++++++++++-----------------------
 1 files changed, 16 insertions(+), 23 deletions(-)

diffs (96 lines):

diff -r f71ddd6d6991 -r fea79c1f34fc sys/dev/i2c/axppmic.c
--- a/sys/dev/i2c/axppmic.c     Tue Jun 19 01:24:17 2018 +0000
+++ b/sys/dev/i2c/axppmic.c     Tue Jun 19 02:08:12 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: axppmic.c,v 1.11 2018/06/16 21:22:13 thorpej Exp $ */
+/* $NetBSD: axppmic.c,v 1.12 2018/06/19 02:08:12 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.11 2018/06/16 21:22:13 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.12 2018/06/19 02:08:12 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -264,6 +264,7 @@
        i2c_addr_t      reg_addr;
 };
 
+static const char *axp803_compatstrings[] = { "x-powers,axp803", NULL };
 static const struct axppmic_config axp803_config = {
        .name = "AXP803",
        .controls = axp803_ctrls,
@@ -282,6 +283,8 @@
        .chargestirq = AXPPMIC_IRQ(4, __BITS(1,0)),     
 };
 
+static const char *axp805_compatstrings[] = { "x-powers,axp805",
+                                             "x-powers,axp806", NULL };
 static const struct axppmic_config axp805_config = {
        .name = "AXP805/806",
        .controls = axp805_ctrls,
@@ -290,11 +293,10 @@
        .poklirq = AXPPMIC_IRQ(2, __BIT(0)),
 };
 
-static const struct of_compat_data compat_data[] = {
-       { "x-powers,axp803",    (uintptr_t)&axp803_config },
-       { "x-powers,axp805",    (uintptr_t)&axp805_config },
-       { "x-powers,axp806",    (uintptr_t)&axp805_config },
-       { NULL }
+static const struct device_compatible_entry axppmic_compat_data[] = {
+       DEVICE_COMPAT_ENTRY_WITH_DATA(axp803_compatstrings, &axp803_config),
+       DEVICE_COMPAT_ENTRY_WITH_DATA(axp805_compatstrings, &axp805_config),
+       DEVICE_COMPAT_TERMINATOR
 };
 
 static int
@@ -678,22 +680,10 @@
 axppmic_match(device_t parent, cfdata_t match, void *aux)
 {
        struct i2c_attach_args *ia = aux;
+       int match_result;
 
-       /* XXXJRT Gross. */
-       if (ia->ia_name != NULL) {
-               if (ia->ia_cookie) {
-                       int match_result =
-                           of_match_compat_data(ia->ia_cookie, compat_data);
-                       if (match_result) {
-                               match_result = match_result - 1 +
-                                   I2C_MATCH_DIRECT_COMPATIBLE;
-                               match_result = MIN(match_result,
-                                   I2C_MATCH_DIRECT_COMPATIBLE_MAX);
-                       }
-                       return match_result;
-               } else
-                       return 0;
-       }
+       if (iic_use_direct_match(ia, match, axppmic_compat_data, &match_result))
+               return match_result;
 
        /* This device is direct-config only. */
 
@@ -704,6 +694,7 @@
 axppmic_attach(device_t parent, device_t self, void *aux)
 {
        struct axppmic_softc *sc = device_private(self);
+       const struct device_compatible_entry *dce;
        const struct axppmic_config *c;
        struct axpreg_attach_args aaa;
        struct i2c_attach_args *ia = aux;
@@ -711,7 +702,9 @@
        uint32_t irq_mask;
        void *ih;
 
-       c = (void *)of_search_compatible(ia->ia_cookie, compat_data)->data;
+       dce = iic_compatible_match(ia, axppmic_compat_data, NULL);
+       KASSERT(dce != NULL);
+       c = DEVICE_COMPAT_ENTRY_GET_PTR(dce);
 
        sc->sc_dev = self;
        sc->sc_i2c = ia->ia_tag;



Home | Main Index | Thread Index | Old Index