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("[ENCODER:%d:%s] [DPMS:%s]\n", DRM_BASE_ID(encoder),
57 drm_get_encoder_name(encoder), drm_get_dpms_name(mode));
59 if (!drm_helper_encoder_in_use(encoder))
62 if (display->panel_ops->dpms)
63 display->panel_ops->dpms(display->panel_ctx, mode);
67 exynos_drm_encoder_mode_fixup(struct drm_encoder *encoder,
68 struct drm_display_mode *mode,
69 struct drm_display_mode *adjusted_mode)
71 struct drm_device *dev = encoder->dev;
72 struct drm_connector *connector;
73 struct exynos_drm_display *display = exynos_drm_get_display(encoder);
75 DRM_DEBUG_KMS("[ENCODER:%d:%s] [MODE:%d:%s]\n", DRM_BASE_ID(encoder),
76 drm_get_encoder_name(encoder), DRM_BASE_ID(mode),
79 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
80 if (connector->encoder != encoder)
83 if (display->panel_ops->mode_fixup)
84 display->panel_ops->mode_fixup(display->panel_ctx,
85 connector, mode, adjusted_mode);
91 static void exynos_drm_encoder_mode_set(struct drm_encoder *encoder,
92 struct drm_display_mode *mode,
93 struct drm_display_mode *adjusted_mode)
95 struct exynos_drm_display *display = exynos_drm_get_display(encoder);
97 DRM_DEBUG_KMS("[ENCODER:%d:%s] [MODE:%d:%s]\n", DRM_BASE_ID(encoder),
98 drm_get_encoder_name(encoder), DRM_BASE_ID(mode),
101 if (!drm_helper_encoder_in_use(encoder))
104 if (display->panel_ops->mode_set)
105 display->panel_ops->mode_set(display->panel_ctx, adjusted_mode);
108 static void exynos_drm_encoder_prepare(struct drm_encoder *encoder)
110 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", DRM_BASE_ID(encoder),
111 drm_get_encoder_name(encoder));
113 exynos_drm_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
116 static void exynos_drm_encoder_commit(struct drm_encoder *encoder)
118 struct exynos_drm_display *display = exynos_drm_get_display(encoder);
120 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", DRM_BASE_ID(encoder),
121 drm_get_encoder_name(encoder));
123 exynos_drm_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
125 if (display->panel_ops->commit)
126 display->panel_ops->commit(display->panel_ctx);
129 static struct drm_crtc *
130 exynos_drm_encoder_get_crtc(struct drm_encoder *encoder)
132 return encoder->crtc;
135 static struct drm_encoder_helper_funcs exynos_encoder_helper_funcs = {
136 .dpms = exynos_drm_encoder_dpms,
137 .mode_fixup = exynos_drm_encoder_mode_fixup,
138 .mode_set = exynos_drm_encoder_mode_set,
139 .prepare = exynos_drm_encoder_prepare,
140 .commit = exynos_drm_encoder_commit,
141 .get_crtc = exynos_drm_encoder_get_crtc,
144 static void exynos_drm_encoder_destroy(struct drm_encoder *encoder)
146 struct exynos_drm_encoder *exynos_encoder = to_exynos_encoder(encoder);
148 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", DRM_BASE_ID(encoder),
149 drm_get_encoder_name(encoder));
151 exynos_encoder->display->pipe = -1;
153 drm_encoder_cleanup(encoder);
154 kfree(exynos_encoder);
157 static struct drm_encoder_funcs exynos_encoder_funcs = {
158 .destroy = exynos_drm_encoder_destroy,
161 static unsigned int exynos_drm_encoder_clones(struct drm_encoder *encoder)
163 struct drm_encoder *clone;
164 struct drm_device *dev = encoder->dev;
165 struct exynos_drm_display *display = exynos_drm_get_display(encoder);
166 unsigned int clone_mask = 0;
169 list_for_each_entry(clone, &dev->mode_config.encoder_list, head) {
170 switch (display->display_type) {
171 case EXYNOS_DRM_DISPLAY_TYPE_FIMD:
172 case EXYNOS_DRM_DISPLAY_TYPE_MIXER:
173 case EXYNOS_DRM_DISPLAY_TYPE_VIDI:
174 clone_mask |= (1 << (cnt++));
184 void exynos_drm_encoder_setup(struct drm_device *dev)
186 struct drm_encoder *encoder;
188 DRM_DEBUG_KMS("[DEV:%s]\n", dev->devname);
190 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
191 encoder->possible_clones = exynos_drm_encoder_clones(encoder);
195 exynos_drm_encoder_create(struct drm_device *dev,
196 struct exynos_drm_display *display,
197 unsigned int possible_crtcs)
199 struct drm_encoder *encoder;
200 struct exynos_drm_encoder *exynos_encoder;
202 DRM_DEBUG_KMS("[DEV:%s] display_type: %s possible_crtcs: 0x%x\n",
203 dev->devname, exynos_display_type_name(display),
206 if (!display || !possible_crtcs)
209 exynos_encoder = kzalloc(sizeof(*exynos_encoder), GFP_KERNEL);
210 if (!exynos_encoder) {
211 DRM_ERROR("failed to allocate encoder\n");
215 exynos_encoder->display = display;
216 encoder = &exynos_encoder->drm_encoder;
217 encoder->possible_crtcs = possible_crtcs;
219 drm_encoder_init(dev, encoder, &exynos_encoder_funcs,
220 DRM_MODE_ENCODER_TMDS);
222 drm_encoder_helper_add(encoder, &exynos_encoder_helper_funcs);
224 DRM_DEBUG_KMS("[ENCODER:%d:%s] has been created\n",
225 DRM_BASE_ID(encoder), drm_get_encoder_name(encoder));
230 struct exynos_drm_display *exynos_drm_get_display(struct drm_encoder *encoder)
232 return to_exynos_encoder(encoder)->display;