|
@@ -22,6 +22,7 @@
|
|
|
|
|
|
/* The I2C_RDWR ioctl code is written by Kolja Waschk <waschk@telos.de> */
|
|
|
|
|
|
+#include <linux/cdev.h>
|
|
|
#include <linux/device.h>
|
|
|
#include <linux/fs.h>
|
|
|
#include <linux/i2c-dev.h>
|
|
@@ -47,9 +48,10 @@ struct i2c_dev {
|
|
|
struct list_head list;
|
|
|
struct i2c_adapter *adap;
|
|
|
struct device *dev;
|
|
|
+ struct cdev cdev;
|
|
|
};
|
|
|
|
|
|
-#define I2C_MINORS 256
|
|
|
+#define I2C_MINORS MINORMASK
|
|
|
static LIST_HEAD(i2c_dev_list);
|
|
|
static DEFINE_SPINLOCK(i2c_dev_list_lock);
|
|
|
|
|
@@ -552,6 +554,12 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy)
|
|
|
if (IS_ERR(i2c_dev))
|
|
|
return PTR_ERR(i2c_dev);
|
|
|
|
|
|
+ cdev_init(&i2c_dev->cdev, &i2cdev_fops);
|
|
|
+ i2c_dev->cdev.owner = THIS_MODULE;
|
|
|
+ res = cdev_add(&i2c_dev->cdev, MKDEV(I2C_MAJOR, adap->nr), 1);
|
|
|
+ if (res)
|
|
|
+ goto error_cdev;
|
|
|
+
|
|
|
/* register this i2c device with the driver core */
|
|
|
i2c_dev->dev = device_create(i2c_dev_class, &adap->dev,
|
|
|
MKDEV(I2C_MAJOR, adap->nr), NULL,
|
|
@@ -565,6 +573,8 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy)
|
|
|
adap->name, adap->nr);
|
|
|
return 0;
|
|
|
error:
|
|
|
+ cdev_del(&i2c_dev->cdev);
|
|
|
+error_cdev:
|
|
|
return_i2c_dev(i2c_dev);
|
|
|
return res;
|
|
|
}
|
|
@@ -584,6 +594,7 @@ static int i2cdev_detach_adapter(struct device *dev, void *dummy)
|
|
|
|
|
|
return_i2c_dev(i2c_dev);
|
|
|
device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
|
|
|
+ cdev_del(&i2c_dev->cdev);
|
|
|
|
|
|
pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name);
|
|
|
return 0;
|
|
@@ -620,7 +631,7 @@ static int __init i2c_dev_init(void)
|
|
|
|
|
|
printk(KERN_INFO "i2c /dev entries driver\n");
|
|
|
|
|
|
- res = register_chrdev(I2C_MAJOR, "i2c", &i2cdev_fops);
|
|
|
+ res = register_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS, "i2c");
|
|
|
if (res)
|
|
|
goto out;
|
|
|
|
|
@@ -644,7 +655,7 @@ static int __init i2c_dev_init(void)
|
|
|
out_unreg_class:
|
|
|
class_destroy(i2c_dev_class);
|
|
|
out_unreg_chrdev:
|
|
|
- unregister_chrdev(I2C_MAJOR, "i2c");
|
|
|
+ unregister_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS);
|
|
|
out:
|
|
|
printk(KERN_ERR "%s: Driver Initialisation failed\n", __FILE__);
|
|
|
return res;
|
|
@@ -655,7 +666,7 @@ static void __exit i2c_dev_exit(void)
|
|
|
bus_unregister_notifier(&i2c_bus_type, &i2cdev_notifier);
|
|
|
i2c_for_each_dev(NULL, i2cdev_detach_adapter);
|
|
|
class_destroy(i2c_dev_class);
|
|
|
- unregister_chrdev(I2C_MAJOR, "i2c");
|
|
|
+ unregister_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS);
|
|
|
}
|
|
|
|
|
|
MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and "
|