i2c-pnx: Add stop conditions for end of transfer
[safe/jmp/linux-2.6] / drivers / i2c / i2c-dev.c
index af4491f..f4110aa 100644 (file)
@@ -34,7 +34,7 @@
 #include <linux/list.h>
 #include <linux/i2c.h>
 #include <linux/i2c-dev.h>
-#include <linux/smp_lock.h>
+#include <linux/jiffies.h>
 #include <asm/uaccess.h>
 
 static struct i2c_driver i2cdev_driver;
@@ -422,7 +422,10 @@ static long i2cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                client->adapter->retries = arg;
                break;
        case I2C_TIMEOUT:
-               client->adapter->timeout = arg;
+               /* For historical reasons, user-space sets the timeout
+                * value in units of 10 ms.
+                */
+               client->adapter->timeout = msecs_to_jiffies(arg * 10);
                break;
        default:
                /* NOTE:  returning a fault code here could cause trouble
@@ -441,20 +444,14 @@ static int i2cdev_open(struct inode *inode, struct file *file)
        struct i2c_client *client;
        struct i2c_adapter *adap;
        struct i2c_dev *i2c_dev;
-       int ret = 0;
 
-       lock_kernel();
        i2c_dev = i2c_dev_get_by_minor(minor);
-       if (!i2c_dev) {
-               ret = -ENODEV;
-               goto out;
-       }
+       if (!i2c_dev)
+               return -ENODEV;
 
        adap = i2c_get_adapter(i2c_dev->adap->nr);
-       if (!adap) {
-               ret = -ENODEV;
-               goto out;
-       }
+       if (!adap)
+               return -ENODEV;
 
        /* This creates an anonymous i2c_client, which may later be
         * pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE.
@@ -466,8 +463,7 @@ static int i2cdev_open(struct inode *inode, struct file *file)
        client = kzalloc(sizeof(*client), GFP_KERNEL);
        if (!client) {
                i2c_put_adapter(adap);
-               ret = -ENOMEM;
-               goto out;
+               return -ENOMEM;
        }
        snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr);
        client->driver = &i2cdev_driver;
@@ -475,9 +471,7 @@ static int i2cdev_open(struct inode *inode, struct file *file)
        client->adapter = adap;
        file->private_data = client;
 
-out:
-       unlock_kernel();
-       return ret;
+       return 0;
 }
 
 static int i2cdev_release(struct inode *inode, struct file *file)
@@ -521,9 +515,9 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap)
                return PTR_ERR(i2c_dev);
 
        /* register this i2c device with the driver core */
-       i2c_dev->dev = device_create_drvdata(i2c_dev_class, &adap->dev,
-                                            MKDEV(I2C_MAJOR, adap->nr),
-                                            NULL, "i2c-%d", adap->nr);
+       i2c_dev->dev = device_create(i2c_dev_class, &adap->dev,
+                                    MKDEV(I2C_MAJOR, adap->nr), NULL,
+                                    "i2c-%d", adap->nr);
        if (IS_ERR(i2c_dev->dev)) {
                res = PTR_ERR(i2c_dev->dev);
                goto error;
@@ -583,8 +577,10 @@ static int __init i2c_dev_init(void)
                goto out;
 
        i2c_dev_class = class_create(THIS_MODULE, "i2c-dev");
-       if (IS_ERR(i2c_dev_class))
+       if (IS_ERR(i2c_dev_class)) {
+               res = PTR_ERR(i2c_dev_class);
                goto out_unreg_chrdev;
+       }
 
        res = i2c_add_driver(&i2cdev_driver);
        if (res)