mdp4_kms.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 __MDP4_KMS_H__
  18. #define __MDP4_KMS_H__
  19. #include <drm/drm_panel.h>
  20. #include "msm_drv.h"
  21. #include "msm_kms.h"
  22. #include "disp/mdp_kms.h"
  23. #include "mdp4.xml.h"
  24. struct device_node;
  25. struct mdp4_kms {
  26. struct mdp_kms base;
  27. struct drm_device *dev;
  28. int rev;
  29. void __iomem *mmio;
  30. struct regulator *vdd;
  31. struct clk *clk;
  32. struct clk *pclk;
  33. struct clk *lut_clk;
  34. struct clk *axi_clk;
  35. struct mdp_irq error_handler;
  36. bool rpm_enabled;
  37. /* empty/blank cursor bo to use when cursor is "disabled" */
  38. struct drm_gem_object *blank_cursor_bo;
  39. uint64_t blank_cursor_iova;
  40. };
  41. #define to_mdp4_kms(x) container_of(x, struct mdp4_kms, base)
  42. /* platform config data (ie. from DT, or pdata) */
  43. struct mdp4_platform_config {
  44. struct iommu_domain *iommu;
  45. uint32_t max_clk;
  46. };
  47. static inline void mdp4_write(struct mdp4_kms *mdp4_kms, u32 reg, u32 data)
  48. {
  49. msm_writel(data, mdp4_kms->mmio + reg);
  50. }
  51. static inline u32 mdp4_read(struct mdp4_kms *mdp4_kms, u32 reg)
  52. {
  53. return msm_readl(mdp4_kms->mmio + reg);
  54. }
  55. static inline uint32_t pipe2flush(enum mdp4_pipe pipe)
  56. {
  57. switch (pipe) {
  58. case VG1: return MDP4_OVERLAY_FLUSH_VG1;
  59. case VG2: return MDP4_OVERLAY_FLUSH_VG2;
  60. case RGB1: return MDP4_OVERLAY_FLUSH_RGB1;
  61. case RGB2: return MDP4_OVERLAY_FLUSH_RGB2;
  62. default: return 0;
  63. }
  64. }
  65. static inline uint32_t ovlp2flush(int ovlp)
  66. {
  67. switch (ovlp) {
  68. case 0: return MDP4_OVERLAY_FLUSH_OVLP0;
  69. case 1: return MDP4_OVERLAY_FLUSH_OVLP1;
  70. default: return 0;
  71. }
  72. }
  73. static inline uint32_t dma2irq(enum mdp4_dma dma)
  74. {
  75. switch (dma) {
  76. case DMA_P: return MDP4_IRQ_DMA_P_DONE;
  77. case DMA_S: return MDP4_IRQ_DMA_S_DONE;
  78. case DMA_E: return MDP4_IRQ_DMA_E_DONE;
  79. default: return 0;
  80. }
  81. }
  82. static inline uint32_t dma2err(enum mdp4_dma dma)
  83. {
  84. switch (dma) {
  85. case DMA_P: return MDP4_IRQ_PRIMARY_INTF_UDERRUN;
  86. case DMA_S: return 0; // ???
  87. case DMA_E: return MDP4_IRQ_EXTERNAL_INTF_UDERRUN;
  88. default: return 0;
  89. }
  90. }
  91. static inline uint32_t mixercfg(uint32_t mixer_cfg, int mixer,
  92. enum mdp4_pipe pipe, enum mdp_mixer_stage_id stage)
  93. {
  94. switch (pipe) {
  95. case VG1:
  96. mixer_cfg &= ~(MDP4_LAYERMIXER_IN_CFG_PIPE0__MASK |
  97. MDP4_LAYERMIXER_IN_CFG_PIPE0_MIXER1);
  98. mixer_cfg |= MDP4_LAYERMIXER_IN_CFG_PIPE0(stage) |
  99. COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE0_MIXER1);
  100. break;
  101. case VG2:
  102. mixer_cfg &= ~(MDP4_LAYERMIXER_IN_CFG_PIPE1__MASK |
  103. MDP4_LAYERMIXER_IN_CFG_PIPE1_MIXER1);
  104. mixer_cfg |= MDP4_LAYERMIXER_IN_CFG_PIPE1(stage) |
  105. COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE1_MIXER1);
  106. break;
  107. case RGB1:
  108. mixer_cfg &= ~(MDP4_LAYERMIXER_IN_CFG_PIPE2__MASK |
  109. MDP4_LAYERMIXER_IN_CFG_PIPE2_MIXER1);
  110. mixer_cfg |= MDP4_LAYERMIXER_IN_CFG_PIPE2(stage) |
  111. COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE2_MIXER1);
  112. break;
  113. case RGB2:
  114. mixer_cfg &= ~(MDP4_LAYERMIXER_IN_CFG_PIPE3__MASK |
  115. MDP4_LAYERMIXER_IN_CFG_PIPE3_MIXER1);
  116. mixer_cfg |= MDP4_LAYERMIXER_IN_CFG_PIPE3(stage) |
  117. COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE3_MIXER1);
  118. break;
  119. case RGB3:
  120. mixer_cfg &= ~(MDP4_LAYERMIXER_IN_CFG_PIPE4__MASK |
  121. MDP4_LAYERMIXER_IN_CFG_PIPE4_MIXER1);
  122. mixer_cfg |= MDP4_LAYERMIXER_IN_CFG_PIPE4(stage) |
  123. COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE4_MIXER1);
  124. break;
  125. case VG3:
  126. mixer_cfg &= ~(MDP4_LAYERMIXER_IN_CFG_PIPE5__MASK |
  127. MDP4_LAYERMIXER_IN_CFG_PIPE5_MIXER1);
  128. mixer_cfg |= MDP4_LAYERMIXER_IN_CFG_PIPE5(stage) |
  129. COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE5_MIXER1);
  130. break;
  131. case VG4:
  132. mixer_cfg &= ~(MDP4_LAYERMIXER_IN_CFG_PIPE6__MASK |
  133. MDP4_LAYERMIXER_IN_CFG_PIPE6_MIXER1);
  134. mixer_cfg |= MDP4_LAYERMIXER_IN_CFG_PIPE6(stage) |
  135. COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE6_MIXER1);
  136. break;
  137. default:
  138. WARN(1, "invalid pipe");
  139. break;
  140. }
  141. return mixer_cfg;
  142. }
  143. int mdp4_disable(struct mdp4_kms *mdp4_kms);
  144. int mdp4_enable(struct mdp4_kms *mdp4_kms);
  145. void mdp4_set_irqmask(struct mdp_kms *mdp_kms, uint32_t irqmask,
  146. uint32_t old_irqmask);
  147. void mdp4_irq_preinstall(struct msm_kms *kms);
  148. int mdp4_irq_postinstall(struct msm_kms *kms);
  149. void mdp4_irq_uninstall(struct msm_kms *kms);
  150. irqreturn_t mdp4_irq(struct msm_kms *kms);
  151. int mdp4_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
  152. void mdp4_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
  153. static inline uint32_t mdp4_pipe_caps(enum mdp4_pipe pipe)
  154. {
  155. switch (pipe) {
  156. case VG1:
  157. case VG2:
  158. case VG3:
  159. case VG4:
  160. return MDP_PIPE_CAP_HFLIP | MDP_PIPE_CAP_VFLIP |
  161. MDP_PIPE_CAP_SCALE | MDP_PIPE_CAP_CSC;
  162. case RGB1:
  163. case RGB2:
  164. case RGB3:
  165. return MDP_PIPE_CAP_SCALE;
  166. default:
  167. return 0;
  168. }
  169. }
  170. enum mdp4_pipe mdp4_plane_pipe(struct drm_plane *plane);
  171. struct drm_plane *mdp4_plane_init(struct drm_device *dev,
  172. enum mdp4_pipe pipe_id, bool private_plane);
  173. uint32_t mdp4_crtc_vblank(struct drm_crtc *crtc);
  174. void mdp4_crtc_set_config(struct drm_crtc *crtc, uint32_t config);
  175. void mdp4_crtc_set_intf(struct drm_crtc *crtc, enum mdp4_intf intf, int mixer);
  176. void mdp4_crtc_wait_for_commit_done(struct drm_crtc *crtc);
  177. struct drm_crtc *mdp4_crtc_init(struct drm_device *dev,
  178. struct drm_plane *plane, int id, int ovlp_id,
  179. enum mdp4_dma dma_id);
  180. long mdp4_dtv_round_pixclk(struct drm_encoder *encoder, unsigned long rate);
  181. struct drm_encoder *mdp4_dtv_encoder_init(struct drm_device *dev);
  182. long mdp4_lcdc_round_pixclk(struct drm_encoder *encoder, unsigned long rate);
  183. struct drm_encoder *mdp4_lcdc_encoder_init(struct drm_device *dev,
  184. struct device_node *panel_node);
  185. struct drm_connector *mdp4_lvds_connector_init(struct drm_device *dev,
  186. struct device_node *panel_node, struct drm_encoder *encoder);
  187. #ifdef CONFIG_DRM_MSM_DSI
  188. struct drm_encoder *mdp4_dsi_encoder_init(struct drm_device *dev);
  189. #else
  190. static inline struct drm_encoder *mdp4_dsi_encoder_init(struct drm_device *dev)
  191. {
  192. return ERR_PTR(-ENODEV);
  193. }
  194. #endif
  195. #ifdef CONFIG_COMMON_CLK
  196. struct clk *mpd4_lvds_pll_init(struct drm_device *dev);
  197. #else
  198. static inline struct clk *mpd4_lvds_pll_init(struct drm_device *dev)
  199. {
  200. return ERR_PTR(-ENODEV);
  201. }
  202. #endif
  203. #ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING
  204. /* bus scaling data is associated with extra pointless platform devices,
  205. * "dtv", etc.. this is a bit of a hack, but we need a way for encoders
  206. * to find their pdata to make the bus-scaling stuff work.
  207. */
  208. static inline void *mdp4_find_pdata(const char *devname)
  209. {
  210. struct device *dev;
  211. dev = bus_find_device_by_name(&platform_bus_type, NULL, devname);
  212. return dev ? dev->platform_data : NULL;
  213. }
  214. #endif
  215. #endif /* __MDP4_KMS_H__ */