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_OVL_2L, 21 MTK_DISP_RDMA, 22 MTK_DISP_WDMA, 23 MTK_DISP_COLOR, 24 MTK_DISP_CCORR, 25 MTK_DISP_DITHER, 26 MTK_DISP_AAL, 27 MTK_DISP_GAMMA, 28 MTK_DISP_UFOE, 29 MTK_DSI, 30 MTK_DPI, 31 MTK_DISP_PWM, 32 MTK_DISP_MUTEX, 33 MTK_DISP_OD, 34 MTK_DISP_BLS, 35 MTK_DDP_COMP_TYPE_MAX, 36 }; 37 38 enum mtk_ddp_comp_id { 39 DDP_COMPONENT_AAL0, 40 DDP_COMPONENT_AAL1, 41 DDP_COMPONENT_BLS, 42 DDP_COMPONENT_CCORR, 43 DDP_COMPONENT_COLOR0, 44 DDP_COMPONENT_COLOR1, 45 DDP_COMPONENT_DITHER, 46 DDP_COMPONENT_DPI0, 47 DDP_COMPONENT_DPI1, 48 DDP_COMPONENT_DSI0, 49 DDP_COMPONENT_DSI1, 50 DDP_COMPONENT_DSI2, 51 DDP_COMPONENT_DSI3, 52 DDP_COMPONENT_GAMMA, 53 DDP_COMPONENT_OD0, 54 DDP_COMPONENT_OD1, 55 DDP_COMPONENT_OVL0, 56 DDP_COMPONENT_OVL_2L0, 57 DDP_COMPONENT_OVL_2L1, 58 DDP_COMPONENT_OVL1, 59 DDP_COMPONENT_PWM0, 60 DDP_COMPONENT_PWM1, 61 DDP_COMPONENT_PWM2, 62 DDP_COMPONENT_RDMA0, 63 DDP_COMPONENT_RDMA1, 64 DDP_COMPONENT_RDMA2, 65 DDP_COMPONENT_UFOE, 66 DDP_COMPONENT_WDMA0, 67 DDP_COMPONENT_WDMA1, 68 DDP_COMPONENT_ID_MAX, 69 }; 70 71 struct mtk_ddp_comp; 72 73 struct mtk_ddp_comp_funcs { 74 void (*config)(struct mtk_ddp_comp *comp, unsigned int w, 75 unsigned int h, unsigned int vrefresh, unsigned int bpc); 76 void (*start)(struct mtk_ddp_comp *comp); 77 void (*stop)(struct mtk_ddp_comp *comp); 78 void (*enable_vblank)(struct mtk_ddp_comp *comp, struct drm_crtc *crtc); 79 void (*disable_vblank)(struct mtk_ddp_comp *comp); 80 unsigned int (*layer_nr)(struct mtk_ddp_comp *comp); 81 void (*layer_on)(struct mtk_ddp_comp *comp, unsigned int idx); 82 void (*layer_off)(struct mtk_ddp_comp *comp, unsigned int idx); 83 void (*layer_config)(struct mtk_ddp_comp *comp, unsigned int idx, 84 struct mtk_plane_state *state); 85 void (*gamma_set)(struct mtk_ddp_comp *comp, 86 struct drm_crtc_state *state); 87 void (*bgclr_in_on)(struct mtk_ddp_comp *comp); 88 void (*bgclr_in_off)(struct mtk_ddp_comp *comp); 89 }; 90 91 struct mtk_ddp_comp { 92 struct clk *clk; 93 void __iomem *regs; 94 int irq; 95 struct device *larb_dev; 96 enum mtk_ddp_comp_id id; 97 const struct mtk_ddp_comp_funcs *funcs; 98 }; 99 100 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp, 101 unsigned int w, unsigned int h, 102 unsigned int vrefresh, unsigned int bpc) 103 { 104 if (comp->funcs && comp->funcs->config) 105 comp->funcs->config(comp, w, h, vrefresh, bpc); 106 } 107 108 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp) 109 { 110 if (comp->funcs && comp->funcs->start) 111 comp->funcs->start(comp); 112 } 113 114 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp) 115 { 116 if (comp->funcs && comp->funcs->stop) 117 comp->funcs->stop(comp); 118 } 119 120 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp, 121 struct drm_crtc *crtc) 122 { 123 if (comp->funcs && comp->funcs->enable_vblank) 124 comp->funcs->enable_vblank(comp, crtc); 125 } 126 127 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp) 128 { 129 if (comp->funcs && comp->funcs->disable_vblank) 130 comp->funcs->disable_vblank(comp); 131 } 132 133 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp) 134 { 135 if (comp->funcs && comp->funcs->layer_nr) 136 return comp->funcs->layer_nr(comp); 137 138 return 0; 139 } 140 141 static inline void mtk_ddp_comp_layer_on(struct mtk_ddp_comp *comp, 142 unsigned int idx) 143 { 144 if (comp->funcs && comp->funcs->layer_on) 145 comp->funcs->layer_on(comp, idx); 146 } 147 148 static inline void mtk_ddp_comp_layer_off(struct mtk_ddp_comp *comp, 149 unsigned int idx) 150 { 151 if (comp->funcs && comp->funcs->layer_off) 152 comp->funcs->layer_off(comp, idx); 153 } 154 155 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp, 156 unsigned int idx, 157 struct mtk_plane_state *state) 158 { 159 if (comp->funcs && comp->funcs->layer_config) 160 comp->funcs->layer_config(comp, idx, state); 161 } 162 163 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp, 164 struct drm_crtc_state *state) 165 { 166 if (comp->funcs && comp->funcs->gamma_set) 167 comp->funcs->gamma_set(comp, state); 168 } 169 170 static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp) 171 { 172 if (comp->funcs && comp->funcs->bgclr_in_on) 173 comp->funcs->bgclr_in_on(comp); 174 } 175 176 static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp) 177 { 178 if (comp->funcs && comp->funcs->bgclr_in_off) 179 comp->funcs->bgclr_in_off(comp); 180 } 181 182 int mtk_ddp_comp_get_id(struct device_node *node, 183 enum mtk_ddp_comp_type comp_type); 184 int mtk_ddp_comp_init(struct device *dev, struct device_node *comp_node, 185 struct mtk_ddp_comp *comp, enum mtk_ddp_comp_id comp_id, 186 const struct mtk_ddp_comp_funcs *funcs); 187 int mtk_ddp_comp_register(struct drm_device *drm, struct mtk_ddp_comp *comp); 188 void mtk_ddp_comp_unregister(struct drm_device *drm, struct mtk_ddp_comp *comp); 189 void mtk_dither_set(struct mtk_ddp_comp *comp, unsigned int bpc, 190 unsigned int CFG); 191 192 #endif /* MTK_DRM_DDP_COMP_H */ 193