Skip to contentSkip to conversation

clk: imx: pll14xx: Extend dynamic rates support to PLL1416x

PATCH In review Marek Vasut 3 participants 5 messages Nov 11, 2024 – Nov 13, 2024

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

PATCH 1/1 clk: imx: pll14xx: Extend dynamic rates support to PLL1416x

The pll1416x PLL so far only supports rates from a rate table passed during initialization. Calculating PLL settings dynamically helps in case e.g. multiple video outputs are used and they each need their own separate source of accurate pixel clock on i.MX8MP. In that case, e.g. PLL1416x PLL3 can be used as another Video PLL for another output.

Extend the existing PLL1443x dynamic rate support to also apply to PLL1416x .

---
Cc: Abel Vesa <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Michael Turquette <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Stephen Boyd <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 drivers/clk/imx/clk-pll14xx.c | 39 ++++++++---------------------------
 1 file changed, 9 insertions(+), 30 deletions(-)
drivers/clk/imx/clk-pll14xx.c +9 -30
index d63564dbb12ca..19b9f764a0015 100644
@@ -214,23 +214,7 @@ static void imx_pll14xx_calc_settings(struct clk_pll14xx *pll, unsigned long rat
 		 t->mdiv, t->kdiv);
 }
 
-static long clk_pll1416x_round_rate(struct clk_hw *hw, unsigned long rate,
-			unsigned long *prate)
-{
-	struct clk_pll14xx *pll = to_clk_pll14xx(hw);
-	const struct imx_pll14xx_rate_table *rate_table = pll->rate_table;
-	int i;
-
-	/* Assuming rate_table is in descending order */
-	for (i = 0; i < pll->rate_count; i++)
-		if (rate >= rate_table[i].rate)
-			return rate_table[i].rate;
-
-	/* return minimum supported value */
-	return rate_table[pll->rate_count - 1].rate;
-}
-
-static long clk_pll1443x_round_rate(struct clk_hw *hw, unsigned long rate,
+static long clk_pll14xx_round_rate(struct clk_hw *hw, unsigned long rate,
 			unsigned long *prate)
 {
 	struct clk_pll14xx *pll = to_clk_pll14xx(hw);
@@ -285,22 +269,17 @@ static int clk_pll1416x_set_rate(struct clk_hw *hw, unsigned long drate,
 				 unsigned long prate)
 {
 	struct clk_pll14xx *pll = to_clk_pll14xx(hw);
-	const struct imx_pll14xx_rate_table *rate;
+	struct imx_pll14xx_rate_table rate;
 	u32 tmp, div_val;
 	int ret;
 
-	rate = imx_get_pll_settings(pll, drate);
-	if (!rate) {
-		pr_err("Invalid rate %lu for pll clk %s\n", drate,
-		       clk_hw_get_name(hw));
-		return -EINVAL;
-	}
+	imx_pll14xx_calc_settings(pll, drate, prate, &rate);
 
 	tmp = readl_relaxed(pll->base + DIV_CTL0);
 
-	if (!clk_pll14xx_mp_change(rate, tmp)) {
+	if (!clk_pll14xx_mp_change(&rate, tmp)) {
 		tmp &= ~SDIV_MASK;
-		tmp |= FIELD_PREP(SDIV_MASK, rate->sdiv);
+		tmp |= FIELD_PREP(SDIV_MASK, rate.sdiv);
 		writel_relaxed(tmp, pll->base + DIV_CTL0);
 
 		return 0;
@@ -319,8 +298,8 @@ static int clk_pll1416x_set_rate(struct clk_hw *hw, unsigned long drate,
 	tmp |= BYPASS_MASK;
 	writel(tmp, pll->base + GNRL_CTL);
 
-	div_val = FIELD_PREP(MDIV_MASK, rate->mdiv) | FIELD_PREP(PDIV_MASK, rate->pdiv) |
-		FIELD_PREP(SDIV_MASK, rate->sdiv);
+	div_val = FIELD_PREP(MDIV_MASK, rate.mdiv) | FIELD_PREP(PDIV_MASK, rate.pdiv) |
+		FIELD_PREP(SDIV_MASK, rate.sdiv);
 	writel_relaxed(div_val, pll->base + DIV_CTL0);
 
 	/*
@@ -468,7 +447,7 @@ static const struct clk_ops clk_pll1416x_ops = {
 	.unprepare	= clk_pll14xx_unprepare,
 	.is_prepared	= clk_pll14xx_is_prepared,
 	.recalc_rate	= clk_pll14xx_recalc_rate,
-	.round_rate	= clk_pll1416x_round_rate,
+	.round_rate	= clk_pll14xx_round_rate,
 	.set_rate	= clk_pll1416x_set_rate,
 };
 
@@ -481,7 +460,7 @@ static const struct clk_ops clk_pll1443x_ops = {
 	.unprepare	= clk_pll14xx_unprepare,
 	.is_prepared	= clk_pll14xx_is_prepared,
 	.recalc_rate	= clk_pll14xx_recalc_rate,
-	.round_rate	= clk_pll1443x_round_rate,
+	.round_rate	= clk_pll14xx_round_rate,
 	.set_rate	= clk_pll1443x_set_rate,
 };
 
Signature · 1 line
2.45.2
#1 lore raw
Quoted 5 lines · Marek Vasut

The pll1416x PLL so far only supports rates from a rate table passed during initialization. Calculating PLL settings dynamically helps in case e.g. multiple video outputs are used and they each need their own separate source of accurate pixel clock on i.MX8MP. In that case, e.g. PLL1416x PLL3 can be used as another Video PLL for another output.

Just want to point out that i.MX8MP audio AXI clock is supposed to be derived from PLL3 to run at 600MHz in nominal mode(i.MX8MP data sheet specifies that rate). So, if a particular i.MX8MP system doesn't use audio, PLL3 can be a free clock source to be used by an i.MX8MP display pipeline, otherwise, video_pll1_out is supposed to be shared by i.MX8MP MIPI DSI and LVDS display pipelines.

Currently, IMX8MP_CLK_AUDIO_AXI_SRC's parent is assigned to IMX8MP_SYS_PLL1_800M in imx8mp.dtsi. Although it's rate is assigned to 600MHz, the actual rate is 400MHz according to clk_summary because the divider cannot find a ratio to reach 600MHz from the clock source running at 800MHz. Looking at imx8mp_audio_axi_sels[], sys_pll3_out is the only free/appropriate clock source that can derive 600MHz audio AXI clock from. Maybe, someone will change IMX8MP_CLK_AUDIO_AXI_SRC's parent to IMX8MP_SYS_PLL3_OUT ?

pgc_audio: power-domain@5 {                                                      
        #power-domain-cells = <0>;                                               
        reg = <IMX8MP_POWER_DOMAIN_AUDIOMIX>;                                    
        clocks = <&clk IMX8MP_CLK_AUDIO_ROOT>,                                   
                 <&clk IMX8MP_CLK_AUDIO_AXI>;                                    
        assigned-clocks = <&clk IMX8MP_CLK_AUDIO_AHB>,                           
                          <&clk IMX8MP_CLK_AUDIO_AXI_SRC>;                       
        assigned-clock-parents = <&clk IMX8MP_SYS_PLL1_800M>,                    
                                 <&clk IMX8MP_SYS_PLL1_800M>;                    
        assigned-clock-rates = <400000000>,                                      
                               <600000000>;                                      
};

sys_pll1_ref_sel 1 1 0 24000000 0 0 50000 Y deviceless no_connection_id
sys_pll1 1 1 0 800000000 0 0 50000 Y deviceless no_connection_id
sys_pll1_bypass 1 1 0 800000000 0 0 50000 Y deviceless no_connection_id
sys_pll1_out 4 4 0 800000000 0 0 50000 Y deviceless no_connection_id
sys_pll1_800m 6 6 0 800000000 0 0 50000 Y deviceless no_connection_id

...

audio_axi 1 1 0 400000000 0 0 50000 Y power-domain@5 no_connection_id
deviceless no_connection_id
audio_axi_root 0 0 0 400000000 0 0 50000 Y deviceless no_connection_id

Signature · 2 lines
Regards,
Liu Ying
#2 lore raw
Quoted 7 lines · Liu Ying
Quoted 5 lines · Marek Vasut

The pll1416x PLL so far only supports rates from a rate table passed during initialization. Calculating PLL settings dynamically helps in case e.g. multiple video outputs are used and they each need their own separate source of accurate pixel clock on i.MX8MP. In that case, e.g. PLL1416x PLL3 can be used as another Video PLL for another output.

Quoted 6 lines

Just want to point out that i.MX8MP audio AXI clock is supposed to be derived from PLL3 to run at 600MHz in nominal mode(i.MX8MP data sheet specifies that rate). So, if a particular i.MX8MP system doesn't use audio, PLL3 can be a free clock source to be used by an i.MX8MP display pipeline, otherwise, video_pll1_out is supposed to be shared by i.MX8MP MIPI DSI and LVDS display pipelines.

In the end, I started using Audio PLL and Video PLL PLL1443x for accurate pixel clock generation and PLL3 to feed CLKOUTn where the less accurate PLL3 PLL1416x is just fine.

With the disparate display requirements, sharing one Video PLL for multiple outputs like DSI and LVDS is unrealistic. (maybe the next SoC should have some nice PLL per display output)

Quoted 8 lines

Currently, IMX8MP_CLK_AUDIO_AXI_SRC's parent is assigned to IMX8MP_SYS_PLL1_800M in imx8mp.dtsi. Although it's rate is assigned to 600MHz, the actual rate is 400MHz according to clk_summary because the divider cannot find a ratio to reach 600MHz from the clock source running at 800MHz. Looking at imx8mp_audio_axi_sels[], sys_pll3_out is the only free/appropriate clock source that can derive 600MHz audio AXI clock from. Maybe, someone will change IMX8MP_CLK_AUDIO_AXI_SRC's parent to IMX8MP_SYS_PLL3_OUT ?

Is the 400 MHz sufficient for audio-axi or does it have some negative performance impact ? If the later, better send a patch to use PLL3 for audio-axi .

Thanks !

#3 lore raw
Quoted 8 lines · Marek Vasut
Quoted 7 lines · Liu Ying
Quoted 5 lines · Marek Vasut

The pll1416x PLL so far only supports rates from a rate table passed during initialization. Calculating PLL settings dynamically helps in case e.g. multiple video outputs are used and they each need their own separate source of accurate pixel clock on i.MX8MP. In that case, e.g. PLL1416x PLL3 can be used as another Video PLL for another output.

Quoted 8 lines
Quoted 6 lines

Just want to point out that i.MX8MP audio AXI clock is supposed to be derived from PLL3 to run at 600MHz in nominal mode(i.MX8MP data sheet specifies that rate).  So, if a particular i.MX8MP system doesn't use audio, PLL3 can be a free clock source to be used by an i.MX8MP display pipeline, otherwise, video_pll1_out is supposed to be shared by i.MX8MP MIPI DSI and LVDS display pipelines.

In the end, I started using Audio PLL and Video PLL PLL1443x for accurate pixel clock generation and PLL3 to feed CLKOUTn where the less accurate PLL3 PLL1416x is just fine.

If audio PLLs or PLL3 are free, I think you may use them for video output.

Quoted 2 lines

With the disparate display requirements, sharing one Video PLL for multiple outputs like DSI and LVDS is unrealistic. (maybe the next SoC should have some nice PLL per display output)

I think there are 2 cases where we may or have to share one video PLL for DSI and LVDS.
1)It happens that the clock rate requirements of the 2 display pipelines
can be met by one video PLL, e.g., an i.MX8MP platform uses both DSI to HDMI and LVDS to HDMI bridges - it's probably good enough to have users use typical display mode combinations, like 1920x1080p@60 (DSI) + 1280x720p@60(LVDS).

In this case, we share one video PLL deliberately.

2) If audio PLLs and PLL3 are used already(very likely by audio subsystem), then the 2 display pipelines have to share one video PLL. It's possible that the video PLL cannot meet the clock rate requirements for one or both of them unfortunately, but maybe that's something we have to accept.

Quoted 10 lines
Quoted 9 lines

Currently, IMX8MP_CLK_AUDIO_AXI_SRC's parent is assigned to IMX8MP_SYS_PLL1_800M in imx8mp.dtsi.  Although it's rate is assigned to 600MHz, the actual rate is 400MHz according to clk_summary because the divider cannot find a ratio to reach 600MHz from the clock source running at 800MHz.  Looking at imx8mp_audio_axi_sels[], sys_pll3_out is the only free/appropriate clock source that can derive 600MHz audio AXI clock from.  Maybe, someone will change IMX8MP_CLK_AUDIO_AXI_SRC's parent to IMX8MP_SYS_PLL3_OUT ?

Is the 400 MHz sufficient for audio-axi or does it have some negative performance impact ? If the later, better send a patch to use PLL3 for audio-axi .

I'm adding Shengjiu to comment the audio part.

Quoted 2 lines

Thanks !

Signature · 2 lines
Regards,
Liu Ying
#4 lore raw

Hi

Quoted 54 lines · Marek Vasut
Quoted 8 lines · Liu Ying
Quoted 7 lines · Marek Vasut
Quoted 5 lines

The pll1416x PLL so far only supports rates from a rate table passed during initialization. Calculating PLL settings dynamically helps in case e.g. multiple video outputs are used and they each need their own separate source of accurate pixel clock on i.MX8MP. In that case, e.g. PLL1416x PLL3 can be used as another Video PLL for another output.

Quoted 8 lines
Quoted 6 lines

Just want to point out that i.MX8MP audio AXI clock is supposed to be derived from PLL3 to run at 600MHz in nominal mode(i.MX8MP data sheet specifies that rate).  So, if a particular i.MX8MP system doesn't use audio, PLL3 can be a free clock source to be used by an i.MX8MP display pipeline, otherwise, video_pll1_out is supposed to be shared by i.MX8MP MIPI DSI and LVDS display pipelines.

In the end, I started using Audio PLL and Video PLL PLL1443x for accurate

pixel clock generation and PLL3 to feed CLKOUTn where the less accurate PLL3 PLL1416x is just fine.

If audio PLLs or PLL3 are free, I think you may use them for video output.

Quoted 4 lines

With the disparate display requirements, sharing one Video PLL for multiple outputs like DSI and LVDS is unrealistic. (maybe the next SoC should have some nice PLL per display output)

I think there are 2 cases where we may or have to share one video PLL for DSI and LVDS.
1)It happens that the clock rate requirements of the 2 display pipelines
can be met by one video PLL, e.g., an i.MX8MP platform uses both DSI to HDMI and LVDS to HDMI bridges - it's probably good enough to have users use typical display mode combinations, like 1920x1080p@60 (DSI) + 1280x720p@60(LVDS).

In this case, we share one video PLL deliberately.

2) If audio PLLs and PLL3 are used already(very likely by audio subsystem), then the 2 display pipelines have to share one video PLL. It's possible that the video PLL cannot meet the clock rate requirements for one or both of them unfortunately, but maybe that's something we have to accept.

Quoted 9 lines
Quoted 9 lines

Currently, IMX8MP_CLK_AUDIO_AXI_SRC's parent is assigned to IMX8MP_SYS_PLL1_800M in imx8mp.dtsi.  Although it's rate is assigned to 600MHz, the actual rate is 400MHz according to clk_summary because the divider cannot find a ratio to reach 600MHz from the clock source running at 800MHz.  Looking at imx8mp_audio_axi_sels[], sys_pll3_out is the only free/appropriate clock source that can derive 600MHz audio AXI clock from.  Maybe, someone will change IMX8MP_CLK_AUDIO_AXI_SRC's parent to IMX8MP_SYS_PLL3_OUT ?

Quoted 5 lines
Quoted 1 line

Is the 400 MHz sufficient for audio-axi or does it have some negative

performance impact ? If the later, better send a patch to use PLL3 for audio- axi .

I'm adding Shengjiu to comment the audio part.

With 400MHz, there is negative performance impact, as the audio AXI Clock is DSP's core clock.

We have the requirement for normal drive mode, so 600MHz is required For audio AXI clock.

Thanks.

Best regards
Shengjiu Wang

Quoted 7 lines
Quoted 3 lines

Thanks !

--
Regards,
Liu Ying