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>
32 #include <linux/export.h>
33 #include <linux/moduleparam.h>
37 #include "drm_fourcc.h"
38 #include "drm_crtc_helper.h"
39 #include "drm_fb_helper.h"
41 static bool drm_kms_helper_poll = true;
42 module_param_named(poll, drm_kms_helper_poll, bool, 0600);
44 static void drm_mode_validate_flag(struct drm_connector *connector,
47 struct drm_display_mode *mode, *t;
49 if (flags == (DRM_MODE_FLAG_DBLSCAN | DRM_MODE_FLAG_INTERLACE))
52 list_for_each_entry_safe(mode, t, &connector->modes, head) {
53 if ((mode->flags & DRM_MODE_FLAG_INTERLACE) &&
54 !(flags & DRM_MODE_FLAG_INTERLACE))
55 mode->status = MODE_NO_INTERLACE;
56 if ((mode->flags & DRM_MODE_FLAG_DBLSCAN) &&
57 !(flags & DRM_MODE_FLAG_DBLSCAN))
58 mode->status = MODE_NO_DBLESCAN;
65 * drm_helper_probe_single_connector_modes - get complete set of display modes
67 * @maxX: max width for modes
68 * @maxY: max height for modes
71 * Caller must hold mode config lock.
73 * Based on @dev's mode_config layout, scan all the connectors and try to detect
74 * modes on them. Modes will first be added to the connector's probed_modes
75 * list, then culled (based on validity and the @maxX, @maxY parameters) and
76 * put into the normal modes list.
78 * Intended to be used either at bootup time or when major configuration
79 * changes have occurred.
81 * FIXME: take into account monitor limits
84 * Number of modes found on @connector.
86 int drm_helper_probe_single_connector_modes(struct drm_connector *connector,
87 uint32_t maxX, uint32_t maxY)
89 struct drm_device *dev = connector->dev;
90 struct drm_display_mode *mode, *t;
91 struct drm_connector_helper_funcs *connector_funcs =
92 connector->helper_private;
96 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
97 drm_get_connector_name(connector));
98 /* set all modes to the unverified state */
99 list_for_each_entry_safe(mode, t, &connector->modes, head)
100 mode->status = MODE_UNVERIFIED;
102 if (connector->force) {
103 if (connector->force == DRM_FORCE_ON)
104 connector->status = connector_status_connected;
106 connector->status = connector_status_disconnected;
107 if (connector->funcs->force)
108 connector->funcs->force(connector);
110 connector->status = connector->funcs->detect(connector, true);
111 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);
225 * drm_helper_disable_unused_functions - disable unused objects
229 * Caller must hold mode config lock.
231 * If an connector or CRTC isn't part of @dev's mode_config, it can be disabled
232 * by calling its dpms function, which should power it off.
234 void drm_helper_disable_unused_functions(struct drm_device *dev)
236 struct drm_encoder *encoder;
237 struct drm_connector *connector;
238 struct drm_crtc *crtc;
240 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
241 if (!connector->encoder)
243 if (connector->status == connector_status_disconnected)
244 connector->encoder = NULL;
247 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
248 if (!drm_helper_encoder_in_use(encoder)) {
249 drm_encoder_disable(encoder);
250 /* disconnector encoder from any connector */
251 encoder->crtc = NULL;
255 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
256 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
257 crtc->enabled = drm_helper_crtc_in_use(crtc);
258 if (!crtc->enabled) {
259 if (crtc_funcs->disable)
260 (*crtc_funcs->disable)(crtc);
262 (*crtc_funcs->dpms)(crtc, DRM_MODE_DPMS_OFF);
267 EXPORT_SYMBOL(drm_helper_disable_unused_functions);
270 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
271 * @encoder: encoder to test
272 * @crtc: crtc to test
274 * Return false if @encoder can't be driven by @crtc, true otherwise.
276 static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
277 struct drm_crtc *crtc)
279 struct drm_device *dev;
280 struct drm_crtc *tmp;
283 WARN(!crtc, "checking null crtc?\n");
287 list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) {
293 if (encoder->possible_crtcs & crtc_mask)
299 * Check the CRTC we're going to map each output to vs. its current
300 * CRTC. If they don't match, we have to disable the output and the CRTC
301 * since the driver will have to re-route things.
304 drm_crtc_prepare_encoders(struct drm_device *dev)
306 struct drm_encoder_helper_funcs *encoder_funcs;
307 struct drm_encoder *encoder;
309 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
310 encoder_funcs = encoder->helper_private;
311 /* Disable unused encoders */
312 if (encoder->crtc == NULL)
313 drm_encoder_disable(encoder);
314 /* Disable encoders whose CRTC is about to change */
315 if (encoder_funcs->get_crtc &&
316 encoder->crtc != (*encoder_funcs->get_crtc)(encoder))
317 drm_encoder_disable(encoder);
322 * drm_crtc_set_mode - set a mode
323 * @crtc: CRTC to program
329 * Caller must hold mode config lock.
331 * Try to set @mode on @crtc. Give @crtc and its associated connectors a chance
332 * to fixup or reject the mode prior to trying to set it.
335 * True if the mode was set successfully, or false otherwise.
337 bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
338 struct drm_display_mode *mode,
340 struct drm_framebuffer *old_fb)
342 struct drm_device *dev = crtc->dev;
343 struct drm_display_mode *adjusted_mode, saved_mode, saved_hwmode;
344 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
345 struct drm_encoder_helper_funcs *encoder_funcs;
346 int saved_x, saved_y;
347 struct drm_encoder *encoder;
350 crtc->enabled = drm_helper_crtc_in_use(crtc);
354 adjusted_mode = drm_mode_duplicate(dev, mode);
356 saved_hwmode = crtc->hwmode;
357 saved_mode = crtc->mode;
361 /* Update crtc values up front so the driver can rely on them for mode
368 /* Pass our mode to the connectors and the CRTC to give them a chance to
369 * adjust it according to limitations or connector properties, and also
370 * a chance to reject the mode entirely.
372 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
374 if (encoder->crtc != crtc)
376 encoder_funcs = encoder->helper_private;
377 if (!(ret = encoder_funcs->mode_fixup(encoder, mode,
379 DRM_DEBUG_KMS("Encoder fixup failed\n");
384 if (!(ret = crtc_funcs->mode_fixup(crtc, mode, adjusted_mode))) {
385 DRM_DEBUG_KMS("CRTC fixup failed\n");
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 /* Calculate and store various constants which
440 * are later needed by vblank and swap-completion
441 * timestamping. They are derived from true hwmode.
443 drm_calc_timestamping_constants(crtc);
445 /* FIXME: add subpixel order */
447 drm_mode_destroy(dev, adjusted_mode);
449 crtc->hwmode = saved_hwmode;
450 crtc->mode = saved_mode;
457 EXPORT_SYMBOL(drm_crtc_helper_set_mode);
461 * drm_crtc_helper_set_config - set a new config from userspace
462 * @crtc: CRTC to setup
463 * @crtc_info: user provided configuration
464 * @new_mode: new mode to set
465 * @connector_set: set of connectors for the new config
466 * @fb: new framebuffer
469 * Caller must hold mode config lock.
471 * Setup a new configuration, provided by the user in @crtc_info, and enable
477 int drm_crtc_helper_set_config(struct drm_mode_set *set)
479 struct drm_device *dev;
480 struct drm_crtc *save_crtcs, *new_crtc, *crtc;
481 struct drm_encoder *save_encoders, *new_encoder, *encoder;
482 struct drm_framebuffer *old_fb = NULL;
483 bool mode_changed = false; /* if true do a full mode set */
484 bool fb_changed = false; /* if true and !mode_changed just do a flip */
485 struct drm_connector *save_connectors, *connector;
486 int count = 0, ro, fail = 0;
487 struct drm_crtc_helper_funcs *crtc_funcs;
499 if (!set->crtc->helper_private)
502 crtc_funcs = set->crtc->helper_private;
508 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
509 set->crtc->base.id, set->fb->base.id,
510 (int)set->num_connectors, set->x, set->y);
512 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
514 set->num_connectors = 0;
517 dev = set->crtc->dev;
519 /* Allocate space for the backup of all (non-pointer) crtc, encoder and
521 save_crtcs = kzalloc(dev->mode_config.num_crtc *
522 sizeof(struct drm_crtc), GFP_KERNEL);
526 save_encoders = kzalloc(dev->mode_config.num_encoder *
527 sizeof(struct drm_encoder), GFP_KERNEL);
528 if (!save_encoders) {
533 save_connectors = kzalloc(dev->mode_config.num_connector *
534 sizeof(struct drm_connector), GFP_KERNEL);
535 if (!save_connectors) {
537 kfree(save_encoders);
541 /* Copy data. Note that driver private data is not affected.
542 * Should anything bad happen only the expected state is
543 * restored, not the drivers personal bookkeeping.
546 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
547 save_crtcs[count++] = *crtc;
551 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
552 save_encoders[count++] = *encoder;
556 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
557 save_connectors[count++] = *connector;
560 /* We should be able to check here if the fb has the same properties
561 * and then just flip_or_move it */
562 if (set->crtc->fb != set->fb) {
563 /* If we have no fb then treat it as a full mode set */
564 if (set->crtc->fb == NULL) {
565 DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
567 } else if (set->fb == NULL) {
569 } else if (set->fb->depth != set->crtc->fb->depth) {
571 } else if (set->fb->bits_per_pixel !=
572 set->crtc->fb->bits_per_pixel) {
578 if (set->x != set->crtc->x || set->y != set->crtc->y)
581 if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
582 DRM_DEBUG_KMS("modes are different, full mode set\n");
583 drm_mode_debug_printmodeline(&set->crtc->mode);
584 drm_mode_debug_printmodeline(set->mode);
588 /* a) traverse passed in connector list and get encoders for them */
590 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
591 struct drm_connector_helper_funcs *connector_funcs =
592 connector->helper_private;
593 new_encoder = connector->encoder;
594 for (ro = 0; ro < set->num_connectors; ro++) {
595 if (set->connectors[ro] == connector) {
596 new_encoder = connector_funcs->best_encoder(connector);
597 /* if we can't get an encoder for a connector
598 we are setting now - then fail */
599 if (new_encoder == NULL)
600 /* don't break so fail path works correct */
606 if (new_encoder != connector->encoder) {
607 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
609 /* If the encoder is reused for another connector, then
610 * the appropriate crtc will be set later.
612 if (connector->encoder)
613 connector->encoder->crtc = NULL;
614 connector->encoder = new_encoder;
624 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
625 if (!connector->encoder)
628 if (connector->encoder->crtc == set->crtc)
631 new_crtc = connector->encoder->crtc;
633 for (ro = 0; ro < set->num_connectors; ro++) {
634 if (set->connectors[ro] == connector)
635 new_crtc = set->crtc;
638 /* Make sure the new CRTC will work with the encoder */
640 !drm_encoder_crtc_ok(connector->encoder, new_crtc)) {
644 if (new_crtc != connector->encoder->crtc) {
645 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
647 connector->encoder->crtc = new_crtc;
650 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
651 connector->base.id, drm_get_connector_name(connector),
654 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
655 connector->base.id, drm_get_connector_name(connector));
659 /* mode_set_base is not a required function */
660 if (fb_changed && !crtc_funcs->mode_set_base)
664 set->crtc->enabled = drm_helper_crtc_in_use(set->crtc);
665 if (set->crtc->enabled) {
666 DRM_DEBUG_KMS("attempting to set mode from"
668 drm_mode_debug_printmodeline(set->mode);
669 old_fb = set->crtc->fb;
670 set->crtc->fb = set->fb;
671 if (!drm_crtc_helper_set_mode(set->crtc, set->mode,
674 DRM_ERROR("failed to set mode on [CRTC:%d]\n",
676 set->crtc->fb = old_fb;
680 DRM_DEBUG_KMS("Setting connector DPMS state to on\n");
681 for (i = 0; i < set->num_connectors; i++) {
682 DRM_DEBUG_KMS("\t[CONNECTOR:%d:%s] set DPMS on\n", set->connectors[i]->base.id,
683 drm_get_connector_name(set->connectors[i]));
684 set->connectors[i]->dpms = DRM_MODE_DPMS_ON;
687 drm_helper_disable_unused_functions(dev);
688 } else if (fb_changed) {
689 set->crtc->x = set->x;
690 set->crtc->y = set->y;
692 old_fb = set->crtc->fb;
693 if (set->crtc->fb != set->fb)
694 set->crtc->fb = set->fb;
695 ret = crtc_funcs->mode_set_base(set->crtc,
696 set->x, set->y, old_fb);
698 set->crtc->fb = old_fb;
703 kfree(save_connectors);
704 kfree(save_encoders);
709 /* Restore all previous data. */
711 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
712 *crtc = save_crtcs[count++];
716 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
717 *encoder = save_encoders[count++];
721 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
722 *connector = save_connectors[count++];
725 kfree(save_connectors);
726 kfree(save_encoders);
730 EXPORT_SYMBOL(drm_crtc_helper_set_config);
732 static int drm_helper_choose_encoder_dpms(struct drm_encoder *encoder)
734 int dpms = DRM_MODE_DPMS_OFF;
735 struct drm_connector *connector;
736 struct drm_device *dev = encoder->dev;
738 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
739 if (connector->encoder == encoder)
740 if (connector->dpms < dpms)
741 dpms = connector->dpms;
745 static int drm_helper_choose_crtc_dpms(struct drm_crtc *crtc)
747 int dpms = DRM_MODE_DPMS_OFF;
748 struct drm_connector *connector;
749 struct drm_device *dev = crtc->dev;
751 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
752 if (connector->encoder && connector->encoder->crtc == crtc)
753 if (connector->dpms < dpms)
754 dpms = connector->dpms;
759 * drm_helper_connector_dpms
760 * @connector affected connector
763 * Calls the low-level connector DPMS function, then
764 * calls appropriate encoder and crtc DPMS functions as well
766 void drm_helper_connector_dpms(struct drm_connector *connector, int mode)
768 struct drm_encoder *encoder = connector->encoder;
769 struct drm_crtc *crtc = encoder ? encoder->crtc : NULL;
772 if (mode == connector->dpms)
775 old_dpms = connector->dpms;
776 connector->dpms = mode;
778 /* from off to on, do crtc then encoder */
779 if (mode < old_dpms) {
781 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
782 if (crtc_funcs->dpms)
783 (*crtc_funcs->dpms) (crtc,
784 drm_helper_choose_crtc_dpms(crtc));
787 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
788 if (encoder_funcs->dpms)
789 (*encoder_funcs->dpms) (encoder,
790 drm_helper_choose_encoder_dpms(encoder));
794 /* from on to off, do encoder then crtc */
795 if (mode > old_dpms) {
797 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
798 if (encoder_funcs->dpms)
799 (*encoder_funcs->dpms) (encoder,
800 drm_helper_choose_encoder_dpms(encoder));
803 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
804 if (crtc_funcs->dpms)
805 (*crtc_funcs->dpms) (crtc,
806 drm_helper_choose_crtc_dpms(crtc));
812 EXPORT_SYMBOL(drm_helper_connector_dpms);
814 int drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
815 struct drm_mode_fb_cmd2 *mode_cmd)
817 fb->width = mode_cmd->width;
818 fb->height = mode_cmd->height;
819 fb->pitch = mode_cmd->pitches[0];
820 drm_fb_get_bpp_depth(mode_cmd->pixel_format, &fb->depth,
821 &fb->bits_per_pixel);
822 fb->pixel_format = mode_cmd->pixel_format;
826 EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct);
828 int drm_helper_resume_force_mode(struct drm_device *dev)
830 struct drm_crtc *crtc;
831 struct drm_encoder *encoder;
832 struct drm_encoder_helper_funcs *encoder_funcs;
833 struct drm_crtc_helper_funcs *crtc_funcs;
836 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
841 ret = drm_crtc_helper_set_mode(crtc, &crtc->mode,
842 crtc->x, crtc->y, crtc->fb);
845 DRM_ERROR("failed to set mode on crtc %p\n", crtc);
847 /* Turn off outputs that were already powered off */
848 if (drm_helper_choose_crtc_dpms(crtc)) {
849 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
851 if(encoder->crtc != crtc)
854 encoder_funcs = encoder->helper_private;
855 if (encoder_funcs->dpms)
856 (*encoder_funcs->dpms) (encoder,
857 drm_helper_choose_encoder_dpms(encoder));
860 crtc_funcs = crtc->helper_private;
861 if (crtc_funcs->dpms)
862 (*crtc_funcs->dpms) (crtc,
863 drm_helper_choose_crtc_dpms(crtc));
866 /* disable the unused connectors while restoring the modesetting */
867 drm_helper_disable_unused_functions(dev);
870 EXPORT_SYMBOL(drm_helper_resume_force_mode);
872 #define DRM_OUTPUT_POLL_PERIOD (10*HZ)
873 static void output_poll_execute(struct work_struct *work)
875 struct delayed_work *delayed_work = to_delayed_work(work);
876 struct drm_device *dev = container_of(delayed_work, struct drm_device, mode_config.output_poll_work);
877 struct drm_connector *connector;
878 enum drm_connector_status old_status;
879 bool repoll = false, changed = false;
881 if (!drm_kms_helper_poll)
884 mutex_lock(&dev->mode_config.mutex);
885 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
887 /* if this is HPD or polled don't check it -
888 TV out for instance */
889 if (!connector->polled)
892 else if (connector->polled & (DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT))
895 old_status = connector->status;
896 /* if we are connected and don't want to poll for disconnect
898 if (old_status == connector_status_connected &&
899 !(connector->polled & DRM_CONNECTOR_POLL_DISCONNECT) &&
900 !(connector->polled & DRM_CONNECTOR_POLL_HPD))
903 connector->status = connector->funcs->detect(connector, false);
904 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %d to %d\n",
906 drm_get_connector_name(connector),
907 old_status, connector->status);
908 if (old_status != connector->status)
912 mutex_unlock(&dev->mode_config.mutex);
915 /* send a uevent + call fbdev */
916 drm_sysfs_hotplug_event(dev);
917 if (dev->mode_config.funcs->output_poll_changed)
918 dev->mode_config.funcs->output_poll_changed(dev);
922 queue_delayed_work(system_nrt_wq, delayed_work, DRM_OUTPUT_POLL_PERIOD);
925 void drm_kms_helper_poll_disable(struct drm_device *dev)
927 if (!dev->mode_config.poll_enabled)
929 cancel_delayed_work_sync(&dev->mode_config.output_poll_work);
931 EXPORT_SYMBOL(drm_kms_helper_poll_disable);
933 void drm_kms_helper_poll_enable(struct drm_device *dev)
936 struct drm_connector *connector;
938 if (!dev->mode_config.poll_enabled || !drm_kms_helper_poll)
941 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
942 if (connector->polled)
947 queue_delayed_work(system_nrt_wq, &dev->mode_config.output_poll_work, DRM_OUTPUT_POLL_PERIOD);
949 EXPORT_SYMBOL(drm_kms_helper_poll_enable);
951 void drm_kms_helper_poll_init(struct drm_device *dev)
953 INIT_DELAYED_WORK(&dev->mode_config.output_poll_work, output_poll_execute);
954 dev->mode_config.poll_enabled = true;
956 drm_kms_helper_poll_enable(dev);
958 EXPORT_SYMBOL(drm_kms_helper_poll_init);
960 void drm_kms_helper_poll_fini(struct drm_device *dev)
962 drm_kms_helper_poll_disable(dev);
964 EXPORT_SYMBOL(drm_kms_helper_poll_fini);
966 void drm_helper_hpd_irq_event(struct drm_device *dev)
968 if (!dev->mode_config.poll_enabled)
971 /* kill timer and schedule immediate execution, this doesn't block */
972 cancel_delayed_work(&dev->mode_config.output_poll_work);
973 if (drm_kms_helper_poll)
974 queue_delayed_work(system_nrt_wq, &dev->mode_config.output_poll_work, 0);
976 EXPORT_SYMBOL(drm_helper_hpd_irq_event);