summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2006-06-15 16:25:23 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2006-06-15 16:25:23 +0000
commit686c8cda73261a63e3f930ab893ed44830d5e938 (patch)
tree9abfa09cdca48b5fa0628ce9e27ad873ed807f91 /sys
parent4e03913b3b140fc8c460573c2f68a87d690031a6 (diff)
tighten this code up
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/ic/pcf8584.c38
1 files changed, 15 insertions, 23 deletions
diff --git a/sys/dev/ic/pcf8584.c b/sys/dev/ic/pcf8584.c
index 6a1b2b6a872..8ad1b91f2f3 100644
--- a/sys/dev/ic/pcf8584.c
+++ b/sys/dev/ic/pcf8584.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pcf8584.c,v 1.4 2006/06/14 04:13:37 deraadt Exp $ */
+/* $OpenBSD: pcf8584.c,v 1.5 2006/06/15 16:25:22 deraadt Exp $ */
/*
* Copyright (c) 2006 David Gwynne <dlg@openbsd.org>
@@ -109,7 +109,9 @@ pcfiic_attach(struct pcfiic_softc *sc, i2c_addr_t addr,
pcfiic_write(sc, PCF_S1, PCF_CTRL_IDLE);
-// pcfiic_read(sc, PCF_S0); /* dummy read */
+#if 0
+ pcfiic_read(sc, PCF_S0); /* dummy read maybe? */
+#endif
printf("\n");
@@ -139,7 +141,7 @@ pcfiic_intr(void *arg)
int
pcfiic_i2c_acquire_bus(void *arg, int flags)
{
- struct pcfiic_softc *sc = arg;
+ struct pcfiic_softc *sc = arg;
if (cold || sc->sc_poll || (flags & I2C_F_POLL))
return (0);
@@ -150,7 +152,7 @@ pcfiic_i2c_acquire_bus(void *arg, int flags)
void
pcfiic_i2c_release_bus(void *arg, int flags)
{
- struct pcfiic_softc *sc = arg;
+ struct pcfiic_softc *sc = arg;
if (cold || sc->sc_poll || (flags & I2C_F_POLL))
return;
@@ -162,8 +164,8 @@ int
pcfiic_i2c_exec(void *arg, i2c_op_t op, i2c_addr_t addr,
const void *cmdbuf, size_t cmdlen, void *buf, size_t len, int flags)
{
- struct pcfiic_softc *sc = arg;
- int ret = 0;
+ struct pcfiic_softc *sc = arg;
+ int ret = 0;
#if 0
printf("%s: exec op: %d addr: 0x%x cmdlen: %d len: %d flags 0x%x\n",
@@ -176,10 +178,9 @@ pcfiic_i2c_exec(void *arg, i2c_op_t op, i2c_addr_t addr,
if (sc->sc_master)
pcfiic_choose_bus(sc, addr >> 7);
- if (cmdlen > 0) {
+ if (cmdlen > 0)
if (pcfiic_xmit(sc, addr & 0x7f, cmdbuf, cmdlen) != 0)
return (1);
- }
if (len > 0) {
if (I2C_OP_WRITE_P(op))
@@ -187,7 +188,6 @@ pcfiic_i2c_exec(void *arg, i2c_op_t op, i2c_addr_t addr,
else
ret = pcfiic_recv(sc, addr & 0x7f, buf, len);
}
-
return (ret);
}
@@ -195,10 +195,8 @@ int
pcfiic_xmit(struct pcfiic_softc *sc, u_int8_t addr, const u_int8_t *buf,
size_t len)
{
- int i;
- int err = 0;
- volatile u_int8_t r;
- int tries = 100;
+ int i, err = 0, tries = 100;
+ volatile u_int8_t r;
while ((pcfiic_read(sc, PCF_S1) & PCF_STAT_nBB) == 0) {
if (--tries == 0)
@@ -228,16 +226,14 @@ pcfiic_xmit(struct pcfiic_softc *sc, u_int8_t addr, const u_int8_t *buf,
}
pcfiic_write(sc, PCF_S1, PCF_CTRL_STOP);
-
return (err);
}
int
pcfiic_recv(struct pcfiic_softc *sc, u_int8_t addr, u_int8_t *buf, size_t len)
{
- int i;
- int err = 0;
- volatile u_int8_t r;
+ int i = 0, err = 0;
+ volatile u_int8_t r;
pcfiic_write(sc, PCF_S0, (addr << 1) | 0x01);
@@ -246,7 +242,6 @@ pcfiic_recv(struct pcfiic_softc *sc, u_int8_t addr, u_int8_t *buf, size_t len)
pcfiic_write(sc, PCF_S1, PCF_CTRL_START);
- i = 0;
for (i = 0; i <= len; i++) {
if (pcfiic_wait_pin(sc, &r) != 0) {
pcfiic_write(sc, PCF_S1, PCF_CTRL_STOP);
@@ -268,7 +263,6 @@ pcfiic_recv(struct pcfiic_softc *sc, u_int8_t addr, u_int8_t *buf, size_t len)
if (i > 0)
buf[i - 1] = r;
}
-
return (err);
}
@@ -299,21 +293,20 @@ pcfiic_choose_bus(struct pcfiic_softc *sc, u_int8_t bus)
int
pcfiic_wait_nBB(struct pcfiic_softc *sc)
{
- int i;
+ int i;
for (i = 0; i < 1000; i++) {
if (pcfiic_read(sc, PCF_S1) & PCF_STAT_nBB)
return (0);
delay(1000);
}
-
return (1);
}
int
pcfiic_wait_pin(struct pcfiic_softc *sc, volatile u_int8_t *r)
{
- int i;
+ int i;
for (i = 0; i < 1000; i++) {
*r = pcfiic_read(sc, PCF_S1);
@@ -321,6 +314,5 @@ pcfiic_wait_pin(struct pcfiic_softc *sc, volatile u_int8_t *r)
return (0);
delay(1000);
}
-
return (1);
}