blob: 5af22a7c11bfae042334a8ac8f938e3eab971a68 [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 */
Jani Nikula3d65a732017-04-06 16:44:14 +030059 lane_count = intel_dp_max_lane_count(intel_dp);
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 void
298intel_dp_mst_connector_destroy(struct drm_connector *connector)
299{
300 struct intel_connector *intel_connector = to_intel_connector(connector);
301
302 if (!IS_ERR_OR_NULL(intel_connector->edid))
303 kfree(intel_connector->edid);
304
305 drm_connector_cleanup(connector);
306 kfree(connector);
307}
308
309static const struct drm_connector_funcs intel_dp_mst_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +0200310 .dpms = drm_atomic_helper_connector_dpms,
Dave Airlie0e32b392014-05-02 14:02:48 +1000311 .detect = intel_dp_mst_detect,
312 .fill_modes = drm_helper_probe_single_connector_modes,
Maarten Lankhorst2e222ed2017-04-10 11:07:09 +0200313 .set_property = drm_atomic_helper_connector_set_property,
Chris Wilson1ebaa0b2016-06-24 14:00:15 +0100314 .late_register = intel_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +0100315 .early_unregister = intel_connector_unregister,
Dave Airlie0e32b392014-05-02 14:02:48 +1000316 .destroy = intel_dp_mst_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -0800317 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +0200318 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Dave Airlie0e32b392014-05-02 14:02:48 +1000319};
320
321static int intel_dp_mst_get_modes(struct drm_connector *connector)
322{
323 return intel_dp_mst_get_ddc_modes(connector);
324}
325
326static enum drm_mode_status
327intel_dp_mst_mode_valid(struct drm_connector *connector,
328 struct drm_display_mode *mode)
329{
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800330 struct intel_connector *intel_connector = to_intel_connector(connector);
331 struct intel_dp *intel_dp = intel_connector->mst_port;
Mika Kahola832d5bf2016-02-02 15:16:40 +0200332 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800333 int bpp = 24; /* MST uses fixed bpp */
334 int max_rate, mode_rate, max_lanes, max_link_clock;
335
336 max_link_clock = intel_dp_max_link_rate(intel_dp);
Jani Nikula3d65a732017-04-06 16:44:14 +0300337 max_lanes = intel_dp_max_lane_count(intel_dp);
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800338
339 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
340 mode_rate = intel_dp_link_required(mode->clock, bpp);
Mika Kahola832d5bf2016-02-02 15:16:40 +0200341
Dave Airlie0e32b392014-05-02 14:02:48 +1000342 /* TODO - validate mode against available PBN for link */
343 if (mode->clock < 10000)
344 return MODE_CLOCK_LOW;
345
346 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
347 return MODE_H_ILLEGAL;
348
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800349 if (mode_rate > max_rate || mode->clock > max_dotclk)
Mika Kahola832d5bf2016-02-02 15:16:40 +0200350 return MODE_CLOCK_HIGH;
351
Dave Airlie0e32b392014-05-02 14:02:48 +1000352 return MODE_OK;
353}
354
Daniel Vetter459485a2015-08-03 17:24:09 +0200355static struct drm_encoder *intel_mst_atomic_best_encoder(struct drm_connector *connector,
356 struct drm_connector_state *state)
357{
358 struct intel_connector *intel_connector = to_intel_connector(connector);
359 struct intel_dp *intel_dp = intel_connector->mst_port;
360 struct intel_crtc *crtc = to_intel_crtc(state->crtc);
361
Dave Airlie0552f762016-03-09 11:14:38 +1000362 if (!intel_dp)
363 return NULL;
Daniel Vetter459485a2015-08-03 17:24:09 +0200364 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;
Dave Airlie0552f762016-03-09 11:14:38 +1000371 if (!intel_dp)
372 return NULL;
Dave Airlie0e32b392014-05-02 14:02:48 +1000373 return &intel_dp->mst_encoders[0]->base.base;
374}
375
376static const struct drm_connector_helper_funcs intel_dp_mst_connector_helper_funcs = {
377 .get_modes = intel_dp_mst_get_modes,
378 .mode_valid = intel_dp_mst_mode_valid,
Daniel Vetter459485a2015-08-03 17:24:09 +0200379 .atomic_best_encoder = intel_mst_atomic_best_encoder,
Dave Airlie0e32b392014-05-02 14:02:48 +1000380 .best_encoder = intel_mst_best_encoder,
381};
382
383static void intel_dp_mst_encoder_destroy(struct drm_encoder *encoder)
384{
385 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder);
386
387 drm_encoder_cleanup(encoder);
388 kfree(intel_mst);
389}
390
391static const struct drm_encoder_funcs intel_dp_mst_enc_funcs = {
392 .destroy = intel_dp_mst_encoder_destroy,
393};
394
395static bool intel_dp_mst_get_hw_state(struct intel_connector *connector)
396{
Maarten Lankhorste85376c2015-08-27 13:13:31 +0200397 if (connector->encoder && connector->base.state->crtc) {
Dave Airlie0e32b392014-05-02 14:02:48 +1000398 enum pipe pipe;
399 if (!connector->encoder->get_hw_state(connector->encoder, &pipe))
400 return false;
401 return true;
402 }
403 return false;
404}
405
Chris Wilson7296c842014-07-22 20:10:28 +1000406static void intel_connector_add_to_fbdev(struct intel_connector *connector)
407{
Daniel Vetter06957262015-08-10 13:34:08 +0200408#ifdef CONFIG_DRM_FBDEV_EMULATION
Chris Wilson7296c842014-07-22 20:10:28 +1000409 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
Lukas Wunner54632ab2015-11-18 13:43:20 +0100410
411 if (dev_priv->fbdev)
412 drm_fb_helper_add_one_connector(&dev_priv->fbdev->helper,
413 &connector->base);
Chris Wilson7296c842014-07-22 20:10:28 +1000414#endif
415}
416
417static void intel_connector_remove_from_fbdev(struct intel_connector *connector)
418{
Daniel Vetter06957262015-08-10 13:34:08 +0200419#ifdef CONFIG_DRM_FBDEV_EMULATION
Chris Wilson7296c842014-07-22 20:10:28 +1000420 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
Lukas Wunner54632ab2015-11-18 13:43:20 +0100421
422 if (dev_priv->fbdev)
423 drm_fb_helper_remove_one_connector(&dev_priv->fbdev->helper,
424 &connector->base);
Chris Wilson7296c842014-07-22 20:10:28 +1000425#endif
426}
427
Thierry Reding12e6cec2014-05-13 11:38:36 +0200428static 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 +1000429{
430 struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
431 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
432 struct drm_device *dev = intel_dig_port->base.base.dev;
Dave Airlie0e32b392014-05-02 14:02:48 +1000433 struct intel_connector *intel_connector;
434 struct drm_connector *connector;
435 int i;
436
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +0300437 intel_connector = intel_connector_alloc();
Dave Airlie0e32b392014-05-02 14:02:48 +1000438 if (!intel_connector)
439 return NULL;
440
441 connector = &intel_connector->base;
442 drm_connector_init(dev, connector, &intel_dp_mst_connector_funcs, DRM_MODE_CONNECTOR_DisplayPort);
443 drm_connector_helper_add(connector, &intel_dp_mst_connector_helper_funcs);
444
Dave Airlie0e32b392014-05-02 14:02:48 +1000445 intel_connector->get_hw_state = intel_dp_mst_get_hw_state;
446 intel_connector->mst_port = intel_dp;
447 intel_connector->port = port;
448
449 for (i = PIPE_A; i <= PIPE_C; i++) {
450 drm_mode_connector_attach_encoder(&intel_connector->base,
451 &intel_dp->mst_encoders[i]->base.base);
452 }
Dave Airlie0e32b392014-05-02 14:02:48 +1000453
454 drm_object_attach_property(&connector->base, dev->mode_config.path_property, 0);
Dave Airlie6f134d72014-10-20 16:30:50 +1000455 drm_object_attach_property(&connector->base, dev->mode_config.tile_property, 0);
456
Dave Airlie0e32b392014-05-02 14:02:48 +1000457 drm_mode_connector_set_path_property(connector, pathprop);
Dave Airlied9515c52015-09-16 17:55:23 +1000458 return connector;
459}
460
461static void intel_dp_register_mst_connector(struct drm_connector *connector)
462{
463 struct intel_connector *intel_connector = to_intel_connector(connector);
464 struct drm_device *dev = connector->dev;
Chris Wilson7a418e32016-06-24 14:00:14 +0100465
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200466 drm_modeset_lock_all(dev);
Chris Wilson7296c842014-07-22 20:10:28 +1000467 intel_connector_add_to_fbdev(intel_connector);
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200468 drm_modeset_unlock_all(dev);
Chris Wilson7a418e32016-06-24 14:00:14 +0100469
Dave Airlie0e32b392014-05-02 14:02:48 +1000470 drm_connector_register(&intel_connector->base);
Dave Airlie0e32b392014-05-02 14:02:48 +1000471}
472
473static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
474 struct drm_connector *connector)
475{
476 struct intel_connector *intel_connector = to_intel_connector(connector);
477 struct drm_device *dev = connector->dev;
Maarten Lankhorst20fae982015-08-06 13:47:36 +0200478
Chris Wilsonc191eca2016-06-17 11:40:33 +0100479 drm_connector_unregister(connector);
Lyude1f771752016-03-16 15:18:04 -0400480
Dave Airlie0e32b392014-05-02 14:02:48 +1000481 /* need to nuke the connector */
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 Airlie0552f762016-03-09 11:14:38 +1000484 intel_connector->mst_port = NULL;
Daniel Vetter8bb4da12015-07-09 23:44:31 +0200485 drm_modeset_unlock_all(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +1000486
Dave Airlie0552f762016-03-09 11:14:38 +1000487 drm_connector_unreference(&intel_connector->base);
Dave Airlie0e32b392014-05-02 14:02:48 +1000488 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
Julia Lawall69a0f892015-12-30 22:20:30 +0100500static const struct drm_dp_mst_topology_cbs mst_cbs = {
Dave Airlie0e32b392014-05-02 14:02:48 +1000501 .add_connector = intel_dp_add_mst_connector,
Dave Airlied9515c52015-09-16 17:55:23 +1000502 .register_connector = intel_dp_register_mst_connector,
Dave Airlie0e32b392014-05-02 14:02:48 +1000503 .destroy_connector = intel_dp_destroy_mst_connector,
504 .hotplug = intel_dp_mst_hotplug,
505};
506
507static struct intel_dp_mst_encoder *
508intel_dp_create_fake_mst_encoder(struct intel_digital_port *intel_dig_port, enum pipe pipe)
509{
510 struct intel_dp_mst_encoder *intel_mst;
511 struct intel_encoder *intel_encoder;
512 struct drm_device *dev = intel_dig_port->base.base.dev;
513
514 intel_mst = kzalloc(sizeof(*intel_mst), GFP_KERNEL);
515
516 if (!intel_mst)
517 return NULL;
518
519 intel_mst->pipe = pipe;
520 intel_encoder = &intel_mst->base;
521 intel_mst->primary = intel_dig_port;
522
523 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_mst_enc_funcs,
Ville Syrjälä580d8ed2016-05-27 20:59:24 +0300524 DRM_MODE_ENCODER_DPMST, "DP-MST %c", pipe_name(pipe));
Dave Airlie0e32b392014-05-02 14:02:48 +1000525
526 intel_encoder->type = INTEL_OUTPUT_DP_MST;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +0200527 intel_encoder->power_domain = intel_dig_port->base.power_domain;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -0700528 intel_encoder->port = intel_dig_port->port;
Dave Airlie0e32b392014-05-02 14:02:48 +1000529 intel_encoder->crtc_mask = 0x7;
530 intel_encoder->cloneable = 0;
531
532 intel_encoder->compute_config = intel_dp_mst_compute_config;
533 intel_encoder->disable = intel_mst_disable_dp;
534 intel_encoder->post_disable = intel_mst_post_disable_dp;
535 intel_encoder->pre_enable = intel_mst_pre_enable_dp;
536 intel_encoder->enable = intel_mst_enable_dp;
537 intel_encoder->get_hw_state = intel_dp_mst_enc_get_hw_state;
538 intel_encoder->get_config = intel_dp_mst_enc_get_config;
539
540 return intel_mst;
541
542}
543
544static bool
545intel_dp_create_fake_mst_encoders(struct intel_digital_port *intel_dig_port)
546{
547 int i;
548 struct intel_dp *intel_dp = &intel_dig_port->dp;
549
550 for (i = PIPE_A; i <= PIPE_C; i++)
551 intel_dp->mst_encoders[i] = intel_dp_create_fake_mst_encoder(intel_dig_port, i);
552 return true;
553}
554
555int
556intel_dp_mst_encoder_init(struct intel_digital_port *intel_dig_port, int conn_base_id)
557{
558 struct intel_dp *intel_dp = &intel_dig_port->dp;
559 struct drm_device *dev = intel_dig_port->base.base.dev;
560 int ret;
561
562 intel_dp->can_mst = true;
563 intel_dp->mst_mgr.cbs = &mst_cbs;
564
565 /* create encoders */
566 intel_dp_create_fake_mst_encoders(intel_dig_port);
Dhinakaran Pandiyan7b0a89a2017-01-24 15:49:29 -0800567 ret = drm_dp_mst_topology_mgr_init(&intel_dp->mst_mgr, dev,
568 &intel_dp->aux, 16, 3, conn_base_id);
Dave Airlie0e32b392014-05-02 14:02:48 +1000569 if (ret) {
570 intel_dp->can_mst = false;
571 return ret;
572 }
573 return 0;
574}
575
576void
577intel_dp_mst_encoder_cleanup(struct intel_digital_port *intel_dig_port)
578{
579 struct intel_dp *intel_dp = &intel_dig_port->dp;
580
581 if (!intel_dp->can_mst)
582 return;
583
584 drm_dp_mst_topology_mgr_destroy(&intel_dp->mst_mgr);
585 /* encoders will get killed by normal cleanup */
586}