drm/i915: wait for a vblank to pass after tv detect
[pandora-kernel.git] / drivers / gpu / drm / i915 / intel_tv.c
index 210d570..12041fa 100644 (file)
@@ -194,10 +194,10 @@ static const u32 filter_table[] = {
  *
  *     if (f >= 1) {
  *         exp = 0x7;
- *        mant = 1 << 8;
+ *        mant = 1 << 8;
  *     } else {
  *         for (exp = 0; exp < 3 && f < 0.5; exp++)
- *            f *= 2.0;
+ *        f *= 2.0;
  *         mant = (f * (1 << 9) + 0.5);
  *         if (mant >= (1 << 9))
  *             mant = (1 << 9) - 1;
@@ -417,7 +417,7 @@ static const struct tv_mode tv_modes[] = {
        {
                .name           = "NTSC-M",
                .clock          = 108000,
-               .refresh        = 29970,
+               .refresh        = 59940,
                .oversample     = TV_OVERSAMPLE_8X,
                .component_only = 0,
                /* 525 Lines, 60 Fields, 15.734KHz line, Sub-Carrier 3.580MHz */
@@ -430,7 +430,7 @@ static const struct tv_mode tv_modes[] = {
                .vsync_start_f1 = 6,                .vsync_start_f2     = 7,
                .vsync_len      = 6,
 
-               .veq_ena        = true,             .veq_start_f1       = 0,
+               .veq_ena        = true,             .veq_start_f1       = 0,
                .veq_start_f2   = 1,                .veq_len            = 18,
 
                .vi_end_f1      = 20,               .vi_end_f2          = 21,
@@ -460,7 +460,7 @@ static const struct tv_mode tv_modes[] = {
        {
                .name           = "NTSC-443",
                .clock          = 108000,
-               .refresh        = 29970,
+               .refresh        = 59940,
                .oversample     = TV_OVERSAMPLE_8X,
                .component_only = 0,
                /* 525 Lines, 60 Fields, 15.734KHz line, Sub-Carrier 4.43MHz */
@@ -472,7 +472,7 @@ static const struct tv_mode tv_modes[] = {
                .vsync_start_f1 = 6,                .vsync_start_f2     = 7,
                .vsync_len      = 6,
 
-               .veq_ena        = true,             .veq_start_f1       = 0,
+               .veq_ena        = true,             .veq_start_f1       = 0,
                .veq_start_f2   = 1,                .veq_len            = 18,
 
                .vi_end_f1      = 20,               .vi_end_f2          = 21,
@@ -502,7 +502,7 @@ static const struct tv_mode tv_modes[] = {
        {
                .name           = "NTSC-J",
                .clock          = 108000,
-               .refresh        = 29970,
+               .refresh        = 59940,
                .oversample     = TV_OVERSAMPLE_8X,
                .component_only = 0,
 
@@ -515,7 +515,7 @@ static const struct tv_mode tv_modes[] = {
                .vsync_start_f1 = 6,        .vsync_start_f2     = 7,
                .vsync_len      = 6,
 
-               .veq_ena        = true,             .veq_start_f1       = 0,
+               .veq_ena      = true,       .veq_start_f1       = 0,
                .veq_start_f2 = 1,          .veq_len            = 18,
 
                .vi_end_f1      = 20,               .vi_end_f2          = 21,
@@ -545,7 +545,7 @@ static const struct tv_mode tv_modes[] = {
        {
                .name           = "PAL-M",
                .clock          = 108000,
-               .refresh        = 29970,
+               .refresh        = 59940,
                .oversample     = TV_OVERSAMPLE_8X,
                .component_only = 0,
 
@@ -558,7 +558,7 @@ static const struct tv_mode tv_modes[] = {
                .vsync_start_f1 = 6,                .vsync_start_f2     = 7,
                .vsync_len      = 6,
 
-               .veq_ena        = true,             .veq_start_f1       = 0,
+               .veq_ena        = true,             .veq_start_f1       = 0,
                .veq_start_f2   = 1,                .veq_len            = 18,
 
                .vi_end_f1      = 20,               .vi_end_f2          = 21,
@@ -589,7 +589,7 @@ static const struct tv_mode tv_modes[] = {
                /* 625 Lines, 50 Fields, 15.625KHz line, Sub-Carrier 4.434MHz */
                .name       = "PAL-N",
                .clock          = 108000,
-               .refresh        = 25000,
+               .refresh        = 50000,
                .oversample     = TV_OVERSAMPLE_8X,
                .component_only = 0,
 
@@ -602,14 +602,14 @@ static const struct tv_mode tv_modes[] = {
                .vsync_start_f1 = 6,       .vsync_start_f2      = 7,
                .vsync_len      = 6,
 
-               .veq_ena        = true,             .veq_start_f1       = 0,
+               .veq_ena        = true,             .veq_start_f1       = 0,
                .veq_start_f2   = 1,                .veq_len            = 18,
 
                .vi_end_f1      = 24,               .vi_end_f2          = 25,
                .nbr_end        = 286,
 
                .burst_ena      = true,
-               .hburst_start = 73,                 .hburst_len         = 34,
+               .hburst_start = 73,         .hburst_len         = 34,
                .vburst_start_f1 = 8,       .vburst_end_f1      = 285,
                .vburst_start_f2 = 8,       .vburst_end_f2      = 286,
                .vburst_start_f3 = 9,       .vburst_end_f3      = 286,
@@ -634,7 +634,7 @@ static const struct tv_mode tv_modes[] = {
                /* 625 Lines, 50 Fields, 15.625KHz line, Sub-Carrier 4.434MHz */
                .name       = "PAL",
                .clock          = 108000,
-               .refresh        = 25000,
+               .refresh        = 50000,
                .oversample     = TV_OVERSAMPLE_8X,
                .component_only = 0,
 
@@ -646,7 +646,7 @@ static const struct tv_mode tv_modes[] = {
                .vsync_start_f1 = 5,        .vsync_start_f2     = 6,
                .vsync_len      = 5,
 
-               .veq_ena        = true,             .veq_start_f1       = 0,
+               .veq_ena        = true,     .veq_start_f1       = 0,
                .veq_start_f2   = 1,        .veq_len            = 15,
 
                .vi_end_f1      = 24,               .vi_end_f2          = 25,
@@ -675,7 +675,7 @@ static const struct tv_mode tv_modes[] = {
        },
        {
                .name       = "480p@59.94Hz",
-               .clock  = 107520,
+               .clock          = 107520,
                .refresh        = 59940,
                .oversample     = TV_OVERSAMPLE_4X,
                .component_only = 1,
@@ -683,7 +683,7 @@ static const struct tv_mode tv_modes[] = {
                .hsync_end      = 64,               .hblank_end         = 122,
                .hblank_start   = 842,              .htotal             = 857,
 
-               .progressive    = true,.trilevel_sync = false,
+               .progressive    = true,             .trilevel_sync = false,
 
                .vsync_start_f1 = 12,               .vsync_start_f2     = 12,
                .vsync_len      = 12,
@@ -699,7 +699,7 @@ static const struct tv_mode tv_modes[] = {
        },
        {
                .name       = "480p@60Hz",
-               .clock  = 107520,
+               .clock          = 107520,
                .refresh        = 60000,
                .oversample     = TV_OVERSAMPLE_4X,
                .component_only = 1,
@@ -707,7 +707,7 @@ static const struct tv_mode tv_modes[] = {
                .hsync_end      = 64,               .hblank_end         = 122,
                .hblank_start   = 842,              .htotal             = 856,
 
-               .progressive    = true,.trilevel_sync = false,
+               .progressive    = true,             .trilevel_sync = false,
 
                .vsync_start_f1 = 12,               .vsync_start_f2     = 12,
                .vsync_len      = 12,
@@ -723,7 +723,7 @@ static const struct tv_mode tv_modes[] = {
        },
        {
                .name       = "576p",
-               .clock  = 107520,
+               .clock          = 107520,
                .refresh        = 50000,
                .oversample     = TV_OVERSAMPLE_4X,
                .component_only = 1,
@@ -755,7 +755,7 @@ static const struct tv_mode tv_modes[] = {
                .hsync_end      = 80,               .hblank_end         = 300,
                .hblank_start   = 1580,             .htotal             = 1649,
 
-               .progressive    = true,             .trilevel_sync = true,
+               .progressive    = true,             .trilevel_sync = true,
 
                .vsync_start_f1 = 10,               .vsync_start_f2     = 10,
                .vsync_len      = 10,
@@ -779,7 +779,7 @@ static const struct tv_mode tv_modes[] = {
                .hsync_end      = 80,               .hblank_end         = 300,
                .hblank_start   = 1580,             .htotal             = 1651,
 
-               .progressive    = true,             .trilevel_sync = true,
+               .progressive    = true,             .trilevel_sync = true,
 
                .vsync_start_f1 = 10,               .vsync_start_f2     = 10,
                .vsync_len      = 10,
@@ -803,7 +803,7 @@ static const struct tv_mode tv_modes[] = {
                .hsync_end      = 80,               .hblank_end         = 300,
                .hblank_start   = 1580,             .htotal             = 1979,
 
-               .progressive    = true,                 .trilevel_sync = true,
+               .progressive    = true,             .trilevel_sync = true,
 
                .vsync_start_f1 = 10,               .vsync_start_f2     = 10,
                .vsync_len      = 10,
@@ -821,19 +821,19 @@ static const struct tv_mode tv_modes[] = {
        {
                .name       = "1080i@50Hz",
                .clock          = 148800,
-               .refresh        = 25000,
+               .refresh        = 50000,
                .oversample     = TV_OVERSAMPLE_2X,
                .component_only = 1,
 
                .hsync_end      = 88,               .hblank_end         = 235,
                .hblank_start   = 2155,             .htotal             = 2639,
 
-               .progressive    = false,            .trilevel_sync = true,
+               .progressive    = false,          .trilevel_sync = true,
 
                .vsync_start_f1 = 4,              .vsync_start_f2     = 5,
                .vsync_len      = 10,
 
-               .veq_ena        = true,             .veq_start_f1       = 4,
+               .veq_ena        = true,     .veq_start_f1       = 4,
                .veq_start_f2   = 4,        .veq_len            = 10,
 
 
@@ -847,19 +847,19 @@ static const struct tv_mode tv_modes[] = {
        {
                .name       = "1080i@60Hz",
                .clock          = 148800,
-               .refresh        = 30000,
+               .refresh        = 60000,
                .oversample     = TV_OVERSAMPLE_2X,
                .component_only = 1,
 
                .hsync_end      = 88,               .hblank_end         = 235,
                .hblank_start   = 2155,             .htotal             = 2199,
 
-               .progressive    = false,            .trilevel_sync = true,
+               .progressive    = false,            .trilevel_sync = true,
 
                .vsync_start_f1 = 4,               .vsync_start_f2     = 5,
                .vsync_len      = 10,
 
-               .veq_ena        = true,             .veq_start_f1       = 4,
+               .veq_ena        = true,             .veq_start_f1       = 4,
                .veq_start_f2   = 4,                .veq_len            = 10,
 
 
@@ -880,16 +880,16 @@ static const struct tv_mode tv_modes[] = {
                .hsync_end      = 88,               .hblank_end         = 235,
                .hblank_start   = 2155,             .htotal             = 2201,
 
-               .progressive    = false,            .trilevel_sync = true,
+               .progressive    = false,            .trilevel_sync = true,
 
                .vsync_start_f1 = 4,            .vsync_start_f2    = 5,
                .vsync_len      = 10,
 
                .veq_ena        = true,             .veq_start_f1       = 4,
-               .veq_start_f2 = 4,                  .veq_len = 10,
+               .veq_start_f2   = 4,            .veq_len          = 10,
 
 
-               .vi_end_f1      = 21,           .vi_end_f2              = 22,
+               .vi_end_f1      = 21,           .vi_end_f2        = 22,
                .nbr_end        = 539,
 
                .burst_ena      = false,
@@ -916,7 +916,7 @@ intel_tv_dpms(struct drm_encoder *encoder, int mode)
        struct drm_device *dev = encoder->dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
 
-       switch(mode) {
+       switch (mode) {
        case DRM_MODE_DPMS_ON:
                I915_WRITE(TV_CTL, I915_READ(TV_CTL) | TV_ENC_ENABLE);
                break;
@@ -933,7 +933,7 @@ intel_tv_mode_lookup(const char *tv_format)
 {
        int i;
 
-       for (i = 0; i < sizeof(tv_modes) / sizeof (tv_modes[0]); i++) {
+       for (i = 0; i < sizeof(tv_modes) / sizeof(tv_modes[0]); i++) {
                const struct tv_mode *tv_mode = &tv_modes[i];
 
                if (!strcmp(tv_format, tv_mode->name))
@@ -1128,7 +1128,7 @@ intel_tv_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
        if (color_conversion) {
                I915_WRITE(TV_CSC_Y, (color_conversion->ry << 16) |
                           color_conversion->gy);
-               I915_WRITE(TV_CSC_Y2,(color_conversion->by << 16) |
+               I915_WRITE(TV_CSC_Y2, (color_conversion->by << 16) |
                           color_conversion->ay);
                I915_WRITE(TV_CSC_U, (color_conversion->ru << 16) |
                           color_conversion->gu);
@@ -1232,7 +1232,7 @@ static const struct drm_display_mode reported_modes[] = {
  * \return false if TV is disconnected.
  */
 static int
-intel_tv_detect_type (struct intel_tv *intel_tv,
+intel_tv_detect_type(struct intel_tv *intel_tv,
                      struct drm_connector *connector)
 {
        struct drm_encoder *encoder = &intel_tv->base.base;
@@ -1307,6 +1307,11 @@ intel_tv_detect_type (struct intel_tv *intel_tv,
 
        I915_WRITE(TV_DAC, save_tv_dac & ~TVDAC_STATE_CHG_EN);
        I915_WRITE(TV_CTL, save_tv_ctl);
+       POSTING_READ(TV_CTL);
+
+       /* For unknown reasons the hw barfs if we don't do this vblank wait. */
+       intel_wait_for_vblank(intel_tv->base.base.dev,
+                             to_intel_crtc(intel_tv->base.base.crtc)->pipe);
 
        /* Restore interrupt config */
        if (connector->polled & DRM_CONNECTOR_POLL_HPD) {
@@ -1486,7 +1491,7 @@ intel_tv_get_modes(struct drm_connector *connector)
 }
 
 static void
-intel_tv_destroy (struct drm_connector *connector)
+intel_tv_destroy(struct drm_connector *connector)
 {
        drm_sysfs_connector_remove(connector);
        drm_connector_cleanup(connector);