1 /* exynos_drm_encoder.c
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
5 * Inki Dae <inki.dae@samsung.com>
6 * Joonyoung Shim <jy0922.shim@samsung.com>
7 * Seung-Woo Kim <sw0312.kim@samsung.com>
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:
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
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.
30 #include "drm_crtc_helper.h"
32 #include "exynos_drm_drv.h"
33 #include "exynos_drm_crtc.h"
34 #include "exynos_drm_encoder.h"
35 #include "exynos_drm_display.h"
37 #define to_exynos_encoder(x) container_of(x, struct exynos_drm_encoder,\
41 * exynos specific encoder structure.
43 * @drm_encoder: encoder object.
44 * @display: specific encoder has its own display to control a hardware
45 * appropriately and we can access a hardware drawing on this display.
47 struct exynos_drm_encoder {
48 struct drm_encoder drm_encoder;
49 struct exynos_drm_display *display;
52 void exynos_drm_encoder_dpms(struct drm_encoder *encoder, int mode)
54 struct exynos_drm_display *display = exynos_drm_get_display(encoder);
56 DRM_DEBUG_KMS("%s, encoder dpms: %d\n", __FILE__, mode);
58 if (!drm_helper_encoder_in_use(encoder))
61 if (display->panel_ops->dpms)
62 display->panel_ops->dpms(display->panel_ctx, mode);
66 exynos_drm_encoder_mode_fixup(struct drm_encoder *encoder,
67 struct drm_display_mode *mode,
68 struct drm_display_mode *adjusted_mode)
70 struct drm_device *dev = encoder->dev;
71 struct drm_connector *connector;
72 struct exynos_drm_display *display = exynos_drm_get_display(encoder);
74 DRM_DEBUG_KMS("%s\n", __FILE__);
76 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
77 if (connector->encoder != encoder)
80 if (display->panel_ops->mode_fixup)
81 display->panel_ops->mode_fixup(display->panel_ctx,
82 connector, mode, adjusted_mode);
88 static void exynos_drm_encoder_mode_set(struct drm_encoder *encoder,
89 struct drm_display_mode *mode,
90 struct drm_display_mode *adjusted_mode)
92 struct exynos_drm_display *display = exynos_drm_get_display(encoder);
94 DRM_DEBUG_KMS("%s\n", __FILE__);
96 if (!drm_helper_encoder_in_use(encoder))
99 if (display->panel_ops->mode_set)
100 display->panel_ops->mode_set(display->panel_ctx, adjusted_mode);
103 static void exynos_drm_encoder_prepare(struct drm_encoder *encoder)
105 DRM_DEBUG_KMS("%s\n", __FILE__);
107 /* drm framework doesn't check NULL. */
110 static void exynos_drm_encoder_commit(struct drm_encoder *encoder)
112 struct exynos_drm_display *display = exynos_drm_get_display(encoder);
114 DRM_DEBUG_KMS("%s\n", __FILE__);
116 exynos_drm_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
118 if (display->panel_ops->commit)
119 display->panel_ops->commit(display->panel_ctx);
122 static struct drm_crtc *
123 exynos_drm_encoder_get_crtc(struct drm_encoder *encoder)
125 return encoder->crtc;
128 static struct drm_encoder_helper_funcs exynos_encoder_helper_funcs = {
129 .dpms = exynos_drm_encoder_dpms,
130 .mode_fixup = exynos_drm_encoder_mode_fixup,
131 .mode_set = exynos_drm_encoder_mode_set,
132 .prepare = exynos_drm_encoder_prepare,
133 .commit = exynos_drm_encoder_commit,
134 .get_crtc = exynos_drm_encoder_get_crtc,
137 static void exynos_drm_encoder_destroy(struct drm_encoder *encoder)
139 struct exynos_drm_encoder *exynos_encoder = to_exynos_encoder(encoder);
141 DRM_DEBUG_KMS("%s\n", __FILE__);
143 exynos_encoder->display->pipe = -1;
145 drm_encoder_cleanup(encoder);
146 kfree(exynos_encoder);
149 static struct drm_encoder_funcs exynos_encoder_funcs = {
150 .destroy = exynos_drm_encoder_destroy,
153 static unsigned int exynos_drm_encoder_clones(struct drm_encoder *encoder)
155 struct drm_encoder *clone;
156 struct drm_device *dev = encoder->dev;
157 struct exynos_drm_display *display = exynos_drm_get_display(encoder);
158 unsigned int clone_mask = 0;
161 list_for_each_entry(clone, &dev->mode_config.encoder_list, head) {
162 switch (display->display_type) {
163 case EXYNOS_DRM_DISPLAY_TYPE_FIMD:
164 case EXYNOS_DRM_DISPLAY_TYPE_MIXER:
165 case EXYNOS_DRM_DISPLAY_TYPE_VIDI:
166 clone_mask |= (1 << (cnt++));
176 void exynos_drm_encoder_setup(struct drm_device *dev)
178 struct drm_encoder *encoder;
180 DRM_DEBUG_KMS("%s\n", __FILE__);
182 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
183 encoder->possible_clones = exynos_drm_encoder_clones(encoder);
187 exynos_drm_encoder_create(struct drm_device *dev,
188 struct exynos_drm_display *display,
189 unsigned int possible_crtcs)
191 struct drm_encoder *encoder;
192 struct exynos_drm_encoder *exynos_encoder;
194 DRM_DEBUG_KMS("%s\n", __FILE__);
196 if (!display || !possible_crtcs)
199 exynos_encoder = kzalloc(sizeof(*exynos_encoder), GFP_KERNEL);
200 if (!exynos_encoder) {
201 DRM_ERROR("failed to allocate encoder\n");
205 exynos_encoder->display = display;
206 encoder = &exynos_encoder->drm_encoder;
207 encoder->possible_crtcs = possible_crtcs;
209 DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
211 drm_encoder_init(dev, encoder, &exynos_encoder_funcs,
212 DRM_MODE_ENCODER_TMDS);
214 drm_encoder_helper_add(encoder, &exynos_encoder_helper_funcs);
216 DRM_DEBUG_KMS("encoder has been created\n");
221 struct exynos_drm_display *exynos_drm_get_display(struct drm_encoder *encoder)
223 return to_exynos_encoder(encoder)->display;