1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2015 MediaTek Inc.
6 #ifndef MTK_DRM_DDP_COMP_H
7 #define MTK_DRM_DDP_COMP_H
10 #include <linux/soc/mediatek/mtk-cmdq.h>
11 #include <linux/soc/mediatek/mtk-mmsys.h>
12 #include <linux/soc/mediatek/mtk-mutex.h>
18 struct mtk_plane_state;
19 struct drm_crtc_state;
21 enum mtk_ddp_comp_type {
43 MTK_DDP_COMP_TYPE_MAX,
48 struct mtk_ddp_comp_funcs {
49 int (*clk_enable)(struct device *dev);
50 void (*clk_disable)(struct device *dev);
51 void (*config)(struct device *dev, unsigned int w,
52 unsigned int h, unsigned int vrefresh,
53 unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
54 void (*start)(struct device *dev);
55 void (*stop)(struct device *dev);
56 void (*register_vblank_cb)(struct device *dev,
57 void (*vblank_cb)(void *),
58 void *vblank_cb_data);
59 void (*unregister_vblank_cb)(struct device *dev);
60 void (*enable_vblank)(struct device *dev);
61 void (*disable_vblank)(struct device *dev);
62 unsigned int (*supported_rotations)(struct device *dev);
63 unsigned int (*layer_nr)(struct device *dev);
64 int (*layer_check)(struct device *dev,
66 struct mtk_plane_state *state);
67 void (*layer_config)(struct device *dev, unsigned int idx,
68 struct mtk_plane_state *state,
69 struct cmdq_pkt *cmdq_pkt);
70 unsigned int (*gamma_get_lut_size)(struct device *dev);
71 void (*gamma_set)(struct device *dev,
72 struct drm_crtc_state *state);
73 void (*bgclr_in_on)(struct device *dev);
74 void (*bgclr_in_off)(struct device *dev);
75 void (*ctm_set)(struct device *dev,
76 struct drm_crtc_state *state);
77 struct device * (*dma_dev_get)(struct device *dev);
78 const u32 *(*get_formats)(struct device *dev);
79 size_t (*get_num_formats)(struct device *dev);
80 void (*connect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
81 void (*disconnect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
82 void (*add)(struct device *dev, struct mtk_mutex *mutex);
83 void (*remove)(struct device *dev, struct mtk_mutex *mutex);
84 unsigned int (*encoder_index)(struct device *dev);
92 const struct mtk_ddp_comp_funcs *funcs;
95 static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
97 if (comp->funcs && comp->funcs->clk_enable)
98 return comp->funcs->clk_enable(comp->dev);
103 static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
105 if (comp->funcs && comp->funcs->clk_disable)
106 comp->funcs->clk_disable(comp->dev);
109 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
110 unsigned int w, unsigned int h,
111 unsigned int vrefresh, unsigned int bpc,
112 struct cmdq_pkt *cmdq_pkt)
114 if (comp->funcs && comp->funcs->config)
115 comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
118 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
120 if (comp->funcs && comp->funcs->start)
121 comp->funcs->start(comp->dev);
124 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
126 if (comp->funcs && comp->funcs->stop)
127 comp->funcs->stop(comp->dev);
130 static inline void mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp *comp,
131 void (*vblank_cb)(void *),
132 void *vblank_cb_data)
134 if (comp->funcs && comp->funcs->register_vblank_cb)
135 comp->funcs->register_vblank_cb(comp->dev, vblank_cb,
139 static inline void mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp *comp)
141 if (comp->funcs && comp->funcs->unregister_vblank_cb)
142 comp->funcs->unregister_vblank_cb(comp->dev);
145 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp)
147 if (comp->funcs && comp->funcs->enable_vblank)
148 comp->funcs->enable_vblank(comp->dev);
151 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
153 if (comp->funcs && comp->funcs->disable_vblank)
154 comp->funcs->disable_vblank(comp->dev);
158 unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
160 if (comp->funcs && comp->funcs->supported_rotations)
161 return comp->funcs->supported_rotations(comp->dev);
166 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
168 if (comp->funcs && comp->funcs->layer_nr)
169 return comp->funcs->layer_nr(comp->dev);
174 static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
176 struct mtk_plane_state *state)
178 if (comp->funcs && comp->funcs->layer_check)
179 return comp->funcs->layer_check(comp->dev, idx, state);
183 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
185 struct mtk_plane_state *state,
186 struct cmdq_pkt *cmdq_pkt)
188 if (comp->funcs && comp->funcs->layer_config)
189 comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
192 static inline unsigned int mtk_ddp_gamma_get_lut_size(struct mtk_ddp_comp *comp)
194 if (comp->funcs && comp->funcs->gamma_get_lut_size)
195 return comp->funcs->gamma_get_lut_size(comp->dev);
200 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
201 struct drm_crtc_state *state)
203 if (comp->funcs && comp->funcs->gamma_set)
204 comp->funcs->gamma_set(comp->dev, state);
207 static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
209 if (comp->funcs && comp->funcs->bgclr_in_on)
210 comp->funcs->bgclr_in_on(comp->dev);
213 static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
215 if (comp->funcs && comp->funcs->bgclr_in_off)
216 comp->funcs->bgclr_in_off(comp->dev);
219 static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
220 struct drm_crtc_state *state)
222 if (comp->funcs && comp->funcs->ctm_set)
223 comp->funcs->ctm_set(comp->dev, state);
226 static inline struct device *mtk_ddp_comp_dma_dev_get(struct mtk_ddp_comp *comp)
228 if (comp->funcs && comp->funcs->dma_dev_get)
229 return comp->funcs->dma_dev_get(comp->dev);
234 const u32 *mtk_ddp_comp_get_formats(struct mtk_ddp_comp *comp)
236 if (comp->funcs && comp->funcs->get_formats)
237 return comp->funcs->get_formats(comp->dev);
243 size_t mtk_ddp_comp_get_num_formats(struct mtk_ddp_comp *comp)
245 if (comp->funcs && comp->funcs->get_num_formats)
246 return comp->funcs->get_num_formats(comp->dev);
251 static inline bool mtk_ddp_comp_add(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
253 if (comp->funcs && comp->funcs->add) {
254 comp->funcs->add(comp->dev, mutex);
260 static inline bool mtk_ddp_comp_remove(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
262 if (comp->funcs && comp->funcs->remove) {
263 comp->funcs->remove(comp->dev, mutex);
269 static inline bool mtk_ddp_comp_connect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
272 if (comp->funcs && comp->funcs->connect) {
273 comp->funcs->connect(comp->dev, mmsys_dev, next);
279 static inline bool mtk_ddp_comp_disconnect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
282 if (comp->funcs && comp->funcs->disconnect) {
283 comp->funcs->disconnect(comp->dev, mmsys_dev, next);
289 static inline void mtk_ddp_comp_encoder_index_set(struct mtk_ddp_comp *comp)
291 if (comp->funcs && comp->funcs->encoder_index)
292 comp->encoder_index = (int)comp->funcs->encoder_index(comp->dev);
295 int mtk_ddp_comp_get_id(struct device_node *node,
296 enum mtk_ddp_comp_type comp_type);
297 unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
299 int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
300 unsigned int comp_id);
301 enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
302 void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
303 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
304 unsigned int offset);
305 void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
306 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
307 unsigned int offset);
308 void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
309 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
310 unsigned int offset, unsigned int mask);
311 #endif /* MTK_DRM_DDP_COMP_H */