blob: c1f62eb07c07a7ce49b3ed39e1e6ee2b23eb65e8 [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;
47
Dave Airlie0e32b392014-05-02 14:02:48 +100048 pipe_config->has_pch_encoder = false;
Dave Airlie0e32b392014-05-02 14:02:48 +100049 bpp = 24;
Manasi Navare611032b2017-01-24 08:21:49 -080050 if (intel_dp->compliance.test_data.bpc) {
51 bpp = intel_dp->compliance.test_data.bpc * 3;
52 DRM_DEBUG_KMS("Setting pipe bpp to %d\n",
53 bpp);
54 }
Dave Airlie0e32b392014-05-02 14:02:48 +100055 /*
56 * for MST we always configure max link bw - the spec doesn't
57 * seem to suggest we should do otherwise.
58 */
59 lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +020060
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +030061 pipe_config->lane_count = lane_count;
Dave Airlie0e32b392014-05-02 14:02:48 +100062
Manasi Navare611032b2017-01-24 08:21:49 -080063 pipe_config->pipe_bpp = bpp;
Ville Syrjälä04a60f92015-07-06 15:10:06 +030064 pipe_config->port_clock = intel_dp_max_link_rate(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +100065
Ander Conselvan de Oliveirae75f4772015-03-20 16:18:13 +020066 state = pipe_config->base.state;
67
Libin Yang7f9e7752016-11-28 20:07:07 +080068 if (drm_dp_mst_port_has_audio(&intel_dp->mst_mgr, connector->port))
69 pipe_config->has_audio = true;
Ville Syrjäläaad941d2015-09-25 16:38:56 +030070 mst_pbn = drm_dp_calc_pbn_mode(adjusted_mode->crtc_clock, bpp);
Dave Airlie0e32b392014-05-02 14:02:48 +100071
72 pipe_config->pbn = mst_pbn;
73 slots = drm_dp_find_vcpi_slots(&intel_dp->mst_mgr, mst_pbn);
74
75 intel_link_compute_m_n(bpp, lane_count,
76 adjusted_mode->crtc_clock,
77 pipe_config->port_clock,
78 &pipe_config->dp_m_n);
79
80 pipe_config->dp_m_n.tu = slots;
Ander Conselvan de Oliveira6fa2d192015-08-31 11:23:28 +030081
Dave Airlie0e32b392014-05-02 14:02:48 +100082 return true;
83
84}
85
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020086static void intel_mst_disable_dp(struct intel_encoder *encoder,
87 struct intel_crtc_state *old_crtc_state,
88 struct drm_connector_state *old_conn_state)
Dave Airlie0e32b392014-05-02 14:02:48 +100089{
90 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
91 struct intel_digital_port *intel_dig_port = intel_mst->primary;
92 struct intel_dp *intel_dp = &intel_dig_port->dp;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +020093 struct intel_connector *connector =
94 to_intel_connector(old_conn_state->connector);
Dave Airlie0e32b392014-05-02 14:02:48 +100095 int ret;
96
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +030097 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
Dave Airlie0e32b392014-05-02 14:02:48 +100098
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +020099 drm_dp_mst_reset_vcpi_slots(&intel_dp->mst_mgr, connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000100
101 ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
102 if (ret) {
103 DRM_ERROR("failed to update payload %d\n", ret);
104 }
Maarten Lankhorst37255d82016-12-15 15:29:43 +0100105 if (old_crtc_state->has_audio)
Libin Yang7f9e7752016-11-28 20:07:07 +0800106 intel_audio_codec_disable(encoder);
Dave Airlie0e32b392014-05-02 14:02:48 +1000107}
108
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +0200109static void intel_mst_post_disable_dp(struct intel_encoder *encoder,
110 struct intel_crtc_state *old_crtc_state,
111 struct drm_connector_state *old_conn_state)
Dave Airlie0e32b392014-05-02 14:02:48 +1000112{
113 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
114 struct intel_digital_port *intel_dig_port = intel_mst->primary;
115 struct intel_dp *intel_dp = &intel_dig_port->dp;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200116 struct intel_connector *connector =
117 to_intel_connector(old_conn_state->connector);
Dave Airlie0e32b392014-05-02 14:02:48 +1000118
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300119 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
Dave Airlie0e32b392014-05-02 14:02:48 +1000120
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
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200126 drm_dp_mst_deallocate_vcpi(&intel_dp->mst_mgr, connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000127
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300128 intel_dp->active_mst_links--;
Dave Airlie0552f762016-03-09 11:14:38 +1000129
130 intel_mst->connector = NULL;
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300131 if (intel_dp->active_mst_links == 0) {
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +0200132 intel_dig_port->base.post_disable(&intel_dig_port->base,
133 NULL, NULL);
134
Dave Airlie0e32b392014-05-02 14:02:48 +1000135 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
136 }
137}
138
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +0200139static void intel_mst_pre_enable_dp(struct intel_encoder *encoder,
140 struct intel_crtc_state *pipe_config,
141 struct drm_connector_state *conn_state)
Dave Airlie0e32b392014-05-02 14:02:48 +1000142{
143 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
144 struct intel_digital_port *intel_dig_port = intel_mst->primary;
145 struct intel_dp *intel_dp = &intel_dig_port->dp;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200146 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000147 enum port port = intel_dig_port->port;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200148 struct intel_connector *connector =
149 to_intel_connector(conn_state->connector);
Dave Airlie0e32b392014-05-02 14:02:48 +1000150 int ret;
151 uint32_t temp;
Dave Airlie0e32b392014-05-02 14:02:48 +1000152
Maarten Lankhorste85376c2015-08-27 13:13:31 +0200153 /* MST encoders are bound to a crtc, not to a connector,
154 * force the mapping here for get_hw_state.
155 */
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200156 connector->encoder = encoder;
157 intel_mst->connector = connector;
Maarten Lankhorste85376c2015-08-27 13:13:31 +0200158
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300159 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
Dave Airlie0552f762016-03-09 11:14:38 +1000160
Ander Conselvan de Oliveirae081c842017-03-02 14:58:57 +0200161 if (intel_dp->active_mst_links == 0)
162 intel_dig_port->base.pre_enable(&intel_dig_port->base,
163 pipe_config, NULL);
Dave Airlie0e32b392014-05-02 14:02:48 +1000164
165 ret = drm_dp_mst_allocate_vcpi(&intel_dp->mst_mgr,
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200166 connector->port,
Pandiyan, Dhinakaran1e797f52017-03-16 00:10:26 -0700167 pipe_config->pbn,
168 pipe_config->dp_m_n.tu);
Dave Airlie0e32b392014-05-02 14:02:48 +1000169 if (ret == false) {
170 DRM_ERROR("failed to allocate vcpi\n");
171 return;
172 }
173
174
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300175 intel_dp->active_mst_links++;
Dave Airlie0e32b392014-05-02 14:02:48 +1000176 temp = I915_READ(DP_TP_STATUS(port));
177 I915_WRITE(DP_TP_STATUS(port), temp);
178
179 ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
180}
181
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +0200182static void intel_mst_enable_dp(struct intel_encoder *encoder,
183 struct intel_crtc_state *pipe_config,
184 struct drm_connector_state *conn_state)
Dave Airlie0e32b392014-05-02 14:02:48 +1000185{
186 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
187 struct intel_digital_port *intel_dig_port = intel_mst->primary;
188 struct intel_dp *intel_dp = &intel_dig_port->dp;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200189 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000190 enum port port = intel_dig_port->port;
191 int ret;
192
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +0300193 DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links);
Dave Airlie0e32b392014-05-02 14:02:48 +1000194
Chris Wilson3016a312016-06-30 15:33:11 +0100195 if (intel_wait_for_register(dev_priv,
196 DP_TP_STATUS(port),
197 DP_TP_STATUS_ACT_SENT,
198 DP_TP_STATUS_ACT_SENT,
199 1))
Dave Airlie0e32b392014-05-02 14:02:48 +1000200 DRM_ERROR("Timed out waiting for ACT sent\n");
201
202 ret = drm_dp_check_act_status(&intel_dp->mst_mgr);
203
204 ret = drm_dp_update_payload_part2(&intel_dp->mst_mgr);
Maarten Lankhorst37255d82016-12-15 15:29:43 +0100205 if (pipe_config->has_audio)
Libin Yang7f9e7752016-11-28 20:07:07 +0800206 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Dave Airlie0e32b392014-05-02 14:02:48 +1000207}
208
209static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder *encoder,
210 enum pipe *pipe)
211{
212 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
213 *pipe = intel_mst->pipe;
Dave Airlie0552f762016-03-09 11:14:38 +1000214 if (intel_mst->connector)
Dave Airlie0e32b392014-05-02 14:02:48 +1000215 return true;
216 return false;
217}
218
219static void intel_dp_mst_enc_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200220 struct intel_crtc_state *pipe_config)
Dave Airlie0e32b392014-05-02 14:02:48 +1000221{
222 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
223 struct intel_digital_port *intel_dig_port = intel_mst->primary;
Maarten Lankhorst1e7bfa02016-08-09 17:04:12 +0200224 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
225 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira0cb09a92015-01-30 12:17:23 +0200226 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Dave Airlie0e32b392014-05-02 14:02:48 +1000227 u32 temp, flags = 0;
228
Libin Yang7f9e7752016-11-28 20:07:07 +0800229 pipe_config->has_audio =
230 intel_ddi_is_audio_enabled(dev_priv, crtc);
231
Dave Airlie0e32b392014-05-02 14:02:48 +1000232 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
233 if (temp & TRANS_DDI_PHSYNC)
234 flags |= DRM_MODE_FLAG_PHSYNC;
235 else
236 flags |= DRM_MODE_FLAG_NHSYNC;
237 if (temp & TRANS_DDI_PVSYNC)
238 flags |= DRM_MODE_FLAG_PVSYNC;
239 else
240 flags |= DRM_MODE_FLAG_NVSYNC;
241
242 switch (temp & TRANS_DDI_BPC_MASK) {
243 case TRANS_DDI_BPC_6:
244 pipe_config->pipe_bpp = 18;
245 break;
246 case TRANS_DDI_BPC_8:
247 pipe_config->pipe_bpp = 24;
248 break;
249 case TRANS_DDI_BPC_10:
250 pipe_config->pipe_bpp = 30;
251 break;
252 case TRANS_DDI_BPC_12:
253 pipe_config->pipe_bpp = 36;
254 break;
255 default:
256 break;
257 }
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200258 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +0300259
260 pipe_config->lane_count =
261 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
262
Dave Airlie0e32b392014-05-02 14:02:48 +1000263 intel_dp_get_m_n(crtc, pipe_config);
264
265 intel_ddi_clock_get(&intel_dig_port->base, pipe_config);
266}
267
268static int intel_dp_mst_get_ddc_modes(struct drm_connector *connector)
269{
270 struct intel_connector *intel_connector = to_intel_connector(connector);
271 struct intel_dp *intel_dp = intel_connector->mst_port;
272 struct edid *edid;
273 int ret;
274
Dave Airlie0552f762016-03-09 11:14:38 +1000275 if (!intel_dp) {
276 return intel_connector_update_modes(connector, NULL);
277 }
Dave Airlie0e32b392014-05-02 14:02:48 +1000278
Dave Airlie0552f762016-03-09 11:14:38 +1000279 edid = drm_dp_mst_get_edid(connector, &intel_dp->mst_mgr, intel_connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000280 ret = intel_connector_update_modes(connector, edid);
281 kfree(edid);
282
283 return ret;
284}
285
286static enum drm_connector_status
Daniel Vetterf7f3d482014-10-22 11:06:44 +0200287intel_dp_mst_detect(struct drm_connector *connector, bool force)
Dave Airlie0e32b392014-05-02 14:02:48 +1000288{
289 struct intel_connector *intel_connector = to_intel_connector(connector);
290 struct intel_dp *intel_dp = intel_connector->mst_port;
291
Dave Airlie0552f762016-03-09 11:14:38 +1000292 if (!intel_dp)
293 return connector_status_disconnected;
Dave Airliec6a0aed2014-10-20 16:28:02 +1000294 return drm_dp_mst_detect_port(connector, &intel_dp->mst_mgr, intel_connector->port);
Dave Airlie0e32b392014-05-02 14:02:48 +1000295}
296
Dave Airlie0e32b392014-05-02 14:02:48 +1000297static int
298intel_dp_mst_set_property(struct drm_connector *connector,
299 struct drm_property *property,
300 uint64_t val)
301{
302 return 0;
303}
304
305static void
306intel_dp_mst_connector_destroy(struct drm_connector *connector)
307{
308 struct intel_connector *intel_connector = to_intel_connector(connector);
309
310 if (!IS_ERR_OR_NULL(intel_connector->edid))
311 kfree(intel_connector->edid);
312
313 drm_connector_cleanup(connector);
314 kfree(connector);
315}
316
317static const struct drm_connector_funcs intel_dp_mst_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +0200318 .dpms = drm_atomic_helper_connector_dpms,
Dave Airlie0e32b392014-05-02 14:02:48 +1000319 .detect = intel_dp_mst_detect,
320 .fill_modes = drm_helper_probe_single_connector_modes,
321 .set_property = intel_dp_mst_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -0800322 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson1ebaa0b2016-06-24 14:00:15 +0100323 .late_register = intel_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +0100324 .early_unregister = intel_connector_unregister,
Dave Airlie0e32b392014-05-02 14:02:48 +1000325 .destroy = intel_dp_mst_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -0800326 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +0200327 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Dave Airlie0e32b392014-05-02 14:02:48 +1000328};
329
330static int intel_dp_mst_get_modes(struct drm_connector *connector)
331{
332 return intel_dp_mst_get_ddc_modes(connector);
333}
334
335static enum drm_mode_status
336intel_dp_mst_mode_valid(struct drm_connector *connector,
337 struct drm_display_mode *mode)
338{
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800339 struct intel_connector *intel_connector = to_intel_connector(connector);
340 struct intel_dp *intel_dp = intel_connector->mst_port;
Mika Kahola832d5bf2016-02-02 15:16:40 +0200341 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800342 int bpp = 24; /* MST uses fixed bpp */
343 int max_rate, mode_rate, max_lanes, max_link_clock;
344
345 max_link_clock = intel_dp_max_link_rate(intel_dp);
346 max_lanes = drm_dp_max_lane_count(intel_dp->dpcd);
347
348 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
349 mode_rate = intel_dp_link_required(mode->clock, bpp);
Mika Kahola832d5bf2016-02-02 15:16:40 +0200350
Dave Airlie0e32b392014-05-02 14:02:48 +1000351 /* TODO - validate mode against available PBN for link */
352 if (mode->clock < 10000)
353 return MODE_CLOCK_LOW;
354
355 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
356 return MODE_H_ILLEGAL;
357
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800358 if (mode_rate > max_rate || mode->clock > max_dotclk)
Mika Kahola832d5bf2016-02-02 15:16:40 +0200359 return MODE_CLOCK_HIGH;
360
Dave Airlie0e32b392014-05-02 14:02:48 +1000361 return MODE_OK;
362}
363
Daniel Vetter459485a2015-08-03 17:24:09 +0200364static struct drm_encoder *intel_mst_atomic_best_encoder(struct drm_connector *connector,
365 struct drm_connector_state *state)
366{
367 struct intel_connector *intel_connector = to_intel_connector(connector);
368 struct intel_dp *intel_dp = intel_connector->mst_port;
369 struct intel_crtc *crtc = to_intel_crtc(state->crtc);
370
Dave Airlie0552f762016-03-09 11:14:38 +1000371 if (!intel_dp)
372 return NULL;
Daniel Vetter459485a2015-08-03 17:24:09 +0200373 return &intel_dp->mst_encoders[crtc->pipe]->base.base;
374}
375
Dave Airlie0e32b392014-05-02 14:02:48 +1000376static struct drm_encoder *intel_mst_best_encoder(struct drm_connector *connector)
377{
378 struct intel_connector *intel_connector = to_intel_connector(connector);
379 struct intel_dp *intel_dp = intel_connector->mst_port;
Dave Airlie0552f762016-03-09 11:14:38 +1000380 if (!intel_dp)
381 return NULL;
Dave Airlie0e32b392014-05-02 14:02:48 +1000382 return &intel_dp->mst_encoders[0]->base.base;
383}
384
385static const struct drm_connector_helper_funcs intel_dp_mst_connector_helper_funcs = {
386 .get_modes = intel_dp_mst_get_modes,
387 .mode_valid = intel_dp_mst_mode_valid,
Daniel Vetter459485a2015-08-03 17:24:09 +0200388 .atomic_best_encoder = intel_mst_atomic_best_encoder,
Dave Airlie0e32b392014-05-02 14:02:48 +1000389 .best_encoder = intel_mst_best_encoder,
390};
391
392static void intel_dp_mst_encoder_destroy(struct drm_encoder *encoder)
393{
394 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder);
395
396 drm_encoder_cleanup(encoder);
397 kfree(intel_mst);
398}
399
400static const struct drm_encoder_funcs intel_dp_mst_enc_funcs = {
401 .destroy = intel_dp_mst_encoder_destroy,
402};
403
404static bool intel_dp_mst_get_hw_state(struct intel_connector *connector)
405{
Maarten Lankhorste85376c2015-08-27 13:13:31 +0200406 if (connector->encoder && connector->base.state->crtc) {
Dave Airlie0e32b392014-05-02 14:02:48 +1000407 enum pipe pipe;
408 if (!connector->encoder->get_hw_state(connector->encoder, &pipe))
409 return false;
410 return true;
411 }
412 return false;
413}
414
Chris Wilson7296c842014-07-22 20:10:28 +1000415static void intel_connector_add_to_fbdev(struct intel_connector *connector)
416{
Daniel Vetter06957262015-08-10 13:34:08 +0200417#ifdef CONFIG_DRM_FBDEV_EMULATION
Chris Wilson7296c842014-07-22 20:10:28 +1000418 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
Lukas Wunner54632ab2015-11-18 13:43:20 +0100419
420 if (dev_priv->fbdev)
421 drm_fb_helper_add_one_connector(&dev_priv->fbdev->helper,
422 &connector->base);
Chris Wilson7296c842014-07-22 20:10:28 +1000423#endif
424}
425
426static void intel_connector_remove_from_fbdev(struct intel_connector *connector)
427{
Daniel Vetter06957262015-08-10 13:34:08 +0200428#ifdef CONFIG_DRM_FBDEV_EMULATION
Chris Wilson7296c842014-07-22 20:10:28 +1000429 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
Lukas Wunner54632ab2015-11-18 13:43:20 +0100430
431 if (dev_priv->fbdev)
432 drm_fb_helper_remove_one_connector(&dev_priv->fbdev->helper,
433 &connector->base);
Chris Wilson7296c842014-07-22 20:10:28 +1000434#endif
435}
436
Thierry Reding12e6cec2014-05-13 11:38:36 +0200437static 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 +1000438{
439 struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
440 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
441 struct drm_device *dev = intel_dig_port->base.base.dev;
Dave Airlie0e32b392014-05-02 14:02:48 +1000442 struct intel_connector *intel_connector;
443 struct drm_connector *connector;
444 int i;
445
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +0300446 intel_connector = intel_connector_alloc();
Dave Airlie0e32b392014-05-02 14:02:48 +1000447 if (!intel_connector)
448 return NULL;
449
450 connector = &intel_connector->base;
451 drm_connector_init(dev, connector, &intel_dp_mst_connector_funcs, DRM_MODE_CONNECTOR_DisplayPort);
452 drm_connector_helper_add(connector, &intel_dp_mst_connector_helper_funcs);
453
Dave Airlie0e32b392014-05-02 14:02:48 +1000454 intel_connector->get_hw_state = intel_dp_mst_get_hw_state;
455 intel_connector->mst_port = intel_dp;
456 intel_connector->port = port;
457
458 for (i = PIPE_A; i <= PIPE_C; i++) {
459 drm_mode_connector_attach_encoder(&intel_connector->base,
460 &intel_dp->mst_encoders[i]->base.base);
461 }
462 intel_dp_add_properties(intel_dp, connector);
463
464 drm_object_attach_property(&connector->base, dev->mode_config.path_property, 0);
Dave Airlie6f134d72014-10-20 16:30:50 +1000465 drm_object_attach_property(&connector->base, dev->mode_config.tile_property, 0);
466
Dave Airlie0e32b392014-05-02 14:02:48 +1000467 drm_mode_connector_set_path_property(connector, pathprop);
Dave Airlied9515c52015-09-16 17:55:23 +1000468 return connector;
469}
470
471static void intel_dp_register_mst_connector(struct drm_connector *connector)
472{
473 struct intel_connector *intel_connector = to_intel_connector(connector);
474 struct drm_device *dev = connector->dev;
Chris Wilson7a418e32016-06-24 14:00:14 +0100475
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200476 drm_modeset_lock_all(dev);
Chris Wilson7296c842014-07-22 20:10:28 +1000477 intel_connector_add_to_fbdev(intel_connector);
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200478 drm_modeset_unlock_all(dev);
Chris Wilson7a418e32016-06-24 14:00:14 +0100479
Dave Airlie0e32b392014-05-02 14:02:48 +1000480 drm_connector_register(&intel_connector->base);
Dave Airlie0e32b392014-05-02 14:02:48 +1000481}
482
483static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
484 struct drm_connector *connector)
485{
486 struct intel_connector *intel_connector = to_intel_connector(connector);
487 struct drm_device *dev = connector->dev;
Maarten Lankhorst20fae982015-08-06 13:47:36 +0200488
Chris Wilsonc191eca2016-06-17 11:40:33 +0100489 drm_connector_unregister(connector);
Lyude1f771752016-03-16 15:18:04 -0400490
Dave Airlie0e32b392014-05-02 14:02:48 +1000491 /* need to nuke the connector */
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200492 drm_modeset_lock_all(dev);
Chris Wilson7296c842014-07-22 20:10:28 +1000493 intel_connector_remove_from_fbdev(intel_connector);
Dave Airlie0552f762016-03-09 11:14:38 +1000494 intel_connector->mst_port = NULL;
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200495 drm_modeset_unlock_all(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000496
Dave Airlie0552f762016-03-09 11:14:38 +1000497 drm_connector_unreference(&intel_connector->base);
Dave Airlie0e32b392014-05-02 14:02:48 +1000498 DRM_DEBUG_KMS("\n");
499}
500
501static void intel_dp_mst_hotplug(struct drm_dp_mst_topology_mgr *mgr)
502{
503 struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
504 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
505 struct drm_device *dev = intel_dig_port->base.base.dev;
506
507 drm_kms_helper_hotplug_event(dev);
508}
509
Julia Lawall69a0f892015-12-30 22:20:30 +0100510static const struct drm_dp_mst_topology_cbs mst_cbs = {
Dave Airlie0e32b392014-05-02 14:02:48 +1000511 .add_connector = intel_dp_add_mst_connector,
Dave Airlied9515c52015-09-16 17:55:23 +1000512 .register_connector = intel_dp_register_mst_connector,
Dave Airlie0e32b392014-05-02 14:02:48 +1000513 .destroy_connector = intel_dp_destroy_mst_connector,
514 .hotplug = intel_dp_mst_hotplug,
515};
516
517static struct intel_dp_mst_encoder *
518intel_dp_create_fake_mst_encoder(struct intel_digital_port *intel_dig_port, enum pipe pipe)
519{
520 struct intel_dp_mst_encoder *intel_mst;
521 struct intel_encoder *intel_encoder;
522 struct drm_device *dev = intel_dig_port->base.base.dev;
523
524 intel_mst = kzalloc(sizeof(*intel_mst), GFP_KERNEL);
525
526 if (!intel_mst)
527 return NULL;
528
529 intel_mst->pipe = pipe;
530 intel_encoder = &intel_mst->base;
531 intel_mst->primary = intel_dig_port;
532
533 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_mst_enc_funcs,
Ville Syrjälä580d8ed2016-05-27 20:59:24 +0300534 DRM_MODE_ENCODER_DPMST, "DP-MST %c", pipe_name(pipe));
Dave Airlie0e32b392014-05-02 14:02:48 +1000535
536 intel_encoder->type = INTEL_OUTPUT_DP_MST;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +0200537 intel_encoder->power_domain = intel_dig_port->base.power_domain;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -0700538 intel_encoder->port = intel_dig_port->port;
Dave Airlie0e32b392014-05-02 14:02:48 +1000539 intel_encoder->crtc_mask = 0x7;
540 intel_encoder->cloneable = 0;
541
542 intel_encoder->compute_config = intel_dp_mst_compute_config;
543 intel_encoder->disable = intel_mst_disable_dp;
544 intel_encoder->post_disable = intel_mst_post_disable_dp;
545 intel_encoder->pre_enable = intel_mst_pre_enable_dp;
546 intel_encoder->enable = intel_mst_enable_dp;
547 intel_encoder->get_hw_state = intel_dp_mst_enc_get_hw_state;
548 intel_encoder->get_config = intel_dp_mst_enc_get_config;
549
550 return intel_mst;
551
552}
553
554static bool
555intel_dp_create_fake_mst_encoders(struct intel_digital_port *intel_dig_port)
556{
557 int i;
558 struct intel_dp *intel_dp = &intel_dig_port->dp;
559
560 for (i = PIPE_A; i <= PIPE_C; i++)
561 intel_dp->mst_encoders[i] = intel_dp_create_fake_mst_encoder(intel_dig_port, i);
562 return true;
563}
564
565int
566intel_dp_mst_encoder_init(struct intel_digital_port *intel_dig_port, int conn_base_id)
567{
568 struct intel_dp *intel_dp = &intel_dig_port->dp;
569 struct drm_device *dev = intel_dig_port->base.base.dev;
570 int ret;
571
572 intel_dp->can_mst = true;
573 intel_dp->mst_mgr.cbs = &mst_cbs;
574
575 /* create encoders */
576 intel_dp_create_fake_mst_encoders(intel_dig_port);
Dhinakaran Pandiyan7b0a89a2017-01-24 15:49:29 -0800577 ret = drm_dp_mst_topology_mgr_init(&intel_dp->mst_mgr, dev,
578 &intel_dp->aux, 16, 3, conn_base_id);
Dave Airlie0e32b392014-05-02 14:02:48 +1000579 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}