CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 16:31:10 UTC 2020 Modified Files: src/sys/dev/i2c: m41t00.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/sys/dev/i2c/m41t00.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/m41t00.c diff -u src/sys/dev/i2c/m41t00.c:1.21 src/sys/dev/i2c/m41t00.c:1.22 --- src/sys/dev/i2c/m41t00.c:1.21 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/m41t00.c Thu Jan 2 16:31:09 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: m41t00.c,v 1.21 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: m41t00.c,v 1.22 2020/01/02 16:31:09 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: m41t00.c,v 1.21 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: m41t00.c,v 1.22 2020/01/02 16:31:09 thorpej Exp $"); #include #include @@ -283,7 +283,7 @@ m41t00_clock_read(struct m41t00_softc *s u_int8_t bcd[M41T00_NBYTES], cmdbuf[1]; int i, n; - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + if (iic_acquire_bus(sc->sc_tag, 0)) { aprint_error_dev(sc->sc_dev, "m41t00_clock_read: failed to acquire I2C bus\n"); return 0; @@ -296,8 +296,8 @@ m41t00_clock_read(struct m41t00_softc *s if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, cmdbuf, 1, - [i], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + [i], 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "m41t00_clock_read: failed to read rtc " "at 0x%x\n", @@ -307,7 +307,7 @@ m41t00_clock_read(struct m41t00_softc *s } /* Done with I2C */ - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); /* * Convert the M41T00's register values into something useable @@ -348,7 +348,7 @@ m41t00_clock_write(struct m41t00_softc * bcd[M41T00_MONTH] = bintobcd(dt->dt_mon); bcd[M41T00_YEAR] = bintobcd(dt->dt_year % 100); - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + if (iic_acquire_bus(sc->sc_tag, 0)) { aprint_error_dev(sc->sc_dev, "m41t00_clock_write: failed to acquire I2C bus\n"); return 0; @@ -371,8 +371,8 @@ m41t00_clock_write(struct m41t00_softc * again: cmdbuf[0] = M41T00_SEC; if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_address, - cmdbuf, 1, [M41T00_SEC], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, [M41T00_SEC], 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "m41t00_clock_write: failed to write SECONDS\n"); return 0; @@ -380,8 +380,8 @@ m41t00_clock_write(struct m41t00_softc * cmdbuf[0] = M41T00_SEC; if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, - cmdbuf, 1, _seconds, 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, _seconds, 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "m41t00_clock_write: failed to read " "INITIAL SECONDS\n"); @@ -393,8 +393,8 @@ m41t00_clock_write(struct m41t00_softc * cmdbuf[0] = m41t00_rtc_offset[i]; if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_address, - cmdbuf, 1, [i], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, [i], 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "m41t00_clock_write: failed to write rtc " " at 0x%x\n", @@ -405,8 +405,8 @@ m41t00_clock_write(struct m41t00_softc * cmdbuf[0] = M41T00_SEC; if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, - cmdbuf, 1, _seconds, 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, _seconds, 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "m41t00_clock_write: failed to read " "FINAL SECONDS\n"); @@ -423,7 +423,7 @@ m41t00_clock_write(struct m41t00_softc * goto again; } - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); return 1; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 16:28:02 UTC 2020 Modified Files: src/sys/dev/i2c: m41st84.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/sys/dev/i2c/m41st84.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/m41st84.c diff -u src/sys/dev/i2c/m41st84.c:1.24 src/sys/dev/i2c/m41st84.c:1.25 --- src/sys/dev/i2c/m41st84.c:1.24 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/m41st84.c Thu Jan 2 16:28:02 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: m41st84.c,v 1.24 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: m41st84.c,v 1.25 2020/01/02 16:28:02 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: m41st84.c,v 1.24 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: m41st84.c,v 1.25 2020/01/02 16:28:02 thorpej Exp $"); #include "opt_strtc.h" @@ -294,7 +294,7 @@ strtc_clock_read(struct strtc_softc *sc, u_int8_t bcd[M41ST84_REG_DATE_BYTES], cmdbuf[2]; int i; - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + if (iic_acquire_bus(sc->sc_tag, 0)) { aprint_error_dev(sc->sc_dev, "strtc_clock_read: failed to acquire I2C bus\n"); return (0); @@ -307,8 +307,8 @@ strtc_clock_read(struct strtc_softc *sc, */ cmdbuf[0] = M41ST84_REG_AL_HOUR; if (iic_exec(sc->sc_tag, I2C_OP_READ, sc->sc_address, - cmdbuf, 1, [1], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, [1], 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "strtc_clock_read: failed to read HT\n"); return (0); @@ -316,8 +316,8 @@ strtc_clock_read(struct strtc_softc *sc, if (cmdbuf[1] & M41ST84_AL_HOUR_HT) { cmdbuf[1] &= ~M41ST84_AL_HOUR_HT; if (iic_exec(sc->sc_tag, I2C_OP_WRITE, sc->sc_address, - cmdbuf, 1, [1], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, [1], 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "strtc_clock_read: failed to reset HT\n"); return (0); @@ -330,8 +330,8 @@ strtc_clock_read(struct strtc_softc *sc, if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, cmdbuf, 1, - [i], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + [i], 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "strtc_clock_read: failed to read rtc " "at 0x%x\n", i); @@ -340,7 +340,7 @@ strtc_clock_read(struct strtc_softc *sc, } /* Done with I2C */ - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); /* * Convert the M41ST84's register values into something useable @@ -376,7 +376,7 @@ strtc_clock_write(struct strtc_softc *sc bcd[M41ST84_REG_MONTH] = bintobcd(dt->dt_mon); bcd[M41ST84_REG_YEAR] = bintobcd((dt->dt_year - POSIX_BASE_YEAR) % 100); - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + if (iic_acquire_bus(sc->sc_tag, 0)) { aprint_error_dev(sc->sc_dev, "strtc_clock_write: failed to acquire I2C bus\n"); return (0); @@ -387,8 +387,8 @@ strtc_clock_write(struct strtc_softc *sc cmdbuf[1] = M41ST84_SEC_ST; if (iic_exec(sc->sc_tag, I2C_OP_WRITE, sc->sc_address, - cmdbuf, 1, [1], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, [1], 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "strtc_clock_write: failed to Hold Clock\n"); return (0); @@ -401,8 +401,8 @@ strtc_clock_write(struct strtc_softc *sc */ cmdbuf[0] = M41ST84_REG_AL_HOUR; if (iic_exec(sc->sc_tag, I2C_OP_READ, sc->sc_address, - cmdbuf, 1, [1], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, [1], 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "strtc_clock_write: failed to read HT\n"); return (0); @@ -410,8 +410,8 @@ strtc_clock_write(struct strtc_softc *sc if (cmdbuf[1] & M41ST84_AL_HOUR_HT) { cmdbuf[1] &= ~M41ST84_AL_HOUR_HT; if (iic_exec(sc->sc_tag, I2C_OP_WRITE, sc->sc_address, - cmdbuf, 1, [1], 1, I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, [1], 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "strtc_clock_write: failed to reset HT\n"); return (0); @@ -426,9 +426,8 @@ strtc_clock_write(struct strtc_softc *sc cmdbuf[0] = i; if (iic_exec(sc->sc_tag, i ? I2C_OP_WRITE : I2C_OP_WRITE_WITH_STOP, - sc->sc_address, cmdbuf, 1, [i], 1, - I2C_F_POLL)) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + sc->sc_address, cmdbuf, 1, [i], 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "strtc_clock_write: failed to write rtc " " at 0x%x\n", i); @@ -437,7 +436,7
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 16:24:51 UTC 2020 Modified Files: src/sys/dev/i2c: ds1307.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 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.33 src/sys/dev/i2c/ds1307.c:1.34 --- src/sys/dev/i2c/ds1307.c:1.33 Sun Sep 29 05:35:29 2019 +++ src/sys/dev/i2c/ds1307.c Thu Jan 2 16:24:51 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: ds1307.c,v 1.33 2019/09/29 05:35:29 macallan Exp $ */ +/* $NetBSD: ds1307.c,v 1.34 2020/01/02 16:24:51 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.33 2019/09/29 05:35:29 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.34 2020/01/02 16:24:51 thorpej Exp $"); #include #include @@ -524,7 +524,7 @@ dsrtc_clock_read_ymdhms(struct dsrtc_sof KASSERT(DS_RTC_SIZE >= dm->dm_rtc_size); - if ((error = iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) != 0) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, "%s: failed to acquire I2C bus: %d\n", __func__, error); @@ -536,11 +536,11 @@ dsrtc_clock_read_ymdhms(struct dsrtc_sof cmdbuf[0] = dm->dm_rtc_start + i; error = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, - sc->sc_address, cmdbuf, 1, [i], 1, I2C_F_POLL); + sc->sc_address, cmdbuf, 1, [i], 1, 0); } /* Done with I2C */ - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); if (error != 0) { aprint_error_dev(sc->sc_dev, @@ -609,7 +609,7 @@ dsrtc_clock_write_ymdhms(struct dsrtc_so if (dt->dt_year - offset >= 100) bcd[DS_MONTH] |= DS_MONTH_CENTURY; - if ((error = iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) != 0) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, "%s: failed to acquire I2C bus: %d\n", __func__, error); @@ -620,8 +620,8 @@ dsrtc_clock_write_ymdhms(struct dsrtc_so cmdbuf[0] = dm->dm_ch_reg; if ((error = iic_exec(sc->sc_tag, I2C_OP_READ, sc->sc_address, - cmdbuf, 1, [1], 1, I2C_F_POLL)) != 0) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, [1], 1, 0)) != 0) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "%s: failed to read Hold Clock: %d\n", __func__, error); @@ -634,8 +634,8 @@ dsrtc_clock_write_ymdhms(struct dsrtc_so cmdbuf[1] |= dm->dm_ch_value; if ((error = iic_exec(sc->sc_tag, I2C_OP_WRITE, sc->sc_address, - cmdbuf, 1, [1], 1, I2C_F_POLL)) != 0) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, [1], 1, 0)) != 0) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "%s: failed to write Hold Clock: %d\n", __func__, error); @@ -658,8 +658,8 @@ dsrtc_clock_write_ymdhms(struct dsrtc_so bcd[i] |= dm->dm_ch_value; } if ((error = iic_exec(sc->sc_tag, op, sc->sc_address, - cmdbuf, 1, [i], 1, I2C_F_POLL)) != 0) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + cmdbuf, 1, [i], 1, 0)) != 0) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "%s: failed to write rtc at 0x%x: %d\n", __func__, i, error); @@ -679,9 +679,8 @@ dsrtc_clock_write_ymdhms(struct dsrtc_so cmdbuf[1] &= ~dm->dm_ch_value; if ((error = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, - sc->sc_address, cmdbuf, 1, [1], 1, - I2C_F_POLL)) != 0) { - iic_release_bus(sc->sc_tag, I2C_F_POLL); + sc->sc_address, cmdbuf, 1, [1], 1, 0)) != 0) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "%s: failed to Hold Clock: %d\n", __func__, error); @@ -689,7 +688,7 @@ dsrtc_clock_write_ymdhms(struct dsrtc_so } } - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); return 1; } @@ -740,7 +739,7 @@ dsrtc_clock_read_timeval(struct dsrtc_so uint8_t buf[4]; int error; - if ((error = iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) != 0) { + if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) { aprint_error_dev(sc->sc_dev, "%s: failed to acquire I2C bus: %d\n", __func__, error); @@ -750,10 +749,10 @@ dsrtc_clock_read_timeval(struct dsrtc_so /* read all registers: */ uint8_t reg = dm->dm_rtc_start; error = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, - , 1, buf, 4, I2C_F_POLL); + , 1, buf, 4, 0); /* Done with I2C */ - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); if (error != 0) { aprint_error_dev(sc->sc_dev, @@ -790,7 +789,7 @@ dsrtc_clock_write_timeval(struct dsrtc_s buf[4] = (t >> 24) & 0xff; buf[5] = 0; - if ((error = iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) != 0) { + if ((error =
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jan 2 16:18:37 UTC 2020 Modified Files: src/sys/dev/i2c: i2c_exec.c Log Message: Also force I2C_F_POLL if shutting_down. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/sys/dev/i2c/i2c_exec.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/i2c_exec.c diff -u src/sys/dev/i2c/i2c_exec.c:1.14 src/sys/dev/i2c/i2c_exec.c:1.15 --- src/sys/dev/i2c/i2c_exec.c:1.14 Mon Dec 23 14:26:19 2019 +++ src/sys/dev/i2c/i2c_exec.c Thu Jan 2 16:18:37 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c_exec.c,v 1.14 2019/12/23 14:26:19 thorpej Exp $ */ +/* $NetBSD: i2c_exec.c,v 1.15 2020/01/02 16:18:37 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: i2c_exec.c,v 1.14 2019/12/23 14:26:19 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c_exec.c,v 1.15 2020/01/02 16:18:37 thorpej Exp $"); #include #include @@ -59,7 +59,7 @@ static inline int iic_op_flags(int flags) { - return flags | (cold ? I2C_F_POLL : 0); + return flags | ((cold || shutting_down) ? I2C_F_POLL : 0); } /*
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Wed Jan 1 18:09:44 UTC 2020 Modified Files: src/sys/dev/i2c: anxedp.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/anxedp.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/anxedp.c diff -u src/sys/dev/i2c/anxedp.c:1.2 src/sys/dev/i2c/anxedp.c:1.3 --- src/sys/dev/i2c/anxedp.c:1.2 Sun Feb 3 13:56:38 2019 +++ src/sys/dev/i2c/anxedp.c Wed Jan 1 18:09:44 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: anxedp.c,v 1.2 2019/02/03 13:56:38 jmcneill Exp $ */ +/* $NetBSD: anxedp.c,v 1.3 2020/01/01 18:09:44 thorpej Exp $ */ /*- * Copyright (c) 2019 Jared D. McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: anxedp.c,v 1.2 2019/02/03 13:56:38 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: anxedp.c,v 1.3 2020/01/01 18:09:44 thorpej Exp $"); #include #include @@ -99,7 +99,7 @@ anxedp_read(struct anxedp_softc *sc, u_i { uint8_t val; - if (iic_smbus_read_byte(sc->sc_i2c, sc->sc_addr + off, reg, , I2C_F_POLL) != 0) + if (iic_smbus_read_byte(sc->sc_i2c, sc->sc_addr + off, reg, , 0) != 0) val = 0xff; return val; @@ -108,7 +108,7 @@ anxedp_read(struct anxedp_softc *sc, u_i static void anxedp_write(struct anxedp_softc *sc, u_int off, uint8_t reg, uint8_t val) { - (void)iic_smbus_write_byte(sc->sc_i2c, sc->sc_addr + off, reg, val, I2C_F_POLL); + (void)iic_smbus_write_byte(sc->sc_i2c, sc->sc_addr + off, reg, val, 0); } static int @@ -247,9 +247,9 @@ anxedp_connector_get_modes(struct drm_co struct edid *pedid = NULL; int error; - iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); + iic_acquire_bus(sc->sc_i2c, 0); error = anxedp_read_edid(sc, edid, sizeof(edid)); - iic_release_bus(sc->sc_i2c, I2C_F_POLL); + iic_release_bus(sc->sc_i2c, 0); if (error == 0) pedid = (struct edid *)edid;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Wed Jan 1 00:38:31 UTC 2020 Modified Files: src/sys/dev/i2c: rkpmic.c Log Message: Add clk provider To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/rkpmic.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/rkpmic.c diff -u src/sys/dev/i2c/rkpmic.c:1.5 src/sys/dev/i2c/rkpmic.c:1.6 --- src/sys/dev/i2c/rkpmic.c:1.5 Wed Sep 18 15:12:37 2019 +++ src/sys/dev/i2c/rkpmic.c Wed Jan 1 00:38:30 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: rkpmic.c,v 1.5 2019/09/18 15:12:37 tnn Exp $ */ +/* $NetBSD: rkpmic.c,v 1.6 2020/01/01 00:38:30 jmcneill Exp $ */ /*- * Copyright (c) 2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rkpmic.c,v 1.5 2019/09/18 15:12:37 tnn Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rkpmic.c,v 1.6 2020/01/01 00:38:30 jmcneill Exp $"); #include #include @@ -41,6 +41,8 @@ __KERNEL_RCSID(0, "$NetBSD: rkpmic.c,v 1 #include +#include + #include #define SECONDS_REG 0x00 @@ -67,6 +69,9 @@ __KERNEL_RCSID(0, "$NetBSD: rkpmic.c,v 1 #define CHIP_NAME_REG 0x17 #define CHIP_VER_REG 0x18 +#define CLK32OUT_REG 0x20 +#define CLK32OUT_CLKOUT2_EN __BIT(0) + struct rkpmic_ctrl { const char * name; uint8_t enable_reg; @@ -187,6 +192,12 @@ static const struct rkpmic_config rk808_ .nctrl = __arraycount(rk808_ctrls), }; +struct rkpmic_softc; + +struct rkpmic_clk { + struct clk base; +}; + struct rkpmic_softc { device_t sc_dev; i2c_tag_t sc_i2c; @@ -194,6 +205,8 @@ struct rkpmic_softc { int sc_phandle; struct todr_chip_handle sc_todr; struct rkpmic_config *sc_conf; + struct clk_domain sc_clkdom; + struct rkpmic_clk sc_clk[2]; }; struct rkreg_softc { @@ -316,6 +329,87 @@ rkpmic_todr_gettime(todr_chip_handle_t c return 0; } +static struct clk * +rkpmic_clk_decode(device_t dev, int cc_phandle, const void *data, size_t len) +{ + struct rkpmic_softc * const sc = device_private(dev); + + if (len != 4) + return NULL; + + const u_int id = be32dec(data); + if (id >= __arraycount(sc->sc_clk)) + return NULL; + + return >sc_clk[id].base; +} + +static const struct fdtbus_clock_controller_func rkpmic_clk_fdt_funcs = { + .decode = rkpmic_clk_decode +}; + +static struct clk * +rkpmic_clk_get(void *priv, const char *name) +{ + struct rkpmic_softc * const sc = priv; + u_int n; + + for (n = 0; n < __arraycount(sc->sc_clk); n++) { + if (strcmp(name, sc->sc_clk[n].base.name) == 0) + return >sc_clk[n].base; + } + + return NULL; +} + +static u_int +rkpmic_clk_get_rate(void *priv, struct clk *clk) +{ + return 32768; +} + +static int +rkpmic_clk_enable(void *priv, struct clk *clk) +{ + struct rkpmic_softc * const sc = priv; + uint8_t val; + + if (clk != >sc_clk[1].base) + return 0; + + I2C_LOCK(sc); + val = I2C_READ(sc, CLK32OUT_REG); + val |= CLK32OUT_CLKOUT2_EN; + I2C_WRITE(sc, CLK32OUT_REG, val); + I2C_UNLOCK(sc); + + return 0; +} + +static int +rkpmic_clk_disable(void *priv, struct clk *clk) +{ + struct rkpmic_softc * const sc = priv; + uint8_t val; + + if (clk != >sc_clk[1].base) + return EIO; + + I2C_LOCK(sc); + val = I2C_READ(sc, CLK32OUT_REG); + val &= ~CLK32OUT_CLKOUT2_EN; + I2C_WRITE(sc, CLK32OUT_REG, val); + I2C_UNLOCK(sc); + + return 0; +} + +static const struct clk_funcs rkpmic_clk_funcs = { + .get = rkpmic_clk_get, + .get_rate = rkpmic_clk_get_rate, + .enable = rkpmic_clk_enable, + .disable = rkpmic_clk_disable, +}; static int rkpmic_match(device_t parent, cfdata_t match, void *aux) @@ -367,6 +461,21 @@ rkpmic_attach(device_t parent, device_t fdtbus_todr_attach(self, sc->sc_phandle, >sc_todr); + sc->sc_clkdom.name = device_xname(self); + sc->sc_clkdom.funcs = _clk_funcs; + sc->sc_clkdom.priv = sc; + + sc->sc_clk[0].base.domain = >sc_clkdom; + sc->sc_clk[0].base.name = "xin32k"; + clk_attach(>sc_clk[0].base); + + sc->sc_clk[1].base.domain = >sc_clkdom; + sc->sc_clk[1].base.name = "clkout2"; + clk_attach(>sc_clk[1].base); + + fdtbus_register_clock_controller(self, sc->sc_phandle, + _clk_fdt_funcs); + regulators = of_find_firstchild_byname(sc->sc_phandle, "regulators"); if (regulators < 0) return;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Tue Dec 31 14:27:50 UTC 2019 Modified Files: src/sys/dev/i2c: nxt2k.c Log Message: Fix mis-placed parentheses. PR kern/54813. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/nxt2k.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/nxt2k.c diff -u src/sys/dev/i2c/nxt2k.c:1.6 src/sys/dev/i2c/nxt2k.c:1.7 --- src/sys/dev/i2c/nxt2k.c:1.6 Mon Dec 23 19:00:59 2019 +++ src/sys/dev/i2c/nxt2k.c Tue Dec 31 14:27:50 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: nxt2k.c,v 1.6 2019/12/23 19:00:59 thorpej Exp $ */ +/* $NetBSD: nxt2k.c,v 1.7 2019/12/31 14:27:50 thorpej Exp $ */ /* * Copyright (c) 2008, 2011 Jonathan A. Kollasch @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: nxt2k.c,v 1.6 2019/12/23 19:00:59 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nxt2k.c,v 1.7 2019/12/31 14:27:50 thorpej Exp $"); #include #include @@ -74,7 +74,7 @@ nxt2k_writedata(struct nxt2k *nxt, uint8 KASSERT((len + 1) <= 384); - if ((error = iic_acquire_bus(nxt->tag, 0) != 0)) + if ((error = iic_acquire_bus(nxt->tag, 0)) != 0) return error; buffer[0] = reg; @@ -93,7 +93,7 @@ nxt2k_readdata(struct nxt2k *nxt, uint8_ { int error; - if ((error = iic_acquire_bus(nxt->tag, 0) != 0)) + if ((error = iic_acquire_bus(nxt->tag, 0)) != 0) return error; error = iic_exec(nxt->tag, I2C_OP_READ_WITH_STOP, nxt->addr,
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Tue Dec 31 14:25:33 UTC 2019 Modified Files: src/sys/dev/i2c: cx24227.c Log Message: Fix mis-placed parentheses. PR kern/54812. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sys/dev/i2c/cx24227.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/cx24227.c diff -u src/sys/dev/i2c/cx24227.c:1.10 src/sys/dev/i2c/cx24227.c:1.11 --- src/sys/dev/i2c/cx24227.c:1.10 Mon Dec 23 18:09:05 2019 +++ src/sys/dev/i2c/cx24227.c Tue Dec 31 14:25:33 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cx24227.c,v 1.10 2019/12/23 18:09:05 thorpej Exp $ */ +/* $NetBSD: cx24227.c,v 1.11 2019/12/31 14:25:33 thorpej Exp $ */ /* * Copyright (c) 2008, 2011 Jonathan A. Kollasch @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cx24227.c,v 1.10 2019/12/23 18:09:05 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cx24227.c,v 1.11 2019/12/31 14:25:33 thorpej Exp $"); #include #include @@ -108,7 +108,7 @@ cx24227_writereg(struct cx24227 *sc, uin int error; uint8_t r[3]; - if ((error = iic_acquire_bus(sc->tag, 0) != 0)) + if ((error = iic_acquire_bus(sc->tag, 0)) != 0) return error; r[0] = reg; @@ -130,7 +130,7 @@ cx24227_readreg(struct cx24227 *sc, uint *data = 0x; - if ((error = iic_acquire_bus(sc->tag, 0) != 0)) + if ((error = iic_acquire_bus(sc->tag, 0)) != 0) return error; error = iic_exec(sc->tag, I2C_OP_READ_WITH_STOP, sc->addr,
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Wed Dec 25 14:08:47 UTC 2019 Modified Files: src/sys/dev/i2c: gttwsi_core.c gttwsivar.h Log Message: Remove assertions that no longer make sense now that the bus acquire / release logic is handled by the upper layer. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/gttwsi_core.c cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/gttwsivar.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/gttwsi_core.c diff -u src/sys/dev/i2c/gttwsi_core.c:1.9 src/sys/dev/i2c/gttwsi_core.c:1.10 --- src/sys/dev/i2c/gttwsi_core.c:1.9 Sun Dec 22 23:23:32 2019 +++ src/sys/dev/i2c/gttwsi_core.c Wed Dec 25 14:08:47 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: gttwsi_core.c,v 1.9 2019/12/22 23:23:32 thorpej Exp $ */ +/* $NetBSD: gttwsi_core.c,v 1.10 2019/12/25 14:08:47 thorpej Exp $ */ /* * Copyright (c) 2008 Eiji Kawauchi. * All rights reserved. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.9 2019/12/22 23:23:32 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.10 2019/12/25 14:08:47 thorpej Exp $"); #include "locators.h" #include @@ -205,8 +205,6 @@ gttwsi_send_start(void *v, int flags) struct gttwsi_softc *sc = v; int expect; - KASSERT(sc->sc_inuse); - if (sc->sc_started) expect = STAT_RSCT; else @@ -222,8 +220,6 @@ gttwsi_send_stop(void *v, int flags) int retry = TWSI_RETRY_COUNT; uint32_t control; - KASSERT(sc->sc_inuse); - sc->sc_started = false; /* Interrupt is not generated for STAT_NRS. */ @@ -249,8 +245,6 @@ gttwsi_initiate_xfer(void *v, i2c_addr_t uint32_t data, expect, alt; int error, read; - KASSERT(sc->sc_inuse); - error = gttwsi_send_start(v, flags); if (error) return error; @@ -303,8 +297,6 @@ gttwsi_read_byte(void *v, uint8_t *valp, struct gttwsi_softc *sc = v; int error; - KASSERT(sc->sc_inuse); - if (flags & I2C_F_LAST) error = gttwsi_wait(sc, 0, STAT_MRRD_ANT, 0, flags); else @@ -322,8 +314,6 @@ gttwsi_write_byte(void *v, uint8_t val, struct gttwsi_softc *sc = v; int error; - KASSERT(sc->sc_inuse); - gttwsi_write_4(sc, TWSI_DATA, val); error = gttwsi_wait(sc, 0, STAT_MTDB_AR, 0, flags); if (flags & I2C_F_STOP) @@ -338,8 +328,6 @@ gttwsi_wait(struct gttwsi_softc *sc, uin uint32_t status; int timo, error = 0; - KASSERT(sc->sc_inuse); - DELAY(5); if (!(flags & I2C_F_POLL)) control |= CONTROL_INTEN; Index: src/sys/dev/i2c/gttwsivar.h diff -u src/sys/dev/i2c/gttwsivar.h:1.4 src/sys/dev/i2c/gttwsivar.h:1.5 --- src/sys/dev/i2c/gttwsivar.h:1.4 Mon May 7 15:03:19 2018 +++ src/sys/dev/i2c/gttwsivar.h Wed Dec 25 14:08:47 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: gttwsivar.h,v 1.4 2018/05/07 15:03:19 jmcneill Exp $ */ +/* $NetBSD: gttwsivar.h,v 1.5 2019/12/25 14:08:47 thorpej Exp $ */ /* * Copyright (c) 2008 Eiji Kawauchi. * All rights reserved. @@ -86,7 +86,6 @@ struct gttwsi_softc { struct i2c_controller sc_i2c; kmutex_t sc_buslock; kmutex_t sc_mtx; - bool sc_inuse; kcondvar_t sc_cv; bool sc_iflg_rwc;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Wed Dec 25 01:19:56 UTC 2019 Modified Files: src/sys/dev/i2c: ihidev.c ihidev.h Log Message: Revert previous until issues can be sorted out. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sys/dev/i2c/ihidev.c cvs rdiff -u -r1.2 -r1.3 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.10 src/sys/dev/i2c/ihidev.c:1.11 --- src/sys/dev/i2c/ihidev.c:1.10 Sun Dec 22 16:44:35 2019 +++ src/sys/dev/i2c/ihidev.c Wed Dec 25 01:19:56 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.10 2019/12/22 16:44:35 thorpej Exp $ */ +/* $NetBSD: ihidev.c,v 1.11 2019/12/25 01:19:56 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.10 2019/12/22 16:44:35 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.11 2019/12/25 01:19:56 thorpej Exp $"); #include #include @@ -71,7 +71,6 @@ __KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1 # include "acpica.h" #endif #if NACPICA > 0 -#include #include #endif @@ -110,14 +109,10 @@ 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 *); @@ -205,9 +200,20 @@ ihidev_attach(device_t parent, device_t repsz)); } sc->sc_ibuf = kmem_zalloc(sc->sc_isize, KM_SLEEP); - if (! ihiddev_intr_init(sc)) { - return; +#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))); } +#endif iha.iaa = ia; iha.parent = sc; @@ -254,7 +260,10 @@ ihidev_detach(device_t self, int flags) struct ihidev_softc *sc = device_private(self); mutex_enter(>sc_intr_lock); - ihiddev_intr_fini(sc); +#if NACPICA > 0 + if (sc->sc_ih != NULL) + acpi_intr_disestablish(sc->sc_ih); +#endif if (ihidev_hid_command(sc, I2C_HID_CMD_SET_POWER, _HID_POWER_OFF, true)) aprint_error_dev(sc->sc_dev, "failed to power down\n"); @@ -640,110 +649,31 @@ ihidev_hid_desc_parse(struct ihidev_soft return (0); } -static bool -ihiddev_intr_init(struct ihidev_softc *sc) -{ -#if NACPICA > 0 - ACPI_HANDLE hdl = (void *)(uintptr_t)sc->sc_phandle; - struct acpi_resources res; - ACPI_STATUS rv; - char buf[100]; - - rv = acpi_resource_parse(sc->sc_dev, hdl, "_CRS", , - _resource_parse_ops_quiet); - if (ACPI_FAILURE(rv)) { - aprint_error_dev(sc->sc_dev, "can't parse '_CRS'\n"); - return false; - } - - const struct acpi_irq * const irq = acpi_res_irq(, 0); - if (irq == NULL) { - aprint_error_dev(sc->sc_dev, "no IRQ resource\n"); - acpi_resource_cleanup(); - return false; - } - - sc->sc_intr_type = - irq->ar_type == ACPI_EDGE_SENSITIVE ? IST_EDGE : IST_LEVEL; - - acpi_resource_cleanup(); - - sc->sc_ih = acpi_intr_establish(sc->sc_dev, sc->sc_phandle, IPL_TTY, - false, ihidev_intr, sc, device_xname(sc->sc_dev)); - if (sc->sc_ih == NULL) { - aprint_error_dev(sc->sc_dev, "can't establish interrupt\n"); - return false; - } - aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", - acpi_intr_string(sc->sc_ih, buf, sizeof(buf))); - - sc->sc_sih = softint_establish(SOFTINT_SERIAL, ihidev_softintr, sc); - if (sc->sc_sih == NULL) { - aprint_error_dev(sc->sc_dev, - "can't establish soft interrupt\n"); - return false; - } - - return true; -#else - aprint_error_dev(sc->sc_dev, "can't establish interrupt\n"); - return false; -#endif -} - -static void -ihiddev_intr_fini(struct ihidev_softc *sc) -{ -#if NACPICA > 0 - if (sc->sc_ih != NULL) { - acpi_intr_disestablish(sc->sc_ih); - } - if (sc->sc_sih != NULL) { - softint_disestablish(sc->sc_sih); - } -#endif -} - static int ihidev_intr(void *arg) { - struct ihidev_softc * const sc = arg; - - mutex_enter(>sc_intr_lock); - - /* - * Schedule our soft interrupt handler. If we're using a level- - * triggered interrupt, we have to mask it off while we wait - * for service. - */ - softint_schedule(sc->sc_sih); - if (sc->sc_intr_type == IST_LEVEL) { -#if NACPICA > 0 - acpi_intr_mask(sc->sc_ih);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 21:24:59 UTC 2019 Modified Files: src/sys/dev/i2c: tps65217pmic.c Log Message: - No need to use I2C_F_POLL here. - Refactor register read / write functions, splitting out i2c bus acquire / release everywhere. This fixes what was almost certainly a deadlock in the FDT regulator section of the code (acquire bus -> read register, which again acquires bus -> locking against myself). To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/sys/dev/i2c/tps65217pmic.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/tps65217pmic.c diff -u src/sys/dev/i2c/tps65217pmic.c:1.14 src/sys/dev/i2c/tps65217pmic.c:1.15 --- src/sys/dev/i2c/tps65217pmic.c:1.14 Sun Nov 3 22:55:34 2019 +++ src/sys/dev/i2c/tps65217pmic.c Mon Dec 23 21:24:59 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: tps65217pmic.c,v 1.14 2019/11/03 22:55:34 jmcneill Exp $ */ +/* $NetBSD: tps65217pmic.c,v 1.15 2019/12/23 21:24:59 thorpej Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #include "opt_fdt.h" #include -__KERNEL_RCSID(0, "$NetBSD: tps65217pmic.c,v 1.14 2019/11/03 22:55:34 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tps65217pmic.c,v 1.15 2019/12/23 21:24:59 thorpej Exp $"); #include #include @@ -146,12 +146,14 @@ struct tps_reg_param { bool is_xadj; /* voltage is adjusted externally */ uint16_t current_voltage; /* in mV */ - }; static int tps65217pmic_match(device_t, cfdata_t, void *); static void tps65217pmic_attach(device_t, device_t, void *); +static int tps65217pmic_i2c_lock(struct tps65217pmic_softc *); +static void tps65217pmic_i2c_unlock(struct tps65217pmic_softc *); + static uint8_t tps65217pmic_reg_read(struct tps65217pmic_softc *, uint8_t); static void tps65217pmic_reg_write(struct tps65217pmic_softc *, uint8_t, uint8_t); @@ -398,11 +400,19 @@ tps65217pmic_power_monitor_init(struct t intrmask = TPS65217PMIC_INT_USBM | TPS65217PMIC_INT_ACM | TPS65217PMIC_INT_PBM; + if (tps65217pmic_i2c_lock(sc) != 0) { + aprint_error_dev(sc->sc_dev, + "failed to initialize power monitor\n"); + return; + } + status = tps65217pmic_reg_read(sc, TPS65217PMIC_STATUS); ppath = tps65217pmic_reg_read(sc, TPS65217PMIC_PPATH); /* acknowledge and disregard whatever interrupt was generated earlier */ intr = tps65217pmic_reg_read(sc, TPS65217PMIC_INT); + tps65217pmic_i2c_unlock(sc); + sc->sc_usbstatus = status & TPS65217PMIC_STATUS_USBPWR; sc->sc_acstatus = status & TPS65217PMIC_STATUS_ACPWR; sc->sc_usbenabled = ppath & TPS65217PMIC_PPATH_USB_EN; @@ -430,7 +440,14 @@ tps65217pmic_power_monitor_task(void *au mutex_enter(>sc_lock); + if (tps65217pmic_i2c_lock(sc) != 0) { + device_printf(sc->sc_dev, + "WARNING: unable to perform power monitor task.\n"); + return; + } status = tps65217pmic_reg_read(sc, TPS65217PMIC_STATUS); + tps65217pmic_i2c_unlock(sc); + usbstatus = status & TPS65217PMIC_STATUS_USBPWR; acstatus = status & TPS65217PMIC_STATUS_ACPWR; @@ -510,11 +527,19 @@ tps65217pmic_wled_init(struct tps65217pm return; } + if (tps65217pmic_i2c_lock(sc) != 0) { + device_printf(sc->sc_dev, + "WARNING: unable to configure LED\n"); + return; + } + tps65217pmic_reg_write(sc, TPS65217PMIC_WLEDCTRL1, val); tps65217pmic_reg_write(sc, TPS65217PMIC_WLEDCTRL2, (brightness - 1) & TPS65217PMIC_WLEDCTRL2_DUTY); val |= TPS65217PMIC_WLEDCTRL1_ISINK_EN; tps65217pmic_reg_write(sc, TPS65217PMIC_WLEDCTRL1, val); + + tps65217pmic_i2c_unlock(sc); } static void @@ -523,10 +548,18 @@ tps65217pmic_reg_refresh(struct tps65217 int i; struct tps_reg_param *c_reg; + if (tps65217pmic_i2c_lock(sc) != 0) { + device_printf(sc->sc_dev, + "WARNING: unable to refresh regulators\n"); + return; + } + for (i = 0; i < NTPS_REG; i++) { c_reg = _regulators[i]; tps65217pmic_regulator_read_config(sc, c_reg); } + + tps65217pmic_i2c_unlock(sc); } /* Get version and revision of the chip. */ @@ -535,8 +568,16 @@ tps65217pmic_version(struct tps65217pmic { uint8_t chipid; + if (tps65217pmic_i2c_lock(sc) != 0) { + device_printf(sc->sc_dev, + "WARNING: unable to get chip ID\n"); + return; + } + chipid = tps65217pmic_reg_read(sc, TPS65217PMIC_CHIPID); + tps65217pmic_i2c_unlock(sc); + sc->sc_version = chipid & TPS65217PMIC_CHIPID_VER_MASK; sc->sc_revision = chipid & TPS65217PMIC_CHIPID_REV_MASK; } @@ -694,32 +735,45 @@ tps65217pmic_print_ppath(struct tps65217 aprint_normal("\n"); } +static int +tps65217pmic_i2c_lock(struct tps65217pmic_softc *sc) +{ + int error; + + error = iic_acquire_bus(sc->sc_tag, 0); + if (error) { + device_printf(sc->sc_dev, + "unable to acquire i2c bus, error %d\n", error); + } + return error; +} + +static void +tps65217pmic_i2c_unlock(struct tps65217pmic_softc *sc) +{ + iic_release_bus(sc->sc_tag,
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 20:49:09 UTC 2019 Modified Files: src/sys/dev/i2c: tea5767.c Log Message: No need to use I2C_F_POLL here. Also fix an uninitialized error variable in tea5767_read(). To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/tea5767.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/tea5767.c diff -u src/sys/dev/i2c/tea5767.c:1.1 src/sys/dev/i2c/tea5767.c:1.2 --- src/sys/dev/i2c/tea5767.c:1.1 Fri Jul 27 12:02:26 2018 +++ src/sys/dev/i2c/tea5767.c Mon Dec 23 20:49:09 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: tea5767.c,v 1.1 2018/07/27 12:02:26 rkujawa Exp $ */ +/* $NetBSD: tea5767.c,v 1.2 2019/12/23 20:49:09 thorpej Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. * All rights reserved. @@ -29,7 +29,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tea5767.c,v 1.1 2018/07/27 12:02:26 rkujawa Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tea5767.c,v 1.2 2019/12/23 20:49:09 thorpej Exp $"); #include #include @@ -151,22 +151,22 @@ tea5767_write(struct tea5767_softc *sc, { int exec_result; - if (iic_acquire_bus(sc->sc_i2c_tag, I2C_F_POLL)) { + if (iic_acquire_bus(sc->sc_i2c_tag, 0)) { device_printf(sc->sc_dev, "bus acquiration failed.\n"); return 1; } exec_result = iic_exec(sc->sc_i2c_tag, I2C_OP_WRITE_WITH_STOP, - sc->sc_addr, NULL, 0, reg, 5, I2C_F_POLL); + sc->sc_addr, NULL, 0, reg, 5, 0); if (exec_result) { - iic_release_bus(sc->sc_i2c_tag, I2C_F_POLL); + iic_release_bus(sc->sc_i2c_tag, 0); device_printf(sc->sc_dev, "write operation failed %d.\n", exec_result); return 1; } - iic_release_bus(sc->sc_i2c_tag, I2C_F_POLL); + iic_release_bus(sc->sc_i2c_tag, 0); return 0; } @@ -177,21 +177,21 @@ tea5767_read(struct tea5767_softc *sc, u { int exec_result; - if (iic_acquire_bus(sc->sc_i2c_tag, I2C_F_POLL)) { + if (iic_acquire_bus(sc->sc_i2c_tag, 0)) { device_printf(sc->sc_dev, "bus acquiration failed.\n"); return 1; } - iic_exec(sc->sc_i2c_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, - NULL, 0, reg, 5, I2C_F_POLL); + exec_result = iic_exec(sc->sc_i2c_tag, I2C_OP_READ_WITH_STOP, + sc->sc_addr, NULL, 0, reg, 5, 0); if (exec_result) { - iic_release_bus(sc->sc_i2c_tag, I2C_F_POLL); + iic_release_bus(sc->sc_i2c_tag, 0); device_printf(sc->sc_dev, "read operation failed.\n"); return 1; } - iic_release_bus(sc->sc_i2c_tag, I2C_F_POLL); + iic_release_bus(sc->sc_i2c_tag, 0); return 0; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 20:38:08 UTC 2019 Modified Files: src/sys/dev/i2c: tcakp.c Log Message: - Don't use I2C_F_POLL. - Don't access the i2c from hard interrupt context. Instead, schedule a soft interrupt to do the real work. (No need to mask the interrupt source, since this device has an edge-sensitive interrupt per the DT info; will need to be revisited if there's ever a flavor that uses a level-sensitive interrupt). - Split out the i2c bus acquire / release from the register read / write functions, allowing us to batch several i2c transactions under a single acquire / release cycle. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sys/dev/i2c/tcakp.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/tcakp.c diff -u src/sys/dev/i2c/tcakp.c:1.10 src/sys/dev/i2c/tcakp.c:1.11 --- src/sys/dev/i2c/tcakp.c:1.10 Wed Oct 17 16:56:40 2018 +++ src/sys/dev/i2c/tcakp.c Mon Dec 23 20:38:08 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: tcakp.c,v 1.10 2018/10/17 16:56:40 jmcneill Exp $ */ +/* $NetBSD: tcakp.c,v 1.11 2019/12/23 20:38:08 thorpej Exp $ */ /*- * Copyright (c) 2017 Jared McNeill @@ -29,7 +29,7 @@ #include "opt_fdt.h" #include -__KERNEL_RCSID(0, "$NetBSD: tcakp.c,v 1.10 2018/10/17 16:56:40 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tcakp.c,v 1.11 2019/12/23 20:38:08 thorpej Exp $"); #include #include @@ -99,6 +99,7 @@ struct tcakp_softc { uint16_t sc_keymap[128]; void *sc_ih; + void *sc_sih; int sc_enabled; device_t sc_wskbddev; @@ -107,6 +108,9 @@ struct tcakp_softc { static int tcakp_match(device_t, cfdata_t, void *); static void tcakp_attach(device_t, device_t, void *); +static int tcakp_i2c_lock(struct tcakp_softc *); +static void tcakp_i2c_unlock(struct tcakp_softc *); + static int tcakp_read(struct tcakp_softc *, uint8_t, uint8_t *); static int tcakp_write(struct tcakp_softc *, uint8_t, uint8_t); @@ -137,8 +141,28 @@ static int tcakp_intr(void *priv) { struct tcakp_softc * const sc = priv; + + /* + * Schedule our soft interrupt handler. We can't access the i2c + * from hard interrupt context, so just go ahead and claim the + * interrupt. + * + * XXX If we ever end up with an instance that uses + * level-sensitive interrupts, we will need to mask + * the interrupt source. + */ + softint_schedule(sc->sc_sih); + return 1; +} + +static void +tcakp_softintr(void *priv) +{ + struct tcakp_softc * const sc = priv; uint8_t stat, ev; - int ret = 0; + + if (tcakp_i2c_lock(sc) != 0) + return; tcakp_read(sc, TCA_INT_STAT, ); if (stat & INT_STAT_K_INT) { @@ -147,6 +171,8 @@ tcakp_intr(void *priv) const bool pressed = __SHIFTOUT(ev, TCA_EVENT_STATE); const uint8_t code = __SHIFTOUT(ev, TCA_EVENT_CODE); + tcakp_i2c_unlock(sc); + /* Translate raw code to keymap index */ const u_int index = tcakp_decode(sc, code); @@ -157,13 +183,13 @@ tcakp_intr(void *priv) if (sc->sc_wskbddev) wskbd_input(sc->sc_wskbddev, type, key); + if (tcakp_i2c_lock(sc) != 0) +return; tcakp_read(sc, TCA_EVENT('A'), ); } - ret = 1; } tcakp_write(sc, TCA_INT_STAT, stat); - - return ret; + tcakp_i2c_unlock(sc); } static int @@ -171,6 +197,7 @@ tcakp_init(struct tcakp_softc *sc) { uint32_t mask; uint8_t val; + int error; if (sc->sc_rows == 0 || sc->sc_cols == 0) { aprint_error_dev(sc->sc_dev, "not configured\n"); @@ -180,6 +207,10 @@ tcakp_init(struct tcakp_softc *sc) mask = __BITS(sc->sc_rows - 1, 0); mask += __BITS(sc->sc_cols - 1, 0) << 8; + error = tcakp_i2c_lock(sc); + if (error) + return error; + /* Lock the keyboard */ tcakp_write(sc, TCA_KEY_LCK_EC, KEY_LCK_EC_K_LCK_EN); /* Select keyboard mode */ @@ -196,6 +227,8 @@ tcakp_init(struct tcakp_softc *sc) tcakp_read(sc, TCA_INT_STAT, ); tcakp_write(sc, TCA_INT_STAT, val); + tcakp_i2c_unlock(sc); + return 0; } @@ -234,6 +267,11 @@ static int tcakp_enable(void *v, int on) { struct tcakp_softc * const sc = v; + int error; + + error = tcakp_i2c_lock(sc); + if (error) + return error; if (on) { /* Disable key lock */ @@ -243,6 +281,7 @@ tcakp_enable(void *v, int on) tcakp_write(sc, TCA_KEY_LCK_EC, KEY_LCK_EC_K_LCK_EN); } + tcakp_i2c_unlock(sc); return 0; } @@ -276,6 +315,8 @@ tcakp_cngetc(void *v, u_int *type, int * struct tcakp_softc * const sc = v; uint8_t ev = 0; + /* XXX i2c bus acquire */ + do { tcakp_read(sc, TCA_EVENT('A'), ); } while (ev == 0); @@ -287,6 +328,8 @@ tcakp_cngetc(void *v, u_int *type, int * *type = pressed ? WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP; *data = sc->sc_keymap[index]; + + /* XXX i2c bus release */ } static void @@ -345,6 +388,21 @@ tcakp_attach(device_t parent, device_t s #ifdef FDT sc->sc_ih = fdtbus_intr_establish(sc->sc_phandle, 0, IPL_VM, 0, tcakp_intr, sc); + /* + *
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 19:38:58 UTC 2019 Modified Files: src/sys/dev/i2c: tcagpio.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/tcagpio.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/tcagpio.c diff -u src/sys/dev/i2c/tcagpio.c:1.4 src/sys/dev/i2c/tcagpio.c:1.5 --- src/sys/dev/i2c/tcagpio.c:1.4 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/tcagpio.c Mon Dec 23 19:38:58 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: tcagpio.c,v 1.4 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: tcagpio.c,v 1.5 2019/12/23 19:38:58 thorpej Exp $ */ /*- * Copyright (c) 2017 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tcagpio.c,v 1.4 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tcagpio.c,v 1.5 2019/12/23 19:38:58 thorpej Exp $"); #include #include @@ -102,10 +102,10 @@ tcagpio_write(struct tcagpio_softc *sc, aprint_error_dev(sc->sc_dev, "error writing reg %#x: %d\n", reg, error); } -#define I2C_READ(sc, reg) tcagpio_read((sc), (reg), I2C_F_POLL) -#define I2C_WRITE(sc, reg, val) tcagpio_write((sc), (reg), (val), I2C_F_POLL) -#define I2C_LOCK(sc) iic_acquire_bus((sc)->sc_i2c, I2C_F_POLL) -#define I2C_UNLOCK(sc) iic_release_bus((sc)->sc_i2c, I2C_F_POLL) +#define I2C_READ(sc, reg) tcagpio_read((sc), (reg), 0) +#define I2C_WRITE(sc, reg, val) tcagpio_write((sc), (reg), (val), 0) +#define I2C_LOCK(sc) iic_acquire_bus((sc)->sc_i2c, 0) +#define I2C_UNLOCK(sc) iic_release_bus((sc)->sc_i2c, 0) static int tcagpio_gpio_config(struct tcagpio_softc *sc, int pin, int flags)
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 19:35:07 UTC 2019 Modified Files: src/sys/dev/i2c: sy8106a.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/sy8106a.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/sy8106a.c diff -u src/sys/dev/i2c/sy8106a.c:1.4 src/sys/dev/i2c/sy8106a.c:1.5 --- src/sys/dev/i2c/sy8106a.c:1.4 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/sy8106a.c Mon Dec 23 19:35:07 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: sy8106a.c,v 1.4 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: sy8106a.c,v 1.5 2019/12/23 19:35:07 thorpej Exp $ */ /*- * Copyright (c) 2017 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sy8106a.c,v 1.4 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sy8106a.c,v 1.5 2019/12/23 19:35:07 thorpej Exp $"); #include #include @@ -93,10 +93,10 @@ sy8106a_write(struct sy8106a_softc *sc, aprint_error_dev(sc->sc_dev, "error writing reg %#x: %d\n", reg, error); } -#define I2C_READ(sc, reg) sy8106a_read((sc), (reg), I2C_F_POLL) -#define I2C_WRITE(sc, reg, val) sy8106a_write((sc), (reg), (val), I2C_F_POLL) -#define I2C_LOCK(sc) iic_acquire_bus((sc)->sc_i2c, I2C_F_POLL) -#define I2C_UNLOCK(sc) iic_release_bus((sc)->sc_i2c, I2C_F_POLL) +#define I2C_READ(sc, reg) sy8106a_read((sc), (reg), 0) +#define I2C_WRITE(sc, reg, val) sy8106a_write((sc), (reg), (val), 0) +#define I2C_LOCK(sc) iic_acquire_bus((sc)->sc_i2c, 0) +#define I2C_UNLOCK(sc) iic_release_bus((sc)->sc_i2c, 0) static int sy8106a_acquire(device_t dev)
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 19:22:46 UTC 2019 Modified Files: src/sys/dev/i2c: fan53555.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 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.4 src/sys/dev/i2c/fan53555.c:1.5 --- src/sys/dev/i2c/fan53555.c:1.4 Tue Nov 12 07:40:04 2019 +++ src/sys/dev/i2c/fan53555.c Mon Dec 23 19:22:46 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: fan53555.c,v 1.4 2019/11/12 07:40:04 mrg Exp $ */ +/* $NetBSD: fan53555.c,v 1.5 2019/12/23 19:22:46 thorpej Exp $ */ /*- * Copyright (c) 2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: fan53555.c,v 1.4 2019/11/12 07:40:04 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fan53555.c,v 1.5 2019/12/23 19:22:46 thorpej Exp $"); #include #include @@ -124,10 +124,10 @@ fan53555_write(struct fan53555_softc *sc aprint_error_dev(sc->sc_dev, "error writing reg %#x: %d\n", reg, error); } -#define I2C_READ(sc, reg) fan53555_read((sc), (reg), I2C_F_POLL) -#define I2C_WRITE(sc, reg, val) fan53555_write((sc), (reg), (val), I2C_F_POLL) -#define I2C_LOCK(sc) iic_acquire_bus((sc)->sc_i2c, I2C_F_POLL) -#define I2C_UNLOCK(sc) iic_release_bus((sc)->sc_i2c, I2C_F_POLL) +#define I2C_READ(sc, reg) fan53555_read((sc), (reg), 0) +#define I2C_WRITE(sc, reg, val) fan53555_write((sc), (reg), (val), 0) +#define I2C_LOCK(sc) iic_acquire_bus((sc)->sc_i2c, 0) +#define I2C_UNLOCK(sc) iic_release_bus((sc)->sc_i2c, 0) static int fan53555_acquire(device_t dev)
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 19:20:18 UTC 2019 Modified Files: src/sys/dev/i2c: max77620.c Log Message: Actually, the local mutex is unnecesary; the i2c bus lock is held across all register r/m/w cycles, so we can just piggy back on that. (I misread the code previously.) To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/max77620.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/max77620.c diff -u src/sys/dev/i2c/max77620.c:1.7 src/sys/dev/i2c/max77620.c:1.8 --- src/sys/dev/i2c/max77620.c:1.7 Mon Dec 23 18:49:13 2019 +++ src/sys/dev/i2c/max77620.c Mon Dec 23 19:20:18 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: max77620.c,v 1.7 2019/12/23 18:49:13 thorpej Exp $ */ +/* $NetBSD: max77620.c,v 1.8 2019/12/23 19:20:18 thorpej Exp $ */ /*- * Copyright (c) 2017 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: max77620.c,v 1.7 2019/12/23 18:49:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: max77620.c,v 1.8 2019/12/23 19:20:18 thorpej Exp $"); #include #include @@ -58,13 +58,6 @@ struct max77620_softc { i2c_tag_t sc_i2c; i2c_addr_t sc_addr; int sc_phandle; - - /* - * Locking order: - * - * max77620 -> i2c - */ - kmutex_t sc_lock; }; struct max77620_pin { @@ -115,7 +108,6 @@ max77620_gpio_config(struct max77620_sof uint32_t gpio; KASSERT(pin >= 0 && pin < MAX_GPIO_COUNT); - KASSERT(mutex_owned(>sc_lock)); gpio = I2C_READ(sc, MAX_GPIO_REG(pin)); @@ -170,11 +162,9 @@ max77620_gpio_acquire(device_t dev, cons if (pin >= MAX_GPIO_COUNT) return NULL; - mutex_enter(>sc_lock); I2C_LOCK(sc); error = max77620_gpio_config(sc, pin, flags); I2C_UNLOCK(sc); - mutex_exit(>sc_lock); if (error != 0) { device_printf(dev, "bad pin %d config %#x\n", pin, flags); @@ -196,11 +186,9 @@ max77620_gpio_release(device_t dev, void struct max77620_softc * const sc = device_private(dev); struct max77620_pin *gpin = priv; - mutex_enter(>sc_lock); I2C_LOCK(sc); max77620_gpio_config(sc, gpin->pin_num, GPIO_PIN_INPUT|GPIO_PIN_OPENDRAIN); I2C_UNLOCK(sc); - mutex_exit(>sc_lock); kmem_free(gpin, sizeof(*gpin)); } @@ -245,7 +233,6 @@ max77620_gpio_write(device_t dev, void * if (!raw && gpin->pin_actlo) val = !val; - mutex_enter(>sc_lock); I2C_LOCK(sc); gpio = I2C_READ(sc, MAX_GPIO_REG(gpin->pin_num)); gpio &= ~MAX_GPIO_OUTPUT_VAL; @@ -257,7 +244,6 @@ max77620_gpio_write(device_t dev, void * #endif I2C_WRITE(sc, MAX_GPIO_REG(gpin->pin_num), gpio); I2C_UNLOCK(sc); - mutex_exit(>sc_lock); } static struct fdtbus_gpio_controller_func max77620_gpio_funcs = { @@ -297,8 +283,6 @@ max77620_attach(device_t parent, device_ sc->sc_addr = ia->ia_addr; sc->sc_phandle = ia->ia_cookie; - mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_NONE); - aprint_naive("\n"); aprint_normal(": MAX77620 Power Management IC\n");
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 19:12:22 UTC 2019 Modified Files: src/sys/dev/i2c: axp20x.c Log Message: - Don't read/write the device if iic_acquire_bus() fails. - axp20x_poweroff(): report the error code if power off fails. - Don't use polled access in axp20xreg_{get,set}_voltage(). To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/sys/dev/i2c/axp20x.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/axp20x.c diff -u src/sys/dev/i2c/axp20x.c:1.14 src/sys/dev/i2c/axp20x.c:1.15 --- src/sys/dev/i2c/axp20x.c:1.14 Mon Dec 23 02:50:50 2019 +++ src/sys/dev/i2c/axp20x.c Mon Dec 23 19:12:22 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: axp20x.c,v 1.14 2019/12/23 02:50:50 thorpej Exp $ */ +/* $NetBSD: axp20x.c,v 1.15 2019/12/23 19:12:22 thorpej Exp $ */ /*- * Copyright (c) 2014-2017 Jared McNeill @@ -29,7 +29,7 @@ #include "opt_fdt.h" #include -__KERNEL_RCSID(0, "$NetBSD: axp20x.c,v 1.14 2019/12/23 02:50:50 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axp20x.c,v 1.15 2019/12/23 19:12:22 thorpej Exp $"); #include #include @@ -567,10 +567,14 @@ axp20x_read(struct axp20x_softc *sc, uin int flags) { int ret; - iic_acquire_bus(sc->sc_i2c, flags); - ret = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr, - , 1, val, len, flags); - iic_release_bus(sc->sc_i2c, flags); + + ret = iic_acquire_bus(sc->sc_i2c, flags); + if (ret == 0) { + ret = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr, + , 1, val, len, flags); + iic_release_bus(sc->sc_i2c, flags); + } + return ret; } @@ -580,10 +584,14 @@ axp20x_write(struct axp20x_softc *sc, ui int flags) { int ret; - iic_acquire_bus(sc->sc_i2c, flags); - ret = iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, - , 1, val, len, flags); - iic_release_bus(sc->sc_i2c, flags); + + ret = iic_acquire_bus(sc->sc_i2c, flags); + if (ret == 0) { + ret = iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, + , 1, val, len, flags); + iic_release_bus(sc->sc_i2c, flags); + } + return ret; } @@ -667,9 +675,13 @@ axp20x_poweroff(device_t dev) { struct axp20x_softc * const sc = device_private(dev); uint8_t reg = AXP_SHUTDOWN_CTRL; + int error; - if (axp20x_write(sc, AXP_SHUTDOWN, , 1, I2C_F_POLL) != 0) - device_printf(dev, "WARNING: poweroff failed\n"); + error = axp20x_write(sc, AXP_SHUTDOWN, , 1, I2C_F_POLL); + if (error) { + device_printf(dev, "WARNING: unable to power off, error %d\n", + error); + } } #ifdef FDT @@ -714,7 +726,7 @@ axp20xreg_set_voltage(device_t dev, u_in { struct axp20xreg_softc * const sc = device_private(dev); - return axp20x_set_dcdc(device_parent(dev), sc->sc_regdef->dcdc, min_uvol / 1000, true); + return axp20x_set_dcdc(device_parent(dev), sc->sc_regdef->dcdc, min_uvol / 1000, false); } static int @@ -723,7 +735,7 @@ axp20xreg_get_voltage(device_t dev, u_in struct axp20xreg_softc * const sc = device_private(dev); int mvol, error; - error = axp20x_get_dcdc(device_parent(dev), sc->sc_regdef->dcdc, , true); + error = axp20x_get_dcdc(device_parent(dev), sc->sc_regdef->dcdc, , false); if (error != 0) return error;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 19:00:59 UTC 2019 Modified Files: src/sys/dev/i2c: nxt2k.c Log Message: - No need to use I2C_F_POLL here. - If iic_acquire_bus() fails, return the error, not false (because false looks like "everything A-OK!" to the caller). To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/nxt2k.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/nxt2k.c diff -u src/sys/dev/i2c/nxt2k.c:1.5 src/sys/dev/i2c/nxt2k.c:1.6 --- src/sys/dev/i2c/nxt2k.c:1.5 Thu Jun 1 02:45:10 2017 +++ src/sys/dev/i2c/nxt2k.c Mon Dec 23 19:00:59 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: nxt2k.c,v 1.5 2017/06/01 02:45:10 chs Exp $ */ +/* $NetBSD: nxt2k.c,v 1.6 2019/12/23 19:00:59 thorpej Exp $ */ /* * Copyright (c) 2008, 2011 Jonathan A. Kollasch @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: nxt2k.c,v 1.5 2017/06/01 02:45:10 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nxt2k.c,v 1.6 2019/12/23 19:00:59 thorpej Exp $"); #include #include @@ -74,16 +74,16 @@ nxt2k_writedata(struct nxt2k *nxt, uint8 KASSERT((len + 1) <= 384); - if (iic_acquire_bus(nxt->tag, I2C_F_POLL) != 0) - return false; + if ((error = iic_acquire_bus(nxt->tag, 0) != 0)) + return error; buffer[0] = reg; memcpy([1], data, len); error = iic_exec(nxt->tag, I2C_OP_WRITE_WITH_STOP, nxt->addr, - buffer, len + 1, NULL, 0, I2C_F_POLL); + buffer, len + 1, NULL, 0, 0); - iic_release_bus(nxt->tag, I2C_F_POLL); + iic_release_bus(nxt->tag, 0); return error; } @@ -93,13 +93,13 @@ nxt2k_readdata(struct nxt2k *nxt, uint8_ { int error; - if (iic_acquire_bus(nxt->tag, I2C_F_POLL) != 0) - return false; + if ((error = iic_acquire_bus(nxt->tag, 0) != 0)) + return error; error = iic_exec(nxt->tag, I2C_OP_READ_WITH_STOP, nxt->addr, - , 1, data, len, I2C_F_POLL); + , 1, data, len, 0); - iic_release_bus(nxt->tag, I2C_F_POLL); + iic_release_bus(nxt->tag, 0); return error; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 18:57:30 UTC 2019 Modified Files: src/sys/dev/i2c: mt2131.c Log Message: - No need to use I2C_F_POLL here. - Don't write to the device if iic_acquire_bus() fails. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/mt2131.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/mt2131.c diff -u src/sys/dev/i2c/mt2131.c:1.6 src/sys/dev/i2c/mt2131.c:1.7 --- src/sys/dev/i2c/mt2131.c:1.6 Thu Jun 1 02:45:10 2017 +++ src/sys/dev/i2c/mt2131.c Mon Dec 23 18:57:30 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: mt2131.c,v 1.6 2017/06/01 02:45:10 chs Exp $ */ +/* $NetBSD: mt2131.c,v 1.7 2019/12/23 18:57:30 thorpej Exp $ */ /* * Copyright (c) 2008, 2011 Jonathan A. Kollasch @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mt2131.c,v 1.6 2017/06/01 02:45:10 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mt2131.c,v 1.7 2019/12/23 18:57:30 thorpej Exp $"); #include #include @@ -85,9 +85,12 @@ mt2131_open(device_t parent, i2c_tag_t t cmd = reg = 0; /* get id reg */ - iic_acquire_bus(t, I2C_F_POLL); - ret = iic_exec(t, I2C_OP_READ_WITH_STOP, a, , 1, , 1, I2C_F_POLL); - iic_release_bus(t, I2C_F_POLL); + ret = iic_acquire_bus(t, 0); + if (ret == 0) { + ret = iic_exec(t, I2C_OP_READ_WITH_STOP, a, , 1, , 1, + 0); + iic_release_bus(t, 0); + } if (ret) { device_printf(parent, "%s(): read fail\n", __func__); @@ -153,9 +156,12 @@ mt2131_tune_dtv(struct mt2131_softc *sc, b[5] = (d2 & 0x001f); b[6] = r2; - iic_acquire_bus(sc->tag, I2C_F_POLL); - rv = iic_exec(sc->tag, I2C_OP_WRITE_WITH_STOP, sc->addr, b, 7, NULL, 0, I2C_F_POLL); - iic_release_bus(sc->tag, I2C_F_POLL); + rv = iic_acquire_bus(sc->tag, 0); + if (rv == 0) { + rv = iic_exec(sc->tag, I2C_OP_WRITE_WITH_STOP, sc->addr, b, 7, + NULL, 0, 0); + iic_release_bus(sc->tag, 0); + } regval = (fr - 27501) / 55000; @@ -191,27 +197,27 @@ mt2131_init(struct mt2131_softc *sc) { int ret; - ret = iic_acquire_bus(sc->tag, I2C_F_POLL); + ret = iic_acquire_bus(sc->tag, 0); if (ret) return -1; ret = iic_exec(sc->tag, I2C_OP_WRITE_WITH_STOP, sc->addr, - mt2131_initstring, sizeof(mt2131_initstring), NULL, 0, I2C_F_POLL); + mt2131_initstring, sizeof(mt2131_initstring), NULL, 0, 0); + iic_release_bus(sc->tag, 0); if (ret) return -1; - iic_release_bus(sc->tag, I2C_F_POLL); ret = mt2131_write(sc, UPC_1, 0x09); ret = mt2131_write(sc, MISC_2, 0x47); ret = mt2131_write(sc, PWR, 0xf2); ret = mt2131_write(sc, UPC_1, 0x01); - ret = iic_acquire_bus(sc->tag, I2C_F_POLL); + ret = iic_acquire_bus(sc->tag, 0); if (ret) return -1; ret = iic_exec(sc->tag, I2C_OP_WRITE_WITH_STOP, sc->addr, mt2131_agcinitstring, sizeof(mt2131_agcinitstring), - NULL, 0, I2C_F_POLL); - iic_release_bus(sc->tag, I2C_F_POLL); + NULL, 0, 0); + iic_release_bus(sc->tag, 0); if (ret) return -1; @@ -223,13 +229,13 @@ mt2131_read(struct mt2131_softc *sc, uin { int ret; - ret = iic_acquire_bus(sc->tag, I2C_F_POLL); + ret = iic_acquire_bus(sc->tag, 0); if (ret) return ret; ret = iic_exec(sc->tag, I2C_OP_READ_WITH_STOP, sc->addr, - , 1, v, 1, I2C_F_POLL); + , 1, v, 1, 0); - iic_release_bus(sc->tag, I2C_F_POLL); + iic_release_bus(sc->tag, 0); return ret; } @@ -240,14 +246,14 @@ mt2131_write(struct mt2131_softc *sc, ui int ret; uint8_t b[] = { a, v }; - ret = iic_acquire_bus(sc->tag, I2C_F_POLL); + ret = iic_acquire_bus(sc->tag, 0); if (ret) return ret; ret = iic_exec(sc->tag, I2C_OP_READ_WITH_STOP, sc->addr, - b, sizeof(b), NULL, 0, I2C_F_POLL); + b, sizeof(b), NULL, 0, 0); - iic_release_bus(sc->tag, I2C_F_POLL); + iic_release_bus(sc->tag, 0); return ret; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 18:49:14 UTC 2019 Modified Files: src/sys/dev/i2c: max77620.c Log Message: - No need to use I2C_F_POLL here. - Use a local mutex to protect register read-modify-write cycles. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/max77620.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/max77620.c diff -u src/sys/dev/i2c/max77620.c:1.6 src/sys/dev/i2c/max77620.c:1.7 --- src/sys/dev/i2c/max77620.c:1.6 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/max77620.c Mon Dec 23 18:49:13 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: max77620.c,v 1.6 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: max77620.c,v 1.7 2019/12/23 18:49:13 thorpej Exp $ */ /*- * Copyright (c) 2017 Jared McNeill @@ -27,10 +27,11 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: max77620.c,v 1.6 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: max77620.c,v 1.7 2019/12/23 18:49:13 thorpej Exp $"); #include #include +#include #include #include #include @@ -57,6 +58,13 @@ struct max77620_softc { i2c_tag_t sc_i2c; i2c_addr_t sc_addr; int sc_phandle; + + /* + * Locking order: + * + * max77620 -> i2c + */ + kmutex_t sc_lock; }; struct max77620_pin { @@ -96,10 +104,10 @@ max77620_write(struct max77620_softc *sc aprint_error_dev(sc->sc_dev, "error writing reg %#x: %d\n", reg, error); } -#define I2C_READ(sc, reg) max77620_read((sc), (reg), I2C_F_POLL) -#define I2C_WRITE(sc, reg, val) max77620_write((sc), (reg), (val), I2C_F_POLL) -#define I2C_LOCK(sc) iic_acquire_bus((sc)->sc_i2c, I2C_F_POLL) -#define I2C_UNLOCK(sc) iic_release_bus((sc)->sc_i2c, I2C_F_POLL) +#define I2C_READ(sc, reg) max77620_read((sc), (reg), 0) +#define I2C_WRITE(sc, reg, val) max77620_write((sc), (reg), (val), 0) +#define I2C_LOCK(sc) iic_acquire_bus((sc)->sc_i2c, 0) +#define I2C_UNLOCK(sc) iic_release_bus((sc)->sc_i2c, 0) static int max77620_gpio_config(struct max77620_softc *sc, int pin, int flags) @@ -107,6 +115,7 @@ max77620_gpio_config(struct max77620_sof uint32_t gpio; KASSERT(pin >= 0 && pin < MAX_GPIO_COUNT); + KASSERT(mutex_owned(>sc_lock)); gpio = I2C_READ(sc, MAX_GPIO_REG(pin)); @@ -161,9 +170,11 @@ max77620_gpio_acquire(device_t dev, cons if (pin >= MAX_GPIO_COUNT) return NULL; + mutex_enter(>sc_lock); I2C_LOCK(sc); error = max77620_gpio_config(sc, pin, flags); I2C_UNLOCK(sc); + mutex_exit(>sc_lock); if (error != 0) { device_printf(dev, "bad pin %d config %#x\n", pin, flags); @@ -185,9 +196,11 @@ max77620_gpio_release(device_t dev, void struct max77620_softc * const sc = device_private(dev); struct max77620_pin *gpin = priv; + mutex_enter(>sc_lock); I2C_LOCK(sc); max77620_gpio_config(sc, gpin->pin_num, GPIO_PIN_INPUT|GPIO_PIN_OPENDRAIN); I2C_UNLOCK(sc); + mutex_exit(>sc_lock); kmem_free(gpin, sizeof(*gpin)); } @@ -200,6 +213,11 @@ max77620_gpio_read(device_t dev, void *p uint8_t gpio; int val; + /* + * Performing a register read only; no need to acquire + * the max77620 lock. + */ + I2C_LOCK(sc); gpio = I2C_READ(sc, MAX_GPIO_REG(gpin->pin_num)); I2C_UNLOCK(sc); @@ -227,6 +245,7 @@ max77620_gpio_write(device_t dev, void * if (!raw && gpin->pin_actlo) val = !val; + mutex_enter(>sc_lock); I2C_LOCK(sc); gpio = I2C_READ(sc, MAX_GPIO_REG(gpin->pin_num)); gpio &= ~MAX_GPIO_OUTPUT_VAL; @@ -238,6 +257,7 @@ max77620_gpio_write(device_t dev, void * #endif I2C_WRITE(sc, MAX_GPIO_REG(gpin->pin_num), gpio); I2C_UNLOCK(sc); + mutex_exit(>sc_lock); } static struct fdtbus_gpio_controller_func max77620_gpio_funcs = { @@ -277,6 +297,8 @@ max77620_attach(device_t parent, device_ sc->sc_addr = ia->ia_addr; sc->sc_phandle = ia->ia_cookie; + mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_NONE); + aprint_naive("\n"); aprint_normal(": MAX77620 Power Management IC\n");
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 18:27:11 UTC 2019 Modified Files: src/sys/dev/i2c: i2c.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.71 -r1.72 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.71 src/sys/dev/i2c/i2c.c:1.72 --- src/sys/dev/i2c/i2c.c:1.71 Sun Dec 22 23:23:32 2019 +++ src/sys/dev/i2c/i2c.c Mon Dec 23 18:27:11 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.71 2019/12/22 23:23:32 thorpej Exp $ */ +/* $NetBSD: i2c.c,v 1.72 2019/12/23 18:27:11 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -40,7 +40,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.71 2019/12/22 23:23:32 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.72 2019/12/23 18:27:11 thorpej Exp $"); #include #include @@ -353,7 +353,7 @@ iic_search(device_t parent, cfdata_t cf, * to see if it looks like something is really there. */ if (match_result == I2C_MATCH_ADDRESS_ONLY && - (error = (*probe_func)(sc, , I2C_F_POLL)) != 0) + (error = (*probe_func)(sc, , 0)) != 0) continue; sc->sc_devices[ia.ia_addr] =
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 18:12:50 UTC 2019 Modified Files: src/sys/dev/i2c: ddc.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/sys/dev/i2c/ddc.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/ddc.c diff -u src/sys/dev/i2c/ddc.c:1.8 src/sys/dev/i2c/ddc.c:1.9 --- src/sys/dev/i2c/ddc.c:1.8 Mon Sep 3 16:29:31 2018 +++ src/sys/dev/i2c/ddc.c Mon Dec 23 18:12:50 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: ddc.c,v 1.8 2018/09/03 16:29:31 riastradh Exp $ */ +/* $NetBSD: ddc.c,v 1.9 2019/12/23 18:12:50 thorpej Exp $ */ /*- * Copyright (c) 2006 Itronix Inc. @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ddc.c,v 1.8 2018/09/03 16:29:31 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ddc.c,v 1.9 2019/12/23 18:12:50 thorpej Exp $"); #include #include @@ -102,17 +102,17 @@ ddc_read_edid_block(i2c_tag_t tag, uint8 uint8_t wbuf[2]; int error; - if ((error = iic_acquire_bus(tag, I2C_F_POLL)) != 0) + if ((error = iic_acquire_bus(tag, 0)) != 0) return error; wbuf[0] = block >> 1; /* start address */ if ((error = iic_exec(tag, I2C_OP_READ_WITH_STOP, DDC_ADDR, wbuf, 1, - edid, sizeof(edid), I2C_F_POLL)) != 0) { - iic_release_bus(tag, I2C_F_POLL); + edid, sizeof(edid), 0)) != 0) { + iic_release_bus(tag, 0); return error; } - iic_release_bus(tag, I2C_F_POLL); + iic_release_bus(tag, 0); if (block & 1) { memcpy(dest, [128], uimin(len, 128));
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 18:09:06 UTC 2019 Modified Files: src/sys/dev/i2c: cx24227.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/cx24227.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/cx24227.c diff -u src/sys/dev/i2c/cx24227.c:1.9 src/sys/dev/i2c/cx24227.c:1.10 --- src/sys/dev/i2c/cx24227.c:1.9 Mon Dec 23 18:03:14 2019 +++ src/sys/dev/i2c/cx24227.c Mon Dec 23 18:09:05 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cx24227.c,v 1.9 2019/12/23 18:03:14 thorpej Exp $ */ +/* $NetBSD: cx24227.c,v 1.10 2019/12/23 18:09:05 thorpej Exp $ */ /* * Copyright (c) 2008, 2011 Jonathan A. Kollasch @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cx24227.c,v 1.9 2019/12/23 18:03:14 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cx24227.c,v 1.10 2019/12/23 18:09:05 thorpej Exp $"); #include #include @@ -108,16 +108,16 @@ cx24227_writereg(struct cx24227 *sc, uin int error; uint8_t r[3]; - if ((error = iic_acquire_bus(sc->tag, I2C_F_POLL) != 0)) + if ((error = iic_acquire_bus(sc->tag, 0) != 0)) return error; r[0] = reg; r[1] = (data >> 8) & 0xff; r[2] = data & 0xff; error = iic_exec(sc->tag, I2C_OP_WRITE_WITH_STOP, sc->addr, - r, 3, NULL, 0, I2C_F_POLL); + r, 3, NULL, 0, 0); - iic_release_bus(sc->tag, I2C_F_POLL); + iic_release_bus(sc->tag, 0); return error; } @@ -130,13 +130,13 @@ cx24227_readreg(struct cx24227 *sc, uint *data = 0x; - if ((error = iic_acquire_bus(sc->tag, I2C_F_POLL) != 0)) + if ((error = iic_acquire_bus(sc->tag, 0) != 0)) return error; error = iic_exec(sc->tag, I2C_OP_READ_WITH_STOP, sc->addr, - , 1, r, 2, I2C_F_POLL); + , 1, r, 2, 0); - iic_release_bus(sc->tag, I2C_F_POLL); + iic_release_bus(sc->tag, 0); *data |= r[0] << 8; *data |= r[1];
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 18:03:14 UTC 2019 Modified Files: src/sys/dev/i2c: cx24227.c Log Message: In cx24227_writereg() / cx24227_readreg(), return the error from iic_acquire_bus(), not some bogus return value that can potentially be confused for a real error code. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/sys/dev/i2c/cx24227.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/cx24227.c diff -u src/sys/dev/i2c/cx24227.c:1.8 src/sys/dev/i2c/cx24227.c:1.9 --- src/sys/dev/i2c/cx24227.c:1.8 Thu Jun 1 02:45:10 2017 +++ src/sys/dev/i2c/cx24227.c Mon Dec 23 18:03:14 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cx24227.c,v 1.8 2017/06/01 02:45:10 chs Exp $ */ +/* $NetBSD: cx24227.c,v 1.9 2019/12/23 18:03:14 thorpej Exp $ */ /* * Copyright (c) 2008, 2011 Jonathan A. Kollasch @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cx24227.c,v 1.8 2017/06/01 02:45:10 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cx24227.c,v 1.9 2019/12/23 18:03:14 thorpej Exp $"); #include #include @@ -108,8 +108,8 @@ cx24227_writereg(struct cx24227 *sc, uin int error; uint8_t r[3]; - if (iic_acquire_bus(sc->tag, I2C_F_POLL) != 0) - return false; + if ((error = iic_acquire_bus(sc->tag, I2C_F_POLL) != 0)) + return error; r[0] = reg; r[1] = (data >> 8) & 0xff; @@ -130,8 +130,8 @@ cx24227_readreg(struct cx24227 *sc, uint *data = 0x; - if (iic_acquire_bus(sc->tag, I2C_F_POLL) != 0) - return -1; + if ((error = iic_acquire_bus(sc->tag, I2C_F_POLL) != 0)) + return error; error = iic_exec(sc->tag, I2C_OP_READ_WITH_STOP, sc->addr, , 1, r, 2, I2C_F_POLL);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 15:51:50 UTC 2019 Modified Files: src/sys/dev/i2c: at24cxx.c Log Message: Oops, missed one more instance of unneeded-I2C_F_POLL. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 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.34 src/sys/dev/i2c/at24cxx.c:1.35 --- src/sys/dev/i2c/at24cxx.c:1.34 Mon Dec 23 02:39:47 2019 +++ src/sys/dev/i2c/at24cxx.c Mon Dec 23 15:51:50 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: at24cxx.c,v 1.34 2019/12/23 02:39:47 thorpej Exp $ */ +/* $NetBSD: at24cxx.c,v 1.35 2019/12/23 15:51:50 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.34 2019/12/23 02:39:47 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.35 2019/12/23 15:51:50 thorpej Exp $"); #include #include @@ -431,7 +431,7 @@ seeprom_bootstrap_read(i2c_tag_t tag, in /* Read a single byte. */ if (iic_exec(tag, I2C_OP_READ_WITH_STOP, addr, - cmdbuf, cmdlen, rvp, 1, I2C_F_POLL)) { + cmdbuf, cmdlen, rvp, 1, 0)) { iic_release_bus(tag, 0); return (-1); }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 15:48:51 UTC 2019 Modified Files: src/sys/dev/i2c: as3722.c Log Message: In as3722_poweroff and as3722_reboot(), check for errors from iic_acquire_bus() before proceeding with writing to the device. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/sys/dev/i2c/as3722.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/as3722.c diff -u src/sys/dev/i2c/as3722.c:1.17 src/sys/dev/i2c/as3722.c:1.18 --- src/sys/dev/i2c/as3722.c:1.17 Mon Dec 23 02:35:18 2019 +++ src/sys/dev/i2c/as3722.c Mon Dec 23 15:48:51 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: as3722.c,v 1.17 2019/12/23 02:35:18 thorpej Exp $ */ +/* $NetBSD: as3722.c,v 1.18 2019/12/23 15:48:51 thorpej Exp $ */ /*- * Copyright (c) 2015 Jared D. McNeill @@ -29,7 +29,7 @@ #include "opt_fdt.h" #include -__KERNEL_RCSID(0, "$NetBSD: as3722.c,v 1.17 2019/12/23 02:35:18 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: as3722.c,v 1.18 2019/12/23 15:48:51 thorpej Exp $"); #include #include @@ -852,10 +852,16 @@ as3722_poweroff(device_t dev) const int flags = I2C_F_POLL; - iic_acquire_bus(sc->sc_i2c, flags); - error = as3722_write(sc, AS3722_RESET_CTRL_REG, - AS3722_RESET_CTRL_POWER_OFF, flags); - iic_release_bus(sc->sc_i2c, flags); + error = iic_acquire_bus(sc->sc_i2c, flags); + if (error == 0) { + error = as3722_write(sc, AS3722_RESET_CTRL_REG, + AS3722_RESET_CTRL_POWER_OFF, flags); + iic_release_bus(sc->sc_i2c, flags); + } + if (error) { + device_printf(dev, "WARNING: unable to power off, error %d\n", + error); + } return error; } @@ -868,10 +874,16 @@ as3722_reboot(device_t dev) const int flags = I2C_F_POLL; - iic_acquire_bus(sc->sc_i2c, flags); - error = as3722_write(sc, AS3722_RESET_CTRL_REG, - AS3722_RESET_CTRL_FORCE_RESET, flags); - iic_release_bus(sc->sc_i2c, flags); + error = iic_acquire_bus(sc->sc_i2c, flags); + if (error == 0) { + error = as3722_write(sc, AS3722_RESET_CTRL_REG, + AS3722_RESET_CTRL_FORCE_RESET, flags); + iic_release_bus(sc->sc_i2c, flags); + } + if (error) { + device_printf(dev, "WARNING: unable to reboot, error %d\n", + error); + } return error; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 15:25:08 UTC 2019 Modified Files: src/sys/dev/i2c: tvpll.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/tvpll.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/tvpll.c diff -u src/sys/dev/i2c/tvpll.c:1.7 src/sys/dev/i2c/tvpll.c:1.8 --- src/sys/dev/i2c/tvpll.c:1.7 Thu Jun 1 02:45:10 2017 +++ src/sys/dev/i2c/tvpll.c Mon Dec 23 15:25:08 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: tvpll.c,v 1.7 2017/06/01 02:45:10 chs Exp $ */ +/* $NetBSD: tvpll.c,v 1.8 2019/12/23 15:25:08 thorpej Exp $ */ /* * Copyright (c) 2008, 2011 Jonathan A. Kollasch @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tvpll.c,v 1.7 2017/06/01 02:45:10 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tvpll.c,v 1.8 2019/12/23 15:25:08 thorpej Exp $"); #include #include @@ -63,11 +63,11 @@ tvpll_open(device_t parent, i2c_tag_t t, tvpll->pll = p; if (tvpll->pll->initdata) { - iic_acquire_bus(tvpll->tag, I2C_F_POLL); + iic_acquire_bus(tvpll->tag, 0); (void)iic_exec(tvpll->tag, I2C_OP_WRITE_WITH_STOP, tvpll->addr, >pll->initdata[1], tvpll->pll->initdata[0], - NULL, 0, I2C_F_POLL); - iic_release_bus(tvpll->tag, I2C_F_POLL); + NULL, 0, 0); + iic_release_bus(tvpll->tag, 0); } device_printf(parent, "tvpll: %s\n", tvpll->pll->name); @@ -132,15 +132,15 @@ tvpll_tune_dtv(struct tvpll *tvpll, if((rv = tvpll_algo(tvpll, b, params, )) != 0) return rv; - iic_acquire_bus(tvpll->tag, I2C_F_POLL); + iic_acquire_bus(tvpll->tag, 0); /* gate ctrl? */ if (b[4] != TVPLL_IGNORE_AUX) { ab[0] = b[2] | 0x18; ab[1] = b[4]; - rv = iic_exec(tvpll->tag, I2C_OP_WRITE_WITH_STOP, tvpll->addr, ab, 2, NULL, 0, I2C_F_POLL); + rv = iic_exec(tvpll->tag, I2C_OP_WRITE_WITH_STOP, tvpll->addr, ab, 2, NULL, 0, 0); } - rv = iic_exec(tvpll->tag, I2C_OP_WRITE_WITH_STOP, tvpll->addr, b, 4, NULL, 0, I2C_F_POLL); - iic_release_bus(tvpll->tag, I2C_F_POLL); + rv = iic_exec(tvpll->tag, I2C_OP_WRITE_WITH_STOP, tvpll->addr, b, 4, NULL, 0, 0); + iic_release_bus(tvpll->tag, 0); if (rv != 0) printf("%s\n", __func__);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 15:07:42 UTC 2019 Modified Files: src/sys/dev/i2c: titemp.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/titemp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/titemp.c diff -u src/sys/dev/i2c/titemp.c:1.7 src/sys/dev/i2c/titemp.c:1.8 --- src/sys/dev/i2c/titemp.c:1.7 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/titemp.c Mon Dec 23 15:07:42 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: titemp.c,v 1.7 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: titemp.c,v 1.8 2019/12/23 15:07:42 thorpej Exp $ */ /*- * Copyright (c) 2015 Jared D. McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: titemp.c,v 1.7 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: titemp.c,v 1.8 2019/12/23 15:07:42 thorpej Exp $"); #include #include @@ -102,11 +102,11 @@ titemp_match(device_t parent, cfdata_t m if (ia->ia_addr != 0x4c) return 0; - if (iic_acquire_bus(ia->ia_tag, I2C_F_POLL) != 0) + if (iic_acquire_bus(ia->ia_tag, 0) != 0) return 0; error = iic_smbus_read_byte(ia->ia_tag, ia->ia_addr, - TITEMP_MFID_REG, , I2C_F_POLL); - iic_release_bus(ia->ia_tag, I2C_F_POLL); + TITEMP_MFID_REG, , 0); + iic_release_bus(ia->ia_tag, 0); if (error || mfid != TITEMP_MFID_TMP451) return 0;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 15:05:32 UTC 2019 Modified Files: src/sys/dev/i2c: tda19988.c Log Message: No need to check 'cold' for I2C_F_POLL; the i2c code does it for us. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 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.3 src/sys/dev/i2c/tda19988.c:1.4 --- src/sys/dev/i2c/tda19988.c:1.3 Mon Nov 4 10:02:39 2019 +++ src/sys/dev/i2c/tda19988.c Mon Dec 23 15:05:32 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: tda19988.c,v 1.3 2019/11/04 10:02:39 jmcneill Exp $ */ +/* $NetBSD: tda19988.c,v 1.4 2019/12/23 15:05:32 thorpej Exp $ */ /*- * Copyright (c) 2015 Oleksandr Tymoshenko @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tda19988.c,v 1.3 2019/11/04 10:02:39 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tda19988.c,v 1.4 2019/12/23 15:05:32 thorpej Exp $"); /* * NXP TDA19988 HDMI encoder @@ -283,8 +283,7 @@ 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, - cold ? I2C_F_POLL : 0); + result = iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, buf, 2, NULL, 0, 0); if (result == 0) sc->sc_current_page = page; @@ -294,8 +293,7 @@ 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, , 1, data, 1, - cold ? I2C_F_POLL : 0); + return iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_cec_addr, , 1, data, 1, 0); } static int @@ -303,8 +301,7 @@ 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, - cold ? I2C_F_POLL : 0); + return iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_cec_addr, buf, 2, NULL, 0, 0); } static int @@ -317,8 +314,7 @@ tda19988_block_read(struct tda19988_soft 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, len, - cold ? I2C_F_POLL : 0); + return iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr, , 1, data, len, 0); } static int @@ -331,8 +327,7 @@ 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, - cold ? I2C_F_POLL : 0); + return iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr, , 1, data, 1, 0); } static int @@ -343,8 +338,7 @@ 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, - cold ? I2C_F_POLL : 0); + return iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, buf, 2, NULL, 0, 0); } static int @@ -359,8 +353,7 @@ 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, - cold ? I2C_F_POLL : 0); + return iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr, buf, 3, NULL, 0, 0); } static void @@ -698,9 +691,9 @@ tda19988_connector_detect(struct drm_con enum drm_connector_status status; uint8_t data = 0; - iic_acquire_bus(sc->sc_i2c, cold ? I2C_F_POLL : 0); + iic_acquire_bus(sc->sc_i2c, 0); tda19988_cec_read(sc, TDA_CEC_RXSHPDLEV, ); - iic_release_bus(sc->sc_i2c, cold ? I2C_F_POLL : 0); + iic_release_bus(sc->sc_i2c, 0); status = (data & RXSHPDLEV_HPD) ? connector_status_connected : @@ -741,10 +734,10 @@ tda19988_connector_get_modes(struct drm_ if (sc->sc_edid_valid) { pedid = (struct edid *)sc->sc_edid; } else { - iic_acquire_bus(sc->sc_i2c, cold ? I2C_F_POLL : 0); + iic_acquire_bus(sc->sc_i2c, 0); if (tda19988_read_edid(sc) == 0) pedid = (struct edid *)sc->sc_edid; - iic_release_bus(sc->sc_i2c, cold ? I2C_F_POLL : 0); + iic_release_bus(sc->sc_i2c, 0); sc->sc_edid_valid = true; } @@ -838,9 +831,9 @@ tda19988_bridge_mode_set(struct drm_brid { struct tda19988_softc * const sc = bridge->driver_private; - iic_acquire_bus(sc->sc_i2c, cold ? I2C_F_POLL : 0); + iic_acquire_bus(sc->sc_i2c, 0); tda19988_init_encoder(sc, adjusted_mode); - iic_release_bus(sc->sc_i2c, cold ? I2C_F_POLL : 0); + iic_release_bus(sc->sc_i2c, 0); } static bool @@ -927,9 +920,9 @@ tda19988_attach(device_t parent, device_ aprint_naive("\n"); aprint_normal(": NXP TDA19988 HDMI transmitter\n"); -
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 14:55:22 UTC 2019 Modified Files: src/sys/dev/i2c: spdmem_i2c.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 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.17 src/sys/dev/i2c/spdmem_i2c.c:1.18 --- src/sys/dev/i2c/spdmem_i2c.c:1.17 Sat Oct 20 03:23:05 2018 +++ src/sys/dev/i2c/spdmem_i2c.c Mon Dec 23 14:55:22 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: spdmem_i2c.c,v 1.17 2018/10/20 03:23:05 macallan Exp $ */ +/* $NetBSD: spdmem_i2c.c,v 1.18 2019/12/23 14:55:22 thorpej Exp $ */ /* * Copyright (c) 2007 Nicolas Joly @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.17 2018/10/20 03:23:05 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.18 2019/12/23 14:55:22 thorpej Exp $"); #include #include @@ -114,9 +114,9 @@ spdmem_reset_page(struct spdmem_i2c_soft * doesn't exist at the address. */ rv = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, , 1, - , 1, I2C_F_POLL); + , 1, 0); rv |= iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, , 1, - , 1, I2C_F_POLL); + , 1, 0); if (rv != 0) goto error; @@ -143,7 +143,7 @@ spdmem_reset_page(struct spdmem_i2c_soft * I don't know whether our icc_exec()'s API is good or not. */ rv = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_page0, - , 1, , 1, I2C_F_POLL); + , 1, , 1, 0); if (rv != 0) { /* * The possibilities are: @@ -153,7 +153,7 @@ spdmem_reset_page(struct spdmem_i2c_soft * Is there no way to distinguish them now? */ rv = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, - sc->sc_page0, , 1, , 1, I2C_F_POLL); + sc->sc_page0, , 1, , 1, 0); if (rv == 0) { aprint_debug("Page 1 was selected. Page 0 is " "selected now.\n"); @@ -269,14 +269,14 @@ spdmem_i2c_read(struct spdmem_softc *sof if (addr & 0x100) { rv = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_page1, - , 1, , 1, I2C_F_POLL); + , 1, , 1, 0); rv |= iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, - , 1, val, 1, I2C_F_POLL); + , 1, val, 1, 0); rv |= iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, - sc->sc_page0, , 1, , 1, I2C_F_POLL); + sc->sc_page0, , 1, , 1, 0); } else { rv = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, - , 1, val, 1, I2C_F_POLL); + , 1, val, 1, 0); } iic_release_bus(sc->sc_tag, 0);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 14:50:44 UTC 2019 Modified Files: src/sys/dev/i2c: mpl115a.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/mpl115a.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/mpl115a.c diff -u src/sys/dev/i2c/mpl115a.c:1.2 src/sys/dev/i2c/mpl115a.c:1.3 --- src/sys/dev/i2c/mpl115a.c:1.2 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/mpl115a.c Mon Dec 23 14:50:43 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: mpl115a.c,v 1.2 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: mpl115a.c,v 1.3 2019/12/23 14:50:43 thorpej Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mpl115a.c,v 1.2 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mpl115a.c,v 1.3 2019/12/23 14:50:43 thorpej Exp $"); #include #include @@ -154,16 +154,16 @@ mpl115a_load_coeffs(struct mpl115a_softc static void mpl115a_reg_write_1(struct mpl115a_softc *sc, uint8_t reg, uint8_t val) { - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL) != 0) { + if (iic_acquire_bus(sc->sc_tag, 0) != 0) { aprint_error_dev(sc->sc_dev, "cannot acquire bus for write\n"); return; } if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, , 1, - , 1, I2C_F_POLL)) { + , 1, 0)) { aprint_error_dev(sc->sc_dev, "cannot execute write\n"); } - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); } static uint8_t @@ -171,7 +171,7 @@ mpl115a_reg_read_1(struct mpl115a_softc { uint8_t rv, wbuf[2]; - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL) != 0) { + if (iic_acquire_bus(sc->sc_tag, 0) != 0) { #ifdef MPL115A_DEBUG aprint_error_dev(sc->sc_dev, "cannot acquire bus for read\n"); #endif /* MPL115A_DEBUG */ @@ -181,12 +181,12 @@ mpl115a_reg_read_1(struct mpl115a_softc wbuf[0] = reg; if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, wbuf, - 1, , 1, I2C_F_POLL)) { + 1, , 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "cannot execute read\n"); - iic_release_bus(sc->sc_tag, I2C_F_POLL); return 0; } - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); return rv; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 14:48:58 UTC 2019 Modified Files: src/sys/dev/i2c: mcp980x.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/mcp980x.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/mcp980x.c diff -u src/sys/dev/i2c/mcp980x.c:1.6 src/sys/dev/i2c/mcp980x.c:1.7 --- src/sys/dev/i2c/mcp980x.c:1.6 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/mcp980x.c Mon Dec 23 14:48:58 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: mcp980x.c,v 1.6 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: mcp980x.c,v 1.7 2019/12/23 14:48:58 thorpej Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mcp980x.c,v 1.6 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mcp980x.c,v 1.7 2019/12/23 14:48:58 thorpej Exp $"); #include #include @@ -143,18 +143,18 @@ mcp980x_reg_read_2(struct mcp980x_softc { uint16_t rv; - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL) != 0) { + if (iic_acquire_bus(sc->sc_tag, 0) != 0) { aprint_error_dev(sc->sc_dev, "cannot acquire bus for read\n"); return 0; } if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, , - 1, , 2, I2C_F_POLL)) { + 1, , 2, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "cannot execute operation\n"); - iic_release_bus(sc->sc_tag, I2C_F_POLL); return 0; } - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); return be16toh(rv); } @@ -164,18 +164,18 @@ mcp980x_reg_read_1(struct mcp980x_softc { uint8_t rv; - if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL) != 0) { + if (iic_acquire_bus(sc->sc_tag, 0) != 0) { aprint_error_dev(sc->sc_dev, "cannot acquire bus for read\n"); return 0; } if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, , - 1, , 1, I2C_F_POLL)) { + 1, , 1, 0)) { + iic_release_bus(sc->sc_tag, 0); aprint_error_dev(sc->sc_dev, "cannot execute operation\n"); - iic_release_bus(sc->sc_tag, I2C_F_POLL); return 0; } - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); return rv; } @@ -187,34 +187,34 @@ mcp980x_reg_write_2(struct mcp980x_softc beval = htobe16(val); -if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL) != 0) { +if (iic_acquire_bus(sc->sc_tag, 0) != 0) { aprint_error_dev(sc->sc_dev, "cannot acquire bus for write\n"); return; } if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, , - 1, , 2, I2C_F_POLL)) { + 1, , 2, 0)) { aprint_error_dev(sc->sc_dev, "cannot execute operation\n"); } - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); } static void mcp980x_reg_write_1(struct mcp980x_softc *sc, uint8_t reg, uint8_t val) { -if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL) != 0) { +if (iic_acquire_bus(sc->sc_tag, 0) != 0) { aprint_error_dev(sc->sc_dev, "cannot acquire bus for write\n"); return; } if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, , - 1, , 1, I2C_F_POLL)) { + 1, , 1, 0)) { aprint_error_dev(sc->sc_dev, "cannot execute operation\n"); } - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 14:43:03 UTC 2019 Modified Files: src/sys/dev/i2c: lm87.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 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.10 src/sys/dev/i2c/lm87.c:1.11 --- src/sys/dev/i2c/lm87.c:1.10 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/lm87.c Mon Dec 23 14:43:03 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: lm87.c,v 1.10 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: lm87.c,v 1.11 2019/12/23 14:43:03 thorpej 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.10 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm87.c,v 1.11 2019/12/23 14:43:03 thorpej Exp $"); #include #include @@ -164,7 +164,7 @@ lmenv_match(device_t parent, cfdata_t ma cmd = LM87_COMPANY_ID; iic_acquire_bus(ia->ia_tag, 0); error = iic_exec(ia->ia_tag, I2C_OP_READ_WITH_STOP, ia->ia_addr, - , 1, , 1, I2C_F_POLL); + , 1, , 1, 0); iic_release_bus(ia->ia_tag, 0); if (error)
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 14:41:41 UTC 2019 Modified Files: src/sys/dev/i2c: lm75.c Log Message: No need to use I2C_F_POLL here. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/sys/dev/i2c/lm75.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/lm75.c diff -u src/sys/dev/i2c/lm75.c:1.34 src/sys/dev/i2c/lm75.c:1.35 --- src/sys/dev/i2c/lm75.c:1.34 Wed Feb 20 18:19:46 2019 +++ src/sys/dev/i2c/lm75.c Mon Dec 23 14:41:41 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: lm75.c,v 1.34 2019/02/20 18:19:46 macallan Exp $ */ +/* $NetBSD: lm75.c,v 1.35 2019/12/23 14:41:41 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.34 2019/02/20 18:19:46 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.35 2019/12/23 14:41:41 thorpej Exp $"); #include #include @@ -206,7 +206,7 @@ lmtemp_attach(device_t parent, device_t sc->sc_lmtemp_decode = lmtemptbl[i].lmtemp_decode; sc->sc_lmtemp_encode = lmtemptbl[i].lmtemp_encode; - iic_acquire_bus(sc->sc_tag, I2C_F_POLL); + iic_acquire_bus(sc->sc_tag, 0); /* Read temperature limit(s) and remember initial value(s). */ if (i == lmtemp_lm77) { @@ -214,28 +214,28 @@ lmtemp_attach(device_t parent, device_t >sc_scrit, 1) != 0) { aprint_error_dev(self, "unable to read low register\n"); - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); return; } if (lmtemp_temp_read(sc, LM77_REG_TLOW_SET_POINT, >sc_smin, 1) != 0) { aprint_error_dev(self, "unable to read low register\n"); - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); return; } if (lmtemp_temp_read(sc, LM77_REG_THIGH_SET_POINT, >sc_smax, 1) != 0) { aprint_error_dev(self, "unable to read high register\n"); - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); return; } } else { /* LM75 or compatible */ if (lmtemp_temp_read(sc, LM75_REG_TOS_SET_POINT, >sc_smax, 1) != 0) { aprint_error_dev(self, "unable to read Tos register\n"); - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); return; } } @@ -247,10 +247,10 @@ lmtemp_attach(device_t parent, device_t /* Set the configuration of the LM75 to defaults. */ if (lmtemp_config_write(sc, LM75_CONFIG_FAULT_QUEUE_4) != 0) { aprint_error_dev(self, "unable to write config register\n"); - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); return; } - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); sc->sc_sme = sysmon_envsys_create(); /* Initialize sensor data. */ @@ -297,7 +297,7 @@ lmtemp_config_write(struct lmtemp_softc cmdbuf[1] = val; return iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, - sc->sc_address, cmdbuf, 1, [1], 1, I2C_F_POLL); + sc->sc_address, cmdbuf, 1, [1], 1, 0); } static int @@ -309,7 +309,7 @@ lmtemp_temp_write(struct lmtemp_softc *s sc->sc_lmtemp_encode(val, [1], degc); return iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, - sc->sc_address, cmdbuf, 1, [1], 2, I2C_F_POLL); + sc->sc_address, cmdbuf, 1, [1], 2, 0); } static int @@ -596,12 +596,12 @@ sysctl_lm75_temp(SYSCTLFN_ARGS) temp = *(int *)node.sysctl_data; sc->sc_tmax = temp; - iic_acquire_bus(sc->sc_tag, I2C_F_POLL); + iic_acquire_bus(sc->sc_tag, 0); lmtemp_temp_write(sc, LM75_REG_THYST_SET_POINT, sc->sc_tmax - 5, 1); lmtemp_temp_write(sc, LM75_REG_TOS_SET_POINT, sc->sc_tmax, 1); - iic_release_bus(sc->sc_tag, I2C_F_POLL); + iic_release_bus(sc->sc_tag, 0); /* Synchronise envsys - calls lmtemp_getlim_lm75() */ sysmon_envsys_update_limits(sc->sc_sme, >sc_sensor);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 14:34:23 UTC 2019 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: In axppmic_power_poweroff(), check for errors from iic_acquire_bus() before proceeding with writing to the device. To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 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.27 src/sys/dev/i2c/axppmic.c:1.28 --- src/sys/dev/i2c/axppmic.c:1.27 Mon Dec 23 02:57:32 2019 +++ src/sys/dev/i2c/axppmic.c Mon Dec 23 14:34:23 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.27 2019/12/23 02:57:32 thorpej Exp $ */ +/* $NetBSD: axppmic.c,v 1.28 2019/12/23 14:34:23 thorpej Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.27 2019/12/23 02:57:32 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.28 2019/12/23 14:34:23 thorpej Exp $"); #include #include @@ -557,12 +557,20 @@ static void axppmic_power_poweroff(device_t dev) { struct axppmic_softc *sc = device_private(dev); + int error; delay(100); - iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); - axppmic_write(sc->sc_i2c, sc->sc_addr, AXP_POWER_DISABLE_REG, AXP_POWER_DISABLE_CTRL, I2C_F_POLL); - iic_release_bus(sc->sc_i2c, I2C_F_POLL); + error = iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); + if (error == 0) { + error = axppmic_write(sc->sc_i2c, sc->sc_addr, + AXP_POWER_DISABLE_REG, AXP_POWER_DISABLE_CTRL, I2C_F_POLL); + iic_release_bus(sc->sc_i2c, I2C_F_POLL); + } + if (error) { + device_printf(dev, "WARNING: unable to power off, error %d\n", + error); + } } static struct fdtbus_power_controller_func axppmic_power_funcs = {
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 14:26:19 UTC 2019 Modified Files: src/sys/dev/i2c: i2c_exec.c Log Message: Disable the not-in-interrupt assertions for now; more work needs to be done in several i2c client drivers. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sys/dev/i2c/i2c_exec.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/i2c_exec.c diff -u src/sys/dev/i2c/i2c_exec.c:1.13 src/sys/dev/i2c/i2c_exec.c:1.14 --- src/sys/dev/i2c/i2c_exec.c:1.13 Sun Dec 22 23:23:32 2019 +++ src/sys/dev/i2c/i2c_exec.c Mon Dec 23 14:26:19 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c_exec.c,v 1.13 2019/12/22 23:23:32 thorpej Exp $ */ +/* $NetBSD: i2c_exec.c,v 1.14 2019/12/23 14:26:19 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: i2c_exec.c,v 1.13 2019/12/22 23:23:32 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c_exec.c,v 1.14 2019/12/23 14:26:19 thorpej Exp $"); #include #include @@ -98,7 +98,9 @@ int iic_acquire_bus(i2c_tag_t tag, int flags) { +#if 0 /* XXX Not quite ready for this yet. */ KASSERT(!cpu_intr_p()); +#endif flags = iic_op_flags(flags); @@ -151,7 +153,9 @@ void iic_release_bus(i2c_tag_t tag, int flags) { +#if 0 /* XXX Not quite ready for this yet. */ KASSERT(!cpu_intr_p()); +#endif flags = iic_op_flags(flags); @@ -181,7 +185,9 @@ iic_exec(i2c_tag_t tag, i2c_op_t op, i2c int error; size_t len; +#if 0 /* XXX Not quite ready for this yet. */ KASSERT(!cpu_intr_p()); +#endif flags = iic_op_flags(flags);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 02:57:32 UTC 2019 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: No need to do the poll-during-autoconfiguration dance; the i2c code does the right thing for us. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 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.26 src/sys/dev/i2c/axppmic.c:1.27 --- src/sys/dev/i2c/axppmic.c:1.26 Tue Oct 1 23:32:52 2019 +++ src/sys/dev/i2c/axppmic.c Mon Dec 23 02:57:32 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.26 2019/10/01 23:32:52 jmcneill Exp $ */ +/* $NetBSD: axppmic.c,v 1.27 2019/12/23 02:57:32 thorpej Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.26 2019/10/01 23:32:52 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.27 2019/12/23 02:57:32 thorpej Exp $"); #include #include @@ -779,12 +779,12 @@ axppmic_attach_battery(struct axppmic_so envsys_data_t *e; uint8_t val; - iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); + iic_acquire_bus(sc->sc_i2c, 0); if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATT_CAP_WARN_REG, , I2C_F_POLL) == 0) { sc->sc_warn_thres = __SHIFTOUT(val, AXP_BATT_CAP_WARN_LV1) + 5; sc->sc_shut_thres = __SHIFTOUT(val, AXP_BATT_CAP_WARN_LV2); } - iic_release_bus(sc->sc_i2c, I2C_F_POLL); + iic_release_bus(sc->sc_i2c, 0); e = >sc_sensor[AXP_SENSOR_BATT_PRESENT]; e->private = AXP_SENSOR_BATT_PRESENT; @@ -928,15 +928,15 @@ axppmic_attach(device_t parent, device_t const bool master_mode = of_hasprop(sc->sc_phandle, "x-powers,self-working-mode") || of_hasprop(sc->sc_phandle, "x-powers,master-mode"); - iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); + iic_acquire_bus(sc->sc_i2c, 0); axppmic_write(sc->sc_i2c, sc->sc_addr, AXP_ADDR_EXT_REG, - master_mode ? AXP_ADDR_EXT_MASTER : AXP_ADDR_EXT_SLAVE, I2C_F_POLL); - iic_release_bus(sc->sc_i2c, I2C_F_POLL); + master_mode ? AXP_ADDR_EXT_MASTER : AXP_ADDR_EXT_SLAVE, 0); + iic_release_bus(sc->sc_i2c, 0); } - iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); - error = axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_CHIP_ID_REG, , I2C_F_POLL); - iic_release_bus(sc->sc_i2c, I2C_F_POLL); + iic_acquire_bus(sc->sc_i2c, 0); + error = axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_CHIP_ID_REG, , 0); + iic_release_bus(sc->sc_i2c, 0); if (error != 0) { aprint_error_dev(self, "couldn't read chipid\n"); return; @@ -948,7 +948,7 @@ axppmic_attach(device_t parent, device_t sysmon_pswitch_register(>sc_smpsw); if (c->irq_regs > 0) { - iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); + iic_acquire_bus(sc->sc_i2c, 0); for (i = 1; i <= c->irq_regs; i++) { irq_mask = 0; if (i == c->poklirq.reg) @@ -963,9 +963,9 @@ axppmic_attach(device_t parent, device_t irq_mask |= c->chargeirq.mask; if (i == c->chargestirq.reg) irq_mask |= c->chargestirq.mask; - axppmic_write(sc->sc_i2c, sc->sc_addr, AXP_IRQ_ENABLE_REG(i), irq_mask, I2C_F_POLL); + axppmic_write(sc->sc_i2c, sc->sc_addr, AXP_IRQ_ENABLE_REG(i), irq_mask, 0); } - iic_release_bus(sc->sc_i2c, I2C_F_POLL); + iic_release_bus(sc->sc_i2c, 0); ih = fdtbus_intr_establish(sc->sc_phandle, 0, IPL_VM, FDT_INTR_MPSAFE, axppmic_intr, sc);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 02:50:50 UTC 2019 Modified Files: src/sys/dev/i2c: axp20x.c Log Message: No need to do the poll-during-autoconfiguration dance; the i2c code does the right thing for us. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sys/dev/i2c/axp20x.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/axp20x.c diff -u src/sys/dev/i2c/axp20x.c:1.13 src/sys/dev/i2c/axp20x.c:1.14 --- src/sys/dev/i2c/axp20x.c:1.13 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/axp20x.c Mon Dec 23 02:50:50 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: axp20x.c,v 1.13 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: axp20x.c,v 1.14 2019/12/23 02:50:50 thorpej Exp $ */ /*- * Copyright (c) 2014-2017 Jared McNeill @@ -29,7 +29,7 @@ #include "opt_fdt.h" #include -__KERNEL_RCSID(0, "$NetBSD: axp20x.c,v 1.13 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axp20x.c,v 1.14 2019/12/23 02:50:50 thorpej Exp $"); #include #include @@ -248,13 +248,13 @@ axp20x_attach(device_t parent, device_t sc->sc_phandle = ia->ia_cookie; error = axp20x_read(sc, AXP_INPUT_STATUS, - >sc_inputstatus, 1, I2C_F_POLL); + >sc_inputstatus, 1, 0); if (error) { aprint_error(": can't read status: %d\n", error); return; } error = axp20x_read(sc, AXP_POWER_MODE, - >sc_powermode, 1, I2C_F_POLL); + >sc_powermode, 1, 0); if (error) { aprint_error(": can't read power mode: %d\n", error); return; @@ -262,18 +262,18 @@ axp20x_attach(device_t parent, device_t value = AXP_ADC_EN1_ACV | AXP_ADC_EN1_ACI | AXP_ADC_EN1_VBUSV | AXP_ADC_EN1_VBUSI | AXP_ADC_EN1_APSV | AXP_ADC_EN1_TS; if (sc->sc_powermode & AXP_POWER_MODE_BATTOK) value |= AXP_ADC_EN1_BATTV | AXP_ADC_EN1_BATTI; - error = axp20x_write(sc, AXP_ADC_EN1, , 1, I2C_F_POLL); + error = axp20x_write(sc, AXP_ADC_EN1, , 1, 0); if (error) { aprint_error(": can't set AXP_ADC_EN1\n"); return; } - error = axp20x_read(sc, AXP_ADC_EN2, , 1, I2C_F_POLL); + error = axp20x_read(sc, AXP_ADC_EN2, , 1, 0); if (error) { aprint_error(": can't read AXP_ADC_EN2\n"); return; } value |= AXP_ADC_EN2_TEMP; - error = axp20x_write(sc, AXP_ADC_EN2, , 1, I2C_F_POLL); + error = axp20x_write(sc, AXP_ADC_EN2, , 1, 0); if (error) { aprint_error(": can't set AXP_ADC_EN2\n"); return; @@ -381,22 +381,22 @@ axp20x_attach(device_t parent, device_t sysmon_envsys_register(sc->sc_sme); - if (axp20x_read(sc, AXP_DCDC2, , 1, I2C_F_POLL) == 0) { + if (axp20x_read(sc, AXP_DCDC2, , 1, 0) == 0) { aprint_verbose_dev(sc->sc_dev, "DCDC2 %dmV\n", (int)(700 + (value & AXP_DCDC2_VOLT_MASK) * 25)); } - if (axp20x_read(sc, AXP_DCDC3, , 1, I2C_F_POLL) == 0) { + if (axp20x_read(sc, AXP_DCDC3, , 1, 0) == 0) { aprint_verbose_dev(sc->sc_dev, "DCDC3 %dmV\n", (int)(700 + (value & AXP_DCDC3_VOLT_MASK) * 25)); } - if (axp20x_read(sc, AXP_LDO2_4, , 1, I2C_F_POLL) == 0) { + if (axp20x_read(sc, AXP_LDO2_4, , 1, 0) == 0) { aprint_verbose_dev(sc->sc_dev, "LDO2 %dmV, LDO4 %dmV\n", (int)(1800 + ((value & AXP_LDO2_VOLT_MASK) >> AXP_LDO2_VOLT_SHIFT) * 100 ), ldo4_mvV[(value & AXP_LDO4_VOLT_MASK) >> AXP_LDO4_VOLT_SHIFT]); } - if (axp20x_read(sc, AXP_LDO3, , 1, I2C_F_POLL) == 0) { + if (axp20x_read(sc, AXP_LDO3, , 1, 0) == 0) { if (value & AXP_LDO3_TRACK) { aprint_verbose_dev(sc->sc_dev, "LDO3: tracking\n"); } else { @@ -405,7 +405,7 @@ axp20x_attach(device_t parent, device_t } } - if (axp20x_read(sc, AXP_BKUP_CTRL, , 1, I2C_F_POLL) == 0) { + if (axp20x_read(sc, AXP_BKUP_CTRL, , 1, 0) == 0) { if (value & AXP_BKUP_CTRL_ENABLE) { aprint_verbose_dev(sc->sc_dev, "RTC supercap charger enabled: %dmV at %duA\n",
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 02:39:47 UTC 2019 Modified Files: src/sys/dev/i2c: at24cxx.c Log Message: seeprom_bootstrap_read(): no need to hard-code I2C_F_POLL here because the i2c code will ensure it's there if the system is cold. To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 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.33 src/sys/dev/i2c/at24cxx.c:1.34 --- src/sys/dev/i2c/at24cxx.c:1.33 Fri Nov 29 04:59:15 2019 +++ src/sys/dev/i2c/at24cxx.c Mon Dec 23 02:39:47 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: at24cxx.c,v 1.33 2019/11/29 04:59:15 hkenken Exp $ */ +/* $NetBSD: at24cxx.c,v 1.34 2019/12/23 02:39:47 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.33 2019/11/29 04:59:15 hkenken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.34 2019/12/23 02:39:47 thorpej Exp $"); #include #include @@ -416,7 +416,7 @@ seeprom_bootstrap_read(i2c_tag_t tag, in /* We are very forgiving about devsize during bootstrap. */ cmdlen = (devsize >= 4096) ? 2 : 1; - if (iic_acquire_bus(tag, I2C_F_POLL) != 0) + if (iic_acquire_bus(tag, 0) != 0) return (-1); while (len) { @@ -432,7 +432,7 @@ seeprom_bootstrap_read(i2c_tag_t tag, in /* Read a single byte. */ if (iic_exec(tag, I2C_OP_READ_WITH_STOP, addr, cmdbuf, cmdlen, rvp, 1, I2C_F_POLL)) { - iic_release_bus(tag, I2C_F_POLL); + iic_release_bus(tag, 0); return (-1); } @@ -441,6 +441,6 @@ seeprom_bootstrap_read(i2c_tag_t tag, in offset++; } - iic_release_bus(tag, I2C_F_POLL); + iic_release_bus(tag, 0); return (0); }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 02:35:18 UTC 2019 Modified Files: src/sys/dev/i2c: as3722.c Log Message: No need to do the poll-during-autoconfiguration dance; the i2c code does the right thing for us. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sys/dev/i2c/as3722.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/as3722.c diff -u src/sys/dev/i2c/as3722.c:1.16 src/sys/dev/i2c/as3722.c:1.17 --- src/sys/dev/i2c/as3722.c:1.16 Sat Jul 27 16:02:27 2019 +++ src/sys/dev/i2c/as3722.c Mon Dec 23 02:35:18 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: as3722.c,v 1.16 2019/07/27 16:02:27 thorpej Exp $ */ +/* $NetBSD: as3722.c,v 1.17 2019/12/23 02:35:18 thorpej Exp $ */ /*- * Copyright (c) 2015 Jared D. McNeill @@ -29,7 +29,7 @@ #include "opt_fdt.h" #include -__KERNEL_RCSID(0, "$NetBSD: as3722.c,v 1.16 2019/07/27 16:02:27 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: as3722.c,v 1.17 2019/12/23 02:35:18 thorpej Exp $"); #include #include @@ -240,11 +240,11 @@ as3722_match(device_t parent, cfdata_t m if (ia->ia_addr != AS3722_I2C_ADDR) return 0; - iic_acquire_bus(ia->ia_tag, I2C_F_POLL); + iic_acquire_bus(ia->ia_tag, 0); reg = AS3722_ASIC_ID1_REG; error = iic_exec(ia->ia_tag, I2C_OP_READ_WITH_STOP, ia->ia_addr, - , 1, , 1, I2C_F_POLL); - iic_release_bus(ia->ia_tag, I2C_F_POLL); + , 1, , 1, 0); + iic_release_bus(ia->ia_tag, 0); if (error == 0 && id1 == 0x0c) return I2C_MATCH_ADDRESS_AND_PROBE; @@ -281,16 +281,16 @@ as3722_wdt_attach(struct as3722_softc *s { int error; - iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); + iic_acquire_bus(sc->sc_i2c, 0); error = as3722_write(sc, AS3722_GPIO0_CTRL_REG, __SHIFTIN(AS3722_GPIO0_CTRL_IOSF_GPIO, AS3722_GPIO0_CTRL_IOSF) | __SHIFTIN(AS3722_GPIO0_CTRL_MODE_PULLDOWN, AS3722_GPIO0_CTRL_MODE), - I2C_F_POLL); + 0); error += as3722_set_clear(sc, AS3722_WATCHDOG_CTRL_REG, - __SHIFTIN(1, AS3722_WATCHDOG_CTRL_MODE), 0, I2C_F_POLL); - iic_release_bus(sc->sc_i2c, I2C_F_POLL); + __SHIFTIN(1, AS3722_WATCHDOG_CTRL_MODE), 0, 0); + iic_release_bus(sc->sc_i2c, 0); if (error) { aprint_error_dev(sc->sc_dev, "couldn't setup watchdog\n"); @@ -315,10 +315,10 @@ as3722_rtc_attach(struct as3722_softc *s { int error; - iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); + iic_acquire_bus(sc->sc_i2c, 0); error = as3722_set_clear(sc, AS3722_RTC_CONTROL_REG, - AS3722_RTC_CONTROL_RTC_ON, 0, I2C_F_POLL); - iic_release_bus(sc->sc_i2c, I2C_F_POLL); + AS3722_RTC_CONTROL_RTC_ON, 0, 0); + iic_release_bus(sc->sc_i2c, 0); if (error) { aprint_error_dev(sc->sc_dev, "couldn't setup RTC\n");
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 23 02:25:28 UTC 2019 Modified Files: src/sys/dev/i2c: adm1026.c Log Message: No need to do the poll-during-autoconfiguration dance; the i2c code does the right thing for us. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/adm1026.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/adm1026.c diff -u src/sys/dev/i2c/adm1026.c:1.6 src/sys/dev/i2c/adm1026.c:1.7 --- src/sys/dev/i2c/adm1026.c:1.6 Wed Dec 11 21:00:11 2019 +++ src/sys/dev/i2c/adm1026.c Mon Dec 23 02:25:28 2019 @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: adm1026.c,v 1.6 2019/12/11 21:00:11 jdc Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adm1026.c,v 1.7 2019/12/23 02:25:28 thorpej Exp $"); #include #include @@ -87,7 +87,6 @@ struct adm1026_softc { device_t sc_dev; i2c_tag_t sc_tag; int sc_address; - int sc_iic_flags; bool sc_multi_read; uint8_t sc_rev, sc_cfg[2]; @@ -136,7 +135,6 @@ adm1026_match(device_t parent, cfdata_t sc.sc_tag = ia->ia_tag; sc.sc_address = ia->ia_addr; - sc.sc_iic_flags = 0; if (iic_use_direct_match(ia, cf, compat_data, _result)) return match_result; @@ -183,7 +181,6 @@ adm1026_attach(device_t parent, device_t sc->sc_tag = ia->ia_tag; sc->sc_address = ia->ia_addr; sc->sc_dev = self; - sc->sc_iic_flags = I2C_F_POLL; /* Use polling during autoconf */ sc->sc_multi_read = false; prop_dictionary_get_bool(props, "multi_read", >sc_multi_read); @@ -239,8 +236,6 @@ adm1026_attach(device_t parent, device_t if (!pmf_device_register(self, adm1026_pmf_suspend, adm1026_pmf_resume)) aprint_error_dev(self, "couldn't establish power handler\n"); - sc->sc_iic_flags = 0; /* Drop polling flag */ - return; } @@ -493,7 +488,7 @@ adm1026_read_reg(struct adm1026_softc *s int i, j, err = 0; uint8_t creg, cval, tmp[ADM1026_READ_RETRIES + 1]; - if ((err = iic_acquire_bus(sc->sc_tag, sc->sc_iic_flags)) != 0) + if ((err = iic_acquire_bus(sc->sc_tag, 0)) != 0) return err; /* Standard ADM1026 */ if (sc->sc_multi_read == false) { @@ -512,7 +507,7 @@ adm1026_read_reg(struct adm1026_softc *s creg = ADM1026_CONF1; if ((err = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, , 1, [0], 1, 0)) != 0) { - iic_release_bus(sc->sc_tag, sc->sc_iic_flags); + iic_release_bus(sc->sc_tag, 0); return err; } for (i = 1; i <= ADM1026_READ_RETRIES; i++) { @@ -522,8 +517,7 @@ adm1026_read_reg(struct adm1026_softc *s for (j = 0; j < i; j++) if (abs(tmp[j] - tmp[i]) < 3) { *val = tmp[i]; - iic_release_bus(sc->sc_tag, - sc->sc_iic_flags); + iic_release_bus(sc->sc_tag, 0); return 0; } if ((err = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, @@ -532,7 +526,7 @@ adm1026_read_reg(struct adm1026_softc *s err = -1; /* Return error if we don't match. */ } } - iic_release_bus(sc->sc_tag, sc->sc_iic_flags); + iic_release_bus(sc->sc_tag, 0); return err; } @@ -541,10 +535,10 @@ adm1026_write_reg(struct adm1026_softc * { int err = 0; - if ((err = iic_acquire_bus(sc->sc_tag, sc->sc_iic_flags)) != 0) + if ((err = iic_acquire_bus(sc->sc_tag, 0)) != 0) return err; err = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_address, , 1, , 1, 0); - iic_release_bus(sc->sc_tag, sc->sc_iic_flags); + iic_release_bus(sc->sc_tag, 0); return err; }
CVS commit: src/sys/dev/i2c
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. 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_intr_lock); -#if NACPICA > 0 - if (sc->sc_ih != NULL) - acpi_intr_disestablish(sc->sc_ih); -#endif + ihiddev_intr_fini(sc); if (ihidev_hid_command(sc, I2C_HID_CMD_SET_POWER, _HID_POWER_OFF, true)) aprint_error_dev(sc->sc_dev, "failed to power down\n"); @@ -649,31 +640,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", , + _resource_parse_ops_quiet); + if (ACPI_FAILURE(rv)) { + aprint_error_dev(sc->sc_dev, "can't parse '_CRS'\n"); + return false; + } + + const struct acpi_irq * const irq = acpi_res_irq(, 0); + if (irq == NULL) { + aprint_error_dev(sc->sc_dev, "no IRQ resource\n"); + acpi_resource_cleanup(); + return false; + } + + sc->sc_intr_type = + irq->ar_type == ACPI_EDGE_SENSITIVE ? IST_EDGE : IST_LEVEL; + + acpi_resource_cleanup(); + + sc->sc_ih = acpi_intr_establish(sc->sc_dev, sc->sc_phandle, IPL_TTY, + false, ihidev_intr, sc, device_xname(sc->sc_dev)); + if (sc->sc_ih == NULL) { + aprint_error_dev(sc->sc_dev, "can't establish interrupt\n"); + return false; + } + aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", + acpi_intr_string(sc->sc_ih, buf, sizeof(buf))); + + sc->sc_sih = softint_establish(SOFTINT_SERIAL, ihidev_softintr, sc); + if (sc->sc_sih == NULL) { + aprint_error_dev(sc->sc_dev, + "can't establish soft interrupt\n"); + return false; + } + + return true; +#else + aprint_error_dev(sc->sc_dev, "can't establish interrupt\n"); + return false; +#endif +} + +static void +ihiddev_intr_fini(struct ihidev_softc *sc) +{ +#if NACPICA > 0 + if (sc->sc_ih != NULL) { +
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jdc Date: Wed Dec 11 21:00:11 UTC 2019 Modified Files: src/sys/dev/i2c: adm1026.c adm1026reg.h Log Message: Chip matching improvements: only match for currently known addresses don't generate messages when matching Tested on Sun Blade 2500 by martin@. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/adm1026.c cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/adm1026reg.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/adm1026.c diff -u src/sys/dev/i2c/adm1026.c:1.5 src/sys/dev/i2c/adm1026.c:1.6 --- src/sys/dev/i2c/adm1026.c:1.5 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/adm1026.c Wed Dec 11 21:00:11 2019 @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: adm1026.c,v 1.5 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adm1026.c,v 1.6 2019/12/11 21:00:11 jdc Exp $"); #include #include @@ -99,11 +99,11 @@ struct adm1026_softc { }; static int adm1026_match(device_t, cfdata_t, void *); -static int adm1026_ident(struct adm1026_softc *sc); +static int adm1026_ident(struct adm1026_softc *, int); static void adm1026_attach(device_t, device_t, void *); static int adm1026_detach(device_t, int); -bool adm1026_pmf_suspend(device_t dev, const pmf_qual_t *qual); -bool adm1026_pmf_resume(device_t dev, const pmf_qual_t *qual); +bool adm1026_pmf_suspend(device_t, const pmf_qual_t *); +bool adm1026_pmf_resume(device_t, const pmf_qual_t *); static void adm1026_setup_fans(struct adm1026_softc *sc, int div2_val); static void adm1026_setup_temps(struct adm1026_softc *sc); @@ -141,15 +141,14 @@ adm1026_match(device_t parent, cfdata_t if (iic_use_direct_match(ia, cf, compat_data, _result)) return match_result; - if ((ia->ia_addr & ADM1026_ADDRMASK) == ADM1026_ADDR && - adm1026_ident()) + if (ia->ia_addr == ADM1026_ADDR1 && adm1026_ident(, 1)) return I2C_MATCH_ADDRESS_AND_PROBE; return 0; } static int -adm1026_ident(struct adm1026_softc *sc) +adm1026_ident(struct adm1026_softc *sc, int probe_only) { uint8_t val; int err; @@ -157,14 +156,16 @@ adm1026_ident(struct adm1026_softc *sc) /* Manufacturer ID and revision/stepping */ err = adm1026_read_reg(sc, ADM1026_ID, ); if (err || val != ADM1026_MANF_ID) { - aprint_verbose("adm1026_ident: " - "manufacturer ID invalid or missing\n"); + if (!probe_only) + aprint_verbose("adm1026_ident: " + "manufacturer ID invalid or missing\n"); return 0; } err = adm1026_read_reg(sc, ADM1026_REV, >sc_rev); if (err || ADM1026_REVISION(sc->sc_rev) != ADM1026_MANF_REV) { - aprint_verbose("adm1026_ident: " - "manufacturer revision invalid or missing\n"); + if (!probe_only) + aprint_verbose("adm1026_ident: " + "manufacturer revision invalid or missing\n"); return 0; } return 1; @@ -191,7 +192,7 @@ adm1026_attach(device_t parent, device_t else div2_val = -1; - (void) adm1026_ident(sc); + (void) adm1026_ident(sc, 0); aprint_normal(": ADM1026 hardware monitor: rev. 0x%x, step. 0x%x\n", ADM1026_REVISION(sc->sc_rev), ADM1026_STEPPING(sc->sc_rev)); Index: src/sys/dev/i2c/adm1026reg.h diff -u src/sys/dev/i2c/adm1026reg.h:1.2 src/sys/dev/i2c/adm1026reg.h:1.3 --- src/sys/dev/i2c/adm1026reg.h:1.2 Sun Oct 13 07:44:51 2019 +++ src/sys/dev/i2c/adm1026reg.h Wed Dec 11 21:00:11 2019 @@ -37,10 +37,9 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: adm1026reg.h,v 1.2 2019/10/13 07:44:51 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: adm1026reg.h,v 1.3 2019/12/11 21:00:11 jdc Exp $"); -#define ADM1026_ADDRMASK 0x2f /* 010 11xx */ -#define ADM1026_ADDR 0x2c +#define ADM1026_ADDR1 0x2c #define ADM1026_CONF1 0x00 #define ADM1026_CONF2 0x01
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Thu Dec 5 06:28:09 UTC 2019 Modified Files: src/sys/dev/i2c: i2c.c Log Message: Revert previous. Indirect matches are not wanted on platforms that use external configuration data (FDT or OF). To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.70 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.69 src/sys/dev/i2c/i2c.c:1.70 --- src/sys/dev/i2c/i2c.c:1.69 Tue Mar 26 09:20:38 2019 +++ src/sys/dev/i2c/i2c.c Thu Dec 5 06:28:09 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.69 2019/03/26 09:20:38 mlelstv Exp $ */ +/* $NetBSD: i2c.c,v 1.70 2019/12/05 06:28:09 mlelstv Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -40,7 +40,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.69 2019/03/26 09:20:38 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.70 2019/12/05 06:28:09 mlelstv Exp $"); #include #include @@ -719,8 +719,6 @@ iic_use_direct_match(const struct i2c_at const struct device_compatible_entry *compats, int *match_resultp) { - int res; - KASSERT(match_resultp != NULL); if (ia->ia_name != NULL && @@ -730,11 +728,8 @@ iic_use_direct_match(const struct i2c_at } if (ia->ia_ncompat > 0 && ia->ia_compat != NULL) { - res = iic_compatible_match(ia, compats, NULL); - if (res) { - *match_resultp = res; - return true; - } + *match_resultp = iic_compatible_match(ia, compats, NULL); + return true; } return false;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Tue Mar 26 09:22:17 UTC 2019 Modified Files: src/sys/dev/i2c: at24cxx.c Log Message: provide compatible names for all sizes. To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 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.30 src/sys/dev/i2c/at24cxx.c:1.31 --- src/sys/dev/i2c/at24cxx.c:1.30 Tue Jun 26 06:34:55 2018 +++ src/sys/dev/i2c/at24cxx.c Tue Mar 26 09:22:17 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: at24cxx.c,v 1.30 2018/06/26 06:34:55 thorpej Exp $ */ +/* $NetBSD: at24cxx.c,v 1.31 2019/03/26 09:22:17 mlelstv Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.30 2018/06/26 06:34:55 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.31 2019/03/26 09:22:17 mlelstv Exp $"); #include #include @@ -112,7 +112,16 @@ const struct cdevsw seeprom_cdevsw = { static int seeprom_wait_idle(struct seeprom_softc *); static const struct device_compatible_entry compat_data[] = { + { "i2c-at24c01", 128 }, + { "i2c-at24c02", 256 }, + { "i2c-at24c04", 512 }, + { "i2c-at24c08", 1024 }, + { "i2c-at24c16", 2048 }, + { "i2c-at24c32", 4096 }, { "i2c-at24c64", 8192 }, + { "i2c-at24c128", 16384 }, + { "i2c-at24c256", 32768 }, + { "i2c-at24c512", 65536 }, { "i2c-at34c02", 256 }, { "atmel,24c02", 256 }, { "atmel,24c16", 2048 },
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mlelstv Date: Tue Mar 26 09:20:38 UTC 2019 Modified Files: src/sys/dev/i2c: i2c.c Log Message: touch match_result only on success. To generate a diff of this commit: cvs rdiff -u -r1.68 -r1.69 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.68 src/sys/dev/i2c/i2c.c:1.69 --- src/sys/dev/i2c/i2c.c:1.68 Sun Jan 27 02:08:41 2019 +++ src/sys/dev/i2c/i2c.c Tue Mar 26 09:20:38 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.68 2019/01/27 02:08:41 pgoyette Exp $ */ +/* $NetBSD: i2c.c,v 1.69 2019/03/26 09:20:38 mlelstv Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -40,7 +40,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.68 2019/01/27 02:08:41 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.69 2019/03/26 09:20:38 mlelstv Exp $"); #include #include @@ -719,6 +719,7 @@ iic_use_direct_match(const struct i2c_at const struct device_compatible_entry *compats, int *match_resultp) { + int res; KASSERT(match_resultp != NULL); @@ -729,8 +730,11 @@ iic_use_direct_match(const struct i2c_at } if (ia->ia_ncompat > 0 && ia->ia_compat != NULL) { - *match_resultp = iic_compatible_match(ia, compats, NULL); - return true; + res = iic_compatible_match(ia, compats, NULL); + if (res) { + *match_resultp = res; + return true; + } } return false;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: tnn Date: Sun Mar 17 01:47:57 UTC 2019 Modified Files: src/sys/dev/i2c: ssdfb_i2c.c Log Message: delete unused variable To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 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.1 src/sys/dev/i2c/ssdfb_i2c.c:1.2 --- src/sys/dev/i2c/ssdfb_i2c.c:1.1 Sun Mar 17 01:03:47 2019 +++ src/sys/dev/i2c/ssdfb_i2c.c Sun Mar 17 01:47:57 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: ssdfb_i2c.c,v 1.1 2019/03/17 01:03:47 tnn Exp $ */ +/* $NetBSD: ssdfb_i2c.c,v 1.2 2019/03/17 01:47:57 tnn Exp $ */ /* * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ssdfb_i2c.c,v 1.1 2019/03/17 01:03:47 tnn Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ssdfb_i2c.c,v 1.2 2019/03/17 01:47:57 tnn Exp $"); #include #include @@ -43,7 +43,6 @@ struct ssdfb_i2c_softc { struct ssdfb_softc sc; i2c_tag_t sc_i2c_tag; i2c_addr_t sc_i2c_addr; - bool sc_parent_is_smbus; }; static int ssdfb_i2c_match(device_t, cfdata_t, void *); @@ -156,7 +155,7 @@ ssdfb_i2c_transfer_rect(void *cookie, ui 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 data[] = {0, 0, 0}; uint8_t cmd[2]; int error;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: tnn Date: Sun Mar 17 01:03:47 UTC 2019 Modified Files: src/sys/dev/i2c: files.i2c Added Files: src/sys/dev/i2c: ssdfb_i2c.c Log Message: add i2c attachment for ssdfb To generate a diff of this commit: cvs rdiff -u -r1.98 -r1.99 src/sys/dev/i2c/files.i2c cvs rdiff -u -r0 -r1.1 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/files.i2c diff -u src/sys/dev/i2c/files.i2c:1.98 src/sys/dev/i2c/files.i2c:1.99 --- src/sys/dev/i2c/files.i2c:1.98 Sun Feb 3 13:17:12 2019 +++ src/sys/dev/i2c/files.i2c Sun Mar 17 01:03:47 2019 @@ -1,4 +1,4 @@ -# $NetBSD: files.i2c,v 1.98 2019/02/03 13:17:12 jmcneill Exp $ +# $NetBSD: files.i2c,v 1.99 2019/03/17 01:03:47 tnn Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } @@ -358,6 +358,10 @@ attach rkpmic at iic attach rkreg at rkpmic file dev/i2c/rkpmic.c rkpmic +# SSD1306 or SH1106 OLED/PLED display +attach ssdfb at iic with ssdfb_iic +file dev/i2c/ssdfb_i2c.c ssdfb_iic + # Analogix ANX6345 eDP transmitter device anxedp: edid, videomode, drmkms, drmkms_i2c attach anxedp at iic Added files: Index: src/sys/dev/i2c/ssdfb_i2c.c diff -u /dev/null src/sys/dev/i2c/ssdfb_i2c.c:1.1 --- /dev/null Sun Mar 17 01:03:47 2019 +++ src/sys/dev/i2c/ssdfb_i2c.c Sun Mar 17 01:03:47 2019 @@ -0,0 +1,368 @@ +/* $NetBSD: ssdfb_i2c.c,v 1.1 2019/03/17 01:03:47 tnn Exp $ */ + +/* + * Copyright (c) 2019 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Tobias Nygren. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: ssdfb_i2c.c,v 1.1 2019/03/17 01:03:47 tnn Exp $"); + +#include +#include +#include +#include +#include +#include + +struct ssdfb_i2c_softc { + struct ssdfb_softc sc; + i2c_tag_t sc_i2c_tag; + i2c_addr_t sc_i2c_addr; + bool sc_parent_is_smbus; +}; + +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_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); +static int ssdfb_i2c_transfer_rect_ssd1306(void *, uint8_t, uint8_t, +uint8_t, uint8_t, uint8_t *, size_t, bool); +static int ssdfb_i2c_transfer_rect_sh1106(void *, uint8_t, uint8_t, +uint8_t, uint8_t, uint8_t *, size_t, bool); +static int ssdfb_smbus_transfer_rect(void *, uint8_t, uint8_t, uint8_t, +uint8_t, uint8_t *, size_t, bool); + +CFATTACH_DECL_NEW(ssdfb_iic, sizeof(struct ssdfb_i2c_softc), +ssdfb_i2c_match, ssdfb_i2c_attach, ssdfb_i2c_detach, NULL); + +static const struct device_compatible_entry compat_data[] = { + { "solomon,ssd1306fb-i2c", 0 }, + { "sino,sh1106fb-i2c", 0 }, + { NULL,0 } +}; + +static int +ssdfb_i2c_match(device_t parent, cfdata_t match, void *aux) +{ + struct i2c_attach_args *ia = aux; + int match_result; + + if (iic_use_direct_match(ia, match, compat_data, _result)) + return match_result; + + switch (ia->ia_addr) { + case SSDFB_I2C_DEFAULT_ADDR: + case SSDFB_I2C_ALTERNATIVE_ADDR: + return I2C_MATCH_ADDRESS_ONLY; + } + + return 0; +} + +static void +ssdfb_i2c_attach(device_t parent, device_t self, void *aux) +{ + struct ssdfb_i2c_softc *sc = device_private(self); + struct cfdata *cf = device_cfdata(self); + struct i2c_attach_args *ia = aux; + int flags = cf->cf_flags; + int i; + + if ((flags & SSDFB_ATTACH_FLAG_PRODUCT_MASK) == SSDFB_PRODUCT_UNKNOWN) {
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Wed Feb 20 18:19:46 UTC 2019 Modified Files: src/sys/dev/i2c: lm75.c Log Message: moar match string To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/sys/dev/i2c/lm75.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/lm75.c diff -u src/sys/dev/i2c/lm75.c:1.33 src/sys/dev/i2c/lm75.c:1.34 --- src/sys/dev/i2c/lm75.c:1.33 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/lm75.c Wed Feb 20 18:19:46 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: lm75.c,v 1.33 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: lm75.c,v 1.34 2019/02/20 18:19:46 macallan Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.33 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.34 2019/02/20 18:19:46 macallan Exp $"); #include #include @@ -103,6 +103,7 @@ static int sysctl_lm75_temp(SYSCTLFN_ARG static const struct device_compatible_entry compat_data[] = { { "i2c-lm75", 0 }, + { "lm75", 0 }, { "ds1775", 0 }, /* * see XXX in _attach() below: add code once non-lm75 matches are
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: martin Date: Wed Feb 6 08:37:12 UTC 2019 Modified Files: src/sys/dev/i2c: dbcool.c Log Message: Change a aprint_verbose into aprint_debug - the message does not add real value to the dmesg(8) output. To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 src/sys/dev/i2c/dbcool.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/dbcool.c diff -u src/sys/dev/i2c/dbcool.c:1.53 src/sys/dev/i2c/dbcool.c:1.54 --- src/sys/dev/i2c/dbcool.c:1.53 Sun Feb 3 11:58:02 2019 +++ src/sys/dev/i2c/dbcool.c Wed Feb 6 08:37:12 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: dbcool.c,v 1.53 2019/02/03 11:58:02 mrg Exp $ */ +/* $NetBSD: dbcool.c,v 1.54 2019/02/06 08:37:12 martin Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -50,7 +50,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.53 2019/02/03 11:58:02 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.54 2019/02/06 08:37:12 martin Exp $"); #include #include @@ -1884,7 +1884,7 @@ dbcool_chip_ident(struct dbcool_chipset return i; } - aprint_verbose("dbcool_chip_ident: addr 0x%02x c_id 0x%02x d_id 0x%02x" + aprint_debug("dbcool_chip_ident: addr 0x%02x c_id 0x%02x d_id 0x%02x" " r_id 0x%02x: No match.\n", dc->dc_addr, c_id, d_id, r_id);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun Feb 3 13:56:38 UTC 2019 Modified Files: src/sys/dev/i2c: anxedp.c Log Message: Broadcast PMF display on/off events when our connector is handling dpms so we can turn off the backlight To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/anxedp.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/anxedp.c diff -u src/sys/dev/i2c/anxedp.c:1.1 src/sys/dev/i2c/anxedp.c:1.2 --- src/sys/dev/i2c/anxedp.c:1.1 Sun Feb 3 13:17:12 2019 +++ src/sys/dev/i2c/anxedp.c Sun Feb 3 13:56:38 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: anxedp.c,v 1.1 2019/02/03 13:17:12 jmcneill Exp $ */ +/* $NetBSD: anxedp.c,v 1.2 2019/02/03 13:56:38 jmcneill Exp $ */ /*- * Copyright (c) 2019 Jared D. McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: anxedp.c,v 1.1 2019/02/03 13:17:12 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: anxedp.c,v 1.2 2019/02/03 13:56:38 jmcneill Exp $"); #include #include @@ -111,6 +111,22 @@ anxedp_write(struct anxedp_softc *sc, u_ (void)iic_smbus_write_byte(sc->sc_i2c, sc->sc_addr + off, reg, val, I2C_F_POLL); } +static int +anxedp_connector_dpms(struct drm_connector *connector, int mode) +{ + int error; + + if (mode != DRM_MODE_DPMS_ON) + pmf_event_inject(NULL, PMFE_DISPLAY_OFF); + + error = drm_helper_connector_dpms(connector, mode); + + if (mode == DRM_MODE_DPMS_ON) + pmf_event_inject(NULL, PMFE_DISPLAY_ON); + + return error; +} + static enum drm_connector_status anxedp_connector_detect(struct drm_connector *connector, bool force) { @@ -125,7 +141,7 @@ anxedp_connector_destroy(struct drm_conn } static const struct drm_connector_funcs anxedp_connector_funcs = { - .dpms = drm_helper_connector_dpms, + .dpms = anxedp_connector_dpms, .detect = anxedp_connector_detect, .fill_modes = drm_helper_probe_single_connector_modes, .destroy = anxedp_connector_destroy,
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun Feb 3 13:17:12 UTC 2019 Modified Files: src/sys/dev/i2c: files.i2c Added Files: src/sys/dev/i2c: anxedp.c Log Message: Add basic support for Analogix eDP transmitters. This driver doesn't know how to mode set yet -- it only knows how to read EDID from a panel. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/sys/dev/i2c/anxedp.c cvs rdiff -u -r1.97 -r1.98 src/sys/dev/i2c/files.i2c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/files.i2c diff -u src/sys/dev/i2c/files.i2c:1.97 src/sys/dev/i2c/files.i2c:1.98 --- src/sys/dev/i2c/files.i2c:1.97 Fri Dec 14 22:05:36 2018 +++ src/sys/dev/i2c/files.i2c Sun Feb 3 13:17:12 2019 @@ -1,4 +1,4 @@ -# $NetBSD: files.i2c,v 1.97 2018/12/14 22:05:36 macallan Exp $ +# $NetBSD: files.i2c,v 1.98 2019/02/03 13:17:12 jmcneill Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } @@ -357,3 +357,8 @@ device rkreg: rkpmic attach rkpmic at iic attach rkreg at rkpmic file dev/i2c/rkpmic.c rkpmic + +# Analogix ANX6345 eDP transmitter +device anxedp: edid, videomode, drmkms, drmkms_i2c +attach anxedp at iic +file dev/i2c/anxedp.c anxedp Added files: Index: src/sys/dev/i2c/anxedp.c diff -u /dev/null src/sys/dev/i2c/anxedp.c:1.1 --- /dev/null Sun Feb 3 13:17:12 2019 +++ src/sys/dev/i2c/anxedp.c Sun Feb 3 13:17:12 2019 @@ -0,0 +1,432 @@ +/* $NetBSD: anxedp.c,v 1.1 2019/02/03 13:17:12 jmcneill Exp $ */ + +/*- + * Copyright (c) 2019 Jared D. McNeill + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: anxedp.c,v 1.1 2019/02/03 13:17:12 jmcneill Exp $"); + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#define ANX_DP_AUX_CH_CTL_1 0xe5 +#define ANX_AUX_LENGTH __BITS(7,4) +#define ANX_AUX_TX_COMM __BITS(3,0) +#define ANX_AUX_TX_COMM_MOT 4 +#define ANX_AUX_TX_COMM_READ 1 +#define ANX_DP_AUX_ADDR(n) (0xe6 + (n)) +#define ANX_DP_AUX_CH_CTL_2 0xe9 +#define ANX_ADDR_ONLY __BIT(1) +#define ANX_AUX_EN __BIT(0) +#define ANX_BUF_DATA(n) (0xf0 + (n)) + +#define ANX_DP_INT_STA 0xf7 +#define ANX_RPLY_RECEIV __BIT(1) + +static const struct device_compatible_entry compat_data[] = { + { "analogix,anx6345", 1 }, + { NULL } +}; + +struct anxedp_softc; + +struct anxedp_connector { + struct drm_connector base; + struct anxedp_softc *sc; +}; + +struct anxedp_softc { + device_t sc_dev; + i2c_tag_t sc_i2c; + i2c_addr_t sc_addr; + int sc_phandle; + + struct anxedp_connector sc_connector; + struct drm_bridge sc_bridge; + + struct fdt_device_ports sc_ports; + struct drm_display_mode sc_curmode; +}; + +#define to_anxedp_connector(x) container_of(x, struct anxedp_connector, base) + +static uint8_t +anxedp_read(struct anxedp_softc *sc, u_int off, uint8_t reg) +{ + uint8_t val; + + if (iic_smbus_read_byte(sc->sc_i2c, sc->sc_addr + off, reg, , I2C_F_POLL) != 0) + val = 0xff; + + return val; +} + +static void +anxedp_write(struct anxedp_softc *sc, u_int off, uint8_t reg, uint8_t val) +{ + (void)iic_smbus_write_byte(sc->sc_i2c, sc->sc_addr + off, reg, val, I2C_F_POLL); +} + +static enum drm_connector_status +anxedp_connector_detect(struct drm_connector *connector, bool force) +{ + return connector_status_connected; +} + +static void +anxedp_connector_destroy(struct drm_connector *connector) +{ + drm_connector_unregister(connector); + drm_connector_cleanup(connector); +} + +static const struct drm_connector_funcs anxedp_connector_funcs = {
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mrg Date: Sun Feb 3 12:18:21 UTC 2019 Modified Files: src/sys/dev/i2c: si70xx.c Log Message: add missing break. fairly sure this is correct, otherwise modelstr would be overwritten with the next entry in this list.. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/si70xx.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/si70xx.c diff -u src/sys/dev/i2c/si70xx.c:1.4 src/sys/dev/i2c/si70xx.c:1.5 --- src/sys/dev/i2c/si70xx.c:1.4 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/si70xx.c Sun Feb 3 12:18:21 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: si70xx.c,v 1.4 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: si70xx.c,v 1.5 2019/02/03 12:18:21 mrg Exp $ */ /* * Copyright (c) 2017 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: si70xx.c,v 1.4 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: si70xx.c,v 1.5 2019/02/03 12:18:21 mrg Exp $"); /* Driver for the Silicon Labs SI7013/SI7020/SI7021 @@ -746,6 +746,7 @@ si70xx_attach(device_t parent, device_t case 0: case 0xff: snprintf(modelstr, sizeof(modelstr), "Engineering Sample"); + break; case 13: case 20: case 21:
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: mrg Date: Sun Feb 3 11:58:02 UTC 2019 Modified Files: src/sys/dev/i2c: dbcool.c Log Message: - dbcool_pmf_suspend() set the wrong bit out of the suspended data as it is stored as a bool and thus when bit 2 was wanted, bit 1 was restored. found by GCC7's "don't use ~ on bool" checker. - consolidate the dbcool_pmf_suspend()/dbcool_pmf_resume() guts in to a shared function dbcool_do_pmf() as they are identical except for 1 vs 2 lines. To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 src/sys/dev/i2c/dbcool.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/dbcool.c diff -u src/sys/dev/i2c/dbcool.c:1.52 src/sys/dev/i2c/dbcool.c:1.53 --- src/sys/dev/i2c/dbcool.c:1.52 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/dbcool.c Sun Feb 3 11:58:02 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: dbcool.c,v 1.52 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: dbcool.c,v 1.53 2019/02/03 11:58:02 mrg Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -50,7 +50,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.52 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.53 2019/02/03 11:58:02 mrg Exp $"); #include #include @@ -825,8 +825,13 @@ dbcool_detach(device_t self, int flags) return 0; } -/* On suspend, we save the state of the SHDN bit, then set it */ -bool dbcool_pmf_suspend(device_t dev, const pmf_qual_t *qual) +/* + * On suspend, we save the state of the SHDN bit, then set it + * On resume, we restore the previous state of the SHDN bit (which + * we saved in sc_suspend) + */ +static bool +dbcool_do_pmf(device_t dev, const pmf_qual_t *qual, bool suspend) { struct dbcool_softc *sc = device_private(dev); uint8_t reg, bit, cfg; @@ -842,34 +847,29 @@ bool dbcool_pmf_suspend(device_t dev, co bit = DBCOOL_CFG2_SHDN; } cfg = sc->sc_dc.dc_readreg(>sc_dc, reg); - sc->sc_suspend = cfg & bit; - cfg |= bit; + if (suspend) { + sc->sc_suspend = (cfg & bit) != 0; + cfg |= bit; + } else { + cfg &= sc->sc_suspend ? bit : 0; + } sc->sc_dc.dc_writereg(>sc_dc, reg, cfg); return true; } -/* On resume, we restore the previous state of the SHDN bit (which - we saved in sc_suspend) */ -bool dbcool_pmf_resume(device_t dev, const pmf_qual_t *qual) +bool +dbcool_pmf_suspend(device_t dev, const pmf_qual_t *qual) { - struct dbcool_softc *sc = device_private(dev); - uint8_t reg, cfg; - if ((sc->sc_dc.dc_chip->flags & DBCFLAG_HAS_SHDN) == 0) - return true; - - if (sc->sc_dc.dc_chip->flags & DBCFLAG_ADT7466) { - reg = DBCOOL_ADT7466_CONFIG2; - } else { - reg = DBCOOL_CONFIG2_REG; - } - cfg = sc->sc_dc.dc_readreg(>sc_dc, reg); - cfg &= ~sc->sc_suspend; - sc->sc_dc.dc_writereg(>sc_dc, reg, cfg); + return dbcool_do_pmf(dev, qual, true); +} - return true; +bool +dbcool_pmf_resume(device_t dev, const pmf_qual_t *qual) +{ + return dbcool_do_pmf(dev, qual, false); } uint8_t
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun Jan 27 11:41:52 UTC 2019 Modified Files: src/sys/dev/i2c: ddcreg.h Log Message: Add a definition for the DDC segment address (30h). To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/ddcreg.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/ddcreg.h diff -u src/sys/dev/i2c/ddcreg.h:1.2 src/sys/dev/i2c/ddcreg.h:1.3 --- src/sys/dev/i2c/ddcreg.h:1.2 Sun May 14 21:42:27 2006 +++ src/sys/dev/i2c/ddcreg.h Sun Jan 27 11:41:52 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: ddcreg.h,v 1.2 2006/05/14 21:42:27 elad Exp $ */ +/* $NetBSD: ddcreg.h,v 1.3 2019/01/27 11:41:52 jmcneill Exp $ */ /*- * Copyright (c) 2006 Itronix Inc. @@ -35,7 +35,8 @@ #ifndef _DEV_I2C_DDCREG_H_ #define _DEV_I2C_DDCREG_H_ -#define DDC_ADDR 0x50 -#define DDC_EDID_START 0 +#define DDC_ADDR 0x50 +#define DDC_SEGMENT_ADDR 0x30 +#define DDC_EDID_START 0 #endif /* _DEV_I2C_DDCREG_H_ */
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Wed Jan 2 18:38:03 UTC 2019 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: Revert part of previous - do not reserve regulators, it's perfectly normal for devices to share one. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 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.17 src/sys/dev/i2c/axppmic.c:1.18 --- src/sys/dev/i2c/axppmic.c:1.17 Wed Jan 2 17:28:55 2019 +++ src/sys/dev/i2c/axppmic.c Wed Jan 2 18:38:03 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.17 2019/01/02 17:28:55 jmcneill Exp $ */ +/* $NetBSD: axppmic.c,v 1.18 2019/01/02 18:38:03 jmcneill Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill @@ -27,13 +27,12 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.17 2019/01/02 17:28:55 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.18 2019/01/02 18:38:03 jmcneill Exp $"); #include #include #include #include -#include #include #include #include @@ -310,7 +309,6 @@ struct axpreg_softc { i2c_tag_t sc_i2c; i2c_addr_t sc_addr; const struct axppmic_ctrl *sc_ctrl; - u_int sc_inuse; }; struct axpreg_attach_args { @@ -880,20 +878,12 @@ axppmic_attach(device_t parent, device_t static int axpreg_acquire(device_t dev) { - struct axpreg_softc *sc = device_private(dev); - - if (atomic_cas_uint(>sc_inuse, 0, 1) != 0) - return EBUSY; - return 0; } static void axpreg_release(device_t dev) { - struct axpreg_softc *sc = device_private(dev); - - atomic_swap_uint(>sc_inuse, 0); } static int
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Wed Jan 2 17:28:55 UTC 2019 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: Add support for AXP813 and only allow one consumer per regulator at a time To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 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.16 src/sys/dev/i2c/axppmic.c:1.17 --- src/sys/dev/i2c/axppmic.c:1.16 Tue Nov 13 19:06:05 2018 +++ src/sys/dev/i2c/axppmic.c Wed Jan 2 17:28:55 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.16 2018/11/13 19:06:05 jakllsch Exp $ */ +/* $NetBSD: axppmic.c,v 1.17 2019/01/02 17:28:55 jmcneill Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill @@ -27,12 +27,13 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.16 2018/11/13 19:06:05 jakllsch Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.17 2019/01/02 17:28:55 jmcneill Exp $"); #include #include #include #include +#include #include #include #include @@ -202,6 +203,47 @@ static const struct axppmic_ctrl axp805_ 0x11, __BIT(6), 0x26, __BITS(4,0)), }; +static const struct axppmic_ctrl axp813_ctrls[] = { + AXP_CTRL("dldo1", 700, 3300, 100, + 0x12, __BIT(3), 0x15, __BITS(4,0)), + AXP_CTRL2("dldo2", 700, 4200, 100, 28, 200, 4, + 0x12, __BIT(4), 0x16, __BITS(4,0)), + AXP_CTRL("dldo3", 700, 3300, 100, + 0x12, __BIT(5), 0x17, __BITS(4,0)), + AXP_CTRL("dldo4", 700, 3300, 100, + 0x12, __BIT(6), 0x18, __BITS(4,0)), + AXP_CTRL("eldo1", 700, 1900, 50, + 0x12, __BIT(0), 0x19, __BITS(4,0)), + AXP_CTRL("eldo2", 700, 1900, 50, + 0x12, __BIT(1), 0x1a, __BITS(4,0)), + AXP_CTRL("eldo3", 700, 1900, 50, + 0x12, __BIT(2), 0x1b, __BITS(4,0)), + AXP_CTRL("fldo1", 700, 1450, 50, + 0x13, __BIT(2), 0x1c, __BITS(3,0)), + AXP_CTRL("fldo2", 700, 1450, 50, + 0x13, __BIT(3), 0x1d, __BITS(3,0)), + AXP_CTRL("dcdc1", 1600, 3400, 100, + 0x10, __BIT(0), 0x20, __BITS(4,0)), + AXP_CTRL2("dcdc2", 500, 1300, 10, 70, 20, 5, + 0x10, __BIT(1), 0x21, __BITS(6,0)), + AXP_CTRL2("dcdc3", 500, 1300, 10, 70, 20, 5, + 0x10, __BIT(2), 0x22, __BITS(6,0)), + AXP_CTRL2("dcdc4", 500, 1300, 10, 70, 20, 5, + 0x10, __BIT(3), 0x23, __BITS(6,0)), + AXP_CTRL2("dcdc5", 800, 1840, 10, 33, 20, 36, + 0x10, __BIT(4), 0x24, __BITS(6,0)), + AXP_CTRL2("dcdc6", 600, 1520, 10, 51, 20, 21, + 0x10, __BIT(5), 0x25, __BITS(6,0)), + AXP_CTRL2("dcdc7", 600, 1520, 10, 51, 20, 21, + 0x10, __BIT(6), 0x26, __BITS(6,0)), + AXP_CTRL("aldo1", 700, 3300, 100, + 0x13, __BIT(5), 0x28, __BITS(4,0)), + AXP_CTRL("aldo2", 700, 3300, 100, + 0x13, __BIT(6), 0x29, __BITS(4,0)), + AXP_CTRL("aldo3", 700, 3300, 100, + 0x13, __BIT(7), 0x2a, __BITS(4,0)), +}; + struct axppmic_irq { u_int reg; uint8_t mask; @@ -268,6 +310,7 @@ struct axpreg_softc { i2c_tag_t sc_i2c; i2c_addr_t sc_addr; const struct axppmic_ctrl *sc_ctrl; + u_int sc_inuse; }; struct axpreg_attach_args { @@ -305,10 +348,31 @@ static const struct axppmic_config axp80 .poklirq = AXPPMIC_IRQ(2, __BIT(0)), }; +static const struct axppmic_config axp813_config = { + .name = "AXP813", + .controls = axp813_ctrls, + .ncontrols = __arraycount(axp813_ctrls), + .irq_regs = 6, + .has_battery = true, + .has_fuel_gauge = true, + .batsense_step = 1100, + .charge_step = 1000, + .discharge_step = 1000, + .maxcap_step = 1456, + .coulomb_step = 1456, + .poklirq = AXPPMIC_IRQ(5, __BIT(3)), + .acinirq = AXPPMIC_IRQ(1, __BITS(6,5)), + .vbusirq = AXPPMIC_IRQ(1, __BITS(3,2)), + .battirq = AXPPMIC_IRQ(2, __BITS(7,6)), + .chargeirq = AXPPMIC_IRQ(2, __BITS(3,2)), + .chargestirq = AXPPMIC_IRQ(4, __BITS(1,0)), +}; + static const struct device_compatible_entry compat_data[] = { { "x-powers,axp803", (uintptr_t)_config }, { "x-powers,axp805", (uintptr_t)_config }, { "x-powers,axp806", (uintptr_t)_config }, + { "x-powers,axp813", (uintptr_t)_config }, { NULL,0 } }; @@ -816,12 +880,20 @@ axppmic_attach(device_t parent, device_t static int axpreg_acquire(device_t dev) { + struct axpreg_softc *sc = device_private(dev); + + if (atomic_cas_uint(>sc_inuse, 0, 1) != 0) + return EBUSY; + return 0; } static void axpreg_release(device_t dev) { + struct axpreg_softc *sc = device_private(dev); + + atomic_swap_uint(>sc_inuse, 0); } static int
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Thu Dec 20 21:36:53 UTC 2018 Modified Files: src/sys/dev/i2c: ds1307.c Log Message: make DSRTC_FLAG_YEAR_START_2K settable by device property To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 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.30 src/sys/dev/i2c/ds1307.c:1.31 --- src/sys/dev/i2c/ds1307.c:1.30 Fri Dec 14 22:05:36 2018 +++ src/sys/dev/i2c/ds1307.c Thu Dec 20 21:36:53 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ds1307.c,v 1.30 2018/12/14 22:05:36 macallan Exp $ */ +/* $NetBSD: ds1307.c,v 1.31 2018/12/20 21:36:53 macallan Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.30 2018/12/14 22:05:36 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.31 2018/12/20 21:36:53 macallan Exp $"); #include #include @@ -297,6 +297,8 @@ dsrtc_attach(device_t parent, device_t s struct dsrtc_softc *sc = device_private(self); struct i2c_attach_args *ia = arg; const struct dsrtc_model *dm; + prop_dictionary_t dict = device_properties(self); + bool base_2k = FALSE; if ((dm = dsrtc_model_by_compat(ia)) == NULL) dm = dsrtc_model_by_number(device_cfdata(self)->cf_flags); @@ -331,6 +333,10 @@ dsrtc_attach(device_t parent, device_t s sc->sc_model.dm_flags |= DSRTC_FLAG_YEAR_START_2K; #endif + prop_dictionary_get_bool(dict, "base_year_is_2000", _2k); + if (base_2k) sc->sc_model.dm_flags |= DSRTC_FLAG_YEAR_START_2K; + + todr_attach(>sc_todr); if ((sc->sc_model.dm_flags & DSRTC_FLAG_TEMP) != 0) { int error;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Fri Dec 14 22:05:36 UTC 2018 Modified Files: src/sys/dev/i2c: ds1307.c files.i2c Log Message: add options DSRTC_YEAR_START_2K for machines which use 2000 and not 1970 as base to count years from, like Iyonix. While there apply the offset when writing to the clock as well. To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/sys/dev/i2c/ds1307.c cvs rdiff -u -r1.96 -r1.97 src/sys/dev/i2c/files.i2c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/ds1307.c diff -u src/sys/dev/i2c/ds1307.c:1.29 src/sys/dev/i2c/ds1307.c:1.30 --- src/sys/dev/i2c/ds1307.c:1.29 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/ds1307.c Fri Dec 14 22:05:36 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ds1307.c,v 1.29 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: ds1307.c,v 1.30 2018/12/14 22:05:36 macallan Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.29 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.30 2018/12/14 22:05:36 macallan Exp $"); #include #include @@ -54,6 +54,7 @@ __KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1 #include #include "ioconf.h" +#include "opt_dsrtc.h" struct dsrtc_model { const i2c_addr_t *dm_valid_addrs; @@ -316,6 +317,7 @@ dsrtc_attach(device_t parent, device_t s sc->sc_dev = self; sc->sc_open = 0; sc->sc_todr.cookie = sc; + if (dm->dm_flags & DSRTC_FLAG_BCD) { sc->sc_todr.todr_gettime_ymdhms = dsrtc_gettime_ymdhms; sc->sc_todr.todr_settime_ymdhms = dsrtc_settime_ymdhms; @@ -325,6 +327,10 @@ dsrtc_attach(device_t parent, device_t s } sc->sc_todr.todr_setwen = NULL; +#ifdef DSRTC_YEAR_START_2K + sc->sc_model.dm_flags |= DSRTC_FLAG_YEAR_START_2K; +#endif + todr_attach(>sc_todr); if ((sc->sc_model.dm_flags & DSRTC_FLAG_TEMP) != 0) { int error; @@ -571,7 +577,7 @@ dsrtc_clock_write_ymdhms(struct dsrtc_so { struct dsrtc_model * const dm = >sc_model; uint8_t bcd[DS_RTC_SIZE], cmdbuf[2]; - int error; + int error, offset; KASSERT(DS_RTC_SIZE >= dm->dm_rtc_size); @@ -585,8 +591,15 @@ dsrtc_clock_write_ymdhms(struct dsrtc_so bcd[DS_DATE] = bintobcd(dt->dt_day); bcd[DS_DAY] = bintobcd(dt->dt_wday); bcd[DS_MONTH] = bintobcd(dt->dt_mon); - bcd[DS_YEAR] = bintobcd((dt->dt_year - POSIX_BASE_YEAR) % 100); - if (dt->dt_year - POSIX_BASE_YEAR >= 100) + + if (sc->sc_model.dm_flags & DSRTC_FLAG_YEAR_START_2K) { + offset = 2000; + } else { + offset = POSIX_BASE_YEAR; + } + + bcd[DS_YEAR] = bintobcd((dt->dt_year - offset) % 100); + if (dt->dt_year - offset >= 100) bcd[DS_MONTH] |= DS_MONTH_CENTURY; if ((error = iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) != 0) { Index: src/sys/dev/i2c/files.i2c diff -u src/sys/dev/i2c/files.i2c:1.96 src/sys/dev/i2c/files.i2c:1.97 --- src/sys/dev/i2c/files.i2c:1.96 Sun Sep 2 01:16:58 2018 +++ src/sys/dev/i2c/files.i2c Fri Dec 14 22:05:36 2018 @@ -1,4 +1,4 @@ -# $NetBSD: files.i2c,v 1.96 2018/09/02 01:16:58 jmcneill Exp $ +# $NetBSD: files.i2c,v 1.97 2018/12/14 22:05:36 macallan Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } @@ -123,6 +123,7 @@ file dev/i2c/lm87.clmenv device dsrtc: sysmon_envsys attach dsrtc at iic file dev/i2c/ds1307.c dsrtc +defflag opt_dsrtc.hDSRTC_YEAR_START_2K # Xicor X1226 Real Time Clock device xrtc
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Mon Dec 10 00:31:45 UTC 2018 Modified Files: src/sys/dev/i2c: i2c_exec.c i2cvar.h Log Message: Make i2c_acquire_bus() / i2c_release_bus() real symbols. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sys/dev/i2c/i2c_exec.c cvs rdiff -u -r1.17 -r1.18 src/sys/dev/i2c/i2cvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/i2c_exec.c diff -u src/sys/dev/i2c/i2c_exec.c:1.10 src/sys/dev/i2c/i2c_exec.c:1.11 --- src/sys/dev/i2c/i2c_exec.c:1.10 Sat Mar 7 14:16:51 2015 +++ src/sys/dev/i2c/i2c_exec.c Mon Dec 10 00:31:45 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c_exec.c,v 1.10 2015/03/07 14:16:51 jmcneill Exp $ */ +/* $NetBSD: i2c_exec.c,v 1.11 2018/12/10 00:31:45 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: i2c_exec.c,v 1.10 2015/03/07 14:16:51 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c_exec.c,v 1.11 2018/12/10 00:31:45 thorpej Exp $"); #include #include @@ -54,6 +54,30 @@ static uint8_t iic_smbus_pec(int, uint8_ static int i2cexec_modcmd(modcmd_t, void *); /* + * iic_acquire_bus: + * + * Acquire the I2C bus for use by a client. + */ +int +iic_acquire_bus(i2c_tag_t tag, int flags) +{ + + return (*tag->ic_acquire_bus)(tag->ic_cookie, flags); +} + +/* + * iic_release_bus: + * + * Relese the I2C bus, allowing another client to use it. + */ +void +iic_release_bus(i2c_tag_t tag, int flags) +{ + + (*tag->ic_release_bus)(tag->ic_cookie, flags); +} + +/* * iic_exec: * * Simplified I2C client interface engine. Index: src/sys/dev/i2c/i2cvar.h diff -u src/sys/dev/i2c/i2cvar.h:1.17 src/sys/dev/i2c/i2cvar.h:1.18 --- src/sys/dev/i2c/i2cvar.h:1.17 Tue Jun 26 06:34:55 2018 +++ src/sys/dev/i2c/i2cvar.h Mon Dec 10 00:31:45 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: i2cvar.h,v 1.17 2018/06/26 06:34:55 thorpej Exp $ */ +/* $NetBSD: i2cvar.h,v 1.18 2018/12/10 00:31:45 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -208,11 +208,8 @@ bool iic_use_direct_match(const struct i * Simplified API for clients of the i2c framework. Definitions * in . */ -#define iic_acquire_bus(ic, flags) \ - (*(ic)->ic_acquire_bus)((ic)->ic_cookie, (flags)) -#define iic_release_bus(ic, flags) \ - (*(ic)->ic_release_bus)((ic)->ic_cookie, (flags)) - +int iic_acquire_bus(i2c_tag_t, int); +void iic_release_bus(i2c_tag_t, int); int iic_exec(i2c_tag_t, i2c_op_t, i2c_addr_t, const void *, size_t, void *, size_t, int);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jakllsch Date: Tue Nov 13 19:06:05 UTC 2018 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: Add AXP803 current and maximum battery capacity sensors To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 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.15 src/sys/dev/i2c/axppmic.c:1.16 --- src/sys/dev/i2c/axppmic.c:1.15 Tue Nov 13 18:27:32 2018 +++ src/sys/dev/i2c/axppmic.c Tue Nov 13 19:06:05 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.15 2018/11/13 18:27:32 jakllsch Exp $ */ +/* $NetBSD: axppmic.c,v 1.16 2018/11/13 19:06:05 jakllsch Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.15 2018/11/13 18:27:32 jakllsch Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.16 2018/11/13 19:06:05 jakllsch Exp $"); #include #include @@ -83,6 +83,17 @@ __KERNEL_RCSID(0, "$NetBSD: axppmic.c,v #define AXP_BATT_CAP_VALID __BIT(7) #define AXP_BATT_CAP_PERCENT __BITS(6,0) +#define AXP_BATT_MAX_CAP_HI_REG 0xe0 +#define AXP_BATT_MAX_CAP_VALID __BIT(7) +#define AXP_BATT_MAX_CAP_LO_REG 0xe1 + +#define AXP_BATT_COULOMB_HI_REG 0xe2 +#define AXP_BATT_COULOMB_VALID __BIT(7) +#define AXP_BATT_COULOMB_LO_REG 0xe3 + +#define AXP_COULOMB_RAW(_hi, _lo) \ + (((u_int)(_hi & ~__BIT(7)) << 8) | (_lo)) + #define AXP_BATT_CAP_WARN_REG 0xe6 #define AXP_BATT_CAP_WARN_LV1 __BITS(7,4) #define AXP_BATT_CAP_WARN_LV2 __BITS(3,0) @@ -229,6 +240,8 @@ enum axppmic_sensor { AXP_SENSOR_BATT_CHARGE_CURRENT, AXP_SENSOR_BATT_DISCHARGE_CURRENT, AXP_SENSOR_BATT_CAPACITY_PERCENT, + AXP_SENSOR_BATT_MAXIMUM_CAPACITY, + AXP_SENSOR_BATT_CURRENT_CAPACITY, AXP_NSENSORS }; @@ -274,6 +287,8 @@ static const struct axppmic_config axp80 .batsense_step = 1100, .charge_step = 1000, .discharge_step = 1000, + .maxcap_step = 1456, + .coulomb_step = 1456, .poklirq = AXPPMIC_IRQ(5, __BIT(3)), .acinirq = AXPPMIC_IRQ(1, __BITS(6,5)), .vbusirq = AXPPMIC_IRQ(1, __BITS(3,2)), @@ -495,6 +510,22 @@ axppmic_sensor_update(struct sysmon_envs e->value_cur = AXP_ADC_RAW(hi, lo) * c->discharge_step; } break; + case AXP_SENSOR_BATT_MAXIMUM_CAPACITY: + if (battery_present && + axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATT_MAX_CAP_HI_REG, , flags) == 0 && + axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATT_MAX_CAP_LO_REG, , flags) == 0) { + e->state = (hi & AXP_BATT_MAX_CAP_VALID) ? ENVSYS_SVALID : ENVSYS_SINVALID; + e->value_cur = AXP_COULOMB_RAW(hi, lo) * c->maxcap_step; + } + break; + case AXP_SENSOR_BATT_CURRENT_CAPACITY: + if (battery_present && + axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATT_COULOMB_HI_REG, , flags) == 0 && + axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATT_COULOMB_LO_REG, , flags) == 0) { + e->state = (hi & AXP_BATT_COULOMB_VALID) ? ENVSYS_SVALID : ENVSYS_SINVALID; + e->value_cur = AXP_COULOMB_RAW(hi, lo) * c->coulomb_step; + } + break; } } @@ -653,6 +684,24 @@ axppmic_attach_battery(struct axppmic_so strlcpy(e->desc, "battery percent", sizeof(e->desc)); sysmon_envsys_sensor_attach(sc->sc_sme, e); } + + if (c->maxcap_step) { + e = >sc_sensor[AXP_SENSOR_BATT_MAXIMUM_CAPACITY]; + e->private = AXP_SENSOR_BATT_MAXIMUM_CAPACITY; + e->units = ENVSYS_SAMPHOUR; + e->state = ENVSYS_SINVALID; + strlcpy(e->desc, "battery maximum capacity", sizeof(e->desc)); + sysmon_envsys_sensor_attach(sc->sc_sme, e); + } + + if (c->coulomb_step) { + e = >sc_sensor[AXP_SENSOR_BATT_CURRENT_CAPACITY]; + e->private = AXP_SENSOR_BATT_CURRENT_CAPACITY; + e->units = ENVSYS_SAMPHOUR; + e->state = ENVSYS_SINVALID; + strlcpy(e->desc, "battery current capacity", sizeof(e->desc)); + sysmon_envsys_sensor_attach(sc->sc_sme, e); + } } static void
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jakllsch Date: Tue Nov 13 18:27:32 UTC 2018 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: Use semantically-correct "_lo" in AXP_ADC_RAW macro. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 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.14 src/sys/dev/i2c/axppmic.c:1.15 --- src/sys/dev/i2c/axppmic.c:1.14 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/axppmic.c Tue Nov 13 18:27:32 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.14 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: axppmic.c,v 1.15 2018/11/13 18:27:32 jakllsch Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.14 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.15 2018/11/13 18:27:32 jakllsch Exp $"); #include #include @@ -74,7 +74,7 @@ __KERNEL_RCSID(0, "$NetBSD: axppmic.c,v #define AXP_BATTDISCHG_LO_REG 0x7d #define AXP_ADC_RAW(_hi, _lo) \ - (((u_int)(_hi) << 4) | ((lo) & 0xf)) + (((u_int)(_hi) << 4) | ((_lo) & 0xf)) #define AXP_FUEL_GAUGE_CTRL_REG 0xb8 #define AXP_FUEL_GAUGE_CTRL_EN __BIT(7)
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Sat Oct 20 03:23:05 UTC 2018 Modified Files: src/sys/dev/i2c: spdmem_i2c.c Log Message: match "i2c-at34c02", found in various sparc64 boxes To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 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.16 src/sys/dev/i2c/spdmem_i2c.c:1.17 --- src/sys/dev/i2c/spdmem_i2c.c:1.16 Wed Sep 26 20:15:08 2018 +++ src/sys/dev/i2c/spdmem_i2c.c Sat Oct 20 03:23:05 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: spdmem_i2c.c,v 1.16 2018/09/26 20:15:08 jakllsch Exp $ */ +/* $NetBSD: spdmem_i2c.c,v 1.17 2018/10/20 03:23:05 macallan Exp $ */ /* * Copyright (c) 2007 Nicolas Joly @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.16 2018/09/26 20:15:08 jakllsch Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.17 2018/10/20 03:23:05 macallan Exp $"); #include #include @@ -173,8 +173,9 @@ error: } static const struct device_compatible_entry compat_data[] = { - { "atmel,spd", 0 }, - { NULL, 0 } + { "atmel,spd", 0 }, + { "i2c-at34c02", 0 }, + { NULL, 0 } }; static int
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Wed Oct 17 16:56:40 UTC 2018 Modified Files: src/sys/dev/i2c: tcakp.c Log Message: lock/unlock I2C bus around transfers as required by API To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/tcakp.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/tcakp.c diff -u src/sys/dev/i2c/tcakp.c:1.9 src/sys/dev/i2c/tcakp.c:1.10 --- src/sys/dev/i2c/tcakp.c:1.9 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/tcakp.c Wed Oct 17 16:56:40 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: tcakp.c,v 1.9 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: tcakp.c,v 1.10 2018/10/17 16:56:40 jmcneill Exp $ */ /*- * Copyright (c) 2017 Jared McNeill @@ -29,7 +29,7 @@ #include "opt_fdt.h" #include -__KERNEL_RCSID(0, "$NetBSD: tcakp.c,v 1.9 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tcakp.c,v 1.10 2018/10/17 16:56:40 jmcneill Exp $"); #include #include @@ -364,14 +364,26 @@ tcakp_attach(device_t parent, device_t s static int tcakp_read(struct tcakp_softc *sc, uint8_t reg, uint8_t *val) { - return iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr, + int error; + + iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); + error = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr, , 1, val, 1, I2C_F_POLL); + iic_release_bus(sc->sc_i2c, I2C_F_POLL); + + return error; } static int tcakp_write(struct tcakp_softc *sc, uint8_t reg, uint8_t val) { uint8_t buf[2] = { reg, val }; - return iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, + int error; + + iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); + error = iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, NULL, 0, buf, 2, I2C_F_POLL); + iic_release_bus(sc->sc_i2c, I2C_F_POLL); + + return error; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: bouyer Date: Mon Oct 1 09:39:20 UTC 2018 Modified Files: src/sys/dev/i2c: gttwsi_core.c Log Message: Expand code covered by sc->sc_mtx, to make sure an interrupt would not be handled before the cv_timedwait_sig() call, or while polling. Seems to fix "sunxitwi0: send STOP failed" messages frequently seen related to axp20x0 sensors. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/gttwsi_core.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/gttwsi_core.c diff -u src/sys/dev/i2c/gttwsi_core.c:1.7 src/sys/dev/i2c/gttwsi_core.c:1.8 --- src/sys/dev/i2c/gttwsi_core.c:1.7 Mon Jun 18 12:42:29 2018 +++ src/sys/dev/i2c/gttwsi_core.c Mon Oct 1 09:39:20 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: gttwsi_core.c,v 1.7 2018/06/18 12:42:29 jakllsch Exp $ */ +/* $NetBSD: gttwsi_core.c,v 1.8 2018/10/01 09:39:20 bouyer Exp $ */ /* * Copyright (c) 2008 Eiji Kawauchi. * All rights reserved. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.7 2018/06/18 12:42:29 jakllsch Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.8 2018/10/01 09:39:20 bouyer Exp $"); #include "locators.h" #include @@ -192,15 +192,15 @@ gttwsi_intr(void *arg) struct gttwsi_softc *sc = arg; uint32_t val; + mutex_enter(>sc_mtx); val = gttwsi_read_4(sc, TWSI_CONTROL); if (val & CONTROL_IFLG) { gttwsi_write_4(sc, TWSI_CONTROL, val & ~CONTROL_INTEN); - mutex_enter(>sc_mtx); cv_broadcast(>sc_cv); mutex_exit(>sc_mtx); - return 1; /* handled */ } + mutex_exit(>sc_mtx); return 0; } @@ -377,6 +377,7 @@ gttwsi_wait(struct gttwsi_softc *sc, uin control |= CONTROL_INTEN; if (sc->sc_iflg_rwc) control |= CONTROL_IFLG; + mutex_enter(>sc_mtx); gttwsi_write_4(sc, TWSI_CONTROL, control | CONTROL_TWSIEN); timo = 0; @@ -385,17 +386,21 @@ gttwsi_wait(struct gttwsi_softc *sc, uin if (control & CONTROL_IFLG) break; if (!(flags & I2C_F_POLL)) { - mutex_enter(>sc_mtx); error = cv_timedwait_sig(>sc_cv, >sc_mtx, hz); - mutex_exit(>sc_mtx); if (error) -return error; +break; + } else { + DELAY(TWSI_RETRY_DELAY); + if (timo++ > 100) /* 1sec */ +break; } - DELAY(TWSI_RETRY_DELAY); - if (timo++ > 100) /* 1sec */ - break; } - + if ((control & CONTROL_IFLG) == 0) { + aprint_error_dev(sc->sc_dev, + "gttwsi_wait(): timeout, control=0x%x\n", control); + error = EWOULDBLOCK; + goto end; + } status = gttwsi_read_4(sc, TWSI_STATUS); if (status != expect) { /* @@ -408,7 +413,9 @@ gttwsi_wait(struct gttwsi_softc *sc, uin aprint_error_dev(sc->sc_dev, "unexpected status 0x%x: expect 0x%x\n", status, expect); - return EIO; + error = EIO; } +end: + mutex_exit(>sc_mtx); return error; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jakllsch Date: Wed Sep 26 20:15:08 UTC 2018 Modified Files: src/sys/dev/i2c: spdmem_i2c.c Log Message: match spdmem_i2c on "atmel,spd" compatible string To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 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.15 src/sys/dev/i2c/spdmem_i2c.c:1.16 --- src/sys/dev/i2c/spdmem_i2c.c:1.15 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/spdmem_i2c.c Wed Sep 26 20:15:08 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: spdmem_i2c.c,v 1.15 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: spdmem_i2c.c,v 1.16 2018/09/26 20:15:08 jakllsch Exp $ */ /* * Copyright (c) 2007 Nicolas Joly @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.15 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.16 2018/09/26 20:15:08 jakllsch Exp $"); #include #include @@ -172,11 +172,20 @@ error: return rv; } +static const struct device_compatible_entry compat_data[] = { + { "atmel,spd", 0 }, + { NULL, 0 } +}; + static int spdmem_i2c_match(device_t parent, cfdata_t match, void *aux) { struct i2c_attach_args *ia = aux; struct spdmem_i2c_softc sc; + int match_result; + + if (iic_use_direct_match(ia, match, compat_data, _result)) + return match_result; /* * XXXJRT
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Thu Sep 20 09:02:46 UTC 2018 Modified Files: src/sys/dev/i2c: rkpmic.c Log Message: Add support for RK805 To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/rkpmic.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/rkpmic.c diff -u src/sys/dev/i2c/rkpmic.c:1.1 src/sys/dev/i2c/rkpmic.c:1.2 --- src/sys/dev/i2c/rkpmic.c:1.1 Sun Sep 2 01:16:58 2018 +++ src/sys/dev/i2c/rkpmic.c Thu Sep 20 09:02:46 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: rkpmic.c,v 1.1 2018/09/02 01:16:58 jmcneill Exp $ */ +/* $NetBSD: rkpmic.c,v 1.2 2018/09/20 09:02:46 jmcneill Exp $ */ /*- * Copyright (c) 2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rkpmic.c,v 1.1 2018/09/02 01:16:58 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rkpmic.c,v 1.2 2018/09/20 09:02:46 jmcneill Exp $"); #include #include @@ -52,6 +52,8 @@ struct rkpmic_ctrl { uint8_t vsel_mask; u_int base; u_int step; + u_int flags; +#define F_ENABLE_WRITE_MASK 0x00 }; struct rkpmic_config { @@ -60,6 +62,44 @@ struct rkpmic_config { u_int nctrl; }; +static const struct rkpmic_ctrl rk805_ctrls[] = { + /* DCDC */ + { .name = "DCDC_REG1", .flags = F_ENABLE_WRITE_MASK, + .enable_reg = 0x23, .enable_mask = __BIT(0), + .vsel_reg = 0x2f, .vsel_mask = __BITS(5,0), + .base = 712500, .step = 12500 }, + { .name = "DCDC_REG2", .flags = F_ENABLE_WRITE_MASK, + .enable_reg = 0x23, .enable_mask = __BIT(1), + .vsel_reg = 0x33, .vsel_mask = __BITS(5,0), + .base = 712500, .step = 12500 }, + { .name = "DCDC_REG3", .flags = F_ENABLE_WRITE_MASK, + .enable_reg = 0x23, .enable_mask = __BIT(2) }, + { .name = "DCDC_REG4", .flags = F_ENABLE_WRITE_MASK, + .enable_reg = 0x23, .enable_mask = __BIT(3), + .vsel_reg = 0x38, .vsel_mask = __BITS(3,0), + .base = 80, .step = 10 }, + + /* LDO */ + { .name = "LDO_REG1", .flags = F_ENABLE_WRITE_MASK, + .enable_reg = 0x27, .enable_mask = __BIT(0), + .vsel_reg = 0x3b, .vsel_mask = __BITS(4,0), + .base = 80, .step = 10 }, + { .name = "LDO_REG2", .flags = F_ENABLE_WRITE_MASK, + .enable_reg = 0x27, .enable_mask = __BIT(1), + .vsel_reg = 0x3d, .vsel_mask = __BITS(4,0), + .base = 80, .step = 10 }, + { .name = "LDO_REG3", .flags = F_ENABLE_WRITE_MASK, + .enable_reg = 0x27, .enable_mask = __BIT(2), + .vsel_reg = 0x3f, .vsel_mask = __BITS(4,0), + .base = 80, .step = 10 }, +}; + +static const struct rkpmic_config rk805_config = { + .name = "RK805", + .ctrl = rk805_ctrls, + .nctrl = __arraycount(rk805_ctrls), +}; + static const struct rkpmic_ctrl rk808_ctrls[] = { /* DCDC */ { .name = "DCDC_REG1", @@ -145,6 +185,7 @@ struct rkreg_attach_args { }; static const struct device_compatible_entry compat_data[] = { + { "rockchip,rk805", (uintptr_t)_config }, { "rockchip,rk808", (uintptr_t)_config }, { NULL } }; @@ -252,7 +293,10 @@ rkreg_enable(device_t dev, bool enable) return EINVAL; I2C_LOCK(sc->sc_pmic); - val = I2C_READ(sc->sc_pmic, c->enable_reg); + if (c->flags & F_ENABLE_WRITE_MASK) + val |= c->enable_mask << 4; + else + val = I2C_READ(sc->sc_pmic, c->enable_reg); if (enable) val |= c->enable_mask; else
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun Sep 2 01:16:58 UTC 2018 Modified Files: src/sys/dev/i2c: files.i2c Added Files: src/sys/dev/i2c: rkpmic.c Log Message: Add driver for Rockchip RK808 Power Management IC. To generate a diff of this commit: cvs rdiff -u -r1.95 -r1.96 src/sys/dev/i2c/files.i2c cvs rdiff -u -r0 -r1.1 src/sys/dev/i2c/rkpmic.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/files.i2c diff -u src/sys/dev/i2c/files.i2c:1.95 src/sys/dev/i2c/files.i2c:1.96 --- src/sys/dev/i2c/files.i2c:1.95 Wed Aug 29 01:57:38 2018 +++ src/sys/dev/i2c/files.i2c Sun Sep 2 01:16:58 2018 @@ -1,4 +1,4 @@ -# $NetBSD: files.i2c,v 1.95 2018/08/29 01:57:38 jmcneill Exp $ +# $NetBSD: files.i2c,v 1.96 2018/09/02 01:16:58 jmcneill Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } @@ -349,3 +349,10 @@ file dev/i2c/tea5767.ctea5767radio device fan53555reg attach fan53555reg at iic file dev/i2c/fan53555.c fan53555reg + +# Rockchip Power Management IC +device rkpmic { } +device rkreg: rkpmic +attach rkpmic at iic +attach rkreg at rkpmic +file dev/i2c/rkpmic.c rkpmic Added files: Index: src/sys/dev/i2c/rkpmic.c diff -u /dev/null src/sys/dev/i2c/rkpmic.c:1.1 --- /dev/null Sun Sep 2 01:16:58 2018 +++ src/sys/dev/i2c/rkpmic.c Sun Sep 2 01:16:58 2018 @@ -0,0 +1,353 @@ +/* $NetBSD: rkpmic.c,v 1.1 2018/09/02 01:16:58 jmcneill Exp $ */ + +/*- + * Copyright (c) 2018 Jared McNeill + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: rkpmic.c,v 1.1 2018/09/02 01:16:58 jmcneill Exp $"); + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#define CHIP_NAME_REG 0x17 +#define CHIP_VER_REG 0x18 + +struct rkpmic_ctrl { + const char * name; + uint8_t enable_reg; + uint8_t enable_mask; + uint8_t vsel_reg; + uint8_t vsel_mask; + u_int base; + u_int step; +}; + +struct rkpmic_config { + const char * name; + const struct rkpmic_ctrl *ctrl; + u_int nctrl; +}; + +static const struct rkpmic_ctrl rk808_ctrls[] = { + /* DCDC */ + { .name = "DCDC_REG1", + .enable_reg = 0x23, .enable_mask = __BIT(0), + .vsel_reg = 0x2f, .vsel_mask = __BITS(5,0), + .base = 712500, .step = 12500 }, + { .name = "DCDC_REG2", + .enable_reg = 0x23, .enable_mask = __BIT(1), + .vsel_reg = 0x33, .vsel_mask = __BITS(5,0), + .base = 712500, .step = 12500 }, + { .name = "DCDC_REG3", + .enable_reg = 0x23, .enable_mask = __BIT(2) }, + { .name = "DCDC_REG4", + .enable_reg = 0x23, .enable_mask = __BIT(3), + .vsel_reg = 0x38, .vsel_mask = __BITS(3,0), + .base = 180, .step = 10 }, + + /* LDO */ + { .name = "LDO_REG1", + .enable_reg = 0x24, .enable_mask = __BIT(0), + .vsel_reg = 0x3b, .vsel_mask = __BITS(4,0), + .base = 180, .step = 10 }, + { .name = "LDO_REG2", + .enable_reg = 0x24, .enable_mask = __BIT(0), + .vsel_reg = 0x3d, .vsel_mask = __BITS(4,0), + .base = 180, .step = 10 }, + { .name = "LDO_REG3", + .enable_reg = 0x24, .enable_mask = __BIT(0), + .vsel_reg = 0x3f, .vsel_mask = __BITS(3,0), + .base = 80, .step = 10 }, + { .name = "LDO_REG4", + .enable_reg = 0x24, .enable_mask = __BIT(0), + .vsel_reg = 0x41, .vsel_mask = __BITS(4,0), + .base = 180, .step = 10 }, + { .name = "LDO_REG5", + .enable_reg = 0x24, .enable_mask = __BIT(0), + .vsel_reg = 0x43, .vsel_mask = __BITS(4,0), + .base = 180, .step = 10 }, + { .name = "LDO_REG6", + .enable_reg = 0x24, .enable_mask = __BIT(0), + .vsel_reg = 0x45, .vsel_mask =
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Wed Aug 29 11:08:30 UTC 2018 Modified Files: src/sys/dev/i2c: fan53555.c Log Message: Initialize transition slew rate if specified in the DT To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 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.1 src/sys/dev/i2c/fan53555.c:1.2 --- src/sys/dev/i2c/fan53555.c:1.1 Wed Aug 29 01:57:38 2018 +++ src/sys/dev/i2c/fan53555.c Wed Aug 29 11:08:30 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: fan53555.c,v 1.1 2018/08/29 01:57:38 jmcneill Exp $ */ +/* $NetBSD: fan53555.c,v 1.2 2018/08/29 11:08:30 jmcneill Exp $ */ /*- * Copyright (c) 2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: fan53555.c,v 1.1 2018/08/29 01:57:38 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fan53555.c,v 1.2 2018/08/29 11:08:30 jmcneill Exp $"); #include #include @@ -80,6 +80,14 @@ enum fan53555_vendor { FAN_VENDOR_SILERGY, }; +/* + * Transition slew rates. + * Array index is reg value, value is slew rate in uV / us + */ +static const int fan53555_slew_rates[] = { + 64000, 32000, 16000, 8000, 4000, 2000, 1000, 500 +}; + static const struct device_compatible_entry compat_data[] = { { "silergy,syr827", FAN_VENDOR_SILERGY }, { "silergy,syr828", FAN_VENDOR_SILERGY }, @@ -205,7 +213,8 @@ static struct fdtbus_regulator_controlle static int fan53555_init(struct fan53555_softc *sc, enum fan53555_vendor vendor) { - uint8_t id1; + uint8_t id1, control; + int n; I2C_LOCK(sc); id1 = I2C_READ(sc, ID1_REG); @@ -232,6 +241,8 @@ fan53555_init(struct fan53555_softc *sc, return ENXIO; } + of_getprop_uint32(sc->sc_phandle, "suspend_voltage_selector", + >sc_suspend_voltage_selector); switch (sc->sc_suspend_voltage_selector) { case 0: sc->sc_suspend_reg = VSEL0_REG; @@ -242,10 +253,28 @@ fan53555_init(struct fan53555_softc *sc, sc->sc_runtime_reg = VSEL0_REG; break; default: - aprint_error(": Unsupported 'fcs,suspend-voltage-selector' value %u\n", sc->sc_suspend_voltage_selector); + aprint_error_dev(sc->sc_dev, "unsupported 'fcs,suspend-voltage-selector' value %u\n", sc->sc_suspend_voltage_selector); return EINVAL; } + of_getprop_uint32(sc->sc_phandle, "regulator-ramp-delay", + >sc_ramp_delay); + if (sc->sc_ramp_delay) { + for (n = 0; n < __arraycount(fan53555_slew_rates); n++) + if (sc->sc_ramp_delay > fan53555_slew_rates[n]) +break; + if (n == __arraycount(fan53555_slew_rates)) { + aprint_error_dev(sc->sc_dev, "unsupported 'regulator-ramp-delay' value %u\n", sc->sc_ramp_delay); + return EINVAL; + } + I2C_LOCK(sc); + control = I2C_READ(sc, CONTROL_REG); + control &= ~CONTROL_SLEW; + control |= __SHIFTIN(fan53555_slew_rates[n], CONTROL_SLEW); + I2C_WRITE(sc, CONTROL_REG, control); + I2C_UNLOCK(sc); + } + return 0; } @@ -267,7 +296,6 @@ fan53555_attach(device_t parent, device_ struct fan53555_softc * const sc = device_private(self); const struct device_compatible_entry *compat; struct i2c_attach_args *ia = aux; - enum fan53555_vendor vendor; sc->sc_dev = self; sc->sc_i2c = ia->ia_tag; @@ -275,14 +303,8 @@ fan53555_attach(device_t parent, device_ sc->sc_phandle = ia->ia_cookie; iic_compatible_match(ia, compat_data, ); - vendor = compat->data; - - of_getprop_uint32(sc->sc_phandle, "regulator-ramp-delay", - >sc_ramp_delay); - of_getprop_uint32(sc->sc_phandle, "suspend_voltage_selector", - >sc_suspend_voltage_selector); - if (fan53555_init(sc, vendor) != 0) + if (fan53555_init(sc, compat->data) != 0) return; fdtbus_register_regulator_controller(self, sc->sc_phandle,
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Wed Aug 29 01:57:38 UTC 2018 Modified Files: src/sys/dev/i2c: files.i2c Added Files: src/sys/dev/i2c: fan53555.c Log Message: Add driver for Silergy SY827/SY828 step down regulator. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/sys/dev/i2c/fan53555.c cvs rdiff -u -r1.94 -r1.95 src/sys/dev/i2c/files.i2c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/files.i2c diff -u src/sys/dev/i2c/files.i2c:1.94 src/sys/dev/i2c/files.i2c:1.95 --- src/sys/dev/i2c/files.i2c:1.94 Fri Jul 27 12:02:26 2018 +++ src/sys/dev/i2c/files.i2c Wed Aug 29 01:57:38 2018 @@ -1,4 +1,4 @@ -# $NetBSD: files.i2c,v 1.94 2018/07/27 12:02:26 rkujawa Exp $ +# $NetBSD: files.i2c,v 1.95 2018/08/29 01:57:38 jmcneill Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } @@ -345,3 +345,7 @@ device tea5767radio : radiodev attach tea5767radio at iic file dev/i2c/tea5767.ctea5767radio +# Fairchild FAN53555 / Silergy SY82x regulator +device fan53555reg +attach fan53555reg at iic +file dev/i2c/fan53555.c fan53555reg Added files: Index: src/sys/dev/i2c/fan53555.c diff -u /dev/null src/sys/dev/i2c/fan53555.c:1.1 --- /dev/null Wed Aug 29 01:57:38 2018 +++ src/sys/dev/i2c/fan53555.c Wed Aug 29 01:57:38 2018 @@ -0,0 +1,293 @@ +/* $NetBSD: fan53555.c,v 1.1 2018/08/29 01:57:38 jmcneill Exp $ */ + +/*- + * Copyright (c) 2018 Jared McNeill + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: fan53555.c,v 1.1 2018/08/29 01:57:38 jmcneill Exp $"); + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#define VSEL0_REG 0x00 +#define VSEL1_REG 0x01 +#define VSEL_BUCK_EN __BIT(7) +#define VSEL_MODE __BIT(6) +#define VSEL_NSEL __BITS(5,0) +#define CONTROL_REG 0x02 +#define CONTROL_OUTPUT_DISCHARGE __BIT(7) +#define CONTROL_SLEW __BITS(6,4) +#define CONTROL_RESET __BIT(2) +#define ID1_REG 0x03 +#define ID1_VENDOR __BITS(7,5) +#define ID1_DIE_ID __BITS(3,0) +#define SILERGY_DIE_ID_SYR82X 8 +#define ID2_REG 0x04 +#define ID2_DIE_REV __BITS(3,0) +#define MONITOR_REG 0x05 +#define MONITOR_PGOOD __BIT(7) + +struct fan53555_softc { + device_t sc_dev; + i2c_tag_t sc_i2c; + i2c_addr_t sc_addr; + int sc_phandle; + + u_int sc_suspend_reg; + u_int sc_runtime_reg; + + u_int sc_base; + u_int sc_step; + + u_int sc_ramp_delay; + u_int sc_suspend_voltage_selector; +}; + +enum fan53555_vendor { + FAN_VENDOR_FAIRCHILD = 1, + FAN_VENDOR_SILERGY, +}; + +static const struct device_compatible_entry compat_data[] = { + { "silergy,syr827", FAN_VENDOR_SILERGY }, + { "silergy,syr828", FAN_VENDOR_SILERGY }, + { NULL,0 } +}; + +static uint8_t +fan53555_read(struct fan53555_softc *sc, uint8_t reg, int flags) +{ + uint8_t val = 0; + int error; + + error = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr, + , 1, , 1, flags); + if (error != 0) + aprint_error_dev(sc->sc_dev, "error reading reg %#x: %d\n", reg, error); + + return val; +} + +static void +fan53555_write(struct fan53555_softc *sc, uint8_t reg, uint8_t val, int flags) +{ + uint8_t buf[2]; + int error; + + buf[0] = reg; + buf[1] = val; + + error = iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, + NULL, 0, buf, 2, flags); + if (error != 0) + aprint_error_dev(sc->sc_dev, "error writing reg %#x: %d\n", reg, error); +} + +#define I2C_READ(sc, reg) fan53555_read((sc), (reg), I2C_F_POLL) +#define I2C_WRITE(sc, reg, val) fan53555_write((sc), (reg), (val), I2C_F_POLL)
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: macallan Date: Thu Jun 28 21:21:03 UTC 2018 Modified Files: src/sys/dev/i2c: fcu.c Log Message: fix a tpyo so now we get the correct maximum speed for CPU intake fans while there, be a bit more responsive to temperature changes To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/fcu.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/fcu.c diff -u src/sys/dev/i2c/fcu.c:1.6 src/sys/dev/i2c/fcu.c:1.7 --- src/sys/dev/i2c/fcu.c:1.6 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/fcu.c Thu Jun 28 21:21:03 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: fcu.c,v 1.6 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: fcu.c,v 1.7 2018/06/28 21:21:03 macallan Exp $ */ /*- * Copyright (c) 2018 Michael Lorenz @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: fcu.c,v 1.6 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fcu.c,v 1.7 2018/06/28 21:21:03 macallan Exp $"); #include #include @@ -256,7 +256,7 @@ fcu_attach(device_t parent, device_t sel } else if (strstr(descr, "INTAKE") != NULL) { KASSERT(eeprom != NULL); memcpy(, [0x4c], 2); -memcpy(, [0x5e], 2); +memcpy(, [0x4e], 2); fan->base_rpm = rmin; fan->max_rpm = rmax; fan->step = (rmax - rmin) / 30; @@ -276,6 +276,8 @@ fcu_attach(device_t parent, device_t sel fan->max_rpm = 3000; fan->step = 100; } + DPRINTF("fan %s: %d - %d rpm, step %d\n", + descr, fan->base_rpm, fan->max_rpm, fan->step); /* now stuff them into zones */ if (strstr(descr, "CPU A") != NULL) { @@ -503,7 +505,7 @@ fcu_adjust(void *cookie) sc->sc_pwm = FALSE; for (i = 0; i < FCU_ZONE_COUNT; i++) fcu_adjust_zone(sc, i); - kpause("fanctrl", true, mstohz(sc->sc_pwm ? 2000 : 3), NULL); + kpause("fanctrl", true, mstohz(sc->sc_pwm ? 1000 : 5000), NULL); } kthread_exit(0); }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Tue Jun 26 06:34:55 UTC 2018 Modified Files: src/sys/dev/i2c: at24cxx.c files.i2c i2c.c i2cvar.h Log Message: Remove the i2c "size" locator and corresponding property / attach arg. It was a hack meant only for EEPROMs, which have another way to specify size in the config directive ("flag" paramter), as well as a better way to detect size based on "compatible" string. To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/sys/dev/i2c/at24cxx.c cvs rdiff -u -r1.92 -r1.93 src/sys/dev/i2c/files.i2c cvs rdiff -u -r1.65 -r1.66 src/sys/dev/i2c/i2c.c cvs rdiff -u -r1.16 -r1.17 src/sys/dev/i2c/i2cvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/at24cxx.c diff -u src/sys/dev/i2c/at24cxx.c:1.29 src/sys/dev/i2c/at24cxx.c:1.30 --- src/sys/dev/i2c/at24cxx.c:1.29 Tue Jun 26 06:21:23 2018 +++ src/sys/dev/i2c/at24cxx.c Tue Jun 26 06:34:55 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: at24cxx.c,v 1.29 2018/06/26 06:21:23 thorpej Exp $ */ +/* $NetBSD: at24cxx.c,v 1.30 2018/06/26 06:34:55 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.29 2018/06/26 06:21:23 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.30 2018/06/26 06:34:55 thorpej Exp $"); #include #include @@ -169,8 +169,6 @@ seeprom_attach(device_t parent, device_t */ if (device_cfdata(self)->cf_flags) sc->sc_size = (device_cfdata(self)->cf_flags << 7); - else - sc->sc_size = ia->ia_size; if (sc->sc_size <= 0 && ia->ia_ncompat > 0) { if (iic_compatible_match(ia, compat_data, )) Index: src/sys/dev/i2c/files.i2c diff -u src/sys/dev/i2c/files.i2c:1.92 src/sys/dev/i2c/files.i2c:1.93 --- src/sys/dev/i2c/files.i2c:1.92 Sun May 27 05:31:20 2018 +++ src/sys/dev/i2c/files.i2c Tue Jun 26 06:34:55 2018 @@ -1,10 +1,10 @@ -# $NetBSD: files.i2c,v 1.92 2018/05/27 05:31:20 thorpej Exp $ +# $NetBSD: files.i2c,v 1.93 2018/06/26 06:34:55 thorpej Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } define i2cexec -device iic { [addr = -1], [size = -1] } : i2c_bitbang +device iic { [addr = -1] } : i2c_bitbang attach iic at i2cbus file dev/i2c/i2c.ciic file dev/i2c/i2c_exec.c iic | i2cbus | i2cexec Index: src/sys/dev/i2c/i2c.c diff -u src/sys/dev/i2c/i2c.c:1.65 src/sys/dev/i2c/i2c.c:1.66 --- src/sys/dev/i2c/i2c.c:1.65 Tue Jun 26 04:32:35 2018 +++ src/sys/dev/i2c/i2c.c Tue Jun 26 06:34:55 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.65 2018/06/26 04:32:35 thorpej Exp $ */ +/* $NetBSD: i2c.c,v 1.66 2018/06/26 06:34:55 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -40,7 +40,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.65 2018/06/26 04:32:35 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.66 2018/06/26 06:34:55 thorpej Exp $"); #include #include @@ -285,7 +285,6 @@ iic_search(device_t parent, cfdata_t cf, } ia.ia_tag = sc->sc_tag; - ia.ia_size = cf->cf_loc[IICCF_SIZE]; ia.ia_type = sc->sc_type; ia.ia_name = NULL; @@ -441,7 +440,7 @@ iic_attach(device_t parent, device_t sel unsigned int i, count; prop_dictionary_t dev; prop_data_t cdata; - uint32_t addr, size; + uint32_t addr; uint64_t cookie; const char *name; struct i2c_attach_args ia; @@ -462,10 +461,6 @@ iic_attach(device_t parent, device_t sel if (!prop_dictionary_get_uint64(dev, "cookie", )) cookie = 0; loc[IICCF_ADDR] = addr; - if (prop_dictionary_get_uint32(dev, "size", )) -loc[IICCF_SIZE] = size; - else -size = loc[IICCF_SIZE] = IICCF_SIZE_DEFAULT; memset(, 0, sizeof ia); ia.ia_addr = addr; @@ -473,7 +468,6 @@ iic_attach(device_t parent, device_t sel ia.ia_tag = ic; ia.ia_name = name; ia.ia_cookie = cookie; - ia.ia_size = size; ia.ia_prop = dev; buf = NULL; Index: src/sys/dev/i2c/i2cvar.h diff -u src/sys/dev/i2c/i2cvar.h:1.16 src/sys/dev/i2c/i2cvar.h:1.17 --- src/sys/dev/i2c/i2cvar.h:1.16 Tue Jun 26 04:32:35 2018 +++ src/sys/dev/i2c/i2cvar.h Tue Jun 26 06:34:55 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: i2cvar.h,v 1.16 2018/06/26 04:32:35 thorpej Exp $ */ +/* $NetBSD: i2cvar.h,v 1.17 2018/06/26 06:34:55 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -133,7 +133,6 @@ struct i2cbus_attach_args { struct i2c_attach_args { i2c_tag_t ia_tag; /* our controller */ i2c_addr_t ia_addr; /* address of device */ - int ia_size; /* size (for EEPROMs) */ int ia_type; /* bus type */ /* only set if using direct config */ const char * ia_name; /* name of the device */
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Tue Jun 26 06:21:23 UTC 2018 Modified Files: src/sys/dev/i2c: at24cxx.c Log Message: Encode the size information in the compat data. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 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.28 src/sys/dev/i2c/at24cxx.c:1.29 --- src/sys/dev/i2c/at24cxx.c:1.28 Tue Jun 26 06:03:57 2018 +++ src/sys/dev/i2c/at24cxx.c Tue Jun 26 06:21:23 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: at24cxx.c,v 1.28 2018/06/26 06:03:57 thorpej Exp $ */ +/* $NetBSD: at24cxx.c,v 1.29 2018/06/26 06:21:23 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.28 2018/06/26 06:03:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.29 2018/06/26 06:21:23 thorpej Exp $"); #include #include @@ -111,20 +111,11 @@ const struct cdevsw seeprom_cdevsw = { static int seeprom_wait_idle(struct seeprom_softc *); -static const struct seeprom_size { - const char *name; - int size; -} seeprom_sizes[] = { - { "atmel,24c02", 256 }, - { "atmel,24c16", 2048 }, -}; - -/* XXXJRT collapse seeprom_size stuff into compat_data; see also ofw code */ static const struct device_compatible_entry compat_data[] = { - { "i2c-at24c64", 0 }, - { "i2c-at34c02", 0 }, - { "atmel,24c02", 0 }, - { "atmel,24c16", 0 }, + { "i2c-at24c64", 8192 }, + { "i2c-at34c02", 256 }, + { "atmel,24c02", 256 }, + { "atmel,24c16", 2048 }, { NULL,0 } }; @@ -148,7 +139,7 @@ seeprom_attach(device_t parent, device_t { struct seeprom_softc *sc = device_private(self); struct i2c_attach_args *ia = aux; - u_int n, m; + const struct device_compatible_entry *dce; sc->sc_tag = ia->ia_tag; sc->sc_address = ia->ia_addr; @@ -182,15 +173,8 @@ seeprom_attach(device_t parent, device_t sc->sc_size = ia->ia_size; if (sc->sc_size <= 0 && ia->ia_ncompat > 0) { - for (n = 0; n < __arraycount(seeprom_sizes); n++) { - for (m = 0; m < ia->ia_ncompat; m++) { -if (!strcmp(seeprom_sizes[n].name, -ia->ia_compat[m])) { - sc->sc_size = seeprom_sizes[n].size; - break; -} - } - } + if (iic_compatible_match(ia, compat_data, )) + sc->sc_size = dce->data; } switch (sc->sc_size) {
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: martin Date: Fri Jun 22 15:52:00 UTC 2018 Modified Files: src/sys/dev/i2c: i2c.c Log Message: iic_use_direct_match(): when iic_compatible_match() does not find a comptible entry, set match quality to 0. Otherwise callers might use random stack garbage. To generate a diff of this commit: cvs rdiff -u -r1.63 -r1.64 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.63 src/sys/dev/i2c/i2c.c:1.64 --- src/sys/dev/i2c/i2c.c:1.63 Mon Jun 18 17:07:07 2018 +++ src/sys/dev/i2c/i2c.c Fri Jun 22 15:52:00 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.63 2018/06/18 17:07:07 thorpej Exp $ */ +/* $NetBSD: i2c.c,v 1.64 2018/06/22 15:52:00 martin Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -40,7 +40,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.63 2018/06/18 17:07:07 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.64 2018/06/22 15:52:00 martin Exp $"); #include #include @@ -735,7 +735,8 @@ iic_use_direct_match(const struct i2c_at } if (ia->ia_ncompat > 0 && ia->ia_compat != NULL) { - (void) iic_compatible_match(ia, compats, match_resultp); + if (iic_compatible_match(ia, compats, match_resultp) == NULL) + *match_resultp = 0; return true; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: martin Date: Fri Jun 22 15:48:57 UTC 2018 Modified Files: src/sys/dev/i2c: dbcool.c Log Message: Add a kernel panic when we matched but can not handle a string - better die explicitly instead of crashing a few lines later with strange NULL derefs. To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.51 src/sys/dev/i2c/dbcool.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/dbcool.c diff -u src/sys/dev/i2c/dbcool.c:1.50 src/sys/dev/i2c/dbcool.c:1.51 --- src/sys/dev/i2c/dbcool.c:1.50 Mon Jun 18 17:07:07 2018 +++ src/sys/dev/i2c/dbcool.c Fri Jun 22 15:48:57 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: dbcool.c,v 1.50 2018/06/18 17:07:07 thorpej Exp $ */ +/* $NetBSD: dbcool.c,v 1.51 2018/06/22 15:48:57 martin Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -50,7 +50,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.50 2018/06/18 17:07:07 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.51 2018/06/22 15:48:57 martin Exp $"); #include #include @@ -779,9 +779,11 @@ dbcool_attach(device_t parent, device_t sc->sc_dc.dc_chip = NULL; sc->sc_dc.dc_readreg = dbcool_readreg; sc->sc_dc.dc_writereg = dbcool_writereg; - (void)dbcool_chip_ident(>sc_dc); sc->sc_dev = self; + if (dbcool_chip_ident(>sc_dc) < 0 || sc->sc_dc.dc_chip == NULL) + panic("could not identify chip at addr %d", args->ia_addr); + aprint_naive("\n"); aprint_normal("\n");
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Tue Jun 19 02:08:12 UTC 2018 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: Use the device_compatible_entry mechanism rather than of_compat_data; all of the OF / FDT data we need is already in the i2c_attach_args. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 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.11 src/sys/dev/i2c/axppmic.c:1.12 --- src/sys/dev/i2c/axppmic.c:1.11 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/axppmic.c Tue Jun 19 02:08:12 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.11 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: axppmic.c,v 1.12 2018/06/19 02:08:12 thorpej Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.11 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.12 2018/06/19 02:08:12 thorpej Exp $"); #include #include @@ -264,6 +264,7 @@ struct axpreg_attach_args { i2c_addr_t reg_addr; }; +static const char *axp803_compatstrings[] = { "x-powers,axp803", NULL }; static const struct axppmic_config axp803_config = { .name = "AXP803", .controls = axp803_ctrls, @@ -282,6 +283,8 @@ static const struct axppmic_config axp80 .chargestirq = AXPPMIC_IRQ(4, __BITS(1,0)), }; +static const char *axp805_compatstrings[] = { "x-powers,axp805", + "x-powers,axp806", NULL }; static const struct axppmic_config axp805_config = { .name = "AXP805/806", .controls = axp805_ctrls, @@ -290,11 +293,10 @@ static const struct axppmic_config axp80 .poklirq = AXPPMIC_IRQ(2, __BIT(0)), }; -static const struct of_compat_data compat_data[] = { - { "x-powers,axp803", (uintptr_t)_config }, - { "x-powers,axp805", (uintptr_t)_config }, - { "x-powers,axp806", (uintptr_t)_config }, - { NULL } +static const struct device_compatible_entry axppmic_compat_data[] = { + DEVICE_COMPAT_ENTRY_WITH_DATA(axp803_compatstrings, _config), + DEVICE_COMPAT_ENTRY_WITH_DATA(axp805_compatstrings, _config), + DEVICE_COMPAT_TERMINATOR }; static int @@ -678,22 +680,10 @@ static int axppmic_match(device_t parent, cfdata_t match, void *aux) { struct i2c_attach_args *ia = aux; + int match_result; - /* XXXJRT Gross. */ - if (ia->ia_name != NULL) { - if (ia->ia_cookie) { - int match_result = - of_match_compat_data(ia->ia_cookie, compat_data); - if (match_result) { -match_result = match_result - 1 + -I2C_MATCH_DIRECT_COMPATIBLE; -match_result = MIN(match_result, -I2C_MATCH_DIRECT_COMPATIBLE_MAX); - } - return match_result; - } else - return 0; - } + if (iic_use_direct_match(ia, match, axppmic_compat_data, _result)) + return match_result; /* This device is direct-config only. */ @@ -704,6 +694,7 @@ static void axppmic_attach(device_t parent, device_t self, void *aux) { struct axppmic_softc *sc = device_private(self); + const struct device_compatible_entry *dce; const struct axppmic_config *c; struct axpreg_attach_args aaa; struct i2c_attach_args *ia = aux; @@ -711,7 +702,9 @@ axppmic_attach(device_t parent, device_t uint32_t irq_mask; void *ih; - c = (void *)of_search_compatible(ia->ia_cookie, compat_data)->data; + dce = iic_compatible_match(ia, axppmic_compat_data, NULL); + KASSERT(dce != NULL); + c = DEVICE_COMPAT_ENTRY_GET_PTR(dce); sc->sc_dev = self; sc->sc_i2c = ia->ia_tag;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jakllsch Date: Mon Jun 18 12:42:29 UTC 2018 Modified Files: src/sys/dev/i2c: gttwsi_core.c Log Message: Bail early if gttwsi_send_start() fails in gttwsi_initiate_xfer() to avoid unexpected state error message later (on Allwinner H5). To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/gttwsi_core.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/gttwsi_core.c diff -u src/sys/dev/i2c/gttwsi_core.c:1.6 src/sys/dev/i2c/gttwsi_core.c:1.7 --- src/sys/dev/i2c/gttwsi_core.c:1.6 Tue Jun 12 13:18:48 2018 +++ src/sys/dev/i2c/gttwsi_core.c Mon Jun 18 12:42:29 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: gttwsi_core.c,v 1.6 2018/06/12 13:18:48 thorpej Exp $ */ +/* $NetBSD: gttwsi_core.c,v 1.7 2018/06/18 12:42:29 jakllsch Exp $ */ /* * Copyright (c) 2008 Eiji Kawauchi. * All rights reserved. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.6 2018/06/12 13:18:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.7 2018/06/18 12:42:29 jakllsch Exp $"); #include "locators.h" #include @@ -283,7 +283,9 @@ gttwsi_initiate_xfer(void *v, i2c_addr_t KASSERT(sc->sc_inuse); - gttwsi_send_start(v, flags); + error = gttwsi_send_start(v, flags); + if (error) + return error; read = (flags & I2C_F_READ) != 0; if (read) {
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sun Jun 17 14:50:54 UTC 2018 Modified Files: src/sys/dev/i2c: max77620.c Log Message: Fix compilation error pointed out by nishimura@. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/max77620.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/max77620.c diff -u src/sys/dev/i2c/max77620.c:1.3 src/sys/dev/i2c/max77620.c:1.4 --- src/sys/dev/i2c/max77620.c:1.3 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/max77620.c Sun Jun 17 14:50:54 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: max77620.c,v 1.3 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: max77620.c,v 1.4 2018/06/17 14:50:54 thorpej Exp $ */ /*- * Copyright (c) 2017 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: max77620.c,v 1.3 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: max77620.c,v 1.4 2018/06/17 14:50:54 thorpej Exp $"); #include #include @@ -260,7 +260,7 @@ max77620_match(device_t parent, cfdata_t struct i2c_attach_args *ia = aux; int match_result; - if (iic_use_direct_match(ia, match, max77620_compats, match_result)) + if (iic_use_direct_match(ia, match, max77620_compats, _result)) return match_result; return 0;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sun Jun 17 01:08:15 UTC 2018 Modified Files: src/sys/dev/i2c: am2315.c Log Message: Oops, another one. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/am2315.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/am2315.c diff -u src/sys/dev/i2c/am2315.c:1.4 src/sys/dev/i2c/am2315.c:1.5 --- src/sys/dev/i2c/am2315.c:1.4 Sun Jun 17 01:07:06 2018 +++ src/sys/dev/i2c/am2315.c Sun Jun 17 01:08:15 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: am2315.c,v 1.4 2018/06/17 01:07:06 thorpej Exp $ */ +/* $NetBSD: am2315.c,v 1.5 2018/06/17 01:08:15 thorpej Exp $ */ /* * Copyright (c) 2017 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: am2315.c,v 1.4 2018/06/17 01:07:06 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: am2315.c,v 1.5 2018/06/17 01:08:15 thorpej Exp $"); /* * Driver for the Aosong AM2315 @@ -171,7 +171,6 @@ static int am2315_match(device_t parent, cfdata_t match, void *aux) { struct i2c_attach_args *ia = aux; - int rv; int match_result; if (iic_use_direct_match(ia, match, NULL, _result))
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sun Jun 17 01:07:06 UTC 2018 Modified Files: src/sys/dev/i2c: am2315.c Log Message: Remove now-unused variable. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/am2315.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/am2315.c diff -u src/sys/dev/i2c/am2315.c:1.3 src/sys/dev/i2c/am2315.c:1.4 --- src/sys/dev/i2c/am2315.c:1.3 Sat Jun 16 21:22:13 2018 +++ src/sys/dev/i2c/am2315.c Sun Jun 17 01:07:06 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: am2315.c,v 1.3 2018/06/16 21:22:13 thorpej Exp $ */ +/* $NetBSD: am2315.c,v 1.4 2018/06/17 01:07:06 thorpej Exp $ */ /* * Copyright (c) 2017 Brad Spencer @@ -17,7 +17,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: am2315.c,v 1.3 2018/06/16 21:22:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: am2315.c,v 1.4 2018/06/17 01:07:06 thorpej Exp $"); /* * Driver for the Aosong AM2315 @@ -172,7 +172,6 @@ am2315_match(device_t parent, cfdata_t m { struct i2c_attach_args *ia = aux; int rv; - const bool matchdebug = false; int match_result; if (iic_use_direct_match(ia, match, NULL, _result))
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sat Jun 16 21:24:36 UTC 2018 Modified Files: src/sys/dev/i2c: hytp14.c Log Message: More cleanup to i2c autoconfiguration: - Get all of the drivers onto the new match quality constants. - Introduce a new helper function, iic_use_direct_match(), that has all of the logic for direct-config matching. If it returns true, the driver returns the match result (which may be 0). If it returns false, the driver does indirect-config matching. - iic_compat_match() now returns a weighted match quality; matches to lower-indexed "compatible" device property are more-specific matches, and return a better match quality accordingly. XXX This driver is an odd-ball with respect to the hardware device. See comments in the match routine. Unclear how best to handle it. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/hytp14.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/hytp14.c diff -u src/sys/dev/i2c/hytp14.c:1.7 src/sys/dev/i2c/hytp14.c:1.8 --- src/sys/dev/i2c/hytp14.c:1.7 Sun Jul 3 12:26:55 2016 +++ src/sys/dev/i2c/hytp14.c Sat Jun 16 21:24:36 2018 @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.7 2016/07/03 12:26:55 kardel Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.8 2018/06/16 21:24:36 thorpej Exp $"); #include #include @@ -98,19 +98,25 @@ static struct hytp14_sensor hytp14_senso static int hytp14_match(device_t parent, cfdata_t match, void *aux) { - struct i2c_attach_args *ia; + struct i2c_attach_args *ia = aux; + int match_result; - ia = aux; + if (iic_use_direct_match(ia, match, NULL, _result)) + return match_result; - if (ia->ia_name) { - /* direct config - check name */ - if (strcmp(ia->ia_name, "hythygtemp") == 0) - return 1; - } else { - /* indirect config - check for configured address */ - if ((ia->ia_addr > 0) && (ia->ia_addr <= 0x7F)) - return 1; - } + if (ia->ia_addr == 0x28) + return I2C_MATCH_ADDRESS_ONLY; + + /* + * XXXJRT + * This device is an odd-ball; the i2c address can be changed + * at run-time using a command sequence documented in the + * application note, but the timing is critical (within 10ms + * after power-on of the device), and the device always starts + * up at address 0x28. + * + * How should we handle this? + */ return 0; }
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sat Jun 16 21:28:07 UTC 2018 Modified Files: src/sys/dev/i2c: ds1307.c Log Message: More cleanup to i2c autoconfiguration: - Get all of the drivers onto the new match quality constants. - Introduce a new helper function, iic_use_direct_match(), that has all of the logic for direct-config matching. If it returns true, the driver returns the match result (which may be 0). If it returns false, the driver does indirect-config matching. - iic_compat_match() now returns a weighted match quality; matches to lower-indexed "compatible" device property are more-specific matches, and return a better match quality accordingly. In addition to the above: - Add support for direct-config matching this driver based on "compatible" properties. - Address-only matching is now done based on the specific addresses the requested model supports. - "compatible" property can specify to the driver which model is to be used, so that using config "flags" directives aren't required in the direct-config case. XXX More changes coming that require re-factoring some other code. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 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.25 src/sys/dev/i2c/ds1307.c:1.26 --- src/sys/dev/i2c/ds1307.c:1.25 Sat Oct 28 04:53:55 2017 +++ src/sys/dev/i2c/ds1307.c Sat Jun 16 21:28:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ds1307.c,v 1.25 2017/10/28 04:53:55 riastradh Exp $ */ +/* $NetBSD: ds1307.c,v 1.26 2018/06/16 21:28:07 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.25 2017/10/28 04:53:55 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.26 2018/06/16 21:28:07 thorpej Exp $"); #include #include @@ -56,6 +56,8 @@ __KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1 #include "ioconf.h" struct dsrtc_model { + const char **dm_compats; + const i2c_addr_t *dm_valid_addrs; uint16_t dm_model; uint8_t dm_ch_reg; uint8_t dm_ch_value; @@ -74,8 +76,23 @@ struct dsrtc_model { #define DSRTC_FLAG_CLOCK_HOLD_REVERSED 0x20 }; +static const char *ds1307_compats[] = { "dallas,ds1307", "maxim,ds1307", NULL }; +static const char *ds1339_compats[] = { "dallas,ds1339", "maxim,ds1339", NULL }; +static const char *ds1340_compats[] = { "dallas,ds1340", "maxim,ds1340", NULL }; +static const char *ds1672_compats[] = { "dallas,ds1672", "maxim,ds1672", NULL }; +static const char *ds3231_compats[] = { "dallas,ds3231", "maxim,ds3231", NULL }; +static const char *ds3232_compats[] = { "dallas,ds3232", "maxim,ds3232", NULL }; + +/* XXX vendor prefix */ +static const char *mcp7940_compats[] = { "microchip,mcp7940", NULL }; + +static const i2c_addr_t ds1307_valid_addrs[] = { DS1307_ADDR, 0 }; +static const i2c_addr_t mcp7940_valid_addrs[] = { MCP7940_ADDR, 0 }; + static const struct dsrtc_model dsrtc_models[] = { { + .dm_compats = ds1307_compats, + .dm_valid_addrs = ds1307_valid_addrs, .dm_model = 1307, .dm_ch_reg = DS_SECONDS, .dm_ch_value = DS1307_SECONDS_CH, @@ -85,11 +102,15 @@ static const struct dsrtc_model dsrtc_mo .dm_nvram_size = DS1307_NVRAM_SIZE, .dm_flags = DSRTC_FLAG_BCD | DSRTC_FLAG_CLOCK_HOLD, }, { + .dm_compats = ds1339_compats, + .dm_valid_addrs = ds1307_valid_addrs, .dm_model = 1339, .dm_rtc_start = DS1339_RTC_START, .dm_rtc_size = DS1339_RTC_SIZE, .dm_flags = DSRTC_FLAG_BCD, }, { + .dm_compats = ds1340_compats, + .dm_valid_addrs = ds1307_valid_addrs, .dm_model = 1340, .dm_ch_reg = DS_SECONDS, .dm_ch_value = DS1340_SECONDS_EOSC, @@ -97,6 +118,8 @@ static const struct dsrtc_model dsrtc_mo .dm_rtc_size = DS1340_RTC_SIZE, .dm_flags = DSRTC_FLAG_BCD, }, { + .dm_compats = ds1672_compats, + .dm_valid_addrs = ds1307_valid_addrs, .dm_model = 1672, .dm_rtc_start = DS1672_RTC_START, .dm_rtc_size = DS1672_RTC_SIZE, @@ -104,6 +127,8 @@ static const struct dsrtc_model dsrtc_mo .dm_ch_value = DS1672_CONTROL_CH, .dm_flags = 0, }, { + .dm_compats = ds3231_compats, + .dm_valid_addrs = ds1307_valid_addrs, .dm_model = 3231, .dm_rtc_start = DS3232_RTC_START, .dm_rtc_size = DS3232_RTC_SIZE, @@ -114,6 +139,8 @@ static const struct dsrtc_model dsrtc_mo */ .dm_flags = DSRTC_FLAG_BCD | DSRTC_FLAG_TEMP, }, { + .dm_compats = ds3232_compats, + .dm_valid_addrs = ds1307_valid_addrs, .dm_model = 3232, .dm_rtc_start = DS3232_RTC_START, .dm_rtc_size = DS3232_RTC_SIZE, @@ -122,6 +149,8 @@ static const struct dsrtc_model dsrtc_mo .dm_flags = DSRTC_FLAG_BCD, }, { /* MCP7940 */ + .dm_compats = mcp7940_compats, + .dm_valid_addrs = mcp7940_valid_addrs, .dm_model = 7940, .dm_rtc_start = DS1307_RTC_START, .dm_rtc_size = DS1307_RTC_SIZE, @@
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Tue Jun 12 13:18:48 UTC 2018 Modified Files: src/sys/dev/i2c: gttwsi_core.c Log Message: When initiating a transfer, if a device isn't present, we won't get an ACK after sending the address. Check for this alternate state and suppress the error message when it occurs. Fixes PR kern/53356. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/gttwsi_core.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/gttwsi_core.c diff -u src/sys/dev/i2c/gttwsi_core.c:1.5 src/sys/dev/i2c/gttwsi_core.c:1.6 --- src/sys/dev/i2c/gttwsi_core.c:1.5 Mon May 7 15:03:19 2018 +++ src/sys/dev/i2c/gttwsi_core.c Tue Jun 12 13:18:48 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: gttwsi_core.c,v 1.5 2018/05/07 15:03:19 jmcneill Exp $ */ +/* $NetBSD: gttwsi_core.c,v 1.6 2018/06/12 13:18:48 thorpej Exp $ */ /* * Copyright (c) 2008 Eiji Kawauchi. * All rights reserved. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.5 2018/05/07 15:03:19 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.6 2018/06/12 13:18:48 thorpej Exp $"); #include "locators.h" #include @@ -91,7 +91,8 @@ static int gttwsi_initiate_xfer(void *v, static int gttwsi_read_byte(void *v, uint8_t *valp, int flags); static int gttwsi_write_byte(void *v, uint8_t val, int flags); -static int gttwsi_wait(struct gttwsi_softc *, uint32_t, uint32_t, int); +static int gttwsi_wait(struct gttwsi_softc *, uint32_t, uint32_t, + uint32_t, int); static inline uint32_t gttwsi_default_read_4(struct gttwsi_softc *sc, uint32_t reg) @@ -243,7 +244,7 @@ gttwsi_send_start(void *v, int flags) else expect = STAT_SCT; sc->sc_started = true; - return gttwsi_wait(sc, CONTROL_START, expect, flags); + return gttwsi_wait(sc, CONTROL_START, expect, 0, flags); } static int @@ -277,7 +278,7 @@ static int gttwsi_initiate_xfer(void *v, i2c_addr_t addr, int flags) { struct gttwsi_softc *sc = v; - uint32_t data, expect; + uint32_t data, expect, alt; int error, read; KASSERT(sc->sc_inuse); @@ -285,10 +286,13 @@ gttwsi_initiate_xfer(void *v, i2c_addr_t gttwsi_send_start(v, flags); read = (flags & I2C_F_READ) != 0; - if (read) + if (read) { expect = STAT_ARBT_AR; - else + alt= STAT_ARBT_ANR; + } else { expect = STAT_AWBT_AR; + alt= STAT_AWBT_ANR; + } /* * First byte contains whether this xfer is a read or write. @@ -301,23 +305,26 @@ gttwsi_initiate_xfer(void *v, i2c_addr_t */ data |= 0xf0 | ((addr & 0x300) >> 7); gttwsi_write_4(sc, TWSI_DATA, data); - error = gttwsi_wait(sc, 0, expect, flags); + error = gttwsi_wait(sc, 0, expect, alt, flags); if (error) return error; /* * The first address byte has been sent, now to send * the second one. */ - if (read) + if (read) { expect = STAT_SARBT_AR; - else + alt= STAT_SARBT_ANR; + } else { expect = STAT_SAWBT_AR; + alt= STAT_SAWBT_ANR; + } data = (uint8_t)addr; } else data |= (addr << 1); gttwsi_write_4(sc, TWSI_DATA, data); - return gttwsi_wait(sc, 0, expect, flags); + return gttwsi_wait(sc, 0, expect, alt, flags); } static int @@ -329,9 +336,9 @@ gttwsi_read_byte(void *v, uint8_t *valp, KASSERT(sc->sc_inuse); if (flags & I2C_F_LAST) - error = gttwsi_wait(sc, 0, STAT_MRRD_ANT, flags); + error = gttwsi_wait(sc, 0, STAT_MRRD_ANT, 0, flags); else - error = gttwsi_wait(sc, CONTROL_ACK, STAT_MRRD_AT, flags); + error = gttwsi_wait(sc, CONTROL_ACK, STAT_MRRD_AT, 0, flags); if (!error) *valp = gttwsi_read_4(sc, TWSI_DATA); if ((flags & (I2C_F_LAST | I2C_F_STOP)) == (I2C_F_LAST | I2C_F_STOP)) @@ -348,7 +355,7 @@ gttwsi_write_byte(void *v, uint8_t val, KASSERT(sc->sc_inuse); gttwsi_write_4(sc, TWSI_DATA, val); - error = gttwsi_wait(sc, 0, STAT_MTDB_AR, flags); + error = gttwsi_wait(sc, 0, STAT_MTDB_AR, 0, flags); if (flags & I2C_F_STOP) gttwsi_send_stop(sc, flags); return error; @@ -356,7 +363,7 @@ gttwsi_write_byte(void *v, uint8_t val, static int gttwsi_wait(struct gttwsi_softc *sc, uint32_t control, uint32_t expect, - int flags) + uint32_t alt, int flags) { uint32_t status; int timo, error = 0; @@ -389,8 +396,16 @@ gttwsi_wait(struct gttwsi_softc *sc, uin status = gttwsi_read_4(sc, TWSI_STATUS); if (status != expect) { - aprint_error_dev(sc->sc_dev, - "unexpected status 0x%x: expect 0x%x\n", status, expect); + /* + * In the case of probing for a device, we are expecting + * 2 different status codes: the ACK case (device exists), + * or the NACK case (device does not exist). We don't + * need to report an error in the later case. + */ + if (alt != 0 && status != alt) + aprint_error_dev(sc->sc_dev, + "unexpected status 0x%x: expect 0x%x\n", status, + expect); return EIO; } return error;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jun 7 13:30:49 UTC 2018 Modified Files: src/sys/dev/i2c: i2c.c i2cvar.h Log Message: Changes / enhancements to i2c indirect device auto-configuration: — iic_search() chooses a “probe strategy” based on the "i2c-indirect-probe-strategy” property on the “iic” instance. Valid values are "smbus-quick-write”, "smbus-receive-byte”, and “none”. If no value is specified, the default is "smbus-quick-write”. — If the "i2c-indirect-device-whitelist” exists on the “iic” instance, iic_search() will first check the driver name in the cfdata_t against this list, and only allow the match/probe to move forward if the cfdata_t driver name is in the list. This is primarily to accommodate the Intel integrated memory controller neutered-i2c-thing. — If the cfdata_t specifies a wildcard address, each address of the i2c bus will be consulted. If the cfdata_t contains a nailed-down address, then we limit the bus scan to that specific address. — We explicitly skip reserved / special i2c addresses, such as the General-Call address, etc. — We introduce the notion of a “match quality” for i2c drivers. From lowest-quality to highest-quality: matched by plausible address only, matched by plausible address and poking at the bus to see if the device looks reasonable, matched by direct-config “compatible” string, matched by direct-config “driver name” string. — If the “match quality” is merely “plausible address only”, then iic_search() will use the probe strategy selected above to see if a device responds to that address. To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 src/sys/dev/i2c/i2c.c cvs rdiff -u -r1.12 -r1.13 src/sys/dev/i2c/i2cvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/i2c.c diff -u src/sys/dev/i2c/i2c.c:1.60 src/sys/dev/i2c/i2c.c:1.61 --- src/sys/dev/i2c/i2c.c:1.60 Thu Jun 7 05:56:18 2018 +++ src/sys/dev/i2c/i2c.c Thu Jun 7 13:30:49 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.60 2018/06/07 05:56:18 thorpej Exp $ */ +/* $NetBSD: i2c.c,v 1.61 2018/06/07 13:30:49 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -40,7 +40,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.60 2018/06/07 05:56:18 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.61 2018/06/07 13:30:49 thorpej Exp $"); #include #include @@ -67,6 +67,7 @@ __KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.60 #endif struct iic_softc { + device_t sc_dev; i2c_tag_t sc_tag; int sc_type; device_t sc_devices[I2C_MAX_ADDR + 1]; @@ -127,21 +128,160 @@ iic_print(void *aux, const char *pnp) return UNCONF; } +static bool +iic_is_special_address(i2c_addr_t addr) +{ + + /* + * See: https://www.i2c-bus.org/addressing/ + */ + + /* General Call (read) / Start Byte (write) */ + if (addr == 0x00) + return (true); + + /* CBUS Addresses */ + if (addr == 0x01) + return (true); + + /* Reserved for Different Bus Formats */ + if (addr == 0x02) + return (true); + + /* Reserved for future purposes */ + if (addr == 0x03) + return (true); + + /* High Speed Master Code */ + if ((addr & 0x7c) == 0x04) + return (true); + + /* 10-bit Slave Addressing prefix */ + if ((addr & 0x7c) == 0x78) + return (true); + + /* Reserved for future purposes */ + if ((addr & 0x7c) == 0x7c) + return (true); + + return (false); +} + +static int +iic_probe_none(struct iic_softc *sc, + const struct i2c_attach_args *ia, int flags) +{ + + return (0); +} + +static int +iic_probe_smbus_quick_write(struct iic_softc *sc, + const struct i2c_attach_args *ia, int flags) +{ + int error; + + if ((error = iic_acquire_bus(ia->ia_tag, flags)) == 0) { + error = iic_smbus_quick_write(ia->ia_tag, ia->ia_addr, flags); + } + (void) iic_release_bus(ia->ia_tag, flags); + + return (error); +} + +static int +iic_probe_smbus_receive_byte(struct iic_softc *sc, + const struct i2c_attach_args *ia, int flags) +{ + int error; + + if ((error = iic_acquire_bus(ia->ia_tag, flags)) == 0) { + uint8_t dummy; + + error = iic_smbus_receive_byte(ia->ia_tag, ia->ia_addr, + , flags); + } + (void) iic_release_bus(ia->ia_tag, flags); + + return (error); +} + +static bool +iic_indirect_driver_is_whitelisted(struct iic_softc *sc, cfdata_t cf) +{ + prop_object_iterator_t iter; + prop_array_t whitelist; + prop_string_t pstr; + prop_type_t ptype; + bool rv = false; + + whitelist = prop_dictionary_get(device_properties(sc->sc_dev), + I2C_PROP_INDIRECT_DEVICE_WHITELIST); + if (whitelist == NULL) { + /* No whitelist -> everything allowed */ + return (true); + } + + if ((ptype = prop_object_type(whitelist)) != PROP_TYPE_ARRAY) { + aprint_error_dev(sc->sc_dev, + "invalid property type (%d) for '%s'; must be array (%d)\n", + ptype, I2C_PROP_INDIRECT_DEVICE_WHITELIST, PROP_TYPE_ARRAY); + return (false); + } + + iter =
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jun 7 05:56:18 UTC 2018 Modified Files: src/sys/dev/i2c: i2c.c i2cvar.h Log Message: Back out unintended commits. To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 src/sys/dev/i2c/i2c.c cvs rdiff -u -r1.11 -r1.12 src/sys/dev/i2c/i2cvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/i2c.c diff -u src/sys/dev/i2c/i2c.c:1.59 src/sys/dev/i2c/i2c.c:1.60 --- src/sys/dev/i2c/i2c.c:1.59 Thu Jun 7 05:54:23 2018 +++ src/sys/dev/i2c/i2c.c Thu Jun 7 05:56:18 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.59 2018/06/07 05:54:23 thorpej Exp $ */ +/* $NetBSD: i2c.c,v 1.60 2018/06/07 05:56:18 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -40,7 +40,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.59 2018/06/07 05:54:23 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.60 2018/06/07 05:56:18 thorpej Exp $"); #include #include @@ -67,7 +67,6 @@ __KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.59 #endif struct iic_softc { - device_t sc_dev; i2c_tag_t sc_tag; int sc_type; device_t sc_devices[I2C_MAX_ADDR + 1]; @@ -128,160 +127,21 @@ iic_print(void *aux, const char *pnp) return UNCONF; } -static bool -iic_is_special_address(i2c_addr_t addr) -{ - - /* - * See: https://www.i2c-bus.org/addressing/ - */ - - /* General Call (read) / Start Byte (write) */ - if (addr == 0x00) - return (true); - - /* CBUS Addresses */ - if (addr == 0x01) - return (true); - - /* Reserved for Different Bus Formats */ - if (addr == 0x02) - return (true); - - /* Reserved for future purposes */ - if (addr == 0x03) - return (true); - - /* High Speed Master Code */ - if ((addr & 0x7c) == 0x04) - return (true); - - /* 10-bit Slave Addressing prefix */ - if ((addr & 0x7c) == 0x78) - return (true); - - /* Reserved for future purposes */ - if ((addr & 0x7c) == 0x7c) - return (true); - - return (false); -} - -static int -iic_probe_none(struct iic_softc *sc, - const struct i2c_attach_args *ia, int flags) -{ - - return (0); -} - -static int -iic_probe_smbus_quick_write(struct iic_softc *sc, - const struct i2c_attach_args *ia, int flags) -{ - int error; - - if ((error = iic_acquire_bus(ia->ia_tag, flags)) == 0) { - error = iic_smbus_quick_write(ia->ia_tag, ia->ia_addr, flags); - } - (void) iic_release_bus(ia->ia_tag, flags); - - return (error); -} - -static int -iic_probe_smbus_receive_byte(struct iic_softc *sc, - const struct i2c_attach_args *ia, int flags) -{ - int error; - - if ((error = iic_acquire_bus(ia->ia_tag, flags)) == 0) { - uint8_t dummy; - - error = iic_smbus_receive_byte(ia->ia_tag, ia->ia_addr, - , flags); - } - (void) iic_release_bus(ia->ia_tag, flags); - - return (error); -} - -static bool -iic_indirect_driver_is_whitelisted(struct iic_softc *sc, cfdata_t cf) -{ - prop_object_iterator_t iter; - prop_array_t whitelist; - prop_string_t pstr; - prop_type_t ptype; - bool rv = false; - - whitelist = prop_dictionary_get(device_properties(sc->sc_dev), - I2C_PROP_INDIRECT_DEVICE_WHITELIST); - if (whitelist == NULL) { - /* No whitelist -> everything allowed */ - return (true); - } - - if ((ptype = prop_object_type(whitelist)) != PROP_TYPE_ARRAY) { - aprint_error_dev(sc->sc_dev, - "invalid property type (%d) for '%s'; must be array (%d)\n", - ptype, I2C_PROP_INDIRECT_DEVICE_WHITELIST, PROP_TYPE_ARRAY); - return (false); - } - - iter = prop_array_iterator(whitelist); - while ((pstr = prop_object_iterator_next(iter)) != NULL) { - if (prop_string_equals_cstring(pstr, cf->cf_name)) { - rv = true; - break; - } - } - prop_object_iterator_release(iter); - - return (rv); -} - static int iic_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux) { struct iic_softc *sc = device_private(parent); struct i2c_attach_args ia; - int (*probe_func)(struct iic_softc *, - const struct i2c_attach_args *, int); - prop_string_t pstr; - i2c_addr_t first_addr, last_addr; /* - * Before we do any more work, consult the allowed-driver - * white-list for this bus (if any). + * I2C doesn't have any regular probing capability. If we + * encounter a cfdata with a wild-carded address or a wild- + * carded parent spec, we skip them because they can only + * be used for direct-coniguration. */ - if (iic_indirect_driver_is_whitelisted(sc, cf) == false) - return (0); - - /* default to "quick write". */ - probe_func = iic_probe_smbus_quick_write; - - pstr = prop_dictionary_get(device_properties(sc->sc_dev), - I2C_PROP_INDIRECT_PROBE_STRATEGY); - if (pstr == NULL) { - /* Use the default. */ - } else if (prop_string_equals_cstring(pstr, - I2C_PROBE_STRATEGY_QUICK_WRITE)) { - probe_func = iic_probe_smbus_quick_write; - } else if (prop_string_equals_cstring(pstr, - I2C_PROBE_STRATEGY_RECEIVE_BYTE)) { - probe_func =
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Thu Jun 7 05:54:24 UTC 2018 Modified Files: src/sys/dev/i2c: i2c.c i2cvar.h tsl256x.c Log Message: Adjust come defaults: - Initial gain -> 16x - auto_gain -> true To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 src/sys/dev/i2c/i2c.c cvs rdiff -u -r1.10 -r1.11 src/sys/dev/i2c/i2cvar.h cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/tsl256x.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/i2c.c diff -u src/sys/dev/i2c/i2c.c:1.58 src/sys/dev/i2c/i2c.c:1.59 --- src/sys/dev/i2c/i2c.c:1.58 Tue May 15 02:02:18 2018 +++ src/sys/dev/i2c/i2c.c Thu Jun 7 05:54:23 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.58 2018/05/15 02:02:18 thorpej Exp $ */ +/* $NetBSD: i2c.c,v 1.59 2018/06/07 05:54:23 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -40,7 +40,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.58 2018/05/15 02:02:18 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.59 2018/06/07 05:54:23 thorpej Exp $"); #include #include @@ -67,6 +67,7 @@ __KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.58 #endif struct iic_softc { + device_t sc_dev; i2c_tag_t sc_tag; int sc_type; device_t sc_devices[I2C_MAX_ADDR + 1]; @@ -127,21 +128,160 @@ iic_print(void *aux, const char *pnp) return UNCONF; } +static bool +iic_is_special_address(i2c_addr_t addr) +{ + + /* + * See: https://www.i2c-bus.org/addressing/ + */ + + /* General Call (read) / Start Byte (write) */ + if (addr == 0x00) + return (true); + + /* CBUS Addresses */ + if (addr == 0x01) + return (true); + + /* Reserved for Different Bus Formats */ + if (addr == 0x02) + return (true); + + /* Reserved for future purposes */ + if (addr == 0x03) + return (true); + + /* High Speed Master Code */ + if ((addr & 0x7c) == 0x04) + return (true); + + /* 10-bit Slave Addressing prefix */ + if ((addr & 0x7c) == 0x78) + return (true); + + /* Reserved for future purposes */ + if ((addr & 0x7c) == 0x7c) + return (true); + + return (false); +} + +static int +iic_probe_none(struct iic_softc *sc, + const struct i2c_attach_args *ia, int flags) +{ + + return (0); +} + +static int +iic_probe_smbus_quick_write(struct iic_softc *sc, + const struct i2c_attach_args *ia, int flags) +{ + int error; + + if ((error = iic_acquire_bus(ia->ia_tag, flags)) == 0) { + error = iic_smbus_quick_write(ia->ia_tag, ia->ia_addr, flags); + } + (void) iic_release_bus(ia->ia_tag, flags); + + return (error); +} + +static int +iic_probe_smbus_receive_byte(struct iic_softc *sc, + const struct i2c_attach_args *ia, int flags) +{ + int error; + + if ((error = iic_acquire_bus(ia->ia_tag, flags)) == 0) { + uint8_t dummy; + + error = iic_smbus_receive_byte(ia->ia_tag, ia->ia_addr, + , flags); + } + (void) iic_release_bus(ia->ia_tag, flags); + + return (error); +} + +static bool +iic_indirect_driver_is_whitelisted(struct iic_softc *sc, cfdata_t cf) +{ + prop_object_iterator_t iter; + prop_array_t whitelist; + prop_string_t pstr; + prop_type_t ptype; + bool rv = false; + + whitelist = prop_dictionary_get(device_properties(sc->sc_dev), + I2C_PROP_INDIRECT_DEVICE_WHITELIST); + if (whitelist == NULL) { + /* No whitelist -> everything allowed */ + return (true); + } + + if ((ptype = prop_object_type(whitelist)) != PROP_TYPE_ARRAY) { + aprint_error_dev(sc->sc_dev, + "invalid property type (%d) for '%s'; must be array (%d)\n", + ptype, I2C_PROP_INDIRECT_DEVICE_WHITELIST, PROP_TYPE_ARRAY); + return (false); + } + + iter = prop_array_iterator(whitelist); + while ((pstr = prop_object_iterator_next(iter)) != NULL) { + if (prop_string_equals_cstring(pstr, cf->cf_name)) { + rv = true; + break; + } + } + prop_object_iterator_release(iter); + + return (rv); +} + static int iic_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux) { struct iic_softc *sc = device_private(parent); struct i2c_attach_args ia; + int (*probe_func)(struct iic_softc *, + const struct i2c_attach_args *, int); + prop_string_t pstr; + i2c_addr_t first_addr, last_addr; /* - * I2C doesn't have any regular probing capability. If we - * encounter a cfdata with a wild-carded address or a wild- - * carded parent spec, we skip them because they can only - * be used for direct-coniguration. + * Before we do any more work, consult the allowed-driver + * white-list for this bus (if any). */ - if (cf->cf_loc[IICCF_ADDR] == IICCF_ADDR_DEFAULT || - cf->cf_pspec->cfp_unit == DVUNIT_ANY) - return 0; + if (iic_indirect_driver_is_whitelisted(sc, cf) == false) + return (0); + + /* default to "quick write". */ + probe_func = iic_probe_smbus_quick_write; + + pstr = prop_dictionary_get(device_properties(sc->sc_dev), + I2C_PROP_INDIRECT_PROBE_STRATEGY); + if (pstr == NULL) { + /* Use the default. */ + } else if (prop_string_equals_cstring(pstr,
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Sun May 27 14:03:56 UTC 2018 Modified Files: src/sys/dev/i2c: tsl256x.c Log Message: Update the compat strings to match what Linux uses, per jmcneill@. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/tsl256x.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/tsl256x.c diff -u src/sys/dev/i2c/tsl256x.c:1.1 src/sys/dev/i2c/tsl256x.c:1.2 --- src/sys/dev/i2c/tsl256x.c:1.1 Sun May 27 05:31:20 2018 +++ src/sys/dev/i2c/tsl256x.c Sun May 27 14:03:56 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: tsl256x.c,v 1.1 2018/05/27 05:31:20 thorpej Exp $ */ +/* $NetBSD: tsl256x.c,v 1.2 2018/05/27 14:03:56 thorpej Exp $ */ /*- * Copyright (c) 2018 Jason R. Thorpe @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tsl256x.c,v 1.1 2018/05/27 05:31:20 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tsl256x.c,v 1.2 2018/05/27 14:03:56 thorpej Exp $"); #include #include @@ -79,9 +79,8 @@ CFATTACH_DECL_NEW(tsllux, sizeof(struct tsllux_match, tsllux_attach, NULL, NULL); static const char *tsllux_compats[] = { - "taos,tsl2560", - "taos,tsl2561", - "taos,tsl256x", + "amstaos,tsl2560", + "amstaos,tsl2561", NULL };
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sat May 26 14:39:20 UTC 2018 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: Add battery voltage, charge current, and discharge current sensors for AXP803. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 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.9 src/sys/dev/i2c/axppmic.c:1.10 --- src/sys/dev/i2c/axppmic.c:1.9 Sun May 13 22:58:58 2018 +++ src/sys/dev/i2c/axppmic.c Sat May 26 14:39:20 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.9 2018/05/13 22:58:58 jmcneill Exp $ */ +/* $NetBSD: axppmic.c,v 1.10 2018/05/26 14:39:20 jmcneill Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill@@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.9 2018/05/13 22:58:58 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.10 2018/05/26 14:39:20 jmcneill Exp $"); #include #include @@ -47,6 +47,7 @@ __KERNEL_RCSID(0, "$NetBSD: axppmic.c,v #define AXP_POWER_SOURCE_REG 0x00 #define AXP_POWER_SOURCE_ACIN_PRESENT __BIT(7) #define AXP_POWER_SOURCE_VBUS_PRESENT __BIT(5) +#define AXP_POWER_SOURCE_CHARGE_DIRECTION __BIT(2) #define AXP_POWER_MODE_REG 0x01 #define AXP_POWER_MODE_BATT_VALID __BIT(4) @@ -63,8 +64,21 @@ __KERNEL_RCSID(0, "$NetBSD: axppmic.c,v #define AXP_IRQ1_VBUS_LOWER __BIT(2) #define AXP_IRQ_STATUS_REG(n) (0x48 + (n) - 1) +#define AXP_BATSENSE_HI_REG 0x78 +#define AXP_BATSENSE_LO_REG 0x79 + +#define AXP_BATTCHG_HI_REG 0x7a +#define AXP_BATTCHG_LO_REG 0x7b + +#define AXP_BATTDISCHG_HI_REG 0x7c +#define AXP_BATTDISCHG_LO_REG 0x7d + +#define AXP_ADC_RAW(_hi, _lo) \ + (((u_int)(_hi) << 4) | ((lo) & 0xf)) + #define AXP_FUEL_GAUGE_CTRL_REG 0xb8 #define AXP_FUEL_GAUGE_CTRL_EN __BIT(7) + #define AXP_BATT_CAP_REG 0xb9 #define AXP_BATT_CAP_VALID __BIT(7) #define AXP_BATT_CAP_PERCENT __BITS(6,0) @@ -198,6 +212,11 @@ struct axppmic_config { struct axppmic_irq battirq; struct axppmic_irq chargeirq; struct axppmic_irq chargestirq; + u_int batsense_step; /* uV */ + u_int charge_step; /* uA */ + u_int discharge_step; /* uA */ + u_int maxcap_step; /* uAh */ + u_int coulomb_step; /* uAh */ }; enum axppmic_sensor { @@ -206,7 +225,10 @@ enum axppmic_sensor { AXP_SENSOR_BATT_PRESENT, AXP_SENSOR_BATT_CHARGING, AXP_SENSOR_BATT_CHARGE_STATE, - AXP_SENSOR_BATT_CAPACITY, + AXP_SENSOR_BATT_VOLTAGE, + AXP_SENSOR_BATT_CHARGE_CURRENT, + AXP_SENSOR_BATT_DISCHARGE_CURRENT, + AXP_SENSOR_BATT_CAPACITY_PERCENT, AXP_NSENSORS }; @@ -249,6 +271,9 @@ static const struct axppmic_config axp80 .irq_regs = 6, .has_battery = true, .has_fuel_gauge = true, + .batsense_step = 1100, + .charge_step = 1000, + .discharge_step = 1000, .poklirq = AXPPMIC_IRQ(5, __BIT(3)), .acinirq = AXPPMIC_IRQ(1, __BITS(6,5)), .vbusirq = AXPPMIC_IRQ(1, __BITS(3,2)), @@ -380,11 +405,16 @@ static void axppmic_sensor_update(struct sysmon_envsys *sme, envsys_data_t *e) { struct axppmic_softc *sc = sme->sme_cookie; + const struct axppmic_config *c = sc->sc_conf; const int flags = I2C_F_POLL; - uint8_t val; + uint8_t val, lo, hi; e->state = ENVSYS_SINVALID; + const bool battery_present = + sc->sc_sensor[AXP_SENSOR_BATT_PRESENT].state == ENVSYS_SVALID && + sc->sc_sensor[AXP_SENSOR_BATT_PRESENT].value_cur == 1; + switch (e->private) { case AXP_SENSOR_ACIN_PRESENT: if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_SOURCE_REG, , flags) == 0) { @@ -413,9 +443,7 @@ axppmic_sensor_update(struct sysmon_envs } break; case AXP_SENSOR_BATT_CHARGE_STATE: - if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_MODE_REG, , flags) == 0 && - (val & AXP_POWER_MODE_BATT_VALID) != 0 && - (val & AXP_POWER_MODE_BATT_PRESENT) != 0 && + if (battery_present && axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATT_CAP_REG, , flags) == 0 && (val & AXP_BATT_CAP_VALID) != 0) { const u_int batt_val = __SHIFTOUT(val, AXP_BATT_CAP_PERCENT); @@ -431,16 +459,42 @@ axppmic_sensor_update(struct sysmon_envs } } break; - case AXP_SENSOR_BATT_CAPACITY: - if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_MODE_REG, , flags) == 0 && - (val & AXP_POWER_MODE_BATT_VALID) != 0 && - (val & AXP_POWER_MODE_BATT_PRESENT) != 0 && + case AXP_SENSOR_BATT_CAPACITY_PERCENT: + if (battery_present && axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATT_CAP_REG, , flags) == 0 && (val & AXP_BATT_CAP_VALID) != 0) { e->state = ENVSYS_SVALID; e->value_cur = __SHIFTOUT(val, AXP_BATT_CAP_PERCENT); } break; + case AXP_SENSOR_BATT_VOLTAGE: + if (battery_present && + axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATSENSE_HI_REG, , flags) == 0 && + axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATSENSE_LO_REG, , flags) == 0) { + e->state =
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Tue May 15 02:02:18 UTC 2018 Modified Files: src/sys/dev/i2c: i2c.c Log Message: Fix a problem reported by jmcneill@ where by a system with multuple i2c busses would end up with "ghost" device instances on the second bus. This issue was previously masked on ARM systems by the empty-child-devices array issue fixed recently (that effectively blocked all indirect config of i2c busses on those systems). To fix this problem, we require that indirectly-configured devices have to fully specify their parent spec and address, e.g.: foo* at iic0 addr 0x55 NOT foo* at iic? addr ? or even: foo* at iic? addr 0x55 This is needed because of how indirect configuration works... attach directives in the kernel config file are enumerated, calling the bus's search routine, which in the case of i2c, enumerates all i2c addresses and calls the match routine for each address. Because we can't always reliably probe for i2c devices, we ended up with erroneous matches. Direct configuration of i2c is still allowed to use wildcarded parent specs and locators. To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 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.57 src/sys/dev/i2c/i2c.c:1.58 --- src/sys/dev/i2c/i2c.c:1.57 Sun Dec 10 16:53:32 2017 +++ src/sys/dev/i2c/i2c.c Tue May 15 02:02:18 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.57 2017/12/10 16:53:32 bouyer Exp $ */ +/* $NetBSD: i2c.c,v 1.58 2018/05/15 02:02:18 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -40,7 +40,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.57 2017/12/10 16:53:32 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.58 2018/05/15 02:02:18 thorpej Exp $"); #include #include @@ -121,7 +121,7 @@ iic_print(void *aux, const char *pnp) { struct i2c_attach_args *ia = aux; - if (ia->ia_addr != (i2c_addr_t)-1) + if (ia->ia_addr != (i2c_addr_t)IICCF_ADDR_DEFAULT) aprint_normal(" addr 0x%x", ia->ia_addr); return UNCONF; @@ -133,6 +133,16 @@ iic_search(device_t parent, cfdata_t cf, struct iic_softc *sc = device_private(parent); struct i2c_attach_args ia; + /* + * I2C doesn't have any regular probing capability. If we + * encounter a cfdata with a wild-carded address or a wild- + * carded parent spec, we skip them because they can only + * be used for direct-coniguration. + */ + if (cf->cf_loc[IICCF_ADDR] == IICCF_ADDR_DEFAULT || + cf->cf_pspec->cfp_unit == DVUNIT_ANY) + return 0; + ia.ia_tag = sc->sc_tag; ia.ia_size = cf->cf_loc[IICCF_SIZE]; ia.ia_type = sc->sc_type; @@ -146,8 +156,7 @@ iic_search(device_t parent, cfdata_t cf, if (sc->sc_devices[ia.ia_addr] != NULL) continue; - if (cf->cf_loc[IICCF_ADDR] != -1 && - cf->cf_loc[IICCF_ADDR] != ia.ia_addr) + if (cf->cf_loc[IICCF_ADDR] != ia.ia_addr) continue; if (config_match(parent, cf, ) > 0)
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun May 13 22:58:58 UTC 2018 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: Battery charge state is invalid until we refresh the first time To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 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.8 src/sys/dev/i2c/axppmic.c:1.9 --- src/sys/dev/i2c/axppmic.c:1.8 Sun May 13 11:13:02 2018 +++ src/sys/dev/i2c/axppmic.c Sun May 13 22:58:58 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.8 2018/05/13 11:13:02 jmcneill Exp $ */ +/* $NetBSD: axppmic.c,v 1.9 2018/05/13 22:58:58 jmcneill Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill@@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.8 2018/05/13 11:13:02 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.9 2018/05/13 22:58:58 jmcneill Exp $"); #include #include @@ -554,7 +554,7 @@ axppmic_attach_battery(struct axppmic_so e->private = AXP_SENSOR_BATT_CHARGE_STATE; e->units = ENVSYS_BATTERY_CAPACITY; e->flags = ENVSYS_FMONSTCHANGED; - e->state = ENVSYS_SVALID; + e->state = ENVSYS_SINVALID; e->value_cur = ENVSYS_BATTERY_CAPACITY_NORMAL; strlcpy(e->desc, "charge state", sizeof(e->desc)); sysmon_envsys_sensor_attach(sc->sc_sme, e);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun May 13 11:13:02 UTC 2018 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: Use IRQs to update status whenever we can. Reduces the amount of work that needs to be done whenever sysmon_envsys refreshes sensors. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 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.7 src/sys/dev/i2c/axppmic.c:1.8 --- src/sys/dev/i2c/axppmic.c:1.7 Sat May 12 01:31:07 2018 +++ src/sys/dev/i2c/axppmic.c Sun May 13 11:13:02 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.7 2018/05/12 01:31:07 jmcneill Exp $ */ +/* $NetBSD: axppmic.c,v 1.8 2018/05/13 11:13:02 jmcneill Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill@@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.7 2018/05/12 01:31:07 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.8 2018/05/13 11:13:02 jmcneill Exp $"); #include #include @@ -177,6 +177,14 @@ static const struct axppmic_ctrl axp805_ 0x11, __BIT(6), 0x26, __BITS(4,0)), }; +struct axppmic_irq { + u_int reg; + uint8_t mask; +}; + +#define AXPPMIC_IRQ(_reg, _mask) \ + { .reg = (_reg), .mask = (_mask) } + struct axppmic_config { const char *name; const struct axppmic_ctrl *controls; @@ -184,8 +192,12 @@ struct axppmic_config { u_int irq_regs; bool has_battery; bool has_fuel_gauge; - u_int poklirq_reg; - uint8_t poklirq_mask; + struct axppmic_irq poklirq; + struct axppmic_irq acinirq; + struct axppmic_irq vbusirq; + struct axppmic_irq battirq; + struct axppmic_irq chargeirq; + struct axppmic_irq chargestirq; }; enum axppmic_sensor { @@ -204,12 +216,7 @@ struct axppmic_softc { i2c_addr_t sc_addr; int sc_phandle; - bool sc_has_battery; - bool sc_has_fuel_gauge; - u_int sc_poklirq_reg; - uint8_t sc_poklirq_mask; - - u_int sc_irq_regs; + const struct axppmic_config *sc_conf; struct sysmon_pswitch sc_smpsw; @@ -242,8 +249,12 @@ static const struct axppmic_config axp80 .irq_regs = 6, .has_battery = true, .has_fuel_gauge = true, - .poklirq_reg = 5, - .poklirq_mask = __BIT(3), + .poklirq = AXPPMIC_IRQ(5, __BIT(3)), + .acinirq = AXPPMIC_IRQ(1, __BITS(6,5)), + .vbusirq = AXPPMIC_IRQ(1, __BITS(3,2)), + .battirq = AXPPMIC_IRQ(2, __BITS(7,6)), + .chargeirq = AXPPMIC_IRQ(2, __BITS(3,2)), + .chargestirq = AXPPMIC_IRQ(4, __BITS(1,0)), }; static const struct axppmic_config axp805_config = { @@ -251,8 +262,7 @@ static const struct axppmic_config axp80 .controls = axp805_ctrls, .ncontrols = __arraycount(axp805_ctrls), .irq_regs = 2, - .poklirq_reg = 2, - .poklirq_mask = __BIT(0), + .poklirq = AXPPMIC_IRQ(2, __BIT(0)), }; static const struct of_compat_data compat_data[] = { @@ -366,31 +376,8 @@ axppmic_task_shut(void *priv) sysmon_pswitch_event(>sc_smpsw, PSWITCH_EVENT_PRESSED); } -static int -axppmic_intr(void *priv) -{ - struct axppmic_softc *sc = priv; - const int flags = I2C_F_POLL; - u_int n; - uint8_t stat; - - iic_acquire_bus(sc->sc_i2c, flags); - for (n = 1; n <= sc->sc_irq_regs; n++) { - if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_IRQ_STATUS_REG(n), , flags) == 0) { - if (n == sc->sc_poklirq_reg && (stat & sc->sc_poklirq_mask) != 0) -sysmon_task_queue_sched(0, axppmic_task_shut, sc); - - axppmic_write(sc->sc_i2c, sc->sc_addr, - AXP_IRQ_STATUS_REG(sc->sc_poklirq_reg), stat, flags); - } - } - iic_release_bus(sc->sc_i2c, flags); - - return 1; -} - static void -axppmic_sensor_refresh(struct sysmon_envsys *sme, envsys_data_t *e) +axppmic_sensor_update(struct sysmon_envsys *sme, envsys_data_t *e) { struct axppmic_softc *sc = sme->sme_cookie; const int flags = I2C_F_POLL; @@ -398,7 +385,6 @@ axppmic_sensor_refresh(struct sysmon_env e->state = ENVSYS_SINVALID; - iic_acquire_bus(sc->sc_i2c, flags); switch (e->private) { case AXP_SENSOR_ACIN_PRESENT: if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_SOURCE_REG, , flags) == 0) { @@ -456,7 +442,65 @@ axppmic_sensor_refresh(struct sysmon_env } break; } +} + +static void +axppmic_sensor_refresh(struct sysmon_envsys *sme, envsys_data_t *e) +{ + struct axppmic_softc *sc = sme->sme_cookie; + const int flags = I2C_F_POLL; + + switch (e->private) { + case AXP_SENSOR_BATT_CAPACITY: + /* Always update battery capacity (fuel gauge) */ + iic_acquire_bus(sc->sc_i2c, flags); + axppmic_sensor_update(sme, e); + iic_release_bus(sc->sc_i2c, flags); + break; + default: + /* Refresh if the sensor is not in valid state */ + if (e->state != ENVSYS_SVALID) { + iic_acquire_bus(sc->sc_i2c, flags); + axppmic_sensor_update(sme, e); + iic_release_bus(sc->sc_i2c, flags); + } + break; + } +} + +static int +axppmic_intr(void *priv) +{ + struct axppmic_softc *sc = priv; + const struct axppmic_config *c =
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sat May 12 01:31:08 UTC 2018 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: Trigger shutdown on POKLIRQ instead of POKSIRQ. POKSIRQ is triggered if POK remains low for less than IRQLEVEL. This makes it way too easy to accidentally trigger shutdown. POKLIRQ is triggered if POK hold time is greater than IRQLEVEL, which is much more reasonable for this use case. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 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.6 src/sys/dev/i2c/axppmic.c:1.7 --- src/sys/dev/i2c/axppmic.c:1.6 Thu May 10 23:57:31 2018 +++ src/sys/dev/i2c/axppmic.c Sat May 12 01:31:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.6 2018/05/10 23:57:31 jmcneill Exp $ */ +/* $NetBSD: axppmic.c,v 1.7 2018/05/12 01:31:07 jmcneill Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill@@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.6 2018/05/10 23:57:31 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.7 2018/05/12 01:31:07 jmcneill Exp $"); #include #include @@ -61,8 +61,6 @@ __KERNEL_RCSID(0, "$NetBSD: axppmic.c,v #define AXP_IRQ1_ACIN_LOWER __BIT(5) #define AXP_IRQ1_VBUS_RAISE __BIT(3) #define AXP_IRQ1_VBUS_LOWER __BIT(2) -#define AXP_IRQ2_POKSIRQ __BIT(1) -#define AXP_IRQ2_ #define AXP_IRQ_STATUS_REG(n) (0x48 + (n) - 1) #define AXP_FUEL_GAUGE_CTRL_REG 0xb8 @@ -186,8 +184,8 @@ struct axppmic_config { u_int irq_regs; bool has_battery; bool has_fuel_gauge; - u_int poksirq_reg; - uint8_t poksirq_mask; + u_int poklirq_reg; + uint8_t poklirq_mask; }; enum axppmic_sensor { @@ -208,8 +206,8 @@ struct axppmic_softc { bool sc_has_battery; bool sc_has_fuel_gauge; - u_int sc_poksirq_reg; - uint8_t sc_poksirq_mask; + u_int sc_poklirq_reg; + uint8_t sc_poklirq_mask; u_int sc_irq_regs; @@ -244,8 +242,8 @@ static const struct axppmic_config axp80 .irq_regs = 6, .has_battery = true, .has_fuel_gauge = true, - .poksirq_reg = 5, - .poksirq_mask = __BIT(4), + .poklirq_reg = 5, + .poklirq_mask = __BIT(3), }; static const struct axppmic_config axp805_config = { @@ -253,8 +251,8 @@ static const struct axppmic_config axp80 .controls = axp805_ctrls, .ncontrols = __arraycount(axp805_ctrls), .irq_regs = 2, - .poksirq_reg = 2, - .poksirq_mask = __BIT(1), + .poklirq_reg = 2, + .poklirq_mask = __BIT(0), }; static const struct of_compat_data compat_data[] = { @@ -379,11 +377,11 @@ axppmic_intr(void *priv) iic_acquire_bus(sc->sc_i2c, flags); for (n = 1; n <= sc->sc_irq_regs; n++) { if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_IRQ_STATUS_REG(n), , flags) == 0) { - if (n == sc->sc_poksirq_reg && (stat & sc->sc_poksirq_mask) != 0) + if (n == sc->sc_poklirq_reg && (stat & sc->sc_poklirq_mask) != 0) sysmon_task_queue_sched(0, axppmic_task_shut, sc); axppmic_write(sc->sc_i2c, sc->sc_addr, - AXP_IRQ_STATUS_REG(sc->sc_poksirq_reg), stat, flags); + AXP_IRQ_STATUS_REG(sc->sc_poklirq_reg), stat, flags); } } iic_release_bus(sc->sc_i2c, flags); @@ -582,8 +580,8 @@ axppmic_attach(device_t parent, device_t sc->sc_has_battery = c->has_battery; sc->sc_has_fuel_gauge = c->has_fuel_gauge; sc->sc_irq_regs = c->irq_regs; - sc->sc_poksirq_reg = c->poksirq_reg; - sc->sc_poksirq_mask = c->poksirq_mask; + sc->sc_poklirq_reg = c->poklirq_reg; + sc->sc_poklirq_mask = c->poklirq_mask; aprint_naive("\n"); aprint_normal(": %s\n", c->name); @@ -595,8 +593,8 @@ axppmic_attach(device_t parent, device_t iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); for (i = 1; i <= c->irq_regs; i++) { irq_mask = 0; - if (i == c->poksirq_reg) - irq_mask |= c->poksirq_mask; + if (i == c->poklirq_reg) + irq_mask |= c->poklirq_mask; axppmic_write(sc->sc_i2c, sc->sc_addr, AXP_IRQ_ENABLE_REG(i), irq_mask, I2C_F_POLL); } iic_release_bus(sc->sc_i2c, I2C_F_POLL);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Thu May 10 23:57:31 UTC 2018 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: Fix off by one in axp803 dcdc2/3/4 definitions To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 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.5 src/sys/dev/i2c/axppmic.c:1.6 --- src/sys/dev/i2c/axppmic.c:1.5 Sun May 6 14:25:48 2018 +++ src/sys/dev/i2c/axppmic.c Thu May 10 23:57:31 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.5 2018/05/06 14:25:48 jmcneill Exp $ */ +/* $NetBSD: axppmic.c,v 1.6 2018/05/10 23:57:31 jmcneill Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill@@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.5 2018/05/06 14:25:48 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.6 2018/05/10 23:57:31 jmcneill Exp $"); #include #include @@ -128,11 +128,11 @@ static const struct axppmic_ctrl axp803_ 0x13, __BIT(3), 0x1d, __BITS(3,0)), AXP_CTRL("dcdc1", 1600, 3400, 100, 0x10, __BIT(0), 0x20, __BITS(4,0)), - AXP_CTRL2("dcdc2", 500, 1300, 10, 71, 20, 5, + AXP_CTRL2("dcdc2", 500, 1300, 10, 70, 20, 5, 0x10, __BIT(1), 0x21, __BITS(6,0)), - AXP_CTRL2("dcdc3", 500, 1300, 10, 71, 20, 5, + AXP_CTRL2("dcdc3", 500, 1300, 10, 70, 20, 5, 0x10, __BIT(2), 0x22, __BITS(6,0)), - AXP_CTRL2("dcdc4", 500, 1300, 10, 71, 20, 5, + AXP_CTRL2("dcdc4", 500, 1300, 10, 70, 20, 5, 0x10, __BIT(3), 0x23, __BITS(6,0)), AXP_CTRL2("dcdc5", 800, 1840, 10, 33, 20, 36, 0x10, __BIT(4), 0x24, __BITS(6,0)),
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: thorpej Date: Wed May 9 02:46:22 UTC 2018 Modified Files: src/sys/dev/i2c: ibmhawk.c Log Message: The probe this driver uses is potentially destructive; at the very least, filter on the I2C address the device is expected at before we unleash its fury. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/ibmhawk.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/ibmhawk.c diff -u src/sys/dev/i2c/ibmhawk.c:1.4 src/sys/dev/i2c/ibmhawk.c:1.5 --- src/sys/dev/i2c/ibmhawk.c:1.4 Thu Jul 14 04:01:32 2016 +++ src/sys/dev/i2c/ibmhawk.c Wed May 9 02:46:22 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ibmhawk.c,v 1.4 2016/07/14 04:01:32 msaitoh Exp $ */ +/* $NetBSD: ibmhawk.c,v 1.5 2018/05/09 02:46:22 thorpej Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -99,6 +99,12 @@ ibmhawk_match(device_t parent, cfdata_t ibmhawk_response_t resp; static struct ibmhawk_softc sc; + /* There is an expected address for this device: */ + if (ia->ia_addr != 0x37) + return 0; + + /* XXX Probe is potentially destructive. */ + sc.sc_tag = ia->ia_tag; sc.sc_addr = ia->ia_addr; if (ibmhawk_request(, IHR_EQUIP, ))
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Mon May 7 15:03:19 UTC 2018 Modified Files: src/sys/dev/i2c: gttwsi_core.c gttwsivar.h Log Message: Don't sleep with IPL_VM lock held. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/gttwsi_core.c cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/gttwsivar.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/gttwsi_core.c diff -u src/sys/dev/i2c/gttwsi_core.c:1.4 src/sys/dev/i2c/gttwsi_core.c:1.5 --- src/sys/dev/i2c/gttwsi_core.c:1.4 Thu May 3 02:08:52 2018 +++ src/sys/dev/i2c/gttwsi_core.c Mon May 7 15:03:19 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: gttwsi_core.c,v 1.4 2018/05/03 02:08:52 jmcneill Exp $ */ +/* $NetBSD: gttwsi_core.c,v 1.5 2018/05/07 15:03:19 jmcneill Exp $ */ /* * Copyright (c) 2008 Eiji Kawauchi. * All rights reserved. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.4 2018/05/03 02:08:52 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.5 2018/05/07 15:03:19 jmcneill Exp $"); #include "locators.h" #include @@ -195,7 +195,7 @@ gttwsi_intr(void *arg) if (val & CONTROL_IFLG) { gttwsi_write_4(sc, TWSI_CONTROL, val & ~CONTROL_INTEN); mutex_enter(>sc_mtx); - cv_signal(>sc_cv); + cv_broadcast(>sc_cv); mutex_exit(>sc_mtx); return 1; /* handled */ @@ -210,6 +210,11 @@ gttwsi_acquire_bus(void *arg, int flags) struct gttwsi_softc *sc = arg; mutex_enter(>sc_buslock); + while (sc->sc_inuse) + cv_wait(>sc_cv, >sc_buslock); + sc->sc_inuse = true; + mutex_exit(>sc_buslock); + return 0; } @@ -219,6 +224,9 @@ gttwsi_release_bus(void *arg, int flags) { struct gttwsi_softc *sc = arg; + mutex_enter(>sc_buslock); + sc->sc_inuse = false; + cv_broadcast(>sc_cv); mutex_exit(>sc_buslock); } @@ -228,7 +236,7 @@ gttwsi_send_start(void *v, int flags) struct gttwsi_softc *sc = v; int expect; - KASSERT(mutex_owned(>sc_buslock)); + KASSERT(sc->sc_inuse); if (sc->sc_started) expect = STAT_RSCT; @@ -245,7 +253,7 @@ gttwsi_send_stop(void *v, int flags) int retry = TWSI_RETRY_COUNT; uint32_t control; - KASSERT(mutex_owned(>sc_buslock)); + KASSERT(sc->sc_inuse); sc->sc_started = false; @@ -272,7 +280,7 @@ gttwsi_initiate_xfer(void *v, i2c_addr_t uint32_t data, expect; int error, read; - KASSERT(mutex_owned(>sc_buslock)); + KASSERT(sc->sc_inuse); gttwsi_send_start(v, flags); @@ -318,7 +326,7 @@ gttwsi_read_byte(void *v, uint8_t *valp, struct gttwsi_softc *sc = v; int error; - KASSERT(mutex_owned(>sc_buslock)); + KASSERT(sc->sc_inuse); if (flags & I2C_F_LAST) error = gttwsi_wait(sc, 0, STAT_MRRD_ANT, flags); @@ -337,7 +345,7 @@ gttwsi_write_byte(void *v, uint8_t val, struct gttwsi_softc *sc = v; int error; - KASSERT(mutex_owned(>sc_buslock)); + KASSERT(sc->sc_inuse); gttwsi_write_4(sc, TWSI_DATA, val); error = gttwsi_wait(sc, 0, STAT_MTDB_AR, flags); @@ -353,7 +361,7 @@ gttwsi_wait(struct gttwsi_softc *sc, uin uint32_t status; int timo, error = 0; - KASSERT(mutex_owned(>sc_buslock)); + KASSERT(sc->sc_inuse); DELAY(5); if (!(flags & I2C_F_POLL)) Index: src/sys/dev/i2c/gttwsivar.h diff -u src/sys/dev/i2c/gttwsivar.h:1.3 src/sys/dev/i2c/gttwsivar.h:1.4 --- src/sys/dev/i2c/gttwsivar.h:1.3 Sun Oct 29 14:59:05 2017 +++ src/sys/dev/i2c/gttwsivar.h Mon May 7 15:03:19 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: gttwsivar.h,v 1.3 2017/10/29 14:59:05 jmcneill Exp $ */ +/* $NetBSD: gttwsivar.h,v 1.4 2018/05/07 15:03:19 jmcneill Exp $ */ /* * Copyright (c) 2008 Eiji Kawauchi. * All rights reserved. @@ -86,6 +86,7 @@ struct gttwsi_softc { struct i2c_controller sc_i2c; kmutex_t sc_buslock; kmutex_t sc_mtx; + bool sc_inuse; kcondvar_t sc_cv; bool sc_iflg_rwc;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sun May 6 14:25:48 UTC 2018 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: POKS IRQ register / bit differ between AXP803 and AXP805/806. Handle these differences. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 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.4 src/sys/dev/i2c/axppmic.c:1.5 --- src/sys/dev/i2c/axppmic.c:1.4 Sat May 5 10:56:40 2018 +++ src/sys/dev/i2c/axppmic.c Sun May 6 14:25:48 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.4 2018/05/05 10:56:40 jmcneill Exp $ */ +/* $NetBSD: axppmic.c,v 1.5 2018/05/06 14:25:48 jmcneill Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill@@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.4 2018/05/05 10:56:40 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.5 2018/05/06 14:25:48 jmcneill Exp $"); #include #include @@ -57,7 +57,12 @@ __KERNEL_RCSID(0, "$NetBSD: axppmic.c,v #define AXP_POWER_DISABLE_CTRL __BIT(7) #define AXP_IRQ_ENABLE_REG(n) (0x40 + (n) - 1) +#define AXP_IRQ1_ACIN_RAISE __BIT(6) +#define AXP_IRQ1_ACIN_LOWER __BIT(5) +#define AXP_IRQ1_VBUS_RAISE __BIT(3) +#define AXP_IRQ1_VBUS_LOWER __BIT(2) #define AXP_IRQ2_POKSIRQ __BIT(1) +#define AXP_IRQ2_ #define AXP_IRQ_STATUS_REG(n) (0x48 + (n) - 1) #define AXP_FUEL_GAUGE_CTRL_REG 0xb8 @@ -181,6 +186,8 @@ struct axppmic_config { u_int irq_regs; bool has_battery; bool has_fuel_gauge; + u_int poksirq_reg; + uint8_t poksirq_mask; }; enum axppmic_sensor { @@ -201,6 +208,10 @@ struct axppmic_softc { bool sc_has_battery; bool sc_has_fuel_gauge; + u_int sc_poksirq_reg; + uint8_t sc_poksirq_mask; + + u_int sc_irq_regs; struct sysmon_pswitch sc_smpsw; @@ -233,6 +244,8 @@ static const struct axppmic_config axp80 .irq_regs = 6, .has_battery = true, .has_fuel_gauge = true, + .poksirq_reg = 5, + .poksirq_mask = __BIT(4), }; static const struct axppmic_config axp805_config = { @@ -240,6 +253,8 @@ static const struct axppmic_config axp80 .controls = axp805_ctrls, .ncontrols = __arraycount(axp805_ctrls), .irq_regs = 2, + .poksirq_reg = 2, + .poksirq_mask = __BIT(1), }; static const struct of_compat_data compat_data[] = { @@ -358,14 +373,18 @@ axppmic_intr(void *priv) { struct axppmic_softc *sc = priv; const int flags = I2C_F_POLL; + u_int n; uint8_t stat; iic_acquire_bus(sc->sc_i2c, flags); - if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_IRQ_STATUS_REG(2), , flags) == 0) { - if (stat & AXP_IRQ2_POKSIRQ) - sysmon_task_queue_sched(0, axppmic_task_shut, sc); + for (n = 1; n <= sc->sc_irq_regs; n++) { + if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_IRQ_STATUS_REG(n), , flags) == 0) { + if (n == sc->sc_poksirq_reg && (stat & sc->sc_poksirq_mask) != 0) +sysmon_task_queue_sched(0, axppmic_task_shut, sc); - axppmic_write(sc->sc_i2c, sc->sc_addr, AXP_IRQ_STATUS_REG(2), stat, flags); + axppmic_write(sc->sc_i2c, sc->sc_addr, + AXP_IRQ_STATUS_REG(sc->sc_poksirq_reg), stat, flags); + } } iic_release_bus(sc->sc_i2c, flags); @@ -518,7 +537,7 @@ axppmic_attach_sensors(struct axppmic_so sc->sc_sme->sme_cookie = sc; sc->sc_sme->sme_refresh = axppmic_sensor_refresh; sc->sc_sme->sme_class = SME_CLASS_BATTERY; - sc->sc_sme->sme_flags = SME_POLL_ONLY | SME_INIT_REFRESH; + sc->sc_sme->sme_flags = SME_INIT_REFRESH; axppmic_attach_acadapter(sc); axppmic_attach_battery(sc); @@ -562,6 +581,9 @@ axppmic_attach(device_t parent, device_t sc->sc_phandle = ia->ia_cookie; sc->sc_has_battery = c->has_battery; sc->sc_has_fuel_gauge = c->has_fuel_gauge; + sc->sc_irq_regs = c->irq_regs; + sc->sc_poksirq_reg = c->poksirq_reg; + sc->sc_poksirq_mask = c->poksirq_mask; aprint_naive("\n"); aprint_normal(": %s\n", c->name); @@ -573,8 +595,8 @@ axppmic_attach(device_t parent, device_t iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); for (i = 1; i <= c->irq_regs; i++) { irq_mask = 0; - if (i == 2) - irq_mask |= AXP_IRQ2_POKSIRQ; + if (i == c->poksirq_reg) + irq_mask |= c->poksirq_mask; axppmic_write(sc->sc_i2c, sc->sc_addr, AXP_IRQ_ENABLE_REG(i), irq_mask, I2C_F_POLL); } iic_release_bus(sc->sc_i2c, I2C_F_POLL);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sat May 5 10:56:40 UTC 2018 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: No need to read battery capacity warning levels each time the sensor is refreshed To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 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.3 src/sys/dev/i2c/axppmic.c:1.4 --- src/sys/dev/i2c/axppmic.c:1.3 Sat May 5 10:25:59 2018 +++ src/sys/dev/i2c/axppmic.c Sat May 5 10:56:40 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.3 2018/05/05 10:25:59 jmcneill Exp $ */ +/* $NetBSD: axppmic.c,v 1.4 2018/05/05 10:56:40 jmcneill Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill@@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.3 2018/05/05 10:25:59 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.4 2018/05/05 10:56:40 jmcneill Exp $"); #include #include @@ -207,6 +207,9 @@ struct axppmic_softc { struct sysmon_envsys *sc_sme; envsys_data_t sc_sensor[AXP_NSENSORS]; + + u_int sc_warn_thres; + u_int sc_shut_thres; }; struct axpreg_softc { @@ -374,7 +377,7 @@ axppmic_sensor_refresh(struct sysmon_env { struct axppmic_softc *sc = sme->sme_cookie; const int flags = I2C_F_POLL; - uint8_t val, warn_val; + uint8_t val; e->state = ENVSYS_SINVALID; @@ -411,16 +414,12 @@ axppmic_sensor_refresh(struct sysmon_env (val & AXP_POWER_MODE_BATT_VALID) != 0 && (val & AXP_POWER_MODE_BATT_PRESENT) != 0 && axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATT_CAP_REG, , flags) == 0 && - (val & AXP_BATT_CAP_VALID) != 0 && - axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATT_CAP_WARN_REG, _val, flags) == 0) { - const u_int warn_thres = __SHIFTOUT(warn_val, AXP_BATT_CAP_WARN_LV1) + 5; - const u_int shut_thres = __SHIFTOUT(warn_val, AXP_BATT_CAP_WARN_LV2); - + (val & AXP_BATT_CAP_VALID) != 0) { const u_int batt_val = __SHIFTOUT(val, AXP_BATT_CAP_PERCENT); - if (batt_val <= shut_thres) { + if (batt_val <= sc->sc_shut_thres) { e->state = ENVSYS_SCRITICAL; e->value_cur = ENVSYS_BATTERY_CAPACITY_CRITICAL; - } else if (batt_val <= warn_thres) { + } else if (batt_val <= sc->sc_warn_thres) { e->state = ENVSYS_SWARNUNDER; e->value_cur = ENVSYS_BATTERY_CAPACITY_WARNING; } else { @@ -467,6 +466,14 @@ static void axppmic_attach_battery(struct axppmic_softc *sc) { envsys_data_t *e; + uint8_t val; + + iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); + if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATT_CAP_WARN_REG, , I2C_F_POLL) == 0) { + sc->sc_warn_thres = __SHIFTOUT(val, AXP_BATT_CAP_WARN_LV1) + 5; + sc->sc_shut_thres = __SHIFTOUT(val, AXP_BATT_CAP_WARN_LV2); + } + iic_release_bus(sc->sc_i2c, I2C_F_POLL); e = >sc_sensor[AXP_SENSOR_BATT_PRESENT]; e->private = AXP_SENSOR_BATT_PRESENT;
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sat May 5 10:25:59 UTC 2018 Modified Files: src/sys/dev/i2c: axppmic.c Log Message: Add ACIN and VBUS present sensors To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 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.2 src/sys/dev/i2c/axppmic.c:1.3 --- src/sys/dev/i2c/axppmic.c:1.2 Sat May 5 00:39:59 2018 +++ src/sys/dev/i2c/axppmic.c Sat May 5 10:25:59 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.2 2018/05/05 00:39:59 jmcneill Exp $ */ +/* $NetBSD: axppmic.c,v 1.3 2018/05/05 10:25:59 jmcneill Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill@@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.2 2018/05/05 00:39:59 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.3 2018/05/05 10:25:59 jmcneill Exp $"); #include #include @@ -44,6 +44,10 @@ __KERNEL_RCSID(0, "$NetBSD: axppmic.c,v #include +#define AXP_POWER_SOURCE_REG 0x00 +#define AXP_POWER_SOURCE_ACIN_PRESENT __BIT(7) +#define AXP_POWER_SOURCE_VBUS_PRESENT __BIT(5) + #define AXP_POWER_MODE_REG 0x01 #define AXP_POWER_MODE_BATT_VALID __BIT(4) #define AXP_POWER_MODE_BATT_PRESENT __BIT(5) @@ -180,6 +184,8 @@ struct axppmic_config { }; enum axppmic_sensor { + AXP_SENSOR_ACIN_PRESENT, + AXP_SENSOR_VBUS_PRESENT, AXP_SENSOR_BATT_PRESENT, AXP_SENSOR_BATT_CHARGING, AXP_SENSOR_BATT_CHARGE_STATE, @@ -199,6 +205,7 @@ struct axppmic_softc { struct sysmon_pswitch sc_smpsw; struct sysmon_envsys *sc_sme; + envsys_data_t sc_sensor[AXP_NSENSORS]; }; @@ -373,12 +380,23 @@ axppmic_sensor_refresh(struct sysmon_env iic_acquire_bus(sc->sc_i2c, flags); switch (e->private) { + case AXP_SENSOR_ACIN_PRESENT: + if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_SOURCE_REG, , flags) == 0) { + e->state = ENVSYS_SVALID; + e->value_cur = !!(val & AXP_POWER_SOURCE_ACIN_PRESENT); + } + break; + case AXP_SENSOR_VBUS_PRESENT: + if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_SOURCE_REG, , flags) == 0) { + e->state = ENVSYS_SVALID; + e->value_cur = !!(val & AXP_POWER_SOURCE_VBUS_PRESENT); + } + break; case AXP_SENSOR_BATT_PRESENT: if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_MODE_REG, , flags) == 0) { if (val & AXP_POWER_MODE_BATT_VALID) { e->state = ENVSYS_SVALID; e->value_cur = !!(val & AXP_POWER_MODE_BATT_PRESENT); -break; } } break; @@ -426,6 +444,26 @@ axppmic_sensor_refresh(struct sysmon_env } static void +axppmic_attach_acadapter(struct axppmic_softc *sc) +{ + envsys_data_t *e; + + e = >sc_sensor[AXP_SENSOR_ACIN_PRESENT]; + e->private = AXP_SENSOR_ACIN_PRESENT; + e->units = ENVSYS_INDICATOR; + e->state = ENVSYS_SINVALID; + strlcpy(e->desc, "ACIN present", sizeof(e->desc)); + sysmon_envsys_sensor_attach(sc->sc_sme, e); + + e = >sc_sensor[AXP_SENSOR_VBUS_PRESENT]; + e->private = AXP_SENSOR_VBUS_PRESENT; + e->units = ENVSYS_INDICATOR; + e->state = ENVSYS_SINVALID; + strlcpy(e->desc, "VBUS present", sizeof(e->desc)); + sysmon_envsys_sensor_attach(sc->sc_sme, e); +} + +static void axppmic_attach_battery(struct axppmic_softc *sc) { envsys_data_t *e; @@ -475,6 +513,7 @@ axppmic_attach_sensors(struct axppmic_so sc->sc_sme->sme_class = SME_CLASS_BATTERY; sc->sc_sme->sme_flags = SME_POLL_ONLY | SME_INIT_REFRESH; + axppmic_attach_acadapter(sc); axppmic_attach_battery(sc); sysmon_envsys_register(sc->sc_sme);
CVS commit: src/sys/dev/i2c
Module Name:src Committed By: jmcneill Date: Sat May 5 02:01:34 UTC 2018 Modified Files: src/sys/dev/i2c: files.i2c Log Message: axppmic depends on sysmon_envsys To generate a diff of this commit: cvs rdiff -u -r1.90 -r1.91 src/sys/dev/i2c/files.i2c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/i2c/files.i2c diff -u src/sys/dev/i2c/files.i2c:1.90 src/sys/dev/i2c/files.i2c:1.91 --- src/sys/dev/i2c/files.i2c:1.90 Fri May 4 21:09:55 2018 +++ src/sys/dev/i2c/files.i2c Sat May 5 02:01:34 2018 @@ -1,4 +1,4 @@ -# $NetBSD: files.i2c,v 1.90 2018/05/04 21:09:55 jmcneill Exp $ +# $NetBSD: files.i2c,v 1.91 2018/05/05 02:01:34 jmcneill Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } @@ -233,7 +233,7 @@ attach axp22x at iic file dev/i2c/axp22x.c axp22x # X-Powers AXP Power Management IC -device axppmic { }: sysmon_taskq +device axppmic { }: sysmon_envsys, sysmon_taskq device axpreg: axppmic attach axppmic at iic attach axpreg at axppmic