1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * TP suspend Control Abstraction
4 *
5 * Copyright (C) RK Company
6 *
7 */
8 #ifndef _RK_TP_SUSPEND_H
9 #define _RK_TP_SUSPEND_H
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/device.h>
13 #include <linux/err.h>
14 #include <linux/fb.h>
15 #include <linux/notifier.h>
16 #include "../../gpu/drm/rockchip/ebc_dev.h"
17
18 struct tp_device{
19 struct notifier_block fb_notif;
20 struct notifier_block ebc_notif;
21 int(*tp_suspend)(struct tp_device*);
22 int(*tp_resume)(struct tp_device*);
23 struct mutex ops_lock;
24 int status;
25 };
26
fb_notifier_callback(struct notifier_block * self,unsigned long action,void * data)27 static inline int fb_notifier_callback(struct notifier_block *self,
28 unsigned long action, void *data)
29 {
30 struct tp_device *tp;
31 struct fb_event *event = data;
32 int blank_mode;
33 int ret = 0;
34
35 tp = container_of(self, struct tp_device, fb_notif);
36
37 if (action != FB_EVENT_BLANK)
38 return NOTIFY_DONE;
39
40 mutex_lock(&tp->ops_lock);
41
42 blank_mode = *((int *)event->data);
43 //printk("%s.....lin=%d tp->status=%x,blank_mode=%x\n",__func__,__LINE__,tp->status,blank_mode);
44
45 switch (blank_mode) {
46 case FB_BLANK_UNBLANK:
47 if (tp->status != FB_BLANK_UNBLANK) {
48 tp->status = blank_mode;
49 tp->tp_resume(tp);
50 }
51 break;
52 default:
53 if (tp->status == FB_BLANK_UNBLANK) {
54 tp->status = blank_mode;
55 ret = tp->tp_suspend(tp);
56 }
57 break;
58 }
59
60 mutex_unlock(&tp->ops_lock);
61
62 if (ret < 0)
63 {
64 printk("TP_notifier_callback error action=%x,blank_mode=%x\n",(int)action,blank_mode);
65 return ret;
66 }
67
68 return NOTIFY_OK;
69 }
70
ebc_notifier_callback(struct notifier_block * self,unsigned long action,void * data)71 static int ebc_notifier_callback(struct notifier_block *self,
72 unsigned long action, void *data)
73 {
74 struct tp_device *tp;
75
76 tp = container_of(self, struct tp_device, ebc_notif);
77
78 mutex_lock(&tp->ops_lock);
79
80 if (action == EBC_FB_BLANK)
81 tp->tp_suspend(tp);
82 else if (action == EBC_FB_UNBLANK)
83 tp->tp_resume(tp);
84
85 mutex_unlock(&tp->ops_lock);
86
87 return NOTIFY_OK;
88 }
89
tp_register_fb(struct tp_device * tp)90 static inline int tp_register_fb(struct tp_device *tp)
91 {
92 memset(&tp->fb_notif, 0, sizeof(tp->fb_notif));
93 tp->fb_notif.notifier_call = fb_notifier_callback;
94 tp->ebc_notif.notifier_call = ebc_notifier_callback;
95 mutex_init(&tp->ops_lock);
96 tp->status = FB_BLANK_UNBLANK;
97
98 ebc_register_notifier(&tp->ebc_notif);
99 fb_register_client(&tp->fb_notif);
100
101 return 0;
102 }
103
tp_unregister_fb(struct tp_device * tp)104 static inline void tp_unregister_fb(struct tp_device *tp)
105 {
106 ebc_unregister_notifier(&tp->ebc_notif);
107 fb_unregister_client(&tp->fb_notif);
108 }
109 #endif
110