0001
0002
0003
0004
0005
0006
0007 #ifndef _KOMEDA_PIPELINE_H_
0008 #define _KOMEDA_PIPELINE_H_
0009
0010 #include <linux/types.h>
0011 #include <drm/drm_atomic.h>
0012 #include <drm/drm_atomic_helper.h>
0013 #include "malidp_utils.h"
0014 #include "komeda_color_mgmt.h"
0015
0016 #define KOMEDA_MAX_PIPELINES 2
0017 #define KOMEDA_PIPELINE_MAX_LAYERS 4
0018 #define KOMEDA_PIPELINE_MAX_SCALERS 2
0019 #define KOMEDA_COMPONENT_N_INPUTS 5
0020
0021
0022 enum {
0023 KOMEDA_COMPONENT_LAYER0 = 0,
0024 KOMEDA_COMPONENT_LAYER1 = 1,
0025 KOMEDA_COMPONENT_LAYER2 = 2,
0026 KOMEDA_COMPONENT_LAYER3 = 3,
0027 KOMEDA_COMPONENT_WB_LAYER = 7,
0028 KOMEDA_COMPONENT_SCALER0 = 8,
0029 KOMEDA_COMPONENT_SCALER1 = 9,
0030 KOMEDA_COMPONENT_SPLITTER = 12,
0031 KOMEDA_COMPONENT_MERGER = 14,
0032 KOMEDA_COMPONENT_COMPIZ0 = 16,
0033 KOMEDA_COMPONENT_COMPIZ1 = 17,
0034 KOMEDA_COMPONENT_IPS0 = 20,
0035 KOMEDA_COMPONENT_IPS1 = 21,
0036 KOMEDA_COMPONENT_TIMING_CTRLR = 22,
0037 };
0038
0039 #define KOMEDA_PIPELINE_LAYERS (BIT(KOMEDA_COMPONENT_LAYER0) |\
0040 BIT(KOMEDA_COMPONENT_LAYER1) |\
0041 BIT(KOMEDA_COMPONENT_LAYER2) |\
0042 BIT(KOMEDA_COMPONENT_LAYER3))
0043
0044 #define KOMEDA_PIPELINE_SCALERS (BIT(KOMEDA_COMPONENT_SCALER0) |\
0045 BIT(KOMEDA_COMPONENT_SCALER1))
0046
0047 #define KOMEDA_PIPELINE_COMPIZS (BIT(KOMEDA_COMPONENT_COMPIZ0) |\
0048 BIT(KOMEDA_COMPONENT_COMPIZ1))
0049
0050 #define KOMEDA_PIPELINE_IMPROCS (BIT(KOMEDA_COMPONENT_IPS0) |\
0051 BIT(KOMEDA_COMPONENT_IPS1))
0052 struct komeda_component;
0053 struct komeda_component_state;
0054
0055
0056 struct komeda_component_funcs {
0057
0058
0059
0060
0061 int (*validate)(struct komeda_component *c,
0062 struct komeda_component_state *state);
0063
0064 void (*update)(struct komeda_component *c,
0065 struct komeda_component_state *state);
0066
0067 void (*disable)(struct komeda_component *c);
0068
0069 void (*dump_register)(struct komeda_component *c, struct seq_file *seq);
0070 };
0071
0072
0073
0074
0075
0076
0077
0078
0079 struct komeda_component {
0080
0081 struct drm_private_obj obj;
0082
0083 struct komeda_pipeline *pipeline;
0084
0085 char name[32];
0086
0087
0088
0089
0090
0091 u32 __iomem *reg;
0092
0093 u32 id;
0094
0095
0096
0097
0098 u32 hw_id;
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110 u8 max_active_inputs;
0111
0112 u8 max_active_outputs;
0113
0114
0115
0116
0117
0118
0119
0120
0121 u32 supported_inputs;
0122
0123 u32 supported_outputs;
0124
0125
0126
0127
0128 const struct komeda_component_funcs *funcs;
0129 };
0130
0131
0132
0133
0134
0135
0136
0137
0138 struct komeda_component_output {
0139
0140 struct komeda_component *component;
0141
0142
0143
0144
0145 u8 output_port;
0146 };
0147
0148
0149
0150
0151
0152
0153
0154
0155 struct komeda_component_state {
0156
0157 struct drm_private_state obj;
0158
0159 struct komeda_component *component;
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170 union {
0171
0172 struct drm_crtc *crtc;
0173
0174 struct drm_plane *plane;
0175
0176 struct drm_connector *wb_conn;
0177 void *binding_user;
0178 };
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195 u16 active_inputs;
0196
0197 u16 changed_active_inputs;
0198
0199 u16 affected_inputs;
0200
0201
0202
0203
0204
0205
0206 struct komeda_component_output inputs[KOMEDA_COMPONENT_N_INPUTS];
0207 };
0208
0209 static inline u16 component_disabling_inputs(struct komeda_component_state *st)
0210 {
0211 return st->affected_inputs ^ st->active_inputs;
0212 }
0213
0214 static inline u16 component_changed_inputs(struct komeda_component_state *st)
0215 {
0216 return component_disabling_inputs(st) | st->changed_active_inputs;
0217 }
0218
0219 #define for_each_changed_input(st, i) \
0220 for ((i) = 0; (i) < (st)->component->max_active_inputs; (i)++) \
0221 if (has_bit((i), component_changed_inputs(st)))
0222
0223 #define to_comp(__c) (((__c) == NULL) ? NULL : &((__c)->base))
0224 #define to_cpos(__c) ((struct komeda_component **)&(__c))
0225
0226 struct komeda_layer {
0227 struct komeda_component base;
0228
0229 struct malidp_range hsize_in, vsize_in;
0230 u32 layer_type;
0231 u32 line_sz;
0232 u32 yuv_line_sz;
0233 u32 supported_rots;
0234
0235
0236
0237
0238
0239 struct komeda_layer *right;
0240 };
0241
0242 struct komeda_layer_state {
0243 struct komeda_component_state base;
0244
0245 u16 hsize, vsize;
0246 u32 rot;
0247 u16 afbc_crop_l;
0248 u16 afbc_crop_r;
0249 u16 afbc_crop_t;
0250 u16 afbc_crop_b;
0251 dma_addr_t addr[3];
0252 };
0253
0254 struct komeda_scaler {
0255 struct komeda_component base;
0256 struct malidp_range hsize, vsize;
0257 u32 max_upscaling;
0258 u32 max_downscaling;
0259 u8 scaling_split_overlap;
0260 u8 enh_split_overlap;
0261 };
0262
0263 struct komeda_scaler_state {
0264 struct komeda_component_state base;
0265 u16 hsize_in, vsize_in;
0266 u16 hsize_out, vsize_out;
0267 u16 total_hsize_in, total_vsize_in;
0268 u16 total_hsize_out;
0269 u16 left_crop, right_crop;
0270 u8 en_scaling : 1,
0271 en_alpha : 1,
0272 en_img_enhancement : 1,
0273 en_split : 1,
0274 right_part : 1;
0275 };
0276
0277 struct komeda_compiz {
0278 struct komeda_component base;
0279 struct malidp_range hsize, vsize;
0280 };
0281
0282 struct komeda_compiz_input_cfg {
0283 u16 hsize, vsize;
0284 u16 hoffset, voffset;
0285 u8 pixel_blend_mode, layer_alpha;
0286 };
0287
0288 struct komeda_compiz_state {
0289 struct komeda_component_state base;
0290
0291 u16 hsize, vsize;
0292 struct komeda_compiz_input_cfg cins[KOMEDA_COMPONENT_N_INPUTS];
0293 };
0294
0295 struct komeda_merger {
0296 struct komeda_component base;
0297 struct malidp_range hsize_merged;
0298 struct malidp_range vsize_merged;
0299 };
0300
0301 struct komeda_merger_state {
0302 struct komeda_component_state base;
0303 u16 hsize_merged;
0304 u16 vsize_merged;
0305 };
0306
0307 struct komeda_splitter {
0308 struct komeda_component base;
0309 struct malidp_range hsize, vsize;
0310 };
0311
0312 struct komeda_splitter_state {
0313 struct komeda_component_state base;
0314 u16 hsize, vsize;
0315 u16 overlap;
0316 };
0317
0318 struct komeda_improc {
0319 struct komeda_component base;
0320 u32 supported_color_formats;
0321 u32 supported_color_depths;
0322 u8 supports_degamma : 1;
0323 u8 supports_csc : 1;
0324 u8 supports_gamma : 1;
0325 };
0326
0327 struct komeda_improc_state {
0328 struct komeda_component_state base;
0329 u8 color_format, color_depth;
0330 u16 hsize, vsize;
0331 u32 fgamma_coeffs[KOMEDA_N_GAMMA_COEFFS];
0332 u32 ctm_coeffs[KOMEDA_N_CTM_COEFFS];
0333 };
0334
0335
0336 struct komeda_timing_ctrlr {
0337 struct komeda_component base;
0338 u8 supports_dual_link : 1;
0339 };
0340
0341 struct komeda_timing_ctrlr_state {
0342 struct komeda_component_state base;
0343 };
0344
0345
0346
0347
0348
0349
0350
0351
0352 struct komeda_data_flow_cfg {
0353 struct komeda_component_output input;
0354 u16 in_x, in_y, in_w, in_h;
0355 u32 out_x, out_y, out_w, out_h;
0356 u16 total_in_h, total_in_w;
0357 u16 total_out_w;
0358 u16 left_crop, right_crop, overlap;
0359 u32 rot;
0360 int blending_zorder;
0361 u8 pixel_blend_mode, layer_alpha;
0362 u8 en_scaling : 1,
0363 en_img_enhancement : 1,
0364 en_split : 1,
0365 is_yuv : 1,
0366 right_part : 1;
0367 };
0368
0369 struct komeda_pipeline_funcs {
0370
0371
0372
0373 int (*downscaling_clk_check)(struct komeda_pipeline *pipe,
0374 struct drm_display_mode *mode,
0375 unsigned long aclk_rate,
0376 struct komeda_data_flow_cfg *dflow);
0377
0378 void (*dump_register)(struct komeda_pipeline *pipe,
0379 struct seq_file *sf);
0380 };
0381
0382
0383
0384
0385
0386
0387 struct komeda_pipeline {
0388
0389 struct drm_private_obj obj;
0390
0391 struct komeda_dev *mdev;
0392
0393 struct clk *pxlclk;
0394
0395 int id;
0396
0397 u32 avail_comps;
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409 u32 standalone_disabled_comps;
0410
0411 int n_layers;
0412
0413 struct komeda_layer *layers[KOMEDA_PIPELINE_MAX_LAYERS];
0414
0415 int n_scalers;
0416
0417 struct komeda_scaler *scalers[KOMEDA_PIPELINE_MAX_SCALERS];
0418
0419 struct komeda_compiz *compiz;
0420
0421 struct komeda_splitter *splitter;
0422
0423 struct komeda_merger *merger;
0424
0425 struct komeda_layer *wb_layer;
0426
0427 struct komeda_improc *improc;
0428
0429 struct komeda_timing_ctrlr *ctrlr;
0430
0431 const struct komeda_pipeline_funcs *funcs;
0432
0433
0434 struct device_node *of_node;
0435
0436 struct device_node *of_output_port;
0437
0438 struct device_node *of_output_links[2];
0439
0440 bool dual_link;
0441 };
0442
0443
0444
0445
0446
0447
0448
0449
0450 struct komeda_pipeline_state {
0451
0452 struct drm_private_state obj;
0453
0454 struct komeda_pipeline *pipe;
0455
0456 struct drm_crtc *crtc;
0457
0458
0459
0460
0461
0462 u32 active_comps;
0463 };
0464
0465 #define to_layer(c) container_of(c, struct komeda_layer, base)
0466 #define to_compiz(c) container_of(c, struct komeda_compiz, base)
0467 #define to_scaler(c) container_of(c, struct komeda_scaler, base)
0468 #define to_splitter(c) container_of(c, struct komeda_splitter, base)
0469 #define to_merger(c) container_of(c, struct komeda_merger, base)
0470 #define to_improc(c) container_of(c, struct komeda_improc, base)
0471 #define to_ctrlr(c) container_of(c, struct komeda_timing_ctrlr, base)
0472
0473 #define to_layer_st(c) container_of(c, struct komeda_layer_state, base)
0474 #define to_compiz_st(c) container_of(c, struct komeda_compiz_state, base)
0475 #define to_scaler_st(c) container_of(c, struct komeda_scaler_state, base)
0476 #define to_splitter_st(c) container_of(c, struct komeda_splitter_state, base)
0477 #define to_merger_st(c) container_of(c, struct komeda_merger_state, base)
0478 #define to_improc_st(c) container_of(c, struct komeda_improc_state, base)
0479 #define to_ctrlr_st(c) container_of(c, struct komeda_timing_ctrlr_state, base)
0480
0481 #define priv_to_comp_st(o) container_of(o, struct komeda_component_state, obj)
0482 #define priv_to_pipe_st(o) container_of(o, struct komeda_pipeline_state, obj)
0483
0484
0485 struct komeda_pipeline *
0486 komeda_pipeline_add(struct komeda_dev *mdev, size_t size,
0487 const struct komeda_pipeline_funcs *funcs);
0488 void komeda_pipeline_destroy(struct komeda_dev *mdev,
0489 struct komeda_pipeline *pipe);
0490 struct komeda_pipeline *
0491 komeda_pipeline_get_slave(struct komeda_pipeline *master);
0492 int komeda_assemble_pipelines(struct komeda_dev *mdev);
0493 struct komeda_component *
0494 komeda_pipeline_get_component(struct komeda_pipeline *pipe, int id);
0495 struct komeda_component *
0496 komeda_pipeline_get_first_component(struct komeda_pipeline *pipe,
0497 u32 comp_mask);
0498
0499 void komeda_pipeline_dump_register(struct komeda_pipeline *pipe,
0500 struct seq_file *sf);
0501
0502
0503 extern __printf(10, 11)
0504 struct komeda_component *
0505 komeda_component_add(struct komeda_pipeline *pipe,
0506 size_t comp_sz, u32 id, u32 hw_id,
0507 const struct komeda_component_funcs *funcs,
0508 u8 max_active_inputs, u32 supported_inputs,
0509 u8 max_active_outputs, u32 __iomem *reg,
0510 const char *name_fmt, ...);
0511
0512 void komeda_component_destroy(struct komeda_dev *mdev,
0513 struct komeda_component *c);
0514
0515 static inline struct komeda_component *
0516 komeda_component_pickup_output(struct komeda_component *c, u32 avail_comps)
0517 {
0518 u32 avail_inputs = c->supported_outputs & (avail_comps);
0519
0520 return komeda_pipeline_get_first_component(c->pipeline, avail_inputs);
0521 }
0522
0523 struct komeda_plane_state;
0524 struct komeda_crtc_state;
0525 struct komeda_crtc;
0526
0527 void pipeline_composition_size(struct komeda_crtc_state *kcrtc_st,
0528 u16 *hsize, u16 *vsize);
0529
0530 int komeda_build_layer_data_flow(struct komeda_layer *layer,
0531 struct komeda_plane_state *kplane_st,
0532 struct komeda_crtc_state *kcrtc_st,
0533 struct komeda_data_flow_cfg *dflow);
0534 int komeda_build_wb_data_flow(struct komeda_layer *wb_layer,
0535 struct drm_connector_state *conn_st,
0536 struct komeda_crtc_state *kcrtc_st,
0537 struct komeda_data_flow_cfg *dflow);
0538 int komeda_build_display_data_flow(struct komeda_crtc *kcrtc,
0539 struct komeda_crtc_state *kcrtc_st);
0540
0541 int komeda_build_layer_split_data_flow(struct komeda_layer *left,
0542 struct komeda_plane_state *kplane_st,
0543 struct komeda_crtc_state *kcrtc_st,
0544 struct komeda_data_flow_cfg *dflow);
0545 int komeda_build_wb_split_data_flow(struct komeda_layer *wb_layer,
0546 struct drm_connector_state *conn_st,
0547 struct komeda_crtc_state *kcrtc_st,
0548 struct komeda_data_flow_cfg *dflow);
0549
0550 int komeda_release_unclaimed_resources(struct komeda_pipeline *pipe,
0551 struct komeda_crtc_state *kcrtc_st);
0552
0553 struct komeda_pipeline_state *
0554 komeda_pipeline_get_old_state(struct komeda_pipeline *pipe,
0555 struct drm_atomic_state *state);
0556 bool komeda_pipeline_disable(struct komeda_pipeline *pipe,
0557 struct drm_atomic_state *old_state);
0558 void komeda_pipeline_update(struct komeda_pipeline *pipe,
0559 struct drm_atomic_state *old_state);
0560
0561 void komeda_complete_data_flow_cfg(struct komeda_layer *layer,
0562 struct komeda_data_flow_cfg *dflow,
0563 struct drm_framebuffer *fb);
0564
0565 #endif