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("[CONNECTOR:%d:%s]\n", connector
->base
.id
,
90 drm_get_connector_name(connector
));
91 /* set all modes to the unverified state */
92 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
93 mode
->status
= MODE_UNVERIFIED
;
95 if (connector
->force
) {
96 if (connector
->force
== DRM_FORCE_ON
)
97 connector
->status
= connector_status_connected
;
99 connector
->status
= connector_status_disconnected
;
100 if (connector
->funcs
->force
)
101 connector
->funcs
->force(connector
);
103 connector
->status
= connector
->funcs
->detect(connector
);
105 if (connector
->status
== connector_status_disconnected
) {
106 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] disconnected\n",
107 connector
->base
.id
, drm_get_connector_name(connector
));
108 drm_mode_connector_update_edid_property(connector
, NULL
);
112 count
= (*connector_funcs
->get_modes
)(connector
);
114 count
= drm_add_modes_noedid(connector
, 1024, 768);
119 drm_mode_connector_list_update(connector
);
122 drm_mode_validate_size(dev
, &connector
->modes
, maxX
,
125 if (connector
->interlace_allowed
)
126 mode_flags
|= DRM_MODE_FLAG_INTERLACE
;
127 if (connector
->doublescan_allowed
)
128 mode_flags
|= DRM_MODE_FLAG_DBLSCAN
;
129 drm_mode_validate_flag(connector
, mode_flags
);
131 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
) {
132 if (mode
->status
== MODE_OK
)
133 mode
->status
= connector_funcs
->mode_valid(connector
,
138 drm_mode_prune_invalid(dev
, &connector
->modes
, true);
140 if (list_empty(&connector
->modes
))
143 drm_mode_sort(&connector
->modes
);
145 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] probed modes :\n", connector
->base
.id
,
146 drm_get_connector_name(connector
));
147 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
) {
148 mode
->vrefresh
= drm_mode_vrefresh(mode
);
150 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
151 drm_mode_debug_printmodeline(mode
);
156 EXPORT_SYMBOL(drm_helper_probe_single_connector_modes
);
159 * drm_helper_encoder_in_use - check if a given encoder is in use
160 * @encoder: encoder to check
163 * Caller must hold mode config lock.
165 * Walk @encoders's DRM device's mode_config and see if it's in use.
168 * True if @encoder is part of the mode_config, false otherwise.
170 bool drm_helper_encoder_in_use(struct drm_encoder
*encoder
)
172 struct drm_connector
*connector
;
173 struct drm_device
*dev
= encoder
->dev
;
174 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
175 if (connector
->encoder
== encoder
)
179 EXPORT_SYMBOL(drm_helper_encoder_in_use
);
182 * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config
183 * @crtc: CRTC to check
186 * Caller must hold mode config lock.
188 * Walk @crtc's DRM device's mode_config and see if it's in use.
191 * True if @crtc is part of the mode_config, false otherwise.
193 bool drm_helper_crtc_in_use(struct drm_crtc
*crtc
)
195 struct drm_encoder
*encoder
;
196 struct drm_device
*dev
= crtc
->dev
;
197 /* FIXME: Locking around list access? */
198 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
199 if (encoder
->crtc
== crtc
&& drm_helper_encoder_in_use(encoder
))
203 EXPORT_SYMBOL(drm_helper_crtc_in_use
);
206 drm_encoder_disable(struct drm_encoder
*encoder
)
208 struct drm_encoder_helper_funcs
*encoder_funcs
= encoder
->helper_private
;
210 if (encoder_funcs
->disable
)
211 (*encoder_funcs
->disable
)(encoder
);
213 (*encoder_funcs
->dpms
)(encoder
, DRM_MODE_DPMS_OFF
);
217 * drm_helper_disable_unused_functions - disable unused objects
221 * Caller must hold mode config lock.
223 * If an connector or CRTC isn't part of @dev's mode_config, it can be disabled
224 * by calling its dpms function, which should power it off.
226 void drm_helper_disable_unused_functions(struct drm_device
*dev
)
228 struct drm_encoder
*encoder
;
229 struct drm_connector
*connector
;
230 struct drm_crtc
*crtc
;
232 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
233 if (!connector
->encoder
)
235 if (connector
->status
== connector_status_disconnected
)
236 connector
->encoder
= NULL
;
239 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
240 if (!drm_helper_encoder_in_use(encoder
)) {
241 drm_encoder_disable(encoder
);
242 /* disconnector encoder from any connector */
243 encoder
->crtc
= NULL
;
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 if (crtc_funcs
->disable
)
252 (*crtc_funcs
->disable
)(crtc
);
254 (*crtc_funcs
->dpms
)(crtc
, DRM_MODE_DPMS_OFF
);
259 EXPORT_SYMBOL(drm_helper_disable_unused_functions
);
262 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
263 * @encoder: encoder to test
264 * @crtc: crtc to test
266 * Return false if @encoder can't be driven by @crtc, true otherwise.
268 static bool drm_encoder_crtc_ok(struct drm_encoder
*encoder
,
269 struct drm_crtc
*crtc
)
271 struct drm_device
*dev
;
272 struct drm_crtc
*tmp
;
275 WARN(!crtc
, "checking null crtc?");
279 list_for_each_entry(tmp
, &dev
->mode_config
.crtc_list
, head
) {
285 if (encoder
->possible_crtcs
& crtc_mask
)
291 * Check the CRTC we're going to map each output to vs. its current
292 * CRTC. If they don't match, we have to disable the output and the CRTC
293 * since the driver will have to re-route things.
296 drm_crtc_prepare_encoders(struct drm_device
*dev
)
298 struct drm_encoder_helper_funcs
*encoder_funcs
;
299 struct drm_encoder
*encoder
;
301 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
302 encoder_funcs
= encoder
->helper_private
;
303 /* Disable unused encoders */
304 if (encoder
->crtc
== NULL
)
305 drm_encoder_disable(encoder
);
306 /* Disable encoders whose CRTC is about to change */
307 if (encoder_funcs
->get_crtc
&&
308 encoder
->crtc
!= (*encoder_funcs
->get_crtc
)(encoder
))
309 drm_encoder_disable(encoder
);
314 * drm_crtc_set_mode - set a mode
315 * @crtc: CRTC to program
321 * Caller must hold mode config lock.
323 * Try to set @mode on @crtc. Give @crtc and its associated connectors a chance
324 * to fixup or reject the mode prior to trying to set it.
327 * True if the mode was set successfully, or false otherwise.
329 bool drm_crtc_helper_set_mode(struct drm_crtc
*crtc
,
330 struct drm_display_mode
*mode
,
332 struct drm_framebuffer
*old_fb
)
334 struct drm_device
*dev
= crtc
->dev
;
335 struct drm_display_mode
*adjusted_mode
, saved_mode
;
336 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
337 struct drm_encoder_helper_funcs
*encoder_funcs
;
338 int saved_x
, saved_y
;
339 struct drm_encoder
*encoder
;
342 adjusted_mode
= drm_mode_duplicate(dev
, mode
);
344 crtc
->enabled
= drm_helper_crtc_in_use(crtc
);
349 saved_mode
= crtc
->mode
;
353 /* Update crtc values up front so the driver can rely on them for mode
360 /* Pass our mode to the connectors and the CRTC to give them a chance to
361 * adjust it according to limitations or connector properties, and also
362 * a chance to reject the mode entirely.
364 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
366 if (encoder
->crtc
!= crtc
)
368 encoder_funcs
= encoder
->helper_private
;
369 if (!(ret
= encoder_funcs
->mode_fixup(encoder
, mode
,
375 if (!(ret
= crtc_funcs
->mode_fixup(crtc
, mode
, adjusted_mode
))) {
378 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
380 /* Prepare the encoders and CRTCs before setting the mode. */
381 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
383 if (encoder
->crtc
!= crtc
)
385 encoder_funcs
= encoder
->helper_private
;
386 /* Disable the encoders as the first thing we do. */
387 encoder_funcs
->prepare(encoder
);
390 drm_crtc_prepare_encoders(dev
);
392 crtc_funcs
->prepare(crtc
);
394 /* Set up the DPLL and any encoders state that needs to adjust or depend
397 ret
= !crtc_funcs
->mode_set(crtc
, mode
, adjusted_mode
, x
, y
, old_fb
);
401 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
403 if (encoder
->crtc
!= crtc
)
406 DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
407 encoder
->base
.id
, drm_get_encoder_name(encoder
),
408 mode
->base
.id
, mode
->name
);
409 encoder_funcs
= encoder
->helper_private
;
410 encoder_funcs
->mode_set(encoder
, mode
, adjusted_mode
);
413 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
414 crtc_funcs
->commit(crtc
);
416 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
418 if (encoder
->crtc
!= crtc
)
421 encoder_funcs
= encoder
->helper_private
;
422 encoder_funcs
->commit(encoder
);
426 /* XXX free adjustedmode */
427 drm_mode_destroy(dev
, adjusted_mode
);
428 /* FIXME: add subpixel order */
431 crtc
->mode
= saved_mode
;
438 EXPORT_SYMBOL(drm_crtc_helper_set_mode
);
442 * drm_crtc_helper_set_config - set a new config from userspace
443 * @crtc: CRTC to setup
444 * @crtc_info: user provided configuration
445 * @new_mode: new mode to set
446 * @connector_set: set of connectors for the new config
447 * @fb: new framebuffer
450 * Caller must hold mode config lock.
452 * Setup a new configuration, provided by the user in @crtc_info, and enable
458 int drm_crtc_helper_set_config(struct drm_mode_set
*set
)
460 struct drm_device
*dev
;
461 struct drm_crtc
*save_crtcs
, *new_crtc
, *crtc
;
462 struct drm_encoder
*save_encoders
, *new_encoder
, *encoder
;
463 struct drm_framebuffer
*old_fb
= NULL
;
464 bool mode_changed
= false; /* if true do a full mode set */
465 bool fb_changed
= false; /* if true and !mode_changed just do a flip */
466 struct drm_connector
*save_connectors
, *connector
;
467 int count
= 0, ro
, fail
= 0;
468 struct drm_crtc_helper_funcs
*crtc_funcs
;
479 if (!set
->crtc
->helper_private
)
482 crtc_funcs
= set
->crtc
->helper_private
;
485 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
486 set
->crtc
->base
.id
, set
->fb
->base
.id
,
487 (int)set
->num_connectors
, set
->x
, set
->y
);
489 DRM_DEBUG_KMS("[CRTC:%d] [NOFB] #connectors=%d (x y) (%i %i)\n",
490 set
->crtc
->base
.id
, (int)set
->num_connectors
,
494 dev
= set
->crtc
->dev
;
496 /* Allocate space for the backup of all (non-pointer) crtc, encoder and
498 save_crtcs
= kzalloc(dev
->mode_config
.num_crtc
*
499 sizeof(struct drm_crtc
), GFP_KERNEL
);
503 save_encoders
= kzalloc(dev
->mode_config
.num_encoder
*
504 sizeof(struct drm_encoder
), GFP_KERNEL
);
505 if (!save_encoders
) {
510 save_connectors
= kzalloc(dev
->mode_config
.num_connector
*
511 sizeof(struct drm_connector
), GFP_KERNEL
);
512 if (!save_connectors
) {
514 kfree(save_encoders
);
518 /* Copy data. Note that driver private data is not affected.
519 * Should anything bad happen only the expected state is
520 * restored, not the drivers personal bookkeeping.
523 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
524 save_crtcs
[count
++] = *crtc
;
528 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
529 save_encoders
[count
++] = *encoder
;
533 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
534 save_connectors
[count
++] = *connector
;
537 /* We should be able to check here if the fb has the same properties
538 * and then just flip_or_move it */
539 if (set
->crtc
->fb
!= set
->fb
) {
540 /* If we have no fb then treat it as a full mode set */
541 if (set
->crtc
->fb
== NULL
) {
542 DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
544 } else if (set
->fb
== NULL
) {
550 if (set
->x
!= set
->crtc
->x
|| set
->y
!= set
->crtc
->y
)
553 if (set
->mode
&& !drm_mode_equal(set
->mode
, &set
->crtc
->mode
)) {
554 DRM_DEBUG_KMS("modes are different, full mode set\n");
555 drm_mode_debug_printmodeline(&set
->crtc
->mode
);
556 drm_mode_debug_printmodeline(set
->mode
);
560 /* a) traverse passed in connector list and get encoders for them */
562 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
563 struct drm_connector_helper_funcs
*connector_funcs
=
564 connector
->helper_private
;
565 new_encoder
= connector
->encoder
;
566 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
567 if (set
->connectors
[ro
] == connector
) {
568 new_encoder
= connector_funcs
->best_encoder(connector
);
569 /* if we can't get an encoder for a connector
570 we are setting now - then fail */
571 if (new_encoder
== NULL
)
572 /* don't break so fail path works correct */
578 if (new_encoder
!= connector
->encoder
) {
579 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
581 /* If the encoder is reused for another connector, then
582 * the appropriate crtc will be set later.
584 if (connector
->encoder
)
585 connector
->encoder
->crtc
= NULL
;
586 connector
->encoder
= new_encoder
;
596 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
597 if (!connector
->encoder
)
600 if (connector
->encoder
->crtc
== set
->crtc
)
603 new_crtc
= connector
->encoder
->crtc
;
605 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
606 if (set
->connectors
[ro
] == connector
)
607 new_crtc
= set
->crtc
;
610 /* Make sure the new CRTC will work with the encoder */
612 !drm_encoder_crtc_ok(connector
->encoder
, new_crtc
)) {
616 if (new_crtc
!= connector
->encoder
->crtc
) {
617 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
619 connector
->encoder
->crtc
= new_crtc
;
622 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
623 connector
->base
.id
, drm_get_connector_name(connector
),
626 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
627 connector
->base
.id
, drm_get_connector_name(connector
));
631 /* mode_set_base is not a required function */
632 if (fb_changed
&& !crtc_funcs
->mode_set_base
)
636 old_fb
= set
->crtc
->fb
;
637 set
->crtc
->fb
= set
->fb
;
638 set
->crtc
->enabled
= (set
->mode
!= NULL
);
639 if (set
->mode
!= NULL
) {
640 DRM_DEBUG_KMS("attempting to set mode from"
642 drm_mode_debug_printmodeline(set
->mode
);
643 if (!drm_crtc_helper_set_mode(set
->crtc
, set
->mode
,
646 DRM_ERROR("failed to set mode on [CRTC:%d]\n",
652 drm_helper_disable_unused_functions(dev
);
653 } else if (fb_changed
) {
654 set
->crtc
->x
= set
->x
;
655 set
->crtc
->y
= set
->y
;
657 old_fb
= set
->crtc
->fb
;
658 if (set
->crtc
->fb
!= set
->fb
)
659 set
->crtc
->fb
= set
->fb
;
660 ret
= crtc_funcs
->mode_set_base(set
->crtc
,
661 set
->x
, set
->y
, old_fb
);
666 kfree(save_connectors
);
667 kfree(save_encoders
);
672 /* Restore all previous data. */
674 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
675 *crtc
= save_crtcs
[count
++];
679 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
680 *encoder
= save_encoders
[count
++];
684 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
685 *connector
= save_connectors
[count
++];
688 kfree(save_connectors
);
689 kfree(save_encoders
);
693 EXPORT_SYMBOL(drm_crtc_helper_set_config
);
695 static int drm_helper_choose_encoder_dpms(struct drm_encoder
*encoder
)
697 int dpms
= DRM_MODE_DPMS_OFF
;
698 struct drm_connector
*connector
;
699 struct drm_device
*dev
= encoder
->dev
;
701 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
702 if (connector
->encoder
== encoder
)
703 if (connector
->dpms
< dpms
)
704 dpms
= connector
->dpms
;
708 static int drm_helper_choose_crtc_dpms(struct drm_crtc
*crtc
)
710 int dpms
= DRM_MODE_DPMS_OFF
;
711 struct drm_connector
*connector
;
712 struct drm_device
*dev
= crtc
->dev
;
714 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
715 if (connector
->encoder
&& connector
->encoder
->crtc
== crtc
)
716 if (connector
->dpms
< dpms
)
717 dpms
= connector
->dpms
;
722 * drm_helper_connector_dpms
723 * @connector affected connector
726 * Calls the low-level connector DPMS function, then
727 * calls appropriate encoder and crtc DPMS functions as well
729 void drm_helper_connector_dpms(struct drm_connector
*connector
, int mode
)
731 struct drm_encoder
*encoder
= connector
->encoder
;
732 struct drm_crtc
*crtc
= encoder
? encoder
->crtc
: NULL
;
735 if (mode
== connector
->dpms
)
738 old_dpms
= connector
->dpms
;
739 connector
->dpms
= mode
;
741 /* from off to on, do crtc then encoder */
742 if (mode
< old_dpms
) {
744 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
745 if (crtc_funcs
->dpms
)
746 (*crtc_funcs
->dpms
) (crtc
,
747 drm_helper_choose_crtc_dpms(crtc
));
750 struct drm_encoder_helper_funcs
*encoder_funcs
= encoder
->helper_private
;
751 if (encoder_funcs
->dpms
)
752 (*encoder_funcs
->dpms
) (encoder
,
753 drm_helper_choose_encoder_dpms(encoder
));
757 /* from on to off, do encoder then crtc */
758 if (mode
> old_dpms
) {
760 struct drm_encoder_helper_funcs
*encoder_funcs
= encoder
->helper_private
;
761 if (encoder_funcs
->dpms
)
762 (*encoder_funcs
->dpms
) (encoder
,
763 drm_helper_choose_encoder_dpms(encoder
));
766 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
767 if (crtc_funcs
->dpms
)
768 (*crtc_funcs
->dpms
) (crtc
,
769 drm_helper_choose_crtc_dpms(crtc
));
775 EXPORT_SYMBOL(drm_helper_connector_dpms
);
777 int drm_helper_mode_fill_fb_struct(struct drm_framebuffer
*fb
,
778 struct drm_mode_fb_cmd
*mode_cmd
)
780 fb
->width
= mode_cmd
->width
;
781 fb
->height
= mode_cmd
->height
;
782 fb
->pitch
= mode_cmd
->pitch
;
783 fb
->bits_per_pixel
= mode_cmd
->bpp
;
784 fb
->depth
= mode_cmd
->depth
;
788 EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct
);
790 int drm_helper_resume_force_mode(struct drm_device
*dev
)
792 struct drm_crtc
*crtc
;
793 struct drm_encoder
*encoder
;
794 struct drm_encoder_helper_funcs
*encoder_funcs
;
795 struct drm_crtc_helper_funcs
*crtc_funcs
;
798 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
803 ret
= drm_crtc_helper_set_mode(crtc
, &crtc
->mode
,
804 crtc
->x
, crtc
->y
, crtc
->fb
);
807 DRM_ERROR("failed to set mode on crtc %p\n", crtc
);
809 /* Turn off outputs that were already powered off */
810 if (drm_helper_choose_crtc_dpms(crtc
)) {
811 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
813 if(encoder
->crtc
!= crtc
)
816 encoder_funcs
= encoder
->helper_private
;
817 if (encoder_funcs
->dpms
)
818 (*encoder_funcs
->dpms
) (encoder
,
819 drm_helper_choose_encoder_dpms(encoder
));
822 crtc_funcs
= crtc
->helper_private
;
823 if (crtc_funcs
->dpms
)
824 (*crtc_funcs
->dpms
) (crtc
,
825 drm_helper_choose_crtc_dpms(crtc
));
828 /* disable the unused connectors while restoring the modesetting */
829 drm_helper_disable_unused_functions(dev
);
832 EXPORT_SYMBOL(drm_helper_resume_force_mode
);
834 #define DRM_OUTPUT_POLL_PERIOD (10*HZ)
835 static void output_poll_execute(struct work_struct
*work
)
837 struct delayed_work
*delayed_work
= to_delayed_work(work
);
838 struct drm_device
*dev
= container_of(delayed_work
, struct drm_device
, mode_config
.output_poll_work
);
839 struct drm_connector
*connector
;
840 enum drm_connector_status old_status
, status
;
841 bool repoll
= false, changed
= false;
843 mutex_lock(&dev
->mode_config
.mutex
);
844 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
846 /* if this is HPD or polled don't check it -
847 TV out for instance */
848 if (!connector
->polled
)
851 else if (connector
->polled
& (DRM_CONNECTOR_POLL_CONNECT
| DRM_CONNECTOR_POLL_DISCONNECT
))
854 old_status
= connector
->status
;
855 /* if we are connected and don't want to poll for disconnect
857 if (old_status
== connector_status_connected
&&
858 !(connector
->polled
& DRM_CONNECTOR_POLL_DISCONNECT
) &&
859 !(connector
->polled
& DRM_CONNECTOR_POLL_HPD
))
862 status
= connector
->funcs
->detect(connector
);
863 if (old_status
!= status
)
867 mutex_unlock(&dev
->mode_config
.mutex
);
870 /* send a uevent + call fbdev */
871 drm_sysfs_hotplug_event(dev
);
872 if (dev
->mode_config
.funcs
->output_poll_changed
)
873 dev
->mode_config
.funcs
->output_poll_changed(dev
);
877 queue_delayed_work(system_nrt_wq
, delayed_work
, DRM_OUTPUT_POLL_PERIOD
);
880 void drm_kms_helper_poll_disable(struct drm_device
*dev
)
882 if (!dev
->mode_config
.poll_enabled
)
884 cancel_delayed_work_sync(&dev
->mode_config
.output_poll_work
);
886 EXPORT_SYMBOL(drm_kms_helper_poll_disable
);
888 void drm_kms_helper_poll_enable(struct drm_device
*dev
)
891 struct drm_connector
*connector
;
893 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
894 if (connector
->polled
)
899 queue_delayed_work(system_nrt_wq
, &dev
->mode_config
.output_poll_work
, DRM_OUTPUT_POLL_PERIOD
);
901 EXPORT_SYMBOL(drm_kms_helper_poll_enable
);
903 void drm_kms_helper_poll_init(struct drm_device
*dev
)
905 INIT_DELAYED_WORK(&dev
->mode_config
.output_poll_work
, output_poll_execute
);
906 dev
->mode_config
.poll_enabled
= true;
908 drm_kms_helper_poll_enable(dev
);
910 EXPORT_SYMBOL(drm_kms_helper_poll_init
);
912 void drm_kms_helper_poll_fini(struct drm_device
*dev
)
914 drm_kms_helper_poll_disable(dev
);
916 EXPORT_SYMBOL(drm_kms_helper_poll_fini
);
918 void drm_helper_hpd_irq_event(struct drm_device
*dev
)
920 if (!dev
->mode_config
.poll_enabled
)
922 /* kill timer and schedule immediate execution, this doesn't block */
923 cancel_delayed_work(&dev
->mode_config
.output_poll_work
);
924 queue_delayed_work(system_nrt_wq
, &dev
->mode_config
.output_poll_work
, 0);
926 EXPORT_SYMBOL(drm_helper_hpd_irq_event
);