mtk_drm_ddp_comp.h 4.4 KB

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