![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 /* 0003 * Backlight Lowlevel Control Abstraction 0004 * 0005 * Copyright (C) 2003,2004 Hewlett-Packard Company 0006 * 0007 */ 0008 0009 #ifndef _LINUX_BACKLIGHT_H 0010 #define _LINUX_BACKLIGHT_H 0011 0012 #include <linux/device.h> 0013 #include <linux/fb.h> 0014 #include <linux/mutex.h> 0015 #include <linux/notifier.h> 0016 0017 /** 0018 * enum backlight_update_reason - what method was used to update backlight 0019 * 0020 * A driver indicates the method (reason) used for updating the backlight 0021 * when calling backlight_force_update(). 0022 */ 0023 enum backlight_update_reason { 0024 /** 0025 * @BACKLIGHT_UPDATE_HOTKEY: The backlight was updated using a hot-key. 0026 */ 0027 BACKLIGHT_UPDATE_HOTKEY, 0028 0029 /** 0030 * @BACKLIGHT_UPDATE_SYSFS: The backlight was updated using sysfs. 0031 */ 0032 BACKLIGHT_UPDATE_SYSFS, 0033 }; 0034 0035 /** 0036 * enum backlight_type - the type of backlight control 0037 * 0038 * The type of interface used to control the backlight. 0039 */ 0040 enum backlight_type { 0041 /** 0042 * @BACKLIGHT_RAW: 0043 * 0044 * The backlight is controlled using hardware registers. 0045 */ 0046 BACKLIGHT_RAW = 1, 0047 0048 /** 0049 * @BACKLIGHT_PLATFORM: 0050 * 0051 * The backlight is controlled using a platform-specific interface. 0052 */ 0053 BACKLIGHT_PLATFORM, 0054 0055 /** 0056 * @BACKLIGHT_FIRMWARE: 0057 * 0058 * The backlight is controlled using a standard firmware interface. 0059 */ 0060 BACKLIGHT_FIRMWARE, 0061 0062 /** 0063 * @BACKLIGHT_TYPE_MAX: Number of entries. 0064 */ 0065 BACKLIGHT_TYPE_MAX, 0066 }; 0067 0068 /** 0069 * enum backlight_notification - the type of notification 0070 * 0071 * The notifications that is used for notification sent to the receiver 0072 * that registered notifications using backlight_register_notifier(). 0073 */ 0074 enum backlight_notification { 0075 /** 0076 * @BACKLIGHT_REGISTERED: The backlight device is registered. 0077 */ 0078 BACKLIGHT_REGISTERED, 0079 0080 /** 0081 * @BACKLIGHT_UNREGISTERED: The backlight revice is unregistered. 0082 */ 0083 BACKLIGHT_UNREGISTERED, 0084 }; 0085 0086 /** enum backlight_scale - the type of scale used for brightness values 0087 * 0088 * The type of scale used for brightness values. 0089 */ 0090 enum backlight_scale { 0091 /** 0092 * @BACKLIGHT_SCALE_UNKNOWN: The scale is unknown. 0093 */ 0094 BACKLIGHT_SCALE_UNKNOWN = 0, 0095 0096 /** 0097 * @BACKLIGHT_SCALE_LINEAR: The scale is linear. 0098 * 0099 * The linear scale will increase brightness the same for each step. 0100 */ 0101 BACKLIGHT_SCALE_LINEAR, 0102 0103 /** 0104 * @BACKLIGHT_SCALE_NON_LINEAR: The scale is not linear. 0105 * 0106 * This is often used when the brightness values tries to adjust to 0107 * the relative perception of the eye demanding a non-linear scale. 0108 */ 0109 BACKLIGHT_SCALE_NON_LINEAR, 0110 }; 0111 0112 struct backlight_device; 0113 struct fb_info; 0114 0115 /** 0116 * struct backlight_ops - backlight operations 0117 * 0118 * The backlight operations are specified when the backlight device is registered. 0119 */ 0120 struct backlight_ops { 0121 /** 0122 * @options: Configure how operations are called from the core. 0123 * 0124 * The options parameter is used to adjust the behaviour of the core. 0125 * Set BL_CORE_SUSPENDRESUME to get the update_status() operation called 0126 * upon suspend and resume. 0127 */ 0128 unsigned int options; 0129 0130 #define BL_CORE_SUSPENDRESUME (1 << 0) 0131 0132 /** 0133 * @update_status: Operation called when properties have changed. 0134 * 0135 * Notify the backlight driver some property has changed. 0136 * The update_status operation is protected by the update_lock. 0137 * 0138 * The backlight driver is expected to use backlight_is_blank() 0139 * to check if the display is blanked and set brightness accordingly. 0140 * update_status() is called when any of the properties has changed. 0141 * 0142 * RETURNS: 0143 * 0144 * 0 on success, negative error code if any failure occurred. 0145 */ 0146 int (*update_status)(struct backlight_device *); 0147 0148 /** 0149 * @get_brightness: Return the current backlight brightness. 0150 * 0151 * The driver may implement this as a readback from the HW. 0152 * This operation is optional and if not present then the current 0153 * brightness property value is used. 0154 * 0155 * RETURNS: 0156 * 0157 * A brightness value which is 0 or a positive number. 0158 * On failure a negative error code is returned. 0159 */ 0160 int (*get_brightness)(struct backlight_device *); 0161 0162 /** 0163 * @check_fb: Check the framebuffer device. 0164 * 0165 * Check if given framebuffer device is the one bound to this backlight. 0166 * This operation is optional and if not implemented it is assumed that the 0167 * fbdev is always the one bound to the backlight. 0168 * 0169 * RETURNS: 0170 * 0171 * If info is NULL or the info matches the fbdev bound to the backlight return true. 0172 * If info does not match the fbdev bound to the backlight return false. 0173 */ 0174 int (*check_fb)(struct backlight_device *bd, struct fb_info *info); 0175 }; 0176 0177 /** 0178 * struct backlight_properties - backlight properties 0179 * 0180 * This structure defines all the properties of a backlight. 0181 */ 0182 struct backlight_properties { 0183 /** 0184 * @brightness: The current brightness requested by the user. 0185 * 0186 * The backlight core makes sure the range is (0 to max_brightness) 0187 * when the brightness is set via the sysfs attribute: 0188 * /sys/class/backlight/<backlight>/brightness. 0189 * 0190 * This value can be set in the backlight_properties passed 0191 * to devm_backlight_device_register() to set a default brightness 0192 * value. 0193 */ 0194 int brightness; 0195 0196 /** 0197 * @max_brightness: The maximum brightness value. 0198 * 0199 * This value must be set in the backlight_properties passed to 0200 * devm_backlight_device_register() and shall not be modified by the 0201 * driver after registration. 0202 */ 0203 int max_brightness; 0204 0205 /** 0206 * @power: The current power mode. 0207 * 0208 * User space can configure the power mode using the sysfs 0209 * attribute: /sys/class/backlight/<backlight>/bl_power 0210 * When the power property is updated update_status() is called. 0211 * 0212 * The possible values are: (0: full on, 1 to 3: power saving 0213 * modes; 4: full off), see FB_BLANK_XXX. 0214 * 0215 * When the backlight device is enabled @power is set 0216 * to FB_BLANK_UNBLANK. When the backlight device is disabled 0217 * @power is set to FB_BLANK_POWERDOWN. 0218 */ 0219 int power; 0220 0221 /** 0222 * @fb_blank: The power state from the FBIOBLANK ioctl. 0223 * 0224 * When the FBIOBLANK ioctl is called @fb_blank is set to the 0225 * blank parameter and the update_status() operation is called. 0226 * 0227 * When the backlight device is enabled @fb_blank is set 0228 * to FB_BLANK_UNBLANK. When the backlight device is disabled 0229 * @fb_blank is set to FB_BLANK_POWERDOWN. 0230 * 0231 * Backlight drivers should avoid using this property. It has been 0232 * replaced by state & BL_CORE_FBLANK (although most drivers should 0233 * use backlight_is_blank() as the preferred means to get the blank 0234 * state). 0235 * 0236 * fb_blank is deprecated and will be removed. 0237 */ 0238 int fb_blank; 0239 0240 /** 0241 * @type: The type of backlight supported. 0242 * 0243 * The backlight type allows userspace to make appropriate 0244 * policy decisions based on the backlight type. 0245 * 0246 * This value must be set in the backlight_properties 0247 * passed to devm_backlight_device_register(). 0248 */ 0249 enum backlight_type type; 0250 0251 /** 0252 * @state: The state of the backlight core. 0253 * 0254 * The state is a bitmask. BL_CORE_FBBLANK is set when the display 0255 * is expected to be blank. BL_CORE_SUSPENDED is set when the 0256 * driver is suspended. 0257 * 0258 * backlight drivers are expected to use backlight_is_blank() 0259 * in their update_status() operation rather than reading the 0260 * state property. 0261 * 0262 * The state is maintained by the core and drivers may not modify it. 0263 */ 0264 unsigned int state; 0265 0266 #define BL_CORE_SUSPENDED (1 << 0) /* backlight is suspended */ 0267 #define BL_CORE_FBBLANK (1 << 1) /* backlight is under an fb blank event */ 0268 0269 /** 0270 * @scale: The type of the brightness scale. 0271 */ 0272 enum backlight_scale scale; 0273 }; 0274 0275 /** 0276 * struct backlight_device - backlight device data 0277 * 0278 * This structure holds all data required by a backlight device. 0279 */ 0280 struct backlight_device { 0281 /** 0282 * @props: Backlight properties 0283 */ 0284 struct backlight_properties props; 0285 0286 /** 0287 * @update_lock: The lock used when calling the update_status() operation. 0288 * 0289 * update_lock is an internal backlight lock that serialise access 0290 * to the update_status() operation. The backlight core holds the update_lock 0291 * when calling the update_status() operation. The update_lock shall not 0292 * be used by backlight drivers. 0293 */ 0294 struct mutex update_lock; 0295 0296 /** 0297 * @ops_lock: The lock used around everything related to backlight_ops. 0298 * 0299 * ops_lock is an internal backlight lock that protects the ops pointer 0300 * and is used around all accesses to ops and when the operations are 0301 * invoked. The ops_lock shall not be used by backlight drivers. 0302 */ 0303 struct mutex ops_lock; 0304 0305 /** 0306 * @ops: Pointer to the backlight operations. 0307 * 0308 * If ops is NULL, the driver that registered this device has been unloaded, 0309 * and if class_get_devdata() points to something in the body of that driver, 0310 * it is also invalid. 0311 */ 0312 const struct backlight_ops *ops; 0313 0314 /** 0315 * @fb_notif: The framebuffer notifier block 0316 */ 0317 struct notifier_block fb_notif; 0318 0319 /** 0320 * @entry: List entry of all registered backlight devices 0321 */ 0322 struct list_head entry; 0323 0324 /** 0325 * @dev: Parent device. 0326 */ 0327 struct device dev; 0328 0329 /** 0330 * @fb_bl_on: The state of individual fbdev's. 0331 * 0332 * Multiple fbdev's may share one backlight device. The fb_bl_on 0333 * records the state of the individual fbdev. 0334 */ 0335 bool fb_bl_on[FB_MAX]; 0336 0337 /** 0338 * @use_count: The number of uses of fb_bl_on. 0339 */ 0340 int use_count; 0341 }; 0342 0343 /** 0344 * backlight_update_status - force an update of the backlight device status 0345 * @bd: the backlight device 0346 */ 0347 static inline int backlight_update_status(struct backlight_device *bd) 0348 { 0349 int ret = -ENOENT; 0350 0351 mutex_lock(&bd->update_lock); 0352 if (bd->ops && bd->ops->update_status) 0353 ret = bd->ops->update_status(bd); 0354 mutex_unlock(&bd->update_lock); 0355 0356 return ret; 0357 } 0358 0359 /** 0360 * backlight_enable - Enable backlight 0361 * @bd: the backlight device to enable 0362 */ 0363 static inline int backlight_enable(struct backlight_device *bd) 0364 { 0365 if (!bd) 0366 return 0; 0367 0368 bd->props.power = FB_BLANK_UNBLANK; 0369 bd->props.fb_blank = FB_BLANK_UNBLANK; 0370 bd->props.state &= ~BL_CORE_FBBLANK; 0371 0372 return backlight_update_status(bd); 0373 } 0374 0375 /** 0376 * backlight_disable - Disable backlight 0377 * @bd: the backlight device to disable 0378 */ 0379 static inline int backlight_disable(struct backlight_device *bd) 0380 { 0381 if (!bd) 0382 return 0; 0383 0384 bd->props.power = FB_BLANK_POWERDOWN; 0385 bd->props.fb_blank = FB_BLANK_POWERDOWN; 0386 bd->props.state |= BL_CORE_FBBLANK; 0387 0388 return backlight_update_status(bd); 0389 } 0390 0391 /** 0392 * backlight_is_blank - Return true if display is expected to be blank 0393 * @bd: the backlight device 0394 * 0395 * Display is expected to be blank if any of these is true:: 0396 * 0397 * 1) if power in not UNBLANK 0398 * 2) if fb_blank is not UNBLANK 0399 * 3) if state indicate BLANK or SUSPENDED 0400 * 0401 * Returns true if display is expected to be blank, false otherwise. 0402 */ 0403 static inline bool backlight_is_blank(const struct backlight_device *bd) 0404 { 0405 return bd->props.power != FB_BLANK_UNBLANK || 0406 bd->props.fb_blank != FB_BLANK_UNBLANK || 0407 bd->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK); 0408 } 0409 0410 /** 0411 * backlight_get_brightness - Returns the current brightness value 0412 * @bd: the backlight device 0413 * 0414 * Returns the current brightness value, taking in consideration the current 0415 * state. If backlight_is_blank() returns true then return 0 as brightness 0416 * otherwise return the current brightness property value. 0417 * 0418 * Backlight drivers are expected to use this function in their update_status() 0419 * operation to get the brightness value. 0420 */ 0421 static inline int backlight_get_brightness(const struct backlight_device *bd) 0422 { 0423 if (backlight_is_blank(bd)) 0424 return 0; 0425 else 0426 return bd->props.brightness; 0427 } 0428 0429 struct backlight_device * 0430 backlight_device_register(const char *name, struct device *dev, void *devdata, 0431 const struct backlight_ops *ops, 0432 const struct backlight_properties *props); 0433 struct backlight_device * 0434 devm_backlight_device_register(struct device *dev, const char *name, 0435 struct device *parent, void *devdata, 0436 const struct backlight_ops *ops, 0437 const struct backlight_properties *props); 0438 void backlight_device_unregister(struct backlight_device *bd); 0439 void devm_backlight_device_unregister(struct device *dev, 0440 struct backlight_device *bd); 0441 void backlight_force_update(struct backlight_device *bd, 0442 enum backlight_update_reason reason); 0443 int backlight_register_notifier(struct notifier_block *nb); 0444 int backlight_unregister_notifier(struct notifier_block *nb); 0445 struct backlight_device *backlight_device_get_by_name(const char *name); 0446 struct backlight_device *backlight_device_get_by_type(enum backlight_type type); 0447 int backlight_device_set_brightness(struct backlight_device *bd, 0448 unsigned long brightness); 0449 0450 #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev) 0451 0452 /** 0453 * bl_get_data - access devdata 0454 * @bl_dev: pointer to backlight device 0455 * 0456 * When a backlight device is registered the driver has the possibility 0457 * to supply a void * devdata. bl_get_data() return a pointer to the 0458 * devdata. 0459 * 0460 * RETURNS: 0461 * 0462 * pointer to devdata stored while registering the backlight device. 0463 */ 0464 static inline void * bl_get_data(struct backlight_device *bl_dev) 0465 { 0466 return dev_get_drvdata(&bl_dev->dev); 0467 } 0468 0469 #ifdef CONFIG_OF 0470 struct backlight_device *of_find_backlight_by_node(struct device_node *node); 0471 #else 0472 static inline struct backlight_device * 0473 of_find_backlight_by_node(struct device_node *node) 0474 { 0475 return NULL; 0476 } 0477 #endif 0478 0479 #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) 0480 struct backlight_device *devm_of_find_backlight(struct device *dev); 0481 #else 0482 static inline struct backlight_device * 0483 devm_of_find_backlight(struct device *dev) 0484 { 0485 return NULL; 0486 } 0487 #endif 0488 0489 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |