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> 12 #include <linux/fb.h> 13 #include <linux/mutex.h> 14 #include <linux/notifier.h> 15 16 /* Notes on locking: 17 * 18 * backlight_device->ops_lock is an internal backlight lock protecting the 19 * ops pointer and no code outside the core should need to touch it. 20 * 21 * Access to update_status() is serialised by the update_lock mutex since 22 * most drivers seem to need this and historically get it wrong. 23 * 24 * Most drivers don't need locking on their get_brightness() method. 25 * If yours does, you need to implement it in the driver. You can use the 26 * update_lock mutex if appropriate. 27 * 28 * Any other use of the locks below is probably wrong. 29 */ 30 31 enum backlight_update_reason { 32 BACKLIGHT_UPDATE_HOTKEY, 33 BACKLIGHT_UPDATE_SYSFS, 34 }; 35 36 enum backlight_type { 37 BACKLIGHT_RAW = 1, 38 BACKLIGHT_PLATFORM, 39 BACKLIGHT_FIRMWARE, 40 BACKLIGHT_TYPE_MAX, 41 }; 42 43 struct backlight_device; 44 struct fb_info; 45 46 struct backlight_ops { 47 unsigned int options; 48 49 #define BL_CORE_SUSPENDRESUME (1 << 0) 50 51 /* Notify the backlight driver some property has changed */ 52 int (*update_status)(struct backlight_device *); 53 /* Return the current backlight brightness (accounting for power, 54 fb_blank etc.) */ 55 int (*get_brightness)(struct backlight_device *); 56 /* Check if given framebuffer device is the one bound to this backlight; 57 return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */ 58 int (*check_fb)(struct backlight_device *, struct fb_info *); 59 }; 60 61 /* This structure defines all the properties of a backlight */ 62 struct backlight_properties { 63 /* Current User requested brightness (0 - max_brightness) */ 64 int brightness; 65 /* Maximal value for brightness (read-only) */ 66 int max_brightness; 67 /* Current FB Power mode (0: full on, 1..3: power saving 68 modes; 4: full off), see FB_BLANK_XXX */ 69 int power; 70 /* FB Blanking active? (values as for power) */ 71 /* Due to be removed, please use (state & BL_CORE_FBBLANK) */ 72 int fb_blank; 73 /* Backlight type */ 74 enum backlight_type type; 75 /* Flags used to signal drivers of state changes */ 76 /* Upper 4 bits are reserved for driver internal use */ 77 unsigned int state; 78 79 #define BL_CORE_SUSPENDED (1 << 0) /* backlight is suspended */ 80 #define BL_CORE_FBBLANK (1 << 1) /* backlight is under an fb blank event */ 81 #define BL_CORE_DRIVER4 (1 << 28) /* reserved for driver specific use */ 82 #define BL_CORE_DRIVER3 (1 << 29) /* reserved for driver specific use */ 83 #define BL_CORE_DRIVER2 (1 << 30) /* reserved for driver specific use */ 84 #define BL_CORE_DRIVER1 (1 << 31) /* reserved for driver specific use */ 85 86 }; 87 88 struct backlight_device { 89 /* Backlight properties */ 90 struct backlight_properties props; 91 92 /* Serialise access to update_status method */ 93 struct mutex update_lock; 94 95 /* This protects the 'ops' field. If 'ops' is NULL, the driver that 96 registered this device has been unloaded, and if class_get_devdata() 97 points to something in the body of that driver, it is also invalid. */ 98 struct mutex ops_lock; 99 const struct backlight_ops *ops; 100 101 /* The framebuffer notifier block */ 102 struct notifier_block fb_notif; 103 104 /* list entry of all registered backlight devices */ 105 struct list_head entry; 106 107 struct device dev; 108 109 /* Multiple framebuffers may share one backlight device */ 110 bool fb_bl_on[FB_MAX]; 111 112 int use_count; 113 }; 114 115 static inline void backlight_update_status(struct backlight_device *bd) 116 { 117 mutex_lock(&bd->update_lock); 118 if (bd->ops && bd->ops->update_status) 119 bd->ops->update_status(bd); 120 mutex_unlock(&bd->update_lock); 121 } 122 123 extern struct backlight_device *backlight_device_register(const char *name, 124 struct device *dev, void *devdata, const struct backlight_ops *ops, 125 const struct backlight_properties *props); 126 extern struct backlight_device *devm_backlight_device_register( 127 struct device *dev, const char *name, struct device *parent, 128 void *devdata, const struct backlight_ops *ops, 129 const struct backlight_properties *props); 130 extern void backlight_device_unregister(struct backlight_device *bd); 131 extern void devm_backlight_device_unregister(struct device *dev, 132 struct backlight_device *bd); 133 extern void backlight_force_update(struct backlight_device *bd, 134 enum backlight_update_reason reason); 135 extern bool backlight_device_registered(enum backlight_type type); 136 137 #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev) 138 139 static inline void * bl_get_data(struct backlight_device *bl_dev) 140 { 141 return dev_get_drvdata(&bl_dev->dev); 142 } 143 144 struct generic_bl_info { 145 const char *name; 146 int max_intensity; 147 int default_intensity; 148 int limit_mask; 149 void (*set_bl_intensity)(int intensity); 150 void (*kick_battery)(void); 151 }; 152 153 #ifdef CONFIG_OF 154 struct backlight_device *of_find_backlight_by_node(struct device_node *node); 155 #else 156 static inline struct backlight_device * 157 of_find_backlight_by_node(struct device_node *node) 158 { 159 return NULL; 160 } 161 #endif 162 163 #endif 164