Subversion Repositories Kolibri OS

Rev

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

Rev 3482 Rev 3746
Line 22... Line 22...
22
 *
22
 *
23
 * Authors:
23
 * Authors:
24
 *  Eric Anholt 
24
 *  Eric Anholt 
25
 */
25
 */
Line 26... Line 26...
26
 
26
 
27
//#include 
27
//#include 
28
#include 
28
#include 
29
//#include 
29
//#include 
30
#include 
30
#include 
31
#include 
31
#include 
32
#include 
32
#include 
33
//#include 
33
#include 
34
#include 
34
#include 
35
#include 
35
#include 
36
#include "intel_drv.h"
36
#include "intel_drv.h"
37
#include 
37
#include 
Line 41... Line 41...
41
#include 
41
#include 
42
//#include 
42
//#include 
Line 43... Line 43...
43
 
43
 
Line 44... Line -...
44
phys_addr_t get_bus_addr(void);
-
 
45
 
-
 
46
static inline __attribute__((const))
-
 
47
bool is_power_of_2(unsigned long n)
-
 
48
{
-
 
Line 49... Line 44...
49
    return (n != 0 && ((n & (n - 1)) == 0));
44
phys_addr_t get_bus_addr(void);
Line 81... Line 76...
81
#define INTEL_P2_NUM              2
76
#define INTEL_P2_NUM              2
82
typedef struct intel_limit intel_limit_t;
77
typedef struct intel_limit intel_limit_t;
83
struct intel_limit {
78
struct intel_limit {
84
    intel_range_t   dot, vco, n, m, m1, m2, p, p1;
79
    intel_range_t   dot, vco, n, m, m1, m2, p, p1;
85
    intel_p2_t      p2;
80
    intel_p2_t      p2;
-
 
81
	/**
-
 
82
	 * find_pll() - Find the best values for the PLL
-
 
83
	 * @limit: limits for the PLL
-
 
84
	 * @crtc: current CRTC
-
 
85
	 * @target: target frequency in kHz
-
 
86
	 * @refclk: reference clock frequency in kHz
-
 
87
	 * @match_clock: if provided, @best_clock P divider must
-
 
88
	 *               match the P divider from @match_clock
-
 
89
	 *               used for LVDS downclocking
-
 
90
	 * @best_clock: best PLL values found
-
 
91
	 *
-
 
92
	 * Returns true on success, false on failure.
-
 
93
	 */
86
    bool (* find_pll)(const intel_limit_t *, struct drm_crtc *,
94
	bool (*find_pll)(const intel_limit_t *limit,
-
 
95
			 struct drm_crtc *crtc,
-
 
96
			 int target, int refclk,
-
 
97
			 intel_clock_t *match_clock,
87
			int, int, intel_clock_t *, intel_clock_t *);
98
			 intel_clock_t *best_clock);
88
};
99
};
Line 89... Line 100...
89
 
100
 
90
/* FDI */
101
/* FDI */
Line 481... Line 492...
481
	struct drm_device *dev = crtc->dev;
492
	struct drm_device *dev = crtc->dev;
482
	const intel_limit_t *limit;
493
	const intel_limit_t *limit;
Line 483... Line 494...
483
 
494
 
484
	if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
495
	if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
485
		if (intel_is_dual_link_lvds(dev)) {
-
 
486
			/* LVDS dual channel */
496
		if (intel_is_dual_link_lvds(dev)) {
487
			if (refclk == 100000)
497
			if (refclk == 100000)
488
				limit = &intel_limits_ironlake_dual_lvds_100m;
498
				limit = &intel_limits_ironlake_dual_lvds_100m;
489
			else
499
			else
490
				limit = &intel_limits_ironlake_dual_lvds;
500
				limit = &intel_limits_ironlake_dual_lvds;
Line 508... Line 518...
508
	struct drm_device *dev = crtc->dev;
518
	struct drm_device *dev = crtc->dev;
509
	const intel_limit_t *limit;
519
	const intel_limit_t *limit;
Line 510... Line 520...
510
 
520
 
511
	if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
521
	if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
512
		if (intel_is_dual_link_lvds(dev))
-
 
513
			/* LVDS with dual channel */
522
		if (intel_is_dual_link_lvds(dev))
514
			limit = &intel_limits_g4x_dual_channel_lvds;
523
			limit = &intel_limits_g4x_dual_channel_lvds;
515
		else
-
 
516
			/* LVDS with dual channel */
524
		else
517
			limit = &intel_limits_g4x_single_channel_lvds;
525
			limit = &intel_limits_g4x_single_channel_lvds;
518
	} else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
526
	} else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
519
		   intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
527
		   intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
520
		limit = &intel_limits_g4x_hdmi;
528
		limit = &intel_limits_g4x_hdmi;
Line 889... Line 897...
889
					     enum pipe pipe)
897
					     enum pipe pipe)
890
{
898
{
891
	struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
899
	struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
892
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
900
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Line 893... Line 901...
893
 
901
 
894
	return intel_crtc->cpu_transcoder;
902
	return intel_crtc->config.cpu_transcoder;
Line 895... Line 903...
895
}
903
}
896
 
904
 
897
static void ironlake_wait_for_vblank(struct drm_device *dev, int pipe)
905
static void ironlake_wait_for_vblank(struct drm_device *dev, int pipe)
Line 1224... Line 1232...
1224
 
1232
 
1225
	/* if we need the pipe A quirk it must be always on */
1233
	/* if we need the pipe A quirk it must be always on */
1226
	if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
1234
	if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
Line 1227... Line 1235...
1227
		state = true;
1235
		state = true;
1228
 
1236
 
1229
	if (IS_HASWELL(dev_priv->dev) && cpu_transcoder != TRANSCODER_EDP &&
1237
	if (!intel_using_power_well(dev_priv->dev) &&
1230
	    !(I915_READ(HSW_PWR_WELL_DRIVER) & HSW_PWR_WELL_ENABLE)) {
1238
	    cpu_transcoder != TRANSCODER_EDP) {
1231
		cur_state = false;
1239
		cur_state = false;
1232
	} else {
1240
	} else {
1233
	reg = PIPECONF(cpu_transcoder);
1241
	reg = PIPECONF(cpu_transcoder);
Line 1264... Line 1272...
1264
	int reg, i;
1272
	int reg, i;
1265
	u32 val;
1273
	u32 val;
1266
	int cur_pipe;
1274
	int cur_pipe;
Line 1267... Line 1275...
1267
 
1275
 
1268
	/* Planes are fixed to pipes on ILK+ */
1276
	/* Planes are fixed to pipes on ILK+ */
1269
	if (HAS_PCH_SPLIT(dev_priv->dev)) {
1277
	if (HAS_PCH_SPLIT(dev_priv->dev) || IS_VALLEYVIEW(dev_priv->dev)) {
1270
		reg = DSPCNTR(pipe);
1278
		reg = DSPCNTR(pipe);
1271
		val = I915_READ(reg);
1279
		val = I915_READ(reg);
1272
		WARN((val & DISPLAY_PLANE_ENABLE),
1280
		WARN((val & DISPLAY_PLANE_ENABLE),
1273
		     "plane %c assertion failure, should be disabled but not\n",
1281
		     "plane %c assertion failure, should be disabled but not\n",
Line 1285... Line 1293...
1285
		     "plane %c assertion failure, should be off on pipe %c but is still active\n",
1293
		     "plane %c assertion failure, should be off on pipe %c but is still active\n",
1286
		     plane_name(i), pipe_name(pipe));
1294
		     plane_name(i), pipe_name(pipe));
1287
	}
1295
	}
1288
}
1296
}
Line -... Line 1297...
-
 
1297
 
-
 
1298
static void assert_sprites_disabled(struct drm_i915_private *dev_priv,
-
 
1299
				    enum pipe pipe)
-
 
1300
{
-
 
1301
	int reg, i;
-
 
1302
	u32 val;
-
 
1303
 
-
 
1304
	if (!IS_VALLEYVIEW(dev_priv->dev))
-
 
1305
		return;
-
 
1306
 
-
 
1307
	/* Need to check both planes against the pipe */
-
 
1308
	for (i = 0; i < dev_priv->num_plane; i++) {
-
 
1309
		reg = SPCNTR(pipe, i);
-
 
1310
		val = I915_READ(reg);
-
 
1311
		WARN((val & SP_ENABLE),
-
 
1312
		     "sprite %d assertion failure, should be off on pipe %c but is still active\n",
-
 
1313
		     pipe * 2 + i, pipe_name(pipe));
-
 
1314
	}
-
 
1315
}
1289
 
1316
 
1290
static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
1317
static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
1291
{
1318
{
1292
	u32 val;
1319
	u32 val;
Line 1337... Line 1364...
1337
}
1364
}
Line 1338... Line 1365...
1338
 
1365
 
1339
static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
1366
static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
1340
			      enum pipe pipe, u32 val)
1367
			      enum pipe pipe, u32 val)
1341
{
1368
{
1342
	if ((val & PORT_ENABLE) == 0)
1369
	if ((val & SDVO_ENABLE) == 0)
Line 1343... Line 1370...
1343
		return false;
1370
		return false;
1344
 
1371
 
1345
	if (HAS_PCH_CPT(dev_priv->dev)) {
1372
	if (HAS_PCH_CPT(dev_priv->dev)) {
1346
		if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1373
		if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
1347
			return false;
1374
			return false;
1348
	} else {
1375
	} else {
1349
		if ((val & TRANSCODER_MASK) != TRANSCODER(pipe))
1376
		if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
1350
			return false;
1377
			return false;
1351
	}
1378
	}
Line 1402... Line 1429...
1402
	u32 val = I915_READ(reg);
1429
	u32 val = I915_READ(reg);
1403
	WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
1430
	WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
1404
	     "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1431
	     "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1405
	     reg, pipe_name(pipe));
1432
	     reg, pipe_name(pipe));
Line 1406... Line 1433...
1406
 
1433
 
1407
	WARN(HAS_PCH_IBX(dev_priv->dev) && (val & PORT_ENABLE) == 0
1434
	WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0
1408
	     && (val & SDVO_PIPE_B_SELECT),
1435
	     && (val & SDVO_PIPE_B_SELECT),
1409
	     "IBX PCH hdmi port still using transcoder B\n");
1436
	     "IBX PCH hdmi port still using transcoder B\n");
Line 1410... Line 1437...
1410
}
1437
}
Line 1429... Line 1456...
1429
	val = I915_READ(reg);
1456
	val = I915_READ(reg);
1430
	WARN(lvds_pipe_enabled(dev_priv, pipe, val),
1457
	WARN(lvds_pipe_enabled(dev_priv, pipe, val),
1431
	     "PCH LVDS enabled on transcoder %c, should be disabled\n",
1458
	     "PCH LVDS enabled on transcoder %c, should be disabled\n",
1432
	     pipe_name(pipe));
1459
	     pipe_name(pipe));
Line 1433... Line 1460...
1433
 
1460
 
1434
	assert_pch_hdmi_disabled(dev_priv, pipe, HDMIB);
1461
	assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
1435
	assert_pch_hdmi_disabled(dev_priv, pipe, HDMIC);
1462
	assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
1436
	assert_pch_hdmi_disabled(dev_priv, pipe, HDMID);
1463
	assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
Line 1437... Line 1464...
1437
}
1464
}
1438
 
1465
 
1439
/**
1466
/**
Line 1869... Line 1896...
1869
    /*
1896
    /*
1870
	 * Make sure planes won't keep trying to pump pixels to us,
1897
	 * Make sure planes won't keep trying to pump pixels to us,
1871
	 * or we might hang the display.
1898
	 * or we might hang the display.
1872
	 */
1899
	 */
1873
	assert_planes_disabled(dev_priv, pipe);
1900
	assert_planes_disabled(dev_priv, pipe);
-
 
1901
	assert_sprites_disabled(dev_priv, pipe);
Line 1874... Line 1902...
1874
 
1902
 
1875
	/* Don't disable pipe A or pipe A PLLs if needed */
1903
	/* Don't disable pipe A or pipe A PLLs if needed */
1876
	if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
1904
	if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
Line 1947... Line 1975...
1947
	I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
1975
	I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
1948
	intel_flush_display_plane(dev_priv, plane);
1976
	intel_flush_display_plane(dev_priv, plane);
1949
    intel_wait_for_vblank(dev_priv->dev, pipe);
1977
    intel_wait_for_vblank(dev_priv->dev, pipe);
1950
}
1978
}
Line -... Line 1979...
-
 
1979
 
-
 
1980
static bool need_vtd_wa(struct drm_device *dev)
-
 
1981
{
-
 
1982
#ifdef CONFIG_INTEL_IOMMU
-
 
1983
	if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped)
-
 
1984
		return true;
-
 
1985
#endif
-
 
1986
	return false;
-
 
1987
}
1951
 
1988
 
1952
int
1989
int
1953
intel_pin_and_fence_fb_obj(struct drm_device *dev,
1990
intel_pin_and_fence_fb_obj(struct drm_device *dev,
1954
			   struct drm_i915_gem_object *obj,
1991
			   struct drm_i915_gem_object *obj,
1955
			   struct intel_ring_buffer *pipelined)
1992
			   struct intel_ring_buffer *pipelined)
Line 1970... Line 2007...
1970
	case I915_TILING_X:
2007
	case I915_TILING_X:
1971
		/* pin() will align the object as required by fence */
2008
		/* pin() will align the object as required by fence */
1972
		alignment = 0;
2009
		alignment = 0;
1973
		break;
2010
		break;
1974
	case I915_TILING_Y:
2011
	case I915_TILING_Y:
-
 
2012
		/* Despite that we check this in framebuffer_init userspace can
-
 
2013
		 * screw us over and change the tiling after the fact. Only
1975
		/* FIXME: Is this true? */
2014
		 * pinned buffers can't change their tiling. */
1976
		DRM_ERROR("Y tiled not allowed for scan out buffers\n");
2015
		DRM_DEBUG_DRIVER("Y tiled not allowed for scan out buffers\n");
1977
		return -EINVAL;
2016
		return -EINVAL;
1978
	default:
2017
	default:
1979
		BUG();
2018
		BUG();
1980
	}
2019
	}
Line -... Line 2020...
-
 
2020
 
-
 
2021
	/* Note that the w/a also requires 64 PTE of padding following the
-
 
2022
	 * bo. We currently fill all unused PTE with the shadow page and so
-
 
2023
	 * we should always have valid PTE following the scanout preventing
-
 
2024
	 * the VT-d warning.
-
 
2025
	 */
-
 
2026
	if (need_vtd_wa(dev) && alignment < 256 * 1024)
-
 
2027
		alignment = 256 * 1024;
1981
 
2028
 
1982
	dev_priv->mm.interruptible = false;
2029
	dev_priv->mm.interruptible = false;
1983
	ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
2030
	ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
1984
	if (ret)
2031
	if (ret)
Line 2093... Line 2140...
2093
	case DRM_FORMAT_XBGR2101010:
2140
	case DRM_FORMAT_XBGR2101010:
2094
	case DRM_FORMAT_ABGR2101010:
2141
	case DRM_FORMAT_ABGR2101010:
2095
		dspcntr |= DISPPLANE_RGBX101010;
2142
		dspcntr |= DISPPLANE_RGBX101010;
2096
        break;
2143
        break;
2097
    default:
2144
    default:
2098
		DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
-
 
2099
        return -EINVAL;
2145
		BUG();
2100
    }
2146
    }
Line 2101... Line 2147...
2101
 
2147
 
2102
    if (INTEL_INFO(dev)->gen >= 4) {
2148
    if (INTEL_INFO(dev)->gen >= 4) {
2103
        if (obj->tiling_mode != I915_TILING_NONE)
2149
        if (obj->tiling_mode != I915_TILING_NONE)
Line 2187... Line 2233...
2187
	case DRM_FORMAT_XBGR2101010:
2233
	case DRM_FORMAT_XBGR2101010:
2188
	case DRM_FORMAT_ABGR2101010:
2234
	case DRM_FORMAT_ABGR2101010:
2189
		dspcntr |= DISPPLANE_RGBX101010;
2235
		dspcntr |= DISPPLANE_RGBX101010;
2190
        break;
2236
        break;
2191
    default:
2237
    default:
2192
		DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
-
 
2193
        return -EINVAL;
2238
		BUG();
2194
    }
2239
    }
Line 2195... Line 2240...
2195
 
2240
 
2196
	if (obj->tiling_mode != I915_TILING_NONE)
2241
	if (obj->tiling_mode != I915_TILING_NONE)
2197
		dspcntr |= DISPPLANE_TILED;
2242
		dspcntr |= DISPPLANE_TILED;
Line 2280... Line 2325...
2280
	if (!fb) {
2325
	if (!fb) {
2281
		DRM_ERROR("No FB bound\n");
2326
		DRM_ERROR("No FB bound\n");
2282
		return 0;
2327
		return 0;
2283
	}
2328
	}
Line 2284... Line 2329...
2284
 
2329
 
2285
	if(intel_crtc->plane > dev_priv->num_pipe) {
2330
	if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) {
2286
		DRM_ERROR("no plane for crtc: plane %d, num_pipes %d\n",
2331
		DRM_ERROR("no plane for crtc: plane %d, num_pipes %d\n",
2287
				intel_crtc->plane,
2332
				intel_crtc->plane,
2288
				dev_priv->num_pipe);
2333
				INTEL_INFO(dev)->num_pipes);
2289
		return -EINVAL;
2334
		return -EINVAL;
Line 2290... Line 2335...
2290
	}
2335
	}
2291
 
2336
 
Line 2297... Line 2342...
2297
//       mutex_unlock(&dev->struct_mutex);
2342
//       mutex_unlock(&dev->struct_mutex);
2298
//       DRM_ERROR("pin & fence failed\n");
2343
//       DRM_ERROR("pin & fence failed\n");
2299
//       return ret;
2344
//       return ret;
2300
//   }
2345
//   }
Line 2301... Line -...
2301
 
-
 
2302
//   if (crtc->fb)
-
 
Line 2303... Line 2346...
2303
//       intel_finish_fb(crtc->fb);
2346
 
2304
 
2347
 
2305
	ret = dev_priv->display.update_plane(crtc, fb, x, y);
2348
	ret = dev_priv->display.update_plane(crtc, fb, x, y);
2306
	if (ret) {
2349
	if (ret) {
Line 2897... Line 2940...
2897
	intel_finish_fb(crtc->fb);
2940
	intel_finish_fb(crtc->fb);
2898
	mutex_unlock(&dev->struct_mutex);
2941
	mutex_unlock(&dev->struct_mutex);
2899
}
2942
}
2900
#endif
2943
#endif
Line 2901... Line -...
2901
 
-
 
2902
static bool ironlake_crtc_driving_pch(struct drm_crtc *crtc)
-
 
2903
{
-
 
2904
	struct drm_device *dev = crtc->dev;
-
 
2905
	struct intel_encoder *intel_encoder;
-
 
2906
 
-
 
2907
	/*
-
 
2908
	 * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
-
 
2909
	 * must be driven by its own crtc; no sharing is possible.
-
 
2910
	 */
-
 
2911
	for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
-
 
2912
		switch (intel_encoder->type) {
-
 
2913
		case INTEL_OUTPUT_EDP:
-
 
2914
			if (!intel_encoder_is_pch_edp(&intel_encoder->base))
-
 
2915
				return false;
-
 
2916
			continue;
-
 
2917
		}
-
 
2918
	}
-
 
2919
 
-
 
2920
	return true;
-
 
Line 2921... Line -...
2921
}
-
 
2922
 
-
 
2923
static bool haswell_crtc_driving_pch(struct drm_crtc *crtc)
-
 
2924
{
-
 
Line 2925... Line 2944...
2925
	return intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG);
2944
 
2926
}
2945
 
2927
 
2946
 
2928
/* Program iCLKIP clock to the desired frequency */
2947
/* Program iCLKIP clock to the desired frequency */
Line 3129... Line 3148...
3129
static void lpt_pch_enable(struct drm_crtc *crtc)
3148
static void lpt_pch_enable(struct drm_crtc *crtc)
3130
{
3149
{
3131
	struct drm_device *dev = crtc->dev;
3150
	struct drm_device *dev = crtc->dev;
3132
	struct drm_i915_private *dev_priv = dev->dev_private;
3151
	struct drm_i915_private *dev_priv = dev->dev_private;
3133
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3152
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3134
	enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
3153
	enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Line 3135... Line 3154...
3135
 
3154
 
Line 3136... Line 3155...
3136
	assert_transcoder_disabled(dev_priv, TRANSCODER_A);
3155
	assert_transcoder_disabled(dev_priv, TRANSCODER_A);
Line 3258... Line 3277...
3258
    struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3277
    struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3259
	struct intel_encoder *encoder;
3278
	struct intel_encoder *encoder;
3260
    int pipe = intel_crtc->pipe;
3279
    int pipe = intel_crtc->pipe;
3261
    int plane = intel_crtc->plane;
3280
    int plane = intel_crtc->plane;
3262
    u32 temp;
3281
    u32 temp;
3263
    bool is_pch_port;
-
 
Line 3264... Line 3282...
3264
 
3282
 
Line 3265... Line 3283...
3265
	WARN_ON(!crtc->enabled);
3283
	WARN_ON(!crtc->enabled);
3266
 
3284
 
Line 3274... Line 3292...
3274
        temp = I915_READ(PCH_LVDS);
3292
        temp = I915_READ(PCH_LVDS);
3275
        if ((temp & LVDS_PORT_EN) == 0)
3293
        if ((temp & LVDS_PORT_EN) == 0)
3276
            I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
3294
            I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
3277
    }
3295
    }
Line 3278... Line -...
3278
 
-
 
Line 3279... Line 3296...
3279
	is_pch_port = ironlake_crtc_driving_pch(crtc);
3296
 
3280
 
3297
 
