TP: sdk tp add early resume
authoryj <yangjie@rock-chips.com>
Fri, 28 Mar 2014 10:30:21 +0000 (18:30 +0800)
committeryj <yangjie@rock-chips.com>
Fri, 28 Mar 2014 10:30:21 +0000 (18:30 +0800)
drivers/input/touchscreen/rk29_i2c_goodix.c
drivers/input/touchscreen/rk29_i2c_goodix.h
drivers/input/touchscreen/tp_suspend.h [new file with mode: 0644]

index f2408940bbe3bd15e4d397b53f82dd4dc3bf1214..d2e76f3ba7bf5a6ad9f697cbbb9925a35e7fed9c 100755 (executable)
@@ -18,9 +18,6 @@
 #include <linux/time.h>\r
 #include <linux/delay.h>\r
 #include <linux/device.h>\r
-#ifdef CONFIG_HAS_EARLYSUSPEND\r
-#include <linux/earlysuspend.h>\r
-#endif\r
 #include <linux/hrtimer.h>\r
 #include <linux/i2c.h>\r
 #include <linux/input.h>\r
 #include <linux/reboot.h>\r
 #include <linux/proc_fs.h>\r
 #include <linux/async.h>\r
-#include "rk29_i2c_goodix.h"\r
-\r
 #include <linux/vmalloc.h>\r
 #include <linux/fs.h>\r
 #include <linux/string.h>\r
 #include <linux/completion.h>\r
 #include <asm/uaccess.h>\r
 \r
+#include "rk29_i2c_goodix.h"\r
+\r
 #define PEN_DOWN 1\r
 #define PEN_RELEASE 0\r
 #define PEN_DOWN_UP 2 //fjp\r
@@ -490,19 +487,17 @@ static irqreturn_t rk_ts_irq_handler(int irq, void *dev_id)
 static int rk_ts_suspend(struct i2c_client *client, pm_message_t mesg)\r
 {\r
        int ret;\r
-       struct rk_ts_data *ts = i2c_get_clientdata(client);\r
+       struct rk_ts_data *ts = i2c_get_clientdata(client);       \r
+\r
+       disable_irq(ts->irq);   \r
 \r
-       \r
-       \r
-       disable_irq(ts->irq);\r
-       \r
-#if 1\r
        if (ts->power) {\r
+               DBG("%s.....line=%d\n",__func__,__LINE__);\r
                ret = ts->power(ts, 0);\r
                if (ret < 0)\r
                        printk(KERN_ERR "goodix_ts_resume power off failed\n");\r
        }\r
-#endif\r
+\r
        return 0;\r
 }\r
 \r
@@ -510,37 +505,34 @@ static int rk_ts_resume(struct i2c_client *client)
 {\r
        int ret;\r
        struct rk_ts_data *ts = i2c_get_clientdata(client);\r
-       \r
-#if 1\r
+\r
        if (ts->power) {\r
+               DBG("%s.....line=%d\n",__func__,__LINE__);\r
                ret = ts->power(ts, 1);\r
                if (ret < 0)\r
                        printk(KERN_ERR "goodix_ts_resume power on failed\n");\r
        }\r
-#endif\r
-       \r
-       enable_irq(ts->irq);\r
 \r
+       enable_irq(ts->irq);\r
        return 0;\r
 }\r
 \r
 \r
 \r
-#ifdef CONFIG_HAS_EARLYSUSPEND\r
-static void rk_ts_early_suspend(struct early_suspend *h)\r
+static void rk_ts_early_suspend(struct tp_device *tp_d)\r
 {\r
        struct rk_ts_data *ts;\r
-       ts = container_of(h, struct rk_ts_data, early_suspend);\r
+       ts = container_of(tp_d, struct rk_ts_data, tp);\r
        rk_ts_suspend(ts->client, PMSG_SUSPEND);\r
 }\r
 \r
-static void rk_ts_late_resume(struct early_suspend *h)\r
+static void rk_ts_early_resume(struct tp_device *tp_d)\r
 {\r
        struct rk_ts_data *ts;\r
-       ts = container_of(h, struct rk_ts_data, early_suspend);\r
+       ts = container_of(tp_d, struct rk_ts_data, tp);\r
        rk_ts_resume(ts->client);\r
 }\r
