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); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 26 | struct exynos_drm_manager *manager = exynos_crtc->manager; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 27 | |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 28 | DRM_DEBUG_KMS("crtc[%d] mode[%d]\n", crtc->base.id, mode); |
| 29 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 30 | if (exynos_crtc->dpms == mode) { |
| 31 | DRM_DEBUG_KMS("desired dpms mode is same as previous one.\n"); |
| 32 | return; |
| 33 | } |
| 34 | |
Inki Dae | 20cd264 | 2013-05-21 16:55:58 +0900 | [diff] [blame] | 35 | if (mode > DRM_MODE_DPMS_ON) { |
| 36 | /* wait for the completion of page flip. */ |
YoungJun Cho | e35d722 | 2014-07-17 18:01:17 +0900 | [diff] [blame] | 37 | if (!wait_event_timeout(exynos_crtc->pending_flip_queue, |
| 38 | !atomic_read(&exynos_crtc->pending_flip), |
| 39 | HZ/20)) |
| 40 | atomic_set(&exynos_crtc->pending_flip, 0); |
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 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 44 | if (manager->ops->dpms) |
| 45 | manager->ops->dpms(manager, mode); |
| 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 | |
| 53 | static void exynos_drm_crtc_prepare(struct drm_crtc *crtc) |
| 54 | { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 55 | /* drm framework doesn't check NULL. */ |
| 56 | } |
| 57 | |
| 58 | static void exynos_drm_crtc_commit(struct drm_crtc *crtc) |
| 59 | { |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 60 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 61 | struct exynos_drm_manager *manager = exynos_crtc->manager; |
Gustavo Padovan | 9d5310c | 2014-11-13 22:17:46 -0200 | [diff] [blame] | 62 | struct exynos_drm_plane *exynos_plane = to_exynos_plane(crtc->primary); |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 63 | |
Inki Dae | 50caf25 | 2012-08-20 21:29:25 +0900 | [diff] [blame] | 64 | exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_ON); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 65 | |
Gustavo Padovan | 9d5310c | 2014-11-13 22:17:46 -0200 | [diff] [blame] | 66 | if (manager->ops->win_commit) |
| 67 | manager->ops->win_commit(manager, exynos_plane->zpos); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 68 | |
| 69 | if (manager->ops->commit) |
| 70 | manager->ops->commit(manager); |
| 71 | |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 72 | exynos_plane_dpms(crtc->primary, DRM_MODE_DPMS_ON); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | static bool |
| 76 | exynos_drm_crtc_mode_fixup(struct drm_crtc *crtc, |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 77 | const struct drm_display_mode *mode, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 78 | struct drm_display_mode *adjusted_mode) |
| 79 | { |
Sean Paul | 4b40526 | 2014-01-30 16:19:19 -0500 | [diff] [blame] | 80 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 81 | struct exynos_drm_manager *manager = exynos_crtc->manager; |
| 82 | |
| 83 | if (manager->ops->mode_fixup) |
| 84 | return manager->ops->mode_fixup(manager, mode, adjusted_mode); |
| 85 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 86 | return true; |
| 87 | } |
| 88 | |
| 89 | static int |
| 90 | exynos_drm_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode, |
| 91 | struct drm_display_mode *adjusted_mode, int x, int y, |
| 92 | struct drm_framebuffer *old_fb) |
| 93 | { |
Joonyoung Shim | aeb2922 | 2012-06-27 14:27:01 +0900 | [diff] [blame] | 94 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
Sean Paul | cd706aa | 2014-01-30 16:19:18 -0500 | [diff] [blame] | 95 | struct exynos_drm_manager *manager = exynos_crtc->manager; |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 96 | struct drm_framebuffer *fb = crtc->primary->fb; |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 97 | unsigned int crtc_w; |
| 98 | unsigned int crtc_h; |
Joonyoung Shim | aeb2922 | 2012-06-27 14:27:01 +0900 | [diff] [blame] | 99 | |
Inki Dae | 1de425b | 2012-03-16 18:47:04 +0900 | [diff] [blame] | 100 | /* |
| 101 | * copy the mode data adjusted by mode_fixup() into crtc->mode |
| 102 | * so that hardware can be seet to proper mode. |
| 103 | */ |
| 104 | memcpy(&crtc->mode, adjusted_mode, sizeof(*adjusted_mode)); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 105 | |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 106 | crtc_w = fb->width - x; |
| 107 | crtc_h = fb->height - y; |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 108 | |
Sean Paul | cd706aa | 2014-01-30 16:19:18 -0500 | [diff] [blame] | 109 | if (manager->ops->mode_set) |
| 110 | manager->ops->mode_set(manager, &crtc->mode); |
| 111 | |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 112 | return exynos_plane_mode_set(crtc->primary, crtc, fb, 0, 0, |
| 113 | crtc_w, crtc_h, x, y, crtc_w, crtc_h); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 114 | } |
| 115 | |
Inki Dae | 7fd65df | 2013-05-12 16:09:33 +0900 | [diff] [blame] | 116 | static int exynos_drm_crtc_mode_set_commit(struct drm_crtc *crtc, int x, int y, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 117 | struct drm_framebuffer *old_fb) |
| 118 | { |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 119 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 120 | struct drm_framebuffer *fb = crtc->primary->fb; |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 121 | unsigned int crtc_w; |
| 122 | unsigned int crtc_h; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 123 | |
Inki Dae | 32aeab1 | 2012-09-14 13:29:47 +0900 | [diff] [blame] | 124 | /* when framebuffer changing is requested, crtc's dpms should be on */ |
| 125 | if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) { |
| 126 | DRM_ERROR("failed framebuffer changing request.\n"); |
| 127 | return -EPERM; |
| 128 | } |
| 129 | |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 130 | crtc_w = fb->width - x; |
| 131 | crtc_h = fb->height - y; |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 132 | |
Gustavo Padovan | 0e0a649 | 2014-11-25 11:21:17 -0200 | [diff] [blame] | 133 | return exynos_update_plane(crtc->primary, crtc, fb, 0, 0, |
| 134 | crtc_w, crtc_h, x, y, crtc_w, crtc_h); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 135 | } |
| 136 | |
Inki Dae | 7fd65df | 2013-05-12 16:09:33 +0900 | [diff] [blame] | 137 | static int exynos_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, |
| 138 | struct drm_framebuffer *old_fb) |
| 139 | { |
| 140 | return exynos_drm_crtc_mode_set_commit(crtc, x, y, old_fb); |
| 141 | } |
| 142 | |
Joonyoung Shim | a365d9e | 2012-06-27 14:27:10 +0900 | [diff] [blame] | 143 | static void exynos_drm_crtc_disable(struct drm_crtc *crtc) |
| 144 | { |
Sean Paul | a9c4cd2 | 2014-01-30 16:19:17 -0500 | [diff] [blame] | 145 | struct drm_plane *plane; |
| 146 | int ret; |
Joonyoung Shim | a365d9e | 2012-06-27 14:27:10 +0900 | [diff] [blame] | 147 | |
Joonyoung Shim | a365d9e | 2012-06-27 14:27:10 +0900 | [diff] [blame] | 148 | exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
Sean Paul | a9c4cd2 | 2014-01-30 16:19:17 -0500 | [diff] [blame] | 149 | |
Matt Roper | 0886327 | 2014-04-01 15:22:31 -0700 | [diff] [blame] | 150 | drm_for_each_legacy_plane(plane, &crtc->dev->mode_config.plane_list) { |
Sean Paul | a9c4cd2 | 2014-01-30 16:19:17 -0500 | [diff] [blame] | 151 | if (plane->crtc != crtc) |
| 152 | continue; |
| 153 | |
| 154 | ret = plane->funcs->disable_plane(plane); |
| 155 | if (ret) |
| 156 | DRM_ERROR("Failed to disable plane %d\n", ret); |
| 157 | } |
Joonyoung Shim | a365d9e | 2012-06-27 14:27:10 +0900 | [diff] [blame] | 158 | } |
| 159 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 160 | static struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = { |
| 161 | .dpms = exynos_drm_crtc_dpms, |
| 162 | .prepare = exynos_drm_crtc_prepare, |
| 163 | .commit = exynos_drm_crtc_commit, |
| 164 | .mode_fixup = exynos_drm_crtc_mode_fixup, |
| 165 | .mode_set = exynos_drm_crtc_mode_set, |
| 166 | .mode_set_base = exynos_drm_crtc_mode_set_base, |
Joonyoung Shim | a365d9e | 2012-06-27 14:27:10 +0900 | [diff] [blame] | 167 | .disable = exynos_drm_crtc_disable, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | static int exynos_drm_crtc_page_flip(struct drm_crtc *crtc, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 171 | struct drm_framebuffer *fb, |
| 172 | struct drm_pending_vblank_event *event, |
| 173 | uint32_t page_flip_flags) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 174 | { |
| 175 | struct drm_device *dev = crtc->dev; |
| 176 | struct exynos_drm_private *dev_priv = dev->dev_private; |
| 177 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 178 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
Gustavo Padovan | 8b9c450 | 2014-11-25 16:18:34 -0200 | [diff] [blame^] | 179 | unsigned int crtc_w, crtc_h; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 180 | int ret = -EINVAL; |
| 181 | |
Inki Dae | ef6223d | 2012-09-11 18:25:21 +0900 | [diff] [blame] | 182 | /* when the page flip is requested, crtc's dpms should be on */ |
| 183 | if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) { |
| 184 | DRM_ERROR("failed page flip request.\n"); |
| 185 | return -EINVAL; |
| 186 | } |
| 187 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 188 | mutex_lock(&dev->struct_mutex); |
| 189 | |
Inki Dae | ccf4d88 | 2011-10-14 13:29:51 +0900 | [diff] [blame] | 190 | if (event) { |
| 191 | /* |
| 192 | * the pipe from user always is 0 so we can set pipe number |
| 193 | * of current owner to event. |
| 194 | */ |
| 195 | event->pipe = exynos_crtc->pipe; |
| 196 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 197 | ret = drm_vblank_get(dev, exynos_crtc->pipe); |
| 198 | if (ret) { |
| 199 | DRM_DEBUG("failed to acquire vblank counter\n"); |
Inki Dae | ccf4d88 | 2011-10-14 13:29:51 +0900 | [diff] [blame] | 200 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 201 | goto out; |
| 202 | } |
| 203 | |
Imre Deak | 8547332 | 2012-11-02 13:30:47 +0200 | [diff] [blame] | 204 | spin_lock_irq(&dev->event_lock); |
Inki Dae | c5614ae | 2012-02-15 11:25:20 +0900 | [diff] [blame] | 205 | list_add_tail(&event->base.link, |
| 206 | &dev_priv->pageflip_event_list); |
Inki Dae | 20cd264 | 2013-05-21 16:55:58 +0900 | [diff] [blame] | 207 | atomic_set(&exynos_crtc->pending_flip, 1); |
Imre Deak | 8547332 | 2012-11-02 13:30:47 +0200 | [diff] [blame] | 208 | spin_unlock_irq(&dev->event_lock); |
Inki Dae | c5614ae | 2012-02-15 11:25:20 +0900 | [diff] [blame] | 209 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 210 | crtc->primary->fb = fb; |
Gustavo Padovan | 8b9c450 | 2014-11-25 16:18:34 -0200 | [diff] [blame^] | 211 | crtc_w = fb->width - crtc->x; |
| 212 | crtc_h = fb->height - crtc->y; |
| 213 | ret = exynos_update_plane(crtc->primary, crtc, fb, 0, 0, |
| 214 | crtc_w, crtc_h, crtc->x, crtc->y, |
| 215 | crtc_w, crtc_h); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 216 | if (ret) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 217 | crtc->primary->fb = old_fb; |
Imre Deak | 8547332 | 2012-11-02 13:30:47 +0200 | [diff] [blame] | 218 | |
| 219 | spin_lock_irq(&dev->event_lock); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 220 | drm_vblank_put(dev, exynos_crtc->pipe); |
Inki Dae | ccf4d88 | 2011-10-14 13:29:51 +0900 | [diff] [blame] | 221 | list_del(&event->base.link); |
YoungJun Cho | e35d722 | 2014-07-17 18:01:17 +0900 | [diff] [blame] | 222 | atomic_set(&exynos_crtc->pending_flip, 0); |
Imre Deak | 8547332 | 2012-11-02 13:30:47 +0200 | [diff] [blame] | 223 | spin_unlock_irq(&dev->event_lock); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 224 | |
| 225 | goto out; |
| 226 | } |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 227 | } |
| 228 | out: |
| 229 | mutex_unlock(&dev->struct_mutex); |
| 230 | return ret; |
| 231 | } |
| 232 | |
| 233 | static void exynos_drm_crtc_destroy(struct drm_crtc *crtc) |
| 234 | { |
| 235 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 236 | struct exynos_drm_private *private = crtc->dev->dev_private; |
| 237 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 238 | private->crtc[exynos_crtc->pipe] = NULL; |
| 239 | |
| 240 | drm_crtc_cleanup(crtc); |
| 241 | kfree(exynos_crtc); |
| 242 | } |
| 243 | |
Joonyoung Shim | 3b8d1cf | 2012-06-27 14:27:11 +0900 | [diff] [blame] | 244 | static int exynos_drm_crtc_set_property(struct drm_crtc *crtc, |
| 245 | struct drm_property *property, |
| 246 | uint64_t val) |
| 247 | { |
| 248 | struct drm_device *dev = crtc->dev; |
| 249 | struct exynos_drm_private *dev_priv = dev->dev_private; |
| 250 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 251 | |
Joonyoung Shim | 3b8d1cf | 2012-06-27 14:27:11 +0900 | [diff] [blame] | 252 | if (property == dev_priv->crtc_mode_property) { |
| 253 | enum exynos_crtc_mode mode = val; |
| 254 | |
| 255 | if (mode == exynos_crtc->mode) |
| 256 | return 0; |
| 257 | |
| 258 | exynos_crtc->mode = mode; |
| 259 | |
| 260 | switch (mode) { |
| 261 | case CRTC_MODE_NORMAL: |
| 262 | exynos_drm_crtc_commit(crtc); |
| 263 | break; |
| 264 | case CRTC_MODE_BLANK: |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 265 | exynos_plane_dpms(crtc->primary, DRM_MODE_DPMS_OFF); |
Joonyoung Shim | 3b8d1cf | 2012-06-27 14:27:11 +0900 | [diff] [blame] | 266 | break; |
| 267 | default: |
| 268 | break; |
| 269 | } |
| 270 | |
| 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | return -EINVAL; |
| 275 | } |
| 276 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 277 | static struct drm_crtc_funcs exynos_crtc_funcs = { |
| 278 | .set_config = drm_crtc_helper_set_config, |
| 279 | .page_flip = exynos_drm_crtc_page_flip, |
| 280 | .destroy = exynos_drm_crtc_destroy, |
Joonyoung Shim | 3b8d1cf | 2012-06-27 14:27:11 +0900 | [diff] [blame] | 281 | .set_property = exynos_drm_crtc_set_property, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 282 | }; |
| 283 | |
Joonyoung Shim | 3b8d1cf | 2012-06-27 14:27:11 +0900 | [diff] [blame] | 284 | static const struct drm_prop_enum_list mode_names[] = { |
| 285 | { CRTC_MODE_NORMAL, "normal" }, |
| 286 | { CRTC_MODE_BLANK, "blank" }, |
| 287 | }; |
| 288 | |
| 289 | static void exynos_drm_crtc_attach_mode_property(struct drm_crtc *crtc) |
| 290 | { |
| 291 | struct drm_device *dev = crtc->dev; |
| 292 | struct exynos_drm_private *dev_priv = dev->dev_private; |
| 293 | struct drm_property *prop; |
| 294 | |
Joonyoung Shim | 3b8d1cf | 2012-06-27 14:27:11 +0900 | [diff] [blame] | 295 | prop = dev_priv->crtc_mode_property; |
| 296 | if (!prop) { |
| 297 | prop = drm_property_create_enum(dev, 0, "mode", mode_names, |
| 298 | ARRAY_SIZE(mode_names)); |
| 299 | if (!prop) |
| 300 | return; |
| 301 | |
| 302 | dev_priv->crtc_mode_property = prop; |
| 303 | } |
| 304 | |
| 305 | drm_object_attach_property(&crtc->base, prop, 0); |
| 306 | } |
| 307 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 308 | int exynos_drm_crtc_create(struct exynos_drm_manager *manager) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 309 | { |
| 310 | struct exynos_drm_crtc *exynos_crtc; |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 311 | struct drm_plane *plane; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 312 | struct exynos_drm_private *private = manager->drm_dev->dev_private; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 313 | struct drm_crtc *crtc; |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 314 | int ret; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 315 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 316 | exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL); |
Sachin Kamat | 38bb525 | 2013-08-19 19:04:55 +0900 | [diff] [blame] | 317 | if (!exynos_crtc) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 318 | return -ENOMEM; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 319 | |
Inki Dae | 20cd264 | 2013-05-21 16:55:58 +0900 | [diff] [blame] | 320 | init_waitqueue_head(&exynos_crtc->pending_flip_queue); |
| 321 | atomic_set(&exynos_crtc->pending_flip, 0); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 322 | |
| 323 | exynos_crtc->dpms = DRM_MODE_DPMS_OFF; |
| 324 | exynos_crtc->manager = manager; |
| 325 | exynos_crtc->pipe = manager->pipe; |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 326 | plane = exynos_plane_init(manager->drm_dev, 1 << manager->pipe, |
| 327 | DRM_PLANE_TYPE_PRIMARY); |
| 328 | if (IS_ERR(plane)) { |
| 329 | ret = PTR_ERR(plane); |
| 330 | goto err_plane; |
Joonyoung Shim | b5d2eb3 | 2012-06-27 14:27:04 +0900 | [diff] [blame] | 331 | } |
| 332 | |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 333 | manager->crtc = &exynos_crtc->drm_crtc; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 334 | crtc = &exynos_crtc->drm_crtc; |
| 335 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 336 | private->crtc[manager->pipe] = crtc; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 337 | |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 338 | ret = drm_crtc_init_with_planes(manager->drm_dev, crtc, plane, NULL, |
| 339 | &exynos_crtc_funcs); |
| 340 | if (ret < 0) |
| 341 | goto err_crtc; |
| 342 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 343 | drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs); |
| 344 | |
Joonyoung Shim | 3b8d1cf | 2012-06-27 14:27:11 +0900 | [diff] [blame] | 345 | exynos_drm_crtc_attach_mode_property(crtc); |
| 346 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 347 | return 0; |
Andrzej Hajda | 72ed6cc | 2014-09-19 14:58:53 +0200 | [diff] [blame] | 348 | |
| 349 | err_crtc: |
| 350 | plane->funcs->destroy(plane); |
| 351 | err_plane: |
| 352 | kfree(exynos_crtc); |
| 353 | return ret; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 354 | } |
| 355 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 356 | int exynos_drm_crtc_enable_vblank(struct drm_device *dev, int pipe) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 357 | { |
| 358 | struct exynos_drm_private *private = dev->dev_private; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 359 | struct exynos_drm_crtc *exynos_crtc = |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 360 | to_exynos_crtc(private->crtc[pipe]); |
| 361 | struct exynos_drm_manager *manager = exynos_crtc->manager; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 362 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 363 | if (exynos_crtc->dpms != DRM_MODE_DPMS_ON) |
| 364 | return -EPERM; |
| 365 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 366 | if (manager->ops->enable_vblank) |
| 367 | manager->ops->enable_vblank(manager); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 372 | void exynos_drm_crtc_disable_vblank(struct drm_device *dev, int pipe) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 373 | { |
| 374 | struct exynos_drm_private *private = dev->dev_private; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 375 | struct exynos_drm_crtc *exynos_crtc = |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 376 | to_exynos_crtc(private->crtc[pipe]); |
| 377 | struct exynos_drm_manager *manager = exynos_crtc->manager; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 378 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 379 | if (exynos_crtc->dpms != DRM_MODE_DPMS_ON) |
| 380 | return; |
| 381 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 382 | if (manager->ops->disable_vblank) |
| 383 | manager->ops->disable_vblank(manager); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 384 | } |
Rahul Sharma | 663d876 | 2013-01-03 05:44:04 -0500 | [diff] [blame] | 385 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 386 | void exynos_drm_crtc_finish_pageflip(struct drm_device *dev, int pipe) |
Rahul Sharma | 663d876 | 2013-01-03 05:44:04 -0500 | [diff] [blame] | 387 | { |
| 388 | struct exynos_drm_private *dev_priv = dev->dev_private; |
| 389 | struct drm_pending_vblank_event *e, *t; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 390 | struct drm_crtc *drm_crtc = dev_priv->crtc[pipe]; |
Inki Dae | 20cd264 | 2013-05-21 16:55:58 +0900 | [diff] [blame] | 391 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(drm_crtc); |
Rahul Sharma | 663d876 | 2013-01-03 05:44:04 -0500 | [diff] [blame] | 392 | unsigned long flags; |
| 393 | |
Rahul Sharma | 663d876 | 2013-01-03 05:44:04 -0500 | [diff] [blame] | 394 | spin_lock_irqsave(&dev->event_lock, flags); |
| 395 | |
| 396 | list_for_each_entry_safe(e, t, &dev_priv->pageflip_event_list, |
| 397 | base.link) { |
| 398 | /* if event's pipe isn't same as crtc then ignore it. */ |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 399 | if (pipe != e->pipe) |
Rahul Sharma | 663d876 | 2013-01-03 05:44:04 -0500 | [diff] [blame] | 400 | continue; |
| 401 | |
Rob Clark | c5cca97 | 2013-05-22 11:48:40 +0900 | [diff] [blame] | 402 | list_del(&e->base.link); |
| 403 | drm_send_vblank_event(dev, -1, e); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 404 | drm_vblank_put(dev, pipe); |
Inki Dae | 20cd264 | 2013-05-21 16:55:58 +0900 | [diff] [blame] | 405 | atomic_set(&exynos_crtc->pending_flip, 0); |
| 406 | wake_up(&exynos_crtc->pending_flip_queue); |
Rahul Sharma | 663d876 | 2013-01-03 05:44:04 -0500 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 410 | } |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 411 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 412 | void exynos_drm_crtc_complete_scanout(struct drm_framebuffer *fb) |
| 413 | { |
| 414 | struct exynos_drm_manager *manager; |
| 415 | struct drm_device *dev = fb->dev; |
| 416 | struct drm_crtc *crtc; |
| 417 | |
| 418 | /* |
| 419 | * make sure that overlay data are updated to real hardware |
| 420 | * for all encoders. |
| 421 | */ |
| 422 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 423 | manager = to_exynos_crtc(crtc)->manager; |
| 424 | |
| 425 | /* |
| 426 | * wait for vblank interrupt |
| 427 | * - this makes sure that overlay data are updated to |
| 428 | * real hardware. |
| 429 | */ |
| 430 | if (manager->ops->wait_for_vblank) |
| 431 | manager->ops->wait_for_vblank(manager); |
| 432 | } |
| 433 | } |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 434 | |
| 435 | int exynos_drm_crtc_get_pipe_from_type(struct drm_device *drm_dev, |
| 436 | unsigned int out_type) |
| 437 | { |
| 438 | struct drm_crtc *crtc; |
| 439 | |
| 440 | list_for_each_entry(crtc, &drm_dev->mode_config.crtc_list, head) { |
| 441 | struct exynos_drm_crtc *exynos_crtc; |
| 442 | |
| 443 | exynos_crtc = to_exynos_crtc(crtc); |
| 444 | if (exynos_crtc->manager->type == out_type) |
| 445 | return exynos_crtc->manager->pipe; |
| 446 | } |
| 447 | |
| 448 | return -EPERM; |
| 449 | } |
YoungJun Cho | 5595d4d | 2014-07-17 18:01:19 +0900 | [diff] [blame] | 450 | |
| 451 | void exynos_drm_crtc_te_handler(struct drm_crtc *crtc) |
| 452 | { |
| 453 | struct exynos_drm_manager *manager = to_exynos_crtc(crtc)->manager; |
| 454 | |
| 455 | if (manager->ops->te_handler) |
| 456 | manager->ops->te_handler(manager); |
| 457 | } |