Skip to contentSkip to conversation

phy: mediatek: phy-mtk-hdmi: Use regmap to manipulate hdmi registers

RFC PATCH In review Luca Leonardo Scorcia 4 participants 6 messages Oct 11 – Oct 31

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover phy: mediatek: phy-mtk-hdmi: Use regmap to manipulate hdmi registers

While working on MediaTek mt8167 HDMI support I noticed that on some SoCs like mt8167 and mt8173 the registers used by HDMI PHY are actually inside the memory space mapped by the apmixedsys driver. On mt8173 this driver maps its memory using of_iomap, while on mt8167 it currently uses devm_platform_ioremap_resource. The current phy_hdmi_mtk uses devm_platform_ioremap_resource too, which causes a conflict between the two at probe:

hdmi-phy: error -EBUSY: can't request region for resource [mem 0x10018300-0x1001831f]

In patch [1] I initially proposed to use the same approach of mt8173 in mt8167 too. While working Sashiko correctly pointed out that it never unmaps its memory during remove [2], even on mt8173. It is of course possible to add code for that, but it would mean creating a dedicated drvdata structure, and it seems a little invasive. Using the devm_* functions is certainly cleaner.

This patch goes in the opposite direction - it converts all register access for mtk hdmi phy to the regmap_* functions and obtains the regmap using device_node_to_regmap, which internally uses iomap and does not trigger the conflict. This way memory can still be managed by the apmixedsys driver using the devm_* and the HDMI phy only gets a regmap.

This patch has been tested on mt8167 only. Unfortunately I have no devices with the other SoCs that are touched by this refactoring, so I am sending it as a RFC to gather feedback from more experienced kernel devs.

[1] https://lore.kernel.org/linux-mediatek/[email protected]/T/#u
[2] https://sashiko.dev/#/patchset/20261010115539.9237-1-l.scorcia%40gmail.com

Luca Leonardo Scorcia (1):
phy: mediatek: phy-mtk-hdmi: Use regmap to manipulate hdmi registers

 drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c | 145 ++++++++--------
 drivers/phy/mediatek/phy-mtk-hdmi-mt8173.c | 133 +++++++--------
 drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c | 185 ++++++++++-----------
 drivers/phy/mediatek/phy-mtk-hdmi.c        |   2 +-
 drivers/phy/mediatek/phy-mtk-hdmi.h        |   3 +-
 5 files changed, 235 insertions(+), 233 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH 1/1 phy: mediatek: phy-mtk-hdmi: Use regmap to manipulate hdmi registers

Use the regmap primitives to manipulate HDMI registers instead of custom helpers from phy-mtk-io.h. No functional changes.

This avoids the following issue with mt8167:

hdmi-phy: error -EBUSY: can't request region for resource [mem 0x10018300-0x1001831f]

due to the fact that HDMI PHY registers are actually mapped inside the apmixedsys memory space.

The same situation is present on mt8173 too but this SoC does not exhibit the issue as its apmixedsys driver uses of_iomap instead of devm_platform_ioremap_resource to map its memory space, just like regmap does.

---
 drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c | 145 ++++++++--------
 drivers/phy/mediatek/phy-mtk-hdmi-mt8173.c | 133 +++++++--------
 drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c | 185 ++++++++++-----------
 drivers/phy/mediatek/phy-mtk-hdmi.c        |   2 +-
 drivers/phy/mediatek/phy-mtk-hdmi.h        |   3 +-
 5 files changed, 235 insertions(+), 233 deletions(-)
drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c +72 -73
index c9a1f20e939b..7fcf9116a0a9 100644
@@ -5,7 +5,13 @@
  */
 
 #include "phy-mtk-hdmi.h"
-#include "phy-mtk-io.h"
+
+/* field @mask shall be constant and continuous */
+#define mtk_phy_update_regmap_field(regmap, reg, mask, val) \
+({ \
+	BUILD_BUG_ON_MSG(!__builtin_constant_p(mask), "mask is not constant"); \
+	regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
+})
 
 #define HDMI_CON0	0x00
 #define RG_HDMITX_DRV_IBIAS_MASK	GENMASK(5, 0)
@@ -50,21 +56,20 @@
 static int mtk_hdmi_pll_prepare(struct clk_hw *hw)
 {
 	struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
-	void __iomem *base = hdmi_phy->regs;
 
-	mtk_phy_set_bits(base + HDMI_CON7, RG_HTPLL_AUTOK_EN);
-	mtk_phy_clear_bits(base + HDMI_CON6, RG_HTPLL_RLH_EN);
-	mtk_phy_set_bits(base + HDMI_CON6, RG_HTPLL_POSDIV_MASK);
-	mtk_phy_set_bits(base + HDMI_CON2, RG_HDMITX_EN_MBIAS);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON7, RG_HTPLL_AUTOK_EN);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_RLH_EN);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_POSDIV_MASK);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_EN_MBIAS);
 	usleep_range(80, 100);
-	mtk_phy_set_bits(base + HDMI_CON6, RG_HTPLL_EN);
-	mtk_phy_set_bits(base + HDMI_CON2, RG_HDMITX_EN_TX_CKLDO);
-	mtk_phy_set_bits(base + HDMI_CON0, RG_HDMITX_EN_SLDO_MASK);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_EN);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_EN_TX_CKLDO);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_SLDO_MASK);
 	usleep_range(80, 100);
-	mtk_phy_set_bits(base + HDMI_CON2, RG_HDMITX_MBIAS_LPF_EN);
-	mtk_phy_set_bits(base + HDMI_CON0, RG_HDMITX_EN_SER_MASK);
-	mtk_phy_set_bits(base + HDMI_CON0, RG_HDMITX_EN_PRED_MASK);
-	mtk_phy_set_bits(base + HDMI_CON0, RG_HDMITX_EN_DRV_MASK);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_MBIAS_LPF_EN);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_SER_MASK);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_PRED_MASK);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_DRV_MASK);
 	usleep_range(80, 100);
 	return 0;
 }
@@ -72,21 +77,20 @@ static int mtk_hdmi_pll_prepare(struct clk_hw *hw)
 static void mtk_hdmi_pll_unprepare(struct clk_hw *hw)
 {
 	struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
-	void __iomem *base = hdmi_phy->regs;
 
-	mtk_phy_clear_bits(base + HDMI_CON0, RG_HDMITX_EN_DRV_MASK);
-	mtk_phy_clear_bits(base + HDMI_CON0, RG_HDMITX_EN_PRED_MASK);
-	mtk_phy_clear_bits(base + HDMI_CON0, RG_HDMITX_EN_SER_MASK);
-	mtk_phy_clear_bits(base + HDMI_CON2, RG_HDMITX_MBIAS_LPF_EN);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_DRV_MASK);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_PRED_MASK);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_SER_MASK);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_MBIAS_LPF_EN);
 	usleep_range(80, 100);
