blob: 989e25577ac0445f9e7632a575a6de38d7f9ec49 [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;
Libin Yang7f9e7752016-11-28 20:07:07 +080040 struct intel_connector *connector =
41 to_intel_connector(conn_state->connector);
Ander Conselvan de Oliveirae75f4772015-03-20 16:18:13 +020042 struct drm_atomic_state *state;
Maarten Lankhorst1189e4f2016-08-09 17:04:06 +020043 int bpp;
Ville Syrjälä04a60f92015-07-06 15:10:06 +030044 int lane_count, slots;
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +030045 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Dave Airlie0e32b392014-05-02 14:02:48 +100046 int mst_pbn;
Jani Nikulab31e85e2017-05-18 14:10:25 +030047 bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc,
48 DP_DPCD_QUIRK_LIMITED_M_N);
Dave Airlie0e32b392014-05-02 14:02:48 +100049
Dave Airlie0e32b392014-05-02 14:02:48 +100050 pipe_config->has_pch_encoder = false;
Dave Airlie0e32b392014-05-02 14:02:48 +100051 bpp = 24;
Manasi Navare611032b2017-01-24 08:21:49 -080052 if (intel_dp->compliance.test_data.bpc) {
53 bpp = intel_dp->compliance.test_data.bpc * 3;
54 DRM_DEBUG_KMS("Setting pipe bpp to %d\n",
55 bpp);
56 }
Dave Airlie0e32b392014-05-02 14:02:48 +100057 /*
58 * for MST we always configure max link bw - the spec doesn't
59 * seem to suggest we should do otherwise.
60 */
61 lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +020062
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +030063 pipe_config->lane_count = lane_count;
Dave Airlie0e32b392014-05-02 14:02:48 +100064
Manasi Navare611032b2017-01-24 08:21:49 -080065 pipe_config->pipe_bpp = bpp;
Ville Syrjälä04a60f92015-07-06 15:10:06 +030066 pipe_config->port_clock = intel_dp_max_link_rate(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +100067
Ander Conselvan de Oliveirae75f4772015-03-20 16:18:13 +020068 state = pipe_config->base.state;
69
Libin Yang7f9e7752016-11-28 20:07:07 +080070 if (drm_dp_mst_port_has_audio(&intel_dp->mst_mgr, connector->port))
71 pipe_config->has_audio = true;
Ville Syrjäläaad941d2015-09-25 16:38:56 +030072 mst_pbn = drm_dp_calc_pbn_mode(adjusted_mode->crtc_clock, bpp);
Dave Airlie0e32b392014-05-02 14:02:48 +100073
74 pipe_config->pbn = mst_pbn;
75 slots = drm_dp_find_vcpi_slots(&intel_dp->mst_mgr, mst_pbn);
76
77 intel_link_compute_m_n(bpp, lane_count,
78 adjusted_mode->crtc_clock,
79 pipe_config->port_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +030080 &pipe_config->dp_m_n,
81 reduce_m_n);
Dave Airlie0e32b392014-05-02 14:02:48 +100082
83 pipe_config->dp_m_n.tu = slots;
Ander Conselvan de Oliveira6fa2d192015-08-31 11:23:28 +030084
Dave Airlie0e32b392014-05-02 14:02:48 +100085 return true;
86
87}
88
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020089static void intel_mst_disable_dp(struct intel_encoder *encoder,
90 struct intel_crtc_state *old_crtc_state,
91 struct drm_connector_state *old_conn_state)
Dave Airlie0e32b392014-05-02 14:02:48 +100092{
93 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
94 struct intel_digital_port *intel_dig_port = intel_mst->primary;
95 struct intel_dp *intel_dp = &intel_dig_port->dp;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +020096 struct intel_connector *connector =
97 to_intel_connector(old_conn_state->connector);
Dave Airlie0e32b392014-05-02 14:02:48 +100098 int ret;
99
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300100 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
Dave Airlie0e32b392014-05-02 14:02:48 +1000101
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200102 drm_dp_mst_reset_vcpi_slots(&intel_dp->mst_mgr, connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000103
104 ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
105 if (ret) {
106 DRM_ERROR("failed to update payload %d\n", ret);
107 }
Maarten Lankhorst37255d82016-12-15 15:29:43 +0100108 if (old_crtc_state->has_audio)
Libin Yang7f9e7752016-11-28 20:07:07 +0800109 intel_audio_codec_disable(encoder);
Dave Airlie0e32b392014-05-02 14:02:48 +1000110}
111
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +0200112static void intel_mst_post_disable_dp(struct intel_encoder *encoder,
113 struct intel_crtc_state *old_crtc_state,
114 struct drm_connector_state *old_conn_state)
Dave Airlie0e32b392014-05-02 14:02:48 +1000115{
116 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
117 struct intel_digital_port *intel_dig_port = intel_mst->primary;
118 struct intel_dp *intel_dp = &intel_dig_port->dp;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200119 struct intel_connector *connector =
120 to_intel_connector(old_conn_state->connector);
Dave Airlie0e32b392014-05-02 14:02:48 +1000121
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300122 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
Dave Airlie0e32b392014-05-02 14:02:48 +1000123
124 /* this can fail */
125 drm_dp_check_act_status(&intel_dp->mst_mgr);
126 /* and this can also fail */
127 drm_dp_update_payload_part2(&intel_dp->mst_mgr);
128
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200129 drm_dp_mst_deallocate_vcpi(&intel_dp->mst_mgr, connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000130
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300131 intel_dp->active_mst_links--;
Dave Airlie0552f762016-03-09 11:14:38 +1000132
133 intel_mst->connector = NULL;
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300134 if (intel_dp->active_mst_links == 0) {
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +0200135 intel_dig_port->base.post_disable(&intel_dig_port->base,
136 NULL, NULL);
137
Dave Airlie0e32b392014-05-02 14:02:48 +1000138 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
139 }
140}
141
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +0200142static void intel_mst_pre_enable_dp(struct intel_encoder *encoder,
143 struct intel_crtc_state *pipe_config,
144 struct drm_connector_state *conn_state)
Dave Airlie0e32b392014-05-02 14:02:48 +1000145{
146 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
147 struct intel_digital_port *intel_dig_port = intel_mst->primary;
148 struct intel_dp *intel_dp = &intel_dig_port->dp;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200149 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000150 enum port port = intel_dig_port->port;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200151 struct intel_connector *connector =
152 to_intel_connector(conn_state->connector);
Dave Airlie0e32b392014-05-02 14:02:48 +1000153 int ret;
154 uint32_t temp;
Dave Airlie0e32b392014-05-02 14:02:48 +1000155
Maarten Lankhorste85376c2015-08-27 13:13:31 +0200156 /* MST encoders are bound to a crtc, not to a connector,
157 * force the mapping here for get_hw_state.
158 */
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200159 connector->encoder = encoder;
160 intel_mst->connector = connector;
Maarten Lankhorste85376c2015-08-27 13:13:31 +0200161
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300162 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
Dave Airlie0552f762016-03-09 11:14:38 +1000163
Ander Conselvan de Oliveirae081c842017-03-02 14:58:57 +0200164 if (intel_dp->active_mst_links == 0)
165 intel_dig_port->base.pre_enable(&intel_dig_port->base,
166 pipe_config, NULL);
Dave Airlie0e32b392014-05-02 14:02:48 +1000167
168 ret = drm_dp_mst_allocate_vcpi(&intel_dp->mst_mgr,
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200169 connector->port,
Pandiyan, Dhinakaran1e797f52017-03-16 00:10:26 -0700170 pipe_config->pbn,
171 pipe_config->dp_m_n.tu);
Dave Airlie0e32b392014-05-02 14:02:48 +1000172 if (ret == false) {
173 DRM_ERROR("failed to allocate vcpi\n");
174 return;
175 }
176
177
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300178 intel_dp->active_mst_links++;
Dave Airlie0e32b392014-05-02 14:02:48 +1000179 temp = I915_READ(DP_TP_STATUS(port));
180 I915_WRITE(DP_TP_STATUS(port), temp);
181
182 ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
183}
184
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +0200185static void intel_mst_enable_dp(struct intel_encoder *encoder,
186 struct intel_crtc_state *pipe_config,
187 struct drm_connector_state *conn_state)
Dave Airlie0e32b392014-05-02 14:02:48 +1000188{
189 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
190 struct intel_digital_port *intel_dig_port = intel_mst->primary;
191 struct intel_dp *intel_dp = &intel_dig_port->dp;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200192 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000193 enum port port = intel_dig_port->port;
194 int ret;
195
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300196 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
Dave Airlie0e32b392014-05-02 14:02:48 +1000197
Chris Wilson3016a312016-06-30 15:33:11 +0100198 if (intel_wait_for_register(dev_priv,
199 DP_TP_STATUS(port),
200 DP_TP_STATUS_ACT_SENT,
201 DP_TP_STATUS_ACT_SENT,
202 1))
Dave Airlie0e32b392014-05-02 14:02:48 +1000203 DRM_ERROR("Timed out waiting for ACT sent\n");
204
205 ret = drm_dp_check_act_status(&intel_dp->mst_mgr);
206
207 ret = drm_dp_update_payload_part2(&intel_dp->mst_mgr);
Maarten Lankhorst37255d82016-12-15 15:29:43 +0100208 if (pipe_config->has_audio)
Libin Yang7f9e7752016-11-28 20:07:07 +0800209 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Dave Airlie0e32b392014-05-02 14:02:48 +1000210}
211
212static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder *encoder,
213 enum pipe *pipe)
214{
215 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
216 *pipe = intel_mst->pipe;
Dave Airlie0552f762016-03-09 11:14:38 +1000217 if (intel_mst->connector)
Dave Airlie0e32b392014-05-02 14:02:48 +1000218 return true;
219 return false;
220}
221
222static void intel_dp_mst_enc_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200223 struct intel_crtc_state *pipe_config)
Dave Airlie0e32b392014-05-02 14:02:48 +1000224{
225 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
226 struct intel_digital_port *intel_dig_port = intel_mst->primary;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200227 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
228 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira0cb09a92015-01-30 12:17:23 +0200229 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Dave Airlie0e32b392014-05-02 14:02:48 +1000230 u32 temp, flags = 0;
231
Libin Yang7f9e7752016-11-28 20:07:07 +0800232 pipe_config->has_audio =
233 intel_ddi_is_audio_enabled(dev_priv, crtc);
234
Dave Airlie0e32b392014-05-02 14:02:48 +1000235 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
236 if (temp & TRANS_DDI_PHSYNC)
237 flags |= DRM_MODE_FLAG_PHSYNC;
238 else
239 flags |= DRM_MODE_FLAG_NHSYNC;
240 if (temp & TRANS_DDI_PVSYNC)
241 flags |= DRM_MODE_FLAG_PVSYNC;
242 else
243 flags |= DRM_MODE_FLAG_NVSYNC;
244
245 switch (temp & TRANS_DDI_BPC_MASK) {
246 case TRANS_DDI_BPC_6:
247 pipe_config->pipe_bpp = 18;
248 break;
249 case TRANS_DDI_BPC_8:
250 pipe_config->pipe_bpp = 24;
251 break;
252 case TRANS_DDI_BPC_10:
253 pipe_config->pipe_bpp = 30;
254 break;
255 case TRANS_DDI_BPC_12:
256 pipe_config->pipe_bpp = 36;
257 break;
258 default:
259 break;
260 }
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200261 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +0300262
263 pipe_config->lane_count =
264 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
265
Dave Airlie0e32b392014-05-02 14:02:48 +1000266 intel_dp_get_m_n(crtc, pipe_config);
267
268 intel_ddi_clock_get(&intel_dig_port->base, pipe_config);
269}
270
271static int intel_dp_mst_get_ddc_modes(struct drm_connector *connector)
272{
273 struct intel_connector *intel_connector = to_intel_connector(connector);
274 struct intel_dp *intel_dp = intel_connector->mst_port;
275 struct edid *edid;
276 int ret;
277
Dave Airlie0552f762016-03-09 11:14:38 +1000278 if (!intel_dp) {
279 return intel_connector_update_modes(connector, NULL);
280 }
Dave Airlie0e32b392014-05-02 14:02:48 +1000281
Dave Airlie0552f762016-03-09 11:14:38 +1000282 edid = drm_dp_mst_get_edid(connector, &intel_dp->mst_mgr, intel_connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000283 ret = intel_connector_update_modes(connector, edid);
284 kfree(edid);
285
286 return ret;
287}
288
289static enum drm_connector_status
Daniel Vetterf7f3d482014-10-22 11:06:44 +0200290intel_dp_mst_detect(struct drm_connector *connector, bool force)
Dave Airlie0e32b392014-05-02 14:02:48 +1000291{
292 struct intel_connector *intel_connector = to_intel_connector(connector);
293 struct intel_dp *intel_dp = intel_connector->mst_port;
294
Dave Airlie0552f762016-03-09 11:14:38 +1000295 if (!intel_dp)
296 return connector_status_disconnected;
Dave Airliec6a0aed2014-10-20 16:28:02 +1000297 return drm_dp_mst_detect_port(connector, &intel_dp->mst_mgr, intel_connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000298}
299
Dave Airlie0e32b392014-05-02 14:02:48 +1000300static int
301intel_dp_mst_set_property(struct drm_connector *connector,
302 struct drm_property *property,
303 uint64_t val)
304{
305 return 0;
306}
307
308static void
309intel_dp_mst_connector_destroy(struct drm_connector *connector)
310{
311 struct intel_connector *intel_connector = to_intel_connector(connector);
312
313 if (!IS_ERR_OR_NULL(intel_connector->edid))
314 kfree(intel_connector->edid);
315
316 drm_connector_cleanup(connector);
317 kfree(connector);
318}
319
320static const struct drm_connector_funcs intel_dp_mst_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +0200321 .dpms = drm_atomic_helper_connector_dpms,
Dave Airlie0e32b392014-05-02 14:02:48 +1000322 .detect = intel_dp_mst_detect,
323 .fill_modes = drm_helper_probe_single_connector_modes,
324 .set_property = intel_dp_mst_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -0800325 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson1ebaa0b2016-06-24 14:00:15 +0100326 .late_register = intel_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +0100327 .early_unregister = intel_connector_unregister,
Dave Airlie0e32b392014-05-02 14:02:48 +1000328 .destroy = intel_dp_mst_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -0800329 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +0200330 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Dave Airlie0e32b392014-05-02 14:02:48 +1000331};
332
333static int intel_dp_mst_get_modes(struct drm_connector *connector)
334{
335 return intel_dp_mst_get_ddc_modes(connector);
336}
337
338static enum drm_mode_status
339intel_dp_mst_mode_valid(struct drm_connector *connector,
340 struct drm_display_mode *mode)
341{
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800342 struct intel_connector *intel_connector = to_intel_connector(connector);
343 struct intel_dp *intel_dp = intel_connector->mst_port;
Mika Kahola832d5bf2016-02-02 15:16:40 +0200344 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800345 int bpp = 24; /* MST uses fixed bpp */
346 int max_rate, mode_rate, max_lanes, max_link_clock;
347
348 max_link_clock = intel_dp_max_link_rate(intel_dp);
349 max_lanes = drm_dp_max_lane_count(intel_dp->dpcd);
350
351 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
352 mode_rate = intel_dp_link_required(mode->clock, bpp);
Mika Kahola832d5bf2016-02-02 15:16:40 +0200353
Dave Airlie0e32b392014-05-02 14:02:48 +1000354 /* TODO - validate mode against available PBN for link */
355 if (mode->clock < 10000)
356 return MODE_CLOCK_LOW;
357
358 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
359 return MODE_H_ILLEGAL;
360
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800361 if (mode_rate > max_rate || mode->clock > max_dotclk)
Mika Kahola832d5bf2016-02-02 15:16:40 +0200362 return MODE_CLOCK_HIGH;
363
Dave Airlie0e32b392014-05-02 14:02:48 +1000364 return MODE_OK;
365}
366
Daniel Vetter459485a2015-08-03 17:24:09 +0200367static struct drm_encoder *intel_mst_atomic_best_encoder(struct drm_connector *connector,
368 struct drm_connector_state *state)
369{
370 struct intel_connector *intel_connector = to_intel_connector(connector);
371 struct intel_dp *intel_dp = intel_connector->mst_port;
372 struct intel_crtc *crtc = to_intel_crtc(state->crtc);
373
Dave Airlie0552f762016-03-09 11:14:38 +1000374 if (!intel_dp)
375 return NULL;
Daniel Vetter459485a2015-08-03 17:24:09 +0200376 return &intel_dp->mst_encoders[crtc->pipe]->base.base;
377}
378
Dave Airlie0e32b392014-05-02 14:02:48 +1000379static struct drm_encoder *intel_mst_best_encoder(struct drm_connector *connector)
380{
381 struct intel_connector *intel_connector = to_intel_connector(connector);
382 struct intel_dp *intel_dp = intel_connector->mst_port;
Dave Airlie0552f762016-03-09 11:14:38 +1000383 if (!intel_dp)
384 return NULL;
Dave Airlie0e32b392014-05-02 14:02:48 +1000385 return &intel_dp->mst_encoders[0]->base.base;
386}
387
388static const struct drm_connector_helper_funcs intel_dp_mst_connector_helper_funcs = {
389 .get_modes = intel_dp_mst_get_modes,
390 .mode_valid = intel_dp_mst_mode_valid,
Daniel Vetter459485a2015-08-03 17:24:09 +0200391 .atomic_best_encoder = intel_mst_atomic_best_encoder,
Dave Airlie0e32b392014-05-02 14:02:48 +1000392 .best_encoder = intel_mst_best_encoder,
393};
394
395static void intel_dp_mst_encoder_destroy(struct drm_encoder *encoder)
396{
397 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder);
398
399 drm_encoder_cleanup(encoder);
400 kfree(intel_mst);
401}
402
403static const struct drm_encoder_funcs intel_dp_mst_enc_funcs = {
404 .destroy = intel_dp_mst_encoder_destroy,
405};
406
407static bool intel_dp_mst_get_hw_state(struct intel_connector *connector)
408{
Maarten Lankhorste85376c2015-08-27 13:13:31 +0200409 if (connector->encoder && connector->base.state->crtc) {
Dave Airlie0e32b392014-05-02 14:02:48 +1000410 enum pipe pipe;
411 if (!connector->encoder->get_hw_state(connector->encoder, &pipe))
412 return false;
413 return true;
414 }
415 return false;
416}
417
Chris Wilson7296c842014-07-22 20:10:28 +1000418static void intel_connector_add_to_fbdev(struct intel_connector *connector)
419{
Daniel Vetter06957262015-08-10 13:34:08 +0200420#ifdef CONFIG_DRM_FBDEV_EMULATION
Chris Wilson7296c842014-07-22 20:10:28 +1000421 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
Lukas Wunner54632ab2015-11-18 13:43:20 +0100422
423 if (dev_priv->fbdev)
424 drm_fb_helper_add_one_connector(&dev_priv->fbdev->helper,
425 &connector->base);
Chris Wilson7296c842014-07-22 20:10:28 +1000426#endif
427}
428
429static void intel_connector_remove_from_fbdev(struct intel_connector *connector)
430{
Daniel Vetter06957262015-08-10 13:34:08 +0200431#ifdef CONFIG_DRM_FBDEV_EMULATION
Chris Wilson7296c842014-07-22 20:10:28 +1000432 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
Lukas Wunner54632ab2015-11-18 13:43:20 +0100433
434 if (dev_priv->fbdev)
435 drm_fb_helper_remove_one_connector(&dev_priv->fbdev->helper,
436 &connector->base);
Chris Wilson7296c842014-07-22 20:10:28 +1000437#endif
438}
439
Thierry Reding12e6cec2014-05-13 11:38:36 +0200440static 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 +1000441{
442 struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
443 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
444 struct drm_device *dev = intel_dig_port->base.base.dev;
Dave Airlie0e32b392014-05-02 14:02:48 +1000445 struct intel_connector *intel_connector;
446 struct drm_connector *connector;
447 int i;
448
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +0300449 intel_connector = intel_connector_alloc();
Dave Airlie0e32b392014-05-02 14:02:48 +1000450 if (!intel_connector)
451 return NULL;
452
453 connector = &intel_connector->base;
454 drm_connector_init(dev, connector, &intel_dp_mst_connector_funcs, DRM_MODE_CONNECTOR_DisplayPort);
455 drm_connector_helper_add(connector, &intel_dp_mst_connector_helper_funcs);
456
Dave Airlie0e32b392014-05-02 14:02:48 +1000457 intel_connector->get_hw_state = intel_dp_mst_get_hw_state;
458 intel_connector->mst_port = intel_dp;
459 intel_connector->port = port;
460
461 for (i = PIPE_A; i <= PIPE_C; i++) {
462 drm_mode_connector_attach_encoder(&intel_connector->base,
463 &intel_dp->mst_encoders[i]->base.base);
464 }
465 intel_dp_add_properties(intel_dp, connector);
466
467 drm_object_attach_property(&connector->base, dev->mode_config.path_property, 0);
Dave Airlie6f134d72014-10-20 16:30:50 +1000468 drm_object_attach_property(&connector->base, dev->mode_config.tile_property, 0);
469
Dave Airlie0e32b392014-05-02 14:02:48 +1000470 drm_mode_connector_set_path_property(connector, pathprop);
Dave Airlied9515c52015-09-16 17:55:23 +1000471 return connector;
472}
473
474static void intel_dp_register_mst_connector(struct drm_connector *connector)
475{
476 struct intel_connector *intel_connector = to_intel_connector(connector);
477 struct drm_device *dev = connector->dev;
Chris Wilson7a418e32016-06-24 14:00:14 +0100478
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200479 drm_modeset_lock_all(dev);
Chris Wilson7296c842014-07-22 20:10:28 +1000480 intel_connector_add_to_fbdev(intel_connector);
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200481 drm_modeset_unlock_all(dev);
Chris Wilson7a418e32016-06-24 14:00:14 +0100482
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;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +0200540 intel_encoder->power_domain = intel_dig_port->base.power_domain;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -0700541 intel_encoder->port = intel_dig_port->port;
Dave Airlie0e32b392014-05-02 14:02:48 +1000542 intel_encoder->crtc_mask = 0x7;
543 intel_encoder->cloneable = 0;
544
545 intel_encoder->compute_config = intel_dp_mst_compute_config;
546 intel_encoder->disable = intel_mst_disable_dp;
547 intel_encoder->post_disable = intel_mst_post_disable_dp;
548 intel_encoder->pre_enable = intel_mst_pre_enable_dp;
549 intel_encoder->enable = intel_mst_enable_dp;
550 intel_encoder->get_hw_state = intel_dp_mst_enc_get_hw_state;
551 intel_encoder->get_config = intel_dp_mst_enc_get_config;
552
553 return intel_mst;
554
555}
556
557static bool
558intel_dp_create_fake_mst_encoders(struct intel_digital_port *intel_dig_port)
559{
560 int i;
561 struct intel_dp *intel_dp = &intel_dig_port->dp;
562
563 for (i = PIPE_A; i <= PIPE_C; i++)
564 intel_dp->mst_encoders[i] = intel_dp_create_fake_mst_encoder(intel_dig_port, i);
565 return true;
566}
567
568int
569intel_dp_mst_encoder_init(struct intel_digital_port *intel_dig_port, int conn_base_id)
570{
571 struct intel_dp *intel_dp = &intel_dig_port->dp;
572 struct drm_device *dev = intel_dig_port->base.base.dev;
573 int ret;
574
575 intel_dp->can_mst = true;
576 intel_dp->mst_mgr.cbs = &mst_cbs;
577
578 /* create encoders */
579 intel_dp_create_fake_mst_encoders(intel_dig_port);
Dhinakaran Pandiyan7b0a89a2017-01-24 15:49:29 -0800580 ret = drm_dp_mst_topology_mgr_init(&intel_dp->mst_mgr, dev,
581 &intel_dp->aux, 16, 3, conn_base_id);
Dave Airlie0e32b392014-05-02 14:02:48 +1000582 if (ret) {
583 intel_dp->can_mst = false;
584 return ret;
585 }
586 return 0;
587}
588
589void
590intel_dp_mst_encoder_cleanup(struct intel_digital_port *intel_dig_port)
591{
592 struct intel_dp *intel_dp = &intel_dig_port->dp;
593
594 if (!intel_dp->can_mst)
595 return;
596
597 drm_dp_mst_topology_mgr_destroy(&intel_dp->mst_mgr);
598 /* encoders will get killed by normal cleanup */
599}