From nobody Sun Nov 10 04:13:14 2024 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1B245BAFA for ; Tue, 20 Feb 2024 09:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708421840; cv=none; b=WtIuc299TEtxLpe3achYU52o9LhjrD6WYTB5OegdTCo2phxhX3XMM4nv/bboyBeMasUAMJrh7IKfAH7ezM2Yc4gRpWy8AO5XgJAHJvP3QffJvlfMZeS/0VKNgF8kAszb9jM5KaDGif8/La8LIIpKG4qW2q/AGKPwDsuVmss6IQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708421840; c=relaxed/simple; bh=FRB5sOLZ4Bg6Jvp09Xh9mOF7HciJe97iuWZQZd8AylA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lDMfMGhqMU6W13p4ityCZ64e2Nm6HMroWljPYlULIhqNMXf6ryxuMDZqoj3efkcw/qYJlZ0qt9o5oCm3uKW1MYxtzjrYKE72mqGHapW938vFEmDEG4SWCmJYJKGE6zPNaYcrKR8om9JFG+SMdaAX/OeyAyEq4+Nsg8wj3sHkoJI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=U6ULFgyv; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="U6ULFgyv" X-UUID: a136bd86cfd311eea2298b7352fd921d-20240220 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=/+VjVeu6YW5cdiWhf4xJoF6pgv0RKnyjDr8r/B5h97o=; b=U6ULFgyvSS5sMKuUnHeQgB+BV8HQ8mgRLQJUUbaob/kAHsrgxGWZ84WY2UFeb0Xug34T9ep9tw4rBjOo7p2f5DmuLVzA2fb5adicuel6wKkDDG0k6j6ZybhEEi2Dv3LxqU4ki4GFv9kgBOvNXWqOtgXVLn5wnhko6wy1HZVMPf8=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:def4a1a2-0f69-4f5c-bc96-0741701e9cea,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:6f543d0,CLOUDID:55699980-4f93-4875-95e7-8c66ea833d57,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: a136bd86cfd311eea2298b7352fd921d-20240220 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 200880732; Tue, 20 Feb 2024 17:37:14 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by MTKMBS14N1.mediatek.inc (172.21.101.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 20 Feb 2024 17:37:12 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 20 Feb 2024 17:37:12 +0800 From: Shawn Sung To: Chun-Kuang Hu CC: Philipp Zabel , David Airlie , Daniel Vetter , Matthias Brugger , , , , , "Hsiao Chien Sung" Subject: [PATCH v3 1/1] drm/mediatek: Filter modes according to hardware capability Date: Tue, 20 Feb 2024 17:37:11 +0800 Message-ID: <20240220093711.20546-2-shawn.sung@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20240220093711.20546-1-shawn.sung@mediatek.com> References: <20240220093711.20546-1-shawn.sung@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--9.699400-8.000000 X-TMASE-MatchedRID: OqZPkXNGKDf8rQJMqxBG8Izb2GR6Ttd3Kx5ICGp/WtG7qpOHKudqc61l cDruwbtbIkxDXi0u/CvJgrDniXuCV0JF8hwyENQ8nIGynr5ObIa4vBuE2X0HlU00Gfbn1vTVPlA WwfVA2w4hax9eXp8NDBKqjdlR+seHJjR5Quw0FeUVglQa/gMvfJKLNrbpy/A01yGUyFK3oV4wKY tIU69m3V+2TZ8bogGeASo1XNPhrPrsz8PwlGcGDaKa0xB73sAABcsh1y6QslbYCfmDULr78j3n7 3EfAgPtHa1OFK8PqLpfSNXDXIBWnv6sIX4Dc0fpBNs0AUqdiH1NedaYR0zWEeIpRqgiF5rtlOts 73NQ5aOv/ywMrWTE9jowbcM3oyOGI6RtAg4ny/ltD1qg9KZYkfQ7szeVKdNbJLfQYoCQHFYtFkD k0067+UfSb/e+ISPMsu3nPiE1MDPlRxm3A2wKuhRFJJyf5BJe3QfwsVk0UbuGrPnef/I+eo0HAc mov1aJasRtmtDFJ+oc79OKiiFbkBpNIfhEsVgiSUt3T068WM8= X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--9.699400-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: D3C9A7EE4B5BDF73D4A9861D36F9E43181267D69474E656C93DBE5E9F467E0712000:8 X-MTK: N Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Hsiao Chien Sung We found a stability issue on MT8188 when connecting an external monitor in 2560x1440@144Hz mode. Checked with the designer, there is a function called "prefetch" which is working during VBP (triggered by VSYNC). If the duration of VBP is too short, the throughput requirement could increase more than 3 times and lead to stability issues. The mode settings that VDOSYS supports are mainly affected by clock rate and throughput, display driver should filter these settings according to the SoC's limitation to avoid unstable conditions. Since currently the mode filter is only available on MT8195 and MT8188 and they share the same compatible name, the reference number (8250) is hard coded instead of in the driver data. Signed-off-by: Hsiao Chien Sung Reviewed-by: CK Hu --- drivers/gpu/drm/mediatek/mtk_disp_drv.h | 4 ++ drivers/gpu/drm/mediatek/mtk_disp_merge.c | 65 +++++++++++++++++++ .../gpu/drm/mediatek/mtk_disp_ovl_adaptor.c | 17 +++++ drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 17 +++++ drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 1 + drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 12 ++++ 6 files changed, 116 insertions(+) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_drv.h b/drivers/gpu/drm/medi= atek/mtk_disp_drv.h index eb738f14f09e3..4a5661334fb1a 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_drv.h +++ b/drivers/gpu/drm/mediatek/mtk_disp_drv.h @@ -72,6 +72,8 @@ void mtk_merge_advance_config(struct device *dev, unsigne= d int l_w, unsigned int struct cmdq_pkt *cmdq_pkt); void mtk_merge_start_cmdq(struct device *dev, struct cmdq_pkt *cmdq_pkt); void mtk_merge_stop_cmdq(struct device *dev, struct cmdq_pkt *cmdq_pkt); +enum drm_mode_status mtk_merge_mode_valid(struct device *dev, + const struct drm_display_mode *mode); =20 void mtk_ovl_bgclr_in_on(struct device *dev); void mtk_ovl_bgclr_in_off(struct device *dev); @@ -130,6 +132,8 @@ unsigned int mtk_ovl_adaptor_layer_nr(struct device *de= v); struct device *mtk_ovl_adaptor_dma_dev_get(struct device *dev); const u32 *mtk_ovl_adaptor_get_formats(struct device *dev); size_t mtk_ovl_adaptor_get_num_formats(struct device *dev); +enum drm_mode_status mtk_ovl_adaptor_mode_valid(struct device *dev, + const struct drm_display_mode *mode); =20 void mtk_rdma_bypass_shadow(struct device *dev); int mtk_rdma_clk_enable(struct device *dev); diff --git a/drivers/gpu/drm/mediatek/mtk_disp_merge.c b/drivers/gpu/drm/me= diatek/mtk_disp_merge.c index c19fb1836034d..80953b3e8ace6 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_merge.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_merge.c @@ -223,6 +223,71 @@ void mtk_merge_clk_disable(struct device *dev) clk_disable_unprepare(priv->clk); } =20 +enum drm_mode_status mtk_merge_mode_valid(struct device *dev, + const struct drm_display_mode *mode) +{ + struct mtk_disp_merge *priv =3D dev_get_drvdata(dev); + unsigned long rate =3D 0; + + rate =3D clk_get_rate(priv->clk); + + /* Convert to KHz and round the number */ + rate =3D (rate + 500) / 1000; + + if (rate && mode->clock > rate) { + dev_dbg(dev, "invalid clock: %d (>%lu)\n", mode->clock, rate); + return MODE_CLOCK_HIGH; + } + + /* + * Measure the bandwidth requirement of hardware prefetch (per frame) + * + * let N =3D prefetch buffer size in lines + * (ex. N=3D3, then prefetch buffer size =3D 3 lines) + * + * prefetch size =3D htotal * N (pixels) + * time per line =3D 1 / fps / vtotal (seconds) + * duration =3D vbp * time per line + * =3D vbp / fps / vtotal + * + * data rate =3D prefetch size / duration + * =3D htotal * N / (vbp / fps / vtotal) + * =3D htotal * vtotal * fps * N / vbp + * =3D clk * N / vbp (pixels per second) + * + * Say 4K60 (CEA-861) is the maximum mode supported by the SoC + * data rate =3D 594000K * N / 72 =3D 8250 (standard) + * (remove K * N due to the same unit) + * + * For 2560x1440@144 (clk=3D583600K, vbp=3D17): + * data rate =3D 583600 / 17 ~=3D 34329 > 8250 (NG) + * + * For 2560x1440@120 (clk=3D497760K, vbp=3D77): + * data rate =3D 497760 / 77 ~=3D 6464 < 8250 (OK) + * + * A non-standard 4K60 timing (clk=3D521280K, vbp=3D54) + * data rate =3D 521280 / 54 ~=3D 9653 > 8250 (NG) + * + * Bandwidth requirement of hardware prefetch increases significantly + * when the VBP decreases (more than 4x in this example). + * + * The proposed formula is only one way to estimate whether our SoC + * supports the mode setting. The basic idea behind it is just to check + * if the data rate requirement is too high (directly proportional to + * pixel clock, inversely proportional to vbp). Please adjust the + * function if it doesn't fit your situation in the future. + */ + rate =3D mode->clock / (mode->vtotal - mode->vsync_end); + + if (rate > 8250) { + dev_dbg(dev, "invalid rate: %lu (>8250): " DRM_MODE_FMT "\n", + rate, DRM_MODE_ARG(mode)); + return MODE_BAD; + } + + return MODE_OK; +} + static int mtk_disp_merge_bind(struct device *dev, struct device *master, void *data) { diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c b/drivers/gpu/= drm/mediatek/mtk_disp_ovl_adaptor.c index 10d23e76acaa9..6d4334955e3d3 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c @@ -88,6 +88,7 @@ static const struct mtk_ddp_comp_funcs ethdr =3D { static const struct mtk_ddp_comp_funcs merge =3D { .clk_enable =3D mtk_merge_clk_enable, .clk_disable =3D mtk_merge_clk_disable, + .mode_valid =3D mtk_merge_mode_valid, }; =20 static const struct mtk_ddp_comp_funcs padding =3D { @@ -341,6 +342,22 @@ void mtk_ovl_adaptor_clk_disable(struct device *dev) } } =20 +enum drm_mode_status mtk_ovl_adaptor_mode_valid(struct device *dev, + const struct drm_display_mode *mode) + +{ + int i; + struct mtk_disp_ovl_adaptor *ovl_adaptor =3D dev_get_drvdata(dev); + + for (i =3D 0; i < OVL_ADAPTOR_ID_MAX; i++) { + dev =3D ovl_adaptor->ovl_adaptor_comp[i]; + if (!dev || !comp_matches[i].funcs->mode_valid) + continue; + return comp_matches[i].funcs->mode_valid(dev, mode); + } + return MODE_OK; +} + unsigned int mtk_ovl_adaptor_layer_nr(struct device *dev) { return MTK_OVL_ADAPTOR_LAYER_NUM; diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/medi= atek/mtk_drm_crtc.c index 1dac8d0fbc669..14cf75fa217f9 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c @@ -212,6 +212,22 @@ static void mtk_drm_crtc_destroy_state(struct drm_crtc= *crtc, kfree(to_mtk_crtc_state(state)); } =20 +static enum drm_mode_status +mtk_drm_crtc_mode_valid(struct drm_crtc *crtc, + const struct drm_display_mode *mode) +{ + struct mtk_drm_crtc *mtk_crtc =3D to_mtk_crtc(crtc); + enum drm_mode_status status =3D MODE_OK; + int i; + + for (i =3D 0; i < mtk_crtc->ddp_comp_nr; i++) { + status =3D mtk_ddp_comp_mode_valid(mtk_crtc->ddp_comp[i], mode); + if (status !=3D MODE_OK) + break; + } + return status; +} + static bool mtk_drm_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode) @@ -830,6 +846,7 @@ static const struct drm_crtc_funcs mtk_crtc_funcs =3D { static const struct drm_crtc_helper_funcs mtk_crtc_helper_funcs =3D { .mode_fixup =3D mtk_drm_crtc_mode_fixup, .mode_set_nofb =3D mtk_drm_crtc_mode_set_nofb, + .mode_valid =3D mtk_drm_crtc_mode_valid, .atomic_begin =3D mtk_drm_crtc_atomic_begin, .atomic_flush =3D mtk_drm_crtc_atomic_flush, .atomic_enable =3D mtk_drm_crtc_atomic_enable, diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/= mediatek/mtk_drm_ddp_comp.c index 9633e860cc3ce..94590227c56a9 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c @@ -416,6 +416,7 @@ static const struct mtk_ddp_comp_funcs ddp_ovl_adaptor = =3D { .remove =3D mtk_ovl_adaptor_remove_comp, .get_formats =3D mtk_ovl_adaptor_get_formats, .get_num_formats =3D mtk_ovl_adaptor_get_num_formats, + .mode_valid =3D mtk_ovl_adaptor_mode_valid, }; =20 static const char * const mtk_ddp_comp_stem[MTK_DDP_COMP_TYPE_MAX] =3D { diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h b/drivers/gpu/drm/= mediatek/mtk_drm_ddp_comp.h index f8c7e8d8ddc12..215b7234ff13c 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h @@ -12,6 +12,8 @@ #include #include =20 +#include + struct device; struct device_node; struct drm_crtc; @@ -84,6 +86,7 @@ struct mtk_ddp_comp_funcs { void (*add)(struct device *dev, struct mtk_mutex *mutex); void (*remove)(struct device *dev, struct mtk_mutex *mutex); unsigned int (*encoder_index)(struct device *dev); + enum drm_mode_status (*mode_valid)(struct device *dev, const struct drm_d= isplay_mode *mode); }; =20 struct mtk_ddp_comp { @@ -125,6 +128,15 @@ static inline void mtk_ddp_comp_clk_disable(struct mtk= _ddp_comp *comp) comp->funcs->clk_disable(comp->dev); } =20 +static inline +enum drm_mode_status mtk_ddp_comp_mode_valid(struct mtk_ddp_comp *comp, + const struct drm_display_mode *mode) +{ + if (comp && comp->funcs && comp->funcs->mode_valid) + return comp->funcs->mode_valid(comp->dev, mode); + return MODE_OK; +} + static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp, unsigned int w, unsigned int h, unsigned int vrefresh, unsigned int bpc, --=20 2.18.0