Skip to content

Commit 5a97bc9

Browse files
krzkAbhinav Kumar
authored andcommitted
drm/msm/dsi/phy: Protect PHY_CMN_CLK_CFG1 against clock driver
PHY_CMN_CLK_CFG1 register is updated by the PHY driver and by a mux clock from Common Clock Framework: devm_clk_hw_register_mux_parent_hws(). There could be a path leading to concurrent and conflicting updates between PHY driver and clock framework, e.g. changing the mux and enabling PLL clocks. Add dedicated spinlock to be sure all PHY_CMN_CLK_CFG1 updates are synchronized. While shuffling the code, define and use PHY_CMN_CLK_CFG1 bitfields to make the code more readable and obvious. Fixes: 1ef7c99 ("drm/msm/dsi: add support for 7nm DSI PHY/PLL") Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> Reviewed-by: Abhinav Kumar <quic_abhinavk@quicinc.com> Patchwork: https://patchwork.freedesktop.org/patch/637378/ Link: https://lore.kernel.org/r/20250214-drm-msm-phy-pll-cfg-reg-v3-2-0943b850722c@linaro.org Signed-off-by: Abhinav Kumar <quic_abhinavk@quicinc.com>
1 parent 5882578 commit 5a97bc9

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ struct dsi_pll_7nm {
8383
/* protects REG_DSI_7nm_PHY_CMN_CLK_CFG0 register */
8484
spinlock_t postdiv_lock;
8585

86+
/* protects REG_DSI_7nm_PHY_CMN_CLK_CFG1 register */
87+
spinlock_t pclk_mux_lock;
88+
8689
struct pll_7nm_cached_state cached_state;
8790

8891
struct dsi_pll_7nm *slave;
@@ -381,22 +384,32 @@ static void dsi_pll_cmn_clk_cfg0_write(struct dsi_pll_7nm *pll, u32 val)
381384
spin_unlock_irqrestore(&pll->postdiv_lock, flags);
382385
}
383386

384-
static void dsi_pll_disable_global_clk(struct dsi_pll_7nm *pll)
387+
static void dsi_pll_cmn_clk_cfg1_update(struct dsi_pll_7nm *pll, u32 mask,
388+
u32 val)
385389
{
390+
unsigned long flags;
386391
u32 data;
387392

393+
spin_lock_irqsave(&pll->pclk_mux_lock, flags);
388394
data = readl(pll->phy->base + REG_DSI_7nm_PHY_CMN_CLK_CFG1);
389-
writel(data & ~BIT(5), pll->phy->base + REG_DSI_7nm_PHY_CMN_CLK_CFG1);
395+
data &= ~mask;
396+
data |= val & mask;
397+
398+
writel(data, pll->phy->base + REG_DSI_7nm_PHY_CMN_CLK_CFG1);
399+
spin_unlock_irqrestore(&pll->pclk_mux_lock, flags);
400+
}
401+
402+
static void dsi_pll_disable_global_clk(struct dsi_pll_7nm *pll)
403+
{
404+
dsi_pll_cmn_clk_cfg1_update(pll, DSI_7nm_PHY_CMN_CLK_CFG1_CLK_EN, 0);
390405
}
391406

392407
static void dsi_pll_enable_global_clk(struct dsi_pll_7nm *pll)
393408
{
394-
u32 data;
409+
u32 cfg_1 = DSI_7nm_PHY_CMN_CLK_CFG1_CLK_EN | DSI_7nm_PHY_CMN_CLK_CFG1_CLK_EN_SEL;
395410

396411
writel(0x04, pll->phy->base + REG_DSI_7nm_PHY_CMN_CTRL_3);
397-
398-
data = readl(pll->phy->base + REG_DSI_7nm_PHY_CMN_CLK_CFG1);
399-
writel(data | BIT(5) | BIT(4), pll->phy->base + REG_DSI_7nm_PHY_CMN_CLK_CFG1);
412+
dsi_pll_cmn_clk_cfg1_update(pll, cfg_1, cfg_1);
400413
}
401414

402415
static void dsi_pll_phy_dig_reset(struct dsi_pll_7nm *pll)
@@ -574,7 +587,6 @@ static int dsi_7nm_pll_restore_state(struct msm_dsi_phy *phy)
574587
{
575588
struct dsi_pll_7nm *pll_7nm = to_pll_7nm(phy->vco_hw);
576589
struct pll_7nm_cached_state *cached = &pll_7nm->cached_state;
577-
void __iomem *phy_base = pll_7nm->phy->base;
578590
u32 val;
579591
int ret;
580592

@@ -586,11 +598,7 @@ static int dsi_7nm_pll_restore_state(struct msm_dsi_phy *phy)
586598
dsi_pll_cmn_clk_cfg0_write(pll_7nm,
587599
DSI_7nm_PHY_CMN_CLK_CFG0_DIV_CTRL_3_0(cached->bit_clk_div) |
588600
DSI_7nm_PHY_CMN_CLK_CFG0_DIV_CTRL_7_4(cached->pix_clk_div));
589-
590-
val = readl(phy_base + REG_DSI_7nm_PHY_CMN_CLK_CFG1);
591-
val &= ~0x3;
592-
val |= cached->pll_mux;
593-
writel(val, phy_base + REG_DSI_7nm_PHY_CMN_CLK_CFG1);
601+
dsi_pll_cmn_clk_cfg1_update(pll_7nm, 0x3, cached->pll_mux);
594602

595603
ret = dsi_pll_7nm_vco_set_rate(phy->vco_hw,
596604
pll_7nm->vco_current_rate,
@@ -743,7 +751,7 @@ static int pll_7nm_register(struct dsi_pll_7nm *pll_7nm, struct clk_hw **provide
743751
pll_by_2_bit,
744752
}), 2, 0, pll_7nm->phy->base +
745753
REG_DSI_7nm_PHY_CMN_CLK_CFG1,
746-
0, 1, 0, NULL);
754+
0, 1, 0, &pll_7nm->pclk_mux_lock);
747755
if (IS_ERR(hw)) {
748756
ret = PTR_ERR(hw);
749757
goto fail;
@@ -788,6 +796,7 @@ static int dsi_pll_7nm_init(struct msm_dsi_phy *phy)
788796
pll_7nm_list[phy->id] = pll_7nm;
789797

790798
spin_lock_init(&pll_7nm->postdiv_lock);
799+
spin_lock_init(&pll_7nm->pclk_mux_lock);
791800

792801
pll_7nm->phy = phy;
793802

drivers/gpu/drm/msm/registers/display/dsi_phy_7nm.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ xsi:schemaLocation="https://gitlab.freedesktop.org/freedreno/ rules-fd.xsd">
1313
<bitfield name="DIV_CTRL_3_0" low="0" high="3" type="uint"/>
1414
<bitfield name="DIV_CTRL_7_4" low="4" high="7" type="uint"/>
1515
</reg32>
16-
<reg32 offset="0x00014" name="CLK_CFG1"/>
16+
<reg32 offset="0x00014" name="CLK_CFG1">
17+
<bitfield name="CLK_EN" pos="5" type="boolean"/>
18+
<bitfield name="CLK_EN_SEL" pos="4" type="boolean"/>
19+
</reg32>
1720
<reg32 offset="0x00018" name="GLBL_CTRL"/>
1821
<reg32 offset="0x0001c" name="RBUF_CTRL"/>
1922
<reg32 offset="0x00020" name="VREG_CTRL_0"/>

0 commit comments

Comments
 (0)