beceem: create class on module installation
authorStephen Hemminger <stephen.hemminger@vyatta.com>
Mon, 1 Nov 2010 14:17:54 +0000 (10:17 -0400)
committerStephen Hemminger <stephen.hemminger@vyatta.com>
Mon, 1 Nov 2010 14:24:16 +0000 (10:24 -0400)
First step to supporting multiple devices, create device class
when module is initialized.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
drivers/staging/bcm/Bcmchar.c
drivers/staging/bcm/InterfaceInit.c

index 3a1b9903bf074fa4b8cf3061acb385caa44854d6..1a255609aeda6891c5a53dc2e9aae597bb980dc4 100644 (file)
@@ -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");
-       }
-
 }
index 6d62a50a2f48e3917e835d8caf9cf4ffe945a7c1..161141d14565f3606947e5f2b3077a2f683dd50c 100644 (file)
@@ -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;
 }