]> Git Repo - linux.git/commitdiff
drm/i915/backlight: Fix backlight takeover on LPT, v3.
authorMaarten Lankhorst <[email protected]>
Tue, 8 Jan 2019 16:08:39 +0000 (17:08 +0100)
committerMaarten Lankhorst <[email protected]>
Thu, 24 Jan 2019 12:02:48 +0000 (13:02 +0100)
On lynxpoint the bios sometimes sets up the backlight using the CPU
display, but the driver expects using the PWM PCH override register.

Read the value from the CPU register, then convert it to the other
units by converting from the old duty cycle, to freq, to the new units.

This value is then programmed in the override register, after which
we set the override and disable the CPU display control. This allows
us to switch the source without flickering, and make the backlight
controls work in the driver.

Changes since v1:
- Read BLC_PWM_CPU_CTL2 to cpu_ctl2.
- Clean up cpu_mode if slightly.
- Always disable BLM_PWM_ENABLE in cpu_ctl2.
Changes since v2:
- Simplify cpu_mode handling (Jani)

Signed-off-by: Maarten Lankhorst <[email protected]>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=108225
Cc: Basil Eric Rabi <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Tolga Cakir <[email protected]>
Cc: Ville Syrjälä <[email protected]>
Tested-by: Tolga Cakir <[email protected]>
Cc: Jani Nikula <[email protected]>
Reviewed-by: Hans de Goede <[email protected]>
Reviewed-by: Jani Nikula <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
drivers/gpu/drm/i915/intel_panel.c

index bb8612ab8ee1613e2b493ba5a49132aea85a84e9..beca98d2b035b2a84f3425a674cfbb4a4966aa13 100644 (file)
@@ -1496,8 +1496,8 @@ static int lpt_setup_backlight(struct intel_connector *connector, enum pipe unus
 {
        struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
        struct intel_panel *panel = &connector->panel;
-       u32 pch_ctl1, pch_ctl2, val;
-       bool alt;
+       u32 cpu_ctl2, pch_ctl1, pch_ctl2, val;
+       bool alt, cpu_mode;
 
        if (HAS_PCH_LPT(dev_priv))
                alt = I915_READ(SOUTH_CHICKEN2) & LPT_PWM_GRANULARITY;
@@ -1511,6 +1511,8 @@ static int lpt_setup_backlight(struct intel_connector *connector, enum pipe unus
        pch_ctl2 = I915_READ(BLC_PWM_PCH_CTL2);
        panel->backlight.max = pch_ctl2 >> 16;
 
+       cpu_ctl2 = I915_READ(BLC_PWM_CPU_CTL2);
+
        if (!panel->backlight.max)
                panel->backlight.max = get_backlight_max_vbt(connector);
 
@@ -1519,12 +1521,28 @@ static int lpt_setup_backlight(struct intel_connector *connector, enum pipe unus
 
        panel->backlight.min = get_backlight_min_vbt(connector);
 
-       val = lpt_get_backlight(connector);
+       panel->backlight.enabled = pch_ctl1 & BLM_PCH_PWM_ENABLE;
+
+       cpu_mode = panel->backlight.enabled && HAS_PCH_LPT(dev_priv) &&
+                  !(pch_ctl1 & BLM_PCH_OVERRIDE_ENABLE) &&
+                  (cpu_ctl2 & BLM_PWM_ENABLE);
+       if (cpu_mode)
+               val = pch_get_backlight(connector);
+       else
+               val = lpt_get_backlight(connector);
        val = intel_panel_compute_brightness(connector, val);
        panel->backlight.level = clamp(val, panel->backlight.min,
                                       panel->backlight.max);
 
-       panel->backlight.enabled = pch_ctl1 & BLM_PCH_PWM_ENABLE;
+       if (cpu_mode) {
+               DRM_DEBUG_KMS("CPU backlight register was enabled, switching to PCH override\n");
+
+               /* Write converted CPU PWM value to PCH override register */
+               lpt_set_backlight(connector->base.state, panel->backlight.level);
+               I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1 | BLM_PCH_OVERRIDE_ENABLE);
+
+               I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2 & ~BLM_PWM_ENABLE);
+       }
 
        return 0;
 }
This page took 0.048961 seconds and 4 git commands to generate.