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/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>
19 struct mtk_plane_state;
20 struct drm_crtc_state;
22 enum mtk_ddp_comp_type {
44 MTK_DDP_COMP_TYPE_MAX,
49 struct mtk_ddp_comp_funcs {
50 int (*power_on)(struct device *dev);
51 void (*power_off)(struct device *dev);
52 int (*clk_enable)(struct device *dev);
53 void (*clk_disable)(struct device *dev);
54 void (*config)(struct device *dev, unsigned int w,
55 unsigned int h, unsigned int vrefresh,
56 unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
57 void (*start)(struct device *dev);
58 void (*stop)(struct device *dev);
59 void (*register_vblank_cb)(struct device *dev,
60 void (*vblank_cb)(void *),
61 void *vblank_cb_data);
62 void (*unregister_vblank_cb)(struct device *dev);
63 void (*enable_vblank)(struct device *dev);
64 void (*disable_vblank)(struct device *dev);
65 unsigned int (*supported_rotations)(struct device *dev);
66 unsigned int (*layer_nr)(struct device *dev);
67 int (*layer_check)(struct device *dev,
69 struct mtk_plane_state *state);
70 void (*layer_config)(struct device *dev, unsigned int idx,
71 struct mtk_plane_state *state,
72 struct cmdq_pkt *cmdq_pkt);
73 unsigned int (*gamma_get_lut_size)(struct device *dev);
74 void (*gamma_set)(struct device *dev,
75 struct drm_crtc_state *state);
76 void (*bgclr_in_on)(struct device *dev);
77 void (*bgclr_in_off)(struct device *dev);
78 void (*ctm_set)(struct device *dev,
79 struct drm_crtc_state *state);
80 struct device * (*dma_dev_get)(struct device *dev);
81 const u32 *(*get_formats)(struct device *dev);
82 size_t (*get_num_formats)(struct device *dev);
83 void (*connect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
84 void (*disconnect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
85 void (*add)(struct device *dev, struct mtk_mutex *mutex);
86 void (*remove)(struct device *dev, struct mtk_mutex *mutex);
87 unsigned int (*encoder_index)(struct device *dev);
95 const struct mtk_ddp_comp_funcs *funcs;
98 static inline int mtk_ddp_comp_power_on(struct mtk_ddp_comp *comp)
100 if (comp->funcs && comp->funcs->power_on)
101 return comp->funcs->power_on(comp->dev);
103 return pm_runtime_resume_and_get(comp->dev);
107 static inline void mtk_ddp_comp_power_off(struct mtk_ddp_comp *comp)
109 if (comp->funcs && comp->funcs->power_off)
110 comp->funcs->power_off(comp->dev);
112 pm_runtime_put(comp->dev);
115 static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
117 if (comp->funcs && comp->funcs->clk_enable)
118 return comp->funcs->clk_enable(comp->dev);
123 static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
125 if (comp->funcs && comp->funcs->clk_disable)
126 comp->funcs->clk_disable(comp->dev);
129 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
130 unsigned int w, unsigned int h,
131 unsigned int vrefresh, unsigned int bpc,
132 struct cmdq_pkt *cmdq_pkt)
134 if (comp->funcs && comp->funcs->config)
135 comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
138 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
140 if (comp->funcs && comp->funcs->start)
141 comp->funcs->start(comp->dev);
144 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
146 if (comp->funcs && comp->funcs->stop)
147 comp->funcs->stop(comp->dev);
150 static inline void mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp *comp,
151 void (*vblank_cb)(void *),
152 void *vblank_cb_data)
154 if (comp->funcs && comp->funcs->register_vblank_cb)
155 comp->funcs->register_vblank_cb(comp->dev, vblank_cb,
159 static inline void mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp *comp)
161 if (comp->funcs && comp->funcs->unregister_vblank_cb)
162 comp->funcs->unregister_vblank_cb(comp->dev);
165 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp)
167 if (comp->funcs && comp->funcs->enable_vblank)
168 comp->funcs->enable_vblank(comp->dev);
171 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
173 if (comp->funcs && comp->funcs->disable_vblank)
174 comp->funcs->disable_vblank(comp->dev);
178 unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
180 if (comp->funcs && comp->funcs->supported_rotations)
181 return comp->funcs->supported_rotations(comp->dev);
186 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
188 if (comp->funcs && comp->funcs->layer_nr)
189 return comp->funcs->layer_nr(comp->dev);
194 static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
196 struct mtk_plane_state *state)
198 if (comp->funcs && comp->funcs->layer_check)
199 return comp->funcs->layer_check(comp->dev, idx, state);
203 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
205 struct mtk_plane_state *state,
206 struct cmdq_pkt *cmdq_pkt)
208 if (comp->funcs && comp->funcs->layer_config)
209 comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
212 static inline unsigned int mtk_ddp_gamma_get_lut_size(struct mtk_ddp_comp *comp)
214 if (comp->funcs && comp->funcs->gamma_get_lut_size)
215 return comp->funcs->gamma_get_lut_size(comp->dev);
220 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
221 struct drm_crtc_state *state)
223 if (comp->funcs && comp->funcs->gamma_set)
224 comp->funcs->gamma_set(comp->dev, state);
227 static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
229 if (comp->funcs && comp->funcs->bgclr_in_on)
230 comp->funcs->bgclr_in_on(comp->dev);
233 static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
235 if (comp->funcs && comp->funcs->bgclr_in_off)
236 comp->funcs->bgclr_in_off(comp->dev);
239 static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
240 struct drm_crtc_state *state)
242 if (comp->funcs && comp->funcs->ctm_set)
243 comp->funcs->ctm_set(comp->dev, state);
246 static inline struct device *mtk_ddp_comp_dma_dev_get(struct mtk_ddp_comp *comp)
248 if (comp->funcs && comp->funcs->dma_dev_get)
249 return comp->funcs->dma_dev_get(comp->dev);
254 const u32 *mtk_ddp_comp_get_formats(struct mtk_ddp_comp *comp)
256 if (comp->funcs && comp->funcs->get_formats)
257 return comp->funcs->get_formats(comp->dev);
263 size_t mtk_ddp_comp_get_num_formats(struct mtk_ddp_comp *comp)
265 if (comp->funcs && comp->funcs->get_num_formats)
266 return comp->funcs->get_num_formats(comp->dev);
271 static inline bool mtk_ddp_comp_add(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
273 if (comp->funcs && comp->funcs->add) {
274 comp->funcs->add(comp->dev, mutex);
280 static inline bool mtk_ddp_comp_remove(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
282 if (comp->funcs && comp->funcs->remove) {
283 comp->funcs->remove(comp->dev, mutex);
289 static inline bool mtk_ddp_comp_connect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
292 if (comp->funcs && comp->funcs->connect) {
293 comp->funcs->connect(comp->dev, mmsys_dev, next);
299 static inline bool mtk_ddp_comp_disconnect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
302 if (comp->funcs && comp->funcs->disconnect) {
303 comp->funcs->disconnect(comp->dev, mmsys_dev, next);
309 static inline void mtk_ddp_comp_encoder_index_set(struct mtk_ddp_comp *comp)
311 if (comp->funcs && comp->funcs->encoder_index)
312 comp->encoder_index = (int)comp->funcs->encoder_index(comp->dev);
315 int mtk_ddp_comp_get_id(struct device_node *node,
316 enum mtk_ddp_comp_type comp_type);
317 unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
319 int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
320 unsigned int comp_id);
321 enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
322 void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
323 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
324 unsigned int offset);
325 void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
326 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
327 unsigned int offset);
328 void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
329 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
330 unsigned int offset, unsigned int mask);
331 #endif /* MTK_DRM_DDP_COMP_H */