i2c-algo-bit: Whitespace fixes (+ NAK/ARB comments)

Fix *LOTS* of whitespace goofs and checkpatch.pl warnings, strangely
parenthesized ternary expressions, and other CodingStyle glitches.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
This commit is contained in:
David Brownell
2008-01-27 18:14:46 +01:00
committed by Jean Delvare
parent 59d70df025
commit cf978ab284

View File

@@ -1,7 +1,7 @@
/* ------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------
/* i2c-algo-bit.c i2c driver algorithms for bit-shift adapters */ * i2c-algo-bit.c i2c driver algorithms for bit-shift adapters
/* ------------------------------------------------------------------------- */ * -------------------------------------------------------------------------
/* Copyright (C) 1995-2000 Simon G. Vogl * Copyright (C) 1995-2000 Simon G. Vogl
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -15,8 +15,8 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
/* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
/* With some changes from Frodo Looijaard <frodol@dds.nl>, Kyösti Mälkki /* With some changes from Frodo Looijaard <frodol@dds.nl>, Kyösti Mälkki
<kmalkki@cc.hut.fi> and Jean Delvare <khali@linux-fr.org> */ <kmalkki@cc.hut.fi> and Jean Delvare <khali@linux-fr.org> */
@@ -99,14 +99,13 @@ static int sclhi(struct i2c_algo_bit_data *adap)
start = jiffies; start = jiffies;
while (!getscl(adap)) { while (!getscl(adap)) {
/* the hw knows how to read the clock line, /* This hw knows how to read the clock line, so we wait
* so we wait until it actually gets high. * until it actually gets high. This is safer as some
* This is safer as some chips may hold it low * chips may hold it low ("clock stretching") while they
* while they are processing data internally. * are processing data internally.
*/ */
if (time_after_eq(jiffies, start+adap->timeout)) { if (time_after_eq(jiffies, start + adap->timeout))
return -ETIMEDOUT; return -ETIMEDOUT;
}
cond_resched(); cond_resched();
} }
#ifdef DEBUG #ifdef DEBUG
@@ -175,9 +174,12 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c)
bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, " bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
"timeout at bit #%d\n", (int)c, i); "timeout at bit #%d\n", (int)c, i);
return -ETIMEDOUT; return -ETIMEDOUT;
}; }
/* do arbitration here: /* FIXME do arbitration here:
* if (sb && !getsda(adap)) -> ouch! Get out of here. * if (sb && !getsda(adap)) -> ouch! Get out of here.
*
* Report a unique code, so higher level code can retry
* the whole (combined) message and *NOT* issue STOP.
*/ */
scllo(adap); scllo(adap);
} }
@@ -186,8 +188,11 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c)
bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, " bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
"timeout at ack\n", (int)c); "timeout at ack\n", (int)c);
return -ETIMEDOUT; return -ETIMEDOUT;
}; }
/* read ack: SDA should be pulled down by slave */
/* read ack: SDA should be pulled down by slave, or it may
* NAK (usually to report problems with the data we wrote).
*/
ack = !getsda(adap); /* ack: sda is pulled low -> success */ ack = !getsda(adap); /* ack: sda is pulled low -> success */
bit_dbg(2, &i2c_adap->dev, "i2c_outb: 0x%02x %s\n", (int)c, bit_dbg(2, &i2c_adap->dev, "i2c_outb: 0x%02x %s\n", (int)c,
ack ? "A" : "NA"); ack ? "A" : "NA");
@@ -213,7 +218,7 @@ static int i2c_inb(struct i2c_adapter *i2c_adap)
bit_dbg(1, &i2c_adap->dev, "i2c_inb: timeout at bit " bit_dbg(1, &i2c_adap->dev, "i2c_inb: timeout at bit "
"#%d\n", 7 - i); "#%d\n", 7 - i);
return -ETIMEDOUT; return -ETIMEDOUT;
}; }
indata *= 2; indata *= 2;
if (getsda(adap)) if (getsda(adap))
indata |= 0x01; indata |= 0x01;
@@ -228,14 +233,15 @@ static int i2c_inb(struct i2c_adapter *i2c_adap)
* Sanity check for the adapter hardware - check the reaction of * Sanity check for the adapter hardware - check the reaction of
* the bus lines only if it seems to be idle. * the bus lines only if it seems to be idle.
*/ */
static int test_bus(struct i2c_algo_bit_data *adap, char* name) { static int test_bus(struct i2c_algo_bit_data *adap, char *name)
{
int scl, sda; int scl, sda;
if (adap->getscl == NULL) if (adap->getscl == NULL)
pr_info("%s: Testing SDA only, SCL is not readable\n", name); pr_info("%s: Testing SDA only, SCL is not readable\n", name);
sda = getsda(adap); sda = getsda(adap);
scl=(adap->getscl==NULL?1:getscl(adap)); scl = (adap->getscl == NULL) ? 1 : getscl(adap);
if (!scl || !sda) { if (!scl || !sda) {
printk(KERN_WARNING "%s: bus seems to be busy\n", name); printk(KERN_WARNING "%s: bus seems to be busy\n", name);
goto bailout; goto bailout;
@@ -243,12 +249,12 @@ static int test_bus(struct i2c_algo_bit_data *adap, char* name) {
sdalo(adap); sdalo(adap);
sda = getsda(adap); sda = getsda(adap);
scl=(adap->getscl==NULL?1:getscl(adap)); scl = (adap->getscl == NULL) ? 1 : getscl(adap);
if ( 0 != sda ) { if (sda) {
printk(KERN_WARNING "%s: SDA stuck high!\n", name); printk(KERN_WARNING "%s: SDA stuck high!\n", name);
goto bailout; goto bailout;
} }
if ( 0 == scl ) { if (!scl) {
printk(KERN_WARNING "%s: SCL unexpected low " printk(KERN_WARNING "%s: SCL unexpected low "
"while pulling SDA low!\n", name); "while pulling SDA low!\n", name);
goto bailout; goto bailout;
@@ -256,12 +262,12 @@ static int test_bus(struct i2c_algo_bit_data *adap, char* name) {
sdahi(adap); sdahi(adap);
sda = getsda(adap); sda = getsda(adap);
scl=(adap->getscl==NULL?1:getscl(adap)); scl = (adap->getscl == NULL) ? 1 : getscl(adap);
if ( 0 == sda ) { if (!sda) {
printk(KERN_WARNING "%s: SDA stuck low!\n", name); printk(KERN_WARNING "%s: SDA stuck low!\n", name);
goto bailout; goto bailout;
} }
if ( 0 == scl ) { if (!scl) {
printk(KERN_WARNING "%s: SCL unexpected low " printk(KERN_WARNING "%s: SCL unexpected low "
"while pulling SDA high!\n", name); "while pulling SDA high!\n", name);
goto bailout; goto bailout;
@@ -269,12 +275,12 @@ static int test_bus(struct i2c_algo_bit_data *adap, char* name) {
scllo(adap); scllo(adap);
sda = getsda(adap); sda = getsda(adap);
scl=(adap->getscl==NULL?0:getscl(adap)); scl = (adap->getscl == NULL) ? 0 : getscl(adap);
if ( 0 != scl ) { if (scl) {
printk(KERN_WARNING "%s: SCL stuck high!\n", name); printk(KERN_WARNING "%s: SCL stuck high!\n", name);
goto bailout; goto bailout;
} }
if ( 0 == sda ) { if (!sda) {
printk(KERN_WARNING "%s: SDA unexpected low " printk(KERN_WARNING "%s: SDA unexpected low "
"while pulling SCL low!\n", name); "while pulling SCL low!\n", name);
goto bailout; goto bailout;
@@ -282,12 +288,12 @@ static int test_bus(struct i2c_algo_bit_data *adap, char* name) {
sclhi(adap); sclhi(adap);
sda = getsda(adap); sda = getsda(adap);
scl=(adap->getscl==NULL?1:getscl(adap)); scl = (adap->getscl == NULL) ? 1 : getscl(adap);
if ( 0 == scl ) { if (!scl) {
printk(KERN_WARNING "%s: SCL stuck low!\n", name); printk(KERN_WARNING "%s: SCL stuck low!\n", name);
goto bailout; goto bailout;
} }
if ( 0 == sda ) { if (!sda) {
printk(KERN_WARNING "%s: SDA unexpected low " printk(KERN_WARNING "%s: SDA unexpected low "
"while pulling SCL high!\n", name); "while pulling SCL high!\n", name);
goto bailout; goto bailout;
@@ -315,6 +321,7 @@ static int try_address(struct i2c_adapter *i2c_adap,
{ {
struct i2c_algo_bit_data *adap = i2c_adap->algo_data; struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
int i, ret = -1; int i, ret = -1;
for (i = 0; i <= retries; i++) { for (i = 0; i <= retries; i++) {
ret = i2c_outb(i2c_adap, addr); ret = i2c_outb(i2c_adap, addr);
if (ret == 1 || i == retries) if (ret == 1 || i == retries)
@@ -344,7 +351,9 @@ static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
while (count > 0) { while (count > 0) {
retval = i2c_outb(i2c_adap, *temp); retval = i2c_outb(i2c_adap, *temp);
if ((retval>0) || (nak_ok && (retval==0))) { /* ok or ignored NAK */
/* OK/ACK; or ignored NAK */
if ((retval > 0) || (nak_ok && (retval == 0))) {
count--; count--;
temp++; temp++;
wrcount++; wrcount++;
@@ -444,7 +453,7 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
retries = nak_ok ? 0 : i2c_adap->retries; retries = nak_ok ? 0 : i2c_adap->retries;
if ( (flags & I2C_M_TEN) ) { if (flags & I2C_M_TEN) {
/* a ten bit address */ /* a ten bit address */
addr = 0xf0 | ((msg->addr >> 7) & 0x03); addr = 0xf0 | ((msg->addr >> 7) & 0x03);
bit_dbg(2, &i2c_adap->dev, "addr0: %d\n", addr); bit_dbg(2, &i2c_adap->dev, "addr0: %d\n", addr);
@@ -476,7 +485,7 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
} }
} }
} else { /* normal 7bit address */ } else { /* normal 7bit address */
addr = ( msg->addr << 1 ); addr = msg->addr << 1;
if (flags & I2C_M_RD) if (flags & I2C_M_RD)
addr |= 1; addr |= 1;
if (flags & I2C_M_REV_DIR_ADDR) if (flags & I2C_M_REV_DIR_ADDR)
@@ -494,7 +503,6 @@ static int bit_xfer(struct i2c_adapter *i2c_adap,
{ {
struct i2c_msg *pmsg; struct i2c_msg *pmsg;
struct i2c_algo_bit_data *adap = i2c_adap->algo_data; struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
int i, ret; int i, ret;
unsigned short nak_ok; unsigned short nak_ok;