DRM: add mode setting support
[linux-2.6/mini2440.git] / drivers / gpu / drm / drm_crtc_helper.c
blob887ed33b06941bf34b2e0356541d96158d2a501a
1 /*
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
23 * OF THIS SOFTWARE.
25 * Authors:
26 * Keith Packard
27 * Eric Anholt <eric@anholt.net>
28 * Dave Airlie <airlied@linux.ie>
29 * Jesse Barnes <jesse.barnes@intel.com>
32 #include "drmP.h"
33 #include "drm_crtc.h"
34 #include "drm_crtc_helper.h"
37 * Detailed mode info for a standard 640x480@60Hz monitor
39 static struct drm_display_mode std_mode[] = {
40 { DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 25200, 640, 656,
41 752, 800, 0, 480, 490, 492, 525, 0,
42 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
45 /**
46 * drm_helper_probe_connector_modes - get complete set of display modes
47 * @dev: DRM device
48 * @maxX: max width for modes
49 * @maxY: max height for modes
51 * LOCKING:
52 * Caller must hold mode config lock.
54 * Based on @dev's mode_config layout, scan all the connectors and try to detect
55 * modes on them. Modes will first be added to the connector's probed_modes
56 * list, then culled (based on validity and the @maxX, @maxY parameters) and
57 * put into the normal modes list.
59 * Intended to be used either at bootup time or when major configuration
60 * changes have occurred.
62 * FIXME: take into account monitor limits
64 void drm_helper_probe_single_connector_modes(struct drm_connector *connector,
65 uint32_t maxX, uint32_t maxY)
67 struct drm_device *dev = connector->dev;
68 struct drm_display_mode *mode, *t;
69 struct drm_connector_helper_funcs *connector_funcs =
70 connector->helper_private;
71 int ret;
73 DRM_DEBUG("%s\n", drm_get_connector_name(connector));
74 /* set all modes to the unverified state */
75 list_for_each_entry_safe(mode, t, &connector->modes, head)
76 mode->status = MODE_UNVERIFIED;
78 connector->status = connector->funcs->detect(connector);
80 if (connector->status == connector_status_disconnected) {
81 DRM_DEBUG("%s is disconnected\n",
82 drm_get_connector_name(connector));
83 /* TODO set EDID to NULL */
84 return;
87 ret = (*connector_funcs->get_modes)(connector);
89 if (ret) {
90 drm_mode_connector_list_update(connector);
93 if (maxX && maxY)
94 drm_mode_validate_size(dev, &connector->modes, maxX,
95 maxY, 0);
96 list_for_each_entry_safe(mode, t, &connector->modes, head) {
97 if (mode->status == MODE_OK)
98 mode->status = connector_funcs->mode_valid(connector,
99 mode);
103 drm_mode_prune_invalid(dev, &connector->modes, true);
105 if (list_empty(&connector->modes)) {
106 struct drm_display_mode *stdmode;
108 DRM_DEBUG("No valid modes on %s\n",
109 drm_get_connector_name(connector));
111 /* Should we do this here ???
112 * When no valid EDID modes are available we end up
113 * here and bailed in the past, now we add a standard
114 * 640x480@60Hz mode and carry on.
116 stdmode = drm_mode_duplicate(dev, &std_mode[0]);
117 drm_mode_probed_add(connector, stdmode);
118 drm_mode_list_concat(&connector->probed_modes,
119 &connector->modes);
121 DRM_DEBUG("Adding standard 640x480 @ 60Hz to %s\n",
122 drm_get_connector_name(connector));
125 drm_mode_sort(&connector->modes);
127 DRM_DEBUG("Probed modes for %s\n", drm_get_connector_name(connector));
128 list_for_each_entry_safe(mode, t, &connector->modes, head) {
129 mode->vrefresh = drm_mode_vrefresh(mode);
131 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
132 drm_mode_debug_printmodeline(mode);
135 EXPORT_SYMBOL(drm_helper_probe_single_connector_modes);
137 void drm_helper_probe_connector_modes(struct drm_device *dev, uint32_t maxX,
138 uint32_t maxY)
140 struct drm_connector *connector;
142 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
143 drm_helper_probe_single_connector_modes(connector, maxX, maxY);
146 EXPORT_SYMBOL(drm_helper_probe_connector_modes);
150 * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config
151 * @crtc: CRTC to check
153 * LOCKING:
154 * Caller must hold mode config lock.
156 * Walk @crtc's DRM device's mode_config and see if it's in use.
158 * RETURNS:
159 * True if @crtc is part of the mode_config, false otherwise.
161 bool drm_helper_crtc_in_use(struct drm_crtc *crtc)
163 struct drm_encoder *encoder;
164 struct drm_device *dev = crtc->dev;
165 /* FIXME: Locking around list access? */
166 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
167 if (encoder->crtc == crtc)
168 return true;
169 return false;
171 EXPORT_SYMBOL(drm_helper_crtc_in_use);
174 * drm_disable_unused_functions - disable unused objects
175 * @dev: DRM device
177 * LOCKING:
178 * Caller must hold mode config lock.
180 * If an connector or CRTC isn't part of @dev's mode_config, it can be disabled
181 * by calling its dpms function, which should power it off.
183 void drm_helper_disable_unused_functions(struct drm_device *dev)
185 struct drm_encoder *encoder;
186 struct drm_encoder_helper_funcs *encoder_funcs;
187 struct drm_crtc *crtc;
189 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
190 encoder_funcs = encoder->helper_private;
191 if (!encoder->crtc)
192 (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF);
195 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
196 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
197 crtc->enabled = drm_helper_crtc_in_use(crtc);
198 if (!crtc->enabled) {
199 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
200 crtc->fb = NULL;
204 EXPORT_SYMBOL(drm_helper_disable_unused_functions);
206 static struct drm_display_mode *drm_has_preferred_mode(struct drm_connector *connector, int width, int height)
208 struct drm_display_mode *mode;
210 list_for_each_entry(mode, &connector->modes, head) {
211 if (drm_mode_width(mode) > width ||
212 drm_mode_height(mode) > height)
213 continue;
214 if (mode->type & DRM_MODE_TYPE_PREFERRED)
215 return mode;
217 return NULL;
220 static bool drm_connector_enabled(struct drm_connector *connector, bool strict)
222 bool enable;
224 if (strict) {
225 enable = connector->status == connector_status_connected;
226 } else {
227 enable = connector->status != connector_status_disconnected;
229 return enable;
232 static void drm_enable_connectors(struct drm_device *dev, bool *enabled)
234 bool any_enabled = false;
235 struct drm_connector *connector;
236 int i = 0;
238 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
239 enabled[i] = drm_connector_enabled(connector, true);
240 any_enabled |= enabled[i];
241 i++;
244 if (any_enabled)
245 return;
247 i = 0;
248 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
249 enabled[i] = drm_connector_enabled(connector, false);
250 i++;
254 static bool drm_target_preferred(struct drm_device *dev,
255 struct drm_display_mode **modes,
256 bool *enabled, int width, int height)
258 struct drm_connector *connector;
259 int i = 0;
261 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
263 if (enabled[i] == false) {
264 i++;
265 continue;
268 modes[i] = drm_has_preferred_mode(connector, width, height);
269 if (!modes[i]) {
270 list_for_each_entry(modes[i], &connector->modes, head)
271 break;
273 i++;
275 return true;
278 static int drm_pick_crtcs(struct drm_device *dev,
279 struct drm_crtc **best_crtcs,
280 struct drm_display_mode **modes,
281 int n, int width, int height)
283 int c, o;
284 struct drm_connector *connector;
285 struct drm_connector_helper_funcs *connector_funcs;
286 struct drm_encoder *encoder;
287 struct drm_crtc *best_crtc;
288 int my_score, best_score, score;
289 struct drm_crtc **crtcs, *crtc;
291 if (n == dev->mode_config.num_connector)
292 return 0;
293 c = 0;
294 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
295 if (c == n)
296 break;
297 c++;
300 best_crtcs[n] = NULL;
301 best_crtc = NULL;
302 best_score = drm_pick_crtcs(dev, best_crtcs, modes, n+1, width, height);
303 if (modes[n] == NULL)
304 return best_score;
306 crtcs = kmalloc(dev->mode_config.num_connector *
307 sizeof(struct drm_crtc *), GFP_KERNEL);
308 if (!crtcs)
309 return best_score;
311 my_score = 1;
312 if (connector->status == connector_status_connected)
313 my_score++;
314 if (drm_has_preferred_mode(connector, width, height))
315 my_score++;
317 connector_funcs = connector->helper_private;
318 encoder = connector_funcs->best_encoder(connector);
319 if (!encoder)
320 goto out;
322 connector->encoder = encoder;
324 /* select a crtc for this connector and then attempt to configure
325 remaining connectors */
326 c = 0;
327 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
329 if ((connector->encoder->possible_crtcs & (1 << c)) == 0) {
330 c++;
331 continue;
334 for (o = 0; o < n; o++)
335 if (best_crtcs[o] == crtc)
336 break;
338 if (o < n) {
339 /* ignore cloning for now */
340 c++;
341 continue;
344 crtcs[n] = crtc;
345 memcpy(crtcs, best_crtcs, n * sizeof(struct drm_crtc *));
346 score = my_score + drm_pick_crtcs(dev, crtcs, modes, n + 1,
347 width, height);
348 if (score > best_score) {
349 best_crtc = crtc;
350 best_score = score;
351 memcpy(best_crtcs, crtcs,
352 dev->mode_config.num_connector *
353 sizeof(struct drm_crtc *));
355 c++;
357 out:
358 kfree(crtcs);
359 return best_score;
362 static void drm_setup_crtcs(struct drm_device *dev)
364 struct drm_crtc **crtcs;
365 struct drm_display_mode **modes;
366 struct drm_encoder *encoder;
367 struct drm_connector *connector;
368 bool *enabled;
369 int width, height;
370 int i, ret;
372 width = dev->mode_config.max_width;
373 height = dev->mode_config.max_height;
375 /* clean out all the encoder/crtc combos */
376 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
377 encoder->crtc = NULL;
380 crtcs = kcalloc(dev->mode_config.num_connector,
381 sizeof(struct drm_crtc *), GFP_KERNEL);
382 modes = kcalloc(dev->mode_config.num_connector,
383 sizeof(struct drm_display_mode *), GFP_KERNEL);
384 enabled = kcalloc(dev->mode_config.num_connector,
385 sizeof(bool), GFP_KERNEL);
387 drm_enable_connectors(dev, enabled);
389 ret = drm_target_preferred(dev, modes, enabled, width, height);
390 if (!ret)
391 DRM_ERROR("Unable to find initial modes\n");
393 drm_pick_crtcs(dev, crtcs, modes, 0, width, height);
395 i = 0;
396 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
397 struct drm_display_mode *mode = modes[i];
398 struct drm_crtc *crtc = crtcs[i];
400 if (connector->encoder == NULL) {
401 i++;
402 continue;
405 if (mode && crtc) {
406 crtc->desired_mode = mode;
407 connector->encoder->crtc = crtc;
408 } else
409 connector->encoder->crtc = NULL;
410 i++;
413 kfree(crtcs);
414 kfree(modes);
415 kfree(enabled);
418 * drm_crtc_set_mode - set a mode
419 * @crtc: CRTC to program
420 * @mode: mode to use
421 * @x: width of mode
422 * @y: height of mode
424 * LOCKING:
425 * Caller must hold mode config lock.
427 * Try to set @mode on @crtc. Give @crtc and its associated connectors a chance
428 * to fixup or reject the mode prior to trying to set it.
430 * RETURNS:
431 * True if the mode was set successfully, or false otherwise.
433 bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
434 struct drm_display_mode *mode,
435 int x, int y)
437 struct drm_device *dev = crtc->dev;
438 struct drm_display_mode *adjusted_mode, saved_mode;
439 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
440 struct drm_encoder_helper_funcs *encoder_funcs;
441 int saved_x, saved_y;
442 struct drm_encoder *encoder;
443 bool ret = true;
445 adjusted_mode = drm_mode_duplicate(dev, mode);
447 crtc->enabled = drm_helper_crtc_in_use(crtc);
449 if (!crtc->enabled)
450 return true;
452 saved_mode = crtc->mode;
453 saved_x = crtc->x;
454 saved_y = crtc->y;
456 /* Update crtc values up front so the driver can rely on them for mode
457 * setting.
459 crtc->mode = *mode;
460 crtc->x = x;
461 crtc->y = y;
463 if (drm_mode_equal(&saved_mode, &crtc->mode)) {
464 if (saved_x != crtc->x || saved_y != crtc->y) {
465 crtc_funcs->mode_set_base(crtc, crtc->x, crtc->y);
466 goto done;
470 /* Pass our mode to the connectors and the CRTC to give them a chance to
471 * adjust it according to limitations or connector properties, and also
472 * a chance to reject the mode entirely.
474 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
476 if (encoder->crtc != crtc)
477 continue;
478 encoder_funcs = encoder->helper_private;
479 if (!(ret = encoder_funcs->mode_fixup(encoder, mode,
480 adjusted_mode))) {
481 goto done;
485 if (!(ret = crtc_funcs->mode_fixup(crtc, mode, adjusted_mode))) {
486 goto done;
489 /* Prepare the encoders and CRTCs before setting the mode. */
490 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
492 if (encoder->crtc != crtc)
493 continue;
494 encoder_funcs = encoder->helper_private;
495 /* Disable the encoders as the first thing we do. */
496 encoder_funcs->prepare(encoder);
499 crtc_funcs->prepare(crtc);
501 /* Set up the DPLL and any encoders state that needs to adjust or depend
502 * on the DPLL.
504 crtc_funcs->mode_set(crtc, mode, adjusted_mode, x, y);
506 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
508 if (encoder->crtc != crtc)
509 continue;
511 DRM_INFO("%s: set mode %s %x\n", drm_get_encoder_name(encoder),
512 mode->name, mode->base.id);
513 encoder_funcs = encoder->helper_private;
514 encoder_funcs->mode_set(encoder, mode, adjusted_mode);
517 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
518 crtc_funcs->commit(crtc);
520 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
522 if (encoder->crtc != crtc)
523 continue;
525 encoder_funcs = encoder->helper_private;
526 encoder_funcs->commit(encoder);
530 /* XXX free adjustedmode */
531 drm_mode_destroy(dev, adjusted_mode);
532 /* FIXME: add subpixel order */
533 done:
534 if (!ret) {
535 crtc->mode = saved_mode;
536 crtc->x = saved_x;
537 crtc->y = saved_y;
540 return ret;
542 EXPORT_SYMBOL(drm_crtc_helper_set_mode);
546 * drm_crtc_helper_set_config - set a new config from userspace
547 * @crtc: CRTC to setup
548 * @crtc_info: user provided configuration
549 * @new_mode: new mode to set
550 * @connector_set: set of connectors for the new config
551 * @fb: new framebuffer
553 * LOCKING:
554 * Caller must hold mode config lock.
556 * Setup a new configuration, provided by the user in @crtc_info, and enable
557 * it.
559 * RETURNS:
560 * Zero. (FIXME)
562 int drm_crtc_helper_set_config(struct drm_mode_set *set)
564 struct drm_device *dev;
565 struct drm_crtc **save_crtcs, *new_crtc;
566 struct drm_encoder **save_encoders, *new_encoder;
567 bool save_enabled;
568 bool changed = false;
569 bool flip_or_move = false;
570 struct drm_connector *connector;
571 int count = 0, ro, fail = 0;
572 struct drm_crtc_helper_funcs *crtc_funcs;
573 int ret = 0;
575 DRM_DEBUG("\n");
577 if (!set)
578 return -EINVAL;
580 if (!set->crtc)
581 return -EINVAL;
583 if (!set->crtc->helper_private)
584 return -EINVAL;
586 crtc_funcs = set->crtc->helper_private;
588 DRM_DEBUG("crtc: %p %d fb: %p connectors: %p num_connectors: %d (x, y) (%i, %i)\n",
589 set->crtc, set->crtc->base.id, set->fb, set->connectors,
590 (int)set->num_connectors, set->x, set->y);
592 dev = set->crtc->dev;
594 /* save previous config */
595 save_enabled = set->crtc->enabled;
597 /* this is meant to be num_connector not num_crtc */
598 save_crtcs = kzalloc(dev->mode_config.num_connector *
599 sizeof(struct drm_crtc *), GFP_KERNEL);
600 if (!save_crtcs)
601 return -ENOMEM;
603 save_encoders = kzalloc(dev->mode_config.num_connector *
604 sizeof(struct drm_encoders *), GFP_KERNEL);
605 if (!save_encoders) {
606 kfree(save_crtcs);
607 return -ENOMEM;
610 /* We should be able to check here if the fb has the same properties
611 * and then just flip_or_move it */
612 if (set->crtc->fb != set->fb) {
613 /* if we have no fb then its a change not a flip */
614 if (set->crtc->fb == NULL)
615 changed = true;
616 else
617 flip_or_move = true;
620 if (set->x != set->crtc->x || set->y != set->crtc->y)
621 flip_or_move = true;
623 if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
624 DRM_DEBUG("modes are different\n");
625 drm_mode_debug_printmodeline(&set->crtc->mode);
626 drm_mode_debug_printmodeline(set->mode);
627 changed = true;
630 /* a) traverse passed in connector list and get encoders for them */
631 count = 0;
632 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
633 struct drm_connector_helper_funcs *connector_funcs =
634 connector->helper_private;
635 save_encoders[count++] = connector->encoder;
636 new_encoder = connector->encoder;
637 for (ro = 0; ro < set->num_connectors; ro++) {
638 if (set->connectors[ro] == connector) {
639 new_encoder = connector_funcs->best_encoder(connector);
640 /* if we can't get an encoder for a connector
641 we are setting now - then fail */
642 if (new_encoder == NULL)
643 /* don't break so fail path works correct */
644 fail = 1;
645 break;
649 if (new_encoder != connector->encoder) {
650 changed = true;
651 connector->encoder = new_encoder;
655 if (fail) {
656 ret = -EINVAL;
657 goto fail_no_encoder;
660 count = 0;
661 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
662 if (!connector->encoder)
663 continue;
665 save_crtcs[count++] = connector->encoder->crtc;
667 if (connector->encoder->crtc == set->crtc)
668 new_crtc = NULL;
669 else
670 new_crtc = connector->encoder->crtc;
672 for (ro = 0; ro < set->num_connectors; ro++) {
673 if (set->connectors[ro] == connector)
674 new_crtc = set->crtc;
676 if (new_crtc != connector->encoder->crtc) {
677 changed = true;
678 connector->encoder->crtc = new_crtc;
682 /* mode_set_base is not a required function */
683 if (flip_or_move && !crtc_funcs->mode_set_base)
684 changed = true;
686 if (changed) {
687 set->crtc->fb = set->fb;
688 set->crtc->enabled = (set->mode != NULL);
689 if (set->mode != NULL) {
690 DRM_DEBUG("attempting to set mode from userspace\n");
691 drm_mode_debug_printmodeline(set->mode);
692 if (!drm_crtc_helper_set_mode(set->crtc, set->mode,
693 set->x, set->y)) {
694 ret = -EINVAL;
695 goto fail_set_mode;
697 /* TODO are these needed? */
698 set->crtc->desired_x = set->x;
699 set->crtc->desired_y = set->y;
700 set->crtc->desired_mode = set->mode;
702 drm_helper_disable_unused_functions(dev);
703 } else if (flip_or_move) {
704 if (set->crtc->fb != set->fb)
705 set->crtc->fb = set->fb;
706 crtc_funcs->mode_set_base(set->crtc, set->x, set->y);
709 kfree(save_encoders);
710 kfree(save_crtcs);
711 return 0;
713 fail_set_mode:
714 set->crtc->enabled = save_enabled;
715 count = 0;
716 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
717 connector->encoder->crtc = save_crtcs[count++];
718 fail_no_encoder:
719 kfree(save_crtcs);
720 count = 0;
721 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
722 connector->encoder = save_encoders[count++];
724 kfree(save_encoders);
725 return ret;
727 EXPORT_SYMBOL(drm_crtc_helper_set_config);
729 bool drm_helper_plugged_event(struct drm_device *dev)
731 DRM_DEBUG("\n");
733 drm_helper_probe_connector_modes(dev, dev->mode_config.max_width,
734 dev->mode_config.max_height);
736 drm_setup_crtcs(dev);
738 /* alert the driver fb layer */
739 dev->mode_config.funcs->fb_changed(dev);
741 /* FIXME: send hotplug event */
742 return true;
745 * drm_initial_config - setup a sane initial connector configuration
746 * @dev: DRM device
747 * @can_grow: this configuration is growable
749 * LOCKING:
750 * Called at init time, must take mode config lock.
752 * Scan the CRTCs and connectors and try to put together an initial setup.
753 * At the moment, this is a cloned configuration across all heads with
754 * a new framebuffer object as the backing store.
756 * RETURNS:
757 * Zero if everything went ok, nonzero otherwise.
759 bool drm_helper_initial_config(struct drm_device *dev, bool can_grow)
761 int ret = false;
763 drm_helper_plugged_event(dev);
764 return ret;
766 EXPORT_SYMBOL(drm_helper_initial_config);
769 * drm_hotplug_stage_two
770 * @dev DRM device
771 * @connector hotpluged connector
773 * LOCKING.
774 * Caller must hold mode config lock, function might grab struct lock.
776 * Stage two of a hotplug.
778 * RETURNS:
779 * Zero on success, errno on failure.
781 int drm_helper_hotplug_stage_two(struct drm_device *dev)
783 dev->mode_config.hotplug_counter++;
785 drm_helper_plugged_event(dev);
787 return 0;
789 EXPORT_SYMBOL(drm_helper_hotplug_stage_two);
791 int drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
792 struct drm_mode_fb_cmd *mode_cmd)
794 fb->width = mode_cmd->width;
795 fb->height = mode_cmd->height;
796 fb->pitch = mode_cmd->pitch;
797 fb->bits_per_pixel = mode_cmd->bpp;
798 fb->depth = mode_cmd->depth;
800 return 0;
802 EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct);
804 int drm_helper_resume_force_mode(struct drm_device *dev)
806 struct drm_crtc *crtc;
807 int ret;
809 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
811 if (!crtc->enabled)
812 continue;
814 ret = drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x,
815 crtc->y);
817 if (ret == false)
818 DRM_ERROR("failed to set mode on crtc %p\n", crtc);
820 return 0;
822 EXPORT_SYMBOL(drm_helper_resume_force_mode);