blob: a85c451ba3929fbc2f916886b968ccfb6e185ea0 [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
Inki Dae1c248b72011-10-04 19:19:01 +090023static void exynos_drm_crtc_dpms(struct drm_crtc *crtc, int mode)
24{
Joonyoung Shimd2716c82011-11-04 17:04:45 +090025 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
Inki Dae1c248b72011-10-04 19:19:01 +090026
Joonyoung Shimd2716c82011-11-04 17:04:45 +090027 DRM_DEBUG_KMS("crtc[%d] mode[%d]\n", crtc->base.id, mode);
28
Inki Daeec05da92011-12-06 11:06:54 +090029 if (exynos_crtc->dpms == mode) {
30 DRM_DEBUG_KMS("desired dpms mode is same as previous one.\n");
31 return;
32 }
33
Inki Dae20cd2642013-05-21 16:55:58 +090034 if (mode > DRM_MODE_DPMS_ON) {
35 /* wait for the completion of page flip. */
YoungJun Choe35d7222014-07-17 18:01:17 +090036 if (!wait_event_timeout(exynos_crtc->pending_flip_queue,
37 !atomic_read(&exynos_crtc->pending_flip),
38 HZ/20))
39 atomic_set(&exynos_crtc->pending_flip, 0);
Andrzej Hajdad6948b22014-10-10 14:31:55 +020040 drm_crtc_vblank_off(crtc);
Inki Dae20cd2642013-05-21 16:55:58 +090041 }
42
Gustavo Padovan93bca242015-01-18 18:16:23 +090043 if (exynos_crtc->ops->dpms)
44 exynos_crtc->ops->dpms(exynos_crtc, mode);
Sean Paul080be03d2014-02-19 21:02:55 +090045
Joonyoung Shimcf5188a2012-06-27 14:27:09 +090046 exynos_crtc->dpms = mode;
Andrzej Hajdad6948b22014-10-10 14:31:55 +020047
48 if (mode == DRM_MODE_DPMS_ON)
49 drm_crtc_vblank_on(crtc);
Inki Dae1c248b72011-10-04 19:19:01 +090050}
51
52static void exynos_drm_crtc_prepare(struct drm_crtc *crtc)
53{
Inki Dae1c248b72011-10-04 19:19:01 +090054 /* drm framework doesn't check NULL. */
55}
56
57static void exynos_drm_crtc_commit(struct drm_crtc *crtc)
58{
Joonyoung Shimd2716c82011-11-04 17:04:45 +090059 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
Gustavo Padovan9d5310c2014-11-13 22:17:46 -020060 struct exynos_drm_plane *exynos_plane = to_exynos_plane(crtc->primary);
Joonyoung Shimd2716c82011-11-04 17:04:45 +090061
Inki Dae50caf252012-08-20 21:29:25 +090062 exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
Sean Paul080be03d2014-02-19 21:02:55 +090063
Gustavo Padovan93bca242015-01-18 18:16:23 +090064 if (exynos_crtc->ops->win_commit)
65 exynos_crtc->ops->win_commit(exynos_crtc, exynos_plane->zpos);
Sean Paul080be03d2014-02-19 21:02:55 +090066
Gustavo Padovan93bca242015-01-18 18:16:23 +090067 if (exynos_crtc->ops->commit)
68 exynos_crtc->ops->commit(exynos_crtc);
Sean Paul080be03d2014-02-19 21:02:55 +090069
Andrzej Hajda72ed6cc2014-09-19 14:58:53 +020070 exynos_plane_dpms(crtc->primary, DRM_MODE_DPMS_ON);
Inki Dae1c248b72011-10-04 19:19:01 +090071}
72
73static bool
74exynos_drm_crtc_mode_fixup(struct drm_crtc *crtc,
Laurent Pincharte811f5a2012-07-17 17:56:50 +020075 const struct drm_display_mode *mode,
Inki Dae1c248b72011-10-04 19:19:01 +090076 struct drm_display_mode *adjusted_mode)
77{
Sean Paul4b405262014-01-30 16:19:19 -050078 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
Sean Paul4b405262014-01-30 16:19:19 -050079
Gustavo Padovan93bca242015-01-18 18:16:23 +090080 if (exynos_crtc->ops->mode_fixup)
81 return exynos_crtc->ops->mode_fixup(exynos_crtc, mode,
82 adjusted_mode);
Sean Paul4b405262014-01-30 16:19:19 -050083
Inki Dae1c248b72011-10-04 19:19:01 +090084 return true;
85}
86
87static int
88exynos_drm_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode,
89 struct drm_display_mode *adjusted_mode, int x, int y,
90 struct drm_framebuffer *old_fb)
91{
Andrzej Hajda72ed6cc2014-09-19 14:58:53 +020092 struct drm_framebuffer *fb = crtc->primary->fb;
Joonyoung Shim4070d212012-06-27 14:27:05 +090093 unsigned int crtc_w;
94 unsigned int crtc_h;
Gustavo Padovanadf56912014-11-27 14:56:09 -020095 int ret;
Joonyoung Shimaeb29222012-06-27 14:27:01 +090096
Inki Dae1de425b2012-03-16 18:47:04 +090097 /*
98 * copy the mode data adjusted by mode_fixup() into crtc->mode
99 * so that hardware can be seet to proper mode.
100 */
101 memcpy(&crtc->mode, adjusted_mode, sizeof(*adjusted_mode));
Inki Dae1c248b72011-10-04 19:19:01 +0900102
Gustavo Padovanadf56912014-11-27 14:56:09 -0200103 ret = exynos_check_plane(crtc->primary, fb);
104 if (ret < 0)
105 return ret;
106
Andrzej Hajda72ed6cc2014-09-19 14:58:53 +0200107 crtc_w = fb->width - x;
108 crtc_h = fb->height - y;
Gustavo Padovanadf56912014-11-27 14:56:09 -0200109 exynos_plane_mode_set(crtc->primary, crtc, fb, 0, 0,
110 crtc_w, crtc_h, x, y, crtc_w, crtc_h);
111
112 return 0;
Inki Dae1c248b72011-10-04 19:19:01 +0900113}
114
Gustavo Padovanfd092d72014-11-13 22:30:00 -0200115static int exynos_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
Inki Dae1c248b72011-10-04 19:19:01 +0900116 struct drm_framebuffer *old_fb)
117{
Joonyoung Shim4070d212012-06-27 14:27:05 +0900118 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
Andrzej Hajda72ed6cc2014-09-19 14:58:53 +0200119 struct drm_framebuffer *fb = crtc->primary->fb;
Joonyoung Shim4070d212012-06-27 14:27:05 +0900120 unsigned int crtc_w;
121 unsigned int crtc_h;
Inki Dae1c248b72011-10-04 19:19:01 +0900122
Inki Dae32aeab12012-09-14 13:29:47 +0900123 /* when framebuffer changing is requested, crtc's dpms should be on */
124 if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) {
125 DRM_ERROR("failed framebuffer changing request.\n");
126 return -EPERM;
127 }
128
Andrzej Hajda72ed6cc2014-09-19 14:58:53 +0200129 crtc_w = fb->width - x;
130 crtc_h = fb->height - y;
Joonyoung Shim4070d212012-06-27 14:27:05 +0900131
Gustavo Padovan0e0a6492014-11-25 11:21:17 -0200132 return exynos_update_plane(crtc->primary, crtc, fb, 0, 0,
133 crtc_w, crtc_h, x, y, crtc_w, crtc_h);
Inki Dae1c248b72011-10-04 19:19:01 +0900134}
135
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900136static void exynos_drm_crtc_disable(struct drm_crtc *crtc)
137{
Sean Paula9c4cd22014-01-30 16:19:17 -0500138 struct drm_plane *plane;
139 int ret;
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900140
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900141 exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
Sean Paula9c4cd22014-01-30 16:19:17 -0500142
Matt Roper08863272014-04-01 15:22:31 -0700143 drm_for_each_legacy_plane(plane, &crtc->dev->mode_config.plane_list) {
Sean Paula9c4cd22014-01-30 16:19:17 -0500144 if (plane->crtc != crtc)
145 continue;
146
147 ret = plane->funcs->disable_plane(plane);
148 if (ret)
149 DRM_ERROR("Failed to disable plane %d\n", ret);
150 }
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900151}
152
Inki Dae1c248b72011-10-04 19:19:01 +0900153static struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = {
154 .dpms = exynos_drm_crtc_dpms,
155 .prepare = exynos_drm_crtc_prepare,
156 .commit = exynos_drm_crtc_commit,
157 .mode_fixup = exynos_drm_crtc_mode_fixup,
158 .mode_set = exynos_drm_crtc_mode_set,
159 .mode_set_base = exynos_drm_crtc_mode_set_base,
Joonyoung Shima365d9e2012-06-27 14:27:10 +0900160 .disable = exynos_drm_crtc_disable,
Inki Dae1c248b72011-10-04 19:19:01 +0900161};
162
163static int exynos_drm_crtc_page_flip(struct drm_crtc *crtc,
Keith Packarded8d1972013-07-22 18:49:58 -0700164 struct drm_framebuffer *fb,
165 struct drm_pending_vblank_event *event,
166 uint32_t page_flip_flags)
Inki Dae1c248b72011-10-04 19:19:01 +0900167{
168 struct drm_device *dev = crtc->dev;
169 struct exynos_drm_private *dev_priv = dev->dev_private;
170 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -0700171 struct drm_framebuffer *old_fb = crtc->primary->fb;
Gustavo Padovan8b9c4502014-11-25 16:18:34 -0200172 unsigned int crtc_w, crtc_h;
Inki Dae1c248b72011-10-04 19:19:01 +0900173 int ret = -EINVAL;
174
Inki Daeef6223d2012-09-11 18:25:21 +0900175 /* when the page flip is requested, crtc's dpms should be on */
176 if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) {
177 DRM_ERROR("failed page flip request.\n");
178 return -EINVAL;
179 }
180
Inki Dae1c248b72011-10-04 19:19:01 +0900181 mutex_lock(&dev->struct_mutex);
182
Inki Daeccf4d882011-10-14 13:29:51 +0900183 if (event) {
184 /*
185 * the pipe from user always is 0 so we can set pipe number
186 * of current owner to event.
187 */
188 event->pipe = exynos_crtc->pipe;
189
Inki Dae1c248b72011-10-04 19:19:01 +0900190 ret = drm_vblank_get(dev, exynos_crtc->pipe);
191 if (ret) {
192 DRM_DEBUG("failed to acquire vblank counter\n");
Inki Daeccf4d882011-10-14 13:29:51 +0900193
Inki Dae1c248b72011-10-04 19:19:01 +0900194 goto out;
195 }
196
Imre Deak85473322012-11-02 13:30:47 +0200197 spin_lock_irq(&dev->event_lock);
Inki Daec5614ae2012-02-15 11:25:20 +0900198 list_add_tail(&event->base.link,
199 &dev_priv->pageflip_event_list);
Inki Dae20cd2642013-05-21 16:55:58 +0900200 atomic_set(&exynos_crtc->pending_flip, 1);
Imre Deak85473322012-11-02 13:30:47 +0200201 spin_unlock_irq(&dev->event_lock);
Inki Daec5614ae2012-02-15 11:25:20 +0900202
Matt Roperf4510a22014-04-01 15:22:40 -0700203 crtc->primary->fb = fb;
Gustavo Padovan8b9c4502014-11-25 16:18:34 -0200204 crtc_w = fb->width - crtc->x;
205 crtc_h = fb->height - crtc->y;
206 ret = exynos_update_plane(crtc->primary, crtc, fb, 0, 0,
207 crtc_w, crtc_h, crtc->x, crtc->y,
208 crtc_w, crtc_h);
Inki Dae1c248b72011-10-04 19:19:01 +0900209 if (ret) {
Matt Roperf4510a22014-04-01 15:22:40 -0700210 crtc->primary->fb = old_fb;
Imre Deak85473322012-11-02 13:30:47 +0200211
212 spin_lock_irq(&dev->event_lock);
Inki Dae1c248b72011-10-04 19:19:01 +0900213 drm_vblank_put(dev, exynos_crtc->pipe);
Inki Daeccf4d882011-10-14 13:29:51 +0900214 list_del(&event->base.link);
YoungJun Choe35d7222014-07-17 18:01:17 +0900215 atomic_set(&exynos_crtc->pending_flip, 0);
Imre Deak85473322012-11-02 13:30:47 +0200216 spin_unlock_irq(&dev->event_lock);
Inki Dae1c248b72011-10-04 19:19:01 +0900217
218 goto out;
219 }
Inki Dae1c248b72011-10-04 19:19:01 +0900220 }
221out:
222 mutex_unlock(&dev->struct_mutex);
223 return ret;
224}
225
226static void exynos_drm_crtc_destroy(struct drm_crtc *crtc)
227{
228 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
229 struct exynos_drm_private *private = crtc->dev->dev_private;
230
Inki Dae1c248b72011-10-04 19:19:01 +0900231 private->crtc[exynos_crtc->pipe] = NULL;
232
233 drm_crtc_cleanup(crtc);
234 kfree(exynos_crtc);
235}
236
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900237static int exynos_drm_crtc_set_property(struct drm_crtc *crtc,
238 struct drm_property *property,
239 uint64_t val)
240{
241 struct drm_device *dev = crtc->dev;
242 struct exynos_drm_private *dev_priv = dev->dev_private;
243 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
244
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900245 if (property == dev_priv->crtc_mode_property) {
246 enum exynos_crtc_mode mode = val;
247
248 if (mode == exynos_crtc->mode)
249 return 0;
250
251 exynos_crtc->mode = mode;
252
253 switch (mode) {
254 case CRTC_MODE_NORMAL:
255 exynos_drm_crtc_commit(crtc);
256 break;
257 case CRTC_MODE_BLANK:
Andrzej Hajda72ed6cc2014-09-19 14:58:53 +0200258 exynos_plane_dpms(crtc->primary, DRM_MODE_DPMS_OFF);
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900259 break;
260 default:
261 break;
262 }
263
264 return 0;
265 }
266
267 return -EINVAL;
268}
269
Inki Dae1c248b72011-10-04 19:19:01 +0900270static struct drm_crtc_funcs exynos_crtc_funcs = {
271 .set_config = drm_crtc_helper_set_config,
272 .page_flip = exynos_drm_crtc_page_flip,
273 .destroy = exynos_drm_crtc_destroy,
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900274 .set_property = exynos_drm_crtc_set_property,
Inki Dae1c248b72011-10-04 19:19:01 +0900275};
276
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900277static const struct drm_prop_enum_list mode_names[] = {
278 { CRTC_MODE_NORMAL, "normal" },
279 { CRTC_MODE_BLANK, "blank" },
280};
281
282static void exynos_drm_crtc_attach_mode_property(struct drm_crtc *crtc)
283{
284 struct drm_device *dev = crtc->dev;
285 struct exynos_drm_private *dev_priv = dev->dev_private;
286 struct drm_property *prop;
287
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900288 prop = dev_priv->crtc_mode_property;
289 if (!prop) {
290 prop = drm_property_create_enum(dev, 0, "mode", mode_names,
291 ARRAY_SIZE(mode_names));
292 if (!prop)
293 return;
294
295 dev_priv->crtc_mode_property = prop;
296 }
297
298 drm_object_attach_property(&crtc->base, prop, 0);
299}
300
Gustavo Padovan93bca242015-01-18 18:16:23 +0900301struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev,
302 int pipe,
303 enum exynos_drm_output_type type,
304 struct exynos_drm_crtc_ops *ops,
305 void *ctx)
Inki Dae1c248b72011-10-04 19:19:01 +0900306{
307 struct exynos_drm_crtc *exynos_crtc;
Andrzej Hajda72ed6cc2014-09-19 14:58:53 +0200308 struct drm_plane *plane;
Gustavo Padovaneb88e422014-11-26 16:43:27 -0200309 struct exynos_drm_private *private = drm_dev->dev_private;
Inki Dae1c248b72011-10-04 19:19:01 +0900310 struct drm_crtc *crtc;
Andrzej Hajda72ed6cc2014-09-19 14:58:53 +0200311 int ret;
Inki Dae1c248b72011-10-04 19:19:01 +0900312
Inki Dae1c248b72011-10-04 19:19:01 +0900313 exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL);
Sachin Kamat38bb5252013-08-19 19:04:55 +0900314 if (!exynos_crtc)
Gustavo Padovan93bca242015-01-18 18:16:23 +0900315 return ERR_PTR(-ENOMEM);
Inki Dae1c248b72011-10-04 19:19:01 +0900316
Inki Dae20cd2642013-05-21 16:55:58 +0900317 init_waitqueue_head(&exynos_crtc->pending_flip_queue);
318 atomic_set(&exynos_crtc->pending_flip, 0);
Sean Paul080be03d2014-02-19 21:02:55 +0900319
320 exynos_crtc->dpms = DRM_MODE_DPMS_OFF;
Gustavo Padovane09f2b02014-11-04 18:25:27 -0200321 exynos_crtc->pipe = pipe;
Gustavo Padovan5d1741a2014-11-05 19:51:35 -0200322 exynos_crtc->type = type;
Gustavo Padovan93bca242015-01-18 18:16:23 +0900323 exynos_crtc->ops = ops;
324 exynos_crtc->ctx = ctx;
Gustavo Padovaneb88e422014-11-26 16:43:27 -0200325 plane = exynos_plane_init(drm_dev, 1 << pipe,
Andrzej Hajda72ed6cc2014-09-19 14:58:53 +0200326 DRM_PLANE_TYPE_PRIMARY);
327 if (IS_ERR(plane)) {
328 ret = PTR_ERR(plane);
329 goto err_plane;
Joonyoung Shimb5d2eb32012-06-27 14:27:04 +0900330 }
331
Gustavo Padovan357193c2014-11-03 18:20:29 -0200332 crtc = &exynos_crtc->base;
Inki Dae1c248b72011-10-04 19:19:01 +0900333
Gustavo Padovane09f2b02014-11-04 18:25:27 -0200334 private->crtc[pipe] = crtc;
Inki Dae1c248b72011-10-04 19:19:01 +0900335
Gustavo Padovaneb88e422014-11-26 16:43:27 -0200336 ret = drm_crtc_init_with_planes(drm_dev, crtc, plane, NULL,
Andrzej Hajda72ed6cc2014-09-19 14:58:53 +0200337 &exynos_crtc_funcs);
338 if (ret < 0)
339 goto err_crtc;
340
Inki Dae1c248b72011-10-04 19:19:01 +0900341 drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs);
342
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900343 exynos_drm_crtc_attach_mode_property(crtc);
344
Gustavo Padovan93bca242015-01-18 18:16:23 +0900345 return exynos_crtc;
Andrzej Hajda72ed6cc2014-09-19 14:58:53 +0200346
347err_crtc:
348 plane->funcs->destroy(plane);
349err_plane:
350 kfree(exynos_crtc);
Gustavo Padovan93bca242015-01-18 18:16:23 +0900351 return ERR_PTR(ret);
Inki Dae1c248b72011-10-04 19:19:01 +0900352}
353
Sean Paul080be03d2014-02-19 21:02:55 +0900354int exynos_drm_crtc_enable_vblank(struct drm_device *dev, int pipe)
Inki Dae1c248b72011-10-04 19:19:01 +0900355{
356 struct exynos_drm_private *private = dev->dev_private;
Inki Daeec05da92011-12-06 11:06:54 +0900357 struct exynos_drm_crtc *exynos_crtc =
Sean Paul080be03d2014-02-19 21:02:55 +0900358 to_exynos_crtc(private->crtc[pipe]);
Inki Dae1c248b72011-10-04 19:19:01 +0900359
Inki Daeec05da92011-12-06 11:06:54 +0900360 if (exynos_crtc->dpms != DRM_MODE_DPMS_ON)
361 return -EPERM;
362
Gustavo Padovan93bca242015-01-18 18:16:23 +0900363 if (exynos_crtc->ops->enable_vblank)
364 exynos_crtc->ops->enable_vblank(exynos_crtc);
Inki Dae1c248b72011-10-04 19:19:01 +0900365
366 return 0;
367}
368
Sean Paul080be03d2014-02-19 21:02:55 +0900369void exynos_drm_crtc_disable_vblank(struct drm_device *dev, int pipe)
Inki Dae1c248b72011-10-04 19:19:01 +0900370{
371 struct exynos_drm_private *private = dev->dev_private;
Inki Daeec05da92011-12-06 11:06:54 +0900372 struct exynos_drm_crtc *exynos_crtc =
Sean Paul080be03d2014-02-19 21:02:55 +0900373 to_exynos_crtc(private->crtc[pipe]);
Inki Dae1c248b72011-10-04 19:19:01 +0900374
Inki Daeec05da92011-12-06 11:06:54 +0900375 if (exynos_crtc->dpms != DRM_MODE_DPMS_ON)
376 return;
377
Gustavo Padovan93bca242015-01-18 18:16:23 +0900378 if (exynos_crtc->ops->disable_vblank)
379 exynos_crtc->ops->disable_vblank(exynos_crtc);
Inki Dae1c248b72011-10-04 19:19:01 +0900380}
Rahul Sharma663d8762013-01-03 05:44:04 -0500381
Sean Paul080be03d2014-02-19 21:02:55 +0900382void exynos_drm_crtc_finish_pageflip(struct drm_device *dev, int pipe)
Rahul Sharma663d8762013-01-03 05:44:04 -0500383{
384 struct exynos_drm_private *dev_priv = dev->dev_private;
385 struct drm_pending_vblank_event *e, *t;
Sean Paul080be03d2014-02-19 21:02:55 +0900386 struct drm_crtc *drm_crtc = dev_priv->crtc[pipe];
Inki Dae20cd2642013-05-21 16:55:58 +0900387 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(drm_crtc);
Rahul Sharma663d8762013-01-03 05:44:04 -0500388 unsigned long flags;
389
Rahul Sharma663d8762013-01-03 05:44:04 -0500390 spin_lock_irqsave(&dev->event_lock, flags);
391
392 list_for_each_entry_safe(e, t, &dev_priv->pageflip_event_list,
393 base.link) {
394 /* if event's pipe isn't same as crtc then ignore it. */
Sean Paul080be03d2014-02-19 21:02:55 +0900395 if (pipe != e->pipe)
Rahul Sharma663d8762013-01-03 05:44:04 -0500396 continue;
397
Rob Clarkc5cca972013-05-22 11:48:40 +0900398 list_del(&e->base.link);
399 drm_send_vblank_event(dev, -1, e);
Sean Paul080be03d2014-02-19 21:02:55 +0900400 drm_vblank_put(dev, pipe);
Inki Dae20cd2642013-05-21 16:55:58 +0900401 atomic_set(&exynos_crtc->pending_flip, 0);
402 wake_up(&exynos_crtc->pending_flip_queue);
Rahul Sharma663d8762013-01-03 05:44:04 -0500403 }
404
405 spin_unlock_irqrestore(&dev->event_lock, flags);
406}
Sean Paul080be03d2014-02-19 21:02:55 +0900407
Sean Paul080be03d2014-02-19 21:02:55 +0900408void exynos_drm_crtc_complete_scanout(struct drm_framebuffer *fb)
409{
Gustavo Padovan93bca242015-01-18 18:16:23 +0900410 struct exynos_drm_crtc *exynos_crtc;
Sean Paul080be03d2014-02-19 21:02:55 +0900411 struct drm_device *dev = fb->dev;
412 struct drm_crtc *crtc;
413
414 /*
415 * make sure that overlay data are updated to real hardware
416 * for all encoders.
417 */
418 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
Gustavo Padovan93bca242015-01-18 18:16:23 +0900419 exynos_crtc = to_exynos_crtc(crtc);
Sean Paul080be03d2014-02-19 21:02:55 +0900420
421 /*
422 * wait for vblank interrupt
423 * - this makes sure that overlay data are updated to
424 * real hardware.
425 */
Gustavo Padovan93bca242015-01-18 18:16:23 +0900426 if (exynos_crtc->ops->wait_for_vblank)
427 exynos_crtc->ops->wait_for_vblank(exynos_crtc);
Sean Paul080be03d2014-02-19 21:02:55 +0900428 }
429}
Inki Daef37cd5e2014-05-09 14:25:20 +0900430
431int exynos_drm_crtc_get_pipe_from_type(struct drm_device *drm_dev,
432 unsigned int out_type)
433{
434 struct drm_crtc *crtc;
435
436 list_for_each_entry(crtc, &drm_dev->mode_config.crtc_list, head) {
437 struct exynos_drm_crtc *exynos_crtc;
438
439 exynos_crtc = to_exynos_crtc(crtc);
Gustavo Padovan5d1741a2014-11-05 19:51:35 -0200440 if (exynos_crtc->type == out_type)
Gustavo Padovan8a326ed2014-11-04 18:44:47 -0200441 return exynos_crtc->pipe;
Inki Daef37cd5e2014-05-09 14:25:20 +0900442 }
443
444 return -EPERM;
445}
YoungJun Cho5595d4d2014-07-17 18:01:19 +0900446
447void exynos_drm_crtc_te_handler(struct drm_crtc *crtc)
448{
Gustavo Padovan93bca242015-01-18 18:16:23 +0900449 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
YoungJun Cho5595d4d2014-07-17 18:01:19 +0900450
Gustavo Padovan93bca242015-01-18 18:16:23 +0900451 if (exynos_crtc->ops->te_handler)
452 exynos_crtc->ops->te_handler(exynos_crtc);
YoungJun Cho5595d4d2014-07-17 18:01:19 +0900453}