Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/i2c fixes from Brad Spenser
details: https://anonhg.NetBSD.org/src/rev/d9eb0582e372
branches: trunk
changeset: 358449:d9eb0582e372
user: christos <christos%NetBSD.org@localhost>
date: Sat Dec 30 03:18:26 2017 +0000
description:
fixes from Brad Spenser
diffstat:
sys/dev/i2c/am2315.c | 25 +++++++++++++------------
sys/dev/i2c/si70xx.c | 51 +++++++++++++++++++++++++++++----------------------
2 files changed, 42 insertions(+), 34 deletions(-)
diffs (213 lines):
diff -r eb30b2fc272f -r d9eb0582e372 sys/dev/i2c/am2315.c
--- a/sys/dev/i2c/am2315.c Sat Dec 30 01:21:25 2017 +0000
+++ b/sys/dev/i2c/am2315.c Sat Dec 30 03:18:26 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: am2315.c,v 1.1 2017/12/28 23:23:47 christos Exp $ */
+/* $NetBSD: am2315.c,v 1.2 2017/12/30 03:18:26 christos Exp $ */
/*
* Copyright (c) 2017 Brad Spencer <brad%anduin.eldar.org@localhost>
@@ -17,7 +17,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: am2315.c,v 1.1 2017/12/28 23:23:47 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: am2315.c,v 1.2 2017/12/30 03:18:26 christos Exp $");
/*
* Driver for the Aosong AM2315
@@ -153,16 +153,16 @@
if (debug)
printf("%s: poke 1: %d\n", name, error);
- if (error != 0)
+ if (error)
delay(2800);
error = am2315_cmd(tag, addr, AM2315_READ_REGISTERS,
AM2315_REGISTER_STATUS, 1, buf, __arraycount(buf));
if (debug)
- printf("%s: poke 2: %d %02x %02x %02x %02x%02x\n", name, error,
- buf[0], buf[1], buf[2], buf[3], buf[4]);
+ printf("%s: poke 2: %d %02x %02x %02x %02x%02x\n", name, error,
+ buf[0], buf[1], buf[2], buf[3], buf[4]);
- if (error != 0)
+ if (error)
delay(2800);
return error;
}
@@ -204,6 +204,7 @@
return 0;
}
+ iic_release_bus(ia->ia_tag, 0);
return 1;
}
@@ -299,7 +300,7 @@
&& crc == readcrc;
error = am2315_read_regs(sc, AM2315_REGISTER_VERSION, 1, buf, 5);
- if (error != 0)
+ if (error)
aprint_error_dev(self, "read chipver: %d\n", error);
readcrc = buf[4] << 8 | buf[3];
crc = am2315_crc(buf, 3);
@@ -309,7 +310,7 @@
&& crc == readcrc;
error = am2315_read_regs(sc, AM2315_REGISTER_ID_PT_24_31, 2, buf, 6);
- if (error != 0)
+ if (error)
aprint_error_dev(self, "read id 1: %d\n", error);
readcrc = buf[5] << 8 | buf[4];
crc = am2315_crc(buf, 4);
@@ -319,7 +320,7 @@
&& crc == readcrc;
error = am2315_read_regs(sc, AM2315_REGISTER_ID_PT_8_15, 2, buf, 6);
- if (error != 0)
+ if (error)
aprint_error_dev(self, "read id 2: %d\n", error);
readcrc = buf[5] << 8 | buf[4];
crc = am2315_crc(buf, 4);
@@ -392,7 +393,7 @@
mutex_enter(&sc->sc_mutex);
error = iic_acquire_bus(sc->sc_tag, 0);
- if (error == 0) {
+ if (error) {
DPRINTF(sc, 2, ("%s: Could not acquire i2c bus: %d\n",
device_xname(sc->sc_dev), error));
goto out;
@@ -415,8 +416,8 @@
am2315_poke(sc);
if ((error = am2315_read_regs(sc, thecommand, 2, buf, 6)) != 0)
- aprint_error_dev(sc->sc_dev,
- "Read sensor %d error: %d\n", edata->sensor, error);
+ DPRINTF(sc, 2, ("%s: Read sensor %d error: %d\n",
+ device_xname(sc->sc_dev),edata->sensor, error));
readcrc = buf[5] << 8 | buf[4];
crc = am2315_crc(buf, 4);
diff -r eb30b2fc272f -r d9eb0582e372 sys/dev/i2c/si70xx.c
--- a/sys/dev/i2c/si70xx.c Sat Dec 30 01:21:25 2017 +0000
+++ b/sys/dev/i2c/si70xx.c Sat Dec 30 03:18:26 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: si70xx.c,v 1.2 2017/12/29 02:19:45 christos Exp $ */
+/* $NetBSD: si70xx.c,v 1.3 2017/12/30 03:18:26 christos Exp $ */
/*
* Copyright (c) 2017 Brad Spencer <brad%anduin.eldar.org@localhost>
@@ -17,7 +17,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: si70xx.c,v 1.2 2017/12/29 02:19:45 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: si70xx.c,v 1.3 2017/12/30 03:18:26 christos Exp $");
/*
Driver for the Silicon Labs SI7013/SI7020/SI7021
@@ -202,12 +202,10 @@
return error;
}
-static int
-si70xx_cmd(i2c_tag_t tag, i2c_addr_t addr, uint8_t *cmd,
- uint8_t clen, uint8_t *buf, size_t blen)
+static uint8_t
+si70xx_dir(uint8_t cmd, size_t len)
{
- uint8_t dir;
- switch (cmd[0]) {
+ switch (cmd) {
case SI70XX_READ_USER_REG_1:
case SI70XX_READ_HEATER_REG:
case SI70XX_READ_ID_PT1A:
@@ -216,22 +214,33 @@
case SI70XX_READ_ID_PT2B:
case SI70XX_READ_FW_VERA:
case SI70XX_READ_FW_VERB:
- dir = I2C_OP_READ_WITH_STOP;
- break;
+ return I2C_OP_READ_WITH_STOP;
case SI70XX_WRITE_USER_REG_1:
case SI70XX_WRITE_HEATER_REG:
case SI70XX_RESET:
- dir = I2C_OP_WRITE_WITH_STOP;
- break;
+ return I2C_OP_WRITE_WITH_STOP;
case SI70XX_MEASURE_RH_NOHOLD:
case SI70XX_MEASURE_TEMP_NOHOLD:
- dir = blen == 0 ? I2C_OP_READ : I2C_OP_READ_WITH_STOP;
- break;
+ return len == 0 ? I2C_OP_READ : I2C_OP_READ_WITH_STOP;
default:
- panic("%s: bad command %#x\n", __func__, cmd[0]);
+ panic("%s: bad command %#x\n", __func__, cmd);
+ return 0;
}
+}
- memset(buf, 0, blen);
+static int
+si70xx_cmd(i2c_tag_t tag, i2c_addr_t addr, uint8_t *cmd,
+ uint8_t clen, uint8_t *buf, size_t blen)
+{
+ uint8_t dir;
+ if (clen == 0)
+ dir = blen == 0 ? I2C_OP_READ : I2C_OP_READ_WITH_STOP;
+ else
+ dir = si70xx_dir(cmd[0], blen);
+
+ if (dir == I2C_OP_READ || dir == I2C_OP_READ_WITH_STOP)
+ memset(buf, 0, blen);
+
return iic_exec(tag, dir, addr, cmd, clen, buf, blen, 0);
}
@@ -359,7 +368,7 @@
DPRINTF(sc, 2, ("%s:%s: heater values after: %#x\n",
device_xname(sc->sc_dev), __func__, heaterregister));
- error = si70xx_cmd1(sc, SI70XX_WRITE_USER_REG_1, &heaterregister, 1);
+ error = si70xx_cmd1(sc, SI70XX_WRITE_HEATER_REG, &heaterregister, 1);
if (error) {
DPRINTF(sc, 2, ("%s: Failed to write heater register: %d\n",
device_xname(sc->sc_dev), error));
@@ -610,7 +619,7 @@
#ifdef HAVE_I2C_EXECV
sc->sc_clockstretch = 2048;
#endif
- sc->sc_readattempts = 15;
+ sc->sc_readattempts = 25;
sc->sc_ignorecrc = false;
sc->sc_sme = NULL;
@@ -877,9 +886,7 @@
break;
DPRINTF(sc, 2, ("%s: Failed to read NO HOLD RH"
" %d %d\n", device_xname(sc->sc_dev), 2, error));
- if (aint < 10) {
- delay(1000);
- }
+ delay(1000);
}
#endif
@@ -933,11 +940,11 @@
}
switch (edata->sensor) {
case SI70XX_HUMIDITY_SENSOR:
- error = si70xx_exec(sc, SI70XX_MEASURE_RH_HOLD, edata);
+ error = si70xx_exec(sc, SI70XX_MEASURE_RH_NOHOLD, edata);
break;
case SI70XX_TEMP_SENSOR:
- error = si70xx_exec(sc, SI70XX_MEASURE_TEMP_HOLD, edata);
+ error = si70xx_exec(sc, SI70XX_MEASURE_TEMP_NOHOLD, edata);
break;
default:
error = EINVAL;
Home |
Main Index |
Thread Index |
Old Index