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