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 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice (including the next |
| 17 | * paragraph) shall be included in all copies or substantial portions of the |
| 18 | * Software. |
| 19 | * |
| 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 23 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 24 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 25 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 26 | * OTHER DEALINGS IN THE SOFTWARE. |
| 27 | */ |
| 28 | |
| 29 | #include "drmP.h" |
| 30 | #include "drm_crtc_helper.h" |
| 31 | |
| 32 | #include "exynos_drm_drv.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 33 | #include "exynos_drm_encoder.h" |
Joonyoung Shim | b5d2eb3 | 2012-06-27 14:27:04 +0900 | [diff] [blame] | 34 | #include "exynos_drm_plane.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 35 | |
| 36 | #define to_exynos_crtc(x) container_of(x, struct exynos_drm_crtc,\ |
| 37 | drm_crtc) |
| 38 | |
Joonyoung Shim | 3b8d1cf | 2012-06-27 14:27:11 +0900 | [diff] [blame] | 39 | enum exynos_crtc_mode { |
| 40 | CRTC_MODE_NORMAL, /* normal mode */ |
| 41 | CRTC_MODE_BLANK, /* The private plane of crtc is blank */ |
| 42 | }; |
| 43 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 44 | /* |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 45 | * Exynos specific crtc structure. |
| 46 | * |
| 47 | * @drm_crtc: crtc object. |
Joonyoung Shim | b5d2eb3 | 2012-06-27 14:27:04 +0900 | [diff] [blame] | 48 | * @drm_plane: pointer of private plane object for this crtc |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 49 | * @pipe: a crtc index created at load() with a new crtc object creation |
| 50 | * and the crtc object would be set to private->crtc array |
| 51 | * to get a crtc object corresponding to this pipe from private->crtc |
| 52 | * array when irq interrupt occured. the reason of using this pipe is that |
| 53 | * drm framework doesn't support multiple irq yet. |
| 54 | * we can refer to the crtc to current hardware interrupt occured through |
| 55 | * this pipe value. |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 56 | * @dpms: store the crtc dpms value |
Joonyoung Shim | 3b8d1cf | 2012-06-27 14:27:11 +0900 | [diff] [blame] | 57 | * @mode: store the crtc mode value |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 58 | */ |
| 59 | struct exynos_drm_crtc { |
| 60 | struct drm_crtc drm_crtc; |
Joonyoung Shim | b5d2eb3 | 2012-06-27 14:27:04 +0900 | [diff] [blame] | 61 | struct drm_plane *plane; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 62 | unsigned int pipe; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 63 | unsigned int dpms; |
Joonyoung Shim | 3b8d1cf | 2012-06-27 14:27:11 +0900 | [diff] [blame] | 64 | enum exynos_crtc_mode mode; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 65 | }; |
| 66 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 67 | static void exynos_drm_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 68 | { |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 69 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 70 | |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 71 | DRM_DEBUG_KMS("crtc[%d] mode[%d]\n", crtc->base.id, mode); |
| 72 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 73 | if (exynos_crtc->dpms == mode) { |
| 74 | DRM_DEBUG_KMS("desired dpms mode is same as previous one.\n"); |
| 75 | return; |
| 76 | } |
| 77 | |
Joonyoung Shim | cf5188a | 2012-06-27 14:27:09 +0900 | [diff] [blame] | 78 | exynos_drm_fn_encoder(crtc, &mode, exynos_drm_encoder_crtc_dpms); |
| 79 | exynos_crtc->dpms = mode; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static void exynos_drm_crtc_prepare(struct drm_crtc *crtc) |
| 83 | { |
| 84 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 85 | |
| 86 | /* drm framework doesn't check NULL. */ |
| 87 | } |
| 88 | |
| 89 | static void exynos_drm_crtc_commit(struct drm_crtc *crtc) |
| 90 | { |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 91 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 92 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 93 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 94 | |
Inki Dae | 50caf25 | 2012-08-20 21:29:25 +0900 | [diff] [blame] | 95 | exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_ON); |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 96 | exynos_plane_commit(exynos_crtc->plane); |
Joonyoung Shim | cf5188a | 2012-06-27 14:27:09 +0900 | [diff] [blame] | 97 | exynos_plane_dpms(exynos_crtc->plane, DRM_MODE_DPMS_ON); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static bool |
| 101 | exynos_drm_crtc_mode_fixup(struct drm_crtc *crtc, |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 102 | const struct drm_display_mode *mode, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 103 | struct drm_display_mode *adjusted_mode) |
| 104 | { |
| 105 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 106 | |
| 107 | /* drm framework doesn't check NULL */ |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | static int |
| 112 | exynos_drm_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode, |
| 113 | struct drm_display_mode *adjusted_mode, int x, int y, |
| 114 | struct drm_framebuffer *old_fb) |
| 115 | { |
Joonyoung Shim | aeb2922 | 2012-06-27 14:27:01 +0900 | [diff] [blame] | 116 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 117 | struct drm_plane *plane = exynos_crtc->plane; |
| 118 | unsigned int crtc_w; |
| 119 | unsigned int crtc_h; |
Joonyoung Shim | d249ce0 | 2012-06-27 14:27:02 +0900 | [diff] [blame] | 120 | int pipe = exynos_crtc->pipe; |
Joonyoung Shim | aeb2922 | 2012-06-27 14:27:01 +0900 | [diff] [blame] | 121 | int ret; |
| 122 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 123 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 124 | |
Inki Dae | 1de425b | 2012-03-16 18:47:04 +0900 | [diff] [blame] | 125 | /* |
| 126 | * copy the mode data adjusted by mode_fixup() into crtc->mode |
| 127 | * so that hardware can be seet to proper mode. |
| 128 | */ |
| 129 | memcpy(&crtc->mode, adjusted_mode, sizeof(*adjusted_mode)); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 130 | |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 131 | crtc_w = crtc->fb->width - x; |
| 132 | crtc_h = crtc->fb->height - y; |
| 133 | |
| 134 | ret = exynos_plane_mode_set(plane, crtc, crtc->fb, 0, 0, crtc_w, crtc_h, |
| 135 | x, y, crtc_w, crtc_h); |
Joonyoung Shim | aeb2922 | 2012-06-27 14:27:01 +0900 | [diff] [blame] | 136 | if (ret) |
| 137 | return ret; |
| 138 | |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 139 | plane->crtc = crtc; |
| 140 | plane->fb = crtc->fb; |
| 141 | |
Joonyoung Shim | d249ce0 | 2012-06-27 14:27:02 +0900 | [diff] [blame] | 142 | exynos_drm_fn_encoder(crtc, &pipe, exynos_drm_encoder_crtc_pipe); |
Joonyoung Shim | aeb2922 | 2012-06-27 14:27:01 +0900 | [diff] [blame] | 143 | |
| 144 | return 0; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static int exynos_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, |
| 148 | struct drm_framebuffer *old_fb) |
| 149 | { |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 150 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 151 | struct drm_plane *plane = exynos_crtc->plane; |
| 152 | unsigned int crtc_w; |
| 153 | unsigned int crtc_h; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 154 | int ret; |
| 155 | |
| 156 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 157 | |
Inki Dae | 32aeab1 | 2012-09-14 13:29:47 +0900 | [diff] [blame^] | 158 | /* when framebuffer changing is requested, crtc's dpms should be on */ |
| 159 | if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) { |
| 160 | DRM_ERROR("failed framebuffer changing request.\n"); |
| 161 | return -EPERM; |
| 162 | } |
| 163 | |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 164 | crtc_w = crtc->fb->width - x; |
| 165 | crtc_h = crtc->fb->height - y; |
| 166 | |
| 167 | ret = exynos_plane_mode_set(plane, crtc, crtc->fb, 0, 0, crtc_w, crtc_h, |
| 168 | x, y, crtc_w, crtc_h); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 169 | if (ret) |
| 170 | return ret; |
| 171 | |
Joonyoung Shim | bebab8f | 2012-06-27 14:27:07 +0900 | [diff] [blame] | 172 | exynos_drm_crtc_commit(crtc); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 173 | |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 174 | return 0; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static void exynos_drm_crtc_load_lut(struct drm_crtc *crtc) |
| 178 | { |
| 179 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 180 | /* drm framework doesn't check NULL */ |
| 181 | } |
| 182 | |
Joonyoung Shim | a365d9e | 2012-06-27 14:27:10 +0900 | [diff] [blame] | 183 | static void exynos_drm_crtc_disable(struct drm_crtc *crtc) |
| 184 | { |
| 185 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 186 | |
| 187 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 188 | |
| 189 | exynos_plane_dpms(exynos_crtc->plane, DRM_MODE_DPMS_OFF); |
| 190 | exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
| 191 | } |
| 192 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 193 | static struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = { |
| 194 | .dpms = exynos_drm_crtc_dpms, |
| 195 | .prepare = exynos_drm_crtc_prepare, |
| 196 | .commit = exynos_drm_crtc_commit, |
| 197 | .mode_fixup = exynos_drm_crtc_mode_fixup, |
| 198 | .mode_set = exynos_drm_crtc_mode_set, |
| 199 | .mode_set_base = exynos_drm_crtc_mode_set_base, |
| 200 | .load_lut = exynos_drm_crtc_load_lut, |
Joonyoung Shim | a365d9e | 2012-06-27 14:27:10 +0900 | [diff] [blame] | 201 | .disable = exynos_drm_crtc_disable, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | static int exynos_drm_crtc_page_flip(struct drm_crtc *crtc, |
| 205 | struct drm_framebuffer *fb, |
| 206 | struct drm_pending_vblank_event *event) |
| 207 | { |
| 208 | struct drm_device *dev = crtc->dev; |
| 209 | struct exynos_drm_private *dev_priv = dev->dev_private; |
| 210 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 211 | struct drm_framebuffer *old_fb = crtc->fb; |
| 212 | int ret = -EINVAL; |
| 213 | |
| 214 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 215 | |
Inki Dae | ef6223d | 2012-09-11 18:25:21 +0900 | [diff] [blame] | 216 | /* when the page flip is requested, crtc's dpms should be on */ |
| 217 | if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) { |
| 218 | DRM_ERROR("failed page flip request.\n"); |
| 219 | return -EINVAL; |
| 220 | } |
| 221 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 222 | mutex_lock(&dev->struct_mutex); |
| 223 | |
Inki Dae | ccf4d88 | 2011-10-14 13:29:51 +0900 | [diff] [blame] | 224 | if (event) { |
| 225 | /* |
| 226 | * the pipe from user always is 0 so we can set pipe number |
| 227 | * of current owner to event. |
| 228 | */ |
| 229 | event->pipe = exynos_crtc->pipe; |
| 230 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 231 | ret = drm_vblank_get(dev, exynos_crtc->pipe); |
| 232 | if (ret) { |
| 233 | DRM_DEBUG("failed to acquire vblank counter\n"); |
Inki Dae | ccf4d88 | 2011-10-14 13:29:51 +0900 | [diff] [blame] | 234 | list_del(&event->base.link); |
| 235 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 236 | goto out; |
| 237 | } |
| 238 | |
Inki Dae | c5614ae | 2012-02-15 11:25:20 +0900 | [diff] [blame] | 239 | list_add_tail(&event->base.link, |
| 240 | &dev_priv->pageflip_event_list); |
| 241 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 242 | crtc->fb = fb; |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 243 | ret = exynos_drm_crtc_mode_set_base(crtc, crtc->x, crtc->y, |
| 244 | NULL); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 245 | if (ret) { |
| 246 | crtc->fb = old_fb; |
| 247 | drm_vblank_put(dev, exynos_crtc->pipe); |
Inki Dae | ccf4d88 | 2011-10-14 13:29:51 +0900 | [diff] [blame] | 248 | list_del(&event->base.link); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 249 | |
| 250 | goto out; |
| 251 | } |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 252 | } |
| 253 | out: |
| 254 | mutex_unlock(&dev->struct_mutex); |
| 255 | return ret; |
| 256 | } |
| 257 | |
| 258 | static void exynos_drm_crtc_destroy(struct drm_crtc *crtc) |
| 259 | { |
| 260 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 261 | struct exynos_drm_private *private = crtc->dev->dev_private; |
| 262 | |
| 263 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 264 | |
| 265 | private->crtc[exynos_crtc->pipe] = NULL; |
| 266 | |
| 267 | drm_crtc_cleanup(crtc); |
| 268 | kfree(exynos_crtc); |
| 269 | } |
| 270 | |
Joonyoung Shim | 3b8d1cf | 2012-06-27 14:27:11 +0900 | [diff] [blame] | 271 | static int exynos_drm_crtc_set_property(struct drm_crtc *crtc, |
| 272 | struct drm_property *property, |
| 273 | uint64_t val) |
| 274 | { |
| 275 | struct drm_device *dev = crtc->dev; |
| 276 | struct exynos_drm_private *dev_priv = dev->dev_private; |
| 277 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 278 | |
| 279 | DRM_DEBUG_KMS("%s\n", __func__); |
| 280 | |
| 281 | if (property == dev_priv->crtc_mode_property) { |
| 282 | enum exynos_crtc_mode mode = val; |
| 283 | |
| 284 | if (mode == exynos_crtc->mode) |
| 285 | return 0; |
| 286 | |
| 287 | exynos_crtc->mode = mode; |
| 288 | |
| 289 | switch (mode) { |
| 290 | case CRTC_MODE_NORMAL: |
| 291 | exynos_drm_crtc_commit(crtc); |
| 292 | break; |
| 293 | case CRTC_MODE_BLANK: |
| 294 | exynos_plane_dpms(exynos_crtc->plane, |
| 295 | DRM_MODE_DPMS_OFF); |
| 296 | break; |
| 297 | default: |
| 298 | break; |
| 299 | } |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | return -EINVAL; |
| 305 | } |
| 306 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 307 | static struct drm_crtc_funcs exynos_crtc_funcs = { |
| 308 | .set_config = drm_crtc_helper_set_config, |
| 309 | .page_flip = exynos_drm_crtc_page_flip, |
| 310 | .destroy = exynos_drm_crtc_destroy, |
Joonyoung Shim | 3b8d1cf | 2012-06-27 14:27:11 +0900 | [diff] [blame] | 311 | .set_property = exynos_drm_crtc_set_property, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 312 | }; |
| 313 | |
Joonyoung Shim | 3b8d1cf | 2012-06-27 14:27:11 +0900 | [diff] [blame] | 314 | static const struct drm_prop_enum_list mode_names[] = { |
| 315 | { CRTC_MODE_NORMAL, "normal" }, |
| 316 | { CRTC_MODE_BLANK, "blank" }, |
| 317 | }; |
| 318 | |
| 319 | static void exynos_drm_crtc_attach_mode_property(struct drm_crtc *crtc) |
| 320 | { |
| 321 | struct drm_device *dev = crtc->dev; |
| 322 | struct exynos_drm_private *dev_priv = dev->dev_private; |
| 323 | struct drm_property *prop; |
| 324 | |
| 325 | DRM_DEBUG_KMS("%s\n", __func__); |
| 326 | |
| 327 | prop = dev_priv->crtc_mode_property; |
| 328 | if (!prop) { |
| 329 | prop = drm_property_create_enum(dev, 0, "mode", mode_names, |
| 330 | ARRAY_SIZE(mode_names)); |
| 331 | if (!prop) |
| 332 | return; |
| 333 | |
| 334 | dev_priv->crtc_mode_property = prop; |
| 335 | } |
| 336 | |
| 337 | drm_object_attach_property(&crtc->base, prop, 0); |
| 338 | } |
| 339 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 340 | int exynos_drm_crtc_create(struct drm_device *dev, unsigned int nr) |
| 341 | { |
| 342 | struct exynos_drm_crtc *exynos_crtc; |
| 343 | struct exynos_drm_private *private = dev->dev_private; |
| 344 | struct drm_crtc *crtc; |
| 345 | |
| 346 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 347 | |
| 348 | exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL); |
| 349 | if (!exynos_crtc) { |
| 350 | DRM_ERROR("failed to allocate exynos crtc\n"); |
| 351 | return -ENOMEM; |
| 352 | } |
| 353 | |
| 354 | exynos_crtc->pipe = nr; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 355 | exynos_crtc->dpms = DRM_MODE_DPMS_OFF; |
Joonyoung Shim | b5d2eb3 | 2012-06-27 14:27:04 +0900 | [diff] [blame] | 356 | exynos_crtc->plane = exynos_plane_init(dev, 1 << nr, true); |
| 357 | if (!exynos_crtc->plane) { |
| 358 | kfree(exynos_crtc); |
| 359 | return -ENOMEM; |
| 360 | } |
| 361 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 362 | crtc = &exynos_crtc->drm_crtc; |
| 363 | |
| 364 | private->crtc[nr] = crtc; |
| 365 | |
| 366 | drm_crtc_init(dev, crtc, &exynos_crtc_funcs); |
| 367 | drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs); |
| 368 | |
Joonyoung Shim | 3b8d1cf | 2012-06-27 14:27:11 +0900 | [diff] [blame] | 369 | exynos_drm_crtc_attach_mode_property(crtc); |
| 370 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | int exynos_drm_crtc_enable_vblank(struct drm_device *dev, int crtc) |
| 375 | { |
| 376 | struct exynos_drm_private *private = dev->dev_private; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 377 | struct exynos_drm_crtc *exynos_crtc = |
| 378 | to_exynos_crtc(private->crtc[crtc]); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 379 | |
| 380 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 381 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 382 | if (exynos_crtc->dpms != DRM_MODE_DPMS_ON) |
| 383 | return -EPERM; |
| 384 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 385 | exynos_drm_fn_encoder(private->crtc[crtc], &crtc, |
| 386 | exynos_drm_enable_vblank); |
| 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | void exynos_drm_crtc_disable_vblank(struct drm_device *dev, int crtc) |
| 392 | { |
| 393 | struct exynos_drm_private *private = dev->dev_private; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 394 | struct exynos_drm_crtc *exynos_crtc = |
| 395 | to_exynos_crtc(private->crtc[crtc]); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 396 | |
| 397 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 398 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 399 | if (exynos_crtc->dpms != DRM_MODE_DPMS_ON) |
| 400 | return; |
| 401 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 402 | exynos_drm_fn_encoder(private->crtc[crtc], &crtc, |
| 403 | exynos_drm_disable_vblank); |
| 404 | } |