blob: 29ba4f6bd01f5f26d9d3a2d448dd45e19d71e01f [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,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +020034 struct intel_crtc_state *pipe_config,
35 struct drm_connector_state *conn_state)
Dave Airlie0e32b392014-05-02 14:02:48 +100036{
37 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;
Maarten Lankhorst1189e4f2016-08-09 17:04:06 +020041 int bpp;
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;
Dave Airlie0e32b392014-05-02 14:02:48 +100044 int mst_pbn;
45
46 pipe_config->dp_encoder_is_mst = true;
47 pipe_config->has_pch_encoder = false;
Dave Airlie0e32b392014-05-02 14:02:48 +100048 bpp = 24;
49 /*
50 * for MST we always configure max link bw - the spec doesn't
51 * seem to suggest we should do otherwise.
52 */
53 lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +020054
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +030055 pipe_config->lane_count = lane_count;
Dave Airlie0e32b392014-05-02 14:02:48 +100056
57 pipe_config->pipe_bpp = 24;
Ville Syrjälä04a60f92015-07-06 15:10:06 +030058 pipe_config->port_clock = intel_dp_max_link_rate(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +100059
Ander Conselvan de Oliveirae75f4772015-03-20 16:18:13 +020060 state = pipe_config->base.state;
61
Ville Syrjäläaad941d2015-09-25 16:38:56 +030062 mst_pbn = drm_dp_calc_pbn_mode(adjusted_mode->crtc_clock, bpp);
Dave Airlie0e32b392014-05-02 14:02:48 +100063
64 pipe_config->pbn = mst_pbn;
65 slots = drm_dp_find_vcpi_slots(&intel_dp->mst_mgr, mst_pbn);
66
67 intel_link_compute_m_n(bpp, lane_count,
68 adjusted_mode->crtc_clock,
69 pipe_config->port_clock,
70 &pipe_config->dp_m_n);
71
72 pipe_config->dp_m_n.tu = slots;
Ander Conselvan de Oliveira6fa2d192015-08-31 11:23:28 +030073
Dave Airlie0e32b392014-05-02 14:02:48 +100074 return true;
75
76}
77
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020078static void intel_mst_disable_dp(struct intel_encoder *encoder,
79 struct intel_crtc_state *old_crtc_state,
80 struct drm_connector_state *old_conn_state)
Dave Airlie0e32b392014-05-02 14:02:48 +100081{
82 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
83 struct intel_digital_port *intel_dig_port = intel_mst->primary;
84 struct intel_dp *intel_dp = &intel_dig_port->dp;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +020085 struct intel_connector *connector =
86 to_intel_connector(old_conn_state->connector);
Dave Airlie0e32b392014-05-02 14:02:48 +100087 int ret;
88
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +030089 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
Dave Airlie0e32b392014-05-02 14:02:48 +100090
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +020091 drm_dp_mst_reset_vcpi_slots(&intel_dp->mst_mgr, connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +100092
93 ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
94 if (ret) {
95 DRM_ERROR("failed to update payload %d\n", ret);
96 }
97}
98
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020099static void intel_mst_post_disable_dp(struct intel_encoder *encoder,
100 struct intel_crtc_state *old_crtc_state,
101 struct drm_connector_state *old_conn_state)
Dave Airlie0e32b392014-05-02 14:02:48 +1000102{
103 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
104 struct intel_digital_port *intel_dig_port = intel_mst->primary;
105 struct intel_dp *intel_dp = &intel_dig_port->dp;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200106 struct intel_connector *connector =
107 to_intel_connector(old_conn_state->connector);
Dave Airlie0e32b392014-05-02 14:02:48 +1000108
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300109 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
Dave Airlie0e32b392014-05-02 14:02:48 +1000110
111 /* this can fail */
112 drm_dp_check_act_status(&intel_dp->mst_mgr);
113 /* and this can also fail */
114 drm_dp_update_payload_part2(&intel_dp->mst_mgr);
115
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200116 drm_dp_mst_deallocate_vcpi(&intel_dp->mst_mgr, connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000117
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300118 intel_dp->active_mst_links--;
Dave Airlie0552f762016-03-09 11:14:38 +1000119
120 intel_mst->connector = NULL;
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300121 if (intel_dp->active_mst_links == 0) {
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +0200122 intel_dig_port->base.post_disable(&intel_dig_port->base,
123 NULL, NULL);
124
Dave Airlie0e32b392014-05-02 14:02:48 +1000125 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
126 }
127}
128
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +0200129static void intel_mst_pre_enable_dp(struct intel_encoder *encoder,
130 struct intel_crtc_state *pipe_config,
131 struct drm_connector_state *conn_state)
Dave Airlie0e32b392014-05-02 14:02:48 +1000132{
133 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
134 struct intel_digital_port *intel_dig_port = intel_mst->primary;
135 struct intel_dp *intel_dp = &intel_dig_port->dp;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200136 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000137 enum port port = intel_dig_port->port;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200138 struct intel_connector *connector =
139 to_intel_connector(conn_state->connector);
Dave Airlie0e32b392014-05-02 14:02:48 +1000140 int ret;
141 uint32_t temp;
Dave Airlie0e32b392014-05-02 14:02:48 +1000142 int slots;
Dave Airlie0e32b392014-05-02 14:02:48 +1000143
Maarten Lankhorste85376c2015-08-27 13:13:31 +0200144 /* MST encoders are bound to a crtc, not to a connector,
145 * force the mapping here for get_hw_state.
146 */
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200147 connector->encoder = encoder;
148 intel_mst->connector = connector;
Maarten Lankhorste85376c2015-08-27 13:13:31 +0200149
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300150 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
Dave Airlie0552f762016-03-09 11:14:38 +1000151
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300152 if (intel_dp->active_mst_links == 0) {
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200153 intel_ddi_clk_select(&intel_dig_port->base, pipe_config);
Dave Airlie0e32b392014-05-02 14:02:48 +1000154
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300155 intel_prepare_dp_ddi_buffers(&intel_dig_port->base);
156
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200157 intel_dp_set_link_params(intel_dp, pipe_config);
Ville Syrjälä901c2da2015-08-17 18:05:12 +0300158
Dave Airlie0e32b392014-05-02 14:02:48 +1000159 intel_ddi_init_dp_buf_reg(&intel_dig_port->base);
160
161 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
162
Dave Airlie0e32b392014-05-02 14:02:48 +1000163 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +1000164 intel_dp_stop_link_train(intel_dp);
165 }
166
167 ret = drm_dp_mst_allocate_vcpi(&intel_dp->mst_mgr,
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200168 connector->port,
169 pipe_config->pbn, &slots);
Dave Airlie0e32b392014-05-02 14:02:48 +1000170 if (ret == false) {
171 DRM_ERROR("failed to allocate vcpi\n");
172 return;
173 }
174
175
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300176 intel_dp->active_mst_links++;
Dave Airlie0e32b392014-05-02 14:02:48 +1000177 temp = I915_READ(DP_TP_STATUS(port));
178 I915_WRITE(DP_TP_STATUS(port), temp);
179
180 ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
181}
182
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +0200183static void intel_mst_enable_dp(struct intel_encoder *encoder,
184 struct intel_crtc_state *pipe_config,
185 struct drm_connector_state *conn_state)
Dave Airlie0e32b392014-05-02 14:02:48 +1000186{
187 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
188 struct intel_digital_port *intel_dig_port = intel_mst->primary;
189 struct intel_dp *intel_dp = &intel_dig_port->dp;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200190 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000191 enum port port = intel_dig_port->port;
192 int ret;
193
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300194 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
Dave Airlie0e32b392014-05-02 14:02:48 +1000195
Chris Wilson3016a312016-06-30 15:33:11 +0100196 if (intel_wait_for_register(dev_priv,
197 DP_TP_STATUS(port),
198 DP_TP_STATUS_ACT_SENT,
199 DP_TP_STATUS_ACT_SENT,
200 1))
Dave Airlie0e32b392014-05-02 14:02:48 +1000201 DRM_ERROR("Timed out waiting for ACT sent\n");
202
203 ret = drm_dp_check_act_status(&intel_dp->mst_mgr);
204
205 ret = drm_dp_update_payload_part2(&intel_dp->mst_mgr);
206}
207
208static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder *encoder,
209 enum pipe *pipe)
210{
211 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
212 *pipe = intel_mst->pipe;
Dave Airlie0552f762016-03-09 11:14:38 +1000213 if (intel_mst->connector)
Dave Airlie0e32b392014-05-02 14:02:48 +1000214 return true;
215 return false;
216}
217
218static void intel_dp_mst_enc_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200219 struct intel_crtc_state *pipe_config)
Dave Airlie0e32b392014-05-02 14:02:48 +1000220{
221 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
222 struct intel_digital_port *intel_dig_port = intel_mst->primary;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200223 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
224 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira0cb09a92015-01-30 12:17:23 +0200225 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Dave Airlie0e32b392014-05-02 14:02:48 +1000226 u32 temp, flags = 0;
227
Dave Airlie0e32b392014-05-02 14:02:48 +1000228 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
229 if (temp & TRANS_DDI_PHSYNC)
230 flags |= DRM_MODE_FLAG_PHSYNC;
231 else
232 flags |= DRM_MODE_FLAG_NHSYNC;
233 if (temp & TRANS_DDI_PVSYNC)
234 flags |= DRM_MODE_FLAG_PVSYNC;
235 else
236 flags |= DRM_MODE_FLAG_NVSYNC;
237
238 switch (temp & TRANS_DDI_BPC_MASK) {
239 case TRANS_DDI_BPC_6:
240 pipe_config->pipe_bpp = 18;
241 break;
242 case TRANS_DDI_BPC_8:
243 pipe_config->pipe_bpp = 24;
244 break;
245 case TRANS_DDI_BPC_10:
246 pipe_config->pipe_bpp = 30;
247 break;
248 case TRANS_DDI_BPC_12:
249 pipe_config->pipe_bpp = 36;
250 break;
251 default:
252 break;
253 }
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200254 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +0300255
256 pipe_config->lane_count =
257 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
258
Dave Airlie0e32b392014-05-02 14:02:48 +1000259 intel_dp_get_m_n(crtc, pipe_config);
260
261 intel_ddi_clock_get(&intel_dig_port->base, pipe_config);
262}
263
264static int intel_dp_mst_get_ddc_modes(struct drm_connector *connector)
265{
266 struct intel_connector *intel_connector = to_intel_connector(connector);
267 struct intel_dp *intel_dp = intel_connector->mst_port;
268 struct edid *edid;
269 int ret;
270
Dave Airlie0552f762016-03-09 11:14:38 +1000271 if (!intel_dp) {
272 return intel_connector_update_modes(connector, NULL);
273 }
Dave Airlie0e32b392014-05-02 14:02:48 +1000274
Dave Airlie0552f762016-03-09 11:14:38 +1000275 edid = drm_dp_mst_get_edid(connector, &intel_dp->mst_mgr, intel_connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000276 ret = intel_connector_update_modes(connector, edid);
277 kfree(edid);
278
279 return ret;
280}
281
282static enum drm_connector_status
Daniel Vetterf7f3d482014-10-22 11:06:44 +0200283intel_dp_mst_detect(struct drm_connector *connector, bool force)
Dave Airlie0e32b392014-05-02 14:02:48 +1000284{
285 struct intel_connector *intel_connector = to_intel_connector(connector);
286 struct intel_dp *intel_dp = intel_connector->mst_port;
287
Dave Airlie0552f762016-03-09 11:14:38 +1000288 if (!intel_dp)
289 return connector_status_disconnected;
Dave Airliec6a0aed2014-10-20 16:28:02 +1000290 return drm_dp_mst_detect_port(connector, &intel_dp->mst_mgr, intel_connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000291}
292
Dave Airlie0e32b392014-05-02 14:02:48 +1000293static int
294intel_dp_mst_set_property(struct drm_connector *connector,
295 struct drm_property *property,
296 uint64_t val)
297{
298 return 0;
299}
300
301static void
302intel_dp_mst_connector_destroy(struct drm_connector *connector)
303{
304 struct intel_connector *intel_connector = to_intel_connector(connector);
305
306 if (!IS_ERR_OR_NULL(intel_connector->edid))
307 kfree(intel_connector->edid);
308
309 drm_connector_cleanup(connector);
310 kfree(connector);
311}
312
313static const struct drm_connector_funcs intel_dp_mst_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +0200314 .dpms = drm_atomic_helper_connector_dpms,
Dave Airlie0e32b392014-05-02 14:02:48 +1000315 .detect = intel_dp_mst_detect,
316 .fill_modes = drm_helper_probe_single_connector_modes,
317 .set_property = intel_dp_mst_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -0800318 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson1ebaa0b2016-06-24 14:00:15 +0100319 .late_register = intel_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +0100320 .early_unregister = intel_connector_unregister,
Dave Airlie0e32b392014-05-02 14:02:48 +1000321 .destroy = intel_dp_mst_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -0800322 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +0200323 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Dave Airlie0e32b392014-05-02 14:02:48 +1000324};
325
326static int intel_dp_mst_get_modes(struct drm_connector *connector)
327{
328 return intel_dp_mst_get_ddc_modes(connector);
329}
330
331static enum drm_mode_status
332intel_dp_mst_mode_valid(struct drm_connector *connector,
333 struct drm_display_mode *mode)
334{
Mika Kahola832d5bf2016-02-02 15:16:40 +0200335 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
336
Dave Airlie0e32b392014-05-02 14:02:48 +1000337 /* TODO - validate mode against available PBN for link */
338 if (mode->clock < 10000)
339 return MODE_CLOCK_LOW;
340
341 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
342 return MODE_H_ILLEGAL;
343
Mika Kahola832d5bf2016-02-02 15:16:40 +0200344 if (mode->clock > max_dotclk)
345 return MODE_CLOCK_HIGH;
346
Dave Airlie0e32b392014-05-02 14:02:48 +1000347 return MODE_OK;
348}
349
Daniel Vetter459485a2015-08-03 17:24:09 +0200350static struct drm_encoder *intel_mst_atomic_best_encoder(struct drm_connector *connector,
351 struct drm_connector_state *state)
352{
353 struct intel_connector *intel_connector = to_intel_connector(connector);
354 struct intel_dp *intel_dp = intel_connector->mst_port;
355 struct intel_crtc *crtc = to_intel_crtc(state->crtc);
356
Dave Airlie0552f762016-03-09 11:14:38 +1000357 if (!intel_dp)
358 return NULL;
Daniel Vetter459485a2015-08-03 17:24:09 +0200359 return &intel_dp->mst_encoders[crtc->pipe]->base.base;
360}
361
Dave Airlie0e32b392014-05-02 14:02:48 +1000362static struct drm_encoder *intel_mst_best_encoder(struct drm_connector *connector)
363{
364 struct intel_connector *intel_connector = to_intel_connector(connector);
365 struct intel_dp *intel_dp = intel_connector->mst_port;
Dave Airlie0552f762016-03-09 11:14:38 +1000366 if (!intel_dp)
367 return NULL;
Dave Airlie0e32b392014-05-02 14:02:48 +1000368 return &intel_dp->mst_encoders[0]->base.base;
369}
370
371static const struct drm_connector_helper_funcs intel_dp_mst_connector_helper_funcs = {
372 .get_modes = intel_dp_mst_get_modes,
373 .mode_valid = intel_dp_mst_mode_valid,
Daniel Vetter459485a2015-08-03 17:24:09 +0200374 .atomic_best_encoder = intel_mst_atomic_best_encoder,
Dave Airlie0e32b392014-05-02 14:02:48 +1000375 .best_encoder = intel_mst_best_encoder,
376};
377
378static void intel_dp_mst_encoder_destroy(struct drm_encoder *encoder)
379{
380 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder);
381
382 drm_encoder_cleanup(encoder);
383 kfree(intel_mst);
384}
385
386static const struct drm_encoder_funcs intel_dp_mst_enc_funcs = {
387 .destroy = intel_dp_mst_encoder_destroy,
388};
389
390static bool intel_dp_mst_get_hw_state(struct intel_connector *connector)
391{
Maarten Lankhorste85376c2015-08-27 13:13:31 +0200392 if (connector->encoder && connector->base.state->crtc) {
Dave Airlie0e32b392014-05-02 14:02:48 +1000393 enum pipe pipe;
394 if (!connector->encoder->get_hw_state(connector->encoder, &pipe))
395 return false;
396 return true;
397 }
398 return false;
399}
400
Chris Wilson7296c842014-07-22 20:10:28 +1000401static void intel_connector_add_to_fbdev(struct intel_connector *connector)
402{
Daniel Vetter06957262015-08-10 13:34:08 +0200403#ifdef CONFIG_DRM_FBDEV_EMULATION
Chris Wilson7296c842014-07-22 20:10:28 +1000404 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
Lukas Wunner54632ab2015-11-18 13:43:20 +0100405
406 if (dev_priv->fbdev)
407 drm_fb_helper_add_one_connector(&dev_priv->fbdev->helper,
408 &connector->base);
Chris Wilson7296c842014-07-22 20:10:28 +1000409#endif
410}
411
412static void intel_connector_remove_from_fbdev(struct intel_connector *connector)
413{
Daniel Vetter06957262015-08-10 13:34:08 +0200414#ifdef CONFIG_DRM_FBDEV_EMULATION
Chris Wilson7296c842014-07-22 20:10:28 +1000415 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
Lukas Wunner54632ab2015-11-18 13:43:20 +0100416
417 if (dev_priv->fbdev)
418 drm_fb_helper_remove_one_connector(&dev_priv->fbdev->helper,
419 &connector->base);
Chris Wilson7296c842014-07-22 20:10:28 +1000420#endif
421}
422
Thierry Reding12e6cec2014-05-13 11:38:36 +0200423static 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 +1000424{
425 struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
426 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
427 struct drm_device *dev = intel_dig_port->base.base.dev;
Dave Airlie0e32b392014-05-02 14:02:48 +1000428 struct intel_connector *intel_connector;
429 struct drm_connector *connector;
430 int i;
431
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +0300432 intel_connector = intel_connector_alloc();
Dave Airlie0e32b392014-05-02 14:02:48 +1000433 if (!intel_connector)
434 return NULL;
435
436 connector = &intel_connector->base;
437 drm_connector_init(dev, connector, &intel_dp_mst_connector_funcs, DRM_MODE_CONNECTOR_DisplayPort);
438 drm_connector_helper_add(connector, &intel_dp_mst_connector_helper_funcs);
439
Dave Airlie0e32b392014-05-02 14:02:48 +1000440 intel_connector->get_hw_state = intel_dp_mst_get_hw_state;
441 intel_connector->mst_port = intel_dp;
442 intel_connector->port = port;
443
444 for (i = PIPE_A; i <= PIPE_C; i++) {
445 drm_mode_connector_attach_encoder(&intel_connector->base,
446 &intel_dp->mst_encoders[i]->base.base);
447 }
448 intel_dp_add_properties(intel_dp, connector);
449
450 drm_object_attach_property(&connector->base, dev->mode_config.path_property, 0);
Dave Airlie6f134d72014-10-20 16:30:50 +1000451 drm_object_attach_property(&connector->base, dev->mode_config.tile_property, 0);
452
Dave Airlie0e32b392014-05-02 14:02:48 +1000453 drm_mode_connector_set_path_property(connector, pathprop);
Dave Airlied9515c52015-09-16 17:55:23 +1000454 return connector;
455}
456
457static void intel_dp_register_mst_connector(struct drm_connector *connector)
458{
459 struct intel_connector *intel_connector = to_intel_connector(connector);
460 struct drm_device *dev = connector->dev;
Chris Wilson7a418e32016-06-24 14:00:14 +0100461
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200462 drm_modeset_lock_all(dev);
Chris Wilson7296c842014-07-22 20:10:28 +1000463 intel_connector_add_to_fbdev(intel_connector);
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200464 drm_modeset_unlock_all(dev);
Chris Wilson7a418e32016-06-24 14:00:14 +0100465
Dave Airlie0e32b392014-05-02 14:02:48 +1000466 drm_connector_register(&intel_connector->base);
Dave Airlie0e32b392014-05-02 14:02:48 +1000467}
468
469static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
470 struct drm_connector *connector)
471{
472 struct intel_connector *intel_connector = to_intel_connector(connector);
473 struct drm_device *dev = connector->dev;
Maarten Lankhorst20fae982015-08-06 13:47:36 +0200474
Chris Wilsonc191eca2016-06-17 11:40:33 +0100475 drm_connector_unregister(connector);
Lyude1f771752016-03-16 15:18:04 -0400476
Dave Airlie0e32b392014-05-02 14:02:48 +1000477 /* need to nuke the connector */
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200478 drm_modeset_lock_all(dev);
Chris Wilson7296c842014-07-22 20:10:28 +1000479 intel_connector_remove_from_fbdev(intel_connector);
Dave Airlie0552f762016-03-09 11:14:38 +1000480 intel_connector->mst_port = NULL;
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200481 drm_modeset_unlock_all(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000482
Dave Airlie0552f762016-03-09 11:14:38 +1000483 drm_connector_unreference(&intel_connector->base);
Dave Airlie0e32b392014-05-02 14:02:48 +1000484 DRM_DEBUG_KMS("\n");
485}
486
487static void intel_dp_mst_hotplug(struct drm_dp_mst_topology_mgr *mgr)
488{
489 struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
490 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
491 struct drm_device *dev = intel_dig_port->base.base.dev;
492
493 drm_kms_helper_hotplug_event(dev);
494}
495
Julia Lawall69a0f892015-12-30 22:20:30 +0100496static const struct drm_dp_mst_topology_cbs mst_cbs = {
Dave Airlie0e32b392014-05-02 14:02:48 +1000497 .add_connector = intel_dp_add_mst_connector,
Dave Airlied9515c52015-09-16 17:55:23 +1000498 .register_connector = intel_dp_register_mst_connector,
Dave Airlie0e32b392014-05-02 14:02:48 +1000499 .destroy_connector = intel_dp_destroy_mst_connector,
500 .hotplug = intel_dp_mst_hotplug,
501};
502
503static struct intel_dp_mst_encoder *
504intel_dp_create_fake_mst_encoder(struct intel_digital_port *intel_dig_port, enum pipe pipe)
505{
506 struct intel_dp_mst_encoder *intel_mst;
507 struct intel_encoder *intel_encoder;
508 struct drm_device *dev = intel_dig_port->base.base.dev;
509
510 intel_mst = kzalloc(sizeof(*intel_mst), GFP_KERNEL);
511
512 if (!intel_mst)
513 return NULL;
514
515 intel_mst->pipe = pipe;
516 intel_encoder = &intel_mst->base;
517 intel_mst->primary = intel_dig_port;
518
519 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_mst_enc_funcs,
Ville Syrjälä580d8ed2016-05-27 20:59:24 +0300520 DRM_MODE_ENCODER_DPMST, "DP-MST %c", pipe_name(pipe));
Dave Airlie0e32b392014-05-02 14:02:48 +1000521
522 intel_encoder->type = INTEL_OUTPUT_DP_MST;
523 intel_encoder->crtc_mask = 0x7;
524 intel_encoder->cloneable = 0;
525
526 intel_encoder->compute_config = intel_dp_mst_compute_config;
527 intel_encoder->disable = intel_mst_disable_dp;
528 intel_encoder->post_disable = intel_mst_post_disable_dp;
529 intel_encoder->pre_enable = intel_mst_pre_enable_dp;
530 intel_encoder->enable = intel_mst_enable_dp;
531 intel_encoder->get_hw_state = intel_dp_mst_enc_get_hw_state;
532 intel_encoder->get_config = intel_dp_mst_enc_get_config;
533
534 return intel_mst;
535
536}
537
538static bool
539intel_dp_create_fake_mst_encoders(struct intel_digital_port *intel_dig_port)
540{
541 int i;
542 struct intel_dp *intel_dp = &intel_dig_port->dp;
543
544 for (i = PIPE_A; i <= PIPE_C; i++)
545 intel_dp->mst_encoders[i] = intel_dp_create_fake_mst_encoder(intel_dig_port, i);
546 return true;
547}
548
549int
550intel_dp_mst_encoder_init(struct intel_digital_port *intel_dig_port, int conn_base_id)
551{
552 struct intel_dp *intel_dp = &intel_dig_port->dp;
553 struct drm_device *dev = intel_dig_port->base.base.dev;
554 int ret;
555
556 intel_dp->can_mst = true;
557 intel_dp->mst_mgr.cbs = &mst_cbs;
558
559 /* create encoders */
560 intel_dp_create_fake_mst_encoders(intel_dig_port);
561 ret = drm_dp_mst_topology_mgr_init(&intel_dp->mst_mgr, dev->dev, &intel_dp->aux, 16, 3, conn_base_id);
562 if (ret) {
563 intel_dp->can_mst = false;
564 return ret;
565 }
566 return 0;
567}
568
569void
570intel_dp_mst_encoder_cleanup(struct intel_digital_port *intel_dig_port)
571{
572 struct intel_dp *intel_dp = &intel_dig_port->dp;
573
574 if (!intel_dp->can_mst)
575 return;
576
577 drm_dp_mst_topology_mgr_destroy(&intel_dp->mst_mgr);
578 /* encoders will get killed by normal cleanup */
579}