3281
	if (is_pch_port) {
3298
	if (intel_crtc->config.has_pch_encoder) {
3282
		/* Note: FDI PLL enabling _must_ be done before we enable the
3299
		/* Note: FDI PLL enabling _must_ be done before we enable the
3283
		 * cpu pipes, hence this is separate from all the other fdi/pch
3300
		 * cpu pipes, hence this is separate from all the other fdi/pch
3284
		 * enabling. */
3301
		 * enabling. */
Line 3313... Line 3330...
3313
     * On ILK+ LUT must be loaded before the pipe is running but with
3330
     * On ILK+ LUT must be loaded before the pipe is running but with
3314
     * clocks enabled
3331
     * clocks enabled
3315
     */
3332
     */
3316
    intel_crtc_load_lut(crtc);
3333
    intel_crtc_load_lut(crtc);
Line 3317... Line 3334...
3317
 
3334
 
-
 
3335
	intel_enable_pipe(dev_priv, pipe,
3318
    intel_enable_pipe(dev_priv, pipe, is_pch_port);
3336
			  intel_crtc->config.has_pch_encoder);
Line 3319... Line 3337...
3319
    intel_enable_plane(dev_priv, plane, pipe);
3337
    intel_enable_plane(dev_priv, plane, pipe);
3320
 
3338
 
Line 3321... Line 3339...
3321
    if (is_pch_port)
3339
	if (intel_crtc->config.has_pch_encoder)
3322
        ironlake_pch_enable(crtc);
3340
        ironlake_pch_enable(crtc);
3323
 
3341
 
Line 3350... Line 3368...
3350
	struct drm_i915_private *dev_priv = dev->dev_private;
3368
	struct drm_i915_private *dev_priv = dev->dev_private;
3351
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3369
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3352
	struct intel_encoder *encoder;
3370
	struct intel_encoder *encoder;
3353
	int pipe = intel_crtc->pipe;
3371
	int pipe = intel_crtc->pipe;
3354
	int plane = intel_crtc->plane;
3372
	int plane = intel_crtc->plane;
3355
	bool is_pch_port;
-
 
Line 3356... Line 3373...
3356
 
3373
 
Line 3357... Line 3374...
3357
	WARN_ON(!crtc->enabled);
3374
	WARN_ON(!crtc->enabled);
3358
 
3375
 
Line 3359... Line 3376...
3359
	if (intel_crtc->active)
3376
	if (intel_crtc->active)
3360
		return;
3377
		return;
Line 3361... Line 3378...
3361
 
3378
 
3362
	intel_crtc->active = true;
-
 
3363
	intel_update_watermarks(dev);
-
 
3364
 
3379
	intel_crtc->active = true;
Line 3365... Line 3380...
3365
	is_pch_port = haswell_crtc_driving_pch(crtc);
3380
	intel_update_watermarks(dev);
3366
 
3381
 
3367
	if (is_pch_port)
3382
	if (intel_crtc->config.has_pch_encoder)
Line 3391... Line 3406...
3391
	 * clocks enabled
3406
	 * clocks enabled
3392
	 */
3407
	 */
3393
	intel_crtc_load_lut(crtc);
3408
	intel_crtc_load_lut(crtc);
Line 3394... Line 3409...
3394
 
3409
 
3395
	intel_ddi_set_pipe_settings(crtc);
3410
	intel_ddi_set_pipe_settings(crtc);
Line 3396... Line 3411...
3396
	intel_ddi_enable_pipe_func(crtc);
3411
	intel_ddi_enable_transcoder_func(crtc);
-
 
3412
 
3397
 
3413
	intel_enable_pipe(dev_priv, pipe,
Line 3398... Line 3414...
3398
	intel_enable_pipe(dev_priv, pipe, is_pch_port);
3414
			  intel_crtc->config.has_pch_encoder);
3399
	intel_enable_plane(dev_priv, plane, pipe);
3415
	intel_enable_plane(dev_priv, plane, pipe);
Line 3400... Line 3416...
3400
 
3416
 
3401
	if (is_pch_port)
3417
	if (intel_crtc->config.has_pch_encoder)
3402
		lpt_pch_enable(crtc);
3418
		lpt_pch_enable(crtc);
Line 3507... Line 3523...
3507
	struct drm_i915_private *dev_priv = dev->dev_private;
3523
	struct drm_i915_private *dev_priv = dev->dev_private;
3508
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3524
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3509
	struct intel_encoder *encoder;
3525
	struct intel_encoder *encoder;
3510
	int pipe = intel_crtc->pipe;
3526
	int pipe = intel_crtc->pipe;
3511
	int plane = intel_crtc->plane;
3527
	int plane = intel_crtc->plane;
3512
	enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
3528
	enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
3513
	bool is_pch_port;
-
 
Line 3514... Line 3529...
3514
 
3529
 
3515
	if (!intel_crtc->active)
3530
	if (!intel_crtc->active)
Line 3516... Line -...
3516
		return;
-
 
3517
 
-
 
3518
	is_pch_port = haswell_crtc_driving_pch(crtc);
3531
		return;
3519
 
3532
 
Line 3520... Line 3533...
3520
	for_each_encoder_on_crtc(dev, crtc, encoder)
3533
	for_each_encoder_on_crtc(dev, crtc, encoder)
Line 3528... Line 3541...
3528
 
3541
 
Line 3529... Line 3542...
3529
	intel_disable_pipe(dev_priv, pipe);
3542
	intel_disable_pipe(dev_priv, pipe);
Line -... Line 3543...
-
 
3543
 
-
 
3544
	intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
-
 
3545
 
3530
 
3546
	/* XXX: Once we have proper panel fitter state tracking implemented with
3531
	intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
3547
	 * hardware state read/check support we should switch to only disable
3532
 
3548
	 * the panel fitter when we know it's used. */
-
 
3549
	if (intel_using_power_well(dev)) {
Line 3533... Line 3550...
3533
	/* Disable PF */
3550
	I915_WRITE(PF_CTL(pipe), 0);
Line 3534... Line 3551...
3534
	I915_WRITE(PF_CTL(pipe), 0);
3551
	I915_WRITE(PF_WIN_SZ(pipe), 0);
3535
	I915_WRITE(PF_WIN_SZ(pipe), 0);
3552
	}
3536
 
3553
 
Line 3537... Line 3554...
3537
	intel_ddi_disable_pipe_clock(intel_crtc);
3554
	intel_ddi_disable_pipe_clock(intel_crtc);
3538
 
3555
 
3539
	for_each_encoder_on_crtc(dev, crtc, encoder)
3556
	for_each_encoder_on_crtc(dev, crtc, encoder)
3540
		if (encoder->post_disable)
3557
		if (encoder->post_disable)
Line 3541... Line 3558...
3541
			encoder->post_disable(encoder);
3558
			encoder->post_disable(encoder);
Line 3563... Line 3580...
3563
{
3580
{
3564
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3581
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Line 3565... Line 3582...
3565
 
3582
 
3566
	/* Stop saying we're using TRANSCODER_EDP because some other CRTC might
3583
	/* Stop saying we're using TRANSCODER_EDP because some other CRTC might
3567
	 * start using it. */
3584
	 * start using it. */
Line 3568... Line 3585...
3568
	intel_crtc->cpu_transcoder = (enum transcoder) intel_crtc->pipe;
3585
	intel_crtc->config.cpu_transcoder = (enum transcoder) intel_crtc->pipe;
3569
 
3586
 
Line 3570... Line 3587...
3570
	intel_ddi_put_crtc_pll(crtc);
3587
	intel_ddi_put_crtc_pll(crtc);
Line 3649... Line 3666...
3649
 
3666
 
3650
	for_each_encoder_on_crtc(dev, crtc, encoder)
3667
	for_each_encoder_on_crtc(dev, crtc, encoder)
3651
		encoder->enable(encoder);
3668
		encoder->enable(encoder);
Line -... Line 3669...
-
 
3669
}
-
 
3670
 
-
 
3671
static void i9xx_pfit_disable(struct intel_crtc *crtc)
-
 
3672
{
-
 
3673
	struct drm_device *dev = crtc->base.dev;
-
 
3674
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
3675
	enum pipe pipe;
-
 
3676
	uint32_t pctl = I915_READ(PFIT_CONTROL);
-
 
3677
 
-
 
3678
	assert_pipe_disabled(dev_priv, crtc->pipe);
-
 
3679
 
-
 
3680
	if (INTEL_INFO(dev)->gen >= 4)
-
 
3681
		pipe = (pctl & PFIT_PIPE_MASK) >> PFIT_PIPE_SHIFT;
-
 
3682
	else
-
 
3683
		pipe = PIPE_B;
-
 
3684
 
-
 
3685
	if (pipe == crtc->pipe) {
-
 
3686
		DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", pctl);
-
 
3687
		I915_WRITE(PFIT_CONTROL, 0);
-
 
3688
	}
3652
}
3689
}
3653
 
3690
 
3654
static void i9xx_crtc_disable(struct drm_crtc *crtc)
3691
static void i9xx_crtc_disable(struct drm_crtc *crtc)
3655
{
3692
{
3656
    struct drm_device *dev = crtc->dev;
3693
    struct drm_device *dev = crtc->dev;
3657
    struct drm_i915_private *dev_priv = dev->dev_private;
3694
    struct drm_i915_private *dev_priv = dev->dev_private;
3658
    struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3695
    struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3659
	struct intel_encoder *encoder;
3696
	struct intel_encoder *encoder;
3660
    int pipe = intel_crtc->pipe;
-
 
3661
    int plane = intel_crtc->plane;
-
 
Line 3662... Line 3697...
3662
	u32 pctl;
3697
    int pipe = intel_crtc->pipe;
3663
 
3698
    int plane = intel_crtc->plane;
Line 3664... Line 3699...
3664
 
3699
 
Line 3678... Line 3713...
3678
        intel_disable_fbc(dev);
3713
        intel_disable_fbc(dev);
Line 3679... Line 3714...
3679
 
3714
 
3680
    intel_disable_plane(dev_priv, plane, pipe);
3715
    intel_disable_plane(dev_priv, plane, pipe);
Line 3681... Line -...
3681
    intel_disable_pipe(dev_priv, pipe);
-
 
3682
 
-
 
3683
	/* Disable pannel fitter if it is on this pipe. */
-
 
3684
	pctl = I915_READ(PFIT_CONTROL);
-
 
3685
	if ((pctl & PFIT_ENABLE) &&
3716
    intel_disable_pipe(dev_priv, pipe);
Line 3686... Line 3717...
3686
	    ((pctl & PFIT_PIPE_MASK) >> PFIT_PIPE_SHIFT) == pipe)
3717
 
Line 3687... Line 3718...
3687
		I915_WRITE(PFIT_CONTROL, 0);
3718
	i9xx_pfit_disable(intel_crtc);
3688
 
3719
 
Line 3892... Line 3923...
3892
	struct intel_encoder *encoder = connector->encoder;
3923
	struct intel_encoder *encoder = connector->encoder;
Line 3893... Line 3924...
3893
 
3924
 
3894
	return encoder->get_hw_state(encoder, &pipe);
3925
	return encoder->get_hw_state(encoder, &pipe);
Line 3895... Line 3926...
3895
}
3926
}
3896
 
-
 
3897
static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
3927
 
3898
				  const struct drm_display_mode *mode,
3928
static bool intel_crtc_compute_config(struct drm_crtc *crtc,
3899
				  struct drm_display_mode *adjusted_mode)
3929
				      struct intel_crtc_config *pipe_config)
-
 
3930
{
Line 3900... Line 3931...
3900
{
3931
	struct drm_device *dev = crtc->dev;
3901
	struct drm_device *dev = crtc->dev;
3932
	struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
-
 
3933
 
3902
 
3934
	if (HAS_PCH_SPLIT(dev)) {
3903
	if (HAS_PCH_SPLIT(dev)) {
3935
		/* FDI link clock is fixed at 2.7G */
3904
		/* FDI link clock is fixed at 2.7G */
3936
		if (pipe_config->requested_mode.clock * 3
Line 3905... Line 3937...
3905
		if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
3937
		    > IRONLAKE_FDI_FREQ * 4)
3906
			return false;
3938
			return false;
3907
	}
3939
	}
3908
 
3940
 
3909
	/* All interlaced capable intel hw wants timings in frames. Note though
3941
	/* All interlaced capable intel hw wants timings in frames. Note though
Line 3910... Line 3942...
3910
	 * that intel_lvds_mode_fixup does some funny tricks with the crtc
3942
	 * that intel_lvds_mode_fixup does some funny tricks with the crtc
3911
	 * timings, so we need to be careful not to clobber these.*/
3943
	 * timings, so we need to be careful not to clobber these.*/
3912
	if (!(adjusted_mode->private_flags & INTEL_MODE_CRTC_TIMINGS_SET))
3944
	if (!pipe_config->timings_set)
3913
		drm_mode_set_crtcinfo(adjusted_mode, 0);
3945
		drm_mode_set_crtcinfo(adjusted_mode, 0);
3914
 
3946
 
3915
	/* WaPruneModeWithIncorrectHsyncOffset: Cantiga+ cannot handle modes
3947
	/* WaPruneModeWithIncorrectHsyncOffset: Cantiga+ cannot handle modes
Line -... Line 3948...
-
 
3948
	 * with a hsync front porch of 0.
-
 
3949
	 */
-
 
3950
	if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
-
 
3951
		adjusted_mode->hsync_start == adjusted_mode->hdisplay)
-
 
3952
		return false;
-
 
3953
 
-
 
3954
	if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && pipe_config->pipe_bpp > 10*3) {
-
 
3955
		pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */
3916
	 * with a hsync front porch of 0.
3956
	} else if (INTEL_INFO(dev)->gen <= 4 && pipe_config->pipe_bpp > 8*3) {
3917
	 */
3957
		/* only a 8bpc pipe, with 6bpc dither through the panel fitter
Line 3918... Line 3958...
3918
	if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
3958
		 * for lvds. */
3919
		adjusted_mode->hsync_start == adjusted_mode->hdisplay)
3959
		pipe_config->pipe_bpp = 8*3;
Line 3990... Line 4030...
3990
{
4030
{
3991
	return 133000;
4031
	return 133000;
3992
}
4032
}
Line 3993... Line 4033...
3993
 
4033
 
3994
static void
4034
static void
3995
intel_reduce_ratio(uint32_t *num, uint32_t *den)
4035
intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
3996
{
4036
{
-
 
4037
	while (*num > DATA_LINK_M_N_MASK ||
3997
	while (*num > 0xffffff || *den > 0xffffff) {
4038
	       *den > DATA_LINK_M_N_MASK) {
3998
		*num >>= 1;
4039
		*num >>= 1;
3999
		*den >>= 1;
4040
		*den >>= 1;
4000
	}
4041
	}
Line -... Line 4042...
-
 
4042
}
-
 
4043
 
-
 
4044
static void compute_m_n(unsigned int m, unsigned int n,
-
 
4045
			uint32_t *ret_m, uint32_t *ret_n)
-
 
4046
{
-
 
4047
	*ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
-
 
4048
	*ret_m = div_u64((uint64_t) m * *ret_n, n);
-
 
4049
	intel_reduce_m_n_ratio(ret_m, ret_n);
4001
}
4050
}
4002
 
4051
 
4003
void
4052
void
4004
intel_link_compute_m_n(int bits_per_pixel, int nlanes,
4053
intel_link_compute_m_n(int bits_per_pixel, int nlanes,
4005
		       int pixel_clock, int link_clock,
4054
		       int pixel_clock, int link_clock,
4006
		       struct intel_link_m_n *m_n)
4055
		       struct intel_link_m_n *m_n)
-
 
4056
{
4007
{
4057
	m_n->tu = 64;
4008
	m_n->tu = 64;
4058
 
4009
	m_n->gmch_m = bits_per_pixel * pixel_clock;
4059
	compute_m_n(bits_per_pixel * pixel_clock,
4010
	m_n->gmch_n = link_clock * nlanes * 8;
-
 
-
 
4060
		    link_clock * nlanes * 8,
4011
	intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
4061
		    &m_n->gmch_m, &m_n->gmch_n);
4012
	m_n->link_m = pixel_clock;
4062
 
4013
	m_n->link_n = link_clock;
4063
	compute_m_n(pixel_clock, link_clock,
Line 4014... Line 4064...
4014
	intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
4064
		    &m_n->link_m, &m_n->link_n);
4015
}
4065
}
4016
 
4066
 
4017
static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
4067
static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
4018
{
4068
{
4019
	if (i915_panel_use_ssc >= 0)
4069
	if (i915_panel_use_ssc >= 0)
4020
		return i915_panel_use_ssc != 0;
4070
		return i915_panel_use_ssc != 0;
Line 4021... Line -...
4021
	return dev_priv->lvds_use_ssc
-
 
4022
		&& !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
-
 
4023
}
-
 
4024
 
-
 
4025
/**
-
 
4026
 * intel_choose_pipe_bpp_dither - figure out what color depth the pipe should send
-
 
4027
 * @crtc: CRTC structure
-
 
4028
 * @mode: requested mode
-
 
4029
 *
-
 
4030
 * A pipe may be connected to one or more outputs.  Based on the depth of the
-
 
4031
 * attached framebuffer, choose a good color depth to use on the pipe.
-
 
4032
 *
-
 
4033
 * If possible, match the pipe depth to the fb depth.  In some cases, this
-
 
4034
 * isn't ideal, because the connected output supports a lesser or restricted
-
 
4035
 * set of depths.  Resolve that here:
-
 
4036
 *    LVDS typically supports only 6bpc, so clamp down in that case
-
 
4037
 *    HDMI supports only 8bpc or 12bpc, so clamp to 8bpc with dither for 10bpc
-
 
4038
 *    Displays may support a restricted set as well, check EDID and clamp as
-
 
4039
 *      appropriate.
-
 
4040
 *    DP may want to dither down to 6bpc to fit larger modes
-
 
4041
 *
-
 
4042
 * RETURNS:
-
 
4043
 * Dithering requirement (i.e. false if display bpc and pipe bpc match,
-
 
4044
 * true if they don't match).
-
 
4045
 */
-
 
4046
static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
-
 
4047
					 struct drm_framebuffer *fb,
-
 
4048
					 unsigned int *pipe_bpp,
-
 
4049
					 struct drm_display_mode *mode)
-
 
4050
{
-
 
4051
	struct drm_device *dev = crtc->dev;
-
 
4052
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
4053
	struct drm_connector *connector;
-
 
4054
	struct intel_encoder *intel_encoder;
-
 
4055
	unsigned int display_bpc = UINT_MAX, bpc;
-
 
4056
 
-
 
4057
	/* Walk the encoders & connectors on this crtc, get min bpc */
-
 
4058
	for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
-
 
4059
 
-
 
4060
		if (intel_encoder->type == INTEL_OUTPUT_LVDS) {
-
 
4061
			unsigned int lvds_bpc;
-
 
4062
 
-
 
4063
			if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) ==
-
 
4064
			    LVDS_A3_POWER_UP)
-
 
4065
				lvds_bpc = 8;
-
 
4066
			else
-
 
4067
				lvds_bpc = 6;
-
 
4068
 
-
 
4069
			if (lvds_bpc < display_bpc) {
-
 
4070
				DRM_DEBUG_KMS("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc);
-
 
4071
				display_bpc = lvds_bpc;
-
 
4072
			}
-
 
4073
			continue;
-
 
4074
		}
-
 
4075
 
-
 
4076
		/* Not one of the known troublemakers, check the EDID */
-
 
4077
		list_for_each_entry(connector, &dev->mode_config.connector_list,
-
 
4078
				    head) {
-
 
4079
			if (connector->encoder != &intel_encoder->base)
-
 
4080
				continue;
-
 
4081
 
-
 
4082
			/* Don't use an invalid EDID bpc value */
-
 
4083
			if (connector->display_info.bpc &&
-
 
4084
			    connector->display_info.bpc < display_bpc) {
-
 
4085
				DRM_DEBUG_KMS("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->display_info.bpc);
-
 
4086
				display_bpc = connector->display_info.bpc;
-
 
4087
        }
-
 
4088
    }
-
 
4089
 
-
 
4090
		if (intel_encoder->type == INTEL_OUTPUT_EDP) {
-
 
4091
			/* Use VBT settings if we have an eDP panel */
-
 
4092
			unsigned int edp_bpc = dev_priv->edp.bpp / 3;
-
 
4093
 
-
 
4094
			if (edp_bpc && edp_bpc < display_bpc) {
-
 
4095
				DRM_DEBUG_KMS("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc);
-
 
4096
				display_bpc = edp_bpc;
-
 
4097
			}
-
 
4098
			continue;
-
 
4099
		}
-
 
4100
 
-
 
4101
		/*
-
 
4102
		 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
-
 
4103
		 * through, clamp it down.  (Note: >12bpc will be caught below.)
-
 
4104
		 */
-
 
4105
		if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
-
 
4106
			if (display_bpc > 8 && display_bpc < 12) {
-
 
4107
				DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n");
-
 
4108
				display_bpc = 12;
-
 
4109
			} else {
-
 
4110
				DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n");
-
 
4111
				display_bpc = 8;
-
 
4112
			}
-
 
4113
		}
-
 
4114
	}
-
 
4115
 
-
 
4116
	if (mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
-
 
4117
		DRM_DEBUG_KMS("Dithering DP to 6bpc\n");
-
 
4118
		display_bpc = 6;
-
 
4119
	}
-
 
4120
 
-
 
4121
	/*
-
 
4122
	 * We could just drive the pipe at the highest bpc all the time and
-
 
4123
	 * enable dithering as needed, but that costs bandwidth.  So choose
-
 
4124
	 * the minimum value that expresses the full color range of the fb but
-
 
4125
	 * also stays within the max display bpc discovered above.
-
 
4126
	 */
-
 
4127
 
-
 
4128
	switch (fb->depth) {
-
 
4129
	case 8:
-
 
4130
		bpc = 8; /* since we go through a colormap */
-
 
4131
		break;
-
 
4132
	case 15:
-
 
4133
	case 16:
-
 
4134
		bpc = 6; /* min is 18bpp */
-
 
4135
		break;
-
 
4136
	case 24:
-
 
4137
		bpc = 8;
-
 
4138
		break;
-
 
4139
	case 30:
-
 
4140
		bpc = 10;
-
 
4141
		break;
-
 
4142
	case 48:
-
 
4143
		bpc = 12;
-
 
4144
		break;
-
 
4145
	default:
-
 
4146
		DRM_DEBUG("unsupported depth, assuming 24 bits\n");
-
 
4147
		bpc = min((unsigned int)8, display_bpc);
-
 
4148
		break;
-
 
4149
	}
-
 
4150
 
-
 
4151
	display_bpc = min(display_bpc, bpc);
-
 
4152
 
-
 
4153
	DRM_DEBUG_KMS("setting pipe bpc to %d (max display bpc %d)\n",
-
 
4154
		      bpc, display_bpc);
-
 
4155
 
-
 
4156
	*pipe_bpp = display_bpc * 3;
-
 
4157
 
4071
	return dev_priv->lvds_use_ssc
4158
	return display_bpc != bpc;
4072
		&& !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
4159
}
4073
}
4160
 
4074
 
4161
static int vlv_get_refclk(struct drm_crtc *crtc)
4075
static int vlv_get_refclk(struct drm_crtc *crtc)
Line 4200... Line 4114...
4200
	}
4114
	}
Line 4201... Line 4115...
4201
 
4115
 
4202
	return refclk;
4116
	return refclk;
Line 4203... Line 4117...
4203
}
4117
}
4204
 
-
 
