lcd.h 3.8 KB

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