@@ -207,6 +207,28 @@ static void mtk_crtc_ddp_clk_disable(struct mtk_drm_crtc *mtk_crtc)
207
207
clk_disable_unprepare (mtk_crtc -> ddp_comp [i ]-> clk );
208
208
}
209
209
210
+ static
211
+ struct mtk_ddp_comp * mtk_drm_ddp_comp_for_plane (struct drm_crtc * crtc ,
212
+ struct drm_plane * plane ,
213
+ unsigned int * local_layer )
214
+ {
215
+ struct mtk_drm_crtc * mtk_crtc = to_mtk_crtc (crtc );
216
+ struct mtk_ddp_comp * comp ;
217
+ int i , count = 0 ;
218
+
219
+ for (i = 0 ; i < mtk_crtc -> ddp_comp_nr ; i ++ ) {
220
+ comp = mtk_crtc -> ddp_comp [i ];
221
+ if (plane -> index < (count + mtk_ddp_comp_layer_nr (comp ))) {
222
+ * local_layer = plane -> index - count ;
223
+ return comp ;
224
+ }
225
+ count += mtk_ddp_comp_layer_nr (comp );
226
+ }
227
+
228
+ WARN (1 , "Failed to find component for plane %d\n" , plane -> index );
229
+ return NULL ;
230
+ }
231
+
210
232
static int mtk_crtc_ddp_hw_init (struct mtk_drm_crtc * mtk_crtc )
211
233
{
212
234
struct drm_crtc * crtc = & mtk_crtc -> base ;
@@ -283,19 +305,12 @@ static int mtk_crtc_ddp_hw_init(struct mtk_drm_crtc *mtk_crtc)
283
305
for (i = 0 ; i < mtk_crtc -> layer_nr ; i ++ ) {
284
306
struct drm_plane * plane = & mtk_crtc -> planes [i ];
285
307
struct mtk_plane_state * plane_state ;
286
- struct mtk_ddp_comp * comp = mtk_crtc -> ddp_comp [0 ];
287
- unsigned int comp_layer_nr = mtk_ddp_comp_layer_nr (comp );
308
+ struct mtk_ddp_comp * comp ;
288
309
unsigned int local_layer ;
289
310
290
311
plane_state = to_mtk_plane_state (plane -> state );
291
-
292
- if (i >= comp_layer_nr ) {
293
- comp = mtk_crtc -> ddp_comp [1 ];
294
- local_layer = i - comp_layer_nr ;
295
- } else
296
- local_layer = i ;
297
- mtk_ddp_comp_layer_config (comp , local_layer ,
298
- plane_state );
312
+ comp = mtk_drm_ddp_comp_for_plane (crtc , plane , & local_layer );
313
+ mtk_ddp_comp_layer_config (comp , local_layer , plane_state );
299
314
}
300
315
301
316
return 0 ;
@@ -343,7 +358,6 @@ static void mtk_crtc_ddp_config(struct drm_crtc *crtc)
343
358
struct mtk_crtc_state * state = to_mtk_crtc_state (mtk_crtc -> base .state );
344
359
struct mtk_ddp_comp * comp = mtk_crtc -> ddp_comp [0 ];
345
360
unsigned int i ;
346
- unsigned int comp_layer_nr = mtk_ddp_comp_layer_nr (comp );
347
361
unsigned int local_layer ;
348
362
349
363
/*
@@ -366,22 +380,30 @@ static void mtk_crtc_ddp_config(struct drm_crtc *crtc)
366
380
367
381
plane_state = to_mtk_plane_state (plane -> state );
368
382
369
- if (plane_state -> pending .config ) {
370
- if (i >= comp_layer_nr ) {
371
- comp = mtk_crtc -> ddp_comp [1 ];
372
- local_layer = i - comp_layer_nr ;
373
- } else
374
- local_layer = i ;
375
-
376
- mtk_ddp_comp_layer_config (comp , local_layer ,
377
- plane_state );
378
- plane_state -> pending .config = false;
379
- }
383
+ if (!plane_state -> pending .config )
384
+ continue ;
385
+
386
+ comp = mtk_drm_ddp_comp_for_plane (crtc , plane ,
387
+ & local_layer );
388
+
389
+ mtk_ddp_comp_layer_config (comp , local_layer ,
390
+ plane_state );
391
+ plane_state -> pending .config = false;
380
392
}
381
393
mtk_crtc -> pending_planes = false;
382
394
}
383
395
}
384
396
397
+ int mtk_drm_crtc_plane_check (struct drm_crtc * crtc , struct drm_plane * plane ,
398
+ struct mtk_plane_state * state )
399
+ {
400
+ unsigned int local_layer ;
401
+ struct mtk_ddp_comp * comp ;
402
+
403
+ comp = mtk_drm_ddp_comp_for_plane (crtc , plane , & local_layer );
404
+ return mtk_ddp_comp_layer_check (comp , local_layer , state );
405
+ }
406
+
385
407
static void mtk_drm_crtc_atomic_enable (struct drm_crtc * crtc ,
386
408
struct drm_crtc_state * old_state )
387
409
{
@@ -543,14 +565,65 @@ void mtk_crtc_ddp_irq(struct drm_crtc *crtc, struct mtk_ddp_comp *comp)
543
565
mtk_drm_finish_page_flip (mtk_crtc );
544
566
}
545
567
568
+ static int mtk_drm_crtc_num_comp_planes (struct mtk_drm_crtc * mtk_crtc ,
569
+ int comp_idx )
570
+ {
571
+ struct mtk_ddp_comp * comp ;
572
+
573
+ if (comp_idx > 1 )
574
+ return 0 ;
575
+
576
+ comp = mtk_crtc -> ddp_comp [comp_idx ];
577
+ if (!comp -> funcs )
578
+ return 0 ;
579
+
580
+ if (comp_idx == 1 && !comp -> funcs -> bgclr_in_on )
581
+ return 0 ;
582
+
583
+ return mtk_ddp_comp_layer_nr (comp );
584
+ }
585
+
586
+ static inline
587
+ enum drm_plane_type mtk_drm_crtc_plane_type (unsigned int plane_idx )
588
+ {
589
+ if (plane_idx == 0 )
590
+ return DRM_PLANE_TYPE_PRIMARY ;
591
+ else if (plane_idx == 1 )
592
+ return DRM_PLANE_TYPE_CURSOR ;
593
+ else
594
+ return DRM_PLANE_TYPE_OVERLAY ;
595
+
596
+ }
597
+
598
+ static int mtk_drm_crtc_init_comp_planes (struct drm_device * drm_dev ,
599
+ struct mtk_drm_crtc * mtk_crtc ,
600
+ int comp_idx , int pipe )
601
+ {
602
+ int num_planes = mtk_drm_crtc_num_comp_planes (mtk_crtc , comp_idx );
603
+ struct mtk_ddp_comp * comp = mtk_crtc -> ddp_comp [comp_idx ];
604
+ int i , ret ;
605
+
606
+ for (i = 0 ; i < num_planes ; i ++ ) {
607
+ ret = mtk_plane_init (drm_dev ,
608
+ & mtk_crtc -> planes [mtk_crtc -> layer_nr ],
609
+ BIT (pipe ),
610
+ mtk_drm_crtc_plane_type (mtk_crtc -> layer_nr ),
611
+ mtk_ddp_comp_supported_rotations (comp ));
612
+ if (ret )
613
+ return ret ;
614
+
615
+ mtk_crtc -> layer_nr ++ ;
616
+ }
617
+ return 0 ;
618
+ }
619
+
546
620
int mtk_drm_crtc_create (struct drm_device * drm_dev ,
547
621
const enum mtk_ddp_comp_id * path , unsigned int path_len )
548
622
{
549
623
struct mtk_drm_private * priv = drm_dev -> dev_private ;
550
624
struct device * dev = drm_dev -> dev ;
551
625
struct mtk_drm_crtc * mtk_crtc ;
552
- enum drm_plane_type type ;
553
- unsigned int zpos ;
626
+ unsigned int num_comp_planes = 0 ;
554
627
int pipe = priv -> num_pipes ;
555
628
int ret ;
556
629
int i ;
@@ -606,23 +679,15 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
606
679
mtk_crtc -> ddp_comp [i ] = comp ;
607
680
}
608
681
609
- mtk_crtc -> layer_nr = mtk_ddp_comp_layer_nr (mtk_crtc -> ddp_comp [0 ]);
610
- if (mtk_crtc -> ddp_comp_nr > 1 ) {
611
- struct mtk_ddp_comp * comp = mtk_crtc -> ddp_comp [1 ];
682
+ for (i = 0 ; i < mtk_crtc -> ddp_comp_nr ; i ++ )
683
+ num_comp_planes += mtk_drm_crtc_num_comp_planes (mtk_crtc , i );
612
684
613
- if (comp -> funcs -> bgclr_in_on )
614
- mtk_crtc -> layer_nr += mtk_ddp_comp_layer_nr (comp );
615
- }
616
- mtk_crtc -> planes = devm_kcalloc (dev , mtk_crtc -> layer_nr ,
617
- sizeof (struct drm_plane ),
618
- GFP_KERNEL );
619
-
620
- for (zpos = 0 ; zpos < mtk_crtc -> layer_nr ; zpos ++ ) {
621
- type = (zpos == 0 ) ? DRM_PLANE_TYPE_PRIMARY :
622
- (zpos == 1 ) ? DRM_PLANE_TYPE_CURSOR :
623
- DRM_PLANE_TYPE_OVERLAY ;
624
- ret = mtk_plane_init (drm_dev , & mtk_crtc -> planes [zpos ],
625
- BIT (pipe ), type );
685
+ mtk_crtc -> planes = devm_kcalloc (dev , num_comp_planes ,
686
+ sizeof (struct drm_plane ), GFP_KERNEL );
687
+
688
+ for (i = 0 ; i < mtk_crtc -> ddp_comp_nr ; i ++ ) {
689
+ ret = mtk_drm_crtc_init_comp_planes (drm_dev , mtk_crtc , i ,
690
+ pipe );
626
691
if (ret )
627
692
return ret ;
628
693
}
0 commit comments