diff options
author | David Brownell <david-b@pacbell.net> | 2008-01-27 12:14:46 -0500 |
---|---|---|
committer | Jean Delvare <khali@hyperion.delvare> | 2008-01-27 12:14:46 -0500 |
commit | cf978ab2846d86709802f38c80d1d53da364bf51 (patch) | |
tree | 306780b67dab2884a78d880eab1ff1e55dbffc87 /drivers | |
parent | 59d70df025473931c500d6d60510798e4bfa3279 (diff) |
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/i2c/algos/i2c-algo-bit.c | 202 |
1 files changed, 105 insertions, 97 deletions
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c index a37cb6b8593c..260c5d70b0b4 100644 --- a/drivers/i2c/algos/i2c-algo-bit.c +++ b/drivers/i2c/algos/i2c-algo-bit.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* ------------------------------------------------------------------------- */ | 1 | /* ------------------------------------------------------------------------- |
2 | /* i2c-algo-bit.c i2c driver algorithms for bit-shift adapters */ | 2 | * i2c-algo-bit.c i2c driver algorithms for bit-shift adapters |
3 | /* ------------------------------------------------------------------------- */ | 3 | * ------------------------------------------------------------------------- |
4 | /* Copyright (C) 1995-2000 Simon G. Vogl | 4 | * Copyright (C) 1995-2000 Simon G. Vogl |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
@@ -15,8 +15,8 @@ | |||
15 | 15 | ||
16 | You should have received a copy of the GNU General Public License | 16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | 17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | /* ------------------------------------------------------------------------- */ | 19 | * ------------------------------------------------------------------------- */ |
20 | 20 | ||
21 | /* With some changes from Frodo Looijaard <frodol@dds.nl>, Kyösti Mälkki | 21 | /* With some changes from Frodo Looijaard <frodol@dds.nl>, Kyösti Mälkki |
22 | <kmalkki@cc.hut.fi> and Jean Delvare <khali@linux-fr.org> */ | 22 | <kmalkki@cc.hut.fi> and Jean Delvare <khali@linux-fr.org> */ |
@@ -60,26 +60,26 @@ MODULE_PARM_DESC(i2c_debug, | |||
60 | 60 | ||
61 | /* --- setting states on the bus with the right timing: --------------- */ | 61 | /* --- setting states on the bus with the right timing: --------------- */ |
62 | 62 | ||
63 | #define setsda(adap,val) adap->setsda(adap->data, val) | 63 | #define setsda(adap, val) adap->setsda(adap->data, val) |
64 | #define setscl(adap,val) adap->setscl(adap->data, val) | 64 | #define setscl(adap, val) adap->setscl(adap->data, val) |
65 | #define getsda(adap) adap->getsda(adap->data) | 65 | #define getsda(adap) adap->getsda(adap->data) |
66 | #define getscl(adap) adap->getscl(adap->data) | 66 | #define getscl(adap) adap->getscl(adap->data) |
67 | 67 | ||
68 | static inline void sdalo(struct i2c_algo_bit_data *adap) | 68 | static inline void sdalo(struct i2c_algo_bit_data *adap) |
69 | { | 69 | { |
70 | setsda(adap,0); | 70 | setsda(adap, 0); |
71 | udelay((adap->udelay + 1) / 2); | 71 | udelay((adap->udelay + 1) / 2); |
72 | } | 72 | } |
73 | 73 | ||
74 | static inline void sdahi(struct i2c_algo_bit_data *adap) | 74 | static inline void sdahi(struct i2c_algo_bit_data *adap) |
75 | { | 75 | { |
76 | setsda(adap,1); | 76 | setsda(adap, 1); |
77 | udelay((adap->udelay + 1) / 2); | 77 | udelay((adap->udelay + 1) / 2); |
78 | } | 78 | } |
79 | 79 | ||
80 | static inline void scllo(struct i2c_algo_bit_data *adap) | 80 | static inline void scllo(struct i2c_algo_bit_data *adap) |
81 | { | 81 | { |
82 | setscl(adap,0); | 82 | setscl(adap, 0); |
83 | udelay(adap->udelay / 2); | 83 | udelay(adap->udelay / 2); |
84 | } | 84 | } |
85 | 85 | ||
@@ -91,22 +91,21 @@ static int sclhi(struct i2c_algo_bit_data *adap) | |||
91 | { | 91 | { |
92 | unsigned long start; | 92 | unsigned long start; |
93 | 93 | ||
94 | setscl(adap,1); | 94 | setscl(adap, 1); |
95 | 95 | ||
96 | /* Not all adapters have scl sense line... */ | 96 | /* Not all adapters have scl sense line... */ |
97 | if (!adap->getscl) | 97 | if (!adap->getscl) |
98 | goto done; | 98 | goto done; |
99 | 99 | ||
100 | start=jiffies; | 100 | start = jiffies; |
101 | while (! getscl(adap) ) { | 101 | while (!getscl(adap)) { |
102 | /* the hw knows how to read the clock line, | 102 | /* This hw knows how to read the clock line, so we wait |
103 | * so we wait until it actually gets high. | 103 | * until it actually gets high. This is safer as some |
104 | * This is safer as some chips may hold it low | 104 | * chips may hold it low ("clock stretching") while they |
105 | * while they are processing data internally. | 105 | * are processing data internally. |
106 | */ | 106 | */ |
107 | if (time_after_eq(jiffies, start+adap->timeout)) { | 107 | if (time_after_eq(jiffies, start + adap->timeout)) |
108 | return -ETIMEDOUT; | 108 | return -ETIMEDOUT; |
109 | } | ||
110 | cond_resched(); | 109 | cond_resched(); |
111 | } | 110 | } |
112 | #ifdef DEBUG | 111 | #ifdef DEBUG |
@@ -118,11 +117,11 @@ static int sclhi(struct i2c_algo_bit_data *adap) | |||
118 | done: | 117 | done: |
119 | udelay(adap->udelay); | 118 | udelay(adap->udelay); |
120 | return 0; | 119 | return 0; |
121 | } | 120 | } |
122 | 121 | ||
123 | 122 | ||
124 | /* --- other auxiliary functions -------------------------------------- */ | 123 | /* --- other auxiliary functions -------------------------------------- */ |
125 | static void i2c_start(struct i2c_algo_bit_data *adap) | 124 | static void i2c_start(struct i2c_algo_bit_data *adap) |
126 | { | 125 | { |
127 | /* assert: scl, sda are high */ | 126 | /* assert: scl, sda are high */ |
128 | setsda(adap, 0); | 127 | setsda(adap, 0); |
@@ -130,7 +129,7 @@ static void i2c_start(struct i2c_algo_bit_data *adap) | |||
130 | scllo(adap); | 129 | scllo(adap); |
131 | } | 130 | } |
132 | 131 | ||
133 | static void i2c_repstart(struct i2c_algo_bit_data *adap) | 132 | static void i2c_repstart(struct i2c_algo_bit_data *adap) |
134 | { | 133 | { |
135 | /* assert: scl is low */ | 134 | /* assert: scl is low */ |
136 | sdahi(adap); | 135 | sdahi(adap); |
@@ -141,18 +140,18 @@ static void i2c_repstart(struct i2c_algo_bit_data *adap) | |||
141 | } | 140 | } |
142 | 141 | ||
143 | 142 | ||
144 | static void i2c_stop(struct i2c_algo_bit_data *adap) | 143 | static void i2c_stop(struct i2c_algo_bit_data *adap) |
145 | { | 144 | { |
146 | /* assert: scl is low */ | 145 | /* assert: scl is low */ |
147 | sdalo(adap); | 146 | sdalo(adap); |
148 | sclhi(adap); | 147 | sclhi(adap); |
149 | setsda(adap, 1); | 148 | setsda(adap, 1); |
150 | udelay(adap->udelay); | 149 | udelay(adap->udelay); |
151 | } | 150 | } |
152 | 151 | ||
153 | 152 | ||
154 | 153 | ||
155 | /* send a byte without start cond., look for arbitration, | 154 | /* send a byte without start cond., look for arbitration, |
156 | check ackn. from slave */ | 155 | check ackn. from slave */ |
157 | /* returns: | 156 | /* returns: |
158 | * 1 if the device acknowledged | 157 | * 1 if the device acknowledged |
@@ -167,27 +166,33 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c) | |||
167 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; | 166 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; |
168 | 167 | ||
169 | /* assert: scl is low */ | 168 | /* assert: scl is low */ |
170 | for ( i=7 ; i>=0 ; i-- ) { | 169 | for (i = 7; i >= 0; i--) { |
171 | sb = (c >> i) & 1; | 170 | sb = (c >> i) & 1; |
172 | setsda(adap,sb); | 171 | setsda(adap, sb); |
173 | udelay((adap->udelay + 1) / 2); | 172 | udelay((adap->udelay + 1) / 2); |
174 | if (sclhi(adap)<0) { /* timed out */ | 173 | if (sclhi(adap) < 0) { /* timed out */ |
175 | bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, " | 174 | bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, " |
176 | "timeout at bit #%d\n", (int)c, i); | 175 | "timeout at bit #%d\n", (int)c, i); |
177 | return -ETIMEDOUT; | 176 | return -ETIMEDOUT; |
178 | }; | 177 | } |
179 | /* do arbitration here: | 178 | /* FIXME do arbitration here: |
180 | * if ( sb && ! getsda(adap) ) -> ouch! Get out of here. | 179 | * if (sb && !getsda(adap)) -> ouch! Get out of here. |
180 | * | ||
181 | * Report a unique code, so higher level code can retry | ||
182 | * the whole (combined) message and *NOT* issue STOP. | ||
181 | */ | 183 | */ |
182 | scllo(adap); | 184 | scllo(adap); |
183 | } | 185 | } |
184 | sdahi(adap); | 186 | sdahi(adap); |
185 | if (sclhi(adap)<0){ /* timeout */ | 187 | if (sclhi(adap) < 0) { /* timeout */ |
186 | bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, " | 188 | bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, " |
187 | "timeout at ack\n", (int)c); | 189 | "timeout at ack\n", (int)c); |
188 | return -ETIMEDOUT; | 190 | return -ETIMEDOUT; |
189 | }; | 191 | } |
190 | /* read ack: SDA should be pulled down by slave */ | 192 | |
193 | /* read ack: SDA should be pulled down by slave, or it may | ||
194 | * NAK (usually to report problems with the data we wrote). | ||
195 | */ | ||
191 | ack = !getsda(adap); /* ack: sda is pulled low -> success */ | 196 | ack = !getsda(adap); /* ack: sda is pulled low -> success */ |
192 | bit_dbg(2, &i2c_adap->dev, "i2c_outb: 0x%02x %s\n", (int)c, | 197 | bit_dbg(2, &i2c_adap->dev, "i2c_outb: 0x%02x %s\n", (int)c, |
193 | ack ? "A" : "NA"); | 198 | ack ? "A" : "NA"); |
@@ -198,24 +203,24 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c) | |||
198 | } | 203 | } |
199 | 204 | ||
200 | 205 | ||
201 | static int i2c_inb(struct i2c_adapter *i2c_adap) | 206 | static int i2c_inb(struct i2c_adapter *i2c_adap) |
202 | { | 207 | { |
203 | /* read byte via i2c port, without start/stop sequence */ | 208 | /* read byte via i2c port, without start/stop sequence */ |
204 | /* acknowledge is sent in i2c_read. */ | 209 | /* acknowledge is sent in i2c_read. */ |
205 | int i; | 210 | int i; |
206 | unsigned char indata=0; | 211 | unsigned char indata = 0; |
207 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; | 212 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; |
208 | 213 | ||
209 | /* assert: scl is low */ | 214 | /* assert: scl is low */ |
210 | sdahi(adap); | 215 | sdahi(adap); |
211 | for (i=0;i<8;i++) { | 216 | for (i = 0; i < 8; i++) { |
212 | if (sclhi(adap)<0) { /* timeout */ | 217 | if (sclhi(adap) < 0) { /* timeout */ |
213 | bit_dbg(1, &i2c_adap->dev, "i2c_inb: timeout at bit " | 218 | bit_dbg(1, &i2c_adap->dev, "i2c_inb: timeout at bit " |
214 | "#%d\n", 7 - i); | 219 | "#%d\n", 7 - i); |
215 | return -ETIMEDOUT; | 220 | return -ETIMEDOUT; |
216 | }; | 221 | } |
217 | indata *= 2; | 222 | indata *= 2; |
218 | if ( getsda(adap) ) | 223 | if (getsda(adap)) |
219 | indata |= 0x01; | 224 | indata |= 0x01; |
220 | setscl(adap, 0); | 225 | setscl(adap, 0); |
221 | udelay(i == 7 ? adap->udelay / 2 : adap->udelay); | 226 | udelay(i == 7 ? adap->udelay / 2 : adap->udelay); |
@@ -228,66 +233,67 @@ static int i2c_inb(struct i2c_adapter *i2c_adap) | |||
228 | * Sanity check for the adapter hardware - check the reaction of | 233 | * Sanity check for the adapter hardware - check the reaction of |
229 | * the bus lines only if it seems to be idle. | 234 | * the bus lines only if it seems to be idle. |
230 | */ | 235 | */ |
231 | static int test_bus(struct i2c_algo_bit_data *adap, char* name) { | 236 | static int test_bus(struct i2c_algo_bit_data *adap, char *name) |
232 | int scl,sda; | 237 | { |
238 | int scl, sda; | ||
233 | 239 | ||
234 | if (adap->getscl==NULL) | 240 | if (adap->getscl == NULL) |
235 | pr_info("%s: Testing SDA only, SCL is not readable\n", name); | 241 | pr_info("%s: Testing SDA only, SCL is not readable\n", name); |
236 | 242 | ||
237 | sda=getsda(adap); | 243 | sda = getsda(adap); |
238 | scl=(adap->getscl==NULL?1:getscl(adap)); | 244 | scl = (adap->getscl == NULL) ? 1 : getscl(adap); |
239 | if (!scl || !sda ) { | 245 | if (!scl || !sda) { |
240 | printk(KERN_WARNING "%s: bus seems to be busy\n", name); | 246 | printk(KERN_WARNING "%s: bus seems to be busy\n", name); |
241 | goto bailout; | 247 | goto bailout; |
242 | } | 248 | } |
243 | 249 | ||
244 | sdalo(adap); | 250 | sdalo(adap); |
245 | sda=getsda(adap); | 251 | sda = getsda(adap); |
246 | scl=(adap->getscl==NULL?1:getscl(adap)); | 252 | scl = (adap->getscl == NULL) ? 1 : getscl(adap); |
247 | if ( 0 != sda ) { | 253 | if (sda) { |
248 | printk(KERN_WARNING "%s: SDA stuck high!\n", name); | 254 | printk(KERN_WARNING "%s: SDA stuck high!\n", name); |
249 | goto bailout; | 255 | goto bailout; |
250 | } | 256 | } |
251 | if ( 0 == scl ) { | 257 | if (!scl) { |
252 | printk(KERN_WARNING "%s: SCL unexpected low " | 258 | printk(KERN_WARNING "%s: SCL unexpected low " |
253 | "while pulling SDA low!\n", name); | 259 | "while pulling SDA low!\n", name); |
254 | goto bailout; | 260 | goto bailout; |
255 | } | 261 | } |
256 | 262 | ||
257 | sdahi(adap); | 263 | sdahi(adap); |
258 | sda=getsda(adap); | 264 | sda = getsda(adap); |
259 | scl=(adap->getscl==NULL?1:getscl(adap)); | 265 | scl = (adap->getscl == NULL) ? 1 : getscl(adap); |
260 | if ( 0 == sda ) { | 266 | if (!sda) { |
261 | printk(KERN_WARNING "%s: SDA stuck low!\n", name); | 267 | printk(KERN_WARNING "%s: SDA stuck low!\n", name); |
262 | goto bailout; | 268 | goto bailout; |
263 | } | 269 | } |
264 | if ( 0 == scl ) { | 270 | if (!scl) { |
265 | printk(KERN_WARNING "%s: SCL unexpected low " | 271 | printk(KERN_WARNING "%s: SCL unexpected low " |
266 | "while pulling SDA high!\n", name); | 272 | "while pulling SDA high!\n", name); |
267 | goto bailout; | 273 | goto bailout; |
268 | } | 274 | } |
269 | 275 | ||
270 | scllo(adap); | 276 | scllo(adap); |
271 | sda=getsda(adap); | 277 | sda = getsda(adap); |
272 | scl=(adap->getscl==NULL?0:getscl(adap)); | 278 | scl = (adap->getscl == NULL) ? 0 : getscl(adap); |
273 | if ( 0 != scl ) { | 279 | if (scl) { |
274 | printk(KERN_WARNING "%s: SCL stuck high!\n", name); | 280 | printk(KERN_WARNING "%s: SCL stuck high!\n", name); |
275 | goto bailout; | 281 | goto bailout; |
276 | } | 282 | } |
277 | if ( 0 == sda ) { | 283 | if (!sda) { |
278 | printk(KERN_WARNING "%s: SDA unexpected low " | 284 | printk(KERN_WARNING "%s: SDA unexpected low " |
279 | "while pulling SCL low!\n", name); | 285 | "while pulling SCL low!\n", name); |
280 | goto bailout; | 286 | goto bailout; |
281 | } | 287 | } |
282 | 288 | ||
283 | sclhi(adap); | 289 | sclhi(adap); |
284 | sda=getsda(adap); | 290 | sda = getsda(adap); |
285 | scl=(adap->getscl==NULL?1:getscl(adap)); | 291 | scl = (adap->getscl == NULL) ? 1 : getscl(adap); |
286 | if ( 0 == scl ) { | 292 | if (!scl) { |
287 | printk(KERN_WARNING "%s: SCL stuck low!\n", name); | 293 | printk(KERN_WARNING "%s: SCL stuck low!\n", name); |
288 | goto bailout; | 294 | goto bailout; |
289 | } | 295 | } |
290 | if ( 0 == sda ) { | 296 | if (!sda) { |
291 | printk(KERN_WARNING "%s: SDA unexpected low " | 297 | printk(KERN_WARNING "%s: SDA unexpected low " |
292 | "while pulling SCL high!\n", name); | 298 | "while pulling SCL high!\n", name); |
293 | goto bailout; | 299 | goto bailout; |
@@ -314,9 +320,10 @@ static int try_address(struct i2c_adapter *i2c_adap, | |||
314 | unsigned char addr, int retries) | 320 | unsigned char addr, int retries) |
315 | { | 321 | { |
316 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; | 322 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; |
317 | int i,ret = -1; | 323 | int i, ret = -1; |
318 | for (i=0;i<=retries;i++) { | 324 | |
319 | ret = i2c_outb(i2c_adap,addr); | 325 | for (i = 0; i <= retries; i++) { |
326 | ret = i2c_outb(i2c_adap, addr); | ||
320 | if (ret == 1 || i == retries) | 327 | if (ret == 1 || i == retries) |
321 | break; | 328 | break; |
322 | bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n"); | 329 | bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n"); |
@@ -338,14 +345,16 @@ static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
338 | { | 345 | { |
339 | const unsigned char *temp = msg->buf; | 346 | const unsigned char *temp = msg->buf; |
340 | int count = msg->len; | 347 | int count = msg->len; |
341 | unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK; | 348 | unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK; |
342 | int retval; | 349 | int retval; |
343 | int wrcount=0; | 350 | int wrcount = 0; |
344 | 351 | ||
345 | while (count > 0) { | 352 | while (count > 0) { |
346 | retval = i2c_outb(i2c_adap, *temp); | 353 | retval = i2c_outb(i2c_adap, *temp); |
347 | if ((retval>0) || (nak_ok && (retval==0))) { /* ok or ignored NAK */ | 354 | |
348 | count--; | 355 | /* OK/ACK; or ignored NAK */ |
356 | if ((retval > 0) || (nak_ok && (retval == 0))) { | ||
357 | count--; | ||
349 | temp++; | 358 | temp++; |
350 | wrcount++; | 359 | wrcount++; |
351 | } else { /* arbitration or no acknowledge */ | 360 | } else { /* arbitration or no acknowledge */ |
@@ -376,14 +385,14 @@ static int acknak(struct i2c_adapter *i2c_adap, int is_ack) | |||
376 | static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | 385 | static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) |
377 | { | 386 | { |
378 | int inval; | 387 | int inval; |
379 | int rdcount=0; /* counts bytes read */ | 388 | int rdcount = 0; /* counts bytes read */ |
380 | unsigned char *temp = msg->buf; | 389 | unsigned char *temp = msg->buf; |
381 | int count = msg->len; | 390 | int count = msg->len; |
382 | const unsigned flags = msg->flags; | 391 | const unsigned flags = msg->flags; |
383 | 392 | ||
384 | while (count > 0) { | 393 | while (count > 0) { |
385 | inval = i2c_inb(i2c_adap); | 394 | inval = i2c_inb(i2c_adap); |
386 | if (inval>=0) { | 395 | if (inval >= 0) { |
387 | *temp = inval; | 396 | *temp = inval; |
388 | rdcount++; | 397 | rdcount++; |
389 | } else { /* read timed out */ | 398 | } else { /* read timed out */ |
@@ -431,7 +440,7 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
431 | * returns: | 440 | * returns: |
432 | * 0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set | 441 | * 0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set |
433 | * -x an error occurred (like: -EREMOTEIO if the device did not answer, or | 442 | * -x an error occurred (like: -EREMOTEIO if the device did not answer, or |
434 | * -ETIMEDOUT, for example if the lines are stuck...) | 443 | * -ETIMEDOUT, for example if the lines are stuck...) |
435 | */ | 444 | */ |
436 | static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | 445 | static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) |
437 | { | 446 | { |
@@ -443,10 +452,10 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
443 | int ret, retries; | 452 | int ret, retries; |
444 | 453 | ||
445 | retries = nak_ok ? 0 : i2c_adap->retries; | 454 | retries = nak_ok ? 0 : i2c_adap->retries; |
446 | 455 | ||
447 | if ( (flags & I2C_M_TEN) ) { | 456 | if (flags & I2C_M_TEN) { |
448 | /* a ten bit address */ | 457 | /* a ten bit address */ |
449 | addr = 0xf0 | (( msg->addr >> 7) & 0x03); | 458 | addr = 0xf0 | ((msg->addr >> 7) & 0x03); |
450 | bit_dbg(2, &i2c_adap->dev, "addr0: %d\n", addr); | 459 | bit_dbg(2, &i2c_adap->dev, "addr0: %d\n", addr); |
451 | /* try extended address code...*/ | 460 | /* try extended address code...*/ |
452 | ret = try_address(i2c_adap, addr, retries); | 461 | ret = try_address(i2c_adap, addr, retries); |
@@ -456,33 +465,33 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
456 | return -EREMOTEIO; | 465 | return -EREMOTEIO; |
457 | } | 466 | } |
458 | /* the remaining 8 bit address */ | 467 | /* the remaining 8 bit address */ |
459 | ret = i2c_outb(i2c_adap,msg->addr & 0x7f); | 468 | ret = i2c_outb(i2c_adap, msg->addr & 0x7f); |
460 | if ((ret != 1) && !nak_ok) { | 469 | if ((ret != 1) && !nak_ok) { |
461 | /* the chip did not ack / xmission error occurred */ | 470 | /* the chip did not ack / xmission error occurred */ |
462 | dev_err(&i2c_adap->dev, "died at 2nd address code\n"); | 471 | dev_err(&i2c_adap->dev, "died at 2nd address code\n"); |
463 | return -EREMOTEIO; | 472 | return -EREMOTEIO; |
464 | } | 473 | } |
465 | if ( flags & I2C_M_RD ) { | 474 | if (flags & I2C_M_RD) { |
466 | bit_dbg(3, &i2c_adap->dev, "emitting repeated " | 475 | bit_dbg(3, &i2c_adap->dev, "emitting repeated " |
467 | "start condition\n"); | 476 | "start condition\n"); |
468 | i2c_repstart(adap); | 477 | i2c_repstart(adap); |
469 | /* okay, now switch into reading mode */ | 478 | /* okay, now switch into reading mode */ |
470 | addr |= 0x01; | 479 | addr |= 0x01; |
471 | ret = try_address(i2c_adap, addr, retries); | 480 | ret = try_address(i2c_adap, addr, retries); |
472 | if ((ret!=1) && !nak_ok) { | 481 | if ((ret != 1) && !nak_ok) { |
473 | dev_err(&i2c_adap->dev, | 482 | dev_err(&i2c_adap->dev, |
474 | "died at repeated address code\n"); | 483 | "died at repeated address code\n"); |
475 | return -EREMOTEIO; | 484 | return -EREMOTEIO; |
476 | } | 485 | } |
477 | } | 486 | } |
478 | } else { /* normal 7bit address */ | 487 | } else { /* normal 7bit address */ |
479 | addr = ( msg->addr << 1 ); | 488 | addr = msg->addr << 1; |
480 | if (flags & I2C_M_RD ) | 489 | if (flags & I2C_M_RD) |
481 | addr |= 1; | 490 | addr |= 1; |
482 | if (flags & I2C_M_REV_DIR_ADDR ) | 491 | if (flags & I2C_M_REV_DIR_ADDR) |
483 | addr ^= 1; | 492 | addr ^= 1; |
484 | ret = try_address(i2c_adap, addr, retries); | 493 | ret = try_address(i2c_adap, addr, retries); |
485 | if ((ret!=1) && !nak_ok) | 494 | if ((ret != 1) && !nak_ok) |
486 | return -EREMOTEIO; | 495 | return -EREMOTEIO; |
487 | } | 496 | } |
488 | 497 | ||
@@ -494,15 +503,14 @@ static int bit_xfer(struct i2c_adapter *i2c_adap, | |||
494 | { | 503 | { |
495 | struct i2c_msg *pmsg; | 504 | struct i2c_msg *pmsg; |
496 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; | 505 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; |
497 | 506 | int i, ret; | |
498 | int i,ret; | ||
499 | unsigned short nak_ok; | 507 | unsigned short nak_ok; |
500 | 508 | ||
501 | bit_dbg(3, &i2c_adap->dev, "emitting start condition\n"); | 509 | bit_dbg(3, &i2c_adap->dev, "emitting start condition\n"); |
502 | i2c_start(adap); | 510 | i2c_start(adap); |
503 | for (i=0;i<num;i++) { | 511 | for (i = 0; i < num; i++) { |
504 | pmsg = &msgs[i]; | 512 | pmsg = &msgs[i]; |
505 | nak_ok = pmsg->flags & I2C_M_IGNORE_NAK; | 513 | nak_ok = pmsg->flags & I2C_M_IGNORE_NAK; |
506 | if (!(pmsg->flags & I2C_M_NOSTART)) { | 514 | if (!(pmsg->flags & I2C_M_NOSTART)) { |
507 | if (i) { | 515 | if (i) { |
508 | bit_dbg(3, &i2c_adap->dev, "emitting " | 516 | bit_dbg(3, &i2c_adap->dev, "emitting " |
@@ -517,7 +525,7 @@ static int bit_xfer(struct i2c_adapter *i2c_adap, | |||
517 | goto bailout; | 525 | goto bailout; |
518 | } | 526 | } |
519 | } | 527 | } |
520 | if (pmsg->flags & I2C_M_RD ) { | 528 | if (pmsg->flags & I2C_M_RD) { |
521 | /* read bytes into buffer*/ | 529 | /* read bytes into buffer*/ |
522 | ret = readbytes(i2c_adap, pmsg); | 530 | ret = readbytes(i2c_adap, pmsg); |
523 | if (ret >= 1) | 531 | if (ret >= 1) |
@@ -551,7 +559,7 @@ bailout: | |||
551 | 559 | ||
552 | static u32 bit_func(struct i2c_adapter *adap) | 560 | static u32 bit_func(struct i2c_adapter *adap) |
553 | { | 561 | { |
554 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | | 562 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | |
555 | I2C_FUNC_SMBUS_READ_BLOCK_DATA | | 563 | I2C_FUNC_SMBUS_READ_BLOCK_DATA | |
556 | I2C_FUNC_SMBUS_BLOCK_PROC_CALL | | 564 | I2C_FUNC_SMBUS_BLOCK_PROC_CALL | |
557 | I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING; | 565 | I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING; |
@@ -565,8 +573,8 @@ static const struct i2c_algorithm i2c_bit_algo = { | |||
565 | .functionality = bit_func, | 573 | .functionality = bit_func, |
566 | }; | 574 | }; |
567 | 575 | ||
568 | /* | 576 | /* |
569 | * registering functions to load algorithms at runtime | 577 | * registering functions to load algorithms at runtime |
570 | */ | 578 | */ |
571 | static int i2c_bit_prepare_bus(struct i2c_adapter *adap) | 579 | static int i2c_bit_prepare_bus(struct i2c_adapter *adap) |
572 | { | 580 | { |
@@ -574,7 +582,7 @@ static int i2c_bit_prepare_bus(struct i2c_adapter *adap) | |||
574 | 582 | ||
575 | if (bit_test) { | 583 | if (bit_test) { |
576 | int ret = test_bus(bit_adap, adap->name); | 584 | int ret = test_bus(bit_adap, adap->name); |
577 | if (ret<0) | 585 | if (ret < 0) |
578 | return -ENODEV; | 586 | return -ENODEV; |
579 | } | 587 | } |
580 | 588 | ||