From nobody Thu Sep 19 23:07:09 2024 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (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 336A6EEB3 for ; Thu, 1 Aug 2024 08:11:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722499917; cv=none; b=ukp3NuQMo1jTll8zMT6TRCzOT7PrYQLbsVleDlafYk36oN6Ghe1NEAVofBMIA8YFmt7kvBUUJHkLmJdY+nBWHLvGFNX3shg0nPrkA/fYIE25Wko5SEtWkVeV6QjXZeQTEopjqDvU6ZruuoRR2IG0XzykW/eUbC0mTzudYSa4R6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722499917; c=relaxed/simple; bh=fqmi3VS+T15tINZ8A8BMI2ZabMNzqr0rnKqGPuFhLeU=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=WY0twfcQmZ9Gitd8lclGeJZdT0y0Xd5LxdzDlQKlwYFwe5XiSKoLElzQLrOPUlIJ02es5ZYDB3PycaIGogQBZ057IoiTtf6FV0+jX5sqnxOyDfRPYDuHb64iVmSoce3UgdfDF7O3Hh68CiLZfbyODb+68jIh9xSV6ZwsUkv9kII= 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=Qbc65LpR; arc=none smtp.client-ip=60.244.123.138 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="Qbc65LpR" X-UUID: b3914dcc4fdd11ef9a4e6796c666300c-20240801 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=fy5DunPAyYU4WYv5r8MiBywBLFV+74bLINMeHVNNHLQ=; b=Qbc65LpR+6Df6d1jHUk4an7g4QeaYu7ECbeECCdRGixXo1mbGkmORVWBeUr+i3tFEO3Va3BKAaVZ0l6xGRkd9C3FQN7uw1AjUw8UgEd+1eZpdCNYpPe8xAiPme02UYLxxt/qjuSsHCvw58P2UmDL7J3lqc80sT0eVEozeMO6+Ts=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.41,REQID:0e4726e6-7e94-40ef-928c-76d950129539,IP:0,U RL:0,TC:0,Content:0,EDM:-30,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-30 X-CID-META: VersionHash:6dc6a47,CLOUDID:541c230e-46b0-425a-97d3-4623fe284021,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:2,IP:nil,UR L:11|1,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,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-UUID: b3914dcc4fdd11ef9a4e6796c666300c-20240801 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 907801158; Thu, 01 Aug 2024 16:11:49 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by MTKMBS14N2.mediatek.inc (172.21.101.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 1 Aug 2024 16:11:47 +0800 Received: from mszsdhlt06.gcn.mediatek.inc (10.16.6.206) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Thu, 1 Aug 2024 16:11:46 +0800 From: Shuijing Li To: , , , , , , CC: , , , , , Shuijing Li Subject: [PATCH v4] drm/mediatek: dsi: Add dsi per-frame lp code for mt8188 Date: Thu, 1 Aug 2024 16:11:34 +0800 Message-ID: <20240801081144.22372-1-shuijing.li@mediatek.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--4.622400-8.000000 X-TMASE-MatchedRID: cgCwsOOlPfAwKP61E4rxu1VN8laWo90M5TpDO1WKs2mYQOVjVNfbbpOu v4LVY2bFTkkjufoIff4jfA7ocKKIpzZQQocM3TDMGVyS87Wb4lzSv+oK79xjnUYvSDWdWaRhlqx 8Dxj9EIVfw77qsJLx4U9h13WKYt0lAM0/G7XUdeMMH4SsGvRsA0qAhuLHn5fE+3n3Z6rbGhPejM lFftvg2ZIEvcwNcKRi3zYWBJaf/JyuYDHQSk88ce7KTDtx8Cggm6ZTMj/Sfrm5ZjHyzYrpGjTdq 51OxL847hUCZUBVS2iyrZirIDlyAmrGB8JmGq18jtK7dC6UBnm5+1figft3Lpsoi2XrUn/JUTdY /mdfTXtJKW4mDlJsMcK21zBg2KlfJLIWFE2XGROPBqcM9Qj5Vcrv+woMCO8y7deJLzvhwSpNzvA 9bEifz1Zca9RSYo/b X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--4.622400-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 704981C5E754EF9CA17F46B6E4ADA1076DB9C6882607B60B0C214675FF94046A2000:8 X-MTK: N Content-Type: text/plain; charset="utf-8" Adding the per-frame lp function of mt8188, which can keep HFP in HS and reduce the time required for each line to enter and exit low power. Per Frame LP: |<----------One Active Frame-------->| --______________________________________----___________________ ^HSA+HBP^^RGB^^HFP^^HSA+HBP^^RGB^^HFP^ ^HSA+HBP^^RGB^^HFP^ Per Line LP: |<---------------One Active Frame----------->| --______________--______________--______________----______________ ^HSA+HBP^^RGB^ ^HSA+HBP^^RGB^ ^HSA+HBP^^RGB^ ^HSA+HBP^^RGB^ Signed-off-by: Shuijing Li --- Changes in v4: Drop the code related to bllp_en and bllp_wc, adjust ps_wc to dsi->vm.hacti= ve * dsi_buf_bpp. Changes in v3: Use function in bitfield.h and get value from phy timing, per suggestion from previous thread: https://patchwork.kernel.org/project/linux-mediatek/patch/20240424091639.22= 759-1-shuijing.li@mediatek.com/ Changes in v2: Use bitfield macros and add new function for per prame lp and improve the format, per suggestion from previous thread: https://patchwork.kernel.org/project/linux-mediatek/patch/20240314094238.33= 15-1-shuijing.li@mediatek.com/ --- drivers/gpu/drm/mediatek/mtk_dsi.c | 210 ++++++++++++++++++++++------- 1 file changed, 163 insertions(+), 47 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/= mtk_dsi.c index b6e3c011a12d..4bda8fa17c3d 100644 --- a/drivers/gpu/drm/mediatek/mtk_dsi.c +++ b/drivers/gpu/drm/mediatek/mtk_dsi.c @@ -88,12 +88,16 @@ #define DSI_HSA_WC 0x50 #define DSI_HBP_WC 0x54 #define DSI_HFP_WC 0x58 +#define HFP_HS_EN 31 +#define HFP_HS_VB_PS_WC_SHIFT 16 =20 #define DSI_CMDQ_SIZE 0x60 #define CMDQ_SIZE 0x3f #define CMDQ_SIZE_SEL BIT(15) =20 #define DSI_HSTX_CKL_WC 0x64 +#define HSTX_CKL_WC GENMASK(15, 2) +#define HSTX_CKL_WC_SHIFT 2 =20 #define DSI_RX_DATA0 0x74 #define DSI_RX_DATA1 0x78 @@ -187,6 +191,7 @@ struct mtk_dsi_driver_data { bool has_shadow_ctl; bool has_size_ctl; bool cmdq_long_packet_ctl; + bool support_per_frame_lp; }; =20 struct mtk_dsi { @@ -426,6 +431,112 @@ static void mtk_dsi_ps_control(struct mtk_dsi *dsi, b= ool config_vact) writel(ps_val, dsi->regs + DSI_PSCTRL); } =20 +static void mtk_dsi_config_vdo_timing_per_frame_lp(struct mtk_dsi *dsi) +{ + u32 horizontal_sync_active_byte; + u32 horizontal_backporch_byte; + u32 horizontal_frontporch_byte; + u32 dsi_tmp_buf_bpp; + unsigned int lpx, da_hs_exit, da_hs_prep, da_hs_trail; + unsigned int da_hs_zero, ps_wc, hs_vb_ps_wc; + u32 v_active_roundup, hstx_cklp_wc; + u32 hstx_cklp_wc_max, hstx_cklp_wc_min; + struct videomode *vm =3D &dsi->vm; + + if (dsi->format =3D=3D MIPI_DSI_FMT_RGB565) + dsi_tmp_buf_bpp =3D 2; + else + dsi_tmp_buf_bpp =3D 3; + + da_hs_trail =3D dsi->phy_timing.da_hs_trail; + ps_wc =3D dsi->vm.hactive * dsi_tmp_buf_bpp; + + if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) { + horizontal_sync_active_byte =3D + vm->hsync_len * dsi_tmp_buf_bpp - 10; + horizontal_backporch_byte =3D + vm->hback_porch * dsi_tmp_buf_bpp - 10; + horizontal_frontporch_byte =3D + vm->hfront_porch * dsi_tmp_buf_bpp - 12; + + v_active_roundup =3D (32 + horizontal_sync_active_byte + + horizontal_backporch_byte + ps_wc + + horizontal_frontporch_byte) % dsi->lanes; + if (v_active_roundup) + horizontal_backporch_byte =3D horizontal_backporch_byte + + dsi->lanes - v_active_roundup; + hstx_cklp_wc_min =3D (DIV_ROUND_UP((12 + 2 + 4 + + horizontal_sync_active_byte), dsi->lanes) + da_hs_trail + 1) + * dsi->lanes / 6 - 1; + hstx_cklp_wc_max =3D (DIV_ROUND_UP((20 + 6 + 4 + + horizontal_sync_active_byte + horizontal_backporch_byte + + ps_wc), dsi->lanes) + da_hs_trail + 1) * dsi->lanes / 6 - 1; + } else { + horizontal_sync_active_byte =3D vm->hsync_len * dsi_tmp_buf_bpp - 4; + + horizontal_backporch_byte =3D (vm->hback_porch + vm->hsync_len) * + dsi_tmp_buf_bpp - 10; + hstx_cklp_wc_min =3D (DIV_ROUND_UP(4, dsi->lanes) + da_hs_trail + 1) + * dsi->lanes / 6 - 1; + + if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST) { + horizontal_frontporch_byte =3D (vm->hfront_porch * + dsi_tmp_buf_bpp - 18); + + v_active_roundup =3D (28 + horizontal_backporch_byte + ps_wc + + horizontal_frontporch_byte) % dsi->lanes; + if (v_active_roundup) + horizontal_backporch_byte =3D horizontal_backporch_byte + + dsi->lanes - v_active_roundup; + + hstx_cklp_wc_max =3D (DIV_ROUND_UP((12 + 4 + 4 + + horizontal_backporch_byte + ps_wc), + dsi->lanes) + da_hs_trail + 1) * dsi->lanes / 6 - 1; + } else { + horizontal_frontporch_byte =3D (vm->hfront_porch * + dsi_tmp_buf_bpp - 12); + + v_active_roundup =3D (22 + horizontal_backporch_byte + ps_wc + + horizontal_frontporch_byte) % dsi->lanes; + if (v_active_roundup) + horizontal_backporch_byte =3D horizontal_backporch_byte + + dsi->lanes - v_active_roundup; + + hstx_cklp_wc_max =3D (DIV_ROUND_UP((12 + 4 + 4 + + horizontal_backporch_byte + ps_wc), + dsi->lanes) + da_hs_trail + 1) * dsi->lanes / 6 - 1; + } + } + hstx_cklp_wc =3D FIELD_GET(HSTX_CKL_WC, readl(dsi->regs + DSI_HSTX_CKL_WC= )); + + if (hstx_cklp_wc <=3D hstx_cklp_wc_min || + hstx_cklp_wc >=3D hstx_cklp_wc_max) { + hstx_cklp_wc =3D ((hstx_cklp_wc_min + hstx_cklp_wc_max) / 2) << HSTX_CKL= _WC_SHIFT; + writel(hstx_cklp_wc, dsi->regs + DSI_HSTX_CKL_WC); + } + hstx_cklp_wc =3D hstx_cklp_wc >> HSTX_CKL_WC_SHIFT; + if (hstx_cklp_wc <=3D hstx_cklp_wc_min || + hstx_cklp_wc >=3D hstx_cklp_wc_max) { + DRM_WARN("Wrong setting of hstx_ckl_wc\n"); + } + + lpx =3D dsi->phy_timing.lpx; + da_hs_exit =3D dsi->phy_timing.da_hs_exit; + da_hs_prep =3D dsi->phy_timing.da_hs_prepare; + da_hs_zero =3D dsi->phy_timing.da_hs_zero; + + hs_vb_ps_wc =3D ps_wc - + (lpx + da_hs_exit + da_hs_prep + da_hs_zero + 2) + * dsi->lanes; + horizontal_frontporch_byte =3D (1 << HFP_HS_EN) + | (hs_vb_ps_wc << HFP_HS_VB_PS_WC_SHIFT) + | (horizontal_frontporch_byte); + + writel(horizontal_sync_active_byte, dsi->regs + DSI_HSA_WC); + writel(horizontal_backporch_byte, dsi->regs + DSI_HBP_WC); + writel(horizontal_frontporch_byte, dsi->regs + DSI_HFP_WC); +} + static void mtk_dsi_config_vdo_timing(struct mtk_dsi *dsi) { u32 horizontal_sync_active_byte; @@ -449,57 +560,61 @@ static void mtk_dsi_config_vdo_timing(struct mtk_dsi = *dsi) writel(vm->vfront_porch, dsi->regs + DSI_VFP_NL); writel(vm->vactive, dsi->regs + DSI_VACT_NL); =20 - if (dsi->driver_data->has_size_ctl) - writel(FIELD_PREP(DSI_HEIGHT, vm->vactive) | - FIELD_PREP(DSI_WIDTH, vm->hactive), - dsi->regs + DSI_SIZE_CON); - - horizontal_sync_active_byte =3D (vm->hsync_len * dsi_tmp_buf_bpp - 10); - - if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) - horizontal_backporch_byte =3D vm->hback_porch * dsi_tmp_buf_bpp - 10; - else - horizontal_backporch_byte =3D (vm->hback_porch + vm->hsync_len) * - dsi_tmp_buf_bpp - 10; - - data_phy_cycles =3D timing->lpx + timing->da_hs_prepare + - timing->da_hs_zero + timing->da_hs_exit + 3; - - delta =3D dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST ? 18 : 12; - delta +=3D dsi->mode_flags & MIPI_DSI_MODE_NO_EOT_PACKET ? 0 : 2; + if (dsi->driver_data->support_per_frame_lp) + mtk_dsi_config_vdo_timing_per_frame_lp(dsi); + else { + if (dsi->driver_data->has_size_ctl) + writel(FIELD_PREP(DSI_HEIGHT, vm->vactive) | + FIELD_PREP(DSI_WIDTH, vm->hactive), + dsi->regs + DSI_SIZE_CON); =20 - horizontal_frontporch_byte =3D vm->hfront_porch * dsi_tmp_buf_bpp; - horizontal_front_back_byte =3D horizontal_frontporch_byte + horizontal_ba= ckporch_byte; - data_phy_cycles_byte =3D data_phy_cycles * dsi->lanes + delta; + horizontal_sync_active_byte =3D (vm->hsync_len * dsi_tmp_buf_bpp - 10); =20 - if (horizontal_front_back_byte > data_phy_cycles_byte) { - horizontal_frontporch_byte -=3D data_phy_cycles_byte * - horizontal_frontporch_byte / - horizontal_front_back_byte; - - horizontal_backporch_byte -=3D data_phy_cycles_byte * - horizontal_backporch_byte / - horizontal_front_back_byte; - } else { - DRM_WARN("HFP + HBP less than d-phy, FPS will under 60Hz\n"); - } - - if ((dsi->mode_flags & MIPI_DSI_HS_PKT_END_ALIGNED) && - (dsi->lanes =3D=3D 4)) { - horizontal_sync_active_byte =3D - roundup(horizontal_sync_active_byte, dsi->lanes) - 2; - horizontal_frontporch_byte =3D - roundup(horizontal_frontporch_byte, dsi->lanes) - 2; - horizontal_backporch_byte =3D - roundup(horizontal_backporch_byte, dsi->lanes) - 2; - horizontal_backporch_byte -=3D - (vm->hactive * dsi_tmp_buf_bpp + 2) % dsi->lanes; + if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) + horizontal_backporch_byte =3D vm->hback_porch * dsi_tmp_buf_bpp - 10; + else + horizontal_backporch_byte =3D (vm->hback_porch + vm->hsync_len) * + dsi_tmp_buf_bpp - 10; + + data_phy_cycles =3D timing->lpx + timing->da_hs_prepare + + timing->da_hs_zero + timing->da_hs_exit + 3; + + delta =3D dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST ? 18 : 12; + delta +=3D dsi->mode_flags & MIPI_DSI_MODE_NO_EOT_PACKET ? 0 : 2; + + horizontal_frontporch_byte =3D vm->hfront_porch * dsi_tmp_buf_bpp; + horizontal_front_back_byte =3D horizontal_frontporch_byte + horizontal_b= ackporch_byte; + data_phy_cycles_byte =3D data_phy_cycles * dsi->lanes + delta; + + if (horizontal_front_back_byte > data_phy_cycles_byte) { + horizontal_frontporch_byte -=3D data_phy_cycles_byte * + horizontal_frontporch_byte / + horizontal_front_back_byte; + + horizontal_backporch_byte -=3D data_phy_cycles_byte * + horizontal_backporch_byte / + horizontal_front_back_byte; + } else { + DRM_WARN("HFP + HBP less than d-phy, FPS will under 60Hz\n"); + } + + if ((dsi->mode_flags & MIPI_DSI_HS_PKT_END_ALIGNED) && + (dsi->lanes =3D=3D 4)) { + horizontal_sync_active_byte =3D + roundup(horizontal_sync_active_byte, dsi->lanes) - 2; + horizontal_frontporch_byte =3D + roundup(horizontal_frontporch_byte, dsi->lanes) - 2; + horizontal_backporch_byte =3D + roundup(horizontal_backporch_byte, dsi->lanes) - 2; + horizontal_backporch_byte -=3D + (vm->hactive * dsi_tmp_buf_bpp + 2) % dsi->lanes; + } + + writel(horizontal_sync_active_byte, dsi->regs + DSI_HSA_WC); + writel(horizontal_backporch_byte, dsi->regs + DSI_HBP_WC); + writel(horizontal_frontporch_byte, dsi->regs + DSI_HFP_WC); } =20 - writel(horizontal_sync_active_byte, dsi->regs + DSI_HSA_WC); - writel(horizontal_backporch_byte, dsi->regs + DSI_HBP_WC); - writel(horizontal_frontporch_byte, dsi->regs + DSI_HFP_WC); - mtk_dsi_ps_control(dsi, false); } =20 @@ -1197,6 +1312,7 @@ static const struct mtk_dsi_driver_data mt8188_dsi_dr= iver_data =3D { .has_shadow_ctl =3D true, .has_size_ctl =3D true, .cmdq_long_packet_ctl =3D true, + .support_per_frame_lp =3D true, }; =20 static const struct of_device_id mtk_dsi_of_match[] =3D { --=20 2.43.0