4205
static void i9xx_adjust_sdvo_tv_clock(struct drm_display_mode *adjusted_mode,
4118
 
-
 
4119
static void i9xx_adjust_sdvo_tv_clock(struct intel_crtc *crtc)
-
 
4120
{
-
 
4121
	unsigned dotclock = crtc->config.adjusted_mode.clock;
4206
				      intel_clock_t *clock)
4122
	struct dpll *clock = &crtc->config.dpll;
4207
{
4123
 
4208
	/* SDVO TV has fixed PLL values depend on its clock range,
-
 
4209
	   this mirrors vbios setting. */
4124
	/* SDVO TV has fixed PLL values depend on its clock range,
4210
	if (adjusted_mode->clock >= 100000
4125
	   this mirrors vbios setting. */
4211
	    && adjusted_mode->clock < 140500) {
4126
	if (dotclock >= 100000 && dotclock < 140500) {
4212
		clock->p1 = 2;
4127
		clock->p1 = 2;
4213
		clock->p2 = 10;
4128
		clock->p2 = 10;
4214
		clock->n = 3;
4129
		clock->n = 3;
4215
		clock->m1 = 16;
4130
		clock->m1 = 16;
4216
		clock->m2 = 8;
-
 
4217
	} else if (adjusted_mode->clock >= 140500
4131
		clock->m2 = 8;
4218
		   && adjusted_mode->clock <= 200000) {
4132
	} else if (dotclock >= 140500 && dotclock <= 200000) {
4219
		clock->p1 = 1;
4133
		clock->p1 = 1;
4220
		clock->p2 = 10;
4134
		clock->p2 = 10;
4221
		clock->n = 6;
4135
		clock->n = 6;
4222
		clock->m1 = 12;
4136
		clock->m1 = 12;
-
 
4137
		clock->m2 = 8;
-
 
4138
	}
4223
		clock->m2 = 8;
4139
 
Line 4224... Line 4140...
4224
	}
4140
	crtc->config.clock_set = true;
4225
}
-
 
4226
 
4141
}
4227
static void i9xx_update_pll_dividers(struct drm_crtc *crtc,
4142
 
4228
				     intel_clock_t *clock,
4143
static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
4229
				     intel_clock_t *reduced_clock)
4144
				     intel_clock_t *reduced_clock)
4230
{
-
 
4231
	struct drm_device *dev = crtc->dev;
4145
{
4232
	struct drm_i915_private *dev_priv = dev->dev_private;
4146
	struct drm_device *dev = crtc->base.dev;
-
 
4147
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 4233... Line 4148...
4233
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4148
	int pipe = crtc->pipe;
4234
	int pipe = intel_crtc->pipe;
4149
	u32 fp, fp2 = 0;
4235
	u32 fp, fp2 = 0;
4150
	struct dpll *clock = &crtc->config.dpll;
4236
 
4151
 
Line 4246... Line 4161...
4246
				reduced_clock->m2;
4161
				reduced_clock->m2;
4247
	}
4162
	}
Line 4248... Line 4163...
4248
 
4163
 
Line 4249... Line 4164...
4249
	I915_WRITE(FP0(pipe), fp);
4164
	I915_WRITE(FP0(pipe), fp);
4250
 
4165
 
4251
	intel_crtc->lowfreq_avail = false;
4166
	crtc->lowfreq_avail = false;
4252
	if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
4167
	if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
4253
	    reduced_clock && i915_powersave) {
4168
	    reduced_clock && i915_powersave) {
4254
		I915_WRITE(FP1(pipe), fp2);
4169
		I915_WRITE(FP1(pipe), fp2);
4255
		intel_crtc->lowfreq_avail = true;
4170
		crtc->lowfreq_avail = true;
4256
	} else {
4171
	} else {
4257
		I915_WRITE(FP1(pipe), fp);
4172
		I915_WRITE(FP1(pipe), fp);
Line 4258... Line 4173...
4258
	}
4173
	}
4259
}
-
 
4260
 
-
 
4261
static void vlv_update_pll(struct drm_crtc *crtc,
-
 
4262
			   struct drm_display_mode *mode,
-
 
4263
			   struct drm_display_mode *adjusted_mode,
4174
}
-
 
4175
 
-
 
4176
static void intel_dp_set_m_n(struct intel_crtc *crtc)
-
 
4177
{
-
 
4178
	if (crtc->config.has_pch_encoder)
-
 
4179
		intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
-
 
4180
	else
-
 
4181
		intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
-
 
4182
}
4264
			   intel_clock_t *clock, intel_clock_t *reduced_clock,
4183
 
4265
			   int num_connectors)
4184
static void vlv_update_pll(struct intel_crtc *crtc)
4266
{
-
 
4267
	struct drm_device *dev = crtc->dev;
4185
{
4268
	struct drm_i915_private *dev_priv = dev->dev_private;
4186
	struct drm_device *dev = crtc->base.dev;
4269
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4187
	struct drm_i915_private *dev_priv = dev->dev_private;
4270
	int pipe = intel_crtc->pipe;
4188
	int pipe = crtc->pipe;
4271
	u32 dpll, mdiv, pdiv;
4189
	u32 dpll, mdiv, pdiv;
Line 4272... Line 4190...
4272
	u32 bestn, bestm1, bestm2, bestp1, bestp2;
4190
	u32 bestn, bestm1, bestm2, bestp1, bestp2;
Line 4273... Line 4191...
4273
	bool is_sdvo;
4191
	bool is_sdvo;
4274
	u32 temp;
4192
	u32 temp;
Line 4275... Line 4193...
4275
 
4193
 
4276
	mutex_lock(&dev_priv->dpio_lock);
4194
	mutex_lock(&dev_priv->dpio_lock);
4277
 
4195
 
4278
	is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
4196
	is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) ||
Line 4279... Line 4197...
4279
		intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
4197
		intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI);
4280
 
4198
 
Line 4281... Line 4199...
4281
	dpll = DPLL_VGA_MODE_DIS;
4199
	dpll = DPLL_VGA_MODE_DIS;
4282
	dpll |= DPLL_EXT_BUFFER_ENABLE_VLV;
4200
	dpll |= DPLL_EXT_BUFFER_ENABLE_VLV;
4283
	dpll |= DPLL_REFA_CLK_ENABLE_VLV;
4201
	dpll |= DPLL_REFA_CLK_ENABLE_VLV;
4284
	dpll |= DPLL_INTEGRATED_CLOCK_VLV;
4202
	dpll |= DPLL_INTEGRATED_CLOCK_VLV;
4285
 
4203
 
Line 4286... Line 4204...
4286
	I915_WRITE(DPLL(pipe), dpll);
4204
	I915_WRITE(DPLL(pipe), dpll);
4287
	POSTING_READ(DPLL(pipe));
4205
	POSTING_READ(DPLL(pipe));
4288
 
4206
 
4289
	bestn = clock->n;
4207
	bestn = crtc->config.dpll.n;
Line 4320... Line 4238...
4320
	if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
4238
	if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
4321
		DRM_ERROR("DPLL %d failed to lock\n", pipe);
4239
		DRM_ERROR("DPLL %d failed to lock\n", pipe);
Line 4322... Line 4240...
4322
 
4240
 
Line 4323... Line 4241...
4323
	intel_dpio_write(dev_priv, DPIO_FASTCLK_DISABLE, 0x620);
4241
	intel_dpio_write(dev_priv, DPIO_FASTCLK_DISABLE, 0x620);
4324
 
4242
 
Line 4325... Line 4243...
4325
	if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
4243
	if (crtc->config.has_dp_encoder)
Line 4326... Line 4244...
4326
		intel_dp_set_m_n(crtc, mode, adjusted_mode);
4244
		intel_dp_set_m_n(crtc);
4327
 
4245
 
4328
	I915_WRITE(DPLL(pipe), dpll);
4246
	I915_WRITE(DPLL(pipe), dpll);
Line 4329... Line 4247...
4329
 
4247
 
4330
	/* Wait for the clocks to stabilize. */
4248
	/* Wait for the clocks to stabilize. */
4331
	POSTING_READ(DPLL(pipe));
-
 
4332
	udelay(150);
-
 
4333
 
-
 
4334
	temp = 0;
-
 
4335
	if (is_sdvo) {
4249
	POSTING_READ(DPLL(pipe));
-
 
4250
	udelay(150);
-
 
4251
 
-
 
4252
	temp = 0;
-
 
4253
	if (is_sdvo) {
4336
		temp = intel_mode_get_pixel_multiplier(adjusted_mode);
4254
			temp = 0;
4337
		if (temp > 1)
4255
		if (crtc->config.pixel_multiplier > 1) {
4338
			temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
4256
			temp = (crtc->config.pixel_multiplier - 1)
Line 4339... Line 4257...
4339
		else
4257
				<< DPLL_MD_UDI_MULTIPLIER_SHIFT;
4340
			temp = 0;
4258
		}
4341
	}
4259
	}
4342
		I915_WRITE(DPLL_MD(pipe), temp);
-
 
4343
		POSTING_READ(DPLL_MD(pipe));
4260
		I915_WRITE(DPLL_MD(pipe), temp);
4344
 
4261
		POSTING_READ(DPLL_MD(pipe));
4345
	/* Now program lane control registers */
4262
 
4346
	if(intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)
4263
	/* Now program lane control registers */
4347
			|| intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
4264
	if(intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)
-
 
4265
	   || intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) {
4348
	{
4266
		temp = 0x1000C4;
4349
		temp = 0x1000C4;
-
 
4350
		if(pipe == 1)
4267
		if(pipe == 1)
4351
			temp |= (1 << 21);
4268
			temp |= (1 << 21);
4352
		intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL1, temp);
4269
		intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL1, temp);
4353
	}
4270
	}
4354
	if(intel_pipe_has_type(crtc,INTEL_OUTPUT_EDP))
4271
 
Line 4355... Line 4272...
4355
	{
4272
	if(intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP)) {
4356
		temp = 0x1000C4;
4273
		temp = 0x1000C4;
Line 4357... Line 4274...
4357
		if(pipe == 1)
4274
		if(pipe == 1)
4358
			temp |= (1 << 21);
-
 
4359
		intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL2, temp);
-
 
4360
	}
4275
			temp |= (1 << 21);
4361
 
4276
		intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL2, temp);
4362
	mutex_unlock(&dev_priv->dpio_lock);
4277
	}
4363
}
4278
 
4364
 
4279
	mutex_unlock(&dev_priv->dpio_lock);
4365
static void i9xx_update_pll(struct drm_crtc *crtc,
-
 
4366
			    struct drm_display_mode *mode,
4280
}
4367
			    struct drm_display_mode *adjusted_mode,
4281
 
4368
			    intel_clock_t *clock, intel_clock_t *reduced_clock,
4282
static void i9xx_update_pll(struct intel_crtc *crtc,
4369
			    int num_connectors)
4283
			    intel_clock_t *reduced_clock,
-
 
4284
			    int num_connectors)
Line 4370... Line 4285...
4370
{
4285
{
Line 4371... Line 4286...
4371
	struct drm_device *dev = crtc->dev;
4286
	struct drm_device *dev = crtc->base.dev;
4372
	struct drm_i915_private *dev_priv = dev->dev_private;
4287
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 4373... Line 4288...
4373
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4288
	struct intel_encoder *encoder;
Line 4374... Line 4289...
4374
	struct intel_encoder *encoder;
4289
	int pipe = crtc->pipe;
4375
	int pipe = intel_crtc->pipe;
4290
	u32 dpll;
4376
	u32 dpll;
4291
	bool is_sdvo;
4377
	bool is_sdvo;
4292
	struct dpll *clock = &crtc->config.dpll;
-
 
4293
 
4378
 
4294
	i9xx_update_pll_dividers(crtc, reduced_clock);
4379
	i9xx_update_pll_dividers(crtc, clock, reduced_clock);
-
 
4380
 
4295
 
4381
	is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
4296
	is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) ||
-
 
4297
		intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI);
4382
		intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
4298
 
4383
 
4299
	dpll = DPLL_VGA_MODE_DIS;
4384
	dpll = DPLL_VGA_MODE_DIS;
4300
 
4385
 
4301
	if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS))
4386
	if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
4302
		dpll |= DPLLB_MODE_LVDS;
4387
		dpll |= DPLLB_MODE_LVDS;
4303
	else
Line 4388... Line 4304...
4388
	else
4304
		dpll |= DPLLB_MODE_DAC_SERIAL;
4389
		dpll |= DPLLB_MODE_DAC_SERIAL;
4305
 
4390
	if (is_sdvo) {
4306
	if (is_sdvo) {
Line 4421... Line 4337...
4421
		break;
4337
		break;
4422
	}
4338
	}
4423
	if (INTEL_INFO(dev)->gen >= 4)
4339
	if (INTEL_INFO(dev)->gen >= 4)
4424
		dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
4340
		dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
Line 4425... Line 4341...
4425
 
4341
 
4426
	if (is_sdvo && intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
4342
	if (is_sdvo && intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_TVOUT))
4427
		dpll |= PLL_REF_INPUT_TVCLKINBC;
4343
		dpll |= PLL_REF_INPUT_TVCLKINBC;
4428
	else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
4344
	else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_TVOUT))
4429
		/* XXX: just matching BIOS for now */
4345
		/* XXX: just matching BIOS for now */
4430
		/*	dpll |= PLL_REF_INPUT_TVCLKINBC; */
4346
		/*	dpll |= PLL_REF_INPUT_TVCLKINBC; */
4431
		dpll |= 3;
4347
		dpll |= 3;
4432
	else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
4348
	else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
4433
		 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
4349
		 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
4434
		dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
4350
		dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
4435
	else
4351
	else
Line 4436... Line 4352...
4436
		dpll |= PLL_REF_INPUT_DREFCLK;
4352
		dpll |= PLL_REF_INPUT_DREFCLK;
4437
 
4353
 
4438
	dpll |= DPLL_VCO_ENABLE;
4354
	dpll |= DPLL_VCO_ENABLE;
4439
	I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
4355
	I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
Line 4440... Line 4356...
4440
	POSTING_READ(DPLL(pipe));
4356
	POSTING_READ(DPLL(pipe));
4441
	udelay(150);
4357
	udelay(150);
4442
 
4358
 
Line 4443... Line 4359...
4443
	for_each_encoder_on_crtc(dev, crtc, encoder)
4359
	for_each_encoder_on_crtc(dev, &crtc->base, encoder)
4444
		if (encoder->pre_pll_enable)
4360
		if (encoder->pre_pll_enable)
Line 4445... Line 4361...
4445
			encoder->pre_pll_enable(encoder);
4361
			encoder->pre_pll_enable(encoder);
Line 4446... Line 4362...
4446
 
4362
 
4447
	if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
4363
	if (crtc->config.has_dp_encoder)
4448
		intel_dp_set_m_n(crtc, mode, adjusted_mode);
4364
		intel_dp_set_m_n(crtc);
Line 4449... Line 4365...
4449
 
4365
 
4450
	I915_WRITE(DPLL(pipe), dpll);
4366
	I915_WRITE(DPLL(pipe), dpll);
4451
 
4367
 
4452
	/* Wait for the clocks to stabilize. */
-
 
4453
	POSTING_READ(DPLL(pipe));
-
 
4454
	udelay(150);
-
 
4455
 
-
 
4456
	if (INTEL_INFO(dev)->gen >= 4) {
4368
	/* Wait for the clocks to stabilize. */
-
 
4369
	POSTING_READ(DPLL(pipe));
-
 
4370
	udelay(150);
-
 
4371
 
-
 
4372
	if (INTEL_INFO(dev)->gen >= 4) {
4457
		u32 temp = 0;
4373
		u32 temp = 0;
4458
		if (is_sdvo) {
4374
		if (is_sdvo) {
4459
			temp = intel_mode_get_pixel_multiplier(adjusted_mode);
4375
				temp = 0;
4460
			if (temp > 1)
4376
			if (crtc->config.pixel_multiplier > 1) {
4461
				temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
4377
				temp = (crtc->config.pixel_multiplier - 1)
Line 4471... Line 4387...
4471
		 */
4387
		 */
4472
		I915_WRITE(DPLL(pipe), dpll);
4388
		I915_WRITE(DPLL(pipe), dpll);
4473
	}
4389
	}
4474
}
4390
}
Line 4475... Line 4391...
4475
 
4391
 
4476
static void i8xx_update_pll(struct drm_crtc *crtc,
4392
static void i8xx_update_pll(struct intel_crtc *crtc,
4477
			    struct drm_display_mode *adjusted_mode,
4393
			    struct drm_display_mode *adjusted_mode,
4478
			    intel_clock_t *clock, intel_clock_t *reduced_clock,
4394
			    intel_clock_t *reduced_clock,
4479
			    int num_connectors)
4395
			    int num_connectors)
4480
{
4396
{
4481
	struct drm_device *dev = crtc->dev;
4397
	struct drm_device *dev = crtc->base.dev;
4482
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
4483
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4398
	struct drm_i915_private *dev_priv = dev->dev_private;
4484
	struct intel_encoder *encoder;
4399
	struct intel_encoder *encoder;
4485
	int pipe = intel_crtc->pipe;
4400
	int pipe = crtc->pipe;
-
 
4401
	u32 dpll;
Line 4486... Line 4402...
4486
	u32 dpll;
4402
	struct dpll *clock = &crtc->config.dpll;
Line 4487... Line 4403...
4487
 
4403
 
Line 4488... Line 4404...
4488
	i9xx_update_pll_dividers(crtc, clock, reduced_clock);
4404
	i9xx_update_pll_dividers(crtc, reduced_clock);
4489
 
4405
 
4490
	dpll = DPLL_VGA_MODE_DIS;
4406
	dpll = DPLL_VGA_MODE_DIS;
4491
 
4407
 
4492
	if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
4408
	if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) {
4493
		dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4409
		dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4494
	} else {
4410
	} else {
4495
		if (clock->p1 == 2)
4411
		if (clock->p1 == 2)
4496
			dpll |= PLL_P1_DIVIDE_BY_TWO;
4412
			dpll |= PLL_P1_DIVIDE_BY_TWO;
4497
		else
4413
		else
Line 4498... Line -...
4498
			dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
-
 
4499
		if (clock->p2 == 4)
-
 
4500
			dpll |= PLL_P2_DIVIDE_BY_4;
-
 
4501
	}
-
 
4502
 
4414
			dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4503
	if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
4415
		if (clock->p2 == 4)
4504
		/* XXX: just matching BIOS for now */
4416
			dpll |= PLL_P2_DIVIDE_BY_4;
4505
		/*	dpll |= PLL_REF_INPUT_TVCLKINBC; */
4417
	}
4506
		dpll |= 3;
4418
 
Line 4507... Line 4419...
4507
	else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
4419
	if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
4508
		 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
4420
		 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
4509
		dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
4421
		dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
4510
	else
4422
	else
Line 4511... Line 4423...
4511
		dpll |= PLL_REF_INPUT_DREFCLK;
4423
		dpll |= PLL_REF_INPUT_DREFCLK;
4512
 
4424
 
4513
	dpll |= DPLL_VCO_ENABLE;
4425
	dpll |= DPLL_VCO_ENABLE;
Line 4514... Line 4426...
4514
	I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
4426
	I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
Line 4538... Line 4450...
4538
				   struct drm_display_mode *adjusted_mode)
4450
				   struct drm_display_mode *adjusted_mode)
