backlight.h 5.1 KB

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