mdp5_kms.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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.xml.h"
  23. #include "mdp5_smp.h"
  24. struct mdp5_kms {
  25. struct mdp_kms base;
  26. struct drm_device *dev;
  27. int rev;
  28. /* mapper-id used to request GEM buffer mapped for scanout: */
  29. int id;
  30. /* for tracking smp allocation amongst pipes: */
  31. mdp5_smp_state_t smp_state;
  32. struct mdp5_client_smp_state smp_client_state[CID_MAX];
  33. int smp_blk_cnt;
  34. /* io/register spaces: */
  35. void __iomem *mmio, *vbif;
  36. struct regulator *vdd;
  37. struct clk *axi_clk;
  38. struct clk *ahb_clk;
  39. struct clk *src_clk;
  40. struct clk *core_clk;
  41. struct clk *lut_clk;
  42. struct clk *vsync_clk;
  43. struct hdmi *hdmi;
  44. struct mdp_irq error_handler;
  45. };
  46. #define to_mdp5_kms(x) container_of(x, struct mdp5_kms, base)
  47. /* platform config data (ie. from DT, or pdata) */
  48. struct mdp5_platform_config {
  49. struct iommu_domain *iommu;
  50. uint32_t max_clk;
  51. int smp_blk_cnt;
  52. };
  53. static inline void mdp5_write(struct mdp5_kms *mdp5_kms, u32 reg, u32 data)
  54. {
  55. msm_writel(data, mdp5_kms->mmio + reg);
  56. }
  57. static inline u32 mdp5_read(struct mdp5_kms *mdp5_kms, u32 reg)
  58. {
  59. return msm_readl(mdp5_kms->mmio + reg);
  60. }
  61. static inline const char *pipe2name(enum mdp5_pipe pipe)
  62. {
  63. static const char *names[] = {
  64. #define NAME(n) [SSPP_ ## n] = #n
  65. NAME(VIG0), NAME(VIG1), NAME(VIG2),
  66. NAME(RGB0), NAME(RGB1), NAME(RGB2),
  67. NAME(DMA0), NAME(DMA1),
  68. #undef NAME
  69. };
  70. return names[pipe];
  71. }
  72. static inline uint32_t pipe2flush(enum mdp5_pipe pipe)
  73. {
  74. switch (pipe) {
  75. case SSPP_VIG0: return MDP5_CTL_FLUSH_VIG0;
  76. case SSPP_VIG1: return MDP5_CTL_FLUSH_VIG1;
  77. case SSPP_VIG2: return MDP5_CTL_FLUSH_VIG2;
  78. case SSPP_RGB0: return MDP5_CTL_FLUSH_RGB0;
  79. case SSPP_RGB1: return MDP5_CTL_FLUSH_RGB1;
  80. case SSPP_RGB2: return MDP5_CTL_FLUSH_RGB2;
  81. case SSPP_DMA0: return MDP5_CTL_FLUSH_DMA0;
  82. case SSPP_DMA1: return MDP5_CTL_FLUSH_DMA1;
  83. default: return 0;
  84. }
  85. }
  86. static inline int pipe2nclients(enum mdp5_pipe pipe)
  87. {
  88. switch (pipe) {
  89. case SSPP_RGB0:
  90. case SSPP_RGB1:
  91. case SSPP_RGB2:
  92. return 1;
  93. default:
  94. return 3;
  95. }
  96. }
  97. static inline enum mdp5_client_id pipe2client(enum mdp5_pipe pipe, int plane)
  98. {
  99. WARN_ON(plane >= pipe2nclients(pipe));
  100. switch (pipe) {
  101. case SSPP_VIG0: return CID_VIG0_Y + plane;
  102. case SSPP_VIG1: return CID_VIG1_Y + plane;
  103. case SSPP_VIG2: return CID_VIG2_Y + plane;
  104. case SSPP_RGB0: return CID_RGB0;
  105. case SSPP_RGB1: return CID_RGB1;
  106. case SSPP_RGB2: return CID_RGB2;
  107. case SSPP_DMA0: return CID_DMA0_Y + plane;
  108. case SSPP_DMA1: return CID_DMA1_Y + plane;
  109. default: return CID_UNUSED;
  110. }
  111. }
  112. static inline uint32_t mixer2flush(int lm)
  113. {
  114. switch (lm) {
  115. case 0: return MDP5_CTL_FLUSH_LM0;
  116. case 1: return MDP5_CTL_FLUSH_LM1;
  117. case 2: return MDP5_CTL_FLUSH_LM2;
  118. default: return 0;
  119. }
  120. }
  121. static inline uint32_t intf2err(int intf)
  122. {
  123. switch (intf) {
  124. case 0: return MDP5_IRQ_INTF0_UNDER_RUN;
  125. case 1: return MDP5_IRQ_INTF1_UNDER_RUN;
  126. case 2: return MDP5_IRQ_INTF2_UNDER_RUN;
  127. case 3: return MDP5_IRQ_INTF3_UNDER_RUN;
  128. default: return 0;
  129. }
  130. }
  131. static inline uint32_t intf2vblank(int intf)
  132. {
  133. switch (intf) {
  134. case 0: return MDP5_IRQ_INTF0_VSYNC;
  135. case 1: return MDP5_IRQ_INTF1_VSYNC;
  136. case 2: return MDP5_IRQ_INTF2_VSYNC;
  137. case 3: return MDP5_IRQ_INTF3_VSYNC;
  138. default: return 0;
  139. }
  140. }
  141. int mdp5_disable(struct mdp5_kms *mdp5_kms);
  142. int mdp5_enable(struct mdp5_kms *mdp5_kms);
  143. void mdp5_set_irqmask(struct mdp_kms *mdp_kms, uint32_t irqmask);
  144. void mdp5_irq_preinstall(struct msm_kms *kms);
  145. int mdp5_irq_postinstall(struct msm_kms *kms);
  146. void mdp5_irq_uninstall(struct msm_kms *kms);
  147. irqreturn_t mdp5_irq(struct msm_kms *kms);
  148. int mdp5_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
  149. void mdp5_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
  150. static inline
  151. uint32_t mdp5_get_formats(enum mdp5_pipe pipe, uint32_t *pixel_formats,
  152. uint32_t max_formats)
  153. {
  154. /* TODO when we have YUV, we need to filter supported formats
  155. * based on pipe id..
  156. */
  157. return mdp_get_formats(pixel_formats, max_formats);
  158. }
  159. void mdp5_plane_install_properties(struct drm_plane *plane,
  160. struct drm_mode_object *obj);
  161. void mdp5_plane_set_scanout(struct drm_plane *plane,
  162. struct drm_framebuffer *fb);
  163. int mdp5_plane_mode_set(struct drm_plane *plane,
  164. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  165. int crtc_x, int crtc_y,
  166. unsigned int crtc_w, unsigned int crtc_h,
  167. uint32_t src_x, uint32_t src_y,
  168. uint32_t src_w, uint32_t src_h);
  169. void mdp5_plane_complete_flip(struct drm_plane *plane);
  170. enum mdp5_pipe mdp5_plane_pipe(struct drm_plane *plane);
  171. struct drm_plane *mdp5_plane_init(struct drm_device *dev,
  172. enum mdp5_pipe pipe, bool private_plane);
  173. uint32_t mdp5_crtc_vblank(struct drm_crtc *crtc);
  174. void mdp5_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file);
  175. void mdp5_crtc_set_intf(struct drm_crtc *crtc, int intf,
  176. enum mdp5_intf intf_id);
  177. void mdp5_crtc_attach(struct drm_crtc *crtc, struct drm_plane *plane);
  178. void mdp5_crtc_detach(struct drm_crtc *crtc, struct drm_plane *plane);
  179. struct drm_crtc *mdp5_crtc_init(struct drm_device *dev,
  180. struct drm_plane *plane, int id);
  181. struct drm_encoder *mdp5_encoder_init(struct drm_device *dev, int intf,
  182. enum mdp5_intf intf_id);
  183. #endif /* __MDP5_KMS_H__ */