diff options
Diffstat (limited to 'drivers/i2c/algos/i2c-algo-bit.c')
-rw-r--r-- | drivers/i2c/algos/i2c-algo-bit.c | 226 |
1 files changed, 125 insertions, 101 deletions
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c index a37cb6b8593c..35812823787b 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,20 +345,38 @@ 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 | |
352 | dev_err(&i2c_adap->dev, "sendbytes: error - bailout.\n"); | 361 | /* A slave NAKing the master means the slave didn't like |
353 | return (retval<0)? retval : -EFAULT; | 362 | * something about the data it saw. For example, maybe |
354 | /* got a better one ?? */ | 363 | * the SMBus PEC was wrong. |
364 | */ | ||
365 | } else if (retval == 0) { | ||
366 | dev_err(&i2c_adap->dev, "sendbytes: NAK bailout.\n"); | ||
367 | return -EIO; | ||
368 | |||
369 | /* Timeout; or (someday) lost arbitration | ||
370 | * | ||
371 | * FIXME Lost ARB implies retrying the transaction from | ||
372 | * the first message, after the "winning" master issues | ||
373 | * its STOP. As a rule, upper layer code has no reason | ||
374 | * to know or care about this ... it is *NOT* an error. | ||
375 | */ | ||
376 | } else { | ||
377 | dev_err(&i2c_adap->dev, "sendbytes: error %d\n", | ||
378 | retval); | ||
379 | return retval; | ||
355 | } | 380 | } |
356 | } | 381 | } |
357 | return wrcount; | 382 | return wrcount; |
@@ -376,14 +401,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) | 401 | static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) |
377 | { | 402 | { |
378 | int inval; | 403 | int inval; |
379 | int rdcount=0; /* counts bytes read */ | 404 | int rdcount = 0; /* counts bytes read */ |
380 | unsigned char *temp = msg->buf; | 405 | unsigned char *temp = msg->buf; |
381 | int count = msg->len; | 406 | int count = msg->len; |
382 | const unsigned flags = msg->flags; | 407 | const unsigned flags = msg->flags; |
383 | 408 | ||
384 | while (count > 0) { | 409 | while (count > 0) { |
385 | inval = i2c_inb(i2c_adap); | 410 | inval = i2c_inb(i2c_adap); |
386 | if (inval>=0) { | 411 | if (inval >= 0) { |
387 | *temp = inval; | 412 | *temp = inval; |
388 | rdcount++; | 413 | rdcount++; |
389 | } else { /* read timed out */ | 414 | } else { /* read timed out */ |
@@ -431,7 +456,7 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
431 | * returns: | 456 | * returns: |
432 | * 0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set | 457 | * 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 | 458 | * -x an error occurred (like: -EREMOTEIO if the device did not answer, or |
434 | * -ETIMEDOUT, for example if the lines are stuck...) | 459 | * -ETIMEDOUT, for example if the lines are stuck...) |
435 | */ | 460 | */ |
436 | static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | 461 | static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) |
437 | { | 462 | { |
@@ -443,10 +468,10 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
443 | int ret, retries; | 468 | int ret, retries; |
444 | 469 | ||
445 | retries = nak_ok ? 0 : i2c_adap->retries; | 470 | retries = nak_ok ? 0 : i2c_adap->retries; |
446 | 471 | ||
447 | if ( (flags & I2C_M_TEN) ) { | 472 | if (flags & I2C_M_TEN) { |
448 | /* a ten bit address */ | 473 | /* a ten bit address */ |
449 | addr = 0xf0 | (( msg->addr >> 7) & 0x03); | 474 | addr = 0xf0 | ((msg->addr >> 7) & 0x03); |
450 | bit_dbg(2, &i2c_adap->dev, "addr0: %d\n", addr); | 475 | bit_dbg(2, &i2c_adap->dev, "addr0: %d\n", addr); |
451 | /* try extended address code...*/ | 476 | /* try extended address code...*/ |
452 | ret = try_address(i2c_adap, addr, retries); | 477 | ret = try_address(i2c_adap, addr, retries); |
@@ -456,33 +481,33 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
456 | return -EREMOTEIO; | 481 | return -EREMOTEIO; |
457 | } | 482 | } |
458 | /* the remaining 8 bit address */ | 483 | /* the remaining 8 bit address */ |
459 | ret = i2c_outb(i2c_adap,msg->addr & 0x7f); | 484 | ret = i2c_outb(i2c_adap, msg->addr & 0x7f); |
460 | if ((ret != 1) && !nak_ok) { | 485 | if ((ret != 1) && !nak_ok) { |
461 | /* the chip did not ack / xmission error occurred */ | 486 | /* the chip did not ack / xmission error occurred */ |
462 | dev_err(&i2c_adap->dev, "died at 2nd address code\n"); | 487 | dev_err(&i2c_adap->dev, "died at 2nd address code\n"); |
463 | return -EREMOTEIO; | 488 | return -EREMOTEIO; |
464 | } | 489 | } |
465 | if ( flags & I2C_M_RD ) { | 490 | if (flags & I2C_M_RD) { |
466 | bit_dbg(3, &i2c_adap->dev, "emitting repeated " | 491 | bit_dbg(3, &i2c_adap->dev, "emitting repeated " |
467 | "start condition\n"); | 492 | "start condition\n"); |
468 | i2c_repstart(adap); | 493 | i2c_repstart(adap); |
469 | /* okay, now switch into reading mode */ | 494 | /* okay, now switch into reading mode */ |
470 | addr |= 0x01; | 495 | addr |= 0x01; |
471 | ret = try_address(i2c_adap, addr, retries); | 496 | ret = try_address(i2c_adap, addr, retries); |
472 | if ((ret!=1) && !nak_ok) { | 497 | if ((ret != 1) && !nak_ok) { |
473 | dev_err(&i2c_adap->dev, | 498 | dev_err(&i2c_adap->dev, |
474 | "died at repeated address code\n"); | 499 | "died at repeated address code\n"); |
475 | return -EREMOTEIO; | 500 | return -EREMOTEIO; |
476 | } | 501 | } |
477 | } | 502 | } |
478 | } else { /* normal 7bit address */ | 503 | } else { /* normal 7bit address */ |
479 | addr = ( msg->addr << 1 ); | 504 | addr = msg->addr << 1; |
480 | if (flags & I2C_M_RD ) | 505 | if (flags & I2C_M_RD) |
481 | addr |= 1; | 506 | addr |= 1; |
482 | if (flags & I2C_M_REV_DIR_ADDR ) | 507 | if (flags & I2C_M_REV_DIR_ADDR) |
483 | addr ^= 1; | 508 | addr ^= 1; |
484 | ret = try_address(i2c_adap, addr, retries); | 509 | ret = try_address(i2c_adap, addr, retries); |
485 | if ((ret!=1) && !nak_ok) | 510 | if ((ret != 1) && !nak_ok) |
486 | return -EREMOTEIO; | 511 | return -EREMOTEIO; |
487 | } | 512 | } |
488 | 513 | ||
@@ -494,15 +519,14 @@ static int bit_xfer(struct i2c_adapter *i2c_adap, | |||
494 | { | 519 | { |
495 | struct i2c_msg *pmsg; | 520 | struct i2c_msg *pmsg; |
496 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; | 521 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; |
497 | 522 | int i, ret; | |
498 | int i,ret; | ||
499 | unsigned short nak_ok; | 523 | unsigned short nak_ok; |
500 | 524 | ||
501 | bit_dbg(3, &i2c_adap->dev, "emitting start condition\n"); | 525 | bit_dbg(3, &i2c_adap->dev, "emitting start condition\n"); |
502 | i2c_start(adap); | 526 | i2c_start(adap); |
503 | for (i=0;i<num;i++) { | 527 | for (i = 0; i < num; i++) { |
504 | pmsg = &msgs[i]; | 528 | pmsg = &msgs[i]; |
505 | nak_ok = pmsg->flags & I2C_M_IGNORE_NAK; | 529 | nak_ok = pmsg->flags & I2C_M_IGNORE_NAK; |
506 | if (!(pmsg->flags & I2C_M_NOSTART)) { | 530 | if (!(pmsg->flags & I2C_M_NOSTART)) { |
507 | if (i) { | 531 | if (i) { |
508 | bit_dbg(3, &i2c_adap->dev, "emitting " | 532 | bit_dbg(3, &i2c_adap->dev, "emitting " |
@@ -517,7 +541,7 @@ static int bit_xfer(struct i2c_adapter *i2c_adap, | |||
517 | goto bailout; | 541 | goto bailout; |
518 | } | 542 | } |
519 | } | 543 | } |
520 | if (pmsg->flags & I2C_M_RD ) { | 544 | if (pmsg->flags & I2C_M_RD) { |
521 | /* read bytes into buffer*/ | 545 | /* read bytes into buffer*/ |
522 | ret = readbytes(i2c_adap, pmsg); | 546 | ret = readbytes(i2c_adap, pmsg); |
523 | if (ret >= 1) | 547 | if (ret >= 1) |
@@ -551,7 +575,7 @@ bailout: | |||
551 | 575 | ||
552 | static u32 bit_func(struct i2c_adapter *adap) | 576 | static u32 bit_func(struct i2c_adapter *adap) |
553 | { | 577 | { |
554 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | | 578 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | |
555 | I2C_FUNC_SMBUS_READ_BLOCK_DATA | | 579 | I2C_FUNC_SMBUS_READ_BLOCK_DATA | |
556 | I2C_FUNC_SMBUS_BLOCK_PROC_CALL | | 580 | I2C_FUNC_SMBUS_BLOCK_PROC_CALL | |
557 | I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING; | 581 | I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING; |
@@ -565,8 +589,8 @@ static const struct i2c_algorithm i2c_bit_algo = { | |||
565 | .functionality = bit_func, | 589 | .functionality = bit_func, |
566 | }; | 590 | }; |
567 | 591 | ||
568 | /* | 592 | /* |
569 | * registering functions to load algorithms at runtime | 593 | * registering functions to load algorithms at runtime |
570 | */ | 594 | */ |
571 | static int i2c_bit_prepare_bus(struct i2c_adapter *adap) | 595 | static int i2c_bit_prepare_bus(struct i2c_adapter *adap) |
572 | { | 596 | { |
@@ -574,7 +598,7 @@ static int i2c_bit_prepare_bus(struct i2c_adapter *adap) | |||
574 | 598 | ||
575 | if (bit_test) { | 599 | if (bit_test) { |
576 | int ret = test_bus(bit_adap, adap->name); | 600 | int ret = test_bus(bit_adap, adap->name); |
577 | if (ret<0) | 601 | if (ret < 0) |
578 | return -ENODEV; | 602 | return -ENODEV; |
579 | } | 603 | } |
580 | 604 | ||