linux/drivers/gpu/drm/i915/intel_dp_mst.c
<<
>>
Prefs
   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_atomic_helper.h>
  30#include <drm/drm_crtc_helper.h>
  31#include <drm/drm_edid.h>
  32
  33static bool intel_dp_mst_compute_config(struct intel_encoder *encoder,
  34                                        struct intel_crtc_state *pipe_config,
  35                                        struct drm_connector_state *conn_state)
  36{
  37        struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
  38        struct intel_digital_port *intel_dig_port = intel_mst->primary;
  39        struct intel_dp *intel_dp = &intel_dig_port->dp;
  40        struct intel_connector *connector =
  41                to_intel_connector(conn_state->connector);
  42        struct drm_atomic_state *state = pipe_config->base.state;
  43        int bpp;
  44        int lane_count, slots;
  45        const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  46        int mst_pbn;
  47        bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc,
  48                                           DP_DPCD_QUIRK_LIMITED_M_N);
  49
  50        pipe_config->has_pch_encoder = false;
  51        bpp = 24;
  52        if (intel_dp->compliance.test_data.bpc) {
  53                bpp = intel_dp->compliance.test_data.bpc * 3;
  54                DRM_DEBUG_KMS("Setting pipe bpp to %d\n",
  55                              bpp);
  56        }
  57        /*
  58         * for MST we always configure max link bw - the spec doesn't
  59         * seem to suggest we should do otherwise.
  60         */
  61        lane_count = intel_dp_max_lane_count(intel_dp);
  62
  63        pipe_config->lane_count = lane_count;
  64
  65        pipe_config->pipe_bpp = bpp;
  66
  67        pipe_config->port_clock = intel_dp_max_link_rate(intel_dp);
  68
  69        if (drm_dp_mst_port_has_audio(&intel_dp->mst_mgr, connector->port))
  70                pipe_config->has_audio = true;
  71
  72        mst_pbn = drm_dp_calc_pbn_mode(adjusted_mode->crtc_clock, bpp);
  73        pipe_config->pbn = mst_pbn;
  74
  75        slots = drm_dp_atomic_find_vcpi_slots(state, &intel_dp->mst_mgr,
  76                                              connector->port, mst_pbn);
  77        if (slots < 0) {
  78                DRM_DEBUG_KMS("failed finding vcpi slots:%d\n", slots);
  79                return false;
  80        }
  81
  82        intel_link_compute_m_n(bpp, lane_count,
  83                               adjusted_mode->crtc_clock,
  84                               pipe_config->port_clock,
  85                               &pipe_config->dp_m_n,
  86                               reduce_m_n);
  87
  88        pipe_config->dp_m_n.tu = slots;
  89
  90        return true;
  91}
  92
  93static int intel_dp_mst_atomic_check(struct drm_connector *connector,
  94                struct drm_connector_state *new_conn_state)
  95{
  96        struct drm_atomic_state *state = new_conn_state->state;
  97        struct drm_connector_state *old_conn_state;
  98        struct drm_crtc *old_crtc;
  99        struct drm_crtc_state *crtc_state;
 100        int slots, ret = 0;
 101
 102        old_conn_state = drm_atomic_get_old_connector_state(state, connector);
 103        old_crtc = old_conn_state->crtc;
 104        if (!old_crtc)
 105                return ret;
 106
 107        crtc_state = drm_atomic_get_new_crtc_state(state, old_crtc);
 108        slots = to_intel_crtc_state(crtc_state)->dp_m_n.tu;
 109        if (drm_atomic_crtc_needs_modeset(crtc_state) && slots > 0) {
 110                struct drm_dp_mst_topology_mgr *mgr;
 111                struct drm_encoder *old_encoder;
 112
 113                old_encoder = old_conn_state->best_encoder;
 114                mgr = &enc_to_mst(old_encoder)->primary->dp.mst_mgr;
 115
 116                ret = drm_dp_atomic_release_vcpi_slots(state, mgr, slots);
 117                if (ret)
 118                        DRM_DEBUG_KMS("failed releasing %d vcpi slots:%d\n", slots, ret);
 119                else
 120                        to_intel_crtc_state(crtc_state)->dp_m_n.tu = 0;
 121        }
 122        return ret;
 123}
 124
 125static void intel_mst_disable_dp(struct intel_encoder *encoder,
 126                                 struct intel_crtc_state *old_crtc_state,
 127                                 struct drm_connector_state *old_conn_state)
 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 intel_connector *connector =
 133                to_intel_connector(old_conn_state->connector);
 134        int ret;
 135
 136        DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
 137
 138        drm_dp_mst_reset_vcpi_slots(&intel_dp->mst_mgr, connector->port);
 139
 140        ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
 141        if (ret) {
 142                DRM_ERROR("failed to update payload %d\n", ret);
 143        }
 144        if (old_crtc_state->has_audio)
 145                intel_audio_codec_disable(encoder);
 146}
 147
 148static void intel_mst_post_disable_dp(struct intel_encoder *encoder,
 149                                      struct intel_crtc_state *old_crtc_state,
 150                                      struct drm_connector_state *old_conn_state)
 151{
 152        struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
 153        struct intel_digital_port *intel_dig_port = intel_mst->primary;
 154        struct intel_dp *intel_dp = &intel_dig_port->dp;
 155        struct intel_connector *connector =
 156                to_intel_connector(old_conn_state->connector);
 157
 158        DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
 159
 160        /* this can fail */
 161        drm_dp_check_act_status(&intel_dp->mst_mgr);
 162        /* and this can also fail */
 163        drm_dp_update_payload_part2(&intel_dp->mst_mgr);
 164
 165        drm_dp_mst_deallocate_vcpi(&intel_dp->mst_mgr, connector->port);
 166
 167        intel_dp->active_mst_links--;
 168
 169        intel_mst->connector = NULL;
 170        if (intel_dp->active_mst_links == 0) {
 171                intel_dig_port->base.post_disable(&intel_dig_port->base,
 172                                                  NULL, NULL);
 173
 174                intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
 175        }
 176}
 177
 178static void intel_mst_pre_enable_dp(struct intel_encoder *encoder,
 179                                    struct intel_crtc_state *pipe_config,
 180                                    struct drm_connector_state *conn_state)
 181{
 182        struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
 183        struct intel_digital_port *intel_dig_port = intel_mst->primary;
 184        struct intel_dp *intel_dp = &intel_dig_port->dp;
 185        struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
 186        enum port port = intel_dig_port->port;
 187        struct intel_connector *connector =
 188                to_intel_connector(conn_state->connector);
 189        int ret;
 190        uint32_t temp;
 191
 192        /* MST encoders are bound to a crtc, not to a connector,
 193         * force the mapping here for get_hw_state.
 194         */
 195        connector->encoder = encoder;
 196        intel_mst->connector = connector;
 197
 198        DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
 199
 200        if (intel_dp->active_mst_links == 0)
 201                intel_dig_port->base.pre_enable(&intel_dig_port->base,
 202                                                pipe_config, NULL);
 203
 204        ret = drm_dp_mst_allocate_vcpi(&intel_dp->mst_mgr,
 205                                       connector->port,
 206                                       pipe_config->pbn,
 207                                       pipe_config->dp_m_n.tu);
 208        if (ret == false) {
 209                DRM_ERROR("failed to allocate vcpi\n");
 210                return;
 211        }
 212
 213
 214        intel_dp->active_mst_links++;
 215        temp = I915_READ(DP_TP_STATUS(port));
 216        I915_WRITE(DP_TP_STATUS(port), temp);
 217
 218        ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
 219}
 220
 221static void intel_mst_enable_dp(struct intel_encoder *encoder,
 222                                struct intel_crtc_state *pipe_config,
 223                                struct drm_connector_state *conn_state)
 224{
 225        struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
 226        struct intel_digital_port *intel_dig_port = intel_mst->primary;
 227        struct intel_dp *intel_dp = &intel_dig_port->dp;
 228        struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
 229        enum port port = intel_dig_port->port;
 230        int ret;
 231
 232        DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
 233
 234        if (intel_wait_for_register(dev_priv,
 235                                    DP_TP_STATUS(port),
 236                                    DP_TP_STATUS_ACT_SENT,
 237                                    DP_TP_STATUS_ACT_SENT,
 238                                    1))
 239                DRM_ERROR("Timed out waiting for ACT sent\n");
 240
 241        ret = drm_dp_check_act_status(&intel_dp->mst_mgr);
 242
 243        ret = drm_dp_update_payload_part2(&intel_dp->mst_mgr);
 244        if (pipe_config->has_audio)
 245                intel_audio_codec_enable(encoder, pipe_config, conn_state);
 246}
 247
 248static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder *encoder,
 249                                      enum pipe *pipe)
 250{
 251        struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
 252        *pipe = intel_mst->pipe;
 253        if (intel_mst->connector)
 254                return true;
 255        return false;
 256}
 257
 258static void intel_dp_mst_enc_get_config(struct intel_encoder *encoder,
 259                                        struct intel_crtc_state *pipe_config)
 260{
 261        struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
 262        struct intel_digital_port *intel_dig_port = intel_mst->primary;
 263        struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
 264        struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
 265        enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
 266        u32 temp, flags = 0;
 267
 268        pipe_config->has_audio =
 269                intel_ddi_is_audio_enabled(dev_priv, crtc);
 270
 271        temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
 272        if (temp & TRANS_DDI_PHSYNC)
 273                flags |= DRM_MODE_FLAG_PHSYNC;
 274        else
 275                flags |= DRM_MODE_FLAG_NHSYNC;
 276        if (temp & TRANS_DDI_PVSYNC)
 277                flags |= DRM_MODE_FLAG_PVSYNC;
 278        else
 279                flags |= DRM_MODE_FLAG_NVSYNC;
 280
 281        switch (temp & TRANS_DDI_BPC_MASK) {
 282        case TRANS_DDI_BPC_6:
 283                pipe_config->pipe_bpp = 18;
 284                break;
 285        case TRANS_DDI_BPC_8:
 286                pipe_config->pipe_bpp = 24;
 287                break;
 288        case TRANS_DDI_BPC_10:
 289                pipe_config->pipe_bpp = 30;
 290                break;
 291        case TRANS_DDI_BPC_12:
 292                pipe_config->pipe_bpp = 36;
 293                break;
 294        default:
 295                break;
 296        }
 297        pipe_config->base.adjusted_mode.flags |= flags;
 298
 299        pipe_config->lane_count =
 300                ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
 301
 302        intel_dp_get_m_n(crtc, pipe_config);
 303
 304        intel_ddi_clock_get(&intel_dig_port->base, pipe_config);
 305}
 306
 307static int intel_dp_mst_get_ddc_modes(struct drm_connector *connector)
 308{
 309        struct intel_connector *intel_connector = to_intel_connector(connector);
 310        struct intel_dp *intel_dp = intel_connector->mst_port;
 311        struct edid *edid;
 312        int ret;
 313
 314        if (!intel_dp) {
 315                return intel_connector_update_modes(connector, NULL);
 316        }
 317
 318        edid = drm_dp_mst_get_edid(connector, &intel_dp->mst_mgr, intel_connector->port);
 319        ret = intel_connector_update_modes(connector, edid);
 320        kfree(edid);
 321
 322        return ret;
 323}
 324
 325static enum drm_connector_status
 326intel_dp_mst_detect(struct drm_connector *connector, bool force)
 327{
 328        struct intel_connector *intel_connector = to_intel_connector(connector);
 329        struct intel_dp *intel_dp = intel_connector->mst_port;
 330
 331        if (!intel_dp)
 332                return connector_status_disconnected;
 333        return drm_dp_mst_detect_port(connector, &intel_dp->mst_mgr, intel_connector->port);
 334}
 335
 336static void
 337intel_dp_mst_connector_destroy(struct drm_connector *connector)
 338{
 339        struct intel_connector *intel_connector = to_intel_connector(connector);
 340
 341        if (!IS_ERR_OR_NULL(intel_connector->edid))
 342                kfree(intel_connector->edid);
 343
 344        drm_connector_cleanup(connector);
 345        kfree(connector);
 346}
 347
 348static const struct drm_connector_funcs intel_dp_mst_connector_funcs = {
 349        .detect = intel_dp_mst_detect,
 350        .fill_modes = drm_helper_probe_single_connector_modes,
 351        .late_register = intel_connector_register,
 352        .early_unregister = intel_connector_unregister,
 353        .destroy = intel_dp_mst_connector_destroy,
 354        .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
 355        .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
 356};
 357
 358static int intel_dp_mst_get_modes(struct drm_connector *connector)
 359{
 360        return intel_dp_mst_get_ddc_modes(connector);
 361}
 362
 363static enum drm_mode_status
 364intel_dp_mst_mode_valid(struct drm_connector *connector,
 365                        struct drm_display_mode *mode)
 366{
 367        struct intel_connector *intel_connector = to_intel_connector(connector);
 368        struct intel_dp *intel_dp = intel_connector->mst_port;
 369        int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
 370        int bpp = 24; /* MST uses fixed bpp */
 371        int max_rate, mode_rate, max_lanes, max_link_clock;
 372
 373        if (!intel_dp)
 374                return MODE_ERROR;
 375
 376        max_link_clock = intel_dp_max_link_rate(intel_dp);
 377        max_lanes = intel_dp_max_lane_count(intel_dp);
 378
 379        max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
 380        mode_rate = intel_dp_link_required(mode->clock, bpp);
 381
 382        /* TODO - validate mode against available PBN for link */
 383        if (mode->clock < 10000)
 384                return MODE_CLOCK_LOW;
 385
 386        if (mode->flags & DRM_MODE_FLAG_DBLCLK)
 387                return MODE_H_ILLEGAL;
 388
 389        if (mode_rate > max_rate || mode->clock > max_dotclk)
 390                return MODE_CLOCK_HIGH;
 391
 392        return MODE_OK;
 393}
 394
 395static struct drm_encoder *intel_mst_atomic_best_encoder(struct drm_connector *connector,
 396                                                         struct drm_connector_state *state)
 397{
 398        struct intel_connector *intel_connector = to_intel_connector(connector);
 399        struct intel_dp *intel_dp = intel_connector->mst_port;
 400        struct intel_crtc *crtc = to_intel_crtc(state->crtc);
 401
 402        if (!intel_dp)
 403                return NULL;
 404        return &intel_dp->mst_encoders[crtc->pipe]->base.base;
 405}
 406
 407static struct drm_encoder *intel_mst_best_encoder(struct drm_connector *connector)
 408{
 409        struct intel_connector *intel_connector = to_intel_connector(connector);
 410        struct intel_dp *intel_dp = intel_connector->mst_port;
 411        if (!intel_dp)
 412                return NULL;
 413        return &intel_dp->mst_encoders[0]->base.base;
 414}
 415
 416static const struct drm_connector_helper_funcs intel_dp_mst_connector_helper_funcs = {
 417        .get_modes = intel_dp_mst_get_modes,
 418        .mode_valid = intel_dp_mst_mode_valid,
 419        .atomic_best_encoder = intel_mst_atomic_best_encoder,
 420        .best_encoder = intel_mst_best_encoder,
 421        .atomic_check = intel_dp_mst_atomic_check,
 422};
 423
 424static void intel_dp_mst_encoder_destroy(struct drm_encoder *encoder)
 425{
 426        struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder);
 427
 428        drm_encoder_cleanup(encoder);
 429        kfree(intel_mst);
 430}
 431
 432static const struct drm_encoder_funcs intel_dp_mst_enc_funcs = {
 433        .destroy = intel_dp_mst_encoder_destroy,
 434};
 435
 436static bool intel_dp_mst_get_hw_state(struct intel_connector *connector)
 437{
 438        if (connector->encoder && connector->base.state->crtc) {
 439                enum pipe pipe;
 440                if (!connector->encoder->get_hw_state(connector->encoder, &pipe))
 441                        return false;
 442                return true;
 443        }
 444        return false;
 445}
 446
 447static struct drm_connector *intel_dp_add_mst_connector(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *pathprop)
 448{
 449        struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
 450        struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
 451        struct drm_device *dev = intel_dig_port->base.base.dev;
 452        struct intel_connector *intel_connector;
 453        struct drm_connector *connector;
 454        int i;
 455
 456        intel_connector = intel_connector_alloc();
 457        if (!intel_connector)
 458                return NULL;
 459
 460        connector = &intel_connector->base;
 461        drm_connector_init(dev, connector, &intel_dp_mst_connector_funcs, DRM_MODE_CONNECTOR_DisplayPort);
 462        drm_connector_helper_add(connector, &intel_dp_mst_connector_helper_funcs);
 463
 464        intel_connector->get_hw_state = intel_dp_mst_get_hw_state;
 465        intel_connector->mst_port = intel_dp;
 466        intel_connector->port = port;
 467
 468        for (i = PIPE_A; i <= PIPE_C; i++) {
 469                drm_mode_connector_attach_encoder(&intel_connector->base,
 470                                                  &intel_dp->mst_encoders[i]->base.base);
 471        }
 472
 473        drm_object_attach_property(&connector->base, dev->mode_config.path_property, 0);
 474        drm_object_attach_property(&connector->base, dev->mode_config.tile_property, 0);
 475
 476        drm_mode_connector_set_path_property(connector, pathprop);
 477        return connector;
 478}
 479
 480static void intel_dp_register_mst_connector(struct drm_connector *connector)
 481{
 482        struct drm_i915_private *dev_priv = to_i915(connector->dev);
 483
 484        if (dev_priv->fbdev)
 485                drm_fb_helper_add_one_connector(&dev_priv->fbdev->helper,
 486                                                connector);
 487
 488        drm_connector_register(connector);
 489}
 490
 491static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
 492                                           struct drm_connector *connector)
 493{
 494        struct intel_connector *intel_connector = to_intel_connector(connector);
 495        struct drm_i915_private *dev_priv = to_i915(connector->dev);
 496
 497        drm_connector_unregister(connector);
 498
 499        if (dev_priv->fbdev)
 500                drm_fb_helper_remove_one_connector(&dev_priv->fbdev->helper,
 501                                                   connector);
 502        /* prevent race with the check in ->detect */
 503        drm_modeset_lock(&connector->dev->mode_config.connection_mutex, NULL);
 504        intel_connector->mst_port = NULL;
 505        drm_modeset_unlock(&connector->dev->mode_config.connection_mutex);
 506
 507        drm_connector_unreference(connector);
 508        DRM_DEBUG_KMS("\n");
 509}
 510
 511static void intel_dp_mst_hotplug(struct drm_dp_mst_topology_mgr *mgr)
 512{
 513        struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
 514        struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
 515        struct drm_device *dev = intel_dig_port->base.base.dev;
 516
 517        drm_kms_helper_hotplug_event(dev);
 518}
 519
 520static const struct drm_dp_mst_topology_cbs mst_cbs = {
 521        .add_connector = intel_dp_add_mst_connector,
 522        .register_connector = intel_dp_register_mst_connector,
 523        .destroy_connector = intel_dp_destroy_mst_connector,
 524        .hotplug = intel_dp_mst_hotplug,
 525};
 526
 527static struct intel_dp_mst_encoder *
 528intel_dp_create_fake_mst_encoder(struct intel_digital_port *intel_dig_port, enum pipe pipe)
 529{
 530        struct intel_dp_mst_encoder *intel_mst;
 531        struct intel_encoder *intel_encoder;
 532        struct drm_device *dev = intel_dig_port->base.base.dev;
 533
 534        intel_mst = kzalloc(sizeof(*intel_mst), GFP_KERNEL);
 535
 536        if (!intel_mst)
 537                return NULL;
 538
 539        intel_mst->pipe = pipe;
 540        intel_encoder = &intel_mst->base;
 541        intel_mst->primary = intel_dig_port;
 542
 543        drm_encoder_init(dev, &intel_encoder->base, &intel_dp_mst_enc_funcs,
 544                         DRM_MODE_ENCODER_DPMST, "DP-MST %c", pipe_name(pipe));
 545
 546        intel_encoder->type = INTEL_OUTPUT_DP_MST;
 547        intel_encoder->power_domain = intel_dig_port->base.power_domain;
 548        intel_encoder->port = intel_dig_port->port;
 549        intel_encoder->crtc_mask = 0x7;
 550        intel_encoder->cloneable = 0;
 551
 552        intel_encoder->compute_config = intel_dp_mst_compute_config;
 553        intel_encoder->disable = intel_mst_disable_dp;
 554        intel_encoder->post_disable = intel_mst_post_disable_dp;
 555        intel_encoder->pre_enable = intel_mst_pre_enable_dp;
 556        intel_encoder->enable = intel_mst_enable_dp;
 557        intel_encoder->get_hw_state = intel_dp_mst_enc_get_hw_state;
 558        intel_encoder->get_config = intel_dp_mst_enc_get_config;
 559
 560        return intel_mst;
 561
 562}
 563
 564static bool
 565intel_dp_create_fake_mst_encoders(struct intel_digital_port *intel_dig_port)
 566{
 567        int i;
 568        struct intel_dp *intel_dp = &intel_dig_port->dp;
 569
 570        for (i = PIPE_A; i <= PIPE_C; i++)
 571                intel_dp->mst_encoders[i] = intel_dp_create_fake_mst_encoder(intel_dig_port, i);
 572        return true;
 573}
 574
 575int
 576intel_dp_mst_encoder_init(struct intel_digital_port *intel_dig_port, int conn_base_id)
 577{
 578        struct intel_dp *intel_dp = &intel_dig_port->dp;
 579        struct drm_device *dev = intel_dig_port->base.base.dev;
 580        int ret;
 581
 582        intel_dp->can_mst = true;
 583        intel_dp->mst_mgr.cbs = &mst_cbs;
 584
 585        /* create encoders */
 586        intel_dp_create_fake_mst_encoders(intel_dig_port);
 587        ret = drm_dp_mst_topology_mgr_init(&intel_dp->mst_mgr, dev,
 588                                           &intel_dp->aux, 16, 3, conn_base_id);
 589        if (ret) {
 590                intel_dp->can_mst = false;
 591                return ret;
 592        }
 593        return 0;
 594}
 595
 596void
 597intel_dp_mst_encoder_cleanup(struct intel_digital_port *intel_dig_port)
 598{
 599        struct intel_dp *intel_dp = &intel_dig_port->dp;
 600
 601        if (!intel_dp->can_mst)
 602                return;
 603
 604        drm_dp_mst_topology_mgr_destroy(&intel_dp->mst_mgr);
 605        /* encoders will get killed by normal cleanup */
 606}
 607