Merge tag 'v4.4-rc7'
[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 = *((int *)event->data);
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         if (action == FB_EARLY_EVENT_BLANK) {
38                 switch (blank_mode) {
39                 case FB_BLANK_UNBLANK:
40                         break;
41                 default:
42                         ret = tp->tp_suspend(tp);
43                         break;
44                 }
45         }
46         else if (action == FB_EVENT_BLANK) {
47                 switch (blank_mode) {
48                 case FB_BLANK_UNBLANK:
49                         tp->tp_resume(tp);
50                         break;
51                 default:
52                         break;
53                 }
54         }
55         mutex_unlock(&tp->ops_lock);
56
57         if (ret < 0)
58         {
59                 printk("TP_notifier_callback error action=%x,blank_mode=%x\n",(int)action,blank_mode);
60                 return ret;
61         }
62
63         return NOTIFY_OK;
64 }
65
66 static inline int tp_register_fb(struct tp_device *tp)
67 {
68         memset(&tp->fb_notif, 0, sizeof(tp->fb_notif));
69         tp->fb_notif.notifier_call = fb_notifier_callback;
70         mutex_init(&tp->ops_lock);
71
72         return fb_register_client(&tp->fb_notif);
73 }
74
75 static inline void tp_unregister_fb(struct tp_device *tp)
76 {
77         fb_unregister_client(&tp->fb_notif);
78 }
79 #endif