32 #include <linux/export.h>
42 static bool drm_kms_helper_poll =
true;
97 DRM_DEBUG_KMS(
"[CONNECTOR:%d:%s]\n", connector->
base.id,
103 if (connector->
force) {
108 if (connector->
funcs->force)
109 connector->
funcs->force(connector);
111 connector->
status = connector->
funcs->detect(connector,
true);
116 DRM_DEBUG_KMS(
"[CONNECTOR:%d:%s] disconnected\n",
122 #ifdef CONFIG_DRM_LOAD_EDID_FIRMWARE
126 count = (*connector_funcs->
get_modes)(connector);
143 drm_mode_validate_flag(connector, mode_flags);
154 if (list_empty(&connector->
modes))
159 DRM_DEBUG_KMS(
"[CONNECTOR:%d:%s] probed modes :\n", connector->
base.id,
189 if (connector->
encoder == encoder)
225 (*encoder_funcs->
disable)(encoder);
255 drm_encoder_disable(encoder);
282 static bool drm_encoder_crtc_ok(
struct drm_encoder *encoder,
289 WARN(!crtc,
"checking null crtc?\n");
310 drm_crtc_prepare_encoders(
struct drm_device *dev)
319 drm_encoder_disable(encoder);
323 drm_encoder_disable(encoder);
364 saved_hwmode = crtc->
hwmode;
365 saved_mode = crtc->
mode;
382 if (encoder->
crtc != crtc)
385 if (!(ret = encoder_funcs->
mode_fixup(encoder, mode,
387 DRM_DEBUG_KMS(
"Encoder fixup failed\n");
392 if (!(ret = crtc_funcs->
mode_fixup(crtc, mode, adjusted_mode))) {
393 DRM_DEBUG_KMS(
"CRTC fixup failed\n");
396 DRM_DEBUG_KMS(
"[CRTC:%d]\n", crtc->
base.id);
401 if (encoder->
crtc != crtc)
405 encoder_funcs->
prepare(encoder);
408 drm_crtc_prepare_encoders(dev);
415 ret = !crtc_funcs->
mode_set(crtc, mode, adjusted_mode, x, y, old_fb);
421 if (encoder->
crtc != crtc)
424 DRM_DEBUG_KMS(
"[ENCODER:%d:%s] set [MODE:%d:%s]\n",
428 encoder_funcs->
mode_set(encoder, mode, adjusted_mode);
436 if (encoder->
crtc != crtc)
440 encoder_funcs->
commit(encoder);
445 crtc->
hwmode = *adjusted_mode;
457 crtc->
hwmode = saved_hwmode;
458 crtc->
mode = saved_mode;
469 drm_crtc_helper_disable(
struct drm_crtc *crtc)
477 if (encoder->
crtc != crtc)
481 if (connector->
encoder != encoder)
512 struct drm_crtc *save_crtcs, *new_crtc, *crtc;
513 struct drm_encoder *save_encoders, *new_encoder, *encoder;
515 bool mode_changed =
false;
516 bool fb_changed =
false;
532 if (!
set->crtc->helper_private)
535 crtc_funcs =
set->crtc->helper_private;
541 DRM_DEBUG_KMS(
"[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
542 set->crtc->base.id,
set->fb->base.id,
543 (
int)
set->num_connectors,
set->x,
set->y);
545 DRM_DEBUG_KMS(
"[CRTC:%d] [NOFB]\n",
set->crtc->base.id);
546 return drm_crtc_helper_disable(
set->crtc);
549 dev =
set->crtc->dev;
553 save_crtcs = kzalloc(dev->mode_config.num_crtc *
558 save_encoders = kzalloc(dev->mode_config.num_encoder *
560 if (!save_encoders) {
565 save_connectors = kzalloc(dev->mode_config.num_connector *
567 if (!save_connectors) {
569 kfree(save_encoders);
579 save_crtcs[count++] = *
crtc;
584 save_encoders[count++] = *encoder;
592 save_set.
crtc =
set->crtc;
593 save_set.
mode = &
set->crtc->mode;
594 save_set.
x =
set->crtc->x;
595 save_set.
y =
set->crtc->y;
596 save_set.
fb =
set->crtc->fb;
600 if (
set->crtc->fb !=
set->fb) {
603 DRM_DEBUG_KMS(
"crtc has no fb, full mode set\n");
607 }
else if (
set->fb->depth !=
set->crtc->fb->depth) {
609 }
else if (
set->fb->bits_per_pixel !=
610 set->crtc->fb->bits_per_pixel) {
620 DRM_DEBUG_KMS(
"modes are different, full mode set\n");
631 new_encoder = connector->
encoder;
632 for (
ro = 0;
ro <
set->num_connectors;
ro++) {
633 if (
set->connectors[
ro] == connector) {
637 if (new_encoder ==
NULL)
644 if (new_encoder != connector->
encoder) {
645 DRM_DEBUG_KMS(
"encoder changed, full mode switch\n");
652 connector->
encoder = new_encoder;
669 new_crtc = connector->
encoder->crtc;
671 for (
ro = 0;
ro <
set->num_connectors;
ro++) {
672 if (
set->connectors[
ro] == connector)
673 new_crtc =
set->crtc;
678 !drm_encoder_crtc_ok(connector->
encoder, new_crtc)) {
682 if (new_crtc != connector->
encoder->crtc) {
683 DRM_DEBUG_KMS(
"crtc changed, full mode switch\n");
685 connector->
encoder->crtc = new_crtc;
688 DRM_DEBUG_KMS(
"[CONNECTOR:%d:%s] to [CRTC:%d]\n",
692 DRM_DEBUG_KMS(
"[CONNECTOR:%d:%s] to [NOCRTC]\n",
703 if (
set->crtc->enabled) {
704 DRM_DEBUG_KMS(
"attempting to set mode from"
707 old_fb =
set->crtc->fb;
708 set->crtc->fb =
set->fb;
712 DRM_ERROR(
"failed to set mode on [CRTC:%d]\n",
714 set->crtc->fb = old_fb;
718 DRM_DEBUG_KMS(
"Setting connector DPMS state to on\n");
719 for (i = 0; i <
set->num_connectors; i++) {
720 DRM_DEBUG_KMS(
"\t[CONNECTOR:%d:%s] set DPMS on\n",
set->connectors[i]->base.id,
726 }
else if (fb_changed) {
727 set->crtc->x =
set->x;
728 set->crtc->y =
set->y;
730 old_fb =
set->crtc->fb;
731 if (
set->crtc->fb !=
set->fb)
732 set->crtc->fb =
set->fb;
736 set->crtc->fb = old_fb;
741 kfree(save_connectors);
742 kfree(save_encoders);
750 *crtc = save_crtcs[count++];
755 *encoder = save_encoders[count++];
760 *connector = save_connectors[count++];
766 save_set.
y, save_set.
fb))
767 DRM_ERROR(
"failed to restore config after modeset failure\n");
769 kfree(save_connectors);
770 kfree(save_encoders);
776 static int drm_helper_choose_encoder_dpms(
struct drm_encoder *encoder)
783 if (connector->encoder == encoder)
784 if (connector->dpms < dpms)
785 dpms = connector->dpms;
796 if (connector->encoder && connector->encoder->crtc == crtc)
797 if (connector->dpms < dpms)
798 dpms = connector->dpms;
816 if (mode == connector->dpms)
819 old_dpms = connector->dpms;
820 connector->dpms =
mode;
823 if (mode < old_dpms) {
826 if (crtc_funcs->
dpms)
827 (*crtc_funcs->
dpms) (crtc,
828 drm_helper_choose_crtc_dpms(crtc));
832 if (encoder_funcs->
dpms)
833 (*encoder_funcs->
dpms) (encoder,
834 drm_helper_choose_encoder_dpms(encoder));
839 if (mode > old_dpms) {
842 if (encoder_funcs->
dpms)
843 (*encoder_funcs->
dpms) (encoder,
844 drm_helper_choose_encoder_dpms(encoder));
848 if (crtc_funcs->
dpms)
849 (*crtc_funcs->
dpms) (crtc,
850 drm_helper_choose_crtc_dpms(crtc));
865 for (i = 0; i < 4; i++) {
891 crtc->
x, crtc->
y, crtc->
fb);
894 DRM_ERROR(
"failed to set mode on crtc %p\n", crtc);
897 if (drm_helper_choose_crtc_dpms(crtc)) {
900 if(encoder->
crtc != crtc)
904 if (encoder_funcs->
dpms)
905 (*encoder_funcs->
dpms) (encoder,
906 drm_helper_choose_encoder_dpms(encoder));
910 if (crtc_funcs->
dpms)
911 (*crtc_funcs->
dpms) (crtc,
912 drm_helper_choose_crtc_dpms(crtc));
921 #define DRM_OUTPUT_POLL_PERIOD (10*HZ)
928 bool repoll =
false,
changed =
false;
930 if (!drm_kms_helper_poll)
944 old_status = connector->
status;
952 connector->
status = connector->
funcs->detect(connector,
false);
953 DRM_DEBUG_KMS(
"[CONNECTOR:%d:%s] status updated from %d to %d\n",
956 old_status, connector->
status);
957 if (old_status != connector->
status)
966 if (dev->mode_config.funcs->output_poll_changed)
967 dev->mode_config.funcs->output_poll_changed(dev);
976 if (!dev->mode_config.poll_enabled)
987 if (!dev->mode_config.poll_enabled || !drm_kms_helper_poll)
1003 dev->mode_config.poll_enabled =
true;
1017 if (!dev->mode_config.poll_enabled)
1022 if (drm_kms_helper_poll)