Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm Use device_compatible_entry / of_search_compati...



details:   https://anonhg.NetBSD.org/src/rev/af3bf16ea560
branches:  trunk
changeset: 1018030:af3bf16ea560
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Tue Jan 19 00:38:52 2021 +0000

description:
Use device_compatible_entry / of_search_compatible() rather than
matching against multiple sets of compatibility strings.

diffstat:

 sys/arch/arm/broadcom/bcm2835_intr.c |  30 +++++++++++++++++-------------
 sys/arch/arm/rockchip/rk_tsadc.c     |  26 ++++++++------------------
 sys/arch/arm/samsung/exynos_dwcmmc.c |  24 ++++++++++++++----------
 3 files changed, 39 insertions(+), 41 deletions(-)

diffs (204 lines):

diff -r d584fa4297bd -r af3bf16ea560 sys/arch/arm/broadcom/bcm2835_intr.c
--- a/sys/arch/arm/broadcom/bcm2835_intr.c      Tue Jan 19 00:36:09 2021 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_intr.c      Tue Jan 19 00:38:52 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bcm2835_intr.c,v 1.34 2021/01/15 00:38:22 jmcneill Exp $       */
+/*     $NetBSD: bcm2835_intr.c,v 1.35 2021/01/19 00:38:52 thorpej Exp $        */
 
 /*-
  * Copyright (c) 2012, 2015, 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_intr.c,v 1.34 2021/01/15 00:38:22 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_intr.c,v 1.35 2021/01/19 00:38:52 thorpej Exp $");
 
 #define _INTR_PRIVATE
 
@@ -254,20 +254,21 @@
 CFATTACH_DECL_NEW(bcmicu, sizeof(struct bcm2835icu_softc),
     bcm2835_icu_match, bcm2835_icu_attach, NULL, NULL);
 
+static const struct device_compatible_entry compat_data[] = {
+       { .compat = "brcm,bcm2708-armctrl-ic",  .value = 0 },
+       { .compat = "brcm,bcm2709-armctrl-ic",  .value = 0 },
+       { .compat = "brcm,bcm2835-armctrl-ic",  .value = 0 },
+       { .compat = "brcm,bcm2836-armctrl-ic",  .value = 0 },
+       { .compat = "brcm,bcm2836-l1-intc",     .value = 1 },
+       { 0 }
+};
+
 static int
 bcm2835_icu_match(device_t parent, cfdata_t cf, void *aux)
 {
-       const char * const compatible[] = {
-           "brcm,bcm2708-armctrl-ic",
-           "brcm,bcm2709-armctrl-ic",
-           "brcm,bcm2835-armctrl-ic",
-           "brcm,bcm2836-armctrl-ic",
-           "brcm,bcm2836-l1-intc",
-           NULL
-       };
        struct fdt_attach_args * const faa = aux;
 
-       return of_match_compatible(faa->faa_phandle, compatible);
+       return of_match_compat_data(faa->faa_phandle, compat_data);
 }
 
 static void
@@ -276,6 +277,7 @@
        struct bcm2835icu_softc * const sc = device_private(self);
        struct fdt_attach_args * const faa = aux;
        struct fdtbus_interrupt_controller_func *ifuncs;
+       const struct device_compatible_entry *dce;
        const int phandle = faa->faa_phandle;
        bus_addr_t addr;
        bus_size_t size;
@@ -298,8 +300,10 @@
        sc->sc_ioh = ioh;
        sc->sc_phandle = phandle;
 
-       const char * const local_intc[] = { "brcm,bcm2836-l1-intc", NULL };
-       if (of_match_compatible(faa->faa_phandle, local_intc)) {
+       dce = of_search_compatible(faa->faa_phandle, compat_data);
+       KASSERT(dce != NULL);
+
+       if (dce->value != 0) {
 #if defined(MULTIPROCESSOR)
                aprint_normal(": Multiprocessor");
 #endif
diff -r d584fa4297bd -r af3bf16ea560 sys/arch/arm/rockchip/rk_tsadc.c
--- a/sys/arch/arm/rockchip/rk_tsadc.c  Tue Jan 19 00:36:09 2021 +0000
+++ b/sys/arch/arm/rockchip/rk_tsadc.c  Tue Jan 19 00:38:52 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rk_tsadc.c,v 1.8 2021/01/15 18:42:41 ryo Exp $ */
+/*     $NetBSD: rk_tsadc.c,v 1.9 2021/01/19 00:38:52 thorpej Exp $     */
 
 /*
  * Copyright (c) 2019 Matthew R. Green
@@ -30,7 +30,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: rk_tsadc.c,v 1.8 2021/01/15 18:42:41 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rk_tsadc.c,v 1.9 2021/01/19 00:38:52 thorpej Exp $");
 
 /*
  * Driver for the TSADC temperature sensor monitor in RK3328 and RK3399.
@@ -374,14 +374,10 @@
        .rd_num_sensors = 2,
 };
 
-static const char * const compatible_rk3328[] = {
-       "rockchip,rk3328-tsadc",
-       NULL
-};
-
-static const char * const compatible_rk3399[] = {
-       "rockchip,rk3399-tsadc",
-       NULL
+static const struct device_compatible_entry compat_data[] = {
+       { .compat = "rockchip,rk3328-tsadc",    .data = &rk3328_data_table },
+       { .compat = "rockchip,rk3399-tsadc",    .data = &rk3399_data_table },
+       { 0 }
 };
 
 #define        TSADC_READ(sc, reg)             \
@@ -399,8 +395,7 @@
 {
        struct fdt_attach_args * const faa = aux;
 
-       return of_match_compatible(faa->faa_phandle, compatible_rk3328) ||
-              of_match_compatible(faa->faa_phandle, compatible_rk3399);
+       return of_match_compat_data(faa->faa_phandle, compat_data);
 }
 
 static void
@@ -430,12 +425,7 @@
 
        pmf_device_register(self, NULL, NULL);
 
-       if (of_match_compatible(faa->faa_phandle, compatible_rk3328)) {
-               sc->sc_rd = &rk3328_data_table;
-       } else {
-               KASSERT(of_match_compatible(faa->faa_phandle, compatible_rk3399));
-               sc->sc_rd = &rk3399_data_table;
-       }
+       sc->sc_rd = of_search_compatible(faa->faa_phandle, compat_data)->data;
 
        /* Default to tshut via gpio and tshut low is active */
        if (of_getprop_uint32(phandle, "rockchip,hw-tshut-mode",
diff -r d584fa4297bd -r af3bf16ea560 sys/arch/arm/samsung/exynos_dwcmmc.c
--- a/sys/arch/arm/samsung/exynos_dwcmmc.c      Tue Jan 19 00:36:09 2021 +0000
+++ b/sys/arch/arm/samsung/exynos_dwcmmc.c      Tue Jan 19 00:38:52 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exynos_dwcmmc.c,v 1.10 2020/03/20 06:23:51 skrll Exp $ */
+/* $NetBSD: exynos_dwcmmc.c,v 1.11 2021/01/19 00:38:52 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exynos_dwcmmc.c,v 1.10 2020/03/20 06:23:51 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exynos_dwcmmc.c,v 1.11 2021/01/19 00:38:52 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -69,11 +69,12 @@
 CFATTACH_DECL_NEW(exynos_dwcmmc, sizeof(struct exynos_dwcmmc_softc),
        exynos_dwcmmc_match, exynos_dwcmmc_attach, NULL, NULL);
 
-static const char * const exynos_dwcmmc_compat[] = {
-       "samsung,exynos5250-dw-mshc",
-       "samsung,exynos5420-dw-mshc-smu",
-       "samsung,exynos5420-dw-mshc",
-       NULL
+static const struct device_compatible_entry compat_data[] = {
+                                               /* disable encryption mode? */
+       { .compat = "samsung,exynos5250-dw-mshc",       .value = 0 },
+       { .compat = "samsung,exynos5420-dw-mshc-smu",   .value = 1 },
+       { .compat = "samsung,exynos5420-dw-mshc",       .value = 0 },
+       { 0 }
 };
 
 static int
@@ -81,7 +82,7 @@
 {
        struct fdt_attach_args * const faa = aux;
 
-       return of_match_compatible(faa->faa_phandle, exynos_dwcmmc_compat);
+       return of_match_compat_data(faa->faa_phandle, compat_data);
 }
 
 static void
@@ -90,6 +91,7 @@
        struct exynos_dwcmmc_softc *esc = device_private(self);
        struct dwc_mmc_softc *sc = &esc->sc;
        struct fdt_attach_args * const faa = aux;
+       const struct device_compatible_entry *dce;
        const int phandle = faa->faa_phandle;
        char intrstr[128];
        bus_addr_t addr;
@@ -128,6 +130,9 @@
                return;
        }
 
+       dce = of_search_compatible(faa->faa_phandle, compat_data);
+       KASSERT(dce != NULL);
+
        sc->sc_dev = self;
        sc->sc_bst = faa->faa_bst;
        sc->sc_dmat = faa->faa_dmat;
@@ -170,8 +175,7 @@
        aprint_normal_dev(self, "interrupting on %s\n", intrstr);
 
        /* Disable encryption mode */
-       const char * compat_enc[] = { "samsung,exynos5420-dw-mshc-smu", NULL };
-       if (of_match_compatible(phandle, compat_enc)) {
+       if (dce->value != 0) {
                bus_space_write_4(sc->sc_bst, sc->sc_bsh, MPS_BEGIN, 0);
                bus_space_write_4(sc->sc_bst, sc->sc_bsh, MPS_END, ~0U);
                bus_space_write_4(sc->sc_bst, sc->sc_bsh, MPS_CTRL,



Home | Main Index | Thread Index | Old Index