4539
{
4451
{
4540
	struct drm_device *dev = intel_crtc->base.dev;
4452
	struct drm_device *dev = intel_crtc->base.dev;
4541
	struct drm_i915_private *dev_priv = dev->dev_private;
4453
	struct drm_i915_private *dev_priv = dev->dev_private;
4542
	enum pipe pipe = intel_crtc->pipe;
4454
	enum pipe pipe = intel_crtc->pipe;
4543
	enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
4455
	enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
4544
	uint32_t vsyncshift;
4456
	uint32_t vsyncshift;
Line 4545... Line 4457...
4545
 
4457
 
4546
	if (!IS_GEN2(dev) && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4458
	if (!IS_GEN2(dev) && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4547
		/* the chip adds 2 halflines automatically */
4459
		/* the chip adds 2 halflines automatically */
Line 4589... Line 4501...
4589
	 */
4501
	 */
4590
	I915_WRITE(PIPESRC(pipe),
4502
	I915_WRITE(PIPESRC(pipe),
4591
		   ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
4503
		   ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
4592
}
4504
}
Line -... Line 4505...
-
 
4505
 
-
 
4506
static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
-
 
4507
{
-
 
4508
	struct drm_device *dev = intel_crtc->base.dev;
-
 
4509
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
4510
	uint32_t pipeconf;
-
 
4511
 
-
 
4512
	pipeconf = I915_READ(PIPECONF(intel_crtc->pipe));
-
 
4513
 
-
 
4514
	if (intel_crtc->pipe == 0 && INTEL_INFO(dev)->gen < 4) {
-
 
4515
		/* Enable pixel doubling when the dot clock is > 90% of the (display)
-
 
4516
		 * core speed.
-
 
4517
		 *
-
 
4518
		 * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
-
 
4519
		 * pipe == 0 check?
-
 
4520
		 */
-
 
4521
		if (intel_crtc->config.requested_mode.clock >
-
 
4522
		    dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
-
 
4523
			pipeconf |= PIPECONF_DOUBLE_WIDE;
-
 
4524
		else
-
 
4525
			pipeconf &= ~PIPECONF_DOUBLE_WIDE;
-
 
4526
	}
-
 
4527
 
-
 
4528
	/* default to 8bpc */
-
 
4529
	pipeconf &= ~(PIPECONF_BPC_MASK | PIPECONF_DITHER_EN);
-
 
4530
	if (intel_crtc->config.has_dp_encoder) {
-
 
4531
		if (intel_crtc->config.dither) {
-
 
4532
			pipeconf |= PIPECONF_6BPC |
-
 
4533
				    PIPECONF_DITHER_EN |
-
 
4534
				    PIPECONF_DITHER_TYPE_SP;
-
 
4535
		}
-
 
4536
	}
-
 
4537
 
-
 
4538
	if (IS_VALLEYVIEW(dev) && intel_pipe_has_type(&intel_crtc->base,
-
 
4539
						      INTEL_OUTPUT_EDP)) {
-
 
4540
		if (intel_crtc->config.dither) {
-
 
4541
			pipeconf |= PIPECONF_6BPC |
-
 
4542
					PIPECONF_ENABLE |
-
 
4543
					I965_PIPECONF_ACTIVE;
-
 
4544
		}
-
 
4545
	}
-
 
4546
 
-
 
4547
	if (HAS_PIPE_CXSR(dev)) {
-
 
4548
		if (intel_crtc->lowfreq_avail) {
-
 
4549
			DRM_DEBUG_KMS("enabling CxSR downclocking\n");
-
 
4550
			pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
-
 
4551
		} else {
-
 
4552
			DRM_DEBUG_KMS("disabling CxSR downclocking\n");
-
 
4553
			pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
-
 
4554
		}
-
 
4555
	}
-
 
4556
 
-
 
4557
	pipeconf &= ~PIPECONF_INTERLACE_MASK;
-
 
4558
	if (!IS_GEN2(dev) &&
-
 
4559
	    intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
-
 
4560
		pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
-
 
4561
	else
-
 
4562
		pipeconf |= PIPECONF_PROGRESSIVE;
-
 
4563
 
-
 
4564
	if (IS_VALLEYVIEW(dev)) {
-
 
4565
		if (intel_crtc->config.limited_color_range)
-
 
4566
			pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
-
 
4567
		else
-
 
4568
			pipeconf &= ~PIPECONF_COLOR_RANGE_SELECT;
-
 
4569
	}
-
 
4570
 
-
 
4571
	I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
-
 
4572
	POSTING_READ(PIPECONF(intel_crtc->pipe));
-
 
4573
}
4593
 
4574
 
4594
static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
-
 
4595
			      struct drm_display_mode *mode,
-
 
4596
			      struct drm_display_mode *adjusted_mode,
4575
static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
4597
			      int x, int y,
4576
			      int x, int y,
4598
			      struct drm_framebuffer *fb)
4577
			      struct drm_framebuffer *fb)
4599
{
4578
{
4600
	struct drm_device *dev = crtc->dev;
4579
	struct drm_device *dev = crtc->dev;
4601
	struct drm_i915_private *dev_priv = dev->dev_private;
4580
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
4581
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
4582
	struct drm_display_mode *adjusted_mode =
-
 
4583
		&intel_crtc->config.adjusted_mode;
4602
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4584
	struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
4603
	int pipe = intel_crtc->pipe;
4585
	int pipe = intel_crtc->pipe;
4604
	int plane = intel_crtc->plane;
4586
	int plane = intel_crtc->plane;
4605
	int refclk, num_connectors = 0;
4587
	int refclk, num_connectors = 0;
4606
	intel_clock_t clock, reduced_clock;
4588
	intel_clock_t clock, reduced_clock;
4607
	u32 dspcntr, pipeconf;
4589
	u32 dspcntr;
4608
	bool ok, has_reduced_clock = false, is_sdvo = false;
4590
	bool ok, has_reduced_clock = false, is_sdvo = false;
4609
	bool is_lvds = false, is_tv = false, is_dp = false;
4591
	bool is_lvds = false, is_tv = false;
4610
	struct intel_encoder *encoder;
4592
	struct intel_encoder *encoder;
4611
	const intel_limit_t *limit;
4593
	const intel_limit_t *limit;
Line 4612... Line 4594...
4612
	int ret;
4594
	int ret;
Line 4623... Line 4605...
4623
				is_tv = true;
4605
				is_tv = true;
4624
			break;
4606
			break;
4625
		case INTEL_OUTPUT_TVOUT:
4607
		case INTEL_OUTPUT_TVOUT:
4626
			is_tv = true;
4608
			is_tv = true;
4627
			break;
4609
			break;
4628
		case INTEL_OUTPUT_DISPLAYPORT:
-
 
4629
			is_dp = true;
-
 
4630
			break;
-
 
4631
		}
4610
		}
Line 4632... Line 4611...
4632
 
4611
 
4633
		num_connectors++;
4612
		num_connectors++;
Line 4662... Line 4641...
4662
						    dev_priv->lvds_downclock,
4641
						    dev_priv->lvds_downclock,
4663
						    refclk,
4642
						    refclk,
4664
						    &clock,
4643
						    &clock,
4665
						    &reduced_clock);
4644
						    &reduced_clock);
4666
	}
4645
	}
-
 
4646
	/* Compat-code for transition, will disappear. */
-
 
4647
	if (!intel_crtc->config.clock_set) {
-
 
4648
		intel_crtc->config.dpll.n = clock.n;
-
 
4649
		intel_crtc->config.dpll.m1 = clock.m1;
-
 
4650
		intel_crtc->config.dpll.m2 = clock.m2;
-
 
4651
		intel_crtc->config.dpll.p1 = clock.p1;
-
 
4652
		intel_crtc->config.dpll.p2 = clock.p2;
-
 
4653
	}
Line 4667... Line 4654...
4667
 
4654
 
4668
	if (is_sdvo && is_tv)
4655
	if (is_sdvo && is_tv)
Line 4669... Line 4656...
4669
		i9xx_adjust_sdvo_tv_clock(adjusted_mode, &clock);
4656
		i9xx_adjust_sdvo_tv_clock(intel_crtc);
4670
 
4657
 
4671
	if (IS_GEN2(dev))
4658
	if (IS_GEN2(dev))
4672
		i8xx_update_pll(crtc, adjusted_mode, &clock,
4659
		i8xx_update_pll(intel_crtc, adjusted_mode,
4673
				has_reduced_clock ? &reduced_clock : NULL,
4660
				has_reduced_clock ? &reduced_clock : NULL,
4674
				num_connectors);
4661
				num_connectors);
4675
	else if (IS_VALLEYVIEW(dev))
-
 
4676
		vlv_update_pll(crtc, mode, adjusted_mode, &clock,
-
 
4677
				has_reduced_clock ? &reduced_clock : NULL,
4662
	else if (IS_VALLEYVIEW(dev))
4678
				num_connectors);
4663
		vlv_update_pll(intel_crtc);
4679
	else
4664
	else
4680
		i9xx_update_pll(crtc, mode, adjusted_mode, &clock,
4665
		i9xx_update_pll(intel_crtc,
Line 4681... Line -...
4681
				has_reduced_clock ? &reduced_clock : NULL,
-
 
4682
				num_connectors);
-
 
4683
 
-
 
4684
	/* setup pipeconf */
4666
				has_reduced_clock ? &reduced_clock : NULL,
4685
	pipeconf = I915_READ(PIPECONF(pipe));
4667
				num_connectors);
Line -... Line 4668...
-
 
4668
 
4686
 
4669
	/* Set up the display plane register */
4687
	/* Set up the display plane register */
4670
	dspcntr = DISPPLANE_GAMMA_ENABLE;
4688
	dspcntr = DISPPLANE_GAMMA_ENABLE;
4671
 
4689
 
4672
	if (!IS_VALLEYVIEW(dev)) {
4690
	if (pipe == 0)
-
 
4691
		dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
-
 
4692
	else
-
 
4693
		dspcntr |= DISPPLANE_SEL_PIPE_B;
-
 
4694
 
-
 
4695
	if (pipe == 0 && INTEL_INFO(dev)->gen < 4) {
-
 
4696
		/* Enable pixel doubling when the dot clock is > 90% of the (display)
-
 
4697
		 * core speed.
-
 
4698
		 *
-
 
4699
		 * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
-
 
4700
		 * pipe == 0 check?
-
 
4701
		 */
-
 
4702
		if (mode->clock >
-
 
4703
		    dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
-
 
4704
			pipeconf |= PIPECONF_DOUBLE_WIDE;
-
 
4705
		else
-
 
4706
			pipeconf &= ~PIPECONF_DOUBLE_WIDE;
-
 
4707
		}
-
 
4708
 
-
 
4709
	/* default to 8bpc */
-
 
4710
	pipeconf &= ~(PIPECONF_BPC_MASK | PIPECONF_DITHER_EN);
-
 
4711
	if (is_dp) {
-
 
4712
		if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
-
 
4713
			pipeconf |= PIPECONF_6BPC |
-
 
4714
				    PIPECONF_DITHER_EN |
-
 
4715
				    PIPECONF_DITHER_TYPE_SP;
-
 
4716
			}
-
 
4717
		}
-
 
4718
 
-
 
4719
	if (IS_VALLEYVIEW(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
-
 
4720
		if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
-
 
4721
			pipeconf |= PIPECONF_6BPC |
4673
	if (pipe == 0)
Line 4722... Line 4674...
4722
					PIPECONF_ENABLE |
4674
		dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
4723
					I965_PIPECONF_ACTIVE;
4675
	else
Line 4724... Line -...
4724
		}
-
 
4725
	}
-
 
4726
 
-
 
4727
	DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
-
 
4728
	drm_mode_debug_printmodeline(mode);
-
 
4729
 
-
 
4730
	if (HAS_PIPE_CXSR(dev)) {
-
 
4731
		if (intel_crtc->lowfreq_avail) {
-
 
4732
			DRM_DEBUG_KMS("enabling CxSR downclocking\n");
-
 
4733
			pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
-
 
4734
		} else {
-
 
4735
			DRM_DEBUG_KMS("disabling CxSR downclocking\n");
-
 
4736
			pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
-
 
4737
			}
-
 
4738
		}
-
 
4739
 
-
 
4740
	pipeconf &= ~PIPECONF_INTERLACE_MASK;
-
 
4741
	if (!IS_GEN2(dev) &&
4676
		dspcntr |= DISPPLANE_SEL_PIPE_B;
Line 4742... Line 4677...
4742
	    adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
4677
	}
4743
		pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
4678
 
4744
	else
4679
	DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
4745
		pipeconf |= PIPECONF_PROGRESSIVE;
4680
	drm_mode_debug_printmodeline(mode);
4746
 
4681
 
4747
	intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
4682
	intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
4748
 
4683
 
Line 4749... Line 4684...
4749
	/* pipesrc and dspsize control the size that is scaled from,
4684
	/* pipesrc and dspsize control the size that is scaled from,
4750
	 * which should always be the user's requested size.
-
 
-
 
4685
	 * which should always be the user's requested size.
4751
	 */
4686
	 */
Line 4752... Line 4687...
4752
	I915_WRITE(DSPSIZE(plane),
4687
	I915_WRITE(DSPSIZE(plane),
Line 4753... Line 4688...
4753
		   ((mode->vdisplay - 1) << 16) |
4688
		   ((mode->vdisplay - 1) << 16) |
Line 4768... Line 4703...
4768
	intel_update_watermarks(dev);
4703
	intel_update_watermarks(dev);
Line 4769... Line 4704...
4769
 
4704
 
4770
    return ret;
4705
    return ret;
Line -... Line 4706...
-
 
4706
}
-
 
4707
 
-
 
4708
static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
-
 
4709
				 struct intel_crtc_config *pipe_config)
-
 
4710
{
-
 
4711
	struct drm_device *dev = crtc->base.dev;
-
 
4712
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
4713
	uint32_t tmp;
-
 
4714
 
-
 
4715
	tmp = I915_READ(PIPECONF(crtc->pipe));
-
 
4716
	if (!(tmp & PIPECONF_ENABLE))
-
 
4717
		return false;
-
 
4718
 
-
 
4719
	return true;
4771
}
4720
}
4772
 
4721
 
