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_crtc_helper.h>
38 #include <drm/drm_fb_helper.h>
39 #include <drm/drm_edid.h>
41 MODULE_AUTHOR("David Airlie, Jesse Barnes");
42 MODULE_DESCRIPTION("DRM KMS helper");
45 * drm_helper_move_panel_connectors_to_head() - move panels to the front in the
47 * @dev: drm device to operate on
49 * Some userspace presumes that the first connected connector is the main
50 * display, where it's supposed to display e.g. the login screen. For
51 * laptops, this should be the main panel. Use this function to sort all
52 * (eDP/LVDS) panels to the front of the connector list, instead of
53 * painstakingly trying to initialize them in the right order.
55 void drm_helper_move_panel_connectors_to_head(struct drm_device *dev)
57 struct drm_connector *connector, *tmp;
58 struct list_head panel_list;
60 INIT_LIST_HEAD(&panel_list);
62 list_for_each_entry_safe(connector, tmp,
63 &dev->mode_config.connector_list, head) {
64 if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS ||
65 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
66 list_move_tail(&connector->head, &panel_list);
69 list_splice(&panel_list, &dev->mode_config.connector_list);
71 EXPORT_SYMBOL(drm_helper_move_panel_connectors_to_head);
74 * drm_helper_encoder_in_use - check if a given encoder is in use
75 * @encoder: encoder to check
77 * Checks whether @encoder is with the current mode setting output configuration
78 * in use by any connector. This doesn't mean that it is actually enabled since
79 * the DPMS state is tracked separately.
82 * True if @encoder is used, false otherwise.
84 bool drm_helper_encoder_in_use(struct drm_encoder *encoder)
86 struct drm_connector *connector;
87 struct drm_device *dev = encoder->dev;
89 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
90 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
91 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
92 if (connector->encoder == encoder)
96 EXPORT_SYMBOL(drm_helper_encoder_in_use);
99 * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config
100 * @crtc: CRTC to check
102 * Checks whether @crtc is with the current mode setting output configuration
103 * in use by any connector. This doesn't mean that it is actually enabled since
104 * the DPMS state is tracked separately.
107 * True if @crtc is used, false otherwise.
109 bool drm_helper_crtc_in_use(struct drm_crtc *crtc)
111 struct drm_encoder *encoder;
112 struct drm_device *dev = crtc->dev;
114 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
115 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
116 if (encoder->crtc == crtc && drm_helper_encoder_in_use(encoder))
120 EXPORT_SYMBOL(drm_helper_crtc_in_use);
123 drm_encoder_disable(struct drm_encoder *encoder)
125 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
128 encoder->bridge->funcs->disable(encoder->bridge);
130 if (encoder_funcs->disable)
131 (*encoder_funcs->disable)(encoder);
133 (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF);
136 encoder->bridge->funcs->post_disable(encoder->bridge);
139 static void __drm_helper_disable_unused_functions(struct drm_device *dev)
141 struct drm_encoder *encoder;
142 struct drm_crtc *crtc;
144 drm_warn_on_modeset_not_all_locked(dev);
146 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
147 if (!drm_helper_encoder_in_use(encoder)) {
148 drm_encoder_disable(encoder);
149 /* disconnect encoder from any connector */
150 encoder->crtc = NULL;
154 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
155 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
156 crtc->enabled = drm_helper_crtc_in_use(crtc);
157 if (!crtc->enabled) {
158 if (crtc_funcs->disable)
159 (*crtc_funcs->disable)(crtc);
161 (*crtc_funcs->dpms)(crtc, DRM_MODE_DPMS_OFF);
162 crtc->primary->fb = NULL;
168 * drm_helper_disable_unused_functions - disable unused objects
171 * This function walks through the entire mode setting configuration of @dev. It
172 * will remove any crtc links of unused encoders and encoder links of
173 * disconnected connectors. Then it will disable all unused encoders and crtcs
174 * either by calling their disable callback if available or by calling their
175 * dpms callback with DRM_MODE_DPMS_OFF.
177 void drm_helper_disable_unused_functions(struct drm_device *dev)
179 drm_modeset_lock_all(dev);
180 __drm_helper_disable_unused_functions(dev);
181 drm_modeset_unlock_all(dev);
183 EXPORT_SYMBOL(drm_helper_disable_unused_functions);
186 * Check the CRTC we're going to map each output to vs. its current
187 * CRTC. If they don't match, we have to disable the output and the CRTC
188 * since the driver will have to re-route things.
191 drm_crtc_prepare_encoders(struct drm_device *dev)
193 struct drm_encoder_helper_funcs *encoder_funcs;
194 struct drm_encoder *encoder;
196 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
197 encoder_funcs = encoder->helper_private;
198 /* Disable unused encoders */
199 if (encoder->crtc == NULL)
200 drm_encoder_disable(encoder);
201 /* Disable encoders whose CRTC is about to change */
202 if (encoder_funcs->get_crtc &&
203 encoder->crtc != (*encoder_funcs->get_crtc)(encoder))
204 drm_encoder_disable(encoder);
209 * drm_crtc_helper_set_mode - internal helper to set a mode
210 * @crtc: CRTC to program
212 * @x: horizontal offset into the surface
213 * @y: vertical offset into the surface
214 * @old_fb: old framebuffer, for cleanup
216 * Try to set @mode on @crtc. Give @crtc and its associated connectors a chance
217 * to fixup or reject the mode prior to trying to set it. This is an internal
218 * helper that drivers could e.g. use to update properties that require the
219 * entire output pipe to be disabled and re-enabled in a new configuration. For
220 * example for changing whether audio is enabled on a hdmi link or for changing
221 * panel fitter or dither attributes. It is also called by the
222 * drm_crtc_helper_set_config() helper function to drive the mode setting
226 * True if the mode was set successfully, false otherwise.
228 bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
229 struct drm_display_mode *mode,
231 struct drm_framebuffer *old_fb)
233 struct drm_device *dev = crtc->dev;
234 struct drm_display_mode *adjusted_mode, saved_mode;
235 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
236 struct drm_encoder_helper_funcs *encoder_funcs;
237 int saved_x, saved_y;
239 struct drm_encoder *encoder;
242 drm_warn_on_modeset_not_all_locked(dev);
244 saved_enabled = crtc->enabled;
245 crtc->enabled = drm_helper_crtc_in_use(crtc);
249 adjusted_mode = drm_mode_duplicate(dev, mode);
250 if (!adjusted_mode) {
251 crtc->enabled = saved_enabled;
255 saved_mode = crtc->mode;
259 /* Update crtc values up front so the driver can rely on them for mode
266 /* Pass our mode to the connectors and the CRTC to give them a chance to
267 * adjust it according to limitations or connector properties, and also
268 * a chance to reject the mode entirely.
270 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
272 if (encoder->crtc != crtc)
275 if (encoder->bridge && encoder->bridge->funcs->mode_fixup) {
276 ret = encoder->bridge->funcs->mode_fixup(
277 encoder->bridge, mode, adjusted_mode);
279 DRM_DEBUG_KMS("Bridge fixup failed\n");
284 encoder_funcs = encoder->helper_private;
285 if (!(ret = encoder_funcs->mode_fixup(encoder, mode,
287 DRM_DEBUG_KMS("Encoder fixup failed\n");
292 if (!(ret = crtc_funcs->mode_fixup(crtc, mode, adjusted_mode))) {
293 DRM_DEBUG_KMS("CRTC fixup failed\n");
296 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
298 /* Prepare the encoders and CRTCs before setting the mode. */
299 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
301 if (encoder->crtc != crtc)
305 encoder->bridge->funcs->disable(encoder->bridge);
307 encoder_funcs = encoder->helper_private;
308 /* Disable the encoders as the first thing we do. */
309 encoder_funcs->prepare(encoder);
312 encoder->bridge->funcs->post_disable(encoder->bridge);
315 drm_crtc_prepare_encoders(dev);
317 crtc_funcs->prepare(crtc);
319 /* Set up the DPLL and any encoders state that needs to adjust or depend
322 ret = !crtc_funcs->mode_set(crtc, mode, adjusted_mode, x, y, old_fb);
326 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
328 if (encoder->crtc != crtc)
331 DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
332 encoder->base.id, encoder->name,
333 mode->base.id, mode->name);
334 encoder_funcs = encoder->helper_private;
335 encoder_funcs->mode_set(encoder, mode, adjusted_mode);
337 if (encoder->bridge && encoder->bridge->funcs->mode_set)
338 encoder->bridge->funcs->mode_set(encoder->bridge, mode,
342 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
343 crtc_funcs->commit(crtc);
345 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
347 if (encoder->crtc != crtc)
351 encoder->bridge->funcs->pre_enable(encoder->bridge);
353 encoder_funcs = encoder->helper_private;
354 encoder_funcs->commit(encoder);
357 encoder->bridge->funcs->enable(encoder->bridge);
360 /* Store real post-adjustment hardware mode. */
361 crtc->hwmode = *adjusted_mode;
363 /* Calculate and store various constants which
364 * are later needed by vblank and swap-completion
365 * timestamping. They are derived from true hwmode.
367 drm_calc_timestamping_constants(crtc, &crtc->hwmode);
369 /* FIXME: add subpixel order */
371 drm_mode_destroy(dev, adjusted_mode);
373 crtc->enabled = saved_enabled;
374 crtc->mode = saved_mode;
381 EXPORT_SYMBOL(drm_crtc_helper_set_mode);
384 drm_crtc_helper_disable(struct drm_crtc *crtc)
386 struct drm_device *dev = crtc->dev;
387 struct drm_connector *connector;
388 struct drm_encoder *encoder;
390 /* Decouple all encoders and their attached connectors from this crtc */
391 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
392 if (encoder->crtc != crtc)
395 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
396 if (connector->encoder != encoder)
399 connector->encoder = NULL;
402 * drm_helper_disable_unused_functions() ought to be
403 * doing this, but since we've decoupled the encoder
404 * from the connector above, the required connection
405 * between them is henceforth no longer available.
407 connector->dpms = DRM_MODE_DPMS_OFF;
411 __drm_helper_disable_unused_functions(dev);
415 * drm_crtc_helper_set_config - set a new config from userspace
416 * @set: mode set configuration
418 * Setup a new configuration, provided by the upper layers (either an ioctl call
419 * from userspace or internally e.g. from the fbdev support code) in @set, and
420 * enable it. This is the main helper functions for drivers that implement
421 * kernel mode setting with the crtc helper functions and the assorted
422 * ->prepare(), ->modeset() and ->commit() helper callbacks.
425 * Returns 0 on success, negative errno numbers on failure.
427 int drm_crtc_helper_set_config(struct drm_mode_set *set)
429 struct drm_device *dev;
430 struct drm_crtc *new_crtc;
431 struct drm_encoder *save_encoders, *new_encoder, *encoder;
432 bool mode_changed = false; /* if true do a full mode set */
433 bool fb_changed = false; /* if true and !mode_changed just do a flip */
434 struct drm_connector *save_connectors, *connector;
435 int count = 0, ro, fail = 0;
436 struct drm_crtc_helper_funcs *crtc_funcs;
437 struct drm_mode_set save_set;
445 BUG_ON(!set->crtc->helper_private);
447 /* Enforce sane interface api - has been abused by the fb helper. */
448 BUG_ON(!set->mode && set->fb);
449 BUG_ON(set->fb && set->num_connectors == 0);
451 crtc_funcs = set->crtc->helper_private;
457 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
458 set->crtc->base.id, set->fb->base.id,
459 (int)set->num_connectors, set->x, set->y);
461 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
462 drm_crtc_helper_disable(set->crtc);
466 dev = set->crtc->dev;
468 drm_warn_on_modeset_not_all_locked(dev);
471 * Allocate space for the backup of all (non-pointer) encoder and
474 save_encoders = kzalloc(dev->mode_config.num_encoder *
475 sizeof(struct drm_encoder), GFP_KERNEL);
479 save_connectors = kzalloc(dev->mode_config.num_connector *
480 sizeof(struct drm_connector), GFP_KERNEL);
481 if (!save_connectors) {
482 kfree(save_encoders);
487 * Copy data. Note that driver private data is not affected.
488 * Should anything bad happen only the expected state is
489 * restored, not the drivers personal bookkeeping.
492 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
493 save_encoders[count++] = *encoder;
497 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
498 save_connectors[count++] = *connector;
501 save_set.crtc = set->crtc;
502 save_set.mode = &set->crtc->mode;
503 save_set.x = set->crtc->x;
504 save_set.y = set->crtc->y;
505 save_set.fb = set->crtc->primary->fb;
507 /* We should be able to check here if the fb has the same properties
508 * and then just flip_or_move it */
509 if (set->crtc->primary->fb != set->fb) {
510 /* If we have no fb then treat it as a full mode set */
511 if (set->crtc->primary->fb == NULL) {
512 DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
514 } else if (set->fb == NULL) {
516 } else if (set->fb->pixel_format !=
517 set->crtc->primary->fb->pixel_format) {
523 if (set->x != set->crtc->x || set->y != set->crtc->y)
526 if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
527 DRM_DEBUG_KMS("modes are different, full mode set\n");
528 drm_mode_debug_printmodeline(&set->crtc->mode);
529 drm_mode_debug_printmodeline(set->mode);
533 /* a) traverse passed in connector list and get encoders for them */
535 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
536 struct drm_connector_helper_funcs *connector_funcs =
537 connector->helper_private;
538 new_encoder = connector->encoder;
539 for (ro = 0; ro < set->num_connectors; ro++) {
540 if (set->connectors[ro] == connector) {
541 new_encoder = connector_funcs->best_encoder(connector);
542 /* if we can't get an encoder for a connector
543 we are setting now - then fail */
544 if (new_encoder == NULL)
545 /* don't break so fail path works correct */
548 if (connector->dpms != DRM_MODE_DPMS_ON) {
549 DRM_DEBUG_KMS("connector dpms not on, full mode switch\n");
557 if (new_encoder != connector->encoder) {
558 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
560 /* If the encoder is reused for another connector, then
561 * the appropriate crtc will be set later.
563 if (connector->encoder)
564 connector->encoder->crtc = NULL;
565 connector->encoder = new_encoder;
575 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
576 if (!connector->encoder)
579 if (connector->encoder->crtc == set->crtc)
582 new_crtc = connector->encoder->crtc;
584 for (ro = 0; ro < set->num_connectors; ro++) {
585 if (set->connectors[ro] == connector)
586 new_crtc = set->crtc;
589 /* Make sure the new CRTC will work with the encoder */
591 !drm_encoder_crtc_ok(connector->encoder, new_crtc)) {
595 if (new_crtc != connector->encoder->crtc) {
596 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
598 connector->encoder->crtc = new_crtc;
601 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
602 connector->base.id, connector->name,
605 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
606 connector->base.id, connector->name);
610 /* mode_set_base is not a required function */
611 if (fb_changed && !crtc_funcs->mode_set_base)
615 if (drm_helper_crtc_in_use(set->crtc)) {
616 DRM_DEBUG_KMS("attempting to set mode from"
618 drm_mode_debug_printmodeline(set->mode);
619 set->crtc->primary->fb = set->fb;
620 if (!drm_crtc_helper_set_mode(set->crtc, set->mode,
623 DRM_ERROR("failed to set mode on [CRTC:%d]\n",
625 set->crtc->primary->fb = save_set.fb;
629 DRM_DEBUG_KMS("Setting connector DPMS state to on\n");
630 for (i = 0; i < set->num_connectors; i++) {
631 DRM_DEBUG_KMS("\t[CONNECTOR:%d:%s] set DPMS on\n", set->connectors[i]->base.id,
632 set->connectors[i]->name);
633 set->connectors[i]->funcs->dpms(set->connectors[i], DRM_MODE_DPMS_ON);
636 __drm_helper_disable_unused_functions(dev);
637 } else if (fb_changed) {
638 set->crtc->x = set->x;
639 set->crtc->y = set->y;
640 set->crtc->primary->fb = set->fb;
641 ret = crtc_funcs->mode_set_base(set->crtc,
642 set->x, set->y, save_set.fb);
644 set->crtc->x = save_set.x;
645 set->crtc->y = save_set.y;
646 set->crtc->primary->fb = save_set.fb;
651 kfree(save_connectors);
652 kfree(save_encoders);
656 /* Restore all previous data. */
658 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
659 *encoder = save_encoders[count++];
663 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
664 *connector = save_connectors[count++];
667 /* Try to restore the config */
669 !drm_crtc_helper_set_mode(save_set.crtc, save_set.mode, save_set.x,
670 save_set.y, save_set.fb))
671 DRM_ERROR("failed to restore config after modeset failure\n");
673 kfree(save_connectors);
674 kfree(save_encoders);
677 EXPORT_SYMBOL(drm_crtc_helper_set_config);
679 static int drm_helper_choose_encoder_dpms(struct drm_encoder *encoder)
681 int dpms = DRM_MODE_DPMS_OFF;
682 struct drm_connector *connector;
683 struct drm_device *dev = encoder->dev;
685 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
686 if (connector->encoder == encoder)
687 if (connector->dpms < dpms)
688 dpms = connector->dpms;
692 /* Helper which handles bridge ordering around encoder dpms */
693 static void drm_helper_encoder_dpms(struct drm_encoder *encoder, int mode)
695 struct drm_bridge *bridge = encoder->bridge;
696 struct drm_encoder_helper_funcs *encoder_funcs;
699 if (mode == DRM_MODE_DPMS_ON)
700 bridge->funcs->pre_enable(bridge);
702 bridge->funcs->disable(bridge);
705 encoder_funcs = encoder->helper_private;
706 if (encoder_funcs->dpms)
707 encoder_funcs->dpms(encoder, mode);
710 if (mode == DRM_MODE_DPMS_ON)
711 bridge->funcs->enable(bridge);
713 bridge->funcs->post_disable(bridge);
717 static int drm_helper_choose_crtc_dpms(struct drm_crtc *crtc)
719 int dpms = DRM_MODE_DPMS_OFF;
720 struct drm_connector *connector;
721 struct drm_device *dev = crtc->dev;
723 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
724 if (connector->encoder && connector->encoder->crtc == crtc)
725 if (connector->dpms < dpms)
726 dpms = connector->dpms;
731 * drm_helper_connector_dpms() - connector dpms helper implementation
732 * @connector: affected connector
735 * This is the main helper function provided by the crtc helper framework for
736 * implementing the DPMS connector attribute. It computes the new desired DPMS
737 * state for all encoders and crtcs in the output mesh and calls the ->dpms()
738 * callback provided by the driver appropriately.
740 void drm_helper_connector_dpms(struct drm_connector *connector, int mode)
742 struct drm_encoder *encoder = connector->encoder;
743 struct drm_crtc *crtc = encoder ? encoder->crtc : NULL;
744 int old_dpms, encoder_dpms = DRM_MODE_DPMS_OFF;
746 if (mode == connector->dpms)
749 old_dpms = connector->dpms;
750 connector->dpms = mode;
753 encoder_dpms = drm_helper_choose_encoder_dpms(encoder);
755 /* from off to on, do crtc then encoder */
756 if (mode < old_dpms) {
758 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
759 if (crtc_funcs->dpms)
760 (*crtc_funcs->dpms) (crtc,
761 drm_helper_choose_crtc_dpms(crtc));
764 drm_helper_encoder_dpms(encoder, encoder_dpms);
767 /* from on to off, do encoder then crtc */
768 if (mode > old_dpms) {
770 drm_helper_encoder_dpms(encoder, encoder_dpms);
772 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
773 if (crtc_funcs->dpms)
774 (*crtc_funcs->dpms) (crtc,
775 drm_helper_choose_crtc_dpms(crtc));
781 EXPORT_SYMBOL(drm_helper_connector_dpms);
784 * drm_helper_mode_fill_fb_struct - fill out framebuffer metadata
785 * @fb: drm_framebuffer object to fill out
786 * @mode_cmd: metadata from the userspace fb creation request
788 * This helper can be used in a drivers fb_create callback to pre-fill the fb's
791 void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
792 struct drm_mode_fb_cmd2 *mode_cmd)
796 fb->width = mode_cmd->width;
797 fb->height = mode_cmd->height;
798 for (i = 0; i < 4; i++) {
799 fb->pitches[i] = mode_cmd->pitches[i];
800 fb->offsets[i] = mode_cmd->offsets[i];
802 drm_fb_get_bpp_depth(mode_cmd->pixel_format, &fb->depth,
803 &fb->bits_per_pixel);
804 fb->pixel_format = mode_cmd->pixel_format;
805 fb->flags = mode_cmd->flags;
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);