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>
17 struct mtk_plane_state;
18 struct drm_crtc_state;
20 enum mtk_ddp_comp_type {
38 MTK_DDP_COMP_TYPE_MAX,
43 struct mtk_ddp_comp_funcs {
44 int (*clk_enable)(struct device *dev);
45 void (*clk_disable)(struct device *dev);
46 void (*config)(struct device *dev, unsigned int w,
47 unsigned int h, unsigned int vrefresh,
48 unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
49 void (*start)(struct device *dev);
50 void (*stop)(struct device *dev);
51 void (*register_vblank_cb)(struct device *dev,
52 void (*vblank_cb)(void *),
53 void *vblank_cb_data);
54 void (*unregister_vblank_cb)(struct device *dev);
55 void (*enable_vblank)(struct device *dev);
56 void (*disable_vblank)(struct device *dev);
57 unsigned int (*supported_rotations)(struct device *dev);
58 unsigned int (*layer_nr)(struct device *dev);
59 int (*layer_check)(struct device *dev,
61 struct mtk_plane_state *state);
62 void (*layer_config)(struct device *dev, unsigned int idx,
63 struct mtk_plane_state *state,
64 struct cmdq_pkt *cmdq_pkt);
65 void (*gamma_set)(struct device *dev,
66 struct drm_crtc_state *state);
67 void (*bgclr_in_on)(struct device *dev);
68 void (*bgclr_in_off)(struct device *dev);
69 void (*ctm_set)(struct device *dev,
70 struct drm_crtc_state *state);
76 enum mtk_ddp_comp_id id;
77 const struct mtk_ddp_comp_funcs *funcs;
80 static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
82 if (comp->funcs && comp->funcs->clk_enable)
83 return comp->funcs->clk_enable(comp->dev);
88 static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
90 if (comp->funcs && comp->funcs->clk_disable)
91 comp->funcs->clk_disable(comp->dev);
94 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
95 unsigned int w, unsigned int h,
96 unsigned int vrefresh, unsigned int bpc,
97 struct cmdq_pkt *cmdq_pkt)
99 if (comp->funcs && comp->funcs->config)
100 comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
103 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
105 if (comp->funcs && comp->funcs->start)
106 comp->funcs->start(comp->dev);
109 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
111 if (comp->funcs && comp->funcs->stop)
112 comp->funcs->stop(comp->dev);
115 static inline void mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp *comp,
116 void (*vblank_cb)(void *),
117 void *vblank_cb_data)
119 if (comp->funcs && comp->funcs->register_vblank_cb)
120 comp->funcs->register_vblank_cb(comp->dev, vblank_cb,
124 static inline void mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp *comp)
126 if (comp->funcs && comp->funcs->unregister_vblank_cb)
127 comp->funcs->unregister_vblank_cb(comp->dev);
130 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp)
132 if (comp->funcs && comp->funcs->enable_vblank)
133 comp->funcs->enable_vblank(comp->dev);
136 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
138 if (comp->funcs && comp->funcs->disable_vblank)
139 comp->funcs->disable_vblank(comp->dev);
143 unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
145 if (comp->funcs && comp->funcs->supported_rotations)
146 return comp->funcs->supported_rotations(comp->dev);
151 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
153 if (comp->funcs && comp->funcs->layer_nr)
154 return comp->funcs->layer_nr(comp->dev);
159 static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
161 struct mtk_plane_state *state)
163 if (comp->funcs && comp->funcs->layer_check)
164 return comp->funcs->layer_check(comp->dev, idx, state);
168 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
170 struct mtk_plane_state *state,
171 struct cmdq_pkt *cmdq_pkt)
173 if (comp->funcs && comp->funcs->layer_config)
174 comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
177 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
178 struct drm_crtc_state *state)
180 if (comp->funcs && comp->funcs->gamma_set)
181 comp->funcs->gamma_set(comp->dev, state);
184 static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
186 if (comp->funcs && comp->funcs->bgclr_in_on)
187 comp->funcs->bgclr_in_on(comp->dev);
190 static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
192 if (comp->funcs && comp->funcs->bgclr_in_off)
193 comp->funcs->bgclr_in_off(comp->dev);
196 static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
197 struct drm_crtc_state *state)
199 if (comp->funcs && comp->funcs->ctm_set)
200 comp->funcs->ctm_set(comp->dev, state);
203 int mtk_ddp_comp_get_id(struct device_node *node,
204 enum mtk_ddp_comp_type comp_type);
205 unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
207 int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
208 enum mtk_ddp_comp_id comp_id);
209 enum mtk_ddp_comp_type mtk_ddp_comp_get_type(enum mtk_ddp_comp_id comp_id);
210 void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
211 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
212 unsigned int offset);
213 void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
214 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
215 unsigned int offset);
216 void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
217 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
218 unsigned int offset, unsigned int mask);
219 #endif /* MTK_DRM_DDP_COMP_H */