aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/drm_crtc_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/drm_crtc_helper.c')
-rw-r--r--drivers/gpu/drm/drm_crtc_helper.c175
1 files changed, 126 insertions, 49 deletions
diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index d8a982b71296..964c5eb1fada 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -36,7 +36,7 @@
36/* 36/*
37 * Detailed mode info for 800x600@60Hz 37 * Detailed mode info for 800x600@60Hz
38 */ 38 */
39static struct drm_display_mode std_mode[] = { 39static struct drm_display_mode std_modes[] = {
40 { DRM_MODE("800x600", DRM_MODE_TYPE_DEFAULT, 40000, 800, 840, 40 { DRM_MODE("800x600", DRM_MODE_TYPE_DEFAULT, 40000, 800, 840,
41 968, 1056, 0, 600, 601, 605, 628, 0, 41 968, 1056, 0, 600, 601, 605, 628, 0,
42 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, 42 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
@@ -60,15 +60,18 @@ static struct drm_display_mode std_mode[] = {
60 * changes have occurred. 60 * changes have occurred.
61 * 61 *
62 * FIXME: take into account monitor limits 62 * FIXME: take into account monitor limits
63 *
64 * RETURNS:
65 * Number of modes found on @connector.
63 */ 66 */
64void drm_helper_probe_single_connector_modes(struct drm_connector *connector, 67int drm_helper_probe_single_connector_modes(struct drm_connector *connector,
65 uint32_t maxX, uint32_t maxY) 68 uint32_t maxX, uint32_t maxY)
66{ 69{
67 struct drm_device *dev = connector->dev; 70 struct drm_device *dev = connector->dev;
68 struct drm_display_mode *mode, *t; 71 struct drm_display_mode *mode, *t;
69 struct drm_connector_helper_funcs *connector_funcs = 72 struct drm_connector_helper_funcs *connector_funcs =
70 connector->helper_private; 73 connector->helper_private;
71 int ret; 74 int count = 0;
72 75
73 DRM_DEBUG("%s\n", drm_get_connector_name(connector)); 76 DRM_DEBUG("%s\n", drm_get_connector_name(connector));
74 /* set all modes to the unverified state */ 77 /* set all modes to the unverified state */
@@ -81,14 +84,14 @@ void drm_helper_probe_single_connector_modes(struct drm_connector *connector,
81 DRM_DEBUG("%s is disconnected\n", 84 DRM_DEBUG("%s is disconnected\n",
82 drm_get_connector_name(connector)); 85 drm_get_connector_name(connector));
83 /* TODO set EDID to NULL */ 86 /* TODO set EDID to NULL */
84 return; 87 return 0;
85 } 88 }
86 89
87 ret = (*connector_funcs->get_modes)(connector); 90 count = (*connector_funcs->get_modes)(connector);
91 if (!count)
92 return 0;
88 93
89 if (ret) { 94 drm_mode_connector_list_update(connector);
90 drm_mode_connector_list_update(connector);
91 }
92 95
93 if (maxX && maxY) 96 if (maxX && maxY)
94 drm_mode_validate_size(dev, &connector->modes, maxX, 97 drm_mode_validate_size(dev, &connector->modes, maxX,
@@ -102,25 +105,8 @@ void drm_helper_probe_single_connector_modes(struct drm_connector *connector,
102 105
103 drm_mode_prune_invalid(dev, &connector->modes, true); 106 drm_mode_prune_invalid(dev, &connector->modes, true);
104 107
105 if (list_empty(&connector->modes)) { 108 if (list_empty(&connector->modes))
106 struct drm_display_mode *stdmode; 109 return 0;
107
108 DRM_DEBUG("No valid modes on %s\n",
109 drm_get_connector_name(connector));
110
111 /* Should we do this here ???
112 * When no valid EDID modes are available we end up
113 * here and bailed in the past, now we add a standard
114 * 640x480@60Hz mode and carry on.
115 */
116 stdmode = drm_mode_duplicate(dev, &std_mode[0]);
117 drm_mode_probed_add(connector, stdmode);
118 drm_mode_list_concat(&connector->probed_modes,
119 &connector->modes);
120
121 DRM_DEBUG("Adding standard 640x480 @ 60Hz to %s\n",
122 drm_get_connector_name(connector));
123 }
124 110
125 drm_mode_sort(&connector->modes); 111 drm_mode_sort(&connector->modes);
126 112
@@ -131,20 +117,58 @@ void drm_helper_probe_single_connector_modes(struct drm_connector *connector,
131 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); 117 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
132 drm_mode_debug_printmodeline(mode); 118 drm_mode_debug_printmodeline(mode);
133 } 119 }
120
121 return count;
134} 122}
135EXPORT_SYMBOL(drm_helper_probe_single_connector_modes); 123EXPORT_SYMBOL(drm_helper_probe_single_connector_modes);
136 124
137void drm_helper_probe_connector_modes(struct drm_device *dev, uint32_t maxX, 125int drm_helper_probe_connector_modes(struct drm_device *dev, uint32_t maxX,
138 uint32_t maxY) 126 uint32_t maxY)
139{ 127{
140 struct drm_connector *connector; 128 struct drm_connector *connector;
129 int count = 0;
141 130
142 list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 131 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
143 drm_helper_probe_single_connector_modes(connector, maxX, maxY); 132 count += drm_helper_probe_single_connector_modes(connector,
133 maxX, maxY);
144 } 134 }
135
136 return count;
145} 137}
146EXPORT_SYMBOL(drm_helper_probe_connector_modes); 138EXPORT_SYMBOL(drm_helper_probe_connector_modes);
147 139
140static void drm_helper_add_std_modes(struct drm_device *dev,
141 struct drm_connector *connector)
142{
143 struct drm_display_mode *mode, *t;
144 int i;
145
146 for (i = 0; i < ARRAY_SIZE(std_modes); i++) {
147 struct drm_display_mode *stdmode;
148
149 /*
150 * When no valid EDID modes are available we end up
151 * here and bailed in the past, now we add some standard
152 * modes and move on.
153 */
154 stdmode = drm_mode_duplicate(dev, &std_modes[i]);
155 drm_mode_probed_add(connector, stdmode);
156 drm_mode_list_concat(&connector->probed_modes,
157 &connector->modes);
158
159 DRM_DEBUG("Adding mode %s to %s\n", stdmode->name,
160 drm_get_connector_name(connector));
161 }
162 drm_mode_sort(&connector->modes);
163
164 DRM_DEBUG("Added std modes on %s\n", drm_get_connector_name(connector));
165 list_for_each_entry_safe(mode, t, &connector->modes, head) {
166 mode->vrefresh = drm_mode_vrefresh(mode);
167
168 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
169 drm_mode_debug_printmodeline(mode);
170 }
171}
148 172
149/** 173/**
150 * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config 174 * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config
@@ -237,6 +261,8 @@ static void drm_enable_connectors(struct drm_device *dev, bool *enabled)
237 261
238 list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 262 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
239 enabled[i] = drm_connector_enabled(connector, true); 263 enabled[i] = drm_connector_enabled(connector, true);
264 DRM_DEBUG("connector %d enabled? %s\n", connector->base.id,
265 enabled[i] ? "yes" : "no");
240 any_enabled |= enabled[i]; 266 any_enabled |= enabled[i];
241 i++; 267 i++;
242 } 268 }
@@ -265,11 +291,17 @@ static bool drm_target_preferred(struct drm_device *dev,
265 continue; 291 continue;
266 } 292 }
267 293
294 DRM_DEBUG("looking for preferred mode on connector %d\n",
295 connector->base.id);
296
268 modes[i] = drm_has_preferred_mode(connector, width, height); 297 modes[i] = drm_has_preferred_mode(connector, width, height);
269 if (!modes[i]) { 298 /* No preferred modes, pick one off the list */
299 if (!modes[i] && !list_empty(&connector->modes)) {
270 list_for_each_entry(modes[i], &connector->modes, head) 300 list_for_each_entry(modes[i], &connector->modes, head)
271 break; 301 break;
272 } 302 }
303 DRM_DEBUG("found mode %s\n", modes[i] ? modes[i]->name :
304 "none");
273 i++; 305 i++;
274 } 306 }
275 return true; 307 return true;
@@ -369,6 +401,8 @@ static void drm_setup_crtcs(struct drm_device *dev)
369 int width, height; 401 int width, height;
370 int i, ret; 402 int i, ret;
371 403
404 DRM_DEBUG("\n");
405
372 width = dev->mode_config.max_width; 406 width = dev->mode_config.max_width;
373 height = dev->mode_config.max_height; 407 height = dev->mode_config.max_height;
374 408
@@ -390,6 +424,8 @@ static void drm_setup_crtcs(struct drm_device *dev)
390 if (!ret) 424 if (!ret)
391 DRM_ERROR("Unable to find initial modes\n"); 425 DRM_ERROR("Unable to find initial modes\n");
392 426
427 DRM_DEBUG("picking CRTCs for %dx%d config\n", width, height);
428
393 drm_pick_crtcs(dev, crtcs, modes, 0, width, height); 429 drm_pick_crtcs(dev, crtcs, modes, 0, width, height);
394 430
395 i = 0; 431 i = 0;
@@ -403,6 +439,8 @@ static void drm_setup_crtcs(struct drm_device *dev)
403 } 439 }
404 440
405 if (mode && crtc) { 441 if (mode && crtc) {
442 DRM_DEBUG("desired mode %s set on crtc %d\n",
443 mode->name, crtc->base.id);
406 crtc->desired_mode = mode; 444 crtc->desired_mode = mode;
407 connector->encoder->crtc = crtc; 445 connector->encoder->crtc = crtc;
408 } else 446 } else
@@ -442,6 +480,7 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
442 int saved_x, saved_y; 480 int saved_x, saved_y;
443 struct drm_encoder *encoder; 481 struct drm_encoder *encoder;
444 bool ret = true; 482 bool ret = true;
483 bool depth_changed, bpp_changed;
445 484
446 adjusted_mode = drm_mode_duplicate(dev, mode); 485 adjusted_mode = drm_mode_duplicate(dev, mode);
447 486
@@ -450,6 +489,15 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
450 if (!crtc->enabled) 489 if (!crtc->enabled)
451 return true; 490 return true;
452 491
492 if (old_fb && crtc->fb) {
493 depth_changed = (old_fb->depth != crtc->fb->depth);
494 bpp_changed = (old_fb->bits_per_pixel !=
495 crtc->fb->bits_per_pixel);
496 } else {
497 depth_changed = true;
498 bpp_changed = true;
499 }
500
453 saved_mode = crtc->mode; 501 saved_mode = crtc->mode;
454 saved_x = crtc->x; 502 saved_x = crtc->x;
455 saved_y = crtc->y; 503 saved_y = crtc->y;
@@ -462,7 +510,8 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
462 crtc->y = y; 510 crtc->y = y;
463 511
464 if (drm_mode_equal(&saved_mode, &crtc->mode)) { 512 if (drm_mode_equal(&saved_mode, &crtc->mode)) {
465 if (saved_x != crtc->x || saved_y != crtc->y) { 513 if (saved_x != crtc->x || saved_y != crtc->y ||
514 depth_changed || bpp_changed) {
466 crtc_funcs->mode_set_base(crtc, crtc->x, crtc->y, 515 crtc_funcs->mode_set_base(crtc, crtc->x, crtc->y,
467 old_fb); 516 old_fb);
468 goto done; 517 goto done;
@@ -568,8 +617,8 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
568 struct drm_encoder **save_encoders, *new_encoder; 617 struct drm_encoder **save_encoders, *new_encoder;
569 struct drm_framebuffer *old_fb; 618 struct drm_framebuffer *old_fb;
570 bool save_enabled; 619 bool save_enabled;
571 bool changed = false; 620 bool mode_changed = false;
572 bool flip_or_move = false; 621 bool fb_changed = false;
573 struct drm_connector *connector; 622 struct drm_connector *connector;
574 int count = 0, ro, fail = 0; 623 int count = 0, ro, fail = 0;
575 struct drm_crtc_helper_funcs *crtc_funcs; 624 struct drm_crtc_helper_funcs *crtc_funcs;
@@ -597,7 +646,10 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
597 /* save previous config */ 646 /* save previous config */
598 save_enabled = set->crtc->enabled; 647 save_enabled = set->crtc->enabled;
599 648
600 /* this is meant to be num_connector not num_crtc */ 649 /*
650 * We do mode_config.num_connectors here since we'll look at the
651 * CRTC and encoder associated with each connector later.
652 */
601 save_crtcs = kzalloc(dev->mode_config.num_connector * 653 save_crtcs = kzalloc(dev->mode_config.num_connector *
602 sizeof(struct drm_crtc *), GFP_KERNEL); 654 sizeof(struct drm_crtc *), GFP_KERNEL);
603 if (!save_crtcs) 655 if (!save_crtcs)
@@ -613,21 +665,25 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
613 /* We should be able to check here if the fb has the same properties 665 /* We should be able to check here if the fb has the same properties
614 * and then just flip_or_move it */ 666 * and then just flip_or_move it */
615 if (set->crtc->fb != set->fb) { 667 if (set->crtc->fb != set->fb) {
616 /* if we have no fb then its a change not a flip */ 668 /* If we have no fb then treat it as a full mode set */
617 if (set->crtc->fb == NULL) 669 if (set->crtc->fb == NULL)
618 changed = true; 670 mode_changed = true;
671 else if ((set->fb->bits_per_pixel !=
672 set->crtc->fb->bits_per_pixel) ||
673 set->fb->depth != set->crtc->fb->depth)
674 fb_changed = true;
619 else 675 else
620 flip_or_move = true; 676 fb_changed = true;
621 } 677 }
622 678
623 if (set->x != set->crtc->x || set->y != set->crtc->y) 679 if (set->x != set->crtc->x || set->y != set->crtc->y)
624 flip_or_move = true; 680 fb_changed = true;
625 681
626 if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) { 682 if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
627 DRM_DEBUG("modes are different\n"); 683 DRM_DEBUG("modes are different\n");
628 drm_mode_debug_printmodeline(&set->crtc->mode); 684 drm_mode_debug_printmodeline(&set->crtc->mode);
629 drm_mode_debug_printmodeline(set->mode); 685 drm_mode_debug_printmodeline(set->mode);
630 changed = true; 686 mode_changed = true;
631 } 687 }
632 688
633 /* a) traverse passed in connector list and get encoders for them */ 689 /* a) traverse passed in connector list and get encoders for them */
@@ -650,7 +706,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
650 } 706 }
651 707
652 if (new_encoder != connector->encoder) { 708 if (new_encoder != connector->encoder) {
653 changed = true; 709 mode_changed = true;
654 connector->encoder = new_encoder; 710 connector->encoder = new_encoder;
655 } 711 }
656 } 712 }
@@ -677,16 +733,16 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
677 new_crtc = set->crtc; 733 new_crtc = set->crtc;
678 } 734 }
679 if (new_crtc != connector->encoder->crtc) { 735 if (new_crtc != connector->encoder->crtc) {
680 changed = true; 736 mode_changed = true;
681 connector->encoder->crtc = new_crtc; 737 connector->encoder->crtc = new_crtc;
682 } 738 }
683 } 739 }
684 740
685 /* mode_set_base is not a required function */ 741 /* mode_set_base is not a required function */
686 if (flip_or_move && !crtc_funcs->mode_set_base) 742 if (fb_changed && !crtc_funcs->mode_set_base)
687 changed = true; 743 mode_changed = true;
688 744
689 if (changed) { 745 if (mode_changed) {
690 old_fb = set->crtc->fb; 746 old_fb = set->crtc->fb;
691 set->crtc->fb = set->fb; 747 set->crtc->fb = set->fb;
692 set->crtc->enabled = (set->mode != NULL); 748 set->crtc->enabled = (set->mode != NULL);
@@ -705,7 +761,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
705 set->crtc->desired_mode = set->mode; 761 set->crtc->desired_mode = set->mode;
706 } 762 }
707 drm_helper_disable_unused_functions(dev); 763 drm_helper_disable_unused_functions(dev);
708 } else if (flip_or_move) { 764 } else if (fb_changed) {
709 old_fb = set->crtc->fb; 765 old_fb = set->crtc->fb;
710 if (set->crtc->fb != set->fb) 766 if (set->crtc->fb != set->fb)
711 set->crtc->fb = set->fb; 767 set->crtc->fb = set->fb;
@@ -764,10 +820,31 @@ bool drm_helper_plugged_event(struct drm_device *dev)
764 */ 820 */
765bool drm_helper_initial_config(struct drm_device *dev, bool can_grow) 821bool drm_helper_initial_config(struct drm_device *dev, bool can_grow)
766{ 822{
767 int ret = false; 823 struct drm_connector *connector;
824 int count = 0;
768 825
769 drm_helper_plugged_event(dev); 826 count = drm_helper_probe_connector_modes(dev,
770 return ret; 827 dev->mode_config.max_width,
828 dev->mode_config.max_height);
829
830 /*
831 * None of the available connectors had any modes, so add some
832 * and try to light them up anyway
833 */
834 if (!count) {
835 DRM_ERROR("connectors have no modes, using standard modes\n");
836 list_for_each_entry(connector,
837 &dev->mode_config.connector_list,
838 head)
839 drm_helper_add_std_modes(dev, connector);
840 }
841
842 drm_setup_crtcs(dev);
843
844 /* alert the driver fb layer */
845 dev->mode_config.funcs->fb_changed(dev);
846
847 return 0;
771} 848}
772EXPORT_SYMBOL(drm_helper_initial_config); 849EXPORT_SYMBOL(drm_helper_initial_config);
773 850