backlight.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. struct device dev;
  63. };
  64. static inline void backlight_update_status(struct backlight_device *bd)
  65. {
  66. mutex_lock(&bd->update_lock);
  67. if (bd->ops && bd->ops->update_status)
  68. bd->ops->update_status(bd);
  69. mutex_unlock(&bd->update_lock);
  70. }
  71. extern struct backlight_device *backlight_device_register(const char *name,
  72. struct device *dev, void *devdata, struct backlight_ops *ops);
  73. extern void backlight_device_unregister(struct backlight_device *bd);
  74. #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)
  75. static inline void * bl_get_data(struct backlight_device *bl_dev)
  76. {
  77. return dev_get_drvdata(&bl_dev->dev);
  78. }
  79. #endif