blob: d1426b852bdfe28001b86b95532cd0c1d62971d8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Richard Purdie28ee0862007-02-08 22:25:09 +000012#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/notifier.h>
14
Richard Purdie28ee0862007-02-08 22:25:09 +000015/* Notes on locking:
16 *
17 * backlight_device->sem is an internal backlight lock protecting the props
18 * field and no code outside the core should need to touch it.
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070030struct 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 {
Richard Purdie6ca01762006-03-31 02:31:49 -080036 /* 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.) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 int (*get_brightness)(struct backlight_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 /* 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 *);
Richard Purdie6ca01762006-03-31 02:31:49 -080044
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054};
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. */
60 struct semaphore sem;
61 /* If this is NULL, the backing module is unloaded */
62 struct backlight_properties *props;
Richard Purdie28ee0862007-02-08 22:25:09 +000063 /* Serialise access to update_status method */
64 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 /* The framebuffer notifier block */
66 struct notifier_block fb_notif;
67 /* The class device structure */
68 struct class_device class_dev;
69};
70
Richard Purdie28ee0862007-02-08 22:25:09 +000071static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern struct backlight_device *backlight_device_register(const char *name,
Yu Luming519ab5f2006-12-19 12:56:15 -080080 struct device *dev,void *devdata,struct backlight_properties *bp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081extern 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