1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (c) 2015 MediaTek Inc.
4 */
5
6#ifndef MTK_DRM_DDP_COMP_H
7#define MTK_DRM_DDP_COMP_H
8
9#include <linux/io.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>
14
15#include <drm/drm_modes.h>
16
17struct device;
18struct device_node;
19struct drm_crtc;
20struct drm_device;
21struct mtk_plane_state;
22struct drm_crtc_state;
23
24enum mtk_ddp_comp_type {
25 MTK_DISP_AAL,
26 MTK_DISP_BLS,
27 MTK_DISP_CCORR,
28 MTK_DISP_COLOR,
29 MTK_DISP_DITHER,
30 MTK_DISP_DSC,
31 MTK_DISP_GAMMA,
32 MTK_DISP_MERGE,
33 MTK_DISP_MUTEX,
34 MTK_DISP_OD,
35 MTK_DISP_OVL,
36 MTK_DISP_OVL_2L,
37 MTK_DISP_OVL_ADAPTOR,
38 MTK_DISP_POSTMASK,
39 MTK_DISP_PWM,
40 MTK_DISP_RDMA,
41 MTK_DISP_UFOE,
42 MTK_DISP_WDMA,
43 MTK_DPI,
44 MTK_DP_INTF,
45 MTK_DSI,
46 MTK_DDP_COMP_TYPE_MAX,
47};
48
49struct mtk_ddp_comp;
50struct cmdq_pkt;
51struct 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,
70 unsigned int idx,
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);
91};
92
93struct mtk_ddp_comp {
94 struct device *dev;
95 int irq;
96 unsigned int id;
97 int encoder_index;
98 const struct mtk_ddp_comp_funcs *funcs;
99};
100
101static inline int mtk_ddp_comp_power_on(struct mtk_ddp_comp *comp)
102{
103 if (comp->funcs && comp->funcs->power_on)
104 return comp->funcs->power_on(comp->dev);
105 else
106 return pm_runtime_resume_and_get(dev: comp->dev);
107 return 0;
108}
109
110static inline void mtk_ddp_comp_power_off(struct mtk_ddp_comp *comp)
111{
112 if (comp->funcs && comp->funcs->power_off)
113 comp->funcs->power_off(comp->dev);
114 else
115 pm_runtime_put(dev: comp->dev);
116}
117
118static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
119{
120 if (comp->funcs && comp->funcs->clk_enable)
121 return comp->funcs->clk_enable(comp->dev);
122
123 return 0;
124}
125
126static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
127{
128 if (comp->funcs && comp->funcs->clk_disable)
129 comp->funcs->clk_disable(comp->dev);
130}
131
132static inline
133enum drm_mode_status mtk_ddp_comp_mode_valid(struct mtk_ddp_comp *comp,
134 const struct drm_display_mode *mode)
135{
136 if (comp && comp->funcs && comp->funcs->mode_valid)
137 return comp->funcs->mode_valid(comp->dev, mode);
138 return MODE_OK;
139}
140
141static 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)
145{
146 if (comp->funcs && comp->funcs->config)
147 comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
148}
149
150static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
151{
152 if (comp->funcs && comp->funcs->start)
153 comp->funcs->start(comp->dev);
154}
155
156static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
157{
158 if (comp->funcs && comp->funcs->stop)
159 comp->funcs->stop(comp->dev);
160}
161
162static inline void mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp *comp,
163 void (*vblank_cb)(void *),
164 void *vblank_cb_data)
165{
166 if (comp->funcs && comp->funcs->register_vblank_cb)
167 comp->funcs->register_vblank_cb(comp->dev, vblank_cb,
168 vblank_cb_data);
169}
170
171static inline void mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp *comp)
172{
173 if (comp->funcs && comp->funcs->unregister_vblank_cb)
174 comp->funcs->unregister_vblank_cb(comp->dev);
175}
176
177static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp)
178{
179 if (comp->funcs && comp->funcs->enable_vblank)
180 comp->funcs->enable_vblank(comp->dev);
181}
182
183static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
184{
185 if (comp->funcs && comp->funcs->disable_vblank)
186 comp->funcs->disable_vblank(comp->dev);
187}
188
189static inline
190unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
191{
192 if (comp->funcs && comp->funcs->supported_rotations)
193 return comp->funcs->supported_rotations(comp->dev);
194
195 return 0;
196}
197
198static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
199{
200 if (comp->funcs && comp->funcs->layer_nr)
201 return comp->funcs->layer_nr(comp->dev);
202
203 return 0;
204}
205
206static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
207 unsigned int idx,
208 struct mtk_plane_state *state)
209{
210 if (comp->funcs && comp->funcs->layer_check)
211 return comp->funcs->layer_check(comp->dev, idx, state);
212 return 0;
213}
214
215static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
216 unsigned int idx,
217 struct mtk_plane_state *state,
218 struct cmdq_pkt *cmdq_pkt)
219{
220 if (comp->funcs && comp->funcs->layer_config)
221 comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
222}
223
224static inline unsigned int mtk_ddp_gamma_get_lut_size(struct mtk_ddp_comp *comp)
225{
226 if (comp->funcs && comp->funcs->gamma_get_lut_size)
227 return comp->funcs->gamma_get_lut_size(comp->dev);
228
229 return 0;
230}
231
232static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
233 struct drm_crtc_state *state)
234{
235 if (comp->funcs && comp->funcs->gamma_set)
236 comp->funcs->gamma_set(comp->dev, state);
237}
238
239static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
240{
241 if (comp->funcs && comp->funcs->bgclr_in_on)
242 comp->funcs->bgclr_in_on(comp->dev);
243}
244
245static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
246{
247 if (comp->funcs && comp->funcs->bgclr_in_off)
248 comp->funcs->bgclr_in_off(comp->dev);
249}
250
251static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
252 struct drm_crtc_state *state)
253{
254 if (comp->funcs && comp->funcs->ctm_set)
255 comp->funcs->ctm_set(comp->dev, state);
256}
257
258static inline struct device *mtk_ddp_comp_dma_dev_get(struct mtk_ddp_comp *comp)
259{
260 if (comp->funcs && comp->funcs->dma_dev_get)
261 return comp->funcs->dma_dev_get(comp->dev);
262 return comp->dev;
263}
264
265static inline
266const u32 *mtk_ddp_comp_get_formats(struct mtk_ddp_comp *comp)
267{
268 if (comp->funcs && comp->funcs->get_formats)
269 return comp->funcs->get_formats(comp->dev);
270
271 return NULL;
272}
273
274static inline
275size_t mtk_ddp_comp_get_num_formats(struct mtk_ddp_comp *comp)
276{
277 if (comp->funcs && comp->funcs->get_num_formats)
278 return comp->funcs->get_num_formats(comp->dev);
279
280 return 0;
281}
282
283static inline bool mtk_ddp_comp_add(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
284{
285 if (comp->funcs && comp->funcs->add) {
286 comp->funcs->add(comp->dev, mutex);
287 return true;
288 }
289 return false;
290}
291
292static inline bool mtk_ddp_comp_remove(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
293{
294 if (comp->funcs && comp->funcs->remove) {
295 comp->funcs->remove(comp->dev, mutex);
296 return true;
297 }
298 return false;
299}
300
301static inline bool mtk_ddp_comp_connect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
302 unsigned int next)
303{
304 if (comp->funcs && comp->funcs->connect) {
305 comp->funcs->connect(comp->dev, mmsys_dev, next);
306 return true;
307 }
308 return false;
309}
310
311static inline bool mtk_ddp_comp_disconnect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
312 unsigned int next)
313{
314 if (comp->funcs && comp->funcs->disconnect) {
315 comp->funcs->disconnect(comp->dev, mmsys_dev, next);
316 return true;
317 }
318 return false;
319}
320
321static inline void mtk_ddp_comp_encoder_index_set(struct mtk_ddp_comp *comp)
322{
323 if (comp->funcs && comp->funcs->encoder_index)
324 comp->encoder_index = (int)comp->funcs->encoder_index(comp->dev);
325}
326
327int mtk_ddp_comp_get_id(struct device_node *node,
328 enum mtk_ddp_comp_type comp_type);
329unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
330 struct device *dev);
331int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
332 unsigned int comp_id);
333enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
334void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
335 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
336 unsigned int offset);
337void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
338 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
339 unsigned int offset);
340void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
341 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
342 unsigned int offset, unsigned int mask);
343#endif /* MTK_DRM_DDP_COMP_H */
344

source code of linux/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h