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) { |
Alex Deucher | 5c8d717 | 2010-06-11 17:04:35 -0400 | [diff] [blame] | 244 | if (crtc_funcs->disable) |
| 245 | (*crtc_funcs->disable)(crtc); |
| 246 | else |
| 247 | (*crtc_funcs->dpms)(crtc, DRM_MODE_DPMS_OFF); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 248 | crtc->fb = NULL; |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | EXPORT_SYMBOL(drm_helper_disable_unused_functions); |
| 253 | |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 254 | /** |
| 255 | * drm_encoder_crtc_ok - can a given crtc drive a given encoder? |
| 256 | * @encoder: encoder to test |
| 257 | * @crtc: crtc to test |
| 258 | * |
| 259 | * Return false if @encoder can't be driven by @crtc, true otherwise. |
| 260 | */ |
| 261 | static bool drm_encoder_crtc_ok(struct drm_encoder *encoder, |
| 262 | struct drm_crtc *crtc) |
| 263 | { |
| 264 | struct drm_device *dev; |
| 265 | struct drm_crtc *tmp; |
| 266 | int crtc_mask = 1; |
| 267 | |
| 268 | WARN(!crtc, "checking null crtc?"); |
| 269 | |
| 270 | dev = crtc->dev; |
| 271 | |
| 272 | list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) { |
| 273 | if (tmp == crtc) |
| 274 | break; |
| 275 | crtc_mask <<= 1; |
| 276 | } |
| 277 | |
| 278 | if (encoder->possible_crtcs & crtc_mask) |
| 279 | return true; |
| 280 | return false; |
| 281 | } |
| 282 | |
| 283 | /* |
| 284 | * Check the CRTC we're going to map each output to vs. its current |
| 285 | * CRTC. If they don't match, we have to disable the output and the CRTC |
| 286 | * since the driver will have to re-route things. |
| 287 | */ |
| 288 | static void |
| 289 | drm_crtc_prepare_encoders(struct drm_device *dev) |
| 290 | { |
| 291 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 292 | struct drm_encoder *encoder; |
| 293 | |
| 294 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 295 | encoder_funcs = encoder->helper_private; |
| 296 | /* Disable unused encoders */ |
| 297 | if (encoder->crtc == NULL) |
| 298 | (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF); |
| 299 | /* Disable encoders whose CRTC is about to change */ |
| 300 | if (encoder_funcs->get_crtc && |
| 301 | encoder->crtc != (*encoder_funcs->get_crtc)(encoder)) |
| 302 | (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF); |
| 303 | } |
| 304 | } |
| 305 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 306 | /** |
| 307 | * drm_crtc_set_mode - set a mode |
| 308 | * @crtc: CRTC to program |
| 309 | * @mode: mode to use |
| 310 | * @x: width of mode |
| 311 | * @y: height of mode |
| 312 | * |
| 313 | * LOCKING: |
| 314 | * Caller must hold mode config lock. |
| 315 | * |
| 316 | * Try to set @mode on @crtc. Give @crtc and its associated connectors a chance |
| 317 | * to fixup or reject the mode prior to trying to set it. |
| 318 | * |
| 319 | * RETURNS: |
| 320 | * True if the mode was set successfully, or false otherwise. |
| 321 | */ |
| 322 | bool drm_crtc_helper_set_mode(struct drm_crtc *crtc, |
| 323 | struct drm_display_mode *mode, |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 324 | int x, int y, |
| 325 | struct drm_framebuffer *old_fb) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 326 | { |
| 327 | struct drm_device *dev = crtc->dev; |
| 328 | struct drm_display_mode *adjusted_mode, saved_mode; |
| 329 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 330 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 331 | int saved_x, saved_y; |
| 332 | struct drm_encoder *encoder; |
| 333 | bool ret = true; |
| 334 | |
| 335 | adjusted_mode = drm_mode_duplicate(dev, mode); |
| 336 | |
| 337 | crtc->enabled = drm_helper_crtc_in_use(crtc); |
| 338 | |
| 339 | if (!crtc->enabled) |
| 340 | return true; |
| 341 | |
| 342 | saved_mode = crtc->mode; |
| 343 | saved_x = crtc->x; |
| 344 | saved_y = crtc->y; |
| 345 | |
| 346 | /* Update crtc values up front so the driver can rely on them for mode |
| 347 | * setting. |
| 348 | */ |
| 349 | crtc->mode = *mode; |
| 350 | crtc->x = x; |
| 351 | crtc->y = y; |
| 352 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 353 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 354 | * adjust it according to limitations or connector properties, and also |
| 355 | * a chance to reject the mode entirely. |
| 356 | */ |
| 357 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 358 | |
| 359 | if (encoder->crtc != crtc) |
| 360 | continue; |
| 361 | encoder_funcs = encoder->helper_private; |
| 362 | if (!(ret = encoder_funcs->mode_fixup(encoder, mode, |
| 363 | adjusted_mode))) { |
| 364 | goto done; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | if (!(ret = crtc_funcs->mode_fixup(crtc, mode, adjusted_mode))) { |
| 369 | goto done; |
| 370 | } |
| 371 | |
| 372 | /* Prepare the encoders and CRTCs before setting the mode. */ |
| 373 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 374 | |
| 375 | if (encoder->crtc != crtc) |
| 376 | continue; |
| 377 | encoder_funcs = encoder->helper_private; |
| 378 | /* Disable the encoders as the first thing we do. */ |
| 379 | encoder_funcs->prepare(encoder); |
| 380 | } |
| 381 | |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 382 | drm_crtc_prepare_encoders(dev); |
| 383 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 384 | crtc_funcs->prepare(crtc); |
| 385 | |
| 386 | /* Set up the DPLL and any encoders state that needs to adjust or depend |
| 387 | * on the DPLL. |
| 388 | */ |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 389 | ret = !crtc_funcs->mode_set(crtc, mode, adjusted_mode, x, y, old_fb); |
| 390 | if (!ret) |
| 391 | goto done; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 392 | |
| 393 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 394 | |
| 395 | if (encoder->crtc != crtc) |
| 396 | continue; |
| 397 | |
Dave Young | ef14587 | 2010-01-13 13:38:59 +0800 | [diff] [blame] | 398 | 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] | 399 | mode->name, mode->base.id); |
| 400 | encoder_funcs = encoder->helper_private; |
| 401 | encoder_funcs->mode_set(encoder, mode, adjusted_mode); |
| 402 | } |
| 403 | |
| 404 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
| 405 | crtc_funcs->commit(crtc); |
| 406 | |
| 407 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 408 | |
| 409 | if (encoder->crtc != crtc) |
| 410 | continue; |
| 411 | |
| 412 | encoder_funcs = encoder->helper_private; |
| 413 | encoder_funcs->commit(encoder); |
| 414 | |
| 415 | } |
| 416 | |
| 417 | /* XXX free adjustedmode */ |
| 418 | drm_mode_destroy(dev, adjusted_mode); |
| 419 | /* FIXME: add subpixel order */ |
| 420 | done: |
| 421 | if (!ret) { |
| 422 | crtc->mode = saved_mode; |
| 423 | crtc->x = saved_x; |
| 424 | crtc->y = saved_y; |
| 425 | } |
| 426 | |
| 427 | return ret; |
| 428 | } |
| 429 | EXPORT_SYMBOL(drm_crtc_helper_set_mode); |
| 430 | |
| 431 | |
| 432 | /** |
| 433 | * drm_crtc_helper_set_config - set a new config from userspace |
| 434 | * @crtc: CRTC to setup |
| 435 | * @crtc_info: user provided configuration |
| 436 | * @new_mode: new mode to set |
| 437 | * @connector_set: set of connectors for the new config |
| 438 | * @fb: new framebuffer |
| 439 | * |
| 440 | * LOCKING: |
| 441 | * Caller must hold mode config lock. |
| 442 | * |
| 443 | * Setup a new configuration, provided by the user in @crtc_info, and enable |
| 444 | * it. |
| 445 | * |
| 446 | * RETURNS: |
| 447 | * Zero. (FIXME) |
| 448 | */ |
| 449 | int drm_crtc_helper_set_config(struct drm_mode_set *set) |
| 450 | { |
| 451 | struct drm_device *dev; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 452 | struct drm_crtc *save_crtcs, *new_crtc, *crtc; |
| 453 | struct drm_encoder *save_encoders, *new_encoder, *encoder; |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 454 | struct drm_framebuffer *old_fb = NULL; |
Jakob Bornecrantz | 4cb72b1 | 2009-08-03 13:43:59 +0100 | [diff] [blame] | 455 | bool mode_changed = false; /* if true do a full mode set */ |
| 456 | 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] | 457 | struct drm_connector *save_connectors, *connector; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 458 | int count = 0, ro, fail = 0; |
| 459 | struct drm_crtc_helper_funcs *crtc_funcs; |
| 460 | int ret = 0; |
| 461 | |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 462 | DRM_DEBUG_KMS("\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 463 | |
| 464 | if (!set) |
| 465 | return -EINVAL; |
| 466 | |
| 467 | if (!set->crtc) |
| 468 | return -EINVAL; |
| 469 | |
| 470 | if (!set->crtc->helper_private) |
| 471 | return -EINVAL; |
| 472 | |
| 473 | crtc_funcs = set->crtc->helper_private; |
| 474 | |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 475 | DRM_DEBUG_KMS("crtc: %p %d fb: %p connectors: %p num_connectors:" |
| 476 | " %d (x, y) (%i, %i)\n", |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 477 | set->crtc, set->crtc->base.id, set->fb, set->connectors, |
| 478 | (int)set->num_connectors, set->x, set->y); |
| 479 | |
| 480 | dev = set->crtc->dev; |
| 481 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 482 | /* Allocate space for the backup of all (non-pointer) crtc, encoder and |
| 483 | * connector data. */ |
| 484 | save_crtcs = kzalloc(dev->mode_config.num_crtc * |
| 485 | sizeof(struct drm_crtc), GFP_KERNEL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 486 | if (!save_crtcs) |
| 487 | return -ENOMEM; |
| 488 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 489 | save_encoders = kzalloc(dev->mode_config.num_encoder * |
| 490 | sizeof(struct drm_encoder), GFP_KERNEL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 491 | if (!save_encoders) { |
| 492 | kfree(save_crtcs); |
| 493 | return -ENOMEM; |
| 494 | } |
| 495 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 496 | save_connectors = kzalloc(dev->mode_config.num_connector * |
| 497 | sizeof(struct drm_connector), GFP_KERNEL); |
| 498 | if (!save_connectors) { |
| 499 | kfree(save_crtcs); |
| 500 | kfree(save_encoders); |
| 501 | return -ENOMEM; |
| 502 | } |
| 503 | |
| 504 | /* Copy data. Note that driver private data is not affected. |
| 505 | * Should anything bad happen only the expected state is |
| 506 | * restored, not the drivers personal bookkeeping. |
| 507 | */ |
| 508 | count = 0; |
| 509 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 510 | save_crtcs[count++] = *crtc; |
| 511 | } |
| 512 | |
| 513 | count = 0; |
| 514 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 515 | save_encoders[count++] = *encoder; |
| 516 | } |
| 517 | |
| 518 | count = 0; |
| 519 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 520 | save_connectors[count++] = *connector; |
| 521 | } |
| 522 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 523 | /* We should be able to check here if the fb has the same properties |
| 524 | * and then just flip_or_move it */ |
| 525 | if (set->crtc->fb != set->fb) { |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 526 | /* 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] | 527 | if (set->crtc->fb == NULL) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 528 | DRM_DEBUG_KMS("crtc has no fb, full mode set\n"); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 529 | mode_changed = true; |
Jakob Bornecrantz | 4cb72b1 | 2009-08-03 13:43:59 +0100 | [diff] [blame] | 530 | } else if (set->fb == NULL) { |
| 531 | mode_changed = true; |
Dave Airlie | 8dff474 | 2010-02-11 14:28:58 +1000 | [diff] [blame] | 532 | } else |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 533 | fb_changed = true; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | if (set->x != set->crtc->x || set->y != set->crtc->y) |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 537 | fb_changed = true; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 538 | |
| 539 | if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 540 | DRM_DEBUG_KMS("modes are different, full mode set\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 541 | drm_mode_debug_printmodeline(&set->crtc->mode); |
| 542 | drm_mode_debug_printmodeline(set->mode); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 543 | mode_changed = true; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | /* a) traverse passed in connector list and get encoders for them */ |
| 547 | count = 0; |
| 548 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 549 | struct drm_connector_helper_funcs *connector_funcs = |
| 550 | connector->helper_private; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 551 | new_encoder = connector->encoder; |
| 552 | for (ro = 0; ro < set->num_connectors; ro++) { |
| 553 | if (set->connectors[ro] == connector) { |
| 554 | new_encoder = connector_funcs->best_encoder(connector); |
| 555 | /* if we can't get an encoder for a connector |
| 556 | we are setting now - then fail */ |
| 557 | if (new_encoder == NULL) |
| 558 | /* don't break so fail path works correct */ |
| 559 | fail = 1; |
| 560 | break; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | if (new_encoder != connector->encoder) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 565 | DRM_DEBUG_KMS("encoder changed, full mode switch\n"); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 566 | mode_changed = true; |
Maarten Maathuis | ff846ab | 2009-08-19 00:56:45 +0200 | [diff] [blame] | 567 | /* If the encoder is reused for another connector, then |
| 568 | * the appropriate crtc will be set later. |
| 569 | */ |
Maarten Maathuis | ff6fdbe | 2009-09-01 03:39:04 +0200 | [diff] [blame] | 570 | if (connector->encoder) |
| 571 | connector->encoder->crtc = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 572 | connector->encoder = new_encoder; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | if (fail) { |
| 577 | ret = -EINVAL; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 578 | goto fail; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | count = 0; |
| 582 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 583 | if (!connector->encoder) |
| 584 | continue; |
| 585 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 586 | if (connector->encoder->crtc == set->crtc) |
| 587 | new_crtc = NULL; |
| 588 | else |
| 589 | new_crtc = connector->encoder->crtc; |
| 590 | |
| 591 | for (ro = 0; ro < set->num_connectors; ro++) { |
| 592 | if (set->connectors[ro] == connector) |
| 593 | new_crtc = set->crtc; |
| 594 | } |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 595 | |
| 596 | /* Make sure the new CRTC will work with the encoder */ |
| 597 | if (new_crtc && |
| 598 | !drm_encoder_crtc_ok(connector->encoder, new_crtc)) { |
| 599 | ret = -EINVAL; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 600 | goto fail; |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 601 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 602 | if (new_crtc != connector->encoder->crtc) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 603 | DRM_DEBUG_KMS("crtc changed, full mode switch\n"); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 604 | mode_changed = true; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 605 | connector->encoder->crtc = new_crtc; |
| 606 | } |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 607 | DRM_DEBUG_KMS("setting connector %d crtc to %p\n", |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 608 | connector->base.id, new_crtc); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /* mode_set_base is not a required function */ |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 612 | if (fb_changed && !crtc_funcs->mode_set_base) |
| 613 | mode_changed = true; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 614 | |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 615 | if (mode_changed) { |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 616 | old_fb = set->crtc->fb; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 617 | set->crtc->fb = set->fb; |
| 618 | set->crtc->enabled = (set->mode != NULL); |
| 619 | if (set->mode != NULL) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 620 | DRM_DEBUG_KMS("attempting to set mode from" |
| 621 | " userspace\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 622 | drm_mode_debug_printmodeline(set->mode); |
| 623 | if (!drm_crtc_helper_set_mode(set->crtc, set->mode, |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 624 | set->x, set->y, |
| 625 | old_fb)) { |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 626 | DRM_ERROR("failed to set mode on crtc %p\n", |
| 627 | set->crtc); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 628 | ret = -EINVAL; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 629 | goto fail; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 630 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 631 | } |
| 632 | drm_helper_disable_unused_functions(dev); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 633 | } else if (fb_changed) { |
Ben Skeggs | 9b1596a | 2009-09-18 10:43:52 +1000 | [diff] [blame] | 634 | set->crtc->x = set->x; |
| 635 | set->crtc->y = set->y; |
| 636 | |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 637 | old_fb = set->crtc->fb; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 638 | if (set->crtc->fb != set->fb) |
| 639 | set->crtc->fb = set->fb; |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 640 | ret = crtc_funcs->mode_set_base(set->crtc, |
| 641 | set->x, set->y, old_fb); |
| 642 | if (ret != 0) |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 643 | goto fail; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 644 | } |
| 645 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 646 | kfree(save_connectors); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 647 | kfree(save_encoders); |
| 648 | kfree(save_crtcs); |
| 649 | return 0; |
| 650 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 651 | fail: |
| 652 | /* Restore all previous data. */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 653 | count = 0; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 654 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 655 | *crtc = save_crtcs[count++]; |
| 656 | } |
Chris Wilson | e62fb64 | 2009-02-11 16:39:21 +0000 | [diff] [blame] | 657 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 658 | count = 0; |
| 659 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 660 | *encoder = save_encoders[count++]; |
Chris Wilson | e62fb64 | 2009-02-11 16:39:21 +0000 | [diff] [blame] | 661 | } |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 662 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 663 | count = 0; |
| 664 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 665 | *connector = save_connectors[count++]; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 666 | } |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 667 | |
| 668 | kfree(save_connectors); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 669 | kfree(save_encoders); |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 670 | kfree(save_crtcs); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 671 | return ret; |
| 672 | } |
| 673 | EXPORT_SYMBOL(drm_crtc_helper_set_config); |
| 674 | |
Keith Packard | c9fb15f | 2009-05-30 20:42:28 -0700 | [diff] [blame] | 675 | static int drm_helper_choose_encoder_dpms(struct drm_encoder *encoder) |
| 676 | { |
| 677 | int dpms = DRM_MODE_DPMS_OFF; |
| 678 | struct drm_connector *connector; |
| 679 | struct drm_device *dev = encoder->dev; |
| 680 | |
| 681 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
| 682 | if (connector->encoder == encoder) |
| 683 | if (connector->dpms < dpms) |
| 684 | dpms = connector->dpms; |
| 685 | return dpms; |
| 686 | } |
| 687 | |
| 688 | static int drm_helper_choose_crtc_dpms(struct drm_crtc *crtc) |
| 689 | { |
| 690 | int dpms = DRM_MODE_DPMS_OFF; |
| 691 | struct drm_connector *connector; |
| 692 | struct drm_device *dev = crtc->dev; |
| 693 | |
| 694 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
| 695 | if (connector->encoder && connector->encoder->crtc == crtc) |
| 696 | if (connector->dpms < dpms) |
| 697 | dpms = connector->dpms; |
| 698 | return dpms; |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * drm_helper_connector_dpms |
| 703 | * @connector affected connector |
| 704 | * @mode DPMS mode |
| 705 | * |
| 706 | * Calls the low-level connector DPMS function, then |
| 707 | * calls appropriate encoder and crtc DPMS functions as well |
| 708 | */ |
| 709 | void drm_helper_connector_dpms(struct drm_connector *connector, int mode) |
| 710 | { |
| 711 | struct drm_encoder *encoder = connector->encoder; |
| 712 | struct drm_crtc *crtc = encoder ? encoder->crtc : NULL; |
| 713 | int old_dpms; |
| 714 | |
| 715 | if (mode == connector->dpms) |
| 716 | return; |
| 717 | |
| 718 | old_dpms = connector->dpms; |
| 719 | connector->dpms = mode; |
| 720 | |
| 721 | /* from off to on, do crtc then encoder */ |
| 722 | if (mode < old_dpms) { |
| 723 | if (crtc) { |
| 724 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 725 | if (crtc_funcs->dpms) |
| 726 | (*crtc_funcs->dpms) (crtc, |
| 727 | drm_helper_choose_crtc_dpms(crtc)); |
| 728 | } |
| 729 | if (encoder) { |
| 730 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; |
| 731 | if (encoder_funcs->dpms) |
| 732 | (*encoder_funcs->dpms) (encoder, |
| 733 | drm_helper_choose_encoder_dpms(encoder)); |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | /* from on to off, do encoder then crtc */ |
| 738 | if (mode > old_dpms) { |
| 739 | if (encoder) { |
| 740 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; |
| 741 | if (encoder_funcs->dpms) |
| 742 | (*encoder_funcs->dpms) (encoder, |
| 743 | drm_helper_choose_encoder_dpms(encoder)); |
| 744 | } |
| 745 | if (crtc) { |
| 746 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 747 | if (crtc_funcs->dpms) |
| 748 | (*crtc_funcs->dpms) (crtc, |
| 749 | drm_helper_choose_crtc_dpms(crtc)); |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | return; |
| 754 | } |
| 755 | EXPORT_SYMBOL(drm_helper_connector_dpms); |
| 756 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 757 | int drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb, |
| 758 | struct drm_mode_fb_cmd *mode_cmd) |
| 759 | { |
| 760 | fb->width = mode_cmd->width; |
| 761 | fb->height = mode_cmd->height; |
| 762 | fb->pitch = mode_cmd->pitch; |
| 763 | fb->bits_per_pixel = mode_cmd->bpp; |
| 764 | fb->depth = mode_cmd->depth; |
| 765 | |
| 766 | return 0; |
| 767 | } |
| 768 | EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct); |
| 769 | |
| 770 | int drm_helper_resume_force_mode(struct drm_device *dev) |
| 771 | { |
| 772 | struct drm_crtc *crtc; |
David John | 89347bb | 2009-12-31 12:00:46 +0530 | [diff] [blame] | 773 | struct drm_encoder *encoder; |
| 774 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 775 | struct drm_crtc_helper_funcs *crtc_funcs; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 776 | int ret; |
| 777 | |
| 778 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 779 | |
| 780 | if (!crtc->enabled) |
| 781 | continue; |
| 782 | |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 783 | ret = drm_crtc_helper_set_mode(crtc, &crtc->mode, |
| 784 | crtc->x, crtc->y, crtc->fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 785 | |
| 786 | if (ret == false) |
| 787 | DRM_ERROR("failed to set mode on crtc %p\n", crtc); |
David John | 89347bb | 2009-12-31 12:00:46 +0530 | [diff] [blame] | 788 | |
| 789 | /* Turn off outputs that were already powered off */ |
| 790 | if (drm_helper_choose_crtc_dpms(crtc)) { |
| 791 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 792 | |
| 793 | if(encoder->crtc != crtc) |
| 794 | continue; |
| 795 | |
| 796 | encoder_funcs = encoder->helper_private; |
| 797 | if (encoder_funcs->dpms) |
| 798 | (*encoder_funcs->dpms) (encoder, |
| 799 | drm_helper_choose_encoder_dpms(encoder)); |
| 800 | |
| 801 | crtc_funcs = crtc->helper_private; |
| 802 | if (crtc_funcs->dpms) |
| 803 | (*crtc_funcs->dpms) (crtc, |
| 804 | drm_helper_choose_crtc_dpms(crtc)); |
| 805 | } |
| 806 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 807 | } |
Zhao Yakui | af4fcb5 | 2009-07-08 14:13:13 +0800 | [diff] [blame] | 808 | /* disable the unused connectors while restoring the modesetting */ |
| 809 | drm_helper_disable_unused_functions(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 810 | return 0; |
| 811 | } |
| 812 | EXPORT_SYMBOL(drm_helper_resume_force_mode); |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 813 | |
| 814 | static struct slow_work_ops output_poll_ops; |
| 815 | |
| 816 | #define DRM_OUTPUT_POLL_PERIOD (10*HZ) |
| 817 | static void output_poll_execute(struct slow_work *work) |
| 818 | { |
| 819 | struct delayed_slow_work *delayed_work = container_of(work, struct delayed_slow_work, work); |
| 820 | struct drm_device *dev = container_of(delayed_work, struct drm_device, mode_config.output_poll_slow_work); |
| 821 | struct drm_connector *connector; |
| 822 | enum drm_connector_status old_status, status; |
| 823 | bool repoll = false, changed = false; |
| 824 | int ret; |
| 825 | |
| 826 | mutex_lock(&dev->mode_config.mutex); |
| 827 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 828 | |
| 829 | /* if this is HPD or polled don't check it - |
| 830 | TV out for instance */ |
| 831 | if (!connector->polled) |
| 832 | continue; |
| 833 | |
| 834 | else if (connector->polled & (DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT)) |
| 835 | repoll = true; |
| 836 | |
| 837 | old_status = connector->status; |
| 838 | /* if we are connected and don't want to poll for disconnect |
| 839 | skip it */ |
| 840 | if (old_status == connector_status_connected && |
| 841 | !(connector->polled & DRM_CONNECTOR_POLL_DISCONNECT) && |
| 842 | !(connector->polled & DRM_CONNECTOR_POLL_HPD)) |
| 843 | continue; |
| 844 | |
| 845 | status = connector->funcs->detect(connector); |
| 846 | if (old_status != status) |
| 847 | changed = true; |
| 848 | } |
| 849 | |
| 850 | mutex_unlock(&dev->mode_config.mutex); |
| 851 | |
| 852 | if (changed) { |
| 853 | /* send a uevent + call fbdev */ |
| 854 | drm_sysfs_hotplug_event(dev); |
| 855 | if (dev->mode_config.funcs->output_poll_changed) |
| 856 | dev->mode_config.funcs->output_poll_changed(dev); |
| 857 | } |
| 858 | |
| 859 | if (repoll) { |
| 860 | ret = delayed_slow_work_enqueue(delayed_work, DRM_OUTPUT_POLL_PERIOD); |
| 861 | if (ret) |
| 862 | DRM_ERROR("delayed enqueue failed %d\n", ret); |
| 863 | } |
| 864 | } |
| 865 | |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 866 | void drm_kms_helper_poll_disable(struct drm_device *dev) |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 867 | { |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 868 | if (!dev->mode_config.poll_enabled) |
| 869 | return; |
| 870 | delayed_slow_work_cancel(&dev->mode_config.output_poll_slow_work); |
| 871 | } |
| 872 | EXPORT_SYMBOL(drm_kms_helper_poll_disable); |
| 873 | |
| 874 | void drm_kms_helper_poll_enable(struct drm_device *dev) |
| 875 | { |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 876 | bool poll = false; |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 877 | struct drm_connector *connector; |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 878 | int ret; |
| 879 | |
| 880 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 881 | if (connector->polled) |
| 882 | poll = true; |
| 883 | } |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 884 | |
| 885 | if (poll) { |
| 886 | ret = delayed_slow_work_enqueue(&dev->mode_config.output_poll_slow_work, DRM_OUTPUT_POLL_PERIOD); |
| 887 | if (ret) |
| 888 | DRM_ERROR("delayed enqueue failed %d\n", ret); |
| 889 | } |
| 890 | } |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 891 | EXPORT_SYMBOL(drm_kms_helper_poll_enable); |
| 892 | |
| 893 | void drm_kms_helper_poll_init(struct drm_device *dev) |
| 894 | { |
| 895 | slow_work_register_user(THIS_MODULE); |
| 896 | delayed_slow_work_init(&dev->mode_config.output_poll_slow_work, |
| 897 | &output_poll_ops); |
| 898 | dev->mode_config.poll_enabled = true; |
| 899 | |
| 900 | drm_kms_helper_poll_enable(dev); |
| 901 | } |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 902 | EXPORT_SYMBOL(drm_kms_helper_poll_init); |
| 903 | |
| 904 | void drm_kms_helper_poll_fini(struct drm_device *dev) |
| 905 | { |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 906 | drm_kms_helper_poll_disable(dev); |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 907 | slow_work_unregister_user(THIS_MODULE); |
| 908 | } |
| 909 | EXPORT_SYMBOL(drm_kms_helper_poll_fini); |
| 910 | |
| 911 | void drm_helper_hpd_irq_event(struct drm_device *dev) |
| 912 | { |
| 913 | if (!dev->mode_config.poll_enabled) |
| 914 | return; |
| 915 | delayed_slow_work_cancel(&dev->mode_config.output_poll_slow_work); |
| 916 | /* schedule a slow work asap */ |
| 917 | delayed_slow_work_enqueue(&dev->mode_config.output_poll_slow_work, 0); |
| 918 | } |
| 919 | EXPORT_SYMBOL(drm_helper_hpd_irq_event); |
| 920 | |
| 921 | static struct slow_work_ops output_poll_ops = { |
| 922 | .execute = output_poll_execute, |
| 923 | }; |