blob: e7e6c25b560c28ffc9b7a32705fc0bbf7f129e8b [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
2 * Copyright (c) 2006-2008 Intel Corporation
3 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
4 *
5 * DRM core CRTC related functions
6 *
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.
16 *
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
23 * OF THIS SOFTWARE.
24 *
25 * Authors:
26 * Keith Packard
27 * Eric Anholt <eric@anholt.net>
28 * Dave Airlie <airlied@linux.ie>
29 * Jesse Barnes <jesse.barnes@intel.com>
30 */
31
32#include "drmP.h"
33#include "drm_crtc.h"
34#include "drm_crtc_helper.h"
35
36/*
Dave Airlieaa91c662008-12-08 14:55:27 +100037 * Detailed mode info for 800x600@60Hz
Dave Airlief453ba02008-11-07 14:05:41 -080038 */
Jesse Barnes40a518d2009-01-12 12:05:32 -080039static struct drm_display_mode std_modes[] = {
Dave Airlieaa91c662008-12-08 14:55:27 +100040 { DRM_MODE("800x600", DRM_MODE_TYPE_DEFAULT, 40000, 800, 840,
41 968, 1056, 0, 600, 601, 605, 628, 0,
42 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Dave Airlief453ba02008-11-07 14:05:41 -080043};
44
yakui_zhao67149772009-04-02 11:52:12 +080045static void drm_mode_validate_flag(struct drm_connector *connector,
46 int flags)
47{
48 struct drm_display_mode *mode, *t;
49
50 if (flags == (DRM_MODE_FLAG_DBLSCAN | DRM_MODE_FLAG_INTERLACE))
51 return;
52
53 list_for_each_entry_safe(mode, t, &connector->modes, head) {
54 if ((mode->flags & DRM_MODE_FLAG_INTERLACE) &&
55 !(flags & DRM_MODE_FLAG_INTERLACE))
56 mode->status = MODE_NO_INTERLACE;
57 if ((mode->flags & DRM_MODE_FLAG_DBLSCAN) &&
58 !(flags & DRM_MODE_FLAG_DBLSCAN))
59 mode->status = MODE_NO_DBLESCAN;
60 }
61
62 return;
63}
64
Dave Airlief453ba02008-11-07 14:05:41 -080065/**
66 * drm_helper_probe_connector_modes - get complete set of display modes
67 * @dev: DRM device
68 * @maxX: max width for modes
69 * @maxY: max height for modes
70 *
71 * LOCKING:
72 * Caller must hold mode config lock.
73 *
74 * Based on @dev's mode_config layout, scan all the connectors and try to detect
75 * modes on them. Modes will first be added to the connector's probed_modes
76 * list, then culled (based on validity and the @maxX, @maxY parameters) and
77 * put into the normal modes list.
78 *
79 * Intended to be used either at bootup time or when major configuration
80 * changes have occurred.
81 *
82 * FIXME: take into account monitor limits
Jesse Barnes40a518d2009-01-12 12:05:32 -080083 *
84 * RETURNS:
85 * Number of modes found on @connector.
Dave Airlief453ba02008-11-07 14:05:41 -080086 */
Jesse Barnes40a518d2009-01-12 12:05:32 -080087int drm_helper_probe_single_connector_modes(struct drm_connector *connector,
88 uint32_t maxX, uint32_t maxY)
Dave Airlief453ba02008-11-07 14:05:41 -080089{
90 struct drm_device *dev = connector->dev;
91 struct drm_display_mode *mode, *t;
92 struct drm_connector_helper_funcs *connector_funcs =
93 connector->helper_private;
Jesse Barnes40a518d2009-01-12 12:05:32 -080094 int count = 0;
yakui_zhao67149772009-04-02 11:52:12 +080095 int mode_flags = 0;
Dave Airlief453ba02008-11-07 14:05:41 -080096
Zhao Yakui58367ed2009-07-20 13:48:07 +080097 DRM_DEBUG_KMS("%s\n", drm_get_connector_name(connector));
Dave Airlief453ba02008-11-07 14:05:41 -080098 /* set all modes to the unverified state */
99 list_for_each_entry_safe(mode, t, &connector->modes, head)
100 mode->status = MODE_UNVERIFIED;
101
102 connector->status = connector->funcs->detect(connector);
103
104 if (connector->status == connector_status_disconnected) {
Zhao Yakui58367ed2009-07-20 13:48:07 +0800105 DRM_DEBUG_KMS("%s is disconnected\n",
Dave Airlief453ba02008-11-07 14:05:41 -0800106 drm_get_connector_name(connector));
107 /* TODO set EDID to NULL */
Jesse Barnes40a518d2009-01-12 12:05:32 -0800108 return 0;
Dave Airlief453ba02008-11-07 14:05:41 -0800109 }
110
Jesse Barnes40a518d2009-01-12 12:05:32 -0800111 count = (*connector_funcs->get_modes)(connector);
112 if (!count)
113 return 0;
Dave Airlief453ba02008-11-07 14:05:41 -0800114
Jesse Barnes40a518d2009-01-12 12:05:32 -0800115 drm_mode_connector_list_update(connector);
Dave Airlief453ba02008-11-07 14:05:41 -0800116
117 if (maxX && maxY)
118 drm_mode_validate_size(dev, &connector->modes, maxX,
119 maxY, 0);
yakui_zhao67149772009-04-02 11:52:12 +0800120
121 if (connector->interlace_allowed)
122 mode_flags |= DRM_MODE_FLAG_INTERLACE;
123 if (connector->doublescan_allowed)
124 mode_flags |= DRM_MODE_FLAG_DBLSCAN;
125 drm_mode_validate_flag(connector, mode_flags);
126
Dave Airlief453ba02008-11-07 14:05:41 -0800127 list_for_each_entry_safe(mode, t, &connector->modes, head) {
128 if (mode->status == MODE_OK)
129 mode->status = connector_funcs->mode_valid(connector,
130 mode);
131 }
132
133
134 drm_mode_prune_invalid(dev, &connector->modes, true);
135
Jesse Barnes40a518d2009-01-12 12:05:32 -0800136 if (list_empty(&connector->modes))
137 return 0;
Dave Airlief453ba02008-11-07 14:05:41 -0800138
139 drm_mode_sort(&connector->modes);
140
Zhao Yakui58367ed2009-07-20 13:48:07 +0800141 DRM_DEBUG_KMS("Probed modes for %s\n",
142 drm_get_connector_name(connector));
Dave Airlief453ba02008-11-07 14:05:41 -0800143 list_for_each_entry_safe(mode, t, &connector->modes, head) {
144 mode->vrefresh = drm_mode_vrefresh(mode);
145
146 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
147 drm_mode_debug_printmodeline(mode);
148 }
Jesse Barnes40a518d2009-01-12 12:05:32 -0800149
150 return count;
Dave Airlief453ba02008-11-07 14:05:41 -0800151}
152EXPORT_SYMBOL(drm_helper_probe_single_connector_modes);
153
Jesse Barnes40a518d2009-01-12 12:05:32 -0800154int drm_helper_probe_connector_modes(struct drm_device *dev, uint32_t maxX,
Dave Airlief453ba02008-11-07 14:05:41 -0800155 uint32_t maxY)
156{
157 struct drm_connector *connector;
Jesse Barnes40a518d2009-01-12 12:05:32 -0800158 int count = 0;
Dave Airlief453ba02008-11-07 14:05:41 -0800159
160 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
Jesse Barnes40a518d2009-01-12 12:05:32 -0800161 count += drm_helper_probe_single_connector_modes(connector,
162 maxX, maxY);
Dave Airlief453ba02008-11-07 14:05:41 -0800163 }
Jesse Barnes40a518d2009-01-12 12:05:32 -0800164
165 return count;
Dave Airlief453ba02008-11-07 14:05:41 -0800166}
167EXPORT_SYMBOL(drm_helper_probe_connector_modes);
168
Jesse Barnes40a518d2009-01-12 12:05:32 -0800169static void drm_helper_add_std_modes(struct drm_device *dev,
170 struct drm_connector *connector)
171{
172 struct drm_display_mode *mode, *t;
173 int i;
174
175 for (i = 0; i < ARRAY_SIZE(std_modes); i++) {
176 struct drm_display_mode *stdmode;
177
178 /*
179 * When no valid EDID modes are available we end up
180 * here and bailed in the past, now we add some standard
181 * modes and move on.
182 */
183 stdmode = drm_mode_duplicate(dev, &std_modes[i]);
184 drm_mode_probed_add(connector, stdmode);
185 drm_mode_list_concat(&connector->probed_modes,
186 &connector->modes);
187
Zhao Yakui58367ed2009-07-20 13:48:07 +0800188 DRM_DEBUG_KMS("Adding mode %s to %s\n", stdmode->name,
Jesse Barnes40a518d2009-01-12 12:05:32 -0800189 drm_get_connector_name(connector));
190 }
191 drm_mode_sort(&connector->modes);
192
Zhao Yakui58367ed2009-07-20 13:48:07 +0800193 DRM_DEBUG_KMS("Added std modes on %s\n",
194 drm_get_connector_name(connector));
Jesse Barnes40a518d2009-01-12 12:05:32 -0800195 list_for_each_entry_safe(mode, t, &connector->modes, head) {
196 mode->vrefresh = drm_mode_vrefresh(mode);
197
198 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
199 drm_mode_debug_printmodeline(mode);
200 }
201}
Dave Airlief453ba02008-11-07 14:05:41 -0800202
203/**
Keith Packardc9fb15f2009-05-30 20:42:28 -0700204 * drm_helper_encoder_in_use - check if a given encoder is in use
205 * @encoder: encoder to check
206 *
207 * LOCKING:
208 * Caller must hold mode config lock.
209 *
210 * Walk @encoders's DRM device's mode_config and see if it's in use.
211 *
212 * RETURNS:
213 * True if @encoder is part of the mode_config, false otherwise.
214 */
215bool drm_helper_encoder_in_use(struct drm_encoder *encoder)
216{
217 struct drm_connector *connector;
218 struct drm_device *dev = encoder->dev;
219 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
220 if (connector->encoder == encoder)
221 return true;
222 return false;
223}
224EXPORT_SYMBOL(drm_helper_encoder_in_use);
225
226/**
Dave Airlief453ba02008-11-07 14:05:41 -0800227 * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config
228 * @crtc: CRTC to check
229 *
230 * LOCKING:
231 * Caller must hold mode config lock.
232 *
233 * Walk @crtc's DRM device's mode_config and see if it's in use.
234 *
235 * RETURNS:
236 * True if @crtc is part of the mode_config, false otherwise.
237 */
238bool drm_helper_crtc_in_use(struct drm_crtc *crtc)
239{
240 struct drm_encoder *encoder;
241 struct drm_device *dev = crtc->dev;
242 /* FIXME: Locking around list access? */
243 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
Keith Packardc9fb15f2009-05-30 20:42:28 -0700244 if (encoder->crtc == crtc && drm_helper_encoder_in_use(encoder))
Dave Airlief453ba02008-11-07 14:05:41 -0800245 return true;
246 return false;
247}
248EXPORT_SYMBOL(drm_helper_crtc_in_use);
249
250/**
251 * drm_disable_unused_functions - disable unused objects
252 * @dev: DRM device
253 *
254 * LOCKING:
255 * Caller must hold mode config lock.
256 *
257 * If an connector or CRTC isn't part of @dev's mode_config, it can be disabled
258 * by calling its dpms function, which should power it off.
259 */
260void drm_helper_disable_unused_functions(struct drm_device *dev)
261{
262 struct drm_encoder *encoder;
Dave Airliea3a05442009-08-31 15:16:30 +1000263 struct drm_connector *connector;
Dave Airlief453ba02008-11-07 14:05:41 -0800264 struct drm_encoder_helper_funcs *encoder_funcs;
265 struct drm_crtc *crtc;
266
Dave Airliea3a05442009-08-31 15:16:30 +1000267 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
268 if (!connector->encoder)
269 continue;
270 if (connector->status == connector_status_disconnected)
271 connector->encoder = NULL;
272 }
273
Dave Airlief453ba02008-11-07 14:05:41 -0800274 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
275 encoder_funcs = encoder->helper_private;
Dave Airliea3a05442009-08-31 15:16:30 +1000276 if (!drm_helper_encoder_in_use(encoder)) {
277 if (encoder_funcs->disable)
278 (*encoder_funcs->disable)(encoder);
279 else
280 (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF);
Dave Airlie9c552dd2009-09-02 14:00:11 +1000281 /* disconnector encoder from any connector */
282 encoder->crtc = NULL;
Dave Airliea3a05442009-08-31 15:16:30 +1000283 }
Dave Airlief453ba02008-11-07 14:05:41 -0800284 }
285
286 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
287 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
288 crtc->enabled = drm_helper_crtc_in_use(crtc);
289 if (!crtc->enabled) {
290 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
291 crtc->fb = NULL;
292 }
293 }
294}
295EXPORT_SYMBOL(drm_helper_disable_unused_functions);
296
297static struct drm_display_mode *drm_has_preferred_mode(struct drm_connector *connector, int width, int height)
298{
299 struct drm_display_mode *mode;
300
301 list_for_each_entry(mode, &connector->modes, head) {
302 if (drm_mode_width(mode) > width ||
303 drm_mode_height(mode) > height)
304 continue;
305 if (mode->type & DRM_MODE_TYPE_PREFERRED)
306 return mode;
307 }
308 return NULL;
309}
310
311static bool drm_connector_enabled(struct drm_connector *connector, bool strict)
312{
313 bool enable;
314
315 if (strict) {
316 enable = connector->status == connector_status_connected;
317 } else {
318 enable = connector->status != connector_status_disconnected;
319 }
320 return enable;
321}
322
323static void drm_enable_connectors(struct drm_device *dev, bool *enabled)
324{
325 bool any_enabled = false;
326 struct drm_connector *connector;
327 int i = 0;
328
329 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
330 enabled[i] = drm_connector_enabled(connector, true);
Zhao Yakui58367ed2009-07-20 13:48:07 +0800331 DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id,
Jesse Barnes40a518d2009-01-12 12:05:32 -0800332 enabled[i] ? "yes" : "no");
Dave Airlief453ba02008-11-07 14:05:41 -0800333 any_enabled |= enabled[i];
334 i++;
335 }
336
337 if (any_enabled)
338 return;
339
340 i = 0;
341 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
342 enabled[i] = drm_connector_enabled(connector, false);
343 i++;
344 }
345}
346
347static bool drm_target_preferred(struct drm_device *dev,
348 struct drm_display_mode **modes,
349 bool *enabled, int width, int height)
350{
351 struct drm_connector *connector;
352 int i = 0;
353
354 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
355
356 if (enabled[i] == false) {
357 i++;
358 continue;
359 }
360
Zhao Yakui58367ed2009-07-20 13:48:07 +0800361 DRM_DEBUG_KMS("looking for preferred mode on connector %d\n",
Jesse Barnes40a518d2009-01-12 12:05:32 -0800362 connector->base.id);
363
Dave Airlief453ba02008-11-07 14:05:41 -0800364 modes[i] = drm_has_preferred_mode(connector, width, height);
Jesse Barnes40a518d2009-01-12 12:05:32 -0800365 /* No preferred modes, pick one off the list */
366 if (!modes[i] && !list_empty(&connector->modes)) {
Dave Airlief453ba02008-11-07 14:05:41 -0800367 list_for_each_entry(modes[i], &connector->modes, head)
368 break;
369 }
Zhao Yakui58367ed2009-07-20 13:48:07 +0800370 DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name :
Jesse Barnes40a518d2009-01-12 12:05:32 -0800371 "none");
Dave Airlief453ba02008-11-07 14:05:41 -0800372 i++;
373 }
374 return true;
375}
376
377static int drm_pick_crtcs(struct drm_device *dev,
378 struct drm_crtc **best_crtcs,
379 struct drm_display_mode **modes,
380 int n, int width, int height)
381{
382 int c, o;
383 struct drm_connector *connector;
384 struct drm_connector_helper_funcs *connector_funcs;
385 struct drm_encoder *encoder;
386 struct drm_crtc *best_crtc;
387 int my_score, best_score, score;
388 struct drm_crtc **crtcs, *crtc;
389
390 if (n == dev->mode_config.num_connector)
391 return 0;
392 c = 0;
393 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
394 if (c == n)
395 break;
396 c++;
397 }
398
399 best_crtcs[n] = NULL;
400 best_crtc = NULL;
401 best_score = drm_pick_crtcs(dev, best_crtcs, modes, n+1, width, height);
402 if (modes[n] == NULL)
403 return best_score;
404
405 crtcs = kmalloc(dev->mode_config.num_connector *
406 sizeof(struct drm_crtc *), GFP_KERNEL);
407 if (!crtcs)
408 return best_score;
409
410 my_score = 1;
411 if (connector->status == connector_status_connected)
412 my_score++;
413 if (drm_has_preferred_mode(connector, width, height))
414 my_score++;
415
416 connector_funcs = connector->helper_private;
417 encoder = connector_funcs->best_encoder(connector);
418 if (!encoder)
419 goto out;
420
421 connector->encoder = encoder;
422
423 /* select a crtc for this connector and then attempt to configure
424 remaining connectors */
425 c = 0;
426 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
427
Dave Airliea3a05442009-08-31 15:16:30 +1000428 if ((encoder->possible_crtcs & (1 << c)) == 0) {
Dave Airlief453ba02008-11-07 14:05:41 -0800429 c++;
430 continue;
431 }
432
433 for (o = 0; o < n; o++)
434 if (best_crtcs[o] == crtc)
435 break;
436
437 if (o < n) {
438 /* ignore cloning for now */
439 c++;
440 continue;
441 }
442
443 crtcs[n] = crtc;
444 memcpy(crtcs, best_crtcs, n * sizeof(struct drm_crtc *));
445 score = my_score + drm_pick_crtcs(dev, crtcs, modes, n + 1,
446 width, height);
447 if (score > best_score) {
448 best_crtc = crtc;
449 best_score = score;
450 memcpy(best_crtcs, crtcs,
451 dev->mode_config.num_connector *
452 sizeof(struct drm_crtc *));
453 }
454 c++;
455 }
456out:
457 kfree(crtcs);
458 return best_score;
459}
460
461static void drm_setup_crtcs(struct drm_device *dev)
462{
463 struct drm_crtc **crtcs;
464 struct drm_display_mode **modes;
465 struct drm_encoder *encoder;
466 struct drm_connector *connector;
467 bool *enabled;
468 int width, height;
469 int i, ret;
470
Zhao Yakui58367ed2009-07-20 13:48:07 +0800471 DRM_DEBUG_KMS("\n");
Jesse Barnes40a518d2009-01-12 12:05:32 -0800472
Dave Airlief453ba02008-11-07 14:05:41 -0800473 width = dev->mode_config.max_width;
474 height = dev->mode_config.max_height;
475
476 /* clean out all the encoder/crtc combos */
477 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
478 encoder->crtc = NULL;
479 }
480
481 crtcs = kcalloc(dev->mode_config.num_connector,
482 sizeof(struct drm_crtc *), GFP_KERNEL);
483 modes = kcalloc(dev->mode_config.num_connector,
484 sizeof(struct drm_display_mode *), GFP_KERNEL);
485 enabled = kcalloc(dev->mode_config.num_connector,
486 sizeof(bool), GFP_KERNEL);
487
488 drm_enable_connectors(dev, enabled);
489
490 ret = drm_target_preferred(dev, modes, enabled, width, height);
491 if (!ret)
492 DRM_ERROR("Unable to find initial modes\n");
493
Zhao Yakui58367ed2009-07-20 13:48:07 +0800494 DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n", width, height);
Jesse Barnes40a518d2009-01-12 12:05:32 -0800495
Dave Airlief453ba02008-11-07 14:05:41 -0800496 drm_pick_crtcs(dev, crtcs, modes, 0, width, height);
497
498 i = 0;
499 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
500 struct drm_display_mode *mode = modes[i];
501 struct drm_crtc *crtc = crtcs[i];
502
503 if (connector->encoder == NULL) {
504 i++;
505 continue;
506 }
507
508 if (mode && crtc) {
Zhao Yakui58367ed2009-07-20 13:48:07 +0800509 DRM_DEBUG_KMS("desired mode %s set on crtc %d\n",
Jesse Barnes40a518d2009-01-12 12:05:32 -0800510 mode->name, crtc->base.id);
Dave Airlief453ba02008-11-07 14:05:41 -0800511 crtc->desired_mode = mode;
512 connector->encoder->crtc = crtc;
Dave Airliea3a05442009-08-31 15:16:30 +1000513 } else {
Dave Airlief453ba02008-11-07 14:05:41 -0800514 connector->encoder->crtc = NULL;
Dave Airliea3a05442009-08-31 15:16:30 +1000515 connector->encoder = NULL;
516 }
Dave Airlief453ba02008-11-07 14:05:41 -0800517 i++;
518 }
519
520 kfree(crtcs);
521 kfree(modes);
522 kfree(enabled);
523}
Jesse Barnes7bec7562009-02-23 16:09:34 -0800524
525/**
526 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
527 * @encoder: encoder to test
528 * @crtc: crtc to test
529 *
530 * Return false if @encoder can't be driven by @crtc, true otherwise.
531 */
532static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
533 struct drm_crtc *crtc)
534{
535 struct drm_device *dev;
536 struct drm_crtc *tmp;
537 int crtc_mask = 1;
538
539 WARN(!crtc, "checking null crtc?");
540
541 dev = crtc->dev;
542
543 list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) {
544 if (tmp == crtc)
545 break;
546 crtc_mask <<= 1;
547 }
548
549 if (encoder->possible_crtcs & crtc_mask)
550 return true;
551 return false;
552}
553
554/*
555 * Check the CRTC we're going to map each output to vs. its current
556 * CRTC. If they don't match, we have to disable the output and the CRTC
557 * since the driver will have to re-route things.
558 */
559static void
560drm_crtc_prepare_encoders(struct drm_device *dev)
561{
562 struct drm_encoder_helper_funcs *encoder_funcs;
563 struct drm_encoder *encoder;
564
565 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
566 encoder_funcs = encoder->helper_private;
567 /* Disable unused encoders */
568 if (encoder->crtc == NULL)
569 (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF);
570 /* Disable encoders whose CRTC is about to change */
571 if (encoder_funcs->get_crtc &&
572 encoder->crtc != (*encoder_funcs->get_crtc)(encoder))
573 (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF);
574 }
575}
576
Dave Airlief453ba02008-11-07 14:05:41 -0800577/**
578 * drm_crtc_set_mode - set a mode
579 * @crtc: CRTC to program
580 * @mode: mode to use
581 * @x: width of mode
582 * @y: height of mode
583 *
584 * LOCKING:
585 * Caller must hold mode config lock.
586 *
587 * Try to set @mode on @crtc. Give @crtc and its associated connectors a chance
588 * to fixup or reject the mode prior to trying to set it.
589 *
590 * RETURNS:
591 * True if the mode was set successfully, or false otherwise.
592 */
593bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
594 struct drm_display_mode *mode,
Kristian Høgsberg3c4fdcf2008-12-17 22:14:46 -0500595 int x, int y,
596 struct drm_framebuffer *old_fb)
Dave Airlief453ba02008-11-07 14:05:41 -0800597{
598 struct drm_device *dev = crtc->dev;
599 struct drm_display_mode *adjusted_mode, saved_mode;
600 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
601 struct drm_encoder_helper_funcs *encoder_funcs;
602 int saved_x, saved_y;
603 struct drm_encoder *encoder;
604 bool ret = true;
605
606 adjusted_mode = drm_mode_duplicate(dev, mode);
607
608 crtc->enabled = drm_helper_crtc_in_use(crtc);
609
610 if (!crtc->enabled)
611 return true;
612
613 saved_mode = crtc->mode;
614 saved_x = crtc->x;
615 saved_y = crtc->y;
616
617 /* Update crtc values up front so the driver can rely on them for mode
618 * setting.
619 */
620 crtc->mode = *mode;
621 crtc->x = x;
622 crtc->y = y;
623
Dave Airlief453ba02008-11-07 14:05:41 -0800624 /* Pass our mode to the connectors and the CRTC to give them a chance to
625 * adjust it according to limitations or connector properties, and also
626 * a chance to reject the mode entirely.
627 */
628 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
629
630 if (encoder->crtc != crtc)
631 continue;
632 encoder_funcs = encoder->helper_private;
633 if (!(ret = encoder_funcs->mode_fixup(encoder, mode,
634 adjusted_mode))) {
635 goto done;
636 }
637 }
638
639 if (!(ret = crtc_funcs->mode_fixup(crtc, mode, adjusted_mode))) {
640 goto done;
641 }
642
643 /* Prepare the encoders and CRTCs before setting the mode. */
644 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
645
646 if (encoder->crtc != crtc)
647 continue;
648 encoder_funcs = encoder->helper_private;
649 /* Disable the encoders as the first thing we do. */
650 encoder_funcs->prepare(encoder);
651 }
652
Jesse Barnes7bec7562009-02-23 16:09:34 -0800653 drm_crtc_prepare_encoders(dev);
654
Dave Airlief453ba02008-11-07 14:05:41 -0800655 crtc_funcs->prepare(crtc);
656
657 /* Set up the DPLL and any encoders state that needs to adjust or depend
658 * on the DPLL.
659 */
Chris Wilson5c3b82e2009-02-11 13:25:09 +0000660 ret = !crtc_funcs->mode_set(crtc, mode, adjusted_mode, x, y, old_fb);
661 if (!ret)
662 goto done;
Dave Airlief453ba02008-11-07 14:05:41 -0800663
664 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
665
666 if (encoder->crtc != crtc)
667 continue;
668
669 DRM_INFO("%s: set mode %s %x\n", drm_get_encoder_name(encoder),
670 mode->name, mode->base.id);
671 encoder_funcs = encoder->helper_private;
672 encoder_funcs->mode_set(encoder, mode, adjusted_mode);
673 }
674
675 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
676 crtc_funcs->commit(crtc);
677
678 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
679
680 if (encoder->crtc != crtc)
681 continue;
682
683 encoder_funcs = encoder->helper_private;
684 encoder_funcs->commit(encoder);
685
686 }
687
688 /* XXX free adjustedmode */
689 drm_mode_destroy(dev, adjusted_mode);
690 /* FIXME: add subpixel order */
691done:
692 if (!ret) {
693 crtc->mode = saved_mode;
694 crtc->x = saved_x;
695 crtc->y = saved_y;
696 }
697
698 return ret;
699}
700EXPORT_SYMBOL(drm_crtc_helper_set_mode);
701
702
703/**
704 * drm_crtc_helper_set_config - set a new config from userspace
705 * @crtc: CRTC to setup
706 * @crtc_info: user provided configuration
707 * @new_mode: new mode to set
708 * @connector_set: set of connectors for the new config
709 * @fb: new framebuffer
710 *
711 * LOCKING:
712 * Caller must hold mode config lock.
713 *
714 * Setup a new configuration, provided by the user in @crtc_info, and enable
715 * it.
716 *
717 * RETURNS:
718 * Zero. (FIXME)
719 */
720int drm_crtc_helper_set_config(struct drm_mode_set *set)
721{
722 struct drm_device *dev;
Maarten Maathuise67aae72009-08-27 10:18:29 +0200723 struct drm_crtc *save_crtcs, *new_crtc, *crtc;
724 struct drm_encoder *save_encoders, *new_encoder, *encoder;
Jesse Barnes7bec7562009-02-23 16:09:34 -0800725 struct drm_framebuffer *old_fb = NULL;
Jakob Bornecrantz4cb72b12009-08-03 13:43:59 +0100726 bool mode_changed = false; /* if true do a full mode set */
727 bool fb_changed = false; /* if true and !mode_changed just do a flip */
Maarten Maathuise67aae72009-08-27 10:18:29 +0200728 struct drm_connector *save_connectors, *connector;
Dave Airlief453ba02008-11-07 14:05:41 -0800729 int count = 0, ro, fail = 0;
730 struct drm_crtc_helper_funcs *crtc_funcs;
731 int ret = 0;
732
Zhao Yakui58367ed2009-07-20 13:48:07 +0800733 DRM_DEBUG_KMS("\n");
Dave Airlief453ba02008-11-07 14:05:41 -0800734
735 if (!set)
736 return -EINVAL;
737
738 if (!set->crtc)
739 return -EINVAL;
740
741 if (!set->crtc->helper_private)
742 return -EINVAL;
743
744 crtc_funcs = set->crtc->helper_private;
745
Zhao Yakui58367ed2009-07-20 13:48:07 +0800746 DRM_DEBUG_KMS("crtc: %p %d fb: %p connectors: %p num_connectors:"
747 " %d (x, y) (%i, %i)\n",
Dave Airlief453ba02008-11-07 14:05:41 -0800748 set->crtc, set->crtc->base.id, set->fb, set->connectors,
749 (int)set->num_connectors, set->x, set->y);
750
751 dev = set->crtc->dev;
752
Maarten Maathuise67aae72009-08-27 10:18:29 +0200753 /* Allocate space for the backup of all (non-pointer) crtc, encoder and
754 * connector data. */
755 save_crtcs = kzalloc(dev->mode_config.num_crtc *
756 sizeof(struct drm_crtc), GFP_KERNEL);
Dave Airlief453ba02008-11-07 14:05:41 -0800757 if (!save_crtcs)
758 return -ENOMEM;
759
Maarten Maathuise67aae72009-08-27 10:18:29 +0200760 save_encoders = kzalloc(dev->mode_config.num_encoder *
761 sizeof(struct drm_encoder), GFP_KERNEL);
Dave Airlief453ba02008-11-07 14:05:41 -0800762 if (!save_encoders) {
763 kfree(save_crtcs);
764 return -ENOMEM;
765 }
766
Maarten Maathuise67aae72009-08-27 10:18:29 +0200767 save_connectors = kzalloc(dev->mode_config.num_connector *
768 sizeof(struct drm_connector), GFP_KERNEL);
769 if (!save_connectors) {
770 kfree(save_crtcs);
771 kfree(save_encoders);
772 return -ENOMEM;
773 }
774
775 /* Copy data. Note that driver private data is not affected.
776 * Should anything bad happen only the expected state is
777 * restored, not the drivers personal bookkeeping.
778 */
779 count = 0;
780 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
781 save_crtcs[count++] = *crtc;
782 }
783
784 count = 0;
785 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
786 save_encoders[count++] = *encoder;
787 }
788
789 count = 0;
790 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
791 save_connectors[count++] = *connector;
792 }
793
Dave Airlief453ba02008-11-07 14:05:41 -0800794 /* We should be able to check here if the fb has the same properties
795 * and then just flip_or_move it */
796 if (set->crtc->fb != set->fb) {
Jesse Barnes712531b2009-01-09 13:56:14 -0800797 /* If we have no fb then treat it as a full mode set */
Jesse Barnes7bec7562009-02-23 16:09:34 -0800798 if (set->crtc->fb == NULL) {
Zhao Yakui58367ed2009-07-20 13:48:07 +0800799 DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
Jesse Barnes712531b2009-01-09 13:56:14 -0800800 mode_changed = true;
Jakob Bornecrantz4cb72b12009-08-03 13:43:59 +0100801 } else if (set->fb == NULL) {
802 mode_changed = true;
Jesse Barnes7bec7562009-02-23 16:09:34 -0800803 } else if ((set->fb->bits_per_pixel !=
Jesse Barnes712531b2009-01-09 13:56:14 -0800804 set->crtc->fb->bits_per_pixel) ||
805 set->fb->depth != set->crtc->fb->depth)
806 fb_changed = true;
Dave Airlief453ba02008-11-07 14:05:41 -0800807 else
Jesse Barnes712531b2009-01-09 13:56:14 -0800808 fb_changed = true;
Dave Airlief453ba02008-11-07 14:05:41 -0800809 }
810
811 if (set->x != set->crtc->x || set->y != set->crtc->y)
Jesse Barnes712531b2009-01-09 13:56:14 -0800812 fb_changed = true;
Dave Airlief453ba02008-11-07 14:05:41 -0800813
814 if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
Zhao Yakui58367ed2009-07-20 13:48:07 +0800815 DRM_DEBUG_KMS("modes are different, full mode set\n");
Dave Airlief453ba02008-11-07 14:05:41 -0800816 drm_mode_debug_printmodeline(&set->crtc->mode);
817 drm_mode_debug_printmodeline(set->mode);
Jesse Barnes712531b2009-01-09 13:56:14 -0800818 mode_changed = true;
Dave Airlief453ba02008-11-07 14:05:41 -0800819 }
820
821 /* a) traverse passed in connector list and get encoders for them */
822 count = 0;
823 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
824 struct drm_connector_helper_funcs *connector_funcs =
825 connector->helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -0800826 new_encoder = connector->encoder;
827 for (ro = 0; ro < set->num_connectors; ro++) {
828 if (set->connectors[ro] == connector) {
829 new_encoder = connector_funcs->best_encoder(connector);
830 /* if we can't get an encoder for a connector
831 we are setting now - then fail */
832 if (new_encoder == NULL)
833 /* don't break so fail path works correct */
834 fail = 1;
835 break;
836 }
837 }
838
839 if (new_encoder != connector->encoder) {
Zhao Yakui58367ed2009-07-20 13:48:07 +0800840 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
Jesse Barnes712531b2009-01-09 13:56:14 -0800841 mode_changed = true;
Maarten Maathuisff846ab2009-08-19 00:56:45 +0200842 /* If the encoder is reused for another connector, then
843 * the appropriate crtc will be set later.
844 */
Maarten Maathuisff6fdbe2009-09-01 03:39:04 +0200845 if (connector->encoder)
846 connector->encoder->crtc = NULL;
Dave Airlief453ba02008-11-07 14:05:41 -0800847 connector->encoder = new_encoder;
848 }
849 }
850
851 if (fail) {
852 ret = -EINVAL;
Maarten Maathuise67aae72009-08-27 10:18:29 +0200853 goto fail;
Dave Airlief453ba02008-11-07 14:05:41 -0800854 }
855
856 count = 0;
857 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
858 if (!connector->encoder)
859 continue;
860
Dave Airlief453ba02008-11-07 14:05:41 -0800861 if (connector->encoder->crtc == set->crtc)
862 new_crtc = NULL;
863 else
864 new_crtc = connector->encoder->crtc;
865
866 for (ro = 0; ro < set->num_connectors; ro++) {
867 if (set->connectors[ro] == connector)
868 new_crtc = set->crtc;
869 }
Jesse Barnes7bec7562009-02-23 16:09:34 -0800870
871 /* Make sure the new CRTC will work with the encoder */
872 if (new_crtc &&
873 !drm_encoder_crtc_ok(connector->encoder, new_crtc)) {
874 ret = -EINVAL;
Maarten Maathuise67aae72009-08-27 10:18:29 +0200875 goto fail;
Jesse Barnes7bec7562009-02-23 16:09:34 -0800876 }
Dave Airlief453ba02008-11-07 14:05:41 -0800877 if (new_crtc != connector->encoder->crtc) {
Zhao Yakui58367ed2009-07-20 13:48:07 +0800878 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
Jesse Barnes712531b2009-01-09 13:56:14 -0800879 mode_changed = true;
Dave Airlief453ba02008-11-07 14:05:41 -0800880 connector->encoder->crtc = new_crtc;
881 }
Zhao Yakui58367ed2009-07-20 13:48:07 +0800882 DRM_DEBUG_KMS("setting connector %d crtc to %p\n",
Jesse Barnes7bec7562009-02-23 16:09:34 -0800883 connector->base.id, new_crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800884 }
885
886 /* mode_set_base is not a required function */
Jesse Barnes712531b2009-01-09 13:56:14 -0800887 if (fb_changed && !crtc_funcs->mode_set_base)
888 mode_changed = true;
Dave Airlief453ba02008-11-07 14:05:41 -0800889
Jesse Barnes712531b2009-01-09 13:56:14 -0800890 if (mode_changed) {
Kristian Høgsberg3c4fdcf2008-12-17 22:14:46 -0500891 old_fb = set->crtc->fb;
Dave Airlief453ba02008-11-07 14:05:41 -0800892 set->crtc->fb = set->fb;
893 set->crtc->enabled = (set->mode != NULL);
894 if (set->mode != NULL) {
Zhao Yakui58367ed2009-07-20 13:48:07 +0800895 DRM_DEBUG_KMS("attempting to set mode from"
896 " userspace\n");
Dave Airlief453ba02008-11-07 14:05:41 -0800897 drm_mode_debug_printmodeline(set->mode);
898 if (!drm_crtc_helper_set_mode(set->crtc, set->mode,
Kristian Høgsberg3c4fdcf2008-12-17 22:14:46 -0500899 set->x, set->y,
900 old_fb)) {
Chris Wilson5c3b82e2009-02-11 13:25:09 +0000901 DRM_ERROR("failed to set mode on crtc %p\n",
902 set->crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800903 ret = -EINVAL;
Maarten Maathuise67aae72009-08-27 10:18:29 +0200904 goto fail;
Dave Airlief453ba02008-11-07 14:05:41 -0800905 }
906 /* TODO are these needed? */
907 set->crtc->desired_x = set->x;
908 set->crtc->desired_y = set->y;
909 set->crtc->desired_mode = set->mode;
910 }
911 drm_helper_disable_unused_functions(dev);
Jesse Barnes712531b2009-01-09 13:56:14 -0800912 } else if (fb_changed) {
Kristian Høgsberg3c4fdcf2008-12-17 22:14:46 -0500913 old_fb = set->crtc->fb;
Dave Airlief453ba02008-11-07 14:05:41 -0800914 if (set->crtc->fb != set->fb)
915 set->crtc->fb = set->fb;
Chris Wilson5c3b82e2009-02-11 13:25:09 +0000916 ret = crtc_funcs->mode_set_base(set->crtc,
917 set->x, set->y, old_fb);
918 if (ret != 0)
Maarten Maathuise67aae72009-08-27 10:18:29 +0200919 goto fail;
Dave Airlief453ba02008-11-07 14:05:41 -0800920 }
921
Maarten Maathuise67aae72009-08-27 10:18:29 +0200922 kfree(save_connectors);
Dave Airlief453ba02008-11-07 14:05:41 -0800923 kfree(save_encoders);
924 kfree(save_crtcs);
925 return 0;
926
Maarten Maathuise67aae72009-08-27 10:18:29 +0200927fail:
928 /* Restore all previous data. */
Dave Airlief453ba02008-11-07 14:05:41 -0800929 count = 0;
Maarten Maathuise67aae72009-08-27 10:18:29 +0200930 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
931 *crtc = save_crtcs[count++];
932 }
Chris Wilsone62fb642009-02-11 16:39:21 +0000933
Maarten Maathuise67aae72009-08-27 10:18:29 +0200934 count = 0;
935 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
936 *encoder = save_encoders[count++];
Chris Wilsone62fb642009-02-11 16:39:21 +0000937 }
Maarten Maathuise67aae72009-08-27 10:18:29 +0200938
Dave Airlief453ba02008-11-07 14:05:41 -0800939 count = 0;
940 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
Maarten Maathuise67aae72009-08-27 10:18:29 +0200941 *connector = save_connectors[count++];
Dave Airlief453ba02008-11-07 14:05:41 -0800942 }
Maarten Maathuise67aae72009-08-27 10:18:29 +0200943
944 kfree(save_connectors);
Dave Airlief453ba02008-11-07 14:05:41 -0800945 kfree(save_encoders);
Maarten Maathuise67aae72009-08-27 10:18:29 +0200946 kfree(save_crtcs);
Dave Airlief453ba02008-11-07 14:05:41 -0800947 return ret;
948}
949EXPORT_SYMBOL(drm_crtc_helper_set_config);
950
951bool drm_helper_plugged_event(struct drm_device *dev)
952{
Zhao Yakui58367ed2009-07-20 13:48:07 +0800953 DRM_DEBUG_KMS("\n");
Dave Airlief453ba02008-11-07 14:05:41 -0800954
955 drm_helper_probe_connector_modes(dev, dev->mode_config.max_width,
956 dev->mode_config.max_height);
957
958 drm_setup_crtcs(dev);
959
960 /* alert the driver fb layer */
961 dev->mode_config.funcs->fb_changed(dev);
962
963 /* FIXME: send hotplug event */
964 return true;
965}
966/**
967 * drm_initial_config - setup a sane initial connector configuration
968 * @dev: DRM device
Dave Airlief453ba02008-11-07 14:05:41 -0800969 *
970 * LOCKING:
971 * Called at init time, must take mode config lock.
972 *
973 * Scan the CRTCs and connectors and try to put together an initial setup.
974 * At the moment, this is a cloned configuration across all heads with
975 * a new framebuffer object as the backing store.
976 *
977 * RETURNS:
978 * Zero if everything went ok, nonzero otherwise.
979 */
Jesse Barnes7a1fb5d2009-03-27 13:05:19 -0700980bool drm_helper_initial_config(struct drm_device *dev)
Dave Airlief453ba02008-11-07 14:05:41 -0800981{
Jesse Barnes40a518d2009-01-12 12:05:32 -0800982 struct drm_connector *connector;
983 int count = 0;
Dave Airlief453ba02008-11-07 14:05:41 -0800984
Jesse Barnes40a518d2009-01-12 12:05:32 -0800985 count = drm_helper_probe_connector_modes(dev,
986 dev->mode_config.max_width,
987 dev->mode_config.max_height);
988
989 /*
990 * None of the available connectors had any modes, so add some
991 * and try to light them up anyway
992 */
993 if (!count) {
994 DRM_ERROR("connectors have no modes, using standard modes\n");
995 list_for_each_entry(connector,
996 &dev->mode_config.connector_list,
997 head)
998 drm_helper_add_std_modes(dev, connector);
999 }
1000
1001 drm_setup_crtcs(dev);
1002
1003 /* alert the driver fb layer */
1004 dev->mode_config.funcs->fb_changed(dev);
1005
1006 return 0;
Dave Airlief453ba02008-11-07 14:05:41 -08001007}
1008EXPORT_SYMBOL(drm_helper_initial_config);
1009
Keith Packardc9fb15f2009-05-30 20:42:28 -07001010static int drm_helper_choose_encoder_dpms(struct drm_encoder *encoder)
1011{
1012 int dpms = DRM_MODE_DPMS_OFF;
1013 struct drm_connector *connector;
1014 struct drm_device *dev = encoder->dev;
1015
1016 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
1017 if (connector->encoder == encoder)
1018 if (connector->dpms < dpms)
1019 dpms = connector->dpms;
1020 return dpms;
1021}
1022
1023static int drm_helper_choose_crtc_dpms(struct drm_crtc *crtc)
1024{
1025 int dpms = DRM_MODE_DPMS_OFF;
1026 struct drm_connector *connector;
1027 struct drm_device *dev = crtc->dev;
1028
1029 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
1030 if (connector->encoder && connector->encoder->crtc == crtc)
1031 if (connector->dpms < dpms)
1032 dpms = connector->dpms;
1033 return dpms;
1034}
1035
1036/**
1037 * drm_helper_connector_dpms
1038 * @connector affected connector
1039 * @mode DPMS mode
1040 *
1041 * Calls the low-level connector DPMS function, then
1042 * calls appropriate encoder and crtc DPMS functions as well
1043 */
1044void drm_helper_connector_dpms(struct drm_connector *connector, int mode)
1045{
1046 struct drm_encoder *encoder = connector->encoder;
1047 struct drm_crtc *crtc = encoder ? encoder->crtc : NULL;
1048 int old_dpms;
1049
1050 if (mode == connector->dpms)
1051 return;
1052
1053 old_dpms = connector->dpms;
1054 connector->dpms = mode;
1055
1056 /* from off to on, do crtc then encoder */
1057 if (mode < old_dpms) {
1058 if (crtc) {
1059 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
1060 if (crtc_funcs->dpms)
1061 (*crtc_funcs->dpms) (crtc,
1062 drm_helper_choose_crtc_dpms(crtc));
1063 }
1064 if (encoder) {
1065 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
1066 if (encoder_funcs->dpms)
1067 (*encoder_funcs->dpms) (encoder,
1068 drm_helper_choose_encoder_dpms(encoder));
1069 }
1070 }
1071
1072 /* from on to off, do encoder then crtc */
1073 if (mode > old_dpms) {
1074 if (encoder) {
1075 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
1076 if (encoder_funcs->dpms)
1077 (*encoder_funcs->dpms) (encoder,
1078 drm_helper_choose_encoder_dpms(encoder));
1079 }
1080 if (crtc) {
1081 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
1082 if (crtc_funcs->dpms)
1083 (*crtc_funcs->dpms) (crtc,
1084 drm_helper_choose_crtc_dpms(crtc));
1085 }
1086 }
1087
1088 return;
1089}
1090EXPORT_SYMBOL(drm_helper_connector_dpms);
1091
Dave Airlief453ba02008-11-07 14:05:41 -08001092/**
1093 * drm_hotplug_stage_two
1094 * @dev DRM device
1095 * @connector hotpluged connector
1096 *
1097 * LOCKING.
1098 * Caller must hold mode config lock, function might grab struct lock.
1099 *
1100 * Stage two of a hotplug.
1101 *
1102 * RETURNS:
1103 * Zero on success, errno on failure.
1104 */
1105int drm_helper_hotplug_stage_two(struct drm_device *dev)
1106{
Dave Airlief453ba02008-11-07 14:05:41 -08001107 drm_helper_plugged_event(dev);
1108
1109 return 0;
1110}
1111EXPORT_SYMBOL(drm_helper_hotplug_stage_two);
1112
1113int drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
1114 struct drm_mode_fb_cmd *mode_cmd)
1115{
1116 fb->width = mode_cmd->width;
1117 fb->height = mode_cmd->height;
1118 fb->pitch = mode_cmd->pitch;
1119 fb->bits_per_pixel = mode_cmd->bpp;
1120 fb->depth = mode_cmd->depth;
1121
1122 return 0;
1123}
1124EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct);
1125
1126int drm_helper_resume_force_mode(struct drm_device *dev)
1127{
1128 struct drm_crtc *crtc;
1129 int ret;
1130
1131 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
1132
1133 if (!crtc->enabled)
1134 continue;
1135
Kristian Høgsberg3c4fdcf2008-12-17 22:14:46 -05001136 ret = drm_crtc_helper_set_mode(crtc, &crtc->mode,
1137 crtc->x, crtc->y, crtc->fb);
Dave Airlief453ba02008-11-07 14:05:41 -08001138
1139 if (ret == false)
1140 DRM_ERROR("failed to set mode on crtc %p\n", crtc);
1141 }
Zhao Yakuiaf4fcb52009-07-08 14:13:13 +08001142 /* disable the unused connectors while restoring the modesetting */
1143 drm_helper_disable_unused_functions(dev);
Dave Airlief453ba02008-11-07 14:05:41 -08001144 return 0;
1145}
1146EXPORT_SYMBOL(drm_helper_resume_force_mode);