if (machine_is(powermac) && pmac_backlight) {
struct backlight_properties *props;
- down(&pmac_backlight->sem);
props = pmac_backlight->props;
props->brightness = props->max_brightness;
props->power = FB_BLANK_UNBLANK;
- props->update_status(pmac_backlight);
- up(&pmac_backlight->sem);
+ backlight_update_status(pmac_backlight);
}
mutex_unlock(&pmac_backlight_mutex);
#endif
*/
static atomic_t kernel_backlight_disabled = ATOMIC_INIT(0);
-/* Protect the pmac_backlight variable */
+/* Protect the pmac_backlight variable below.
+ You should hold this lock when using the pmac_backlight pointer to
+ prevent its potential removal. */
DEFINE_MUTEX(pmac_backlight_mutex);
/* Main backlight storage
* internal display, it doesn't matter. Other backlight drivers can be used
* independently.
*
- * Lock ordering:
- * pmac_backlight_mutex (global, main backlight)
- * pmac_backlight->sem (backlight class)
*/
struct backlight_device *pmac_backlight;
struct backlight_properties *props;
int brightness;
- down(&pmac_backlight->sem);
props = pmac_backlight->props;
brightness = props->brightness +
brightness = props->max_brightness;
props->brightness = brightness;
- props->update_status(pmac_backlight);
-
- up(&pmac_backlight->sem);
+ backlight_update_status(pmac_backlight);
}
mutex_unlock(&pmac_backlight_mutex);
}
if (pmac_backlight) {
struct backlight_properties *props;
- down(&pmac_backlight->sem);
props = pmac_backlight->props;
props->brightness = brightness *
(props->max_brightness + 1) /
else if (props->brightness < 0)
props->brightness = 0;
- props->update_status(pmac_backlight);
- up(&pmac_backlight->sem);
+ backlight_update_status(pmac_backlight);
error = 0;
}
if (pmac_backlight) {
struct backlight_properties *props;
- down(&pmac_backlight->sem);
props = pmac_backlight->props;
result = props->brightness *
(OLD_BACKLIGHT_MAX + 1) /
(props->max_brightness + 1);
-
- up(&pmac_backlight->sem);
}
mutex_unlock(&pmac_backlight_mutex);
pmu_backlight_data.max_brightness / 15);
}
- down(&bd->sem);
bd->props->brightness = level;
bd->props->power = FB_BLANK_UNBLANK;
- bd->props->update_status(bd);
- up(&bd->sem);
+ backlight_update_status(bd);
mutex_lock(&pmac_backlight_mutex);
if (!pmac_backlight)
struct backlight_device *bd = asus_backlight_device;
if (bd) {
- down(&bd->sem);
- if (likely(bd->props)) {
- bd->props->power = blank;
- if (likely(bd->props->update_status))
- bd->props->update_status(bd);
- }
- up(&bd->sem);
+ bd->props->power = blank;
+ backlight_update_status(bd);
}
}
asus_backlight_device = bd;
- down(&bd->sem);
- if (likely(bd->props)) {
- bd->props->brightness = read_brightness(NULL);
- bd->props->power = FB_BLANK_UNBLANK;
- if (likely(bd->props->update_status))
- bd->props->update_status(bd);
- }
- up(&bd->sem);
+ bd->props->brightness = read_brightness(NULL);
+ bd->props->power = FB_BLANK_UNBLANK;
+ backlight_update_status(bd);
}
return 0;
}
container_of(work, struct appledisplay, work.work);
int retval;
- up(&pdata->bd->sem);
retval = appledisplay_bl_get_brightness(pdata->bd);
if (retval >= 0)
pdata->bd->props->brightness = retval;
- down(&pdata->bd->sem);
/* Poll again in about 125ms if there's still a button pressed */
if (pdata->button_pressed)
}
/* Try to get brightness */
- up(&pdata->bd->sem);
brightness = appledisplay_bl_get_brightness(pdata->bd);
- down(&pdata->bd->sem);
if (brightness < 0) {
retval = brightness;
}
/* Set brightness in backlight device */
- up(&pdata->bd->sem);
pdata->bd->props->brightness = brightness;
- down(&pdata->bd->sem);
/* save our data pointer in the interface device */
usb_set_intfdata(iface, pdata);
mutex_lock(&info->bl_mutex);
if (info->bl_dev) {
- down(&info->bl_dev->sem);
info->bl_dev->props->power = power;
__aty128_bl_update_status(info->bl_dev);
- up(&info->bl_dev->sem);
}
mutex_unlock(&info->bl_mutex);
219 * FB_BACKLIGHT_MAX / MAX_LEVEL);
mutex_unlock(&info->bl_mutex);
- down(&bd->sem);
bd->props->brightness = aty128_bl_data.max_brightness;
bd->props->power = FB_BLANK_UNBLANK;
- bd->props->update_status(bd);
- up(&bd->sem);
+ backlight_update_status(bd);
#ifdef CONFIG_PMAC_BACKLIGHT
mutex_lock(&pmac_backlight_mutex);
mutex_lock(&info->bl_mutex);
if (info->bl_dev) {
- down(&info->bl_dev->sem);
info->bl_dev->props->power = power;
__aty_bl_update_status(info->bl_dev);
- up(&info->bl_dev->sem);
}
mutex_unlock(&info->bl_mutex);
0xFF * FB_BACKLIGHT_MAX / MAX_LEVEL);
mutex_unlock(&info->bl_mutex);
- down(&bd->sem);
bd->props->brightness = aty_bl_data.max_brightness;
bd->props->power = FB_BLANK_UNBLANK;
- bd->props->update_status(bd);
- up(&bd->sem);
+ backlight_update_status(bd);
#ifdef CONFIG_PMAC_BACKLIGHT
mutex_lock(&pmac_backlight_mutex);
217 * FB_BACKLIGHT_MAX / MAX_RADEON_LEVEL);
mutex_unlock(&rinfo->info->bl_mutex);
- down(&bd->sem);
bd->props->brightness = radeon_bl_data.max_brightness;
bd->props->power = FB_BLANK_UNBLANK;
- bd->props->update_status(bd);
- up(&bd->sem);
+ backlight_update_status(bd);
#ifdef CONFIG_PMAC_BACKLIGHT
mutex_lock(&pmac_backlight_mutex);
if (!bd->props->check_fb ||
bd->props->check_fb(evdata->info)) {
bd->props->fb_blank = *(int *)evdata->data;
- if (bd->props && bd->props->update_status)
- bd->props->update_status(bd);
+ backlight_update_status(bd);
}
up(&bd->sem);
return 0;
if (bd->props) {
pr_debug("backlight: set power to %d\n", power);
bd->props->power = power;
- if (bd->props->update_status)
- bd->props->update_status(bd);
+ backlight_update_status(bd);
rc = count;
}
up(&bd->sem);
pr_debug("backlight: set brightness to %d\n",
brightness);
bd->props->brightness = brightness;
- if (bd->props->update_status)
- bd->props->update_status(bd);
+ backlight_update_status(bd);
rc = count;
}
}
if (!new_bd)
return ERR_PTR(-ENOMEM);
+ mutex_init(&new_bd->update_lock);
init_MUTEX(&new_bd->sem);
new_bd->props = bp;
memset(&new_bd->class_dev, 0, sizeof(new_bd->class_dev));
return ERR_PTR(-ENOMEM);
init_MUTEX(&new_ld->sem);
+ mutex_init(&new_ld->update_lock);
new_ld->props = lp;
memset(&new_ld->class_dev, 0, sizeof(new_ld->class_dev));
new_ld->class_dev.class = &lcd_class;
* useful at blank = 1 too (saves battery, extends backlight
* life)
*/
- down(&pmac_backlight->sem);
if (blank)
pmac_backlight->props->power = FB_BLANK_POWERDOWN;
else
pmac_backlight->props->power = FB_BLANK_UNBLANK;
- pmac_backlight->props->update_status(pmac_backlight);
- up(&pmac_backlight->sem);
+ backlight_update_status(pmac_backlight);
}
mutex_unlock(&pmac_backlight_mutex);
/* turn on the backlight */
mutex_lock(&pmac_backlight_mutex);
if (pmac_backlight) {
- down(&pmac_backlight->sem);
pmac_backlight->props->power = FB_BLANK_UNBLANK;
- pmac_backlight->props->update_status(pmac_backlight);
- up(&pmac_backlight->sem);
+ backlight_update_status(pmac_backlight);
}
mutex_unlock(&pmac_backlight_mutex);
#endif /* CONFIG_PMAC_BACKLIGHT */
mutex_lock(&info->bl_mutex);
if (info->bl_dev) {
- down(&info->bl_dev->sem);
info->bl_dev->props->power = power;
__nvidia_bl_update_status(info->bl_dev);
- up(&info->bl_dev->sem);
}
mutex_unlock(&info->bl_mutex);
0x534 * FB_BACKLIGHT_MAX / MAX_LEVEL);
mutex_unlock(&info->bl_mutex);
- down(&bd->sem);
bd->props->brightness = nvidia_bl_data.max_brightness;
bd->props->power = FB_BLANK_UNBLANK;
- bd->props->update_status(bd);
- up(&bd->sem);
+ backlight_update_status(bd);
#ifdef CONFIG_PMAC_BACKLIGHT
mutex_lock(&pmac_backlight_mutex);
mutex_lock(&info->bl_mutex);
if (info->bl_dev) {
- down(&info->bl_dev->sem);
info->bl_dev->props->power = power;
__riva_bl_update_status(info->bl_dev);
- up(&info->bl_dev->sem);
}
mutex_unlock(&info->bl_mutex);
FB_BACKLIGHT_MAX);
mutex_unlock(&info->bl_mutex);
- down(&bd->sem);
bd->props->brightness = riva_bl_data.max_brightness;
bd->props->power = FB_BLANK_UNBLANK;
- bd->props->update_status(bd);
- up(&bd->sem);
+ backlight_update_status(bd);
#ifdef CONFIG_PMAC_BACKLIGHT
mutex_lock(&pmac_backlight_mutex);
#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;
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);
#define _LINUX_LCD_H
#include <linux/device.h>
+#include <linux/mutex.h>
#include <linux/notifier.h>
+/* 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;
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);