blob: 7810338591dfca21fc82bb4702335a28b6cf2f34 [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);
Sean Paulcd706aa2014-01-30 16:19:18 -0500118 struct exynos_drm_manager *manager = exynos_crtc->manager;
Joonyoung Shim4070d212012-06-27 14:27:05 +0900119 struct drm_plane *plane = exynos_crtc->plane;
120 unsigned int crtc_w;
121 unsigned int crtc_h;
Joonyoung Shimaeb29222012-06-27 14:27:01 +0900122 int ret;
123
Inki Dae1de425b2012-03-16 18:47:04 +0900124 /*
125 * copy the mode data adjusted by mode_fixup() into crtc->mode
126 * so that hardware can be seet to proper mode.
127 */
128 memcpy(&crtc->mode, adjusted_mode, sizeof(*adjusted_mode));
Inki Dae1c248b72011-10-04 19:19:01 +0900129
Joonyoung Shim4070d212012-06-27 14:27:05 +0900130 crtc_w = crtc->fb->width - x;
131 crtc_h = crtc->fb->height - y;
132
Sean Paulcd706aa2014-01-30 16:19:18 -0500133 if (manager->ops->mode_set)
134 manager->ops->mode_set(manager, &crtc->mode);
135
Joonyoung Shim4070d212012-06-27 14:27:05 +0900136 ret = exynos_plane_mode_set(plane, crtc, crtc->fb, 0, 0, crtc_w, crtc_h,
137 x, y, crtc_w, crtc_h);
Joonyoung Shimaeb29222012-06-27 14:27:01 +0900138 if (ret)
139 return ret;
140
Joonyoung Shim4070d212012-06-27 14:27:05 +0900141 plane->crtc = crtc;
142 plane->fb = crtc->fb;
143
Joonyoung Shimaeb29222012-06-27 14:27:01 +0900144 return 0;
Inki Dae1c248b72011-10-04 19:19:01 +0900145}
146
Inki Dae7fd65df2013-05-12 16:09:33 +0900147static int exynos_drm_crtc_mode_set_commit(struct drm_crtc *crtc, int x, int y,
Inki Dae1c248b72011-10-04 19:19:01 +0900148 struct drm_framebuffer *old_fb)
149{
Joonyoung Shim4070d212012-06-27 14:27:05 +0900150 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
151 struct drm_plane *plane = exynos_crtc->plane;
152 unsigned int crtc_w;
153 unsigned int crtc_h;
Inki Dae1c248b72011-10-04 19:19:01 +0900154 int ret;
155
Inki Dae32aeab12012-09-14 13:29:47 +0900156 /* when framebuffer changing is requested, crtc's dpms should be on */
157 if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) {
158 DRM_ERROR("failed framebuffer changing request.\n");
159 return -EPERM;
160 }
161
Joonyoung Shim4070d212012-06-27 14:27:05 +0900162 crtc_w = crtc->fb->width - x;
163 crtc_h = crtc->fb->height - y;
164
165 ret = exynos_plane_mode_set(plane, crtc, crtc->fb, 0, 0, crtc_w, crtc_h,
166 x, y, crtc_w, crtc_h);
Inki Dae1c248b72011-10-04 19:19:01 +0900167 if (ret)
168 return ret;
169
Joonyoung Shimbebab8f2012-06-27 14:27:07 +0900170 exynos_drm_crtc_commit(crtc);
Inki Dae1c248b72011-10-04 19:19:01 +0900171
Joonyoung Shim4070d212012-06-27 14:27:05 +0900172 return 0;
Inki Dae1c248b72011-10-04 19:19:01 +0900173}
174
Inki Dae7fd65df2013-05-12 16:09:33 +0900175static int exynos_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
176 struct drm_framebuffer *old_fb)
177{
178 return exynos_drm_crtc_mode_set_commit(crtc, x, y, old_fb);
179}
180
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900181static void exynos_drm_crtc_disable(struct drm_crtc *crtc)
182{
Sean Paula9c4cd22014-01-30 16:19:17 -0500183 struct drm_plane *plane;
184 int ret;
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900185
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900186 exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
Sean Paula9c4cd22014-01-30 16:19:17 -0500187
188 list_for_each_entry(plane, &crtc->dev->mode_config.plane_list, head) {
189 if (plane->crtc != crtc)
190 continue;
191
192 ret = plane->funcs->disable_plane(plane);
193 if (ret)
194 DRM_ERROR("Failed to disable plane %d\n", ret);
195 }
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900196}
197
Inki Dae1c248b72011-10-04 19:19:01 +0900198static struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = {
199 .dpms = exynos_drm_crtc_dpms,
200 .prepare = exynos_drm_crtc_prepare,
201 .commit = exynos_drm_crtc_commit,
202 .mode_fixup = exynos_drm_crtc_mode_fixup,
203 .mode_set = exynos_drm_crtc_mode_set,
204 .mode_set_base = exynos_drm_crtc_mode_set_base,
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900205 .disable = exynos_drm_crtc_disable,
Inki Dae1c248b72011-10-04 19:19:01 +0900206};
207
208static int exynos_drm_crtc_page_flip(struct drm_crtc *crtc,
Keith Packarded8d1972013-07-22 18:49:58 -0700209 struct drm_framebuffer *fb,
210 struct drm_pending_vblank_event *event,
211 uint32_t page_flip_flags)
Inki Dae1c248b72011-10-04 19:19:01 +0900212{
213 struct drm_device *dev = crtc->dev;
214 struct exynos_drm_private *dev_priv = dev->dev_private;
215 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
216 struct drm_framebuffer *old_fb = crtc->fb;
217 int ret = -EINVAL;
218
Inki Daeef6223d2012-09-11 18:25:21 +0900219 /* when the page flip is requested, crtc's dpms should be on */
220 if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) {
221 DRM_ERROR("failed page flip request.\n");
222 return -EINVAL;
223 }
224
Inki Dae1c248b72011-10-04 19:19:01 +0900225 mutex_lock(&dev->struct_mutex);
226
Inki Daeccf4d882011-10-14 13:29:51 +0900227 if (event) {
228 /*
229 * the pipe from user always is 0 so we can set pipe number
230 * of current owner to event.
231 */
232 event->pipe = exynos_crtc->pipe;
233
Inki Dae1c248b72011-10-04 19:19:01 +0900234 ret = drm_vblank_get(dev, exynos_crtc->pipe);
235 if (ret) {
236 DRM_DEBUG("failed to acquire vblank counter\n");
Inki Daeccf4d882011-10-14 13:29:51 +0900237
Inki Dae1c248b72011-10-04 19:19:01 +0900238 goto out;
239 }
240
Imre Deak85473322012-11-02 13:30:47 +0200241 spin_lock_irq(&dev->event_lock);
Inki Daec5614ae2012-02-15 11:25:20 +0900242 list_add_tail(&event->base.link,
243 &dev_priv->pageflip_event_list);
Inki Dae20cd2642013-05-21 16:55:58 +0900244 atomic_set(&exynos_crtc->pending_flip, 1);
Imre Deak85473322012-11-02 13:30:47 +0200245 spin_unlock_irq(&dev->event_lock);
Inki Daec5614ae2012-02-15 11:25:20 +0900246
Inki Dae1c248b72011-10-04 19:19:01 +0900247 crtc->fb = fb;
Inki Dae7fd65df2013-05-12 16:09:33 +0900248 ret = exynos_drm_crtc_mode_set_commit(crtc, crtc->x, crtc->y,
Joonyoung Shim4070d212012-06-27 14:27:05 +0900249 NULL);
Inki Dae1c248b72011-10-04 19:19:01 +0900250 if (ret) {
251 crtc->fb = old_fb;
Imre Deak85473322012-11-02 13:30:47 +0200252
253 spin_lock_irq(&dev->event_lock);
Inki Dae1c248b72011-10-04 19:19:01 +0900254 drm_vblank_put(dev, exynos_crtc->pipe);
Inki Daeccf4d882011-10-14 13:29:51 +0900255 list_del(&event->base.link);
Imre Deak85473322012-11-02 13:30:47 +0200256 spin_unlock_irq(&dev->event_lock);
Inki Dae1c248b72011-10-04 19:19:01 +0900257
258 goto out;
259 }
Inki Dae1c248b72011-10-04 19:19:01 +0900260 }
261out:
262 mutex_unlock(&dev->struct_mutex);
263 return ret;
264}
265
266static void exynos_drm_crtc_destroy(struct drm_crtc *crtc)
267{
268 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
269 struct exynos_drm_private *private = crtc->dev->dev_private;
270
Inki Dae1c248b72011-10-04 19:19:01 +0900271 private->crtc[exynos_crtc->pipe] = NULL;
272
273 drm_crtc_cleanup(crtc);
274 kfree(exynos_crtc);
275}
276
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900277static int exynos_drm_crtc_set_property(struct drm_crtc *crtc,
278 struct drm_property *property,
279 uint64_t val)
280{
281 struct drm_device *dev = crtc->dev;
282 struct exynos_drm_private *dev_priv = dev->dev_private;
283 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
284
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900285 if (property == dev_priv->crtc_mode_property) {
286 enum exynos_crtc_mode mode = val;
287
288 if (mode == exynos_crtc->mode)
289 return 0;
290
291 exynos_crtc->mode = mode;
292
293 switch (mode) {
294 case CRTC_MODE_NORMAL:
295 exynos_drm_crtc_commit(crtc);
296 break;
297 case CRTC_MODE_BLANK:
298 exynos_plane_dpms(exynos_crtc->plane,
299 DRM_MODE_DPMS_OFF);
300 break;
301 default:
302 break;
303 }
304
305 return 0;
306 }
307
308 return -EINVAL;
309}
310
Inki Dae1c248b72011-10-04 19:19:01 +0900311static struct drm_crtc_funcs exynos_crtc_funcs = {
312 .set_config = drm_crtc_helper_set_config,
313 .page_flip = exynos_drm_crtc_page_flip,
314 .destroy = exynos_drm_crtc_destroy,
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900315 .set_property = exynos_drm_crtc_set_property,
Inki Dae1c248b72011-10-04 19:19:01 +0900316};
317
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900318static const struct drm_prop_enum_list mode_names[] = {
319 { CRTC_MODE_NORMAL, "normal" },
320 { CRTC_MODE_BLANK, "blank" },
321};
322
323static void exynos_drm_crtc_attach_mode_property(struct drm_crtc *crtc)
324{
325 struct drm_device *dev = crtc->dev;
326 struct exynos_drm_private *dev_priv = dev->dev_private;
327 struct drm_property *prop;
328
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900329 prop = dev_priv->crtc_mode_property;
330 if (!prop) {
331 prop = drm_property_create_enum(dev, 0, "mode", mode_names,
332 ARRAY_SIZE(mode_names));
333 if (!prop)
334 return;
335
336 dev_priv->crtc_mode_property = prop;
337 }
338
339 drm_object_attach_property(&crtc->base, prop, 0);
340}
341
Sean Paul080be03d2014-02-19 21:02:55 +0900342int exynos_drm_crtc_create(struct exynos_drm_manager *manager)
Inki Dae1c248b72011-10-04 19:19:01 +0900343{
344 struct exynos_drm_crtc *exynos_crtc;
Sean Paul080be03d2014-02-19 21:02:55 +0900345 struct exynos_drm_private *private = manager->drm_dev->dev_private;
Inki Dae1c248b72011-10-04 19:19:01 +0900346 struct drm_crtc *crtc;
347
Inki Dae1c248b72011-10-04 19:19:01 +0900348 exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL);
Sachin Kamat38bb5252013-08-19 19:04:55 +0900349 if (!exynos_crtc)
Inki Dae1c248b72011-10-04 19:19:01 +0900350 return -ENOMEM;
Inki Dae1c248b72011-10-04 19:19:01 +0900351
Inki Dae20cd2642013-05-21 16:55:58 +0900352 init_waitqueue_head(&exynos_crtc->pending_flip_queue);
353 atomic_set(&exynos_crtc->pending_flip, 0);
Sean Paul080be03d2014-02-19 21:02:55 +0900354
355 exynos_crtc->dpms = DRM_MODE_DPMS_OFF;
356 exynos_crtc->manager = manager;
357 exynos_crtc->pipe = manager->pipe;
358 exynos_crtc->plane = exynos_plane_init(manager->drm_dev,
359 1 << manager->pipe, true);
Joonyoung Shimb5d2eb32012-06-27 14:27:04 +0900360 if (!exynos_crtc->plane) {
361 kfree(exynos_crtc);
362 return -ENOMEM;
363 }
364
Inki Dae1c248b72011-10-04 19:19:01 +0900365 crtc = &exynos_crtc->drm_crtc;
366
Sean Paul080be03d2014-02-19 21:02:55 +0900367 private->crtc[manager->pipe] = crtc;
Inki Dae1c248b72011-10-04 19:19:01 +0900368
Sean Paul080be03d2014-02-19 21:02:55 +0900369 drm_crtc_init(manager->drm_dev, crtc, &exynos_crtc_funcs);
Inki Dae1c248b72011-10-04 19:19:01 +0900370 drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs);
371
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900372 exynos_drm_crtc_attach_mode_property(crtc);
373
Inki Dae1c248b72011-10-04 19:19:01 +0900374 return 0;
375}
376
Sean Paul080be03d2014-02-19 21:02:55 +0900377int exynos_drm_crtc_enable_vblank(struct drm_device *dev, int pipe)
Inki Dae1c248b72011-10-04 19:19:01 +0900378{
379 struct exynos_drm_private *private = dev->dev_private;
Inki Daeec05da92011-12-06 11:06:54 +0900380 struct exynos_drm_crtc *exynos_crtc =
Sean Paul080be03d2014-02-19 21:02:55 +0900381 to_exynos_crtc(private->crtc[pipe]);
382 struct exynos_drm_manager *manager = exynos_crtc->manager;
Inki Dae1c248b72011-10-04 19:19:01 +0900383
Inki Daeec05da92011-12-06 11:06:54 +0900384 if (exynos_crtc->dpms != DRM_MODE_DPMS_ON)
385 return -EPERM;
386
Sean Paul080be03d2014-02-19 21:02:55 +0900387 if (manager->ops->enable_vblank)
388 manager->ops->enable_vblank(manager);
Inki Dae1c248b72011-10-04 19:19:01 +0900389
390 return 0;
391}
392
Sean Paul080be03d2014-02-19 21:02:55 +0900393void exynos_drm_crtc_disable_vblank(struct drm_device *dev, int pipe)
Inki Dae1c248b72011-10-04 19:19:01 +0900394{
395 struct exynos_drm_private *private = dev->dev_private;
Inki Daeec05da92011-12-06 11:06:54 +0900396 struct exynos_drm_crtc *exynos_crtc =
Sean Paul080be03d2014-02-19 21:02:55 +0900397 to_exynos_crtc(private->crtc[pipe]);
398 struct exynos_drm_manager *manager = exynos_crtc->manager;
Inki Dae1c248b72011-10-04 19:19:01 +0900399
Inki Daeec05da92011-12-06 11:06:54 +0900400 if (exynos_crtc->dpms != DRM_MODE_DPMS_ON)
401 return;
402
Sean Paul080be03d2014-02-19 21:02:55 +0900403 if (manager->ops->disable_vblank)
404 manager->ops->disable_vblank(manager);
Inki Dae1c248b72011-10-04 19:19:01 +0900405}
Rahul Sharma663d8762013-01-03 05:44:04 -0500406
Sean Paul080be03d2014-02-19 21:02:55 +0900407void exynos_drm_crtc_finish_pageflip(struct drm_device *dev, int pipe)
Rahul Sharma663d8762013-01-03 05:44:04 -0500408{
409 struct exynos_drm_private *dev_priv = dev->dev_private;
410 struct drm_pending_vblank_event *e, *t;
Sean Paul080be03d2014-02-19 21:02:55 +0900411 struct drm_crtc *drm_crtc = dev_priv->crtc[pipe];
Inki Dae20cd2642013-05-21 16:55:58 +0900412 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(drm_crtc);
Rahul Sharma663d8762013-01-03 05:44:04 -0500413 unsigned long flags;
414
Rahul Sharma663d8762013-01-03 05:44:04 -0500415 spin_lock_irqsave(&dev->event_lock, flags);
416
417 list_for_each_entry_safe(e, t, &dev_priv->pageflip_event_list,
418 base.link) {
419 /* if event's pipe isn't same as crtc then ignore it. */
Sean Paul080be03d2014-02-19 21:02:55 +0900420 if (pipe != e->pipe)
Rahul Sharma663d8762013-01-03 05:44:04 -0500421 continue;
422
Rob Clarkc5cca972013-05-22 11:48:40 +0900423 list_del(&e->base.link);
424 drm_send_vblank_event(dev, -1, e);
Sean Paul080be03d2014-02-19 21:02:55 +0900425 drm_vblank_put(dev, pipe);
Inki Dae20cd2642013-05-21 16:55:58 +0900426 atomic_set(&exynos_crtc->pending_flip, 0);
427 wake_up(&exynos_crtc->pending_flip_queue);
Rahul Sharma663d8762013-01-03 05:44:04 -0500428 }
429
430 spin_unlock_irqrestore(&dev->event_lock, flags);
431}
Sean Paul080be03d2014-02-19 21:02:55 +0900432
433void exynos_drm_crtc_plane_mode_set(struct drm_crtc *crtc,
434 struct exynos_drm_overlay *overlay)
435{
436 struct exynos_drm_manager *manager = to_exynos_crtc(crtc)->manager;
437
438 if (manager->ops->win_mode_set)
439 manager->ops->win_mode_set(manager, overlay);
440}
441
442void exynos_drm_crtc_plane_commit(struct drm_crtc *crtc, int zpos)
443{
444 struct exynos_drm_manager *manager = to_exynos_crtc(crtc)->manager;
445
446 if (manager->ops->win_commit)
447 manager->ops->win_commit(manager, zpos);
448}
449
450void exynos_drm_crtc_plane_enable(struct drm_crtc *crtc, int zpos)
451{
452 struct exynos_drm_manager *manager = to_exynos_crtc(crtc)->manager;
453
454 if (manager->ops->win_enable)
455 manager->ops->win_enable(manager, zpos);
456}
457
458void exynos_drm_crtc_plane_disable(struct drm_crtc *crtc, int zpos)
459{
460 struct exynos_drm_manager *manager = to_exynos_crtc(crtc)->manager;
461
462 if (manager->ops->win_disable)
463 manager->ops->win_disable(manager, zpos);
464}
465
466void exynos_drm_crtc_complete_scanout(struct drm_framebuffer *fb)
467{
468 struct exynos_drm_manager *manager;
469 struct drm_device *dev = fb->dev;
470 struct drm_crtc *crtc;
471
472 /*
473 * make sure that overlay data are updated to real hardware
474 * for all encoders.
475 */
476 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
477 manager = to_exynos_crtc(crtc)->manager;
478
479 /*
480 * wait for vblank interrupt
481 * - this makes sure that overlay data are updated to
482 * real hardware.
483 */
484 if (manager->ops->wait_for_vblank)
485 manager->ops->wait_for_vblank(manager);
486 }
487}