-#endif\r
+\r
 \r
 /*******************************************************\r
 Description:\r
@@ -557,21 +549,21 @@ static int goodix_ts_power(struct rk_ts_data * ts, int on)
        int ret = -1;\r
        unsigned char i2c_control_buf[2] = {80,  1};            //suspend cmd\r
        int retry = 0;\r
+\r
        if(on != 0 && on !=1)\r
        {\r
-               printk(KERN_DEBUG "%s: Cant't support this command.", rk_ts_name);\r
+               printk("%s: Cant't support this command.", rk_ts_name);\r
                return -EINVAL;\r
        }\r
-       \r
-       \r
-       if(on == 0)             //suspend\r
+               \r
+       if(on == 0)//suspend\r
        { \r
         while(retry<5)\r
                {\r
                        ret = goodix_i2c_write_bytes(ts->client, i2c_control_buf, 2);\r
                        if(ret == 1)\r
                        {\r
-                               printk(KERN_DEBUG "touch goodix Send suspend cmd successed \n");\r
+                               printk("touch goodix Send suspend cmd successed \n");\r
                                break;\r
                        }\r
                       retry++;\r
@@ -580,9 +572,9 @@ static int goodix_ts_power(struct rk_ts_data * ts, int on)
                if(ret > 0)\r
                  ret = 0;\r
        }\r
-       else if(on == 1)                //resume\r
+       else if(on == 1)//resume\r
        {\r
-               printk(KERN_DEBUG "touch goodix int resume\n");\r
+               printk("touch goodix int resume\n");\r
                gpio_set_value(ts->rst_pin, ts->rst_val);\r
                msleep(20);\r
                gpio_set_value(ts->rst_pin, !ts->rst_val);\r
@@ -793,12 +785,10 @@ static int rk_ts_probe(struct i2c_client *client, const struct i2c_device_id *id
 \r
        i2c_connect_client = client;\r
 \r
-#ifdef CONFIG_HAS_EARLYSUSPEND\r
-       ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;\r
-       ts->early_suspend.suspend = rk_ts_early_suspend;\r
-       ts->early_suspend.resume = rk_ts_late_resume;\r
-       register_early_suspend(&ts->early_suspend);\r
-#endif\r
+       ts->tp.tp_resume = rk_ts_early_resume;\r
+       ts->tp.tp_suspend = rk_ts_early_suspend;\r
+       tp_register_fb(&ts->tp);\r
+\r
        i2c_set_clientdata(client, ts);\r
 \r
        ts->irq=gpio_to_irq(ts->irq_pin);               //If not defined in client\r
@@ -809,15 +799,14 @@ static int rk_ts_probe(struct i2c_client *client, const struct i2c_device_id *id
                        printk(KERN_ALERT "Cannot allocate ts INT!ERRNO:%d\n", ret);\r
                        goto err;\r
                }\r
+               disable_irq(ts->irq);\r
        }\r
        printk("goodix_ts_init: probe successfully!\n");\r
        return 0;\r
 \r
        \r
 err:\r
-#ifdef CONFIG_HAS_EARLYSUSPEND\r
-       unregister_early_suspend(&ts->early_suspend);\r
-#endif\r
+       tp_unregister_fb(&ts->tp);\r
        i2c_set_clientdata(client, NULL);       \r
        return ret;\r
 }\r
@@ -835,10 +824,9 @@ return:
 *******************************************************/\r
 static int rk_ts_remove(struct i2c_client *client)\r
 {\r
-#ifdef CONFIG_HAS_EARLYSUSPEND\r
        struct rk_ts_data *ts = i2c_get_clientdata(client);\r
-       unregister_early_suspend(&ts->early_suspend);\r
-#endif\r
+       tp_unregister_fb(&ts->tp);\r
+\r
 #ifdef CONFIG_TOUCHSCREEN_GOODIX_IAP\r
        remove_proc_entry("goodix-update", NULL);\r
 #endif\r
@@ -850,11 +838,10 @@ static int rk_ts_remove(struct i2c_client *client)
 \r
 static void rk_ts_shutdown(struct i2c_client *client)\r
 {\r
-#ifdef CONFIG_HAS_EARLYSUSPEND\r
        struct rk_ts_data *ts = i2c_get_clientdata(client);\r
        if (ts)\r
-               unregister_early_suspend(&ts->early_suspend);\r
-#endif\r
+               tp_unregister_fb(&ts->tp);\r
+\r
 }\r
 \r
 //******************************Begin of firmware update surpport*******************************\r
@@ -1600,10 +1587,6 @@ static struct i2c_driver rk_ts_driver = {
        .probe          = rk_ts_probe,\r
        .remove         = rk_ts_remove,\r
        .shutdown       = rk_ts_shutdown,\r
-#ifndef CONFIG_HAS_EARLYSUSPEND\r
-       .suspend        = rk_ts_suspend,\r
-       .resume         = rk_ts_resume,\r
-#endif\r
        .id_table       = goodix_ts_id,\r
        .driver = {\r
                .name   = "Goodix-TS",\r
index d04b6a6d6b7a32edc19fdf7a8515da09ea0d4fd7..31cc6c3d6563b70515e17bb24c7ce22ac4d7d74e 100755 (executable)
 #ifndef        _LINUX_GOODIX_TOUCH_H
 #define                _LINUX_GOODIX_TOUCH_H
 
-#ifdef CONFIG_HAS_EARLYSUSPEND
-#include <linux/earlysuspend.h>
-#endif
 #include <linux/hrtimer.h>
 #include <linux/i2c.h>
 #include <linux/input.h>
 
+#include "tp_suspend.h"
+
 //*************************TouchScreen Work Part*****************************
 
 #define GOODIX_I2C_NAME "Goodix-TS"
@@ -76,9 +75,6 @@ struct rk_ts_data{
        int rst_val;
        int read_mode;                                  //read moudle mode,20110221 by andrew
        char phys[32];
-#ifdef CONFIG_HAS_EARLYSUSPEND
-       struct early_suspend early_suspend;
-#endif
        int (*power)(struct rk_ts_data * ts, int on);
        int (*ts_init)(struct rk_ts_data*ts);
        int (*input_parms_init)(struct rk_ts_data *ts);
@@ -88,6 +84,7 @@ struct rk_ts_data{
        uint8_t max_touch_num;
        bool            pendown;
        struct rk_touch_info *info_buf;
+       struct  tp_device  tp;
 };
 
 
@@ -104,9 +101,6 @@ struct goodix_ts_data {
        struct delayed_work  work;
        char phys[32];
        int retry;
-#ifdef CONFIG_HAS_EARLYSUSPEND
-       struct early_suspend early_suspend;
-#endif
        int (*power)(struct goodix_ts_data * ts, int on);
        uint16_t abs_x_max;
        uint16_t abs_y_max;
diff --git a/drivers/input/touchscreen/tp_suspend.h b/drivers/input/touchscreen/tp_suspend.h
new file mode 100644 (file)
index 0000000..4ea2322
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * TP  suspend Control Abstraction
+ *
+ * Copyright (C) RK Company
+ *
+ */
+#ifndef _RK_TP_SUSPEND_H
+#define _RK_TP_SUSPEND_H
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/fb.h>
+#include <linux/notifier.h>
+
+struct  tp_device{
+       struct notifier_block fb_notif;
+       int(*tp_suspend)(struct  tp_device*);
+       int(*tp_resume)(struct  tp_device*);
+       struct mutex ops_lock;
+};
+
+static int fb_notifier_callback(struct notifier_block *self,
+                               unsigned long action, void *data)
+{
+       struct tp_device *tp;
+       struct fb_event *event = data;
+       int blank_mode = *((int *)event->data);
+       int ret = 0;
+
+       tp = container_of(self, struct tp_device, fb_notif);
+
+       //printk("%s.....lin=%d tp->status=%x,blank_mode=%x\n",__func__,__LINE__,tp->status,blank_mode);
+
+       mutex_lock(&tp->ops_lock);
+
+       if (action == FB_EARLY_EVENT_BLANK) {
+               switch (blank_mode) {
+               case FB_BLANK_UNBLANK:
+                       break;
+               default:
+                       ret = tp->tp_suspend(tp);
+                       break;
+               }
+       }
+       else if (action == FB_EVENT_BLANK) {
+               switch (blank_mode) {
+               case FB_BLANK_UNBLANK:
+                       tp->tp_resume(tp);
+                       break;
+               default:
+                       break;
+               }
+       }
+       mutex_unlock(&tp->ops_lock);
+
+       if (ret < 0)
+       {
+               printk("TP_notifier_callback error action=%x,blank_mode=%x\n",action,blank_mode);
+               return ret;
+       }
+
+       return NOTIFY_OK;
+}
+
+static int tp_register_fb(struct tp_device *tp)
+{
+       memset(&tp->fb_notif, 0, sizeof(tp->fb_notif));
+       tp->fb_notif.notifier_call = fb_notifier_callback;
+       mutex_init(&tp->ops_lock);
+
+       return fb_register_client(&tp->fb_notif);
+}
+
+static void tp_unregister_fb(struct tp_device *tp)
+{
+       fb_unregister_client(&tp->fb_notif);
+}
+#endif _RK_TP_SUSPEND_H