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 
11 struct device;
12 struct device_node;
13 struct drm_crtc;
14 struct drm_device;
15 struct mtk_plane_state;
16 struct drm_crtc_state;
17 
18 enum mtk_ddp_comp_type {
19 	MTK_DISP_OVL,
20 	MTK_DISP_OVL_2L,
21 	MTK_DISP_RDMA,
22 	MTK_DISP_WDMA,
23 	MTK_DISP_COLOR,
24 	MTK_DISP_CCORR,
25 	MTK_DISP_DITHER,
26 	MTK_DISP_AAL,
27 	MTK_DISP_GAMMA,
28 	MTK_DISP_UFOE,
29 	MTK_DSI,
30 	MTK_DPI,
31 	MTK_DISP_PWM,
32 	MTK_DISP_MUTEX,
33 	MTK_DISP_OD,
34 	MTK_DISP_BLS,
35 	MTK_DDP_COMP_TYPE_MAX,
36 };
37 
38 enum mtk_ddp_comp_id {
39 	DDP_COMPONENT_AAL0,
40 	DDP_COMPONENT_AAL1,
41 	DDP_COMPONENT_BLS,
42 	DDP_COMPONENT_CCORR,
43 	DDP_COMPONENT_COLOR0,
44 	DDP_COMPONENT_COLOR1,
45 	DDP_COMPONENT_DITHER,
46 	DDP_COMPONENT_DPI0,
47 	DDP_COMPONENT_DPI1,
48 	DDP_COMPONENT_DSI0,
49 	DDP_COMPONENT_DSI1,
50 	DDP_COMPONENT_DSI2,
51 	DDP_COMPONENT_DSI3,
52 	DDP_COMPONENT_GAMMA,
53 	DDP_COMPONENT_OD0,
54 	DDP_COMPONENT_OD1,
55 	DDP_COMPONENT_OVL0,
56 	DDP_COMPONENT_OVL_2L0,
57 	DDP_COMPONENT_OVL_2L1,
58 	DDP_COMPONENT_OVL1,
59 	DDP_COMPONENT_PWM0,
60 	DDP_COMPONENT_PWM1,
61 	DDP_COMPONENT_PWM2,
62 	DDP_COMPONENT_RDMA0,
63 	DDP_COMPONENT_RDMA1,
64 	DDP_COMPONENT_RDMA2,
65 	DDP_COMPONENT_UFOE,
66 	DDP_COMPONENT_WDMA0,
67 	DDP_COMPONENT_WDMA1,
68 	DDP_COMPONENT_ID_MAX,
69 };
70 
71 struct mtk_ddp_comp;
72 
73 struct mtk_ddp_comp_funcs {
74 	void (*config)(struct mtk_ddp_comp *comp, unsigned int w,
75 		       unsigned int h, unsigned int vrefresh, unsigned int bpc);
76 	void (*start)(struct mtk_ddp_comp *comp);
77 	void (*stop)(struct mtk_ddp_comp *comp);
78 	void (*enable_vblank)(struct mtk_ddp_comp *comp, struct drm_crtc *crtc);
79 	void (*disable_vblank)(struct mtk_ddp_comp *comp);
80 	unsigned int (*supported_rotations)(struct mtk_ddp_comp *comp);
81 	unsigned int (*layer_nr)(struct mtk_ddp_comp *comp);
82 	void (*layer_on)(struct mtk_ddp_comp *comp, unsigned int idx);
83 	void (*layer_off)(struct mtk_ddp_comp *comp, unsigned int idx);
84 	int (*layer_check)(struct mtk_ddp_comp *comp,
85 			   unsigned int idx,
86 			   struct mtk_plane_state *state);
87 	void (*layer_config)(struct mtk_ddp_comp *comp, unsigned int idx,
88 			     struct mtk_plane_state *state);
89 	void (*gamma_set)(struct mtk_ddp_comp *comp,
90 			  struct drm_crtc_state *state);
91 	void (*bgclr_in_on)(struct mtk_ddp_comp *comp);
92 	void (*bgclr_in_off)(struct mtk_ddp_comp *comp);
93 };
94 
95 struct mtk_ddp_comp {
96 	struct clk *clk;
97 	void __iomem *regs;
98 	int irq;
99 	struct device *larb_dev;
100 	enum mtk_ddp_comp_id id;
101 	const struct mtk_ddp_comp_funcs *funcs;
102 };
103 
104 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
105 				       unsigned int w, unsigned int h,
106 				       unsigned int vrefresh, unsigned int bpc)
107 {
108 	if (comp->funcs && comp->funcs->config)
109 		comp->funcs->config(comp, w, h, vrefresh, bpc);
110 }
111 
112 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
113 {
114 	if (comp->funcs && comp->funcs->start)
115 		comp->funcs->start(comp);
116 }
117 
118 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
119 {
120 	if (comp->funcs && comp->funcs->stop)
121 		comp->funcs->stop(comp);
122 }
123 
124 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp,
125 					      struct drm_crtc *crtc)
126 {
127 	if (comp->funcs && comp->funcs->enable_vblank)
128 		comp->funcs->enable_vblank(comp, crtc);
129 }
130 
131 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
132 {
133 	if (comp->funcs && comp->funcs->disable_vblank)
134 		comp->funcs->disable_vblank(comp);
135 }
136 
137 static inline
138 unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
139 {
140 	if (comp->funcs && comp->funcs->supported_rotations)
141 		return comp->funcs->supported_rotations(comp);
142 
143 	return 0;
144 }
145 
146 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
147 {
148 	if (comp->funcs && comp->funcs->layer_nr)
149 		return comp->funcs->layer_nr(comp);
150 
151 	return 0;
152 }
153 
154 static inline void mtk_ddp_comp_layer_on(struct mtk_ddp_comp *comp,
155 					 unsigned int idx)
156 {
157 	if (comp->funcs && comp->funcs->layer_on)
158 		comp->funcs->layer_on(comp, idx);
159 }
160 
161 static inline void mtk_ddp_comp_layer_off(struct mtk_ddp_comp *comp,
162 					  unsigned int idx)
163 {
164 	if (comp->funcs && comp->funcs->layer_off)
165 		comp->funcs->layer_off(comp, idx);
166 }
167 
168 static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
169 					   unsigned int idx,
170 					   struct mtk_plane_state *state)
171 {
172 	if (comp->funcs && comp->funcs->layer_check)
173 		return comp->funcs->layer_check(comp, idx, state);
174 	return 0;
175 }
176 
177 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
178 					     unsigned int idx,
179 					     struct mtk_plane_state *state)
180 {
181 	if (comp->funcs && comp->funcs->layer_config)
182 		comp->funcs->layer_config(comp, idx, state);
183 }
184 
185 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
186 				     struct drm_crtc_state *state)
187 {
188 	if (comp->funcs && comp->funcs->gamma_set)
189 		comp->funcs->gamma_set(comp, state);
190 }
191 
192 static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
193 {
194 	if (comp->funcs && comp->funcs->bgclr_in_on)
195 		comp->funcs->bgclr_in_on(comp);
196 }
197 
198 static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
199 {
200 	if (comp->funcs && comp->funcs->bgclr_in_off)
201 		comp->funcs->bgclr_in_off(comp);
202 }
203 
204 int mtk_ddp_comp_get_id(struct device_node *node,
205 			enum mtk_ddp_comp_type comp_type);
206 int mtk_ddp_comp_init(struct device *dev, struct device_node *comp_node,
207 		      struct mtk_ddp_comp *comp, enum mtk_ddp_comp_id comp_id,
208 		      const struct mtk_ddp_comp_funcs *funcs);
209 int mtk_ddp_comp_register(struct drm_device *drm, struct mtk_ddp_comp *comp);
210 void mtk_ddp_comp_unregister(struct drm_device *drm, struct mtk_ddp_comp *comp);
211 void mtk_dither_set(struct mtk_ddp_comp *comp, unsigned int bpc,
212 		    unsigned int CFG);
213 
214 #endif /* MTK_DRM_DDP_COMP_H */
215