diff options
author | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
---|---|---|
committer | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
commit | c71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch) | |
tree | ecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /drivers/gpu/drm/i915/intel_sdvo.c | |
parent | ea53c912f8a86a8567697115b6a0d8152beee5c8 (diff) | |
parent | 6a00f206debf8a5c8899055726ad127dbeeed098 (diff) |
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts:
litmus/sched_cedf.c
Diffstat (limited to 'drivers/gpu/drm/i915/intel_sdvo.c')
-rw-r--r-- | drivers/gpu/drm/i915/intel_sdvo.c | 1193 |
1 files changed, 570 insertions, 623 deletions
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c index ee73e428a84a..30fe554d8936 100644 --- a/drivers/gpu/drm/i915/intel_sdvo.c +++ b/drivers/gpu/drm/i915/intel_sdvo.c | |||
@@ -46,6 +46,7 @@ | |||
46 | SDVO_TV_MASK) | 46 | SDVO_TV_MASK) |
47 | 47 | ||
48 | #define IS_TV(c) (c->output_flag & SDVO_TV_MASK) | 48 | #define IS_TV(c) (c->output_flag & SDVO_TV_MASK) |
49 | #define IS_TMDS(c) (c->output_flag & SDVO_TMDS_MASK) | ||
49 | #define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK) | 50 | #define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK) |
50 | #define IS_TV_OR_LVDS(c) (c->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK)) | 51 | #define IS_TV_OR_LVDS(c) (c->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK)) |
51 | 52 | ||
@@ -65,8 +66,11 @@ static const char *tv_format_names[] = { | |||
65 | struct intel_sdvo { | 66 | struct intel_sdvo { |
66 | struct intel_encoder base; | 67 | struct intel_encoder base; |
67 | 68 | ||
69 | struct i2c_adapter *i2c; | ||
68 | u8 slave_addr; | 70 | u8 slave_addr; |
69 | 71 | ||
72 | struct i2c_adapter ddc; | ||
73 | |||
70 | /* Register for the SDVO device: SDVOB or SDVOC */ | 74 | /* Register for the SDVO device: SDVOB or SDVOC */ |
71 | int sdvo_reg; | 75 | int sdvo_reg; |
72 | 76 | ||
@@ -89,6 +93,12 @@ struct intel_sdvo { | |||
89 | uint16_t attached_output; | 93 | uint16_t attached_output; |
90 | 94 | ||
91 | /** | 95 | /** |
96 | * This is used to select the color range of RBG outputs in HDMI mode. | ||
97 | * It is only valid when using TMDS encoding and 8 bit per color mode. | ||
98 | */ | ||
99 | uint32_t color_range; | ||
100 | |||
101 | /** | ||
92 | * This is set if we're going to treat the device as TV-out. | 102 | * This is set if we're going to treat the device as TV-out. |
93 | * | 103 | * |
94 | * While we have these nice friendly flags for output types that ought | 104 | * While we have these nice friendly flags for output types that ought |
@@ -104,34 +114,25 @@ struct intel_sdvo { | |||
104 | * This is set if we treat the device as HDMI, instead of DVI. | 114 | * This is set if we treat the device as HDMI, instead of DVI. |
105 | */ | 115 | */ |
106 | bool is_hdmi; | 116 | bool is_hdmi; |
117 | bool has_hdmi_monitor; | ||
118 | bool has_hdmi_audio; | ||
107 | 119 | ||
108 | /** | 120 | /** |
109 | * This is set if we detect output of sdvo device as LVDS. | 121 | * This is set if we detect output of sdvo device as LVDS and |
122 | * have a valid fixed mode to use with the panel. | ||
110 | */ | 123 | */ |
111 | bool is_lvds; | 124 | bool is_lvds; |
112 | 125 | ||
113 | /** | 126 | /** |
114 | * This is sdvo flags for input timing. | ||
115 | */ | ||
116 | uint8_t sdvo_flags; | ||
117 | |||
118 | /** | ||
119 | * This is sdvo fixed pannel mode pointer | 127 | * This is sdvo fixed pannel mode pointer |
120 | */ | 128 | */ |
121 | struct drm_display_mode *sdvo_lvds_fixed_mode; | 129 | struct drm_display_mode *sdvo_lvds_fixed_mode; |
122 | 130 | ||
123 | /* | ||
124 | * supported encoding mode, used to determine whether HDMI is | ||
125 | * supported | ||
126 | */ | ||
127 | struct intel_sdvo_encode encode; | ||
128 | |||
129 | /* DDC bus used by this SDVO encoder */ | 131 | /* DDC bus used by this SDVO encoder */ |
130 | uint8_t ddc_bus; | 132 | uint8_t ddc_bus; |
131 | 133 | ||
132 | /* Mac mini hack -- use the same DDC as the analog connector */ | 134 | /* Input timings for adjusted_mode */ |
133 | struct i2c_adapter *analog_ddc_bus; | 135 | struct intel_sdvo_dtd input_dtd; |
134 | |||
135 | }; | 136 | }; |
136 | 137 | ||
137 | struct intel_sdvo_connector { | 138 | struct intel_sdvo_connector { |
@@ -140,6 +141,8 @@ struct intel_sdvo_connector { | |||
140 | /* Mark the type of connector */ | 141 | /* Mark the type of connector */ |
141 | uint16_t output_flag; | 142 | uint16_t output_flag; |
142 | 143 | ||
144 | int force_audio; | ||
145 | |||
143 | /* This contains all current supported TV format */ | 146 | /* This contains all current supported TV format */ |
144 | u8 tv_format_supported[TV_FORMAT_NUM]; | 147 | u8 tv_format_supported[TV_FORMAT_NUM]; |
145 | int format_supported_num; | 148 | int format_supported_num; |
@@ -186,9 +189,15 @@ struct intel_sdvo_connector { | |||
186 | u32 cur_dot_crawl, max_dot_crawl; | 189 | u32 cur_dot_crawl, max_dot_crawl; |
187 | }; | 190 | }; |
188 | 191 | ||
189 | static struct intel_sdvo *enc_to_intel_sdvo(struct drm_encoder *encoder) | 192 | static struct intel_sdvo *to_intel_sdvo(struct drm_encoder *encoder) |
193 | { | ||
194 | return container_of(encoder, struct intel_sdvo, base.base); | ||
195 | } | ||
196 | |||
197 | static struct intel_sdvo *intel_attached_sdvo(struct drm_connector *connector) | ||
190 | { | 198 | { |
191 | return container_of(enc_to_intel_encoder(encoder), struct intel_sdvo, base); | 199 | return container_of(intel_attached_encoder(connector), |
200 | struct intel_sdvo, base); | ||
192 | } | 201 | } |
193 | 202 | ||
194 | static struct intel_sdvo_connector *to_intel_sdvo_connector(struct drm_connector *connector) | 203 | static struct intel_sdvo_connector *to_intel_sdvo_connector(struct drm_connector *connector) |
@@ -213,7 +222,7 @@ intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo, | |||
213 | */ | 222 | */ |
214 | static void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val) | 223 | static void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val) |
215 | { | 224 | { |
216 | struct drm_device *dev = intel_sdvo->base.enc.dev; | 225 | struct drm_device *dev = intel_sdvo->base.base.dev; |
217 | struct drm_i915_private *dev_priv = dev->dev_private; | 226 | struct drm_i915_private *dev_priv = dev->dev_private; |
218 | u32 bval = val, cval = val; | 227 | u32 bval = val, cval = val; |
219 | int i; | 228 | int i; |
@@ -245,49 +254,29 @@ static void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val) | |||
245 | 254 | ||
246 | static bool intel_sdvo_read_byte(struct intel_sdvo *intel_sdvo, u8 addr, u8 *ch) | 255 | static bool intel_sdvo_read_byte(struct intel_sdvo *intel_sdvo, u8 addr, u8 *ch) |
247 | { | 256 | { |
248 | u8 out_buf[2] = { addr, 0 }; | ||
249 | u8 buf[2]; | ||
250 | struct i2c_msg msgs[] = { | 257 | struct i2c_msg msgs[] = { |
251 | { | 258 | { |
252 | .addr = intel_sdvo->slave_addr >> 1, | 259 | .addr = intel_sdvo->slave_addr, |
253 | .flags = 0, | 260 | .flags = 0, |
254 | .len = 1, | 261 | .len = 1, |
255 | .buf = out_buf, | 262 | .buf = &addr, |
256 | }, | 263 | }, |
257 | { | 264 | { |
258 | .addr = intel_sdvo->slave_addr >> 1, | 265 | .addr = intel_sdvo->slave_addr, |
259 | .flags = I2C_M_RD, | 266 | .flags = I2C_M_RD, |
260 | .len = 1, | 267 | .len = 1, |
261 | .buf = buf, | 268 | .buf = ch, |
262 | } | 269 | } |
263 | }; | 270 | }; |
264 | int ret; | 271 | int ret; |
265 | 272 | ||
266 | if ((ret = i2c_transfer(intel_sdvo->base.i2c_bus, msgs, 2)) == 2) | 273 | if ((ret = i2c_transfer(intel_sdvo->i2c, msgs, 2)) == 2) |
267 | { | ||
268 | *ch = buf[0]; | ||
269 | return true; | 274 | return true; |
270 | } | ||
271 | 275 | ||
272 | DRM_DEBUG_KMS("i2c transfer returned %d\n", ret); | 276 | DRM_DEBUG_KMS("i2c transfer returned %d\n", ret); |
273 | return false; | 277 | return false; |
274 | } | 278 | } |
275 | 279 | ||
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} | 280 | #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd} |
292 | /** Mapping of command numbers to names, for debug output */ | 281 | /** Mapping of command numbers to names, for debug output */ |
293 | static const struct _sdvo_cmd_name { | 282 | static const struct _sdvo_cmd_name { |
@@ -432,22 +421,6 @@ static void intel_sdvo_debug_write(struct intel_sdvo *intel_sdvo, u8 cmd, | |||
432 | DRM_LOG_KMS("\n"); | 421 | DRM_LOG_KMS("\n"); |
433 | } | 422 | } |
434 | 423 | ||
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[] = { | 424 | static const char *cmd_status_names[] = { |
452 | "Power on", | 425 | "Power on", |
453 | "Success", | 426 | "Success", |
@@ -458,54 +431,108 @@ static const char *cmd_status_names[] = { | |||
458 | "Scaling not supported" | 431 | "Scaling not supported" |
459 | }; | 432 | }; |
460 | 433 | ||
461 | static void intel_sdvo_debug_response(struct intel_sdvo *intel_sdvo, | 434 | static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd, |
462 | void *response, int response_len, | 435 | const void *args, int args_len) |
463 | u8 status) | ||
464 | { | 436 | { |
465 | int i; | 437 | u8 buf[args_len*2 + 2], status; |
438 | struct i2c_msg msgs[args_len + 3]; | ||
439 | int i, ret; | ||
466 | 440 | ||
467 | DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(intel_sdvo)); | 441 | intel_sdvo_debug_write(intel_sdvo, cmd, args, args_len); |
468 | for (i = 0; i < response_len; i++) | 442 | |
469 | DRM_LOG_KMS("%02X ", ((u8 *)response)[i]); | 443 | for (i = 0; i < args_len; i++) { |
470 | for (; i < 8; i++) | 444 | msgs[i].addr = intel_sdvo->slave_addr; |
471 | DRM_LOG_KMS(" "); | 445 | msgs[i].flags = 0; |
472 | if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP) | 446 | msgs[i].len = 2; |
473 | DRM_LOG_KMS("(%s)", cmd_status_names[status]); | 447 | msgs[i].buf = buf + 2 *i; |
474 | else | 448 | buf[2*i + 0] = SDVO_I2C_ARG_0 - i; |
475 | DRM_LOG_KMS("(??? %d)", status); | 449 | buf[2*i + 1] = ((u8*)args)[i]; |
476 | DRM_LOG_KMS("\n"); | 450 | } |
451 | msgs[i].addr = intel_sdvo->slave_addr; | ||
452 | msgs[i].flags = 0; | ||
453 | msgs[i].len = 2; | ||
454 | msgs[i].buf = buf + 2*i; | ||
455 | buf[2*i + 0] = SDVO_I2C_OPCODE; | ||
456 | buf[2*i + 1] = cmd; | ||
457 | |||
458 | /* the following two are to read the response */ | ||
459 | status = SDVO_I2C_CMD_STATUS; | ||
460 | msgs[i+1].addr = intel_sdvo->slave_addr; | ||
461 | msgs[i+1].flags = 0; | ||
462 | msgs[i+1].len = 1; | ||
463 | msgs[i+1].buf = &status; | ||
464 | |||
465 | msgs[i+2].addr = intel_sdvo->slave_addr; | ||
466 | msgs[i+2].flags = I2C_M_RD; | ||
467 | msgs[i+2].len = 1; | ||
468 | msgs[i+2].buf = &status; | ||
469 | |||
470 | ret = i2c_transfer(intel_sdvo->i2c, msgs, i+3); | ||
471 | if (ret < 0) { | ||
472 | DRM_DEBUG_KMS("I2c transfer returned %d\n", ret); | ||
473 | return false; | ||
474 | } | ||
475 | if (ret != i+3) { | ||
476 | /* failure in I2C transfer */ | ||
477 | DRM_DEBUG_KMS("I2c transfer returned %d/%d\n", ret, i+3); | ||
478 | return false; | ||
479 | } | ||
480 | |||
481 | return true; | ||
477 | } | 482 | } |
478 | 483 | ||
479 | static bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo, | 484 | static bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo, |
480 | void *response, int response_len) | 485 | void *response, int response_len) |
481 | { | 486 | { |
482 | int i; | 487 | u8 retry = 5; |
483 | u8 status; | 488 | u8 status; |
484 | u8 retry = 50; | 489 | int i; |
485 | 490 | ||
486 | while (retry--) { | 491 | DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(intel_sdvo)); |
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 | 492 | ||
495 | /* read the return status */ | 493 | /* |
496 | if (!intel_sdvo_read_byte(intel_sdvo, SDVO_I2C_CMD_STATUS, | 494 | * The documentation states that all commands will be |
495 | * processed within 15µs, and that we need only poll | ||
496 | * the status byte a maximum of 3 times in order for the | ||
497 | * command to be complete. | ||
498 | * | ||
499 | * Check 5 times in case the hardware failed to read the docs. | ||
500 | */ | ||
501 | if (!intel_sdvo_read_byte(intel_sdvo, | ||
502 | SDVO_I2C_CMD_STATUS, | ||
503 | &status)) | ||
504 | goto log_fail; | ||
505 | |||
506 | while (status == SDVO_CMD_STATUS_PENDING && retry--) { | ||
507 | udelay(15); | ||
508 | if (!intel_sdvo_read_byte(intel_sdvo, | ||
509 | SDVO_I2C_CMD_STATUS, | ||
497 | &status)) | 510 | &status)) |
498 | return false; | 511 | goto log_fail; |
512 | } | ||
499 | 513 | ||
500 | intel_sdvo_debug_response(intel_sdvo, response, response_len, | 514 | if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP) |
501 | status); | 515 | DRM_LOG_KMS("(%s)", cmd_status_names[status]); |
502 | if (status != SDVO_CMD_STATUS_PENDING) | 516 | else |
503 | break; | 517 | DRM_LOG_KMS("(??? %d)", status); |
504 | 518 | ||
505 | mdelay(50); | 519 | if (status != SDVO_CMD_STATUS_SUCCESS) |
520 | goto log_fail; | ||
521 | |||
522 | /* Read the command response */ | ||
523 | for (i = 0; i < response_len; i++) { | ||
524 | if (!intel_sdvo_read_byte(intel_sdvo, | ||
525 | SDVO_I2C_RETURN_0 + i, | ||
526 | &((u8 *)response)[i])) | ||
527 | goto log_fail; | ||
528 | DRM_LOG_KMS(" %02X", ((u8 *)response)[i]); | ||
506 | } | 529 | } |
530 | DRM_LOG_KMS("\n"); | ||
531 | return true; | ||
507 | 532 | ||
508 | return status == SDVO_CMD_STATUS_SUCCESS; | 533 | log_fail: |
534 | DRM_LOG_KMS("... failed\n"); | ||
535 | return false; | ||
509 | } | 536 | } |
510 | 537 | ||
511 | static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode) | 538 | static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode) |
@@ -518,63 +545,13 @@ static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode) | |||
518 | return 4; | 545 | return 4; |
519 | } | 546 | } |
520 | 547 | ||
521 | /** | 548 | 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 | 549 | 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 | { | 550 | { |
531 | u8 out_buf[2], cmd_buf[2], ret_value[2], ret; | 551 | /* This must be the immediately preceding write before the i2c xfer */ |
532 | struct i2c_msg msgs[] = { | 552 | return intel_sdvo_write_cmd(intel_sdvo, |
533 | { | 553 | SDVO_CMD_SET_CONTROL_BUS_SWITCH, |
534 | .addr = intel_sdvo->slave_addr >> 1, | 554 | &ddc_bus, 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 | } | 555 | } |
579 | 556 | ||
580 | static bool intel_sdvo_set_value(struct intel_sdvo *intel_sdvo, u8 cmd, const void *data, int len) | 557 | static bool intel_sdvo_set_value(struct intel_sdvo *intel_sdvo, u8 cmd, const void *data, int len) |
@@ -612,6 +589,7 @@ static bool intel_sdvo_get_trained_inputs(struct intel_sdvo *intel_sdvo, bool *i | |||
612 | { | 589 | { |
613 | struct intel_sdvo_get_trained_inputs_response response; | 590 | struct intel_sdvo_get_trained_inputs_response response; |
614 | 591 | ||
592 | BUILD_BUG_ON(sizeof(response) != 1); | ||
615 | if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_TRAINED_INPUTS, | 593 | if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_TRAINED_INPUTS, |
616 | &response, sizeof(response))) | 594 | &response, sizeof(response))) |
617 | return false; | 595 | return false; |
@@ -659,6 +637,7 @@ static bool intel_sdvo_get_input_pixel_clock_range(struct intel_sdvo *intel_sdvo | |||
659 | { | 637 | { |
660 | struct intel_sdvo_pixel_clock_range clocks; | 638 | struct intel_sdvo_pixel_clock_range clocks; |
661 | 639 | ||
640 | BUILD_BUG_ON(sizeof(clocks) != 4); | ||
662 | if (!intel_sdvo_get_value(intel_sdvo, | 641 | if (!intel_sdvo_get_value(intel_sdvo, |
663 | SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE, | 642 | SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE, |
664 | &clocks, sizeof(clocks))) | 643 | &clocks, sizeof(clocks))) |
@@ -726,6 +705,8 @@ intel_sdvo_create_preferred_input_timing(struct intel_sdvo *intel_sdvo, | |||
726 | static bool intel_sdvo_get_preferred_input_timing(struct intel_sdvo *intel_sdvo, | 705 | static bool intel_sdvo_get_preferred_input_timing(struct intel_sdvo *intel_sdvo, |
727 | struct intel_sdvo_dtd *dtd) | 706 | struct intel_sdvo_dtd *dtd) |
728 | { | 707 | { |
708 | BUILD_BUG_ON(sizeof(dtd->part1) != 8); | ||
709 | BUILD_BUG_ON(sizeof(dtd->part2) != 8); | ||
729 | return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1, | 710 | return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1, |
730 | &dtd->part1, sizeof(dtd->part1)) && | 711 | &dtd->part1, sizeof(dtd->part1)) && |
731 | intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2, | 712 | intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2, |
@@ -819,17 +800,14 @@ static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode, | |||
819 | mode->flags |= DRM_MODE_FLAG_PVSYNC; | 800 | mode->flags |= DRM_MODE_FLAG_PVSYNC; |
820 | } | 801 | } |
821 | 802 | ||
822 | static bool intel_sdvo_get_supp_encode(struct intel_sdvo *intel_sdvo, | 803 | static bool intel_sdvo_check_supp_encode(struct intel_sdvo *intel_sdvo) |
823 | struct intel_sdvo_encode *encode) | ||
824 | { | 804 | { |
825 | if (intel_sdvo_get_value(intel_sdvo, | 805 | struct intel_sdvo_encode encode; |
826 | SDVO_CMD_GET_SUPP_ENCODE, | ||
827 | encode, sizeof(*encode))) | ||
828 | return true; | ||
829 | 806 | ||
830 | /* non-support means DVI */ | 807 | BUILD_BUG_ON(sizeof(encode) != 2); |
831 | memset(encode, 0, sizeof(*encode)); | 808 | return intel_sdvo_get_value(intel_sdvo, |
832 | return false; | 809 | SDVO_CMD_GET_SUPP_ENCODE, |
810 | &encode, sizeof(encode)); | ||
833 | } | 811 | } |
834 | 812 | ||
835 | static bool intel_sdvo_set_encode(struct intel_sdvo *intel_sdvo, | 813 | static bool intel_sdvo_set_encode(struct intel_sdvo *intel_sdvo, |
@@ -874,115 +852,36 @@ static void intel_sdvo_dump_hdmi_buf(struct intel_sdvo *intel_sdvo) | |||
874 | } | 852 | } |
875 | #endif | 853 | #endif |
876 | 854 | ||
877 | static bool intel_sdvo_set_hdmi_buf(struct intel_sdvo *intel_sdvo, | 855 | static bool intel_sdvo_set_avi_infoframe(struct intel_sdvo *intel_sdvo) |
878 | int index, | ||
879 | uint8_t *data, int8_t size, uint8_t tx_rate) | ||
880 | { | ||
881 | uint8_t set_buf_index[2]; | ||
882 | |||
883 | set_buf_index[0] = index; | ||
884 | set_buf_index[1] = 0; | ||
885 | |||
886 | if (!intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_HBUF_INDEX, | ||
887 | set_buf_index, 2)) | ||
888 | return false; | ||
889 | |||
890 | for (; size > 0; size -= 8) { | ||
891 | if (!intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_HBUF_DATA, data, 8)) | ||
892 | return false; | ||
893 | |||
894 | data += 8; | ||
895 | } | ||
896 | |||
897 | return intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1); | ||
898 | } | ||
899 | |||
900 | static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data, uint8_t size) | ||
901 | { | ||
902 | uint8_t csum = 0; | ||
903 | int i; | ||
904 | |||
905 | for (i = 0; i < size; i++) | ||
906 | csum += data[i]; | ||
907 | |||
908 | return 0x100 - csum; | ||
909 | } | ||
910 | |||
911 | #define DIP_TYPE_AVI 0x82 | ||
912 | #define DIP_VERSION_AVI 0x2 | ||
913 | #define DIP_LEN_AVI 13 | ||
914 | |||
915 | struct dip_infoframe { | ||
916 | uint8_t type; | ||
917 | uint8_t version; | ||
918 | uint8_t len; | ||
919 | uint8_t checksum; | ||
920 | union { | ||
921 | struct { | ||
922 | /* Packet Byte #1 */ | ||
923 | uint8_t S:2; | ||
924 | uint8_t B:2; | ||
925 | uint8_t A:1; | ||
926 | uint8_t Y:2; | ||
927 | uint8_t rsvd1:1; | ||
928 | /* Packet Byte #2 */ | ||
929 | uint8_t R:4; | ||
930 | uint8_t M:2; | ||
931 | uint8_t C:2; | ||
932 | /* Packet Byte #3 */ | ||
933 | uint8_t SC:2; | ||
934 | uint8_t Q:2; | ||
935 | uint8_t EC:3; | ||
936 | uint8_t ITC:1; | ||
937 | /* Packet Byte #4 */ | ||
938 | uint8_t VIC:7; | ||
939 | uint8_t rsvd2:1; | ||
940 | /* Packet Byte #5 */ | ||
941 | uint8_t PR:4; | ||
942 | uint8_t rsvd3:4; | ||
943 | /* Packet Byte #6~13 */ | ||
944 | uint16_t top_bar_end; | ||
945 | uint16_t bottom_bar_start; | ||
946 | uint16_t left_bar_end; | ||
947 | uint16_t right_bar_start; | ||
948 | } avi; | ||
949 | struct { | ||
950 | /* Packet Byte #1 */ | ||
951 | uint8_t channel_count:3; | ||
952 | uint8_t rsvd1:1; | ||
953 | uint8_t coding_type:4; | ||
954 | /* Packet Byte #2 */ | ||
955 | uint8_t sample_size:2; /* SS0, SS1 */ | ||
956 | uint8_t sample_frequency:3; | ||
957 | uint8_t rsvd2:3; | ||
958 | /* Packet Byte #3 */ | ||
959 | uint8_t coding_type_private:5; | ||
960 | uint8_t rsvd3:3; | ||
961 | /* Packet Byte #4 */ | ||
962 | uint8_t channel_allocation; | ||
963 | /* Packet Byte #5 */ | ||
964 | uint8_t rsvd4:3; | ||
965 | uint8_t level_shift:4; | ||
966 | uint8_t downmix_inhibit:1; | ||
967 | } audio; | ||
968 | uint8_t payload[28]; | ||
969 | } __attribute__ ((packed)) u; | ||
970 | } __attribute__((packed)); | ||
971 | |||
972 | static bool intel_sdvo_set_avi_infoframe(struct intel_sdvo *intel_sdvo, | ||
973 | struct drm_display_mode * mode) | ||
974 | { | 856 | { |
975 | struct dip_infoframe avi_if = { | 857 | struct dip_infoframe avi_if = { |
976 | .type = DIP_TYPE_AVI, | 858 | .type = DIP_TYPE_AVI, |
977 | .version = DIP_VERSION_AVI, | 859 | .ver = DIP_VERSION_AVI, |
978 | .len = DIP_LEN_AVI, | 860 | .len = DIP_LEN_AVI, |
979 | }; | 861 | }; |
862 | uint8_t tx_rate = SDVO_HBUF_TX_VSYNC; | ||
863 | uint8_t set_buf_index[2] = { 1, 0 }; | ||
864 | uint64_t *data = (uint64_t *)&avi_if; | ||
865 | unsigned i; | ||
866 | |||
867 | intel_dip_infoframe_csum(&avi_if); | ||
868 | |||
869 | if (!intel_sdvo_set_value(intel_sdvo, | ||
870 | SDVO_CMD_SET_HBUF_INDEX, | ||
871 | set_buf_index, 2)) | ||
872 | return false; | ||
980 | 873 | ||
981 | avi_if.checksum = intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if, | 874 | for (i = 0; i < sizeof(avi_if); i += 8) { |
982 | 4 + avi_if.len); | 875 | if (!intel_sdvo_set_value(intel_sdvo, |
983 | return intel_sdvo_set_hdmi_buf(intel_sdvo, 1, (uint8_t *)&avi_if, | 876 | SDVO_CMD_SET_HBUF_DATA, |
984 | 4 + avi_if.len, | 877 | data, 8)) |
985 | SDVO_HBUF_TX_VSYNC); | 878 | return false; |
879 | data++; | ||
880 | } | ||
881 | |||
882 | return intel_sdvo_set_value(intel_sdvo, | ||
883 | SDVO_CMD_SET_HBUF_TXRATE, | ||
884 | &tx_rate, 1); | ||
986 | } | 885 | } |
987 | 886 | ||
988 | static bool intel_sdvo_set_tv_format(struct intel_sdvo *intel_sdvo) | 887 | static bool intel_sdvo_set_tv_format(struct intel_sdvo *intel_sdvo) |
@@ -1022,8 +921,6 @@ intel_sdvo_set_input_timings_for_mode(struct intel_sdvo *intel_sdvo, | |||
1022 | struct drm_display_mode *mode, | 921 | struct drm_display_mode *mode, |
1023 | struct drm_display_mode *adjusted_mode) | 922 | struct drm_display_mode *adjusted_mode) |
1024 | { | 923 | { |
1025 | struct intel_sdvo_dtd input_dtd; | ||
1026 | |||
1027 | /* Reset the input timing to the screen. Assume always input 0. */ | 924 | /* Reset the input timing to the screen. Assume always input 0. */ |
1028 | if (!intel_sdvo_set_target_input(intel_sdvo)) | 925 | if (!intel_sdvo_set_target_input(intel_sdvo)) |
1029 | return false; | 926 | return false; |
@@ -1035,14 +932,12 @@ intel_sdvo_set_input_timings_for_mode(struct intel_sdvo *intel_sdvo, | |||
1035 | return false; | 932 | return false; |
1036 | 933 | ||
1037 | if (!intel_sdvo_get_preferred_input_timing(intel_sdvo, | 934 | if (!intel_sdvo_get_preferred_input_timing(intel_sdvo, |
1038 | &input_dtd)) | 935 | &intel_sdvo->input_dtd)) |
1039 | return false; | 936 | return false; |
1040 | 937 | ||
1041 | intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd); | 938 | intel_sdvo_get_mode_from_dtd(adjusted_mode, &intel_sdvo->input_dtd); |
1042 | intel_sdvo->sdvo_flags = input_dtd.part2.sdvo_flags; | ||
1043 | 939 | ||
1044 | drm_mode_set_crtcinfo(adjusted_mode, 0); | 940 | drm_mode_set_crtcinfo(adjusted_mode, 0); |
1045 | mode->clock = adjusted_mode->clock; | ||
1046 | return true; | 941 | return true; |
1047 | } | 942 | } |
1048 | 943 | ||
@@ -1050,7 +945,8 @@ static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder, | |||
1050 | struct drm_display_mode *mode, | 945 | struct drm_display_mode *mode, |
1051 | struct drm_display_mode *adjusted_mode) | 946 | struct drm_display_mode *adjusted_mode) |
1052 | { | 947 | { |
1053 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | 948 | struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder); |
949 | int multiplier; | ||
1054 | 950 | ||
1055 | /* We need to construct preferred input timings based on our | 951 | /* We need to construct preferred input timings based on our |
1056 | * output timings. To do that, we have to set the output | 952 | * output timings. To do that, we have to set the output |
@@ -1065,10 +961,8 @@ static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder, | |||
1065 | mode, | 961 | mode, |
1066 | adjusted_mode); | 962 | adjusted_mode); |
1067 | } else if (intel_sdvo->is_lvds) { | 963 | } 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, | 964 | if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo, |
1071 | intel_sdvo->sdvo_lvds_fixed_mode)) | 965 | intel_sdvo->sdvo_lvds_fixed_mode)) |
1072 | return false; | 966 | return false; |
1073 | 967 | ||
1074 | (void) intel_sdvo_set_input_timings_for_mode(intel_sdvo, | 968 | (void) intel_sdvo_set_input_timings_for_mode(intel_sdvo, |
@@ -1077,9 +971,10 @@ static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder, | |||
1077 | } | 971 | } |
1078 | 972 | ||
1079 | /* Make the CRTC code factor in the SDVO pixel multiplier. The | 973 | /* Make the CRTC code factor in the SDVO pixel multiplier. The |
1080 | * SDVO device will be told of the multiplier during mode_set. | 974 | * SDVO device will factor out the multiplier during mode_set. |
1081 | */ | 975 | */ |
1082 | adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode); | 976 | multiplier = intel_sdvo_get_pixel_multiplier(adjusted_mode); |
977 | intel_mode_set_pixel_multiplier(adjusted_mode, multiplier); | ||
1083 | 978 | ||
1084 | return true; | 979 | return true; |
1085 | } | 980 | } |
@@ -1092,11 +987,12 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, | |||
1092 | struct drm_i915_private *dev_priv = dev->dev_private; | 987 | struct drm_i915_private *dev_priv = dev->dev_private; |
1093 | struct drm_crtc *crtc = encoder->crtc; | 988 | struct drm_crtc *crtc = encoder->crtc; |
1094 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | 989 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
1095 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | 990 | struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder); |
1096 | u32 sdvox = 0; | 991 | u32 sdvox; |
1097 | int sdvo_pixel_multiply, rate; | ||
1098 | struct intel_sdvo_in_out_map in_out; | 992 | struct intel_sdvo_in_out_map in_out; |
1099 | struct intel_sdvo_dtd input_dtd; | 993 | struct intel_sdvo_dtd input_dtd; |
994 | int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode); | ||
995 | int rate; | ||
1100 | 996 | ||
1101 | if (!mode) | 997 | if (!mode) |
1102 | return; | 998 | return; |
@@ -1114,28 +1010,23 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, | |||
1114 | SDVO_CMD_SET_IN_OUT_MAP, | 1010 | SDVO_CMD_SET_IN_OUT_MAP, |
1115 | &in_out, sizeof(in_out)); | 1011 | &in_out, sizeof(in_out)); |
1116 | 1012 | ||
1117 | if (intel_sdvo->is_hdmi) { | 1013 | /* Set the output timings to the screen */ |
1118 | if (!intel_sdvo_set_avi_infoframe(intel_sdvo, mode)) | 1014 | if (!intel_sdvo_set_target_output(intel_sdvo, |
1119 | return; | 1015 | intel_sdvo->attached_output)) |
1120 | 1016 | return; | |
1121 | sdvox |= SDVO_AUDIO_ENABLE; | ||
1122 | } | ||
1123 | 1017 | ||
1124 | /* We have tried to get input timing in mode_fixup, and filled into | 1018 | /* We have tried to get input timing in mode_fixup, and filled into |
1125 | adjusted_mode */ | 1019 | * 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 | */ | 1020 | */ |
1133 | if (!intel_sdvo->is_tv && !intel_sdvo->is_lvds) { | 1021 | if (intel_sdvo->is_tv || intel_sdvo->is_lvds) { |
1022 | input_dtd = intel_sdvo->input_dtd; | ||
1023 | } else { | ||
1134 | /* Set the output timing to the screen */ | 1024 | /* Set the output timing to the screen */ |
1135 | if (!intel_sdvo_set_target_output(intel_sdvo, | 1025 | if (!intel_sdvo_set_target_output(intel_sdvo, |
1136 | intel_sdvo->attached_output)) | 1026 | intel_sdvo->attached_output)) |
1137 | return; | 1027 | return; |
1138 | 1028 | ||
1029 | intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode); | ||
1139 | (void) intel_sdvo_set_output_timing(intel_sdvo, &input_dtd); | 1030 | (void) intel_sdvo_set_output_timing(intel_sdvo, &input_dtd); |
1140 | } | 1031 | } |
1141 | 1032 | ||
@@ -1143,31 +1034,22 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, | |||
1143 | if (!intel_sdvo_set_target_input(intel_sdvo)) | 1034 | if (!intel_sdvo_set_target_input(intel_sdvo)) |
1144 | return; | 1035 | return; |
1145 | 1036 | ||
1146 | if (intel_sdvo->is_tv) { | 1037 | if (intel_sdvo->has_hdmi_monitor) { |
1147 | if (!intel_sdvo_set_tv_format(intel_sdvo)) | 1038 | intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_HDMI); |
1148 | return; | 1039 | intel_sdvo_set_colorimetry(intel_sdvo, |
1149 | } | 1040 | SDVO_COLORIMETRY_RGB256); |
1041 | intel_sdvo_set_avi_infoframe(intel_sdvo); | ||
1042 | } else | ||
1043 | intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_DVI); | ||
1150 | 1044 | ||
1151 | /* We would like to use intel_sdvo_create_preferred_input_timing() to | 1045 | if (intel_sdvo->is_tv && |
1152 | * provide the device with a timing it can support, if it supports that | 1046 | !intel_sdvo_set_tv_format(intel_sdvo)) |
1153 | * feature. However, presumably we would need to adjust the CRTC to | 1047 | 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 | 1048 | ||
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); | 1049 | (void) intel_sdvo_set_input_timing(intel_sdvo, &input_dtd); |
1167 | #endif | ||
1168 | 1050 | ||
1169 | sdvo_pixel_multiply = intel_sdvo_get_pixel_multiplier(mode); | 1051 | switch (pixel_multiplier) { |
1170 | switch (sdvo_pixel_multiply) { | 1052 | default: |
1171 | case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break; | 1053 | case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break; |
1172 | case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break; | 1054 | case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break; |
1173 | case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break; | 1055 | case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break; |
@@ -1176,14 +1058,18 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, | |||
1176 | return; | 1058 | return; |
1177 | 1059 | ||
1178 | /* Set the SDVO control regs. */ | 1060 | /* Set the SDVO control regs. */ |
1179 | if (IS_I965G(dev)) { | 1061 | if (INTEL_INFO(dev)->gen >= 4) { |
1180 | sdvox |= SDVO_BORDER_ENABLE; | 1062 | sdvox = 0; |
1063 | if (intel_sdvo->is_hdmi) | ||
1064 | sdvox |= intel_sdvo->color_range; | ||
1065 | if (INTEL_INFO(dev)->gen < 5) | ||
1066 | sdvox |= SDVO_BORDER_ENABLE; | ||
1181 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) | 1067 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
1182 | sdvox |= SDVO_VSYNC_ACTIVE_HIGH; | 1068 | sdvox |= SDVO_VSYNC_ACTIVE_HIGH; |
1183 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) | 1069 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
1184 | sdvox |= SDVO_HSYNC_ACTIVE_HIGH; | 1070 | sdvox |= SDVO_HSYNC_ACTIVE_HIGH; |
1185 | } else { | 1071 | } else { |
1186 | sdvox |= I915_READ(intel_sdvo->sdvo_reg); | 1072 | sdvox = I915_READ(intel_sdvo->sdvo_reg); |
1187 | switch (intel_sdvo->sdvo_reg) { | 1073 | switch (intel_sdvo->sdvo_reg) { |
1188 | case SDVOB: | 1074 | case SDVOB: |
1189 | sdvox &= SDVOB_PRESERVE_MASK; | 1075 | sdvox &= SDVOB_PRESERVE_MASK; |
@@ -1196,16 +1082,19 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, | |||
1196 | } | 1082 | } |
1197 | if (intel_crtc->pipe == 1) | 1083 | if (intel_crtc->pipe == 1) |
1198 | sdvox |= SDVO_PIPE_B_SELECT; | 1084 | sdvox |= SDVO_PIPE_B_SELECT; |
1085 | if (intel_sdvo->has_hdmi_audio) | ||
1086 | sdvox |= SDVO_AUDIO_ENABLE; | ||
1199 | 1087 | ||
1200 | if (IS_I965G(dev)) { | 1088 | if (INTEL_INFO(dev)->gen >= 4) { |
1201 | /* done in crtc_mode_set as the dpll_md reg must be written early */ | 1089 | /* 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)) { | 1090 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
1203 | /* done in crtc_mode_set as it lives inside the dpll register */ | 1091 | /* done in crtc_mode_set as it lives inside the dpll register */ |
1204 | } else { | 1092 | } else { |
1205 | sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT; | 1093 | sdvox |= (pixel_multiplier - 1) << SDVO_PORT_MULTIPLY_SHIFT; |
1206 | } | 1094 | } |
1207 | 1095 | ||
1208 | if (intel_sdvo->sdvo_flags & SDVO_NEED_TO_STALL) | 1096 | if (input_dtd.part2.sdvo_flags & SDVO_NEED_TO_STALL && |
1097 | INTEL_INFO(dev)->gen < 5) | ||
1209 | sdvox |= SDVO_STALL_SELECT; | 1098 | sdvox |= SDVO_STALL_SELECT; |
1210 | intel_sdvo_write_sdvox(intel_sdvo, sdvox); | 1099 | intel_sdvo_write_sdvox(intel_sdvo, sdvox); |
1211 | } | 1100 | } |
@@ -1214,7 +1103,7 @@ static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode) | |||
1214 | { | 1103 | { |
1215 | struct drm_device *dev = encoder->dev; | 1104 | struct drm_device *dev = encoder->dev; |
1216 | struct drm_i915_private *dev_priv = dev->dev_private; | 1105 | struct drm_i915_private *dev_priv = dev->dev_private; |
1217 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | 1106 | struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder); |
1218 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); | 1107 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
1219 | u32 temp; | 1108 | u32 temp; |
1220 | 1109 | ||
@@ -1260,8 +1149,7 @@ static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode) | |||
1260 | static int intel_sdvo_mode_valid(struct drm_connector *connector, | 1149 | static int intel_sdvo_mode_valid(struct drm_connector *connector, |
1261 | struct drm_display_mode *mode) | 1150 | struct drm_display_mode *mode) |
1262 | { | 1151 | { |
1263 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1152 | struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector); |
1264 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | ||
1265 | 1153 | ||
1266 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) | 1154 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
1267 | return MODE_NO_DBLESCAN; | 1155 | return MODE_NO_DBLESCAN; |
@@ -1285,7 +1173,39 @@ static int intel_sdvo_mode_valid(struct drm_connector *connector, | |||
1285 | 1173 | ||
1286 | static bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct intel_sdvo_caps *caps) | 1174 | static bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct intel_sdvo_caps *caps) |
1287 | { | 1175 | { |
1288 | return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_DEVICE_CAPS, caps, sizeof(*caps)); | 1176 | BUILD_BUG_ON(sizeof(*caps) != 8); |
1177 | if (!intel_sdvo_get_value(intel_sdvo, | ||
1178 | SDVO_CMD_GET_DEVICE_CAPS, | ||
1179 | caps, sizeof(*caps))) | ||
1180 | return false; | ||
1181 | |||
1182 | DRM_DEBUG_KMS("SDVO capabilities:\n" | ||
1183 | " vendor_id: %d\n" | ||
1184 | " device_id: %d\n" | ||
1185 | " device_rev_id: %d\n" | ||
1186 | " sdvo_version_major: %d\n" | ||
1187 | " sdvo_version_minor: %d\n" | ||
1188 | " sdvo_inputs_mask: %d\n" | ||
1189 | " smooth_scaling: %d\n" | ||
1190 | " sharp_scaling: %d\n" | ||
1191 | " up_scaling: %d\n" | ||
1192 | " down_scaling: %d\n" | ||
1193 | " stall_support: %d\n" | ||
1194 | " output_flags: %d\n", | ||
1195 | caps->vendor_id, | ||
1196 | caps->device_id, | ||
1197 | caps->device_rev_id, | ||
1198 | caps->sdvo_version_major, | ||
1199 | caps->sdvo_version_minor, | ||
1200 | caps->sdvo_inputs_mask, | ||
1201 | caps->smooth_scaling, | ||
1202 | caps->sharp_scaling, | ||
1203 | caps->up_scaling, | ||
1204 | caps->down_scaling, | ||
1205 | caps->stall_support, | ||
1206 | caps->output_flags); | ||
1207 | |||
1208 | return true; | ||
1289 | } | 1209 | } |
1290 | 1210 | ||
1291 | /* No use! */ | 1211 | /* No use! */ |
@@ -1360,128 +1280,85 @@ void intel_sdvo_set_hotplug(struct drm_connector *connector, int on) | |||
1360 | static bool | 1280 | static bool |
1361 | intel_sdvo_multifunc_encoder(struct intel_sdvo *intel_sdvo) | 1281 | intel_sdvo_multifunc_encoder(struct intel_sdvo *intel_sdvo) |
1362 | { | 1282 | { |
1363 | int caps = 0; | 1283 | /* Is there more than one type of output? */ |
1364 | 1284 | int caps = intel_sdvo->caps.output_flags & 0xf; | |
1365 | if (intel_sdvo->caps.output_flags & | 1285 | return caps & -caps; |
1366 | (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) | ||
1367 | caps++; | ||
1368 | if (intel_sdvo->caps.output_flags & | ||
1369 | (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)) | ||
1370 | caps++; | ||
1371 | if (intel_sdvo->caps.output_flags & | ||
1372 | (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_SVID1)) | ||
1373 | caps++; | ||
1374 | if (intel_sdvo->caps.output_flags & | ||
1375 | (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_CVBS1)) | ||
1376 | caps++; | ||
1377 | if (intel_sdvo->caps.output_flags & | ||
1378 | (SDVO_OUTPUT_YPRPB0 | SDVO_OUTPUT_YPRPB1)) | ||
1379 | caps++; | ||
1380 | |||
1381 | if (intel_sdvo->caps.output_flags & | ||
1382 | (SDVO_OUTPUT_SCART0 | SDVO_OUTPUT_SCART1)) | ||
1383 | caps++; | ||
1384 | |||
1385 | if (intel_sdvo->caps.output_flags & | ||
1386 | (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)) | ||
1387 | caps++; | ||
1388 | |||
1389 | return (caps > 1); | ||
1390 | } | 1286 | } |
1391 | 1287 | ||
1392 | static struct drm_connector * | 1288 | static struct edid * |
1393 | intel_find_analog_connector(struct drm_device *dev) | 1289 | intel_sdvo_get_edid(struct drm_connector *connector) |
1394 | { | 1290 | { |
1395 | struct drm_connector *connector; | 1291 | struct intel_sdvo *sdvo = intel_attached_sdvo(connector); |
1396 | struct drm_encoder *encoder; | 1292 | return drm_get_edid(connector, &sdvo->ddc); |
1397 | struct intel_sdvo *intel_sdvo; | ||
1398 | |||
1399 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { | ||
1400 | intel_sdvo = enc_to_intel_sdvo(encoder); | ||
1401 | if (intel_sdvo->base.type == INTEL_OUTPUT_ANALOG) { | ||
1402 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | ||
1403 | if (encoder == intel_attached_encoder(connector)) | ||
1404 | return connector; | ||
1405 | } | ||
1406 | } | ||
1407 | } | ||
1408 | return NULL; | ||
1409 | } | 1293 | } |
1410 | 1294 | ||
1411 | static int | 1295 | /* Mac mini hack -- use the same DDC as the analog connector */ |
1412 | intel_analog_is_connected(struct drm_device *dev) | 1296 | static struct edid * |
1297 | intel_sdvo_get_analog_edid(struct drm_connector *connector) | ||
1413 | { | 1298 | { |
1414 | struct drm_connector *analog_connector; | 1299 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
1415 | |||
1416 | analog_connector = intel_find_analog_connector(dev); | ||
1417 | if (!analog_connector) | ||
1418 | return false; | ||
1419 | |||
1420 | if (analog_connector->funcs->detect(analog_connector, false) == | ||
1421 | connector_status_disconnected) | ||
1422 | return false; | ||
1423 | 1300 | ||
1424 | return true; | 1301 | return drm_get_edid(connector, |
1302 | &dev_priv->gmbus[dev_priv->crt_ddc_pin].adapter); | ||
1425 | } | 1303 | } |
1426 | 1304 | ||
1427 | enum drm_connector_status | 1305 | enum drm_connector_status |
1428 | intel_sdvo_hdmi_sink_detect(struct drm_connector *connector) | 1306 | intel_sdvo_hdmi_sink_detect(struct drm_connector *connector) |
1429 | { | 1307 | { |
1430 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1308 | struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector); |
1431 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | 1309 | enum drm_connector_status status; |
1432 | struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector); | 1310 | struct edid *edid; |
1433 | enum drm_connector_status status = connector_status_connected; | ||
1434 | struct edid *edid = NULL; | ||
1435 | 1311 | ||
1436 | edid = drm_get_edid(connector, intel_sdvo->base.ddc_bus); | 1312 | edid = intel_sdvo_get_edid(connector); |
1437 | 1313 | ||
1438 | /* This is only applied to SDVO cards with multiple outputs */ | ||
1439 | if (edid == NULL && intel_sdvo_multifunc_encoder(intel_sdvo)) { | 1314 | if (edid == NULL && intel_sdvo_multifunc_encoder(intel_sdvo)) { |
1440 | uint8_t saved_ddc, temp_ddc; | 1315 | u8 ddc, saved_ddc = intel_sdvo->ddc_bus; |
1441 | saved_ddc = intel_sdvo->ddc_bus; | 1316 | |
1442 | temp_ddc = intel_sdvo->ddc_bus >> 1; | ||
1443 | /* | 1317 | /* |
1444 | * Don't use the 1 as the argument of DDC bus switch to get | 1318 | * Don't use the 1 as the argument of DDC bus switch to get |
1445 | * the EDID. It is used for SDVO SPD ROM. | 1319 | * the EDID. It is used for SDVO SPD ROM. |
1446 | */ | 1320 | */ |
1447 | while(temp_ddc > 1) { | 1321 | for (ddc = intel_sdvo->ddc_bus >> 1; ddc > 1; ddc >>= 1) { |
1448 | intel_sdvo->ddc_bus = temp_ddc; | 1322 | intel_sdvo->ddc_bus = ddc; |
1449 | edid = drm_get_edid(connector, intel_sdvo->base.ddc_bus); | 1323 | edid = intel_sdvo_get_edid(connector); |
1450 | if (edid) { | 1324 | 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; | 1325 | break; |
1457 | } | ||
1458 | temp_ddc >>= 1; | ||
1459 | } | 1326 | } |
1327 | /* | ||
1328 | * If we found the EDID on the other bus, | ||
1329 | * assume that is the correct DDC bus. | ||
1330 | */ | ||
1460 | if (edid == NULL) | 1331 | if (edid == NULL) |
1461 | intel_sdvo->ddc_bus = saved_ddc; | 1332 | intel_sdvo->ddc_bus = saved_ddc; |
1462 | } | 1333 | } |
1463 | /* when there is no edid and no monitor is connected with VGA | 1334 | |
1464 | * port, try to use the CRT ddc to read the EDID for DVI-connector | 1335 | /* |
1336 | * When there is no edid and no monitor is connected with VGA | ||
1337 | * port, try to use the CRT ddc to read the EDID for DVI-connector. | ||
1465 | */ | 1338 | */ |
1466 | if (edid == NULL && intel_sdvo->analog_ddc_bus && | 1339 | if (edid == NULL) |
1467 | !intel_analog_is_connected(connector->dev)) | 1340 | edid = intel_sdvo_get_analog_edid(connector); |
1468 | edid = drm_get_edid(connector, intel_sdvo->analog_ddc_bus); | ||
1469 | 1341 | ||
1342 | status = connector_status_unknown; | ||
1470 | if (edid != NULL) { | 1343 | 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 */ | 1344 | /* DDC bus is shared, match EDID to connector type */ |
1475 | if (is_digital && need_digital) | 1345 | if (edid->input & DRM_EDID_INPUT_DIGITAL) { |
1476 | intel_sdvo->is_hdmi = drm_detect_hdmi_monitor(edid); | 1346 | status = connector_status_connected; |
1477 | else if (is_digital != need_digital) | 1347 | if (intel_sdvo->is_hdmi) { |
1348 | intel_sdvo->has_hdmi_monitor = drm_detect_hdmi_monitor(edid); | ||
1349 | intel_sdvo->has_hdmi_audio = drm_detect_monitor_audio(edid); | ||
1350 | } | ||
1351 | } else | ||
1478 | status = connector_status_disconnected; | 1352 | status = connector_status_disconnected; |
1479 | |||
1480 | connector->display_info.raw_edid = NULL; | 1353 | connector->display_info.raw_edid = NULL; |
1481 | } else | 1354 | kfree(edid); |
1482 | status = connector_status_disconnected; | 1355 | } |
1483 | 1356 | ||
1484 | kfree(edid); | 1357 | if (status == connector_status_connected) { |
1358 | struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector); | ||
1359 | if (intel_sdvo_connector->force_audio) | ||
1360 | intel_sdvo->has_hdmi_audio = intel_sdvo_connector->force_audio > 0; | ||
1361 | } | ||
1485 | 1362 | ||
1486 | return status; | 1363 | return status; |
1487 | } | 1364 | } |
@@ -1490,34 +1367,55 @@ static enum drm_connector_status | |||
1490 | intel_sdvo_detect(struct drm_connector *connector, bool force) | 1367 | intel_sdvo_detect(struct drm_connector *connector, bool force) |
1491 | { | 1368 | { |
1492 | uint16_t response; | 1369 | uint16_t response; |
1493 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1370 | 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); | 1371 | struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector); |
1496 | enum drm_connector_status ret; | 1372 | enum drm_connector_status ret; |
1497 | 1373 | ||
1498 | if (!intel_sdvo_write_cmd(intel_sdvo, | 1374 | if (!intel_sdvo_write_cmd(intel_sdvo, |
1499 | SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0)) | 1375 | SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0)) |
1500 | return connector_status_unknown; | 1376 | return connector_status_unknown; |
1501 | if (intel_sdvo->is_tv) { | 1377 | |
1502 | /* add 30ms delay when the output type is SDVO-TV */ | 1378 | /* add 30ms delay when the output type might be TV */ |
1379 | if (intel_sdvo->caps.output_flags & | ||
1380 | (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_CVBS0)) | ||
1503 | mdelay(30); | 1381 | mdelay(30); |
1504 | } | 1382 | |
1505 | if (!intel_sdvo_read_response(intel_sdvo, &response, 2)) | 1383 | if (!intel_sdvo_read_response(intel_sdvo, &response, 2)) |
1506 | return connector_status_unknown; | 1384 | return connector_status_unknown; |
1507 | 1385 | ||
1508 | DRM_DEBUG_KMS("SDVO response %d %d\n", response & 0xff, response >> 8); | 1386 | DRM_DEBUG_KMS("SDVO response %d %d [%x]\n", |
1387 | response & 0xff, response >> 8, | ||
1388 | intel_sdvo_connector->output_flag); | ||
1509 | 1389 | ||
1510 | if (response == 0) | 1390 | if (response == 0) |
1511 | return connector_status_disconnected; | 1391 | return connector_status_disconnected; |
1512 | 1392 | ||
1513 | intel_sdvo->attached_output = response; | 1393 | intel_sdvo->attached_output = response; |
1514 | 1394 | ||
1395 | intel_sdvo->has_hdmi_monitor = false; | ||
1396 | intel_sdvo->has_hdmi_audio = false; | ||
1397 | |||
1515 | if ((intel_sdvo_connector->output_flag & response) == 0) | 1398 | if ((intel_sdvo_connector->output_flag & response) == 0) |
1516 | ret = connector_status_disconnected; | 1399 | ret = connector_status_disconnected; |
1517 | else if (response & SDVO_TMDS_MASK) | 1400 | else if (IS_TMDS(intel_sdvo_connector)) |
1518 | ret = intel_sdvo_hdmi_sink_detect(connector); | 1401 | ret = intel_sdvo_hdmi_sink_detect(connector); |
1519 | else | 1402 | else { |
1520 | ret = connector_status_connected; | 1403 | struct edid *edid; |
1404 | |||
1405 | /* if we have an edid check it matches the connection */ | ||
1406 | edid = intel_sdvo_get_edid(connector); | ||
1407 | if (edid == NULL) | ||
1408 | edid = intel_sdvo_get_analog_edid(connector); | ||
1409 | if (edid != NULL) { | ||
1410 | if (edid->input & DRM_EDID_INPUT_DIGITAL) | ||
1411 | ret = connector_status_disconnected; | ||
1412 | else | ||
1413 | ret = connector_status_connected; | ||
1414 | connector->display_info.raw_edid = NULL; | ||
1415 | kfree(edid); | ||
1416 | } else | ||
1417 | ret = connector_status_connected; | ||
1418 | } | ||
1521 | 1419 | ||
1522 | /* May update encoder flag for like clock for SDVO TV, etc.*/ | 1420 | /* May update encoder flag for like clock for SDVO TV, etc.*/ |
1523 | if (ret == connector_status_connected) { | 1421 | if (ret == connector_status_connected) { |
@@ -1538,12 +1436,10 @@ intel_sdvo_detect(struct drm_connector *connector, bool force) | |||
1538 | 1436 | ||
1539 | static void intel_sdvo_get_ddc_modes(struct drm_connector *connector) | 1437 | static void intel_sdvo_get_ddc_modes(struct drm_connector *connector) |
1540 | { | 1438 | { |
1541 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1439 | struct edid *edid; |
1542 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | ||
1543 | int num_modes; | ||
1544 | 1440 | ||
1545 | /* set the bus switch and get the modes */ | 1441 | /* set the bus switch and get the modes */ |
1546 | num_modes = intel_ddc_get_modes(connector, intel_sdvo->base.ddc_bus); | 1442 | edid = intel_sdvo_get_edid(connector); |
1547 | 1443 | ||
1548 | /* | 1444 | /* |
1549 | * Mac mini hack. On this device, the DVI-I connector shares one DDC | 1445 | * Mac mini hack. On this device, the DVI-I connector shares one DDC |
@@ -1551,12 +1447,21 @@ static void intel_sdvo_get_ddc_modes(struct drm_connector *connector) | |||
1551 | * DDC fails, check to see if the analog output is disconnected, in | 1447 | * DDC fails, check to see if the analog output is disconnected, in |
1552 | * which case we'll look there for the digital DDC data. | 1448 | * which case we'll look there for the digital DDC data. |
1553 | */ | 1449 | */ |
1554 | if (num_modes == 0 && | 1450 | if (edid == NULL) |
1555 | intel_sdvo->analog_ddc_bus && | 1451 | edid = intel_sdvo_get_analog_edid(connector); |
1556 | !intel_analog_is_connected(connector->dev)) { | 1452 | |
1557 | /* Switch to the analog ddc bus and try that | 1453 | if (edid != NULL) { |
1558 | */ | 1454 | struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector); |
1559 | (void) intel_ddc_get_modes(connector, intel_sdvo->analog_ddc_bus); | 1455 | bool monitor_is_digital = !!(edid->input & DRM_EDID_INPUT_DIGITAL); |
1456 | bool connector_is_digital = !!IS_TMDS(intel_sdvo_connector); | ||
1457 | |||
1458 | if (connector_is_digital == monitor_is_digital) { | ||
1459 | drm_mode_connector_update_edid_property(connector, edid); | ||
1460 | drm_add_edid_modes(connector, edid); | ||
1461 | } | ||
1462 | |||
1463 | connector->display_info.raw_edid = NULL; | ||
1464 | kfree(edid); | ||
1560 | } | 1465 | } |
1561 | } | 1466 | } |
1562 | 1467 | ||
@@ -1565,7 +1470,7 @@ static void intel_sdvo_get_ddc_modes(struct drm_connector *connector) | |||
1565 | * Note! This is in reply order (see loop in get_tv_modes). | 1470 | * Note! This is in reply order (see loop in get_tv_modes). |
1566 | * XXX: all 60Hz refresh? | 1471 | * XXX: all 60Hz refresh? |
1567 | */ | 1472 | */ |
1568 | struct drm_display_mode sdvo_tv_modes[] = { | 1473 | static const struct drm_display_mode sdvo_tv_modes[] = { |
1569 | { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384, | 1474 | { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384, |
1570 | 416, 0, 200, 201, 232, 233, 0, | 1475 | 416, 0, 200, 201, 232, 233, 0, |
1571 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | 1476 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
@@ -1627,8 +1532,7 @@ struct drm_display_mode sdvo_tv_modes[] = { | |||
1627 | 1532 | ||
1628 | static void intel_sdvo_get_tv_modes(struct drm_connector *connector) | 1533 | static void intel_sdvo_get_tv_modes(struct drm_connector *connector) |
1629 | { | 1534 | { |
1630 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1535 | 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; | 1536 | struct intel_sdvo_sdtv_resolution_request tv_res; |
1633 | uint32_t reply = 0, format_map = 0; | 1537 | uint32_t reply = 0, format_map = 0; |
1634 | int i; | 1538 | int i; |
@@ -1644,7 +1548,8 @@ static void intel_sdvo_get_tv_modes(struct drm_connector *connector) | |||
1644 | return; | 1548 | return; |
1645 | 1549 | ||
1646 | BUILD_BUG_ON(sizeof(tv_res) != 3); | 1550 | BUILD_BUG_ON(sizeof(tv_res) != 3); |
1647 | if (!intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT, | 1551 | if (!intel_sdvo_write_cmd(intel_sdvo, |
1552 | SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT, | ||
1648 | &tv_res, sizeof(tv_res))) | 1553 | &tv_res, sizeof(tv_res))) |
1649 | return; | 1554 | return; |
1650 | if (!intel_sdvo_read_response(intel_sdvo, &reply, 3)) | 1555 | if (!intel_sdvo_read_response(intel_sdvo, &reply, 3)) |
@@ -1662,8 +1567,7 @@ static void intel_sdvo_get_tv_modes(struct drm_connector *connector) | |||
1662 | 1567 | ||
1663 | static void intel_sdvo_get_lvds_modes(struct drm_connector *connector) | 1568 | static void intel_sdvo_get_lvds_modes(struct drm_connector *connector) |
1664 | { | 1569 | { |
1665 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1570 | 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; | 1571 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
1668 | struct drm_display_mode *newmode; | 1572 | struct drm_display_mode *newmode; |
1669 | 1573 | ||
@@ -1672,7 +1576,7 @@ static void intel_sdvo_get_lvds_modes(struct drm_connector *connector) | |||
1672 | * Assume that the preferred modes are | 1576 | * Assume that the preferred modes are |
1673 | * arranged in priority order. | 1577 | * arranged in priority order. |
1674 | */ | 1578 | */ |
1675 | intel_ddc_get_modes(connector, intel_sdvo->base.ddc_bus); | 1579 | intel_ddc_get_modes(connector, intel_sdvo->i2c); |
1676 | if (list_empty(&connector->probed_modes) == false) | 1580 | if (list_empty(&connector->probed_modes) == false) |
1677 | goto end; | 1581 | goto end; |
1678 | 1582 | ||
@@ -1693,6 +1597,10 @@ end: | |||
1693 | if (newmode->type & DRM_MODE_TYPE_PREFERRED) { | 1597 | if (newmode->type & DRM_MODE_TYPE_PREFERRED) { |
1694 | intel_sdvo->sdvo_lvds_fixed_mode = | 1598 | intel_sdvo->sdvo_lvds_fixed_mode = |
1695 | drm_mode_duplicate(connector->dev, newmode); | 1599 | drm_mode_duplicate(connector->dev, newmode); |
1600 | |||
1601 | drm_mode_set_crtcinfo(intel_sdvo->sdvo_lvds_fixed_mode, | ||
1602 | 0); | ||
1603 | |||
1696 | intel_sdvo->is_lvds = true; | 1604 | intel_sdvo->is_lvds = true; |
1697 | break; | 1605 | break; |
1698 | } | 1606 | } |
@@ -1770,14 +1678,30 @@ static void intel_sdvo_destroy(struct drm_connector *connector) | |||
1770 | kfree(connector); | 1678 | kfree(connector); |
1771 | } | 1679 | } |
1772 | 1680 | ||
1681 | static bool intel_sdvo_detect_hdmi_audio(struct drm_connector *connector) | ||
1682 | { | ||
1683 | struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector); | ||
1684 | struct edid *edid; | ||
1685 | bool has_audio = false; | ||
1686 | |||
1687 | if (!intel_sdvo->is_hdmi) | ||
1688 | return false; | ||
1689 | |||
1690 | edid = intel_sdvo_get_edid(connector); | ||
1691 | if (edid != NULL && edid->input & DRM_EDID_INPUT_DIGITAL) | ||
1692 | has_audio = drm_detect_monitor_audio(edid); | ||
1693 | |||
1694 | return has_audio; | ||
1695 | } | ||
1696 | |||
1773 | static int | 1697 | static int |
1774 | intel_sdvo_set_property(struct drm_connector *connector, | 1698 | intel_sdvo_set_property(struct drm_connector *connector, |
1775 | struct drm_property *property, | 1699 | struct drm_property *property, |
1776 | uint64_t val) | 1700 | uint64_t val) |
1777 | { | 1701 | { |
1778 | struct drm_encoder *encoder = intel_attached_encoder(connector); | 1702 | 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); | 1703 | struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector); |
1704 | struct drm_i915_private *dev_priv = connector->dev->dev_private; | ||
1781 | uint16_t temp_value; | 1705 | uint16_t temp_value; |
1782 | uint8_t cmd; | 1706 | uint8_t cmd; |
1783 | int ret; | 1707 | int ret; |
@@ -1786,6 +1710,35 @@ intel_sdvo_set_property(struct drm_connector *connector, | |||
1786 | if (ret) | 1710 | if (ret) |
1787 | return ret; | 1711 | return ret; |
1788 | 1712 | ||
1713 | if (property == dev_priv->force_audio_property) { | ||
1714 | int i = val; | ||
1715 | bool has_audio; | ||
1716 | |||
1717 | if (i == intel_sdvo_connector->force_audio) | ||
1718 | return 0; | ||
1719 | |||
1720 | intel_sdvo_connector->force_audio = i; | ||
1721 | |||
1722 | if (i == 0) | ||
1723 | has_audio = intel_sdvo_detect_hdmi_audio(connector); | ||
1724 | else | ||
1725 | has_audio = i > 0; | ||
1726 | |||
1727 | if (has_audio == intel_sdvo->has_hdmi_audio) | ||
1728 | return 0; | ||
1729 | |||
1730 | intel_sdvo->has_hdmi_audio = has_audio; | ||
1731 | goto done; | ||
1732 | } | ||
1733 | |||
1734 | if (property == dev_priv->broadcast_rgb_property) { | ||
1735 | if (val == !!intel_sdvo->color_range) | ||
1736 | return 0; | ||
1737 | |||
1738 | intel_sdvo->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0; | ||
1739 | goto done; | ||
1740 | } | ||
1741 | |||
1789 | #define CHECK_PROPERTY(name, NAME) \ | 1742 | #define CHECK_PROPERTY(name, NAME) \ |
1790 | if (intel_sdvo_connector->name == property) { \ | 1743 | if (intel_sdvo_connector->name == property) { \ |
1791 | if (intel_sdvo_connector->cur_##name == temp_value) return 0; \ | 1744 | if (intel_sdvo_connector->cur_##name == temp_value) return 0; \ |
@@ -1879,9 +1832,8 @@ set_value: | |||
1879 | 1832 | ||
1880 | 1833 | ||
1881 | done: | 1834 | done: |
1882 | if (encoder->crtc) { | 1835 | if (intel_sdvo->base.base.crtc) { |
1883 | struct drm_crtc *crtc = encoder->crtc; | 1836 | struct drm_crtc *crtc = intel_sdvo->base.base.crtc; |
1884 | |||
1885 | drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x, | 1837 | drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x, |
1886 | crtc->y, crtc->fb); | 1838 | crtc->y, crtc->fb); |
1887 | } | 1839 | } |
@@ -1909,20 +1861,18 @@ static const struct drm_connector_funcs intel_sdvo_connector_funcs = { | |||
1909 | static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = { | 1861 | static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = { |
1910 | .get_modes = intel_sdvo_get_modes, | 1862 | .get_modes = intel_sdvo_get_modes, |
1911 | .mode_valid = intel_sdvo_mode_valid, | 1863 | .mode_valid = intel_sdvo_mode_valid, |
1912 | .best_encoder = intel_attached_encoder, | 1864 | .best_encoder = intel_best_encoder, |
1913 | }; | 1865 | }; |
1914 | 1866 | ||
1915 | static void intel_sdvo_enc_destroy(struct drm_encoder *encoder) | 1867 | static void intel_sdvo_enc_destroy(struct drm_encoder *encoder) |
1916 | { | 1868 | { |
1917 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | 1869 | 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 | 1870 | ||
1922 | if (intel_sdvo->sdvo_lvds_fixed_mode != NULL) | 1871 | if (intel_sdvo->sdvo_lvds_fixed_mode != NULL) |
1923 | drm_mode_destroy(encoder->dev, | 1872 | drm_mode_destroy(encoder->dev, |
1924 | intel_sdvo->sdvo_lvds_fixed_mode); | 1873 | intel_sdvo->sdvo_lvds_fixed_mode); |
1925 | 1874 | ||
1875 | i2c_del_adapter(&intel_sdvo->ddc); | ||
1926 | intel_encoder_destroy(encoder); | 1876 | intel_encoder_destroy(encoder); |
1927 | } | 1877 | } |
1928 | 1878 | ||
@@ -1990,54 +1940,39 @@ intel_sdvo_select_ddc_bus(struct drm_i915_private *dev_priv, | |||
1990 | intel_sdvo_guess_ddc_bus(sdvo); | 1940 | intel_sdvo_guess_ddc_bus(sdvo); |
1991 | } | 1941 | } |
1992 | 1942 | ||
1993 | static bool | 1943 | static void |
1994 | intel_sdvo_get_digital_encoding_mode(struct intel_sdvo *intel_sdvo, int device) | 1944 | intel_sdvo_select_i2c_bus(struct drm_i915_private *dev_priv, |
1945 | struct intel_sdvo *sdvo, u32 reg) | ||
1995 | { | 1946 | { |
1996 | return intel_sdvo_set_target_output(intel_sdvo, | 1947 | struct sdvo_device_mapping *mapping; |
1997 | device == 0 ? SDVO_OUTPUT_TMDS0 : SDVO_OUTPUT_TMDS1) && | 1948 | u8 pin, speed; |
1998 | intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_ENCODE, | ||
1999 | &intel_sdvo->is_hdmi, 1); | ||
2000 | } | ||
2001 | 1949 | ||
2002 | static struct intel_sdvo * | 1950 | if (IS_SDVOB(reg)) |
2003 | intel_sdvo_chan_to_intel_sdvo(struct intel_i2c_chan *chan) | 1951 | mapping = &dev_priv->sdvo_mappings[0]; |
2004 | { | 1952 | else |
2005 | struct drm_device *dev = chan->drm_dev; | 1953 | mapping = &dev_priv->sdvo_mappings[1]; |
2006 | struct drm_encoder *encoder; | ||
2007 | 1954 | ||
2008 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { | 1955 | pin = GMBUS_PORT_DPB; |
2009 | struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder); | 1956 | speed = GMBUS_RATE_1MHZ >> 8; |
2010 | if (intel_sdvo->base.ddc_bus == &chan->adapter) | 1957 | if (mapping->initialized) { |
2011 | return intel_sdvo; | 1958 | pin = mapping->i2c_pin; |
1959 | speed = mapping->i2c_speed; | ||
2012 | } | 1960 | } |
2013 | 1961 | ||
2014 | return NULL; | 1962 | if (pin < GMBUS_NUM_PORTS) { |
1963 | sdvo->i2c = &dev_priv->gmbus[pin].adapter; | ||
1964 | intel_gmbus_set_speed(sdvo->i2c, speed); | ||
1965 | intel_gmbus_force_bit(sdvo->i2c, true); | ||
1966 | } else | ||
1967 | sdvo->i2c = &dev_priv->gmbus[GMBUS_PORT_DPB].adapter; | ||
2015 | } | 1968 | } |
2016 | 1969 | ||
2017 | static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap, | 1970 | static bool |
2018 | struct i2c_msg msgs[], int num) | 1971 | intel_sdvo_is_hdmi_connector(struct intel_sdvo *intel_sdvo, int device) |
2019 | { | 1972 | { |
2020 | struct intel_sdvo *intel_sdvo; | 1973 | return intel_sdvo_check_supp_encode(intel_sdvo); |
2021 | struct i2c_algo_bit_data *algo_data; | ||
2022 | const struct i2c_algorithm *algo; | ||
2023 | |||
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 | } | 1974 | } |
2036 | 1975 | ||
2037 | static struct i2c_algorithm intel_sdvo_i2c_bit_algo = { | ||
2038 | .master_xfer = intel_sdvo_master_xfer, | ||
2039 | }; | ||
2040 | |||
2041 | static u8 | 1976 | static u8 |
2042 | intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg) | 1977 | intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg) |
2043 | { | 1978 | { |
@@ -2076,26 +2011,39 @@ intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg) | |||
2076 | } | 2011 | } |
2077 | 2012 | ||
2078 | static void | 2013 | static void |
2079 | intel_sdvo_connector_init(struct drm_encoder *encoder, | 2014 | intel_sdvo_connector_init(struct intel_sdvo_connector *connector, |
2080 | struct drm_connector *connector) | 2015 | struct intel_sdvo *encoder) |
2081 | { | 2016 | { |
2082 | drm_connector_init(encoder->dev, connector, &intel_sdvo_connector_funcs, | 2017 | drm_connector_init(encoder->base.base.dev, |
2083 | connector->connector_type); | 2018 | &connector->base.base, |
2019 | &intel_sdvo_connector_funcs, | ||
2020 | connector->base.base.connector_type); | ||
2084 | 2021 | ||
2085 | drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs); | 2022 | drm_connector_helper_add(&connector->base.base, |
2023 | &intel_sdvo_connector_helper_funcs); | ||
2086 | 2024 | ||
2087 | connector->interlace_allowed = 0; | 2025 | connector->base.base.interlace_allowed = 0; |
2088 | connector->doublescan_allowed = 0; | 2026 | connector->base.base.doublescan_allowed = 0; |
2089 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; | 2027 | connector->base.base.display_info.subpixel_order = SubPixelHorizontalRGB; |
2090 | 2028 | ||
2091 | drm_mode_connector_attach_encoder(connector, encoder); | 2029 | intel_connector_attach_encoder(&connector->base, &encoder->base); |
2092 | drm_sysfs_connector_add(connector); | 2030 | drm_sysfs_connector_add(&connector->base.base); |
2031 | } | ||
2032 | |||
2033 | static void | ||
2034 | intel_sdvo_add_hdmi_properties(struct intel_sdvo_connector *connector) | ||
2035 | { | ||
2036 | struct drm_device *dev = connector->base.base.dev; | ||
2037 | |||
2038 | intel_attach_force_audio_property(&connector->base.base); | ||
2039 | if (INTEL_INFO(dev)->gen >= 4 && IS_MOBILE(dev)) | ||
2040 | intel_attach_broadcast_rgb_property(&connector->base.base); | ||
2093 | } | 2041 | } |
2094 | 2042 | ||
2095 | static bool | 2043 | static bool |
2096 | intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device) | 2044 | intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device) |
2097 | { | 2045 | { |
2098 | struct drm_encoder *encoder = &intel_sdvo->base.enc; | 2046 | struct drm_encoder *encoder = &intel_sdvo->base.base; |
2099 | struct drm_connector *connector; | 2047 | struct drm_connector *connector; |
2100 | struct intel_connector *intel_connector; | 2048 | struct intel_connector *intel_connector; |
2101 | struct intel_sdvo_connector *intel_sdvo_connector; | 2049 | struct intel_sdvo_connector *intel_sdvo_connector; |
@@ -2118,19 +2066,16 @@ intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device) | |||
2118 | encoder->encoder_type = DRM_MODE_ENCODER_TMDS; | 2066 | encoder->encoder_type = DRM_MODE_ENCODER_TMDS; |
2119 | connector->connector_type = DRM_MODE_CONNECTOR_DVID; | 2067 | connector->connector_type = DRM_MODE_CONNECTOR_DVID; |
2120 | 2068 | ||
2121 | if (intel_sdvo_get_supp_encode(intel_sdvo, &intel_sdvo->encode) | 2069 | if (intel_sdvo_is_hdmi_connector(intel_sdvo, device)) { |
2122 | && intel_sdvo_get_digital_encoding_mode(intel_sdvo, device) | ||
2123 | && intel_sdvo->is_hdmi) { | ||
2124 | /* enable hdmi encoding mode if supported */ | ||
2125 | intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_HDMI); | ||
2126 | intel_sdvo_set_colorimetry(intel_sdvo, | ||
2127 | SDVO_COLORIMETRY_RGB256); | ||
2128 | connector->connector_type = DRM_MODE_CONNECTOR_HDMIA; | 2070 | connector->connector_type = DRM_MODE_CONNECTOR_HDMIA; |
2071 | intel_sdvo->is_hdmi = true; | ||
2129 | } | 2072 | } |
2130 | intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) | | 2073 | intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) | |
2131 | (1 << INTEL_ANALOG_CLONE_BIT)); | 2074 | (1 << INTEL_ANALOG_CLONE_BIT)); |
2132 | 2075 | ||
2133 | intel_sdvo_connector_init(encoder, connector); | 2076 | intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo); |
2077 | if (intel_sdvo->is_hdmi) | ||
2078 | intel_sdvo_add_hdmi_properties(intel_sdvo_connector); | ||
2134 | 2079 | ||
2135 | return true; | 2080 | return true; |
2136 | } | 2081 | } |
@@ -2138,36 +2083,36 @@ intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device) | |||
2138 | static bool | 2083 | static bool |
2139 | intel_sdvo_tv_init(struct intel_sdvo *intel_sdvo, int type) | 2084 | intel_sdvo_tv_init(struct intel_sdvo *intel_sdvo, int type) |
2140 | { | 2085 | { |
2141 | struct drm_encoder *encoder = &intel_sdvo->base.enc; | 2086 | struct drm_encoder *encoder = &intel_sdvo->base.base; |
2142 | struct drm_connector *connector; | 2087 | struct drm_connector *connector; |
2143 | struct intel_connector *intel_connector; | 2088 | struct intel_connector *intel_connector; |
2144 | struct intel_sdvo_connector *intel_sdvo_connector; | 2089 | struct intel_sdvo_connector *intel_sdvo_connector; |
2145 | 2090 | ||
2146 | intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); | 2091 | intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); |
2147 | if (!intel_sdvo_connector) | 2092 | if (!intel_sdvo_connector) |
2148 | return false; | 2093 | return false; |
2149 | 2094 | ||
2150 | intel_connector = &intel_sdvo_connector->base; | 2095 | intel_connector = &intel_sdvo_connector->base; |
2151 | connector = &intel_connector->base; | 2096 | connector = &intel_connector->base; |
2152 | encoder->encoder_type = DRM_MODE_ENCODER_TVDAC; | 2097 | encoder->encoder_type = DRM_MODE_ENCODER_TVDAC; |
2153 | connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO; | 2098 | connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO; |
2154 | 2099 | ||
2155 | intel_sdvo->controlled_output |= type; | 2100 | intel_sdvo->controlled_output |= type; |
2156 | intel_sdvo_connector->output_flag = type; | 2101 | intel_sdvo_connector->output_flag = type; |
2157 | 2102 | ||
2158 | intel_sdvo->is_tv = true; | 2103 | intel_sdvo->is_tv = true; |
2159 | intel_sdvo->base.needs_tv_clock = true; | 2104 | intel_sdvo->base.needs_tv_clock = true; |
2160 | intel_sdvo->base.clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT; | 2105 | intel_sdvo->base.clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT; |
2161 | 2106 | ||
2162 | intel_sdvo_connector_init(encoder, connector); | 2107 | intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo); |
2163 | 2108 | ||
2164 | if (!intel_sdvo_tv_create_property(intel_sdvo, intel_sdvo_connector, type)) | 2109 | if (!intel_sdvo_tv_create_property(intel_sdvo, intel_sdvo_connector, type)) |
2165 | goto err; | 2110 | goto err; |
2166 | 2111 | ||
2167 | if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector)) | 2112 | if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector)) |
2168 | goto err; | 2113 | goto err; |
2169 | 2114 | ||
2170 | return true; | 2115 | return true; |
2171 | 2116 | ||
2172 | err: | 2117 | err: |
2173 | intel_sdvo_destroy(connector); | 2118 | intel_sdvo_destroy(connector); |
@@ -2177,43 +2122,44 @@ err: | |||
2177 | static bool | 2122 | static bool |
2178 | intel_sdvo_analog_init(struct intel_sdvo *intel_sdvo, int device) | 2123 | intel_sdvo_analog_init(struct intel_sdvo *intel_sdvo, int device) |
2179 | { | 2124 | { |
2180 | struct drm_encoder *encoder = &intel_sdvo->base.enc; | 2125 | struct drm_encoder *encoder = &intel_sdvo->base.base; |
2181 | struct drm_connector *connector; | 2126 | struct drm_connector *connector; |
2182 | struct intel_connector *intel_connector; | 2127 | struct intel_connector *intel_connector; |
2183 | struct intel_sdvo_connector *intel_sdvo_connector; | 2128 | struct intel_sdvo_connector *intel_sdvo_connector; |
2184 | 2129 | ||
2185 | intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); | 2130 | intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); |
2186 | if (!intel_sdvo_connector) | 2131 | if (!intel_sdvo_connector) |
2187 | return false; | 2132 | return false; |
2188 | 2133 | ||
2189 | intel_connector = &intel_sdvo_connector->base; | 2134 | intel_connector = &intel_sdvo_connector->base; |
2190 | connector = &intel_connector->base; | 2135 | connector = &intel_connector->base; |
2191 | connector->polled = DRM_CONNECTOR_POLL_CONNECT; | 2136 | connector->polled = DRM_CONNECTOR_POLL_CONNECT; |
2192 | encoder->encoder_type = DRM_MODE_ENCODER_DAC; | 2137 | encoder->encoder_type = DRM_MODE_ENCODER_DAC; |
2193 | connector->connector_type = DRM_MODE_CONNECTOR_VGA; | 2138 | connector->connector_type = DRM_MODE_CONNECTOR_VGA; |
2194 | 2139 | ||
2195 | if (device == 0) { | 2140 | if (device == 0) { |
2196 | intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB0; | 2141 | intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB0; |
2197 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB0; | 2142 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB0; |
2198 | } else if (device == 1) { | 2143 | } else if (device == 1) { |
2199 | intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB1; | 2144 | intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB1; |
2200 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB1; | 2145 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB1; |
2201 | } | 2146 | } |
2202 | 2147 | ||
2203 | intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) | | 2148 | intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) | |
2204 | (1 << INTEL_ANALOG_CLONE_BIT)); | 2149 | (1 << INTEL_ANALOG_CLONE_BIT)); |
2205 | 2150 | ||
2206 | intel_sdvo_connector_init(encoder, connector); | 2151 | intel_sdvo_connector_init(intel_sdvo_connector, |
2207 | return true; | 2152 | intel_sdvo); |
2153 | return true; | ||
2208 | } | 2154 | } |
2209 | 2155 | ||
2210 | static bool | 2156 | static bool |
2211 | intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device) | 2157 | intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device) |
2212 | { | 2158 | { |
2213 | struct drm_encoder *encoder = &intel_sdvo->base.enc; | 2159 | struct drm_encoder *encoder = &intel_sdvo->base.base; |
2214 | struct drm_connector *connector; | 2160 | struct drm_connector *connector; |
2215 | struct intel_connector *intel_connector; | 2161 | struct intel_connector *intel_connector; |
2216 | struct intel_sdvo_connector *intel_sdvo_connector; | 2162 | struct intel_sdvo_connector *intel_sdvo_connector; |
2217 | 2163 | ||
2218 | intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); | 2164 | intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); |
2219 | if (!intel_sdvo_connector) | 2165 | if (!intel_sdvo_connector) |
@@ -2221,22 +2167,22 @@ intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device) | |||
2221 | 2167 | ||
2222 | intel_connector = &intel_sdvo_connector->base; | 2168 | intel_connector = &intel_sdvo_connector->base; |
2223 | connector = &intel_connector->base; | 2169 | connector = &intel_connector->base; |
2224 | encoder->encoder_type = DRM_MODE_ENCODER_LVDS; | 2170 | encoder->encoder_type = DRM_MODE_ENCODER_LVDS; |
2225 | connector->connector_type = DRM_MODE_CONNECTOR_LVDS; | 2171 | connector->connector_type = DRM_MODE_CONNECTOR_LVDS; |
2226 | 2172 | ||
2227 | if (device == 0) { | 2173 | if (device == 0) { |
2228 | intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS0; | 2174 | intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS0; |
2229 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0; | 2175 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0; |
2230 | } else if (device == 1) { | 2176 | } else if (device == 1) { |
2231 | intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS1; | 2177 | intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS1; |
2232 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1; | 2178 | intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1; |
2233 | } | 2179 | } |
2234 | 2180 | ||
2235 | intel_sdvo->base.clone_mask = ((1 << INTEL_ANALOG_CLONE_BIT) | | 2181 | intel_sdvo->base.clone_mask = ((1 << INTEL_ANALOG_CLONE_BIT) | |
2236 | (1 << INTEL_SDVO_LVDS_CLONE_BIT)); | 2182 | (1 << INTEL_SDVO_LVDS_CLONE_BIT)); |
2237 | 2183 | ||
2238 | intel_sdvo_connector_init(encoder, connector); | 2184 | intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo); |
2239 | if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector)) | 2185 | if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector)) |
2240 | goto err; | 2186 | goto err; |
2241 | 2187 | ||
2242 | return true; | 2188 | return true; |
@@ -2307,13 +2253,14 @@ static bool intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo, | |||
2307 | struct intel_sdvo_connector *intel_sdvo_connector, | 2253 | struct intel_sdvo_connector *intel_sdvo_connector, |
2308 | int type) | 2254 | int type) |
2309 | { | 2255 | { |
2310 | struct drm_device *dev = intel_sdvo->base.enc.dev; | 2256 | struct drm_device *dev = intel_sdvo->base.base.dev; |
2311 | struct intel_sdvo_tv_format format; | 2257 | struct intel_sdvo_tv_format format; |
2312 | uint32_t format_map, i; | 2258 | uint32_t format_map, i; |
2313 | 2259 | ||
2314 | if (!intel_sdvo_set_target_output(intel_sdvo, type)) | 2260 | if (!intel_sdvo_set_target_output(intel_sdvo, type)) |
2315 | return false; | 2261 | return false; |
2316 | 2262 | ||
2263 | BUILD_BUG_ON(sizeof(format) != 6); | ||
2317 | if (!intel_sdvo_get_value(intel_sdvo, | 2264 | if (!intel_sdvo_get_value(intel_sdvo, |
2318 | SDVO_CMD_GET_SUPPORTED_TV_FORMATS, | 2265 | SDVO_CMD_GET_SUPPORTED_TV_FORMATS, |
2319 | &format, sizeof(format))) | 2266 | &format, sizeof(format))) |
@@ -2373,7 +2320,7 @@ intel_sdvo_create_enhance_property_tv(struct intel_sdvo *intel_sdvo, | |||
2373 | struct intel_sdvo_connector *intel_sdvo_connector, | 2320 | struct intel_sdvo_connector *intel_sdvo_connector, |
2374 | struct intel_sdvo_enhancements_reply enhancements) | 2321 | struct intel_sdvo_enhancements_reply enhancements) |
2375 | { | 2322 | { |
2376 | struct drm_device *dev = intel_sdvo->base.enc.dev; | 2323 | struct drm_device *dev = intel_sdvo->base.base.dev; |
2377 | struct drm_connector *connector = &intel_sdvo_connector->base.base; | 2324 | struct drm_connector *connector = &intel_sdvo_connector->base.base; |
2378 | uint16_t response, data_value[2]; | 2325 | uint16_t response, data_value[2]; |
2379 | 2326 | ||
@@ -2502,7 +2449,7 @@ intel_sdvo_create_enhance_property_lvds(struct intel_sdvo *intel_sdvo, | |||
2502 | struct intel_sdvo_connector *intel_sdvo_connector, | 2449 | struct intel_sdvo_connector *intel_sdvo_connector, |
2503 | struct intel_sdvo_enhancements_reply enhancements) | 2450 | struct intel_sdvo_enhancements_reply enhancements) |
2504 | { | 2451 | { |
2505 | struct drm_device *dev = intel_sdvo->base.enc.dev; | 2452 | struct drm_device *dev = intel_sdvo->base.base.dev; |
2506 | struct drm_connector *connector = &intel_sdvo_connector->base.base; | 2453 | struct drm_connector *connector = &intel_sdvo_connector->base.base; |
2507 | uint16_t response, data_value[2]; | 2454 | uint16_t response, data_value[2]; |
2508 | 2455 | ||
@@ -2520,6 +2467,8 @@ static bool intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo, | |||
2520 | uint16_t response; | 2467 | uint16_t response; |
2521 | } enhancements; | 2468 | } enhancements; |
2522 | 2469 | ||
2470 | BUILD_BUG_ON(sizeof(enhancements) != 2); | ||
2471 | |||
2523 | enhancements.response = 0; | 2472 | enhancements.response = 0; |
2524 | intel_sdvo_get_value(intel_sdvo, | 2473 | intel_sdvo_get_value(intel_sdvo, |
2525 | SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS, | 2474 | SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS, |
@@ -2535,7 +2484,43 @@ static bool intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo, | |||
2535 | return intel_sdvo_create_enhance_property_lvds(intel_sdvo, intel_sdvo_connector, enhancements.reply); | 2484 | return intel_sdvo_create_enhance_property_lvds(intel_sdvo, intel_sdvo_connector, enhancements.reply); |
2536 | else | 2485 | else |
2537 | return true; | 2486 | return true; |
2487 | } | ||
2538 | 2488 | ||
2489 | static int intel_sdvo_ddc_proxy_xfer(struct i2c_adapter *adapter, | ||
2490 | struct i2c_msg *msgs, | ||
2491 | int num) | ||
2492 | { | ||
2493 | struct intel_sdvo *sdvo = adapter->algo_data; | ||
2494 | |||
2495 | if (!intel_sdvo_set_control_bus_switch(sdvo, sdvo->ddc_bus)) | ||
2496 | return -EIO; | ||
2497 | |||
2498 | return sdvo->i2c->algo->master_xfer(sdvo->i2c, msgs, num); | ||
2499 | } | ||
2500 | |||
2501 | static u32 intel_sdvo_ddc_proxy_func(struct i2c_adapter *adapter) | ||
2502 | { | ||
2503 | struct intel_sdvo *sdvo = adapter->algo_data; | ||
2504 | return sdvo->i2c->algo->functionality(sdvo->i2c); | ||
2505 | } | ||
2506 | |||
2507 | static const struct i2c_algorithm intel_sdvo_ddc_proxy = { | ||
2508 | .master_xfer = intel_sdvo_ddc_proxy_xfer, | ||
2509 | .functionality = intel_sdvo_ddc_proxy_func | ||
2510 | }; | ||
2511 | |||
2512 | static bool | ||
2513 | intel_sdvo_init_ddc_proxy(struct intel_sdvo *sdvo, | ||
2514 | struct drm_device *dev) | ||
2515 | { | ||
2516 | sdvo->ddc.owner = THIS_MODULE; | ||
2517 | sdvo->ddc.class = I2C_CLASS_DDC; | ||
2518 | snprintf(sdvo->ddc.name, I2C_NAME_SIZE, "SDVO DDC proxy"); | ||
2519 | sdvo->ddc.dev.parent = &dev->pdev->dev; | ||
2520 | sdvo->ddc.algo_data = sdvo; | ||
2521 | sdvo->ddc.algo = &intel_sdvo_ddc_proxy; | ||
2522 | |||
2523 | return i2c_add_adapter(&sdvo->ddc) == 0; | ||
2539 | } | 2524 | } |
2540 | 2525 | ||
2541 | bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg) | 2526 | bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg) |
@@ -2543,95 +2528,64 @@ bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg) | |||
2543 | struct drm_i915_private *dev_priv = dev->dev_private; | 2528 | struct drm_i915_private *dev_priv = dev->dev_private; |
2544 | struct intel_encoder *intel_encoder; | 2529 | struct intel_encoder *intel_encoder; |
2545 | struct intel_sdvo *intel_sdvo; | 2530 | struct intel_sdvo *intel_sdvo; |
2546 | u8 ch[0x40]; | ||
2547 | int i; | 2531 | int i; |
2548 | u32 i2c_reg, ddc_reg, analog_ddc_reg; | ||
2549 | 2532 | ||
2550 | intel_sdvo = kzalloc(sizeof(struct intel_sdvo), GFP_KERNEL); | 2533 | intel_sdvo = kzalloc(sizeof(struct intel_sdvo), GFP_KERNEL); |
2551 | if (!intel_sdvo) | 2534 | if (!intel_sdvo) |
2552 | return false; | 2535 | return false; |
2553 | 2536 | ||
2554 | intel_sdvo->sdvo_reg = sdvo_reg; | 2537 | intel_sdvo->sdvo_reg = sdvo_reg; |
2538 | intel_sdvo->slave_addr = intel_sdvo_get_slave_addr(dev, sdvo_reg) >> 1; | ||
2539 | intel_sdvo_select_i2c_bus(dev_priv, intel_sdvo, sdvo_reg); | ||
2540 | if (!intel_sdvo_init_ddc_proxy(intel_sdvo, dev)) { | ||
2541 | kfree(intel_sdvo); | ||
2542 | return false; | ||
2543 | } | ||
2555 | 2544 | ||
2545 | /* encoder type will be decided later */ | ||
2556 | intel_encoder = &intel_sdvo->base; | 2546 | intel_encoder = &intel_sdvo->base; |
2557 | intel_encoder->type = INTEL_OUTPUT_SDVO; | 2547 | intel_encoder->type = INTEL_OUTPUT_SDVO; |
2558 | 2548 | drm_encoder_init(dev, &intel_encoder->base, &intel_sdvo_enc_funcs, 0); | |
2559 | if (HAS_PCH_SPLIT(dev)) { | ||
2560 | i2c_reg = PCH_GPIOE; | ||
2561 | ddc_reg = PCH_GPIOE; | ||
2562 | analog_ddc_reg = PCH_GPIOA; | ||
2563 | } else { | ||
2564 | i2c_reg = GPIOE; | ||
2565 | ddc_reg = GPIOE; | ||
2566 | analog_ddc_reg = GPIOA; | ||
2567 | } | ||
2568 | |||
2569 | /* setup the DDC bus. */ | ||
2570 | if (IS_SDVOB(sdvo_reg)) | ||
2571 | intel_encoder->i2c_bus = intel_i2c_create(dev, i2c_reg, "SDVOCTRL_E for SDVOB"); | ||
2572 | else | ||
2573 | intel_encoder->i2c_bus = intel_i2c_create(dev, i2c_reg, "SDVOCTRL_E for SDVOC"); | ||
2574 | |||
2575 | if (!intel_encoder->i2c_bus) | ||
2576 | goto err_inteloutput; | ||
2577 | |||
2578 | intel_sdvo->slave_addr = intel_sdvo_get_slave_addr(dev, sdvo_reg); | ||
2579 | |||
2580 | /* Save the bit-banging i2c functionality for use by the DDC wrapper */ | ||
2581 | intel_sdvo_i2c_bit_algo.functionality = intel_encoder->i2c_bus->algo->functionality; | ||
2582 | 2549 | ||
2583 | /* Read the regs to test if we can talk to the device */ | 2550 | /* Read the regs to test if we can talk to the device */ |
2584 | for (i = 0; i < 0x40; i++) { | 2551 | for (i = 0; i < 0x40; i++) { |
2585 | if (!intel_sdvo_read_byte(intel_sdvo, i, &ch[i])) { | 2552 | u8 byte; |
2553 | |||
2554 | if (!intel_sdvo_read_byte(intel_sdvo, i, &byte)) { | ||
2586 | DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n", | 2555 | DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n", |
2587 | IS_SDVOB(sdvo_reg) ? 'B' : 'C'); | 2556 | IS_SDVOB(sdvo_reg) ? 'B' : 'C'); |
2588 | goto err_i2c; | 2557 | goto err; |
2589 | } | 2558 | } |
2590 | } | 2559 | } |
2591 | 2560 | ||
2592 | /* setup the DDC bus. */ | 2561 | if (IS_SDVOB(sdvo_reg)) |
2593 | if (IS_SDVOB(sdvo_reg)) { | ||
2594 | intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOB DDC BUS"); | ||
2595 | intel_sdvo->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg, | ||
2596 | "SDVOB/VGA DDC BUS"); | ||
2597 | dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS; | 2562 | dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS; |
2598 | } else { | 2563 | else |
2599 | intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOC DDC BUS"); | ||
2600 | intel_sdvo->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg, | ||
2601 | "SDVOC/VGA DDC BUS"); | ||
2602 | dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS; | 2564 | dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS; |
2603 | } | ||
2604 | if (intel_encoder->ddc_bus == NULL || intel_sdvo->analog_ddc_bus == NULL) | ||
2605 | goto err_i2c; | ||
2606 | 2565 | ||
2607 | /* Wrap with our custom algo which switches to DDC mode */ | 2566 | drm_encoder_helper_add(&intel_encoder->base, &intel_sdvo_helper_funcs); |
2608 | intel_encoder->ddc_bus->algo = &intel_sdvo_i2c_bit_algo; | ||
2609 | |||
2610 | /* encoder type will be decided later */ | ||
2611 | drm_encoder_init(dev, &intel_encoder->enc, &intel_sdvo_enc_funcs, 0); | ||
2612 | drm_encoder_helper_add(&intel_encoder->enc, &intel_sdvo_helper_funcs); | ||
2613 | 2567 | ||
2614 | /* In default case sdvo lvds is false */ | 2568 | /* In default case sdvo lvds is false */ |
2615 | if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps)) | 2569 | if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps)) |
2616 | goto err_enc; | 2570 | goto err; |
2617 | 2571 | ||
2618 | if (intel_sdvo_output_setup(intel_sdvo, | 2572 | if (intel_sdvo_output_setup(intel_sdvo, |
2619 | intel_sdvo->caps.output_flags) != true) { | 2573 | intel_sdvo->caps.output_flags) != true) { |
2620 | DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n", | 2574 | DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n", |
2621 | IS_SDVOB(sdvo_reg) ? 'B' : 'C'); | 2575 | IS_SDVOB(sdvo_reg) ? 'B' : 'C'); |
2622 | goto err_enc; | 2576 | goto err; |
2623 | } | 2577 | } |
2624 | 2578 | ||
2625 | intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo, sdvo_reg); | 2579 | intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo, sdvo_reg); |
2626 | 2580 | ||
2627 | /* Set the input timing to the screen. Assume always input 0. */ | 2581 | /* Set the input timing to the screen. Assume always input 0. */ |
2628 | if (!intel_sdvo_set_target_input(intel_sdvo)) | 2582 | if (!intel_sdvo_set_target_input(intel_sdvo)) |
2629 | goto err_enc; | 2583 | goto err; |
2630 | 2584 | ||
2631 | if (!intel_sdvo_get_input_pixel_clock_range(intel_sdvo, | 2585 | if (!intel_sdvo_get_input_pixel_clock_range(intel_sdvo, |
2632 | &intel_sdvo->pixel_clock_min, | 2586 | &intel_sdvo->pixel_clock_min, |
2633 | &intel_sdvo->pixel_clock_max)) | 2587 | &intel_sdvo->pixel_clock_max)) |
2634 | goto err_enc; | 2588 | goto err; |
2635 | 2589 | ||
2636 | DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, " | 2590 | DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, " |
2637 | "clock range %dMHz - %dMHz, " | 2591 | "clock range %dMHz - %dMHz, " |
@@ -2651,16 +2605,9 @@ bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg) | |||
2651 | (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N'); | 2605 | (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N'); |
2652 | return true; | 2606 | return true; |
2653 | 2607 | ||
2654 | err_enc: | 2608 | err: |
2655 | drm_encoder_cleanup(&intel_encoder->enc); | 2609 | drm_encoder_cleanup(&intel_encoder->base); |
2656 | err_i2c: | 2610 | i2c_del_adapter(&intel_sdvo->ddc); |
2657 | if (intel_sdvo->analog_ddc_bus != NULL) | ||
2658 | intel_i2c_destroy(intel_sdvo->analog_ddc_bus); | ||
2659 | if (intel_encoder->ddc_bus != NULL) | ||
2660 | intel_i2c_destroy(intel_encoder->ddc_bus); | ||
2661 | if (intel_encoder->i2c_bus != NULL) | ||
2662 | intel_i2c_destroy(intel_encoder->i2c_bus); | ||
2663 | err_inteloutput: | ||
2664 | kfree(intel_sdvo); | 2611 | kfree(intel_sdvo); |
2665 | 2612 | ||
2666 | return false; | 2613 | return false; |