summaryrefslogtreecommitdiffstats
path: root/include/linux/backlight.h
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@rpsys.net>2007-02-08 22:25:09 +0000
committerRichard Purdie <rpurdie@rpsys.net>2007-02-20 08:38:45 +0000
commit28ee086d5b36aab2931f6740e409bb0fb6c65e5f (patch)
tree0a308c80affcc39c2c869f29f1109e5ee9d6140f /include/linux/backlight.h
parenta8db3c1948eb30cd6988b5b96b654f591e6280b1 (diff)
downloadlinux-stable-28ee086d5b36aab2931f6740e409bb0fb6c65e5f.tar.gz
linux-stable-28ee086d5b36aab2931f6740e409bb0fb6c65e5f.tar.bz2
linux-stable-28ee086d5b36aab2931f6740e409bb0fb6c65e5f.zip
backlight: Fix external uses of backlight internal semaphore
backlight_device->sem has a very specific use as documented in the header file. The external users of this are using it for a different reason, to serialise access to the update_status() method. backlight users were supposed to implement their own internal serialisation of update_status() if needed but everyone is doing things differently and incorrectly. Therefore add a global mutex to take care of serialisation for everyone, once and for all. Locking for get_brightness remains optional since most users don't need it. Also update the lcd class in a similar way. Signed-off-by: Richard Purdie <rpurdie@rpsys.net>
Diffstat (limited to 'include/linux/backlight.h')
-rw-r--r--include/linux/backlight.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index 287c62d956f2..d1426b852bdf 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -9,8 +9,24 @@
#define _LINUX_BACKLIGHT_H
#include <linux/device.h>
+#include <linux/mutex.h>
#include <linux/notifier.h>
+/* Notes on locking:
+ *
+ * backlight_device->sem is an internal backlight lock protecting the props
+ * field and no code outside the core should need to touch it.
+ *
+ * Access to update_status() is serialised by the update_lock mutex since
+ * most drivers seem to need this and historically get it wrong.
+ *
+ * Most drivers don't need locking on their get_brightness() method.
+ * If yours does, you need to implement it in the driver. You can use the
+ * update_lock mutex if appropriate.
+ *
+ * Any other use of the locks below is probably wrong.
+ */
+
struct backlight_device;
struct fb_info;
@@ -44,12 +60,22 @@ struct backlight_device {
struct semaphore sem;
/* If this is NULL, the backing module is unloaded */
struct backlight_properties *props;
+ /* Serialise access to update_status method */
+ struct mutex update_lock;
/* The framebuffer notifier block */
struct notifier_block fb_notif;
/* The class device structure */
struct class_device class_dev;
};
+static inline void backlight_update_status(struct backlight_device *bd)
+{
+ mutex_lock(&bd->update_lock);
+ if (bd->props && bd->props->update_status)
+ bd->props->update_status(bd);
+ mutex_unlock(&bd->update_lock);
+}
+
extern struct backlight_device *backlight_device_register(const char *name,
struct device *dev,void *devdata,struct backlight_properties *bp);
extern void backlight_device_unregister(struct backlight_device *bd);