|
|
@@ -72,6 +72,9 @@
|
|
|
|
|
|
static unsigned int max_units, chip_type;
|
|
|
|
|
|
+static int major = 56;
|
|
|
+static int minor = 30;
|
|
|
+
|
|
|
static unsigned int timeout = DEFAULT_TIMEOUT;
|
|
|
static int testmode = DEFAULT_TESTMODE;
|
|
|
|
|
|
@@ -84,6 +87,9 @@ MODULE_PARM_DESC(testmode, "Watchdog test mode (1 = no reboot), default="
|
|
|
|
|
|
/* Character device variables */
|
|
|
static int major_number;
|
|
|
+static dev_t dev_num;
|
|
|
+
|
|
|
+static struct cdev cdev;
|
|
|
static struct class *watchdog_class = NULL;
|
|
|
static struct device *watchdog_device = NULL;
|
|
|
|
|
|
@@ -594,11 +600,27 @@ int watchdog_init(void)
|
|
|
timeout = wdt_round_time(timeout);
|
|
|
|
|
|
/* Register character device */
|
|
|
- major_number = register_chrdev(0, DEVICE_NAME, &watchdog_fops);
|
|
|
- if (major_number < 0) {
|
|
|
+
|
|
|
+ dev_num = MKDEV(major, minor);
|
|
|
+ rc = register_chrdev_region(dev_num, 1, DEVICE_NAME);
|
|
|
+ if (rc < 0) {
|
|
|
pr_err("Failed to register character device\n");
|
|
|
- return major_number;
|
|
|
+ return rc;
|
|
|
}
|
|
|
+ cdev_init(&cdev, &watchdog_fops);
|
|
|
+ cdev.owner = THIS_MODULE;
|
|
|
+ rc = cdev_add(&cdev, dev_num, 1);
|
|
|
+ if (rc)
|
|
|
+ {
|
|
|
+ printk(KERN_ALERT "ssegment: Failed to add cdev\n");
|
|
|
+ unregister_chrdev_region(dev_num, 1);
|
|
|
+ return rc;
|
|
|
+ }
|
|
|
+ // major_number = register_chrdev(0, DEVICE_NAME, &watchdog_fops);
|
|
|
+ // if (major_number < 0) {
|
|
|
+ // pr_err("Failed to register character device\n");
|
|
|
+ // return major_number;
|
|
|
+ // }
|
|
|
|
|
|
/* Create device class */
|
|
|
watchdog_class = class_create(THIS_MODULE, CLASS_NAME);
|
|
|
@@ -612,8 +634,7 @@ int watchdog_init(void)
|
|
|
|
|
|
/* Create device node /dev/watchdog */
|
|
|
watchdog_device = device_create(watchdog_class, NULL,
|
|
|
- MKDEV(major_number, 0),
|
|
|
- NULL, DEVICE_NAME);
|
|
|
+ dev_num, NULL, DEVICE_NAME);
|
|
|
if (IS_ERR(watchdog_device)) {
|
|
|
class_destroy(watchdog_class);
|
|
|
unregister_chrdev(major_number, DEVICE_NAME);
|
|
|
@@ -648,9 +669,9 @@ void watchdog_exit(void)
|
|
|
kobject_put(watchdog_kobj);
|
|
|
|
|
|
/* Remove device */
|
|
|
- device_destroy(watchdog_class, MKDEV(major_number, 0));
|
|
|
+ device_destroy(watchdog_class, MKDEV(major, minor));
|
|
|
class_destroy(watchdog_class);
|
|
|
- unregister_chrdev(major_number, DEVICE_NAME);
|
|
|
+ unregister_chrdev_region(MKDEV(major, minor), 1);
|
|
|
|
|
|
pr_info("Watchdog driver exited\n");
|
|
|
}
|