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 WARN_ON(!mutex_is_locked(&dev->mode_config.connection_mutex));
94 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
95 if (connector->encoder == encoder)
99 EXPORT_SYMBOL(drm_helper_encoder_in_use);
102 * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config
103 * @crtc: CRTC to check
105 * Checks whether @crtc is with the current mode setting output configuration
106 * in use by any connector. This doesn't mean that it is actually enabled since
107 * the DPMS state is tracked separately.
110 * True if @crtc is used, false otherwise.
112 bool drm_helper_crtc_in_use(struct drm_crtc *crtc)
114 struct drm_encoder *encoder;
115 struct drm_device *dev = crtc->dev;
117 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
118 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
119 if (encoder->crtc == crtc && drm_helper_encoder_in_use(encoder))
123 EXPORT_SYMBOL(drm_helper_crtc_in_use);
126 drm_encoder_disable(struct drm_encoder *encoder)
128 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
131 encoder->bridge->funcs->disable(encoder->bridge);
133 if (encoder_funcs->disable)
134 (*encoder_funcs->disable)(encoder);
136 (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF);
139 encoder->bridge->funcs->post_disable(encoder->bridge);
142 static void __drm_helper_disable_unused_functions(struct drm_device *dev)
144 struct drm_encoder *encoder;
145 struct drm_crtc *crtc;
147 drm_warn_on_modeset_not_all_locked(dev);
149 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
150 if (!drm_helper_encoder_in_use(encoder)) {
151 drm_encoder_disable(encoder);
152 /* disconnect encoder from any connector */
153 encoder->crtc = NULL;
157 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
158 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
159 crtc->enabled = drm_helper_crtc_in_use(crtc);
160 if (!crtc->enabled) {
161 if (crtc_funcs->disable)
162 (*crtc_funcs->disable)(crtc);
164 (*crtc_funcs->dpms)(crtc, DRM_MODE_DPMS_OFF);
165 crtc->primary->fb = NULL;
171 * drm_helper_disable_unused_functions - disable unused objects
174 * This function walks through the entire mode setting configuration of @dev. It
175 * will remove any crtc links of unused encoders and encoder links of
176 * disconnected connectors. Then it will disable all unused encoders and crtcs
177 * either by calling their disable callback if available or by calling their
178 * dpms callback with DRM_MODE_DPMS_OFF.
180 void drm_helper_disable_unused_functions(struct drm_device *dev)
182 drm_modeset_lock_all(dev);
183 __drm_helper_disable_unused_functions(dev);
184 drm_modeset_unlock_all(dev);
186 EXPORT_SYMBOL(drm_helper_disable_unused_functions);
189 * Check the CRTC we're going to map each output to vs. its current
190 * CRTC. If they don't match, we have to disable the output and the CRTC
191 * since the driver will have to re-route things.
194 drm_crtc_prepare_encoders(struct drm_device *dev)
196 struct drm_encoder_helper_funcs *encoder_funcs;
197 struct drm_encoder *encoder;
199 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
200 encoder_funcs = encoder->helper_private;
201 /* Disable unused encoders */
202 if (encoder->crtc == NULL)
203 drm_encoder_disable(encoder);
204 /* Disable encoders whose CRTC is about to change */
205 if (encoder_funcs->get_crtc &&
206 encoder->crtc != (*encoder_funcs->get_crtc)(encoder))
207 drm_encoder_disable(encoder);
212 * drm_crtc_helper_set_mode - internal helper to set a mode
213 * @crtc: CRTC to program
215 * @x: horizontal offset into the surface
216 * @y: vertical offset into the surface
217 * @old_fb: old framebuffer, for cleanup
219 * Try to set @mode on @crtc. Give @crtc and its associated connectors a chance
220 * to fixup or reject the mode prior to trying to set it. This is an internal
221 * helper that drivers could e.g. use to update properties that require the
222 * entire output pipe to be disabled and re-enabled in a new configuration. For
223 * example for changing whether audio is enabled on a hdmi link or for changing
224 * panel fitter or dither attributes. It is also called by the
225 * drm_crtc_helper_set_config() helper function to drive the mode setting
229 * True if the mode was set successfully, false otherwise.
231 bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
232 struct drm_display_mode *mode,
234 struct drm_framebuffer *old_fb)
236 struct drm_device *dev = crtc->dev;
237 struct drm_display_mode *adjusted_mode, saved_mode;
238 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
239 struct drm_encoder_helper_funcs *encoder_funcs;
240 int saved_x, saved_y;
242 struct drm_encoder *encoder;
245 drm_warn_on_modeset_not_all_locked(dev);
247 saved_enabled = crtc->enabled;
248 crtc->enabled = drm_helper_crtc_in_use(crtc);
252 adjusted_mode = drm_mode_duplicate(dev, mode);
253 if (!adjusted_mode) {
254 crtc->enabled = saved_enabled;
258 saved_mode = crtc->mode;
262 /* Update crtc values up front so the driver can rely on them for mode
269 /* Pass our mode to the connectors and the CRTC to give them a chance to
270 * adjust it according to limitations or connector properties, and also
271 * a chance to reject the mode entirely.
273 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
275 if (encoder->crtc != crtc)
278 if (encoder->bridge && encoder->bridge->funcs->mode_fixup) {
279 ret = encoder->bridge->funcs->mode_fixup(
280 encoder->bridge, mode, adjusted_mode);
282 DRM_DEBUG_KMS("Bridge fixup failed\n");
287 encoder_funcs = encoder->helper_private;
288 if (!(ret = encoder_funcs->mode_fixup(encoder, mode,
290 DRM_DEBUG_KMS("Encoder fixup failed\n");
295 if (!(ret = crtc_funcs->mode_fixup(crtc, mode, adjusted_mode))) {
296 DRM_DEBUG_KMS("CRTC fixup failed\n");
299 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
301 /* Prepare the encoders and CRTCs before setting the mode. */
302 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
304 if (encoder->crtc != crtc)
308 encoder->bridge->funcs->disable(encoder->bridge);
310 encoder_funcs = encoder->helper_private;
311 /* Disable the encoders as the first thing we do. */
312 encoder_funcs->prepare(encoder);
315 encoder->bridge->funcs->post_disable(encoder->bridge);
318 drm_crtc_prepare_encoders(dev);
320 crtc_funcs->prepare(crtc);
322 /* Set up the DPLL and any encoders state that needs to adjust or depend
325 ret = !crtc_funcs->mode_set(crtc, mode, adjusted_mode, x, y, old_fb);
329 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
331 if (encoder->crtc != crtc)
334 DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
335 encoder->base.id, encoder->name,
336 mode->base.id, mode->name);
337 encoder_funcs = encoder->helper_private;
338 encoder_funcs->mode_set(encoder, mode, adjusted_mode);
340 if (encoder->bridge && encoder->bridge->funcs->mode_set)
341 encoder->bridge->funcs->mode_set(encoder->bridge, mode,
345 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
346 crtc_funcs->commit(crtc);
348 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
350 if (encoder->crtc != crtc)
354 encoder->bridge->funcs->pre_enable(encoder->bridge);
356 encoder_funcs = encoder->helper_private;
357 encoder_funcs->commit(encoder);
360 encoder->bridge->funcs->enable(encoder->bridge);
363 /* Store real post-adjustment hardware mode. */
364 crtc->hwmode = *adjusted_mode;
366 /* Calculate and store various constants which
367 * are later needed by vblank and swap-completion
368 * timestamping. They are derived from true hwmode.
370 drm_calc_timestamping_constants(crtc, &crtc->hwmode);
372 /* FIXME: add subpixel order */
374 drm_mode_destroy(dev, adjusted_mode);
376 crtc->enabled = saved_enabled;
377 crtc->mode = saved_mode;
384 EXPORT_SYMBOL(drm_crtc_helper_set_mode);
387 drm_crtc_helper_disable(struct drm_crtc *crtc)
389 struct drm_device *dev = crtc->dev;
390 struct drm_connector *connector;
391 struct drm_encoder *encoder;
393 /* Decouple all encoders and their attached connectors from this crtc */
394 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
395 if (encoder->crtc != crtc)
398 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
399 if (connector->encoder != encoder)
402 connector->encoder = NULL;
405 * drm_helper_disable_unused_functions() ought to be
406 * doing this, but since we've decoupled the encoder
407 * from the connector above, the required connection
408 * between them is henceforth no longer available.
410 connector->dpms = DRM_MODE_DPMS_OFF;
414 __drm_helper_disable_unused_functions(dev);
418 * drm_crtc_helper_set_config - set a new config from userspace
419 * @set: mode set configuration
421 * Setup a new configuration, provided by the upper layers (either an ioctl call
422 * from userspace or internally e.g. from the fbdev support code) in @set, and
423 * enable it. This is the main helper functions for drivers that implement
424 * kernel mode setting with the crtc helper functions and the assorted
425 * ->prepare(), ->modeset() and ->commit() helper callbacks.
428 * Returns 0 on success, negative errno numbers on failure.
430 int drm_crtc_helper_set_config(struct drm_mode_set *set)
432 struct drm_device *dev;
433 struct drm_crtc *new_crtc;
434 struct drm_encoder *save_encoders, *new_encoder, *encoder;
435 bool mode_changed = false; /* if true do a full mode set */
436 bool fb_changed = false; /* if true and !mode_changed just do a flip */
437 struct drm_connector *save_connectors, *connector;
438 int count = 0, ro, fail = 0;
439 struct drm_crtc_helper_funcs *crtc_funcs;
440 struct drm_mode_set save_set;
448 BUG_ON(!set->crtc->helper_private);
450 /* Enforce sane interface api - has been abused by the fb helper. */
451 BUG_ON(!set->mode && set->fb);
452 BUG_ON(set->fb && set->num_connectors == 0);
454 crtc_funcs = set->crtc->helper_private;
460 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
461 set->crtc->base.id, set->fb->base.id,
462 (int)set->num_connectors, set->x, set->y);
464 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
465 drm_crtc_helper_disable(set->crtc);
469 dev = set->crtc->dev;
471 drm_warn_on_modeset_not_all_locked(dev);
474 * Allocate space for the backup of all (non-pointer) encoder and
477 save_encoders = kzalloc(dev->mode_config.num_encoder *
478 sizeof(struct drm_encoder), GFP_KERNEL);
482 save_connectors = kzalloc(dev->mode_config.num_connector *
483 sizeof(struct drm_connector), GFP_KERNEL);
484 if (!save_connectors) {
485 kfree(save_encoders);
490 * Copy data. Note that driver private data is not affected.
491 * Should anything bad happen only the expected state is
492 * restored, not the drivers personal bookkeeping.
495 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
496 save_encoders[count++] = *encoder;
500 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
501 save_connectors[count++] = *connector;
504 save_set.crtc = set->crtc;
505 save_set.mode = &set->crtc->mode;
506 save_set.x = set->crtc->x;
507 save_set.y = set->crtc->y;
508 save_set.fb = set->crtc->primary->fb;
510 /* We should be able to check here if the fb has the same properties
511 * and then just flip_or_move it */
512 if (set->crtc->primary->fb != set->fb) {
513 /* If we have no fb then treat it as a full mode set */
514 if (set->crtc->primary->fb == NULL) {
515 DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
517 } else if (set->fb == NULL) {
519 } else if (set->fb->pixel_format !=
520 set->crtc->primary->fb->pixel_format) {
526 if (set->x != set->crtc->x || set->y != set->crtc->y)
529 if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
530 DRM_DEBUG_KMS("modes are different, full mode set\n");
531 drm_mode_debug_printmodeline(&set->crtc->mode);
532 drm_mode_debug_printmodeline(set->mode);
536 /* a) traverse passed in connector list and get encoders for them */
538 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
539 struct drm_connector_helper_funcs *connector_funcs =
540 connector->helper_private;
541 new_encoder = connector->encoder;
542 for (ro = 0; ro < set->num_connectors; ro++) {
543 if (set->connectors[ro] == connector) {
544 new_encoder = connector_funcs->best_encoder(connector);
545 /* if we can't get an encoder for a connector
546 we are setting now - then fail */
547 if (new_encoder == NULL)
548 /* don't break so fail path works correct */
551 if (connector->dpms != DRM_MODE_DPMS_ON) {
552 DRM_DEBUG_KMS("connector dpms not on, full mode switch\n");
560 if (new_encoder != connector->encoder) {
561 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
563 /* If the encoder is reused for another connector, then
564 * the appropriate crtc will be set later.
566 if (connector->encoder)
567 connector->encoder->crtc = NULL;
568 connector->encoder = new_encoder;
578 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
579 if (!connector->encoder)
582 if (connector->encoder->crtc == set->crtc)
585 new_crtc = connector->encoder->crtc;
587 for (ro = 0; ro < set->num_connectors; ro++) {
588 if (set->connectors[ro] == connector)
589 new_crtc = set->crtc;
592 /* Make sure the new CRTC will work with the encoder */
594 !drm_encoder_crtc_ok(connector->encoder, new_crtc)) {
598 if (new_crtc != connector->encoder->crtc) {
599 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
601 connector->encoder->crtc = new_crtc;
604 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
605 connector->base.id, connector->name,
608 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
609 connector->base.id, connector->name);
613 /* mode_set_base is not a required function */
614 if (fb_changed && !crtc_funcs->mode_set_base)
618 if (drm_helper_crtc_in_use(set->crtc)) {
619 DRM_DEBUG_KMS("attempting to set mode from"
621 drm_mode_debug_printmodeline(set->mode);
622 set->crtc->primary->fb = set->fb;
623 if (!drm_crtc_helper_set_mode(set->crtc, set->mode,
626 DRM_ERROR("failed to set mode on [CRTC:%d]\n",
628 set->crtc->primary->fb = save_set.fb;
632 DRM_DEBUG_KMS("Setting connector DPMS state to on\n");
633 for (i = 0; i < set->num_connectors; i++) {
634 DRM_DEBUG_KMS("\t[CONNECTOR:%d:%s] set DPMS on\n", set->connectors[i]->base.id,
635 set->connectors[i]->name);
636 set->connectors[i]->funcs->dpms(set->connectors[i], DRM_MODE_DPMS_ON);
639 __drm_helper_disable_unused_functions(dev);
640 } else if (fb_changed) {
641 set->crtc->x = set->x;
642 set->crtc->y = set->y;
643 set->crtc->primary->fb = set->fb;
644 ret = crtc_funcs->mode_set_base(set->crtc,
645 set->x, set->y, save_set.fb);
647 set->crtc->x = save_set.x;
648 set->crtc->y = save_set.y;
649 set->crtc->primary->fb = save_set.fb;
654 kfree(save_connectors);
655 kfree(save_encoders);
659 /* Restore all previous data. */
661 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
662 *encoder = save_encoders[count++];
666 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
667 *connector = save_connectors[count++];
670 /* Try to restore the config */
672 !drm_crtc_helper_set_mode(save_set.crtc, save_set.mode, save_set.x,
673 save_set.y, save_set.fb))
674 DRM_ERROR("failed to restore config after modeset failure\n");
676 kfree(save_connectors);
677 kfree(save_encoders);
680 EXPORT_SYMBOL(drm_crtc_helper_set_config);
682 static int drm_helper_choose_encoder_dpms(struct drm_encoder *encoder)
684 int dpms = DRM_MODE_DPMS_OFF;
685 struct drm_connector *connector;
686 struct drm_device *dev = encoder->dev;
688 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
689 if (connector->encoder == encoder)
690 if (connector->dpms < dpms)
691 dpms = connector->dpms;
695 /* Helper which handles bridge ordering around encoder dpms */
696 static void drm_helper_encoder_dpms(struct drm_encoder *encoder, int mode)
698 struct drm_bridge *bridge = encoder->bridge;
699 struct drm_encoder_helper_funcs *encoder_funcs;
702 if (mode == DRM_MODE_DPMS_ON)
703 bridge->funcs->pre_enable(bridge);
705 bridge->funcs->disable(bridge);
708 encoder_funcs = encoder->helper_private;
709 if (encoder_funcs->dpms)
710 encoder_funcs->dpms(encoder, mode);
713 if (mode == DRM_MODE_DPMS_ON)
714 bridge->funcs->enable(bridge);
716 bridge->funcs->post_disable(bridge);
720 static int drm_helper_choose_crtc_dpms(struct drm_crtc *crtc)
722 int dpms = DRM_MODE_DPMS_OFF;
723 struct drm_connector *connector;
724 struct drm_device *dev = crtc->dev;
726 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
727 if (connector->encoder && connector->encoder->crtc == crtc)
728 if (connector->dpms < dpms)
729 dpms = connector->dpms;
734 * drm_helper_connector_dpms() - connector dpms helper implementation
735 * @connector: affected connector
738 * This is the main helper function provided by the crtc helper framework for
739 * implementing the DPMS connector attribute. It computes the new desired DPMS
740 * state for all encoders and crtcs in the output mesh and calls the ->dpms()
741 * callback provided by the driver appropriately.
743 void drm_helper_connector_dpms(struct drm_connector *connector, int mode)
745 struct drm_encoder *encoder = connector->encoder;
746 struct drm_crtc *crtc = encoder ? encoder->crtc : NULL;
747 int old_dpms, encoder_dpms = DRM_MODE_DPMS_OFF;
749 if (mode == connector->dpms)
752 old_dpms = connector->dpms;
753 connector->dpms = mode;
756 encoder_dpms = drm_helper_choose_encoder_dpms(encoder);
758 /* from off to on, do crtc then encoder */
759 if (mode < old_dpms) {
761 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
762 if (crtc_funcs->dpms)
763 (*crtc_funcs->dpms) (crtc,
764 drm_helper_choose_crtc_dpms(crtc));
767 drm_helper_encoder_dpms(encoder, encoder_dpms);
770 /* from on to off, do encoder then crtc */
771 if (mode > old_dpms) {
773 drm_helper_encoder_dpms(encoder, encoder_dpms);
775 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
776 if (crtc_funcs->dpms)
777 (*crtc_funcs->dpms) (crtc,
778 drm_helper_choose_crtc_dpms(crtc));
784 EXPORT_SYMBOL(drm_helper_connector_dpms);
787 * drm_helper_mode_fill_fb_struct - fill out framebuffer metadata
788 * @fb: drm_framebuffer object to fill out
789 * @mode_cmd: metadata from the userspace fb creation request
791 * This helper can be used in a drivers fb_create callback to pre-fill the fb's
794 void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
795 struct drm_mode_fb_cmd2 *mode_cmd)
799 fb->width = mode_cmd->width;
800 fb->height = mode_cmd->height;
801 for (i = 0; i < 4; i++) {
802 fb->pitches[i] = mode_cmd->pitches[i];
803 fb->offsets[i] = mode_cmd->offsets[i];
805 drm_fb_get_bpp_depth(mode_cmd->pixel_format, &fb->depth,
806 &fb->bits_per_pixel);
807 fb->pixel_format = mode_cmd->pixel_format;
809 EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct);
812 * drm_helper_resume_force_mode - force-restore mode setting configuration
813 * @dev: drm_device which should be restored
815 * Drivers which use the mode setting helpers can use this function to
816 * force-restore the mode setting configuration e.g. on resume or when something
817 * else might have trampled over the hw state (like some overzealous old BIOSen
820 * This helper doesn't provide a error return value since restoring the old
821 * config should never fail due to resource allocation issues since the driver
822 * has successfully set the restored configuration already. Hence this should
823 * boil down to the equivalent of a few dpms on calls, which also don't provide
826 * Drivers where simply restoring an old configuration again might fail (e.g.
827 * due to slight differences in allocating shared resources when the
828 * configuration is restored in a different order than when userspace set it up)
829 * need to use their own restore logic.
831 void drm_helper_resume_force_mode(struct drm_device *dev)
833 struct drm_crtc *crtc;
834 struct drm_encoder *encoder;
835 struct drm_crtc_helper_funcs *crtc_funcs;
839 drm_modeset_lock_all(dev);
840 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
845 ret = drm_crtc_helper_set_mode(crtc, &crtc->mode,
846 crtc->x, crtc->y, crtc->primary->fb);
848 /* Restoring the old config should never fail! */
850 DRM_ERROR("failed to set mode on crtc %p\n", crtc);
852 /* Turn off outputs that were already powered off */
853 if (drm_helper_choose_crtc_dpms(crtc)) {
854 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
856 if(encoder->crtc != crtc)
859 encoder_dpms = drm_helper_choose_encoder_dpms(
862 drm_helper_encoder_dpms(encoder, encoder_dpms);
865 crtc_funcs = crtc->helper_private;
866 if (crtc_funcs->dpms)
867 (*crtc_funcs->dpms) (crtc,
868 drm_helper_choose_crtc_dpms(crtc));
872 /* disable the unused connectors while restoring the modesetting */
873 __drm_helper_disable_unused_functions(dev);
874 drm_modeset_unlock_all(dev);
876 EXPORT_SYMBOL(drm_helper_resume_force_mode);