diff options
Diffstat (limited to 'drivers/gpu/drm/i915/intel_sdvo.c')
-rw-r--r-- | drivers/gpu/drm/i915/intel_sdvo.c | 894 |
1 files changed, 439 insertions, 455 deletions
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c index e8e902d614ed..a84224f37605 100644 --- a/drivers/gpu/drm/i915/intel_sdvo.c +++ b/drivers/gpu/drm/i915/intel_sdvo.c | |||
@@ -65,8 +65,11 @@ static const char *tv_format_names[] = { | |||
65 | struct intel_sdvo { | 65 | struct intel_sdvo { |
66 | struct intel_encoder base; | 66 | struct intel_encoder base; |
67 | 67 | ||
68 | struct i2c_adapter *i2c; | ||
68 | u8 slave_addr; | 69 | u8 slave_addr; |
69 | 70 | ||
71 | struct i2c_adapter ddc; | ||
72 | |||
70 | /* Register for the SDVO device: SDVOB or SDVOC */ | 73 | /* Register for the SDVO device: SDVOB or SDVOC */ |
71 | int sdvo_reg; | 74 | int sdvo_reg; |
72 | 75 | ||
@@ -106,16 +109,12 @@ struct intel_sdvo { | |||
106 | bool is_hdmi; | 109 | bool is_hdmi; |
107 | 110 | ||
108 | /** | 111 | /** |
109 | * This is set if we detect output of sdvo device as LVDS. | 112 | * This is set if we detect output of sdvo device as LVDS and |
113 | * have a valid fixed mode to use with the panel. | ||
110 | */ | 114 | */ |
111 | bool is_lvds; | 115 | bool is_lvds; |
112 | 116 | ||
113 | /** | 117 | /** |
114 | * This is sdvo flags for input timing. | ||
115 | */ | ||
116 | uint8_t sdvo_flags; | ||
117 | |||
118 | /** | ||
119 | * This is sdvo fixed pannel mode pointer | 118 | * This is sdvo fixed pannel mode pointer |
120 | */ | 119 | */ |
121 | struct drm_display_mode *sdvo_lvds_fixed_mode; | 120 | struct drm_display_mode *sdvo_lvds_fixed_mode; |
@@ -129,9 +128,8 @@ struct intel_sdvo { | |||
129 | /* DDC bus used by this SDVO encoder */ | 128 | /* DDC bus used by this SDVO encoder */ |
130 | uint8_t ddc_bus; | 129 | uint8_t ddc_bus; |
131 | 130 | ||
132 | /* Mac mini hack -- use the same DDC as the analog connector */ | 131 | /* Input timings for adjusted_mode */ |
133 | struct i2c_adapter *analog_ddc_bus; | 132 | struct intel_sdvo_dtd input_dtd; |
134 | |||
135 | }; | 133 | }; |
136 | 134 | ||
137 | struct intel_sdvo_connector { | 135 | struct intel_sdvo_connector { |
@@ -186,9 +184,15 @@ struct intel_sdvo_connector { | |||
186 | u32 cur_dot_crawl, max_dot_crawl; | 184 | u32 cur_dot_crawl, max_dot_crawl; |
187 | }; | 185 | }; |
188 | 186 | ||
189 | static struct intel_sdvo *enc_to_intel_sdvo(struct drm_encoder *encoder) | 187 | static struct intel_sdvo *to_intel_sdvo(struct drm_encoder *encoder) |
188 | { | ||
189 | return container_of(encoder, struct intel_sdvo, base.base); | ||
190 | } | ||
191 | |||
192 | static struct intel_sdvo *intel_attached_sdvo(struct drm_connector *connector) | ||
190 | { | 193 | { |
191 | return container_of(enc_to_intel_encoder(encoder), struct intel_sdvo, base); | 194 | return container_of(intel_attached_encoder(connector), |
195 | struct intel_sdvo, base); | ||
192 | } | 196 | } |
193 | 197 | ||
194 | static struct intel_sdvo_connector *to_intel_sdvo_connector(struct drm_connector *connector) | 198 | static struct intel_sdvo_connector *to_intel_sdvo_connector(struct drm_connector *connector) |
@@ -213,7 +217,7 @@ intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo, | |||
213 | */ | 217 | */ |
214 | static void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val) | 218 | static void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val) |
215 | { | 219 | { |
216 | struct drm_device *dev = intel_sdvo->base.enc.dev; | 220 | struct drm_device *dev = intel_sdvo->base.base.dev; |
217 | struct drm_i915_private *dev_priv = dev->dev_private; | 221 | struct drm_i915_private *dev_priv = dev->dev_private; |
218 | u32 bval = val, cval = val; | 222 | u32 bval = val, cval = val; |
219 | int i; | 223 | int i; |
@@ -245,49 +249,29 @@ static void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val) | |||
245 | 249 | ||
246 | static bool intel_sdvo_read_byte(struct intel_sdvo *intel_sdvo, u8 addr, u8 *ch) | 250 | static bool intel_sdvo_read_byte(struct intel_sdvo *intel_sdvo, u8 addr, u8 *ch) |
247 | { | 251 | { |
248 | u8 out_buf[2] = { addr, 0 }; | ||
249 | u8 buf[2]; | ||
250 | struct i2c_msg msgs[] = { | 252 | struct i2c_msg msgs[] = { |
251 | { | 253 | { |
252 | .addr = intel_sdvo->slave_addr >> 1, | 254 | .addr = intel_sdvo->slave_addr, |
253 | .flags = 0, | 255 | .flags = 0, |
254 | .len = 1, | 256 | .len = 1, |
255 | .buf = out_buf, | 257 | .buf = &addr, |
256 | }, | 258 | }, |
257 | { | 259 | { |
258 | .addr = intel_sdvo->slave_addr >> 1, | 260 | .addr = intel_sdvo->slave_addr, |
259 | .flags = I2C_M_RD, | 261 | .flags = I2C_M_RD, |
260 | .len = 1, | 262 | .len = 1, |
261 | .buf = buf, | 263 | .buf = ch, |
262 | } | 264 | } |
263 | }; | 265 | }; |
264 | int ret; | 266 | int ret; |
265 | 267 | ||
266 | if ((ret = i2c_transfer(intel_sdvo->base.i2c_bus, msgs, 2)) == 2) | 268 | if ((ret = i2c_transfer(intel_sdvo->i2c, msgs, 2)) == 2) |
267 | { | ||
268 | *ch = buf[0]; | ||
269 | return true; | 269 | return true; |
270 | } | ||
271 | 270 | ||
272 | DRM_DEBUG_KMS("i2c transfer returned %d\n", ret); | 271 | DRM_DEBUG_KMS("i2c transfer returned %d\n", ret); |
273 | return false; | 272 | return false; |
274 | } | 273 | } |
275 | 274 | ||
276 | static bool intel_sdvo_write_byte(struct intel_sdvo *intel_sdvo, int addr, u8 ch) | ||
277 | { | ||
278 | u8 out_buf[2] = { addr, ch }; | ||
279 | struct i2c_msg msgs[] = { | ||
280 | { | ||
281 | .addr = intel_sdvo->slave_addr >> 1, | ||
282 | .flags = 0, | ||
283 | .len = 2, | ||
284 | .buf = out_buf, | ||
285 | } | ||
286 | }; | ||
287 | |||
288 | return i2c_transfer(intel_sdvo->base.i2c_bus, msgs, 1) == 1; | ||
289 | } | ||
290 | |||
291 | #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd} | 275 | #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd} |
292 | /** Mapping of command numbers to names, for debug output */ | 276 | /** Mapping of command numbers to names, for debug output */ |
293 | static const struct _sdvo_cmd_name { | 277 | static const struct _sdvo_cmd_name { |
@@ -432,22 +416,6 @@ static void intel_sdvo_debug_write(struct intel_sdvo *intel_sdvo, u8 cmd, | |||
432 | DRM_LOG_KMS("\n"); | 416 | DRM_LOG_KMS("\n"); |
433 | } | 417 | } |
434 | 418 | ||
435 | static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd, | ||
436 | const void *args, int args_len) | ||
437 | { | ||
438 | int i; | ||
439 | |||
440 | intel_sdvo_debug_write(intel_sdvo, cmd, args, args_len); | ||
441 | |||
442 | for (i = 0; i < args_len; i++) { | ||
443 | if (!intel_sdvo_write_byte(intel_sdvo, SDVO_I2C_ARG_0 - i, | ||
444 | ((u8*)args)[i])) | ||
445 | return false; | ||
446 | } | ||
447 | |||
448 | return intel_sdvo_write_byte(intel_sdvo, SDVO_I2C_OPCODE, cmd); | ||
449 | } | ||
450 | |||
451 | static const char *cmd_status_names[] = { | 419 | static const char *cmd_status_names[] = { |
452 | "Power on", | 420 | "Power on", |
453 | "Success", | 421 | "Success", |
@@ -458,54 +426,115 @@ static const char *cmd_status_names[] = { | |||
458 | "Scaling not supported" | 426 | "Scaling not supported" |
459 | }; | 427 | }; |
460 | 428 | ||
461 | static void intel_sdvo_debug_response(struct intel_sdvo *intel_sdvo, | 429 | static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd, |
462 | void *response, int response_len, | 430 | const void *args, int args_len) |
463 | u8 status) | ||
464 | { | 431 | { |
465 | int i; | 432 | u8 buf[args_len*2 + 2], status; |
433 | struct i2c_msg msgs[args_len + 3]; | ||
434 | int i, ret; | ||
466 | 435 | ||
467 | DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(intel_sdvo)); | 436 | intel_sdvo_debug_write(intel_sdvo, cmd, args, args_len); |
468 | for (i = 0; i < response_len; i++) | 437 | |
469 | DRM_LOG_KMS("%02X ", ((u8 *)response)[i]); | 438 | for (i = 0; i < args_len; i++) { |
470 | for (; i < 8; i++) | 439 | msgs[i].addr = intel_sdvo->slave_addr; |
471 | DRM_LOG_KMS(" "); | 440 | msgs[i].flags = 0; |
472 | if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP) | 441 | msgs[i].len = 2; |
473 | DRM_LOG_KMS("(%s)", cmd_status_names[status]); | 442 | msgs[i].buf = buf + 2 *i; |
474 | else | 443 | buf[2*i + 0] = SDVO_I2C_ARG_0 - i; |
475 | DRM_LOG_KMS("(??? %d)", status); | 444 | buf[2*i + 1] = ((u8*)args)[i]; |
476 | DRM_LOG_KMS("\n"); | 445 | } |
446 | msgs[i].addr = intel_sdvo->slave_addr; | ||
447 | msgs[i].flags = 0; | ||
448 | msgs[i].len = 2; | ||
449 | msgs[i].buf = buf + 2*i; | ||
450 | buf[2*i + 0] = SDVO_I2C_OPCODE; | ||
451 | buf[2*i + 1] = cmd; | ||
452 | |||
453 | /* the following two are to read the response */ | ||
454 | status = SDVO_I2C_CMD_STATUS; | ||
455 | msgs[i+1].addr = intel_sdvo->slave_addr; | ||
456 | msgs[i+1].flags = 0; | ||
457 | msgs[i+1].len = 1; | ||
458 | msgs[i+1].buf = &status; | ||
459 | |||
460 | msgs[i+2].addr = intel_sdvo->slave_addr; | ||
461 | msgs[i+2].flags = I2C_M_RD; | ||
462 | msgs[i+2].len = 1; | ||
463 | msgs[i+2].buf = &status; | ||
464 | |||
465 | ret = i2c_transfer(intel_sdvo->i2c, msgs, i+3); | ||
466 | if (ret < 0) { | ||
467 | DRM_DEBUG_KMS("I2c transfer returned %d\n", ret); | ||
468 | return false; | ||
469 | } | ||
470 | if (ret != i+3) { | ||
471 | /* failure in I2C transfer */ | ||
472 | DRM_DEBUG_KMS("I2c transfer returned %d/%d\n", ret, i+3); | ||
473 | return false; | ||
474 | } | ||
475 | |||
476 | i = 3; | ||
477 | while (status == SDVO_CMD_STATUS_PENDING && i--) { | ||
478 | if (!intel_sdvo_read_byte(intel_sdvo, | ||
479 | SDVO_I2C_CMD_STATUS, | ||
480 | &status)) | ||
481 | return false; | ||
482 | } | ||
483 | if (status != SDVO_CMD_STATUS_SUCCESS) { | ||
484 | DRM_DEBUG_KMS("command returns response %s [%d]\n", | ||
485 | status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP ? cmd_status_names[status] : "???", | ||
486 | status); | ||
487 | return false; | ||
488 | } | ||
489 | |||
490 | return true; | ||
477 | } | 491 | } |
478 | 492 | ||
479 | static bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo, | 493 | static bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo, |
480 | void *response, int response_len) | 494 | void *response, int response_len) |
481 | { | 495 | { |
482 | int i; | 496 | u8 retry = 5; |
483 | u8 status; | 497 | u8 status; |
484 | u8 retry = 50; | 498 | int i; |
485 | |||
486 | while (retry--) { | ||
487 | /* Read the command response */ | ||
488 | for (i = 0; i < response_len; i++) { | ||
489 | if (!intel_sdvo_read_byte(intel_sdvo, | ||
490 | SDVO_I2C_RETURN_0 + i, | ||
491 | &((u8 *)response)[i])) | ||
492 | return false; | ||
493 | } | ||
494 | 499 | ||
495 | /* read the return status */ | 500 | /* |
496 | if (!intel_sdvo_read_byte(intel_sdvo, SDVO_I2C_CMD_STATUS, | 501 | * The documentation states that all commands will be |
502 | * processed within 15µs, and that we need only poll | ||
503 | * the status byte a maximum of 3 times in order for the | ||
504 | * command to be complete. | ||
505 | * | ||
506 | * Check 5 times in case the hardware failed to read the docs. | ||
507 | */ | ||
508 | do { | ||
509 | if (!intel_sdvo_read_byte(intel_sdvo, | ||
510 | SDVO_I2C_CMD_STATUS, | ||
497 | &status)) | 511 | &status)) |
498 | return false; | 512 | return false; |
513 | } while (status == SDVO_CMD_STATUS_PENDING && --retry); | ||
499 | 514 | ||
500 | intel_sdvo_debug_response(intel_sdvo, response, response_len, | 515 | DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(intel_sdvo)); |
501 | status); | 516 | if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP) |
502 | if (status != SDVO_CMD_STATUS_PENDING) | 517 | DRM_LOG_KMS("(%s)", cmd_status_names[status]); |
503 | break; | 518 | else |
519 | DRM_LOG_KMS("(??? %d)", status); | ||
520 | |||
521 | if (status != SDVO_CMD_STATUS_SUCCESS) | ||
522 | goto log_fail; | ||
504 | 523 | ||
505 | mdelay(50); | 524 | /* Read the command response */ |
525 | for (i = 0; i < response_len; i++) { | ||
526 | if (!intel_sdvo_read_byte(intel_sdvo, | ||
527 | SDVO_I2C_RETURN_0 + i, | ||
528 | &((u8 *)response)[i])) | ||
529 | goto log_fail; | ||
530 | DRM_LOG_KMS(" %02X", ((u8 *)response)[i]); | ||
506 | } | 531 | } |
532 | DRM_LOG_KMS("\n"); | ||
533 | return true; | ||
507 | 534 | ||
508 | return status == SDVO_CMD_STATUS_SUCCESS; | 535 | log_fail: |
536 | DRM_LOG_KMS("\n"); | ||
537 | return false; | ||
509 | } | 538 | } |
510 | 539 | ||
511 | static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode) | 540 | static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode) |
@@ -518,71 +547,17 @@ static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode) | |||
518 | return 4; | 547 | return 4; |
519 | } | 548 | } |
520 | 549 | ||
521 | /** | 550 | static bool intel_sdvo_set_control_bus_switch(struct intel_sdvo *intel_sdvo, |
522 | * Try to read the response after issuie the DDC switch command. But it | 551 | u8 ddc_bus) |
523 | * is noted that we must do the action of reading response and issuing DDC | ||
524 | * switch command in one I2C transaction. Otherwise when we try to start | ||
525 | * another I2C transaction after issuing the DDC bus switch, it will be | ||
526 | * switched to the internal SDVO register. | ||
527 | */ | ||
528 | static void intel_sdvo_set_control_bus_switch(struct intel_sdvo *intel_sdvo, | ||
529 | u8 target) | ||
530 | { | 552 | { |
531 | u8 out_buf[2], cmd_buf[2], ret_value[2], ret; | 553 | return intel_sdvo_write_cmd(intel_sdvo, |
532 | struct i2c_msg msgs[] = { | 554 | SDVO_CMD_SET_CONTROL_BUS_SWITCH, |
533 | { | 555 | &ddc_bus, 1); |
534 | .addr = intel_sdvo->slave_addr >> 1, | ||
535 | .flags = 0, | ||
536 | .len = 2, | ||
537 | .buf = out_buf, | ||
538 | }, | ||
539 | /* the following two are to read the response */ | ||
540 | { | ||
541 | .addr = intel_sdvo->slave_addr >> 1, | ||
542 | .flags = 0, | ||
543 | .len = 1, | ||
544 | .buf = cmd_buf, | ||
545 | }, | ||
546 | { | ||
547 | .addr = intel_sdvo->slave_addr >> 1, | ||
548 | .flags = I2C_M_RD, | ||
549 | .len = 1, | ||
550 | .buf = ret_value, | ||
551 | }, | ||
552 | }; | ||
553 | |||
554 | intel_sdvo_debug_write(intel_sdvo, SDVO_CMD_SET_CONTROL_BUS_SWITCH, | ||
555 | &target, 1); | ||
556 | /* write the DDC switch command argument */ | ||
557 | intel_sdvo_write_byte(intel_sdvo, SDVO_I2C_ARG_0, target); | ||
558 | |||
559 | out_buf[0] = SDVO_I2C_OPCODE; | ||
560 | out_buf[1] = SDVO_CMD_SET_CONTROL_BUS_SWITCH; | ||
561 | cmd_buf[0] = SDVO_I2C_CMD_STATUS; | ||
562 | cmd_buf[1] = 0; | ||
563 | ret_value[0] = 0; | ||
564 | ret_value[1] = 0; | ||
565 | |||
566 | ret = i2c_transfer(intel_sdvo->base.i2c_bus, msgs, 3); | ||
567 | if (ret != 3) { | ||
568 | /* failure in I2C transfer */ | ||
569 | DRM_DEBUG_KMS("I2c transfer returned %d\n", ret); | ||
570 | return; | ||
571 | } | ||
572 | if (ret_value[0] != SDVO_CMD_STATUS_SUCCESS) { | ||
573 | DRM_DEBUG_KMS("DDC switch command returns response %d\n", | ||
574 | ret_value[0]); | ||
575 | return; | ||
576 | } | ||
577 | return; | ||
578 | } | 556 | } |
579 | 557 | ||
580 | static bool intel_sdvo_set_value(struct intel_sdvo *intel_sdvo, u8 cmd, const void *data, int len) | 558 | static bool intel_sdvo_set_value(struct intel_sdvo *intel_sdvo, u8 cmd, const void *data, int len) |
581 | { | 559 | { |
582 | if (!intel_sdvo_write_cmd(intel_sdvo, cmd, data, len)) | 560 | return intel_sdvo_write_cmd(intel_sdvo, cmd, data, len); |
583 | return false; | ||
584 | |||
585 | return intel_sdvo_read_response(intel_sdvo, NULL, 0); | ||
586 | } | 561 | } |
587 | 562 | ||
588 | static bool | 563 | static bool |
@@ -1022,8 +997,6 @@ intel_sdvo_set_input_timings_for_mode(struct intel_sdvo *intel_sdvo, | |||
1022 | struct drm_display_mode *mode, | 997 | struct drm_display_mode *mode, |
1023 | struct drm_display_mode *adjusted_mode) | 998 | struct drm_display_mode *adjusted_mode) |
1024 | { | 999 | { |
1025 | struct intel_sdvo_dtd input_dtd; | ||
1026 | |||
1027 | /* Reset the input timing to the screen. Assume always input 0. */ | 1000 | /* Reset the input timing to the screen. Assume always input 0. */ |
1028 | if (!intel_sdvo_set_target_input(intel_sdvo)) | 1001 | if (!intel_sdvo_set_target_input(intel_sdvo)) |
1029 | return false; | 1002 | return false; |
@@ -1035,14 +1008,12 @@ intel_sdvo_set_input_timings_for_mode(struct intel_sdvo *intel_sdvo, | |||
1035 | return false; | 1008 | return false; |
1036 | 1009 | ||
1037 | if (!intel_sdvo_get_preferred_input_timing(intel_sdvo, | 1010 | if (!intel_sdvo_get_preferred_input_timing(intel_sdvo, |
1038 | &input_dtd)) | 1011 | &intel_sdvo->input_dtd)) |
1039 | return false; | 1012 | return false; |
1040 | 1013 | ||
1041 | intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd); | 1014 | intel_sdvo_get_mode_from_dtd(adjusted_mode, &intel_sdvo->input_dtd); |
1042 | intel_sdvo->sdvo_flags = input_dtd.part2.sdvo_flags; | ||
1043 | 1015 | ||
1044 | drm_mode_set_crtcinfo(adjusted_mode, 0); | 1016 | drm_mode_set_crtcinfo(adjusted_mode, 0); |
1045 | mode->clock = adjusted_mode->clock; | ||
1046 | return true; | 1017 | return true; |
1047 | } | 1018 | } |
1048 | 1019 | ||
@@ -1050,7 +1021,8 @@ static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder, | |||
1050 | struct drm_display_mode *mode, | 1021 | struct drm_display_mode *mode, |
1051 | struct drm_display_mode *adjusted_mode) | 1022 | struct drm_display_mode *adjusted_mode) |
1052 | { | 1023 | { |
1053 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | 1024 | struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder); |
1025 | int multiplier; | ||
1054 | 1026 | ||
1055 | /* We need to construct preferred input timings based on our | 1027 | /* We need to construct preferred input timings based on our |
1056 | * output timings. To do that, we have to set the output | 1028 | * output timings. To do that, we have to set the output |
@@ -1065,10 +1037,8 @@ static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder, | |||
1065 | mode, | 1037 | mode, |
1066 | adjusted_mode); | 1038 | adjusted_mode); |
1067 | } else if (intel_sdvo->is_lvds) { | 1039 | } else if (intel_sdvo->is_lvds) { |
1068 | drm_mode_set_crtcinfo(intel_sdvo->sdvo_lvds_fixed_mode, 0); | ||
1069 | |||
1070 | if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo, | 1040 | if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo, |
1071 | intel_sdvo->sdvo_lvds_fixed_mode)) | 1041 | intel_sdvo->sdvo_lvds_fixed_mode)) |
1072 | return false; | 1042 | return false; |
1073 | 1043 | ||
1074 | (void) intel_sdvo_set_input_timings_for_mode(intel_sdvo, | 1044 | (void) intel_sdvo_set_input_timings_for_mode(intel_sdvo, |
@@ -1077,9 +1047,10 @@ static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder, | |||
1077 | } | 1047 | } |
1078 | 1048 | ||
1079 | /* Make the CRTC code factor in the SDVO pixel multiplier. The | 1049 | /* Make the CRTC code factor in the SDVO pixel multiplier. The |
1080 | * SDVO device will be told of the multiplier during mode_set. | 1050 | * SDVO device will factor out the multiplier during mode_set. |
1081 | */ | 1051 | */ |
1082 | adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode); | 1052 | multiplier = intel_sdvo_get_pixel_multiplier(adjusted_mode); |
1053 | intel_mode_set_pixel_multiplier(adjusted_mode, multiplier); | ||
1083 | 1054 | ||
1084 | return true; | 1055 | return true; |
1085 | } | 1056 | } |
@@ -1092,11 +1063,12 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, | |||
1092 | struct drm_i915_private *dev_priv = dev->dev_private; | 1063 | struct drm_i915_private *dev_priv = dev->dev_private; |
1093 | struct drm_crtc *crtc = encoder->crtc; | 1064 | struct drm_crtc *crtc = encoder->crtc; |
1094 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | 1065 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
1095 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | 1066 | struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder); |
1096 | u32 sdvox = 0; | 1067 | u32 sdvox; |
1097 | int sdvo_pixel_multiply, rate; | ||
1098 | struct intel_sdvo_in_out_map in_out; | 1068 | struct intel_sdvo_in_out_map in_out; |
1099 | struct intel_sdvo_dtd input_dtd; | 1069 | struct intel_sdvo_dtd input_dtd; |
1070 | int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode); | ||
1071 | int rate; | ||
1100 | 1072 | ||
1101 | if (!mode) | 1073 | if (!mode) |
1102 | return; | 1074 | return; |
@@ -1114,28 +1086,23 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, | |||
1114 | SDVO_CMD_SET_IN_OUT_MAP, | 1086 | SDVO_CMD_SET_IN_OUT_MAP, |
1115 | &in_out, sizeof(in_out)); | 1087 | &in_out, sizeof(in_out)); |
1116 | 1088 | ||
1117 | if (intel_sdvo->is_hdmi) { | 1089 | /* Set the output timings to the screen */ |
1118 | if (!intel_sdvo_set_avi_infoframe(intel_sdvo, mode)) | 1090 | if (!intel_sdvo_set_target_output(intel_sdvo, |
1119 | return; | 1091 | intel_sdvo->attached_output)) |
1120 | 1092 | return; | |
1121 | sdvox |= SDVO_AUDIO_ENABLE; | ||
1122 | } | ||
1123 | 1093 | ||
1124 | /* We have tried to get input timing in mode_fixup, and filled into | 1094 | /* We have tried to get input timing in mode_fixup, and filled into |
1125 | adjusted_mode */ | 1095 | * adjusted_mode. |
1126 | intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode); | ||
1127 | if (intel_sdvo->is_tv || intel_sdvo->is_lvds) | ||
1128 | input_dtd.part2.sdvo_flags = intel_sdvo->sdvo_flags; | ||
1129 | |||
1130 | /* If it's a TV, we already set the output timing in mode_fixup. | ||
1131 | * Otherwise, the output timing is equal to the input timing. | ||
1132 | */ | 1096 | */ |
1133 | if (!intel_sdvo->is_tv && !intel_sdvo->is_lvds) { | 1097 | if (intel_sdvo->is_tv || intel_sdvo->is_lvds) { |
1098 | input_dtd = intel_sdvo->input_dtd; | ||
1099 | } else { | ||
1134 | /* Set the output timing to the screen */ | 1100 | /* Set the output timing to the screen */ |
1135 | if (!intel_sdvo_set_target_output(intel_sdvo, | 1101 | if (!intel_sdvo_set_target_output(intel_sdvo, |
1136 | intel_sdvo->attached_output)) | 1102 | intel_sdvo->attached_output)) |
1137 | return; | 1103 | return; |
1138 | 1104 | ||
1105 | intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode); | ||
1139 | (void) intel_sdvo_set_output_timing(intel_sdvo, &input_dtd); | 1106 | (void) intel_sdvo_set_output_timing(intel_sdvo, &input_dtd); |
1140 | } | 1107 | } |
1141 | 1108 | ||
@@ -1143,31 +1110,18 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, | |||
1143 | if (!intel_sdvo_set_target_input(intel_sdvo)) | 1110 | if (!intel_sdvo_set_target_input(intel_sdvo)) |
1144 | return; | 1111 | return; |
1145 | 1112 | ||
1146 | if (intel_sdvo->is_tv) { | 1113 | if (intel_sdvo->is_hdmi && |
1147 | if (!intel_sdvo_set_tv_format(intel_sdvo)) | 1114 | !intel_sdvo_set_avi_infoframe(intel_sdvo, mode)) |
1148 | return; | 1115 | return; |
1149 | } | ||
1150 | 1116 | ||
1151 | /* We would like to use intel_sdvo_create_preferred_input_timing() to | 1117 | if (intel_sdvo->is_tv && |
1152 | * provide the device with a timing it can support, if it supports that | 1118 | !intel_sdvo_set_tv_format(intel_sdvo)) |
1153 | * feature. However, presumably we would need to adjust the CRTC to | 1119 | return; |
1154 | * output the preferred timing, and we don't support that currently. | ||
1155 | */ | ||
1156 | #if 0 | ||
1157 | success = intel_sdvo_create_preferred_input_timing(encoder, clock, | ||
1158 | width, height); | ||
1159 | if (success) { | ||
1160 | struct intel_sdvo_dtd *input_dtd; | ||
1161 | 1120 | ||
1162 | intel_sdvo_get_preferred_input_timing(encoder, &input_dtd); | ||
1163 | intel_sdvo_set_input_timing(encoder, &input_dtd); | ||
1164 | } | ||
1165 | #else | ||
1166 | (void) intel_sdvo_set_input_timing(intel_sdvo, &input_dtd); | 1121 | (void) intel_sdvo_set_input_timing(intel_sdvo, &input_dtd); |
1167 | #endif | ||
1168 | 1122 | ||
1169 | sdvo_pixel_multiply = intel_sdvo_get_pixel_multiplier(mode); | 1123 | switch (pixel_multiplier) { |
1170 | switch (sdvo_pixel_multiply) { | 1124 | default: |
1171 | case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break; | 1125 | case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break; |
1172 | case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break; | 1126 | case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break; |
1173 | case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break; | 1127 | case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break; |
@@ -1176,14 +1130,14 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, | |||
1176 | return; | 1130 | return; |
1177 | 1131 | ||
1178 | /* Set the SDVO control regs. */ | 1132 | /* Set the SDVO control regs. */ |
1179 | if (IS_I965G(dev)) { | 1133 | if (INTEL_INFO(dev)->gen >= 4) { |
1180 | sdvox |= SDVO_BORDER_ENABLE; | 1134 | sdvox = SDVO_BORDER_ENABLE; |
1181 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) | 1135 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
1182 | sdvox |= SDVO_VSYNC_ACTIVE_HIGH; | 1136 | sdvox |= SDVO_VSYNC_ACTIVE_HIGH; |
1183 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) | 1137 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
1184 | sdvox |= SDVO_HSYNC_ACTIVE_HIGH; | 1138 | sdvox |= SDVO_HSYNC_ACTIVE_HIGH; |
1185 | } else { | 1139 | } else { |
1186 | sdvox |= I915_READ(intel_sdvo->sdvo_reg); | 1140 | sdvox = I915_READ(intel_sdvo->sdvo_reg); |
1187 | switch (intel_sdvo->sdvo_reg) { | 1141 | switch (intel_sdvo->sdvo_reg) { |
1188 | case SDVOB: | 1142 | case SDVOB: |
1189 | sdvox &= SDVOB_PRESERVE_MASK; | 1143 | sdvox &= SDVOB_PRESERVE_MASK; |
@@ -1196,16 +1150,18 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, | |||
1196 | } | 1150 | } |
1197 | if (intel_crtc->pipe == 1) | 1151 | if (intel_crtc->pipe == 1) |
1198 | sdvox |= SDVO_PIPE_B_SELECT; | 1152 | sdvox |= SDVO_PIPE_B_SELECT; |
1153 | if (intel_sdvo->is_hdmi) | ||
1154 | sdvox |= SDVO_AUDIO_ENABLE; | ||
1199 | 1155 | ||
1200 | if (IS_I965G(dev)) { | 1156 | if (INTEL_INFO(dev)->gen >= 4) { |
1201 | /* done in crtc_mode_set as the dpll_md reg must be written early */ | 1157 | /* done in crtc_mode_set as the dpll_md reg must be written early */ |
1202 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { | 1158 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
1203 | /* done in crtc_mode_set as it lives inside the dpll register */ | 1159 | /* done in crtc_mode_set as it lives inside the dpll register */ |
1204 | } else { | 1160 | } else { |
1205 | sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT; | 1161 | sdvox |= (pixel_multiplier - 1) << SDVO_PORT_MULTIPLY_SHIFT; |
1206 | } | 1162 | } |
1207 | 1163 | ||
1208 | if (intel_sdvo->sdvo_flags & SDVO_NEED_TO_STALL) | 1164 | if (input_dtd.part2.sdvo_flags & SDVO_NEED_TO_STALL) |
1209 | sdvox |= SDVO_STALL_SELECT; | 1165 | sdvox |= SDVO_STALL_SELECT; |
1210 | intel_sdvo_write_sdvox(intel_sdvo, sdvox); | 1166 | intel_sdvo_write_sdvox(intel_sdvo, sdvox); |
1211 | } | 1167 | } |
@@ -1214,7 +1170,7 @@ static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode) | |||
1214 | { | 1170 | { |
1215 | struct drm_device *dev = encoder->dev; | 1171 | struct drm_device *dev = encoder->dev; |
1216 | struct drm_i915_private *dev_priv = dev->dev_private; | 1172 | struct drm_i915_private *dev_priv = dev->dev_private; |
1217 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | 1173 | struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder); |
1218 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); | 1174 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
1219 | u32 temp; | 1175 | u32 temp; |
1220 | 1176 | ||
@@ -1260,8 +1216,7 @@ static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode) | |||
1260 | static int intel_sdvo_mode_valid(struct drm_connector *connector, | 1216 | static int intel_sdvo_mode_valid(struct drm_connector *connector, |
1261 | struct drm_display_mode *mode) | 1217 | struct drm_display_mode *mode) |
1262 | { | 1218 | { |
1263 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1219 | struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector); |
1264 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | ||
1265 | 1220 | ||
1266 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) | 1221 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
1267 | return MODE_NO_DBLESCAN; | 1222 | return MODE_NO_DBLESCAN; |
@@ -1285,7 +1240,38 @@ static int intel_sdvo_mode_valid(struct drm_connector *connector, | |||
1285 | 1240 | ||
1286 | static bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct intel_sdvo_caps *caps) | 1241 | static bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct intel_sdvo_caps *caps) |
1287 | { | 1242 | { |
1288 | return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_DEVICE_CAPS, caps, sizeof(*caps)); | 1243 | if (!intel_sdvo_get_value(intel_sdvo, |
1244 | SDVO_CMD_GET_DEVICE_CAPS, | ||
1245 | caps, sizeof(*caps))) | ||
1246 | return false; | ||
1247 | |||
1248 | DRM_DEBUG_KMS("SDVO capabilities:\n" | ||
1249 | " vendor_id: %d\n" | ||
1250 | " device_id: %d\n" | ||
1251 | " device_rev_id: %d\n" | ||
1252 | " sdvo_version_major: %d\n" | ||
1253 | " sdvo_version_minor: %d\n" | ||
1254 | " sdvo_inputs_mask: %d\n" | ||
1255 | " smooth_scaling: %d\n" | ||
1256 | " sharp_scaling: %d\n" | ||
1257 | " up_scaling: %d\n" | ||
1258 | " down_scaling: %d\n" | ||
1259 | " stall_support: %d\n" | ||
1260 | " output_flags: %d\n", | ||
1261 | caps->vendor_id, | ||
1262 | caps->device_id, | ||
1263 | caps->device_rev_id, | ||
1264 | caps->sdvo_version_major, | ||
1265 | caps->sdvo_version_minor, | ||
1266 | caps->sdvo_inputs_mask, | ||
1267 | caps->smooth_scaling, | ||
1268 | caps->sharp_scaling, | ||
1269 | caps->up_scaling, | ||
1270 | caps->down_scaling, | ||
1271 | caps->stall_support, | ||
1272 | caps->output_flags); | ||
1273 | |||
1274 | return true; | ||
1289 | } | 1275 | } |
1290 | 1276 | ||
1291 | /* No use! */ | 1277 | /* No use! */ |
@@ -1389,22 +1375,33 @@ intel_sdvo_multifunc_encoder(struct intel_sdvo *intel_sdvo) | |||
1389 | return (caps > 1); | 1375 | return (caps > 1); |
1390 | } | 1376 | } |
1391 | 1377 | ||
1378 | static struct edid * | ||
1379 | intel_sdvo_get_edid(struct drm_connector *connector) | ||
1380 | { | ||
1381 | struct intel_sdvo *sdvo = intel_attached_sdvo(connector); | ||
1382 | return drm_get_edid(connector, &sdvo->ddc); | ||
1383 | } | ||
1384 | |||
1392 | static struct drm_connector * | 1385 | static struct drm_connector * |
1393 | intel_find_analog_connector(struct drm_device *dev) | 1386 | intel_find_analog_connector(struct drm_device *dev) |
1394 | { | 1387 | { |
1395 | struct drm_connector *connector; | 1388 | struct drm_connector *connector; |
1396 | struct drm_encoder *encoder; | 1389 | struct intel_sdvo *encoder; |
1397 | struct intel_sdvo *intel_sdvo; | 1390 | |
1398 | 1391 | list_for_each_entry(encoder, | |
1399 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { | 1392 | &dev->mode_config.encoder_list, |
1400 | intel_sdvo = enc_to_intel_sdvo(encoder); | 1393 | base.base.head) { |
1401 | if (intel_sdvo->base.type == INTEL_OUTPUT_ANALOG) { | 1394 | if (encoder->base.type == INTEL_OUTPUT_ANALOG) { |
1402 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | 1395 | list_for_each_entry(connector, |
1403 | if (encoder == intel_attached_encoder(connector)) | 1396 | &dev->mode_config.connector_list, |
1397 | head) { | ||
1398 | if (&encoder->base == | ||
1399 | intel_attached_encoder(connector)) | ||
1404 | return connector; | 1400 | return connector; |
1405 | } | 1401 | } |
1406 | } | 1402 | } |
1407 | } | 1403 | } |
1404 | |||
1408 | return NULL; | 1405 | return NULL; |
1409 | } | 1406 | } |
1410 | 1407 | ||
@@ -1424,65 +1421,66 @@ intel_analog_is_connected(struct drm_device *dev) | |||
1424 | return true; | 1421 | return true; |
1425 | } | 1422 | } |
1426 | 1423 | ||
1424 | /* Mac mini hack -- use the same DDC as the analog connector */ | ||
1425 | static struct edid * | ||
1426 | intel_sdvo_get_analog_edid(struct drm_connector *connector) | ||
1427 | { | ||
1428 | struct drm_i915_private *dev_priv = connector->dev->dev_private; | ||
1429 | |||
1430 | if (!intel_analog_is_connected(connector->dev)) | ||
1431 | return NULL; | ||
1432 | |||
1433 | return drm_get_edid(connector, &dev_priv->gmbus[dev_priv->crt_ddc_pin].adapter); | ||
1434 | } | ||
1435 | |||
1427 | enum drm_connector_status | 1436 | enum drm_connector_status |
1428 | intel_sdvo_hdmi_sink_detect(struct drm_connector *connector) | 1437 | intel_sdvo_hdmi_sink_detect(struct drm_connector *connector) |
1429 | { | 1438 | { |
1430 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1439 | struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector); |
1431 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | 1440 | enum drm_connector_status status; |
1432 | struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector); | 1441 | struct edid *edid; |
1433 | enum drm_connector_status status = connector_status_connected; | ||
1434 | struct edid *edid = NULL; | ||
1435 | 1442 | ||
1436 | edid = drm_get_edid(connector, intel_sdvo->base.ddc_bus); | 1443 | edid = intel_sdvo_get_edid(connector); |
1437 | 1444 | ||
1438 | /* This is only applied to SDVO cards with multiple outputs */ | ||
1439 | if (edid == NULL && intel_sdvo_multifunc_encoder(intel_sdvo)) { | 1445 | if (edid == NULL && intel_sdvo_multifunc_encoder(intel_sdvo)) { |
1440 | uint8_t saved_ddc, temp_ddc; | 1446 | u8 ddc, saved_ddc = intel_sdvo->ddc_bus; |
1441 | saved_ddc = intel_sdvo->ddc_bus; | 1447 | |
1442 | temp_ddc = intel_sdvo->ddc_bus >> 1; | ||
1443 | /* | 1448 | /* |
1444 | * Don't use the 1 as the argument of DDC bus switch to get | 1449 | * Don't use the 1 as the argument of DDC bus switch to get |
1445 | * the EDID. It is used for SDVO SPD ROM. | 1450 | * the EDID. It is used for SDVO SPD ROM. |
1446 | */ | 1451 | */ |
1447 | while(temp_ddc > 1) { | 1452 | for (ddc = intel_sdvo->ddc_bus >> 1; ddc > 1; ddc >>= 1) { |
1448 | intel_sdvo->ddc_bus = temp_ddc; | 1453 | intel_sdvo->ddc_bus = ddc; |
1449 | edid = drm_get_edid(connector, intel_sdvo->base.ddc_bus); | 1454 | edid = intel_sdvo_get_edid(connector); |
1450 | if (edid) { | 1455 | if (edid) |
1451 | /* | ||
1452 | * When we can get the EDID, maybe it is the | ||
1453 | * correct DDC bus. Update it. | ||
1454 | */ | ||
1455 | intel_sdvo->ddc_bus = temp_ddc; | ||
1456 | break; | 1456 | break; |
1457 | } | ||
1458 | temp_ddc >>= 1; | ||
1459 | } | 1457 | } |
1458 | /* | ||
1459 | * If we found the EDID on the other bus, | ||
1460 | * assume that is the correct DDC bus. | ||
1461 | */ | ||
1460 | if (edid == NULL) | 1462 | if (edid == NULL) |
1461 | intel_sdvo->ddc_bus = saved_ddc; | 1463 | intel_sdvo->ddc_bus = saved_ddc; |
1462 | } | 1464 | } |
1463 | /* when there is no edid and no monitor is connected with VGA | 1465 | |
1464 | * port, try to use the CRT ddc to read the EDID for DVI-connector | 1466 | /* |
1467 | * When there is no edid and no monitor is connected with VGA | ||
1468 | * port, try to use the CRT ddc to read the EDID for DVI-connector. | ||
1465 | */ | 1469 | */ |
1466 | if (edid == NULL && intel_sdvo->analog_ddc_bus && | 1470 | if (edid == NULL) |
1467 | !intel_analog_is_connected(connector->dev)) | 1471 | edid = intel_sdvo_get_analog_edid(connector); |
1468 | edid = drm_get_edid(connector, intel_sdvo->analog_ddc_bus); | ||
1469 | 1472 | ||
1473 | status = connector_status_unknown; | ||
1470 | if (edid != NULL) { | 1474 | if (edid != NULL) { |
1471 | bool is_digital = !!(edid->input & DRM_EDID_INPUT_DIGITAL); | ||
1472 | bool need_digital = !!(intel_sdvo_connector->output_flag & SDVO_TMDS_MASK); | ||
1473 | |||
1474 | /* DDC bus is shared, match EDID to connector type */ | 1475 | /* DDC bus is shared, match EDID to connector type */ |
1475 | if (is_digital && need_digital) | 1476 | if (edid->input & DRM_EDID_INPUT_DIGITAL) { |
1477 | status = connector_status_connected; | ||
1476 | intel_sdvo->is_hdmi = drm_detect_hdmi_monitor(edid); | 1478 | intel_sdvo->is_hdmi = drm_detect_hdmi_monitor(edid); |
1477 | else if (is_digital != need_digital) | 1479 | } |
1478 | status = connector_status_disconnected; | ||
1479 | |||
1480 | connector->display_info.raw_edid = NULL; | 1480 | connector->display_info.raw_edid = NULL; |
1481 | } else | 1481 | kfree(edid); |
1482 | status = connector_status_disconnected; | 1482 | } |
1483 | 1483 | ||
1484 | kfree(edid); | ||
1485 | |||
1486 | return status; | 1484 | return status; |
1487 | } | 1485 | } |
1488 | 1486 | ||
@@ -1490,13 +1488,12 @@ static enum drm_connector_status | |||
1490 | intel_sdvo_detect(struct drm_connector *connector, bool force) | 1488 | intel_sdvo_detect(struct drm_connector *connector, bool force) |
1491 | { | 1489 | { |
1492 | uint16_t response; | 1490 | uint16_t response; |
1493 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1491 | struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector); |
1494 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | ||
1495 | struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector); | 1492 | struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector); |
1496 | enum drm_connector_status ret; | 1493 | enum drm_connector_status ret; |
1497 | 1494 | ||
1498 | if (!intel_sdvo_write_cmd(intel_sdvo, | 1495 | if (!intel_sdvo_write_cmd(intel_sdvo, |
1499 | SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0)) | 1496 | SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0)) |
1500 | return connector_status_unknown; | 1497 | return connector_status_unknown; |
1501 | if (intel_sdvo->is_tv) { | 1498 | if (intel_sdvo->is_tv) { |
1502 | /* add 30ms delay when the output type is SDVO-TV */ | 1499 | /* add 30ms delay when the output type is SDVO-TV */ |
@@ -1505,7 +1502,9 @@ intel_sdvo_detect(struct drm_connector *connector, bool force) | |||
1505 | if (!intel_sdvo_read_response(intel_sdvo, &response, 2)) | 1502 | if (!intel_sdvo_read_response(intel_sdvo, &response, 2)) |
1506 | return connector_status_unknown; | 1503 | return connector_status_unknown; |
1507 | 1504 | ||
1508 | DRM_DEBUG_KMS("SDVO response %d %d\n", response & 0xff, response >> 8); | 1505 | DRM_DEBUG_KMS("SDVO response %d %d [%x]\n", |
1506 | response & 0xff, response >> 8, | ||
1507 | intel_sdvo_connector->output_flag); | ||
1509 | 1508 | ||
1510 | if (response == 0) | 1509 | if (response == 0) |
1511 | return connector_status_disconnected; | 1510 | return connector_status_disconnected; |
@@ -1538,12 +1537,10 @@ intel_sdvo_detect(struct drm_connector *connector, bool force) | |||
1538 | 1537 | ||
1539 | static void intel_sdvo_get_ddc_modes(struct drm_connector *connector) | 1538 | static void intel_sdvo_get_ddc_modes(struct drm_connector *connector) |
1540 | { | 1539 | { |
1541 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1540 | struct edid *edid; |
1542 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | ||
1543 | int num_modes; | ||
1544 | 1541 | ||
1545 | /* set the bus switch and get the modes */ | 1542 | /* set the bus switch and get the modes */ |
1546 | num_modes = intel_ddc_get_modes(connector, intel_sdvo->base.ddc_bus); | 1543 | edid = intel_sdvo_get_edid(connector); |
1547 | 1544 | ||
1548 | /* | 1545 | /* |
1549 | * Mac mini hack. On this device, the DVI-I connector shares one DDC | 1546 | * Mac mini hack. On this device, the DVI-I connector shares one DDC |
@@ -1551,12 +1548,14 @@ static void intel_sdvo_get_ddc_modes(struct drm_connector *connector) | |||
1551 | * DDC fails, check to see if the analog output is disconnected, in | 1548 | * DDC fails, check to see if the analog output is disconnected, in |
1552 | * which case we'll look there for the digital DDC data. | 1549 | * which case we'll look there for the digital DDC data. |
1553 | */ | 1550 | */ |
1554 | if (num_modes == 0 && | 1551 | if (edid == NULL) |
1555 | intel_sdvo->analog_ddc_bus && | 1552 | edid = intel_sdvo_get_analog_edid(connector); |
1556 | !intel_analog_is_connected(connector->dev)) { | 1553 | |
1557 | /* Switch to the analog ddc bus and try that | 1554 | if (edid != NULL) { |
1558 | */ | 1555 | drm_mode_connector_update_edid_property(connector, edid); |
1559 | (void) intel_ddc_get_modes(connector, intel_sdvo->analog_ddc_bus); | 1556 | drm_add_edid_modes(connector, edid); |
1557 | connector->display_info.raw_edid = NULL; | ||
1558 | kfree(edid); | ||
1560 | } | 1559 | } |
1561 | } | 1560 | } |
1562 | 1561 | ||
@@ -1627,8 +1626,7 @@ struct drm_display_mode sdvo_tv_modes[] = { | |||
1627 | 1626 | ||
1628 | static void intel_sdvo_get_tv_modes(struct drm_connector *connector) | 1627 | static void intel_sdvo_get_tv_modes(struct drm_connector *connector) |
1629 | { | 1628 | { |
1630 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1629 | struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector); |
1631 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | ||
1632 | struct intel_sdvo_sdtv_resolution_request tv_res; | 1630 | struct intel_sdvo_sdtv_resolution_request tv_res; |
1633 | uint32_t reply = 0, format_map = 0; | 1631 | uint32_t reply = 0, format_map = 0; |
1634 | int i; | 1632 | int i; |
@@ -1644,7 +1642,8 @@ static void intel_sdvo_get_tv_modes(struct drm_connector *connector) | |||
1644 | return; | 1642 | return; |
1645 | 1643 | ||
1646 | BUILD_BUG_ON(sizeof(tv_res) != 3); | 1644 | BUILD_BUG_ON(sizeof(tv_res) != 3); |
1647 | if (!intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT, | 1645 | if (!intel_sdvo_write_cmd(intel_sdvo, |
1646 | SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT, | ||
1648 | &tv_res, sizeof(tv_res))) | 1647 | &tv_res, sizeof(tv_res))) |
1649 | return; | 1648 | return; |
1650 | if (!intel_sdvo_read_response(intel_sdvo, &reply, 3)) | 1649 | if (!intel_sdvo_read_response(intel_sdvo, &reply, 3)) |
@@ -1662,8 +1661,7 @@ static void intel_sdvo_get_tv_modes(struct drm_connector *connector) | |||
1662 | 1661 | ||
1663 | static void intel_sdvo_get_lvds_modes(struct drm_connector *connector) | 1662 | static void intel_sdvo_get_lvds_modes(struct drm_connector *connector) |
1664 | { | 1663 | { |
1665 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1664 | struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector); |
1666 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | ||
1667 | struct drm_i915_private *dev_priv = connector->dev->dev_private; | 1665 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
1668 | struct drm_display_mode *newmode; | 1666 | struct drm_display_mode *newmode; |
1669 | 1667 | ||
@@ -1672,7 +1670,7 @@ static void intel_sdvo_get_lvds_modes(struct drm_connector *connector) | |||
1672 | * Assume that the preferred modes are | 1670 | * Assume that the preferred modes are |
1673 | * arranged in priority order. | 1671 | * arranged in priority order. |
1674 | */ | 1672 | */ |
1675 | intel_ddc_get_modes(connector, intel_sdvo->base.ddc_bus); | 1673 | intel_ddc_get_modes(connector, intel_sdvo->i2c); |
1676 | if (list_empty(&connector->probed_modes) == false) | 1674 | if (list_empty(&connector->probed_modes) == false) |
1677 | goto end; | 1675 | goto end; |
1678 | 1676 | ||
@@ -1693,6 +1691,10 @@ end: | |||
1693 | if (newmode->type & DRM_MODE_TYPE_PREFERRED) { | 1691 | if (newmode->type & DRM_MODE_TYPE_PREFERRED) { |
1694 | intel_sdvo->sdvo_lvds_fixed_mode = | 1692 | intel_sdvo->sdvo_lvds_fixed_mode = |
1695 | drm_mode_duplicate(connector->dev, newmode); | 1693 | drm_mode_duplicate(connector->dev, newmode); |
1694 | |||
1695 | drm_mode_set_crtcinfo(intel_sdvo->sdvo_lvds_fixed_mode, | ||
1696 | 0); | ||
1697 | |||
1696 | intel_sdvo->is_lvds = true; | 1698 | intel_sdvo->is_lvds = true; |
1697 | break; | 1699 | break; |
1698 | } | 1700 | } |
@@ -1775,8 +1777,7 @@ intel_sdvo_set_property(struct drm_connector *connector, | |||
1775 | struct drm_property *property, | 1777 | struct drm_property *property, |
1776 | uint64_t val) | 1778 | uint64_t val) |
1777 | { | 1779 | { |
1778 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1780 | struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector); |
1779 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | ||
1780 | struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector); | 1781 | struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector); |
1781 | uint16_t temp_value; | 1782 | uint16_t temp_value; |
1782 | uint8_t cmd; | 1783 | uint8_t cmd; |
@@ -1879,9 +1880,8 @@ set_value: | |||
1879 | 1880 | ||
1880 | 1881 | ||
1881 | done: | 1882 | done: |
1882 | if (encoder->crtc) { | 1883 | if (intel_sdvo->base.base.crtc) { |
1883 | struct drm_crtc *crtc = encoder->crtc; | 1884 | struct drm_crtc *crtc = intel_sdvo->base.base.crtc; |
1884 | |||
1885 | drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x, | 1885 | drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x, |
1886 | crtc->y, crtc->fb); | 1886 | crtc->y, crtc->fb); |
1887 | } | 1887 | } |
@@ -1909,20 +1909,18 @@ static const struct drm_connector_funcs intel_sdvo_connector_funcs = { | |||
1909 | static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = { | 1909 | static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = { |
1910 | .get_modes = intel_sdvo_get_modes, | 1910 | .get_modes = intel_sdvo_get_modes, |
1911 | .mode_valid = intel_sdvo_mode_valid, | 1911 | .mode_valid = intel_sdvo_mode_valid, |
1912 | .best_encoder = intel_attached_encoder, | 1912 | .best_encoder = intel_best_encoder, |
1913 | }; | 1913 | }; |
1914 | 1914 | ||
1915 | static void intel_sdvo_enc_destroy(struct drm_encoder *encoder) | 1915 | static void intel_sdvo_enc_destroy(struct drm_encoder *encoder) |
1916 | { | 1916 | { |
1917 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | 1917 | struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder); |
1918 | |||
1919 | if (intel_sdvo->analog_ddc_bus) | ||
1920 | intel_i2c_destroy(intel_sdvo->analog_ddc_bus); | ||
1921 | 1918 | ||
1922 | if (intel_sdvo->sdvo_lvds_fixed_mode != NULL) | 1919 | if (intel_sdvo->sdvo_lvds_fixed_mode != NULL) |
1923 | drm_mode_destroy(encoder->dev, | 1920 | drm_mode_destroy(encoder->dev, |
1924 | intel_sdvo->sdvo_lvds_fixed_mode); | 1921 | intel_sdvo->sdvo_lvds_fixed_mode); |
1925 | 1922 | ||
1923 | i2c_del_adapter(&intel_sdvo->ddc); | ||
1926 | intel_encoder_destroy(encoder); | 1924 | intel_encoder_destroy(encoder); |
1927 | } | 1925 | } |
1928 | 1926 | ||
@@ -1990,54 +1988,39 @@ intel_sdvo_select_ddc_bus(struct drm_i915_private *dev_priv, | |||
1990 | intel_sdvo_guess_ddc_bus(sdvo); | 1988 | intel_sdvo_guess_ddc_bus(sdvo); |
1991 | } | 1989 | } |
1992 | 1990 | ||
1993 | static bool | 1991 | static void |
1994 | intel_sdvo_get_digital_encoding_mode(struct intel_sdvo *intel_sdvo, int device) | 1992 | intel_sdvo_select_i2c_bus(struct drm_i915_private *dev_priv, |
1993 | struct intel_sdvo *sdvo, u32 reg) | ||
1995 | { | 1994 | { |
1996 | return intel_sdvo_set_target_output(intel_sdvo, | 1995 | struct sdvo_device_mapping *mapping; |
1997 | device == 0 ? SDVO_OUTPUT_TMDS0 : SDVO_OUTPUT_TMDS1) && | 1996 | u8 pin, speed; |
1998 | intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_ENCODE, | ||
1999 | &intel_sdvo->is_hdmi, 1); | ||
2000 | } | ||
2001 | 1997 | ||
2002 | static struct intel_sdvo * | 1998 | if (IS_SDVOB(reg)) |
2003 | intel_sdvo_chan_to_intel_sdvo(struct intel_i2c_chan *chan) | 1999 | mapping = &dev_priv->sdvo_mappings[0]; |
2004 | { | 2000 | else |
2005 | struct drm_device *dev = chan->drm_dev; | 2001 | mapping = &dev_priv->sdvo_mappings[1]; |
2006 | struct drm_encoder *encoder; | ||
2007 | 2002 | ||
2008 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { | 2003 | pin = GMBUS_PORT_DPB; |
2009 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | 2004 | speed = GMBUS_RATE_1MHZ >> 8; |
2010 | if (intel_sdvo->base.ddc_bus == &chan->adapter) | 2005 | if (mapping->initialized) { |
2011 | return intel_sdvo; | 2006 | pin = mapping->i2c_pin; |
2007 | speed = mapping->i2c_speed; | ||
2012 | } | 2008 | } |
2013 | 2009 | ||
2014 | return NULL; | 2010 | sdvo->i2c = &dev_priv->gmbus[pin].adapter; |
2011 | intel_gmbus_set_speed(sdvo->i2c, speed); | ||
2012 | intel_gmbus_force_bit(sdvo->i2c, true); | ||
2015 | } | 2013 | } |
2016 | 2014 | ||
2017 | static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap, | 2015 | static bool |
2018 | struct i2c_msg msgs[], int num) | 2016 | intel_sdvo_get_digital_encoding_mode(struct intel_sdvo *intel_sdvo, int device) |
2019 | { | 2017 | { |
2020 | struct intel_sdvo *intel_sdvo; | 2018 | return intel_sdvo_set_target_output(intel_sdvo, |
2021 | struct i2c_algo_bit_data *algo_data; | 2019 | device == 0 ? SDVO_OUTPUT_TMDS0 : SDVO_OUTPUT_TMDS1) && |
2022 | const struct i2c_algorithm *algo; | 2020 | intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_ENCODE, |
2023 | 2021 | &intel_sdvo->is_hdmi, 1); | |
2024 | algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data; | ||
2025 | intel_sdvo = | ||
2026 | intel_sdvo_chan_to_intel_sdvo((struct intel_i2c_chan *) | ||
2027 | (algo_data->data)); | ||
2028 | if (intel_sdvo == NULL) | ||
2029 | return -EINVAL; | ||
2030 | |||
2031 | algo = intel_sdvo->base.i2c_bus->algo; | ||
2032 | |||
2033 | intel_sdvo_set_control_bus_switch(intel_sdvo, intel_sdvo->ddc_bus); | ||
2034 | return algo->master_xfer(i2c_adap, msgs, num); | ||
2035 | } | 2022 | } |
2036 | 2023 | ||
2037 | static struct i2c_algorithm intel_sdvo_i2c_bit_algo = { | ||
2038 | .master_xfer = intel_sdvo_master_xfer, | ||
2039 | }; | ||
2040 | |||
2041 | static u8 | 2024 | static u8 |
2042 | intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg) | 2025 | intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg) |
2043 | { | 2026 | { |
@@ -2076,26 +2059,29 @@ intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg) | |||
2076 | } | 2059 | } |
2077 | 2060 | ||
2078 | static void | 2061 | static void |
2079 | intel_sdvo_connector_init(struct drm_encoder *encoder, | 2062 | intel_sdvo_connector_init(struct intel_sdvo_connector *connector, |
2080 | struct drm_connector *connector) | 2063 | struct intel_sdvo *encoder) |
2081 | { | 2064 | { |
2082 | drm_connector_init(encoder->dev, connector, &intel_sdvo_connector_funcs, | 2065 | drm_connector_init(encoder->base.base.dev, |
2083 | connector->connector_type); | 2066 | &connector->base.base, |
2067 | &intel_sdvo_connector_funcs, | ||
2068 | connector->base.base.connector_type); | ||
2084 | 2069 | ||
2085 | drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs); | 2070 | drm_connector_helper_add(&connector->base.base, |
2071 | &intel_sdvo_connector_helper_funcs); | ||
2086 | 2072 | ||
2087 | connector->interlace_allowed = 0; | 2073 | connector->base.base.interlace_allowed = 0; |
2088 | connector->doublescan_allowed = 0; | 2074 | connector->base.base.doublescan_allowed = 0; |
2089 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; | 2075 | connector->base.base.display_info.subpixel_order = SubPixelHorizontalRGB; |
2090 | 2076 | ||
2091 | drm_mode_connector_attach_encoder(connector, encoder); | 2077 | intel_connector_attach_encoder(&connector->base, &encoder->base); |
2092 | drm_sysfs_connector_add(connector); | 2078 | drm_sysfs_connector_add(&connector->base.base); |
2093 | } | 2079 | } |
2094 | 2080 | ||
2095 | static bool | 2081 | static bool |
2096 | intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device) | 2082 | intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device) |
2097 | { | 2083 | { |
2098 | struct drm_encoder *encoder = &intel_sdvo->base.enc; | 2084 | struct drm_encoder *encoder = &intel_sdvo->base.base; |
2099 | struct drm_connector *connector; | 2085 | struct drm_connector *connector; |
2100 | struct intel_connector *intel_connector; | 2086 | struct intel_connector *intel_connector; |
2101 | struct intel_sdvo_connector *intel_sdvo_connector; | 2087 | struct intel_sdvo_connector *intel_sdvo_connector; |
@@ -2130,7 +2116,7 @@ intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device) | |||
2130 | intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) | | 2116 | intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) | |
2131 | (1 << INTEL_ANALOG_CLONE_BIT)); | 2117 | (1 << INTEL_ANALOG_CLONE_BIT)); |
2132 | 2118 | ||
2133 | intel_sdvo_connector_init(encoder, connector); | 2119 | intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo); |
2134 | 2120 | ||
2135 | return true; | 2121 | return true; |
2136 | } | 2122 | } |
@@ -2138,83 +2124,83 @@ intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device) | |||
2138 | static bool | 2124 | static bool |
2139 | intel_sdvo_tv_init(struct intel_sdvo *intel_sdvo, int type) | 2125 | intel_sdvo_tv_init(struct intel_sdvo *intel_sdvo, int type) |
2140 | { | 2126 | { |
2141 | struct drm_encoder *encoder = &intel_sdvo->base.enc; | 2127 | struct drm_encoder *encoder = &intel_sdvo->base.base; |
2142 | struct drm_connector *connector; | 2128 | struct drm_connector *connector; |
2143 | struct intel_connector *intel_connector; | 2129 | struct intel_connector *intel_connector; |
2144 | struct intel_sdvo_connector *intel_sdvo_connector; | 2130 | struct intel_sdvo_connector *intel_sdvo_connector; |
2145 | 2131 | ||
2146 | intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); | 2132 | intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); |
2147 | if (!intel_sdvo_connector) | 2133 | if (!intel_sdvo_connector) |
2148 | return false; | 2134 | return false; |
2149 | 2135 | ||
2150 | intel_connector = &intel_sdvo_connector->base; | 2136 | intel_connector = &intel_sdvo_connector->base; |
2151 | connector = &intel_connector->base; | 2137 | connector = &intel_connector->base; |
2152 | encoder->encoder_type = DRM_MODE_ENCODER_TVDAC; | 2138 | encoder->encoder_type = DRM_MODE_ENCODER_TVDAC; |
2153 | connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO; | 2139 | connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO; |
2154 | 2140 | ||
2155 | intel_sdvo->controlled_output |= type; | 2141 | intel_sdvo->controlled_output |= type; |
2156 | intel_sdvo_connector->output_flag = type; | 2142 | intel_sdvo_connector->output_flag = type; |
2157 | 2143 | ||
2158 | intel_sdvo->is_tv = true; | 2144 | intel_sdvo->is_tv = true; |
2159 | intel_sdvo->base.needs_tv_clock = true; | 2145 | intel_sdvo->base.needs_tv_clock = true; |
2160 | intel_sdvo->base.clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT; | 2146 | intel_sdvo->base.clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT; |
2161 | 2147 | ||
2162 | intel_sdvo_connector_init(encoder, connector); | 2148 | intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo); |
2163 | 2149 | ||
2164 | if (!intel_sdvo_tv_create_property(intel_sdvo, intel_sdvo_connector, type)) | 2150 | if (!intel_sdvo_tv_create_property(intel_sdvo, intel_sdvo_connector, type)) |
2165 | goto err; | 2151 | goto err; |
2166 | 2152 | ||
2167 | if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector)) | 2153 | if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector)) |
2168 | goto err; | 2154 | goto err; |
2169 | 2155 | ||
2170 | return true; | 2156 | return true; |
2171 | 2157 | ||
2172 | err: | 2158 | err: |
2173 | intel_sdvo_destroy_enhance_property(connector); | 2159 | intel_sdvo_destroy(connector); |
2174 | kfree(intel_sdvo_connector); | ||
2175 | return false; | 2160 | return false; |
2176 | } | 2161 | } |
2177 | 2162 | ||
2178 | static bool | 2163 | static bool |
2179 | intel_sdvo_analog_init(struct intel_sdvo *intel_sdvo, int device) | 2164 | intel_sdvo_analog_init(struct intel_sdvo *intel_sdvo, int device) |
2180 | { | 2165 | { |
2181 | struct drm_encoder *encoder = &intel_sdvo->base.enc; | 2166 | struct drm_encoder *encoder = &intel_sdvo->base.base; |
2182 | struct drm_connector *connector; | 2167 | struct drm_connector *connector; |
2183 | struct intel_connector *intel_connector; | 2168 | struct intel_connector *intel_connector; |
2184 | struct intel_sdvo_connector *intel_sdvo_connector; | 2169 | struct intel_sdvo_connector *intel_sdvo_connector; |
2185 | 2170 | ||
2186 | intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); | 2171 | intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); |
2187 | if (!intel_sdvo_connector) | 2172 | if (!intel_sdvo_connector) |
2188 | return false; | 2173 | return false; |
2189 | 2174 | ||
2190 | intel_connector = &intel_sdvo_connector->base; | 2175 | intel_connector = &intel_sdvo_connector->base; |
2191 | connector = &intel_connector->base; | 2176 | connector = &intel_connector->base; |
2192 | connector->polled = DRM_CONNECTOR_POLL_CONNECT; | 2177 | connector->polled = DRM_CONNECTOR_POLL_CONNECT; |
2193 | encoder->encoder_type = DRM_MODE_ENCODER_DAC; | 2178 | encoder->encoder_type = DRM_MODE_ENCODER_DAC; |
2194 | connector->connector_type = DRM_MODE_CONNECTOR_VGA; | 2179 | connector->connector_type = DRM_MODE_CONNECTOR_VGA; |
2195 | 2180 | ||
2196 | if (device == 0) { | 2181 | if (device == 0) { |
2197 | intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB0; | 2182 | intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB0; |
2198 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB0; | 2183 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB0; |
2199 | } else if (device == 1) { | 2184 | } else if (device == 1) { |
2200 | intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB1; | 2185 | intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB1; |
2201 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB1; | 2186 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB1; |
2202 | } | 2187 | } |
2203 | 2188 | ||
2204 | intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) | | 2189 | intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) | |
2205 | (1 << INTEL_ANALOG_CLONE_BIT)); | 2190 | (1 << INTEL_ANALOG_CLONE_BIT)); |
2206 | 2191 | ||
2207 | intel_sdvo_connector_init(encoder, connector); | 2192 | intel_sdvo_connector_init(intel_sdvo_connector, |
2208 | return true; | 2193 | intel_sdvo); |
2194 | return true; | ||
2209 | } | 2195 | } |
2210 | 2196 | ||
2211 | static bool | 2197 | static bool |
2212 | intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device) | 2198 | intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device) |
2213 | { | 2199 | { |
2214 | struct drm_encoder *encoder = &intel_sdvo->base.enc; | 2200 | struct drm_encoder *encoder = &intel_sdvo->base.base; |
2215 | struct drm_connector *connector; | 2201 | struct drm_connector *connector; |
2216 | struct intel_connector *intel_connector; | 2202 | struct intel_connector *intel_connector; |
2217 | struct intel_sdvo_connector *intel_sdvo_connector; | 2203 | struct intel_sdvo_connector *intel_sdvo_connector; |
2218 | 2204 | ||
2219 | intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); | 2205 | intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); |
2220 | if (!intel_sdvo_connector) | 2206 | if (!intel_sdvo_connector) |
@@ -2222,29 +2208,28 @@ intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device) | |||
2222 | 2208 | ||
2223 | intel_connector = &intel_sdvo_connector->base; | 2209 | intel_connector = &intel_sdvo_connector->base; |
2224 | connector = &intel_connector->base; | 2210 | connector = &intel_connector->base; |
2225 | encoder->encoder_type = DRM_MODE_ENCODER_LVDS; | 2211 | encoder->encoder_type = DRM_MODE_ENCODER_LVDS; |
2226 | connector->connector_type = DRM_MODE_CONNECTOR_LVDS; | 2212 | connector->connector_type = DRM_MODE_CONNECTOR_LVDS; |
2227 | 2213 | ||
2228 | if (device == 0) { | 2214 | if (device == 0) { |
2229 | intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS0; | 2215 | intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS0; |
2230 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0; | 2216 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0; |
2231 | } else if (device == 1) { | 2217 | } else if (device == 1) { |
2232 | intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS1; | 2218 | intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS1; |
2233 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1; | 2219 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1; |
2234 | } | 2220 | } |
2235 | 2221 | ||
2236 | intel_sdvo->base.clone_mask = ((1 << INTEL_ANALOG_CLONE_BIT) | | 2222 | intel_sdvo->base.clone_mask = ((1 << INTEL_ANALOG_CLONE_BIT) | |
2237 | (1 << INTEL_SDVO_LVDS_CLONE_BIT)); | 2223 | (1 << INTEL_SDVO_LVDS_CLONE_BIT)); |
2238 | 2224 | ||
2239 | intel_sdvo_connector_init(encoder, connector); | 2225 | intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo); |
2240 | if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector)) | 2226 | if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector)) |
2241 | goto err; | 2227 | goto err; |
2242 | 2228 | ||
2243 | return true; | 2229 | return true; |
2244 | 2230 | ||
2245 | err: | 2231 | err: |
2246 | intel_sdvo_destroy_enhance_property(connector); | 2232 | intel_sdvo_destroy(connector); |
2247 | kfree(intel_sdvo_connector); | ||
2248 | return false; | 2233 | return false; |
2249 | } | 2234 | } |
2250 | 2235 | ||
@@ -2309,7 +2294,7 @@ static bool intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo, | |||
2309 | struct intel_sdvo_connector *intel_sdvo_connector, | 2294 | struct intel_sdvo_connector *intel_sdvo_connector, |
2310 | int type) | 2295 | int type) |
2311 | { | 2296 | { |
2312 | struct drm_device *dev = intel_sdvo->base.enc.dev; | 2297 | struct drm_device *dev = intel_sdvo->base.base.dev; |
2313 | struct intel_sdvo_tv_format format; | 2298 | struct intel_sdvo_tv_format format; |
2314 | uint32_t format_map, i; | 2299 | uint32_t format_map, i; |
2315 | 2300 | ||
@@ -2375,7 +2360,7 @@ intel_sdvo_create_enhance_property_tv(struct intel_sdvo *intel_sdvo, | |||
2375 | struct intel_sdvo_connector *intel_sdvo_connector, | 2360 | struct intel_sdvo_connector *intel_sdvo_connector, |
2376 | struct intel_sdvo_enhancements_reply enhancements) | 2361 | struct intel_sdvo_enhancements_reply enhancements) |
2377 | { | 2362 | { |
2378 | struct drm_device *dev = intel_sdvo->base.enc.dev; | 2363 | struct drm_device *dev = intel_sdvo->base.base.dev; |
2379 | struct drm_connector *connector = &intel_sdvo_connector->base.base; | 2364 | struct drm_connector *connector = &intel_sdvo_connector->base.base; |
2380 | uint16_t response, data_value[2]; | 2365 | uint16_t response, data_value[2]; |
2381 | 2366 | ||
@@ -2504,7 +2489,7 @@ intel_sdvo_create_enhance_property_lvds(struct intel_sdvo *intel_sdvo, | |||
2504 | struct intel_sdvo_connector *intel_sdvo_connector, | 2489 | struct intel_sdvo_connector *intel_sdvo_connector, |
2505 | struct intel_sdvo_enhancements_reply enhancements) | 2490 | struct intel_sdvo_enhancements_reply enhancements) |
2506 | { | 2491 | { |
2507 | struct drm_device *dev = intel_sdvo->base.enc.dev; | 2492 | struct drm_device *dev = intel_sdvo->base.base.dev; |
2508 | struct drm_connector *connector = &intel_sdvo_connector->base.base; | 2493 | struct drm_connector *connector = &intel_sdvo_connector->base.base; |
2509 | uint16_t response, data_value[2]; | 2494 | uint16_t response, data_value[2]; |
2510 | 2495 | ||
@@ -2522,11 +2507,10 @@ static bool intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo, | |||
2522 | uint16_t response; | 2507 | uint16_t response; |
2523 | } enhancements; | 2508 | } enhancements; |
2524 | 2509 | ||
2525 | if (!intel_sdvo_get_value(intel_sdvo, | 2510 | enhancements.response = 0; |
2526 | SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS, | 2511 | intel_sdvo_get_value(intel_sdvo, |
2527 | &enhancements, sizeof(enhancements))) | 2512 | SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS, |
2528 | return false; | 2513 | &enhancements, sizeof(enhancements)); |
2529 | |||
2530 | if (enhancements.response == 0) { | 2514 | if (enhancements.response == 0) { |
2531 | DRM_DEBUG_KMS("No enhancement is supported\n"); | 2515 | DRM_DEBUG_KMS("No enhancement is supported\n"); |
2532 | return true; | 2516 | return true; |
@@ -2538,7 +2522,43 @@ static bool intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo, | |||
2538 | return intel_sdvo_create_enhance_property_lvds(intel_sdvo, intel_sdvo_connector, enhancements.reply); | 2522 | return intel_sdvo_create_enhance_property_lvds(intel_sdvo, intel_sdvo_connector, enhancements.reply); |
2539 | else | 2523 | else |
2540 | return true; | 2524 | return true; |
2525 | } | ||
2526 | |||
2527 | static int intel_sdvo_ddc_proxy_xfer(struct i2c_adapter *adapter, | ||
2528 | struct i2c_msg *msgs, | ||
2529 | int num) | ||
2530 | { | ||
2531 | struct intel_sdvo *sdvo = adapter->algo_data; | ||
2532 | |||
2533 | if (!intel_sdvo_set_control_bus_switch(sdvo, sdvo->ddc_bus)) | ||
2534 | return -EIO; | ||
2535 | |||
2536 | return sdvo->i2c->algo->master_xfer(sdvo->i2c, msgs, num); | ||
2537 | } | ||
2541 | 2538 | ||
2539 | static u32 intel_sdvo_ddc_proxy_func(struct i2c_adapter *adapter) | ||
2540 | { | ||
2541 | struct intel_sdvo *sdvo = adapter->algo_data; | ||
2542 | return sdvo->i2c->algo->functionality(sdvo->i2c); | ||
2543 | } | ||
2544 | |||
2545 | static const struct i2c_algorithm intel_sdvo_ddc_proxy = { | ||
2546 | .master_xfer = intel_sdvo_ddc_proxy_xfer, | ||
2547 | .functionality = intel_sdvo_ddc_proxy_func | ||
2548 | }; | ||
2549 | |||
2550 | static bool | ||
2551 | intel_sdvo_init_ddc_proxy(struct intel_sdvo *sdvo, | ||
2552 | struct drm_device *dev) | ||
2553 | { | ||
2554 | sdvo->ddc.owner = THIS_MODULE; | ||
2555 | sdvo->ddc.class = I2C_CLASS_DDC; | ||
2556 | snprintf(sdvo->ddc.name, I2C_NAME_SIZE, "SDVO DDC proxy"); | ||
2557 | sdvo->ddc.dev.parent = &dev->pdev->dev; | ||
2558 | sdvo->ddc.algo_data = sdvo; | ||
2559 | sdvo->ddc.algo = &intel_sdvo_ddc_proxy; | ||
2560 | |||
2561 | return i2c_add_adapter(&sdvo->ddc) == 0; | ||
2542 | } | 2562 | } |
2543 | 2563 | ||
2544 | bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg) | 2564 | bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg) |
@@ -2546,95 +2566,66 @@ bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg) | |||
2546 | struct drm_i915_private *dev_priv = dev->dev_private; | 2566 | struct drm_i915_private *dev_priv = dev->dev_private; |
2547 | struct intel_encoder *intel_encoder; | 2567 | struct intel_encoder *intel_encoder; |
2548 | struct intel_sdvo *intel_sdvo; | 2568 | struct intel_sdvo *intel_sdvo; |
2549 | u8 ch[0x40]; | ||
2550 | int i; | 2569 | int i; |
2551 | u32 i2c_reg, ddc_reg, analog_ddc_reg; | ||
2552 | 2570 | ||
2553 | intel_sdvo = kzalloc(sizeof(struct intel_sdvo), GFP_KERNEL); | 2571 | intel_sdvo = kzalloc(sizeof(struct intel_sdvo), GFP_KERNEL); |
2554 | if (!intel_sdvo) | 2572 | if (!intel_sdvo) |
2555 | return false; | 2573 | return false; |
2556 | 2574 | ||
2575 | if (!intel_sdvo_init_ddc_proxy(intel_sdvo, dev)) { | ||
2576 | kfree(intel_sdvo); | ||
2577 | return false; | ||
2578 | } | ||
2579 | |||
2557 | intel_sdvo->sdvo_reg = sdvo_reg; | 2580 | intel_sdvo->sdvo_reg = sdvo_reg; |
2558 | 2581 | ||
2559 | intel_encoder = &intel_sdvo->base; | 2582 | intel_encoder = &intel_sdvo->base; |
2560 | intel_encoder->type = INTEL_OUTPUT_SDVO; | 2583 | intel_encoder->type = INTEL_OUTPUT_SDVO; |
2584 | /* encoder type will be decided later */ | ||
2585 | drm_encoder_init(dev, &intel_encoder->base, &intel_sdvo_enc_funcs, 0); | ||
2561 | 2586 | ||
2562 | if (HAS_PCH_SPLIT(dev)) { | 2587 | intel_sdvo->slave_addr = intel_sdvo_get_slave_addr(dev, sdvo_reg) >> 1; |
2563 | i2c_reg = PCH_GPIOE; | 2588 | intel_sdvo_select_i2c_bus(dev_priv, intel_sdvo, sdvo_reg); |
2564 | ddc_reg = PCH_GPIOE; | ||
2565 | analog_ddc_reg = PCH_GPIOA; | ||
2566 | } else { | ||
2567 | i2c_reg = GPIOE; | ||
2568 | ddc_reg = GPIOE; | ||
2569 | analog_ddc_reg = GPIOA; | ||
2570 | } | ||
2571 | |||
2572 | /* setup the DDC bus. */ | ||
2573 | if (IS_SDVOB(sdvo_reg)) | ||
2574 | intel_encoder->i2c_bus = intel_i2c_create(dev, i2c_reg, "SDVOCTRL_E for SDVOB"); | ||
2575 | else | ||
2576 | intel_encoder->i2c_bus = intel_i2c_create(dev, i2c_reg, "SDVOCTRL_E for SDVOC"); | ||
2577 | |||
2578 | if (!intel_encoder->i2c_bus) | ||
2579 | goto err_inteloutput; | ||
2580 | |||
2581 | intel_sdvo->slave_addr = intel_sdvo_get_slave_addr(dev, sdvo_reg); | ||
2582 | |||
2583 | /* Save the bit-banging i2c functionality for use by the DDC wrapper */ | ||
2584 | intel_sdvo_i2c_bit_algo.functionality = intel_encoder->i2c_bus->algo->functionality; | ||
2585 | 2589 | ||
2586 | /* Read the regs to test if we can talk to the device */ | 2590 | /* Read the regs to test if we can talk to the device */ |
2587 | for (i = 0; i < 0x40; i++) { | 2591 | for (i = 0; i < 0x40; i++) { |
2588 | if (!intel_sdvo_read_byte(intel_sdvo, i, &ch[i])) { | 2592 | u8 byte; |
2593 | |||
2594 | if (!intel_sdvo_read_byte(intel_sdvo, i, &byte)) { | ||
2589 | DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n", | 2595 | DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n", |
2590 | IS_SDVOB(sdvo_reg) ? 'B' : 'C'); | 2596 | IS_SDVOB(sdvo_reg) ? 'B' : 'C'); |
2591 | goto err_i2c; | 2597 | goto err; |
2592 | } | 2598 | } |
2593 | } | 2599 | } |
2594 | 2600 | ||
2595 | /* setup the DDC bus. */ | 2601 | if (IS_SDVOB(sdvo_reg)) |
2596 | if (IS_SDVOB(sdvo_reg)) { | ||
2597 | intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOB DDC BUS"); | ||
2598 | intel_sdvo->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg, | ||
2599 | "SDVOB/VGA DDC BUS"); | ||
2600 | dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS; | 2602 | dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS; |
2601 | } else { | 2603 | else |
2602 | intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOC DDC BUS"); | ||
2603 | intel_sdvo->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg, | ||
2604 | "SDVOC/VGA DDC BUS"); | ||
2605 | dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS; | 2604 | dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS; |
2606 | } | ||
2607 | if (intel_encoder->ddc_bus == NULL || intel_sdvo->analog_ddc_bus == NULL) | ||
2608 | goto err_i2c; | ||
2609 | |||
2610 | /* Wrap with our custom algo which switches to DDC mode */ | ||
2611 | intel_encoder->ddc_bus->algo = &intel_sdvo_i2c_bit_algo; | ||
2612 | 2605 | ||
2613 | /* encoder type will be decided later */ | 2606 | drm_encoder_helper_add(&intel_encoder->base, &intel_sdvo_helper_funcs); |
2614 | drm_encoder_init(dev, &intel_encoder->enc, &intel_sdvo_enc_funcs, 0); | ||
2615 | drm_encoder_helper_add(&intel_encoder->enc, &intel_sdvo_helper_funcs); | ||
2616 | 2607 | ||
2617 | /* In default case sdvo lvds is false */ | 2608 | /* In default case sdvo lvds is false */ |
2618 | if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps)) | 2609 | if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps)) |
2619 | goto err_enc; | 2610 | goto err; |
2620 | 2611 | ||
2621 | if (intel_sdvo_output_setup(intel_sdvo, | 2612 | if (intel_sdvo_output_setup(intel_sdvo, |
2622 | intel_sdvo->caps.output_flags) != true) { | 2613 | intel_sdvo->caps.output_flags) != true) { |
2623 | DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n", | 2614 | DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n", |
2624 | IS_SDVOB(sdvo_reg) ? 'B' : 'C'); | 2615 | IS_SDVOB(sdvo_reg) ? 'B' : 'C'); |
2625 | goto err_enc; | 2616 | goto err; |
2626 | } | 2617 | } |
2627 | 2618 | ||
2628 | intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo, sdvo_reg); | 2619 | intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo, sdvo_reg); |
2629 | 2620 | ||
2630 | /* Set the input timing to the screen. Assume always input 0. */ | 2621 | /* Set the input timing to the screen. Assume always input 0. */ |
2631 | if (!intel_sdvo_set_target_input(intel_sdvo)) | 2622 | if (!intel_sdvo_set_target_input(intel_sdvo)) |
2632 | goto err_enc; | 2623 | goto err; |
2633 | 2624 | ||
2634 | if (!intel_sdvo_get_input_pixel_clock_range(intel_sdvo, | 2625 | if (!intel_sdvo_get_input_pixel_clock_range(intel_sdvo, |
2635 | &intel_sdvo->pixel_clock_min, | 2626 | &intel_sdvo->pixel_clock_min, |
2636 | &intel_sdvo->pixel_clock_max)) | 2627 | &intel_sdvo->pixel_clock_max)) |
2637 | goto err_enc; | 2628 | goto err; |
2638 | 2629 | ||
2639 | DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, " | 2630 | DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, " |
2640 | "clock range %dMHz - %dMHz, " | 2631 | "clock range %dMHz - %dMHz, " |
@@ -2654,16 +2645,9 @@ bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg) | |||
2654 | (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N'); | 2645 | (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N'); |
2655 | return true; | 2646 | return true; |
2656 | 2647 | ||
2657 | err_enc: | 2648 | err: |
2658 | drm_encoder_cleanup(&intel_encoder->enc); | 2649 | drm_encoder_cleanup(&intel_encoder->base); |
2659 | err_i2c: | 2650 | i2c_del_adapter(&intel_sdvo->ddc); |
2660 | if (intel_sdvo->analog_ddc_bus != NULL) | ||
2661 | intel_i2c_destroy(intel_sdvo->analog_ddc_bus); | ||
2662 | if (intel_encoder->ddc_bus != NULL) | ||
2663 | intel_i2c_destroy(intel_encoder->ddc_bus); | ||
2664 | if (intel_encoder->i2c_bus != NULL) | ||
2665 | intel_i2c_destroy(intel_encoder->i2c_bus); | ||
2666 | err_inteloutput: | ||
2667 | kfree(intel_sdvo); | 2651 | kfree(intel_sdvo); |
2668 | 2652 | ||
2669 | return false; | 2653 | return false; |