backlight.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. enum backlight_type {
  31. BACKLIGHT_RAW = 1,
  32. BACKLIGHT_PLATFORM,
  33. BACKLIGHT_FIRMWARE,
  34. BACKLIGHT_TYPE_MAX,
  35. };
  36. struct backlight_device;
  37. struct fb_info;
  38. struct backlight_ops {
  39. unsigned int options;
  40. #define BL_CORE_SUSPENDRESUME (1 << 0)
  41. /* Notify the backlight driver some property has changed */
  42. int (*update_status)(struct backlight_device *);
  43. /* Return the current backlight brightness (accounting for power,
  44. fb_blank etc.) */
  45. int (*get_brightness)(struct backlight_device *);
  46. /* Check if given framebuffer device is the one bound to this backlight;
  47. return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
  48. int (*check_fb)(struct backlight_device *, struct fb_info *);
  49. };
  50. /* This structure defines all the properties of a backlight */
  51. struct backlight_properties {
  52. /* Current User requested brightness (0 - max_brightness) */
  53. int brightness;
  54. /* Maximal value for brightness (read-only) */
  55. int max_brightness;
  56. /* Current FB Power mode (0: full on, 1..3: power saving
  57. modes; 4: full off), see FB_BLANK_XXX */
  58. int power;
  59. /* FB Blanking active? (values as for power) */
  60. /* Due to be removed, please use (state & BL_CORE_FBBLANK) */
  61. int fb_blank;
  62. /* Backlight type */
  63. enum backlight_type type;
  64. /* Flags used to signal drivers of state changes */
  65. /* Upper 4 bits are reserved for driver internal use */
  66. unsigned int state;
  67. #define BL_CORE_SUSPENDED (1 << 0) /* backlight is suspended */
  68. #define BL_CORE_FBBLANK (1 << 1) /* backlight is under an fb blank event */
  69. #define BL_CORE_DRIVER4 (1 << 28) /* reserved for driver specific use */
  70. #define BL_CORE_DRIVER3 (1 << 29) /* reserved for driver specific use */
  71. #define BL_CORE_DRIVER2 (1 << 30) /* reserved for driver specific use */
  72. #define BL_CORE_DRIVER1 (1 << 31) /* reserved for driver specific use */
  73. };
  74. struct backlight_device {
  75. /* Backlight properties */
  76. struct backlight_properties props;
  77. /* Serialise access to update_status method */
  78. struct mutex update_lock;
  79. /* This protects the 'ops' field. If 'ops' is NULL, the driver that
  80. registered this device has been unloaded, and if class_get_devdata()
  81. points to something in the body of that driver, it is also invalid. */
  82. struct mutex ops_lock;
  83. const struct backlight_ops *ops;
  84. /* The framebuffer notifier block */
  85. struct notifier_block fb_notif;
  86. struct device dev;
  87. };
  88. static inline void backlight_update_status(struct backlight_device *bd)
  89. {
  90. mutex_lock(&bd->update_lock);
  91. if (bd->ops && bd->ops->update_status)
  92. bd->ops->update_status(bd);
  93. mutex_unlock(&bd->update_lock);
  94. }
  95. extern struct backlight_device *backlight_device_register(const char *name,
  96. struct device *dev, void *devdata, const struct backlight_ops *ops,
  97. const struct backlight_properties *props);
  98. extern void backlight_device_unregister(struct backlight_device *bd);
  99. extern void backlight_force_update(struct backlight_device *bd,
  100. enum backlight_update_reason reason);
  101. #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)
  102. static inline void * bl_get_data(struct backlight_device *bl_dev)
  103. {
  104. return dev_get_drvdata(&bl_dev->dev);
  105. }
  106. struct generic_bl_info {
  107. const char *name;
  108. int max_intensity;
  109. int default_intensity;
  110. int limit_mask;
  111. void (*set_bl_intensity)(int intensity);
  112. void (*kick_battery)(void);
  113. };
  114. #endif