mdp4_kms.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 <linux/clk.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/regulator/consumer.h>
  22. #include "msm_drv.h"
  23. #include "mdp4.xml.h"
  24. /* For transiently registering for different MDP4 irqs that various parts
  25. * of the KMS code need during setup/configuration. We these are not
  26. * necessarily the same as what drm_vblank_get/put() are requesting, and
  27. * the hysteresis in drm_vblank_put() is not necessarily desirable for
  28. * internal housekeeping related irq usage.
  29. */
  30. struct mdp4_irq {
  31. struct list_head node;
  32. uint32_t irqmask;
  33. bool registered;
  34. void (*irq)(struct mdp4_irq *irq, uint32_t irqstatus);
  35. };
  36. struct mdp4_kms {
  37. struct msm_kms base;
  38. struct drm_device *dev;
  39. int rev;
  40. /* mapper-id used to request GEM buffer mapped for scanout: */
  41. int id;
  42. void __iomem *mmio;
  43. struct regulator *dsi_pll_vdda;
  44. struct regulator *dsi_pll_vddio;
  45. struct regulator *vdd;
  46. struct clk *clk;
  47. struct clk *pclk;
  48. struct clk *lut_clk;
  49. /* irq handling: */
  50. bool in_irq;
  51. struct list_head irq_list; /* list of mdp4_irq */
  52. uint32_t vblank_mask; /* irq bits set for userspace vblank */
  53. struct mdp4_irq error_handler;
  54. };
  55. #define to_mdp4_kms(x) container_of(x, struct mdp4_kms, base)
  56. /* platform config data (ie. from DT, or pdata) */
  57. struct mdp4_platform_config {
  58. struct iommu_domain *iommu;
  59. uint32_t max_clk;
  60. };
  61. struct mdp4_format {
  62. struct msm_format base;
  63. enum mdp4_bpc bpc_r, bpc_g, bpc_b;
  64. enum mdp4_bpc_alpha bpc_a;
  65. uint8_t unpack[4];
  66. bool alpha_enable, unpack_tight;
  67. uint8_t cpp, unpack_count;
  68. };
  69. #define to_mdp4_format(x) container_of(x, struct mdp4_format, base)
  70. static inline void mdp4_write(struct mdp4_kms *mdp4_kms, u32 reg, u32 data)
  71. {
  72. msm_writel(data, mdp4_kms->mmio + reg);
  73. }
  74. static inline u32 mdp4_read(struct mdp4_kms *mdp4_kms, u32 reg)
  75. {
  76. return msm_readl(mdp4_kms->mmio + reg);
  77. }
  78. static inline uint32_t pipe2flush(enum mdp4_pipe pipe)
  79. {
  80. switch (pipe) {
  81. case VG1: return MDP4_OVERLAY_FLUSH_VG1;
  82. case VG2: return MDP4_OVERLAY_FLUSH_VG2;
  83. case RGB1: return MDP4_OVERLAY_FLUSH_RGB1;
  84. case RGB2: return MDP4_OVERLAY_FLUSH_RGB1;
  85. default: return 0;
  86. }
  87. }
  88. static inline uint32_t ovlp2flush(int ovlp)
  89. {
  90. switch (ovlp) {
  91. case 0: return MDP4_OVERLAY_FLUSH_OVLP0;
  92. case 1: return MDP4_OVERLAY_FLUSH_OVLP1;
  93. default: return 0;
  94. }
  95. }
  96. static inline uint32_t dma2irq(enum mdp4_dma dma)
  97. {
  98. switch (dma) {
  99. case DMA_P: return MDP4_IRQ_DMA_P_DONE;
  100. case DMA_S: return MDP4_IRQ_DMA_S_DONE;
  101. case DMA_E: return MDP4_IRQ_DMA_E_DONE;
  102. default: return 0;
  103. }
  104. }
  105. static inline uint32_t dma2err(enum mdp4_dma dma)
  106. {
  107. switch (dma) {
  108. case DMA_P: return MDP4_IRQ_PRIMARY_INTF_UDERRUN;
  109. case DMA_S: return 0; // ???
  110. case DMA_E: return MDP4_IRQ_EXTERNAL_INTF_UDERRUN;
  111. default: return 0;
  112. }
  113. }
  114. static inline uint32_t mixercfg(int mixer, enum mdp4_pipe pipe,
  115. enum mdp4_mixer_stage_id stage)
  116. {
  117. uint32_t mixer_cfg = 0;
  118. switch (pipe) {
  119. case VG1:
  120. mixer_cfg = MDP4_LAYERMIXER_IN_CFG_PIPE0(stage) |
  121. COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE0_MIXER1);
  122. break;
  123. case VG2:
  124. mixer_cfg = MDP4_LAYERMIXER_IN_CFG_PIPE1(stage) |
  125. COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE1_MIXER1);
  126. break;
  127. case RGB1:
  128. mixer_cfg = MDP4_LAYERMIXER_IN_CFG_PIPE2(stage) |
  129. COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE2_MIXER1);
  130. break;
  131. case RGB2:
  132. mixer_cfg = MDP4_LAYERMIXER_IN_CFG_PIPE3(stage) |
  133. COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE3_MIXER1);
  134. break;
  135. case RGB3:
  136. mixer_cfg = MDP4_LAYERMIXER_IN_CFG_PIPE4(stage) |
  137. COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE4_MIXER1);
  138. break;
  139. case VG3:
  140. mixer_cfg = MDP4_LAYERMIXER_IN_CFG_PIPE5(stage) |
  141. COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE5_MIXER1);
  142. break;
  143. case VG4:
  144. mixer_cfg = MDP4_LAYERMIXER_IN_CFG_PIPE6(stage) |
  145. COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE6_MIXER1);
  146. break;
  147. default:
  148. WARN_ON("invalid pipe");
  149. break;
  150. }
  151. return mixer_cfg;
  152. }
  153. int mdp4_disable(struct mdp4_kms *mdp4_kms);
  154. int mdp4_enable(struct mdp4_kms *mdp4_kms);
  155. void mdp4_irq_preinstall(struct msm_kms *kms);
  156. int mdp4_irq_postinstall(struct msm_kms *kms);
  157. void mdp4_irq_uninstall(struct msm_kms *kms);
  158. irqreturn_t mdp4_irq(struct msm_kms *kms);
  159. void mdp4_irq_wait(struct mdp4_kms *mdp4_kms, uint32_t irqmask);
  160. void mdp4_irq_register(struct mdp4_kms *mdp4_kms, struct mdp4_irq *irq);
  161. void mdp4_irq_unregister(struct mdp4_kms *mdp4_kms, struct mdp4_irq *irq);
  162. int mdp4_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
  163. void mdp4_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
  164. uint32_t mdp4_get_formats(enum mdp4_pipe pipe_id, uint32_t *formats,
  165. uint32_t max_formats);
  166. const struct msm_format *mdp4_get_format(struct msm_kms *kms, uint32_t format);
  167. void mdp4_plane_install_properties(struct drm_plane *plane,
  168. struct drm_mode_object *obj);
  169. void mdp4_plane_set_scanout(struct drm_plane *plane,
  170. struct drm_framebuffer *fb);
  171. int mdp4_plane_mode_set(struct drm_plane *plane,
  172. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  173. int crtc_x, int crtc_y,
  174. unsigned int crtc_w, unsigned int crtc_h,
  175. uint32_t src_x, uint32_t src_y,
  176. uint32_t src_w, uint32_t src_h);
  177. enum mdp4_pipe mdp4_plane_pipe(struct drm_plane *plane);
  178. struct drm_plane *mdp4_plane_init(struct drm_device *dev,
  179. enum mdp4_pipe pipe_id, bool private_plane);
  180. uint32_t mdp4_crtc_vblank(struct drm_crtc *crtc);
  181. void mdp4_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file);
  182. void mdp4_crtc_set_config(struct drm_crtc *crtc, uint32_t config);
  183. void mdp4_crtc_set_intf(struct drm_crtc *crtc, enum mdp4_intf intf);
  184. void mdp4_crtc_attach(struct drm_crtc *crtc, struct drm_plane *plane);
  185. void mdp4_crtc_detach(struct drm_crtc *crtc, struct drm_plane *plane);
  186. struct drm_crtc *mdp4_crtc_init(struct drm_device *dev,
  187. struct drm_plane *plane, int id, int ovlp_id,
  188. enum mdp4_dma dma_id);
  189. long mdp4_dtv_round_pixclk(struct drm_encoder *encoder, unsigned long rate);
  190. struct drm_encoder *mdp4_dtv_encoder_init(struct drm_device *dev);
  191. #ifdef CONFIG_MSM_BUS_SCALING
  192. static inline int match_dev_name(struct device *dev, void *data)
  193. {
  194. return !strcmp(dev_name(dev), data);
  195. }
  196. /* bus scaling data is associated with extra pointless platform devices,
  197. * "dtv", etc.. this is a bit of a hack, but we need a way for encoders
  198. * to find their pdata to make the bus-scaling stuff work.
  199. */
  200. static inline void *mdp4_find_pdata(const char *devname)
  201. {
  202. struct device *dev;
  203. dev = bus_find_device(&platform_bus_type, NULL,
  204. (void *)devname, match_dev_name);
  205. return dev ? dev->platform_data : NULL;
  206. }
  207. #endif
  208. #endif /* __MDP4_KMS_H__ */