Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2008 Intel Corporation |
| 3 | * 2014 Red Hat Inc. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the next |
| 13 | * paragraph) shall be included in all copies or substantial portions of the |
| 14 | * Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 22 | * IN THE SOFTWARE. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <drm/drmP.h> |
| 27 | #include "i915_drv.h" |
| 28 | #include "intel_drv.h" |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 29 | #include <drm/drm_atomic_helper.h> |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 30 | #include <drm/drm_crtc_helper.h> |
| 31 | #include <drm/drm_edid.h> |
| 32 | |
| 33 | static bool intel_dp_mst_compute_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 34 | struct intel_crtc_state *pipe_config) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 35 | { |
| 36 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 37 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 38 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Ander Conselvan de Oliveira | e75f477 | 2015-03-20 16:18:13 +0200 | [diff] [blame] | 39 | struct drm_atomic_state *state; |
| 40 | int bpp, i; |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 41 | int lane_count, slots, rate; |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 42 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Ander Conselvan de Oliveira | e75f477 | 2015-03-20 16:18:13 +0200 | [diff] [blame] | 43 | struct intel_connector *found = NULL; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 44 | int mst_pbn; |
| 45 | |
| 46 | pipe_config->dp_encoder_is_mst = true; |
| 47 | pipe_config->has_pch_encoder = false; |
| 48 | pipe_config->has_dp_encoder = true; |
| 49 | bpp = 24; |
| 50 | /* |
| 51 | * for MST we always configure max link bw - the spec doesn't |
| 52 | * seem to suggest we should do otherwise. |
| 53 | */ |
| 54 | lane_count = drm_dp_max_lane_count(intel_dp->dpcd); |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 55 | |
| 56 | rate = intel_dp_max_link_rate(intel_dp); |
| 57 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 58 | if (intel_dp->num_sink_rates) { |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 59 | intel_dp->link_bw = 0; |
| 60 | intel_dp->rate_select = intel_dp_rate_select(intel_dp, rate); |
| 61 | } else { |
| 62 | intel_dp->link_bw = drm_dp_link_rate_to_bw_code(rate); |
| 63 | intel_dp->rate_select = 0; |
| 64 | } |
| 65 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 66 | intel_dp->lane_count = lane_count; |
| 67 | |
| 68 | pipe_config->pipe_bpp = 24; |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 69 | pipe_config->port_clock = rate; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 70 | |
Ander Conselvan de Oliveira | e75f477 | 2015-03-20 16:18:13 +0200 | [diff] [blame] | 71 | state = pipe_config->base.state; |
| 72 | |
| 73 | for (i = 0; i < state->num_connector; i++) { |
| 74 | if (!state->connectors[i]) |
| 75 | continue; |
| 76 | |
| 77 | if (state->connector_states[i]->best_encoder == &encoder->base) { |
| 78 | found = to_intel_connector(state->connectors[i]); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 79 | break; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | if (!found) { |
| 84 | DRM_ERROR("can't find connector\n"); |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | mst_pbn = drm_dp_calc_pbn_mode(adjusted_mode->clock, bpp); |
| 89 | |
| 90 | pipe_config->pbn = mst_pbn; |
| 91 | slots = drm_dp_find_vcpi_slots(&intel_dp->mst_mgr, mst_pbn); |
| 92 | |
| 93 | intel_link_compute_m_n(bpp, lane_count, |
| 94 | adjusted_mode->crtc_clock, |
| 95 | pipe_config->port_clock, |
| 96 | &pipe_config->dp_m_n); |
| 97 | |
| 98 | pipe_config->dp_m_n.tu = slots; |
| 99 | return true; |
| 100 | |
| 101 | } |
| 102 | |
| 103 | static void intel_mst_disable_dp(struct intel_encoder *encoder) |
| 104 | { |
| 105 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 106 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 107 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 108 | int ret; |
| 109 | |
| 110 | DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links); |
| 111 | |
| 112 | drm_dp_mst_reset_vcpi_slots(&intel_dp->mst_mgr, intel_mst->port); |
| 113 | |
| 114 | ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr); |
| 115 | if (ret) { |
| 116 | DRM_ERROR("failed to update payload %d\n", ret); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | static void intel_mst_post_disable_dp(struct intel_encoder *encoder) |
| 121 | { |
| 122 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 123 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 124 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 125 | |
| 126 | DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links); |
| 127 | |
| 128 | /* this can fail */ |
| 129 | drm_dp_check_act_status(&intel_dp->mst_mgr); |
| 130 | /* and this can also fail */ |
| 131 | drm_dp_update_payload_part2(&intel_dp->mst_mgr); |
| 132 | |
| 133 | drm_dp_mst_deallocate_vcpi(&intel_dp->mst_mgr, intel_mst->port); |
| 134 | |
| 135 | intel_dp->active_mst_links--; |
| 136 | intel_mst->port = NULL; |
| 137 | if (intel_dp->active_mst_links == 0) { |
| 138 | intel_dig_port->base.post_disable(&intel_dig_port->base); |
| 139 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | static void intel_mst_pre_enable_dp(struct intel_encoder *encoder) |
| 144 | { |
| 145 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 146 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 147 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 148 | struct drm_device *dev = encoder->base.dev; |
| 149 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 150 | enum port port = intel_dig_port->port; |
| 151 | int ret; |
| 152 | uint32_t temp; |
Ander Conselvan de Oliveira | 9b4fd8f | 2015-04-02 14:48:01 +0300 | [diff] [blame] | 153 | struct intel_connector *found = NULL, *connector; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 154 | int slots; |
| 155 | struct drm_crtc *crtc = encoder->base.crtc; |
| 156 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 157 | |
Ander Conselvan de Oliveira | 9b4fd8f | 2015-04-02 14:48:01 +0300 | [diff] [blame] | 158 | for_each_intel_connector(dev, connector) { |
| 159 | if (connector->base.state->best_encoder == &encoder->base) { |
| 160 | found = connector; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 161 | break; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | if (!found) { |
| 166 | DRM_ERROR("can't find connector\n"); |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links); |
| 171 | intel_mst->port = found->port; |
| 172 | |
| 173 | if (intel_dp->active_mst_links == 0) { |
| 174 | enum port port = intel_ddi_get_encoder_port(encoder); |
| 175 | |
Satheeshakrishna M | 1ab2338 | 2014-08-22 09:49:06 +0530 | [diff] [blame^] | 176 | /* FIXME: add support for SKL */ |
| 177 | if (INTEL_INFO(dev)->gen < 9) |
| 178 | I915_WRITE(PORT_CLK_SEL(port), |
| 179 | intel_crtc->config->ddi_pll_sel); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 180 | |
| 181 | intel_ddi_init_dp_buf_reg(&intel_dig_port->base); |
| 182 | |
| 183 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
| 184 | |
| 185 | |
| 186 | intel_dp_start_link_train(intel_dp); |
| 187 | intel_dp_complete_link_train(intel_dp); |
| 188 | intel_dp_stop_link_train(intel_dp); |
| 189 | } |
| 190 | |
| 191 | ret = drm_dp_mst_allocate_vcpi(&intel_dp->mst_mgr, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 192 | intel_mst->port, |
| 193 | intel_crtc->config->pbn, &slots); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 194 | if (ret == false) { |
| 195 | DRM_ERROR("failed to allocate vcpi\n"); |
| 196 | return; |
| 197 | } |
| 198 | |
| 199 | |
| 200 | intel_dp->active_mst_links++; |
| 201 | temp = I915_READ(DP_TP_STATUS(port)); |
| 202 | I915_WRITE(DP_TP_STATUS(port), temp); |
| 203 | |
| 204 | ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr); |
| 205 | } |
| 206 | |
| 207 | static void intel_mst_enable_dp(struct intel_encoder *encoder) |
| 208 | { |
| 209 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 210 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 211 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 212 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 213 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 214 | enum port port = intel_dig_port->port; |
| 215 | int ret; |
| 216 | |
| 217 | DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links); |
| 218 | |
| 219 | if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_ACT_SENT), |
| 220 | 1)) |
| 221 | DRM_ERROR("Timed out waiting for ACT sent\n"); |
| 222 | |
| 223 | ret = drm_dp_check_act_status(&intel_dp->mst_mgr); |
| 224 | |
| 225 | ret = drm_dp_update_payload_part2(&intel_dp->mst_mgr); |
| 226 | } |
| 227 | |
| 228 | static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder *encoder, |
| 229 | enum pipe *pipe) |
| 230 | { |
| 231 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 232 | *pipe = intel_mst->pipe; |
| 233 | if (intel_mst->port) |
| 234 | return true; |
| 235 | return false; |
| 236 | } |
| 237 | |
| 238 | static void intel_dp_mst_enc_get_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 239 | struct intel_crtc_state *pipe_config) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 240 | { |
| 241 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 242 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 243 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
| 244 | struct drm_device *dev = encoder->base.dev; |
| 245 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 0cb09a9 | 2015-01-30 12:17:23 +0200 | [diff] [blame] | 246 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 247 | u32 temp, flags = 0; |
| 248 | |
| 249 | pipe_config->has_dp_encoder = true; |
| 250 | |
| 251 | temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
| 252 | if (temp & TRANS_DDI_PHSYNC) |
| 253 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 254 | else |
| 255 | flags |= DRM_MODE_FLAG_NHSYNC; |
| 256 | if (temp & TRANS_DDI_PVSYNC) |
| 257 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 258 | else |
| 259 | flags |= DRM_MODE_FLAG_NVSYNC; |
| 260 | |
| 261 | switch (temp & TRANS_DDI_BPC_MASK) { |
| 262 | case TRANS_DDI_BPC_6: |
| 263 | pipe_config->pipe_bpp = 18; |
| 264 | break; |
| 265 | case TRANS_DDI_BPC_8: |
| 266 | pipe_config->pipe_bpp = 24; |
| 267 | break; |
| 268 | case TRANS_DDI_BPC_10: |
| 269 | pipe_config->pipe_bpp = 30; |
| 270 | break; |
| 271 | case TRANS_DDI_BPC_12: |
| 272 | pipe_config->pipe_bpp = 36; |
| 273 | break; |
| 274 | default: |
| 275 | break; |
| 276 | } |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 277 | pipe_config->base.adjusted_mode.flags |= flags; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 278 | intel_dp_get_m_n(crtc, pipe_config); |
| 279 | |
| 280 | intel_ddi_clock_get(&intel_dig_port->base, pipe_config); |
| 281 | } |
| 282 | |
| 283 | static int intel_dp_mst_get_ddc_modes(struct drm_connector *connector) |
| 284 | { |
| 285 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 286 | struct intel_dp *intel_dp = intel_connector->mst_port; |
| 287 | struct edid *edid; |
| 288 | int ret; |
| 289 | |
| 290 | edid = drm_dp_mst_get_edid(connector, &intel_dp->mst_mgr, intel_connector->port); |
| 291 | if (!edid) |
| 292 | return 0; |
| 293 | |
| 294 | ret = intel_connector_update_modes(connector, edid); |
| 295 | kfree(edid); |
| 296 | |
| 297 | return ret; |
| 298 | } |
| 299 | |
| 300 | static enum drm_connector_status |
Daniel Vetter | f7f3d48 | 2014-10-22 11:06:44 +0200 | [diff] [blame] | 301 | intel_dp_mst_detect(struct drm_connector *connector, bool force) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 302 | { |
| 303 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 304 | struct intel_dp *intel_dp = intel_connector->mst_port; |
| 305 | |
Dave Airlie | c6a0aed | 2014-10-20 16:28:02 +1000 | [diff] [blame] | 306 | return drm_dp_mst_detect_port(connector, &intel_dp->mst_mgr, intel_connector->port); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 307 | } |
| 308 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 309 | static int |
| 310 | intel_dp_mst_set_property(struct drm_connector *connector, |
| 311 | struct drm_property *property, |
| 312 | uint64_t val) |
| 313 | { |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | static void |
| 318 | intel_dp_mst_connector_destroy(struct drm_connector *connector) |
| 319 | { |
| 320 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 321 | |
| 322 | if (!IS_ERR_OR_NULL(intel_connector->edid)) |
| 323 | kfree(intel_connector->edid); |
| 324 | |
| 325 | drm_connector_cleanup(connector); |
| 326 | kfree(connector); |
| 327 | } |
| 328 | |
| 329 | static const struct drm_connector_funcs intel_dp_mst_connector_funcs = { |
| 330 | .dpms = intel_connector_dpms, |
| 331 | .detect = intel_dp_mst_detect, |
| 332 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 333 | .set_property = intel_dp_mst_set_property, |
Matt Roper | 2545e4a | 2015-01-22 16:51:27 -0800 | [diff] [blame] | 334 | .atomic_get_property = intel_connector_atomic_get_property, |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 335 | .destroy = intel_dp_mst_connector_destroy, |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 336 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
Ander Conselvan de Oliveira | 9896972 | 2015-03-20 16:18:06 +0200 | [diff] [blame] | 337 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 338 | }; |
| 339 | |
| 340 | static int intel_dp_mst_get_modes(struct drm_connector *connector) |
| 341 | { |
| 342 | return intel_dp_mst_get_ddc_modes(connector); |
| 343 | } |
| 344 | |
| 345 | static enum drm_mode_status |
| 346 | intel_dp_mst_mode_valid(struct drm_connector *connector, |
| 347 | struct drm_display_mode *mode) |
| 348 | { |
| 349 | /* TODO - validate mode against available PBN for link */ |
| 350 | if (mode->clock < 10000) |
| 351 | return MODE_CLOCK_LOW; |
| 352 | |
| 353 | if (mode->flags & DRM_MODE_FLAG_DBLCLK) |
| 354 | return MODE_H_ILLEGAL; |
| 355 | |
| 356 | return MODE_OK; |
| 357 | } |
| 358 | |
| 359 | static struct drm_encoder *intel_mst_best_encoder(struct drm_connector *connector) |
| 360 | { |
| 361 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 362 | struct intel_dp *intel_dp = intel_connector->mst_port; |
| 363 | return &intel_dp->mst_encoders[0]->base.base; |
| 364 | } |
| 365 | |
| 366 | static const struct drm_connector_helper_funcs intel_dp_mst_connector_helper_funcs = { |
| 367 | .get_modes = intel_dp_mst_get_modes, |
| 368 | .mode_valid = intel_dp_mst_mode_valid, |
| 369 | .best_encoder = intel_mst_best_encoder, |
| 370 | }; |
| 371 | |
| 372 | static void intel_dp_mst_encoder_destroy(struct drm_encoder *encoder) |
| 373 | { |
| 374 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); |
| 375 | |
| 376 | drm_encoder_cleanup(encoder); |
| 377 | kfree(intel_mst); |
| 378 | } |
| 379 | |
| 380 | static const struct drm_encoder_funcs intel_dp_mst_enc_funcs = { |
| 381 | .destroy = intel_dp_mst_encoder_destroy, |
| 382 | }; |
| 383 | |
| 384 | static bool intel_dp_mst_get_hw_state(struct intel_connector *connector) |
| 385 | { |
| 386 | if (connector->encoder) { |
| 387 | enum pipe pipe; |
| 388 | if (!connector->encoder->get_hw_state(connector->encoder, &pipe)) |
| 389 | return false; |
| 390 | return true; |
| 391 | } |
| 392 | return false; |
| 393 | } |
| 394 | |
Chris Wilson | 7296c84 | 2014-07-22 20:10:28 +1000 | [diff] [blame] | 395 | static void intel_connector_add_to_fbdev(struct intel_connector *connector) |
| 396 | { |
| 397 | #ifdef CONFIG_DRM_I915_FBDEV |
| 398 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
| 399 | drm_fb_helper_add_one_connector(&dev_priv->fbdev->helper, &connector->base); |
| 400 | #endif |
| 401 | } |
| 402 | |
| 403 | static void intel_connector_remove_from_fbdev(struct intel_connector *connector) |
| 404 | { |
| 405 | #ifdef CONFIG_DRM_I915_FBDEV |
| 406 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
| 407 | drm_fb_helper_remove_one_connector(&dev_priv->fbdev->helper, &connector->base); |
| 408 | #endif |
| 409 | } |
| 410 | |
Thierry Reding | 12e6cec | 2014-05-13 11:38:36 +0200 | [diff] [blame] | 411 | static struct drm_connector *intel_dp_add_mst_connector(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *pathprop) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 412 | { |
| 413 | struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr); |
| 414 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 415 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 416 | struct intel_connector *intel_connector; |
| 417 | struct drm_connector *connector; |
| 418 | int i; |
| 419 | |
Ander Conselvan de Oliveira | 9bdbd0b | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 420 | intel_connector = intel_connector_alloc(); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 421 | if (!intel_connector) |
| 422 | return NULL; |
| 423 | |
| 424 | connector = &intel_connector->base; |
| 425 | drm_connector_init(dev, connector, &intel_dp_mst_connector_funcs, DRM_MODE_CONNECTOR_DisplayPort); |
| 426 | drm_connector_helper_add(connector, &intel_dp_mst_connector_helper_funcs); |
| 427 | |
| 428 | intel_connector->unregister = intel_connector_unregister; |
| 429 | intel_connector->get_hw_state = intel_dp_mst_get_hw_state; |
| 430 | intel_connector->mst_port = intel_dp; |
| 431 | intel_connector->port = port; |
| 432 | |
| 433 | for (i = PIPE_A; i <= PIPE_C; i++) { |
| 434 | drm_mode_connector_attach_encoder(&intel_connector->base, |
| 435 | &intel_dp->mst_encoders[i]->base.base); |
| 436 | } |
| 437 | intel_dp_add_properties(intel_dp, connector); |
| 438 | |
| 439 | drm_object_attach_property(&connector->base, dev->mode_config.path_property, 0); |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 440 | drm_object_attach_property(&connector->base, dev->mode_config.tile_property, 0); |
| 441 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 442 | drm_mode_connector_set_path_property(connector, pathprop); |
| 443 | drm_reinit_primary_mode_group(dev); |
| 444 | mutex_lock(&dev->mode_config.mutex); |
Chris Wilson | 7296c84 | 2014-07-22 20:10:28 +1000 | [diff] [blame] | 445 | intel_connector_add_to_fbdev(intel_connector); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 446 | mutex_unlock(&dev->mode_config.mutex); |
| 447 | drm_connector_register(&intel_connector->base); |
| 448 | return connector; |
| 449 | } |
| 450 | |
| 451 | static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr, |
| 452 | struct drm_connector *connector) |
| 453 | { |
| 454 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 455 | struct drm_device *dev = connector->dev; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 456 | /* need to nuke the connector */ |
| 457 | mutex_lock(&dev->mode_config.mutex); |
| 458 | intel_connector_dpms(connector, DRM_MODE_DPMS_OFF); |
| 459 | mutex_unlock(&dev->mode_config.mutex); |
| 460 | |
| 461 | intel_connector->unregister(intel_connector); |
| 462 | |
| 463 | mutex_lock(&dev->mode_config.mutex); |
Chris Wilson | 7296c84 | 2014-07-22 20:10:28 +1000 | [diff] [blame] | 464 | intel_connector_remove_from_fbdev(intel_connector); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 465 | drm_connector_cleanup(connector); |
| 466 | mutex_unlock(&dev->mode_config.mutex); |
| 467 | |
| 468 | drm_reinit_primary_mode_group(dev); |
| 469 | |
| 470 | kfree(intel_connector); |
| 471 | DRM_DEBUG_KMS("\n"); |
| 472 | } |
| 473 | |
| 474 | static void intel_dp_mst_hotplug(struct drm_dp_mst_topology_mgr *mgr) |
| 475 | { |
| 476 | struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr); |
| 477 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 478 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 479 | |
| 480 | drm_kms_helper_hotplug_event(dev); |
| 481 | } |
| 482 | |
| 483 | static struct drm_dp_mst_topology_cbs mst_cbs = { |
| 484 | .add_connector = intel_dp_add_mst_connector, |
| 485 | .destroy_connector = intel_dp_destroy_mst_connector, |
| 486 | .hotplug = intel_dp_mst_hotplug, |
| 487 | }; |
| 488 | |
| 489 | static struct intel_dp_mst_encoder * |
| 490 | intel_dp_create_fake_mst_encoder(struct intel_digital_port *intel_dig_port, enum pipe pipe) |
| 491 | { |
| 492 | struct intel_dp_mst_encoder *intel_mst; |
| 493 | struct intel_encoder *intel_encoder; |
| 494 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 495 | |
| 496 | intel_mst = kzalloc(sizeof(*intel_mst), GFP_KERNEL); |
| 497 | |
| 498 | if (!intel_mst) |
| 499 | return NULL; |
| 500 | |
| 501 | intel_mst->pipe = pipe; |
| 502 | intel_encoder = &intel_mst->base; |
| 503 | intel_mst->primary = intel_dig_port; |
| 504 | |
| 505 | drm_encoder_init(dev, &intel_encoder->base, &intel_dp_mst_enc_funcs, |
| 506 | DRM_MODE_ENCODER_DPMST); |
| 507 | |
| 508 | intel_encoder->type = INTEL_OUTPUT_DP_MST; |
| 509 | intel_encoder->crtc_mask = 0x7; |
| 510 | intel_encoder->cloneable = 0; |
| 511 | |
| 512 | intel_encoder->compute_config = intel_dp_mst_compute_config; |
| 513 | intel_encoder->disable = intel_mst_disable_dp; |
| 514 | intel_encoder->post_disable = intel_mst_post_disable_dp; |
| 515 | intel_encoder->pre_enable = intel_mst_pre_enable_dp; |
| 516 | intel_encoder->enable = intel_mst_enable_dp; |
| 517 | intel_encoder->get_hw_state = intel_dp_mst_enc_get_hw_state; |
| 518 | intel_encoder->get_config = intel_dp_mst_enc_get_config; |
| 519 | |
| 520 | return intel_mst; |
| 521 | |
| 522 | } |
| 523 | |
| 524 | static bool |
| 525 | intel_dp_create_fake_mst_encoders(struct intel_digital_port *intel_dig_port) |
| 526 | { |
| 527 | int i; |
| 528 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 529 | |
| 530 | for (i = PIPE_A; i <= PIPE_C; i++) |
| 531 | intel_dp->mst_encoders[i] = intel_dp_create_fake_mst_encoder(intel_dig_port, i); |
| 532 | return true; |
| 533 | } |
| 534 | |
| 535 | int |
| 536 | intel_dp_mst_encoder_init(struct intel_digital_port *intel_dig_port, int conn_base_id) |
| 537 | { |
| 538 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 539 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 540 | int ret; |
| 541 | |
| 542 | intel_dp->can_mst = true; |
| 543 | intel_dp->mst_mgr.cbs = &mst_cbs; |
| 544 | |
| 545 | /* create encoders */ |
| 546 | intel_dp_create_fake_mst_encoders(intel_dig_port); |
| 547 | ret = drm_dp_mst_topology_mgr_init(&intel_dp->mst_mgr, dev->dev, &intel_dp->aux, 16, 3, conn_base_id); |
| 548 | if (ret) { |
| 549 | intel_dp->can_mst = false; |
| 550 | return ret; |
| 551 | } |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | void |
| 556 | intel_dp_mst_encoder_cleanup(struct intel_digital_port *intel_dig_port) |
| 557 | { |
| 558 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 559 | |
| 560 | if (!intel_dp->can_mst) |
| 561 | return; |
| 562 | |
| 563 | drm_dp_mst_topology_mgr_destroy(&intel_dp->mst_mgr); |
| 564 | /* encoders will get killed by normal cleanup */ |
| 565 | } |