backlight.h 3.7 KB

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