mdp5_kms.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * Copyright (C) 2013 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __MDP5_KMS_H__
  18. #define __MDP5_KMS_H__
  19. #include "msm_drv.h"
  20. #include "msm_kms.h"
  21. #include "mdp/mdp_kms.h"
  22. #include "mdp5_cfg.h" /* must be included before mdp5.xml.h */
  23. #include "mdp5.xml.h"
  24. #include "mdp5_ctl.h"
  25. #include "mdp5_pipe.h"
  26. #include "mdp5_smp.h"
  27. struct mdp5_state;
  28. struct mdp5_kms {
  29. struct mdp_kms base;
  30. struct drm_device *dev;
  31. struct platform_device *pdev;
  32. unsigned num_hwpipes;
  33. struct mdp5_hw_pipe *hwpipes[SSPP_MAX];
  34. struct mdp5_cfg_handler *cfg;
  35. uint32_t caps; /* MDP capabilities (MDP_CAP_XXX bits) */
  36. /**
  37. * Global atomic state. Do not access directly, use mdp5_get_state()
  38. */
  39. struct mdp5_state *state;
  40. struct drm_modeset_lock state_lock;
  41. /* mapper-id used to request GEM buffer mapped for scanout: */
  42. int id;
  43. struct msm_gem_address_space *aspace;
  44. struct mdp5_smp *smp;
  45. struct mdp5_ctl_manager *ctlm;
  46. /* io/register spaces: */
  47. void __iomem *mmio;
  48. struct clk *axi_clk;
  49. struct clk *ahb_clk;
  50. struct clk *core_clk;
  51. struct clk *lut_clk;
  52. struct clk *vsync_clk;
  53. /*
  54. * lock to protect access to global resources: ie., following register:
  55. * - REG_MDP5_DISP_INTF_SEL
  56. */
  57. spinlock_t resource_lock;
  58. bool rpm_enabled;
  59. struct mdp_irq error_handler;
  60. };
  61. #define to_mdp5_kms(x) container_of(x, struct mdp5_kms, base)
  62. /* Global atomic state for tracking resources that are shared across
  63. * multiple kms objects (planes/crtcs/etc).
  64. *
  65. * For atomic updates which require modifying global state,
  66. */
  67. struct mdp5_state {
  68. struct mdp5_hw_pipe_state hwpipe;
  69. struct mdp5_smp_state smp;
  70. };
  71. struct mdp5_state *__must_check
  72. mdp5_get_state(struct drm_atomic_state *s);
  73. /* Atomic plane state. Subclasses the base drm_plane_state in order to
  74. * track assigned hwpipe and hw specific state.
  75. */
  76. struct mdp5_plane_state {
  77. struct drm_plane_state base;
  78. struct mdp5_hw_pipe *hwpipe;
  79. /* aligned with property */
  80. uint8_t premultiplied;
  81. uint8_t zpos;
  82. uint8_t alpha;
  83. /* assigned by crtc blender */
  84. enum mdp_mixer_stage_id stage;
  85. };
  86. #define to_mdp5_plane_state(x) \
  87. container_of(x, struct mdp5_plane_state, base)
  88. enum mdp5_intf_mode {
  89. MDP5_INTF_MODE_NONE = 0,
  90. /* Modes used for DSI interface (INTF_DSI type): */
  91. MDP5_INTF_DSI_MODE_VIDEO,
  92. MDP5_INTF_DSI_MODE_COMMAND,
  93. /* Modes used for WB interface (INTF_WB type): */
  94. MDP5_INTF_WB_MODE_BLOCK,
  95. MDP5_INTF_WB_MODE_LINE,
  96. };
  97. struct mdp5_interface {
  98. int num; /* display interface number */
  99. enum mdp5_intf_type type;
  100. enum mdp5_intf_mode mode;
  101. };
  102. static inline void mdp5_write(struct mdp5_kms *mdp5_kms, u32 reg, u32 data)
  103. {
  104. msm_writel(data, mdp5_kms->mmio + reg);
  105. }
  106. static inline u32 mdp5_read(struct mdp5_kms *mdp5_kms, u32 reg)
  107. {
  108. return msm_readl(mdp5_kms->mmio + reg);
  109. }
  110. static inline const char *stage2name(enum mdp_mixer_stage_id stage)
  111. {
  112. static const char *names[] = {
  113. #define NAME(n) [n] = #n
  114. NAME(STAGE_UNUSED), NAME(STAGE_BASE),
  115. NAME(STAGE0), NAME(STAGE1), NAME(STAGE2),
  116. NAME(STAGE3), NAME(STAGE4), NAME(STAGE6),
  117. #undef NAME
  118. };
  119. return names[stage];
  120. }
  121. static inline const char *pipe2name(enum mdp5_pipe pipe)
  122. {
  123. static const char *names[] = {
  124. #define NAME(n) [SSPP_ ## n] = #n
  125. NAME(VIG0), NAME(VIG1), NAME(VIG2),
  126. NAME(RGB0), NAME(RGB1), NAME(RGB2),
  127. NAME(DMA0), NAME(DMA1),
  128. NAME(VIG3), NAME(RGB3),
  129. #undef NAME
  130. };
  131. return names[pipe];
  132. }
  133. static inline int pipe2nclients(enum mdp5_pipe pipe)
  134. {
  135. switch (pipe) {
  136. case SSPP_RGB0:
  137. case SSPP_RGB1:
  138. case SSPP_RGB2:
  139. case SSPP_RGB3:
  140. return 1;
  141. default:
  142. return 3;
  143. }
  144. }
  145. static inline uint32_t intf2err(int intf_num)
  146. {
  147. switch (intf_num) {
  148. case 0: return MDP5_IRQ_INTF0_UNDER_RUN;
  149. case 1: return MDP5_IRQ_INTF1_UNDER_RUN;
  150. case 2: return MDP5_IRQ_INTF2_UNDER_RUN;
  151. case 3: return MDP5_IRQ_INTF3_UNDER_RUN;
  152. default: return 0;
  153. }
  154. }
  155. #define GET_PING_PONG_ID(layer_mixer) ((layer_mixer == 5) ? 3 : layer_mixer)
  156. static inline uint32_t intf2vblank(int lm, struct mdp5_interface *intf)
  157. {
  158. /*
  159. * In case of DSI Command Mode, the Ping Pong's read pointer IRQ
  160. * acts as a Vblank signal. The Ping Pong buffer used is bound to
  161. * layer mixer.
  162. */
  163. if ((intf->type == INTF_DSI) &&
  164. (intf->mode == MDP5_INTF_DSI_MODE_COMMAND))
  165. return MDP5_IRQ_PING_PONG_0_RD_PTR << GET_PING_PONG_ID(lm);
  166. if (intf->type == INTF_WB)
  167. return MDP5_IRQ_WB_2_DONE;
  168. switch (intf->num) {
  169. case 0: return MDP5_IRQ_INTF0_VSYNC;
  170. case 1: return MDP5_IRQ_INTF1_VSYNC;
  171. case 2: return MDP5_IRQ_INTF2_VSYNC;
  172. case 3: return MDP5_IRQ_INTF3_VSYNC;
  173. default: return 0;
  174. }
  175. }
  176. static inline uint32_t lm2ppdone(int lm)
  177. {
  178. return MDP5_IRQ_PING_PONG_0_DONE << GET_PING_PONG_ID(lm);
  179. }
  180. int mdp5_disable(struct mdp5_kms *mdp5_kms);
  181. int mdp5_enable(struct mdp5_kms *mdp5_kms);
  182. void mdp5_set_irqmask(struct mdp_kms *mdp_kms, uint32_t irqmask,
  183. uint32_t old_irqmask);
  184. void mdp5_irq_preinstall(struct msm_kms *kms);
  185. int mdp5_irq_postinstall(struct msm_kms *kms);
  186. void mdp5_irq_uninstall(struct msm_kms *kms);
  187. irqreturn_t mdp5_irq(struct msm_kms *kms);
  188. int mdp5_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
  189. void mdp5_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
  190. int mdp5_irq_domain_init(struct mdp5_kms *mdp5_kms);
  191. void mdp5_irq_domain_fini(struct mdp5_kms *mdp5_kms);
  192. uint32_t mdp5_plane_get_flush(struct drm_plane *plane);
  193. enum mdp5_pipe mdp5_plane_pipe(struct drm_plane *plane);
  194. struct drm_plane *mdp5_plane_init(struct drm_device *dev, bool primary);
  195. uint32_t mdp5_crtc_vblank(struct drm_crtc *crtc);
  196. int mdp5_crtc_get_lm(struct drm_crtc *crtc);
  197. void mdp5_crtc_set_pipeline(struct drm_crtc *crtc,
  198. struct mdp5_interface *intf, struct mdp5_ctl *ctl);
  199. void mdp5_crtc_wait_for_commit_done(struct drm_crtc *crtc);
  200. struct drm_crtc *mdp5_crtc_init(struct drm_device *dev,
  201. struct drm_plane *plane, int id);
  202. struct drm_encoder *mdp5_encoder_init(struct drm_device *dev,
  203. struct mdp5_interface *intf, struct mdp5_ctl *ctl);
  204. int mdp5_encoder_set_split_display(struct drm_encoder *encoder,
  205. struct drm_encoder *slave_encoder);
  206. int mdp5_encoder_get_linecount(struct drm_encoder *encoder);
  207. u32 mdp5_encoder_get_framecount(struct drm_encoder *encoder);
  208. #ifdef CONFIG_DRM_MSM_DSI
  209. struct drm_encoder *mdp5_cmd_encoder_init(struct drm_device *dev,
  210. struct mdp5_interface *intf, struct mdp5_ctl *ctl);
  211. int mdp5_cmd_encoder_set_split_display(struct drm_encoder *encoder,
  212. struct drm_encoder *slave_encoder);
  213. #else
  214. static inline struct drm_encoder *mdp5_cmd_encoder_init(struct drm_device *dev,
  215. struct mdp5_interface *intf, struct mdp5_ctl *ctl)
  216. {
  217. return ERR_PTR(-EINVAL);
  218. }
  219. static inline int mdp5_cmd_encoder_set_split_display(
  220. struct drm_encoder *encoder, struct drm_encoder *slave_encoder)
  221. {
  222. return -EINVAL;
  223. }
  224. #endif
  225. #endif /* __MDP5_KMS_H__ */