CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Sun Jul 25 00:11:43 UTC 2021 Modified Files: src/sys/dev/i2c: fcu.c Log Message: don't put CPUs in separate zones, turns out there really isn't much that keeps the airflow apart around them To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/sys/dev/i2c/fcu.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/dev/i2c/fcu.c diff -u src/sys/dev/i2c/fcu.c:1.12 src/sys/dev/i2c/fcu.c:1.13 --- src/sys/dev/i2c/fcu.c:1.12 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/fcu.c Sun Jul 25 00:11:43 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fcu.c,v 1.12 2021/01/27 02:29:48 thorpej Exp $ */ +/* $NetBSD: fcu.c,v 1.13 2021/07/25 00:11:43 macallan Exp $ */ /*- * Copyright (c) 2018 Michael Lorenz @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: fcu.c,v 1.12 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fcu.c,v 1.13 2021/07/25 00:11:43 macallan Exp $"); #include #include @@ -75,11 +75,10 @@ typedef struct _fcu_fan { int duty; /* for pwm fans */ } fcu_fan_t; -#define FCU_ZONE_CPU_A 0 -#define FCU_ZONE_CPU_B 1 -#define FCU_ZONE_CASE 2 -#define FCU_ZONE_DRIVEBAY 3 -#define FCU_ZONE_COUNT 4 +#define FCU_ZONE_CPU 0 +#define FCU_ZONE_CASE 1 +#define FCU_ZONE_DRIVEBAY 2 +#define FCU_ZONE_COUNT 3 struct fcu_softc { device_t sc_dev; @@ -103,8 +102,7 @@ static void fcu_attach(device_t, device_ static void fcu_sensors_refresh(struct sysmon_envsys *, envsys_data_t *); -static bool is_cpu_a(const envsys_data_t *); -static bool is_cpu_b(const envsys_data_t *); +static bool is_cpu(const envsys_data_t *); static bool is_case(const envsys_data_t *); static bool is_drive(const envsys_data_t *); @@ -162,12 +160,9 @@ fcu_attach(device_t parent, device_t sel have_eeprom1 = 0; /* init zones */ - sc->sc_zones[FCU_ZONE_CPU_A].filter = is_cpu_a; - sc->sc_zones[FCU_ZONE_CPU_A].threshold = 50; - sc->sc_zones[FCU_ZONE_CPU_A].nfans = 0; - sc->sc_zones[FCU_ZONE_CPU_B].filter = is_cpu_b; - sc->sc_zones[FCU_ZONE_CPU_B].threshold = 50; - sc->sc_zones[FCU_ZONE_CPU_B].nfans = 0; + sc->sc_zones[FCU_ZONE_CPU].filter = is_cpu; + sc->sc_zones[FCU_ZONE_CPU].threshold = 50; + sc->sc_zones[FCU_ZONE_CPU].nfans = 0; sc->sc_zones[FCU_ZONE_CASE].filter = is_case; sc->sc_zones[FCU_ZONE_CASE].threshold = 50; sc->sc_zones[FCU_ZONE_CASE].nfans = 0; @@ -282,12 +277,8 @@ fcu_attach(device_t parent, device_t sel descr, fan->base_rpm, fan->max_rpm, fan->step); /* now stuff them into zones */ - if (strstr(descr, "CPU A") != NULL) { -fcu_zone_t *z = >sc_zones[FCU_ZONE_CPU_A]; -z->fans[z->nfans] = sc->sc_nfans; -z->nfans++; - } else if (strstr(descr, "CPU B") != NULL) { -fcu_zone_t *z = >sc_zones[FCU_ZONE_CPU_B]; + if (strstr(descr, "CPU") != NULL) { +fcu_zone_t *z = >sc_zones[FCU_ZONE_CPU]; z->fans[z->nfans] = sc->sc_nfans; z->nfans++; } else if ((strstr(descr, "BACKSIDE") != NULL) || @@ -358,21 +349,11 @@ fcu_sensors_refresh(struct sysmon_envsys } static bool -is_cpu_a(const envsys_data_t *edata) +is_cpu(const envsys_data_t *edata) { if (edata->units != ENVSYS_STEMP) return false; - if (strstr(edata->desc, "CPU A") != NULL) - return TRUE; - return false; -} - -static bool -is_cpu_b(const envsys_data_t *edata) -{ - if (edata->units != ENVSYS_STEMP) - return false; - if (strstr(edata->desc, "CPU B") != NULL) + if (strstr(edata->desc, "CPU") != NULL) return TRUE; return false; } @@ -462,7 +443,6 @@ fcu_adjust_zone(struct fcu_softc *sc, in fcu_fan_t *f; int temp, i, speed, diff; - if (z->nfans <= 0) return;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: christos Date: Mon Jun 21 03:12:54 UTC 2021 Modified Files: src/sys/dev/i2c: adm1021.c dbcool.c dstemp.c i2c.c lm75.c pcagpio.c pcf8574.c Log Message: fix proplib deprecation To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/sys/dev/i2c/adm1021.c cvs rdiff -u -r1.61 -r1.62 src/sys/dev/i2c/dbcool.c cvs rdiff -u -r1.13 -r1.14 src/sys/dev/i2c/dstemp.c cvs rdiff -u -r1.78 -r1.79 src/sys/dev/i2c/i2c.c cvs rdiff -u -r1.44 -r1.45 src/sys/dev/i2c/lm75.c cvs rdiff -u -r1.10 -r1.11 src/sys/dev/i2c/pcagpio.c cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/pcf8574.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/dev/i2c/adm1021.c diff -u src/sys/dev/i2c/adm1021.c:1.28 src/sys/dev/i2c/adm1021.c:1.29 --- src/sys/dev/i2c/adm1021.c:1.28 Tue Jun 15 00:41:01 2021 +++ src/sys/dev/i2c/adm1021.c Sun Jun 20 23:12:54 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: adm1021.c,v 1.28 2021/06/15 04:41:01 mlelstv Exp $ */ +/* $NetBSD: adm1021.c,v 1.29 2021/06/21 03:12:54 christos Exp $ */ /* $OpenBSD: adm1021.c,v 1.27 2007/06/24 05:34:35 dlg Exp $ */ /* @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.28 2021/06/15 04:41:01 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.29 2021/06/21 03:12:54 christos Exp $"); #include #include @@ -409,11 +409,11 @@ admtemp_attach(device_t parent, device_t sc->sc_sensor[ADMTEMP_EXT].flags = ENVSYS_FMONLIMITS | ENVSYS_FHAS_ENTROPY; - if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, "s00", )) { + if (prop_dictionary_get_string(sc->sc_prop, "s00", )) { strncpy(iname, desc, 64); } - if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, "s01", )) { + if (prop_dictionary_get_string(sc->sc_prop, "s01", )) { strncpy(ename, desc, 64); } Index: src/sys/dev/i2c/dbcool.c diff -u src/sys/dev/i2c/dbcool.c:1.61 src/sys/dev/i2c/dbcool.c:1.62 --- src/sys/dev/i2c/dbcool.c:1.61 Tue Jun 15 00:39:49 2021 +++ src/sys/dev/i2c/dbcool.c Sun Jun 20 23:12:54 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: dbcool.c,v 1.61 2021/06/15 04:39:49 mlelstv Exp $ */ +/* $NetBSD: dbcool.c,v 1.62 2021/06/21 03:12:54 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -50,7 +50,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.61 2021/06/15 04:39:49 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.62 2021/06/21 03:12:54 christos Exp $"); #include #include @@ -1697,7 +1697,7 @@ dbcool_attach_sensor(struct dbcool_softc name_index = sc->sc_dc.dc_chip->table[idx].name_index; snprintf(name, 7, "s%02x", sc->sc_dc.dc_chip->table[idx].reg.val_reg); - if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, name, )) { + if (prop_dictionary_get_string(sc->sc_prop, name, )) { strlcpy(sc->sc_sensor[idx].desc, desc, sizeof(sc->sc_sensor[idx].desc)); } else { Index: src/sys/dev/i2c/dstemp.c diff -u src/sys/dev/i2c/dstemp.c:1.13 src/sys/dev/i2c/dstemp.c:1.14 --- src/sys/dev/i2c/dstemp.c:1.13 Tue Jun 15 00:41:01 2021 +++ src/sys/dev/i2c/dstemp.c Sun Jun 20 23:12:54 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: dstemp.c,v 1.13 2021/06/15 04:41:01 mlelstv Exp $ */ +/* $NetBSD: dstemp.c,v 1.14 2021/06/21 03:12:54 christos Exp $ */ /*- * Copyright (c) 2018 Michael Lorenz @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.13 2021/06/15 04:41:01 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.14 2021/06/21 03:12:54 christos Exp $"); #include #include @@ -126,9 +126,9 @@ dstemp_attach(device_t parent, device_t sc->sc_sensor_temp.state = ENVSYS_SINVALID; sc->sc_sensor_temp.flags = ENVSYS_FHAS_ENTROPY; - if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, "s00", )) { + if (prop_dictionary_get_string(sc->sc_prop, "s00", )) { strncpy(name, desc, 64); - } else if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, "saa", )) { + } else if (prop_dictionary_get_string(sc->sc_prop, "saa", )) { strncpy(name, desc, 64); } Index: src/sys/dev/i2c/i2c.c diff -u src/sys/dev/i2c/i2c.c:1.78 src/sys/dev/i2c/i2c.c:1.79 --- src/sys/dev/i2c/i2c.c:1.78 Sat Apr 24 19:36:54 2021 +++ src/sys/dev/i2c/i2c.c Sun Jun 20 23:12:54 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.78 2021/04/24 23:36:54 thorpej Exp $ */ +/* $NetBSD: i2c.c,v 1.79 2021/06/21 03:12:54 christos Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -40,7 +40,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78 2021/04/24 23:36:54 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.79 2021/06/21 03:12:54 christos Exp $"); #include #include @@ -452,7 +452,7 @@ iic_attach(device_t parent, device_t sel for (i = 0; i < count; i++) { dev = prop_array_get(child_devices, i); if (!dev) continue; - if (!prop_dictionary_get_cstring_nocopy( + if (!prop_dictionary_get_string( dev, "name", )) { /* "name" property is optional.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Tue Jun 15 04:41:01 UTC 2021 Modified Files: src/sys/dev/i2c: adm1021.c dstemp.c Log Message: iic_acquire_bus may fail. To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/sys/dev/i2c/adm1021.c cvs rdiff -u -r1.12 -r1.13 src/sys/dev/i2c/dstemp.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/dev/i2c/adm1021.c diff -u src/sys/dev/i2c/adm1021.c:1.27 src/sys/dev/i2c/adm1021.c:1.28 --- src/sys/dev/i2c/adm1021.c:1.27 Sat Jan 30 01:22:06 2021 +++ src/sys/dev/i2c/adm1021.c Tue Jun 15 04:41:01 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: adm1021.c,v 1.27 2021/01/30 01:22:06 thorpej Exp $ */ +/* $NetBSD: adm1021.c,v 1.28 2021/06/15 04:41:01 mlelstv Exp $ */ /* $OpenBSD: adm1021.c,v 1.27 2007/06/24 05:34:35 dlg Exp $ */ /* @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.27 2021/01/30 01:22:06 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.28 2021/06/15 04:41:01 mlelstv Exp $"); #include #include @@ -344,7 +344,11 @@ admtemp_attach(device_t parent, device_t sc->sc_prop = ia->ia_prop; prop_object_retain(sc->sc_prop); - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) { + aprint_error_dev(self, "cannot acquire iic bus\n"); + return; + } + cmd = ADM1021_CONFIG_READ; if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, , ) != 0) { iic_release_bus(sc->sc_tag, 0); @@ -466,10 +470,8 @@ admtemp_refresh(struct sysmon_envsys *sm uint8_t cmd, xdata; int8_t sdata; - if (iic_acquire_bus(sc->sc_tag, 0)) { - edata->state = ENVSYS_SINVALID; + if (iic_acquire_bus(sc->sc_tag, 0) != 0) return; - } if (edata->sensor == ADMTEMP_INT) cmd = ADM1021_INT_TEMP; Index: src/sys/dev/i2c/dstemp.c diff -u src/sys/dev/i2c/dstemp.c:1.12 src/sys/dev/i2c/dstemp.c:1.13 --- src/sys/dev/i2c/dstemp.c:1.12 Mon Mar 1 04:39:45 2021 +++ src/sys/dev/i2c/dstemp.c Tue Jun 15 04:41:01 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: dstemp.c,v 1.12 2021/03/01 04:39:45 rin Exp $ */ +/* $NetBSD: dstemp.c,v 1.13 2021/06/15 04:41:01 mlelstv Exp $ */ /*- * Copyright (c) 2018 Michael Lorenz @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.12 2021/03/01 04:39:45 rin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.13 2021/06/15 04:41:01 mlelstv Exp $"); #include #include @@ -145,7 +145,8 @@ dstemp_init(struct dstemp_softc *sc) int error; uint8_t cmd[2], data; - iic_acquire_bus(sc->sc_i2c, 0); + if (iic_acquire_bus(sc->sc_i2c, 0)) + return; cmd[0] = DSTEMP_CONFIG; data = 0; error = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, @@ -171,10 +172,12 @@ dstemp_sensors_refresh(struct sysmon_env int error; - iic_acquire_bus(sc->sc_i2c, 0); - error = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, - sc->sc_addr, , 1, , 2, 0); - iic_release_bus(sc->sc_i2c, 0); + error = iic_acquire_bus(sc->sc_i2c, 0); + if (error == 0) { + error = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, + sc->sc_addr, , 1, , 2, 0); + iic_release_bus(sc->sc_i2c, 0); + } if (error) { edata->state = ENVSYS_SINVALID;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Tue Jun 15 04:40:13 UTC 2021 Modified Files: src/sys/dev/i2c: am2315.c Log Message: avoid double-free To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/am2315.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/dev/i2c/am2315.c diff -u src/sys/dev/i2c/am2315.c:1.5 src/sys/dev/i2c/am2315.c:1.6 --- src/sys/dev/i2c/am2315.c:1.5 Sun Jun 17 01:08:15 2018 +++ src/sys/dev/i2c/am2315.c Tue Jun 15 04:40:13 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: am2315.c,v 1.5 2018/06/17 01:08:15 thorpej Exp $ */ +/* $NetBSD: am2315.c,v 1.6 2021/06/15 04:40:13 mlelstv Exp $ */ /* * Copyright (c) 2017 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: am2315.c,v 1.5 2018/06/17 01:08:15 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: am2315.c,v 1.6 2021/06/15 04:40:13 mlelstv Exp $"); /* * Driver for the Aosong AM2315 @@ -458,10 +458,8 @@ am2315_detach(device_t self, int flags) mutex_enter(>sc_mutex); /* Remove the sensors */ - if (sc->sc_sme != NULL) { + if (sc->sc_sme != NULL) sysmon_envsys_unregister(sc->sc_sme); - sc->sc_sme = NULL; - } mutex_exit(>sc_mutex); /* Destroy the wait cond */
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Tue Jun 15 04:39:49 UTC 2021 Modified Files: src/sys/dev/i2c: dbcool.c hytp14.c si70xx.c Log Message: avoid double-free To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 src/sys/dev/i2c/dbcool.c cvs rdiff -u -r1.13 -r1.14 src/sys/dev/i2c/hytp14.c cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/si70xx.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/dev/i2c/dbcool.c diff -u src/sys/dev/i2c/dbcool.c:1.60 src/sys/dev/i2c/dbcool.c:1.61 --- src/sys/dev/i2c/dbcool.c:1.60 Sat Jan 30 01:22:06 2021 +++ src/sys/dev/i2c/dbcool.c Tue Jun 15 04:39:49 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: dbcool.c,v 1.60 2021/01/30 01:22:06 thorpej Exp $ */ +/* $NetBSD: dbcool.c,v 1.61 2021/06/15 04:39:49 mlelstv Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -50,7 +50,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.60 2021/01/30 01:22:06 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.61 2021/06/15 04:39:49 mlelstv Exp $"); #include #include @@ -819,11 +819,11 @@ dbcool_detach(device_t self, int flags) pmf_device_deregister(self); - sysmon_envsys_unregister(sc->sc_sme); + if (sc->sc_sme != NULL) + sysmon_envsys_unregister(sc->sc_sme); sysctl_teardown(>sc_sysctl_log); - sc->sc_sme = NULL; return 0; } @@ -1600,6 +1600,7 @@ dbcool_setup(device_t self) out: sysmon_envsys_destroy(sc->sc_sme); + sc->sc_sme = NULL; } static int Index: src/sys/dev/i2c/hytp14.c diff -u src/sys/dev/i2c/hytp14.c:1.13 src/sys/dev/i2c/hytp14.c:1.14 --- src/sys/dev/i2c/hytp14.c:1.13 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/hytp14.c Tue Jun 15 04:39:49 2021 @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.13 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.14 2021/06/15 04:39:49 mlelstv Exp $"); #include #include @@ -204,6 +204,7 @@ hytp14_attach(device_t parent, device_t aprint_error_dev(sc->sc_dev, "unable to register with sysmon\n"); sysmon_envsys_destroy(sc->sc_sme); + sc->sc_sme = NULL; return; } @@ -244,10 +245,8 @@ hytp14_detach(device_t self, int flags) sc = device_private(self); - if (sc->sc_sme != NULL) { + if (sc->sc_sme != NULL) sysmon_envsys_unregister(sc->sc_sme); - sc->sc_sme = NULL; - } /* stop measurement thread */ mutex_enter(>sc_mutex); Index: src/sys/dev/i2c/si70xx.c diff -u src/sys/dev/i2c/si70xx.c:1.6 src/sys/dev/i2c/si70xx.c:1.7 --- src/sys/dev/i2c/si70xx.c:1.6 Sat Dec 5 14:50:33 2020 +++ src/sys/dev/i2c/si70xx.c Tue Jun 15 04:39:49 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: si70xx.c,v 1.6 2020/12/05 14:50:33 jdc Exp $ */ +/* $NetBSD: si70xx.c,v 1.7 2021/06/15 04:39:49 mlelstv Exp $ */ /* * Copyright (c) 2017 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: si70xx.c,v 1.6 2020/12/05 14:50:33 jdc Exp $"); +__KERNEL_RCSID(0, "$NetBSD: si70xx.c,v 1.7 2021/06/15 04:39:49 mlelstv Exp $"); /* Driver for the Silicon Labs SI7013/SI7020/SI7021 @@ -968,10 +968,8 @@ si70xx_detach(device_t self, int flags) mutex_enter(>sc_mutex); /* Remove the sensors */ - if (sc->sc_sme != NULL) { + if (sc->sc_sme != NULL) sysmon_envsys_unregister(sc->sc_sme); - sc->sc_sme = NULL; - } mutex_exit(>sc_mutex); /* Remove the sysctl tree */
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jdc Date: Mon Jun 14 13:52:11 UTC 2021 Modified Files: src/sys/dev/i2c: adm1026.c Log Message: Call sysmon_envsys_destroy() if we receive any error from sysmon, rather than just on some errors. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/sys/dev/i2c/adm1026.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/dev/i2c/adm1026.c diff -u src/sys/dev/i2c/adm1026.c:1.12 src/sys/dev/i2c/adm1026.c:1.13 --- src/sys/dev/i2c/adm1026.c:1.12 Mon Jun 14 09:56:04 2021 +++ src/sys/dev/i2c/adm1026.c Mon Jun 14 13:52:11 2021 @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: adm1026.c,v 1.12 2021/06/14 09:56:04 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adm1026.c,v 1.13 2021/06/14 13:52:11 jdc Exp $"); #include #include @@ -104,9 +104,9 @@ static int adm1026_detach(device_t, int) bool adm1026_pmf_suspend(device_t, const pmf_qual_t *); bool adm1026_pmf_resume(device_t, const pmf_qual_t *); -static void adm1026_setup_fans(struct adm1026_softc *sc, int div2_val); -static void adm1026_setup_temps(struct adm1026_softc *sc); -static void adm1026_setup_volts(struct adm1026_softc *sc); +static int adm1026_setup_fans(struct adm1026_softc *sc, int div2_val); +static int adm1026_setup_temps(struct adm1026_softc *sc); +static int adm1026_setup_volts(struct adm1026_softc *sc); void adm1026_refresh(struct sysmon_envsys *sme, envsys_data_t *edata); static void adm1026_read_fan(struct adm1026_softc *sc, envsys_data_t *edata); @@ -221,10 +221,13 @@ adm1026_attach(device_t parent, device_t sc->sc_sme = sysmon_envsys_create(); sc->sc_nfans = 0; - adm1026_setup_fans(sc, div2_val); sc->sc_ntemps = 0; - adm1026_setup_temps(sc); - adm1026_setup_volts(sc); + if (adm1026_setup_fans(sc, div2_val)) + goto bad; + if (adm1026_setup_temps(sc)) + goto bad; + if (adm1026_setup_volts(sc)) + goto bad; aprint_normal_dev(self, "%d fans, %d temperatures, %d voltages\n", sc->sc_nfans, sc->sc_ntemps, sc->sc_ntemps == 3 ? 15 : 17); @@ -234,15 +237,18 @@ adm1026_attach(device_t parent, device_t if (sysmon_envsys_register(sc->sc_sme)) { aprint_error_dev(self, "unable to register with sysmon\n"); - sysmon_envsys_destroy(sc->sc_sme); - sc->sc_sme = NULL; - return; + goto bad; } if (!pmf_device_register(self, adm1026_pmf_suspend, adm1026_pmf_resume)) aprint_error_dev(self, "couldn't establish power handler\n"); return; + +bad: + sysmon_envsys_destroy(sc->sc_sme); + sc->sc_sme = NULL; + return; } /* @@ -275,7 +281,7 @@ adm1026_detach(device_t self, int flags) return 0; } -static void +static int adm1026_setup_fans(struct adm1026_softc *sc, int div2_val) { int i, err = 0; @@ -284,11 +290,11 @@ adm1026_setup_fans(struct adm1026_softc /* Read fan-related registers (configuration and divisors) */ if ((err = adm1026_read_reg(sc, ADM1026_CONF2, >sc_cfg[1])) != 0) { aprint_error_dev(sc->sc_dev, "unable to read conf2\n"); - return; + return 0; } if ((err = adm1026_read_reg(sc, ADM1026_FAN_DIV1, )) != 0) { aprint_error_dev(sc->sc_dev, "unable to read fan_div1\n"); - return; + return 0; } sc->sc_fandiv[0] = 1 << ADM1026_FAN0_DIV(div1); sc->sc_fandiv[1] = 1 << ADM1026_FAN1_DIV(div1); @@ -299,7 +305,7 @@ adm1026_setup_fans(struct adm1026_softc adm1026_read_reg(sc, ADM1026_FAN_DIV2, )) != 0) { aprint_error_dev(sc->sc_dev, "unable to read fan_div2\n"); - return; + return 0; } } else div2 = div2_val; @@ -317,20 +323,19 @@ adm1026_setup_fans(struct adm1026_softc snprintf(sc->sc_sensor[ADM1026_FAN_NUM(i)].desc, sizeof(sc->sc_sensor[ADM1026_FAN_NUM(i)].desc), "fan %d", ADM1026_FAN_NUM(i)); - sc->sc_nfans++; if (sysmon_envsys_sensor_attach( sc->sc_sme, >sc_sensor[ADM1026_FAN_NUM(i)])) { -sysmon_envsys_destroy(sc->sc_sme); -sc->sc_sme = NULL; aprint_error_dev(sc->sc_dev, "unable to attach fan %d at sysmon\n", i); -return; +return 1; } + sc->sc_nfans++; } } + return 0; } -static void +static int adm1026_setup_temps(struct adm1026_softc *sc) { int i; @@ -340,7 +345,7 @@ adm1026_setup_temps(struct adm1026_softc if (adm1026_read_reg(sc, ADM1026_INT_TEMP_OFF, ) != 0) { aprint_error_dev(sc->sc_dev, "unable to read int temp. off.\n"); - return; + return 0; } if (val & 0x80) sc->sc_temp_off[0] = 0 - 100 * (val & 0x7f); @@ -348,7 +353,7 @@ adm1026_setup_temps(struct adm1026_softc sc->sc_temp_off[0] = 100 * (val & 0x7f); if (adm1026_read_reg(sc, ADM1026_TDM1_OFF, ) != 0) { aprint_error_dev(sc->sc_dev, "unable to read tdm1 off.\n"); - return; + return 0; } if (val & 0x80) sc->sc_temp_off[1] = 0 - 100 * (val & 0x7f); @@ -356,7 +361,7 @@ adm1026_setup_temps(struct adm1026_softc sc->sc_temp_off[1] = 100 * (val & 0x7f); if
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Mon Jun 14 09:56:04 UTC 2021 Modified Files: src/sys/dev/i2c: adm1026.c Log Message: Avoid double free when attach fails. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sys/dev/i2c/adm1026.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/dev/i2c/adm1026.c diff -u src/sys/dev/i2c/adm1026.c:1.11 src/sys/dev/i2c/adm1026.c:1.12 --- src/sys/dev/i2c/adm1026.c:1.11 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/adm1026.c Mon Jun 14 09:56:04 2021 @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: adm1026.c,v 1.11 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adm1026.c,v 1.12 2021/06/14 09:56:04 mlelstv Exp $"); #include #include @@ -235,6 +235,7 @@ adm1026_attach(device_t parent, device_t aprint_error_dev(self, "unable to register with sysmon\n"); sysmon_envsys_destroy(sc->sc_sme); + sc->sc_sme = NULL; return; } @@ -268,8 +269,8 @@ adm1026_detach(device_t self, int flags) pmf_device_deregister(self); - sysmon_envsys_unregister(sc->sc_sme); - sc->sc_sme = NULL; + if (sc->sc_sme != NULL) + sysmon_envsys_unregister(sc->sc_sme); return 0; } @@ -320,6 +321,7 @@ adm1026_setup_fans(struct adm1026_softc if (sysmon_envsys_sensor_attach( sc->sc_sme, >sc_sensor[ADM1026_FAN_NUM(i)])) { sysmon_envsys_destroy(sc->sc_sme); +sc->sc_sme = NULL; aprint_error_dev(sc->sc_dev, "unable to attach fan %d at sysmon\n", i); return; @@ -377,6 +379,7 @@ adm1026_setup_temps(struct adm1026_softc if (sysmon_envsys_sensor_attach( sc->sc_sme, >sc_sensor[ADM1026_TEMP_NUM(i)])) { sysmon_envsys_destroy(sc->sc_sme); + sc->sc_sme = NULL; aprint_error_dev(sc->sc_dev, "unable to attach temp %d at sysmon\n", i); return; @@ -402,6 +405,7 @@ adm1026_setup_volts(struct adm1026_softc if (sysmon_envsys_sensor_attach( sc->sc_sme, >sc_sensor[ADM1026_VOLT_NUM(i)])) { sysmon_envsys_destroy(sc->sc_sme); + sc->sc_sme = NULL; aprint_error_dev(sc->sc_dev, "unable to attach volts %d at sysmon\n", i); return;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Sun Jun 13 09:48:45 UTC 2021 Modified Files: src/sys/dev/i2c: lm_i2c.c Log Message: iic_acquire_bus can fail To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/lm_i2c.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/dev/i2c/lm_i2c.c diff -u src/sys/dev/i2c/lm_i2c.c:1.6 src/sys/dev/i2c/lm_i2c.c:1.7 --- src/sys/dev/i2c/lm_i2c.c:1.6 Wed Jun 24 19:11:49 2020 +++ src/sys/dev/i2c/lm_i2c.c Sun Jun 13 09:48:44 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lm_i2c.c,v 1.6 2020/06/24 19:11:49 jdolecek Exp $ */ +/* $NetBSD: lm_i2c.c,v 1.7 2021/06/13 09:48:44 mlelstv Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lm_i2c.c,v 1.6 2020/06/24 19:11:49 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm_i2c.c,v 1.7 2021/06/13 09:48:44 mlelstv Exp $"); #include #include @@ -119,7 +119,8 @@ lm_i2c_readreg(struct lm_softc *lmsc, in struct lm_i2c_softc *sc = (struct lm_i2c_softc *)lmsc; uint8_t cmd, data; - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) + return 0; cmd = reg; iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, @@ -137,7 +138,8 @@ lm_i2c_writereg(struct lm_softc *lmsc, i struct lm_i2c_softc *sc = (struct lm_i2c_softc *)lmsc; uint8_t cmd, data; - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) + return; cmd = reg; data = val;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Sun Jun 13 09:48:04 UTC 2021 Modified Files: src/sys/dev/i2c: spdmem_i2c.c Log Message: iic_acquire_bus can fail To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/sys/dev/i2c/spdmem_i2c.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/dev/i2c/spdmem_i2c.c diff -u src/sys/dev/i2c/spdmem_i2c.c:1.21 src/sys/dev/i2c/spdmem_i2c.c:1.22 --- src/sys/dev/i2c/spdmem_i2c.c:1.21 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/spdmem_i2c.c Sun Jun 13 09:48:04 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: spdmem_i2c.c,v 1.21 2021/01/27 02:29:48 thorpej Exp $ */ +/* $NetBSD: spdmem_i2c.c,v 1.22 2021/06/13 09:48:04 mlelstv Exp $ */ /* * Copyright (c) 2007 Nicolas Joly @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.22 2021/06/13 09:48:04 mlelstv Exp $"); #include #include @@ -107,7 +107,9 @@ spdmem_reset_page(struct spdmem_i2c_soft reg = 0; - iic_acquire_bus(sc->sc_tag, 0); + rv = iic_acquire_bus(sc->sc_tag, 0); + if (rv) + return rv; /* * Try to read byte 0 and 2. If it failed, it's not spdmem or a device @@ -265,7 +267,9 @@ spdmem_i2c_read(struct spdmem_softc *sof reg = addr & 0xff; - iic_acquire_bus(sc->sc_tag, 0); + rv = iic_acquire_bus(sc->sc_tag, 0); + if (rv) + return rv; if (addr & 0x100) { rv = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_page1,
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Sun Jun 13 09:47:36 UTC 2021 Modified Files: src/sys/dev/i2c: sdtemp.c Log Message: Clear sc_sme pointer to avoid double free. To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/sys/dev/i2c/sdtemp.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/dev/i2c/sdtemp.c diff -u src/sys/dev/i2c/sdtemp.c:1.39 src/sys/dev/i2c/sdtemp.c:1.40 --- src/sys/dev/i2c/sdtemp.c:1.39 Tue Jun 30 19:02:42 2020 +++ src/sys/dev/i2c/sdtemp.c Sun Jun 13 09:47:36 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: sdtemp.c,v 1.39 2020/06/30 19:02:42 msaitoh Exp $*/ +/* $NetBSD: sdtemp.c,v 1.40 2021/06/13 09:47:36 mlelstv Exp $*/ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.39 2020/06/30 19:02:42 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.40 2021/06/13 09:47:36 mlelstv Exp $"); #include #include @@ -405,6 +405,7 @@ sdtemp_attach(device_t parent, device_t bad: kmem_free(sc->sc_sensor, sizeof(envsys_data_t)); sysmon_envsys_destroy(sc->sc_sme); + sc->sc_sme = NULL; } static int
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Sun Jun 13 09:46:04 UTC 2021 Modified Files: src/sys/dev/i2c: lm75.c lm87.c Log Message: iic_acquire_bus can fail. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/sys/dev/i2c/lm75.c cvs rdiff -u -r1.14 -r1.15 src/sys/dev/i2c/lm87.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/dev/i2c/lm75.c diff -u src/sys/dev/i2c/lm75.c:1.43 src/sys/dev/i2c/lm75.c:1.44 --- src/sys/dev/i2c/lm75.c:1.43 Fri May 21 20:42:05 2021 +++ src/sys/dev/i2c/lm75.c Sun Jun 13 09:46:04 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lm75.c,v 1.43 2021/05/21 20:42:05 macallan Exp $ */ +/* $NetBSD: lm75.c,v 1.44 2021/06/13 09:46:04 mlelstv Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.43 2021/05/21 20:42:05 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.44 2021/06/13 09:46:04 mlelstv Exp $"); #include #include @@ -230,7 +230,11 @@ lmtemp_attach(device_t parent, device_t sc->sc_lmtemp_decode = lmtemptbl[i].lmtemp_decode; sc->sc_lmtemp_encode = lmtemptbl[i].lmtemp_encode; - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) { + aprint_error_dev(self, + "unable to acquire I2C bus\n"); + return; + } /* Read temperature limit(s) and remember initial value(s). */ if (i == lmtemp_lm77) { @@ -378,7 +382,8 @@ lmtemp_refresh(struct sysmon_envsys *sme { struct lmtemp_softc *sc = sme->sme_cookie; - iic_acquire_bus(sc->sc_tag, 0); /* also locks our instance */ + if (iic_acquire_bus(sc->sc_tag, 0)) /* also locks our instance */ + return; lmtemp_refresh_sensor_data(sc); iic_release_bus(sc->sc_tag, 0); /* also unlocks our instance */ } @@ -392,7 +397,8 @@ lmtemp_getlim_lm75(struct sysmon_envsys *props &= ~(PROP_CRITMAX); - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) + return; if (lmtemp_temp_read(sc, LM75_REG_TOS_SET_POINT, , 0) == 0) { limits->sel_critmax = val; *props |= PROP_CRITMAX; @@ -409,7 +415,8 @@ lmtemp_getlim_lm77(struct sysmon_envsys *props &= ~(PROP_CRITMAX | PROP_WARNMAX | PROP_WARNMIN); - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) + return; if (lmtemp_temp_read(sc, LM77_REG_TCRIT_SET_POINT, , 0) == 0) { limits->sel_critmax = val; *props |= PROP_CRITMAX; @@ -437,7 +444,8 @@ lmtemp_setlim_lm75(struct sysmon_envsys limit = sc->sc_smax; else limit = limits->sel_critmax; - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) + return; lmtemp_temp_write(sc, LM75_REG_THYST_SET_POINT, limit - 500, 0); lmtemp_temp_write(sc, LM75_REG_TOS_SET_POINT, limit, 0); @@ -608,7 +616,7 @@ sysctl_lm75_temp(SYSCTLFN_ARGS) { struct sysctlnode node = *rnode; struct lmtemp_softc *sc = node.sysctl_data; - int temp; + int temp, error; if (newp) { @@ -618,7 +626,9 @@ sysctl_lm75_temp(SYSCTLFN_ARGS) temp = *(int *)node.sysctl_data; sc->sc_tmax = temp; - iic_acquire_bus(sc->sc_tag, 0); + error = iic_acquire_bus(sc->sc_tag, 0); + if (error) +return error; lmtemp_temp_write(sc, LM75_REG_THYST_SET_POINT, sc->sc_tmax - 5, 1); lmtemp_temp_write(sc, LM75_REG_TOS_SET_POINT, Index: src/sys/dev/i2c/lm87.c diff -u src/sys/dev/i2c/lm87.c:1.14 src/sys/dev/i2c/lm87.c:1.15 --- src/sys/dev/i2c/lm87.c:1.14 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/lm87.c Sun Jun 13 09:46:04 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lm87.c,v 1.14 2021/01/27 02:29:48 thorpej Exp $ */ +/* $NetBSD: lm87.c,v 1.15 2021/06/13 09:46:04 mlelstv Exp $ */ /* $OpenBSD: lm87.c,v 1.20 2008/11/10 05:19:48 cnst Exp $ */ /* @@ -18,7 +18,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lm87.c,v 1.14 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm87.c,v 1.15 2021/06/13 09:46:04 mlelstv Exp $"); #include #include @@ -162,7 +162,8 @@ lmenv_match(device_t parent, cfdata_t ma return 0; cmd = LM87_COMPANY_ID; - iic_acquire_bus(ia->ia_tag, 0); + if (iic_acquire_bus(ia->ia_tag, 0)) + return 0; error = iic_exec(ia->ia_tag, I2C_OP_READ_WITH_STOP, ia->ia_addr, , 1, , 1, 0); iic_release_bus(ia->ia_tag, 0);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: skrll Date: Mon May 24 05:58:42 UTC 2021 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: Bail out of axpreg_attach if axpreg_get_voltage returns an error. uvol isn't updated and shouldn't be used. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/sys/dev/i2c/axppmic.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/dev/i2c/axppmic.c diff -u src/sys/dev/i2c/axppmic.c:1.34 src/sys/dev/i2c/axppmic.c:1.35 --- src/sys/dev/i2c/axppmic.c:1.34 Sat Apr 24 23:36:54 2021 +++ src/sys/dev/i2c/axppmic.c Mon May 24 05:58:42 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.34 2021/04/24 23:36:54 thorpej Exp $ */ +/* $NetBSD: axppmic.c,v 1.35 2021/05/24 05:58:42 skrll Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.34 2021/04/24 23:36:54 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.35 2021/05/24 05:58:42 skrll Exp $"); #include #include @@ -1161,7 +1161,10 @@ axpreg_attach(device_t parent, device_t else aprint_normal("\n"); - axpreg_get_voltage(self, ); + int error = axpreg_get_voltage(self, ); + if (error) + return; + if (of_getprop_uint32(phandle, "regulator-min-microvolt", _uvol) == 0 && of_getprop_uint32(phandle, "regulator-max-microvolt", _uvol) == 0) { if (uvol < min_uvol || uvol > max_uvol) {
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Fri May 21 21:21:01 UTC 2021 Modified Files: src/sys/dev/i2c: m41st84.c Log Message: add \n to attach output To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/sys/dev/i2c/m41st84.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/dev/i2c/m41st84.c diff -u src/sys/dev/i2c/m41st84.c:1.31 src/sys/dev/i2c/m41st84.c:1.32 --- src/sys/dev/i2c/m41st84.c:1.31 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/m41st84.c Fri May 21 21:21:01 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: m41st84.c,v 1.31 2021/01/27 02:29:48 thorpej Exp $ */ +/* $NetBSD: m41st84.c,v 1.32 2021/05/21 21:21:01 macallan Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: m41st84.c,v 1.31 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: m41st84.c,v 1.32 2021/05/21 21:21:01 macallan Exp $"); #include #include @@ -194,7 +194,7 @@ strtc_attach(device_t parent, device_t s aprint_naive(": Real-time Clock%s\n", sm->sm_nvram_size ? "/NVRAM" : ""); - aprint_normal(": M41T%d Real-time Clock%s", sm->sm_model, + aprint_normal(": M41T%d Real-time Clock%s\n", sm->sm_model, sm->sm_nvram_size ? "/NVRAM" : ""); sc->sc_tag = ia->ia_tag;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Fri May 21 20:42:05 UTC 2021 Modified Files: src/sys/dev/i2c: lm75.c Log Message: don't prop_object_retain(NULL) To generate a diff of this commit: cvs rdiff -u -r1.42 -r1.43 src/sys/dev/i2c/lm75.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/dev/i2c/lm75.c diff -u src/sys/dev/i2c/lm75.c:1.42 src/sys/dev/i2c/lm75.c:1.43 --- src/sys/dev/i2c/lm75.c:1.42 Mon Mar 1 04:40:39 2021 +++ src/sys/dev/i2c/lm75.c Fri May 21 20:42:05 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lm75.c,v 1.42 2021/03/01 04:40:39 rin Exp $ */ +/* $NetBSD: lm75.c,v 1.43 2021/05/21 20:42:05 macallan Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.42 2021/03/01 04:40:39 rin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.43 2021/05/21 20:42:05 macallan Exp $"); #include #include @@ -215,7 +215,8 @@ lmtemp_attach(device_t parent, device_t sc->sc_tag = ia->ia_tag; sc->sc_address = ia->ia_addr; sc->sc_prop = ia->ia_prop; - prop_object_retain(sc->sc_prop); + + if (ia->ia_prop != NULL) prop_object_retain(sc->sc_prop); aprint_naive(": Temperature Sensor\n"); if (ia->ia_name) {
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: skrll Date: Fri Apr 16 07:02:09 UTC 2021 Modified Files: src/sys/dev/i2c: i2cvar.h Log Message: spello in comment To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/sys/dev/i2c/i2cvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/i2cvar.h diff -u src/sys/dev/i2c/i2cvar.h:1.23 src/sys/dev/i2c/i2cvar.h:1.24 --- src/sys/dev/i2c/i2cvar.h:1.23 Mon Jan 25 12:15:32 2021 +++ src/sys/dev/i2c/i2cvar.h Fri Apr 16 07:02:09 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: i2cvar.h,v 1.23 2021/01/25 12:15:32 jmcneill Exp $ */ +/* $NetBSD: i2cvar.h,v 1.24 2021/04/16 07:02:09 skrll Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -151,7 +151,7 @@ struct i2c_attach_args { int ia_ncompat; /* number of pointers in the ia_compat array */ const char ** ia_compat; /* chip names */ - prop_dictionary_t ia_prop; /* dictionnary for this device */ + prop_dictionary_t ia_prop; /* dictionary for this device */ /* * The following is of limited usefulness and should only be used * in rare cases where we really know what we are doing. Example:
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: rin Date: Mon Mar 1 04:40:39 UTC 2021 Modified Files: src/sys/dev/i2c: lm75.c Log Message: Use lmtemp(4) as entropy source. To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.42 src/sys/dev/i2c/lm75.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/dev/i2c/lm75.c diff -u src/sys/dev/i2c/lm75.c:1.41 src/sys/dev/i2c/lm75.c:1.42 --- src/sys/dev/i2c/lm75.c:1.41 Sat Feb 6 05:21:47 2021 +++ src/sys/dev/i2c/lm75.c Mon Mar 1 04:40:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lm75.c,v 1.41 2021/02/06 05:21:47 thorpej Exp $ */ +/* $NetBSD: lm75.c,v 1.42 2021/03/01 04:40:39 rin Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.41 2021/02/06 05:21:47 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.42 2021/03/01 04:40:39 rin Exp $"); #include #include @@ -279,7 +279,7 @@ lmtemp_attach(device_t parent, device_t /* Initialize sensor data. */ sc->sc_sensor.units = ENVSYS_STEMP; sc->sc_sensor.state = ENVSYS_SINVALID; - sc->sc_sensor.flags = ENVSYS_FMONLIMITS; + sc->sc_sensor.flags = ENVSYS_FMONLIMITS | ENVSYS_FHAS_ENTROPY; (void)strlcpy(name, ia->ia_name? ia->ia_name : device_xname(self),
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: rin Date: Mon Mar 1 04:39:45 UTC 2021 Modified Files: src/sys/dev/i2c: dstemp.c Log Message: Use dstemp(4) as entropy source. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sys/dev/i2c/dstemp.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/dev/i2c/dstemp.c diff -u src/sys/dev/i2c/dstemp.c:1.11 src/sys/dev/i2c/dstemp.c:1.12 --- src/sys/dev/i2c/dstemp.c:1.11 Sat Jan 30 17:37:25 2021 +++ src/sys/dev/i2c/dstemp.c Mon Mar 1 04:39:45 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: dstemp.c,v 1.11 2021/01/30 17:37:25 thorpej Exp $ */ +/* $NetBSD: dstemp.c,v 1.12 2021/03/01 04:39:45 rin Exp $ */ /*- * Copyright (c) 2018 Michael Lorenz @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.11 2021/01/30 17:37:25 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.12 2021/03/01 04:39:45 rin Exp $"); #include #include @@ -124,6 +124,7 @@ dstemp_attach(device_t parent, device_t sc->sc_sensor_temp.units = ENVSYS_STEMP; sc->sc_sensor_temp.state = ENVSYS_SINVALID; + sc->sc_sensor_temp.flags = ENVSYS_FHAS_ENTROPY; if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, "s00", )) { strncpy(name, desc, 64);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sat Feb 6 05:21:47 UTC 2021 Modified Files: src/sys/dev/i2c: lm75.c Log Message: - Add some additional compat strings from the DT bindings. - Use device_compatible_entry::value to hold the device type, and generally tidy up device type selection. To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.41 src/sys/dev/i2c/lm75.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/dev/i2c/lm75.c diff -u src/sys/dev/i2c/lm75.c:1.40 src/sys/dev/i2c/lm75.c:1.41 --- src/sys/dev/i2c/lm75.c:1.40 Sat Jan 30 01:22:06 2021 +++ src/sys/dev/i2c/lm75.c Sat Feb 6 05:21:47 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lm75.c,v 1.40 2021/01/30 01:22:06 thorpej Exp $ */ +/* $NetBSD: lm75.c,v 1.41 2021/02/06 05:21:47 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.40 2021/01/30 01:22:06 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.41 2021/02/06 05:21:47 thorpej Exp $"); #include #include @@ -94,10 +94,23 @@ static void lmtemp_setlim_lm77(struct sy static void lmtemp_setup_sysctl(struct lmtemp_softc *); static int sysctl_lm75_temp(SYSCTLFN_ARGS); +enum { + lmtemp_lm75 = 0, + lmtemp_ds75 = 1, + lmtemp_lm77 = 2, +}; + static const struct device_compatible_entry compat_data[] = { - { .compat = "i2c-lm75" }, - { .compat = "lm75" }, - { .compat = "ds1775" }, + { .compat = "national,lm75", .value = lmtemp_lm75 }, + { .compat = "i2c-lm75", .value = lmtemp_lm75 }, + { .compat = "lm75", .value = lmtemp_lm75 }, + + /* XXX Linux treats ds1775 and ds75 differently. */ + { .compat = "dallas,ds1775", .value = lmtemp_ds75 }, + { .compat = "ds1775", .value = lmtemp_ds75 }, + + { .compat = "national,lm77", .value = lmtemp_lm77 }, + /* * see XXX in _attach() below: add code once non-lm75 matches are * added here! @@ -105,13 +118,7 @@ static const struct device_compatible_en DEVICE_COMPAT_EOL }; -enum { - lmtemp_lm75 = 0, - lmtemp_ds75, - lmtemp_lm77, -}; static const struct { - int lmtemp_type; const char *lmtemp_name; int lmtemp_addrmask; int lmtemp_addr; @@ -122,18 +129,36 @@ static const struct { void (*lmtemp_setlim)(struct sysmon_envsys *, envsys_data_t *, sysmon_envsys_lim_t *, uint32_t *); } lmtemptbl[] = { - { lmtemp_lm75, "LM75", LM75_ADDRMASK, LM75_ADDR, - lmtemp_decode_lm75, lmtemp_encode_lm75, - lmtemp_getlim_lm75, lmtemp_setlim_lm75 }, - { lmtemp_ds75, "DS75", LM75_ADDRMASK, LM75_ADDR, - lmtemp_decode_ds75, lmtemp_encode_ds75, - lmtemp_getlim_lm75, lmtemp_setlim_lm75 }, - { lmtemp_lm77, "LM77", LM77_ADDRMASK, LM77_ADDR, - lmtemp_decode_lm77, lmtemp_encode_lm77, - lmtemp_getlim_lm77, lmtemp_setlim_lm77 }, - { -1, NULL, 0, 0, - NULL, NULL, - NULL, NULL } +[lmtemp_lm75] = + { + .lmtemp_name = "LM75", + .lmtemp_addrmask = LM75_ADDRMASK, + .lmtemp_addr = LM75_ADDR, + .lmtemp_decode = lmtemp_decode_lm75, + .lmtemp_encode = lmtemp_encode_lm75, + .lmtemp_getlim = lmtemp_getlim_lm75, + .lmtemp_setlim = lmtemp_setlim_lm75, + }, +[lmtemp_ds75] = + { + .lmtemp_name = "DS75", + .lmtemp_addrmask = LM75_ADDRMASK, + .lmtemp_addr = LM75_ADDR, + .lmtemp_decode = lmtemp_decode_ds75, + .lmtemp_encode = lmtemp_encode_ds75, + .lmtemp_getlim = lmtemp_getlim_lm75, + .lmtemp_setlim = lmtemp_setlim_lm75, + }, +[lmtemp_lm77] = + { + .lmtemp_name = "LM77", + .lmtemp_addrmask = LM77_ADDRMASK, + .lmtemp_addr = LM77_ADDR, + .lmtemp_decode = lmtemp_decode_lm77, + .lmtemp_encode = lmtemp_encode_lm77, + .lmtemp_getlim = lmtemp_getlim_lm77, + .lmtemp_setlim = lmtemp_setlim_lm77, + }, }; static int @@ -148,11 +173,14 @@ lmtemp_match(device_t parent, cfdata_t c /* * Indirect config - not much we can do! */ - for (i = 0; lmtemptbl[i].lmtemp_type != -1 ; i++) - if (lmtemptbl[i].lmtemp_type == cf->cf_flags) + for (i = 0; i < __arraycount(lmtemptbl); i++) { + if (i == cf->cf_flags) { break; - if (lmtemptbl[i].lmtemp_type == -1) + } + } + if (i == __arraycount(lmtemptbl)) { return 0; + } if ((ia->ia_addr & lmtemptbl[i].lmtemp_addrmask) == lmtemptbl[i].lmtemp_addr) @@ -166,23 +194,22 @@ lmtemp_attach(device_t parent, device_t { struct lmtemp_softc *sc = device_private(self); struct i2c_attach_args *ia = aux; + const struct device_compatible_entry *dce; char name[64]; const char *desc; int i; sc->sc_dev = self; - if (ia->ia_name == NULL) { - for (i = 0; lmtemptbl[i].lmtemp_type != -1 ; i++) - if (lmtemptbl[i].lmtemp_type == - device_cfdata(self)->cf_flags) -break; + dce = iic_compatible_lookup(ia, compat_data); + if (dce != NULL) { + i = (int)dce->value; } else { - if (strcmp(ia->ia_name, "ds1775") == 0) { - i = 1; /* LMTYPE_DS75 */ - } else { - /* XXX - add code when adding other direct matches! */ - i = 0; + for (i = 0; i <
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sat Jan 30 17:38:57 UTC 2021 Modified Files: src/sys/dev/i2c: s390.c Log Message: Add the standard compat string from the Device Tree bindings. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/s390.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/dev/i2c/s390.c diff -u src/sys/dev/i2c/s390.c:1.6 src/sys/dev/i2c/s390.c:1.7 --- src/sys/dev/i2c/s390.c:1.6 Thu Jan 2 19:00:34 2020 +++ src/sys/dev/i2c/s390.c Sat Jan 30 17:38:57 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: s390.c,v 1.6 2020/01/02 19:00:34 thorpej Exp $ */ +/* $NetBSD: s390.c,v 1.7 2021/01/30 17:38:57 thorpej Exp $ */ /*- * Copyright (c) 2011 Frank Wille. @@ -29,7 +29,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: s390.c,v 1.6 2020/01/02 19:00:34 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: s390.c,v 1.7 2021/01/30 17:38:57 thorpej Exp $"); #include #include @@ -62,13 +62,18 @@ static int s390rtc_read(struct s390rtc_s static int s390rtc_write(struct s390rtc_softc *, int, uint8_t *, size_t); static uint8_t bitreverse(uint8_t); +static const struct device_compatible_entry compat_data[] = { + { .compat = "sii,s35390a" }, + DEVICE_COMPAT_EOL +}; + static int s390rtc_match(device_t parent, cfdata_t cf, void *arg) { struct i2c_attach_args *ia = arg; int match_result; - if (iic_use_direct_match(ia, cf, NULL, _result)) + if (iic_use_direct_match(ia, cf, compat_data, _result)) return match_result; /* indirect config - check typical address */
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sat Jan 30 17:38:28 UTC 2021 Modified Files: src/sys/dev/i2c: rs5c372.c Log Message: Add standard compat strings from the Device Tree bindings. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sys/dev/i2c/rs5c372.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/dev/i2c/rs5c372.c diff -u src/sys/dev/i2c/rs5c372.c:1.16 src/sys/dev/i2c/rs5c372.c:1.17 --- src/sys/dev/i2c/rs5c372.c:1.16 Thu Jan 2 17:17:36 2020 +++ src/sys/dev/i2c/rs5c372.c Sat Jan 30 17:38:27 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: rs5c372.c,v 1.16 2020/01/02 17:17:36 thorpej Exp $ */ +/* $NetBSD: rs5c372.c,v 1.17 2021/01/30 17:38:27 thorpej Exp $ */ /*- * Copyright (C) 2005 NONAKA Kimihiro @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rs5c372.c,v 1.16 2020/01/02 17:17:36 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rs5c372.c,v 1.17 2021/01/30 17:38:27 thorpej Exp $"); #include #include @@ -61,13 +61,19 @@ static int rs5c372rtc_clock_write(struct static int rs5c372rtc_gettime_ymdhms(todr_chip_handle_t, struct clock_ymdhms *); static int rs5c372rtc_settime_ymdhms(todr_chip_handle_t, struct clock_ymdhms *); +static const struct device_compatible_entry compat_data[] = { + { .compat = "ricoh,rs5c372a" }, + { .compat = "ricoh,rs5c372b" }, + DEVICE_COMPAT_EOL +}; + static int rs5c372rtc_match(device_t parent, cfdata_t cf, void *arg) { struct i2c_attach_args *ia = arg; int match_result; - if (iic_use_direct_match(ia, cf, NULL, _result)) + if (iic_use_direct_match(ia, cf, compat_data, _result)) return match_result; /* indirect config - check typical address */
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sat Jan 30 17:37:25 UTC 2021 Modified Files: src/sys/dev/i2c: dstemp.c Log Message: Add the standard compat string from the Device Tree bindings. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sys/dev/i2c/dstemp.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/dev/i2c/dstemp.c diff -u src/sys/dev/i2c/dstemp.c:1.10 src/sys/dev/i2c/dstemp.c:1.11 --- src/sys/dev/i2c/dstemp.c:1.10 Sat Jan 30 01:22:06 2021 +++ src/sys/dev/i2c/dstemp.c Sat Jan 30 17:37:25 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: dstemp.c,v 1.10 2021/01/30 01:22:06 thorpej Exp $ */ +/* $NetBSD: dstemp.c,v 1.11 2021/01/30 17:37:25 thorpej Exp $ */ /*- * Copyright (c) 2018 Michael Lorenz @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.10 2021/01/30 01:22:06 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.11 2021/01/30 17:37:25 thorpej Exp $"); #include #include @@ -78,6 +78,7 @@ CFATTACH_DECL_NEW(dstemp, sizeof(struct dstemp_match, dstemp_attach, NULL, NULL); static const struct device_compatible_entry compat_data[] = { + { .compat = "dallas,ds1631" }, { .compat = "ds1631" }, DEVICE_COMPAT_EOL };
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sat Jan 30 01:23:08 UTC 2021 Modified Files: src/sys/dev/i2c: sgsmix.c Log Message: Add a proper compat string for this device, following the standard conventions. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/sgsmix.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/dev/i2c/sgsmix.c diff -u src/sys/dev/i2c/sgsmix.c:1.9 src/sys/dev/i2c/sgsmix.c:1.10 --- src/sys/dev/i2c/sgsmix.c:1.9 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/sgsmix.c Sat Jan 30 01:23:08 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: sgsmix.c,v 1.9 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: sgsmix.c,v 1.10 2021/01/30 01:23:08 thorpej Exp $ */ /*- * Copyright (C) 2005 Michael Lorenz. @@ -31,7 +31,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: sgsmix.c,v 1.9 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sgsmix.c,v 1.10 2021/01/30 01:23:08 thorpej Exp $"); #include #include @@ -75,6 +75,11 @@ static void sgsmix_writereg(struct sgsmi CFATTACH_DECL_NEW(sgsmix, sizeof(struct sgsmix_softc), sgsmix_match, sgsmix_attach, NULL, NULL); +static const struct device_compatible_entry compat_data[] = { + { .compat = "st,tda7433" }, + DEVICE_COMPAT_EOL +}; + static int sgsmix_match(device_t parent, cfdata_t cf, void *aux) { @@ -83,7 +88,7 @@ sgsmix_match(device_t parent, cfdata_t c uint8_t out[2] = {1, 0x20}; int match_result; - if (iic_use_direct_match(args, cf, NULL, _result)) + if (iic_use_direct_match(args, cf, compat_data, _result)) return match_result; /* see if we can talk to something at address 0x8a */
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sat Jan 30 01:22:06 UTC 2021 Modified Files: src/sys/dev/i2c: adm1021.c dbcool.c dstemp.c lm75.c Log Message: If we're going to keep a reference on the "props" dictionary from the i2c_attach_args, we should retain it. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/sys/dev/i2c/adm1021.c cvs rdiff -u -r1.59 -r1.60 src/sys/dev/i2c/dbcool.c cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/dstemp.c cvs rdiff -u -r1.39 -r1.40 src/sys/dev/i2c/lm75.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/dev/i2c/adm1021.c diff -u src/sys/dev/i2c/adm1021.c:1.26 src/sys/dev/i2c/adm1021.c:1.27 --- src/sys/dev/i2c/adm1021.c:1.26 Thu Jan 28 14:35:11 2021 +++ src/sys/dev/i2c/adm1021.c Sat Jan 30 01:22:06 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: adm1021.c,v 1.26 2021/01/28 14:35:11 thorpej Exp $ */ +/* $NetBSD: adm1021.c,v 1.27 2021/01/30 01:22:06 thorpej Exp $ */ /* $OpenBSD: adm1021.c,v 1.27 2007/06/24 05:34:35 dlg Exp $ */ /* @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.26 2021/01/28 14:35:11 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.27 2021/01/30 01:22:06 thorpej Exp $"); #include #include @@ -342,6 +342,7 @@ admtemp_attach(device_t parent, device_t sc->sc_tag = ia->ia_tag; sc->sc_addr = ia->ia_addr; sc->sc_prop = ia->ia_prop; + prop_object_retain(sc->sc_prop); iic_acquire_bus(sc->sc_tag, 0); cmd = ADM1021_CONFIG_READ; Index: src/sys/dev/i2c/dbcool.c diff -u src/sys/dev/i2c/dbcool.c:1.59 src/sys/dev/i2c/dbcool.c:1.60 --- src/sys/dev/i2c/dbcool.c:1.59 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/dbcool.c Sat Jan 30 01:22:06 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: dbcool.c,v 1.59 2021/01/27 02:29:48 thorpej Exp $ */ +/* $NetBSD: dbcool.c,v 1.60 2021/01/30 01:22:06 thorpej Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -50,7 +50,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.59 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.60 2021/01/30 01:22:06 thorpej Exp $"); #include #include @@ -776,6 +776,7 @@ dbcool_attach(device_t parent, device_t sc->sc_dc.dc_writereg = dbcool_writereg; sc->sc_dev = self; sc->sc_prop = args->ia_prop; + prop_object_retain(sc->sc_prop); if (dbcool_chip_ident(>sc_dc) < 0 || sc->sc_dc.dc_chip == NULL) panic("could not identify chip at addr %d", args->ia_addr); Index: src/sys/dev/i2c/dstemp.c diff -u src/sys/dev/i2c/dstemp.c:1.9 src/sys/dev/i2c/dstemp.c:1.10 --- src/sys/dev/i2c/dstemp.c:1.9 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/dstemp.c Sat Jan 30 01:22:06 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: dstemp.c,v 1.9 2021/01/27 02:29:48 thorpej Exp $ */ +/* $NetBSD: dstemp.c,v 1.10 2021/01/30 01:22:06 thorpej Exp $ */ /*- * Copyright (c) 2018 Michael Lorenz @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.9 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.10 2021/01/30 01:22:06 thorpej Exp $"); #include #include @@ -109,6 +109,7 @@ dstemp_attach(device_t parent, device_t sc->sc_i2c = ia->ia_tag; sc->sc_addr = ia->ia_addr; sc->sc_prop = ia->ia_prop; + prop_object_retain(sc->sc_prop); aprint_naive("\n"); aprint_normal(": DS1361\n"); Index: src/sys/dev/i2c/lm75.c diff -u src/sys/dev/i2c/lm75.c:1.39 src/sys/dev/i2c/lm75.c:1.40 --- src/sys/dev/i2c/lm75.c:1.39 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/lm75.c Sat Jan 30 01:22:06 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lm75.c,v 1.39 2021/01/27 02:29:48 thorpej Exp $ */ +/* $NetBSD: lm75.c,v 1.40 2021/01/30 01:22:06 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.39 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.40 2021/01/30 01:22:06 thorpej Exp $"); #include #include @@ -188,6 +188,7 @@ lmtemp_attach(device_t parent, device_t sc->sc_tag = ia->ia_tag; sc->sc_address = ia->ia_addr; sc->sc_prop = ia->ia_prop; + prop_object_retain(sc->sc_prop); aprint_naive(": Temperature Sensor\n"); if (ia->ia_name) {
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 28 14:57:43 UTC 2021 Modified Files: src/sys/dev/i2c: at24cxx.c Log Message: No need to consult ia->ia_ncompat before calling iic_compatible_lookup(). To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.41 src/sys/dev/i2c/at24cxx.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/dev/i2c/at24cxx.c diff -u src/sys/dev/i2c/at24cxx.c:1.40 src/sys/dev/i2c/at24cxx.c:1.41 --- src/sys/dev/i2c/at24cxx.c:1.40 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/at24cxx.c Thu Jan 28 14:57:43 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: at24cxx.c,v 1.40 2021/01/27 02:29:48 thorpej Exp $ */ +/* $NetBSD: at24cxx.c,v 1.41 2021/01/28 14:57:43 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.40 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.41 2021/01/28 14:57:43 thorpej Exp $"); #include #include @@ -180,7 +180,7 @@ seeprom_attach(device_t parent, device_t if (device_cfdata(self)->cf_flags) sc->sc_size = (device_cfdata(self)->cf_flags << 7); - if (sc->sc_size <= 0 && ia->ia_ncompat > 0) { + if (sc->sc_size <= 0) { if ((dce = iic_compatible_lookup(ia, compat_data)) != NULL) sc->sc_size = dce->value; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 28 14:42:45 UTC 2021 Modified Files: src/sys/dev/i2c: ssdfb_i2c.c Log Message: Use iic_compatible_lookup() in ssdfb_i2c_attach(). To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/sys/dev/i2c/ssdfb_i2c.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/dev/i2c/ssdfb_i2c.c diff -u src/sys/dev/i2c/ssdfb_i2c.c:1.8 src/sys/dev/i2c/ssdfb_i2c.c:1.9 --- src/sys/dev/i2c/ssdfb_i2c.c:1.8 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/ssdfb_i2c.c Thu Jan 28 14:42:45 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: ssdfb_i2c.c,v 1.8 2021/01/27 02:29:48 thorpej Exp $ */ +/* $NetBSD: ssdfb_i2c.c,v 1.9 2021/01/28 14:42:45 thorpej Exp $ */ /* * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ssdfb_i2c.c,v 1.8 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ssdfb_i2c.c,v 1.9 2021/01/28 14:42:45 thorpej Exp $"); #include #include @@ -67,8 +67,12 @@ CFATTACH_DECL_NEW(ssdfb_iic, sizeof(stru ssdfb_i2c_match, ssdfb_i2c_attach, ssdfb_i2c_detach, NULL); static const struct device_compatible_entry compat_data[] = { - { .compat = "solomon,ssd1306fb-i2c" }, - { .compat = "sino,sh1106fb-i2c" }, + { .compat = "solomon,ssd1306fb-i2c", + .value = SSDFB_PRODUCT_SSD1306_GENERIC }, + + { .compat = "sino,sh1106fb-i2c", + .value = SSDFB_PRODUCT_SH1106_GENERIC }, + DEVICE_COMPAT_EOL }; @@ -97,20 +101,12 @@ ssdfb_i2c_attach(device_t parent, device struct cfdata *cf = device_cfdata(self); struct i2c_attach_args *ia = aux; int flags = cf->cf_flags; - int i; if ((flags & SSDFB_ATTACH_FLAG_PRODUCT_MASK) == SSDFB_PRODUCT_UNKNOWN) { - for (i = 0; i < ia->ia_ncompat; i++) { - if (strncmp("solomon,ssd1306", ia->ia_compat[i], 15) - == 0) { -flags |= SSDFB_PRODUCT_SSD1306_GENERIC; -break; - } - else if (strncmp("sino,sh1106", ia->ia_compat[i], 11) - == 0) { -flags |= SSDFB_PRODUCT_SH1106_GENERIC; -break; - } + const struct device_compatible_entry *dce = + iic_compatible_lookup(ia, compat_data); + if (dce != NULL) { + flags |= (int)dce->value; } } if ((flags & SSDFB_ATTACH_FLAG_PRODUCT_MASK) == SSDFB_PRODUCT_UNKNOWN)
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 28 14:35:11 UTC 2021 Modified Files: src/sys/dev/i2c: adm1021.c Log Message: Use iic_compatible_lookup() in admtemp_setflags(). To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sys/dev/i2c/adm1021.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/dev/i2c/adm1021.c diff -u src/sys/dev/i2c/adm1021.c:1.25 src/sys/dev/i2c/adm1021.c:1.26 --- src/sys/dev/i2c/adm1021.c:1.25 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/adm1021.c Thu Jan 28 14:35:11 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: adm1021.c,v 1.25 2021/01/27 02:29:48 thorpej Exp $ */ +/* $NetBSD: adm1021.c,v 1.26 2021/01/28 14:35:11 thorpej Exp $ */ /* $OpenBSD: adm1021.c,v 1.27 2007/06/24 05:34:35 dlg Exp $ */ /* @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.25 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.26 2021/01/28 14:35:11 thorpej Exp $"); #include #include @@ -143,11 +143,42 @@ void admtemp_setlim_1032(struct sysmon_e CFATTACH_DECL_NEW(admtemp, sizeof(struct admtemp_softc), admtemp_match, admtemp_attach, NULL, NULL); -/* XXX: add flags for compats to admtemp_setflags() */ +struct admtemp_params { + const char *name; + int noneg; + int nolow; + int ext11; + int therm; +}; + +static const struct admtemp_params admtemp_params_max1617 = { + .name = "MAX1617A", + .noneg = 0, + .nolow = 0, + .ext11 = 0, + .therm = 0, +}; + +static const struct admtemp_params admtemp_params_max6642 = { + .name = "MAX6642", + .noneg = 0, + .nolow = 1, + .ext11 = 0, + .therm = 0, +}; + +static const struct admtemp_params admtemp_params_max6690 = { + .name = "MAX6690", + .noneg = 0, + .nolow = 0, + .ext11 = 1, + .therm = 0, +}; + static const struct device_compatible_entry compat_data[] = { - { .compat = "i2c-max1617" }, - { .compat = "max6642" }, - { .compat = "max6690" }, + { .compat = "i2c-max1617", .data = _params_max1617 }, + { .compat = "max6642", .data = _params_max6642 }, + { .compat = "max6690", .data = _params_max6690 }, DEVICE_COMPAT_EOL }; @@ -203,7 +234,6 @@ admtemp_setflags(struct admtemp_softc *s uint8_t* comp, uint8_t *rev, char* name) { uint8_t cmd, data, tmp; - int i; *comp = 0; *rev = 0; @@ -220,24 +250,17 @@ admtemp_setflags(struct admtemp_softc *s sc->sc_therm = 0; /* Direct config */ - for (i = 0; i < ia->ia_ncompat; i++) { - if (strcmp("i2c-max1617", ia->ia_compat[i]) == 0) { - sc->sc_noneg = 0; - strlcpy(name, "MAX1617A", ADMTEMP_NAMELEN); - return; - } - if (strcmp("max6642", ia->ia_compat[i]) == 0) { - sc->sc_noneg = 0; - sc->sc_nolow = 1; - strlcpy(name, "MAX6642", ADMTEMP_NAMELEN); - return; - } - if (strcmp("max6690", ia->ia_compat[i]) == 0) { - sc->sc_noneg = 0; - sc->sc_ext11 = 1; - strlcpy(name, "MAX6690", ADMTEMP_NAMELEN); - return; - } + const struct device_compatible_entry *dce = + iic_compatible_lookup(ia, compat_data); + if (dce != NULL) { + const struct admtemp_params *params = dce->data; + + sc->sc_noneg = params->noneg; + sc->sc_nolow = params->nolow; + sc->sc_ext11 = params->ext11; + sc->sc_therm = params->therm; + strlcpy(name, params->name, ADMTEMP_NAMELEN); + return; } /* Indirect config */
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Wed Jan 27 02:29:48 UTC 2021 Modified Files: src/sys/dev/i2c: ac100.c adadc.c adm1021.c adm1026.c anxedp.c as3722.c asms.c at24cxx.c axp20x.c axp22x.c axppmic.c cwfg.c dbcool.c ds1307.c dstemp.c em3027.c es8316ac.c fan53555.c fcu.c hytp14.c ihidev.c lm75.c lm87.c m41st84.c max77620.c pca9685.c pcagpio.c pcai2cmux.c pcf8563.c pcf8574.c rkpmic.c spdmem_i2c.c ssdfb_i2c.c sy8106a.c tcagpio.c tcakp.c tda19988.c titemp.c tps65217pmic.c tsllux.c Log Message: Use DEVICE_COMPAT_EOL. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/ac100.c src/sys/dev/i2c/tda19988.c cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/adadc.c src/sys/dev/i2c/pcagpio.c cvs rdiff -u -r1.24 -r1.25 src/sys/dev/i2c/adm1021.c cvs rdiff -u -r1.10 -r1.11 src/sys/dev/i2c/adm1026.c \ src/sys/dev/i2c/max77620.c src/sys/dev/i2c/titemp.c cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/anxedp.c src/sys/dev/i2c/pca9685.c cvs rdiff -u -r1.21 -r1.22 src/sys/dev/i2c/as3722.c cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/asms.c src/sys/dev/i2c/cwfg.c cvs rdiff -u -r1.39 -r1.40 src/sys/dev/i2c/at24cxx.c cvs rdiff -u -r1.18 -r1.19 src/sys/dev/i2c/axp20x.c cvs rdiff -u -r1.8 -r1.9 src/sys/dev/i2c/axp22x.c src/sys/dev/i2c/dstemp.c \ src/sys/dev/i2c/fan53555.c src/sys/dev/i2c/pcf8574.c cvs rdiff -u -r1.32 -r1.33 src/sys/dev/i2c/axppmic.c cvs rdiff -u -r1.58 -r1.59 src/sys/dev/i2c/dbcool.c cvs rdiff -u -r1.37 -r1.38 src/sys/dev/i2c/ds1307.c cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/em3027.c src/sys/dev/i2c/pcai2cmux.c \ src/sys/dev/i2c/ssdfb_i2c.c src/sys/dev/i2c/sy8106a.c \ src/sys/dev/i2c/tcagpio.c cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/es8316ac.c cvs rdiff -u -r1.11 -r1.12 src/sys/dev/i2c/fcu.c src/sys/dev/i2c/rkpmic.c cvs rdiff -u -r1.12 -r1.13 src/sys/dev/i2c/hytp14.c cvs rdiff -u -r1.17 -r1.18 src/sys/dev/i2c/ihidev.c \ src/sys/dev/i2c/tps65217pmic.c cvs rdiff -u -r1.38 -r1.39 src/sys/dev/i2c/lm75.c cvs rdiff -u -r1.13 -r1.14 src/sys/dev/i2c/lm87.c cvs rdiff -u -r1.30 -r1.31 src/sys/dev/i2c/m41st84.c cvs rdiff -u -r1.14 -r1.15 src/sys/dev/i2c/pcf8563.c src/sys/dev/i2c/tcakp.c cvs rdiff -u -r1.20 -r1.21 src/sys/dev/i2c/spdmem_i2c.c cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/tsllux.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/dev/i2c/ac100.c diff -u src/sys/dev/i2c/ac100.c:1.6 src/sys/dev/i2c/ac100.c:1.7 --- src/sys/dev/i2c/ac100.c:1.6 Mon Jan 25 13:30:20 2021 +++ src/sys/dev/i2c/ac100.c Wed Jan 27 02:29:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: ac100.c,v 1.6 2021/01/25 13:30:20 thorpej Exp $ */ +/* $NetBSD: ac100.c,v 1.7 2021/01/27 02:29:48 thorpej Exp $ */ /*- * Copyright (c) 2014 Jared D. McNeill @@ -29,7 +29,7 @@ #include "opt_fdt.h" #include -__KERNEL_RCSID(0, "$NetBSD: ac100.c,v 1.6 2021/01/25 13:30:20 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ac100.c,v 1.7 2021/01/27 02:29:48 thorpej Exp $"); #include #include @@ -94,7 +94,7 @@ __KERNEL_RCSID(0, "$NetBSD: ac100.c,v 1. static const struct device_compatible_entry compat_data[] = { { .compat = "x-powers,ac100" }, - { } + DEVICE_COMPAT_EOL }; struct ac100_softc { Index: src/sys/dev/i2c/tda19988.c diff -u src/sys/dev/i2c/tda19988.c:1.6 src/sys/dev/i2c/tda19988.c:1.7 --- src/sys/dev/i2c/tda19988.c:1.6 Mon Jan 25 13:30:20 2021 +++ src/sys/dev/i2c/tda19988.c Wed Jan 27 02:29:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tda19988.c,v 1.6 2021/01/25 13:30:20 thorpej Exp $ */ +/* $NetBSD: tda19988.c,v 1.7 2021/01/27 02:29:48 thorpej Exp $ */ /*- * Copyright (c) 2015 Oleksandr Tymoshenko @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tda19988.c,v 1.6 2021/01/25 13:30:20 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tda19988.c,v 1.7 2021/01/27 02:29:48 thorpej Exp $"); /* * NXP TDA19988 HDMI encoder @@ -245,7 +245,7 @@ enum { static const struct device_compatible_entry compat_data[] = { { .compat = "nxp,tda998x" }, - { } + DEVICE_COMPAT_EOL }; struct tda19988_softc; Index: src/sys/dev/i2c/adadc.c diff -u src/sys/dev/i2c/adadc.c:1.9 src/sys/dev/i2c/adadc.c:1.10 --- src/sys/dev/i2c/adadc.c:1.9 Mon Jan 25 13:30:20 2021 +++ src/sys/dev/i2c/adadc.c Wed Jan 27 02:29:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: adadc.c,v 1.9 2021/01/25 13:30:20 thorpej Exp $ */ +/* $NetBSD: adadc.c,v 1.10 2021/01/27 02:29:48 thorpej Exp $ */ /*- * Copyright (c) 2018 Michael Lorenz @@ -34,7 +34,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: adadc.c,v 1.9 2021/01/25 13:30:20 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adadc.c,v 1.10 2021/01/27 02:29:48 thorpej Exp $"); #include #include @@ -95,7 +95,7 @@ CFATTACH_DECL_NEW(adadc, sizeof(struct a static const struct device_compatible_entry compat_data[] = { { .compat = "ad7417" }, - { } + DEVICE_COMPAT_EOL }; /* calibaration table from Darwin via
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Wed Jan 27 02:28:37 UTC 2021 Modified Files: src/sys/dev/i2c: twl4030.c Log Message: Replace 2 uses of of_match_compatible(). Also use DEVICE_COMPAT_EOL. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/twl4030.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/dev/i2c/twl4030.c diff -u src/sys/dev/i2c/twl4030.c:1.4 src/sys/dev/i2c/twl4030.c:1.5 --- src/sys/dev/i2c/twl4030.c:1.4 Sun Jan 17 21:42:35 2021 +++ src/sys/dev/i2c/twl4030.c Wed Jan 27 02:28:37 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: twl4030.c,v 1.4 2021/01/17 21:42:35 thorpej Exp $ */ +/* $NetBSD: twl4030.c,v 1.5 2021/01/27 02:28:37 thorpej Exp $ */ /*- * Copyright (c) 2019 Jared McNeill @@ -29,7 +29,7 @@ #include "opt_fdt.h" #include -__KERNEL_RCSID(0, "$NetBSD: twl4030.c,v 1.4 2021/01/17 21:42:35 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: twl4030.c,v 1.5 2021/01/27 02:28:37 thorpej Exp $"); #include #include @@ -100,13 +100,19 @@ struct twl_pin { static const struct device_compatible_entry compat_data[] = { { .compat = "ti,twl4030" }, - - { 0 } + DEVICE_COMPAT_EOL }; #ifdef FDT -static const char * const rtc_compatible[] = { "ti,twl4030-rtc", NULL }; -static const char * const gpio_compatible[] = { "ti,twl4030-gpio", NULL }; +static const struct device_compatible_entry rtc_compat_data[] = { + { .compat = "ti,twl4030-rtc" }, + DEVICE_COMPAT_EOL +}; + +static const struct device_compatible_entry gpio_compat_data[] = { + { .compat = "ti,twl4030-gpio" }, + DEVICE_COMPAT_EOL +}; #endif static uint8_t @@ -384,10 +390,10 @@ twl_attach(device_t parent, device_t sel #ifdef FDT for (int child = OF_child(sc->sc_phandle); child; child = OF_peer(child)) { - if (of_match_compatible(child, gpio_compatible)) { + if (of_match_compat_data(child, gpio_compat_data)) { aprint_normal(", GPIO"); twl_gpio_attach(sc, child); - } else if (of_match_compatible(child, rtc_compatible)) { + } else if (of_match_compat_data(child, rtc_compat_data)) { aprint_normal(", RTC"); twl_rtc_attach(sc, child); }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Tue Jan 26 02:33:55 UTC 2021 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: Now that the ACPI layer no longer does this for us, evaluate the _DSM that returns the HID descriptor address at attach time. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sys/dev/i2c/ihidev.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/dev/i2c/ihidev.c diff -u src/sys/dev/i2c/ihidev.c:1.16 src/sys/dev/i2c/ihidev.c:1.17 --- src/sys/dev/i2c/ihidev.c:1.16 Tue Jan 26 01:23:08 2021 +++ src/sys/dev/i2c/ihidev.c Tue Jan 26 02:33:54 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.16 2021/01/26 01:23:08 thorpej Exp $ */ +/* $NetBSD: ihidev.c,v 1.17 2021/01/26 02:33:54 thorpej Exp $ */ /* $OpenBSD ihidev.c,v 1.13 2017/04/08 02:57:23 deraadt Exp $ */ /*- @@ -54,7 +54,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.16 2021/01/26 01:23:08 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.17 2021/01/26 02:33:54 thorpej Exp $"); #include #include @@ -125,6 +125,8 @@ static int ihidev_maxrepid(void *, int); static int ihidev_print(void *, const char *); static int ihidev_submatch(device_t, cfdata_t, const int *, void *); +static bool ihidev_acpi_get_info(struct ihidev_softc *); + static const struct device_compatible_entry compat_data[] = { { .compat = "PNP0C50" }, { .compat = "ACPI0C50" }, @@ -153,22 +155,21 @@ ihidev_attach(device_t parent, device_t device_t dev; int repid, repsz; int isize; - uint32_t v; int locs[IHIDBUSCF_NLOCS]; - sc->sc_dev = self; sc->sc_tag = ia->ia_tag; sc->sc_addr = ia->ia_addr; - sc->sc_phandle = ia->ia_cookie; mutex_init(>sc_intr_lock, MUTEX_DEFAULT, IPL_VM); - if (!prop_dictionary_get_uint32(ia->ia_prop, "hid-descr-addr", )) { - aprint_error(": no hid-descr-addr value\n"); + sc->sc_phandle = ia->ia_cookie; + if (ia->ia_cookietype != I2C_COOKIE_ACPI) { + aprint_error(": unsupported device tree type\n"); + return; + } + if (! ihidev_acpi_get_info(sc)) { return; } - - sc->sc_hid_desc_addr = v; if (ihidev_hid_command(sc, I2C_HID_CMD_DESCR, NULL, false) || ihidev_hid_desc_parse(sc)) { @@ -968,3 +969,32 @@ ihidev_set_report(struct device *dev, in return 0; } + +static bool +ihidev_acpi_get_info(struct ihidev_softc *sc) +{ + ACPI_HANDLE hdl = (void *)(uintptr_t)sc->sc_phandle; + ACPI_STATUS status; + ACPI_INTEGER val; + + /* 3cdff6f7-4267-4555-ad05-b30a3d8938de */ + uint8_t i2c_hid_guid[] = { + 0xF7, 0xF6, 0xDF, 0x3C, + 0x67, 0x42, + 0x55, 0x45, + 0xAD, 0x05, + 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE, + }; + + status = acpi_dsm_integer(hdl, i2c_hid_guid, 1, 1, NULL, ); + if (ACPI_FAILURE(status)) { + aprint_error_dev(sc->sc_dev, + "failed to get HidDescriptorAddress: %s\n", + AcpiFormatException(status)); + return false; + } + + sc->sc_hid_desc_addr = (u_int)val; + + return true; +}
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Tue Jan 26 01:15:39 UTC 2021 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: Back out unintended change in previous. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/sys/dev/i2c/ihidev.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/dev/i2c/ihidev.c diff -u src/sys/dev/i2c/ihidev.c:1.14 src/sys/dev/i2c/ihidev.c:1.15 --- src/sys/dev/i2c/ihidev.c:1.14 Mon Jan 25 13:30:20 2021 +++ src/sys/dev/i2c/ihidev.c Tue Jan 26 01:15:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.14 2021/01/25 13:30:20 thorpej Exp $ */ +/* $NetBSD: ihidev.c,v 1.15 2021/01/26 01:15:39 thorpej Exp $ */ /* $OpenBSD ihidev.c,v 1.13 2017/04/08 02:57:23 deraadt Exp $ */ /*- @@ -54,7 +54,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.14 2021/01/25 13:30:20 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.15 2021/01/26 01:15:39 thorpej Exp $"); #include #include @@ -126,8 +126,6 @@ static int ihidev_print(void *, const ch static int ihidev_submatch(device_t, cfdata_t, const int *, void *); static const struct device_compatible_entry compat_data[] = { - { .compat = "PNP0C50" }, - { .compat = "ACPI0C50" }, { .compat = "hid-over-i2c" }, { } };
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Jan 25 13:30:20 UTC 2021 Modified Files: src/sys/dev/i2c: ac100.c adadc.c adm1021.c adm1026.c anxedp.c as3722.c asms.c at24cxx.c axp20x.c axp22x.c axppmic.c cwfg.c dbcool.c ds1307.c dstemp.c em3027.c es8316ac.c fan53555.c fcu.c hytp14.c ihidev.c lm75.c lm87.c m41st84.c max77620.c pca9685.c pcagpio.c pcf8563.c pcf8574.c rkpmic.c spdmem_i2c.c ssdfb_i2c.c sy8106a.c tcagpio.c tcakp.c tda19988.c titemp.c tps65217pmic.c Log Message: Since we're using designated initialisers for compat data, we should use a completely empty initializer for the sentinel. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/ac100.c src/sys/dev/i2c/tda19988.c cvs rdiff -u -r1.8 -r1.9 src/sys/dev/i2c/adadc.c src/sys/dev/i2c/pcagpio.c cvs rdiff -u -r1.23 -r1.24 src/sys/dev/i2c/adm1021.c cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/adm1026.c \ src/sys/dev/i2c/max77620.c src/sys/dev/i2c/titemp.c cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/anxedp.c src/sys/dev/i2c/pca9685.c cvs rdiff -u -r1.20 -r1.21 src/sys/dev/i2c/as3722.c cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/asms.c src/sys/dev/i2c/cwfg.c cvs rdiff -u -r1.38 -r1.39 src/sys/dev/i2c/at24cxx.c cvs rdiff -u -r1.17 -r1.18 src/sys/dev/i2c/axp20x.c cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/axp22x.c src/sys/dev/i2c/dstemp.c \ src/sys/dev/i2c/fan53555.c src/sys/dev/i2c/pcf8574.c cvs rdiff -u -r1.31 -r1.32 src/sys/dev/i2c/axppmic.c cvs rdiff -u -r1.57 -r1.58 src/sys/dev/i2c/dbcool.c cvs rdiff -u -r1.36 -r1.37 src/sys/dev/i2c/ds1307.c cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/em3027.c src/sys/dev/i2c/ssdfb_i2c.c \ src/sys/dev/i2c/sy8106a.c src/sys/dev/i2c/tcagpio.c cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/es8316ac.c cvs rdiff -u -r1.10 -r1.11 src/sys/dev/i2c/fcu.c src/sys/dev/i2c/rkpmic.c cvs rdiff -u -r1.11 -r1.12 src/sys/dev/i2c/hytp14.c cvs rdiff -u -r1.13 -r1.14 src/sys/dev/i2c/ihidev.c src/sys/dev/i2c/pcf8563.c \ src/sys/dev/i2c/tcakp.c cvs rdiff -u -r1.37 -r1.38 src/sys/dev/i2c/lm75.c cvs rdiff -u -r1.12 -r1.13 src/sys/dev/i2c/lm87.c cvs rdiff -u -r1.29 -r1.30 src/sys/dev/i2c/m41st84.c cvs rdiff -u -r1.19 -r1.20 src/sys/dev/i2c/spdmem_i2c.c cvs rdiff -u -r1.16 -r1.17 src/sys/dev/i2c/tps65217pmic.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/dev/i2c/ac100.c diff -u src/sys/dev/i2c/ac100.c:1.5 src/sys/dev/i2c/ac100.c:1.6 --- src/sys/dev/i2c/ac100.c:1.5 Sun Jan 17 21:42:35 2021 +++ src/sys/dev/i2c/ac100.c Mon Jan 25 13:30:20 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: ac100.c,v 1.5 2021/01/17 21:42:35 thorpej Exp $ */ +/* $NetBSD: ac100.c,v 1.6 2021/01/25 13:30:20 thorpej Exp $ */ /*- * Copyright (c) 2014 Jared D. McNeill @@ -29,7 +29,7 @@ #include "opt_fdt.h" #include -__KERNEL_RCSID(0, "$NetBSD: ac100.c,v 1.5 2021/01/17 21:42:35 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ac100.c,v 1.6 2021/01/25 13:30:20 thorpej Exp $"); #include #include @@ -94,8 +94,7 @@ __KERNEL_RCSID(0, "$NetBSD: ac100.c,v 1. static const struct device_compatible_entry compat_data[] = { { .compat = "x-powers,ac100" }, - - { 0 } + { } }; struct ac100_softc { Index: src/sys/dev/i2c/tda19988.c diff -u src/sys/dev/i2c/tda19988.c:1.5 src/sys/dev/i2c/tda19988.c:1.6 --- src/sys/dev/i2c/tda19988.c:1.5 Sun Jan 17 21:42:35 2021 +++ src/sys/dev/i2c/tda19988.c Mon Jan 25 13:30:20 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tda19988.c,v 1.5 2021/01/17 21:42:35 thorpej Exp $ */ +/* $NetBSD: tda19988.c,v 1.6 2021/01/25 13:30:20 thorpej Exp $ */ /*- * Copyright (c) 2015 Oleksandr Tymoshenko @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tda19988.c,v 1.5 2021/01/17 21:42:35 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tda19988.c,v 1.6 2021/01/25 13:30:20 thorpej Exp $"); /* * NXP TDA19988 HDMI encoder @@ -245,8 +245,7 @@ enum { static const struct device_compatible_entry compat_data[] = { { .compat = "nxp,tda998x" }, - - { 0 } + { } }; struct tda19988_softc; Index: src/sys/dev/i2c/adadc.c diff -u src/sys/dev/i2c/adadc.c:1.8 src/sys/dev/i2c/adadc.c:1.9 --- src/sys/dev/i2c/adadc.c:1.8 Sun Jan 17 21:42:35 2021 +++ src/sys/dev/i2c/adadc.c Mon Jan 25 13:30:20 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: adadc.c,v 1.8 2021/01/17 21:42:35 thorpej Exp $ */ +/* $NetBSD: adadc.c,v 1.9 2021/01/25 13:30:20 thorpej Exp $ */ /*- * Copyright (c) 2018 Michael Lorenz @@ -34,7 +34,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: adadc.c,v 1.8 2021/01/17 21:42:35 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adadc.c,v 1.9 2021/01/25 13:30:20 thorpej Exp $"); #include #include @@ -95,8 +95,7 @@ CFATTACH_DECL_NEW(adadc, sizeof(struct a static const struct device_compatible_entry compat_data[] = { { .compat = "ad7417" }, - - { 0 } + { } }; /* calibaration table from Darwin via Linux */ Index: src/sys/dev/i2c/pcagpio.c diff -u
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Mon Jan 25 12:08:47 UTC 2021 Modified Files: src/sys/dev/i2c: motoi2c.c motoi2cvar.h Log Message: NXP Layerscape LX2160A has an almost compatible controller, with a few quirks: - IBCR bit 7 is "module disable" instead of "module enable". - Status bits in IBSR are W1C. Add quirk flags for both. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/motoi2c.c cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/motoi2cvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/motoi2c.c diff -u src/sys/dev/i2c/motoi2c.c:1.9 src/sys/dev/i2c/motoi2c.c:1.10 --- src/sys/dev/i2c/motoi2c.c:1.9 Sun Jan 24 18:01:13 2021 +++ src/sys/dev/i2c/motoi2c.c Mon Jan 25 12:08:47 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: motoi2c.c,v 1.9 2021/01/24 18:01:13 jmcneill Exp $ */ +/* $NetBSD: motoi2c.c,v 1.10 2021/01/25 12:08:47 jmcneill Exp $ */ /*- * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: motoi2c.c,v 1.9 2021/01/24 18:01:13 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: motoi2c.c,v 1.10 2021/01/25 12:08:47 jmcneill Exp $"); #if defined(__arm__) || defined(__aarch64__) #include "opt_fdt.h" @@ -109,11 +109,23 @@ motoi2c_attach_common(device_t self, str iba.iba_tag = >sc_i2c; iba.iba_child_devices = sc->sc_child_devices; - I2C_WRITE(I2CCR, 0); /* reset before changing anything */ + if ((sc->sc_flags & MOTOI2C_F_ENABLE_INV) != 0) { + sc->sc_enable_mask = 0; + sc->sc_disable_mask = CR_MEN; + } else { + sc->sc_enable_mask = CR_MEN; + sc->sc_disable_mask = 0; + } + + I2C_WRITE(I2CCR, sc->sc_disable_mask); /* reset before config */ I2C_WRITE(I2CDFSRR, i2c->i2c_dfsrr); /* sampling units */ I2C_WRITE(I2CFDR, i2c->i2c_fdr); /* divider 3072 (0x31) */ I2C_WRITE(I2CADR, i2c->i2c_adr); /* our slave address is 0x7f */ - I2C_WRITE(I2CSR, 0); /* clear status flags */ + if ((sc->sc_flags & MOTOI2C_F_STATUS_W1C) != 0) { + I2C_WRITE(I2CSR, I2C_READ(I2CSR)); /* clear status flags */ + } else { + I2C_WRITE(I2CSR, 0); /* clear status flags */ + } #ifdef FDT if (sc->sc_phandle != 0) { @@ -130,7 +142,7 @@ motoi2c_acquire_bus(void *v, int flags) { struct motoi2c_softc * const sc = v; - I2C_WRITE(I2CCR, CR_MEN); /* enable the I2C module */ + I2C_WRITE(I2CCR, sc->sc_enable_mask); /* enable the I2C module */ return 0; } @@ -140,7 +152,7 @@ motoi2c_release_bus(void *v, int flags) { struct motoi2c_softc * const sc = v; - I2C_WRITE(I2CCR, 0); /* reset before changing anything */ + I2C_WRITE(I2CCR, sc->sc_disable_mask); /* disable the I2C module */ } static int @@ -161,6 +173,16 @@ motoi2c_stop_wait(struct motoi2c_softc * return error; } +static void +motoi2c_clear_status(struct motoi2c_softc *sc, uint8_t sr) +{ + if ((sc->sc_flags & MOTOI2C_F_STATUS_W1C) != 0) { + I2C_WRITE(I2CSR, sr); + } else { + I2C_WRITE(I2CSR, 0); + } +} + /* busy waiting for byte data transfer completion */ static int motoi2c_busy_wait(struct motoi2c_softc *sc, uint8_t cr) @@ -186,7 +208,7 @@ motoi2c_busy_wait(struct motoi2c_softc * __func__, sr, 1000 - timo)); error = EIO; } - I2C_WRITE(I2CSR, 0); + motoi2c_clear_status(sc, sr); return error; } @@ -228,13 +250,13 @@ motoi2c_exec(void *v, i2c_op_t op, i2c_a } /* reset interrupt and arbitration-lost flags (all others are RO) */ - I2C_WRITE(I2CSR, 0); + motoi2c_clear_status(sc, sr); sr = I2C_READ(I2CSR); /* * Generate start condition */ - cr = CR_MEN | CR_MTX | CR_MSTA; + cr = sc->sc_enable_mask | CR_MTX | CR_MSTA; I2C_WRITE(I2CCR, cr); DPRINTF(("%s: started: sr=%#x cr=%#x/%#x\n", @@ -244,9 +266,9 @@ motoi2c_exec(void *v, i2c_op_t op, i2c_a if (sr & SR_MAL) { DPRINTF(("%s: lost bus: sr=%#x cr=%#x/%#x\n", __func__, I2C_READ(I2CSR), cr, I2C_READ(I2CCR))); - I2C_WRITE(I2CCR, 0); + I2C_WRITE(I2CCR, sc->sc_disable_mask); DELAY(10); - I2C_WRITE(I2CCR, CR_MEN | CR_MTX | CR_MSTA); + I2C_WRITE(I2CCR, sc->sc_enable_mask | CR_MTX | CR_MSTA); DELAY(10); sr = I2C_READ(I2CSR); if (sr & SR_MAL) { @@ -329,14 +351,14 @@ motoi2c_exec(void *v, i2c_op_t op, i2c_a cr |= CR_TXAK; I2C_WRITE(I2CCR, cr); } else if (i == datalen - 1 && I2C_OP_STOP_P(op)) { -cr = CR_MEN | CR_TXAK; +cr = sc->sc_enable_mask | CR_TXAK; I2C_WRITE(I2CCR, cr); } *dataptr++ = I2C_READ(I2CDR); } if (datalen == 0) { if (I2C_OP_STOP_P(op)) { -cr = CR_MEN | CR_TXAK; +cr = sc->sc_enable_mask | CR_TXAK; I2C_WRITE(I2CCR, cr); } (void)I2C_READ(I2CDR); /* dummy read */ @@ -366,7 +388,7 @@ motoi2c_exec(void *v, i2c_op_t op, i2c_a * send a STOP. */ if (error || (cr & CR_TXAK) || ((cr & CR_MSTA) && I2C_OP_STOP_P(op))) { - cr = CR_MEN; + cr = sc->sc_enable_mask; I2C_WRITE(I2CCR, cr); motoi2c_stop_wait(sc); DPRINTF(("%s: stopping:
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun Jan 24 19:38:49 UTC 2021 Modified Files: src/sys/dev/i2c: pcai2cmux.c Log Message: remove part of previous that was committed by mistake To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/pcai2cmux.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/dev/i2c/pcai2cmux.c diff -u src/sys/dev/i2c/pcai2cmux.c:1.4 src/sys/dev/i2c/pcai2cmux.c:1.5 --- src/sys/dev/i2c/pcai2cmux.c:1.4 Sun Jan 24 19:37:45 2021 +++ src/sys/dev/i2c/pcai2cmux.c Sun Jan 24 19:38:49 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pcai2cmux.c,v 1.4 2021/01/24 19:37:45 jmcneill Exp $ */ +/* $NetBSD: pcai2cmux.c,v 1.5 2021/01/24 19:38:49 jmcneill Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pcai2cmux.c,v 1.4 2021/01/24 19:37:45 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcai2cmux.c,v 1.5 2021/01/24 19:38:49 jmcneill Exp $"); /* * Driver for NXP PCA954x / PCA984x I2C switches and multiplexers. @@ -126,10 +126,6 @@ static const struct device_compatible_en { .compat = "nxp,pca9547", .data = _type }, - /* PCA9547 - 8 channel i2c mux (NXP Layerscape ACPI) */ - { .compat = "NXP0002", - .data = _type }, - /* PCA9548 - 8 channel i2c switch */ { .compat = "nxp,pca9548", .data = _type },
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun Jan 24 19:37:45 UTC 2021 Modified Files: src/sys/dev/i2c: pcai2cmux.c Log Message: trailing whitespace To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/pcai2cmux.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/dev/i2c/pcai2cmux.c diff -u src/sys/dev/i2c/pcai2cmux.c:1.3 src/sys/dev/i2c/pcai2cmux.c:1.4 --- src/sys/dev/i2c/pcai2cmux.c:1.3 Mon Jan 18 15:28:21 2021 +++ src/sys/dev/i2c/pcai2cmux.c Sun Jan 24 19:37:45 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pcai2cmux.c,v 1.3 2021/01/18 15:28:21 thorpej Exp $ */ +/* $NetBSD: pcai2cmux.c,v 1.4 2021/01/24 19:37:45 jmcneill Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pcai2cmux.c,v 1.3 2021/01/18 15:28:21 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcai2cmux.c,v 1.4 2021/01/24 19:37:45 jmcneill Exp $"); /* * Driver for NXP PCA954x / PCA984x I2C switches and multiplexers. @@ -126,6 +126,10 @@ static const struct device_compatible_en { .compat = "nxp,pca9547", .data = _type }, + /* PCA9547 - 8 channel i2c mux (NXP Layerscape ACPI) */ + { .compat = "NXP0002", + .data = _type }, + /* PCA9548 - 8 channel i2c switch */ { .compat = "nxp,pca9548", .data = _type }, @@ -291,7 +295,7 @@ pcaiicmux_match(device_t parent, cfdata_ if (iic_use_direct_match(ia, cf, compat_data, _result)) { return match_result; } - + /* This device is direct-config only. */ return 0;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun Jan 24 19:35:45 UTC 2021 Modified Files: src/sys/dev/i2c: i2cmuxvar.h Log Message: trailing whitespace To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/i2cmuxvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/i2cmuxvar.h diff -u src/sys/dev/i2c/i2cmuxvar.h:1.1 src/sys/dev/i2c/i2cmuxvar.h:1.2 --- src/sys/dev/i2c/i2cmuxvar.h:1.1 Mon Dec 28 20:29:57 2020 +++ src/sys/dev/i2c/i2cmuxvar.h Sun Jan 24 19:35:45 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: i2cmuxvar.h,v 1.1 2020/12/28 20:29:57 thorpej Exp $ */ +/* $NetBSD: i2cmuxvar.h,v 1.2 2021/01/24 19:35:45 jmcneill Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -15,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright *notice, this list of conditions and the following disclaimer in the *documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -26,15 +26,15 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef _DEV_I2C_I2CMUXVAR_H_ #define _DEV_I2C_I2CMUXVAR_H_ #include -struct iicmux_softc; +struct iicmux_softc; struct iicmux_bus; struct iicmux_config {
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun Jan 24 19:35:21 UTC 2021 Modified Files: src/sys/dev/i2c: i2cmux.c Log Message: trailing whitespace To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/i2cmux.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/dev/i2c/i2cmux.c diff -u src/sys/dev/i2c/i2cmux.c:1.1 src/sys/dev/i2c/i2cmux.c:1.2 --- src/sys/dev/i2c/i2cmux.c:1.1 Mon Dec 28 20:29:57 2020 +++ src/sys/dev/i2c/i2cmux.c Sun Jan 24 19:35:21 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: i2cmux.c,v 1.1 2020/12/28 20:29:57 thorpej Exp $ */ +/* $NetBSD: i2cmux.c,v 1.2 2021/01/24 19:35:21 jmcneill Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -15,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright *notice, this list of conditions and the following disclaimer in the *documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -26,44 +26,44 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ + * POSSIBILITY OF SUCH DAMAGE. + */ #include -__KERNEL_RCSID(0, "$NetBSD: i2cmux.c,v 1.1 2020/12/28 20:29:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2cmux.c,v 1.2 2021/01/24 19:35:21 jmcneill Exp $"); #include #include #include -#include +#include #include #include #include -/* - * i2c mux - * +/* + * i2c mux + * * This works by interposing a set of virtual controllers behind the real * i2c controller. We provide our own acquire and release functions that * perform the following tasks: - * + * * acquire -> acquire parent controller, program mux - * + * * release -> idle mux, release parent controller - * + * * All of the actual I/O operations are transparently passed through. - * - * N.B. the locking order; the generic I2C layer has already acquired + * + * N.B. the locking order; the generic I2C layer has already acquired * our virtual controller's mutex before calling our acquire function, - * and we will then acquire the real controller's mutex when we acquire + * and we will then acquire the real controller's mutex when we acquire * the bus, so the order is: - * + * * mux virtual controller -> parent controller * * These are common routines used by various i2c mux controller * implementations (gpio, pin mux, i2c device, etc.). - */ + */ /*/ @@ -141,7 +141,7 @@ iicmux_count_children(struct iicmux_soft /* XXX iicbus_print() should be able to do this. */ static int iicmux_print(void * const aux, const char * const pnp) -{ +{ i2c_tag_t const tag = aux; struct iicmux_bus * const bus = tag->ic_cookie; int rv; @@ -152,7 +152,7 @@ iicmux_print(void * const aux, const cha return rv; } -static void +static void iicmux_attach_bus(struct iicmux_softc * const sc, int const phandle, int const busidx) {
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun Jan 24 18:01:14 UTC 2021 Modified Files: src/sys/dev/i2c: motoi2c.c motoi2cvar.h Log Message: Support non-FDT attachment. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/sys/dev/i2c/motoi2c.c cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/motoi2cvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/motoi2c.c diff -u src/sys/dev/i2c/motoi2c.c:1.8 src/sys/dev/i2c/motoi2c.c:1.9 --- src/sys/dev/i2c/motoi2c.c:1.8 Wed Dec 23 16:02:11 2020 +++ src/sys/dev/i2c/motoi2c.c Sun Jan 24 18:01:13 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: motoi2c.c,v 1.8 2020/12/23 16:02:11 thorpej Exp $ */ +/* $NetBSD: motoi2c.c,v 1.9 2021/01/24 18:01:13 jmcneill Exp $ */ /*- * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: motoi2c.c,v 1.8 2020/12/23 16:02:11 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: motoi2c.c,v 1.9 2021/01/24 18:01:13 jmcneill Exp $"); #if defined(__arm__) || defined(__aarch64__) #include "opt_fdt.h" @@ -107,6 +107,7 @@ motoi2c_attach_common(device_t self, str sc->sc_iowr = motoi2c_iowr1; memset(, 0, sizeof(iba)); iba.iba_tag = >sc_i2c; + iba.iba_child_devices = sc->sc_child_devices; I2C_WRITE(I2CCR, 0); /* reset before changing anything */ I2C_WRITE(I2CDFSRR, i2c->i2c_dfsrr); /* sampling units */ @@ -115,13 +116,13 @@ motoi2c_attach_common(device_t self, str I2C_WRITE(I2CSR, 0); /* clear status flags */ #ifdef FDT - KASSERT(sc->sc_phandle != 0); - fdtbus_register_i2c_controller(>sc_i2c, sc->sc_phandle); - - fdtbus_attach_i2cbus(self, sc->sc_phandle, >sc_i2c, iicbus_print); -#else - config_found_ia(self, "i2cbus", , iicbus_print); + if (sc->sc_phandle != 0) { + fdtbus_register_i2c_controller(>sc_i2c, sc->sc_phandle); + fdtbus_attach_i2cbus(self, sc->sc_phandle, >sc_i2c, + iicbus_print); + } else #endif + config_found_ia(self, "i2cbus", , iicbus_print); } static int Index: src/sys/dev/i2c/motoi2cvar.h diff -u src/sys/dev/i2c/motoi2cvar.h:1.6 src/sys/dev/i2c/motoi2cvar.h:1.7 --- src/sys/dev/i2c/motoi2cvar.h:1.6 Sun Dec 22 23:23:32 2019 +++ src/sys/dev/i2c/motoi2cvar.h Sun Jan 24 18:01:13 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: motoi2cvar.h,v 1.6 2019/12/22 23:23:32 thorpej Exp $ */ +/* $NetBSD: motoi2cvar.h,v 1.7 2021/01/24 18:01:13 jmcneill Exp $ */ /*- * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc. @@ -51,6 +51,7 @@ struct motoi2c_softc { motoi2c_iord_t sc_iord; motoi2c_iowr_t sc_iowr; int sc_phandle; + prop_array_t sc_child_devices; }; #define MOTOI2C_ADR_DEFAULT (0x7e << 1)
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: rin Date: Sun Jan 24 05:30:05 UTC 2021 Modified Files: src/sys/dev/i2c: adm1021.c Log Message: Use temperature sensors as rnd(9) sources. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/sys/dev/i2c/adm1021.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/dev/i2c/adm1021.c diff -u src/sys/dev/i2c/adm1021.c:1.22 src/sys/dev/i2c/adm1021.c:1.23 --- src/sys/dev/i2c/adm1021.c:1.22 Sun Jan 17 21:42:35 2021 +++ src/sys/dev/i2c/adm1021.c Sun Jan 24 05:30:05 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: adm1021.c,v 1.22 2021/01/17 21:42:35 thorpej Exp $ */ +/* $NetBSD: adm1021.c,v 1.23 2021/01/24 05:30:05 rin Exp $ */ /* $OpenBSD: adm1021.c,v 1.27 2007/06/24 05:34:35 dlg Exp $ */ /* @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.22 2021/01/17 21:42:35 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.23 2021/01/24 05:30:05 rin Exp $"); #include #include @@ -377,8 +377,10 @@ admtemp_attach(device_t parent, device_t sc->sc_sensor[ADMTEMP_INT].units = ENVSYS_STEMP; sc->sc_sensor[ADMTEMP_EXT].state = ENVSYS_SINVALID; sc->sc_sensor[ADMTEMP_EXT].units = ENVSYS_STEMP; - sc->sc_sensor[ADMTEMP_INT].flags = ENVSYS_FMONLIMITS; - sc->sc_sensor[ADMTEMP_EXT].flags = ENVSYS_FMONLIMITS; + sc->sc_sensor[ADMTEMP_INT].flags = + ENVSYS_FMONLIMITS | ENVSYS_FHAS_ENTROPY; + sc->sc_sensor[ADMTEMP_EXT].flags = + ENVSYS_FMONLIMITS | ENVSYS_FHAS_ENTROPY; if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, "s00", )) { strncpy(iname, desc, 64);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sun Jan 17 21:47:50 UTC 2021 Modified Files: src/sys/dev/i2c: ihidev.c tsllux.c Log Message: Use designated initializers and a consistent termination style in compat_data[]. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/sys/dev/i2c/ihidev.c cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/tsllux.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/dev/i2c/ihidev.c diff -u src/sys/dev/i2c/ihidev.c:1.12 src/sys/dev/i2c/ihidev.c:1.13 --- src/sys/dev/i2c/ihidev.c:1.12 Thu Jan 9 04:04:01 2020 +++ src/sys/dev/i2c/ihidev.c Sun Jan 17 21:47:50 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.12 2020/01/09 04:04:01 thorpej Exp $ */ +/* $NetBSD: ihidev.c,v 1.13 2021/01/17 21:47:50 thorpej Exp $ */ /* $OpenBSD ihidev.c,v 1.13 2017/04/08 02:57:23 deraadt Exp $ */ /*- @@ -54,7 +54,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.12 2020/01/09 04:04:01 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.13 2021/01/17 21:47:50 thorpej Exp $"); #include #include @@ -126,8 +126,9 @@ static int ihidev_print(void *, const ch static int ihidev_submatch(device_t, cfdata_t, const int *, void *); static const struct device_compatible_entry compat_data[] = { - { "hid-over-i2c", 0 }, - { NULL,0 } + { .compat = "hid-over-i2c" }, + + { 0 } }; static int Index: src/sys/dev/i2c/tsllux.c diff -u src/sys/dev/i2c/tsllux.c:1.1 src/sys/dev/i2c/tsllux.c:1.2 --- src/sys/dev/i2c/tsllux.c:1.1 Mon Jan 4 22:09:35 2021 +++ src/sys/dev/i2c/tsllux.c Sun Jan 17 21:47:50 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tsllux.c,v 1.1 2021/01/04 22:09:35 thorpej Exp $ */ +/* $NetBSD: tsllux.c,v 1.2 2021/01/17 21:47:50 thorpej Exp $ */ /*- * Copyright (c) 2018 Jason R. Thorpe @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tsllux.c,v 1.1 2021/01/04 22:09:35 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tsllux.c,v 1.2 2021/01/17 21:47:50 thorpej Exp $"); #include #include @@ -78,9 +78,10 @@ CFATTACH_DECL_NEW(tsllux, sizeof(struct tsllux_match, tsllux_attach, NULL, NULL); static const struct device_compatible_entry tsllux_compat_data[] = { - { "amstaos,tsl2560", 0 }, - { "amstaos,tsl2561", 0 }, - { NULL,0 } + { .compat = "amstaos,tsl2560" }, + { .compat = "amstaos,tsl2561" }, + + { 0 } }; static int tsllux_read1(struct tsllux_softc *, uint8_t, uint8_t *);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Jan 4 22:09:35 UTC 2021 Modified Files: src/sys/dev/i2c: files.i2c Added Files: src/sys/dev/i2c: tsllux.c Removed Files: src/sys/dev/i2c: tsl256x.c Log Message: Rename tsl256x.c -> tsllux.c. No other changes are made by this commit. To generate a diff of this commit: cvs rdiff -u -r1.114 -r1.115 src/sys/dev/i2c/files.i2c cvs rdiff -u -r1.9 -r0 src/sys/dev/i2c/tsl256x.c cvs rdiff -u -r0 -r1.1 src/sys/dev/i2c/tsllux.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/dev/i2c/files.i2c diff -u src/sys/dev/i2c/files.i2c:1.114 src/sys/dev/i2c/files.i2c:1.115 --- src/sys/dev/i2c/files.i2c:1.114 Tue Dec 29 01:47:51 2020 +++ src/sys/dev/i2c/files.i2c Mon Jan 4 22:09:35 2021 @@ -1,4 +1,4 @@ -# $NetBSD: files.i2c,v 1.114 2020/12/29 01:47:51 thorpej Exp $ +# $NetBSD: files.i2c,v 1.115 2021/01/04 22:09:35 thorpej Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } @@ -342,7 +342,7 @@ file dev/i2c/imt.cimt # Taos TSL256x ambient light sensor device tsllux: sysmon_envsys attach tsllux at iic -file dev/i2c/tsl256x.c tsllux +file dev/i2c/tsllux.c tsllux # Philips/NXP TEA5767 device tea5767radio : radiodev Added files: Index: src/sys/dev/i2c/tsllux.c diff -u /dev/null src/sys/dev/i2c/tsllux.c:1.1 --- /dev/null Mon Jan 4 22:09:36 2021 +++ src/sys/dev/i2c/tsllux.c Mon Jan 4 22:09:35 2021 @@ -0,0 +1,1049 @@ +/* $NetBSD: tsllux.c,v 1.1 2021/01/04 22:09:35 thorpej Exp $ */ + +/*- + * Copyright (c) 2018 Jason R. Thorpe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: tsllux.c,v 1.1 2021/01/04 22:09:35 thorpej Exp $"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +struct tsllux_softc { + device_t sc_dev; + i2c_tag_t sc_i2c; + i2c_addr_t sc_addr; + + uint32_t sc_poweron; + + /* + * Locking order is: + * tsllux mutex -> i2c bus + */ + kmutex_t sc_lock; + + uint8_t sc_itime; + uint8_t sc_gain; + bool sc_cs_package; + bool sc_auto_gain; + + struct sysmon_envsys *sc_sme; + envsys_data_t sc_sensor; + + struct sysctllog *sc_sysctllog; +}; + +#define TSLLUX_F_CS_PACKAGE 0x01 + +static int tsllux_match(device_t, cfdata_t, void *); +static void tsllux_attach(device_t, device_t, void *); + +CFATTACH_DECL_NEW(tsllux, sizeof(struct tsllux_softc), +tsllux_match, tsllux_attach, NULL, NULL); + +static const struct device_compatible_entry tsllux_compat_data[] = { + { "amstaos,tsl2560", 0 }, + { "amstaos,tsl2561", 0 }, + { NULL,0 } +}; + +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); +#if 0 +static int tsllux_write2(struct tsllux_softc *, uint8_t, uint16_t); +#endif + +static void tsllux_sysctl_attach(struct tsllux_softc *); + +static int tsllux_poweron(struct tsllux_softc *); +static int tsllux_poweroff(struct tsllux_softc *); + +static int tsllux_set_integration_time(struct tsllux_softc *, uint8_t); +static int tsllux_set_gain(struct tsllux_softc *, uint8_t); +static int tsllux_set_autogain(struct tsllux_softc *, bool); + +static int tsllux_get_lux(struct tsllux_softc *, uint32_t *, + uint16_t *, uint16_t *); + +static void tsllux_sensors_refresh(struct sysmon_envsys *, envsys_data_t *); + +static int +tsllux_match(device_t parent, cfdata_t match, void *aux) +{ + struct i2c_attach_args *ia = aux; + uint8_t
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Jan 4 21:59:49 UTC 2021 Modified Files: src/sys/dev/i2c: tsl256x.c tsl256xreg.h Log Message: Tweak register bit names, in preparation for supporting younger siblings of this chip. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/sys/dev/i2c/tsl256x.c cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/tsl256xreg.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/tsl256x.c diff -u src/sys/dev/i2c/tsl256x.c:1.8 src/sys/dev/i2c/tsl256x.c:1.9 --- src/sys/dev/i2c/tsl256x.c:1.8 Wed Jan 15 05:56:57 2020 +++ src/sys/dev/i2c/tsl256x.c Mon Jan 4 21:59:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tsl256x.c,v 1.8 2020/01/15 05:56:57 thorpej Exp $ */ +/* $NetBSD: tsl256x.c,v 1.9 2021/01/04 21:59:48 thorpej Exp $ */ /*- * Copyright (c) 2018 Jason R. Thorpe @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tsl256x.c,v 1.8 2020/01/15 05:56:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tsl256x.c,v 1.9 2021/01/04 21:59:48 thorpej Exp $"); #include #include @@ -127,7 +127,7 @@ tsllux_match(device_t parent, cfdata_t m if (iic_acquire_bus(ia->ia_tag, 0) != 0) return (0); error = iic_smbus_read_byte(ia->ia_tag, ia->ia_addr, - TSL256x_REG_ID | COMMAND_CMD, _reg, 0); + TSL256x_REG_ID | COMMAND6x_CMD, _reg, 0); iic_release_bus(ia->ia_tag, 0); if (error) @@ -165,15 +165,15 @@ tsllux_attach(device_t parent, device_t have_i2c = true; /* Power on the device and clear any pending interrupts. */ - if (tsllux_write1(sc, TSL256x_REG_CONTROL | COMMAND_CLEAR, - CONTROL_POWER_ON)) { + if (tsllux_write1(sc, TSL256x_REG_CONTROL | COMMAND6x_CLEAR, + CONTROL6x_POWER_ON)) { aprint_error_dev(self, ": unable to power on device\n"); goto out; } sc->sc_poweron = 1; /* Make sure interrupts are disabled. */ - if (tsllux_write1(sc, TSL256x_REG_INTERRUPT | COMMAND_CLEAR, 0)) { + if (tsllux_write1(sc, TSL256x_REG_INTERRUPT | COMMAND6x_CLEAR, 0)) { aprint_error_dev(self, ": unable to disable interrupts\n"); goto out; } @@ -184,8 +184,8 @@ tsllux_attach(device_t parent, device_t /* Inititalize timing to reasonable defaults. */ sc->sc_auto_gain = true; - sc->sc_gain = TIMING_GAIN_16X; - if (tsllux_set_integration_time(sc, TIMING_INTEG_101ms)) { + sc->sc_gain = TIMING6x_GAIN_16X; + if (tsllux_set_integration_time(sc, TIMING6x_INTEG_101ms)) { aprint_error_dev(self, ": unable to set integration time\n"); goto out; } @@ -289,11 +289,11 @@ tsllux_sysctl_gain(SYSCTLFN_ARGS) mutex_enter(>sc_lock); switch (sc->sc_gain) { - case TIMING_GAIN_1X: + case TIMING6x_GAIN_1X: val = 1; break; - case TIMING_GAIN_16X: + case TIMING6x_GAIN_16X: val = 16; break; @@ -310,11 +310,11 @@ tsllux_sysctl_gain(SYSCTLFN_ARGS) switch (val) { case 1: - new_gain = TIMING_GAIN_1X; + new_gain = TIMING6x_GAIN_1X; break; case 16: - new_gain = TIMING_GAIN_16X; + new_gain = TIMING6x_GAIN_16X; break; default: @@ -349,15 +349,15 @@ tsllux_sysctl_itime(SYSCTLFN_ARGS) mutex_enter(>sc_lock); switch (sc->sc_itime) { - case TIMING_INTEG_13_7ms: + case TIMING6x_INTEG_13_7ms: val = 13; break; - case TIMING_INTEG_101ms: + case TIMING6x_INTEG_101ms: val = 101; break; - case TIMING_INTEG_402ms: + case TIMING6x_INTEG_402ms: default: val = 402; break; @@ -372,15 +372,15 @@ tsllux_sysctl_itime(SYSCTLFN_ARGS) switch (val) { case 13: case 14: - new_itime = TIMING_INTEG_13_7ms; + new_itime = TIMING6x_INTEG_13_7ms; break; case 101: - new_itime = TIMING_INTEG_101ms; + new_itime = TIMING6x_INTEG_101ms; break; case 402: - new_itime = TIMING_INTEG_402ms; + new_itime = TIMING6x_INTEG_402ms; break; default: @@ -478,26 +478,26 @@ tsllux_sensors_refresh(struct sysmon_env /* * Allow pending interrupts to be cleared as part of another operation. */ -#define REGMASK (COMMAND_REGMASK | COMMAND_CLEAR) +#define REGMASK6x (COMMAND6x_REGMASK | COMMAND6x_CLEAR) static int tsllux_read1(struct tsllux_softc *sc, uint8_t reg, uint8_t *valp) { - reg = (reg & REGMASK) | COMMAND_CMD; + reg = (reg & REGMASK6x) | COMMAND6x_CMD; return (iic_smbus_read_byte(sc->sc_i2c, sc->sc_addr, reg, valp, 0)); } static int tsllux_read2(struct tsllux_softc *sc, uint8_t reg, uint16_t *valp) { - reg = (reg & REGMASK) | COMMAND_CMD | COMMAND_WORD; + reg = (reg & REGMASK6x) | COMMAND6x_CMD | COMMAND6x_WORD; return (iic_smbus_read_word(sc->sc_i2c, sc->sc_addr, reg, valp, 0)); } static int tsllux_write1(struct tsllux_softc *sc, uint8_t reg, uint8_t val) { - reg = (reg & REGMASK) | COMMAND_CMD; + reg = (reg & REGMASK6x) | COMMAND6x_CMD; return (iic_smbus_write_byte(sc->sc_i2c, sc->sc_addr, reg, val, 0)); } @@ -505,7 +505,7 @@ tsllux_write1(struct tsllux_softc *sc, u static int tsllux_write2(struct tsllux_softc *sc, uint8_t reg, uint16_t
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Tue Dec 29 01:47:52 UTC 2020 Modified Files: src/sys/dev/i2c: files.i2c Added Files: src/sys/dev/i2c: pcai2cmux.c Log Message: Add a driver for NXP PCA954x / PCA984x I2C switch / mux controllers. To generate a diff of this commit: cvs rdiff -u -r1.113 -r1.114 src/sys/dev/i2c/files.i2c cvs rdiff -u -r0 -r1.1 src/sys/dev/i2c/pcai2cmux.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/dev/i2c/files.i2c diff -u src/sys/dev/i2c/files.i2c:1.113 src/sys/dev/i2c/files.i2c:1.114 --- src/sys/dev/i2c/files.i2c:1.113 Mon Dec 28 20:29:57 2020 +++ src/sys/dev/i2c/files.i2c Tue Dec 29 01:47:51 2020 @@ -1,4 +1,4 @@ -# $NetBSD: files.i2c,v 1.113 2020/12/28 20:29:57 thorpej Exp $ +# $NetBSD: files.i2c,v 1.114 2020/12/29 01:47:51 thorpej Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } @@ -370,6 +370,11 @@ device anxedp: edid, videomode, drmkms, attach anxedp at iic file dev/i2c/anxedp.c anxedp +# NXP PCA954x / PCA984x I2C switch / mux controllers +device pcaiicmux: i2cbus, i2cmux +attach pcaiicmux at iic +file dev/i2c/pcai2cmux.c pcaiicmux + # NXP PCA9685 16-channel, 12-bit PWM Fm+ LED controller device pcapwm: pwm attach pcapwm at iic Added files: Index: src/sys/dev/i2c/pcai2cmux.c diff -u /dev/null src/sys/dev/i2c/pcai2cmux.c:1.1 --- /dev/null Tue Dec 29 01:47:52 2020 +++ src/sys/dev/i2c/pcai2cmux.c Tue Dec 29 01:47:51 2020 @@ -0,0 +1,354 @@ +/* $NetBSD: pcai2cmux.c,v 1.1 2020/12/29 01:47:51 thorpej Exp $ */ + +/*- + * Copyright (c) 2020 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: pcai2cmux.c,v 1.1 2020/12/29 01:47:51 thorpej Exp $"); + +/* + * Driver for NXP PCA954x / PCA984x I2C switches and multiplexers. + * + * There are two flavors of this device: + * + * - Multiplexers, which connect the upstream bus to one downstream bus + * at a time. + * + * - Switches, which can connect the upstream bus to one or more downstream + * busses at a time (which is useful when using an all-call address for + * a large array of PCA9685 LED controllers, for example). + * + * Alas, the device tree bindings don't have anything specifically for + * switches, so we treat the switch variants as basic multiplexers, + * only enabling one downstream bus at a time. + * + * Note that some versions of these chips also have interrupt mux + * capability. XXX We do not support this yet. + */ + +#include +#include +#include + +#include +#include + +/* There are a maximum of 8 busses supported. */ +#define PCAIICMUX_MAX_BUSSES 8 + +struct pcaiicmux_type { + unsigned int nchannels; /* # of downstream channels */ + uint8_t enable_bit; /* if 0, chip is switch type */ +}; + +static const struct pcaiicmux_type mux2_type = { + .nchannels = 2, + .enable_bit = __BIT(2), +}; + +static const struct pcaiicmux_type switch2_type = { + .nchannels = 2, + .enable_bit = 0, +}; + +static const struct pcaiicmux_type mux4_type = { + .nchannels = 4, + .enable_bit = __BIT(2), +}; + +static const struct pcaiicmux_type switch4_type = { + .nchannels = 4, + .enable_bit = 0, +}; + +static const struct pcaiicmux_type mux8_type = { + .nchannels = 8, + .enable_bit = __BIT(3), +}; + +static const struct pcaiicmux_type switch8_type = { + .nchannels = 8, + .enable_bit = 0, +}; + +static const struct device_compatible_entry compat_data[] = { + /* PCA9540 - 2 channel i2c mux */ + { .compat = "nxp,pca9540",
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Tue Dec 29 00:26:51 UTC 2020 Modified Files: src/sys/dev/i2c: i2cvar.h Log Message: - Use __BIT() macro to define I2C_F_* bits. - Define an I2C_F_SPEED bitfield that can be used to specify an I2C bus speed: -> Standard Mode (100Kb/s) -> Fast Mode (400Kb/s) -> Fast Mode Plus (1Mb/s) -> High Speed (3.4Mb/s) The speed values are treated as advisory; if a controller does not support the requested speed mode, fallback to a lower one is allowed. (Currently, all controllers simply use Standard Mode.) To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/sys/dev/i2c/i2cvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/i2cvar.h diff -u src/sys/dev/i2c/i2cvar.h:1.20 src/sys/dev/i2c/i2cvar.h:1.21 --- src/sys/dev/i2c/i2cvar.h:1.20 Tue Jul 7 16:14:23 2020 +++ src/sys/dev/i2c/i2cvar.h Tue Dec 29 00:26:51 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: i2cvar.h,v 1.20 2020/07/07 16:14:23 thorpej Exp $ */ +/* $NetBSD: i2cvar.h,v 1.21 2020/12/29 00:26:51 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -44,12 +44,18 @@ #include /* Flags passed to i2c routines. */ -#define I2C_F_WRITE 0x00 /* new transfer is a write */ -#define I2C_F_READ 0x01 /* new transfer is a read */ -#define I2C_F_LAST 0x02 /* last byte of read */ -#define I2C_F_STOP 0x04 /* send stop after byte */ -#define I2C_F_POLL 0x08 /* poll, don't sleep */ -#define I2C_F_PEC 0x10 /* smbus packet error checking */ +#define I2C_F_WRITE 0 /* new transfer is a write */ +#define I2C_F_READ __BIT(0) /* new transfer is a read */ +#define I2C_F_LAST __BIT(1) /* last byte of read */ +#define I2C_F_STOP __BIT(2) /* send stop after byte */ +#define I2C_F_POLL __BIT(3) /* poll, don't sleep */ +#define I2C_F_PEC __BIT(4) /* smbus packet error checking */ +#define I2C_F_SPEED __BITS(28,31) /* I2C transfer speed selector */ + +#define I2C_SPEED_SM 0 /* standard mode (100Kb/s) */ +#define I2C_SPEED_FM 1 /* fast mode (400Kb/s) */ +#define I2C_SPEED_FMPLUS 2 /* fast mode+ (1Mb/s) */ +#define I2C_SPEED_HS 3 /* high speed (3.4Mb/s) */ /* i2c bus instance properties */ #define I2C_PROP_INDIRECT_PROBE_STRATEGY \
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: uwe Date: Wed Dec 23 17:57:00 UTC 2020 Modified Files: src/sys/dev/i2c: em3027.c Log Message: G/c trailing whitespace. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/em3027.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/dev/i2c/em3027.c diff -u src/sys/dev/i2c/em3027.c:1.4 src/sys/dev/i2c/em3027.c:1.5 --- src/sys/dev/i2c/em3027.c:1.4 Wed Dec 23 17:10:37 2020 +++ src/sys/dev/i2c/em3027.c Wed Dec 23 17:57:00 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: em3027.c,v 1.4 2020/12/23 17:10:37 thorpej Exp $ */ +/* $NetBSD: em3027.c,v 1.5 2020/12/23 17:57:00 uwe Exp $ */ /* * Copyright (c) 2018 Valery Ushakov * All rights reserved. @@ -28,7 +28,7 @@ * EM Microelectronic EM3027 RTC */ #include -__KERNEL_RCSID(0, "$NetBSD: em3027.c,v 1.4 2020/12/23 17:10:37 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: em3027.c,v 1.5 2020/12/23 17:57:00 uwe Exp $"); #include #include @@ -305,7 +305,7 @@ em3027rtc_envsys_attach(struct em3027rtc "unable to attach sensor (error %d)\n", error); goto out; } - + error = sysmon_envsys_register(sc->sc_sme); if (error) { aprint_error_dev(sc->sc_dev, @@ -360,7 +360,7 @@ static int em3027rtc_read_byte(struct em3027rtc_softc *sc, uint8_t reg, uint8_t *valp) { - return em3027rtc_read(sc, reg, valp, 1); + return em3027rtc_read(sc, reg, valp, 1); }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Wed Dec 23 17:10:37 UTC 2020 Modified Files: src/sys/dev/i2c: em3027.c Log Message: Add direct-config support. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/em3027.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/dev/i2c/em3027.c diff -u src/sys/dev/i2c/em3027.c:1.3 src/sys/dev/i2c/em3027.c:1.4 --- src/sys/dev/i2c/em3027.c:1.3 Sat Jul 27 16:02:27 2019 +++ src/sys/dev/i2c/em3027.c Wed Dec 23 17:10:37 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: em3027.c,v 1.3 2019/07/27 16:02:27 thorpej Exp $ */ +/* $NetBSD: em3027.c,v 1.4 2020/12/23 17:10:37 thorpej Exp $ */ /* * Copyright (c) 2018 Valery Ushakov * All rights reserved. @@ -28,7 +28,7 @@ * EM Microelectronic EM3027 RTC */ #include -__KERNEL_RCSID(0, "$NetBSD: em3027.c,v 1.3 2019/07/27 16:02:27 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: em3027.c,v 1.4 2020/12/23 17:10:37 thorpej Exp $"); #include #include @@ -105,7 +105,10 @@ static int em3027rtc_write(struct em3027 static int em3027rtc_read_byte(struct em3027rtc_softc *, uint8_t, uint8_t *); static int em3027rtc_write_byte(struct em3027rtc_softc *, uint8_t, uint8_t); - +static const struct device_compatible_entry compat_data[] = { + { "emmicro,em3027", 0 }, + { NULL, 0 }, +}; static int em3027rtc_match(device_t parent, cfdata_t cf, void *aux) @@ -113,6 +116,10 @@ em3027rtc_match(device_t parent, cfdata_ const struct i2c_attach_args *ia = aux; uint8_t reg; int error; + int match_result; + + if (iic_use_direct_match(ia, cf, compat_data, _result)) + return match_result; if (ia->ia_addr != EM3027_ADDR) return 0;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jdc Date: Wed Dec 23 07:06:26 UTC 2020 Modified Files: src/sys/dev/i2c: pcf8574.c Log Message: Handle pins that represent alerts. split out common code for alert and indicator pins change the previously debug-only callout to work for alerts too split out common code for alerts in refresh and in callout While here, remove redundant variable used for checking sysmon setup. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/pcf8574.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/dev/i2c/pcf8574.c diff -u src/sys/dev/i2c/pcf8574.c:1.5 src/sys/dev/i2c/pcf8574.c:1.6 --- src/sys/dev/i2c/pcf8574.c:1.5 Sun Dec 6 10:09:36 2020 +++ src/sys/dev/i2c/pcf8574.c Wed Dec 23 07:06:26 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: pcf8574.c,v 1.5 2020/12/06 10:09:36 jdc Exp $ */ +/* $NetBSD: pcf8574.c,v 1.6 2020/12/23 07:06:26 jdc Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v 1.5 2020/12/06 10:09:36 jdc Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v 1.6 2020/12/23 07:06:26 jdc Exp $"); #include #include @@ -43,6 +43,7 @@ __KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v #include #include +#include #include #include @@ -59,6 +60,12 @@ struct pcf8574_led { uint8_t mask, v_on, v_off; }; +struct pcf8574_pin { + int pin_sensor; + int pin_active; + char pin_desc[ENVSYS_DESCLEN]; +}; + #define PCF8574_NPINS 8 struct pcf8574_softc { device_t sc_dev; @@ -67,34 +74,35 @@ struct pcf8574_softc { uint8_t sc_state; uint8_t sc_mask; + uint8_t sc_alert_mask; +#define PCF8574_DEFAULT_TIMER 60 + int sc_callout_time; + callout_t sc_timer; + int sc_nleds; struct pcf8574_led sc_leds[PCF8574_NPINS]; + struct pcf8574_pin sc_pins[PCF8574_NPINS]; struct sysmon_envsys *sc_sme; envsys_data_t sc_sensor[PCF8574_NPINS]; - int sc_pin_sensor[PCF8574_NPINS]; - int sc_pin_active[PCF8574_NPINS]; - -#ifdef PCF8574_DEBUG - callout_t sc_timer; -#endif }; static int pcf8574_match(device_t, cfdata_t, void *); static void pcf8574_attach(device_t, device_t, void *); static int pcf8574_detach(device_t, int); -static int pcf8574_read(struct pcf8574_softc *sc, uint8_t *val); -static int pcf8574_write(struct pcf8574_softc *sc, uint8_t val); +static int pcf8574_read(struct pcf8574_softc *sc, uint8_t *); +static int pcf8574_write(struct pcf8574_softc *sc, uint8_t); static void pcf8574_attach_led( struct pcf8574_softc *, char *, int, int, int); +static int pcf8574_attach_sysmon( + struct pcf8574_softc *, char *, int, int, int); void pcf8574_refresh(struct sysmon_envsys *, envsys_data_t *); int pcf8574_get_led(void *); void pcf8574_set_led(void *, int); - -#ifdef PCF8574_DEBUG -static void pcf8574_timeout(void *); -#endif +static void pcf8574_timeout(void *); +static void pcf8574_check(void *); +static void pcf8574_check_alert(struct pcf8574_softc *, uint8_t, uint8_t); CFATTACH_DECL_NEW(pcf8574io, sizeof(struct pcf8574_softc), pcf8574_match, pcf8574_attach, pcf8574_detach, NULL); @@ -128,12 +136,19 @@ pcf8574_attach(device_t parent, device_t int i, num, def, envc = 0; char name[32]; const char *nptr = NULL, *spptr; - bool ok = TRUE, act, sysmon = FALSE; + bool ok = TRUE, act; sc->sc_tag = ia->ia_tag; sc->sc_addr = ia->ia_addr; sc->sc_dev = self; + sc->sc_sme = NULL; +#ifdef PCF8574_DEBUG + sc->sc_callout_time = 60; /* watch for changes when debugging */ +#else + sc->sc_callout_time = 0; +#endif + /* * The PCF8574 requires input pins to be written with the value 1, * and then read. Assume that all pins are input initially. @@ -150,9 +165,6 @@ pcf8574_attach(device_t parent, device_t #ifdef PCF8574_DEBUG aprint_normal(": GPIO: state = 0x%02x\n", sc->sc_state); - - callout_init(>sc_timer, CALLOUT_MPSAFE); - callout_reset(>sc_timer, hz*30, pcf8574_timeout, sc); #else aprint_normal(": GPIO\n"); #endif @@ -177,37 +189,38 @@ pcf8574_attach(device_t parent, device_t continue; spptr += 1; strncpy(name, spptr, 31); - sc->sc_pin_active[i] = act; + sc->sc_pins[i].pin_active = act; if (!strncmp(nptr, "LED ", 4)) { sc->sc_mask &= ~(1 << num); pcf8574_attach_led(sc, name, num, act, def); } - if (!strncmp(nptr, "INDICATOR ", 4)) { - if (!sysmon) { -sc->sc_sme = sysmon_envsys_create(); -sysmon = TRUE; - } - /* envsys sensor # to pin # mapping */ - sc->sc_pin_sensor[envc] = num; - sc->sc_sensor[i].state = ENVSYS_SINVALID; - sc->sc_sensor[i].units = ENVSYS_INDICATOR; - strlcpy(sc->sc_sensor[i].desc, name, - sizeof(sc->sc_sensor[i].desc)); - if (sysmon_envsys_sensor_attach(sc->sc_sme, - >sc_sensor[i])) { -sysmon_envsys_destroy(sc->sc_sme); -sc->sc_sme = NULL; -aprint_error_dev(self, -"unable to attach pin %d at sysmon\n", i); + if
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jdc Date: Thu Dec 10 17:02:51 UTC 2020 Modified Files: src/sys/dev/i2c: adm1021.c Log Message: Handle failing to acquire the iic bus. Better handle errors when attaching sysmon sensors. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/sys/dev/i2c/adm1021.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/dev/i2c/adm1021.c diff -u src/sys/dev/i2c/adm1021.c:1.20 src/sys/dev/i2c/adm1021.c:1.21 --- src/sys/dev/i2c/adm1021.c:1.20 Fri Aug 21 20:44:38 2020 +++ src/sys/dev/i2c/adm1021.c Thu Dec 10 17:02:51 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: adm1021.c,v 1.20 2020/08/21 20:44:38 macallan Exp $ */ +/* $NetBSD: adm1021.c,v 1.21 2020/12/10 17:02:51 jdc Exp $ */ /* $OpenBSD: adm1021.c,v 1.27 2007/06/24 05:34:35 dlg Exp $ */ /* @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.20 2020/08/21 20:44:38 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.21 2020/12/10 17:02:51 jdc Exp $"); #include #include @@ -396,6 +396,7 @@ admtemp_attach(device_t parent, device_t if (sysmon_envsys_sensor_attach( sc->sc_sme, >sc_sensor[ADMTEMP_INT])) { sysmon_envsys_destroy(sc->sc_sme); + sc->sc_sme = NULL; aprint_error_dev(self, "unable to attach internal at sysmon\n"); return; @@ -404,6 +405,7 @@ admtemp_attach(device_t parent, device_t sysmon_envsys_sensor_attach( sc->sc_sme, >sc_sensor[ADMTEMP_EXT])) { sysmon_envsys_destroy(sc->sc_sme); + sc->sc_sme = NULL; aprint_error_dev(self, "unable to attach external at sysmon\n"); return; @@ -425,6 +427,7 @@ admtemp_attach(device_t parent, device_t aprint_error_dev(self, "unable to register with sysmon\n"); sysmon_envsys_destroy(sc->sc_sme); + sc->sc_sme = NULL; return; } } @@ -437,7 +440,10 @@ admtemp_refresh(struct sysmon_envsys *sm uint8_t cmd, xdata; int8_t sdata; - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) { + edata->state = ENVSYS_SINVALID; + return; + } if (edata->sensor == ADMTEMP_INT) cmd = ADM1021_INT_TEMP; @@ -472,7 +478,8 @@ admtemp_getlim_1021(struct sysmon_envsys *props &= ~(PROP_CRITMAX | PROP_CRITMIN); - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) + return; if (edata->sensor == ADMTEMP_INT) cmd = ADM1021_INT_HIGH_READ; @@ -521,7 +528,8 @@ admtemp_getlim_1023(struct sysmon_envsys *props &= ~(PROP_CRITMAX | PROP_CRITMIN); - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) + return; if (edata->sensor == ADMTEMP_INT) cmd = ADM1021_INT_HIGH_READ; @@ -585,7 +593,8 @@ admtemp_getlim_1032(struct sysmon_envsys *props &= ~(PROP_WARNMAX | PROP_CRITMAX | PROP_WARNMIN); - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) + return; if (edata->sensor == ADMTEMP_INT) cmd = ADM1032_INT_THERM; @@ -660,7 +669,8 @@ admtemp_setlim_1021(struct sysmon_envsys int tmp; int8_t sdata; - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) + return; if (*props & PROP_CRITMAX) { if (edata->sensor == ADMTEMP_INT) @@ -746,7 +756,8 @@ admtemp_setlim_1023(struct sysmon_envsys else ext11 = 1; - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) + return; if (*props & PROP_CRITMAX) { if (edata->sensor == ADMTEMP_INT) @@ -803,7 +814,8 @@ admtemp_setlim_1032(struct sysmon_envsys else ext11 = 1; - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) + return; if (*props & PROP_CRITMAX) { if (edata->sensor == ADMTEMP_INT)
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jdc Date: Sun Dec 6 10:09:36 UTC 2020 Modified Files: src/sys/dev/i2c: pcf8574.c Log Message: Don't read from the chip when matching, fail the attach instead (requested by jmcneill). Reverts previous. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/pcf8574.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/dev/i2c/pcf8574.c diff -u src/sys/dev/i2c/pcf8574.c:1.4 src/sys/dev/i2c/pcf8574.c:1.5 --- src/sys/dev/i2c/pcf8574.c:1.4 Sat Dec 5 15:02:29 2020 +++ src/sys/dev/i2c/pcf8574.c Sun Dec 6 10:09:36 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: pcf8574.c,v 1.4 2020/12/05 15:02:29 jdc Exp $ */ +/* $NetBSD: pcf8574.c,v 1.5 2020/12/06 10:09:36 jdc Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v 1.4 2020/12/05 15:02:29 jdc Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v 1.5 2020/12/06 10:09:36 jdc Exp $"); #include #include @@ -108,21 +108,10 @@ static int pcf8574_match(device_t parent, cfdata_t cf, void *aux) { struct i2c_attach_args *ia = aux; - struct pcf8574_softc sc; int match_result; - if (!iic_use_direct_match(ia, cf, compat_data, _result)) - return 0; - - /* Try a read so that we don't match on optional components */ - if (match_result) { - sc.sc_tag = ia->ia_tag; - sc.sc_addr = ia->ia_addr; - if (pcf8574_read(, _state)) - return 0; - else - return match_result; - } + if (iic_use_direct_match(ia, cf, compat_data, _result)) + return match_result; /* We don't support indirect matches */ return 0; @@ -153,7 +142,11 @@ pcf8574_attach(device_t parent, device_t */ sc->sc_mask = 0xff; - pcf8574_read(sc, >sc_state); + /* Try a read, and fail if this component isn't present */ + if (pcf8574_read(sc, >sc_state)) { + aprint_normal(": read failed\n"); + return; + } #ifdef PCF8574_DEBUG aprint_normal(": GPIO: state = 0x%02x\n", sc->sc_state);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jdc Date: Sat Dec 5 15:02:29 UTC 2020 Modified Files: src/sys/dev/i2c: pcf8574.c Log Message: Return "match_result", not "1". Pointed out by jmcneill. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/pcf8574.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/dev/i2c/pcf8574.c diff -u src/sys/dev/i2c/pcf8574.c:1.3 src/sys/dev/i2c/pcf8574.c:1.4 --- src/sys/dev/i2c/pcf8574.c:1.3 Sat Dec 5 14:48:09 2020 +++ src/sys/dev/i2c/pcf8574.c Sat Dec 5 15:02:29 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: pcf8574.c,v 1.3 2020/12/05 14:48:09 jdc Exp $ */ +/* $NetBSD: pcf8574.c,v 1.4 2020/12/05 15:02:29 jdc Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v 1.3 2020/12/05 14:48:09 jdc Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v 1.4 2020/12/05 15:02:29 jdc Exp $"); #include #include @@ -121,7 +121,7 @@ pcf8574_match(device_t parent, cfdata_t if (pcf8574_read(, _state)) return 0; else - return 1; + return match_result; } /* We don't support indirect matches */
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jdc Date: Sat Dec 5 14:50:33 UTC 2020 Modified Files: src/sys/dev/i2c: hytp14.c si70xx.c Log Message: Make sure that we set sc->sc_sme to NULL in failure cases in order to avoid calling sysmon_envsys_unregister() with an invalid struct when we detach. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/hytp14.c cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/si70xx.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/dev/i2c/hytp14.c diff -u src/sys/dev/i2c/hytp14.c:1.9 src/sys/dev/i2c/hytp14.c:1.10 --- src/sys/dev/i2c/hytp14.c:1.9 Tue Oct 8 21:16:11 2019 +++ src/sys/dev/i2c/hytp14.c Sat Dec 5 14:50:33 2020 @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.9 2019/10/08 21:16:11 kardel Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.10 2020/12/05 14:50:33 jdc Exp $"); #include #include @@ -189,6 +189,7 @@ hytp14_attach(device_t parent, device_t aprint_error_dev(sc->sc_dev, "unable to attach sensor\n"); sysmon_envsys_destroy(sc->sc_sme); + sc->sc_sme = NULL; return; } } Index: src/sys/dev/i2c/si70xx.c diff -u src/sys/dev/i2c/si70xx.c:1.5 src/sys/dev/i2c/si70xx.c:1.6 --- src/sys/dev/i2c/si70xx.c:1.5 Sun Feb 3 12:18:21 2019 +++ src/sys/dev/i2c/si70xx.c Sat Dec 5 14:50:33 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: si70xx.c,v 1.5 2019/02/03 12:18:21 mrg Exp $ */ +/* $NetBSD: si70xx.c,v 1.6 2020/12/05 14:50:33 jdc Exp $ */ /* * Copyright (c) 2017 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: si70xx.c,v 1.5 2019/02/03 12:18:21 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: si70xx.c,v 1.6 2020/12/05 14:50:33 jdc Exp $"); /* Driver for the Silicon Labs SI7013/SI7020/SI7021 @@ -718,6 +718,7 @@ si70xx_attach(device_t parent, device_t if (error) { aprint_error_dev(self, "Unable to attach sensor %d: %d\n", i, error); + sc->sc_sme = NULL; goto out; } }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jdc Date: Sat Dec 5 14:48:09 UTC 2020 Modified Files: src/sys/dev/i2c: pcf8574.c Log Message: When matching, try a read in case this is an optional device and isn't actually present. Make sure that we set sc->sc_sme to NULL in failure cases and when we detach in order to avoid calling sysmon_envsys_unregister() with an invalid struct. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/pcf8574.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/dev/i2c/pcf8574.c diff -u src/sys/dev/i2c/pcf8574.c:1.2 src/sys/dev/i2c/pcf8574.c:1.3 --- src/sys/dev/i2c/pcf8574.c:1.2 Sat Oct 31 14:39:31 2020 +++ src/sys/dev/i2c/pcf8574.c Sat Dec 5 14:48:09 2020 @@ -1,3 +1,5 @@ +/* $NetBSD: pcf8574.c,v 1.3 2020/12/05 14:48:09 jdc Exp $ */ + /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. * All rights reserved. @@ -33,7 +35,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v 1.2 2020/10/31 14:39:31 jdc Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v 1.3 2020/12/05 14:48:09 jdc Exp $"); #include #include @@ -106,10 +108,21 @@ static int pcf8574_match(device_t parent, cfdata_t cf, void *aux) { struct i2c_attach_args *ia = aux; + struct pcf8574_softc sc; int match_result; - if (iic_use_direct_match(ia, cf, compat_data, _result)) - return match_result; + if (!iic_use_direct_match(ia, cf, compat_data, _result)) + return 0; + + /* Try a read so that we don't match on optional components */ + if (match_result) { + sc.sc_tag = ia->ia_tag; + sc.sc_addr = ia->ia_addr; + if (pcf8574_read(, _state)) + return 0; + else + return 1; + } /* We don't support indirect matches */ return 0; @@ -190,6 +203,7 @@ pcf8574_attach(device_t parent, device_t if (sysmon_envsys_sensor_attach(sc->sc_sme, >sc_sensor[i])) { sysmon_envsys_destroy(sc->sc_sme); +sc->sc_sme = NULL; aprint_error_dev(self, "unable to attach pin %d at sysmon\n", i); return; @@ -208,6 +222,7 @@ pcf8574_attach(device_t parent, device_t aprint_error_dev(self, "unable to register with sysmon\n"); sysmon_envsys_destroy(sc->sc_sme); + sc->sc_sme = NULL; return; } } @@ -219,8 +234,10 @@ pcf8574_detach(device_t self, int flags) struct pcf8574_softc *sc = device_private(self); int i; - if (sc->sc_sme != NULL) + if (sc->sc_sme != NULL) { sysmon_envsys_unregister(sc->sc_sme); + sc->sc_sme = NULL; + } for (i = 0; i < sc->sc_nleds; i++) led_detach(sc->sc_leds[i].led);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: skrll Date: Thu Nov 26 12:53:03 UTC 2020 Modified Files: src/sys/dev/i2c: g760a.c Log Message: Fix build and improve error handling To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/g760a.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/dev/i2c/g760a.c diff -u src/sys/dev/i2c/g760a.c:1.5 src/sys/dev/i2c/g760a.c:1.6 --- src/sys/dev/i2c/g760a.c:1.5 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/g760a.c Thu Nov 26 12:53:03 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: g760a.c,v 1.5 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: g760a.c,v 1.6 2020/11/26 12:53:03 skrll Exp $ */ /*- * Copyright (C) 2008 A.Leo. @@ -32,7 +32,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: g760a.c,v 1.5 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: g760a.c,v 1.6 2020/11/26 12:53:03 skrll Exp $"); #include #include @@ -227,6 +227,8 @@ g760a_setup(struct g760a_softc* sc) CTLTYPE_NODE, device_xname(sc->sc_dev), NULL, NULL, 0, NULL, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL); + if (ret) + goto sysctl_failed; (void)strlcpy(sc->sc_sensor.desc, "sysfan rpm", sizeof(sc->sc_sensor.desc)); @@ -242,6 +244,9 @@ g760a_setup(struct g760a_softc* sc) sysctl_g760a_rpm, 0x42, (void*)sc, 0, CTL_MACHDEP, me->sysctl_num, CTL_CREATE, CTL_EOL); + if (ret) + goto sysctl_failed; + sc->sc_sme->sme_name = device_xname(sc->sc_dev); sc->sc_sme->sme_cookie = sc; sc->sc_sme->sme_refresh = g760a_refresh; @@ -255,6 +260,11 @@ g760a_setup(struct g760a_softc* sc) } return; + +sysctl_failed: + aprint_error_dev(sc->sc_dev, + "couldn't create sysctl nodes (%d)\n", ret); + out: sysmon_envsys_destroy(sc->sc_sme); }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jdc Date: Sat Oct 31 14:38:54 UTC 2020 Modified Files: src/sys/dev/i2c: pcagpio.c Log Message: Detach led's in our detach routine. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/pcagpio.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/dev/i2c/pcagpio.c diff -u src/sys/dev/i2c/pcagpio.c:1.5 src/sys/dev/i2c/pcagpio.c:1.6 --- src/sys/dev/i2c/pcagpio.c:1.5 Thu Oct 29 06:50:53 2020 +++ src/sys/dev/i2c/pcagpio.c Sat Oct 31 14:38:54 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: pcagpio.c,v 1.5 2020/10/29 06:50:53 jdc Exp $ */ +/* $NetBSD: pcagpio.c,v 1.6 2020/10/31 14:38:54 jdc Exp $ */ /*- * Copyright (c) 2020 Michael Lorenz @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.5 2020/10/29 06:50:53 jdc Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.6 2020/10/31 14:38:54 jdc Exp $"); #include #include @@ -67,6 +67,7 @@ static void pcagpio_timeout(void *); /* we can only pass one cookie to led_attach() but we need several values... */ struct pcagpio_led { void *cookie; + struct led_device *led; uint32_t mask, v_on, v_off; }; @@ -215,9 +216,13 @@ pcagpio_attach(device_t parent, device_t static int pcagpio_detach(device_t self, int flags) { -#ifdef PCAGPIO_DEBUG struct pcagpio_softc *sc = device_private(self); + int i; + for (i = 0; i < sc->sc_nleds; i++) + led_detach(sc->sc_leds[i].led); + +#ifdef PCAGPIO_DEBUG callout_halt(>sc_timer, NULL); callout_destroy(>sc_timer); #endif @@ -311,7 +316,7 @@ pcagpio_attach_led(struct pcagpio_softc l->mask = 1 << pin; l->v_on = act ? l->mask : 0; l->v_off = act ? 0 : l->mask; - led_attach(n, l, pcagpio_get, pcagpio_set); + l->led = led_attach(n, l, pcagpio_get, pcagpio_set); if (def != -1) pcagpio_set(l, def); DPRINTF("%s: %04x %04x %04x def %d\n", __func__, l->mask, l->v_on, l->v_off, def);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jdc Date: Sat Oct 31 14:39:31 UTC 2020 Modified Files: src/sys/dev/i2c: pcf8574.c Log Message: Detach led's and sysmon in our detach routine. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/pcf8574.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/dev/i2c/pcf8574.c diff -u src/sys/dev/i2c/pcf8574.c:1.1 src/sys/dev/i2c/pcf8574.c:1.2 --- src/sys/dev/i2c/pcf8574.c:1.1 Thu Oct 29 06:55:51 2020 +++ src/sys/dev/i2c/pcf8574.c Sat Oct 31 14:39:31 2020 @@ -33,7 +33,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v 1.1 2020/10/29 06:55:51 jdc Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v 1.2 2020/10/31 14:39:31 jdc Exp $"); #include #include @@ -53,6 +53,7 @@ __KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v struct pcf8574_led { void *cookie; + struct led_device *led; uint8_t mask, v_on, v_off; }; @@ -215,13 +216,19 @@ pcf8574_attach(device_t parent, device_t static int pcf8574_detach(device_t self, int flags) { -#ifdef PCF8574_DEBUG struct pcf8574_softc *sc = device_private(self); + int i; + + if (sc->sc_sme != NULL) + sysmon_envsys_unregister(sc->sc_sme); + + for (i = 0; i < sc->sc_nleds; i++) + led_detach(sc->sc_leds[i].led); +#ifdef PCF8574_DEBUG callout_halt(>sc_timer, NULL); callout_destroy(>sc_timer); #endif - return 0; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jdc Date: Thu Oct 29 06:55:51 UTC 2020 Modified Files: src/sys/dev/i2c: files.i2c Added Files: src/sys/dev/i2c: pcf8574.c Log Message: Add a driver for the PCF8574 I/O expander, used as a GPIO in some sparc64 hardware. The driver currently handles pins configured as LED or INDICATOR and adds them to the LED and sysmon_envsys subsystems, respectively. To generate a diff of this commit: cvs rdiff -u -r1.111 -r1.112 src/sys/dev/i2c/files.i2c cvs rdiff -u -r0 -r1.1 src/sys/dev/i2c/pcf8574.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/dev/i2c/files.i2c diff -u src/sys/dev/i2c/files.i2c:1.111 src/sys/dev/i2c/files.i2c:1.112 --- src/sys/dev/i2c/files.i2c:1.111 Fri Apr 24 12:38:31 2020 +++ src/sys/dev/i2c/files.i2c Thu Oct 29 06:55:51 2020 @@ -1,4 +1,4 @@ -# $NetBSD: files.i2c,v 1.111 2020/04/24 12:38:31 macallan Exp $ +# $NetBSD: files.i2c,v 1.112 2020/10/29 06:55:51 jdc Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } @@ -395,3 +395,8 @@ file dev/i2c/cwfg.ccwfg device pcagpio: leds attach pcagpio at iic file dev/i2c/pcagpio.c pcagpio + +# Philips PCF8574 IO expander +device pcf8574io: leds, sysmon_envsys +attach pcf8574io at iic +file dev/i2c/pcf8574.c pcf8574io Added files: Index: src/sys/dev/i2c/pcf8574.c diff -u /dev/null src/sys/dev/i2c/pcf8574.c:1.1 --- /dev/null Thu Oct 29 06:55:51 2020 +++ src/sys/dev/i2c/pcf8574.c Thu Oct 29 06:55:51 2020 @@ -0,0 +1,328 @@ +/*- + * Copyright (c) 2020 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * A driver for Philips Semiconductor (NXP) PCF8574/PCF857A GPIO's. + * Uses device properties to connect pins to the appropriate subsystem. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v 1.1 2020/10/29 06:55:51 jdc Exp $"); + +#include +#include +#include +#include + +#include + +#include +#include + +#ifdef PCF8574_DEBUG +#define DPRINTF printf +#else +#define DPRINTF if (0) printf +#endif + +struct pcf8574_led { + void *cookie; + uint8_t mask, v_on, v_off; +}; + +#define PCF8574_NPINS 8 +struct pcf8574_softc { + device_t sc_dev; + i2c_tag_t sc_tag; + i2c_addr_t sc_addr; + uint8_t sc_state; + uint8_t sc_mask; + + int sc_nleds; + struct pcf8574_led sc_leds[PCF8574_NPINS]; + + struct sysmon_envsys *sc_sme; + envsys_data_t sc_sensor[PCF8574_NPINS]; + int sc_pin_sensor[PCF8574_NPINS]; + int sc_pin_active[PCF8574_NPINS]; + +#ifdef PCF8574_DEBUG + callout_t sc_timer; +#endif +}; + +static int pcf8574_match(device_t, cfdata_t, void *); +static void pcf8574_attach(device_t, device_t, void *); +static int pcf8574_detach(device_t, int); + +static int pcf8574_read(struct pcf8574_softc *sc, uint8_t *val); +static int pcf8574_write(struct pcf8574_softc *sc, uint8_t val); +static void pcf8574_attach_led( + struct pcf8574_softc *, char *, int, int, int); +void pcf8574_refresh(struct sysmon_envsys *, envsys_data_t *); +int pcf8574_get_led(void *); +void pcf8574_set_led(void *, int); + +#ifdef PCF8574_DEBUG +static void pcf8574_timeout(void *); +#endif + +CFATTACH_DECL_NEW(pcf8574io, sizeof(struct pcf8574_softc), + pcf8574_match, pcf8574_attach, pcf8574_detach, NULL); + +static const struct device_compatible_entry compat_data[] = { + { "i2c-pcf8574", 0 }, + { NULL,0 } +}; + +static int +pcf8574_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,
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jdc Date: Thu Oct 29 06:50:53 UTC 2020 Modified Files: src/sys/dev/i2c: pcagpio.c Log Message: Handle the change in the sparc64 OFW patching, where we now encode the GPIO pin type in the pin name (only LED types are currently handled). To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/pcagpio.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/dev/i2c/pcagpio.c diff -u src/sys/dev/i2c/pcagpio.c:1.4 src/sys/dev/i2c/pcagpio.c:1.5 --- src/sys/dev/i2c/pcagpio.c:1.4 Tue Oct 27 20:13:21 2020 +++ src/sys/dev/i2c/pcagpio.c Thu Oct 29 06:50:53 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: pcagpio.c,v 1.4 2020/10/27 20:13:21 jdc Exp $ */ +/* $NetBSD: pcagpio.c,v 1.5 2020/10/29 06:50:53 jdc Exp $ */ /*- * Copyright (c) 2020 Michael Lorenz @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.4 2020/10/27 20:13:21 jdc Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.5 2020/10/29 06:50:53 jdc Exp $"); #include #include @@ -184,7 +184,7 @@ pcagpio_attach(device_t parent, device_t if (pins != NULL) { int i, num, def; char name[32]; - const char *nptr; + const char *spptr, *nptr; bool ok = TRUE, act; for (i = 0; i < prop_array_count(pins); i++) { @@ -192,16 +192,22 @@ pcagpio_attach(device_t parent, device_t pin = prop_array_get(pins, i); ok &= prop_dictionary_get_cstring_nocopy(pin, "name", ); - strncpy(name, nptr, 31); ok &= prop_dictionary_get_uint32(pin, "pin", ); - ok &= prop_dictionary_get_bool( - pin, "active_high", ); + ok &= prop_dictionary_get_bool( pin, "active_high", + ); /* optional default state */ def = -1; prop_dictionary_get_int32(pin, "default_state", ); - if (ok) { + if (!ok) +continue; + /* Extract pin type from the name */ + spptr = strstr(nptr, " "); + if (spptr == NULL) +continue; + spptr += 1; + strncpy(name, spptr, 31); + if (!strncmp(nptr, "LED ", 4)) pcagpio_attach_led(sc, name, num, act, def); - } } } }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jdc Date: Tue Oct 27 20:13:21 UTC 2020 Modified Files: src/sys/dev/i2c: pcagpio.c Log Message: Add additional debugging output. Track more chip state in the softc and check the chip state via a timer. This allows us to easily observe changes caused by external events (e.g. disk removal or PSU failure). To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/pcagpio.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/dev/i2c/pcagpio.c diff -u src/sys/dev/i2c/pcagpio.c:1.3 src/sys/dev/i2c/pcagpio.c:1.4 --- src/sys/dev/i2c/pcagpio.c:1.3 Sun Feb 2 06:43:14 2020 +++ src/sys/dev/i2c/pcagpio.c Tue Oct 27 20:13:21 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: pcagpio.c,v 1.3 2020/02/02 06:43:14 macallan Exp $ */ +/* $NetBSD: pcagpio.c,v 1.4 2020/10/27 20:13:21 jdc Exp $ */ /*- * Copyright (c) 2020 Michael Lorenz @@ -31,11 +31,14 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.3 2020/02/02 06:43:14 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.4 2020/10/27 20:13:21 jdc Exp $"); #include #include #include +#ifdef PCAGPIO_DEBUG +#include +#endif #include #include @@ -56,6 +59,10 @@ __KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v static int pcagpio_match(device_t, cfdata_t, void *); static void pcagpio_attach(device_t, device_t, void *); +static int pcagpio_detach(device_t, int); +#ifdef PCAGPIO_DEBUG +static void pcagpio_timeout(void *); +#endif /* we can only pass one cookie to led_attach() but we need several values... */ struct pcagpio_led { @@ -72,6 +79,11 @@ struct pcagpio_softc { uint32_t sc_state; struct pcagpio_led sc_leds[16]; int sc_nleds; + +#ifdef PCAGPIO_DEBUG + uint32_t sc_dir, sc_in; + callout_t sc_timer; +#endif }; @@ -83,7 +95,7 @@ static int pcagpio_get(void *); static void pcagpio_set(void *, int); CFATTACH_DECL_NEW(pcagpio, sizeof(struct pcagpio_softc), -pcagpio_match, pcagpio_attach, NULL, NULL); +pcagpio_match, pcagpio_attach, pcagpio_detach, NULL); static const struct device_compatible_entry compat_data[] = { { "i2c-pca9555", 1 }, @@ -107,7 +119,7 @@ pcagpio_match(device_t parent, cfdata_t #ifdef PCAGPIO_DEBUG static void -printdir(uint32_t val, uint32_t mask, char letter) +printdir(char* name, uint32_t val, uint32_t mask, char letter) { char flags[17], bits[17]; uint32_t bit = 0x8000; @@ -121,8 +133,8 @@ printdir(uint32_t val, uint32_t mask, ch } flags[16] = 0; bits[16] = 0; - printf("dir: %s\n", flags); - printf("lvl: %s\n", bits); + printf("%s: dir: %s\n", name, flags); + printf("%s: lvl: %s\n", name, bits); } #endif @@ -151,16 +163,21 @@ pcagpio_attach(device_t parent, device_t sc->sc_state = pcagpio_readreg(sc, PCAGPIO_OUTPUT); #ifdef PCAGPIO_DEBUG - uint32_t dir, in, out; - dir = pcagpio_readreg(sc, PCAGPIO_CONFIG); - in = pcagpio_readreg(sc, PCAGPIO_INPUT); + uint32_t in, out; + sc->sc_dir = pcagpio_readreg(sc, PCAGPIO_CONFIG); + sc->sc_in = pcagpio_readreg(sc, PCAGPIO_INPUT); + in = sc-> sc_in; out = sc->sc_state; - out &= ~dir; - in &= dir; + out &= ~sc->sc_dir; + in &= sc->sc_dir; - printdir(in, dir, 'I'); - printdir(out, ~dir, 'O'); + printdir(sc->sc_dev->dv_xname, in, sc->sc_dir, 'I'); + printdir(sc->sc_dev->dv_xname, out, ~sc->sc_dir, 'O'); + + callout_init(>sc_timer, CALLOUT_MPSAFE); + callout_reset(>sc_timer, hz*20, pcagpio_timeout, sc); + #endif pins = prop_dictionary_get(dict, "pins"); @@ -189,6 +206,49 @@ pcagpio_attach(device_t parent, device_t } } +static int +pcagpio_detach(device_t self, int flags) +{ +#ifdef PCAGPIO_DEBUG + struct pcagpio_softc *sc = device_private(self); + + callout_halt(>sc_timer, NULL); + callout_destroy(>sc_timer); +#endif + + return 0; +} + +#ifdef PCAGPIO_DEBUG +static void +pcagpio_timeout(void *v) +{ + struct pcagpio_softc *sc = v; + uint32_t out, dir, in, o_out, o_in; + + out = pcagpio_readreg(sc, PCAGPIO_OUTPUT); + dir = pcagpio_readreg(sc, PCAGPIO_CONFIG); + in = pcagpio_readreg(sc, PCAGPIO_INPUT); + if (out != sc->sc_state || dir != sc->sc_dir || in != sc->sc_in) { + aprint_normal_dev(sc->sc_dev, "status change\n"); + o_out = sc->sc_state; + o_in = sc->sc_in; + o_out &= ~sc->sc_dir; + o_in &= sc->sc_dir; + printdir(sc->sc_dev->dv_xname, o_in, sc->sc_dir, 'I'); + printdir(sc->sc_dev->dv_xname, o_out, ~sc->sc_dir, 'O'); + sc->sc_state = out; + sc->sc_dir = dir; + sc->sc_in = in; + out &= ~sc->sc_dir; + in &= sc->sc_dir; + printdir(sc->sc_dev->dv_xname, in, sc->sc_dir, 'I'); + printdir(sc->sc_dev->dv_xname, out, ~sc->sc_dir, 'O'); + } + callout_reset(>sc_timer, hz*60, pcagpio_timeout, sc); +} +#endif + static void pcagpio_writereg(struct pcagpio_softc *sc, int reg, uint32_t val) {
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Fri Aug 21 21:28:22 UTC 2020 Modified Files: src/sys/dev/i2c: dstemp.c Log Message: more OF -> properties for sensor names, this should be the last one To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/dstemp.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/dev/i2c/dstemp.c diff -u src/sys/dev/i2c/dstemp.c:1.5 src/sys/dev/i2c/dstemp.c:1.6 --- src/sys/dev/i2c/dstemp.c:1.5 Fri Feb 28 13:18:25 2020 +++ src/sys/dev/i2c/dstemp.c Fri Aug 21 21:28:22 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: dstemp.c,v 1.5 2020/02/28 13:18:25 macallan Exp $ */ +/* $NetBSD: dstemp.c,v 1.6 2020/08/21 21:28:22 macallan Exp $ */ /*- * Copyright (c) 2018 Michael Lorenz @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.5 2020/02/28 13:18:25 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.6 2020/08/21 21:28:22 macallan Exp $"); #include #include @@ -39,14 +39,6 @@ __KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1 #include -#ifdef macppc -#define HAVE_OF 1 -#endif - -#ifdef HAVE_OF -#include -#endif - #define DSTEMP_CMD_START 0x51 /* command, no data */ #define DSTEMP_CMD_POR 0x54 /* command, no data */ #define DSTEMP_CMD_STOP 0x22 /* command, no data */ @@ -68,12 +60,12 @@ __KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1 #define DSTEMP_DONE 0x80 struct dstemp_softc { - device_t sc_dev; - i2c_tag_t sc_i2c; - i2c_addr_t sc_addr; - - struct sysmon_envsys *sc_sme; - envsys_data_t sc_sensor_temp; + device_t sc_dev; + i2c_tag_t sc_i2c; + i2c_addr_t sc_addr; + prop_dictionary_t sc_prop; + struct sysmon_envsys *sc_sme; + envsys_data_t sc_sensor_temp; }; static int dstemp_match(device_t, cfdata_t, void *); @@ -111,10 +103,12 @@ dstemp_attach(device_t parent, device_t struct dstemp_softc *sc = device_private(self); struct i2c_attach_args *ia = aux; char name[64] = "temperature"; + const char *desc; sc->sc_dev = self; sc->sc_i2c = ia->ia_tag; sc->sc_addr = ia->ia_addr; + sc->sc_prop = ia->ia_prop; aprint_naive("\n"); aprint_normal(": DS1361\n"); @@ -128,13 +122,13 @@ dstemp_attach(device_t parent, device_t sc->sc_sensor_temp.units = ENVSYS_STEMP; sc->sc_sensor_temp.state = ENVSYS_SINVALID; -#ifdef HAVE_OF - int ch; - ch = OF_child(ia->ia_cookie); - if (ch != 0) { - OF_getprop(ch, "location", name, 64); + + if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, "s00", )) { + strncpy(name, desc, 64); + } else if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, "saa", )) { + strncpy(name, desc, 64); } -#endif + strncpy(sc->sc_sensor_temp.desc, name, sizeof(sc->sc_sensor_temp.desc)); sysmon_envsys_sensor_attach(sc->sc_sme, >sc_sensor_temp);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Fri Aug 21 20:44:38 UTC 2020 Modified Files: src/sys/dev/i2c: adm1021.c Log Message: get sensore names from properties, remove OF code To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sys/dev/i2c/adm1021.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/dev/i2c/adm1021.c diff -u src/sys/dev/i2c/adm1021.c:1.19 src/sys/dev/i2c/adm1021.c:1.20 --- src/sys/dev/i2c/adm1021.c:1.19 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/adm1021.c Fri Aug 21 20:44:38 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: adm1021.c,v 1.19 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: adm1021.c,v 1.20 2020/08/21 20:44:38 macallan Exp $ */ /* $OpenBSD: adm1021.c,v 1.27 2007/06/24 05:34:35 dlg Exp $ */ /* @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.19 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.20 2020/08/21 20:44:38 macallan Exp $"); #include #include @@ -47,14 +47,6 @@ __KERNEL_RCSID(0, "$NetBSD: adm1021.c,v #include -#ifdef macppc -#define HAVE_OF 1 -#endif - -#ifdef HAVE_OF -#include -#endif - /* Registers */ #define ADM1021_INT_TEMP 0x00 /* Internal temperature value */ #define ADM1021_EXT_TEMP 0x01 /* External temperature value */ @@ -118,6 +110,7 @@ __KERNEL_RCSID(0, "$NetBSD: adm1021.c,v struct admtemp_softc { i2c_tag_t sc_tag; i2c_addr_t sc_addr; + prop_dictionary_t sc_prop; int sc_flags; int sc_noexternal, sc_noneg, sc_nolow; @@ -320,12 +313,12 @@ admtemp_attach(device_t parent, device_t struct i2c_attach_args *ia = aux; uint8_t cmd, data, stat, comp, rev; char name[ADMTEMP_NAMELEN]; -#ifdef HAVE_OF - char ename[64], iname[64]; - int ch; -#endif + char ename[64] = "external", iname[64] = "internal"; + const char *desc; + sc->sc_tag = ia->ia_tag; sc->sc_addr = ia->ia_addr; + sc->sc_prop = ia->ia_prop; iic_acquire_bus(sc->sc_tag, 0); cmd = ADM1021_CONFIG_READ; @@ -385,27 +378,20 @@ admtemp_attach(device_t parent, device_t sc->sc_sensor[ADMTEMP_EXT].units = ENVSYS_STEMP; sc->sc_sensor[ADMTEMP_INT].flags = ENVSYS_FMONLIMITS; sc->sc_sensor[ADMTEMP_EXT].flags = ENVSYS_FMONLIMITS; -#ifdef HAVE_OF - strcpy(iname, "internal"); - strcpy(ename, "external"); - ch = OF_child(ia->ia_cookie); - if (ch != 0) { - OF_getprop(ch, "location", iname, 64); - ch = OF_peer(ch); - if (ch != 0) { - OF_getprop(ch, "location", ename, 64); - } - } + + if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, "s00", )) { + strncpy(iname, desc, 64); + } + + if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, "s01", )) { + strncpy(ename, desc, 64); + } + strlcpy(sc->sc_sensor[ADMTEMP_INT].desc, iname, sizeof(sc->sc_sensor[ADMTEMP_INT].desc)); strlcpy(sc->sc_sensor[ADMTEMP_EXT].desc, ename, sizeof(sc->sc_sensor[ADMTEMP_EXT].desc)); -#else - strlcpy(sc->sc_sensor[ADMTEMP_INT].desc, "internal", - sizeof(sc->sc_sensor[ADMTEMP_INT].desc)); - strlcpy(sc->sc_sensor[ADMTEMP_EXT].desc, "external", - sizeof(sc->sc_sensor[ADMTEMP_EXT].desc)); -#endif + sc->sc_sme = sysmon_envsys_create(); if (sysmon_envsys_sensor_attach( sc->sc_sme, >sc_sensor[ADMTEMP_INT])) {
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Fri Aug 21 20:41:43 UTC 2020 Modified Files: src/sys/dev/i2c: lm75.c Log Message: get sensor name from properties, remove macppc-specific OF support To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/sys/dev/i2c/lm75.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/dev/i2c/lm75.c diff -u src/sys/dev/i2c/lm75.c:1.35 src/sys/dev/i2c/lm75.c:1.36 --- src/sys/dev/i2c/lm75.c:1.35 Mon Dec 23 14:41:41 2019 +++ src/sys/dev/i2c/lm75.c Fri Aug 21 20:41:43 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: lm75.c,v 1.35 2019/12/23 14:41:41 thorpej Exp $ */ +/* $NetBSD: lm75.c,v 1.36 2020/08/21 20:41:43 macallan Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.35 2019/12/23 14:41:41 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.36 2020/08/21 20:41:43 macallan Exp $"); #include #include @@ -49,18 +49,11 @@ __KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.3 #include #include -#ifdef macppc -#define HAVE_OF 1 -#endif - -#ifdef HAVE_OF -#include -#endif - struct lmtemp_softc { device_t sc_dev; i2c_tag_t sc_tag; int sc_address; + prop_dictionary_t sc_prop; struct sysmon_envsys *sc_sme; envsys_data_t sc_sensor; @@ -174,6 +167,7 @@ lmtemp_attach(device_t parent, device_t struct lmtemp_softc *sc = device_private(self); struct i2c_attach_args *ia = aux; char name[64]; + const char *desc; int i; sc->sc_dev = self; @@ -193,6 +187,7 @@ lmtemp_attach(device_t parent, device_t sc->sc_tag = ia->ia_tag; sc->sc_address = ia->ia_addr; + sc->sc_prop = ia->ia_prop; aprint_naive(": Temperature Sensor\n"); if (ia->ia_name) { @@ -261,13 +256,11 @@ lmtemp_attach(device_t parent, device_t (void)strlcpy(name, ia->ia_name? ia->ia_name : device_xname(self), sizeof(sc->sc_sensor.desc)); -#ifdef HAVE_OF - int ch; - ch = OF_child(ia->ia_cookie); - if (ch != 0) { - OF_getprop(ch, "location", name, 64); + + if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, "s00", )) { + strncpy(name, desc, 64); } -#endif + (void)strlcpy(sc->sc_sensor.desc, name, sizeof(sc->sc_sensor.desc)); if (sysmon_envsys_sensor_attach(sc->sc_sme, >sc_sensor)) {
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: kim Date: Sun Jul 12 08:48:49 UTC 2020 Modified Files: src/sys/dev/i2c: dbcool_var.h Log Message: Make this compile To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sys/dev/i2c/dbcool_var.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/dbcool_var.h diff -u src/sys/dev/i2c/dbcool_var.h:1.16 src/sys/dev/i2c/dbcool_var.h:1.17 --- src/sys/dev/i2c/dbcool_var.h:1.16 Thu Apr 16 23:29:53 2020 +++ src/sys/dev/i2c/dbcool_var.h Sun Jul 12 08:48:49 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: dbcool_var.h,v 1.16 2020/04/16 23:29:53 rin Exp $ */ +/* $NetBSD: dbcool_var.h,v 1.17 2020/07/12 08:48:49 kim Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: dbcool_var.h,v 1.16 2020/04/16 23:29:53 rin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dbcool_var.h,v 1.17 2020/07/12 08:48:49 kim Exp $"); #include @@ -129,6 +129,7 @@ struct dbcool_softc { int64_t sc_supply_voltage; bool sc_suspend; struct sysctllog *sc_sysctl_log; + prop_dictionary_t sc_prop; #ifdef DBCOOL_DEBUG uint8_t sc_user_reg; #endif
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Sun Jul 12 06:42:33 UTC 2020 Modified Files: src/sys/dev/i2c: dbcool.c Log Message: in sysctl_dbcool_behavior() - actually use the array index when translating text from sysctl -w *.behavior= now this actually works on my sb2500's two adm1030s To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 src/sys/dev/i2c/dbcool.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/dev/i2c/dbcool.c diff -u src/sys/dev/i2c/dbcool.c:1.55 src/sys/dev/i2c/dbcool.c:1.56 --- src/sys/dev/i2c/dbcool.c:1.55 Sun Jul 12 06:38:56 2020 +++ src/sys/dev/i2c/dbcool.c Sun Jul 12 06:42:32 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: dbcool.c,v 1.55 2020/07/12 06:38:56 macallan Exp $ */ +/* $NetBSD: dbcool.c,v 1.56 2020/07/12 06:42:32 macallan Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -50,7 +50,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.55 2020/07/12 06:38:56 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.56 2020/07/12 06:42:32 macallan Exp $"); #include #include @@ -1314,7 +1314,7 @@ sysctl_dbcool_behavior(SYSCTLFN_ARGS) break; if (i >= __arraycount(behavior)) return EINVAL; - + newreg = i; if (sc->sc_dc.dc_chip->flags & DBCFLAG_ADM1030) { /* * ADM1030 splits fan controller behavior across two
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Sun Jul 12 06:38:57 UTC 2020 Modified Files: src/sys/dev/i2c: dbcool.c Log Message: get sensor names from device properties if possible To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 src/sys/dev/i2c/dbcool.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/dev/i2c/dbcool.c diff -u src/sys/dev/i2c/dbcool.c:1.54 src/sys/dev/i2c/dbcool.c:1.55 --- src/sys/dev/i2c/dbcool.c:1.54 Wed Feb 6 08:37:12 2019 +++ src/sys/dev/i2c/dbcool.c Sun Jul 12 06:38:56 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: dbcool.c,v 1.54 2019/02/06 08:37:12 martin Exp $ */ +/* $NetBSD: dbcool.c,v 1.55 2020/07/12 06:38:56 macallan Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -50,7 +50,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.54 2019/02/06 08:37:12 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.55 2020/07/12 06:38:56 macallan Exp $"); #include #include @@ -775,6 +775,7 @@ dbcool_attach(device_t parent, device_t sc->sc_dc.dc_readreg = dbcool_readreg; sc->sc_dc.dc_writereg = dbcool_writereg; sc->sc_dev = self; + sc->sc_prop = args->ia_prop; if (dbcool_chip_ident(>sc_dc) < 0 || sc->sc_dc.dc_chip == NULL) panic("could not identify chip at addr %d", args->ia_addr); @@ -1689,10 +1690,18 @@ dbcool_attach_sensor(struct dbcool_softc { int name_index; int error = 0; + char name[8]; + const char *desc; name_index = sc->sc_dc.dc_chip->table[idx].name_index; - strlcpy(sc->sc_sensor[idx].desc, dbc_sensor_names[name_index], - sizeof(sc->sc_sensor[idx].desc)); + snprintf(name, 7, "s%02x", sc->sc_dc.dc_chip->table[idx].reg.val_reg); + if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, name, )) { + strlcpy(sc->sc_sensor[idx].desc, desc, + sizeof(sc->sc_sensor[idx].desc)); + } else { + strlcpy(sc->sc_sensor[idx].desc, dbc_sensor_names[name_index], + sizeof(sc->sc_sensor[idx].desc)); + } sc->sc_regs[idx] = >sc_dc.dc_chip->table[idx].reg; sc->sc_nom_volt[idx] = sc->sc_dc.dc_chip->table[idx].nom_volt_index; @@ -1721,9 +1730,12 @@ dbcool_attach_temp_control(struct dbcool /* create sysctl node for the sensor if not one already there */ if (sc->sc_sysctl_num[j] == -1) { + int name_index = sc->sc_dc.dc_chip->table[idx].name_index; + ret = sysctl_createv(>sc_sysctl_log, 0, NULL, , CTLFLAG_READWRITE, - CTLTYPE_NODE, sc->sc_sensor[j].desc, NULL, + CTLTYPE_NODE, dbc_sensor_names[name_index], + sc->sc_sensor[j].desc, NULL, 0, NULL, 0, CTL_HW, sc->sc_root_sysctl_num, CTL_CREATE, CTL_EOL);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: msaitoh Date: Tue Jun 30 19:02:42 UTC 2020 Modified Files: src/sys/dev/i2c: sdtemp.c Log Message: If an error occurred in sme_refresh function, pass ENVSYS_SINVALID. OK'd by pgoyette. To generate a diff of this commit: cvs rdiff -u -r1.38 -r1.39 src/sys/dev/i2c/sdtemp.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/dev/i2c/sdtemp.c diff -u src/sys/dev/i2c/sdtemp.c:1.38 src/sys/dev/i2c/sdtemp.c:1.39 --- src/sys/dev/i2c/sdtemp.c:1.38 Mon Jun 29 09:24:07 2020 +++ src/sys/dev/i2c/sdtemp.c Tue Jun 30 19:02:42 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: sdtemp.c,v 1.38 2020/06/29 09:24:07 msaitoh Exp $*/ +/* $NetBSD: sdtemp.c,v 1.39 2020/06/30 19:02:42 msaitoh Exp $*/ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.38 2020/06/29 09:24:07 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.39 2020/06/30 19:02:42 msaitoh Exp $"); #include #include @@ -578,8 +578,10 @@ sdtemp_refresh(struct sysmon_envsys *sme int error; error = iic_acquire_bus(sc->sc_tag, 0); - if (error) + if (error) { + edata->state = ENVSYS_SINVALID; return; + } error = sdtemp_read_16(sc, SDTEMP_REG_AMBIENT_TEMP, ); iic_release_bus(sc->sc_tag, 0);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: msaitoh Date: Mon Jun 29 09:24:07 UTC 2020 Modified Files: src/sys/dev/i2c: sdtemp.c Log Message: Check the return value of iic_acquire_bus(). This function may fail. One of the case is driver's detaching phase on shutdown. mutex_tryenter() might fail and return with EBUSY. To avoid calling iic_release_bus() without taking lock, check the return value of iic_acquire_bus(). To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 src/sys/dev/i2c/sdtemp.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/dev/i2c/sdtemp.c diff -u src/sys/dev/i2c/sdtemp.c:1.37 src/sys/dev/i2c/sdtemp.c:1.38 --- src/sys/dev/i2c/sdtemp.c:1.37 Mon Jun 29 06:01:30 2020 +++ src/sys/dev/i2c/sdtemp.c Mon Jun 29 09:24:07 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: sdtemp.c,v 1.37 2020/06/29 06:01:30 msaitoh Exp $*/ +/* $NetBSD: sdtemp.c,v 1.38 2020/06/29 09:24:07 msaitoh Exp $*/ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.37 2020/06/29 06:01:30 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.38 2020/06/29 09:24:07 msaitoh Exp $"); #include #include @@ -218,7 +218,9 @@ sdtemp_match(device_t parent, cfdata_t c * Verify that we can read the manufacturer ID, Device ID and the * capability */ - iic_acquire_bus(sc.sc_tag, 0); + error = iic_acquire_bus(sc.sc_tag, 0); + if (error) + return 0; error = sdtemp_read_16(, SDTEMP_REG_MFG_ID, ) | sdtemp_read_16(, SDTEMP_REG_DEV_REV, ) | sdtemp_read_16(, SDTEMP_REG_CAPABILITY, ); @@ -258,7 +260,10 @@ sdtemp_attach(device_t parent, device_t sc->sc_address = ia->ia_addr; sc->sc_dev = self; - iic_acquire_bus(sc->sc_tag, 0); + error = iic_acquire_bus(sc->sc_tag, 0); + if (error) + return; + if ((error = sdtemp_read_16(sc, SDTEMP_REG_MFG_ID, )) != 0 || (error = sdtemp_read_16(sc, SDTEMP_REG_DEV_REV, )) != 0) { iic_release_bus(sc->sc_tag, 0); @@ -426,7 +431,9 @@ sdtemp_get_limits(struct sysmon_envsys * uint16_t lim; *props = 0; - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0) != 0) + return; + if (sdtemp_read_16(sc, SDTEMP_REG_LOWER_LIM, ) == 0 && lim != 0) { limits->sel_warnmin = sdtemp_decode_temp(sc, lim); *props |= PROP_WARNMIN; @@ -456,7 +463,9 @@ sdtemp_set_limits(struct sysmon_envsys * limits = >sc_deflims; props = >sc_defprops; } - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0) != 0) + return; + if (*props & PROP_WARNMIN) { val = __UK2C(limits->sel_warnmin); (void)sdtemp_write_16(sc, SDTEMP_REG_LOWER_LIM, @@ -568,7 +577,10 @@ sdtemp_refresh(struct sysmon_envsys *sme uint16_t val; int error; - iic_acquire_bus(sc->sc_tag, 0); + error = iic_acquire_bus(sc->sc_tag, 0); + if (error) + return; + error = sdtemp_read_16(sc, SDTEMP_REG_AMBIENT_TEMP, ); iic_release_bus(sc->sc_tag, 0); @@ -610,7 +622,10 @@ sdtemp_pmf_suspend(device_t dev, const p int error; uint16_t config; - iic_acquire_bus(sc->sc_tag, 0); + error = iic_acquire_bus(sc->sc_tag, 0); + if (error != 0) + return false; + error = sdtemp_read_16(sc, SDTEMP_REG_CONFIG, ); if (error == 0) { config |= SDTEMP_CONFIG_SHUTDOWN_MODE; @@ -627,7 +642,10 @@ sdtemp_pmf_resume(device_t dev, const pm int error; uint16_t config; - iic_acquire_bus(sc->sc_tag, 0); + error = iic_acquire_bus(sc->sc_tag, 0); + if (error != 0) + return false; + error = sdtemp_read_16(sc, SDTEMP_REG_CONFIG, ); if (error == 0) { config &= ~SDTEMP_CONFIG_SHUTDOWN_MODE;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: msaitoh Date: Mon Jun 29 06:01:30 UTC 2020 Modified Files: src/sys/dev/i2c: sdtemp.c Log Message: KNF. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/sys/dev/i2c/sdtemp.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/dev/i2c/sdtemp.c diff -u src/sys/dev/i2c/sdtemp.c:1.36 src/sys/dev/i2c/sdtemp.c:1.37 --- src/sys/dev/i2c/sdtemp.c:1.36 Tue Oct 1 18:00:08 2019 +++ src/sys/dev/i2c/sdtemp.c Mon Jun 29 06:01:30 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: sdtemp.c,v 1.36 2019/10/01 18:00:08 chs Exp $*/ +/* $NetBSD: sdtemp.c,v 1.37 2020/06/29 06:01:30 msaitoh Exp $*/ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.36 2019/10/01 18:00:08 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.37 2020/06/29 06:01:30 msaitoh Exp $"); #include #include @@ -214,7 +214,10 @@ sdtemp_match(device_t parent, cfdata_t c if ((ia->ia_addr & SDTEMP_ADDRMASK) != SDTEMP_ADDR) return 0; - /* Verify that we can read the manufacturer ID, Device ID and the capability */ + /* + * Verify that we can read the manufacturer ID, Device ID and the + * capability + */ iic_acquire_bus(sc.sc_tag, 0); error = sdtemp_read_16(, SDTEMP_REG_MFG_ID, ) | sdtemp_read_16(, SDTEMP_REG_DEV_REV, ) | @@ -234,8 +237,8 @@ sdtemp_match(device_t parent, cfdata_t c } /* - * Check by SDTEMP_IS_TSE2004AV() might not be enough, so check the alarm - * capability, too. + * Check by SDTEMP_IS_TSE2004AV() might not be enough, so check the + * alarm capability, too. */ if ((cap & SDTEMP_CAP_HAS_ALARM) == 0) return 0; @@ -593,7 +596,7 @@ sdtemp_refresh(struct sysmon_envsys *sme } /* - * power management functions + * Power management functions * * We go into "shutdown" mode at suspend time, and return to normal * mode upon resume. This reduces power consumption by disabling
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: martin Date: Fri Jun 26 10:06:57 UTC 2020 Modified Files: src/sys/dev/i2c: adm1026.c Log Message: Avoid creating a full temporary softc struct on the stack. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/adm1026.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/dev/i2c/adm1026.c diff -u src/sys/dev/i2c/adm1026.c:1.7 src/sys/dev/i2c/adm1026.c:1.8 --- src/sys/dev/i2c/adm1026.c:1.7 Mon Dec 23 02:25:28 2019 +++ src/sys/dev/i2c/adm1026.c Fri Jun 26 10:06:57 2020 @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: adm1026.c,v 1.7 2019/12/23 02:25:28 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adm1026.c,v 1.8 2020/06/26 10:06:57 martin Exp $"); #include #include @@ -98,7 +98,7 @@ struct adm1026_softc { }; static int adm1026_match(device_t, cfdata_t, void *); -static int adm1026_ident(struct adm1026_softc *, int); +static int adm1026_ident(i2c_tag_t, i2c_addr_t, int, uint8_t*); static void adm1026_attach(device_t, device_t, void *); static int adm1026_detach(device_t, int); bool adm1026_pmf_suspend(device_t, const pmf_qual_t *); @@ -113,11 +113,18 @@ static void adm1026_read_fan(struct adm1 static void adm1026_read_temp(struct adm1026_softc *sc, envsys_data_t *edata); static void adm1026_read_volt(struct adm1026_softc *sc, envsys_data_t *edata); -static int adm1026_read_reg(struct adm1026_softc *sc, -uint8_t reg, uint8_t *val); +static int adm1026_read_reg_int(i2c_tag_t, i2c_addr_t, +uint8_t reg, bool multi_read, uint8_t *val); static int adm1026_write_reg(struct adm1026_softc *sc, uint8_t reg, uint8_t val); +static inline int +adm1026_read_reg(struct adm1026_softc *sc, uint8_t reg, uint8_t *val) +{ + return adm1026_read_reg_int(sc->sc_tag, sc->sc_address, reg, + sc->sc_multi_read, val); +} + CFATTACH_DECL_NEW(adm1026hm, sizeof(struct adm1026_softc), adm1026_match, adm1026_attach, adm1026_detach, NULL); @@ -130,37 +137,35 @@ static int adm1026_match(device_t parent, cfdata_t cf, void *aux) { struct i2c_attach_args *ia = aux; - struct adm1026_softc sc; /* For chip ident */ int match_result; - - sc.sc_tag = ia->ia_tag; - sc.sc_address = ia->ia_addr; + uint8_t rev; if (iic_use_direct_match(ia, cf, compat_data, _result)) return match_result; - if (ia->ia_addr == ADM1026_ADDR1 && adm1026_ident(, 1)) + if (ia->ia_addr == ADM1026_ADDR1 + && adm1026_ident(ia->ia_tag, ia->ia_addr, 1, )) return I2C_MATCH_ADDRESS_AND_PROBE; return 0; } static int -adm1026_ident(struct adm1026_softc *sc, int probe_only) +adm1026_ident(i2c_tag_t tag, i2c_addr_t addr, int probe_only, uint8_t *rev) { uint8_t val; int err; /* Manufacturer ID and revision/stepping */ - err = adm1026_read_reg(sc, ADM1026_ID, ); + err = adm1026_read_reg_int(tag, addr, ADM1026_ID, false, ); if (err || val != ADM1026_MANF_ID) { if (!probe_only) aprint_verbose("adm1026_ident: " "manufacturer ID invalid or missing\n"); return 0; } - err = adm1026_read_reg(sc, ADM1026_REV, >sc_rev); - if (err || ADM1026_REVISION(sc->sc_rev) != ADM1026_MANF_REV) { + err = adm1026_read_reg_int(tag, addr, ADM1026_REV, false, rev); + if (err || ADM1026_REVISION(*rev) != ADM1026_MANF_REV) { if (!probe_only) aprint_verbose("adm1026_ident: " "manufacturer revision invalid or missing\n"); @@ -189,7 +194,7 @@ adm1026_attach(device_t parent, device_t else div2_val = -1; - (void) adm1026_ident(sc, 0); + (void) adm1026_ident(sc->sc_tag, sc->sc_address, 0, >sc_rev); aprint_normal(": ADM1026 hardware monitor: rev. 0x%x, step. 0x%x\n", ADM1026_REVISION(sc->sc_rev), ADM1026_STEPPING(sc->sc_rev)); @@ -482,18 +487,19 @@ adm1026_read_volt(struct adm1026_softc * } static int -adm1026_read_reg(struct adm1026_softc *sc, uint8_t reg, uint8_t *val) +adm1026_read_reg_int(i2c_tag_t tag, i2c_addr_t addr, uint8_t reg, +bool multi_read, uint8_t *val) { #define ADM1026_READ_RETRIES 5 int i, j, err = 0; uint8_t creg, cval, tmp[ADM1026_READ_RETRIES + 1]; - if ((err = iic_acquire_bus(sc->sc_tag, 0)) != 0) + if ((err = iic_acquire_bus(tag, 0)) != 0) return err; /* Standard ADM1026 */ - if (sc->sc_multi_read == false) { - err = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, - sc->sc_address, , 1, val, 1, 0); + if (multi_read == false) { + err = iic_exec(tag, I2C_OP_READ_WITH_STOP, + addr, , 1, val, 1, 0); /* * The ADM1026 found in some Sun machines sometimes reads bogus values. * We'll read at least twice and check that we get (nearly) the same @@ -505,28 +511,28 @@ adm1026_read_reg(struct adm1026_softc *s creg = ADM1026_CONF2; else creg = ADM1026_CONF1; - if ((err = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, - sc->sc_address, , 1, [0], 1, 0)) != 0) { - iic_release_bus(sc->sc_tag, 0); + if ((err = iic_exec(tag, I2C_OP_READ_WITH_STOP, +
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Fri Apr 24 12:38:31 UTC 2020 Modified Files: src/sys/dev/i2c: files.i2c Added Files: src/sys/dev/i2c: asms.c Log Message: a very preliminary driver for the acclerometer found in later *Books register definitions from OpenBSD To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/sys/dev/i2c/asms.c cvs rdiff -u -r1.110 -r1.111 src/sys/dev/i2c/files.i2c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/files.i2c diff -u src/sys/dev/i2c/files.i2c:1.110 src/sys/dev/i2c/files.i2c:1.111 --- src/sys/dev/i2c/files.i2c:1.110 Sun Feb 2 06:41:27 2020 +++ src/sys/dev/i2c/files.i2c Fri Apr 24 12:38:31 2020 @@ -1,4 +1,4 @@ -# $NetBSD: files.i2c,v 1.110 2020/02/02 06:41:27 macallan Exp $ +# $NetBSD: files.i2c,v 1.111 2020/04/24 12:38:31 macallan Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } @@ -311,6 +311,11 @@ device adadc: sysmon_envsys attach adadc at iic file dev/i2c/adadc.cadadc +# Apple Sudden Motion Sensor +device asms: sysmon_envsys +attach asms at iic +file dev/i2c/asms.casms + # HID over i2c # HID "bus" define ihidbus {[ reportid = -1 ]} Added files: Index: src/sys/dev/i2c/asms.c diff -u /dev/null src/sys/dev/i2c/asms.c:1.1 --- /dev/null Fri Apr 24 12:38:31 2020 +++ src/sys/dev/i2c/asms.c Fri Apr 24 12:38:31 2020 @@ -0,0 +1,200 @@ +/* $NetBSD: asms.c,v 1.1 2020/04/24 12:38:31 macallan Exp $ */ + +/*- + * Copyright (c) 2020 Michael Lorenz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: asms.c,v 1.1 2020/04/24 12:38:31 macallan Exp $"); + +#include +#include +#include +#include +#include + +#include + +#include + +struct asms_softc { + device_t sc_dev; + i2c_tag_t sc_i2c; + i2c_addr_t sc_addr; + + struct sysmon_envsys *sc_sme; + envsys_data_t sc_sensors[3]; +}; + +static int asms_match(device_t, cfdata_t, void *); +static void asms_attach(device_t, device_t, void *); + +static void asms_sensors_refresh(struct sysmon_envsys *, envsys_data_t *); +static void asms_init(struct asms_softc *); + +CFATTACH_DECL_NEW(asms, sizeof(struct asms_softc), +asms_match, asms_attach, NULL, NULL); + +static const struct device_compatible_entry compat_data[] = { + { "accelerometer", 0 }, + { "AAPL,accelerometer_1", 0 }, + { NULL,0 } +}; + +/* ASMS Registers, from OpenBSD */ +#define ASMS_REG_COMMAND 0x00 +#define ASMS_REG_STATUS 0x01 +#define ASMS_REG_RCONTROL1 0x02 +#define ASMS_REG_RCONTROL2 0x03 +#define ASMS_REG_RCONTROL3 0x04 +#define ASMS_REG_RDATA1 0x05 +#define ASMS_REG_RDATA2 0x06 +#define ASMS_REG_DATA_X 0x20 +#define ASMS_REG_DATA_Y 0x21 +#define ASMS_REG_DATA_Z 0x22 +#define ASMS_REG_SENS_LOW 0x26 /* init with 0x15 */ +#define ASMS_REG_SENS_HIGH 0x27 /* init with 0x60 */ +#define ASMS_REG_CONTROL_X 0x28 /* init with 0x08 */ +#define ASMS_REG_CONTROL_Y 0x29 /* init with 0x0f */ +#define ASMS_REG_CONTROL_Z 0x2a /* init with 0x4f */ +#define ASMS_REG_UNKNOWN1 0x2b /* init with 0x14 */ +#define ASMS_REG_VENDOR 0x2e +#define ASMS_CMD_READ_VER 0x01 +#define ASMS_CMD_READ_MEM 0x02 +#define ASMS_CMD_RESET 0x07 +#define ASMS_CMD_START 0x08 + +static int +asms_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, compat_data, _result)) + return match_result; + + if ((ia->ia_addr & 0xf8) == 0xd8) + return I2C_MATCH_ADDRESS_ONLY; + + return 0; +} + +static void +asms_attach(device_t parent, device_t self, void *aux) +{ + struct asms_softc *sc =
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sun Apr 19 17:08:14 UTC 2020 Modified Files: src/sys/dev/i2c: i2c_exec.c Log Message: In iic_acquire_bus(), unlock the bus lock if the back-end returns an error from its acquire-bus function. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/sys/dev/i2c/i2c_exec.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/dev/i2c/i2c_exec.c diff -u src/sys/dev/i2c/i2c_exec.c:1.15 src/sys/dev/i2c/i2c_exec.c:1.16 --- src/sys/dev/i2c/i2c_exec.c:1.15 Thu Jan 2 16:18:37 2020 +++ src/sys/dev/i2c/i2c_exec.c Sun Apr 19 17:08:14 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c_exec.c,v 1.15 2020/01/02 16:18:37 thorpej Exp $ */ +/* $NetBSD: i2c_exec.c,v 1.16 2020/04/19 17:08:14 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: i2c_exec.c,v 1.15 2020/01/02 16:18:37 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c_exec.c,v 1.16 2020/04/19 17:08:14 thorpej Exp $"); #include #include @@ -141,6 +141,10 @@ iic_acquire_bus(i2c_tag_t tag, int flags error = (*tag->ic_acquire_bus)(tag->ic_cookie, flags); } + if (__predict_false(error)) { + mutex_exit(>ic_bus_lock); + } + return error; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Fri Feb 28 13:18:25 UTC 2020 Modified Files: src/sys/dev/i2c: dstemp.c Log Message: - document the config register - do some setup and send a start command - mark the sensor as invalid if readings are out of range now this works properly on my PCI-X G5 To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/dstemp.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/dev/i2c/dstemp.c diff -u src/sys/dev/i2c/dstemp.c:1.4 src/sys/dev/i2c/dstemp.c:1.5 --- src/sys/dev/i2c/dstemp.c:1.4 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/dstemp.c Fri Feb 28 13:18:25 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: dstemp.c,v 1.4 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: dstemp.c,v 1.5 2020/02/28 13:18:25 macallan Exp $ */ /*- * Copyright (c) 2018 Michael Lorenz @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.4 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.5 2020/02/28 13:18:25 macallan Exp $"); #include #include @@ -55,6 +55,18 @@ __KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1 #define DSTEMP_TLOW 0xa2 /* low threshold, 2 bytes */ #define DSTEMP_CONFIG 0xac /* 1 byte */ +#define DSTEMP_1SHOT 0x01 +#define DSTEMP_POL 0x02 /* Tout polarity, 1 - active high */ +#define DSTEMP_8BIT 0x00 +#define DSTEMP_10BIT 0x04 +#define DSTEMP_11BIT 0x08 +#define DSTEMP_12BIT 0x0c +#define DSTEMP_RES_MASK 0x0c +#define DSTEMP_NVB 0x10 /* EEPROM busy */ +#define DSTEMP_TLF 0x20 /* temperature low flag */ +#define DSTEMP_THF 0x40 /* temperature high flag */ +#define DSTEMP_DONE 0x80 + struct dstemp_softc { device_t sc_dev; i2c_tag_t sc_i2c; @@ -68,6 +80,7 @@ static int dstemp_match(device_t, cfdata static void dstemp_attach(device_t, device_t, void *); static void dstemp_sensors_refresh(struct sysmon_envsys *, envsys_data_t *); +static void dstemp_init(struct dstemp_softc *); CFATTACH_DECL_NEW(dstemp, sizeof(struct dstemp_softc), dstemp_match, dstemp_attach, NULL, NULL); @@ -106,6 +119,8 @@ dstemp_attach(device_t parent, device_t aprint_naive("\n"); aprint_normal(": DS1361\n"); + dstemp_init(sc); + sc->sc_sme = sysmon_envsys_create(); sc->sc_sme->sme_name = device_xname(self); sc->sc_sme->sme_cookie = sc; @@ -128,6 +143,29 @@ dstemp_attach(device_t parent, device_t } static void +dstemp_init(struct dstemp_softc *sc) +{ + int error; + uint8_t cmd[2], data; + + iic_acquire_bus(sc->sc_i2c, 0); + cmd[0] = DSTEMP_CONFIG; + data = 0; + error = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, + sc->sc_addr, cmd, 1, , 1, 0); + /* we don't want to change the POL bit, so preserve it */ + cmd[1] = (data & DSTEMP_POL) | DSTEMP_12BIT; + error |= iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, + sc->sc_addr, cmd, 2, NULL, 0, 0); + /* ... and start converting */ + cmd[0] = DSTEMP_CMD_START; + error |= iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, + sc->sc_addr, cmd, 1, NULL, 0, 0); + if (error) aprint_error_dev(sc->sc_dev, "chip initialization failed\n"); + iic_release_bus(sc->sc_i2c, 0); +} + +static void dstemp_sensors_refresh(struct sysmon_envsys *sme, envsys_data_t *edata) { struct dstemp_softc *sc = sme->sme_cookie; @@ -145,8 +183,11 @@ dstemp_sensors_refresh(struct sysmon_env edata->state = ENVSYS_SINVALID; } else { edata->value_cur = - ((uint64_t)(data>>4) * 62500) + + ((uint64_t)(be16toh(data) >> 4) * 62500) + + 27315; - edata->state = ENVSYS_SVALID; + if (edata->value_cur > (27315 + 12000)) { + edata->state = ENVSYS_SINVALID; + } else + edata->state = ENVSYS_SVALID; } }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sun Feb 16 22:43:27 UTC 2020 Modified Files: src/sys/dev/i2c: axp20x.c Removed Files: src/sys/dev/i2c: axp20xvar.h Log Message: - Don't use I2C_F_POLL. - G/C the non-FDT entry points; nothing uses them anymore. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/sys/dev/i2c/axp20x.c cvs rdiff -u -r1.3 -r0 src/sys/dev/i2c/axp20xvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/axp20x.c diff -u src/sys/dev/i2c/axp20x.c:1.15 src/sys/dev/i2c/axp20x.c:1.16 --- src/sys/dev/i2c/axp20x.c:1.15 Mon Dec 23 19:12:22 2019 +++ src/sys/dev/i2c/axp20x.c Sun Feb 16 22:43:27 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: axp20x.c,v 1.15 2019/12/23 19:12:22 thorpej Exp $ */ +/* $NetBSD: axp20x.c,v 1.16 2020/02/16 22:43:27 thorpej Exp $ */ /*- * Copyright (c) 2014-2017 Jared McNeill @@ -26,10 +26,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "opt_fdt.h" - #include -__KERNEL_RCSID(0, "$NetBSD: axp20x.c,v 1.15 2019/12/23 19:12:22 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axp20x.c,v 1.16 2020/02/16 22:43:27 thorpej Exp $"); #include #include @@ -39,13 +37,13 @@ __KERNEL_RCSID(0, "$NetBSD: axp20x.c,v 1 #include #include -#include #include -#ifdef FDT #include -#endif + +#define AXP20X_DCDC22 +#define AXP20X_DCDC33 #define AXP209_I2C_ADDR 0x34 @@ -204,12 +202,10 @@ static int axp20x_match(device_t, cfdata static void axp20x_attach(device_t, device_t, void *); static void axp20x_sensors_refresh(struct sysmon_envsys *, envsys_data_t *); -static int axp20x_read(struct axp20x_softc *, uint8_t, uint8_t *, size_t, int); -static int axp20x_write(struct axp20x_softc *, uint8_t, uint8_t *, size_t, int); +static int axp20x_read(struct axp20x_softc *, uint8_t, uint8_t *, size_t); +static int axp20x_write(struct axp20x_softc *, uint8_t, uint8_t *, size_t); -#ifdef FDT static void axp20x_fdt_attach(struct axp20x_softc *); -#endif CFATTACH_DECL_NEW(axp20x, sizeof(struct axp20x_softc), axp20x_match, axp20x_attach, NULL, NULL); @@ -248,13 +244,13 @@ axp20x_attach(device_t parent, device_t sc->sc_phandle = ia->ia_cookie; error = axp20x_read(sc, AXP_INPUT_STATUS, - >sc_inputstatus, 1, 0); + >sc_inputstatus, 1); if (error) { aprint_error(": can't read status: %d\n", error); return; } error = axp20x_read(sc, AXP_POWER_MODE, - >sc_powermode, 1, 0); + >sc_powermode, 1); if (error) { aprint_error(": can't read power mode: %d\n", error); return; @@ -262,18 +258,18 @@ axp20x_attach(device_t parent, device_t value = AXP_ADC_EN1_ACV | AXP_ADC_EN1_ACI | AXP_ADC_EN1_VBUSV | AXP_ADC_EN1_VBUSI | AXP_ADC_EN1_APSV | AXP_ADC_EN1_TS; if (sc->sc_powermode & AXP_POWER_MODE_BATTOK) value |= AXP_ADC_EN1_BATTV | AXP_ADC_EN1_BATTI; - error = axp20x_write(sc, AXP_ADC_EN1, , 1, 0); + error = axp20x_write(sc, AXP_ADC_EN1, , 1); if (error) { aprint_error(": can't set AXP_ADC_EN1\n"); return; } - error = axp20x_read(sc, AXP_ADC_EN2, , 1, 0); + error = axp20x_read(sc, AXP_ADC_EN2, , 1); if (error) { aprint_error(": can't read AXP_ADC_EN2\n"); return; } value |= AXP_ADC_EN2_TEMP; - error = axp20x_write(sc, AXP_ADC_EN2, , 1, 0); + error = axp20x_write(sc, AXP_ADC_EN2, , 1); if (error) { aprint_error(": can't set AXP_ADC_EN2\n"); return; @@ -381,22 +377,22 @@ axp20x_attach(device_t parent, device_t sysmon_envsys_register(sc->sc_sme); - if (axp20x_read(sc, AXP_DCDC2, , 1, 0) == 0) { + if (axp20x_read(sc, AXP_DCDC2, , 1) == 0) { aprint_verbose_dev(sc->sc_dev, "DCDC2 %dmV\n", (int)(700 + (value & AXP_DCDC2_VOLT_MASK) * 25)); } - if (axp20x_read(sc, AXP_DCDC3, , 1, 0) == 0) { + if (axp20x_read(sc, AXP_DCDC3, , 1) == 0) { aprint_verbose_dev(sc->sc_dev, "DCDC3 %dmV\n", (int)(700 + (value & AXP_DCDC3_VOLT_MASK) * 25)); } - if (axp20x_read(sc, AXP_LDO2_4, , 1, 0) == 0) { + if (axp20x_read(sc, AXP_LDO2_4, , 1) == 0) { aprint_verbose_dev(sc->sc_dev, "LDO2 %dmV, LDO4 %dmV\n", (int)(1800 + ((value & AXP_LDO2_VOLT_MASK) >> AXP_LDO2_VOLT_SHIFT) * 100 ), ldo4_mvV[(value & AXP_LDO4_VOLT_MASK) >> AXP_LDO4_VOLT_SHIFT]); } - if (axp20x_read(sc, AXP_LDO3, , 1, 0) == 0) { + if (axp20x_read(sc, AXP_LDO3, , 1) == 0) { if (value & AXP_LDO3_TRACK) { aprint_verbose_dev(sc->sc_dev, "LDO3: tracking\n"); } else { @@ -405,7 +401,7 @@ axp20x_attach(device_t parent, device_t } } - if (axp20x_read(sc, AXP_BKUP_CTRL, , 1, 0) == 0) { + if (axp20x_read(sc, AXP_BKUP_CTRL, , 1) == 0) { if (value & AXP_BKUP_CTRL_ENABLE) { aprint_verbose_dev(sc->sc_dev, "RTC supercap charger enabled: %dmV at %duA\n", @@ -417,9 +413,7 @@ axp20x_attach(device_t parent, device_t } } -#ifdef FDT axp20x_fdt_attach(sc); -#endif } static void @@ -429,7 +423,7 @@ axp20x_sensors_refresh_volt(struct
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sun Feb 16 20:32:29 UTC 2020 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: Don't access the i2c bus in interrupt context. Instead, mask the interrupt and process it on a work queue. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/sys/dev/i2c/axppmic.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/dev/i2c/axppmic.c diff -u src/sys/dev/i2c/axppmic.c:1.28 src/sys/dev/i2c/axppmic.c:1.29 --- src/sys/dev/i2c/axppmic.c:1.28 Mon Dec 23 14:34:23 2019 +++ src/sys/dev/i2c/axppmic.c Sun Feb 16 20:32:29 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.28 2019/12/23 14:34:23 thorpej Exp $ */ +/* $NetBSD: axppmic.c,v 1.29 2020/02/16 20:32:29 thorpej Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.28 2019/12/23 14:34:23 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.29 2020/02/16 20:32:29 thorpej Exp $"); #include #include @@ -36,6 +36,7 @@ __KERNEL_RCSID(0, "$NetBSD: axppmic.c,v #include #include #include +#include #include @@ -366,6 +367,13 @@ struct axppmic_softc { i2c_addr_t sc_addr; int sc_phandle; + void *sc_ih; + struct workqueue *sc_wq; + + kmutex_t sc_intr_lock; + struct work sc_work; + bool sc_work_scheduled; + const struct axppmic_config *sc_conf; struct sysmon_pswitch sc_smpsw; @@ -481,7 +489,6 @@ axppmic_write(i2c_tag_t tag, i2c_addr_t static int axppmic_set_voltage(i2c_tag_t tag, i2c_addr_t addr, const struct axppmic_ctrl *c, u_int min, u_int max) { - const int flags = 0; u_int vol, reg_val; int nstep, error; uint8_t val; @@ -512,13 +519,13 @@ axppmic_set_voltage(i2c_tag_t tag, i2c_a if (vol > max) return EINVAL; - iic_acquire_bus(tag, flags); - if ((error = axppmic_read(tag, addr, c->c_voltage_reg, , flags)) == 0) { + iic_acquire_bus(tag, 0); + if ((error = axppmic_read(tag, addr, c->c_voltage_reg, , 0)) == 0) { val &= ~c->c_voltage_mask; val |= __SHIFTIN(reg_val, c->c_voltage_mask); - error = axppmic_write(tag, addr, c->c_voltage_reg, val, flags); + error = axppmic_write(tag, addr, c->c_voltage_reg, val, 0); } - iic_release_bus(tag, flags); + iic_release_bus(tag, 0); return error; } @@ -526,16 +533,15 @@ axppmic_set_voltage(i2c_tag_t tag, i2c_a static int axppmic_get_voltage(i2c_tag_t tag, i2c_addr_t addr, const struct axppmic_ctrl *c, u_int *pvol) { - const int flags = 0; int reg_val, error; uint8_t val; if (!c->c_voltage_mask) return EINVAL; - iic_acquire_bus(tag, flags); - error = axppmic_read(tag, addr, c->c_voltage_reg, , flags); - iic_release_bus(tag, flags); + iic_acquire_bus(tag, 0); + error = axppmic_read(tag, addr, c->c_voltage_reg, , 0); + iic_release_bus(tag, 0); if (error) return error; @@ -561,11 +567,11 @@ axppmic_power_poweroff(device_t dev) delay(100); - error = iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); + error = iic_acquire_bus(sc->sc_i2c, 0); if (error == 0) { error = axppmic_write(sc->sc_i2c, sc->sc_addr, - AXP_POWER_DISABLE_REG, AXP_POWER_DISABLE_CTRL, I2C_F_POLL); - iic_release_bus(sc->sc_i2c, I2C_F_POLL); + AXP_POWER_DISABLE_REG, AXP_POWER_DISABLE_CTRL, 0); + iic_release_bus(sc->sc_i2c, 0); } if (error) { device_printf(dev, "WARNING: unable to power off, error %d\n", @@ -590,7 +596,6 @@ axppmic_sensor_update(struct sysmon_envs { struct axppmic_softc *sc = sme->sme_cookie; const struct axppmic_config *c = sc->sc_conf; - const int flags = I2C_F_POLL; uint8_t val, lo, hi; e->state = ENVSYS_SINVALID; @@ -601,19 +606,19 @@ axppmic_sensor_update(struct sysmon_envs switch (e->private) { case AXP_SENSOR_ACIN_PRESENT: - if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_SOURCE_REG, , flags) == 0) { + if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_SOURCE_REG, , 0) == 0) { e->state = ENVSYS_SVALID; e->value_cur = !!(val & AXP_POWER_SOURCE_ACIN_PRESENT); } break; case AXP_SENSOR_VBUS_PRESENT: - if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_SOURCE_REG, , flags) == 0) { + if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_SOURCE_REG, , 0) == 0) { e->state = ENVSYS_SVALID; e->value_cur = !!(val & AXP_POWER_SOURCE_VBUS_PRESENT); } break; case AXP_SENSOR_BATT_PRESENT: - if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_MODE_REG, , flags) == 0) { + if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_MODE_REG, , 0) == 0) { if (val & AXP_POWER_MODE_BATT_VALID) { e->state = ENVSYS_SVALID; e->value_cur = !!(val & AXP_POWER_MODE_BATT_PRESENT); @@ -621,14 +626,14 @@ axppmic_sensor_update(struct sysmon_envs } break; case AXP_SENSOR_BATT_CHARGING: - if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_MODE_REG, , flags) == 0) { + if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_MODE_REG, , 0) ==
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sat Feb 15 23:42:01 UTC 2020 Modified Files: src/sys/dev/i2c: gttwsi_core.c Log Message: Interrupt-driven I/O seems to completely go off the rails, at least on AllWinner implementations of this controller, so force polled mode for now. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/sys/dev/i2c/gttwsi_core.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/dev/i2c/gttwsi_core.c diff -u src/sys/dev/i2c/gttwsi_core.c:1.15 src/sys/dev/i2c/gttwsi_core.c:1.16 --- src/sys/dev/i2c/gttwsi_core.c:1.15 Mon Jan 13 12:53:46 2020 +++ src/sys/dev/i2c/gttwsi_core.c Sat Feb 15 23:42:01 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: gttwsi_core.c,v 1.15 2020/01/13 12:53:46 thorpej Exp $ */ +/* $NetBSD: gttwsi_core.c,v 1.16 2020/02/15 23:42:01 thorpej Exp $ */ /* * Copyright (c) 2008 Eiji Kawauchi. * All rights reserved. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.15 2020/01/13 12:53:46 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.16 2020/02/15 23:42:01 thorpej Exp $"); #include "locators.h" #include @@ -317,6 +317,13 @@ gttwsi_wait(struct gttwsi_softc *sc, uin uint32_t status; int timo, error = 0; + /* + * XXX Interrupt-driven mode seems to be horribly broken, + * XXX at least on AllWinner implementations. Force polled + * XXX mode for now. + */ + flags |= I2C_F_POLL; + DELAY(5); if (!(flags & I2C_F_POLL)) control |= CONTROL_INTEN;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Sun Feb 2 06:43:14 UTC 2020 Modified Files: src/sys/dev/i2c: pcagpio.c Log Message: break long lines To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/pcagpio.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/dev/i2c/pcagpio.c diff -u src/sys/dev/i2c/pcagpio.c:1.2 src/sys/dev/i2c/pcagpio.c:1.3 --- src/sys/dev/i2c/pcagpio.c:1.2 Sun Feb 2 06:41:27 2020 +++ src/sys/dev/i2c/pcagpio.c Sun Feb 2 06:43:14 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: pcagpio.c,v 1.2 2020/02/02 06:41:27 macallan Exp $ */ +/* $NetBSD: pcagpio.c,v 1.3 2020/02/02 06:43:14 macallan Exp $ */ /*- * Copyright (c) 2020 Michael Lorenz @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.2 2020/02/02 06:41:27 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.3 2020/02/02 06:43:14 macallan Exp $"); #include #include @@ -77,7 +77,8 @@ struct pcagpio_softc { static void pcagpio_writereg(struct pcagpio_softc *, int, uint32_t); static uint32_t pcagpio_readreg(struct pcagpio_softc *, int); -static void pcagpio_attach_led(struct pcagpio_softc *, char *, int, int, int); +static void pcagpio_attach_led( + struct pcagpio_softc *, char *, int, int, int); static int pcagpio_get(void *); static void pcagpio_set(void *, int); @@ -172,10 +173,12 @@ pcagpio_attach(device_t parent, device_t for (i = 0; i < prop_array_count(pins); i++) { nptr = NULL; pin = prop_array_get(pins, i); - ok &= prop_dictionary_get_cstring_nocopy(pin, "name", ); + ok &= prop_dictionary_get_cstring_nocopy(pin, "name", + ); strncpy(name, nptr, 31); ok &= prop_dictionary_get_uint32(pin, "pin", ); - ok &= prop_dictionary_get_bool(pin, "active_high", ); + ok &= prop_dictionary_get_bool( + pin, "active_high", ); /* optional default state */ def = -1; prop_dictionary_get_int32(pin, "default_state", ); @@ -244,7 +247,8 @@ pcagpio_attach_led(struct pcagpio_softc l->v_off = act ? 0 : l->mask; led_attach(n, l, pcagpio_get, pcagpio_set); if (def != -1) pcagpio_set(l, def); - DPRINTF("%s: %04x %04x %04x def %d\n", __func__, l->mask, l->v_on, l->v_off, def); + DPRINTF("%s: %04x %04x %04x def %d\n", + __func__, l->mask, l->v_on, l->v_off, def); sc->sc_nleds++; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Sun Feb 2 06:41:27 UTC 2020 Modified Files: src/sys/dev/i2c: files.i2c pcagpio.c Log Message: attach LEDs according to info passed as device properties To generate a diff of this commit: cvs rdiff -u -r1.109 -r1.110 src/sys/dev/i2c/files.i2c cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/pcagpio.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/dev/i2c/files.i2c diff -u src/sys/dev/i2c/files.i2c:1.109 src/sys/dev/i2c/files.i2c:1.110 --- src/sys/dev/i2c/files.i2c:1.109 Wed Jan 29 05:27:05 2020 +++ src/sys/dev/i2c/files.i2c Sun Feb 2 06:41:27 2020 @@ -1,4 +1,4 @@ -# $NetBSD: files.i2c,v 1.109 2020/01/29 05:27:05 macallan Exp $ +# $NetBSD: files.i2c,v 1.110 2020/02/02 06:41:27 macallan Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } @@ -387,6 +387,6 @@ attach cwfg at iic file dev/i2c/cwfg.ccwfg # Philips PCA955x GPIO -device pcagpio +device pcagpio: leds attach pcagpio at iic file dev/i2c/pcagpio.c pcagpio Index: src/sys/dev/i2c/pcagpio.c diff -u src/sys/dev/i2c/pcagpio.c:1.1 src/sys/dev/i2c/pcagpio.c:1.2 --- src/sys/dev/i2c/pcagpio.c:1.1 Wed Jan 29 05:27:05 2020 +++ src/sys/dev/i2c/pcagpio.c Sun Feb 2 06:41:27 2020 @@ -1,7 +1,7 @@ -/* $NetBSD: pcagpio.c,v 1.1 2020/01/29 05:27:05 macallan Exp $ */ +/* $NetBSD: pcagpio.c,v 1.2 2020/02/02 06:41:27 macallan Exp $ */ /*- - * Copyright (c) 2018 Michael Lorenz + * Copyright (c) 2020 Michael Lorenz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.1 2020/01/29 05:27:05 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.2 2020/02/02 06:41:27 macallan Exp $"); #include #include @@ -40,6 +40,13 @@ __KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v #include #include +#include + +#ifdef PCAGPIO_DEBUG +#define DPRINTF printf +#else +#define DPRINTF if (0) printf +#endif /* commands */ #define PCAGPIO_INPUT 0x00 /* line status */ @@ -50,17 +57,29 @@ __KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v static int pcagpio_match(device_t, cfdata_t, void *); static void pcagpio_attach(device_t, device_t, void *); +/* we can only pass one cookie to led_attach() but we need several values... */ +struct pcagpio_led { + void *cookie; + uint32_t mask, v_on, v_off; +}; + struct pcagpio_softc { device_t sc_dev; i2c_tag_t sc_i2c; i2c_addr_t sc_addr; int sc_is_16bit; + uint32_t sc_state; + struct pcagpio_led sc_leds[16]; + int sc_nleds; }; static void pcagpio_writereg(struct pcagpio_softc *, int, uint32_t); static uint32_t pcagpio_readreg(struct pcagpio_softc *, int); +static void pcagpio_attach_led(struct pcagpio_softc *, char *, int, int, int); +static int pcagpio_get(void *); +static void pcagpio_set(void *, int); CFATTACH_DECL_NEW(pcagpio, sizeof(struct pcagpio_softc), pcagpio_match, pcagpio_attach, NULL, NULL); @@ -85,6 +104,7 @@ pcagpio_match(device_t parent, cfdata_t return 0; } +#ifdef PCAGPIO_DEBUG static void printdir(uint32_t val, uint32_t mask, char letter) { @@ -103,6 +123,7 @@ printdir(uint32_t val, uint32_t mask, ch printf("dir: %s\n", flags); printf("lvl: %s\n", bits); } +#endif static void pcagpio_attach(device_t parent, device_t self, void *aux) @@ -110,11 +131,14 @@ pcagpio_attach(device_t parent, device_t struct pcagpio_softc *sc = device_private(self); struct i2c_attach_args *ia = aux; const struct device_compatible_entry *dce; - uint32_t dir, in, out; + prop_dictionary_t dict = device_properties(self); + prop_array_t pins; + prop_dictionary_t pin; sc->sc_dev = self; sc->sc_i2c = ia->ia_tag; sc->sc_addr = ia->ia_addr; + sc->sc_nleds = 0; aprint_naive("\n"); sc->sc_is_16bit = 0; @@ -123,17 +147,43 @@ pcagpio_attach(device_t parent, device_t aprint_normal(": %s\n", sc->sc_is_16bit ? "PCA9555" : "PCA9556"); - if (sc->sc_addr == 0x38) pcagpio_writereg(sc, 1, 0xff & ~0x10); - - dir = pcagpio_readreg(sc, 3); - in = pcagpio_readreg(sc, 0); - out = pcagpio_readreg(sc, 1); + sc->sc_state = pcagpio_readreg(sc, PCAGPIO_OUTPUT); + +#ifdef PCAGPIO_DEBUG + uint32_t dir, in, out; + dir = pcagpio_readreg(sc, PCAGPIO_CONFIG); + in = pcagpio_readreg(sc, PCAGPIO_INPUT); + out = sc->sc_state; out &= ~dir; in &= dir; printdir(in, dir, 'I'); printdir(out, ~dir, 'O'); +#endif + + pins = prop_dictionary_get(dict, "pins"); + if (pins != NULL) { + int i, num, def; + char name[32]; + const char *nptr; + bool ok = TRUE, act; + + for (i = 0; i < prop_array_count(pins); i++) { + nptr = NULL; + pin = prop_array_get(pins, i); + ok &= prop_dictionary_get_cstring_nocopy(pin, "name", ); + strncpy(name, nptr, 31); + ok &= prop_dictionary_get_uint32(pin, "pin", ); + ok &= prop_dictionary_get_bool(pin, "active_high", ); + /* optional default state */ + def =
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Wed Jan 29 05:27:05 UTC 2020 Modified Files: src/sys/dev/i2c: files.i2c Added Files: src/sys/dev/i2c: pcagpio.c Log Message: the beginning of a driver for Philips Semiconductors PCA 9555 and 9556 GPIO controllers, found in Sun Fire v210 and some G5 macs. Only prints configuration and line status so far. To generate a diff of this commit: cvs rdiff -u -r1.108 -r1.109 src/sys/dev/i2c/files.i2c cvs rdiff -u -r0 -r1.1 src/sys/dev/i2c/pcagpio.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/dev/i2c/files.i2c diff -u src/sys/dev/i2c/files.i2c:1.108 src/sys/dev/i2c/files.i2c:1.109 --- src/sys/dev/i2c/files.i2c:1.108 Sun Jan 12 17:48:42 2020 +++ src/sys/dev/i2c/files.i2c Wed Jan 29 05:27:05 2020 @@ -1,4 +1,4 @@ -# $NetBSD: files.i2c,v 1.108 2020/01/12 17:48:42 thorpej Exp $ +# $NetBSD: files.i2c,v 1.109 2020/01/29 05:27:05 macallan Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } @@ -385,3 +385,8 @@ file dev/i2c/es8316ac.c es8316ac device cwfg: sysmon_envsys attach cwfg at iic file dev/i2c/cwfg.ccwfg + +# Philips PCA955x GPIO +device pcagpio +attach pcagpio at iic +file dev/i2c/pcagpio.c pcagpio Added files: Index: src/sys/dev/i2c/pcagpio.c diff -u /dev/null src/sys/dev/i2c/pcagpio.c:1.1 --- /dev/null Wed Jan 29 05:27:05 2020 +++ src/sys/dev/i2c/pcagpio.c Wed Jan 29 05:27:05 2020 @@ -0,0 +1,182 @@ +/* $NetBSD: pcagpio.c,v 1.1 2020/01/29 05:27:05 macallan Exp $ */ + +/*- + * Copyright (c) 2018 Michael Lorenz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * a driver for Philips Semiconductor PCA9555 GPIO controllers + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.1 2020/01/29 05:27:05 macallan Exp $"); + +#include +#include +#include +#include +#include + +#include + +/* commands */ +#define PCAGPIO_INPUT 0x00 /* line status */ +#define PCAGPIO_OUTPUT 0x01 /* output status */ +#define PCAGPIO_REVERT 0x02 /* revert input if set */ +#define PCAGPIO_CONFIG 0x03 /* input if set, output if not */ + +static int pcagpio_match(device_t, cfdata_t, void *); +static void pcagpio_attach(device_t, device_t, void *); + +struct pcagpio_softc { + device_t sc_dev; + i2c_tag_t sc_i2c; + i2c_addr_t sc_addr; + + int sc_is_16bit; +}; + + +static void pcagpio_writereg(struct pcagpio_softc *, int, uint32_t); +static uint32_t pcagpio_readreg(struct pcagpio_softc *, int); + +CFATTACH_DECL_NEW(pcagpio, sizeof(struct pcagpio_softc), +pcagpio_match, pcagpio_attach, NULL, NULL); + +static const struct device_compatible_entry compat_data[] = { + { "i2c-pca9555", 1 }, + { "pca9555", 1 }, + { "i2c-pca9556", 0 }, + { "pca9556", 0 }, + { NULL, 0 } +}; + +static int +pcagpio_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, compat_data, _result)) + return match_result; + + return 0; +} + +static void +printdir(uint32_t val, uint32_t mask, char letter) +{ + char flags[17], bits[17]; + uint32_t bit = 0x8000; + int i; + + val &= mask; + for (i = 0; i < 16; i++) { + flags[i] = (mask & bit) ? letter : '-'; + bits[i] = (val & bit) ? 'X' : ' '; + bit = bit >> 1; + } + flags[16] = 0; + bits[16] = 0; + printf("dir: %s\n", flags); + printf("lvl: %s\n", bits); +} + +static void +pcagpio_attach(device_t parent, device_t self, void *aux) +{ + struct pcagpio_softc *sc = device_private(self); + struct i2c_attach_args *ia = aux; + const struct device_compatible_entry *dce; + uint32_t dir, in, out; + + sc->sc_dev = self; + sc->sc_i2c
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Wed Jan 15 06:09:37 UTC 2020 Modified Files: src/sys/dev/i2c: at24cxx.c Log Message: tsleep -> kpause To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/sys/dev/i2c/at24cxx.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/dev/i2c/at24cxx.c diff -u src/sys/dev/i2c/at24cxx.c:1.35 src/sys/dev/i2c/at24cxx.c:1.36 --- src/sys/dev/i2c/at24cxx.c:1.35 Mon Dec 23 15:51:50 2019 +++ src/sys/dev/i2c/at24cxx.c Wed Jan 15 06:09:36 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: at24cxx.c,v 1.35 2019/12/23 15:51:50 thorpej Exp $ */ +/* $NetBSD: at24cxx.c,v 1.36 2020/01/15 06:09:36 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.35 2019/12/23 15:51:50 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.36 2020/01/15 06:09:36 thorpej Exp $"); #include #include @@ -392,8 +392,8 @@ seeprom_wait_idle(struct seeprom_softc * if (error == 0) break; - rv = tsleep(sc, PRIBIO | PCATCH, "seepromwr", timeout); - if (rv != EWOULDBLOCK) + rv = kpause("seepromwr", true, timeout, NULL); + if (rv != EWOULDBLOCK && rv != 0) return (rv); }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Wed Jan 15 05:56:57 UTC 2020 Modified Files: src/sys/dev/i2c: tsl256x.c Log Message: tsleep -> kpause To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/tsl256x.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/dev/i2c/tsl256x.c diff -u src/sys/dev/i2c/tsl256x.c:1.7 src/sys/dev/i2c/tsl256x.c:1.8 --- src/sys/dev/i2c/tsl256x.c:1.7 Thu Jul 25 04:25:40 2019 +++ src/sys/dev/i2c/tsl256x.c Wed Jan 15 05:56:57 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: tsl256x.c,v 1.7 2019/07/25 04:25:40 thorpej Exp $ */ +/* $NetBSD: tsl256x.c,v 1.8 2020/01/15 05:56:57 thorpej Exp $ */ /*- * Copyright (c) 2018 Jason R. Thorpe @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tsl256x.c,v 1.7 2019/07/25 04:25:40 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tsl256x.c,v 1.8 2020/01/15 05:56:57 thorpej Exp $"); #include #include @@ -652,8 +652,7 @@ tsllux_wait_for_adcs(struct tsllux_softc delay(ms * 1000); } else { /* Round up one tick for the case where we sleep. */ - (void) tsleep(tsllux_wait_for_adcs, PWAIT, "tslluxwait", - mstohz(ms) + 1); + (void) kpause("tslluxwait", false, mstohz(ms) + 1, NULL); } return (0);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Jan 13 12:53:46 UTC 2020 Modified Files: src/sys/dev/i2c: gttwsi_core.c Log Message: Fix silly mistake in rev 1.12. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/sys/dev/i2c/gttwsi_core.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/dev/i2c/gttwsi_core.c diff -u src/sys/dev/i2c/gttwsi_core.c:1.14 src/sys/dev/i2c/gttwsi_core.c:1.15 --- src/sys/dev/i2c/gttwsi_core.c:1.14 Mon Jan 13 09:53:54 2020 +++ src/sys/dev/i2c/gttwsi_core.c Mon Jan 13 12:53:46 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: gttwsi_core.c,v 1.14 2020/01/13 09:53:54 martin Exp $ */ +/* $NetBSD: gttwsi_core.c,v 1.15 2020/01/13 12:53:46 thorpej Exp $ */ /* * Copyright (c) 2008 Eiji Kawauchi. * All rights reserved. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.14 2020/01/13 09:53:54 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.15 2020/01/13 12:53:46 thorpej Exp $"); #include "locators.h" #include @@ -109,7 +109,7 @@ void gttwsi_write_4(struct gttwsi_softc *sc, uint32_t reg, uint32_t val) { - bus_space_write_4(sc->sc_bust, sc->sc_bush, reg, val); + bus_space_write_4(sc->sc_bust, sc->sc_bush, sc->sc_regmap[reg], val); #ifdef TWSI_DEBUG printf("I2C:W:[%" PRIu32 "]%02" PRIxBUSSIZE ":%02" PRIx32 "\n", reg, sc->sc_regmap[reg], val); #else
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: martin Date: Mon Jan 13 09:53:54 UTC 2020 Modified Files: src/sys/dev/i2c: gttwsi_core.c Log Message: Fix debug printf formats. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sys/dev/i2c/gttwsi_core.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/dev/i2c/gttwsi_core.c diff -u src/sys/dev/i2c/gttwsi_core.c:1.13 src/sys/dev/i2c/gttwsi_core.c:1.14 --- src/sys/dev/i2c/gttwsi_core.c:1.13 Mon Jan 13 00:09:28 2020 +++ src/sys/dev/i2c/gttwsi_core.c Mon Jan 13 09:53:54 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: gttwsi_core.c,v 1.13 2020/01/13 00:09:28 thorpej Exp $ */ +/* $NetBSD: gttwsi_core.c,v 1.14 2020/01/13 09:53:54 martin Exp $ */ /* * Copyright (c) 2008 Eiji Kawauchi. * All rights reserved. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.13 2020/01/13 00:09:28 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.14 2020/01/13 09:53:54 martin Exp $"); #include "locators.h" #include @@ -98,7 +98,7 @@ gttwsi_read_4(struct gttwsi_softc *sc, u const uint32_t val = bus_space_read_4(sc->sc_bust, sc->sc_bush, sc->sc_regmap[reg]); #ifdef TWSI_DEBUG - printf("I2C:R:[%u]%02x:%02x\n", reg, sc->sc_regmap[reg], val); + printf("I2C:R:[%" PRIu32 "]%02" PRIxBUSSIZE ":%02" PRIx32 "\n", reg, sc->sc_regmap[reg], val); #else DELAY(TWSI_READ_DELAY); #endif @@ -111,7 +111,7 @@ gttwsi_write_4(struct gttwsi_softc *sc, bus_space_write_4(sc->sc_bust, sc->sc_bush, reg, val); #ifdef TWSI_DEBUG - printf("I2C:W:[%u]%02x:%02x\n", reg, sc->sc_regmap[reg], val); + printf("I2C:W:[%" PRIu32 "]%02" PRIxBUSSIZE ":%02" PRIx32 "\n", reg, sc->sc_regmap[reg], val); #else DELAY(TWSI_WRITE_DELAY); #endif
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Jan 13 00:09:28 UTC 2020 Modified Files: src/sys/dev/i2c: gttwsi_core.c Log Message: Improve diagnostic messages: - Pass an additional argument to gttwsi_wait() to indicate what's going on, and report that, along with the error code from cv_timedwait(), if a timeout occurs. - In gttwsi_send_stop(), if we don't get the expected NRS status, report which status we *did* get when a timeout occurs. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/sys/dev/i2c/gttwsi_core.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/dev/i2c/gttwsi_core.c diff -u src/sys/dev/i2c/gttwsi_core.c:1.12 src/sys/dev/i2c/gttwsi_core.c:1.13 --- src/sys/dev/i2c/gttwsi_core.c:1.12 Sun Jan 12 17:48:42 2020 +++ src/sys/dev/i2c/gttwsi_core.c Mon Jan 13 00:09:28 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: gttwsi_core.c,v 1.12 2020/01/12 17:48:42 thorpej Exp $ */ +/* $NetBSD: gttwsi_core.c,v 1.13 2020/01/13 00:09:28 thorpej Exp $ */ /* * Copyright (c) 2008 Eiji Kawauchi. * All rights reserved. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.12 2020/01/12 17:48:42 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.13 2020/01/13 00:09:28 thorpej Exp $"); #include "locators.h" #include @@ -90,7 +90,7 @@ static int gttwsi_read_byte(void *v, uin static int gttwsi_write_byte(void *v, uint8_t val, int flags); static int gttwsi_wait(struct gttwsi_softc *, uint32_t, uint32_t, - uint32_t, int); + uint32_t, int, const char *); uint32_t gttwsi_read_4(struct gttwsi_softc *sc, uint32_t reg) @@ -195,7 +195,7 @@ gttwsi_send_start(void *v, int flags) else expect = STAT_SCT; sc->sc_started = true; - return gttwsi_wait(sc, CONTROL_START, expect, 0, flags); + return gttwsi_wait(sc, CONTROL_START, expect, 0, flags, "send-start"); } static int @@ -203,7 +203,7 @@ gttwsi_send_stop(void *v, int flags) { struct gttwsi_softc *sc = v; int retry = TWSI_RETRY_COUNT; - uint32_t control; + uint32_t control, status; sc->sc_started = false; @@ -213,14 +213,15 @@ gttwsi_send_stop(void *v, int flags) control |= CONTROL_IFLG; gttwsi_write_4(sc, TWSI_CONTROL, control); while (retry > 0) { - if (gttwsi_read_4(sc, TWSI_STATUS) == STAT_NRS) + if ((status = gttwsi_read_4(sc, TWSI_STATUS)) == STAT_NRS) return 0; retry--; DELAY(TWSI_STAT_DELAY); } - aprint_error_dev(sc->sc_dev, "send STOP failed\n"); - return -1; + aprint_error_dev(sc->sc_dev, "send STOP failed, status=0x%02x\n", + status); + return EWOULDBLOCK; } static int @@ -254,7 +255,7 @@ gttwsi_initiate_xfer(void *v, i2c_addr_t */ data |= 0xf0 | ((addr & 0x300) >> 7); gttwsi_write_4(sc, TWSI_DATA, data); - error = gttwsi_wait(sc, 0, expect, alt, flags); + error = gttwsi_wait(sc, 0, expect, alt, flags, "send-addr-10"); if (error) return error; /* @@ -273,7 +274,7 @@ gttwsi_initiate_xfer(void *v, i2c_addr_t data |= (addr << 1); gttwsi_write_4(sc, TWSI_DATA, data); - return gttwsi_wait(sc, 0, expect, alt, flags); + return gttwsi_wait(sc, 0, expect, alt, flags, "send-addr"); } static int @@ -282,10 +283,13 @@ gttwsi_read_byte(void *v, uint8_t *valp, struct gttwsi_softc *sc = v; int error; - if (flags & I2C_F_LAST) - error = gttwsi_wait(sc, 0, STAT_MRRD_ANT, 0, flags); - else - error = gttwsi_wait(sc, CONTROL_ACK, STAT_MRRD_AT, 0, flags); + if (flags & I2C_F_LAST) { + error = gttwsi_wait(sc, 0, STAT_MRRD_ANT, 0, flags, +"read-last-byte"); + } else { + error = gttwsi_wait(sc, CONTROL_ACK, STAT_MRRD_AT, 0, flags, +"read-byte"); + } if (!error) *valp = gttwsi_read_4(sc, TWSI_DATA); if ((flags & (I2C_F_LAST | I2C_F_STOP)) == (I2C_F_LAST | I2C_F_STOP)) @@ -300,7 +304,7 @@ gttwsi_write_byte(void *v, uint8_t val, int error; gttwsi_write_4(sc, TWSI_DATA, val); - error = gttwsi_wait(sc, 0, STAT_MTDB_AR, 0, flags); + error = gttwsi_wait(sc, 0, STAT_MTDB_AR, 0, flags, "write-byte"); if (flags & I2C_F_STOP) gttwsi_send_stop(sc, flags); return error; @@ -308,7 +312,7 @@ gttwsi_write_byte(void *v, uint8_t val, static int gttwsi_wait(struct gttwsi_softc *sc, uint32_t control, uint32_t expect, - uint32_t alt, int flags) + uint32_t alt, int flags, const char *what) { uint32_t status; int timo, error = 0; @@ -328,8 +332,9 @@ gttwsi_wait(struct gttwsi_softc *sc, uin break; if (!(flags & I2C_F_POLL)) { error = cv_timedwait(>sc_cv, >sc_mtx, hz); - if (error) + if (error) { break; + } } else { DELAY(TWSI_RETRY_DELAY); if (timo++ > 100) /* 1sec */ @@ -337,9 +342,19 @@ gttwsi_wait(struct gttwsi_softc *sc, uin } } if ((control & CONTROL_IFLG) == 0) { + /* + * error is set by the cv_timedwait() call above in the + * non-polled case. + */ + if (flags & I2C_F_POLL) { + error = EWOULDBLOCK; + } else
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sat Jan 11 22:21:26 UTC 2020 Modified Files: src/sys/dev/i2c: gttwsi_core.c Log Message: In gttwsi_wait(), don't use cv_timedwait_sig() -- there's no reason to catch signals here, and the code would need to handle them properly, which this code does not. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sys/dev/i2c/gttwsi_core.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/dev/i2c/gttwsi_core.c diff -u src/sys/dev/i2c/gttwsi_core.c:1.10 src/sys/dev/i2c/gttwsi_core.c:1.11 --- src/sys/dev/i2c/gttwsi_core.c:1.10 Wed Dec 25 14:08:47 2019 +++ src/sys/dev/i2c/gttwsi_core.c Sat Jan 11 22:21:25 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: gttwsi_core.c,v 1.10 2019/12/25 14:08:47 thorpej Exp $ */ +/* $NetBSD: gttwsi_core.c,v 1.11 2020/01/11 22:21:25 thorpej Exp $ */ /* * Copyright (c) 2008 Eiji Kawauchi. * All rights reserved. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.10 2019/12/25 14:08:47 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.11 2020/01/11 22:21:25 thorpej Exp $"); #include "locators.h" #include @@ -342,7 +342,7 @@ gttwsi_wait(struct gttwsi_softc *sc, uin if (control & CONTROL_IFLG) break; if (!(flags & I2C_F_POLL)) { - error = cv_timedwait_sig(>sc_cv, >sc_mtx, hz); + error = cv_timedwait(>sc_cv, >sc_mtx, hz); if (error) break; } else {
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 9 04:04:01 UTC 2020 Modified Files: src/sys/dev/i2c: ihidev.c ihidev.h Log Message: Re-enable the intr / mask / softint / unmask dance now that the x86 interrupt issue is fixed. Verified working by ryoon@ (thanks!). To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sys/dev/i2c/ihidev.c cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/ihidev.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/ihidev.c diff -u src/sys/dev/i2c/ihidev.c:1.11 src/sys/dev/i2c/ihidev.c:1.12 --- src/sys/dev/i2c/ihidev.c:1.11 Wed Dec 25 01:19:56 2019 +++ src/sys/dev/i2c/ihidev.c Thu Jan 9 04:04:01 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.11 2019/12/25 01:19:56 thorpej Exp $ */ +/* $NetBSD: ihidev.c,v 1.12 2020/01/09 04:04:01 thorpej Exp $ */ /* $OpenBSD ihidev.c,v 1.13 2017/04/08 02:57:23 deraadt Exp $ */ /*- @@ -54,7 +54,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.11 2019/12/25 01:19:56 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.12 2020/01/09 04:04:01 thorpej Exp $"); #include #include @@ -71,6 +71,7 @@ __KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1 # include "acpica.h" #endif #if NACPICA > 0 +#include #include #endif @@ -109,10 +110,14 @@ static int ihidev_detach(device_t, int); CFATTACH_DECL_NEW(ihidev, sizeof(struct ihidev_softc), ihidev_match, ihidev_attach, ihidev_detach, NULL); +static bool ihiddev_intr_init(struct ihidev_softc *); +static void ihiddev_intr_fini(struct ihidev_softc *); + static bool ihidev_suspend(device_t, const pmf_qual_t *); static bool ihidev_resume(device_t, const pmf_qual_t *); static int ihidev_hid_command(struct ihidev_softc *, int, void *, bool); static int ihidev_intr(void *); +static void ihidev_softintr(void *); static int ihidev_reset(struct ihidev_softc *, bool); static int ihidev_hid_desc_parse(struct ihidev_softc *); @@ -200,20 +205,9 @@ ihidev_attach(device_t parent, device_t repsz)); } sc->sc_ibuf = kmem_zalloc(sc->sc_isize, KM_SLEEP); -#if NACPICA > 0 - { - char buf[100]; - - sc->sc_ih = acpi_intr_establish(self, sc->sc_phandle, IPL_TTY, - false, ihidev_intr, sc, device_xname(self)); - if (sc->sc_ih == NULL) { - aprint_error_dev(self, "can't establish interrupt\n"); - return; - } - aprint_normal_dev(self, "interrupting at %s\n", - acpi_intr_string(sc->sc_ih, buf, sizeof(buf))); + if (! ihiddev_intr_init(sc)) { + return; } -#endif iha.iaa = ia; iha.parent = sc; @@ -260,10 +254,7 @@ ihidev_detach(device_t self, int flags) struct ihidev_softc *sc = device_private(self); mutex_enter(>sc_intr_lock); -#if NACPICA > 0 - if (sc->sc_ih != NULL) - acpi_intr_disestablish(sc->sc_ih); -#endif + ihiddev_intr_fini(sc); if (ihidev_hid_command(sc, I2C_HID_CMD_SET_POWER, _HID_POWER_OFF, true)) aprint_error_dev(sc->sc_dev, "failed to power down\n"); @@ -649,31 +640,131 @@ ihidev_hid_desc_parse(struct ihidev_soft return (0); } +static bool +ihiddev_intr_init(struct ihidev_softc *sc) +{ +#if NACPICA > 0 + ACPI_HANDLE hdl = (void *)(uintptr_t)sc->sc_phandle; + struct acpi_resources res; + ACPI_STATUS rv; + char buf[100]; + + rv = acpi_resource_parse(sc->sc_dev, hdl, "_CRS", , + _resource_parse_ops_quiet); + if (ACPI_FAILURE(rv)) { + aprint_error_dev(sc->sc_dev, "can't parse '_CRS'\n"); + return false; + } + + const struct acpi_irq * const irq = acpi_res_irq(, 0); + if (irq == NULL) { + aprint_error_dev(sc->sc_dev, "no IRQ resource\n"); + acpi_resource_cleanup(); + return false; + } + + sc->sc_intr_type = + irq->ar_type == ACPI_EDGE_SENSITIVE ? IST_EDGE : IST_LEVEL; + + acpi_resource_cleanup(); + + sc->sc_ih = acpi_intr_establish(sc->sc_dev, sc->sc_phandle, IPL_TTY, + false, ihidev_intr, sc, device_xname(sc->sc_dev)); + if (sc->sc_ih == NULL) { + aprint_error_dev(sc->sc_dev, "can't establish interrupt\n"); + return false; + } + aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", + acpi_intr_string(sc->sc_ih, buf, sizeof(buf))); + + sc->sc_sih = softint_establish(SOFTINT_SERIAL, ihidev_softintr, sc); + if (sc->sc_sih == NULL) { + aprint_error_dev(sc->sc_dev, + "can't establish soft interrupt\n"); + return false; + } + + return true; +#else + aprint_error_dev(sc->sc_dev, "can't establish interrupt\n"); + return false; +#endif +} + +static void +ihiddev_intr_fini(struct ihidev_softc *sc) +{ +#if NACPICA > 0 + if (sc->sc_ih != NULL) { + acpi_intr_disestablish(sc->sc_ih); + } + if (sc->sc_sih != NULL) { + softint_disestablish(sc->sc_sih); + } +#endif +} + +static void +ihidev_intr_mask(struct ihidev_softc * const sc) +{ + + if (sc->sc_intr_type == IST_LEVEL) { +#if NACPICA > 0 + acpi_intr_mask(sc->sc_ih); +#endif + } +} + +static void +ihidev_intr_unmask(struct ihidev_softc * const sc) +{ + + if (sc->sc_intr_type == IST_LEVEL) { +#if NACPICA > 0 +
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sat Jan 4 02:21:15 UTC 2020 Modified Files: src/sys/dev/i2c: as3722.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sys/dev/i2c/as3722.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/dev/i2c/as3722.c diff -u src/sys/dev/i2c/as3722.c:1.18 src/sys/dev/i2c/as3722.c:1.19 --- src/sys/dev/i2c/as3722.c:1.18 Mon Dec 23 15:48:51 2019 +++ src/sys/dev/i2c/as3722.c Sat Jan 4 02:21:15 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: as3722.c,v 1.18 2019/12/23 15:48:51 thorpej Exp $ */ +/* $NetBSD: as3722.c,v 1.19 2020/01/04 02:21:15 thorpej Exp $ */ /*- * Copyright (c) 2015 Jared D. McNeill @@ -29,7 +29,7 @@ #include "opt_fdt.h" #include -__KERNEL_RCSID(0, "$NetBSD: as3722.c,v 1.18 2019/12/23 15:48:51 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: as3722.c,v 1.19 2020/01/04 02:21:15 thorpej Exp $"); #include #include @@ -850,13 +850,11 @@ as3722_poweroff(device_t dev) struct as3722_softc * const sc = device_private(dev); int error; - const int flags = I2C_F_POLL; - - error = iic_acquire_bus(sc->sc_i2c, flags); + error = iic_acquire_bus(sc->sc_i2c, 0); if (error == 0) { error = as3722_write(sc, AS3722_RESET_CTRL_REG, - AS3722_RESET_CTRL_POWER_OFF, flags); - iic_release_bus(sc->sc_i2c, flags); + AS3722_RESET_CTRL_POWER_OFF, 0); + iic_release_bus(sc->sc_i2c, 0); } if (error) { device_printf(dev, "WARNING: unable to power off, error %d\n", @@ -872,13 +870,11 @@ as3722_reboot(device_t dev) struct as3722_softc * const sc = device_private(dev); int error; - const int flags = I2C_F_POLL; - - error = iic_acquire_bus(sc->sc_i2c, flags); + error = iic_acquire_bus(sc->sc_i2c, 0); if (error == 0) { error = as3722_write(sc, AS3722_RESET_CTRL_REG, - AS3722_RESET_CTRL_FORCE_RESET, flags); - iic_release_bus(sc->sc_i2c, flags); + AS3722_RESET_CTRL_FORCE_RESET, 0); + iic_release_bus(sc->sc_i2c, 0); } if (error) { device_printf(dev, "WARNING: unable to reboot, error %d\n",
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Fri Jan 3 18:00:05 UTC 2020 Modified Files: src/sys/dev/i2c: files.i2c Added Files: src/sys/dev/i2c: cwfg.c Log Message: Add driver for CellWise CW2015 Fuel Gauge IC. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/sys/dev/i2c/cwfg.c cvs rdiff -u -r1.106 -r1.107 src/sys/dev/i2c/files.i2c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/files.i2c diff -u src/sys/dev/i2c/files.i2c:1.106 src/sys/dev/i2c/files.i2c:1.107 --- src/sys/dev/i2c/files.i2c:1.106 Fri Jan 3 03:44:42 2020 +++ src/sys/dev/i2c/files.i2c Fri Jan 3 18:00:05 2020 @@ -1,4 +1,4 @@ -# $NetBSD: files.i2c,v 1.106 2020/01/03 03:44:42 thorpej Exp $ +# $NetBSD: files.i2c,v 1.107 2020/01/03 18:00:05 jmcneill Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } @@ -381,3 +381,8 @@ file dev/i2c/tda19988.c tdahdmi device es8316ac attach es8316ac at iic file dev/i2c/es8316ac.c es8316ac + +# CellWise CW2015 Fuel Gauge IC +device cwfg: sysmon_envsys +attach cwfg at iic +file dev/i2c/cwfg.ccwfg Added files: Index: src/sys/dev/i2c/cwfg.c diff -u /dev/null src/sys/dev/i2c/cwfg.c:1.1 --- /dev/null Fri Jan 3 18:00:05 2020 +++ src/sys/dev/i2c/cwfg.c Fri Jan 3 18:00:05 2020 @@ -0,0 +1,449 @@ +/* $NetBSD: cwfg.c,v 1.1 2020/01/03 18:00:05 jmcneill Exp $ */ + +/*- + * Copyright (c) 2020 Jared McNeill + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: cwfg.c,v 1.1 2020/01/03 18:00:05 jmcneill Exp $"); + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include + +#define VERSION_REG 0x00 +#define VCELL_HI_REG 0x02 +#define VCELL_HI __BITS(5,0) +#define VCELL_LO_REG 0x03 +#define VCELL_LO __BITS(7,0) +#define SOC_HI_REG 0x04 +#define SOC_LO_REG 0x05 +#define RTT_ALRT_HI_REG 0x06 +#define RTT_ALRT __BIT(7) +#define RTT_HI __BITS(4,0) +#define RTT_ALRT_LO_REG 0x07 +#define RTT_LO __BITS(7,0) +#define CONFIG_REG 0x08 +#define CONFIG_ATHD __BITS(7,3) +#define CONFIG_UFG __BIT(1) +#define MODE_REG 0x0a +#define MODE_SLEEP __BITS(7,6) +#define MODE_SLEEP_WAKE 0x0 +#define MODE_SLEEP_SLEEP 0x3 +#define MODE_QSTRT __BITS(5,4) +#define MODE_POR __BITS(3,0) +#define BATINFO_REG(n) (0x10 + (n)) + +#define VCELL_STEP 312 +#define VCELL_DIV 1024 +#define BATINFO_SIZE 64 +#define RESET_COUNT 30 +#define RESET_DELAY 10 + +enum cwfg_sensor { + CWFG_SENSOR_VCELL, + CWFG_SENSOR_SOC, + CWFG_SENSOR_RTT, + CWFG_NSENSORS +}; + +struct cwfg_softc { + device_t sc_dev; + i2c_tag_t sc_i2c; + i2c_addr_t sc_addr; + int sc_phandle; + + uint8_t sc_batinfo[BATINFO_SIZE]; + + u_int sc_alert_level; + u_int sc_monitor_interval; + u_int sc_design_capacity; + + struct sysmon_envsys *sc_sme; + + envsys_data_t sc_sensor[CWFG_NSENSORS]; +}; + +#define CWFG_MONITOR_INTERVAL_DEFAULT 8 +#define CWFG_DESIGN_CAPACITY_DEFAULT 2000 +#define CWFG_ALERT_LEVEL_DEFAULT 0 + +static const struct device_compatible_entry compat_data[] = { + { "cellwise,cw201x", 1 }, + { NULL,0 } +}; + +static int +cwfg_lock(struct cwfg_softc *sc) +{ + return iic_acquire_bus(sc->sc_i2c, 0); +} + +static void +cwfg_unlock(struct cwfg_softc *sc) +{ + iic_release_bus(sc->sc_i2c, 0); +} + +static int +cwfg_read(struct cwfg_softc *sc, uint8_t reg, uint8_t *val) +{ + return iic_smbus_read_byte(sc->sc_i2c, sc->sc_addr, reg, val, 0); +} + +static int +cwfg_write(struct cwfg_softc *sc, uint8_t reg, uint8_t val) +{ + return iic_smbus_write_byte(sc->sc_i2c, sc->sc_addr, reg, val, 0); +} + +static
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Fri Jan 3 01:17:29 UTC 2020 Modified Files: src/sys/dev/i2c: rkpmic.c Log Message: If the rockchip,system-power-controller property is present, try to power off with the PMIC To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/rkpmic.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/dev/i2c/rkpmic.c diff -u src/sys/dev/i2c/rkpmic.c:1.7 src/sys/dev/i2c/rkpmic.c:1.8 --- src/sys/dev/i2c/rkpmic.c:1.7 Thu Jan 2 17:09:59 2020 +++ src/sys/dev/i2c/rkpmic.c Fri Jan 3 01:17:29 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: rkpmic.c,v 1.7 2020/01/02 17:09:59 thorpej Exp $ */ +/* $NetBSD: rkpmic.c,v 1.8 2020/01/03 01:17:29 jmcneill Exp $ */ /*- * Copyright (c) 2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rkpmic.c,v 1.7 2020/01/02 17:09:59 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rkpmic.c,v 1.8 2020/01/03 01:17:29 jmcneill Exp $"); #include #include @@ -72,6 +72,9 @@ __KERNEL_RCSID(0, "$NetBSD: rkpmic.c,v 1 #define CLK32OUT_REG 0x20 #define CLK32OUT_CLKOUT2_EN __BIT(0) +#define DEVCTRL_REG 0x4b +#define DEVCTRL_DEV_OFF_RST __BIT(3) + struct rkpmic_ctrl { const char * name; uint8_t enable_reg; @@ -88,6 +91,9 @@ struct rkpmic_config { const char * name; const struct rkpmic_ctrl *ctrl; u_int nctrl; + + u_int poweroff_reg; + u_int poweroff_mask; }; static const struct rkpmic_ctrl rk805_ctrls[] = { @@ -190,6 +196,8 @@ static const struct rkpmic_config rk808_ .name = "RK808", .ctrl = rk808_ctrls, .nctrl = __arraycount(rk808_ctrls), + .poweroff_reg = DEVCTRL_REG, + .poweroff_mask = DEVCTRL_DEV_OFF_RST, }; struct rkpmic_softc; @@ -417,6 +425,25 @@ static const struct clk_funcs rkpmic_clk .disable = rkpmic_clk_disable, }; +static void +rkpmic_power_poweroff(device_t dev) +{ + struct rkpmic_softc * const sc = device_private(dev); + uint8_t val; + + delay(100); + + I2C_LOCK(sc); + val = I2C_READ(sc, sc->sc_conf->poweroff_reg); + val |= sc->sc_conf->poweroff_mask; + I2C_WRITE(sc, sc->sc_conf->poweroff_reg, val); + I2C_UNLOCK(sc); +} + +static struct fdtbus_power_controller_func rkpmic_power_funcs = { + .poweroff = rkpmic_power_poweroff, +}; + static int rkpmic_match(device_t parent, cfdata_t match, void *aux) { @@ -482,6 +509,11 @@ rkpmic_attach(device_t parent, device_t fdtbus_register_clock_controller(self, sc->sc_phandle, _clk_fdt_funcs); + if (of_hasprop(sc->sc_phandle, "rockchip,system-power-controller") && + sc->sc_conf->poweroff_mask != 0) + fdtbus_register_power_controller(self, sc->sc_phandle, + _power_funcs); + regulators = of_find_firstchild_byname(sc->sc_phandle, "regulators"); if (regulators < 0) return;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Fri Jan 3 01:00:09 UTC 2020 Modified Files: src/sys/dev/i2c: es8316ac.c Log Message: Avoid sleeping while the audio intr lock is held. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/es8316ac.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/dev/i2c/es8316ac.c diff -u src/sys/dev/i2c/es8316ac.c:1.1 src/sys/dev/i2c/es8316ac.c:1.2 --- src/sys/dev/i2c/es8316ac.c:1.1 Thu Jan 2 22:06:59 2020 +++ src/sys/dev/i2c/es8316ac.c Fri Jan 3 01:00:08 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: es8316ac.c,v 1.1 2020/01/02 22:06:59 jmcneill Exp $ */ +/* $NetBSD: es8316ac.c,v 1.2 2020/01/03 01:00:08 jmcneill Exp $ */ /*- * Copyright (c) 2020 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: es8316ac.c,v 1.1 2020/01/02 22:06:59 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: es8316ac.c,v 1.2 2020/01/03 01:00:08 jmcneill Exp $"); #include #include @@ -137,7 +137,7 @@ escodec_read(struct escodec_softc *sc, u { uint8_t val; - if (iic_smbus_read_byte(sc->sc_i2c, sc->sc_addr, reg, , I2C_F_POLL) != 0) + if (iic_smbus_read_byte(sc->sc_i2c, sc->sc_addr, reg, , 0) != 0) val = 0xff; return val; @@ -146,7 +146,7 @@ escodec_read(struct escodec_softc *sc, u static void escodec_write(struct escodec_softc *sc, uint8_t reg, uint8_t val) { - (void)iic_smbus_write_byte(sc->sc_i2c, sc->sc_addr, reg, val, I2C_F_POLL); + (void)iic_smbus_write_byte(sc->sc_i2c, sc->sc_addr, reg, val, 0); } enum escodec_mixer_ctrl { @@ -322,40 +322,6 @@ escodec_get_mixer(u_int index) } static int -escodec_trigger_output(void *priv, void *start, void *end, int blksize, -void (*intr)(void *), void *intarg, const audio_params_t *params) -{ - struct escodec_softc * const sc = priv; - uint8_t val; - - escodec_lock(sc); - - /* Enable HP output */ - val = HPOUTEN_EN_HPL | HPOUTEN_EN_HPR | - HPOUTEN_HPL_OUTEN | HPOUTEN_HPR_OUTEN; - escodec_write(sc, ESCODEC_HPOUTEN_REG, val); - - escodec_unlock(sc); - - return 0; -} - -static int -escodec_halt_output(void *priv) -{ - struct escodec_softc * const sc = priv; - - escodec_lock(sc); - - /* Disable HP output */ - escodec_write(sc, ESCODEC_HPOUTEN_REG, 0); - - escodec_unlock(sc); - - return 0; -} - -static int escodec_set_format(void *priv, int setmode, const audio_params_t *play, const audio_params_t *rec, audio_filter_reg_t *pfil, audio_filter_reg_t *rfil) @@ -514,8 +480,6 @@ escodec_query_devinfo(void *priv, mixer_ } static const struct audio_hw_if escodec_hw_if = { - .trigger_output = escodec_trigger_output, - .halt_output = escodec_halt_output, .set_format = escodec_set_format, .set_port = escodec_set_port, .get_port = escodec_get_port, @@ -699,6 +663,11 @@ escodec_init(struct escodec_softc *sc) escodec_write(sc, ESCODEC_DACVOL_L_REG, 0); escodec_write(sc, ESCODEC_DACVOL_R_REG, 0); + /* Enable HP output */ + val = HPOUTEN_EN_HPL | HPOUTEN_EN_HPR | + HPOUTEN_HPL_OUTEN | HPOUTEN_HPR_OUTEN; + escodec_write(sc, ESCODEC_HPOUTEN_REG, val); + escodec_unlock(sc); }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Thu Jan 2 22:06:59 UTC 2020 Modified Files: src/sys/dev/i2c: files.i2c Added Files: src/sys/dev/i2c: es8316ac.c Log Message: Add driver for Everest Semi ES8316 Low Power Audio CODEC To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/sys/dev/i2c/es8316ac.c cvs rdiff -u -r1.104 -r1.105 src/sys/dev/i2c/files.i2c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/files.i2c diff -u src/sys/dev/i2c/files.i2c:1.104 src/sys/dev/i2c/files.i2c:1.105 --- src/sys/dev/i2c/files.i2c:1.104 Sun Nov 3 22:57:52 2019 +++ src/sys/dev/i2c/files.i2c Thu Jan 2 22:06:59 2020 @@ -1,4 +1,4 @@ -# $NetBSD: files.i2c,v 1.104 2019/11/03 22:57:52 jmcneill Exp $ +# $NetBSD: files.i2c,v 1.105 2020/01/02 22:06:59 jmcneill Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } @@ -378,3 +378,8 @@ file dev/i2c/twl4030.c twl device tdahdmi: edid, videomode, drmkms, drmkms_i2c attach tdahdmi at iic file dev/i2c/tda19988.c tdahdmi + +# Everest Semi ES8316 Low Power Audio CODEC +device es8316ac +attach es8316ac at iic +file dev/i2c/es8316ac.c es8316ac Added files: Index: src/sys/dev/i2c/es8316ac.c diff -u /dev/null src/sys/dev/i2c/es8316ac.c:1.1 --- /dev/null Thu Jan 2 22:06:59 2020 +++ src/sys/dev/i2c/es8316ac.c Thu Jan 2 22:06:59 2020 @@ -0,0 +1,753 @@ +/* $NetBSD: es8316ac.c,v 1.1 2020/01/02 22:06:59 jmcneill Exp $ */ + +/*- + * Copyright (c) 2020 Jared McNeill + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: es8316ac.c,v 1.1 2020/01/02 22:06:59 jmcneill Exp $"); + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include + +#define ESCODEC_RESET_REG 0x00 +#define RESET_ALL __BITS(5,0) +#define RESET_CSM_ON __BIT(7) +#define ESCODEC_CLKMAN1_REG 0x01 +#define CLKMAN1_MCLK_ON __BIT(6) +#define CLKMAN1_BCLK_ON __BIT(5) +#define CLKMAN1_CLK_CP_ON __BIT(4) +#define CLKMAN1_CLK_DAC_ON __BIT(2) +#define CLKMAN1_ANACLK_DAC_ON __BIT(0) +#define ESCODEC_ADC_OSR_REG 0x03 +#define ESCODEC_SD_CLK_REG 0x09 +#define SD_CLK_MSC __BIT(7) +#define SD_CLK_BCLK_INV __BIT(5) +#define ESCODEC_SD_ADC_REG 0x0a +#define ESCODEC_SD_DAC_REG 0x0b +#define SD_FMT_LRP __BIT(5) +#define SD_FMT_WL __BITS(4,2) +#define SD_FMT_WL_16 3 +#define SD_FMT_MASK __BITS(1,0) +#define SD_FMT_I2S 0 +#define ESCODEC_VMID_REG 0x0c +#define ESCODEC_PDN_REG 0x0d +#define ESCODEC_HPSEL_REG 0x13 +#define ESCODEC_HPMIXRT_REG 0x14 +#define HPMIXRT_LD2LHPMIX __BIT(7) +#define HPMIXRT_RD2RHPMIX __BIT(3) +#define ESCODEC_HPMIX_REG 0x15 +#define HPMIX_LHPMIX_MUTE __BIT(5) +#define HPMIX_PDN_LHP_MIX __BIT(4) +#define HPMIX_RHPMIX_MUTE __BIT(1) +#define HPMIX_PDN_RHP_MIX __BIT(0) +#define ESCODEC_HPMIXVOL_REG 0x16 +#define HPMIXVOL_LHPMIXVOL __BITS(7,4) +#define HPMIXVOL_RHPMIXVOL __BITS(3,0) +#define ESCODEC_HPOUTEN_REG 0x17 +#define HPOUTEN_EN_HPL __BIT(6) +#define HPOUTEN_HPL_OUTEN __BIT(5) +#define HPOUTEN_EN_HPR __BIT(2) +#define HPOUTEN_HPR_OUTEN __BIT(1) +#define ESCODEC_HPVOL_REG 0x18 +#define HPVOL_PDN_LICAL __BIT(7) +#define HPVOL_HPLVOL __BITS(5,4) +#define HPVOL_PDN_RICAL __BIT(3) +#define HPVOL_HPRVOL __BITS(1,0) +#define ESCODEC_HPPWR_REG 0x19 +#define HPPWR_PDN_CPHP __BIT(2) +#define ESCODEC_CPPWR_REG 0x1a +#define CPPWR_PDN_CP __BIT(5) +#define ESCODEC_DACPWR_REG 0x2f +#define DACPWR_PDN_DAC_L __BIT(4) +#define DACPWR_PDN_DAC_R __BIT(0) +#define ESCODEC_DACCTL1_REG 0x30 +#define DACCTL1_MUTE __BIT(5) +#define
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 19:24:48 UTC 2020 Modified Files: src/sys/dev/i2c: m41st84.c Log Message: - Use todr_gettime_ymdhms / todr_settime_ymdhms. - Correctly propagate errors up the stack. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sys/dev/i2c/m41st84.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/dev/i2c/m41st84.c diff -u src/sys/dev/i2c/m41st84.c:1.25 src/sys/dev/i2c/m41st84.c:1.26 --- src/sys/dev/i2c/m41st84.c:1.25 Thu Jan 2 16:28:02 2020 +++ src/sys/dev/i2c/m41st84.c Thu Jan 2 19:24:48 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: m41st84.c,v 1.25 2020/01/02 16:28:02 thorpej Exp $ */ +/* $NetBSD: m41st84.c,v 1.26 2020/01/02 19:24:48 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: m41st84.c,v 1.25 2020/01/02 16:28:02 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: m41st84.c,v 1.26 2020/01/02 19:24:48 thorpej Exp $"); #include "opt_strtc.h" @@ -93,10 +93,11 @@ const struct cdevsw strtc_cdevsw = { }; #endif -static int strtc_clock_read(struct strtc_softc *, struct clock_ymdhms *); -static int strtc_clock_write(struct strtc_softc *, struct clock_ymdhms *); -static int strtc_gettime(struct todr_chip_handle *, struct timeval *); -static int strtc_settime(struct todr_chip_handle *, struct timeval *); +static int strtc_clock_read(struct strtc_softc *sc, struct clock_ymdhms *); +static int strtc_gettime_ymdhms(struct todr_chip_handle *, +struct clock_ymdhms *); +static int strtc_settime_ymdhms(struct todr_chip_handle *, +struct clock_ymdhms *); static int strtc_match(device_t parent, cfdata_t cf, void *arg) @@ -132,8 +133,10 @@ strtc_attach(device_t parent, device_t s sc->sc_dev = self; sc->sc_open = 0; sc->sc_todr.cookie = sc; - sc->sc_todr.todr_gettime = strtc_gettime; - sc->sc_todr.todr_settime = strtc_settime; + sc->sc_todr.todr_gettime = NULL; + sc->sc_todr.todr_settime = NULL; + sc->sc_todr.todr_gettime_ymdhms = strtc_gettime_ymdhms; + sc->sc_todr.todr_settime_ymdhms = strtc_settime_ymdhms; sc->sc_todr.todr_setwen = NULL; todr_attach(>sc_todr); @@ -249,13 +252,13 @@ strtc_write(dev_t dev, struct uio *uio, #endif /* STRTC_NO_USERRAM */ static int -strtc_gettime(struct todr_chip_handle *ch, struct timeval *tv) +strtc_gettime_ymdhms(struct todr_chip_handle *ch, struct clock_ymdhms *dt) { struct strtc_softc *sc = ch->cookie; - struct clock_ymdhms dt, check; - int retries; + struct clock_ymdhms check; + int retries, error; - memset(, 0, sizeof(dt)); + memset(dt, 0, sizeof(*dt)); memset(, 0, sizeof(check)); /* @@ -264,26 +267,11 @@ strtc_gettime(struct todr_chip_handle *c */ retries = 5; do { - strtc_clock_read(sc, ); - strtc_clock_read(sc, ); - } while (memcmp(, , sizeof(check)) != 0 && --retries); - - tv->tv_sec = clock_ymdhms_to_secs(); - tv->tv_usec = 0; - - return (0); -} - -static int -strtc_settime(struct todr_chip_handle *ch, struct timeval *tv) -{ - struct strtc_softc *sc = ch->cookie; - struct clock_ymdhms dt; - - clock_secs_to_ymdhms(tv->tv_sec, ); - - if (strtc_clock_write(sc, ) == 0) - return (-1); + if ((error = strtc_clock_read(sc, dt)) == 0) + error = strtc_clock_read(sc, ); + if (error) + return error; + } while (memcmp(dt, , sizeof(check)) != 0 && --retries); return (0); } @@ -292,12 +280,12 @@ static int strtc_clock_read(struct strtc_softc *sc, struct clock_ymdhms *dt) { u_int8_t bcd[M41ST84_REG_DATE_BYTES], cmdbuf[2]; - int i; + int i, error; - if (iic_acquire_bus(sc->sc_tag, 0)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, "strtc_clock_read: failed to acquire I2C bus\n"); - return (0); + return (error); } /* @@ -306,21 +294,21 @@ strtc_clock_read(struct strtc_softc *sc, * a chance to run again. */ cmdbuf[0] = M41ST84_REG_AL_HOUR; - if (iic_exec(sc->sc_tag, I2C_OP_READ, sc->sc_address, - cmdbuf, 1, [1], 1, 0)) { + if ((error = iic_exec(sc->sc_tag, I2C_OP_READ, sc->sc_address, + cmdbuf, 1, [1], 1, 0)) != 0) { iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "strtc_clock_read: failed to read HT\n"); - return (0); + return (error); } if (cmdbuf[1] & M41ST84_AL_HOUR_HT) { cmdbuf[1] &= ~M41ST84_AL_HOUR_HT; - if (iic_exec(sc->sc_tag, I2C_OP_WRITE, sc->sc_address, - cmdbuf, 1, [1], 1, 0)) { + if ((error = iic_exec(sc->sc_tag, I2C_OP_WRITE, sc->sc_address, + cmdbuf, 1, [1], 1, 0)) != 0) { iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "strtc_clock_read: failed to reset HT\n"); - return (0); + return (error); } } @@ -328,14 +316,14 @@ strtc_clock_read(struct strtc_softc *sc, for (i = M41ST84_REG_CSEC; i < M41ST84_REG_DATE_BYTES; i++) { cmdbuf[0] = i; - if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 19:11:12 UTC 2020 Modified Files: src/sys/dev/i2c: m41t00.c Log Message: - Use todr_gettime_ymdhms / todr_settime_ymdhms. - Correctly propagate errors up the stack. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/sys/dev/i2c/m41t00.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/dev/i2c/m41t00.c diff -u src/sys/dev/i2c/m41t00.c:1.22 src/sys/dev/i2c/m41t00.c:1.23 --- src/sys/dev/i2c/m41t00.c:1.22 Thu Jan 2 16:31:09 2020 +++ src/sys/dev/i2c/m41t00.c Thu Jan 2 19:11:12 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: m41t00.c,v 1.22 2020/01/02 16:31:09 thorpej Exp $ */ +/* $NetBSD: m41t00.c,v 1.23 2020/01/02 19:11:12 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: m41t00.c,v 1.22 2020/01/02 16:31:09 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: m41t00.c,v 1.23 2020/01/02 19:11:12 thorpej Exp $"); #include #include @@ -91,10 +91,10 @@ const struct cdevsw m41t00_cdevsw = { .d_flag = D_OTHER }; -static int m41t00_clock_read(struct m41t00_softc *, struct clock_ymdhms *); -static int m41t00_clock_write(struct m41t00_softc *, struct clock_ymdhms *); -static int m41t00_gettime(struct todr_chip_handle *, struct timeval *); -static int m41t00_settime(struct todr_chip_handle *, struct timeval *); +static int m41t00_gettime_ymdhms(struct todr_chip_handle *, + struct clock_ymdhms *); +static int m41t00_settime_ymdhms(struct todr_chip_handle *, + struct clock_ymdhms *); int m41t00_match(device_t parent, cfdata_t cf, void *aux) @@ -123,8 +123,10 @@ m41t00_attach(device_t parent, device_t sc->sc_open = 0; sc->sc_todr.cookie = sc; - sc->sc_todr.todr_gettime = m41t00_gettime; - sc->sc_todr.todr_settime = m41t00_settime; + sc->sc_todr.todr_gettime = NULL; + sc->sc_todr.todr_settime = NULL; + sc->sc_todr.todr_gettime_ymdhms = m41t00_gettime_ymdhms; + sc->sc_todr.todr_settime_ymdhms = m41t00_settime_ymdhms; sc->sc_todr.todr_setwen = NULL; todr_attach(>sc_todr); @@ -238,35 +240,6 @@ m41t00_write(dev_t dev, struct uio *uio, return error; } -static int -m41t00_gettime(struct todr_chip_handle *ch, struct timeval *tv) -{ - struct m41t00_softc *sc = ch->cookie; - struct clock_ymdhms dt; - - if (m41t00_clock_read(sc, ) == 0) - return -1; - - tv->tv_sec = clock_ymdhms_to_secs(); - tv->tv_usec = 0; - - return 0; -} - -static int -m41t00_settime(struct todr_chip_handle *ch, struct timeval *tv) -{ - struct m41t00_softc *sc = ch->cookie; - struct clock_ymdhms dt; - - clock_secs_to_ymdhms(tv->tv_sec, ); - - if (m41t00_clock_write(sc, ) == 0) - return -1; - - return 0; -} - static int m41t00_rtc_offset[] = { M41T00_SEC, M41T00_MIN, @@ -278,15 +251,16 @@ static int m41t00_rtc_offset[] = { }; static int -m41t00_clock_read(struct m41t00_softc *sc, struct clock_ymdhms *dt) +m41t00_gettime_ymdhms(struct todr_chip_handle *ch, struct clock_ymdhms *dt) { + struct m41t00_softc *sc = ch->cookie; u_int8_t bcd[M41T00_NBYTES], cmdbuf[1]; - int i, n; + int i, n, error; - if (iic_acquire_bus(sc->sc_tag, 0)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, "m41t00_clock_read: failed to acquire I2C bus\n"); - return 0; + return error; } /* Read each timekeeping register in order. */ @@ -294,15 +268,15 @@ m41t00_clock_read(struct m41t00_softc *s for (i = 0; i < n ; i++) { cmdbuf[0] = m41t00_rtc_offset[i]; - if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, + if ((error = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, cmdbuf, 1, - [i], 1, 0)) { + [i], 1, 0)) != 0) { iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "m41t00_clock_read: failed to read rtc " "at 0x%x\n", m41t00_rtc_offset[i]); - return 0; + return error; } } @@ -326,15 +300,16 @@ m41t00_clock_read(struct m41t00_softc *s */ dt->dt_year += 2000; - return 1; + return 0; } static int -m41t00_clock_write(struct m41t00_softc *sc, struct clock_ymdhms *dt) +m41t00_settime_ymdhms(struct todr_chip_handle *ch, struct clock_ymdhms *dt) { + struct m41t00_softc *sc = ch->cookie; uint8_t bcd[M41T00_DATE_BYTES], cmdbuf[2]; uint8_t init_seconds, final_seconds; - int i; + int i, error; /* * Convert our time representation into something the MAX6900 @@ -348,10 +323,10 @@ m41t00_clock_write(struct m41t00_softc * bcd[M41T00_MONTH] = bintobcd(dt->dt_mon); bcd[M41T00_YEAR] = bintobcd(dt->dt_year % 100); - if (iic_acquire_bus(sc->sc_tag, 0)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, "m41t00_clock_write: failed to acquire I2C bus\n"); - return 0; + return error; } /* @@ -370,47 +345,48 @@ m41t00_clock_write(struct m41t00_softc * */ again: cmdbuf[0] =
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 19:00:34 UTC 2020 Modified Files: src/sys/dev/i2c: r2025.c s390.c x1226.c Log Message: Use todr_gettime_ymdhms / todr_settime_ymdhms. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/r2025.c cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/s390.c cvs rdiff -u -r1.22 -r1.23 src/sys/dev/i2c/x1226.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/dev/i2c/r2025.c diff -u src/sys/dev/i2c/r2025.c:1.9 src/sys/dev/i2c/r2025.c:1.10 --- src/sys/dev/i2c/r2025.c:1.9 Thu Jan 2 17:03:05 2020 +++ src/sys/dev/i2c/r2025.c Thu Jan 2 19:00:34 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: r2025.c,v 1.9 2020/01/02 17:03:05 thorpej Exp $ */ +/* $NetBSD: r2025.c,v 1.10 2020/01/02 19:00:34 thorpej Exp $ */ /*- * Copyright (c) 2006 Shigeyuki Fukushima. @@ -33,7 +33,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: r2025.c,v 1.9 2020/01/02 17:03:05 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: r2025.c,v 1.10 2020/01/02 19:00:34 thorpej Exp $"); #include #include @@ -63,8 +63,10 @@ static int r2025rtc_match(device_t, cfda CFATTACH_DECL_NEW(r2025rtc, sizeof(struct r2025rtc_softc), r2025rtc_match, r2025rtc_attach, NULL, NULL); -static int r2025rtc_gettime(struct todr_chip_handle *, struct timeval *); -static int r2025rtc_settime(struct todr_chip_handle *, struct timeval *); +static int r2025rtc_gettime_ymdhms(struct todr_chip_handle *, + struct clock_ymdhms *); +static int r2025rtc_settime_ymdhms(struct todr_chip_handle *, + struct clock_ymdhms *); static int r2025rtc_reg_write(struct r2025rtc_softc *, int, uint8_t*, int); static int r2025rtc_reg_read(struct r2025rtc_softc *, int, uint8_t*, int); @@ -94,24 +96,25 @@ r2025rtc_attach(device_t parent, device_ sc->sc_dev = self; sc->sc_open = 0; sc->sc_todr.cookie = sc; - sc->sc_todr.todr_gettime = r2025rtc_gettime; - sc->sc_todr.todr_settime = r2025rtc_settime; + sc->sc_todr.todr_gettime = NULL; + sc->sc_todr.todr_settime = NULL; + sc->sc_todr.todr_gettime_ymdhms = r2025rtc_gettime_ymdhms; + sc->sc_todr.todr_settime_ymdhms = r2025rtc_settime_ymdhms; sc->sc_todr.todr_setwen = NULL; todr_attach(>sc_todr); } static int -r2025rtc_gettime(struct todr_chip_handle *ch, struct timeval *tv) +r2025rtc_gettime_ymdhms(struct todr_chip_handle *ch, struct clock_ymdhms *dt) { struct r2025rtc_softc *sc = ch->cookie; - struct clock_ymdhms dt; uint8_t rctrl; uint8_t bcd[R2025_CLK_SIZE]; int hour; int error; - memset(, 0, sizeof(dt)); + memset(dt, 0, sizeof(*dt)); if ((error = r2025rtc_reg_read(sc, R2025_REG_CTRL1, , 1)) != 0) { aprint_error_dev(sc->sc_dev, @@ -126,47 +129,41 @@ r2025rtc_gettime(struct todr_chip_handle return error; } - dt.dt_sec = bcdtobin(bcd[R2025_REG_SEC] & R2025_REG_SEC_MASK); - dt.dt_min = bcdtobin(bcd[R2025_REG_MIN] & R2025_REG_MIN_MASK); + dt->dt_sec = bcdtobin(bcd[R2025_REG_SEC] & R2025_REG_SEC_MASK); + dt->dt_min = bcdtobin(bcd[R2025_REG_MIN] & R2025_REG_MIN_MASK); hour = bcdtobin(bcd[R2025_REG_HOUR] & R2025_REG_HOUR_MASK); if (rctrl & R2025_REG_CTRL1_H1224) { - dt.dt_hour = hour; + dt->dt_hour = hour; } else { if (hour == 12) { - dt.dt_hour = 0; + dt->dt_hour = 0; } else if (hour == 32) { - dt.dt_hour = 12; + dt->dt_hour = 12; } else if (hour > 13) { - dt.dt_hour = (hour - 8); + dt->dt_hour = (hour - 8); } else { /* (hour < 12) */ - dt.dt_hour = hour; + dt->dt_hour = hour; } } - dt.dt_wday = bcdtobin(bcd[R2025_REG_WDAY] & R2025_REG_WDAY_MASK); - dt.dt_day = bcdtobin(bcd[R2025_REG_DAY] & R2025_REG_DAY_MASK); - dt.dt_mon = bcdtobin(bcd[R2025_REG_MON] & R2025_REG_MON_MASK); - dt.dt_year = bcdtobin(bcd[R2025_REG_YEAR] & R2025_REG_YEAR_MASK) + dt->dt_wday = bcdtobin(bcd[R2025_REG_WDAY] & R2025_REG_WDAY_MASK); + dt->dt_day = bcdtobin(bcd[R2025_REG_DAY] & R2025_REG_DAY_MASK); + dt->dt_mon = bcdtobin(bcd[R2025_REG_MON] & R2025_REG_MON_MASK); + dt->dt_year = bcdtobin(bcd[R2025_REG_YEAR] & R2025_REG_YEAR_MASK) + ((bcd[R2025_REG_MON] & R2025_REG_MON_Y1920) ? 2000 : 1900); - tv->tv_sec = clock_ymdhms_to_secs(); - tv->tv_usec = 0; - return 0; } static int -r2025rtc_settime(struct todr_chip_handle *ch, struct timeval *tv) +r2025rtc_settime_ymdhms(struct todr_chip_handle *ch, struct clock_ymdhms *dt) { struct r2025rtc_softc *sc = ch->cookie; - struct clock_ymdhms dt; uint8_t rctrl; uint8_t bcd[R2025_CLK_SIZE]; int error; - clock_secs_to_ymdhms(tv->tv_sec, ); - /* Y3K problem */ - if (dt.dt_year >= 3000) { + if (dt->dt_year >= 3000) { aprint_error_dev(sc->sc_dev, "r2025rtc_settime: " "RTC does not support year 3000 or over.\n"); @@ -181,14 +178,14 @@ r2025rtc_settime(struct todr_chip_handle rctrl |= R2025_REG_CTRL1_H1224; /* setup registers 0x00-0x06 (7 byte) */ - bcd[R2025_REG_SEC] = bintobcd(dt.dt_sec) & R2025_REG_SEC_MASK; - bcd[R2025_REG_MIN] =
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 18:57:58 UTC 2020 Modified Files: src/sys/dev/i2c: max6900.c Log Message: - Use todr_gettime_ymdhms / todr_settime_ymdhms. - Correctly propagate errors up the stack. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/sys/dev/i2c/max6900.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/dev/i2c/max6900.c diff -u src/sys/dev/i2c/max6900.c:1.17 src/sys/dev/i2c/max6900.c:1.18 --- src/sys/dev/i2c/max6900.c:1.17 Thu Jan 2 16:33:08 2020 +++ src/sys/dev/i2c/max6900.c Thu Jan 2 18:57:58 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: max6900.c,v 1.17 2020/01/02 16:33:08 thorpej Exp $ */ +/* $NetBSD: max6900.c,v 1.18 2020/01/02 18:57:58 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: max6900.c,v 1.17 2020/01/02 16:33:08 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: max6900.c,v 1.18 2020/01/02 18:57:58 thorpej Exp $"); #include #include @@ -87,10 +87,10 @@ const struct cdevsw maxrtc_cdevsw = { .d_flag = D_OTHER }; -static int maxrtc_clock_read(struct maxrtc_softc *, struct clock_ymdhms *); -static int maxrtc_clock_write(struct maxrtc_softc *, struct clock_ymdhms *); -static int maxrtc_gettime(struct todr_chip_handle *, struct timeval *); -static int maxrtc_settime(struct todr_chip_handle *, struct timeval *); +static int maxrtc_gettime_ymdhms(struct todr_chip_handle *, + struct clock_ymdhms *); +static int maxrtc_settime_ymdhms(struct todr_chip_handle *, + struct clock_ymdhms *); int maxrtc_match(device_t parent, cfdata_t cf, void *aux) @@ -119,8 +119,10 @@ maxrtc_attach(device_t parent, device_t sc->sc_open = 0; sc->sc_todr.cookie = sc; - sc->sc_todr.todr_gettime = maxrtc_gettime; - sc->sc_todr.todr_settime = maxrtc_settime; + sc->sc_todr.todr_gettime = NULL; + sc->sc_todr.todr_settime = NULL; + sc->sc_todr.todr_gettime_ymdhms = maxrtc_gettime_ymdhms; + sc->sc_todr.todr_settime_ymdhms = maxrtc_settime_ymdhms; sc->sc_todr.todr_setwen = NULL; todr_attach(>sc_todr); @@ -259,35 +261,6 @@ maxrtc_write(dev_t dev, struct uio *uio, return (error); } -static int -maxrtc_gettime(struct todr_chip_handle *ch, struct timeval *tv) -{ - struct maxrtc_softc *sc = ch->cookie; - struct clock_ymdhms dt; - - if (maxrtc_clock_read(sc, ) == 0) - return (-1); - - tv->tv_sec = clock_ymdhms_to_secs(); - tv->tv_usec = 0; - - return (0); -} - -static int -maxrtc_settime(struct todr_chip_handle *ch, struct timeval *tv) -{ - struct maxrtc_softc *sc = ch->cookie; - struct clock_ymdhms dt; - - clock_secs_to_ymdhms(tv->tv_sec, ); - - if (maxrtc_clock_write(sc, ) == 0) - return (-1); - - return (0); -} - /* * While the MAX6900 has a nice Clock Burst Read/Write command, * we can't use it, since some I2C controllers do not support @@ -305,30 +278,31 @@ static int max6900_rtc_offset[] = { }; static int -maxrtc_clock_read(struct maxrtc_softc *sc, struct clock_ymdhms *dt) +maxrtc_gettime_ymdhms(struct todr_chip_handle *ch, struct clock_ymdhms *dt) { + struct maxrtc_softc *sc = ch->cookie; u_int8_t bcd[MAX6900_BURST_LEN], cmdbuf[1]; - int i; + int i, error; - if (iic_acquire_bus(sc->sc_tag, 0)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, "maxrtc_clock_read: failed to acquire I2C bus\n"); - return (0); + return (error); } /* Read each timekeeping register in order. */ for (i = 0; i < MAX6900_BURST_LEN; i++) { cmdbuf[0] = max6900_rtc_offset[i] | MAX6900_CMD_READ; - if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, + if ((error = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, cmdbuf, 1, - [i], 1, 0)) { + [i], 1, 0)) != 0) { iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "maxrtc_clock_read: failed to read rtc " "at 0x%x\n", max6900_rtc_offset[i]); - return (0); + return (error); } } @@ -357,15 +331,16 @@ maxrtc_clock_read(struct maxrtc_softc *s /* century in the burst control slot */ dt->dt_year += (int)bcdtobin(bcd[MAX6900_BURST_CONTROL]) * 100; - return (1); + return (0); } static int -maxrtc_clock_write(struct maxrtc_softc *sc, struct clock_ymdhms *dt) +maxrtc_settime_ymdhms(struct todr_chip_handle *ch, struct clock_ymdhms *dt) { + struct maxrtc_softc *sc = ch->cookie; uint8_t bcd[MAX6900_BURST_LEN], cmdbuf[2]; uint8_t init_seconds, final_seconds; - int i; + int i, error; /* * Convert our time representation into something the MAX6900 @@ -381,22 +356,22 @@ maxrtc_clock_write(struct maxrtc_softc * /* century in control slot */ bcd[MAX6900_BURST_CONTROL] = bintobcd(dt->dt_year / 100); - if (iic_acquire_bus(sc->sc_tag, 0)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, "maxrtc_clock_write: failed to
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 17:40:27 UTC 2020 Modified Files: src/sys/dev/i2c: x1226.c Log Message: - No need to use I2C_F_POLL here. - Correctly propagate errors up the stack. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/sys/dev/i2c/x1226.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/dev/i2c/x1226.c diff -u src/sys/dev/i2c/x1226.c:1.21 src/sys/dev/i2c/x1226.c:1.22 --- src/sys/dev/i2c/x1226.c:1.21 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/x1226.c Thu Jan 2 17:40:27 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: x1226.c,v 1.21 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: x1226.c,v 1.22 2020/01/02 17:40:27 thorpej Exp $ */ /* * Copyright (c) 2003 Shigeyuki Fukushima. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: x1226.c,v 1.21 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x1226.c,v 1.22 2020/01/02 17:40:27 thorpej Exp $"); #include #include @@ -252,14 +252,17 @@ xrtc_gettime(struct todr_chip_handle *ch struct xrtc_softc *sc = ch->cookie; struct clock_ymdhms dt, check; int retries; + int error; memset(, 0, sizeof(dt)); memset(, 0, sizeof(check)); retries = 5; do { - xrtc_clock_read(sc, ); - xrtc_clock_read(sc, ); + if ((error = xrtc_clock_read(sc, )) == 0) + error = xrtc_clock_read(sc, ); + if (error) + return error; } while (memcmp(, , sizeof(check)) != 0 && --retries); tv->tv_sec = clock_ymdhms_to_secs(); @@ -276,10 +279,7 @@ xrtc_settime(struct todr_chip_handle *ch clock_secs_to_ymdhms(tv->tv_sec, ); - if (xrtc_clock_write(sc, ) == 0) - return (-1); - - return (0); + return xrtc_clock_write(sc, ); } static int @@ -287,11 +287,12 @@ xrtc_clock_read(struct xrtc_softc *sc, s { int i = 0; u_int8_t bcd[X1226_REG_RTC_SIZE], cmdbuf[2]; + int error; - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, "xrtc_clock_read: failed to acquire I2C bus\n"); - return (0); + return (error); } /* Read each RTC register in order */ @@ -300,20 +301,20 @@ xrtc_clock_read(struct xrtc_softc *sc, s cmdbuf[0] = (addr >> 8) & 0xff; cmdbuf[1] = addr & 0xff; - if (iic_exec(sc->sc_tag, + if ((error = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, cmdbuf, 2, - [i], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + [i], 1, 0)) != 0) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "xrtc_clock_read: failed to read rtc " "at 0x%x\n", i); - return (0); + return (error); } } /* Done with I2C */ - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); /* * Convert the X1226's register bcd values @@ -343,7 +344,7 @@ xrtc_clock_read(struct xrtc_softc *sc, s dt->dt_year += bcdtobin(bcd[X1226_REG_Y2K - X1226_REG_RTC_BASE] & X1226_REG_Y2K_MASK) * 100; - return (1); + return (0); } static int @@ -351,6 +352,7 @@ xrtc_clock_write(struct xrtc_softc *sc, { int i = 0, addr; u_int8_t bcd[X1226_REG_RTC_SIZE], cmdbuf[3]; + int error, error2; /* * Convert our time to bcd values @@ -365,10 +367,10 @@ xrtc_clock_write(struct xrtc_softc *sc, bcd[X1226_REG_YR - X1226_REG_RTC_BASE] = bintobcd(dt->dt_year % 100); bcd[X1226_REG_Y2K - X1226_REG_RTC_BASE] = bintobcd(dt->dt_year / 100); - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, "xrtc_clock_write: failed to acquire I2C bus\n"); - return (0); + return (error); } /* Unlock register: Write Enable Latch */ @@ -376,13 +378,13 @@ xrtc_clock_write(struct xrtc_softc *sc, cmdbuf[0] = ((addr >> 8) & 0xff); cmdbuf[1] = (addr & 0xff); cmdbuf[2] = X1226_FLAG_SR_WEL; - if (iic_exec(sc->sc_tag, + if ((error = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, - sc->sc_address, cmdbuf, 2, [2], 1, 0) != 0) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + sc->sc_address, cmdbuf, 2, [2], 1, 0)) != 0) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "xrtc_clock_write: " "failed to write-unlock status register(WEL=1)\n"); - return (0); + return (error); } /* Unlock register: Register Write Enable Latch */ @@ -390,13 +392,13 @@ xrtc_clock_write(struct xrtc_softc *sc, cmdbuf[0] = ((addr >> 8) & 0xff); cmdbuf[1] = (addr & 0xff); cmdbuf[2] = X1226_FLAG_SR_WEL | X1226_FLAG_SR_RWEL; - if (iic_exec(sc->sc_tag, + if ((error = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, - sc->sc_address, cmdbuf, 2, [2], 1, 0) != 0) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + sc->sc_address, cmdbuf, 2, [2], 1, 0)) != 0) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "xrtc_clock_write: " "failed to write-unlock status register(RWEL=1)\n"); - return (0); +
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 17:26:37 UTC 2020 Modified Files: src/sys/dev/i2c: s390.c Log Message: - No need to use I2C_F_POLL here. - Correctly propagate errors up the stack. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/s390.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/dev/i2c/s390.c diff -u src/sys/dev/i2c/s390.c:1.4 src/sys/dev/i2c/s390.c:1.5 --- src/sys/dev/i2c/s390.c:1.4 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/s390.c Thu Jan 2 17:26:37 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: s390.c,v 1.4 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: s390.c,v 1.5 2020/01/02 17:26:37 thorpej Exp $ */ /*- * Copyright (c) 2011 Frank Wille. @@ -29,7 +29,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: s390.c,v 1.4 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: s390.c,v 1.5 2020/01/02 17:26:37 thorpej Exp $"); #include #include @@ -93,20 +93,20 @@ s390rtc_attach(device_t parent, device_t sc->sc_dev = self; /* Reset the chip and turn on 24h mode, after power-off or battery. */ - if (!s390rtc_read(sc, S390_STATUS1, reg, sizeof(reg))) + if (s390rtc_read(sc, S390_STATUS1, reg, sizeof(reg))) return; if (reg[0] & (S390_ST1_POC | S390_ST1_BLD)) { reg[0] |= S390_ST1_24H | S390_ST1_RESET; - if (!s390rtc_write(sc, S390_STATUS1, reg, sizeof(reg))) + if (s390rtc_write(sc, S390_STATUS1, reg, sizeof(reg))) return; } /* Disable the test mode, when enabled. */ - if (!s390rtc_read(sc, S390_STATUS2, reg, sizeof(reg))) + if (s390rtc_read(sc, S390_STATUS2, reg, sizeof(reg))) return; if ((reg[0] & S390_ST2_TEST)) { reg[0] &= ~S390_ST2_TEST; - if (!s390rtc_write(sc, S390_STATUS2, reg, sizeof(reg))) + if (s390rtc_write(sc, S390_STATUS2, reg, sizeof(reg))) return; } @@ -122,11 +122,12 @@ s390rtc_gettime(struct todr_chip_handle { struct s390rtc_softc *sc = ch->cookie; struct clock_ymdhms dt; + int error; memset(, 0, sizeof(dt)); - if (!s390rtc_clock_read(sc, )) - return -1; + if ((error = s390rtc_clock_read(sc, )) != 0) + return error; tv->tv_sec = clock_ymdhms_to_secs(); tv->tv_usec = 0; @@ -139,11 +140,12 @@ s390rtc_settime(struct todr_chip_handle { struct s390rtc_softc *sc = ch->cookie; struct clock_ymdhms dt; + int error; clock_secs_to_ymdhms(tv->tv_sec, ); - if (!s390rtc_clock_write(sc, )) - return -1; + if ((error = s390rtc_clock_write(sc, )) != 0) + return error; return 0; } @@ -152,9 +154,11 @@ static int s390rtc_clock_read(struct s390rtc_softc *sc, struct clock_ymdhms *dt) { uint8_t bcd[S390_RT1_NBYTES]; + int error; - if (!s390rtc_read(sc, S390_REALTIME1, bcd, S390_RT1_NBYTES)) - return 0; + if ((error = s390rtc_read(sc, S390_REALTIME1, bcd, + S390_RT1_NBYTES)) != 0) + return error; /* * Convert the register values into something useable. @@ -166,7 +170,7 @@ s390rtc_clock_read(struct s390rtc_softc dt->dt_mon = bcdtobin(bcd[S390_RT1_MONTH]); dt->dt_year = bcdtobin(bcd[S390_RT1_YEAR]) + 2000; - return 1; + return 0; } static int @@ -192,56 +196,56 @@ s390rtc_clock_write(struct s390rtc_softc static int s390rtc_read(struct s390rtc_softc *sc, int reg, uint8_t *buf, size_t len) { - int i; + int i, error; - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, "%s: failed to acquire I2C bus\n", __func__); - return 0; + return error; } - if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr + reg, - NULL, 0, buf, len, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + if ((error = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, + sc->sc_addr + reg, NULL, 0, buf, len, 0)) != 0) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "%s: failed to read reg%d\n", __func__, reg); - return 0; + return error; } - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); /* this chip returns each byte in reverse order */ for (i = 0; i < len; i++) buf[i] = bitreverse(buf[i]); - return 1; + return 0; } static int s390rtc_write(struct s390rtc_softc *sc, int reg, uint8_t *buf, size_t len) { - int i; + int i, error; - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, "%s: failed to acquire I2C bus\n", __func__); - return 0; + return error; } /* this chip expects each byte in reverse order */ for (i = 0; i < len; i++) buf[i] = bitreverse(buf[i]); - if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_addr + reg, - NULL, 0, buf, len, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + if ((error = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, + sc->sc_addr + reg, NULL, 0, buf, len, 0)) != 0) { +
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 17:17:36 UTC 2020 Modified Files: src/sys/dev/i2c: rs5c372.c Log Message: - No need to use I2C_F_POLL here. - Correctly propagate errors up the stack. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/sys/dev/i2c/rs5c372.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/dev/i2c/rs5c372.c diff -u src/sys/dev/i2c/rs5c372.c:1.15 src/sys/dev/i2c/rs5c372.c:1.16 --- src/sys/dev/i2c/rs5c372.c:1.15 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/rs5c372.c Thu Jan 2 17:17:36 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: rs5c372.c,v 1.15 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: rs5c372.c,v 1.16 2020/01/02 17:17:36 thorpej Exp $ */ /*- * Copyright (C) 2005 NONAKA Kimihiro @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rs5c372.c,v 1.15 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rs5c372.c,v 1.16 2020/01/02 17:17:36 thorpej Exp $"); #include #include @@ -55,7 +55,7 @@ static void rs5c372rtc_attach(device_t, CFATTACH_DECL_NEW(rs5c372rtc, sizeof(struct rs5c372rtc_softc), rs5c372rtc_match, rs5c372rtc_attach, NULL, NULL); -static void rs5c372rtc_reg_write(struct rs5c372rtc_softc *, int, uint8_t); +static int rs5c372rtc_reg_write(struct rs5c372rtc_softc *, int, uint8_t); static int rs5c372rtc_clock_read(struct rs5c372rtc_softc *, struct clock_ymdhms *); static int rs5c372rtc_clock_write(struct rs5c372rtc_softc *, struct clock_ymdhms *); static int rs5c372rtc_gettime_ymdhms(todr_chip_handle_t, struct clock_ymdhms *); @@ -106,10 +106,7 @@ rs5c372rtc_gettime_ymdhms(todr_chip_hand { struct rs5c372rtc_softc *sc = ch->cookie; - if (rs5c372rtc_clock_read(sc, dt) == 0) - return (-1); - - return (0); + return rs5c372rtc_clock_read(sc, dt); } static int @@ -117,35 +114,36 @@ rs5c372rtc_settime_ymdhms(todr_chip_hand { struct rs5c372rtc_softc *sc = ch->cookie; - if (rs5c372rtc_clock_write(sc, dt) == 0) - return (-1); - - return (0); + return rs5c372rtc_clock_write(sc, dt); } -static void +static int rs5c372rtc_reg_write(struct rs5c372rtc_softc *sc, int reg, uint8_t val) { uint8_t cmdbuf[2]; + int error; - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, "rs5c372rtc_reg_write: failed to acquire I2C bus\n"); - return; + return error; } reg &= 0xf; cmdbuf[0] = (reg << 4); cmdbuf[1] = val; - if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_address, - cmdbuf, 1, [1], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + if ((error = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, + sc->sc_address, cmdbuf, 1, [1], 1, + 0)) != 0) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "rs5c372rtc_reg_write: failed to write reg%d\n", reg); - return; + return error; } - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); + + return 0; } static int @@ -153,23 +151,24 @@ rs5c372rtc_clock_read(struct rs5c372rtc_ { uint8_t bcd[RS5C372_NRTC_REGS]; uint8_t cmdbuf[1]; + int error; - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, "rs5c372rtc_clock_read: failed to acquire I2C bus\n"); - return (0); + return (error); } cmdbuf[0] = (RS5C372_SECONDS << 4); - if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, - cmdbuf, 1, bcd, RS5C372_NRTC_REGS, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + if ((error = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, + cmdbuf, 1, bcd, RS5C372_NRTC_REGS, 0)) != 0) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "rs5c372rtc_clock_read: failed to read rtc\n"); - return (0); + return (error); } - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); /* * Convert the RS5C372's register values into something useable @@ -181,7 +180,7 @@ rs5c372rtc_clock_read(struct rs5c372rtc_ dt->dt_mon = bcdtobin(bcd[RS5C372_MONTH] & RS5C372_MONTH_MASK); dt->dt_year = bcdtobin(bcd[RS5C372_YEAR]) + 2000; - return (1); + return (0); } static int @@ -189,6 +188,7 @@ rs5c372rtc_clock_write(struct rs5c372rtc { uint8_t bcd[RS5C372_NRTC_REGS]; uint8_t cmdbuf[1]; + int error; /* * Convert our time representation into something the RS5C372 @@ -202,22 +202,23 @@ rs5c372rtc_clock_write(struct rs5c372rtc bcd[RS5C372_MONTH] = bintobcd(dt->dt_mon); bcd[RS5C372_YEAR] = bintobcd(dt->dt_year % 100); - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, "rs5c372rtc_clock_write: failed to " "acquire I2C bus\n"); - return (0); + return (error);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 17:10:00 UTC 2020 Modified Files: src/sys/dev/i2c: rkpmic.c Log Message: No need to use I2C_F_POLL here. XXX This entire driver needs to have its error reporting overhauled. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/rkpmic.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/dev/i2c/rkpmic.c diff -u src/sys/dev/i2c/rkpmic.c:1.6 src/sys/dev/i2c/rkpmic.c:1.7 --- src/sys/dev/i2c/rkpmic.c:1.6 Wed Jan 1 00:38:30 2020 +++ src/sys/dev/i2c/rkpmic.c Thu Jan 2 17:09:59 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: rkpmic.c,v 1.6 2020/01/01 00:38:30 jmcneill Exp $ */ +/* $NetBSD: rkpmic.c,v 1.7 2020/01/02 17:09:59 thorpej Exp $ */ /*- * Copyright (c) 2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rkpmic.c,v 1.6 2020/01/01 00:38:30 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rkpmic.c,v 1.7 2020/01/02 17:09:59 thorpej Exp $"); #include #include @@ -249,24 +249,27 @@ rkpmic_write(struct rkpmic_softc *sc, ui device_printf(sc->sc_dev, "error writing reg %#x: %d\n", reg, error); } -#define I2C_READ(sc, reg) rkpmic_read((sc), (reg), I2C_F_POLL) -#define I2C_WRITE(sc, reg, val) rkpmic_write((sc), (reg), (val), I2C_F_POLL) -#define I2C_LOCK(sc) iic_acquire_bus((sc)->sc_i2c, I2C_F_POLL) -#define I2C_UNLOCK(sc) iic_release_bus((sc)->sc_i2c, I2C_F_POLL) +#define I2C_READ(sc, reg) rkpmic_read((sc), (reg), 0) +#define I2C_WRITE(sc, reg, val) rkpmic_write((sc), (reg), (val), 0) +#define I2C_LOCK(sc) iic_acquire_bus((sc)->sc_i2c, 0) +#define I2C_UNLOCK(sc) iic_release_bus((sc)->sc_i2c, 0) static int rkpmic_todr_settime(todr_chip_handle_t ch, struct clock_ymdhms *dt) { struct rkpmic_softc * const sc = ch->cookie; uint8_t val; + int error; if (dt->dt_year < 2000 || dt->dt_year >= 2100) { device_printf(sc->sc_dev, "year out of range\n"); return EINVAL; } - if (I2C_LOCK(sc)) - return EBUSY; + if ((error = I2C_LOCK(sc)) != 0) + return error; + + /* XXX Fix error reporting. */ val = I2C_READ(sc, RTC_CTRL_REG); I2C_WRITE(sc, RTC_CTRL_REG, val | RTC_CTRL_STOP_RTC); @@ -288,9 +291,12 @@ rkpmic_todr_gettime(todr_chip_handle_t c { struct rkpmic_softc * const sc = ch->cookie; uint8_t val; + int error; + + if ((error = I2C_LOCK(sc)) != 0) + return error; - if (I2C_LOCK(sc)) - return EBUSY; + /* XXX Fix error reporting. */ val = I2C_READ(sc, RTC_CTRL_REG); I2C_WRITE(sc, RTC_CTRL_REG, val | RTC_CTRL_GET_TIME | RTC_CTRL_READSEL);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 17:03:05 UTC 2020 Modified Files: src/sys/dev/i2c: r2025.c Log Message: - No need to use I2C_F_POLL here. - Correctly propagate errors up the stack. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/sys/dev/i2c/r2025.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/dev/i2c/r2025.c diff -u src/sys/dev/i2c/r2025.c:1.8 src/sys/dev/i2c/r2025.c:1.9 --- src/sys/dev/i2c/r2025.c:1.8 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/r2025.c Thu Jan 2 17:03:05 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: r2025.c,v 1.8 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: r2025.c,v 1.9 2020/01/02 17:03:05 thorpej Exp $ */ /*- * Copyright (c) 2006 Shigeyuki Fukushima. @@ -33,7 +33,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: r2025.c,v 1.8 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: r2025.c,v 1.9 2020/01/02 17:03:05 thorpej Exp $"); #include #include @@ -109,20 +109,21 @@ r2025rtc_gettime(struct todr_chip_handle uint8_t rctrl; uint8_t bcd[R2025_CLK_SIZE]; int hour; + int error; memset(, 0, sizeof(dt)); - if (r2025rtc_reg_read(sc, R2025_REG_CTRL1, , 1) != 0) { + if ((error = r2025rtc_reg_read(sc, R2025_REG_CTRL1, , 1)) != 0) { aprint_error_dev(sc->sc_dev, "r2025rtc_gettime: failed to read registers.\n"); - return -1; + return error; } - if (r2025rtc_reg_read(sc, R2025_REG_SEC, [0], R2025_CLK_SIZE) - != 0) { + if ((error = r2025rtc_reg_read(sc, R2025_REG_SEC, [0], + R2025_CLK_SIZE)) != 0) { aprint_error_dev(sc->sc_dev, "r2025rtc_gettime: failed to read registers.\n"); - return -1; + return error; } dt.dt_sec = bcdtobin(bcd[R2025_REG_SEC] & R2025_REG_SEC_MASK); @@ -160,6 +161,7 @@ r2025rtc_settime(struct todr_chip_handle struct clock_ymdhms dt; uint8_t rctrl; uint8_t bcd[R2025_CLK_SIZE]; + int error; clock_secs_to_ymdhms(tv->tv_sec, ); @@ -168,13 +170,13 @@ r2025rtc_settime(struct todr_chip_handle aprint_error_dev(sc->sc_dev, "r2025rtc_settime: " "RTC does not support year 3000 or over.\n"); - return -1; + return EINVAL; } - if (r2025rtc_reg_read(sc, R2025_REG_CTRL1, , 1) != 0) { + if ((error = r2025rtc_reg_read(sc, R2025_REG_CTRL1, , 1)) != 0) { aprint_error_dev(sc->sc_dev, "r2025rtc_settime: failed to read register.\n"); - return -1; + return error; } rctrl |= R2025_REG_CTRL1_H1224; @@ -189,15 +191,16 @@ r2025rtc_settime(struct todr_chip_handle bcd[R2025_REG_YEAR] = bintobcd(dt.dt_year % 100) & R2025_REG_YEAR_MASK; /* Write RTC register */ - if (r2025rtc_reg_write(sc, R2025_REG_CTRL1, , 1) != 0) { + if ((error = r2025rtc_reg_write(sc, R2025_REG_CTRL1, , 1)) != 0) { aprint_error_dev(sc->sc_dev, "r2025rtc_settime: failed to write registers.\n"); - return -1; + return error; } - if (r2025rtc_reg_write(sc, R2025_REG_SEC, bcd, R2025_CLK_SIZE) != 0) { + if ((error = r2025rtc_reg_write(sc, R2025_REG_SEC, bcd, + R2025_CLK_SIZE)) != 0) { aprint_error_dev(sc->sc_dev, "r2025rtc_settime: failed to write registers.\n"); - return -1; + return error; } return 0; @@ -209,26 +212,28 @@ r2025rtc_reg_write(struct r2025rtc_softc int i; uint8_t buf[1]; uint8_t cmdbuf[1]; + int error; - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, - "r2025rtc_clock_write: failed to acquire I2C bus\n"); - return -1; + "r2025rtc_reg_write: failed to acquire I2C bus\n"); + return error; } for (i = 0 ; i < len ; i++) { cmdbuf[0] = (((reg + i) << 4) & 0xf0); buf[0] = val[i]; - if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_address, -cmdbuf, 1, buf, 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + if ((error = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, + sc->sc_address, cmdbuf, 1, buf, 1, + 0)) != 0) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "r2025rtc_reg_write: " "failed to write registers\n"); - return -1; + return error; } } - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); return 0; } @@ -239,28 +244,30 @@ r2025rtc_reg_read(struct r2025rtc_softc int i; uint8_t buf[1]; uint8_t cmdbuf[1]; + int error; - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, - "r2025rtc_clock_read: failed to acquire I2C bus\n"); - return -1; + "r2025rtc_reg_read: failed to acquire I2C bus\n"); + return error; } for (i = 0 ; i < len ; i++) { cmdbuf[0] = (((reg + i) << 4) & 0xf0); buf[0] = 0; - if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, -cmdbuf, 1, buf, 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + if ((error =
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 16:53:05 UTC 2020 Modified Files: src/sys/dev/i2c: pcf8583.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sys/dev/i2c/pcf8583.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/dev/i2c/pcf8583.c diff -u src/sys/dev/i2c/pcf8583.c:1.18 src/sys/dev/i2c/pcf8583.c:1.19 --- src/sys/dev/i2c/pcf8583.c:1.18 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/pcf8583.c Thu Jan 2 16:53:05 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: pcf8583.c,v 1.18 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: pcf8583.c,v 1.19 2020/01/02 16:53:05 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pcf8583.c,v 1.18 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcf8583.c,v 1.19 2020/01/02 16:53:05 thorpej Exp $"); #include #include @@ -327,7 +327,7 @@ pcfrtc_clock_read(struct pcfrtc_softc *s u_int8_t bcd[10], cmdbuf[1]; int i, err; - if ((err = iic_acquire_bus(sc->sc_tag, I2C_F_POLL))) { + if ((err = iic_acquire_bus(sc->sc_tag, 0))) { aprint_error_dev(sc->sc_dev, "pcfrtc_clock_read: failed to acquire I2C bus\n"); return err; @@ -339,8 +339,8 @@ pcfrtc_clock_read(struct pcfrtc_softc *s if ((err = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, cmdbuf, 1, - [i], 1, I2C_F_POLL))) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + [i], 1, 0))) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "pcfrtc_clock_read: failed to read rtc " "at 0x%x\n", @@ -350,7 +350,7 @@ pcfrtc_clock_read(struct pcfrtc_softc *s } /* Done with I2C */ - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); /* * Convert the PCF8583's register values into something useable @@ -405,7 +405,7 @@ pcfrtc_clock_write(struct pcfrtc_softc * bcd[8]= dt->dt_year % 100; bcd[9]= dt->dt_year / 100; - if ((err = iic_acquire_bus(sc->sc_tag, I2C_F_POLL))) { + if ((err = iic_acquire_bus(sc->sc_tag, 0))) { aprint_error_dev(sc->sc_dev, "pcfrtc_clock_write: failed to acquire I2C bus\n"); return err; @@ -416,8 +416,8 @@ pcfrtc_clock_write(struct pcfrtc_softc * if ((err = iic_exec(sc->sc_tag, i != 9 ? I2C_OP_WRITE : I2C_OP_WRITE_WITH_STOP, sc->sc_address, cmdbuf, 1, - [i], 1, I2C_F_POLL))) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + [i], 1, 0))) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "pcfrtc_clock_write: failed to write rtc " " at 0x%x\n", @@ -426,7 +426,7 @@ pcfrtc_clock_write(struct pcfrtc_softc * } } - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); return 0; } @@ -445,15 +445,15 @@ pcfrtc_bootstrap_read(i2c_tag_t tag, int if (len == 0) return (0); - if (iic_acquire_bus(tag, I2C_F_POLL) != 0) + if (iic_acquire_bus(tag, 0) != 0) return (-1); while (len) { /* Read a single byte. */ cmdbuf[0] = offset; if (iic_exec(tag, I2C_OP_READ_WITH_STOP, i2caddr, - cmdbuf, 1, rvp, 1, I2C_F_POLL)) { - iic_release_bus(tag, I2C_F_POLL); + cmdbuf, 1, rvp, 1, 0)) { + iic_release_bus(tag, 0); return (-1); } @@ -462,7 +462,7 @@ pcfrtc_bootstrap_read(i2c_tag_t tag, int offset++; } - iic_release_bus(tag, I2C_F_POLL); + iic_release_bus(tag, 0); return (0); } @@ -480,15 +480,15 @@ pcfrtc_bootstrap_write(i2c_tag_t tag, in if (len == 0) return (0); - if (iic_acquire_bus(tag, I2C_F_POLL) != 0) + if (iic_acquire_bus(tag, 0) != 0) return (-1); while (len) { /* Write a single byte. */ cmdbuf[0] = offset; if (iic_exec(tag, I2C_OP_WRITE_WITH_STOP, i2caddr, - cmdbuf, 1, rvp, 1, I2C_F_POLL)) { - iic_release_bus(tag, I2C_F_POLL); + cmdbuf, 1, rvp, 1, 0)) { + iic_release_bus(tag, 0); return (-1); } @@ -497,6 +497,6 @@ pcfrtc_bootstrap_write(i2c_tag_t tag, in offset++; } - iic_release_bus(tag, I2C_F_POLL); + iic_release_bus(tag, 0); return (0); }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 16:48:05 UTC 2020 Modified Files: src/sys/dev/i2c: pcf8563.c Log Message: - No need to use I2C_F_POLL here. - Properly propagate errors up the stack. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sys/dev/i2c/pcf8563.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/dev/i2c/pcf8563.c diff -u src/sys/dev/i2c/pcf8563.c:1.11 src/sys/dev/i2c/pcf8563.c:1.12 --- src/sys/dev/i2c/pcf8563.c:1.11 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/pcf8563.c Thu Jan 2 16:48:05 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: pcf8563.c,v 1.11 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: pcf8563.c,v 1.12 2020/01/02 16:48:05 thorpej Exp $ */ /* * Copyright (c) 2011 Jonathan A. Kollasch @@ -32,7 +32,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: pcf8563.c,v 1.11 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcf8563.c,v 1.12 2020/01/02 16:48:05 thorpej Exp $"); #include #include @@ -93,6 +93,7 @@ pcf8563rtc_attach(device_t parent, devic { struct pcf8563rtc_softc *sc = device_private(self); struct i2c_attach_args *ia = aux; + int error; aprint_naive(": Real-time Clock\n"); aprint_normal(": NXP PCF8563 Real-time Clock\n"); @@ -105,12 +106,21 @@ pcf8563rtc_attach(device_t parent, devic sc->sc_todr.todr_settime_ymdhms = pcf8563rtc_settime; sc->sc_todr.todr_setwen = NULL; - iic_acquire_bus(sc->sc_tag, I2C_F_POLL); - iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, PCF8563_R_CS1, 0, - I2C_F_POLL); - iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, PCF8563_R_CS2, 0, - I2C_F_POLL); - iic_release_bus(sc->sc_tag, I2C_F_POLL); + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { + aprint_error_dev(sc->sc_dev, + "failed to acquire bus for attach\n"); + return; + } + if ((error = iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, + PCF8563_R_CS1, 0, 0)) == 0) { + error = iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, + PCF8563_R_CS2, 0, 0); + } + iic_release_bus(sc->sc_tag, 0); + if (error) { + aprint_error_dev(sc->sc_dev, "failed to initialize RTC\n"); + return; + } #ifdef FDT fdtbus_todr_attach(self, ia->ia_cookie, >sc_todr); @@ -123,11 +133,8 @@ static int pcf8563rtc_gettime(struct todr_chip_handle *ch, struct clock_ymdhms *dt) { struct pcf8563rtc_softc *sc = ch->cookie; - - if (pcf8563rtc_clock_read(sc, dt) == 0) - return -1; - return 0; + return pcf8563rtc_clock_read(sc, dt); } static int @@ -135,10 +142,7 @@ pcf8563rtc_settime(struct todr_chip_hand { struct pcf8563rtc_softc *sc = ch->cookie; - if (pcf8563rtc_clock_write(sc, dt) == 0) - return -1; - - return 0; + return pcf8563rtc_clock_write(sc, dt); } static int @@ -146,24 +150,25 @@ pcf8563rtc_clock_read(struct pcf8563rtc_ { uint8_t bcd[PCF8563_NREGS]; uint8_t reg = PCF8563_R_SECOND; - const int flags = I2C_F_POLL; + int error; - if (iic_acquire_bus(sc->sc_tag, flags)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { device_printf(sc->sc_dev, "acquire bus for read failed\n"); - return 0; + return error; } - if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, , 1, - [reg], PCF8563_R_YEAR - reg + 1, flags)) { - iic_release_bus(sc->sc_tag, flags); + if ((error = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, + , 1, [reg], PCF8563_R_YEAR - reg + 1, + 0)) != 0) { + iic_release_bus(sc->sc_tag, 0); device_printf(sc->sc_dev, "read failed\n"); - return 0; + return error; } - iic_release_bus(sc->sc_tag, flags); + iic_release_bus(sc->sc_tag, 0); if (bcd[PCF8563_R_SECOND] & PCF8563_M_VL) - return 0; + return EIO; dt->dt_sec = bcdtobin(bcd[PCF8563_R_SECOND] & PCF8563_M_SECOND); dt->dt_min = bcdtobin(bcd[PCF8563_R_MINUTE] & PCF8563_M_MINUTE); @@ -176,7 +181,7 @@ pcf8563rtc_clock_read(struct pcf8563rtc_ if ((bcd[PCF8563_R_MONTH] & PCF8563_M_CENTURY) == 0) dt->dt_year += 100; - return 1; + return error; } static int @@ -184,7 +189,7 @@ pcf8563rtc_clock_write(struct pcf8563rtc { uint8_t bcd[PCF8563_NREGS]; uint8_t reg = PCF8563_R_SECOND; - const int flags = I2C_F_POLL; + int error; bcd[PCF8563_R_SECOND] = bintobcd(dt->dt_sec); bcd[PCF8563_R_MINUTE] = bintobcd(dt->dt_min); @@ -196,19 +201,18 @@ pcf8563rtc_clock_write(struct pcf8563rtc if (dt->dt_year < 2000) bcd[PCF8563_R_MONTH] |= PCF8563_M_CENTURY; - if (iic_acquire_bus(sc->sc_tag, flags)) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { device_printf(sc->sc_dev, "acquire bus for write failed\n"); - return 0; + return error; } - if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, , 1, - [reg], PCF8563_R_YEAR - reg + 1, flags)) { - iic_release_bus(sc->sc_tag, flags); + if ((error = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, , 1, [reg], PCF8563_R_YEAR - reg + 1, 0)) != 0) { +
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 16:33:08 UTC 2020 Modified Files: src/sys/dev/i2c: max6900.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sys/dev/i2c/max6900.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/dev/i2c/max6900.c diff -u src/sys/dev/i2c/max6900.c:1.16 src/sys/dev/i2c/max6900.c:1.17 --- src/sys/dev/i2c/max6900.c:1.16 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/max6900.c Thu Jan 2 16:33:08 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: max6900.c,v 1.16 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: max6900.c,v 1.17 2020/01/02 16:33:08 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: max6900.c,v 1.16 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: max6900.c,v 1.17 2020/01/02 16:33:08 thorpej Exp $"); #include #include @@ -310,7 +310,7 @@ maxrtc_clock_read(struct maxrtc_softc *s u_int8_t bcd[MAX6900_BURST_LEN], cmdbuf[1]; int i; - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + if (iic_acquire_bus(sc->sc_tag, 0)) { aprint_error_dev(sc->sc_dev, "maxrtc_clock_read: failed to acquire I2C bus\n"); return (0); @@ -322,8 +322,8 @@ maxrtc_clock_read(struct maxrtc_softc *s if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, cmdbuf, 1, - [i], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + [i], 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "maxrtc_clock_read: failed to read rtc " "at 0x%x\n", @@ -333,7 +333,7 @@ maxrtc_clock_read(struct maxrtc_softc *s } /* Done with I2C */ - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); /* * Convert the MAX6900's register values into something useable @@ -381,7 +381,7 @@ maxrtc_clock_write(struct maxrtc_softc * /* century in control slot */ bcd[MAX6900_BURST_CONTROL] = bintobcd(dt->dt_year / 100); - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + if (iic_acquire_bus(sc->sc_tag, 0)) { aprint_error_dev(sc->sc_dev, "maxrtc_clock_write: failed to acquire I2C bus\n"); return (0); @@ -392,8 +392,8 @@ maxrtc_clock_write(struct maxrtc_softc * cmdbuf[1] = 0; if (iic_exec(sc->sc_tag, I2C_OP_WRITE, sc->sc_address, - cmdbuf, 1, [1], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, [1], 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "maxrtc_clock_write: failed to clear WP bit\n"); return (0); @@ -414,8 +414,8 @@ maxrtc_clock_write(struct maxrtc_softc * again: cmdbuf[0] = MAX6900_REG_SECOND | MAX6900_CMD_WRITE; if (iic_exec(sc->sc_tag, I2C_OP_WRITE, sc->sc_address, - cmdbuf, 1, [MAX6900_BURST_SECOND], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, [MAX6900_BURST_SECOND], 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "maxrtc_clock_write: failed to write SECONDS\n"); return (0); @@ -423,8 +423,8 @@ maxrtc_clock_write(struct maxrtc_softc * cmdbuf[0] = MAX6900_REG_SECOND | MAX6900_CMD_READ; if (iic_exec(sc->sc_tag, I2C_OP_READ, sc->sc_address, - cmdbuf, 1, _seconds, 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, _seconds, 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "maxrtc_clock_write: failed to read " "INITIAL SECONDS\n"); @@ -436,8 +436,8 @@ maxrtc_clock_write(struct maxrtc_softc * if (iic_exec(sc->sc_tag, i != MAX6900_BURST_LEN - 1 ? I2C_OP_WRITE : I2C_OP_WRITE_WITH_STOP, sc->sc_address, - cmdbuf, 1, [i], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, [i], 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "maxrtc_clock_write: failed to write rtc " " at 0x%x\n", @@ -448,8 +448,8 @@ maxrtc_clock_write(struct maxrtc_softc * cmdbuf[0] = MAX6900_REG_SECOND | MAX6900_CMD_READ; if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, - cmdbuf, 1, _seconds, 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, _seconds, 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "maxrtc_clock_write: failed to read " "FINAL SECONDS\n"); @@ -470,14 +470,14 @@ maxrtc_clock_write(struct maxrtc_softc * cmdbuf[1] = MAX6900_CONTROL_WP; if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_address, - cmdbuf, 1, [1], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, [1], 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "maxrtc_clock_write: failed to set WP bit\n"); return (0); } -