Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1 | /* |
| 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" |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 35 | #include "drm_fb_helper.h" |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 36 | |
yakui_zhao | 6714977 | 2009-04-02 11:52:12 +0800 | [diff] [blame] | 37 | static void drm_mode_validate_flag(struct drm_connector *connector, |
| 38 | int flags) |
| 39 | { |
| 40 | struct drm_display_mode *mode, *t; |
| 41 | |
| 42 | if (flags == (DRM_MODE_FLAG_DBLSCAN | DRM_MODE_FLAG_INTERLACE)) |
| 43 | return; |
| 44 | |
| 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; |
| 52 | } |
| 53 | |
| 54 | return; |
| 55 | } |
| 56 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 57 | /** |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame^] | 58 | * drm_helper_probe_single_connector_modes - get complete set of display modes |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 59 | * @dev: DRM device |
| 60 | * @maxX: max width for modes |
| 61 | * @maxY: max height for modes |
| 62 | * |
| 63 | * LOCKING: |
| 64 | * Caller must hold mode config lock. |
| 65 | * |
| 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. |
| 70 | * |
| 71 | * Intended to be used either at bootup time or when major configuration |
| 72 | * changes have occurred. |
| 73 | * |
| 74 | * FIXME: take into account monitor limits |
Jesse Barnes | 40a518d | 2009-01-12 12:05:32 -0800 | [diff] [blame] | 75 | * |
| 76 | * RETURNS: |
| 77 | * Number of modes found on @connector. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 78 | */ |
Jesse Barnes | 40a518d | 2009-01-12 12:05:32 -0800 | [diff] [blame] | 79 | int drm_helper_probe_single_connector_modes(struct drm_connector *connector, |
| 80 | uint32_t maxX, uint32_t maxY) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 81 | { |
| 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; |
Jesse Barnes | 40a518d | 2009-01-12 12:05:32 -0800 | [diff] [blame] | 86 | int count = 0; |
yakui_zhao | 6714977 | 2009-04-02 11:52:12 +0800 | [diff] [blame] | 87 | int mode_flags = 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 88 | |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 89 | DRM_DEBUG_KMS("%s\n", drm_get_connector_name(connector)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 90 | /* set all modes to the unverified state */ |
| 91 | list_for_each_entry_safe(mode, t, &connector->modes, head) |
| 92 | mode->status = MODE_UNVERIFIED; |
| 93 | |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 94 | if (connector->force) { |
| 95 | if (connector->force == DRM_FORCE_ON) |
| 96 | connector->status = connector_status_connected; |
| 97 | else |
| 98 | connector->status = connector_status_disconnected; |
| 99 | if (connector->funcs->force) |
| 100 | connector->funcs->force(connector); |
| 101 | } else |
| 102 | connector->status = connector->funcs->detect(connector); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 103 | |
| 104 | if (connector->status == connector_status_disconnected) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 105 | DRM_DEBUG_KMS("%s is disconnected\n", |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 106 | drm_get_connector_name(connector)); |
Zhao Yakui | 7253983 | 2010-03-04 08:25:55 +0000 | [diff] [blame] | 107 | drm_mode_connector_update_edid_property(connector, NULL); |
Adam Jackson | 620f378 | 2009-09-08 11:51:46 +1000 | [diff] [blame] | 108 | goto prune; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Jesse Barnes | 40a518d | 2009-01-12 12:05:32 -0800 | [diff] [blame] | 111 | count = (*connector_funcs->get_modes)(connector); |
ykzhao | 50fe4cf | 2009-09-03 14:30:04 +0800 | [diff] [blame] | 112 | if (!count) { |
Adam Jackson | 9632b41 | 2009-11-23 14:23:07 -0500 | [diff] [blame] | 113 | count = drm_add_modes_noedid(connector, 1024, 768); |
ykzhao | 50fe4cf | 2009-09-03 14:30:04 +0800 | [diff] [blame] | 114 | if (!count) |
| 115 | return 0; |
| 116 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 117 | |
Jesse Barnes | 40a518d | 2009-01-12 12:05:32 -0800 | [diff] [blame] | 118 | drm_mode_connector_list_update(connector); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 119 | |
| 120 | if (maxX && maxY) |
| 121 | drm_mode_validate_size(dev, &connector->modes, maxX, |
| 122 | maxY, 0); |
yakui_zhao | 6714977 | 2009-04-02 11:52:12 +0800 | [diff] [blame] | 123 | |
| 124 | if (connector->interlace_allowed) |
| 125 | mode_flags |= DRM_MODE_FLAG_INTERLACE; |
| 126 | if (connector->doublescan_allowed) |
| 127 | mode_flags |= DRM_MODE_FLAG_DBLSCAN; |
| 128 | drm_mode_validate_flag(connector, mode_flags); |
| 129 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 130 | list_for_each_entry_safe(mode, t, &connector->modes, head) { |
| 131 | if (mode->status == MODE_OK) |
| 132 | mode->status = connector_funcs->mode_valid(connector, |
| 133 | mode); |
| 134 | } |
| 135 | |
Adam Jackson | 620f378 | 2009-09-08 11:51:46 +1000 | [diff] [blame] | 136 | prune: |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 137 | drm_mode_prune_invalid(dev, &connector->modes, true); |
| 138 | |
Jesse Barnes | 40a518d | 2009-01-12 12:05:32 -0800 | [diff] [blame] | 139 | if (list_empty(&connector->modes)) |
| 140 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 141 | |
| 142 | drm_mode_sort(&connector->modes); |
| 143 | |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 144 | DRM_DEBUG_KMS("Probed modes for %s\n", |
| 145 | drm_get_connector_name(connector)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 146 | list_for_each_entry_safe(mode, t, &connector->modes, head) { |
| 147 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 148 | |
| 149 | drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); |
| 150 | drm_mode_debug_printmodeline(mode); |
| 151 | } |
Jesse Barnes | 40a518d | 2009-01-12 12:05:32 -0800 | [diff] [blame] | 152 | |
| 153 | return count; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 154 | } |
| 155 | EXPORT_SYMBOL(drm_helper_probe_single_connector_modes); |
| 156 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 157 | /** |
Keith Packard | c9fb15f | 2009-05-30 20:42:28 -0700 | [diff] [blame] | 158 | * drm_helper_encoder_in_use - check if a given encoder is in use |
| 159 | * @encoder: encoder to check |
| 160 | * |
| 161 | * LOCKING: |
| 162 | * Caller must hold mode config lock. |
| 163 | * |
| 164 | * Walk @encoders's DRM device's mode_config and see if it's in use. |
| 165 | * |
| 166 | * RETURNS: |
| 167 | * True if @encoder is part of the mode_config, false otherwise. |
| 168 | */ |
| 169 | bool drm_helper_encoder_in_use(struct drm_encoder *encoder) |
| 170 | { |
| 171 | struct drm_connector *connector; |
| 172 | struct drm_device *dev = encoder->dev; |
| 173 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
| 174 | if (connector->encoder == encoder) |
| 175 | return true; |
| 176 | return false; |
| 177 | } |
| 178 | EXPORT_SYMBOL(drm_helper_encoder_in_use); |
| 179 | |
| 180 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 181 | * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config |
| 182 | * @crtc: CRTC to check |
| 183 | * |
| 184 | * LOCKING: |
| 185 | * Caller must hold mode config lock. |
| 186 | * |
| 187 | * Walk @crtc's DRM device's mode_config and see if it's in use. |
| 188 | * |
| 189 | * RETURNS: |
| 190 | * True if @crtc is part of the mode_config, false otherwise. |
| 191 | */ |
| 192 | bool drm_helper_crtc_in_use(struct drm_crtc *crtc) |
| 193 | { |
| 194 | struct drm_encoder *encoder; |
| 195 | struct drm_device *dev = crtc->dev; |
| 196 | /* FIXME: Locking around list access? */ |
| 197 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
Keith Packard | c9fb15f | 2009-05-30 20:42:28 -0700 | [diff] [blame] | 198 | if (encoder->crtc == crtc && drm_helper_encoder_in_use(encoder)) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 199 | return true; |
| 200 | return false; |
| 201 | } |
| 202 | EXPORT_SYMBOL(drm_helper_crtc_in_use); |
| 203 | |
| 204 | /** |
David John | 89347bb | 2009-12-31 12:00:46 +0530 | [diff] [blame] | 205 | * drm_helper_disable_unused_functions - disable unused objects |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 206 | * @dev: DRM device |
| 207 | * |
| 208 | * LOCKING: |
| 209 | * Caller must hold mode config lock. |
| 210 | * |
| 211 | * If an connector or CRTC isn't part of @dev's mode_config, it can be disabled |
| 212 | * by calling its dpms function, which should power it off. |
| 213 | */ |
| 214 | void drm_helper_disable_unused_functions(struct drm_device *dev) |
| 215 | { |
| 216 | struct drm_encoder *encoder; |
Dave Airlie | a3a0544 | 2009-08-31 15:16:30 +1000 | [diff] [blame] | 217 | struct drm_connector *connector; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 218 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 219 | struct drm_crtc *crtc; |
| 220 | |
Dave Airlie | a3a0544 | 2009-08-31 15:16:30 +1000 | [diff] [blame] | 221 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 222 | if (!connector->encoder) |
| 223 | continue; |
| 224 | if (connector->status == connector_status_disconnected) |
| 225 | connector->encoder = NULL; |
| 226 | } |
| 227 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 228 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 229 | encoder_funcs = encoder->helper_private; |
Dave Airlie | a3a0544 | 2009-08-31 15:16:30 +1000 | [diff] [blame] | 230 | if (!drm_helper_encoder_in_use(encoder)) { |
| 231 | if (encoder_funcs->disable) |
| 232 | (*encoder_funcs->disable)(encoder); |
| 233 | else |
| 234 | (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF); |
Dave Airlie | 9c552dd | 2009-09-02 14:00:11 +1000 | [diff] [blame] | 235 | /* disconnector encoder from any connector */ |
| 236 | encoder->crtc = NULL; |
Dave Airlie | a3a0544 | 2009-08-31 15:16:30 +1000 | [diff] [blame] | 237 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 241 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 242 | crtc->enabled = drm_helper_crtc_in_use(crtc); |
| 243 | if (!crtc->enabled) { |
| 244 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF); |
| 245 | crtc->fb = NULL; |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | EXPORT_SYMBOL(drm_helper_disable_unused_functions); |
| 250 | |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 251 | /** |
| 252 | * drm_encoder_crtc_ok - can a given crtc drive a given encoder? |
| 253 | * @encoder: encoder to test |
| 254 | * @crtc: crtc to test |
| 255 | * |
| 256 | * Return false if @encoder can't be driven by @crtc, true otherwise. |
| 257 | */ |
| 258 | static bool drm_encoder_crtc_ok(struct drm_encoder *encoder, |
| 259 | struct drm_crtc *crtc) |
| 260 | { |
| 261 | struct drm_device *dev; |
| 262 | struct drm_crtc *tmp; |
| 263 | int crtc_mask = 1; |
| 264 | |
| 265 | WARN(!crtc, "checking null crtc?"); |
| 266 | |
| 267 | dev = crtc->dev; |
| 268 | |
| 269 | list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) { |
| 270 | if (tmp == crtc) |
| 271 | break; |
| 272 | crtc_mask <<= 1; |
| 273 | } |
| 274 | |
| 275 | if (encoder->possible_crtcs & crtc_mask) |
| 276 | return true; |
| 277 | return false; |
| 278 | } |
| 279 | |
| 280 | /* |
| 281 | * Check the CRTC we're going to map each output to vs. its current |
| 282 | * CRTC. If they don't match, we have to disable the output and the CRTC |
| 283 | * since the driver will have to re-route things. |
| 284 | */ |
| 285 | static void |
| 286 | drm_crtc_prepare_encoders(struct drm_device *dev) |
| 287 | { |
| 288 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 289 | struct drm_encoder *encoder; |
| 290 | |
| 291 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 292 | encoder_funcs = encoder->helper_private; |
| 293 | /* Disable unused encoders */ |
| 294 | if (encoder->crtc == NULL) |
| 295 | (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF); |
| 296 | /* Disable encoders whose CRTC is about to change */ |
| 297 | if (encoder_funcs->get_crtc && |
| 298 | encoder->crtc != (*encoder_funcs->get_crtc)(encoder)) |
| 299 | (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF); |
| 300 | } |
| 301 | } |
| 302 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 303 | /** |
| 304 | * drm_crtc_set_mode - set a mode |
| 305 | * @crtc: CRTC to program |
| 306 | * @mode: mode to use |
| 307 | * @x: width of mode |
| 308 | * @y: height of mode |
| 309 | * |
| 310 | * LOCKING: |
| 311 | * Caller must hold mode config lock. |
| 312 | * |
| 313 | * Try to set @mode on @crtc. Give @crtc and its associated connectors a chance |
| 314 | * to fixup or reject the mode prior to trying to set it. |
| 315 | * |
| 316 | * RETURNS: |
| 317 | * True if the mode was set successfully, or false otherwise. |
| 318 | */ |
| 319 | bool drm_crtc_helper_set_mode(struct drm_crtc *crtc, |
| 320 | struct drm_display_mode *mode, |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 321 | int x, int y, |
| 322 | struct drm_framebuffer *old_fb) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 323 | { |
| 324 | struct drm_device *dev = crtc->dev; |
| 325 | struct drm_display_mode *adjusted_mode, saved_mode; |
| 326 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 327 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 328 | int saved_x, saved_y; |
| 329 | struct drm_encoder *encoder; |
| 330 | bool ret = true; |
| 331 | |
| 332 | adjusted_mode = drm_mode_duplicate(dev, mode); |
| 333 | |
| 334 | crtc->enabled = drm_helper_crtc_in_use(crtc); |
| 335 | |
| 336 | if (!crtc->enabled) |
| 337 | return true; |
| 338 | |
| 339 | saved_mode = crtc->mode; |
| 340 | saved_x = crtc->x; |
| 341 | saved_y = crtc->y; |
| 342 | |
| 343 | /* Update crtc values up front so the driver can rely on them for mode |
| 344 | * setting. |
| 345 | */ |
| 346 | crtc->mode = *mode; |
| 347 | crtc->x = x; |
| 348 | crtc->y = y; |
| 349 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 350 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 351 | * adjust it according to limitations or connector properties, and also |
| 352 | * a chance to reject the mode entirely. |
| 353 | */ |
| 354 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 355 | |
| 356 | if (encoder->crtc != crtc) |
| 357 | continue; |
| 358 | encoder_funcs = encoder->helper_private; |
| 359 | if (!(ret = encoder_funcs->mode_fixup(encoder, mode, |
| 360 | adjusted_mode))) { |
| 361 | goto done; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | if (!(ret = crtc_funcs->mode_fixup(crtc, mode, adjusted_mode))) { |
| 366 | goto done; |
| 367 | } |
| 368 | |
| 369 | /* Prepare the encoders and CRTCs before setting the mode. */ |
| 370 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 371 | |
| 372 | if (encoder->crtc != crtc) |
| 373 | continue; |
| 374 | encoder_funcs = encoder->helper_private; |
| 375 | /* Disable the encoders as the first thing we do. */ |
| 376 | encoder_funcs->prepare(encoder); |
| 377 | } |
| 378 | |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 379 | drm_crtc_prepare_encoders(dev); |
| 380 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 381 | crtc_funcs->prepare(crtc); |
| 382 | |
| 383 | /* Set up the DPLL and any encoders state that needs to adjust or depend |
| 384 | * on the DPLL. |
| 385 | */ |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 386 | ret = !crtc_funcs->mode_set(crtc, mode, adjusted_mode, x, y, old_fb); |
| 387 | if (!ret) |
| 388 | goto done; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 389 | |
| 390 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 391 | |
| 392 | if (encoder->crtc != crtc) |
| 393 | continue; |
| 394 | |
Dave Young | ef14587 | 2010-01-13 13:38:59 +0800 | [diff] [blame] | 395 | DRM_DEBUG("%s: set mode %s %x\n", drm_get_encoder_name(encoder), |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 396 | mode->name, mode->base.id); |
| 397 | encoder_funcs = encoder->helper_private; |
| 398 | encoder_funcs->mode_set(encoder, mode, adjusted_mode); |
| 399 | } |
| 400 | |
| 401 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
| 402 | crtc_funcs->commit(crtc); |
| 403 | |
| 404 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 405 | |
| 406 | if (encoder->crtc != crtc) |
| 407 | continue; |
| 408 | |
| 409 | encoder_funcs = encoder->helper_private; |
| 410 | encoder_funcs->commit(encoder); |
| 411 | |
| 412 | } |
| 413 | |
| 414 | /* XXX free adjustedmode */ |
| 415 | drm_mode_destroy(dev, adjusted_mode); |
| 416 | /* FIXME: add subpixel order */ |
| 417 | done: |
| 418 | if (!ret) { |
| 419 | crtc->mode = saved_mode; |
| 420 | crtc->x = saved_x; |
| 421 | crtc->y = saved_y; |
| 422 | } |
| 423 | |
| 424 | return ret; |
| 425 | } |
| 426 | EXPORT_SYMBOL(drm_crtc_helper_set_mode); |
| 427 | |
| 428 | |
| 429 | /** |
| 430 | * drm_crtc_helper_set_config - set a new config from userspace |
| 431 | * @crtc: CRTC to setup |
| 432 | * @crtc_info: user provided configuration |
| 433 | * @new_mode: new mode to set |
| 434 | * @connector_set: set of connectors for the new config |
| 435 | * @fb: new framebuffer |
| 436 | * |
| 437 | * LOCKING: |
| 438 | * Caller must hold mode config lock. |
| 439 | * |
| 440 | * Setup a new configuration, provided by the user in @crtc_info, and enable |
| 441 | * it. |
| 442 | * |
| 443 | * RETURNS: |
| 444 | * Zero. (FIXME) |
| 445 | */ |
| 446 | int drm_crtc_helper_set_config(struct drm_mode_set *set) |
| 447 | { |
| 448 | struct drm_device *dev; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 449 | struct drm_crtc *save_crtcs, *new_crtc, *crtc; |
| 450 | struct drm_encoder *save_encoders, *new_encoder, *encoder; |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 451 | struct drm_framebuffer *old_fb = NULL; |
Jakob Bornecrantz | 4cb72b1 | 2009-08-03 13:43:59 +0100 | [diff] [blame] | 452 | bool mode_changed = false; /* if true do a full mode set */ |
| 453 | bool fb_changed = false; /* if true and !mode_changed just do a flip */ |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 454 | struct drm_connector *save_connectors, *connector; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 455 | int count = 0, ro, fail = 0; |
| 456 | struct drm_crtc_helper_funcs *crtc_funcs; |
| 457 | int ret = 0; |
| 458 | |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 459 | DRM_DEBUG_KMS("\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 460 | |
| 461 | if (!set) |
| 462 | return -EINVAL; |
| 463 | |
| 464 | if (!set->crtc) |
| 465 | return -EINVAL; |
| 466 | |
| 467 | if (!set->crtc->helper_private) |
| 468 | return -EINVAL; |
| 469 | |
| 470 | crtc_funcs = set->crtc->helper_private; |
| 471 | |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 472 | DRM_DEBUG_KMS("crtc: %p %d fb: %p connectors: %p num_connectors:" |
| 473 | " %d (x, y) (%i, %i)\n", |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 474 | set->crtc, set->crtc->base.id, set->fb, set->connectors, |
| 475 | (int)set->num_connectors, set->x, set->y); |
| 476 | |
| 477 | dev = set->crtc->dev; |
| 478 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 479 | /* Allocate space for the backup of all (non-pointer) crtc, encoder and |
| 480 | * connector data. */ |
| 481 | save_crtcs = kzalloc(dev->mode_config.num_crtc * |
| 482 | sizeof(struct drm_crtc), GFP_KERNEL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 483 | if (!save_crtcs) |
| 484 | return -ENOMEM; |
| 485 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 486 | save_encoders = kzalloc(dev->mode_config.num_encoder * |
| 487 | sizeof(struct drm_encoder), GFP_KERNEL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 488 | if (!save_encoders) { |
| 489 | kfree(save_crtcs); |
| 490 | return -ENOMEM; |
| 491 | } |
| 492 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 493 | save_connectors = kzalloc(dev->mode_config.num_connector * |
| 494 | sizeof(struct drm_connector), GFP_KERNEL); |
| 495 | if (!save_connectors) { |
| 496 | kfree(save_crtcs); |
| 497 | kfree(save_encoders); |
| 498 | return -ENOMEM; |
| 499 | } |
| 500 | |
| 501 | /* Copy data. Note that driver private data is not affected. |
| 502 | * Should anything bad happen only the expected state is |
| 503 | * restored, not the drivers personal bookkeeping. |
| 504 | */ |
| 505 | count = 0; |
| 506 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 507 | save_crtcs[count++] = *crtc; |
| 508 | } |
| 509 | |
| 510 | count = 0; |
| 511 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 512 | save_encoders[count++] = *encoder; |
| 513 | } |
| 514 | |
| 515 | count = 0; |
| 516 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 517 | save_connectors[count++] = *connector; |
| 518 | } |
| 519 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 520 | /* We should be able to check here if the fb has the same properties |
| 521 | * and then just flip_or_move it */ |
| 522 | if (set->crtc->fb != set->fb) { |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 523 | /* If we have no fb then treat it as a full mode set */ |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 524 | if (set->crtc->fb == NULL) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 525 | DRM_DEBUG_KMS("crtc has no fb, full mode set\n"); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 526 | mode_changed = true; |
Jakob Bornecrantz | 4cb72b1 | 2009-08-03 13:43:59 +0100 | [diff] [blame] | 527 | } else if (set->fb == NULL) { |
| 528 | mode_changed = true; |
Dave Airlie | 8dff474 | 2010-02-11 14:28:58 +1000 | [diff] [blame] | 529 | } else |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 530 | fb_changed = true; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | if (set->x != set->crtc->x || set->y != set->crtc->y) |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 534 | fb_changed = true; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 535 | |
| 536 | if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 537 | DRM_DEBUG_KMS("modes are different, full mode set\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 538 | drm_mode_debug_printmodeline(&set->crtc->mode); |
| 539 | drm_mode_debug_printmodeline(set->mode); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 540 | mode_changed = true; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | /* a) traverse passed in connector list and get encoders for them */ |
| 544 | count = 0; |
| 545 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 546 | struct drm_connector_helper_funcs *connector_funcs = |
| 547 | connector->helper_private; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 548 | new_encoder = connector->encoder; |
| 549 | for (ro = 0; ro < set->num_connectors; ro++) { |
| 550 | if (set->connectors[ro] == connector) { |
| 551 | new_encoder = connector_funcs->best_encoder(connector); |
| 552 | /* if we can't get an encoder for a connector |
| 553 | we are setting now - then fail */ |
| 554 | if (new_encoder == NULL) |
| 555 | /* don't break so fail path works correct */ |
| 556 | fail = 1; |
| 557 | break; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | if (new_encoder != connector->encoder) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 562 | DRM_DEBUG_KMS("encoder changed, full mode switch\n"); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 563 | mode_changed = true; |
Maarten Maathuis | ff846ab | 2009-08-19 00:56:45 +0200 | [diff] [blame] | 564 | /* If the encoder is reused for another connector, then |
| 565 | * the appropriate crtc will be set later. |
| 566 | */ |
Maarten Maathuis | ff6fdbe | 2009-09-01 03:39:04 +0200 | [diff] [blame] | 567 | if (connector->encoder) |
| 568 | connector->encoder->crtc = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 569 | connector->encoder = new_encoder; |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | if (fail) { |
| 574 | ret = -EINVAL; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 575 | goto fail; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | count = 0; |
| 579 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 580 | if (!connector->encoder) |
| 581 | continue; |
| 582 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 583 | if (connector->encoder->crtc == set->crtc) |
| 584 | new_crtc = NULL; |
| 585 | else |
| 586 | new_crtc = connector->encoder->crtc; |
| 587 | |
| 588 | for (ro = 0; ro < set->num_connectors; ro++) { |
| 589 | if (set->connectors[ro] == connector) |
| 590 | new_crtc = set->crtc; |
| 591 | } |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 592 | |
| 593 | /* Make sure the new CRTC will work with the encoder */ |
| 594 | if (new_crtc && |
| 595 | !drm_encoder_crtc_ok(connector->encoder, new_crtc)) { |
| 596 | ret = -EINVAL; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 597 | goto fail; |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 598 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 599 | if (new_crtc != connector->encoder->crtc) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 600 | DRM_DEBUG_KMS("crtc changed, full mode switch\n"); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 601 | mode_changed = true; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 602 | connector->encoder->crtc = new_crtc; |
| 603 | } |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 604 | DRM_DEBUG_KMS("setting connector %d crtc to %p\n", |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 605 | connector->base.id, new_crtc); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | /* mode_set_base is not a required function */ |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 609 | if (fb_changed && !crtc_funcs->mode_set_base) |
| 610 | mode_changed = true; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 611 | |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 612 | if (mode_changed) { |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 613 | old_fb = set->crtc->fb; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 614 | set->crtc->fb = set->fb; |
| 615 | set->crtc->enabled = (set->mode != NULL); |
| 616 | if (set->mode != NULL) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 617 | DRM_DEBUG_KMS("attempting to set mode from" |
| 618 | " userspace\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 619 | drm_mode_debug_printmodeline(set->mode); |
| 620 | if (!drm_crtc_helper_set_mode(set->crtc, set->mode, |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 621 | set->x, set->y, |
| 622 | old_fb)) { |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 623 | DRM_ERROR("failed to set mode on crtc %p\n", |
| 624 | set->crtc); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 625 | ret = -EINVAL; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 626 | goto fail; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 627 | } |
| 628 | /* TODO are these needed? */ |
| 629 | set->crtc->desired_x = set->x; |
| 630 | set->crtc->desired_y = set->y; |
| 631 | set->crtc->desired_mode = set->mode; |
| 632 | } |
| 633 | drm_helper_disable_unused_functions(dev); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 634 | } else if (fb_changed) { |
Ben Skeggs | 9b1596a | 2009-09-18 10:43:52 +1000 | [diff] [blame] | 635 | set->crtc->x = set->x; |
| 636 | set->crtc->y = set->y; |
| 637 | |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 638 | old_fb = set->crtc->fb; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 639 | if (set->crtc->fb != set->fb) |
| 640 | set->crtc->fb = set->fb; |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 641 | ret = crtc_funcs->mode_set_base(set->crtc, |
| 642 | set->x, set->y, old_fb); |
| 643 | if (ret != 0) |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 644 | goto fail; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 645 | } |
| 646 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 647 | kfree(save_connectors); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 648 | kfree(save_encoders); |
| 649 | kfree(save_crtcs); |
| 650 | return 0; |
| 651 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 652 | fail: |
| 653 | /* Restore all previous data. */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 654 | count = 0; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 655 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 656 | *crtc = save_crtcs[count++]; |
| 657 | } |
Chris Wilson | e62fb64 | 2009-02-11 16:39:21 +0000 | [diff] [blame] | 658 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 659 | count = 0; |
| 660 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 661 | *encoder = save_encoders[count++]; |
Chris Wilson | e62fb64 | 2009-02-11 16:39:21 +0000 | [diff] [blame] | 662 | } |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 663 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 664 | count = 0; |
| 665 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 666 | *connector = save_connectors[count++]; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 667 | } |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 668 | |
| 669 | kfree(save_connectors); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 670 | kfree(save_encoders); |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 671 | kfree(save_crtcs); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 672 | return ret; |
| 673 | } |
| 674 | EXPORT_SYMBOL(drm_crtc_helper_set_config); |
| 675 | |
Keith Packard | c9fb15f | 2009-05-30 20:42:28 -0700 | [diff] [blame] | 676 | static int drm_helper_choose_encoder_dpms(struct drm_encoder *encoder) |
| 677 | { |
| 678 | int dpms = DRM_MODE_DPMS_OFF; |
| 679 | struct drm_connector *connector; |
| 680 | struct drm_device *dev = encoder->dev; |
| 681 | |
| 682 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
| 683 | if (connector->encoder == encoder) |
| 684 | if (connector->dpms < dpms) |
| 685 | dpms = connector->dpms; |
| 686 | return dpms; |
| 687 | } |
| 688 | |
| 689 | static int drm_helper_choose_crtc_dpms(struct drm_crtc *crtc) |
| 690 | { |
| 691 | int dpms = DRM_MODE_DPMS_OFF; |
| 692 | struct drm_connector *connector; |
| 693 | struct drm_device *dev = crtc->dev; |
| 694 | |
| 695 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
| 696 | if (connector->encoder && connector->encoder->crtc == crtc) |
| 697 | if (connector->dpms < dpms) |
| 698 | dpms = connector->dpms; |
| 699 | return dpms; |
| 700 | } |
| 701 | |
| 702 | /** |
| 703 | * drm_helper_connector_dpms |
| 704 | * @connector affected connector |
| 705 | * @mode DPMS mode |
| 706 | * |
| 707 | * Calls the low-level connector DPMS function, then |
| 708 | * calls appropriate encoder and crtc DPMS functions as well |
| 709 | */ |
| 710 | void drm_helper_connector_dpms(struct drm_connector *connector, int mode) |
| 711 | { |
| 712 | struct drm_encoder *encoder = connector->encoder; |
| 713 | struct drm_crtc *crtc = encoder ? encoder->crtc : NULL; |
| 714 | int old_dpms; |
| 715 | |
| 716 | if (mode == connector->dpms) |
| 717 | return; |
| 718 | |
| 719 | old_dpms = connector->dpms; |
| 720 | connector->dpms = mode; |
| 721 | |
| 722 | /* from off to on, do crtc then encoder */ |
| 723 | if (mode < old_dpms) { |
| 724 | if (crtc) { |
| 725 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 726 | if (crtc_funcs->dpms) |
| 727 | (*crtc_funcs->dpms) (crtc, |
| 728 | drm_helper_choose_crtc_dpms(crtc)); |
| 729 | } |
| 730 | if (encoder) { |
| 731 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; |
| 732 | if (encoder_funcs->dpms) |
| 733 | (*encoder_funcs->dpms) (encoder, |
| 734 | drm_helper_choose_encoder_dpms(encoder)); |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | /* from on to off, do encoder then crtc */ |
| 739 | if (mode > old_dpms) { |
| 740 | if (encoder) { |
| 741 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; |
| 742 | if (encoder_funcs->dpms) |
| 743 | (*encoder_funcs->dpms) (encoder, |
| 744 | drm_helper_choose_encoder_dpms(encoder)); |
| 745 | } |
| 746 | if (crtc) { |
| 747 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 748 | if (crtc_funcs->dpms) |
| 749 | (*crtc_funcs->dpms) (crtc, |
| 750 | drm_helper_choose_crtc_dpms(crtc)); |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | return; |
| 755 | } |
| 756 | EXPORT_SYMBOL(drm_helper_connector_dpms); |
| 757 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 758 | int drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb, |
| 759 | struct drm_mode_fb_cmd *mode_cmd) |
| 760 | { |
| 761 | fb->width = mode_cmd->width; |
| 762 | fb->height = mode_cmd->height; |
| 763 | fb->pitch = mode_cmd->pitch; |
| 764 | fb->bits_per_pixel = mode_cmd->bpp; |
| 765 | fb->depth = mode_cmd->depth; |
| 766 | |
| 767 | return 0; |
| 768 | } |
| 769 | EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct); |
| 770 | |
| 771 | int drm_helper_resume_force_mode(struct drm_device *dev) |
| 772 | { |
| 773 | struct drm_crtc *crtc; |
David John | 89347bb | 2009-12-31 12:00:46 +0530 | [diff] [blame] | 774 | struct drm_encoder *encoder; |
| 775 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 776 | struct drm_crtc_helper_funcs *crtc_funcs; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 777 | int ret; |
| 778 | |
| 779 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 780 | |
| 781 | if (!crtc->enabled) |
| 782 | continue; |
| 783 | |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 784 | ret = drm_crtc_helper_set_mode(crtc, &crtc->mode, |
| 785 | crtc->x, crtc->y, crtc->fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 786 | |
| 787 | if (ret == false) |
| 788 | DRM_ERROR("failed to set mode on crtc %p\n", crtc); |
David John | 89347bb | 2009-12-31 12:00:46 +0530 | [diff] [blame] | 789 | |
| 790 | /* Turn off outputs that were already powered off */ |
| 791 | if (drm_helper_choose_crtc_dpms(crtc)) { |
| 792 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 793 | |
| 794 | if(encoder->crtc != crtc) |
| 795 | continue; |
| 796 | |
| 797 | encoder_funcs = encoder->helper_private; |
| 798 | if (encoder_funcs->dpms) |
| 799 | (*encoder_funcs->dpms) (encoder, |
| 800 | drm_helper_choose_encoder_dpms(encoder)); |
| 801 | |
| 802 | crtc_funcs = crtc->helper_private; |
| 803 | if (crtc_funcs->dpms) |
| 804 | (*crtc_funcs->dpms) (crtc, |
| 805 | drm_helper_choose_crtc_dpms(crtc)); |
| 806 | } |
| 807 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 808 | } |
Zhao Yakui | af4fcb5 | 2009-07-08 14:13:13 +0800 | [diff] [blame] | 809 | /* disable the unused connectors while restoring the modesetting */ |
| 810 | drm_helper_disable_unused_functions(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 811 | return 0; |
| 812 | } |
| 813 | EXPORT_SYMBOL(drm_helper_resume_force_mode); |