blob: 3945057c5bbeb9f1a93ab52fda0550a3dce22b52 [file] [log] [blame]
Dave Airlie0e32b392014-05-02 14:02:48 +10001/*
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 Roperc6f95f22015-01-22 16:50:32 -080029#include <drm/drm_atomic_helper.h>
Dave Airlie0e32b392014-05-02 14:02:48 +100030#include <drm/drm_crtc_helper.h>
31#include <drm/drm_edid.h>
32
33static bool intel_dp_mst_compute_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020034 struct intel_crtc_state *pipe_config)
Dave Airlie0e32b392014-05-02 14:02:48 +100035{
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 Oliveirae75f4772015-03-20 16:18:13 +020039 struct drm_atomic_state *state;
40 int bpp, i;
Ville Syrjäläed4e9c12015-03-12 17:10:36 +020041 int lane_count, slots, rate;
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020042 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ander Conselvan de Oliveirae75f4772015-03-20 16:18:13 +020043 struct intel_connector *found = NULL;
Dave Airlie0e32b392014-05-02 14:02:48 +100044 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äed4e9c12015-03-12 17:10:36 +020055
56 rate = intel_dp_max_link_rate(intel_dp);
57
Ville Syrjälä94ca7192015-03-13 19:40:31 +020058 if (intel_dp->num_sink_rates) {
Ville Syrjäläed4e9c12015-03-12 17:10:36 +020059 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 Airlie0e32b392014-05-02 14:02:48 +100066 intel_dp->lane_count = lane_count;
67
68 pipe_config->pipe_bpp = 24;
Ville Syrjäläed4e9c12015-03-12 17:10:36 +020069 pipe_config->port_clock = rate;
Dave Airlie0e32b392014-05-02 14:02:48 +100070
Ander Conselvan de Oliveirae75f4772015-03-20 16:18:13 +020071 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 Airlie0e32b392014-05-02 14:02:48 +100079 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
103static 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
120static 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
143static 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 Oliveira9b4fd8f2015-04-02 14:48:01 +0300153 struct intel_connector *found = NULL, *connector;
Dave Airlie0e32b392014-05-02 14:02:48 +1000154 int slots;
155 struct drm_crtc *crtc = encoder->base.crtc;
156 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
157
Ander Conselvan de Oliveira9b4fd8f2015-04-02 14:48:01 +0300158 for_each_intel_connector(dev, connector) {
159 if (connector->base.state->best_encoder == &encoder->base) {
160 found = connector;
Dave Airlie0e32b392014-05-02 14:02:48 +1000161 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 M1ab23382014-08-22 09:49:06 +0530176 /* 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 Airlie0e32b392014-05-02 14:02:48 +1000180
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 Oliveira6e3c9712015-01-15 14:55:25 +0200192 intel_mst->port,
193 intel_crtc->config->pbn, &slots);
Dave Airlie0e32b392014-05-02 14:02:48 +1000194 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
207static 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
228static 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
238static void intel_dp_mst_enc_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200239 struct intel_crtc_state *pipe_config)
Dave Airlie0e32b392014-05-02 14:02:48 +1000240{
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 Oliveira0cb09a92015-01-30 12:17:23 +0200246 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Dave Airlie0e32b392014-05-02 14:02:48 +1000247 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 Oliveira2d112de2015-01-15 14:55:22 +0200277 pipe_config->base.adjusted_mode.flags |= flags;
Dave Airlie0e32b392014-05-02 14:02:48 +1000278 intel_dp_get_m_n(crtc, pipe_config);
279
280 intel_ddi_clock_get(&intel_dig_port->base, pipe_config);
281}
282
283static 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
300static enum drm_connector_status
Daniel Vetterf7f3d482014-10-22 11:06:44 +0200301intel_dp_mst_detect(struct drm_connector *connector, bool force)
Dave Airlie0e32b392014-05-02 14:02:48 +1000302{
303 struct intel_connector *intel_connector = to_intel_connector(connector);
304 struct intel_dp *intel_dp = intel_connector->mst_port;
305
Dave Airliec6a0aed2014-10-20 16:28:02 +1000306 return drm_dp_mst_detect_port(connector, &intel_dp->mst_mgr, intel_connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000307}
308
Dave Airlie0e32b392014-05-02 14:02:48 +1000309static int
310intel_dp_mst_set_property(struct drm_connector *connector,
311 struct drm_property *property,
312 uint64_t val)
313{
314 return 0;
315}
316
317static void
318intel_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
329static 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 Roper2545e4a2015-01-22 16:51:27 -0800334 .atomic_get_property = intel_connector_atomic_get_property,
Dave Airlie0e32b392014-05-02 14:02:48 +1000335 .destroy = intel_dp_mst_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -0800336 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +0200337 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Dave Airlie0e32b392014-05-02 14:02:48 +1000338};
339
340static int intel_dp_mst_get_modes(struct drm_connector *connector)
341{
342 return intel_dp_mst_get_ddc_modes(connector);
343}
344
345static enum drm_mode_status
346intel_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
359static 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
366static 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
372static 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
380static const struct drm_encoder_funcs intel_dp_mst_enc_funcs = {
381 .destroy = intel_dp_mst_encoder_destroy,
382};
383
384static 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 Wilson7296c842014-07-22 20:10:28 +1000395static 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
403static 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 Reding12e6cec2014-05-13 11:38:36 +0200411static 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 Airlie0e32b392014-05-02 14:02:48 +1000412{
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 Airlie0e32b392014-05-02 14:02:48 +1000416 struct intel_connector *intel_connector;
417 struct drm_connector *connector;
418 int i;
419
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +0300420 intel_connector = intel_connector_alloc();
Dave Airlie0e32b392014-05-02 14:02:48 +1000421 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 Airlie6f134d72014-10-20 16:30:50 +1000440 drm_object_attach_property(&connector->base, dev->mode_config.tile_property, 0);
441
Dave Airlie0e32b392014-05-02 14:02:48 +1000442 drm_mode_connector_set_path_property(connector, pathprop);
443 drm_reinit_primary_mode_group(dev);
444 mutex_lock(&dev->mode_config.mutex);
Chris Wilson7296c842014-07-22 20:10:28 +1000445 intel_connector_add_to_fbdev(intel_connector);
Dave Airlie0e32b392014-05-02 14:02:48 +1000446 mutex_unlock(&dev->mode_config.mutex);
447 drm_connector_register(&intel_connector->base);
448 return connector;
449}
450
451static 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 Airlie0e32b392014-05-02 14:02:48 +1000456 /* 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 Wilson7296c842014-07-22 20:10:28 +1000464 intel_connector_remove_from_fbdev(intel_connector);
Dave Airlie0e32b392014-05-02 14:02:48 +1000465 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
474static 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
483static 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
489static struct intel_dp_mst_encoder *
490intel_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
524static bool
525intel_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
535int
536intel_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
555void
556intel_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}