mtk_drm_ddp_comp.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright (c) 2015 MediaTek Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef MTK_DRM_DDP_COMP_H
  14. #define MTK_DRM_DDP_COMP_H
  15. #include <linux/io.h>
  16. struct device;
  17. struct device_node;
  18. struct drm_crtc;
  19. struct drm_device;
  20. struct mtk_plane_state;
  21. struct drm_crtc_state;
  22. enum mtk_ddp_comp_type {
  23. MTK_DISP_OVL,
  24. MTK_DISP_RDMA,
  25. MTK_DISP_WDMA,
  26. MTK_DISP_COLOR,
  27. MTK_DISP_AAL,
  28. MTK_DISP_GAMMA,
  29. MTK_DISP_UFOE,
  30. MTK_DSI,
  31. MTK_DPI,
  32. MTK_DISP_PWM,
  33. MTK_DISP_MUTEX,
  34. MTK_DISP_OD,
  35. MTK_DISP_BLS,
  36. MTK_DDP_COMP_TYPE_MAX,
  37. };
  38. enum mtk_ddp_comp_id {
  39. DDP_COMPONENT_AAL0,
  40. DDP_COMPONENT_AAL1,
  41. DDP_COMPONENT_BLS,
  42. DDP_COMPONENT_COLOR0,
  43. DDP_COMPONENT_COLOR1,
  44. DDP_COMPONENT_DPI0,
  45. DDP_COMPONENT_DPI1,
  46. DDP_COMPONENT_DSI0,
  47. DDP_COMPONENT_DSI1,
  48. DDP_COMPONENT_DSI2,
  49. DDP_COMPONENT_DSI3,
  50. DDP_COMPONENT_GAMMA,
  51. DDP_COMPONENT_OD0,
  52. DDP_COMPONENT_OD1,
  53. DDP_COMPONENT_OVL0,
  54. DDP_COMPONENT_OVL1,
  55. DDP_COMPONENT_PWM0,
  56. DDP_COMPONENT_PWM1,
  57. DDP_COMPONENT_PWM2,
  58. DDP_COMPONENT_RDMA0,
  59. DDP_COMPONENT_RDMA1,
  60. DDP_COMPONENT_RDMA2,
  61. DDP_COMPONENT_UFOE,
  62. DDP_COMPONENT_WDMA0,
  63. DDP_COMPONENT_WDMA1,
  64. DDP_COMPONENT_ID_MAX,
  65. };
  66. struct mtk_ddp_comp;
  67. struct mtk_ddp_comp_funcs {
  68. void (*config)(struct mtk_ddp_comp *comp, unsigned int w,
  69. unsigned int h, unsigned int vrefresh, unsigned int bpc);
  70. void (*start)(struct mtk_ddp_comp *comp);
  71. void (*stop)(struct mtk_ddp_comp *comp);
  72. void (*enable_vblank)(struct mtk_ddp_comp *comp, struct drm_crtc *crtc);
  73. void (*disable_vblank)(struct mtk_ddp_comp *comp);
  74. unsigned int (*layer_nr)(struct mtk_ddp_comp *comp);
  75. void (*layer_on)(struct mtk_ddp_comp *comp, unsigned int idx);
  76. void (*layer_off)(struct mtk_ddp_comp *comp, unsigned int idx);
  77. void (*layer_config)(struct mtk_ddp_comp *comp, unsigned int idx,
  78. struct mtk_plane_state *state);
  79. void (*gamma_set)(struct mtk_ddp_comp *comp,
  80. struct drm_crtc_state *state);
  81. };
  82. struct mtk_ddp_comp {
  83. struct clk *clk;
  84. void __iomem *regs;
  85. int irq;
  86. struct device *larb_dev;
  87. enum mtk_ddp_comp_id id;
  88. const struct mtk_ddp_comp_funcs *funcs;
  89. };
  90. static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
  91. unsigned int w, unsigned int h,
  92. unsigned int vrefresh, unsigned int bpc)
  93. {
  94. if (comp->funcs && comp->funcs->config)
  95. comp->funcs->config(comp, w, h, vrefresh, bpc);
  96. }
  97. static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
  98. {
  99. if (comp->funcs && comp->funcs->start)
  100. comp->funcs->start(comp);
  101. }
  102. static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
  103. {
  104. if (comp->funcs && comp->funcs->stop)
  105. comp->funcs->stop(comp);
  106. }
  107. static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp,
  108. struct drm_crtc *crtc)
  109. {
  110. if (comp->funcs && comp->funcs->enable_vblank)
  111. comp->funcs->enable_vblank(comp, crtc);
  112. }
  113. static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
  114. {
  115. if (comp->funcs && comp->funcs->disable_vblank)
  116. comp->funcs->disable_vblank(comp);
  117. }
  118. static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
  119. {
  120. if (comp->funcs && comp->funcs->layer_nr)
  121. return comp->funcs->layer_nr(comp);
  122. return 0;
  123. }
  124. static inline void mtk_ddp_comp_layer_on(struct mtk_ddp_comp *comp,
  125. unsigned int idx)
  126. {
  127. if (comp->funcs && comp->funcs->layer_on)
  128. comp->funcs->layer_on(comp, idx);
  129. }
  130. static inline void mtk_ddp_comp_layer_off(struct mtk_ddp_comp *comp,
  131. unsigned int idx)
  132. {
  133. if (comp->funcs && comp->funcs->layer_off)
  134. comp->funcs->layer_off(comp, idx);
  135. }
  136. static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
  137. unsigned int idx,
  138. struct mtk_plane_state *state)
  139. {
  140. if (comp->funcs && comp->funcs->layer_config)
  141. comp->funcs->layer_config(comp, idx, state);
  142. }
  143. static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
  144. struct drm_crtc_state *state)
  145. {
  146. if (comp->funcs && comp->funcs->gamma_set)
  147. comp->funcs->gamma_set(comp, state);
  148. }
  149. int mtk_ddp_comp_get_id(struct device_node *node,
  150. enum mtk_ddp_comp_type comp_type);
  151. int mtk_ddp_comp_init(struct device *dev, struct device_node *comp_node,
  152. struct mtk_ddp_comp *comp, enum mtk_ddp_comp_id comp_id,
  153. const struct mtk_ddp_comp_funcs *funcs);
  154. int mtk_ddp_comp_register(struct drm_device *drm, struct mtk_ddp_comp *comp);
  155. void mtk_ddp_comp_unregister(struct drm_device *drm, struct mtk_ddp_comp *comp);
  156. void mtk_dither_set(struct mtk_ddp_comp *comp, unsigned int bpc,
  157. unsigned int CFG);
  158. #endif /* MTK_DRM_DDP_COMP_H */