| 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 | * |
| 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" |
| 33 | #include "exynos_drm_crtc.h" |
| 34 | #include "exynos_drm_encoder.h" |
| 35 | |
| 36 | #define to_exynos_encoder(x) container_of(x, struct exynos_drm_encoder,\ |
| 37 | drm_encoder) |
| 38 | |
| 39 | /* |
| 40 | * exynos specific encoder structure. |
| 41 | * |
| 42 | * @drm_encoder: encoder object. |
| 43 | * @manager: specific encoder has its own manager to control a hardware |
| 44 | * appropriately and we can access a hardware drawing on this manager. |
| 45 | */ |
| 46 | struct exynos_drm_encoder { |
| 47 | struct drm_encoder drm_encoder; |
| 48 | struct exynos_drm_manager *manager; |
| 49 | }; |
| 50 | |
| 51 | static void exynos_drm_encoder_dpms(struct drm_encoder *encoder, int mode) |
| 52 | { |
| 53 | struct drm_device *dev = encoder->dev; |
| 54 | struct drm_connector *connector; |
| 55 | struct exynos_drm_manager *manager = exynos_drm_get_manager(encoder); |
| 56 | |
| 57 | DRM_DEBUG_KMS("%s, encoder dpms: %d\n", __FILE__, mode); |
| 58 | |
| 59 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 60 | if (connector->encoder == encoder) { |
| 61 | struct exynos_drm_display_ops *display_ops = |
| 62 | manager->display_ops; |
| 63 | |
| 64 | if (display_ops && display_ops->power_on) |
| 65 | display_ops->power_on(manager->dev, mode); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | static bool |
| 71 | exynos_drm_encoder_mode_fixup(struct drm_encoder *encoder, |
| 72 | struct drm_display_mode *mode, |
| 73 | struct drm_display_mode *adjusted_mode) |
| 74 | { |
| 75 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 76 | |
| 77 | /* drm framework doesn't check NULL. */ |
| 78 | |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | static void exynos_drm_encoder_mode_set(struct drm_encoder *encoder, |
| 83 | struct drm_display_mode *mode, |
| 84 | struct drm_display_mode *adjusted_mode) |
| 85 | { |
| 86 | struct drm_device *dev = encoder->dev; |
| 87 | struct drm_connector *connector; |
| 88 | struct exynos_drm_manager *manager = exynos_drm_get_manager(encoder); |
| 89 | struct exynos_drm_manager_ops *manager_ops = manager->ops; |
| 90 | struct exynos_drm_overlay_ops *overlay_ops = manager->overlay_ops; |
| 91 | struct exynos_drm_overlay *overlay = get_exynos_drm_overlay(dev, |
| 92 | encoder->crtc); |
| 93 | |
| 94 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 95 | |
| 96 | mode = adjusted_mode; |
| 97 | |
| 98 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 99 | if (connector->encoder == encoder) { |
| 100 | if (manager_ops && manager_ops->mode_set) |
| 101 | manager_ops->mode_set(manager->dev, mode); |
| 102 | |
| 103 | if (overlay_ops && overlay_ops->mode_set) |
| 104 | overlay_ops->mode_set(manager->dev, overlay); |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | static void exynos_drm_encoder_prepare(struct drm_encoder *encoder) |
| 110 | { |
| 111 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 112 | |
| 113 | /* drm framework doesn't check NULL. */ |
| 114 | } |
| 115 | |
| 116 | static void exynos_drm_encoder_commit(struct drm_encoder *encoder) |
| 117 | { |
| 118 | struct exynos_drm_manager *manager = exynos_drm_get_manager(encoder); |
| 119 | struct exynos_drm_manager_ops *manager_ops = manager->ops; |
| 120 | struct exynos_drm_overlay_ops *overlay_ops = manager->overlay_ops; |
| 121 | |
| 122 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 123 | |
| 124 | if (manager_ops && manager_ops->commit) |
| 125 | manager_ops->commit(manager->dev); |
| 126 | |
| 127 | if (overlay_ops && overlay_ops->commit) |
| 128 | overlay_ops->commit(manager->dev); |
| 129 | } |
| 130 | |
| 131 | static struct drm_crtc * |
| 132 | exynos_drm_encoder_get_crtc(struct drm_encoder *encoder) |
| 133 | { |
| 134 | return encoder->crtc; |
| 135 | } |
| 136 | |
| 137 | static struct drm_encoder_helper_funcs exynos_encoder_helper_funcs = { |
| 138 | .dpms = exynos_drm_encoder_dpms, |
| 139 | .mode_fixup = exynos_drm_encoder_mode_fixup, |
| 140 | .mode_set = exynos_drm_encoder_mode_set, |
| 141 | .prepare = exynos_drm_encoder_prepare, |
| 142 | .commit = exynos_drm_encoder_commit, |
| 143 | .get_crtc = exynos_drm_encoder_get_crtc, |
| 144 | }; |
| 145 | |
| 146 | static void exynos_drm_encoder_destroy(struct drm_encoder *encoder) |
| 147 | { |
| 148 | struct exynos_drm_encoder *exynos_encoder = |
| 149 | to_exynos_encoder(encoder); |
| 150 | |
| 151 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 152 | |
| 153 | exynos_encoder->manager->pipe = -1; |
| 154 | |
| 155 | drm_encoder_cleanup(encoder); |
| 156 | encoder->dev->mode_config.num_encoder--; |
| 157 | kfree(exynos_encoder); |
| 158 | } |
| 159 | |
| 160 | static struct drm_encoder_funcs exynos_encoder_funcs = { |
| 161 | .destroy = exynos_drm_encoder_destroy, |
| 162 | }; |
| 163 | |
| 164 | struct drm_encoder * |
| 165 | exynos_drm_encoder_create(struct drm_device *dev, |
| 166 | struct exynos_drm_manager *manager, |
| 167 | unsigned int possible_crtcs) |
| 168 | { |
| 169 | struct drm_encoder *encoder; |
| 170 | struct exynos_drm_encoder *exynos_encoder; |
| 171 | |
| 172 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 173 | |
| 174 | if (!manager || !possible_crtcs) |
| 175 | return NULL; |
| 176 | |
| 177 | if (!manager->dev) |
| 178 | return NULL; |
| 179 | |
| 180 | exynos_encoder = kzalloc(sizeof(*exynos_encoder), GFP_KERNEL); |
| 181 | if (!exynos_encoder) { |
| 182 | DRM_ERROR("failed to allocate encoder\n"); |
| 183 | return NULL; |
| 184 | } |
| 185 | |
| 186 | exynos_encoder->manager = manager; |
| 187 | encoder = &exynos_encoder->drm_encoder; |
| 188 | encoder->possible_crtcs = possible_crtcs; |
| 189 | |
| 190 | DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs); |
| 191 | |
| 192 | drm_encoder_init(dev, encoder, &exynos_encoder_funcs, |
| 193 | DRM_MODE_ENCODER_TMDS); |
| 194 | |
| 195 | drm_encoder_helper_add(encoder, &exynos_encoder_helper_funcs); |
| 196 | |
| 197 | DRM_DEBUG_KMS("encoder has been created\n"); |
| 198 | |
| 199 | return encoder; |
| 200 | } |
| 201 | |
| 202 | struct exynos_drm_manager *exynos_drm_get_manager(struct drm_encoder *encoder) |
| 203 | { |
| 204 | return to_exynos_encoder(encoder)->manager; |
| 205 | } |
| 206 | |
| 207 | void exynos_drm_fn_encoder(struct drm_crtc *crtc, void *data, |
| 208 | void (*fn)(struct drm_encoder *, void *)) |
| 209 | { |
| 210 | struct drm_device *dev = crtc->dev; |
| 211 | struct drm_encoder *encoder; |
| 212 | |
| 213 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 214 | if (encoder->crtc != crtc) |
| 215 | continue; |
| 216 | |
| 217 | fn(encoder, data); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | void exynos_drm_enable_vblank(struct drm_encoder *encoder, void *data) |
| 222 | { |
| 223 | struct exynos_drm_manager *manager = |
| 224 | to_exynos_encoder(encoder)->manager; |
| 225 | struct exynos_drm_manager_ops *manager_ops = manager->ops; |
| 226 | int crtc = *(int *)data; |
| 227 | |
| 228 | if (manager->pipe == -1) |
| 229 | manager->pipe = crtc; |
| 230 | |
| 231 | if (manager_ops->enable_vblank) |
| 232 | manager_ops->enable_vblank(manager->dev); |
| 233 | } |
| 234 | |
| 235 | void exynos_drm_disable_vblank(struct drm_encoder *encoder, void *data) |
| 236 | { |
| 237 | struct exynos_drm_manager *manager = |
| 238 | to_exynos_encoder(encoder)->manager; |
| 239 | struct exynos_drm_manager_ops *manager_ops = manager->ops; |
| 240 | int crtc = *(int *)data; |
| 241 | |
| 242 | if (manager->pipe == -1) |
| 243 | manager->pipe = crtc; |
| 244 | |
| 245 | if (manager_ops->disable_vblank) |
| 246 | manager_ops->disable_vblank(manager->dev); |
| 247 | } |
| 248 | |
| 249 | void exynos_drm_encoder_crtc_commit(struct drm_encoder *encoder, void *data) |
| 250 | { |
| 251 | struct exynos_drm_manager *manager = |
| 252 | to_exynos_encoder(encoder)->manager; |
| 253 | struct exynos_drm_overlay_ops *overlay_ops = manager->overlay_ops; |
| 254 | |
| 255 | overlay_ops->commit(manager->dev); |
| 256 | } |
| 257 | |
| 258 | void exynos_drm_encoder_crtc_mode_set(struct drm_encoder *encoder, void *data) |
| 259 | { |
| 260 | struct exynos_drm_manager *manager = |
| 261 | to_exynos_encoder(encoder)->manager; |
| 262 | struct exynos_drm_overlay_ops *overlay_ops = manager->overlay_ops; |
| 263 | struct exynos_drm_overlay *overlay = data; |
| 264 | |
| 265 | overlay_ops->mode_set(manager->dev, overlay); |
| 266 | } |
| 267 | |
| 268 | MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>"); |
| 269 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
| 270 | MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>"); |
| 271 | MODULE_DESCRIPTION("Samsung SoC DRM Encoder Driver"); |
| 272 | MODULE_LICENSE("GPL"); |