2 * Copyright (c) 2006-2008 Intel Corporation
3 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
5 * DRM core CRTC related functions
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that copyright
10 * notice and this permission notice appear in supporting documentation, and
11 * that the name of the copyright holders not be used in advertising or
12 * publicity pertaining to distribution of the software without specific,
13 * written prior permission. The copyright holders make no representations
14 * about the suitability of this software for any purpose. It is provided "as
15 * is" without express or implied warranty.
17 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
20 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
27 * Eric Anholt <eric@anholt.net>
28 * Dave Airlie <airlied@linux.ie>
29 * Jesse Barnes <jesse.barnes@intel.com>
32 #include <linux/export.h>
33 #include <linux/moduleparam.h>
36 #include <drm/drm_crtc.h>
37 #include <drm/drm_fourcc.h>
38 #include <drm/drm_crtc_helper.h>
39 #include <drm/drm_fb_helper.h>
40 #include <drm/drm_edid.h>
42 MODULE_AUTHOR("David Airlie, Jesse Barnes");
43 MODULE_DESCRIPTION("DRM KMS helper");
44 MODULE_LICENSE("GPL and additional rights");
47 * drm_helper_move_panel_connectors_to_head() - move panels to the front in the
49 * @dev: drm device to operate on
51 * Some userspace presumes that the first connected connector is the main
52 * display, where it's supposed to display e.g. the login screen. For
53 * laptops, this should be the main panel. Use this function to sort all
54 * (eDP/LVDS) panels to the front of the connector list, instead of
55 * painstakingly trying to initialize them in the right order.
57 void drm_helper_move_panel_connectors_to_head(struct drm_device
*dev
)
59 struct drm_connector
*connector
, *tmp
;
60 struct list_head panel_list
;
62 INIT_LIST_HEAD(&panel_list
);
64 list_for_each_entry_safe(connector
, tmp
,
65 &dev
->mode_config
.connector_list
, head
) {
66 if (connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
||
67 connector
->connector_type
== DRM_MODE_CONNECTOR_eDP
)
68 list_move_tail(&connector
->head
, &panel_list
);
71 list_splice(&panel_list
, &dev
->mode_config
.connector_list
);
73 EXPORT_SYMBOL(drm_helper_move_panel_connectors_to_head
);
76 * drm_helper_encoder_in_use - check if a given encoder is in use
77 * @encoder: encoder to check
79 * Checks whether @encoder is with the current mode setting output configuration
80 * in use by any connector. This doesn't mean that it is actually enabled since
81 * the DPMS state is tracked separately.
84 * True if @encoder is used, false otherwise.
86 bool drm_helper_encoder_in_use(struct drm_encoder
*encoder
)
88 struct drm_connector
*connector
;
89 struct drm_device
*dev
= encoder
->dev
;
91 WARN_ON(!mutex_is_locked(&dev
->mode_config
.mutex
));
92 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
93 if (connector
->encoder
== encoder
)
97 EXPORT_SYMBOL(drm_helper_encoder_in_use
);
100 * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config
101 * @crtc: CRTC to check
103 * Checks whether @crtc is with the current mode setting output configuration
104 * in use by any connector. This doesn't mean that it is actually enabled since
105 * the DPMS state is tracked separately.
108 * True if @crtc is used, false otherwise.
110 bool drm_helper_crtc_in_use(struct drm_crtc
*crtc
)
112 struct drm_encoder
*encoder
;
113 struct drm_device
*dev
= crtc
->dev
;
115 WARN_ON(!mutex_is_locked(&dev
->mode_config
.mutex
));
116 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
117 if (encoder
->crtc
== crtc
&& drm_helper_encoder_in_use(encoder
))
121 EXPORT_SYMBOL(drm_helper_crtc_in_use
);
124 drm_encoder_disable(struct drm_encoder
*encoder
)
126 struct drm_encoder_helper_funcs
*encoder_funcs
= encoder
->helper_private
;
129 encoder
->bridge
->funcs
->disable(encoder
->bridge
);
131 if (encoder_funcs
->disable
)
132 (*encoder_funcs
->disable
)(encoder
);
134 (*encoder_funcs
->dpms
)(encoder
, DRM_MODE_DPMS_OFF
);
137 encoder
->bridge
->funcs
->post_disable(encoder
->bridge
);
140 static void __drm_helper_disable_unused_functions(struct drm_device
*dev
)
142 struct drm_encoder
*encoder
;
143 struct drm_crtc
*crtc
;
145 drm_warn_on_modeset_not_all_locked(dev
);
147 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
148 if (!drm_helper_encoder_in_use(encoder
)) {
149 drm_encoder_disable(encoder
);
150 /* disconnector encoder from any connector */
151 encoder
->crtc
= NULL
;
155 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
156 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
157 crtc
->enabled
= drm_helper_crtc_in_use(crtc
);
158 if (!crtc
->enabled
) {
159 if (crtc_funcs
->disable
)
160 (*crtc_funcs
->disable
)(crtc
);
162 (*crtc_funcs
->dpms
)(crtc
, DRM_MODE_DPMS_OFF
);
163 crtc
->primary
->fb
= NULL
;
169 * drm_helper_disable_unused_functions - disable unused objects
172 * This function walks through the entire mode setting configuration of @dev. It
173 * will remove any crtc links of unused encoders and encoder links of
174 * disconnected connectors. Then it will disable all unused encoders and crtcs
175 * either by calling their disable callback if available or by calling their
176 * dpms callback with DRM_MODE_DPMS_OFF.
178 void drm_helper_disable_unused_functions(struct drm_device
*dev
)
180 drm_modeset_lock_all(dev
);
181 __drm_helper_disable_unused_functions(dev
);
182 drm_modeset_unlock_all(dev
);
184 EXPORT_SYMBOL(drm_helper_disable_unused_functions
);
187 * Check the CRTC we're going to map each output to vs. its current
188 * CRTC. If they don't match, we have to disable the output and the CRTC
189 * since the driver will have to re-route things.
192 drm_crtc_prepare_encoders(struct drm_device
*dev
)
194 struct drm_encoder_helper_funcs
*encoder_funcs
;
195 struct drm_encoder
*encoder
;
197 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
198 encoder_funcs
= encoder
->helper_private
;
199 /* Disable unused encoders */
200 if (encoder
->crtc
== NULL
)
201 drm_encoder_disable(encoder
);
202 /* Disable encoders whose CRTC is about to change */
203 if (encoder_funcs
->get_crtc
&&
204 encoder
->crtc
!= (*encoder_funcs
->get_crtc
)(encoder
))
205 drm_encoder_disable(encoder
);
210 * drm_crtc_helper_set_mode - internal helper to set a mode
211 * @crtc: CRTC to program
213 * @x: horizontal offset into the surface
214 * @y: vertical offset into the surface
215 * @old_fb: old framebuffer, for cleanup
217 * Try to set @mode on @crtc. Give @crtc and its associated connectors a chance
218 * to fixup or reject the mode prior to trying to set it. This is an internal
219 * helper that drivers could e.g. use to update properties that require the
220 * entire output pipe to be disabled and re-enabled in a new configuration. For
221 * example for changing whether audio is enabled on a hdmi link or for changing
222 * panel fitter or dither attributes. It is also called by the
223 * drm_crtc_helper_set_config() helper function to drive the mode setting
227 * True if the mode was set successfully, false otherwise.
229 bool drm_crtc_helper_set_mode(struct drm_crtc
*crtc
,
230 struct drm_display_mode
*mode
,
232 struct drm_framebuffer
*old_fb
)
234 struct drm_device
*dev
= crtc
->dev
;
235 struct drm_display_mode
*adjusted_mode
, saved_mode
;
236 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
237 struct drm_encoder_helper_funcs
*encoder_funcs
;
238 int saved_x
, saved_y
;
240 struct drm_encoder
*encoder
;
243 drm_warn_on_modeset_not_all_locked(dev
);
245 saved_enabled
= crtc
->enabled
;
246 crtc
->enabled
= drm_helper_crtc_in_use(crtc
);
250 adjusted_mode
= drm_mode_duplicate(dev
, mode
);
251 if (!adjusted_mode
) {
252 crtc
->enabled
= saved_enabled
;
256 saved_mode
= crtc
->mode
;
260 /* Update crtc values up front so the driver can rely on them for mode
267 /* Pass our mode to the connectors and the CRTC to give them a chance to
268 * adjust it according to limitations or connector properties, and also
269 * a chance to reject the mode entirely.
271 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
273 if (encoder
->crtc
!= crtc
)
276 if (encoder
->bridge
&& encoder
->bridge
->funcs
->mode_fixup
) {
277 ret
= encoder
->bridge
->funcs
->mode_fixup(
278 encoder
->bridge
, mode
, adjusted_mode
);
280 DRM_DEBUG_KMS("Bridge fixup failed\n");
285 encoder_funcs
= encoder
->helper_private
;
286 if (!(ret
= encoder_funcs
->mode_fixup(encoder
, mode
,
288 DRM_DEBUG_KMS("Encoder fixup failed\n");
293 if (!(ret
= crtc_funcs
->mode_fixup(crtc
, mode
, adjusted_mode
))) {
294 DRM_DEBUG_KMS("CRTC fixup failed\n");
297 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
299 /* Prepare the encoders and CRTCs before setting the mode. */
300 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
302 if (encoder
->crtc
!= crtc
)
306 encoder
->bridge
->funcs
->disable(encoder
->bridge
);
308 encoder_funcs
= encoder
->helper_private
;
309 /* Disable the encoders as the first thing we do. */
310 encoder_funcs
->prepare(encoder
);
313 encoder
->bridge
->funcs
->post_disable(encoder
->bridge
);
316 drm_crtc_prepare_encoders(dev
);
318 crtc_funcs
->prepare(crtc
);
320 /* Set up the DPLL and any encoders state that needs to adjust or depend
323 ret
= !crtc_funcs
->mode_set(crtc
, mode
, adjusted_mode
, x
, y
, old_fb
);
327 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
329 if (encoder
->crtc
!= crtc
)
332 DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
333 encoder
->base
.id
, drm_get_encoder_name(encoder
),
334 mode
->base
.id
, mode
->name
);
335 encoder_funcs
= encoder
->helper_private
;
336 encoder_funcs
->mode_set(encoder
, mode
, adjusted_mode
);
338 if (encoder
->bridge
&& encoder
->bridge
->funcs
->mode_set
)
339 encoder
->bridge
->funcs
->mode_set(encoder
->bridge
, mode
,
343 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
344 crtc_funcs
->commit(crtc
);
346 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
348 if (encoder
->crtc
!= crtc
)
352 encoder
->bridge
->funcs
->pre_enable(encoder
->bridge
);
354 encoder_funcs
= encoder
->helper_private
;
355 encoder_funcs
->commit(encoder
);
358 encoder
->bridge
->funcs
->enable(encoder
->bridge
);
361 /* Store real post-adjustment hardware mode. */
362 crtc
->hwmode
= *adjusted_mode
;
364 /* Calculate and store various constants which
365 * are later needed by vblank and swap-completion
366 * timestamping. They are derived from true hwmode.
368 drm_calc_timestamping_constants(crtc
, &crtc
->hwmode
);
370 /* FIXME: add subpixel order */
372 drm_mode_destroy(dev
, adjusted_mode
);
374 crtc
->enabled
= saved_enabled
;
375 crtc
->mode
= saved_mode
;
382 EXPORT_SYMBOL(drm_crtc_helper_set_mode
);
385 drm_crtc_helper_disable(struct drm_crtc
*crtc
)
387 struct drm_device
*dev
= crtc
->dev
;
388 struct drm_connector
*connector
;
389 struct drm_encoder
*encoder
;
391 /* Decouple all encoders and their attached connectors from this crtc */
392 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
393 if (encoder
->crtc
!= crtc
)
396 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
397 if (connector
->encoder
!= encoder
)
400 connector
->encoder
= NULL
;
403 * drm_helper_disable_unused_functions() ought to be
404 * doing this, but since we've decoupled the encoder
405 * from the connector above, the required connection
406 * between them is henceforth no longer available.
408 connector
->dpms
= DRM_MODE_DPMS_OFF
;
412 __drm_helper_disable_unused_functions(dev
);
416 * drm_crtc_helper_set_config - set a new config from userspace
417 * @set: mode set configuration
419 * Setup a new configuration, provided by the upper layers (either an ioctl call
420 * from userspace or internally e.g. from the fbdev support code) in @set, and
421 * enable it. This is the main helper functions for drivers that implement
422 * kernel mode setting with the crtc helper functions and the assorted
423 * ->prepare(), ->modeset() and ->commit() helper callbacks.
426 * Returns 0 on success, negative errno numbers on failure.
428 int drm_crtc_helper_set_config(struct drm_mode_set
*set
)
430 struct drm_device
*dev
;
431 struct drm_crtc
*new_crtc
;
432 struct drm_encoder
*save_encoders
, *new_encoder
, *encoder
;
433 bool mode_changed
= false; /* if true do a full mode set */
434 bool fb_changed
= false; /* if true and !mode_changed just do a flip */
435 struct drm_connector
*save_connectors
, *connector
;
436 int count
= 0, ro
, fail
= 0;
437 struct drm_crtc_helper_funcs
*crtc_funcs
;
438 struct drm_mode_set save_set
;
446 BUG_ON(!set
->crtc
->helper_private
);
448 /* Enforce sane interface api - has been abused by the fb helper. */
449 BUG_ON(!set
->mode
&& set
->fb
);
450 BUG_ON(set
->fb
&& set
->num_connectors
== 0);
452 crtc_funcs
= set
->crtc
->helper_private
;
458 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
459 set
->crtc
->base
.id
, set
->fb
->base
.id
,
460 (int)set
->num_connectors
, set
->x
, set
->y
);
462 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set
->crtc
->base
.id
);
463 drm_crtc_helper_disable(set
->crtc
);
467 dev
= set
->crtc
->dev
;
469 drm_warn_on_modeset_not_all_locked(dev
);
472 * Allocate space for the backup of all (non-pointer) encoder and
475 save_encoders
= kzalloc(dev
->mode_config
.num_encoder
*
476 sizeof(struct drm_encoder
), GFP_KERNEL
);
480 save_connectors
= kzalloc(dev
->mode_config
.num_connector
*
481 sizeof(struct drm_connector
), GFP_KERNEL
);
482 if (!save_connectors
) {
483 kfree(save_encoders
);
488 * Copy data. Note that driver private data is not affected.
489 * Should anything bad happen only the expected state is
490 * restored, not the drivers personal bookkeeping.
493 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
494 save_encoders
[count
++] = *encoder
;
498 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
499 save_connectors
[count
++] = *connector
;
502 save_set
.crtc
= set
->crtc
;
503 save_set
.mode
= &set
->crtc
->mode
;
504 save_set
.x
= set
->crtc
->x
;
505 save_set
.y
= set
->crtc
->y
;
506 save_set
.fb
= set
->crtc
->primary
->fb
;
508 /* We should be able to check here if the fb has the same properties
509 * and then just flip_or_move it */
510 if (set
->crtc
->primary
->fb
!= set
->fb
) {
511 /* If we have no fb then treat it as a full mode set */
512 if (set
->crtc
->primary
->fb
== NULL
) {
513 DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
515 } else if (set
->fb
== NULL
) {
517 } else if (set
->fb
->pixel_format
!=
518 set
->crtc
->primary
->fb
->pixel_format
) {
524 if (set
->x
!= set
->crtc
->x
|| set
->y
!= set
->crtc
->y
)
527 if (set
->mode
&& !drm_mode_equal(set
->mode
, &set
->crtc
->mode
)) {
528 DRM_DEBUG_KMS("modes are different, full mode set\n");
529 drm_mode_debug_printmodeline(&set
->crtc
->mode
);
530 drm_mode_debug_printmodeline(set
->mode
);
534 /* a) traverse passed in connector list and get encoders for them */
536 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
537 struct drm_connector_helper_funcs
*connector_funcs
=
538 connector
->helper_private
;
539 new_encoder
= connector
->encoder
;
540 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
541 if (set
->connectors
[ro
] == connector
) {
542 new_encoder
= connector_funcs
->best_encoder(connector
);
543 /* if we can't get an encoder for a connector
544 we are setting now - then fail */
545 if (new_encoder
== NULL
)
546 /* don't break so fail path works correct */
549 if (connector
->dpms
!= DRM_MODE_DPMS_ON
) {
550 DRM_DEBUG_KMS("connector dpms not on, full mode switch\n");
558 if (new_encoder
!= connector
->encoder
) {
559 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
561 /* If the encoder is reused for another connector, then
562 * the appropriate crtc will be set later.
564 if (connector
->encoder
)
565 connector
->encoder
->crtc
= NULL
;
566 connector
->encoder
= new_encoder
;
576 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
577 if (!connector
->encoder
)
580 if (connector
->encoder
->crtc
== set
->crtc
)
583 new_crtc
= connector
->encoder
->crtc
;
585 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
586 if (set
->connectors
[ro
] == connector
)
587 new_crtc
= set
->crtc
;
590 /* Make sure the new CRTC will work with the encoder */
592 !drm_encoder_crtc_ok(connector
->encoder
, new_crtc
)) {
596 if (new_crtc
!= connector
->encoder
->crtc
) {
597 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
599 connector
->encoder
->crtc
= new_crtc
;
602 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
603 connector
->base
.id
, drm_get_connector_name(connector
),
606 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
607 connector
->base
.id
, drm_get_connector_name(connector
));
611 /* mode_set_base is not a required function */
612 if (fb_changed
&& !crtc_funcs
->mode_set_base
)
616 if (drm_helper_crtc_in_use(set
->crtc
)) {
617 DRM_DEBUG_KMS("attempting to set mode from"
619 drm_mode_debug_printmodeline(set
->mode
);
620 set
->crtc
->primary
->fb
= set
->fb
;
621 if (!drm_crtc_helper_set_mode(set
->crtc
, set
->mode
,
624 DRM_ERROR("failed to set mode on [CRTC:%d]\n",
626 set
->crtc
->primary
->fb
= save_set
.fb
;
630 DRM_DEBUG_KMS("Setting connector DPMS state to on\n");
631 for (i
= 0; i
< set
->num_connectors
; i
++) {
632 DRM_DEBUG_KMS("\t[CONNECTOR:%d:%s] set DPMS on\n", set
->connectors
[i
]->base
.id
,
633 drm_get_connector_name(set
->connectors
[i
]));
634 set
->connectors
[i
]->funcs
->dpms(set
->connectors
[i
], DRM_MODE_DPMS_ON
);
637 __drm_helper_disable_unused_functions(dev
);
638 } else if (fb_changed
) {
639 set
->crtc
->x
= set
->x
;
640 set
->crtc
->y
= set
->y
;
641 set
->crtc
->primary
->fb
= set
->fb
;
642 ret
= crtc_funcs
->mode_set_base(set
->crtc
,
643 set
->x
, set
->y
, save_set
.fb
);
645 set
->crtc
->x
= save_set
.x
;
646 set
->crtc
->y
= save_set
.y
;
647 set
->crtc
->primary
->fb
= save_set
.fb
;
652 kfree(save_connectors
);
653 kfree(save_encoders
);
657 /* Restore all previous data. */
659 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
660 *encoder
= save_encoders
[count
++];
664 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
665 *connector
= save_connectors
[count
++];
668 /* Try to restore the config */
670 !drm_crtc_helper_set_mode(save_set
.crtc
, save_set
.mode
, save_set
.x
,
671 save_set
.y
, save_set
.fb
))
672 DRM_ERROR("failed to restore config after modeset failure\n");
674 kfree(save_connectors
);
675 kfree(save_encoders
);
678 EXPORT_SYMBOL(drm_crtc_helper_set_config
);
680 static int drm_helper_choose_encoder_dpms(struct drm_encoder
*encoder
)
682 int dpms
= DRM_MODE_DPMS_OFF
;
683 struct drm_connector
*connector
;
684 struct drm_device
*dev
= encoder
->dev
;
686 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
687 if (connector
->encoder
== encoder
)
688 if (connector
->dpms
< dpms
)
689 dpms
= connector
->dpms
;
693 /* Helper which handles bridge ordering around encoder dpms */
694 static void drm_helper_encoder_dpms(struct drm_encoder
*encoder
, int mode
)
696 struct drm_bridge
*bridge
= encoder
->bridge
;
697 struct drm_encoder_helper_funcs
*encoder_funcs
;
700 if (mode
== DRM_MODE_DPMS_ON
)
701 bridge
->funcs
->pre_enable(bridge
);
703 bridge
->funcs
->disable(bridge
);
706 encoder_funcs
= encoder
->helper_private
;
707 if (encoder_funcs
->dpms
)
708 encoder_funcs
->dpms(encoder
, mode
);
711 if (mode
== DRM_MODE_DPMS_ON
)
712 bridge
->funcs
->enable(bridge
);
714 bridge
->funcs
->post_disable(bridge
);
718 static int drm_helper_choose_crtc_dpms(struct drm_crtc
*crtc
)
720 int dpms
= DRM_MODE_DPMS_OFF
;
721 struct drm_connector
*connector
;
722 struct drm_device
*dev
= crtc
->dev
;
724 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
725 if (connector
->encoder
&& connector
->encoder
->crtc
== crtc
)
726 if (connector
->dpms
< dpms
)
727 dpms
= connector
->dpms
;
732 * drm_helper_connector_dpms() - connector dpms helper implementation
733 * @connector: affected connector
736 * This is the main helper function provided by the crtc helper framework for
737 * implementing the DPMS connector attribute. It computes the new desired DPMS
738 * state for all encoders and crtcs in the output mesh and calls the ->dpms()
739 * callback provided by the driver appropriately.
741 void drm_helper_connector_dpms(struct drm_connector
*connector
, int mode
)
743 struct drm_encoder
*encoder
= connector
->encoder
;
744 struct drm_crtc
*crtc
= encoder
? encoder
->crtc
: NULL
;
745 int old_dpms
, encoder_dpms
= DRM_MODE_DPMS_OFF
;
747 if (mode
== connector
->dpms
)
750 old_dpms
= connector
->dpms
;
751 connector
->dpms
= mode
;
754 encoder_dpms
= drm_helper_choose_encoder_dpms(encoder
);
756 /* from off to on, do crtc then encoder */
757 if (mode
< old_dpms
) {
759 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
760 if (crtc_funcs
->dpms
)
761 (*crtc_funcs
->dpms
) (crtc
,
762 drm_helper_choose_crtc_dpms(crtc
));
765 drm_helper_encoder_dpms(encoder
, encoder_dpms
);
768 /* from on to off, do encoder then crtc */
769 if (mode
> old_dpms
) {
771 drm_helper_encoder_dpms(encoder
, encoder_dpms
);
773 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
774 if (crtc_funcs
->dpms
)
775 (*crtc_funcs
->dpms
) (crtc
,
776 drm_helper_choose_crtc_dpms(crtc
));
782 EXPORT_SYMBOL(drm_helper_connector_dpms
);
785 * drm_helper_mode_fill_fb_struct - fill out framebuffer metadata
786 * @fb: drm_framebuffer object to fill out
787 * @mode_cmd: metadata from the userspace fb creation request
789 * This helper can be used in a drivers fb_create callback to pre-fill the fb's
792 void drm_helper_mode_fill_fb_struct(struct drm_framebuffer
*fb
,
793 struct drm_mode_fb_cmd2
*mode_cmd
)
797 fb
->width
= mode_cmd
->width
;
798 fb
->height
= mode_cmd
->height
;
799 for (i
= 0; i
< 4; i
++) {
800 fb
->pitches
[i
] = mode_cmd
->pitches
[i
];
801 fb
->offsets
[i
] = mode_cmd
->offsets
[i
];
803 drm_fb_get_bpp_depth(mode_cmd
->pixel_format
, &fb
->depth
,
804 &fb
->bits_per_pixel
);
805 fb
->pixel_format
= mode_cmd
->pixel_format
;
807 EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct
);
810 * drm_helper_resume_force_mode - force-restore mode setting configuration
811 * @dev: drm_device which should be restored
813 * Drivers which use the mode setting helpers can use this function to
814 * force-restore the mode setting configuration e.g. on resume or when something
815 * else might have trampled over the hw state (like some overzealous old BIOSen
818 * This helper doesn't provide a error return value since restoring the old
819 * config should never fail due to resource allocation issues since the driver
820 * has successfully set the restored configuration already. Hence this should
821 * boil down to the equivalent of a few dpms on calls, which also don't provide
824 * Drivers where simply restoring an old configuration again might fail (e.g.
825 * due to slight differences in allocating shared resources when the
826 * configuration is restored in a different order than when userspace set it up)
827 * need to use their own restore logic.
829 void drm_helper_resume_force_mode(struct drm_device
*dev
)
831 struct drm_crtc
*crtc
;
832 struct drm_encoder
*encoder
;
833 struct drm_crtc_helper_funcs
*crtc_funcs
;
837 drm_modeset_lock_all(dev
);
838 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
843 ret
= drm_crtc_helper_set_mode(crtc
, &crtc
->mode
,
844 crtc
->x
, crtc
->y
, crtc
->primary
->fb
);
846 /* Restoring the old config should never fail! */
848 DRM_ERROR("failed to set mode on crtc %p\n", crtc
);
850 /* Turn off outputs that were already powered off */
851 if (drm_helper_choose_crtc_dpms(crtc
)) {
852 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
854 if(encoder
->crtc
!= crtc
)
857 encoder_dpms
= drm_helper_choose_encoder_dpms(
860 drm_helper_encoder_dpms(encoder
, encoder_dpms
);
863 crtc_funcs
= crtc
->helper_private
;
864 if (crtc_funcs
->dpms
)
865 (*crtc_funcs
->dpms
) (crtc
,
866 drm_helper_choose_crtc_dpms(crtc
));
870 /* disable the unused connectors while restoring the modesetting */
871 __drm_helper_disable_unused_functions(dev
);
872 drm_modeset_unlock_all(dev
);
874 EXPORT_SYMBOL(drm_helper_resume_force_mode
);