28 #include <linux/i2c.h>
29 #include <linux/slab.h>
31 #include <linux/export.h>
36 #include <drm/i915_drm.h>
40 #define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
41 #define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
42 #define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)
43 #define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_YPRPB0)
45 #define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\
48 #define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
49 #define IS_TMDS(c) (c->output_flag & SDVO_TMDS_MASK)
50 #define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
51 #define IS_TV_OR_LVDS(c) (c->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK))
52 #define IS_DIGITAL(c) (c->output_flag & (SDVO_TMDS_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))
257 for (i = 0; i < 2; i++)
266 static bool intel_sdvo_read_byte(
struct intel_sdvo *intel_sdvo,
u8 addr,
u8 *ch)
287 DRM_DEBUG_KMS(
"i2c transfer returned %d\n", ret);
291 #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
293 static const struct _sdvo_cmd_name {
296 } sdvo_cmd_names[] = {
410 #define SDVO_NAME(svdo) ((svdo)->is_sdvob ? "SDVOB" : "SDVOC")
412 static void intel_sdvo_debug_write(
struct intel_sdvo *intel_sdvo,
u8 cmd,
413 const void *args,
int args_len)
417 DRM_DEBUG_KMS(
"%s: W: %02X ",
419 for (i = 0; i < args_len; i++)
420 DRM_LOG_KMS(
"%02X ", ((
u8 *)args)[i]);
423 for (i = 0; i <
ARRAY_SIZE(sdvo_cmd_names); i++) {
424 if (cmd == sdvo_cmd_names[i].cmd) {
425 DRM_LOG_KMS(
"(%s)", sdvo_cmd_names[i].
name);
430 DRM_LOG_KMS(
"(%02X)", cmd);
434 static const char *cmd_status_names[] = {
440 "Target not specified",
441 "Scaling not supported"
444 static bool intel_sdvo_write_cmd(
struct intel_sdvo *intel_sdvo,
u8 cmd,
445 const void *args,
int args_len)
456 msgs = kcalloc(args_len + 3,
sizeof(*msgs),
GFP_KERNEL);
462 intel_sdvo_debug_write(intel_sdvo, cmd, args, args_len);
464 for (i = 0; i < args_len; i++) {
468 msgs[
i].
buf = buf + 2 *
i;
470 buf[2*i + 1] = ((
u8*)args)[
i];
475 msgs[
i].
buf = buf + 2*
i;
493 DRM_DEBUG_KMS(
"I2c transfer returned %d\n", ret);
499 DRM_DEBUG_KMS(
"I2c transfer returned %d/%d\n", ret, i+3);
509 static bool intel_sdvo_read_response(
struct intel_sdvo *intel_sdvo,
516 DRM_DEBUG_KMS(
"%s: R: ",
SDVO_NAME(intel_sdvo));
526 if (!intel_sdvo_read_byte(intel_sdvo,
533 if (!intel_sdvo_read_byte(intel_sdvo,
540 DRM_LOG_KMS(
"(%s)", cmd_status_names[status]);
542 DRM_LOG_KMS(
"(??? %d)", status);
548 for (i = 0; i < response_len; i++) {
549 if (!intel_sdvo_read_byte(intel_sdvo,
551 &((
u8 *)response)[i]))
553 DRM_LOG_KMS(
" %02X", ((
u8 *)response)[i]);
559 DRM_LOG_KMS(
"... failed\n");
565 if (mode->
clock >= 100000)
567 else if (mode->
clock >= 50000)
573 static bool intel_sdvo_set_control_bus_switch(
struct intel_sdvo *intel_sdvo,
577 return intel_sdvo_write_cmd(intel_sdvo,
582 static bool intel_sdvo_set_value(
struct intel_sdvo *intel_sdvo,
u8 cmd,
const void *
data,
int len)
584 if (!intel_sdvo_write_cmd(intel_sdvo, cmd, data, len))
587 return intel_sdvo_read_response(intel_sdvo,
NULL, 0);
591 intel_sdvo_get_value(
struct intel_sdvo *intel_sdvo,
u8 cmd,
void *
value,
int len)
593 if (!intel_sdvo_write_cmd(intel_sdvo, cmd,
NULL, 0))
596 return intel_sdvo_read_response(intel_sdvo, value, len);
599 static bool intel_sdvo_set_target_input(
struct intel_sdvo *intel_sdvo)
602 return intel_sdvo_set_value(intel_sdvo,
604 &targets,
sizeof(targets));
613 static bool intel_sdvo_get_trained_inputs(
struct intel_sdvo *intel_sdvo,
bool *input_1,
bool *input_2)
619 &response,
sizeof(response)))
622 *input_1 = response.input0_trained;
623 *input_2 = response.input1_trained;
627 static bool intel_sdvo_set_active_outputs(
struct intel_sdvo *intel_sdvo,
630 return intel_sdvo_set_value(intel_sdvo,
632 &outputs,
sizeof(outputs));
635 static bool intel_sdvo_get_active_outputs(
struct intel_sdvo *intel_sdvo,
638 return intel_sdvo_get_value(intel_sdvo,
640 outputs,
sizeof(*outputs));
643 static bool intel_sdvo_set_encoder_power_state(
struct intel_sdvo *intel_sdvo,
663 return intel_sdvo_set_value(intel_sdvo,
667 static bool intel_sdvo_get_input_pixel_clock_range(
struct intel_sdvo *intel_sdvo,
674 if (!intel_sdvo_get_value(intel_sdvo,
676 &clocks,
sizeof(clocks)))
680 *clock_min = clocks.min * 10;
681 *clock_max = clocks.max * 10;
685 static bool intel_sdvo_set_target_output(
struct intel_sdvo *intel_sdvo,
688 return intel_sdvo_set_value(intel_sdvo,
690 &outputs,
sizeof(outputs));
693 static bool intel_sdvo_set_timing(
struct intel_sdvo *intel_sdvo,
u8 cmd,
696 return intel_sdvo_set_value(intel_sdvo, cmd, &dtd->
part1,
sizeof(dtd->
part1)) &&
697 intel_sdvo_set_value(intel_sdvo, cmd + 1, &dtd->
part2,
sizeof(dtd->
part2));
700 static bool intel_sdvo_set_input_timing(
struct intel_sdvo *intel_sdvo,
703 return intel_sdvo_set_timing(intel_sdvo,
707 static bool intel_sdvo_set_output_timing(
struct intel_sdvo *intel_sdvo,
710 return intel_sdvo_set_timing(intel_sdvo,
715 intel_sdvo_create_preferred_input_timing(
struct intel_sdvo *intel_sdvo,
722 memset(&args, 0,
sizeof(args));
733 return intel_sdvo_set_value(intel_sdvo,
735 &args,
sizeof(args));
738 static bool intel_sdvo_get_preferred_input_timing(
struct intel_sdvo *intel_sdvo,
749 static bool intel_sdvo_set_clock_rate_mult(
struct intel_sdvo *intel_sdvo,
u8 val)
754 static void intel_sdvo_get_dtd_from_mode(
struct intel_sdvo_dtd *dtd,
758 uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
759 uint16_t h_sync_offset, v_sync_offset;
775 mode_clock = mode->
clock;
776 mode_clock /= intel_mode_get_pixel_multiplier(mode) ?: 1;
778 dtd->
part1.clock = mode_clock;
780 dtd->
part1.h_active = width & 0xff;
781 dtd->
part1.h_blank = h_blank_len & 0xff;
782 dtd->
part1.h_high = (((width >> 8) & 0xf) << 4) |
783 ((h_blank_len >> 8) & 0xf);
784 dtd->
part1.v_active = height & 0xff;
785 dtd->
part1.v_blank = v_blank_len & 0xff;
786 dtd->
part1.v_high = (((height >> 8) & 0xf) << 4) |
787 ((v_blank_len >> 8) & 0xf);
789 dtd->
part2.h_sync_off = h_sync_offset & 0xff;
790 dtd->
part2.h_sync_width = h_sync_len & 0xff;
791 dtd->
part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
793 dtd->
part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
794 ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
795 ((v_sync_len & 0x30) >> 4);
797 dtd->
part2.dtd_flags = 0x18;
805 dtd->
part2.sdvo_flags = 0;
806 dtd->
part2.v_sync_off_high = v_sync_offset & 0xc0;
807 dtd->
part2.reserved = 0;
829 (dtd->
part2.v_sync_off_width & 0xf);
845 static bool intel_sdvo_check_supp_encode(
struct intel_sdvo *intel_sdvo)
850 return intel_sdvo_get_value(intel_sdvo,
852 &encode,
sizeof(encode));
855 static bool intel_sdvo_set_encode(
struct intel_sdvo *intel_sdvo,
861 static bool intel_sdvo_set_colorimetry(
struct intel_sdvo *intel_sdvo,
868 static void intel_sdvo_dump_hdmi_buf(
struct intel_sdvo *intel_sdvo)
879 for (i = 0; i <= av_split; i++) {
880 set_buf_index[0] =
i; set_buf_index[1] = 0;
884 intel_sdvo_read_response(encoder, &buf_size, 1);
887 for (j = 0; j <=
buf_size; j += 8) {
890 intel_sdvo_read_response(encoder, pos, 8);
897 static bool intel_sdvo_write_infoframe(
struct intel_sdvo *intel_sdvo,
898 unsigned if_index,
uint8_t tx_rate,
901 uint8_t set_buf_index[2] = { if_index, 0 };
905 if (!intel_sdvo_set_value(intel_sdvo,
917 DRM_DEBUG_KMS(
"writing sdvo hbuf: %i, hbuf_size %i, hbuf_size: %i\n",
918 if_index, length, hbuf_size);
920 for (i = 0; i < hbuf_size; i += 8) {
923 memcpy(tmp, data + i,
min_t(
unsigned, 8, length - i));
925 if (!intel_sdvo_set_value(intel_sdvo,
931 return intel_sdvo_set_value(intel_sdvo,
936 static bool intel_sdvo_set_avi_infoframe(
struct intel_sdvo *intel_sdvo)
943 uint8_t sdvo_data[4 +
sizeof(avi_if.body.avi)];
949 memcpy(sdvo_data, &avi_if, 3);
951 memcpy(&sdvo_data[4], &avi_if.body,
sizeof(avi_if.body.avi));
955 sdvo_data,
sizeof(sdvo_data));
958 static bool intel_sdvo_set_tv_format(
struct intel_sdvo *intel_sdvo)
968 return intel_sdvo_set_value(intel_sdvo,
974 intel_sdvo_set_output_timings_from_mode(
struct intel_sdvo *intel_sdvo,
979 if (!intel_sdvo_set_target_output(intel_sdvo,
983 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
984 if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
993 intel_sdvo_get_preferred_input_mode(
struct intel_sdvo *intel_sdvo,
1000 if (!intel_sdvo_set_target_input(intel_sdvo))
1003 if (!intel_sdvo_create_preferred_input_timing(intel_sdvo,
1009 if (!intel_sdvo_get_preferred_input_timing(intel_sdvo,
1013 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1019 static bool intel_sdvo_mode_fixup(
struct drm_encoder *encoder,
1023 struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder);
1031 if (intel_sdvo->
is_tv) {
1032 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo, mode))
1035 (
void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1038 }
else if (intel_sdvo->
is_lvds) {
1039 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo,
1043 (
void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1051 multiplier = intel_sdvo_get_pixel_multiplier(adjusted_mode);
1052 intel_mode_set_pixel_multiplier(adjusted_mode, multiplier);
1057 static void intel_sdvo_mode_set(
struct drm_encoder *encoder,
1065 struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder);
1069 int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
1084 intel_sdvo_set_value(intel_sdvo,
1086 &in_out,
sizeof(in_out));
1089 if (!intel_sdvo_set_target_output(intel_sdvo,
1095 intel_sdvo_get_dtd_from_mode(&output_dtd,
1098 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1099 if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
1100 DRM_INFO(
"Setting output timings on %s failed\n",
1104 if (!intel_sdvo_set_target_input(intel_sdvo))
1109 intel_sdvo_set_colorimetry(intel_sdvo,
1111 intel_sdvo_set_avi_infoframe(intel_sdvo);
1115 if (intel_sdvo->
is_tv &&
1116 !intel_sdvo_set_tv_format(intel_sdvo))
1122 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
1125 if (!intel_sdvo_set_input_timing(intel_sdvo, &input_dtd))
1126 DRM_INFO(
"Setting input timings on %s failed\n",
1129 switch (pixel_multiplier) {
1135 if (!intel_sdvo_set_clock_rate_mult(intel_sdvo, rate))
1179 intel_sdvo_write_sdvox(intel_sdvo, sdvox);
1182 static bool intel_sdvo_connector_get_hw_state(
struct intel_connector *connector)
1185 to_intel_sdvo_connector(&connector->
base);
1186 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(&connector->
base);
1189 intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1191 if (active_outputs & intel_sdvo_connector->
output_flag)
1197 static bool intel_sdvo_get_hw_state(
struct intel_encoder *encoder,
1202 struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->
base);
1218 static void intel_disable_sdvo(
struct intel_encoder *encoder)
1221 struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->
base);
1224 intel_sdvo_set_active_outputs(intel_sdvo, 0);
1226 intel_sdvo_set_encoder_power_state(intel_sdvo,
1230 if ((temp & SDVO_ENABLE) != 0) {
1231 intel_sdvo_write_sdvox(intel_sdvo, temp & ~SDVO_ENABLE);
1235 static void intel_enable_sdvo(
struct intel_encoder *encoder)
1239 struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->
base);
1242 bool input1, input2;
1247 if ((temp & SDVO_ENABLE) == 0)
1248 intel_sdvo_write_sdvox(intel_sdvo, temp | SDVO_ENABLE);
1249 for (i = 0; i < 2; i++)
1252 status = intel_sdvo_get_trained_inputs(intel_sdvo, &input1, &input2);
1258 DRM_DEBUG_KMS(
"First %s output reported failure to "
1263 intel_sdvo_set_encoder_power_state(intel_sdvo,
1265 intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->
attached_output);
1268 static void intel_sdvo_dpms(
struct drm_connector *connector,
int mode)
1271 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1277 if (mode == connector->
dpms)
1283 crtc = intel_sdvo->
base.base.crtc;
1285 intel_sdvo->
base.connectors_active =
false;
1290 intel_sdvo_set_active_outputs(intel_sdvo, 0);
1292 intel_sdvo_set_encoder_power_state(intel_sdvo, mode);
1294 intel_sdvo->
base.connectors_active =
false;
1298 intel_sdvo->
base.connectors_active =
true;
1303 intel_sdvo_set_encoder_power_state(intel_sdvo, mode);
1304 intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->
attached_output);
1310 static int intel_sdvo_mode_valid(
struct drm_connector *connector,
1313 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1335 static bool intel_sdvo_get_capabilities(
struct intel_sdvo *intel_sdvo,
struct intel_sdvo_caps *
caps)
1338 if (!intel_sdvo_get_value(intel_sdvo,
1340 caps,
sizeof(*caps)))
1343 DRM_DEBUG_KMS(
"SDVO capabilities:\n"
1346 " device_rev_id: %d\n"
1347 " sdvo_version_major: %d\n"
1348 " sdvo_version_minor: %d\n"
1349 " sdvo_inputs_mask: %d\n"
1350 " smooth_scaling: %d\n"
1351 " sharp_scaling: %d\n"
1353 " down_scaling: %d\n"
1354 " stall_support: %d\n"
1355 " output_flags: %d\n",
1372 static uint16_t intel_sdvo_get_hotplug_support(
struct intel_sdvo *intel_sdvo)
1383 &hotplug,
sizeof(hotplug)))
1389 static void intel_sdvo_enable_hotplug(
struct intel_encoder *encoder)
1391 struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->
base);
1398 intel_sdvo_multifunc_encoder(
struct intel_sdvo *intel_sdvo)
1404 static struct edid *
1407 struct intel_sdvo *sdvo = intel_attached_sdvo(connector);
1412 static struct edid *
1423 intel_sdvo_tmds_sink_detect(
struct drm_connector *connector)
1425 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1429 edid = intel_sdvo_get_edid(connector);
1431 if (edid ==
NULL && intel_sdvo_multifunc_encoder(intel_sdvo)) {
1432 u8 ddc, saved_ddc = intel_sdvo->
ddc_bus;
1438 for (ddc = intel_sdvo->
ddc_bus >> 1; ddc > 1; ddc >>= 1) {
1440 edid = intel_sdvo_get_edid(connector);
1449 intel_sdvo->
ddc_bus = saved_ddc;
1457 edid = intel_sdvo_get_analog_edid(connector);
1474 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1483 intel_sdvo_connector_matches_edid(
struct intel_sdvo_connector *sdvo,
1487 bool connector_is_digital = !!
IS_DIGITAL(sdvo);
1489 DRM_DEBUG_KMS(
"connector_is_digital? %d, monitor_is_digital? %d\n",
1490 connector_is_digital, monitor_is_digital);
1491 return connector_is_digital == monitor_is_digital;
1498 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1499 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1502 if (!intel_sdvo_write_cmd(intel_sdvo,
1510 if (!intel_sdvo_read_response(intel_sdvo, &response, 2))
1513 DRM_DEBUG_KMS(
"SDVO response %d %d [%x]\n",
1514 response & 0xff, response >> 8,
1525 if ((intel_sdvo_connector->
output_flag & response) == 0)
1527 else if (
IS_TMDS(intel_sdvo_connector))
1528 ret = intel_sdvo_tmds_sink_detect(connector);
1533 edid = intel_sdvo_get_edid(connector);
1535 edid = intel_sdvo_get_analog_edid(connector);
1537 if (intel_sdvo_connector_matches_edid(intel_sdvo_connector,
1550 intel_sdvo->
is_tv =
false;
1552 intel_sdvo->
base.needs_tv_clock =
false;
1555 intel_sdvo->
is_tv =
true;
1556 intel_sdvo->
base.needs_tv_clock =
true;
1565 static void intel_sdvo_get_ddc_modes(
struct drm_connector *connector)
1570 edid = intel_sdvo_get_edid(connector);
1579 edid = intel_sdvo_get_analog_edid(connector);
1582 if (intel_sdvo_connector_matches_edid(to_intel_sdvo_connector(connector),
1599 416, 0, 200, 201, 232, 233, 0,
1602 416, 0, 240, 241, 272, 273, 0,
1605 496, 0, 300, 301, 332, 333, 0,
1608 736, 0, 350, 351, 382, 383, 0,
1611 736, 0, 400, 401, 432, 433, 0,
1614 736, 0, 480, 481, 512, 513, 0,
1617 800, 0, 480, 481, 512, 513, 0,
1620 800, 0, 576, 577, 608, 609, 0,
1623 816, 0, 350, 351, 382, 383, 0,
1626 816, 0, 400, 401, 432, 433, 0,
1629 816, 0, 480, 481, 512, 513, 0,
1632 816, 0, 540, 541, 572, 573, 0,
1635 816, 0, 576, 577, 608, 609, 0,
1638 864, 0, 576, 577, 608, 609, 0,
1641 896, 0, 600, 601, 632, 633, 0,
1644 928, 0, 624, 625, 656, 657, 0,
1647 1016, 0, 766, 767, 798, 799, 0,
1650 1120, 0, 768, 769, 800, 801, 0,
1653 1376, 0, 1024, 1025, 1056, 1057, 0,
1657 static void intel_sdvo_get_tv_modes(
struct drm_connector *connector)
1659 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1661 uint32_t reply = 0, format_map = 0;
1668 memcpy(&tv_res, &format_map,
1671 if (!intel_sdvo_set_target_output(intel_sdvo, intel_sdvo->
attached_output))
1675 if (!intel_sdvo_write_cmd(intel_sdvo,
1677 &tv_res,
sizeof(tv_res)))
1679 if (!intel_sdvo_read_response(intel_sdvo, &reply, 3))
1682 for (i = 0; i <
ARRAY_SIZE(sdvo_tv_modes); i++)
1683 if (reply & (1 << i)) {
1692 static void intel_sdvo_get_lvds_modes(
struct drm_connector *connector)
1694 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1711 if (newmode !=
NULL) {
1732 static int intel_sdvo_get_modes(
struct drm_connector *connector)
1734 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1736 if (
IS_TV(intel_sdvo_connector))
1737 intel_sdvo_get_tv_modes(connector);
1738 else if (
IS_LVDS(intel_sdvo_connector))
1739 intel_sdvo_get_lvds_modes(connector);
1741 intel_sdvo_get_ddc_modes(connector);
1747 intel_sdvo_destroy_enhance_property(
struct drm_connector *connector)
1749 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1752 if (intel_sdvo_connector->
left)
1754 if (intel_sdvo_connector->
right)
1756 if (intel_sdvo_connector->
top)
1758 if (intel_sdvo_connector->
bottom)
1760 if (intel_sdvo_connector->
hpos)
1762 if (intel_sdvo_connector->
vpos)
1766 if (intel_sdvo_connector->
contrast)
1768 if (intel_sdvo_connector->
hue)
1788 static void intel_sdvo_destroy(
struct drm_connector *connector)
1790 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1796 intel_sdvo_destroy_enhance_property(connector);
1802 static bool intel_sdvo_detect_hdmi_audio(
struct drm_connector *connector)
1804 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1806 bool has_audio =
false;
1811 edid = intel_sdvo_get_edid(connector);
1824 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1825 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1845 has_audio = intel_sdvo_detect_hdmi_audio(connector);
1864 #define CHECK_PROPERTY(name, NAME) \
1865 if (intel_sdvo_connector->name == property) { \
1866 if (intel_sdvo_connector->cur_##name == temp_value) return 0; \
1867 if (intel_sdvo_connector->max_##name < temp_value) return -EINVAL; \
1868 cmd = SDVO_CMD_SET_##NAME; \
1869 intel_sdvo_connector->cur_##name = temp_value; \
1873 if (property == intel_sdvo_connector->
tv_format) {
1885 if (intel_sdvo_connector->
left == property) {
1887 intel_sdvo_connector->
right, val);
1888 if (intel_sdvo_connector->
left_margin == temp_value)
1893 temp_value = intel_sdvo_connector->
max_hscan -
1897 }
else if (intel_sdvo_connector->
right == property) {
1899 intel_sdvo_connector->
left, val);
1905 temp_value = intel_sdvo_connector->
max_hscan -
1909 }
else if (intel_sdvo_connector->
top == property) {
1911 intel_sdvo_connector->
bottom, val);
1912 if (intel_sdvo_connector->
top_margin == temp_value)
1915 intel_sdvo_connector->
top_margin = temp_value;
1917 temp_value = intel_sdvo_connector->
max_vscan -
1921 }
else if (intel_sdvo_connector->
bottom == property) {
1923 intel_sdvo_connector->
top, val);
1927 intel_sdvo_connector->
top_margin = temp_value;
1929 temp_value = intel_sdvo_connector->
max_vscan -
1952 if (!intel_sdvo_set_value(intel_sdvo, cmd, &temp_value, 2))
1957 if (intel_sdvo->base.base.crtc) {
1960 crtc->
x, crtc->
y, crtc->
fb);
1964 #undef CHECK_PROPERTY
1968 .mode_fixup = intel_sdvo_mode_fixup,
1969 .mode_set = intel_sdvo_mode_set,
1974 .dpms = intel_sdvo_dpms,
1975 .detect = intel_sdvo_detect,
1977 .set_property = intel_sdvo_set_property,
1978 .destroy = intel_sdvo_destroy,
1982 .get_modes = intel_sdvo_get_modes,
1983 .mode_valid = intel_sdvo_mode_valid,
1987 static void intel_sdvo_enc_destroy(
struct drm_encoder *encoder)
1989 struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder);
2000 .destroy = intel_sdvo_enc_destroy,
2004 intel_sdvo_guess_ddc_bus(
struct intel_sdvo *sdvo)
2007 unsigned int num_bits;
2029 mask &= sdvo->
caps.output_flags;
2036 sdvo->
ddc_bus = 1 << num_bits;
2048 struct intel_sdvo *sdvo,
u32 reg)
2060 intel_sdvo_guess_ddc_bus(sdvo);
2065 struct intel_sdvo *sdvo,
u32 reg)
2089 intel_sdvo_is_hdmi_connector(
struct intel_sdvo *intel_sdvo,
int device)
2091 return intel_sdvo_check_supp_encode(intel_sdvo);
2095 intel_sdvo_get_slave_addr(
struct drm_device *dev,
struct intel_sdvo *sdvo)
2132 intel_sdvo_connector_init(
struct intel_sdvo_connector *connector,
2133 struct intel_sdvo *encoder)
2136 &connector->
base.base,
2137 &intel_sdvo_connector_funcs,
2138 connector->
base.base.connector_type);
2140 drm_connector_helper_add(&connector->
base.base,
2141 &intel_sdvo_connector_helper_funcs);
2143 connector->
base.base.interlace_allowed = 1;
2144 connector->
base.base.doublescan_allowed = 0;
2146 connector->
base.get_hw_state = intel_sdvo_connector_get_hw_state;
2153 intel_sdvo_add_hdmi_properties(
struct intel_sdvo_connector *connector)
2163 intel_sdvo_dvi_init(
struct intel_sdvo *intel_sdvo,
int device)
2169 struct intel_sdvo_connector *intel_sdvo_connector;
2171 intel_sdvo_connector = kzalloc(
sizeof(
struct intel_sdvo_connector),
GFP_KERNEL);
2172 if (!intel_sdvo_connector)
2178 }
else if (device == 1) {
2183 intel_connector = &intel_sdvo_connector->
base;
2184 connector = &intel_connector->
base;
2185 if (intel_sdvo_get_hotplug_support(intel_sdvo) &
2192 intel_encoder->
hot_plug = intel_sdvo_enable_hotplug;
2193 intel_sdvo_enable_hotplug(intel_encoder);
2200 if (intel_sdvo_is_hdmi_connector(intel_sdvo, device)) {
2205 intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo);
2207 intel_sdvo_add_hdmi_properties(intel_sdvo_connector);
2213 intel_sdvo_tv_init(
struct intel_sdvo *intel_sdvo,
int type)
2217 struct intel_connector *intel_connector;
2218 struct intel_sdvo_connector *intel_sdvo_connector;
2220 intel_sdvo_connector = kzalloc(
sizeof(
struct intel_sdvo_connector),
GFP_KERNEL);
2221 if (!intel_sdvo_connector)
2224 intel_connector = &intel_sdvo_connector->
base;
2225 connector = &intel_connector->
base;
2232 intel_sdvo->
is_tv =
true;
2233 intel_sdvo->
base.needs_tv_clock =
true;
2235 intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo);
2237 if (!intel_sdvo_tv_create_property(intel_sdvo, intel_sdvo_connector, type))
2240 if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
2246 intel_sdvo_destroy(connector);
2251 intel_sdvo_analog_init(
struct intel_sdvo *intel_sdvo,
int device)
2255 struct intel_connector *intel_connector;
2256 struct intel_sdvo_connector *intel_sdvo_connector;
2258 intel_sdvo_connector = kzalloc(
sizeof(
struct intel_sdvo_connector),
GFP_KERNEL);
2259 if (!intel_sdvo_connector)
2262 intel_connector = &intel_sdvo_connector->
base;
2263 connector = &intel_connector->
base;
2271 }
else if (device == 1) {
2276 intel_sdvo_connector_init(intel_sdvo_connector,
2282 intel_sdvo_lvds_init(
struct intel_sdvo *intel_sdvo,
int device)
2286 struct intel_connector *intel_connector;
2287 struct intel_sdvo_connector *intel_sdvo_connector;
2289 intel_sdvo_connector = kzalloc(
sizeof(
struct intel_sdvo_connector),
GFP_KERNEL);
2290 if (!intel_sdvo_connector)
2293 intel_connector = &intel_sdvo_connector->
base;
2294 connector = &intel_connector->
base;
2301 }
else if (device == 1) {
2306 intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo);
2307 if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
2313 intel_sdvo_destroy(connector);
2318 intel_sdvo_output_setup(
struct intel_sdvo *intel_sdvo,
uint16_t flags)
2320 intel_sdvo->
is_tv =
false;
2321 intel_sdvo->
base.needs_tv_clock =
false;
2327 if (!intel_sdvo_dvi_init(intel_sdvo, 0))
2331 if (!intel_sdvo_dvi_init(intel_sdvo, 1))
2336 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_SVID0))
2340 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_CVBS0))
2344 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_YPRPB0))
2348 if (!intel_sdvo_analog_init(intel_sdvo, 0))
2352 if (!intel_sdvo_analog_init(intel_sdvo, 1))
2356 if (!intel_sdvo_lvds_init(intel_sdvo, 0))
2360 if (!intel_sdvo_lvds_init(intel_sdvo, 1))
2364 unsigned char bytes[2];
2367 memcpy(bytes, &intel_sdvo->
caps.output_flags, 2);
2368 DRM_DEBUG_KMS(
"%s: Unknown SDVO output type (0x%02x%02x)\n",
2370 bytes[0], bytes[1]);
2373 intel_sdvo->
base.crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
2378 static void intel_sdvo_output_cleanup(
struct intel_sdvo *intel_sdvo)
2384 &dev->mode_config.connector_list,
head) {
2385 if (intel_attached_encoder(connector) == &intel_sdvo->
base)
2386 intel_sdvo_destroy(connector);
2390 static bool intel_sdvo_tv_create_property(
struct intel_sdvo *intel_sdvo,
2391 struct intel_sdvo_connector *intel_sdvo_connector,
2398 if (!intel_sdvo_set_target_output(intel_sdvo, type))
2402 if (!intel_sdvo_get_value(intel_sdvo,
2409 if (format_map == 0)
2414 if (format_map & (1 << i))
2436 #define ENHANCEMENT(name, NAME) do { \
2437 if (enhancements.name) { \
2438 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_MAX_##NAME, &data_value, 4) || \
2439 !intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_##NAME, &response, 2)) \
2441 intel_sdvo_connector->max_##name = data_value[0]; \
2442 intel_sdvo_connector->cur_##name = response; \
2443 intel_sdvo_connector->name = \
2444 drm_property_create_range(dev, 0, #name, 0, data_value[0]); \
2445 if (!intel_sdvo_connector->name) return false; \
2446 drm_connector_attach_property(connector, \
2447 intel_sdvo_connector->name, \
2448 intel_sdvo_connector->cur_##name); \
2449 DRM_DEBUG_KMS(#name ": max %d, default %d, current %d\n", \
2450 data_value[0], data_value[1], response); \
2455 intel_sdvo_create_enhance_property_tv(
struct intel_sdvo *intel_sdvo,
2456 struct intel_sdvo_connector *intel_sdvo_connector,
2465 if (!intel_sdvo_get_value(intel_sdvo,
2470 if (!intel_sdvo_get_value(intel_sdvo,
2475 intel_sdvo_connector->
max_hscan = data_value[0];
2478 intel_sdvo_connector->
left =
2480 if (!intel_sdvo_connector->
left)
2484 intel_sdvo_connector->
left,
2487 intel_sdvo_connector->
right =
2489 if (!intel_sdvo_connector->
right)
2493 intel_sdvo_connector->
right,
2495 DRM_DEBUG_KMS(
"h_overscan: max %d, "
2496 "default %d, current %d\n",
2497 data_value[0], data_value[1], response);
2501 if (!intel_sdvo_get_value(intel_sdvo,
2506 if (!intel_sdvo_get_value(intel_sdvo,
2511 intel_sdvo_connector->
max_vscan = data_value[0];
2514 intel_sdvo_connector->
top =
2516 "top_margin", 0, data_value[0]);
2517 if (!intel_sdvo_connector->
top)
2521 intel_sdvo_connector->
top,
2524 intel_sdvo_connector->
bottom =
2526 "bottom_margin", 0, data_value[0]);
2527 if (!intel_sdvo_connector->
bottom)
2531 intel_sdvo_connector->
bottom,
2533 DRM_DEBUG_KMS(
"v_overscan: max %d, "
2534 "default %d, current %d\n",
2535 data_value[0], data_value[1], response);
2565 DRM_DEBUG_KMS(
"dot crawl: current %d\n", response);
2572 intel_sdvo_create_enhance_property_lvds(
struct intel_sdvo *intel_sdvo,
2573 struct intel_sdvo_connector *intel_sdvo_connector,
2586 static bool intel_sdvo_create_enhance_property(
struct intel_sdvo *intel_sdvo,
2587 struct intel_sdvo_connector *intel_sdvo_connector)
2596 enhancements.response = 0;
2597 intel_sdvo_get_value(intel_sdvo,
2599 &enhancements,
sizeof(enhancements));
2600 if (enhancements.response == 0) {
2601 DRM_DEBUG_KMS(
"No enhancement is supported\n");
2605 if (
IS_TV(intel_sdvo_connector))
2606 return intel_sdvo_create_enhance_property_tv(intel_sdvo, intel_sdvo_connector, enhancements.reply);
2607 else if (
IS_LVDS(intel_sdvo_connector))
2608 return intel_sdvo_create_enhance_property_lvds(intel_sdvo, intel_sdvo_connector, enhancements.reply);
2617 struct intel_sdvo *sdvo = adapter->
algo_data;
2619 if (!intel_sdvo_set_control_bus_switch(sdvo, sdvo->
ddc_bus))
2622 return sdvo->
i2c->algo->master_xfer(sdvo->
i2c, msgs, num);
2625 static u32 intel_sdvo_ddc_proxy_func(
struct i2c_adapter *adapter)
2627 struct intel_sdvo *sdvo = adapter->
algo_data;
2628 return sdvo->
i2c->algo->functionality(sdvo->
i2c);
2632 .master_xfer = intel_sdvo_ddc_proxy_xfer,
2633 .functionality = intel_sdvo_ddc_proxy_func
2637 intel_sdvo_init_ddc_proxy(
struct intel_sdvo *sdvo,
2643 sdvo->
ddc.dev.parent = &dev->pdev->dev;
2644 sdvo->
ddc.algo_data = sdvo;
2645 sdvo->
ddc.algo = &intel_sdvo_ddc_proxy;
2653 struct intel_encoder *intel_encoder;
2654 struct intel_sdvo *intel_sdvo;
2658 intel_sdvo = kzalloc(
sizeof(
struct intel_sdvo),
GFP_KERNEL);
2664 intel_sdvo->
slave_addr = intel_sdvo_get_slave_addr(dev, intel_sdvo) >> 1;
2665 intel_sdvo_select_i2c_bus(dev_priv, intel_sdvo, sdvo_reg);
2666 if (!intel_sdvo_init_ddc_proxy(intel_sdvo, dev)) {
2672 intel_encoder = &intel_sdvo->
base;
2677 for (i = 0; i < 0x40; i++) {
2680 if (!intel_sdvo_read_byte(intel_sdvo, i, &byte)) {
2681 DRM_DEBUG_KMS(
"No SDVO device found on %s\n",
2689 hotplug_mask = intel_sdvo->
is_sdvob ?
2692 hotplug_mask = intel_sdvo->
is_sdvob ?
2695 hotplug_mask = intel_sdvo->
is_sdvob ?
2699 drm_encoder_helper_add(&intel_encoder->
base, &intel_sdvo_helper_funcs);
2701 intel_encoder->
disable = intel_disable_sdvo;
2702 intel_encoder->
enable = intel_enable_sdvo;
2706 if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->
caps))
2709 if (intel_sdvo_output_setup(intel_sdvo,
2710 intel_sdvo->
caps.output_flags) !=
true) {
2711 DRM_DEBUG_KMS(
"SDVO output failed to setup on %s\n",
2725 intel_sdvo->
base.cloneable =
false;
2733 intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo, sdvo_reg);
2736 if (!intel_sdvo_set_target_input(intel_sdvo))
2739 if (!intel_sdvo_get_input_pixel_clock_range(intel_sdvo,
2744 DRM_DEBUG_KMS(
"%s device VID/DID: %02X:%02X.%02X, "
2745 "clock range %dMHz - %dMHz, "
2746 "input 1: %c, input 2: %c, "
2747 "output 1: %c, output 2: %c\n",
2749 intel_sdvo->
caps.vendor_id, intel_sdvo->
caps.device_id,
2750 intel_sdvo->
caps.device_rev_id,
2753 (intel_sdvo->
caps.sdvo_inputs_mask & 0x1) ?
'Y' :
'N',
2754 (intel_sdvo->
caps.sdvo_inputs_mask & 0x2) ?
'Y' :
'N',
2756 intel_sdvo->
caps.output_flags &
2757 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ?
'Y' :
'N',
2758 intel_sdvo->
caps.output_flags &
2763 intel_sdvo_output_cleanup(intel_sdvo);