drm_panel.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright (C) 2013, NVIDIA Corporation. All rights reserved.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sub license,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the
  12. * next paragraph) shall be included in all copies or substantial portions
  13. * of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. */
  23. #ifndef __DRM_PANEL_H__
  24. #define __DRM_PANEL_H__
  25. #include <linux/errno.h>
  26. #include <linux/list.h>
  27. struct device_node;
  28. struct drm_connector;
  29. struct drm_device;
  30. struct drm_panel;
  31. struct display_timing;
  32. /**
  33. * struct drm_panel_funcs - perform operations on a given panel
  34. * @disable: disable panel (turn off back light, etc.)
  35. * @unprepare: turn off panel
  36. * @prepare: turn on panel and perform set up
  37. * @enable: enable panel (turn on back light, etc.)
  38. * @get_modes: add modes to the connector that the panel is attached to and
  39. * return the number of modes added
  40. * @get_timings: copy display timings into the provided array and return
  41. * the number of display timings available
  42. *
  43. * The .prepare() function is typically called before the display controller
  44. * starts to transmit video data. Panel drivers can use this to turn the panel
  45. * on and wait for it to become ready. If additional configuration is required
  46. * (via a control bus such as I2C, SPI or DSI for example) this is a good time
  47. * to do that.
  48. *
  49. * After the display controller has started transmitting video data, it's safe
  50. * to call the .enable() function. This will typically enable the backlight to
  51. * make the image on screen visible. Some panels require a certain amount of
  52. * time or frames before the image is displayed. This function is responsible
  53. * for taking this into account before enabling the backlight to avoid visual
  54. * glitches.
  55. *
  56. * Before stopping video transmission from the display controller it can be
  57. * necessary to turn off the panel to avoid visual glitches. This is done in
  58. * the .disable() function. Analogously to .enable() this typically involves
  59. * turning off the backlight and waiting for some time to make sure no image
  60. * is visible on the panel. It is then safe for the display controller to
  61. * cease transmission of video data.
  62. *
  63. * To save power when no video data is transmitted, a driver can power down
  64. * the panel. This is the job of the .unprepare() function.
  65. */
  66. struct drm_panel_funcs {
  67. int (*disable)(struct drm_panel *panel);
  68. int (*unprepare)(struct drm_panel *panel);
  69. int (*prepare)(struct drm_panel *panel);
  70. int (*enable)(struct drm_panel *panel);
  71. int (*get_modes)(struct drm_panel *panel);
  72. int (*get_timings)(struct drm_panel *panel, unsigned int num_timings,
  73. struct display_timing *timings);
  74. };
  75. /**
  76. * struct drm_panel - DRM panel object
  77. * @drm: DRM device owning the panel
  78. * @connector: DRM connector that the panel is attached to
  79. * @dev: parent device of the panel
  80. * @funcs: operations that can be performed on the panel
  81. * @list: panel entry in registry
  82. */
  83. struct drm_panel {
  84. struct drm_device *drm;
  85. struct drm_connector *connector;
  86. struct device *dev;
  87. const struct drm_panel_funcs *funcs;
  88. struct list_head list;
  89. };
  90. /**
  91. * drm_disable_unprepare - power off a panel
  92. * @panel: DRM panel
  93. *
  94. * Calling this function will completely power off a panel (assert the panel's
  95. * reset, turn off power supplies, ...). After this function has completed, it
  96. * is usually no longer possible to communicate with the panel until another
  97. * call to drm_panel_prepare().
  98. *
  99. * Return: 0 on success or a negative error code on failure.
  100. */
  101. static inline int drm_panel_unprepare(struct drm_panel *panel)
  102. {
  103. if (panel && panel->funcs && panel->funcs->unprepare)
  104. return panel->funcs->unprepare(panel);
  105. return panel ? -ENOSYS : -EINVAL;
  106. }
  107. /**
  108. * drm_panel_disable - disable a panel
  109. * @panel: DRM panel
  110. *
  111. * This will typically turn off the panel's backlight or disable the display
  112. * drivers. For smart panels it should still be possible to communicate with
  113. * the integrated circuitry via any command bus after this call.
  114. *
  115. * Return: 0 on success or a negative error code on failure.
  116. */
  117. static inline int drm_panel_disable(struct drm_panel *panel)
  118. {
  119. if (panel && panel->funcs && panel->funcs->disable)
  120. return panel->funcs->disable(panel);
  121. return panel ? -ENOSYS : -EINVAL;
  122. }
  123. /**
  124. * drm_panel_prepare - power on a panel
  125. * @panel: DRM panel
  126. *
  127. * Calling this function will enable power and deassert any reset signals to
  128. * the panel. After this has completed it is possible to communicate with any
  129. * integrated circuitry via a command bus.
  130. *
  131. * Return: 0 on success or a negative error code on failure.
  132. */
  133. static inline int drm_panel_prepare(struct drm_panel *panel)
  134. {
  135. if (panel && panel->funcs && panel->funcs->prepare)
  136. return panel->funcs->prepare(panel);
  137. return panel ? -ENOSYS : -EINVAL;
  138. }
  139. /**
  140. * drm_panel_enable - enable a panel
  141. * @panel: DRM panel
  142. *
  143. * Calling this function will cause the panel display drivers to be turned on
  144. * and the backlight to be enabled. Content will be visible on screen after
  145. * this call completes.
  146. *
  147. * Return: 0 on success or a negative error code on failure.
  148. */
  149. static inline int drm_panel_enable(struct drm_panel *panel)
  150. {
  151. if (panel && panel->funcs && panel->funcs->enable)
  152. return panel->funcs->enable(panel);
  153. return panel ? -ENOSYS : -EINVAL;
  154. }
  155. /**
  156. * drm_panel_get_modes - probe the available display modes of a panel
  157. * @panel: DRM panel
  158. *
  159. * The modes probed from the panel are automatically added to the connector
  160. * that the panel is attached to.
  161. *
  162. * Return: The number of modes available from the panel on success or a
  163. * negative error code on failure.
  164. */
  165. static inline int drm_panel_get_modes(struct drm_panel *panel)
  166. {
  167. if (panel && panel->funcs && panel->funcs->get_modes)
  168. return panel->funcs->get_modes(panel);
  169. return panel ? -ENOSYS : -EINVAL;
  170. }
  171. void drm_panel_init(struct drm_panel *panel);
  172. int drm_panel_add(struct drm_panel *panel);
  173. void drm_panel_remove(struct drm_panel *panel);
  174. int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector);
  175. int drm_panel_detach(struct drm_panel *panel);
  176. #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL)
  177. struct drm_panel *of_drm_find_panel(const struct device_node *np);
  178. #else
  179. static inline struct drm_panel *of_drm_find_panel(const struct device_node *np)
  180. {
  181. return NULL;
  182. }
  183. #endif
  184. #endif