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"
36 #define to_exynos_encoder(x) container_of(x, struct exynos_drm_encoder,\
40 * exynos specific encoder structure.
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 * @dpms: store the encoder dpms value.
47 struct exynos_drm_encoder
{
48 struct drm_encoder drm_encoder
;
49 struct exynos_drm_manager
*manager
;
53 static void exynos_drm_display_power(struct drm_encoder
*encoder
, int mode
)
55 struct drm_device
*dev
= encoder
->dev
;
56 struct drm_connector
*connector
;
57 struct exynos_drm_manager
*manager
= exynos_drm_get_manager(encoder
);
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
=
64 DRM_DEBUG_KMS("connector[%d] dpms[%d]\n",
65 connector
->base
.id
, mode
);
66 if (display_ops
&& display_ops
->power_on
)
67 display_ops
->power_on(manager
->dev
, mode
);
72 static void exynos_drm_encoder_dpms(struct drm_encoder
*encoder
, int mode
)
74 struct drm_device
*dev
= encoder
->dev
;
75 struct exynos_drm_manager
*manager
= exynos_drm_get_manager(encoder
);
76 struct exynos_drm_manager_ops
*manager_ops
= manager
->ops
;
77 struct exynos_drm_encoder
*exynos_encoder
= to_exynos_encoder(encoder
);
79 DRM_DEBUG_KMS("%s, encoder dpms: %d\n", __FILE__
, mode
);
81 if (exynos_encoder
->dpms
== mode
) {
82 DRM_DEBUG_KMS("desired dpms mode is same as previous one.\n");
86 mutex_lock(&dev
->struct_mutex
);
89 case DRM_MODE_DPMS_ON
:
90 if (manager_ops
&& manager_ops
->apply
)
91 manager_ops
->apply(manager
->dev
);
92 exynos_drm_display_power(encoder
, mode
);
93 exynos_encoder
->dpms
= mode
;
95 case DRM_MODE_DPMS_STANDBY
:
96 case DRM_MODE_DPMS_SUSPEND
:
97 case DRM_MODE_DPMS_OFF
:
98 exynos_drm_display_power(encoder
, mode
);
99 exynos_encoder
->dpms
= mode
;
102 DRM_ERROR("unspecified mode %d\n", mode
);
106 mutex_unlock(&dev
->struct_mutex
);
110 exynos_drm_encoder_mode_fixup(struct drm_encoder
*encoder
,
111 struct drm_display_mode
*mode
,
112 struct drm_display_mode
*adjusted_mode
)
114 struct drm_device
*dev
= encoder
->dev
;
115 struct drm_connector
*connector
;
116 struct exynos_drm_manager
*manager
= exynos_drm_get_manager(encoder
);
117 struct exynos_drm_manager_ops
*manager_ops
= manager
->ops
;
119 DRM_DEBUG_KMS("%s\n", __FILE__
);
121 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
122 if (connector
->encoder
== encoder
)
123 if (manager_ops
&& manager_ops
->mode_fixup
)
124 manager_ops
->mode_fixup(manager
->dev
, connector
,
125 mode
, adjusted_mode
);
131 static void exynos_drm_encoder_mode_set(struct drm_encoder
*encoder
,
132 struct drm_display_mode
*mode
,
133 struct drm_display_mode
*adjusted_mode
)
135 struct drm_device
*dev
= encoder
->dev
;
136 struct drm_connector
*connector
;
137 struct exynos_drm_manager
*manager
= exynos_drm_get_manager(encoder
);
138 struct exynos_drm_manager_ops
*manager_ops
= manager
->ops
;
139 struct exynos_drm_overlay_ops
*overlay_ops
= manager
->overlay_ops
;
140 struct exynos_drm_overlay
*overlay
= get_exynos_drm_overlay(dev
,
143 DRM_DEBUG_KMS("%s\n", __FILE__
);
145 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
146 if (connector
->encoder
== encoder
) {
147 if (manager_ops
&& manager_ops
->mode_set
)
148 manager_ops
->mode_set(manager
->dev
,
151 if (overlay_ops
&& overlay_ops
->mode_set
)
152 overlay_ops
->mode_set(manager
->dev
, overlay
);
157 static void exynos_drm_encoder_prepare(struct drm_encoder
*encoder
)
159 DRM_DEBUG_KMS("%s\n", __FILE__
);
161 /* drm framework doesn't check NULL. */
164 static void exynos_drm_encoder_commit(struct drm_encoder
*encoder
)
166 struct exynos_drm_manager
*manager
= exynos_drm_get_manager(encoder
);
167 struct exynos_drm_manager_ops
*manager_ops
= manager
->ops
;
169 DRM_DEBUG_KMS("%s\n", __FILE__
);
171 if (manager_ops
&& manager_ops
->commit
)
172 manager_ops
->commit(manager
->dev
);
175 static struct drm_crtc
*
176 exynos_drm_encoder_get_crtc(struct drm_encoder
*encoder
)
178 return encoder
->crtc
;
181 static struct drm_encoder_helper_funcs exynos_encoder_helper_funcs
= {
182 .dpms
= exynos_drm_encoder_dpms
,
183 .mode_fixup
= exynos_drm_encoder_mode_fixup
,
184 .mode_set
= exynos_drm_encoder_mode_set
,
185 .prepare
= exynos_drm_encoder_prepare
,
186 .commit
= exynos_drm_encoder_commit
,
187 .get_crtc
= exynos_drm_encoder_get_crtc
,
190 static void exynos_drm_encoder_destroy(struct drm_encoder
*encoder
)
192 struct exynos_drm_encoder
*exynos_encoder
=
193 to_exynos_encoder(encoder
);
195 DRM_DEBUG_KMS("%s\n", __FILE__
);
197 exynos_encoder
->manager
->pipe
= -1;
199 drm_encoder_cleanup(encoder
);
200 kfree(exynos_encoder
);
203 static struct drm_encoder_funcs exynos_encoder_funcs
= {
204 .destroy
= exynos_drm_encoder_destroy
,
207 static unsigned int exynos_drm_encoder_clones(struct drm_encoder
*encoder
)
209 struct drm_encoder
*clone
;
210 struct drm_device
*dev
= encoder
->dev
;
211 struct exynos_drm_encoder
*exynos_encoder
= to_exynos_encoder(encoder
);
212 struct exynos_drm_display_ops
*display_ops
=
213 exynos_encoder
->manager
->display_ops
;
214 unsigned int clone_mask
= 0;
217 list_for_each_entry(clone
, &dev
->mode_config
.encoder_list
, head
) {
218 switch (display_ops
->type
) {
219 case EXYNOS_DISPLAY_TYPE_LCD
:
220 case EXYNOS_DISPLAY_TYPE_HDMI
:
221 case EXYNOS_DISPLAY_TYPE_VIDI
:
222 clone_mask
|= (1 << (cnt
++));
232 void exynos_drm_encoder_setup(struct drm_device
*dev
)
234 struct drm_encoder
*encoder
;
236 DRM_DEBUG_KMS("%s\n", __FILE__
);
238 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
239 encoder
->possible_clones
= exynos_drm_encoder_clones(encoder
);
243 exynos_drm_encoder_create(struct drm_device
*dev
,
244 struct exynos_drm_manager
*manager
,
245 unsigned int possible_crtcs
)
247 struct drm_encoder
*encoder
;
248 struct exynos_drm_encoder
*exynos_encoder
;
250 DRM_DEBUG_KMS("%s\n", __FILE__
);
252 if (!manager
|| !possible_crtcs
)
258 exynos_encoder
= kzalloc(sizeof(*exynos_encoder
), GFP_KERNEL
);
259 if (!exynos_encoder
) {
260 DRM_ERROR("failed to allocate encoder\n");
264 exynos_encoder
->dpms
= DRM_MODE_DPMS_OFF
;
265 exynos_encoder
->manager
= manager
;
266 encoder
= &exynos_encoder
->drm_encoder
;
267 encoder
->possible_crtcs
= possible_crtcs
;
269 DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder
->possible_crtcs
);
271 drm_encoder_init(dev
, encoder
, &exynos_encoder_funcs
,
272 DRM_MODE_ENCODER_TMDS
);
274 drm_encoder_helper_add(encoder
, &exynos_encoder_helper_funcs
);
276 DRM_DEBUG_KMS("encoder has been created\n");
281 struct exynos_drm_manager
*exynos_drm_get_manager(struct drm_encoder
*encoder
)
283 return to_exynos_encoder(encoder
)->manager
;
286 void exynos_drm_fn_encoder(struct drm_crtc
*crtc
, void *data
,
287 void (*fn
)(struct drm_encoder
*, void *))
289 struct drm_device
*dev
= crtc
->dev
;
290 struct drm_encoder
*encoder
;
291 struct exynos_drm_private
*private = dev
->dev_private
;
292 struct exynos_drm_manager
*manager
;
294 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
296 * if crtc is detached from encoder, check pipe,
297 * otherwise check crtc attached to encoder
299 if (!encoder
->crtc
) {
300 manager
= to_exynos_encoder(encoder
)->manager
;
301 if (manager
->pipe
< 0 ||
302 private->crtc
[manager
->pipe
] != crtc
)
305 if (encoder
->crtc
!= crtc
)
313 void exynos_drm_enable_vblank(struct drm_encoder
*encoder
, void *data
)
315 struct exynos_drm_manager
*manager
=
316 to_exynos_encoder(encoder
)->manager
;
317 struct exynos_drm_manager_ops
*manager_ops
= manager
->ops
;
318 int crtc
= *(int *)data
;
320 if (manager
->pipe
== -1)
321 manager
->pipe
= crtc
;
323 if (manager_ops
->enable_vblank
)
324 manager_ops
->enable_vblank(manager
->dev
);
327 void exynos_drm_disable_vblank(struct drm_encoder
*encoder
, void *data
)
329 struct exynos_drm_manager
*manager
=
330 to_exynos_encoder(encoder
)->manager
;
331 struct exynos_drm_manager_ops
*manager_ops
= manager
->ops
;
332 int crtc
= *(int *)data
;
334 if (manager
->pipe
== -1)
335 manager
->pipe
= crtc
;
337 if (manager_ops
->disable_vblank
)
338 manager_ops
->disable_vblank(manager
->dev
);
341 void exynos_drm_encoder_crtc_plane_commit(struct drm_encoder
*encoder
,
344 struct exynos_drm_manager
*manager
=
345 to_exynos_encoder(encoder
)->manager
;
346 struct exynos_drm_overlay_ops
*overlay_ops
= manager
->overlay_ops
;
347 int zpos
= DEFAULT_ZPOS
;
352 if (overlay_ops
&& overlay_ops
->commit
)
353 overlay_ops
->commit(manager
->dev
, zpos
);
356 void exynos_drm_encoder_crtc_commit(struct drm_encoder
*encoder
, void *data
)
358 struct exynos_drm_manager
*manager
=
359 to_exynos_encoder(encoder
)->manager
;
360 int crtc
= *(int *)data
;
361 int zpos
= DEFAULT_ZPOS
;
363 DRM_DEBUG_KMS("%s\n", __FILE__
);
366 * when crtc is detached from encoder, this pipe is used
367 * to select manager operation
369 manager
->pipe
= crtc
;
371 exynos_drm_encoder_crtc_plane_commit(encoder
, &zpos
);
374 void exynos_drm_encoder_dpms_from_crtc(struct drm_encoder
*encoder
, void *data
)
376 struct exynos_drm_encoder
*exynos_encoder
= to_exynos_encoder(encoder
);
377 int mode
= *(int *)data
;
379 DRM_DEBUG_KMS("%s\n", __FILE__
);
381 exynos_drm_encoder_dpms(encoder
, mode
);
383 exynos_encoder
->dpms
= mode
;
386 void exynos_drm_encoder_crtc_dpms(struct drm_encoder
*encoder
, void *data
)
388 struct drm_device
*dev
= encoder
->dev
;
389 struct exynos_drm_encoder
*exynos_encoder
= to_exynos_encoder(encoder
);
390 struct exynos_drm_manager
*manager
= exynos_encoder
->manager
;
391 struct exynos_drm_manager_ops
*manager_ops
= manager
->ops
;
392 struct drm_connector
*connector
;
393 int mode
= *(int *)data
;
395 DRM_DEBUG_KMS("%s\n", __FILE__
);
397 if (manager_ops
&& manager_ops
->dpms
)
398 manager_ops
->dpms(manager
->dev
, mode
);
401 * set current dpms mode to the connector connected to
402 * current encoder. connector->dpms would be checked
403 * at drm_helper_connector_dpms()
405 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
406 if (connector
->encoder
== encoder
)
407 connector
->dpms
= mode
;
410 * if this condition is ok then it means that the crtc is already
411 * detached from encoder and last function for detaching is properly
412 * done, so clear pipe from manager to prevent repeated call.
414 if (mode
> DRM_MODE_DPMS_ON
) {
420 void exynos_drm_encoder_crtc_mode_set(struct drm_encoder
*encoder
, void *data
)
422 struct exynos_drm_manager
*manager
=
423 to_exynos_encoder(encoder
)->manager
;
424 struct exynos_drm_overlay_ops
*overlay_ops
= manager
->overlay_ops
;
425 struct exynos_drm_overlay
*overlay
= data
;
427 if (overlay_ops
&& overlay_ops
->mode_set
)
428 overlay_ops
->mode_set(manager
->dev
, overlay
);
431 void exynos_drm_encoder_crtc_disable(struct drm_encoder
*encoder
, void *data
)
433 struct exynos_drm_manager
*manager
=
434 to_exynos_encoder(encoder
)->manager
;
435 struct exynos_drm_overlay_ops
*overlay_ops
= manager
->overlay_ops
;
436 int zpos
= DEFAULT_ZPOS
;
443 if (overlay_ops
&& overlay_ops
->disable
)
444 overlay_ops
->disable(manager
->dev
, zpos
);