lcd.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * LCD Lowlevel Control Abstraction
  3. *
  4. * Copyright (C) 2003,2004 Hewlett-Packard Company
  5. *
  6. */
  7. #ifndef _LINUX_LCD_H
  8. #define _LINUX_LCD_H
  9. #include <linux/device.h>
  10. #include <linux/mutex.h>
  11. #include <linux/notifier.h>
  12. /* Notes on locking:
  13. *
  14. * lcd_device->ops_lock is an internal backlight lock protecting the ops
  15. * field and no code outside the core should need to touch it.
  16. *
  17. * Access to set_power() 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_power() 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 lcd_device;
  27. struct fb_info;
  28. struct lcd_properties {
  29. /* The maximum value for contrast (read-only) */
  30. int max_contrast;
  31. };
  32. struct lcd_ops {
  33. /* Get the LCD panel power status (0: full on, 1..3: controller
  34. power on, flat panel power off, 4: full off), see FB_BLANK_XXX */
  35. int (*get_power)(struct lcd_device *);
  36. /* Enable or disable power to the LCD (0: on; 4: off, see FB_BLANK_XXX) */
  37. int (*set_power)(struct lcd_device *, int power);
  38. /* Get the current contrast setting (0-max_contrast) */
  39. int (*get_contrast)(struct lcd_device *);
  40. /* Set LCD panel contrast */
  41. int (*set_contrast)(struct lcd_device *, int contrast);
  42. /* Check if given framebuffer device is the one LCD is bound to;
  43. return 0 if not, !=0 if it is. If NULL, lcd always matches the fb. */
  44. int (*check_fb)(struct fb_info *);
  45. };
  46. struct lcd_device {
  47. struct lcd_properties props;
  48. /* This protects the 'ops' field. If 'ops' is NULL, the driver that
  49. registered this device has been unloaded, and if class_get_devdata()
  50. points to something in the body of that driver, it is also invalid. */
  51. struct mutex ops_lock;
  52. /* If this is NULL, the backing module is unloaded */
  53. struct lcd_ops *ops;
  54. /* Serialise access to set_power method */
  55. struct mutex update_lock;
  56. /* The framebuffer notifier block */
  57. struct notifier_block fb_notif;
  58. /* The class device structure */
  59. struct class_device class_dev;
  60. };
  61. static inline void lcd_set_power(struct lcd_device *ld, int power)
  62. {
  63. mutex_lock(&ld->update_lock);
  64. if (ld->ops && ld->ops->set_power)
  65. ld->ops->set_power(ld, power);
  66. mutex_unlock(&ld->update_lock);
  67. }
  68. extern struct lcd_device *lcd_device_register(const char *name,
  69. void *devdata, struct lcd_ops *ops);
  70. extern void lcd_device_unregister(struct lcd_device *ld);
  71. #define to_lcd_device(obj) container_of(obj, struct lcd_device, class_dev)
  72. #endif