CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sat May 18 00:02:04 UTC 2024 Modified Files: src/sys/dev/i2c: dbcool.c sgsmix.c Log Message: Remove unnecessary include of . To generate a diff of this commit: cvs rdiff -u -r1.64 -r1.65 src/sys/dev/i2c/dbcool.c cvs rdiff -u -r1.10 -r1.11 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/dbcool.c diff -u src/sys/dev/i2c/dbcool.c:1.64 src/sys/dev/i2c/dbcool.c:1.65 --- src/sys/dev/i2c/dbcool.c:1.64 Wed Mar 30 00:06:50 2022 +++ src/sys/dev/i2c/dbcool.c Sat May 18 00:02:04 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: dbcool.c,v 1.64 2022/03/30 00:06:50 pgoyette Exp $ */ +/* $NetBSD: dbcool.c,v 1.65 2024/05/18 00:02:04 thorpej Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -50,13 +50,12 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.64 2022/03/30 00:06:50 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.65 2024/05/18 00:02:04 thorpej Exp $"); #include #include #include #include -#include #include #include Index: src/sys/dev/i2c/sgsmix.c diff -u src/sys/dev/i2c/sgsmix.c:1.10 src/sys/dev/i2c/sgsmix.c:1.11 --- src/sys/dev/i2c/sgsmix.c:1.10 Sat Jan 30 01:23:08 2021 +++ src/sys/dev/i2c/sgsmix.c Sat May 18 00:02:04 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: sgsmix.c,v 1.10 2021/01/30 01:23:08 thorpej Exp $ */ +/* $NetBSD: sgsmix.c,v 1.11 2024/05/18 00:02:04 thorpej Exp $ */ /*- * Copyright (C) 2005 Michael Lorenz. @@ -31,13 +31,12 @@ #include -__KERNEL_RCSID(0, "$NetBSD: sgsmix.c,v 1.10 2021/01/30 01:23:08 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sgsmix.c,v 1.11 2024/05/18 00:02:04 thorpej Exp $"); #include #include #include #include -#include #include #include
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sat May 18 00:02:04 UTC 2024 Modified Files: src/sys/dev/i2c: dbcool.c sgsmix.c Log Message: Remove unnecessary include of . To generate a diff of this commit: cvs rdiff -u -r1.64 -r1.65 src/sys/dev/i2c/dbcool.c cvs rdiff -u -r1.10 -r1.11 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: andvar Date: Mon Apr 29 21:25:34 UTC 2024 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: ihidev(4): make driver compile with ACPI option disabled. This change unlikely useful in practice, but adds consistency to already available guards. Driver won't attach currently without ACPI. To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 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.29 src/sys/dev/i2c/ihidev.c:1.30 --- src/sys/dev/i2c/ihidev.c:1.29 Tue Aug 1 19:36:45 2023 +++ src/sys/dev/i2c/ihidev.c Mon Apr 29 21:25:34 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.29 2023/08/01 19:36:45 riastradh Exp $ */ +/* $NetBSD: ihidev.c,v 1.30 2024/04/29 21:25:34 andvar 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.29 2023/08/01 19:36:45 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.30 2024/04/29 21:25:34 andvar Exp $"); #include #include @@ -116,8 +116,10 @@ static void ihidev_intr_fini(struct ihid 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); +#if NACPICA > 0 static int ihidev_intr(void *); static void ihidev_work(struct work *, void *); +#endif static int ihidev_reset(struct ihidev_softc *, bool); static int ihidev_hid_desc_parse(struct ihidev_softc *); @@ -730,14 +732,13 @@ ihidev_intr_fini(struct ihidev_softc *sc #endif } +#if NACPICA > 0 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 } } @@ -746,9 +747,7 @@ ihidev_intr_unmask(struct ihidev_softc * { if (sc->sc_intr_type == IST_LEVEL) { -#if NACPICA > 0 acpi_intr_unmask(sc->sc_ih); -#endif } } @@ -832,6 +831,7 @@ ihidev_work(struct work *wk, void *arg) */ ihidev_intr_unmask(sc); } +#endif static int ihidev_maxrepid(void *buf, int len) @@ -1009,6 +1009,7 @@ ihidev_set_report(struct device *dev, in static bool ihidev_acpi_get_info(struct ihidev_softc *sc) { +#if NACPICA > 0 ACPI_HANDLE hdl = (void *)(uintptr_t)sc->sc_phandle; ACPI_STATUS status; ACPI_INTEGER val; @@ -1033,4 +1034,7 @@ ihidev_acpi_get_info(struct ihidev_softc sc->sc_hid_desc_addr = (u_int)val; return true; +#else + return false; +#endif }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: andvar Date: Mon Apr 29 21:25:34 UTC 2024 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: ihidev(4): make driver compile with ACPI option disabled. This change unlikely useful in practice, but adds consistency to already available guards. Driver won't attach currently without ACPI. To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: andvar Date: Sun Feb 11 09:20:08 UTC 2024 Modified Files: src/sys/dev/i2c: w83795g.c Log Message: s/Nuvaton/Nuvoton/ in log message. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/w83795g.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/w83795g.c diff -u src/sys/dev/i2c/w83795g.c:1.5 src/sys/dev/i2c/w83795g.c:1.6 --- src/sys/dev/i2c/w83795g.c:1.5 Sat Aug 7 16:19:11 2021 +++ src/sys/dev/i2c/w83795g.c Sun Feb 11 09:20:08 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: w83795g.c,v 1.5 2021/08/07 16:19:11 thorpej Exp $ */ +/* $NetBSD: w83795g.c,v 1.6 2024/02/11 09:20:08 andvar Exp $ */ /* * Copyright (c) 2013 Soren S. Jorvang. All rights reserved. @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: w83795g.c,v 1.5 2021/08/07 16:19:11 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: w83795g.c,v 1.6 2024/02/11 09:20:08 andvar Exp $"); #include #include @@ -192,7 +192,7 @@ w83795g_attach(device_t parent, device_t iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, W83795G_CONFIG, &conf, 0); iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, W83795G_DEVICE, &rev, 0); - aprint_normal(": Nuvaton W83795"); + aprint_normal(": Nuvoton W83795"); if (conf & CONFIG_CONFIG48) aprint_normal("ADG"); else
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: andvar Date: Sun Feb 11 09:20:08 UTC 2024 Modified Files: src/sys/dev/i2c: w83795g.c Log Message: s/Nuvaton/Nuvoton/ in log message. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/w83795g.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Mon Dec 11 13:27:24 UTC 2023 Modified Files: src/sys/dev/i2c: es8316ac.c Log Message: Output is always 16bit, the internal audio data type may differ. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 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.5 src/sys/dev/i2c/es8316ac.c:1.6 --- src/sys/dev/i2c/es8316ac.c:1.5 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/es8316ac.c Mon Dec 11 13:27:24 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: es8316ac.c,v 1.5 2021/01/27 02:29:48 thorpej Exp $ */ +/* $NetBSD: es8316ac.c,v 1.6 2023/12/11 13:27:24 mlelstv Exp $ */ /*- * Copyright (c) 2020 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: es8316ac.c,v 1.5 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: es8316ac.c,v 1.6 2023/12/11 13:27:24 mlelstv Exp $"); #include #include @@ -298,7 +298,7 @@ escodec_swvol_codec(audio_filter_arg_t * { struct escodec_softc * const sc = arg->context; const aint_t *src; - aint_t *dst; + int16_t *dst; u_int sample_count; u_int i;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Mon Dec 11 13:27:24 UTC 2023 Modified Files: src/sys/dev/i2c: es8316ac.c Log Message: Output is always 16bit, the internal audio data type may differ. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Tue Aug 1 19:36:46 UTC 2023 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: ihidev(4): Use iic_use_direct_match as intended. This appears to have been a mistake; there's no obvious explanation in the commit history for why this is different from all other iic_use_direct_match users. Patch from Vladimir 'phcoder' Serbinenko , thanks! (If it really is intended to ues I2C_MATCH_DIRECT_COMPATIBLE here, we need a clear explanation of why, written down in a nearby comment.) To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 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.28 src/sys/dev/i2c/ihidev.c:1.29 --- src/sys/dev/i2c/ihidev.c:1.28 Sat Feb 12 03:24:35 2022 +++ src/sys/dev/i2c/ihidev.c Tue Aug 1 19:36:45 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.28 2022/02/12 03:24:35 riastradh Exp $ */ +/* $NetBSD: ihidev.c,v 1.29 2023/08/01 19:36:45 riastradh 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.28 2022/02/12 03:24:35 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.29 2023/08/01 19:36:45 riastradh Exp $"); #include #include @@ -141,7 +141,7 @@ ihidev_match(device_t parent, cfdata_t m int match_result; if (iic_use_direct_match(ia, match, compat_data, &match_result)) - return I2C_MATCH_DIRECT_COMPATIBLE; + return match_result; return 0; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Tue Aug 1 19:36:46 UTC 2023 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: ihidev(4): Use iic_use_direct_match as intended. This appears to have been a mistake; there's no obvious explanation in the commit history for why this is different from all other iic_use_direct_match users. Patch from Vladimir 'phcoder' Serbinenko , thanks! (If it really is intended to ues I2C_MATCH_DIRECT_COMPATIBLE here, we need a clear explanation of why, written down in a nearby comment.) To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Wed May 10 00:10:02 UTC 2023 Modified Files: src/sys/dev/i2c: ims.c Log Message: ims(4): Use config_detach_children. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/ims.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/ims.c diff -u src/sys/dev/i2c/ims.c:1.4 src/sys/dev/i2c/ims.c:1.5 --- src/sys/dev/i2c/ims.c:1.4 Fri Jan 14 22:28:42 2022 +++ src/sys/dev/i2c/ims.c Wed May 10 00:10:02 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: ims.c,v 1.4 2022/01/14 22:28:42 riastradh Exp $ */ +/* $NetBSD: ims.c,v 1.5 2023/05/10 00:10:02 riastradh Exp $ */ /* $OpenBSD ims.c,v 1.1 2016/01/12 01:11:15 jcs Exp $ */ /* @@ -20,7 +20,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ims.c,v 1.4 2022/01/14 22:28:42 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ims.c,v 1.5 2023/05/10 00:10:02 riastradh Exp $"); #include #include @@ -146,16 +146,15 @@ ims_attach(device_t parent, device_t sel static int ims_detach(device_t self, int flags) { - struct ims_softc *sc = device_private(self); - int rv = 0; + int error; /* No need to do reference counting of ums, wsmouse has all the goo. */ - if (sc->sc_ms.hidms_wsmousedev != NULL) - rv = config_detach(sc->sc_ms.hidms_wsmousedev, flags); + error = config_detach_children(self, flags); + if (error) + return error; pmf_device_deregister(self); - - return rv; + return 0; } void
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Wed May 10 00:10:02 UTC 2023 Modified Files: src/sys/dev/i2c: ims.c Log Message: ims(4): Use config_detach_children. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/ims.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Tue Jan 24 07:09:48 UTC 2023 Modified Files: src/sys/dev/i2c: ds1307.c Log Message: Don't panic with invalid user data, just return an error. To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/sys/dev/i2c/ds1307.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/ds1307.c diff -u src/sys/dev/i2c/ds1307.c:1.39 src/sys/dev/i2c/ds1307.c:1.40 --- src/sys/dev/i2c/ds1307.c:1.39 Tue Aug 3 23:12:14 2021 +++ src/sys/dev/i2c/ds1307.c Tue Jan 24 07:09:48 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: ds1307.c,v 1.39 2021/08/03 23:12:14 andvar Exp $ */ +/* $NetBSD: ds1307.c,v 1.40 2023/01/24 07:09:48 mlelstv Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.39 2021/08/03 23:12:14 andvar Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.40 2023/01/24 07:09:48 mlelstv Exp $"); #include #include @@ -411,13 +411,12 @@ dsrtc_read(dev_t dev, struct uio *uio, i return ENXIO; const struct dsrtc_model * const dm = &sc->sc_model; - if (uio->uio_offset >= dm->dm_nvram_size) + if (uio->uio_offset < 0 || uio->uio_offset >= dm->dm_nvram_size) return EINVAL; if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) return error; - KASSERT(uio->uio_offset >= 0); while (uio->uio_resid && uio->uio_offset < dm->dm_nvram_size) { uint8_t ch, cmd; const u_int a = uio->uio_offset;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Tue Jan 24 07:09:48 UTC 2023 Modified Files: src/sys/dev/i2c: ds1307.c Log Message: Don't panic with invalid user data, just return an error. To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/sys/dev/i2c/ds1307.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: andvar Date: Mon Jan 23 22:20:59 UTC 2023 Modified Files: src/sys/dev/i2c: m41st84reg.h Log Message: fix typos in comments. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/m41st84reg.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/m41st84reg.h diff -u src/sys/dev/i2c/m41st84reg.h:1.3 src/sys/dev/i2c/m41st84reg.h:1.4 --- src/sys/dev/i2c/m41st84reg.h:1.3 Sun Dec 11 12:21:22 2005 +++ src/sys/dev/i2c/m41st84reg.h Mon Jan 23 22:20:59 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: m41st84reg.h,v 1.3 2005/12/11 12:21:22 christos Exp $ */ +/* $NetBSD: m41st84reg.h,v 1.4 2023/01/23 22:20:59 andvar Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -77,13 +77,13 @@ #define M41ST84_CONTROL_FT 0x40 /* Frequency test bit */ #define M41ST84_CONTROL_OUT 0x80 /* Output level */ -#define M41ST84_WATCHDOG_RB_MASK 0x03 /* Watchdog resulotion bits */ +#define M41ST84_WATCHDOG_RB_MASK 0x03 /* Watchdog resolution bits */ #define M41ST84_WATCHDOG_BMB_MASK 0x7c /* Watchdog multiplier bits */ #define M41ST84_WATCHDOG_WDS 0x80 /* Watchdog steering bit */ #define M41ST84_AL_MONTH_ABE 0x20 /* alarm in b-backup mode en */ #define M41ST84_AL_MONTH_SQWE 0x40 /* square wave enable */ -#define M41ST84_AL_MONTH_AFE 0x80 /* alarm flage enable */ +#define M41ST84_AL_MONTH_AFE 0x80 /* alarm flag enable */ #define M41ST84_AL_HOUR_HT 0x40 /* Halt Update Bit */
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: andvar Date: Mon Jan 23 22:20:59 UTC 2023 Modified Files: src/sys/dev/i2c: m41st84reg.h Log Message: fix typos in comments. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/m41st84reg.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: brad Date: Thu Dec 1 02:29:37 UTC 2022 Modified Files: src/sys/dev/i2c: bmx280.c Log Message: Use a better choice for the print format string. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/bmx280.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/bmx280.c diff -u src/sys/dev/i2c/bmx280.c:1.5 src/sys/dev/i2c/bmx280.c:1.6 --- src/sys/dev/i2c/bmx280.c:1.5 Thu Dec 1 00:47:51 2022 +++ src/sys/dev/i2c/bmx280.c Thu Dec 1 02:29:37 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: bmx280.c,v 1.5 2022/12/01 00:47:51 brad Exp $ */ +/* $NetBSD: bmx280.c,v 1.6 2022/12/01 02:29:37 brad Exp $ */ /* * Copyright (c) 2022 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bmx280.c,v 1.5 2022/12/01 00:47:51 brad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bmx280.c,v 1.6 2022/12/01 02:29:37 brad Exp $"); /* Driver for the Bosch BMP280/BME280 temperature, humidity (sometimes) and @@ -1065,10 +1065,10 @@ bmx280_refresh(struct sysmon_envsys * sm uint64_t q; q = (uint64_t)comp_hum * 100; - DPRINTF(sc, 1, ("%s: Refresh humidity Q 1: %lld\n", __func__, q)); + DPRINTF(sc, 1, ("%s: Refresh humidity Q 1: %jd\n", __func__, (uintmax_t)q)); q = q / 1024; - DPRINTF(sc, 1, ("%s: Refresh humidity Q 2: %lld\n", __func__, q)); + DPRINTF(sc, 1, ("%s: Refresh humidity Q 2: %jd\n", __func__, (uintmax_t)q)); edata->value_cur = (uint32_t) q; edata->state = ENVSYS_SVALID;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: brad Date: Thu Dec 1 02:29:37 UTC 2022 Modified Files: src/sys/dev/i2c: bmx280.c Log Message: Use a better choice for the print format string. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/bmx280.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: brad Date: Thu Dec 1 00:47:51 UTC 2022 Modified Files: src/sys/dev/i2c: bmx280.c Log Message: Correct the humidity conversion for the BME280 To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/bmx280.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/bmx280.c diff -u src/sys/dev/i2c/bmx280.c:1.4 src/sys/dev/i2c/bmx280.c:1.5 --- src/sys/dev/i2c/bmx280.c:1.4 Thu Nov 24 21:07:05 2022 +++ src/sys/dev/i2c/bmx280.c Thu Dec 1 00:47:51 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: bmx280.c,v 1.4 2022/11/24 21:07:05 brad Exp $ */ +/* $NetBSD: bmx280.c,v 1.5 2022/12/01 00:47:51 brad Exp $ */ /* * Copyright (c) 2022 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bmx280.c,v 1.4 2022/11/24 21:07:05 brad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bmx280.c,v 1.5 2022/12/01 00:47:51 brad Exp $"); /* Driver for the Bosch BMP280/BME280 temperature, humidity (sometimes) and @@ -277,8 +277,7 @@ bmx280_store_raw_blob_h(struct bmx280_sc sc->sc_cal_blob.dig_H2 = (int16_t)b[2] << 8; sc->sc_cal_blob.dig_H2 = sc->sc_cal_blob.dig_H2 | (int16_t)b[1]; sc->sc_cal_blob.dig_H3 = (uint8_t)b[3]; - sc->sc_cal_blob.dig_H4 = ((int16_t)b[5] & 0x000f) << 8; - sc->sc_cal_blob.dig_H4 = sc->sc_cal_blob.dig_H4 | (int16_t)b[4]; + sc->sc_cal_blob.dig_H4 = ((int16_t)((b[4] << 4) | (b[5] & 0x0F))); sc->sc_cal_blob.dig_H5 = (int16_t)b[6] << 4; sc->sc_cal_blob.dig_H5 = sc->sc_cal_blob.dig_H5 | (((int16_t)b[5] & 0x00f0) >> 4); sc->sc_cal_blob.dig_H6 = (int8_t)b[7]; @@ -566,6 +565,13 @@ bmx280_attach(device_t parent, device_t error); } + if (sc->sc_bmx280debug > 0) { + for(int _d = 0;_d < 24;_d++) { + DPRINTF(sc, 0, ("%s: %d %02x\n", + device_xname(sc->sc_dev), _d, raw_blob_tp[_d])); + } + } + bmx280_store_raw_blob_tp(sc,raw_blob_tp); if (sc->sc_has_humidity) { @@ -585,6 +591,13 @@ bmx280_attach(device_t parent, device_t error); } + if (sc->sc_bmx280debug > 0) { + for(int _d = 0;_d < 8;_d++) { +DPRINTF(sc, 0, ("%s: %d %02x\n", +device_xname(sc->sc_dev), _d, raw_blob_h[_d])); + } + } + bmx280_store_raw_blob_h(sc,raw_blob_h); } @@ -1049,15 +1062,15 @@ bmx280_refresh(struct sysmon_envsys * sm DPRINTF(sc, 2, ("%s: Refresh compensated humidity: %d\n", device_xname(sc->sc_dev), comp_hum)); - uint32_t q; + uint64_t q; - q = comp_hum; + q = (uint64_t)comp_hum * 100; + DPRINTF(sc, 1, ("%s: Refresh humidity Q 1: %lld\n", __func__, q)); q = q / 1024; - q = q * 100; /* XXX - this probably is not correct */ - DPRINTF(sc, 1, ("%s: Refresh humidity Q: %d\n", __func__, q)); + DPRINTF(sc, 1, ("%s: Refresh humidity Q 2: %lld\n", __func__, q)); - edata->value_cur = q; + edata->value_cur = (uint32_t) q; edata->state = ENVSYS_SVALID; } }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: brad Date: Thu Dec 1 00:47:51 UTC 2022 Modified Files: src/sys/dev/i2c: bmx280.c Log Message: Correct the humidity conversion for the BME280 To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/bmx280.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: brad Date: Thu Nov 24 21:07:05 UTC 2022 Modified Files: src/sys/dev/i2c: bmx280.c Log Message: Mention where in the datasheet the compensation algorithms came from. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/bmx280.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/bmx280.c diff -u src/sys/dev/i2c/bmx280.c:1.3 src/sys/dev/i2c/bmx280.c:1.4 --- src/sys/dev/i2c/bmx280.c:1.3 Wed Nov 23 23:45:29 2022 +++ src/sys/dev/i2c/bmx280.c Thu Nov 24 21:07:05 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: bmx280.c,v 1.3 2022/11/23 23:45:29 brad Exp $ */ +/* $NetBSD: bmx280.c,v 1.4 2022/11/24 21:07:05 brad Exp $ */ /* * Copyright (c) 2022 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bmx280.c,v 1.3 2022/11/23 23:45:29 brad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bmx280.c,v 1.4 2022/11/24 21:07:05 brad Exp $"); /* Driver for the Bosch BMP280/BME280 temperature, humidity (sometimes) and @@ -643,8 +643,13 @@ out: sc->sc_sme = NULL; } -/* The conversion algorithms are taken from the Bosch datasheet for - * the BMX280 and adapted to the envsys infrastructure. +/* The conversion algorithms are taken from the BMP280 datasheet. The + * same algorithms are used with the BME280. + * + * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp280-ds001.pdf + * + * Section 3.11.3, page 21 + * */ static int32_t
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: brad Date: Thu Nov 24 21:07:05 UTC 2022 Modified Files: src/sys/dev/i2c: bmx280.c Log Message: Mention where in the datasheet the compensation algorithms came from. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/bmx280.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/sys/dev/i2c
Taylor R Campbell writes: [snip] > The issue here isn't the duration of the delay -- just the mechanism. > Sleeping for 35ms with kpause(9) is fine, but busy-waiting on the CPU > for 35ms with delay(9) is not (unless HZ is set to something absurdly > low like 10 instead of the usual 100, but I doubt that's an important > use-case to consider here). > > In this case, you should use: > > kpause("bmx280", /*intr*/false, MAX(1, mstohz(35)), NULL); All understood.. the above, however, was not quite right either. That delay is related to the over sampling that is set and wasn't a fixed value. I made adjustments to scale the amount of time actually needed to wait with the over sampling setting. This is the proper thing that needed to be done in this case. I do agree that kpause is a better thing to use here too.. no doubt.. There wasn't any real documentation about this, but it clearly was something that needed to be considered. The only reference was a single table that listed some of the typical and max durations for just *SOME* of the over sampling setting (worse, yet, this table was removed from later versions of the docs). It left out a lot and did not include any sort of formula. Though some experimentation I can up with one that should be workable and allowed for some tuning if it wasn't quite right. >> was, as one might say, a "surprising development" as the documentation >> really does not hint that this sort of thing goes on (or was even >> possible to do). > > Can you put a link to the documentation in the source code, and cite > the sections where you get the complicated formulas like in > bmx280_compensate_P_int64? Ya, I can do that. The three compensation formulas are pulled mostly literally from the docs. All I really did was changed the types to match the kernel names and unglobal'ed some of the variables for the factory calibration settings. Peeking at Adafruit's Ardunio code, they did the same thing. -- Brad Spencer - b...@anduin.eldar.org - KC8VKS - http://anduin.eldar.org
Re: CVS commit: src/sys/dev/i2c
> Date: Wed, 23 Nov 2022 01:42:13 -0500 > From: Brad Spencer > > Simon Burge writes: > > > + delay(35000); > > > > This will spin for 35 milliseconds (per sensor read if I read this > > correctly). Can you please look at using kpause(9) for this delay? > > See some other i2c drivers for examples of this. > > Probably possible, may be a couple of days before I can get to > it (or not, depends on how holiday prep goes)... > > I have used some of the cv_timedwait stuff in the past and didn't know > about kpause which seems to be suited to what I need to do. Almost all > sensor chips require some sort of wait after a command is sent, but this > one was particularly frustrating about it. The issue here isn't the duration of the delay -- just the mechanism. Sleeping for 35ms with kpause(9) is fine, but busy-waiting on the CPU for 35ms with delay(9) is not (unless HZ is set to something absurdly low like 10 instead of the usual 100, but I doubt that's an important use-case to consider here). In this case, you should use: kpause("bmx280", /*intr*/false, MAX(1, mstohz(35)), NULL); > This > was, as one might say, a "surprising development" as the documentation > really does not hint that this sort of thing goes on (or was even > possible to do). Can you put a link to the documentation in the source code, and cite the sections where you get the complicated formulas like in bmx280_compensate_P_int64?
Re: CVS commit: src/sys/dev/i2c
Simon Burge writes: > Hi Brad, > >> Module Name: src >> Committed By:brad >> Date:Tue Nov 22 19:40:31 UTC 2022 >> >> Modified Files: >> >> src/sys/dev/i2c: bmx280.c >> >> Log Message: >> >> Read the datasheet more closely and put in some delays. The chip will >> just return junk if the wait is not long enough to allow a measurement >> to start. > > > + /* Hmm... this delay is not documented well.. mostly just a guess... > +* If it is too short, you will get junk returned as it is possible > to try > +* to ask for the data before the chip has even started... it seems... > +*/ > + delay(35000); > > This will spin for 35 milliseconds (per sensor read if I read this > correctly). Can you please look at using kpause(9) for this delay? > See some other i2c drivers for examples of this. > > Cheers, > Simon. Probably possible, may be a couple of days before I can get to it (or not, depends on how holiday prep goes)... I have used some of the cv_timedwait stuff in the past and didn't know about kpause which seems to be suited to what I need to do. Almost all sensor chips require some sort of wait after a command is sent, but this one was particularly frustrating about it. To give out too much information, all of the other sensors I have worked with NACK the I2C bus during the measurement cycle. This one, and probably all of Bosch's chips, do not do that. You have to read back a status register and check to see if it is busy doing something or other. If you just go ahead and read the data registers when it is busy you get junk with no hint that it is junk. But a big "however" is that it is possible (even for a RPI) to read the status register BEFORE the chip has even started to do its measurements, get a positive response (i.e. not busy) and then read the data registers and get junk. This was, as one might say, a "surprising development" as the documentation really does not hint that this sort of thing goes on (or was even possible to do). -- Brad Spencer - b...@anduin.eldar.org - KC8VKS - http://anduin.eldar.org
Re: CVS commit: src/sys/dev/i2c
Hi Brad, > Module Name: src > Committed By: brad > Date: Tue Nov 22 19:40:31 UTC 2022 > > Modified Files: > > src/sys/dev/i2c: bmx280.c > > Log Message: > > Read the datasheet more closely and put in some delays. The chip will > just return junk if the wait is not long enough to allow a measurement > to start. + /* Hmm... this delay is not documented well.. mostly just a guess... +* If it is too short, you will get junk returned as it is possible to try +* to ask for the data before the chip has even started... it seems... +*/ + delay(35000); This will spin for 35 milliseconds (per sensor read if I read this correctly). Can you please look at using kpause(9) for this delay? See some other i2c drivers for examples of this. Cheers, Simon.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: brad Date: Tue Nov 22 19:40:31 UTC 2022 Modified Files: src/sys/dev/i2c: bmx280.c Log Message: Read the datasheet more closely and put in some delays. The chip will just return junk if the wait is not long enough to allow a measurement to start. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/bmx280.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/bmx280.c diff -u src/sys/dev/i2c/bmx280.c:1.1 src/sys/dev/i2c/bmx280.c:1.2 --- src/sys/dev/i2c/bmx280.c:1.1 Mon Nov 21 21:24:01 2022 +++ src/sys/dev/i2c/bmx280.c Tue Nov 22 19:40:31 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: bmx280.c,v 1.1 2022/11/21 21:24:01 brad Exp $ */ +/* $NetBSD: bmx280.c,v 1.2 2022/11/22 19:40:31 brad Exp $ */ /* * Copyright (c) 2022 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bmx280.c,v 1.1 2022/11/21 21:24:01 brad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bmx280.c,v 1.2 2022/11/22 19:40:31 brad Exp $"); /* Driver for the Bosch BMP280/BME280 temperature, humidity (sometimes) and @@ -501,7 +501,7 @@ bmx280_attach(device_t parent, device_t error); } - delay(100); + delay(3); reg = BMX280_REGISTER_ID; error = bmx280_read_register(sc->sc_tag, sc->sc_addr, ®, &chip_id, 1); @@ -510,7 +510,7 @@ bmx280_attach(device_t parent, device_t error); } - delay(100); + delay(1000); DPRINTF(sc, 2, ("%s: read ID value: %02x\n", device_xname(sc->sc_dev), chip_id)); @@ -718,6 +718,12 @@ bmx280_set_control_and_trigger(struct bm error = EINVAL; } + /* Hmm... this delay is not documented well.. mostly just a guess... + * If it is too short, you will get junk returned as it is possible to try + * to ask for the data before the chip has even started... it seems... + */ + delay(35000); + return error; } @@ -731,7 +737,7 @@ bmx280_wait_for_data(struct bmx280_sc *s reg = BMX280_REGISTER_STATUS; do { - delay(10); + delay(1000); ierror = bmx280_read_register(sc->sc_tag, sc->sc_addr, ®, &running, 1); if (ierror) { DPRINTF(sc, 2, ("%s: Refresh failed to read back status: %d\n",
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: brad Date: Tue Nov 22 19:40:31 UTC 2022 Modified Files: src/sys/dev/i2c: bmx280.c Log Message: Read the datasheet more closely and put in some delays. The chip will just return junk if the wait is not long enough to allow a measurement to start. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/bmx280.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun Oct 30 11:51:20 UTC 2022 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: Add GPIO support. PR# kern/57030 To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun Oct 30 11:51:20 UTC 2022 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: Add GPIO support. PR# kern/57030 To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 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.36 src/sys/dev/i2c/axppmic.c:1.37 --- src/sys/dev/i2c/axppmic.c:1.36 Sat Aug 7 16:19:11 2021 +++ src/sys/dev/i2c/axppmic.c Sun Oct 30 11:51:19 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.36 2021/08/07 16:19:11 thorpej Exp $ */ +/* $NetBSD: axppmic.c,v 1.37 2022/10/30 11:51:19 jmcneill Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.36 2021/08/07 16:19:11 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.37 2022/10/30 11:51:19 jmcneill Exp $"); #include #include @@ -79,6 +79,13 @@ __KERNEL_RCSID(0, "$NetBSD: axppmic.c,v #define AXP_ADC_RAW(_hi, _lo) \ (((u_int)(_hi) << 4) | ((_lo) & 0xf)) +#define AXP_GPIO_CTRL_REG(pin) (0x90 + (pin) * 2) +#define AXP_GPIO_CTRL_FUNC_MASK __BITS(2,0) +#define AXP_GPIO_CTRL_FUNC_LOW 0 +#define AXP_GPIO_CTRL_FUNC_HIGH 1 +#define AXP_GPIO_CTRL_FUNC_INPUT 2 +#define AXP_GPIO_SIGNAL_REG 0x94 + #define AXP_FUEL_GAUGE_CTRL_REG 0xb8 #define AXP_FUEL_GAUGE_CTRL_EN __BIT(7) @@ -327,6 +334,8 @@ struct axppmic_irq { struct axppmic_config { const char *name; + const char *gpio_compat; + u_int gpio_npins; const struct axppmic_ctrl *controls; u_int ncontrols; u_int irq_regs; @@ -386,6 +395,13 @@ struct axppmic_softc { u_int sc_shut_thres; }; +struct axppmic_gpio_pin { + struct axppmic_softc *pin_sc; + u_int pin_nr; + int pin_flags; + bool pin_actlo; +}; + struct axpreg_softc { device_t sc_dev; i2c_tag_t sc_i2c; @@ -402,6 +418,8 @@ struct axpreg_attach_args { static const struct axppmic_config axp803_config = { .name = "AXP803", + .gpio_compat = "x-powers,axp803-gpio", + .gpio_npins = 2, .controls = axp803_ctrls, .ncontrols = __arraycount(axp803_ctrls), .irq_regs = 6, @@ -447,6 +465,8 @@ static const struct axppmic_config axp80 static const struct axppmic_config axp813_config = { .name = "AXP813", + .gpio_compat = "x-powers,axp813-gpio", + .gpio_npins = 2, .controls = axp813_ctrls, .ncontrols = __arraycount(axp813_ctrls), .irq_regs = 6, @@ -583,6 +603,132 @@ static struct fdtbus_power_controller_fu .poweroff = axppmic_power_poweroff, }; +static int +axppmic_gpio_ctl(struct axppmic_softc *sc, uint8_t pin, uint8_t func) +{ + uint8_t val; + int error; + + KASSERT(pin < sc->sc_conf->gpio_npins); + KASSERT((func & ~AXP_GPIO_CTRL_FUNC_MASK) == 0); + + iic_acquire_bus(sc->sc_i2c, 0); + error = axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_GPIO_CTRL_REG(pin), + &val, 0); + if (error == 0) { + val &= ~AXP_GPIO_CTRL_FUNC_MASK; + val |= func; + error = axppmic_write(sc->sc_i2c, sc->sc_addr, + AXP_GPIO_CTRL_REG(pin), val, 0); + } + iic_release_bus(sc->sc_i2c, 0); + + return error; +} + +static void * +axppmic_gpio_acquire(device_t dev, const void *data, size_t len, int flags) +{ + struct axppmic_softc *sc = device_private(dev); + struct axppmic_gpio_pin *gpin; + const u_int *gpio = data; + int error; + + if (len != 12) { + return NULL; + } + + const uint8_t pin = be32toh(gpio[1]) & 0xff; + const bool actlo = be32toh(gpio[2]) & 1; + + if (pin >= sc->sc_conf->gpio_npins) { + return NULL; + } + + if ((flags & GPIO_PIN_INPUT) != 0) { + error = axppmic_gpio_ctl(sc, pin, AXP_GPIO_CTRL_FUNC_INPUT); + if (error != 0) { + return NULL; + } + } + + gpin = kmem_zalloc(sizeof(*gpin), KM_SLEEP); + gpin->pin_sc = sc; + gpin->pin_nr = pin; + gpin->pin_flags = flags; + gpin->pin_actlo = actlo; + + return gpin; +} + +static void +axppmic_gpio_release(device_t dev, void *priv) +{ + struct axppmic_softc *sc = device_private(dev); + struct axppmic_gpio_pin *gpin = priv; + + axppmic_gpio_ctl(sc, gpin->pin_nr, AXP_GPIO_CTRL_FUNC_INPUT); + + kmem_free(gpin, sizeof(*gpin)); +} + +static int +axppmic_gpio_read(device_t dev, void *priv, bool raw) +{ + struct axppmic_softc *sc = device_private(dev); + struct axppmic_gpio_pin *gpin = priv; + uint8_t data; + int error, val; + + KASSERT(sc == gpin->pin_sc); + + const uint8_t data_mask = __BIT(gpin->pin_nr); + + iic_acquire_bus(sc->sc_i2c, 0); + error = axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_GPIO_SIGNAL_REG, + &data, 0); + iic_release_bus(sc->sc_i2c, 0); + + if (error != 0) { + device_printf(dev, "WARNING: failed to read pin %d: %d\n", + gpin->pin_nr, error); + val = 0; + } else { + val = __SHIFTOUT(data, data_mask); + } + if (!raw && gpin->pin_actlo) { + val = !val; + } + + return val; +} + +static void +axppmic_gpio_write(device_t dev, void *priv, int val, bool raw) +{ + struct axppmic_softc *sc = device_pr
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Mon Oct 24 10:17:40 UTC 2022 Modified Files: src/sys/dev/i2c: i2c.c Log Message: iic(4): Use config_detach_children to simplify. To generate a diff of this commit: cvs rdiff -u -r1.89 -r1.90 src/sys/dev/i2c/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/i2c.c diff -u src/sys/dev/i2c/i2c.c:1.89 src/sys/dev/i2c/i2c.c:1.90 --- src/sys/dev/i2c/i2c.c:1.89 Mon Oct 24 10:17:27 2022 +++ src/sys/dev/i2c/i2c.c Mon Oct 24 10:17:40 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.89 2022/10/24 10:17:27 riastradh Exp $ */ +/* $NetBSD: i2c.c,v 1.90 2022/10/24 10:17:40 riastradh Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -53,7 +53,7 @@ #endif /* _KERNEL_OPT */ #include -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.89 2022/10/24 10:17:27 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.90 2022/10/24 10:17:40 riastradh Exp $"); #include #include @@ -543,16 +543,11 @@ iic_attach(device_t parent, device_t sel static int iic_detach(device_t self, int flags) { - struct iic_softc *sc = device_private(self); - int i, error; + int error; - for (i = 0; i <= I2C_MAX_ADDR; i++) { - if (sc->sc_devices[i]) { - error = config_detach(sc->sc_devices[i], flags); - if (error) -return error; - } - } + error = config_detach_children(self, flags); + if (error) + return error; pmf_device_deregister(self);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Mon Oct 24 10:17:40 UTC 2022 Modified Files: src/sys/dev/i2c: i2c.c Log Message: iic(4): Use config_detach_children to simplify. To generate a diff of this commit: cvs rdiff -u -r1.89 -r1.90 src/sys/dev/i2c/i2c.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sat Jul 23 03:05:27 UTC 2022 Modified Files: src/sys/dev/i2c: i2c.c Log Message: If there is a compat string list, parenthetically print the first one in iic_print_direct(). (From thorpej-i2c-spi-conf2 branch.) To generate a diff of this commit: cvs rdiff -u -r1.87 -r1.88 src/sys/dev/i2c/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/i2c.c diff -u src/sys/dev/i2c/i2c.c:1.87 src/sys/dev/i2c/i2c.c:1.88 --- src/sys/dev/i2c/i2c.c:1.87 Wed Jun 29 15:33:45 2022 +++ src/sys/dev/i2c/i2c.c Sat Jul 23 03:05:27 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.87 2022/06/29 15:33:45 mlelstv Exp $ */ +/* $NetBSD: i2c.c,v 1.88 2022/07/23 03:05:27 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -53,7 +53,7 @@ #endif /* _KERNEL_OPT */ #include -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.87 2022/06/29 15:33:45 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.88 2022/07/23 03:05:27 thorpej Exp $"); #include #include @@ -129,8 +129,11 @@ iic_print_direct(void *aux, const char * struct i2c_attach_args *ia = aux; if (pnp != NULL) - aprint_normal("%s at %s addr 0x%02x", + aprint_normal("%s%s%s%s at %s addr 0x%02x", ia->ia_name ? ia->ia_name : "(unknown)", + ia->ia_ncompat ? " (" : "", + ia->ia_ncompat ? ia->ia_compat[0] : "", + ia->ia_ncompat ? ")" : "", pnp, ia->ia_addr); else aprint_normal(" addr 0x%02x", ia->ia_addr);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sat Jul 23 03:05:27 UTC 2022 Modified Files: src/sys/dev/i2c: i2c.c Log Message: If there is a compat string list, parenthetically print the first one in iic_print_direct(). (From thorpej-i2c-spi-conf2 branch.) To generate a diff of this commit: cvs rdiff -u -r1.87 -r1.88 src/sys/dev/i2c/i2c.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Wed Jul 20 22:58:35 UTC 2022 Modified Files: src/sys/dev/i2c: pcai2cmux.c Log Message: Improve error reporting. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Wed Jul 20 22:58:35 UTC 2022 Modified Files: src/sys/dev/i2c: pcai2cmux.c Log Message: Improve error reporting. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 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.8 src/sys/dev/i2c/pcai2cmux.c:1.9 --- src/sys/dev/i2c/pcai2cmux.c:1.8 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/pcai2cmux.c Wed Jul 20 22:58:35 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: pcai2cmux.c,v 1.8 2021/01/27 02:29:48 thorpej Exp $ */ +/* $NetBSD: pcai2cmux.c,v 1.9 2022/07/20 22:58:35 thorpej Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: pcai2cmux.c,v 1.8 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcai2cmux.c,v 1.9 2022/07/20 22:58:35 thorpej Exp $"); /* * Driver for NXP PCA954x / PCA984x I2C switches and multiplexers. @@ -278,8 +278,14 @@ pcaiicmux_acquire_bus(struct iicmux_bus { struct pcaiicmux_softc * const sc = bus->mux->sc_mux_data; struct pcaiicmux_bus_info * const bus_info = bus->bus_data; + int error; - return pcaiicmux_write(sc, bus_info->enable_value, flags); + error = pcaiicmux_write(sc, bus_info->enable_value, flags); + if (error) { + printf("%s: %s: pcaiicmux_write failed (error = %d)\n", + device_xname(sc->sc_iicmux.sc_dev), __func__, error); + } + return error; } static void @@ -288,7 +294,14 @@ pcaiicmux_release_bus(struct iicmux_bus struct pcaiicmux_softc * const sc = bus->mux->sc_mux_data; if (sc->sc_idle_disconnect) { - (void) pcaiicmux_write(sc, 0, flags); + int error; + + error = pcaiicmux_write(sc, 0, flags); + if (error) { + printf("%s: %s: pcaiicmux_write failed (error = %d)\n", + device_xname(sc->sc_iicmux.sc_dev), __func__, + error); + } } } @@ -371,14 +384,16 @@ pcaiicmux_attach(device_t parent, device sc->sc_cur_value = -1; error = iic_acquire_bus(ia->ia_tag, 0); if (error) { - aprint_error_dev(self, "failed to acquire I2C bus\n"); + aprint_error_dev(self, + "failed to acquire I2C bus (error = %d)\n", error); return; } error = pcaiicmux_write(sc, 0, 0); iic_release_bus(ia->ia_tag, 0); if (error) { aprint_error_dev(self, - "failed to set mux to disconnected state\n"); + "failed to set mux to disconnected state (error = %d)\n", + error); return; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: andvar Date: Sat Jul 2 16:28:39 UTC 2022 Modified Files: src/sys/dev/i2c: lm87.c Log Message: s/tempurature/temperature/ To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 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/lm87.c diff -u src/sys/dev/i2c/lm87.c:1.15 src/sys/dev/i2c/lm87.c:1.16 --- src/sys/dev/i2c/lm87.c:1.15 Sun Jun 13 09:46:04 2021 +++ src/sys/dev/i2c/lm87.c Sat Jul 2 16:28:39 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: lm87.c,v 1.15 2021/06/13 09:46:04 mlelstv Exp $ */ +/* $NetBSD: lm87.c,v 1.16 2022/07/02 16:28:39 andvar 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.15 2021/06/13 09:46:04 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm87.c,v 1.16 2022/07/02 16:28:39 andvar Exp $"); #include #include @@ -43,7 +43,7 @@ __KERNEL_RCSID(0, "$NetBSD: lm87.c,v 1.1 #define LM87_5V 0x23 /* +5V reading */ #define LM87_12V 0x24 /* +12V reading */ #define LM87_VCCP2 0x25 /* Vccp2 reading */ -#define LM87_EXT_TEMP 0x26 /* External tempurature 1 reading */ +#define LM87_EXT_TEMP 0x26 /* External temperature 1 reading */ #define LM87_INT_TEMP 0x27 /* Internal temperature reading */ #define LM87_FAN1 0x28 /* Fan1 or AIN1 reading */ #define LM87_FAN2 0x29 /* Fan2 or AIN2 reading */ @@ -59,10 +59,10 @@ __KERNEL_RCSID(0, "$NetBSD: lm87.c,v 1.1 #define LM87_12V_LOW 0x34 /* +12V low limit */ #define LM87_VCCP2_HIGH 0x35 /* Vccp2 high limit */ #define LM87_VCCP2_LOW 0x36 /* Vccp2 low limit */ -#define LM87_EXT_HIGH 0x37 /* External tempurature 1 high limit */ -#define LM87_EXT_LOW 0x38 /* External tempurature low limit */ -#define LM87_INT_HIGH 0x39 /* Internal tempurature 1 high limit */ -#define LM87_INT_LOW 0x3a /* Internal tempurature low limit */ +#define LM87_EXT_HIGH 0x37 /* External temperature 1 high limit */ +#define LM87_EXT_LOW 0x38 /* External temperature low limit */ +#define LM87_INT_HIGH 0x39 /* Internal temperature 1 high limit */ +#define LM87_INT_LOW 0x3a /* Internal temperature low limit */ #define LM87_FAN1_HIGH 0x3b /* Fan 1 count or AIN1 high limit */ #define LM87_FAN2_HIGH 0x3c /* Fan 2 count or AIN2 high limit */ #define LM87_COMPANY_ID 0x3e /* Company ID */
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: andvar Date: Sat Jul 2 16:28:39 UTC 2022 Modified Files: src/sys/dev/i2c: lm87.c Log Message: s/tempurature/temperature/ To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Wed Jun 29 15:34:15 UTC 2022 Modified Files: src/sys/dev/i2c: i2c_io.h Log Message: Bump max transaction size from 32 Bytes to 4kB. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/i2c_io.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/i2c_io.h diff -u src/sys/dev/i2c/i2c_io.h:1.4 src/sys/dev/i2c/i2c_io.h:1.5 --- src/sys/dev/i2c/i2c_io.h:1.4 Sat Oct 28 06:27:32 2017 +++ src/sys/dev/i2c/i2c_io.h Wed Jun 29 15:34:15 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c_io.h,v 1.4 2017/10/28 06:27:32 riastradh Exp $ */ +/* $NetBSD: i2c_io.h,v 1.5 2022/06/29 15:34:15 mlelstv Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -99,8 +99,8 @@ typedef struct i2c_ioctl_exec { void *iie_buf; /* pointer to data buffer */ size_t iie_buflen; /* length of data buffer */ } i2c_ioctl_exec_t; -#define I2C_EXEC_MAX_CMDLEN 32 -#define I2C_EXEC_MAX_BUFLEN 32 +#define I2C_EXEC_MAX_CMDLEN 4096 +#define I2C_EXEC_MAX_BUFLEN 4096 #define I2C_IOCTL_EXEC _IOW('I', 0, i2c_ioctl_exec_t)
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Wed Jun 29 15:34:15 UTC 2022 Modified Files: src/sys/dev/i2c: i2c_io.h Log Message: Bump max transaction size from 32 Bytes to 4kB. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/i2c_io.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Wed Jun 29 15:33:45 UTC 2022 Modified Files: src/sys/dev/i2c: i2c.c Log Message: Allocate data buffer instead of using the stack. To generate a diff of this commit: cvs rdiff -u -r1.86 -r1.87 src/sys/dev/i2c/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/i2c.c diff -u src/sys/dev/i2c/i2c.c:1.86 src/sys/dev/i2c/i2c.c:1.87 --- src/sys/dev/i2c/i2c.c:1.86 Fri Apr 1 15:49:12 2022 +++ src/sys/dev/i2c/i2c.c Wed Jun 29 15:33:45 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.86 2022/04/01 15:49:12 pgoyette Exp $ */ +/* $NetBSD: i2c.c,v 1.87 2022/06/29 15:33:45 mlelstv Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -53,7 +53,7 @@ #endif /* _KERNEL_OPT */ #include -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.86 2022/04/01 15:49:12 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.87 2022/06/29 15:33:45 mlelstv Exp $"); #include #include @@ -819,7 +819,7 @@ static int iic_ioctl_exec(struct iic_softc *sc, i2c_ioctl_exec_t *iie, int flag) { i2c_tag_t ic = sc->sc_tag; - uint8_t buf[I2C_EXEC_MAX_BUFLEN]; + uint8_t *buf = NULL; void *cmd = NULL; int error; @@ -849,10 +849,13 @@ iic_ioctl_exec(struct iic_softc *sc, i2c goto out; } - if (iie->iie_buf != NULL && I2C_OP_WRITE_P(iie->iie_op)) { - error = copyin(iie->iie_buf, buf, iie->iie_buflen); - if (error) - goto out; + if (iie->iie_buf != NULL) { + buf = kmem_alloc(iie->iie_buflen, KM_SLEEP); + if (I2C_OP_WRITE_P(iie->iie_op)) { + error = copyin(iie->iie_buf, buf, iie->iie_buflen); + if (error) +goto out; + } } iic_acquire_bus(ic, 0); @@ -867,15 +870,18 @@ iic_ioctl_exec(struct iic_softc *sc, i2c error = EIO; out: + if (iie->iie_buf != NULL && I2C_OP_READ_P(iie->iie_op)) + error = copyout(buf, iie->iie_buf, iie->iie_buflen); + + if (buf) + kmem_free(buf, iie->iie_buflen); + if (cmd) kmem_free(cmd, iie->iie_cmdlen); if (error) return error; - if (iie->iie_buf != NULL && I2C_OP_READ_P(iie->iie_op)) - error = copyout(buf, iie->iie_buf, iie->iie_buflen); - return error; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Wed Jun 29 15:33:45 UTC 2022 Modified Files: src/sys/dev/i2c: i2c.c Log Message: Allocate data buffer instead of using the stack. To generate a diff of this commit: cvs rdiff -u -r1.86 -r1.87 src/sys/dev/i2c/i2c.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: pgoyette Date: Wed Mar 30 00:06:51 UTC 2022 Modified Files: src/sys/dev/i2c: am2315.c dbcool.c hytp14.c scmdi2c.c sgp40.c sht3x.c sht4x.c si70xx.c spdmem_i2c.c Log Message: These modules need to depend on iic, not just on i2cexec. (They will still recursively get i2cexec since the iic depends on it.) Partial fix for kern/56772 To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/am2315.c cvs rdiff -u -r1.63 -r1.64 src/sys/dev/i2c/dbcool.c cvs rdiff -u -r1.14 -r1.15 src/sys/dev/i2c/hytp14.c cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/scmdi2c.c cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/sgp40.c src/sys/dev/i2c/sht4x.c cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/sht3x.c cvs rdiff -u -r1.10 -r1.11 src/sys/dev/i2c/si70xx.c cvs rdiff -u -r1.25 -r1.26 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/am2315.c diff -u src/sys/dev/i2c/am2315.c:1.6 src/sys/dev/i2c/am2315.c:1.7 --- src/sys/dev/i2c/am2315.c:1.6 Tue Jun 15 04:40:13 2021 +++ src/sys/dev/i2c/am2315.c Wed Mar 30 00:06:50 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: am2315.c,v 1.6 2021/06/15 04:40:13 mlelstv Exp $ */ +/* $NetBSD: am2315.c,v 1.7 2022/03/30 00:06:50 pgoyette Exp $ */ /* * Copyright (c) 2017 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: am2315.c,v 1.6 2021/06/15 04:40:13 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: am2315.c,v 1.7 2022/03/30 00:06:50 pgoyette Exp $"); /* * Driver for the Aosong AM2315 @@ -475,7 +475,7 @@ am2315_detach(device_t self, int flags) return 0; } -MODULE(MODULE_CLASS_DRIVER, am2315temp, "i2cexec,sysmon_envsys"); +MODULE(MODULE_CLASS_DRIVER, am2315temp, "iic,sysmon_envsys"); #ifdef _MODULE #include "ioconf.c" Index: src/sys/dev/i2c/dbcool.c diff -u src/sys/dev/i2c/dbcool.c:1.63 src/sys/dev/i2c/dbcool.c:1.64 --- src/sys/dev/i2c/dbcool.c:1.63 Mon Aug 9 20:49:09 2021 +++ src/sys/dev/i2c/dbcool.c Wed Mar 30 00:06:50 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: dbcool.c,v 1.63 2021/08/09 20:49:09 andvar Exp $ */ +/* $NetBSD: dbcool.c,v 1.64 2022/03/30 00:06:50 pgoyette Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -50,7 +50,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.63 2021/08/09 20:49:09 andvar Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.64 2022/03/30 00:06:50 pgoyette Exp $"); #include #include @@ -2189,7 +2189,7 @@ dbcool_set_fan_limits(struct dbcool_soft } } -MODULE(MODULE_CLASS_DRIVER, dbcool, "i2cexec,sysmon_envsys"); +MODULE(MODULE_CLASS_DRIVER, dbcool, "iic,sysmon_envsys"); #ifdef _MODULE #include "ioconf.c" Index: src/sys/dev/i2c/hytp14.c diff -u src/sys/dev/i2c/hytp14.c:1.14 src/sys/dev/i2c/hytp14.c:1.15 --- src/sys/dev/i2c/hytp14.c:1.14 Tue Jun 15 04:39:49 2021 +++ src/sys/dev/i2c/hytp14.c Wed Mar 30 00:06:50 2022 @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.14 2021/06/15 04:39:49 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.15 2022/03/30 00:06:50 pgoyette Exp $"); #include #include @@ -487,7 +487,7 @@ sysctl_hytp14_interval(SYSCTLFN_ARGS) return 0; } -MODULE(MODULE_CLASS_DRIVER, hythygtemp, "i2cexec,sysmon_envsys"); +MODULE(MODULE_CLASS_DRIVER, hythygtemp, "iic,sysmon_envsys"); #ifdef _MODULE #include "ioconf.c" Index: src/sys/dev/i2c/scmdi2c.c diff -u src/sys/dev/i2c/scmdi2c.c:1.1 src/sys/dev/i2c/scmdi2c.c:1.2 --- src/sys/dev/i2c/scmdi2c.c:1.1 Tue Dec 7 17:39:54 2021 +++ src/sys/dev/i2c/scmdi2c.c Wed Mar 30 00:06:50 2022 @@ -1,5 +1,5 @@ -/* $NetBSD: scmdi2c.c,v 1.1 2021/12/07 17:39:54 brad Exp $ */ +/* $NetBSD: scmdi2c.c,v 1.2 2022/03/30 00:06:50 pgoyette Exp $ */ /* * Copyright (c) 2021 Brad Spencer @@ -18,7 +18,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: scmdi2c.c,v 1.1 2021/12/07 17:39:54 brad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: scmdi2c.c,v 1.2 2022/03/30 00:06:50 pgoyette Exp $"); /* * I2C driver for the Sparkfun Serial motor controller. @@ -233,7 +233,7 @@ scmdi2c_activate(device_t self, enum dev } } -MODULE(MODULE_CLASS_DRIVER, scmdi2c, "i2cexec,scmd"); +MODULE(MODULE_CLASS_DRIVER, scmdi2c, "iic,scmd"); #ifdef _MODULE /* Like other drivers, we do this because the scmd common Index: src/sys/dev/i2c/sgp40.c diff -u src/sys/dev/i2c/sgp40.c:1.2 src/sys/dev/i2c/sgp40.c:1.3 --- src/sys/dev/i2c/sgp40.c:1.2 Wed Oct 20 17:52:44 2021 +++ src/sys/dev/i2c/sgp40.c Wed Mar 30 00:06:50 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: sgp40.c,v 1.2 2021/10/20 17:52:44 christos Exp $ */ +/* $NetBSD: sgp40.c,v 1.3 2022/03/30 00:06:50 pgoyette Exp $ */ /* * Copyright (c) 2021 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sgp40.c,v 1.2 2021/10/20 17:52:44 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sgp40.c,v 1.3 2022/03/30 00:06:50 pgoyette Exp $"); /* Driver for the Sensirion SGP40
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: pgoyette Date: Wed Mar 30 00:06:51 UTC 2022 Modified Files: src/sys/dev/i2c: am2315.c dbcool.c hytp14.c scmdi2c.c sgp40.c sht3x.c sht4x.c si70xx.c spdmem_i2c.c Log Message: These modules need to depend on iic, not just on i2cexec. (They will still recursively get i2cexec since the iic depends on it.) Partial fix for kern/56772 To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/am2315.c cvs rdiff -u -r1.63 -r1.64 src/sys/dev/i2c/dbcool.c cvs rdiff -u -r1.14 -r1.15 src/sys/dev/i2c/hytp14.c cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/scmdi2c.c cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/sgp40.c src/sys/dev/i2c/sht4x.c cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/sht3x.c cvs rdiff -u -r1.10 -r1.11 src/sys/dev/i2c/si70xx.c cvs rdiff -u -r1.25 -r1.26 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Jan 17 19:34:31 UTC 2022 Modified Files: src/sys/dev/i2c: i2c.c Log Message: Minimal hack to pass child devices a devhandle created from the OF or ACPI "cookie". Temporary measure until the i2c autoconfiguration overhaul is merged (which fixes this in a more generic way). To generate a diff of this commit: cvs rdiff -u -r1.80 -r1.81 src/sys/dev/i2c/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/i2c.c diff -u src/sys/dev/i2c/i2c.c:1.80 src/sys/dev/i2c/i2c.c:1.81 --- src/sys/dev/i2c/i2c.c:1.80 Sat Aug 7 16:19:11 2021 +++ src/sys/dev/i2c/i2c.c Mon Jan 17 19:34:31 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.80 2021/08/07 16:19:11 thorpej Exp $ */ +/* $NetBSD: i2c.c,v 1.81 2022/01/17 19:34:31 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -37,10 +37,23 @@ #ifdef _KERNEL_OPT #include "opt_i2c.h" -#endif + +#include "opt_fdt.h" +#ifdef FDT +#define I2C_USE_FDT +#endif /* FDT */ + +#if defined(__aarch64__) || defined(__amd64__) +#include "acpica.h" +#if NACPICA > 0 +#define I2C_USE_ACPI +#endif /* NACPICA > 0 */ +#endif /* __aarch64__ || __amd64__ */ + +#endif /* _KERNEL_OPT */ #include -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.80 2021/08/07 16:19:11 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.81 2022/01/17 19:34:31 thorpej Exp $"); #include #include @@ -57,6 +70,14 @@ __KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.80 #include #include +#ifdef I2C_USE_ACPI +#include +#endif /* I2C_USE_ACPI */ + +#ifdef I2C_USE_FDT +#include +#endif /* I2C_USE_FDT */ + #include #include "ioconf.h" @@ -444,6 +465,7 @@ iic_attach(device_t parent, device_t sel uint32_t cookietype; const char *name; struct i2c_attach_args ia; + devhandle_t devhandle; int loc[IICCF_NLOCS]; memset(loc, 0, sizeof loc); @@ -473,6 +495,19 @@ iic_attach(device_t parent, device_t sel ia.ia_cookietype = cookietype; ia.ia_prop = dev; + devhandle_invalidate(&devhandle); +#ifdef I2C_USE_FDT + if (cookietype == I2C_COOKIE_OF) { +devhandle = devhandle_from_of((int)cookie); + } +#endif /* I2C_USE_FDT */ +#ifdef I2C_USE_ACPI + if (cookietype == I2C_COOKIE_ACPI) { +devhandle = +devhandle_from_acpi((ACPI_HANDLE)cookie); + } +#endif /* I2C_USE_ACPI */ + buf = NULL; cdata = prop_dictionary_get(dev, "compatible"); if (cdata) @@ -493,7 +528,8 @@ iic_attach(device_t parent, device_t sel sc->sc_devices[addr] = config_found(self, &ia, iic_print_direct, - CFARGS(.locators = loc)); + CFARGS(.locators = loc, + .devhandle = devhandle)); } }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Jan 17 19:34:31 UTC 2022 Modified Files: src/sys/dev/i2c: i2c.c Log Message: Minimal hack to pass child devices a devhandle created from the OF or ACPI "cookie". Temporary measure until the i2c autoconfiguration overhaul is merged (which fixes this in a more generic way). To generate a diff of this commit: cvs rdiff -u -r1.80 -r1.81 src/sys/dev/i2c/i2c.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: skrll Date: Sat Jan 15 06:22:30 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: Trailing whitespace To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: skrll Date: Sat Jan 15 06:22:30 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: Trailing whitespace To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 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.26 src/sys/dev/i2c/ihidev.c:1.27 --- src/sys/dev/i2c/ihidev.c:1.26 Fri Jan 14 22:28:59 2022 +++ src/sys/dev/i2c/ihidev.c Sat Jan 15 06:22:30 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.26 2022/01/14 22:28:59 riastradh Exp $ */ +/* $NetBSD: ihidev.c,v 1.27 2022/01/15 06:22:30 skrll 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.26 2022/01/14 22:28:59 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.27 2022/01/15 06:22:30 skrll Exp $"); #include #include @@ -1025,7 +1025,7 @@ ihidev_acpi_get_info(struct ihidev_softc if (ACPI_FAILURE(status)) { aprint_error_dev(sc->sc_dev, "failed to get HidDescriptorAddress: %s\n", - AcpiFormatException(status)); + AcpiFormatException(status)); return false; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 22:28:59 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: ihidev(4): Prohibit closing an unopened ihidev. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 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.25 src/sys/dev/i2c/ihidev.c:1.26 --- src/sys/dev/i2c/ihidev.c:1.25 Fri Jan 14 22:28:50 2022 +++ src/sys/dev/i2c/ihidev.c Fri Jan 14 22:28:59 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.25 2022/01/14 22:28:50 riastradh Exp $ */ +/* $NetBSD: ihidev.c,v 1.26 2022/01/14 22:28:59 riastradh 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.25 2022/01/14 22:28:50 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.26 2022/01/14 22:28:59 riastradh Exp $"); #include #include @@ -919,10 +919,10 @@ ihidev_close(struct ihidev *scd) mutex_enter(&sc->sc_lock); - /* XXX make this an assertion */ - if (!(scd->sc_state & IHIDEV_OPEN)) - goto out; - + KASSERTMSG(scd->sc_state & IHIDEV_OPEN, + "%s: closing %s when not open", + device_xname(scd->sc_idev), + device_xname(sc->sc_dev)); scd->sc_state &= ~IHIDEV_OPEN; if (--sc->sc_refcnt)
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 22:28:59 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: ihidev(4): Prohibit closing an unopened ihidev. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 22:28:50 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: ihidev(4): Avoid reference count overflow. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 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.24 src/sys/dev/i2c/ihidev.c:1.25 --- src/sys/dev/i2c/ihidev.c:1.24 Fri Jan 14 22:28:23 2022 +++ src/sys/dev/i2c/ihidev.c Fri Jan 14 22:28:50 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.24 2022/01/14 22:28:23 riastradh Exp $ */ +/* $NetBSD: ihidev.c,v 1.25 2022/01/14 22:28:50 riastradh 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.24 2022/01/14 22:28:23 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.25 2022/01/14 22:28:50 riastradh Exp $"); #include #include @@ -889,7 +889,7 @@ ihidev_open(struct ihidev *scd) mutex_enter(&sc->sc_lock); - if (scd->sc_state & IHIDEV_OPEN) { + if (scd->sc_state & IHIDEV_OPEN || sc->sc_refcnt == INT_MAX) { error = EBUSY; goto out; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 22:28:50 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: ihidev(4): Avoid reference count overflow. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 22:28:42 UTC 2022 Modified Files: src/sys/dev/i2c: ims.c Log Message: ims(4): Sprinkle KERNEL_LOCKED_P assertions. Access to the softc and hidms state is currently kernel-locked. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/ims.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/ims.c diff -u src/sys/dev/i2c/ims.c:1.3 src/sys/dev/i2c/ims.c:1.4 --- src/sys/dev/i2c/ims.c:1.3 Tue Jul 9 12:56:30 2019 +++ src/sys/dev/i2c/ims.c Fri Jan 14 22:28:42 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: ims.c,v 1.3 2019/07/09 12:56:30 ryoon Exp $ */ +/* $NetBSD: ims.c,v 1.4 2022/01/14 22:28:42 riastradh Exp $ */ /* $OpenBSD ims.c,v 1.1 2016/01/12 01:11:15 jcs Exp $ */ /* @@ -20,7 +20,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ims.c,v 1.3 2019/07/09 12:56:30 ryoon Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ims.c,v 1.4 2022/01/14 22:28:42 riastradh Exp $"); #include #include @@ -158,11 +158,13 @@ ims_detach(device_t self, int flags) return rv; } -void +void ims_childdet(device_t self, device_t child) { struct ims_softc *sc = device_private(self); + KASSERT(KERNEL_LOCKED_P()); + KASSERT(sc->sc_ms.hidms_wsmousedev == child); sc->sc_ms.hidms_wsmousedev = NULL; } @@ -184,6 +186,8 @@ ims_enable(void *v) struct ims_softc *sc = v; int error; + KASSERT(KERNEL_LOCKED_P()); + if (sc->sc_enabled) return EBUSY; @@ -201,6 +205,8 @@ ims_disable(void *v) { struct ims_softc *sc = v; + KASSERT(KERNEL_LOCKED_P()); + #ifdef DIAGNOSTIC if (!sc->sc_enabled) { printf("ums_disable: not enabled\n");
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 22:28:42 UTC 2022 Modified Files: src/sys/dev/i2c: ims.c Log Message: ims(4): Sprinkle KERNEL_LOCKED_P assertions. Access to the softc and hidms state is currently kernel-locked. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/ims.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 22:28:23 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: ihidev(4): Take the lock for ihidev_open, ihidev_close. Need this to serialize access to sc_state, sc_refcnt. XXX Should harmonize this with uhidev(4) and tighten assertions. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 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.23 src/sys/dev/i2c/ihidev.c:1.24 --- src/sys/dev/i2c/ihidev.c:1.23 Fri Jan 14 22:26:45 2022 +++ src/sys/dev/i2c/ihidev.c Fri Jan 14 22:28:23 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.23 2022/01/14 22:26:45 riastradh Exp $ */ +/* $NetBSD: ihidev.c,v 1.24 2022/01/14 22:28:23 riastradh 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.23 2022/01/14 22:26:45 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.24 2022/01/14 22:28:23 riastradh Exp $"); #include #include @@ -882,22 +882,31 @@ int ihidev_open(struct ihidev *scd) { struct ihidev_softc *sc = scd->sc_parent; + int error; DPRINTF(("%s: %s: state=%d refcnt=%d\n", sc->sc_dev.dv_xname, __func__, scd->sc_state, sc->sc_refcnt)); - if (scd->sc_state & IHIDEV_OPEN) - return (EBUSY); + mutex_enter(&sc->sc_lock); + + if (scd->sc_state & IHIDEV_OPEN) { + error = EBUSY; + goto out; + } scd->sc_state |= IHIDEV_OPEN; - if (sc->sc_refcnt++ || sc->sc_isize == 0) - return (0); + if (sc->sc_refcnt++ || sc->sc_isize == 0) { + error = 0; + goto out; + } /* power on */ ihidev_reset(sc, false); + error = 0; - return (0); +out: mutex_exit(&sc->sc_lock); + return error; } void @@ -908,17 +917,22 @@ ihidev_close(struct ihidev *scd) DPRINTF(("%s: %s: state=%d refcnt=%d\n", sc->sc_dev.dv_xname, __func__, scd->sc_state, sc->sc_refcnt)); + mutex_enter(&sc->sc_lock); + + /* XXX make this an assertion */ if (!(scd->sc_state & IHIDEV_OPEN)) - return; + goto out; scd->sc_state &= ~IHIDEV_OPEN; if (--sc->sc_refcnt) - return; + goto out; if (ihidev_hid_command(sc, I2C_HID_CMD_SET_POWER, &I2C_HID_POWER_OFF, false)) aprint_error_dev(sc->sc_dev, "failed to power down\n"); + +out: mutex_exit(&sc->sc_lock); } void
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 22:28:23 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: ihidev(4): Take the lock for ihidev_open, ihidev_close. Need this to serialize access to sc_state, sc_refcnt. XXX Should harmonize this with uhidev(4) and tighten assertions. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 22:26:45 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: ihidev(4): Check kmem_alloc(..., KM_NOSLEEP) for failure. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 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.22 src/sys/dev/i2c/ihidev.c:1.23 --- src/sys/dev/i2c/ihidev.c:1.22 Fri Jan 14 22:26:35 2022 +++ src/sys/dev/i2c/ihidev.c Fri Jan 14 22:26:45 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.22 2022/01/14 22:26:35 riastradh Exp $ */ +/* $NetBSD: ihidev.c,v 1.23 2022/01/14 22:26:45 riastradh 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.22 2022/01/14 22:26:35 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.23 2022/01/14 22:26:45 riastradh Exp $"); #include #include @@ -416,6 +416,13 @@ ihidev_hid_command(struct ihidev_softc * */ report_len += report_id_len; tmprep = kmem_zalloc(report_len, KM_NOSLEEP); + if (tmprep == NULL) { + /* XXX pool or preallocate? */ + DPRINTF(("%s: out of memory\n", +device_xname(sc->sc_dev))); + res = ENOMEM; + break; + } /* type 3 id 8: 22 00 38 02 23 00 */ res = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, @@ -507,6 +514,10 @@ ihidev_hid_command(struct ihidev_softc * cmd[dataoff] = rreq->id; finalcmd = kmem_zalloc(cmdlen + rreq->len, KM_NOSLEEP); + if (finalcmd == NULL) { + res = ENOMEM; + break; + } memcpy(finalcmd, cmd, cmdlen); memcpy(finalcmd + cmdlen, rreq->data, rreq->len);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 22:26:45 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: ihidev(4): Check kmem_alloc(..., KM_NOSLEEP) for failure. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 22:26:35 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: ihidev(4): Allocate report buffer with KM_SLEEP. Limited to 64k and only happens on attach anyway. Let's not leave a rake to trip on here. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 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.21 src/sys/dev/i2c/ihidev.c:1.22 --- src/sys/dev/i2c/ihidev.c:1.21 Fri Jan 14 22:25:49 2022 +++ src/sys/dev/i2c/ihidev.c Fri Jan 14 22:26:35 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.21 2022/01/14 22:25:49 riastradh Exp $ */ +/* $NetBSD: ihidev.c,v 1.22 2022/01/14 22:26:35 riastradh 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.21 2022/01/14 22:25:49 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.22 2022/01/14 22:26:35 riastradh Exp $"); #include #include @@ -643,7 +643,7 @@ ihidev_hid_desc_parse(struct ihidev_soft } sc->sc_reportlen = le16toh(sc->hid_desc.wReportDescLength); - sc->sc_report = kmem_zalloc(sc->sc_reportlen, KM_NOSLEEP); + sc->sc_report = kmem_zalloc(sc->sc_reportlen, KM_SLEEP); if (ihidev_hid_command(sc, I2C_HID_REPORT_DESCR, 0, false)) { aprint_error_dev(sc->sc_dev, "failed fetching HID report\n");
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 22:26:35 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.c Log Message: ihidev(4): Allocate report buffer with KM_SLEEP. Limited to 64k and only happens on attach anyway. Let's not leave a rake to trip on here. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 22:25:49 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.c ihidev.h Log Message: ihidev(4): Fix locking and interrupt handler. - Can't run iic_exec in softint because it does cv_wait, at least on some i2c controllers -- defer to workqueue instead. - Fix violations of locking rules: . Do not take a lock at higher IPL than it is defined at! . Do not sleep under a lock! . Definitely do not sleep under a spin lock! In this case, sc_intr_lock was defined at IPL_VM but used at IPL_TTY, and i2c transactions -- possibly causing sleep for cv_wait -- were issued under it. But in this case, the interrupt handler needs only a single bit to mark whether the work is pending, so just use atomic_swap for that. - Use an adaptive lock (IPL_NONE) for i2c transactions. - Detach children, and do so before freeing anything. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/sys/dev/i2c/ihidev.c cvs rdiff -u -r1.5 -r1.6 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.20 src/sys/dev/i2c/ihidev.c:1.21 --- src/sys/dev/i2c/ihidev.c:1.20 Sat Aug 7 16:19:11 2021 +++ src/sys/dev/i2c/ihidev.c Fri Jan 14 22:25:49 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.20 2021/08/07 16:19:11 thorpej Exp $ */ +/* $NetBSD: ihidev.c,v 1.21 2022/01/14 22:25:49 riastradh Exp $ */ /* $OpenBSD ihidev.c,v 1.13 2017/04/08 02:57:23 deraadt Exp $ */ /*- @@ -54,13 +54,13 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.20 2021/08/07 16:19:11 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.21 2022/01/14 22:25:49 riastradh Exp $"); #include #include #include #include - +#include #include #include @@ -110,14 +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_intr_init(struct ihidev_softc *); +static void ihidev_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 void ihidev_work(struct work *, void *); static int ihidev_reset(struct ihidev_softc *, bool); static int ihidev_hid_desc_parse(struct ihidev_softc *); @@ -160,14 +160,14 @@ ihidev_attach(device_t parent, device_t sc->sc_dev = self; sc->sc_tag = ia->ia_tag; sc->sc_addr = ia->ia_addr; - mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_VM); + mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE); 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)) { + if (!ihidev_acpi_get_info(sc)) { return; } @@ -208,7 +208,7 @@ ihidev_attach(device_t parent, device_t repsz)); } sc->sc_ibuf = kmem_zalloc(sc->sc_isize, KM_SLEEP); - if (! ihiddev_intr_init(sc)) { + if (!ihidev_intr_init(sc)) { return; } @@ -245,7 +245,8 @@ ihidev_attach(device_t parent, device_t } /* power down until we're opened */ - if (ihidev_hid_command(sc, I2C_HID_CMD_SET_POWER, &I2C_HID_POWER_OFF, false)) { + if (ihidev_hid_command(sc, I2C_HID_CMD_SET_POWER, &I2C_HID_POWER_OFF, + false)) { aprint_error_dev(sc->sc_dev, "failed to power down\n"); return; } @@ -257,13 +258,19 @@ static int ihidev_detach(device_t self, int flags) { struct ihidev_softc *sc = device_private(self); + int error; + + error = config_detach_children(self, flags); + if (error) + return error; + + pmf_device_deregister(self); + ihidev_intr_fini(sc); + + if (ihidev_hid_command(sc, I2C_HID_CMD_SET_POWER, &I2C_HID_POWER_OFF, + true)) + aprint_error_dev(sc->sc_dev, "failed to power down\n"); - mutex_enter(&sc->sc_intr_lock); - ihiddev_intr_fini(sc); - if (ihidev_hid_command(sc, I2C_HID_CMD_SET_POWER, - &I2C_HID_POWER_OFF, true)) - aprint_error_dev(sc->sc_dev, "failed to power down\n"); - mutex_exit(&sc->sc_intr_lock); if (sc->sc_ibuf != NULL) { kmem_free(sc->sc_ibuf, sc->sc_isize); sc->sc_ibuf = NULL; @@ -272,8 +279,9 @@ ihidev_detach(device_t self, int flags) if (sc->sc_report != NULL) kmem_free(sc->sc_report, sc->sc_reportlen); - pmf_device_deregister(self); - return (0); + mutex_destroy(&sc->sc_lock); + + return 0; } static bool @@ -281,14 +289,14 @@ ihidev_suspend(device_t self, const pmf_ { struct ihidev_softc *sc = device_private(self); - mutex_enter(&sc->sc_intr_lock); + mutex_enter(&sc->sc_lock); if (sc->sc_refcnt > 0) { printf("i
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 22:25:49 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.c ihidev.h Log Message: ihidev(4): Fix locking and interrupt handler. - Can't run iic_exec in softint because it does cv_wait, at least on some i2c controllers -- defer to workqueue instead. - Fix violations of locking rules: . Do not take a lock at higher IPL than it is defined at! . Do not sleep under a lock! . Definitely do not sleep under a spin lock! In this case, sc_intr_lock was defined at IPL_VM but used at IPL_TTY, and i2c transactions -- possibly causing sleep for cv_wait -- were issued under it. But in this case, the interrupt handler needs only a single bit to mark whether the work is pending, so just use atomic_swap for that. - Use an adaptive lock (IPL_NONE) for i2c transactions. - Detach children, and do so before freeing anything. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/sys/dev/i2c/ihidev.c cvs rdiff -u -r1.5 -r1.6 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 21:32:27 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.h Log Message: ihidev(4): Add missing includes and header guard. Mark the sections that are conventionally separate files for hardware interface (*reg.h) versus software state (*var.h). To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 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.h diff -u src/sys/dev/i2c/ihidev.h:1.4 src/sys/dev/i2c/ihidev.h:1.5 --- src/sys/dev/i2c/ihidev.h:1.4 Thu Jan 9 04:04:01 2020 +++ src/sys/dev/i2c/ihidev.h Fri Jan 14 21:32:27 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.h,v 1.4 2020/01/09 04:04:01 thorpej Exp $ */ +/* $NetBSD: ihidev.h,v 1.5 2022/01/14 21:32:27 riastradh Exp $ */ /* $OpenBSD ihidev.h,v 1.4 2016/01/31 18:24:35 jcs Exp $ */ /*- @@ -30,6 +30,11 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#ifndef _DEV_I2C_IHIDEV_H_ +#define _DEV_I2C_IHIDEV_H_ + +/* ihidevreg.h */ + /* * HID-over-i2c driver * @@ -48,6 +53,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include + /* from usbdi.h: Match codes. */ /* First five codes is for a whole device. */ #define IMATCH_VENDOR_PRODUCT_REV 14 @@ -93,6 +100,15 @@ struct i2c_hid_desc { uint32_t reserved; } __packed; +/* ihidevvar.h */ + +#include + +#include +#include + +#include + struct ihidev_softc { device_t sc_dev; i2c_tag_t sc_tag; @@ -160,3 +176,4 @@ int ihidev_set_report(device_t, int, int int ihidev_get_report(device_t, int, int, void *, int); int ihidev_report_type_conv(int); +#endif /* _DEV_I2C_IHIDEV_H_ */
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Fri Jan 14 21:32:27 UTC 2022 Modified Files: src/sys/dev/i2c: ihidev.h Log Message: ihidev(4): Add missing includes and header guard. Mark the sections that are conventionally separate files for hardware interface (*reg.h) versus software state (*var.h). To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Sun Dec 19 12:44:35 UTC 2021 Modified Files: src/sys/dev/i2c: tda19988.c Log Message: drm: Fix tda19988 drm build. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/tda19988.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/tda19988.c diff -u src/sys/dev/i2c/tda19988.c:1.7 src/sys/dev/i2c/tda19988.c:1.8 --- src/sys/dev/i2c/tda19988.c:1.7 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/tda19988.c Sun Dec 19 12:44:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tda19988.c,v 1.7 2021/01/27 02:29:48 thorpej Exp $ */ +/* $NetBSD: tda19988.c,v 1.8 2021/12/19 12:44:34 riastradh Exp $ */ /*- * Copyright (c) 2015 Oleksandr Tymoshenko @@ -27,10 +27,10 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tda19988.c,v 1.7 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tda19988.c,v 1.8 2021/12/19 12:44:34 riastradh Exp $"); /* -* NXP TDA19988 HDMI encoder +* NXP TDA19988 HDMI encoder */ #include #include @@ -49,10 +49,12 @@ __KERNEL_RCSID(0, "$NetBSD: tda19988.c,v #include #include -#include +#include #include #include +#include #include +#include enum { TDA19988_PORT_INPUT = 0 @@ -729,7 +731,6 @@ tda19988_connector_get_modes(struct drm_ struct tda19988_connector *tda_connector = to_tda_connector(connector); struct tda19988_softc * const sc = tda_connector->sc; struct edid *pedid = NULL; - int error; if (sc->sc_edid_valid) { pedid = (struct edid *)sc->sc_edid; @@ -741,37 +742,15 @@ tda19988_connector_get_modes(struct drm_ sc->sc_edid_valid = true; } - drm_mode_connector_update_edid_property(connector, pedid); + drm_connector_update_edid_property(connector, pedid); if (pedid == NULL) return 0; - error = drm_add_edid_modes(connector, pedid); - drm_edid_to_eld(connector, pedid); - - return error; -} - -static struct drm_encoder * -tda19988_connector_best_encoder(struct drm_connector *connector) -{ - int enc_id = connector->encoder_ids[0]; - struct drm_mode_object *obj; - struct drm_encoder *encoder = NULL; - - if (enc_id) { - obj = drm_mode_object_find(connector->dev, enc_id, - DRM_MODE_OBJECT_ENCODER); - if (obj == NULL) - return NULL; - encoder = obj_to_encoder(obj); - } - - return encoder; + return drm_add_edid_modes(connector, pedid); } static const struct drm_connector_helper_funcs tda19988_connector_helper_funcs = { .get_modes = tda19988_connector_get_modes, - .best_encoder = tda19988_connector_best_encoder, }; static int @@ -792,8 +771,8 @@ tda19988_bridge_attach(struct drm_bridge DRM_MODE_CONNECTOR_HDMIA); drm_connector_helper_add(connector, &tda19988_connector_helper_funcs); - error = drm_mode_connector_attach_encoder(connector, bridge->encoder); - if (error != 0) + error = drm_connector_attach_encoder(connector, bridge->encoder); + if (error) return error; return drm_connector_register(connector); @@ -827,7 +806,8 @@ tda19988_bridge_post_disable(struct drm_ static void tda19988_bridge_mode_set(struct drm_bridge *bridge, -struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode) +const struct drm_display_mode *mode, +const struct drm_display_mode *adjusted_mode) { struct tda19988_softc * const sc = bridge->driver_private; @@ -882,12 +862,10 @@ tda19988_ep_activate(device_t dev, struc sc->sc_bridge.driver_private = sc; sc->sc_bridge.funcs = &tda19988_bridge_funcs; sc->sc_bridge.encoder = encoder; - error = drm_bridge_attach(encoder->dev, &sc->sc_bridge); - if (error != 0) + error = drm_bridge_attach(encoder, &sc->sc_bridge, NULL); + if (error) return EIO; - encoder->bridge = &sc->sc_bridge; - return 0; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: riastradh Date: Sun Dec 19 12:44:35 UTC 2021 Modified Files: src/sys/dev/i2c: tda19988.c Log Message: drm: Fix tda19988 drm build. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/tda19988.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: msaitoh Date: Mon Dec 6 16:24:57 UTC 2021 Modified Files: src/sys/dev/i2c: spdmem_i2c.c Log Message: Check the return value correctly. Pointed out by pgoyette@. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 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.24 src/sys/dev/i2c/spdmem_i2c.c:1.25 --- src/sys/dev/i2c/spdmem_i2c.c:1.24 Mon Dec 6 04:25:36 2021 +++ src/sys/dev/i2c/spdmem_i2c.c Mon Dec 6 16:24:57 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: spdmem_i2c.c,v 1.24 2021/12/06 04:25:36 msaitoh Exp $ */ +/* $NetBSD: spdmem_i2c.c,v 1.25 2021/12/06 16:24:57 msaitoh Exp $ */ /* * Copyright (c) 2007 Nicolas Joly @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.24 2021/12/06 04:25:36 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.25 2021/12/06 16:24:57 msaitoh Exp $"); #include #include @@ -121,7 +121,7 @@ spdmem_reset_page(struct spdmem_i2c_soft goto error; reg = 2; - rv |= iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, ®, 1, + rv = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, ®, 1, &byte2, 1, 0); if (rv != 0) goto error;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: msaitoh Date: Mon Dec 6 16:24:57 UTC 2021 Modified Files: src/sys/dev/i2c: spdmem_i2c.c Log Message: Check the return value correctly. Pointed out by pgoyette@. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: msaitoh Date: Mon Dec 6 04:25:36 UTC 2021 Modified Files: src/sys/dev/i2c: spdmem_i2c.c Log Message: Carefully access to the I2C bus in the match function. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 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.23 src/sys/dev/i2c/spdmem_i2c.c:1.24 --- src/sys/dev/i2c/spdmem_i2c.c:1.23 Tue Nov 30 05:02:29 2021 +++ src/sys/dev/i2c/spdmem_i2c.c Mon Dec 6 04:25:36 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: spdmem_i2c.c,v 1.23 2021/11/30 05:02:29 msaitoh Exp $ */ +/* $NetBSD: spdmem_i2c.c,v 1.24 2021/12/06 04:25:36 msaitoh Exp $ */ /* * Copyright (c) 2007 Nicolas Joly @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.23 2021/11/30 05:02:29 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.24 2021/12/06 04:25:36 msaitoh Exp $"); #include #include @@ -117,6 +117,9 @@ spdmem_reset_page(struct spdmem_i2c_soft */ rv = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, ®, 1, &byte0, 1, 0); + if (rv != 0) + goto error; + reg = 2; rv |= iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, ®, 1, &byte2, 1, 0);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: msaitoh Date: Mon Dec 6 04:25:36 UTC 2021 Modified Files: src/sys/dev/i2c: spdmem_i2c.c Log Message: Carefully access to the I2C bus in the match function. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: msaitoh Date: Wed Dec 1 21:33:19 UTC 2021 Modified Files: src/sys/dev/i2c: sdtemp.c Log Message: Use aprint_debug instead of aprint_error for expected failure. To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.41 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.40 src/sys/dev/i2c/sdtemp.c:1.41 --- src/sys/dev/i2c/sdtemp.c:1.40 Sun Jun 13 09:47:36 2021 +++ src/sys/dev/i2c/sdtemp.c Wed Dec 1 21:33:19 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: sdtemp.c,v 1.40 2021/06/13 09:47:36 mlelstv Exp $*/ +/* $NetBSD: sdtemp.c,v 1.41 2021/12/01 21:33:19 msaitoh Exp $*/ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.40 2021/06/13 09:47:36 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.41 2021/12/01 21:33:19 msaitoh Exp $"); #include #include @@ -692,8 +692,8 @@ sdtemp_config_mcp(struct sdtemp_softc *s if (rv == 0) sc->sc_resolution = SDTEMP_CAP_RESOLUTION_MAX; else - aprint_error("%s: error %d writing resolution register\n", - device_xname(sc->sc_dev), rv); + aprint_debug_dev(sc->sc_dev, + "error %d writing resolution register\n", rv); } static void @@ -712,8 +712,8 @@ sdtemp_config_idt(struct sdtemp_softc *s if (rv == 0) sc->sc_resolution = SDTEMP_CAP_RESOLUTION_MAX; else - aprint_error("%s: error %d writing resolution register\n", - device_xname(sc->sc_dev), rv); + aprint_debug_dev(sc->sc_dev, + "error %d writing resolution register\n", rv); } MODULE(MODULE_CLASS_DRIVER, sdtemp, "i2cexec,sysmon_envsys");
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: msaitoh Date: Wed Dec 1 21:33:19 UTC 2021 Modified Files: src/sys/dev/i2c: sdtemp.c Log Message: Use aprint_debug instead of aprint_error for expected failure. To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.41 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: msaitoh Date: Tue Nov 30 05:02:29 UTC 2021 Modified Files: src/sys/dev/i2c: spdmem_i2c.c Log Message: Access byte2... To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 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.22 src/sys/dev/i2c/spdmem_i2c.c:1.23 --- src/sys/dev/i2c/spdmem_i2c.c:1.22 Sun Jun 13 09:48:04 2021 +++ src/sys/dev/i2c/spdmem_i2c.c Tue Nov 30 05:02:29 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: spdmem_i2c.c,v 1.22 2021/06/13 09:48:04 mlelstv Exp $ */ +/* $NetBSD: spdmem_i2c.c,v 1.23 2021/11/30 05:02:29 msaitoh Exp $ */ /* * Copyright (c) 2007 Nicolas Joly @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.22 2021/06/13 09:48:04 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.23 2021/11/30 05:02:29 msaitoh Exp $"); #include #include @@ -117,6 +117,7 @@ spdmem_reset_page(struct spdmem_i2c_soft */ rv = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, ®, 1, &byte0, 1, 0); + reg = 2; rv |= iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, ®, 1, &byte2, 1, 0); if (rv != 0)
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: msaitoh Date: Tue Nov 30 05:02:29 UTC 2021 Modified Files: src/sys/dev/i2c: spdmem_i2c.c Log Message: Access byte2... To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: brad Date: Sun Nov 14 18:36:13 UTC 2021 Modified Files: src/sys/dev/i2c: sht3x.c Log Message: Fix some regressions that were introduced. One must make sure that you release the i2c bus if you acquire. One must not try to release the i2c bus if you failed to acquire it. One can't leave too early from the single-shot refresh without checking the status register as there may have been a reset and releasing the i2c bus. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/sht3x.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/sht3x.c diff -u src/sys/dev/i2c/sht3x.c:1.3 src/sys/dev/i2c/sht3x.c:1.4 --- src/sys/dev/i2c/sht3x.c:1.3 Sat Nov 13 13:36:42 2021 +++ src/sys/dev/i2c/sht3x.c Sun Nov 14 18:36:13 2021 @@ -1,4 +1,5 @@ -/* $NetBSD: sht3x.c,v 1.3 2021/11/13 13:36:42 christos Exp $ */ + +/* $NetBSD: sht3x.c,v 1.4 2021/11/14 18:36:13 brad Exp $ */ /* * Copyright (c) 2021 Brad Spencer @@ -17,7 +18,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sht3x.c,v 1.3 2021/11/13 13:36:42 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sht3x.c,v 1.4 2021/11/14 18:36:13 brad Exp $"); /* Driver for the Sensirion SHT30/SHT31/SHT35 @@ -487,7 +488,7 @@ sht3x_init_periodic_measurement(void *au if (error) { DPRINTF(sc, 2, ("%s: Could not acquire iic bus for initing: " " %d\n", device_xname(sc->sc_dev), error)); - goto out; + goto outm; } error = sht3x_take_break(sc, true); @@ -510,6 +511,7 @@ sht3x_init_periodic_measurement(void *au out: iic_release_bus(sc->sc_tag, 0); +outm: mutex_exit(&sc->sc_mutex); return error; } @@ -605,7 +607,9 @@ err: "%x%x - %x -- %d\n", device_xname(sc->sc_dev), rawbuf[0], rawbuf[1], rawbuf[2], rawbuf[3], rawbuf[4], rawbuf[5], error)); iic_release_bus(sc->sc_tag, 0); - memcpy(sc->sc_pbuffer, "dedbef", sizeof(sc->sc_pbuffer)); + if (error != 0) { + memcpy(sc->sc_pbuffer, "dedbef", sizeof(sc->sc_pbuffer)); + } mutex_exit(&sc->sc_mutex); } @@ -1427,14 +1431,11 @@ sht3x_refresh_oneshot(struct sysmon_envs measurement_command_ss = sht3x_compute_measure_command_ss( sc->sc_repeatability); - DPRINTF(sc, 2, ("%s: Measurement command: %04x\n", - device_xname(sc->sc_dev), measurement_command_ss)); error = sht3x_cmdr(sc, measurement_command_ss, rawdata, sizeof(rawdata)); + DPRINTF(sc, 2, ("%s: Status for single-shot measurement cmd %04x " + "Error %d\n", device_xname(sc->sc_dev), measurement_command_ss, error)); if (error == 0) { - DPRINTF(sc, 2, ("%s: Failed to get new status in refresh for " - "single-shot %d\n", device_xname(sc->sc_dev), error)); - if ((error = sht3x_parse_data(sc, edata, rawdata)) == 0) - return 0; + error = sht3x_parse_data(sc, edata, rawdata); } uint16_t sbuf; @@ -1455,7 +1456,8 @@ sht3x_refresh_oneshot(struct sysmon_envs } iic_release_bus(sc->sc_tag, 0); - return 0; + + return error; } static void @@ -1875,7 +1877,7 @@ sht3x_set_limits(struct sysmon_envsys *s rawlimitslow = (rawlimitslow & 0x1FF) | limitlow; DPRINTF(sc, 2, ("%s: RH new raw limits high/low " "%04x %04x from %x %x\n", - device_xname(sc->sc_dev), rawlimitshigh, rawlimitslow, + device_xname(sc->sc_dev), rawlimitshigh, rawlimitslow, limithigh, limitlow)); sht3x_set_alert_limits(sc, rawlimitshigh, rawlimitslow, true); break; @@ -2036,6 +2038,10 @@ sht3x_detach(device_t self, int flags) mutex_exit(&sc->sc_read_mutex); DPRINTF(sc, 2, ("%s: Will wait for anything to exit\n", device_xname(sc->sc_dev))); + /* In the worst case this will time out after 5 seconds. + * It really should not take that long for the drain / whatever + * to happen + */ cv_timedwait_sig(&sc->sc_cond_dying, &sc->sc_dying_mutex, mstohz(5000)); mutex_exit(&sc->sc_dying_mutex);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: brad Date: Sun Nov 14 18:36:13 UTC 2021 Modified Files: src/sys/dev/i2c: sht3x.c Log Message: Fix some regressions that were introduced. One must make sure that you release the i2c bus if you acquire. One must not try to release the i2c bus if you failed to acquire it. One can't leave too early from the single-shot refresh without checking the status register as there may have been a reset and releasing the i2c bus. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/sht3x.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: christos Date: Sat Nov 13 13:36:43 UTC 2021 Modified Files: src/sys/dev/i2c: sht3x.c Log Message: Brad wants the __did_not_work code back :-) To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/sht3x.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: christos Date: Sat Nov 13 13:36:43 UTC 2021 Modified Files: src/sys/dev/i2c: sht3x.c Log Message: Brad wants the __did_not_work code back :-) To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/sht3x.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/sht3x.c diff -u src/sys/dev/i2c/sht3x.c:1.2 src/sys/dev/i2c/sht3x.c:1.3 --- src/sys/dev/i2c/sht3x.c:1.2 Fri Nov 12 17:16:27 2021 +++ src/sys/dev/i2c/sht3x.c Sat Nov 13 08:36:42 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: sht3x.c,v 1.2 2021/11/12 22:16:27 christos Exp $ */ +/* $NetBSD: sht3x.c,v 1.3 2021/11/13 13:36:42 christos Exp $ */ /* * Copyright (c) 2021 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sht3x.c,v 1.2 2021/11/12 22:16:27 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sht3x.c,v 1.3 2021/11/13 13:36:42 christos Exp $"); /* Driver for the Sensirion SHT30/SHT31/SHT35 @@ -41,7 +41,6 @@ __KERNEL_RCSID(0, "$NetBSD: sht3x.c,v 1. #include #include - static int sht3x_take_break(void *, bool); static int sht3x_get_status_register(void *, uint16_t *, bool); static int sht3x_clear_status_register(void *, bool); @@ -52,6 +51,18 @@ static int sht3x_match(device_t, cfdata static void sht3x_attach(device_t, device_t, void *); static int sht3x_detach(device_t, int); static void sht3x_refresh(struct sysmon_envsys *, envsys_data_t *); +#ifdef __did_not_work +/* + * The chip that I had would not allow the limits to actually be set + * for reasons which are not obvious. The chip took the command just + * fine, but a read back of the limit registers showed that no change + * was made, so disable limits for now. + */ +static void sht3x_get_limits(struct sysmon_envsys *, envsys_data_t *, +sysmon_envsys_lim_t *, uint32_t *); +static void sht3x_set_limits(struct sysmon_envsys *, envsys_data_t *, +sysmon_envsys_lim_t *, uint32_t *); +#endif static int sht3x_verify_sysctl(SYSCTLFN_ARGS); static int sht3x_verify_sysctl_heateron(SYSCTLFN_ARGS); static int sht3x_verify_sysctl_modes(SYSCTLFN_ARGS); @@ -1166,6 +1177,9 @@ sht3x_attach(device_t parent, device_t s sc->sc_sensors[i].units = sht3x_sensors[i].type; sc->sc_sensors[i].state = ENVSYS_SINVALID; +#ifdef __did_not_work + sc->sc_sensors[i].flags |= ENVSYS_FMONLIMITS; +#endif DPRINTF(sc, 2, ("%s: registering sensor %d (%s)\n", __func__, i, sc->sc_sensors[i].desc)); @@ -1182,6 +1196,10 @@ sht3x_attach(device_t parent, device_t s sc->sc_sme->sme_name = device_xname(sc->sc_dev); sc->sc_sme->sme_cookie = sc; sc->sc_sme->sme_refresh = sht3x_refresh; +#ifdef __did_not_work + sc->sc_sme->sme_get_limits = sht3x_get_limits; + sc->sc_sme->sme_set_limits = sht3x_set_limits; +#endif DPRINTF(sc, 2, ("sht3x_attach: registering with envsys\n")); @@ -1348,6 +1366,38 @@ sht3x_parse_data(struct sht3x_sc *sc, en return 0; } +#ifdef __did_not_work +/* + * These are the the same as above except solved for the raw tick rather than + * temperature or humidity. These are needed for setting the alert limits, but + * since that did not work, disable these too for now. + */ +static uint16_t +sht3x_compute_raw_from_temp(uint32_t temp) +{ + uint64_t i1; + uint32_t tempc; + + tempc = temp - 27215; + tempc = tempc / 100; + + i1 = (13107 * tempc) + 589815; + return (uint16_t)(i1 / 35); +} + +static uint16_t +sht3x_compute_raw_from_rh(uint32_t mrh) +{ + uint64_t i1; + uint32_t rh; + + rh = mrh / 100; + + i1 = 13107 * rh; + return (uint16_t)(i1 / 20); +} +#endif + static int sht3x_refresh_periodic(struct sysmon_envsys *sme, envsys_data_t *edata) { @@ -1426,6 +1476,419 @@ sht3x_refresh(struct sysmon_envsys *sme, mutex_exit(&sc->sc_mutex); } +#ifdef __did_not_work +static void +sht3x_get_limits(struct sysmon_envsys *sme, envsys_data_t *edata, +sysmon_envsys_lim_t *limits, uint32_t *props) +{ + struct sht3x_sc *sc = sme->sme_cookie; + uint16_t rawlimitshigh, rawlimitslow; + uint16_t templimithigh, rhlimithigh, + templimitlow, rhlimitlow; + uint8_t templimithighmsb, templimithighlsb, + templimitlowmsb, templimitlowlsb; + uint8_t rhlimithighmsb, rhlimithighlsb, + rhlimitlowmsb, rhlimitlowlsb; + int error; + uint8_t lbuf[3]; + uint8_t limitscrchigh, limitskcrchigh, + limitscrclow, limitskcrclow; + + *props = 0; + + mutex_enter(&sc->sc_mutex); + error = iic_acquire_bus(sc->sc_tag, 0); + if (error) { + DPRINTF(sc, 2, ("%s: Could not acquire i2c bus: %x\n", + device_xname(sc->sc_dev), error)); + mutex_exit(&sc->sc_mutex); + return; + } + + error = sht3x_cmdr(sc, SHT3X_READ_HIGH_ALERT_SET, lbuf, 3); + if (error) { + DPRINTF(sc, 2, ("%s: Could not get high alert: %x\n", + device_xname(sc->sc_dev), error)); + goto out; + } + + rawlimitshigh = (lbuf[0] << 8) | lbuf[1]; + limitskcrchigh = lbuf[2]; + limitscrchigh = sht3x_crc(&lbuf[0
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: christos Date: Fri Nov 12 22:16:28 UTC 2021 Modified Files: src/sys/dev/i2c: sht3x.c Log Message: simplify the code and remove unused (it is in CVS anyway). Try to merge duplicate code. Follow KNF. Brad, please test! To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/sht3x.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/sht3x.c diff -u src/sys/dev/i2c/sht3x.c:1.1 src/sys/dev/i2c/sht3x.c:1.2 --- src/sys/dev/i2c/sht3x.c:1.1 Sat Nov 6 09:34:40 2021 +++ src/sys/dev/i2c/sht3x.c Fri Nov 12 17:16:27 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: sht3x.c,v 1.1 2021/11/06 13:34:40 brad Exp $ */ +/* $NetBSD: sht3x.c,v 1.2 2021/11/12 22:16:27 christos Exp $ */ /* * Copyright (c) 2021 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sht3x.c,v 1.1 2021/11/06 13:34:40 brad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sht3x.c,v 1.2 2021/11/12 22:16:27 christos Exp $"); /* Driver for the Sensirion SHT30/SHT31/SHT35 @@ -52,17 +52,6 @@ static int sht3x_match(device_t, cfdata static void sht3x_attach(device_t, device_t, void *); static int sht3x_detach(device_t, int); static void sht3x_refresh(struct sysmon_envsys *, envsys_data_t *); -/* The chip that I had would not allow the limits to actually be set - * for reasons which are not obvious. The chip took the command just - * fine, but a read back of the limit registers showed that no change - * was made, so disable limits for now. - */ -#ifdef __did_not_work -static void sht3x_get_limits(struct sysmon_envsys *, envsys_data_t *, - sysmon_envsys_lim_t *, uint32_t *); -static void sht3x_set_limits(struct sysmon_envsys *, envsys_data_t *, - sysmon_envsys_lim_t *, uint32_t *); -#endif static int sht3x_verify_sysctl(SYSCTLFN_ARGS); static int sht3x_verify_sysctl_heateron(SYSCTLFN_ARGS); static int sht3x_verify_sysctl_modes(SYSCTLFN_ARGS); @@ -338,8 +327,8 @@ sht3x_take_break(void *aux, bool have_bu if (! have_bus) { error = iic_acquire_bus(sc->sc_tag, 0); if (error) { - DPRINTF(sc, 2, ("%s: Could not acquire iic bus for breaking %d\n", - device_xname(sc->sc_dev), error)); + DPRINTF(sc, 2, ("%s: Could not acquire iic bus for " + "breaking %d\n", device_xname(sc->sc_dev), error)); goto out; } } @@ -348,13 +337,13 @@ sht3x_take_break(void *aux, bool have_bu DPRINTF(sc, 2, ("%s: Error breaking: %d\n", device_xname(sc->sc_dev), error)); } - out: +out: if (! have_bus) { iic_release_bus(sc->sc_tag, 0); } sc->sc_isperiodic = false; - strlcpy(sc->sc_mode,"single-shot",SHT3X_MODE_NAME); + strlcpy(sc->sc_mode, "single-shot", SHT3X_MODE_NAME); return error; } @@ -362,56 +351,53 @@ sht3x_take_break(void *aux, bool have_bu static int sht3x_get_status_register(void *aux, uint16_t *reg, bool have_bus) { - struct sht3x_sc *sc; - sc = aux; + struct sht3x_sc *sc = aux; uint8_t buf[3]; - int error = 0; + int error; if (! have_bus) { error = iic_acquire_bus(sc->sc_tag, 0); if (error) { - DPRINTF(sc, 2, ("%s: Could not acquire iic bus for getting status %d\n", - device_xname(sc->sc_dev), error)); - goto out; + DPRINTF(sc, 2, ("%s: Could not acquire iic bus for " + "getting status %d\n", device_xname(sc->sc_dev), + error)); + return error; } } error = sht3x_cmdr(sc, SHT3X_GET_STATUS_REGISTER, buf, 3); if (error) { DPRINTF(sc, 2, ("%s: Error getting status: %d\n", device_xname(sc->sc_dev), error)); + goto out; } - out: + + uint8_t c = sht3x_crc(&buf[0], 2); + if (c == buf[2]) { + *reg = buf[0] << 8 | buf[1]; + } else { + error = EINVAL; + } +out: if (! have_bus) { iic_release_bus(sc->sc_tag, 0); } - if (!error) { - uint8_t c; - - c = sht3x_crc(&buf[0],2); - if (c == buf[2]) { - *reg = buf[0] << 8 | buf[1]; - } else { - error = EINVAL; - } - } - return error; } static int sht3x_clear_status_register(void *aux, bool have_bus) { - struct sht3x_sc *sc; - sc = aux; - int error = 0; + struct sht3x_sc *sc = aux; + int error; if (! have_bus) { error = iic_acquire_bus(sc->sc_tag, 0); if (error) { - DPRINTF(sc, 2, ("%s: Could not acquire iic bus for clearing status %d\n", - device_xname(sc->sc_dev), error)); - goto out; + DPRINTF(sc, 2, ("%s: Could not acquire iic bus for " + "clearing status %d\n", device_xname(sc->sc_dev), + error)); + return error; } } error = sht3x_cmdr(sc, SHT3X_CLEAR_STATUS_REGISTER, NULL, 0); @@ -419,7 +405,6 @@ sht3x_clear_status_register(void *aux, b DPRINTF(sc, 2, ("%s: Error clear status register: %d\n", device_xname(sc->sc_dev), error)); } - out: if (! have_bus) { iic_release_bus(sc->sc_tag, 0); } @@ -438,16 +423,18 @@ sht3x_thread(void *aux) while (!sc->sc_stopping && !sc->sc_dying) { if (sc->sc_initperiodic) { - error = sht3x_
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: christos Date: Fri Nov 12 22:16:28 UTC 2021 Modified Files: src/sys/dev/i2c: sht3x.c Log Message: simplify the code and remove unused (it is in CVS anyway). Try to merge duplicate code. Follow KNF. Brad, please test! To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/sht3x.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun Nov 7 17:14:38 UTC 2021 Modified Files: src/sys/dev/i2c: cwfg.c Log Message: cwfg: update for dts-5.15 binding changes To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/cwfg.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/cwfg.c diff -u src/sys/dev/i2c/cwfg.c:1.4 src/sys/dev/i2c/cwfg.c:1.5 --- src/sys/dev/i2c/cwfg.c:1.4 Wed Jan 27 02:29:48 2021 +++ src/sys/dev/i2c/cwfg.c Sun Nov 7 17:14:38 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cwfg.c,v 1.4 2021/01/27 02:29:48 thorpej Exp $ */ +/* $NetBSD: cwfg.c,v 1.5 2021/11/07 17:14:38 jmcneill Exp $ */ /*- * Copyright (c) 2020 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cwfg.c,v 1.4 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cwfg.c,v 1.5 2021/11/07 17:14:38 jmcneill Exp $"); #include #include @@ -102,7 +102,8 @@ struct cwfg_softc { #define CWFG_ALERT_LEVEL_DEFAULT 0 static const struct device_compatible_entry compat_data[] = { - { .compat = "cellwise,cw201x" }, + { .compat = "cellwise,cw2015" }, + { .compat = "cellwise,cw201x" }, /* DTCOMPAT */ DEVICE_COMPAT_EOL }; @@ -357,10 +358,16 @@ static int cwfg_parse_resources(struct cwfg_softc *sc) { const u_int *batinfo; + u_int val; int len = 0, n; batinfo = fdtbus_get_prop(sc->sc_phandle, - "cellwise,bat-config-info", &len); + "cellwise,battery-profile", &len); + if (batinfo == NULL) { + /* DTCOMPAT */ + batinfo = fdtbus_get_prop(sc->sc_phandle, + "cellwise,bat-config-info", &len); + } switch (len) { case BATINFO_SIZE: memcpy(sc->sc_batinfo, batinfo, BATINFO_SIZE); @@ -376,12 +383,25 @@ cwfg_parse_resources(struct cwfg_softc * } if (of_getprop_uint32(sc->sc_phandle, - "cellwise,monitor-interval", &sc->sc_monitor_interval) != 0) { + "cellwise,monitor-interval-ms", &val) == 0) { + sc->sc_monitor_interval = howmany(val, 1000); + } else if (of_getprop_uint32(sc->sc_phandle, + "cellwise,monitor-interval", &val) == 0) { + /* DTCOMPAT */ + sc->sc_monitor_interval = val; + } else { sc->sc_monitor_interval = CWFG_MONITOR_INTERVAL_DEFAULT; } - if (of_getprop_uint32(sc->sc_phandle, - "cellwise,design-capacity", &sc->sc_design_capacity) != 0) { + const int bphandle = fdtbus_get_phandle(sc->sc_phandle, "monitored-battery"); + if (bphandle != -1 && of_getprop_uint32(bphandle, + "charge-full-design-microamp-hours", &val) == 0) { + sc->sc_design_capacity = howmany(val, 1000); + } else if (of_getprop_uint32(sc->sc_phandle, + "cellwise,design-capacity", &val) == 0) { + /* DTCOMPAT */ + sc->sc_design_capacity = val; + } else { sc->sc_design_capacity = CWFG_DESIGN_CAPACITY_DEFAULT; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun Nov 7 17:14:38 UTC 2021 Modified Files: src/sys/dev/i2c: cwfg.c Log Message: cwfg: update for dts-5.15 binding changes To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/cwfg.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: brad Date: Fri Oct 29 23:23:33 UTC 2021 Modified Files: src/sys/dev/i2c: sht4x.c Log Message: Correct an off by one degree error in the temperature conversion. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/sht4x.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/sht4x.c diff -u src/sys/dev/i2c/sht4x.c:1.1 src/sys/dev/i2c/sht4x.c:1.2 --- src/sys/dev/i2c/sht4x.c:1.1 Sun Oct 3 17:27:02 2021 +++ src/sys/dev/i2c/sht4x.c Fri Oct 29 23:23:33 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: sht4x.c,v 1.1 2021/10/03 17:27:02 brad Exp $ */ +/* $NetBSD: sht4x.c,v 1.2 2021/10/29 23:23:33 brad Exp $ */ /* * Copyright (c) 2021 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sht4x.c,v 1.1 2021/10/03 17:27:02 brad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sht4x.c,v 1.2 2021/10/29 23:23:33 brad Exp $"); /* Driver for the Sensirion SHT40/SHT41/SHT45 @@ -723,7 +723,7 @@ sht4x_refresh(struct sysmon_envsys * sme It follows then: - T in Kelvin = (229.15 + 175 * rawvalue / 65535) + T in Kelvin = (228.15 + 175 * rawvalue / 65535) given the relationship between Celsius and Kelvin. @@ -771,7 +771,7 @@ sht4x_refresh(struct sysmon_envsys * sme switch (edata->sensor) { case SHT4X_TEMP_SENSOR: svalptr = &rawdata[0]; - v1 = 22915; /* this is scaled up already from 229.15 */ + v1 = 22815; /* this is scaled up already from 228.15 */ v2 = 175; mul1 = 100; mul2 = 1;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: brad Date: Fri Oct 29 23:23:33 UTC 2021 Modified Files: src/sys/dev/i2c: sht4x.c Log Message: Correct an off by one degree error in the temperature conversion. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/sht4x.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: christos Date: Wed Oct 20 17:52:44 UTC 2021 Modified Files: src/sys/dev/i2c: sgp40.c Log Message: - fix clang compilation: add "%s" to format string - comma is followed by space - KNF multi-line comments - fold long lines - early returns, fixes a missed iic_release_bus() on error. - foo == false -> !foo To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/sgp40.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/sgp40.c diff -u src/sys/dev/i2c/sgp40.c:1.1 src/sys/dev/i2c/sgp40.c:1.2 --- src/sys/dev/i2c/sgp40.c:1.1 Thu Oct 14 09:54:46 2021 +++ src/sys/dev/i2c/sgp40.c Wed Oct 20 13:52:44 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: sgp40.c,v 1.1 2021/10/14 13:54:46 brad Exp $ */ +/* $NetBSD: sgp40.c,v 1.2 2021/10/20 17:52:44 christos Exp $ */ /* * Copyright (c) 2021 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sgp40.c,v 1.1 2021/10/14 13:54:46 brad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sgp40.c,v 1.2 2021/10/20 17:52:44 christos Exp $"); /* Driver for the Sensirion SGP40 MOx gas sensor for air quality @@ -42,7 +42,8 @@ __KERNEL_RCSID(0, "$NetBSD: sgp40.c,v 1. #include static uint8_t sgp40_crc(uint8_t *, size_t); -static int sgp40_cmdr(struct sgp40_sc *, uint16_t, uint8_t *, uint8_t, uint8_t *, size_t); +static int sgp40_cmdr(struct sgp40_sc *, uint16_t, uint8_t *, uint8_t, +uint8_t *, size_t); static int sgp40_poke(i2c_tag_t, i2c_addr_t, bool); static int sgp40_match(device_t, cfdata_t, void *); static void sgp40_attach(device_t, device_t, void *); @@ -110,9 +111,10 @@ sgp40_thread(void *aux) VocAlgorithm_init(&voc_algorithm_params); - while (sc->sc_stopping == false) { - rv = cv_timedwait(&sc->sc_condvar, &sc->sc_threadmutex, mstohz(1000)); - if (rv == EWOULDBLOCK && sc->sc_stopping == false) { + while (!sc->sc_stopping) { + rv = cv_timedwait(&sc->sc_condvar, &sc->sc_threadmutex, + mstohz(1000)); + if (rv == EWOULDBLOCK && !sc->sc_stopping) { sgp40_take_measurement(sc,&voc_algorithm_params); } } @@ -138,35 +140,37 @@ sgp40_stop_thread(void *aux) mutex_enter(&sc->sc_mutex); error = iic_acquire_bus(sc->sc_tag, 0); if (error) { - DPRINTF(sc, 2, ("%s: Could not acquire iic bus for heater off in stop thread: %d\n", + DPRINTF(sc, 2, ("%s: Could not acquire iic bus for heater off " + "in stop thread: %d\n", device_xname(sc->sc_dev), error)); + goto out; + } + error = sgp40_cmdr(sc, SGP40_HEATER_OFF, NULL, 0, NULL, 0); + if (error) { + DPRINTF(sc, 2, ("%s: Error turning heater off: %d\n", device_xname(sc->sc_dev), error)); - } else { - error = sgp40_cmdr(sc, SGP40_HEATER_OFF,NULL,0,NULL,0); - if (error) { - DPRINTF(sc, 2, ("%s: Error turning heater off: %d\n", - device_xname(sc->sc_dev), error)); - } - iic_release_bus(sc->sc_tag, 0); } +out: + iic_release_bus(sc->sc_tag, 0); mutex_exit(&sc->sc_mutex); } static int sgp40_compute_temp_comp(int unconverted) { - /* The published algorithm for this conversion is: - (temp_in_celcius + 45) * 65535 / 175 - - However, this did not exactly yield the results that - the example in the data sheet, so something a little - different was done. - - (temp_in_celcius + 45) * 65536 / 175 - - This was also scaled up by 10^2 and then scaled back to - preserve some percision. 37449 is simply (65536 * 100) / 175 - and rounded. - */ + /* + * The published algorithm for this conversion is: + * (temp_in_celcius + 45) * 65535 / 175 + * + * However, this did not exactly yield the results that + * the example in the data sheet, so something a little + * different was done. + * + * (temp_in_celcius + 45) * 65536 / 175 + * + * This was also scaled up by 10^2 and then scaled back to + * preserve some percision. 37449 is simply (65536 * 100) / 175 + * and rounded. + */ return (((unconverted + 45) * 100) * 37449) / 1; } @@ -176,19 +180,20 @@ sgp40_compute_rh_comp(int unconverted) { int q; - /* The published algorithm for this conversion is: - %rh * 65535 / 100 - - However, this did not exactly yield the results that - the example in the data sheet, so something a little - different was done. - - %rh * 65536 / 100 - - This was also scaled up by 10^2 and then scaled back to - preserve some percision. The value is also latched to 65535 - as an upper limit. - */ + /* + * The published algorithm for this conversion is: + * %rh * 65535 / 100 + * + * However, this did not exactly yield the results that + * the example in the data sheet, so something a little + * different was done. + * + * %rh * 65536 / 100 + * + * This was also scaled up by 10^2 and then scaled back to + * preserve some percision. The value is also latched to 65535 + * as an upper limit. + */ q = ((unconverted * 100) * 65536) / 1; if
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: christos Date: Wed Oct 20 17:52:44 UTC 2021 Modified Files: src/sys/dev/i2c: sgp40.c Log Message: - fix clang compilation: add "%s" to format string - comma is followed by space - KNF multi-line comments - fold long lines - early returns, fixes a missed iic_release_bus() on error. - foo == false -> !foo To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/sgp40.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: christos Date: Mon Oct 18 14:14:07 UTC 2021 Modified Files: src/sys/dev/i2c: sensirion_voc_algorithm.c Log Message: Fix llvm build: error: equality comparison with extraneous parentheses [-Werror,-Wparentheses-equality] To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/sensirion_voc_algorithm.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/sensirion_voc_algorithm.c diff -u src/sys/dev/i2c/sensirion_voc_algorithm.c:1.1 src/sys/dev/i2c/sensirion_voc_algorithm.c:1.2 --- src/sys/dev/i2c/sensirion_voc_algorithm.c:1.1 Thu Oct 14 09:54:46 2021 +++ src/sys/dev/i2c/sensirion_voc_algorithm.c Mon Oct 18 10:14:07 2021 @@ -1,5 +1,4 @@ -/* - * $NetBSD: sensirion_voc_algorithm.c,v 1.1 2021/10/14 13:54:46 brad Exp $ +/* $NetBSD: sensirion_voc_algorithm.c,v 1.2 2021/10/18 14:14:07 christos Exp $ */ /* @@ -599,7 +598,7 @@ static void VocAlgorithm__mean_variance_ fix16_t c; fix16_t additional_scaling; -if ((params->m_Mean_Variance_Estimator___Initialized == false)) { +if (!params->m_Mean_Variance_Estimator___Initialized) { params->m_Mean_Variance_Estimator___Initialized = true; params->m_Mean_Variance_Estimator___Sraw_Offset = sraw; params->m_Mean_Variance_Estimator___Mean = F16(0.); @@ -776,7 +775,7 @@ VocAlgorithm__adaptive_lowpass__process( fix16_t tau_a; fix16_t a3; -if ((params->m_Adaptive_Lowpass___Initialized == false)) { +if (!params->m_Adaptive_Lowpass___Initialized) { params->m_Adaptive_Lowpass___X1 = sample; params->m_Adaptive_Lowpass___X2 = sample; params->m_Adaptive_Lowpass___X3 = sample;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: christos Date: Mon Oct 18 14:14:07 UTC 2021 Modified Files: src/sys/dev/i2c: sensirion_voc_algorithm.c Log Message: Fix llvm build: error: equality comparison with extraneous parentheses [-Werror,-Wparentheses-equality] To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/sensirion_voc_algorithm.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/sys/dev/i2c
Hi Michael, Perhaps your commit missed some changes? The code no longer compiles. Cheers, + Kimmo /p/netbsd/cvs/src/sys/dev/i2c/dbcool.c: In function 'dbcool_attach': /p/netbsd/cvs/src/sys/dev/i2c/dbcool.c:778:4: error: 'struct dbcool_softc' has no member named 'sc_prop' sc->sc_prop = args->ia_prop; ^~ /p/netbsd/cvs/src/sys/dev/i2c/dbcool.c: In function 'dbcool_attach_sensor': /p/netbsd/cvs/src/sys/dev/i2c/dbcool.c:1698:43: error: 'struct dbcool_softc' has no member named 'sc_prop' if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, name, &desc)) { On Sun, Jul 12, 2020 at 06:42:33AM +, Michael Lorenz wrote: > 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. >
Re: CVS commit: src/sys/dev/i2c
Hi, "Jason R Thorpe" writes: > Module Name: src > Committed By: thorpej > Date: Sun Dec 22 16:44:35 UTC 2019 > > Modified Files: > src/sys/dev/i2c: ihidev.c ihidev.h > > Log Message: > The hid-over-i2c spec specifies that compliant devices use level-sensitive > interrupts. However, it's not safe to do i2c bus access in hard interrupt > context, and we must read the event data off the device in order to clear > the interrupt condition. > > Address this by using acpi_intr_mask() to mask off the interrupt source > while a softint is pending to service the events, re-enabling it once > servicing is completed. > > While here, re-factor the interrupt setup / tear-down code a bit to > eventually once day simplify supporting the FDT bindings for hid-over-i2c. This change freezes an amd64 kernel boot on my laptop. And I cannot enter into DDB with ALt+Ctrl+ESC. My laptop is HP Spectre x360 and it has twi ims(4) touch/pen screen. With "userconf disable ihidev", the kernel boots fine as of 2019-12-24T08:00 (UTC). Could you take a look at my problem? > To generate a diff of this commit: > cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/ihidev.c > cvs rdiff -u -r1.1 -r1.2 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.9 src/sys/dev/i2c/ihidev.c:1.10 > --- src/sys/dev/i2c/ihidev.c:1.9 Tue Oct 1 18:00:08 2019 > +++ src/sys/dev/i2c/ihidev.c Sun Dec 22 16:44:35 2019 > @@ -1,4 +1,4 @@ > -/* $NetBSD: ihidev.c,v 1.9 2019/10/01 18:00:08 chs Exp $ */ > +/* $NetBSD: ihidev.c,v 1.10 2019/12/22 16:44:35 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.9 2019/10/01 18:00:08 chs Exp $"); > +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.10 2019/12/22 16:44:35 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->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, > &I2C_HID_POWER_OFF, true)) > aprint_error_dev(sc->sc_dev, "failed to power down\n"); > @@ -649,31 +640,110 @@ 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", &res, > + &acpi_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(&res, 0); > + if (irq == NULL) { > + aprint_error_dev(sc->sc_dev, "no IRQ resource\n"); > + acpi_resource_cleanup(&res); > + ret
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: hkenken Date: Fri Nov 29 12:42:54 UTC 2019 Modified Files: src/sys/dev/i2c: motoi2c.c Log Message: Add wait for stop condition. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/motoi2c.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: hkenken Date: Fri Nov 29 12:42:54 UTC 2019 Modified Files: src/sys/dev/i2c: motoi2c.c Log Message: Add wait for stop condition. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/motoi2c.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/motoi2c.c diff -u src/sys/dev/i2c/motoi2c.c:1.5 src/sys/dev/i2c/motoi2c.c:1.6 --- src/sys/dev/i2c/motoi2c.c:1.5 Mon Aug 5 12:21:00 2019 +++ src/sys/dev/i2c/motoi2c.c Fri Nov 29 12:42:53 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: motoi2c.c,v 1.5 2019/08/05 12:21:00 hkenken Exp $ */ +/* $NetBSD: motoi2c.c,v 1.6 2019/11/29 12:42:53 hkenken Exp $ */ /*- * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: motoi2c.c,v 1.5 2019/08/05 12:21:00 hkenken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: motoi2c.c,v 1.6 2019/11/29 12:42:53 hkenken Exp $"); #if defined(__arm__) || defined(__aarch64__) #include "opt_fdt.h" @@ -163,6 +163,24 @@ motoi2c_release_bus(void *v, int flags) mutex_exit(&sc->sc_buslock); } +static int +motoi2c_stop_wait(struct motoi2c_softc *sc) +{ + u_int timo; + int error = 0; + + timo = 1000; + while ((I2C_READ(I2CSR) & SR_MBB) != 0 && --timo) + DELAY(1); + + if (timo == 0) { + DPRINTF(("%s: timeout (sr=%#x)\n", __func__, I2C_READ(I2CSR))); + error = ETIMEDOUT; + } + + return error; +} + /* busy waiting for byte data transfer completion */ static int motoi2c_busy_wait(struct motoi2c_softc *sc, uint8_t cr) @@ -224,15 +242,9 @@ motoi2c_exec(void *v, i2c_op_t op, i2c_a if ((cr & CR_MSTA) == 0 && (sr & SR_MBB) != 0) { /* wait for bus becoming available */ - u_int timo = 100; - do { - DELAY(10); - } while (--timo > 0 && ((sr = I2C_READ(I2CSR)) & SR_MBB) != 0); - - if (timo == 0) { - DPRINTF(("%s: bus is busy (%#x)\n", __func__, sr)); + error = motoi2c_stop_wait(sc); + if (error) return ETIMEDOUT; - } } /* reset interrupt and arbitration-lost flags (all others are RO) */ @@ -240,12 +252,10 @@ motoi2c_exec(void *v, i2c_op_t op, i2c_a sr = I2C_READ(I2CSR); /* - * Generate start (or restart) condition + * Generate start condition */ - /* CR_RTSA is write-only and transitory */ - uint8_t rsta = (cr & CR_MSTA ? CR_RSTA : 0); cr = CR_MEN | CR_MTX | CR_MSTA; - I2C_WRITE(I2CCR, cr | rsta); + I2C_WRITE(I2CCR, cr); DPRINTF(("%s: started: sr=%#x cr=%#x/%#x\n", __func__, I2C_READ(I2CSR), cr, I2C_READ(I2CCR))); @@ -339,14 +349,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 = CR_MEN | CR_TXAK; I2C_WRITE(I2CCR, cr); } *dataptr++ = I2C_READ(I2CDR); } if (datalen == 0) { if (I2C_OP_STOP_P(op)) { -cr = CR_MEN; +cr = CR_MEN | CR_TXAK; I2C_WRITE(I2CCR, cr); } (void)I2C_READ(I2CDR); /* dummy read */ @@ -378,6 +388,7 @@ motoi2c_exec(void *v, i2c_op_t op, i2c_a if (error || (cr & CR_TXAK) || ((cr & CR_MSTA) && I2C_OP_STOP_P(op))) { cr = CR_MEN; I2C_WRITE(I2CCR, cr); + motoi2c_stop_wait(sc); DPRINTF(("%s: stopping: cr=%#x/%#x\n", __func__, cr, I2C_READ(I2CCR))); }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: hkenken Date: Fri Nov 29 04:59:15 UTC 2019 Modified Files: src/sys/dev/i2c: at24cxx.c Log Message: Support more than 128Kbit model. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: hkenken Date: Fri Nov 29 04:59:15 UTC 2019 Modified Files: src/sys/dev/i2c: at24cxx.c Log Message: Support more than 128Kbit model. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 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.32 src/sys/dev/i2c/at24cxx.c:1.33 --- src/sys/dev/i2c/at24cxx.c:1.32 Sun Oct 27 19:10:38 2019 +++ src/sys/dev/i2c/at24cxx.c Fri Nov 29 04:59:15 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: at24cxx.c,v 1.32 2019/10/27 19:10:38 jmcneill Exp $ */ +/* $NetBSD: at24cxx.c,v 1.33 2019/11/29 04:59:15 hkenken Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.32 2019/10/27 19:10:38 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.33 2019/11/29 04:59:15 hkenken Exp $"); #include #include @@ -67,7 +67,7 @@ __KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v #define AT24CXX_ADDR 0x50 #define AT24CXX_WRITE_CYCLE_MS 10 -#define AT24CXX_ADDR_HI(a) (((a) >> 8) & 0x1f) +#define AT24CXX_ADDR_HI(a) (((a) >> 8) & 0xff) #define AT24CXX_ADDR_LO(a) ((a) & 0xff) #include "seeprom.h"
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mrg Date: Tue Nov 12 07:40:04 UTC 2019 Modified Files: src/sys/dev/i2c: fan53555.c Log Message: match DIE_ID of 9 (SILERGY_DIE_ID_SYR83X), seen on some rockpro64s. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/fan53555.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mrg Date: Tue Nov 12 07:40:04 UTC 2019 Modified Files: src/sys/dev/i2c: fan53555.c Log Message: match DIE_ID of 9 (SILERGY_DIE_ID_SYR83X), seen on some rockpro64s. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/fan53555.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/fan53555.c diff -u src/sys/dev/i2c/fan53555.c:1.3 src/sys/dev/i2c/fan53555.c:1.4 --- src/sys/dev/i2c/fan53555.c:1.3 Sat Jun 29 14:45:10 2019 +++ src/sys/dev/i2c/fan53555.c Tue Nov 12 07:40:04 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: fan53555.c,v 1.3 2019/06/29 14:45:10 jmcneill Exp $ */ +/* $NetBSD: fan53555.c,v 1.4 2019/11/12 07:40:04 mrg Exp $ */ /*- * Copyright (c) 2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: fan53555.c,v 1.3 2019/06/29 14:45:10 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fan53555.c,v 1.4 2019/11/12 07:40:04 mrg Exp $"); #include #include @@ -54,6 +54,7 @@ __KERNEL_RCSID(0, "$NetBSD: fan53555.c,v #define ID1_VENDOR __BITS(7,5) #define ID1_DIE_ID __BITS(3,0) #define SILERGY_DIE_ID_SYR82X 8 +#define SILERGY_DIE_ID_SYR83X 9 #define ID2_REG 0x04 #define ID2_DIE_REV __BITS(3,0) #define MONITOR_REG 0x05 @@ -231,6 +232,11 @@ fan53555_init(struct fan53555_softc *sc, sc->sc_base = 712500; sc->sc_step = 12500; break; + case SILERGY_DIE_ID_SYR83X: + aprint_normal(": Silergy SYR83X\n"); + sc->sc_base = 712500; + sc->sc_step = 12500; + break; default: aprint_error(": Unsupported Silergy chip (0x%x)\n", die_id); return ENXIO;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: tnn Date: Tue Nov 5 19:59:35 UTC 2019 Modified Files: src/sys/dev/i2c: ssdfb_i2c.c Log Message: ssdfb: fix i2c transfer error with some controllers If the controller doesn't support the full 128 byte transfer size we need, then split the write across multiple transactions. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 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.
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: tnn Date: Tue Nov 5 19:59:35 UTC 2019 Modified Files: src/sys/dev/i2c: ssdfb_i2c.c Log Message: ssdfb: fix i2c transfer error with some controllers If the controller doesn't support the full 128 byte transfer size we need, then split the write across multiple transactions. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 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.4 src/sys/dev/i2c/ssdfb_i2c.c:1.5 --- src/sys/dev/i2c/ssdfb_i2c.c:1.4 Sat Nov 2 14:23:59 2019 +++ src/sys/dev/i2c/ssdfb_i2c.c Tue Nov 5 19:59:35 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: ssdfb_i2c.c,v 1.4 2019/11/02 14:23:59 tnn Exp $ */ +/* $NetBSD: ssdfb_i2c.c,v 1.5 2019/11/05 19:59:35 tnn Exp $ */ /* * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ssdfb_i2c.c,v 1.4 2019/11/02 14:23:59 tnn Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ssdfb_i2c.c,v 1.5 2019/11/05 19:59:35 tnn Exp $"); #include #include @@ -43,12 +43,16 @@ struct ssdfb_i2c_softc { struct ssdfb_softc sc; i2c_tag_t sc_i2c_tag; i2c_addr_t sc_i2c_addr; + size_t sc_transfer_size; }; static int ssdfb_i2c_match(device_t, cfdata_t, void *); static void ssdfb_i2c_attach(device_t, device_t, void *); static int ssdfb_i2c_detach(device_t, int); +static int ssdfb_i2c_probe_transfer_size(struct ssdfb_i2c_softc *, bool); +static int ssdfb_i2c_transfer(struct ssdfb_i2c_softc *, uint8_t, uint8_t *, +size_t, int); static int ssdfb_i2c_cmd(void *, uint8_t *, size_t, bool); static int ssdfb_i2c_transfer_rect(void *, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t *, size_t, bool); @@ -132,6 +136,61 @@ ssdfb_i2c_detach(device_t self, int flag } static int +ssdfb_i2c_probe_transfer_size(struct ssdfb_i2c_softc *sc, bool usepoll) +{ + int flags = usepoll ? I2C_F_POLL : 0; + uint8_t cb = SSDFB_I2C_CTRL_BYTE_DATA_MASK; + int error; + uint8_t buf[128]; + size_t len; + + error = iic_acquire_bus(sc->sc_i2c_tag, flags); + if (error) + return error; + len = sizeof(buf); + memset(buf, 0, len); + while (len > 0) { + error = iic_exec(sc->sc_i2c_tag, I2C_OP_WRITE_WITH_STOP, + sc->sc_i2c_addr, &cb, sizeof(cb), buf, len, flags); + if (!error) { + break; + } + len >>= 1; + } + if (!error && len < 2) { + error = E2BIG; + } else { + sc->sc_transfer_size = len; + } + (void) iic_release_bus(sc->sc_i2c_tag, flags); + + return error; +} + +static int +ssdfb_i2c_transfer(struct ssdfb_i2c_softc *sc, uint8_t cb, uint8_t *data, + size_t len, int flags) +{ + int error; + size_t xfer_size = sc->sc_transfer_size; + + while (len >= xfer_size) { + error = iic_exec(sc->sc_i2c_tag, I2C_OP_WRITE_WITH_STOP, + sc->sc_i2c_addr, &cb, sizeof(cb), data, xfer_size, flags); + if (error) + return error; + len -= xfer_size; + data += xfer_size; + } + if (len > 0) { + error = iic_exec(sc->sc_i2c_tag, I2C_OP_WRITE_WITH_STOP, + sc->sc_i2c_addr, &cb, sizeof(cb), data, len, flags); + } + + return error; +} + +static int ssdfb_i2c_cmd(void *cookie, uint8_t *cmd, size_t len, bool usepoll) { struct ssdfb_i2c_softc *sc = (struct ssdfb_i2c_softc *)cookie; @@ -154,9 +213,6 @@ ssdfb_i2c_transfer_rect(void *cookie, ui uint8_t frompage, uint8_t topage, uint8_t *p, size_t stride, bool usepoll) { struct ssdfb_i2c_softc *sc = (struct ssdfb_i2c_softc *)cookie; - int flags = usepoll ? I2C_F_POLL : 0; - uint8_t cb = SSDFB_I2C_CTRL_BYTE_DATA_MASK; - uint8_t data[] = {0, 0, 0}; uint8_t cmd[2]; int error; @@ -177,13 +233,12 @@ ssdfb_i2c_transfer_rect(void *cookie, ui } if (sc->sc.sc_transfer_rect != ssdfb_smbus_transfer_rect) { - error = iic_acquire_bus(sc->sc_i2c_tag, flags); + error = ssdfb_i2c_probe_transfer_size(sc, usepoll); if (error) return error; - error = iic_exec(sc->sc_i2c_tag, I2C_OP_WRITE_WITH_STOP, - sc->sc_i2c_addr, &cb, sizeof(cb), data, sizeof(data), flags); - (void) iic_release_bus(sc->sc_i2c_tag, flags); - if (error) { + aprint_verbose_dev(sc->sc.sc_dev, "%zd-byte transfers\n", + sc->sc_transfer_size); + if (sc->sc_transfer_size == 2) { sc->sc.sc_transfer_rect = ssdfb_smbus_transfer_rect; } } @@ -238,8 +293,7 @@ ssdfb_i2c_transfer_rect_ssd1306(void *co if (error) goto out; while (frompage <= topage) { - error = iic_exec(sc->sc_i2c_tag, I2C_OP_WRITE_WITH_STOP, - sc->sc_i2c_addr, &cb, sizeof(cb), p, len, flags); + error = ssdfb_i2c_transfer(sc, cb, p, len, flags); if (error) goto out; frompage++; @@ -278,8 +332,7 @@ ssdfb_i2c_transfer_rect_sh1106(void *coo sc->sc_i2c_addr, &cc, sizeof(cc), cmds, sizeof(cmds), flags); if (error) goto out; - error = iic_exec(sc->sc_i2c_tag, I2C_OP_WRITE_WITH_STOP, - sc->sc_i2c_addr, &cb, sizeof(cb), p, len, flags); + error = ssdfb_i2c_transfe
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Mon Nov 4 10:02:39 UTC 2019 Modified Files: src/sys/dev/i2c: tda19988.c Log Message: Speed up mode setting a bit and turn off the display while changing modes To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/tda19988.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/tda19988.c diff -u src/sys/dev/i2c/tda19988.c:1.2 src/sys/dev/i2c/tda19988.c:1.3 --- src/sys/dev/i2c/tda19988.c:1.2 Sun Nov 3 23:28:59 2019 +++ src/sys/dev/i2c/tda19988.c Mon Nov 4 10:02:39 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: tda19988.c,v 1.2 2019/11/03 23:28:59 jmcneill Exp $ */ +/* $NetBSD: tda19988.c,v 1.3 2019/11/04 10:02:39 jmcneill Exp $ */ /*- * Copyright (c) 2015 Oleksandr Tymoshenko @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tda19988.c,v 1.2 2019/11/03 23:28:59 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tda19988.c,v 1.3 2019/11/04 10:02:39 jmcneill Exp $"); /* * NXP TDA19988 HDMI encoder @@ -257,6 +257,7 @@ struct tda19988_connector { struct tda19988_softc { device_t sc_dev; + int sc_phandle; i2c_tag_t sc_i2c; i2c_addr_t sc_addr; uint32_t sc_cec_addr; @@ -264,12 +265,14 @@ struct tda19988_softc { int sc_current_page; uint8_t *sc_edid; uint32_t sc_edid_len; + bool sc_edid_valid; struct drm_bridge sc_bridge; struct tda19988_connector sc_connector; struct fdt_device_ports sc_ports; - struct drm_display_mode sc_curmode; + + enum drm_connector_status sc_last_status; }; #define to_tda_connector(x) container_of(x, struct tda19988_connector, base) @@ -280,7 +283,8 @@ tda19988_set_page(struct tda19988_softc uint8_t buf[2] = { TDA_CURPAGE_ADDR, page }; int result; - result = iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, buf, 2, NULL, 0, I2C_F_POLL); + result = iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, buf, 2, NULL, 0, + cold ? I2C_F_POLL : 0); if (result == 0) sc->sc_current_page = page; @@ -290,7 +294,8 @@ tda19988_set_page(struct tda19988_softc static int tda19988_cec_read(struct tda19988_softc *sc, uint8_t addr, uint8_t *data) { - return iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_cec_addr, &addr, 1, data, 1, I2C_F_POLL); + return iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_cec_addr, &addr, 1, data, 1, + cold ? I2C_F_POLL : 0); } static int @@ -298,7 +303,8 @@ tda19988_cec_write(struct tda19988_softc { uint8_t buf[2] = { addr, data }; - return iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_cec_addr, buf, 2, NULL, 0, I2C_F_POLL); + return iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_cec_addr, buf, 2, NULL, 0, + cold ? I2C_F_POLL : 0); } static int @@ -311,19 +317,8 @@ tda19988_block_read(struct tda19988_soft if (sc->sc_current_page != REGPAGE(addr)) tda19988_set_page(sc, REGPAGE(addr)); -#if notyet - return iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr, ®, 1, data, len, I2C_F_POLL); -#else - int error, i; - for (i = 0; i < len; i++) { - error = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr, ®, 1, &data[i], 1, I2C_F_POLL); - if (error != 0) - return error; - reg++; - } - - return 0; -#endif + return iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr, ®, 1, data, len, + cold ? I2C_F_POLL : 0); } static int @@ -336,7 +331,8 @@ tda19988_reg_read(struct tda19988_softc if (sc->sc_current_page != REGPAGE(addr)) tda19988_set_page(sc, REGPAGE(addr)); - return iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr, ®, 1, data, 1, I2C_F_POLL); + return iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr, ®, 1, data, 1, + cold ? I2C_F_POLL : 0); } static int @@ -347,7 +343,8 @@ tda19988_reg_write(struct tda19988_softc if (sc->sc_current_page != REGPAGE(addr)) tda19988_set_page(sc, REGPAGE(addr)); - return iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, buf, 2, NULL, 0, I2C_F_POLL); + return iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, buf, 2, NULL, 0, + cold ? I2C_F_POLL : 0); } static int @@ -362,7 +359,8 @@ tda19988_reg_write2(struct tda19988_soft if (sc->sc_current_page != REGPAGE(address)) tda19988_set_page(sc, REGPAGE(address)); - return iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr, buf, 3, NULL, 0, I2C_F_POLL); + return iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr, buf, 3, NULL, 0, + cold ? I2C_F_POLL : 0); } static void @@ -686,13 +684,6 @@ tda19988_start(struct tda19988_softc *sc tda19988_cec_write(sc, TDA_CEC_FRO_IM_CLK_CTRL, CEC_FRO_IM_CLK_CTRL_GHOST_DIS | CEC_FRO_IM_CLK_CTRL_IMCLK_SEL); -#if 0 - if (tda19988_read_edid(sc) < 0) { - device_printf(dev, "failed to read EDID\n"); - return; - } -#endif - /* Default values for RGB 4:4:4 mapping */ tda19988_reg_write(sc, TDA_VIP_CNTRL_0, 0x23); tda19988_reg_
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Mon Nov 4 10:02:39 UTC 2019 Modified Files: src/sys/dev/i2c: tda19988.c Log Message: Speed up mode setting a bit and turn off the display while changing modes To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/tda19988.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.