1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (c) 2015 MediaTek Inc. 4 */ 5 6 #ifndef MTK_DRM_DDP_COMP_H 7 #define MTK_DRM_DDP_COMP_H 8 9 #include <linux/io.h> 10 11 struct device; 12 struct device_node; 13 struct drm_crtc; 14 struct drm_device; 15 struct mtk_plane_state; 16 struct drm_crtc_state; 17 18 enum mtk_ddp_comp_type { 19 MTK_DISP_OVL, 20 MTK_DISP_RDMA, 21 MTK_DISP_WDMA, 22 MTK_DISP_COLOR, 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 35 enum mtk_ddp_comp_id { 36 DDP_COMPONENT_AAL0, 37 DDP_COMPONENT_AAL1, 38 DDP_COMPONENT_BLS, 39 DDP_COMPONENT_COLOR0, 40 DDP_COMPONENT_COLOR1, 41 DDP_COMPONENT_DPI0, 42 DDP_COMPONENT_DPI1, 43 DDP_COMPONENT_DSI0, 44 DDP_COMPONENT_DSI1, 45 DDP_COMPONENT_DSI2, 46 DDP_COMPONENT_DSI3, 47 DDP_COMPONENT_GAMMA, 48 DDP_COMPONENT_OD0, 49 DDP_COMPONENT_OD1, 50 DDP_COMPONENT_OVL0, 51 DDP_COMPONENT_OVL1, 52 DDP_COMPONENT_PWM0, 53 DDP_COMPONENT_PWM1, 54 DDP_COMPONENT_PWM2, 55 DDP_COMPONENT_RDMA0, 56 DDP_COMPONENT_RDMA1, 57 DDP_COMPONENT_RDMA2, 58 DDP_COMPONENT_UFOE, 59 DDP_COMPONENT_WDMA0, 60 DDP_COMPONENT_WDMA1, 61 DDP_COMPONENT_ID_MAX, 62 }; 63 64 struct mtk_ddp_comp; 65 66 struct mtk_ddp_comp_funcs { 67 void (*config)(struct mtk_ddp_comp *comp, unsigned int w, 68 unsigned int h, unsigned int vrefresh, unsigned int bpc); 69 void (*start)(struct mtk_ddp_comp *comp); 70 void (*stop)(struct mtk_ddp_comp *comp); 71 void (*enable_vblank)(struct mtk_ddp_comp *comp, struct drm_crtc *crtc); 72 void (*disable_vblank)(struct mtk_ddp_comp *comp); 73 unsigned int (*layer_nr)(struct mtk_ddp_comp *comp); 74 void (*layer_on)(struct mtk_ddp_comp *comp, unsigned int idx); 75 void (*layer_off)(struct mtk_ddp_comp *comp, unsigned int idx); 76 void (*layer_config)(struct mtk_ddp_comp *comp, unsigned int idx, 77 struct mtk_plane_state *state); 78 void (*gamma_set)(struct mtk_ddp_comp *comp, 79 struct drm_crtc_state *state); 80 }; 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 91 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp, 92 unsigned int w, unsigned int h, 93 unsigned int vrefresh, unsigned int bpc) 94 { 95 if (comp->funcs && comp->funcs->config) 96 comp->funcs->config(comp, w, h, vrefresh, bpc); 97 } 98 99 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp) 100 { 101 if (comp->funcs && comp->funcs->start) 102 comp->funcs->start(comp); 103 } 104 105 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp) 106 { 107 if (comp->funcs && comp->funcs->stop) 108 comp->funcs->stop(comp); 109 } 110 111 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp, 112 struct drm_crtc *crtc) 113 { 114 if (comp->funcs && comp->funcs->enable_vblank) 115 comp->funcs->enable_vblank(comp, crtc); 116 } 117 118 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp) 119 { 120 if (comp->funcs && comp->funcs->disable_vblank) 121 comp->funcs->disable_vblank(comp); 122 } 123 124 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp) 125 { 126 if (comp->funcs && comp->funcs->layer_nr) 127 return comp->funcs->layer_nr(comp); 128 129 return 0; 130 } 131 132 static inline void mtk_ddp_comp_layer_on(struct mtk_ddp_comp *comp, 133 unsigned int idx) 134 { 135 if (comp->funcs && comp->funcs->layer_on) 136 comp->funcs->layer_on(comp, idx); 137 } 138 139 static inline void mtk_ddp_comp_layer_off(struct mtk_ddp_comp *comp, 140 unsigned int idx) 141 { 142 if (comp->funcs && comp->funcs->layer_off) 143 comp->funcs->layer_off(comp, idx); 144 } 145 146 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp, 147 unsigned int idx, 148 struct mtk_plane_state *state) 149 { 150 if (comp->funcs && comp->funcs->layer_config) 151 comp->funcs->layer_config(comp, idx, state); 152 } 153 154 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp, 155 struct drm_crtc_state *state) 156 { 157 if (comp->funcs && comp->funcs->gamma_set) 158 comp->funcs->gamma_set(comp, state); 159 } 160 161 int mtk_ddp_comp_get_id(struct device_node *node, 162 enum mtk_ddp_comp_type comp_type); 163 int mtk_ddp_comp_init(struct device *dev, struct device_node *comp_node, 164 struct mtk_ddp_comp *comp, enum mtk_ddp_comp_id comp_id, 165 const struct mtk_ddp_comp_funcs *funcs); 166 int mtk_ddp_comp_register(struct drm_device *drm, struct mtk_ddp_comp *comp); 167 void mtk_ddp_comp_unregister(struct drm_device *drm, struct mtk_ddp_comp *comp); 168 void mtk_dither_set(struct mtk_ddp_comp *comp, unsigned int bpc, 169 unsigned int CFG); 170 171 #endif /* MTK_DRM_DDP_COMP_H */ 172