Subject: [PATCH] powermac: defer work in backlight key press

From: Aristeu Sergio Rozanski Filho <[email-masked]>
Date: Mon, 3 Jul 2006 22:39:23 -0300

powermac: defer work in backlight key press

pmac_backlight_key() is called under interrupt context, can't use mutexes or
semaphores, so defer the backlight level for later, as it's not critical

Signed-off-by: Aristeu S. Rozanski F. <[email-masked]>

Index: ppc-2.6/arch/powerpc/platforms/powermac/backlight.c
===================================================================
--- ppc-2.6.orig/arch/powerpc/platforms/powermac/backlight.c	2006-07-03 21:00:44.000000000 -0300
+++ ppc-2.6/arch/powerpc/platforms/powermac/backlight.c	2006-07-03 21:38:12.000000000 -0300
@@ -15,6 +15,10 @@
 
 #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);
+static int pmac_backlight_key_queued;
+
 /* Protect the pmac_backlight variable */
 DEFINE_MUTEX(pmac_backlight_mutex);
 
@@ -71,7 +75,7 @@
 	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 +86,8 @@
 		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,6 +102,14 @@
 	mutex_unlock(&pmac_backlight_mutex);
 }
 
+static void pmac_backlight_key(int direction)
+{
+	/* 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);
+}
+
 void pmac_backlight_key_up()
 {
 	pmac_backlight_key(0);