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"
35 #include "drm_fb_helper.h"
37 static void drm_mode_validate_flag(struct drm_connector
*connector
,
40 struct drm_display_mode
*mode
, *t
;
42 if (flags
== (DRM_MODE_FLAG_DBLSCAN
| DRM_MODE_FLAG_INTERLACE
))
45 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
) {
46 if ((mode
->flags
& DRM_MODE_FLAG_INTERLACE
) &&
47 !(flags
& DRM_MODE_FLAG_INTERLACE
))
48 mode
->status
= MODE_NO_INTERLACE
;
49 if ((mode
->flags
& DRM_MODE_FLAG_DBLSCAN
) &&
50 !(flags
& DRM_MODE_FLAG_DBLSCAN
))
51 mode
->status
= MODE_NO_DBLESCAN
;
58 * drm_helper_probe_single_connector_modes - get complete set of display modes
60 * @maxX: max width for modes
61 * @maxY: max height for modes
64 * Caller must hold mode config lock.
66 * Based on @dev's mode_config layout, scan all the connectors and try to detect
67 * modes on them. Modes will first be added to the connector's probed_modes
68 * list, then culled (based on validity and the @maxX, @maxY parameters) and
69 * put into the normal modes list.
71 * Intended to be used either at bootup time or when major configuration
72 * changes have occurred.
74 * FIXME: take into account monitor limits
77 * Number of modes found on @connector.
79 int drm_helper_probe_single_connector_modes(struct drm_connector
*connector
,
80 uint32_t maxX
, uint32_t maxY
)
82 struct drm_device
*dev
= connector
->dev
;
83 struct drm_display_mode
*mode
, *t
;
84 struct drm_connector_helper_funcs
*connector_funcs
=
85 connector
->helper_private
;
89 DRM_DEBUG_KMS("%s\n", drm_get_connector_name(connector
));
90 /* set all modes to the unverified state */
91 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
92 mode
->status
= MODE_UNVERIFIED
;
94 if (connector
->force
) {
95 if (connector
->force
== DRM_FORCE_ON
)
96 connector
->status
= connector_status_connected
;
98 connector
->status
= connector_status_disconnected
;
99 if (connector
->funcs
->force
)
100 connector
->funcs
->force(connector
);
102 connector
->status
= connector
->funcs
->detect(connector
);
104 if (connector
->status
== connector_status_disconnected
) {
105 DRM_DEBUG_KMS("%s is disconnected\n",
106 drm_get_connector_name(connector
));
107 drm_mode_connector_update_edid_property(connector
, NULL
);
111 count
= (*connector_funcs
->get_modes
)(connector
);
113 count
= drm_add_modes_noedid(connector
, 1024, 768);
118 drm_mode_connector_list_update(connector
);
121 drm_mode_validate_size(dev
, &connector
->modes
, maxX
,
124 if (connector
->interlace_allowed
)
125 mode_flags
|= DRM_MODE_FLAG_INTERLACE
;
126 if (connector
->doublescan_allowed
)
127 mode_flags
|= DRM_MODE_FLAG_DBLSCAN
;
128 drm_mode_validate_flag(connector
, mode_flags
);
130 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
) {
131 if (mode
->status
== MODE_OK
)
132 mode
->status
= connector_funcs
->mode_valid(connector
,
137 drm_mode_prune_invalid(dev
, &connector
->modes
, true);
139 if (list_empty(&connector
->modes
))
142 drm_mode_sort(&connector
->modes
);
144 DRM_DEBUG_KMS("Probed modes for %s\n",
145 drm_get_connector_name(connector
));
146 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
) {
147 mode
->vrefresh
= drm_mode_vrefresh(mode
);
149 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
150 drm_mode_debug_printmodeline(mode
);
155 EXPORT_SYMBOL(drm_helper_probe_single_connector_modes
);
158 * drm_helper_encoder_in_use - check if a given encoder is in use
159 * @encoder: encoder to check
162 * Caller must hold mode config lock.
164 * Walk @encoders's DRM device's mode_config and see if it's in use.
167 * True if @encoder is part of the mode_config, false otherwise.
169 bool drm_helper_encoder_in_use(struct drm_encoder
*encoder
)
171 struct drm_connector
*connector
;
172 struct drm_device
*dev
= encoder
->dev
;
173 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
174 if (connector
->encoder
== encoder
)
178 EXPORT_SYMBOL(drm_helper_encoder_in_use
);
181 * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config
182 * @crtc: CRTC to check
185 * Caller must hold mode config lock.
187 * Walk @crtc's DRM device's mode_config and see if it's in use.
190 * True if @crtc is part of the mode_config, false otherwise.
192 bool drm_helper_crtc_in_use(struct drm_crtc
*crtc
)
194 struct drm_encoder
*encoder
;
195 struct drm_device
*dev
= crtc
->dev
;
196 /* FIXME: Locking around list access? */
197 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
198 if (encoder
->crtc
== crtc
&& drm_helper_encoder_in_use(encoder
))
202 EXPORT_SYMBOL(drm_helper_crtc_in_use
);
205 * drm_helper_disable_unused_functions - disable unused objects
209 * Caller must hold mode config lock.
211 * If an connector or CRTC isn't part of @dev's mode_config, it can be disabled
212 * by calling its dpms function, which should power it off.
214 void drm_helper_disable_unused_functions(struct drm_device
*dev
)
216 struct drm_encoder
*encoder
;
217 struct drm_connector
*connector
;
218 struct drm_encoder_helper_funcs
*encoder_funcs
;
219 struct drm_crtc
*crtc
;
221 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
222 if (!connector
->encoder
)
224 if (connector
->status
== connector_status_disconnected
)
225 connector
->encoder
= NULL
;
228 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
229 encoder_funcs
= encoder
->helper_private
;
230 if (!drm_helper_encoder_in_use(encoder
)) {
231 if (encoder_funcs
->disable
)
232 (*encoder_funcs
->disable
)(encoder
);
234 (*encoder_funcs
->dpms
)(encoder
, DRM_MODE_DPMS_OFF
);
235 /* disconnector encoder from any connector */
236 encoder
->crtc
= NULL
;
240 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
241 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
242 crtc
->enabled
= drm_helper_crtc_in_use(crtc
);
243 if (!crtc
->enabled
) {
244 crtc_funcs
->dpms(crtc
, DRM_MODE_DPMS_OFF
);
249 EXPORT_SYMBOL(drm_helper_disable_unused_functions
);
252 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
253 * @encoder: encoder to test
254 * @crtc: crtc to test
256 * Return false if @encoder can't be driven by @crtc, true otherwise.
258 static bool drm_encoder_crtc_ok(struct drm_encoder
*encoder
,
259 struct drm_crtc
*crtc
)
261 struct drm_device
*dev
;
262 struct drm_crtc
*tmp
;
265 WARN(!crtc
, "checking null crtc?");
269 list_for_each_entry(tmp
, &dev
->mode_config
.crtc_list
, head
) {
275 if (encoder
->possible_crtcs
& crtc_mask
)
281 * Check the CRTC we're going to map each output to vs. its current
282 * CRTC. If they don't match, we have to disable the output and the CRTC
283 * since the driver will have to re-route things.
286 drm_crtc_prepare_encoders(struct drm_device
*dev
)
288 struct drm_encoder_helper_funcs
*encoder_funcs
;
289 struct drm_encoder
*encoder
;
291 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
292 encoder_funcs
= encoder
->helper_private
;
293 /* Disable unused encoders */
294 if (encoder
->crtc
== NULL
)
295 (*encoder_funcs
->dpms
)(encoder
, DRM_MODE_DPMS_OFF
);
296 /* Disable encoders whose CRTC is about to change */
297 if (encoder_funcs
->get_crtc
&&
298 encoder
->crtc
!= (*encoder_funcs
->get_crtc
)(encoder
))
299 (*encoder_funcs
->dpms
)(encoder
, DRM_MODE_DPMS_OFF
);
304 * drm_crtc_set_mode - set a mode
305 * @crtc: CRTC to program
311 * Caller must hold mode config lock.
313 * Try to set @mode on @crtc. Give @crtc and its associated connectors a chance
314 * to fixup or reject the mode prior to trying to set it.
317 * True if the mode was set successfully, or false otherwise.
319 bool drm_crtc_helper_set_mode(struct drm_crtc
*crtc
,
320 struct drm_display_mode
*mode
,
322 struct drm_framebuffer
*old_fb
)
324 struct drm_device
*dev
= crtc
->dev
;
325 struct drm_display_mode
*adjusted_mode
, saved_mode
;
326 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
327 struct drm_encoder_helper_funcs
*encoder_funcs
;
328 int saved_x
, saved_y
;
329 struct drm_encoder
*encoder
;
332 adjusted_mode
= drm_mode_duplicate(dev
, mode
);
334 crtc
->enabled
= drm_helper_crtc_in_use(crtc
);
339 saved_mode
= crtc
->mode
;
343 /* Update crtc values up front so the driver can rely on them for mode
350 /* Pass our mode to the connectors and the CRTC to give them a chance to
351 * adjust it according to limitations or connector properties, and also
352 * a chance to reject the mode entirely.
354 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
356 if (encoder
->crtc
!= crtc
)
358 encoder_funcs
= encoder
->helper_private
;
359 if (!(ret
= encoder_funcs
->mode_fixup(encoder
, mode
,
365 if (!(ret
= crtc_funcs
->mode_fixup(crtc
, mode
, adjusted_mode
))) {
369 /* Prepare the encoders and CRTCs before setting the mode. */
370 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
372 if (encoder
->crtc
!= crtc
)
374 encoder_funcs
= encoder
->helper_private
;
375 /* Disable the encoders as the first thing we do. */
376 encoder_funcs
->prepare(encoder
);
379 drm_crtc_prepare_encoders(dev
);
381 crtc_funcs
->prepare(crtc
);
383 /* Set up the DPLL and any encoders state that needs to adjust or depend
386 ret
= !crtc_funcs
->mode_set(crtc
, mode
, adjusted_mode
, x
, y
, old_fb
);
390 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
392 if (encoder
->crtc
!= crtc
)
395 DRM_DEBUG("%s: set mode %s %x\n", drm_get_encoder_name(encoder
),
396 mode
->name
, mode
->base
.id
);
397 encoder_funcs
= encoder
->helper_private
;
398 encoder_funcs
->mode_set(encoder
, mode
, adjusted_mode
);
401 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
402 crtc_funcs
->commit(crtc
);
404 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
406 if (encoder
->crtc
!= crtc
)
409 encoder_funcs
= encoder
->helper_private
;
410 encoder_funcs
->commit(encoder
);
414 /* XXX free adjustedmode */
415 drm_mode_destroy(dev
, adjusted_mode
);
416 /* FIXME: add subpixel order */
419 crtc
->mode
= saved_mode
;
426 EXPORT_SYMBOL(drm_crtc_helper_set_mode
);
430 * drm_crtc_helper_set_config - set a new config from userspace
431 * @crtc: CRTC to setup
432 * @crtc_info: user provided configuration
433 * @new_mode: new mode to set
434 * @connector_set: set of connectors for the new config
435 * @fb: new framebuffer
438 * Caller must hold mode config lock.
440 * Setup a new configuration, provided by the user in @crtc_info, and enable
446 int drm_crtc_helper_set_config(struct drm_mode_set
*set
)
448 struct drm_device
*dev
;
449 struct drm_crtc
*save_crtcs
, *new_crtc
, *crtc
;
450 struct drm_encoder
*save_encoders
, *new_encoder
, *encoder
;
451 struct drm_framebuffer
*old_fb
= NULL
;
452 bool mode_changed
= false; /* if true do a full mode set */
453 bool fb_changed
= false; /* if true and !mode_changed just do a flip */
454 struct drm_connector
*save_connectors
, *connector
;
455 int count
= 0, ro
, fail
= 0;
456 struct drm_crtc_helper_funcs
*crtc_funcs
;
467 if (!set
->crtc
->helper_private
)
470 crtc_funcs
= set
->crtc
->helper_private
;
472 DRM_DEBUG_KMS("crtc: %p %d fb: %p connectors: %p num_connectors:"
473 " %d (x, y) (%i, %i)\n",
474 set
->crtc
, set
->crtc
->base
.id
, set
->fb
, set
->connectors
,
475 (int)set
->num_connectors
, set
->x
, set
->y
);
477 dev
= set
->crtc
->dev
;
479 /* Allocate space for the backup of all (non-pointer) crtc, encoder and
481 save_crtcs
= kzalloc(dev
->mode_config
.num_crtc
*
482 sizeof(struct drm_crtc
), GFP_KERNEL
);
486 save_encoders
= kzalloc(dev
->mode_config
.num_encoder
*
487 sizeof(struct drm_encoder
), GFP_KERNEL
);
488 if (!save_encoders
) {
493 save_connectors
= kzalloc(dev
->mode_config
.num_connector
*
494 sizeof(struct drm_connector
), GFP_KERNEL
);
495 if (!save_connectors
) {
497 kfree(save_encoders
);
501 /* Copy data. Note that driver private data is not affected.
502 * Should anything bad happen only the expected state is
503 * restored, not the drivers personal bookkeeping.
506 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
507 save_crtcs
[count
++] = *crtc
;
511 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
512 save_encoders
[count
++] = *encoder
;
516 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
517 save_connectors
[count
++] = *connector
;
520 /* We should be able to check here if the fb has the same properties
521 * and then just flip_or_move it */
522 if (set
->crtc
->fb
!= set
->fb
) {
523 /* If we have no fb then treat it as a full mode set */
524 if (set
->crtc
->fb
== NULL
) {
525 DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
527 } else if (set
->fb
== NULL
) {
533 if (set
->x
!= set
->crtc
->x
|| set
->y
!= set
->crtc
->y
)
536 if (set
->mode
&& !drm_mode_equal(set
->mode
, &set
->crtc
->mode
)) {
537 DRM_DEBUG_KMS("modes are different, full mode set\n");
538 drm_mode_debug_printmodeline(&set
->crtc
->mode
);
539 drm_mode_debug_printmodeline(set
->mode
);
543 /* a) traverse passed in connector list and get encoders for them */
545 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
546 struct drm_connector_helper_funcs
*connector_funcs
=
547 connector
->helper_private
;
548 new_encoder
= connector
->encoder
;
549 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
550 if (set
->connectors
[ro
] == connector
) {
551 new_encoder
= connector_funcs
->best_encoder(connector
);
552 /* if we can't get an encoder for a connector
553 we are setting now - then fail */
554 if (new_encoder
== NULL
)
555 /* don't break so fail path works correct */
561 if (new_encoder
!= connector
->encoder
) {
562 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
564 /* If the encoder is reused for another connector, then
565 * the appropriate crtc will be set later.
567 if (connector
->encoder
)
568 connector
->encoder
->crtc
= NULL
;
569 connector
->encoder
= new_encoder
;
579 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
580 if (!connector
->encoder
)
583 if (connector
->encoder
->crtc
== set
->crtc
)
586 new_crtc
= connector
->encoder
->crtc
;
588 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
589 if (set
->connectors
[ro
] == connector
)
590 new_crtc
= set
->crtc
;
593 /* Make sure the new CRTC will work with the encoder */
595 !drm_encoder_crtc_ok(connector
->encoder
, new_crtc
)) {
599 if (new_crtc
!= connector
->encoder
->crtc
) {
600 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
602 connector
->encoder
->crtc
= new_crtc
;
604 DRM_DEBUG_KMS("setting connector %d crtc to %p\n",
605 connector
->base
.id
, new_crtc
);
608 /* mode_set_base is not a required function */
609 if (fb_changed
&& !crtc_funcs
->mode_set_base
)
613 old_fb
= set
->crtc
->fb
;
614 set
->crtc
->fb
= set
->fb
;
615 set
->crtc
->enabled
= (set
->mode
!= NULL
);
616 if (set
->mode
!= NULL
) {
617 DRM_DEBUG_KMS("attempting to set mode from"
619 drm_mode_debug_printmodeline(set
->mode
);
620 if (!drm_crtc_helper_set_mode(set
->crtc
, set
->mode
,
623 DRM_ERROR("failed to set mode on crtc %p\n",
629 drm_helper_disable_unused_functions(dev
);
630 } else if (fb_changed
) {
631 set
->crtc
->x
= set
->x
;
632 set
->crtc
->y
= set
->y
;
634 old_fb
= set
->crtc
->fb
;
635 if (set
->crtc
->fb
!= set
->fb
)
636 set
->crtc
->fb
= set
->fb
;
637 ret
= crtc_funcs
->mode_set_base(set
->crtc
,
638 set
->x
, set
->y
, old_fb
);
643 kfree(save_connectors
);
644 kfree(save_encoders
);
649 /* Restore all previous data. */
651 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
652 *crtc
= save_crtcs
[count
++];
656 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
657 *encoder
= save_encoders
[count
++];
661 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
662 *connector
= save_connectors
[count
++];
665 kfree(save_connectors
);
666 kfree(save_encoders
);
670 EXPORT_SYMBOL(drm_crtc_helper_set_config
);
672 static int drm_helper_choose_encoder_dpms(struct drm_encoder
*encoder
)
674 int dpms
= DRM_MODE_DPMS_OFF
;
675 struct drm_connector
*connector
;
676 struct drm_device
*dev
= encoder
->dev
;
678 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
679 if (connector
->encoder
== encoder
)
680 if (connector
->dpms
< dpms
)
681 dpms
= connector
->dpms
;
685 static int drm_helper_choose_crtc_dpms(struct drm_crtc
*crtc
)
687 int dpms
= DRM_MODE_DPMS_OFF
;
688 struct drm_connector
*connector
;
689 struct drm_device
*dev
= crtc
->dev
;
691 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
692 if (connector
->encoder
&& connector
->encoder
->crtc
== crtc
)
693 if (connector
->dpms
< dpms
)
694 dpms
= connector
->dpms
;
699 * drm_helper_connector_dpms
700 * @connector affected connector
703 * Calls the low-level connector DPMS function, then
704 * calls appropriate encoder and crtc DPMS functions as well
706 void drm_helper_connector_dpms(struct drm_connector
*connector
, int mode
)
708 struct drm_encoder
*encoder
= connector
->encoder
;
709 struct drm_crtc
*crtc
= encoder
? encoder
->crtc
: NULL
;
712 if (mode
== connector
->dpms
)
715 old_dpms
= connector
->dpms
;
716 connector
->dpms
= mode
;
718 /* from off to on, do crtc then encoder */
719 if (mode
< old_dpms
) {
721 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
722 if (crtc_funcs
->dpms
)
723 (*crtc_funcs
->dpms
) (crtc
,
724 drm_helper_choose_crtc_dpms(crtc
));
727 struct drm_encoder_helper_funcs
*encoder_funcs
= encoder
->helper_private
;
728 if (encoder_funcs
->dpms
)
729 (*encoder_funcs
->dpms
) (encoder
,
730 drm_helper_choose_encoder_dpms(encoder
));
734 /* from on to off, do encoder then crtc */
735 if (mode
> old_dpms
) {
737 struct drm_encoder_helper_funcs
*encoder_funcs
= encoder
->helper_private
;
738 if (encoder_funcs
->dpms
)
739 (*encoder_funcs
->dpms
) (encoder
,
740 drm_helper_choose_encoder_dpms(encoder
));
743 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
744 if (crtc_funcs
->dpms
)
745 (*crtc_funcs
->dpms
) (crtc
,
746 drm_helper_choose_crtc_dpms(crtc
));
752 EXPORT_SYMBOL(drm_helper_connector_dpms
);
754 int drm_helper_mode_fill_fb_struct(struct drm_framebuffer
*fb
,
755 struct drm_mode_fb_cmd
*mode_cmd
)
757 fb
->width
= mode_cmd
->width
;
758 fb
->height
= mode_cmd
->height
;
759 fb
->pitch
= mode_cmd
->pitch
;
760 fb
->bits_per_pixel
= mode_cmd
->bpp
;
761 fb
->depth
= mode_cmd
->depth
;
765 EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct
);
767 int drm_helper_resume_force_mode(struct drm_device
*dev
)
769 struct drm_crtc
*crtc
;
770 struct drm_encoder
*encoder
;
771 struct drm_encoder_helper_funcs
*encoder_funcs
;
772 struct drm_crtc_helper_funcs
*crtc_funcs
;
775 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
780 ret
= drm_crtc_helper_set_mode(crtc
, &crtc
->mode
,
781 crtc
->x
, crtc
->y
, crtc
->fb
);
784 DRM_ERROR("failed to set mode on crtc %p\n", crtc
);
786 /* Turn off outputs that were already powered off */
787 if (drm_helper_choose_crtc_dpms(crtc
)) {
788 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
790 if(encoder
->crtc
!= crtc
)
793 encoder_funcs
= encoder
->helper_private
;
794 if (encoder_funcs
->dpms
)
795 (*encoder_funcs
->dpms
) (encoder
,
796 drm_helper_choose_encoder_dpms(encoder
));
798 crtc_funcs
= crtc
->helper_private
;
799 if (crtc_funcs
->dpms
)
800 (*crtc_funcs
->dpms
) (crtc
,
801 drm_helper_choose_crtc_dpms(crtc
));
805 /* disable the unused connectors while restoring the modesetting */
806 drm_helper_disable_unused_functions(dev
);
809 EXPORT_SYMBOL(drm_helper_resume_force_mode
);
811 static struct slow_work_ops output_poll_ops
;
813 #define DRM_OUTPUT_POLL_PERIOD (10*HZ)
814 static void output_poll_execute(struct slow_work
*work
)
816 struct delayed_slow_work
*delayed_work
= container_of(work
, struct delayed_slow_work
, work
);
817 struct drm_device
*dev
= container_of(delayed_work
, struct drm_device
, mode_config
.output_poll_slow_work
);
818 struct drm_connector
*connector
;
819 enum drm_connector_status old_status
, status
;
820 bool repoll
= false, changed
= false;
823 mutex_lock(&dev
->mode_config
.mutex
);
824 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
826 /* if this is HPD or polled don't check it -
827 TV out for instance */
828 if (!connector
->polled
)
831 else if (connector
->polled
& (DRM_CONNECTOR_POLL_CONNECT
| DRM_CONNECTOR_POLL_DISCONNECT
))
834 old_status
= connector
->status
;
835 /* if we are connected and don't want to poll for disconnect
837 if (old_status
== connector_status_connected
&&
838 !(connector
->polled
& DRM_CONNECTOR_POLL_DISCONNECT
) &&
839 !(connector
->polled
& DRM_CONNECTOR_POLL_HPD
))
842 status
= connector
->funcs
->detect(connector
);
843 if (old_status
!= status
)
847 mutex_unlock(&dev
->mode_config
.mutex
);
850 /* send a uevent + call fbdev */
851 drm_sysfs_hotplug_event(dev
);
852 if (dev
->mode_config
.funcs
->output_poll_changed
)
853 dev
->mode_config
.funcs
->output_poll_changed(dev
);
857 ret
= delayed_slow_work_enqueue(delayed_work
, DRM_OUTPUT_POLL_PERIOD
);
859 DRM_ERROR("delayed enqueue failed %d\n", ret
);
863 void drm_kms_helper_poll_disable(struct drm_device
*dev
)
865 if (!dev
->mode_config
.poll_enabled
)
867 delayed_slow_work_cancel(&dev
->mode_config
.output_poll_slow_work
);
869 EXPORT_SYMBOL(drm_kms_helper_poll_disable
);
871 void drm_kms_helper_poll_enable(struct drm_device
*dev
)
874 struct drm_connector
*connector
;
877 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
878 if (connector
->polled
)
883 ret
= delayed_slow_work_enqueue(&dev
->mode_config
.output_poll_slow_work
, DRM_OUTPUT_POLL_PERIOD
);
885 DRM_ERROR("delayed enqueue failed %d\n", ret
);
888 EXPORT_SYMBOL(drm_kms_helper_poll_enable
);
890 void drm_kms_helper_poll_init(struct drm_device
*dev
)
892 slow_work_register_user(THIS_MODULE
);
893 delayed_slow_work_init(&dev
->mode_config
.output_poll_slow_work
,
895 dev
->mode_config
.poll_enabled
= true;
897 drm_kms_helper_poll_enable(dev
);
899 EXPORT_SYMBOL(drm_kms_helper_poll_init
);
901 void drm_kms_helper_poll_fini(struct drm_device
*dev
)
903 drm_kms_helper_poll_disable(dev
);
904 slow_work_unregister_user(THIS_MODULE
);
906 EXPORT_SYMBOL(drm_kms_helper_poll_fini
);
908 void drm_helper_hpd_irq_event(struct drm_device
*dev
)
910 if (!dev
->mode_config
.poll_enabled
)
912 delayed_slow_work_cancel(&dev
->mode_config
.output_poll_slow_work
);
913 /* schedule a slow work asap */
914 delayed_slow_work_enqueue(&dev
->mode_config
.output_poll_slow_work
, 0);
916 EXPORT_SYMBOL(drm_helper_hpd_irq_event
);
918 static struct slow_work_ops output_poll_ops
= {
919 .execute
= output_poll_execute
,