65
65
#define OVL_CON_CLRFMT_RGB (1 << 12)
66
66
#define OVL_CON_CLRFMT_ARGB8888 (2 << 12)
67
67
#define OVL_CON_CLRFMT_RGBA8888 (3 << 12)
68
- #define OVL_CON_CLRFMT_ABGR8888 (OVL_CON_CLRFMT_RGBA8888 | OVL_CON_BYTE_SWAP)
69
- #define OVL_CON_CLRFMT_BGRA8888 (OVL_CON_CLRFMT_ARGB8888 | OVL_CON_BYTE_SWAP)
68
+ #define OVL_CON_CLRFMT_ABGR8888 (OVL_CON_CLRFMT_ARGB8888 | OVL_CON_BYTE_SWAP)
69
+ #define OVL_CON_CLRFMT_BGRA8888 (OVL_CON_CLRFMT_RGBA8888 | OVL_CON_BYTE_SWAP)
70
70
#define OVL_CON_CLRFMT_UYVY (4 << 12)
71
71
#define OVL_CON_CLRFMT_YUYV (5 << 12)
72
72
#define OVL_CON_MTX_YUV_TO_RGB (6 << 16)
@@ -146,6 +146,7 @@ struct mtk_disp_ovl_data {
146
146
bool fmt_rgb565_is_0 ;
147
147
bool smi_id_en ;
148
148
bool supports_afbc ;
149
+ const u32 blend_modes ;
149
150
const u32 * formats ;
150
151
size_t num_formats ;
151
152
bool supports_clrfmt_ext ;
@@ -214,6 +215,13 @@ void mtk_ovl_disable_vblank(struct device *dev)
214
215
writel_relaxed (0x0 , ovl -> regs + DISP_REG_OVL_INTEN );
215
216
}
216
217
218
+ u32 mtk_ovl_get_blend_modes (struct device * dev )
219
+ {
220
+ struct mtk_disp_ovl * ovl = dev_get_drvdata (dev );
221
+
222
+ return ovl -> data -> blend_modes ;
223
+ }
224
+
217
225
const u32 * mtk_ovl_get_formats (struct device * dev )
218
226
{
219
227
struct mtk_disp_ovl * ovl = dev_get_drvdata (dev );
@@ -386,14 +394,27 @@ void mtk_ovl_layer_off(struct device *dev, unsigned int idx,
386
394
DISP_REG_OVL_RDMA_CTRL (idx ));
387
395
}
388
396
389
- static unsigned int ovl_fmt_convert (struct mtk_disp_ovl * ovl , unsigned int fmt ,
390
- unsigned int blend_mode )
397
+ static unsigned int mtk_ovl_fmt_convert (struct mtk_disp_ovl * ovl ,
398
+ struct mtk_plane_state * state )
391
399
{
392
- /* The return value in switch "MEM_MODE_INPUT_FORMAT_XXX"
393
- * is defined in mediatek HW data sheet.
394
- * The alphabet order in XXX is no relation to data
395
- * arrangement in memory.
400
+ unsigned int fmt = state -> pending .format ;
401
+ unsigned int blend_mode = DRM_MODE_BLEND_COVERAGE ;
402
+
403
+ /*
404
+ * For the platforms where OVL_CON_CLRFMT_MAN is defined in the hardware data sheet
405
+ * and supports premultiplied color formats, such as OVL_CON_CLRFMT_PARGB8888.
406
+ *
407
+ * Check blend_modes in the driver data to see if premultiplied mode is supported.
408
+ * If not, use coverage mode instead to set it to the supported color formats.
409
+ *
410
+ * Current DRM assumption is that alpha is default premultiplied, so the bitmask of
411
+ * blend_modes must include BIT(DRM_MODE_BLEND_PREMULTI). Otherwise, mtk_plane_init()
412
+ * will get an error return from drm_plane_create_blend_mode_property() and
413
+ * state->base.pixel_blend_mode should not be used.
396
414
*/
415
+ if (ovl -> data -> blend_modes & BIT (DRM_MODE_BLEND_PREMULTI ))
416
+ blend_mode = state -> base .pixel_blend_mode ;
417
+
397
418
switch (fmt ) {
398
419
default :
399
420
case DRM_FORMAT_RGB565 :
@@ -471,20 +492,26 @@ void mtk_ovl_layer_config(struct device *dev, unsigned int idx,
471
492
return ;
472
493
}
473
494
474
- con = ovl_fmt_convert (ovl , fmt , blend_mode );
495
+ con = mtk_ovl_fmt_convert (ovl , state );
475
496
if (state -> base .fb ) {
476
- con |= OVL_CON_AEN ;
477
497
con |= state -> base .alpha & OVL_CON_ALPHA ;
478
- }
479
498
480
- /* CONST_BLD must be enabled for XRGB formats although the alpha channel
481
- * can be ignored, or OVL will still read the value from memory.
482
- * For RGB888 related formats, whether CONST_BLD is enabled or not won't
483
- * affect the result. Therefore we use !has_alpha as the condition.
484
- */
485
- if ((state -> base .fb && !state -> base .fb -> format -> has_alpha ) ||
486
- blend_mode == DRM_MODE_BLEND_PIXEL_NONE )
487
- ignore_pixel_alpha = OVL_CONST_BLEND ;
499
+ /*
500
+ * For blend_modes supported SoCs, always enable alpha blending.
501
+ * For blend_modes unsupported SoCs, enable alpha blending when has_alpha is set.
502
+ */
503
+ if (blend_mode || state -> base .fb -> format -> has_alpha )
504
+ con |= OVL_CON_AEN ;
505
+
506
+ /*
507
+ * Although the alpha channel can be ignored, CONST_BLD must be enabled
508
+ * for XRGB format, otherwise OVL will still read the value from memory.
509
+ * For RGB888 related formats, whether CONST_BLD is enabled or not won't
510
+ * affect the result. Therefore we use !has_alpha as the condition.
511
+ */
512
+ if (blend_mode == DRM_MODE_BLEND_PIXEL_NONE || !state -> base .fb -> format -> has_alpha )
513
+ ignore_pixel_alpha = OVL_CONST_BLEND ;
514
+ }
488
515
489
516
if (pending -> rotation & DRM_MODE_REFLECT_Y ) {
490
517
con |= OVL_CON_VIRT_FLIP ;
@@ -663,6 +690,9 @@ static const struct mtk_disp_ovl_data mt8192_ovl_driver_data = {
663
690
.layer_nr = 4 ,
664
691
.fmt_rgb565_is_0 = true,
665
692
.smi_id_en = true,
693
+ .blend_modes = BIT (DRM_MODE_BLEND_PREMULTI ) |
694
+ BIT (DRM_MODE_BLEND_COVERAGE ) |
695
+ BIT (DRM_MODE_BLEND_PIXEL_NONE ),
666
696
.formats = mt8173_formats ,
667
697
.num_formats = ARRAY_SIZE (mt8173_formats ),
668
698
};
@@ -673,6 +703,9 @@ static const struct mtk_disp_ovl_data mt8192_ovl_2l_driver_data = {
673
703
.layer_nr = 2 ,
674
704
.fmt_rgb565_is_0 = true,
675
705
.smi_id_en = true,
706
+ .blend_modes = BIT (DRM_MODE_BLEND_PREMULTI ) |
707
+ BIT (DRM_MODE_BLEND_COVERAGE ) |
708
+ BIT (DRM_MODE_BLEND_PIXEL_NONE ),
676
709
.formats = mt8173_formats ,
677
710
.num_formats = ARRAY_SIZE (mt8173_formats ),
678
711
};
@@ -684,6 +717,9 @@ static const struct mtk_disp_ovl_data mt8195_ovl_driver_data = {
684
717
.fmt_rgb565_is_0 = true,
685
718
.smi_id_en = true,
686
719
.supports_afbc = true,
720
+ .blend_modes = BIT (DRM_MODE_BLEND_PREMULTI ) |
721
+ BIT (DRM_MODE_BLEND_COVERAGE ) |
722
+ BIT (DRM_MODE_BLEND_PIXEL_NONE ),
687
723
.formats = mt8195_formats ,
688
724
.num_formats = ARRAY_SIZE (mt8195_formats ),
689
725
.supports_clrfmt_ext = true,
0 commit comments