From 28ee086d5b36aab2931f6740e409bb0fb6c65e5f Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Thu, 8 Feb 2007 22:25:09 +0000 Subject: 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 --- include/linux/lcd.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'include/linux/lcd.h') diff --git a/include/linux/lcd.h b/include/linux/lcd.h index 8a468f168c45..bfbf6552eb51 100644 --- a/include/linux/lcd.h +++ b/include/linux/lcd.h @@ -9,8 +9,24 @@ #define _LINUX_LCD_H #include +#include #include +/* Notes on locking: + * + * lcd_device->sem is an internal backlight lock protecting the props + * field and no code outside the core should need to touch it. + * + * Access to set_power() 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_power() 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 lcd_device; struct fb_info; @@ -39,12 +55,22 @@ struct lcd_device { struct semaphore sem; /* If this is NULL, the backing module is unloaded */ struct lcd_properties *props; + /* Serialise access to set_power 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 lcd_set_power(struct lcd_device *ld, int power) +{ + mutex_lock(&ld->update_lock); + if (ld->props && ld->props->set_power) + ld->props->set_power(ld, power); + mutex_unlock(&ld->update_lock); +} + extern struct lcd_device *lcd_device_register(const char *name, void *devdata, struct lcd_properties *lp); extern void lcd_device_unregister(struct lcd_device *ld); -- cgit v1.2.3