blob: 7678ad08178e2e079f656ceb68aacf8dcddc86f9 [file] [log] [blame]
Inki Dae1c248b72011-10-04 19:19:01 +09001/* exynos_drm_crtc.c
2 *
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * Authors:
5 * Inki Dae <inki.dae@samsung.com>
6 * Joonyoung Shim <jy0922.shim@samsung.com>
7 * Seung-Woo Kim <sw0312.kim@samsung.com>
8 *
Inki Daed81aecb2012-12-18 02:30:17 +09009 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
Inki Dae1c248b72011-10-04 19:19:01 +090013 */
14
David Howells760285e2012-10-02 18:01:07 +010015#include <drm/drmP.h>
16#include <drm/drm_crtc_helper.h>
Inki Dae1c248b72011-10-04 19:19:01 +090017
Mark Browne30655d2013-08-13 00:46:40 +010018#include "exynos_drm_crtc.h"
Inki Dae1c248b72011-10-04 19:19:01 +090019#include "exynos_drm_drv.h"
Inki Dae1c248b72011-10-04 19:19:01 +090020#include "exynos_drm_encoder.h"
Joonyoung Shimb5d2eb32012-06-27 14:27:04 +090021#include "exynos_drm_plane.h"
Inki Dae1c248b72011-10-04 19:19:01 +090022
23#define to_exynos_crtc(x) container_of(x, struct exynos_drm_crtc,\
24 drm_crtc)
25
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +090026enum exynos_crtc_mode {
27 CRTC_MODE_NORMAL, /* normal mode */
28 CRTC_MODE_BLANK, /* The private plane of crtc is blank */
29};
30
Inki Dae1c248b72011-10-04 19:19:01 +090031/*
Inki Dae1c248b72011-10-04 19:19:01 +090032 * Exynos specific crtc structure.
33 *
34 * @drm_crtc: crtc object.
Joonyoung Shimb5d2eb32012-06-27 14:27:04 +090035 * @drm_plane: pointer of private plane object for this crtc
Sean Paul080be03d2014-02-19 21:02:55 +090036 * @manager: the manager associated with this crtc
Inki Dae1c248b72011-10-04 19:19:01 +090037 * @pipe: a crtc index created at load() with a new crtc object creation
38 * and the crtc object would be set to private->crtc array
39 * to get a crtc object corresponding to this pipe from private->crtc
Masanari Iidac6b78bc2013-10-24 16:02:57 +090040 * array when irq interrupt occurred. the reason of using this pipe is that
Inki Dae1c248b72011-10-04 19:19:01 +090041 * drm framework doesn't support multiple irq yet.
Masanari Iidac6b78bc2013-10-24 16:02:57 +090042 * we can refer to the crtc to current hardware interrupt occurred through
Inki Dae1c248b72011-10-04 19:19:01 +090043 * this pipe value.
Inki Daeec05da92011-12-06 11:06:54 +090044 * @dpms: store the crtc dpms value
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +090045 * @mode: store the crtc mode value
Inki Dae1c248b72011-10-04 19:19:01 +090046 */
47struct exynos_drm_crtc {
48 struct drm_crtc drm_crtc;
Joonyoung Shimb5d2eb32012-06-27 14:27:04 +090049 struct drm_plane *plane;
Sean Paul080be03d2014-02-19 21:02:55 +090050 struct exynos_drm_manager *manager;
Inki Dae1c248b72011-10-04 19:19:01 +090051 unsigned int pipe;
Inki Daeec05da92011-12-06 11:06:54 +090052 unsigned int dpms;
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +090053 enum exynos_crtc_mode mode;
Inki Dae20cd2642013-05-21 16:55:58 +090054 wait_queue_head_t pending_flip_queue;
55 atomic_t pending_flip;
Inki Dae1c248b72011-10-04 19:19:01 +090056};
57
Inki Dae1c248b72011-10-04 19:19:01 +090058static void exynos_drm_crtc_dpms(struct drm_crtc *crtc, int mode)
59{
Joonyoung Shimd2716c82011-11-04 17:04:45 +090060 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
Sean Paul080be03d2014-02-19 21:02:55 +090061 struct exynos_drm_manager *manager = exynos_crtc->manager;
Inki Dae1c248b72011-10-04 19:19:01 +090062
Joonyoung Shimd2716c82011-11-04 17:04:45 +090063 DRM_DEBUG_KMS("crtc[%d] mode[%d]\n", crtc->base.id, mode);
64
Inki Daeec05da92011-12-06 11:06:54 +090065 if (exynos_crtc->dpms == mode) {
66 DRM_DEBUG_KMS("desired dpms mode is same as previous one.\n");
67 return;
68 }
69
Inki Dae20cd2642013-05-21 16:55:58 +090070 if (mode > DRM_MODE_DPMS_ON) {
71 /* wait for the completion of page flip. */
72 wait_event(exynos_crtc->pending_flip_queue,
73 atomic_read(&exynos_crtc->pending_flip) == 0);
74 drm_vblank_off(crtc->dev, exynos_crtc->pipe);
75 }
76
Sean Paul080be03d2014-02-19 21:02:55 +090077 if (manager->ops->dpms)
78 manager->ops->dpms(manager, mode);
79
Joonyoung Shimcf5188a2012-06-27 14:27:09 +090080 exynos_crtc->dpms = mode;
Inki Dae1c248b72011-10-04 19:19:01 +090081}
82
83static void exynos_drm_crtc_prepare(struct drm_crtc *crtc)
84{
Inki Dae1c248b72011-10-04 19:19:01 +090085 /* drm framework doesn't check NULL. */
86}
87
88static void exynos_drm_crtc_commit(struct drm_crtc *crtc)
89{
Joonyoung Shimd2716c82011-11-04 17:04:45 +090090 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
Sean Paul080be03d2014-02-19 21:02:55 +090091 struct exynos_drm_manager *manager = exynos_crtc->manager;
Joonyoung Shimd2716c82011-11-04 17:04:45 +090092
Inki Dae50caf252012-08-20 21:29:25 +090093 exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
Sean Paul080be03d2014-02-19 21:02:55 +090094
Joonyoung Shim4070d212012-06-27 14:27:05 +090095 exynos_plane_commit(exynos_crtc->plane);
Sean Paul080be03d2014-02-19 21:02:55 +090096
97 if (manager->ops->commit)
98 manager->ops->commit(manager);
99
Joonyoung Shimcf5188a2012-06-27 14:27:09 +0900100 exynos_plane_dpms(exynos_crtc->plane, DRM_MODE_DPMS_ON);
Inki Dae1c248b72011-10-04 19:19:01 +0900101}
102
103static bool
104exynos_drm_crtc_mode_fixup(struct drm_crtc *crtc,
Laurent Pincharte811f5a2012-07-17 17:56:50 +0200105 const struct drm_display_mode *mode,
Inki Dae1c248b72011-10-04 19:19:01 +0900106 struct drm_display_mode *adjusted_mode)
107{
Inki Dae1c248b72011-10-04 19:19:01 +0900108 /* drm framework doesn't check NULL */
109 return true;
110}
111
112static int
113exynos_drm_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode,
114 struct drm_display_mode *adjusted_mode, int x, int y,
115 struct drm_framebuffer *old_fb)
116{
Joonyoung Shimaeb29222012-06-27 14:27:01 +0900117 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
Joonyoung Shim4070d212012-06-27 14:27:05 +0900118 struct drm_plane *plane = exynos_crtc->plane;
119 unsigned int crtc_w;
120 unsigned int crtc_h;
Joonyoung Shimaeb29222012-06-27 14:27:01 +0900121 int ret;
122
Inki Dae1de425b2012-03-16 18:47:04 +0900123 /*
124 * copy the mode data adjusted by mode_fixup() into crtc->mode
125 * so that hardware can be seet to proper mode.
126 */
127 memcpy(&crtc->mode, adjusted_mode, sizeof(*adjusted_mode));
Inki Dae1c248b72011-10-04 19:19:01 +0900128
Joonyoung Shim4070d212012-06-27 14:27:05 +0900129 crtc_w = crtc->fb->width - x;
130 crtc_h = crtc->fb->height - y;
131
132 ret = exynos_plane_mode_set(plane, crtc, crtc->fb, 0, 0, crtc_w, crtc_h,
133 x, y, crtc_w, crtc_h);
Joonyoung Shimaeb29222012-06-27 14:27:01 +0900134 if (ret)
135 return ret;
136
Joonyoung Shim4070d212012-06-27 14:27:05 +0900137 plane->crtc = crtc;
138 plane->fb = crtc->fb;
139
Joonyoung Shimaeb29222012-06-27 14:27:01 +0900140 return 0;
Inki Dae1c248b72011-10-04 19:19:01 +0900141}
142
Inki Dae7fd65df2013-05-12 16:09:33 +0900143static int exynos_drm_crtc_mode_set_commit(struct drm_crtc *crtc, int x, int y,
Inki Dae1c248b72011-10-04 19:19:01 +0900144 struct drm_framebuffer *old_fb)
145{
Joonyoung Shim4070d212012-06-27 14:27:05 +0900146 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
147 struct drm_plane *plane = exynos_crtc->plane;
148 unsigned int crtc_w;
149 unsigned int crtc_h;
Inki Dae1c248b72011-10-04 19:19:01 +0900150 int ret;
151
Inki Dae32aeab12012-09-14 13:29:47 +0900152 /* when framebuffer changing is requested, crtc's dpms should be on */
153 if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) {
154 DRM_ERROR("failed framebuffer changing request.\n");
155 return -EPERM;
156 }
157
Joonyoung Shim4070d212012-06-27 14:27:05 +0900158 crtc_w = crtc->fb->width - x;
159 crtc_h = crtc->fb->height - y;
160
161 ret = exynos_plane_mode_set(plane, crtc, crtc->fb, 0, 0, crtc_w, crtc_h,
162 x, y, crtc_w, crtc_h);
Inki Dae1c248b72011-10-04 19:19:01 +0900163 if (ret)
164 return ret;
165
Joonyoung Shimbebab8f2012-06-27 14:27:07 +0900166 exynos_drm_crtc_commit(crtc);
Inki Dae1c248b72011-10-04 19:19:01 +0900167
Joonyoung Shim4070d212012-06-27 14:27:05 +0900168 return 0;
Inki Dae1c248b72011-10-04 19:19:01 +0900169}
170
Inki Dae7fd65df2013-05-12 16:09:33 +0900171static int exynos_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
172 struct drm_framebuffer *old_fb)
173{
174 return exynos_drm_crtc_mode_set_commit(crtc, x, y, old_fb);
175}
176
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900177static void exynos_drm_crtc_disable(struct drm_crtc *crtc)
178{
Sean Paula9c4cd22014-01-30 16:19:17 -0500179 struct drm_plane *plane;
180 int ret;
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900181
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900182 exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
Sean Paula9c4cd22014-01-30 16:19:17 -0500183
184 list_for_each_entry(plane, &crtc->dev->mode_config.plane_list, head) {
185 if (plane->crtc != crtc)
186 continue;
187
188 ret = plane->funcs->disable_plane(plane);
189 if (ret)
190 DRM_ERROR("Failed to disable plane %d\n", ret);
191 }
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900192}
193
Inki Dae1c248b72011-10-04 19:19:01 +0900194static struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = {
195 .dpms = exynos_drm_crtc_dpms,
196 .prepare = exynos_drm_crtc_prepare,
197 .commit = exynos_drm_crtc_commit,
198 .mode_fixup = exynos_drm_crtc_mode_fixup,
199 .mode_set = exynos_drm_crtc_mode_set,
200 .mode_set_base = exynos_drm_crtc_mode_set_base,
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900201 .disable = exynos_drm_crtc_disable,
Inki Dae1c248b72011-10-04 19:19:01 +0900202};
203
204static int exynos_drm_crtc_page_flip(struct drm_crtc *crtc,
Keith Packarded8d1972013-07-22 18:49:58 -0700205 struct drm_framebuffer *fb,
206 struct drm_pending_vblank_event *event,
207 uint32_t page_flip_flags)
Inki Dae1c248b72011-10-04 19:19:01 +0900208{
209 struct drm_device *dev = crtc->dev;
210 struct exynos_drm_private *dev_priv = dev->dev_private;
211 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
212 struct drm_framebuffer *old_fb = crtc->fb;
213 int ret = -EINVAL;
214
Inki Daeef6223d2012-09-11 18:25:21 +0900215 /* when the page flip is requested, crtc's dpms should be on */
216 if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) {
217 DRM_ERROR("failed page flip request.\n");
218 return -EINVAL;
219 }
220
Inki Dae1c248b72011-10-04 19:19:01 +0900221 mutex_lock(&dev->struct_mutex);
222
Inki Daeccf4d882011-10-14 13:29:51 +0900223 if (event) {
224 /*
225 * the pipe from user always is 0 so we can set pipe number
226 * of current owner to event.
227 */
228 event->pipe = exynos_crtc->pipe;
229
Inki Dae1c248b72011-10-04 19:19:01 +0900230 ret = drm_vblank_get(dev, exynos_crtc->pipe);
231 if (ret) {
232 DRM_DEBUG("failed to acquire vblank counter\n");
Inki Daeccf4d882011-10-14 13:29:51 +0900233
Inki Dae1c248b72011-10-04 19:19:01 +0900234 goto out;
235 }
236
Imre Deak85473322012-11-02 13:30:47 +0200237 spin_lock_irq(&dev->event_lock);
Inki Daec5614ae2012-02-15 11:25:20 +0900238 list_add_tail(&event->base.link,
239 &dev_priv->pageflip_event_list);
Inki Dae20cd2642013-05-21 16:55:58 +0900240 atomic_set(&exynos_crtc->pending_flip, 1);
Imre Deak85473322012-11-02 13:30:47 +0200241 spin_unlock_irq(&dev->event_lock);
Inki Daec5614ae2012-02-15 11:25:20 +0900242
Inki Dae1c248b72011-10-04 19:19:01 +0900243 crtc->fb = fb;
Inki Dae7fd65df2013-05-12 16:09:33 +0900244 ret = exynos_drm_crtc_mode_set_commit(crtc, crtc->x, crtc->y,
Joonyoung Shim4070d212012-06-27 14:27:05 +0900245 NULL);
Inki Dae1c248b72011-10-04 19:19:01 +0900246 if (ret) {
247 crtc->fb = old_fb;
Imre Deak85473322012-11-02 13:30:47 +0200248
249 spin_lock_irq(&dev->event_lock);
Inki Dae1c248b72011-10-04 19:19:01 +0900250 drm_vblank_put(dev, exynos_crtc->pipe);
Inki Daeccf4d882011-10-14 13:29:51 +0900251 list_del(&event->base.link);
Imre Deak85473322012-11-02 13:30:47 +0200252 spin_unlock_irq(&dev->event_lock);
Inki Dae1c248b72011-10-04 19:19:01 +0900253
254 goto out;
255 }
Inki Dae1c248b72011-10-04 19:19:01 +0900256 }
257out:
258 mutex_unlock(&dev->struct_mutex);
259 return ret;
260}
261
262static void exynos_drm_crtc_destroy(struct drm_crtc *crtc)
263{
264 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
265 struct exynos_drm_private *private = crtc->dev->dev_private;
266
Inki Dae1c248b72011-10-04 19:19:01 +0900267 private->crtc[exynos_crtc->pipe] = NULL;
268
269 drm_crtc_cleanup(crtc);
270 kfree(exynos_crtc);
271}
272
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900273static int exynos_drm_crtc_set_property(struct drm_crtc *crtc,
274 struct drm_property *property,
275 uint64_t val)
276{
277 struct drm_device *dev = crtc->dev;
278 struct exynos_drm_private *dev_priv = dev->dev_private;
279 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
280
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900281 if (property == dev_priv->crtc_mode_property) {
282 enum exynos_crtc_mode mode = val;
283
284 if (mode == exynos_crtc->mode)
285 return 0;
286
287 exynos_crtc->mode = mode;
288
289 switch (mode) {
290 case CRTC_MODE_NORMAL:
291 exynos_drm_crtc_commit(crtc);
292 break;
293 case CRTC_MODE_BLANK:
294 exynos_plane_dpms(exynos_crtc->plane,
295 DRM_MODE_DPMS_OFF);
296 break;
297 default:
298 break;
299 }
300
301 return 0;
302 }
303
304 return -EINVAL;
305}
306
Inki Dae1c248b72011-10-04 19:19:01 +0900307static struct drm_crtc_funcs exynos_crtc_funcs = {
308 .set_config = drm_crtc_helper_set_config,
309 .page_flip = exynos_drm_crtc_page_flip,
310 .destroy = exynos_drm_crtc_destroy,
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900311 .set_property = exynos_drm_crtc_set_property,
Inki Dae1c248b72011-10-04 19:19:01 +0900312};
313
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900314static const struct drm_prop_enum_list mode_names[] = {
315 { CRTC_MODE_NORMAL, "normal" },
316 { CRTC_MODE_BLANK, "blank" },
317};
318
319static void exynos_drm_crtc_attach_mode_property(struct drm_crtc *crtc)
320{
321 struct drm_device *dev = crtc->dev;
322 struct exynos_drm_private *dev_priv = dev->dev_private;
323 struct drm_property *prop;
324
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900325 prop = dev_priv->crtc_mode_property;
326 if (!prop) {
327 prop = drm_property_create_enum(dev, 0, "mode", mode_names,
328 ARRAY_SIZE(mode_names));
329 if (!prop)
330 return;
331
332 dev_priv->crtc_mode_property = prop;
333 }
334
335 drm_object_attach_property(&crtc->base, prop, 0);
336}
337
Sean Paul080be03d2014-02-19 21:02:55 +0900338int exynos_drm_crtc_create(struct exynos_drm_manager *manager)
Inki Dae1c248b72011-10-04 19:19:01 +0900339{
340 struct exynos_drm_crtc *exynos_crtc;
Sean Paul080be03d2014-02-19 21:02:55 +0900341 struct exynos_drm_private *private = manager->drm_dev->dev_private;
Inki Dae1c248b72011-10-04 19:19:01 +0900342 struct drm_crtc *crtc;
343
Inki Dae1c248b72011-10-04 19:19:01 +0900344 exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL);
Sachin Kamat38bb5252013-08-19 19:04:55 +0900345 if (!exynos_crtc)
Inki Dae1c248b72011-10-04 19:19:01 +0900346 return -ENOMEM;
Inki Dae1c248b72011-10-04 19:19:01 +0900347
Inki Dae20cd2642013-05-21 16:55:58 +0900348 init_waitqueue_head(&exynos_crtc->pending_flip_queue);
349 atomic_set(&exynos_crtc->pending_flip, 0);
Sean Paul080be03d2014-02-19 21:02:55 +0900350
351 exynos_crtc->dpms = DRM_MODE_DPMS_OFF;
352 exynos_crtc->manager = manager;
353 exynos_crtc->pipe = manager->pipe;
354 exynos_crtc->plane = exynos_plane_init(manager->drm_dev,
355 1 << manager->pipe, true);
Joonyoung Shimb5d2eb32012-06-27 14:27:04 +0900356 if (!exynos_crtc->plane) {
357 kfree(exynos_crtc);
358 return -ENOMEM;
359 }
360
Inki Dae1c248b72011-10-04 19:19:01 +0900361 crtc = &exynos_crtc->drm_crtc;
362
Sean Paul080be03d2014-02-19 21:02:55 +0900363 private->crtc[manager->pipe] = crtc;
Inki Dae1c248b72011-10-04 19:19:01 +0900364
Sean Paul080be03d2014-02-19 21:02:55 +0900365 drm_crtc_init(manager->drm_dev, crtc, &exynos_crtc_funcs);
Inki Dae1c248b72011-10-04 19:19:01 +0900366 drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs);
367
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900368 exynos_drm_crtc_attach_mode_property(crtc);
369
Inki Dae1c248b72011-10-04 19:19:01 +0900370 return 0;
371}
372
Sean Paul080be03d2014-02-19 21:02:55 +0900373int exynos_drm_crtc_enable_vblank(struct drm_device *dev, int pipe)
Inki Dae1c248b72011-10-04 19:19:01 +0900374{
375 struct exynos_drm_private *private = dev->dev_private;
Inki Daeec05da92011-12-06 11:06:54 +0900376 struct exynos_drm_crtc *exynos_crtc =
Sean Paul080be03d2014-02-19 21:02:55 +0900377 to_exynos_crtc(private->crtc[pipe]);
378 struct exynos_drm_manager *manager = exynos_crtc->manager;
Inki Dae1c248b72011-10-04 19:19:01 +0900379
Inki Daeec05da92011-12-06 11:06:54 +0900380 if (exynos_crtc->dpms != DRM_MODE_DPMS_ON)
381 return -EPERM;
382
Sean Paul080be03d2014-02-19 21:02:55 +0900383 if (manager->ops->enable_vblank)
384 manager->ops->enable_vblank(manager);
Inki Dae1c248b72011-10-04 19:19:01 +0900385
386 return 0;
387}
388
Sean Paul080be03d2014-02-19 21:02:55 +0900389void exynos_drm_crtc_disable_vblank(struct drm_device *dev, int pipe)
Inki Dae1c248b72011-10-04 19:19:01 +0900390{
391 struct exynos_drm_private *private = dev->dev_private;
Inki Daeec05da92011-12-06 11:06:54 +0900392 struct exynos_drm_crtc *exynos_crtc =
Sean Paul080be03d2014-02-19 21:02:55 +0900393 to_exynos_crtc(private->crtc[pipe]);
394 struct exynos_drm_manager *manager = exynos_crtc->manager;
Inki Dae1c248b72011-10-04 19:19:01 +0900395
Inki Daeec05da92011-12-06 11:06:54 +0900396 if (exynos_crtc->dpms != DRM_MODE_DPMS_ON)
397 return;
398
Sean Paul080be03d2014-02-19 21:02:55 +0900399 if (manager->ops->disable_vblank)
400 manager->ops->disable_vblank(manager);
Inki Dae1c248b72011-10-04 19:19:01 +0900401}
Rahul Sharma663d8762013-01-03 05:44:04 -0500402
Sean Paul080be03d2014-02-19 21:02:55 +0900403void exynos_drm_crtc_finish_pageflip(struct drm_device *dev, int pipe)
Rahul Sharma663d8762013-01-03 05:44:04 -0500404{
405 struct exynos_drm_private *dev_priv = dev->dev_private;
406 struct drm_pending_vblank_event *e, *t;
Sean Paul080be03d2014-02-19 21:02:55 +0900407 struct drm_crtc *drm_crtc = dev_priv->crtc[pipe];
Inki Dae20cd2642013-05-21 16:55:58 +0900408 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(drm_crtc);
Rahul Sharma663d8762013-01-03 05:44:04 -0500409 unsigned long flags;
410
Rahul Sharma663d8762013-01-03 05:44:04 -0500411 spin_lock_irqsave(&dev->event_lock, flags);
412
413 list_for_each_entry_safe(e, t, &dev_priv->pageflip_event_list,
414 base.link) {
415 /* if event's pipe isn't same as crtc then ignore it. */
Sean Paul080be03d2014-02-19 21:02:55 +0900416 if (pipe != e->pipe)
Rahul Sharma663d8762013-01-03 05:44:04 -0500417 continue;
418
Rob Clarkc5cca972013-05-22 11:48:40 +0900419 list_del(&e->base.link);
420 drm_send_vblank_event(dev, -1, e);
Sean Paul080be03d2014-02-19 21:02:55 +0900421 drm_vblank_put(dev, pipe);
Inki Dae20cd2642013-05-21 16:55:58 +0900422 atomic_set(&exynos_crtc->pending_flip, 0);
423 wake_up(&exynos_crtc->pending_flip_queue);
Rahul Sharma663d8762013-01-03 05:44:04 -0500424 }
425
426 spin_unlock_irqrestore(&dev->event_lock, flags);
427}
Sean Paul080be03d2014-02-19 21:02:55 +0900428
429void exynos_drm_crtc_plane_mode_set(struct drm_crtc *crtc,
430 struct exynos_drm_overlay *overlay)
431{
432 struct exynos_drm_manager *manager = to_exynos_crtc(crtc)->manager;
433
434 if (manager->ops->win_mode_set)
435 manager->ops->win_mode_set(manager, overlay);
436}
437
438void exynos_drm_crtc_plane_commit(struct drm_crtc *crtc, int zpos)
439{
440 struct exynos_drm_manager *manager = to_exynos_crtc(crtc)->manager;
441
442 if (manager->ops->win_commit)
443 manager->ops->win_commit(manager, zpos);
444}
445
446void exynos_drm_crtc_plane_enable(struct drm_crtc *crtc, int zpos)
447{
448 struct exynos_drm_manager *manager = to_exynos_crtc(crtc)->manager;
449
450 if (manager->ops->win_enable)
451 manager->ops->win_enable(manager, zpos);
452}
453
454void exynos_drm_crtc_plane_disable(struct drm_crtc *crtc, int zpos)
455{
456 struct exynos_drm_manager *manager = to_exynos_crtc(crtc)->manager;
457
458 if (manager->ops->win_disable)
459 manager->ops->win_disable(manager, zpos);
460}
461
462void exynos_drm_crtc_complete_scanout(struct drm_framebuffer *fb)
463{
464 struct exynos_drm_manager *manager;
465 struct drm_device *dev = fb->dev;
466 struct drm_crtc *crtc;
467
468 /*
469 * make sure that overlay data are updated to real hardware
470 * for all encoders.
471 */
472 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
473 manager = to_exynos_crtc(crtc)->manager;
474
475 /*
476 * wait for vblank interrupt
477 * - this makes sure that overlay data are updated to
478 * real hardware.
479 */
480 if (manager->ops->wait_for_vblank)
481 manager->ops->wait_for_vblank(manager);
482 }
483}