4773
static void ironlake_init_pch_refclk(struct drm_device *dev)
4722
static void ironlake_init_pch_refclk(struct drm_device *dev)
4774
{
4723
{
4775
	struct drm_i915_private *dev_priv = dev->dev_private;
4724
	struct drm_i915_private *dev_priv = dev->dev_private;
4776
	struct drm_mode_config *mode_config = &dev->mode_config;
4725
	struct drm_mode_config *mode_config = &dev->mode_config;
4777
	struct intel_encoder *encoder;
4726
	struct intel_encoder *encoder;
4778
	u32 temp;
4727
	u32 val, final;
4779
	bool has_lvds = false;
4728
	bool has_lvds = false;
4780
	bool has_cpu_edp = false;
4729
	bool has_cpu_edp = false;
4781
	bool has_pch_edp = false;
4730
	bool has_pch_edp = false;
Line 4816... Line 4765...
4816
	/* Ironlake: try to setup display ref clock before DPLL
4765
	/* Ironlake: try to setup display ref clock before DPLL
4817
	 * enabling. This is only under driver's control after
4766
	 * enabling. This is only under driver's control after
4818
	 * PCH B stepping, previous chipset stepping should be
4767
	 * PCH B stepping, previous chipset stepping should be
4819
	 * ignoring this setting.
4768
	 * ignoring this setting.
4820
	 */
4769
	 */
4821
	temp = I915_READ(PCH_DREF_CONTROL);
4770
	val = I915_READ(PCH_DREF_CONTROL);
-
 
4771
 
-
 
4772
	/* As we must carefully and slowly disable/enable each source in turn,
-
 
4773
	 * compute the final state we want first and check if we need to
-
 
4774
	 * make any changes at all.
-
 
4775
	 */
-
 
4776
	final = val;
-
 
4777
	final &= ~DREF_NONSPREAD_SOURCE_MASK;
-
 
4778
	if (has_ck505)
-
 
4779
		final |= DREF_NONSPREAD_CK505_ENABLE;
-
 
4780
	else
-
 
4781
		final |= DREF_NONSPREAD_SOURCE_ENABLE;
-
 
4782
 
-
 
4783
	final &= ~DREF_SSC_SOURCE_MASK;
-
 
4784
	final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
-
 
4785
	final &= ~DREF_SSC1_ENABLE;
-
 
4786
 
-
 
4787
	if (has_panel) {
-
 
4788
		final |= DREF_SSC_SOURCE_ENABLE;
-
 
4789
 
-
 
4790
		if (intel_panel_use_ssc(dev_priv) && can_ssc)
-
 
4791
			final |= DREF_SSC1_ENABLE;
-
 
4792
 
-
 
4793
		if (has_cpu_edp) {
-
 
4794
			if (intel_panel_use_ssc(dev_priv) && can_ssc)
-
 
4795
				final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
-
 
4796
			else
-
 
4797
				final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
-
 
4798
		} else
-
 
4799
			final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
-
 
4800
	} else {
-
 
4801
		final |= DREF_SSC_SOURCE_DISABLE;
-
 
4802
		final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
-
 
4803
	}
-
 
4804
 
-
 
4805
	if (final == val)
-
 
4806
		return;
-
 
4807
 
4822
	/* Always enable nonspread source */
4808
	/* Always enable nonspread source */
4823
	temp &= ~DREF_NONSPREAD_SOURCE_MASK;
4809
	val &= ~DREF_NONSPREAD_SOURCE_MASK;
Line 4824... Line 4810...
4824
 
4810
 
4825
	if (has_ck505)
4811
	if (has_ck505)
4826
		temp |= DREF_NONSPREAD_CK505_ENABLE;
4812
		val |= DREF_NONSPREAD_CK505_ENABLE;
4827
	else
4813
	else
Line 4828... Line 4814...
4828
	temp |= DREF_NONSPREAD_SOURCE_ENABLE;
4814
		val |= DREF_NONSPREAD_SOURCE_ENABLE;
4829
 
4815
 
4830
	if (has_panel) {
4816
	if (has_panel) {
Line 4831... Line 4817...
4831
	temp &= ~DREF_SSC_SOURCE_MASK;
4817
		val &= ~DREF_SSC_SOURCE_MASK;
4832
	temp |= DREF_SSC_SOURCE_ENABLE;
4818
		val |= DREF_SSC_SOURCE_ENABLE;
4833
 
4819
 
4834
		/* SSC must be turned on before enabling the CPU output  */
4820
		/* SSC must be turned on before enabling the CPU output  */
4835
		if (intel_panel_use_ssc(dev_priv) && can_ssc) {
4821
		if (intel_panel_use_ssc(dev_priv) && can_ssc) {
4836
			DRM_DEBUG_KMS("Using SSC on panel\n");
4822
			DRM_DEBUG_KMS("Using SSC on panel\n");
Line 4837... Line 4823...
4837
			temp |= DREF_SSC1_ENABLE;
4823
			val |= DREF_SSC1_ENABLE;
4838
		} else
4824
		} else
4839
			temp &= ~DREF_SSC1_ENABLE;
4825
			val &= ~DREF_SSC1_ENABLE;
4840
 
4826
 
Line 4841... Line 4827...
4841
		/* Get SSC going before enabling the outputs */
4827
		/* Get SSC going before enabling the outputs */
Line 4842... Line 4828...
4842
			I915_WRITE(PCH_DREF_CONTROL, temp);
4828
		I915_WRITE(PCH_DREF_CONTROL, val);
4843
			POSTING_READ(PCH_DREF_CONTROL);
4829
			POSTING_READ(PCH_DREF_CONTROL);
4844
			udelay(200);
4830
			udelay(200);
4845
 
4831
 
4846
		temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
4832
		val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
4847
 
4833
 
4848
		/* Enable CPU source on CPU attached eDP */
4834
		/* Enable CPU source on CPU attached eDP */
4849
		if (has_cpu_edp) {
4835
		if (has_cpu_edp) {
4850
			if (intel_panel_use_ssc(dev_priv) && can_ssc) {
4836
			if (intel_panel_use_ssc(dev_priv) && can_ssc) {
4851
				DRM_DEBUG_KMS("Using SSC on eDP\n");
4837
				DRM_DEBUG_KMS("Using SSC on eDP\n");
Line 4852... Line 4838...
4852
				temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
4838
				val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
4853
			}
4839
			}
4854
			else
4840
			else
4855
				temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
4841
				val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
4856
		} else
4842
		} else
Line 4857... Line 4843...
4857
			temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
4843
			val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Line 4858... Line 4844...
4858
 
4844
 
4859
		I915_WRITE(PCH_DREF_CONTROL, temp);
4845
		I915_WRITE(PCH_DREF_CONTROL, val);
Line 4860... Line 4846...
4860
		POSTING_READ(PCH_DREF_CONTROL);
4846
		POSTING_READ(PCH_DREF_CONTROL);
4861
		udelay(200);
4847
		udelay(200);
4862
		} else {
4848
		} else {
Line 4863... Line 4849...
4863
		DRM_DEBUG_KMS("Disabling SSC entirely\n");
4849
		DRM_DEBUG_KMS("Disabling SSC entirely\n");
4864
 
4850
 
4865
		temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
4851
		val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Line 4866... Line 4852...
4866
 
4852
 
4867
		/* Turn off CPU output */
4853
		/* Turn off CPU output */
Line 4868... Line 4854...
4868
		temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
4854
		val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
4869
 
4855
 
4870
		I915_WRITE(PCH_DREF_CONTROL, temp);
4856
		I915_WRITE(PCH_DREF_CONTROL, val);
4871
		POSTING_READ(PCH_DREF_CONTROL);
4857
		POSTING_READ(PCH_DREF_CONTROL);
-
 
4858
		udelay(200);
-
 
4859
 
4872
		udelay(200);
4860
		/* Turn off the SSC source */
Line 4873... Line 4861...
4873
 
4861
		val &= ~DREF_SSC_SOURCE_MASK;
4874
		/* Turn off the SSC source */
4862
		val |= DREF_SSC_SOURCE_DISABLE;
4875
		temp &= ~DREF_SSC_SOURCE_MASK;
4863
 
Line 4944... Line 4932...
4944
	tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
4932
	tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
4945
	tmp &= ~(0xFF << 24);
4933
	tmp &= ~(0xFF << 24);
4946
	tmp |= (0x12 << 24);
4934
	tmp |= (0x12 << 24);
4947
	intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
4935
	intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
Line 4948... Line -...
4948
 
-
 
4949
	if (!is_sdv) {
-
 
4950
		tmp = intel_sbi_read(dev_priv, 0x808C, SBI_MPHY);
-
 
4951
		tmp &= ~(0x3 << 6);
-
 
4952
		tmp |= (1 << 6) | (1 << 0);
-
 
4953
		intel_sbi_write(dev_priv, 0x808C, tmp, SBI_MPHY);
-
 
4954
	}
-
 
4955
 
4936
 
4956
	if (is_sdv) {
4937
	if (is_sdv) {
4957
		tmp = intel_sbi_read(dev_priv, 0x800C, SBI_MPHY);
4938
		tmp = intel_sbi_read(dev_priv, 0x800C, SBI_MPHY);
4958
		tmp |= 0x7FFF;
4939
		tmp |= 0x7FFF;
4959
		intel_sbi_write(dev_priv, 0x800C, tmp, SBI_MPHY);
4940
		intel_sbi_write(dev_priv, 0x800C, tmp, SBI_MPHY);
Line 5104... Line 5085...
5104
	uint32_t val;
5085
	uint32_t val;
Line 5105... Line 5086...
5105
 
5086
 
Line 5106... Line 5087...
5106
	val = I915_READ(PIPECONF(pipe));
5087
	val = I915_READ(PIPECONF(pipe));
5107
 
5088
 
5108
	val &= ~PIPECONF_BPC_MASK;
5089
	val &= ~PIPECONF_BPC_MASK;
5109
	switch (intel_crtc->bpp) {
5090
	switch (intel_crtc->config.pipe_bpp) {
5110
	case 18:
5091
	case 18:
5111
		val |= PIPECONF_6BPC;
5092
		val |= PIPECONF_6BPC;
5112
		break;
5093
		break;
Line 5132... Line 5113...
5132
	if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
5113
	if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
5133
		val |= PIPECONF_INTERLACED_ILK;
5114
		val |= PIPECONF_INTERLACED_ILK;
5134
	else
5115
	else
5135
		val |= PIPECONF_PROGRESSIVE;
5116
		val |= PIPECONF_PROGRESSIVE;
Line 5136... Line 5117...
5136
 
5117
 
5137
	if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
5118
	if (intel_crtc->config.limited_color_range)
5138
		val |= PIPECONF_COLOR_RANGE_SELECT;
5119
		val |= PIPECONF_COLOR_RANGE_SELECT;
5139
	else
5120
	else
Line 5140... Line 5121...
5140
		val &= ~PIPECONF_COLOR_RANGE_SELECT;
5121
		val &= ~PIPECONF_COLOR_RANGE_SELECT;
Line 5148... Line 5129...
5148
 *
5129
 *
5149
 * Currently only full range RGB to limited range RGB conversion
5130
 * Currently only full range RGB to limited range RGB conversion
5150
 * is supported, but eventually this should handle various
5131
 * is supported, but eventually this should handle various
5151
 * RGB<->YCbCr scenarios as well.
5132
 * RGB<->YCbCr scenarios as well.
5152
 */
5133
 */
5153
static void intel_set_pipe_csc(struct drm_crtc *crtc,
5134
static void intel_set_pipe_csc(struct drm_crtc *crtc)
5154
			       const struct drm_display_mode *adjusted_mode)
-
 
5155
{
5135
{
5156
	struct drm_device *dev = crtc->dev;
5136
	struct drm_device *dev = crtc->dev;
5157
	struct drm_i915_private *dev_priv = dev->dev_private;
5137
	struct drm_i915_private *dev_priv = dev->dev_private;
5158
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5138
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5159
	int pipe = intel_crtc->pipe;
5139
	int pipe = intel_crtc->pipe;
Line 5164... Line 5144...
5164
	 * with these coeff/postoff values and adjust to get the best
5144
	 * with these coeff/postoff values and adjust to get the best
5165
	 * accuracy. Perhaps we even need to take the bpc value into
5145
	 * accuracy. Perhaps we even need to take the bpc value into
5166
	 * consideration.
5146
	 * consideration.
5167
	 */
5147
	 */
Line 5168... Line 5148...
5168
 
5148
 
5169
	if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
5149
	if (intel_crtc->config.limited_color_range)
Line 5170... Line 5150...
5170
		coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
5150
		coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
5171
 
5151
 
5172
	/*
5152
	/*
Line 5188... Line 5168...
5188
	I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
5168
	I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
Line 5189... Line 5169...
5189
 
5169
 
5190
	if (INTEL_INFO(dev)->gen > 6) {
5170
	if (INTEL_INFO(dev)->gen > 6) {
Line 5191... Line 5171...
5191
		uint16_t postoff = 0;
5171
		uint16_t postoff = 0;
5192
 
5172
 
Line 5193... Line 5173...
5193
		if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
5173
		if (intel_crtc->config.limited_color_range)
5194
			postoff = (16 * (1 << 13) / 255) & 0x1fff;
5174
			postoff = (16 * (1 << 13) / 255) & 0x1fff;
5195
 
5175
 
Line 5196... Line 5176...
5196
		I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
5176
		I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
5197
		I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
5177
		I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
5198
		I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
5178
		I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
Line 5199... Line 5179...
5199
 
5179
 
5200
		I915_WRITE(PIPE_CSC_MODE(pipe), 0);
5180
		I915_WRITE(PIPE_CSC_MODE(pipe), 0);
Line 5201... Line 5181...
5201
	} else {
5181
	} else {
5202
		uint32_t mode = CSC_MODE_YUV_TO_RGB;
5182
		uint32_t mode = CSC_MODE_YUV_TO_RGB;
5203
 
5183
 
Line 5212... Line 5192...
5212
				 struct drm_display_mode *adjusted_mode,
5192
				 struct drm_display_mode *adjusted_mode,
5213
				 bool dither)
5193
				 bool dither)
5214
{
5194
{
5215
	struct drm_i915_private *dev_priv = crtc->dev->dev_private;
5195
	struct drm_i915_private *dev_priv = crtc->dev->dev_private;
5216
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5196
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5217
	enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
5197
	enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
5218
	uint32_t val;
5198
	uint32_t val;
Line 5219... Line 5199...
5219
 
5199
 
Line 5220... Line 5200...
5220
	val = I915_READ(PIPECONF(cpu_transcoder));
5200
	val = I915_READ(PIPECONF(cpu_transcoder));
Line 5289... Line 5269...
5289
						     clock,
5269
						     clock,
5290
						     reduced_clock);
5270
						     reduced_clock);
5291
	}
5271
	}
Line 5292... Line 5272...
5292
 
5272
 
5293
	if (is_sdvo && is_tv)
5273
	if (is_sdvo && is_tv)
Line 5294... Line 5274...
5294
		i9xx_adjust_sdvo_tv_clock(adjusted_mode, clock);
5274
		i9xx_adjust_sdvo_tv_clock(to_intel_crtc(crtc));
5295
 
5275
 
Line 5296... Line 5276...
5296
	return true;
5276
	return true;
Line 5330... Line 5310...
5330
		intel_crtc->fdi_lanes = 4;
5310
		intel_crtc->fdi_lanes = 4;
Line 5331... Line 5311...
5331
 
5311
 
5332
		return false;
5312
		return false;
Line 5333... Line 5313...
5333
	}
5313
	}
5334
 
5314
 
Line 5335... Line 5315...
5335
	if (dev_priv->num_pipe == 2)
5315
	if (INTEL_INFO(dev)->num_pipes == 2)
5336
		return true;
5316
		return true;
5337
 
5317
 
Line 5387... Line 5367...
5387
	 */
5367
	 */
5388
	u32 bps = target_clock * bpp * 21 / 20;
5368
	u32 bps = target_clock * bpp * 21 / 20;
5389
	return bps / (link_bw * 8) + 1;
5369
	return bps / (link_bw * 8) + 1;
5390
}
5370
}
Line 5391... Line 5371...
5391
 
5371
 
5392
static void ironlake_set_m_n(struct drm_crtc *crtc,
-
 
5393
                  struct drm_display_mode *mode,
5372
void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
5394
			     struct drm_display_mode *adjusted_mode)
5373
				  struct intel_link_m_n *m_n)
5395
{
5374
{
5396
    struct drm_device *dev = crtc->dev;
5375
	struct drm_device *dev = crtc->base.dev;
5397
    struct drm_i915_private *dev_priv = dev->dev_private;
-
 
5398
    struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
5399
	enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
-
 
5400
	struct intel_encoder *intel_encoder, *edp_encoder = NULL;
5376
	struct drm_i915_private *dev_priv = dev->dev_private;
5401
	struct intel_link_m_n m_n = {0};
-
 
5402
	int target_clock, pixel_multiplier, lane, link_bw;
-
 
Line 5403... Line 5377...
5403
	bool is_dp = false, is_cpu_edp = false;
5377
	int pipe = crtc->pipe;
5404
 
5378
 
5405
	for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
5379
	I915_WRITE(TRANSDATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
5406
		switch (intel_encoder->type) {
-
 
5407
        case INTEL_OUTPUT_DISPLAYPORT:
-
 
5408
            is_dp = true;
-
 
5409
            break;
-
 
5410
        case INTEL_OUTPUT_EDP:
5380
	I915_WRITE(TRANSDATA_N1(pipe), m_n->gmch_n);
5411
			is_dp = true;
-
 
5412
			if (!intel_encoder_is_pch_edp(&intel_encoder->base))
-
 
5413
				is_cpu_edp = true;
-
 
5414
			edp_encoder = intel_encoder;
-
 
5415
            break;
5381
	I915_WRITE(TRANSDPLINK_M1(pipe), m_n->link_m);
Line -... Line 5382...
-
 
5382
	I915_WRITE(TRANSDPLINK_N1(pipe), m_n->link_n);
5416
        }
5383
}
-
 
5384
 
-
 
5385
void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
5417
    }
5386
				  struct intel_link_m_n *m_n)
5418
 
5387
{
5419
    /* FDI link */
5388
	struct drm_device *dev = crtc->base.dev;
-
 
5389
	struct drm_i915_private *dev_priv = dev->dev_private;
5420
    pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
5390
	int pipe = crtc->pipe;
-
 
5391
	enum transcoder transcoder = crtc->config.cpu_transcoder;
-
 
5392
 
5421
    lane = 0;
5393
	if (INTEL_INFO(dev)->gen >= 5) {
5422
    /* CPU eDP doesn't require FDI link, so just set DP M/N
5394
		I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
5423
       according to current link config */
5395
		I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
-
 
5396
		I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
-
 
5397
		I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
-
 
5398
	} else {
-
 
5399
		I915_WRITE(PIPE_GMCH_DATA_M(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
-
 
5400
		I915_WRITE(PIPE_GMCH_DATA_N(pipe), m_n->gmch_n);
-
 
5401
		I915_WRITE(PIPE_DP_LINK_M(pipe), m_n->link_m);
-
 
5402
		I915_WRITE(PIPE_DP_LINK_N(pipe), m_n->link_n);
-
 
5403
	}
-
 
5404
}
-
 
5405
 
-
 
5406
static void ironlake_fdi_set_m_n(struct drm_crtc *crtc)
-
 
5407
{
-
 
5408
    struct drm_device *dev = crtc->dev;
-
 
5409
    struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
5410
	struct drm_display_mode *adjusted_mode =
-
 
5411
		&intel_crtc->config.adjusted_mode;
5424
	if (is_cpu_edp) {
5412
	struct intel_link_m_n m_n = {0};
5425
		intel_edp_link_config(edp_encoder, &lane, &link_bw);
5413
	int target_clock, lane, link_bw;
5426
    } else {
5414
 
5427
        /* FDI is a binary signal running at ~2.7GHz, encoding
5415
        /* FDI is a binary signal running at ~2.7GHz, encoding
5428
         * each output octet as 10 bits. The actual frequency
5416
         * each output octet as 10 bits. The actual frequency
5429
         * is stored as a divider into a 100MHz clock, and the
5417
         * is stored as a divider into a 100MHz clock, and the
5430
         * mode pixel clock is stored in units of 1KHz.
5418
         * mode pixel clock is stored in units of 1KHz.
5431
         * Hence the bw of each lane in terms of the mode signal
5419
         * Hence the bw of each lane in terms of the mode signal
5432
         * is:
-
 
Line 5433... Line -...
5433
         */
-
 
5434
        link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
-
 
5435
    }
5420
         * is:
5436
 
-
 
5437
	/* [e]DP over FDI requires target mode clock instead of link clock. */
5421
         */
5438
	if (edp_encoder)
5422
        link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
5439
		target_clock = intel_edp_target_clock(edp_encoder, mode);
5423
 
Line 5440... Line -...
5440
	else if (is_dp)
-
 
5441
		target_clock = mode->clock;
5424
	if (intel_crtc->config.pixel_target_clock)
5442
	else
5425
		target_clock = intel_crtc->config.pixel_target_clock;
Line 5443... Line 5426...
5443
		target_clock = adjusted_mode->clock;
5426
	else
Line 5444... Line 5427...
5444
 
5427
		target_clock = adjusted_mode->clock;
5445
	if (!lane)
5428
 
5446
		lane = ironlake_get_lanes_required(target_clock, link_bw,
5429
		lane = ironlake_get_lanes_required(target_clock, link_bw,
-
 
5430
					   intel_crtc->config.pipe_bpp);
5447
						   intel_crtc->bpp);
5431
 
5448
 
5432
    intel_crtc->fdi_lanes = lane;
5449
    intel_crtc->fdi_lanes = lane;
-
 
5450
 
-
 
5451
    if (pixel_multiplier > 1)
-
 
5452
        link_bw *= pixel_multiplier;
5433
 
Line 5453... Line 5434...
5453
	intel_link_compute_m_n(intel_crtc->bpp, lane, target_clock, link_bw, &m_n);
5434
	if (intel_crtc->config.pixel_multiplier > 1)
5454
 
5435
		link_bw *= intel_crtc->config.pixel_multiplier;
5455
	I915_WRITE(PIPE_DATA_M1(cpu_transcoder), TU_SIZE(m_n.tu) | m_n.gmch_m);
5436
	intel_link_compute_m_n(intel_crtc->config.pipe_bpp, lane, target_clock,
5456
	I915_WRITE(PIPE_DATA_N1(cpu_transcoder), m_n.gmch_n);
5437
			       link_bw, &m_n);
5457
	I915_WRITE(PIPE_LINK_M1(cpu_transcoder), m_n.link_m);
5438
 
5458
	I915_WRITE(PIPE_LINK_N1(cpu_transcoder), m_n.link_n);
5439
	intel_cpu_transcoder_set_m_n(intel_crtc, &m_n);
5459
}
5440
}
5460
 
5441
 
5461
static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
5442
static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
5462
				      struct drm_display_mode *adjusted_mode,
5443
				      intel_clock_t *clock, u32 *fp,
5463
				      intel_clock_t *clock, u32 fp)
5444
				      intel_clock_t *reduced_clock, u32 *fp2)
5464
{
-
 
Line 5465... Line 5445...
5465
	struct drm_crtc *crtc = &intel_crtc->base;
5445
{
5466
	struct drm_device *dev = crtc->dev;
5446
	struct drm_crtc *crtc = &intel_crtc->base;
5467
	struct drm_i915_private *dev_priv = dev->dev_private;
5447
	struct drm_device *dev = crtc->dev;
5468
	struct intel_encoder *intel_encoder;
5448
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 5483... Line 5463...
5483
				is_tv = true;
5463
				is_tv = true;
5484
			break;
5464
			break;
5485
		case INTEL_OUTPUT_TVOUT:
5465
		case INTEL_OUTPUT_TVOUT:
5486
			is_tv = true;
5466
			is_tv = true;
5487
			break;
5467
			break;
5488
		case INTEL_OUTPUT_DISPLAYPORT:
-
 
5489
			is_dp = true;
-
 
5490
			break;
-
 
5491
		case INTEL_OUTPUT_EDP:
-
 
5492
			is_dp = true;
-
 
5493
			if (!intel_encoder_is_pch_edp(&intel_encoder->base))
-
 
5494
				is_cpu_edp = true;
-
 
5495
			break;
-
 
5496
		}
5468
		}
Line 5497... Line 5469...
5497
 
5469
 
5498
		num_connectors++;
5470
		num_connectors++;
Line 5499... Line 5471...
5499
	}
5471
	}
5500
 
5472
 
5501
    /* Enable autotuning of the PLL clock (if permissible) */
5473
    /* Enable autotuning of the PLL clock (if permissible) */
5502
    factor = 21;
5474
    factor = 21;
5503
    if (is_lvds) {
5475
    if (is_lvds) {
5504
        if ((intel_panel_use_ssc(dev_priv) &&
5476
        if ((intel_panel_use_ssc(dev_priv) &&
5505
             dev_priv->lvds_ssc_freq == 100) ||
5477
             dev_priv->lvds_ssc_freq == 100) ||
5506
		    intel_is_dual_link_lvds(dev))
5478
		    (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev)))
5507
            factor = 25;
5479
            factor = 25;
Line 5508... Line 5480...
5508
    } else if (is_sdvo && is_tv)
5480
    } else if (is_sdvo && is_tv)
5509
        factor = 20;
5481
        factor = 20;
-
 
5482
 
-
 
5483
	if (clock->m < factor * clock->n)
-
 
5484
		*fp |= FP_CB_TUNE;
Line 5510... Line 5485...
5510
 
5485
 
Line 5511... Line 5486...
5511
	if (clock->m < factor * clock->n)
5486
	if (fp2 && (reduced_clock->m < factor * reduced_clock->n))
5512
        fp |= FP_CB_TUNE;
5487
		*fp2 |= FP_CB_TUNE;
5513
 
5488
 
5514
    dpll = 0;
5489
    dpll = 0;
5515
 
5490
 
5516
    if (is_lvds)
5491
    if (is_lvds)
5517
        dpll |= DPLLB_MODE_LVDS;
5492
        dpll |= DPLLB_MODE_LVDS;
5518
    else
5493
    else
5519
        dpll |= DPLLB_MODE_DAC_SERIAL;
5494
        dpll |= DPLLB_MODE_DAC_SERIAL;
5520
    if (is_sdvo) {
5495
    if (is_sdvo) {
5521
		pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
5496
		if (intel_crtc->config.pixel_multiplier > 1) {
5522
        if (pixel_multiplier > 1) {
5497
			dpll |= (intel_crtc->config.pixel_multiplier - 1)
-
 
5498
				<< PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
5523
            dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
5499
        }
Line 5524... Line 5500...
5524
        }
5500
        dpll |= DPLL_DVO_HIGH_SPEED;
5525
        dpll |= DPLL_DVO_HIGH_SPEED;
5501
    }
5526
    }
5502
	if (intel_crtc->config.has_dp_encoder &&
Line 5560... Line 5536...
5560
 
5536
 
5561
	return dpll;
5537
	return dpll;
Line 5562... Line 5538...
5562
}
5538
}
5563
 
-
 
5564
static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
-
 
5565
				  struct drm_display_mode *mode,
5539
 
5566
				  struct drm_display_mode *adjusted_mode,
5540
static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
5567
				  int x, int y,
5541
				  int x, int y,
5568
				  struct drm_framebuffer *fb)
5542
				  struct drm_framebuffer *fb)
5569
{
5543
{
5570
	struct drm_device *dev = crtc->dev;
5544
	struct drm_device *dev = crtc->dev;
-
 
5545
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
5546
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
5547
	struct drm_display_mode *adjusted_mode =
5571
	struct drm_i915_private *dev_priv = dev->dev_private;
5548
		&intel_crtc->config.adjusted_mode;
5572
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5549
	struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
5573
	int pipe = intel_crtc->pipe;
5550
	int pipe = intel_crtc->pipe;
5574
	int plane = intel_crtc->plane;
5551
	int plane = intel_crtc->plane;
5575
	int num_connectors = 0;
5552
	int num_connectors = 0;
5576
	intel_clock_t clock, reduced_clock;
5553
	intel_clock_t clock, reduced_clock;
5577
	u32 dpll, fp = 0, fp2 = 0;
5554
	u32 dpll, fp = 0, fp2 = 0;
5578
	bool ok, has_reduced_clock = false;
5555
	bool ok, has_reduced_clock = false;
5579
	bool is_lvds = false, is_dp = false, is_cpu_edp = false;
5556
	bool is_lvds = false;
5580
	struct intel_encoder *encoder;
5557
	struct intel_encoder *encoder;
Line 5581... Line 5558...
5581
	int ret;
5558
	int ret;
5582
	bool dither, fdi_config_ok;
5559
	bool dither, fdi_config_ok;
5583
 
5560
 
5584
	for_each_encoder_on_crtc(dev, crtc, encoder) {
5561
	for_each_encoder_on_crtc(dev, crtc, encoder) {
5585
		switch (encoder->type) {
5562
		switch (encoder->type) {
5586
		case INTEL_OUTPUT_LVDS:
-
 
5587
			is_lvds = true;
-
 
5588
			break;
-
 
5589
		case INTEL_OUTPUT_DISPLAYPORT:
-
 
5590
			is_dp = true;
-
 
5591
			break;
-
 
5592
		case INTEL_OUTPUT_EDP:
-
 
5593
			is_dp = true;
-
 
5594
			if (!intel_encoder_is_pch_edp(&encoder->base))
5563
		case INTEL_OUTPUT_LVDS:
Line 5595... Line 5564...
5595
				is_cpu_edp = true;
5564
			is_lvds = true;
5596
			break;
5565
			break;
Line 5597... Line 5566...
5597
		}
5566
		}
5598
 
5567
 
Line -... Line 5568...
-
 
5568
		num_connectors++;
-
 
5569
	}
5599
		num_connectors++;
5570
 
5600
	}
5571
	WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
5601
 
5572
	     "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
5602
	WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
5573
 
5603
	     "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
5574
	intel_crtc->config.cpu_transcoder = pipe;
5604
 
5575
 
-
 
5576
	ok = ironlake_compute_clocks(crtc, adjusted_mode, &clock,
-
 
5577
				     &has_reduced_clock, &reduced_clock);
-
 
5578
	if (!ok) {
-
 
5579
		DRM_ERROR("Couldn't find PLL settings for mode!\n");
-
 
5580
		return -EINVAL;
-
 
5581
	}
-
 
5582
	/* Compat-code for transition, will disappear. */
-
 
5583
	if (!intel_crtc->config.clock_set) {
Line 5605... Line 5584...
5605
	ok = ironlake_compute_clocks(crtc, adjusted_mode, &clock,
5584
		intel_crtc->config.dpll.n = clock.n;
5606
				     &has_reduced_clock, &reduced_clock);
5585
		intel_crtc->config.dpll.m1 = clock.m1;
Line 5607... Line 5586...
5607
	if (!ok) {
5586
		intel_crtc->config.dpll.m2 = clock.m2;
5608
		DRM_ERROR("Couldn't find PLL settings for mode!\n");
5587
		intel_crtc->config.dpll.p1 = clock.p1;
5609
		return -EINVAL;
-
 
5610
	}
5588
		intel_crtc->config.dpll.p2 = clock.p2;
5611
 
5589
	}
Line 5612... Line 5590...
5612
	/* Ensure that the cursor is valid for the new mode before changing... */
5590
 
5613
//	intel_crtc_update_cursor(crtc, true);
5591
	/* Ensure that the cursor is valid for the new mode before changing... */
5614
 
5592
//	intel_crtc_update_cursor(crtc, true);
5615
	/* determine panel color depth */
5593
 
Line 5616... Line 5594...
5616
	dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
5594
	/* determine panel color depth */
-
 
5595
	dither = intel_crtc->config.dither;
Line 5617... Line 5596...
5617
					      adjusted_mode);
5596
	if (is_lvds && dev_priv->lvds_dither)
5618
	if (is_lvds && dev_priv->lvds_dither)
5597
		dither = true;
Line 5619... Line 5598...
5619
		dither = true;
5598
 
5620
 
5599
	fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
5621
	fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
5600
	if (has_reduced_clock)
Line 5622... Line 5601...
5622
	if (has_reduced_clock)
5601
		fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
5623
		fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
5602
			reduced_clock.m2;
5624
			reduced_clock.m2;
5603
 
Line 5639... Line 5618...
5639
			return -EINVAL;
5618
			return -EINVAL;
5640
        }
5619
        }
5641
	} else
5620
	} else
5642
		intel_put_pch_pll(intel_crtc);
5621
		intel_put_pch_pll(intel_crtc);
Line 5643... Line 5622...
5643
 
5622
 
5644
	if (is_dp && !is_cpu_edp)
5623
	if (intel_crtc->config.has_dp_encoder)
Line 5645... Line 5624...
5645
		intel_dp_set_m_n(crtc, mode, adjusted_mode);
5624
		intel_dp_set_m_n(intel_crtc);
5646
 
5625
 
5647
	for_each_encoder_on_crtc(dev, crtc, encoder)
5626
	for_each_encoder_on_crtc(dev, crtc, encoder)
Line 5675... Line 5654...
5675
 
5654
 
Line 5676... Line 5655...
5676
	intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
5655
	intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
5677
 
5656
 
-
 
5657
	/* Note, this also computes intel_crtc->fdi_lanes which is used below in
-
 
5658
	 * ironlake_check_fdi_lanes. */
5678
	/* Note, this also computes intel_crtc->fdi_lanes which is used below in
5659
	intel_crtc->fdi_lanes = 0;
Line 5679... Line 5660...
5679
	 * ironlake_check_fdi_lanes. */
5660
	if (intel_crtc->config.has_pch_encoder)
Line 5680... Line 5661...
5680
	ironlake_set_m_n(crtc, mode, adjusted_mode);
5661
		ironlake_fdi_set_m_n(crtc);
Line 5696... Line 5677...
5696
	intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
5677
	intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
Line 5697... Line 5678...
5697
 
5678
 
5698
	return fdi_config_ok ? ret : -EINVAL;
5679
	return fdi_config_ok ? ret : -EINVAL;
Line -... Line 5680...
-
 
5680
}
-
 
5681
 
-
 
5682
static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
-
 
5683
				     struct intel_crtc_config *pipe_config)
-
 
