1
2
3
4
5
6
7#ifndef _KOMEDA_PIPELINE_H_
8#define _KOMEDA_PIPELINE_H_
9
10#include <linux/types.h>
11#include <drm/drm_atomic.h>
12#include <drm/drm_atomic_helper.h>
13#include "malidp_utils.h"
14#include "komeda_color_mgmt.h"
15
16#define KOMEDA_MAX_PIPELINES 2
17#define KOMEDA_PIPELINE_MAX_LAYERS 4
18#define KOMEDA_PIPELINE_MAX_SCALERS 2
19#define KOMEDA_COMPONENT_N_INPUTS 5
20
21
22enum {
23 KOMEDA_COMPONENT_LAYER0 = 0,
24 KOMEDA_COMPONENT_LAYER1 = 1,
25 KOMEDA_COMPONENT_LAYER2 = 2,
26 KOMEDA_COMPONENT_LAYER3 = 3,
27 KOMEDA_COMPONENT_WB_LAYER = 7,
28 KOMEDA_COMPONENT_SCALER0 = 8,
29 KOMEDA_COMPONENT_SCALER1 = 9,
30 KOMEDA_COMPONENT_SPLITTER = 12,
31 KOMEDA_COMPONENT_MERGER = 14,
32 KOMEDA_COMPONENT_COMPIZ0 = 16,
33 KOMEDA_COMPONENT_COMPIZ1 = 17,
34 KOMEDA_COMPONENT_IPS0 = 20,
35 KOMEDA_COMPONENT_IPS1 = 21,
36 KOMEDA_COMPONENT_TIMING_CTRLR = 22,
37};
38
39#define KOMEDA_PIPELINE_LAYERS (BIT(KOMEDA_COMPONENT_LAYER0) |\
40 BIT(KOMEDA_COMPONENT_LAYER1) |\
41 BIT(KOMEDA_COMPONENT_LAYER2) |\
42 BIT(KOMEDA_COMPONENT_LAYER3))
43
44#define KOMEDA_PIPELINE_SCALERS (BIT(KOMEDA_COMPONENT_SCALER0) |\
45 BIT(KOMEDA_COMPONENT_SCALER1))
46
47#define KOMEDA_PIPELINE_COMPIZS (BIT(KOMEDA_COMPONENT_COMPIZ0) |\
48 BIT(KOMEDA_COMPONENT_COMPIZ1))
49
50#define KOMEDA_PIPELINE_IMPROCS (BIT(KOMEDA_COMPONENT_IPS0) |\
51 BIT(KOMEDA_COMPONENT_IPS1))
52struct komeda_component;
53struct komeda_component_state;
54
55
56struct komeda_component_funcs {
57
58
59
60
61 int (*validate)(struct komeda_component *c,
62 struct komeda_component_state *state);
63
64 void (*update)(struct komeda_component *c,
65 struct komeda_component_state *state);
66
67 void (*disable)(struct komeda_component *c);
68
69 void (*dump_register)(struct komeda_component *c, struct seq_file *seq);
70};
71
72
73
74
75
76
77
78
79struct komeda_component {
80
81 struct drm_private_obj obj;
82
83 struct komeda_pipeline *pipeline;
84
85 char name[32];
86
87
88
89
90
91 u32 __iomem *reg;
92
93 u32 id;
94
95
96
97
98 u32 hw_id;
99
100
101
102
103
104
105
106
107
108
109
110 u8 max_active_inputs;
111
112 u8 max_active_outputs;
113
114
115
116
117
118
119
120
121 u32 supported_inputs;
122
123 u32 supported_outputs;
124
125
126
127
128 const struct komeda_component_funcs *funcs;
129};
130
131
132
133
134
135
136
137
138struct komeda_component_output {
139
140 struct komeda_component *component;
141
142
143
144
145 u8 output_port;
146};
147
148
149
150
151
152
153
154
155struct komeda_component_state {
156
157 struct drm_private_state obj;
158
159 struct komeda_component *component;
160
161
162
163
164
165
166
167
168
169
170 union {
171
172 struct drm_crtc *crtc;
173
174 struct drm_plane *plane;
175
176 struct drm_connector *wb_conn;
177 void *binding_user;
178 };
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195 u16 active_inputs;
196
197 u16 changed_active_inputs;
198
199 u16 affected_inputs;
200
201
202
203
204
205
206 struct komeda_component_output inputs[KOMEDA_COMPONENT_N_INPUTS];
207};
208
209static inline u16 component_disabling_inputs(struct komeda_component_state *st)
210{
211 return st->affected_inputs ^ st->active_inputs;
212}
213
214static inline u16 component_changed_inputs(struct komeda_component_state *st)
215{
216 return component_disabling_inputs(st) | st->changed_active_inputs;
217}
218
219#define for_each_changed_input(st, i) \
220 for ((i) = 0; (i) < (st)->component->max_active_inputs; (i)++) \
221 if (has_bit((i), component_changed_inputs(st)))
222
223#define to_comp(__c) (((__c) == NULL) ? NULL : &((__c)->base))
224#define to_cpos(__c) ((struct komeda_component **)&(__c))
225
226struct komeda_layer {
227 struct komeda_component base;
228
229 struct malidp_range hsize_in, vsize_in;
230 u32 layer_type;
231 u32 line_sz;
232 u32 yuv_line_sz;
233 u32 supported_rots;
234
235
236
237
238
239 struct komeda_layer *right;
240};
241
242struct komeda_layer_state {
243 struct komeda_component_state base;
244
245 u16 hsize, vsize;
246 u32 rot;
247 u16 afbc_crop_l;
248 u16 afbc_crop_r;
249 u16 afbc_crop_t;
250 u16 afbc_crop_b;
251 dma_addr_t addr[3];
252};
253
254struct komeda_scaler {
255 struct komeda_component base;
256 struct malidp_range hsize, vsize;
257 u32 max_upscaling;
258 u32 max_downscaling;
259 u8 scaling_split_overlap;
260 u8 enh_split_overlap;
261};
262
263struct komeda_scaler_state {
264 struct komeda_component_state base;
265 u16 hsize_in, vsize_in;
266 u16 hsize_out, vsize_out;
267 u16 total_hsize_in, total_vsize_in;
268 u16 total_hsize_out;
269 u16 left_crop, right_crop;
270 u8 en_scaling : 1,
271 en_alpha : 1,
272 en_img_enhancement : 1,
273 en_split : 1,
274 right_part : 1;
275};
276
277struct komeda_compiz {
278 struct komeda_component base;
279 struct malidp_range hsize, vsize;
280};
281
282struct komeda_compiz_input_cfg {
283 u16 hsize, vsize;
284 u16 hoffset, voffset;
285 u8 pixel_blend_mode, layer_alpha;
286};
287
288struct komeda_compiz_state {
289 struct komeda_component_state base;
290
291 u16 hsize, vsize;
292 struct komeda_compiz_input_cfg cins[KOMEDA_COMPONENT_N_INPUTS];
293};
294
295struct komeda_merger {
296 struct komeda_component base;
297 struct malidp_range hsize_merged;
298 struct malidp_range vsize_merged;
299};
300
301struct komeda_merger_state {
302 struct komeda_component_state base;
303 u16 hsize_merged;
304 u16 vsize_merged;
305};
306
307struct komeda_splitter {
308 struct komeda_component base;
309 struct malidp_range hsize, vsize;
310};
311
312struct komeda_splitter_state {
313 struct komeda_component_state base;
314 u16 hsize, vsize;
315 u16 overlap;
316};
317
318struct komeda_improc {
319 struct komeda_component base;
320 u32 supported_color_formats;
321 u32 supported_color_depths;
322 u8 supports_degamma : 1;
323 u8 supports_csc : 1;
324 u8 supports_gamma : 1;
325};
326
327struct komeda_improc_state {
328 struct komeda_component_state base;
329 u8 color_format, color_depth;
330 u16 hsize, vsize;
331 u32 fgamma_coeffs[KOMEDA_N_GAMMA_COEFFS];
332 u32 ctm_coeffs[KOMEDA_N_CTM_COEFFS];
333};
334
335
336struct komeda_timing_ctrlr {
337 struct komeda_component base;
338 u8 supports_dual_link : 1;
339};
340
341struct komeda_timing_ctrlr_state {
342 struct komeda_component_state base;
343};
344
345
346
347
348
349
350
351
352struct komeda_data_flow_cfg {
353 struct komeda_component_output input;
354 u16 in_x, in_y, in_w, in_h;
355 u32 out_x, out_y, out_w, out_h;
356 u16 total_in_h, total_in_w;
357 u16 total_out_w;
358 u16 left_crop, right_crop, overlap;
359 u32 rot;
360 int blending_zorder;
361 u8 pixel_blend_mode, layer_alpha;
362 u8 en_scaling : 1,
363 en_img_enhancement : 1,
364 en_split : 1,
365 is_yuv : 1,
366 right_part : 1;
367};
368
369struct komeda_pipeline_funcs {
370
371
372
373 int (*downscaling_clk_check)(struct komeda_pipeline *pipe,
374 struct drm_display_mode *mode,
375 unsigned long aclk_rate,
376 struct komeda_data_flow_cfg *dflow);
377
378 void (*dump_register)(struct komeda_pipeline *pipe,
379 struct seq_file *sf);
380};
381
382
383
384
385
386
387struct komeda_pipeline {
388
389 struct drm_private_obj obj;
390
391 struct komeda_dev *mdev;
392
393 struct clk *pxlclk;
394
395 int id;
396
397 u32 avail_comps;
398
399
400
401
402
403
404
405
406
407
408
409 u32 standalone_disabled_comps;
410
411 int n_layers;
412
413 struct komeda_layer *layers[KOMEDA_PIPELINE_MAX_LAYERS];
414
415 int n_scalers;
416
417 struct komeda_scaler *scalers[KOMEDA_PIPELINE_MAX_SCALERS];
418
419 struct komeda_compiz *compiz;
420
421 struct komeda_splitter *splitter;
422
423 struct komeda_merger *merger;
424
425 struct komeda_layer *wb_layer;
426
427 struct komeda_improc *improc;
428
429 struct komeda_timing_ctrlr *ctrlr;
430
431 const struct komeda_pipeline_funcs *funcs;
432
433
434 struct device_node *of_node;
435
436 struct device_node *of_output_port;
437
438 struct device_node *of_output_links[2];
439
440 bool dual_link;
441};
442
443
444
445
446
447
448
449
450struct komeda_pipeline_state {
451
452 struct drm_private_state obj;
453
454 struct komeda_pipeline *pipe;
455
456 struct drm_crtc *crtc;
457
458
459
460
461
462 u32 active_comps;
463};
464
465#define to_layer(c) container_of(c, struct komeda_layer, base)
466#define to_compiz(c) container_of(c, struct komeda_compiz, base)
467#define to_scaler(c) container_of(c, struct komeda_scaler, base)
468#define to_splitter(c) container_of(c, struct komeda_splitter, base)
469#define to_merger(c) container_of(c, struct komeda_merger, base)
470#define to_improc(c) container_of(c, struct komeda_improc, base)
471#define to_ctrlr(c) container_of(c, struct komeda_timing_ctrlr, base)
472
473#define to_layer_st(c) container_of(c, struct komeda_layer_state, base)
474#define to_compiz_st(c) container_of(c, struct komeda_compiz_state, base)
475#define to_scaler_st(c) container_of(c, struct komeda_scaler_state, base)
476#define to_splitter_st(c) container_of(c, struct komeda_splitter_state, base)
477#define to_merger_st(c) container_of(c, struct komeda_merger_state, base)
478#define to_improc_st(c) container_of(c, struct komeda_improc_state, base)
479#define to_ctrlr_st(c) container_of(c, struct komeda_timing_ctrlr_state, base)
480
481#define priv_to_comp_st(o) container_of(o, struct komeda_component_state, obj)
482#define priv_to_pipe_st(o) container_of(o, struct komeda_pipeline_state, obj)
483
484
485struct komeda_pipeline *
486komeda_pipeline_add(struct komeda_dev *mdev, size_t size,
487 const struct komeda_pipeline_funcs *funcs);
488void komeda_pipeline_destroy(struct komeda_dev *mdev,
489 struct komeda_pipeline *pipe);
490struct komeda_pipeline *
491komeda_pipeline_get_slave(struct komeda_pipeline *master);
492int komeda_assemble_pipelines(struct komeda_dev *mdev);
493struct komeda_component *
494komeda_pipeline_get_component(struct komeda_pipeline *pipe, int id);
495struct komeda_component *
496komeda_pipeline_get_first_component(struct komeda_pipeline *pipe,
497 u32 comp_mask);
498
499void komeda_pipeline_dump_register(struct komeda_pipeline *pipe,
500 struct seq_file *sf);
501
502
503extern __printf(10, 11)
504struct komeda_component *
505komeda_component_add(struct komeda_pipeline *pipe,
506 size_t comp_sz, u32 id, u32 hw_id,
507 const struct komeda_component_funcs *funcs,
508 u8 max_active_inputs, u32 supported_inputs,
509 u8 max_active_outputs, u32 __iomem *reg,
510 const char *name_fmt, ...);
511
512void komeda_component_destroy(struct komeda_dev *mdev,
513 struct komeda_component *c);
514
515static inline struct komeda_component *
516komeda_component_pickup_output(struct komeda_component *c, u32 avail_comps)
517{
518 u32 avail_inputs = c->supported_outputs & (avail_comps);
519
520 return komeda_pipeline_get_first_component(c->pipeline, avail_inputs);
521}
522
523struct komeda_plane_state;
524struct komeda_crtc_state;
525struct komeda_crtc;
526
527void pipeline_composition_size(struct komeda_crtc_state *kcrtc_st,
528 u16 *hsize, u16 *vsize);
529
530int komeda_build_layer_data_flow(struct komeda_layer *layer,
531 struct komeda_plane_state *kplane_st,
532 struct komeda_crtc_state *kcrtc_st,
533 struct komeda_data_flow_cfg *dflow);
534int komeda_build_wb_data_flow(struct komeda_layer *wb_layer,
535 struct drm_connector_state *conn_st,
536 struct komeda_crtc_state *kcrtc_st,
537 struct komeda_data_flow_cfg *dflow);
538int komeda_build_display_data_flow(struct komeda_crtc *kcrtc,
539 struct komeda_crtc_state *kcrtc_st);
540
541int komeda_build_layer_split_data_flow(struct komeda_layer *left,
542 struct komeda_plane_state *kplane_st,
543 struct komeda_crtc_state *kcrtc_st,
544 struct komeda_data_flow_cfg *dflow);
545int komeda_build_wb_split_data_flow(struct komeda_layer *wb_layer,
546 struct drm_connector_state *conn_st,
547 struct komeda_crtc_state *kcrtc_st,
548 struct komeda_data_flow_cfg *dflow);
549
550int komeda_release_unclaimed_resources(struct komeda_pipeline *pipe,
551 struct komeda_crtc_state *kcrtc_st);
552
553struct komeda_pipeline_state *
554komeda_pipeline_get_old_state(struct komeda_pipeline *pipe,
555 struct drm_atomic_state *state);
556bool komeda_pipeline_disable(struct komeda_pipeline *pipe,
557 struct drm_atomic_state *old_state);
558void komeda_pipeline_update(struct komeda_pipeline *pipe,
559 struct drm_atomic_state *old_state);
560
561void komeda_complete_data_flow_cfg(struct komeda_layer *layer,
562 struct komeda_data_flow_cfg *dflow,
563 struct drm_framebuffer *fb);
564
565#endif
566