1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (c) 2015 MediaTek Inc. 4 */ 5 6 #ifndef MTK_DDP_COMP_H 7 #define MTK_DDP_COMP_H 8 9 #include <linux/io.h> 10 #include <linux/pm_runtime.h> 11 #include <linux/soc/mediatek/mtk-cmdq.h> 12 #include <linux/soc/mediatek/mtk-mmsys.h> 13 #include <linux/soc/mediatek/mtk-mutex.h> 14 15 #include <drm/drm_modes.h> 16 17 struct device; 18 struct device_node; 19 struct drm_crtc; 20 struct drm_device; 21 struct mtk_plane_state; 22 struct drm_crtc_state; 23 24 enum mtk_ddp_comp_type { 25 MTK_DISP_AAL, 26 MTK_DISP_BLS, 27 MTK_DISP_CCORR, 28 MTK_DISP_COLOR, 29 MTK_DISP_DITHER, 30 MTK_DISP_DSC, 31 MTK_DISP_GAMMA, 32 MTK_DISP_MERGE, 33 MTK_DISP_MUTEX, 34 MTK_DISP_OD, 35 MTK_DISP_OVL, 36 MTK_DISP_OVL_2L, 37 MTK_DISP_OVL_ADAPTOR, 38 MTK_DISP_POSTMASK, 39 MTK_DISP_PWM, 40 MTK_DISP_RDMA, 41 MTK_DISP_UFOE, 42 MTK_DISP_WDMA, 43 MTK_DPI, 44 MTK_DP_INTF, 45 MTK_DSI, 46 MTK_DDP_COMP_TYPE_MAX, 47 }; 48 49 struct mtk_ddp_comp; 50 struct cmdq_pkt; 51 struct mtk_ddp_comp_funcs { 52 int (*power_on)(struct device *dev); 53 void (*power_off)(struct device *dev); 54 int (*clk_enable)(struct device *dev); 55 void (*clk_disable)(struct device *dev); 56 void (*config)(struct device *dev, unsigned int w, 57 unsigned int h, unsigned int vrefresh, 58 unsigned int bpc, struct cmdq_pkt *cmdq_pkt); 59 void (*start)(struct device *dev); 60 void (*stop)(struct device *dev); 61 void (*register_vblank_cb)(struct device *dev, 62 void (*vblank_cb)(void *), 63 void *vblank_cb_data); 64 void (*unregister_vblank_cb)(struct device *dev); 65 void (*enable_vblank)(struct device *dev); 66 void (*disable_vblank)(struct device *dev); 67 unsigned int (*supported_rotations)(struct device *dev); 68 unsigned int (*layer_nr)(struct device *dev); 69 int (*layer_check)(struct device *dev, 70 unsigned int idx, 71 struct mtk_plane_state *state); 72 void (*layer_config)(struct device *dev, unsigned int idx, 73 struct mtk_plane_state *state, 74 struct cmdq_pkt *cmdq_pkt); 75 unsigned int (*gamma_get_lut_size)(struct device *dev); 76 void (*gamma_set)(struct device *dev, 77 struct drm_crtc_state *state); 78 void (*bgclr_in_on)(struct device *dev); 79 void (*bgclr_in_off)(struct device *dev); 80 void (*ctm_set)(struct device *dev, 81 struct drm_crtc_state *state); 82 struct device * (*dma_dev_get)(struct device *dev); 83 const u32 *(*get_formats)(struct device *dev); 84 size_t (*get_num_formats)(struct device *dev); 85 void (*connect)(struct device *dev, struct device *mmsys_dev, unsigned int next); 86 void (*disconnect)(struct device *dev, struct device *mmsys_dev, unsigned int next); 87 void (*add)(struct device *dev, struct mtk_mutex *mutex); 88 void (*remove)(struct device *dev, struct mtk_mutex *mutex); 89 unsigned int (*encoder_index)(struct device *dev); 90 enum drm_mode_status (*mode_valid)(struct device *dev, const struct drm_display_mode *mode); 91 }; 92 93 struct mtk_ddp_comp { 94 struct device *dev; 95 int irq; 96 unsigned int id; 97 int encoder_index; 98 const struct mtk_ddp_comp_funcs *funcs; 99 }; 100 101 static inline int mtk_ddp_comp_power_on(struct mtk_ddp_comp *comp) 102 { 103 if (comp->funcs && comp->funcs->power_on) 104 return comp->funcs->power_on(comp->dev); 105 else 106 return pm_runtime_resume_and_get(comp->dev); 107 return 0; 108 } 109 110 static inline void mtk_ddp_comp_power_off(struct mtk_ddp_comp *comp) 111 { 112 if (comp->funcs && comp->funcs->power_off) 113 comp->funcs->power_off(comp->dev); 114 else 115 pm_runtime_put(comp->dev); 116 } 117 118 static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp) 119 { 120 if (comp->funcs && comp->funcs->clk_enable) 121 return comp->funcs->clk_enable(comp->dev); 122 123 return 0; 124 } 125 126 static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp) 127 { 128 if (comp->funcs && comp->funcs->clk_disable) 129 comp->funcs->clk_disable(comp->dev); 130 } 131 132 static inline 133 enum drm_mode_status mtk_ddp_comp_mode_valid(struct mtk_ddp_comp *comp, 134 const struct drm_display_mode *mode) 135 { 136 if (comp && comp->funcs && comp->funcs->mode_valid) 137 return comp->funcs->mode_valid(comp->dev, mode); 138 return MODE_OK; 139 } 140 141 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp, 142 unsigned int w, unsigned int h, 143 unsigned int vrefresh, unsigned int bpc, 144 struct cmdq_pkt *cmdq_pkt) 145 { 146 if (comp->funcs && comp->funcs->config) 147 comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt); 148 } 149 150 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp) 151 { 152 if (comp->funcs && comp->funcs->start) 153 comp->funcs->start(comp->dev); 154 } 155 156 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp) 157 { 158 if (comp->funcs && comp->funcs->stop) 159 comp->funcs->stop(comp->dev); 160 } 161 162 static inline void mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp *comp, 163 void (*vblank_cb)(void *), 164 void *vblank_cb_data) 165 { 166 if (comp->funcs && comp->funcs->register_vblank_cb) 167 comp->funcs->register_vblank_cb(comp->dev, vblank_cb, 168 vblank_cb_data); 169 } 170 171 static inline void mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp *comp) 172 { 173 if (comp->funcs && comp->funcs->unregister_vblank_cb) 174 comp->funcs->unregister_vblank_cb(comp->dev); 175 } 176 177 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp) 178 { 179 if (comp->funcs && comp->funcs->enable_vblank) 180 comp->funcs->enable_vblank(comp->dev); 181 } 182 183 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp) 184 { 185 if (comp->funcs && comp->funcs->disable_vblank) 186 comp->funcs->disable_vblank(comp->dev); 187 } 188 189 static inline 190 unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp) 191 { 192 if (comp->funcs && comp->funcs->supported_rotations) 193 return comp->funcs->supported_rotations(comp->dev); 194 195 /* 196 * In order to pass IGT tests, DRM_MODE_ROTATE_0 is required when 197 * rotation is not supported. 198 */ 199 return DRM_MODE_ROTATE_0; 200 } 201 202 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp) 203 { 204 if (comp->funcs && comp->funcs->layer_nr) 205 return comp->funcs->layer_nr(comp->dev); 206 207 return 0; 208 } 209 210 static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp, 211 unsigned int idx, 212 struct mtk_plane_state *state) 213 { 214 if (comp->funcs && comp->funcs->layer_check) 215 return comp->funcs->layer_check(comp->dev, idx, state); 216 return 0; 217 } 218 219 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp, 220 unsigned int idx, 221 struct mtk_plane_state *state, 222 struct cmdq_pkt *cmdq_pkt) 223 { 224 if (comp->funcs && comp->funcs->layer_config) 225 comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt); 226 } 227 228 static inline unsigned int mtk_ddp_gamma_get_lut_size(struct mtk_ddp_comp *comp) 229 { 230 if (comp->funcs && comp->funcs->gamma_get_lut_size) 231 return comp->funcs->gamma_get_lut_size(comp->dev); 232 233 return 0; 234 } 235 236 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp, 237 struct drm_crtc_state *state) 238 { 239 if (comp->funcs && comp->funcs->gamma_set) 240 comp->funcs->gamma_set(comp->dev, state); 241 } 242 243 static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp) 244 { 245 if (comp->funcs && comp->funcs->bgclr_in_on) 246 comp->funcs->bgclr_in_on(comp->dev); 247 } 248 249 static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp) 250 { 251 if (comp->funcs && comp->funcs->bgclr_in_off) 252 comp->funcs->bgclr_in_off(comp->dev); 253 } 254 255 static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp, 256 struct drm_crtc_state *state) 257 { 258 if (comp->funcs && comp->funcs->ctm_set) 259 comp->funcs->ctm_set(comp->dev, state); 260 } 261 262 static inline struct device *mtk_ddp_comp_dma_dev_get(struct mtk_ddp_comp *comp) 263 { 264 if (comp->funcs && comp->funcs->dma_dev_get) 265 return comp->funcs->dma_dev_get(comp->dev); 266 return comp->dev; 267 } 268 269 static inline 270 const u32 *mtk_ddp_comp_get_formats(struct mtk_ddp_comp *comp) 271 { 272 if (comp->funcs && comp->funcs->get_formats) 273 return comp->funcs->get_formats(comp->dev); 274 275 return NULL; 276 } 277 278 static inline 279 size_t mtk_ddp_comp_get_num_formats(struct mtk_ddp_comp *comp) 280 { 281 if (comp->funcs && comp->funcs->get_num_formats) 282 return comp->funcs->get_num_formats(comp->dev); 283 284 return 0; 285 } 286 287 static inline bool mtk_ddp_comp_add(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex) 288 { 289 if (comp->funcs && comp->funcs->add) { 290 comp->funcs->add(comp->dev, mutex); 291 return true; 292 } 293 return false; 294 } 295 296 static inline bool mtk_ddp_comp_remove(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex) 297 { 298 if (comp->funcs && comp->funcs->remove) { 299 comp->funcs->remove(comp->dev, mutex); 300 return true; 301 } 302 return false; 303 } 304 305 static inline bool mtk_ddp_comp_connect(struct mtk_ddp_comp *comp, struct device *mmsys_dev, 306 unsigned int next) 307 { 308 if (comp->funcs && comp->funcs->connect) { 309 comp->funcs->connect(comp->dev, mmsys_dev, next); 310 return true; 311 } 312 return false; 313 } 314 315 static inline bool mtk_ddp_comp_disconnect(struct mtk_ddp_comp *comp, struct device *mmsys_dev, 316 unsigned int next) 317 { 318 if (comp->funcs && comp->funcs->disconnect) { 319 comp->funcs->disconnect(comp->dev, mmsys_dev, next); 320 return true; 321 } 322 return false; 323 } 324 325 static inline void mtk_ddp_comp_encoder_index_set(struct mtk_ddp_comp *comp) 326 { 327 if (comp->funcs && comp->funcs->encoder_index) 328 comp->encoder_index = (int)comp->funcs->encoder_index(comp->dev); 329 } 330 331 int mtk_ddp_comp_get_id(struct device_node *node, 332 enum mtk_ddp_comp_type comp_type); 333 int mtk_find_possible_crtcs(struct drm_device *drm, struct device *dev); 334 int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp, 335 unsigned int comp_id); 336 enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id); 337 void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value, 338 struct cmdq_client_reg *cmdq_reg, void __iomem *regs, 339 unsigned int offset); 340 void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value, 341 struct cmdq_client_reg *cmdq_reg, void __iomem *regs, 342 unsigned int offset); 343 void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value, 344 struct cmdq_client_reg *cmdq_reg, void __iomem *regs, 345 unsigned int offset, unsigned int mask); 346 #endif /* MTK_DDP_COMP_H */ 347