msm_kms.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * Copyright (c) 2016-2019, 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 panel mode */
  37. #define MSM_MODE_FLAG_SEAMLESS_POMS (1<<4)
  38. /* As there are different display controller blocks depending on the
  39. * snapdragon version, the kms support is split out and the appropriate
  40. * implementation is loaded at runtime. The kms module is responsible
  41. * for constructing the appropriate planes/crtcs/encoders/connectors.
  42. */
  43. struct msm_kms_funcs {
  44. /* hw initialization: */
  45. int (*hw_init)(struct msm_kms *kms);
  46. int (*postinit)(struct msm_kms *kms);
  47. /* irq handling: */
  48. void (*irq_preinstall)(struct msm_kms *kms);
  49. int (*irq_postinstall)(struct msm_kms *kms);
  50. void (*irq_uninstall)(struct msm_kms *kms);
  51. irqreturn_t (*irq)(struct msm_kms *kms);
  52. int (*enable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
  53. void (*disable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
  54. /* modeset, bracketing atomic_commit(): */
  55. void (*prepare_fence)(struct msm_kms *kms,
  56. struct drm_atomic_state *state);
  57. void (*prepare_commit)(struct msm_kms *kms,
  58. struct drm_atomic_state *state);
  59. void (*commit)(struct msm_kms *kms, struct drm_atomic_state *state);
  60. void (*complete_commit)(struct msm_kms *kms,
  61. struct drm_atomic_state *state);
  62. /* functions to wait for atomic commit completed on each CRTC */
  63. void (*wait_for_crtc_commit_done)(struct msm_kms *kms,
  64. struct drm_crtc *crtc);
  65. /* function pointer to wait for pixel transfer to panel to complete*/
  66. void (*wait_for_tx_complete)(struct msm_kms *kms,
  67. struct drm_crtc *crtc);
  68. /* get msm_format w/ optional format modifiers from drm_mode_fb_cmd2 */
  69. const struct msm_format *(*get_format)(struct msm_kms *kms,
  70. const uint32_t format,
  71. const uint64_t modifier);
  72. /* do format checking on format modified through fb_cmd2 modifiers */
  73. int (*check_modified_format)(const struct msm_kms *kms,
  74. const struct msm_format *msm_fmt,
  75. const struct drm_mode_fb_cmd2 *cmd,
  76. struct drm_gem_object **bos);
  77. /* perform complete atomic check of given atomic state */
  78. int (*atomic_check)(struct msm_kms *kms,
  79. struct drm_atomic_state *state);
  80. /* misc: */
  81. long (*round_pixclk)(struct msm_kms *kms, unsigned long rate,
  82. struct drm_encoder *encoder);
  83. int (*set_split_display)(struct msm_kms *kms,
  84. struct drm_encoder *encoder,
  85. struct drm_encoder *slave_encoder,
  86. bool is_cmd_mode);
  87. void (*postopen)(struct msm_kms *kms, struct drm_file *file);
  88. void (*preclose)(struct msm_kms *kms, struct drm_file *file);
  89. void (*postclose)(struct msm_kms *kms, struct drm_file *file);
  90. void (*lastclose)(struct msm_kms *kms,
  91. struct drm_modeset_acquire_ctx *ctx);
  92. int (*register_events)(struct msm_kms *kms,
  93. struct drm_mode_object *obj, u32 event, bool en);
  94. void (*set_encoder_mode)(struct msm_kms *kms,
  95. struct drm_encoder *encoder,
  96. bool cmd_mode);
  97. /* pm suspend/resume hooks */
  98. int (*pm_suspend)(struct device *dev);
  99. int (*pm_resume)(struct device *dev);
  100. /* cleanup: */
  101. void (*destroy)(struct msm_kms *kms);
  102. /* get address space */
  103. struct msm_gem_address_space *(*get_address_space)(
  104. struct msm_kms *kms,
  105. unsigned int domain);
  106. struct device *(*get_address_space_device)(
  107. struct msm_kms *kms,
  108. unsigned int domain);
  109. #ifdef CONFIG_DEBUG_FS
  110. /* debugfs: */
  111. int (*debugfs_init)(struct msm_kms *kms, struct drm_minor *minor);
  112. #endif
  113. /* handle continuous splash */
  114. int (*cont_splash_config)(struct msm_kms *kms);
  115. /* check for continuous splash status */
  116. bool (*check_for_splash)(struct msm_kms *kms);
  117. };
  118. struct msm_kms {
  119. const struct msm_kms_funcs *funcs;
  120. /* irq number to be passed on to drm_irq_install */
  121. int irq;
  122. /* mapper-id used to request GEM buffer mapped for scanout: */
  123. struct msm_gem_address_space *aspace;
  124. };
  125. /**
  126. * Subclass of drm_atomic_state, to allow kms backend to have driver
  127. * private global state. The kms backend can do whatever it wants
  128. * with the ->state ptr. On ->atomic_state_clear() the ->state ptr
  129. * is kfree'd and set back to NULL.
  130. */
  131. struct msm_kms_state {
  132. struct drm_atomic_state base;
  133. void *state;
  134. };
  135. #define to_kms_state(x) container_of(x, struct msm_kms_state, base)
  136. static inline void msm_kms_init(struct msm_kms *kms,
  137. const struct msm_kms_funcs *funcs)
  138. {
  139. kms->funcs = funcs;
  140. }
  141. #ifdef CONFIG_DRM_MSM_MDP4
  142. struct msm_kms *mdp4_kms_init(struct drm_device *dev);
  143. #else
  144. static inline
  145. struct msm_kms *mdp4_kms_init(struct drm_device *dev) { return NULL; };
  146. #endif
  147. #ifdef CONFIG_DRM_MSM_MDP5
  148. struct msm_kms *mdp5_kms_init(struct drm_device *dev);
  149. int msm_mdss_init(struct drm_device *dev);
  150. void msm_mdss_destroy(struct drm_device *dev);
  151. struct msm_kms *mdp5_kms_init(struct drm_device *dev);
  152. int msm_mdss_enable(struct msm_mdss *mdss);
  153. int msm_mdss_disable(struct msm_mdss *mdss);
  154. #else
  155. static inline int msm_mdss_init(struct drm_device *dev)
  156. {
  157. return 0;
  158. }
  159. static inline void msm_mdss_destroy(struct drm_device *dev)
  160. {
  161. }
  162. static inline struct msm_kms *mdp5_kms_init(struct drm_device *dev)
  163. {
  164. return NULL;
  165. }
  166. static inline int msm_mdss_enable(struct msm_mdss *mdss)
  167. {
  168. return 0;
  169. }
  170. static inline int msm_mdss_disable(struct msm_mdss *mdss)
  171. {
  172. return 0;
  173. }
  174. #endif
  175. struct msm_kms *sde_kms_init(struct drm_device *dev);
  176. /**
  177. * Mode Set Utility Functions
  178. */
  179. static inline bool msm_is_mode_seamless(const struct drm_display_mode *mode)
  180. {
  181. return (mode->flags & DRM_MODE_FLAG_SEAMLESS);
  182. }
  183. static inline bool msm_is_mode_seamless_dms(const struct drm_display_mode *mode)
  184. {
  185. return mode ? (mode->private_flags & MSM_MODE_FLAG_SEAMLESS_DMS)
  186. : false;
  187. }
  188. static inline bool msm_is_mode_dynamic_fps(const struct drm_display_mode *mode)
  189. {
  190. return ((mode->flags & DRM_MODE_FLAG_SEAMLESS) &&
  191. (mode->private_flags & MSM_MODE_FLAG_SEAMLESS_DYNAMIC_FPS));
  192. }
  193. static inline bool msm_is_mode_seamless_vrr(const struct drm_display_mode *mode)
  194. {
  195. return mode ? (mode->private_flags & MSM_MODE_FLAG_SEAMLESS_VRR)
  196. : false;
  197. }
  198. static inline bool msm_is_mode_seamless_poms(
  199. const struct drm_display_mode *mode)
  200. {
  201. return mode ? (mode->private_flags & MSM_MODE_FLAG_SEAMLESS_POMS)
  202. : false;
  203. }
  204. static inline bool msm_needs_vblank_pre_modeset(
  205. const struct drm_display_mode *mode)
  206. {
  207. return (mode->private_flags & MSM_MODE_FLAG_VBLANK_PRE_MODESET);
  208. }
  209. #endif /* __MSM_KMS_H__ */