Module Name: src Committed By: thorpej Date: Mon Jun 18 17:07:07 UTC 2018
Modified Files: src/sys/arch/macppc/dev: deq.c smusat.c src/sys/arch/sparc64/dev: pcf8591_envctrl.c src/sys/dev/i2c: adadc.c adm1021.c adm1026.c as3722.c at24cxx.c axp20x.c axp22x.c dbcool.c ds1307.c dstemp.c fcu.c i2c.c i2cvar.h ihidev.c lm75.c lm87.c max77620.c pcf8563.c sy8106a.c tcagpio.c tcakp.c titemp.c tsl256x.c Log Message: - Rename iic_compat_match() to iic_compatible_match() and change it to use the new device_compatible_match() routine. A pointer to the matching device_compatible_entry is returned if a match is found. - Adjust iic_use_direct_match() accordingly. - i2c drivers now provide device_compatible_entry tables when performing direct-config matching. - In the dsrtc driver, take advantage of this new capability to greatly simplify model selection. (I'm coming for you next, of_compat_data...) To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/sys/arch/macppc/dev/deq.c cvs rdiff -u -r1.4 -r1.5 src/sys/arch/macppc/dev/smusat.c cvs rdiff -u -r1.7 -r1.8 src/sys/arch/sparc64/dev/pcf8591_envctrl.c cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/adadc.c src/sys/dev/i2c/axp22x.c \ src/sys/dev/i2c/fcu.c src/sys/dev/i2c/max77620.c \ src/sys/dev/i2c/tsl256x.c cvs rdiff -u -r1.17 -r1.18 src/sys/dev/i2c/adm1021.c cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/adm1026.c src/sys/dev/i2c/ihidev.c cvs rdiff -u -r1.13 -r1.14 src/sys/dev/i2c/as3722.c cvs rdiff -u -r1.26 -r1.27 src/sys/dev/i2c/at24cxx.c src/sys/dev/i2c/ds1307.c cvs rdiff -u -r1.11 -r1.12 src/sys/dev/i2c/axp20x.c cvs rdiff -u -r1.49 -r1.50 src/sys/dev/i2c/dbcool.c cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/dstemp.c src/sys/dev/i2c/sy8106a.c \ src/sys/dev/i2c/tcagpio.c cvs rdiff -u -r1.62 -r1.63 src/sys/dev/i2c/i2c.c cvs rdiff -u -r1.14 -r1.15 src/sys/dev/i2c/i2cvar.h cvs rdiff -u -r1.31 -r1.32 src/sys/dev/i2c/lm75.c cvs rdiff -u -r1.8 -r1.9 src/sys/dev/i2c/lm87.c cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/pcf8563.c cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/tcakp.c cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/titemp.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/macppc/dev/deq.c diff -u src/sys/arch/macppc/dev/deq.c:1.14 src/sys/arch/macppc/dev/deq.c:1.15 --- src/sys/arch/macppc/dev/deq.c:1.14 Sat Jun 16 21:22:13 2018 +++ src/sys/arch/macppc/dev/deq.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: deq.c,v 1.14 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: deq.c,v 1.15 2018/06/18 17:07:07 thorpej Exp $ */ /*- * Copyright (C) 2005 Michael Lorenz @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: deq.c,v 1.14 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: deq.c,v 1.15 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -61,13 +61,18 @@ static const char * deq_compats[] = { NULL }; +static const struct device_compatible_entry deq_compat_data[] = { + DEVICE_COMPAT_ENTRY(deq_compats), + DEVICE_COMPAT_TERMINATOR +}; + int deq_match(device_t parent, struct cfdata *cf, void *aux) { struct i2c_attach_args *ia = aux; int match_result; - if (iic_use_direct_match(ia, cf, deq_compats, &match_result)) + if (iic_use_direct_match(ia, cf, deq_compat_data, &match_result)) return match_result; /* This driver is direct-config only. */ Index: src/sys/arch/macppc/dev/smusat.c diff -u src/sys/arch/macppc/dev/smusat.c:1.4 src/sys/arch/macppc/dev/smusat.c:1.5 --- src/sys/arch/macppc/dev/smusat.c:1.4 Sat Jun 16 21:22:13 2018 +++ src/sys/arch/macppc/dev/smusat.c Mon Jun 18 17:07:07 2018 @@ -111,13 +111,18 @@ static const char * smusat_compats[] = { NULL }; +static const struct device_compatible_entry smusat_compat_data[] = { + DEVICE_COMPAT_ENTRY(smusat_compats), + DEVICE_COMPAT_TERMINATOR +}; + static int smusat_match(device_t parent, struct cfdata *cf, void *aux) { struct i2c_attach_args *ia = aux; int match_result; - if (iic_use_direct_match(ia, cf, smusat_compats, &match_result)) + if (iic_use_direct_match(ia, cf, smusat_compat_data, &match_result)) return match_result; if (ia->ia_addr == 0x58) Index: src/sys/arch/sparc64/dev/pcf8591_envctrl.c diff -u src/sys/arch/sparc64/dev/pcf8591_envctrl.c:1.7 src/sys/arch/sparc64/dev/pcf8591_envctrl.c:1.8 --- src/sys/arch/sparc64/dev/pcf8591_envctrl.c:1.7 Sat Jun 16 21:22:13 2018 +++ src/sys/arch/sparc64/dev/pcf8591_envctrl.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: pcf8591_envctrl.c,v 1.7 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: pcf8591_envctrl.c,v 1.8 2018/06/18 17:07:07 thorpej Exp $ */ /* $OpenBSD: pcf8591_envctrl.c,v 1.6 2007/10/25 21:17:20 kettenis Exp $ */ /* @@ -19,7 +19,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pcf8591_envctrl.c,v 1.7 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcf8591_envctrl.c,v 1.8 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -74,13 +74,18 @@ static const char * ecadc_compats[] = { NULL }; +static const struct device_compatible_entry ecadc_compat_data[] = { + DEVICE_COMPAT_ENTRY(ecadc_compats), + DEVICE_COMPAT_TERMINATOR +}; + static int ecadc_match(device_t parent, cfdata_t cf, void *aux) { struct i2c_attach_args *ia = aux; int match_result; - if (iic_use_direct_match(ia, cf, ecadc_compats, &match_result)) + if (iic_use_direct_match(ia, cf, ecadc_compat_data, &match_result)) return match_result; /* This driver is direct-config only. */ Index: src/sys/dev/i2c/adadc.c diff -u src/sys/dev/i2c/adadc.c:1.4 src/sys/dev/i2c/adadc.c:1.5 --- src/sys/dev/i2c/adadc.c:1.4 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/adadc.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: adadc.c,v 1.4 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: adadc.c,v 1.5 2018/06/18 17:07:07 thorpej Exp $ */ /*- * Copyright (c) 2018 Michael Lorenz @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: adadc.c,v 1.4 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adadc.c,v 1.5 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -93,11 +93,16 @@ static void adadc_sensors_refresh(struct CFATTACH_DECL_NEW(adadc, sizeof(struct adadc_softc), adadc_match, adadc_attach, NULL, NULL); -static const char * dstemp_compats[] = { +static const char * adadc_compats[] = { "ad7417", NULL }; +static const struct device_compatible_entry adadc_compat_data[] = { + DEVICE_COMPAT_ENTRY(adadc_compats), + DEVICE_COMPAT_TERMINATOR +}; + /* calibaration table from Darwin via Linux */ static int slope[5] = {0, 0, 0x0320, 0x00a0, 0x1f40}; @@ -107,7 +112,7 @@ adadc_match(device_t parent, cfdata_t ma struct i2c_attach_args *ia = aux; int match_result; - if (iic_use_direct_match(ia, match, dstemp_compats, &match_result)) + if (iic_use_direct_match(ia, match, adadc_compat_data, &match_result)) return match_result; /* Index: src/sys/dev/i2c/axp22x.c diff -u src/sys/dev/i2c/axp22x.c:1.4 src/sys/dev/i2c/axp22x.c:1.5 --- src/sys/dev/i2c/axp22x.c:1.4 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/axp22x.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: axp22x.c,v 1.4 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: axp22x.c,v 1.5 2018/06/18 17:07:07 thorpej Exp $ */ /*- * Copyright (c) 2014 Jared D. McNeill <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: axp22x.c,v 1.4 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axp22x.c,v 1.5 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -45,6 +45,11 @@ static const char *compatible[] = { NULL }; +static const struct device_compatible_entry axp22x_compat_data[] = { + DEVICE_COMPAT_ENTRY(compatible), + DEVICE_COMPAT_TERMINATOR +}; + #define AXP_TEMP_MON_REG 0x56 /* 2 bytes */ struct axp22x_softc { @@ -71,7 +76,7 @@ axp22x_match(device_t parent, cfdata_t m struct i2c_attach_args *ia = aux; int match_result; - if (iic_use_direct_match(ia, match, compatible, &match_result)) + if (iic_use_direct_match(ia, match, axp22x_compat_data, &match_result)) return match_result; /* This device is direct-config only. */ Index: src/sys/dev/i2c/fcu.c diff -u src/sys/dev/i2c/fcu.c:1.4 src/sys/dev/i2c/fcu.c:1.5 --- src/sys/dev/i2c/fcu.c:1.4 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/fcu.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: fcu.c,v 1.4 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: fcu.c,v 1.5 2018/06/18 17:07:07 thorpej Exp $ */ /*- * Copyright (c) 2018 Michael Lorenz @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: fcu.c,v 1.4 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fcu.c,v 1.5 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -120,13 +120,18 @@ static const char * fcu_compats[] = { NULL }; +static const struct device_compatible_entry fcu_compat_data[] = { + DEVICE_COMPAT_ENTRY(fcu_compats), + DEVICE_COMPAT_TERMINATOR +}; + static int fcu_match(device_t parent, cfdata_t match, void *aux) { struct i2c_attach_args *ia = aux; int match_result; - if (iic_use_direct_match(ia, match, fcu_compats, &match_result)) + if (iic_use_direct_match(ia, match, fcu_compat_data, &match_result)) return match_result; if (ia->ia_addr == 0x2f) Index: src/sys/dev/i2c/max77620.c diff -u src/sys/dev/i2c/max77620.c:1.4 src/sys/dev/i2c/max77620.c:1.5 --- src/sys/dev/i2c/max77620.c:1.4 Sun Jun 17 14:50:54 2018 +++ src/sys/dev/i2c/max77620.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: max77620.c,v 1.4 2018/06/17 14:50:54 thorpej Exp $ */ +/* $NetBSD: max77620.c,v 1.5 2018/06/18 17:07:07 thorpej Exp $ */ /*- * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: max77620.c,v 1.4 2018/06/17 14:50:54 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: max77620.c,v 1.5 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -71,6 +71,11 @@ static const char * max77620_compats[] = NULL }; +static const struct device_compatible_entry max77620_compat_data[] = { + DEVICE_COMPAT_ENTRY(max77620_compats), + DEVICE_COMPAT_TERMINATOR +}; + static uint8_t max77620_read(struct max77620_softc *sc, uint8_t reg, int flags) { @@ -260,7 +265,8 @@ max77620_match(device_t parent, cfdata_t struct i2c_attach_args *ia = aux; int match_result; - if (iic_use_direct_match(ia, match, max77620_compats, &match_result)) + if (iic_use_direct_match(ia, match, max77620_compat_data, + &match_result)) return match_result; return 0; Index: src/sys/dev/i2c/tsl256x.c diff -u src/sys/dev/i2c/tsl256x.c:1.4 src/sys/dev/i2c/tsl256x.c:1.5 --- src/sys/dev/i2c/tsl256x.c:1.4 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/tsl256x.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: tsl256x.c,v 1.4 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: tsl256x.c,v 1.5 2018/06/18 17:07:07 thorpej Exp $ */ /*- * Copyright (c) 2018 Jason R. Thorpe @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tsl256x.c,v 1.4 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tsl256x.c,v 1.5 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -84,6 +84,11 @@ static const char *tsllux_compats[] = { NULL }; +static const struct device_compatible_entry tsllux_compat_data[] = { + DEVICE_COMPAT_ENTRY(tsllux_compats), + DEVICE_COMPAT_TERMINATOR +}; + static int tsllux_read1(struct tsllux_softc *, uint8_t, uint8_t *); static int tsllux_read2(struct tsllux_softc *, uint8_t, uint16_t *); static int tsllux_write1(struct tsllux_softc *, uint8_t, uint8_t); @@ -112,7 +117,7 @@ tsllux_match(device_t parent, cfdata_t m uint8_t id_reg; int error, match_result; - if (iic_use_direct_match(ia, match, tsllux_compats, &match_result)) + if (iic_use_direct_match(ia, match, tsllux_compat_data, &match_result)) return (match_result); switch (ia->ia_addr) { Index: src/sys/dev/i2c/adm1021.c diff -u src/sys/dev/i2c/adm1021.c:1.17 src/sys/dev/i2c/adm1021.c:1.18 --- src/sys/dev/i2c/adm1021.c:1.17 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/adm1021.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: adm1021.c,v 1.17 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: adm1021.c,v 1.18 2018/06/18 17:07:07 thorpej Exp $ */ /* $OpenBSD: adm1021.c,v 1.27 2007/06/24 05:34:35 dlg Exp $ */ /* @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.17 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.18 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -158,13 +158,18 @@ static const char * admtemp_compats[] = NULL }; +static const struct device_compatible_entry admtemp_compat_data[] = { + DEVICE_COMPAT_ENTRY(admtemp_compats), + DEVICE_COMPAT_TERMINATOR +}; + int admtemp_match(device_t parent, cfdata_t match, void *aux) { struct i2c_attach_args *ia = aux; int match_result; - if (iic_use_direct_match(ia, match, admtemp_compats, &match_result)) + if (iic_use_direct_match(ia, match, admtemp_compat_data, &match_result)) return match_result; /* Index: src/sys/dev/i2c/adm1026.c diff -u src/sys/dev/i2c/adm1026.c:1.3 src/sys/dev/i2c/adm1026.c:1.4 --- src/sys/dev/i2c/adm1026.c:1.3 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/adm1026.c Mon Jun 18 17:07:07 2018 @@ -28,7 +28,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: adm1026.c,v 1.3 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adm1026.c,v 1.4 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -127,6 +127,11 @@ static const char * adm1026_compats[] = NULL }; +static const struct device_compatible_entry adm1026_compat_data[] = { + DEVICE_COMPAT_ENTRY(adm1026_compats), + DEVICE_COMPAT_TERMINATOR +}; + static int adm1026_match(device_t parent, cfdata_t cf, void *aux) { @@ -138,7 +143,7 @@ adm1026_match(device_t parent, cfdata_t sc.sc_address = ia->ia_addr; sc.sc_iic_flags = 0; - if (iic_use_direct_match(ia, cf, adm1026_compats, &match_result)) + if (iic_use_direct_match(ia, cf, adm1026_compat_data, &match_result)) return match_result; if ((ia->ia_addr & ADM1026_ADDRMASK) == ADM1026_ADDR && Index: src/sys/dev/i2c/ihidev.c diff -u src/sys/dev/i2c/ihidev.c:1.3 src/sys/dev/i2c/ihidev.c:1.4 --- src/sys/dev/i2c/ihidev.c:1.3 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/ihidev.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.3 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: ihidev.c,v 1.4 2018/06/18 17:07:07 thorpej Exp $ */ /* $OpenBSD ihidev.c,v 1.13 2017/04/08 02:57:23 deraadt Exp $ */ /*- @@ -54,7 +54,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.3 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.4 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -125,13 +125,18 @@ static const char *ihidev_compats[] = { NULL }; +static const struct device_compatible_entry ihidev_compat_data[] = { + DEVICE_COMPAT_ENTRY(ihidev_compats), + DEVICE_COMPAT_TERMINATOR +}; + static int ihidev_match(device_t parent, cfdata_t match, void *aux) { struct i2c_attach_args * const ia = aux; int match_result; - if (iic_use_direct_match(ia, match, ihidev_compats, &match_result)) + if (iic_use_direct_match(ia, match, ihidev_compat_data, &match_result)) return I2C_MATCH_DIRECT_COMPATIBLE; return 0; Index: src/sys/dev/i2c/as3722.c diff -u src/sys/dev/i2c/as3722.c:1.13 src/sys/dev/i2c/as3722.c:1.14 --- src/sys/dev/i2c/as3722.c:1.13 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/as3722.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: as3722.c,v 1.13 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: as3722.c,v 1.14 2018/06/18 17:07:07 thorpej Exp $ */ /*- * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca> @@ -29,7 +29,7 @@ #include "opt_fdt.h" #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: as3722.c,v 1.13 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: as3722.c,v 1.14 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -227,6 +227,11 @@ static const char * as3722_compats[] = { NULL }; +static const struct device_compatible_entry as3722_compat_data[] = { + DEVICE_COMPAT_ENTRY(as3722_compats), + DEVICE_COMPAT_TERMINATOR +}; + static int as3722_match(device_t parent, cfdata_t match, void *aux) { @@ -234,7 +239,7 @@ as3722_match(device_t parent, cfdata_t m uint8_t reg, id1; int error, match_result; - if (iic_use_direct_match(ia, match, as3722_compats, &match_result)) + if (iic_use_direct_match(ia, match, as3722_compat_data, &match_result)) return match_result; if (ia->ia_addr != AS3722_I2C_ADDR) Index: src/sys/dev/i2c/at24cxx.c diff -u src/sys/dev/i2c/at24cxx.c:1.26 src/sys/dev/i2c/at24cxx.c:1.27 --- src/sys/dev/i2c/at24cxx.c:1.26 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/at24cxx.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: at24cxx.c,v 1.26 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: at24cxx.c,v 1.27 2018/06/18 17:07:07 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.26 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.27 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -127,13 +127,18 @@ static const struct seeprom_size { { "atmel,24c16", 2048 }, }; +static const struct device_compatible_entry seeprom_compat_data[] = { + DEVICE_COMPAT_ENTRY(seeprom_compats), + DEVICE_COMPAT_TERMINATOR +}; + static int seeprom_match(device_t parent, cfdata_t cf, void *aux) { struct i2c_attach_args *ia = aux; int match_result; - if (iic_use_direct_match(ia, cf, seeprom_compats, &match_result)) + if (iic_use_direct_match(ia, cf, seeprom_compat_data, &match_result)) return match_result; if ((ia->ia_addr & AT24CXX_ADDRMASK) == AT24CXX_ADDR) Index: src/sys/dev/i2c/ds1307.c diff -u src/sys/dev/i2c/ds1307.c:1.26 src/sys/dev/i2c/ds1307.c:1.27 --- src/sys/dev/i2c/ds1307.c:1.26 Sat Jun 16 21:28:07 2018 +++ src/sys/dev/i2c/ds1307.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ds1307.c,v 1.26 2018/06/16 21:28:07 thorpej Exp $ */ +/* $NetBSD: ds1307.c,v 1.27 2018/06/18 17:07:07 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.26 2018/06/16 21:28:07 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.27 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -56,7 +56,6 @@ __KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1 #include "ioconf.h" struct dsrtc_model { - const char **dm_compats; const i2c_addr_t *dm_valid_addrs; uint16_t dm_model; uint8_t dm_ch_reg; @@ -77,92 +76,102 @@ struct dsrtc_model { }; static const char *ds1307_compats[] = { "dallas,ds1307", "maxim,ds1307", NULL }; +static const i2c_addr_t ds1307_valid_addrs[] = { DS1307_ADDR, 0 }; +static const struct dsrtc_model ds1307_model = { + .dm_valid_addrs = ds1307_valid_addrs, + .dm_model = 1307, + .dm_ch_reg = DSXXXX_SECONDS, + .dm_ch_value = DS1307_SECONDS_CH, + .dm_rtc_start = DS1307_RTC_START, + .dm_rtc_size = DS1307_RTC_SIZE, + .dm_nvram_start = DS1307_NVRAM_START, + .dm_nvram_size = DS1307_NVRAM_SIZE, + .dm_flags = DSRTC_FLAG_BCD | DSRTC_FLAG_CLOCK_HOLD, +}; + static const char *ds1339_compats[] = { "dallas,ds1339", "maxim,ds1339", NULL }; +static const struct dsrtc_model ds1339_model = { + .dm_valid_addrs = ds1307_valid_addrs, + .dm_model = 1339, + .dm_rtc_start = DS1339_RTC_START, + .dm_rtc_size = DS1339_RTC_SIZE, + .dm_flags = DSRTC_FLAG_BCD, +}; + static const char *ds1340_compats[] = { "dallas,ds1340", "maxim,ds1340", NULL }; +static const struct dsrtc_model ds1340_model = { + .dm_valid_addrs = ds1307_valid_addrs, + .dm_model = 1340, + .dm_ch_reg = DSXXXX_SECONDS, + .dm_ch_value = DS1340_SECONDS_EOSC, + .dm_rtc_start = DS1340_RTC_START, + .dm_rtc_size = DS1340_RTC_SIZE, + .dm_flags = DSRTC_FLAG_BCD, +}; + static const char *ds1672_compats[] = { "dallas,ds1672", "maxim,ds1672", NULL }; +static const struct dsrtc_model ds1672_model = { + .dm_valid_addrs = ds1307_valid_addrs, + .dm_model = 1672, + .dm_rtc_start = DS1672_RTC_START, + .dm_rtc_size = DS1672_RTC_SIZE, + .dm_ch_reg = DS1672_CONTROL, + .dm_ch_value = DS1672_CONTROL_CH, + .dm_flags = 0, +}; + static const char *ds3231_compats[] = { "dallas,ds3231", "maxim,ds3231", NULL }; +static const struct dsrtc_model ds3231_model = { + .dm_valid_addrs = ds1307_valid_addrs, + .dm_model = 3231, + .dm_rtc_start = DS3232_RTC_START, + .dm_rtc_size = DS3232_RTC_SIZE, + .dm_flags = DSRTC_FLAG_BCD | DSRTC_FLAG_TEMP, +}; + static const char *ds3232_compats[] = { "dallas,ds3232", "maxim,ds3232", NULL }; +static const struct dsrtc_model ds3232_model = { + .dm_valid_addrs = ds1307_valid_addrs, + .dm_model = 3232, + .dm_rtc_start = DS3232_RTC_START, + .dm_rtc_size = DS3232_RTC_SIZE, + .dm_nvram_start = DS3232_NVRAM_START, + .dm_nvram_size = DS3232_NVRAM_SIZE, + /* + * XXX + * the DS3232 likely has the temperature sensor too but I can't + * easily verify or test that right now + */ + .dm_flags = DSRTC_FLAG_BCD, +}; /* XXX vendor prefix */ static const char *mcp7940_compats[] = { "microchip,mcp7940", NULL }; - -static const i2c_addr_t ds1307_valid_addrs[] = { DS1307_ADDR, 0 }; static const i2c_addr_t mcp7940_valid_addrs[] = { MCP7940_ADDR, 0 }; +static const struct dsrtc_model mcp7940_model = { + .dm_valid_addrs = mcp7940_valid_addrs, + .dm_model = 7940, + .dm_rtc_start = DS1307_RTC_START, + .dm_rtc_size = DS1307_RTC_SIZE, + .dm_ch_reg = DSXXXX_SECONDS, + .dm_ch_value = DS1307_SECONDS_CH, + .dm_vbaten_reg = DSXXXX_DAY, + .dm_vbaten_value = MCP7940_TOD_DAY_VBATEN, + .dm_nvram_start = MCP7940_NVRAM_START, + .dm_nvram_size = MCP7940_NVRAM_SIZE, + .dm_flags = DSRTC_FLAG_BCD | DSRTC_FLAG_CLOCK_HOLD | + DSRTC_FLAG_VBATEN | DSRTC_FLAG_CLOCK_HOLD_REVERSED, +}; -static const struct dsrtc_model dsrtc_models[] = { - { - .dm_compats = ds1307_compats, - .dm_valid_addrs = ds1307_valid_addrs, - .dm_model = 1307, - .dm_ch_reg = DSXXXX_SECONDS, - .dm_ch_value = DS1307_SECONDS_CH, - .dm_rtc_start = DS1307_RTC_START, - .dm_rtc_size = DS1307_RTC_SIZE, - .dm_nvram_start = DS1307_NVRAM_START, - .dm_nvram_size = DS1307_NVRAM_SIZE, - .dm_flags = DSRTC_FLAG_BCD | DSRTC_FLAG_CLOCK_HOLD, - }, { - .dm_compats = ds1339_compats, - .dm_valid_addrs = ds1307_valid_addrs, - .dm_model = 1339, - .dm_rtc_start = DS1339_RTC_START, - .dm_rtc_size = DS1339_RTC_SIZE, - .dm_flags = DSRTC_FLAG_BCD, - }, { - .dm_compats = ds1340_compats, - .dm_valid_addrs = ds1307_valid_addrs, - .dm_model = 1340, - .dm_ch_reg = DSXXXX_SECONDS, - .dm_ch_value = DS1340_SECONDS_EOSC, - .dm_rtc_start = DS1340_RTC_START, - .dm_rtc_size = DS1340_RTC_SIZE, - .dm_flags = DSRTC_FLAG_BCD, - }, { - .dm_compats = ds1672_compats, - .dm_valid_addrs = ds1307_valid_addrs, - .dm_model = 1672, - .dm_rtc_start = DS1672_RTC_START, - .dm_rtc_size = DS1672_RTC_SIZE, - .dm_ch_reg = DS1672_CONTROL, - .dm_ch_value = DS1672_CONTROL_CH, - .dm_flags = 0, - }, { - .dm_compats = ds3231_compats, - .dm_valid_addrs = ds1307_valid_addrs, - .dm_model = 3231, - .dm_rtc_start = DS3232_RTC_START, - .dm_rtc_size = DS3232_RTC_SIZE, - /* - * XXX - * the DS3232 likely has the temperature sensor too but I can't - * easily verify or test that right now - */ - .dm_flags = DSRTC_FLAG_BCD | DSRTC_FLAG_TEMP, - }, { - .dm_compats = ds3232_compats, - .dm_valid_addrs = ds1307_valid_addrs, - .dm_model = 3232, - .dm_rtc_start = DS3232_RTC_START, - .dm_rtc_size = DS3232_RTC_SIZE, - .dm_nvram_start = DS3232_NVRAM_START, - .dm_nvram_size = DS3232_NVRAM_SIZE, - .dm_flags = DSRTC_FLAG_BCD, - }, { - /* MCP7940 */ - .dm_compats = mcp7940_compats, - .dm_valid_addrs = mcp7940_valid_addrs, - .dm_model = 7940, - .dm_rtc_start = DS1307_RTC_START, - .dm_rtc_size = DS1307_RTC_SIZE, - .dm_ch_reg = DSXXXX_SECONDS, - .dm_ch_value = DS1307_SECONDS_CH, - .dm_vbaten_reg = DSXXXX_DAY, - .dm_vbaten_value = MCP7940_TOD_DAY_VBATEN, - .dm_nvram_start = MCP7940_NVRAM_START, - .dm_nvram_size = MCP7940_NVRAM_SIZE, - .dm_flags = DSRTC_FLAG_BCD | DSRTC_FLAG_CLOCK_HOLD | - DSRTC_FLAG_VBATEN | DSRTC_FLAG_CLOCK_HOLD_REVERSED, - }, +static const struct device_compatible_entry dsrtc_compat_data[] = { + DEVICE_COMPAT_ENTRY_WITH_DATA(ds1307_compats, &ds1307_model), + DEVICE_COMPAT_ENTRY_WITH_DATA(ds1339_compats, &ds1339_model), + DEVICE_COMPAT_ENTRY_WITH_DATA(ds1340_compats, &ds1340_model), + DEVICE_COMPAT_ENTRY_WITH_DATA(ds1672_compats, &ds1672_model), + DEVICE_COMPAT_ENTRY_WITH_DATA(ds3231_compats, &ds3231_model), + DEVICE_COMPAT_ENTRY_WITH_DATA(ds3232_compats, &ds3232_model), + DEVICE_COMPAT_ENTRY_WITH_DATA(mcp7940_compats, &mcp7940_model), + DEVICE_COMPAT_TERMINATOR }; struct dsrtc_softc { @@ -218,12 +227,16 @@ static void dsrtc_refresh(struct sysmon_ static const struct dsrtc_model * dsrtc_model_by_number(u_int model) { - /* no model given, assume it's a DS1307 (the first one) */ + const struct device_compatible_entry *dce; + const struct dsrtc_model *dm; + + /* no model given, assume it's a DS1307 */ if (model == 0) - return &dsrtc_models[0]; + return &ds1307_model; - for (const struct dsrtc_model *dm = dsrtc_models; - dm < dsrtc_models + __arraycount(dsrtc_models); dm++) { + for (dce = dsrtc_compat_data; + DEVICE_COMPAT_ENTRY_IS_TERMINATOR(dce) == false; dce++) { + dm = DEVICE_COMPAT_ENTRY_GET_PTR(dce); if (dm->dm_model == model) return dm; } @@ -233,38 +246,14 @@ dsrtc_model_by_number(u_int model) static const struct dsrtc_model * dsrtc_model_by_compat(const struct i2c_attach_args *ia) { - const struct dsrtc_model *best_model = NULL, *dm; - int best_match = 0, match_result; - - for (dm = dsrtc_models; - dm < dsrtc_models + __arraycount(dsrtc_models); dm++) { - match_result = iic_compat_match(ia, dm->dm_compats); - if (match_result > best_match) { - best_match = match_result; - best_model = dm; - } - } - return best_model; -} - -static bool -dsrtc_direct_match(const struct i2c_attach_args *ia, const cfdata_t cf, - int *best_matchp) -{ - const struct dsrtc_model *dm; - int best_match = 0, match_result; + const struct dsrtc_model *dm = NULL; + const struct device_compatible_entry *dce; - for (dm = dsrtc_models; - dm < dsrtc_models + __arraycount(dsrtc_models); dm++) { - if (iic_use_direct_match(ia, cf, dm->dm_compats, - &match_result) == false) - return false; - if (match_result > best_match) - best_match = match_result; - } + dce = iic_compatible_match(ia, dsrtc_compat_data, NULL); + if (dce != NULL) + dm = DEVICE_COMPAT_ENTRY_GET_PTR(dce); - *best_matchp = best_match; - return true; + return dm; } static bool @@ -285,7 +274,7 @@ dsrtc_match(device_t parent, cfdata_t cf const struct dsrtc_model *dm; int match_result; - if (dsrtc_direct_match(ia, cf, &match_result)) + if (iic_use_direct_match(ia, cf, dsrtc_compat_data, &match_result)) return match_result; dm = dsrtc_model_by_number(cf->cf_flags & 0xffff); Index: src/sys/dev/i2c/axp20x.c diff -u src/sys/dev/i2c/axp20x.c:1.11 src/sys/dev/i2c/axp20x.c:1.12 --- src/sys/dev/i2c/axp20x.c:1.11 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/axp20x.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: axp20x.c,v 1.11 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: axp20x.c,v 1.12 2018/06/18 17:07:07 thorpej Exp $ */ /*- * Copyright (c) 2014-2017 Jared McNeill <jmcne...@invisible.ca> @@ -29,7 +29,7 @@ #include "opt_fdt.h" #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: axp20x.c,v 1.11 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axp20x.c,v 1.12 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -219,13 +219,18 @@ static const char * compatible[] = { NULL }; +static const struct device_compatible_entry axp20x_compat_data[] = { + DEVICE_COMPAT_ENTRY(compatible), + DEVICE_COMPAT_TERMINATOR +}; + static int axp20x_match(device_t parent, cfdata_t match, void *aux) { struct i2c_attach_args * const ia = aux; int match_result; - if (iic_use_direct_match(ia, match, compatible, &match_result)) + if (iic_use_direct_match(ia, match, axp20x_compat_data, &match_result)) return match_result; /* This device is direct-config only. */ Index: src/sys/dev/i2c/dbcool.c diff -u src/sys/dev/i2c/dbcool.c:1.49 src/sys/dev/i2c/dbcool.c:1.50 --- src/sys/dev/i2c/dbcool.c:1.49 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/dbcool.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: dbcool.c,v 1.49 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: dbcool.c,v 1.50 2018/06/18 17:07:07 thorpej Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -50,7 +50,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.49 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.50 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -738,6 +738,12 @@ static const char * dbcool_compats[] = { "adm1030", NULL }; + +static const struct device_compatible_entry dbcool_compat_data[] = { + DEVICE_COMPAT_ENTRY(dbcool_compats), + DEVICE_COMPAT_TERMINATOR +}; + int dbcool_match(device_t parent, cfdata_t cf, void *aux) { @@ -750,7 +756,7 @@ dbcool_match(device_t parent, cfdata_t c dc.dc_writereg = dbcool_writereg; int match_result; - if (iic_use_direct_match(ia, cf, dbcool_compats, &match_result)) + if (iic_use_direct_match(ia, cf, dbcool_compat_data, &match_result)) return match_result; if ((ia->ia_addr & DBCOOL_ADDRMASK) != DBCOOL_ADDR) Index: src/sys/dev/i2c/dstemp.c diff -u src/sys/dev/i2c/dstemp.c:1.2 src/sys/dev/i2c/dstemp.c:1.3 --- src/sys/dev/i2c/dstemp.c:1.2 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/dstemp.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: dstemp.c,v 1.2 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: dstemp.c,v 1.3 2018/06/18 17:07:07 thorpej Exp $ */ /*- * Copyright (c) 2018 Michael Lorenz @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.2 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.3 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -77,13 +77,18 @@ static const char * dstemp_compats[] = { NULL }; +static const struct device_compatible_entry dstemp_compat_data[] = { + DEVICE_COMPAT_ENTRY(dstemp_compats), + DEVICE_COMPAT_TERMINATOR +}; + static int dstemp_match(device_t parent, cfdata_t match, void *aux) { struct i2c_attach_args *ia = aux; int match_result; - if (iic_use_direct_match(ia, match, dstemp_compats, &match_result)) + if (iic_use_direct_match(ia, match, dstemp_compat_data, &match_result)) return match_result; if ((ia->ia_addr & 0xf8) == 0x48) Index: src/sys/dev/i2c/sy8106a.c diff -u src/sys/dev/i2c/sy8106a.c:1.2 src/sys/dev/i2c/sy8106a.c:1.3 --- src/sys/dev/i2c/sy8106a.c:1.2 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/sy8106a.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: sy8106a.c,v 1.2 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: sy8106a.c,v 1.3 2018/06/18 17:07:07 thorpej Exp $ */ /*- * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sy8106a.c,v 1.2 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sy8106a.c,v 1.3 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -64,6 +64,11 @@ static const char * compatible[] = { NULL }; +static const struct device_compatible_entry sy8106a_compat_data[] = { + DEVICE_COMPAT_ENTRY(compatible), + DEVICE_COMPAT_TERMINATOR +}; + static uint8_t sy8106a_read(struct sy8106a_softc *sc, uint8_t reg, int flags) { @@ -187,7 +192,7 @@ sy8106a_match(device_t parent, cfdata_t struct i2c_attach_args *ia = aux; int match_result; - if (iic_use_direct_match(ia, match, compatible, &match_result)) + if (iic_use_direct_match(ia, match, sy8106a_compat_data, &match_result)) return match_result; return 0; Index: src/sys/dev/i2c/tcagpio.c diff -u src/sys/dev/i2c/tcagpio.c:1.2 src/sys/dev/i2c/tcagpio.c:1.3 --- src/sys/dev/i2c/tcagpio.c:1.2 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/tcagpio.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: tcagpio.c,v 1.2 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: tcagpio.c,v 1.3 2018/06/18 17:07:07 thorpej Exp $ */ /*- * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tcagpio.c,v 1.2 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tcagpio.c,v 1.3 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -73,6 +73,11 @@ static const char * compatible[] = { NULL }; +static const struct device_compatible_entry tcagpio_compat_data[] = { + DEVICE_COMPAT_ENTRY(compatible), + DEVICE_COMPAT_TERMINATOR +}; + static uint8_t tcagpio_read(struct tcagpio_softc *sc, uint8_t reg, int flags) { @@ -248,7 +253,7 @@ tcagpio_match(device_t parent, cfdata_t struct i2c_attach_args *ia = aux; int match_result; - if (iic_use_direct_match(ia, match, compatible, &match_result)) + if (iic_use_direct_match(ia, match, tcagpio_compat_data, &match_result)) return match_result; return 0; Index: src/sys/dev/i2c/i2c.c diff -u src/sys/dev/i2c/i2c.c:1.62 src/sys/dev/i2c/i2c.c:1.63 --- src/sys/dev/i2c/i2c.c:1.62 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/i2c.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.62 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: i2c.c,v 1.63 2018/06/18 17:07:07 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.62 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.63 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -691,41 +691,39 @@ iic_fill_compat(struct i2c_attach_args * } /* - * iic_compat_match -- + * iic_compatible_match -- * Match a device's "compatible" property against the list - * of compatible strings provided by the driver. Note that - * we weight the match to the reverse index of the device's - * "compatible" property strings so that a driver that matches - * an lower-indexed "compatible" property is given a higher - * match priority than one that matches a higher-indexed - * "compatible" property. + * of compatible strings provided by the driver. */ -int -iic_compat_match(const struct i2c_attach_args *ia, const char **compats) -{ - int match_result = 0, i, ri; - - if (ia->ia_ncompat == 0 || ia->ia_compat == NULL) - return 0; - - for (; compats && *compats; compats++) { - for (i = 0, ri = ia->ia_ncompat - 1; - i < ia->ia_ncompat; - i++, ri--) { - if (strcmp(*compats, ia->ia_compat[i]) == 0) { - KASSERT(ri >= 0); - match_result = - I2C_MATCH_DIRECT_COMPATIBLE + ri; - } - } +const struct device_compatible_entry * +iic_compatible_match(const struct i2c_attach_args *ia, + const struct device_compatible_entry *compats, + int *match_resultp) +{ + const struct device_compatible_entry *dce; + int match_weight; + + dce = device_compatible_match(ia->ia_compat, ia->ia_ncompat, + compats, &match_weight); + if (dce != NULL && match_resultp != NULL) { + *match_resultp = MIN(I2C_MATCH_DIRECT_COMPATIBLE + match_weight, + I2C_MATCH_DIRECT_COMPATIBLE_MAX); } - match_result = MIN(match_result, I2C_MATCH_DIRECT_COMPATIBLE_MAX); - return match_result; + + return dce; } +/* + * iic_use_direct_match -- + * Helper for direct-config of i2c. Returns true if this is + * a direct-config situation, along with with match result. + * Returns false if the driver should use indirect-config + * matching logic. + */ bool iic_use_direct_match(const struct i2c_attach_args *ia, const cfdata_t cf, - const char **compats, int *match_resultp) + const struct device_compatible_entry *compats, + int *match_resultp) { KASSERT(match_resultp != NULL); @@ -737,7 +735,7 @@ iic_use_direct_match(const struct i2c_at } if (ia->ia_ncompat > 0 && ia->ia_compat != NULL) { - *match_resultp = iic_compat_match(ia, compats); + (void) iic_compatible_match(ia, compats, match_resultp); return true; } Index: src/sys/dev/i2c/i2cvar.h diff -u src/sys/dev/i2c/i2cvar.h:1.14 src/sys/dev/i2c/i2cvar.h:1.15 --- src/sys/dev/i2c/i2cvar.h:1.14 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/i2cvar.h Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: i2cvar.h,v 1.14 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: i2cvar.h,v 1.15 2018/06/18 17:07:07 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -164,9 +164,11 @@ int iicbus_print(void *, const char *); /* * API presented to i2c devices. */ -int iic_compat_match(const struct i2c_attach_args *, const char **); -bool iic_use_direct_match(const struct i2c_attach_args *, - const cfdata_t, const char **, int *); +const struct device_compatible_entry * + iic_compatible_match(const struct i2c_attach_args *, + const struct device_compatible_entry *, int *); +bool iic_use_direct_match(const struct i2c_attach_args *, const cfdata_t, + const struct device_compatible_entry *, int *); /* * Constants to indicate the quality of a match made by a driver's Index: src/sys/dev/i2c/lm75.c diff -u src/sys/dev/i2c/lm75.c:1.31 src/sys/dev/i2c/lm75.c:1.32 --- src/sys/dev/i2c/lm75.c:1.31 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/lm75.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: lm75.c,v 1.31 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: lm75.c,v 1.32 2018/06/18 17:07:07 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.31 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.32 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -111,6 +111,11 @@ static const char * lmtemp_compats[] = { NULL }; +static const struct device_compatible_entry lmtemp_compat_data[] = { + DEVICE_COMPAT_ENTRY(lmtemp_compats), + DEVICE_COMPAT_TERMINATOR +}; + enum { lmtemp_lm75 = 0, lmtemp_ds75, @@ -148,7 +153,7 @@ lmtemp_match(device_t parent, cfdata_t c struct i2c_attach_args *ia = aux; int i, match_result; - if (iic_use_direct_match(ia, cf, lmtemp_compats, &match_result)) + if (iic_use_direct_match(ia, cf, lmtemp_compat_data, &match_result)) return match_result; /* Index: src/sys/dev/i2c/lm87.c diff -u src/sys/dev/i2c/lm87.c:1.8 src/sys/dev/i2c/lm87.c:1.9 --- src/sys/dev/i2c/lm87.c:1.8 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/lm87.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: lm87.c,v 1.8 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: lm87.c,v 1.9 2018/06/18 17:07:07 thorpej Exp $ */ /* $OpenBSD: lm87.c,v 1.20 2008/11/10 05:19:48 cnst Exp $ */ /* @@ -18,7 +18,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: lm87.c,v 1.8 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm87.c,v 1.9 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -144,6 +144,11 @@ static const char * lmenv_compats[] = { NULL }; +static const struct device_compatible_entry lmenv_compat_data[] = { + DEVICE_COMPAT_ENTRY(lmenv_compats), + DEVICE_COMPAT_TERMINATOR, +}; + int lmenv_match(device_t parent, cfdata_t match, void *aux) { @@ -151,7 +156,7 @@ lmenv_match(device_t parent, cfdata_t ma u_int8_t cmd, val; int error, i, match_result; - if (iic_use_direct_match(ia, match, lmenv_compats, &match_result)) + if (iic_use_direct_match(ia, match, lmenv_compat_data, &match_result)) return match_result; /* Index: src/sys/dev/i2c/pcf8563.c diff -u src/sys/dev/i2c/pcf8563.c:1.9 src/sys/dev/i2c/pcf8563.c:1.10 --- src/sys/dev/i2c/pcf8563.c:1.9 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/pcf8563.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: pcf8563.c,v 1.9 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: pcf8563.c,v 1.10 2018/06/18 17:07:07 thorpej Exp $ */ /* * Copyright (c) 2011 Jonathan A. Kollasch @@ -32,7 +32,7 @@ #endif #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pcf8563.c,v 1.9 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcf8563.c,v 1.10 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -54,6 +54,11 @@ static const char *compatible[] = { NULL }; +static const struct device_compatible_entry pcf8563rtc_compat_data[] = { + DEVICE_COMPAT_ENTRY(compatible), + DEVICE_COMPAT_TERMINATOR +}; + struct pcf8563rtc_softc { device_t sc_dev; i2c_tag_t sc_tag; @@ -78,7 +83,7 @@ pcf8563rtc_match(device_t parent, cfdata struct i2c_attach_args *ia = aux; int match_result; - if (iic_use_direct_match(ia, cf, compatible, &match_result)) + if (iic_use_direct_match(ia, cf, pcf8563rtc_compat_data, &match_result)) return match_result; /* indirect config - check typical address */ Index: src/sys/dev/i2c/tcakp.c diff -u src/sys/dev/i2c/tcakp.c:1.7 src/sys/dev/i2c/tcakp.c:1.8 --- src/sys/dev/i2c/tcakp.c:1.7 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/tcakp.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: tcakp.c,v 1.7 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: tcakp.c,v 1.8 2018/06/18 17:07:07 thorpej Exp $ */ /*- * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca> @@ -29,7 +29,7 @@ #include "opt_fdt.h" #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tcakp.c,v 1.7 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tcakp.c,v 1.8 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -118,6 +118,11 @@ static const char * tcakp_compats[] = { NULL }; +static const struct device_compatible_entry tcakp_compat_data[] = { + DEVICE_COMPAT_ENTRY(tcakp_compats), + DEVICE_COMPAT_TERMINATOR +}; + static u_int tcakp_decode(struct tcakp_softc *sc, uint8_t code) { @@ -318,7 +323,7 @@ tcakp_match(device_t parent, cfdata_t ma struct i2c_attach_args *ia = aux; int match_result; - if (iic_use_direct_match(ia, match, tcakp_compats, &match_result)) + if (iic_use_direct_match(ia, match, tcakp_compat_data, &match_result)) return match_result; if (ia->ia_addr == 0x34) Index: src/sys/dev/i2c/titemp.c diff -u src/sys/dev/i2c/titemp.c:1.5 src/sys/dev/i2c/titemp.c:1.6 --- src/sys/dev/i2c/titemp.c:1.5 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/titemp.c Mon Jun 18 17:07:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: titemp.c,v 1.5 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: titemp.c,v 1.6 2018/06/18 17:07:07 thorpej Exp $ */ /*- * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: titemp.c,v 1.5 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: titemp.c,v 1.6 2018/06/18 17:07:07 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -89,6 +89,11 @@ static const char * titemp_compats[] = { NULL }; +static const struct device_compatible_entry titemp_compat_data[] = { + DEVICE_COMPAT_ENTRY(titemp_compats), + DEVICE_COMPAT_TERMINATOR +}; + static int titemp_match(device_t parent, cfdata_t match, void *aux) { @@ -96,7 +101,7 @@ titemp_match(device_t parent, cfdata_t m uint8_t mfid; int error, match_result; - if (iic_use_direct_match(ia, match, titemp_compats, &match_result)) + if (iic_use_direct_match(ia, match, titemp_compat_data, &match_result)) return match_result; if (ia->ia_addr != 0x4c)