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>
34 #include "drm_crtc_helper.h"
37 * Detailed mode info for 800x600@60Hz
39 static struct drm_display_mode std_modes[] = {
40 { DRM_MODE("800x600", DRM_MODE_TYPE_DEFAULT, 40000, 800, 840,
41 968, 1056, 0, 600, 601, 605, 628, 0,
42 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
45 static void drm_mode_validate_flag(struct drm_connector *connector,
48 struct drm_display_mode *mode, *t;
50 if (flags == (DRM_MODE_FLAG_DBLSCAN | DRM_MODE_FLAG_INTERLACE))
53 list_for_each_entry_safe(mode, t, &connector->modes, head) {
54 if ((mode->flags & DRM_MODE_FLAG_INTERLACE) &&
55 !(flags & DRM_MODE_FLAG_INTERLACE))
56 mode->status = MODE_NO_INTERLACE;
57 if ((mode->flags & DRM_MODE_FLAG_DBLSCAN) &&
58 !(flags & DRM_MODE_FLAG_DBLSCAN))
59 mode->status = MODE_NO_DBLESCAN;
66 * drm_helper_probe_connector_modes - get complete set of display modes
68 * @maxX: max width for modes
69 * @maxY: max height for modes
72 * Caller must hold mode config lock.
74 * Based on @dev's mode_config layout, scan all the connectors and try to detect
75 * modes on them. Modes will first be added to the connector's probed_modes
76 * list, then culled (based on validity and the @maxX, @maxY parameters) and
77 * put into the normal modes list.
79 * Intended to be used either at bootup time or when major configuration
80 * changes have occurred.
82 * FIXME: take into account monitor limits
85 * Number of modes found on @connector.
87 int drm_helper_probe_single_connector_modes(struct drm_connector *connector,
88 uint32_t maxX, uint32_t maxY)
90 struct drm_device *dev = connector->dev;
91 struct drm_display_mode *mode, *t;
92 struct drm_connector_helper_funcs *connector_funcs =
93 connector->helper_private;
97 DRM_DEBUG("%s\n", drm_get_connector_name(connector));
98 /* set all modes to the unverified state */
99 list_for_each_entry_safe(mode, t, &connector->modes, head)
100 mode->status = MODE_UNVERIFIED;
102 connector->status = connector->funcs->detect(connector);
104 if (connector->status == connector_status_disconnected) {
105 DRM_DEBUG("%s is disconnected\n",
106 drm_get_connector_name(connector));
107 /* TODO set EDID to NULL */
111 count = (*connector_funcs->get_modes)(connector);
115 drm_mode_connector_list_update(connector);
118 drm_mode_validate_size(dev, &connector->modes, maxX,
121 if (connector->interlace_allowed)
122 mode_flags |= DRM_MODE_FLAG_INTERLACE;
123 if (connector->doublescan_allowed)
124 mode_flags |= DRM_MODE_FLAG_DBLSCAN;
125 drm_mode_validate_flag(connector, mode_flags);
127 list_for_each_entry_safe(mode, t, &connector->modes, head) {
128 if (mode->status == MODE_OK)
129 mode->status = connector_funcs->mode_valid(connector,
134 drm_mode_prune_invalid(dev, &connector->modes, true);
136 if (list_empty(&connector->modes))
139 drm_mode_sort(&connector->modes);
141 DRM_DEBUG("Probed modes for %s\n", drm_get_connector_name(connector));
142 list_for_each_entry_safe(mode, t, &connector->modes, head) {
143 mode->vrefresh = drm_mode_vrefresh(mode);
145 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
146 drm_mode_debug_printmodeline(mode);
151 EXPORT_SYMBOL(drm_helper_probe_single_connector_modes);
153 int drm_helper_probe_connector_modes(struct drm_device *dev, uint32_t maxX,
156 struct drm_connector *connector;
159 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
160 count += drm_helper_probe_single_connector_modes(connector,
166 EXPORT_SYMBOL(drm_helper_probe_connector_modes);
168 static void drm_helper_add_std_modes(struct drm_device *dev,
169 struct drm_connector *connector)
171 struct drm_display_mode *mode, *t;
174 for (i = 0; i < ARRAY_SIZE(std_modes); i++) {
175 struct drm_display_mode *stdmode;
178 * When no valid EDID modes are available we end up
179 * here and bailed in the past, now we add some standard
182 stdmode = drm_mode_duplicate(dev, &std_modes[i]);
183 drm_mode_probed_add(connector, stdmode);
184 drm_mode_list_concat(&connector->probed_modes,
187 DRM_DEBUG("Adding mode %s to %s\n", stdmode->name,
188 drm_get_connector_name(connector));
190 drm_mode_sort(&connector->modes);
192 DRM_DEBUG("Added std modes on %s\n", drm_get_connector_name(connector));
193 list_for_each_entry_safe(mode, t, &connector->modes, head) {
194 mode->vrefresh = drm_mode_vrefresh(mode);
196 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
197 drm_mode_debug_printmodeline(mode);
202 * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config
203 * @crtc: CRTC to check
206 * Caller must hold mode config lock.
208 * Walk @crtc's DRM device's mode_config and see if it's in use.
211 * True if @crtc is part of the mode_config, false otherwise.
213 bool drm_helper_crtc_in_use(struct drm_crtc *crtc)
215 struct drm_encoder *encoder;
216 struct drm_device *dev = crtc->dev;
217 /* FIXME: Locking around list access? */
218 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
219 if (encoder->crtc == crtc)
223 EXPORT_SYMBOL(drm_helper_crtc_in_use);
226 * drm_disable_unused_functions - disable unused objects
230 * Caller must hold mode config lock.
232 * If an connector or CRTC isn't part of @dev's mode_config, it can be disabled
233 * by calling its dpms function, which should power it off.
235 void drm_helper_disable_unused_functions(struct drm_device *dev)
237 struct drm_encoder *encoder;
238 struct drm_encoder_helper_funcs *encoder_funcs;
239 struct drm_crtc *crtc;
241 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
242 encoder_funcs = encoder->helper_private;
244 (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF);
247 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
248 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
249 crtc->enabled = drm_helper_crtc_in_use(crtc);
250 if (!crtc->enabled) {
251 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
256 EXPORT_SYMBOL(drm_helper_disable_unused_functions);
258 static struct drm_display_mode *drm_has_preferred_mode(struct drm_connector *connector, int width, int height)
260 struct drm_display_mode *mode;
262 list_for_each_entry(mode, &connector->modes, head) {
263 if (drm_mode_width(mode) > width ||
264 drm_mode_height(mode) > height)
266 if (mode->type & DRM_MODE_TYPE_PREFERRED)
272 static bool drm_connector_enabled(struct drm_connector *connector, bool strict)
277 enable = connector->status == connector_status_connected;
279 enable = connector->status != connector_status_disconnected;
284 static void drm_enable_connectors(struct drm_device *dev, bool *enabled)
286 bool any_enabled = false;
287 struct drm_connector *connector;
290 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
291 enabled[i] = drm_connector_enabled(connector, true);
292 DRM_DEBUG("connector %d enabled? %s\n", connector->base.id,
293 enabled[i] ? "yes" : "no");
294 any_enabled |= enabled[i];
302 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
303 enabled[i] = drm_connector_enabled(connector, false);
308 static bool drm_target_preferred(struct drm_device *dev,
309 struct drm_display_mode **modes,
310 bool *enabled, int width, int height)
312 struct drm_connector *connector;
315 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
317 if (enabled[i] == false) {
322 DRM_DEBUG("looking for preferred mode on connector %d\n",
325 modes[i] = drm_has_preferred_mode(connector, width, height);
326 /* No preferred modes, pick one off the list */
327 if (!modes[i] && !list_empty(&connector->modes)) {
328 list_for_each_entry(modes[i], &connector->modes, head)
331 DRM_DEBUG("found mode %s\n", modes[i] ? modes[i]->name :
338 static int drm_pick_crtcs(struct drm_device *dev,
339 struct drm_crtc **best_crtcs,
340 struct drm_display_mode **modes,
341 int n, int width, int height)
344 struct drm_connector *connector;
345 struct drm_connector_helper_funcs *connector_funcs;
346 struct drm_encoder *encoder;
347 struct drm_crtc *best_crtc;
348 int my_score, best_score, score;
349 struct drm_crtc **crtcs, *crtc;
351 if (n == dev->mode_config.num_connector)
354 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
360 best_crtcs[n] = NULL;
362 best_score = drm_pick_crtcs(dev, best_crtcs, modes, n+1, width, height);
363 if (modes[n] == NULL)
366 crtcs = kmalloc(dev->mode_config.num_connector *
367 sizeof(struct drm_crtc *), GFP_KERNEL);
372 if (connector->status == connector_status_connected)
374 if (drm_has_preferred_mode(connector, width, height))
377 connector_funcs = connector->helper_private;
378 encoder = connector_funcs->best_encoder(connector);
382 connector->encoder = encoder;
384 /* select a crtc for this connector and then attempt to configure
385 remaining connectors */
387 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
389 if ((connector->encoder->possible_crtcs & (1 << c)) == 0) {
394 for (o = 0; o < n; o++)
395 if (best_crtcs[o] == crtc)
399 /* ignore cloning for now */
405 memcpy(crtcs, best_crtcs, n * sizeof(struct drm_crtc *));
406 score = my_score + drm_pick_crtcs(dev, crtcs, modes, n + 1,
408 if (score > best_score) {
411 memcpy(best_crtcs, crtcs,
412 dev->mode_config.num_connector *
413 sizeof(struct drm_crtc *));
422 static void drm_setup_crtcs(struct drm_device *dev)
424 struct drm_crtc **crtcs;
425 struct drm_display_mode **modes;
426 struct drm_encoder *encoder;
427 struct drm_connector *connector;
434 width = dev->mode_config.max_width;
435 height = dev->mode_config.max_height;
437 /* clean out all the encoder/crtc combos */
438 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
439 encoder->crtc = NULL;
442 crtcs = kcalloc(dev->mode_config.num_connector,
443 sizeof(struct drm_crtc *), GFP_KERNEL);
444 modes = kcalloc(dev->mode_config.num_connector,
445 sizeof(struct drm_display_mode *), GFP_KERNEL);
446 enabled = kcalloc(dev->mode_config.num_connector,
447 sizeof(bool), GFP_KERNEL);
449 drm_enable_connectors(dev, enabled);
451 ret = drm_target_preferred(dev, modes, enabled, width, height);
453 DRM_ERROR("Unable to find initial modes\n");
455 DRM_DEBUG("picking CRTCs for %dx%d config\n", width, height);
457 drm_pick_crtcs(dev, crtcs, modes, 0, width, height);
460 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
461 struct drm_display_mode *mode = modes[i];
462 struct drm_crtc *crtc = crtcs[i];
464 if (connector->encoder == NULL) {
470 DRM_DEBUG("desired mode %s set on crtc %d\n",
471 mode->name, crtc->base.id);
472 crtc->desired_mode = mode;
473 connector->encoder->crtc = crtc;
475 connector->encoder->crtc = NULL;
485 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
486 * @encoder: encoder to test
487 * @crtc: crtc to test
489 * Return false if @encoder can't be driven by @crtc, true otherwise.
491 static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
492 struct drm_crtc *crtc)
494 struct drm_device *dev;
495 struct drm_crtc *tmp;
498 WARN(!crtc, "checking null crtc?");
502 list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) {
508 if (encoder->possible_crtcs & crtc_mask)
514 * Check the CRTC we're going to map each output to vs. its current
515 * CRTC. If they don't match, we have to disable the output and the CRTC
516 * since the driver will have to re-route things.
519 drm_crtc_prepare_encoders(struct drm_device *dev)
521 struct drm_encoder_helper_funcs *encoder_funcs;
522 struct drm_encoder *encoder;
524 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
525 encoder_funcs = encoder->helper_private;
526 /* Disable unused encoders */
527 if (encoder->crtc == NULL)
528 (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF);
529 /* Disable encoders whose CRTC is about to change */
530 if (encoder_funcs->get_crtc &&
531 encoder->crtc != (*encoder_funcs->get_crtc)(encoder))
532 (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF);
537 * drm_crtc_set_mode - set a mode
538 * @crtc: CRTC to program
544 * Caller must hold mode config lock.
546 * Try to set @mode on @crtc. Give @crtc and its associated connectors a chance
547 * to fixup or reject the mode prior to trying to set it.
550 * True if the mode was set successfully, or false otherwise.
552 bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
553 struct drm_display_mode *mode,
555 struct drm_framebuffer *old_fb)
557 struct drm_device *dev = crtc->dev;
558 struct drm_display_mode *adjusted_mode, saved_mode;
559 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
560 struct drm_encoder_helper_funcs *encoder_funcs;
561 int saved_x, saved_y;
562 struct drm_encoder *encoder;
565 adjusted_mode = drm_mode_duplicate(dev, mode);
567 crtc->enabled = drm_helper_crtc_in_use(crtc);
572 saved_mode = crtc->mode;
576 /* Update crtc values up front so the driver can rely on them for mode
583 /* Pass our mode to the connectors and the CRTC to give them a chance to
584 * adjust it according to limitations or connector properties, and also
585 * a chance to reject the mode entirely.
587 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
589 if (encoder->crtc != crtc)
591 encoder_funcs = encoder->helper_private;
592 if (!(ret = encoder_funcs->mode_fixup(encoder, mode,
598 if (!(ret = crtc_funcs->mode_fixup(crtc, mode, adjusted_mode))) {
602 /* Prepare the encoders and CRTCs before setting the mode. */
603 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
605 if (encoder->crtc != crtc)
607 encoder_funcs = encoder->helper_private;
608 /* Disable the encoders as the first thing we do. */
609 encoder_funcs->prepare(encoder);
612 drm_crtc_prepare_encoders(dev);
614 crtc_funcs->prepare(crtc);
616 /* Set up the DPLL and any encoders state that needs to adjust or depend
619 ret = !crtc_funcs->mode_set(crtc, mode, adjusted_mode, x, y, old_fb);
623 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
625 if (encoder->crtc != crtc)
628 DRM_INFO("%s: set mode %s %x\n", drm_get_encoder_name(encoder),
629 mode->name, mode->base.id);
630 encoder_funcs = encoder->helper_private;
631 encoder_funcs->mode_set(encoder, mode, adjusted_mode);
634 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
635 crtc_funcs->commit(crtc);
637 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
639 if (encoder->crtc != crtc)
642 encoder_funcs = encoder->helper_private;
643 encoder_funcs->commit(encoder);
647 /* XXX free adjustedmode */
648 drm_mode_destroy(dev, adjusted_mode);
649 /* FIXME: add subpixel order */
652 crtc->mode = saved_mode;
659 EXPORT_SYMBOL(drm_crtc_helper_set_mode);
663 * drm_crtc_helper_set_config - set a new config from userspace
664 * @crtc: CRTC to setup
665 * @crtc_info: user provided configuration
666 * @new_mode: new mode to set
667 * @connector_set: set of connectors for the new config
668 * @fb: new framebuffer
671 * Caller must hold mode config lock.
673 * Setup a new configuration, provided by the user in @crtc_info, and enable
679 int drm_crtc_helper_set_config(struct drm_mode_set *set)
681 struct drm_device *dev;
682 struct drm_crtc **save_crtcs, *new_crtc;
683 struct drm_encoder **save_encoders, *new_encoder;
684 struct drm_framebuffer *old_fb = NULL;
686 bool mode_changed = false;
687 bool fb_changed = false;
688 struct drm_connector *connector;
689 int count = 0, ro, fail = 0;
690 struct drm_crtc_helper_funcs *crtc_funcs;
701 if (!set->crtc->helper_private)
704 crtc_funcs = set->crtc->helper_private;
706 DRM_DEBUG("crtc: %p %d fb: %p connectors: %p num_connectors: %d (x, y) (%i, %i)\n",
707 set->crtc, set->crtc->base.id, set->fb, set->connectors,
708 (int)set->num_connectors, set->x, set->y);
710 dev = set->crtc->dev;
712 /* save previous config */
713 save_enabled = set->crtc->enabled;
716 * We do mode_config.num_connectors here since we'll look at the
717 * CRTC and encoder associated with each connector later.
719 save_crtcs = kzalloc(dev->mode_config.num_connector *
720 sizeof(struct drm_crtc *), GFP_KERNEL);
724 save_encoders = kzalloc(dev->mode_config.num_connector *
725 sizeof(struct drm_encoders *), GFP_KERNEL);
726 if (!save_encoders) {
731 /* We should be able to check here if the fb has the same properties
732 * and then just flip_or_move it */
733 if (set->crtc->fb != set->fb) {
734 /* If we have no fb then treat it as a full mode set */
735 if (set->crtc->fb == NULL) {
736 DRM_DEBUG("crtc has no fb, full mode set\n");
738 } else if ((set->fb->bits_per_pixel !=
739 set->crtc->fb->bits_per_pixel) ||
740 set->fb->depth != set->crtc->fb->depth)
746 if (set->x != set->crtc->x || set->y != set->crtc->y)
749 if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
750 DRM_DEBUG("modes are different, full mode set\n");
751 drm_mode_debug_printmodeline(&set->crtc->mode);
752 drm_mode_debug_printmodeline(set->mode);
756 /* a) traverse passed in connector list and get encoders for them */
758 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
759 struct drm_connector_helper_funcs *connector_funcs =
760 connector->helper_private;
761 save_encoders[count++] = connector->encoder;
762 new_encoder = connector->encoder;
763 for (ro = 0; ro < set->num_connectors; ro++) {
764 if (set->connectors[ro] == connector) {
765 new_encoder = connector_funcs->best_encoder(connector);
766 /* if we can't get an encoder for a connector
767 we are setting now - then fail */
768 if (new_encoder == NULL)
769 /* don't break so fail path works correct */
775 if (new_encoder != connector->encoder) {
776 DRM_DEBUG("encoder changed, full mode switch\n");
778 connector->encoder = new_encoder;
784 goto fail_no_encoder;
788 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
789 if (!connector->encoder)
792 save_crtcs[count++] = connector->encoder->crtc;
794 if (connector->encoder->crtc == set->crtc)
797 new_crtc = connector->encoder->crtc;
799 for (ro = 0; ro < set->num_connectors; ro++) {
800 if (set->connectors[ro] == connector)
801 new_crtc = set->crtc;
804 /* Make sure the new CRTC will work with the encoder */
806 !drm_encoder_crtc_ok(connector->encoder, new_crtc)) {
810 if (new_crtc != connector->encoder->crtc) {
811 DRM_DEBUG("crtc changed, full mode switch\n");
813 connector->encoder->crtc = new_crtc;
815 DRM_DEBUG("setting connector %d crtc to %p\n",
816 connector->base.id, new_crtc);
819 /* mode_set_base is not a required function */
820 if (fb_changed && !crtc_funcs->mode_set_base)
824 old_fb = set->crtc->fb;
825 set->crtc->fb = set->fb;
826 set->crtc->enabled = (set->mode != NULL);
827 if (set->mode != NULL) {
828 DRM_DEBUG("attempting to set mode from userspace\n");
829 drm_mode_debug_printmodeline(set->mode);
830 if (!drm_crtc_helper_set_mode(set->crtc, set->mode,
833 DRM_ERROR("failed to set mode on crtc %p\n",
838 /* TODO are these needed? */
839 set->crtc->desired_x = set->x;
840 set->crtc->desired_y = set->y;
841 set->crtc->desired_mode = set->mode;
843 drm_helper_disable_unused_functions(dev);
844 } else if (fb_changed) {
845 old_fb = set->crtc->fb;
846 if (set->crtc->fb != set->fb)
847 set->crtc->fb = set->fb;
848 ret = crtc_funcs->mode_set_base(set->crtc,
849 set->x, set->y, old_fb);
854 kfree(save_encoders);
859 set->crtc->enabled = save_enabled;
860 set->crtc->fb = old_fb;
862 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
863 if (!connector->encoder)
866 connector->encoder->crtc = save_crtcs[count++];
871 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
872 connector->encoder = save_encoders[count++];
874 kfree(save_encoders);
877 EXPORT_SYMBOL(drm_crtc_helper_set_config);
879 bool drm_helper_plugged_event(struct drm_device *dev)
883 drm_helper_probe_connector_modes(dev, dev->mode_config.max_width,
884 dev->mode_config.max_height);
886 drm_setup_crtcs(dev);
888 /* alert the driver fb layer */
889 dev->mode_config.funcs->fb_changed(dev);
891 /* FIXME: send hotplug event */
895 * drm_initial_config - setup a sane initial connector configuration
899 * Called at init time, must take mode config lock.
901 * Scan the CRTCs and connectors and try to put together an initial setup.
902 * At the moment, this is a cloned configuration across all heads with
903 * a new framebuffer object as the backing store.
906 * Zero if everything went ok, nonzero otherwise.
908 bool drm_helper_initial_config(struct drm_device *dev)
910 struct drm_connector *connector;
913 count = drm_helper_probe_connector_modes(dev,
914 dev->mode_config.max_width,
915 dev->mode_config.max_height);
918 * None of the available connectors had any modes, so add some
919 * and try to light them up anyway
922 DRM_ERROR("connectors have no modes, using standard modes\n");
923 list_for_each_entry(connector,
924 &dev->mode_config.connector_list,
926 drm_helper_add_std_modes(dev, connector);
929 drm_setup_crtcs(dev);
931 /* alert the driver fb layer */
932 dev->mode_config.funcs->fb_changed(dev);
936 EXPORT_SYMBOL(drm_helper_initial_config);
939 * drm_hotplug_stage_two
941 * @connector hotpluged connector
944 * Caller must hold mode config lock, function might grab struct lock.
946 * Stage two of a hotplug.
949 * Zero on success, errno on failure.
951 int drm_helper_hotplug_stage_two(struct drm_device *dev)
953 drm_helper_plugged_event(dev);
957 EXPORT_SYMBOL(drm_helper_hotplug_stage_two);
959 int drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
960 struct drm_mode_fb_cmd *mode_cmd)
962 fb->width = mode_cmd->width;
963 fb->height = mode_cmd->height;
964 fb->pitch = mode_cmd->pitch;
965 fb->bits_per_pixel = mode_cmd->bpp;
966 fb->depth = mode_cmd->depth;
970 EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct);
972 int drm_helper_resume_force_mode(struct drm_device *dev)
974 struct drm_crtc *crtc;
977 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
982 ret = drm_crtc_helper_set_mode(crtc, &crtc->mode,
983 crtc->x, crtc->y, crtc->fb);
986 DRM_ERROR("failed to set mode on crtc %p\n", crtc);
990 EXPORT_SYMBOL(drm_helper_resume_force_mode);