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" |
| 29 | #include <drm/drm_crtc_helper.h> |
| 30 | #include <drm/drm_edid.h> |
| 31 | |
| 32 | static bool intel_dp_mst_compute_config(struct intel_encoder *encoder, |
| 33 | struct intel_crtc_config *pipe_config) |
| 34 | { |
| 35 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 36 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 37 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 38 | struct drm_device *dev = encoder->base.dev; |
| 39 | int bpp; |
| 40 | int lane_count, slots; |
| 41 | struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode; |
| 42 | struct intel_connector *found = NULL, *intel_connector; |
| 43 | int mst_pbn; |
| 44 | |
| 45 | pipe_config->dp_encoder_is_mst = true; |
| 46 | pipe_config->has_pch_encoder = false; |
| 47 | pipe_config->has_dp_encoder = true; |
| 48 | bpp = 24; |
| 49 | /* |
| 50 | * for MST we always configure max link bw - the spec doesn't |
| 51 | * seem to suggest we should do otherwise. |
| 52 | */ |
| 53 | lane_count = drm_dp_max_lane_count(intel_dp->dpcd); |
| 54 | intel_dp->link_bw = intel_dp_max_link_bw(intel_dp); |
| 55 | intel_dp->lane_count = lane_count; |
| 56 | |
| 57 | pipe_config->pipe_bpp = 24; |
| 58 | pipe_config->port_clock = drm_dp_bw_code_to_link_rate(intel_dp->link_bw); |
| 59 | |
| 60 | list_for_each_entry(intel_connector, &dev->mode_config.connector_list, base.head) { |
| 61 | if (intel_connector->new_encoder == encoder) { |
| 62 | found = intel_connector; |
| 63 | break; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | if (!found) { |
| 68 | DRM_ERROR("can't find connector\n"); |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | mst_pbn = drm_dp_calc_pbn_mode(adjusted_mode->clock, bpp); |
| 73 | |
| 74 | pipe_config->pbn = mst_pbn; |
| 75 | slots = drm_dp_find_vcpi_slots(&intel_dp->mst_mgr, mst_pbn); |
| 76 | |
| 77 | intel_link_compute_m_n(bpp, lane_count, |
| 78 | adjusted_mode->crtc_clock, |
| 79 | pipe_config->port_clock, |
| 80 | &pipe_config->dp_m_n); |
| 81 | |
| 82 | pipe_config->dp_m_n.tu = slots; |
| 83 | return true; |
| 84 | |
| 85 | } |
| 86 | |
| 87 | static void intel_mst_disable_dp(struct intel_encoder *encoder) |
| 88 | { |
| 89 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 90 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 91 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 92 | int ret; |
| 93 | |
| 94 | DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links); |
| 95 | |
| 96 | drm_dp_mst_reset_vcpi_slots(&intel_dp->mst_mgr, intel_mst->port); |
| 97 | |
| 98 | ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr); |
| 99 | if (ret) { |
| 100 | DRM_ERROR("failed to update payload %d\n", ret); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | static void intel_mst_post_disable_dp(struct intel_encoder *encoder) |
| 105 | { |
| 106 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 107 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 108 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 109 | |
| 110 | DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links); |
| 111 | |
| 112 | /* this can fail */ |
| 113 | drm_dp_check_act_status(&intel_dp->mst_mgr); |
| 114 | /* and this can also fail */ |
| 115 | drm_dp_update_payload_part2(&intel_dp->mst_mgr); |
| 116 | |
| 117 | drm_dp_mst_deallocate_vcpi(&intel_dp->mst_mgr, intel_mst->port); |
| 118 | |
| 119 | intel_dp->active_mst_links--; |
| 120 | intel_mst->port = NULL; |
| 121 | if (intel_dp->active_mst_links == 0) { |
| 122 | intel_dig_port->base.post_disable(&intel_dig_port->base); |
| 123 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | static void intel_mst_pre_enable_dp(struct intel_encoder *encoder) |
| 128 | { |
| 129 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 130 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 131 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 132 | struct drm_device *dev = encoder->base.dev; |
| 133 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 134 | enum port port = intel_dig_port->port; |
| 135 | int ret; |
| 136 | uint32_t temp; |
| 137 | struct intel_connector *found = NULL, *intel_connector; |
| 138 | int slots; |
| 139 | struct drm_crtc *crtc = encoder->base.crtc; |
| 140 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 141 | |
| 142 | list_for_each_entry(intel_connector, &dev->mode_config.connector_list, base.head) { |
| 143 | if (intel_connector->new_encoder == encoder) { |
| 144 | found = intel_connector; |
| 145 | break; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | if (!found) { |
| 150 | DRM_ERROR("can't find connector\n"); |
| 151 | return; |
| 152 | } |
| 153 | |
| 154 | DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links); |
| 155 | intel_mst->port = found->port; |
| 156 | |
| 157 | if (intel_dp->active_mst_links == 0) { |
| 158 | enum port port = intel_ddi_get_encoder_port(encoder); |
| 159 | |
| 160 | I915_WRITE(PORT_CLK_SEL(port), intel_crtc->config.ddi_pll_sel); |
| 161 | |
| 162 | intel_ddi_init_dp_buf_reg(&intel_dig_port->base); |
| 163 | |
| 164 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
| 165 | |
| 166 | |
| 167 | intel_dp_start_link_train(intel_dp); |
| 168 | intel_dp_complete_link_train(intel_dp); |
| 169 | intel_dp_stop_link_train(intel_dp); |
| 170 | } |
| 171 | |
| 172 | ret = drm_dp_mst_allocate_vcpi(&intel_dp->mst_mgr, |
| 173 | intel_mst->port, intel_crtc->config.pbn, &slots); |
| 174 | if (ret == false) { |
| 175 | DRM_ERROR("failed to allocate vcpi\n"); |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | |
| 180 | intel_dp->active_mst_links++; |
| 181 | temp = I915_READ(DP_TP_STATUS(port)); |
| 182 | I915_WRITE(DP_TP_STATUS(port), temp); |
| 183 | |
| 184 | ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr); |
| 185 | } |
| 186 | |
| 187 | static void intel_mst_enable_dp(struct intel_encoder *encoder) |
| 188 | { |
| 189 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 190 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 191 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 192 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 193 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 194 | enum port port = intel_dig_port->port; |
| 195 | int ret; |
| 196 | |
| 197 | DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links); |
| 198 | |
| 199 | if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_ACT_SENT), |
| 200 | 1)) |
| 201 | DRM_ERROR("Timed out waiting for ACT sent\n"); |
| 202 | |
| 203 | ret = drm_dp_check_act_status(&intel_dp->mst_mgr); |
| 204 | |
| 205 | ret = drm_dp_update_payload_part2(&intel_dp->mst_mgr); |
| 206 | } |
| 207 | |
| 208 | static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder *encoder, |
| 209 | enum pipe *pipe) |
| 210 | { |
| 211 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 212 | *pipe = intel_mst->pipe; |
| 213 | if (intel_mst->port) |
| 214 | return true; |
| 215 | return false; |
| 216 | } |
| 217 | |
| 218 | static void intel_dp_mst_enc_get_config(struct intel_encoder *encoder, |
| 219 | struct intel_crtc_config *pipe_config) |
| 220 | { |
| 221 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 222 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 223 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
| 224 | struct drm_device *dev = encoder->base.dev; |
| 225 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 226 | enum transcoder cpu_transcoder = crtc->config.cpu_transcoder; |
| 227 | u32 temp, flags = 0; |
| 228 | |
| 229 | pipe_config->has_dp_encoder = true; |
| 230 | |
| 231 | temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
| 232 | if (temp & TRANS_DDI_PHSYNC) |
| 233 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 234 | else |
| 235 | flags |= DRM_MODE_FLAG_NHSYNC; |
| 236 | if (temp & TRANS_DDI_PVSYNC) |
| 237 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 238 | else |
| 239 | flags |= DRM_MODE_FLAG_NVSYNC; |
| 240 | |
| 241 | switch (temp & TRANS_DDI_BPC_MASK) { |
| 242 | case TRANS_DDI_BPC_6: |
| 243 | pipe_config->pipe_bpp = 18; |
| 244 | break; |
| 245 | case TRANS_DDI_BPC_8: |
| 246 | pipe_config->pipe_bpp = 24; |
| 247 | break; |
| 248 | case TRANS_DDI_BPC_10: |
| 249 | pipe_config->pipe_bpp = 30; |
| 250 | break; |
| 251 | case TRANS_DDI_BPC_12: |
| 252 | pipe_config->pipe_bpp = 36; |
| 253 | break; |
| 254 | default: |
| 255 | break; |
| 256 | } |
| 257 | pipe_config->adjusted_mode.flags |= flags; |
| 258 | intel_dp_get_m_n(crtc, pipe_config); |
| 259 | |
| 260 | intel_ddi_clock_get(&intel_dig_port->base, pipe_config); |
| 261 | } |
| 262 | |
| 263 | static int intel_dp_mst_get_ddc_modes(struct drm_connector *connector) |
| 264 | { |
| 265 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 266 | struct intel_dp *intel_dp = intel_connector->mst_port; |
| 267 | struct edid *edid; |
| 268 | int ret; |
| 269 | |
| 270 | edid = drm_dp_mst_get_edid(connector, &intel_dp->mst_mgr, intel_connector->port); |
| 271 | if (!edid) |
| 272 | return 0; |
| 273 | |
| 274 | ret = intel_connector_update_modes(connector, edid); |
| 275 | kfree(edid); |
| 276 | |
| 277 | return ret; |
| 278 | } |
| 279 | |
| 280 | static enum drm_connector_status |
Daniel Vetter | f7f3d48 | 2014-10-22 11:06:44 +0200 | [diff] [blame] | 281 | intel_dp_mst_detect(struct drm_connector *connector, bool force) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 282 | { |
| 283 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 284 | struct intel_dp *intel_dp = intel_connector->mst_port; |
| 285 | |
| 286 | return drm_dp_mst_detect_port(&intel_dp->mst_mgr, intel_connector->port); |
| 287 | } |
| 288 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 289 | static int |
| 290 | intel_dp_mst_set_property(struct drm_connector *connector, |
| 291 | struct drm_property *property, |
| 292 | uint64_t val) |
| 293 | { |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | static void |
| 298 | intel_dp_mst_connector_destroy(struct drm_connector *connector) |
| 299 | { |
| 300 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 301 | |
| 302 | if (!IS_ERR_OR_NULL(intel_connector->edid)) |
| 303 | kfree(intel_connector->edid); |
| 304 | |
| 305 | drm_connector_cleanup(connector); |
| 306 | kfree(connector); |
| 307 | } |
| 308 | |
| 309 | static const struct drm_connector_funcs intel_dp_mst_connector_funcs = { |
| 310 | .dpms = intel_connector_dpms, |
| 311 | .detect = intel_dp_mst_detect, |
| 312 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 313 | .set_property = intel_dp_mst_set_property, |
| 314 | .destroy = intel_dp_mst_connector_destroy, |
| 315 | }; |
| 316 | |
| 317 | static int intel_dp_mst_get_modes(struct drm_connector *connector) |
| 318 | { |
| 319 | return intel_dp_mst_get_ddc_modes(connector); |
| 320 | } |
| 321 | |
| 322 | static enum drm_mode_status |
| 323 | intel_dp_mst_mode_valid(struct drm_connector *connector, |
| 324 | struct drm_display_mode *mode) |
| 325 | { |
| 326 | /* TODO - validate mode against available PBN for link */ |
| 327 | if (mode->clock < 10000) |
| 328 | return MODE_CLOCK_LOW; |
| 329 | |
| 330 | if (mode->flags & DRM_MODE_FLAG_DBLCLK) |
| 331 | return MODE_H_ILLEGAL; |
| 332 | |
| 333 | return MODE_OK; |
| 334 | } |
| 335 | |
| 336 | static struct drm_encoder *intel_mst_best_encoder(struct drm_connector *connector) |
| 337 | { |
| 338 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 339 | struct intel_dp *intel_dp = intel_connector->mst_port; |
| 340 | return &intel_dp->mst_encoders[0]->base.base; |
| 341 | } |
| 342 | |
| 343 | static const struct drm_connector_helper_funcs intel_dp_mst_connector_helper_funcs = { |
| 344 | .get_modes = intel_dp_mst_get_modes, |
| 345 | .mode_valid = intel_dp_mst_mode_valid, |
| 346 | .best_encoder = intel_mst_best_encoder, |
| 347 | }; |
| 348 | |
| 349 | static void intel_dp_mst_encoder_destroy(struct drm_encoder *encoder) |
| 350 | { |
| 351 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); |
| 352 | |
| 353 | drm_encoder_cleanup(encoder); |
| 354 | kfree(intel_mst); |
| 355 | } |
| 356 | |
| 357 | static const struct drm_encoder_funcs intel_dp_mst_enc_funcs = { |
| 358 | .destroy = intel_dp_mst_encoder_destroy, |
| 359 | }; |
| 360 | |
| 361 | static bool intel_dp_mst_get_hw_state(struct intel_connector *connector) |
| 362 | { |
| 363 | if (connector->encoder) { |
| 364 | enum pipe pipe; |
| 365 | if (!connector->encoder->get_hw_state(connector->encoder, &pipe)) |
| 366 | return false; |
| 367 | return true; |
| 368 | } |
| 369 | return false; |
| 370 | } |
| 371 | |
Chris Wilson | 7296c84 | 2014-07-22 20:10:28 +1000 | [diff] [blame] | 372 | static void intel_connector_add_to_fbdev(struct intel_connector *connector) |
| 373 | { |
| 374 | #ifdef CONFIG_DRM_I915_FBDEV |
| 375 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
| 376 | drm_fb_helper_add_one_connector(&dev_priv->fbdev->helper, &connector->base); |
| 377 | #endif |
| 378 | } |
| 379 | |
| 380 | static void intel_connector_remove_from_fbdev(struct intel_connector *connector) |
| 381 | { |
| 382 | #ifdef CONFIG_DRM_I915_FBDEV |
| 383 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
| 384 | drm_fb_helper_remove_one_connector(&dev_priv->fbdev->helper, &connector->base); |
| 385 | #endif |
| 386 | } |
| 387 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 388 | static struct drm_connector *intel_dp_add_mst_connector(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, char *pathprop) |
| 389 | { |
| 390 | struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr); |
| 391 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 392 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 393 | struct intel_connector *intel_connector; |
| 394 | struct drm_connector *connector; |
| 395 | int i; |
| 396 | |
| 397 | intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL); |
| 398 | if (!intel_connector) |
| 399 | return NULL; |
| 400 | |
| 401 | connector = &intel_connector->base; |
| 402 | drm_connector_init(dev, connector, &intel_dp_mst_connector_funcs, DRM_MODE_CONNECTOR_DisplayPort); |
| 403 | drm_connector_helper_add(connector, &intel_dp_mst_connector_helper_funcs); |
| 404 | |
| 405 | intel_connector->unregister = intel_connector_unregister; |
| 406 | intel_connector->get_hw_state = intel_dp_mst_get_hw_state; |
| 407 | intel_connector->mst_port = intel_dp; |
| 408 | intel_connector->port = port; |
| 409 | |
| 410 | for (i = PIPE_A; i <= PIPE_C; i++) { |
| 411 | drm_mode_connector_attach_encoder(&intel_connector->base, |
| 412 | &intel_dp->mst_encoders[i]->base.base); |
| 413 | } |
| 414 | intel_dp_add_properties(intel_dp, connector); |
| 415 | |
| 416 | drm_object_attach_property(&connector->base, dev->mode_config.path_property, 0); |
| 417 | drm_mode_connector_set_path_property(connector, pathprop); |
| 418 | drm_reinit_primary_mode_group(dev); |
| 419 | mutex_lock(&dev->mode_config.mutex); |
Chris Wilson | 7296c84 | 2014-07-22 20:10:28 +1000 | [diff] [blame] | 420 | intel_connector_add_to_fbdev(intel_connector); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 421 | mutex_unlock(&dev->mode_config.mutex); |
| 422 | drm_connector_register(&intel_connector->base); |
| 423 | return connector; |
| 424 | } |
| 425 | |
| 426 | static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr, |
| 427 | struct drm_connector *connector) |
| 428 | { |
| 429 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 430 | struct drm_device *dev = connector->dev; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 431 | /* need to nuke the connector */ |
| 432 | mutex_lock(&dev->mode_config.mutex); |
| 433 | intel_connector_dpms(connector, DRM_MODE_DPMS_OFF); |
| 434 | mutex_unlock(&dev->mode_config.mutex); |
| 435 | |
| 436 | intel_connector->unregister(intel_connector); |
| 437 | |
| 438 | mutex_lock(&dev->mode_config.mutex); |
Chris Wilson | 7296c84 | 2014-07-22 20:10:28 +1000 | [diff] [blame] | 439 | intel_connector_remove_from_fbdev(intel_connector); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 440 | drm_connector_cleanup(connector); |
| 441 | mutex_unlock(&dev->mode_config.mutex); |
| 442 | |
| 443 | drm_reinit_primary_mode_group(dev); |
| 444 | |
| 445 | kfree(intel_connector); |
| 446 | DRM_DEBUG_KMS("\n"); |
| 447 | } |
| 448 | |
| 449 | static void intel_dp_mst_hotplug(struct drm_dp_mst_topology_mgr *mgr) |
| 450 | { |
| 451 | struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr); |
| 452 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 453 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 454 | |
| 455 | drm_kms_helper_hotplug_event(dev); |
| 456 | } |
| 457 | |
| 458 | static struct drm_dp_mst_topology_cbs mst_cbs = { |
| 459 | .add_connector = intel_dp_add_mst_connector, |
| 460 | .destroy_connector = intel_dp_destroy_mst_connector, |
| 461 | .hotplug = intel_dp_mst_hotplug, |
| 462 | }; |
| 463 | |
| 464 | static struct intel_dp_mst_encoder * |
| 465 | intel_dp_create_fake_mst_encoder(struct intel_digital_port *intel_dig_port, enum pipe pipe) |
| 466 | { |
| 467 | struct intel_dp_mst_encoder *intel_mst; |
| 468 | struct intel_encoder *intel_encoder; |
| 469 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 470 | |
| 471 | intel_mst = kzalloc(sizeof(*intel_mst), GFP_KERNEL); |
| 472 | |
| 473 | if (!intel_mst) |
| 474 | return NULL; |
| 475 | |
| 476 | intel_mst->pipe = pipe; |
| 477 | intel_encoder = &intel_mst->base; |
| 478 | intel_mst->primary = intel_dig_port; |
| 479 | |
| 480 | drm_encoder_init(dev, &intel_encoder->base, &intel_dp_mst_enc_funcs, |
| 481 | DRM_MODE_ENCODER_DPMST); |
| 482 | |
| 483 | intel_encoder->type = INTEL_OUTPUT_DP_MST; |
| 484 | intel_encoder->crtc_mask = 0x7; |
| 485 | intel_encoder->cloneable = 0; |
| 486 | |
| 487 | intel_encoder->compute_config = intel_dp_mst_compute_config; |
| 488 | intel_encoder->disable = intel_mst_disable_dp; |
| 489 | intel_encoder->post_disable = intel_mst_post_disable_dp; |
| 490 | intel_encoder->pre_enable = intel_mst_pre_enable_dp; |
| 491 | intel_encoder->enable = intel_mst_enable_dp; |
| 492 | intel_encoder->get_hw_state = intel_dp_mst_enc_get_hw_state; |
| 493 | intel_encoder->get_config = intel_dp_mst_enc_get_config; |
| 494 | |
| 495 | return intel_mst; |
| 496 | |
| 497 | } |
| 498 | |
| 499 | static bool |
| 500 | intel_dp_create_fake_mst_encoders(struct intel_digital_port *intel_dig_port) |
| 501 | { |
| 502 | int i; |
| 503 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 504 | |
| 505 | for (i = PIPE_A; i <= PIPE_C; i++) |
| 506 | intel_dp->mst_encoders[i] = intel_dp_create_fake_mst_encoder(intel_dig_port, i); |
| 507 | return true; |
| 508 | } |
| 509 | |
| 510 | int |
| 511 | intel_dp_mst_encoder_init(struct intel_digital_port *intel_dig_port, int conn_base_id) |
| 512 | { |
| 513 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 514 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 515 | int ret; |
| 516 | |
| 517 | intel_dp->can_mst = true; |
| 518 | intel_dp->mst_mgr.cbs = &mst_cbs; |
| 519 | |
| 520 | /* create encoders */ |
| 521 | intel_dp_create_fake_mst_encoders(intel_dig_port); |
| 522 | ret = drm_dp_mst_topology_mgr_init(&intel_dp->mst_mgr, dev->dev, &intel_dp->aux, 16, 3, conn_base_id); |
| 523 | if (ret) { |
| 524 | intel_dp->can_mst = false; |
| 525 | return ret; |
| 526 | } |
| 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | void |
| 531 | intel_dp_mst_encoder_cleanup(struct intel_digital_port *intel_dig_port) |
| 532 | { |
| 533 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 534 | |
| 535 | if (!intel_dp->can_mst) |
| 536 | return; |
| 537 | |
| 538 | drm_dp_mst_topology_mgr_destroy(&intel_dp->mst_mgr); |
| 539 | /* encoders will get killed by normal cleanup */ |
| 540 | } |