Subversion Repositories Kolibri OS

Rev

Rev 3746 | Rev 4560 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3746 Rev 4104
Line 78... Line 78...
78
    /* Active outputs controlled by this SDVO output */
78
    /* Active outputs controlled by this SDVO output */
79
    uint16_t controlled_output;
79
    uint16_t controlled_output;
Line 80... Line 80...
80
 
80
 
81
    /*
81
    /*
82
     * Capabilities of the SDVO device returned by
82
     * Capabilities of the SDVO device returned by
83
     * i830_sdvo_get_capabilities()
83
	 * intel_sdvo_get_capabilities()
84
     */
84
     */
Line 85... Line 85...
85
    struct intel_sdvo_caps caps;
85
    struct intel_sdvo_caps caps;
86
 
86
 
Line 200... Line 200...
200
    u32 cur_tv_chroma_filter,   max_tv_chroma_filter;
200
    u32 cur_tv_chroma_filter,   max_tv_chroma_filter;
201
    u32 cur_tv_luma_filter, max_tv_luma_filter;
201
    u32 cur_tv_luma_filter, max_tv_luma_filter;
202
    u32 cur_dot_crawl,  max_dot_crawl;
202
    u32 cur_dot_crawl,  max_dot_crawl;
203
};
203
};
Line 204... Line 204...
204
 
204
 
205
static struct intel_sdvo *to_intel_sdvo(struct drm_encoder *encoder)
205
static struct intel_sdvo *to_sdvo(struct intel_encoder *encoder)
206
{
206
{
207
    return container_of(encoder, struct intel_sdvo, base.base);
207
	return container_of(encoder, struct intel_sdvo, base);
Line 208... Line 208...
208
}
208
}
209
 
209
 
210
static struct intel_sdvo *intel_attached_sdvo(struct drm_connector *connector)
210
static struct intel_sdvo *intel_attached_sdvo(struct drm_connector *connector)
211
{
-
 
212
	return container_of(intel_attached_encoder(connector),
211
{
Line 213... Line 212...
213
			    struct intel_sdvo, base);
212
	return to_sdvo(intel_attached_encoder(connector));
214
}
213
}
215
 
214
 
Line 537... Line 536...
537
	if (!intel_sdvo_read_byte(intel_sdvo,
536
	if (!intel_sdvo_read_byte(intel_sdvo,
538
				  SDVO_I2C_CMD_STATUS,
537
				  SDVO_I2C_CMD_STATUS,
539
				  &status))
538
				  &status))
540
		goto log_fail;
539
		goto log_fail;
Line 541... Line 540...
541
 
540
 
-
 
