backlight.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Backlight Lowlevel Control Abstraction
  3. *
  4. * Copyright (C) 2003,2004 Hewlett-Packard Company
  5. *
  6. */
  7. #ifndef _LINUX_BACKLIGHT_H
  8. #define _LINUX_BACKLIGHT_H
  9. #include <linux/device.h>
  10. #include <linux/mutex.h>
  11. #include <linux/notifier.h>
  12. /* Notes on locking:
  13. *
  14. * backlight_device->ops_lock is an internal backlight lock protecting the
  15. * ops pointer and no code outside the core should need to touch it.
  16. *
  17. * Access to update_status() is serialised by the update_lock mutex since
  18. * most drivers seem to need this and historically get it wrong.
  19. *
  20. * Most drivers don't need locking on their get_brightness() method.
  21. * If yours does, you need to implement it in the driver. You can use the
  22. * update_lock mutex if appropriate.
  23. *
  24. * Any other use of the locks below is probably wrong.
  25. */
  26. enum backlight_update_reason {
  27. BACKLIGHT_UPDATE_HOTKEY,
  28. BACKLIGHT_UPDATE_SYSFS,
  29. };
  30. struct backlight_device;
  31. struct fb_info;
  32. struct backlight_ops {
  33. const unsigned int options;
  34. #define BL_CORE_SUSPENDRESUME (1 << 0)
  35. /* Notify the backlight driver some property has changed */
  36. int (* const update_status)(struct backlight_device *);
  37. /* Return the current backlight brightness (accounting for power,
  38. fb_blank etc.) */
  39. int (* const get_brightness)(struct backlight_device *);
  40. /* Check if given framebuffer device is the one bound to this backlight;
  41. return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
  42. int (* const check_fb)(struct fb_info *);
  43. };
  44. /* This structure defines all the properties of a backlight */
  45. struct backlight_properties {
  46. /* Current User requested brightness (0 - max_brightness) */
  47. int brightness;
  48. /* Maximal value for brightness (read-only) */
  49. int max_brightness;
  50. /* Current FB Power mode (0: full on, 1..3: power saving
  51. modes; 4: full off), see FB_BLANK_XXX */
  52. int power;
  53. /* FB Blanking active? (values as for power) */
  54. /* Due to be removed, please use (state & BL_CORE_FBBLANK) */
  55. int fb_blank;
  56. /* Flags used to signal drivers of state changes */
  57. /* Upper 4 bits are reserved for driver internal use */
  58. unsigned int state;
  59. #define BL_CORE_SUSPENDED (1 << 0) /* backlight is suspended */
  60. #define BL_CORE_FBBLANK (1 << 1) /* backlight is under an fb blank event */
  61. #define BL_CORE_DRIVER4 (1 << 28) /* reserved for driver specific use */
  62. #define BL_CORE_DRIVER3 (1 << 29) /* reserved for driver specific use */
  63. #define BL_CORE_DRIVER2 (1 << 30) /* reserved for driver specific use */
  64. #define BL_CORE_DRIVER1 (1 << 31) /* reserved for driver specific use */
  65. };
  66. struct backlight_device {
  67. /* Backlight properties */
  68. struct backlight_properties props;
  69. /* Serialise access to update_status method */
  70. struct mutex update_lock;
  71. /* This protects the 'ops' field. If 'ops' is NULL, the driver that
  72. registered this device has been unloaded, and if class_get_devdata()
  73. points to something in the body of that driver, it is also invalid. */
  74. struct mutex ops_lock;
  75. const struct backlight_ops *ops;
  76. /* The framebuffer notifier block */
  77. struct notifier_block fb_notif;
  78. struct device dev;
  79. };
  80. static inline void backlight_update_status(struct backlight_device *bd)
  81. {
  82. mutex_lock(&bd->update_lock);
  83. if (bd->ops && bd->ops->update_status)
  84. bd->ops->update_status(bd);
  85. mutex_unlock(&bd->update_lock);
  86. }
  87. extern struct backlight_device *backlight_device_register(const char *name,
  88. struct device *dev, void *devdata, const struct backlight_ops *ops);
  89. extern void backlight_device_unregister(struct backlight_device *bd);
  90. extern void backlight_force_update(struct backlight_device *bd,
  91. enum backlight_update_reason reason);
  92. #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)
  93. static inline void * bl_get_data(struct backlight_device *bl_dev)
  94. {
  95. return dev_get_drvdata(&bl_dev->dev);
  96. }
  97. struct generic_bl_info {
  98. const char *name;
  99. int max_intensity;
  100. int default_intensity;
  101. int limit_mask;
  102. void (*set_bl_intensity)(int intensity);
  103. void (*kick_battery)(void);
  104. };
  105. #endif