msm_kms.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <[email protected]>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __MSM_KMS_H__
  19. #define __MSM_KMS_H__
  20. #include <linux/clk.h>
  21. #include <linux/regulator/consumer.h>
  22. #include "msm_drv.h"
  23. #define MAX_PLANE 4
  24. /**
  25. * Device Private DRM Mode Flags
  26. * drm_mode->private_flags
  27. */
  28. /* Connector has interpreted seamless transition request as dynamic fps */
  29. #define MSM_MODE_FLAG_SEAMLESS_DYNAMIC_FPS (1<<0)
  30. /* Transition to new mode requires a wait-for-vblank before the modeset */
  31. #define MSM_MODE_FLAG_VBLANK_PRE_MODESET (1<<1)
  32. /* Request to switch the connector mode */
  33. #define MSM_MODE_FLAG_SEAMLESS_DMS (1<<2)
  34. /* Request to switch the fps */
  35. #define MSM_MODE_FLAG_SEAMLESS_VRR (1<<3)
  36. /* Request to switch the bit clk */
  37. #define MSM_MODE_FLAG_SEAMLESS_DYN_CLK (1<<4)
  38. /* Request to make the seamless switch */
  39. #define DRM_MODE_FLAG_SEAMLESS (1<<5)
  40. /* Request to switch the panel mode to video */
  41. #define MSM_MODE_FLAG_SEAMLESS_POMS_VID (1<<6)
  42. /* Request to switch the panel mode to command */
  43. #define MSM_MODE_FLAG_SEAMLESS_POMS_CMD (1<<7)
  44. /* As there are different display controller blocks depending on the
  45. * snapdragon version, the kms support is split out and the appropriate
  46. * implementation is loaded at runtime. The kms module is responsible
  47. * for constructing the appropriate planes/crtcs/encoders/connectors.
  48. */
  49. struct msm_kms_funcs {
  50. /* hw initialization: */
  51. int (*hw_init)(struct msm_kms *kms);
  52. int (*postinit)(struct msm_kms *kms);
  53. /* irq handling: */
  54. void (*irq_preinstall)(struct msm_kms *kms);
  55. int (*irq_postinstall)(struct msm_kms *kms);
  56. void (*irq_uninstall)(struct msm_kms *kms);
  57. irqreturn_t (*irq)(struct msm_kms *kms);
  58. /* modeset, bracketing atomic_commit(): */
  59. void (*prepare_fence)(struct msm_kms *kms,
  60. struct drm_atomic_state *state);
  61. void (*prepare_commit)(struct msm_kms *kms,
  62. struct drm_atomic_state *state);
  63. void (*commit)(struct msm_kms *kms, struct drm_atomic_state *state);
  64. void (*complete_commit)(struct msm_kms *kms,
  65. struct drm_atomic_state *state);
  66. struct msm_display_mode *(*get_msm_mode)(
  67. struct drm_crtc_state *c_state);
  68. /* functions to wait for atomic commit completed on each CRTC */
  69. void (*wait_for_crtc_commit_done)(struct msm_kms *kms,
  70. struct drm_crtc *crtc);
  71. /* function pointer to wait for pixel transfer to panel to complete*/
  72. void (*wait_for_tx_complete)(struct msm_kms *kms,
  73. struct drm_crtc *crtc);
  74. /* get msm_format w/ optional format modifiers from drm_mode_fb_cmd2 */
  75. const struct msm_format *(*get_format)(struct msm_kms *kms,
  76. const uint32_t format,
  77. const uint64_t modifier);
  78. /* do format checking on format modified through fb_cmd2 modifiers */
  79. int (*check_modified_format)(const struct msm_kms *kms,
  80. const struct msm_format *msm_fmt,
  81. const struct drm_mode_fb_cmd2 *cmd,
  82. struct drm_gem_object **bos);
  83. /* perform complete atomic check of given atomic state */
  84. int (*atomic_check)(struct msm_kms *kms,
  85. struct drm_atomic_state *state);
  86. /* misc: */
  87. long (*round_pixclk)(struct msm_kms *kms, unsigned long rate,
  88. struct drm_encoder *encoder);
  89. int (*set_split_display)(struct msm_kms *kms,
  90. struct drm_encoder *encoder,
  91. struct drm_encoder *slave_encoder,
  92. bool is_cmd_mode);
  93. void (*postopen)(struct msm_kms *kms, struct drm_file *file);
  94. void (*postclose)(struct msm_kms *kms, struct drm_file *file);
  95. void (*lastclose)(struct msm_kms *kms);
  96. int (*register_events)(struct msm_kms *kms,
  97. struct drm_mode_object *obj, u32 event, bool en);
  98. void (*set_encoder_mode)(struct msm_kms *kms,
  99. struct drm_encoder *encoder,
  100. bool cmd_mode);
  101. void (*display_early_wakeup)(struct drm_device *dev,
  102. const int32_t connector_id);
  103. /* pm suspend/resume hooks */
  104. int (*pm_suspend)(struct device *dev);
  105. int (*pm_resume)(struct device *dev);
  106. /* cleanup: */
  107. void (*destroy)(struct msm_kms *kms);
  108. /* get address space */
  109. struct msm_gem_address_space *(*get_address_space)(
  110. struct msm_kms *kms,
  111. unsigned int domain);
  112. struct device *(*get_address_space_device)(
  113. struct msm_kms *kms,
  114. unsigned int domain);
  115. #ifdef CONFIG_DEBUG_FS
  116. /* debugfs: */
  117. int (*debugfs_init)(struct msm_kms *kms, struct drm_minor *minor);
  118. #endif
  119. /* destroys debugfs */
  120. void (*debugfs_destroy)(struct msm_kms *kms);
  121. /* handle continuous splash */
  122. int (*cont_splash_config)(struct msm_kms *kms,
  123. struct drm_atomic_state *state);
  124. /* check for continuous splash status */
  125. bool (*check_for_splash)(struct msm_kms *kms);
  126. /* topology lm information */
  127. int (*get_mixer_count)(const struct msm_kms *kms,
  128. const struct drm_display_mode *mode,
  129. const struct msm_resource_caps_info *res, u32 *num_lm);
  130. /* topology dsc information */
  131. int (*get_dsc_count)(const struct msm_kms *kms,
  132. u32 hdisplay, u32 *num_dsc);
  133. };
  134. struct msm_kms {
  135. const struct msm_kms_funcs *funcs;
  136. /* irq number to be passed on to drm_irq_install */
  137. int irq;
  138. /* mapper-id used to request GEM buffer mapped for scanout: */
  139. struct msm_gem_address_space *aspace;
  140. /* DRM client used for lastclose cleanup */
  141. struct drm_client_dev client;
  142. };
  143. /**
  144. * Subclass of drm_atomic_state, to allow kms backend to have driver
  145. * private global state. The kms backend can do whatever it wants
  146. * with the ->state ptr. On ->atomic_state_clear() the ->state ptr
  147. * is kfree'd and set back to NULL.
  148. */
  149. struct msm_kms_state {
  150. struct drm_atomic_state base;
  151. void *state;
  152. };
  153. #define to_kms_state(x) container_of(x, struct msm_kms_state, base)
  154. static inline void msm_kms_init(struct msm_kms *kms,
  155. const struct msm_kms_funcs *funcs)
  156. {
  157. kms->funcs = funcs;
  158. }
  159. #ifdef CONFIG_DRM_MSM_MDP4
  160. struct msm_kms *mdp4_kms_init(struct drm_device *dev);
  161. #else
  162. static inline
  163. struct msm_kms *mdp4_kms_init(struct drm_device *dev) { return NULL; };
  164. #endif
  165. #if IS_ENABLED(CONFIG_DRM_MSM_MDP5)
  166. struct msm_kms *mdp5_kms_init(struct drm_device *dev);
  167. int msm_mdss_init(struct drm_device *dev);
  168. void msm_mdss_destroy(struct drm_device *dev);
  169. struct msm_kms *mdp5_kms_init(struct drm_device *dev);
  170. int msm_mdss_enable(struct msm_mdss *mdss);
  171. int msm_mdss_disable(struct msm_mdss *mdss);
  172. #else
  173. static inline int msm_mdss_init(struct drm_device *dev)
  174. {
  175. return 0;
  176. }
  177. static inline void msm_mdss_destroy(struct drm_device *dev)
  178. {
  179. }
  180. static inline struct msm_kms *mdp5_kms_init(struct drm_device *dev)
  181. {
  182. return NULL;
  183. }
  184. static inline int msm_mdss_enable(struct msm_mdss *mdss)
  185. {
  186. return 0;
  187. }
  188. static inline int msm_mdss_disable(struct msm_mdss *mdss)
  189. {
  190. return 0;
  191. }
  192. #endif /* CONFIG_DRM_MSM_MDP5 */
  193. struct msm_kms *sde_kms_init(struct drm_device *dev);
  194. /**
  195. * Mode Set Utility Functions
  196. */
  197. static inline bool msm_is_mode_seamless(const struct msm_display_mode *mode)
  198. {
  199. return (mode->private_flags & DRM_MODE_FLAG_SEAMLESS);
  200. }
  201. static inline bool msm_is_mode_seamless_dms(const struct msm_display_mode *mode)
  202. {
  203. return mode ? (mode->private_flags & MSM_MODE_FLAG_SEAMLESS_DMS)
  204. : false;
  205. }
  206. static inline bool msm_is_mode_dynamic_fps(const struct msm_display_mode *mode)
  207. {
  208. return ((mode->private_flags & DRM_MODE_FLAG_SEAMLESS) &&
  209. (mode->private_flags & MSM_MODE_FLAG_SEAMLESS_DYNAMIC_FPS));
  210. }
  211. static inline bool msm_is_mode_seamless_vrr(const struct msm_display_mode *mode)
  212. {
  213. return mode ? (mode->private_flags & MSM_MODE_FLAG_SEAMLESS_VRR)
  214. : false;
  215. }
  216. static inline bool msm_is_mode_seamless_poms_to_vid(
  217. const struct msm_display_mode *mode)
  218. {
  219. return mode ? (mode->private_flags & MSM_MODE_FLAG_SEAMLESS_POMS_VID)
  220. : false;
  221. }
  222. static inline bool msm_is_mode_seamless_poms_to_cmd(
  223. const struct msm_display_mode *mode)
  224. {
  225. return mode ? (mode->private_flags & MSM_MODE_FLAG_SEAMLESS_POMS_CMD)
  226. : false;
  227. }
  228. static inline bool msm_is_mode_seamless_poms(
  229. const struct msm_display_mode *mode)
  230. {
  231. return (msm_is_mode_seamless_poms_to_vid(mode) ||
  232. msm_is_mode_seamless_poms_to_cmd(mode));
  233. }
  234. static inline bool msm_is_mode_seamless_dyn_clk(
  235. const struct msm_display_mode *mode)
  236. {
  237. return mode ? (mode->private_flags & MSM_MODE_FLAG_SEAMLESS_DYN_CLK)
  238. : false;
  239. }
  240. static inline bool msm_needs_vblank_pre_modeset(
  241. const struct msm_display_mode *mode)
  242. {
  243. return (mode->private_flags & MSM_MODE_FLAG_VBLANK_PRE_MODESET);
  244. }
  245. static inline bool msm_is_private_mode_changed(
  246. struct drm_crtc_state *state)
  247. {
  248. struct msm_display_mode *msm_mode = NULL;
  249. struct msm_drm_private *priv = NULL;
  250. struct msm_kms *kms;
  251. if (!state || !state->crtc)
  252. return false;
  253. priv = state->crtc->dev->dev_private;
  254. if (!priv)
  255. return false;
  256. kms = priv->kms;
  257. if (!kms || !kms->funcs->get_msm_mode)
  258. return false;
  259. msm_mode = kms->funcs->get_msm_mode(state);
  260. if (!msm_mode)
  261. return false;
  262. if (msm_is_mode_seamless_poms(msm_mode))
  263. return true;
  264. return false;
  265. }
  266. static inline bool msm_atomic_needs_modeset(struct drm_crtc_state *state)
  267. {
  268. if (drm_atomic_crtc_needs_modeset(state))
  269. return true;
  270. if (msm_is_private_mode_changed(state))
  271. return true;
  272. return false;
  273. }
  274. #endif /* __MSM_KMS_H__ */