From 9bca4ef76a67fdaba8e4a3a9d0dbabd0ddd3c824 Mon Sep 17 00:00:00 2001 From: Carl Vanderlip Date: Tue, 25 Sep 2012 18:52:00 -0700 Subject: [PATCH] video: msm_fb: Ensure backlight is scaled atomically. Ensure that when backlight scaling ratio or backlight level is being changed that the operation execute atomically. This prevents a backlight level change from being overwritten when it interrupts a backlight scale update. CRs-Fixed: 404017 Signed-off-by: Carl Vanderlip (cherry picked from commit ce328861aa1f4fa489e9abfc9d1e02b13af2ba47) Signed-off-by: Dhivya Subramanian (cherry picked from commit 0584596f75f8f2b184b8be1a0479ee61e449acba) Change-Id: Ifb4bd5e823815b51dae38f1b8647b80d21b8ee45 Signed-off-by: Sudhir Sharma --- drivers/video/msm/msm_fb.c | 22 ++++++++++------------ drivers/video/msm/msm_fb_bl.c | 2 ++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/video/msm/msm_fb.c b/drivers/video/msm/msm_fb.c index d777d6a643b..78395775c44 100644 --- a/drivers/video/msm/msm_fb.c +++ b/drivers/video/msm/msm_fb.c @@ -198,7 +198,9 @@ static void msm_fb_set_bl_brightness(struct led_classdev *led_cdev, MAX_BACKLIGHT_BRIGHTNESS - 1) / (MAX_BACKLIGHT_BRIGHTNESS - 1) / 2; + down(&mfd->sem); msm_fb_set_backlight(mfd, bl_lvl); + up(&mfd->sem); } static struct led_classdev backlight_led = { @@ -845,7 +847,9 @@ static int mdp_bl_scale_config(struct msm_fb_data_type *mfd, struct mdp_bl_scale_data *data) { int ret = 0; - int curr_bl = mfd->bl_level; + int curr_bl; + down(&mfd->sem); + curr_bl = mfd->bl_level; bl_scale = data->scale; bl_min_lvl = data->min_lvl; pr_debug("%s: update scale = %d, min_lvl = %d\n", __func__, bl_scale, @@ -853,6 +857,7 @@ static int mdp_bl_scale_config(struct msm_fb_data_type *mfd, /* update current backlight to use new scaling*/ msm_fb_set_backlight(mfd, curr_bl); + up(&mfd->sem); return ret; } @@ -860,6 +865,7 @@ static int mdp_bl_scale_config(struct msm_fb_data_type *mfd, static void msm_fb_scale_bl(__u32 *bl_lvl) { __u32 temp = *bl_lvl; + pr_debug("%s: input = %d, scale = %d", __func__, temp, bl_scale); if (temp >= bl_min_lvl) { /* bl_scale is the numerator of scaling fraction (x/1024)*/ temp = ((*bl_lvl) * bl_scale) / 1024; @@ -868,10 +874,12 @@ static void msm_fb_scale_bl(__u32 *bl_lvl) if (temp < bl_min_lvl) temp = bl_min_lvl; } + pr_debug("%s: output = %d", __func__, temp); (*bl_lvl) = temp; } +/*must call this function from within mfd->sem*/ void msm_fb_set_backlight(struct msm_fb_data_type *mfd, __u32 bkl_lvl) { struct msm_fb_panel_data *pdata; @@ -884,27 +892,17 @@ void msm_fb_set_backlight(struct msm_fb_data_type *mfd, __u32 bkl_lvl) unset_bl_level = 0; } - if (!mfd->panel_power_on || !bl_updated) { - unset_bl_level = bkl_lvl; - return; - } else { - unset_bl_level = 0; - } - - msm_fb_scale_bl(&temp); pdata = (struct msm_fb_panel_data *)mfd->pdev->dev.platform_data; if ((pdata) && (pdata->set_backlight)) { - down(&mfd->sem); + msm_fb_scale_bl(&temp); if (bl_level_old == temp) { - up(&mfd->sem); return; } mfd->bl_level = temp; pdata->set_backlight(mfd); mfd->bl_level = bkl_lvl; bl_level_old = temp; - up(&mfd->sem); } } diff --git a/drivers/video/msm/msm_fb_bl.c b/drivers/video/msm/msm_fb_bl.c index 9afbbf16a57..b21adeef343 100644 --- a/drivers/video/msm/msm_fb_bl.c +++ b/drivers/video/msm/msm_fb_bl.c @@ -34,7 +34,9 @@ static int msm_fb_bl_update_status(struct backlight_device *pbd) bl_lvl = pbd->props.brightness; bl_lvl = mfd->fbi->bl_curve[bl_lvl]; + down(&mfd->sem); msm_fb_set_backlight(mfd, bl_lvl); + up(&mfd->sem); return 0; }