6565#define OVL_CON_CLRFMT_RGB (1 << 12)
6666#define OVL_CON_CLRFMT_ARGB8888 (2 << 12)
6767#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)
7070#define OVL_CON_CLRFMT_UYVY (4 << 12)
7171#define OVL_CON_CLRFMT_YUYV (5 << 12)
7272#define OVL_CON_MTX_YUV_TO_RGB (6 << 16)
@@ -146,6 +146,7 @@ struct mtk_disp_ovl_data {
146146 bool fmt_rgb565_is_0 ;
147147 bool smi_id_en ;
148148 bool supports_afbc ;
149+ const u32 blend_modes ;
149150 const u32 * formats ;
150151 size_t num_formats ;
151152 bool supports_clrfmt_ext ;
@@ -214,6 +215,13 @@ void mtk_ovl_disable_vblank(struct device *dev)
214215 writel_relaxed (0x0 , ovl -> regs + DISP_REG_OVL_INTEN );
215216}
216217
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+
217225const u32 * mtk_ovl_get_formats (struct device * dev )
218226{
219227 struct mtk_disp_ovl * ovl = dev_get_drvdata (dev );
@@ -386,14 +394,27 @@ void mtk_ovl_layer_off(struct device *dev, unsigned int idx,
386394 DISP_REG_OVL_RDMA_CTRL (idx ));
387395}
388396
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 )
391399{
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.
396414 */
415+ if (ovl -> data -> blend_modes & BIT (DRM_MODE_BLEND_PREMULTI ))
416+ blend_mode = state -> base .pixel_blend_mode ;
417+
397418 switch (fmt ) {
398419 default :
399420 case DRM_FORMAT_RGB565 :
@@ -471,20 +492,26 @@ void mtk_ovl_layer_config(struct device *dev, unsigned int idx,
471492 return ;
472493 }
473494
474- con = ovl_fmt_convert (ovl , fmt , blend_mode );
495+ con = mtk_ovl_fmt_convert (ovl , state );
475496 if (state -> base .fb ) {
476- con |= OVL_CON_AEN ;
477497 con |= state -> base .alpha & OVL_CON_ALPHA ;
478- }
479498
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+ }
488515
489516 if (pending -> rotation & DRM_MODE_REFLECT_Y ) {
490517 con |= OVL_CON_VIRT_FLIP ;
@@ -663,6 +690,9 @@ static const struct mtk_disp_ovl_data mt8192_ovl_driver_data = {
663690 .layer_nr = 4 ,
664691 .fmt_rgb565_is_0 = true,
665692 .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 ),
666696 .formats = mt8173_formats ,
667697 .num_formats = ARRAY_SIZE (mt8173_formats ),
668698};
@@ -673,6 +703,9 @@ static const struct mtk_disp_ovl_data mt8192_ovl_2l_driver_data = {
673703 .layer_nr = 2 ,
674704 .fmt_rgb565_is_0 = true,
675705 .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 ),
676709 .formats = mt8173_formats ,
677710 .num_formats = ARRAY_SIZE (mt8173_formats ),
678711};
@@ -684,6 +717,9 @@ static const struct mtk_disp_ovl_data mt8195_ovl_driver_data = {
684717 .fmt_rgb565_is_0 = true,
685718 .smi_id_en = true,
686719 .supports_afbc = true,
720+ .blend_modes = BIT (DRM_MODE_BLEND_PREMULTI ) |
721+ BIT (DRM_MODE_BLEND_COVERAGE ) |
722+ BIT (DRM_MODE_BLEND_PIXEL_NONE ),
687723 .formats = mt8195_formats ,
688724 .num_formats = ARRAY_SIZE (mt8195_formats ),
689725 .supports_clrfmt_ext = true,
0 commit comments