touchscreen: optimize module init flow
authorQianggui Song <qianggui.song@amlogic.com>
Wed, 4 Jul 2018 05:42:37 +0000 (13:42 +0800)
committerYixun Lan <yixun.lan@amlogic.com>
Thu, 19 Jul 2018 02:35:29 +0000 (19:35 -0700)
PD#169285: touchscreen: optimize module init flow

1.Initializing/Uninitializing resource in probe/remove function is more
appropriate in this case.
2.Use module_i2c_driver to replace module_init/exit to make code more
compact.
verify on a311d_w400

Change-Id: If02f12a6c290a6346d439785060e60a6cd815c12
Signed-off-by: Qianggui Song <qianggui.song@amlogic.com>
drivers/amlogic/input/touchscreen/focaltech_touch/focaltech_core.c
drivers/amlogic/input/touchscreen/goodix_gt1x/gt1x.c
drivers/amlogic/input/touchscreen/goodix_gt9xx/gt9xx.c

index 0672aa5d38d823e2fbc34af9570737df6e15d7f6..5e8cd663e4e6fc01c6c86709001a16649fa163d4 100644 (file)
@@ -1449,41 +1449,7 @@ static struct i2c_driver fts_ts_driver =
     .id_table = fts_ts_id,
 };
 
-/*****************************************************************************
-*  Name: fts_ts_init
-*  Brief:
-*  Input:
-*  Output:
-*  Return:
-*****************************************************************************/
-static int __init fts_ts_init(void)
-{
-    int ret = 0;
-
-    FTS_FUNC_ENTER();
-    ret = i2c_add_driver(&fts_ts_driver);
-    if ( ret != 0 )
-    {
-        FTS_ERROR("Focaltech touch screen driver init failed!");
-    }
-    FTS_FUNC_EXIT();
-    return ret;
-}
-
-/*****************************************************************************
-*  Name: fts_ts_exit
-*  Brief:
-*  Input:
-*  Output:
-*  Return:
-*****************************************************************************/
-static void __exit fts_ts_exit(void)
-{
-    i2c_del_driver(&fts_ts_driver);
-}
-
-module_init(fts_ts_init);
-module_exit(fts_ts_exit);
+module_i2c_driver(fts_ts_driver);
 
 MODULE_AUTHOR("FocalTech Driver Team");
 MODULE_DESCRIPTION("FocalTech Touchscreen Driver");
index 8882585f14fc112be0482cbacde01677d4c458fe..509b716078af293fe540d3be0fa979078f6591e9 100644 (file)
@@ -534,9 +534,17 @@ static int gt1x_ts_probe(struct i2c_client *client, const struct i2c_device_id *
        gt1x_i2c_client = client;
        spin_lock_init(&irq_lock);
 
+       gt1x_wq = create_singlethread_workqueue("gt1x_wq");
+       if (!gt1x_wq) {
+               GTP_ERROR("Create workqueue failed.");
+               ret = -ENOMEM;
+               goto err_create_workqueue;
+       }
+
        if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
                GTP_ERROR("I2C check functionality failed.");
-               return -ENODEV;
+               ret = -ENODEV;
+               goto err_i2c_check_func;
        }
 
 #ifdef GTP_CONFIG_OF   /* device tree support */
