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/soc/mediatek/mtk-cmdq.h>
11 #include <linux/soc/mediatek/mtk-mmsys.h>
12 #include <linux/soc/mediatek/mtk-mutex.h>
13
14 struct device;
15 struct device_node;
16 struct drm_crtc;
17 struct drm_device;
18 struct mtk_plane_state;
19 struct drm_crtc_state;
20
21 enum mtk_ddp_comp_type {
22 MTK_DISP_AAL,
23 MTK_DISP_BLS,
24 MTK_DISP_CCORR,
25 MTK_DISP_COLOR,
26 MTK_DISP_DITHER,
27 MTK_DISP_DSC,
28 MTK_DISP_GAMMA,
29 MTK_DISP_MERGE,
30 MTK_DISP_MUTEX,
31 MTK_DISP_OD,
32 MTK_DISP_OVL,
33 MTK_DISP_OVL_2L,
34 MTK_DISP_OVL_ADAPTOR,
35 MTK_DISP_POSTMASK,
36 MTK_DISP_PWM,
37 MTK_DISP_RDMA,
38 MTK_DISP_UFOE,
39 MTK_DISP_WDMA,
40 MTK_DPI,
41 MTK_DP_INTF,
42 MTK_DSI,
43 MTK_DDP_COMP_TYPE_MAX,
44 };
45
46 struct mtk_ddp_comp;
47 struct cmdq_pkt;
48 struct mtk_ddp_comp_funcs {
49 int (*clk_enable)(struct device *dev);
50 void (*clk_disable)(struct device *dev);
51 void (*config)(struct device *dev, unsigned int w,
52 unsigned int h, unsigned int vrefresh,
53 unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
54 void (*start)(struct device *dev);
55 void (*stop)(struct device *dev);
56 void (*register_vblank_cb)(struct device *dev,
57 void (*vblank_cb)(void *),
58 void *vblank_cb_data);
59 void (*unregister_vblank_cb)(struct device *dev);
60 void (*enable_vblank)(struct device *dev);
61 void (*disable_vblank)(struct device *dev);
62 unsigned int (*supported_rotations)(struct device *dev);
63 unsigned int (*layer_nr)(struct device *dev);
64 int (*layer_check)(struct device *dev,
65 unsigned int idx,
66 struct mtk_plane_state *state);
67 void (*layer_config)(struct device *dev, unsigned int idx,
68 struct mtk_plane_state *state,
69 struct cmdq_pkt *cmdq_pkt);
70 void (*gamma_set)(struct device *dev,
71 struct drm_crtc_state *state);
72 void (*bgclr_in_on)(struct device *dev);
73 void (*bgclr_in_off)(struct device *dev);
74 void (*ctm_set)(struct device *dev,
75 struct drm_crtc_state *state);
76 struct device * (*dma_dev_get)(struct device *dev);
77 const u32 *(*get_formats)(struct device *dev);
78 size_t (*get_num_formats)(struct device *dev);
79 void (*connect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
80 void (*disconnect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
81 void (*add)(struct device *dev, struct mtk_mutex *mutex);
82 void (*remove)(struct device *dev, struct mtk_mutex *mutex);
83 };
84
85 struct mtk_ddp_comp {
86 struct device *dev;
87 int irq;
88 unsigned int id;
89 const struct mtk_ddp_comp_funcs *funcs;
90 };
91
mtk_ddp_comp_clk_enable(struct mtk_ddp_comp * comp)92 static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
93 {
94 if (comp->funcs && comp->funcs->clk_enable)
95 return comp->funcs->clk_enable(comp->dev);
96
97 return 0;
98 }
99
mtk_ddp_comp_clk_disable(struct mtk_ddp_comp * comp)100 static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
101 {
102 if (comp->funcs && comp->funcs->clk_disable)
103 comp->funcs->clk_disable(comp->dev);
104 }
105
mtk_ddp_comp_config(struct mtk_ddp_comp * comp,unsigned int w,unsigned int h,unsigned int vrefresh,unsigned int bpc,struct cmdq_pkt * cmdq_pkt)106 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
107 unsigned int w, unsigned int h,
108 unsigned int vrefresh, unsigned int bpc,
109 struct cmdq_pkt *cmdq_pkt)
110 {
111 if (comp->funcs && comp->funcs->config)
112 comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
113 }
114
mtk_ddp_comp_start(struct mtk_ddp_comp * comp)115 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
116 {
117 if (comp->funcs && comp->funcs->start)
118 comp->funcs->start(comp->dev);
119 }
120
mtk_ddp_comp_stop(struct mtk_ddp_comp * comp)121 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
122 {
123 if (comp->funcs && comp->funcs->stop)
124 comp->funcs->stop(comp->dev);
125 }
126
mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp * comp,void (* vblank_cb)(void *),void * vblank_cb_data)127 static inline void mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp *comp,
128 void (*vblank_cb)(void *),
129 void *vblank_cb_data)
130 {
131 if (comp->funcs && comp->funcs->register_vblank_cb)
132 comp->funcs->register_vblank_cb(comp->dev, vblank_cb,
133 vblank_cb_data);
134 }
135
mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp * comp)136 static inline void mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp *comp)
137 {
138 if (comp->funcs && comp->funcs->unregister_vblank_cb)
139 comp->funcs->unregister_vblank_cb(comp->dev);
140 }
141
mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp * comp)142 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp)
143 {
144 if (comp->funcs && comp->funcs->enable_vblank)
145 comp->funcs->enable_vblank(comp->dev);
146 }
147
mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp * comp)148 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
149 {
150 if (comp->funcs && comp->funcs->disable_vblank)
151 comp->funcs->disable_vblank(comp->dev);
152 }
153
154 static inline
mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp * comp)155 unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
156 {
157 if (comp->funcs && comp->funcs->supported_rotations)
158 return comp->funcs->supported_rotations(comp->dev);
159
160 return 0;
161 }
162
mtk_ddp_comp_layer_nr(struct mtk_ddp_comp * comp)163 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
164 {
165 if (comp->funcs && comp->funcs->layer_nr)
166 return comp->funcs->layer_nr(comp->dev);
167
168 return 0;
169 }
170
mtk_ddp_comp_layer_check(struct mtk_ddp_comp * comp,unsigned int idx,struct mtk_plane_state * state)171 static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
172 unsigned int idx,
173 struct mtk_plane_state *state)
174 {
175 if (comp->funcs && comp->funcs->layer_check)
176 return comp->funcs->layer_check(comp->dev, idx, state);
177 return 0;
178 }
179
mtk_ddp_comp_layer_config(struct mtk_ddp_comp * comp,unsigned int idx,struct mtk_plane_state * state,struct cmdq_pkt * cmdq_pkt)180 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
181 unsigned int idx,
182 struct mtk_plane_state *state,
183 struct cmdq_pkt *cmdq_pkt)
184 {
185 if (comp->funcs && comp->funcs->layer_config)
186 comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
187 }
188
mtk_ddp_gamma_set(struct mtk_ddp_comp * comp,struct drm_crtc_state * state)189 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
190 struct drm_crtc_state *state)
191 {
192 if (comp->funcs && comp->funcs->gamma_set)
193 comp->funcs->gamma_set(comp->dev, state);
194 }
195
mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp * comp)196 static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
197 {
198 if (comp->funcs && comp->funcs->bgclr_in_on)
199 comp->funcs->bgclr_in_on(comp->dev);
200 }
201
mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp * comp)202 static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
203 {
204 if (comp->funcs && comp->funcs->bgclr_in_off)
205 comp->funcs->bgclr_in_off(comp->dev);
206 }
207
mtk_ddp_ctm_set(struct mtk_ddp_comp * comp,struct drm_crtc_state * state)208 static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
209 struct drm_crtc_state *state)
210 {
211 if (comp->funcs && comp->funcs->ctm_set)
212 comp->funcs->ctm_set(comp->dev, state);
213 }
214
mtk_ddp_comp_dma_dev_get(struct mtk_ddp_comp * comp)215 static inline struct device *mtk_ddp_comp_dma_dev_get(struct mtk_ddp_comp *comp)
216 {
217 if (comp->funcs && comp->funcs->dma_dev_get)
218 return comp->funcs->dma_dev_get(comp->dev);
219 return comp->dev;
220 }
221
222 static inline
mtk_ddp_comp_get_formats(struct mtk_ddp_comp * comp)223 const u32 *mtk_ddp_comp_get_formats(struct mtk_ddp_comp *comp)
224 {
225 if (comp->funcs && comp->funcs->get_formats)
226 return comp->funcs->get_formats(comp->dev);
227
228 return NULL;
229 }
230
231 static inline
mtk_ddp_comp_get_num_formats(struct mtk_ddp_comp * comp)232 size_t mtk_ddp_comp_get_num_formats(struct mtk_ddp_comp *comp)
233 {
234 if (comp->funcs && comp->funcs->get_num_formats)
235 return comp->funcs->get_num_formats(comp->dev);
236
237 return 0;
238 }
239
mtk_ddp_comp_add(struct mtk_ddp_comp * comp,struct mtk_mutex * mutex)240 static inline bool mtk_ddp_comp_add(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
241 {
242 if (comp->funcs && comp->funcs->add) {
243 comp->funcs->add(comp->dev, mutex);
244 return true;
245 }
246 return false;
247 }
248
mtk_ddp_comp_remove(struct mtk_ddp_comp * comp,struct mtk_mutex * mutex)249 static inline bool mtk_ddp_comp_remove(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
250 {
251 if (comp->funcs && comp->funcs->remove) {
252 comp->funcs->remove(comp->dev, mutex);
253 return true;
254 }
255 return false;
256 }
257
mtk_ddp_comp_connect(struct mtk_ddp_comp * comp,struct device * mmsys_dev,unsigned int next)258 static inline bool mtk_ddp_comp_connect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
259 unsigned int next)
260 {
261 if (comp->funcs && comp->funcs->connect) {
262 comp->funcs->connect(comp->dev, mmsys_dev, next);
263 return true;
264 }
265 return false;
266 }
267
mtk_ddp_comp_disconnect(struct mtk_ddp_comp * comp,struct device * mmsys_dev,unsigned int next)268 static inline bool mtk_ddp_comp_disconnect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
269 unsigned int next)
270 {
271 if (comp->funcs && comp->funcs->disconnect) {
272 comp->funcs->disconnect(comp->dev, mmsys_dev, next);
273 return true;
274 }
275 return false;
276 }
277
278 int mtk_ddp_comp_get_id(struct device_node *node,
279 enum mtk_ddp_comp_type comp_type);
280 unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
281 struct device *dev);
282 int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
283 unsigned int comp_id);
284 enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
285 void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
286 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
287 unsigned int offset);
288 void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
289 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
290 unsigned int offset);
291 void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
292 struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
293 unsigned int offset, unsigned int mask);
294 #endif /* MTK_DRM_DDP_COMP_H */
295