-	mtk_phy_clear_bits(base + HDMI_CON0, RG_HDMITX_EN_SLDO_MASK);
-	mtk_phy_clear_bits(base + HDMI_CON2, RG_HDMITX_EN_TX_CKLDO);
-	mtk_phy_clear_bits(base + HDMI_CON6, RG_HTPLL_EN);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_SLDO_MASK);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_EN_TX_CKLDO);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_EN);
 	usleep_range(80, 100);
-	mtk_phy_clear_bits(base + HDMI_CON2, RG_HDMITX_EN_MBIAS);
-	mtk_phy_clear_bits(base + HDMI_CON6, RG_HTPLL_POSDIV_MASK);
-	mtk_phy_clear_bits(base + HDMI_CON6, RG_HTPLL_RLH_EN);
-	mtk_phy_clear_bits(base + HDMI_CON7, RG_HTPLL_AUTOK_EN);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_EN_MBIAS);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_POSDIV_MASK);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_RLH_EN);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON7, RG_HTPLL_AUTOK_EN);
 	usleep_range(80, 100);
 }
 
@@ -94,7 +98,6 @@ static int mtk_hdmi_pll_set_rate(struct clk_hw *hw, unsigned long rate,
 				 unsigned long parent_rate)
 {
 	struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
-	void __iomem *base = hdmi_phy->regs;
 	u32 pos_div;
 
 	if (rate <= 64000000)
@@ -104,25 +107,25 @@ static int mtk_hdmi_pll_set_rate(struct clk_hw *hw, unsigned long rate,
 	else
 		pos_div = 1;
 
-	mtk_phy_set_bits(base + HDMI_CON6, RG_HTPLL_PREDIV_MASK);
-	mtk_phy_set_bits(base + HDMI_CON6, RG_HTPLL_POSDIV_MASK);
-	mtk_phy_set_bits(base + HDMI_CON2, RG_HDMITX_EN_TX_POSDIV);
-	mtk_phy_update_field(base + HDMI_CON6, RG_HTPLL_IC_MASK, 0x1);
-	mtk_phy_update_field(base + HDMI_CON6, RG_HTPLL_IR_MASK, 0x1);
-	mtk_phy_update_field(base + HDMI_CON2, RG_HDMITX_TX_POSDIV_MASK, pos_div);
-	mtk_phy_update_field(base + HDMI_CON6, RG_HTPLL_FBKSEL_MASK, 1);
-	mtk_phy_update_field(base + HDMI_CON6, RG_HTPLL_FBKDIV_MASK, 19);
-	mtk_phy_update_field(base + HDMI_CON7, RG_HTPLL_DIVEN_MASK, 0x2);
-	mtk_phy_update_field(base + HDMI_CON6, RG_HTPLL_BP_MASK, 0xc);
-	mtk_phy_update_field(base + HDMI_CON6, RG_HTPLL_BC_MASK, 0x2);
-	mtk_phy_update_field(base + HDMI_CON6, RG_HTPLL_BR_MASK, 0x1);
-
-	mtk_phy_clear_bits(base + HDMI_CON1, RG_HDMITX_PRED_IMP);
-	mtk_phy_update_field(base + HDMI_CON1, RG_HDMITX_PRED_IBIAS_MASK, 0x3);
-	mtk_phy_clear_bits(base + HDMI_CON0, RG_HDMITX_EN_IMP_MASK);
-	mtk_phy_update_field(base + HDMI_CON1, RG_HDMITX_DRV_IMP_MASK, 0x28);
-	mtk_phy_update_field(base + HDMI_CON4, RG_HDMITX_RESERVE_MASK, 0x28);
-	mtk_phy_update_field(base + HDMI_CON0, RG_HDMITX_DRV_IBIAS_MASK, 0xa);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_PREDIV_MASK);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_POSDIV_MASK);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_EN_TX_POSDIV);
+	mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_IC_MASK, 0x1);
+	mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_IR_MASK, 0x1);
+	mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_TX_POSDIV_MASK, pos_div);
+	mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_FBKSEL_MASK, 1);
+	mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_FBKDIV_MASK, 19);
+	mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON7, RG_HTPLL_DIVEN_MASK, 0x2);
+	mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_BP_MASK, 0xc);
+	mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_BC_MASK, 0x2);
+	mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_BR_MASK, 0x1);
+
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON1, RG_HDMITX_PRED_IMP);
+	mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON1, RG_HDMITX_PRED_IBIAS_MASK, 0x3);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_IMP_MASK);
+	mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON1, RG_HDMITX_DRV_IMP_MASK, 0x28);
+	mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON4, RG_HDMITX_RESERVE_MASK, 0x28);
+	mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_DRV_IBIAS_MASK, 0xa);
 	return 0;
 }
 
@@ -133,7 +136,7 @@ static unsigned long mtk_hdmi_pll_recalc_rate(struct clk_hw *hw,
 	unsigned long out_rate, val;
 	u32 tmp;
 
-	tmp = readl(hdmi_phy->regs + HDMI_CON6);
+	regmap_read(hdmi_phy->regs, HDMI_CON6, &tmp);
 	val = FIELD_GET(RG_HTPLL_PREDIV_MASK, tmp);
 	switch (val) {
 	case 0x00:
@@ -150,7 +153,7 @@ static unsigned long mtk_hdmi_pll_recalc_rate(struct clk_hw *hw,
 	val = FIELD_GET(RG_HTPLL_FBKDIV_MASK, tmp);
 	out_rate *= (val + 1) * 2;
 
-	tmp = readl(hdmi_phy->regs + HDMI_CON2);
+	regmap_read(hdmi_phy->regs, HDMI_CON2, &tmp);
 	val = FIELD_GET(RG_HDMITX_TX_POSDIV_MASK, tmp);
 	out_rate >>= val;
 
@@ -170,41 +173,37 @@ static const struct clk_ops mtk_hdmi_phy_pll_ops = {
 
 static void mtk_hdmi_phy_enable_tmds(struct mtk_hdmi_phy *hdmi_phy)
 {
-	void __iomem *base = hdmi_phy->regs;
-
-	mtk_phy_set_bits(base + HDMI_CON7, RG_HTPLL_AUTOK_EN);
-	mtk_phy_clear_bits(base + HDMI_CON6, RG_HTPLL_RLH_EN);
-	mtk_phy_set_bits(base + HDMI_CON6, RG_HTPLL_POSDIV_MASK);
-	mtk_phy_set_bits(base + HDMI_CON2, RG_HDMITX_EN_MBIAS);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON7, RG_HTPLL_AUTOK_EN);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_RLH_EN);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_POSDIV_MASK);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_EN_MBIAS);
 	usleep_range(80, 100);
-	mtk_phy_set_bits(base + HDMI_CON6, RG_HTPLL_EN);
-	mtk_phy_set_bits(base + HDMI_CON2, RG_HDMITX_EN_TX_CKLDO);
-	mtk_phy_set_bits(base + HDMI_CON0, RG_HDMITX_EN_SLDO_MASK);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_EN);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_EN_TX_CKLDO);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_SLDO_MASK);
 	usleep_range(80, 100);
