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 void (*gamma_set)(struct device *dev,
71 struct drm_crtc_state *state);
72 void (*bgclr_in_on)(struct device *dev);
73 void (*bgclr_in_off)(struct device *dev);
74 void (*ctm_set)(struct device *dev,
75 struct drm_crtc_state *state);
76 struct device * (*dma_dev_get)(struct device *dev);
77 const u32 *(*get_formats)(struct device *dev);
78 size_t (*get_num_formats)(struct device *dev);
79 void (*connect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
80 void (*disconnect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
81 void (*add)(struct device *dev, struct mtk_mutex *mutex);
82 void (*remove)(struct device *dev, struct mtk_mutex *mutex);
89 const struct mtk_ddp_comp_funcs *funcs;
92 static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
94 if (comp->funcs && comp->funcs->clk_enable)
95 return comp->funcs->clk_enable(comp->dev);
100 static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
102 if (comp->funcs && comp->funcs->clk_disable)
103 comp->funcs->clk_disable(comp->dev);
106 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
107 unsigned int w, unsigned int h,
108 unsigned int vrefresh, unsigned int bpc,
109 struct cmdq_pkt *cmdq_pkt)
111 if (comp->funcs && comp->funcs->config)
112 comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
115 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
117 if (comp->funcs && comp->funcs->start)
118 comp->funcs->start(comp->dev);
121 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
123 if (comp->funcs && comp->funcs->stop)
124 comp->funcs->stop(comp->dev);
127 static inline void mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp *comp,
128 void (*vblank_cb)(void *),
129 void *vblank_cb_data)
131 if (comp->funcs && comp->funcs->register_vblank_cb)
132 comp->funcs->register_vblank_cb(comp->dev, vblank_cb,
136 static inline void mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp *comp)
138 if (comp->funcs && comp->funcs->unregister_vblank_cb)
139 comp->funcs->unregister_vblank_cb(comp->dev);
142 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp)
144 if (comp->funcs && comp->funcs->enable_vblank)
145 comp->funcs->enable_vblank(comp->dev);
148 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
150 if (comp->funcs && comp->funcs->disable_vblank)
151 comp->funcs->disable_vblank(comp->dev);
155 unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
157 if (comp->funcs && comp->funcs->supported_rotations)
158 return comp->funcs->supported_rotations(comp->dev);
163 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
165 if (comp->funcs && comp->funcs->layer_nr)
166 return comp->funcs->layer_nr(comp->dev);
171 static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
173 struct mtk_plane_state *state)
175 if (comp->funcs && comp->funcs->layer_check)
176 return comp->funcs->layer_check(comp->dev, idx, state);
180 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
182 struct mtk_plane_state *state,
183 struct cmdq_pkt *cmdq_pkt)
185 if (comp->funcs && comp->funcs->layer_config)
186 comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
189 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
190 struct drm_crtc_state *state)
192 if (comp->funcs && comp->funcs->gamma_set)
193 comp->funcs->gamma_set(comp->dev, state);
196 static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
198 if (comp->funcs && comp->funcs->bgclr_in_on)
199 comp->funcs->bgclr_in_on(comp->dev);
202 static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
204 if (comp->funcs && comp->funcs->bgclr_in_off)
205 comp->funcs->bgclr_in_off(comp->dev);
208 static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
209 struct drm_crtc_state *state)
211 if (comp->funcs && comp->funcs->ctm_set)
212 comp->funcs->ctm_set(comp->dev, state);
215 static inline struct device *mtk_ddp_comp_dma_dev_get(struct mtk_ddp_comp *comp)
217 if (comp->funcs && comp->funcs->dma_dev_get)
218 return comp->funcs->dma_dev_get(comp->dev);
223 const u32 *mtk_ddp_comp_get_formats(struct mtk_ddp_comp *comp)
225 if (comp->funcs && comp->funcs->get_formats)
226 return comp->funcs->get_formats(comp->dev);
232 size_t mtk_ddp_comp_get_num_formats(struct mtk_ddp_comp *comp)
234 if (comp->funcs && comp->funcs->get_num_formats)
235 return comp->funcs->get_num_formats(comp->dev);
240 static inline bool mtk_ddp_comp_add(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
242 if (comp->funcs && comp->funcs->add) {
243 comp->funcs->add(comp->dev, mutex);
249 static inline bool mtk_ddp_comp_remove(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
251 if (comp->funcs && comp->funcs->remove) {
252 comp->funcs->remove(comp->dev, mutex);
258 static inline bool mtk_ddp_comp_connect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
261 if (comp->funcs && comp->funcs->connect) {
262 comp->funcs->connect(comp->dev, mmsys_dev, next);
268 static inline bool mtk_ddp_comp_disconnect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
271 if (comp->funcs && comp->funcs->disconnect) {
272 comp->funcs->disconnect(comp->dev, mmsys_dev, next);
278 int mtk_ddp_comp_get_id(struct device_node *node,
279 enum mtk_ddp_comp_type comp_type);
280 unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
282 int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
283 unsigned int comp_id);
284 enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
285 void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
286 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
287 unsigned int offset);
288 void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
289 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
290 unsigned int offset);
291 void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
292 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
293 unsigned int offset, unsigned int mask);
294 #endif /* MTK_DRM_DDP_COMP_H */