backlight.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. /* Notify the backlight driver some property has changed */
  30. int (*update_status)(struct backlight_device *);
  31. /* Return the current backlight brightness (accounting for power,
  32. fb_blank etc.) */
  33. int (*get_brightness)(struct backlight_device *);
  34. /* Check if given framebuffer device is the one bound to this backlight;
  35. return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
  36. int (*check_fb)(struct fb_info *);
  37. };
  38. /* This structure defines all the properties of a backlight */
  39. struct backlight_properties {
  40. /* Current User requested brightness (0 - max_brightness) */
  41. int brightness;
  42. /* Maximal value for brightness (read-only) */
  43. int max_brightness;
  44. /* Current FB Power mode (0: full on, 1..3: power saving
  45. modes; 4: full off), see FB_BLANK_XXX */
  46. int power;
  47. /* FB Blanking active? (values as for power) */
  48. int fb_blank;
  49. };
  50. struct backlight_device {
  51. /* Backlight properties */
  52. struct backlight_properties props;
  53. /* Serialise access to update_status method */
  54. struct mutex update_lock;
  55. /* This protects the 'ops' field. If 'ops' is NULL, the driver that
  56. registered this device has been unloaded, and if class_get_devdata()
  57. points to something in the body of that driver, it is also invalid. */
  58. struct mutex ops_lock;
  59. struct backlight_ops *ops;
  60. /* The framebuffer notifier block */
  61. struct notifier_block fb_notif;
  62. /* The class device structure */
  63. struct class_device class_dev;
  64. };
  65. static inline void backlight_update_status(struct backlight_device *bd)
  66. {
  67. mutex_lock(&bd->update_lock);
  68. if (bd->ops && bd->ops->update_status)
  69. bd->ops->update_status(bd);
  70. mutex_unlock(&bd->update_lock);
  71. }
  72. extern struct backlight_device *backlight_device_register(const char *name,
  73. struct device *dev, void *devdata, struct backlight_ops *ops);
  74. extern void backlight_device_unregister(struct backlight_device *bd);
  75. #define to_backlight_device(obj) container_of(obj, struct backlight_device, class_dev)
  76. #endif