-	mtk_phy_set_bits(base + HDMI_CON2, RG_HDMITX_MBIAS_LPF_EN);
-	mtk_phy_set_bits(base + HDMI_CON0, RG_HDMITX_EN_SER_MASK);
-	mtk_phy_set_bits(base + HDMI_CON0, RG_HDMITX_EN_PRED_MASK);
-	mtk_phy_set_bits(base + HDMI_CON0, RG_HDMITX_EN_DRV_MASK);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_MBIAS_LPF_EN);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_SER_MASK);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_PRED_MASK);
+	regmap_set_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_DRV_MASK);
 	usleep_range(80, 100);
 }
 
 static void mtk_hdmi_phy_disable_tmds(struct mtk_hdmi_phy *hdmi_phy)
 {
-	void __iomem *base = hdmi_phy->regs;
-
-	mtk_phy_clear_bits(base + HDMI_CON0, RG_HDMITX_EN_DRV_MASK);
-	mtk_phy_clear_bits(base + HDMI_CON0, RG_HDMITX_EN_PRED_MASK);
-	mtk_phy_clear_bits(base + HDMI_CON0, RG_HDMITX_EN_SER_MASK);
-	mtk_phy_clear_bits(base + HDMI_CON2, RG_HDMITX_MBIAS_LPF_EN);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_DRV_MASK);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_PRED_MASK);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_SER_MASK);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_MBIAS_LPF_EN);
 	usleep_range(80, 100);
-	mtk_phy_clear_bits(base + HDMI_CON0, RG_HDMITX_EN_SLDO_MASK);
-	mtk_phy_clear_bits(base + HDMI_CON2, RG_HDMITX_EN_TX_CKLDO);
-	mtk_phy_clear_bits(base + HDMI_CON6, RG_HTPLL_EN);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_SLDO_MASK);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_EN_TX_CKLDO);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_EN);
 	usleep_range(80, 100);
-	mtk_phy_clear_bits(base + HDMI_CON2, RG_HDMITX_EN_MBIAS);
-	mtk_phy_clear_bits(base + HDMI_CON6, RG_HTPLL_POSDIV_MASK);
-	mtk_phy_clear_bits(base + HDMI_CON6, RG_HTPLL_RLH_EN);
-	mtk_phy_clear_bits(base + HDMI_CON7, RG_HTPLL_AUTOK_EN);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_EN_MBIAS);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_POSDIV_MASK);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_RLH_EN);
+	regmap_clear_bits(hdmi_phy->regs, HDMI_CON7, RG_HTPLL_AUTOK_EN);
 	usleep_range(80, 100);
 }
 
drivers/phy/mediatek/phy-mtk-hdmi-mt8173.c +68 -65

189 lines not on this page · raw message

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c +92 -93

340 lines not on this page · raw message

drivers/phy/mediatek/phy-mtk-hdmi.c +1 -1
index 4e167a421f0e..0450cb6288ec 100644
@@ -116,7 +116,7 @@ static int mtk_hdmi_phy_probe(struct platform_device *pdev)
 	if (!hdmi_phy)
 		return -ENOMEM;
 
-	hdmi_phy->regs = devm_platform_ioremap_resource(pdev, 0);
+	hdmi_phy->regs = device_node_to_regmap(dev->of_node);
 	if (IS_ERR(hdmi_phy->regs))
 		return PTR_ERR(hdmi_phy->regs);
 
drivers/phy/mediatek/phy-mtk-hdmi.h +2 -1
index 5137d1c3345b..63ec39a343cc 100644
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 #include <linux/phy/phy.h>
 #include <linux/platform_device.h>
+#include <linux/regmap.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
 #include <linux/types.h>
@@ -30,7 +31,7 @@ struct mtk_hdmi_phy_conf {
 };
 
 struct mtk_hdmi_phy {
-	void __iomem *regs;
+	struct regmap *regs;
 	struct device *dev;
 	struct mtk_hdmi_phy_conf *conf;
 	struct clk *pll;
Signature · 1 line
2.43.0
#2 lore raw
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] phy: mediatek: uninitialized stack variable used if regmap_read() fails - [Medium] phy…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] phy: mediatek: uninitialized stack variable used if regmap_read() fails
- [Medium] phy: mediatek: uninitialized stack variable use if regmap_read() fails
- [Low] Build: missing explicit include of <linux/bitfield.h>
--

commit 0d55ccaecdee64be04bc28971e8e4aca3393e3a3
Author: Luca Leonardo Scorcia <[email protected]>

phy: mediatek: phy-mtk-hdmi: Use regmap to manipulate hdmi registers

This commit transitions the Mediatek HDMI PHY driver to use the regmap API for register manipulation, removing custom helpers. This resolves an -EBUSY error on mt8167 devices where the HDMI PHY registers are mapped inside the apmixedsys memory space.

Quoted 6 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c +0 -0
index c9a1f20e939b9..7fcf9116a0a93 100644
@@ -5,7 +5,13 @@
  */

drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c line 14

Quoted 10 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c +7 -1
 
 #include "phy-mtk-hdmi.h"
-#include "phy-mtk-io.h"
+
+/* field @mask shall be constant and continuous */
+#define mtk_phy_update_regmap_field(regmap, reg, mask, val) \
+({ \
+	BUILD_BUG_ON_MSG(!__builtin_constant_p(mask), "mask is not constant"); \
+	regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
+})

[Severity: Low]
The code removes phy-mtk-io.h which explicitly included <linux/bitfield.h>, but does not add <linux/bitfield.h> while still using FIELD_PREP. Relying on implicit transitive inclusion for core bitfield macros can sometimes cause build failures across different architectures or under varying compiler flags. Should <linux/bitfield.h> be explicitly included in this file or the common header?

[ ... ]

drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c static unsigned long mtk_hdmi_pll_recalc_rate(struct clk_hw *hw, · line 140

Quoted 7 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c +1 -1
@@ -133,7 +136,7 @@ static unsigned long mtk_hdmi_pll_recalc_rate(struct clk_hw *hw,
 	unsigned long out_rate, val;
 	u32 tmp;
 
-	tmp = readl(hdmi_phy->regs + HDMI_CON6);
+	regmap_read(hdmi_phy->regs, HDMI_CON6, &tmp);
 	val = FIELD_GET(RG_HTPLL_PREDIV_MASK, tmp);

[Severity: Medium]
If regmap_read() fails and returns an error code, tmp is left uninitialized. Using the uninitialized stack variable tmp in the FIELD_GET macro leads to undefined behavior, which could result in incorrect PLL clock rates. Should the return value of regmap_read() be checked here?

drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c static unsigned long mtk_hdmi_pll_recalc_rate(struct clk_hw *hw, · line 157

Quoted 9 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c +1 -1
 	switch (val) {
 	case 0x00:
@@ -150,7 +153,7 @@ static unsigned long mtk_hdmi_pll_recalc_rate(struct clk_hw *hw,
 	val = FIELD_GET(RG_HTPLL_FBKDIV_MASK, tmp);
 	out_rate *= (val + 1) * 2;
 
-	tmp = readl(hdmi_phy->regs + HDMI_CON2);
+	regmap_read(hdmi_phy->regs, HDMI_CON2, &tmp);
 	val = FIELD_GET(RG_HDMITX_TX_POSDIV_MASK, tmp);

[Severity: Medium]
Similar to the previous read, if regmap_read() fails, tmp remains uninitialized. Does this also need an error check?

[ ... ]

Quoted 6 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt8173.c +0 -0
index 58c6596c8c20b..6df997ff74c97 100644
@@ -5,7 +5,13 @@
  */

drivers/phy/mediatek/phy-mtk-hdmi-mt8173.c line 14

Quoted 10 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt8173.c +7 -1
 
 #include "phy-mtk-hdmi.h"
-#include "phy-mtk-io.h"
+
+/* field @mask shall be constant and continuous */
+#define mtk_phy_update_regmap_field(regmap, reg, mask, val) \
+({ \
+	BUILD_BUG_ON_MSG(!__builtin_constant_p(mask), "mask is not constant"); \
+	regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
+})

[Severity: Low]
As in the mt2701 driver, <linux/bitfield.h> is not explicitly included but FIELD_PREP is used. Should the header be explicitly included here as well?

[ ... ]

Quoted 8 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c +0 -0
index a4bc1268946d8..5d6122277725a 100644
@@ -15,62 +15,64 @@
 #include <linux/units.h>
 #include <linux/nvmem-consumer.h>
 

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c line 26

Quoted 10 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c +6 -1
-#include "phy-mtk-io.h"
 #include "phy-mtk-hdmi.h"
 #include "phy-mtk-hdmi-mt8195.h"
 
+/* field @mask shall be constant and continuous */
+#define mtk_phy_update_regmap_field(regmap, reg, mask, val) \
+({ \
+	BUILD_BUG_ON_MSG(!__builtin_constant_p(mask), "mask is not constant"); \
+	regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
+})

[Severity: Low]
Missing explicit include of <linux/bitfield.h> for FIELD_PREP here too.

[ ... ]

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c static int mtk_hdmi_phy_pwr5v_disable(struct regulator_dev *rdev) · line 505

Quoted 11 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c +4 -1
@@ -501,8 +497,11 @@ static int mtk_hdmi_phy_pwr5v_disable(struct regulator_dev *rdev)
 static int mtk_hdmi_phy_pwr5v_is_enabled(struct regulator_dev *rdev)
 {
 	struct mtk_hdmi_phy *hdmi_phy = rdev_get_drvdata(rdev);
+	u32 tmp;
+
+	regmap_read(hdmi_phy->regs, HDMI_CTL_1, &tmp);
 
-	return !!(readl(hdmi_phy->regs + HDMI_CTL_1) & RG_HDMITX_PWR5V_O);
+	return !!(tmp & RG_HDMITX_PWR5V_O);
 }

[Severity: Medium]
If regmap_read() fails, tmp is uninitialized. The function then evaluates the regulator enabled state based on stack garbage. Does regmap_read()'s return value need to be checked to prevent this?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw
In reply to Luca Leonardo Scorcia
kernel test robot noticed the following build errors:

Hi Luca,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on linux-review/Luca-Leonardo-Scorcia/dt-bindings-mediatek-hdmi-phy-Add-compatible-for-mt8167/20261010-135401]

url:    https://github.com/intel-lab-lkp/linux/commits/Luca-Leonardo-Scorcia/phy-mediatek-phy-mtk-hdmi-Use-regmap-to-manipulate-hdmi-registers/20261011-102031
base:   https://github.com/intel-lab-lkp/linux Luca-Leonardo-Scorcia/dt-bindings-mediatek-hdmi-phy-Add-compatible-for-mt8167/20261010-135401
patch link:    https://lore.kernel.org/r/20261011082042.348422-2-l.scorcia%40gmail.com
patch subject: [RFC PATCH 1/1] phy: mediatek: phy-mtk-hdmi: Use regmap to manipulate hdmi registers
config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20261015/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261015/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c: In function 'mtk_hdmi_pll_set_rate':

>> drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:13:47: error: implicit declaration of function 'FIELD_PREP' [-Wimplicit-function-declaration]
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^~~~~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:113:9: note: in expansion of macro 'mtk_phy_update_regmap_field'
     113 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_IC_MASK, 0x1);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c: In function 'mtk_hdmi_pll_recalc_rate':
>> drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:140:15: error: implicit declaration of function 'FIELD_GET' [-Wimplicit-function-declaration]
     140 |         val = FIELD_GET(RG_HTPLL_PREDIV_MASK, tmp);
         |               ^~~~~~~~~
--
   In file included from include/linux/swab.h:5,
                    from include/uapi/linux/byteorder/big_endian.h:14,
                    from include/linux/byteorder/big_endian.h:5,
                    from arch/m68k/include/uapi/asm/byteorder.h:5,
                    from include/asm-generic/bitops/le.h:6,
                    from arch/m68k/include/asm/bitops.h:569,
                    from include/linux/bitops.h:67,
                    from include/linux/kernel.h:23,
                    from include/linux/clk.h:13,
                    from drivers/phy/mediatek/phy-mtk-hdmi.h:9,
                    from drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:2:
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c: In function 'mtk_hdmi_pll_recalc_rate':
>> drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:156:36: error: invalid use of undefined type 'struct regmap'
     156 |         tmp = readl(hdmi_phy->regs + HDMI_CON6);
         |                                    ^
   include/uapi/linux/swab.h:118:38: note: in definition of macro '__swab32'
     118 |         (__u32)(__builtin_constant_p(x) ?       \
         |                                      ^
   include/linux/byteorder/generic.h:89:21: note: in expansion of macro '__le32_to_cpu'
      89 | #define le32_to_cpu __le32_to_cpu
         |                     ^~~~~~~~~~~~~
   arch/m68k/include/asm/io_mm.h:372:26: note: in expansion of macro 'in_le32'
     372 | #define readl(addr)      in_le32(addr)
         |                          ^~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:156:15: note: in expansion of macro 'readl'
     156 |         tmp = readl(hdmi_phy->regs + HDMI_CON6);
         |               ^~~~~
>> drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:156:36: error: invalid use of undefined type 'struct regmap'
     156 |         tmp = readl(hdmi_phy->regs + HDMI_CON6);
         |                                    ^
   include/uapi/linux/swab.h:19:19: note: in definition of macro '___constant_swab32'
      19 |         (((__u32)(x) & (__u32)0x000000ffUL) << 24) |            \
         |                   ^
   include/uapi/linux/byteorder/big_endian.h:35:26: note: in expansion of macro '__swab32'
      35 | #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
         |                          ^~~~~~~~
   include/linux/byteorder/generic.h:89:21: note: in expansion of macro '__le32_to_cpu'
      89 | #define le32_to_cpu __le32_to_cpu
         |                     ^~~~~~~~~~~~~
   arch/m68k/include/asm/io_mm.h:372:26: note: in expansion of macro 'in_le32'
     372 | #define readl(addr)      in_le32(addr)
         |                          ^~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:156:15: note: in expansion of macro 'readl'
     156 |         tmp = readl(hdmi_phy->regs + HDMI_CON6);
         |               ^~~~~
>> drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:156:36: error: invalid use of undefined type 'struct regmap'
     156 |         tmp = readl(hdmi_phy->regs + HDMI_CON6);
         |                                    ^
   include/uapi/linux/swab.h:20:19: note: in definition of macro '___constant_swab32'
      20 |         (((__u32)(x) & (__u32)0x0000ff00UL) <<  8) |            \
         |                   ^
   include/uapi/linux/byteorder/big_endian.h:35:26: note: in expansion of macro '__swab32'
      35 | #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
         |                          ^~~~~~~~
   include/linux/byteorder/generic.h:89:21: note: in expansion of macro '__le32_to_cpu'
      89 | #define le32_to_cpu __le32_to_cpu
         |                     ^~~~~~~~~~~~~
   arch/m68k/include/asm/io_mm.h:372:26: note: in expansion of macro 'in_le32'
     372 | #define readl(addr)      in_le32(addr)
         |                          ^~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:156:15: note: in expansion of macro 'readl'
     156 |         tmp = readl(hdmi_phy->regs + HDMI_CON6);
         |               ^~~~~
>> drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:156:36: error: invalid use of undefined type 'struct regmap'
     156 |         tmp = readl(hdmi_phy->regs + HDMI_CON6);
         |                                    ^
   include/uapi/linux/swab.h:21:19: note: in definition of macro '___constant_swab32'
      21 |         (((__u32)(x) & (__u32)0x00ff0000UL) >>  8) |            \
         |                   ^
   include/uapi/linux/byteorder/big_endian.h:35:26: note: in expansion of macro '__swab32'
      35 | #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
         |                          ^~~~~~~~
   include/linux/byteorder/generic.h:89:21: note: in expansion of macro '__le32_to_cpu'
      89 | #define le32_to_cpu __le32_to_cpu
         |                     ^~~~~~~~~~~~~
   arch/m68k/include/asm/io_mm.h:372:26: note: in expansion of macro 'in_le32'
     372 | #define readl(addr)      in_le32(addr)
         |                          ^~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:156:15: note: in expansion of macro 'readl'
     156 |         tmp = readl(hdmi_phy->regs + HDMI_CON6);
         |               ^~~~~
>> drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:156:36: error: invalid use of undefined type 'struct regmap'
     156 |         tmp = readl(hdmi_phy->regs + HDMI_CON6);
         |                                    ^
   include/uapi/linux/swab.h:22:19: note: in definition of macro '___constant_swab32'
      22 |         (((__u32)(x) & (__u32)0xff000000UL) >> 24)))
         |                   ^
   include/uapi/linux/byteorder/big_endian.h:35:26: note: in expansion of macro '__swab32'
      35 | #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
         |                          ^~~~~~~~
   include/linux/byteorder/generic.h:89:21: note: in expansion of macro '__le32_to_cpu'
      89 | #define le32_to_cpu __le32_to_cpu
         |                     ^~~~~~~~~~~~~
   arch/m68k/include/asm/io_mm.h:372:26: note: in expansion of macro 'in_le32'
     372 | #define readl(addr)      in_le32(addr)
         |                          ^~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:156:15: note: in expansion of macro 'readl'
     156 |         tmp = readl(hdmi_phy->regs + HDMI_CON6);
         |               ^~~~~
>> drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:156:36: error: invalid use of undefined type 'struct regmap'
     156 |         tmp = readl(hdmi_phy->regs + HDMI_CON6);
         |                                    ^
   include/uapi/linux/swab.h:120:19: note: in definition of macro '__swab32'
     120 |         __fswab32(x))
         |                   ^
   include/linux/byteorder/generic.h:89:21: note: in expansion of macro '__le32_to_cpu'
      89 | #define le32_to_cpu __le32_to_cpu
         |                     ^~~~~~~~~~~~~
   arch/m68k/include/asm/io_mm.h:372:26: note: in expansion of macro 'in_le32'
     372 | #define readl(addr)      in_le32(addr)
         |                          ^~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:156:15: note: in expansion of macro 'readl'
     156 |         tmp = readl(hdmi_phy->regs + HDMI_CON6);
         |               ^~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:173:36: error: invalid use of undefined type 'struct regmap'
     173 |         tmp = readl(hdmi_phy->regs + HDMI_CON2);
         |                                    ^
   include/uapi/linux/swab.h:118:38: note: in definition of macro '__swab32'
     118 |         (__u32)(__builtin_constant_p(x) ?       \
         |                                      ^
   include/linux/byteorder/generic.h:89:21: note: in expansion of macro '__le32_to_cpu'
      89 | #define le32_to_cpu __le32_to_cpu
         |                     ^~~~~~~~~~~~~
   arch/m68k/include/asm/io_mm.h:372:26: note: in expansion of macro 'in_le32'
     372 | #define readl(addr)      in_le32(addr)
         |                          ^~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:173:15: note: in expansion of macro 'readl'
     173 |         tmp = readl(hdmi_phy->regs + HDMI_CON2);
         |               ^~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:173:36: error: invalid use of undefined type 'struct regmap'
     173 |         tmp = readl(hdmi_phy->regs + HDMI_CON2);
         |                                    ^
   include/uapi/linux/swab.h:19:19: note: in definition of macro '___constant_swab32'
      19 |         (((__u32)(x) & (__u32)0x000000ffUL) << 24) |            \
         |                   ^
   include/uapi/linux/byteorder/big_endian.h:35:26: note: in expansion of macro '__swab32'
      35 | #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
         |                          ^~~~~~~~
   include/linux/byteorder/generic.h:89:21: note: in expansion of macro '__le32_to_cpu'
      89 | #define le32_to_cpu __le32_to_cpu
         |                     ^~~~~~~~~~~~~
   arch/m68k/include/asm/io_mm.h:372:26: note: in expansion of macro 'in_le32'
     372 | #define readl(addr)      in_le32(addr)
         |                          ^~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:173:15: note: in expansion of macro 'readl'
     173 |         tmp = readl(hdmi_phy->regs + HDMI_CON2);
         |               ^~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:173:36: error: invalid use of undefined type 'struct regmap'
     173 |         tmp = readl(hdmi_phy->regs + HDMI_CON2);
         |                                    ^
   include/uapi/linux/swab.h:20:19: note: in definition of macro '___constant_swab32'
      20 |         (((__u32)(x) & (__u32)0x0000ff00UL) <<  8) |            \
         |                   ^
   include/uapi/linux/byteorder/big_endian.h:35:26: note: in expansion of macro '__swab32'
      35 | #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
         |                          ^~~~~~~~
   include/linux/byteorder/generic.h:89:21: note: in expansion of macro '__le32_to_cpu'
      89 | #define le32_to_cpu __le32_to_cpu
         |                     ^~~~~~~~~~~~~
   arch/m68k/include/asm/io_mm.h:372:26: note: in expansion of macro 'in_le32'
     372 | #define readl(addr)      in_le32(addr)
         |                          ^~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:173:15: note: in expansion of macro 'readl'
     173 |         tmp = readl(hdmi_phy->regs + HDMI_CON2);
         |               ^~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:173:36: error: invalid use of undefined type 'struct regmap'
     173 |         tmp = readl(hdmi_phy->regs + HDMI_CON2);
         |                                    ^
   include/uapi/linux/swab.h:21:19: note: in definition of macro '___constant_swab32'
      21 |         (((__u32)(x) & (__u32)0x00ff0000UL) >>  8) |            \
         |                   ^
   include/uapi/linux/byteorder/big_endian.h:35:26: note: in expansion of macro '__swab32'
      35 | #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
         |                          ^~~~~~~~
   include/linux/byteorder/generic.h:89:21: note: in expansion of macro '__le32_to_cpu'
      89 | #define le32_to_cpu __le32_to_cpu
         |                     ^~~~~~~~~~~~~
   arch/m68k/include/asm/io_mm.h:372:26: note: in expansion of macro 'in_le32'
     372 | #define readl(addr)      in_le32(addr)
         |                          ^~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:173:15: note: in expansion of macro 'readl'
     173 |         tmp = readl(hdmi_phy->regs + HDMI_CON2);
         |               ^~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:173:36: error: invalid use of undefined type 'struct regmap'
     173 |         tmp = readl(hdmi_phy->regs + HDMI_CON2);
         |                                    ^
   include/uapi/linux/swab.h:22:19: note: in definition of macro '___constant_swab32'
      22 |         (((__u32)(x) & (__u32)0xff000000UL) >> 24)))
         |                   ^
   include/uapi/linux/byteorder/big_endian.h:35:26: note: in expansion of macro '__swab32'
      35 | #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
         |                          ^~~~~~~~
   include/linux/byteorder/generic.h:89:21: note: in expansion of macro '__le32_to_cpu'
      89 | #define le32_to_cpu __le32_to_cpu
         |                     ^~~~~~~~~~~~~
   arch/m68k/include/asm/io_mm.h:372:26: note: in expansion of macro 'in_le32'
     372 | #define readl(addr)      in_le32(addr)
         |                          ^~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:173:15: note: in expansion of macro 'readl'
     173 |         tmp = readl(hdmi_phy->regs + HDMI_CON2);
