lcd.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. #include <linux/fb.h>
  13. /* Notes on locking:
  14. *
  15. * lcd_device->ops_lock is an internal backlight lock protecting the ops
  16. * field and no code outside the core should need to touch it.
  17. *
  18. * Access to set_power() is serialised by the update_lock mutex since
  19. * most drivers seem to need this and historically get it wrong.
  20. *
  21. * Most drivers don't need locking on their get_power() method.
  22. * If yours does, you need to implement it in the driver. You can use the
  23. * update_lock mutex if appropriate.
  24. *
  25. * Any other use of the locks below is probably wrong.
  26. */
  27. struct lcd_device;
  28. struct fb_info;
  29. struct lcd_properties {
  30. /* The maximum value for contrast (read-only) */
  31. int max_contrast;
  32. };
  33. struct lcd_ops {
  34. /* Get the LCD panel power status (0: full on, 1..3: controller
  35. power on, flat panel power off, 4: full off), see FB_BLANK_XXX */
  36. int (*get_power)(struct lcd_device *);
  37. /*
  38. * Enable or disable power to the LCD(0: on; 4: off, see FB_BLANK_XXX)
  39. * and this callback would be called proir to fb driver's callback.
  40. *
  41. * P.S. note that if early_set_power is not NULL then early fb notifier
  42. * would be registered.
  43. */
  44. int (*early_set_power)(struct lcd_device *, int power);
  45. /* revert the effects of the early blank event. */
  46. int (*r_early_set_power)(struct lcd_device *, int power);
  47. /* Enable or disable power to the LCD (0: on; 4: off, see FB_BLANK_XXX) */
  48. int (*set_power)(struct lcd_device *, int power);
  49. /* Get the current contrast setting (0-max_contrast) */
  50. int (*get_contrast)(struct lcd_device *);
  51. /* Set LCD panel contrast */
  52. int (*set_contrast)(struct lcd_device *, int contrast);
  53. /* Set LCD panel mode (resolutions ...) */
  54. int (*set_mode)(struct lcd_device *, struct fb_videomode *);
  55. /* Check if given framebuffer device is the one LCD is bound to;
  56. return 0 if not, !=0 if it is. If NULL, lcd always matches the fb. */
  57. int (*check_fb)(struct lcd_device *, struct fb_info *);
  58. };
  59. struct lcd_device {
  60. struct lcd_properties props;
  61. /* This protects the 'ops' field. If 'ops' is NULL, the driver that
  62. registered this device has been unloaded, and if class_get_devdata()
  63. points to something in the body of that driver, it is also invalid. */
  64. struct mutex ops_lock;
  65. /* If this is NULL, the backing module is unloaded */
  66. struct lcd_ops *ops;
  67. /* Serialise access to set_power method */
  68. struct mutex update_lock;
  69. /* The framebuffer notifier block */
  70. struct notifier_block fb_notif;
  71. struct device dev;
  72. };
  73. struct lcd_platform_data {
  74. /* reset lcd panel device. */
  75. int (*reset)(struct lcd_device *ld);
  76. /* on or off to lcd panel. if 'enable' is 0 then
  77. lcd power off and 1, lcd power on. */
  78. int (*power_on)(struct lcd_device *ld, int enable);
  79. /* it indicates whether lcd panel was enabled
  80. from bootloader or not. */
  81. int lcd_enabled;
  82. /* it means delay for stable time when it becomes low to high
  83. or high to low that is dependent on whether reset gpio is
  84. low active or high active. */
  85. unsigned int reset_delay;
  86. /* stable time needing to become lcd power on. */
  87. unsigned int power_on_delay;
  88. /* stable time needing to become lcd power off. */
  89. unsigned int power_off_delay;
  90. /* it could be used for any purpose. */
  91. void *pdata;
  92. };
  93. static inline void lcd_set_power(struct lcd_device *ld, int power)
  94. {
  95. mutex_lock(&ld->update_lock);
  96. if (ld->ops && ld->ops->set_power)
  97. ld->ops->set_power(ld, power);
  98. mutex_unlock(&ld->update_lock);
  99. }
  100. extern struct lcd_device *lcd_device_register(const char *name,
  101. struct device *parent, void *devdata, struct lcd_ops *ops);
  102. extern struct lcd_device *devm_lcd_device_register(struct device *dev,
  103. const char *name, struct device *parent,
  104. void *devdata, struct lcd_ops *ops);
  105. extern void lcd_device_unregister(struct lcd_device *ld);
  106. extern void devm_lcd_device_unregister(struct device *dev,
  107. struct lcd_device *ld);
  108. #define to_lcd_device(obj) container_of(obj, struct lcd_device, dev)
  109. static inline void * lcd_get_data(struct lcd_device *ld_dev)
  110. {
  111. return dev_get_drvdata(&ld_dev->dev);
  112. }
  113. #endif