1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * RZ/G2L Display Unit CRTCs
4  *
5  * Copyright (C) 2023 Renesas Electronics Corporation
6  *
7  * Based on rcar_du_crtc.h
8  */
9 
10 #ifndef __RZG2L_DU_CRTC_H__
11 #define __RZG2L_DU_CRTC_H__
12 
13 #include <linux/container_of.h>
14 #include <linux/mutex.h>
15 #include <linux/spinlock.h>
16 #include <linux/wait.h>
17 
18 #include <drm/drm_crtc.h>
19 #include <drm/drm_writeback.h>
20 
21 #include <media/vsp1.h>
22 
23 struct clk;
24 struct reset_control;
25 struct rzg2l_du_vsp;
26 struct rzg2l_du_format_info;
27 
28 /**
29  * struct rzg2l_du_crtc - the CRTC, representing a DU superposition processor
30  * @crtc: base DRM CRTC
31  * @dev: the DU device
32  * @initialized: whether the CRTC has been initialized and clocks enabled
33  * @vblank_enable: whether vblank events are enabled on this CRTC
34  * @event: event to post when the pending page flip completes
35  * @flip_wait: wait queue used to signal page flip completion
36  * @vsp: VSP feeding video to this CRTC
37  * @vsp_pipe: index of the VSP pipeline feeding video to this CRTC
38  * @rstc: reset controller
39  * @rzg2l_clocks: the bus, main and video clock
40  */
41 struct rzg2l_du_crtc {
42 	struct drm_crtc crtc;
43 
44 	struct rzg2l_du_device *dev;
45 	bool initialized;
46 
47 	bool vblank_enable;
48 	struct drm_pending_vblank_event *event;
49 	wait_queue_head_t flip_wait;
50 
51 	struct rzg2l_du_vsp *vsp;
52 	unsigned int vsp_pipe;
53 
54 	const char *const *sources;
55 	unsigned int sources_count;
56 
57 	struct reset_control *rstc;
58 	struct {
59 		struct clk *aclk;
60 		struct clk *pclk;
61 		struct clk *dclk;
62 	} rzg2l_clocks;
63 };
64 
65 static inline struct rzg2l_du_crtc *to_rzg2l_crtc(struct drm_crtc *c)
66 {
67 	return container_of(c, struct rzg2l_du_crtc, crtc);
68 }
69 
70 /**
71  * struct rzg2l_du_crtc_state - Driver-specific CRTC state
72  * @state: base DRM CRTC state
73  * @outputs: bitmask of the outputs (enum rzg2l_du_output) driven by this CRTC
74  */
75 struct rzg2l_du_crtc_state {
76 	struct drm_crtc_state state;
77 	unsigned int outputs;
78 };
79 
80 static inline struct rzg2l_du_crtc_state *to_rzg2l_crtc_state(struct drm_crtc_state *s)
81 {
82 	return container_of(s, struct rzg2l_du_crtc_state, state);
83 }
84 
85 int rzg2l_du_crtc_create(struct rzg2l_du_device *rcdu);
86 
87 void rzg2l_du_crtc_finish_page_flip(struct rzg2l_du_crtc *rcrtc);
88 
89 #endif /* __RZG2L_DU_CRTC_H__ */
90