forked from dzo/kernel
/
cm_ioctrl.patch
186 lines (164 loc) · 5.37 KB
/
cm_ioctrl.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
From aa03c27869e0d827f8fc78efe5e82a77f3b9f715 Mon Sep 17 00:00:00 2001
From: Dave Savage <bedalus@gmail.com>
Date: Mon, 3 Dec 2012 17:19:03 +0000
Subject: [PATCH] custom io control
---
drivers/video/fbmem.c | 10 ++++++++
drivers/video/samsung/s3cfb.c | 54 ++++++++++---------------------------------
drivers/video/samsung/s3cfb.h | 4 +++-
3 files changed, 25 insertions(+), 43 deletions(-)
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 7a41220..264d172 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -35,6 +35,9 @@
#include <asm/fb.h>
+#ifdef CONFIG_FB_S3C
+#include "./samsung/s3cfb.h"
+#endif
/*
* Frame buffer device initialization and setup routines
@@ -1169,6 +1172,10 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
unlock_fb_info(info);
break;
default:
+// Skip mutex for vsync poll because it's in its own thread
+#ifdef CONFIG_FB_S3C
+ if (cmd != S3CFB_WAIT_FOR_VSYNC)
+#endif
if (!lock_fb_info(info))
return -ENODEV;
fb = info->fbops;
@@ -1176,6 +1183,9 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
ret = fb->fb_ioctl(info, cmd, arg);
else
ret = -ENOTTY;
+#ifdef CONFIG_FB_S3C
+ if (cmd != S3CFB_WAIT_FOR_VSYNC)
+#endif
unlock_fb_info(info);
}
return ret;
diff --git a/drivers/video/samsung/s3cfb.c b/drivers/video/samsung/s3cfb.c
index 8429d48..82bb801 100755
--- a/drivers/video/samsung/s3cfb.c
+++ b/drivers/video/samsung/s3cfb.c
@@ -116,7 +116,7 @@ static irqreturn_t s3cfb_irq_frame(int irq, void *data)
fbdev->vsync_timestamp = ktime_get();
wmb();
- wake_up_interruptible(&fbdev->vsync_wq);
+ wake_up_interruptible(&fbdev->vsync_wait);
return IRQ_HANDLED;
}
@@ -143,7 +143,7 @@ static int s3cfb_init_global(struct s3cfb_global *ctrl)
ctrl->output = OUTPUT_RGB;
ctrl->rgb_mode = MODE_RGB_P;
- init_waitqueue_head(&ctrl->vsync_wq);
+ init_waitqueue_head(&ctrl->vsync_wait);
mutex_init(&ctrl->lock);
s3cfb_set_output(ctrl);
@@ -573,10 +573,8 @@ static int s3cfb_wait_for_vsync(struct s3cfb_global *ctrl)
ktime_t prev_timestamp;
int ret;
- dev_dbg(ctrl->dev, "waiting for VSYNC interrupt\n");
-
prev_timestamp = ctrl->vsync_timestamp;
- ret = wait_event_interruptible_timeout(ctrl->vsync_wq,
+ ret = wait_event_interruptible_timeout(ctrl->vsync_wait,
s3cfb_vsync_timestamp_changed(ctrl, prev_timestamp),
msecs_to_jiffies(100));
if (ret == 0)
@@ -584,8 +582,6 @@ static int s3cfb_wait_for_vsync(struct s3cfb_global *ctrl)
if (ret < 0)
return ret;
- dev_dbg(ctrl->dev, "got a VSYNC interrupt\n");
-
return ret;
}
static int s3cfb_ioctl(struct fb_info *fb, unsigned int cmd, unsigned long arg)
@@ -612,6 +608,15 @@ static int s3cfb_ioctl(struct fb_info *fb, unsigned int cmd, unsigned long arg)
s3cfb_wait_for_vsync(fbdev);
break;
+ // Custom IOCTL added to return the VSYNC timestamp
+ case S3CFB_WAIT_FOR_VSYNC:
+ ret = s3cfb_wait_for_vsync(fbdev);
+ if(ret > 0) {
+ u64 nsecs = ktime_to_ns(fbdev->vsync_timestamp);
+ copy_to_user((void*)arg, &nsecs, sizeof(u64));
+ }
+ break;
+
case S3CFB_WIN_POSITION:
if (copy_from_user(&p.user_window,
(struct s3cfb_user_window __user *)arg,
@@ -919,31 +924,6 @@ static int s3cfb_sysfs_store_win_power(struct device *dev,
return len;
}
-static int s3cfb_wait_for_vsync_thread(void *data)
-{
- struct s3cfb_global *fbdev = data;
-
- while (!kthread_should_stop()) {
- ktime_t prev_timestamp = fbdev->vsync_timestamp;
- int ret = wait_event_interruptible_timeout(fbdev->vsync_wq,
- s3cfb_vsync_timestamp_changed(fbdev,
- prev_timestamp),
- msecs_to_jiffies(100));
- if (ret > 0) {
- char *envp[2];
- char buf[64];
- snprintf(buf, sizeof(buf), "VSYNC=%llu",
- ktime_to_ns(fbdev->vsync_timestamp));
- envp[0] = buf;
- envp[1] = NULL;
- kobject_uevent_env(&fbdev->dev->kobj, KOBJ_CHANGE,
- envp);
- }
- }
-
- return 0;
-}
-
static DEVICE_ATTR(win_power, S_IRUGO | S_IWUSR,
s3cfb_sysfs_show_win_power, s3cfb_sysfs_store_win_power);
@@ -1082,13 +1062,6 @@ static int __devinit s3cfb_probe(struct platform_device *pdev)
register_early_suspend(&fbdev->early_suspend);
#endif
- fbdev->vsync_thread = kthread_run(s3cfb_wait_for_vsync_thread,
- fbdev, "s3cfb-vsync");
- if (fbdev->vsync_thread == ERR_PTR(-ENOMEM)) {
- dev_err(fbdev->dev, "failed to run vsync thread\n");
- fbdev->vsync_thread = NULL;
- }
-
ret = device_create_file(&(pdev->dev), &dev_attr_win_power);
if (ret < 0)
dev_err(fbdev->dev, "failed to add sysfs entries\n");
@@ -1181,9 +1154,6 @@ static int __devexit s3cfb_remove(struct platform_device *pdev)
regulator_disable(fbdev->regulator);
- if (fbdev->vsync_thread)
- kthread_stop(fbdev->vsync_thread);
-
kfree(fbdev->fb);
kfree(fbdev);
diff --git a/drivers/video/samsung/s3cfb.h b/drivers/video/samsung/s3cfb.h
index 21e581d..147b4d8 100644
--- a/drivers/video/samsung/s3cfb.h
+++ b/drivers/video/samsung/s3cfb.h
@@ -232,7 +232,7 @@ struct s3cfb_global {
int irq;
struct fb_info **fb;
- wait_queue_head_t vsync_wq;
+ wait_queue_head_t vsync_wait;
ktime_t vsync_timestamp;
int vsync_state;
@@ -318,6 +318,8 @@ struct s3cfb_next_info {
#define S3CFB_SET_WIN_ADDR _IOW('F', 309, unsigned long)
#define S3CFB_SET_WIN_MEM _IOW('F', 310, \
enum s3cfb_mem_owner_t)
+// New IOCTL that waits for vsync and returns a timestamp
+#define S3CFB_WAIT_FOR_VSYNC _IOR('F', 311, u64)
/*
* E X T E R N S
--
1.8.1.5