These functions mostly do the same thing so unify them into one. Oaktrail doesn't power on/off the backlight so don't touch that. Ignore runtime-pm stuff since runtime-pm is broken anyways.
Signed-off-by: Patrik Jakobsson <patrik.r.jakobs...@gmail.com> --- drivers/gpu/drm/gma500/cdv_intel_lvds.c | 41 +++------------------ drivers/gpu/drm/gma500/gma_lvds.c | 37 ++++++++++++++++++- drivers/gpu/drm/gma500/gma_lvds.h | 2 +- drivers/gpu/drm/gma500/oaktrail_lvds.c | 47 +++---------------------- drivers/gpu/drm/gma500/psb_drv.h | 1 - drivers/gpu/drm/gma500/psb_intel_lvds.c | 43 +++------------------- 6 files changed, 49 insertions(+), 122 deletions(-) diff --git a/drivers/gpu/drm/gma500/cdv_intel_lvds.c b/drivers/gpu/drm/gma500/cdv_intel_lvds.c index 615570de82b0..7bf883bb8104 100644 --- a/drivers/gpu/drm/gma500/cdv_intel_lvds.c +++ b/drivers/gpu/drm/gma500/cdv_intel_lvds.c @@ -53,46 +53,13 @@ struct cdv_intel_lvds_priv { uint32_t saveBLC_PWM_CTL; }; -/* - * Sets the power state for the panel. - */ -static void cdv_intel_lvds_set_power(struct drm_device *dev, - struct drm_encoder *encoder, bool on) -{ - struct drm_psb_private *dev_priv = to_drm_psb_private(dev); - u32 pp_status; - - if (!gma_power_begin(dev, true)) - return; - - if (on) { - REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) | - POWER_TARGET_ON); - do { - pp_status = REG_READ(PP_STATUS); - } while ((pp_status & PP_ON) == 0); - - gma_lvds_set_backlight(dev, - dev_priv->mode_dev.backlight_duty_cycle); - } else { - gma_lvds_set_backlight(dev, 0); - - REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) & - ~POWER_TARGET_ON); - do { - pp_status = REG_READ(PP_STATUS); - } while (pp_status & PP_ON); - } - gma_power_end(dev); -} - static void cdv_intel_lvds_encoder_dpms(struct drm_encoder *encoder, int mode) { struct drm_device *dev = encoder->dev; if (mode == DRM_MODE_DPMS_ON) - cdv_intel_lvds_set_power(dev, encoder, true); + gma_lvds_set_power(dev, true); else - cdv_intel_lvds_set_power(dev, encoder, false); + gma_lvds_set_power(dev, false); /* XXX: We never power down the LVDS pairs. */ } @@ -191,7 +158,7 @@ static void cdv_intel_lvds_prepare(struct drm_encoder *encoder) mode_dev->backlight_duty_cycle = (mode_dev->saveBLC_PWM_CTL & BACKLIGHT_DUTY_CYCLE_MASK); - cdv_intel_lvds_set_power(dev, encoder, false); + gma_lvds_set_power(dev, false); gma_power_end(dev); } @@ -206,7 +173,7 @@ static void cdv_intel_lvds_commit(struct drm_encoder *encoder) mode_dev->backlight_duty_cycle = gma_lvds_get_max_backlight(dev); - cdv_intel_lvds_set_power(dev, encoder, true); + gma_lvds_set_power(dev, true); } static void cdv_intel_lvds_mode_set(struct drm_encoder *encoder, diff --git a/drivers/gpu/drm/gma500/gma_lvds.c b/drivers/gpu/drm/gma500/gma_lvds.c index 5b041fab82ba..11efbb14b55c 100644 --- a/drivers/gpu/drm/gma500/gma_lvds.c +++ b/drivers/gpu/drm/gma500/gma_lvds.c @@ -36,7 +36,7 @@ u32 gma_lvds_get_max_backlight(struct drm_device *dev) * * level: backlight level, from 0 to gma_lvds_get_max_backlight(). */ -void gma_lvds_set_backlight(struct drm_device *dev, int level) +static void gma_lvds_set_backlight(struct drm_device *dev, int level) { struct drm_psb_private *dev_priv = to_drm_psb_private(dev); u32 blc_pwm_ctl; @@ -58,3 +58,38 @@ void gma_lvds_set_backlight(struct drm_device *dev, int level) } } +/* + * Sets the power state for the panel. + */ +void gma_lvds_set_power(struct drm_device *dev, bool on) +{ + struct drm_psb_private *dev_priv = to_drm_psb_private(dev); + u32 pp_status; + + if (!gma_power_begin(dev, true)) + return; + + if (on) { + REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) | + POWER_TARGET_ON); + do { + pp_status = REG_READ(PP_STATUS); + } while ((pp_status & PP_ON) == 0); + + if (!IS_MRST(dev)) { + gma_lvds_set_backlight(dev, + dev_priv->mode_dev.backlight_duty_cycle); + } + } else { + if (!IS_MRST(dev)) + gma_lvds_set_backlight(dev, 0); + + REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) & + ~POWER_TARGET_ON); + do { + pp_status = REG_READ(PP_STATUS); + } while (pp_status & PP_ON); + } + gma_power_end(dev); +} + diff --git a/drivers/gpu/drm/gma500/gma_lvds.h b/drivers/gpu/drm/gma500/gma_lvds.h index f26cc69b6caa..477d3b5005f7 100644 --- a/drivers/gpu/drm/gma500/gma_lvds.h +++ b/drivers/gpu/drm/gma500/gma_lvds.h @@ -8,6 +8,6 @@ #define _GMA_LVDS_H u32 gma_lvds_get_max_backlight(struct drm_device *dev); -void gma_lvds_set_backlight(struct drm_device *dev, int level); +void gma_lvds_set_power(struct drm_device *dev, bool on); #endif diff --git a/drivers/gpu/drm/gma500/oaktrail_lvds.c b/drivers/gpu/drm/gma500/oaktrail_lvds.c index 4913baca7ae2..9634807e4d8c 100644 --- a/drivers/gpu/drm/gma500/oaktrail_lvds.c +++ b/drivers/gpu/drm/gma500/oaktrail_lvds.c @@ -30,51 +30,14 @@ #define MRST_BLC_MAX_PWM_REG_FREQ 0xFFFF #define BRIGHTNESS_MAX_LEVEL 100 -/* - * Sets the power state for the panel. - */ -static void oaktrail_lvds_set_power(struct drm_device *dev, - struct gma_encoder *gma_encoder, - bool on) -{ - u32 pp_status; - struct drm_psb_private *dev_priv = to_drm_psb_private(dev); - - if (!gma_power_begin(dev, true)) - return; - - if (on) { - REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) | - POWER_TARGET_ON); - do { - pp_status = REG_READ(PP_STATUS); - } while ((pp_status & (PP_ON | PP_READY)) == PP_READY); - dev_priv->is_lvds_on = true; - if (dev_priv->ops->lvds_bl_power) - dev_priv->ops->lvds_bl_power(dev, true); - } else { - if (dev_priv->ops->lvds_bl_power) - dev_priv->ops->lvds_bl_power(dev, false); - REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) & - ~POWER_TARGET_ON); - do { - pp_status = REG_READ(PP_STATUS); - } while (pp_status & PP_ON); - dev_priv->is_lvds_on = false; - pm_request_idle(dev->dev); - } - gma_power_end(dev); -} - static void oaktrail_lvds_dpms(struct drm_encoder *encoder, int mode) { struct drm_device *dev = encoder->dev; - struct gma_encoder *gma_encoder = to_gma_encoder(encoder); if (mode == DRM_MODE_DPMS_ON) - oaktrail_lvds_set_power(dev, gma_encoder, true); + gma_lvds_set_power(dev, true); else - oaktrail_lvds_set_power(dev, gma_encoder, false); + gma_lvds_set_power(dev, false); /* XXX: We never power down the LVDS pairs. */ } @@ -158,7 +121,6 @@ static void oaktrail_lvds_prepare(struct drm_encoder *encoder) { struct drm_device *dev = encoder->dev; struct drm_psb_private *dev_priv = to_drm_psb_private(dev); - struct gma_encoder *gma_encoder = to_gma_encoder(encoder); struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; if (!gma_power_begin(dev, true)) @@ -167,7 +129,7 @@ static void oaktrail_lvds_prepare(struct drm_encoder *encoder) mode_dev->saveBLC_PWM_CTL = REG_READ(BLC_PWM_CTL); mode_dev->backlight_duty_cycle = (mode_dev->saveBLC_PWM_CTL & BACKLIGHT_DUTY_CYCLE_MASK); - oaktrail_lvds_set_power(dev, gma_encoder, false); + gma_lvds_set_power(dev, false); gma_power_end(dev); } @@ -175,12 +137,11 @@ static void oaktrail_lvds_commit(struct drm_encoder *encoder) { struct drm_device *dev = encoder->dev; struct drm_psb_private *dev_priv = to_drm_psb_private(dev); - struct gma_encoder *gma_encoder = to_gma_encoder(encoder); struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; if (mode_dev->backlight_duty_cycle == 0) mode_dev->backlight_duty_cycle = gma_lvds_get_max_backlight(dev); - oaktrail_lvds_set_power(dev, gma_encoder, true); + gma_lvds_set_power(dev, true); } static const struct drm_encoder_helper_funcs oaktrail_lvds_helper_funcs = { diff --git a/drivers/gpu/drm/gma500/psb_drv.h b/drivers/gpu/drm/gma500/psb_drv.h index 0ea3d23575f3..2789ae9efe3c 100644 --- a/drivers/gpu/drm/gma500/psb_drv.h +++ b/drivers/gpu/drm/gma500/psb_drv.h @@ -601,7 +601,6 @@ struct psb_ops { void (*update_wm)(struct drm_device *dev, struct drm_crtc *crtc); void (*disable_sr)(struct drm_device *dev); - void (*lvds_bl_power)(struct drm_device *dev, bool on); #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE /* Backlight */ int (*backlight_init)(struct drm_device *dev); diff --git a/drivers/gpu/drm/gma500/psb_intel_lvds.c b/drivers/gpu/drm/gma500/psb_intel_lvds.c index a304f840b127..06f1bd2250dd 100644 --- a/drivers/gpu/drm/gma500/psb_intel_lvds.c +++ b/drivers/gpu/drm/gma500/psb_intel_lvds.c @@ -148,49 +148,14 @@ void psb_intel_lvds_set_brightness(struct drm_device *dev, int level) psb_lvds_pwm_set_brightness(dev, level); } -/* - * Sets the power state for the panel. - */ -static void psb_intel_lvds_set_power(struct drm_device *dev, bool on) -{ - struct drm_psb_private *dev_priv = to_drm_psb_private(dev); - struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; - u32 pp_status; - - if (!gma_power_begin(dev, true)) { - dev_err(dev->dev, "set power, chip off!\n"); - return; - } - - if (on) { - REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) | - POWER_TARGET_ON); - do { - pp_status = REG_READ(PP_STATUS); - } while ((pp_status & PP_ON) == 0); - - gma_lvds_set_backlight(dev, mode_dev->backlight_duty_cycle); - } else { - gma_lvds_set_backlight(dev, 0); - - REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) & - ~POWER_TARGET_ON); - do { - pp_status = REG_READ(PP_STATUS); - } while (pp_status & PP_ON); - } - - gma_power_end(dev); -} - static void psb_intel_lvds_encoder_dpms(struct drm_encoder *encoder, int mode) { struct drm_device *dev = encoder->dev; if (mode == DRM_MODE_DPMS_ON) - psb_intel_lvds_set_power(dev, true); + gma_lvds_set_power(dev, true); else - psb_intel_lvds_set_power(dev, false); + gma_lvds_set_power(dev, false); /* XXX: We never power down the LVDS pairs. */ } @@ -378,7 +343,7 @@ static void psb_intel_lvds_prepare(struct drm_encoder *encoder) mode_dev->backlight_duty_cycle = (mode_dev->saveBLC_PWM_CTL & BACKLIGHT_DUTY_CYCLE_MASK); - psb_intel_lvds_set_power(dev, false); + gma_lvds_set_power(dev, false); gma_power_end(dev); } @@ -393,7 +358,7 @@ static void psb_intel_lvds_commit(struct drm_encoder *encoder) mode_dev->backlight_duty_cycle = gma_lvds_get_max_backlight(dev); - psb_intel_lvds_set_power(dev, true); + gma_lvds_set_power(dev, true); } static void psb_intel_lvds_mode_set(struct drm_encoder *encoder, -- 2.36.1