@@ -548,7 +556,7 @@ static int gt1x_ts_probe(struct i2c_client *client, const struct i2c_device_id *
        ret = gt1x_request_io_port();
        if (ret < 0) {
                GTP_ERROR("GTP request IO port failed.");
-               return ret;
+               goto err_request_io_port;
        }
 
        gt1x_init();
@@ -558,6 +566,7 @@ static int gt1x_ts_probe(struct i2c_client *client, const struct i2c_device_id *
        ret = gt1x_request_input_dev();
        if (ret < 0) {
                GTP_ERROR("GTP request input dev failed");
+               goto err_request_input_dev;
        }
 
        ret = gt1x_request_irq();
@@ -589,6 +598,15 @@ static int gt1x_ts_probe(struct i2c_client *client, const struct i2c_device_id *
 #endif
        gt1x_register_powermanger();
        return 0;
+
+err_request_input_dev:
+       gt1x_remove_gpio_and_power();
+err_request_io_port:
+err_i2c_check_func:
+       destroy_workqueue(gt1x_wq);
+err_create_workqueue:
+       return ret;
+
 }
 
 /**
@@ -605,11 +623,14 @@ static int gt1x_ts_remove(struct i2c_client *client)
 #if GTP_GESTURE_WAKEUP
        disable_irq_wake(client->irq);
 #endif
-    gt1x_deinit();
+       gt1x_deinit();
        input_unregister_device(input_dev);
-    gt1x_remove_gpio_and_power();
+       gt1x_remove_gpio_and_power();
 
-    return 0;
+       if (gt1x_wq)
+               destroy_workqueue(gt1x_wq);
+
+       return 0;
 }
 
 #if   defined(CONFIG_FB)
@@ -751,39 +772,7 @@ static struct i2c_driver gt1x_ts_driver = {
                   },
 };
 
-/**
- * gt1x_ts_init - Driver Install function.
- * Return   0---succeed.
- */
-static int __init gt1x_ts_init(void)
-{
-       GTP_DEBUG_FUNC();
-       GTP_INFO("GTP driver installing...");
-       gt1x_wq = create_singlethread_workqueue("gt1x_wq");
-       if (!gt1x_wq) {
-               GTP_ERROR("Creat workqueue failed.");
-               return -ENOMEM;
-       }
-
-       return i2c_add_driver(&gt1x_ts_driver);
-}
-
-/**
- * gt1x_ts_exit - Driver uninstall function.
- * Return   0---succeed.
- */
-static void __exit gt1x_ts_exit(void)
-{
-       GTP_DEBUG_FUNC();
-       GTP_INFO("GTP driver exited.");
-       i2c_del_driver(&gt1x_ts_driver);
-       if (gt1x_wq) {
-               destroy_workqueue(gt1x_wq);
-       }
-}
-
-module_init(gt1x_ts_init);
-module_exit(gt1x_ts_exit);
+module_i2c_driver(gt1x_ts_driver);
 
 MODULE_DESCRIPTION("GTP Series Driver");
 MODULE_LICENSE("GPL");
index 4455f0ae1869c2b9631aceb93690324329f45f8d..89bb5a03d8a2303f7ca3ce7cbeb03d8bed673d2a 100644 (file)
@@ -2408,18 +2408,37 @@ static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id
     GTP_INFO("GTP Driver Version: %s", GTP_DRIVER_VERSION);
     GTP_INFO("GTP I2C Address: 0x%02x", client->addr);
 
+    goodix_wq = create_singlethread_workqueue("goodix_wq");
+    if (!goodix_wq) {
+       GTP_ERROR("Create workqueue failed.");
+       ret = -ENOMEM;
+       goto err_create_workqueue;
+    }
+
+#if GTP_ESD_PROTECT
+    INIT_DELAYED_WORK(&gtp_esd_check_work, gtp_esd_check_func);
+    gtp_esd_check_workqueue = create_workqueue("gtp_esd_check");
+    if (!gtp_esd_check_workqueue) {
+       GTP_ERROR("Create esd workqueue failed.");
+       ret = -ENOMEM;
+       goto err_create_esd_work;
+    }
+#endif
+
     i2c_connect_client = client;
 
     if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
     {
         GTP_ERROR("I2C check functionality failed.");
-        return -ENODEV;
+        ret = -ENODEV;
+        goto err_i2c_check_func;
     }
     ts = kzalloc(sizeof(*ts), GFP_KERNEL);
     if (ts == NULL)
     {
         GTP_ERROR("Alloc GFP_KERNEL memory failed.");
-        return -ENOMEM;
+        ret = -ENOMEM;
+        goto err_mem_alloc;
     }
 
 #ifdef GTP_CONFIG_OF   /* device tree support */
@@ -2429,7 +2448,8 @@ static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id
     ret = gtp_power_switch(client, 1);
        if (ret) {
                GTP_ERROR("GTP power on failed.");
-               return -EINVAL;
+               ret = -EINVAL;
+               goto err_power_switch;
        }
 #else                  /* use gpio defined in gt9xx.h */
        gtp_rst_gpio = GTP_RST_PORT;
@@ -2452,8 +2472,7 @@ static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id
     if (ret < 0)
     {
         GTP_ERROR("GTP request IO port failed.");
-        kfree(ts);
-        return ret;
+        goto err_request_io_port;
     }
 
 #if GTP_COMPATIBLE_MODE
@@ -2472,14 +2491,14 @@ static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id
     if (ret < 0)
     {
         GTP_ERROR("I2C communication ERROR!");
-        goto goodix_ts_probe_err;
+        goto err_chip_init;
     }
 
     ret = gtp_read_version(client, &version_info);
     if (ret < 0)
     {
         GTP_ERROR("Read version failed.");
-        goto goodix_ts_probe_err;
+        goto err_chip_init;
     }
 
     ret = gtp_init_panel(ts);
@@ -2489,7 +2508,7 @@ static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id
         ts->abs_x_max = GTP_MAX_WIDTH;
         ts->abs_y_max = GTP_MAX_HEIGHT;
         ts->int_trigger_type = GTP_INT_TRIGGER;
-        goto goodix_ts_probe_err;
+        goto err_chip_init;
     }
 
     // Create proc file system
@@ -2519,7 +2538,7 @@ static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id
     if (ret < 0)
     {
         GTP_ERROR("GTP request input dev failed");
-        goto goodix_ts_probe_err;
+        goto err_request_input_dev;
     }
 
     ret = gtp_request_irq(ts);
@@ -2548,10 +2567,29 @@ static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id
 #endif
     return 0;
 
-goodix_ts_probe_err:
+err_request_input_dev:
+#if GTP_ESD_PROTECT
+       gtp_esd_switch(client, SWITCH_OFF);
+#endif
+err_chip_init:
        GTP_GPIO_FREE(gtp_int_gpio);
        GTP_GPIO_FREE(gtp_rst_gpio);
-       return -ENODEV;
+err_request_io_port:
+#ifdef GTP_CONFIG_OF
+       gtp_power_switch(client, 0);
+err_power_switch:
+#endif
+       kfree(ts);
+err_mem_alloc:
+err_i2c_check_func:
+#if GTP_ESD_PROTECT
+       destroy_workqueue(gtp_esd_check_workqueue);
+err_create_esd_work:
+#endif
+       destroy_workqueue(goodix_wq);
+err_create_workqueue:
+       return ret;
+
 }
 
 
