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