xref: /linux/drivers/gpu/drm/mediatek/mtk_ddp_comp.h (revision c460535a6d6182dcb00773132a8c384c1f9b5408)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2015 MediaTek Inc.
4  */
5 
6 #ifndef MTK_DDP_COMP_H
7 #define MTK_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 
17 struct device;
18 struct device_node;
19 struct drm_crtc;
20 struct drm_device;
21 struct mtk_plane_state;
22 struct drm_crtc_state;
23 
24 enum 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 
49 struct mtk_ddp_comp;
50 struct cmdq_pkt;
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,
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 	u32 (*get_blend_modes)(struct device *dev);
84 	const u32 *(*get_formats)(struct device *dev);
85 	size_t (*get_num_formats)(struct device *dev);
86 	bool (*is_afbc_supported)(struct device *dev);
87 	void (*connect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
88 	void (*disconnect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
89 	void (*add)(struct device *dev, struct mtk_mutex *mutex);
90 	void (*remove)(struct device *dev, struct mtk_mutex *mutex);
91 	unsigned int (*encoder_index)(struct device *dev);
92 	enum drm_mode_status (*mode_valid)(struct device *dev, const struct drm_display_mode *mode);
93 };
94 
95 struct mtk_ddp_comp {
96 	struct device *dev;
97 	int irq;
98 	unsigned int id;
99 	int encoder_index;
100 	const struct mtk_ddp_comp_funcs *funcs;
101 };
102 
103 static inline int mtk_ddp_comp_power_on(struct mtk_ddp_comp *comp)
104 {
105 	if (comp->funcs && comp->funcs->power_on)
106 		return comp->funcs->power_on(comp->dev);
107 	else
108 		return pm_runtime_resume_and_get(comp->dev);
109 	return 0;
110 }
111 
112 static inline void mtk_ddp_comp_power_off(struct mtk_ddp_comp *comp)
113 {
114 	if (comp->funcs && comp->funcs->power_off)
115 		comp->funcs->power_off(comp->dev);
116 	else
117 		pm_runtime_put(comp->dev);
118 }
119 
120 static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
121 {
122 	if (comp->funcs && comp->funcs->clk_enable)
123 		return comp->funcs->clk_enable(comp->dev);
124 
125 	return 0;
126 }
127 
128 static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
129 {
130 	if (comp->funcs && comp->funcs->clk_disable)
131 		comp->funcs->clk_disable(comp->dev);
132 }
133 
134 static inline
135 enum drm_mode_status mtk_ddp_comp_mode_valid(struct mtk_ddp_comp *comp,
136 					     const struct drm_display_mode *mode)
137 {
138 	if (comp && comp->funcs && comp->funcs->mode_valid)
139 		return comp->funcs->mode_valid(comp->dev, mode);
140 	return MODE_OK;
141 }
142 
143 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
144 				       unsigned int w, unsigned int h,
145 				       unsigned int vrefresh, unsigned int bpc,
146 				       struct cmdq_pkt *cmdq_pkt)
147 {
148 	if (comp->funcs && comp->funcs->config)
149 		comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
150 }
151 
152 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
153 {
154 	if (comp->funcs && comp->funcs->start)
155 		comp->funcs->start(comp->dev);
156 }
157 
158 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
159 {
160 	if (comp->funcs && comp->funcs->stop)
161 		comp->funcs->stop(comp->dev);
162 }
163 
164 static inline void mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp *comp,
165 						   void (*vblank_cb)(void *),
166 						   void *vblank_cb_data)
167 {
168 	if (comp->funcs && comp->funcs->register_vblank_cb)
169 		comp->funcs->register_vblank_cb(comp->dev, vblank_cb,
170 						vblank_cb_data);
171 }
172 
173 static inline void mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp *comp)
174 {
175 	if (comp->funcs && comp->funcs->unregister_vblank_cb)
176 		comp->funcs->unregister_vblank_cb(comp->dev);
177 }
178 
179 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp)
180 {
181 	if (comp->funcs && comp->funcs->enable_vblank)
182 		comp->funcs->enable_vblank(comp->dev);
183 }
184 
185 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
186 {
187 	if (comp->funcs && comp->funcs->disable_vblank)
188 		comp->funcs->disable_vblank(comp->dev);
189 }
190 
191 static inline
192 unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
193 {
194 	if (comp->funcs && comp->funcs->supported_rotations)
195 		return comp->funcs->supported_rotations(comp->dev);
196 
197 	/*
198 	 * In order to pass IGT tests, DRM_MODE_ROTATE_0 is required when
199 	 * rotation is not supported.
200 	 */
201 	return DRM_MODE_ROTATE_0;
202 }
203 
204 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
205 {
206 	if (comp->funcs && comp->funcs->layer_nr)
207 		return comp->funcs->layer_nr(comp->dev);
208 
209 	return 0;
210 }
211 
212 static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
213 					   unsigned int idx,
214 					   struct mtk_plane_state *state)
215 {
216 	if (comp->funcs && comp->funcs->layer_check)
217 		return comp->funcs->layer_check(comp->dev, idx, state);
218 	return 0;
219 }
220 
221 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
222 					     unsigned int idx,
223 					     struct mtk_plane_state *state,
224 					     struct cmdq_pkt *cmdq_pkt)
225 {
226 	if (comp->funcs && comp->funcs->layer_config)
227 		comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
228 }
229 
230 static inline unsigned int mtk_ddp_gamma_get_lut_size(struct mtk_ddp_comp *comp)
231 {
232 	if (comp->funcs && comp->funcs->gamma_get_lut_size)
233 		return comp->funcs->gamma_get_lut_size(comp->dev);
234 
235 	return 0;
236 }
237 
238 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
239 				     struct drm_crtc_state *state)
240 {
241 	if (comp->funcs && comp->funcs->gamma_set)
242 		comp->funcs->gamma_set(comp->dev, state);
243 }
244 
245 static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
246 {
247 	if (comp->funcs && comp->funcs->bgclr_in_on)
248 		comp->funcs->bgclr_in_on(comp->dev);
249 }
250 
251 static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
252 {
253 	if (comp->funcs && comp->funcs->bgclr_in_off)
254 		comp->funcs->bgclr_in_off(comp->dev);
255 }
256 
257 static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
258 				   struct drm_crtc_state *state)
259 {
260 	if (comp->funcs && comp->funcs->ctm_set)
261 		comp->funcs->ctm_set(comp->dev, state);
262 }
263 
264 static inline struct device *mtk_ddp_comp_dma_dev_get(struct mtk_ddp_comp *comp)
265 {
266 	if (comp->funcs && comp->funcs->dma_dev_get)
267 		return comp->funcs->dma_dev_get(comp->dev);
268 	return comp->dev;
269 }
270 
271 static inline
272 u32 mtk_ddp_comp_get_blend_modes(struct mtk_ddp_comp *comp)
273 {
274 	if (comp->funcs && comp->funcs->get_blend_modes)
275 		return comp->funcs->get_blend_modes(comp->dev);
276 
277 	return 0;
278 }
279 
280 static inline
281 const u32 *mtk_ddp_comp_get_formats(struct mtk_ddp_comp *comp)
282 {
283 	if (comp->funcs && comp->funcs->get_formats)
284 		return comp->funcs->get_formats(comp->dev);
285 
286 	return NULL;
287 }
288 
289 static inline
290 size_t mtk_ddp_comp_get_num_formats(struct mtk_ddp_comp *comp)
291 {
292 	if (comp->funcs && comp->funcs->get_num_formats)
293 		return comp->funcs->get_num_formats(comp->dev);
294 
295 	return 0;
296 }
297 
298 static inline bool mtk_ddp_comp_is_afbc_supported(struct mtk_ddp_comp *comp)
299 {
300 	if (comp->funcs && comp->funcs->is_afbc_supported)
301 		return comp->funcs->is_afbc_supported(comp->dev);
302 
303 	return false;
304 }
305 
306 static inline bool mtk_ddp_comp_add(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
307 {
308 	if (comp->funcs && comp->funcs->add) {
309 		comp->funcs->add(comp->dev, mutex);
310 		return true;
311 	}
312 	return false;
313 }
314 
315 static inline bool mtk_ddp_comp_remove(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
316 {
317 	if (comp->funcs && comp->funcs->remove) {
318 		comp->funcs->remove(comp->dev, mutex);
319 		return true;
320 	}
321 	return false;
322 }
323 
324 static inline bool mtk_ddp_comp_connect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
325 					unsigned int next)
326 {
327 	if (comp->funcs && comp->funcs->connect) {
328 		comp->funcs->connect(comp->dev, mmsys_dev, next);
329 		return true;
330 	}
331 	return false;
332 }
333 
334 static inline bool mtk_ddp_comp_disconnect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
335 					   unsigned int next)
336 {
337 	if (comp->funcs && comp->funcs->disconnect) {
338 		comp->funcs->disconnect(comp->dev, mmsys_dev, next);
339 		return true;
340 	}
341 	return false;
342 }
343 
344 static inline void mtk_ddp_comp_encoder_index_set(struct mtk_ddp_comp *comp)
345 {
346 	if (comp->funcs && comp->funcs->encoder_index)
347 		comp->encoder_index = (int)comp->funcs->encoder_index(comp->dev);
348 }
349 
350 int mtk_ddp_comp_get_id(struct device_node *node,
351 			enum mtk_ddp_comp_type comp_type);
352 int mtk_find_possible_crtcs(struct drm_device *drm, struct device *dev);
353 int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
354 		      unsigned int comp_id);
355 enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
356 void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
357 		   struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
358 		   unsigned int offset);
359 void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
360 			   struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
361 			   unsigned int offset);
362 void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
363 			struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
364 			unsigned int offset, unsigned int mask);
365 #endif /* MTK_DDP_COMP_H */
366