summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2008-04-17 19:01:48 +0000
committerderaadt <deraadt@openbsd.org>2008-04-17 19:01:48 +0000
commit91eacc75c9904a072e8b7c3428f766321fd5fb57 (patch)
tree55ab09b9332dce463634e456f696c3177475a2e0
parentdo not blindly call ieee80211_get_hdrlen() in rt2860_rx_intr(). (diff)
downloadwireguard-openbsd-91eacc75c9904a072e8b7c3428f766321fd5fb57.tar.xz
wireguard-openbsd-91eacc75c9904a072e8b7c3428f766321fd5fb57.zip
make it more apparent that when we are dealing with 16 bit registers
(not a series of 8 bit registers), the bytes come off the wire in big-endian order
-rw-r--r--sys/dev/i2c/ad741x.c13
-rw-r--r--sys/dev/i2c/asb100.c6
-rw-r--r--sys/dev/i2c/ds1631.c7
-rw-r--r--sys/dev/i2c/i2c_scan.c14
-rw-r--r--sys/dev/i2c/lm75.c4
-rw-r--r--sys/dev/i2c/sdtemp.c14
-rw-r--r--sys/dev/i2c/spdmem.c6
7 files changed, 32 insertions, 32 deletions
diff --git a/sys/dev/i2c/ad741x.c b/sys/dev/i2c/ad741x.c
index b9310191748..e4b9b67dc98 100644
--- a/sys/dev/i2c/ad741x.c
+++ b/sys/dev/i2c/ad741x.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ad741x.c,v 1.13 2007/10/20 22:06:43 cnst Exp $ */
+/* $OpenBSD: ad741x.c,v 1.14 2008/04/17 19:01:48 deraadt Exp $ */
/*
* Copyright (c) 2005 Theo de Raadt
@@ -158,7 +158,8 @@ void
adc_refresh(void *arg)
{
struct adc_softc *sc = arg;
- u_int8_t cmd, data[2], reg;
+ u_int8_t cmd, reg;
+ u_int16_t data;
int i;
iic_acquire_bus(sc->sc_tag, 0);
@@ -173,7 +174,7 @@ adc_refresh(void *arg)
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0))
goto done;
sc->sc_sensor[ADC_TEMP].value = 273150000 +
- ((data[0] << 8 | data[1]) >> 6) * 250000;
+ (betoh16(data) >> 6) * 250000;
if (sc->sc_chip == 0)
goto done;
@@ -188,8 +189,7 @@ adc_refresh(void *arg)
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0))
goto done;
- sc->sc_sensor[ADC_ADC0].value =
- (data[0] << 8 | data[1]) >> 6;
+ sc->sc_sensor[ADC_ADC0].value = betoh16(data) >> 6;
goto done;
}
@@ -203,8 +203,7 @@ adc_refresh(void *arg)
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0))
goto done;
- sc->sc_sensor[ADC_ADC0 + i].value =
- (data[0] << 8 | data[1]) >> 6;
+ sc->sc_sensor[ADC_ADC0 + i].value = betoh16(data) >> 6;
}
done:
diff --git a/sys/dev/i2c/asb100.c b/sys/dev/i2c/asb100.c
index 37961c82ece..62a0e13d379 100644
--- a/sys/dev/i2c/asb100.c
+++ b/sys/dev/i2c/asb100.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asb100.c,v 1.10 2007/06/24 05:34:35 dlg Exp $ */
+/* $OpenBSD: asb100.c,v 1.11 2008/04/17 19:01:48 deraadt Exp $ */
/*
* Copyright (c) 2005 Damien Miller <djm@openbsd.org>
@@ -372,7 +372,7 @@ asbtm_refresh(void *arg)
sc->sc_satellite[0], &cmd, sizeof cmd, &sdata2,
sizeof sdata2, 0) == 0 && sdata2 != 0xffff) {
sc->sc_sensor[ASB100_SENSOR_TEMP1].value = 273150000 +
- 500000 * (swap16(sdata2) / 128);
+ 500000 * (betoh16(sdata2) / 128);
sc->sc_sensor[ASB100_SENSOR_TEMP2].flags &=
~SENSOR_FINVALID;
} else {
@@ -387,7 +387,7 @@ asbtm_refresh(void *arg)
sc->sc_satellite[1], &cmd, sizeof cmd, &sdata2,
sizeof sdata2, 0) == 0 && sdata2 != 0xffff) {
sc->sc_sensor[ASB100_SENSOR_TEMP2].value = 273150000 +
- 500000 * (swap16(sdata2) / 128);
+ 500000 * (betoh16(sdata2) / 128);
sc->sc_sensor[ASB100_SENSOR_TEMP2].flags &=
~SENSOR_FINVALID;
} else {
diff --git a/sys/dev/i2c/ds1631.c b/sys/dev/i2c/ds1631.c
index c0a911dcff3..946e2dc354c 100644
--- a/sys/dev/i2c/ds1631.c
+++ b/sys/dev/i2c/ds1631.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ds1631.c,v 1.9 2007/06/24 05:34:35 dlg Exp $ */
+/* $OpenBSD: ds1631.c,v 1.10 2008/04/17 19:01:48 deraadt Exp $ */
/*
* Copyright (c) 2005 Theo de Raadt
@@ -136,7 +136,8 @@ void
maxds_refresh(void *arg)
{
struct maxds_softc *sc = arg;
- u_int8_t cmd, data[2];
+ u_int8_t cmd;
+ u_int16_t data;
iic_acquire_bus(sc->sc_tag, 0);
@@ -144,7 +145,7 @@ maxds_refresh(void *arg)
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0) == 0)
sc->sc_sensor[MAXDS_TEMP].value = 273150000 +
- ((int)((u_int16_t)data[0] << 8 | data[1])) / 8 * 31250;
+ (int)(betoh16(data)) / 8 * 31250;
iic_release_bus(sc->sc_tag, 0);
}
diff --git a/sys/dev/i2c/i2c_scan.c b/sys/dev/i2c/i2c_scan.c
index 015131e4996..1722c021545 100644
--- a/sys/dev/i2c/i2c_scan.c
+++ b/sys/dev/i2c/i2c_scan.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: i2c_scan.c,v 1.121 2008/04/10 17:14:09 deraadt Exp $ */
+/* $OpenBSD: i2c_scan.c,v 1.122 2008/04/17 19:01:48 deraadt Exp $ */
/*
* Copyright (c) 2005 Theo de Raadt <deraadt@openbsd.org>
@@ -123,7 +123,7 @@ iicprobenc(u_int8_t cmd)
return (0xff);
iic_acquire_bus(probe_ic, 0);
if (iic_exec(probe_ic, I2C_OP_READ_WITH_STOP,
- probe_addr, &cmd, 1, &data, 1, 0) != 0)
+ probe_addr, &cmd, sizeof cmd, &data, sizeof data, 0) != 0)
data = 0xff;
iic_release_bus(probe_ic, 0);
return (data);
@@ -132,7 +132,7 @@ iicprobenc(u_int8_t cmd)
u_int16_t
iicprobew(u_int8_t cmd)
{
- u_int8_t data[2];
+ u_int16_t data;
/*
* If we think we are talking to an evil Maxim 1617 or clone,
@@ -142,10 +142,10 @@ iicprobew(u_int8_t cmd)
return (0xffff);
iic_acquire_bus(probe_ic, 0);
if (iic_exec(probe_ic, I2C_OP_READ_WITH_STOP,
- probe_addr, &cmd, 1, &data, 2, 0) != 0)
- data[0] = data[1] = 0xff;
+ probe_addr, &cmd, sizeof cmd, &data, sizeof data, 0) != 0)
+ data = 0xffff;
iic_release_bus(probe_ic, 0);
- return ((data[0] << 8) | data[1]);
+ return betoh16(data);
}
u_int8_t
@@ -961,7 +961,7 @@ iic_scan(struct device *self, struct i2cbus_attach_args *iba)
/* Perform RECEIVE BYTE command */
iic_acquire_bus(ic, 0);
if (iic_exec(ic, I2C_OP_READ_WITH_STOP, addr,
- &cmd, 1, NULL, 0, 0) == 0) {
+ &cmd, sizeof cmd, NULL, 0, 0) == 0) {
iic_release_bus(ic, 0);
/* Some device exists */
diff --git a/sys/dev/i2c/lm75.c b/sys/dev/i2c/lm75.c
index ba3b11f8728..3145e1fa11e 100644
--- a/sys/dev/i2c/lm75.c
+++ b/sys/dev/i2c/lm75.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lm75.c,v 1.17 2008/04/16 22:44:37 deraadt Exp $ */
+/* $OpenBSD: lm75.c,v 1.18 2008/04/17 19:01:48 deraadt Exp $ */
/* $NetBSD: lm75.c,v 1.1 2003/09/30 00:35:31 thorpej Exp $ */
/*
* Copyright (c) 2006 Theo de Raadt <deraadt@openbsd.org>
@@ -232,7 +232,7 @@ lmtemp_temp_read(struct lmtemp_softc *sc, uint8_t which, int *valp)
return (1);
/* convert to half-degrees C */
- *valp = ntohs(data) / (1 << (16 - sc->sc_bits));
+ *valp = betoh16(data) / (1 << (16 - sc->sc_bits));
return (0);
}
diff --git a/sys/dev/i2c/sdtemp.c b/sys/dev/i2c/sdtemp.c
index d2dde590fe2..ea83ec46dc5 100644
--- a/sys/dev/i2c/sdtemp.c
+++ b/sys/dev/i2c/sdtemp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sdtemp.c,v 1.4 2008/04/10 17:14:09 deraadt Exp $ */
+/* $OpenBSD: sdtemp.c,v 1.5 2008/04/17 19:01:48 deraadt Exp $ */
/*
* Copyright (c) 2008 Theo de Raadt
@@ -100,22 +100,22 @@ void
sdtemp_refresh(void *arg)
{
struct sdtemp_softc *sc = arg;
- u_int8_t cmd, data[2];
- int16_t sdata;
+ u_int8_t cmd;
+ int16_t data, sdata;
iic_acquire_bus(sc->sc_tag, 0);
cmd = JC_TEMP;
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr,
- &cmd, sizeof cmd, data, sizeof data, 0) == 0) {
- sdata = ((data[0] << 8) | data[1]) & 0x0fff;
- if (data[0] & JC_TEMP_SIGN)
+ &cmd, sizeof cmd, &data, sizeof data, 0) == 0) {
+ sdata = betoh16(data) & 0x0fff;
+ if (betoh16(data) & JC_TEMP_SIGN)
sdata = -sdata;
sc->sc_sensor[JCTEMP_TEMP].value =
273150000 + 62500 * sdata;
sc->sc_sensor[JCTEMP_TEMP].flags &= ~SENSOR_FINVALID;
#if 0
- printf("sdtemp %02x%02x %04x %d\n", data[0], data[1],
+ printf("sdtemp %04x %04x %d\n", data & 0xffff,
(u_int)sdata & 0xffff,
sc->sc_sensor[JCTEMP_TEMP].value);
#endif
diff --git a/sys/dev/i2c/spdmem.c b/sys/dev/i2c/spdmem.c
index 19197afb0d2..3a02f6386e3 100644
--- a/sys/dev/i2c/spdmem.c
+++ b/sys/dev/i2c/spdmem.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: spdmem.c,v 1.23 2007/11/26 17:40:56 jsg Exp $ */
+/* $OpenBSD: spdmem.c,v 1.24 2008/04/17 19:01:48 deraadt Exp $ */
/* $NetBSD: spdmem.c,v 1.3 2007/09/20 23:09:59 xtraeme Exp $ */
/*
@@ -580,8 +580,8 @@ spdmem_read(struct spdmem_softc *sc, uint8_t reg)
uint8_t val;
iic_acquire_bus(sc->sc_tag,0);
- iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, &reg, 1,
- &val, 1, 0);
+ iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr,
+ &reg, sizeof reg, &val, sizeof val, 0);
iic_release_bus(sc->sc_tag, 0);
return val;