* [PATCH 0/2] MediaTek MT8195 HDMI PHY Fixes @ 2026-07-01 12:19 AngeloGioacchino Del Regno 2026-07-01 12:19 ` [PATCH 1/2] phy: mediatek: phy-mtk-hdmi-mt8195: Fix PLL calc divisor overflow AngeloGioacchino Del Regno 2026-07-01 12:19 ` [PATCH 2/2] phy: mediatek: phy-mtk-hdmi-mt8195: Fix TMDS clk bit ratio setting AngeloGioacchino Del Regno 0 siblings, 2 replies; 4+ messages in thread From: AngeloGioacchino Del Regno @ 2026-07-01 12:19 UTC (permalink / raw) To: chunfeng.yun Cc: p.zabel, chunkuang.hu, vkoul, neil.armstrong, matthias.bgg, angelogioacchino.delregno, granquet, justin.yeh, dri-devel, linux-mediatek, linux-arm-kernel, linux-phy, linux-kernel, kernel This series adds two fixes for the MT8195-class HDMI PHY, found in MT8195, MT8188 and Genio variants. This is fixing PLL calculation, and TMDS clock dividers, to achieve all of the modes requiring data rates higher than 3.4Gbps, with the successfully tested target being 3840x2160@60Hz. This was tested on MT8395 MediaTek Genio 1200, Radxa NIO-12L and on MT8390 MediaTek Genio 700, with 3 different HDMI displays (two TVs and a 4k LG workstation display). AngeloGioacchino Del Regno (2): phy: mediatek: phy-mtk-hdmi-mt8195: Fix PLL calc divisor overflow phy: mediatek: phy-mtk-hdmi-mt8195: Fix TMDS clk bit ratio setting drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c | 4 ++-- drivers/phy/mediatek/phy-mtk-hdmi-mt8195.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) -- 2.54.0 -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] phy: mediatek: phy-mtk-hdmi-mt8195: Fix PLL calc divisor overflow 2026-07-01 12:19 [PATCH 0/2] MediaTek MT8195 HDMI PHY Fixes AngeloGioacchino Del Regno @ 2026-07-01 12:19 ` AngeloGioacchino Del Regno 2026-07-01 12:31 ` sashiko-bot 2026-07-01 12:19 ` [PATCH 2/2] phy: mediatek: phy-mtk-hdmi-mt8195: Fix TMDS clk bit ratio setting AngeloGioacchino Del Regno 1 sibling, 1 reply; 4+ messages in thread From: AngeloGioacchino Del Regno @ 2026-07-01 12:19 UTC (permalink / raw) To: chunfeng.yun Cc: p.zabel, chunkuang.hu, vkoul, neil.armstrong, matthias.bgg, angelogioacchino.delregno, granquet, justin.yeh, dri-devel, linux-mediatek, linux-arm-kernel, linux-phy, linux-kernel, kernel When trying to calculate a PLL rate for target display resolutions above 2560x1440, 24bpp, 30Hz, the pixel clock value will be more than 32-bits long but the division to finally calculate the digital clock divider is being done with div_u64(), which expects a 32bit unsigned divisor. Fix the overflow by using div64_u64() instead. Fixes: 9d9ff3d2a4a5 ("phy: mediatek: hdmi: mt8195: fix wrong pll calculus") Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> --- drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c b/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c index 1426a2db984d..e6ee8e080022 100644 --- a/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c +++ b/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c @@ -290,7 +290,7 @@ static int mtk_hdmi_pll_calc(struct mtk_hdmi_phy *hdmi_phy, struct clk_hw *hw, posdiv2 = 1; /* Digital clk divider, max /32 */ - digital_div = div_u64(ns_hdmipll_ck, posdiv1 * posdiv2 * pixel_clk); + digital_div = div64_u64(ns_hdmipll_ck, posdiv1 * posdiv2 * pixel_clk); if (!(digital_div <= 32 && digital_div >= 1)) return -EINVAL; -- 2.54.0 -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] phy: mediatek: phy-mtk-hdmi-mt8195: Fix PLL calc divisor overflow 2026-07-01 12:19 ` [PATCH 1/2] phy: mediatek: phy-mtk-hdmi-mt8195: Fix PLL calc divisor overflow AngeloGioacchino Del Regno @ 2026-07-01 12:31 ` sashiko-bot 0 siblings, 0 replies; 4+ messages in thread From: sashiko-bot @ 2026-07-01 12:31 UTC (permalink / raw) To: AngeloGioacchino Del Regno Cc: dri-devel, olteanv, vkoul, linux-phy, neil.armstrong Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: Pre-existing issues: - [High] Calculations using `14835 * MEGA`, `5 * GIGA`, and `12 * GIGA` silently overflow 32-bit `unsigned long` types on 32-bit architectures, completely breaking clock tiering and boundary checks. -- commit 8179a32cf1dac8f1d080e57bbce79246661b50eb Author: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> phy: mediatek: phy-mtk-hdmi-mt8195: Fix PLL calc divisor overflow This commit fixes an issue where calculating a PLL rate for high display resolutions results in a pixel clock exceeding 32 bits, but the digital clock divider calculation uses div_u64(), which expects a 32-bit divisor. It resolves this by using div64_u64() instead to prevent overflow. > diff --git a/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c b/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c > index 1426a2db984d5..e6ee8e0800222 100644 > --- a/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c > +++ b/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c > @@ -290,7 +290,7 @@ static int mtk_hdmi_pll_calc(struct mtk_hdmi_phy *hdmi_phy, struct clk_hw *hw, [Severity: High] This is a pre-existing issue, but do the constants in this function silently overflow on 32-bit architectures? Earlier in mtk_hdmi_pll_calc(), there are tier threshold calculations like: else if ((tmds_clk * 100) >= 14835 * MEGA && (tmds_clk * 10) < 2967 * MEGA) and later boundary checks: if (ns_hdmipll_ck >= 5 * GIGA && ns_hdmipll_ck <= 12 * GIGA) If MEGA and GIGA evaluate as 32-bit types on 32-bit systems, a multiplication like 14835 * MEGA evaluates to 14,835,000,000, which wraps around modulo 2^32 to 1,950,098,112 before being promoted to u64 for the comparison against tmds_clk * 100. Similarly, 5 * GIGA and 12 * GIGA would overflow, potentially rendering the valid PLL clock range mathematically unreachable and forcing the function to always return -EINVAL on 32-bit builds. Should these constants be explicitly typed or cast to u64 to ensure the comparisons work correctly on 32-bit kernels? > posdiv2 = 1; > > /* Digital clk divider, max /32 */ > - digital_div = div_u64(ns_hdmipll_ck, posdiv1 * posdiv2 * pixel_clk); > + digital_div = div64_u64(ns_hdmipll_ck, posdiv1 * posdiv2 * pixel_clk); > if (!(digital_div <= 32 && digital_div >= 1)) > return -EINVAL; > -- Sashiko AI review · https://sashiko.dev/#/patchset/20260701121936.19407-1-angelogioacchino.delregno@collabora.com?part=1 -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] phy: mediatek: phy-mtk-hdmi-mt8195: Fix TMDS clk bit ratio setting 2026-07-01 12:19 [PATCH 0/2] MediaTek MT8195 HDMI PHY Fixes AngeloGioacchino Del Regno 2026-07-01 12:19 ` [PATCH 1/2] phy: mediatek: phy-mtk-hdmi-mt8195: Fix PLL calc divisor overflow AngeloGioacchino Del Regno @ 2026-07-01 12:19 ` AngeloGioacchino Del Regno 1 sibling, 0 replies; 4+ messages in thread From: AngeloGioacchino Del Regno @ 2026-07-01 12:19 UTC (permalink / raw) To: chunfeng.yun Cc: p.zabel, chunkuang.hu, vkoul, neil.armstrong, matthias.bgg, angelogioacchino.delregno, granquet, justin.yeh, dri-devel, linux-mediatek, linux-arm-kernel, linux-phy, linux-kernel, kernel The comment in the mtk_phy_tmds_clk_ratio() function clearly and correctly explains that the TMDS ratio has to be 1/10 for data rates under 3.4Gbps, and 1/40 over that. Unfortunately though, the TXC_DIV register setting was wrong, as in value 3 means to divide by 8 and, in order to achieve the in spec 1/40 (tmds) data rate, this has to divide by 4 instead! In order to achieve the correct 1/40 (tmds) data rate, this has Add definitions for the TXC_DIV register values clearly explaining the meanings (DIV2, DIV4, DIV8), and program the correct, DIV 4, value to the register in mtk_phy_tmds_clk_ratio(). This fixes out of spec clocking and, with this change, SoCs using the MT8195 class HDMI PHYs can now successfully be configured to output 3840x2160@60Hz over HDMI. Fixes: 45810d486bb4 ("phy: mediatek: add support for phy-mtk-hdmi-mt8195") Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> --- drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c | 2 +- drivers/phy/mediatek/phy-mtk-hdmi-mt8195.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c b/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c index e6ee8e080022..a4bc1268946d 100644 --- a/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c +++ b/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c @@ -36,7 +36,7 @@ mtk_phy_tmds_clk_ratio(struct mtk_hdmi_phy *hdmi_phy, bool enable) * clock bit ratio 1:40, under 3.4Gbps, clock bit ratio 1:10 */ if (enable) - mtk_phy_update_field(regs + HDMI20_CLK_CFG, REG_TXC_DIV, 3); + mtk_phy_update_field(regs + HDMI20_CLK_CFG, REG_TXC_DIV, VAL_TXC_DIV4); else mtk_phy_clear_bits(regs + HDMI20_CLK_CFG, REG_TXC_DIV); } diff --git a/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.h b/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.h index e26caaf4d104..58800d7659ca 100644 --- a/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.h +++ b/drivers/phy/mediatek/phy-mtk-hdmi-mt8195.h @@ -17,6 +17,9 @@ #define HDMI20_CLK_CFG 0x70 #define REG_TXC_DIV GENMASK(31, 30) +#define VAL_TXC_DIV2 1 +#define VAL_TXC_DIV4 2 +#define VAL_TXC_DIV8 3 #define HDMI_1_CFG_0 0x00 #define RG_HDMITX21_DRV_IBIAS_CLK GENMASK(10, 5) -- 2.54.0 -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-01 12:31 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-07-01 12:19 [PATCH 0/2] MediaTek MT8195 HDMI PHY Fixes AngeloGioacchino Del Regno 2026-07-01 12:19 ` [PATCH 1/2] phy: mediatek: phy-mtk-hdmi-mt8195: Fix PLL calc divisor overflow AngeloGioacchino Del Regno 2026-07-01 12:31 ` sashiko-bot 2026-07-01 12:19 ` [PATCH 2/2] phy: mediatek: phy-mtk-hdmi-mt8195: Fix TMDS clk bit ratio setting AngeloGioacchino Del Regno
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox