blob: 9646816604be657d02e4f9fa56b1dc926234b795 [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ä04a60f92015-07-06 15:10:06 +030041 int lane_count, slots;
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +030042 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +030043 struct drm_connector *drm_connector;
44 struct intel_connector *connector, *found = NULL;
45 struct drm_connector_state *connector_state;
Dave Airlie0e32b392014-05-02 14:02:48 +100046 int mst_pbn;
47
48 pipe_config->dp_encoder_is_mst = true;
49 pipe_config->has_pch_encoder = false;
50 pipe_config->has_dp_encoder = true;
51 bpp = 24;
52 /*
53 * for MST we always configure max link bw - the spec doesn't
54 * seem to suggest we should do otherwise.
55 */
56 lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +020057
Ville Syrjäläed4e9c12015-03-12 17:10:36 +020058
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +030059 pipe_config->lane_count = lane_count;
Dave Airlie0e32b392014-05-02 14:02:48 +100060
61 pipe_config->pipe_bpp = 24;
Ville Syrjälä04a60f92015-07-06 15:10:06 +030062 pipe_config->port_clock = intel_dp_max_link_rate(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +100063
Ander Conselvan de Oliveirae75f4772015-03-20 16:18:13 +020064 state = pipe_config->base.state;
65
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +030066 for_each_connector_in_state(state, drm_connector, connector_state, i) {
67 connector = to_intel_connector(drm_connector);
Ander Conselvan de Oliveirae75f4772015-03-20 16:18:13 +020068
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +030069 if (connector_state->best_encoder == &encoder->base) {
70 found = connector;
Dave Airlie0e32b392014-05-02 14:02:48 +100071 break;
72 }
73 }
74
75 if (!found) {
76 DRM_ERROR("can't find connector\n");
77 return false;
78 }
79
Ville Syrjäläaad941d2015-09-25 16:38:56 +030080 mst_pbn = drm_dp_calc_pbn_mode(adjusted_mode->crtc_clock, bpp);
Dave Airlie0e32b392014-05-02 14:02:48 +100081
82 pipe_config->pbn = mst_pbn;
83 slots = drm_dp_find_vcpi_slots(&intel_dp->mst_mgr, mst_pbn);
84
85 intel_link_compute_m_n(bpp, lane_count,
86 adjusted_mode->crtc_clock,
87 pipe_config->port_clock,
88 &pipe_config->dp_m_n);
89
90 pipe_config->dp_m_n.tu = slots;
Ander Conselvan de Oliveira6fa2d192015-08-31 11:23:28 +030091
Dave Airlie0e32b392014-05-02 14:02:48 +100092 return true;
93
94}
95
96static void intel_mst_disable_dp(struct intel_encoder *encoder)
97{
98 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
99 struct intel_digital_port *intel_dig_port = intel_mst->primary;
100 struct intel_dp *intel_dp = &intel_dig_port->dp;
101 int ret;
102
103 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
104
Dave Airlie0552f762016-03-09 11:14:38 +1000105 drm_dp_mst_reset_vcpi_slots(&intel_dp->mst_mgr, intel_mst->connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000106
107 ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
108 if (ret) {
109 DRM_ERROR("failed to update payload %d\n", ret);
110 }
111}
112
113static void intel_mst_post_disable_dp(struct intel_encoder *encoder)
114{
115 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
116 struct intel_digital_port *intel_dig_port = intel_mst->primary;
117 struct intel_dp *intel_dp = &intel_dig_port->dp;
118
119 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
120
121 /* this can fail */
122 drm_dp_check_act_status(&intel_dp->mst_mgr);
123 /* and this can also fail */
124 drm_dp_update_payload_part2(&intel_dp->mst_mgr);
125
Dave Airlie0552f762016-03-09 11:14:38 +1000126 drm_dp_mst_deallocate_vcpi(&intel_dp->mst_mgr, intel_mst->connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000127
128 intel_dp->active_mst_links--;
Dave Airlie0552f762016-03-09 11:14:38 +1000129
130 intel_mst->connector = NULL;
Dave Airlie0e32b392014-05-02 14:02:48 +1000131 if (intel_dp->active_mst_links == 0) {
132 intel_dig_port->base.post_disable(&intel_dig_port->base);
133 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
134 }
135}
136
137static void intel_mst_pre_enable_dp(struct intel_encoder *encoder)
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 drm_device *dev = encoder->base.dev;
143 struct drm_i915_private *dev_priv = dev->dev_private;
144 enum port port = intel_dig_port->port;
145 int ret;
146 uint32_t temp;
Ander Conselvan de Oliveira9b4fd8f2015-04-02 14:48:01 +0300147 struct intel_connector *found = NULL, *connector;
Dave Airlie0e32b392014-05-02 14:02:48 +1000148 int slots;
149 struct drm_crtc *crtc = encoder->base.crtc;
150 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
151
Ander Conselvan de Oliveira9b4fd8f2015-04-02 14:48:01 +0300152 for_each_intel_connector(dev, connector) {
153 if (connector->base.state->best_encoder == &encoder->base) {
154 found = connector;
Dave Airlie0e32b392014-05-02 14:02:48 +1000155 break;
156 }
157 }
158
159 if (!found) {
160 DRM_ERROR("can't find connector\n");
161 return;
162 }
163
Maarten Lankhorste85376c2015-08-27 13:13:31 +0200164 /* MST encoders are bound to a crtc, not to a connector,
165 * force the mapping here for get_hw_state.
166 */
167 found->encoder = encoder;
168
Dave Airlie0e32b392014-05-02 14:02:48 +1000169 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
Dave Airlie0552f762016-03-09 11:14:38 +1000170
171 intel_mst->connector = found;
Dave Airlie0e32b392014-05-02 14:02:48 +1000172
173 if (intel_dp->active_mst_links == 0) {
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200174 intel_prepare_ddi_buffer(&intel_dig_port->base);
175
Ville Syrjäläd9191612015-12-08 19:59:36 +0200176 intel_ddi_clk_select(&intel_dig_port->base, intel_crtc->config);
Dave Airlie0e32b392014-05-02 14:02:48 +1000177
Ville Syrjälä901c2da2015-08-17 18:05:12 +0300178 intel_dp_set_link_params(intel_dp, intel_crtc->config);
179
Dave Airlie0e32b392014-05-02 14:02:48 +1000180 intel_ddi_init_dp_buf_reg(&intel_dig_port->base);
181
182 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
183
Dave Airlie0e32b392014-05-02 14:02:48 +1000184 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +1000185 intel_dp_stop_link_train(intel_dp);
186 }
187
188 ret = drm_dp_mst_allocate_vcpi(&intel_dp->mst_mgr,
Dave Airlie0552f762016-03-09 11:14:38 +1000189 intel_mst->connector->port,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200190 intel_crtc->config->pbn, &slots);
Dave Airlie0e32b392014-05-02 14:02:48 +1000191 if (ret == false) {
192 DRM_ERROR("failed to allocate vcpi\n");
193 return;
194 }
195
196
197 intel_dp->active_mst_links++;
198 temp = I915_READ(DP_TP_STATUS(port));
199 I915_WRITE(DP_TP_STATUS(port), temp);
200
201 ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
202}
203
204static void intel_mst_enable_dp(struct intel_encoder *encoder)
205{
206 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
207 struct intel_digital_port *intel_dig_port = intel_mst->primary;
208 struct intel_dp *intel_dp = &intel_dig_port->dp;
209 struct drm_device *dev = intel_dig_port->base.base.dev;
210 struct drm_i915_private *dev_priv = dev->dev_private;
211 enum port port = intel_dig_port->port;
212 int ret;
213
214 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
215
216 if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_ACT_SENT),
217 1))
218 DRM_ERROR("Timed out waiting for ACT sent\n");
219
220 ret = drm_dp_check_act_status(&intel_dp->mst_mgr);
221
222 ret = drm_dp_update_payload_part2(&intel_dp->mst_mgr);
223}
224
225static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder *encoder,
226 enum pipe *pipe)
227{
228 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
229 *pipe = intel_mst->pipe;
Dave Airlie0552f762016-03-09 11:14:38 +1000230 if (intel_mst->connector)
Dave Airlie0e32b392014-05-02 14:02:48 +1000231 return true;
232 return false;
233}
234
235static void intel_dp_mst_enc_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200236 struct intel_crtc_state *pipe_config)
Dave Airlie0e32b392014-05-02 14:02:48 +1000237{
238 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
239 struct intel_digital_port *intel_dig_port = intel_mst->primary;
240 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
241 struct drm_device *dev = encoder->base.dev;
242 struct drm_i915_private *dev_priv = dev->dev_private;
Ander Conselvan de Oliveira0cb09a92015-01-30 12:17:23 +0200243 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Dave Airlie0e32b392014-05-02 14:02:48 +1000244 u32 temp, flags = 0;
245
246 pipe_config->has_dp_encoder = true;
247
248 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
249 if (temp & TRANS_DDI_PHSYNC)
250 flags |= DRM_MODE_FLAG_PHSYNC;
251 else
252 flags |= DRM_MODE_FLAG_NHSYNC;
253 if (temp & TRANS_DDI_PVSYNC)
254 flags |= DRM_MODE_FLAG_PVSYNC;
255 else
256 flags |= DRM_MODE_FLAG_NVSYNC;
257
258 switch (temp & TRANS_DDI_BPC_MASK) {
259 case TRANS_DDI_BPC_6:
260 pipe_config->pipe_bpp = 18;
261 break;
262 case TRANS_DDI_BPC_8:
263 pipe_config->pipe_bpp = 24;
264 break;
265 case TRANS_DDI_BPC_10:
266 pipe_config->pipe_bpp = 30;
267 break;
268 case TRANS_DDI_BPC_12:
269 pipe_config->pipe_bpp = 36;
270 break;
271 default:
272 break;
273 }
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200274 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +0300275
276 pipe_config->lane_count =
277 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
278
Dave Airlie0e32b392014-05-02 14:02:48 +1000279 intel_dp_get_m_n(crtc, pipe_config);
280
281 intel_ddi_clock_get(&intel_dig_port->base, pipe_config);
282}
283
284static int intel_dp_mst_get_ddc_modes(struct drm_connector *connector)
285{
286 struct intel_connector *intel_connector = to_intel_connector(connector);
287 struct intel_dp *intel_dp = intel_connector->mst_port;
288 struct edid *edid;
289 int ret;
290
Dave Airlie0552f762016-03-09 11:14:38 +1000291 if (!intel_dp) {
292 return intel_connector_update_modes(connector, NULL);
293 }
Dave Airlie0e32b392014-05-02 14:02:48 +1000294
Dave Airlie0552f762016-03-09 11:14:38 +1000295 edid = drm_dp_mst_get_edid(connector, &intel_dp->mst_mgr, intel_connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000296 ret = intel_connector_update_modes(connector, edid);
297 kfree(edid);
298
299 return ret;
300}
301
302static enum drm_connector_status
Daniel Vetterf7f3d482014-10-22 11:06:44 +0200303intel_dp_mst_detect(struct drm_connector *connector, bool force)
Dave Airlie0e32b392014-05-02 14:02:48 +1000304{
305 struct intel_connector *intel_connector = to_intel_connector(connector);
306 struct intel_dp *intel_dp = intel_connector->mst_port;
307
Dave Airlie0552f762016-03-09 11:14:38 +1000308 if (!intel_dp)
309 return connector_status_disconnected;
Dave Airliec6a0aed2014-10-20 16:28:02 +1000310 return drm_dp_mst_detect_port(connector, &intel_dp->mst_mgr, intel_connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000311}
312
Dave Airlie0e32b392014-05-02 14:02:48 +1000313static int
314intel_dp_mst_set_property(struct drm_connector *connector,
315 struct drm_property *property,
316 uint64_t val)
317{
318 return 0;
319}
320
321static void
322intel_dp_mst_connector_destroy(struct drm_connector *connector)
323{
324 struct intel_connector *intel_connector = to_intel_connector(connector);
325
326 if (!IS_ERR_OR_NULL(intel_connector->edid))
327 kfree(intel_connector->edid);
328
329 drm_connector_cleanup(connector);
330 kfree(connector);
331}
332
333static const struct drm_connector_funcs intel_dp_mst_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +0200334 .dpms = drm_atomic_helper_connector_dpms,
Dave Airlie0e32b392014-05-02 14:02:48 +1000335 .detect = intel_dp_mst_detect,
336 .fill_modes = drm_helper_probe_single_connector_modes,
337 .set_property = intel_dp_mst_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -0800338 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilsonc191eca2016-06-17 11:40:33 +0100339 .early_unregister = intel_connector_unregister,
Dave Airlie0e32b392014-05-02 14:02:48 +1000340 .destroy = intel_dp_mst_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -0800341 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +0200342 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Dave Airlie0e32b392014-05-02 14:02:48 +1000343};
344
345static int intel_dp_mst_get_modes(struct drm_connector *connector)
346{
347 return intel_dp_mst_get_ddc_modes(connector);
348}
349
350static enum drm_mode_status
351intel_dp_mst_mode_valid(struct drm_connector *connector,
352 struct drm_display_mode *mode)
353{
Mika Kahola832d5bf2016-02-02 15:16:40 +0200354 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
355
Dave Airlie0e32b392014-05-02 14:02:48 +1000356 /* TODO - validate mode against available PBN for link */
357 if (mode->clock < 10000)
358 return MODE_CLOCK_LOW;
359
360 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
361 return MODE_H_ILLEGAL;
362
Mika Kahola832d5bf2016-02-02 15:16:40 +0200363 if (mode->clock > max_dotclk)
364 return MODE_CLOCK_HIGH;
365
Dave Airlie0e32b392014-05-02 14:02:48 +1000366 return MODE_OK;
367}
368
Daniel Vetter459485a2015-08-03 17:24:09 +0200369static struct drm_encoder *intel_mst_atomic_best_encoder(struct drm_connector *connector,
370 struct drm_connector_state *state)
371{
372 struct intel_connector *intel_connector = to_intel_connector(connector);
373 struct intel_dp *intel_dp = intel_connector->mst_port;
374 struct intel_crtc *crtc = to_intel_crtc(state->crtc);
375
Dave Airlie0552f762016-03-09 11:14:38 +1000376 if (!intel_dp)
377 return NULL;
Daniel Vetter459485a2015-08-03 17:24:09 +0200378 return &intel_dp->mst_encoders[crtc->pipe]->base.base;
379}
380
Dave Airlie0e32b392014-05-02 14:02:48 +1000381static struct drm_encoder *intel_mst_best_encoder(struct drm_connector *connector)
382{
383 struct intel_connector *intel_connector = to_intel_connector(connector);
384 struct intel_dp *intel_dp = intel_connector->mst_port;
Dave Airlie0552f762016-03-09 11:14:38 +1000385 if (!intel_dp)
386 return NULL;
Dave Airlie0e32b392014-05-02 14:02:48 +1000387 return &intel_dp->mst_encoders[0]->base.base;
388}
389
390static const struct drm_connector_helper_funcs intel_dp_mst_connector_helper_funcs = {
391 .get_modes = intel_dp_mst_get_modes,
392 .mode_valid = intel_dp_mst_mode_valid,
Daniel Vetter459485a2015-08-03 17:24:09 +0200393 .atomic_best_encoder = intel_mst_atomic_best_encoder,
Dave Airlie0e32b392014-05-02 14:02:48 +1000394 .best_encoder = intel_mst_best_encoder,
395};
396
397static void intel_dp_mst_encoder_destroy(struct drm_encoder *encoder)
398{
399 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder);
400
401 drm_encoder_cleanup(encoder);
402 kfree(intel_mst);
403}
404
405static const struct drm_encoder_funcs intel_dp_mst_enc_funcs = {
406 .destroy = intel_dp_mst_encoder_destroy,
407};
408
409static bool intel_dp_mst_get_hw_state(struct intel_connector *connector)
410{
Maarten Lankhorste85376c2015-08-27 13:13:31 +0200411 if (connector->encoder && connector->base.state->crtc) {
Dave Airlie0e32b392014-05-02 14:02:48 +1000412 enum pipe pipe;
413 if (!connector->encoder->get_hw_state(connector->encoder, &pipe))
414 return false;
415 return true;
416 }
417 return false;
418}
419
Chris Wilson7296c842014-07-22 20:10:28 +1000420static void intel_connector_add_to_fbdev(struct intel_connector *connector)
421{
Daniel Vetter06957262015-08-10 13:34:08 +0200422#ifdef CONFIG_DRM_FBDEV_EMULATION
Chris Wilson7296c842014-07-22 20:10:28 +1000423 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
Lukas Wunner54632ab2015-11-18 13:43:20 +0100424
425 if (dev_priv->fbdev)
426 drm_fb_helper_add_one_connector(&dev_priv->fbdev->helper,
427 &connector->base);
Chris Wilson7296c842014-07-22 20:10:28 +1000428#endif
429}
430
431static void intel_connector_remove_from_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_remove_one_connector(&dev_priv->fbdev->helper,
438 &connector->base);
Chris Wilson7296c842014-07-22 20:10:28 +1000439#endif
440}
441
Thierry Reding12e6cec2014-05-13 11:38:36 +0200442static 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 +1000443{
444 struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
445 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
446 struct drm_device *dev = intel_dig_port->base.base.dev;
Dave Airlie0e32b392014-05-02 14:02:48 +1000447 struct intel_connector *intel_connector;
448 struct drm_connector *connector;
449 int i;
450
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +0300451 intel_connector = intel_connector_alloc();
Dave Airlie0e32b392014-05-02 14:02:48 +1000452 if (!intel_connector)
453 return NULL;
454
455 connector = &intel_connector->base;
456 drm_connector_init(dev, connector, &intel_dp_mst_connector_funcs, DRM_MODE_CONNECTOR_DisplayPort);
457 drm_connector_helper_add(connector, &intel_dp_mst_connector_helper_funcs);
458
Dave Airlie0e32b392014-05-02 14:02:48 +1000459 intel_connector->get_hw_state = intel_dp_mst_get_hw_state;
460 intel_connector->mst_port = intel_dp;
461 intel_connector->port = port;
462
463 for (i = PIPE_A; i <= PIPE_C; i++) {
464 drm_mode_connector_attach_encoder(&intel_connector->base,
465 &intel_dp->mst_encoders[i]->base.base);
466 }
467 intel_dp_add_properties(intel_dp, connector);
468
469 drm_object_attach_property(&connector->base, dev->mode_config.path_property, 0);
Dave Airlie6f134d72014-10-20 16:30:50 +1000470 drm_object_attach_property(&connector->base, dev->mode_config.tile_property, 0);
471
Dave Airlie0e32b392014-05-02 14:02:48 +1000472 drm_mode_connector_set_path_property(connector, pathprop);
Dave Airlied9515c52015-09-16 17:55:23 +1000473 return connector;
474}
475
476static void intel_dp_register_mst_connector(struct drm_connector *connector)
477{
478 struct intel_connector *intel_connector = to_intel_connector(connector);
479 struct drm_device *dev = connector->dev;
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200480 drm_modeset_lock_all(dev);
Chris Wilson7296c842014-07-22 20:10:28 +1000481 intel_connector_add_to_fbdev(intel_connector);
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200482 drm_modeset_unlock_all(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000483 drm_connector_register(&intel_connector->base);
Dave Airlie0e32b392014-05-02 14:02:48 +1000484}
485
486static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
487 struct drm_connector *connector)
488{
489 struct intel_connector *intel_connector = to_intel_connector(connector);
490 struct drm_device *dev = connector->dev;
Maarten Lankhorst20fae982015-08-06 13:47:36 +0200491
Chris Wilsonc191eca2016-06-17 11:40:33 +0100492 drm_connector_unregister(connector);
Lyude1f771752016-03-16 15:18:04 -0400493
Dave Airlie0e32b392014-05-02 14:02:48 +1000494 /* need to nuke the connector */
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200495 drm_modeset_lock_all(dev);
Chris Wilson7296c842014-07-22 20:10:28 +1000496 intel_connector_remove_from_fbdev(intel_connector);
Dave Airlie0552f762016-03-09 11:14:38 +1000497 intel_connector->mst_port = NULL;
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200498 drm_modeset_unlock_all(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000499
Dave Airlie0552f762016-03-09 11:14:38 +1000500 drm_connector_unreference(&intel_connector->base);
Dave Airlie0e32b392014-05-02 14:02:48 +1000501 DRM_DEBUG_KMS("\n");
502}
503
504static void intel_dp_mst_hotplug(struct drm_dp_mst_topology_mgr *mgr)
505{
506 struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
507 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
508 struct drm_device *dev = intel_dig_port->base.base.dev;
509
510 drm_kms_helper_hotplug_event(dev);
511}
512
Julia Lawall69a0f892015-12-30 22:20:30 +0100513static const struct drm_dp_mst_topology_cbs mst_cbs = {
Dave Airlie0e32b392014-05-02 14:02:48 +1000514 .add_connector = intel_dp_add_mst_connector,
Dave Airlied9515c52015-09-16 17:55:23 +1000515 .register_connector = intel_dp_register_mst_connector,
Dave Airlie0e32b392014-05-02 14:02:48 +1000516 .destroy_connector = intel_dp_destroy_mst_connector,
517 .hotplug = intel_dp_mst_hotplug,
518};
519
520static struct intel_dp_mst_encoder *
521intel_dp_create_fake_mst_encoder(struct intel_digital_port *intel_dig_port, enum pipe pipe)
522{
523 struct intel_dp_mst_encoder *intel_mst;
524 struct intel_encoder *intel_encoder;
525 struct drm_device *dev = intel_dig_port->base.base.dev;
526
527 intel_mst = kzalloc(sizeof(*intel_mst), GFP_KERNEL);
528
529 if (!intel_mst)
530 return NULL;
531
532 intel_mst->pipe = pipe;
533 intel_encoder = &intel_mst->base;
534 intel_mst->primary = intel_dig_port;
535
536 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_mst_enc_funcs,
Ville Syrjälä580d8ed2016-05-27 20:59:24 +0300537 DRM_MODE_ENCODER_DPMST, "DP-MST %c", pipe_name(pipe));
Dave Airlie0e32b392014-05-02 14:02:48 +1000538
539 intel_encoder->type = INTEL_OUTPUT_DP_MST;
540 intel_encoder->crtc_mask = 0x7;
541 intel_encoder->cloneable = 0;
542
543 intel_encoder->compute_config = intel_dp_mst_compute_config;
544 intel_encoder->disable = intel_mst_disable_dp;
545 intel_encoder->post_disable = intel_mst_post_disable_dp;
546 intel_encoder->pre_enable = intel_mst_pre_enable_dp;
547 intel_encoder->enable = intel_mst_enable_dp;
548 intel_encoder->get_hw_state = intel_dp_mst_enc_get_hw_state;
549 intel_encoder->get_config = intel_dp_mst_enc_get_config;
550
551 return intel_mst;
552
553}
554
555static bool
556intel_dp_create_fake_mst_encoders(struct intel_digital_port *intel_dig_port)
557{
558 int i;
559 struct intel_dp *intel_dp = &intel_dig_port->dp;
560
561 for (i = PIPE_A; i <= PIPE_C; i++)
562 intel_dp->mst_encoders[i] = intel_dp_create_fake_mst_encoder(intel_dig_port, i);
563 return true;
564}
565
566int
567intel_dp_mst_encoder_init(struct intel_digital_port *intel_dig_port, int conn_base_id)
568{
569 struct intel_dp *intel_dp = &intel_dig_port->dp;
570 struct drm_device *dev = intel_dig_port->base.base.dev;
571 int ret;
572
573 intel_dp->can_mst = true;
574 intel_dp->mst_mgr.cbs = &mst_cbs;
575
576 /* create encoders */
577 intel_dp_create_fake_mst_encoders(intel_dig_port);
578 ret = drm_dp_mst_topology_mgr_init(&intel_dp->mst_mgr, dev->dev, &intel_dp->aux, 16, 3, conn_base_id);
579 if (ret) {
580 intel_dp->can_mst = false;
581 return ret;
582 }
583 return 0;
584}
585
586void
587intel_dp_mst_encoder_cleanup(struct intel_digital_port *intel_dig_port)
588{
589 struct intel_dp *intel_dp = &intel_dig_port->dp;
590
591 if (!intel_dp->can_mst)
592 return;
593
594 drm_dp_mst_topology_mgr_destroy(&intel_dp->mst_mgr);
595 /* encoders will get killed by normal cleanup */
596}