drm_panel.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. #include <linux/kref.h>
  30. struct backlight_device;
  31. struct dentry;
  32. struct device_node;
  33. struct drm_connector;
  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. * @panel_enabled:
  151. *
  152. * Called after the panel and the backlight have been enabled.
  153. */
  154. int (*panel_enabled)(struct drm_panel_follower *follower);
  155. /**
  156. * @panel_disabling:
  157. *
  158. * Called before the panel and the backlight are disabled.
  159. */
  160. int (*panel_disabling)(struct drm_panel_follower *follower);
  161. };
  162. struct drm_panel_follower {
  163. /**
  164. * @funcs:
  165. *
  166. * Dependent device callbacks; should be initted by the caller.
  167. */
  168. const struct drm_panel_follower_funcs *funcs;
  169. /**
  170. * @list
  171. *
  172. * Used for linking into panel's list; set by drm_panel_add_follower().
  173. */
  174. struct list_head list;
  175. /**
  176. * @panel
  177. *
  178. * The panel we're dependent on; set by drm_panel_add_follower().
  179. */
  180. struct drm_panel *panel;
  181. };
  182. /**
  183. * struct drm_panel - DRM panel object
  184. */
  185. struct drm_panel {
  186. /**
  187. * @dev:
  188. *
  189. * Parent device of the panel.
  190. */
  191. struct device *dev;
  192. /**
  193. * @backlight:
  194. *
  195. * Backlight device, used to turn on backlight after the call
  196. * to enable(), and to turn off backlight before the call to
  197. * disable().
  198. * backlight is set by drm_panel_of_backlight() or
  199. * drm_panel_dp_aux_backlight() and drivers shall not assign it.
  200. */
  201. struct backlight_device *backlight;
  202. /**
  203. * @funcs:
  204. *
  205. * Operations that can be performed on the panel.
  206. */
  207. const struct drm_panel_funcs *funcs;
  208. /**
  209. * @connector_type:
  210. *
  211. * Type of the panel as a DRM_MODE_CONNECTOR_* value. This is used to
  212. * initialise the drm_connector corresponding to the panel with the
  213. * correct connector type.
  214. */
  215. int connector_type;
  216. /**
  217. * @list:
  218. *
  219. * Panel entry in registry.
  220. */
  221. struct list_head list;
  222. /**
  223. * @followers:
  224. *
  225. * A list of struct drm_panel_follower dependent on this panel.
  226. */
  227. struct list_head followers;
  228. /**
  229. * @follower_lock:
  230. *
  231. * Lock for followers list.
  232. */
  233. struct mutex follower_lock;
  234. /**
  235. * @prepare_prev_first:
  236. *
  237. * The previous controller should be prepared first, before the prepare
  238. * for the panel is called. This is largely required for DSI panels
  239. * where the DSI host controller should be initialised to LP-11 before
  240. * the panel is powered up.
  241. */
  242. bool prepare_prev_first;
  243. /**
  244. * @prepared:
  245. *
  246. * If true then the panel has been prepared.
  247. */
  248. bool prepared;
  249. /**
  250. * @enabled:
  251. *
  252. * If true then the panel has been enabled.
  253. */
  254. bool enabled;
  255. /**
  256. * @container: Pointer to the private driver struct embedding this
  257. * @struct drm_panel.
  258. */
  259. void *container;
  260. /**
  261. * @refcount: reference count of users referencing this panel.
  262. */
  263. struct kref refcount;
  264. };
  265. void *__devm_drm_panel_alloc(struct device *dev, size_t size, size_t offset,
  266. const struct drm_panel_funcs *funcs,
  267. int connector_type);
  268. /**
  269. * devm_drm_panel_alloc - Allocate and initialize a refcounted panel.
  270. *
  271. * @dev: struct device of the panel device
  272. * @type: the type of the struct which contains struct &drm_panel
  273. * @member: the name of the &drm_panel within @type
  274. * @funcs: callbacks for this panel
  275. * @connector_type: the connector type (DRM_MODE_CONNECTOR_*) corresponding to
  276. * the panel interface
  277. *
  278. * The reference count of the returned panel is initialized to 1. This
  279. * reference will be automatically dropped via devm (by calling
  280. * drm_panel_put()) when @dev is removed.
  281. *
  282. * Returns:
  283. * Pointer to container structure embedding the panel, ERR_PTR on failure.
  284. */
  285. #define devm_drm_panel_alloc(dev, type, member, funcs, connector_type) \
  286. ((type *)__devm_drm_panel_alloc(dev, sizeof(type), \
  287. offsetof(type, member), funcs, \
  288. connector_type))
  289. void drm_panel_init(struct drm_panel *panel, struct device *dev,
  290. const struct drm_panel_funcs *funcs,
  291. int connector_type);
  292. struct drm_panel *drm_panel_get(struct drm_panel *panel);
  293. void drm_panel_put(struct drm_panel *panel);
  294. void drm_panel_add(struct drm_panel *panel);
  295. void drm_panel_remove(struct drm_panel *panel);
  296. void drm_panel_prepare(struct drm_panel *panel);
  297. void drm_panel_unprepare(struct drm_panel *panel);
  298. void drm_panel_enable(struct drm_panel *panel);
  299. void drm_panel_disable(struct drm_panel *panel);
  300. int drm_panel_get_modes(struct drm_panel *panel, struct drm_connector *connector);
  301. #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL)
  302. struct drm_panel *of_drm_find_panel(const struct device_node *np);
  303. int of_drm_get_panel_orientation(const struct device_node *np,
  304. enum drm_panel_orientation *orientation);
  305. #else
  306. static inline struct drm_panel *of_drm_find_panel(const struct device_node *np)
  307. {
  308. return ERR_PTR(-ENODEV);
  309. }
  310. static inline int of_drm_get_panel_orientation(const struct device_node *np,
  311. enum drm_panel_orientation *orientation)
  312. {
  313. return -ENODEV;
  314. }
  315. #endif
  316. #if defined(CONFIG_DRM_PANEL)
  317. bool drm_is_panel_follower(struct device *dev);
  318. int drm_panel_add_follower(struct device *follower_dev,
  319. struct drm_panel_follower *follower);
  320. void drm_panel_remove_follower(struct drm_panel_follower *follower);
  321. int devm_drm_panel_add_follower(struct device *follower_dev,
  322. struct drm_panel_follower *follower);
  323. #else
  324. static inline bool drm_is_panel_follower(struct device *dev)
  325. {
  326. return false;
  327. }
  328. static inline int drm_panel_add_follower(struct device *follower_dev,
  329. struct drm_panel_follower *follower)
  330. {
  331. return -ENODEV;
  332. }
  333. static inline void drm_panel_remove_follower(struct drm_panel_follower *follower) { }
  334. static inline int devm_drm_panel_add_follower(struct device *follower_dev,
  335. struct drm_panel_follower *follower)
  336. {
  337. return -ENODEV;
  338. }
  339. #endif
  340. #if IS_ENABLED(CONFIG_DRM_PANEL) && (IS_BUILTIN(CONFIG_BACKLIGHT_CLASS_DEVICE) || \
  341. (IS_MODULE(CONFIG_DRM) && IS_MODULE(CONFIG_BACKLIGHT_CLASS_DEVICE)))
  342. int drm_panel_of_backlight(struct drm_panel *panel);
  343. #else
  344. static inline int drm_panel_of_backlight(struct drm_panel *panel)
  345. {
  346. return 0;
  347. }
  348. #endif
  349. #endif