11c248b7dSInki Dae /* exynos_drm_crtc.c 21c248b7dSInki Dae * 31c248b7dSInki Dae * Copyright (c) 2011 Samsung Electronics Co., Ltd. 41c248b7dSInki Dae * Authors: 51c248b7dSInki Dae * Inki Dae <inki.dae@samsung.com> 61c248b7dSInki Dae * Joonyoung Shim <jy0922.shim@samsung.com> 71c248b7dSInki Dae * Seung-Woo Kim <sw0312.kim@samsung.com> 81c248b7dSInki Dae * 9d81aecb5SInki Dae * This program is free software; you can redistribute it and/or modify it 10d81aecb5SInki Dae * under the terms of the GNU General Public License as published by the 11d81aecb5SInki Dae * Free Software Foundation; either version 2 of the License, or (at your 12d81aecb5SInki Dae * option) any later version. 131c248b7dSInki Dae */ 141c248b7dSInki Dae 15760285e7SDavid Howells #include <drm/drmP.h> 16760285e7SDavid Howells #include <drm/drm_crtc_helper.h> 171c248b7dSInki Dae 18e30655d0SMark Brown #include "exynos_drm_crtc.h" 191c248b7dSInki Dae #include "exynos_drm_drv.h" 201c248b7dSInki Dae #include "exynos_drm_encoder.h" 21b5d2eb3bSJoonyoung Shim #include "exynos_drm_plane.h" 221c248b7dSInki Dae 231c248b7dSInki Dae #define to_exynos_crtc(x) container_of(x, struct exynos_drm_crtc,\ 241c248b7dSInki Dae drm_crtc) 251c248b7dSInki Dae 263b8d1cf8SJoonyoung Shim enum exynos_crtc_mode { 273b8d1cf8SJoonyoung Shim CRTC_MODE_NORMAL, /* normal mode */ 283b8d1cf8SJoonyoung Shim CRTC_MODE_BLANK, /* The private plane of crtc is blank */ 293b8d1cf8SJoonyoung Shim }; 303b8d1cf8SJoonyoung Shim 311c248b7dSInki Dae /* 321c248b7dSInki Dae * Exynos specific crtc structure. 331c248b7dSInki Dae * 341c248b7dSInki Dae * @drm_crtc: crtc object. 35b5d2eb3bSJoonyoung Shim * @drm_plane: pointer of private plane object for this crtc 361c248b7dSInki Dae * @pipe: a crtc index created at load() with a new crtc object creation 371c248b7dSInki Dae * and the crtc object would be set to private->crtc array 381c248b7dSInki Dae * to get a crtc object corresponding to this pipe from private->crtc 391c248b7dSInki Dae * array when irq interrupt occured. the reason of using this pipe is that 401c248b7dSInki Dae * drm framework doesn't support multiple irq yet. 411c248b7dSInki Dae * we can refer to the crtc to current hardware interrupt occured through 421c248b7dSInki Dae * this pipe value. 43ec05da95SInki Dae * @dpms: store the crtc dpms value 443b8d1cf8SJoonyoung Shim * @mode: store the crtc mode value 451c248b7dSInki Dae */ 461c248b7dSInki Dae struct exynos_drm_crtc { 471c248b7dSInki Dae struct drm_crtc drm_crtc; 48b5d2eb3bSJoonyoung Shim struct drm_plane *plane; 491c248b7dSInki Dae unsigned int pipe; 50ec05da95SInki Dae unsigned int dpms; 513b8d1cf8SJoonyoung Shim enum exynos_crtc_mode mode; 5220cd2640SInki Dae wait_queue_head_t pending_flip_queue; 5320cd2640SInki Dae atomic_t pending_flip; 541c248b7dSInki Dae }; 551c248b7dSInki Dae 561c248b7dSInki Dae static void exynos_drm_crtc_dpms(struct drm_crtc *crtc, int mode) 571c248b7dSInki Dae { 58d2716c89SJoonyoung Shim struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); 591c248b7dSInki Dae 60d2716c89SJoonyoung Shim DRM_DEBUG_KMS("crtc[%d] mode[%d]\n", crtc->base.id, mode); 61d2716c89SJoonyoung Shim 62ec05da95SInki Dae if (exynos_crtc->dpms == mode) { 63ec05da95SInki Dae DRM_DEBUG_KMS("desired dpms mode is same as previous one.\n"); 64ec05da95SInki Dae return; 65ec05da95SInki Dae } 66ec05da95SInki Dae 6720cd2640SInki Dae if (mode > DRM_MODE_DPMS_ON) { 6820cd2640SInki Dae /* wait for the completion of page flip. */ 6920cd2640SInki Dae wait_event(exynos_crtc->pending_flip_queue, 7020cd2640SInki Dae atomic_read(&exynos_crtc->pending_flip) == 0); 7120cd2640SInki Dae drm_vblank_off(crtc->dev, exynos_crtc->pipe); 7220cd2640SInki Dae } 7320cd2640SInki Dae 74cf5188acSJoonyoung Shim exynos_drm_fn_encoder(crtc, &mode, exynos_drm_encoder_crtc_dpms); 75ec05da95SInki Dae exynos_crtc->dpms = mode; 761c248b7dSInki Dae } 771c248b7dSInki Dae 781c248b7dSInki Dae static void exynos_drm_crtc_prepare(struct drm_crtc *crtc) 791c248b7dSInki Dae { 801c248b7dSInki Dae /* drm framework doesn't check NULL. */ 811c248b7dSInki Dae } 821c248b7dSInki Dae 831c248b7dSInki Dae static void exynos_drm_crtc_commit(struct drm_crtc *crtc) 841c248b7dSInki Dae { 85d2716c89SJoonyoung Shim struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); 86d2716c89SJoonyoung Shim 8750caf25cSInki Dae exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_ON); 884070d212SJoonyoung Shim exynos_plane_commit(exynos_crtc->plane); 89cf5188acSJoonyoung Shim exynos_plane_dpms(exynos_crtc->plane, DRM_MODE_DPMS_ON); 901c248b7dSInki Dae } 911c248b7dSInki Dae 921c248b7dSInki Dae static bool 931c248b7dSInki Dae exynos_drm_crtc_mode_fixup(struct drm_crtc *crtc, 94e811f5aeSLaurent Pinchart const struct drm_display_mode *mode, 951c248b7dSInki Dae struct drm_display_mode *adjusted_mode) 961c248b7dSInki Dae { 971c248b7dSInki Dae /* drm framework doesn't check NULL */ 981c248b7dSInki Dae return true; 991c248b7dSInki Dae } 1001c248b7dSInki Dae 1011c248b7dSInki Dae static int 1021c248b7dSInki Dae exynos_drm_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode, 1031c248b7dSInki Dae struct drm_display_mode *adjusted_mode, int x, int y, 1041c248b7dSInki Dae struct drm_framebuffer *old_fb) 1051c248b7dSInki Dae { 106aeb29224SJoonyoung Shim struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); 1074070d212SJoonyoung Shim struct drm_plane *plane = exynos_crtc->plane; 1084070d212SJoonyoung Shim unsigned int crtc_w; 1094070d212SJoonyoung Shim unsigned int crtc_h; 110d249ce02SJoonyoung Shim int pipe = exynos_crtc->pipe; 111aeb29224SJoonyoung Shim int ret; 112aeb29224SJoonyoung Shim 1131de425b0SInki Dae /* 1141de425b0SInki Dae * copy the mode data adjusted by mode_fixup() into crtc->mode 1151de425b0SInki Dae * so that hardware can be seet to proper mode. 1161de425b0SInki Dae */ 1171de425b0SInki Dae memcpy(&crtc->mode, adjusted_mode, sizeof(*adjusted_mode)); 1181c248b7dSInki Dae 1194070d212SJoonyoung Shim crtc_w = crtc->fb->width - x; 1204070d212SJoonyoung Shim crtc_h = crtc->fb->height - y; 1214070d212SJoonyoung Shim 1224070d212SJoonyoung Shim ret = exynos_plane_mode_set(plane, crtc, crtc->fb, 0, 0, crtc_w, crtc_h, 1234070d212SJoonyoung Shim x, y, crtc_w, crtc_h); 124aeb29224SJoonyoung Shim if (ret) 125aeb29224SJoonyoung Shim return ret; 126aeb29224SJoonyoung Shim 1274070d212SJoonyoung Shim plane->crtc = crtc; 1284070d212SJoonyoung Shim plane->fb = crtc->fb; 1294070d212SJoonyoung Shim 130d249ce02SJoonyoung Shim exynos_drm_fn_encoder(crtc, &pipe, exynos_drm_encoder_crtc_pipe); 131aeb29224SJoonyoung Shim 132aeb29224SJoonyoung Shim return 0; 1331c248b7dSInki Dae } 1341c248b7dSInki Dae 1357fd65df1SInki Dae static int exynos_drm_crtc_mode_set_commit(struct drm_crtc *crtc, int x, int y, 1361c248b7dSInki Dae struct drm_framebuffer *old_fb) 1371c248b7dSInki Dae { 1384070d212SJoonyoung Shim struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); 1394070d212SJoonyoung Shim struct drm_plane *plane = exynos_crtc->plane; 1404070d212SJoonyoung Shim unsigned int crtc_w; 1414070d212SJoonyoung Shim unsigned int crtc_h; 1421c248b7dSInki Dae int ret; 1431c248b7dSInki Dae 14432aeab17SInki Dae /* when framebuffer changing is requested, crtc's dpms should be on */ 14532aeab17SInki Dae if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) { 14632aeab17SInki Dae DRM_ERROR("failed framebuffer changing request.\n"); 14732aeab17SInki Dae return -EPERM; 14832aeab17SInki Dae } 14932aeab17SInki Dae 1504070d212SJoonyoung Shim crtc_w = crtc->fb->width - x; 1514070d212SJoonyoung Shim crtc_h = crtc->fb->height - y; 1524070d212SJoonyoung Shim 1534070d212SJoonyoung Shim ret = exynos_plane_mode_set(plane, crtc, crtc->fb, 0, 0, crtc_w, crtc_h, 1544070d212SJoonyoung Shim x, y, crtc_w, crtc_h); 1551c248b7dSInki Dae if (ret) 1561c248b7dSInki Dae return ret; 1571c248b7dSInki Dae 158bebab8ffSJoonyoung Shim exynos_drm_crtc_commit(crtc); 1591c248b7dSInki Dae 1604070d212SJoonyoung Shim return 0; 1611c248b7dSInki Dae } 1621c248b7dSInki Dae 1637fd65df1SInki Dae static int exynos_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, 1647fd65df1SInki Dae struct drm_framebuffer *old_fb) 1657fd65df1SInki Dae { 1667fd65df1SInki Dae return exynos_drm_crtc_mode_set_commit(crtc, x, y, old_fb); 1677fd65df1SInki Dae } 1687fd65df1SInki Dae 169a365d9ebSJoonyoung Shim static void exynos_drm_crtc_disable(struct drm_crtc *crtc) 170a365d9ebSJoonyoung Shim { 171a365d9ebSJoonyoung Shim struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); 172a365d9ebSJoonyoung Shim 173a365d9ebSJoonyoung Shim exynos_plane_dpms(exynos_crtc->plane, DRM_MODE_DPMS_OFF); 174a365d9ebSJoonyoung Shim exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); 175a365d9ebSJoonyoung Shim } 176a365d9ebSJoonyoung Shim 1771c248b7dSInki Dae static struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = { 1781c248b7dSInki Dae .dpms = exynos_drm_crtc_dpms, 1791c248b7dSInki Dae .prepare = exynos_drm_crtc_prepare, 1801c248b7dSInki Dae .commit = exynos_drm_crtc_commit, 1811c248b7dSInki Dae .mode_fixup = exynos_drm_crtc_mode_fixup, 1821c248b7dSInki Dae .mode_set = exynos_drm_crtc_mode_set, 1831c248b7dSInki Dae .mode_set_base = exynos_drm_crtc_mode_set_base, 184a365d9ebSJoonyoung Shim .disable = exynos_drm_crtc_disable, 1851c248b7dSInki Dae }; 1861c248b7dSInki Dae 1871c248b7dSInki Dae static int exynos_drm_crtc_page_flip(struct drm_crtc *crtc, 1881c248b7dSInki Dae struct drm_framebuffer *fb, 189ed8d1975SKeith Packard struct drm_pending_vblank_event *event, 190ed8d1975SKeith Packard uint32_t page_flip_flags) 1911c248b7dSInki Dae { 1921c248b7dSInki Dae struct drm_device *dev = crtc->dev; 1931c248b7dSInki Dae struct exynos_drm_private *dev_priv = dev->dev_private; 1941c248b7dSInki Dae struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); 1951c248b7dSInki Dae struct drm_framebuffer *old_fb = crtc->fb; 1961c248b7dSInki Dae int ret = -EINVAL; 1971c248b7dSInki Dae 198ef6223dcSInki Dae /* when the page flip is requested, crtc's dpms should be on */ 199ef6223dcSInki Dae if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) { 200ef6223dcSInki Dae DRM_ERROR("failed page flip request.\n"); 201ef6223dcSInki Dae return -EINVAL; 202ef6223dcSInki Dae } 203ef6223dcSInki Dae 2041c248b7dSInki Dae mutex_lock(&dev->struct_mutex); 2051c248b7dSInki Dae 206ccf4d883SInki Dae if (event) { 207ccf4d883SInki Dae /* 208ccf4d883SInki Dae * the pipe from user always is 0 so we can set pipe number 209ccf4d883SInki Dae * of current owner to event. 210ccf4d883SInki Dae */ 211ccf4d883SInki Dae event->pipe = exynos_crtc->pipe; 212ccf4d883SInki Dae 2131c248b7dSInki Dae ret = drm_vblank_get(dev, exynos_crtc->pipe); 2141c248b7dSInki Dae if (ret) { 2151c248b7dSInki Dae DRM_DEBUG("failed to acquire vblank counter\n"); 216ccf4d883SInki Dae 2171c248b7dSInki Dae goto out; 2181c248b7dSInki Dae } 2191c248b7dSInki Dae 22085473328SImre Deak spin_lock_irq(&dev->event_lock); 221c5614ae3SInki Dae list_add_tail(&event->base.link, 222c5614ae3SInki Dae &dev_priv->pageflip_event_list); 22320cd2640SInki Dae atomic_set(&exynos_crtc->pending_flip, 1); 22485473328SImre Deak spin_unlock_irq(&dev->event_lock); 225c5614ae3SInki Dae 2261c248b7dSInki Dae crtc->fb = fb; 2277fd65df1SInki Dae ret = exynos_drm_crtc_mode_set_commit(crtc, crtc->x, crtc->y, 2284070d212SJoonyoung Shim NULL); 2291c248b7dSInki Dae if (ret) { 2301c248b7dSInki Dae crtc->fb = old_fb; 23185473328SImre Deak 23285473328SImre Deak spin_lock_irq(&dev->event_lock); 2331c248b7dSInki Dae drm_vblank_put(dev, exynos_crtc->pipe); 234ccf4d883SInki Dae list_del(&event->base.link); 23585473328SImre Deak spin_unlock_irq(&dev->event_lock); 2361c248b7dSInki Dae 2371c248b7dSInki Dae goto out; 2381c248b7dSInki Dae } 2391c248b7dSInki Dae } 2401c248b7dSInki Dae out: 2411c248b7dSInki Dae mutex_unlock(&dev->struct_mutex); 2421c248b7dSInki Dae return ret; 2431c248b7dSInki Dae } 2441c248b7dSInki Dae 2451c248b7dSInki Dae static void exynos_drm_crtc_destroy(struct drm_crtc *crtc) 2461c248b7dSInki Dae { 2471c248b7dSInki Dae struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); 2481c248b7dSInki Dae struct exynos_drm_private *private = crtc->dev->dev_private; 2491c248b7dSInki Dae 2501c248b7dSInki Dae private->crtc[exynos_crtc->pipe] = NULL; 2511c248b7dSInki Dae 2521c248b7dSInki Dae drm_crtc_cleanup(crtc); 2531c248b7dSInki Dae kfree(exynos_crtc); 2541c248b7dSInki Dae } 2551c248b7dSInki Dae 2563b8d1cf8SJoonyoung Shim static int exynos_drm_crtc_set_property(struct drm_crtc *crtc, 2573b8d1cf8SJoonyoung Shim struct drm_property *property, 2583b8d1cf8SJoonyoung Shim uint64_t val) 2593b8d1cf8SJoonyoung Shim { 2603b8d1cf8SJoonyoung Shim struct drm_device *dev = crtc->dev; 2613b8d1cf8SJoonyoung Shim struct exynos_drm_private *dev_priv = dev->dev_private; 2623b8d1cf8SJoonyoung Shim struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); 2633b8d1cf8SJoonyoung Shim 2643b8d1cf8SJoonyoung Shim if (property == dev_priv->crtc_mode_property) { 2653b8d1cf8SJoonyoung Shim enum exynos_crtc_mode mode = val; 2663b8d1cf8SJoonyoung Shim 2673b8d1cf8SJoonyoung Shim if (mode == exynos_crtc->mode) 2683b8d1cf8SJoonyoung Shim return 0; 2693b8d1cf8SJoonyoung Shim 2703b8d1cf8SJoonyoung Shim exynos_crtc->mode = mode; 2713b8d1cf8SJoonyoung Shim 2723b8d1cf8SJoonyoung Shim switch (mode) { 2733b8d1cf8SJoonyoung Shim case CRTC_MODE_NORMAL: 2743b8d1cf8SJoonyoung Shim exynos_drm_crtc_commit(crtc); 2753b8d1cf8SJoonyoung Shim break; 2763b8d1cf8SJoonyoung Shim case CRTC_MODE_BLANK: 2773b8d1cf8SJoonyoung Shim exynos_plane_dpms(exynos_crtc->plane, 2783b8d1cf8SJoonyoung Shim DRM_MODE_DPMS_OFF); 2793b8d1cf8SJoonyoung Shim break; 2803b8d1cf8SJoonyoung Shim default: 2813b8d1cf8SJoonyoung Shim break; 2823b8d1cf8SJoonyoung Shim } 2833b8d1cf8SJoonyoung Shim 2843b8d1cf8SJoonyoung Shim return 0; 2853b8d1cf8SJoonyoung Shim } 2863b8d1cf8SJoonyoung Shim 2873b8d1cf8SJoonyoung Shim return -EINVAL; 2883b8d1cf8SJoonyoung Shim } 2893b8d1cf8SJoonyoung Shim 2901c248b7dSInki Dae static struct drm_crtc_funcs exynos_crtc_funcs = { 2911c248b7dSInki Dae .set_config = drm_crtc_helper_set_config, 2921c248b7dSInki Dae .page_flip = exynos_drm_crtc_page_flip, 2931c248b7dSInki Dae .destroy = exynos_drm_crtc_destroy, 2943b8d1cf8SJoonyoung Shim .set_property = exynos_drm_crtc_set_property, 2951c248b7dSInki Dae }; 2961c248b7dSInki Dae 2973b8d1cf8SJoonyoung Shim static const struct drm_prop_enum_list mode_names[] = { 2983b8d1cf8SJoonyoung Shim { CRTC_MODE_NORMAL, "normal" }, 2993b8d1cf8SJoonyoung Shim { CRTC_MODE_BLANK, "blank" }, 3003b8d1cf8SJoonyoung Shim }; 3013b8d1cf8SJoonyoung Shim 3023b8d1cf8SJoonyoung Shim static void exynos_drm_crtc_attach_mode_property(struct drm_crtc *crtc) 3033b8d1cf8SJoonyoung Shim { 3043b8d1cf8SJoonyoung Shim struct drm_device *dev = crtc->dev; 3053b8d1cf8SJoonyoung Shim struct exynos_drm_private *dev_priv = dev->dev_private; 3063b8d1cf8SJoonyoung Shim struct drm_property *prop; 3073b8d1cf8SJoonyoung Shim 3083b8d1cf8SJoonyoung Shim prop = dev_priv->crtc_mode_property; 3093b8d1cf8SJoonyoung Shim if (!prop) { 3103b8d1cf8SJoonyoung Shim prop = drm_property_create_enum(dev, 0, "mode", mode_names, 3113b8d1cf8SJoonyoung Shim ARRAY_SIZE(mode_names)); 3123b8d1cf8SJoonyoung Shim if (!prop) 3133b8d1cf8SJoonyoung Shim return; 3143b8d1cf8SJoonyoung Shim 3153b8d1cf8SJoonyoung Shim dev_priv->crtc_mode_property = prop; 3163b8d1cf8SJoonyoung Shim } 3173b8d1cf8SJoonyoung Shim 3183b8d1cf8SJoonyoung Shim drm_object_attach_property(&crtc->base, prop, 0); 3193b8d1cf8SJoonyoung Shim } 3203b8d1cf8SJoonyoung Shim 3211c248b7dSInki Dae int exynos_drm_crtc_create(struct drm_device *dev, unsigned int nr) 3221c248b7dSInki Dae { 3231c248b7dSInki Dae struct exynos_drm_crtc *exynos_crtc; 3241c248b7dSInki Dae struct exynos_drm_private *private = dev->dev_private; 3251c248b7dSInki Dae struct drm_crtc *crtc; 3261c248b7dSInki Dae 3271c248b7dSInki Dae exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL); 32838bb5253SSachin Kamat if (!exynos_crtc) 3291c248b7dSInki Dae return -ENOMEM; 3301c248b7dSInki Dae 3311c248b7dSInki Dae exynos_crtc->pipe = nr; 332ec05da95SInki Dae exynos_crtc->dpms = DRM_MODE_DPMS_OFF; 33320cd2640SInki Dae init_waitqueue_head(&exynos_crtc->pending_flip_queue); 33420cd2640SInki Dae atomic_set(&exynos_crtc->pending_flip, 0); 335b5d2eb3bSJoonyoung Shim exynos_crtc->plane = exynos_plane_init(dev, 1 << nr, true); 336b5d2eb3bSJoonyoung Shim if (!exynos_crtc->plane) { 337b5d2eb3bSJoonyoung Shim kfree(exynos_crtc); 338b5d2eb3bSJoonyoung Shim return -ENOMEM; 339b5d2eb3bSJoonyoung Shim } 340b5d2eb3bSJoonyoung Shim 3411c248b7dSInki Dae crtc = &exynos_crtc->drm_crtc; 3421c248b7dSInki Dae 3431c248b7dSInki Dae private->crtc[nr] = crtc; 3441c248b7dSInki Dae 3451c248b7dSInki Dae drm_crtc_init(dev, crtc, &exynos_crtc_funcs); 3461c248b7dSInki Dae drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs); 3471c248b7dSInki Dae 3483b8d1cf8SJoonyoung Shim exynos_drm_crtc_attach_mode_property(crtc); 3493b8d1cf8SJoonyoung Shim 3501c248b7dSInki Dae return 0; 3511c248b7dSInki Dae } 3521c248b7dSInki Dae 3531c248b7dSInki Dae int exynos_drm_crtc_enable_vblank(struct drm_device *dev, int crtc) 3541c248b7dSInki Dae { 3551c248b7dSInki Dae struct exynos_drm_private *private = dev->dev_private; 356ec05da95SInki Dae struct exynos_drm_crtc *exynos_crtc = 357ec05da95SInki Dae to_exynos_crtc(private->crtc[crtc]); 3581c248b7dSInki Dae 359ec05da95SInki Dae if (exynos_crtc->dpms != DRM_MODE_DPMS_ON) 360ec05da95SInki Dae return -EPERM; 361ec05da95SInki Dae 3621c248b7dSInki Dae exynos_drm_fn_encoder(private->crtc[crtc], &crtc, 3631c248b7dSInki Dae exynos_drm_enable_vblank); 3641c248b7dSInki Dae 3651c248b7dSInki Dae return 0; 3661c248b7dSInki Dae } 3671c248b7dSInki Dae 3681c248b7dSInki Dae void exynos_drm_crtc_disable_vblank(struct drm_device *dev, int crtc) 3691c248b7dSInki Dae { 3701c248b7dSInki Dae struct exynos_drm_private *private = dev->dev_private; 371ec05da95SInki Dae struct exynos_drm_crtc *exynos_crtc = 372ec05da95SInki Dae to_exynos_crtc(private->crtc[crtc]); 3731c248b7dSInki Dae 374ec05da95SInki Dae if (exynos_crtc->dpms != DRM_MODE_DPMS_ON) 375ec05da95SInki Dae return; 376ec05da95SInki Dae 3771c248b7dSInki Dae exynos_drm_fn_encoder(private->crtc[crtc], &crtc, 3781c248b7dSInki Dae exynos_drm_disable_vblank); 3791c248b7dSInki Dae } 380663d8766SRahul Sharma 381663d8766SRahul Sharma void exynos_drm_crtc_finish_pageflip(struct drm_device *dev, int crtc) 382663d8766SRahul Sharma { 383663d8766SRahul Sharma struct exynos_drm_private *dev_priv = dev->dev_private; 384663d8766SRahul Sharma struct drm_pending_vblank_event *e, *t; 38520cd2640SInki Dae struct drm_crtc *drm_crtc = dev_priv->crtc[crtc]; 38620cd2640SInki Dae struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(drm_crtc); 387663d8766SRahul Sharma unsigned long flags; 388663d8766SRahul Sharma 389663d8766SRahul Sharma spin_lock_irqsave(&dev->event_lock, flags); 390663d8766SRahul Sharma 391663d8766SRahul Sharma list_for_each_entry_safe(e, t, &dev_priv->pageflip_event_list, 392663d8766SRahul Sharma base.link) { 393663d8766SRahul Sharma /* if event's pipe isn't same as crtc then ignore it. */ 394663d8766SRahul Sharma if (crtc != e->pipe) 395663d8766SRahul Sharma continue; 396663d8766SRahul Sharma 397c5cca97fSRob Clark list_del(&e->base.link); 398c5cca97fSRob Clark drm_send_vblank_event(dev, -1, e); 399663d8766SRahul Sharma drm_vblank_put(dev, crtc); 40020cd2640SInki Dae atomic_set(&exynos_crtc->pending_flip, 0); 40120cd2640SInki Dae wake_up(&exynos_crtc->pending_flip_queue); 402663d8766SRahul Sharma } 403663d8766SRahul Sharma 404663d8766SRahul Sharma spin_unlock_irqrestore(&dev->event_lock, flags); 405663d8766SRahul Sharma } 406