Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1 | /* 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 Dae | d81aecb | 2012-12-18 02:30:17 +0900 | [diff] [blame] | 9 | * 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 Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 13 | */ |
| 14 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 15 | #include <drm/drmP.h> |
| 16 | #include <drm/drm_crtc_helper.h> |
Gustavo Padovan | 4ea9526 | 2015-06-01 12:04:44 -0300 | [diff] [blame] | 17 | #include <drm/drm_atomic.h> |
| 18 | #include <drm/drm_atomic_helper.h> |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 19 | |
Mark Brown | e30655d | 2013-08-13 00:46:40 +0100 | [diff] [blame] | 20 | #include "exynos_drm_crtc.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 21 | #include "exynos_drm_drv.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 22 | #include "exynos_drm_encoder.h" |
Joonyoung Shim | b5d2eb3 | 2012-06-27 14:27:04 +0900 | [diff] [blame] | 23 | #include "exynos_drm_plane.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 24 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 25 | static void exynos_drm_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 26 | { |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 27 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 28 | |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 29 | DRM_DEBUG_KMS("crtc[%d] mode[%d]\n", crtc->base.id, mode); |
| 30 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 31 | if (exynos_crtc->dpms == mode) { |
| 32 | DRM_DEBUG_KMS("desired dpms mode is same as previous one.\n"); |
| 33 | return; |
| 34 | } |
| 35 | |
Inki Dae | 20cd264 | 2013-05-21 16:55:58 +0900 | [diff] [blame] | 36 | if (mode > DRM_MODE_DPMS_ON) { |
| 37 | /* wait for the completion of page flip. */ |
YoungJun Cho | e35d722 | 2014-07-17 18:01:17 +0900 | [diff] [blame] | 38 | if (!wait_event_timeout(exynos_crtc->pending_flip_queue, |
Mandeep Singh Baines | e752747 | 2015-04-01 13:02:12 -0300 | [diff] [blame] | 39 | (exynos_crtc->event == NULL), HZ/20)) |
| 40 | exynos_crtc->event = NULL; |
Andrzej Hajda | d6948b2 | 2014-10-10 14:31:55 +0200 | [diff] [blame] | 41 | drm_crtc_vblank_off(crtc); |
Inki Dae | 20cd264 | 2013-05-21 16:55:58 +0900 | [diff] [blame] | 42 | } |
| 43 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 44 | if (exynos_crtc->ops->dpms) |
| 45 | exynos_crtc->ops->dpms(exynos_crtc, mode); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 46 | |
Joonyoung Shim | cf5188a | 2012-06-27 14:27:09 +0900 | [diff] [blame] | 47 | exynos_crtc->dpms = mode; |
Andrzej Hajda | d6948b2 | 2014-10-10 14:31:55 +0200 | [diff] [blame] | 48 | |
| 49 | if (mode == DRM_MODE_DPMS_ON) |
| 50 | drm_crtc_vblank_on(crtc); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 51 | } |
| 52 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 53 | static void exynos_drm_crtc_commit(struct drm_crtc *crtc) |
| 54 | { |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 55 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
Gustavo Padovan | 9d5310c | 2014-11-13 22:17:46 -0200 | [diff] [blame] | 56 | struct exynos_drm_plane *exynos_plane = to_exynos_plane(crtc->primary); |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 57 | |
Inki Dae | 50caf25 | 2012-08-20 21:29:25 +0900 | [diff] [blame] | 58 | exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_ON); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 59 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 60 | if (exynos_crtc->ops->win_commit) |
| 61 | exynos_crtc->ops->win_commit(exynos_crtc, exynos_plane->zpos); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | static bool |
| 65 | exynos_drm_crtc_mode_fixup(struct drm_crtc *crtc, |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 66 | const struct drm_display_mode *mode, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 67 | struct drm_display_mode *adjusted_mode) |
| 68 | { |
Sean Paul | 4b40526 | 2014-01-30 16:19:19 -0500 | [diff] [blame] | 69 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
Sean Paul | 4b40526 | 2014-01-30 16:19:19 -0500 | [diff] [blame] | 70 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 71 | if (exynos_crtc->ops->mode_fixup) |
| 72 | return exynos_crtc->ops->mode_fixup(exynos_crtc, mode, |
| 73 | adjusted_mode); |
Sean Paul | 4b40526 | 2014-01-30 16:19:19 -0500 | [diff] [blame] | 74 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 75 | return true; |
| 76 | } |
| 77 | |
Gustavo Padovan | 199329c | 2015-06-01 12:04:43 -0300 | [diff] [blame] | 78 | static void |
| 79 | exynos_drm_crtc_mode_set_nofb(struct drm_crtc *crtc) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 80 | { |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 81 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 82 | |
Gustavo Padovan | 199329c | 2015-06-01 12:04:43 -0300 | [diff] [blame] | 83 | if (exynos_crtc->ops->commit) |
| 84 | exynos_crtc->ops->commit(exynos_crtc); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 85 | } |
| 86 | |
Joonyoung Shim | a365d9e | 2012-06-27 14:27:10 +0900 | [diff] [blame] | 87 | static void exynos_drm_crtc_disable(struct drm_crtc *crtc) |
| 88 | { |
Sean Paul | a9c4cd2 | 2014-01-30 16:19:17 -0500 | [diff] [blame] | 89 | struct drm_plane *plane; |
| 90 | int ret; |
Joonyoung Shim | a365d9e | 2012-06-27 14:27:10 +0900 | [diff] [blame] | 91 | |
Joonyoung Shim | a365d9e | 2012-06-27 14:27:10 +0900 | [diff] [blame] | 92 | exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
Sean Paul | a9c4cd2 | 2014-01-30 16:19:17 -0500 | [diff] [blame] | 93 | |
Matt Roper | 0886327 | 2014-04-01 15:22:31 -0700 | [diff] [blame] | 94 | drm_for_each_legacy_plane(plane, &crtc->dev->mode_config.plane_list) { |
Sean Paul | a9c4cd2 | 2014-01-30 16:19:17 -0500 | [diff] [blame] | 95 | if (plane->crtc != crtc) |
| 96 | continue; |
| 97 | |
| 98 | ret = plane->funcs->disable_plane(plane); |
| 99 | if (ret) |
| 100 | DRM_ERROR("Failed to disable plane %d\n", ret); |
| 101 | } |
Joonyoung Shim | a365d9e | 2012-06-27 14:27:10 +0900 | [diff] [blame] | 102 | } |
| 103 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 104 | static struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = { |
| 105 | .dpms = exynos_drm_crtc_dpms, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 106 | .commit = exynos_drm_crtc_commit, |
| 107 | .mode_fixup = exynos_drm_crtc_mode_fixup, |
Gustavo Padovan | 199329c | 2015-06-01 12:04:43 -0300 | [diff] [blame] | 108 | .mode_set_nofb = exynos_drm_crtc_mode_set_nofb, |
Joonyoung Shim | a365d9e | 2012-06-27 14:27:10 +0900 | [diff] [blame] | 109 | .disable = exynos_drm_crtc_disable, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | static int exynos_drm_crtc_page_flip(struct drm_crtc *crtc, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 113 | struct drm_framebuffer *fb, |
| 114 | struct drm_pending_vblank_event *event, |
| 115 | uint32_t page_flip_flags) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 116 | { |
| 117 | struct drm_device *dev = crtc->dev; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 118 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
Gustavo Padovan | 8b9c450 | 2014-11-25 16:18:34 -0200 | [diff] [blame] | 119 | unsigned int crtc_w, crtc_h; |
Mandeep Singh Baines | e752747 | 2015-04-01 13:02:12 -0300 | [diff] [blame] | 120 | int ret; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 121 | |
Inki Dae | ef6223d | 2012-09-11 18:25:21 +0900 | [diff] [blame] | 122 | /* when the page flip is requested, crtc's dpms should be on */ |
| 123 | if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) { |
| 124 | DRM_ERROR("failed page flip request.\n"); |
| 125 | return -EINVAL; |
| 126 | } |
| 127 | |
Mandeep Singh Baines | e752747 | 2015-04-01 13:02:12 -0300 | [diff] [blame] | 128 | if (!event) |
| 129 | return -EINVAL; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 130 | |
Mandeep Singh Baines | e752747 | 2015-04-01 13:02:12 -0300 | [diff] [blame] | 131 | spin_lock_irq(&dev->event_lock); |
| 132 | if (exynos_crtc->event) { |
| 133 | ret = -EBUSY; |
| 134 | goto out; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 135 | } |
Mandeep Singh Baines | e752747 | 2015-04-01 13:02:12 -0300 | [diff] [blame] | 136 | |
Gustavo Padovan | 43dbdad | 2015-06-01 12:04:41 -0300 | [diff] [blame] | 137 | ret = exynos_check_plane(crtc->primary, fb); |
| 138 | if (ret) |
| 139 | goto out; |
| 140 | |
Mandeep Singh Baines | e752747 | 2015-04-01 13:02:12 -0300 | [diff] [blame] | 141 | ret = drm_vblank_get(dev, exynos_crtc->pipe); |
| 142 | if (ret) { |
| 143 | DRM_DEBUG("failed to acquire vblank counter\n"); |
| 144 | goto out; |
| 145 | } |
| 146 | |
| 147 | exynos_crtc->event = event; |
| 148 | spin_unlock_irq(&dev->event_lock); |
| 149 | |
| 150 | /* |
| 151 | * the pipe from user always is 0 so we can set pipe number |
| 152 | * of current owner to event. |
| 153 | */ |
| 154 | event->pipe = exynos_crtc->pipe; |
| 155 | |
| 156 | crtc->primary->fb = fb; |
| 157 | crtc_w = fb->width - crtc->x; |
| 158 | crtc_h = fb->height - crtc->y; |
Gustavo Padovan | 43dbdad | 2015-06-01 12:04:41 -0300 | [diff] [blame] | 159 | exynos_update_plane(crtc->primary, crtc, fb, 0, 0, |
| 160 | crtc_w, crtc_h, crtc->x << 16, crtc->y << 16, |
| 161 | crtc_w << 16, crtc_h << 16); |
Mandeep Singh Baines | e752747 | 2015-04-01 13:02:12 -0300 | [diff] [blame] | 162 | |
Gustavo Padovan | 7cf1ff25 | 2015-06-01 12:04:45 -0300 | [diff] [blame] | 163 | if (crtc->primary->state) |
| 164 | drm_atomic_set_fb_for_plane(crtc->primary->state, fb); |
| 165 | |
Mandeep Singh Baines | e752747 | 2015-04-01 13:02:12 -0300 | [diff] [blame] | 166 | return 0; |
| 167 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 168 | out: |
Mandeep Singh Baines | e752747 | 2015-04-01 13:02:12 -0300 | [diff] [blame] | 169 | spin_unlock_irq(&dev->event_lock); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 170 | return ret; |
| 171 | } |
| 172 | |
| 173 | static void exynos_drm_crtc_destroy(struct drm_crtc *crtc) |
| 174 | { |
| 175 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 176 | struct exynos_drm_private *private = crtc->dev->dev_private; |
| 177 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 178 | private->crtc[exynos_crtc->pipe] = NULL; |
| 179 | |
| 180 | drm_crtc_cleanup(crtc); |
| 181 | kfree(exynos_crtc); |
| 182 | } |
| 183 | |
| 184 | static struct drm_crtc_funcs exynos_crtc_funcs = { |
Gustavo Padovan | 47a7def | 2015-06-01 12:04:47 -0300 | [diff] [blame^] | 185 | .set_config = drm_atomic_helper_set_config, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 186 | .page_flip = exynos_drm_crtc_page_flip, |
| 187 | .destroy = exynos_drm_crtc_destroy, |
Gustavo Padovan | 4ea9526 | 2015-06-01 12:04:44 -0300 | [diff] [blame] | 188 | .reset = drm_atomic_helper_crtc_reset, |
| 189 | .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, |
| 190 | .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 191 | }; |
| 192 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 193 | struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev, |
Krzysztof Kozlowski | f3aaf76 | 2015-05-07 09:04:45 +0900 | [diff] [blame] | 194 | struct drm_plane *plane, |
| 195 | int pipe, |
| 196 | enum exynos_drm_output_type type, |
| 197 | const struct exynos_drm_crtc_ops *ops, |
| 198 | void *ctx) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 199 | { |
| 200 | struct exynos_drm_crtc *exynos_crtc; |
Gustavo Padovan | eb88e42 | 2014-11-26 16:43:27 -0200 | [diff] [blame] | 201 | struct exynos_drm_private *private = drm_dev->dev_private; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 202 | struct drm_crtc *crtc; |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 203 | int ret; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 204 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 205 | exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL); |
Sachin Kamat | 38bb525 | 2013-08-19 19:04:55 +0900 | [diff] [blame] | 206 | if (!exynos_crtc) |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 207 | return ERR_PTR(-ENOMEM); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 208 | |
Inki Dae | 20cd264 | 2013-05-21 16:55:58 +0900 | [diff] [blame] | 209 | init_waitqueue_head(&exynos_crtc->pending_flip_queue); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 210 | |
| 211 | exynos_crtc->dpms = DRM_MODE_DPMS_OFF; |
Gustavo Padovan | e09f2b0 | 2014-11-04 18:25:27 -0200 | [diff] [blame] | 212 | exynos_crtc->pipe = pipe; |
Gustavo Padovan | 5d1741a | 2014-11-05 19:51:35 -0200 | [diff] [blame] | 213 | exynos_crtc->type = type; |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 214 | exynos_crtc->ops = ops; |
| 215 | exynos_crtc->ctx = ctx; |
Joonyoung Shim | b5d2eb3 | 2012-06-27 14:27:04 +0900 | [diff] [blame] | 216 | |
Gustavo Padovan | 357193c | 2014-11-03 18:20:29 -0200 | [diff] [blame] | 217 | crtc = &exynos_crtc->base; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 218 | |
Gustavo Padovan | e09f2b0 | 2014-11-04 18:25:27 -0200 | [diff] [blame] | 219 | private->crtc[pipe] = crtc; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 220 | |
Gustavo Padovan | eb88e42 | 2014-11-26 16:43:27 -0200 | [diff] [blame] | 221 | ret = drm_crtc_init_with_planes(drm_dev, crtc, plane, NULL, |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 222 | &exynos_crtc_funcs); |
| 223 | if (ret < 0) |
| 224 | goto err_crtc; |
| 225 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 226 | drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs); |
| 227 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 228 | return exynos_crtc; |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 229 | |
| 230 | err_crtc: |
| 231 | plane->funcs->destroy(plane); |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 232 | kfree(exynos_crtc); |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 233 | return ERR_PTR(ret); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 234 | } |
| 235 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 236 | int exynos_drm_crtc_enable_vblank(struct drm_device *dev, int pipe) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 237 | { |
| 238 | struct exynos_drm_private *private = dev->dev_private; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 239 | struct exynos_drm_crtc *exynos_crtc = |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 240 | to_exynos_crtc(private->crtc[pipe]); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 241 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 242 | if (exynos_crtc->dpms != DRM_MODE_DPMS_ON) |
| 243 | return -EPERM; |
| 244 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 245 | if (exynos_crtc->ops->enable_vblank) |
| 246 | exynos_crtc->ops->enable_vblank(exynos_crtc); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 251 | void exynos_drm_crtc_disable_vblank(struct drm_device *dev, int pipe) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 252 | { |
| 253 | struct exynos_drm_private *private = dev->dev_private; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 254 | struct exynos_drm_crtc *exynos_crtc = |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 255 | to_exynos_crtc(private->crtc[pipe]); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 256 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 257 | if (exynos_crtc->dpms != DRM_MODE_DPMS_ON) |
| 258 | return; |
| 259 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 260 | if (exynos_crtc->ops->disable_vblank) |
| 261 | exynos_crtc->ops->disable_vblank(exynos_crtc); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 262 | } |
Rahul Sharma | 663d876 | 2013-01-03 05:44:04 -0500 | [diff] [blame] | 263 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 264 | void exynos_drm_crtc_finish_pageflip(struct drm_device *dev, int pipe) |
Rahul Sharma | 663d876 | 2013-01-03 05:44:04 -0500 | [diff] [blame] | 265 | { |
| 266 | struct exynos_drm_private *dev_priv = dev->dev_private; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 267 | struct drm_crtc *drm_crtc = dev_priv->crtc[pipe]; |
Inki Dae | 20cd264 | 2013-05-21 16:55:58 +0900 | [diff] [blame] | 268 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(drm_crtc); |
Rahul Sharma | 663d876 | 2013-01-03 05:44:04 -0500 | [diff] [blame] | 269 | unsigned long flags; |
| 270 | |
Rahul Sharma | 663d876 | 2013-01-03 05:44:04 -0500 | [diff] [blame] | 271 | spin_lock_irqsave(&dev->event_lock, flags); |
Mandeep Singh Baines | e752747 | 2015-04-01 13:02:12 -0300 | [diff] [blame] | 272 | if (exynos_crtc->event) { |
Rahul Sharma | 663d876 | 2013-01-03 05:44:04 -0500 | [diff] [blame] | 273 | |
Mandeep Singh Baines | e752747 | 2015-04-01 13:02:12 -0300 | [diff] [blame] | 274 | drm_send_vblank_event(dev, -1, exynos_crtc->event); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 275 | drm_vblank_put(dev, pipe); |
Inki Dae | 20cd264 | 2013-05-21 16:55:58 +0900 | [diff] [blame] | 276 | wake_up(&exynos_crtc->pending_flip_queue); |
Mandeep Singh Baines | e752747 | 2015-04-01 13:02:12 -0300 | [diff] [blame] | 277 | |
Rahul Sharma | 663d876 | 2013-01-03 05:44:04 -0500 | [diff] [blame] | 278 | } |
| 279 | |
Mandeep Singh Baines | e752747 | 2015-04-01 13:02:12 -0300 | [diff] [blame] | 280 | exynos_crtc->event = NULL; |
Rahul Sharma | 663d876 | 2013-01-03 05:44:04 -0500 | [diff] [blame] | 281 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 282 | } |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 283 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 284 | void exynos_drm_crtc_complete_scanout(struct drm_framebuffer *fb) |
| 285 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 286 | struct exynos_drm_crtc *exynos_crtc; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 287 | struct drm_device *dev = fb->dev; |
| 288 | struct drm_crtc *crtc; |
| 289 | |
| 290 | /* |
| 291 | * make sure that overlay data are updated to real hardware |
| 292 | * for all encoders. |
| 293 | */ |
| 294 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 295 | exynos_crtc = to_exynos_crtc(crtc); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 296 | |
| 297 | /* |
| 298 | * wait for vblank interrupt |
| 299 | * - this makes sure that overlay data are updated to |
| 300 | * real hardware. |
| 301 | */ |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 302 | if (exynos_crtc->ops->wait_for_vblank) |
| 303 | exynos_crtc->ops->wait_for_vblank(exynos_crtc); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 304 | } |
| 305 | } |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 306 | |
| 307 | int exynos_drm_crtc_get_pipe_from_type(struct drm_device *drm_dev, |
| 308 | unsigned int out_type) |
| 309 | { |
| 310 | struct drm_crtc *crtc; |
| 311 | |
| 312 | list_for_each_entry(crtc, &drm_dev->mode_config.crtc_list, head) { |
| 313 | struct exynos_drm_crtc *exynos_crtc; |
| 314 | |
| 315 | exynos_crtc = to_exynos_crtc(crtc); |
Gustavo Padovan | 5d1741a | 2014-11-05 19:51:35 -0200 | [diff] [blame] | 316 | if (exynos_crtc->type == out_type) |
Gustavo Padovan | 8a326ed | 2014-11-04 18:44:47 -0200 | [diff] [blame] | 317 | return exynos_crtc->pipe; |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | return -EPERM; |
| 321 | } |
YoungJun Cho | 5595d4d | 2014-07-17 18:01:19 +0900 | [diff] [blame] | 322 | |
| 323 | void exynos_drm_crtc_te_handler(struct drm_crtc *crtc) |
| 324 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 325 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
YoungJun Cho | 5595d4d | 2014-07-17 18:01:19 +0900 | [diff] [blame] | 326 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 327 | if (exynos_crtc->ops->te_handler) |
| 328 | exynos_crtc->ops->te_handler(exynos_crtc); |
YoungJun Cho | 5595d4d | 2014-07-17 18:01:19 +0900 | [diff] [blame] | 329 | } |