Module Name:    src
Committed By:   thorpej
Date:           Tue Jan 19 00:38:52 UTC 2021

Modified Files:
        src/sys/arch/arm/broadcom: bcm2835_intr.c
        src/sys/arch/arm/rockchip: rk_tsadc.c
        src/sys/arch/arm/samsung: exynos_dwcmmc.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/arm/broadcom/bcm2835_intr.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/arm/rockchip/rk_tsadc.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/arm/samsung/exynos_dwcmmc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/broadcom/bcm2835_intr.c
diff -u src/sys/arch/arm/broadcom/bcm2835_intr.c:1.34 src/sys/arch/arm/broadcom/bcm2835_intr.c:1.35
--- src/sys/arch/arm/broadcom/bcm2835_intr.c:1.34	Fri Jan 15 00:38:22 2021
+++ src/sys/arch/arm/broadcom/bcm2835_intr.c	Tue Jan 19 00:38:52 2021
@@ -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 @@ static const char * const bcm2836mp_sour
 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 @@ bcm2835_icu_attach(device_t parent, devi
 	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 @@ bcm2835_icu_attach(device_t parent, devi
 	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

Index: src/sys/arch/arm/rockchip/rk_tsadc.c
diff -u src/sys/arch/arm/rockchip/rk_tsadc.c:1.8 src/sys/arch/arm/rockchip/rk_tsadc.c:1.9
--- src/sys/arch/arm/rockchip/rk_tsadc.c:1.8	Fri Jan 15 18:42:41 2021
+++ src/sys/arch/arm/rockchip/rk_tsadc.c	Tue Jan 19 00:38:52 2021
@@ -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 @@ static const rk_data rk3399_data_table =
 	.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 @@ rk_tsadc_match(device_t parent, cfdata_t
 {
 	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 @@ rk_tsadc_attach(device_t parent, device_
 
 	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",

Index: src/sys/arch/arm/samsung/exynos_dwcmmc.c
diff -u src/sys/arch/arm/samsung/exynos_dwcmmc.c:1.10 src/sys/arch/arm/samsung/exynos_dwcmmc.c:1.11
--- src/sys/arch/arm/samsung/exynos_dwcmmc.c:1.10	Fri Mar 20 06:23:51 2020
+++ src/sys/arch/arm/samsung/exynos_dwcmmc.c	Tue Jan 19 00:38:52 2021
@@ -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 <[email protected]>
@@ -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 @@ struct exynos_dwcmmc_softc {
 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 @@ exynos_dwcmmc_match(device_t parent, cfd
 {
 	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 @@ exynos_dwcmmc_attach(device_t parent, de
 	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 @@ exynos_dwcmmc_attach(device_t parent, de
 		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 @@ exynos_dwcmmc_attach(device_t parent, de
 	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,

Reply via email to