--
   drivers/phy/mediatek/phy-mtk-hdmi-mt8173.c: In function 'mtk_hdmi_pll_set_rate':
>> drivers/phy/mediatek/phy-mtk-hdmi-mt8173.c:13:47: error: implicit declaration of function 'FIELD_PREP' [-Wimplicit-function-declaration]
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^~~~~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8173.c:163:9: note: in expansion of macro 'mtk_phy_update_regmap_field'
     163 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_PLL_PREDIV, pre_div);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
--
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c: In function 'mtk_phy_tmds_clk_ratio':
>> drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:47: error: implicit declaration of function 'FIELD_PREP' [-Wimplicit-function-declaration]
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^~~~~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:43:17: note: in expansion of macro 'mtk_phy_update_regmap_field'
      43 |                 mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI20_CLK_CFG, REG_TXC_DIV, VAL_TXC_DIV4);
         |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c: In function 'mtk_hdmi_pll_calc':
>> drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:282:23: error: implicit declaration of function 'FIELD_GET' [-Wimplicit-function-declaration]
     282 |         fbkdiv_high = FIELD_GET(GENMASK_ULL(63, 32), pcw);
         |                       ^~~~~~~~~

vim +/FIELD_PREP +13 drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c

     8	
     9	/* field @mask shall be constant and continuous */
    10	#define mtk_phy_update_regmap_field(regmap, reg, mask, val) \
    11	({ \
    12		BUILD_BUG_ON_MSG(!__builtin_constant_p(mask), "mask is not constant"); \
  > 13		regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
    14	})
    15	
    16	#define HDMI_CON0	0x00
    17	#define RG_HDMITX_DRV_IBIAS_MASK	GENMASK(5, 0)
    18	#define RG_HDMITX_EN_SER_MASK		GENMASK(15, 12)
    19	#define RG_HDMITX_EN_SLDO_MASK		GENMASK(19, 16)
    20	#define RG_HDMITX_EN_PRED_MASK		GENMASK(23, 20)
    21	#define RG_HDMITX_EN_IMP_MASK		GENMASK(27, 24)
    22	#define RG_HDMITX_EN_DRV_MASK		GENMASK(31, 28)
    23	
    24	#define HDMI_CON1	0x04
    25	#define RG_HDMITX_PRED_IBIAS_MASK	GENMASK(21, 18)
    26	#define RG_HDMITX_PRED_IMP		BIT(22)
    27	#define RG_HDMITX_DRV_IMP_MASK		GENMASK(31, 26)
    28	
    29	#define HDMI_CON2	0x08
    30	#define RG_HDMITX_EN_TX_CKLDO		BIT(0)
    31	#define RG_HDMITX_EN_TX_POSDIV		BIT(1)
    32	#define RG_HDMITX_TX_POSDIV_MASK	GENMASK(4, 3)
    33	#define RG_HDMITX_EN_MBIAS		BIT(6)
    34	#define RG_HDMITX_MBIAS_LPF_EN		BIT(7)
    35	
    36	#define HDMI_CON4	0x10
    37	#define RG_HDMITX_RESERVE_MASK		GENMASK(31, 0)
    38	
    39	#define HDMI_CON6	0x18
    40	#define RG_HTPLL_BR_MASK		GENMASK(1, 0)
    41	#define RG_HTPLL_BC_MASK		GENMASK(3, 2)
    42	#define RG_HTPLL_BP_MASK		GENMASK(7, 4)
    43	#define RG_HTPLL_IR_MASK		GENMASK(11, 8)
    44	#define RG_HTPLL_IC_MASK		GENMASK(15, 12)
    45	#define RG_HTPLL_POSDIV_MASK		GENMASK(17, 16)
    46	#define RG_HTPLL_PREDIV_MASK		GENMASK(19, 18)
    47	#define RG_HTPLL_FBKSEL_MASK		GENMASK(21, 20)
    48	#define RG_HTPLL_RLH_EN			BIT(22)
    49	#define RG_HTPLL_FBKDIV_MASK		GENMASK(30, 24)
    50	#define RG_HTPLL_EN			BIT(31)
    51	
    52	#define HDMI_CON7	0x1c
    53	#define RG_HTPLL_AUTOK_EN		BIT(23)
    54	#define RG_HTPLL_DIVEN_MASK		GENMASK(30, 28)
    55	
    56	static int mtk_hdmi_pll_prepare(struct clk_hw *hw)
    57	{
    58		struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
    59	
    60		regmap_set_bits(hdmi_phy->regs, HDMI_CON7, RG_HTPLL_AUTOK_EN);
    61		regmap_clear_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_RLH_EN);
    62		regmap_set_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_POSDIV_MASK);
    63		regmap_set_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_EN_MBIAS);
    64		usleep_range(80, 100);
    65		regmap_set_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_EN);
    66		regmap_set_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_EN_TX_CKLDO);
    67		regmap_set_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_SLDO_MASK);
    68		usleep_range(80, 100);
    69		regmap_set_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_MBIAS_LPF_EN);
    70		regmap_set_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_SER_MASK);
    71		regmap_set_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_PRED_MASK);
    72		regmap_set_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_DRV_MASK);
    73		usleep_range(80, 100);
    74		return 0;
    75	}
    76	
    77	static void mtk_hdmi_pll_unprepare(struct clk_hw *hw)
    78	{
    79		struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
    80	
    81		regmap_clear_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_DRV_MASK);
    82		regmap_clear_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_PRED_MASK);
    83		regmap_clear_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_SER_MASK);
    84		regmap_clear_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_MBIAS_LPF_EN);
    85		usleep_range(80, 100);
    86		regmap_clear_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_SLDO_MASK);
    87		regmap_clear_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_EN_TX_CKLDO);
    88		regmap_clear_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_EN);
    89		usleep_range(80, 100);
    90		regmap_clear_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_EN_MBIAS);
    91		regmap_clear_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_POSDIV_MASK);
    92		regmap_clear_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_RLH_EN);
    93		regmap_clear_bits(hdmi_phy->regs, HDMI_CON7, RG_HTPLL_AUTOK_EN);
    94		usleep_range(80, 100);
    95	}
    96	
    97	static int mtk_hdmi_pll_set_rate(struct clk_hw *hw, unsigned long rate,
    98					 unsigned long parent_rate)
    99	{
   100		struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
   101		u32 pos_div;
   102	
   103		if (rate <= 64000000)
   104			pos_div = 3;
   105		else if (rate <= 128000000)
   106			pos_div = 2;
   107		else
   108			pos_div = 1;
   109	
   110		regmap_set_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_PREDIV_MASK);
   111		regmap_set_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_POSDIV_MASK);
   112		regmap_set_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_EN_TX_POSDIV);
   113		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_IC_MASK, 0x1);
   114		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_IR_MASK, 0x1);
   115		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_TX_POSDIV_MASK, pos_div);
   116		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_FBKSEL_MASK, 1);
   117		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_FBKDIV_MASK, 19);
   118		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON7, RG_HTPLL_DIVEN_MASK, 0x2);
   119		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_BP_MASK, 0xc);
   120		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_BC_MASK, 0x2);
   121		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_BR_MASK, 0x1);
   122	
   123		regmap_clear_bits(hdmi_phy->regs, HDMI_CON1, RG_HDMITX_PRED_IMP);
   124		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON1, RG_HDMITX_PRED_IBIAS_MASK, 0x3);
   125		regmap_clear_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_IMP_MASK);
   126		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON1, RG_HDMITX_DRV_IMP_MASK, 0x28);
   127		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON4, RG_HDMITX_RESERVE_MASK, 0x28);
   128		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_DRV_IBIAS_MASK, 0xa);
   129		return 0;
   130	}
   131	
   132	static unsigned long mtk_hdmi_pll_recalc_rate(struct clk_hw *hw,
   133						      unsigned long parent_rate)
   134	{
   135		struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
   136		unsigned long out_rate, val;
   137		u32 tmp;
   138	
   139		regmap_read(hdmi_phy->regs, HDMI_CON6, &tmp);
 > 140		val = FIELD_GET(RG_HTPLL_PREDIV_MASK, tmp);

141 switch (val) {
142 case 0x00:
143 out_rate = parent_rate;
144 break;
145 case 0x01:
146 out_rate = parent_rate / 2;
147 break;
148 default:
149 out_rate = parent_rate / 4;
150 break;
151 }
152
153 val = FIELD_GET(RG_HTPLL_FBKDIV_MASK, tmp);
154 out_rate *= (val + 1) * 2;
155
156 regmap_read(hdmi_phy->regs, HDMI_CON2, &tmp);
157 val = FIELD_GET(RG_HDMITX_TX_POSDIV_MASK, tmp);
158 out_rate >>= val;
159
160 if (tmp & RG_HDMITX_EN_TX_POSDIV)
161 out_rate /= 5;
162
163 return out_rate;
164 }
165

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#4 lore raw
In reply to Luca Leonardo Scorcia
kernel test robot noticed the following build errors:

