drm_panel.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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/err.h>
  26. #include <linux/errno.h>
  27. #include <linux/list.h>
  28. struct device_node;
  29. struct drm_connector;
  30. struct drm_device;
  31. struct drm_panel;
  32. struct display_timing;
  33. /**
  34. * struct drm_panel_funcs - perform operations on a given panel
  35. * @disable: disable panel (turn off back light, etc.)
  36. * @unprepare: turn off panel
  37. * @prepare: turn on panel and perform set up
  38. * @enable: enable panel (turn on back light, etc.)
  39. * @get_modes: add modes to the connector that the panel is attached to and
  40. * return the number of modes added
  41. * @get_timings: copy display timings into the provided array and return
  42. * the number of display timings available
  43. *
  44. * The .prepare() function is typically called before the display controller
  45. * starts to transmit video data. Panel drivers can use this to turn the panel
  46. * on and wait for it to become ready. If additional configuration is required
  47. * (via a control bus such as I2C, SPI or DSI for example) this is a good time
  48. * to do that.
  49. *
  50. * After the display controller has started transmitting video data, it's safe
  51. * to call the .enable() function. This will typically enable the backlight to
  52. * make the image on screen visible. Some panels require a certain amount of
  53. * time or frames before the image is displayed. This function is responsible
  54. * for taking this into account before enabling the backlight to avoid visual
  55. * glitches.
  56. *
  57. * Before stopping video transmission from the display controller it can be
  58. * necessary to turn off the panel to avoid visual glitches. This is done in
  59. * the .disable() function. Analogously to .enable() this typically involves
  60. * turning off the backlight and waiting for some time to make sure no image
  61. * is visible on the panel. It is then safe for the display controller to
  62. * cease transmission of video data.
  63. *
  64. * To save power when no video data is transmitted, a driver can power down
  65. * the panel. This is the job of the .unprepare() function.
  66. */
  67. struct drm_panel_funcs {
  68. int (*disable)(struct drm_panel *panel);
  69. int (*unprepare)(struct drm_panel *panel);
  70. int (*prepare)(struct drm_panel *panel);
  71. int (*enable)(struct drm_panel *panel);
  72. int (*get_modes)(struct drm_panel *panel);
  73. int (*get_timings)(struct drm_panel *panel, unsigned int num_timings,
  74. struct display_timing *timings);
  75. };
  76. /**
  77. * struct drm_panel - DRM panel object
  78. * @drm: DRM device owning the panel
  79. * @connector: DRM connector that the panel is attached to
  80. * @dev: parent device of the panel
  81. * @funcs: operations that can be performed on the panel
  82. * @list: panel entry in registry
  83. */
  84. struct drm_panel {
  85. struct drm_device *drm;
  86. struct drm_connector *connector;
  87. struct device *dev;
  88. const struct drm_panel_funcs *funcs;
  89. struct list_head list;
  90. };
  91. /**
  92. * drm_disable_unprepare - power off a panel
  93. * @panel: DRM panel
  94. *
  95. * Calling this function will completely power off a panel (assert the panel's
  96. * reset, turn off power supplies, ...). After this function has completed, it
  97. * is usually no longer possible to communicate with the panel until another
  98. * call to drm_panel_prepare().
  99. *
  100. * Return: 0 on success or a negative error code on failure.
  101. */
  102. static inline int drm_panel_unprepare(struct drm_panel *panel)
  103. {
  104. if (panel && panel->funcs && panel->funcs->unprepare)
  105. return panel->funcs->unprepare(panel);
  106. return panel ? -ENOSYS : -EINVAL;
  107. }
  108. /**
  109. * drm_panel_disable - disable a panel
  110. * @panel: DRM panel
  111. *
  112. * This will typically turn off the panel's backlight or disable the display
  113. * drivers. For smart panels it should still be possible to communicate with
  114. * the integrated circuitry via any command bus after this call.
  115. *
  116. * Return: 0 on success or a negative error code on failure.
  117. */
  118. static inline int drm_panel_disable(struct drm_panel *panel)
  119. {
  120. if (panel && panel->funcs && panel->funcs->disable)
  121. return panel->funcs->disable(panel);
  122. return panel ? -ENOSYS : -EINVAL;
  123. }
  124. /**
  125. * drm_panel_prepare - power on a panel
  126. * @panel: DRM panel
  127. *
  128. * Calling this function will enable power and deassert any reset signals to
  129. * the panel. After this has completed it is possible to communicate with any
  130. * integrated circuitry via a command bus.
  131. *
  132. * Return: 0 on success or a negative error code on failure.
  133. */
  134. static inline int drm_panel_prepare(struct drm_panel *panel)
  135. {
  136. if (panel && panel->funcs && panel->funcs->prepare)
  137. return panel->funcs->prepare(panel);
  138. return panel ? -ENOSYS : -EINVAL;
  139. }
  140. /**
  141. * drm_panel_enable - enable a panel
  142. * @panel: DRM panel
  143. *
  144. * Calling this function will cause the panel display drivers to be turned on
  145. * and the backlight to be enabled. Content will be visible on screen after
  146. * this call completes.
  147. *
  148. * Return: 0 on success or a negative error code on failure.
  149. */
  150. static inline int drm_panel_enable(struct drm_panel *panel)
  151. {
  152. if (panel && panel->funcs && panel->funcs->enable)
  153. return panel->funcs->enable(panel);
  154. return panel ? -ENOSYS : -EINVAL;
  155. }
  156. /**
  157. * drm_panel_get_modes - probe the available display modes of a panel
  158. * @panel: DRM panel
  159. *
  160. * The modes probed from the panel are automatically added to the connector
  161. * that the panel is attached to.
  162. *
  163. * Return: The number of modes available from the panel on success or a
  164. * negative error code on failure.
  165. */
  166. static inline int drm_panel_get_modes(struct drm_panel *panel)
  167. {
  168. if (panel && panel->funcs && panel->funcs->get_modes)
  169. return panel->funcs->get_modes(panel);
  170. return panel ? -ENOSYS : -EINVAL;
  171. }
  172. void drm_panel_init(struct drm_panel *panel);
  173. int drm_panel_add(struct drm_panel *panel);
  174. void drm_panel_remove(struct drm_panel *panel);
  175. int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector);
  176. int drm_panel_detach(struct drm_panel *panel);
  177. #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL)
  178. struct drm_panel *of_drm_find_panel(const struct device_node *np);
  179. #else
  180. static inline struct drm_panel *of_drm_find_panel(const struct device_node *np)
  181. {
  182. return ERR_PTR(-ENODEV);
  183. }
  184. #endif
  185. #endif