i2c-pnx: Correct use of request_region/request_mem_region
[safe/jmp/linux-2.6] / drivers / i2c / i2c-dev.c
index e96d986..7e13d2d 100644 (file)
@@ -34,6 +34,8 @@
 #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;
@@ -146,7 +148,7 @@ static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count,
        if (tmp==NULL)
                return -ENOMEM;
 
-       pr_debug("i2c-dev: i2c-%d reading %zd bytes.\n",
+       pr_debug("i2c-dev: i2c-%d reading %zu bytes.\n",
                iminor(file->f_path.dentry->d_inode), count);
 
        ret = i2c_master_recv(client,tmp,count);
@@ -174,7 +176,7 @@ static ssize_t i2cdev_write (struct file *file, const char __user *buf, size_t c
                return -EFAULT;
        }
 
-       pr_debug("i2c-dev: i2c-%d writing %zd bytes.\n",
+       pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n",
                iminor(file->f_path.dentry->d_inode), count);
 
        ret = i2c_master_send(client,tmp,count);
@@ -421,7 +423,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
@@ -440,14 +445,20 @@ 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)
-               return -ENODEV;
+       if (!i2c_dev) {
+               ret = -ENODEV;
+               goto out;
+       }
 
        adap = i2c_get_adapter(i2c_dev->adap->nr);
-       if (!adap)
-               return -ENODEV;
+       if (!adap) {
+               ret = -ENODEV;
+               goto out;
+       }
 
        /* This creates an anonymous i2c_client, which may later be
         * pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE.
@@ -459,7 +470,8 @@ static int i2cdev_open(struct inode *inode, struct file *file)
        client = kzalloc(sizeof(*client), GFP_KERNEL);
        if (!client) {
                i2c_put_adapter(adap);
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto out;
        }
        snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr);
        client->driver = &i2cdev_driver;
@@ -467,7 +479,9 @@ static int i2cdev_open(struct inode *inode, struct file *file)
        client->adapter = adap;
        file->private_data = client;
 
-       return 0;
+out:
+       unlock_kernel();
+       return ret;
 }
 
 static int i2cdev_release(struct inode *inode, struct file *file)
@@ -512,7 +526,7 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap)
 
        /* register this i2c device with the driver core */
        i2c_dev->dev = device_create(i2c_dev_class, &adap->dev,
-                                    MKDEV(I2C_MAJOR, adap->nr),
+                                    MKDEV(I2C_MAJOR, adap->nr), NULL,
                                     "i2c-%d", adap->nr);
        if (IS_ERR(i2c_dev->dev)) {
                res = PTR_ERR(i2c_dev->dev);
@@ -548,19 +562,12 @@ static int i2cdev_detach_adapter(struct i2c_adapter *adap)
        return 0;
 }
 
-static int i2cdev_detach_client(struct i2c_client *client)
-{
-       return 0;
-}
-
 static struct i2c_driver i2cdev_driver = {
        .driver = {
                .name   = "dev_driver",
        },
-       .id             = I2C_DRIVERID_I2CDEV,
        .attach_adapter = i2cdev_attach_adapter,
        .detach_adapter = i2cdev_detach_adapter,
-       .detach_client  = i2cdev_detach_client,
 };
 
 /* ------------------------------------------------------------------------- */
@@ -580,8 +587,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)