Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1 | /* exynos_drm_encoder.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 | |
| 18 | #include "exynos_drm_drv.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 19 | #include "exynos_drm_encoder.h" |
Inki Dae | 50caf25 | 2012-08-20 21:29:25 +0900 | [diff] [blame] | 20 | #include "exynos_drm_connector.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 21 | |
| 22 | #define to_exynos_encoder(x) container_of(x, struct exynos_drm_encoder,\ |
| 23 | drm_encoder) |
| 24 | |
| 25 | /* |
| 26 | * exynos specific encoder structure. |
| 27 | * |
| 28 | * @drm_encoder: encoder object. |
| 29 | * @manager: specific encoder has its own manager to control a hardware |
| 30 | * appropriately and we can access a hardware drawing on this manager. |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 31 | * @dpms: store the encoder dpms value. |
Inki Dae | 44c9169 | 2012-10-18 18:59:55 +0900 | [diff] [blame] | 32 | * @updated: indicate whether overlay data updating is needed or not. |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 33 | */ |
| 34 | struct exynos_drm_encoder { |
Inki Dae | 1b85a07 | 2012-08-17 17:58:38 +0900 | [diff] [blame] | 35 | struct drm_crtc *old_crtc; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 36 | struct drm_encoder drm_encoder; |
| 37 | struct exynos_drm_manager *manager; |
Inki Dae | 44c9169 | 2012-10-18 18:59:55 +0900 | [diff] [blame] | 38 | int dpms; |
| 39 | bool updated; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 40 | }; |
| 41 | |
Inki Dae | 50caf25 | 2012-08-20 21:29:25 +0900 | [diff] [blame] | 42 | static void exynos_drm_connector_power(struct drm_encoder *encoder, int mode) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 43 | { |
| 44 | struct drm_device *dev = encoder->dev; |
| 45 | struct drm_connector *connector; |
Joonyoung Shim | 396464d | 2011-11-14 15:20:49 +0900 | [diff] [blame] | 46 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 47 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Inki Dae | 58f6aad | 2012-09-24 20:04:24 +0900 | [diff] [blame] | 48 | if (exynos_drm_best_encoder(connector) == encoder) { |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 49 | DRM_DEBUG_KMS("connector[%d] dpms[%d]\n", |
| 50 | connector->base.id, mode); |
Inki Dae | 50caf25 | 2012-08-20 21:29:25 +0900 | [diff] [blame] | 51 | |
| 52 | exynos_drm_display_power(connector, mode); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 57 | static void exynos_drm_encoder_dpms(struct drm_encoder *encoder, int mode) |
| 58 | { |
| 59 | struct drm_device *dev = encoder->dev; |
| 60 | struct exynos_drm_manager *manager = exynos_drm_get_manager(encoder); |
| 61 | struct exynos_drm_manager_ops *manager_ops = manager->ops; |
| 62 | struct exynos_drm_encoder *exynos_encoder = to_exynos_encoder(encoder); |
| 63 | |
YoungJun Cho | bca34c9 | 2013-06-12 10:40:52 +0900 | [diff] [blame] | 64 | DRM_DEBUG_KMS("encoder dpms: %d\n", mode); |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 65 | |
| 66 | if (exynos_encoder->dpms == mode) { |
| 67 | DRM_DEBUG_KMS("desired dpms mode is same as previous one.\n"); |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | mutex_lock(&dev->struct_mutex); |
| 72 | |
| 73 | switch (mode) { |
| 74 | case DRM_MODE_DPMS_ON: |
| 75 | if (manager_ops && manager_ops->apply) |
Inki Dae | 44c9169 | 2012-10-18 18:59:55 +0900 | [diff] [blame] | 76 | if (!exynos_encoder->updated) |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 77 | manager_ops->apply(manager); |
Inki Dae | 44c9169 | 2012-10-18 18:59:55 +0900 | [diff] [blame] | 78 | |
Inki Dae | 50caf25 | 2012-08-20 21:29:25 +0900 | [diff] [blame] | 79 | exynos_drm_connector_power(encoder, mode); |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 80 | exynos_encoder->dpms = mode; |
| 81 | break; |
| 82 | case DRM_MODE_DPMS_STANDBY: |
| 83 | case DRM_MODE_DPMS_SUSPEND: |
| 84 | case DRM_MODE_DPMS_OFF: |
Inki Dae | 50caf25 | 2012-08-20 21:29:25 +0900 | [diff] [blame] | 85 | exynos_drm_connector_power(encoder, mode); |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 86 | exynos_encoder->dpms = mode; |
Inki Dae | 44c9169 | 2012-10-18 18:59:55 +0900 | [diff] [blame] | 87 | exynos_encoder->updated = false; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 88 | break; |
| 89 | default: |
| 90 | DRM_ERROR("unspecified mode %d\n", mode); |
| 91 | break; |
| 92 | } |
| 93 | |
| 94 | mutex_unlock(&dev->struct_mutex); |
| 95 | } |
| 96 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 97 | static bool |
| 98 | exynos_drm_encoder_mode_fixup(struct drm_encoder *encoder, |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 99 | const struct drm_display_mode *mode, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 100 | struct drm_display_mode *adjusted_mode) |
| 101 | { |
Inki Dae | 1de425b | 2012-03-16 18:47:04 +0900 | [diff] [blame] | 102 | struct drm_device *dev = encoder->dev; |
| 103 | struct drm_connector *connector; |
| 104 | struct exynos_drm_manager *manager = exynos_drm_get_manager(encoder); |
| 105 | struct exynos_drm_manager_ops *manager_ops = manager->ops; |
| 106 | |
Inki Dae | 1de425b | 2012-03-16 18:47:04 +0900 | [diff] [blame] | 107 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 108 | if (connector->encoder == encoder) |
| 109 | if (manager_ops && manager_ops->mode_fixup) |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 110 | manager_ops->mode_fixup(manager, connector, |
Inki Dae | 1de425b | 2012-03-16 18:47:04 +0900 | [diff] [blame] | 111 | mode, adjusted_mode); |
| 112 | } |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 113 | |
| 114 | return true; |
| 115 | } |
| 116 | |
Inki Dae | 1b85a07 | 2012-08-17 17:58:38 +0900 | [diff] [blame] | 117 | static void disable_plane_to_crtc(struct drm_device *dev, |
| 118 | struct drm_crtc *old_crtc, |
| 119 | struct drm_crtc *new_crtc) |
| 120 | { |
| 121 | struct drm_plane *plane; |
| 122 | |
| 123 | /* |
| 124 | * if old_crtc isn't same as encoder->crtc then it means that |
| 125 | * user changed crtc id to another one so the plane to old_crtc |
| 126 | * should be disabled and plane->crtc should be set to new_crtc |
| 127 | * (encoder->crtc) |
| 128 | */ |
| 129 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 130 | if (plane->crtc == old_crtc) { |
| 131 | /* |
| 132 | * do not change below call order. |
| 133 | * |
| 134 | * plane->funcs->disable_plane call checks |
| 135 | * if encoder->crtc is same as plane->crtc and if same |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 136 | * then manager_ops->win_disable callback will be called |
Inki Dae | 1b85a07 | 2012-08-17 17:58:38 +0900 | [diff] [blame] | 137 | * to diasble current hw overlay so plane->crtc should |
| 138 | * have new_crtc because new_crtc was set to |
| 139 | * encoder->crtc in advance. |
| 140 | */ |
| 141 | plane->crtc = new_crtc; |
| 142 | plane->funcs->disable_plane(plane); |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 147 | static void exynos_drm_encoder_mode_set(struct drm_encoder *encoder, |
| 148 | struct drm_display_mode *mode, |
| 149 | struct drm_display_mode *adjusted_mode) |
| 150 | { |
| 151 | struct drm_device *dev = encoder->dev; |
| 152 | struct drm_connector *connector; |
Inki Dae | 1b85a07 | 2012-08-17 17:58:38 +0900 | [diff] [blame] | 153 | struct exynos_drm_manager *manager; |
| 154 | struct exynos_drm_manager_ops *manager_ops; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 155 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 156 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Inki Dae | 1b85a07 | 2012-08-17 17:58:38 +0900 | [diff] [blame] | 157 | if (connector->encoder == encoder) { |
| 158 | struct exynos_drm_encoder *exynos_encoder; |
| 159 | |
| 160 | exynos_encoder = to_exynos_encoder(encoder); |
| 161 | |
| 162 | if (exynos_encoder->old_crtc != encoder->crtc && |
| 163 | exynos_encoder->old_crtc) { |
| 164 | |
| 165 | /* |
| 166 | * disable a plane to old crtc and change |
| 167 | * crtc of the plane to new one. |
| 168 | */ |
| 169 | disable_plane_to_crtc(dev, |
| 170 | exynos_encoder->old_crtc, |
| 171 | encoder->crtc); |
| 172 | } |
| 173 | |
| 174 | manager = exynos_drm_get_manager(encoder); |
| 175 | manager_ops = manager->ops; |
| 176 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 177 | if (manager_ops && manager_ops->mode_set) |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 178 | manager_ops->mode_set(manager, adjusted_mode); |
Inki Dae | 1b85a07 | 2012-08-17 17:58:38 +0900 | [diff] [blame] | 179 | |
| 180 | exynos_encoder->old_crtc = encoder->crtc; |
| 181 | } |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
| 185 | static void exynos_drm_encoder_prepare(struct drm_encoder *encoder) |
| 186 | { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 187 | /* drm framework doesn't check NULL. */ |
| 188 | } |
| 189 | |
| 190 | static void exynos_drm_encoder_commit(struct drm_encoder *encoder) |
| 191 | { |
Inki Dae | 44c9169 | 2012-10-18 18:59:55 +0900 | [diff] [blame] | 192 | struct exynos_drm_encoder *exynos_encoder = to_exynos_encoder(encoder); |
| 193 | struct exynos_drm_manager *manager = exynos_encoder->manager; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 194 | struct exynos_drm_manager_ops *manager_ops = manager->ops; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 195 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 196 | if (manager_ops && manager_ops->commit) |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 197 | manager_ops->commit(manager); |
Inki Dae | 44c9169 | 2012-10-18 18:59:55 +0900 | [diff] [blame] | 198 | |
| 199 | /* |
| 200 | * this will avoid one issue that overlay data is updated to |
| 201 | * real hardware two times. |
| 202 | * And this variable will be used to check if the data was |
| 203 | * already updated or not by exynos_drm_encoder_dpms function. |
| 204 | */ |
| 205 | exynos_encoder->updated = true; |
Inki Dae | 8e8755d | 2012-11-14 20:41:35 +0900 | [diff] [blame] | 206 | |
| 207 | /* |
| 208 | * In case of setcrtc, there is no way to update encoder's dpms |
| 209 | * so update it here. |
| 210 | */ |
| 211 | exynos_encoder->dpms = DRM_MODE_DPMS_ON; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 212 | } |
| 213 | |
Inki Dae | 1daa892 | 2012-11-22 17:41:23 +0900 | [diff] [blame] | 214 | void exynos_drm_encoder_complete_scanout(struct drm_framebuffer *fb) |
| 215 | { |
| 216 | struct exynos_drm_encoder *exynos_encoder; |
Prathyush K | f74085a | 2012-12-06 20:16:00 +0530 | [diff] [blame] | 217 | struct exynos_drm_manager_ops *ops; |
Inki Dae | 1daa892 | 2012-11-22 17:41:23 +0900 | [diff] [blame] | 218 | struct drm_device *dev = fb->dev; |
| 219 | struct drm_encoder *encoder; |
| 220 | |
| 221 | /* |
| 222 | * make sure that overlay data are updated to real hardware |
| 223 | * for all encoders. |
| 224 | */ |
| 225 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 226 | exynos_encoder = to_exynos_encoder(encoder); |
Prathyush K | f74085a | 2012-12-06 20:16:00 +0530 | [diff] [blame] | 227 | ops = exynos_encoder->manager->ops; |
Inki Dae | 1daa892 | 2012-11-22 17:41:23 +0900 | [diff] [blame] | 228 | |
| 229 | /* |
| 230 | * wait for vblank interrupt |
| 231 | * - this makes sure that overlay data are updated to |
| 232 | * real hardware. |
| 233 | */ |
Prathyush K | f74085a | 2012-12-06 20:16:00 +0530 | [diff] [blame] | 234 | if (ops->wait_for_vblank) |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 235 | ops->wait_for_vblank(exynos_encoder->manager); |
Inki Dae | 1daa892 | 2012-11-22 17:41:23 +0900 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
| 239 | |
Inki Dae | bcf4cef | 2012-08-24 10:54:12 -0700 | [diff] [blame] | 240 | static void exynos_drm_encoder_disable(struct drm_encoder *encoder) |
| 241 | { |
| 242 | struct drm_plane *plane; |
| 243 | struct drm_device *dev = encoder->dev; |
| 244 | |
| 245 | exynos_drm_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); |
| 246 | |
| 247 | /* all planes connected to this encoder should be also disabled. */ |
| 248 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 249 | if (plane->crtc == encoder->crtc) |
| 250 | plane->funcs->disable_plane(plane); |
| 251 | } |
| 252 | } |
| 253 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 254 | static struct drm_encoder_helper_funcs exynos_encoder_helper_funcs = { |
| 255 | .dpms = exynos_drm_encoder_dpms, |
| 256 | .mode_fixup = exynos_drm_encoder_mode_fixup, |
| 257 | .mode_set = exynos_drm_encoder_mode_set, |
| 258 | .prepare = exynos_drm_encoder_prepare, |
| 259 | .commit = exynos_drm_encoder_commit, |
Inki Dae | bcf4cef | 2012-08-24 10:54:12 -0700 | [diff] [blame] | 260 | .disable = exynos_drm_encoder_disable, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 261 | }; |
| 262 | |
| 263 | static void exynos_drm_encoder_destroy(struct drm_encoder *encoder) |
| 264 | { |
| 265 | struct exynos_drm_encoder *exynos_encoder = |
| 266 | to_exynos_encoder(encoder); |
| 267 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 268 | exynos_encoder->manager->pipe = -1; |
| 269 | |
| 270 | drm_encoder_cleanup(encoder); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 271 | kfree(exynos_encoder); |
| 272 | } |
| 273 | |
| 274 | static struct drm_encoder_funcs exynos_encoder_funcs = { |
| 275 | .destroy = exynos_drm_encoder_destroy, |
| 276 | }; |
| 277 | |
Inki Dae | d081f56 | 2012-02-15 11:25:19 +0900 | [diff] [blame] | 278 | static unsigned int exynos_drm_encoder_clones(struct drm_encoder *encoder) |
| 279 | { |
| 280 | struct drm_encoder *clone; |
| 281 | struct drm_device *dev = encoder->dev; |
| 282 | struct exynos_drm_encoder *exynos_encoder = to_exynos_encoder(encoder); |
| 283 | struct exynos_drm_display_ops *display_ops = |
| 284 | exynos_encoder->manager->display_ops; |
| 285 | unsigned int clone_mask = 0; |
| 286 | int cnt = 0; |
| 287 | |
| 288 | list_for_each_entry(clone, &dev->mode_config.encoder_list, head) { |
| 289 | switch (display_ops->type) { |
| 290 | case EXYNOS_DISPLAY_TYPE_LCD: |
| 291 | case EXYNOS_DISPLAY_TYPE_HDMI: |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 292 | case EXYNOS_DISPLAY_TYPE_VIDI: |
Inki Dae | d081f56 | 2012-02-15 11:25:19 +0900 | [diff] [blame] | 293 | clone_mask |= (1 << (cnt++)); |
| 294 | break; |
| 295 | default: |
| 296 | continue; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | return clone_mask; |
| 301 | } |
| 302 | |
| 303 | void exynos_drm_encoder_setup(struct drm_device *dev) |
| 304 | { |
| 305 | struct drm_encoder *encoder; |
| 306 | |
Inki Dae | d081f56 | 2012-02-15 11:25:19 +0900 | [diff] [blame] | 307 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
| 308 | encoder->possible_clones = exynos_drm_encoder_clones(encoder); |
| 309 | } |
| 310 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 311 | struct drm_encoder * |
| 312 | exynos_drm_encoder_create(struct drm_device *dev, |
| 313 | struct exynos_drm_manager *manager, |
| 314 | unsigned int possible_crtcs) |
| 315 | { |
| 316 | struct drm_encoder *encoder; |
| 317 | struct exynos_drm_encoder *exynos_encoder; |
Sean Paul | 1f9cafc3 | 2014-01-30 16:19:03 -0500 | [diff] [blame] | 318 | int ret; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 319 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 320 | if (!manager || !possible_crtcs) |
| 321 | return NULL; |
| 322 | |
| 323 | if (!manager->dev) |
| 324 | return NULL; |
| 325 | |
| 326 | exynos_encoder = kzalloc(sizeof(*exynos_encoder), GFP_KERNEL); |
Sachin Kamat | 38bb525 | 2013-08-19 19:04:55 +0900 | [diff] [blame] | 327 | if (!exynos_encoder) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 328 | return NULL; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 329 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 330 | exynos_encoder->dpms = DRM_MODE_DPMS_OFF; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 331 | exynos_encoder->manager = manager; |
| 332 | encoder = &exynos_encoder->drm_encoder; |
| 333 | encoder->possible_crtcs = possible_crtcs; |
| 334 | |
| 335 | DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs); |
| 336 | |
| 337 | drm_encoder_init(dev, encoder, &exynos_encoder_funcs, |
| 338 | DRM_MODE_ENCODER_TMDS); |
| 339 | |
| 340 | drm_encoder_helper_add(encoder, &exynos_encoder_helper_funcs); |
| 341 | |
Sean Paul | 1f9cafc3 | 2014-01-30 16:19:03 -0500 | [diff] [blame] | 342 | if (manager->ops && manager->ops->initialize) { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 343 | ret = manager->ops->initialize(manager, dev); |
Sean Paul | 1f9cafc3 | 2014-01-30 16:19:03 -0500 | [diff] [blame] | 344 | if (ret) { |
| 345 | DRM_ERROR("Manager initialize failed %d\n", ret); |
| 346 | goto error; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | if (manager->display_ops && manager->display_ops->initialize) { |
| 351 | ret = manager->display_ops->initialize(manager->dev, dev); |
| 352 | if (ret) { |
| 353 | DRM_ERROR("Display initialize failed %d\n", ret); |
| 354 | goto error; |
| 355 | } |
| 356 | } |
| 357 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 358 | DRM_DEBUG_KMS("encoder has been created\n"); |
| 359 | |
| 360 | return encoder; |
Sean Paul | 1f9cafc3 | 2014-01-30 16:19:03 -0500 | [diff] [blame] | 361 | |
| 362 | error: |
| 363 | exynos_drm_encoder_destroy(&exynos_encoder->drm_encoder); |
| 364 | return NULL; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | struct exynos_drm_manager *exynos_drm_get_manager(struct drm_encoder *encoder) |
| 368 | { |
| 369 | return to_exynos_encoder(encoder)->manager; |
| 370 | } |
| 371 | |
| 372 | void exynos_drm_fn_encoder(struct drm_crtc *crtc, void *data, |
| 373 | void (*fn)(struct drm_encoder *, void *)) |
| 374 | { |
| 375 | struct drm_device *dev = crtc->dev; |
| 376 | struct drm_encoder *encoder; |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 377 | struct exynos_drm_private *private = dev->dev_private; |
| 378 | struct exynos_drm_manager *manager; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 379 | |
| 380 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
Joonyoung Shim | d2716c8 | 2011-11-04 17:04:45 +0900 | [diff] [blame] | 381 | /* |
| 382 | * if crtc is detached from encoder, check pipe, |
| 383 | * otherwise check crtc attached to encoder |
| 384 | */ |
| 385 | if (!encoder->crtc) { |
| 386 | manager = to_exynos_encoder(encoder)->manager; |
| 387 | if (manager->pipe < 0 || |
| 388 | private->crtc[manager->pipe] != crtc) |
| 389 | continue; |
| 390 | } else { |
| 391 | if (encoder->crtc != crtc) |
| 392 | continue; |
| 393 | } |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 394 | |
| 395 | fn(encoder, data); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | void exynos_drm_enable_vblank(struct drm_encoder *encoder, void *data) |
| 400 | { |
| 401 | struct exynos_drm_manager *manager = |
| 402 | to_exynos_encoder(encoder)->manager; |
| 403 | struct exynos_drm_manager_ops *manager_ops = manager->ops; |
| 404 | int crtc = *(int *)data; |
| 405 | |
Joonyoung Shim | d249ce0 | 2012-06-27 14:27:02 +0900 | [diff] [blame] | 406 | if (manager->pipe != crtc) |
| 407 | return; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 408 | |
| 409 | if (manager_ops->enable_vblank) |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 410 | manager_ops->enable_vblank(manager); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | void exynos_drm_disable_vblank(struct drm_encoder *encoder, void *data) |
| 414 | { |
| 415 | struct exynos_drm_manager *manager = |
| 416 | to_exynos_encoder(encoder)->manager; |
| 417 | struct exynos_drm_manager_ops *manager_ops = manager->ops; |
| 418 | int crtc = *(int *)data; |
| 419 | |
Joonyoung Shim | d249ce0 | 2012-06-27 14:27:02 +0900 | [diff] [blame] | 420 | if (manager->pipe != crtc) |
| 421 | return; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 422 | |
| 423 | if (manager_ops->disable_vblank) |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 424 | manager_ops->disable_vblank(manager); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 425 | } |
| 426 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 427 | void exynos_drm_encoder_crtc_dpms(struct drm_encoder *encoder, void *data) |
| 428 | { |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 429 | struct exynos_drm_encoder *exynos_encoder = to_exynos_encoder(encoder); |
| 430 | struct exynos_drm_manager *manager = exynos_encoder->manager; |
| 431 | struct exynos_drm_manager_ops *manager_ops = manager->ops; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 432 | int mode = *(int *)data; |
| 433 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 434 | if (manager_ops && manager_ops->dpms) |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 435 | manager_ops->dpms(manager, mode); |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 436 | |
| 437 | /* |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 438 | * if this condition is ok then it means that the crtc is already |
| 439 | * detached from encoder and last function for detaching is properly |
| 440 | * done, so clear pipe from manager to prevent repeated call. |
| 441 | */ |
| 442 | if (mode > DRM_MODE_DPMS_ON) { |
| 443 | if (!encoder->crtc) |
| 444 | manager->pipe = -1; |
| 445 | } |
| 446 | } |
| 447 | |
Joonyoung Shim | d249ce0 | 2012-06-27 14:27:02 +0900 | [diff] [blame] | 448 | void exynos_drm_encoder_crtc_pipe(struct drm_encoder *encoder, void *data) |
| 449 | { |
| 450 | struct exynos_drm_manager *manager = |
| 451 | to_exynos_encoder(encoder)->manager; |
| 452 | int pipe = *(int *)data; |
| 453 | |
Joonyoung Shim | d249ce0 | 2012-06-27 14:27:02 +0900 | [diff] [blame] | 454 | /* |
| 455 | * when crtc is detached from encoder, this pipe is used |
| 456 | * to select manager operation |
| 457 | */ |
| 458 | manager->pipe = pipe; |
| 459 | } |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 460 | |
| 461 | void exynos_drm_encoder_plane_mode_set(struct drm_encoder *encoder, void *data) |
| 462 | { |
| 463 | struct exynos_drm_manager *manager = |
| 464 | to_exynos_encoder(encoder)->manager; |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 465 | struct exynos_drm_manager_ops *manager_ops = manager->ops; |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 466 | struct exynos_drm_overlay *overlay = data; |
| 467 | |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 468 | if (manager_ops && manager_ops->win_mode_set) |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 469 | manager_ops->win_mode_set(manager, overlay); |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | void exynos_drm_encoder_plane_commit(struct drm_encoder *encoder, void *data) |
| 473 | { |
| 474 | struct exynos_drm_manager *manager = |
| 475 | to_exynos_encoder(encoder)->manager; |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 476 | struct exynos_drm_manager_ops *manager_ops = manager->ops; |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 477 | int zpos = DEFAULT_ZPOS; |
| 478 | |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 479 | if (data) |
| 480 | zpos = *(int *)data; |
| 481 | |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 482 | if (manager_ops && manager_ops->win_commit) |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 483 | manager_ops->win_commit(manager, zpos); |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 484 | } |
| 485 | |
Joonyoung Shim | cf5188a | 2012-06-27 14:27:09 +0900 | [diff] [blame] | 486 | void exynos_drm_encoder_plane_enable(struct drm_encoder *encoder, void *data) |
| 487 | { |
| 488 | struct exynos_drm_manager *manager = |
| 489 | to_exynos_encoder(encoder)->manager; |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 490 | struct exynos_drm_manager_ops *manager_ops = manager->ops; |
Joonyoung Shim | cf5188a | 2012-06-27 14:27:09 +0900 | [diff] [blame] | 491 | int zpos = DEFAULT_ZPOS; |
| 492 | |
Joonyoung Shim | cf5188a | 2012-06-27 14:27:09 +0900 | [diff] [blame] | 493 | if (data) |
| 494 | zpos = *(int *)data; |
| 495 | |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 496 | if (manager_ops && manager_ops->win_enable) |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 497 | manager_ops->win_enable(manager, zpos); |
Joonyoung Shim | cf5188a | 2012-06-27 14:27:09 +0900 | [diff] [blame] | 498 | } |
| 499 | |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 500 | void exynos_drm_encoder_plane_disable(struct drm_encoder *encoder, void *data) |
| 501 | { |
| 502 | struct exynos_drm_manager *manager = |
| 503 | to_exynos_encoder(encoder)->manager; |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 504 | struct exynos_drm_manager_ops *manager_ops = manager->ops; |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 505 | int zpos = DEFAULT_ZPOS; |
| 506 | |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 507 | if (data) |
| 508 | zpos = *(int *)data; |
| 509 | |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 510 | if (manager_ops && manager_ops->win_disable) |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 511 | manager_ops->win_disable(manager, zpos); |
Joonyoung Shim | 4070d21 | 2012-06-27 14:27:05 +0900 | [diff] [blame] | 512 | } |