backlight: Clean up pmac_backlight handling
[linux-2.6-block.git] / include / linux / backlight.h
CommitLineData
1da177e4
LT
1/*
2 * Backlight Lowlevel Control Abstraction
3 *
4 * Copyright (C) 2003,2004 Hewlett-Packard Company
5 *
6 */
7
8#ifndef _LINUX_BACKLIGHT_H
9#define _LINUX_BACKLIGHT_H
10
11#include <linux/device.h>
28ee086d 12#include <linux/mutex.h>
1da177e4
LT
13#include <linux/notifier.h>
14
28ee086d
RP
15/* Notes on locking:
16 *
249040dc
RP
17 * backlight_device->props_lock is an internal backlight lock protecting the
18 * props field and no code outside the core should need to touch it.
28ee086d
RP
19 *
20 * Access to update_status() is serialised by the update_lock mutex since
21 * most drivers seem to need this and historically get it wrong.
22 *
23 * Most drivers don't need locking on their get_brightness() method.
24 * If yours does, you need to implement it in the driver. You can use the
25 * update_lock mutex if appropriate.
26 *
27 * Any other use of the locks below is probably wrong.
28 */
29
1da177e4
LT
30struct backlight_device;
31struct fb_info;
32
33/* This structure defines all the properties of a backlight
34 (usually attached to a LCD). */
35struct backlight_properties {
6ca01765
RP
36 /* Notify the backlight driver some property has changed */
37 int (*update_status)(struct backlight_device *);
38 /* Return the current backlight brightness (accounting for power,
39 fb_blank etc.) */
1da177e4 40 int (*get_brightness)(struct backlight_device *);
1da177e4
LT
41 /* Check if given framebuffer device is the one bound to this backlight;
42 return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
43 int (*check_fb)(struct fb_info *);
6ca01765
RP
44
45 /* Current User requested brightness (0 - max_brightness) */
46 int brightness;
47 /* Maximal value for brightness (read-only) */
48 int max_brightness;
49 /* Current FB Power mode (0: full on, 1..3: power saving
50 modes; 4: full off), see FB_BLANK_XXX */
51 int power;
52 /* FB Blanking active? (values as for power) */
53 int fb_blank;
1da177e4
LT
54};
55
56struct backlight_device {
57 /* This protects the 'props' field. If 'props' is NULL, the driver that
58 registered this device has been unloaded, and if class_get_devdata()
59 points to something in the body of that driver, it is also invalid. */
249040dc 60 struct mutex props_lock;
1da177e4
LT
61 /* If this is NULL, the backing module is unloaded */
62 struct backlight_properties *props;
28ee086d
RP
63 /* Serialise access to update_status method */
64 struct mutex update_lock;
1da177e4
LT
65 /* The framebuffer notifier block */
66 struct notifier_block fb_notif;
67 /* The class device structure */
68 struct class_device class_dev;
69};
70
28ee086d
RP
71static inline void backlight_update_status(struct backlight_device *bd)
72{
73 mutex_lock(&bd->update_lock);
74 if (bd->props && bd->props->update_status)
75 bd->props->update_status(bd);
76 mutex_unlock(&bd->update_lock);
77}
78
1da177e4 79extern struct backlight_device *backlight_device_register(const char *name,
519ab5f2 80 struct device *dev,void *devdata,struct backlight_properties *bp);
1da177e4
LT
81extern void backlight_device_unregister(struct backlight_device *bd);
82
83#define to_backlight_device(obj) container_of(obj, struct backlight_device, class_dev)
84
85#endif