1 /* Public domain. */
2
3 #ifndef _LINUX_BACKLIGHT_H
4 #define _LINUX_BACKLIGHT_H
5
6 #include <sys/task.h>
7 #include <linux/fb.h>
8
9 struct backlight_device;
10 struct device;
11
12 struct backlight_properties {
13 int type;
14 #define BACKLIGHT_RAW 0
15 #define BACKLIGHT_FIRMWARE 1
16 #define BACKLIGHT_PLATFORM 2
17 int max_brightness;
18 int brightness;
19 int power;
20 #define BACKLIGHT_POWER_ON 0
21 #define BACKLIGHT_POWER_OFF 1
22 int scale;
23 #define BACKLIGHT_SCALE_LINEAR 0
24 int state;
25 #define BL_CORE_SUSPENDED 0x00000001
26 };
27
28 struct backlight_ops {
29 int options;
30 #define BL_CORE_SUSPENDRESUME 0x00000001
31 int (*update_status)(struct backlight_device *);
32 int (*get_brightness)(struct backlight_device *);
33 };
34
35 struct backlight_device {
36 const struct backlight_ops *ops;
37 struct backlight_properties props;
38 struct task task;
39 void *data;
40 SLIST_ENTRY(backlight_device) next;
41 const char *name;
42 };
43
44 static inline void *
bl_get_data(struct backlight_device * bd)45 bl_get_data(struct backlight_device *bd)
46 {
47 return bd->data;
48 }
49
50 static inline int
backlight_get_brightness(struct backlight_device * bd)51 backlight_get_brightness(struct backlight_device *bd)
52 {
53 return bd->props.brightness;
54 }
55
56 #define BACKLIGHT_UPDATE_HOTKEY 0
57
58 struct backlight_device *backlight_device_register(const char *, void *,
59 void *, const struct backlight_ops *, const struct backlight_properties *);
60 void backlight_device_unregister(struct backlight_device *);
61
62 static inline struct backlight_device *
devm_backlight_device_register(void * dev,const char * name,void * parent,void * data,const struct backlight_ops * bo,const struct backlight_properties * bp)63 devm_backlight_device_register(void *dev, const char *name, void *parent,
64 void *data, const struct backlight_ops *bo,
65 const struct backlight_properties *bp)
66 {
67 return backlight_device_register(name, dev, data, bo, bp);
68 }
69
70 static inline void
backlight_update_status(struct backlight_device * bd)71 backlight_update_status(struct backlight_device *bd)
72 {
73 bd->ops->update_status(bd);
74 }
75
76 static inline void
backlight_force_update(struct backlight_device * bd,int reason)77 backlight_force_update(struct backlight_device *bd, int reason)
78 {
79 bd->props.brightness = bd->ops->get_brightness(bd);
80 }
81
82 static inline void
backlight_device_set_brightness(struct backlight_device * bd,int level)83 backlight_device_set_brightness(struct backlight_device *bd, int level)
84 {
85 if (level > bd->props.max_brightness)
86 return;
87 bd->props.brightness = level;
88 bd->ops->update_status(bd);
89 }
90
91 void backlight_schedule_update_status(struct backlight_device *);
92
93 int backlight_enable(struct backlight_device *);
94 int backlight_disable(struct backlight_device *);
95
96 static inline struct backlight_device *
devm_of_find_backlight(struct device * dev)97 devm_of_find_backlight(struct device *dev)
98 {
99 return NULL;
100 }
101
102 struct backlight_device *backlight_device_get_by_name(const char *);
103
104 #endif
105