aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c28
-rw-r--r--drivers/i2c/i2c-dev.c22
2 files changed, 30 insertions, 20 deletions
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 1305ef190fc1..9e8c875437be 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -290,12 +290,12 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
290 * bus, or started a new i2c message 290 * bus, or started a new i2c message
291 */ 291 */
292 292
293 if (iicstat & S3C2410_IICSTAT_LASTBIT && 293 if (iicstat & S3C2410_IICSTAT_LASTBIT &&
294 !(i2c->msg->flags & I2C_M_IGNORE_NAK)) { 294 !(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
295 /* ack was not received... */ 295 /* ack was not received... */
296 296
297 dev_dbg(i2c->dev, "ack was not received\n"); 297 dev_dbg(i2c->dev, "ack was not received\n");
298 s3c24xx_i2c_stop(i2c, -EREMOTEIO); 298 s3c24xx_i2c_stop(i2c, -ENXIO);
299 goto out_ack; 299 goto out_ack;
300 } 300 }
301 301
@@ -305,7 +305,7 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
305 i2c->state = STATE_WRITE; 305 i2c->state = STATE_WRITE;
306 306
307 /* terminate the transfer if there is nothing to do 307 /* terminate the transfer if there is nothing to do
308 * (used by the i2c probe to find devices */ 308 * as this is used by the i2c probe to find devices. */
309 309
310 if (is_lastmsg(i2c) && i2c->msg->len == 0) { 310 if (is_lastmsg(i2c) && i2c->msg->len == 0) {
311 s3c24xx_i2c_stop(i2c, 0); 311 s3c24xx_i2c_stop(i2c, 0);
@@ -323,7 +323,17 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
323 * end of the message, and if so, work out what to do 323 * end of the message, and if so, work out what to do
324 */ 324 */
325 325
326 if (!(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
327 if (iicstat & S3C2410_IICSTAT_LASTBIT) {
328 dev_dbg(i2c->dev, "WRITE: No Ack\n");
329
330 s3c24xx_i2c_stop(i2c, -ECONNREFUSED);
331 goto out_ack;
332 }
333 }
334
326 retry_write: 335 retry_write:
336
327 if (!is_msgend(i2c)) { 337 if (!is_msgend(i2c)) {
328 byte = i2c->msg->buf[i2c->msg_ptr++]; 338 byte = i2c->msg->buf[i2c->msg_ptr++];
329 writeb(byte, i2c->regs + S3C2410_IICDS); 339 writeb(byte, i2c->regs + S3C2410_IICDS);
@@ -377,17 +387,6 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
377 * going to do any more read/write 387 * going to do any more read/write
378 */ 388 */
379 389
380 if (!(i2c->msg->flags & I2C_M_IGNORE_NAK) &&
381 !(is_msglast(i2c) && is_lastmsg(i2c))) {
382
383 if (iicstat & S3C2410_IICSTAT_LASTBIT) {
384 dev_dbg(i2c->dev, "READ: No Ack\n");
385
386 s3c24xx_i2c_stop(i2c, -ECONNREFUSED);
387 goto out_ack;
388 }
389 }
390
391 byte = readb(i2c->regs + S3C2410_IICDS); 390 byte = readb(i2c->regs + S3C2410_IICDS);
392 i2c->msg->buf[i2c->msg_ptr++] = byte; 391 i2c->msg->buf[i2c->msg_ptr++] = byte;
393 392
@@ -949,3 +948,4 @@ MODULE_DESCRIPTION("S3C24XX I2C Bus driver");
949MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); 948MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
950MODULE_LICENSE("GPL"); 949MODULE_LICENSE("GPL");
951MODULE_ALIAS("platform:s3c2410-i2c"); 950MODULE_ALIAS("platform:s3c2410-i2c");
951MODULE_ALIAS("platform:s3c2440-i2c");
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index d34c14c81c29..006a5857256a 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -34,6 +34,7 @@
34#include <linux/list.h> 34#include <linux/list.h>
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36#include <linux/i2c-dev.h> 36#include <linux/i2c-dev.h>
37#include <linux/smp_lock.h>
37#include <asm/uaccess.h> 38#include <asm/uaccess.h>
38 39
39static struct i2c_driver i2cdev_driver; 40static struct i2c_driver i2cdev_driver;
@@ -441,14 +442,20 @@ static int i2cdev_open(struct inode *inode, struct file *file)
441 struct i2c_client *client; 442 struct i2c_client *client;
442 struct i2c_adapter *adap; 443 struct i2c_adapter *adap;
443 struct i2c_dev *i2c_dev; 444 struct i2c_dev *i2c_dev;
445 int ret = 0;
444 446
447 lock_kernel();
445 i2c_dev = i2c_dev_get_by_minor(minor); 448 i2c_dev = i2c_dev_get_by_minor(minor);
446 if (!i2c_dev) 449 if (!i2c_dev) {
447 return -ENODEV; 450 ret = -ENODEV;
451 goto out;
452 }
448 453
449 adap = i2c_get_adapter(i2c_dev->adap->nr); 454 adap = i2c_get_adapter(i2c_dev->adap->nr);
450 if (!adap) 455 if (!adap) {
451 return -ENODEV; 456 ret = -ENODEV;
457 goto out;
458 }
452 459
453 /* This creates an anonymous i2c_client, which may later be 460 /* This creates an anonymous i2c_client, which may later be
454 * pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE. 461 * pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE.
@@ -460,7 +467,8 @@ static int i2cdev_open(struct inode *inode, struct file *file)
460 client = kzalloc(sizeof(*client), GFP_KERNEL); 467 client = kzalloc(sizeof(*client), GFP_KERNEL);
461 if (!client) { 468 if (!client) {
462 i2c_put_adapter(adap); 469 i2c_put_adapter(adap);
463 return -ENOMEM; 470 ret = -ENOMEM;
471 goto out;
464 } 472 }
465 snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr); 473 snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr);
466 client->driver = &i2cdev_driver; 474 client->driver = &i2cdev_driver;
@@ -468,7 +476,9 @@ static int i2cdev_open(struct inode *inode, struct file *file)
468 client->adapter = adap; 476 client->adapter = adap;
469 file->private_data = client; 477 file->private_data = client;
470 478
471 return 0; 479out:
480 unlock_kernel();
481 return ret;
472} 482}
473 483
474static int i2cdev_release(struct inode *inode, struct file *file) 484static int i2cdev_release(struct inode *inode, struct file *file)