5684
{
-
 
5685
	struct drm_device *dev = crtc->base.dev;
-
 
5686
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
5687
	uint32_t tmp;
-
 
5688
 
-
 
5689
	tmp = I915_READ(PIPECONF(crtc->pipe));
-
 
5690
	if (!(tmp & PIPECONF_ENABLE))
-
 
5691
		return false;
-
 
5692
 
-
 
5693
	if (I915_READ(TRANSCONF(crtc->pipe)) & TRANS_ENABLE)
-
 
5694
		pipe_config->has_pch_encoder = true;
-
 
5695
 
-
 
5696
	return true;
5699
}
5697
}
5700
 
5698
 
5701
static void haswell_modeset_global_resources(struct drm_device *dev)
5699
static void haswell_modeset_global_resources(struct drm_device *dev)
5702
{
5700
{
5703
	struct drm_i915_private *dev_priv = dev->dev_private;
5701
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 5726... Line 5724...
5726
 
5724
 
5727
	intel_set_power_well(dev, enable);
5725
	intel_set_power_well(dev, enable);
Line 5728... Line 5726...
5728
}
5726
}
5729
 
-
 
5730
static int haswell_crtc_mode_set(struct drm_crtc *crtc,
-
 
5731
				 struct drm_display_mode *mode,
5727
 
5732
				 struct drm_display_mode *adjusted_mode,
5728
static int haswell_crtc_mode_set(struct drm_crtc *crtc,
5733
				 int x, int y,
5729
				 int x, int y,
5734
				 struct drm_framebuffer *fb)
5730
				 struct drm_framebuffer *fb)
5735
{
5731
{
5736
	struct drm_device *dev = crtc->dev;
5732
	struct drm_device *dev = crtc->dev;
-
 
5733
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
5734
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
5735
	struct drm_display_mode *adjusted_mode =
5737
	struct drm_i915_private *dev_priv = dev->dev_private;
5736
		&intel_crtc->config.adjusted_mode;
5738
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5737
	struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
5739
	int pipe = intel_crtc->pipe;
5738
	int pipe = intel_crtc->pipe;
5740
	int plane = intel_crtc->plane;
5739
	int plane = intel_crtc->plane;
5741
	int num_connectors = 0;
5740
	int num_connectors = 0;
5742
	bool is_dp = false, is_cpu_edp = false;
5741
	bool is_cpu_edp = false;
5743
	struct intel_encoder *encoder;
5742
	struct intel_encoder *encoder;
Line 5744... Line 5743...
5744
	int ret;
5743
	int ret;
5745
	bool dither;
5744
	bool dither;
5746
 
-
 
5747
	for_each_encoder_on_crtc(dev, crtc, encoder) {
-
 
5748
		switch (encoder->type) {
-
 
5749
		case INTEL_OUTPUT_DISPLAYPORT:
5745
 
5750
			is_dp = true;
-
 
5751
			break;
5746
	for_each_encoder_on_crtc(dev, crtc, encoder) {
5752
		case INTEL_OUTPUT_EDP:
5747
		switch (encoder->type) {
5753
			is_dp = true;
5748
		case INTEL_OUTPUT_EDP:
5754
			if (!intel_encoder_is_pch_edp(&encoder->base))
5749
			if (!intel_encoder_is_pch_edp(&encoder->base))
Line 5755... Line 5750...
5755
				is_cpu_edp = true;
5750
				is_cpu_edp = true;
5756
			break;
5751
			break;
Line 5757... Line 5752...
5757
		}
5752
		}
5758
 
5753
 
5759
		num_connectors++;
5754
		num_connectors++;
5760
	}
5755
	}
Line 5761... Line 5756...
5761
 
5756
 
5762
	if (is_cpu_edp)
5757
	if (is_cpu_edp)
5763
		intel_crtc->cpu_transcoder = TRANSCODER_EDP;
5758
		intel_crtc->config.cpu_transcoder = TRANSCODER_EDP;
Line 5764... Line 5759...
5764
	else
5759
	else
5765
		intel_crtc->cpu_transcoder = pipe;
5760
		intel_crtc->config.cpu_transcoder = pipe;
Line 5766... Line 5761...
5766
 
5761
 
5767
	/* We are not sure yet this won't happen. */
5762
	/* We are not sure yet this won't happen. */
Line 5768... Line 5763...
5768
	WARN(!HAS_PCH_LPT(dev), "Unexpected PCH type %d\n",
5763
	WARN(!HAS_PCH_LPT(dev), "Unexpected PCH type %d\n",
Line 5769... Line 5764...
5769
	     INTEL_PCH_TYPE(dev));
5764
	     INTEL_PCH_TYPE(dev));
Line 5781... Line 5776...
5781
 
5776
 
5782
	/* Ensure that the cursor is valid for the new mode before changing... */
5777
	/* Ensure that the cursor is valid for the new mode before changing... */
Line 5783... Line 5778...
5783
//   intel_crtc_update_cursor(crtc, true);
5778
//   intel_crtc_update_cursor(crtc, true);
5784
 
5779
 
5785
	/* determine panel color depth */
-
 
Line 5786... Line 5780...
5786
	dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
5780
	/* determine panel color depth */
5787
					      adjusted_mode);
5781
	dither = intel_crtc->config.dither;
Line 5788... Line 5782...
5788
 
5782
 
5789
	DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
5783
	DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
Line 5790... Line 5784...
5790
	drm_mode_debug_printmodeline(mode);
5784
	drm_mode_debug_printmodeline(mode);
Line 5791... Line 5785...
5791
 
5785
 
Line 5792... Line 5786...
5792
	if (is_dp && !is_cpu_edp)
5786
	if (intel_crtc->config.has_dp_encoder)
5793
		intel_dp_set_m_n(crtc, mode, adjusted_mode);
5787
		intel_dp_set_m_n(intel_crtc);
Line 5794... Line 5788...
5794
 
5788
 
Line 5795... Line 5789...
5795
	intel_crtc->lowfreq_avail = false;
5789
	intel_crtc->lowfreq_avail = false;
Line 5796... Line 5790...
5796
 
5790
 
5797
	intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
5791
	intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
5798
 
5792
 
Line 5814... Line 5808...
5814
	intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
5808
	intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
Line 5815... Line 5809...
5815
 
5809
 
5816
    return ret;
5810
    return ret;
Line -... Line 5811...
-
 
5811
}
-
 
5812
 
-
 
5813
static bool haswell_get_pipe_config(struct intel_crtc *crtc,
-
 
5814
				    struct intel_crtc_config *pipe_config)
-
 
5815
{
-
 
5816
	struct drm_device *dev = crtc->base.dev;
-
 
5817
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
5818
	uint32_t tmp;
-
 
5819
 
-
 
5820
	tmp = I915_READ(PIPECONF(crtc->config.cpu_transcoder));
-
 
5821
	if (!(tmp & PIPECONF_ENABLE))
-
 
5822
		return false;
-
 
5823
 
-
 
5824
	/*
-
 
5825
	 * aswell has only FDI/PCH transcoder A. It is which is connected to
-
 
5826
	 * DDI E. So just check whether this pipe is wired to DDI E and whether
-
 
5827
	 * the PCH transcoder is on.
-
 
5828
	 */
-
 
5829
	tmp = I915_READ(TRANS_DDI_FUNC_CTL(crtc->pipe));
-
 
5830
	if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(PORT_E) &&
-
 
5831
	    I915_READ(TRANSCONF(PIPE_A)) & TRANS_ENABLE)
-
 
5832
		pipe_config->has_pch_encoder = true;
-
 
5833
 
-
 
5834
 
-
 
5835
	return true;
5817
}
5836
}
5818
 
-
 
5819
static int intel_crtc_mode_set(struct drm_crtc *crtc,
-
 
5820
			       struct drm_display_mode *mode,
5837
 
5821
			       struct drm_display_mode *adjusted_mode,
5838
static int intel_crtc_mode_set(struct drm_crtc *crtc,
5822
			       int x, int y,
5839
			       int x, int y,
5823
			       struct drm_framebuffer *fb)
5840
			       struct drm_framebuffer *fb)
5824
{
5841
{
5825
	struct drm_device *dev = crtc->dev;
5842
	struct drm_device *dev = crtc->dev;
5826
	struct drm_i915_private *dev_priv = dev->dev_private;
5843
	struct drm_i915_private *dev_priv = dev->dev_private;
5827
	struct drm_encoder_helper_funcs *encoder_funcs;
5844
	struct drm_encoder_helper_funcs *encoder_funcs;
-
 
5845
	struct intel_encoder *encoder;
-
 
5846
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
5847
	struct drm_display_mode *adjusted_mode =
5828
	struct intel_encoder *encoder;
5848
		&intel_crtc->config.adjusted_mode;
5829
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5849
	struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
Line 5830... Line 5850...
5830
	int pipe = intel_crtc->pipe;
5850
	int pipe = intel_crtc->pipe;
Line 5831... Line 5851...
5831
	int ret;
5851
	int ret;
5832
 
-
 
-
 
5852
 
5833
	drm_vblank_pre_modeset(dev, pipe);
5853
	drm_vblank_pre_modeset(dev, pipe);
Line 5834... Line 5854...
5834
 
5854
 
5835
	ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode,
5855
	ret = dev_priv->display.crtc_mode_set(crtc, x, y, fb);
Line 5836... Line 5856...
5836
					      x, y, fb);
5856
 
5837
	drm_vblank_post_modeset(dev, pipe);
5857
	drm_vblank_post_modeset(dev, pipe);
5838
 
5858
 
5839
	if (ret != 0)
5859
	if (ret != 0)
5840
	return ret;
5860
	return ret;
-
 
5861
 
-
 
5862
	for_each_encoder_on_crtc(dev, crtc, encoder) {
-
 
5863
		DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
5841
 
5864
			encoder->base.base.id,
5842
	for_each_encoder_on_crtc(dev, crtc, encoder) {
5865
			drm_get_encoder_name(&encoder->base),
5843
		DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
5866
			mode->base.id, mode->name);
-
 
5867
		if (encoder->mode_set) {
Line 5844... Line 5868...
5844
			encoder->base.base.id,
5868
			encoder->mode_set(encoder);
5845
			drm_get_encoder_name(&encoder->base),
5869
		} else {
Line 5846... Line 5870...
5846
			mode->base.id, mode->name);
5870
		encoder_funcs = encoder->base.helper_private;
Line 6312... Line 6336...
6312
	}
6336
	}
Line 6313... Line 6337...
6313
 
6337
 
6314
	/* we only need to pin inside GTT if cursor is non-phy */
6338
	/* we only need to pin inside GTT if cursor is non-phy */
6315
	mutex_lock(&dev->struct_mutex);
6339
	mutex_lock(&dev->struct_mutex);
-
 
6340
	if (!dev_priv->info->cursor_needs_physical) {
-
 
6341
		unsigned alignment;
6316
	if (!dev_priv->info->cursor_needs_physical) {
6342
 
6317
		if (obj->tiling_mode) {
6343
		if (obj->tiling_mode) {
6318
			DRM_ERROR("cursor cannot be tiled\n");
6344
			DRM_ERROR("cursor cannot be tiled\n");
6319
			ret = -EINVAL;
6345
			ret = -EINVAL;
6320
			goto fail_locked;
6346
			goto fail_locked;
Line -... Line 6347...
-
 
6347
		}
-
 
6348
 
-
 
6349
		/* Note that the w/a also requires 2 PTE of padding following
-
 
6350
		 * the bo. We currently fill all unused PTE with the shadow
-
 
6351
		 * page and so we should always have valid PTE following the
-
 
6352
		 * cursor preventing the VT-d warning.
-
 
6353
		 */
-
 
6354
		alignment = 0;
-
 
6355
		if (need_vtd_wa(dev))
6321
		}
6356
			alignment = 64*1024;
6322
 
6357
 
6323
		ret = i915_gem_object_pin_to_display_plane(obj, 0, NULL);
6358
		ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL);
6324
		if (ret) {
6359
		if (ret) {
6325
			DRM_ERROR("failed to move cursor bo into the GTT\n");
6360
			DRM_ERROR("failed to move cursor bo into the GTT\n");
Line 6424... Line 6459...
6424
	}
6459
	}
Line 6425... Line 6460...
6425
 
6460
 
6426
	intel_crtc_load_lut(crtc);
6461
	intel_crtc_load_lut(crtc);
Line 6427... Line -...
6427
}
-
 
6428
 
-
 
6429
/**
-
 
6430
 * Get a pipe with a simple mode set on it for doing load-based monitor
-
 
6431
 * detection.
-
 
6432
 *
-
 
6433
 * It will be up to the load-detect code to adjust the pipe as appropriate for
-
 
6434
 * its requirements.  The pipe will be connected to no other encoders.
-
 
6435
 *
-
 
6436
 * Currently this code will only succeed if there is a pipe with no encoders
-
 
6437
 * configured for it.  In the future, it could choose to temporarily disable
-
 
6438
 * some outputs to free up a pipe for its use.
-
 
6439
 *
-
 
6440
 * \return crtc, or NULL if no pipes are available.
-
 
6441
 */
6462
}
6442
 
6463
 
6443
/* VESA 640x480x72Hz mode to set on the pipe */
6464
/* VESA 640x480x72Hz mode to set on the pipe */
6444
static struct drm_display_mode load_detect_mode = {
6465
static struct drm_display_mode load_detect_mode = {
6445
	DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
6466
	DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
Line 6764... Line 6785...
6764
struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
6785
struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
6765
					     struct drm_crtc *crtc)
6786
					     struct drm_crtc *crtc)
6766
{
6787
{
6767
	struct drm_i915_private *dev_priv = dev->dev_private;
6788
	struct drm_i915_private *dev_priv = dev->dev_private;
6768
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6789
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6769
	enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
6790
	enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
6770
	struct drm_display_mode *mode;
6791
	struct drm_display_mode *mode;
6771
	int htot = I915_READ(HTOTAL(cpu_transcoder));
6792
	int htot = I915_READ(HTOTAL(cpu_transcoder));
6772
	int hsync = I915_READ(HSYNC(cpu_transcoder));
6793
	int hsync = I915_READ(HSYNC(cpu_transcoder));
6773
	int vtot = I915_READ(VTOTAL(cpu_transcoder));
6794
	int vtot = I915_READ(VTOTAL(cpu_transcoder));
6774
	int vsync = I915_READ(VSYNC(cpu_transcoder));
6795
	int vsync = I915_READ(VSYNC(cpu_transcoder));
Line 6943... Line 6964...
6943
				      struct drm_crtc *crtc)
6964
				      struct drm_crtc *crtc)
6944
{
6965
{
6945
	drm_i915_private_t *dev_priv = dev->dev_private;
6966
	drm_i915_private_t *dev_priv = dev->dev_private;
6946
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6967
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6947
	struct intel_unpin_work *work;
6968
	struct intel_unpin_work *work;
6948
	struct drm_i915_gem_object *obj;
-
 
6949
	unsigned long flags;
6969
	unsigned long flags;
Line 6950... Line 6970...
6950
 
6970
 
6951
	/* Ignore early vblank irqs */
6971
	/* Ignore early vblank irqs */
6952
	if (intel_crtc == NULL)
6972
	if (intel_crtc == NULL)
Line 6973... Line 6993...
6973
 
6993
 
Line 6974... Line 6994...
6974
	drm_vblank_put(dev, intel_crtc->pipe);
6994
	drm_vblank_put(dev, intel_crtc->pipe);
Line 6975... Line -...
6975
 
-
 
6976
	spin_unlock_irqrestore(&dev->event_lock, flags);
-
 
6977
 
6995
 
Line 6978... Line 6996...
6978
	obj = work->old_fb_obj;
6996
	spin_unlock_irqrestore(&dev->event_lock, flags);
Line 6979... Line 6997...
6979
 
6997
 
Line 7464... Line 7482...
7464
			    base.head) {
7482
			    base.head) {
7465
		encoder->base.crtc = &encoder->new_crtc->base;
7483
		encoder->base.crtc = &encoder->new_crtc->base;
7466
	}
7484
	}
7467
}
7485
}
Line -... Line 7486...
-
 
7486
 
-
 
7487
static int
-
 
7488
pipe_config_set_bpp(struct drm_crtc *crtc,
-
 
7489
		    struct drm_framebuffer *fb,
-
 
7490
		    struct intel_crtc_config *pipe_config)
-
 
7491
{
-
 
7492
	struct drm_device *dev = crtc->dev;
-
 
7493
	struct drm_connector *connector;
-
 
7494
	int bpp;
-
 
7495
 
-
 
7496
	switch (fb->pixel_format) {
-
 
7497
	case DRM_FORMAT_C8:
-
 
7498
		bpp = 8*3; /* since we go through a colormap */
-
 
7499
		break;
-
 
7500
	case DRM_FORMAT_XRGB1555:
-
 
7501
	case DRM_FORMAT_ARGB1555:
-
 
7502
		/* checked in intel_framebuffer_init already */
-
 
7503
		if (WARN_ON(INTEL_INFO(dev)->gen > 3))
-
 
7504
			return -EINVAL;
-
 
7505
	case DRM_FORMAT_RGB565:
-
 
7506
		bpp = 6*3; /* min is 18bpp */
-
 
7507
		break;
-
 
7508
	case DRM_FORMAT_XBGR8888:
-
 
7509
	case DRM_FORMAT_ABGR8888:
-
 
7510
		/* checked in intel_framebuffer_init already */
-
 
7511
		if (WARN_ON(INTEL_INFO(dev)->gen < 4))
-
 
7512
			return -EINVAL;
-
 
7513
	case DRM_FORMAT_XRGB8888:
-
 
7514
	case DRM_FORMAT_ARGB8888:
-
 
7515
		bpp = 8*3;
-
 
7516
		break;
-
 
7517
	case DRM_FORMAT_XRGB2101010:
-
 
7518
	case DRM_FORMAT_ARGB2101010:
-
 
7519
	case DRM_FORMAT_XBGR2101010:
-
 
7520
	case DRM_FORMAT_ABGR2101010:
-
 
7521
		/* checked in intel_framebuffer_init already */
-
 
7522
		if (WARN_ON(INTEL_INFO(dev)->gen < 4))
-
 
7523
			return -EINVAL;
-
 
7524
		bpp = 10*3;
-
 
7525
		break;
-
 
7526
	/* TODO: gen4+ supports 16 bpc floating point, too. */
-
 
7527
	default:
-
 
7528
		DRM_DEBUG_KMS("unsupported depth\n");
-
 
7529
		return -EINVAL;
-
 
7530
	}
-
 
7531
 
-
 
7532
	pipe_config->pipe_bpp = bpp;
-
 
7533
 
-
 
7534
	/* Clamp display bpp to EDID value */
-
 
7535
	list_for_each_entry(connector, &dev->mode_config.connector_list,
-
 
7536
			    head) {
-
 
7537
		if (connector->encoder && connector->encoder->crtc != crtc)
-
 
7538
			continue;
-
 
7539
 
-
 
7540
		/* Don't use an invalid EDID bpc value */
-
 
7541
		if (connector->display_info.bpc &&
-
 
7542
		    connector->display_info.bpc * 3 < bpp) {
-
 
7543
			DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
-
 
7544
				      bpp, connector->display_info.bpc*3);
-
 
7545
			pipe_config->pipe_bpp = connector->display_info.bpc*3;
-
 
7546
		}
-
 
7547
	}
-
 
7548
 
-
 
7549
	return bpp;
-
 
7550
}
7468
 
7551
 
7469
static struct drm_display_mode *
7552
static struct intel_crtc_config *
-
 
7553
intel_modeset_pipe_config(struct drm_crtc *crtc,
7470
intel_modeset_adjusted_mode(struct drm_crtc *crtc,
7554
			  struct drm_framebuffer *fb,
7471
			    struct drm_display_mode *mode)
7555
			    struct drm_display_mode *mode)
