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 | |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 32 | #include "exynos_drm_crtc.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 33 | #include "exynos_drm_drv.h" |
| 34 | #include "exynos_drm_fb.h" |
| 35 | #include "exynos_drm_encoder.h" |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 36 | #include "exynos_drm_gem.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 37 | |
| 38 | #define to_exynos_crtc(x) container_of(x, struct exynos_drm_crtc,\ |
| 39 | drm_crtc) |
| 40 | |
| 41 | /* |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 42 | * Exynos specific crtc structure. |
| 43 | * |
| 44 | * @drm_crtc: crtc object. |
| 45 | * @overlay: contain information common to display controller and hdmi and |
| 46 | * contents of this overlay object would be copied to sub driver size. |
| 47 | * @pipe: a crtc index created at load() with a new crtc object creation |
| 48 | * and the crtc object would be set to private->crtc array |
| 49 | * to get a crtc object corresponding to this pipe from private->crtc |
| 50 | * array when irq interrupt occured. the reason of using this pipe is that |
| 51 | * drm framework doesn't support multiple irq yet. |
| 52 | * we can refer to the crtc to current hardware interrupt occured through |
| 53 | * this pipe value. |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 54 | * @dpms: store the crtc dpms value |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 55 | */ |
| 56 | struct exynos_drm_crtc { |
| 57 | struct drm_crtc drm_crtc; |
| 58 | struct exynos_drm_overlay overlay; |
| 59 | unsigned int pipe; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 60 | unsigned int dpms; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 61 | }; |
| 62 | |
Inki Dae | 8e9cc6a | 2011-10-14 13:29:47 +0900 | [diff] [blame] | 63 | static void exynos_drm_crtc_apply(struct drm_crtc *crtc) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 64 | { |
| 65 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 66 | struct exynos_drm_overlay *overlay = &exynos_crtc->overlay; |
| 67 | |
| 68 | exynos_drm_fn_encoder(crtc, overlay, |
| 69 | exynos_drm_encoder_crtc_mode_set); |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 70 | exynos_drm_fn_encoder(crtc, &exynos_crtc->pipe, |
| 71 | exynos_drm_encoder_crtc_commit); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 72 | } |
| 73 | |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 74 | int exynos_drm_overlay_update(struct exynos_drm_overlay *overlay, |
| 75 | struct drm_framebuffer *fb, |
| 76 | struct drm_display_mode *mode, |
| 77 | struct exynos_drm_crtc_pos *pos) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 78 | { |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 79 | struct exynos_drm_gem_buf *buffer; |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 80 | unsigned int actual_w; |
| 81 | unsigned int actual_h; |
Seung-Woo Kim | 229d353 | 2011-12-15 14:36:22 +0900 | [diff] [blame] | 82 | int nr = exynos_drm_format_num_buffers(fb->pixel_format); |
| 83 | int i; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 84 | |
Seung-Woo Kim | 229d353 | 2011-12-15 14:36:22 +0900 | [diff] [blame] | 85 | for (i = 0; i < nr; i++) { |
| 86 | buffer = exynos_drm_fb_buffer(fb, i); |
| 87 | if (!buffer) { |
| 88 | DRM_LOG_KMS("buffer is null\n"); |
| 89 | return -EFAULT; |
| 90 | } |
| 91 | |
| 92 | overlay->dma_addr[i] = buffer->dma_addr; |
| 93 | overlay->vaddr[i] = buffer->kvaddr; |
| 94 | |
| 95 | DRM_DEBUG_KMS("buffer: %d, vaddr = 0x%lx, dma_addr = 0x%lx\n", |
| 96 | i, (unsigned long)overlay->vaddr[i], |
| 97 | (unsigned long)overlay->dma_addr[i]); |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 98 | } |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 99 | |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 100 | actual_w = min((mode->hdisplay - pos->crtc_x), pos->crtc_w); |
| 101 | actual_h = min((mode->vdisplay - pos->crtc_y), pos->crtc_h); |
| 102 | |
| 103 | /* set drm framebuffer data. */ |
| 104 | overlay->fb_x = pos->fb_x; |
| 105 | overlay->fb_y = pos->fb_y; |
| 106 | overlay->fb_width = fb->width; |
| 107 | overlay->fb_height = fb->height; |
Seung-Woo Kim | 0d8071ee | 2012-04-24 18:43:10 +0900 | [diff] [blame] | 108 | overlay->src_width = pos->src_w; |
| 109 | overlay->src_height = pos->src_h; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 110 | overlay->bpp = fb->bits_per_pixel; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 111 | overlay->pitch = fb->pitches[0]; |
Seung-Woo Kim | 229d353 | 2011-12-15 14:36:22 +0900 | [diff] [blame] | 112 | overlay->pixel_format = fb->pixel_format; |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 113 | |
| 114 | /* set overlay range to be displayed. */ |
| 115 | overlay->crtc_x = pos->crtc_x; |
| 116 | overlay->crtc_y = pos->crtc_y; |
| 117 | overlay->crtc_width = actual_w; |
| 118 | overlay->crtc_height = actual_h; |
| 119 | |
| 120 | /* set drm mode data. */ |
| 121 | overlay->mode_width = mode->hdisplay; |
| 122 | overlay->mode_height = mode->vdisplay; |
| 123 | overlay->refresh = mode->vrefresh; |
| 124 | overlay->scan_flag = mode->flags; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 125 | |
| 126 | DRM_DEBUG_KMS("overlay : offset_x/y(%d,%d), width/height(%d,%d)", |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 127 | overlay->crtc_x, overlay->crtc_y, |
| 128 | overlay->crtc_width, overlay->crtc_height); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 129 | |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 130 | return 0; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | static int exynos_drm_crtc_update(struct drm_crtc *crtc) |
| 134 | { |
| 135 | struct exynos_drm_crtc *exynos_crtc; |
| 136 | struct exynos_drm_overlay *overlay; |
| 137 | struct exynos_drm_crtc_pos pos; |
| 138 | struct drm_display_mode *mode = &crtc->mode; |
| 139 | struct drm_framebuffer *fb = crtc->fb; |
| 140 | |
| 141 | if (!mode || !fb) |
| 142 | return -EINVAL; |
| 143 | |
| 144 | exynos_crtc = to_exynos_crtc(crtc); |
| 145 | overlay = &exynos_crtc->overlay; |
| 146 | |
| 147 | memset(&pos, 0, sizeof(struct exynos_drm_crtc_pos)); |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 148 | |
| 149 | /* it means the offset of framebuffer to be displayed. */ |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 150 | pos.fb_x = crtc->x; |
| 151 | pos.fb_y = crtc->y; |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 152 | |
| 153 | /* OSD position to be displayed. */ |
| 154 | pos.crtc_x = 0; |
| 155 | pos.crtc_y = 0; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 156 | pos.crtc_w = fb->width - crtc->x; |
| 157 | pos.crtc_h = fb->height - crtc->y; |
Seung-Woo Kim | 0d8071ee | 2012-04-24 18:43:10 +0900 | [diff] [blame] | 158 | pos.src_w = pos.crtc_w; |
| 159 | pos.src_h = pos.crtc_h; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 160 | |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 161 | return exynos_drm_overlay_update(overlay, crtc->fb, mode, &pos); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | static void exynos_drm_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 165 | { |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 166 | struct drm_device *dev = crtc->dev; |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 167 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 168 | |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 169 | DRM_DEBUG_KMS("crtc[%d] mode[%d]\n", crtc->base.id, mode); |
| 170 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 171 | if (exynos_crtc->dpms == mode) { |
| 172 | DRM_DEBUG_KMS("desired dpms mode is same as previous one.\n"); |
| 173 | return; |
| 174 | } |
| 175 | |
| 176 | mutex_lock(&dev->struct_mutex); |
| 177 | |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 178 | switch (mode) { |
| 179 | case DRM_MODE_DPMS_ON: |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 180 | exynos_drm_fn_encoder(crtc, &mode, |
| 181 | exynos_drm_encoder_crtc_dpms); |
| 182 | exynos_crtc->dpms = mode; |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 183 | break; |
| 184 | case DRM_MODE_DPMS_STANDBY: |
| 185 | case DRM_MODE_DPMS_SUSPEND: |
| 186 | case DRM_MODE_DPMS_OFF: |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 187 | exynos_drm_fn_encoder(crtc, &mode, |
| 188 | exynos_drm_encoder_crtc_dpms); |
| 189 | exynos_crtc->dpms = mode; |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 190 | break; |
| 191 | default: |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 192 | DRM_ERROR("unspecified mode %d\n", mode); |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 193 | break; |
| 194 | } |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 195 | |
| 196 | mutex_unlock(&dev->struct_mutex); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static void exynos_drm_crtc_prepare(struct drm_crtc *crtc) |
| 200 | { |
| 201 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 202 | |
| 203 | /* drm framework doesn't check NULL. */ |
| 204 | } |
| 205 | |
| 206 | static void exynos_drm_crtc_commit(struct drm_crtc *crtc) |
| 207 | { |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 208 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 209 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 210 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 211 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 212 | /* |
| 213 | * when set_crtc is requested from user or at booting time, |
| 214 | * crtc->commit would be called without dpms call so if dpms is |
| 215 | * no power on then crtc->dpms should be called |
| 216 | * with DRM_MODE_DPMS_ON for the hardware power to be on. |
| 217 | */ |
| 218 | if (exynos_crtc->dpms != DRM_MODE_DPMS_ON) { |
| 219 | int mode = DRM_MODE_DPMS_ON; |
| 220 | |
| 221 | /* |
| 222 | * enable hardware(power on) to all encoders hdmi connected |
| 223 | * to current crtc. |
| 224 | */ |
| 225 | exynos_drm_crtc_dpms(crtc, mode); |
| 226 | /* |
| 227 | * enable dma to all encoders connected to current crtc and |
| 228 | * lcd panel. |
| 229 | */ |
| 230 | exynos_drm_fn_encoder(crtc, &mode, |
| 231 | exynos_drm_encoder_dpms_from_crtc); |
| 232 | } |
| 233 | |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 234 | exynos_drm_fn_encoder(crtc, &exynos_crtc->pipe, |
| 235 | exynos_drm_encoder_crtc_commit); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | static bool |
| 239 | exynos_drm_crtc_mode_fixup(struct drm_crtc *crtc, |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 240 | const struct drm_display_mode *mode, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 241 | struct drm_display_mode *adjusted_mode) |
| 242 | { |
| 243 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 244 | |
| 245 | /* drm framework doesn't check NULL */ |
| 246 | return true; |
| 247 | } |
| 248 | |
| 249 | static int |
| 250 | exynos_drm_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode, |
| 251 | struct drm_display_mode *adjusted_mode, int x, int y, |
| 252 | struct drm_framebuffer *old_fb) |
| 253 | { |
Joonyoung Shim | aeb2922 | 2012-06-27 14:27:01 +0900 | [diff] [blame^] | 254 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 255 | struct exynos_drm_overlay *overlay = &exynos_crtc->overlay; |
| 256 | int ret; |
| 257 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 258 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 259 | |
Inki Dae | 1de425b | 2012-03-16 18:47:04 +0900 | [diff] [blame] | 260 | /* |
| 261 | * copy the mode data adjusted by mode_fixup() into crtc->mode |
| 262 | * so that hardware can be seet to proper mode. |
| 263 | */ |
| 264 | memcpy(&crtc->mode, adjusted_mode, sizeof(*adjusted_mode)); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 265 | |
Joonyoung Shim | aeb2922 | 2012-06-27 14:27:01 +0900 | [diff] [blame^] | 266 | ret = exynos_drm_crtc_update(crtc); |
| 267 | if (ret) |
| 268 | return ret; |
| 269 | |
| 270 | exynos_drm_fn_encoder(crtc, overlay, exynos_drm_encoder_crtc_mode_set); |
| 271 | |
| 272 | return 0; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | static int exynos_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, |
| 276 | struct drm_framebuffer *old_fb) |
| 277 | { |
| 278 | int ret; |
| 279 | |
| 280 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 281 | |
| 282 | ret = exynos_drm_crtc_update(crtc); |
| 283 | if (ret) |
| 284 | return ret; |
| 285 | |
| 286 | exynos_drm_crtc_apply(crtc); |
| 287 | |
| 288 | return ret; |
| 289 | } |
| 290 | |
| 291 | static void exynos_drm_crtc_load_lut(struct drm_crtc *crtc) |
| 292 | { |
| 293 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 294 | /* drm framework doesn't check NULL */ |
| 295 | } |
| 296 | |
| 297 | static struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = { |
| 298 | .dpms = exynos_drm_crtc_dpms, |
| 299 | .prepare = exynos_drm_crtc_prepare, |
| 300 | .commit = exynos_drm_crtc_commit, |
| 301 | .mode_fixup = exynos_drm_crtc_mode_fixup, |
| 302 | .mode_set = exynos_drm_crtc_mode_set, |
| 303 | .mode_set_base = exynos_drm_crtc_mode_set_base, |
| 304 | .load_lut = exynos_drm_crtc_load_lut, |
| 305 | }; |
| 306 | |
| 307 | static int exynos_drm_crtc_page_flip(struct drm_crtc *crtc, |
| 308 | struct drm_framebuffer *fb, |
| 309 | struct drm_pending_vblank_event *event) |
| 310 | { |
| 311 | struct drm_device *dev = crtc->dev; |
| 312 | struct exynos_drm_private *dev_priv = dev->dev_private; |
| 313 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 314 | struct drm_framebuffer *old_fb = crtc->fb; |
| 315 | int ret = -EINVAL; |
| 316 | |
| 317 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 318 | |
| 319 | mutex_lock(&dev->struct_mutex); |
| 320 | |
Inki Dae | ccf4d88 | 2011-10-14 13:29:51 +0900 | [diff] [blame] | 321 | if (event) { |
| 322 | /* |
| 323 | * the pipe from user always is 0 so we can set pipe number |
| 324 | * of current owner to event. |
| 325 | */ |
| 326 | event->pipe = exynos_crtc->pipe; |
| 327 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 328 | ret = drm_vblank_get(dev, exynos_crtc->pipe); |
| 329 | if (ret) { |
| 330 | DRM_DEBUG("failed to acquire vblank counter\n"); |
Inki Dae | ccf4d88 | 2011-10-14 13:29:51 +0900 | [diff] [blame] | 331 | list_del(&event->base.link); |
| 332 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 333 | goto out; |
| 334 | } |
| 335 | |
Inki Dae | c5614ae | 2012-02-15 11:25:20 +0900 | [diff] [blame] | 336 | list_add_tail(&event->base.link, |
| 337 | &dev_priv->pageflip_event_list); |
| 338 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 339 | crtc->fb = fb; |
| 340 | ret = exynos_drm_crtc_update(crtc); |
| 341 | if (ret) { |
| 342 | crtc->fb = old_fb; |
| 343 | drm_vblank_put(dev, exynos_crtc->pipe); |
Inki Dae | ccf4d88 | 2011-10-14 13:29:51 +0900 | [diff] [blame] | 344 | list_del(&event->base.link); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 345 | |
| 346 | goto out; |
| 347 | } |
| 348 | |
Inki Dae | f6b9825 | 2011-10-14 13:29:50 +0900 | [diff] [blame] | 349 | /* |
| 350 | * the values related to a buffer of the drm framebuffer |
| 351 | * to be applied should be set at here. because these values |
Inki Dae | ccf4d88 | 2011-10-14 13:29:51 +0900 | [diff] [blame] | 352 | * first, are set to shadow registers and then to |
Inki Dae | f6b9825 | 2011-10-14 13:29:50 +0900 | [diff] [blame] | 353 | * real registers at vsync front porch period. |
| 354 | */ |
Inki Dae | 8e9cc6a | 2011-10-14 13:29:47 +0900 | [diff] [blame] | 355 | exynos_drm_crtc_apply(crtc); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 356 | } |
| 357 | out: |
| 358 | mutex_unlock(&dev->struct_mutex); |
| 359 | return ret; |
| 360 | } |
| 361 | |
| 362 | static void exynos_drm_crtc_destroy(struct drm_crtc *crtc) |
| 363 | { |
| 364 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 365 | struct exynos_drm_private *private = crtc->dev->dev_private; |
| 366 | |
| 367 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 368 | |
| 369 | private->crtc[exynos_crtc->pipe] = NULL; |
| 370 | |
| 371 | drm_crtc_cleanup(crtc); |
| 372 | kfree(exynos_crtc); |
| 373 | } |
| 374 | |
| 375 | static struct drm_crtc_funcs exynos_crtc_funcs = { |
| 376 | .set_config = drm_crtc_helper_set_config, |
| 377 | .page_flip = exynos_drm_crtc_page_flip, |
| 378 | .destroy = exynos_drm_crtc_destroy, |
| 379 | }; |
| 380 | |
| 381 | struct exynos_drm_overlay *get_exynos_drm_overlay(struct drm_device *dev, |
| 382 | struct drm_crtc *crtc) |
| 383 | { |
| 384 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
| 385 | |
| 386 | return &exynos_crtc->overlay; |
| 387 | } |
| 388 | |
| 389 | int exynos_drm_crtc_create(struct drm_device *dev, unsigned int nr) |
| 390 | { |
| 391 | struct exynos_drm_crtc *exynos_crtc; |
| 392 | struct exynos_drm_private *private = dev->dev_private; |
| 393 | struct drm_crtc *crtc; |
| 394 | |
| 395 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 396 | |
| 397 | exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL); |
| 398 | if (!exynos_crtc) { |
| 399 | DRM_ERROR("failed to allocate exynos crtc\n"); |
| 400 | return -ENOMEM; |
| 401 | } |
| 402 | |
| 403 | exynos_crtc->pipe = nr; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 404 | exynos_crtc->dpms = DRM_MODE_DPMS_OFF; |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 405 | exynos_crtc->overlay.zpos = DEFAULT_ZPOS; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 406 | crtc = &exynos_crtc->drm_crtc; |
| 407 | |
| 408 | private->crtc[nr] = crtc; |
| 409 | |
| 410 | drm_crtc_init(dev, crtc, &exynos_crtc_funcs); |
| 411 | drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs); |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | int exynos_drm_crtc_enable_vblank(struct drm_device *dev, int crtc) |
| 417 | { |
| 418 | struct exynos_drm_private *private = dev->dev_private; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 419 | struct exynos_drm_crtc *exynos_crtc = |
| 420 | to_exynos_crtc(private->crtc[crtc]); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 421 | |
| 422 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 423 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 424 | if (exynos_crtc->dpms != DRM_MODE_DPMS_ON) |
| 425 | return -EPERM; |
| 426 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 427 | exynos_drm_fn_encoder(private->crtc[crtc], &crtc, |
| 428 | exynos_drm_enable_vblank); |
| 429 | |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | void exynos_drm_crtc_disable_vblank(struct drm_device *dev, int crtc) |
| 434 | { |
| 435 | struct exynos_drm_private *private = dev->dev_private; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 436 | struct exynos_drm_crtc *exynos_crtc = |
| 437 | to_exynos_crtc(private->crtc[crtc]); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 438 | |
| 439 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 440 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 441 | if (exynos_crtc->dpms != DRM_MODE_DPMS_ON) |
| 442 | return; |
| 443 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 444 | exynos_drm_fn_encoder(private->crtc[crtc], &crtc, |
| 445 | exynos_drm_disable_vblank); |
| 446 | } |