diff options
| author | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-09-10 17:42:39 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-09-10 17:42:39 -0400 |
| commit | f3f94ce5dba6e134cf0958dd3a42ab28a028fc83 (patch) | |
| tree | 4539d11ddc93f000c96e3a21976cf4b4fe6742d1 | |
| parent | 5d9adefc1e7218d060a88416943dd18e86c3c975 (diff) | |
| parent | 939bc4943d0483961edc45b63a7d27b4ffe547e3 (diff) | |
Merge branch 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6
* 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6:
i2c-algo-bit: Read block data bugfix
i2c-pxa: Fix adapter number
i2c-gpio: Fix adapter number
| -rw-r--r-- | drivers/i2c/algos/i2c-algo-bit.c | 52 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-gpio.c | 2 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-pxa.c | 2 |
3 files changed, 34 insertions, 22 deletions
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c index 8a5f5825bb72..7f0a0a62cf60 100644 --- a/drivers/i2c/algos/i2c-algo-bit.c +++ b/drivers/i2c/algos/i2c-algo-bit.c | |||
| @@ -357,13 +357,29 @@ static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
| 357 | return wrcount; | 357 | return wrcount; |
| 358 | } | 358 | } |
| 359 | 359 | ||
| 360 | static int acknak(struct i2c_adapter *i2c_adap, int is_ack) | ||
| 361 | { | ||
| 362 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; | ||
| 363 | |||
| 364 | /* assert: sda is high */ | ||
| 365 | if (is_ack) /* send ack */ | ||
| 366 | setsda(adap, 0); | ||
| 367 | udelay((adap->udelay + 1) / 2); | ||
| 368 | if (sclhi(adap) < 0) { /* timeout */ | ||
| 369 | dev_err(&i2c_adap->dev, "readbytes: ack/nak timeout\n"); | ||
| 370 | return -ETIMEDOUT; | ||
| 371 | } | ||
| 372 | scllo(adap); | ||
| 373 | return 0; | ||
| 374 | } | ||
| 375 | |||
| 360 | static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | 376 | static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) |
| 361 | { | 377 | { |
| 362 | int inval; | 378 | int inval; |
| 363 | int rdcount=0; /* counts bytes read */ | 379 | int rdcount=0; /* counts bytes read */ |
| 364 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; | ||
| 365 | unsigned char *temp = msg->buf; | 380 | unsigned char *temp = msg->buf; |
| 366 | int count = msg->len; | 381 | int count = msg->len; |
| 382 | const unsigned flags = msg->flags; | ||
| 367 | 383 | ||
| 368 | while (count > 0) { | 384 | while (count > 0) { |
| 369 | inval = i2c_inb(i2c_adap); | 385 | inval = i2c_inb(i2c_adap); |
| @@ -377,28 +393,12 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
| 377 | temp++; | 393 | temp++; |
| 378 | count--; | 394 | count--; |
| 379 | 395 | ||
| 380 | if (msg->flags & I2C_M_NO_RD_ACK) { | ||
| 381 | bit_dbg(2, &i2c_adap->dev, "i2c_inb: 0x%02x\n", | ||
| 382 | inval); | ||
| 383 | continue; | ||
| 384 | } | ||
| 385 | |||
| 386 | /* assert: sda is high */ | ||
| 387 | if (count) /* send ack */ | ||
| 388 | setsda(adap, 0); | ||
| 389 | udelay((adap->udelay + 1) / 2); | ||
| 390 | bit_dbg(2, &i2c_adap->dev, "i2c_inb: 0x%02x %s\n", inval, | ||
| 391 | count ? "A" : "NA"); | ||
| 392 | if (sclhi(adap)<0) { /* timeout */ | ||
| 393 | dev_err(&i2c_adap->dev, "readbytes: timeout at ack\n"); | ||
| 394 | return -ETIMEDOUT; | ||
| 395 | }; | ||
| 396 | scllo(adap); | ||
| 397 | |||
| 398 | /* Some SMBus transactions require that we receive the | 396 | /* Some SMBus transactions require that we receive the |
| 399 | transaction length as the first read byte. */ | 397 | transaction length as the first read byte. */ |
| 400 | if (rdcount == 1 && (msg->flags & I2C_M_RECV_LEN)) { | 398 | if (rdcount == 1 && (flags & I2C_M_RECV_LEN)) { |
| 401 | if (inval <= 0 || inval > I2C_SMBUS_BLOCK_MAX) { | 399 | if (inval <= 0 || inval > I2C_SMBUS_BLOCK_MAX) { |
| 400 | if (!(flags & I2C_M_NO_RD_ACK)) | ||
| 401 | acknak(i2c_adap, 0); | ||
| 402 | dev_err(&i2c_adap->dev, "readbytes: invalid " | 402 | dev_err(&i2c_adap->dev, "readbytes: invalid " |
| 403 | "block length (%d)\n", inval); | 403 | "block length (%d)\n", inval); |
| 404 | return -EREMOTEIO; | 404 | return -EREMOTEIO; |
| @@ -409,6 +409,18 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
| 409 | count += inval; | 409 | count += inval; |
| 410 | msg->len += inval; | 410 | msg->len += inval; |
| 411 | } | 411 | } |
| 412 | |||
| 413 | bit_dbg(2, &i2c_adap->dev, "readbytes: 0x%02x %s\n", | ||
| 414 | inval, | ||
| 415 | (flags & I2C_M_NO_RD_ACK) | ||
| 416 | ? "(no ack/nak)" | ||
| 417 | : (count ? "A" : "NA")); | ||
| 418 | |||
| 419 | if (!(flags & I2C_M_NO_RD_ACK)) { | ||
| 420 | inval = acknak(i2c_adap, count); | ||
| 421 | if (inval < 0) | ||
| 422 | return inval; | ||
| 423 | } | ||
| 412 | } | 424 | } |
| 413 | return rdcount; | 425 | return rdcount; |
| 414 | } | 426 | } |
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c index 025f19423faf..44e1cd21bb01 100644 --- a/drivers/i2c/busses/i2c-gpio.c +++ b/drivers/i2c/busses/i2c-gpio.c | |||
| @@ -147,7 +147,7 @@ static int __init i2c_gpio_probe(struct platform_device *pdev) | |||
| 147 | * The reason to do so is to avoid sysfs names that only make | 147 | * The reason to do so is to avoid sysfs names that only make |
| 148 | * sense when there are multiple adapters. | 148 | * sense when there are multiple adapters. |
| 149 | */ | 149 | */ |
| 150 | adap->nr = pdev->id >= 0 ? pdev->id : 0; | 150 | adap->nr = (pdev->id != -1) ? pdev->id : 0; |
| 151 | ret = i2c_bit_add_numbered_bus(adap); | 151 | ret = i2c_bit_add_numbered_bus(adap); |
| 152 | if (ret) | 152 | if (ret) |
| 153 | goto err_add_bus; | 153 | goto err_add_bus; |
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index 9d6b790d4321..bb5466b27b59 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c | |||
| @@ -926,7 +926,7 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
| 926 | * The reason to do so is to avoid sysfs names that only make | 926 | * The reason to do so is to avoid sysfs names that only make |
| 927 | * sense when there are multiple adapters. | 927 | * sense when there are multiple adapters. |
| 928 | */ | 928 | */ |
| 929 | i2c->adap.nr = dev->id >= 0 ? dev->id : 0; | 929 | i2c->adap.nr = dev->id != -1 ? dev->id : 0; |
| 930 | 930 | ||
| 931 | ret = i2c_add_numbered_adapter(&i2c->adap); | 931 | ret = i2c_add_numbered_adapter(&i2c->adap); |
| 932 | if (ret < 0) { | 932 | if (ret < 0) { |
