mtk_drm_ddp_comp.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015 MediaTek Inc.
  4. */
  5. #ifndef MTK_DRM_DDP_COMP_H
  6. #define MTK_DRM_DDP_COMP_H
  7. #include <linux/io.h>
  8. #include <linux/soc/mediatek/mtk-mmsys.h>
  9. struct device;
  10. struct device_node;
  11. struct drm_crtc;
  12. struct drm_device;
  13. struct mtk_plane_state;
  14. struct drm_crtc_state;
  15. enum mtk_ddp_comp_type {
  16. MTK_DISP_OVL,
  17. MTK_DISP_OVL_2L,
  18. MTK_DISP_RDMA,
  19. MTK_DISP_WDMA,
  20. MTK_DISP_COLOR,
  21. MTK_DISP_CCORR,
  22. MTK_DISP_DITHER,
  23. MTK_DISP_AAL,
  24. MTK_DISP_GAMMA,
  25. MTK_DISP_UFOE,
  26. MTK_DSI,
  27. MTK_DPI,
  28. MTK_DISP_PWM,
  29. MTK_DISP_MUTEX,
  30. MTK_DISP_OD,
  31. MTK_DISP_BLS,
  32. MTK_DDP_COMP_TYPE_MAX,
  33. };
  34. struct mtk_ddp_comp;
  35. struct cmdq_pkt;
  36. struct mtk_ddp_comp_funcs {
  37. void (*config)(struct mtk_ddp_comp *comp, unsigned int w,
  38. unsigned int h, unsigned int vrefresh,
  39. unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
  40. void (*start)(struct mtk_ddp_comp *comp);
  41. void (*stop)(struct mtk_ddp_comp *comp);
  42. void (*enable_vblank)(struct mtk_ddp_comp *comp, struct drm_crtc *crtc);
  43. void (*disable_vblank)(struct mtk_ddp_comp *comp);
  44. unsigned int (*supported_rotations)(struct mtk_ddp_comp *comp);
  45. unsigned int (*layer_nr)(struct mtk_ddp_comp *comp);
  46. int (*layer_check)(struct mtk_ddp_comp *comp,
  47. unsigned int idx,
  48. struct mtk_plane_state *state);
  49. void (*layer_config)(struct mtk_ddp_comp *comp, unsigned int idx,
  50. struct mtk_plane_state *state,
  51. struct cmdq_pkt *cmdq_pkt);
  52. void (*gamma_set)(struct mtk_ddp_comp *comp,
  53. struct drm_crtc_state *state);
  54. void (*bgclr_in_on)(struct mtk_ddp_comp *comp);
  55. void (*bgclr_in_off)(struct mtk_ddp_comp *comp);
  56. void (*ctm_set)(struct mtk_ddp_comp *comp,
  57. struct drm_crtc_state *state);
  58. };
  59. struct mtk_ddp_comp {
  60. struct clk *clk;
  61. void __iomem *regs;
  62. int irq;
  63. struct device *larb_dev;
  64. enum mtk_ddp_comp_id id;
  65. const struct mtk_ddp_comp_funcs *funcs;
  66. resource_size_t regs_pa;
  67. u8 subsys;
  68. };
  69. static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
  70. unsigned int w, unsigned int h,
  71. unsigned int vrefresh, unsigned int bpc,
  72. struct cmdq_pkt *cmdq_pkt)
  73. {
  74. if (comp->funcs && comp->funcs->config)
  75. comp->funcs->config(comp, w, h, vrefresh, bpc, cmdq_pkt);
  76. }
  77. static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
  78. {
  79. if (comp->funcs && comp->funcs->start)
  80. comp->funcs->start(comp);
  81. }
  82. static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
  83. {
  84. if (comp->funcs && comp->funcs->stop)
  85. comp->funcs->stop(comp);
  86. }
  87. static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp,
  88. struct drm_crtc *crtc)
  89. {
  90. if (comp->funcs && comp->funcs->enable_vblank)
  91. comp->funcs->enable_vblank(comp, crtc);
  92. }
  93. static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
  94. {
  95. if (comp->funcs && comp->funcs->disable_vblank)
  96. comp->funcs->disable_vblank(comp);
  97. }
  98. static inline
  99. unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
  100. {
  101. if (comp->funcs && comp->funcs->supported_rotations)
  102. return comp->funcs->supported_rotations(comp);
  103. return 0;
  104. }
  105. static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
  106. {
  107. if (comp->funcs && comp->funcs->layer_nr)
  108. return comp->funcs->layer_nr(comp);
  109. return 0;
  110. }
  111. static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
  112. unsigned int idx,
  113. struct mtk_plane_state *state)
  114. {
  115. if (comp->funcs && comp->funcs->layer_check)
  116. return comp->funcs->layer_check(comp, idx, state);
  117. return 0;
  118. }
  119. static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
  120. unsigned int idx,
  121. struct mtk_plane_state *state,
  122. struct cmdq_pkt *cmdq_pkt)
  123. {
  124. if (comp->funcs && comp->funcs->layer_config)
  125. comp->funcs->layer_config(comp, idx, state, cmdq_pkt);
  126. }
  127. static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
  128. struct drm_crtc_state *state)
  129. {
  130. if (comp->funcs && comp->funcs->gamma_set)
  131. comp->funcs->gamma_set(comp, state);
  132. }
  133. static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
  134. {
  135. if (comp->funcs && comp->funcs->bgclr_in_on)
  136. comp->funcs->bgclr_in_on(comp);
  137. }
  138. static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
  139. {
  140. if (comp->funcs && comp->funcs->bgclr_in_off)
  141. comp->funcs->bgclr_in_off(comp);
  142. }
  143. static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
  144. struct drm_crtc_state *state)
  145. {
  146. if (comp->funcs && comp->funcs->ctm_set)
  147. comp->funcs->ctm_set(comp, state);
  148. }
  149. int mtk_ddp_comp_get_id(struct device_node *node,
  150. enum mtk_ddp_comp_type comp_type);
  151. unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
  152. struct mtk_ddp_comp ddp_comp);
  153. int mtk_ddp_comp_init(struct device *dev, struct device_node *comp_node,
  154. struct mtk_ddp_comp *comp, enum mtk_ddp_comp_id comp_id,
  155. const struct mtk_ddp_comp_funcs *funcs);
  156. int mtk_ddp_comp_register(struct drm_device *drm, struct mtk_ddp_comp *comp);
  157. void mtk_ddp_comp_unregister(struct drm_device *drm, struct mtk_ddp_comp *comp);
  158. void mtk_dither_set(struct mtk_ddp_comp *comp, unsigned int bpc,
  159. unsigned int CFG, struct cmdq_pkt *cmdq_pkt);
  160. enum mtk_ddp_comp_type mtk_ddp_comp_get_type(enum mtk_ddp_comp_id comp_id);
  161. void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
  162. struct mtk_ddp_comp *comp, unsigned int offset);
  163. void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
  164. struct mtk_ddp_comp *comp, unsigned int offset);
  165. void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
  166. struct mtk_ddp_comp *comp, unsigned int offset,
  167. unsigned int mask);
  168. #endif /* MTK_DRM_DDP_COMP_H */