7472
{
7556
{
7473
	struct drm_device *dev = crtc->dev;
-
 
7474
	struct drm_display_mode *adjusted_mode;
7557
	struct drm_device *dev = crtc->dev;
7475
	struct drm_encoder_helper_funcs *encoder_funcs;
7558
	struct drm_encoder_helper_funcs *encoder_funcs;
-
 
7559
	struct intel_encoder *encoder;
-
 
7560
	struct intel_crtc_config *pipe_config;
Line 7476... Line 7561...
7476
	struct intel_encoder *encoder;
7561
	int plane_bpp;
7477
 
7562
 
7478
	adjusted_mode = drm_mode_duplicate(dev, mode);
7563
	pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
Line -... Line 7564...
-
 
7564
	if (!pipe_config)
-
 
7565
		return ERR_PTR(-ENOMEM);
-
 
7566
 
-
 
7567
	drm_mode_copy(&pipe_config->adjusted_mode, mode);
-
 
7568
	drm_mode_copy(&pipe_config->requested_mode, mode);
-
 
7569
 
-
 
7570
	plane_bpp = pipe_config_set_bpp(crtc, fb, pipe_config);
7479
	if (!adjusted_mode)
7571
	if (plane_bpp < 0)
7480
		return ERR_PTR(-ENOMEM);
7572
		goto fail;
7481
 
7573
 
7482
	/* Pass our mode to the connectors and the CRTC to give them a chance to
7574
	/* Pass our mode to the connectors and the CRTC to give them a chance to
7483
	 * adjust it according to limitations or connector properties, and also
7575
	 * adjust it according to limitations or connector properties, and also
7484
	 * a chance to reject the mode entirely.
7576
	 * a chance to reject the mode entirely.
Line 7485... Line 7577...
7485
	 */
7577
	 */
7486
	list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7578
	list_for_each_entry(encoder, &dev->mode_config.encoder_list,
-
 
7579
			    base.head) {
-
 
7580
 
-
 
7581
		if (&encoder->new_crtc->base != crtc)
-
 
7582
			continue;
-
 
7583
 
-
 
7584
		if (encoder->compute_config) {
-
 
7585
			if (!(encoder->compute_config(encoder, pipe_config))) {
-
 
7586
				DRM_DEBUG_KMS("Encoder config failure\n");
-
 
7587
				goto fail;
-
 
7588
			}
7487
			    base.head) {
7589
 
7488
 
7590
			continue;
-
 
7591
		}
7489
		if (&encoder->new_crtc->base != crtc)
7592
 
7490
			continue;
7593
		encoder_funcs = encoder->base.helper_private;
7491
		encoder_funcs = encoder->base.helper_private;
7594
		if (!(encoder_funcs->mode_fixup(&encoder->base,
7492
		if (!(encoder_funcs->mode_fixup(&encoder->base, mode,
7595
						&pipe_config->requested_mode,
7493
						adjusted_mode))) {
7596
						&pipe_config->adjusted_mode))) {
Line 7494... Line 7597...
7494
			DRM_DEBUG_KMS("Encoder fixup failed\n");
7597
			DRM_DEBUG_KMS("Encoder fixup failed\n");
7495
			goto fail;
7598
			goto fail;
7496
		}
7599
		}
7497
	}
7600
	}
7498
 
7601
 
Line -... Line 7602...
-
 
7602
	if (!(intel_crtc_compute_config(crtc, pipe_config))) {
-
 
7603
		DRM_DEBUG_KMS("CRTC fixup failed\n");
-
 
7604
		goto fail;
-
 
7605
	}
7499
	if (!(intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
7606
	DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
7500
		DRM_DEBUG_KMS("CRTC fixup failed\n");
7607
 
7501
		goto fail;
7608
	pipe_config->dither = pipe_config->pipe_bpp != plane_bpp;
7502
	}
7609
	DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
7503
	DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
7610
		      plane_bpp, pipe_config->pipe_bpp, pipe_config->dither);
Line 7504... Line 7611...
7504
 
7611
 
7505
	return adjusted_mode;
7612
	return pipe_config;
Line 7580... Line 7687...
7580
	/* set_mode is also used to update properties on life display pipes. */
7687
	/* set_mode is also used to update properties on life display pipes. */
7581
	intel_crtc = to_intel_crtc(crtc);
7688
	intel_crtc = to_intel_crtc(crtc);
7582
	if (crtc->enabled)
7689
	if (crtc->enabled)
7583
		*prepare_pipes |= 1 << intel_crtc->pipe;
7690
		*prepare_pipes |= 1 << intel_crtc->pipe;
Line 7584... Line -...
7584
 
-
 
7585
	/* We only support modeset on one single crtc, hence we need to do that
-
 
7586
	 * only for the passed in crtc iff we change anything else than just
-
 
7587
	 * disable crtcs.
7691
 
7588
	 *
7692
	/*
7589
	 * This is actually not true, to be fully compatible with the old crtc
7693
	 * For simplicity do a full modeset on any pipe where the output routing
7590
	 * helper we automatically disable _any_ output (i.e. doesn't need to be
7694
	 * changed. We could be more clever, but that would require us to be
7591
	 * connected to the crtc we're modesetting on) if it's disconnected.
-
 
7592
	 * Which is a rather nutty api (since changed the output configuration
-
 
7593
	 * without userspace's explicit request can lead to confusion), but
-
 
-
 
7695
	 * more careful with calling the relevant encoder->mode_set functions.
7594
	 * alas. Hence we currently need to modeset on all pipes we prepare. */
7696
	 */
7595
	if (*prepare_pipes)
7697
	if (*prepare_pipes)
Line 7596... Line 7698...
7596
		*modeset_pipes = *prepare_pipes;
7698
		*modeset_pipes = *prepare_pipes;
7597
 
7699
 
7598
	/* ... and mask these out. */
7700
	/* ... and mask these out. */
-
 
7701
	*modeset_pipes &= ~(*disable_pipes);
-
 
7702
	*prepare_pipes &= ~(*disable_pipes);
-
 
7703
 
-
 
7704
	/*
-
 
7705
	 * HACK: We don't (yet) fully support global modesets. intel_set_config
-
 
7706
	 * obies this rule, but the modeset restore mode of
-
 
7707
	 * intel_modeset_setup_hw_state does not.
-
 
7708
	 */
7599
	*modeset_pipes &= ~(*disable_pipes);
7709
	*modeset_pipes &= 1 << intel_crtc->pipe;
Line 7600... Line 7710...
7600
	*prepare_pipes &= ~(*disable_pipes);
7710
	*prepare_pipes &= 1 << intel_crtc->pipe;
7601
}
7711
}
7602
 
7712
 
Line 7664... Line 7774...
7664
	list_for_each_entry((intel_crtc), \
7774
	list_for_each_entry((intel_crtc), \
7665
			    &(dev)->mode_config.crtc_list, \
7775
			    &(dev)->mode_config.crtc_list, \
7666
			    base.head) \
7776
			    base.head) \
7667
		if (mask & (1 <<(intel_crtc)->pipe)) \
7777
		if (mask & (1 <<(intel_crtc)->pipe)) \
Line -... Line 7778...
-
 
7778
 
-
 
7779
static bool
-
 
7780
intel_pipe_config_compare(struct intel_crtc_config *current_config,
-
 
7781
			  struct intel_crtc_config *pipe_config)
-
 
7782
{
-
 
7783
	if (current_config->has_pch_encoder != pipe_config->has_pch_encoder) {
-
 
7784
		DRM_ERROR("mismatch in has_pch_encoder "
-
 
7785
			  "(expected %i, found %i)\n",
-
 
7786
			  current_config->has_pch_encoder,
-
 
7787
			  pipe_config->has_pch_encoder);
-
 
7788
		return false;
-
 
7789
	}
-
 
7790
 
-
 
7791
	return true;
-
 
7792
}
7668
 
7793
 
7669
void
7794
void
7670
intel_modeset_check_state(struct drm_device *dev)
7795
intel_modeset_check_state(struct drm_device *dev)
-
 
7796
{
7671
{
7797
	drm_i915_private_t *dev_priv = dev->dev_private;
7672
	struct intel_crtc *crtc;
7798
	struct intel_crtc *crtc;
7673
	struct intel_encoder *encoder;
7799
	struct intel_encoder *encoder;
-
 
7800
	struct intel_connector *connector;
Line 7674... Line 7801...
7674
	struct intel_connector *connector;
7801
	struct intel_crtc_config pipe_config;
7675
 
7802
 
7676
	list_for_each_entry(connector, &dev->mode_config.connector_list,
7803
	list_for_each_entry(connector, &dev->mode_config.connector_list,
7677
			    base.head) {
7804
			    base.head) {
Line 7758... Line 7885...
7758
		     "(expected %i, found %i)\n", active, crtc->active);
7885
		     "(expected %i, found %i)\n", active, crtc->active);
7759
		WARN(enabled != crtc->base.enabled,
7886
		WARN(enabled != crtc->base.enabled,
7760
		     "crtc's computed enabled state doesn't match tracked enabled state "
7887
		     "crtc's computed enabled state doesn't match tracked enabled state "
7761
		     "(expected %i, found %i)\n", enabled, crtc->base.enabled);
7888
		     "(expected %i, found %i)\n", enabled, crtc->base.enabled);
Line -... Line 7889...
-
 
7889
 
-
 
7890
		memset(&pipe_config, 0, sizeof(pipe_config));
-
 
7891
		active = dev_priv->display.get_pipe_config(crtc,
-
 
7892
							   &pipe_config);
-
 
7893
 
-
 
7894
		/* hw state is inconsistent with the pipe A quirk */
-
 
7895
		if (crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
-
 
7896
			active = crtc->active;
-
 
7897
 
-
 
7898
		WARN(crtc->active != active,
7762
 
7899
		     "crtc active state doesn't match with hw state "
-
 
7900
		     "(expected %i, found %i)\n", crtc->active, active);
-
 
7901
 
-
 
7902
		WARN(active &&
-
 
7903
		     !intel_pipe_config_compare(&crtc->config, &pipe_config),
7763
		assert_pipe(dev->dev_private, crtc->pipe, crtc->active);
7904
		     "pipe state doesn't match!\n");
7764
	}
7905
	}
Line 7765... Line 7906...
7765
}
7906
}
7766
 
7907
 
7767
int intel_set_mode(struct drm_crtc *crtc,
7908
static int __intel_set_mode(struct drm_crtc *crtc,
7768
		    struct drm_display_mode *mode,
7909
		    struct drm_display_mode *mode,
7769
		    int x, int y, struct drm_framebuffer *fb)
7910
		    int x, int y, struct drm_framebuffer *fb)
7770
{
7911
{
7771
	struct drm_device *dev = crtc->dev;
7912
	struct drm_device *dev = crtc->dev;
-
 
7913
	drm_i915_private_t *dev_priv = dev->dev_private;
7772
	drm_i915_private_t *dev_priv = dev->dev_private;
7914
	struct drm_display_mode *saved_mode, *saved_hwmode;
7773
	struct drm_display_mode *adjusted_mode, *saved_mode, *saved_hwmode;
7915
	struct intel_crtc_config *pipe_config = NULL;
7774
	struct intel_crtc *intel_crtc;
7916
	struct intel_crtc *intel_crtc;
Line 7775... Line 7917...
7775
	unsigned disable_pipes, prepare_pipes, modeset_pipes;
7917
	unsigned disable_pipes, prepare_pipes, modeset_pipes;
Line 7781... Line 7923...
7781
	saved_hwmode = saved_mode + 1;
7923
	saved_hwmode = saved_mode + 1;
Line 7782... Line 7924...
7782
 
7924
 
7783
	intel_modeset_affected_pipes(crtc, &modeset_pipes,
7925
	intel_modeset_affected_pipes(crtc, &modeset_pipes,
Line 7784... Line -...
7784
				     &prepare_pipes, &disable_pipes);
-
 
7785
 
-
 
7786
	DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
-
 
7787
		      modeset_pipes, prepare_pipes, disable_pipes);
-
 
7788
 
-
 
7789
	for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
-
 
7790
		intel_crtc_disable(&intel_crtc->base);
7926
				     &prepare_pipes, &disable_pipes);
7791
 
7927
 
Line 7792... Line 7928...
7792
	*saved_hwmode = crtc->hwmode;
7928
	*saved_hwmode = crtc->hwmode;
7793
	*saved_mode = crtc->mode;
7929
	*saved_mode = crtc->mode;
7794
 
7930
 
7795
	/* Hack: Because we don't (yet) support global modeset on multiple
7931
	/* Hack: Because we don't (yet) support global modeset on multiple
7796
	 * crtcs, we don't keep track of the new mode for more than one crtc.
7932
	 * crtcs, we don't keep track of the new mode for more than one crtc.
7797
	 * Hence simply check whether any bit is set in modeset_pipes in all the
-
 
7798
	 * pieces of code that are not yet converted to deal with mutliple crtcs
7933
	 * Hence simply check whether any bit is set in modeset_pipes in all the
7799
	 * changing their mode at the same time. */
7934
	 * pieces of code that are not yet converted to deal with mutliple crtcs
7800
	adjusted_mode = NULL;
7935
	 * changing their mode at the same time. */
7801
	if (modeset_pipes) {
7936
	if (modeset_pipes) {
-
 
7937
		pipe_config = intel_modeset_pipe_config(crtc, fb, mode);
-
 
7938
		if (IS_ERR(pipe_config)) {
7802
		adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
7939
			ret = PTR_ERR(pipe_config);
7803
		if (IS_ERR(adjusted_mode)) {
7940
			pipe_config = NULL;
7804
			ret = PTR_ERR(adjusted_mode);
7941
 
Line -... Line 7942...
-
 
7942
			goto out;
-
 
7943
		}
-
 
7944
	}
-
 
7945
 
-
 
7946
	DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
-
 
7947
		      modeset_pipes, prepare_pipes, disable_pipes);
7805
			goto out;
7948
 
7806
		}
7949
	for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
7807
	}
7950
		intel_crtc_disable(&intel_crtc->base);
7808
 
7951
 
Line 7809... Line 7952...
7809
	for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
7952
	for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
7810
		if (intel_crtc->base.enabled)
7953
		if (intel_crtc->base.enabled)
7811
			dev_priv->display.crtc_disable(&intel_crtc->base);
7954
			dev_priv->display.crtc_disable(&intel_crtc->base);
7812
	}
7955
	}
-
 
7956
 
7813
 
7957
	/* crtc->mode is already used by the ->mode_set callbacks, hence we need
-
 
7958
	 * to set it here already despite that we pass it down the callchain.
-
 
7959
	 */
-
 
7960
	if (modeset_pipes) {
-
 
7961
		enum transcoder tmp = to_intel_crtc(crtc)->config.cpu_transcoder;
-
 
7962
		crtc->mode = *mode;
Line 7814... Line 7963...
7814
	/* crtc->mode is already used by the ->mode_set callbacks, hence we need
7963
		/* mode_set/enable/disable functions rely on a correct pipe
7815
	 * to set it here already despite that we pass it down the callchain.
7964
		 * config. */
7816
	 */
7965
		to_intel_crtc(crtc)->config = *pipe_config;
Line 7827... Line 7976...
7827
	/* Set up the DPLL and any encoders state that needs to adjust or depend
7976
	/* Set up the DPLL and any encoders state that needs to adjust or depend
7828
	 * on the DPLL.
7977
	 * on the DPLL.
7829
	 */
7978
	 */
7830
	for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
7979
	for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
7831
		ret = intel_crtc_mode_set(&intel_crtc->base,
7980
		ret = intel_crtc_mode_set(&intel_crtc->base,
7832
					   mode, adjusted_mode,
-
 
7833
					   x, y, fb);
7981
					   x, y, fb);
7834
		if (ret)
7982
		if (ret)
7835
		    goto done;
7983
		    goto done;
7836
	}
7984
	}
Line 7839... Line 7987...
7839
	for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc)
7987
	for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc)
7840
		dev_priv->display.crtc_enable(&intel_crtc->base);
7988
		dev_priv->display.crtc_enable(&intel_crtc->base);
Line 7841... Line 7989...
7841
 
7989
 
7842
	if (modeset_pipes) {
7990
	if (modeset_pipes) {
7843
		/* Store real post-adjustment hardware mode. */
7991
		/* Store real post-adjustment hardware mode. */
Line 7844... Line 7992...
7844
		crtc->hwmode = *adjusted_mode;
7992
		crtc->hwmode = pipe_config->adjusted_mode;
7845
 
7993
 
7846
		/* Calculate and store various constants which
7994
		/* Calculate and store various constants which
7847
		 * are later needed by vblank and swap-completion
7995
		 * are later needed by vblank and swap-completion
7848
		 * timestamping. They are derived from true hwmode.
7996
		 * timestamping. They are derived from true hwmode.
7849
		 */
7997
		 */
Line 7850... Line 7998...
7850
		drm_calc_timestamping_constants(crtc);
7998
		drm_calc_timestamping_constants(crtc);
7851
	}
7999
	}
7852
 
-
 
7853
	/* FIXME: add subpixel order */
8000
 
7854
done:
8001
	/* FIXME: add subpixel order */
7855
	drm_mode_destroy(dev, adjusted_mode);
8002
done:
7856
	if (ret && crtc->enabled) {
-
 
7857
		crtc->hwmode = *saved_hwmode;
-
 
7858
		crtc->mode = *saved_mode;
8003
	if (ret && crtc->enabled) {
Line 7859... Line 8004...
7859
	} else {
8004
		crtc->hwmode = *saved_hwmode;
-
 
8005
		crtc->mode = *saved_mode;
7860
		intel_modeset_check_state(dev);
8006
	}
7861
	}
8007
 
7862
 
8008
out:
Line -... Line 8009...
-
 
8009
	kfree(pipe_config);
-
 
8010
	kfree(saved_mode);
-
 
8011
	return ret;
-
 
8012
}
-
 
8013
 
-
 
8014
int intel_set_mode(struct drm_crtc *crtc,
-
 
8015
		     struct drm_display_mode *mode,
-
 
8016
		     int x, int y, struct drm_framebuffer *fb)
-
 
8017
{
-
 
8018
	int ret;
-
 
8019
 
-
 
8020
	ret = __intel_set_mode(crtc, mode, x, y, fb);
-
 
8021
 
-
 
8022
	if (ret == 0)
7863
out:
8023
		intel_modeset_check_state(crtc->dev);
7864
	kfree(saved_mode);
8024
 
7865
	return ret;
8025
	return ret;
7866
}
8026
}
Line 7936... Line 8096...
7936
		connector->new_encoder =
8096
		connector->new_encoder =
7937
			to_intel_encoder(config->save_connector_encoders[count++]);
8097
			to_intel_encoder(config->save_connector_encoders[count++]);
7938
	}
8098
	}
7939
}
8099
}
Line -... Line 8100...
-
 
8100
 
-
 
8101
static bool
-
 
8102
is_crtc_connector_off(struct drm_crtc *crtc, struct drm_connector *connectors,
-
 
8103
		      int num_connectors)
-
 
8104
{
-
 
8105
	int i;
-
 
8106
 
-
 
8107
	for (i = 0; i < num_connectors; i++)
-
 
8108
		if (connectors[i].encoder &&
-
 
8109
		    connectors[i].encoder->crtc == crtc &&
-
 
8110
		    connectors[i].dpms != DRM_MODE_DPMS_ON)
-
 
8111
			return true;
-
 
8112
 
-
 
8113
	return false;
-
 
8114
}
7940
 
8115
 
7941
static void
8116
static void
7942
intel_set_config_compute_mode_changes(struct drm_mode_set *set,
8117
intel_set_config_compute_mode_changes(struct drm_mode_set *set,
7943
				      struct intel_set_config *config)
8118
				      struct intel_set_config *config)
Line 7944... Line 8119...
7944
{
8119
{
7945
 
8120
 
-
 
8121
	/* We should be able to check here if the fb has the same properties
-
 
8122
	 * and then just flip_or_move it */
-
 
8123
	if (set->connectors != NULL &&
-
 
8124
	    is_crtc_connector_off(set->crtc, *set->connectors,
7946
	/* We should be able to check here if the fb has the same properties
8125
				  set->num_connectors)) {
7947
	 * and then just flip_or_move it */
8126
			config->mode_changed = true;
7948
	if (set->crtc->fb != set->fb) {
8127
	} else if (set->crtc->fb != set->fb) {
7949
		/* If we have no fb then treat it as a full mode set */
8128
		/* If we have no fb then treat it as a full mode set */
7950
		if (set->crtc->fb == NULL) {
8129
		if (set->crtc->fb == NULL) {
7951
			DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
8130
			DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
7952
			config->mode_changed = true;
8131
			config->mode_changed = true;
7953
		} else if (set->fb == NULL) {
-
 
7954
			config->mode_changed = true;
-
 
7955
		} else if (set->fb->depth != set->crtc->fb->depth) {
8132
		} else if (set->fb == NULL) {
7956
			config->mode_changed = true;
8133
			config->mode_changed = true;
7957
		} else if (set->fb->bits_per_pixel !=
8134
		} else if (set->fb->pixel_format !=
7958
			   set->crtc->fb->bits_per_pixel) {
8135
			   set->crtc->fb->pixel_format) {
7959
			config->mode_changed = true;
8136
			config->mode_changed = true;
7960
		} else
8137
		} else {
-
 
8138
			config->fb_changed = true;
Line 7961... Line 8139...
7961
			config->fb_changed = true;
8139
	}
7962
	}
8140
	}
Line 7963... Line 8141...
7963
 
8141
 
Line 8130... Line 8308...
8130
			drm_mode_debug_printmodeline(set->mode);
8308
			drm_mode_debug_printmodeline(set->mode);
8131
		}
8309
		}
Line 8132... Line 8310...
8132
 
8310
 
8133
		ret = intel_set_mode(set->crtc, set->mode,
8311
		ret = intel_set_mode(set->crtc, set->mode,
8134
				     set->x, set->y, set->fb);
-
 
8135
		if (ret) {
-
 
8136
			DRM_ERROR("failed to set mode on [CRTC:%d], err = %d\n",
-
 
8137
				  set->crtc->base.id, ret);
-
 
8138
			goto fail;
-
 
8139
		}
8312
				     set->x, set->y, set->fb);
-
 
8313
	} else if (config->fb_changed) {
-
 
8314
//       intel_crtc_wait_for_pending_flips(set->crtc);
8140
	} else if (config->fb_changed) {
8315
 
8141
		ret = intel_pipe_set_base(set->crtc,
8316
		ret = intel_pipe_set_base(set->crtc,
8142
					  set->x, set->y, set->fb);
8317
					  set->x, set->y, set->fb);
Line -... Line 8318...
-
 
8318
	}
8143
	}
8319
 
8144
 
-
 
8145
	intel_set_config_free(config);
8320
	if (ret) {
8146
 
-
 
8147
	return 0;
8321
		DRM_ERROR("failed to set mode on [CRTC:%d], err = %d\n",
8148
 
8322
			  set->crtc->base.id, ret);
Line 8149... Line 8323...
8149
fail:
8323
fail:
8150
	intel_set_config_restore_state(dev, config);
8324
	intel_set_config_restore_state(dev, config);
8151
 
8325
 
8152
	/* Try to restore the config */
8326
	/* Try to restore the config */
8153
	if (config->mode_changed &&
8327
	if (config->mode_changed &&
-
 
8328
	    intel_set_mode(save_set.crtc, save_set.mode,
Line 8154... Line 8329...
8154
	    intel_set_mode(save_set.crtc, save_set.mode,
8329
			    save_set.x, save_set.y, save_set.fb))
8155
			    save_set.x, save_set.y, save_set.fb))
8330
		DRM_ERROR("failed to restore config after modeset failure\n");
8156
		DRM_ERROR("failed to restore config after modeset failure\n");
8331
	}
8157
 
8332
 
Line 8212... Line 8387...
8212
	}
8387
	}
Line 8213... Line 8388...
8213
 
8388
 
8214
	/* Swap pipes & planes for FBC on pre-965 */
8389
	/* Swap pipes & planes for FBC on pre-965 */
8215
	intel_crtc->pipe = pipe;
8390
	intel_crtc->pipe = pipe;
8216
	intel_crtc->plane = pipe;
8391
	intel_crtc->plane = pipe;
8217
	intel_crtc->cpu_transcoder = pipe;
8392
	intel_crtc->config.cpu_transcoder = pipe;
8218
	if (IS_MOBILE(dev) && IS_GEN3(dev)) {
8393
	if (IS_MOBILE(dev) && IS_GEN3(dev)) {
8219
		DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
8394
		DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
8220
		intel_crtc->plane = !pipe;
8395
		intel_crtc->plane = !pipe;
Line 8221... Line 8396...
8221
	}
8396
	}
8222
 
8397
 
8223
	BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
8398
	BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
8224
	       dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
8399
	       dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
Line 8225... Line -...
8225
	dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
-
 
8226
	dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
-
 
8227
 
8400
	dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
8228
	intel_crtc->bpp = 24; /* default for pre-Ironlake */
8401
	dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
Line 8229... Line 8402...
8229
 
8402
 
8230
	drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
8403
	drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
Line 8305... Line 8478...
8305
	if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
8478
	if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
8306
		/* disable the panel fitter on everything but LVDS */
8479
		/* disable the panel fitter on everything but LVDS */
8307
		I915_WRITE(PFIT_CONTROL, 0);
8480
		I915_WRITE(PFIT_CONTROL, 0);
8308
	}
8481
	}
Line 8309... Line 8482...
8309
 
8482
 
8310
	if (!(HAS_DDI(dev) && (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)))
8483
	if (!IS_ULT(dev))
Line 8311... Line 8484...
8311
	intel_crt_init(dev);
8484
	intel_crt_init(dev);
8312
 
