Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1 | /* |
| 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 Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 29 | #include <drm/drm_atomic_helper.h> |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 30 | #include <drm/drm_crtc_helper.h> |
| 31 | #include <drm/drm_edid.h> |
| 32 | |
| 33 | static bool intel_dp_mst_compute_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 34 | struct intel_crtc_state *pipe_config) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 35 | { |
Ander Conselvan de Oliveira | 6fa2d19 | 2015-08-31 11:23:28 +0300 | [diff] [blame] | 36 | struct drm_device *dev = encoder->base.dev; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 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 Oliveira | e75f477 | 2015-03-20 16:18:13 +0200 | [diff] [blame] | 40 | struct drm_atomic_state *state; |
| 41 | int bpp, i; |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 42 | int lane_count, slots; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 43 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Ander Conselvan de Oliveira | da3ced2 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 44 | struct drm_connector *drm_connector; |
| 45 | struct intel_connector *connector, *found = NULL; |
| 46 | struct drm_connector_state *connector_state; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 47 | int mst_pbn; |
| 48 | |
| 49 | pipe_config->dp_encoder_is_mst = true; |
| 50 | pipe_config->has_pch_encoder = false; |
| 51 | pipe_config->has_dp_encoder = true; |
| 52 | bpp = 24; |
| 53 | /* |
| 54 | * for MST we always configure max link bw - the spec doesn't |
| 55 | * seem to suggest we should do otherwise. |
| 56 | */ |
| 57 | lane_count = drm_dp_max_lane_count(intel_dp->dpcd); |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 58 | |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 59 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 60 | pipe_config->lane_count = lane_count; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 61 | |
| 62 | pipe_config->pipe_bpp = 24; |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 63 | pipe_config->port_clock = intel_dp_max_link_rate(intel_dp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 64 | |
Ander Conselvan de Oliveira | e75f477 | 2015-03-20 16:18:13 +0200 | [diff] [blame] | 65 | state = pipe_config->base.state; |
| 66 | |
Ander Conselvan de Oliveira | da3ced2 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 67 | for_each_connector_in_state(state, drm_connector, connector_state, i) { |
| 68 | connector = to_intel_connector(drm_connector); |
Ander Conselvan de Oliveira | e75f477 | 2015-03-20 16:18:13 +0200 | [diff] [blame] | 69 | |
Ander Conselvan de Oliveira | da3ced2 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 70 | if (connector_state->best_encoder == &encoder->base) { |
| 71 | found = connector; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 72 | break; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | if (!found) { |
| 77 | DRM_ERROR("can't find connector\n"); |
| 78 | return false; |
| 79 | } |
| 80 | |
Libin Yang | 3d52ccf | 2015-12-02 14:09:44 +0800 | [diff] [blame] | 81 | if (drm_dp_mst_port_has_audio(&intel_dp->mst_mgr, found->port)) |
| 82 | pipe_config->has_audio = true; |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 83 | mst_pbn = drm_dp_calc_pbn_mode(adjusted_mode->crtc_clock, bpp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 84 | |
| 85 | pipe_config->pbn = mst_pbn; |
| 86 | slots = drm_dp_find_vcpi_slots(&intel_dp->mst_mgr, mst_pbn); |
| 87 | |
| 88 | intel_link_compute_m_n(bpp, lane_count, |
| 89 | adjusted_mode->crtc_clock, |
| 90 | pipe_config->port_clock, |
| 91 | &pipe_config->dp_m_n); |
| 92 | |
| 93 | pipe_config->dp_m_n.tu = slots; |
Ander Conselvan de Oliveira | 6fa2d19 | 2015-08-31 11:23:28 +0300 | [diff] [blame] | 94 | |
| 95 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 96 | hsw_dp_set_ddi_pll_sel(pipe_config); |
| 97 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 98 | return true; |
| 99 | |
| 100 | } |
| 101 | |
| 102 | static void intel_mst_disable_dp(struct intel_encoder *encoder) |
| 103 | { |
| 104 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 105 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 106 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Libin Yang | 3d52ccf | 2015-12-02 14:09:44 +0800 | [diff] [blame] | 107 | struct drm_device *dev = encoder->base.dev; |
| 108 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 109 | struct drm_crtc *crtc = encoder->base.crtc; |
| 110 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 111 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 112 | int ret; |
| 113 | |
| 114 | DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links); |
| 115 | |
| 116 | drm_dp_mst_reset_vcpi_slots(&intel_dp->mst_mgr, intel_mst->port); |
| 117 | |
| 118 | ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr); |
| 119 | if (ret) { |
| 120 | DRM_ERROR("failed to update payload %d\n", ret); |
| 121 | } |
Libin Yang | 3d52ccf | 2015-12-02 14:09:44 +0800 | [diff] [blame] | 122 | if (intel_crtc->config->has_audio) { |
| 123 | intel_audio_codec_disable(encoder); |
| 124 | intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO); |
| 125 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static void intel_mst_post_disable_dp(struct intel_encoder *encoder) |
| 129 | { |
| 130 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 131 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 132 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 133 | |
| 134 | DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links); |
| 135 | |
| 136 | /* this can fail */ |
| 137 | drm_dp_check_act_status(&intel_dp->mst_mgr); |
| 138 | /* and this can also fail */ |
| 139 | drm_dp_update_payload_part2(&intel_dp->mst_mgr); |
| 140 | |
| 141 | drm_dp_mst_deallocate_vcpi(&intel_dp->mst_mgr, intel_mst->port); |
| 142 | |
| 143 | intel_dp->active_mst_links--; |
| 144 | intel_mst->port = NULL; |
| 145 | if (intel_dp->active_mst_links == 0) { |
| 146 | intel_dig_port->base.post_disable(&intel_dig_port->base); |
| 147 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | static void intel_mst_pre_enable_dp(struct intel_encoder *encoder) |
| 152 | { |
| 153 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 154 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 155 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 156 | struct drm_device *dev = encoder->base.dev; |
| 157 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 158 | enum port port = intel_dig_port->port; |
| 159 | int ret; |
| 160 | uint32_t temp; |
Ander Conselvan de Oliveira | 9b4fd8f | 2015-04-02 14:48:01 +0300 | [diff] [blame] | 161 | struct intel_connector *found = NULL, *connector; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 162 | int slots; |
| 163 | struct drm_crtc *crtc = encoder->base.crtc; |
| 164 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 165 | |
Ander Conselvan de Oliveira | 9b4fd8f | 2015-04-02 14:48:01 +0300 | [diff] [blame] | 166 | for_each_intel_connector(dev, connector) { |
| 167 | if (connector->base.state->best_encoder == &encoder->base) { |
| 168 | found = connector; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 169 | break; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | if (!found) { |
| 174 | DRM_ERROR("can't find connector\n"); |
| 175 | return; |
| 176 | } |
| 177 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 178 | /* MST encoders are bound to a crtc, not to a connector, |
| 179 | * force the mapping here for get_hw_state. |
| 180 | */ |
| 181 | found->encoder = encoder; |
| 182 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 183 | DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links); |
| 184 | intel_mst->port = found->port; |
| 185 | |
| 186 | if (intel_dp->active_mst_links == 0) { |
Ville Syrjälä | 6a7e4f9 | 2015-12-08 19:59:44 +0200 | [diff] [blame^] | 187 | intel_prepare_ddi_buffer(&intel_dig_port->base); |
| 188 | |
Ville Syrjälä | d919161 | 2015-12-08 19:59:36 +0200 | [diff] [blame] | 189 | intel_ddi_clk_select(&intel_dig_port->base, intel_crtc->config); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 190 | |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 191 | intel_dp_set_link_params(intel_dp, intel_crtc->config); |
| 192 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 193 | intel_ddi_init_dp_buf_reg(&intel_dig_port->base); |
| 194 | |
| 195 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
| 196 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 197 | intel_dp_start_link_train(intel_dp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 198 | intel_dp_stop_link_train(intel_dp); |
| 199 | } |
| 200 | |
| 201 | ret = drm_dp_mst_allocate_vcpi(&intel_dp->mst_mgr, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 202 | intel_mst->port, |
| 203 | intel_crtc->config->pbn, &slots); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 204 | if (ret == false) { |
| 205 | DRM_ERROR("failed to allocate vcpi\n"); |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | |
| 210 | intel_dp->active_mst_links++; |
| 211 | temp = I915_READ(DP_TP_STATUS(port)); |
| 212 | I915_WRITE(DP_TP_STATUS(port), temp); |
| 213 | |
| 214 | ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr); |
| 215 | } |
| 216 | |
| 217 | static void intel_mst_enable_dp(struct intel_encoder *encoder) |
| 218 | { |
| 219 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 220 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 221 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 222 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 223 | struct drm_i915_private *dev_priv = dev->dev_private; |
Libin Yang | 3d52ccf | 2015-12-02 14:09:44 +0800 | [diff] [blame] | 224 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 225 | enum port port = intel_dig_port->port; |
| 226 | int ret; |
| 227 | |
| 228 | DRM_DEBUG_KMS("%d\n", intel_dp->active_mst_links); |
| 229 | |
| 230 | if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_ACT_SENT), |
| 231 | 1)) |
| 232 | DRM_ERROR("Timed out waiting for ACT sent\n"); |
| 233 | |
| 234 | ret = drm_dp_check_act_status(&intel_dp->mst_mgr); |
| 235 | |
| 236 | ret = drm_dp_update_payload_part2(&intel_dp->mst_mgr); |
Libin Yang | 3d52ccf | 2015-12-02 14:09:44 +0800 | [diff] [blame] | 237 | |
| 238 | if (crtc->config->has_audio) { |
| 239 | DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n", |
| 240 | pipe_name(crtc->pipe)); |
| 241 | intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO); |
| 242 | intel_audio_codec_enable(encoder); |
| 243 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder *encoder, |
| 247 | enum pipe *pipe) |
| 248 | { |
| 249 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 250 | *pipe = intel_mst->pipe; |
| 251 | if (intel_mst->port) |
| 252 | return true; |
| 253 | return false; |
| 254 | } |
| 255 | |
| 256 | static void intel_dp_mst_enc_get_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 257 | struct intel_crtc_state *pipe_config) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 258 | { |
| 259 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); |
| 260 | struct intel_digital_port *intel_dig_port = intel_mst->primary; |
| 261 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
| 262 | struct drm_device *dev = encoder->base.dev; |
| 263 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 0cb09a9 | 2015-01-30 12:17:23 +0200 | [diff] [blame] | 264 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 265 | u32 temp, flags = 0; |
| 266 | |
| 267 | pipe_config->has_dp_encoder = true; |
| 268 | |
Libin Yang | 3d52ccf | 2015-12-02 14:09:44 +0800 | [diff] [blame] | 269 | pipe_config->has_audio = |
| 270 | intel_ddi_is_audio_enabled(dev_priv, crtc); |
| 271 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 272 | temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
| 273 | if (temp & TRANS_DDI_PHSYNC) |
| 274 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 275 | else |
| 276 | flags |= DRM_MODE_FLAG_NHSYNC; |
| 277 | if (temp & TRANS_DDI_PVSYNC) |
| 278 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 279 | else |
| 280 | flags |= DRM_MODE_FLAG_NVSYNC; |
| 281 | |
| 282 | switch (temp & TRANS_DDI_BPC_MASK) { |
| 283 | case TRANS_DDI_BPC_6: |
| 284 | pipe_config->pipe_bpp = 18; |
| 285 | break; |
| 286 | case TRANS_DDI_BPC_8: |
| 287 | pipe_config->pipe_bpp = 24; |
| 288 | break; |
| 289 | case TRANS_DDI_BPC_10: |
| 290 | pipe_config->pipe_bpp = 30; |
| 291 | break; |
| 292 | case TRANS_DDI_BPC_12: |
| 293 | pipe_config->pipe_bpp = 36; |
| 294 | break; |
| 295 | default: |
| 296 | break; |
| 297 | } |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 298 | pipe_config->base.adjusted_mode.flags |= flags; |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 299 | |
| 300 | pipe_config->lane_count = |
| 301 | ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1; |
| 302 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 303 | intel_dp_get_m_n(crtc, pipe_config); |
| 304 | |
| 305 | intel_ddi_clock_get(&intel_dig_port->base, pipe_config); |
| 306 | } |
| 307 | |
| 308 | static int intel_dp_mst_get_ddc_modes(struct drm_connector *connector) |
| 309 | { |
| 310 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 311 | struct intel_dp *intel_dp = intel_connector->mst_port; |
| 312 | struct edid *edid; |
| 313 | int ret; |
| 314 | |
| 315 | edid = drm_dp_mst_get_edid(connector, &intel_dp->mst_mgr, intel_connector->port); |
| 316 | if (!edid) |
| 317 | return 0; |
| 318 | |
| 319 | ret = intel_connector_update_modes(connector, edid); |
| 320 | kfree(edid); |
| 321 | |
| 322 | return ret; |
| 323 | } |
| 324 | |
| 325 | static enum drm_connector_status |
Daniel Vetter | f7f3d48 | 2014-10-22 11:06:44 +0200 | [diff] [blame] | 326 | intel_dp_mst_detect(struct drm_connector *connector, bool force) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 327 | { |
| 328 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 329 | struct intel_dp *intel_dp = intel_connector->mst_port; |
| 330 | |
Dave Airlie | c6a0aed | 2014-10-20 16:28:02 +1000 | [diff] [blame] | 331 | return drm_dp_mst_detect_port(connector, &intel_dp->mst_mgr, intel_connector->port); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 332 | } |
| 333 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 334 | static int |
| 335 | intel_dp_mst_set_property(struct drm_connector *connector, |
| 336 | struct drm_property *property, |
| 337 | uint64_t val) |
| 338 | { |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | static void |
| 343 | intel_dp_mst_connector_destroy(struct drm_connector *connector) |
| 344 | { |
| 345 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 346 | |
| 347 | if (!IS_ERR_OR_NULL(intel_connector->edid)) |
| 348 | kfree(intel_connector->edid); |
| 349 | |
| 350 | drm_connector_cleanup(connector); |
| 351 | kfree(connector); |
| 352 | } |
| 353 | |
| 354 | static const struct drm_connector_funcs intel_dp_mst_connector_funcs = { |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 355 | .dpms = drm_atomic_helper_connector_dpms, |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 356 | .detect = intel_dp_mst_detect, |
| 357 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 358 | .set_property = intel_dp_mst_set_property, |
Matt Roper | 2545e4a | 2015-01-22 16:51:27 -0800 | [diff] [blame] | 359 | .atomic_get_property = intel_connector_atomic_get_property, |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 360 | .destroy = intel_dp_mst_connector_destroy, |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 361 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
Ander Conselvan de Oliveira | 9896972 | 2015-03-20 16:18:06 +0200 | [diff] [blame] | 362 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 363 | }; |
| 364 | |
| 365 | static int intel_dp_mst_get_modes(struct drm_connector *connector) |
| 366 | { |
| 367 | return intel_dp_mst_get_ddc_modes(connector); |
| 368 | } |
| 369 | |
| 370 | static enum drm_mode_status |
| 371 | intel_dp_mst_mode_valid(struct drm_connector *connector, |
| 372 | struct drm_display_mode *mode) |
| 373 | { |
| 374 | /* TODO - validate mode against available PBN for link */ |
| 375 | if (mode->clock < 10000) |
| 376 | return MODE_CLOCK_LOW; |
| 377 | |
| 378 | if (mode->flags & DRM_MODE_FLAG_DBLCLK) |
| 379 | return MODE_H_ILLEGAL; |
| 380 | |
| 381 | return MODE_OK; |
| 382 | } |
| 383 | |
Daniel Vetter | 459485a | 2015-08-03 17:24:09 +0200 | [diff] [blame] | 384 | static struct drm_encoder *intel_mst_atomic_best_encoder(struct drm_connector *connector, |
| 385 | struct drm_connector_state *state) |
| 386 | { |
| 387 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 388 | struct intel_dp *intel_dp = intel_connector->mst_port; |
| 389 | struct intel_crtc *crtc = to_intel_crtc(state->crtc); |
| 390 | |
| 391 | return &intel_dp->mst_encoders[crtc->pipe]->base.base; |
| 392 | } |
| 393 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 394 | static struct drm_encoder *intel_mst_best_encoder(struct drm_connector *connector) |
| 395 | { |
| 396 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 397 | struct intel_dp *intel_dp = intel_connector->mst_port; |
| 398 | return &intel_dp->mst_encoders[0]->base.base; |
| 399 | } |
| 400 | |
| 401 | static const struct drm_connector_helper_funcs intel_dp_mst_connector_helper_funcs = { |
| 402 | .get_modes = intel_dp_mst_get_modes, |
| 403 | .mode_valid = intel_dp_mst_mode_valid, |
Daniel Vetter | 459485a | 2015-08-03 17:24:09 +0200 | [diff] [blame] | 404 | .atomic_best_encoder = intel_mst_atomic_best_encoder, |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 405 | .best_encoder = intel_mst_best_encoder, |
| 406 | }; |
| 407 | |
| 408 | static void intel_dp_mst_encoder_destroy(struct drm_encoder *encoder) |
| 409 | { |
| 410 | struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); |
| 411 | |
| 412 | drm_encoder_cleanup(encoder); |
| 413 | kfree(intel_mst); |
| 414 | } |
| 415 | |
| 416 | static const struct drm_encoder_funcs intel_dp_mst_enc_funcs = { |
| 417 | .destroy = intel_dp_mst_encoder_destroy, |
| 418 | }; |
| 419 | |
| 420 | static bool intel_dp_mst_get_hw_state(struct intel_connector *connector) |
| 421 | { |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 422 | if (connector->encoder && connector->base.state->crtc) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 423 | enum pipe pipe; |
| 424 | if (!connector->encoder->get_hw_state(connector->encoder, &pipe)) |
| 425 | return false; |
| 426 | return true; |
| 427 | } |
| 428 | return false; |
| 429 | } |
| 430 | |
Chris Wilson | 7296c84 | 2014-07-22 20:10:28 +1000 | [diff] [blame] | 431 | static void intel_connector_add_to_fbdev(struct intel_connector *connector) |
| 432 | { |
Daniel Vetter | 0695726 | 2015-08-10 13:34:08 +0200 | [diff] [blame] | 433 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Chris Wilson | 7296c84 | 2014-07-22 20:10:28 +1000 | [diff] [blame] | 434 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Lukas Wunner | 54632ab | 2015-11-18 13:43:20 +0100 | [diff] [blame] | 435 | |
| 436 | if (dev_priv->fbdev) |
| 437 | drm_fb_helper_add_one_connector(&dev_priv->fbdev->helper, |
| 438 | &connector->base); |
Chris Wilson | 7296c84 | 2014-07-22 20:10:28 +1000 | [diff] [blame] | 439 | #endif |
| 440 | } |
| 441 | |
| 442 | static void intel_connector_remove_from_fbdev(struct intel_connector *connector) |
| 443 | { |
Daniel Vetter | 0695726 | 2015-08-10 13:34:08 +0200 | [diff] [blame] | 444 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Chris Wilson | 7296c84 | 2014-07-22 20:10:28 +1000 | [diff] [blame] | 445 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Lukas Wunner | 54632ab | 2015-11-18 13:43:20 +0100 | [diff] [blame] | 446 | |
| 447 | if (dev_priv->fbdev) |
| 448 | drm_fb_helper_remove_one_connector(&dev_priv->fbdev->helper, |
| 449 | &connector->base); |
Chris Wilson | 7296c84 | 2014-07-22 20:10:28 +1000 | [diff] [blame] | 450 | #endif |
| 451 | } |
| 452 | |
Thierry Reding | 12e6cec | 2014-05-13 11:38:36 +0200 | [diff] [blame] | 453 | static 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 Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 454 | { |
| 455 | struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr); |
| 456 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 457 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 458 | struct intel_connector *intel_connector; |
| 459 | struct drm_connector *connector; |
| 460 | int i; |
| 461 | |
Ander Conselvan de Oliveira | 9bdbd0b | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 462 | intel_connector = intel_connector_alloc(); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 463 | if (!intel_connector) |
| 464 | return NULL; |
| 465 | |
| 466 | connector = &intel_connector->base; |
| 467 | drm_connector_init(dev, connector, &intel_dp_mst_connector_funcs, DRM_MODE_CONNECTOR_DisplayPort); |
| 468 | drm_connector_helper_add(connector, &intel_dp_mst_connector_helper_funcs); |
| 469 | |
| 470 | intel_connector->unregister = intel_connector_unregister; |
| 471 | intel_connector->get_hw_state = intel_dp_mst_get_hw_state; |
| 472 | intel_connector->mst_port = intel_dp; |
| 473 | intel_connector->port = port; |
| 474 | |
| 475 | for (i = PIPE_A; i <= PIPE_C; i++) { |
| 476 | drm_mode_connector_attach_encoder(&intel_connector->base, |
| 477 | &intel_dp->mst_encoders[i]->base.base); |
| 478 | } |
| 479 | intel_dp_add_properties(intel_dp, connector); |
| 480 | |
| 481 | drm_object_attach_property(&connector->base, dev->mode_config.path_property, 0); |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 482 | drm_object_attach_property(&connector->base, dev->mode_config.tile_property, 0); |
| 483 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 484 | drm_mode_connector_set_path_property(connector, pathprop); |
Dave Airlie | d9515c5 | 2015-09-16 17:55:23 +1000 | [diff] [blame] | 485 | return connector; |
| 486 | } |
| 487 | |
| 488 | static void intel_dp_register_mst_connector(struct drm_connector *connector) |
| 489 | { |
| 490 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 491 | struct drm_device *dev = connector->dev; |
Daniel Vetter | 8bb4da1 | 2015-07-09 23:44:31 +0200 | [diff] [blame] | 492 | drm_modeset_lock_all(dev); |
Chris Wilson | 7296c84 | 2014-07-22 20:10:28 +1000 | [diff] [blame] | 493 | intel_connector_add_to_fbdev(intel_connector); |
Daniel Vetter | 8bb4da1 | 2015-07-09 23:44:31 +0200 | [diff] [blame] | 494 | drm_modeset_unlock_all(dev); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 495 | drm_connector_register(&intel_connector->base); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr, |
| 499 | struct drm_connector *connector) |
| 500 | { |
| 501 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 502 | struct drm_device *dev = connector->dev; |
Maarten Lankhorst | 20fae98 | 2015-08-06 13:47:36 +0200 | [diff] [blame] | 503 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 504 | /* need to nuke the connector */ |
Daniel Vetter | 8bb4da1 | 2015-07-09 23:44:31 +0200 | [diff] [blame] | 505 | drm_modeset_lock_all(dev); |
Maarten Lankhorst | 20fae98 | 2015-08-06 13:47:36 +0200 | [diff] [blame] | 506 | if (connector->state->crtc) { |
| 507 | struct drm_mode_set set; |
| 508 | int ret; |
| 509 | |
| 510 | memset(&set, 0, sizeof(set)); |
| 511 | set.crtc = connector->state->crtc, |
| 512 | |
| 513 | ret = drm_atomic_helper_set_config(&set); |
| 514 | |
| 515 | WARN(ret, "Disabling mst crtc failed with %i\n", ret); |
| 516 | } |
Daniel Vetter | 8bb4da1 | 2015-07-09 23:44:31 +0200 | [diff] [blame] | 517 | drm_modeset_unlock_all(dev); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 518 | |
| 519 | intel_connector->unregister(intel_connector); |
| 520 | |
Daniel Vetter | 8bb4da1 | 2015-07-09 23:44:31 +0200 | [diff] [blame] | 521 | drm_modeset_lock_all(dev); |
Chris Wilson | 7296c84 | 2014-07-22 20:10:28 +1000 | [diff] [blame] | 522 | intel_connector_remove_from_fbdev(intel_connector); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 523 | drm_connector_cleanup(connector); |
Daniel Vetter | 8bb4da1 | 2015-07-09 23:44:31 +0200 | [diff] [blame] | 524 | drm_modeset_unlock_all(dev); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 525 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 526 | kfree(intel_connector); |
| 527 | DRM_DEBUG_KMS("\n"); |
| 528 | } |
| 529 | |
| 530 | static void intel_dp_mst_hotplug(struct drm_dp_mst_topology_mgr *mgr) |
| 531 | { |
| 532 | struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr); |
| 533 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 534 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 535 | |
| 536 | drm_kms_helper_hotplug_event(dev); |
| 537 | } |
| 538 | |
| 539 | static struct drm_dp_mst_topology_cbs mst_cbs = { |
| 540 | .add_connector = intel_dp_add_mst_connector, |
Dave Airlie | d9515c5 | 2015-09-16 17:55:23 +1000 | [diff] [blame] | 541 | .register_connector = intel_dp_register_mst_connector, |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 542 | .destroy_connector = intel_dp_destroy_mst_connector, |
| 543 | .hotplug = intel_dp_mst_hotplug, |
| 544 | }; |
| 545 | |
| 546 | static struct intel_dp_mst_encoder * |
| 547 | intel_dp_create_fake_mst_encoder(struct intel_digital_port *intel_dig_port, enum pipe pipe) |
| 548 | { |
| 549 | struct intel_dp_mst_encoder *intel_mst; |
| 550 | struct intel_encoder *intel_encoder; |
| 551 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 552 | |
| 553 | intel_mst = kzalloc(sizeof(*intel_mst), GFP_KERNEL); |
| 554 | |
| 555 | if (!intel_mst) |
| 556 | return NULL; |
| 557 | |
| 558 | intel_mst->pipe = pipe; |
| 559 | intel_encoder = &intel_mst->base; |
| 560 | intel_mst->primary = intel_dig_port; |
| 561 | |
| 562 | drm_encoder_init(dev, &intel_encoder->base, &intel_dp_mst_enc_funcs, |
| 563 | DRM_MODE_ENCODER_DPMST); |
| 564 | |
| 565 | intel_encoder->type = INTEL_OUTPUT_DP_MST; |
| 566 | intel_encoder->crtc_mask = 0x7; |
| 567 | intel_encoder->cloneable = 0; |
| 568 | |
| 569 | intel_encoder->compute_config = intel_dp_mst_compute_config; |
| 570 | intel_encoder->disable = intel_mst_disable_dp; |
| 571 | intel_encoder->post_disable = intel_mst_post_disable_dp; |
| 572 | intel_encoder->pre_enable = intel_mst_pre_enable_dp; |
| 573 | intel_encoder->enable = intel_mst_enable_dp; |
| 574 | intel_encoder->get_hw_state = intel_dp_mst_enc_get_hw_state; |
| 575 | intel_encoder->get_config = intel_dp_mst_enc_get_config; |
| 576 | |
| 577 | return intel_mst; |
| 578 | |
| 579 | } |
| 580 | |
| 581 | static bool |
| 582 | intel_dp_create_fake_mst_encoders(struct intel_digital_port *intel_dig_port) |
| 583 | { |
| 584 | int i; |
| 585 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 586 | |
| 587 | for (i = PIPE_A; i <= PIPE_C; i++) |
| 588 | intel_dp->mst_encoders[i] = intel_dp_create_fake_mst_encoder(intel_dig_port, i); |
| 589 | return true; |
| 590 | } |
| 591 | |
| 592 | int |
| 593 | intel_dp_mst_encoder_init(struct intel_digital_port *intel_dig_port, int conn_base_id) |
| 594 | { |
| 595 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 596 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 597 | int ret; |
| 598 | |
| 599 | intel_dp->can_mst = true; |
| 600 | intel_dp->mst_mgr.cbs = &mst_cbs; |
| 601 | |
| 602 | /* create encoders */ |
| 603 | intel_dp_create_fake_mst_encoders(intel_dig_port); |
| 604 | ret = drm_dp_mst_topology_mgr_init(&intel_dp->mst_mgr, dev->dev, &intel_dp->aux, 16, 3, conn_base_id); |
| 605 | if (ret) { |
| 606 | intel_dp->can_mst = false; |
| 607 | return ret; |
| 608 | } |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | void |
| 613 | intel_dp_mst_encoder_cleanup(struct intel_digital_port *intel_dig_port) |
| 614 | { |
| 615 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 616 | |
| 617 | if (!intel_dp->can_mst) |
| 618 | return; |
| 619 | |
| 620 | drm_dp_mst_topology_mgr_destroy(&intel_dp->mst_mgr); |
| 621 | /* encoders will get killed by normal cleanup */ |
| 622 | } |