From e01af0384f54023b4548b7742952da2ffcafd4cd Mon Sep 17 00:00:00 2001 From: Michael Hanselmann Date: Mon, 10 Jul 2006 04:44:45 -0700 Subject: [PATCH] powermac: Combined fixes for backlight code This patch fixes several problems: - pmac_backlight_key() is called under interrupt context, and therefore can't use mutexes or semaphores, so defer the backlight level for later, as it's not critical (original code by Aristeu S. Rozanski F. ). - Add exports for functions that might be called from modules - Fix Kconfig depdencies on PMAC_BACKLIGHT. - Fix locking issues on calls from inside the driver (reported by Aristeu S. Rozanski F., too) - Fix wrong calculation of backlight values in some of the drivers - Replace pmac_backlight_key_up/down by inline functions [akpm@osdl.org: fix function prototypes] Signed-off-by: Michael Hanselmann Acked-by: Aristeu S. Rozanski F. Acked-by: Rene Nussbaumer Cc: Benjamin Herrenschmidt Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/powerpc/platforms/powermac/backlight.c | 31 ++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'arch/powerpc/platforms/powermac/backlight.c') diff --git a/arch/powerpc/platforms/powermac/backlight.c b/arch/powerpc/platforms/powermac/backlight.c index 69f65e215a5c..74eed6b74cd6 100644 --- a/arch/powerpc/platforms/powermac/backlight.c +++ b/arch/powerpc/platforms/powermac/backlight.c @@ -15,6 +15,15 @@ #define OLD_BACKLIGHT_MAX 15 +static void pmac_backlight_key_worker(void *data); +static DECLARE_WORK(pmac_backlight_key_work, pmac_backlight_key_worker, NULL); + +/* Although this variable is used in interrupt context, it makes no sense to + * protect it. No user is able to produce enough key events per second and + * notice the errors that might happen. + */ +static int pmac_backlight_key_queued; + /* Protect the pmac_backlight variable */ DEFINE_MUTEX(pmac_backlight_mutex); @@ -71,7 +80,7 @@ int pmac_backlight_curve_lookup(struct fb_info *info, int value) return level; } -static void pmac_backlight_key(int direction) +static void pmac_backlight_key_worker(void *data) { mutex_lock(&pmac_backlight_mutex); if (pmac_backlight) { @@ -82,7 +91,8 @@ static void pmac_backlight_key(int direction) props = pmac_backlight->props; brightness = props->brightness + - ((direction?-1:1) * (props->max_brightness / 15)); + ((pmac_backlight_key_queued?-1:1) * + (props->max_brightness / 15)); if (brightness < 0) brightness = 0; @@ -97,14 +107,13 @@ static void pmac_backlight_key(int direction) mutex_unlock(&pmac_backlight_mutex); } -void pmac_backlight_key_up() +void pmac_backlight_key(int direction) { - pmac_backlight_key(0); -} - -void pmac_backlight_key_down() -{ - pmac_backlight_key(1); + /* we can receive multiple interrupts here, but the scheduled work + * will run only once, with the last value + */ + pmac_backlight_key_queued = direction; + schedule_work(&pmac_backlight_key_work); } int pmac_backlight_set_legacy_brightness(int brightness) @@ -157,3 +166,7 @@ int pmac_backlight_get_legacy_brightness() return result; } + +EXPORT_SYMBOL_GPL(pmac_backlight); +EXPORT_SYMBOL_GPL(pmac_backlight_mutex); +EXPORT_SYMBOL_GPL(pmac_has_backlight_type); -- cgit