Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/mediatek: only announce AFBC if really supported

Currently even the SoC's OVL does not declare the support of AFBC, AFBC
is still announced to the userspace within the IN_FORMATS blob, which
breaks modern Wayland compositors like KWin Wayland and others.

Gate passing modifiers to drm_universal_plane_init() behind querying the
driver of the hardware block for AFBC support.

Fixes: c410fa9b07c3 ("drm/mediatek: Add AFBC support to Mediatek DRM driver")
Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
Reviewed-by: CK Hu <ck.hu@medaitek.com>
Link: https://patchwork.kernel.org/project/linux-mediatek/patch/20250531121140.387661-1-uwu@icenowy.me/
Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>

authored by

Icenowy Zheng and committed by
Chun-Kuang Hu
8d121a82 d208261e

+27 -4
+2 -1
drivers/gpu/drm/mediatek/mtk_crtc.c
··· 963 963 mtk_ddp_comp_supported_rotations(comp), 964 964 mtk_ddp_comp_get_blend_modes(comp), 965 965 mtk_ddp_comp_get_formats(comp), 966 - mtk_ddp_comp_get_num_formats(comp), i); 966 + mtk_ddp_comp_get_num_formats(comp), 967 + mtk_ddp_comp_is_afbc_supported(comp), i); 967 968 if (ret) 968 969 return ret; 969 970
+1
drivers/gpu/drm/mediatek/mtk_ddp_comp.c
··· 366 366 .get_blend_modes = mtk_ovl_get_blend_modes, 367 367 .get_formats = mtk_ovl_get_formats, 368 368 .get_num_formats = mtk_ovl_get_num_formats, 369 + .is_afbc_supported = mtk_ovl_is_afbc_supported, 369 370 }; 370 371 371 372 static const struct mtk_ddp_comp_funcs ddp_postmask = {
+9
drivers/gpu/drm/mediatek/mtk_ddp_comp.h
··· 83 83 u32 (*get_blend_modes)(struct device *dev); 84 84 const u32 *(*get_formats)(struct device *dev); 85 85 size_t (*get_num_formats)(struct device *dev); 86 + bool (*is_afbc_supported)(struct device *dev); 86 87 void (*connect)(struct device *dev, struct device *mmsys_dev, unsigned int next); 87 88 void (*disconnect)(struct device *dev, struct device *mmsys_dev, unsigned int next); 88 89 void (*add)(struct device *dev, struct mtk_mutex *mutex); ··· 293 292 return comp->funcs->get_num_formats(comp->dev); 294 293 295 294 return 0; 295 + } 296 + 297 + static inline bool mtk_ddp_comp_is_afbc_supported(struct mtk_ddp_comp *comp) 298 + { 299 + if (comp->funcs && comp->funcs->is_afbc_supported) 300 + return comp->funcs->is_afbc_supported(comp->dev); 301 + 302 + return false; 296 303 } 297 304 298 305 static inline bool mtk_ddp_comp_add(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
+1
drivers/gpu/drm/mediatek/mtk_disp_drv.h
··· 106 106 u32 mtk_ovl_get_blend_modes(struct device *dev); 107 107 const u32 *mtk_ovl_get_formats(struct device *dev); 108 108 size_t mtk_ovl_get_num_formats(struct device *dev); 109 + bool mtk_ovl_is_afbc_supported(struct device *dev); 109 110 110 111 void mtk_ovl_adaptor_add_comp(struct device *dev, struct mtk_mutex *mutex); 111 112 void mtk_ovl_adaptor_remove_comp(struct device *dev, struct mtk_mutex *mutex);
+7
drivers/gpu/drm/mediatek/mtk_disp_ovl.c
··· 236 236 return ovl->data->num_formats; 237 237 } 238 238 239 + bool mtk_ovl_is_afbc_supported(struct device *dev) 240 + { 241 + struct mtk_disp_ovl *ovl = dev_get_drvdata(dev); 242 + 243 + return ovl->data->supports_afbc; 244 + } 245 + 239 246 int mtk_ovl_clk_enable(struct device *dev) 240 247 { 241 248 struct mtk_disp_ovl *ovl = dev_get_drvdata(dev);
+5 -2
drivers/gpu/drm/mediatek/mtk_plane.c
··· 326 326 int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane, 327 327 unsigned long possible_crtcs, enum drm_plane_type type, 328 328 unsigned int supported_rotations, const u32 blend_modes, 329 - const u32 *formats, size_t num_formats, unsigned int plane_idx) 329 + const u32 *formats, size_t num_formats, 330 + bool supports_afbc, unsigned int plane_idx) 330 331 { 331 332 int err; 332 333 ··· 338 337 339 338 err = drm_universal_plane_init(dev, plane, possible_crtcs, 340 339 &mtk_plane_funcs, formats, 341 - num_formats, modifiers, type, NULL); 340 + num_formats, 341 + supports_afbc ? modifiers : NULL, 342 + type, NULL); 342 343 if (err) { 343 344 DRM_ERROR("failed to initialize plane\n"); 344 345 return err;
+2 -1
drivers/gpu/drm/mediatek/mtk_plane.h
··· 49 49 int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane, 50 50 unsigned long possible_crtcs, enum drm_plane_type type, 51 51 unsigned int supported_rotations, const u32 blend_modes, 52 - const u32 *formats, size_t num_formats, unsigned int plane_idx); 52 + const u32 *formats, size_t num_formats, 53 + bool supports_afbc, unsigned int plane_idx); 53 54 #endif