backlight.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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->sem is an internal backlight lock protecting the props
  15. * field 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. /* This structure defines all the properties of a backlight
  29. (usually attached to a LCD). */
  30. struct backlight_properties {
  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. /* Current User requested brightness (0 - max_brightness) */
  40. int brightness;
  41. /* Maximal value for brightness (read-only) */
  42. int max_brightness;
  43. /* Current FB Power mode (0: full on, 1..3: power saving
  44. modes; 4: full off), see FB_BLANK_XXX */
  45. int power;
  46. /* FB Blanking active? (values as for power) */
  47. int fb_blank;
  48. };
  49. struct backlight_device {
  50. /* This protects the 'props' field. If 'props' is NULL, the driver that
  51. registered this device has been unloaded, and if class_get_devdata()
  52. points to something in the body of that driver, it is also invalid. */
  53. struct semaphore sem;
  54. /* If this is NULL, the backing module is unloaded */
  55. struct backlight_properties *props;
  56. /* Serialise access to update_status method */
  57. struct mutex update_lock;
  58. /* The framebuffer notifier block */
  59. struct notifier_block fb_notif;
  60. /* The class device structure */
  61. struct class_device class_dev;
  62. };
  63. static inline void backlight_update_status(struct backlight_device *bd)
  64. {
  65. mutex_lock(&bd->update_lock);
  66. if (bd->props && bd->props->update_status)
  67. bd->props->update_status(bd);
  68. mutex_unlock(&bd->update_lock);
  69. }
  70. extern struct backlight_device *backlight_device_register(const char *name,
  71. struct device *dev,void *devdata,struct backlight_properties *bp);
  72. extern void backlight_device_unregister(struct backlight_device *bd);
  73. #define to_backlight_device(obj) container_of(obj, struct backlight_device, class_dev)
  74. #endif