541
	while ((status == SDVO_CMD_STATUS_PENDING ||
542
	while (status == SDVO_CMD_STATUS_PENDING && --retry) {
542
			status == SDVO_CMD_STATUS_TARGET_NOT_SPECIFIED) && --retry) {
543
		if (retry < 10)
543
		if (retry < 10)
544
			msleep(15);
544
			msleep(15);
545
		else
545
		else
Line 710... Line 710...
710
{
710
{
711
	return intel_sdvo_set_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
711
	return intel_sdvo_set_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
712
		intel_sdvo_set_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
712
		intel_sdvo_set_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
713
}
713
}
Line -... Line 714...
-
 
714
 
-
 
715
static bool intel_sdvo_get_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
-
 
716
				  struct intel_sdvo_dtd *dtd)
-
 
717
{
-
 
718
	return intel_sdvo_get_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
-
 
719
		intel_sdvo_get_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
-
 
720
}
714
 
721
 
715
static bool intel_sdvo_set_input_timing(struct intel_sdvo *intel_sdvo,
722
static bool intel_sdvo_set_input_timing(struct intel_sdvo *intel_sdvo,
716
					 struct intel_sdvo_dtd *dtd)
723
					 struct intel_sdvo_dtd *dtd)
717
{
724
{
718
	return intel_sdvo_set_timing(intel_sdvo,
725
	return intel_sdvo_set_timing(intel_sdvo,
Line 724... Line 731...
724
{
731
{
725
	return intel_sdvo_set_timing(intel_sdvo,
732
	return intel_sdvo_set_timing(intel_sdvo,
726
				     SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
733
				     SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
727
}
734
}
Line -... Line 735...
-
 
735
 
-
 
736
static bool intel_sdvo_get_input_timing(struct intel_sdvo *intel_sdvo,
-
 
737
					struct intel_sdvo_dtd *dtd)
-
 
738
{
-
 
739
	return intel_sdvo_get_timing(intel_sdvo,
-
 
740
				     SDVO_CMD_GET_INPUT_TIMINGS_PART1, dtd);
-
 
741
}
728
 
742
 
729
static bool
743
static bool
730
intel_sdvo_create_preferred_input_timing(struct intel_sdvo *intel_sdvo,
744
intel_sdvo_create_preferred_input_timing(struct intel_sdvo *intel_sdvo,
731
					 uint16_t clock,
745
					 uint16_t clock,
732
					 uint16_t width,
746
					 uint16_t width,
Line 772... Line 786...
772
	uint16_t width, height;
786
	uint16_t width, height;
773
	uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
787
	uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
774
	uint16_t h_sync_offset, v_sync_offset;
788
	uint16_t h_sync_offset, v_sync_offset;
775
	int mode_clock;
789
	int mode_clock;
Line -... Line 790...
-
 
790
 
-
 
791
	memset(dtd, 0, sizeof(*dtd));
776
 
792
 
777
	width = mode->hdisplay;
793
	width = mode->hdisplay;
Line 778... Line 794...
778
	height = mode->vdisplay;
794
	height = mode->vdisplay;
779
 
795
 
Line 814... Line 830...
814
	if (mode->flags & DRM_MODE_FLAG_PHSYNC)
830
	if (mode->flags & DRM_MODE_FLAG_PHSYNC)
815
		dtd->part2.dtd_flags |= DTD_FLAG_HSYNC_POSITIVE;
831
		dtd->part2.dtd_flags |= DTD_FLAG_HSYNC_POSITIVE;
816
	if (mode->flags & DRM_MODE_FLAG_PVSYNC)
832
	if (mode->flags & DRM_MODE_FLAG_PVSYNC)
817
		dtd->part2.dtd_flags |= DTD_FLAG_VSYNC_POSITIVE;
833
		dtd->part2.dtd_flags |= DTD_FLAG_VSYNC_POSITIVE;
Line 818... Line -...
818
 
-
 
819
	dtd->part2.sdvo_flags = 0;
834
 
820
	dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
-
 
821
	dtd->part2.reserved = 0;
835
	dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
Line 822... Line 836...
822
}
836
}
823
 
837
 
824
static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode,
838
static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode *pmode,
-
 
839
					 const struct intel_sdvo_dtd *dtd)
-
 
840
{
825
					 const struct intel_sdvo_dtd *dtd)
841
	struct drm_display_mode mode = {};
826
{
842
 
827
	mode->hdisplay = dtd->part1.h_active;
843
	mode.hdisplay = dtd->part1.h_active;
828
	mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
844
	mode.hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
829
	mode->hsync_start = mode->hdisplay + dtd->part2.h_sync_off;
845
	mode.hsync_start = mode.hdisplay + dtd->part2.h_sync_off;
830
	mode->hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
846
	mode.hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
831
	mode->hsync_end = mode->hsync_start + dtd->part2.h_sync_width;
847
	mode.hsync_end = mode.hsync_start + dtd->part2.h_sync_width;
832
	mode->hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
848
	mode.hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
833
	mode->htotal = mode->hdisplay + dtd->part1.h_blank;
849
	mode.htotal = mode.hdisplay + dtd->part1.h_blank;
834
	mode->htotal += (dtd->part1.h_high & 0xf) << 8;
850
	mode.htotal += (dtd->part1.h_high & 0xf) << 8;
835
 
851
 
836
	mode->vdisplay = dtd->part1.v_active;
852
	mode.vdisplay = dtd->part1.v_active;
837
	mode->vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
853
	mode.vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
838
	mode->vsync_start = mode->vdisplay;
854
	mode.vsync_start = mode.vdisplay;
839
	mode->vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
855
	mode.vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
840
	mode->vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
856
	mode.vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
841
	mode->vsync_start += dtd->part2.v_sync_off_high & 0xc0;
857
	mode.vsync_start += dtd->part2.v_sync_off_high & 0xc0;
842
	mode->vsync_end = mode->vsync_start +
858
	mode.vsync_end = mode.vsync_start +
843
		(dtd->part2.v_sync_off_width & 0xf);
859
		(dtd->part2.v_sync_off_width & 0xf);
844
	mode->vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
860
	mode.vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
Line 845... Line 861...
845
	mode->vtotal = mode->vdisplay + dtd->part1.v_blank;
861
	mode.vtotal = mode.vdisplay + dtd->part1.v_blank;
Line 846... Line -...
846
	mode->vtotal += (dtd->part1.v_high & 0xf) << 8;
-
 
847
 
862
	mode.vtotal += (dtd->part1.v_high & 0xf) << 8;
848
	mode->clock = dtd->part1.clock * 10;
863
 
849
 
864
	mode.clock = dtd->part1.clock * 10;
850
	mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC);
865
 
-
 
866
	if (dtd->part2.dtd_flags & DTD_FLAG_INTERLACE)
-
 
867
		mode.flags |= DRM_MODE_FLAG_INTERLACE;
851
	if (dtd->part2.dtd_flags & DTD_FLAG_INTERLACE)
868
	if (dtd->part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
852
		mode->flags |= DRM_MODE_FLAG_INTERLACE;
869
		mode.flags |= DRM_MODE_FLAG_PHSYNC;
-
 
870
	else
-
 
871
		mode.flags |= DRM_MODE_FLAG_NHSYNC;
-
 
872
	if (dtd->part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
-
 
873
		mode.flags |= DRM_MODE_FLAG_PVSYNC;
-
 
874
	else
-
 
875
		mode.flags |= DRM_MODE_FLAG_NVSYNC;
853
	if (dtd->part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
876
 
Line 854... Line 877...
854
		mode->flags |= DRM_MODE_FLAG_PHSYNC;
877
	drm_mode_set_crtcinfo(&mode, 0);
855
	if (dtd->part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
878
 
856
		mode->flags |= DRM_MODE_FLAG_PVSYNC;
879
	drm_mode_copy(pmode, &mode);
Line 948... Line 971...
948
}
971
}
Line 949... Line 972...
949
 
972
 
950
static bool intel_sdvo_set_avi_infoframe(struct intel_sdvo *intel_sdvo,
973
static bool intel_sdvo_set_avi_infoframe(struct intel_sdvo *intel_sdvo,
951
					 const struct drm_display_mode *adjusted_mode)
974
					 const struct drm_display_mode *adjusted_mode)
-
 
975
{
952
{
976
	uint8_t sdvo_data[HDMI_INFOFRAME_SIZE(AVI)];
953
	struct dip_infoframe avi_if = {
977
	struct drm_crtc *crtc = intel_sdvo->base.base.crtc;
954
		.type = DIP_TYPE_AVI,
978
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
979
	union hdmi_infoframe frame;
955
		.ver = DIP_VERSION_AVI,
980
	int ret;
956
		.len = DIP_LEN_AVI,
981
	ssize_t len;
957
	};
982
 
-
 
983
	ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
-
 
984
						       adjusted_mode);
958
	uint8_t sdvo_data[4 + sizeof(avi_if.body.avi)];
985
	if (ret < 0) {
-
 
986
		DRM_ERROR("couldn't fill AVI infoframe\n");
-
 
987
		return false;
Line 959... Line 988...
959
	struct intel_crtc *intel_crtc = to_intel_crtc(intel_sdvo->base.base.crtc);
988
	}
960
 
989
 
-
 
990
	if (intel_sdvo->rgb_quant_range_selectable) {
961
	if (intel_sdvo->rgb_quant_range_selectable) {
991
		if (intel_crtc->config.limited_color_range)
962
		if (intel_crtc->config.limited_color_range)
992
			frame.avi.quantization_range =
-
 
993
				HDMI_QUANTIZATION_RANGE_LIMITED;
963
			avi_if.body.avi.ITC_EC_Q_SC |= DIP_AVI_RGB_QUANT_RANGE_LIMITED;
994
		else
964
		else
995
			frame.avi.quantization_range =
Line 965... Line -...
965
			avi_if.body.avi.ITC_EC_Q_SC |= DIP_AVI_RGB_QUANT_RANGE_FULL;
-
 
966
	}
-
 
967
 
996
				HDMI_QUANTIZATION_RANGE_FULL;
968
	avi_if.body.avi.VIC = drm_match_cea_mode(adjusted_mode);
-
 
969
 
-
 
970
	intel_dip_infoframe_csum(&avi_if);
-
 
971
 
997
	}
972
	/* sdvo spec says that the ecc is handled by the hw, and it looks like
998
 
973
	 * we must not send the ecc field, either. */
-
 
Line 974... Line 999...
974
	memcpy(sdvo_data, &avi_if, 3);
999
	len = hdmi_infoframe_pack(&frame, sdvo_data, sizeof(sdvo_data));
975
	sdvo_data[3] = avi_if.checksum;
1000
	if (len < 0)
976
	memcpy(&sdvo_data[4], &avi_if.body, sizeof(avi_if.body.avi));
1001
		return false;
977
 
1002
 
Line 1039... Line 1064...
1039
	intel_sdvo->dtd_sdvo_flags = input_dtd.part2.sdvo_flags;
1064
	intel_sdvo->dtd_sdvo_flags = input_dtd.part2.sdvo_flags;
Line 1040... Line 1065...
1040
 
1065
 
1041
	return true;
1066
	return true;
Line -... Line 1067...
-
 
1067
}
-
 
1068
 
-
 
1069
static void i9xx_adjust_sdvo_tv_clock(struct intel_crtc_config *pipe_config)
-
 
1070
{
-
 
1071
	unsigned dotclock = pipe_config->adjusted_mode.clock;
-
 
1072
	struct dpll *clock = &pipe_config->dpll;
-
 
1073
 
-
 
1074
	/* SDVO TV has fixed PLL values depend on its clock range,
-
 
1075
	   this mirrors vbios setting. */
-
 
1076
	if (dotclock >= 100000 && dotclock < 140500) {
-
 
1077
		clock->p1 = 2;
-
 
1078
		clock->p2 = 10;
-
 
1079
		clock->n = 3;
-
 
1080
		clock->m1 = 16;
-
 
1081
		clock->m2 = 8;
-
 
1082
	} else if (dotclock >= 140500 && dotclock <= 200000) {
-
 
1083
		clock->p1 = 1;
-
 
1084
		clock->p2 = 10;
-
 
1085
		clock->n = 6;
-
 
1086
		clock->m1 = 12;
-
 
1087
		clock->m2 = 8;
-
 
1088
	} else {
-
 
1089
		WARN(1, "SDVO TV clock out of range: %i\n", dotclock);
-
 
1090
	}
-
 
1091
 
-
 
1092
	pipe_config->clock_set = true;
1042
}
1093
}
1043
 
1094
 
1044
static bool intel_sdvo_compute_config(struct intel_encoder *encoder,
1095
static bool intel_sdvo_compute_config(struct intel_encoder *encoder,
1045
				      struct intel_crtc_config *pipe_config)
1096
				      struct intel_crtc_config *pipe_config)
1046
{
1097
{
1047
	struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
1098
	struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
Line 1048... Line 1099...
1048
	struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
1099
	struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
1049
	struct drm_display_mode *mode = &pipe_config->requested_mode;
1100
	struct drm_display_mode *mode = &pipe_config->requested_mode;
Line 1064... Line 1115...
1064
			return false;
1115
			return false;
Line 1065... Line 1116...
1065
 
1116
 
1066
		(void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1117
		(void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1067
							     mode,
1118
							     mode,
-
 
1119
							     adjusted_mode);
1068
							     adjusted_mode);
1120
		pipe_config->sdvo_tv_clock = true;
1069
	} else if (intel_sdvo->is_lvds) {
1121
	} else if (intel_sdvo->is_lvds) {
1070
		if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo,
1122
		if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo,
1071
							     intel_sdvo->sdvo_lvds_fixed_mode))
1123
							     intel_sdvo->sdvo_lvds_fixed_mode))
Line 1095... Line 1147...
1095
	}
1147
	}
Line 1096... Line 1148...
1096
 
1148
 
1097
	if (intel_sdvo->color_range)
1149
	if (intel_sdvo->color_range)
Line -... Line 1150...
-
 
1150
		pipe_config->limited_color_range = true;
-
 
1151
 
-
 
1152
	/* Clock computation needs to happen after pixel multiplier. */
-
 
1153
	if (intel_sdvo->is_tv)
1098
		pipe_config->limited_color_range = true;
1154
		i9xx_adjust_sdvo_tv_clock(pipe_config);
1099
 
1155
 
Line 1100... Line 1156...
1100
	return true;
1156
	return true;
1101
}
1157
}
1102
 
1158
 
1103
static void intel_sdvo_mode_set(struct intel_encoder *intel_encoder)
1159
static void intel_sdvo_mode_set(struct intel_encoder *intel_encoder)
1104
{
1160
{
1105
	struct drm_device *dev = intel_encoder->base.dev;
-
 
1106
	struct drm_i915_private *dev_priv = dev->dev_private;
1161
	struct drm_device *dev = intel_encoder->base.dev;
1107
	struct drm_crtc *crtc = intel_encoder->base.crtc;
1162
	struct drm_i915_private *dev_priv = dev->dev_private;
1108
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1163
	struct intel_crtc *crtc = to_intel_crtc(intel_encoder->base.crtc);
1109
	struct drm_display_mode *adjusted_mode =
1164
	struct drm_display_mode *adjusted_mode =
1110
		&intel_crtc->config.adjusted_mode;
1165
		&crtc->config.adjusted_mode;
1111
	struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
1166
	struct drm_display_mode *mode = &crtc->config.requested_mode;
1112
	struct intel_sdvo *intel_sdvo = to_intel_sdvo(&intel_encoder->base);
1167
	struct intel_sdvo *intel_sdvo = to_sdvo(intel_encoder);
1113
	u32 sdvox;
1168
	u32 sdvox;
Line 1164... Line 1219...
1164
 
1219
 
1165
	/* We have tried to get input timing in mode_fixup, and filled into
1220
	/* We have tried to get input timing in mode_fixup, and filled into
1166
	 * adjusted_mode.
1221
	 * adjusted_mode.
1167
	 */
1222
	 */
-
 
1223
	intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
-
 
1224
	input_dtd.part1.clock /= crtc->config.pixel_multiplier;
1168
	intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
1225
 
1169
	if (intel_sdvo->is_tv || intel_sdvo->is_lvds)
1226
	if (intel_sdvo->is_tv || intel_sdvo->is_lvds)
1170
		input_dtd.part2.sdvo_flags = intel_sdvo->dtd_sdvo_flags;
1227
		input_dtd.part2.sdvo_flags = intel_sdvo->dtd_sdvo_flags;
1171
	if (!intel_sdvo_set_input_timing(intel_sdvo, &input_dtd))
1228
	if (!intel_sdvo_set_input_timing(intel_sdvo, &input_dtd))
1172
		DRM_INFO("Setting input timings on %s failed\n",
1229
		DRM_INFO("Setting input timings on %s failed\n",
Line 1173... Line 1230...
1173
			 SDVO_NAME(intel_sdvo));
1230
			 SDVO_NAME(intel_sdvo));
1174
 
1231
 
-
 
1232
	switch (crtc->config.pixel_multiplier) {
1175
	switch (intel_crtc->config.pixel_multiplier) {
1233
	default:
1176
	default:
1234
		WARN(1, "unknown pixel mutlipler specified\n");
1177
	case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break;
1235
	case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break;
1178
	case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break;
1236
	case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break;
1179
	case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break;
1237
	case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break;
Line 1202... Line 1260...
1202
		}
1260
		}
1203
		sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
1261
		sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
1204
	}
1262
	}
Line 1205... Line 1263...
1205
 
1263
 
1206
	if (INTEL_PCH_TYPE(dev) >= PCH_CPT)
1264
	if (INTEL_PCH_TYPE(dev) >= PCH_CPT)
1207
		sdvox |= SDVO_PIPE_SEL_CPT(intel_crtc->pipe);
1265
		sdvox |= SDVO_PIPE_SEL_CPT(crtc->pipe);
1208
	else
1266
	else
Line 1209... Line 1267...
1209
		sdvox |= SDVO_PIPE_SEL(intel_crtc->pipe);
1267
		sdvox |= SDVO_PIPE_SEL(crtc->pipe);
1210
 
1268
 
Line 1211... Line 1269...
1211
	if (intel_sdvo->has_hdmi_audio)
1269
	if (intel_sdvo->has_hdmi_audio)
1212
		sdvox |= SDVO_AUDIO_ENABLE;
1270
		sdvox |= SDVO_AUDIO_ENABLE;
1213
 
1271
 
1214
	if (INTEL_INFO(dev)->gen >= 4) {
1272
	if (INTEL_INFO(dev)->gen >= 4) {
1215
		/* done in crtc_mode_set as the dpll_md reg must be written early */
1273
		/* done in crtc_mode_set as the dpll_md reg must be written early */
1216
	} else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
1274
	} else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
1217
		/* done in crtc_mode_set as it lives inside the dpll register */
1275
		/* done in crtc_mode_set as it lives inside the dpll register */
1218
	} else {
1276
	} else {
Line 1219... Line 1277...
1219
		sdvox |= (intel_crtc->config.pixel_multiplier - 1)
1277
		sdvox |= (crtc->config.pixel_multiplier - 1)
1220
			<< SDVO_PORT_MULTIPLY_SHIFT;
1278
			<< SDVO_PORT_MULTIPLY_SHIFT;
Line 1229... Line 1287...
1229
static bool intel_sdvo_connector_get_hw_state(struct intel_connector *connector)
1287
static bool intel_sdvo_connector_get_hw_state(struct intel_connector *connector)
1230
{
1288
{
1231
	struct intel_sdvo_connector *intel_sdvo_connector =
1289
	struct intel_sdvo_connector *intel_sdvo_connector =
1232
		to_intel_sdvo_connector(&connector->base);
1290
		to_intel_sdvo_connector(&connector->base);
1233
	struct intel_sdvo *intel_sdvo = intel_attached_sdvo(&connector->base);
1291
	struct intel_sdvo *intel_sdvo = intel_attached_sdvo(&connector->base);
1234
	u16 active_outputs;
1292
	u16 active_outputs = 0;
Line 1235... Line 1293...
1235
 
1293
 
Line 1236... Line 1294...
1236
	intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1294
	intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1237
 
1295
 
Line 1244... Line 1302...
1244
static bool intel_sdvo_get_hw_state(struct intel_encoder *encoder,
1302
static bool intel_sdvo_get_hw_state(struct intel_encoder *encoder,
1245
				    enum pipe *pipe)
1303
				    enum pipe *pipe)
1246
{
1304
{
1247
	struct drm_device *dev = encoder->base.dev;
1305
	struct drm_device *dev = encoder->base.dev;
1248
	struct drm_i915_private *dev_priv = dev->dev_private;
1306
	struct drm_i915_private *dev_priv = dev->dev_private;
1249
	struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
1307
	struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1250
	u16 active_outputs;
1308
	u16 active_outputs = 0;
1251
	u32 tmp;
1309
	u32 tmp;
Line 1252... Line 1310...
1252
 
1310
 
1253
	tmp = I915_READ(intel_sdvo->sdvo_reg);
1311
	tmp = I915_READ(intel_sdvo->sdvo_reg);
Line 1262... Line 1320...
1262
		*pipe = PORT_TO_PIPE(tmp);
1320
		*pipe = PORT_TO_PIPE(tmp);
Line 1263... Line 1321...
1263
 
1321
 
1264
	return true;
1322
	return true;
Line -... Line 1323...
-
 
1323
}
-
 
1324
 
-
 
1325
static void intel_sdvo_get_config(struct intel_encoder *encoder,
-
 
1326
				  struct intel_crtc_config *pipe_config)
-
 
1327
{
-
 
1328
	struct drm_device *dev = encoder->base.dev;
-
 
1329
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
1330
	struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
-
 
1331
	struct intel_sdvo_dtd dtd;
-
 
1332
	int encoder_pixel_multiplier = 0;
-
 
1333
	u32 flags = 0, sdvox;
-
 
1334
	u8 val;
-
 
1335
	bool ret;
-
 
1336
 
-
 
1337
	ret = intel_sdvo_get_input_timing(intel_sdvo, &dtd);
-
 
1338
	if (!ret) {
-
 
1339
		/* Some sdvo encoders are not spec compliant and don't
-
 
1340
		 * implement the mandatory get_timings function. */
-
 
1341
		DRM_DEBUG_DRIVER("failed to retrieve SDVO DTD\n");
-
 
1342
		pipe_config->quirks |= PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS;
-
 
1343
	} else {
-
 
1344
		if (dtd.part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
-
 
1345
			flags |= DRM_MODE_FLAG_PHSYNC;
-
 
1346
		else
-
 
1347
			flags |= DRM_MODE_FLAG_NHSYNC;
-
 
1348
 
-
 
1349
		if (dtd.part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
-
 
1350
			flags |= DRM_MODE_FLAG_PVSYNC;
-
 
1351
		else
-
 
1352
			flags |= DRM_MODE_FLAG_NVSYNC;
-
 
1353
	}
-
 
1354
 
-
 
1355
	pipe_config->adjusted_mode.flags |= flags;
-
 
1356
 
-
 
1357
	/*
-
 
1358
	 * pixel multiplier readout is tricky: Only on i915g/gm it is stored in
-
 
1359
	 * the sdvo port register, on all other platforms it is part of the dpll
-
 
1360
	 * state. Since the general pipe state readout happens before the
-
 
1361
	 * encoder->get_config we so already have a valid pixel multplier on all
-
 
1362
	 * other platfroms.
-
 
1363
	 */
-
 
1364
	if (IS_I915G(dev) || IS_I915GM(dev)) {
-
 
1365
		sdvox = I915_READ(intel_sdvo->sdvo_reg);
-
 
1366
		pipe_config->pixel_multiplier =
-
 
1367
			((sdvox & SDVO_PORT_MULTIPLY_MASK)
-
 
1368
			 >> SDVO_PORT_MULTIPLY_SHIFT) + 1;
-
 
1369
	}
-
 
1370
 
-
 
1371
	/* Cross check the port pixel multiplier with the sdvo encoder state. */
-
 
1372
	if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT,
-
 
1373
				 &val, 1)) {
-
 
1374
	switch (val) {
-
 
1375
	case SDVO_CLOCK_RATE_MULT_1X:
-
 
1376
		encoder_pixel_multiplier = 1;
-
 
1377
		break;
-
 
1378
	case SDVO_CLOCK_RATE_MULT_2X:
-
 
1379
		encoder_pixel_multiplier = 2;
-
 
1380
		break;
-
 
1381
	case SDVO_CLOCK_RATE_MULT_4X:
-
 
1382
		encoder_pixel_multiplier = 4;
-
 
1383
		break;
-
 
1384
	}
-
 
1385
	}
-
 
1386
 
-
 
1387
	WARN(encoder_pixel_multiplier != pipe_config->pixel_multiplier,
-
 
1388
	     "SDVO pixel multiplier mismatch, port: %i, encoder: %i\n",
-
 
1389
	     pipe_config->pixel_multiplier, encoder_pixel_multiplier);
1265
}
1390
}
1266
 
1391
 
1267
static void intel_disable_sdvo(struct intel_encoder *encoder)
1392
static void intel_disable_sdvo(struct intel_encoder *encoder)
1268
{
1393
{
1269
	struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1394
	struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Line 1270... Line 1395...
1270
	struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
1395
	struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1271
	u32 temp;
1396
	u32 temp;
1272
 
1397
 
Line 1307... Line 1432...
1307
 
1432
 
1308
static void intel_enable_sdvo(struct intel_encoder *encoder)
1433
static void intel_enable_sdvo(struct intel_encoder *encoder)
1309
{
1434
{
1310
	struct drm_device *dev = encoder->base.dev;
1435
	struct drm_device *dev = encoder->base.dev;
1311
	struct drm_i915_private *dev_priv = dev->dev_private;
1436
	struct drm_i915_private *dev_priv = dev->dev_private;
1312
	struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
1437
	struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1313
	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1438
	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1314
	u32 temp;
1439
	u32 temp;
1315
		bool input1, input2;
1440
		bool input1, input2;
1316
		int i;
1441
		int i;
Line 1342... Line 1467...
1342
		intel_sdvo_set_encoder_power_state(intel_sdvo,
1467
		intel_sdvo_set_encoder_power_state(intel_sdvo,
1343
						   DRM_MODE_DPMS_ON);
1468
						   DRM_MODE_DPMS_ON);
1344
	intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
1469
	intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
1345
}
1470
}
Line -... Line 1471...
-
 
1471
 
1346
 
1472
/* Special dpms function to support cloning between dvo/sdvo/crt. */
1347
static void intel_sdvo_dpms(struct drm_connector *connector, int mode)
1473
static void intel_sdvo_dpms(struct drm_connector *connector, int mode)
1348
{
1474
{
1349
	struct drm_crtc *crtc;
1475
	struct drm_crtc *crtc;
Line 1363... Line 1489...
1363
	if (!crtc) {
1489
	if (!crtc) {
1364
		intel_sdvo->base.connectors_active = false;
1490
		intel_sdvo->base.connectors_active = false;
1365
		return;
1491
		return;
1366
	}
1492
	}
Line -... Line 1493...
-
 
1493
 
-
 
1494
	/* We set active outputs manually below in case pipe dpms doesn't change
1367
 
1495
	 * due to cloning. */
1368
	if (mode != DRM_MODE_DPMS_ON) {
1496
	if (mode != DRM_MODE_DPMS_ON) {
1369
		intel_sdvo_set_active_outputs(intel_sdvo, 0);
1497
		intel_sdvo_set_active_outputs(intel_sdvo, 0);
1370
		if (0)
1498
		if (0)
Line 1465... Line 1593...
1465
	return hotplug;
1593
	return hotplug;
1466
}
1594
}
Line 1467... Line 1595...
1467
 
1595
 
1468
static void intel_sdvo_enable_hotplug(struct intel_encoder *encoder)
1596
static void intel_sdvo_enable_hotplug(struct intel_encoder *encoder)
1469
{
1597
{
Line 1470... Line 1598...
1470
	struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
1598
	struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1471
 
1599
 
1472
	intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG,
1600
	intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG,
Line 1493... Line 1621...
1493
{
1621
{
1494
	struct drm_i915_private *dev_priv = connector->dev->dev_private;
1622
	struct drm_i915_private *dev_priv = connector->dev->dev_private;
Line 1495... Line 1623...
1495
 
1623
 
1496
	return drm_get_edid(connector,
1624
	return drm_get_edid(connector,
1497
			    intel_gmbus_get_adapter(dev_priv,
1625
			    intel_gmbus_get_adapter(dev_priv,
1498
						    dev_priv->crt_ddc_pin));
1626
						    dev_priv->vbt.crt_ddc_pin));
Line 1499... Line 1627...
1499
}
1627
}
1500
 
1628
 
1501
static enum drm_connector_status
1629
static enum drm_connector_status
Line 1578... Line 1706...
1578
	uint16_t response;
1706
	uint16_t response;
1579
	struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1707
	struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1580
	struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1708
	struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1581
	enum drm_connector_status ret;
1709
	enum drm_connector_status ret;
Line -... Line 1710...
-
 
1710
 
-
 
1711
	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
-
 
1712
		      connector->base.id, drm_get_connector_name(connector));
1582
 
1713
 
1583
	if (!intel_sdvo_get_value(intel_sdvo,
1714
	if (!intel_sdvo_get_value(intel_sdvo,
1584
				  SDVO_CMD_GET_ATTACHED_DISPLAYS,
1715
				  SDVO_CMD_GET_ATTACHED_DISPLAYS,
1585
				  &response, 2))
1716
				  &response, 2))
Line 1623... Line 1754...
1623
 
1754
 
1624
	/* May update encoder flag for like clock for SDVO TV, etc.*/
1755
	/* May update encoder flag for like clock for SDVO TV, etc.*/
1625
	if (ret == connector_status_connected) {
1756
	if (ret == connector_status_connected) {
1626
		intel_sdvo->is_tv = false;
1757
		intel_sdvo->is_tv = false;
1627
		intel_sdvo->is_lvds = false;
-
 
Line 1628... Line 1758...
1628
		intel_sdvo->base.needs_tv_clock = false;
1758
		intel_sdvo->is_lvds = false;
1629
 
1759
 
1630
		if (response & SDVO_TV_MASK) {
-
 
1631
			intel_sdvo->is_tv = true;
-
 
1632
			intel_sdvo->base.needs_tv_clock = true;
1760
		if (response & SDVO_TV_MASK)
1633
		}
1761
			intel_sdvo->is_tv = true;
1634
		if (response & SDVO_LVDS_MASK)
1762
		if (response & SDVO_LVDS_MASK)
Line 1635... Line 1763...
1635
			intel_sdvo->is_lvds = intel_sdvo->sdvo_lvds_fixed_mode != NULL;
1763
			intel_sdvo->is_lvds = intel_sdvo->sdvo_lvds_fixed_mode != NULL;
Line 1770... Line 1898...
1770
	struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1898
	struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1771
	struct drm_i915_private *dev_priv = connector->dev->dev_private;
1899
	struct drm_i915_private *dev_priv = connector->dev->dev_private;
1772
	struct drm_display_mode *newmode;
1900
	struct drm_display_mode *newmode;
Line 1773... Line 1901...
1773
 
1901
 
1774
	/*
-
 
1775
	 * Attempt to get the mode list from DDC.
-
 
1776
	 * Assume that the preferred modes are
-
 
1777
	 * arranged in priority order.
-
 
1778
	 */
-
 
1779
	intel_ddc_get_modes(connector, &intel_sdvo->ddc);
-
 
1780
 
-
 
1781
	/*
1902
	/*
1782
	 * Fetch modes from VBT. For SDVO prefer the VBT mode since some
1903
	 * Fetch modes from VBT. For SDVO prefer the VBT mode since some
1783
	 * SDVO->LVDS transcoders can't cope with the EDID mode. Since
-
 
1784
	 * drm_mode_probed_add adds the mode at the head of the list we add it
-
 
1785
	 * last.
1904
	 * SDVO->LVDS transcoders can't cope with the EDID mode.
1786
	 */
1905
	 */
1787
	if (dev_priv->sdvo_lvds_vbt_mode != NULL) {
1906
	if (dev_priv->vbt.sdvo_lvds_vbt_mode != NULL) {
1788
		newmode = drm_mode_duplicate(connector->dev,
1907
		newmode = drm_mode_duplicate(connector->dev,
1789
					     dev_priv->sdvo_lvds_vbt_mode);
1908
					     dev_priv->vbt.sdvo_lvds_vbt_mode);
1790
		if (newmode != NULL) {
1909
		if (newmode != NULL) {
1791
			/* Guarantee the mode is preferred */
1910
			/* Guarantee the mode is preferred */
1792
			newmode->type = (DRM_MODE_TYPE_PREFERRED |
1911
			newmode->type = (DRM_MODE_TYPE_PREFERRED |
1793
					 DRM_MODE_TYPE_DRIVER);
1912
					 DRM_MODE_TYPE_DRIVER);
1794
			drm_mode_probed_add(connector, newmode);
1913
			drm_mode_probed_add(connector, newmode);
1795
		}
1914
		}
Line -... Line 1915...
-
 
1915
	}
-
 
1916
 
-
 
1917
	/*
-
 
1918
	 * Attempt to get the mode list from DDC.
-
 
1919
	 * Assume that the preferred modes are
-
 
1920
	 * arranged in priority order.
-
 
1921
	 */
1796
	}
1922
	intel_ddc_get_modes(connector, &intel_sdvo->ddc);
1797
 
1923
 
1798
	list_for_each_entry(newmode, &connector->probed_modes, head) {
1924
	list_for_each_entry(newmode, &connector->probed_modes, head) {
1799
		if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
1925
		if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
Line 2074... Line 2200...
2074
	.best_encoder = intel_best_encoder,
2200
	.best_encoder = intel_best_encoder,
2075
};
2201
};
Line 2076... Line 2202...
2076
 
2202
 
2077
static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
2203
static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
2078
{
2204
{
Line 2079... Line 2205...
2079
	struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder);
2205
	struct intel_sdvo *intel_sdvo = to_sdvo(to_intel_encoder(encoder));
2080
 
2206
 
2081
	if (intel_sdvo->sdvo_lvds_fixed_mode != NULL)
2207
	if (intel_sdvo->sdvo_lvds_fixed_mode != NULL)
Line 2327... Line 2453...
2327
 
2453
 
2328
	intel_sdvo->controlled_output |= type;
2454
	intel_sdvo->controlled_output |= type;
Line 2329... Line 2455...
2329
	intel_sdvo_connector->output_flag = type;
2455
	intel_sdvo_connector->output_flag = type;
2330
 
-
 
Line 2331... Line 2456...
2331
	intel_sdvo->is_tv = true;
2456
 
Line 2332... Line 2457...
2332
	intel_sdvo->base.needs_tv_clock = true;
2457
	intel_sdvo->is_tv = true;
2333
 
2458
 
Line 2415... Line 2540...
2415
 
2540
 
2416
static bool
2541
static bool
2417
intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, uint16_t flags)
2542
intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, uint16_t flags)
2418
{
2543
{
2419
	intel_sdvo->is_tv = false;
-
 
2420
	intel_sdvo->base.needs_tv_clock = false;
2544
	intel_sdvo->is_tv = false;
Line 2421... Line 2545...
2421
	intel_sdvo->is_lvds = false;
2545
	intel_sdvo->is_lvds = false;
Line 2422... Line 2546...
2422
 
2546
 
Line 2749... Line 2873...
2749
bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob)
2873
bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob)
2750
{
2874
{
2751
    struct drm_i915_private *dev_priv = dev->dev_private;
2875
    struct drm_i915_private *dev_priv = dev->dev_private;
2752
    struct intel_encoder *intel_encoder;
2876
    struct intel_encoder *intel_encoder;
2753
    struct intel_sdvo *intel_sdvo;
2877
    struct intel_sdvo *intel_sdvo;
2754
	u32 hotplug_mask;
-
 
2755
    int i;
2878
    int i;
2756
    intel_sdvo = kzalloc(sizeof(struct intel_sdvo), GFP_KERNEL);
2879
    intel_sdvo = kzalloc(sizeof(struct intel_sdvo), GFP_KERNEL);
2757
    if (!intel_sdvo)
2880
    if (!intel_sdvo)
2758
        return false;
2881
        return false;
Line 2778... Line 2901...
2778
				      SDVO_NAME(intel_sdvo));
2901
				      SDVO_NAME(intel_sdvo));
2779
            goto err;
2902
            goto err;
2780
        }
2903
        }
2781
    }
2904
    }
Line 2782... Line -...
2782
 
-
 
2783
	hotplug_mask = 0;
-
 
2784
	if (IS_G4X(dev)) {
-
 
2785
		hotplug_mask = intel_sdvo->is_sdvob ?
-
 
2786
			SDVOB_HOTPLUG_INT_STATUS_G4X : SDVOC_HOTPLUG_INT_STATUS_G4X;
-
 
2787
	} else if (IS_GEN4(dev)) {
-
 
2788
		hotplug_mask = intel_sdvo->is_sdvob ?
-
 
2789
			SDVOB_HOTPLUG_INT_STATUS_I965 : SDVOC_HOTPLUG_INT_STATUS_I965;
-
 
2790
	} else {
-
 
2791
		hotplug_mask = intel_sdvo->is_sdvob ?
-
 
2792
			SDVOB_HOTPLUG_INT_STATUS_I915 : SDVOC_HOTPLUG_INT_STATUS_I915;
-
 
2793
	}
-
 
2794
 
2905
 
2795
	intel_encoder->compute_config = intel_sdvo_compute_config;
2906
	intel_encoder->compute_config = intel_sdvo_compute_config;
2796
	intel_encoder->disable = intel_disable_sdvo;
2907
	intel_encoder->disable = intel_disable_sdvo;
2797
	intel_encoder->mode_set = intel_sdvo_mode_set;
2908
	intel_encoder->mode_set = intel_sdvo_mode_set;
2798
	intel_encoder->enable = intel_enable_sdvo;
2909
	intel_encoder->enable = intel_enable_sdvo;
-
 
2910
	intel_encoder->get_hw_state = intel_sdvo_get_hw_state;
Line 2799... Line 2911...
2799
	intel_encoder->get_hw_state = intel_sdvo_get_hw_state;
2911
	intel_encoder->get_config = intel_sdvo_get_config;
2800
 
2912
 
2801
    /* In default case sdvo lvds is false */
2913
    /* In default case sdvo lvds is false */