Commit 0611825d authored by Subramaniam C.A's avatar Subramaniam C.A Committed by Hari Kanigeri

SysLink : Notify - Patch to add udev support for ipcnotify and ducati notify modules.

This patch adds udev support for ipcnotify and ducati notify
modules.
Signed-off-by: default avatarC A Subramaniam <subramaniam.ca@ti.com>
parent f29cf4fa
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/cdev.h>
#include <linux/io.h> #include <linux/io.h>
#include <asm/pgtable.h> #include <asm/pgtable.h>
...@@ -33,8 +34,28 @@ ...@@ -33,8 +34,28 @@
#include <syslink/GlobalTypes.h> #include <syslink/GlobalTypes.h>
/* Major number of driver */ /** ============================================================================
static signed long int major = 234 ; * Macros and types
* ============================================================================
*/
#define NOTIFYDUCATI_NAME "notifyducatidrv"
static char *driver_name = NOTIFYDUCATI_NAME;
static s32 driver_major;
static s32 driver_minor;
struct notifyducati_dev {
struct cdev cdev;
};
static struct notifyducati_dev *notifyducati_device;
static struct class *notifyducati_class;
/* driver function to open the notify mailbox driver object. */ /* driver function to open the notify mailbox driver object. */
...@@ -64,19 +85,70 @@ static const struct file_operations driver_ops = { ...@@ -64,19 +85,70 @@ static const struct file_operations driver_ops = {
/* Initialization function */ /* Initialization function */
static int __init drvducati_initialize_module(void) static int __init drvducati_initialize_module(void)
{ {
int result = 0; int result = 0 ;
dev_t dev;
if (driver_major) {
dev = MKDEV(driver_major, driver_minor);
result = register_chrdev_region(dev, 1, driver_name);
} else {
result = alloc_chrdev_region(&dev, driver_minor, 1,
driver_name);
driver_major = MAJOR(dev);
}
result = register_chrdev(major, "notifyducatidrv", &driver_ops); notifyducati_device = kmalloc(sizeof(struct notifyducati_dev),
if (result < 0) GFP_KERNEL);
pr_err("Notify ducati driver initialization file\n"); if (!notifyducati_device) {
result = -ENOMEM;
unregister_chrdev_region(dev, 1);
goto func_end;
}
memset(notifyducati_device, 0, sizeof(struct notifyducati_dev));
cdev_init(&notifyducati_device->cdev, &driver_ops);
notifyducati_device->cdev.owner = THIS_MODULE;
notifyducati_device->cdev.ops = &driver_ops;
result = cdev_add(&notifyducati_device->cdev, dev, 1);
if (result) {
printk(KERN_ERR "Failed to add the syslink notify ducati device \n");
goto func_end;
}
/* udev support */
notifyducati_class = class_create(THIS_MODULE, "syslink-notifyducati");
if (IS_ERR(notifyducati_class)) {
printk(KERN_ERR "Error creating notifyducati class \n");
goto func_end;
}
device_create(notifyducati_class, NULL,
MKDEV(driver_major, driver_minor), NULL,
NOTIFYDUCATI_NAME);
func_end:
return result ; return result ;
} }
/* Finalization function */ /* Finalization function */
static void __exit drvducati_finalize_module(void) static void __exit drvducati_finalize_module(void)
{ {
unregister_chrdev(major, "notifyducatidrv"); dev_t dev_no;
dev_no = MKDEV(driver_major, driver_minor);
if (notifyducati_device) {
cdev_del(&notifyducati_device->cdev);
kfree(notifyducati_device);
}
unregister_chrdev_region(dev_no, 1);
if (notifyducati_class) {
/* remove the device from sysfs */
device_destroy(notifyducati_class, MKDEV(driver_major,
driver_minor));
class_destroy(notifyducati_class);
}
} }
/* driver open*/ /* driver open*/
static int drvducati_open(struct inode *inode, struct file *filp) static int drvducati_open(struct inode *inode, struct file *filp)
......
...@@ -26,12 +26,35 @@ ...@@ -26,12 +26,35 @@
#include <linux/io.h> #include <linux/io.h>
#include <asm/pgtable.h> #include <asm/pgtable.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/cdev.h>
#include <syslink/gt.h> #include <syslink/gt.h>
#include <syslink/notify_driver.h> #include <syslink/notify_driver.h>
#include <syslink/notify.h> #include <syslink/notify.h>
#include <syslink/GlobalTypes.h> #include <syslink/GlobalTypes.h>
/** ============================================================================
* Macros and types
* ============================================================================
*/
#define IPCNOTIFY_NAME "ipcnotify"
static char *driver_name = IPCNOTIFY_NAME;
static s32 driver_major;
static s32 driver_minor;
struct ipcnotify_dev {
struct cdev cdev;
};
static struct ipcnotify_dev *ipcnotify_device;
static struct class *ipcnotify_class;
/* /*
* Maximum number of user supported. * Maximum number of user supported.
*/ */
...@@ -776,13 +799,44 @@ static void notify_drv_destroy(void) ...@@ -776,13 +799,44 @@ static void notify_drv_destroy(void)
static int __init notify_drv_init_module(void) static int __init notify_drv_init_module(void)
{ {
int result = 0 ; int result = 0 ;
dev_t dev;
if (driver_major) {
dev = MKDEV(driver_major, driver_minor);
result = register_chrdev_region(dev, 1, driver_name);
} else {
result = alloc_chrdev_region(&dev, driver_minor, 1,
driver_name);
driver_major = MAJOR(dev);
}
ipcnotify_device = kmalloc(sizeof(struct ipcnotify_dev), GFP_KERNEL);
if (!ipcnotify_device) {
result = -ENOMEM;
unregister_chrdev_region(dev, 1);
goto func_end;
}
memset(ipcnotify_device, 0, sizeof(struct ipcnotify_dev));
cdev_init(&ipcnotify_device->cdev, &driver_ops);
ipcnotify_device->cdev.owner = THIS_MODULE;
ipcnotify_device->cdev.ops = &driver_ops;
result = cdev_add(&ipcnotify_device->cdev, dev, 1);
result = register_chrdev(major, "ipcnotify", &driver_ops); if (result) {
printk(KERN_ERR "Failed to add the syslink ipcnotify device \n");
goto func_end;
}
/* udev support */
ipcnotify_class = class_create(THIS_MODULE, "syslink-ipcnotify");
if (result < 0) { if (IS_ERR(ipcnotify_class)) {
printk(KERN_ERR "Notify driver initialization failure - 1\n"); printk(KERN_ERR "Error creating ipcnotify class \n");
goto func_end; goto func_end;
} }
device_create(ipcnotify_class, NULL, MKDEV(driver_major, driver_minor),
NULL, IPCNOTIFY_NAME);
result = notify_drv_register_driver(); result = notify_drv_register_driver();
func_end: func_end:
return result ; return result ;
...@@ -791,9 +845,22 @@ func_end: ...@@ -791,9 +845,22 @@ func_end:
/* Module finalization function for Notify driver.*/ /* Module finalization function for Notify driver.*/
static void __exit notify_drv_finalize_module(void) static void __exit notify_drv_finalize_module(void)
{ {
unregister_chrdev(major, "ipcnotify") ; dev_t dev_no;
notify_drv_unregister_driver(); notify_drv_unregister_driver();
dev_no = MKDEV(driver_major, driver_minor);
if (ipcnotify_device) {
cdev_del(&ipcnotify_device->cdev);
kfree(ipcnotify_device);
}
unregister_chrdev_region(dev_no, 1);
if (ipcnotify_class) {
/* remove the device from sysfs */
device_destroy(ipcnotify_class, MKDEV(driver_major,
driver_minor));
class_destroy(ipcnotify_class);
}
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment