diff options
Diffstat (limited to 'drivers/gpu/drm/i915/intel_dp.c')
-rw-r--r-- | drivers/gpu/drm/i915/intel_dp.c | 671 |
1 files changed, 343 insertions, 328 deletions
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c index 40be1fa65be1..9ab8708ac6ba 100644 --- a/drivers/gpu/drm/i915/intel_dp.c +++ b/drivers/gpu/drm/i915/intel_dp.c | |||
@@ -42,10 +42,11 @@ | |||
42 | 42 | ||
43 | #define DP_LINK_CONFIGURATION_SIZE 9 | 43 | #define DP_LINK_CONFIGURATION_SIZE 9 |
44 | 44 | ||
45 | #define IS_eDP(i) ((i)->type == INTEL_OUTPUT_EDP) | 45 | #define IS_eDP(i) ((i)->base.type == INTEL_OUTPUT_EDP) |
46 | #define IS_PCH_eDP(dp_priv) ((dp_priv)->is_pch_edp) | 46 | #define IS_PCH_eDP(i) ((i)->is_pch_edp) |
47 | 47 | ||
48 | struct intel_dp_priv { | 48 | struct intel_dp { |
49 | struct intel_encoder base; | ||
49 | uint32_t output_reg; | 50 | uint32_t output_reg; |
50 | uint32_t DP; | 51 | uint32_t DP; |
51 | uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE]; | 52 | uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE]; |
@@ -54,40 +55,39 @@ struct intel_dp_priv { | |||
54 | uint8_t link_bw; | 55 | uint8_t link_bw; |
55 | uint8_t lane_count; | 56 | uint8_t lane_count; |
56 | uint8_t dpcd[4]; | 57 | uint8_t dpcd[4]; |
57 | struct intel_encoder *intel_encoder; | ||
58 | struct i2c_adapter adapter; | 58 | struct i2c_adapter adapter; |
59 | struct i2c_algo_dp_aux_data algo; | 59 | struct i2c_algo_dp_aux_data algo; |
60 | bool is_pch_edp; | 60 | bool is_pch_edp; |
61 | }; | 61 | }; |
62 | 62 | ||
63 | static void | 63 | static struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder) |
64 | intel_dp_link_train(struct intel_encoder *intel_encoder, uint32_t DP, | 64 | { |
65 | uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE]); | 65 | return container_of(enc_to_intel_encoder(encoder), struct intel_dp, base); |
66 | } | ||
66 | 67 | ||
67 | static void | 68 | static void intel_dp_link_train(struct intel_dp *intel_dp); |
68 | intel_dp_link_down(struct intel_encoder *intel_encoder, uint32_t DP); | 69 | static void intel_dp_link_down(struct intel_dp *intel_dp); |
69 | 70 | ||
70 | void | 71 | void |
71 | intel_edp_link_config (struct intel_encoder *intel_encoder, | 72 | intel_edp_link_config (struct intel_encoder *intel_encoder, |
72 | int *lane_num, int *link_bw) | 73 | int *lane_num, int *link_bw) |
73 | { | 74 | { |
74 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | 75 | struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base); |
75 | 76 | ||
76 | *lane_num = dp_priv->lane_count; | 77 | *lane_num = intel_dp->lane_count; |
77 | if (dp_priv->link_bw == DP_LINK_BW_1_62) | 78 | if (intel_dp->link_bw == DP_LINK_BW_1_62) |
78 | *link_bw = 162000; | 79 | *link_bw = 162000; |
79 | else if (dp_priv->link_bw == DP_LINK_BW_2_7) | 80 | else if (intel_dp->link_bw == DP_LINK_BW_2_7) |
80 | *link_bw = 270000; | 81 | *link_bw = 270000; |
81 | } | 82 | } |
82 | 83 | ||
83 | static int | 84 | static int |
84 | intel_dp_max_lane_count(struct intel_encoder *intel_encoder) | 85 | intel_dp_max_lane_count(struct intel_dp *intel_dp) |
85 | { | 86 | { |
86 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | ||
87 | int max_lane_count = 4; | 87 | int max_lane_count = 4; |
88 | 88 | ||
89 | if (dp_priv->dpcd[0] >= 0x11) { | 89 | if (intel_dp->dpcd[0] >= 0x11) { |
90 | max_lane_count = dp_priv->dpcd[2] & 0x1f; | 90 | max_lane_count = intel_dp->dpcd[2] & 0x1f; |
91 | switch (max_lane_count) { | 91 | switch (max_lane_count) { |
92 | case 1: case 2: case 4: | 92 | case 1: case 2: case 4: |
93 | break; | 93 | break; |
@@ -99,10 +99,9 @@ intel_dp_max_lane_count(struct intel_encoder *intel_encoder) | |||
99 | } | 99 | } |
100 | 100 | ||
101 | static int | 101 | static int |
102 | intel_dp_max_link_bw(struct intel_encoder *intel_encoder) | 102 | intel_dp_max_link_bw(struct intel_dp *intel_dp) |
103 | { | 103 | { |
104 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | 104 | int max_link_bw = intel_dp->dpcd[1]; |
105 | int max_link_bw = dp_priv->dpcd[1]; | ||
106 | 105 | ||
107 | switch (max_link_bw) { | 106 | switch (max_link_bw) { |
108 | case DP_LINK_BW_1_62: | 107 | case DP_LINK_BW_1_62: |
@@ -126,13 +125,11 @@ intel_dp_link_clock(uint8_t link_bw) | |||
126 | 125 | ||
127 | /* I think this is a fiction */ | 126 | /* I think this is a fiction */ |
128 | static int | 127 | static int |
129 | intel_dp_link_required(struct drm_device *dev, | 128 | intel_dp_link_required(struct drm_device *dev, struct intel_dp *intel_dp, int pixel_clock) |
130 | struct intel_encoder *intel_encoder, int pixel_clock) | ||
131 | { | 129 | { |
132 | struct drm_i915_private *dev_priv = dev->dev_private; | 130 | struct drm_i915_private *dev_priv = dev->dev_private; |
133 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | ||
134 | 131 | ||
135 | if (IS_eDP(intel_encoder) || IS_PCH_eDP(dp_priv)) | 132 | if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) |
136 | return (pixel_clock * dev_priv->edp_bpp) / 8; | 133 | return (pixel_clock * dev_priv->edp_bpp) / 8; |
137 | else | 134 | else |
138 | return pixel_clock * 3; | 135 | return pixel_clock * 3; |
@@ -149,14 +146,13 @@ intel_dp_mode_valid(struct drm_connector *connector, | |||
149 | struct drm_display_mode *mode) | 146 | struct drm_display_mode *mode) |
150 | { | 147 | { |
151 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 148 | struct drm_encoder *encoder = intel_attached_encoder(connector); |
152 | struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); | 149 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
153 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | ||
154 | struct drm_device *dev = connector->dev; | 150 | struct drm_device *dev = connector->dev; |
155 | struct drm_i915_private *dev_priv = dev->dev_private; | 151 | struct drm_i915_private *dev_priv = dev->dev_private; |
156 | int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_encoder)); | 152 | int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp)); |
157 | int max_lanes = intel_dp_max_lane_count(intel_encoder); | 153 | int max_lanes = intel_dp_max_lane_count(intel_dp); |
158 | 154 | ||
159 | if ((IS_eDP(intel_encoder) || IS_PCH_eDP(dp_priv)) && | 155 | if ((IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) && |
160 | dev_priv->panel_fixed_mode) { | 156 | dev_priv->panel_fixed_mode) { |
161 | if (mode->hdisplay > dev_priv->panel_fixed_mode->hdisplay) | 157 | if (mode->hdisplay > dev_priv->panel_fixed_mode->hdisplay) |
162 | return MODE_PANEL; | 158 | return MODE_PANEL; |
@@ -167,8 +163,8 @@ intel_dp_mode_valid(struct drm_connector *connector, | |||
167 | 163 | ||
168 | /* only refuse the mode on non eDP since we have seen some wierd eDP panels | 164 | /* only refuse the mode on non eDP since we have seen some wierd eDP panels |
169 | which are outside spec tolerances but somehow work by magic */ | 165 | which are outside spec tolerances but somehow work by magic */ |
170 | if (!IS_eDP(intel_encoder) && | 166 | if (!IS_eDP(intel_dp) && |
171 | (intel_dp_link_required(connector->dev, intel_encoder, mode->clock) | 167 | (intel_dp_link_required(connector->dev, intel_dp, mode->clock) |
172 | > intel_dp_max_data_rate(max_link_clock, max_lanes))) | 168 | > intel_dp_max_data_rate(max_link_clock, max_lanes))) |
173 | return MODE_CLOCK_HIGH; | 169 | return MODE_CLOCK_HIGH; |
174 | 170 | ||
@@ -232,19 +228,17 @@ intel_hrawclk(struct drm_device *dev) | |||
232 | } | 228 | } |
233 | 229 | ||
234 | static int | 230 | static int |
235 | intel_dp_aux_ch(struct intel_encoder *intel_encoder, | 231 | intel_dp_aux_ch(struct intel_dp *intel_dp, |
236 | uint8_t *send, int send_bytes, | 232 | uint8_t *send, int send_bytes, |
237 | uint8_t *recv, int recv_size) | 233 | uint8_t *recv, int recv_size) |
238 | { | 234 | { |
239 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | 235 | uint32_t output_reg = intel_dp->output_reg; |
240 | uint32_t output_reg = dp_priv->output_reg; | 236 | struct drm_device *dev = intel_dp->base.enc.dev; |
241 | struct drm_device *dev = intel_encoder->enc.dev; | ||
242 | struct drm_i915_private *dev_priv = dev->dev_private; | 237 | struct drm_i915_private *dev_priv = dev->dev_private; |
243 | uint32_t ch_ctl = output_reg + 0x10; | 238 | uint32_t ch_ctl = output_reg + 0x10; |
244 | uint32_t ch_data = ch_ctl + 4; | 239 | uint32_t ch_data = ch_ctl + 4; |
245 | int i; | 240 | int i; |
246 | int recv_bytes; | 241 | int recv_bytes; |
247 | uint32_t ctl; | ||
248 | uint32_t status; | 242 | uint32_t status; |
249 | uint32_t aux_clock_divider; | 243 | uint32_t aux_clock_divider; |
250 | int try, precharge; | 244 | int try, precharge; |
@@ -253,7 +247,7 @@ intel_dp_aux_ch(struct intel_encoder *intel_encoder, | |||
253 | * and would like to run at 2MHz. So, take the | 247 | * and would like to run at 2MHz. So, take the |
254 | * hrawclk value and divide by 2 and use that | 248 | * hrawclk value and divide by 2 and use that |
255 | */ | 249 | */ |
256 | if (IS_eDP(intel_encoder)) { | 250 | if (IS_eDP(intel_dp)) { |
257 | if (IS_GEN6(dev)) | 251 | if (IS_GEN6(dev)) |
258 | aux_clock_divider = 200; /* SNB eDP input clock at 400Mhz */ | 252 | aux_clock_divider = 200; /* SNB eDP input clock at 400Mhz */ |
259 | else | 253 | else |
@@ -268,41 +262,43 @@ intel_dp_aux_ch(struct intel_encoder *intel_encoder, | |||
268 | else | 262 | else |
269 | precharge = 5; | 263 | precharge = 5; |
270 | 264 | ||
265 | if (I915_READ(ch_ctl) & DP_AUX_CH_CTL_SEND_BUSY) { | ||
266 | DRM_ERROR("dp_aux_ch not started status 0x%08x\n", | ||
267 | I915_READ(ch_ctl)); | ||
268 | return -EBUSY; | ||
269 | } | ||
270 | |||
271 | /* Must try at least 3 times according to DP spec */ | 271 | /* Must try at least 3 times according to DP spec */ |
272 | for (try = 0; try < 5; try++) { | 272 | for (try = 0; try < 5; try++) { |
273 | /* Load the send data into the aux channel data registers */ | 273 | /* Load the send data into the aux channel data registers */ |
274 | for (i = 0; i < send_bytes; i += 4) { | 274 | for (i = 0; i < send_bytes; i += 4) |
275 | uint32_t d = pack_aux(send + i, send_bytes - i); | 275 | I915_WRITE(ch_data + i, |
276 | 276 | pack_aux(send + i, send_bytes - i)); | |
277 | I915_WRITE(ch_data + i, d); | ||
278 | } | ||
279 | |||
280 | ctl = (DP_AUX_CH_CTL_SEND_BUSY | | ||
281 | DP_AUX_CH_CTL_TIME_OUT_400us | | ||
282 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | | ||
283 | (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) | | ||
284 | (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) | | ||
285 | DP_AUX_CH_CTL_DONE | | ||
286 | DP_AUX_CH_CTL_TIME_OUT_ERROR | | ||
287 | DP_AUX_CH_CTL_RECEIVE_ERROR); | ||
288 | 277 | ||
289 | /* Send the command and wait for it to complete */ | 278 | /* Send the command and wait for it to complete */ |
290 | I915_WRITE(ch_ctl, ctl); | 279 | I915_WRITE(ch_ctl, |
291 | (void) I915_READ(ch_ctl); | 280 | DP_AUX_CH_CTL_SEND_BUSY | |
281 | DP_AUX_CH_CTL_TIME_OUT_400us | | ||
282 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | | ||
283 | (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) | | ||
284 | (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) | | ||
285 | DP_AUX_CH_CTL_DONE | | ||
286 | DP_AUX_CH_CTL_TIME_OUT_ERROR | | ||
287 | DP_AUX_CH_CTL_RECEIVE_ERROR); | ||
292 | for (;;) { | 288 | for (;;) { |
293 | udelay(100); | ||
294 | status = I915_READ(ch_ctl); | 289 | status = I915_READ(ch_ctl); |
295 | if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0) | 290 | if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0) |
296 | break; | 291 | break; |
292 | udelay(100); | ||
297 | } | 293 | } |
298 | 294 | ||
299 | /* Clear done status and any errors */ | 295 | /* Clear done status and any errors */ |
300 | I915_WRITE(ch_ctl, (status | | 296 | I915_WRITE(ch_ctl, |
301 | DP_AUX_CH_CTL_DONE | | 297 | status | |
302 | DP_AUX_CH_CTL_TIME_OUT_ERROR | | 298 | DP_AUX_CH_CTL_DONE | |
303 | DP_AUX_CH_CTL_RECEIVE_ERROR)); | 299 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
304 | (void) I915_READ(ch_ctl); | 300 | DP_AUX_CH_CTL_RECEIVE_ERROR); |
305 | if ((status & DP_AUX_CH_CTL_TIME_OUT_ERROR) == 0) | 301 | if (status & DP_AUX_CH_CTL_DONE) |
306 | break; | 302 | break; |
307 | } | 303 | } |
308 | 304 | ||
@@ -329,22 +325,19 @@ intel_dp_aux_ch(struct intel_encoder *intel_encoder, | |||
329 | /* Unload any bytes sent back from the other side */ | 325 | /* Unload any bytes sent back from the other side */ |
330 | recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >> | 326 | recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >> |
331 | DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT); | 327 | DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT); |
332 | |||
333 | if (recv_bytes > recv_size) | 328 | if (recv_bytes > recv_size) |
334 | recv_bytes = recv_size; | 329 | recv_bytes = recv_size; |
335 | 330 | ||
336 | for (i = 0; i < recv_bytes; i += 4) { | 331 | for (i = 0; i < recv_bytes; i += 4) |
337 | uint32_t d = I915_READ(ch_data + i); | 332 | unpack_aux(I915_READ(ch_data + i), |
338 | 333 | recv + i, recv_bytes - i); | |
339 | unpack_aux(d, recv + i, recv_bytes - i); | ||
340 | } | ||
341 | 334 | ||
342 | return recv_bytes; | 335 | return recv_bytes; |
343 | } | 336 | } |
344 | 337 | ||
345 | /* Write data to the aux channel in native mode */ | 338 | /* Write data to the aux channel in native mode */ |
346 | static int | 339 | static int |
347 | intel_dp_aux_native_write(struct intel_encoder *intel_encoder, | 340 | intel_dp_aux_native_write(struct intel_dp *intel_dp, |
348 | uint16_t address, uint8_t *send, int send_bytes) | 341 | uint16_t address, uint8_t *send, int send_bytes) |
349 | { | 342 | { |
350 | int ret; | 343 | int ret; |
@@ -361,7 +354,7 @@ intel_dp_aux_native_write(struct intel_encoder *intel_encoder, | |||
361 | memcpy(&msg[4], send, send_bytes); | 354 | memcpy(&msg[4], send, send_bytes); |
362 | msg_bytes = send_bytes + 4; | 355 | msg_bytes = send_bytes + 4; |
363 | for (;;) { | 356 | for (;;) { |
364 | ret = intel_dp_aux_ch(intel_encoder, msg, msg_bytes, &ack, 1); | 357 | ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1); |
365 | if (ret < 0) | 358 | if (ret < 0) |
366 | return ret; | 359 | return ret; |
367 | if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) | 360 | if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) |
@@ -376,15 +369,15 @@ intel_dp_aux_native_write(struct intel_encoder *intel_encoder, | |||
376 | 369 | ||
377 | /* Write a single byte to the aux channel in native mode */ | 370 | /* Write a single byte to the aux channel in native mode */ |
378 | static int | 371 | static int |
379 | intel_dp_aux_native_write_1(struct intel_encoder *intel_encoder, | 372 | intel_dp_aux_native_write_1(struct intel_dp *intel_dp, |
380 | uint16_t address, uint8_t byte) | 373 | uint16_t address, uint8_t byte) |
381 | { | 374 | { |
382 | return intel_dp_aux_native_write(intel_encoder, address, &byte, 1); | 375 | return intel_dp_aux_native_write(intel_dp, address, &byte, 1); |
383 | } | 376 | } |
384 | 377 | ||
385 | /* read bytes from a native aux channel */ | 378 | /* read bytes from a native aux channel */ |
386 | static int | 379 | static int |
387 | intel_dp_aux_native_read(struct intel_encoder *intel_encoder, | 380 | intel_dp_aux_native_read(struct intel_dp *intel_dp, |
388 | uint16_t address, uint8_t *recv, int recv_bytes) | 381 | uint16_t address, uint8_t *recv, int recv_bytes) |
389 | { | 382 | { |
390 | uint8_t msg[4]; | 383 | uint8_t msg[4]; |
@@ -403,7 +396,7 @@ intel_dp_aux_native_read(struct intel_encoder *intel_encoder, | |||
403 | reply_bytes = recv_bytes + 1; | 396 | reply_bytes = recv_bytes + 1; |
404 | 397 | ||
405 | for (;;) { | 398 | for (;;) { |
406 | ret = intel_dp_aux_ch(intel_encoder, msg, msg_bytes, | 399 | ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, |
407 | reply, reply_bytes); | 400 | reply, reply_bytes); |
408 | if (ret == 0) | 401 | if (ret == 0) |
409 | return -EPROTO; | 402 | return -EPROTO; |
@@ -426,10 +419,9 @@ intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode, | |||
426 | uint8_t write_byte, uint8_t *read_byte) | 419 | uint8_t write_byte, uint8_t *read_byte) |
427 | { | 420 | { |
428 | struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; | 421 | struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; |
429 | struct intel_dp_priv *dp_priv = container_of(adapter, | 422 | struct intel_dp *intel_dp = container_of(adapter, |
430 | struct intel_dp_priv, | 423 | struct intel_dp, |
431 | adapter); | 424 | adapter); |
432 | struct intel_encoder *intel_encoder = dp_priv->intel_encoder; | ||
433 | uint16_t address = algo_data->address; | 425 | uint16_t address = algo_data->address; |
434 | uint8_t msg[5]; | 426 | uint8_t msg[5]; |
435 | uint8_t reply[2]; | 427 | uint8_t reply[2]; |
@@ -468,7 +460,7 @@ intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode, | |||
468 | } | 460 | } |
469 | 461 | ||
470 | for (;;) { | 462 | for (;;) { |
471 | ret = intel_dp_aux_ch(intel_encoder, | 463 | ret = intel_dp_aux_ch(intel_dp, |
472 | msg, msg_bytes, | 464 | msg, msg_bytes, |
473 | reply, reply_bytes); | 465 | reply, reply_bytes); |
474 | if (ret < 0) { | 466 | if (ret < 0) { |
@@ -496,57 +488,42 @@ intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode, | |||
496 | } | 488 | } |
497 | 489 | ||
498 | static int | 490 | static int |
499 | intel_dp_i2c_init(struct intel_encoder *intel_encoder, | 491 | intel_dp_i2c_init(struct intel_dp *intel_dp, |
500 | struct intel_connector *intel_connector, const char *name) | 492 | struct intel_connector *intel_connector, const char *name) |
501 | { | 493 | { |
502 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | ||
503 | |||
504 | DRM_DEBUG_KMS("i2c_init %s\n", name); | 494 | DRM_DEBUG_KMS("i2c_init %s\n", name); |
505 | dp_priv->algo.running = false; | 495 | intel_dp->algo.running = false; |
506 | dp_priv->algo.address = 0; | 496 | intel_dp->algo.address = 0; |
507 | dp_priv->algo.aux_ch = intel_dp_i2c_aux_ch; | 497 | intel_dp->algo.aux_ch = intel_dp_i2c_aux_ch; |
508 | 498 | ||
509 | memset(&dp_priv->adapter, '\0', sizeof (dp_priv->adapter)); | 499 | memset(&intel_dp->adapter, '\0', sizeof (intel_dp->adapter)); |
510 | dp_priv->adapter.owner = THIS_MODULE; | 500 | intel_dp->adapter.owner = THIS_MODULE; |
511 | dp_priv->adapter.class = I2C_CLASS_DDC; | 501 | intel_dp->adapter.class = I2C_CLASS_DDC; |
512 | strncpy (dp_priv->adapter.name, name, sizeof(dp_priv->adapter.name) - 1); | 502 | strncpy (intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1); |
513 | dp_priv->adapter.name[sizeof(dp_priv->adapter.name) - 1] = '\0'; | 503 | intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0'; |
514 | dp_priv->adapter.algo_data = &dp_priv->algo; | 504 | intel_dp->adapter.algo_data = &intel_dp->algo; |
515 | dp_priv->adapter.dev.parent = &intel_connector->base.kdev; | 505 | intel_dp->adapter.dev.parent = &intel_connector->base.kdev; |
516 | 506 | ||
517 | return i2c_dp_aux_add_bus(&dp_priv->adapter); | 507 | return i2c_dp_aux_add_bus(&intel_dp->adapter); |
518 | } | 508 | } |
519 | 509 | ||
520 | static bool | 510 | static bool |
521 | intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode, | 511 | intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode, |
522 | struct drm_display_mode *adjusted_mode) | 512 | struct drm_display_mode *adjusted_mode) |
523 | { | 513 | { |
524 | struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); | ||
525 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | ||
526 | struct drm_device *dev = encoder->dev; | 514 | struct drm_device *dev = encoder->dev; |
527 | struct drm_i915_private *dev_priv = dev->dev_private; | 515 | struct drm_i915_private *dev_priv = dev->dev_private; |
516 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); | ||
528 | int lane_count, clock; | 517 | int lane_count, clock; |
529 | int max_lane_count = intel_dp_max_lane_count(intel_encoder); | 518 | int max_lane_count = intel_dp_max_lane_count(intel_dp); |
530 | int max_clock = intel_dp_max_link_bw(intel_encoder) == DP_LINK_BW_2_7 ? 1 : 0; | 519 | int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0; |
531 | static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 }; | 520 | static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 }; |
532 | 521 | ||
533 | if ((IS_eDP(intel_encoder) || IS_PCH_eDP(dp_priv)) && | 522 | if ((IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) && |
534 | dev_priv->panel_fixed_mode) { | 523 | dev_priv->panel_fixed_mode) { |
535 | struct drm_display_mode *fixed_mode = dev_priv->panel_fixed_mode; | 524 | intel_fixed_panel_mode(dev_priv->panel_fixed_mode, adjusted_mode); |
536 | 525 | intel_pch_panel_fitting(dev, DRM_MODE_SCALE_FULLSCREEN, | |
537 | adjusted_mode->hdisplay = fixed_mode->hdisplay; | 526 | mode, adjusted_mode); |
538 | adjusted_mode->hsync_start = fixed_mode->hsync_start; | ||
539 | adjusted_mode->hsync_end = fixed_mode->hsync_end; | ||
540 | adjusted_mode->htotal = fixed_mode->htotal; | ||
541 | |||
542 | adjusted_mode->vdisplay = fixed_mode->vdisplay; | ||
543 | adjusted_mode->vsync_start = fixed_mode->vsync_start; | ||
544 | adjusted_mode->vsync_end = fixed_mode->vsync_end; | ||
545 | adjusted_mode->vtotal = fixed_mode->vtotal; | ||
546 | |||
547 | adjusted_mode->clock = fixed_mode->clock; | ||
548 | drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V); | ||
549 | |||
550 | /* | 527 | /* |
551 | * the mode->clock is used to calculate the Data&Link M/N | 528 | * the mode->clock is used to calculate the Data&Link M/N |
552 | * of the pipe. For the eDP the fixed clock should be used. | 529 | * of the pipe. For the eDP the fixed clock should be used. |
@@ -558,31 +535,33 @@ intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode, | |||
558 | for (clock = 0; clock <= max_clock; clock++) { | 535 | for (clock = 0; clock <= max_clock; clock++) { |
559 | int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count); | 536 | int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count); |
560 | 537 | ||
561 | if (intel_dp_link_required(encoder->dev, intel_encoder, mode->clock) | 538 | if (intel_dp_link_required(encoder->dev, intel_dp, mode->clock) |
562 | <= link_avail) { | 539 | <= link_avail) { |
563 | dp_priv->link_bw = bws[clock]; | 540 | intel_dp->link_bw = bws[clock]; |
564 | dp_priv->lane_count = lane_count; | 541 | intel_dp->lane_count = lane_count; |
565 | adjusted_mode->clock = intel_dp_link_clock(dp_priv->link_bw); | 542 | adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw); |
566 | DRM_DEBUG_KMS("Display port link bw %02x lane " | 543 | DRM_DEBUG_KMS("Display port link bw %02x lane " |
567 | "count %d clock %d\n", | 544 | "count %d clock %d\n", |
568 | dp_priv->link_bw, dp_priv->lane_count, | 545 | intel_dp->link_bw, intel_dp->lane_count, |
569 | adjusted_mode->clock); | 546 | adjusted_mode->clock); |
570 | return true; | 547 | return true; |
571 | } | 548 | } |
572 | } | 549 | } |
573 | } | 550 | } |
574 | 551 | ||
575 | if (IS_eDP(intel_encoder) || IS_PCH_eDP(dp_priv)) { | 552 | if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) { |
576 | /* okay we failed just pick the highest */ | 553 | /* okay we failed just pick the highest */ |
577 | dp_priv->lane_count = max_lane_count; | 554 | intel_dp->lane_count = max_lane_count; |
578 | dp_priv->link_bw = bws[max_clock]; | 555 | intel_dp->link_bw = bws[max_clock]; |
579 | adjusted_mode->clock = intel_dp_link_clock(dp_priv->link_bw); | 556 | adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw); |
580 | DRM_DEBUG_KMS("Force picking display port link bw %02x lane " | 557 | DRM_DEBUG_KMS("Force picking display port link bw %02x lane " |
581 | "count %d clock %d\n", | 558 | "count %d clock %d\n", |
582 | dp_priv->link_bw, dp_priv->lane_count, | 559 | intel_dp->link_bw, intel_dp->lane_count, |
583 | adjusted_mode->clock); | 560 | adjusted_mode->clock); |
561 | |||
584 | return true; | 562 | return true; |
585 | } | 563 | } |
564 | |||
586 | return false; | 565 | return false; |
587 | } | 566 | } |
588 | 567 | ||
@@ -626,17 +605,14 @@ bool intel_pch_has_edp(struct drm_crtc *crtc) | |||
626 | struct drm_encoder *encoder; | 605 | struct drm_encoder *encoder; |
627 | 606 | ||
628 | list_for_each_entry(encoder, &mode_config->encoder_list, head) { | 607 | list_for_each_entry(encoder, &mode_config->encoder_list, head) { |
629 | struct intel_encoder *intel_encoder; | 608 | struct intel_dp *intel_dp; |
630 | struct intel_dp_priv *dp_priv; | ||
631 | 609 | ||
632 | if (!encoder || encoder->crtc != crtc) | 610 | if (encoder->crtc != crtc) |
633 | continue; | 611 | continue; |
634 | 612 | ||
635 | intel_encoder = enc_to_intel_encoder(encoder); | 613 | intel_dp = enc_to_intel_dp(encoder); |
636 | dp_priv = intel_encoder->dev_priv; | 614 | if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT) |
637 | 615 | return intel_dp->is_pch_edp; | |
638 | if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT) | ||
639 | return dp_priv->is_pch_edp; | ||
640 | } | 616 | } |
641 | return false; | 617 | return false; |
642 | } | 618 | } |
@@ -657,18 +633,15 @@ intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode, | |||
657 | * Find the lane count in the intel_encoder private | 633 | * Find the lane count in the intel_encoder private |
658 | */ | 634 | */ |
659 | list_for_each_entry(encoder, &mode_config->encoder_list, head) { | 635 | list_for_each_entry(encoder, &mode_config->encoder_list, head) { |
660 | struct intel_encoder *intel_encoder; | 636 | struct intel_dp *intel_dp; |
661 | struct intel_dp_priv *dp_priv; | ||
662 | 637 | ||
663 | if (encoder->crtc != crtc) | 638 | if (encoder->crtc != crtc) |
664 | continue; | 639 | continue; |
665 | 640 | ||
666 | intel_encoder = enc_to_intel_encoder(encoder); | 641 | intel_dp = enc_to_intel_dp(encoder); |
667 | dp_priv = intel_encoder->dev_priv; | 642 | if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT) { |
668 | 643 | lane_count = intel_dp->lane_count; | |
669 | if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT) { | 644 | if (IS_PCH_eDP(intel_dp)) |
670 | lane_count = dp_priv->lane_count; | ||
671 | if (IS_PCH_eDP(dp_priv)) | ||
672 | bpp = dev_priv->edp_bpp; | 645 | bpp = dev_priv->edp_bpp; |
673 | break; | 646 | break; |
674 | } | 647 | } |
@@ -724,107 +697,114 @@ intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, | |||
724 | struct drm_display_mode *adjusted_mode) | 697 | struct drm_display_mode *adjusted_mode) |
725 | { | 698 | { |
726 | struct drm_device *dev = encoder->dev; | 699 | struct drm_device *dev = encoder->dev; |
727 | struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); | 700 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
728 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | 701 | struct drm_crtc *crtc = intel_dp->base.enc.crtc; |
729 | struct drm_crtc *crtc = intel_encoder->enc.crtc; | ||
730 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | 702 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
731 | 703 | ||
732 | dp_priv->DP = (DP_VOLTAGE_0_4 | | 704 | intel_dp->DP = (DP_VOLTAGE_0_4 | |
733 | DP_PRE_EMPHASIS_0); | 705 | DP_PRE_EMPHASIS_0); |
734 | 706 | ||
735 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) | 707 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
736 | dp_priv->DP |= DP_SYNC_HS_HIGH; | 708 | intel_dp->DP |= DP_SYNC_HS_HIGH; |
737 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) | 709 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
738 | dp_priv->DP |= DP_SYNC_VS_HIGH; | 710 | intel_dp->DP |= DP_SYNC_VS_HIGH; |
739 | 711 | ||
740 | if (HAS_PCH_CPT(dev) && !IS_eDP(intel_encoder)) | 712 | if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp)) |
741 | dp_priv->DP |= DP_LINK_TRAIN_OFF_CPT; | 713 | intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; |
742 | else | 714 | else |
743 | dp_priv->DP |= DP_LINK_TRAIN_OFF; | 715 | intel_dp->DP |= DP_LINK_TRAIN_OFF; |
744 | 716 | ||
745 | switch (dp_priv->lane_count) { | 717 | switch (intel_dp->lane_count) { |
746 | case 1: | 718 | case 1: |
747 | dp_priv->DP |= DP_PORT_WIDTH_1; | 719 | intel_dp->DP |= DP_PORT_WIDTH_1; |
748 | break; | 720 | break; |
749 | case 2: | 721 | case 2: |
750 | dp_priv->DP |= DP_PORT_WIDTH_2; | 722 | intel_dp->DP |= DP_PORT_WIDTH_2; |
751 | break; | 723 | break; |
752 | case 4: | 724 | case 4: |
753 | dp_priv->DP |= DP_PORT_WIDTH_4; | 725 | intel_dp->DP |= DP_PORT_WIDTH_4; |
754 | break; | 726 | break; |
755 | } | 727 | } |
756 | if (dp_priv->has_audio) | 728 | if (intel_dp->has_audio) |
757 | dp_priv->DP |= DP_AUDIO_OUTPUT_ENABLE; | 729 | intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE; |
758 | 730 | ||
759 | memset(dp_priv->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE); | 731 | memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE); |
760 | dp_priv->link_configuration[0] = dp_priv->link_bw; | 732 | intel_dp->link_configuration[0] = intel_dp->link_bw; |
761 | dp_priv->link_configuration[1] = dp_priv->lane_count; | 733 | intel_dp->link_configuration[1] = intel_dp->lane_count; |
762 | 734 | ||
763 | /* | 735 | /* |
764 | * Check for DPCD version > 1.1 and enhanced framing support | 736 | * Check for DPCD version > 1.1 and enhanced framing support |
765 | */ | 737 | */ |
766 | if (dp_priv->dpcd[0] >= 0x11 && (dp_priv->dpcd[2] & DP_ENHANCED_FRAME_CAP)) { | 738 | if (intel_dp->dpcd[0] >= 0x11 && (intel_dp->dpcd[2] & DP_ENHANCED_FRAME_CAP)) { |
767 | dp_priv->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN; | 739 | intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN; |
768 | dp_priv->DP |= DP_ENHANCED_FRAMING; | 740 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
769 | } | 741 | } |
770 | 742 | ||
771 | /* CPT DP's pipe select is decided in TRANS_DP_CTL */ | 743 | /* CPT DP's pipe select is decided in TRANS_DP_CTL */ |
772 | if (intel_crtc->pipe == 1 && !HAS_PCH_CPT(dev)) | 744 | if (intel_crtc->pipe == 1 && !HAS_PCH_CPT(dev)) |
773 | dp_priv->DP |= DP_PIPEB_SELECT; | 745 | intel_dp->DP |= DP_PIPEB_SELECT; |
774 | 746 | ||
775 | if (IS_eDP(intel_encoder)) { | 747 | if (IS_eDP(intel_dp)) { |
776 | /* don't miss out required setting for eDP */ | 748 | /* don't miss out required setting for eDP */ |
777 | dp_priv->DP |= DP_PLL_ENABLE; | 749 | intel_dp->DP |= DP_PLL_ENABLE; |
778 | if (adjusted_mode->clock < 200000) | 750 | if (adjusted_mode->clock < 200000) |
779 | dp_priv->DP |= DP_PLL_FREQ_160MHZ; | 751 | intel_dp->DP |= DP_PLL_FREQ_160MHZ; |
780 | else | 752 | else |
781 | dp_priv->DP |= DP_PLL_FREQ_270MHZ; | 753 | intel_dp->DP |= DP_PLL_FREQ_270MHZ; |
782 | } | 754 | } |
783 | } | 755 | } |
784 | 756 | ||
785 | static void ironlake_edp_panel_on (struct drm_device *dev) | 757 | static void ironlake_edp_panel_on (struct drm_device *dev) |
786 | { | 758 | { |
787 | struct drm_i915_private *dev_priv = dev->dev_private; | 759 | struct drm_i915_private *dev_priv = dev->dev_private; |
788 | unsigned long timeout = jiffies + msecs_to_jiffies(5000); | 760 | u32 pp; |
789 | u32 pp, pp_status; | ||
790 | 761 | ||
791 | pp_status = I915_READ(PCH_PP_STATUS); | 762 | if (I915_READ(PCH_PP_STATUS) & PP_ON) |
792 | if (pp_status & PP_ON) | ||
793 | return; | 763 | return; |
794 | 764 | ||
795 | pp = I915_READ(PCH_PP_CONTROL); | 765 | pp = I915_READ(PCH_PP_CONTROL); |
766 | |||
767 | /* ILK workaround: disable reset around power sequence */ | ||
768 | pp &= ~PANEL_POWER_RESET; | ||
769 | I915_WRITE(PCH_PP_CONTROL, pp); | ||
770 | POSTING_READ(PCH_PP_CONTROL); | ||
771 | |||
796 | pp |= PANEL_UNLOCK_REGS | POWER_TARGET_ON; | 772 | pp |= PANEL_UNLOCK_REGS | POWER_TARGET_ON; |
797 | I915_WRITE(PCH_PP_CONTROL, pp); | 773 | I915_WRITE(PCH_PP_CONTROL, pp); |
798 | do { | ||
799 | pp_status = I915_READ(PCH_PP_STATUS); | ||
800 | } while (((pp_status & PP_ON) == 0) && !time_after(jiffies, timeout)); | ||
801 | 774 | ||
802 | if (time_after(jiffies, timeout)) | 775 | if (wait_for(I915_READ(PCH_PP_STATUS) & PP_ON, 5000, 10)) |
803 | DRM_DEBUG_KMS("panel on wait timed out: 0x%08x\n", pp_status); | 776 | DRM_ERROR("panel on wait timed out: 0x%08x\n", |
777 | I915_READ(PCH_PP_STATUS)); | ||
804 | 778 | ||
805 | pp &= ~(PANEL_UNLOCK_REGS | EDP_FORCE_VDD); | 779 | pp &= ~(PANEL_UNLOCK_REGS | EDP_FORCE_VDD); |
780 | pp |= PANEL_POWER_RESET; /* restore panel reset bit */ | ||
806 | I915_WRITE(PCH_PP_CONTROL, pp); | 781 | I915_WRITE(PCH_PP_CONTROL, pp); |
782 | POSTING_READ(PCH_PP_CONTROL); | ||
807 | } | 783 | } |
808 | 784 | ||
809 | static void ironlake_edp_panel_off (struct drm_device *dev) | 785 | static void ironlake_edp_panel_off (struct drm_device *dev) |
810 | { | 786 | { |
811 | struct drm_i915_private *dev_priv = dev->dev_private; | 787 | struct drm_i915_private *dev_priv = dev->dev_private; |
812 | unsigned long timeout = jiffies + msecs_to_jiffies(5000); | 788 | u32 pp; |
813 | u32 pp, pp_status; | ||
814 | 789 | ||
815 | pp = I915_READ(PCH_PP_CONTROL); | 790 | pp = I915_READ(PCH_PP_CONTROL); |
791 | |||
792 | /* ILK workaround: disable reset around power sequence */ | ||
793 | pp &= ~PANEL_POWER_RESET; | ||
794 | I915_WRITE(PCH_PP_CONTROL, pp); | ||
795 | POSTING_READ(PCH_PP_CONTROL); | ||
796 | |||
816 | pp &= ~POWER_TARGET_ON; | 797 | pp &= ~POWER_TARGET_ON; |
817 | I915_WRITE(PCH_PP_CONTROL, pp); | 798 | I915_WRITE(PCH_PP_CONTROL, pp); |
818 | do { | ||
819 | pp_status = I915_READ(PCH_PP_STATUS); | ||
820 | } while ((pp_status & PP_ON) && !time_after(jiffies, timeout)); | ||
821 | 799 | ||
822 | if (time_after(jiffies, timeout)) | 800 | if (wait_for((I915_READ(PCH_PP_STATUS) & PP_ON) == 0, 5000, 10)) |
823 | DRM_DEBUG_KMS("panel off wait timed out\n"); | 801 | DRM_ERROR("panel off wait timed out: 0x%08x\n", |
802 | I915_READ(PCH_PP_STATUS)); | ||
824 | 803 | ||
825 | /* Make sure VDD is enabled so DP AUX will work */ | 804 | /* Make sure VDD is enabled so DP AUX will work */ |
826 | pp |= EDP_FORCE_VDD; | 805 | pp |= EDP_FORCE_VDD | PANEL_POWER_RESET; /* restore panel reset bit */ |
827 | I915_WRITE(PCH_PP_CONTROL, pp); | 806 | I915_WRITE(PCH_PP_CONTROL, pp); |
807 | POSTING_READ(PCH_PP_CONTROL); | ||
828 | } | 808 | } |
829 | 809 | ||
830 | static void ironlake_edp_backlight_on (struct drm_device *dev) | 810 | static void ironlake_edp_backlight_on (struct drm_device *dev) |
@@ -849,33 +829,87 @@ static void ironlake_edp_backlight_off (struct drm_device *dev) | |||
849 | I915_WRITE(PCH_PP_CONTROL, pp); | 829 | I915_WRITE(PCH_PP_CONTROL, pp); |
850 | } | 830 | } |
851 | 831 | ||
832 | static void ironlake_edp_pll_on(struct drm_encoder *encoder) | ||
833 | { | ||
834 | struct drm_device *dev = encoder->dev; | ||
835 | struct drm_i915_private *dev_priv = dev->dev_private; | ||
836 | u32 dpa_ctl; | ||
837 | |||
838 | DRM_DEBUG_KMS("\n"); | ||
839 | dpa_ctl = I915_READ(DP_A); | ||
840 | dpa_ctl &= ~DP_PLL_ENABLE; | ||
841 | I915_WRITE(DP_A, dpa_ctl); | ||
842 | } | ||
843 | |||
844 | static void ironlake_edp_pll_off(struct drm_encoder *encoder) | ||
845 | { | ||
846 | struct drm_device *dev = encoder->dev; | ||
847 | struct drm_i915_private *dev_priv = dev->dev_private; | ||
848 | u32 dpa_ctl; | ||
849 | |||
850 | dpa_ctl = I915_READ(DP_A); | ||
851 | dpa_ctl |= DP_PLL_ENABLE; | ||
852 | I915_WRITE(DP_A, dpa_ctl); | ||
853 | udelay(200); | ||
854 | } | ||
855 | |||
856 | static void intel_dp_prepare(struct drm_encoder *encoder) | ||
857 | { | ||
858 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); | ||
859 | struct drm_device *dev = encoder->dev; | ||
860 | struct drm_i915_private *dev_priv = dev->dev_private; | ||
861 | uint32_t dp_reg = I915_READ(intel_dp->output_reg); | ||
862 | |||
863 | if (IS_eDP(intel_dp)) { | ||
864 | ironlake_edp_backlight_off(dev); | ||
865 | ironlake_edp_panel_on(dev); | ||
866 | ironlake_edp_pll_on(encoder); | ||
867 | } | ||
868 | if (dp_reg & DP_PORT_EN) | ||
869 | intel_dp_link_down(intel_dp); | ||
870 | } | ||
871 | |||
872 | static void intel_dp_commit(struct drm_encoder *encoder) | ||
873 | { | ||
874 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); | ||
875 | struct drm_device *dev = encoder->dev; | ||
876 | struct drm_i915_private *dev_priv = dev->dev_private; | ||
877 | uint32_t dp_reg = I915_READ(intel_dp->output_reg); | ||
878 | |||
879 | if (!(dp_reg & DP_PORT_EN)) { | ||
880 | intel_dp_link_train(intel_dp); | ||
881 | } | ||
882 | if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) | ||
883 | ironlake_edp_backlight_on(dev); | ||
884 | } | ||
885 | |||
852 | static void | 886 | static void |
853 | intel_dp_dpms(struct drm_encoder *encoder, int mode) | 887 | intel_dp_dpms(struct drm_encoder *encoder, int mode) |
854 | { | 888 | { |
855 | struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); | 889 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
856 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | ||
857 | struct drm_device *dev = encoder->dev; | 890 | struct drm_device *dev = encoder->dev; |
858 | struct drm_i915_private *dev_priv = dev->dev_private; | 891 | struct drm_i915_private *dev_priv = dev->dev_private; |
859 | uint32_t dp_reg = I915_READ(dp_priv->output_reg); | 892 | uint32_t dp_reg = I915_READ(intel_dp->output_reg); |
860 | 893 | ||
861 | if (mode != DRM_MODE_DPMS_ON) { | 894 | if (mode != DRM_MODE_DPMS_ON) { |
862 | if (dp_reg & DP_PORT_EN) { | 895 | if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) { |
863 | intel_dp_link_down(intel_encoder, dp_priv->DP); | 896 | ironlake_edp_backlight_off(dev); |
864 | if (IS_eDP(intel_encoder) || IS_PCH_eDP(dp_priv)) { | 897 | ironlake_edp_panel_off(dev); |
865 | ironlake_edp_backlight_off(dev); | ||
866 | ironlake_edp_panel_off(dev); | ||
867 | } | ||
868 | } | 898 | } |
899 | if (dp_reg & DP_PORT_EN) | ||
900 | intel_dp_link_down(intel_dp); | ||
901 | if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) | ||
902 | ironlake_edp_pll_off(encoder); | ||
869 | } else { | 903 | } else { |
870 | if (!(dp_reg & DP_PORT_EN)) { | 904 | if (!(dp_reg & DP_PORT_EN)) { |
871 | intel_dp_link_train(intel_encoder, dp_priv->DP, dp_priv->link_configuration); | 905 | if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) |
872 | if (IS_eDP(intel_encoder) || IS_PCH_eDP(dp_priv)) { | ||
873 | ironlake_edp_panel_on(dev); | 906 | ironlake_edp_panel_on(dev); |
907 | intel_dp_link_train(intel_dp); | ||
908 | if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) | ||
874 | ironlake_edp_backlight_on(dev); | 909 | ironlake_edp_backlight_on(dev); |
875 | } | ||
876 | } | 910 | } |
877 | } | 911 | } |
878 | dp_priv->dpms_mode = mode; | 912 | intel_dp->dpms_mode = mode; |
879 | } | 913 | } |
880 | 914 | ||
881 | /* | 915 | /* |
@@ -883,12 +917,12 @@ intel_dp_dpms(struct drm_encoder *encoder, int mode) | |||
883 | * link status information | 917 | * link status information |
884 | */ | 918 | */ |
885 | static bool | 919 | static bool |
886 | intel_dp_get_link_status(struct intel_encoder *intel_encoder, | 920 | intel_dp_get_link_status(struct intel_dp *intel_dp, |
887 | uint8_t link_status[DP_LINK_STATUS_SIZE]) | 921 | uint8_t link_status[DP_LINK_STATUS_SIZE]) |
888 | { | 922 | { |
889 | int ret; | 923 | int ret; |
890 | 924 | ||
891 | ret = intel_dp_aux_native_read(intel_encoder, | 925 | ret = intel_dp_aux_native_read(intel_dp, |
892 | DP_LANE0_1_STATUS, | 926 | DP_LANE0_1_STATUS, |
893 | link_status, DP_LINK_STATUS_SIZE); | 927 | link_status, DP_LINK_STATUS_SIZE); |
894 | if (ret != DP_LINK_STATUS_SIZE) | 928 | if (ret != DP_LINK_STATUS_SIZE) |
@@ -965,7 +999,7 @@ intel_dp_pre_emphasis_max(uint8_t voltage_swing) | |||
965 | } | 999 | } |
966 | 1000 | ||
967 | static void | 1001 | static void |
968 | intel_get_adjust_train(struct intel_encoder *intel_encoder, | 1002 | intel_get_adjust_train(struct intel_dp *intel_dp, |
969 | uint8_t link_status[DP_LINK_STATUS_SIZE], | 1003 | uint8_t link_status[DP_LINK_STATUS_SIZE], |
970 | int lane_count, | 1004 | int lane_count, |
971 | uint8_t train_set[4]) | 1005 | uint8_t train_set[4]) |
@@ -1101,27 +1135,23 @@ intel_channel_eq_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count) | |||
1101 | } | 1135 | } |
1102 | 1136 | ||
1103 | static bool | 1137 | static bool |
1104 | intel_dp_set_link_train(struct intel_encoder *intel_encoder, | 1138 | intel_dp_set_link_train(struct intel_dp *intel_dp, |
1105 | uint32_t dp_reg_value, | 1139 | uint32_t dp_reg_value, |
1106 | uint8_t dp_train_pat, | 1140 | uint8_t dp_train_pat, |
1107 | uint8_t train_set[4], | 1141 | uint8_t train_set[4]) |
1108 | bool first) | ||
1109 | { | 1142 | { |
1110 | struct drm_device *dev = intel_encoder->enc.dev; | 1143 | struct drm_device *dev = intel_dp->base.enc.dev; |
1111 | struct drm_i915_private *dev_priv = dev->dev_private; | 1144 | struct drm_i915_private *dev_priv = dev->dev_private; |
1112 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | ||
1113 | int ret; | 1145 | int ret; |
1114 | 1146 | ||
1115 | I915_WRITE(dp_priv->output_reg, dp_reg_value); | 1147 | I915_WRITE(intel_dp->output_reg, dp_reg_value); |
1116 | POSTING_READ(dp_priv->output_reg); | 1148 | POSTING_READ(intel_dp->output_reg); |
1117 | if (first) | ||
1118 | intel_wait_for_vblank(dev); | ||
1119 | 1149 | ||
1120 | intel_dp_aux_native_write_1(intel_encoder, | 1150 | intel_dp_aux_native_write_1(intel_dp, |
1121 | DP_TRAINING_PATTERN_SET, | 1151 | DP_TRAINING_PATTERN_SET, |
1122 | dp_train_pat); | 1152 | dp_train_pat); |
1123 | 1153 | ||
1124 | ret = intel_dp_aux_native_write(intel_encoder, | 1154 | ret = intel_dp_aux_native_write(intel_dp, |
1125 | DP_TRAINING_LANE0_SET, train_set, 4); | 1155 | DP_TRAINING_LANE0_SET, train_set, 4); |
1126 | if (ret != 4) | 1156 | if (ret != 4) |
1127 | return false; | 1157 | return false; |
@@ -1130,28 +1160,33 @@ intel_dp_set_link_train(struct intel_encoder *intel_encoder, | |||
1130 | } | 1160 | } |
1131 | 1161 | ||
1132 | static void | 1162 | static void |
1133 | intel_dp_link_train(struct intel_encoder *intel_encoder, uint32_t DP, | 1163 | intel_dp_link_train(struct intel_dp *intel_dp) |
1134 | uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE]) | ||
1135 | { | 1164 | { |
1136 | struct drm_device *dev = intel_encoder->enc.dev; | 1165 | struct drm_device *dev = intel_dp->base.enc.dev; |
1137 | struct drm_i915_private *dev_priv = dev->dev_private; | 1166 | struct drm_i915_private *dev_priv = dev->dev_private; |
1138 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | ||
1139 | uint8_t train_set[4]; | 1167 | uint8_t train_set[4]; |
1140 | uint8_t link_status[DP_LINK_STATUS_SIZE]; | 1168 | uint8_t link_status[DP_LINK_STATUS_SIZE]; |
1141 | int i; | 1169 | int i; |
1142 | uint8_t voltage; | 1170 | uint8_t voltage; |
1143 | bool clock_recovery = false; | 1171 | bool clock_recovery = false; |
1144 | bool channel_eq = false; | 1172 | bool channel_eq = false; |
1145 | bool first = true; | ||
1146 | int tries; | 1173 | int tries; |
1147 | u32 reg; | 1174 | u32 reg; |
1175 | uint32_t DP = intel_dp->DP; | ||
1176 | struct intel_crtc *intel_crtc = to_intel_crtc(intel_dp->base.enc.crtc); | ||
1177 | |||
1178 | /* Enable output, wait for it to become active */ | ||
1179 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); | ||
1180 | POSTING_READ(intel_dp->output_reg); | ||
1181 | intel_wait_for_vblank(dev, intel_crtc->pipe); | ||
1148 | 1182 | ||
1149 | /* Write the link configuration data */ | 1183 | /* Write the link configuration data */ |
1150 | intel_dp_aux_native_write(intel_encoder, DP_LINK_BW_SET, | 1184 | intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET, |
1151 | link_configuration, DP_LINK_CONFIGURATION_SIZE); | 1185 | intel_dp->link_configuration, |
1186 | DP_LINK_CONFIGURATION_SIZE); | ||
1152 | 1187 | ||
1153 | DP |= DP_PORT_EN; | 1188 | DP |= DP_PORT_EN; |
1154 | if (HAS_PCH_CPT(dev) && !IS_eDP(intel_encoder)) | 1189 | if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp)) |
1155 | DP &= ~DP_LINK_TRAIN_MASK_CPT; | 1190 | DP &= ~DP_LINK_TRAIN_MASK_CPT; |
1156 | else | 1191 | else |
1157 | DP &= ~DP_LINK_TRAIN_MASK; | 1192 | DP &= ~DP_LINK_TRAIN_MASK; |
@@ -1162,39 +1197,38 @@ intel_dp_link_train(struct intel_encoder *intel_encoder, uint32_t DP, | |||
1162 | for (;;) { | 1197 | for (;;) { |
1163 | /* Use train_set[0] to set the voltage and pre emphasis values */ | 1198 | /* Use train_set[0] to set the voltage and pre emphasis values */ |
1164 | uint32_t signal_levels; | 1199 | uint32_t signal_levels; |
1165 | if (IS_GEN6(dev) && IS_eDP(intel_encoder)) { | 1200 | if (IS_GEN6(dev) && IS_eDP(intel_dp)) { |
1166 | signal_levels = intel_gen6_edp_signal_levels(train_set[0]); | 1201 | signal_levels = intel_gen6_edp_signal_levels(train_set[0]); |
1167 | DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels; | 1202 | DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels; |
1168 | } else { | 1203 | } else { |
1169 | signal_levels = intel_dp_signal_levels(train_set[0], dp_priv->lane_count); | 1204 | signal_levels = intel_dp_signal_levels(train_set[0], intel_dp->lane_count); |
1170 | DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; | 1205 | DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; |
1171 | } | 1206 | } |
1172 | 1207 | ||
1173 | if (HAS_PCH_CPT(dev) && !IS_eDP(intel_encoder)) | 1208 | if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp)) |
1174 | reg = DP | DP_LINK_TRAIN_PAT_1_CPT; | 1209 | reg = DP | DP_LINK_TRAIN_PAT_1_CPT; |
1175 | else | 1210 | else |
1176 | reg = DP | DP_LINK_TRAIN_PAT_1; | 1211 | reg = DP | DP_LINK_TRAIN_PAT_1; |
1177 | 1212 | ||
1178 | if (!intel_dp_set_link_train(intel_encoder, reg, | 1213 | if (!intel_dp_set_link_train(intel_dp, reg, |
1179 | DP_TRAINING_PATTERN_1, train_set, first)) | 1214 | DP_TRAINING_PATTERN_1, train_set)) |
1180 | break; | 1215 | break; |
1181 | first = false; | ||
1182 | /* Set training pattern 1 */ | 1216 | /* Set training pattern 1 */ |
1183 | 1217 | ||
1184 | udelay(100); | 1218 | udelay(100); |
1185 | if (!intel_dp_get_link_status(intel_encoder, link_status)) | 1219 | if (!intel_dp_get_link_status(intel_dp, link_status)) |
1186 | break; | 1220 | break; |
1187 | 1221 | ||
1188 | if (intel_clock_recovery_ok(link_status, dp_priv->lane_count)) { | 1222 | if (intel_clock_recovery_ok(link_status, intel_dp->lane_count)) { |
1189 | clock_recovery = true; | 1223 | clock_recovery = true; |
1190 | break; | 1224 | break; |
1191 | } | 1225 | } |
1192 | 1226 | ||
1193 | /* Check to see if we've tried the max voltage */ | 1227 | /* Check to see if we've tried the max voltage */ |
1194 | for (i = 0; i < dp_priv->lane_count; i++) | 1228 | for (i = 0; i < intel_dp->lane_count; i++) |
1195 | if ((train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0) | 1229 | if ((train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0) |
1196 | break; | 1230 | break; |
1197 | if (i == dp_priv->lane_count) | 1231 | if (i == intel_dp->lane_count) |
1198 | break; | 1232 | break; |
1199 | 1233 | ||
1200 | /* Check to see if we've tried the same voltage 5 times */ | 1234 | /* Check to see if we've tried the same voltage 5 times */ |
@@ -1207,7 +1241,7 @@ intel_dp_link_train(struct intel_encoder *intel_encoder, uint32_t DP, | |||
1207 | voltage = train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK; | 1241 | voltage = train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK; |
1208 | 1242 | ||
1209 | /* Compute new train_set as requested by target */ | 1243 | /* Compute new train_set as requested by target */ |
1210 | intel_get_adjust_train(intel_encoder, link_status, dp_priv->lane_count, train_set); | 1244 | intel_get_adjust_train(intel_dp, link_status, intel_dp->lane_count, train_set); |
1211 | } | 1245 | } |
1212 | 1246 | ||
1213 | /* channel equalization */ | 1247 | /* channel equalization */ |
@@ -1217,30 +1251,29 @@ intel_dp_link_train(struct intel_encoder *intel_encoder, uint32_t DP, | |||
1217 | /* Use train_set[0] to set the voltage and pre emphasis values */ | 1251 | /* Use train_set[0] to set the voltage and pre emphasis values */ |
1218 | uint32_t signal_levels; | 1252 | uint32_t signal_levels; |
1219 | 1253 | ||
1220 | if (IS_GEN6(dev) && IS_eDP(intel_encoder)) { | 1254 | if (IS_GEN6(dev) && IS_eDP(intel_dp)) { |
1221 | signal_levels = intel_gen6_edp_signal_levels(train_set[0]); | 1255 | signal_levels = intel_gen6_edp_signal_levels(train_set[0]); |
1222 | DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels; | 1256 | DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels; |
1223 | } else { | 1257 | } else { |
1224 | signal_levels = intel_dp_signal_levels(train_set[0], dp_priv->lane_count); | 1258 | signal_levels = intel_dp_signal_levels(train_set[0], intel_dp->lane_count); |
1225 | DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; | 1259 | DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; |
1226 | } | 1260 | } |
1227 | 1261 | ||
1228 | if (HAS_PCH_CPT(dev) && !IS_eDP(intel_encoder)) | 1262 | if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp)) |
1229 | reg = DP | DP_LINK_TRAIN_PAT_2_CPT; | 1263 | reg = DP | DP_LINK_TRAIN_PAT_2_CPT; |
1230 | else | 1264 | else |
1231 | reg = DP | DP_LINK_TRAIN_PAT_2; | 1265 | reg = DP | DP_LINK_TRAIN_PAT_2; |
1232 | 1266 | ||
1233 | /* channel eq pattern */ | 1267 | /* channel eq pattern */ |
1234 | if (!intel_dp_set_link_train(intel_encoder, reg, | 1268 | if (!intel_dp_set_link_train(intel_dp, reg, |
1235 | DP_TRAINING_PATTERN_2, train_set, | 1269 | DP_TRAINING_PATTERN_2, train_set)) |
1236 | false)) | ||
1237 | break; | 1270 | break; |
1238 | 1271 | ||
1239 | udelay(400); | 1272 | udelay(400); |
1240 | if (!intel_dp_get_link_status(intel_encoder, link_status)) | 1273 | if (!intel_dp_get_link_status(intel_dp, link_status)) |
1241 | break; | 1274 | break; |
1242 | 1275 | ||
1243 | if (intel_channel_eq_ok(link_status, dp_priv->lane_count)) { | 1276 | if (intel_channel_eq_ok(link_status, intel_dp->lane_count)) { |
1244 | channel_eq = true; | 1277 | channel_eq = true; |
1245 | break; | 1278 | break; |
1246 | } | 1279 | } |
@@ -1250,53 +1283,53 @@ intel_dp_link_train(struct intel_encoder *intel_encoder, uint32_t DP, | |||
1250 | break; | 1283 | break; |
1251 | 1284 | ||
1252 | /* Compute new train_set as requested by target */ | 1285 | /* Compute new train_set as requested by target */ |
1253 | intel_get_adjust_train(intel_encoder, link_status, dp_priv->lane_count, train_set); | 1286 | intel_get_adjust_train(intel_dp, link_status, intel_dp->lane_count, train_set); |
1254 | ++tries; | 1287 | ++tries; |
1255 | } | 1288 | } |
1256 | 1289 | ||
1257 | if (HAS_PCH_CPT(dev) && !IS_eDP(intel_encoder)) | 1290 | if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp)) |
1258 | reg = DP | DP_LINK_TRAIN_OFF_CPT; | 1291 | reg = DP | DP_LINK_TRAIN_OFF_CPT; |
1259 | else | 1292 | else |
1260 | reg = DP | DP_LINK_TRAIN_OFF; | 1293 | reg = DP | DP_LINK_TRAIN_OFF; |
1261 | 1294 | ||
1262 | I915_WRITE(dp_priv->output_reg, reg); | 1295 | I915_WRITE(intel_dp->output_reg, reg); |
1263 | POSTING_READ(dp_priv->output_reg); | 1296 | POSTING_READ(intel_dp->output_reg); |
1264 | intel_dp_aux_native_write_1(intel_encoder, | 1297 | intel_dp_aux_native_write_1(intel_dp, |
1265 | DP_TRAINING_PATTERN_SET, DP_TRAINING_PATTERN_DISABLE); | 1298 | DP_TRAINING_PATTERN_SET, DP_TRAINING_PATTERN_DISABLE); |
1266 | } | 1299 | } |
1267 | 1300 | ||
1268 | static void | 1301 | static void |
1269 | intel_dp_link_down(struct intel_encoder *intel_encoder, uint32_t DP) | 1302 | intel_dp_link_down(struct intel_dp *intel_dp) |
1270 | { | 1303 | { |
1271 | struct drm_device *dev = intel_encoder->enc.dev; | 1304 | struct drm_device *dev = intel_dp->base.enc.dev; |
1272 | struct drm_i915_private *dev_priv = dev->dev_private; | 1305 | struct drm_i915_private *dev_priv = dev->dev_private; |
1273 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | 1306 | uint32_t DP = intel_dp->DP; |
1274 | 1307 | ||
1275 | DRM_DEBUG_KMS("\n"); | 1308 | DRM_DEBUG_KMS("\n"); |
1276 | 1309 | ||
1277 | if (IS_eDP(intel_encoder)) { | 1310 | if (IS_eDP(intel_dp)) { |
1278 | DP &= ~DP_PLL_ENABLE; | 1311 | DP &= ~DP_PLL_ENABLE; |
1279 | I915_WRITE(dp_priv->output_reg, DP); | 1312 | I915_WRITE(intel_dp->output_reg, DP); |
1280 | POSTING_READ(dp_priv->output_reg); | 1313 | POSTING_READ(intel_dp->output_reg); |
1281 | udelay(100); | 1314 | udelay(100); |
1282 | } | 1315 | } |
1283 | 1316 | ||
1284 | if (HAS_PCH_CPT(dev) && !IS_eDP(intel_encoder)) { | 1317 | if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp)) { |
1285 | DP &= ~DP_LINK_TRAIN_MASK_CPT; | 1318 | DP &= ~DP_LINK_TRAIN_MASK_CPT; |
1286 | I915_WRITE(dp_priv->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT); | 1319 | I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT); |
1287 | POSTING_READ(dp_priv->output_reg); | 1320 | POSTING_READ(intel_dp->output_reg); |
1288 | } else { | 1321 | } else { |
1289 | DP &= ~DP_LINK_TRAIN_MASK; | 1322 | DP &= ~DP_LINK_TRAIN_MASK; |
1290 | I915_WRITE(dp_priv->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE); | 1323 | I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE); |
1291 | POSTING_READ(dp_priv->output_reg); | 1324 | POSTING_READ(intel_dp->output_reg); |
1292 | } | 1325 | } |
1293 | 1326 | ||
1294 | udelay(17000); | 1327 | udelay(17000); |
1295 | 1328 | ||
1296 | if (IS_eDP(intel_encoder)) | 1329 | if (IS_eDP(intel_dp)) |
1297 | DP |= DP_LINK_TRAIN_OFF; | 1330 | DP |= DP_LINK_TRAIN_OFF; |
1298 | I915_WRITE(dp_priv->output_reg, DP & ~DP_PORT_EN); | 1331 | I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN); |
1299 | POSTING_READ(dp_priv->output_reg); | 1332 | POSTING_READ(intel_dp->output_reg); |
1300 | } | 1333 | } |
1301 | 1334 | ||
1302 | /* | 1335 | /* |
@@ -1309,41 +1342,39 @@ intel_dp_link_down(struct intel_encoder *intel_encoder, uint32_t DP) | |||
1309 | */ | 1342 | */ |
1310 | 1343 | ||
1311 | static void | 1344 | static void |
1312 | intel_dp_check_link_status(struct intel_encoder *intel_encoder) | 1345 | intel_dp_check_link_status(struct intel_dp *intel_dp) |
1313 | { | 1346 | { |
1314 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | ||
1315 | uint8_t link_status[DP_LINK_STATUS_SIZE]; | 1347 | uint8_t link_status[DP_LINK_STATUS_SIZE]; |
1316 | 1348 | ||
1317 | if (!intel_encoder->enc.crtc) | 1349 | if (!intel_dp->base.enc.crtc) |
1318 | return; | 1350 | return; |
1319 | 1351 | ||
1320 | if (!intel_dp_get_link_status(intel_encoder, link_status)) { | 1352 | if (!intel_dp_get_link_status(intel_dp, link_status)) { |
1321 | intel_dp_link_down(intel_encoder, dp_priv->DP); | 1353 | intel_dp_link_down(intel_dp); |
1322 | return; | 1354 | return; |
1323 | } | 1355 | } |
1324 | 1356 | ||
1325 | if (!intel_channel_eq_ok(link_status, dp_priv->lane_count)) | 1357 | if (!intel_channel_eq_ok(link_status, intel_dp->lane_count)) |
1326 | intel_dp_link_train(intel_encoder, dp_priv->DP, dp_priv->link_configuration); | 1358 | intel_dp_link_train(intel_dp); |
1327 | } | 1359 | } |
1328 | 1360 | ||
1329 | static enum drm_connector_status | 1361 | static enum drm_connector_status |
1330 | ironlake_dp_detect(struct drm_connector *connector) | 1362 | ironlake_dp_detect(struct drm_connector *connector) |
1331 | { | 1363 | { |
1332 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1364 | struct drm_encoder *encoder = intel_attached_encoder(connector); |
1333 | struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); | 1365 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
1334 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | ||
1335 | enum drm_connector_status status; | 1366 | enum drm_connector_status status; |
1336 | 1367 | ||
1337 | status = connector_status_disconnected; | 1368 | status = connector_status_disconnected; |
1338 | if (intel_dp_aux_native_read(intel_encoder, | 1369 | if (intel_dp_aux_native_read(intel_dp, |
1339 | 0x000, dp_priv->dpcd, | 1370 | 0x000, intel_dp->dpcd, |
1340 | sizeof (dp_priv->dpcd)) == sizeof (dp_priv->dpcd)) | 1371 | sizeof (intel_dp->dpcd)) == sizeof (intel_dp->dpcd)) |
1341 | { | 1372 | { |
1342 | if (dp_priv->dpcd[0] != 0) | 1373 | if (intel_dp->dpcd[0] != 0) |
1343 | status = connector_status_connected; | 1374 | status = connector_status_connected; |
1344 | } | 1375 | } |
1345 | DRM_DEBUG_KMS("DPCD: %hx%hx%hx%hx\n", dp_priv->dpcd[0], | 1376 | DRM_DEBUG_KMS("DPCD: %hx%hx%hx%hx\n", intel_dp->dpcd[0], |
1346 | dp_priv->dpcd[1], dp_priv->dpcd[2], dp_priv->dpcd[3]); | 1377 | intel_dp->dpcd[1], intel_dp->dpcd[2], intel_dp->dpcd[3]); |
1347 | return status; | 1378 | return status; |
1348 | } | 1379 | } |
1349 | 1380 | ||
@@ -1354,22 +1385,21 @@ ironlake_dp_detect(struct drm_connector *connector) | |||
1354 | * \return false if DP port is disconnected. | 1385 | * \return false if DP port is disconnected. |
1355 | */ | 1386 | */ |
1356 | static enum drm_connector_status | 1387 | static enum drm_connector_status |
1357 | intel_dp_detect(struct drm_connector *connector) | 1388 | intel_dp_detect(struct drm_connector *connector, bool force) |
1358 | { | 1389 | { |
1359 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1390 | struct drm_encoder *encoder = intel_attached_encoder(connector); |
1360 | struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); | 1391 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
1361 | struct drm_device *dev = intel_encoder->enc.dev; | 1392 | struct drm_device *dev = intel_dp->base.enc.dev; |
1362 | struct drm_i915_private *dev_priv = dev->dev_private; | 1393 | struct drm_i915_private *dev_priv = dev->dev_private; |
1363 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | ||
1364 | uint32_t temp, bit; | 1394 | uint32_t temp, bit; |
1365 | enum drm_connector_status status; | 1395 | enum drm_connector_status status; |
1366 | 1396 | ||
1367 | dp_priv->has_audio = false; | 1397 | intel_dp->has_audio = false; |
1368 | 1398 | ||
1369 | if (HAS_PCH_SPLIT(dev)) | 1399 | if (HAS_PCH_SPLIT(dev)) |
1370 | return ironlake_dp_detect(connector); | 1400 | return ironlake_dp_detect(connector); |
1371 | 1401 | ||
1372 | switch (dp_priv->output_reg) { | 1402 | switch (intel_dp->output_reg) { |
1373 | case DP_B: | 1403 | case DP_B: |
1374 | bit = DPB_HOTPLUG_INT_STATUS; | 1404 | bit = DPB_HOTPLUG_INT_STATUS; |
1375 | break; | 1405 | break; |
@@ -1389,11 +1419,11 @@ intel_dp_detect(struct drm_connector *connector) | |||
1389 | return connector_status_disconnected; | 1419 | return connector_status_disconnected; |
1390 | 1420 | ||
1391 | status = connector_status_disconnected; | 1421 | status = connector_status_disconnected; |
1392 | if (intel_dp_aux_native_read(intel_encoder, | 1422 | if (intel_dp_aux_native_read(intel_dp, |
1393 | 0x000, dp_priv->dpcd, | 1423 | 0x000, intel_dp->dpcd, |
1394 | sizeof (dp_priv->dpcd)) == sizeof (dp_priv->dpcd)) | 1424 | sizeof (intel_dp->dpcd)) == sizeof (intel_dp->dpcd)) |
1395 | { | 1425 | { |
1396 | if (dp_priv->dpcd[0] != 0) | 1426 | if (intel_dp->dpcd[0] != 0) |
1397 | status = connector_status_connected; | 1427 | status = connector_status_connected; |
1398 | } | 1428 | } |
1399 | return status; | 1429 | return status; |
@@ -1402,18 +1432,17 @@ intel_dp_detect(struct drm_connector *connector) | |||
1402 | static int intel_dp_get_modes(struct drm_connector *connector) | 1432 | static int intel_dp_get_modes(struct drm_connector *connector) |
1403 | { | 1433 | { |
1404 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1434 | struct drm_encoder *encoder = intel_attached_encoder(connector); |
1405 | struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); | 1435 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
1406 | struct drm_device *dev = intel_encoder->enc.dev; | 1436 | struct drm_device *dev = intel_dp->base.enc.dev; |
1407 | struct drm_i915_private *dev_priv = dev->dev_private; | 1437 | struct drm_i915_private *dev_priv = dev->dev_private; |
1408 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | ||
1409 | int ret; | 1438 | int ret; |
1410 | 1439 | ||
1411 | /* We should parse the EDID data and find out if it has an audio sink | 1440 | /* We should parse the EDID data and find out if it has an audio sink |
1412 | */ | 1441 | */ |
1413 | 1442 | ||
1414 | ret = intel_ddc_get_modes(connector, intel_encoder->ddc_bus); | 1443 | ret = intel_ddc_get_modes(connector, intel_dp->base.ddc_bus); |
1415 | if (ret) { | 1444 | if (ret) { |
1416 | if ((IS_eDP(intel_encoder) || IS_PCH_eDP(dp_priv)) && | 1445 | if ((IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) && |
1417 | !dev_priv->panel_fixed_mode) { | 1446 | !dev_priv->panel_fixed_mode) { |
1418 | struct drm_display_mode *newmode; | 1447 | struct drm_display_mode *newmode; |
1419 | list_for_each_entry(newmode, &connector->probed_modes, | 1448 | list_for_each_entry(newmode, &connector->probed_modes, |
@@ -1430,7 +1459,7 @@ static int intel_dp_get_modes(struct drm_connector *connector) | |||
1430 | } | 1459 | } |
1431 | 1460 | ||
1432 | /* if eDP has no EDID, try to use fixed panel mode from VBT */ | 1461 | /* if eDP has no EDID, try to use fixed panel mode from VBT */ |
1433 | if (IS_eDP(intel_encoder) || IS_PCH_eDP(dp_priv)) { | 1462 | if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) { |
1434 | if (dev_priv->panel_fixed_mode != NULL) { | 1463 | if (dev_priv->panel_fixed_mode != NULL) { |
1435 | struct drm_display_mode *mode; | 1464 | struct drm_display_mode *mode; |
1436 | mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode); | 1465 | mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode); |
@@ -1452,9 +1481,9 @@ intel_dp_destroy (struct drm_connector *connector) | |||
1452 | static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = { | 1481 | static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = { |
1453 | .dpms = intel_dp_dpms, | 1482 | .dpms = intel_dp_dpms, |
1454 | .mode_fixup = intel_dp_mode_fixup, | 1483 | .mode_fixup = intel_dp_mode_fixup, |
1455 | .prepare = intel_encoder_prepare, | 1484 | .prepare = intel_dp_prepare, |
1456 | .mode_set = intel_dp_mode_set, | 1485 | .mode_set = intel_dp_mode_set, |
1457 | .commit = intel_encoder_commit, | 1486 | .commit = intel_dp_commit, |
1458 | }; | 1487 | }; |
1459 | 1488 | ||
1460 | static const struct drm_connector_funcs intel_dp_connector_funcs = { | 1489 | static const struct drm_connector_funcs intel_dp_connector_funcs = { |
@@ -1470,27 +1499,17 @@ static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = | |||
1470 | .best_encoder = intel_attached_encoder, | 1499 | .best_encoder = intel_attached_encoder, |
1471 | }; | 1500 | }; |
1472 | 1501 | ||
1473 | static void intel_dp_enc_destroy(struct drm_encoder *encoder) | ||
1474 | { | ||
1475 | struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); | ||
1476 | |||
1477 | if (intel_encoder->i2c_bus) | ||
1478 | intel_i2c_destroy(intel_encoder->i2c_bus); | ||
1479 | drm_encoder_cleanup(encoder); | ||
1480 | kfree(intel_encoder); | ||
1481 | } | ||
1482 | |||
1483 | static const struct drm_encoder_funcs intel_dp_enc_funcs = { | 1502 | static const struct drm_encoder_funcs intel_dp_enc_funcs = { |
1484 | .destroy = intel_dp_enc_destroy, | 1503 | .destroy = intel_encoder_destroy, |
1485 | }; | 1504 | }; |
1486 | 1505 | ||
1487 | void | 1506 | void |
1488 | intel_dp_hot_plug(struct intel_encoder *intel_encoder) | 1507 | intel_dp_hot_plug(struct intel_encoder *intel_encoder) |
1489 | { | 1508 | { |
1490 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | 1509 | struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base); |
1491 | 1510 | ||
1492 | if (dp_priv->dpms_mode == DRM_MODE_DPMS_ON) | 1511 | if (intel_dp->dpms_mode == DRM_MODE_DPMS_ON) |
1493 | intel_dp_check_link_status(intel_encoder); | 1512 | intel_dp_check_link_status(intel_dp); |
1494 | } | 1513 | } |
1495 | 1514 | ||
1496 | /* Return which DP Port should be selected for Transcoder DP control */ | 1515 | /* Return which DP Port should be selected for Transcoder DP control */ |
@@ -1500,18 +1519,18 @@ intel_trans_dp_port_sel (struct drm_crtc *crtc) | |||
1500 | struct drm_device *dev = crtc->dev; | 1519 | struct drm_device *dev = crtc->dev; |
1501 | struct drm_mode_config *mode_config = &dev->mode_config; | 1520 | struct drm_mode_config *mode_config = &dev->mode_config; |
1502 | struct drm_encoder *encoder; | 1521 | struct drm_encoder *encoder; |
1503 | struct intel_encoder *intel_encoder = NULL; | ||
1504 | 1522 | ||
1505 | list_for_each_entry(encoder, &mode_config->encoder_list, head) { | 1523 | list_for_each_entry(encoder, &mode_config->encoder_list, head) { |
1524 | struct intel_dp *intel_dp; | ||
1525 | |||
1506 | if (encoder->crtc != crtc) | 1526 | if (encoder->crtc != crtc) |
1507 | continue; | 1527 | continue; |
1508 | 1528 | ||
1509 | intel_encoder = enc_to_intel_encoder(encoder); | 1529 | intel_dp = enc_to_intel_dp(encoder); |
1510 | if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT) { | 1530 | if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT) |
1511 | struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; | 1531 | return intel_dp->output_reg; |
1512 | return dp_priv->output_reg; | ||
1513 | } | ||
1514 | } | 1532 | } |
1533 | |||
1515 | return -1; | 1534 | return -1; |
1516 | } | 1535 | } |
1517 | 1536 | ||
@@ -1540,30 +1559,28 @@ intel_dp_init(struct drm_device *dev, int output_reg) | |||
1540 | { | 1559 | { |
1541 | struct drm_i915_private *dev_priv = dev->dev_private; | 1560 | struct drm_i915_private *dev_priv = dev->dev_private; |
1542 | struct drm_connector *connector; | 1561 | struct drm_connector *connector; |
1562 | struct intel_dp *intel_dp; | ||
1543 | struct intel_encoder *intel_encoder; | 1563 | struct intel_encoder *intel_encoder; |
1544 | struct intel_connector *intel_connector; | 1564 | struct intel_connector *intel_connector; |
1545 | struct intel_dp_priv *dp_priv; | ||
1546 | const char *name = NULL; | 1565 | const char *name = NULL; |
1547 | int type; | 1566 | int type; |
1548 | 1567 | ||
1549 | intel_encoder = kcalloc(sizeof(struct intel_encoder) + | 1568 | intel_dp = kzalloc(sizeof(struct intel_dp), GFP_KERNEL); |
1550 | sizeof(struct intel_dp_priv), 1, GFP_KERNEL); | 1569 | if (!intel_dp) |
1551 | if (!intel_encoder) | ||
1552 | return; | 1570 | return; |
1553 | 1571 | ||
1554 | intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); | 1572 | intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); |
1555 | if (!intel_connector) { | 1573 | if (!intel_connector) { |
1556 | kfree(intel_encoder); | 1574 | kfree(intel_dp); |
1557 | return; | 1575 | return; |
1558 | } | 1576 | } |
1577 | intel_encoder = &intel_dp->base; | ||
1559 | 1578 | ||
1560 | dp_priv = (struct intel_dp_priv *)(intel_encoder + 1); | 1579 | if (HAS_PCH_SPLIT(dev) && output_reg == PCH_DP_D) |
1561 | |||
1562 | if (HAS_PCH_SPLIT(dev) && (output_reg == PCH_DP_D)) | ||
1563 | if (intel_dpd_is_edp(dev)) | 1580 | if (intel_dpd_is_edp(dev)) |
1564 | dp_priv->is_pch_edp = true; | 1581 | intel_dp->is_pch_edp = true; |
1565 | 1582 | ||
1566 | if (output_reg == DP_A || IS_PCH_eDP(dp_priv)) { | 1583 | if (output_reg == DP_A || IS_PCH_eDP(intel_dp)) { |
1567 | type = DRM_MODE_CONNECTOR_eDP; | 1584 | type = DRM_MODE_CONNECTOR_eDP; |
1568 | intel_encoder->type = INTEL_OUTPUT_EDP; | 1585 | intel_encoder->type = INTEL_OUTPUT_EDP; |
1569 | } else { | 1586 | } else { |
@@ -1584,18 +1601,16 @@ intel_dp_init(struct drm_device *dev, int output_reg) | |||
1584 | else if (output_reg == DP_D || output_reg == PCH_DP_D) | 1601 | else if (output_reg == DP_D || output_reg == PCH_DP_D) |
1585 | intel_encoder->clone_mask = (1 << INTEL_DP_D_CLONE_BIT); | 1602 | intel_encoder->clone_mask = (1 << INTEL_DP_D_CLONE_BIT); |
1586 | 1603 | ||
1587 | if (IS_eDP(intel_encoder)) | 1604 | if (IS_eDP(intel_dp)) |
1588 | intel_encoder->clone_mask = (1 << INTEL_EDP_CLONE_BIT); | 1605 | intel_encoder->clone_mask = (1 << INTEL_EDP_CLONE_BIT); |
1589 | 1606 | ||
1590 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1); | 1607 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1); |
1591 | connector->interlace_allowed = true; | 1608 | connector->interlace_allowed = true; |
1592 | connector->doublescan_allowed = 0; | 1609 | connector->doublescan_allowed = 0; |
1593 | 1610 | ||
1594 | dp_priv->intel_encoder = intel_encoder; | 1611 | intel_dp->output_reg = output_reg; |
1595 | dp_priv->output_reg = output_reg; | 1612 | intel_dp->has_audio = false; |
1596 | dp_priv->has_audio = false; | 1613 | intel_dp->dpms_mode = DRM_MODE_DPMS_ON; |
1597 | dp_priv->dpms_mode = DRM_MODE_DPMS_ON; | ||
1598 | intel_encoder->dev_priv = dp_priv; | ||
1599 | 1614 | ||
1600 | drm_encoder_init(dev, &intel_encoder->enc, &intel_dp_enc_funcs, | 1615 | drm_encoder_init(dev, &intel_encoder->enc, &intel_dp_enc_funcs, |
1601 | DRM_MODE_ENCODER_TMDS); | 1616 | DRM_MODE_ENCODER_TMDS); |
@@ -1630,12 +1645,12 @@ intel_dp_init(struct drm_device *dev, int output_reg) | |||
1630 | break; | 1645 | break; |
1631 | } | 1646 | } |
1632 | 1647 | ||
1633 | intel_dp_i2c_init(intel_encoder, intel_connector, name); | 1648 | intel_dp_i2c_init(intel_dp, intel_connector, name); |
1634 | 1649 | ||
1635 | intel_encoder->ddc_bus = &dp_priv->adapter; | 1650 | intel_encoder->ddc_bus = &intel_dp->adapter; |
1636 | intel_encoder->hot_plug = intel_dp_hot_plug; | 1651 | intel_encoder->hot_plug = intel_dp_hot_plug; |
1637 | 1652 | ||
1638 | if (output_reg == DP_A || IS_PCH_eDP(dp_priv)) { | 1653 | if (output_reg == DP_A || IS_PCH_eDP(intel_dp)) { |
1639 | /* initialize panel mode from VBT if available for eDP */ | 1654 | /* initialize panel mode from VBT if available for eDP */ |
1640 | if (dev_priv->lfp_lvds_vbt_mode) { | 1655 | if (dev_priv->lfp_lvds_vbt_mode) { |
1641 | dev_priv->panel_fixed_mode = | 1656 | dev_priv->panel_fixed_mode = |