Merge tag 'lsk-v4.4-16.07-android'
[firefly-linux-kernel-4.4.55.git] / drivers / input / touchscreen / tp_suspend.h
1 /*
2  * TP  suspend Control Abstraction
3  *
4  * Copyright (C) RK Company
5  *
6  */
7 #ifndef _RK_TP_SUSPEND_H
8 #define _RK_TP_SUSPEND_H
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/device.h>
12 #include <linux/err.h>
13 #include <linux/fb.h>
14 #include <linux/notifier.h>
15
16 struct  tp_device{
17         struct notifier_block fb_notif;
18         int(*tp_suspend)(struct  tp_device*);
19         int(*tp_resume)(struct  tp_device*);
20         struct mutex ops_lock;
21 };
22
23 static inline int fb_notifier_callback(struct notifier_block *self,
24                                 unsigned long action, void *data)
25 {
26         struct tp_device *tp;
27         struct fb_event *event = data;
28         int blank_mode;
29         int ret = 0;
30
31         tp = container_of(self, struct tp_device, fb_notif);
32
33         //printk("%s.....lin=%d tp->status=%x,blank_mode=%x\n",__func__,__LINE__,tp->status,blank_mode);
34
35         mutex_lock(&tp->ops_lock);
36
37         switch (action) {
38         case FB_EARLY_EVENT_BLANK:
39                 blank_mode = *((int *)event->data);
40                 if (blank_mode != FB_BLANK_UNBLANK)
41                         ret = tp->tp_suspend(tp);
42                 break;
43
44         case FB_EVENT_BLANK:
45                 blank_mode = *((int *)event->data);
46                 if (blank_mode == FB_BLANK_UNBLANK)
47                         tp->tp_resume(tp);
48                 break;
49
50         default:
51                 break;
52         }
53
54         mutex_unlock(&tp->ops_lock);
55
56         if (ret < 0)
57         {
58                 printk("TP_notifier_callback error action=%x,blank_mode=%x\n",(int)action,blank_mode);
59                 return ret;
60         }
61
62         return NOTIFY_OK;
63 }
64
65 static inline int tp_register_fb(struct tp_device *tp)
66 {
67         memset(&tp->fb_notif, 0, sizeof(tp->fb_notif));
68         tp->fb_notif.notifier_call = fb_notifier_callback;
69         mutex_init(&tp->ops_lock);
70
71         return fb_register_client(&tp->fb_notif);
72 }
73
74 static inline void tp_unregister_fb(struct tp_device *tp)
75 {
76         fb_unregister_client(&tp->fb_notif);
77 }
78 #endif