@@ -2598,6 +2636,9 @@ static int goodix_ts_remove(struct i2c_client *client)
     input_unregister_device(ts->input_dev);
     kfree(ts);
 
+    if (goodix_wq)
+       destroy_workqueue(goodix_wq);
+
     return 0;
 }
 
@@ -3081,55 +3122,7 @@ static struct i2c_driver goodix_ts_driver = {
     },
 };
 
-/*******************************************************
-Function:
-    Driver Install function.
-Input:
-    None.
-Output:
-    Executive Outcomes. 0---succeed.
-********************************************************/
-static int __init goodix_ts_init(void)
-{
-    s32 ret;
-
-    GTP_DEBUG_FUNC();
-    GTP_INFO("GTP driver installing....");
-    goodix_wq = create_singlethread_workqueue("goodix_wq");
-    if (!goodix_wq)
-    {
-        GTP_ERROR("Creat workqueue failed.");
-        return -ENOMEM;
-    }
-#if GTP_ESD_PROTECT
-    INIT_DELAYED_WORK(&gtp_esd_check_work, gtp_esd_check_func);
-    gtp_esd_check_workqueue = create_workqueue("gtp_esd_check");
-#endif
-    ret = i2c_add_driver(&goodix_ts_driver);
-    return ret;
-}
-
-/*******************************************************
-Function:
-    Driver uninstall function.
-Input:
-    None.
-Output:
-    Executive Outcomes. 0---succeed.
-********************************************************/
-static void __exit goodix_ts_exit(void)
-{
-    GTP_DEBUG_FUNC();
-    GTP_INFO("GTP driver exited.");
-    i2c_del_driver(&goodix_ts_driver);
-    if (goodix_wq)
-    {
-        destroy_workqueue(goodix_wq);
-    }
-}
-
-module_init(goodix_ts_init);
-module_exit(goodix_ts_exit);
+module_i2c_driver(goodix_ts_driver);
 
 MODULE_DESCRIPTION("GTP Series Driver");
 MODULE_LICENSE("GPL");