blob: 9cc92ae6b71089724a60bba37d0753368da61832 [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{
Sean Paul4b405262014-01-30 16:19:19 -0500108 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
109 struct exynos_drm_manager *manager = exynos_crtc->manager;
110
111 if (manager->ops->mode_fixup)
112 return manager->ops->mode_fixup(manager, mode, adjusted_mode);
113
Inki Dae1c248b72011-10-04 19:19:01 +0900114 return true;
115}
116
117static int
118exynos_drm_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode,
119 struct drm_display_mode *adjusted_mode, int x, int y,
120 struct drm_framebuffer *old_fb)
121{
Joonyoung Shimaeb29222012-06-27 14:27:01 +0900122 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
Sean Paulcd706aa2014-01-30 16:19:18 -0500123 struct exynos_drm_manager *manager = exynos_crtc->manager;
Joonyoung Shim4070d212012-06-27 14:27:05 +0900124 struct drm_plane *plane = exynos_crtc->plane;
125 unsigned int crtc_w;
126 unsigned int crtc_h;
Joonyoung Shimaeb29222012-06-27 14:27:01 +0900127 int ret;
128
Inki Dae1de425b2012-03-16 18:47:04 +0900129 /*
130 * copy the mode data adjusted by mode_fixup() into crtc->mode
131 * so that hardware can be seet to proper mode.
132 */
133 memcpy(&crtc->mode, adjusted_mode, sizeof(*adjusted_mode));
Inki Dae1c248b72011-10-04 19:19:01 +0900134
Joonyoung Shim4070d212012-06-27 14:27:05 +0900135 crtc_w = crtc->fb->width - x;
136 crtc_h = crtc->fb->height - y;
137
Sean Paulcd706aa2014-01-30 16:19:18 -0500138 if (manager->ops->mode_set)
139 manager->ops->mode_set(manager, &crtc->mode);
140
Joonyoung Shim4070d212012-06-27 14:27:05 +0900141 ret = exynos_plane_mode_set(plane, crtc, crtc->fb, 0, 0, crtc_w, crtc_h,
142 x, y, crtc_w, crtc_h);
Joonyoung Shimaeb29222012-06-27 14:27:01 +0900143 if (ret)
144 return ret;
145
Joonyoung Shim4070d212012-06-27 14:27:05 +0900146 plane->crtc = crtc;
147 plane->fb = crtc->fb;
148
Joonyoung Shimaeb29222012-06-27 14:27:01 +0900149 return 0;
Inki Dae1c248b72011-10-04 19:19:01 +0900150}
151
Inki Dae7fd65df2013-05-12 16:09:33 +0900152static int exynos_drm_crtc_mode_set_commit(struct drm_crtc *crtc, int x, int y,
Inki Dae1c248b72011-10-04 19:19:01 +0900153 struct drm_framebuffer *old_fb)
154{
Joonyoung Shim4070d212012-06-27 14:27:05 +0900155 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
156 struct drm_plane *plane = exynos_crtc->plane;
157 unsigned int crtc_w;
158 unsigned int crtc_h;
Inki Dae1c248b72011-10-04 19:19:01 +0900159 int ret;
160
Inki Dae32aeab12012-09-14 13:29:47 +0900161 /* when framebuffer changing is requested, crtc's dpms should be on */
162 if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) {
163 DRM_ERROR("failed framebuffer changing request.\n");
164 return -EPERM;
165 }
166
Joonyoung Shim4070d212012-06-27 14:27:05 +0900167 crtc_w = crtc->fb->width - x;
168 crtc_h = crtc->fb->height - y;
169
170 ret = exynos_plane_mode_set(plane, crtc, crtc->fb, 0, 0, crtc_w, crtc_h,
171 x, y, crtc_w, crtc_h);
Inki Dae1c248b72011-10-04 19:19:01 +0900172 if (ret)
173 return ret;
174
Joonyoung Shimbebab8f2012-06-27 14:27:07 +0900175 exynos_drm_crtc_commit(crtc);
Inki Dae1c248b72011-10-04 19:19:01 +0900176
Joonyoung Shim4070d212012-06-27 14:27:05 +0900177 return 0;
Inki Dae1c248b72011-10-04 19:19:01 +0900178}
179
Inki Dae7fd65df2013-05-12 16:09:33 +0900180static int exynos_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
181 struct drm_framebuffer *old_fb)
182{
183 return exynos_drm_crtc_mode_set_commit(crtc, x, y, old_fb);
184}
185
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900186static void exynos_drm_crtc_disable(struct drm_crtc *crtc)
187{
Sean Paula9c4cd22014-01-30 16:19:17 -0500188 struct drm_plane *plane;
189 int ret;
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900190
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900191 exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
Sean Paula9c4cd22014-01-30 16:19:17 -0500192
193 list_for_each_entry(plane, &crtc->dev->mode_config.plane_list, head) {
194 if (plane->crtc != crtc)
195 continue;
196
197 ret = plane->funcs->disable_plane(plane);
198 if (ret)
199 DRM_ERROR("Failed to disable plane %d\n", ret);
200 }
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900201}
202
Inki Dae1c248b72011-10-04 19:19:01 +0900203static struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = {
204 .dpms = exynos_drm_crtc_dpms,
205 .prepare = exynos_drm_crtc_prepare,
206 .commit = exynos_drm_crtc_commit,
207 .mode_fixup = exynos_drm_crtc_mode_fixup,
208 .mode_set = exynos_drm_crtc_mode_set,
209 .mode_set_base = exynos_drm_crtc_mode_set_base,
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900210 .disable = exynos_drm_crtc_disable,
Inki Dae1c248b72011-10-04 19:19:01 +0900211};
212
213static int exynos_drm_crtc_page_flip(struct drm_crtc *crtc,
Keith Packarded8d1972013-07-22 18:49:58 -0700214 struct drm_framebuffer *fb,
215 struct drm_pending_vblank_event *event,
216 uint32_t page_flip_flags)
Inki Dae1c248b72011-10-04 19:19:01 +0900217{
218 struct drm_device *dev = crtc->dev;
219 struct exynos_drm_private *dev_priv = dev->dev_private;
220 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
221 struct drm_framebuffer *old_fb = crtc->fb;
222 int ret = -EINVAL;
223
Inki Daeef6223d2012-09-11 18:25:21 +0900224 /* when the page flip is requested, crtc's dpms should be on */
225 if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) {
226 DRM_ERROR("failed page flip request.\n");
227 return -EINVAL;
228 }
229
Inki Dae1c248b72011-10-04 19:19:01 +0900230 mutex_lock(&dev->struct_mutex);
231
Inki Daeccf4d882011-10-14 13:29:51 +0900232 if (event) {
233 /*
234 * the pipe from user always is 0 so we can set pipe number
235 * of current owner to event.
236 */
237 event->pipe = exynos_crtc->pipe;
238
Inki Dae1c248b72011-10-04 19:19:01 +0900239 ret = drm_vblank_get(dev, exynos_crtc->pipe);
240 if (ret) {
241 DRM_DEBUG("failed to acquire vblank counter\n");
Inki Daeccf4d882011-10-14 13:29:51 +0900242
Inki Dae1c248b72011-10-04 19:19:01 +0900243 goto out;
244 }
245
Imre Deak85473322012-11-02 13:30:47 +0200246 spin_lock_irq(&dev->event_lock);
Inki Daec5614ae2012-02-15 11:25:20 +0900247 list_add_tail(&event->base.link,
248 &dev_priv->pageflip_event_list);
Inki Dae20cd2642013-05-21 16:55:58 +0900249 atomic_set(&exynos_crtc->pending_flip, 1);
Imre Deak85473322012-11-02 13:30:47 +0200250 spin_unlock_irq(&dev->event_lock);
Inki Daec5614ae2012-02-15 11:25:20 +0900251
Inki Dae1c248b72011-10-04 19:19:01 +0900252 crtc->fb = fb;
Inki Dae7fd65df2013-05-12 16:09:33 +0900253 ret = exynos_drm_crtc_mode_set_commit(crtc, crtc->x, crtc->y,
Joonyoung Shim4070d212012-06-27 14:27:05 +0900254 NULL);
Inki Dae1c248b72011-10-04 19:19:01 +0900255 if (ret) {
256 crtc->fb = old_fb;
Imre Deak85473322012-11-02 13:30:47 +0200257
258 spin_lock_irq(&dev->event_lock);
Inki Dae1c248b72011-10-04 19:19:01 +0900259 drm_vblank_put(dev, exynos_crtc->pipe);
Inki Daeccf4d882011-10-14 13:29:51 +0900260 list_del(&event->base.link);
Imre Deak85473322012-11-02 13:30:47 +0200261 spin_unlock_irq(&dev->event_lock);
Inki Dae1c248b72011-10-04 19:19:01 +0900262
263 goto out;
264 }
Inki Dae1c248b72011-10-04 19:19:01 +0900265 }
266out:
267 mutex_unlock(&dev->struct_mutex);
268 return ret;
269}
270
271static void exynos_drm_crtc_destroy(struct drm_crtc *crtc)
272{
273 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
274 struct exynos_drm_private *private = crtc->dev->dev_private;
275
Inki Dae1c248b72011-10-04 19:19:01 +0900276 private->crtc[exynos_crtc->pipe] = NULL;
277
278 drm_crtc_cleanup(crtc);
279 kfree(exynos_crtc);
280}
281
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900282static int exynos_drm_crtc_set_property(struct drm_crtc *crtc,
283 struct drm_property *property,
284 uint64_t val)
285{
286 struct drm_device *dev = crtc->dev;
287 struct exynos_drm_private *dev_priv = dev->dev_private;
288 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
289
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900290 if (property == dev_priv->crtc_mode_property) {
291 enum exynos_crtc_mode mode = val;
292
293 if (mode == exynos_crtc->mode)
294 return 0;
295
296 exynos_crtc->mode = mode;
297
298 switch (mode) {
299 case CRTC_MODE_NORMAL:
300 exynos_drm_crtc_commit(crtc);
301 break;
302 case CRTC_MODE_BLANK:
303 exynos_plane_dpms(exynos_crtc->plane,
304 DRM_MODE_DPMS_OFF);
305 break;
306 default:
307 break;
308 }
309
310 return 0;
311 }
312
313 return -EINVAL;
314}
315
Inki Dae1c248b72011-10-04 19:19:01 +0900316static struct drm_crtc_funcs exynos_crtc_funcs = {
317 .set_config = drm_crtc_helper_set_config,
318 .page_flip = exynos_drm_crtc_page_flip,
319 .destroy = exynos_drm_crtc_destroy,
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900320 .set_property = exynos_drm_crtc_set_property,
Inki Dae1c248b72011-10-04 19:19:01 +0900321};
322
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900323static const struct drm_prop_enum_list mode_names[] = {
324 { CRTC_MODE_NORMAL, "normal" },
325 { CRTC_MODE_BLANK, "blank" },
326};
327
328static void exynos_drm_crtc_attach_mode_property(struct drm_crtc *crtc)
329{
330 struct drm_device *dev = crtc->dev;
331 struct exynos_drm_private *dev_priv = dev->dev_private;
332 struct drm_property *prop;
333
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900334 prop = dev_priv->crtc_mode_property;
335 if (!prop) {
336 prop = drm_property_create_enum(dev, 0, "mode", mode_names,
337 ARRAY_SIZE(mode_names));
338 if (!prop)
339 return;
340
341 dev_priv->crtc_mode_property = prop;
342 }
343
344 drm_object_attach_property(&crtc->base, prop, 0);
345}
346
Sean Paul080be03d2014-02-19 21:02:55 +0900347int exynos_drm_crtc_create(struct exynos_drm_manager *manager)
Inki Dae1c248b72011-10-04 19:19:01 +0900348{
349 struct exynos_drm_crtc *exynos_crtc;
Sean Paul080be03d2014-02-19 21:02:55 +0900350 struct exynos_drm_private *private = manager->drm_dev->dev_private;
Inki Dae1c248b72011-10-04 19:19:01 +0900351 struct drm_crtc *crtc;
352
Inki Dae1c248b72011-10-04 19:19:01 +0900353 exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL);
Sachin Kamat38bb5252013-08-19 19:04:55 +0900354 if (!exynos_crtc)
Inki Dae1c248b72011-10-04 19:19:01 +0900355 return -ENOMEM;
Inki Dae1c248b72011-10-04 19:19:01 +0900356
Inki Dae20cd2642013-05-21 16:55:58 +0900357 init_waitqueue_head(&exynos_crtc->pending_flip_queue);
358 atomic_set(&exynos_crtc->pending_flip, 0);
Sean Paul080be03d2014-02-19 21:02:55 +0900359
360 exynos_crtc->dpms = DRM_MODE_DPMS_OFF;
361 exynos_crtc->manager = manager;
362 exynos_crtc->pipe = manager->pipe;
363 exynos_crtc->plane = exynos_plane_init(manager->drm_dev,
364 1 << manager->pipe, true);
Joonyoung Shimb5d2eb32012-06-27 14:27:04 +0900365 if (!exynos_crtc->plane) {
366 kfree(exynos_crtc);
367 return -ENOMEM;
368 }
369
Inki Dae1c248b72011-10-04 19:19:01 +0900370 crtc = &exynos_crtc->drm_crtc;
371
Sean Paul080be03d2014-02-19 21:02:55 +0900372 private->crtc[manager->pipe] = crtc;
Inki Dae1c248b72011-10-04 19:19:01 +0900373
Sean Paul080be03d2014-02-19 21:02:55 +0900374 drm_crtc_init(manager->drm_dev, crtc, &exynos_crtc_funcs);
Inki Dae1c248b72011-10-04 19:19:01 +0900375 drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs);
376
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900377 exynos_drm_crtc_attach_mode_property(crtc);
378
Inki Dae1c248b72011-10-04 19:19:01 +0900379 return 0;
380}
381
Sean Paul080be03d2014-02-19 21:02:55 +0900382int exynos_drm_crtc_enable_vblank(struct drm_device *dev, int pipe)
Inki Dae1c248b72011-10-04 19:19:01 +0900383{
384 struct exynos_drm_private *private = dev->dev_private;
Inki Daeec05da92011-12-06 11:06:54 +0900385 struct exynos_drm_crtc *exynos_crtc =
Sean Paul080be03d2014-02-19 21:02:55 +0900386 to_exynos_crtc(private->crtc[pipe]);
387 struct exynos_drm_manager *manager = exynos_crtc->manager;
Inki Dae1c248b72011-10-04 19:19:01 +0900388
Inki Daeec05da92011-12-06 11:06:54 +0900389 if (exynos_crtc->dpms != DRM_MODE_DPMS_ON)
390 return -EPERM;
391
Sean Paul080be03d2014-02-19 21:02:55 +0900392 if (manager->ops->enable_vblank)
393 manager->ops->enable_vblank(manager);
Inki Dae1c248b72011-10-04 19:19:01 +0900394
395 return 0;
396}
397
Sean Paul080be03d2014-02-19 21:02:55 +0900398void exynos_drm_crtc_disable_vblank(struct drm_device *dev, int pipe)
Inki Dae1c248b72011-10-04 19:19:01 +0900399{
400 struct exynos_drm_private *private = dev->dev_private;
Inki Daeec05da92011-12-06 11:06:54 +0900401 struct exynos_drm_crtc *exynos_crtc =
Sean Paul080be03d2014-02-19 21:02:55 +0900402 to_exynos_crtc(private->crtc[pipe]);
403 struct exynos_drm_manager *manager = exynos_crtc->manager;
Inki Dae1c248b72011-10-04 19:19:01 +0900404
Inki Daeec05da92011-12-06 11:06:54 +0900405 if (exynos_crtc->dpms != DRM_MODE_DPMS_ON)
406 return;
407
Sean Paul080be03d2014-02-19 21:02:55 +0900408 if (manager->ops->disable_vblank)
409 manager->ops->disable_vblank(manager);
Inki Dae1c248b72011-10-04 19:19:01 +0900410}
Rahul Sharma663d8762013-01-03 05:44:04 -0500411
Sean Paul080be03d2014-02-19 21:02:55 +0900412void exynos_drm_crtc_finish_pageflip(struct drm_device *dev, int pipe)
Rahul Sharma663d8762013-01-03 05:44:04 -0500413{
414 struct exynos_drm_private *dev_priv = dev->dev_private;
415 struct drm_pending_vblank_event *e, *t;
Sean Paul080be03d2014-02-19 21:02:55 +0900416 struct drm_crtc *drm_crtc = dev_priv->crtc[pipe];
Inki Dae20cd2642013-05-21 16:55:58 +0900417 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(drm_crtc);
Rahul Sharma663d8762013-01-03 05:44:04 -0500418 unsigned long flags;
419
Rahul Sharma663d8762013-01-03 05:44:04 -0500420 spin_lock_irqsave(&dev->event_lock, flags);
421
422 list_for_each_entry_safe(e, t, &dev_priv->pageflip_event_list,
423 base.link) {
424 /* if event's pipe isn't same as crtc then ignore it. */
Sean Paul080be03d2014-02-19 21:02:55 +0900425 if (pipe != e->pipe)
Rahul Sharma663d8762013-01-03 05:44:04 -0500426 continue;
427
Rob Clarkc5cca972013-05-22 11:48:40 +0900428 list_del(&e->base.link);
429 drm_send_vblank_event(dev, -1, e);
Sean Paul080be03d2014-02-19 21:02:55 +0900430 drm_vblank_put(dev, pipe);
Inki Dae20cd2642013-05-21 16:55:58 +0900431 atomic_set(&exynos_crtc->pending_flip, 0);
432 wake_up(&exynos_crtc->pending_flip_queue);
Rahul Sharma663d8762013-01-03 05:44:04 -0500433 }
434
435 spin_unlock_irqrestore(&dev->event_lock, flags);
436}
Sean Paul080be03d2014-02-19 21:02:55 +0900437
438void exynos_drm_crtc_plane_mode_set(struct drm_crtc *crtc,
439 struct exynos_drm_overlay *overlay)
440{
441 struct exynos_drm_manager *manager = to_exynos_crtc(crtc)->manager;
442
443 if (manager->ops->win_mode_set)
444 manager->ops->win_mode_set(manager, overlay);
445}
446
447void exynos_drm_crtc_plane_commit(struct drm_crtc *crtc, int zpos)
448{
449 struct exynos_drm_manager *manager = to_exynos_crtc(crtc)->manager;
450
451 if (manager->ops->win_commit)
452 manager->ops->win_commit(manager, zpos);
453}
454
455void exynos_drm_crtc_plane_enable(struct drm_crtc *crtc, int zpos)
456{
457 struct exynos_drm_manager *manager = to_exynos_crtc(crtc)->manager;
458
459 if (manager->ops->win_enable)
460 manager->ops->win_enable(manager, zpos);
461}
462
463void exynos_drm_crtc_plane_disable(struct drm_crtc *crtc, int zpos)
464{
465 struct exynos_drm_manager *manager = to_exynos_crtc(crtc)->manager;
466
467 if (manager->ops->win_disable)
468 manager->ops->win_disable(manager, zpos);
469}
470
471void exynos_drm_crtc_complete_scanout(struct drm_framebuffer *fb)
472{
473 struct exynos_drm_manager *manager;
474 struct drm_device *dev = fb->dev;
475 struct drm_crtc *crtc;
476
477 /*
478 * make sure that overlay data are updated to real hardware
479 * for all encoders.
480 */
481 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
482 manager = to_exynos_crtc(crtc)->manager;
483
484 /*
485 * wait for vblank interrupt
486 * - this makes sure that overlay data are updated to
487 * real hardware.
488 */
489 if (manager->ops->wait_for_vblank)
490 manager->ops->wait_for_vblank(manager);
491 }
492}