From 321709c5994f952b78d567fd7083dbebbdc381b7 Mon Sep 17 00:00:00 2001
From: Richard Purdie <rpurdie@rpsys.net>
Date: Sat, 10 Feb 2007 15:04:08 +0000
Subject: backlight: Clean up pmac_backlight handling

Move the setting/unsetting of pmac_backlight into the
backlight core instead of doing it in each driver.

Signed-off-by: Richard Purdie <rpurdie@rpsys.net>
---
 drivers/video/backlight/backlight.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

(limited to 'drivers/video/backlight')

diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 5490b2ae513..822a373d334 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -14,6 +14,9 @@
 #include <linux/err.h>
 #include <linux/fb.h>
 
+#ifdef CONFIG_PMAC_BACKLIGHT
+#include <asm/backlight.h>
+#endif
 
 #if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \
 			   defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE))
@@ -262,6 +265,13 @@ struct backlight_device *backlight_device_register(const char *name,
 		}
 	}
 
+#ifdef CONFIG_PMAC_BACKLIGHT
+	mutex_lock(&pmac_backlight_mutex);
+	if (!pmac_backlight)
+		pmac_backlight = new_bd;
+	mutex_unlock(&pmac_backlight_mutex);
+#endif
+
 	return new_bd;
 }
 EXPORT_SYMBOL(backlight_device_register);
@@ -281,6 +291,13 @@ void backlight_device_unregister(struct backlight_device *bd)
 
 	pr_debug("backlight_device_unregister: name=%s\n", bd->class_dev.class_id);
 
+#ifdef CONFIG_PMAC_BACKLIGHT
+	mutex_lock(&pmac_backlight_mutex);
+	if (pmac_backlight == bd)
+		pmac_backlight = NULL;
+	mutex_unlock(&pmac_backlight_mutex);
+#endif
+
 	for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++)
 		class_device_remove_file(&bd->class_dev,
 					 &bl_class_device_attributes[i]);
-- 
cgit v1.2.3-70-g09d2