3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
5 * Inki Dae <inki.dae@samsung.com>
6 * Joonyoung Shim <jy0922.shim@samsung.com>
7 * Seung-Woo Kim <sw0312.kim@samsung.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
30 #include "drm_crtc_helper.h"
32 #include <linux/kfifo.h>
34 #include "exynos_drm_crtc.h"
35 #include "exynos_drm_drv.h"
36 #include "exynos_drm_fb.h"
37 #include "exynos_drm_encoder.h"
38 #include "exynos_drm_display.h"
39 #include "exynos_drm_gem.h"
40 #include "exynos_trace.h"
41 #include "exynos_drm_plane.h"
43 #define KDS_WAITALL_MAX_TRIES 15
45 struct exynos_drm_flip_desc {
46 struct drm_framebuffer *fb;
47 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
48 struct kds_resource_set *kds;
53 * Exynos specific crtc structure.
55 * @drm_crtc: crtc object.
56 * @current_fb: current fb that is being scanned out
57 * @event: vblank event that is currently queued for flip
58 * @plane: pointer of private plane object for this crtc
59 * @pipe: a crtc index created at load() with a new crtc object creation
60 * and the crtc object would be set to private->crtc array
61 * to get a crtc object corresponding to this pipe from private->crtc
62 * array when irq interrupt occured. the reason of using this pipe is that
63 * drm framework doesn't support multiple irq yet.
64 * we can refer to the crtc to current hardware interrupt occured through
66 * @flip_pending: there is a flip pending that we need to process next vblank
68 struct exynos_drm_crtc {
69 struct drm_crtc drm_crtc;
70 struct drm_pending_vblank_event *event;
71 DECLARE_KFIFO(flip_fifo, struct exynos_drm_flip_desc, 2);
72 struct exynos_drm_flip_desc scanout_desc;
73 struct exynos_drm_display *display;
74 struct drm_plane *plane;
76 atomic_t flip_pending;
79 #define to_exynos_crtc(x) container_of(x, struct exynos_drm_crtc,\
82 void exynos_drm_crtc_apply(struct drm_crtc *crtc,
83 struct exynos_drm_overlay *overlay)
85 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
86 struct exynos_drm_display *display = exynos_crtc->display;
88 if (display->controller_ops && display->controller_ops->mode_set)
89 display->controller_ops->mode_set(display->controller_ctx,
92 display->pipe = exynos_crtc->pipe;
94 if (display->controller_ops && display->controller_ops->win_commit)
95 display->controller_ops->win_commit(display->controller_ctx,
99 void exynos_drm_overlay_update(struct exynos_drm_overlay *overlay,
100 struct drm_framebuffer *fb,
101 struct drm_display_mode *mode,
102 struct exynos_drm_crtc_pos *pos)
104 struct exynos_drm_gem_buf *buffer;
105 unsigned int actual_w;
106 unsigned int actual_h;
107 struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb);
108 int nr = exynos_drm_format_num_buffers(fb->pixel_format);
111 for (i = 0; i < nr; i++) {
112 buffer = exynos_drm_fb_buffer(exynos_fb, i);
114 overlay->dma_addr[i] = buffer->dma_addr;
116 DRM_DEBUG_KMS("buffer: %d, dma_addr = 0x%lx\n",
117 i, (unsigned long)overlay->dma_addr[i]);
120 actual_w = min((mode->hdisplay - pos->crtc_x), pos->crtc_w);
121 actual_h = min((mode->vdisplay - pos->crtc_y), pos->crtc_h);
123 /* set drm framebuffer data. */
124 overlay->fb_x = pos->fb_x;
125 overlay->fb_y = pos->fb_y;
126 overlay->fb_width = min(pos->fb_w, actual_w);
127 overlay->fb_height = min(pos->fb_h, actual_h);
128 overlay->fb_pitch = fb->pitches[0];
129 overlay->bpp = fb->bits_per_pixel;
130 overlay->pixel_format = fb->pixel_format;
132 /* set overlay range to be displayed. */
133 overlay->crtc_x = pos->crtc_x;
134 overlay->crtc_y = pos->crtc_y;
135 overlay->crtc_width = actual_w;
136 overlay->crtc_height = actual_h;
137 overlay->crtc_htotal = mode->crtc_htotal;
138 overlay->crtc_hsync_len = mode->hsync_end - mode->hsync_start;
139 overlay->crtc_vtotal = mode->crtc_vtotal;
140 overlay->crtc_vsync_len = mode->vsync_end - mode->vsync_start;
142 /* set drm mode data. */
143 overlay->mode_width = mode->hdisplay;
144 overlay->mode_height = mode->vdisplay;
145 overlay->refresh = mode->vrefresh;
146 overlay->scan_flag = mode->flags;
148 DRM_DEBUG_KMS("overlay : offset_x/y(%d,%d), width/height(%d,%d)",
149 overlay->crtc_x, overlay->crtc_y,
150 overlay->crtc_width, overlay->crtc_height);
153 void exynos_drm_overlay_disable(struct drm_crtc *crtc, int zpos)
155 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
156 struct exynos_drm_display *display = exynos_crtc->display;
158 if (display->controller_ops && display->controller_ops->win_disable)
159 display->controller_ops->win_disable(display->controller_ctx,
163 static void exynos_drm_crtc_update(struct drm_crtc *crtc,
164 struct drm_framebuffer *fb)
166 struct exynos_drm_crtc *exynos_crtc;
167 struct exynos_drm_overlay *overlay;
168 struct exynos_drm_crtc_pos pos;
169 struct drm_display_mode *mode = &crtc->mode;
171 exynos_crtc = to_exynos_crtc(crtc);
172 overlay = get_exynos_drm_overlay(exynos_crtc->plane);
174 memset(&pos, 0, sizeof(struct exynos_drm_crtc_pos));
176 /* it means the offset of framebuffer to be displayed. */
179 pos.fb_w = fb->width;
180 pos.fb_h = fb->height;
182 /* OSD position to be displayed. */
185 pos.crtc_w = fb->width - crtc->x;
186 pos.crtc_h = fb->height - crtc->y;
188 exynos_drm_overlay_update(overlay, fb, mode, &pos);
191 static void exynos_drm_crtc_flip_complete(struct drm_device *dev,
192 struct drm_pending_vblank_event *e)
197 do_gettimeofday(&now);
198 e->event.sequence = 0;
199 e->event.tv_sec = now.tv_sec;
200 e->event.tv_usec = now.tv_usec;
201 spin_lock_irqsave(&dev->event_lock, flags);
202 list_add_tail(&e->base.link, &e->base.file_priv->event_list);
203 spin_unlock_irqrestore(&dev->event_lock, flags);
204 wake_up_interruptible(&e->base.file_priv->event_wait);
205 trace_exynos_fake_flip_complete(e->pipe);
208 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
209 static void exynos_drm_crtc_wait_and_release_kds(
210 struct exynos_drm_flip_desc *desc)
212 struct exynos_drm_fb *exynos_fb;
213 struct exynos_drm_gem_obj *gem_ob;
215 unsigned long shared = 0UL;
216 struct kds_resource *resource_list;
217 struct kds_resource_set *resource_set;
226 kds_resource_set_release(&desc->kds);
228 exynos_fb = to_exynos_fb(desc->fb);
229 gem_ob = (struct exynos_drm_gem_obj *)exynos_fb->exynos_gem_obj[0];
230 buf = gem_ob->base.export_dma_buf;
234 if (unlikely(!exynos_fb->dma_buf)) {
236 exynos_fb->dma_buf = buf;
238 BUG_ON(exynos_fb->dma_buf != buf);
240 /* Synchronously wait for the frame to render */
241 resource_list = get_dma_buf_kds_resource(buf);
243 for (i = 0; i < KDS_WAITALL_MAX_TRIES; i++) {
244 resource_set = kds_waitall(1, &shared, &resource_list,
245 msecs_to_jiffies(1000));
246 if (PTR_ERR(resource_set) != -ERESTARTSYS)
249 if (IS_ERR(resource_set)) {
250 DRM_ERROR("kds_waitall failed with ret=%ld\n",
251 PTR_ERR(resource_set));
253 } else if (!resource_set) {
254 DRM_ERROR("kds_waitall timed out\n");
258 /* Clean up the remaining resource so we're not holding onto anything */
259 kds_resource_set_release(&resource_set);
262 static void exynos_drm_crtc_release_flips(struct drm_crtc *crtc)
264 struct drm_device *drm_dev = crtc->dev;
265 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
266 struct exynos_drm_flip_desc *cur_desc = &exynos_crtc->scanout_desc;
267 struct exynos_drm_flip_desc next_desc;
270 DRM_DEBUG_KMS("[CRTC:%d]\n", DRM_BASE_ID(crtc));
273 kds_resource_set_release(&cur_desc->kds);
275 /* If there aren't any pending frames, be merry and exit */
276 if (!kfifo_len(&exynos_crtc->flip_fifo))
279 /* Loop through the fifo and drop all frames except the last */
280 while (kfifo_len(&exynos_crtc->flip_fifo) > 1) {
281 ret = kfifo_get(&exynos_crtc->flip_fifo, &next_desc);
285 exynos_drm_fb_put(to_exynos_fb(next_desc.fb));
287 kds_resource_set_release(&next_desc.kds);
290 /* Now we'll promote the pending frame to front */
291 ret = kfifo_get(&exynos_crtc->flip_fifo, &next_desc);
294 atomic_set(&exynos_crtc->flip_pending, 0);
296 exynos_drm_crtc_wait_and_release_kds(&next_desc);
298 to_exynos_fb(next_desc.fb)->rendered = true;
299 exynos_drm_crtc_update(crtc, next_desc.fb);
300 exynos_drm_crtc_apply(crtc, get_exynos_drm_overlay(exynos_crtc->plane));
301 to_exynos_fb(next_desc.fb)->prepared = true;
303 if (exynos_crtc->event) {
304 exynos_drm_crtc_flip_complete(drm_dev, exynos_crtc->event);
305 exynos_crtc->event = NULL;
308 *cur_desc = next_desc;
312 static void exynos_drm_crtc_dpms(struct drm_crtc *crtc, int mode)
314 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
315 struct exynos_drm_display *display = exynos_crtc->display;
317 DRM_DEBUG_KMS("[CRTC:%d] [DPMS:%s]\n", DRM_BASE_ID(crtc),
318 drm_get_dpms_name(mode));
320 if (display->controller_ops && display->controller_ops->dpms)
321 display->controller_ops->dpms(display->controller_ctx, mode);
323 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
324 if (mode != DRM_MODE_DPMS_ON)
325 exynos_drm_crtc_release_flips(crtc);
329 static void exynos_drm_crtc_prepare(struct drm_crtc *crtc)
331 DRM_DEBUG_KMS("[CRTC:%d]\n", DRM_BASE_ID(crtc));
333 /* drm framework doesn't check NULL. */
336 static int exynos_drm_crtc_page_flip(struct drm_crtc *crtc,
337 struct drm_framebuffer *fb,
338 struct drm_pending_vblank_event *event);
340 static void exynos_drm_crtc_commit(struct drm_crtc *crtc)
342 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
343 struct exynos_drm_display *display = exynos_crtc->display;
346 DRM_DEBUG_KMS("[CRTC:%d]\n", DRM_BASE_ID(crtc));
349 * when set_crtc is requested from user or at booting time,
350 * crtc->commit would be called without dpms call so crtc->dpms
351 * should be called with DRM_MODE_DPMS_ON for the controller power
354 exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
356 ret = exynos_drm_crtc_page_flip(crtc, crtc->fb, NULL);
358 DRM_ERROR("page_flip failed\n");
360 if (display->controller_ops && display->controller_ops->commit)
361 display->controller_ops->commit(display->controller_ctx);
365 exynos_drm_crtc_mode_fixup(struct drm_crtc *crtc,
366 struct drm_display_mode *mode,
367 struct drm_display_mode *adjusted_mode)
369 DRM_DEBUG_KMS("[CRTC:%d] [MODE:%d:%s]\n", DRM_BASE_ID(crtc),
370 DRM_BASE_ID(mode), mode->name);
372 /* drm framework doesn't check NULL */
377 exynos_drm_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode,
378 struct drm_display_mode *adjusted_mode, int x, int y,
379 struct drm_framebuffer *old_fb)
381 struct exynos_drm_private *dev_priv = crtc->dev->dev_private;
382 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
383 struct exynos_drm_display *display = exynos_crtc->display;
384 struct drm_framebuffer *fb = crtc->fb;
387 DRM_DEBUG_KMS("[CRTC:%d] [MODE:%d:%s] @ (%d, %d) [OLD_FB:%d]\n",
388 DRM_BASE_ID(crtc), DRM_BASE_ID(mode), mode->name, x, y,
389 DRM_BASE_ID(old_fb));
395 * copy the mode data adjusted by mode_fixup() into crtc->mode
396 * so that hardware can be seet to proper mode.
398 memcpy(&crtc->mode, adjusted_mode, sizeof(*adjusted_mode));
400 /* We should never timeout here. */
401 ret = wait_event_timeout(dev_priv->wait_vsync_queue,
402 kfifo_is_empty(&exynos_crtc->flip_fifo),
405 DRM_ERROR("Timed out waiting for flips to complete\n");
407 exynos_drm_crtc_update(crtc, fb);
409 if (display->controller_ops && display->controller_ops->mode_set)
410 display->controller_ops->mode_set(display->controller_ctx,
411 get_exynos_drm_overlay(exynos_crtc->plane));
416 static int exynos_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
417 struct drm_framebuffer *old_fb)
419 struct exynos_drm_private *dev_priv = crtc->dev->dev_private;
420 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
421 struct drm_framebuffer *fb = crtc->fb;
424 DRM_DEBUG_KMS("[CRTC:%d] @ (%d, %d) [OLD_FB:%d]\n",
425 DRM_BASE_ID(crtc), x, y, DRM_BASE_ID(old_fb));
430 /* We should never timeout here. */
431 ret = wait_event_timeout(dev_priv->wait_vsync_queue,
432 kfifo_is_empty(&exynos_crtc->flip_fifo),
435 DRM_ERROR("Timed out waiting for flips to complete\n");
437 ret = exynos_drm_crtc_page_flip(crtc, fb, NULL);
439 DRM_ERROR("page_flip failed\n");
444 static void exynos_drm_crtc_load_lut(struct drm_crtc *crtc)
446 DRM_DEBUG_KMS("[CRTC:%d]\n", DRM_BASE_ID(crtc));
447 /* drm framework doesn't check NULL */
450 static struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = {
451 .dpms = exynos_drm_crtc_dpms,
452 .prepare = exynos_drm_crtc_prepare,
453 .commit = exynos_drm_crtc_commit,
454 .mode_fixup = exynos_drm_crtc_mode_fixup,
455 .mode_set = exynos_drm_crtc_mode_set,
456 .mode_set_base = exynos_drm_crtc_mode_set_base,
457 .load_lut = exynos_drm_crtc_load_lut,
460 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
461 void exynos_drm_kds_callback(void *callback_parameter, void *callback_extra_parameter)
463 struct drm_framebuffer *fb = callback_parameter;
464 struct drm_crtc *crtc = callback_extra_parameter;
465 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
468 * Under rare circumstances (modeset followed by flip) it is possible
469 * to have two fbs ready in time for the same vblank. We don't want to
470 * drop the latter fb because it is most recent. We can't drop the
471 * former either because we've already applied it and the mixer does
472 * not allow applying more than one frame on a vblank. So instead of
473 * dropping a frame, we store the latter frame in the extra slot and
474 * apply it on the next vblank.
477 to_exynos_fb(fb)->rendered = true;
479 if (!atomic_cmpxchg(&exynos_crtc->flip_pending, 0, 1)) {
480 struct exynos_drm_overlay *overlay;
482 overlay = get_exynos_drm_overlay(exynos_crtc->plane);
483 exynos_drm_crtc_update(crtc, fb);
484 exynos_drm_crtc_apply(crtc, overlay);
485 to_exynos_fb(fb)->prepared = true;
490 static int exynos_drm_crtc_page_flip(struct drm_crtc *crtc,
491 struct drm_framebuffer *fb,
492 struct drm_pending_vblank_event *event)
494 struct drm_device *dev = crtc->dev;
495 struct exynos_drm_private *dev_priv = dev->dev_private;
496 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
497 struct exynos_drm_flip_desc flip_desc;
498 bool send_event = false;
500 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
501 struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb);
502 struct exynos_drm_gem_obj *gem_ob = (struct exynos_drm_gem_obj *)exynos_fb->exynos_gem_obj[0];
504 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d]\n", DRM_BASE_ID(crtc),
508 * the pipe from user always is 0 so we can set pipe number
509 * of current owner to event.
512 event->pipe = exynos_crtc->pipe;
514 ret = drm_vblank_get(dev, exynos_crtc->pipe);
516 DRM_ERROR("Unable to get vblank\n");
520 if (kfifo_is_full(&exynos_crtc->flip_fifo)) {
521 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
523 goto fail_queue_full;
526 /* Send flip event if no flips pending. */
527 BUG_ON(exynos_crtc->event);
528 if (kfifo_is_empty(&exynos_crtc->flip_fifo))
531 exynos_drm_fb_get(exynos_fb);
533 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
535 exynos_fb->rendered = false;
536 exynos_fb->prepared = false;
537 if (gem_ob->base.export_dma_buf) {
538 struct dma_buf *buf = gem_ob->base.export_dma_buf;
539 unsigned long shared = 0UL;
540 struct kds_resource *res_list = get_dma_buf_kds_resource(buf);
543 * If we don't already have a reference to the dma_buf,
544 * grab one now. We'll release it in exynos_drm_fb_destory().
546 if (!exynos_fb->dma_buf) {
548 exynos_fb->dma_buf = buf;
550 BUG_ON(exynos_fb->dma_buf != buf);
552 /* Waiting for the KDS resource*/
553 ret = kds_async_waitall(&flip_desc.kds, KDS_FLAG_LOCKED_WAIT,
554 &dev_priv->kds_cb, fb, crtc, 1,
557 DRM_ERROR("kds_async_waitall failed: %d\n", ret);
562 * For normal page-flip (i.e. non-modeset) we should
563 * never be flipping a non-kds buffer.
566 DRM_ERROR("flipping a non-kds buffer\n");
567 flip_desc.kds = NULL;
568 exynos_drm_kds_callback(fb, crtc);
574 exynos_drm_crtc_flip_complete(dev, event);
576 exynos_crtc->event = event;
578 kfifo_put(&exynos_crtc->flip_fifo, &flip_desc);
581 trace_exynos_flip_request(exynos_crtc->pipe);
586 exynos_drm_fb_put(exynos_fb);
588 drm_vblank_put(dev, exynos_crtc->pipe);
592 void exynos_drm_crtc_finish_pageflip(struct drm_device *drm_dev, int crtc_idx)
594 struct exynos_drm_private *dev_priv = drm_dev->dev_private;
595 struct drm_crtc *crtc = dev_priv->crtc[crtc_idx];
596 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
597 struct exynos_drm_flip_desc *cur_descp = &exynos_crtc->scanout_desc;
598 struct exynos_drm_flip_desc next_desc;
600 /* set wait vsync wake up queue. */
601 DRM_WAKEUP(&dev_priv->wait_vsync_queue);
603 if (!atomic_read(&exynos_crtc->flip_pending))
605 if (!kfifo_peek(&exynos_crtc->flip_fifo, &next_desc))
607 if (!to_exynos_fb(next_desc.fb)->prepared)
609 if (!atomic_cmpxchg(&exynos_crtc->flip_pending, 1, 0))
612 trace_exynos_flip_complete(crtc_idx);
615 exynos_drm_fb_put(to_exynos_fb(cur_descp->fb));
617 kds_resource_set_release(&cur_descp->kds);
618 *cur_descp = next_desc;
619 kfifo_skip(&exynos_crtc->flip_fifo);
621 if (exynos_crtc->event) {
622 exynos_drm_crtc_flip_complete(drm_dev, exynos_crtc->event);
623 exynos_crtc->event = NULL;
627 * exynos_drm_kds_callback can't update the shadow registers if there
628 * is a pending flip ahead. So we do the update here.
630 if (kfifo_peek(&exynos_crtc->flip_fifo, &next_desc)) {
631 if (unlikely(to_exynos_fb(next_desc.fb)->rendered) &&
632 !atomic_cmpxchg(&exynos_crtc->flip_pending, 0, 1)) {
633 struct exynos_drm_overlay *overlay;
635 overlay = get_exynos_drm_overlay(exynos_crtc->plane);
636 exynos_drm_crtc_update(crtc, next_desc.fb);
637 exynos_drm_crtc_apply(crtc, overlay);
638 to_exynos_fb(next_desc.fb)->prepared = true;
642 drm_vblank_put(drm_dev, crtc_idx);
645 static void exynos_drm_crtc_destroy(struct drm_crtc *crtc)
647 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
648 struct exynos_drm_private *private = crtc->dev->dev_private;
650 DRM_DEBUG_KMS("[CRTC:%d]\n", DRM_BASE_ID(crtc));
652 private->crtc[exynos_crtc->pipe] = NULL;
654 drm_crtc_cleanup(crtc);
658 static struct drm_crtc_funcs exynos_crtc_funcs = {
659 .set_config = drm_crtc_helper_set_config,
660 .page_flip = exynos_drm_crtc_page_flip,
661 .destroy = exynos_drm_crtc_destroy,
664 int exynos_drm_crtc_create(struct drm_device *dev, unsigned int nr,
665 struct exynos_drm_display *display)
667 struct exynos_drm_crtc *exynos_crtc;
668 struct exynos_drm_private *private = dev->dev_private;
669 struct drm_crtc *crtc;
671 DRM_DEBUG_KMS("[DEV:%s] pipe: %d\n", dev->devname, nr);
673 exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL);
675 DRM_ERROR("failed to allocate exynos crtc\n");
679 INIT_KFIFO(exynos_crtc->flip_fifo);
680 exynos_crtc->pipe = nr;
681 exynos_crtc->display = display;
683 exynos_crtc->plane = exynos_plane_init(dev, 1 << nr, true);
684 if (!exynos_crtc->plane) {
689 crtc = &exynos_crtc->drm_crtc;
691 private->crtc[nr] = crtc;
693 drm_crtc_init(dev, crtc, &exynos_crtc_funcs);
694 drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs);
696 DRM_DEBUG_KMS("Created [CRTC:%d]\n", DRM_BASE_ID(crtc));
701 int exynos_drm_crtc_enable_vblank(struct drm_device *dev, int crtc)
703 struct exynos_drm_private *private = dev->dev_private;
704 struct exynos_drm_crtc *exynos_crtc =
705 to_exynos_crtc(private->crtc[crtc]);
706 struct exynos_drm_display *display = exynos_crtc->display;
709 DRM_DEBUG_KMS("[DEV:%s] crtc: %d\n", dev->devname, crtc);
711 if (display->pipe == -1)
712 display->pipe = crtc;
714 if (display->controller_ops && display->controller_ops->enable_vblank)
715 ret = display->controller_ops->enable_vblank(
716 display->controller_ctx, crtc);
720 void exynos_drm_crtc_disable_vblank(struct drm_device *dev, int crtc)
722 struct exynos_drm_private *private = dev->dev_private;
723 struct exynos_drm_crtc *exynos_crtc =
724 to_exynos_crtc(private->crtc[crtc]);
725 struct exynos_drm_display *display = exynos_crtc->display;
727 DRM_DEBUG_KMS("[DEV:%s] pipe: %d\n", dev->devname, crtc);
730 * TODO(seanpaul): This seems like a hack. I don't think it's actually
731 * needed for 2 reasons:
732 * (1) disable_vblank implies vblank has been enabled. If
733 * enable_vblank hasn't already been called, that's a bug.
734 * (2) Even if (1) isn't true, this function should just disable an
735 * interrupt, and shouldn't affect pipe.
737 if (display->pipe == -1)
738 display->pipe = crtc;
740 if (display->controller_ops && display->controller_ops->disable_vblank)
741 display->controller_ops->disable_vblank(
742 display->controller_ctx);