msm_kms.h 9.9 KB

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