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 | |
Paul Gortmaker | 2d1a8a4 | 2011-08-30 18:16:33 -0400 | [diff] [blame] | 32 | #include <linux/export.h> |
Paul Gortmaker | 0603ba1 | 2011-08-31 11:29:09 -0400 | [diff] [blame] | 33 | #include <linux/moduleparam.h> |
Paul Gortmaker | 2d1a8a4 | 2011-08-30 18:16:33 -0400 | [diff] [blame] | 34 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 35 | #include <drm/drmP.h> |
| 36 | #include <drm/drm_crtc.h> |
| 37 | #include <drm/drm_fourcc.h> |
| 38 | #include <drm/drm_crtc_helper.h> |
| 39 | #include <drm/drm_fb_helper.h> |
| 40 | #include <drm/drm_edid.h> |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 41 | |
Daniel Vetter | cfc1a06 | 2012-10-27 15:52:04 +0200 | [diff] [blame] | 42 | void drm_helper_move_panel_connectors_to_head(struct drm_device *dev) |
| 43 | { |
| 44 | struct drm_connector *connector, *tmp; |
| 45 | struct list_head panel_list; |
| 46 | |
| 47 | INIT_LIST_HEAD(&panel_list); |
| 48 | |
| 49 | list_for_each_entry_safe(connector, tmp, |
| 50 | &dev->mode_config.connector_list, head) { |
| 51 | if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS || |
| 52 | connector->connector_type == DRM_MODE_CONNECTOR_eDP) |
| 53 | list_move_tail(&connector->head, &panel_list); |
| 54 | } |
| 55 | |
| 56 | list_splice(&panel_list, &dev->mode_config.connector_list); |
| 57 | } |
| 58 | EXPORT_SYMBOL(drm_helper_move_panel_connectors_to_head); |
| 59 | |
Chris Wilson | e58f637 | 2010-08-20 09:13:36 +0100 | [diff] [blame] | 60 | static bool drm_kms_helper_poll = true; |
| 61 | module_param_named(poll, drm_kms_helper_poll, bool, 0600); |
| 62 | |
yakui_zhao | 6714977 | 2009-04-02 11:52:12 +0800 | [diff] [blame] | 63 | static void drm_mode_validate_flag(struct drm_connector *connector, |
| 64 | int flags) |
| 65 | { |
Sascha Hauer | a1178ca | 2012-02-01 11:38:30 +0100 | [diff] [blame] | 66 | struct drm_display_mode *mode; |
yakui_zhao | 6714977 | 2009-04-02 11:52:12 +0800 | [diff] [blame] | 67 | |
| 68 | if (flags == (DRM_MODE_FLAG_DBLSCAN | DRM_MODE_FLAG_INTERLACE)) |
| 69 | return; |
| 70 | |
Sascha Hauer | a1178ca | 2012-02-01 11:38:30 +0100 | [diff] [blame] | 71 | list_for_each_entry(mode, &connector->modes, head) { |
yakui_zhao | 6714977 | 2009-04-02 11:52:12 +0800 | [diff] [blame] | 72 | if ((mode->flags & DRM_MODE_FLAG_INTERLACE) && |
| 73 | !(flags & DRM_MODE_FLAG_INTERLACE)) |
| 74 | mode->status = MODE_NO_INTERLACE; |
| 75 | if ((mode->flags & DRM_MODE_FLAG_DBLSCAN) && |
| 76 | !(flags & DRM_MODE_FLAG_DBLSCAN)) |
| 77 | mode->status = MODE_NO_DBLESCAN; |
| 78 | } |
| 79 | |
| 80 | return; |
| 81 | } |
| 82 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 83 | /** |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 84 | * drm_helper_probe_single_connector_modes - get complete set of display modes |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 85 | * @dev: DRM device |
| 86 | * @maxX: max width for modes |
| 87 | * @maxY: max height for modes |
| 88 | * |
| 89 | * LOCKING: |
| 90 | * Caller must hold mode config lock. |
| 91 | * |
| 92 | * Based on @dev's mode_config layout, scan all the connectors and try to detect |
| 93 | * modes on them. Modes will first be added to the connector's probed_modes |
| 94 | * list, then culled (based on validity and the @maxX, @maxY parameters) and |
| 95 | * put into the normal modes list. |
| 96 | * |
| 97 | * Intended to be used either at bootup time or when major configuration |
| 98 | * changes have occurred. |
| 99 | * |
| 100 | * FIXME: take into account monitor limits |
Jesse Barnes | 40a518d | 2009-01-12 12:05:32 -0800 | [diff] [blame] | 101 | * |
| 102 | * RETURNS: |
| 103 | * Number of modes found on @connector. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 104 | */ |
Jesse Barnes | 40a518d | 2009-01-12 12:05:32 -0800 | [diff] [blame] | 105 | int drm_helper_probe_single_connector_modes(struct drm_connector *connector, |
| 106 | uint32_t maxX, uint32_t maxY) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 107 | { |
| 108 | struct drm_device *dev = connector->dev; |
Sascha Hauer | a1178ca | 2012-02-01 11:38:30 +0100 | [diff] [blame] | 109 | struct drm_display_mode *mode; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 110 | struct drm_connector_helper_funcs *connector_funcs = |
| 111 | connector->helper_private; |
Jesse Barnes | 40a518d | 2009-01-12 12:05:32 -0800 | [diff] [blame] | 112 | int count = 0; |
yakui_zhao | 6714977 | 2009-04-02 11:52:12 +0800 | [diff] [blame] | 113 | int mode_flags = 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 114 | |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 115 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id, |
| 116 | drm_get_connector_name(connector)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 117 | /* set all modes to the unverified state */ |
Sascha Hauer | a1178ca | 2012-02-01 11:38:30 +0100 | [diff] [blame] | 118 | list_for_each_entry(mode, &connector->modes, head) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 119 | mode->status = MODE_UNVERIFIED; |
| 120 | |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 121 | if (connector->force) { |
| 122 | if (connector->force == DRM_FORCE_ON) |
| 123 | connector->status = connector_status_connected; |
| 124 | else |
| 125 | connector->status = connector_status_disconnected; |
| 126 | if (connector->funcs->force) |
| 127 | connector->funcs->force(connector); |
Chris Wilson | e58f637 | 2010-08-20 09:13:36 +0100 | [diff] [blame] | 128 | } else { |
Chris Wilson | 930a9e2 | 2010-09-14 11:07:23 +0100 | [diff] [blame] | 129 | connector->status = connector->funcs->detect(connector, true); |
Chris Wilson | e58f637 | 2010-08-20 09:13:36 +0100 | [diff] [blame] | 130 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 131 | |
Daniel Vetter | 905bc9f | 2012-10-23 18:23:36 +0000 | [diff] [blame] | 132 | /* Re-enable polling in case the global poll config changed. */ |
| 133 | if (drm_kms_helper_poll != dev->mode_config.poll_running) |
| 134 | drm_kms_helper_poll_enable(dev); |
| 135 | |
| 136 | dev->mode_config.poll_running = drm_kms_helper_poll; |
| 137 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 138 | if (connector->status == connector_status_disconnected) { |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 139 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] disconnected\n", |
| 140 | connector->base.id, drm_get_connector_name(connector)); |
Zhao Yakui | 7253983 | 2010-03-04 08:25:55 +0000 | [diff] [blame] | 141 | drm_mode_connector_update_edid_property(connector, NULL); |
Adam Jackson | 620f378 | 2009-09-08 11:51:46 +1000 | [diff] [blame] | 142 | goto prune; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 143 | } |
| 144 | |
Carsten Emde | da0df92 | 2012-03-18 22:37:33 +0100 | [diff] [blame] | 145 | #ifdef CONFIG_DRM_LOAD_EDID_FIRMWARE |
| 146 | count = drm_load_edid_firmware(connector); |
| 147 | if (count == 0) |
| 148 | #endif |
| 149 | count = (*connector_funcs->get_modes)(connector); |
| 150 | |
Chris Wilson | c7ef35a | 2010-09-05 16:55:25 +0100 | [diff] [blame] | 151 | if (count == 0 && connector->status == connector_status_connected) |
Adam Jackson | 9632b41 | 2009-11-23 14:23:07 -0500 | [diff] [blame] | 152 | count = drm_add_modes_noedid(connector, 1024, 768); |
Chris Wilson | c7ef35a | 2010-09-05 16:55:25 +0100 | [diff] [blame] | 153 | if (count == 0) |
| 154 | goto prune; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 155 | |
Jesse Barnes | 40a518d | 2009-01-12 12:05:32 -0800 | [diff] [blame] | 156 | drm_mode_connector_list_update(connector); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 157 | |
| 158 | if (maxX && maxY) |
| 159 | drm_mode_validate_size(dev, &connector->modes, maxX, |
| 160 | maxY, 0); |
yakui_zhao | 6714977 | 2009-04-02 11:52:12 +0800 | [diff] [blame] | 161 | |
| 162 | if (connector->interlace_allowed) |
| 163 | mode_flags |= DRM_MODE_FLAG_INTERLACE; |
| 164 | if (connector->doublescan_allowed) |
| 165 | mode_flags |= DRM_MODE_FLAG_DBLSCAN; |
| 166 | drm_mode_validate_flag(connector, mode_flags); |
| 167 | |
Sascha Hauer | a1178ca | 2012-02-01 11:38:30 +0100 | [diff] [blame] | 168 | list_for_each_entry(mode, &connector->modes, head) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 169 | if (mode->status == MODE_OK) |
| 170 | mode->status = connector_funcs->mode_valid(connector, |
| 171 | mode); |
| 172 | } |
| 173 | |
Adam Jackson | 620f378 | 2009-09-08 11:51:46 +1000 | [diff] [blame] | 174 | prune: |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 175 | drm_mode_prune_invalid(dev, &connector->modes, true); |
| 176 | |
Jesse Barnes | 40a518d | 2009-01-12 12:05:32 -0800 | [diff] [blame] | 177 | if (list_empty(&connector->modes)) |
| 178 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 179 | |
| 180 | drm_mode_sort(&connector->modes); |
| 181 | |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 182 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] probed modes :\n", connector->base.id, |
| 183 | drm_get_connector_name(connector)); |
Sascha Hauer | a1178ca | 2012-02-01 11:38:30 +0100 | [diff] [blame] | 184 | list_for_each_entry(mode, &connector->modes, head) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 185 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 186 | |
| 187 | drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); |
| 188 | drm_mode_debug_printmodeline(mode); |
| 189 | } |
Jesse Barnes | 40a518d | 2009-01-12 12:05:32 -0800 | [diff] [blame] | 190 | |
| 191 | return count; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 192 | } |
| 193 | EXPORT_SYMBOL(drm_helper_probe_single_connector_modes); |
| 194 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 195 | /** |
Keith Packard | c9fb15f | 2009-05-30 20:42:28 -0700 | [diff] [blame] | 196 | * drm_helper_encoder_in_use - check if a given encoder is in use |
| 197 | * @encoder: encoder to check |
| 198 | * |
| 199 | * LOCKING: |
| 200 | * Caller must hold mode config lock. |
| 201 | * |
| 202 | * Walk @encoders's DRM device's mode_config and see if it's in use. |
| 203 | * |
| 204 | * RETURNS: |
| 205 | * True if @encoder is part of the mode_config, false otherwise. |
| 206 | */ |
| 207 | bool drm_helper_encoder_in_use(struct drm_encoder *encoder) |
| 208 | { |
| 209 | struct drm_connector *connector; |
| 210 | struct drm_device *dev = encoder->dev; |
| 211 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
| 212 | if (connector->encoder == encoder) |
| 213 | return true; |
| 214 | return false; |
| 215 | } |
| 216 | EXPORT_SYMBOL(drm_helper_encoder_in_use); |
| 217 | |
| 218 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 219 | * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config |
| 220 | * @crtc: CRTC to check |
| 221 | * |
| 222 | * LOCKING: |
| 223 | * Caller must hold mode config lock. |
| 224 | * |
| 225 | * Walk @crtc's DRM device's mode_config and see if it's in use. |
| 226 | * |
| 227 | * RETURNS: |
| 228 | * True if @crtc is part of the mode_config, false otherwise. |
| 229 | */ |
| 230 | bool drm_helper_crtc_in_use(struct drm_crtc *crtc) |
| 231 | { |
| 232 | struct drm_encoder *encoder; |
| 233 | struct drm_device *dev = crtc->dev; |
| 234 | /* FIXME: Locking around list access? */ |
| 235 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
Keith Packard | c9fb15f | 2009-05-30 20:42:28 -0700 | [diff] [blame] | 236 | if (encoder->crtc == crtc && drm_helper_encoder_in_use(encoder)) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 237 | return true; |
| 238 | return false; |
| 239 | } |
| 240 | EXPORT_SYMBOL(drm_helper_crtc_in_use); |
| 241 | |
Ben Skeggs | 86a1b9d | 2010-07-01 16:49:57 +1000 | [diff] [blame] | 242 | static void |
| 243 | drm_encoder_disable(struct drm_encoder *encoder) |
| 244 | { |
| 245 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; |
| 246 | |
| 247 | if (encoder_funcs->disable) |
| 248 | (*encoder_funcs->disable)(encoder); |
| 249 | else |
| 250 | (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF); |
| 251 | } |
| 252 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 253 | /** |
David John | 89347bb | 2009-12-31 12:00:46 +0530 | [diff] [blame] | 254 | * drm_helper_disable_unused_functions - disable unused objects |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 255 | * @dev: DRM device |
| 256 | * |
| 257 | * LOCKING: |
| 258 | * Caller must hold mode config lock. |
| 259 | * |
| 260 | * If an connector or CRTC isn't part of @dev's mode_config, it can be disabled |
| 261 | * by calling its dpms function, which should power it off. |
| 262 | */ |
| 263 | void drm_helper_disable_unused_functions(struct drm_device *dev) |
| 264 | { |
| 265 | struct drm_encoder *encoder; |
Dave Airlie | a3a0544 | 2009-08-31 15:16:30 +1000 | [diff] [blame] | 266 | struct drm_connector *connector; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 267 | struct drm_crtc *crtc; |
| 268 | |
Dave Airlie | a3a0544 | 2009-08-31 15:16:30 +1000 | [diff] [blame] | 269 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 270 | if (!connector->encoder) |
| 271 | continue; |
| 272 | if (connector->status == connector_status_disconnected) |
| 273 | connector->encoder = NULL; |
| 274 | } |
| 275 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 276 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
Dave Airlie | 92971021 | 2010-12-21 12:47:56 +1000 | [diff] [blame] | 277 | if (!drm_helper_encoder_in_use(encoder)) { |
Ben Skeggs | 86a1b9d | 2010-07-01 16:49:57 +1000 | [diff] [blame] | 278 | drm_encoder_disable(encoder); |
Dave Airlie | 9c552dd | 2009-09-02 14:00:11 +1000 | [diff] [blame] | 279 | /* disconnector encoder from any connector */ |
| 280 | encoder->crtc = NULL; |
Dave Airlie | a3a0544 | 2009-08-31 15:16:30 +1000 | [diff] [blame] | 281 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 285 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 286 | crtc->enabled = drm_helper_crtc_in_use(crtc); |
| 287 | if (!crtc->enabled) { |
Alex Deucher | 5c8d717 | 2010-06-11 17:04:35 -0400 | [diff] [blame] | 288 | if (crtc_funcs->disable) |
| 289 | (*crtc_funcs->disable)(crtc); |
| 290 | else |
| 291 | (*crtc_funcs->dpms)(crtc, DRM_MODE_DPMS_OFF); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 292 | crtc->fb = NULL; |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | EXPORT_SYMBOL(drm_helper_disable_unused_functions); |
| 297 | |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 298 | /** |
| 299 | * drm_encoder_crtc_ok - can a given crtc drive a given encoder? |
| 300 | * @encoder: encoder to test |
| 301 | * @crtc: crtc to test |
| 302 | * |
| 303 | * Return false if @encoder can't be driven by @crtc, true otherwise. |
| 304 | */ |
| 305 | static bool drm_encoder_crtc_ok(struct drm_encoder *encoder, |
| 306 | struct drm_crtc *crtc) |
| 307 | { |
| 308 | struct drm_device *dev; |
| 309 | struct drm_crtc *tmp; |
| 310 | int crtc_mask = 1; |
| 311 | |
Joe Perches | fce7d61 | 2010-10-30 21:08:30 +0000 | [diff] [blame] | 312 | WARN(!crtc, "checking null crtc?\n"); |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 313 | |
| 314 | dev = crtc->dev; |
| 315 | |
| 316 | list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) { |
| 317 | if (tmp == crtc) |
| 318 | break; |
| 319 | crtc_mask <<= 1; |
| 320 | } |
| 321 | |
| 322 | if (encoder->possible_crtcs & crtc_mask) |
| 323 | return true; |
| 324 | return false; |
| 325 | } |
| 326 | |
| 327 | /* |
| 328 | * Check the CRTC we're going to map each output to vs. its current |
| 329 | * CRTC. If they don't match, we have to disable the output and the CRTC |
| 330 | * since the driver will have to re-route things. |
| 331 | */ |
| 332 | static void |
| 333 | drm_crtc_prepare_encoders(struct drm_device *dev) |
| 334 | { |
| 335 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 336 | struct drm_encoder *encoder; |
| 337 | |
| 338 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 339 | encoder_funcs = encoder->helper_private; |
| 340 | /* Disable unused encoders */ |
| 341 | if (encoder->crtc == NULL) |
Ben Skeggs | 86a1b9d | 2010-07-01 16:49:57 +1000 | [diff] [blame] | 342 | drm_encoder_disable(encoder); |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 343 | /* Disable encoders whose CRTC is about to change */ |
| 344 | if (encoder_funcs->get_crtc && |
| 345 | encoder->crtc != (*encoder_funcs->get_crtc)(encoder)) |
Ben Skeggs | 86a1b9d | 2010-07-01 16:49:57 +1000 | [diff] [blame] | 346 | drm_encoder_disable(encoder); |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 350 | /** |
| 351 | * drm_crtc_set_mode - set a mode |
| 352 | * @crtc: CRTC to program |
| 353 | * @mode: mode to use |
Alex Deucher | 4c9287c | 2012-11-09 17:26:32 +0000 | [diff] [blame] | 354 | * @x: horizontal offset into the surface |
| 355 | * @y: vertical offset into the surface |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 356 | * |
| 357 | * LOCKING: |
| 358 | * Caller must hold mode config lock. |
| 359 | * |
| 360 | * Try to set @mode on @crtc. Give @crtc and its associated connectors a chance |
| 361 | * to fixup or reject the mode prior to trying to set it. |
| 362 | * |
| 363 | * RETURNS: |
| 364 | * True if the mode was set successfully, or false otherwise. |
| 365 | */ |
| 366 | bool drm_crtc_helper_set_mode(struct drm_crtc *crtc, |
| 367 | struct drm_display_mode *mode, |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 368 | int x, int y, |
| 369 | struct drm_framebuffer *old_fb) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 370 | { |
| 371 | struct drm_device *dev = crtc->dev; |
Mario Kleiner | 27641c3 | 2010-10-23 04:20:23 +0200 | [diff] [blame] | 372 | struct drm_display_mode *adjusted_mode, saved_mode, saved_hwmode; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 373 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 374 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 375 | int saved_x, saved_y; |
| 376 | struct drm_encoder *encoder; |
| 377 | bool ret = true; |
| 378 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 379 | crtc->enabled = drm_helper_crtc_in_use(crtc); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 380 | if (!crtc->enabled) |
| 381 | return true; |
| 382 | |
Chris Wilson | 021a845 | 2011-01-28 11:31:56 +0000 | [diff] [blame] | 383 | adjusted_mode = drm_mode_duplicate(dev, mode); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 384 | if (!adjusted_mode) |
| 385 | return false; |
Chris Wilson | 021a845 | 2011-01-28 11:31:56 +0000 | [diff] [blame] | 386 | |
Mario Kleiner | 27641c3 | 2010-10-23 04:20:23 +0200 | [diff] [blame] | 387 | saved_hwmode = crtc->hwmode; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 388 | saved_mode = crtc->mode; |
| 389 | saved_x = crtc->x; |
| 390 | saved_y = crtc->y; |
| 391 | |
| 392 | /* Update crtc values up front so the driver can rely on them for mode |
| 393 | * setting. |
| 394 | */ |
| 395 | crtc->mode = *mode; |
| 396 | crtc->x = x; |
| 397 | crtc->y = y; |
| 398 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 399 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 400 | * adjust it according to limitations or connector properties, and also |
| 401 | * a chance to reject the mode entirely. |
| 402 | */ |
| 403 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 404 | |
| 405 | if (encoder->crtc != crtc) |
| 406 | continue; |
| 407 | encoder_funcs = encoder->helper_private; |
| 408 | if (!(ret = encoder_funcs->mode_fixup(encoder, mode, |
| 409 | adjusted_mode))) { |
Adam Jackson | 836e53d | 2011-10-10 16:21:27 -0400 | [diff] [blame] | 410 | DRM_DEBUG_KMS("Encoder fixup failed\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 411 | goto done; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | if (!(ret = crtc_funcs->mode_fixup(crtc, mode, adjusted_mode))) { |
Adam Jackson | 836e53d | 2011-10-10 16:21:27 -0400 | [diff] [blame] | 416 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 417 | goto done; |
| 418 | } |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 419 | DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 420 | |
| 421 | /* Prepare the encoders and CRTCs before setting the mode. */ |
| 422 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 423 | |
| 424 | if (encoder->crtc != crtc) |
| 425 | continue; |
| 426 | encoder_funcs = encoder->helper_private; |
| 427 | /* Disable the encoders as the first thing we do. */ |
| 428 | encoder_funcs->prepare(encoder); |
| 429 | } |
| 430 | |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 431 | drm_crtc_prepare_encoders(dev); |
| 432 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 433 | crtc_funcs->prepare(crtc); |
| 434 | |
| 435 | /* Set up the DPLL and any encoders state that needs to adjust or depend |
| 436 | * on the DPLL. |
| 437 | */ |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 438 | ret = !crtc_funcs->mode_set(crtc, mode, adjusted_mode, x, y, old_fb); |
| 439 | if (!ret) |
| 440 | goto done; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 441 | |
| 442 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 443 | |
| 444 | if (encoder->crtc != crtc) |
| 445 | continue; |
| 446 | |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 447 | DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n", |
| 448 | encoder->base.id, drm_get_encoder_name(encoder), |
| 449 | mode->base.id, mode->name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 450 | encoder_funcs = encoder->helper_private; |
| 451 | encoder_funcs->mode_set(encoder, mode, adjusted_mode); |
| 452 | } |
| 453 | |
| 454 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
| 455 | crtc_funcs->commit(crtc); |
| 456 | |
| 457 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 458 | |
| 459 | if (encoder->crtc != crtc) |
| 460 | continue; |
| 461 | |
| 462 | encoder_funcs = encoder->helper_private; |
| 463 | encoder_funcs->commit(encoder); |
| 464 | |
| 465 | } |
| 466 | |
Mario Kleiner | 27641c3 | 2010-10-23 04:20:23 +0200 | [diff] [blame] | 467 | /* Store real post-adjustment hardware mode. */ |
| 468 | crtc->hwmode = *adjusted_mode; |
| 469 | |
| 470 | /* Calculate and store various constants which |
| 471 | * are later needed by vblank and swap-completion |
| 472 | * timestamping. They are derived from true hwmode. |
| 473 | */ |
| 474 | drm_calc_timestamping_constants(crtc); |
| 475 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 476 | /* FIXME: add subpixel order */ |
| 477 | done: |
Chris Wilson | 021a845 | 2011-01-28 11:31:56 +0000 | [diff] [blame] | 478 | drm_mode_destroy(dev, adjusted_mode); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 479 | if (!ret) { |
Mario Kleiner | 27641c3 | 2010-10-23 04:20:23 +0200 | [diff] [blame] | 480 | crtc->hwmode = saved_hwmode; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 481 | crtc->mode = saved_mode; |
| 482 | crtc->x = saved_x; |
| 483 | crtc->y = saved_y; |
| 484 | } |
| 485 | |
| 486 | return ret; |
| 487 | } |
| 488 | EXPORT_SYMBOL(drm_crtc_helper_set_mode); |
| 489 | |
| 490 | |
Chris Wilson | 6eebd6b | 2011-11-28 21:10:05 +0000 | [diff] [blame] | 491 | static int |
| 492 | drm_crtc_helper_disable(struct drm_crtc *crtc) |
| 493 | { |
| 494 | struct drm_device *dev = crtc->dev; |
| 495 | struct drm_connector *connector; |
| 496 | struct drm_encoder *encoder; |
| 497 | |
| 498 | /* Decouple all encoders and their attached connectors from this crtc */ |
| 499 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 500 | if (encoder->crtc != crtc) |
| 501 | continue; |
| 502 | |
| 503 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 504 | if (connector->encoder != encoder) |
| 505 | continue; |
| 506 | |
| 507 | connector->encoder = NULL; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | drm_helper_disable_unused_functions(dev); |
| 512 | return 0; |
| 513 | } |
| 514 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 515 | /** |
| 516 | * drm_crtc_helper_set_config - set a new config from userspace |
| 517 | * @crtc: CRTC to setup |
| 518 | * @crtc_info: user provided configuration |
| 519 | * @new_mode: new mode to set |
| 520 | * @connector_set: set of connectors for the new config |
| 521 | * @fb: new framebuffer |
| 522 | * |
| 523 | * LOCKING: |
| 524 | * Caller must hold mode config lock. |
| 525 | * |
| 526 | * Setup a new configuration, provided by the user in @crtc_info, and enable |
| 527 | * it. |
| 528 | * |
| 529 | * RETURNS: |
| 530 | * Zero. (FIXME) |
| 531 | */ |
| 532 | int drm_crtc_helper_set_config(struct drm_mode_set *set) |
| 533 | { |
| 534 | struct drm_device *dev; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 535 | struct drm_crtc *save_crtcs, *new_crtc, *crtc; |
| 536 | struct drm_encoder *save_encoders, *new_encoder, *encoder; |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 537 | struct drm_framebuffer *old_fb = NULL; |
Jakob Bornecrantz | 4cb72b1 | 2009-08-03 13:43:59 +0100 | [diff] [blame] | 538 | bool mode_changed = false; /* if true do a full mode set */ |
| 539 | 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] | 540 | struct drm_connector *save_connectors, *connector; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 541 | int count = 0, ro, fail = 0; |
| 542 | struct drm_crtc_helper_funcs *crtc_funcs; |
Jesse Barnes | c5006cfe | 2011-11-07 10:39:57 -0800 | [diff] [blame] | 543 | struct drm_mode_set save_set; |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 544 | int ret; |
Keith Packard | bf9dc10 | 2010-11-26 10:45:58 -0800 | [diff] [blame] | 545 | int i; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 546 | |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 547 | DRM_DEBUG_KMS("\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 548 | |
| 549 | if (!set) |
| 550 | return -EINVAL; |
| 551 | |
| 552 | if (!set->crtc) |
| 553 | return -EINVAL; |
| 554 | |
| 555 | if (!set->crtc->helper_private) |
| 556 | return -EINVAL; |
| 557 | |
| 558 | crtc_funcs = set->crtc->helper_private; |
| 559 | |
Chris Wilson | ede3ff5 | 2011-01-31 11:16:33 +0000 | [diff] [blame] | 560 | if (!set->mode) |
| 561 | set->fb = NULL; |
| 562 | |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 563 | if (set->fb) { |
| 564 | DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n", |
| 565 | set->crtc->base.id, set->fb->base.id, |
| 566 | (int)set->num_connectors, set->x, set->y); |
| 567 | } else { |
Chris Wilson | ede3ff5 | 2011-01-31 11:16:33 +0000 | [diff] [blame] | 568 | DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id); |
Chris Wilson | 6eebd6b | 2011-11-28 21:10:05 +0000 | [diff] [blame] | 569 | return drm_crtc_helper_disable(set->crtc); |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 570 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 571 | |
| 572 | dev = set->crtc->dev; |
| 573 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 574 | /* Allocate space for the backup of all (non-pointer) crtc, encoder and |
| 575 | * connector data. */ |
| 576 | save_crtcs = kzalloc(dev->mode_config.num_crtc * |
| 577 | sizeof(struct drm_crtc), GFP_KERNEL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 578 | if (!save_crtcs) |
| 579 | return -ENOMEM; |
| 580 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 581 | save_encoders = kzalloc(dev->mode_config.num_encoder * |
| 582 | sizeof(struct drm_encoder), GFP_KERNEL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 583 | if (!save_encoders) { |
| 584 | kfree(save_crtcs); |
| 585 | return -ENOMEM; |
| 586 | } |
| 587 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 588 | save_connectors = kzalloc(dev->mode_config.num_connector * |
| 589 | sizeof(struct drm_connector), GFP_KERNEL); |
| 590 | if (!save_connectors) { |
| 591 | kfree(save_crtcs); |
| 592 | kfree(save_encoders); |
| 593 | return -ENOMEM; |
| 594 | } |
| 595 | |
| 596 | /* Copy data. Note that driver private data is not affected. |
| 597 | * Should anything bad happen only the expected state is |
| 598 | * restored, not the drivers personal bookkeeping. |
| 599 | */ |
| 600 | count = 0; |
| 601 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 602 | save_crtcs[count++] = *crtc; |
| 603 | } |
| 604 | |
| 605 | count = 0; |
| 606 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 607 | save_encoders[count++] = *encoder; |
| 608 | } |
| 609 | |
| 610 | count = 0; |
| 611 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 612 | save_connectors[count++] = *connector; |
| 613 | } |
| 614 | |
Jesse Barnes | c5006cfe | 2011-11-07 10:39:57 -0800 | [diff] [blame] | 615 | save_set.crtc = set->crtc; |
| 616 | save_set.mode = &set->crtc->mode; |
| 617 | save_set.x = set->crtc->x; |
| 618 | save_set.y = set->crtc->y; |
| 619 | save_set.fb = set->crtc->fb; |
| 620 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 621 | /* We should be able to check here if the fb has the same properties |
| 622 | * and then just flip_or_move it */ |
| 623 | if (set->crtc->fb != set->fb) { |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 624 | /* 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] | 625 | if (set->crtc->fb == NULL) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 626 | DRM_DEBUG_KMS("crtc has no fb, full mode set\n"); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 627 | mode_changed = true; |
Jakob Bornecrantz | 4cb72b1 | 2009-08-03 13:43:59 +0100 | [diff] [blame] | 628 | } else if (set->fb == NULL) { |
| 629 | mode_changed = true; |
Jesse Barnes | 46e4845 | 2011-06-24 12:19:26 -0700 | [diff] [blame] | 630 | } else if (set->fb->depth != set->crtc->fb->depth) { |
| 631 | mode_changed = true; |
| 632 | } else if (set->fb->bits_per_pixel != |
| 633 | set->crtc->fb->bits_per_pixel) { |
| 634 | mode_changed = true; |
Dave Airlie | 8dff474 | 2010-02-11 14:28:58 +1000 | [diff] [blame] | 635 | } else |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 636 | fb_changed = true; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | if (set->x != set->crtc->x || set->y != set->crtc->y) |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 640 | fb_changed = true; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 641 | |
| 642 | if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 643 | DRM_DEBUG_KMS("modes are different, full mode set\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 644 | drm_mode_debug_printmodeline(&set->crtc->mode); |
| 645 | drm_mode_debug_printmodeline(set->mode); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 646 | mode_changed = true; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | /* a) traverse passed in connector list and get encoders for them */ |
| 650 | count = 0; |
| 651 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 652 | struct drm_connector_helper_funcs *connector_funcs = |
| 653 | connector->helper_private; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 654 | new_encoder = connector->encoder; |
| 655 | for (ro = 0; ro < set->num_connectors; ro++) { |
| 656 | if (set->connectors[ro] == connector) { |
| 657 | new_encoder = connector_funcs->best_encoder(connector); |
| 658 | /* if we can't get an encoder for a connector |
| 659 | we are setting now - then fail */ |
| 660 | if (new_encoder == NULL) |
| 661 | /* don't break so fail path works correct */ |
| 662 | fail = 1; |
| 663 | break; |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | if (new_encoder != connector->encoder) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 668 | DRM_DEBUG_KMS("encoder changed, full mode switch\n"); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 669 | mode_changed = true; |
Maarten Maathuis | ff846ab | 2009-08-19 00:56:45 +0200 | [diff] [blame] | 670 | /* If the encoder is reused for another connector, then |
| 671 | * the appropriate crtc will be set later. |
| 672 | */ |
Maarten Maathuis | ff6fdbe | 2009-09-01 03:39:04 +0200 | [diff] [blame] | 673 | if (connector->encoder) |
| 674 | connector->encoder->crtc = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 675 | connector->encoder = new_encoder; |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | if (fail) { |
| 680 | ret = -EINVAL; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 681 | goto fail; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | count = 0; |
| 685 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 686 | if (!connector->encoder) |
| 687 | continue; |
| 688 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 689 | if (connector->encoder->crtc == set->crtc) |
| 690 | new_crtc = NULL; |
| 691 | else |
| 692 | new_crtc = connector->encoder->crtc; |
| 693 | |
| 694 | for (ro = 0; ro < set->num_connectors; ro++) { |
| 695 | if (set->connectors[ro] == connector) |
| 696 | new_crtc = set->crtc; |
| 697 | } |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 698 | |
| 699 | /* Make sure the new CRTC will work with the encoder */ |
| 700 | if (new_crtc && |
| 701 | !drm_encoder_crtc_ok(connector->encoder, new_crtc)) { |
| 702 | ret = -EINVAL; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 703 | goto fail; |
Jesse Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 704 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 705 | if (new_crtc != connector->encoder->crtc) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 706 | DRM_DEBUG_KMS("crtc changed, full mode switch\n"); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 707 | mode_changed = true; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 708 | connector->encoder->crtc = new_crtc; |
| 709 | } |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 710 | if (new_crtc) { |
| 711 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n", |
| 712 | connector->base.id, drm_get_connector_name(connector), |
| 713 | new_crtc->base.id); |
| 714 | } else { |
| 715 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n", |
| 716 | connector->base.id, drm_get_connector_name(connector)); |
| 717 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | /* mode_set_base is not a required function */ |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 721 | if (fb_changed && !crtc_funcs->mode_set_base) |
| 722 | mode_changed = true; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 723 | |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 724 | if (mode_changed) { |
Chris Wilson | 9334ef7 | 2011-01-28 11:53:03 +0000 | [diff] [blame] | 725 | set->crtc->enabled = drm_helper_crtc_in_use(set->crtc); |
| 726 | if (set->crtc->enabled) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 727 | DRM_DEBUG_KMS("attempting to set mode from" |
| 728 | " userspace\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 729 | drm_mode_debug_printmodeline(set->mode); |
Chris Wilson | 356ad3c | 2010-09-09 09:41:32 +0100 | [diff] [blame] | 730 | old_fb = set->crtc->fb; |
| 731 | set->crtc->fb = set->fb; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 732 | if (!drm_crtc_helper_set_mode(set->crtc, set->mode, |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 733 | set->x, set->y, |
| 734 | old_fb)) { |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 735 | DRM_ERROR("failed to set mode on [CRTC:%d]\n", |
| 736 | set->crtc->base.id); |
Chris Wilson | 0ba41e4 | 2011-01-08 15:10:41 +0000 | [diff] [blame] | 737 | set->crtc->fb = old_fb; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 738 | ret = -EINVAL; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 739 | goto fail; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 740 | } |
Keith Packard | 811aaa5 | 2011-02-03 16:57:28 -0800 | [diff] [blame] | 741 | DRM_DEBUG_KMS("Setting connector DPMS state to on\n"); |
| 742 | for (i = 0; i < set->num_connectors; i++) { |
| 743 | DRM_DEBUG_KMS("\t[CONNECTOR:%d:%s] set DPMS on\n", set->connectors[i]->base.id, |
| 744 | drm_get_connector_name(set->connectors[i])); |
Rob Clark | c754883 | 2011-12-15 14:53:24 -0600 | [diff] [blame] | 745 | set->connectors[i]->funcs->dpms(set->connectors[i], DRM_MODE_DPMS_ON); |
Keith Packard | 811aaa5 | 2011-02-03 16:57:28 -0800 | [diff] [blame] | 746 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 747 | } |
| 748 | drm_helper_disable_unused_functions(dev); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 749 | } else if (fb_changed) { |
Ben Skeggs | 9b1596a | 2009-09-18 10:43:52 +1000 | [diff] [blame] | 750 | set->crtc->x = set->x; |
| 751 | set->crtc->y = set->y; |
| 752 | |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 753 | old_fb = set->crtc->fb; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 754 | if (set->crtc->fb != set->fb) |
| 755 | set->crtc->fb = set->fb; |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 756 | ret = crtc_funcs->mode_set_base(set->crtc, |
| 757 | set->x, set->y, old_fb); |
Chris Wilson | 0ba41e4 | 2011-01-08 15:10:41 +0000 | [diff] [blame] | 758 | if (ret != 0) { |
| 759 | set->crtc->fb = old_fb; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 760 | goto fail; |
Chris Wilson | 0ba41e4 | 2011-01-08 15:10:41 +0000 | [diff] [blame] | 761 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 762 | } |
| 763 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 764 | kfree(save_connectors); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 765 | kfree(save_encoders); |
| 766 | kfree(save_crtcs); |
| 767 | return 0; |
| 768 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 769 | fail: |
| 770 | /* Restore all previous data. */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 771 | count = 0; |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 772 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 773 | *crtc = save_crtcs[count++]; |
| 774 | } |
Chris Wilson | e62fb64 | 2009-02-11 16:39:21 +0000 | [diff] [blame] | 775 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 776 | count = 0; |
| 777 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 778 | *encoder = save_encoders[count++]; |
Chris Wilson | e62fb64 | 2009-02-11 16:39:21 +0000 | [diff] [blame] | 779 | } |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 780 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 781 | count = 0; |
| 782 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 783 | *connector = save_connectors[count++]; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 784 | } |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 785 | |
Jesse Barnes | c5006cfe | 2011-11-07 10:39:57 -0800 | [diff] [blame] | 786 | /* Try to restore the config */ |
| 787 | if (mode_changed && |
| 788 | !drm_crtc_helper_set_mode(save_set.crtc, save_set.mode, save_set.x, |
| 789 | save_set.y, save_set.fb)) |
| 790 | DRM_ERROR("failed to restore config after modeset failure\n"); |
| 791 | |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 792 | kfree(save_connectors); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 793 | kfree(save_encoders); |
Maarten Maathuis | e67aae7 | 2009-08-27 10:18:29 +0200 | [diff] [blame] | 794 | kfree(save_crtcs); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 795 | return ret; |
| 796 | } |
| 797 | EXPORT_SYMBOL(drm_crtc_helper_set_config); |
| 798 | |
Keith Packard | c9fb15f | 2009-05-30 20:42:28 -0700 | [diff] [blame] | 799 | static int drm_helper_choose_encoder_dpms(struct drm_encoder *encoder) |
| 800 | { |
| 801 | int dpms = DRM_MODE_DPMS_OFF; |
| 802 | struct drm_connector *connector; |
| 803 | struct drm_device *dev = encoder->dev; |
| 804 | |
| 805 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
| 806 | if (connector->encoder == encoder) |
| 807 | if (connector->dpms < dpms) |
| 808 | dpms = connector->dpms; |
| 809 | return dpms; |
| 810 | } |
| 811 | |
| 812 | static int drm_helper_choose_crtc_dpms(struct drm_crtc *crtc) |
| 813 | { |
| 814 | int dpms = DRM_MODE_DPMS_OFF; |
| 815 | struct drm_connector *connector; |
| 816 | struct drm_device *dev = crtc->dev; |
| 817 | |
| 818 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
| 819 | if (connector->encoder && connector->encoder->crtc == crtc) |
| 820 | if (connector->dpms < dpms) |
| 821 | dpms = connector->dpms; |
| 822 | return dpms; |
| 823 | } |
| 824 | |
| 825 | /** |
| 826 | * drm_helper_connector_dpms |
| 827 | * @connector affected connector |
| 828 | * @mode DPMS mode |
| 829 | * |
| 830 | * Calls the low-level connector DPMS function, then |
| 831 | * calls appropriate encoder and crtc DPMS functions as well |
| 832 | */ |
| 833 | void drm_helper_connector_dpms(struct drm_connector *connector, int mode) |
| 834 | { |
| 835 | struct drm_encoder *encoder = connector->encoder; |
| 836 | struct drm_crtc *crtc = encoder ? encoder->crtc : NULL; |
| 837 | int old_dpms; |
| 838 | |
| 839 | if (mode == connector->dpms) |
| 840 | return; |
| 841 | |
| 842 | old_dpms = connector->dpms; |
| 843 | connector->dpms = mode; |
| 844 | |
| 845 | /* from off to on, do crtc then encoder */ |
| 846 | if (mode < old_dpms) { |
| 847 | if (crtc) { |
| 848 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 849 | if (crtc_funcs->dpms) |
| 850 | (*crtc_funcs->dpms) (crtc, |
| 851 | drm_helper_choose_crtc_dpms(crtc)); |
| 852 | } |
| 853 | if (encoder) { |
| 854 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; |
| 855 | if (encoder_funcs->dpms) |
| 856 | (*encoder_funcs->dpms) (encoder, |
| 857 | drm_helper_choose_encoder_dpms(encoder)); |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | /* from on to off, do encoder then crtc */ |
| 862 | if (mode > old_dpms) { |
| 863 | if (encoder) { |
| 864 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; |
| 865 | if (encoder_funcs->dpms) |
| 866 | (*encoder_funcs->dpms) (encoder, |
| 867 | drm_helper_choose_encoder_dpms(encoder)); |
| 868 | } |
| 869 | if (crtc) { |
| 870 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 871 | if (crtc_funcs->dpms) |
| 872 | (*crtc_funcs->dpms) (crtc, |
| 873 | drm_helper_choose_crtc_dpms(crtc)); |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | return; |
| 878 | } |
| 879 | EXPORT_SYMBOL(drm_helper_connector_dpms); |
| 880 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 881 | int drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 882 | struct drm_mode_fb_cmd2 *mode_cmd) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 883 | { |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 884 | int i; |
| 885 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 886 | fb->width = mode_cmd->width; |
| 887 | fb->height = mode_cmd->height; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 888 | for (i = 0; i < 4; i++) { |
| 889 | fb->pitches[i] = mode_cmd->pitches[i]; |
| 890 | fb->offsets[i] = mode_cmd->offsets[i]; |
| 891 | } |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 892 | drm_fb_get_bpp_depth(mode_cmd->pixel_format, &fb->depth, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 893 | &fb->bits_per_pixel); |
| 894 | fb->pixel_format = mode_cmd->pixel_format; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 895 | |
| 896 | return 0; |
| 897 | } |
| 898 | EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct); |
| 899 | |
| 900 | int drm_helper_resume_force_mode(struct drm_device *dev) |
| 901 | { |
| 902 | struct drm_crtc *crtc; |
David John | 89347bb | 2009-12-31 12:00:46 +0530 | [diff] [blame] | 903 | struct drm_encoder *encoder; |
| 904 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 905 | struct drm_crtc_helper_funcs *crtc_funcs; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 906 | int ret; |
| 907 | |
| 908 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 909 | |
| 910 | if (!crtc->enabled) |
| 911 | continue; |
| 912 | |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 913 | ret = drm_crtc_helper_set_mode(crtc, &crtc->mode, |
| 914 | crtc->x, crtc->y, crtc->fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 915 | |
| 916 | if (ret == false) |
| 917 | DRM_ERROR("failed to set mode on crtc %p\n", crtc); |
David John | 89347bb | 2009-12-31 12:00:46 +0530 | [diff] [blame] | 918 | |
| 919 | /* Turn off outputs that were already powered off */ |
| 920 | if (drm_helper_choose_crtc_dpms(crtc)) { |
| 921 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 922 | |
| 923 | if(encoder->crtc != crtc) |
| 924 | continue; |
| 925 | |
| 926 | encoder_funcs = encoder->helper_private; |
| 927 | if (encoder_funcs->dpms) |
| 928 | (*encoder_funcs->dpms) (encoder, |
| 929 | drm_helper_choose_encoder_dpms(encoder)); |
David John | 89347bb | 2009-12-31 12:00:46 +0530 | [diff] [blame] | 930 | } |
Chris Wilson | 817e631 | 2010-08-06 15:03:31 +0100 | [diff] [blame] | 931 | |
| 932 | crtc_funcs = crtc->helper_private; |
| 933 | if (crtc_funcs->dpms) |
| 934 | (*crtc_funcs->dpms) (crtc, |
| 935 | drm_helper_choose_crtc_dpms(crtc)); |
David John | 89347bb | 2009-12-31 12:00:46 +0530 | [diff] [blame] | 936 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 937 | } |
Zhao Yakui | af4fcb5 | 2009-07-08 14:13:13 +0800 | [diff] [blame] | 938 | /* disable the unused connectors while restoring the modesetting */ |
| 939 | drm_helper_disable_unused_functions(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 940 | return 0; |
| 941 | } |
| 942 | EXPORT_SYMBOL(drm_helper_resume_force_mode); |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 943 | |
Daniel Vetter | 3d3683f | 2012-10-23 18:23:32 +0000 | [diff] [blame] | 944 | void drm_kms_helper_hotplug_event(struct drm_device *dev) |
| 945 | { |
| 946 | /* send a uevent + call fbdev */ |
| 947 | drm_sysfs_hotplug_event(dev); |
| 948 | if (dev->mode_config.funcs->output_poll_changed) |
| 949 | dev->mode_config.funcs->output_poll_changed(dev); |
| 950 | } |
| 951 | EXPORT_SYMBOL(drm_kms_helper_hotplug_event); |
| 952 | |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 953 | #define DRM_OUTPUT_POLL_PERIOD (10*HZ) |
Tejun Heo | 991ea75 | 2010-07-20 22:09:02 +0200 | [diff] [blame] | 954 | static void output_poll_execute(struct work_struct *work) |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 955 | { |
Tejun Heo | 991ea75 | 2010-07-20 22:09:02 +0200 | [diff] [blame] | 956 | struct delayed_work *delayed_work = to_delayed_work(work); |
| 957 | struct drm_device *dev = container_of(delayed_work, struct drm_device, mode_config.output_poll_work); |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 958 | struct drm_connector *connector; |
Keith Packard | c5027de | 2010-11-26 10:45:59 -0800 | [diff] [blame] | 959 | enum drm_connector_status old_status; |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 960 | bool repoll = false, changed = false; |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 961 | |
Chris Wilson | e58f637 | 2010-08-20 09:13:36 +0100 | [diff] [blame] | 962 | if (!drm_kms_helper_poll) |
| 963 | return; |
| 964 | |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 965 | mutex_lock(&dev->mode_config.mutex); |
| 966 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 967 | |
Daniel Vetter | 11e6868 | 2012-10-23 18:23:38 +0000 | [diff] [blame] | 968 | /* Ignore forced connectors. */ |
| 969 | if (connector->force) |
| 970 | continue; |
| 971 | |
Daniel Vetter | 816da85 | 2012-10-23 18:23:33 +0000 | [diff] [blame] | 972 | /* Ignore HPD capable connectors and connectors where we don't |
| 973 | * want any hotplug detection at all for polling. */ |
| 974 | if (!connector->polled || connector->polled == DRM_CONNECTOR_POLL_HPD) |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 975 | continue; |
| 976 | |
| 977 | else if (connector->polled & (DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT)) |
| 978 | repoll = true; |
| 979 | |
| 980 | old_status = connector->status; |
| 981 | /* if we are connected and don't want to poll for disconnect |
| 982 | skip it */ |
| 983 | if (old_status == connector_status_connected && |
Daniel Vetter | 816da85 | 2012-10-23 18:23:33 +0000 | [diff] [blame] | 984 | !(connector->polled & DRM_CONNECTOR_POLL_DISCONNECT)) |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 985 | continue; |
| 986 | |
Keith Packard | c5027de | 2010-11-26 10:45:59 -0800 | [diff] [blame] | 987 | connector->status = connector->funcs->detect(connector, false); |
Chris Wilson | 0f16830 | 2010-12-21 22:49:28 +0000 | [diff] [blame] | 988 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %d to %d\n", |
| 989 | connector->base.id, |
| 990 | drm_get_connector_name(connector), |
| 991 | old_status, connector->status); |
Keith Packard | c5027de | 2010-11-26 10:45:59 -0800 | [diff] [blame] | 992 | if (old_status != connector->status) |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 993 | changed = true; |
| 994 | } |
| 995 | |
| 996 | mutex_unlock(&dev->mode_config.mutex); |
| 997 | |
Daniel Vetter | 3d3683f | 2012-10-23 18:23:32 +0000 | [diff] [blame] | 998 | if (changed) |
| 999 | drm_kms_helper_hotplug_event(dev); |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1000 | |
Tejun Heo | 9a919c4 | 2010-08-09 12:01:27 +0200 | [diff] [blame] | 1001 | if (repoll) |
Tejun Heo | 3b07e9c | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 1002 | schedule_delayed_work(delayed_work, DRM_OUTPUT_POLL_PERIOD); |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 1005 | void drm_kms_helper_poll_disable(struct drm_device *dev) |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1006 | { |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 1007 | if (!dev->mode_config.poll_enabled) |
| 1008 | return; |
Tejun Heo | 991ea75 | 2010-07-20 22:09:02 +0200 | [diff] [blame] | 1009 | cancel_delayed_work_sync(&dev->mode_config.output_poll_work); |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 1010 | } |
| 1011 | EXPORT_SYMBOL(drm_kms_helper_poll_disable); |
| 1012 | |
| 1013 | void drm_kms_helper_poll_enable(struct drm_device *dev) |
| 1014 | { |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1015 | bool poll = false; |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 1016 | struct drm_connector *connector; |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1017 | |
Chris Wilson | e58f637 | 2010-08-20 09:13:36 +0100 | [diff] [blame] | 1018 | if (!dev->mode_config.poll_enabled || !drm_kms_helper_poll) |
| 1019 | return; |
| 1020 | |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1021 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 1022 | if (connector->polled) |
| 1023 | poll = true; |
| 1024 | } |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1025 | |
Tejun Heo | 9a919c4 | 2010-08-09 12:01:27 +0200 | [diff] [blame] | 1026 | if (poll) |
Tejun Heo | 3b07e9c | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 1027 | schedule_delayed_work(&dev->mode_config.output_poll_work, DRM_OUTPUT_POLL_PERIOD); |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1028 | } |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 1029 | EXPORT_SYMBOL(drm_kms_helper_poll_enable); |
| 1030 | |
| 1031 | void drm_kms_helper_poll_init(struct drm_device *dev) |
| 1032 | { |
Tejun Heo | 991ea75 | 2010-07-20 22:09:02 +0200 | [diff] [blame] | 1033 | INIT_DELAYED_WORK(&dev->mode_config.output_poll_work, output_poll_execute); |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 1034 | dev->mode_config.poll_enabled = true; |
| 1035 | |
| 1036 | drm_kms_helper_poll_enable(dev); |
| 1037 | } |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1038 | EXPORT_SYMBOL(drm_kms_helper_poll_init); |
| 1039 | |
| 1040 | void drm_kms_helper_poll_fini(struct drm_device *dev) |
| 1041 | { |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 1042 | drm_kms_helper_poll_disable(dev); |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1043 | } |
| 1044 | EXPORT_SYMBOL(drm_kms_helper_poll_fini); |
| 1045 | |
Daniel Vetter | 69787f7 | 2012-10-23 18:23:34 +0000 | [diff] [blame] | 1046 | void drm_helper_hpd_irq_event(struct drm_device *dev) |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1047 | { |
Daniel Vetter | 816da85 | 2012-10-23 18:23:33 +0000 | [diff] [blame] | 1048 | struct drm_connector *connector; |
| 1049 | enum drm_connector_status old_status; |
| 1050 | bool changed = false; |
| 1051 | |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1052 | if (!dev->mode_config.poll_enabled) |
| 1053 | return; |
Chris Wilson | e58f637 | 2010-08-20 09:13:36 +0100 | [diff] [blame] | 1054 | |
Daniel Vetter | 816da85 | 2012-10-23 18:23:33 +0000 | [diff] [blame] | 1055 | mutex_lock(&dev->mode_config.mutex); |
| 1056 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 1057 | |
| 1058 | /* Only handle HPD capable connectors. */ |
| 1059 | if (!(connector->polled & DRM_CONNECTOR_POLL_HPD)) |
| 1060 | continue; |
| 1061 | |
| 1062 | old_status = connector->status; |
| 1063 | |
| 1064 | connector->status = connector->funcs->detect(connector, false); |
| 1065 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %d to %d\n", |
| 1066 | connector->base.id, |
| 1067 | drm_get_connector_name(connector), |
| 1068 | old_status, connector->status); |
| 1069 | if (old_status != connector->status) |
| 1070 | changed = true; |
| 1071 | } |
| 1072 | |
| 1073 | mutex_unlock(&dev->mode_config.mutex); |
| 1074 | |
| 1075 | if (changed) |
| 1076 | drm_kms_helper_hotplug_event(dev); |
| 1077 | } |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1078 | EXPORT_SYMBOL(drm_helper_hpd_irq_event); |