Hi Luca,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on linux-review/Luca-Leonardo-Scorcia/dt-bindings-mediatek-hdmi-phy-Add-compatible-for-mt8167/20261010-135401]

url:    https://github.com/intel-lab-lkp/linux/commits/Luca-Leonardo-Scorcia/phy-mediatek-phy-mtk-hdmi-Use-regmap-to-manipulate-hdmi-registers/20261011-102031
base:   https://github.com/intel-lab-lkp/linux Luca-Leonardo-Scorcia/dt-bindings-mediatek-hdmi-phy-Add-compatible-for-mt8167/20261010-135401
patch link:    https://lore.kernel.org/r/20261011082042.348422-2-l.scorcia%40gmail.com
patch subject: [RFC PATCH 1/1] phy: mediatek: phy-mtk-hdmi: Use regmap to manipulate hdmi registers
config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20261015/[email protected]/config)
compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project 6719b9e31d6a93099612c474eec76d9f41d0275a)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261015/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:113:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     113 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_IC_MASK, 0x1);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:13:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:114:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     114 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_IR_MASK, 0x1);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:13:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:115:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     115 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_TX_POSDIV_MASK, pos_div);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:13:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:116:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     116 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_FBKSEL_MASK, 1);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:13:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:117:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     117 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_FBKDIV_MASK, 19);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:13:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:118:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     118 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON7, RG_HTPLL_DIVEN_MASK, 0x2);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:13:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:119:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     119 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_BP_MASK, 0xc);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:13:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:120:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     120 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_BC_MASK, 0x2);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:13:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:121:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     121 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_BR_MASK, 0x1);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:13:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:124:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     124 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON1, RG_HDMITX_PRED_IBIAS_MASK, 0x3);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:13:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:126:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     126 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON1, RG_HDMITX_DRV_IMP_MASK, 0x28);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:13:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:127:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     127 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON4, RG_HDMITX_RESERVE_MASK, 0x28);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:13:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:128:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     128 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_DRV_IBIAS_MASK, 0xa);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:13:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
>> drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c:140:8: error: call to undeclared function 'FIELD_GET'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     140 |         val = FIELD_GET(RG_HTPLL_PREDIV_MASK, tmp);
         |               ^
   14 errors generated.
