[PATCH] powermac backlight fixes
authorMichael Hanselmann <linux-kernel@hansmi.ch>
Wed, 28 Jun 2006 11:26:55 +0000 (04:26 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Wed, 28 Jun 2006 21:59:06 +0000 (14:59 -0700)
Fix a erroneous calculation of the legacy brightness values as reported by
Paul Collins.  Additionally, it moves the calculation of the negative value
in the radeonfb driver after the value check.

Signed-off-by: Michael Hanselmann <linux-kernel@hansmi.ch>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Paul Collins <paul@briny.ondioline.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
arch/powerpc/platforms/powermac/backlight.c
drivers/video/aty/radeon_backlight.c

index 498b042e1837567c2326c93faa404d6ffa6a4d00..c7a27eddca6d4b96f002f2c5b5a3725933849089 100644 (file)
@@ -119,7 +119,14 @@ int pmac_backlight_set_legacy_brightness(int brightness)
                down(&pmac_backlight->sem);
                props = pmac_backlight->props;
                props->brightness = brightness *
-                       props->max_brightness / OLD_BACKLIGHT_MAX;
+                       (props->max_brightness + 1) /
+                       (OLD_BACKLIGHT_MAX + 1);
+
+               if (props->brightness > props->max_brightness)
+                       props->brightness = props->max_brightness;
+               else if (props->brightness < 0)
+                       props->brightness = 0;
+
                props->update_status(pmac_backlight);
                up(&pmac_backlight->sem);
 
@@ -140,8 +147,11 @@ int pmac_backlight_get_legacy_brightness()
 
                down(&pmac_backlight->sem);
                props = pmac_backlight->props;
+
                result = props->brightness *
-                       OLD_BACKLIGHT_MAX / props->max_brightness;
+                       (OLD_BACKLIGHT_MAX + 1) /
+                       (props->max_brightness + 1);
+
                up(&pmac_backlight->sem);
        }
        mutex_unlock(&pmac_backlight_mutex);
index 7de66b855d4e4e292d13182c40fafe0a44ceddac..1755dddf189908550b0dae24bdf8d2d498b1cc46 100644 (file)
@@ -40,14 +40,14 @@ static int radeon_bl_get_level_brightness(struct radeon_bl_privdata *pdata,
 
        mutex_unlock(&info->bl_mutex);
 
-       if (pdata->negative)
-               rlevel = MAX_RADEON_LEVEL - rlevel;
-
        if (rlevel < 0)
                rlevel = 0;
        else if (rlevel > MAX_RADEON_LEVEL)
                rlevel = MAX_RADEON_LEVEL;
 
+       if (pdata->negative)
+               rlevel = MAX_RADEON_LEVEL - rlevel;
+
        return rlevel;
 }