8485
 
Line 8334... Line 8507...
8334
		dpd_is_edp = intel_dpd_is_edp(dev);
8507
		dpd_is_edp = intel_dpd_is_edp(dev);
Line 8335... Line 8508...
8335
 
8508
 
8336
		if (has_edp_a(dev))
8509
		if (has_edp_a(dev))
Line 8337... Line 8510...
8337
			intel_dp_init(dev, DP_A, PORT_A);
8510
			intel_dp_init(dev, DP_A, PORT_A);
8338
 
8511
 
8339
		if (I915_READ(HDMIB) & PORT_DETECTED) {
8512
		if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
8340
			/* PCH SDVOB multiplex with HDMIB */
8513
			/* PCH SDVOB multiplex with HDMIB */
8341
			found = intel_sdvo_init(dev, PCH_SDVOB, true);
8514
			found = intel_sdvo_init(dev, PCH_SDVOB, true);
8342
			if (!found)
8515
			if (!found)
8343
				intel_hdmi_init(dev, HDMIB, PORT_B);
8516
				intel_hdmi_init(dev, PCH_HDMIB, PORT_B);
8344
			if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
8517
			if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
Line 8345... Line 8518...
8345
				intel_dp_init(dev, PCH_DP_B, PORT_B);
8518
				intel_dp_init(dev, PCH_DP_B, PORT_B);
8346
		}
8519
		}
Line 8347... Line 8520...
8347
 
8520
 
8348
		if (I915_READ(HDMIC) & PORT_DETECTED)
8521
		if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
Line 8349... Line 8522...
8349
			intel_hdmi_init(dev, HDMIC, PORT_C);
8522
			intel_hdmi_init(dev, PCH_HDMIC, PORT_C);
8350
 
8523
 
Line 8351... Line 8524...
8351
		if (!dpd_is_edp && I915_READ(HDMID) & PORT_DETECTED)
8524
		if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
Line 8359... Line 8532...
8359
	} else if (IS_VALLEYVIEW(dev)) {
8532
	} else if (IS_VALLEYVIEW(dev)) {
8360
		/* Check for built-in panel first. Shares lanes with HDMI on SDVOC */
8533
		/* Check for built-in panel first. Shares lanes with HDMI on SDVOC */
8361
		if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
8534
		if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
8362
			intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
8535
			intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
Line 8363... Line 8536...
8363
 
8536
 
8364
		if (I915_READ(VLV_DISPLAY_BASE + SDVOB) & PORT_DETECTED) {
8537
		if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED) {
-
 
8538
			intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
8365
			intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOB, PORT_B);
8539
					PORT_B);
8366
			if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
8540
			if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
8367
				intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
8541
				intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
8368
		}
-
 
8369
 
-
 
8370
		if (I915_READ(VLV_DISPLAY_BASE + SDVOC) & PORT_DETECTED)
-
 
8371
			intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOC, PORT_C);
-
 
8372
 
8542
		}
8373
	} else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
8543
	} else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
Line 8374... Line 8544...
8374
		bool found = false;
8544
		bool found = false;
8375
 
8545
 
8376
		if (I915_READ(SDVOB) & SDVO_DETECTED) {
8546
		if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
8377
			DRM_DEBUG_KMS("probing SDVOB\n");
8547
			DRM_DEBUG_KMS("probing SDVOB\n");
8378
			found = intel_sdvo_init(dev, SDVOB, true);
8548
			found = intel_sdvo_init(dev, GEN3_SDVOB, true);
8379
			if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
8549
			if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
8380
				DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
8550
				DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
Line 8381... Line 8551...
8381
				intel_hdmi_init(dev, SDVOB, PORT_B);
8551
				intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
8382
			}
8552
			}
8383
 
8553
 
8384
			if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
8554
			if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
8385
				DRM_DEBUG_KMS("probing DP_B\n");
8555
				DRM_DEBUG_KMS("probing DP_B\n");
Line 8386... Line 8556...
8386
				intel_dp_init(dev, DP_B, PORT_B);
8556
				intel_dp_init(dev, DP_B, PORT_B);
Line 8387... Line 8557...
8387
			}
8557
			}
8388
		}
8558
		}
8389
 
8559
 
8390
		/* Before G4X SDVOC doesn't have its own detect register */
8560
		/* Before G4X SDVOC doesn't have its own detect register */
Line 8391... Line 8561...
8391
 
8561
 
Line 8392... Line 8562...
8392
		if (I915_READ(SDVOB) & SDVO_DETECTED) {
8562
		if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
8393
			DRM_DEBUG_KMS("probing SDVOC\n");
8563
			DRM_DEBUG_KMS("probing SDVOC\n");
8394
			found = intel_sdvo_init(dev, SDVOC, false);
8564
			found = intel_sdvo_init(dev, GEN3_SDVOC, false);
8395
		}
8565
		}
8396
 
8566
 
8397
		if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
8567
		if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
8398
 
8568
 
8399
			if (SUPPORTS_INTEGRATED_HDMI(dev)) {
8569
			if (SUPPORTS_INTEGRATED_HDMI(dev)) {
Line 8531... Line 8701...
8531
/* Set up chip specific display functions */
8701
/* Set up chip specific display functions */
8532
static void intel_init_display(struct drm_device *dev)
8702
static void intel_init_display(struct drm_device *dev)
8533
{
8703
{
8534
	struct drm_i915_private *dev_priv = dev->dev_private;
8704
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 8535... Line -...
8535
 
-
 
8536
	/* We always want a DPMS function */
8705
 
-
 
8706
	if (HAS_DDI(dev)) {
8537
	if (HAS_DDI(dev)) {
8707
		dev_priv->display.get_pipe_config = haswell_get_pipe_config;
8538
		dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
8708
		dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
8539
		dev_priv->display.crtc_enable = haswell_crtc_enable;
8709
		dev_priv->display.crtc_enable = haswell_crtc_enable;
8540
		dev_priv->display.crtc_disable = haswell_crtc_disable;
8710
		dev_priv->display.crtc_disable = haswell_crtc_disable;
8541
		dev_priv->display.off = haswell_crtc_off;
8711
		dev_priv->display.off = haswell_crtc_off;
8542
		dev_priv->display.update_plane = ironlake_update_plane;
8712
		dev_priv->display.update_plane = ironlake_update_plane;
-
 
8713
	} else if (HAS_PCH_SPLIT(dev)) {
8543
	} else if (HAS_PCH_SPLIT(dev)) {
8714
		dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
8544
		dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
8715
		dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
8545
		dev_priv->display.crtc_enable = ironlake_crtc_enable;
8716
		dev_priv->display.crtc_enable = ironlake_crtc_enable;
8546
		dev_priv->display.crtc_disable = ironlake_crtc_disable;
8717
		dev_priv->display.crtc_disable = ironlake_crtc_disable;
8547
		dev_priv->display.off = ironlake_crtc_off;
8718
		dev_priv->display.off = ironlake_crtc_off;
8548
		dev_priv->display.update_plane = ironlake_update_plane;
8719
		dev_priv->display.update_plane = ironlake_update_plane;
-
 
8720
	} else {
8549
	} else {
8721
		dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
8550
		dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
8722
		dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
8551
		dev_priv->display.crtc_enable = i9xx_crtc_enable;
8723
		dev_priv->display.crtc_enable = i9xx_crtc_enable;
8552
		dev_priv->display.crtc_disable = i9xx_crtc_disable;
8724
		dev_priv->display.crtc_disable = i9xx_crtc_disable;
8553
		dev_priv->display.off = i9xx_crtc_off;
8725
		dev_priv->display.off = i9xx_crtc_off;
Line 8769... Line 8941...
8769
}
8941
}
Line 8770... Line 8942...
8770
 
8942
 
8771
void intel_modeset_init(struct drm_device *dev)
8943
void intel_modeset_init(struct drm_device *dev)
8772
{
8944
{
8773
	struct drm_i915_private *dev_priv = dev->dev_private;
8945
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 8774... Line 8946...
8774
	int i, ret;
8946
	int i, j, ret;
Line 8775... Line 8947...
8775
 
8947
 
8776
	drm_mode_config_init(dev);
8948
	drm_mode_config_init(dev);
Line 8785... Line 8957...
8785
 
8957
 
Line 8786... Line 8958...
8786
	intel_init_quirks(dev);
8958
	intel_init_quirks(dev);
Line -... Line 8959...
-
 
8959
 
-
 
8960
	intel_init_pm(dev);
-
 
8961
 
8787
 
8962
	if (INTEL_INFO(dev)->num_pipes == 0)
Line 8788... Line 8963...
8788
	intel_init_pm(dev);
8963
		return;
8789
 
8964
 
8790
	intel_init_display(dev);
8965
	intel_init_display(dev);
Line 8800... Line 8975...
8800
		dev->mode_config.max_height = 8192;
8975
		dev->mode_config.max_height = 8192;
8801
	}
8976
	}
8802
	dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
8977
	dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
Line 8803... Line 8978...
8803
 
8978
 
-
 
8979
	DRM_DEBUG_KMS("%d display pipe%s available.\n",
8804
	DRM_DEBUG_KMS("%d display pipe%s available.\n",
8980
		      INTEL_INFO(dev)->num_pipes,
Line 8805... Line 8981...
8805
		      dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : "");
8981
		      INTEL_INFO(dev)->num_pipes > 1 ? "s" : "");
8806
 
8982
 
-
 
8983
	for (i = 0; i < INTEL_INFO(dev)->num_pipes; i++) {
8807
	for (i = 0; i < dev_priv->num_pipe; i++) {
8984
		intel_crtc_init(dev, i);
8808
		intel_crtc_init(dev, i);
8985
		for (j = 0; j < dev_priv->num_plane; j++) {
8809
		ret = intel_plane_init(dev, i);
8986
			ret = intel_plane_init(dev, i, j);
-
 
8987
		if (ret)
-
 
8988
				DRM_DEBUG_KMS("pipe %d plane %d init failed: %d\n",
8810
		if (ret)
8989
					      i, j, ret);
Line 8811... Line 8990...
8811
			DRM_DEBUG_KMS("plane %d init failed: %d\n", i, ret);
8990
		}
8812
	}
8991
	}
Line 8859... Line 9038...
8859
}
9038
}
Line 8860... Line 9039...
8860
 
9039
 
8861
static bool
9040
static bool
8862
intel_check_plane_mapping(struct intel_crtc *crtc)
9041
intel_check_plane_mapping(struct intel_crtc *crtc)
-
 
9042
{
8863
{
9043
	struct drm_device *dev = crtc->base.dev;
8864
	struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
9044
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 8865... Line 9045...
8865
	u32 reg, val;
9045
	u32 reg, val;
8866
 
9046
 
Line 8867... Line 9047...
8867
	if (dev_priv->num_pipe == 1)
9047
	if (INTEL_INFO(dev)->num_pipes == 1)
8868
		return true;
9048
		return true;
Line 8882... Line 9062...
8882
	struct drm_device *dev = crtc->base.dev;
9062
	struct drm_device *dev = crtc->base.dev;
8883
	struct drm_i915_private *dev_priv = dev->dev_private;
9063
	struct drm_i915_private *dev_priv = dev->dev_private;
8884
	u32 reg;
9064
	u32 reg;
Line 8885... Line 9065...
8885
 
9065
 
8886
	/* Clear any frame start delays used for debugging left by the BIOS */
9066
	/* Clear any frame start delays used for debugging left by the BIOS */
8887
	reg = PIPECONF(crtc->cpu_transcoder);
9067
	reg = PIPECONF(crtc->config.cpu_transcoder);
Line 8888... Line 9068...
8888
	I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
9068
	I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
8889
 
9069
 
8890
	/* We need to sanitize the plane -> pipe mapping first because this will
9070
	/* We need to sanitize the plane -> pipe mapping first because this will
Line 8999... Line 9179...
8999
	}
9179
	}
9000
	/* Enabled encoders without active connectors will be fixed in
9180
	/* Enabled encoders without active connectors will be fixed in
9001
	 * the crtc fixup. */
9181
	 * the crtc fixup. */
9002
}
9182
}
Line -... Line 9183...
-
 
9183
 
-
 
9184
void i915_redisable_vga(struct drm_device *dev)
-
 
9185
{
-
 
9186
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
9187
	u32 vga_reg = i915_vgacntrl_reg(dev);
-
 
9188
 
-
 
9189
	if (I915_READ(vga_reg) != VGA_DISP_DISABLE) {
-
 
9190
		DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
-
 
9191
		i915_disable_vga(dev);
-
 
9192
	}
-
 
9193
}
9003
 
9194
 
9004
/* Scan out the current hw modeset state, sanitizes it and maps it into the drm
9195
/* Scan out the current hw modeset state, sanitizes it and maps it into the drm
9005
 * and i915 state tracking structures. */
9196
 * and i915 state tracking structures. */
9006
void intel_modeset_setup_hw_state(struct drm_device *dev,
9197
void intel_modeset_setup_hw_state(struct drm_device *dev,
9007
				  bool force_restore)
9198
				  bool force_restore)
9008
{
9199
{
9009
	struct drm_i915_private *dev_priv = dev->dev_private;
9200
	struct drm_i915_private *dev_priv = dev->dev_private;
9010
	enum pipe pipe;
9201
	enum pipe pipe;
-
 
9202
	u32 tmp;
9011
	u32 tmp;
9203
	struct drm_plane *plane;
9012
	struct intel_crtc *crtc;
9204
	struct intel_crtc *crtc;
9013
	struct intel_encoder *encoder;
9205
	struct intel_encoder *encoder;
Line 9014... Line 9206...
9014
	struct intel_connector *connector;
9206
	struct intel_connector *connector;
Line 9026... Line 9218...
9026
				pipe = PIPE_B;
9218
				pipe = PIPE_B;
9027
				break;
9219
				break;
9028
			case TRANS_DDI_EDP_INPUT_C_ONOFF:
9220
			case TRANS_DDI_EDP_INPUT_C_ONOFF:
9029
				pipe = PIPE_C;
9221
				pipe = PIPE_C;
9030
				break;
9222
				break;
-
 
9223
			default:
-
 
9224
				/* A bogus value has been programmed, disable
-
 
9225
				 * the transcoder */
-
 
9226
				WARN(1, "Bogus eDP source %08x\n", tmp);
-
 
9227
				intel_ddi_disable_transcoder_func(dev_priv,
-
 
9228
						TRANSCODER_EDP);
-
 
9229
				goto setup_pipes;
9031
			}
9230
			}
Line 9032... Line 9231...
9032
 
9231
 
9033
			crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
9232
			crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Line 9034... Line 9233...
9034
			crtc->cpu_transcoder = TRANSCODER_EDP;
9233
			crtc->config.cpu_transcoder = TRANSCODER_EDP;
9035
 
9234
 
9036
			DRM_DEBUG_KMS("Pipe %c using transcoder EDP\n",
9235
			DRM_DEBUG_KMS("Pipe %c using transcoder EDP\n",
9037
				      pipe_name(pipe));
9236
				      pipe_name(pipe));
Line -... Line 9237...
-
 
9237
		}
-
 
9238
	}
9038
		}
9239
 
-
 
9240
setup_pipes:
9039
	}
9241
	list_for_each_entry(crtc, &dev->mode_config.crtc_list,
-
 
9242
			    base.head) {
Line 9040... Line 9243...
9040
 
9243
		enum transcoder tmp = crtc->config.cpu_transcoder;
9041
	for_each_pipe(pipe) {
-
 
9042
		crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
-
 
9043
 
-
 
9044
		tmp = I915_READ(PIPECONF(crtc->cpu_transcoder));
9244
		memset(&crtc->config, 0, sizeof(crtc->config));
Line 9045... Line 9245...
9045
		if (tmp & PIPECONF_ENABLE)
9245
		crtc->config.cpu_transcoder = tmp;
Line 9046... Line 9246...
9046
			crtc->active = true;
9246
 
9047
		else
9247
		crtc->active = dev_priv->display.get_pipe_config(crtc,
Line 9102... Line 9302...
9102
		crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
9302
		crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
9103
		intel_sanitize_crtc(crtc);
9303
		intel_sanitize_crtc(crtc);
9104
	}
9304
	}
Line 9105... Line 9305...
9105
 
9305
 
-
 
9306
	if (force_restore) {
-
 
9307
		/*
-
 
9308
		 * We need to use raw interfaces for restoring state to avoid
-
 
9309
		 * checking (bogus) intermediate states.
9106
	if (force_restore) {
9310
		 */
-
 
9311
		for_each_pipe(pipe) {
9107
		for_each_pipe(pipe) {
9312
			struct drm_crtc *crtc =
-
 
9313
				dev_priv->pipe_to_crtc_mapping[pipe];
-
 
9314
 
-
 
9315
			__intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y,
9108
			intel_crtc_restore_mode(dev_priv->pipe_to_crtc_mapping[pipe]);
9316
					 crtc->fb);
-
 
9317
		}
-
 
9318
		list_for_each_entry(plane, &dev->mode_config.plane_list, head)
Line 9109... Line 9319...
9109
		}
9319
			intel_plane_restore(plane);
9110
 
9320
 
9111
//       i915_redisable_vga(dev);
9321
		i915_redisable_vga(dev);
9112
	} else {
9322
	} else {
Line 9113... Line 9323...
9113
	intel_modeset_update_staged_output_state(dev);
9323
	intel_modeset_update_staged_output_state(dev);
Line 9253... Line 9463...
9253
		return NULL;
9463
		return NULL;
Line 9254... Line 9464...
9254
 
9464
 
9255
	for_each_pipe(i) {
9465
	for_each_pipe(i) {
Line -... Line 9466...
-
 
9466
		cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, i);
9256
		cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, i);
9467
 
9257
 
9468
		if (INTEL_INFO(dev)->gen <= 6 || IS_VALLEYVIEW(dev)) {
9258
		error->cursor[i].control = I915_READ(CURCNTR(i));
9469
		error->cursor[i].control = I915_READ(CURCNTR(i));
-
 
9470
		error->cursor[i].position = I915_READ(CURPOS(i));
-
 
9471
		error->cursor[i].base = I915_READ(CURBASE(i));
-
 
9472
		} else {
-
 
9473
			error->cursor[i].control = I915_READ(CURCNTR_IVB(i));
-
 
9474
			error->cursor[i].position = I915_READ(CURPOS_IVB(i));
Line 9259... Line 9475...
9259
		error->cursor[i].position = I915_READ(CURPOS(i));
9475
			error->cursor[i].base = I915_READ(CURBASE_IVB(i));
9260
		error->cursor[i].base = I915_READ(CURBASE(i));
9476
		}
-
 
9477
 
9261
 
9478
		error->plane[i].control = I915_READ(DSPCNTR(i));
9262
		error->plane[i].control = I915_READ(DSPCNTR(i));
9479
		error->plane[i].stride = I915_READ(DSPSTRIDE(i));
-
 
9480
		if (INTEL_INFO(dev)->gen <= 3) {
-
 
9481
		error->plane[i].size = I915_READ(DSPSIZE(i));
9263
		error->plane[i].stride = I915_READ(DSPSTRIDE(i));
9482
		error->plane[i].pos = I915_READ(DSPPOS(i));
9264
		error->plane[i].size = I915_READ(DSPSIZE(i));
9483
		}
9265
		error->plane[i].pos = I915_READ(DSPPOS(i));
9484
		if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
9266
		error->plane[i].addr = I915_READ(DSPADDR(i));
9485
		error->plane[i].addr = I915_READ(DSPADDR(i));
9267
		if (INTEL_INFO(dev)->gen >= 4) {
9486
		if (INTEL_INFO(dev)->gen >= 4) {
Line 9285... Line 9504...
9285
void
9504
void
9286
intel_display_print_error_state(struct seq_file *m,
9505
intel_display_print_error_state(struct seq_file *m,
9287
				struct drm_device *dev,
9506
				struct drm_device *dev,
9288
				struct intel_display_error_state *error)
9507
				struct intel_display_error_state *error)
9289
{
9508
{
9290
	drm_i915_private_t *dev_priv = dev->dev_private;
-
 
9291
	int i;
9509
	int i;
Line 9292... Line 9510...
9292
 
9510
 
9293
	seq_printf(m, "Num Pipes: %d\n", dev_priv->num_pipe);
9511
	seq_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes);
9294
	for_each_pipe(i) {
9512
	for_each_pipe(i) {
9295
		seq_printf(m, "Pipe [%d]:\n", i);
9513
		seq_printf(m, "Pipe [%d]:\n", i);
9296
		seq_printf(m, "  CONF: %08x\n", error->pipe[i].conf);
9514
		seq_printf(m, "  CONF: %08x\n", error->pipe[i].conf);
9297
		seq_printf(m, "  SRC: %08x\n", error->pipe[i].source);
9515
		seq_printf(m, "  SRC: %08x\n", error->pipe[i].source);
Line 9303... Line 9521...
9303
		seq_printf(m, "  VSYNC: %08x\n", error->pipe[i].vsync);
9521
		seq_printf(m, "  VSYNC: %08x\n", error->pipe[i].vsync);
Line 9304... Line 9522...
9304
 
9522
 
9305
		seq_printf(m, "Plane [%d]:\n", i);
9523
		seq_printf(m, "Plane [%d]:\n", i);
9306
		seq_printf(m, "  CNTR: %08x\n", error->plane[i].control);
9524
		seq_printf(m, "  CNTR: %08x\n", error->plane[i].control);
-
 
9525
		seq_printf(m, "  STRIDE: %08x\n", error->plane[i].stride);
9307
		seq_printf(m, "  STRIDE: %08x\n", error->plane[i].stride);
9526
		if (INTEL_INFO(dev)->gen <= 3) {
9308
		seq_printf(m, "  SIZE: %08x\n", error->plane[i].size);
9527
		seq_printf(m, "  SIZE: %08x\n", error->plane[i].size);
-
 
9528
		seq_printf(m, "  POS: %08x\n", error->plane[i].pos);
-
 
9529
		}
9309
		seq_printf(m, "  POS: %08x\n", error->plane[i].pos);
9530
		if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
9310
		seq_printf(m, "  ADDR: %08x\n", error->plane[i].addr);
9531
		seq_printf(m, "  ADDR: %08x\n", error->plane[i].addr);
9311
		if (INTEL_INFO(dev)->gen >= 4) {
9532
		if (INTEL_INFO(dev)->gen >= 4) {
9312
			seq_printf(m, "  SURF: %08x\n", error->plane[i].surface);
9533
			seq_printf(m, "  SURF: %08x\n", error->plane[i].surface);
9313
			seq_printf(m, "  TILEOFF: %08x\n", error->plane[i].tile_offset);
9534
			seq_printf(m, "  TILEOFF: %08x\n", error->plane[i].tile_offset);