--
>> drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:156:29: error: arithmetic on a pointer to an incomplete type 'struct regmap'
     156 |         tmp = readl(hdmi_phy->regs + HDMI_CON6);
         |                     ~~~~~~~~~~~~~~ ^
   include/linux/mfd/syscon.h:20:8: note: forward declaration of 'struct regmap'
      20 | struct regmap *device_node_to_regmap(struct device_node *np);
         |        ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8167.c:173:29: error: arithmetic on a pointer to an incomplete type 'struct regmap'
     173 |         tmp = readl(hdmi_phy->regs + HDMI_CON2);
         |                     ~~~~~~~~~~~~~~ ^
   include/linux/mfd/syscon.h:20:8: note: forward declaration of 'struct regmap'
      20 | struct regmap *device_node_to_regmap(struct device_node *np);
         |        ^
   2 errors generated.
--
>> drivers/phy/mediatek/phy-mtk-hdmi-mt8173.c:163:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     163 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_PLL_PREDIV, pre_div);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8173.c:13:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      13 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8173.c:167:7: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     167 |                            FIELD_PREP(RG_HDMITX_PLL_IC, 0x1) |
         |                            ^
   2 errors generated.
--
>> drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:43:3: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      43 |                 mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI20_CLK_CFG, REG_TXC_DIV, VAL_TXC_DIV4);
         |                 ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:65:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      65 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_PLL_CFG_2, RG_HDMITXPLL_IC, 0x1);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:66:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      66 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_PLL_CFG_2, RG_HDMITXPLL_BR, 0x2);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:67:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      67 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_PLL_CFG_2, RG_HDMITXPLL_IR, 0x2);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:72:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      72 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_PLL_CFG_0, RG_HDMITXPLL_HREN, 0x1);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:73:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      73 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_PLL_CFG_0, RG_HDMITXPLL_LVR_SEL, 0x1);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:99:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      99 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_CFG_10, RG_HDMITX21_BIAS_PE_BG_VREF_SEL, 0x2);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:101:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     101 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_CFG_9, RG_HDMITX21_SLDO_VREF_SEL, 0x2);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:104:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     104 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_CFG_6, RG_HDMITX21_INTR_CAL, 0x11);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:110:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     110 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_CFG_6, RG_HDMITX21_TX_POSDIV, txposdiv_value);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:136:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     136 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_PLL_CFG_4, RG_HDMITXPLL_POSDIV_DIV3_CTRL, div3_ctrl_value);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:137:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     137 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_PLL_CFG_4, RG_HDMITXPLL_POSDIV, posdiv_vallue);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:157:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     157 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_PLL_CFG_4, RG_HDMITXPLL_DIV_CTRL, div_ctrl_value);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:180:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     180 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_PLL_CFG_1, RG_HDMITXPLL_RESERVE_BIT3_2, reserve_3_2_value);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:183:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     183 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_PLL_CFG_1, RG_HDMITXPLL_RESERVE_BIT1_0, 0x2);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:188:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     188 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_PLL_CFG_4, RG_HDMITXPLL_PREDIV, prediv_value);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \
         |                                               ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:193:2: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     193 |         mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_1_PLL_CFG_1, RG_HDMITXPLL_RESERVE_BIT13, reserve13_value);
         |         ^
   drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:25:40: note: expanded from macro 'mtk_phy_update_regmap_field'
      25 |         regmap_update_bits(regmap, reg, mask, FIELD_PREP(mask, val)); \

