blob: 6f4762dc5a94be08e3eac3c09475081bd1c2595d [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{
Ander Conselvan de Oliveira6fa2d192015-08-31 11:23:28 +030036 struct drm_device *dev = encoder->base.dev;
Dave Airlie0e32b392014-05-02 14:02:48 +100037 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;
Ander Conselvan de Oliveirae75f4772015-03-20 16:18:13 +020040 struct drm_atomic_state *state;
41 int bpp, i;
Ville Syrjälä04a60f92015-07-06 15:10:06 +030042 int lane_count, slots;
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +030043 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +030044 struct drm_connector *drm_connector;
45 struct intel_connector *connector, *found = NULL;
46 struct drm_connector_state *connector_state;
Dave Airlie0e32b392014-05-02 14:02:48 +100047 int mst_pbn;
48
49 pipe_config->dp_encoder_is_mst = true;
50 pipe_config->has_pch_encoder = false;
51 pipe_config->has_dp_encoder = true;
52 bpp = 24;
53 /*
54 * for MST we always configure max link bw - the spec doesn't
55 * seem to suggest we should do otherwise.
56 */
57 lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +020058
Ville Syrjäläed4e9c12015-03-12 17:10:36 +020059
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +030060 pipe_config->lane_count = lane_count;
Dave Airlie0e32b392014-05-02 14:02:48 +100061
62 pipe_config->pipe_bpp = 24;
Ville Syrjälä04a60f92015-07-06 15:10:06 +030063 pipe_config->port_clock = intel_dp_max_link_rate(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +100064
Ander Conselvan de Oliveirae75f4772015-03-20 16:18:13 +020065 state = pipe_config->base.state;
66
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +030067 for_each_connector_in_state(state, drm_connector, connector_state, i) {
68 connector = to_intel_connector(drm_connector);
Ander Conselvan de Oliveirae75f4772015-03-20 16:18:13 +020069
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +030070 if (connector_state->best_encoder == &encoder->base) {
71 found = connector;
Dave Airlie0e32b392014-05-02 14:02:48 +100072 break;
73 }
74 }
75
76 if (!found) {
77 DRM_ERROR("can't find connector\n");
78 return false;
79 }
80
Libin Yang3d52ccf2015-12-02 14:09:44 +080081 if (drm_dp_mst_port_has_audio(&intel_dp->mst_mgr, found->port))
82 pipe_config->has_audio = true;
Ville Syrjäläaad941d2015-09-25 16:38:56 +030083 mst_pbn = drm_dp_calc_pbn_mode(adjusted_mode->crtc_clock, bpp);
Dave Airlie0e32b392014-05-02 14:02:48 +100084
85 pipe_config->pbn = mst_pbn;
86 slots = drm_dp_find_vcpi_slots(&intel_dp->mst_mgr, mst_pbn);
87
88 intel_link_compute_m_n(bpp, lane_count,
89 adjusted_mode->crtc_clock,
90 pipe_config->port_clock,
91 &pipe_config->dp_m_n);
92
93 pipe_config->dp_m_n.tu = slots;
Ander Conselvan de Oliveira6fa2d192015-08-31 11:23:28 +030094
95 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
96 hsw_dp_set_ddi_pll_sel(pipe_config);
97
Dave Airlie0e32b392014-05-02 14:02:48 +100098 return true;
99
100}
101
102static void intel_mst_disable_dp(struct intel_encoder *encoder)
103{
104 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
105 struct intel_digital_port *intel_dig_port = intel_mst->primary;
106 struct intel_dp *intel_dp = &intel_dig_port->dp;
Libin Yang3d52ccf2015-12-02 14:09:44 +0800107 struct drm_device *dev = encoder->base.dev;
108 struct drm_i915_private *dev_priv = dev->dev_private;
109 struct drm_crtc *crtc = encoder->base.crtc;
110 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
111
Dave Airlie0e32b392014-05-02 14:02:48 +1000112 int ret;
113
114 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
115
116 drm_dp_mst_reset_vcpi_slots(&intel_dp->mst_mgr, intel_mst->port);
117
118 ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
119 if (ret) {
120 DRM_ERROR("failed to update payload %d\n", ret);
121 }
Libin Yang3d52ccf2015-12-02 14:09:44 +0800122 if (intel_crtc->config->has_audio) {
123 intel_audio_codec_disable(encoder);
124 intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
125 }
Dave Airlie0e32b392014-05-02 14:02:48 +1000126}
127
128static void intel_mst_post_disable_dp(struct intel_encoder *encoder)
129{
130 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
131 struct intel_digital_port *intel_dig_port = intel_mst->primary;
132 struct intel_dp *intel_dp = &intel_dig_port->dp;
133
134 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
135
136 /* this can fail */
137 drm_dp_check_act_status(&intel_dp->mst_mgr);
138 /* and this can also fail */
139 drm_dp_update_payload_part2(&intel_dp->mst_mgr);
140
141 drm_dp_mst_deallocate_vcpi(&intel_dp->mst_mgr, intel_mst->port);
142
143 intel_dp->active_mst_links--;
144 intel_mst->port = NULL;
145 if (intel_dp->active_mst_links == 0) {
146 intel_dig_port->base.post_disable(&intel_dig_port->base);
147 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
148 }
149}
150
151static void intel_mst_pre_enable_dp(struct intel_encoder *encoder)
152{
153 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
154 struct intel_digital_port *intel_dig_port = intel_mst->primary;
155 struct intel_dp *intel_dp = &intel_dig_port->dp;
156 struct drm_device *dev = encoder->base.dev;
157 struct drm_i915_private *dev_priv = dev->dev_private;
158 enum port port = intel_dig_port->port;
159 int ret;
160 uint32_t temp;
Ander Conselvan de Oliveira9b4fd8f2015-04-02 14:48:01 +0300161 struct intel_connector *found = NULL, *connector;
Dave Airlie0e32b392014-05-02 14:02:48 +1000162 int slots;
163 struct drm_crtc *crtc = encoder->base.crtc;
164 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
165
Ander Conselvan de Oliveira9b4fd8f2015-04-02 14:48:01 +0300166 for_each_intel_connector(dev, connector) {
167 if (connector->base.state->best_encoder == &encoder->base) {
168 found = connector;
Dave Airlie0e32b392014-05-02 14:02:48 +1000169 break;
170 }
171 }
172
173 if (!found) {
174 DRM_ERROR("can't find connector\n");
175 return;
176 }
177
Maarten Lankhorste85376c2015-08-27 13:13:31 +0200178 /* MST encoders are bound to a crtc, not to a connector,
179 * force the mapping here for get_hw_state.
180 */
181 found->encoder = encoder;
182
Dave Airlie0e32b392014-05-02 14:02:48 +1000183 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
184 intel_mst->port = found->port;
185
186 if (intel_dp->active_mst_links == 0) {
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200187 intel_prepare_ddi_buffer(&intel_dig_port->base);
188
Ville Syrjäläd9191612015-12-08 19:59:36 +0200189 intel_ddi_clk_select(&intel_dig_port->base, intel_crtc->config);
Dave Airlie0e32b392014-05-02 14:02:48 +1000190
Ville Syrjälä901c2da2015-08-17 18:05:12 +0300191 intel_dp_set_link_params(intel_dp, intel_crtc->config);
192
Dave Airlie0e32b392014-05-02 14:02:48 +1000193 intel_ddi_init_dp_buf_reg(&intel_dig_port->base);
194
195 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
196
Dave Airlie0e32b392014-05-02 14:02:48 +1000197 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +1000198 intel_dp_stop_link_train(intel_dp);
199 }
200
201 ret = drm_dp_mst_allocate_vcpi(&intel_dp->mst_mgr,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200202 intel_mst->port,
203 intel_crtc->config->pbn, &slots);
Dave Airlie0e32b392014-05-02 14:02:48 +1000204 if (ret == false) {
205 DRM_ERROR("failed to allocate vcpi\n");
206 return;
207 }
208
209
210 intel_dp->active_mst_links++;
211 temp = I915_READ(DP_TP_STATUS(port));
212 I915_WRITE(DP_TP_STATUS(port), temp);
213
214 ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
215}
216
217static void intel_mst_enable_dp(struct intel_encoder *encoder)
218{
219 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
220 struct intel_digital_port *intel_dig_port = intel_mst->primary;
221 struct intel_dp *intel_dp = &intel_dig_port->dp;
222 struct drm_device *dev = intel_dig_port->base.base.dev;
223 struct drm_i915_private *dev_priv = dev->dev_private;
Libin Yang3d52ccf2015-12-02 14:09:44 +0800224 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Dave Airlie0e32b392014-05-02 14:02:48 +1000225 enum port port = intel_dig_port->port;
226 int ret;
227
228 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
229
230 if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_ACT_SENT),
231 1))
232 DRM_ERROR("Timed out waiting for ACT sent\n");
233
234 ret = drm_dp_check_act_status(&intel_dp->mst_mgr);
235
236 ret = drm_dp_update_payload_part2(&intel_dp->mst_mgr);
Libin Yang3d52ccf2015-12-02 14:09:44 +0800237
238 if (crtc->config->has_audio) {
239 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
240 pipe_name(crtc->pipe));
241 intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
242 intel_audio_codec_enable(encoder);
243 }
Dave Airlie0e32b392014-05-02 14:02:48 +1000244}
245
246static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder *encoder,
247 enum pipe *pipe)
248{
249 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
250 *pipe = intel_mst->pipe;
251 if (intel_mst->port)
252 return true;
253 return false;
254}
255
256static void intel_dp_mst_enc_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200257 struct intel_crtc_state *pipe_config)
Dave Airlie0e32b392014-05-02 14:02:48 +1000258{
259 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
260 struct intel_digital_port *intel_dig_port = intel_mst->primary;
261 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
262 struct drm_device *dev = encoder->base.dev;
263 struct drm_i915_private *dev_priv = dev->dev_private;
Ander Conselvan de Oliveira0cb09a92015-01-30 12:17:23 +0200264 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Dave Airlie0e32b392014-05-02 14:02:48 +1000265 u32 temp, flags = 0;
266
267 pipe_config->has_dp_encoder = true;
268
Libin Yang3d52ccf2015-12-02 14:09:44 +0800269 pipe_config->has_audio =
270 intel_ddi_is_audio_enabled(dev_priv, crtc);
271
Dave Airlie0e32b392014-05-02 14:02:48 +1000272 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
273 if (temp & TRANS_DDI_PHSYNC)
274 flags |= DRM_MODE_FLAG_PHSYNC;
275 else
276 flags |= DRM_MODE_FLAG_NHSYNC;
277 if (temp & TRANS_DDI_PVSYNC)
278 flags |= DRM_MODE_FLAG_PVSYNC;
279 else
280 flags |= DRM_MODE_FLAG_NVSYNC;
281
282 switch (temp & TRANS_DDI_BPC_MASK) {
283 case TRANS_DDI_BPC_6:
284 pipe_config->pipe_bpp = 18;
285 break;
286 case TRANS_DDI_BPC_8:
287 pipe_config->pipe_bpp = 24;
288 break;
289 case TRANS_DDI_BPC_10:
290 pipe_config->pipe_bpp = 30;
291 break;
292 case TRANS_DDI_BPC_12:
293 pipe_config->pipe_bpp = 36;
294 break;
295 default:
296 break;
297 }
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200298 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +0300299
300 pipe_config->lane_count =
301 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
302
Dave Airlie0e32b392014-05-02 14:02:48 +1000303 intel_dp_get_m_n(crtc, pipe_config);
304
305 intel_ddi_clock_get(&intel_dig_port->base, pipe_config);
306}
307
308static int intel_dp_mst_get_ddc_modes(struct drm_connector *connector)
309{
310 struct intel_connector *intel_connector = to_intel_connector(connector);
311 struct intel_dp *intel_dp = intel_connector->mst_port;
312 struct edid *edid;
313 int ret;
314
315 edid = drm_dp_mst_get_edid(connector, &intel_dp->mst_mgr, intel_connector->port);
316 if (!edid)
317 return 0;
318
319 ret = intel_connector_update_modes(connector, edid);
320 kfree(edid);
321
322 return ret;
323}
324
325static enum drm_connector_status
Daniel Vetterf7f3d482014-10-22 11:06:44 +0200326intel_dp_mst_detect(struct drm_connector *connector, bool force)
Dave Airlie0e32b392014-05-02 14:02:48 +1000327{
328 struct intel_connector *intel_connector = to_intel_connector(connector);
329 struct intel_dp *intel_dp = intel_connector->mst_port;
330
Dave Airliec6a0aed2014-10-20 16:28:02 +1000331 return drm_dp_mst_detect_port(connector, &intel_dp->mst_mgr, intel_connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000332}
333
Dave Airlie0e32b392014-05-02 14:02:48 +1000334static int
335intel_dp_mst_set_property(struct drm_connector *connector,
336 struct drm_property *property,
337 uint64_t val)
338{
339 return 0;
340}
341
342static void
343intel_dp_mst_connector_destroy(struct drm_connector *connector)
344{
345 struct intel_connector *intel_connector = to_intel_connector(connector);
346
347 if (!IS_ERR_OR_NULL(intel_connector->edid))
348 kfree(intel_connector->edid);
349
350 drm_connector_cleanup(connector);
351 kfree(connector);
352}
353
354static const struct drm_connector_funcs intel_dp_mst_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +0200355 .dpms = drm_atomic_helper_connector_dpms,
Dave Airlie0e32b392014-05-02 14:02:48 +1000356 .detect = intel_dp_mst_detect,
357 .fill_modes = drm_helper_probe_single_connector_modes,
358 .set_property = intel_dp_mst_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -0800359 .atomic_get_property = intel_connector_atomic_get_property,
Dave Airlie0e32b392014-05-02 14:02:48 +1000360 .destroy = intel_dp_mst_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -0800361 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +0200362 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Dave Airlie0e32b392014-05-02 14:02:48 +1000363};
364
365static int intel_dp_mst_get_modes(struct drm_connector *connector)
366{
367 return intel_dp_mst_get_ddc_modes(connector);
368}
369
370static enum drm_mode_status
371intel_dp_mst_mode_valid(struct drm_connector *connector,
372 struct drm_display_mode *mode)
373{
374 /* TODO - validate mode against available PBN for link */
375 if (mode->clock < 10000)
376 return MODE_CLOCK_LOW;
377
378 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
379 return MODE_H_ILLEGAL;
380
381 return MODE_OK;
382}
383
Daniel Vetter459485a2015-08-03 17:24:09 +0200384static struct drm_encoder *intel_mst_atomic_best_encoder(struct drm_connector *connector,
385 struct drm_connector_state *state)
386{
387 struct intel_connector *intel_connector = to_intel_connector(connector);
388 struct intel_dp *intel_dp = intel_connector->mst_port;
389 struct intel_crtc *crtc = to_intel_crtc(state->crtc);
390
391 return &intel_dp->mst_encoders[crtc->pipe]->base.base;
392}
393
Dave Airlie0e32b392014-05-02 14:02:48 +1000394static struct drm_encoder *intel_mst_best_encoder(struct drm_connector *connector)
395{
396 struct intel_connector *intel_connector = to_intel_connector(connector);
397 struct intel_dp *intel_dp = intel_connector->mst_port;
398 return &intel_dp->mst_encoders[0]->base.base;
399}
400
401static const struct drm_connector_helper_funcs intel_dp_mst_connector_helper_funcs = {
402 .get_modes = intel_dp_mst_get_modes,
403 .mode_valid = intel_dp_mst_mode_valid,
Daniel Vetter459485a2015-08-03 17:24:09 +0200404 .atomic_best_encoder = intel_mst_atomic_best_encoder,
Dave Airlie0e32b392014-05-02 14:02:48 +1000405 .best_encoder = intel_mst_best_encoder,
406};
407
408static void intel_dp_mst_encoder_destroy(struct drm_encoder *encoder)
409{
410 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder);
411
412 drm_encoder_cleanup(encoder);
413 kfree(intel_mst);
414}
415
416static const struct drm_encoder_funcs intel_dp_mst_enc_funcs = {
417 .destroy = intel_dp_mst_encoder_destroy,
418};
419
420static bool intel_dp_mst_get_hw_state(struct intel_connector *connector)
421{
Maarten Lankhorste85376c2015-08-27 13:13:31 +0200422 if (connector->encoder && connector->base.state->crtc) {
Dave Airlie0e32b392014-05-02 14:02:48 +1000423 enum pipe pipe;
424 if (!connector->encoder->get_hw_state(connector->encoder, &pipe))
425 return false;
426 return true;
427 }
428 return false;
429}
430
Chris Wilson7296c842014-07-22 20:10:28 +1000431static void intel_connector_add_to_fbdev(struct intel_connector *connector)
432{
Daniel Vetter06957262015-08-10 13:34:08 +0200433#ifdef CONFIG_DRM_FBDEV_EMULATION
Chris Wilson7296c842014-07-22 20:10:28 +1000434 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
Lukas Wunner54632ab2015-11-18 13:43:20 +0100435
436 if (dev_priv->fbdev)
437 drm_fb_helper_add_one_connector(&dev_priv->fbdev->helper,
438 &connector->base);
Chris Wilson7296c842014-07-22 20:10:28 +1000439#endif
440}
441
442static void intel_connector_remove_from_fbdev(struct intel_connector *connector)
443{
Daniel Vetter06957262015-08-10 13:34:08 +0200444#ifdef CONFIG_DRM_FBDEV_EMULATION
Chris Wilson7296c842014-07-22 20:10:28 +1000445 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
Lukas Wunner54632ab2015-11-18 13:43:20 +0100446
447 if (dev_priv->fbdev)
448 drm_fb_helper_remove_one_connector(&dev_priv->fbdev->helper,
449 &connector->base);
Chris Wilson7296c842014-07-22 20:10:28 +1000450#endif
451}
452
Thierry Reding12e6cec2014-05-13 11:38:36 +0200453static 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 +1000454{
455 struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
456 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
457 struct drm_device *dev = intel_dig_port->base.base.dev;
Dave Airlie0e32b392014-05-02 14:02:48 +1000458 struct intel_connector *intel_connector;
459 struct drm_connector *connector;
460 int i;
461
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +0300462 intel_connector = intel_connector_alloc();
Dave Airlie0e32b392014-05-02 14:02:48 +1000463 if (!intel_connector)
464 return NULL;
465
466 connector = &intel_connector->base;
467 drm_connector_init(dev, connector, &intel_dp_mst_connector_funcs, DRM_MODE_CONNECTOR_DisplayPort);
468 drm_connector_helper_add(connector, &intel_dp_mst_connector_helper_funcs);
469
470 intel_connector->unregister = intel_connector_unregister;
471 intel_connector->get_hw_state = intel_dp_mst_get_hw_state;
472 intel_connector->mst_port = intel_dp;
473 intel_connector->port = port;
474
475 for (i = PIPE_A; i <= PIPE_C; i++) {
476 drm_mode_connector_attach_encoder(&intel_connector->base,
477 &intel_dp->mst_encoders[i]->base.base);
478 }
479 intel_dp_add_properties(intel_dp, connector);
480
481 drm_object_attach_property(&connector->base, dev->mode_config.path_property, 0);
Dave Airlie6f134d72014-10-20 16:30:50 +1000482 drm_object_attach_property(&connector->base, dev->mode_config.tile_property, 0);
483
Dave Airlie0e32b392014-05-02 14:02:48 +1000484 drm_mode_connector_set_path_property(connector, pathprop);
Dave Airlied9515c52015-09-16 17:55:23 +1000485 return connector;
486}
487
488static void intel_dp_register_mst_connector(struct drm_connector *connector)
489{
490 struct intel_connector *intel_connector = to_intel_connector(connector);
491 struct drm_device *dev = connector->dev;
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200492 drm_modeset_lock_all(dev);
Chris Wilson7296c842014-07-22 20:10:28 +1000493 intel_connector_add_to_fbdev(intel_connector);
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200494 drm_modeset_unlock_all(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000495 drm_connector_register(&intel_connector->base);
Dave Airlie0e32b392014-05-02 14:02:48 +1000496}
497
498static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
499 struct drm_connector *connector)
500{
501 struct intel_connector *intel_connector = to_intel_connector(connector);
502 struct drm_device *dev = connector->dev;
Maarten Lankhorst20fae982015-08-06 13:47:36 +0200503
Dave Airlie0e32b392014-05-02 14:02:48 +1000504 /* need to nuke the connector */
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200505 drm_modeset_lock_all(dev);
Maarten Lankhorst20fae982015-08-06 13:47:36 +0200506 if (connector->state->crtc) {
507 struct drm_mode_set set;
508 int ret;
509
510 memset(&set, 0, sizeof(set));
511 set.crtc = connector->state->crtc,
512
513 ret = drm_atomic_helper_set_config(&set);
514
515 WARN(ret, "Disabling mst crtc failed with %i\n", ret);
516 }
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200517 drm_modeset_unlock_all(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000518
519 intel_connector->unregister(intel_connector);
520
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200521 drm_modeset_lock_all(dev);
Chris Wilson7296c842014-07-22 20:10:28 +1000522 intel_connector_remove_from_fbdev(intel_connector);
Dave Airlie0e32b392014-05-02 14:02:48 +1000523 drm_connector_cleanup(connector);
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200524 drm_modeset_unlock_all(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000525
Dave Airlie0e32b392014-05-02 14:02:48 +1000526 kfree(intel_connector);
527 DRM_DEBUG_KMS("\n");
528}
529
530static void intel_dp_mst_hotplug(struct drm_dp_mst_topology_mgr *mgr)
531{
532 struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
533 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
534 struct drm_device *dev = intel_dig_port->base.base.dev;
535
536 drm_kms_helper_hotplug_event(dev);
537}
538
539static struct drm_dp_mst_topology_cbs mst_cbs = {
540 .add_connector = intel_dp_add_mst_connector,
Dave Airlied9515c52015-09-16 17:55:23 +1000541 .register_connector = intel_dp_register_mst_connector,
Dave Airlie0e32b392014-05-02 14:02:48 +1000542 .destroy_connector = intel_dp_destroy_mst_connector,
543 .hotplug = intel_dp_mst_hotplug,
544};
545
546static struct intel_dp_mst_encoder *
547intel_dp_create_fake_mst_encoder(struct intel_digital_port *intel_dig_port, enum pipe pipe)
548{
549 struct intel_dp_mst_encoder *intel_mst;
550 struct intel_encoder *intel_encoder;
551 struct drm_device *dev = intel_dig_port->base.base.dev;
552
553 intel_mst = kzalloc(sizeof(*intel_mst), GFP_KERNEL);
554
555 if (!intel_mst)
556 return NULL;
557
558 intel_mst->pipe = pipe;
559 intel_encoder = &intel_mst->base;
560 intel_mst->primary = intel_dig_port;
561
562 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_mst_enc_funcs,
563 DRM_MODE_ENCODER_DPMST);
564
565 intel_encoder->type = INTEL_OUTPUT_DP_MST;
566 intel_encoder->crtc_mask = 0x7;
567 intel_encoder->cloneable = 0;
568
569 intel_encoder->compute_config = intel_dp_mst_compute_config;
570 intel_encoder->disable = intel_mst_disable_dp;
571 intel_encoder->post_disable = intel_mst_post_disable_dp;
572 intel_encoder->pre_enable = intel_mst_pre_enable_dp;
573 intel_encoder->enable = intel_mst_enable_dp;
574 intel_encoder->get_hw_state = intel_dp_mst_enc_get_hw_state;
575 intel_encoder->get_config = intel_dp_mst_enc_get_config;
576
577 return intel_mst;
578
579}
580
581static bool
582intel_dp_create_fake_mst_encoders(struct intel_digital_port *intel_dig_port)
583{
584 int i;
585 struct intel_dp *intel_dp = &intel_dig_port->dp;
586
587 for (i = PIPE_A; i <= PIPE_C; i++)
588 intel_dp->mst_encoders[i] = intel_dp_create_fake_mst_encoder(intel_dig_port, i);
589 return true;
590}
591
592int
593intel_dp_mst_encoder_init(struct intel_digital_port *intel_dig_port, int conn_base_id)
594{
595 struct intel_dp *intel_dp = &intel_dig_port->dp;
596 struct drm_device *dev = intel_dig_port->base.base.dev;
597 int ret;
598
599 intel_dp->can_mst = true;
600 intel_dp->mst_mgr.cbs = &mst_cbs;
601
602 /* create encoders */
603 intel_dp_create_fake_mst_encoders(intel_dig_port);
604 ret = drm_dp_mst_topology_mgr_init(&intel_dp->mst_mgr, dev->dev, &intel_dp->aux, 16, 3, conn_base_id);
605 if (ret) {
606 intel_dp->can_mst = false;
607 return ret;
608 }
609 return 0;
610}
611
612void
613intel_dp_mst_encoder_cleanup(struct intel_digital_port *intel_dig_port)
614{
615 struct intel_dp *intel_dp = &intel_dig_port->dp;
616
617 if (!intel_dp->can_mst)
618 return;
619
620 drm_dp_mst_topology_mgr_destroy(&intel_dp->mst_mgr);
621 /* encoders will get killed by normal cleanup */
622}