mtk_drm_ddp_comp.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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_AAL,
  40. DDP_COMPONENT_BLS,
  41. DDP_COMPONENT_COLOR0,
  42. DDP_COMPONENT_COLOR1,
  43. DDP_COMPONENT_DPI0,
  44. DDP_COMPONENT_DSI0,
  45. DDP_COMPONENT_DSI1,
  46. DDP_COMPONENT_GAMMA,
  47. DDP_COMPONENT_OD,
  48. DDP_COMPONENT_OVL0,
  49. DDP_COMPONENT_OVL1,
  50. DDP_COMPONENT_PWM0,
  51. DDP_COMPONENT_PWM1,
  52. DDP_COMPONENT_RDMA0,
  53. DDP_COMPONENT_RDMA1,
  54. DDP_COMPONENT_RDMA2,
  55. DDP_COMPONENT_UFOE,
  56. DDP_COMPONENT_WDMA0,
  57. DDP_COMPONENT_WDMA1,
  58. DDP_COMPONENT_ID_MAX,
  59. };
  60. struct mtk_ddp_comp;
  61. struct mtk_ddp_comp_funcs {
  62. void (*config)(struct mtk_ddp_comp *comp, unsigned int w,
  63. unsigned int h, unsigned int vrefresh, unsigned int bpc);
  64. void (*start)(struct mtk_ddp_comp *comp);
  65. void (*stop)(struct mtk_ddp_comp *comp);
  66. void (*enable_vblank)(struct mtk_ddp_comp *comp, struct drm_crtc *crtc);
  67. void (*disable_vblank)(struct mtk_ddp_comp *comp);
  68. void (*layer_on)(struct mtk_ddp_comp *comp, unsigned int idx);
  69. void (*layer_off)(struct mtk_ddp_comp *comp, unsigned int idx);
  70. void (*layer_config)(struct mtk_ddp_comp *comp, unsigned int idx,
  71. struct mtk_plane_state *state);
  72. void (*gamma_set)(struct mtk_ddp_comp *comp,
  73. struct drm_crtc_state *state);
  74. };
  75. struct mtk_ddp_comp {
  76. struct clk *clk;
  77. void __iomem *regs;
  78. int irq;
  79. struct device *larb_dev;
  80. enum mtk_ddp_comp_id id;
  81. const struct mtk_ddp_comp_funcs *funcs;
  82. };
  83. static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
  84. unsigned int w, unsigned int h,
  85. unsigned int vrefresh, unsigned int bpc)
  86. {
  87. if (comp->funcs && comp->funcs->config)
  88. comp->funcs->config(comp, w, h, vrefresh, bpc);
  89. }
  90. static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
  91. {
  92. if (comp->funcs && comp->funcs->start)
  93. comp->funcs->start(comp);
  94. }
  95. static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
  96. {
  97. if (comp->funcs && comp->funcs->stop)
  98. comp->funcs->stop(comp);
  99. }
  100. static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp,
  101. struct drm_crtc *crtc)
  102. {
  103. if (comp->funcs && comp->funcs->enable_vblank)
  104. comp->funcs->enable_vblank(comp, crtc);
  105. }
  106. static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
  107. {
  108. if (comp->funcs && comp->funcs->disable_vblank)
  109. comp->funcs->disable_vblank(comp);
  110. }
  111. static inline void mtk_ddp_comp_layer_on(struct mtk_ddp_comp *comp,
  112. unsigned int idx)
  113. {
  114. if (comp->funcs && comp->funcs->layer_on)
  115. comp->funcs->layer_on(comp, idx);
  116. }
  117. static inline void mtk_ddp_comp_layer_off(struct mtk_ddp_comp *comp,
  118. unsigned int idx)
  119. {
  120. if (comp->funcs && comp->funcs->layer_off)
  121. comp->funcs->layer_off(comp, idx);
  122. }
  123. static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
  124. unsigned int idx,
  125. struct mtk_plane_state *state)
  126. {
  127. if (comp->funcs && comp->funcs->layer_config)
  128. comp->funcs->layer_config(comp, idx, state);
  129. }
  130. static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
  131. struct drm_crtc_state *state)
  132. {
  133. if (comp->funcs && comp->funcs->gamma_set)
  134. comp->funcs->gamma_set(comp, state);
  135. }
  136. int mtk_ddp_comp_get_id(struct device_node *node,
  137. enum mtk_ddp_comp_type comp_type);
  138. int mtk_ddp_comp_init(struct device *dev, struct device_node *comp_node,
  139. struct mtk_ddp_comp *comp, enum mtk_ddp_comp_id comp_id,
  140. const struct mtk_ddp_comp_funcs *funcs);
  141. int mtk_ddp_comp_register(struct drm_device *drm, struct mtk_ddp_comp *comp);
  142. void mtk_ddp_comp_unregister(struct drm_device *drm, struct mtk_ddp_comp *comp);
  143. void mtk_dither_set(struct mtk_ddp_comp *comp, unsigned int bpc,
  144. unsigned int CFG);
  145. #endif /* MTK_DRM_DDP_COMP_H */