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