28 #include <linux/module.h>
29 #include <linux/i2c.h>
30 #include <linux/slab.h>
41 #define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
42 #define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
43 #define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)
44 #define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0)
46 #define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\
49 #define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
50 #define IS_TMDS(c) (c->output_flag & SDVO_TMDS_MASK)
51 #define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
52 #define IS_TV_OR_LVDS(c) (c->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK))
55 static const char *tv_format_names[] = {
56 "NTSC_M" ,
"NTSC_J" ,
"NTSC_443",
57 "PAL_B" ,
"PAL_D" ,
"PAL_G" ,
58 "PAL_H" ,
"PAL_I" ,
"PAL_M" ,
59 "PAL_N" ,
"PAL_NC" ,
"PAL_60" ,
60 "SECAM_B" ,
"SECAM_D" ,
"SECAM_G" ,
61 "SECAM_K" ,
"SECAM_K1",
"SECAM_L" ,
65 #define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names))
200 return container_of(psb_intel_attached_encoder(connector),
240 for (i = 0; i < 2; i++)
249 static bool psb_intel_sdvo_read_byte(
struct psb_intel_sdvo *psb_intel_sdvo,
u8 addr,
u8 *ch)
270 DRM_DEBUG_KMS(
"i2c transfer returned %d\n", ret);
274 #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
276 static const struct _sdvo_cmd_name {
279 } sdvo_cmd_names[] = {
393 #define IS_SDVOB(reg) (reg == SDVOB)
394 #define SDVO_NAME(svdo) (IS_SDVOB((svdo)->sdvo_reg) ? "SDVOB" : "SDVOC")
396 static void psb_intel_sdvo_debug_write(
struct psb_intel_sdvo *psb_intel_sdvo,
u8 cmd,
397 const void *args,
int args_len)
401 DRM_DEBUG_KMS(
"%s: W: %02X ",
403 for (i = 0; i < args_len; i++)
404 DRM_LOG_KMS(
"%02X ", ((
u8 *)args)[i]);
407 for (i = 0; i <
ARRAY_SIZE(sdvo_cmd_names); i++) {
408 if (cmd == sdvo_cmd_names[i].cmd) {
409 DRM_LOG_KMS(
"(%s)", sdvo_cmd_names[i].
name);
414 DRM_LOG_KMS(
"(%02X)", cmd);
418 static const char *cmd_status_names[] = {
424 "Target not specified",
425 "Scaling not supported"
428 static bool psb_intel_sdvo_write_cmd(
struct psb_intel_sdvo *psb_intel_sdvo,
u8 cmd,
429 const void *args,
int args_len)
432 struct i2c_msg msgs[args_len + 3];
435 psb_intel_sdvo_debug_write(psb_intel_sdvo, cmd, args, args_len);
437 for (i = 0; i < args_len; i++) {
441 msgs[
i].
buf = buf + 2 *
i;
443 buf[2*i + 1] = ((
u8*)args)[
i];
448 msgs[
i].
buf = buf + 2*
i;
466 DRM_DEBUG_KMS(
"I2c transfer returned %d\n", ret);
471 DRM_DEBUG_KMS(
"I2c transfer returned %d/%d\n", ret, i+3);
478 static bool psb_intel_sdvo_read_response(
struct psb_intel_sdvo *psb_intel_sdvo,
485 DRM_DEBUG_KMS(
"%s: R: ",
SDVO_NAME(psb_intel_sdvo));
495 if (!psb_intel_sdvo_read_byte(psb_intel_sdvo,
502 if (!psb_intel_sdvo_read_byte(psb_intel_sdvo,
509 DRM_LOG_KMS(
"(%s)", cmd_status_names[status]);
511 DRM_LOG_KMS(
"(??? %d)", status);
517 for (i = 0; i < response_len; i++) {
518 if (!psb_intel_sdvo_read_byte(psb_intel_sdvo,
520 &((
u8 *)response)[i]))
522 DRM_LOG_KMS(
" %02X", ((
u8 *)response)[i]);
528 DRM_LOG_KMS(
"... failed\n");
534 if (mode->
clock >= 100000)
536 else if (mode->
clock >= 50000)
542 static bool psb_intel_sdvo_set_control_bus_switch(
struct psb_intel_sdvo *psb_intel_sdvo,
546 return psb_intel_sdvo_write_cmd(psb_intel_sdvo,
551 static bool psb_intel_sdvo_set_value(
struct psb_intel_sdvo *psb_intel_sdvo,
u8 cmd,
const void *
data,
int len)
553 if (!psb_intel_sdvo_write_cmd(psb_intel_sdvo, cmd, data, len))
556 return psb_intel_sdvo_read_response(psb_intel_sdvo,
NULL, 0);
560 psb_intel_sdvo_get_value(
struct psb_intel_sdvo *psb_intel_sdvo,
u8 cmd,
void *
value,
int len)
562 if (!psb_intel_sdvo_write_cmd(psb_intel_sdvo, cmd,
NULL, 0))
565 return psb_intel_sdvo_read_response(psb_intel_sdvo, value, len);
568 static bool psb_intel_sdvo_set_target_input(
struct psb_intel_sdvo *psb_intel_sdvo)
571 return psb_intel_sdvo_set_value(psb_intel_sdvo,
573 &targets,
sizeof(targets));
582 static bool psb_intel_sdvo_get_trained_inputs(
struct psb_intel_sdvo *psb_intel_sdvo,
bool *input_1,
bool *input_2)
588 &response,
sizeof(response)))
591 *input_1 = response.input0_trained;
592 *input_2 = response.input1_trained;
596 static bool psb_intel_sdvo_set_active_outputs(
struct psb_intel_sdvo *psb_intel_sdvo,
599 return psb_intel_sdvo_set_value(psb_intel_sdvo,
601 &outputs,
sizeof(outputs));
604 static bool psb_intel_sdvo_set_encoder_power_state(
struct psb_intel_sdvo *psb_intel_sdvo,
624 return psb_intel_sdvo_set_value(psb_intel_sdvo,
628 static bool psb_intel_sdvo_get_input_pixel_clock_range(
struct psb_intel_sdvo *psb_intel_sdvo,
635 if (!psb_intel_sdvo_get_value(psb_intel_sdvo,
637 &clocks,
sizeof(clocks)))
641 *clock_min = clocks.min * 10;
642 *clock_max = clocks.max * 10;
646 static bool psb_intel_sdvo_set_target_output(
struct psb_intel_sdvo *psb_intel_sdvo,
649 return psb_intel_sdvo_set_value(psb_intel_sdvo,
651 &outputs,
sizeof(outputs));
654 static bool psb_intel_sdvo_set_timing(
struct psb_intel_sdvo *psb_intel_sdvo,
u8 cmd,
657 return psb_intel_sdvo_set_value(psb_intel_sdvo, cmd, &dtd->
part1,
sizeof(dtd->
part1)) &&
658 psb_intel_sdvo_set_value(psb_intel_sdvo, cmd + 1, &dtd->
part2,
sizeof(dtd->
part2));
661 static bool psb_intel_sdvo_set_input_timing(
struct psb_intel_sdvo *psb_intel_sdvo,
664 return psb_intel_sdvo_set_timing(psb_intel_sdvo,
668 static bool psb_intel_sdvo_set_output_timing(
struct psb_intel_sdvo *psb_intel_sdvo,
671 return psb_intel_sdvo_set_timing(psb_intel_sdvo,
676 psb_intel_sdvo_create_preferred_input_timing(
struct psb_intel_sdvo *psb_intel_sdvo,
683 memset(&args, 0,
sizeof(args));
694 return psb_intel_sdvo_set_value(psb_intel_sdvo,
696 &args,
sizeof(args));
699 static bool psb_intel_sdvo_get_preferred_input_timing(
struct psb_intel_sdvo *psb_intel_sdvo,
710 static bool psb_intel_sdvo_set_clock_rate_mult(
struct psb_intel_sdvo *psb_intel_sdvo,
u8 val)
719 uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
720 uint16_t h_sync_offset, v_sync_offset;
736 dtd->
part1.h_active = width & 0xff;
737 dtd->
part1.h_blank = h_blank_len & 0xff;
738 dtd->
part1.h_high = (((width >> 8) & 0xf) << 4) |
739 ((h_blank_len >> 8) & 0xf);
740 dtd->
part1.v_active = height & 0xff;
741 dtd->
part1.v_blank = v_blank_len & 0xff;
742 dtd->
part1.v_high = (((height >> 8) & 0xf) << 4) |
743 ((v_blank_len >> 8) & 0xf);
745 dtd->
part2.h_sync_off = h_sync_offset & 0xff;
746 dtd->
part2.h_sync_width = h_sync_len & 0xff;
747 dtd->
part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
749 dtd->
part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
750 ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
751 ((v_sync_len & 0x30) >> 4);
753 dtd->
part2.dtd_flags = 0x18;
755 dtd->
part2.dtd_flags |= 0x2;
757 dtd->
part2.dtd_flags |= 0x4;
759 dtd->
part2.sdvo_flags = 0;
760 dtd->
part2.v_sync_off_high = v_sync_offset & 0xc0;
761 dtd->
part2.reserved = 0;
764 static void psb_intel_sdvo_get_mode_from_dtd(
struct drm_display_mode * mode,
783 (dtd->
part2.v_sync_off_width & 0xf);
791 if (dtd->
part2.dtd_flags & 0x2)
793 if (dtd->
part2.dtd_flags & 0x4)
797 static bool psb_intel_sdvo_check_supp_encode(
struct psb_intel_sdvo *psb_intel_sdvo)
802 return psb_intel_sdvo_get_value(psb_intel_sdvo,
804 &encode,
sizeof(encode));
807 static bool psb_intel_sdvo_set_encode(
struct psb_intel_sdvo *psb_intel_sdvo,
813 static bool psb_intel_sdvo_set_colorimetry(
struct psb_intel_sdvo *psb_intel_sdvo,
820 static void psb_intel_sdvo_dump_hdmi_buf(
struct psb_intel_sdvo *psb_intel_sdvo)
831 for (i = 0; i <= av_split; i++) {
832 set_buf_index[0] =
i; set_buf_index[1] = 0;
836 psb_intel_sdvo_read_response(encoder, &buf_size, 1);
839 for (j = 0; j <=
buf_size; j += 8) {
842 psb_intel_sdvo_read_response(encoder, pos, 8);
849 static bool psb_intel_sdvo_set_avi_infoframe(
struct psb_intel_sdvo *psb_intel_sdvo)
851 DRM_INFO(
"HDMI is not supported yet");
861 uint8_t set_buf_index[2] = { 1, 0 };
867 if (!psb_intel_sdvo_set_value(psb_intel_sdvo,
872 for (i = 0; i <
sizeof(avi_if); i += 8) {
873 if (!psb_intel_sdvo_set_value(psb_intel_sdvo,
880 return psb_intel_sdvo_set_value(psb_intel_sdvo,
886 static bool psb_intel_sdvo_set_tv_format(
struct psb_intel_sdvo *psb_intel_sdvo)
896 return psb_intel_sdvo_set_value(psb_intel_sdvo,
902 psb_intel_sdvo_set_output_timings_from_mode(
struct psb_intel_sdvo *psb_intel_sdvo,
907 if (!psb_intel_sdvo_set_target_output(psb_intel_sdvo,
911 psb_intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
912 if (!psb_intel_sdvo_set_output_timing(psb_intel_sdvo, &output_dtd))
919 psb_intel_sdvo_set_input_timings_for_mode(
struct psb_intel_sdvo *psb_intel_sdvo,
924 if (!psb_intel_sdvo_set_target_input(psb_intel_sdvo))
927 if (!psb_intel_sdvo_create_preferred_input_timing(psb_intel_sdvo,
933 if (!psb_intel_sdvo_get_preferred_input_timing(psb_intel_sdvo,
937 psb_intel_sdvo_get_mode_from_dtd(adjusted_mode, &psb_intel_sdvo->
input_dtd);
943 static bool psb_intel_sdvo_mode_fixup(
struct drm_encoder *encoder,
947 struct psb_intel_sdvo *psb_intel_sdvo = to_psb_intel_sdvo(encoder);
955 if (psb_intel_sdvo->
is_tv) {
956 if (!psb_intel_sdvo_set_output_timings_from_mode(psb_intel_sdvo, mode))
959 (
void) psb_intel_sdvo_set_input_timings_for_mode(psb_intel_sdvo,
962 }
else if (psb_intel_sdvo->
is_lvds) {
963 if (!psb_intel_sdvo_set_output_timings_from_mode(psb_intel_sdvo,
967 (
void) psb_intel_sdvo_set_input_timings_for_mode(psb_intel_sdvo,
975 multiplier = psb_intel_sdvo_get_pixel_multiplier(adjusted_mode);
976 psb_intel_mode_set_pixel_multiplier(adjusted_mode, multiplier);
981 static void psb_intel_sdvo_mode_set(
struct drm_encoder *encoder,
988 struct psb_intel_sdvo *psb_intel_sdvo = to_psb_intel_sdvo(encoder);
992 int pixel_multiplier = psb_intel_mode_get_pixel_multiplier(adjusted_mode);
1007 psb_intel_sdvo_set_value(psb_intel_sdvo,
1009 &in_out,
sizeof(in_out));
1012 if (!psb_intel_sdvo_set_target_output(psb_intel_sdvo,
1019 if (psb_intel_sdvo->
is_tv || psb_intel_sdvo->
is_lvds) {
1023 if (!psb_intel_sdvo_set_target_output(psb_intel_sdvo,
1027 psb_intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
1028 (
void) psb_intel_sdvo_set_output_timing(psb_intel_sdvo, &input_dtd);
1032 if (!psb_intel_sdvo_set_target_input(psb_intel_sdvo))
1037 psb_intel_sdvo_set_colorimetry(psb_intel_sdvo,
1039 psb_intel_sdvo_set_avi_infoframe(psb_intel_sdvo);
1043 if (psb_intel_sdvo->
is_tv &&
1044 !psb_intel_sdvo_set_tv_format(psb_intel_sdvo))
1047 (
void) psb_intel_sdvo_set_input_timing(psb_intel_sdvo, &input_dtd);
1049 switch (pixel_multiplier) {
1055 if (!psb_intel_sdvo_set_clock_rate_mult(psb_intel_sdvo, rate))
1060 switch (psb_intel_sdvo->
sdvo_reg) {
1070 if (psb_intel_crtc->
pipe == 1)
1081 psb_intel_sdvo_write_sdvox(psb_intel_sdvo, sdvox);
1084 static void psb_intel_sdvo_dpms(
struct drm_encoder *encoder,
int mode)
1087 struct psb_intel_sdvo *psb_intel_sdvo = to_psb_intel_sdvo(encoder);
1092 DRM_DEBUG(
"DPMS_ON");
1095 DRM_DEBUG(
"DPMS_OFF");
1098 DRM_DEBUG(
"DPMS: %d", mode);
1102 psb_intel_sdvo_set_active_outputs(psb_intel_sdvo, 0);
1104 psb_intel_sdvo_set_encoder_power_state(psb_intel_sdvo, mode);
1109 psb_intel_sdvo_write_sdvox(psb_intel_sdvo, temp & ~SDVO_ENABLE);
1113 bool input1, input2;
1119 psb_intel_sdvo_write_sdvox(psb_intel_sdvo, temp | SDVO_ENABLE);
1120 for (i = 0; i < 2; i++)
1123 status = psb_intel_sdvo_get_trained_inputs(psb_intel_sdvo, &input1, &input2);
1129 DRM_DEBUG_KMS(
"First %s output reported failure to "
1134 psb_intel_sdvo_set_encoder_power_state(psb_intel_sdvo, mode);
1135 psb_intel_sdvo_set_active_outputs(psb_intel_sdvo, psb_intel_sdvo->
attached_output);
1140 static int psb_intel_sdvo_mode_valid(
struct drm_connector *connector,
1143 struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector);
1154 if (psb_intel_sdvo->
is_lvds) {
1165 static bool psb_intel_sdvo_get_capabilities(
struct psb_intel_sdvo *psb_intel_sdvo,
struct psb_intel_sdvo_caps *
caps)
1168 if (!psb_intel_sdvo_get_value(psb_intel_sdvo,
1170 caps,
sizeof(*caps)))
1173 DRM_DEBUG_KMS(
"SDVO capabilities:\n"
1176 " device_rev_id: %d\n"
1177 " sdvo_version_major: %d\n"
1178 " sdvo_version_minor: %d\n"
1179 " sdvo_inputs_mask: %d\n"
1180 " smooth_scaling: %d\n"
1181 " sharp_scaling: %d\n"
1183 " down_scaling: %d\n"
1184 " stall_support: %d\n"
1185 " output_flags: %d\n",
1207 struct psb_intel_sdvo *iout =
NULL;
1208 struct psb_intel_sdvo *sdvo;
1212 iout = to_psb_intel_sdvo(connector);
1217 sdvo = iout->dev_priv;
1234 struct psb_intel_sdvo *psb_intel_sdvo;
1235 DRM_DEBUG_KMS(
"\n");
1240 psb_intel_sdvo = to_psb_intel_sdvo(connector);
1243 &response, 2) && response[0];
1250 struct psb_intel_sdvo *psb_intel_sdvo = to_psb_intel_sdvo(connector);
1253 psb_intel_sdvo_read_response(psb_intel_sdvo, &response, 2);
1257 status = psb_intel_sdvo_read_response(psb_intel_sdvo, &response, 2);
1267 psb_intel_sdvo_read_response(psb_intel_sdvo, &response, 2);
1272 psb_intel_sdvo_multifunc_encoder(
struct psb_intel_sdvo *psb_intel_sdvo)
1275 int caps = psb_intel_sdvo->
caps.output_flags & 0xf;
1276 return caps & -
caps;
1279 static struct edid *
1282 struct psb_intel_sdvo *sdvo = intel_attached_sdvo(connector);
1287 static struct edid *
1288 psb_intel_sdvo_get_analog_edid(
struct drm_connector *connector)
1297 psb_intel_sdvo_hdmi_sink_detect(
struct drm_connector *connector)
1299 struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector);
1303 edid = psb_intel_sdvo_get_edid(connector);
1305 if (edid ==
NULL && psb_intel_sdvo_multifunc_encoder(psb_intel_sdvo)) {
1306 u8 ddc, saved_ddc = psb_intel_sdvo->
ddc_bus;
1312 for (ddc = psb_intel_sdvo->
ddc_bus >> 1; ddc > 1; ddc >>= 1) {
1313 psb_intel_sdvo->
ddc_bus = ddc;
1314 edid = psb_intel_sdvo_get_edid(connector);
1323 psb_intel_sdvo->
ddc_bus = saved_ddc;
1331 edid = psb_intel_sdvo_get_analog_edid(connector);
1338 if (psb_intel_sdvo->
is_hdmi) {
1360 struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector);
1364 if (!psb_intel_sdvo_write_cmd(psb_intel_sdvo,
1369 if (psb_intel_sdvo->
caps.output_flags &
1373 if (!psb_intel_sdvo_read_response(psb_intel_sdvo, &response, 2))
1376 DRM_DEBUG_KMS(
"SDVO response %d %d [%x]\n",
1377 response & 0xff, response >> 8,
1388 if ((psb_intel_sdvo_connector->
output_flag & response) == 0)
1390 else if (
IS_TMDS(psb_intel_sdvo_connector))
1391 ret = psb_intel_sdvo_hdmi_sink_detect(connector);
1396 edid = psb_intel_sdvo_get_edid(connector);
1398 edid = psb_intel_sdvo_get_analog_edid(connector);
1411 psb_intel_sdvo->
is_tv =
false;
1412 psb_intel_sdvo->
is_lvds =
false;
1413 psb_intel_sdvo->
base.needs_tv_clock =
false;
1416 psb_intel_sdvo->
is_tv =
true;
1417 psb_intel_sdvo->
base.needs_tv_clock =
true;
1426 static void psb_intel_sdvo_get_ddc_modes(
struct drm_connector *connector)
1431 edid = psb_intel_sdvo_get_edid(connector);
1440 edid = psb_intel_sdvo_get_analog_edid(connector);
1443 struct psb_intel_sdvo_connector *psb_intel_sdvo_connector = to_psb_intel_sdvo_connector(connector);
1445 bool connector_is_digital = !!
IS_TMDS(psb_intel_sdvo_connector);
1447 if (connector_is_digital == monitor_is_digital) {
1463 416, 0, 200, 201, 232, 233, 0,
1466 416, 0, 240, 241, 272, 273, 0,
1469 496, 0, 300, 301, 332, 333, 0,
1472 736, 0, 350, 351, 382, 383, 0,
1475 736, 0, 400, 401, 432, 433, 0,
1478 736, 0, 480, 481, 512, 513, 0,
1481 800, 0, 480, 481, 512, 513, 0,
1484 800, 0, 576, 577, 608, 609, 0,
1487 816, 0, 350, 351, 382, 383, 0,
1490 816, 0, 400, 401, 432, 433, 0,
1493 816, 0, 480, 481, 512, 513, 0,
1496 816, 0, 540, 541, 572, 573, 0,
1499 816, 0, 576, 577, 608, 609, 0,
1502 864, 0, 576, 577, 608, 609, 0,
1505 896, 0, 600, 601, 632, 633, 0,
1508 928, 0, 624, 625, 656, 657, 0,
1511 1016, 0, 766, 767, 798, 799, 0,
1514 1120, 0, 768, 769, 800, 801, 0,
1517 1376, 0, 1024, 1025, 1056, 1057, 0,
1521 static void psb_intel_sdvo_get_tv_modes(
struct drm_connector *connector)
1523 struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector);
1525 uint32_t reply = 0, format_map = 0;
1532 memcpy(&tv_res, &format_map,
1535 if (!psb_intel_sdvo_set_target_output(psb_intel_sdvo, psb_intel_sdvo->
attached_output))
1539 if (!psb_intel_sdvo_write_cmd(psb_intel_sdvo,
1541 &tv_res,
sizeof(tv_res)))
1543 if (!psb_intel_sdvo_read_response(psb_intel_sdvo, &reply, 3))
1546 for (i = 0; i <
ARRAY_SIZE(sdvo_tv_modes); i++)
1547 if (reply & (1 << i)) {
1556 static void psb_intel_sdvo_get_lvds_modes(
struct drm_connector *connector)
1558 struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector);
1575 if (newmode !=
NULL) {
1592 psb_intel_sdvo->
is_lvds =
true;
1599 static int psb_intel_sdvo_get_modes(
struct drm_connector *connector)
1601 struct psb_intel_sdvo_connector *psb_intel_sdvo_connector = to_psb_intel_sdvo_connector(connector);
1603 if (
IS_TV(psb_intel_sdvo_connector))
1604 psb_intel_sdvo_get_tv_modes(connector);
1605 else if (
IS_LVDS(psb_intel_sdvo_connector))
1606 psb_intel_sdvo_get_lvds_modes(connector);
1608 psb_intel_sdvo_get_ddc_modes(connector);
1614 psb_intel_sdvo_destroy_enhance_property(
struct drm_connector *connector)
1616 struct psb_intel_sdvo_connector *psb_intel_sdvo_connector = to_psb_intel_sdvo_connector(connector);
1619 if (psb_intel_sdvo_connector->
left)
1621 if (psb_intel_sdvo_connector->
right)
1623 if (psb_intel_sdvo_connector->
top)
1625 if (psb_intel_sdvo_connector->
bottom)
1627 if (psb_intel_sdvo_connector->
hpos)
1629 if (psb_intel_sdvo_connector->
vpos)
1633 if (psb_intel_sdvo_connector->
contrast)
1635 if (psb_intel_sdvo_connector->
hue)
1637 if (psb_intel_sdvo_connector->
sharpness)
1649 if (psb_intel_sdvo_connector->
dot_crawl)
1655 static void psb_intel_sdvo_destroy(
struct drm_connector *connector)
1657 struct psb_intel_sdvo_connector *psb_intel_sdvo_connector = to_psb_intel_sdvo_connector(connector);
1659 if (psb_intel_sdvo_connector->
tv_format)
1663 psb_intel_sdvo_destroy_enhance_property(connector);
1669 static bool psb_intel_sdvo_detect_hdmi_audio(
struct drm_connector *connector)
1671 struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector);
1673 bool has_audio =
false;
1678 edid = psb_intel_sdvo_get_edid(connector);
1686 psb_intel_sdvo_set_property(
struct drm_connector *connector,
1690 struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector);
1691 struct psb_intel_sdvo_connector *psb_intel_sdvo_connector = to_psb_intel_sdvo_connector(connector);
1711 has_audio = psb_intel_sdvo_detect_hdmi_audio(connector);
1730 #define CHECK_PROPERTY(name, NAME) \
1731 if (psb_intel_sdvo_connector->name == property) { \
1732 if (psb_intel_sdvo_connector->cur_##name == temp_value) return 0; \
1733 if (psb_intel_sdvo_connector->max_##name < temp_value) return -EINVAL; \
1734 cmd = SDVO_CMD_SET_##NAME; \
1735 psb_intel_sdvo_connector->cur_##name = temp_value; \
1739 if (property == psb_intel_sdvo_connector->
tv_format) {
1751 if (psb_intel_sdvo_connector->
left == property) {
1753 psb_intel_sdvo_connector->
right, val);
1754 if (psb_intel_sdvo_connector->
left_margin == temp_value)
1757 psb_intel_sdvo_connector->
left_margin = temp_value;
1759 temp_value = psb_intel_sdvo_connector->
max_hscan -
1763 }
else if (psb_intel_sdvo_connector->
right == property) {
1765 psb_intel_sdvo_connector->
left, val);
1766 if (psb_intel_sdvo_connector->
right_margin == temp_value)
1769 psb_intel_sdvo_connector->
left_margin = temp_value;
1771 temp_value = psb_intel_sdvo_connector->
max_hscan -
1775 }
else if (psb_intel_sdvo_connector->
top == property) {
1777 psb_intel_sdvo_connector->
bottom, val);
1778 if (psb_intel_sdvo_connector->
top_margin == temp_value)
1781 psb_intel_sdvo_connector->
top_margin = temp_value;
1783 temp_value = psb_intel_sdvo_connector->
max_vscan -
1787 }
else if (psb_intel_sdvo_connector->
bottom == property) {
1789 psb_intel_sdvo_connector->
top, val);
1793 psb_intel_sdvo_connector->
top_margin = temp_value;
1795 temp_value = psb_intel_sdvo_connector->
max_vscan -
1818 if (!psb_intel_sdvo_set_value(psb_intel_sdvo, cmd, &temp_value, 2))
1823 if (psb_intel_sdvo->base.base.crtc) {
1824 struct drm_crtc *crtc = psb_intel_sdvo->
base.base.crtc;
1830 #undef CHECK_PROPERTY
1834 .dpms = psb_intel_sdvo_dpms,
1835 .mode_fixup = psb_intel_sdvo_mode_fixup,
1837 .mode_set = psb_intel_sdvo_mode_set,
1843 .detect = psb_intel_sdvo_detect,
1845 .set_property = psb_intel_sdvo_set_property,
1846 .destroy = psb_intel_sdvo_destroy,
1850 .get_modes = psb_intel_sdvo_get_modes,
1851 .mode_valid = psb_intel_sdvo_mode_valid,
1855 static void psb_intel_sdvo_enc_destroy(
struct drm_encoder *encoder)
1857 struct psb_intel_sdvo *psb_intel_sdvo = to_psb_intel_sdvo(encoder);
1868 .destroy = psb_intel_sdvo_enc_destroy,
1872 psb_intel_sdvo_guess_ddc_bus(
struct psb_intel_sdvo *sdvo)
1882 unsigned int num_bits;
1904 mask &= sdvo->
caps.output_flags;
1911 sdvo->
ddc_bus = 1 << num_bits;
1924 struct psb_intel_sdvo *sdvo,
u32 reg)
1936 psb_intel_sdvo_guess_ddc_bus(sdvo);
1941 struct psb_intel_sdvo *sdvo,
u32 reg)
1967 psb_intel_sdvo_is_hdmi_connector(
struct psb_intel_sdvo *psb_intel_sdvo,
int device)
1969 return psb_intel_sdvo_check_supp_encode(psb_intel_sdvo);
1973 psb_intel_sdvo_get_slave_addr(
struct drm_device *dev,
int sdvo_reg)
2010 psb_intel_sdvo_connector_init(
struct psb_intel_sdvo_connector *connector,
2011 struct psb_intel_sdvo *encoder)
2014 &connector->
base.base,
2015 &psb_intel_sdvo_connector_funcs,
2016 connector->
base.base.connector_type);
2018 drm_connector_helper_add(&connector->
base.base,
2019 &psb_intel_sdvo_connector_helper_funcs);
2021 connector->
base.base.interlace_allowed = 0;
2022 connector->
base.base.doublescan_allowed = 0;
2030 psb_intel_sdvo_add_hdmi_properties(
struct psb_intel_sdvo_connector *connector)
2041 psb_intel_sdvo_dvi_init(
struct psb_intel_sdvo *psb_intel_sdvo,
int device)
2046 struct psb_intel_sdvo_connector *psb_intel_sdvo_connector;
2048 psb_intel_sdvo_connector = kzalloc(
sizeof(
struct psb_intel_sdvo_connector),
GFP_KERNEL);
2049 if (!psb_intel_sdvo_connector)
2055 }
else if (device == 1) {
2060 intel_connector = &psb_intel_sdvo_connector->
base;
2061 connector = &intel_connector->
base;
2066 if (psb_intel_sdvo_is_hdmi_connector(psb_intel_sdvo, device)) {
2068 psb_intel_sdvo->
is_hdmi =
true;
2073 psb_intel_sdvo_connector_init(psb_intel_sdvo_connector, psb_intel_sdvo);
2075 psb_intel_sdvo_add_hdmi_properties(psb_intel_sdvo_connector);
2081 psb_intel_sdvo_tv_init(
struct psb_intel_sdvo *psb_intel_sdvo,
int type)
2086 struct psb_intel_sdvo_connector *psb_intel_sdvo_connector;
2088 psb_intel_sdvo_connector = kzalloc(
sizeof(
struct psb_intel_sdvo_connector),
GFP_KERNEL);
2089 if (!psb_intel_sdvo_connector)
2092 intel_connector = &psb_intel_sdvo_connector->
base;
2093 connector = &intel_connector->
base;
2100 psb_intel_sdvo->
is_tv =
true;
2101 psb_intel_sdvo->
base.needs_tv_clock =
true;
2104 psb_intel_sdvo_connector_init(psb_intel_sdvo_connector, psb_intel_sdvo);
2106 if (!psb_intel_sdvo_tv_create_property(psb_intel_sdvo, psb_intel_sdvo_connector, type))
2109 if (!psb_intel_sdvo_create_enhance_property(psb_intel_sdvo, psb_intel_sdvo_connector))
2115 psb_intel_sdvo_destroy(connector);
2120 psb_intel_sdvo_analog_init(
struct psb_intel_sdvo *psb_intel_sdvo,
int device)
2125 struct psb_intel_sdvo_connector *psb_intel_sdvo_connector;
2127 psb_intel_sdvo_connector = kzalloc(
sizeof(
struct psb_intel_sdvo_connector),
GFP_KERNEL);
2128 if (!psb_intel_sdvo_connector)
2131 intel_connector = &psb_intel_sdvo_connector->
base;
2132 connector = &intel_connector->
base;
2140 }
else if (device == 1) {
2148 psb_intel_sdvo_connector_init(psb_intel_sdvo_connector,
2154 psb_intel_sdvo_lvds_init(
struct psb_intel_sdvo *psb_intel_sdvo,
int device)
2159 struct psb_intel_sdvo_connector *psb_intel_sdvo_connector;
2161 psb_intel_sdvo_connector = kzalloc(
sizeof(
struct psb_intel_sdvo_connector),
GFP_KERNEL);
2162 if (!psb_intel_sdvo_connector)
2165 intel_connector = &psb_intel_sdvo_connector->
base;
2166 connector = &intel_connector->
base;
2173 }
else if (device == 1) {
2181 psb_intel_sdvo_connector_init(psb_intel_sdvo_connector, psb_intel_sdvo);
2182 if (!psb_intel_sdvo_create_enhance_property(psb_intel_sdvo, psb_intel_sdvo_connector))
2188 psb_intel_sdvo_destroy(connector);
2193 psb_intel_sdvo_output_setup(
struct psb_intel_sdvo *psb_intel_sdvo,
uint16_t flags)
2195 psb_intel_sdvo->
is_tv =
false;
2196 psb_intel_sdvo->
base.needs_tv_clock =
false;
2197 psb_intel_sdvo->
is_lvds =
false;
2202 if (!psb_intel_sdvo_dvi_init(psb_intel_sdvo, 0))
2206 if (!psb_intel_sdvo_dvi_init(psb_intel_sdvo, 1))
2211 if (!psb_intel_sdvo_tv_init(psb_intel_sdvo, SDVO_OUTPUT_SVID0))
2215 if (!psb_intel_sdvo_tv_init(psb_intel_sdvo, SDVO_OUTPUT_CVBS0))
2219 if (!psb_intel_sdvo_analog_init(psb_intel_sdvo, 0))
2223 if (!psb_intel_sdvo_analog_init(psb_intel_sdvo, 1))
2227 if (!psb_intel_sdvo_lvds_init(psb_intel_sdvo, 0))
2231 if (!psb_intel_sdvo_lvds_init(psb_intel_sdvo, 1))
2235 unsigned char bytes[2];
2238 memcpy(bytes, &psb_intel_sdvo->
caps.output_flags, 2);
2239 DRM_DEBUG_KMS(
"%s: Unknown SDVO output type (0x%02x%02x)\n",
2241 bytes[0], bytes[1]);
2244 psb_intel_sdvo->
base.crtc_mask = (1 << 0) | (1 << 1);
2249 static bool psb_intel_sdvo_tv_create_property(
struct psb_intel_sdvo *psb_intel_sdvo,
2250 struct psb_intel_sdvo_connector *psb_intel_sdvo_connector,
2257 if (!psb_intel_sdvo_set_target_output(psb_intel_sdvo, type))
2261 if (!psb_intel_sdvo_get_value(psb_intel_sdvo,
2268 if (format_map == 0)
2273 if (format_map & (1 << i))
2280 if (!psb_intel_sdvo_connector->
tv_format)
2290 psb_intel_sdvo_connector->
tv_format, 0);
2295 #define ENHANCEMENT(name, NAME) do { \
2296 if (enhancements.name) { \
2297 if (!psb_intel_sdvo_get_value(psb_intel_sdvo, SDVO_CMD_GET_MAX_##NAME, &data_value, 4) || \
2298 !psb_intel_sdvo_get_value(psb_intel_sdvo, SDVO_CMD_GET_##NAME, &response, 2)) \
2300 psb_intel_sdvo_connector->max_##name = data_value[0]; \
2301 psb_intel_sdvo_connector->cur_##name = response; \
2302 psb_intel_sdvo_connector->name = \
2303 drm_property_create_range(dev, 0, #name, 0, data_value[0]); \
2304 if (!psb_intel_sdvo_connector->name) return false; \
2305 drm_connector_attach_property(connector, \
2306 psb_intel_sdvo_connector->name, \
2307 psb_intel_sdvo_connector->cur_##name); \
2308 DRM_DEBUG_KMS(#name ": max %d, default %d, current %d\n", \
2309 data_value[0], data_value[1], response); \
2314 psb_intel_sdvo_create_enhance_property_tv(
struct psb_intel_sdvo *psb_intel_sdvo,
2315 struct psb_intel_sdvo_connector *psb_intel_sdvo_connector,
2324 if (!psb_intel_sdvo_get_value(psb_intel_sdvo,
2329 if (!psb_intel_sdvo_get_value(psb_intel_sdvo,
2334 psb_intel_sdvo_connector->
max_hscan = data_value[0];
2337 psb_intel_sdvo_connector->
left =
2339 if (!psb_intel_sdvo_connector->
left)
2343 psb_intel_sdvo_connector->
left,
2346 psb_intel_sdvo_connector->
right =
2348 if (!psb_intel_sdvo_connector->
right)
2352 psb_intel_sdvo_connector->
right,
2354 DRM_DEBUG_KMS(
"h_overscan: max %d, "
2355 "default %d, current %d\n",
2356 data_value[0], data_value[1], response);
2360 if (!psb_intel_sdvo_get_value(psb_intel_sdvo,
2365 if (!psb_intel_sdvo_get_value(psb_intel_sdvo,
2370 psb_intel_sdvo_connector->
max_vscan = data_value[0];
2373 psb_intel_sdvo_connector->
top =
2375 if (!psb_intel_sdvo_connector->
top)
2379 psb_intel_sdvo_connector->
top,
2382 psb_intel_sdvo_connector->
bottom =
2384 if (!psb_intel_sdvo_connector->
bottom)
2388 psb_intel_sdvo_connector->
bottom,
2390 DRM_DEBUG_KMS(
"v_overscan: max %d, "
2391 "default %d, current %d\n",
2392 data_value[0], data_value[1], response);
2416 if (!psb_intel_sdvo_connector->
dot_crawl)
2422 DRM_DEBUG_KMS(
"dot crawl: current %d\n", response);
2429 psb_intel_sdvo_create_enhance_property_lvds(
struct psb_intel_sdvo *psb_intel_sdvo,
2430 struct psb_intel_sdvo_connector *psb_intel_sdvo_connector,
2443 static bool psb_intel_sdvo_create_enhance_property(
struct psb_intel_sdvo *psb_intel_sdvo,
2444 struct psb_intel_sdvo_connector *psb_intel_sdvo_connector)
2453 enhancements.response = 0;
2454 psb_intel_sdvo_get_value(psb_intel_sdvo,
2456 &enhancements,
sizeof(enhancements));
2457 if (enhancements.response == 0) {
2458 DRM_DEBUG_KMS(
"No enhancement is supported\n");
2462 if (
IS_TV(psb_intel_sdvo_connector))
2463 return psb_intel_sdvo_create_enhance_property_tv(psb_intel_sdvo, psb_intel_sdvo_connector, enhancements.reply);
2464 else if(
IS_LVDS(psb_intel_sdvo_connector))
2465 return psb_intel_sdvo_create_enhance_property_lvds(psb_intel_sdvo, psb_intel_sdvo_connector, enhancements.reply);
2474 struct psb_intel_sdvo *sdvo = adapter->
algo_data;
2476 if (!psb_intel_sdvo_set_control_bus_switch(sdvo, sdvo->
ddc_bus))
2479 return sdvo->
i2c->algo->master_xfer(sdvo->
i2c, msgs, num);
2482 static u32 psb_intel_sdvo_ddc_proxy_func(
struct i2c_adapter *adapter)
2484 struct psb_intel_sdvo *sdvo = adapter->
algo_data;
2485 return sdvo->
i2c->algo->functionality(sdvo->
i2c);
2488 static const struct i2c_algorithm psb_intel_sdvo_ddc_proxy = {
2489 .master_xfer = psb_intel_sdvo_ddc_proxy_xfer,
2490 .functionality = psb_intel_sdvo_ddc_proxy_func
2494 psb_intel_sdvo_init_ddc_proxy(
struct psb_intel_sdvo *sdvo,
2500 sdvo->
ddc.dev.parent = &dev->pdev->dev;
2501 sdvo->
ddc.algo_data = sdvo;
2502 sdvo->
ddc.algo = &psb_intel_sdvo_ddc_proxy;
2511 struct psb_intel_sdvo *psb_intel_sdvo;
2514 psb_intel_sdvo = kzalloc(
sizeof(
struct psb_intel_sdvo),
GFP_KERNEL);
2515 if (!psb_intel_sdvo)
2519 psb_intel_sdvo->
slave_addr = psb_intel_sdvo_get_slave_addr(dev, sdvo_reg) >> 1;
2520 psb_intel_sdvo_select_i2c_bus(dev_priv, psb_intel_sdvo, sdvo_reg);
2521 if (!psb_intel_sdvo_init_ddc_proxy(psb_intel_sdvo, dev)) {
2522 kfree(psb_intel_sdvo);
2527 psb_intel_encoder = &psb_intel_sdvo->
base;
2532 for (i = 0; i < 0x40; i++) {
2535 if (!psb_intel_sdvo_read_byte(psb_intel_sdvo, i, &byte)) {
2536 DRM_DEBUG_KMS(
"No SDVO device found on SDVO%c\n",
2547 drm_encoder_helper_add(&psb_intel_encoder->
base, &psb_intel_sdvo_helper_funcs);
2550 if (!psb_intel_sdvo_get_capabilities(psb_intel_sdvo, &psb_intel_sdvo->
caps))
2553 if (psb_intel_sdvo_output_setup(psb_intel_sdvo,
2554 psb_intel_sdvo->
caps.output_flags) !=
true) {
2555 DRM_DEBUG_KMS(
"SDVO output failed to setup on SDVO%c\n",
2560 psb_intel_sdvo_select_ddc_bus(dev_priv, psb_intel_sdvo, sdvo_reg);
2563 if (!psb_intel_sdvo_set_target_input(psb_intel_sdvo))
2566 if (!psb_intel_sdvo_get_input_pixel_clock_range(psb_intel_sdvo,
2571 DRM_DEBUG_KMS(
"%s device VID/DID: %02X:%02X.%02X, "
2572 "clock range %dMHz - %dMHz, "
2573 "input 1: %c, input 2: %c, "
2574 "output 1: %c, output 2: %c\n",
2576 psb_intel_sdvo->
caps.vendor_id, psb_intel_sdvo->
caps.device_id,
2577 psb_intel_sdvo->
caps.device_rev_id,
2580 (psb_intel_sdvo->
caps.sdvo_inputs_mask & 0x1) ?
'Y' :
'N',
2581 (psb_intel_sdvo->
caps.sdvo_inputs_mask & 0x2) ?
'Y' :
'N',
2583 psb_intel_sdvo->
caps.output_flags &
2584 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ?
'Y' :
'N',
2585 psb_intel_sdvo->
caps.output_flags &
2592 kfree(psb_intel_sdvo);