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 {
37 MTK_DDP_COMP_TYPE_MAX,
42 struct mtk_ddp_comp_funcs {
43 int (*clk_enable)(struct device *dev);
44 void (*clk_disable)(struct device *dev);
45 void (*config)(struct device *dev, unsigned int w,
46 unsigned int h, unsigned int vrefresh,
47 unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
48 void (*start)(struct device *dev);
49 void (*stop)(struct device *dev);
50 void (*enable_vblank)(struct device *dev,
51 void (*vblank_cb)(void *),
52 void *vblank_cb_data);
53 void (*disable_vblank)(struct device *dev);
54 unsigned int (*supported_rotations)(struct device *dev);
55 unsigned int (*layer_nr)(struct device *dev);
56 int (*layer_check)(struct device *dev,
58 struct mtk_plane_state *state);
59 void (*layer_config)(struct device *dev, unsigned int idx,
60 struct mtk_plane_state *state,
61 struct cmdq_pkt *cmdq_pkt);
62 void (*gamma_set)(struct device *dev,
63 struct drm_crtc_state *state);
64 void (*bgclr_in_on)(struct device *dev);
65 void (*bgclr_in_off)(struct device *dev);
66 void (*ctm_set)(struct device *dev,
67 struct drm_crtc_state *state);
73 struct device *larb_dev;
74 enum mtk_ddp_comp_id id;
75 const struct mtk_ddp_comp_funcs *funcs;
78 static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
80 if (comp->funcs && comp->funcs->clk_enable)
81 return comp->funcs->clk_enable(comp->dev);
86 static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
88 if (comp->funcs && comp->funcs->clk_disable)
89 comp->funcs->clk_disable(comp->dev);
92 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
93 unsigned int w, unsigned int h,
94 unsigned int vrefresh, unsigned int bpc,
95 struct cmdq_pkt *cmdq_pkt)
97 if (comp->funcs && comp->funcs->config)
98 comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
101 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
103 if (comp->funcs && comp->funcs->start)
104 comp->funcs->start(comp->dev);
107 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
109 if (comp->funcs && comp->funcs->stop)
110 comp->funcs->stop(comp->dev);
113 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp,
114 void (*vblank_cb)(void *),
115 void *vblank_cb_data)
117 if (comp->funcs && comp->funcs->enable_vblank)
118 comp->funcs->enable_vblank(comp->dev, vblank_cb, vblank_cb_data);
121 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
123 if (comp->funcs && comp->funcs->disable_vblank)
124 comp->funcs->disable_vblank(comp->dev);
128 unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
130 if (comp->funcs && comp->funcs->supported_rotations)
131 return comp->funcs->supported_rotations(comp->dev);
136 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
138 if (comp->funcs && comp->funcs->layer_nr)
139 return comp->funcs->layer_nr(comp->dev);
144 static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
146 struct mtk_plane_state *state)
148 if (comp->funcs && comp->funcs->layer_check)
149 return comp->funcs->layer_check(comp->dev, idx, state);
153 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
155 struct mtk_plane_state *state,
156 struct cmdq_pkt *cmdq_pkt)
158 if (comp->funcs && comp->funcs->layer_config)
159 comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
162 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
163 struct drm_crtc_state *state)
165 if (comp->funcs && comp->funcs->gamma_set)
166 comp->funcs->gamma_set(comp->dev, state);
169 static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
171 if (comp->funcs && comp->funcs->bgclr_in_on)
172 comp->funcs->bgclr_in_on(comp->dev);
175 static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
177 if (comp->funcs && comp->funcs->bgclr_in_off)
178 comp->funcs->bgclr_in_off(comp->dev);
181 static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
182 struct drm_crtc_state *state)
184 if (comp->funcs && comp->funcs->ctm_set)
185 comp->funcs->ctm_set(comp->dev, state);
188 int mtk_ddp_comp_get_id(struct device_node *node,
189 enum mtk_ddp_comp_type comp_type);
190 unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
192 int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
193 enum mtk_ddp_comp_id comp_id);
194 enum mtk_ddp_comp_type mtk_ddp_comp_get_type(enum mtk_ddp_comp_id comp_id);
195 void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
196 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
197 unsigned int offset);
198 void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
199 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
200 unsigned int offset);
201 void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
202 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
203 unsigned int offset, unsigned int mask);
204 #endif /* MTK_DRM_DDP_COMP_H */