drm_panel.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. #include <linux/mutex.h>
  29. struct backlight_device;
  30. struct dentry;
  31. struct device_node;
  32. struct drm_connector;
  33. struct drm_device;
  34. struct drm_panel_follower;
  35. struct drm_panel;
  36. struct display_timing;
  37. enum drm_panel_orientation;
  38. /**
  39. * struct drm_panel_funcs - perform operations on a given panel
  40. *
  41. * The .prepare() function is typically called before the display controller
  42. * starts to transmit video data. Panel drivers can use this to turn the panel
  43. * on and wait for it to become ready. If additional configuration is required
  44. * (via a control bus such as I2C, SPI or DSI for example) this is a good time
  45. * to do that.
  46. *
  47. * After the display controller has started transmitting video data, it's safe
  48. * to call the .enable() function. This will typically enable the backlight to
  49. * make the image on screen visible. Some panels require a certain amount of
  50. * time or frames before the image is displayed. This function is responsible
  51. * for taking this into account before enabling the backlight to avoid visual
  52. * glitches.
  53. *
  54. * Before stopping video transmission from the display controller it can be
  55. * necessary to turn off the panel to avoid visual glitches. This is done in
  56. * the .disable() function. Analogously to .enable() this typically involves
  57. * turning off the backlight and waiting for some time to make sure no image
  58. * is visible on the panel. It is then safe for the display controller to
  59. * cease transmission of video data.
  60. *
  61. * To save power when no video data is transmitted, a driver can power down
  62. * the panel. This is the job of the .unprepare() function.
  63. *
  64. * Backlight can be handled automatically if configured using
  65. * drm_panel_of_backlight() or drm_panel_dp_aux_backlight(). Then the driver
  66. * does not need to implement the functionality to enable/disable backlight.
  67. */
  68. struct drm_panel_funcs {
  69. /**
  70. * @prepare:
  71. *
  72. * Turn on panel and perform set up.
  73. *
  74. * This function is optional.
  75. */
  76. int (*prepare)(struct drm_panel *panel);
  77. /**
  78. * @enable:
  79. *
  80. * Enable panel (turn on back light, etc.).
  81. *
  82. * This function is optional.
  83. */
  84. int (*enable)(struct drm_panel *panel);
  85. /**
  86. * @disable:
  87. *
  88. * Disable panel (turn off back light, etc.).
  89. *
  90. * This function is optional.
  91. */
  92. int (*disable)(struct drm_panel *panel);
  93. /**
  94. * @unprepare:
  95. *
  96. * Turn off panel.
  97. *
  98. * This function is optional.
  99. */
  100. int (*unprepare)(struct drm_panel *panel);
  101. /**
  102. * @get_modes:
  103. *
  104. * Add modes to the connector that the panel is attached to
  105. * and returns the number of modes added.
  106. *
  107. * This function is mandatory.
  108. */
  109. int (*get_modes)(struct drm_panel *panel,
  110. struct drm_connector *connector);
  111. /**
  112. * @get_orientation:
  113. *
  114. * Return the panel orientation set by device tree or EDID.
  115. *
  116. * This function is optional.
  117. */
  118. enum drm_panel_orientation (*get_orientation)(struct drm_panel *panel);
  119. /**
  120. * @get_timings:
  121. *
  122. * Copy display timings into the provided array and return
  123. * the number of display timings available.
  124. *
  125. * This function is optional.
  126. */
  127. int (*get_timings)(struct drm_panel *panel, unsigned int num_timings,
  128. struct display_timing *timings);
  129. /**
  130. * @debugfs_init:
  131. *
  132. * Allows panels to create panels-specific debugfs files.
  133. */
  134. void (*debugfs_init)(struct drm_panel *panel, struct dentry *root);
  135. };
  136. struct drm_panel_follower_funcs {
  137. /**
  138. * @panel_prepared:
  139. *
  140. * Called after the panel has been powered on.
  141. */
  142. int (*panel_prepared)(struct drm_panel_follower *follower);
  143. /**
  144. * @panel_unpreparing:
  145. *
  146. * Called before the panel is powered off.
  147. */
  148. int (*panel_unpreparing)(struct drm_panel_follower *follower);
  149. };
  150. struct drm_panel_follower {
  151. /**
  152. * @funcs:
  153. *
  154. * Dependent device callbacks; should be initted by the caller.
  155. */
  156. const struct drm_panel_follower_funcs *funcs;
  157. /**
  158. * @list
  159. *
  160. * Used for linking into panel's list; set by drm_panel_add_follower().
  161. */
  162. struct list_head list;
  163. /**
  164. * @panel
  165. *
  166. * The panel we're dependent on; set by drm_panel_add_follower().
  167. */
  168. struct drm_panel *panel;
  169. };
  170. /**
  171. * struct drm_panel - DRM panel object
  172. */
  173. struct drm_panel {
  174. /**
  175. * @dev:
  176. *
  177. * Parent device of the panel.
  178. */
  179. struct device *dev;
  180. /**
  181. * @backlight:
  182. *
  183. * Backlight device, used to turn on backlight after the call
  184. * to enable(), and to turn off backlight before the call to
  185. * disable().
  186. * backlight is set by drm_panel_of_backlight() or
  187. * drm_panel_dp_aux_backlight() and drivers shall not assign it.
  188. */
  189. struct backlight_device *backlight;
  190. /**
  191. * @funcs:
  192. *
  193. * Operations that can be performed on the panel.
  194. */
  195. const struct drm_panel_funcs *funcs;
  196. /**
  197. * @connector_type:
  198. *
  199. * Type of the panel as a DRM_MODE_CONNECTOR_* value. This is used to
  200. * initialise the drm_connector corresponding to the panel with the
  201. * correct connector type.
  202. */
  203. int connector_type;
  204. /**
  205. * @list:
  206. *
  207. * Panel entry in registry.
  208. */
  209. struct list_head list;
  210. /**
  211. * @followers:
  212. *
  213. * A list of struct drm_panel_follower dependent on this panel.
  214. */
  215. struct list_head followers;
  216. /**
  217. * @follower_lock:
  218. *
  219. * Lock for followers list.
  220. */
  221. struct mutex follower_lock;
  222. /**
  223. * @prepare_prev_first:
  224. *
  225. * The previous controller should be prepared first, before the prepare
  226. * for the panel is called. This is largely required for DSI panels
  227. * where the DSI host controller should be initialised to LP-11 before
  228. * the panel is powered up.
  229. */
  230. bool prepare_prev_first;
  231. /**
  232. * @prepared:
  233. *
  234. * If true then the panel has been prepared.
  235. */
  236. bool prepared;
  237. /**
  238. * @enabled:
  239. *
  240. * If true then the panel has been enabled.
  241. */
  242. bool enabled;
  243. };
  244. void drm_panel_init(struct drm_panel *panel, struct device *dev,
  245. const struct drm_panel_funcs *funcs,
  246. int connector_type);
  247. void drm_panel_add(struct drm_panel *panel);
  248. void drm_panel_remove(struct drm_panel *panel);
  249. int drm_panel_prepare(struct drm_panel *panel);
  250. int drm_panel_unprepare(struct drm_panel *panel);
  251. int drm_panel_enable(struct drm_panel *panel);
  252. int drm_panel_disable(struct drm_panel *panel);
  253. int drm_panel_get_modes(struct drm_panel *panel, struct drm_connector *connector);
  254. #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL)
  255. struct drm_panel *of_drm_find_panel(const struct device_node *np);
  256. int of_drm_get_panel_orientation(const struct device_node *np,
  257. enum drm_panel_orientation *orientation);
  258. #else
  259. static inline struct drm_panel *of_drm_find_panel(const struct device_node *np)
  260. {
  261. return ERR_PTR(-ENODEV);
  262. }
  263. static inline int of_drm_get_panel_orientation(const struct device_node *np,
  264. enum drm_panel_orientation *orientation)
  265. {
  266. return -ENODEV;
  267. }
  268. #endif
  269. #if defined(CONFIG_DRM_PANEL)
  270. bool drm_is_panel_follower(struct device *dev);
  271. int drm_panel_add_follower(struct device *follower_dev,
  272. struct drm_panel_follower *follower);
  273. void drm_panel_remove_follower(struct drm_panel_follower *follower);
  274. int devm_drm_panel_add_follower(struct device *follower_dev,
  275. struct drm_panel_follower *follower);
  276. #else
  277. static inline bool drm_is_panel_follower(struct device *dev)
  278. {
  279. return false;
  280. }
  281. static inline int drm_panel_add_follower(struct device *follower_dev,
  282. struct drm_panel_follower *follower)
  283. {
  284. return -ENODEV;
  285. }
  286. static inline void drm_panel_remove_follower(struct drm_panel_follower *follower) { }
  287. static inline int devm_drm_panel_add_follower(struct device *follower_dev,
  288. struct drm_panel_follower *follower)
  289. {
  290. return -ENODEV;
  291. }
  292. #endif
  293. #if IS_ENABLED(CONFIG_DRM_PANEL) && (IS_BUILTIN(CONFIG_BACKLIGHT_CLASS_DEVICE) || \
  294. (IS_MODULE(CONFIG_DRM) && IS_MODULE(CONFIG_BACKLIGHT_CLASS_DEVICE)))
  295. int drm_panel_of_backlight(struct drm_panel *panel);
  296. #else
  297. static inline int drm_panel_of_backlight(struct drm_panel *panel)
  298. {
  299. return 0;
  300. }
  301. #endif
  302. #endif