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