aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses
diff options
context:
space:
mode:
authorBen Gardner <bgardner@wabtec.com>2006-01-18 16:44:04 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-03-23 17:21:49 -0500
commit9b7b6d3b2b46c5c336a441ed12b504ee192e63b3 (patch)
tree199e4ffbcd7398e416eff70a4b35386310f123d9 /drivers/i2c/busses
parentef4d9275e2949976cb43c8bd0c11cb77b9b017e9 (diff)
[PATCH] i2c: scx200_acb refactor/simplify code
scx200_acb: refactor/simplify code (no functional changes) Signed-off-by: Ben Gardner <bgardner@wabtec.com> Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/i2c/busses')
-rw-r--r--drivers/i2c/busses/scx200_acb.c73
1 files changed, 29 insertions, 44 deletions
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index bfa243d5a8f2..517a050625f1 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -124,8 +124,17 @@ static void scx200_acb_machine(struct scx200_acb_iface *iface, u8 status)
124 errmsg = "not master"; 124 errmsg = "not master";
125 goto error; 125 goto error;
126 } 126 }
127 if (status & ACBST_NEGACK) 127 if (status & ACBST_NEGACK) {
128 goto negack; 128 dev_dbg(&iface->adapter.dev, "negative ack in state %s\n",
129 scx200_acb_state_name[iface->state]);
130
131 iface->state = state_idle;
132 iface->result = -ENXIO;
133
134 outb(inb(ACBCTL1) | ACBCTL1_STOP, ACBCTL1);
135 outb(ACBST_STASTR | ACBST_NEGACK, ACBST);
136 return;
137 }
129 138
130 switch (iface->state) { 139 switch (iface->state) {
131 case state_idle: 140 case state_idle:
@@ -202,17 +211,6 @@ static void scx200_acb_machine(struct scx200_acb_iface *iface, u8 status)
202 211
203 return; 212 return;
204 213
205 negack:
206 dev_dbg(&iface->adapter.dev, "negative ack in state %s\n",
207 scx200_acb_state_name[iface->state]);
208
209 iface->state = state_idle;
210 iface->result = -ENXIO;
211
212 outb(inb(ACBCTL1) | ACBCTL1_STOP, ACBCTL1);
213 outb(ACBST_STASTR | ACBST_NEGACK, ACBST);
214 return;
215
216 error: 214 error:
217 dev_err(&iface->adapter.dev, "%s in state %s\n", errmsg, 215 dev_err(&iface->adapter.dev, "%s in state %s\n", errmsg,
218 scx200_acb_state_name[iface->state]); 216 scx200_acb_state_name[iface->state]);
@@ -222,20 +220,10 @@ static void scx200_acb_machine(struct scx200_acb_iface *iface, u8 status)
222 iface->needs_reset = 1; 220 iface->needs_reset = 1;
223} 221}
224 222
225static void scx200_acb_timeout(struct scx200_acb_iface *iface)
226{
227 dev_err(&iface->adapter.dev, "timeout in state %s\n",
228 scx200_acb_state_name[iface->state]);
229
230 iface->state = state_idle;
231 iface->result = -EIO;
232 iface->needs_reset = 1;
233}
234
235#ifdef POLLED_MODE 223#ifdef POLLED_MODE
236static void scx200_acb_poll(struct scx200_acb_iface *iface) 224static void scx200_acb_poll(struct scx200_acb_iface *iface)
237{ 225{
238 u8 status = 0; 226 u8 status;
239 unsigned long timeout; 227 unsigned long timeout;
240 228
241 timeout = jiffies + POLL_TIMEOUT; 229 timeout = jiffies + POLL_TIMEOUT;
@@ -248,7 +236,12 @@ static void scx200_acb_poll(struct scx200_acb_iface *iface)
248 msleep(10); 236 msleep(10);
249 } 237 }
250 238
251 scx200_acb_timeout(iface); 239 dev_err(&iface->adapter.dev, "timeout in state %s\n",
240 scx200_acb_state_name[iface->state]);
241
242 iface->state = state_idle;
243 iface->result = -EIO;
244 iface->needs_reset = 1;
252} 245}
253#endif /* POLLED_MODE */ 246#endif /* POLLED_MODE */
254 247
@@ -291,13 +284,8 @@ static s32 scx200_acb_smbus_xfer(struct i2c_adapter *adapter,
291 break; 284 break;
292 285
293 case I2C_SMBUS_BYTE: 286 case I2C_SMBUS_BYTE:
294 if (rw == I2C_SMBUS_READ) { 287 len = 1;
295 len = 1; 288 buffer = rw ? &data->byte : &command;
296 buffer = &data->byte;
297 } else {
298 len = 1;
299 buffer = &command;
300 }
301 break; 289 break;
302 290
303 case I2C_SMBUS_BYTE_DATA: 291 case I2C_SMBUS_BYTE_DATA:
@@ -331,9 +319,7 @@ static s32 scx200_acb_smbus_xfer(struct i2c_adapter *adapter,
331 319
332 down(&iface->sem); 320 down(&iface->sem);
333 321
334 iface->address_byte = address<<1; 322 iface->address_byte = (address << 1) | rw;
335 if (rw == I2C_SMBUS_READ)
336 iface->address_byte |= 1;
337 iface->command = command; 323 iface->command = command;
338 iface->ptr = buffer; 324 iface->ptr = buffer;
339 iface->len = len; 325 iface->len = len;
@@ -433,7 +419,7 @@ static int __init scx200_acb_create(int base, int index)
433{ 419{
434 struct scx200_acb_iface *iface; 420 struct scx200_acb_iface *iface;
435 struct i2c_adapter *adapter; 421 struct i2c_adapter *adapter;
436 int rc = 0; 422 int rc;
437 char description[64]; 423 char description[64];
438 424
439 iface = kzalloc(sizeof(*iface), GFP_KERNEL); 425 iface = kzalloc(sizeof(*iface), GFP_KERNEL);
@@ -459,14 +445,14 @@ static int __init scx200_acb_create(int base, int index)
459 printk(KERN_ERR NAME ": can't allocate io 0x%x-0x%x\n", 445 printk(KERN_ERR NAME ": can't allocate io 0x%x-0x%x\n",
460 base, base + 8-1); 446 base, base + 8-1);
461 rc = -EBUSY; 447 rc = -EBUSY;
462 goto errout; 448 goto errout_free;
463 } 449 }
464 iface->base = base; 450 iface->base = base;
465 451
466 rc = scx200_acb_probe(iface); 452 rc = scx200_acb_probe(iface);
467 if (rc) { 453 if (rc) {
468 printk(KERN_WARNING NAME ": probe failed\n"); 454 printk(KERN_WARNING NAME ": probe failed\n");
469 goto errout; 455 goto errout_release;
470 } 456 }
471 457
472 scx200_acb_reset(iface); 458 scx200_acb_reset(iface);
@@ -474,7 +460,7 @@ static int __init scx200_acb_create(int base, int index)
474 if (i2c_add_adapter(adapter) < 0) { 460 if (i2c_add_adapter(adapter) < 0) {
475 printk(KERN_ERR NAME ": failed to register\n"); 461 printk(KERN_ERR NAME ": failed to register\n");
476 rc = -ENODEV; 462 rc = -ENODEV;
477 goto errout; 463 goto errout_release;
478 } 464 }
479 465
480 lock_kernel(); 466 lock_kernel();
@@ -484,12 +470,11 @@ static int __init scx200_acb_create(int base, int index)
484 470
485 return 0; 471 return 0;
486 472
473 errout_release:
474 release_region(iface->base, 8);
475 errout_free:
476 kfree(iface);
487 errout: 477 errout:
488 if (iface) {
489 if (iface->base)
490 release_region(iface->base, 8);
491 kfree(iface);
492 }
493 return rc; 478 return rc;
494} 479}
495 480