blob: dd291d123219334b4477f6e01ca6459558c1009d [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;
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020042 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
80 mst_pbn = drm_dp_calc_pbn_mode(adjusted_mode->clock, bpp);
81
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;
91 return true;
92
93}
94
95static void intel_mst_disable_dp(struct intel_encoder *encoder)
96{
97 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
98 struct intel_digital_port *intel_dig_port = intel_mst->primary;
99 struct intel_dp *intel_dp = &intel_dig_port->dp;
100 int ret;
101
102 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
103
104 drm_dp_mst_reset_vcpi_slots(&intel_dp->mst_mgr, intel_mst->port);
105
106 ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
107 if (ret) {
108 DRM_ERROR("failed to update payload %d\n", ret);
109 }
110}
111
112static void intel_mst_post_disable_dp(struct intel_encoder *encoder)
113{
114 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
115 struct intel_digital_port *intel_dig_port = intel_mst->primary;
116 struct intel_dp *intel_dp = &intel_dig_port->dp;
117
118 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
119
120 /* this can fail */
121 drm_dp_check_act_status(&intel_dp->mst_mgr);
122 /* and this can also fail */
123 drm_dp_update_payload_part2(&intel_dp->mst_mgr);
124
125 drm_dp_mst_deallocate_vcpi(&intel_dp->mst_mgr, intel_mst->port);
126
127 intel_dp->active_mst_links--;
128 intel_mst->port = NULL;
129 if (intel_dp->active_mst_links == 0) {
130 intel_dig_port->base.post_disable(&intel_dig_port->base);
131 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
132 }
133}
134
135static void intel_mst_pre_enable_dp(struct intel_encoder *encoder)
136{
137 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
138 struct intel_digital_port *intel_dig_port = intel_mst->primary;
139 struct intel_dp *intel_dp = &intel_dig_port->dp;
140 struct drm_device *dev = encoder->base.dev;
141 struct drm_i915_private *dev_priv = dev->dev_private;
142 enum port port = intel_dig_port->port;
143 int ret;
144 uint32_t temp;
Ander Conselvan de Oliveira9b4fd8f2015-04-02 14:48:01 +0300145 struct intel_connector *found = NULL, *connector;
Dave Airlie0e32b392014-05-02 14:02:48 +1000146 int slots;
147 struct drm_crtc *crtc = encoder->base.crtc;
148 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
149
Ander Conselvan de Oliveira9b4fd8f2015-04-02 14:48:01 +0300150 for_each_intel_connector(dev, connector) {
151 if (connector->base.state->best_encoder == &encoder->base) {
152 found = connector;
Dave Airlie0e32b392014-05-02 14:02:48 +1000153 break;
154 }
155 }
156
157 if (!found) {
158 DRM_ERROR("can't find connector\n");
159 return;
160 }
161
162 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
163 intel_mst->port = found->port;
164
165 if (intel_dp->active_mst_links == 0) {
166 enum port port = intel_ddi_get_encoder_port(encoder);
167
Ville Syrjälä901c2da2015-08-17 18:05:12 +0300168 intel_dp_set_link_params(intel_dp, intel_crtc->config);
169
Satheeshakrishna M1ab23382014-08-22 09:49:06 +0530170 /* FIXME: add support for SKL */
171 if (INTEL_INFO(dev)->gen < 9)
172 I915_WRITE(PORT_CLK_SEL(port),
173 intel_crtc->config->ddi_pll_sel);
Dave Airlie0e32b392014-05-02 14:02:48 +1000174
175 intel_ddi_init_dp_buf_reg(&intel_dig_port->base);
176
177 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
178
179
180 intel_dp_start_link_train(intel_dp);
181 intel_dp_complete_link_train(intel_dp);
182 intel_dp_stop_link_train(intel_dp);
183 }
184
185 ret = drm_dp_mst_allocate_vcpi(&intel_dp->mst_mgr,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200186 intel_mst->port,
187 intel_crtc->config->pbn, &slots);
Dave Airlie0e32b392014-05-02 14:02:48 +1000188 if (ret == false) {
189 DRM_ERROR("failed to allocate vcpi\n");
190 return;
191 }
192
193
194 intel_dp->active_mst_links++;
195 temp = I915_READ(DP_TP_STATUS(port));
196 I915_WRITE(DP_TP_STATUS(port), temp);
197
198 ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
199}
200
201static void intel_mst_enable_dp(struct intel_encoder *encoder)
202{
203 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
204 struct intel_digital_port *intel_dig_port = intel_mst->primary;
205 struct intel_dp *intel_dp = &intel_dig_port->dp;
206 struct drm_device *dev = intel_dig_port->base.base.dev;
207 struct drm_i915_private *dev_priv = dev->dev_private;
208 enum port port = intel_dig_port->port;
209 int ret;
210
211 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
212
213 if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_ACT_SENT),
214 1))
215 DRM_ERROR("Timed out waiting for ACT sent\n");
216
217 ret = drm_dp_check_act_status(&intel_dp->mst_mgr);
218
219 ret = drm_dp_update_payload_part2(&intel_dp->mst_mgr);
220}
221
222static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder *encoder,
223 enum pipe *pipe)
224{
225 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
226 *pipe = intel_mst->pipe;
227 if (intel_mst->port)
228 return true;
229 return false;
230}
231
232static void intel_dp_mst_enc_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200233 struct intel_crtc_state *pipe_config)
Dave Airlie0e32b392014-05-02 14:02:48 +1000234{
235 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
236 struct intel_digital_port *intel_dig_port = intel_mst->primary;
237 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
238 struct drm_device *dev = encoder->base.dev;
239 struct drm_i915_private *dev_priv = dev->dev_private;
Ander Conselvan de Oliveira0cb09a92015-01-30 12:17:23 +0200240 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Dave Airlie0e32b392014-05-02 14:02:48 +1000241 u32 temp, flags = 0;
242
243 pipe_config->has_dp_encoder = true;
244
245 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
246 if (temp & TRANS_DDI_PHSYNC)
247 flags |= DRM_MODE_FLAG_PHSYNC;
248 else
249 flags |= DRM_MODE_FLAG_NHSYNC;
250 if (temp & TRANS_DDI_PVSYNC)
251 flags |= DRM_MODE_FLAG_PVSYNC;
252 else
253 flags |= DRM_MODE_FLAG_NVSYNC;
254
255 switch (temp & TRANS_DDI_BPC_MASK) {
256 case TRANS_DDI_BPC_6:
257 pipe_config->pipe_bpp = 18;
258 break;
259 case TRANS_DDI_BPC_8:
260 pipe_config->pipe_bpp = 24;
261 break;
262 case TRANS_DDI_BPC_10:
263 pipe_config->pipe_bpp = 30;
264 break;
265 case TRANS_DDI_BPC_12:
266 pipe_config->pipe_bpp = 36;
267 break;
268 default:
269 break;
270 }
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200271 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +0300272
273 pipe_config->lane_count =
274 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
275
Dave Airlie0e32b392014-05-02 14:02:48 +1000276 intel_dp_get_m_n(crtc, pipe_config);
277
278 intel_ddi_clock_get(&intel_dig_port->base, pipe_config);
279}
280
281static int intel_dp_mst_get_ddc_modes(struct drm_connector *connector)
282{
283 struct intel_connector *intel_connector = to_intel_connector(connector);
284 struct intel_dp *intel_dp = intel_connector->mst_port;
285 struct edid *edid;
286 int ret;
287
288 edid = drm_dp_mst_get_edid(connector, &intel_dp->mst_mgr, intel_connector->port);
289 if (!edid)
290 return 0;
291
292 ret = intel_connector_update_modes(connector, edid);
293 kfree(edid);
294
295 return ret;
296}
297
298static enum drm_connector_status
Daniel Vetterf7f3d482014-10-22 11:06:44 +0200299intel_dp_mst_detect(struct drm_connector *connector, bool force)
Dave Airlie0e32b392014-05-02 14:02:48 +1000300{
301 struct intel_connector *intel_connector = to_intel_connector(connector);
302 struct intel_dp *intel_dp = intel_connector->mst_port;
303
Dave Airliec6a0aed2014-10-20 16:28:02 +1000304 return drm_dp_mst_detect_port(connector, &intel_dp->mst_mgr, intel_connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000305}
306
Dave Airlie0e32b392014-05-02 14:02:48 +1000307static int
308intel_dp_mst_set_property(struct drm_connector *connector,
309 struct drm_property *property,
310 uint64_t val)
311{
312 return 0;
313}
314
315static void
316intel_dp_mst_connector_destroy(struct drm_connector *connector)
317{
318 struct intel_connector *intel_connector = to_intel_connector(connector);
319
320 if (!IS_ERR_OR_NULL(intel_connector->edid))
321 kfree(intel_connector->edid);
322
323 drm_connector_cleanup(connector);
324 kfree(connector);
325}
326
327static const struct drm_connector_funcs intel_dp_mst_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +0200328 .dpms = drm_atomic_helper_connector_dpms,
Dave Airlie0e32b392014-05-02 14:02:48 +1000329 .detect = intel_dp_mst_detect,
330 .fill_modes = drm_helper_probe_single_connector_modes,
331 .set_property = intel_dp_mst_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -0800332 .atomic_get_property = intel_connector_atomic_get_property,
Dave Airlie0e32b392014-05-02 14:02:48 +1000333 .destroy = intel_dp_mst_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -0800334 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +0200335 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Dave Airlie0e32b392014-05-02 14:02:48 +1000336};
337
338static int intel_dp_mst_get_modes(struct drm_connector *connector)
339{
340 return intel_dp_mst_get_ddc_modes(connector);
341}
342
343static enum drm_mode_status
344intel_dp_mst_mode_valid(struct drm_connector *connector,
345 struct drm_display_mode *mode)
346{
347 /* TODO - validate mode against available PBN for link */
348 if (mode->clock < 10000)
349 return MODE_CLOCK_LOW;
350
351 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
352 return MODE_H_ILLEGAL;
353
354 return MODE_OK;
355}
356
Daniel Vetter459485a2015-08-03 17:24:09 +0200357static struct drm_encoder *intel_mst_atomic_best_encoder(struct drm_connector *connector,
358 struct drm_connector_state *state)
359{
360 struct intel_connector *intel_connector = to_intel_connector(connector);
361 struct intel_dp *intel_dp = intel_connector->mst_port;
362 struct intel_crtc *crtc = to_intel_crtc(state->crtc);
363
364 return &intel_dp->mst_encoders[crtc->pipe]->base.base;
365}
366
Dave Airlie0e32b392014-05-02 14:02:48 +1000367static struct drm_encoder *intel_mst_best_encoder(struct drm_connector *connector)
368{
369 struct intel_connector *intel_connector = to_intel_connector(connector);
370 struct intel_dp *intel_dp = intel_connector->mst_port;
371 return &intel_dp->mst_encoders[0]->base.base;
372}
373
374static const struct drm_connector_helper_funcs intel_dp_mst_connector_helper_funcs = {
375 .get_modes = intel_dp_mst_get_modes,
376 .mode_valid = intel_dp_mst_mode_valid,
Daniel Vetter459485a2015-08-03 17:24:09 +0200377 .atomic_best_encoder = intel_mst_atomic_best_encoder,
Dave Airlie0e32b392014-05-02 14:02:48 +1000378 .best_encoder = intel_mst_best_encoder,
379};
380
381static void intel_dp_mst_encoder_destroy(struct drm_encoder *encoder)
382{
383 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder);
384
385 drm_encoder_cleanup(encoder);
386 kfree(intel_mst);
387}
388
389static const struct drm_encoder_funcs intel_dp_mst_enc_funcs = {
390 .destroy = intel_dp_mst_encoder_destroy,
391};
392
393static bool intel_dp_mst_get_hw_state(struct intel_connector *connector)
394{
395 if (connector->encoder) {
396 enum pipe pipe;
397 if (!connector->encoder->get_hw_state(connector->encoder, &pipe))
398 return false;
399 return true;
400 }
401 return false;
402}
403
Chris Wilson7296c842014-07-22 20:10:28 +1000404static void intel_connector_add_to_fbdev(struct intel_connector *connector)
405{
406#ifdef CONFIG_DRM_I915_FBDEV
407 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
408 drm_fb_helper_add_one_connector(&dev_priv->fbdev->helper, &connector->base);
409#endif
410}
411
412static void intel_connector_remove_from_fbdev(struct intel_connector *connector)
413{
414#ifdef CONFIG_DRM_I915_FBDEV
415 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
416 drm_fb_helper_remove_one_connector(&dev_priv->fbdev->helper, &connector->base);
417#endif
418}
419
Thierry Reding12e6cec2014-05-13 11:38:36 +0200420static 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 +1000421{
422 struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
423 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
424 struct drm_device *dev = intel_dig_port->base.base.dev;
Dave Airlie0e32b392014-05-02 14:02:48 +1000425 struct intel_connector *intel_connector;
426 struct drm_connector *connector;
427 int i;
428
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +0300429 intel_connector = intel_connector_alloc();
Dave Airlie0e32b392014-05-02 14:02:48 +1000430 if (!intel_connector)
431 return NULL;
432
433 connector = &intel_connector->base;
434 drm_connector_init(dev, connector, &intel_dp_mst_connector_funcs, DRM_MODE_CONNECTOR_DisplayPort);
435 drm_connector_helper_add(connector, &intel_dp_mst_connector_helper_funcs);
436
437 intel_connector->unregister = intel_connector_unregister;
438 intel_connector->get_hw_state = intel_dp_mst_get_hw_state;
439 intel_connector->mst_port = intel_dp;
440 intel_connector->port = port;
441
442 for (i = PIPE_A; i <= PIPE_C; i++) {
443 drm_mode_connector_attach_encoder(&intel_connector->base,
444 &intel_dp->mst_encoders[i]->base.base);
445 }
446 intel_dp_add_properties(intel_dp, connector);
447
448 drm_object_attach_property(&connector->base, dev->mode_config.path_property, 0);
Dave Airlie6f134d72014-10-20 16:30:50 +1000449 drm_object_attach_property(&connector->base, dev->mode_config.tile_property, 0);
450
Dave Airlie0e32b392014-05-02 14:02:48 +1000451 drm_mode_connector_set_path_property(connector, pathprop);
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200452 drm_modeset_lock_all(dev);
Chris Wilson7296c842014-07-22 20:10:28 +1000453 intel_connector_add_to_fbdev(intel_connector);
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200454 drm_modeset_unlock_all(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000455 drm_connector_register(&intel_connector->base);
456 return connector;
457}
458
459static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
460 struct drm_connector *connector)
461{
462 struct intel_connector *intel_connector = to_intel_connector(connector);
463 struct drm_device *dev = connector->dev;
Maarten Lankhorst20fae982015-08-06 13:47:36 +0200464
Dave Airlie0e32b392014-05-02 14:02:48 +1000465 /* need to nuke the connector */
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200466 drm_modeset_lock_all(dev);
Maarten Lankhorst20fae982015-08-06 13:47:36 +0200467 if (connector->state->crtc) {
468 struct drm_mode_set set;
469 int ret;
470
471 memset(&set, 0, sizeof(set));
472 set.crtc = connector->state->crtc,
473
474 ret = drm_atomic_helper_set_config(&set);
475
476 WARN(ret, "Disabling mst crtc failed with %i\n", ret);
477 }
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200478 drm_modeset_unlock_all(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000479
480 intel_connector->unregister(intel_connector);
481
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200482 drm_modeset_lock_all(dev);
Chris Wilson7296c842014-07-22 20:10:28 +1000483 intel_connector_remove_from_fbdev(intel_connector);
Dave Airlie0e32b392014-05-02 14:02:48 +1000484 drm_connector_cleanup(connector);
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200485 drm_modeset_unlock_all(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000486
Dave Airlie0e32b392014-05-02 14:02:48 +1000487 kfree(intel_connector);
488 DRM_DEBUG_KMS("\n");
489}
490
491static void intel_dp_mst_hotplug(struct drm_dp_mst_topology_mgr *mgr)
492{
493 struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
494 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
495 struct drm_device *dev = intel_dig_port->base.base.dev;
496
497 drm_kms_helper_hotplug_event(dev);
498}
499
500static struct drm_dp_mst_topology_cbs mst_cbs = {
501 .add_connector = intel_dp_add_mst_connector,
502 .destroy_connector = intel_dp_destroy_mst_connector,
503 .hotplug = intel_dp_mst_hotplug,
504};
505
506static struct intel_dp_mst_encoder *
507intel_dp_create_fake_mst_encoder(struct intel_digital_port *intel_dig_port, enum pipe pipe)
508{
509 struct intel_dp_mst_encoder *intel_mst;
510 struct intel_encoder *intel_encoder;
511 struct drm_device *dev = intel_dig_port->base.base.dev;
512
513 intel_mst = kzalloc(sizeof(*intel_mst), GFP_KERNEL);
514
515 if (!intel_mst)
516 return NULL;
517
518 intel_mst->pipe = pipe;
519 intel_encoder = &intel_mst->base;
520 intel_mst->primary = intel_dig_port;
521
522 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_mst_enc_funcs,
523 DRM_MODE_ENCODER_DPMST);
524
525 intel_encoder->type = INTEL_OUTPUT_DP_MST;
526 intel_encoder->crtc_mask = 0x7;
527 intel_encoder->cloneable = 0;
528
529 intel_encoder->compute_config = intel_dp_mst_compute_config;
530 intel_encoder->disable = intel_mst_disable_dp;
531 intel_encoder->post_disable = intel_mst_post_disable_dp;
532 intel_encoder->pre_enable = intel_mst_pre_enable_dp;
533 intel_encoder->enable = intel_mst_enable_dp;
534 intel_encoder->get_hw_state = intel_dp_mst_enc_get_hw_state;
535 intel_encoder->get_config = intel_dp_mst_enc_get_config;
536
537 return intel_mst;
538
539}
540
541static bool
542intel_dp_create_fake_mst_encoders(struct intel_digital_port *intel_dig_port)
543{
544 int i;
545 struct intel_dp *intel_dp = &intel_dig_port->dp;
546
547 for (i = PIPE_A; i <= PIPE_C; i++)
548 intel_dp->mst_encoders[i] = intel_dp_create_fake_mst_encoder(intel_dig_port, i);
549 return true;
550}
551
552int
553intel_dp_mst_encoder_init(struct intel_digital_port *intel_dig_port, int conn_base_id)
554{
555 struct intel_dp *intel_dp = &intel_dig_port->dp;
556 struct drm_device *dev = intel_dig_port->base.base.dev;
557 int ret;
558
559 intel_dp->can_mst = true;
560 intel_dp->mst_mgr.cbs = &mst_cbs;
561
562 /* create encoders */
563 intel_dp_create_fake_mst_encoders(intel_dig_port);
564 ret = drm_dp_mst_topology_mgr_init(&intel_dp->mst_mgr, dev->dev, &intel_dp->aux, 16, 3, conn_base_id);
565 if (ret) {
566 intel_dp->can_mst = false;
567 return ret;
568 }
569 return 0;
570}
571
572void
573intel_dp_mst_encoder_cleanup(struct intel_digital_port *intel_dig_port)
574{
575 struct intel_dp *intel_dp = &intel_dig_port->dp;
576
577 if (!intel_dp->can_mst)
578 return;
579
580 drm_dp_mst_topology_mgr_destroy(&intel_dp->mst_mgr);
581 /* encoders will get killed by normal cleanup */
582}