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 #if !defined(__AROS__)
36 #include "drm_fb_helper.h"
38 static bool drm_kms_helper_poll
= true;
39 module_param_named(poll
, drm_kms_helper_poll
, bool, 0600);
42 static void drm_mode_validate_flag(struct drm_connector
*connector
,
45 struct drm_display_mode
*mode
, *t
;
47 if (flags
== (DRM_MODE_FLAG_DBLSCAN
| DRM_MODE_FLAG_INTERLACE
))
50 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
) {
51 if ((mode
->flags
& DRM_MODE_FLAG_INTERLACE
) &&
52 !(flags
& DRM_MODE_FLAG_INTERLACE
))
53 mode
->status
= MODE_NO_INTERLACE
;
54 if ((mode
->flags
& DRM_MODE_FLAG_DBLSCAN
) &&
55 !(flags
& DRM_MODE_FLAG_DBLSCAN
))
56 mode
->status
= MODE_NO_DBLESCAN
;
63 * drm_helper_probe_single_connector_modes - get complete set of display modes
65 * @maxX: max width for modes
66 * @maxY: max height for modes
69 * Caller must hold mode config lock.
71 * Based on @dev's mode_config layout, scan all the connectors and try to detect
72 * modes on them. Modes will first be added to the connector's probed_modes
73 * list, then culled (based on validity and the @maxX, @maxY parameters) and
74 * put into the normal modes list.
76 * Intended to be used either at bootup time or when major configuration
77 * changes have occurred.
79 * FIXME: take into account monitor limits
82 * Number of modes found on @connector.
84 int drm_helper_probe_single_connector_modes(struct drm_connector
*connector
,
85 uint32_t maxX
, uint32_t maxY
)
87 struct drm_device
*dev
= connector
->dev
;
88 struct drm_display_mode
*mode
, *t
;
89 struct drm_connector_helper_funcs
*connector_funcs
=
90 connector
->helper_private
;
94 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector
->base
.id
,
95 drm_get_connector_name(connector
));
96 /* set all modes to the unverified state */
97 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
98 mode
->status
= MODE_UNVERIFIED
;
100 if (connector
->force
) {
101 if (connector
->force
== DRM_FORCE_ON
)
102 connector
->status
= connector_status_connected
;
104 connector
->status
= connector_status_disconnected
;
105 if (connector
->funcs
->force
)
106 connector
->funcs
->force(connector
);
108 connector
->status
= connector
->funcs
->detect(connector
, true);
109 #if !defined(__AROS__)
110 drm_kms_helper_poll_enable(dev
);
114 if (connector
->status
== connector_status_disconnected
) {
115 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] disconnected\n",
116 connector
->base
.id
, drm_get_connector_name(connector
));
117 drm_mode_connector_update_edid_property(connector
, NULL
);
121 count
= (*connector_funcs
->get_modes
)(connector
);
122 if (count
== 0 && connector
->status
== connector_status_connected
)
123 count
= drm_add_modes_noedid(connector
, 1024, 768);
127 drm_mode_connector_list_update(connector
);
130 drm_mode_validate_size(dev
, &connector
->modes
, maxX
,
133 if (connector
->interlace_allowed
)
134 mode_flags
|= DRM_MODE_FLAG_INTERLACE
;
135 if (connector
->doublescan_allowed
)
136 mode_flags
|= DRM_MODE_FLAG_DBLSCAN
;
137 drm_mode_validate_flag(connector
, mode_flags
);
139 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
) {
140 if (mode
->status
== MODE_OK
)
141 mode
->status
= connector_funcs
->mode_valid(connector
,
146 drm_mode_prune_invalid(dev
, &connector
->modes
, true);
148 if (list_empty(&connector
->modes
))
151 drm_mode_sort(&connector
->modes
);
153 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] probed modes :\n", connector
->base
.id
,
154 drm_get_connector_name(connector
));
155 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
) {
156 mode
->vrefresh
= drm_mode_vrefresh(mode
);
158 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
159 drm_mode_debug_printmodeline(mode
);
164 EXPORT_SYMBOL(drm_helper_probe_single_connector_modes
);
167 * drm_helper_encoder_in_use - check if a given encoder is in use
168 * @encoder: encoder to check
171 * Caller must hold mode config lock.
173 * Walk @encoders's DRM device's mode_config and see if it's in use.
176 * True if @encoder is part of the mode_config, false otherwise.
178 bool drm_helper_encoder_in_use(struct drm_encoder
*encoder
)
180 struct drm_connector
*connector
;
181 struct drm_device
*dev
= encoder
->dev
;
182 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
183 if (connector
->encoder
== encoder
)
187 EXPORT_SYMBOL(drm_helper_encoder_in_use
);
190 * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config
191 * @crtc: CRTC to check
194 * Caller must hold mode config lock.
196 * Walk @crtc's DRM device's mode_config and see if it's in use.
199 * True if @crtc is part of the mode_config, false otherwise.
201 bool drm_helper_crtc_in_use(struct drm_crtc
*crtc
)
203 struct drm_encoder
*encoder
;
204 struct drm_device
*dev
= crtc
->dev
;
205 /* FIXME: Locking around list access? */
206 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
207 if (encoder
->crtc
== crtc
&& drm_helper_encoder_in_use(encoder
))
211 EXPORT_SYMBOL(drm_helper_crtc_in_use
);
214 drm_encoder_disable(struct drm_encoder
*encoder
)
216 struct drm_encoder_helper_funcs
*encoder_funcs
= encoder
->helper_private
;
218 if (encoder_funcs
->disable
)
219 (*encoder_funcs
->disable
)(encoder
);
221 (*encoder_funcs
->dpms
)(encoder
, DRM_MODE_DPMS_OFF
);
224 #if !defined(__AROS__)
226 * drm_helper_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_connector
*connector
;
239 struct drm_crtc
*crtc
;
241 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
242 if (!connector
->encoder
)
244 if (connector
->status
== connector_status_disconnected
)
245 connector
->encoder
= NULL
;
248 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
249 if (!drm_helper_encoder_in_use(encoder
)) {
250 drm_encoder_disable(encoder
);
251 /* disconnector encoder from any connector */
252 encoder
->crtc
= NULL
;
256 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
257 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
258 crtc
->enabled
= drm_helper_crtc_in_use(crtc
);
259 if (!crtc
->enabled
) {
260 if (crtc_funcs
->disable
)
261 (*crtc_funcs
->disable
)(crtc
);
263 (*crtc_funcs
->dpms
)(crtc
, DRM_MODE_DPMS_OFF
);
268 EXPORT_SYMBOL(drm_helper_disable_unused_functions
);
272 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
273 * @encoder: encoder to test
274 * @crtc: crtc to test
276 * Return false if @encoder can't be driven by @crtc, true otherwise.
278 static bool drm_encoder_crtc_ok(struct drm_encoder
*encoder
,
279 struct drm_crtc
*crtc
)
281 struct drm_device
*dev
;
282 struct drm_crtc
*tmp
;
285 WARN(!crtc
, "checking null crtc?\n");
289 list_for_each_entry(tmp
, &dev
->mode_config
.crtc_list
, head
) {
295 if (encoder
->possible_crtcs
& crtc_mask
)
301 * Check the CRTC we're going to map each output to vs. its current
302 * CRTC. If they don't match, we have to disable the output and the CRTC
303 * since the driver will have to re-route things.
306 drm_crtc_prepare_encoders(struct drm_device
*dev
)
308 struct drm_encoder_helper_funcs
*encoder_funcs
;
309 struct drm_encoder
*encoder
;
311 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
312 encoder_funcs
= encoder
->helper_private
;
313 /* Disable unused encoders */
314 if (encoder
->crtc
== NULL
)
315 drm_encoder_disable(encoder
);
316 /* Disable encoders whose CRTC is about to change */
317 if (encoder_funcs
->get_crtc
&&
318 encoder
->crtc
!= (*encoder_funcs
->get_crtc
)(encoder
))
319 drm_encoder_disable(encoder
);
324 * drm_crtc_set_mode - set a mode
325 * @crtc: CRTC to program
331 * Caller must hold mode config lock.
333 * Try to set @mode on @crtc. Give @crtc and its associated connectors a chance
334 * to fixup or reject the mode prior to trying to set it.
337 * True if the mode was set successfully, or false otherwise.
339 bool drm_crtc_helper_set_mode(struct drm_crtc
*crtc
,
340 struct drm_display_mode
*mode
,
342 struct drm_framebuffer
*old_fb
)
344 struct drm_device
*dev
= crtc
->dev
;
345 struct drm_display_mode
*adjusted_mode
, saved_mode
, saved_hwmode
;
346 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
347 struct drm_encoder_helper_funcs
*encoder_funcs
;
348 int saved_x
, saved_y
;
349 struct drm_encoder
*encoder
;
352 crtc
->enabled
= drm_helper_crtc_in_use(crtc
);
356 adjusted_mode
= drm_mode_duplicate(dev
, mode
);
358 saved_hwmode
= crtc
->hwmode
;
359 saved_mode
= crtc
->mode
;
363 /* Update crtc values up front so the driver can rely on them for mode
370 /* Pass our mode to the connectors and the CRTC to give them a chance to
371 * adjust it according to limitations or connector properties, and also
372 * a chance to reject the mode entirely.
374 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
376 if (encoder
->crtc
!= crtc
)
378 encoder_funcs
= encoder
->helper_private
;
379 if (!(ret
= encoder_funcs
->mode_fixup(encoder
, mode
,
385 if (!(ret
= crtc_funcs
->mode_fixup(crtc
, mode
, adjusted_mode
))) {
388 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
390 /* Prepare the encoders and CRTCs before setting the mode. */
391 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
393 if (encoder
->crtc
!= crtc
)
395 encoder_funcs
= encoder
->helper_private
;
396 /* Disable the encoders as the first thing we do. */
397 encoder_funcs
->prepare(encoder
);
400 drm_crtc_prepare_encoders(dev
);
402 crtc_funcs
->prepare(crtc
);
404 /* Set up the DPLL and any encoders state that needs to adjust or depend
407 ret
= !crtc_funcs
->mode_set(crtc
, mode
, adjusted_mode
, x
, y
, old_fb
);
411 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
413 if (encoder
->crtc
!= crtc
)
416 DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
417 encoder
->base
.id
, drm_get_encoder_name(encoder
),
418 mode
->base
.id
, mode
->name
);
419 encoder_funcs
= encoder
->helper_private
;
420 encoder_funcs
->mode_set(encoder
, mode
, adjusted_mode
);
423 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
424 crtc_funcs
->commit(crtc
);
426 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
428 if (encoder
->crtc
!= crtc
)
431 encoder_funcs
= encoder
->helper_private
;
432 encoder_funcs
->commit(encoder
);
436 /* Store real post-adjustment hardware mode. */
437 crtc
->hwmode
= *adjusted_mode
;
439 #if !defined(__AROS__)
440 /* Calculate and store various constants which
441 * are later needed by vblank and swap-completion
442 * timestamping. They are derived from true hwmode.
444 drm_calc_timestamping_constants(crtc
);
447 /* FIXME: add subpixel order */
449 drm_mode_destroy(dev
, adjusted_mode
);
451 crtc
->hwmode
= saved_hwmode
;
452 crtc
->mode
= saved_mode
;
459 EXPORT_SYMBOL(drm_crtc_helper_set_mode
);
463 * drm_crtc_helper_set_config - set a new config from userspace
464 * @crtc: CRTC to setup
465 * @crtc_info: user provided configuration
466 * @new_mode: new mode to set
467 * @connector_set: set of connectors for the new config
468 * @fb: new framebuffer
471 * Caller must hold mode config lock.
473 * Setup a new configuration, provided by the user in @crtc_info, and enable
479 int drm_crtc_helper_set_config(struct drm_mode_set
*set
)
481 struct drm_device
*dev
;
482 struct drm_crtc
*save_crtcs
, *new_crtc
, *crtc
;
483 struct drm_encoder
*save_encoders
, *new_encoder
, *encoder
;
484 struct drm_framebuffer
*old_fb
= NULL
;
485 bool mode_changed
= false; /* if true do a full mode set */
486 bool fb_changed
= false; /* if true and !mode_changed just do a flip */
487 struct drm_connector
*save_connectors
, *connector
;
488 int count
= 0, ro
, fail
= 0;
489 struct drm_crtc_helper_funcs
*crtc_funcs
;
501 if (!set
->crtc
->helper_private
)
504 crtc_funcs
= set
->crtc
->helper_private
;
510 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
511 set
->crtc
->base
.id
, set
->fb
->base
.id
,
512 (int)set
->num_connectors
, set
->x
, set
->y
);
514 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set
->crtc
->base
.id
);
516 set
->num_connectors
= 0;
519 dev
= set
->crtc
->dev
;
521 /* Allocate space for the backup of all (non-pointer) crtc, encoder and
523 save_crtcs
= kzalloc(dev
->mode_config
.num_crtc
*
524 sizeof(struct drm_crtc
), GFP_KERNEL
);
528 save_encoders
= kzalloc(dev
->mode_config
.num_encoder
*
529 sizeof(struct drm_encoder
), GFP_KERNEL
);
530 if (!save_encoders
) {
535 save_connectors
= kzalloc(dev
->mode_config
.num_connector
*
536 sizeof(struct drm_connector
), GFP_KERNEL
);
537 if (!save_connectors
) {
539 kfree(save_encoders
);
543 /* Copy data. Note that driver private data is not affected.
544 * Should anything bad happen only the expected state is
545 * restored, not the drivers personal bookkeeping.
548 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
549 save_crtcs
[count
++] = *crtc
;
553 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
554 save_encoders
[count
++] = *encoder
;
558 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
559 save_connectors
[count
++] = *connector
;
562 /* We should be able to check here if the fb has the same properties
563 * and then just flip_or_move it */
564 if (set
->crtc
->fb
!= set
->fb
) {
565 /* If we have no fb then treat it as a full mode set */
566 if (set
->crtc
->fb
== NULL
) {
567 DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
569 } else if (set
->fb
== NULL
) {
571 } else if (set
->fb
->depth
!= set
->crtc
->fb
->depth
) {
573 } else if (set
->fb
->bits_per_pixel
!=
574 set
->crtc
->fb
->bits_per_pixel
) {
580 if (set
->x
!= set
->crtc
->x
|| set
->y
!= set
->crtc
->y
)
583 if (set
->mode
&& !drm_mode_equal(set
->mode
, &set
->crtc
->mode
)) {
584 DRM_DEBUG_KMS("modes are different, full mode set\n");
585 drm_mode_debug_printmodeline(&set
->crtc
->mode
);
586 drm_mode_debug_printmodeline(set
->mode
);
590 /* a) traverse passed in connector list and get encoders for them */
592 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
593 struct drm_connector_helper_funcs
*connector_funcs
=
594 connector
->helper_private
;
595 new_encoder
= connector
->encoder
;
596 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
597 if (set
->connectors
[ro
] == connector
) {
598 new_encoder
= connector_funcs
->best_encoder(connector
);
599 /* if we can't get an encoder for a connector
600 we are setting now - then fail */
601 if (new_encoder
== NULL
)
602 /* don't break so fail path works correct */
608 if (new_encoder
!= connector
->encoder
) {
609 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
611 /* If the encoder is reused for another connector, then
612 * the appropriate crtc will be set later.
614 if (connector
->encoder
)
615 connector
->encoder
->crtc
= NULL
;
616 connector
->encoder
= new_encoder
;
626 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
627 if (!connector
->encoder
)
630 if (connector
->encoder
->crtc
== set
->crtc
)
633 new_crtc
= connector
->encoder
->crtc
;
635 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
636 if (set
->connectors
[ro
] == connector
)
637 new_crtc
= set
->crtc
;
640 /* Make sure the new CRTC will work with the encoder */
642 !drm_encoder_crtc_ok(connector
->encoder
, new_crtc
)) {
646 if (new_crtc
!= connector
->encoder
->crtc
) {
647 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
649 connector
->encoder
->crtc
= new_crtc
;
652 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
653 connector
->base
.id
, drm_get_connector_name(connector
),
656 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
657 connector
->base
.id
, drm_get_connector_name(connector
));
661 /* mode_set_base is not a required function */
662 if (fb_changed
&& !crtc_funcs
->mode_set_base
)
666 set
->crtc
->enabled
= drm_helper_crtc_in_use(set
->crtc
);
667 if (set
->crtc
->enabled
) {
668 DRM_DEBUG_KMS("attempting to set mode from"
670 drm_mode_debug_printmodeline(set
->mode
);
671 old_fb
= set
->crtc
->fb
;
672 set
->crtc
->fb
= set
->fb
;
673 if (!drm_crtc_helper_set_mode(set
->crtc
, set
->mode
,
676 DRM_ERROR("failed to set mode on [CRTC:%d]\n",
678 set
->crtc
->fb
= old_fb
;
682 DRM_DEBUG_KMS("Setting connector DPMS state to on\n");
683 for (i
= 0; i
< set
->num_connectors
; i
++) {
684 DRM_DEBUG_KMS("\t[CONNECTOR:%d:%s] set DPMS on\n", set
->connectors
[i
]->base
.id
,
685 drm_get_connector_name(set
->connectors
[i
]));
686 set
->connectors
[i
]->dpms
= DRM_MODE_DPMS_ON
;
689 #if !defined(__AROS__)
690 drm_helper_disable_unused_functions(dev
);
692 } else if (fb_changed
) {
693 set
->crtc
->x
= set
->x
;
694 set
->crtc
->y
= set
->y
;
696 old_fb
= set
->crtc
->fb
;
697 if (set
->crtc
->fb
!= set
->fb
)
698 set
->crtc
->fb
= set
->fb
;
699 ret
= crtc_funcs
->mode_set_base(set
->crtc
,
700 set
->x
, set
->y
, old_fb
);
702 set
->crtc
->fb
= old_fb
;
707 kfree(save_connectors
);
708 kfree(save_encoders
);
713 /* Restore all previous data. */
715 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
716 *crtc
= save_crtcs
[count
++];
720 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
721 *encoder
= save_encoders
[count
++];
725 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
726 *connector
= save_connectors
[count
++];
729 kfree(save_connectors
);
730 kfree(save_encoders
);
734 EXPORT_SYMBOL(drm_crtc_helper_set_config
);
736 static int drm_helper_choose_encoder_dpms(struct drm_encoder
*encoder
)
738 int dpms
= DRM_MODE_DPMS_OFF
;
739 struct drm_connector
*connector
;
740 struct drm_device
*dev
= encoder
->dev
;
742 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
743 if (connector
->encoder
== encoder
)
744 if (connector
->dpms
< dpms
)
745 dpms
= connector
->dpms
;
749 static int drm_helper_choose_crtc_dpms(struct drm_crtc
*crtc
)
751 int dpms
= DRM_MODE_DPMS_OFF
;
752 struct drm_connector
*connector
;
753 struct drm_device
*dev
= crtc
->dev
;
755 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
756 if (connector
->encoder
&& connector
->encoder
->crtc
== crtc
)
757 if (connector
->dpms
< dpms
)
758 dpms
= connector
->dpms
;
763 * drm_helper_connector_dpms
764 * @connector affected connector
767 * Calls the low-level connector DPMS function, then
768 * calls appropriate encoder and crtc DPMS functions as well
770 void drm_helper_connector_dpms(struct drm_connector
*connector
, int mode
)
772 struct drm_encoder
*encoder
= connector
->encoder
;
773 struct drm_crtc
*crtc
= encoder
? encoder
->crtc
: NULL
;
776 if (mode
== connector
->dpms
)
779 old_dpms
= connector
->dpms
;
780 connector
->dpms
= mode
;
782 /* from off to on, do crtc then encoder */
783 if (mode
< old_dpms
) {
785 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
786 if (crtc_funcs
->dpms
)
787 (*crtc_funcs
->dpms
) (crtc
,
788 drm_helper_choose_crtc_dpms(crtc
));
791 struct drm_encoder_helper_funcs
*encoder_funcs
= encoder
->helper_private
;
792 if (encoder_funcs
->dpms
)
793 (*encoder_funcs
->dpms
) (encoder
,
794 drm_helper_choose_encoder_dpms(encoder
));
798 /* from on to off, do encoder then crtc */
799 if (mode
> old_dpms
) {
801 struct drm_encoder_helper_funcs
*encoder_funcs
= encoder
->helper_private
;
802 if (encoder_funcs
->dpms
)
803 (*encoder_funcs
->dpms
) (encoder
,
804 drm_helper_choose_encoder_dpms(encoder
));
807 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
808 if (crtc_funcs
->dpms
)
809 (*crtc_funcs
->dpms
) (crtc
,
810 drm_helper_choose_crtc_dpms(crtc
));
816 EXPORT_SYMBOL(drm_helper_connector_dpms
);
818 int drm_helper_mode_fill_fb_struct(struct drm_framebuffer
*fb
,
819 struct drm_mode_fb_cmd
*mode_cmd
)
821 fb
->width
= mode_cmd
->width
;
822 fb
->height
= mode_cmd
->height
;
823 fb
->pitch
= mode_cmd
->pitch
;
824 fb
->bits_per_pixel
= mode_cmd
->bpp
;
825 fb
->depth
= mode_cmd
->depth
;
829 EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct
);
831 #if !defined(__AROS__)
832 int drm_helper_resume_force_mode(struct drm_device
*dev
)
834 struct drm_crtc
*crtc
;
835 struct drm_encoder
*encoder
;
836 struct drm_encoder_helper_funcs
*encoder_funcs
;
837 struct drm_crtc_helper_funcs
*crtc_funcs
;
840 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
845 ret
= drm_crtc_helper_set_mode(crtc
, &crtc
->mode
,
846 crtc
->x
, crtc
->y
, crtc
->fb
);
849 DRM_ERROR("failed to set mode on crtc %p\n", crtc
);
851 /* Turn off outputs that were already powered off */
852 if (drm_helper_choose_crtc_dpms(crtc
)) {
853 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
855 if(encoder
->crtc
!= crtc
)
858 encoder_funcs
= encoder
->helper_private
;
859 if (encoder_funcs
->dpms
)
860 (*encoder_funcs
->dpms
) (encoder
,
861 drm_helper_choose_encoder_dpms(encoder
));
864 crtc_funcs
= crtc
->helper_private
;
865 if (crtc_funcs
->dpms
)
866 (*crtc_funcs
->dpms
) (crtc
,
867 drm_helper_choose_crtc_dpms(crtc
));
870 /* disable the unused connectors while restoring the modesetting */
871 drm_helper_disable_unused_functions(dev
);
874 EXPORT_SYMBOL(drm_helper_resume_force_mode
);
876 #define DRM_OUTPUT_POLL_PERIOD (10*HZ)
877 static void output_poll_execute(struct work_struct
*work
)
879 struct delayed_work
*delayed_work
= to_delayed_work(work
);
880 struct drm_device
*dev
= container_of(delayed_work
, struct drm_device
, mode_config
.output_poll_work
);
881 struct drm_connector
*connector
;
882 enum drm_connector_status old_status
;
883 bool repoll
= false, changed
= false;
885 if (!drm_kms_helper_poll
)
888 mutex_lock(&dev
->mode_config
.mutex
);
889 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
891 /* if this is HPD or polled don't check it -
892 TV out for instance */
893 if (!connector
->polled
)
896 else if (connector
->polled
& (DRM_CONNECTOR_POLL_CONNECT
| DRM_CONNECTOR_POLL_DISCONNECT
))
899 old_status
= connector
->status
;
900 /* if we are connected and don't want to poll for disconnect
902 if (old_status
== connector_status_connected
&&
903 !(connector
->polled
& DRM_CONNECTOR_POLL_DISCONNECT
) &&
904 !(connector
->polled
& DRM_CONNECTOR_POLL_HPD
))
907 connector
->status
= connector
->funcs
->detect(connector
, false);
908 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %d to %d\n",
910 drm_get_connector_name(connector
),
911 old_status
, connector
->status
);
912 if (old_status
!= connector
->status
)
916 mutex_unlock(&dev
->mode_config
.mutex
);
919 /* send a uevent + call fbdev */
920 drm_sysfs_hotplug_event(dev
);
921 if (dev
->mode_config
.funcs
->output_poll_changed
)
922 dev
->mode_config
.funcs
->output_poll_changed(dev
);
926 queue_delayed_work(system_nrt_wq
, delayed_work
, DRM_OUTPUT_POLL_PERIOD
);
929 void drm_kms_helper_poll_disable(struct drm_device
*dev
)
931 if (!dev
->mode_config
.poll_enabled
)
933 cancel_delayed_work_sync(&dev
->mode_config
.output_poll_work
);
935 EXPORT_SYMBOL(drm_kms_helper_poll_disable
);
937 void drm_kms_helper_poll_enable(struct drm_device
*dev
)
940 struct drm_connector
*connector
;
942 if (!dev
->mode_config
.poll_enabled
|| !drm_kms_helper_poll
)
945 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
946 if (connector
->polled
)
951 queue_delayed_work(system_nrt_wq
, &dev
->mode_config
.output_poll_work
, DRM_OUTPUT_POLL_PERIOD
);
953 EXPORT_SYMBOL(drm_kms_helper_poll_enable
);
955 void drm_kms_helper_poll_init(struct drm_device
*dev
)
957 INIT_DELAYED_WORK(&dev
->mode_config
.output_poll_work
, output_poll_execute
);
958 dev
->mode_config
.poll_enabled
= true;
960 drm_kms_helper_poll_enable(dev
);
962 EXPORT_SYMBOL(drm_kms_helper_poll_init
);
964 void drm_kms_helper_poll_fini(struct drm_device
*dev
)
966 drm_kms_helper_poll_disable(dev
);
968 EXPORT_SYMBOL(drm_kms_helper_poll_fini
);
970 void drm_helper_hpd_irq_event(struct drm_device
*dev
)
972 if (!dev
->mode_config
.poll_enabled
)
975 /* kill timer and schedule immediate execution, this doesn't block */
976 cancel_delayed_work(&dev
->mode_config
.output_poll_work
);
977 if (drm_kms_helper_poll
)
978 queue_delayed_work(system_nrt_wq
, &dev
->mode_config
.output_poll_work
, 0);
980 EXPORT_SYMBOL(drm_helper_hpd_irq_event
);