vim +/FIELD_PREP +113 drivers/phy/mediatek/phy-mtk-hdmi-mt2701.c

    96	
    97	static int mtk_hdmi_pll_set_rate(struct clk_hw *hw, unsigned long rate,
    98					 unsigned long parent_rate)
    99	{
   100		struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
   101		u32 pos_div;
   102	
   103		if (rate <= 64000000)
   104			pos_div = 3;
   105		else if (rate <= 128000000)
   106			pos_div = 2;
   107		else
   108			pos_div = 1;
   109	
   110		regmap_set_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_PREDIV_MASK);
   111		regmap_set_bits(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_POSDIV_MASK);
   112		regmap_set_bits(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_EN_TX_POSDIV);
 > 113		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_IC_MASK, 0x1);
   114		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_IR_MASK, 0x1);
   115		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON2, RG_HDMITX_TX_POSDIV_MASK, pos_div);
   116		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_FBKSEL_MASK, 1);
   117		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_FBKDIV_MASK, 19);
   118		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON7, RG_HTPLL_DIVEN_MASK, 0x2);
   119		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_BP_MASK, 0xc);
   120		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_BC_MASK, 0x2);
   121		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON6, RG_HTPLL_BR_MASK, 0x1);
   122	
   123		regmap_clear_bits(hdmi_phy->regs, HDMI_CON1, RG_HDMITX_PRED_IMP);
   124		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON1, RG_HDMITX_PRED_IBIAS_MASK, 0x3);
   125		regmap_clear_bits(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_EN_IMP_MASK);
   126		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON1, RG_HDMITX_DRV_IMP_MASK, 0x28);
   127		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON4, RG_HDMITX_RESERVE_MASK, 0x28);
   128		mtk_phy_update_regmap_field(hdmi_phy->regs, HDMI_CON0, RG_HDMITX_DRV_IBIAS_MASK, 0xa);
   129		return 0;
   130	}
   131	
   132	static unsigned long mtk_hdmi_pll_recalc_rate(struct clk_hw *hw,
   133						      unsigned long parent_rate)
   134	{
   135		struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
   136		unsigned long out_rate, val;
   137		u32 tmp;
   138	
   139		regmap_read(hdmi_phy->regs, HDMI_CON6, &tmp);
 > 140		val = FIELD_GET(RG_HTPLL_PREDIV_MASK, tmp);

141 switch (val) {
142 case 0x00:
143 out_rate = parent_rate;
144 break;
145 case 0x01:
146 out_rate = parent_rate / 2;
147 break;
148 default:
149 out_rate = parent_rate / 4;
150 break;
151 }
152
153 val = FIELD_GET(RG_HTPLL_FBKDIV_MASK, tmp);
154 out_rate *= (val + 1) * 2;
155
156 regmap_read(hdmi_phy->regs, HDMI_CON2, &tmp);
157 val = FIELD_GET(RG_HDMITX_TX_POSDIV_MASK, tmp);
158 out_rate >>= val;
159
160 if (tmp & RG_HDMITX_EN_TX_POSDIV)
161 out_rate /= 5;
162
163 return out_rate;
164 }
165

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#5 lore raw
In reply to Luca Leonardo Scorcia
Quoted 11 lines · Luca Leonardo Scorcia

Use the regmap primitives to manipulate HDMI registers instead of custom helpers from phy-mtk-io.h. No functional changes.

This avoids the following issue with mt8167:

hdmi-phy: error -EBUSY: can't request region for resource [mem 0x10018300-0x1001831f]

due to the fact that HDMI PHY registers are actually mapped inside the apmixedsys memory space.

Quoted 6 lines

The same situation is present on mt8173 too but this SoC does not exhibit the issue as its apmixedsys driver uses of_iomap instead of devm_platform_ioremap_resource to map its memory space, just like regmap does.

Why RFC?

Anyhow, please fix the build errors reported.

- Mani