1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2015 MediaTek Inc.
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>
15 #include <drm/drm_modes.h>
21 struct mtk_plane_state;
22 struct drm_crtc_state;
24 enum mtk_ddp_comp_type {
46 MTK_DDP_COMP_TYPE_MAX,
51 struct mtk_ddp_comp_funcs {
52 int (*power_on)(struct device *dev);
53 void (*power_off)(struct device *dev);
54 int (*clk_enable)(struct device *dev);
55 void (*clk_disable)(struct device *dev);
56 void (*config)(struct device *dev, unsigned int w,
57 unsigned int h, unsigned int vrefresh,
58 unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
59 void (*start)(struct device *dev);
60 void (*stop)(struct device *dev);
61 void (*register_vblank_cb)(struct device *dev,
62 void (*vblank_cb)(void *),
63 void *vblank_cb_data);
64 void (*unregister_vblank_cb)(struct device *dev);
65 void (*enable_vblank)(struct device *dev);
66 void (*disable_vblank)(struct device *dev);
67 unsigned int (*supported_rotations)(struct device *dev);
68 unsigned int (*layer_nr)(struct device *dev);
69 int (*layer_check)(struct device *dev,
71 struct mtk_plane_state *state);
72 void (*layer_config)(struct device *dev, unsigned int idx,
73 struct mtk_plane_state *state,
74 struct cmdq_pkt *cmdq_pkt);
75 unsigned int (*gamma_get_lut_size)(struct device *dev);
76 void (*gamma_set)(struct device *dev,
77 struct drm_crtc_state *state);
78 void (*bgclr_in_on)(struct device *dev);
79 void (*bgclr_in_off)(struct device *dev);
80 void (*ctm_set)(struct device *dev,
81 struct drm_crtc_state *state);
82 struct device * (*dma_dev_get)(struct device *dev);
83 const u32 *(*get_formats)(struct device *dev);
84 size_t (*get_num_formats)(struct device *dev);
85 void (*connect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
86 void (*disconnect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
87 void (*add)(struct device *dev, struct mtk_mutex *mutex);
88 void (*remove)(struct device *dev, struct mtk_mutex *mutex);
89 unsigned int (*encoder_index)(struct device *dev);
90 enum drm_mode_status (*mode_valid)(struct device *dev, const struct drm_display_mode *mode);
98 const struct mtk_ddp_comp_funcs *funcs;
101 static inline int mtk_ddp_comp_power_on(struct mtk_ddp_comp *comp)
103 if (comp->funcs && comp->funcs->power_on)
104 return comp->funcs->power_on(comp->dev);
106 return pm_runtime_resume_and_get(comp->dev);
110 static inline void mtk_ddp_comp_power_off(struct mtk_ddp_comp *comp)
112 if (comp->funcs && comp->funcs->power_off)
113 comp->funcs->power_off(comp->dev);
115 pm_runtime_put(comp->dev);
118 static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
120 if (comp->funcs && comp->funcs->clk_enable)
121 return comp->funcs->clk_enable(comp->dev);
126 static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
128 if (comp->funcs && comp->funcs->clk_disable)
129 comp->funcs->clk_disable(comp->dev);
133 enum drm_mode_status mtk_ddp_comp_mode_valid(struct mtk_ddp_comp *comp,
134 const struct drm_display_mode *mode)
136 if (comp && comp->funcs && comp->funcs->mode_valid)
137 return comp->funcs->mode_valid(comp->dev, mode);
141 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
142 unsigned int w, unsigned int h,
143 unsigned int vrefresh, unsigned int bpc,
144 struct cmdq_pkt *cmdq_pkt)
146 if (comp->funcs && comp->funcs->config)
147 comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
150 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
152 if (comp->funcs && comp->funcs->start)
153 comp->funcs->start(comp->dev);
156 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
158 if (comp->funcs && comp->funcs->stop)
159 comp->funcs->stop(comp->dev);
162 static inline void mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp *comp,
163 void (*vblank_cb)(void *),
164 void *vblank_cb_data)
166 if (comp->funcs && comp->funcs->register_vblank_cb)
167 comp->funcs->register_vblank_cb(comp->dev, vblank_cb,
171 static inline void mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp *comp)
173 if (comp->funcs && comp->funcs->unregister_vblank_cb)
174 comp->funcs->unregister_vblank_cb(comp->dev);
177 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp)
179 if (comp->funcs && comp->funcs->enable_vblank)
180 comp->funcs->enable_vblank(comp->dev);
183 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
185 if (comp->funcs && comp->funcs->disable_vblank)
186 comp->funcs->disable_vblank(comp->dev);
190 unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
192 if (comp->funcs && comp->funcs->supported_rotations)
193 return comp->funcs->supported_rotations(comp->dev);
198 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
200 if (comp->funcs && comp->funcs->layer_nr)
201 return comp->funcs->layer_nr(comp->dev);
206 static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
208 struct mtk_plane_state *state)
210 if (comp->funcs && comp->funcs->layer_check)
211 return comp->funcs->layer_check(comp->dev, idx, state);
215 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
217 struct mtk_plane_state *state,
218 struct cmdq_pkt *cmdq_pkt)
220 if (comp->funcs && comp->funcs->layer_config)
221 comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
224 static inline unsigned int mtk_ddp_gamma_get_lut_size(struct mtk_ddp_comp *comp)
226 if (comp->funcs && comp->funcs->gamma_get_lut_size)
227 return comp->funcs->gamma_get_lut_size(comp->dev);
232 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
233 struct drm_crtc_state *state)
235 if (comp->funcs && comp->funcs->gamma_set)
236 comp->funcs->gamma_set(comp->dev, state);
239 static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
241 if (comp->funcs && comp->funcs->bgclr_in_on)
242 comp->funcs->bgclr_in_on(comp->dev);
245 static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
247 if (comp->funcs && comp->funcs->bgclr_in_off)
248 comp->funcs->bgclr_in_off(comp->dev);
251 static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
252 struct drm_crtc_state *state)
254 if (comp->funcs && comp->funcs->ctm_set)
255 comp->funcs->ctm_set(comp->dev, state);
258 static inline struct device *mtk_ddp_comp_dma_dev_get(struct mtk_ddp_comp *comp)
260 if (comp->funcs && comp->funcs->dma_dev_get)
261 return comp->funcs->dma_dev_get(comp->dev);
266 const u32 *mtk_ddp_comp_get_formats(struct mtk_ddp_comp *comp)
268 if (comp->funcs && comp->funcs->get_formats)
269 return comp->funcs->get_formats(comp->dev);
275 size_t mtk_ddp_comp_get_num_formats(struct mtk_ddp_comp *comp)
277 if (comp->funcs && comp->funcs->get_num_formats)
278 return comp->funcs->get_num_formats(comp->dev);
283 static inline bool mtk_ddp_comp_add(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
285 if (comp->funcs && comp->funcs->add) {
286 comp->funcs->add(comp->dev, mutex);
292 static inline bool mtk_ddp_comp_remove(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
294 if (comp->funcs && comp->funcs->remove) {
295 comp->funcs->remove(comp->dev, mutex);
301 static inline bool mtk_ddp_comp_connect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
304 if (comp->funcs && comp->funcs->connect) {
305 comp->funcs->connect(comp->dev, mmsys_dev, next);
311 static inline bool mtk_ddp_comp_disconnect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
314 if (comp->funcs && comp->funcs->disconnect) {
315 comp->funcs->disconnect(comp->dev, mmsys_dev, next);
321 static inline void mtk_ddp_comp_encoder_index_set(struct mtk_ddp_comp *comp)
323 if (comp->funcs && comp->funcs->encoder_index)
324 comp->encoder_index = (int)comp->funcs->encoder_index(comp->dev);
327 int mtk_ddp_comp_get_id(struct device_node *node,
328 enum mtk_ddp_comp_type comp_type);
329 unsigned int mtk_find_possible_crtcs(struct drm_device *drm, struct device *dev);
330 int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
331 unsigned int comp_id);
332 enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
333 void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
334 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
335 unsigned int offset);
336 void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
337 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
338 unsigned int offset);
339 void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
340 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
341 unsigned int offset, unsigned int mask);
342 #endif /* MTK_DDP_COMP_H */