aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Airlie <airlied@gmail.com>2012-09-19 06:00:10 -0400
committerDave Airlie <airlied@gmail.com>2012-09-19 06:00:10 -0400
commit7facf16690dc4160e5ff605271704183ff56b2d9 (patch)
tree77b19e5a0cbc32e2b03cf429a753402e1f1b566f
parent87229ad9de079cb12ee09a3dc16113c390b729d5 (diff)
parent3b7a89fce3e3dc96b549d6d829387b4439044d0d (diff)
Merge branch 'for-airlied' of git://people.freedesktop.org/~danvet/drm-intel into drm-next
Daniel writes: "The big ticket item here is the new i915 modeset infrastructure. Shockingly it didn't not blow up all over the place (i.e. I've managed to fix the ugly issues before merging). 1-2 smaller corner cases broke, but we have patches. Also, there's tons of patches on top of this that clean out cruft and fix a few bugs that couldn't be fixed with the crtc helper based stuff. So more stuff to come ;-) Also a few other things: - Tiny fix in the fb helper to go through the official dpms interface instead of calling the crtc helper code. - forcewake code frobbery from Ben, code should be more in-line with what Windows does now. - fixes for the render ring flush on hsw (Paulo) - gpu frequency tracepoint - vlv forcewake changes to better align it with our understanding of the forcewake magic. - a few smaller cleanups" + 2 fixes. * 'for-airlied' of git://people.freedesktop.org/~danvet/drm-intel: (78 commits) drm/i915: fix OOPS in lid_notify drm/i915: correctly update crtc->x/y in set_base drm/fb helper: don't call drm_helper_connector_dpms directly drm/i915: improve modeset state checking after dpms calls drm/i915: add tons of modeset state checks drm/i915: no longer call drm_helper_resume_force_mode drm/i915: disable all crtcs at suspend time drm/i915: push commit_output_state past the crtc/encoder preparing drm/i915: switch the load detect code to the staged modeset config drm/i915: WARN if the pipe won't turn off drm/i915: s/intel_encoder_disable/intel_encoder_noop drm/i915: push commit_output_state past crtc disabling drm/i915: implement new set_mode code flow drm/i915: compute masks of crtcs affected in set_mode drm/i915: use staged outuput config in lvds->mode_fixup drm/i915: use staged outuput config in tv->mode_fixup drm/i915: extract adjusted mode computation drm/i915: move output commit and crtc disabling into set_mode drm/i915: remove crtc disabling special case drm/i915: push crtc->fb update into pipe_set_base ...
-rw-r--r--drivers/gpu/drm/drm_fb_helper.c2
-rw-r--r--drivers/gpu/drm/i915/dvo.h6
-rw-r--r--drivers/gpu/drm/i915/dvo_ch7017.c13
-rw-r--r--drivers/gpu/drm/i915/dvo_ch7xxx.c13
-rw-r--r--drivers/gpu/drm/i915/dvo_ivch.c15
-rw-r--r--drivers/gpu/drm/i915/dvo_ns2501.c15
-rw-r--r--drivers/gpu/drm/i915/dvo_sil164.c16
-rw-r--r--drivers/gpu/drm/i915/dvo_tfp410.c14
-rw-r--r--drivers/gpu/drm/i915/i915_debugfs.c54
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c9
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h36
-rw-r--r--drivers/gpu/drm/i915/i915_irq.c20
-rw-r--r--drivers/gpu/drm/i915/i915_reg.h2
-rw-r--r--drivers/gpu/drm/i915/i915_sysfs.c15
-rw-r--r--drivers/gpu/drm/i915/i915_trace.h15
-rw-r--r--drivers/gpu/drm/i915/intel_crt.c136
-rw-r--r--drivers/gpu/drm/i915/intel_ddi.c59
-rw-r--r--drivers/gpu/drm/i915/intel_display.c1419
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c144
-rw-r--r--drivers/gpu/drm/i915/intel_drv.h67
-rw-r--r--drivers/gpu/drm/i915/intel_dvo.c94
-rw-r--r--drivers/gpu/drm/i915/intel_hdmi.c151
-rw-r--r--drivers/gpu/drm/i915/intel_lvds.c97
-rw-r--r--drivers/gpu/drm/i915/intel_pm.c138
-rw-r--r--drivers/gpu/drm/i915/intel_ringbuffer.c82
-rw-r--r--drivers/gpu/drm/i915/intel_sdvo.c206
-rw-r--r--drivers/gpu/drm/i915/intel_tv.c61
27 files changed, 2257 insertions, 642 deletions
diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index eb79515797d9..b5d05f58c15a 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -330,7 +330,7 @@ static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode)
330 /* Walk the connectors & encoders on this fb turning them on/off */ 330 /* Walk the connectors & encoders on this fb turning them on/off */
331 for (j = 0; j < fb_helper->connector_count; j++) { 331 for (j = 0; j < fb_helper->connector_count; j++) {
332 connector = fb_helper->connector_info[j]->connector; 332 connector = fb_helper->connector_info[j]->connector;
333 drm_helper_connector_dpms(connector, dpms_mode); 333 connector->funcs->dpms(connector, dpms_mode);
334 drm_connector_property_set_value(connector, 334 drm_connector_property_set_value(connector,
335 dev->mode_config.dpms_property, dpms_mode); 335 dev->mode_config.dpms_property, dpms_mode);
336 } 336 }
diff --git a/drivers/gpu/drm/i915/dvo.h b/drivers/gpu/drm/i915/dvo.h
index 0fa839e439b3..74b5efccfdb1 100644
--- a/drivers/gpu/drm/i915/dvo.h
+++ b/drivers/gpu/drm/i915/dvo.h
@@ -114,6 +114,12 @@ struct intel_dvo_dev_ops {
114 */ 114 */
115 enum drm_connector_status (*detect)(struct intel_dvo_device *dvo); 115 enum drm_connector_status (*detect)(struct intel_dvo_device *dvo);
116 116
117 /*
118 * Probe the current hw status, returning true if the connected output
119 * is active.
120 */
121 bool (*get_hw_state)(struct intel_dvo_device *dev);
122
117 /** 123 /**
118 * Query the device for the modes it provides. 124 * Query the device for the modes it provides.
119 * 125 *
diff --git a/drivers/gpu/drm/i915/dvo_ch7017.c b/drivers/gpu/drm/i915/dvo_ch7017.c
index 71e7650a2994..86b27d1d90c2 100644
--- a/drivers/gpu/drm/i915/dvo_ch7017.c
+++ b/drivers/gpu/drm/i915/dvo_ch7017.c
@@ -359,6 +359,18 @@ static void ch7017_dpms(struct intel_dvo_device *dvo, bool enable)
359 msleep(20); 359 msleep(20);
360} 360}
361 361
362static bool ch7017_get_hw_state(struct intel_dvo_device *dvo)
363{
364 uint8_t val;
365
366 ch7017_read(dvo, CH7017_LVDS_POWER_DOWN, &val);
367
368 if (val & CH7017_LVDS_POWER_DOWN_EN)
369 return false;
370 else
371 return true;
372}
373
362static void ch7017_dump_regs(struct intel_dvo_device *dvo) 374static void ch7017_dump_regs(struct intel_dvo_device *dvo)
363{ 375{
364 uint8_t val; 376 uint8_t val;
@@ -396,6 +408,7 @@ struct intel_dvo_dev_ops ch7017_ops = {
396 .mode_valid = ch7017_mode_valid, 408 .mode_valid = ch7017_mode_valid,
397 .mode_set = ch7017_mode_set, 409 .mode_set = ch7017_mode_set,
398 .dpms = ch7017_dpms, 410 .dpms = ch7017_dpms,
411 .get_hw_state = ch7017_get_hw_state,
399 .dump_regs = ch7017_dump_regs, 412 .dump_regs = ch7017_dump_regs,
400 .destroy = ch7017_destroy, 413 .destroy = ch7017_destroy,
401}; 414};
diff --git a/drivers/gpu/drm/i915/dvo_ch7xxx.c b/drivers/gpu/drm/i915/dvo_ch7xxx.c
index c1dea5b11f91..38f3a6cb8c7d 100644
--- a/drivers/gpu/drm/i915/dvo_ch7xxx.c
+++ b/drivers/gpu/drm/i915/dvo_ch7xxx.c
@@ -297,6 +297,18 @@ static void ch7xxx_dpms(struct intel_dvo_device *dvo, bool enable)
297 ch7xxx_writeb(dvo, CH7xxx_PM, CH7xxx_PM_FPD); 297 ch7xxx_writeb(dvo, CH7xxx_PM, CH7xxx_PM_FPD);
298} 298}
299 299
300static bool ch7xxx_get_hw_state(struct intel_dvo_device *dvo)
301{
302 u8 val;
303
304 ch7xxx_readb(dvo, CH7xxx_PM, &val);
305
306 if (val & CH7xxx_PM_FPD)
307 return false;
308 else
309 return true;
310}
311
300static void ch7xxx_dump_regs(struct intel_dvo_device *dvo) 312static void ch7xxx_dump_regs(struct intel_dvo_device *dvo)
301{ 313{
302 int i; 314 int i;
@@ -326,6 +338,7 @@ struct intel_dvo_dev_ops ch7xxx_ops = {
326 .mode_valid = ch7xxx_mode_valid, 338 .mode_valid = ch7xxx_mode_valid,
327 .mode_set = ch7xxx_mode_set, 339 .mode_set = ch7xxx_mode_set,
328 .dpms = ch7xxx_dpms, 340 .dpms = ch7xxx_dpms,
341 .get_hw_state = ch7xxx_get_hw_state,
329 .dump_regs = ch7xxx_dump_regs, 342 .dump_regs = ch7xxx_dump_regs,
330 .destroy = ch7xxx_destroy, 343 .destroy = ch7xxx_destroy,
331}; 344};
diff --git a/drivers/gpu/drm/i915/dvo_ivch.c b/drivers/gpu/drm/i915/dvo_ivch.c
index fa8ff6b050fa..baaf65bf0bdd 100644
--- a/drivers/gpu/drm/i915/dvo_ivch.c
+++ b/drivers/gpu/drm/i915/dvo_ivch.c
@@ -323,6 +323,20 @@ static void ivch_dpms(struct intel_dvo_device *dvo, bool enable)
323 udelay(16 * 1000); 323 udelay(16 * 1000);
324} 324}
325 325
326static bool ivch_get_hw_state(struct intel_dvo_device *dvo)
327{
328 uint16_t vr01;
329
330 /* Set the new power state of the panel. */
331 if (!ivch_read(dvo, VR01, &vr01))
332 return false;
333
334 if (vr01 & VR01_LCD_ENABLE)
335 return true;
336 else
337 return false;
338}
339
326static void ivch_mode_set(struct intel_dvo_device *dvo, 340static void ivch_mode_set(struct intel_dvo_device *dvo,
327 struct drm_display_mode *mode, 341 struct drm_display_mode *mode,
328 struct drm_display_mode *adjusted_mode) 342 struct drm_display_mode *adjusted_mode)
@@ -413,6 +427,7 @@ static void ivch_destroy(struct intel_dvo_device *dvo)
413struct intel_dvo_dev_ops ivch_ops = { 427struct intel_dvo_dev_ops ivch_ops = {
414 .init = ivch_init, 428 .init = ivch_init,
415 .dpms = ivch_dpms, 429 .dpms = ivch_dpms,
430 .get_hw_state = ivch_get_hw_state,
416 .mode_valid = ivch_mode_valid, 431 .mode_valid = ivch_mode_valid,
417 .mode_set = ivch_mode_set, 432 .mode_set = ivch_mode_set,
418 .detect = ivch_detect, 433 .detect = ivch_detect,
diff --git a/drivers/gpu/drm/i915/dvo_ns2501.c b/drivers/gpu/drm/i915/dvo_ns2501.c
index c4d9f2f395e6..c4a255be6979 100644
--- a/drivers/gpu/drm/i915/dvo_ns2501.c
+++ b/drivers/gpu/drm/i915/dvo_ns2501.c
@@ -493,6 +493,20 @@ static void ns2501_mode_set(struct intel_dvo_device *dvo,
493} 493}
494 494
495/* set the NS2501 power state */ 495/* set the NS2501 power state */
496static bool ns2501_get_hw_state(struct intel_dvo_device *dvo)
497{
498 unsigned char ch;
499
500 if (!ns2501_readb(dvo, NS2501_REG8, &ch))
501 return false;
502
503 if (ch & NS2501_8_PD)
504 return true;
505 else
506 return false;
507}
508
509/* set the NS2501 power state */
496static void ns2501_dpms(struct intel_dvo_device *dvo, bool enable) 510static void ns2501_dpms(struct intel_dvo_device *dvo, bool enable)
497{ 511{
498 bool ok; 512 bool ok;
@@ -568,6 +582,7 @@ struct intel_dvo_dev_ops ns2501_ops = {
568 .mode_valid = ns2501_mode_valid, 582 .mode_valid = ns2501_mode_valid,
569 .mode_set = ns2501_mode_set, 583 .mode_set = ns2501_mode_set,
570 .dpms = ns2501_dpms, 584 .dpms = ns2501_dpms,
585 .get_hw_state = ns2501_get_hw_state,
571 .dump_regs = ns2501_dump_regs, 586 .dump_regs = ns2501_dump_regs,
572 .destroy = ns2501_destroy, 587 .destroy = ns2501_destroy,
573}; 588};
diff --git a/drivers/gpu/drm/i915/dvo_sil164.c b/drivers/gpu/drm/i915/dvo_sil164.c
index cc24c1cabecd..4debd32e3e4c 100644
--- a/drivers/gpu/drm/i915/dvo_sil164.c
+++ b/drivers/gpu/drm/i915/dvo_sil164.c
@@ -226,6 +226,21 @@ static void sil164_dpms(struct intel_dvo_device *dvo, bool enable)
226 return; 226 return;
227} 227}
228 228
229static bool sil164_get_hw_state(struct intel_dvo_device *dvo)
230{
231 int ret;
232 unsigned char ch;
233
234 ret = sil164_readb(dvo, SIL164_REG8, &ch);
235 if (ret == false)
236 return false;
237
238 if (ch & SIL164_8_PD)
239 return true;
240 else
241 return false;
242}
243
229static void sil164_dump_regs(struct intel_dvo_device *dvo) 244static void sil164_dump_regs(struct intel_dvo_device *dvo)
230{ 245{
231 uint8_t val; 246 uint8_t val;
@@ -258,6 +273,7 @@ struct intel_dvo_dev_ops sil164_ops = {
258 .mode_valid = sil164_mode_valid, 273 .mode_valid = sil164_mode_valid,
259 .mode_set = sil164_mode_set, 274 .mode_set = sil164_mode_set,
260 .dpms = sil164_dpms, 275 .dpms = sil164_dpms,
276 .get_hw_state = sil164_get_hw_state,
261 .dump_regs = sil164_dump_regs, 277 .dump_regs = sil164_dump_regs,
262 .destroy = sil164_destroy, 278 .destroy = sil164_destroy,
263}; 279};
diff --git a/drivers/gpu/drm/i915/dvo_tfp410.c b/drivers/gpu/drm/i915/dvo_tfp410.c
index 097b3e82b00f..e17f1b07e915 100644
--- a/drivers/gpu/drm/i915/dvo_tfp410.c
+++ b/drivers/gpu/drm/i915/dvo_tfp410.c
@@ -249,6 +249,19 @@ static void tfp410_dpms(struct intel_dvo_device *dvo, bool enable)
249 tfp410_writeb(dvo, TFP410_CTL_1, ctl1); 249 tfp410_writeb(dvo, TFP410_CTL_1, ctl1);
250} 250}
251 251
252static bool tfp410_get_hw_state(struct intel_dvo_device *dvo)
253{
254 uint8_t ctl1;
255
256 if (!tfp410_readb(dvo, TFP410_CTL_1, &ctl1))
257 return false;
258
259 if (ctl1 & TFP410_CTL_1_PD)
260 return true;
261 else
262 return false;
263}
264
252static void tfp410_dump_regs(struct intel_dvo_device *dvo) 265static void tfp410_dump_regs(struct intel_dvo_device *dvo)
253{ 266{
254 uint8_t val, val2; 267 uint8_t val, val2;
@@ -299,6 +312,7 @@ struct intel_dvo_dev_ops tfp410_ops = {
299 .mode_valid = tfp410_mode_valid, 312 .mode_valid = tfp410_mode_valid,
300 .mode_set = tfp410_mode_set, 313 .mode_set = tfp410_mode_set,
301 .dpms = tfp410_dpms, 314 .dpms = tfp410_dpms,
315 .get_hw_state = tfp410_get_hw_state,
302 .dump_regs = tfp410_dump_regs, 316 .dump_regs = tfp410_dump_regs,
303 .destroy = tfp410_destroy, 317 .destroy = tfp410_destroy,
304}; 318};
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 3d886af2aae6..274a3280cdce 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -353,40 +353,22 @@ static int i915_gem_request_info(struct seq_file *m, void *data)
353 struct drm_info_node *node = (struct drm_info_node *) m->private; 353 struct drm_info_node *node = (struct drm_info_node *) m->private;
354 struct drm_device *dev = node->minor->dev; 354 struct drm_device *dev = node->minor->dev;
355 drm_i915_private_t *dev_priv = dev->dev_private; 355 drm_i915_private_t *dev_priv = dev->dev_private;
356 struct intel_ring_buffer *ring;
356 struct drm_i915_gem_request *gem_request; 357 struct drm_i915_gem_request *gem_request;
357 int ret, count; 358 int ret, count, i;
358 359
359 ret = mutex_lock_interruptible(&dev->struct_mutex); 360 ret = mutex_lock_interruptible(&dev->struct_mutex);
360 if (ret) 361 if (ret)
361 return ret; 362 return ret;
362 363
363 count = 0; 364 count = 0;
364 if (!list_empty(&dev_priv->ring[RCS].request_list)) { 365 for_each_ring(ring, dev_priv, i) {
365 seq_printf(m, "Render requests:\n"); 366 if (list_empty(&ring->request_list))
366 list_for_each_entry(gem_request, 367 continue;
367 &dev_priv->ring[RCS].request_list, 368
368 list) { 369 seq_printf(m, "%s requests:\n", ring->name);
369 seq_printf(m, " %d @ %d\n",
370 gem_request->seqno,
371 (int) (jiffies - gem_request->emitted_jiffies));
372 }
373 count++;
374 }
375 if (!list_empty(&dev_priv->ring[VCS].request_list)) {
376 seq_printf(m, "BSD requests:\n");
377 list_for_each_entry(gem_request,
378 &dev_priv->ring[VCS].request_list,
379 list) {
380 seq_printf(m, " %d @ %d\n",
381 gem_request->seqno,
382 (int) (jiffies - gem_request->emitted_jiffies));
383 }
384 count++;
385 }
386 if (!list_empty(&dev_priv->ring[BCS].request_list)) {
387 seq_printf(m, "BLT requests:\n");
388 list_for_each_entry(gem_request, 370 list_for_each_entry(gem_request,
389 &dev_priv->ring[BCS].request_list, 371 &ring->request_list,
390 list) { 372 list) {
391 seq_printf(m, " %d @ %d\n", 373 seq_printf(m, " %d @ %d\n",
392 gem_request->seqno, 374 gem_request->seqno,
@@ -416,14 +398,15 @@ static int i915_gem_seqno_info(struct seq_file *m, void *data)
416 struct drm_info_node *node = (struct drm_info_node *) m->private; 398 struct drm_info_node *node = (struct drm_info_node *) m->private;
417 struct drm_device *dev = node->minor->dev; 399 struct drm_device *dev = node->minor->dev;
418 drm_i915_private_t *dev_priv = dev->dev_private; 400 drm_i915_private_t *dev_priv = dev->dev_private;
401 struct intel_ring_buffer *ring;
419 int ret, i; 402 int ret, i;
420 403
421 ret = mutex_lock_interruptible(&dev->struct_mutex); 404 ret = mutex_lock_interruptible(&dev->struct_mutex);
422 if (ret) 405 if (ret)
423 return ret; 406 return ret;
424 407
425 for (i = 0; i < I915_NUM_RINGS; i++) 408 for_each_ring(ring, dev_priv, i)
426 i915_ring_seqno_info(m, &dev_priv->ring[i]); 409 i915_ring_seqno_info(m, ring);
427 410
428 mutex_unlock(&dev->struct_mutex); 411 mutex_unlock(&dev->struct_mutex);
429 412
@@ -436,6 +419,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
436 struct drm_info_node *node = (struct drm_info_node *) m->private; 419 struct drm_info_node *node = (struct drm_info_node *) m->private;
437 struct drm_device *dev = node->minor->dev; 420 struct drm_device *dev = node->minor->dev;
438 drm_i915_private_t *dev_priv = dev->dev_private; 421 drm_i915_private_t *dev_priv = dev->dev_private;
422 struct intel_ring_buffer *ring;
439 int ret, i, pipe; 423 int ret, i, pipe;
440 424
441 ret = mutex_lock_interruptible(&dev->struct_mutex); 425 ret = mutex_lock_interruptible(&dev->struct_mutex);
@@ -513,13 +497,13 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
513 } 497 }
514 seq_printf(m, "Interrupts received: %d\n", 498 seq_printf(m, "Interrupts received: %d\n",
515 atomic_read(&dev_priv->irq_received)); 499 atomic_read(&dev_priv->irq_received));
516 for (i = 0; i < I915_NUM_RINGS; i++) { 500 for_each_ring(ring, dev_priv, i) {
517 if (IS_GEN6(dev) || IS_GEN7(dev)) { 501 if (IS_GEN6(dev) || IS_GEN7(dev)) {
518 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n", 502 seq_printf(m,
519 dev_priv->ring[i].name, 503 "Graphics Interrupt mask (%s): %08x\n",
520 I915_READ_IMR(&dev_priv->ring[i])); 504 ring->name, I915_READ_IMR(ring));
521 } 505 }
522 i915_ring_seqno_info(m, &dev_priv->ring[i]); 506 i915_ring_seqno_info(m, ring);
523 } 507 }
524 mutex_unlock(&dev->struct_mutex); 508 mutex_unlock(&dev->struct_mutex);
525 509
@@ -1529,9 +1513,7 @@ static int i915_ppgtt_info(struct seq_file *m, void *data)
1529 if (INTEL_INFO(dev)->gen == 6) 1513 if (INTEL_INFO(dev)->gen == 6)
1530 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE)); 1514 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1531 1515
1532 for (i = 0; i < I915_NUM_RINGS; i++) { 1516 for_each_ring(ring, dev_priv, i) {
1533 ring = &dev_priv->ring[i];
1534
1535 seq_printf(m, "%s\n", ring->name); 1517 seq_printf(m, "%s\n", ring->name);
1536 if (INTEL_INFO(dev)->gen == 7) 1518 if (INTEL_INFO(dev)->gen == 7)
1537 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring))); 1519 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 7f3863fb138c..a7837e556945 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -470,6 +470,9 @@ static int i915_drm_freeze(struct drm_device *dev)
470 "GEM idle failed, resume might fail\n"); 470 "GEM idle failed, resume might fail\n");
471 return error; 471 return error;
472 } 472 }
473
474 intel_modeset_disable(dev);
475
473 drm_irq_uninstall(dev); 476 drm_irq_uninstall(dev);
474 } 477 }
475 478
@@ -543,13 +546,9 @@ static int i915_drm_thaw(struct drm_device *dev)
543 mutex_unlock(&dev->struct_mutex); 546 mutex_unlock(&dev->struct_mutex);
544 547
545 intel_modeset_init_hw(dev); 548 intel_modeset_init_hw(dev);
549 intel_modeset_setup_hw_state(dev);
546 drm_mode_config_reset(dev); 550 drm_mode_config_reset(dev);
547 drm_irq_install(dev); 551 drm_irq_install(dev);
548
549 /* Resume the modeset for every activated CRTC */
550 mutex_lock(&dev->mode_config.mutex);
551 drm_helper_resume_force_mode(dev);
552 mutex_unlock(&dev->mode_config.mutex);
553 } 552 }
554 553
555 intel_opregion_init(dev); 554 intel_opregion_init(dev);
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 58b43db0a134..26c6959a524a 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -241,7 +241,6 @@ struct drm_i915_error_state {
241}; 241};
242 242
243struct drm_i915_display_funcs { 243struct drm_i915_display_funcs {
244 void (*dpms)(struct drm_crtc *crtc, int mode);
245 bool (*fbc_enabled)(struct drm_device *dev); 244 bool (*fbc_enabled)(struct drm_device *dev);
246 void (*enable_fbc)(struct drm_crtc *crtc, unsigned long interval); 245 void (*enable_fbc)(struct drm_crtc *crtc, unsigned long interval);
247 void (*disable_fbc)(struct drm_device *dev); 246 void (*disable_fbc)(struct drm_device *dev);
@@ -257,6 +256,8 @@ struct drm_i915_display_funcs {
257 struct drm_display_mode *adjusted_mode, 256 struct drm_display_mode *adjusted_mode,
258 int x, int y, 257 int x, int y,
259 struct drm_framebuffer *old_fb); 258 struct drm_framebuffer *old_fb);
259 void (*crtc_enable)(struct drm_crtc *crtc);
260 void (*crtc_disable)(struct drm_crtc *crtc);
260 void (*off)(struct drm_crtc *crtc); 261 void (*off)(struct drm_crtc *crtc);
261 void (*write_eld)(struct drm_connector *connector, 262 void (*write_eld)(struct drm_connector *connector,
262 struct drm_crtc *crtc); 263 struct drm_crtc *crtc);
@@ -839,22 +840,26 @@ typedef struct drm_i915_private {
839 u8 max_delay; 840 u8 max_delay;
840 } rps; 841 } rps;
841 842
843 /* ilk-only ips/rps state. Everything in here is protected by the global
844 * mchdev_lock in intel_pm.c */
845 struct {
846 u8 cur_delay;
847 u8 min_delay;
848 u8 max_delay;
849 u8 fmax;
850 u8 fstart;
842 851
843 u8 cur_delay; 852 u64 last_count1;
844 u8 min_delay; 853 unsigned long last_time1;
845 u8 max_delay; 854 unsigned long chipset_power;
846 u8 fmax; 855 u64 last_count2;
847 u8 fstart; 856 struct timespec last_time2;
857 unsigned long gfx_power;
858 u8 corr;
848 859
849 u64 last_count1; 860 int c_m;
850 unsigned long last_time1; 861 int r_t;
851 unsigned long chipset_power; 862 } ips;
852 u64 last_count2;
853 struct timespec last_time2;
854 unsigned long gfx_power;
855 int c_m;
856 int r_t;
857 u8 corr;
858 863
859 enum no_fbc_reason no_fbc_reason; 864 enum no_fbc_reason no_fbc_reason;
860 865
@@ -1546,6 +1551,7 @@ extern void intel_modeset_init(struct drm_device *dev);
1546extern void intel_modeset_gem_init(struct drm_device *dev); 1551extern void intel_modeset_gem_init(struct drm_device *dev);
1547extern void intel_modeset_cleanup(struct drm_device *dev); 1552extern void intel_modeset_cleanup(struct drm_device *dev);
1548extern int intel_modeset_vga_set_state(struct drm_device *dev, bool state); 1553extern int intel_modeset_vga_set_state(struct drm_device *dev, bool state);
1554extern void intel_modeset_setup_hw_state(struct drm_device *dev);
1549extern bool intel_fbc_enabled(struct drm_device *dev); 1555extern bool intel_fbc_enabled(struct drm_device *dev);
1550extern void intel_disable_fbc(struct drm_device *dev); 1556extern void intel_disable_fbc(struct drm_device *dev);
1551extern bool ironlake_set_drps(struct drm_device *dev, u8 val); 1557extern bool ironlake_set_drps(struct drm_device *dev, u8 val);
diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index a9f74f3b4073..d6010135e404 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -310,7 +310,7 @@ static void ironlake_handle_rps_change(struct drm_device *dev)
310 310
311 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS)); 311 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
312 312
313 new_delay = dev_priv->cur_delay; 313 new_delay = dev_priv->ips.cur_delay;
314 314
315 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG); 315 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
316 busy_up = I915_READ(RCPREVBSYTUPAVG); 316 busy_up = I915_READ(RCPREVBSYTUPAVG);
@@ -320,19 +320,19 @@ static void ironlake_handle_rps_change(struct drm_device *dev)
320 320
321 /* Handle RCS change request from hw */ 321 /* Handle RCS change request from hw */
322 if (busy_up > max_avg) { 322 if (busy_up > max_avg) {
323 if (dev_priv->cur_delay != dev_priv->max_delay) 323 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
324 new_delay = dev_priv->cur_delay - 1; 324 new_delay = dev_priv->ips.cur_delay - 1;
325 if (new_delay < dev_priv->max_delay) 325 if (new_delay < dev_priv->ips.max_delay)
326 new_delay = dev_priv->max_delay; 326 new_delay = dev_priv->ips.max_delay;
327 } else if (busy_down < min_avg) { 327 } else if (busy_down < min_avg) {
328 if (dev_priv->cur_delay != dev_priv->min_delay) 328 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
329 new_delay = dev_priv->cur_delay + 1; 329 new_delay = dev_priv->ips.cur_delay + 1;
330 if (new_delay > dev_priv->min_delay) 330 if (new_delay > dev_priv->ips.min_delay)
331 new_delay = dev_priv->min_delay; 331 new_delay = dev_priv->ips.min_delay;
332 } 332 }
333 333
334 if (ironlake_set_drps(dev, new_delay)) 334 if (ironlake_set_drps(dev, new_delay))
335 dev_priv->cur_delay = new_delay; 335 dev_priv->ips.cur_delay = new_delay;
336 336
337 spin_unlock_irqrestore(&mchdev_lock, flags); 337 spin_unlock_irqrestore(&mchdev_lock, flags);
338 338
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 75dcfa4ec5ce..a828e90602b9 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -4037,6 +4037,8 @@
4037#define PORT_TRANS_C_SEL_CPT (2<<29) 4037#define PORT_TRANS_C_SEL_CPT (2<<29)
4038#define PORT_TRANS_SEL_MASK (3<<29) 4038#define PORT_TRANS_SEL_MASK (3<<29)
4039#define PORT_TRANS_SEL_CPT(pipe) ((pipe) << 29) 4039#define PORT_TRANS_SEL_CPT(pipe) ((pipe) << 29)
4040#define PORT_TO_PIPE(val) (((val) & (1<<30)) >> 30)
4041#define PORT_TO_PIPE_CPT(val) (((val) & PORT_TRANS_SEL_MASK) >> 29)
4040 4042
4041#define TRANS_DP_CTL_A 0xe0300 4043#define TRANS_DP_CTL_A 0xe0300
4042#define TRANS_DP_CTL_B 0xe1300 4044#define TRANS_DP_CTL_B 0xe1300
diff --git a/drivers/gpu/drm/i915/i915_sysfs.c b/drivers/gpu/drm/i915/i915_sysfs.c
index c5ee7ee3b17e..da733a3fe1ef 100644
--- a/drivers/gpu/drm/i915/i915_sysfs.c
+++ b/drivers/gpu/drm/i915/i915_sysfs.c
@@ -93,6 +93,7 @@ static struct attribute_group rc6_attr_group = {
93 .name = power_group_name, 93 .name = power_group_name,
94 .attrs = rc6_attrs 94 .attrs = rc6_attrs
95}; 95};
96#endif
96 97
97static int l3_access_valid(struct drm_device *dev, loff_t offset) 98static int l3_access_valid(struct drm_device *dev, loff_t offset)
98{ 99{
@@ -206,13 +207,14 @@ void i915_setup_sysfs(struct drm_device *dev)
206{ 207{
207 int ret; 208 int ret;
208 209
210#ifdef CONFIG_PM
209 if (INTEL_INFO(dev)->gen >= 6) { 211 if (INTEL_INFO(dev)->gen >= 6) {
210 ret = sysfs_merge_group(&dev->primary->kdev.kobj, 212 ret = sysfs_merge_group(&dev->primary->kdev.kobj,
211 &rc6_attr_group); 213 &rc6_attr_group);
212 if (ret) 214 if (ret)
213 DRM_ERROR("RC6 residency sysfs setup failed\n"); 215 DRM_ERROR("RC6 residency sysfs setup failed\n");
214 } 216 }
215 217#endif
216 if (HAS_L3_GPU_CACHE(dev)) { 218 if (HAS_L3_GPU_CACHE(dev)) {
217 ret = device_create_bin_file(&dev->primary->kdev, &dpf_attrs); 219 ret = device_create_bin_file(&dev->primary->kdev, &dpf_attrs);
218 if (ret) 220 if (ret)
@@ -225,14 +227,3 @@ void i915_teardown_sysfs(struct drm_device *dev)
225 device_remove_bin_file(&dev->primary->kdev, &dpf_attrs); 227 device_remove_bin_file(&dev->primary->kdev, &dpf_attrs);
226 sysfs_unmerge_group(&dev->primary->kdev.kobj, &rc6_attr_group); 228 sysfs_unmerge_group(&dev->primary->kdev.kobj, &rc6_attr_group);
227} 229}
228#else
229void i915_setup_sysfs(struct drm_device *dev)
230{
231 return;
232}
233
234void i915_teardown_sysfs(struct drm_device *dev)
235{
236 return;
237}
238#endif /* CONFIG_PM */
diff --git a/drivers/gpu/drm/i915/i915_trace.h b/drivers/gpu/drm/i915/i915_trace.h
index 3c4093d91f60..8134421b89a6 100644
--- a/drivers/gpu/drm/i915/i915_trace.h
+++ b/drivers/gpu/drm/i915/i915_trace.h
@@ -430,6 +430,21 @@ TRACE_EVENT(i915_reg_rw,
430 (u32)(__entry->val >> 32)) 430 (u32)(__entry->val >> 32))
431); 431);
432 432
433TRACE_EVENT(intel_gpu_freq_change,
434 TP_PROTO(u32 freq),
435 TP_ARGS(freq),
436
437 TP_STRUCT__entry(
438 __field(u32, freq)
439 ),
440
441 TP_fast_assign(
442 __entry->freq = freq;
443 ),
444
445 TP_printk("new_freq=%u", __entry->freq)
446);
447
433#endif /* _I915_TRACE_H_ */ 448#endif /* _I915_TRACE_H_ */
434 449
435/* This part must be outside protection */ 450/* This part must be outside protection */
diff --git a/drivers/gpu/drm/i915/intel_crt.c b/drivers/gpu/drm/i915/intel_crt.c
index 236191377b0f..c42b9809f86d 100644
--- a/drivers/gpu/drm/i915/intel_crt.c
+++ b/drivers/gpu/drm/i915/intel_crt.c
@@ -61,42 +61,63 @@ static struct intel_crt *intel_encoder_to_crt(struct intel_encoder *encoder)
61 return container_of(encoder, struct intel_crt, base); 61 return container_of(encoder, struct intel_crt, base);
62} 62}
63 63
64static void pch_crt_dpms(struct drm_encoder *encoder, int mode) 64static bool intel_crt_get_hw_state(struct intel_encoder *encoder,
65 enum pipe *pipe)
65{ 66{
66 struct drm_device *dev = encoder->dev; 67 struct drm_device *dev = encoder->base.dev;
67 struct drm_i915_private *dev_priv = dev->dev_private; 68 struct drm_i915_private *dev_priv = dev->dev_private;
69 struct intel_crt *crt = intel_encoder_to_crt(encoder);
70 u32 tmp;
71
72 tmp = I915_READ(crt->adpa_reg);
73
74 if (!(tmp & ADPA_DAC_ENABLE))
75 return false;
76
77 if (HAS_PCH_CPT(dev))
78 *pipe = PORT_TO_PIPE_CPT(tmp);
79 else
80 *pipe = PORT_TO_PIPE(tmp);
81
82 return true;
83}
84
85static void intel_disable_crt(struct intel_encoder *encoder)
86{
87 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
88 struct intel_crt *crt = intel_encoder_to_crt(encoder);
68 u32 temp; 89 u32 temp;
69 90
70 temp = I915_READ(PCH_ADPA); 91 temp = I915_READ(crt->adpa_reg);
92 temp &= ~(ADPA_HSYNC_CNTL_DISABLE | ADPA_VSYNC_CNTL_DISABLE);
71 temp &= ~ADPA_DAC_ENABLE; 93 temp &= ~ADPA_DAC_ENABLE;
94 I915_WRITE(crt->adpa_reg, temp);
95}
72 96
73 switch (mode) { 97static void intel_enable_crt(struct intel_encoder *encoder)
74 case DRM_MODE_DPMS_ON: 98{
75 temp |= ADPA_DAC_ENABLE; 99 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
76 break; 100 struct intel_crt *crt = intel_encoder_to_crt(encoder);
77 case DRM_MODE_DPMS_STANDBY: 101 u32 temp;
78 case DRM_MODE_DPMS_SUSPEND:
79 case DRM_MODE_DPMS_OFF:
80 /* Just leave port enable cleared */
81 break;
82 }
83 102
84 I915_WRITE(PCH_ADPA, temp); 103 temp = I915_READ(crt->adpa_reg);
104 temp |= ADPA_DAC_ENABLE;
105 I915_WRITE(crt->adpa_reg, temp);
85} 106}
86 107
87static void gmch_crt_dpms(struct drm_encoder *encoder, int mode) 108/* Note: The caller is required to filter out dpms modes not supported by the
109 * platform. */
110static void intel_crt_set_dpms(struct intel_encoder *encoder, int mode)
88{ 111{
89 struct drm_device *dev = encoder->dev; 112 struct drm_device *dev = encoder->base.dev;
90 struct drm_i915_private *dev_priv = dev->dev_private; 113 struct drm_i915_private *dev_priv = dev->dev_private;
114 struct intel_crt *crt = intel_encoder_to_crt(encoder);
91 u32 temp; 115 u32 temp;
92 116
93 temp = I915_READ(ADPA); 117 temp = I915_READ(crt->adpa_reg);
94 temp &= ~(ADPA_HSYNC_CNTL_DISABLE | ADPA_VSYNC_CNTL_DISABLE); 118 temp &= ~(ADPA_HSYNC_CNTL_DISABLE | ADPA_VSYNC_CNTL_DISABLE);
95 temp &= ~ADPA_DAC_ENABLE; 119 temp &= ~ADPA_DAC_ENABLE;
96 120
97 if (IS_VALLEYVIEW(dev) && mode != DRM_MODE_DPMS_ON)
98 mode = DRM_MODE_DPMS_OFF;
99
100 switch (mode) { 121 switch (mode) {
101 case DRM_MODE_DPMS_ON: 122 case DRM_MODE_DPMS_ON:
102 temp |= ADPA_DAC_ENABLE; 123 temp |= ADPA_DAC_ENABLE;
@@ -112,7 +133,51 @@ static void gmch_crt_dpms(struct drm_encoder *encoder, int mode)
112 break; 133 break;
113 } 134 }
114 135
115 I915_WRITE(ADPA, temp); 136 I915_WRITE(crt->adpa_reg, temp);
137}
138
139static void intel_crt_dpms(struct drm_connector *connector, int mode)
140{
141 struct drm_device *dev = connector->dev;
142 struct intel_encoder *encoder = intel_attached_encoder(connector);
143 struct drm_crtc *crtc;
144 int old_dpms;
145
146 /* PCH platforms and VLV only support on/off. */
147 if (INTEL_INFO(dev)->gen < 5 && mode != DRM_MODE_DPMS_ON)
148 mode = DRM_MODE_DPMS_OFF;
149
150 if (mode == connector->dpms)
151 return;
152
153 old_dpms = connector->dpms;
154 connector->dpms = mode;
155
156 /* Only need to change hw state when actually enabled */
157 crtc = encoder->base.crtc;
158 if (!crtc) {
159 encoder->connectors_active = false;
160 return;
161 }
162
163 /* We need the pipe to run for anything but OFF. */
164 if (mode == DRM_MODE_DPMS_OFF)
165 encoder->connectors_active = false;
166 else
167 encoder->connectors_active = true;
168
169 if (mode < old_dpms) {
170 /* From off to on, enable the pipe first. */
171 intel_crtc_update_dpms(crtc);
172
173 intel_crt_set_dpms(encoder, mode);
174 } else {
175 intel_crt_set_dpms(encoder, mode);
176
177 intel_crtc_update_dpms(crtc);
178 }
179
180 intel_modeset_check_state(connector->dev);
116} 181}
117 182
118static int intel_crt_mode_valid(struct drm_connector *connector, 183static int intel_crt_mode_valid(struct drm_connector *connector,
@@ -603,25 +668,15 @@ static void intel_crt_reset(struct drm_connector *connector)
603 * Routines for controlling stuff on the analog port 668 * Routines for controlling stuff on the analog port
604 */ 669 */
605 670
606static const struct drm_encoder_helper_funcs pch_encoder_funcs = { 671static const struct drm_encoder_helper_funcs crt_encoder_funcs = {
607 .mode_fixup = intel_crt_mode_fixup, 672 .mode_fixup = intel_crt_mode_fixup,
608 .prepare = intel_encoder_prepare,
609 .commit = intel_encoder_commit,
610 .mode_set = intel_crt_mode_set, 673 .mode_set = intel_crt_mode_set,
611 .dpms = pch_crt_dpms, 674 .disable = intel_encoder_noop,
612};
613
614static const struct drm_encoder_helper_funcs gmch_encoder_funcs = {
615 .mode_fixup = intel_crt_mode_fixup,
616 .prepare = intel_encoder_prepare,
617 .commit = intel_encoder_commit,
618 .mode_set = intel_crt_mode_set,
619 .dpms = gmch_crt_dpms,
620}; 675};
621 676
622static const struct drm_connector_funcs intel_crt_connector_funcs = { 677static const struct drm_connector_funcs intel_crt_connector_funcs = {
623 .reset = intel_crt_reset, 678 .reset = intel_crt_reset,
624 .dpms = drm_helper_connector_dpms, 679 .dpms = intel_crt_dpms,
625 .detect = intel_crt_detect, 680 .detect = intel_crt_detect,
626 .fill_modes = drm_helper_probe_single_connector_modes, 681 .fill_modes = drm_helper_probe_single_connector_modes,
627 .destroy = intel_crt_destroy, 682 .destroy = intel_crt_destroy,
@@ -662,7 +717,6 @@ void intel_crt_init(struct drm_device *dev)
662 struct intel_crt *crt; 717 struct intel_crt *crt;
663 struct intel_connector *intel_connector; 718 struct intel_connector *intel_connector;
664 struct drm_i915_private *dev_priv = dev->dev_private; 719 struct drm_i915_private *dev_priv = dev->dev_private;
665 const struct drm_encoder_helper_funcs *encoder_helper_funcs;
666 720
667 /* Skip machines without VGA that falsely report hotplug events */ 721 /* Skip machines without VGA that falsely report hotplug events */
668 if (dmi_check_system(intel_no_crt)) 722 if (dmi_check_system(intel_no_crt))
@@ -701,18 +755,18 @@ void intel_crt_init(struct drm_device *dev)
701 connector->doublescan_allowed = 0; 755 connector->doublescan_allowed = 0;
702 756
703 if (HAS_PCH_SPLIT(dev)) 757 if (HAS_PCH_SPLIT(dev))
704 encoder_helper_funcs = &pch_encoder_funcs;
705 else
706 encoder_helper_funcs = &gmch_encoder_funcs;
707
708 if (HAS_PCH_SPLIT(dev))
709 crt->adpa_reg = PCH_ADPA; 758 crt->adpa_reg = PCH_ADPA;
710 else if (IS_VALLEYVIEW(dev)) 759 else if (IS_VALLEYVIEW(dev))
711 crt->adpa_reg = VLV_ADPA; 760 crt->adpa_reg = VLV_ADPA;
712 else 761 else
713 crt->adpa_reg = ADPA; 762 crt->adpa_reg = ADPA;
714 763
715 drm_encoder_helper_add(&crt->base.base, encoder_helper_funcs); 764 crt->base.disable = intel_disable_crt;
765 crt->base.enable = intel_enable_crt;
766 crt->base.get_hw_state = intel_crt_get_hw_state;
767 intel_connector->get_hw_state = intel_connector_get_hw_state;
768
769 drm_encoder_helper_add(&crt->base.base, &crt_encoder_funcs);
716 drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs); 770 drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
717 771
718 drm_sysfs_connector_add(connector); 772 drm_sysfs_connector_add(connector);
diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
index 170e3861aa4e..bfe375466a0e 100644
--- a/drivers/gpu/drm/i915/intel_ddi.c
+++ b/drivers/gpu/drm/i915/intel_ddi.c
@@ -757,26 +757,63 @@ void intel_ddi_mode_set(struct drm_encoder *encoder,
757 intel_hdmi->set_infoframes(encoder, adjusted_mode); 757 intel_hdmi->set_infoframes(encoder, adjusted_mode);
758} 758}
759 759
760void intel_ddi_dpms(struct drm_encoder *encoder, int mode) 760bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
761 enum pipe *pipe)
761{ 762{
762 struct drm_device *dev = encoder->dev; 763 struct drm_device *dev = encoder->base.dev;
763 struct drm_i915_private *dev_priv = dev->dev_private; 764 struct drm_i915_private *dev_priv = dev->dev_private;
764 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 765 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
766 u32 tmp;
767 int i;
768
769 tmp = I915_READ(DDI_BUF_CTL(intel_hdmi->ddi_port));
770
771 if (!(tmp & DDI_BUF_CTL_ENABLE))
772 return false;
773
774 for_each_pipe(i) {
775 tmp = I915_READ(DDI_FUNC_CTL(i));
776
777 if ((tmp & PIPE_DDI_PORT_MASK)
778 == PIPE_DDI_SELECT_PORT(intel_hdmi->ddi_port)) {
779 *pipe = i;
780 return true;
781 }
782 }
783
784 DRM_DEBUG_KMS("No pipe for ddi port %i found\n", intel_hdmi->ddi_port);
785
786 return true;
787}
788
789void intel_enable_ddi(struct intel_encoder *encoder)
790{
791 struct drm_device *dev = encoder->base.dev;
792 struct drm_i915_private *dev_priv = dev->dev_private;
793 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
765 int port = intel_hdmi->ddi_port; 794 int port = intel_hdmi->ddi_port;
766 u32 temp; 795 u32 temp;
767 796
768 temp = I915_READ(DDI_BUF_CTL(port)); 797 temp = I915_READ(DDI_BUF_CTL(port));
769 798 temp |= DDI_BUF_CTL_ENABLE;
770 if (mode != DRM_MODE_DPMS_ON) {
771 temp &= ~DDI_BUF_CTL_ENABLE;
772 } else {
773 temp |= DDI_BUF_CTL_ENABLE;
774 }
775 799
776 /* Enable DDI_BUF_CTL. In HDMI/DVI mode, the port width, 800 /* Enable DDI_BUF_CTL. In HDMI/DVI mode, the port width,
777 * and swing/emphasis values are ignored so nothing special needs 801 * and swing/emphasis values are ignored so nothing special needs
778 * to be done besides enabling the port. 802 * to be done besides enabling the port.
779 */ 803 */
780 I915_WRITE(DDI_BUF_CTL(port), 804 I915_WRITE(DDI_BUF_CTL(port), temp);
781 temp); 805}
806
807void intel_disable_ddi(struct intel_encoder *encoder)
808{
809 struct drm_device *dev = encoder->base.dev;
810 struct drm_i915_private *dev_priv = dev->dev_private;
811 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
812 int port = intel_hdmi->ddi_port;
813 u32 temp;
814
815 temp = I915_READ(DDI_BUF_CTL(port));
816 temp &= ~DDI_BUF_CTL_ENABLE;
817
818 I915_WRITE(DDI_BUF_CTL(port), temp);
782} 819}
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 778cbb88bddc..5576b7c695ed 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -1006,7 +1006,7 @@ void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
1006 /* Wait for the Pipe State to go off */ 1006 /* Wait for the Pipe State to go off */
1007 if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, 1007 if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
1008 100)) 1008 100))
1009 DRM_DEBUG_KMS("pipe_off wait timed out\n"); 1009 WARN(1, "pipe_off wait timed out\n");
1010 } else { 1010 } else {
1011 u32 last_line, line_mask; 1011 u32 last_line, line_mask;
1012 int reg = PIPEDSL(pipe); 1012 int reg = PIPEDSL(pipe);
@@ -1024,7 +1024,7 @@ void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
1024 } while (((I915_READ(reg) & line_mask) != last_line) && 1024 } while (((I915_READ(reg) & line_mask) != last_line) &&
1025 time_after(timeout, jiffies)); 1025 time_after(timeout, jiffies));
1026 if (time_after(jiffies, timeout)) 1026 if (time_after(jiffies, timeout))
1027 DRM_DEBUG_KMS("pipe_off wait timed out\n"); 1027 WARN(1, "pipe_off wait timed out\n");
1028 } 1028 }
1029} 1029}
1030 1030
@@ -2201,16 +2201,17 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
2201 2201
2202static int 2202static int
2203intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, 2203intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
2204 struct drm_framebuffer *old_fb) 2204 struct drm_framebuffer *fb)
2205{ 2205{
2206 struct drm_device *dev = crtc->dev; 2206 struct drm_device *dev = crtc->dev;
2207 struct drm_i915_private *dev_priv = dev->dev_private; 2207 struct drm_i915_private *dev_priv = dev->dev_private;
2208 struct drm_i915_master_private *master_priv; 2208 struct drm_i915_master_private *master_priv;
2209 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 2209 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2210 struct drm_framebuffer *old_fb;
2210 int ret; 2211 int ret;
2211 2212
2212 /* no fb bound */ 2213 /* no fb bound */
2213 if (!crtc->fb) { 2214 if (!fb) {
2214 DRM_ERROR("No FB bound\n"); 2215 DRM_ERROR("No FB bound\n");
2215 return 0; 2216 return 0;
2216 } 2217 }
@@ -2224,7 +2225,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
2224 2225
2225 mutex_lock(&dev->struct_mutex); 2226 mutex_lock(&dev->struct_mutex);
2226 ret = intel_pin_and_fence_fb_obj(dev, 2227 ret = intel_pin_and_fence_fb_obj(dev,
2227 to_intel_framebuffer(crtc->fb)->obj, 2228 to_intel_framebuffer(fb)->obj,
2228 NULL); 2229 NULL);
2229 if (ret != 0) { 2230 if (ret != 0) {
2230 mutex_unlock(&dev->struct_mutex); 2231 mutex_unlock(&dev->struct_mutex);
@@ -2232,17 +2233,22 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
2232 return ret; 2233 return ret;
2233 } 2234 }
2234 2235
2235 if (old_fb) 2236 if (crtc->fb)
2236 intel_finish_fb(old_fb); 2237 intel_finish_fb(crtc->fb);
2237 2238
2238 ret = dev_priv->display.update_plane(crtc, crtc->fb, x, y); 2239 ret = dev_priv->display.update_plane(crtc, fb, x, y);
2239 if (ret) { 2240 if (ret) {
2240 intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj); 2241 intel_unpin_fb_obj(to_intel_framebuffer(fb)->obj);
2241 mutex_unlock(&dev->struct_mutex); 2242 mutex_unlock(&dev->struct_mutex);
2242 DRM_ERROR("failed to update base address\n"); 2243 DRM_ERROR("failed to update base address\n");
2243 return ret; 2244 return ret;
2244 } 2245 }
2245 2246
2247 old_fb = crtc->fb;
2248 crtc->fb = fb;
2249 crtc->x = x;
2250 crtc->y = y;
2251
2246 if (old_fb) { 2252 if (old_fb) {
2247 intel_wait_for_vblank(dev, intel_crtc->pipe); 2253 intel_wait_for_vblank(dev, intel_crtc->pipe);
2248 intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj); 2254 intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj);
@@ -3209,11 +3215,14 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
3209 struct drm_device *dev = crtc->dev; 3215 struct drm_device *dev = crtc->dev;
3210 struct drm_i915_private *dev_priv = dev->dev_private; 3216 struct drm_i915_private *dev_priv = dev->dev_private;
3211 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 3217 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3218 struct intel_encoder *encoder;
3212 int pipe = intel_crtc->pipe; 3219 int pipe = intel_crtc->pipe;
3213 int plane = intel_crtc->plane; 3220 int plane = intel_crtc->plane;
3214 u32 temp; 3221 u32 temp;
3215 bool is_pch_port; 3222 bool is_pch_port;
3216 3223
3224 WARN_ON(!crtc->enabled);
3225
3217 if (intel_crtc->active) 3226 if (intel_crtc->active)
3218 return; 3227 return;
3219 3228
@@ -3262,6 +3271,12 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
3262 mutex_unlock(&dev->struct_mutex); 3271 mutex_unlock(&dev->struct_mutex);
3263 3272
3264 intel_crtc_update_cursor(crtc, true); 3273 intel_crtc_update_cursor(crtc, true);
3274
3275 for_each_encoder_on_crtc(dev, crtc, encoder)
3276 encoder->enable(encoder);
3277
3278 if (HAS_PCH_CPT(dev))
3279 intel_cpt_verify_modeset(dev, intel_crtc->pipe);
3265} 3280}
3266 3281
3267static void ironlake_crtc_disable(struct drm_crtc *crtc) 3282static void ironlake_crtc_disable(struct drm_crtc *crtc)
@@ -3269,13 +3284,18 @@ static void ironlake_crtc_disable(struct drm_crtc *crtc)
3269 struct drm_device *dev = crtc->dev; 3284 struct drm_device *dev = crtc->dev;
3270 struct drm_i915_private *dev_priv = dev->dev_private; 3285 struct drm_i915_private *dev_priv = dev->dev_private;
3271 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 3286 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3287 struct intel_encoder *encoder;
3272 int pipe = intel_crtc->pipe; 3288 int pipe = intel_crtc->pipe;
3273 int plane = intel_crtc->plane; 3289 int plane = intel_crtc->plane;
3274 u32 reg, temp; 3290 u32 reg, temp;
3275 3291
3292
3276 if (!intel_crtc->active) 3293 if (!intel_crtc->active)
3277 return; 3294 return;
3278 3295
3296 for_each_encoder_on_crtc(dev, crtc, encoder)
3297 encoder->disable(encoder);
3298
3279 intel_crtc_wait_for_pending_flips(crtc); 3299 intel_crtc_wait_for_pending_flips(crtc);
3280 drm_vblank_off(dev, pipe); 3300 drm_vblank_off(dev, pipe);
3281 intel_crtc_update_cursor(crtc, false); 3301 intel_crtc_update_cursor(crtc, false);
@@ -3342,30 +3362,6 @@ static void ironlake_crtc_disable(struct drm_crtc *crtc)
3342 mutex_unlock(&dev->struct_mutex); 3362 mutex_unlock(&dev->struct_mutex);
3343} 3363}
3344 3364
3345static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode)
3346{
3347 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3348 int pipe = intel_crtc->pipe;
3349 int plane = intel_crtc->plane;
3350
3351 /* XXX: When our outputs are all unaware of DPMS modes other than off
3352 * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
3353 */
3354 switch (mode) {
3355 case DRM_MODE_DPMS_ON:
3356 case DRM_MODE_DPMS_STANDBY:
3357 case DRM_MODE_DPMS_SUSPEND:
3358 DRM_DEBUG_KMS("crtc %d/%d dpms on\n", pipe, plane);
3359 ironlake_crtc_enable(crtc);
3360 break;
3361
3362 case DRM_MODE_DPMS_OFF:
3363 DRM_DEBUG_KMS("crtc %d/%d dpms off\n", pipe, plane);
3364 ironlake_crtc_disable(crtc);
3365 break;
3366 }
3367}
3368
3369static void ironlake_crtc_off(struct drm_crtc *crtc) 3365static void ironlake_crtc_off(struct drm_crtc *crtc)
3370{ 3366{
3371 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 3367 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
@@ -3395,9 +3391,12 @@ static void i9xx_crtc_enable(struct drm_crtc *crtc)
3395 struct drm_device *dev = crtc->dev; 3391 struct drm_device *dev = crtc->dev;
3396 struct drm_i915_private *dev_priv = dev->dev_private; 3392 struct drm_i915_private *dev_priv = dev->dev_private;
3397 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 3393 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3394 struct intel_encoder *encoder;
3398 int pipe = intel_crtc->pipe; 3395 int pipe = intel_crtc->pipe;
3399 int plane = intel_crtc->plane; 3396 int plane = intel_crtc->plane;
3400 3397
3398 WARN_ON(!crtc->enabled);
3399
3401 if (intel_crtc->active) 3400 if (intel_crtc->active)
3402 return; 3401 return;
3403 3402
@@ -3414,6 +3413,9 @@ static void i9xx_crtc_enable(struct drm_crtc *crtc)
3414 /* Give the overlay scaler a chance to enable if it's on this pipe */ 3413 /* Give the overlay scaler a chance to enable if it's on this pipe */
3415 intel_crtc_dpms_overlay(intel_crtc, true); 3414 intel_crtc_dpms_overlay(intel_crtc, true);
3416 intel_crtc_update_cursor(crtc, true); 3415 intel_crtc_update_cursor(crtc, true);
3416
3417 for_each_encoder_on_crtc(dev, crtc, encoder)
3418 encoder->enable(encoder);
3417} 3419}
3418 3420
3419static void i9xx_crtc_disable(struct drm_crtc *crtc) 3421static void i9xx_crtc_disable(struct drm_crtc *crtc)
@@ -3421,12 +3423,17 @@ static void i9xx_crtc_disable(struct drm_crtc *crtc)
3421 struct drm_device *dev = crtc->dev; 3423 struct drm_device *dev = crtc->dev;
3422 struct drm_i915_private *dev_priv = dev->dev_private; 3424 struct drm_i915_private *dev_priv = dev->dev_private;
3423 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 3425 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3426 struct intel_encoder *encoder;
3424 int pipe = intel_crtc->pipe; 3427 int pipe = intel_crtc->pipe;
3425 int plane = intel_crtc->plane; 3428 int plane = intel_crtc->plane;
3426 3429
3430
3427 if (!intel_crtc->active) 3431 if (!intel_crtc->active)
3428 return; 3432 return;
3429 3433
3434 for_each_encoder_on_crtc(dev, crtc, encoder)
3435 encoder->disable(encoder);
3436
3430 /* Give the overlay scaler a chance to disable if it's on this pipe */ 3437 /* Give the overlay scaler a chance to disable if it's on this pipe */
3431 intel_crtc_wait_for_pending_flips(crtc); 3438 intel_crtc_wait_for_pending_flips(crtc);
3432 drm_vblank_off(dev, pipe); 3439 drm_vblank_off(dev, pipe);
@@ -3445,45 +3452,17 @@ static void i9xx_crtc_disable(struct drm_crtc *crtc)
3445 intel_update_watermarks(dev); 3452 intel_update_watermarks(dev);
3446} 3453}
3447 3454
3448static void i9xx_crtc_dpms(struct drm_crtc *crtc, int mode)
3449{
3450 /* XXX: When our outputs are all unaware of DPMS modes other than off
3451 * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
3452 */
3453 switch (mode) {
3454 case DRM_MODE_DPMS_ON:
3455 case DRM_MODE_DPMS_STANDBY:
3456 case DRM_MODE_DPMS_SUSPEND:
3457 i9xx_crtc_enable(crtc);
3458 break;
3459 case DRM_MODE_DPMS_OFF:
3460 i9xx_crtc_disable(crtc);
3461 break;
3462 }
3463}
3464
3465static void i9xx_crtc_off(struct drm_crtc *crtc) 3455static void i9xx_crtc_off(struct drm_crtc *crtc)
3466{ 3456{
3467} 3457}
3468 3458
3469/** 3459static void intel_crtc_update_sarea(struct drm_crtc *crtc,
3470 * Sets the power management mode of the pipe and plane. 3460 bool enabled)
3471 */
3472static void intel_crtc_dpms(struct drm_crtc *crtc, int mode)
3473{ 3461{
3474 struct drm_device *dev = crtc->dev; 3462 struct drm_device *dev = crtc->dev;
3475 struct drm_i915_private *dev_priv = dev->dev_private;
3476 struct drm_i915_master_private *master_priv; 3463 struct drm_i915_master_private *master_priv;
3477 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 3464 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3478 int pipe = intel_crtc->pipe; 3465 int pipe = intel_crtc->pipe;
3479 bool enabled;
3480
3481 if (intel_crtc->dpms_mode == mode)
3482 return;
3483
3484 intel_crtc->dpms_mode = mode;
3485
3486 dev_priv->display.dpms(crtc, mode);
3487 3466
3488 if (!dev->primary->master) 3467 if (!dev->primary->master)
3489 return; 3468 return;
@@ -3492,8 +3471,6 @@ static void intel_crtc_dpms(struct drm_crtc *crtc, int mode)
3492 if (!master_priv->sarea_priv) 3471 if (!master_priv->sarea_priv)
3493 return; 3472 return;
3494 3473
3495 enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF;
3496
3497 switch (pipe) { 3474 switch (pipe) {
3498 case 0: 3475 case 0:
3499 master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0; 3476 master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
@@ -3509,13 +3486,42 @@ static void intel_crtc_dpms(struct drm_crtc *crtc, int mode)
3509 } 3486 }
3510} 3487}
3511 3488
3489/**
3490 * Sets the power management mode of the pipe and plane.
3491 */
3492void intel_crtc_update_dpms(struct drm_crtc *crtc)
3493{
3494 struct drm_device *dev = crtc->dev;
3495 struct drm_i915_private *dev_priv = dev->dev_private;
3496 struct intel_encoder *intel_encoder;
3497 bool enable = false;
3498
3499 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
3500 enable |= intel_encoder->connectors_active;
3501
3502 if (enable)
3503 dev_priv->display.crtc_enable(crtc);
3504 else
3505 dev_priv->display.crtc_disable(crtc);
3506
3507 intel_crtc_update_sarea(crtc, enable);
3508}
3509
3510static void intel_crtc_noop(struct drm_crtc *crtc)
3511{
3512}
3513
3512static void intel_crtc_disable(struct drm_crtc *crtc) 3514static void intel_crtc_disable(struct drm_crtc *crtc)
3513{ 3515{
3514 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
3515 struct drm_device *dev = crtc->dev; 3516 struct drm_device *dev = crtc->dev;
3517 struct drm_connector *connector;
3516 struct drm_i915_private *dev_priv = dev->dev_private; 3518 struct drm_i915_private *dev_priv = dev->dev_private;
3517 3519
3518 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF); 3520 /* crtc should still be enabled when we disable it. */
3521 WARN_ON(!crtc->enabled);
3522
3523 dev_priv->display.crtc_disable(crtc);
3524 intel_crtc_update_sarea(crtc, false);
3519 dev_priv->display.off(crtc); 3525 dev_priv->display.off(crtc);
3520 3526
3521 assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane); 3527 assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
@@ -3525,63 +3531,128 @@ static void intel_crtc_disable(struct drm_crtc *crtc)
3525 mutex_lock(&dev->struct_mutex); 3531 mutex_lock(&dev->struct_mutex);
3526 intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj); 3532 intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj);
3527 mutex_unlock(&dev->struct_mutex); 3533 mutex_unlock(&dev->struct_mutex);
3534 crtc->fb = NULL;
3535 }
3536
3537 /* Update computed state. */
3538 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3539 if (!connector->encoder || !connector->encoder->crtc)
3540 continue;
3541
3542 if (connector->encoder->crtc != crtc)
3543 continue;
3544
3545 connector->dpms = DRM_MODE_DPMS_OFF;
3546 to_intel_encoder(connector->encoder)->connectors_active = false;
3528 } 3547 }
3529} 3548}
3530 3549
3531/* Prepare for a mode set. 3550void intel_modeset_disable(struct drm_device *dev)
3532 *
3533 * Note we could be a lot smarter here. We need to figure out which outputs
3534 * will be enabled, which disabled (in short, how the config will changes)
3535 * and perform the minimum necessary steps to accomplish that, e.g. updating
3536 * watermarks, FBC configuration, making sure PLLs are programmed correctly,
3537 * panel fitting is in the proper state, etc.
3538 */
3539static void i9xx_crtc_prepare(struct drm_crtc *crtc)
3540{ 3551{
3541 i9xx_crtc_disable(crtc); 3552 struct drm_crtc *crtc;
3553
3554 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
3555 if (crtc->enabled)
3556 intel_crtc_disable(crtc);
3557 }
3542} 3558}
3543 3559
3544static void i9xx_crtc_commit(struct drm_crtc *crtc) 3560void intel_encoder_noop(struct drm_encoder *encoder)
3545{ 3561{
3546 i9xx_crtc_enable(crtc);
3547} 3562}
3548 3563
3549static void ironlake_crtc_prepare(struct drm_crtc *crtc) 3564void intel_encoder_destroy(struct drm_encoder *encoder)
3550{ 3565{
3551 ironlake_crtc_disable(crtc); 3566 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
3567
3568 drm_encoder_cleanup(encoder);
3569 kfree(intel_encoder);
3552} 3570}
3553 3571
3554static void ironlake_crtc_commit(struct drm_crtc *crtc) 3572/* Simple dpms helper for encodres with just one connector, no cloning and only
3573 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
3574 * state of the entire output pipe. */
3575void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
3555{ 3576{
3556 ironlake_crtc_enable(crtc); 3577 if (mode == DRM_MODE_DPMS_ON) {
3578 encoder->connectors_active = true;
3579
3580 intel_crtc_update_dpms(encoder->base.crtc);
3581 } else {
3582 encoder->connectors_active = false;
3583
3584 intel_crtc_update_dpms(encoder->base.crtc);
3585 }
3557} 3586}
3558 3587
3559void intel_encoder_prepare(struct drm_encoder *encoder) 3588/* Cross check the actual hw state with our own modeset state tracking (and it's
3589 * internal consistency). */
3590static void intel_connector_check_state(struct intel_connector *connector)
3560{ 3591{
3561 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; 3592 if (connector->get_hw_state(connector)) {
3562 /* lvds has its own version of prepare see intel_lvds_prepare */ 3593 struct intel_encoder *encoder = connector->encoder;
3563 encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF); 3594 struct drm_crtc *crtc;
3595 bool encoder_enabled;
3596 enum pipe pipe;
3597
3598 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
3599 connector->base.base.id,
3600 drm_get_connector_name(&connector->base));
3601
3602 WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
3603 "wrong connector dpms state\n");
3604 WARN(connector->base.encoder != &encoder->base,
3605 "active connector not linked to encoder\n");
3606 WARN(!encoder->connectors_active,
3607 "encoder->connectors_active not set\n");
3608
3609 encoder_enabled = encoder->get_hw_state(encoder, &pipe);
3610 WARN(!encoder_enabled, "encoder not enabled\n");
3611 if (WARN_ON(!encoder->base.crtc))
3612 return;
3613
3614 crtc = encoder->base.crtc;
3615
3616 WARN(!crtc->enabled, "crtc not enabled\n");
3617 WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
3618 WARN(pipe != to_intel_crtc(crtc)->pipe,
3619 "encoder active on the wrong pipe\n");
3620 }
3564} 3621}
3565 3622
3566void intel_encoder_commit(struct drm_encoder *encoder) 3623/* Even simpler default implementation, if there's really no special case to
3624 * consider. */
3625void intel_connector_dpms(struct drm_connector *connector, int mode)
3567{ 3626{
3568 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; 3627 struct intel_encoder *encoder = intel_attached_encoder(connector);
3569 struct drm_device *dev = encoder->dev;
3570 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
3571 3628
3572 /* lvds has its own version of commit see intel_lvds_commit */ 3629 /* All the simple cases only support two dpms states. */
3573 encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON); 3630 if (mode != DRM_MODE_DPMS_ON)
3631 mode = DRM_MODE_DPMS_OFF;
3574 3632
3575 if (HAS_PCH_CPT(dev)) 3633 if (mode == connector->dpms)
3576 intel_cpt_verify_modeset(dev, intel_crtc->pipe); 3634 return;
3635
3636 connector->dpms = mode;
3637
3638 /* Only need to change hw state when actually enabled */
3639 if (encoder->base.crtc)
3640 intel_encoder_dpms(encoder, mode);
3641 else
3642 WARN_ON(encoder->connectors_active != false);
3643
3644 intel_modeset_check_state(connector->dev);
3577} 3645}
3578 3646
3579void intel_encoder_destroy(struct drm_encoder *encoder) 3647/* Simple connector->get_hw_state implementation for encoders that support only
3648 * one connector and no cloning and hence the encoder state determines the state
3649 * of the connector. */
3650bool intel_connector_get_hw_state(struct intel_connector *connector)
3580{ 3651{
3581 struct intel_encoder *intel_encoder = to_intel_encoder(encoder); 3652 enum pipe pipe = 0;
3653 struct intel_encoder *encoder = connector->encoder;
3582 3654
3583 drm_encoder_cleanup(encoder); 3655 return encoder->get_hw_state(encoder, &pipe);
3584 kfree(intel_encoder);
3585} 3656}
3586 3657
3587static bool intel_crtc_mode_fixup(struct drm_crtc *crtc, 3658static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
@@ -3744,6 +3815,7 @@ static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
3744 * true if they don't match). 3815 * true if they don't match).
3745 */ 3816 */
3746static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc, 3817static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
3818 struct drm_framebuffer *fb,
3747 unsigned int *pipe_bpp, 3819 unsigned int *pipe_bpp,
3748 struct drm_display_mode *mode) 3820 struct drm_display_mode *mode)
3749{ 3821{
@@ -3813,7 +3885,7 @@ static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
3813 * also stays within the max display bpc discovered above. 3885 * also stays within the max display bpc discovered above.
3814 */ 3886 */
3815 3887
3816 switch (crtc->fb->depth) { 3888 switch (fb->depth) {
3817 case 8: 3889 case 8:
3818 bpc = 8; /* since we go through a colormap */ 3890 bpc = 8; /* since we go through a colormap */
3819 break; 3891 break;
@@ -4232,7 +4304,7 @@ static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
4232 struct drm_display_mode *mode, 4304 struct drm_display_mode *mode,
4233 struct drm_display_mode *adjusted_mode, 4305 struct drm_display_mode *adjusted_mode,
4234 int x, int y, 4306 int x, int y,
4235 struct drm_framebuffer *old_fb) 4307 struct drm_framebuffer *fb)
4236{ 4308{
4237 struct drm_device *dev = crtc->dev; 4309 struct drm_device *dev = crtc->dev;
4238 struct drm_i915_private *dev_priv = dev->dev_private; 4310 struct drm_i915_private *dev_priv = dev->dev_private;
@@ -4422,7 +4494,7 @@ static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
4422 I915_WRITE(DSPCNTR(plane), dspcntr); 4494 I915_WRITE(DSPCNTR(plane), dspcntr);
4423 POSTING_READ(DSPCNTR(plane)); 4495 POSTING_READ(DSPCNTR(plane));
4424 4496
4425 ret = intel_pipe_set_base(crtc, x, y, old_fb); 4497 ret = intel_pipe_set_base(crtc, x, y, fb);
4426 4498
4427 intel_update_watermarks(dev); 4499 intel_update_watermarks(dev);
4428 4500
@@ -4580,7 +4652,7 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
4580 struct drm_display_mode *mode, 4652 struct drm_display_mode *mode,
4581 struct drm_display_mode *adjusted_mode, 4653 struct drm_display_mode *adjusted_mode,
4582 int x, int y, 4654 int x, int y,
4583 struct drm_framebuffer *old_fb) 4655 struct drm_framebuffer *fb)
4584{ 4656{
4585 struct drm_device *dev = crtc->dev; 4657 struct drm_device *dev = crtc->dev;
4586 struct drm_i915_private *dev_priv = dev->dev_private; 4658 struct drm_i915_private *dev_priv = dev->dev_private;
@@ -4700,7 +4772,7 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
4700 /* determine panel color depth */ 4772 /* determine panel color depth */
4701 temp = I915_READ(PIPECONF(pipe)); 4773 temp = I915_READ(PIPECONF(pipe));
4702 temp &= ~PIPE_BPC_MASK; 4774 temp &= ~PIPE_BPC_MASK;
4703 dither = intel_choose_pipe_bpp_dither(crtc, &pipe_bpp, mode); 4775 dither = intel_choose_pipe_bpp_dither(crtc, fb, &pipe_bpp, mode);
4704 switch (pipe_bpp) { 4776 switch (pipe_bpp) {
4705 case 18: 4777 case 18:
4706 temp |= PIPE_6BPC; 4778 temp |= PIPE_6BPC;
@@ -4969,7 +5041,7 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
4969 I915_WRITE(DSPCNTR(plane), dspcntr); 5041 I915_WRITE(DSPCNTR(plane), dspcntr);
4970 POSTING_READ(DSPCNTR(plane)); 5042 POSTING_READ(DSPCNTR(plane));
4971 5043
4972 ret = intel_pipe_set_base(crtc, x, y, old_fb); 5044 ret = intel_pipe_set_base(crtc, x, y, fb);
4973 5045
4974 intel_update_watermarks(dev); 5046 intel_update_watermarks(dev);
4975 5047
@@ -4982,7 +5054,7 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
4982 struct drm_display_mode *mode, 5054 struct drm_display_mode *mode,
4983 struct drm_display_mode *adjusted_mode, 5055 struct drm_display_mode *adjusted_mode,
4984 int x, int y, 5056 int x, int y,
4985 struct drm_framebuffer *old_fb) 5057 struct drm_framebuffer *fb)
4986{ 5058{
4987 struct drm_device *dev = crtc->dev; 5059 struct drm_device *dev = crtc->dev;
4988 struct drm_i915_private *dev_priv = dev->dev_private; 5060 struct drm_i915_private *dev_priv = dev->dev_private;
@@ -4993,14 +5065,9 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
4993 drm_vblank_pre_modeset(dev, pipe); 5065 drm_vblank_pre_modeset(dev, pipe);
4994 5066
4995 ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode, 5067 ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode,
4996 x, y, old_fb); 5068 x, y, fb);
4997 drm_vblank_post_modeset(dev, pipe); 5069 drm_vblank_post_modeset(dev, pipe);
4998 5070
4999 if (ret)
5000 intel_crtc->dpms_mode = DRM_MODE_DPMS_OFF;
5001 else
5002 intel_crtc->dpms_mode = DRM_MODE_DPMS_ON;
5003
5004 return ret; 5071 return ret;
5005} 5072}
5006 5073
@@ -5434,8 +5501,6 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc,
5434 uint32_t addr; 5501 uint32_t addr;
5435 int ret; 5502 int ret;
5436 5503
5437 DRM_DEBUG_KMS("\n");
5438
5439 /* if we want to turn off the cursor ignore width and height */ 5504 /* if we want to turn off the cursor ignore width and height */
5440 if (!handle) { 5505 if (!handle) {
5441 DRM_DEBUG_KMS("cursor off\n"); 5506 DRM_DEBUG_KMS("cursor off\n");
@@ -5692,7 +5757,7 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector,
5692 struct drm_encoder *encoder = &intel_encoder->base; 5757 struct drm_encoder *encoder = &intel_encoder->base;
5693 struct drm_crtc *crtc = NULL; 5758 struct drm_crtc *crtc = NULL;
5694 struct drm_device *dev = encoder->dev; 5759 struct drm_device *dev = encoder->dev;
5695 struct drm_framebuffer *old_fb; 5760 struct drm_framebuffer *fb;
5696 int i = -1; 5761 int i = -1;
5697 5762
5698 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", 5763 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
@@ -5742,8 +5807,8 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector,
5742 return false; 5807 return false;
5743 } 5808 }
5744 5809
5745 encoder->crtc = crtc; 5810 intel_encoder->new_crtc = to_intel_crtc(crtc);
5746 connector->encoder = encoder; 5811 to_intel_connector(connector)->new_encoder = intel_encoder;
5747 5812
5748 intel_crtc = to_intel_crtc(crtc); 5813 intel_crtc = to_intel_crtc(crtc);
5749 old->dpms_mode = connector->dpms; 5814 old->dpms_mode = connector->dpms;
@@ -5753,8 +5818,6 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector,
5753 if (!mode) 5818 if (!mode)
5754 mode = &load_detect_mode; 5819 mode = &load_detect_mode;
5755 5820
5756 old_fb = crtc->fb;
5757
5758 /* We need a framebuffer large enough to accommodate all accesses 5821 /* We need a framebuffer large enough to accommodate all accesses
5759 * that the plane may generate whilst we perform load detection. 5822 * that the plane may generate whilst we perform load detection.
5760 * We can not rely on the fbcon either being present (we get called 5823 * We can not rely on the fbcon either being present (we get called
@@ -5762,19 +5825,19 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector,
5762 * not even exist) or that it is large enough to satisfy the 5825 * not even exist) or that it is large enough to satisfy the
5763 * requested mode. 5826 * requested mode.
5764 */ 5827 */
5765 crtc->fb = mode_fits_in_fbdev(dev, mode); 5828 fb = mode_fits_in_fbdev(dev, mode);
5766 if (crtc->fb == NULL) { 5829 if (fb == NULL) {
5767 DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); 5830 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
5768 crtc->fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); 5831 fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
5769 old->release_fb = crtc->fb; 5832 old->release_fb = fb;
5770 } else 5833 } else
5771 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); 5834 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
5772 if (IS_ERR(crtc->fb)) { 5835 if (IS_ERR(fb)) {
5773 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); 5836 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
5774 goto fail; 5837 goto fail;
5775 } 5838 }
5776 5839
5777 if (!drm_crtc_helper_set_mode(crtc, mode, 0, 0, old_fb)) { 5840 if (!intel_set_mode(crtc, mode, 0, 0, fb)) {
5778 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); 5841 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
5779 if (old->release_fb) 5842 if (old->release_fb)
5780 old->release_fb->funcs->destroy(old->release_fb); 5843 old->release_fb->funcs->destroy(old->release_fb);
@@ -5788,7 +5851,6 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector,
5788fail: 5851fail:
5789 connector->encoder = NULL; 5852 connector->encoder = NULL;
5790 encoder->crtc = NULL; 5853 encoder->crtc = NULL;
5791 crtc->fb = old_fb;
5792 return false; 5854 return false;
5793} 5855}
5794 5856
@@ -5798,16 +5860,17 @@ void intel_release_load_detect_pipe(struct drm_connector *connector,
5798 struct intel_encoder *intel_encoder = 5860 struct intel_encoder *intel_encoder =
5799 intel_attached_encoder(connector); 5861 intel_attached_encoder(connector);
5800 struct drm_encoder *encoder = &intel_encoder->base; 5862 struct drm_encoder *encoder = &intel_encoder->base;
5801 struct drm_device *dev = encoder->dev;
5802 5863
5803 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", 5864 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
5804 connector->base.id, drm_get_connector_name(connector), 5865 connector->base.id, drm_get_connector_name(connector),
5805 encoder->base.id, drm_get_encoder_name(encoder)); 5866 encoder->base.id, drm_get_encoder_name(encoder));
5806 5867
5807 if (old->load_detect_temp) { 5868 if (old->load_detect_temp) {
5808 connector->encoder = NULL; 5869 struct drm_crtc *crtc = encoder->crtc;
5809 encoder->crtc = NULL; 5870
5810 drm_helper_disable_unused_functions(dev); 5871 to_intel_connector(connector)->new_encoder = NULL;
5872 intel_encoder->new_crtc = NULL;
5873 intel_set_mode(crtc, NULL, 0, 0, NULL);
5811 5874
5812 if (old->release_fb) 5875 if (old->release_fb)
5813 old->release_fb->funcs->destroy(old->release_fb); 5876 old->release_fb->funcs->destroy(old->release_fb);
@@ -6529,81 +6592,811 @@ free_work:
6529 return ret; 6592 return ret;
6530} 6593}
6531 6594
6532static void intel_sanitize_modesetting(struct drm_device *dev, 6595static struct drm_crtc_helper_funcs intel_helper_funcs = {
6533 int pipe, int plane) 6596 .mode_set_base_atomic = intel_pipe_set_base_atomic,
6597 .load_lut = intel_crtc_load_lut,
6598 .disable = intel_crtc_noop,
6599};
6600
6601bool intel_encoder_check_is_cloned(struct intel_encoder *encoder)
6534{ 6602{
6535 struct drm_i915_private *dev_priv = dev->dev_private; 6603 struct intel_encoder *other_encoder;
6536 u32 reg, val; 6604 struct drm_crtc *crtc = &encoder->new_crtc->base;
6537 int i;
6538 6605
6539 /* Clear any frame start delays used for debugging left by the BIOS */ 6606 if (WARN_ON(!crtc))
6540 for_each_pipe(i) { 6607 return false;
6541 reg = PIPECONF(i); 6608
6542 I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); 6609 list_for_each_entry(other_encoder,
6610 &crtc->dev->mode_config.encoder_list,
6611 base.head) {
6612
6613 if (&other_encoder->new_crtc->base != crtc ||
6614 encoder == other_encoder)
6615 continue;
6616 else
6617 return true;
6543 } 6618 }
6544 6619
6545 if (HAS_PCH_SPLIT(dev)) 6620 return false;
6546 return; 6621}
6547 6622
6548 /* Who knows what state these registers were left in by the BIOS or 6623static bool intel_encoder_crtc_ok(struct drm_encoder *encoder,
6549 * grub? 6624 struct drm_crtc *crtc)
6550 * 6625{
6551 * If we leave the registers in a conflicting state (e.g. with the 6626 struct drm_device *dev;
6552 * display plane reading from the other pipe than the one we intend 6627 struct drm_crtc *tmp;
6553 * to use) then when we attempt to teardown the active mode, we will 6628 int crtc_mask = 1;
6554 * not disable the pipes and planes in the correct order -- leaving 6629
6555 * a plane reading from a disabled pipe and possibly leading to 6630 WARN(!crtc, "checking null crtc?\n");
6556 * undefined behaviour. 6631
6632 dev = crtc->dev;
6633
6634 list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) {
6635 if (tmp == crtc)
6636 break;
6637 crtc_mask <<= 1;
6638 }
6639
6640 if (encoder->possible_crtcs & crtc_mask)
6641 return true;
6642 return false;
6643}
6644
6645/**
6646 * intel_modeset_update_staged_output_state
6647 *
6648 * Updates the staged output configuration state, e.g. after we've read out the
6649 * current hw state.
6650 */
6651static void intel_modeset_update_staged_output_state(struct drm_device *dev)
6652{
6653 struct intel_encoder *encoder;
6654 struct intel_connector *connector;
6655
6656 list_for_each_entry(connector, &dev->mode_config.connector_list,
6657 base.head) {
6658 connector->new_encoder =
6659 to_intel_encoder(connector->base.encoder);
6660 }
6661
6662 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
6663 base.head) {
6664 encoder->new_crtc =
6665 to_intel_crtc(encoder->base.crtc);
6666 }
6667}
6668
6669/**
6670 * intel_modeset_commit_output_state
6671 *
6672 * This function copies the stage display pipe configuration to the real one.
6673 */
6674static void intel_modeset_commit_output_state(struct drm_device *dev)
6675{
6676 struct intel_encoder *encoder;
6677 struct intel_connector *connector;
6678
6679 list_for_each_entry(connector, &dev->mode_config.connector_list,
6680 base.head) {
6681 connector->base.encoder = &connector->new_encoder->base;
6682 }
6683
6684 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
6685 base.head) {
6686 encoder->base.crtc = &encoder->new_crtc->base;
6687 }
6688}
6689
6690static struct drm_display_mode *
6691intel_modeset_adjusted_mode(struct drm_crtc *crtc,
6692 struct drm_display_mode *mode)
6693{
6694 struct drm_device *dev = crtc->dev;
6695 struct drm_display_mode *adjusted_mode;
6696 struct drm_encoder_helper_funcs *encoder_funcs;
6697 struct intel_encoder *encoder;
6698
6699 adjusted_mode = drm_mode_duplicate(dev, mode);
6700 if (!adjusted_mode)
6701 return ERR_PTR(-ENOMEM);
6702
6703 /* Pass our mode to the connectors and the CRTC to give them a chance to
6704 * adjust it according to limitations or connector properties, and also
6705 * a chance to reject the mode entirely.
6557 */ 6706 */
6707 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
6708 base.head) {
6558 6709
6559 reg = DSPCNTR(plane); 6710 if (&encoder->new_crtc->base != crtc)
6560 val = I915_READ(reg); 6711 continue;
6712 encoder_funcs = encoder->base.helper_private;
6713 if (!(encoder_funcs->mode_fixup(&encoder->base, mode,
6714 adjusted_mode))) {
6715 DRM_DEBUG_KMS("Encoder fixup failed\n");
6716 goto fail;
6717 }
6718 }
6561 6719
6562 if ((val & DISPLAY_PLANE_ENABLE) == 0) 6720 if (!(intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
6563 return; 6721 DRM_DEBUG_KMS("CRTC fixup failed\n");
6564 if (!!(val & DISPPLANE_SEL_PIPE_MASK) == pipe) 6722 goto fail;
6565 return; 6723 }
6724 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
6566 6725
6567 /* This display plane is active and attached to the other CPU pipe. */ 6726 return adjusted_mode;
6568 pipe = !pipe; 6727fail:
6728 drm_mode_destroy(dev, adjusted_mode);
6729 return ERR_PTR(-EINVAL);
6730}
6569 6731
6570 /* Disable the plane and wait for it to stop reading from the pipe. */ 6732/* Computes which crtcs are affected and sets the relevant bits in the mask. For
6571 intel_disable_plane(dev_priv, plane, pipe); 6733 * simplicity we use the crtc's pipe number (because it's easier to obtain). */
6572 intel_disable_pipe(dev_priv, pipe); 6734static void
6735intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
6736 unsigned *prepare_pipes, unsigned *disable_pipes)
6737{
6738 struct intel_crtc *intel_crtc;
6739 struct drm_device *dev = crtc->dev;
6740 struct intel_encoder *encoder;
6741 struct intel_connector *connector;
6742 struct drm_crtc *tmp_crtc;
6743
6744 *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
6745
6746 /* Check which crtcs have changed outputs connected to them, these need
6747 * to be part of the prepare_pipes mask. We don't (yet) support global
6748 * modeset across multiple crtcs, so modeset_pipes will only have one
6749 * bit set at most. */
6750 list_for_each_entry(connector, &dev->mode_config.connector_list,
6751 base.head) {
6752 if (connector->base.encoder == &connector->new_encoder->base)
6753 continue;
6754
6755 if (connector->base.encoder) {
6756 tmp_crtc = connector->base.encoder->crtc;
6757
6758 *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
6759 }
6760
6761 if (connector->new_encoder)
6762 *prepare_pipes |=
6763 1 << connector->new_encoder->new_crtc->pipe;
6764 }
6765
6766 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
6767 base.head) {
6768 if (encoder->base.crtc == &encoder->new_crtc->base)
6769 continue;
6770
6771 if (encoder->base.crtc) {
6772 tmp_crtc = encoder->base.crtc;
6773
6774 *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
6775 }
6776
6777 if (encoder->new_crtc)
6778 *prepare_pipes |= 1 << encoder->new_crtc->pipe;
6779 }
6780
6781 /* Check for any pipes that will be fully disabled ... */
6782 list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
6783 base.head) {
6784 bool used = false;
6785
6786 /* Don't try to disable disabled crtcs. */
6787 if (!intel_crtc->base.enabled)
6788 continue;
6789
6790 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
6791 base.head) {
6792 if (encoder->new_crtc == intel_crtc)
6793 used = true;
6794 }
6795
6796 if (!used)
6797 *disable_pipes |= 1 << intel_crtc->pipe;
6798 }
6799
6800
6801 /* set_mode is also used to update properties on life display pipes. */
6802 intel_crtc = to_intel_crtc(crtc);
6803 if (crtc->enabled)
6804 *prepare_pipes |= 1 << intel_crtc->pipe;
6805
6806 /* We only support modeset on one single crtc, hence we need to do that
6807 * only for the passed in crtc iff we change anything else than just
6808 * disable crtcs.
6809 *
6810 * This is actually not true, to be fully compatible with the old crtc
6811 * helper we automatically disable _any_ output (i.e. doesn't need to be
6812 * connected to the crtc we're modesetting on) if it's disconnected.
6813 * Which is a rather nutty api (since changed the output configuration
6814 * without userspace's explicit request can lead to confusion), but
6815 * alas. Hence we currently need to modeset on all pipes we prepare. */
6816 if (*prepare_pipes)
6817 *modeset_pipes = *prepare_pipes;
6818
6819 /* ... and mask these out. */
6820 *modeset_pipes &= ~(*disable_pipes);
6821 *prepare_pipes &= ~(*disable_pipes);
6573} 6822}
6574 6823
6575static void intel_crtc_reset(struct drm_crtc *crtc) 6824static bool intel_crtc_in_use(struct drm_crtc *crtc)
6576{ 6825{
6826 struct drm_encoder *encoder;
6577 struct drm_device *dev = crtc->dev; 6827 struct drm_device *dev = crtc->dev;
6578 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6579 6828
6580 /* Reset flags back to the 'unknown' status so that they 6829 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
6581 * will be correctly set on the initial modeset. 6830 if (encoder->crtc == crtc)
6831 return true;
6832
6833 return false;
6834}
6835
6836static void
6837intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
6838{
6839 struct intel_encoder *intel_encoder;
6840 struct intel_crtc *intel_crtc;
6841 struct drm_connector *connector;
6842
6843 list_for_each_entry(intel_encoder, &dev->mode_config.encoder_list,
6844 base.head) {
6845 if (!intel_encoder->base.crtc)
6846 continue;
6847
6848 intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
6849
6850 if (prepare_pipes & (1 << intel_crtc->pipe))
6851 intel_encoder->connectors_active = false;
6852 }
6853
6854 intel_modeset_commit_output_state(dev);
6855
6856 /* Update computed state. */
6857 list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
6858 base.head) {
6859 intel_crtc->base.enabled = intel_crtc_in_use(&intel_crtc->base);
6860 }
6861
6862 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
6863 if (!connector->encoder || !connector->encoder->crtc)
6864 continue;
6865
6866 intel_crtc = to_intel_crtc(connector->encoder->crtc);
6867
6868 if (prepare_pipes & (1 << intel_crtc->pipe)) {
6869 connector->dpms = DRM_MODE_DPMS_ON;
6870
6871 intel_encoder = to_intel_encoder(connector->encoder);
6872 intel_encoder->connectors_active = true;
6873 }
6874 }
6875
6876}
6877
6878#define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
6879 list_for_each_entry((intel_crtc), \
6880 &(dev)->mode_config.crtc_list, \
6881 base.head) \
6882 if (mask & (1 <<(intel_crtc)->pipe)) \
6883
6884void
6885intel_modeset_check_state(struct drm_device *dev)
6886{
6887 struct intel_crtc *crtc;
6888 struct intel_encoder *encoder;
6889 struct intel_connector *connector;
6890
6891 list_for_each_entry(connector, &dev->mode_config.connector_list,
6892 base.head) {
6893 /* This also checks the encoder/connector hw state with the
6894 * ->get_hw_state callbacks. */
6895 intel_connector_check_state(connector);
6896
6897 WARN(&connector->new_encoder->base != connector->base.encoder,
6898 "connector's staged encoder doesn't match current encoder\n");
6899 }
6900
6901 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
6902 base.head) {
6903 bool enabled = false;
6904 bool active = false;
6905 enum pipe pipe, tracked_pipe;
6906
6907 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
6908 encoder->base.base.id,
6909 drm_get_encoder_name(&encoder->base));
6910
6911 WARN(&encoder->new_crtc->base != encoder->base.crtc,
6912 "encoder's stage crtc doesn't match current crtc\n");
6913 WARN(encoder->connectors_active && !encoder->base.crtc,
6914 "encoder's active_connectors set, but no crtc\n");
6915
6916 list_for_each_entry(connector, &dev->mode_config.connector_list,
6917 base.head) {
6918 if (connector->base.encoder != &encoder->base)
6919 continue;
6920 enabled = true;
6921 if (connector->base.dpms != DRM_MODE_DPMS_OFF)
6922 active = true;
6923 }
6924 WARN(!!encoder->base.crtc != enabled,
6925 "encoder's enabled state mismatch "
6926 "(expected %i, found %i)\n",
6927 !!encoder->base.crtc, enabled);
6928 WARN(active && !encoder->base.crtc,
6929 "active encoder with no crtc\n");
6930
6931 WARN(encoder->connectors_active != active,
6932 "encoder's computed active state doesn't match tracked active state "
6933 "(expected %i, found %i)\n", active, encoder->connectors_active);
6934
6935 active = encoder->get_hw_state(encoder, &pipe);
6936 WARN(active != encoder->connectors_active,
6937 "encoder's hw state doesn't match sw tracking "
6938 "(expected %i, found %i)\n",
6939 encoder->connectors_active, active);
6940
6941 if (!encoder->base.crtc)
6942 continue;
6943
6944 tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
6945 WARN(active && pipe != tracked_pipe,
6946 "active encoder's pipe doesn't match"
6947 "(expected %i, found %i)\n",
6948 tracked_pipe, pipe);
6949
6950 }
6951
6952 list_for_each_entry(crtc, &dev->mode_config.crtc_list,
6953 base.head) {
6954 bool enabled = false;
6955 bool active = false;
6956
6957 DRM_DEBUG_KMS("[CRTC:%d]\n",
6958 crtc->base.base.id);
6959
6960 WARN(crtc->active && !crtc->base.enabled,
6961 "active crtc, but not enabled in sw tracking\n");
6962
6963 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
6964 base.head) {
6965 if (encoder->base.crtc != &crtc->base)
6966 continue;
6967 enabled = true;
6968 if (encoder->connectors_active)
6969 active = true;
6970 }
6971 WARN(active != crtc->active,
6972 "crtc's computed active state doesn't match tracked active state "
6973 "(expected %i, found %i)\n", active, crtc->active);
6974 WARN(enabled != crtc->base.enabled,
6975 "crtc's computed enabled state doesn't match tracked enabled state "
6976 "(expected %i, found %i)\n", enabled, crtc->base.enabled);
6977
6978 assert_pipe(dev->dev_private, crtc->pipe, crtc->active);
6979 }
6980}
6981
6982bool intel_set_mode(struct drm_crtc *crtc,
6983 struct drm_display_mode *mode,
6984 int x, int y, struct drm_framebuffer *fb)
6985{
6986 struct drm_device *dev = crtc->dev;
6987 drm_i915_private_t *dev_priv = dev->dev_private;
6988 struct drm_display_mode *adjusted_mode, saved_mode, saved_hwmode;
6989 struct drm_encoder_helper_funcs *encoder_funcs;
6990 struct drm_encoder *encoder;
6991 struct intel_crtc *intel_crtc;
6992 unsigned disable_pipes, prepare_pipes, modeset_pipes;
6993 bool ret = true;
6994
6995 intel_modeset_affected_pipes(crtc, &modeset_pipes,
6996 &prepare_pipes, &disable_pipes);
6997
6998 DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
6999 modeset_pipes, prepare_pipes, disable_pipes);
7000
7001 for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
7002 intel_crtc_disable(&intel_crtc->base);
7003
7004 saved_hwmode = crtc->hwmode;
7005 saved_mode = crtc->mode;
7006
7007 /* Hack: Because we don't (yet) support global modeset on multiple
7008 * crtcs, we don't keep track of the new mode for more than one crtc.
7009 * Hence simply check whether any bit is set in modeset_pipes in all the
7010 * pieces of code that are not yet converted to deal with mutliple crtcs
7011 * changing their mode at the same time. */
7012 adjusted_mode = NULL;
7013 if (modeset_pipes) {
7014 adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
7015 if (IS_ERR(adjusted_mode)) {
7016 return false;
7017 }
7018 }
7019
7020 for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
7021 if (intel_crtc->base.enabled)
7022 dev_priv->display.crtc_disable(&intel_crtc->base);
7023 }
7024
7025 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
7026 * to set it here already despite that we pass it down the callchain.
6582 */ 7027 */
6583 intel_crtc->dpms_mode = -1; 7028 if (modeset_pipes)
7029 crtc->mode = *mode;
6584 7030
6585 /* We need to fix up any BIOS configuration that conflicts with 7031 /* Only after disabling all output pipelines that will be changed can we
6586 * our expectations. 7032 * update the the output configuration. */
7033 intel_modeset_update_state(dev, prepare_pipes);
7034
7035 /* Set up the DPLL and any encoders state that needs to adjust or depend
7036 * on the DPLL.
6587 */ 7037 */
6588 intel_sanitize_modesetting(dev, intel_crtc->pipe, intel_crtc->plane); 7038 for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
7039 ret = !intel_crtc_mode_set(&intel_crtc->base,
7040 mode, adjusted_mode,
7041 x, y, fb);
7042 if (!ret)
7043 goto done;
7044
7045 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
7046
7047 if (encoder->crtc != &intel_crtc->base)
7048 continue;
7049
7050 DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
7051 encoder->base.id, drm_get_encoder_name(encoder),
7052 mode->base.id, mode->name);
7053 encoder_funcs = encoder->helper_private;
7054 encoder_funcs->mode_set(encoder, mode, adjusted_mode);
7055 }
7056 }
7057
7058 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
7059 for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc)
7060 dev_priv->display.crtc_enable(&intel_crtc->base);
7061
7062 if (modeset_pipes) {
7063 /* Store real post-adjustment hardware mode. */
7064 crtc->hwmode = *adjusted_mode;
7065
7066 /* Calculate and store various constants which
7067 * are later needed by vblank and swap-completion
7068 * timestamping. They are derived from true hwmode.
7069 */
7070 drm_calc_timestamping_constants(crtc);
7071 }
7072
7073 /* FIXME: add subpixel order */
7074done:
7075 drm_mode_destroy(dev, adjusted_mode);
7076 if (!ret && crtc->enabled) {
7077 crtc->hwmode = saved_hwmode;
7078 crtc->mode = saved_mode;
7079 } else {
7080 intel_modeset_check_state(dev);
7081 }
7082
7083 return ret;
6589} 7084}
6590 7085
6591static struct drm_crtc_helper_funcs intel_helper_funcs = { 7086#undef for_each_intel_crtc_masked
6592 .dpms = intel_crtc_dpms, 7087
6593 .mode_fixup = intel_crtc_mode_fixup, 7088static void intel_set_config_free(struct intel_set_config *config)
6594 .mode_set = intel_crtc_mode_set, 7089{
6595 .mode_set_base = intel_pipe_set_base, 7090 if (!config)
6596 .mode_set_base_atomic = intel_pipe_set_base_atomic, 7091 return;
6597 .load_lut = intel_crtc_load_lut, 7092
6598 .disable = intel_crtc_disable, 7093 kfree(config->save_connector_encoders);
6599}; 7094 kfree(config->save_encoder_crtcs);
7095 kfree(config);
7096}
7097
7098static int intel_set_config_save_state(struct drm_device *dev,
7099 struct intel_set_config *config)
7100{
7101 struct drm_encoder *encoder;
7102 struct drm_connector *connector;
7103 int count;
7104
7105 config->save_encoder_crtcs =
7106 kcalloc(dev->mode_config.num_encoder,
7107 sizeof(struct drm_crtc *), GFP_KERNEL);
7108 if (!config->save_encoder_crtcs)
7109 return -ENOMEM;
7110
7111 config->save_connector_encoders =
7112 kcalloc(dev->mode_config.num_connector,
7113 sizeof(struct drm_encoder *), GFP_KERNEL);
7114 if (!config->save_connector_encoders)
7115 return -ENOMEM;
7116
7117 /* Copy data. Note that driver private data is not affected.
7118 * Should anything bad happen only the expected state is
7119 * restored, not the drivers personal bookkeeping.
7120 */
7121 count = 0;
7122 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
7123 config->save_encoder_crtcs[count++] = encoder->crtc;
7124 }
7125
7126 count = 0;
7127 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
7128 config->save_connector_encoders[count++] = connector->encoder;
7129 }
7130
7131 return 0;
7132}
7133
7134static void intel_set_config_restore_state(struct drm_device *dev,
7135 struct intel_set_config *config)
7136{
7137 struct intel_encoder *encoder;
7138 struct intel_connector *connector;
7139 int count;
7140
7141 count = 0;
7142 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
7143 encoder->new_crtc =
7144 to_intel_crtc(config->save_encoder_crtcs[count++]);
7145 }
7146
7147 count = 0;
7148 list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
7149 connector->new_encoder =
7150 to_intel_encoder(config->save_connector_encoders[count++]);
7151 }
7152}
7153
7154static void
7155intel_set_config_compute_mode_changes(struct drm_mode_set *set,
7156 struct intel_set_config *config)
7157{
7158
7159 /* We should be able to check here if the fb has the same properties
7160 * and then just flip_or_move it */
7161 if (set->crtc->fb != set->fb) {
7162 /* If we have no fb then treat it as a full mode set */
7163 if (set->crtc->fb == NULL) {
7164 DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
7165 config->mode_changed = true;
7166 } else if (set->fb == NULL) {
7167 config->mode_changed = true;
7168 } else if (set->fb->depth != set->crtc->fb->depth) {
7169 config->mode_changed = true;
7170 } else if (set->fb->bits_per_pixel !=
7171 set->crtc->fb->bits_per_pixel) {
7172 config->mode_changed = true;
7173 } else
7174 config->fb_changed = true;
7175 }
7176
7177 if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
7178 config->fb_changed = true;
7179
7180 if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
7181 DRM_DEBUG_KMS("modes are different, full mode set\n");
7182 drm_mode_debug_printmodeline(&set->crtc->mode);
7183 drm_mode_debug_printmodeline(set->mode);
7184 config->mode_changed = true;
7185 }
7186}
7187
7188static int
7189intel_modeset_stage_output_state(struct drm_device *dev,
7190 struct drm_mode_set *set,
7191 struct intel_set_config *config)
7192{
7193 struct drm_crtc *new_crtc;
7194 struct intel_connector *connector;
7195 struct intel_encoder *encoder;
7196 int count, ro;
7197
7198 /* The upper layers ensure that we either disabl a crtc or have a list
7199 * of connectors. For paranoia, double-check this. */
7200 WARN_ON(!set->fb && (set->num_connectors != 0));
7201 WARN_ON(set->fb && (set->num_connectors == 0));
7202
7203 count = 0;
7204 list_for_each_entry(connector, &dev->mode_config.connector_list,
7205 base.head) {
7206 /* Otherwise traverse passed in connector list and get encoders
7207 * for them. */
7208 for (ro = 0; ro < set->num_connectors; ro++) {
7209 if (set->connectors[ro] == &connector->base) {
7210 connector->new_encoder = connector->encoder;
7211 break;
7212 }
7213 }
7214
7215 /* If we disable the crtc, disable all its connectors. Also, if
7216 * the connector is on the changing crtc but not on the new
7217 * connector list, disable it. */
7218 if ((!set->fb || ro == set->num_connectors) &&
7219 connector->base.encoder &&
7220 connector->base.encoder->crtc == set->crtc) {
7221 connector->new_encoder = NULL;
7222
7223 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
7224 connector->base.base.id,
7225 drm_get_connector_name(&connector->base));
7226 }
7227
7228
7229 if (&connector->new_encoder->base != connector->base.encoder) {
7230 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
7231 config->mode_changed = true;
7232 }
7233
7234 /* Disable all disconnected encoders. */
7235 if (connector->base.status == connector_status_disconnected)
7236 connector->new_encoder = NULL;
7237 }
7238 /* connector->new_encoder is now updated for all connectors. */
7239
7240 /* Update crtc of enabled connectors. */
7241 count = 0;
7242 list_for_each_entry(connector, &dev->mode_config.connector_list,
7243 base.head) {
7244 if (!connector->new_encoder)
7245 continue;
7246
7247 new_crtc = connector->new_encoder->base.crtc;
7248
7249 for (ro = 0; ro < set->num_connectors; ro++) {
7250 if (set->connectors[ro] == &connector->base)
7251 new_crtc = set->crtc;
7252 }
7253
7254 /* Make sure the new CRTC will work with the encoder */
7255 if (!intel_encoder_crtc_ok(&connector->new_encoder->base,
7256 new_crtc)) {
7257 return -EINVAL;
7258 }
7259 connector->encoder->new_crtc = to_intel_crtc(new_crtc);
7260
7261 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
7262 connector->base.base.id,
7263 drm_get_connector_name(&connector->base),
7264 new_crtc->base.id);
7265 }
7266
7267 /* Check for any encoders that needs to be disabled. */
7268 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7269 base.head) {
7270 list_for_each_entry(connector,
7271 &dev->mode_config.connector_list,
7272 base.head) {
7273 if (connector->new_encoder == encoder) {
7274 WARN_ON(!connector->new_encoder->new_crtc);
7275
7276 goto next_encoder;
7277 }
7278 }
7279 encoder->new_crtc = NULL;
7280next_encoder:
7281 /* Only now check for crtc changes so we don't miss encoders
7282 * that will be disabled. */
7283 if (&encoder->new_crtc->base != encoder->base.crtc) {
7284 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
7285 config->mode_changed = true;
7286 }
7287 }
7288 /* Now we've also updated encoder->new_crtc for all encoders. */
7289
7290 return 0;
7291}
7292
7293static int intel_crtc_set_config(struct drm_mode_set *set)
7294{
7295 struct drm_device *dev;
7296 struct drm_mode_set save_set;
7297 struct intel_set_config *config;
7298 int ret;
7299 int i;
7300
7301 BUG_ON(!set);
7302 BUG_ON(!set->crtc);
7303 BUG_ON(!set->crtc->helper_private);
7304
7305 if (!set->mode)
7306 set->fb = NULL;
7307
7308 /* The fb helper likes to play gross jokes with ->mode_set_config.
7309 * Unfortunately the crtc helper doesn't do much at all for this case,
7310 * so we have to cope with this madness until the fb helper is fixed up. */
7311 if (set->fb && set->num_connectors == 0)
7312 return 0;
7313
7314 if (set->fb) {
7315 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
7316 set->crtc->base.id, set->fb->base.id,
7317 (int)set->num_connectors, set->x, set->y);
7318 } else {
7319 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
7320 }
7321
7322 dev = set->crtc->dev;
7323
7324 ret = -ENOMEM;
7325 config = kzalloc(sizeof(*config), GFP_KERNEL);
7326 if (!config)
7327 goto out_config;
7328
7329 ret = intel_set_config_save_state(dev, config);
7330 if (ret)
7331 goto out_config;
7332
7333 save_set.crtc = set->crtc;
7334 save_set.mode = &set->crtc->mode;
7335 save_set.x = set->crtc->x;
7336 save_set.y = set->crtc->y;
7337 save_set.fb = set->crtc->fb;
7338
7339 /* Compute whether we need a full modeset, only an fb base update or no
7340 * change at all. In the future we might also check whether only the
7341 * mode changed, e.g. for LVDS where we only change the panel fitter in
7342 * such cases. */
7343 intel_set_config_compute_mode_changes(set, config);
7344
7345 ret = intel_modeset_stage_output_state(dev, set, config);
7346 if (ret)
7347 goto fail;
7348
7349 if (config->mode_changed) {
7350 if (set->mode) {
7351 DRM_DEBUG_KMS("attempting to set mode from"
7352 " userspace\n");
7353 drm_mode_debug_printmodeline(set->mode);
7354 }
7355
7356 if (!intel_set_mode(set->crtc, set->mode,
7357 set->x, set->y, set->fb)) {
7358 DRM_ERROR("failed to set mode on [CRTC:%d]\n",
7359 set->crtc->base.id);
7360 ret = -EINVAL;
7361 goto fail;
7362 }
7363
7364 if (set->crtc->enabled) {
7365 DRM_DEBUG_KMS("Setting connector DPMS state to on\n");
7366 for (i = 0; i < set->num_connectors; i++) {
7367 DRM_DEBUG_KMS("\t[CONNECTOR:%d:%s] set DPMS on\n", set->connectors[i]->base.id,
7368 drm_get_connector_name(set->connectors[i]));
7369 set->connectors[i]->funcs->dpms(set->connectors[i], DRM_MODE_DPMS_ON);
7370 }
7371 }
7372 } else if (config->fb_changed) {
7373 ret = intel_pipe_set_base(set->crtc,
7374 set->x, set->y, set->fb);
7375 }
7376
7377 intel_set_config_free(config);
7378
7379 return 0;
7380
7381fail:
7382 intel_set_config_restore_state(dev, config);
7383
7384 /* Try to restore the config */
7385 if (config->mode_changed &&
7386 !intel_set_mode(save_set.crtc, save_set.mode,
7387 save_set.x, save_set.y, save_set.fb))
7388 DRM_ERROR("failed to restore config after modeset failure\n");
7389
7390out_config:
7391 intel_set_config_free(config);
7392 return ret;
7393}
6600 7394
6601static const struct drm_crtc_funcs intel_crtc_funcs = { 7395static const struct drm_crtc_funcs intel_crtc_funcs = {
6602 .reset = intel_crtc_reset,
6603 .cursor_set = intel_crtc_cursor_set, 7396 .cursor_set = intel_crtc_cursor_set,
6604 .cursor_move = intel_crtc_cursor_move, 7397 .cursor_move = intel_crtc_cursor_move,
6605 .gamma_set = intel_crtc_gamma_set, 7398 .gamma_set = intel_crtc_gamma_set,
6606 .set_config = drm_crtc_helper_set_config, 7399 .set_config = intel_crtc_set_config,
6607 .destroy = intel_crtc_destroy, 7400 .destroy = intel_crtc_destroy,
6608 .page_flip = intel_crtc_page_flip, 7401 .page_flip = intel_crtc_page_flip,
6609}; 7402};
@@ -6657,18 +7450,8 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
6657 dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; 7450 dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
6658 dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; 7451 dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
6659 7452
6660 intel_crtc_reset(&intel_crtc->base);
6661 intel_crtc->active = true; /* force the pipe off on setup_init_config */
6662 intel_crtc->bpp = 24; /* default for pre-Ironlake */ 7453 intel_crtc->bpp = 24; /* default for pre-Ironlake */
6663 7454
6664 if (HAS_PCH_SPLIT(dev)) {
6665 intel_helper_funcs.prepare = ironlake_crtc_prepare;
6666 intel_helper_funcs.commit = ironlake_crtc_commit;
6667 } else {
6668 intel_helper_funcs.prepare = i9xx_crtc_prepare;
6669 intel_helper_funcs.commit = i9xx_crtc_commit;
6670 }
6671
6672 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); 7455 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
6673} 7456}
6674 7457
@@ -6874,9 +7657,6 @@ static void intel_setup_outputs(struct drm_device *dev)
6874 intel_encoder_clones(encoder); 7657 intel_encoder_clones(encoder);
6875 } 7658 }
6876 7659
6877 /* disable all the possible outputs/crtcs before entering KMS mode */
6878 drm_helper_disable_unused_functions(dev);
6879
6880 if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) 7660 if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
6881 ironlake_init_pch_refclk(dev); 7661 ironlake_init_pch_refclk(dev);
6882} 7662}
@@ -6978,13 +7758,15 @@ static void intel_init_display(struct drm_device *dev)
6978 7758
6979 /* We always want a DPMS function */ 7759 /* We always want a DPMS function */
6980 if (HAS_PCH_SPLIT(dev)) { 7760 if (HAS_PCH_SPLIT(dev)) {
6981 dev_priv->display.dpms = ironlake_crtc_dpms;
6982 dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set; 7761 dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
7762 dev_priv->display.crtc_enable = ironlake_crtc_enable;
7763 dev_priv->display.crtc_disable = ironlake_crtc_disable;
6983 dev_priv->display.off = ironlake_crtc_off; 7764 dev_priv->display.off = ironlake_crtc_off;
6984 dev_priv->display.update_plane = ironlake_update_plane; 7765 dev_priv->display.update_plane = ironlake_update_plane;
6985 } else { 7766 } else {
6986 dev_priv->display.dpms = i9xx_crtc_dpms;
6987 dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set; 7767 dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
7768 dev_priv->display.crtc_enable = i9xx_crtc_enable;
7769 dev_priv->display.crtc_disable = i9xx_crtc_disable;
6988 dev_priv->display.off = i9xx_crtc_off; 7770 dev_priv->display.off = i9xx_crtc_off;
6989 dev_priv->display.update_plane = i9xx_update_plane; 7771 dev_priv->display.update_plane = i9xx_update_plane;
6990 } 7772 }
@@ -7233,11 +8015,258 @@ void intel_modeset_init(struct drm_device *dev)
7233 intel_setup_outputs(dev); 8015 intel_setup_outputs(dev);
7234} 8016}
7235 8017
8018static void
8019intel_connector_break_all_links(struct intel_connector *connector)
8020{
8021 connector->base.dpms = DRM_MODE_DPMS_OFF;
8022 connector->base.encoder = NULL;
8023 connector->encoder->connectors_active = false;
8024 connector->encoder->base.crtc = NULL;
8025}
8026
8027static void intel_enable_pipe_a(struct drm_device *dev)
8028{
8029 struct intel_connector *connector;
8030 struct drm_connector *crt = NULL;
8031 struct intel_load_detect_pipe load_detect_temp;
8032
8033 /* We can't just switch on the pipe A, we need to set things up with a
8034 * proper mode and output configuration. As a gross hack, enable pipe A
8035 * by enabling the load detect pipe once. */
8036 list_for_each_entry(connector,
8037 &dev->mode_config.connector_list,
8038 base.head) {
8039 if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
8040 crt = &connector->base;
8041 break;
8042 }
8043 }
8044
8045 if (!crt)
8046 return;
8047
8048 if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp))
8049 intel_release_load_detect_pipe(crt, &load_detect_temp);
8050
8051
8052}
8053
8054static void intel_sanitize_crtc(struct intel_crtc *crtc)
8055{
8056 struct drm_device *dev = crtc->base.dev;
8057 struct drm_i915_private *dev_priv = dev->dev_private;
8058 u32 reg, val;
8059
8060 /* Clear any frame start delays used for debugging left by the BIOS */
8061 reg = PIPECONF(crtc->pipe);
8062 I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
8063
8064 /* We need to sanitize the plane -> pipe mapping first because this will
8065 * disable the crtc (and hence change the state) if it is wrong. */
8066 if (!HAS_PCH_SPLIT(dev)) {
8067 struct intel_connector *connector;
8068 bool plane;
8069
8070 reg = DSPCNTR(crtc->plane);
8071 val = I915_READ(reg);
8072
8073 if ((val & DISPLAY_PLANE_ENABLE) == 0 &&
8074 (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
8075 goto ok;
8076
8077 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
8078 crtc->base.base.id);
8079
8080 /* Pipe has the wrong plane attached and the plane is active.
8081 * Temporarily change the plane mapping and disable everything
8082 * ... */
8083 plane = crtc->plane;
8084 crtc->plane = !plane;
8085 dev_priv->display.crtc_disable(&crtc->base);
8086 crtc->plane = plane;
8087
8088 /* ... and break all links. */
8089 list_for_each_entry(connector, &dev->mode_config.connector_list,
8090 base.head) {
8091 if (connector->encoder->base.crtc != &crtc->base)
8092 continue;
8093
8094 intel_connector_break_all_links(connector);
8095 }
8096
8097 WARN_ON(crtc->active);
8098 crtc->base.enabled = false;
8099 }
8100ok:
8101
8102 if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
8103 crtc->pipe == PIPE_A && !crtc->active) {
8104 /* BIOS forgot to enable pipe A, this mostly happens after
8105 * resume. Force-enable the pipe to fix this, the update_dpms
8106 * call below we restore the pipe to the right state, but leave
8107 * the required bits on. */
8108 intel_enable_pipe_a(dev);
8109 }
8110
8111 /* Adjust the state of the output pipe according to whether we
8112 * have active connectors/encoders. */
8113 intel_crtc_update_dpms(&crtc->base);
8114
8115 if (crtc->active != crtc->base.enabled) {
8116 struct intel_encoder *encoder;
8117
8118 /* This can happen either due to bugs in the get_hw_state
8119 * functions or because the pipe is force-enabled due to the
8120 * pipe A quirk. */
8121 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
8122 crtc->base.base.id,
8123 crtc->base.enabled ? "enabled" : "disabled",
8124 crtc->active ? "enabled" : "disabled");
8125
8126 crtc->base.enabled = crtc->active;
8127
8128 /* Because we only establish the connector -> encoder ->
8129 * crtc links if something is active, this means the
8130 * crtc is now deactivated. Break the links. connector
8131 * -> encoder links are only establish when things are
8132 * actually up, hence no need to break them. */
8133 WARN_ON(crtc->active);
8134
8135 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
8136 WARN_ON(encoder->connectors_active);
8137 encoder->base.crtc = NULL;
8138 }
8139 }
8140}
8141
8142static void intel_sanitize_encoder(struct intel_encoder *encoder)
8143{
8144 struct intel_connector *connector;
8145 struct drm_device *dev = encoder->base.dev;
8146
8147 /* We need to check both for a crtc link (meaning that the
8148 * encoder is active and trying to read from a pipe) and the
8149 * pipe itself being active. */
8150 bool has_active_crtc = encoder->base.crtc &&
8151 to_intel_crtc(encoder->base.crtc)->active;
8152
8153 if (encoder->connectors_active && !has_active_crtc) {
8154 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
8155 encoder->base.base.id,
8156 drm_get_encoder_name(&encoder->base));
8157
8158 /* Connector is active, but has no active pipe. This is
8159 * fallout from our resume register restoring. Disable
8160 * the encoder manually again. */
8161 if (encoder->base.crtc) {
8162 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
8163 encoder->base.base.id,
8164 drm_get_encoder_name(&encoder->base));
8165 encoder->disable(encoder);
8166 }
8167
8168 /* Inconsistent output/port/pipe state happens presumably due to
8169 * a bug in one of the get_hw_state functions. Or someplace else
8170 * in our code, like the register restore mess on resume. Clamp
8171 * things to off as a safer default. */
8172 list_for_each_entry(connector,
8173 &dev->mode_config.connector_list,
8174 base.head) {
8175 if (connector->encoder != encoder)
8176 continue;
8177
8178 intel_connector_break_all_links(connector);
8179 }
8180 }
8181 /* Enabled encoders without active connectors will be fixed in
8182 * the crtc fixup. */
8183}
8184
8185/* Scan out the current hw modeset state, sanitizes it and maps it into the drm
8186 * and i915 state tracking structures. */
8187void intel_modeset_setup_hw_state(struct drm_device *dev)
8188{
8189 struct drm_i915_private *dev_priv = dev->dev_private;
8190 enum pipe pipe;
8191 u32 tmp;
8192 struct intel_crtc *crtc;
8193 struct intel_encoder *encoder;
8194 struct intel_connector *connector;
8195
8196 for_each_pipe(pipe) {
8197 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
8198
8199 tmp = I915_READ(PIPECONF(pipe));
8200 if (tmp & PIPECONF_ENABLE)
8201 crtc->active = true;
8202 else
8203 crtc->active = false;
8204
8205 crtc->base.enabled = crtc->active;
8206
8207 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
8208 crtc->base.base.id,
8209 crtc->active ? "enabled" : "disabled");
8210 }
8211
8212 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
8213 base.head) {
8214 pipe = 0;
8215
8216 if (encoder->get_hw_state(encoder, &pipe)) {
8217 encoder->base.crtc =
8218 dev_priv->pipe_to_crtc_mapping[pipe];
8219 } else {
8220 encoder->base.crtc = NULL;
8221 }
8222
8223 encoder->connectors_active = false;
8224 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe=%i\n",
8225 encoder->base.base.id,
8226 drm_get_encoder_name(&encoder->base),
8227 encoder->base.crtc ? "enabled" : "disabled",
8228 pipe);
8229 }
8230
8231 list_for_each_entry(connector, &dev->mode_config.connector_list,
8232 base.head) {
8233 if (connector->get_hw_state(connector)) {
8234 connector->base.dpms = DRM_MODE_DPMS_ON;
8235 connector->encoder->connectors_active = true;
8236 connector->base.encoder = &connector->encoder->base;
8237 } else {
8238 connector->base.dpms = DRM_MODE_DPMS_OFF;
8239 connector->base.encoder = NULL;
8240 }
8241 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
8242 connector->base.base.id,
8243 drm_get_connector_name(&connector->base),
8244 connector->base.encoder ? "enabled" : "disabled");
8245 }
8246
8247 /* HW state is read out, now we need to sanitize this mess. */
8248 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
8249 base.head) {
8250 intel_sanitize_encoder(encoder);
8251 }
8252
8253 for_each_pipe(pipe) {
8254 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
8255 intel_sanitize_crtc(crtc);
8256 }
8257
8258 intel_modeset_update_staged_output_state(dev);
8259
8260 intel_modeset_check_state(dev);
8261}
8262
7236void intel_modeset_gem_init(struct drm_device *dev) 8263void intel_modeset_gem_init(struct drm_device *dev)
7237{ 8264{
7238 intel_modeset_init_hw(dev); 8265 intel_modeset_init_hw(dev);
7239 8266
7240 intel_setup_overlay(dev); 8267 intel_setup_overlay(dev);
8268
8269 intel_modeset_setup_hw_state(dev);
7241} 8270}
7242 8271
7243void intel_modeset_cleanup(struct drm_device *dev) 8272void intel_modeset_cleanup(struct drm_device *dev)
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 143d19c26752..c59710db653e 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -1248,10 +1248,57 @@ static void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
1248 } 1248 }
1249} 1249}
1250 1250
1251static void intel_dp_prepare(struct drm_encoder *encoder) 1251static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
1252 enum pipe *pipe)
1252{ 1253{
1253 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1254 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1255 struct drm_device *dev = encoder->base.dev;
1256 struct drm_i915_private *dev_priv = dev->dev_private;
1257 u32 tmp = I915_READ(intel_dp->output_reg);
1258
1259 if (!(tmp & DP_PORT_EN))
1260 return false;
1254 1261
1262 if (is_cpu_edp(intel_dp) && IS_GEN7(dev)) {
1263 *pipe = PORT_TO_PIPE_CPT(tmp);
1264 } else if (!HAS_PCH_CPT(dev) || is_cpu_edp(intel_dp)) {
1265 *pipe = PORT_TO_PIPE(tmp);
1266 } else {
1267 u32 trans_sel;
1268 u32 trans_dp;
1269 int i;
1270
1271 switch (intel_dp->output_reg) {
1272 case PCH_DP_B:
1273 trans_sel = TRANS_DP_PORT_SEL_B;
1274 break;
1275 case PCH_DP_C:
1276 trans_sel = TRANS_DP_PORT_SEL_C;
1277 break;
1278 case PCH_DP_D:
1279 trans_sel = TRANS_DP_PORT_SEL_D;
1280 break;
1281 default:
1282 return true;
1283 }
1284
1285 for_each_pipe(i) {
1286 trans_dp = I915_READ(TRANS_DP_CTL(i));
1287 if ((trans_dp & TRANS_DP_PORT_SEL_MASK) == trans_sel) {
1288 *pipe = i;
1289 return true;
1290 }
1291 }
1292 }
1293
1294 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n", intel_dp->output_reg);
1295
1296 return true;
1297}
1298
1299static void intel_disable_dp(struct intel_encoder *encoder)
1300{
1301 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1255 1302
1256 /* Make sure the panel is off before trying to change the mode. But also 1303 /* Make sure the panel is off before trying to change the mode. But also
1257 * ensure that we have vdd while we switch off the panel. */ 1304 * ensure that we have vdd while we switch off the panel. */
@@ -1262,60 +1309,58 @@ static void intel_dp_prepare(struct drm_encoder *encoder)
1262 intel_dp_link_down(intel_dp); 1309 intel_dp_link_down(intel_dp);
1263} 1310}
1264 1311
1265static void intel_dp_commit(struct drm_encoder *encoder) 1312static void intel_enable_dp(struct intel_encoder *encoder)
1266{ 1313{
1267 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1314 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1268 struct drm_device *dev = encoder->dev; 1315 struct drm_device *dev = encoder->base.dev;
1269 struct intel_crtc *intel_crtc = to_intel_crtc(intel_dp->base.base.crtc); 1316 struct drm_i915_private *dev_priv = dev->dev_private;
1317 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
1270 1318
1271 ironlake_edp_panel_vdd_on(intel_dp); 1319 ironlake_edp_panel_vdd_on(intel_dp);
1272 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); 1320 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1273 intel_dp_start_link_train(intel_dp); 1321 if (!(dp_reg & DP_PORT_EN)) {
1274 ironlake_edp_panel_on(intel_dp); 1322 intel_dp_start_link_train(intel_dp);
1275 ironlake_edp_panel_vdd_off(intel_dp, true); 1323 ironlake_edp_panel_on(intel_dp);
1276 intel_dp_complete_link_train(intel_dp); 1324 ironlake_edp_panel_vdd_off(intel_dp, true);
1325 intel_dp_complete_link_train(intel_dp);
1326 } else
1327 ironlake_edp_panel_vdd_off(intel_dp, false);
1277 ironlake_edp_backlight_on(intel_dp); 1328 ironlake_edp_backlight_on(intel_dp);
1278
1279 intel_dp->dpms_mode = DRM_MODE_DPMS_ON;
1280
1281 if (HAS_PCH_CPT(dev))
1282 intel_cpt_verify_modeset(dev, intel_crtc->pipe);
1283} 1329}
1284 1330
1285static void 1331static void
1286intel_dp_dpms(struct drm_encoder *encoder, int mode) 1332intel_dp_dpms(struct drm_connector *connector, int mode)
1287{ 1333{
1288 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1334 struct intel_dp *intel_dp = intel_attached_dp(connector);
1289 struct drm_device *dev = encoder->dev; 1335
1290 struct drm_i915_private *dev_priv = dev->dev_private; 1336 /* DP supports only 2 dpms states. */
1291 uint32_t dp_reg = I915_READ(intel_dp->output_reg); 1337 if (mode != DRM_MODE_DPMS_ON)
1338 mode = DRM_MODE_DPMS_OFF;
1339
1340 if (mode == connector->dpms)
1341 return;
1342
1343 connector->dpms = mode;
1344
1345 /* Only need to change hw state when actually enabled */
1346 if (!intel_dp->base.base.crtc) {
1347 intel_dp->base.connectors_active = false;
1348 return;
1349 }
1292 1350
1293 if (mode != DRM_MODE_DPMS_ON) { 1351 if (mode != DRM_MODE_DPMS_ON) {
1294 /* Switching the panel off requires vdd. */ 1352 intel_encoder_dpms(&intel_dp->base, mode);
1295 ironlake_edp_panel_vdd_on(intel_dp);
1296 ironlake_edp_backlight_off(intel_dp);
1297 intel_dp_sink_dpms(intel_dp, mode);
1298 ironlake_edp_panel_off(intel_dp);
1299 intel_dp_link_down(intel_dp);
1300 1353
1301 if (is_cpu_edp(intel_dp)) 1354 if (is_cpu_edp(intel_dp))
1302 ironlake_edp_pll_off(encoder); 1355 ironlake_edp_pll_off(&intel_dp->base.base);
1303 } else { 1356 } else {
1304 if (is_cpu_edp(intel_dp)) 1357 if (is_cpu_edp(intel_dp))
1305 ironlake_edp_pll_on(encoder); 1358 ironlake_edp_pll_on(&intel_dp->base.base);
1306 1359
1307 ironlake_edp_panel_vdd_on(intel_dp); 1360 intel_encoder_dpms(&intel_dp->base, mode);
1308 intel_dp_sink_dpms(intel_dp, mode);
1309 if (!(dp_reg & DP_PORT_EN)) {
1310 intel_dp_start_link_train(intel_dp);
1311 ironlake_edp_panel_on(intel_dp);
1312 ironlake_edp_panel_vdd_off(intel_dp, true);
1313 intel_dp_complete_link_train(intel_dp);
1314 } else
1315 ironlake_edp_panel_vdd_off(intel_dp, false);
1316 ironlake_edp_backlight_on(intel_dp);
1317 } 1361 }
1318 intel_dp->dpms_mode = mode; 1362
1363 intel_modeset_check_state(connector->dev);
1319} 1364}
1320 1365
1321/* 1366/*
@@ -2016,10 +2061,10 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
2016 u8 sink_irq_vector; 2061 u8 sink_irq_vector;
2017 u8 link_status[DP_LINK_STATUS_SIZE]; 2062 u8 link_status[DP_LINK_STATUS_SIZE];
2018 2063
2019 if (intel_dp->dpms_mode != DRM_MODE_DPMS_ON) 2064 if (!intel_dp->base.connectors_active)
2020 return; 2065 return;
2021 2066
2022 if (!intel_dp->base.base.crtc) 2067 if (WARN_ON(!intel_dp->base.base.crtc))
2023 return; 2068 return;
2024 2069
2025 /* Try to read receiver status if the link appears to be up */ 2070 /* Try to read receiver status if the link appears to be up */
@@ -2305,9 +2350,8 @@ intel_dp_set_property(struct drm_connector *connector,
2305done: 2350done:
2306 if (intel_dp->base.base.crtc) { 2351 if (intel_dp->base.base.crtc) {
2307 struct drm_crtc *crtc = intel_dp->base.base.crtc; 2352 struct drm_crtc *crtc = intel_dp->base.base.crtc;
2308 drm_crtc_helper_set_mode(crtc, &crtc->mode, 2353 intel_set_mode(crtc, &crtc->mode,
2309 crtc->x, crtc->y, 2354 crtc->x, crtc->y, crtc->fb);
2310 crtc->fb);
2311 } 2355 }
2312 2356
2313 return 0; 2357 return 0;
@@ -2341,15 +2385,13 @@ static void intel_dp_encoder_destroy(struct drm_encoder *encoder)
2341} 2385}
2342 2386
2343static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = { 2387static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
2344 .dpms = intel_dp_dpms,
2345 .mode_fixup = intel_dp_mode_fixup, 2388 .mode_fixup = intel_dp_mode_fixup,
2346 .prepare = intel_dp_prepare,
2347 .mode_set = intel_dp_mode_set, 2389 .mode_set = intel_dp_mode_set,
2348 .commit = intel_dp_commit, 2390 .disable = intel_encoder_noop,
2349}; 2391};
2350 2392
2351static const struct drm_connector_funcs intel_dp_connector_funcs = { 2393static const struct drm_connector_funcs intel_dp_connector_funcs = {
2352 .dpms = drm_helper_connector_dpms, 2394 .dpms = intel_dp_dpms,
2353 .detect = intel_dp_detect, 2395 .detect = intel_dp_detect,
2354 .fill_modes = drm_helper_probe_single_connector_modes, 2396 .fill_modes = drm_helper_probe_single_connector_modes,
2355 .set_property = intel_dp_set_property, 2397 .set_property = intel_dp_set_property,
@@ -2436,7 +2478,6 @@ intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
2436 2478
2437 intel_dp->output_reg = output_reg; 2479 intel_dp->output_reg = output_reg;
2438 intel_dp->port = port; 2480 intel_dp->port = port;
2439 intel_dp->dpms_mode = -1;
2440 2481
2441 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); 2482 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
2442 if (!intel_connector) { 2483 if (!intel_connector) {
@@ -2480,6 +2521,11 @@ intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
2480 intel_connector_attach_encoder(intel_connector, intel_encoder); 2521 intel_connector_attach_encoder(intel_connector, intel_encoder);
2481 drm_sysfs_connector_add(connector); 2522 drm_sysfs_connector_add(connector);
2482 2523
2524 intel_encoder->enable = intel_enable_dp;
2525 intel_encoder->disable = intel_disable_dp;
2526 intel_encoder->get_hw_state = intel_dp_get_hw_state;
2527 intel_connector->get_hw_state = intel_connector_get_hw_state;
2528
2483 /* Set up the DDC bus. */ 2529 /* Set up the DDC bus. */
2484 switch (port) { 2530 switch (port) {
2485 case PORT_A: 2531 case PORT_A:
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index ee0beb4833fb..4f2b2d6a2489 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -41,7 +41,11 @@
41 ret__ = -ETIMEDOUT; \ 41 ret__ = -ETIMEDOUT; \
42 break; \ 42 break; \
43 } \ 43 } \
44 if (W && drm_can_sleep()) msleep(W); \ 44 if (W && drm_can_sleep()) { \
45 msleep(W); \
46 } else { \
47 cpu_relax(); \
48 } \
45 } \ 49 } \
46 ret__; \ 50 ret__; \
47}) 51})
@@ -133,6 +137,12 @@ struct intel_fbdev {
133 137
134struct intel_encoder { 138struct intel_encoder {
135 struct drm_encoder base; 139 struct drm_encoder base;
140 /*
141 * The new crtc this encoder will be driven from. Only differs from
142 * base->crtc while a modeset is in progress.
143 */
144 struct intel_crtc *new_crtc;
145
136 int type; 146 int type;
137 bool needs_tv_clock; 147 bool needs_tv_clock;
138 /* 148 /*
@@ -140,13 +150,33 @@ struct intel_encoder {
140 * simple flag is enough to compute the possible_clones mask. 150 * simple flag is enough to compute the possible_clones mask.
141 */ 151 */
142 bool cloneable; 152 bool cloneable;
153 bool connectors_active;
143 void (*hot_plug)(struct intel_encoder *); 154 void (*hot_plug)(struct intel_encoder *);
155 void (*enable)(struct intel_encoder *);
156 void (*disable)(struct intel_encoder *);
157 /* Read out the current hw state of this connector, returning true if
158 * the encoder is active. If the encoder is enabled it also set the pipe
159 * it is connected to in the pipe parameter. */
160 bool (*get_hw_state)(struct intel_encoder *, enum pipe *pipe);
144 int crtc_mask; 161 int crtc_mask;
145}; 162};
146 163
147struct intel_connector { 164struct intel_connector {
148 struct drm_connector base; 165 struct drm_connector base;
166 /*
167 * The fixed encoder this connector is connected to.
168 */
149 struct intel_encoder *encoder; 169 struct intel_encoder *encoder;
170
171 /*
172 * The new encoder this connector will be driven. Only differs from
173 * encoder while a modeset is in progress.
174 */
175 struct intel_encoder *new_encoder;
176
177 /* Reads out the current hw, returning true if the connector is enabled
178 * and active (i.e. dpms ON state). */
179 bool (*get_hw_state)(struct intel_connector *);
150}; 180};
151 181
152struct intel_crtc { 182struct intel_crtc {
@@ -154,8 +184,12 @@ struct intel_crtc {
154 enum pipe pipe; 184 enum pipe pipe;
155 enum plane plane; 185 enum plane plane;
156 u8 lut_r[256], lut_g[256], lut_b[256]; 186 u8 lut_r[256], lut_g[256], lut_b[256];
157 int dpms_mode; 187 /*
158 bool active; /* is the crtc on? independent of the dpms mode */ 188 * Whether the crtc and the connected output pipeline is active. Implies
189 * that crtc->enabled is set, i.e. the current mode configuration has
190 * some outputs connected to this crtc.
191 */
192 bool active;
159 bool primary_disabled; /* is the crtc obscured by a plane? */ 193 bool primary_disabled; /* is the crtc obscured by a plane? */
160 bool lowfreq_avail; 194 bool lowfreq_avail;
161 struct intel_overlay *overlay; 195 struct intel_overlay *overlay;
@@ -307,7 +341,6 @@ struct intel_dp {
307 enum hdmi_force_audio force_audio; 341 enum hdmi_force_audio force_audio;
308 enum port port; 342 enum port port;
309 uint32_t color_range; 343 uint32_t color_range;
310 int dpms_mode;
311 uint8_t link_bw; 344 uint8_t link_bw;
312 uint8_t lane_count; 345 uint8_t lane_count;
313 uint8_t dpcd[DP_RECEIVER_CAP_SIZE]; 346 uint8_t dpcd[DP_RECEIVER_CAP_SIZE];
@@ -409,10 +442,27 @@ extern void intel_panel_disable_backlight(struct drm_device *dev);
409extern void intel_panel_destroy_backlight(struct drm_device *dev); 442extern void intel_panel_destroy_backlight(struct drm_device *dev);
410extern enum drm_connector_status intel_panel_detect(struct drm_device *dev); 443extern enum drm_connector_status intel_panel_detect(struct drm_device *dev);
411 444
445struct intel_set_config {
446 struct drm_encoder **save_connector_encoders;
447 struct drm_crtc **save_encoder_crtcs;
448
449 bool fb_changed;
450 bool mode_changed;
451};
452
453extern bool intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
454 int x, int y, struct drm_framebuffer *old_fb);
455extern void intel_modeset_disable(struct drm_device *dev);
412extern void intel_crtc_load_lut(struct drm_crtc *crtc); 456extern void intel_crtc_load_lut(struct drm_crtc *crtc);
413extern void intel_encoder_prepare(struct drm_encoder *encoder); 457extern void intel_crtc_update_dpms(struct drm_crtc *crtc);
414extern void intel_encoder_commit(struct drm_encoder *encoder); 458extern void intel_encoder_noop(struct drm_encoder *encoder);
415extern void intel_encoder_destroy(struct drm_encoder *encoder); 459extern void intel_encoder_destroy(struct drm_encoder *encoder);
460extern void intel_encoder_dpms(struct intel_encoder *encoder, int mode);
461extern bool intel_encoder_check_is_cloned(struct intel_encoder *encoder);
462extern void intel_connector_dpms(struct drm_connector *, int mode);
463extern bool intel_connector_get_hw_state(struct intel_connector *connector);
464extern void intel_modeset_check_state(struct drm_device *dev);
465
416 466
417static inline struct intel_encoder *intel_attached_encoder(struct drm_connector *connector) 467static inline struct intel_encoder *intel_attached_encoder(struct drm_connector *connector)
418{ 468{
@@ -519,7 +569,10 @@ extern void intel_disable_gt_powersave(struct drm_device *dev);
519extern void gen6_gt_check_fifodbg(struct drm_i915_private *dev_priv); 569extern void gen6_gt_check_fifodbg(struct drm_i915_private *dev_priv);
520extern void ironlake_teardown_rc6(struct drm_device *dev); 570extern void ironlake_teardown_rc6(struct drm_device *dev);
521 571
522extern void intel_ddi_dpms(struct drm_encoder *encoder, int mode); 572extern void intel_enable_ddi(struct intel_encoder *encoder);
573extern void intel_disable_ddi(struct intel_encoder *encoder);
574extern bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
575 enum pipe *pipe);
523extern void intel_ddi_mode_set(struct drm_encoder *encoder, 576extern void intel_ddi_mode_set(struct drm_encoder *encoder,
524 struct drm_display_mode *mode, 577 struct drm_display_mode *mode,
525 struct drm_display_mode *adjusted_mode); 578 struct drm_display_mode *adjusted_mode);
diff --git a/drivers/gpu/drm/i915/intel_dvo.c b/drivers/gpu/drm/i915/intel_dvo.c
index 227551f12d25..4f1fdcc44005 100644
--- a/drivers/gpu/drm/i915/intel_dvo.c
+++ b/drivers/gpu/drm/i915/intel_dvo.c
@@ -105,22 +105,91 @@ static struct intel_dvo *intel_attached_dvo(struct drm_connector *connector)
105 struct intel_dvo, base); 105 struct intel_dvo, base);
106} 106}
107 107
108static void intel_dvo_dpms(struct drm_encoder *encoder, int mode) 108static bool intel_dvo_connector_get_hw_state(struct intel_connector *connector)
109{ 109{
110 struct drm_i915_private *dev_priv = encoder->dev->dev_private; 110 struct intel_dvo *intel_dvo = intel_attached_dvo(&connector->base);
111 struct intel_dvo *intel_dvo = enc_to_intel_dvo(encoder); 111
112 return intel_dvo->dev.dev_ops->get_hw_state(&intel_dvo->dev);
113}
114
115static bool intel_dvo_get_hw_state(struct intel_encoder *encoder,
116 enum pipe *pipe)
117{
118 struct drm_device *dev = encoder->base.dev;
119 struct drm_i915_private *dev_priv = dev->dev_private;
120 struct intel_dvo *intel_dvo = enc_to_intel_dvo(&encoder->base);
121 u32 tmp;
122
123 tmp = I915_READ(intel_dvo->dev.dvo_reg);
124
125 if (!(tmp & DVO_ENABLE))
126 return false;
127
128 *pipe = PORT_TO_PIPE(tmp);
129
130 return true;
131}
132
133static void intel_disable_dvo(struct intel_encoder *encoder)
134{
135 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
136 struct intel_dvo *intel_dvo = enc_to_intel_dvo(&encoder->base);
137 u32 dvo_reg = intel_dvo->dev.dvo_reg;
138 u32 temp = I915_READ(dvo_reg);
139
140 intel_dvo->dev.dev_ops->dpms(&intel_dvo->dev, false);
141 I915_WRITE(dvo_reg, temp & ~DVO_ENABLE);
142 I915_READ(dvo_reg);
143}
144
145static void intel_enable_dvo(struct intel_encoder *encoder)
146{
147 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
148 struct intel_dvo *intel_dvo = enc_to_intel_dvo(&encoder->base);
112 u32 dvo_reg = intel_dvo->dev.dvo_reg; 149 u32 dvo_reg = intel_dvo->dev.dvo_reg;
113 u32 temp = I915_READ(dvo_reg); 150 u32 temp = I915_READ(dvo_reg);
114 151
152 I915_WRITE(dvo_reg, temp | DVO_ENABLE);
153 I915_READ(dvo_reg);
154 intel_dvo->dev.dev_ops->dpms(&intel_dvo->dev, true);
155}
156
157static void intel_dvo_dpms(struct drm_connector *connector, int mode)
158{
159 struct intel_dvo *intel_dvo = intel_attached_dvo(connector);
160 struct drm_crtc *crtc;
161
162 /* dvo supports only 2 dpms states. */
163 if (mode != DRM_MODE_DPMS_ON)
164 mode = DRM_MODE_DPMS_OFF;
165
166 if (mode == connector->dpms)
167 return;
168
169 connector->dpms = mode;
170
171 /* Only need to change hw state when actually enabled */
172 crtc = intel_dvo->base.base.crtc;
173 if (!crtc) {
174 intel_dvo->base.connectors_active = false;
175 return;
176 }
177
115 if (mode == DRM_MODE_DPMS_ON) { 178 if (mode == DRM_MODE_DPMS_ON) {
116 I915_WRITE(dvo_reg, temp | DVO_ENABLE); 179 intel_dvo->base.connectors_active = true;
117 I915_READ(dvo_reg); 180
181 intel_crtc_update_dpms(crtc);
182
118 intel_dvo->dev.dev_ops->dpms(&intel_dvo->dev, true); 183 intel_dvo->dev.dev_ops->dpms(&intel_dvo->dev, true);
119 } else { 184 } else {
120 intel_dvo->dev.dev_ops->dpms(&intel_dvo->dev, false); 185 intel_dvo->dev.dev_ops->dpms(&intel_dvo->dev, false);
121 I915_WRITE(dvo_reg, temp & ~DVO_ENABLE); 186
122 I915_READ(dvo_reg); 187 intel_dvo->base.connectors_active = false;
188
189 intel_crtc_update_dpms(crtc);
123 } 190 }
191
192 intel_modeset_check_state(connector->dev);
124} 193}
125 194
126static int intel_dvo_mode_valid(struct drm_connector *connector, 195static int intel_dvo_mode_valid(struct drm_connector *connector,
@@ -275,15 +344,13 @@ static void intel_dvo_destroy(struct drm_connector *connector)
275} 344}
276 345
277static const struct drm_encoder_helper_funcs intel_dvo_helper_funcs = { 346static const struct drm_encoder_helper_funcs intel_dvo_helper_funcs = {
278 .dpms = intel_dvo_dpms,
279 .mode_fixup = intel_dvo_mode_fixup, 347 .mode_fixup = intel_dvo_mode_fixup,
280 .prepare = intel_encoder_prepare,
281 .mode_set = intel_dvo_mode_set, 348 .mode_set = intel_dvo_mode_set,
282 .commit = intel_encoder_commit, 349 .disable = intel_encoder_noop,
283}; 350};
284 351
285static const struct drm_connector_funcs intel_dvo_connector_funcs = { 352static const struct drm_connector_funcs intel_dvo_connector_funcs = {
286 .dpms = drm_helper_connector_dpms, 353 .dpms = intel_dvo_dpms,
287 .detect = intel_dvo_detect, 354 .detect = intel_dvo_detect,
288 .destroy = intel_dvo_destroy, 355 .destroy = intel_dvo_destroy,
289 .fill_modes = drm_helper_probe_single_connector_modes, 356 .fill_modes = drm_helper_probe_single_connector_modes,
@@ -372,6 +439,11 @@ void intel_dvo_init(struct drm_device *dev)
372 drm_encoder_init(dev, &intel_encoder->base, 439 drm_encoder_init(dev, &intel_encoder->base,
373 &intel_dvo_enc_funcs, encoder_type); 440 &intel_dvo_enc_funcs, encoder_type);
374 441
442 intel_encoder->disable = intel_disable_dvo;
443 intel_encoder->enable = intel_enable_dvo;
444 intel_encoder->get_hw_state = intel_dvo_get_hw_state;
445 intel_connector->get_hw_state = intel_dvo_connector_get_hw_state;
446
375 /* Now, try to find a controller */ 447 /* Now, try to find a controller */
376 for (i = 0; i < ARRAY_SIZE(intel_dvo_devices); i++) { 448 for (i = 0; i < ARRAY_SIZE(intel_dvo_devices); i++) {
377 struct drm_connector *connector = &intel_connector->base; 449 struct drm_connector *connector = &intel_connector->base;
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index 35a6ee7a8cca..5d02aad0de8e 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -601,11 +601,32 @@ static void intel_hdmi_mode_set(struct drm_encoder *encoder,
601 intel_hdmi->set_infoframes(encoder, adjusted_mode); 601 intel_hdmi->set_infoframes(encoder, adjusted_mode);
602} 602}
603 603
604static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode) 604static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
605 enum pipe *pipe)
605{ 606{
606 struct drm_device *dev = encoder->dev; 607 struct drm_device *dev = encoder->base.dev;
607 struct drm_i915_private *dev_priv = dev->dev_private; 608 struct drm_i915_private *dev_priv = dev->dev_private;
608 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 609 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
610 u32 tmp;
611
612 tmp = I915_READ(intel_hdmi->sdvox_reg);
613
614 if (!(tmp & SDVO_ENABLE))
615 return false;
616
617 if (HAS_PCH_CPT(dev))
618 *pipe = PORT_TO_PIPE_CPT(tmp);
619 else
620 *pipe = PORT_TO_PIPE(tmp);
621
622 return true;
623}
624
625static void intel_enable_hdmi(struct intel_encoder *encoder)
626{
627 struct drm_device *dev = encoder->base.dev;
628 struct drm_i915_private *dev_priv = dev->dev_private;
629 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
609 u32 temp; 630 u32 temp;
610 u32 enable_bits = SDVO_ENABLE; 631 u32 enable_bits = SDVO_ENABLE;
611 632
@@ -617,31 +638,12 @@ static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
617 /* HW workaround for IBX, we need to move the port to transcoder A 638 /* HW workaround for IBX, we need to move the port to transcoder A
618 * before disabling it. */ 639 * before disabling it. */
619 if (HAS_PCH_IBX(dev)) { 640 if (HAS_PCH_IBX(dev)) {
620 struct drm_crtc *crtc = encoder->crtc; 641 struct drm_crtc *crtc = encoder->base.crtc;
621 int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1; 642 int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
622 643
623 if (mode != DRM_MODE_DPMS_ON) { 644 /* Restore the transcoder select bit. */
624 if (temp & SDVO_PIPE_B_SELECT) { 645 if (pipe == PIPE_B)
625 temp &= ~SDVO_PIPE_B_SELECT; 646 enable_bits |= SDVO_PIPE_B_SELECT;
626 I915_WRITE(intel_hdmi->sdvox_reg, temp);
627 POSTING_READ(intel_hdmi->sdvox_reg);
628
629 /* Again we need to write this twice. */
630 I915_WRITE(intel_hdmi->sdvox_reg, temp);
631 POSTING_READ(intel_hdmi->sdvox_reg);
632
633 /* Transcoder selection bits only update
634 * effectively on vblank. */
635 if (crtc)
636 intel_wait_for_vblank(dev, pipe);
637 else
638 msleep(50);
639 }
640 } else {
641 /* Restore the transcoder select bit. */
642 if (pipe == PIPE_B)
643 enable_bits |= SDVO_PIPE_B_SELECT;
644 }
645 } 647 }
646 648
647 /* HW workaround, need to toggle enable bit off and on for 12bpc, but 649 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
@@ -652,11 +654,66 @@ static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
652 POSTING_READ(intel_hdmi->sdvox_reg); 654 POSTING_READ(intel_hdmi->sdvox_reg);
653 } 655 }
654 656
655 if (mode != DRM_MODE_DPMS_ON) { 657 temp |= enable_bits;
656 temp &= ~enable_bits; 658
657 } else { 659 I915_WRITE(intel_hdmi->sdvox_reg, temp);
658 temp |= enable_bits; 660 POSTING_READ(intel_hdmi->sdvox_reg);
661
662 /* HW workaround, need to write this twice for issue that may result
663 * in first write getting masked.
664 */
665 if (HAS_PCH_SPLIT(dev)) {
666 I915_WRITE(intel_hdmi->sdvox_reg, temp);
667 POSTING_READ(intel_hdmi->sdvox_reg);
659 } 668 }
669}
670
671static void intel_disable_hdmi(struct intel_encoder *encoder)
672{
673 struct drm_device *dev = encoder->base.dev;
674 struct drm_i915_private *dev_priv = dev->dev_private;
675 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
676 u32 temp;
677 u32 enable_bits = SDVO_ENABLE;
678
679 if (intel_hdmi->has_audio)
680 enable_bits |= SDVO_AUDIO_ENABLE;
681
682 temp = I915_READ(intel_hdmi->sdvox_reg);
683
684 /* HW workaround for IBX, we need to move the port to transcoder A
685 * before disabling it. */
686 if (HAS_PCH_IBX(dev)) {
687 struct drm_crtc *crtc = encoder->base.crtc;
688 int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
689
690 if (temp & SDVO_PIPE_B_SELECT) {
691 temp &= ~SDVO_PIPE_B_SELECT;
692 I915_WRITE(intel_hdmi->sdvox_reg, temp);
693 POSTING_READ(intel_hdmi->sdvox_reg);
694
695 /* Again we need to write this twice. */
696 I915_WRITE(intel_hdmi->sdvox_reg, temp);
697 POSTING_READ(intel_hdmi->sdvox_reg);
698
699 /* Transcoder selection bits only update
700 * effectively on vblank. */
701 if (crtc)
702 intel_wait_for_vblank(dev, pipe);
703 else
704 msleep(50);
705 }
706 }
707
708 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
709 * we do this anyway which shows more stable in testing.
710 */
711 if (HAS_PCH_SPLIT(dev)) {
712 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
713 POSTING_READ(intel_hdmi->sdvox_reg);
714 }
715
716 temp &= ~enable_bits;
660 717
661 I915_WRITE(intel_hdmi->sdvox_reg, temp); 718 I915_WRITE(intel_hdmi->sdvox_reg, temp);
662 POSTING_READ(intel_hdmi->sdvox_reg); 719 POSTING_READ(intel_hdmi->sdvox_reg);
@@ -830,9 +887,8 @@ intel_hdmi_set_property(struct drm_connector *connector,
830done: 887done:
831 if (intel_hdmi->base.base.crtc) { 888 if (intel_hdmi->base.base.crtc) {
832 struct drm_crtc *crtc = intel_hdmi->base.base.crtc; 889 struct drm_crtc *crtc = intel_hdmi->base.base.crtc;
833 drm_crtc_helper_set_mode(crtc, &crtc->mode, 890 intel_set_mode(crtc, &crtc->mode,
834 crtc->x, crtc->y, 891 crtc->x, crtc->y, crtc->fb);
835 crtc->fb);
836 } 892 }
837 893
838 return 0; 894 return 0;
@@ -846,23 +902,19 @@ static void intel_hdmi_destroy(struct drm_connector *connector)
846} 902}
847 903
848static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs_hsw = { 904static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs_hsw = {
849 .dpms = intel_ddi_dpms,
850 .mode_fixup = intel_hdmi_mode_fixup, 905 .mode_fixup = intel_hdmi_mode_fixup,
851 .prepare = intel_encoder_prepare,
852 .mode_set = intel_ddi_mode_set, 906 .mode_set = intel_ddi_mode_set,
853 .commit = intel_encoder_commit, 907 .disable = intel_encoder_noop,
854}; 908};
855 909
856static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = { 910static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
857 .dpms = intel_hdmi_dpms,
858 .mode_fixup = intel_hdmi_mode_fixup, 911 .mode_fixup = intel_hdmi_mode_fixup,
859 .prepare = intel_encoder_prepare,
860 .mode_set = intel_hdmi_mode_set, 912 .mode_set = intel_hdmi_mode_set,
861 .commit = intel_encoder_commit, 913 .disable = intel_encoder_noop,
862}; 914};
863 915
864static const struct drm_connector_funcs intel_hdmi_connector_funcs = { 916static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
865 .dpms = drm_helper_connector_dpms, 917 .dpms = intel_connector_dpms,
866 .detect = intel_hdmi_detect, 918 .detect = intel_hdmi_detect,
867 .fill_modes = drm_helper_probe_single_connector_modes, 919 .fill_modes = drm_helper_probe_single_connector_modes,
868 .set_property = intel_hdmi_set_property, 920 .set_property = intel_hdmi_set_property,
@@ -961,10 +1013,21 @@ void intel_hdmi_init(struct drm_device *dev, int sdvox_reg, enum port port)
961 intel_hdmi->set_infoframes = cpt_set_infoframes; 1013 intel_hdmi->set_infoframes = cpt_set_infoframes;
962 } 1014 }
963 1015
964 if (IS_HASWELL(dev)) 1016 if (IS_HASWELL(dev)) {
965 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs_hsw); 1017 intel_encoder->enable = intel_enable_ddi;
966 else 1018 intel_encoder->disable = intel_disable_ddi;
967 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs); 1019 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
1020 drm_encoder_helper_add(&intel_encoder->base,
1021 &intel_hdmi_helper_funcs_hsw);
1022 } else {
1023 intel_encoder->enable = intel_enable_hdmi;
1024 intel_encoder->disable = intel_disable_hdmi;
1025 intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
1026 drm_encoder_helper_add(&intel_encoder->base,
1027 &intel_hdmi_helper_funcs);
1028 }
1029 intel_connector->get_hw_state = intel_connector_get_hw_state;
1030
968 1031
969 intel_hdmi_add_properties(intel_hdmi, connector); 1032 intel_hdmi_add_properties(intel_hdmi, connector);
970 1033
diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
index d789fdad5d37..dc9f9ff34d8c 100644
--- a/drivers/gpu/drm/i915/intel_lvds.c
+++ b/drivers/gpu/drm/i915/intel_lvds.c
@@ -65,13 +65,40 @@ static struct intel_lvds *intel_attached_lvds(struct drm_connector *connector)
65 struct intel_lvds, base); 65 struct intel_lvds, base);
66} 66}
67 67
68static bool intel_lvds_get_hw_state(struct intel_encoder *encoder,
69 enum pipe *pipe)
70{
71 struct drm_device *dev = encoder->base.dev;
72 struct drm_i915_private *dev_priv = dev->dev_private;
73 u32 lvds_reg, tmp;
74
75 if (HAS_PCH_SPLIT(dev)) {
76 lvds_reg = PCH_LVDS;
77 } else {
78 lvds_reg = LVDS;
79 }
80
81 tmp = I915_READ(lvds_reg);
82
83 if (!(tmp & LVDS_PORT_EN))
84 return false;
85
86 if (HAS_PCH_CPT(dev))
87 *pipe = PORT_TO_PIPE_CPT(tmp);
88 else
89 *pipe = PORT_TO_PIPE(tmp);
90
91 return true;
92}
93
68/** 94/**
69 * Sets the power state for the panel. 95 * Sets the power state for the panel.
70 */ 96 */
71static void intel_lvds_enable(struct intel_lvds *intel_lvds) 97static void intel_enable_lvds(struct intel_encoder *encoder)
72{ 98{
73 struct drm_device *dev = intel_lvds->base.base.dev; 99 struct drm_device *dev = encoder->base.dev;
74 struct intel_crtc *intel_crtc = to_intel_crtc(intel_lvds->base.base.crtc); 100 struct intel_lvds *intel_lvds = to_intel_lvds(&encoder->base);
101 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
75 struct drm_i915_private *dev_priv = dev->dev_private; 102 struct drm_i915_private *dev_priv = dev->dev_private;
76 u32 ctl_reg, lvds_reg, stat_reg; 103 u32 ctl_reg, lvds_reg, stat_reg;
77 104
@@ -111,9 +138,10 @@ static void intel_lvds_enable(struct intel_lvds *intel_lvds)
111 intel_panel_enable_backlight(dev, intel_crtc->pipe); 138 intel_panel_enable_backlight(dev, intel_crtc->pipe);
112} 139}
113 140
114static void intel_lvds_disable(struct intel_lvds *intel_lvds) 141static void intel_disable_lvds(struct intel_encoder *encoder)
115{ 142{
116 struct drm_device *dev = intel_lvds->base.base.dev; 143 struct drm_device *dev = encoder->base.dev;
144 struct intel_lvds *intel_lvds = to_intel_lvds(&encoder->base);
117 struct drm_i915_private *dev_priv = dev->dev_private; 145 struct drm_i915_private *dev_priv = dev->dev_private;
118 u32 ctl_reg, lvds_reg, stat_reg; 146 u32 ctl_reg, lvds_reg, stat_reg;
119 147
@@ -142,18 +170,6 @@ static void intel_lvds_disable(struct intel_lvds *intel_lvds)
142 POSTING_READ(lvds_reg); 170 POSTING_READ(lvds_reg);
143} 171}
144 172
145static void intel_lvds_dpms(struct drm_encoder *encoder, int mode)
146{
147 struct intel_lvds *intel_lvds = to_intel_lvds(encoder);
148
149 if (mode == DRM_MODE_DPMS_ON)
150 intel_lvds_enable(intel_lvds);
151 else
152 intel_lvds_disable(intel_lvds);
153
154 /* XXX: We never power down the LVDS pairs. */
155}
156
157static int intel_lvds_mode_valid(struct drm_connector *connector, 173static int intel_lvds_mode_valid(struct drm_connector *connector,
158 struct drm_display_mode *mode) 174 struct drm_display_mode *mode)
159{ 175{
@@ -234,9 +250,8 @@ static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
234{ 250{
235 struct drm_device *dev = encoder->dev; 251 struct drm_device *dev = encoder->dev;
236 struct drm_i915_private *dev_priv = dev->dev_private; 252 struct drm_i915_private *dev_priv = dev->dev_private;
237 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
238 struct intel_lvds *intel_lvds = to_intel_lvds(encoder); 253 struct intel_lvds *intel_lvds = to_intel_lvds(encoder);
239 struct intel_encoder *tmp_encoder; 254 struct intel_crtc *intel_crtc = intel_lvds->base.new_crtc;
240 u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0; 255 u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0;
241 int pipe; 256 int pipe;
242 257
@@ -246,14 +261,8 @@ static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
246 return false; 261 return false;
247 } 262 }
248 263
249 /* Should never happen!! */ 264 if (intel_encoder_check_is_cloned(&intel_lvds->base))
250 for_each_encoder_on_crtc(dev, encoder->crtc, tmp_encoder) { 265 return false;
251 if (&tmp_encoder->base != encoder) {
252 DRM_ERROR("Can't enable LVDS and another "
253 "encoder on the same pipe\n");
254 return false;
255 }
256 }
257 266
258 /* 267 /*
259 * We have timings from the BIOS for the panel, put them in 268 * We have timings from the BIOS for the panel, put them in
@@ -405,23 +414,6 @@ out:
405 return true; 414 return true;
406} 415}
407 416
408static void intel_lvds_prepare(struct drm_encoder *encoder)
409{
410 struct intel_lvds *intel_lvds = to_intel_lvds(encoder);
411
412 intel_lvds_disable(intel_lvds);
413}
414
415static void intel_lvds_commit(struct drm_encoder *encoder)
416{
417 struct intel_lvds *intel_lvds = to_intel_lvds(encoder);
418
419 /* Always do a full power on as we do not know what state
420 * we were left in.
421 */
422 intel_lvds_enable(intel_lvds);
423}
424
425static void intel_lvds_mode_set(struct drm_encoder *encoder, 417static void intel_lvds_mode_set(struct drm_encoder *encoder,
426 struct drm_display_mode *mode, 418 struct drm_display_mode *mode,
427 struct drm_display_mode *adjusted_mode) 419 struct drm_display_mode *adjusted_mode)
@@ -535,7 +527,7 @@ static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
535 dev_priv->modeset_on_lid = 0; 527 dev_priv->modeset_on_lid = 0;
536 528
537 mutex_lock(&dev->mode_config.mutex); 529 mutex_lock(&dev->mode_config.mutex);
538 drm_helper_resume_force_mode(dev); 530 intel_modeset_check_state(dev);
539 mutex_unlock(&dev->mode_config.mutex); 531 mutex_unlock(&dev->mode_config.mutex);
540 532
541 return NOTIFY_OK; 533 return NOTIFY_OK;
@@ -587,8 +579,8 @@ static int intel_lvds_set_property(struct drm_connector *connector,
587 * If the CRTC is enabled, the display will be changed 579 * If the CRTC is enabled, the display will be changed
588 * according to the new panel fitting mode. 580 * according to the new panel fitting mode.
589 */ 581 */
590 drm_crtc_helper_set_mode(crtc, &crtc->mode, 582 intel_set_mode(crtc, &crtc->mode,
591 crtc->x, crtc->y, crtc->fb); 583 crtc->x, crtc->y, crtc->fb);
592 } 584 }
593 } 585 }
594 586
@@ -596,11 +588,9 @@ static int intel_lvds_set_property(struct drm_connector *connector,
596} 588}
597 589
598static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = { 590static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {
599 .dpms = intel_lvds_dpms,
600 .mode_fixup = intel_lvds_mode_fixup, 591 .mode_fixup = intel_lvds_mode_fixup,
601 .prepare = intel_lvds_prepare,
602 .mode_set = intel_lvds_mode_set, 592 .mode_set = intel_lvds_mode_set,
603 .commit = intel_lvds_commit, 593 .disable = intel_encoder_noop,
604}; 594};
605 595
606static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = { 596static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
@@ -610,7 +600,7 @@ static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs
610}; 600};
611 601
612static const struct drm_connector_funcs intel_lvds_connector_funcs = { 602static const struct drm_connector_funcs intel_lvds_connector_funcs = {
613 .dpms = drm_helper_connector_dpms, 603 .dpms = intel_connector_dpms,
614 .detect = intel_lvds_detect, 604 .detect = intel_lvds_detect,
615 .fill_modes = drm_helper_probe_single_connector_modes, 605 .fill_modes = drm_helper_probe_single_connector_modes,
616 .set_property = intel_lvds_set_property, 606 .set_property = intel_lvds_set_property,
@@ -964,6 +954,11 @@ bool intel_lvds_init(struct drm_device *dev)
964 drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs, 954 drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
965 DRM_MODE_ENCODER_LVDS); 955 DRM_MODE_ENCODER_LVDS);
966 956
957 intel_encoder->enable = intel_enable_lvds;
958 intel_encoder->disable = intel_disable_lvds;
959 intel_encoder->get_hw_state = intel_lvds_get_hw_state;
960 intel_connector->get_hw_state = intel_connector_get_hw_state;
961
967 intel_connector_attach_encoder(intel_connector, intel_encoder); 962 intel_connector_attach_encoder(intel_connector, intel_encoder);
968 intel_encoder->type = INTEL_OUTPUT_LVDS; 963 intel_encoder->type = INTEL_OUTPUT_LVDS;
969 964
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index a465debdfcf7..36c64091bc90 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -31,6 +31,8 @@
31#include "../../../platform/x86/intel_ips.h" 31#include "../../../platform/x86/intel_ips.h"
32#include <linux/module.h> 32#include <linux/module.h>
33 33
34#define FORCEWAKE_ACK_TIMEOUT_MS 2
35
34/* FBC, or Frame Buffer Compression, is a technique employed to compress the 36/* FBC, or Frame Buffer Compression, is a technique employed to compress the
35 * framebuffer contents in-memory, aiming at reducing the required bandwidth 37 * framebuffer contents in-memory, aiming at reducing the required bandwidth
36 * during in-memory transfers and, therefore, reduce the power packet. 38 * during in-memory transfers and, therefore, reduce the power packet.
@@ -593,7 +595,7 @@ static void i915_ironlake_get_mem_freq(struct drm_device *dev)
593 break; 595 break;
594 } 596 }
595 597
596 dev_priv->r_t = dev_priv->mem_freq; 598 dev_priv->ips.r_t = dev_priv->mem_freq;
597 599
598 switch (csipll & 0x3ff) { 600 switch (csipll & 0x3ff) {
599 case 0x00c: 601 case 0x00c:
@@ -625,11 +627,11 @@ static void i915_ironlake_get_mem_freq(struct drm_device *dev)
625 } 627 }
626 628
627 if (dev_priv->fsb_freq == 3200) { 629 if (dev_priv->fsb_freq == 3200) {
628 dev_priv->c_m = 0; 630 dev_priv->ips.c_m = 0;
629 } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { 631 } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) {
630 dev_priv->c_m = 1; 632 dev_priv->ips.c_m = 1;
631 } else { 633 } else {
632 dev_priv->c_m = 2; 634 dev_priv->ips.c_m = 2;
633 } 635 }
634} 636}
635 637
@@ -2162,12 +2164,6 @@ err_unref:
2162 2164
2163/** 2165/**
2164 * Lock protecting IPS related data structures 2166 * Lock protecting IPS related data structures
2165 * - i915_mch_dev
2166 * - dev_priv->max_delay
2167 * - dev_priv->min_delay
2168 * - dev_priv->fmax
2169 * - dev_priv->gpu_busy
2170 * - dev_priv->gfx_power
2171 */ 2167 */
2172DEFINE_SPINLOCK(mchdev_lock); 2168DEFINE_SPINLOCK(mchdev_lock);
2173 2169
@@ -2230,12 +2226,12 @@ static void ironlake_enable_drps(struct drm_device *dev)
2230 vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> 2226 vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >>
2231 PXVFREQ_PX_SHIFT; 2227 PXVFREQ_PX_SHIFT;
2232 2228
2233 dev_priv->fmax = fmax; /* IPS callback will increase this */ 2229 dev_priv->ips.fmax = fmax; /* IPS callback will increase this */
2234 dev_priv->fstart = fstart; 2230 dev_priv->ips.fstart = fstart;
2235 2231
2236 dev_priv->max_delay = fstart; 2232 dev_priv->ips.max_delay = fstart;
2237 dev_priv->min_delay = fmin; 2233 dev_priv->ips.min_delay = fmin;
2238 dev_priv->cur_delay = fstart; 2234 dev_priv->ips.cur_delay = fstart;
2239 2235
2240 DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", 2236 DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n",
2241 fmax, fmin, fstart); 2237 fmax, fmin, fstart);
@@ -2258,11 +2254,11 @@ static void ironlake_enable_drps(struct drm_device *dev)
2258 2254
2259 ironlake_set_drps(dev, fstart); 2255 ironlake_set_drps(dev, fstart);
2260 2256
2261 dev_priv->last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) + 2257 dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) +
2262 I915_READ(0x112e0); 2258 I915_READ(0x112e0);
2263 dev_priv->last_time1 = jiffies_to_msecs(jiffies); 2259 dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies);
2264 dev_priv->last_count2 = I915_READ(0x112f4); 2260 dev_priv->ips.last_count2 = I915_READ(0x112f4);
2265 getrawmonotonic(&dev_priv->last_time2); 2261 getrawmonotonic(&dev_priv->ips.last_time2);
2266 2262
2267 spin_unlock_irq(&mchdev_lock); 2263 spin_unlock_irq(&mchdev_lock);
2268} 2264}
@@ -2284,7 +2280,7 @@ static void ironlake_disable_drps(struct drm_device *dev)
2284 I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); 2280 I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT);
2285 2281
2286 /* Go back to the starting frequency */ 2282 /* Go back to the starting frequency */
2287 ironlake_set_drps(dev, dev_priv->fstart); 2283 ironlake_set_drps(dev, dev_priv->ips.fstart);
2288 mdelay(1); 2284 mdelay(1);
2289 rgvswctl |= MEMCTL_CMD_STS; 2285 rgvswctl |= MEMCTL_CMD_STS;
2290 I915_WRITE(MEMSWCTL, rgvswctl); 2286 I915_WRITE(MEMSWCTL, rgvswctl);
@@ -2343,6 +2339,8 @@ void gen6_set_rps(struct drm_device *dev, u8 val)
2343 I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, limits); 2339 I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, limits);
2344 2340
2345 dev_priv->rps.cur_delay = val; 2341 dev_priv->rps.cur_delay = val;
2342
2343 trace_intel_gpu_freq_change(val * 50);
2346} 2344}
2347 2345
2348static void gen6_disable_rps(struct drm_device *dev) 2346static void gen6_disable_rps(struct drm_device *dev)
@@ -2741,7 +2739,7 @@ unsigned long i915_chipset_val(struct drm_i915_private *dev_priv)
2741 2739
2742 assert_spin_locked(&mchdev_lock); 2740 assert_spin_locked(&mchdev_lock);
2743 2741
2744 diff1 = now - dev_priv->last_time1; 2742 diff1 = now - dev_priv->ips.last_time1;
2745 2743
2746 /* Prevent division-by-zero if we are asking too fast. 2744 /* Prevent division-by-zero if we are asking too fast.
2747 * Also, we don't get interesting results if we are polling 2745 * Also, we don't get interesting results if we are polling
@@ -2749,7 +2747,7 @@ unsigned long i915_chipset_val(struct drm_i915_private *dev_priv)
2749 * in such cases. 2747 * in such cases.
2750 */ 2748 */
2751 if (diff1 <= 10) 2749 if (diff1 <= 10)
2752 return dev_priv->chipset_power; 2750 return dev_priv->ips.chipset_power;
2753 2751
2754 count1 = I915_READ(DMIEC); 2752 count1 = I915_READ(DMIEC);
2755 count2 = I915_READ(DDREC); 2753 count2 = I915_READ(DDREC);
@@ -2758,16 +2756,16 @@ unsigned long i915_chipset_val(struct drm_i915_private *dev_priv)
2758 total_count = count1 + count2 + count3; 2756 total_count = count1 + count2 + count3;
2759 2757
2760 /* FIXME: handle per-counter overflow */ 2758 /* FIXME: handle per-counter overflow */
2761 if (total_count < dev_priv->last_count1) { 2759 if (total_count < dev_priv->ips.last_count1) {
2762 diff = ~0UL - dev_priv->last_count1; 2760 diff = ~0UL - dev_priv->ips.last_count1;
2763 diff += total_count; 2761 diff += total_count;
2764 } else { 2762 } else {
2765 diff = total_count - dev_priv->last_count1; 2763 diff = total_count - dev_priv->ips.last_count1;
2766 } 2764 }
2767 2765
2768 for (i = 0; i < ARRAY_SIZE(cparams); i++) { 2766 for (i = 0; i < ARRAY_SIZE(cparams); i++) {
2769 if (cparams[i].i == dev_priv->c_m && 2767 if (cparams[i].i == dev_priv->ips.c_m &&
2770 cparams[i].t == dev_priv->r_t) { 2768 cparams[i].t == dev_priv->ips.r_t) {
2771 m = cparams[i].m; 2769 m = cparams[i].m;
2772 c = cparams[i].c; 2770 c = cparams[i].c;
2773 break; 2771 break;
@@ -2778,10 +2776,10 @@ unsigned long i915_chipset_val(struct drm_i915_private *dev_priv)
2778 ret = ((m * diff) + c); 2776 ret = ((m * diff) + c);
2779 ret = div_u64(ret, 10); 2777 ret = div_u64(ret, 10);
2780 2778
2781 dev_priv->last_count1 = total_count; 2779 dev_priv->ips.last_count1 = total_count;
2782 dev_priv->last_time1 = now; 2780 dev_priv->ips.last_time1 = now;
2783 2781
2784 dev_priv->chipset_power = ret; 2782 dev_priv->ips.chipset_power = ret;
2785 2783
2786 return ret; 2784 return ret;
2787} 2785}
@@ -2952,7 +2950,7 @@ static void __i915_update_gfx_val(struct drm_i915_private *dev_priv)
2952 assert_spin_locked(&mchdev_lock); 2950 assert_spin_locked(&mchdev_lock);
2953 2951
2954 getrawmonotonic(&now); 2952 getrawmonotonic(&now);
2955 diff1 = timespec_sub(now, dev_priv->last_time2); 2953 diff1 = timespec_sub(now, dev_priv->ips.last_time2);
2956 2954
2957 /* Don't divide by 0 */ 2955 /* Don't divide by 0 */
2958 diffms = diff1.tv_sec * 1000 + diff1.tv_nsec / 1000000; 2956 diffms = diff1.tv_sec * 1000 + diff1.tv_nsec / 1000000;
@@ -2961,20 +2959,20 @@ static void __i915_update_gfx_val(struct drm_i915_private *dev_priv)
2961 2959
2962 count = I915_READ(GFXEC); 2960 count = I915_READ(GFXEC);
2963 2961
2964 if (count < dev_priv->last_count2) { 2962 if (count < dev_priv->ips.last_count2) {
2965 diff = ~0UL - dev_priv->last_count2; 2963 diff = ~0UL - dev_priv->ips.last_count2;
2966 diff += count; 2964 diff += count;
2967 } else { 2965 } else {
2968 diff = count - dev_priv->last_count2; 2966 diff = count - dev_priv->ips.last_count2;
2969 } 2967 }
2970 2968
2971 dev_priv->last_count2 = count; 2969 dev_priv->ips.last_count2 = count;
2972 dev_priv->last_time2 = now; 2970 dev_priv->ips.last_time2 = now;
2973 2971
2974 /* More magic constants... */ 2972 /* More magic constants... */
2975 diff = diff * 1181; 2973 diff = diff * 1181;
2976 diff = div_u64(diff, diffms * 10); 2974 diff = div_u64(diff, diffms * 10);
2977 dev_priv->gfx_power = diff; 2975 dev_priv->ips.gfx_power = diff;
2978} 2976}
2979 2977
2980void i915_update_gfx_val(struct drm_i915_private *dev_priv) 2978void i915_update_gfx_val(struct drm_i915_private *dev_priv)
@@ -3016,14 +3014,14 @@ unsigned long i915_gfx_val(struct drm_i915_private *dev_priv)
3016 3014
3017 corr = corr * ((150142 * state1) / 10000 - 78642); 3015 corr = corr * ((150142 * state1) / 10000 - 78642);
3018 corr /= 100000; 3016 corr /= 100000;
3019 corr2 = (corr * dev_priv->corr); 3017 corr2 = (corr * dev_priv->ips.corr);
3020 3018
3021 state2 = (corr2 * state1) / 10000; 3019 state2 = (corr2 * state1) / 10000;
3022 state2 /= 100; /* convert to mW */ 3020 state2 /= 100; /* convert to mW */
3023 3021
3024 __i915_update_gfx_val(dev_priv); 3022 __i915_update_gfx_val(dev_priv);
3025 3023
3026 return dev_priv->gfx_power + state2; 3024 return dev_priv->ips.gfx_power + state2;
3027} 3025}
3028 3026
3029/** 3027/**
@@ -3071,8 +3069,8 @@ bool i915_gpu_raise(void)
3071 } 3069 }
3072 dev_priv = i915_mch_dev; 3070 dev_priv = i915_mch_dev;
3073 3071
3074 if (dev_priv->max_delay > dev_priv->fmax) 3072 if (dev_priv->ips.max_delay > dev_priv->ips.fmax)
3075 dev_priv->max_delay--; 3073 dev_priv->ips.max_delay--;
3076 3074
3077out_unlock: 3075out_unlock:
3078 spin_unlock_irq(&mchdev_lock); 3076 spin_unlock_irq(&mchdev_lock);
@@ -3099,8 +3097,8 @@ bool i915_gpu_lower(void)
3099 } 3097 }
3100 dev_priv = i915_mch_dev; 3098 dev_priv = i915_mch_dev;
3101 3099
3102 if (dev_priv->max_delay < dev_priv->min_delay) 3100 if (dev_priv->ips.max_delay < dev_priv->ips.min_delay)
3103 dev_priv->max_delay++; 3101 dev_priv->ips.max_delay++;
3104 3102
3105out_unlock: 3103out_unlock:
3106 spin_unlock_irq(&mchdev_lock); 3104 spin_unlock_irq(&mchdev_lock);
@@ -3154,9 +3152,9 @@ bool i915_gpu_turbo_disable(void)
3154 } 3152 }
3155 dev_priv = i915_mch_dev; 3153 dev_priv = i915_mch_dev;
3156 3154
3157 dev_priv->max_delay = dev_priv->fstart; 3155 dev_priv->ips.max_delay = dev_priv->ips.fstart;
3158 3156
3159 if (!ironlake_set_drps(dev_priv->dev, dev_priv->fstart)) 3157 if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart))
3160 ret = false; 3158 ret = false;
3161 3159
3162out_unlock: 3160out_unlock:
@@ -3271,7 +3269,7 @@ static void intel_init_emon(struct drm_device *dev)
3271 3269
3272 lcfuse = I915_READ(LCFUSE02); 3270 lcfuse = I915_READ(LCFUSE02);
3273 3271
3274 dev_priv->corr = (lcfuse & LCFUSE_HIV_MASK); 3272 dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK);
3275} 3273}
3276 3274
3277void intel_disable_gt_powersave(struct drm_device *dev) 3275void intel_disable_gt_powersave(struct drm_device *dev)
@@ -3966,14 +3964,16 @@ static void __gen6_gt_force_wake_get(struct drm_i915_private *dev_priv)
3966 else 3964 else
3967 forcewake_ack = FORCEWAKE_ACK; 3965 forcewake_ack = FORCEWAKE_ACK;
3968 3966
3969 if (wait_for_atomic_us((I915_READ_NOTRACE(forcewake_ack) & 1) == 0, 500)) 3967 if (wait_for_atomic((I915_READ_NOTRACE(forcewake_ack) & 1) == 0,
3970 DRM_ERROR("Force wake wait timed out\n"); 3968 FORCEWAKE_ACK_TIMEOUT_MS))
3969 DRM_ERROR("Timed out waiting for forcewake old ack to clear.\n");
3971 3970
3972 I915_WRITE_NOTRACE(FORCEWAKE, 1); 3971 I915_WRITE_NOTRACE(FORCEWAKE, 1);
3973 POSTING_READ(FORCEWAKE); 3972 POSTING_READ(ECOBUS); /* something from same cacheline, but !FORCEWAKE */
3974 3973
3975 if (wait_for_atomic_us((I915_READ_NOTRACE(forcewake_ack) & 1), 500)) 3974 if (wait_for_atomic((I915_READ_NOTRACE(forcewake_ack) & 1),
3976 DRM_ERROR("Force wake wait timed out\n"); 3975 FORCEWAKE_ACK_TIMEOUT_MS))
3976 DRM_ERROR("Timed out waiting for forcewake to ack request.\n");
3977 3977
3978 __gen6_gt_wait_for_thread_c0(dev_priv); 3978 __gen6_gt_wait_for_thread_c0(dev_priv);
3979} 3979}
@@ -3987,14 +3987,16 @@ static void __gen6_gt_force_wake_mt_get(struct drm_i915_private *dev_priv)
3987 else 3987 else
3988 forcewake_ack = FORCEWAKE_MT_ACK; 3988 forcewake_ack = FORCEWAKE_MT_ACK;
3989 3989
3990 if (wait_for_atomic_us((I915_READ_NOTRACE(forcewake_ack) & 1) == 0, 500)) 3990 if (wait_for_atomic((I915_READ_NOTRACE(forcewake_ack) & 1) == 0,
3991 DRM_ERROR("Force wake wait timed out\n"); 3991 FORCEWAKE_ACK_TIMEOUT_MS))
3992 DRM_ERROR("Timed out waiting for forcewake old ack to clear.\n");
3992 3993
3993 I915_WRITE_NOTRACE(FORCEWAKE_MT, _MASKED_BIT_ENABLE(1)); 3994 I915_WRITE_NOTRACE(FORCEWAKE_MT, _MASKED_BIT_ENABLE(1));
3994 POSTING_READ(FORCEWAKE_MT); 3995 POSTING_READ(ECOBUS); /* something from same cacheline, but !FORCEWAKE */
3995 3996
3996 if (wait_for_atomic_us((I915_READ_NOTRACE(forcewake_ack) & 1), 500)) 3997 if (wait_for_atomic((I915_READ_NOTRACE(forcewake_ack) & 1),
3997 DRM_ERROR("Force wake wait timed out\n"); 3998 FORCEWAKE_ACK_TIMEOUT_MS))
3999 DRM_ERROR("Timed out waiting for forcewake to ack request.\n");
3998 4000
3999 __gen6_gt_wait_for_thread_c0(dev_priv); 4001 __gen6_gt_wait_for_thread_c0(dev_priv);
4000} 4002}
@@ -4027,14 +4029,14 @@ void gen6_gt_check_fifodbg(struct drm_i915_private *dev_priv)
4027static void __gen6_gt_force_wake_put(struct drm_i915_private *dev_priv) 4029static void __gen6_gt_force_wake_put(struct drm_i915_private *dev_priv)
4028{ 4030{
4029 I915_WRITE_NOTRACE(FORCEWAKE, 0); 4031 I915_WRITE_NOTRACE(FORCEWAKE, 0);
4030 POSTING_READ(FORCEWAKE); 4032 /* gen6_gt_check_fifodbg doubles as the POSTING_READ */
4031 gen6_gt_check_fifodbg(dev_priv); 4033 gen6_gt_check_fifodbg(dev_priv);
4032} 4034}
4033 4035
4034static void __gen6_gt_force_wake_mt_put(struct drm_i915_private *dev_priv) 4036static void __gen6_gt_force_wake_mt_put(struct drm_i915_private *dev_priv)
4035{ 4037{
4036 I915_WRITE_NOTRACE(FORCEWAKE_MT, _MASKED_BIT_DISABLE(1)); 4038 I915_WRITE_NOTRACE(FORCEWAKE_MT, _MASKED_BIT_DISABLE(1));
4037 POSTING_READ(FORCEWAKE_MT); 4039 /* gen6_gt_check_fifodbg doubles as the POSTING_READ */
4038 gen6_gt_check_fifodbg(dev_priv); 4040 gen6_gt_check_fifodbg(dev_priv);
4039} 4041}
4040 4042
@@ -4073,24 +4075,24 @@ int __gen6_gt_wait_for_fifo(struct drm_i915_private *dev_priv)
4073 4075
4074static void vlv_force_wake_get(struct drm_i915_private *dev_priv) 4076static void vlv_force_wake_get(struct drm_i915_private *dev_priv)
4075{ 4077{
4076 /* Already awake? */ 4078 if (wait_for_atomic((I915_READ_NOTRACE(FORCEWAKE_ACK_VLV) & 1) == 0,
4077 if ((I915_READ(0x130094) & 0xa1) == 0xa1) 4079 FORCEWAKE_ACK_TIMEOUT_MS))
4078 return; 4080 DRM_ERROR("Timed out waiting for forcewake old ack to clear.\n");
4079 4081
4080 I915_WRITE_NOTRACE(FORCEWAKE_VLV, 0xffffffff); 4082 I915_WRITE_NOTRACE(FORCEWAKE_VLV, _MASKED_BIT_ENABLE(1));
4081 POSTING_READ(FORCEWAKE_VLV);
4082 4083
4083 if (wait_for_atomic_us((I915_READ_NOTRACE(FORCEWAKE_ACK_VLV) & 1), 500)) 4084 if (wait_for_atomic((I915_READ_NOTRACE(FORCEWAKE_ACK_VLV) & 1),
4084 DRM_ERROR("Force wake wait timed out\n"); 4085 FORCEWAKE_ACK_TIMEOUT_MS))
4086 DRM_ERROR("Timed out waiting for forcewake to ack request.\n");
4085 4087
4086 __gen6_gt_wait_for_thread_c0(dev_priv); 4088 __gen6_gt_wait_for_thread_c0(dev_priv);
4087} 4089}
4088 4090
4089static void vlv_force_wake_put(struct drm_i915_private *dev_priv) 4091static void vlv_force_wake_put(struct drm_i915_private *dev_priv)
4090{ 4092{
4091 I915_WRITE_NOTRACE(FORCEWAKE_VLV, 0xffff0000); 4093 I915_WRITE_NOTRACE(FORCEWAKE_VLV, _MASKED_BIT_DISABLE(1));
4092 /* FIXME: confirm VLV behavior with Punit folks */ 4094 /* The below doubles as a POSTING_READ */
4093 POSTING_READ(FORCEWAKE_VLV); 4095 gen6_gt_check_fifodbg(dev_priv);
4094} 4096}
4095 4097
4096void intel_gt_init(struct drm_device *dev) 4098void intel_gt_init(struct drm_device *dev)
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
index ac93643731aa..55cdb4d30a16 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
@@ -218,6 +218,11 @@ gen6_render_ring_flush(struct intel_ring_buffer *ring,
218 u32 scratch_addr = pc->gtt_offset + 128; 218 u32 scratch_addr = pc->gtt_offset + 128;
219 int ret; 219 int ret;
220 220
221 /* Force SNB workarounds for PIPE_CONTROL flushes */
222 ret = intel_emit_post_sync_nonzero_flush(ring);
223 if (ret)
224 return ret;
225
221 /* Just flush everything. Experiments have shown that reducing the 226 /* Just flush everything. Experiments have shown that reducing the
222 * number of bits based on the write domains has little performance 227 * number of bits based on the write domains has little performance
223 * impact. 228 * impact.
@@ -258,17 +263,80 @@ gen6_render_ring_flush(struct intel_ring_buffer *ring,
258} 263}
259 264
260static int 265static int
261gen6_render_ring_flush__wa(struct intel_ring_buffer *ring, 266gen7_render_ring_cs_stall_wa(struct intel_ring_buffer *ring)
262 u32 invalidate_domains, u32 flush_domains)
263{ 267{
264 int ret; 268 int ret;
265 269
266 /* Force SNB workarounds for PIPE_CONTROL flushes */ 270 ret = intel_ring_begin(ring, 4);
267 ret = intel_emit_post_sync_nonzero_flush(ring);
268 if (ret) 271 if (ret)
269 return ret; 272 return ret;
270 273
271 return gen6_render_ring_flush(ring, invalidate_domains, flush_domains); 274 intel_ring_emit(ring, GFX_OP_PIPE_CONTROL(4));
275 intel_ring_emit(ring, PIPE_CONTROL_CS_STALL |
276 PIPE_CONTROL_STALL_AT_SCOREBOARD);
277 intel_ring_emit(ring, 0);
278 intel_ring_emit(ring, 0);
279 intel_ring_advance(ring);
280
281 return 0;
282}
283
284static int
285gen7_render_ring_flush(struct intel_ring_buffer *ring,
286 u32 invalidate_domains, u32 flush_domains)
287{
288 u32 flags = 0;
289 struct pipe_control *pc = ring->private;
290 u32 scratch_addr = pc->gtt_offset + 128;
291 int ret;
292
293 /*
294 * Ensure that any following seqno writes only happen when the render
295 * cache is indeed flushed.
296 *
297 * Workaround: 4th PIPE_CONTROL command (except the ones with only
298 * read-cache invalidate bits set) must have the CS_STALL bit set. We
299 * don't try to be clever and just set it unconditionally.
300 */
301 flags |= PIPE_CONTROL_CS_STALL;
302
303 /* Just flush everything. Experiments have shown that reducing the
304 * number of bits based on the write domains has little performance
305 * impact.
306 */
307 if (flush_domains) {
308 flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH;
309 flags |= PIPE_CONTROL_DEPTH_CACHE_FLUSH;
310 }
311 if (invalidate_domains) {
312 flags |= PIPE_CONTROL_TLB_INVALIDATE;
313 flags |= PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE;
314 flags |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE;
315 flags |= PIPE_CONTROL_VF_CACHE_INVALIDATE;
316 flags |= PIPE_CONTROL_CONST_CACHE_INVALIDATE;
317 flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE;
318 /*
319 * TLB invalidate requires a post-sync write.
320 */
321 flags |= PIPE_CONTROL_QW_WRITE;
322
323 /* Workaround: we must issue a pipe_control with CS-stall bit
324 * set before a pipe_control command that has the state cache
325 * invalidate bit set. */
326 gen7_render_ring_cs_stall_wa(ring);
327 }
328
329 ret = intel_ring_begin(ring, 4);
330 if (ret)
331 return ret;
332
333 intel_ring_emit(ring, GFX_OP_PIPE_CONTROL(4));
334 intel_ring_emit(ring, flags);
335 intel_ring_emit(ring, scratch_addr | PIPE_CONTROL_GLOBAL_GTT);
336 intel_ring_emit(ring, 0);
337 intel_ring_advance(ring);
338
339 return 0;
272} 340}
273 341
274static void ring_write_tail(struct intel_ring_buffer *ring, 342static void ring_write_tail(struct intel_ring_buffer *ring,
@@ -1385,9 +1453,9 @@ int intel_init_render_ring_buffer(struct drm_device *dev)
1385 1453
1386 if (INTEL_INFO(dev)->gen >= 6) { 1454 if (INTEL_INFO(dev)->gen >= 6) {
1387 ring->add_request = gen6_add_request; 1455 ring->add_request = gen6_add_request;
1388 ring->flush = gen6_render_ring_flush; 1456 ring->flush = gen7_render_ring_flush;
1389 if (INTEL_INFO(dev)->gen == 6) 1457 if (INTEL_INFO(dev)->gen == 6)
1390 ring->flush = gen6_render_ring_flush__wa; 1458 ring->flush = gen6_render_ring_flush;
1391 ring->irq_get = gen6_ring_get_irq; 1459 ring->irq_get = gen6_ring_get_irq;
1392 ring->irq_put = gen6_ring_put_irq; 1460 ring->irq_put = gen6_ring_put_irq;
1393 ring->irq_enable_mask = GT_USER_INTERRUPT; 1461 ring->irq_enable_mask = GT_USER_INTERRUPT;
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
index 434b1d1d3c84..39c319827f91 100644
--- a/drivers/gpu/drm/i915/intel_sdvo.c
+++ b/drivers/gpu/drm/i915/intel_sdvo.c
@@ -97,7 +97,7 @@ struct intel_sdvo {
97 /* 97 /*
98 * Hotplug activation bits for this device 98 * Hotplug activation bits for this device
99 */ 99 */
100 uint8_t hotplug_active[2]; 100 uint16_t hotplug_active;
101 101
102 /** 102 /**
103 * This is used to select the color range of RBG outputs in HDMI mode. 103 * This is used to select the color range of RBG outputs in HDMI mode.
@@ -628,6 +628,14 @@ static bool intel_sdvo_set_active_outputs(struct intel_sdvo *intel_sdvo,
628 &outputs, sizeof(outputs)); 628 &outputs, sizeof(outputs));
629} 629}
630 630
631static bool intel_sdvo_get_active_outputs(struct intel_sdvo *intel_sdvo,
632 u16 *outputs)
633{
634 return intel_sdvo_get_value(intel_sdvo,
635 SDVO_CMD_GET_ACTIVE_OUTPUTS,
636 outputs, sizeof(*outputs));
637}
638
631static bool intel_sdvo_set_encoder_power_state(struct intel_sdvo *intel_sdvo, 639static bool intel_sdvo_set_encoder_power_state(struct intel_sdvo *intel_sdvo,
632 int mode) 640 int mode)
633{ 641{
@@ -1142,51 +1150,132 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1142 intel_sdvo_write_sdvox(intel_sdvo, sdvox); 1150 intel_sdvo_write_sdvox(intel_sdvo, sdvox);
1143} 1151}
1144 1152
1145static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode) 1153static bool intel_sdvo_connector_get_hw_state(struct intel_connector *connector)
1146{ 1154{
1147 struct drm_device *dev = encoder->dev; 1155 struct intel_sdvo_connector *intel_sdvo_connector =
1156 to_intel_sdvo_connector(&connector->base);
1157 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(&connector->base);
1158 u16 active_outputs;
1159
1160 intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1161
1162 if (active_outputs & intel_sdvo_connector->output_flag)
1163 return true;
1164 else
1165 return false;
1166}
1167
1168static bool intel_sdvo_get_hw_state(struct intel_encoder *encoder,
1169 enum pipe *pipe)
1170{
1171 struct drm_device *dev = encoder->base.dev;
1148 struct drm_i915_private *dev_priv = dev->dev_private; 1172 struct drm_i915_private *dev_priv = dev->dev_private;
1149 struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder); 1173 struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
1150 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); 1174 u32 tmp;
1175
1176 tmp = I915_READ(intel_sdvo->sdvo_reg);
1177
1178 if (!(tmp & SDVO_ENABLE))
1179 return false;
1180
1181 if (HAS_PCH_CPT(dev))
1182 *pipe = PORT_TO_PIPE_CPT(tmp);
1183 else
1184 *pipe = PORT_TO_PIPE(tmp);
1185
1186 return true;
1187}
1188
1189static void intel_disable_sdvo(struct intel_encoder *encoder)
1190{
1191 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1192 struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
1193 u32 temp;
1194
1195 intel_sdvo_set_active_outputs(intel_sdvo, 0);
1196 if (0)
1197 intel_sdvo_set_encoder_power_state(intel_sdvo,
1198 DRM_MODE_DPMS_OFF);
1199
1200 temp = I915_READ(intel_sdvo->sdvo_reg);
1201 if ((temp & SDVO_ENABLE) != 0) {
1202 intel_sdvo_write_sdvox(intel_sdvo, temp & ~SDVO_ENABLE);
1203 }
1204}
1205
1206static void intel_enable_sdvo(struct intel_encoder *encoder)
1207{
1208 struct drm_device *dev = encoder->base.dev;
1209 struct drm_i915_private *dev_priv = dev->dev_private;
1210 struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
1211 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1151 u32 temp; 1212 u32 temp;
1213 bool input1, input2;
1214 int i;
1215 u8 status;
1216
1217 temp = I915_READ(intel_sdvo->sdvo_reg);
1218 if ((temp & SDVO_ENABLE) == 0)
1219 intel_sdvo_write_sdvox(intel_sdvo, temp | SDVO_ENABLE);
1220 for (i = 0; i < 2; i++)
1221 intel_wait_for_vblank(dev, intel_crtc->pipe);
1222
1223 status = intel_sdvo_get_trained_inputs(intel_sdvo, &input1, &input2);
1224 /* Warn if the device reported failure to sync.
1225 * A lot of SDVO devices fail to notify of sync, but it's
1226 * a given it the status is a success, we succeeded.
1227 */
1228 if (status == SDVO_CMD_STATUS_SUCCESS && !input1) {
1229 DRM_DEBUG_KMS("First %s output reported failure to "
1230 "sync\n", SDVO_NAME(intel_sdvo));
1231 }
1232
1233 if (0)
1234 intel_sdvo_set_encoder_power_state(intel_sdvo,
1235 DRM_MODE_DPMS_ON);
1236 intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
1237}
1238
1239static void intel_sdvo_dpms(struct drm_connector *connector, int mode)
1240{
1241 struct drm_crtc *crtc;
1242 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1243
1244 /* dvo supports only 2 dpms states. */
1245 if (mode != DRM_MODE_DPMS_ON)
1246 mode = DRM_MODE_DPMS_OFF;
1247
1248 if (mode == connector->dpms)
1249 return;
1250
1251 connector->dpms = mode;
1252
1253 /* Only need to change hw state when actually enabled */
1254 crtc = intel_sdvo->base.base.crtc;
1255 if (!crtc) {
1256 intel_sdvo->base.connectors_active = false;
1257 return;
1258 }
1152 1259
1153 if (mode != DRM_MODE_DPMS_ON) { 1260 if (mode != DRM_MODE_DPMS_ON) {
1154 intel_sdvo_set_active_outputs(intel_sdvo, 0); 1261 intel_sdvo_set_active_outputs(intel_sdvo, 0);
1155 if (0) 1262 if (0)
1156 intel_sdvo_set_encoder_power_state(intel_sdvo, mode); 1263 intel_sdvo_set_encoder_power_state(intel_sdvo, mode);
1157 1264
1158 if (mode == DRM_MODE_DPMS_OFF) { 1265 intel_sdvo->base.connectors_active = false;
1159 temp = I915_READ(intel_sdvo->sdvo_reg); 1266
1160 if ((temp & SDVO_ENABLE) != 0) { 1267 intel_crtc_update_dpms(crtc);
1161 intel_sdvo_write_sdvox(intel_sdvo, temp & ~SDVO_ENABLE);
1162 }
1163 }
1164 } else { 1268 } else {
1165 bool input1, input2; 1269 intel_sdvo->base.connectors_active = true;
1166 int i; 1270
1167 u8 status; 1271 intel_crtc_update_dpms(crtc);
1168
1169 temp = I915_READ(intel_sdvo->sdvo_reg);
1170 if ((temp & SDVO_ENABLE) == 0)
1171 intel_sdvo_write_sdvox(intel_sdvo, temp | SDVO_ENABLE);
1172 for (i = 0; i < 2; i++)
1173 intel_wait_for_vblank(dev, intel_crtc->pipe);
1174
1175 status = intel_sdvo_get_trained_inputs(intel_sdvo, &input1, &input2);
1176 /* Warn if the device reported failure to sync.
1177 * A lot of SDVO devices fail to notify of sync, but it's
1178 * a given it the status is a success, we succeeded.
1179 */
1180 if (status == SDVO_CMD_STATUS_SUCCESS && !input1) {
1181 DRM_DEBUG_KMS("First %s output reported failure to "
1182 "sync\n", SDVO_NAME(intel_sdvo));
1183 }
1184 1272
1185 if (0) 1273 if (0)
1186 intel_sdvo_set_encoder_power_state(intel_sdvo, mode); 1274 intel_sdvo_set_encoder_power_state(intel_sdvo, mode);
1187 intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output); 1275 intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
1188 } 1276 }
1189 return; 1277
1278 intel_modeset_check_state(connector->dev);
1190} 1279}
1191 1280
1192static int intel_sdvo_mode_valid(struct drm_connector *connector, 1281static int intel_sdvo_mode_valid(struct drm_connector *connector,
@@ -1251,25 +1340,29 @@ static bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct in
1251 return true; 1340 return true;
1252} 1341}
1253 1342
1254static int intel_sdvo_supports_hotplug(struct intel_sdvo *intel_sdvo) 1343static uint16_t intel_sdvo_get_hotplug_support(struct intel_sdvo *intel_sdvo)
1255{ 1344{
1256 struct drm_device *dev = intel_sdvo->base.base.dev; 1345 struct drm_device *dev = intel_sdvo->base.base.dev;
1257 u8 response[2]; 1346 uint16_t hotplug;
1258 1347
1259 /* HW Erratum: SDVO Hotplug is broken on all i945G chips, there's noise 1348 /* HW Erratum: SDVO Hotplug is broken on all i945G chips, there's noise
1260 * on the line. */ 1349 * on the line. */
1261 if (IS_I945G(dev) || IS_I945GM(dev)) 1350 if (IS_I945G(dev) || IS_I945GM(dev))
1262 return false; 1351 return 0;
1352
1353 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT,
1354 &hotplug, sizeof(hotplug)))
1355 return 0;
1263 1356
1264 return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT, 1357 return hotplug;
1265 &response, 2) && response[0];
1266} 1358}
1267 1359
1268static void intel_sdvo_enable_hotplug(struct intel_encoder *encoder) 1360static void intel_sdvo_enable_hotplug(struct intel_encoder *encoder)
1269{ 1361{
1270 struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base); 1362 struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
1271 1363
1272 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &intel_sdvo->hotplug_active, 2); 1364 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG,
1365 &intel_sdvo->hotplug_active, 2);
1273} 1366}
1274 1367
1275static bool 1368static bool
@@ -1834,8 +1927,8 @@ set_value:
1834done: 1927done:
1835 if (intel_sdvo->base.base.crtc) { 1928 if (intel_sdvo->base.base.crtc) {
1836 struct drm_crtc *crtc = intel_sdvo->base.base.crtc; 1929 struct drm_crtc *crtc = intel_sdvo->base.base.crtc;
1837 drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x, 1930 intel_set_mode(crtc, &crtc->mode,
1838 crtc->y, crtc->fb); 1931 crtc->x, crtc->y, crtc->fb);
1839 } 1932 }
1840 1933
1841 return 0; 1934 return 0;
@@ -1843,15 +1936,13 @@ done:
1843} 1936}
1844 1937
1845static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = { 1938static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = {
1846 .dpms = intel_sdvo_dpms,
1847 .mode_fixup = intel_sdvo_mode_fixup, 1939 .mode_fixup = intel_sdvo_mode_fixup,
1848 .prepare = intel_encoder_prepare,
1849 .mode_set = intel_sdvo_mode_set, 1940 .mode_set = intel_sdvo_mode_set,
1850 .commit = intel_encoder_commit, 1941 .disable = intel_encoder_noop,
1851}; 1942};
1852 1943
1853static const struct drm_connector_funcs intel_sdvo_connector_funcs = { 1944static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
1854 .dpms = drm_helper_connector_dpms, 1945 .dpms = intel_sdvo_dpms,
1855 .detect = intel_sdvo_detect, 1946 .detect = intel_sdvo_detect,
1856 .fill_modes = drm_helper_probe_single_connector_modes, 1947 .fill_modes = drm_helper_probe_single_connector_modes,
1857 .set_property = intel_sdvo_set_property, 1948 .set_property = intel_sdvo_set_property,
@@ -2023,6 +2114,7 @@ intel_sdvo_connector_init(struct intel_sdvo_connector *connector,
2023 connector->base.base.interlace_allowed = 1; 2114 connector->base.base.interlace_allowed = 1;
2024 connector->base.base.doublescan_allowed = 0; 2115 connector->base.base.doublescan_allowed = 0;
2025 connector->base.base.display_info.subpixel_order = SubPixelHorizontalRGB; 2116 connector->base.base.display_info.subpixel_order = SubPixelHorizontalRGB;
2117 connector->base.get_hw_state = intel_sdvo_connector_get_hw_state;
2026 2118
2027 intel_connector_attach_encoder(&connector->base, &encoder->base); 2119 intel_connector_attach_encoder(&connector->base, &encoder->base);
2028 drm_sysfs_connector_add(&connector->base.base); 2120 drm_sysfs_connector_add(&connector->base.base);
@@ -2061,17 +2153,18 @@ intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device)
2061 2153
2062 intel_connector = &intel_sdvo_connector->base; 2154 intel_connector = &intel_sdvo_connector->base;
2063 connector = &intel_connector->base; 2155 connector = &intel_connector->base;
2064 if (intel_sdvo_supports_hotplug(intel_sdvo) & (1 << device)) { 2156 if (intel_sdvo_get_hotplug_support(intel_sdvo) &
2157 intel_sdvo_connector->output_flag) {
2065 connector->polled = DRM_CONNECTOR_POLL_HPD; 2158 connector->polled = DRM_CONNECTOR_POLL_HPD;
2066 intel_sdvo->hotplug_active[0] |= 1 << device; 2159 intel_sdvo->hotplug_active |= intel_sdvo_connector->output_flag;
2067 /* Some SDVO devices have one-shot hotplug interrupts. 2160 /* Some SDVO devices have one-shot hotplug interrupts.
2068 * Ensure that they get re-enabled when an interrupt happens. 2161 * Ensure that they get re-enabled when an interrupt happens.
2069 */ 2162 */
2070 intel_encoder->hot_plug = intel_sdvo_enable_hotplug; 2163 intel_encoder->hot_plug = intel_sdvo_enable_hotplug;
2071 intel_sdvo_enable_hotplug(intel_encoder); 2164 intel_sdvo_enable_hotplug(intel_encoder);
2072 } 2165 } else {
2073 else
2074 connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT; 2166 connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
2167 }
2075 encoder->encoder_type = DRM_MODE_ENCODER_TMDS; 2168 encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
2076 connector->connector_type = DRM_MODE_CONNECTOR_DVID; 2169 connector->connector_type = DRM_MODE_CONNECTOR_DVID;
2077 2170
@@ -2570,22 +2663,17 @@ bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob)
2570 hotplug_mask = intel_sdvo->is_sdvob ? 2663 hotplug_mask = intel_sdvo->is_sdvob ?
2571 SDVOB_HOTPLUG_INT_STATUS_I915 : SDVOC_HOTPLUG_INT_STATUS_I915; 2664 SDVOB_HOTPLUG_INT_STATUS_I915 : SDVOC_HOTPLUG_INT_STATUS_I915;
2572 } 2665 }
2573 dev_priv->hotplug_supported_mask |= hotplug_mask;
2574 2666
2575 drm_encoder_helper_add(&intel_encoder->base, &intel_sdvo_helper_funcs); 2667 drm_encoder_helper_add(&intel_encoder->base, &intel_sdvo_helper_funcs);
2576 2668
2669 intel_encoder->disable = intel_disable_sdvo;
2670 intel_encoder->enable = intel_enable_sdvo;
2671 intel_encoder->get_hw_state = intel_sdvo_get_hw_state;
2672
2577 /* In default case sdvo lvds is false */ 2673 /* In default case sdvo lvds is false */
2578 if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps)) 2674 if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps))
2579 goto err; 2675 goto err;
2580 2676
2581 /* Set up hotplug command - note paranoia about contents of reply.
2582 * We assume that the hardware is in a sane state, and only touch
2583 * the bits we think we understand.
2584 */
2585 intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_ACTIVE_HOT_PLUG,
2586 &intel_sdvo->hotplug_active, 2);
2587 intel_sdvo->hotplug_active[0] &= ~0x3;
2588
2589 if (intel_sdvo_output_setup(intel_sdvo, 2677 if (intel_sdvo_output_setup(intel_sdvo,
2590 intel_sdvo->caps.output_flags) != true) { 2678 intel_sdvo->caps.output_flags) != true) {
2591 DRM_DEBUG_KMS("SDVO output failed to setup on %s\n", 2679 DRM_DEBUG_KMS("SDVO output failed to setup on %s\n",
@@ -2593,6 +2681,12 @@ bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob)
2593 goto err; 2681 goto err;
2594 } 2682 }
2595 2683
2684 /* Only enable the hotplug irq if we need it, to work around noisy
2685 * hotplug lines.
2686 */
2687 if (intel_sdvo->hotplug_active)
2688 dev_priv->hotplug_supported_mask |= hotplug_mask;
2689
2596 intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo, sdvo_reg); 2690 intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo, sdvo_reg);
2597 2691
2598 /* Set the input timing to the screen. Assume always input 0. */ 2692 /* Set the input timing to the screen. Assume always input 0. */
diff --git a/drivers/gpu/drm/i915/intel_tv.c b/drivers/gpu/drm/i915/intel_tv.c
index 95653a508987..d2c5c8f3baf3 100644
--- a/drivers/gpu/drm/i915/intel_tv.c
+++ b/drivers/gpu/drm/i915/intel_tv.c
@@ -836,22 +836,37 @@ static struct intel_tv *intel_attached_tv(struct drm_connector *connector)
836 base); 836 base);
837} 837}
838 838
839static bool
840intel_tv_get_hw_state(struct intel_encoder *encoder, enum pipe *pipe)
841{
842 struct drm_device *dev = encoder->base.dev;
843 struct drm_i915_private *dev_priv = dev->dev_private;
844 u32 tmp = I915_READ(TV_CTL);
845
846 if (!(tmp & TV_ENC_ENABLE))
847 return false;
848
849 *pipe = PORT_TO_PIPE(tmp);
850
851 return true;
852}
853
839static void 854static void
840intel_tv_dpms(struct drm_encoder *encoder, int mode) 855intel_enable_tv(struct intel_encoder *encoder)
841{ 856{
842 struct drm_device *dev = encoder->dev; 857 struct drm_device *dev = encoder->base.dev;
843 struct drm_i915_private *dev_priv = dev->dev_private; 858 struct drm_i915_private *dev_priv = dev->dev_private;
844 859
845 switch (mode) { 860 I915_WRITE(TV_CTL, I915_READ(TV_CTL) | TV_ENC_ENABLE);
846 case DRM_MODE_DPMS_ON: 861}
847 I915_WRITE(TV_CTL, I915_READ(TV_CTL) | TV_ENC_ENABLE); 862
848 break; 863static void
849 case DRM_MODE_DPMS_STANDBY: 864intel_disable_tv(struct intel_encoder *encoder)
850 case DRM_MODE_DPMS_SUSPEND: 865{
851 case DRM_MODE_DPMS_OFF: 866 struct drm_device *dev = encoder->base.dev;
852 I915_WRITE(TV_CTL, I915_READ(TV_CTL) & ~TV_ENC_ENABLE); 867 struct drm_i915_private *dev_priv = dev->dev_private;
853 break; 868
854 } 869 I915_WRITE(TV_CTL, I915_READ(TV_CTL) & ~TV_ENC_ENABLE);
855} 870}
856 871
857static const struct tv_mode * 872static const struct tv_mode *
@@ -895,17 +910,14 @@ intel_tv_mode_fixup(struct drm_encoder *encoder,
895 const struct drm_display_mode *mode, 910 const struct drm_display_mode *mode,
896 struct drm_display_mode *adjusted_mode) 911 struct drm_display_mode *adjusted_mode)
897{ 912{
898 struct drm_device *dev = encoder->dev;
899 struct intel_tv *intel_tv = enc_to_intel_tv(encoder); 913 struct intel_tv *intel_tv = enc_to_intel_tv(encoder);
900 const struct tv_mode *tv_mode = intel_tv_mode_find(intel_tv); 914 const struct tv_mode *tv_mode = intel_tv_mode_find(intel_tv);
901 struct intel_encoder *other_encoder;
902 915
903 if (!tv_mode) 916 if (!tv_mode)
904 return false; 917 return false;
905 918
906 for_each_encoder_on_crtc(dev, encoder->crtc, other_encoder) 919 if (intel_encoder_check_is_cloned(&intel_tv->base))
907 if (&other_encoder->base != encoder) 920 return false;
908 return false;
909 921
910 adjusted_mode->clock = tv_mode->clock; 922 adjusted_mode->clock = tv_mode->clock;
911 return true; 923 return true;
@@ -1471,22 +1483,20 @@ intel_tv_set_property(struct drm_connector *connector, struct drm_property *prop
1471 } 1483 }
1472 1484
1473 if (changed && crtc) 1485 if (changed && crtc)
1474 drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x, 1486 intel_set_mode(crtc, &crtc->mode,
1475 crtc->y, crtc->fb); 1487 crtc->x, crtc->y, crtc->fb);
1476out: 1488out:
1477 return ret; 1489 return ret;
1478} 1490}
1479 1491
1480static const struct drm_encoder_helper_funcs intel_tv_helper_funcs = { 1492static const struct drm_encoder_helper_funcs intel_tv_helper_funcs = {
1481 .dpms = intel_tv_dpms,
1482 .mode_fixup = intel_tv_mode_fixup, 1493 .mode_fixup = intel_tv_mode_fixup,
1483 .prepare = intel_encoder_prepare,
1484 .mode_set = intel_tv_mode_set, 1494 .mode_set = intel_tv_mode_set,
1485 .commit = intel_encoder_commit, 1495 .disable = intel_encoder_noop,
1486}; 1496};
1487 1497
1488static const struct drm_connector_funcs intel_tv_connector_funcs = { 1498static const struct drm_connector_funcs intel_tv_connector_funcs = {
1489 .dpms = drm_helper_connector_dpms, 1499 .dpms = intel_connector_dpms,
1490 .detect = intel_tv_detect, 1500 .detect = intel_tv_detect,
1491 .destroy = intel_tv_destroy, 1501 .destroy = intel_tv_destroy,
1492 .set_property = intel_tv_set_property, 1502 .set_property = intel_tv_set_property,
@@ -1616,6 +1626,11 @@ intel_tv_init(struct drm_device *dev)
1616 drm_encoder_init(dev, &intel_encoder->base, &intel_tv_enc_funcs, 1626 drm_encoder_init(dev, &intel_encoder->base, &intel_tv_enc_funcs,
1617 DRM_MODE_ENCODER_TVDAC); 1627 DRM_MODE_ENCODER_TVDAC);
1618 1628
1629 intel_encoder->enable = intel_enable_tv;
1630 intel_encoder->disable = intel_disable_tv;
1631 intel_encoder->get_hw_state = intel_tv_get_hw_state;
1632 intel_connector->get_hw_state = intel_connector_get_hw_state;
1633
1619 intel_connector_attach_encoder(intel_connector, intel_encoder); 1634 intel_connector_attach_encoder(intel_connector, intel_encoder);
1620 intel_encoder->type = INTEL_OUTPUT_TVOUT; 1635 intel_encoder->type = INTEL_OUTPUT_TVOUT;
1621 intel_encoder->crtc_mask = (1 << 0) | (1 << 1); 1636 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);