mdp5_kms.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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_smp.h"
  26. struct mdp5_kms {
  27. struct mdp_kms base;
  28. struct drm_device *dev;
  29. struct mdp5_cfg_handler *cfg;
  30. uint32_t caps; /* MDP capabilities (MDP_CAP_XXX bits) */
  31. /* mapper-id used to request GEM buffer mapped for scanout: */
  32. int id;
  33. struct msm_mmu *mmu;
  34. struct mdp5_smp *smp;
  35. struct mdp5_ctl_manager *ctlm;
  36. /* io/register spaces: */
  37. void __iomem *mmio, *vbif;
  38. struct regulator *vdd;
  39. struct clk *axi_clk;
  40. struct clk *ahb_clk;
  41. struct clk *src_clk;
  42. struct clk *core_clk;
  43. struct clk *lut_clk;
  44. struct clk *vsync_clk;
  45. /*
  46. * lock to protect access to global resources: ie., following register:
  47. * - REG_MDP5_MDP_DISP_INTF_SEL
  48. */
  49. spinlock_t resource_lock;
  50. struct mdp_irq error_handler;
  51. struct {
  52. volatile unsigned long enabled_mask;
  53. struct irq_domain *domain;
  54. } irqcontroller;
  55. };
  56. #define to_mdp5_kms(x) container_of(x, struct mdp5_kms, base)
  57. struct mdp5_plane_state {
  58. struct drm_plane_state base;
  59. /* aligned with property */
  60. uint8_t premultiplied;
  61. uint8_t zpos;
  62. uint8_t alpha;
  63. /* assigned by crtc blender */
  64. enum mdp_mixer_stage_id stage;
  65. /* some additional transactional status to help us know in the
  66. * apply path whether we need to update SMP allocation, and
  67. * whether current update is still pending:
  68. */
  69. bool mode_changed : 1;
  70. bool pending : 1;
  71. };
  72. #define to_mdp5_plane_state(x) \
  73. container_of(x, struct mdp5_plane_state, base)
  74. enum mdp5_intf_mode {
  75. MDP5_INTF_MODE_NONE = 0,
  76. /* Modes used for DSI interface (INTF_DSI type): */
  77. MDP5_INTF_DSI_MODE_VIDEO,
  78. MDP5_INTF_DSI_MODE_COMMAND,
  79. /* Modes used for WB interface (INTF_WB type): */
  80. MDP5_INTF_WB_MODE_BLOCK,
  81. MDP5_INTF_WB_MODE_LINE,
  82. };
  83. struct mdp5_interface {
  84. int num; /* display interface number */
  85. enum mdp5_intf_type type;
  86. enum mdp5_intf_mode mode;
  87. };
  88. static inline void mdp5_write(struct mdp5_kms *mdp5_kms, u32 reg, u32 data)
  89. {
  90. msm_writel(data, mdp5_kms->mmio + reg);
  91. }
  92. static inline u32 mdp5_read(struct mdp5_kms *mdp5_kms, u32 reg)
  93. {
  94. return msm_readl(mdp5_kms->mmio + reg);
  95. }
  96. static inline const char *pipe2name(enum mdp5_pipe pipe)
  97. {
  98. static const char *names[] = {
  99. #define NAME(n) [SSPP_ ## n] = #n
  100. NAME(VIG0), NAME(VIG1), NAME(VIG2),
  101. NAME(RGB0), NAME(RGB1), NAME(RGB2),
  102. NAME(DMA0), NAME(DMA1),
  103. NAME(VIG3), NAME(RGB3),
  104. #undef NAME
  105. };
  106. return names[pipe];
  107. }
  108. static inline int pipe2nclients(enum mdp5_pipe pipe)
  109. {
  110. switch (pipe) {
  111. case SSPP_RGB0:
  112. case SSPP_RGB1:
  113. case SSPP_RGB2:
  114. case SSPP_RGB3:
  115. return 1;
  116. default:
  117. return 3;
  118. }
  119. }
  120. static inline uint32_t intf2err(int intf_num)
  121. {
  122. switch (intf_num) {
  123. case 0: return MDP5_IRQ_INTF0_UNDER_RUN;
  124. case 1: return MDP5_IRQ_INTF1_UNDER_RUN;
  125. case 2: return MDP5_IRQ_INTF2_UNDER_RUN;
  126. case 3: return MDP5_IRQ_INTF3_UNDER_RUN;
  127. default: return 0;
  128. }
  129. }
  130. #define GET_PING_PONG_ID(layer_mixer) ((layer_mixer == 5) ? 3 : layer_mixer)
  131. static inline uint32_t intf2vblank(int lm, struct mdp5_interface *intf)
  132. {
  133. /*
  134. * In case of DSI Command Mode, the Ping Pong's read pointer IRQ
  135. * acts as a Vblank signal. The Ping Pong buffer used is bound to
  136. * layer mixer.
  137. */
  138. if ((intf->type == INTF_DSI) &&
  139. (intf->mode == MDP5_INTF_DSI_MODE_COMMAND))
  140. return MDP5_IRQ_PING_PONG_0_RD_PTR << GET_PING_PONG_ID(lm);
  141. if (intf->type == INTF_WB)
  142. return MDP5_IRQ_WB_2_DONE;
  143. switch (intf->num) {
  144. case 0: return MDP5_IRQ_INTF0_VSYNC;
  145. case 1: return MDP5_IRQ_INTF1_VSYNC;
  146. case 2: return MDP5_IRQ_INTF2_VSYNC;
  147. case 3: return MDP5_IRQ_INTF3_VSYNC;
  148. default: return 0;
  149. }
  150. }
  151. static inline uint32_t lm2ppdone(int lm)
  152. {
  153. return MDP5_IRQ_PING_PONG_0_DONE << GET_PING_PONG_ID(lm);
  154. }
  155. int mdp5_disable(struct mdp5_kms *mdp5_kms);
  156. int mdp5_enable(struct mdp5_kms *mdp5_kms);
  157. void mdp5_set_irqmask(struct mdp_kms *mdp_kms, uint32_t irqmask,
  158. uint32_t old_irqmask);
  159. void mdp5_irq_preinstall(struct msm_kms *kms);
  160. int mdp5_irq_postinstall(struct msm_kms *kms);
  161. void mdp5_irq_uninstall(struct msm_kms *kms);
  162. irqreturn_t mdp5_irq(struct msm_kms *kms);
  163. int mdp5_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
  164. void mdp5_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
  165. int mdp5_irq_domain_init(struct mdp5_kms *mdp5_kms);
  166. void mdp5_irq_domain_fini(struct mdp5_kms *mdp5_kms);
  167. uint32_t mdp5_plane_get_flush(struct drm_plane *plane);
  168. void mdp5_plane_complete_flip(struct drm_plane *plane);
  169. void mdp5_plane_complete_commit(struct drm_plane *plane,
  170. struct drm_plane_state *state);
  171. enum mdp5_pipe mdp5_plane_pipe(struct drm_plane *plane);
  172. struct drm_plane *mdp5_plane_init(struct drm_device *dev,
  173. enum mdp5_pipe pipe, bool private_plane,
  174. uint32_t reg_offset, uint32_t caps);
  175. uint32_t mdp5_crtc_vblank(struct drm_crtc *crtc);
  176. int mdp5_crtc_get_lm(struct drm_crtc *crtc);
  177. void mdp5_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file);
  178. void mdp5_crtc_set_pipeline(struct drm_crtc *crtc,
  179. struct mdp5_interface *intf, struct mdp5_ctl *ctl);
  180. void mdp5_crtc_wait_for_commit_done(struct drm_crtc *crtc);
  181. struct drm_crtc *mdp5_crtc_init(struct drm_device *dev,
  182. struct drm_plane *plane, int id);
  183. struct drm_encoder *mdp5_encoder_init(struct drm_device *dev,
  184. struct mdp5_interface *intf, struct mdp5_ctl *ctl);
  185. int mdp5_encoder_set_split_display(struct drm_encoder *encoder,
  186. struct drm_encoder *slave_encoder);
  187. #ifdef CONFIG_DRM_MSM_DSI
  188. struct drm_encoder *mdp5_cmd_encoder_init(struct drm_device *dev,
  189. struct mdp5_interface *intf, struct mdp5_ctl *ctl);
  190. int mdp5_cmd_encoder_set_split_display(struct drm_encoder *encoder,
  191. struct drm_encoder *slave_encoder);
  192. #else
  193. static inline struct drm_encoder *mdp5_cmd_encoder_init(struct drm_device *dev,
  194. struct mdp5_interface *intf, struct mdp5_ctl *ctl)
  195. {
  196. return ERR_PTR(-EINVAL);
  197. }
  198. static inline int mdp5_cmd_encoder_set_split_display(
  199. struct drm_encoder *encoder, struct drm_encoder *slave_encoder)
  200. {
  201. return -EINVAL;
  202. }
  203. #endif
  204. #endif /* __MDP5_KMS_H__ */