diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-11-01 10:17:54 -0400 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-11-01 10:24:16 -0400 |
commit | 9e0a3169a34ba5fd04bde058a63fa0a36f2d7ed3 (patch) | |
tree | 61757133f86768e35a1540313fe48a88e18d3367 /drivers | |
parent | 46c3790eb523931a803bb3c28c5bf8bbfc8acf48 (diff) | |
download | talos-op-linux-9e0a3169a34ba5fd04bde058a63fa0a36f2d7ed3.tar.gz talos-op-linux-9e0a3169a34ba5fd04bde058a63fa0a36f2d7ed3.zip |
beceem: create class on module installation
First step to supporting multiple devices, create device class
when module is initialized.
Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/bcm/Bcmchar.c | 62 | ||||
-rw-r--r-- | drivers/staging/bcm/InterfaceInit.c | 14 |
2 files changed, 28 insertions, 48 deletions
diff --git a/drivers/staging/bcm/Bcmchar.c b/drivers/staging/bcm/Bcmchar.c index 3a1b9903bf07..1a255609aeda 100644 --- a/drivers/staging/bcm/Bcmchar.c +++ b/drivers/staging/bcm/Bcmchar.c @@ -12,7 +12,7 @@ * * Returns - Zero(Success) ****************************************************************/ -static struct class *bcm_class = NULL; + static int bcm_char_open(struct inode *inode, struct file * filp) { PMINI_ADAPTER Adapter = NULL; @@ -2093,59 +2093,37 @@ static struct file_operations bcm_fops = { .llseek = no_llseek, }; +extern struct class *bcm_class; int register_control_device_interface(PMINI_ADAPTER Adapter) { + if(Adapter->major>0) - return Adapter->major; - Adapter->major = register_chrdev(0, "tarang", &bcm_fops); - if(Adapter->major < 0) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "register_chrdev:Failed to registering WiMax control char device!"); - return Adapter->major; - } - - bcm_class = NULL; - bcm_class = class_create (THIS_MODULE, "tarang"); - if(IS_ERR (bcm_class)) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Unable to create class\n"); - unregister_chrdev(Adapter->major, "tarang"); - Adapter->major = 0; - return -ENODEV; + return Adapter->major; + + Adapter->major = register_chrdev(0, DEV_NAME, &bcm_fops); + if(Adapter->major < 0) { + pr_err(DRV_NAME ": could not created character device\n"); + return Adapter->major; } + Adapter->pstCreatedClassDevice = device_create (bcm_class, NULL, - MKDEV(Adapter->major, 0), -#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26) - NULL , -#endif - "tarang"); + MKDEV(Adapter->major, 0), Adapter, + DEV_NAME); - if(IS_ERR(Adapter->pstCreatedClassDevice)) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "class device did not get created : %ld", PTR_ERR(Adapter->pstCreatedClassDevice) ); + if(IS_ERR(Adapter->pstCreatedClassDevice)) { + pr_err(DRV_NAME ": class device create failed\n"); + unregister_chrdev(Adapter->major, DEV_NAME); + return PTR_ERR(Adapter->pstCreatedClassDevice); } - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Got Major No: %d", Adapter->major); - return 0; + + return 0; } void unregister_control_device_interface(PMINI_ADAPTER Adapter) { - if(Adapter->major > 0) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "destroying class device"); + if(Adapter->major > 0) { device_destroy (bcm_class, MKDEV(Adapter->major, 0)); + unregister_chrdev(Adapter->major, DEV_NAME); } - if(!IS_ERR(bcm_class)) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "destroying created class "); - class_destroy (bcm_class); - bcm_class = NULL; - } - if(Adapter->major > 0) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"unregistering character interface"); - unregister_chrdev(Adapter->major, "tarang"); - } - } diff --git a/drivers/staging/bcm/InterfaceInit.c b/drivers/staging/bcm/InterfaceInit.c index 6d62a50a2f48..161141d14565 100644 --- a/drivers/staging/bcm/InterfaceInit.c +++ b/drivers/staging/bcm/InterfaceInit.c @@ -738,6 +738,7 @@ static struct usb_driver usbbcm_driver = { .supports_autosuspend = 1, }; +struct class *bcm_class; /* Function: InterfaceInitialize @@ -755,16 +756,17 @@ Return: BCM_STATUS_SUCCESS - If Initialization of the */ INT InterfaceInitialize(void) { -// BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Registering Usb driver!!"); + bcm_class = class_create(THIS_MODULE, DRV_NAME); + if (IS_ERR(bcm_class)) { + printk(KERN_ERR DRV_NAME ": could not create class\n"); + return PTR_ERR(bcm_class); + } return usb_register(&usbbcm_driver); } INT InterfaceExit(void) { - //PMINI_ADAPTER psAdapter = NULL; - int status = 0; - - //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Deregistering Usb driver!!"); + class_destroy (bcm_class); usb_deregister(&usbbcm_driver); - return status; + return 0; } |