Skip to contentSkip to conversation

clk: amlogic: optimize the PLL driver

PATCH Superseded Chuan Liu 2 participants 15 messages Oct 30, 2025

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Chuan Liu

author
#0 lore raw

v2 cover clk: amlogic: optimize the PLL driver

This patch series consists of four topics involving the amlogic PLL driver:
- Fix out-of-range PLL frequency setting
- Improve the issue of PLL lock failures
- Add handling for PLL lock failure
- Optimize PLL enable timing
- Change the active level of l_detect

For easier review and management, these are submitted as a single patch series.

The PLL timing optimization changes were merged into our internal repository quite some time ago and have been verified on a large number of SoCs :
- Already supported upstream: G12A, G12B, SM1, S4, A1, C3
- Planned for upstream support: T7, A5, A4, S7, S7D, S6, etc.

Based on the upstream code base, I have performed functional testing on G12A, A1, A5, A4, T7, S7, S7D, and S6, all of which passed.

Additionally, stress testing using scripts was conducted on A5 and A1, with over 40,000 and 50,000 iterations respectively, and no abnormalities were observed. Below is a portion of the stress test log (CLOCK_ALLOW_WRITE_DEBUGFS has been manually enabled):

- For A5:

  # echo 491520000 > /sys/kernel/debug/clk/hifi_pll/clk_rate
  # cnt=0
  # while true; do
Quoted 8 lines

echo "------------ cnt=$cnt -----------"
echo 1 > /sys/kernel/debug/clk/hifi_pll/clk_prepare_enable en=$(cat /sys/kernel/debug/clk/hifi_pll/clk_prepare_enable 2>/dev/null) if [ "$en" != "1" ]; then
echo "[ERROR] PLL enable test failed! (clk_prepare_enable=$en)" break
fi

Quoted 5 lines

echo 0 > /sys/kernel/debug/clk/hifi_pll/clk_prepare_enable cnt=$((cnt + 1))
echo -e "sleep time: 1 s."
sleep 1
done &

# ------------ cnt=0 -----------
sleep time: 1 s.
------------ cnt=1 -----------
sleep time: 1 s.
------------ cnt=2 -----------
sleep time: 1 s.
...
------------ cnt=42076 -----------
sleep time: 1 s.

- For A1:

  # echo 983040000 > /sys/kernel/debug/clk/hifi_pll/clk_rate
  # cnt=0
  # while true; do
Quoted 8 lines

echo "------------ cnt=$cnt -----------"
echo 1 > /sys/kernel/debug/clk/hifi_pll/clk_prepare_enable en=$(cat /sys/kernel/debug/clk/hifi_pll/clk_prepare_enable 2>/dev/null) if [ "$en" != "1" ]; then
echo "[ERROR] PLL enable test failed! (clk_prepare_enable=$en)" break
fi

Quoted 5 lines

echo 0 > /sys/kernel/debug/clk/hifi_pll/clk_prepare_enable cnt=$((cnt + 1))
echo -e "sleep time: 1 s."
sleep 1
done &

# ------------ cnt=0 -----------
sleep time: 1 s.
------------ cnt=1 -----------
sleep time: 1 s.
------------ cnt=2 -----------
sleep time: 1 s.
...
------------ cnt=55051 -----------
sleep time: 1 s.

---
Changes in v2:
- Modify the judgment condition of 'm' out of range.
- Split the PLL timing optimization patch to make it easier to review.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Chuan Liu (5):
clk: amlogic: Fix out-of-range PLL frequency setting
clk: amlogic: Improve the issue of PLL lock failures
clk: amlogic: Add handling for PLL lock failure
clk: amlogic: Optimize PLL enable timing
clk: amlogic: Change the active level of l_detect

 drivers/clk/meson/a1-pll.c  |  1 +
 drivers/clk/meson/clk-pll.c | 76 ++++++++++++++++++++++++++++-----------------
 drivers/clk/meson/clk-pll.h |  2 ++
 3 files changed, 51 insertions(+), 28 deletions(-)

---
base-commit: 01f3a6d1d59b8e25a6de243b0d73075cf0415eaf
change-id: 20251020-optimize_pll_driver-7bef91876c41

Best regards,

Signature · 1 line
Chuan Liu <[email protected]>
author
#1 lore raw

PATCH v2 1/5 clk: amlogic: Fix out-of-range PLL frequency setting

If the calculated 'm' falls into the range:

    pll->range->max < m < (1 << pll->m.width)

Here an incorrect 'm' value could be obtained, so an additional condition is added to ensure that the calculated 'm' stays within a valid range.

Fixes 8eed1db1adec6 ("clk: meson: pll: update driver for the g12a")
---
 drivers/clk/meson/clk-pll.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/meson/clk-pll.c +1 -1
index 1ea6579a760f..629f6af18ea1 100644
@@ -191,7 +191,7 @@ static int meson_clk_get_pll_range_index(unsigned long rate,
 	*m = meson_clk_get_pll_range_m(rate, parent_rate, *n, pll);
 
 	/* the pre-divider gives a multiplier too big - stop */
-	if (*m >= (1 << pll->m.width))
+	if (*m > pll->range->max || *m >= (1 << pll->m.width))
 		return -EINVAL;
 
 	return 0;
Signature · 1 line
2.42.0
author
#2 lore raw

PATCH v2 2/5 clk: amlogic: Improve the issue of PLL lock failures

In reply to Chuan Liu

Due to factors such as temperature and process variations, the internal circuits of the PLL may require a longer time to reach a steady state, which can result in occasional lock failures on some SoCs under low-temperature conditions.

After enabling the PLL and releasing its reset, a 20 us delay is added at each step to provide enough time for the internal PLL circuit to stabilize, thus reducing the probability of PLL lock failure.

---
 drivers/clk/meson/clk-pll.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/clk/meson/clk-pll.c +5 -0
index 629f6af18ea1..f81ebf6cc981 100644
@@ -368,11 +368,16 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
 
 	/* Enable the pll */
 	meson_parm_write(clk->map, &pll->en, 1);
+	/* Wait for Bandgap and LDO to power up and stabilize */
+	udelay(20);
 
 	/* Take the pll out reset */
 	if (MESON_PARM_APPLICABLE(&pll->rst))
 		meson_parm_write(clk->map, &pll->rst, 0);
 
+	/* Wait for PLL loop stabilization */
+	udelay(20);
+
 	/*
 	 * Compared with the previous SoCs, self-adaption current module
 	 * is newly added for A1, keep the new power-on sequence to enable the
Signature · 1 line
2.42.0
maintainer
#3 lore raw

Re: [PATCH v2 2/5] clk: amlogic: Improve the issue of PLL lock failures

Quoted 22 lines · On Thu 30 Oct 2025 at 13:24, Chuan Liu via B4 Relay…

From: Chuan Liu <[email protected]>

Due to factors such as temperature and process variations, the internal circuits of the PLL may require a longer time to reach a steady state, which can result in occasional lock failures on some SoCs under low-temperature conditions.

After enabling the PLL and releasing its reset, a 20 us delay is added at each step to provide enough time for the internal PLL circuit to stabilize, thus reducing the probability of PLL lock failure.

---
 drivers/clk/meson/clk-pll.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/clk/meson/clk-pll.c +0 -0
index 629f6af18ea1..f81ebf6cc981 100644

drivers/clk/meson/clk-pll.c static int meson_clk_pll_enable(struct clk_hw *hw) · line 370

Quoted 3 lines
drivers/clk/meson/clk-pll.c +0 -0
@@ -368,11 +368,16 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
 
 	/* Enable the pll */
 	meson_parm_write(clk->map, &pll->en, 1);

New line

Quoted 13 lines
drivers/clk/meson/clk-pll.c +5 -0
+	/* Wait for Bandgap and LDO to power up and stabilize */
+	udelay(20);
 
 	/* Take the pll out reset */
 	if (MESON_PARM_APPLICABLE(&pll->rst))
 		meson_parm_write(clk->map, &pll->rst, 0);
 
+	/* Wait for PLL loop stabilization */
+	udelay(20);
+
 	/*
 	 * Compared with the previous SoCs, self-adaption current module
 	 * is newly added for A1, keep the new power-on sequence to enable the
Signature · 1 line
Jerome
author
#4 lore raw

Re: [PATCH v2 2/5] clk: amlogic: Improve the issue of PLL lock failures

Hi Jerome,

Quoted 27 lines · Jerome Brunet

[ EXTERNAL EMAIL ]

Quoted 23 lines · On Thu 30 Oct 2025 at 13:24, Chuan Liu via B4 Relay…

From: Chuan Liu <[email protected]>

Due to factors such as temperature and process variations, the internal circuits of the PLL may require a longer time to reach a steady state, which can result in occasional lock failures on some SoCs under low-temperature conditions.

After enabling the PLL and releasing its reset, a 20 us delay is added at each step to provide enough time for the internal PLL circuit to stabilize, thus reducing the probability of PLL lock failure.

---
  drivers/clk/meson/clk-pll.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/clk/meson/clk-pll.c +0 -0
index 629f6af18ea1..f81ebf6cc981 100644
@@ -368,11 +368,16 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
 
Quoted 4 lines

drivers/clk/meson/clk-pll.c static int meson_clk_pll_enable(struct clk_hw *hw) · line 370

Quoted 2 lines
drivers/clk/meson/clk-pll.c +0 -0
       /* Enable the pll */
       meson_parm_write(clk->map, &pll->en, 1);

New line

Ok, fix it in the next version.

Quoted 17 lines
Quoted 4 lines
drivers/clk/meson/clk-pll.c +2 -0
+     /* Wait for Bandgap and LDO to power up and stabilize */
+     udelay(20);
 

drivers/clk/meson/clk-pll.c static int meson_clk_pll_enable(struct clk_hw *hw) · line 383

Quoted 10 lines
drivers/clk/meson/clk-pll.c +3 -0
       /* Take the pll out reset */
       if (MESON_PARM_APPLICABLE(&pll->rst))
               meson_parm_write(clk->map, &pll->rst, 0);
 
+     /* Wait for PLL loop stabilization */
+     udelay(20);
+
       /*
        * Compared with the previous SoCs, self-adaption current module
        * is newly added for A1, keep the new power-on sequence to enable the

--
Jerome

author
#5 lore raw

PATCH v2 3/5 clk: amlogic: Add handling for PLL lock failure

In reply to Chuan Liu

If the PLL fails to lock, it should be disabled, This makes the logic more complete, and also helps save unnecessary power consumption when the PLL is malfunctioning.

---
 drivers/clk/meson/clk-pll.c | 41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)
drivers/clk/meson/clk-pll.c +23 -18
index f81ebf6cc981..6c794adb8ccd 100644
@@ -353,6 +353,23 @@ static int meson_clk_pcie_pll_enable(struct clk_hw *hw)
 	return -EIO;
 }
 
+static void meson_clk_pll_disable(struct clk_hw *hw)
+{
+	struct clk_regmap *clk = to_clk_regmap(hw);
+	struct meson_clk_pll_data *pll = meson_clk_pll_data(clk);
+
+	/* Put the pll is in reset */
+	if (MESON_PARM_APPLICABLE(&pll->rst))
+		meson_parm_write(clk->map, &pll->rst, 1);
+
+	/* Disable the pll */
+	meson_parm_write(clk->map, &pll->en, 0);
+
+	/* Disable PLL internal self-adaption current module */
+	if (MESON_PARM_APPLICABLE(&pll->current_en))
+		meson_parm_write(clk->map, &pll->current_en, 0);
+}
+
 static int meson_clk_pll_enable(struct clk_hw *hw)
 {
 	struct clk_regmap *clk = to_clk_regmap(hw);
@@ -397,29 +414,17 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
 		meson_parm_write(clk->map, &pll->l_detect, 0);
 	}
 
-	if (meson_clk_pll_wait_lock(hw))
+	if (meson_clk_pll_wait_lock(hw)) {
+		/* disable PLL when PLL lock failed. */
+		meson_clk_pll_disable(hw);
+		pr_warn("%s: PLL lock failed!!!\n", clk_hw_get_name(hw));
+
 		return -EIO;
+	}
 
 	return 0;
 }
 
-static void meson_clk_pll_disable(struct clk_hw *hw)
-{
-	struct clk_regmap *clk = to_clk_regmap(hw);
-	struct meson_clk_pll_data *pll = meson_clk_pll_data(clk);
-
-	/* Put the pll is in reset */
-	if (MESON_PARM_APPLICABLE(&pll->rst))
-		meson_parm_write(clk->map, &pll->rst, 1);
-
-	/* Disable the pll */
-	meson_parm_write(clk->map, &pll->en, 0);
-
-	/* Disable PLL internal self-adaption current module */
-	if (MESON_PARM_APPLICABLE(&pll->current_en))
-		meson_parm_write(clk->map, &pll->current_en, 0);
-}
-
 static int meson_clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
 				  unsigned long parent_rate)
 {
Signature · 1 line
2.42.0
maintainer
#6 lore raw

Re: [PATCH v2 3/5] clk: amlogic: Add handling for PLL lock failure

Quoted 40 lines · On Thu 30 Oct 2025 at 13:24, Chuan Liu via B4 Relay…

From: Chuan Liu <[email protected]>

If the PLL fails to lock, it should be disabled, This makes the logic more complete, and also helps save unnecessary power consumption when the PLL is malfunctioning.

---
 drivers/clk/meson/clk-pll.c | 41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)
drivers/clk/meson/clk-pll.c +17 -0
index f81ebf6cc981..6c794adb8ccd 100644
@@ -353,6 +353,23 @@ static int meson_clk_pcie_pll_enable(struct clk_hw *hw)
 	return -EIO;
 }
 
+static void meson_clk_pll_disable(struct clk_hw *hw)
+{
+	struct clk_regmap *clk = to_clk_regmap(hw);
+	struct meson_clk_pll_data *pll = meson_clk_pll_data(clk);
+
+	/* Put the pll is in reset */
+	if (MESON_PARM_APPLICABLE(&pll->rst))
+		meson_parm_write(clk->map, &pll->rst, 1);
+
+	/* Disable the pll */
+	meson_parm_write(clk->map, &pll->en, 0);
+
+	/* Disable PLL internal self-adaption current module */
+	if (MESON_PARM_APPLICABLE(&pll->current_en))
+		meson_parm_write(clk->map, &pll->current_en, 0);
+}
+
 static int meson_clk_pll_enable(struct clk_hw *hw)
 {
 	struct clk_regmap *clk = to_clk_regmap(hw);

drivers/clk/meson/clk-pll.c static int meson_clk_pll_enable(struct clk_hw *hw) · line 421

Quoted 9 lines
drivers/clk/meson/clk-pll.c +5 -1
@@ -397,29 +414,17 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
 		meson_parm_write(clk->map, &pll->l_detect, 0);
 	}
 
-	if (meson_clk_pll_wait_lock(hw))
+	if (meson_clk_pll_wait_lock(hw)) {
+		/* disable PLL when PLL lock failed. */
+		meson_clk_pll_disable(hw);
+		pr_warn("%s: PLL lock failed!!!\n", clk_hw_get_name(hw));
+

This is something that's likely to spam, so pr_warn_once() (if you must warn) and I don't think 3 "!" are necessary to convey the message.

Quoted 26 lines
drivers/clk/meson/clk-pll.c +1 -17
 		return -EIO;
+	}
 
 	return 0;
 }
 
-static void meson_clk_pll_disable(struct clk_hw *hw)
-{
-	struct clk_regmap *clk = to_clk_regmap(hw);
-	struct meson_clk_pll_data *pll = meson_clk_pll_data(clk);
-
-	/* Put the pll is in reset */
-	if (MESON_PARM_APPLICABLE(&pll->rst))
-		meson_parm_write(clk->map, &pll->rst, 1);
-
-	/* Disable the pll */
-	meson_parm_write(clk->map, &pll->en, 0);
-
-	/* Disable PLL internal self-adaption current module */
-	if (MESON_PARM_APPLICABLE(&pll->current_en))
-		meson_parm_write(clk->map, &pll->current_en, 0);
-}
-
 static int meson_clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
 				  unsigned long parent_rate)
 {
Signature · 1 line
Jerome
author
#7 lore raw

Re: [PATCH v2 3/5] clk: amlogic: Add handling for PLL lock failure

Hi Jerome,

Quoted 47 lines · Jerome Brunet

[ EXTERNAL EMAIL ]

Quoted 43 lines · On Thu 30 Oct 2025 at 13:24, Chuan Liu via B4 Relay…

From: Chuan Liu <[email protected]>

If the PLL fails to lock, it should be disabled, This makes the logic more complete, and also helps save unnecessary power consumption when the PLL is malfunctioning.

---
  drivers/clk/meson/clk-pll.c | 41 +++++++++++++++++++++++------------------
  1 file changed, 23 insertions(+), 18 deletions(-)
drivers/clk/meson/clk-pll.c +17 -0
index f81ebf6cc981..6c794adb8ccd 100644
@@ -353,6 +353,23 @@ static int meson_clk_pcie_pll_enable(struct clk_hw *hw)
       return -EIO;
  }
 
+static void meson_clk_pll_disable(struct clk_hw *hw)
+{
+     struct clk_regmap *clk = to_clk_regmap(hw);
+     struct meson_clk_pll_data *pll = meson_clk_pll_data(clk);
+
+     /* Put the pll is in reset */
+     if (MESON_PARM_APPLICABLE(&pll->rst))
+             meson_parm_write(clk->map, &pll->rst, 1);
+
+     /* Disable the pll */
+     meson_parm_write(clk->map, &pll->en, 0);
+
+     /* Disable PLL internal self-adaption current module */
+     if (MESON_PARM_APPLICABLE(&pll->current_en))
+             meson_parm_write(clk->map, &pll->current_en, 0);
+}
+
  static int meson_clk_pll_enable(struct clk_hw *hw)
  {
       struct clk_regmap *clk = to_clk_regmap(hw);
@@ -397,29 +414,17 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
               meson_parm_write(clk->map, &pll->l_detect, 0);
       }
 
Quoted 10 lines

drivers/clk/meson/clk-pll.c static int meson_clk_pll_enable(struct clk_hw *hw) · line 421

Quoted 6 lines
drivers/clk/meson/clk-pll.c +5 -1
-     if (meson_clk_pll_wait_lock(hw))
+     if (meson_clk_pll_wait_lock(hw)) {
+             /* disable PLL when PLL lock failed. */
+             meson_clk_pll_disable(hw);
+             pr_warn("%s: PLL lock failed!!!\n", clk_hw_get_name(hw));
+

This is something that's likely to spam, so pr_warn_once() (if you must warn) and I don't think 3 "!" are necessary to convey the message.

In the next version, I'll remove the "!", and replace pr_warn to pr_warn_once.

Some drivers that reference the clock may not check the function’s return value (even though that's not ideal), so adding this warning makes the issue more noticeable.

Quoted 29 lines
Quoted 16 lines
drivers/clk/meson/clk-pll.c +1 -10
               return -EIO;
+     }
 
       return 0;
  }
 
-static void meson_clk_pll_disable(struct clk_hw *hw)
-{
-     struct clk_regmap *clk = to_clk_regmap(hw);
-     struct meson_clk_pll_data *pll = meson_clk_pll_data(clk);
-
-     /* Put the pll is in reset */
-     if (MESON_PARM_APPLICABLE(&pll->rst))
-             meson_parm_write(clk->map, &pll->rst, 1);
-
-     /* Disable the pll */

drivers/clk/meson/clk-pll.c static int meson_clk_pll_enable(struct clk_hw *hw) · line 430

Quoted 10 lines
drivers/clk/meson/clk-pll.c +0 -7
-     meson_parm_write(clk->map, &pll->en, 0);
-
-     /* Disable PLL internal self-adaption current module */
-     if (MESON_PARM_APPLICABLE(&pll->current_en))
-             meson_parm_write(clk->map, &pll->current_en, 0);
-}
-
  static int meson_clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
                                 unsigned long parent_rate)
  {

--
Jerome

author
#8 lore raw

Re: [PATCH v2 3/5] clk: amlogic: Add handling for PLL lock failure

Hi Jerome,

Quoted 60 lines · Chuan Liu

Hi Jerome,

Quoted 57 lines · Jerome Brunet

[ EXTERNAL EMAIL ]

Quoted 42 lines · On Thu 30 Oct 2025 at 13:24, Chuan Liu via B4 Relay…

From: Chuan Liu <[email protected]>

If the PLL fails to lock, it should be disabled, This makes the logic more complete, and also helps save unnecessary power consumption when the PLL is malfunctioning.

---
  drivers/clk/meson/clk-pll.c | 41 ++++++++++++++++++++++
+------------------

  1 file changed, 23 insertions(+), 18 deletions(-)
drivers/clk/meson/clk-pll.c +17 -0
index f81ebf6cc981..6c794adb8ccd 100644
@@ -353,6 +353,23 @@ static int meson_clk_pcie_pll_enable(struct 
 clk_hw *hw)
        return -EIO;
   }
 
+static void meson_clk_pll_disable(struct clk_hw *hw)
+{
+     struct clk_regmap *clk = to_clk_regmap(hw);
+     struct meson_clk_pll_data *pll = meson_clk_pll_data(clk);
+
+     /* Put the pll is in reset */
+     if (MESON_PARM_APPLICABLE(&pll->rst))
+             meson_parm_write(clk->map, &pll->rst, 1);
+
+     /* Disable the pll */
+     meson_parm_write(clk->map, &pll->en, 0);
+
+     /* Disable PLL internal self-adaption current module */
+     if (MESON_PARM_APPLICABLE(&pll->current_en))
+             meson_parm_write(clk->map, &pll->current_en, 0);
+}
+
   static int meson_clk_pll_enable(struct clk_hw *hw)
   {

       struct clk_regmap *clk = to_clk_regmap(hw);

drivers/clk/meson/clk-pll.c static int meson_clk_pll_enable(struct clk_hw *hw) · line 421

Quoted 9 lines
drivers/clk/meson/clk-pll.c +5 -1
@@ -397,29 +414,17 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
                meson_parm_write(clk->map, &pll->l_detect, 0);
        }
 
-     if (meson_clk_pll_wait_lock(hw))
+     if (meson_clk_pll_wait_lock(hw)) {
+             /* disable PLL when PLL lock failed. */
+             meson_clk_pll_disable(hw);
+             pr_warn("%s: PLL lock failed!!!\n", clk_hw_get_name(hw));
+

This is something that's likely to spam, so pr_warn_once() (if you must warn)

Different PLLs or different timing conditions may trigger PLL lock failures repeatedly, so using pr_warn_once() might not achieve the intended effect.

Do you mind keeping pr_warn() here?

Quoted 40 lines
Quoted 2 lines

and I don't think 3 "!" are necessary to convey the message.

In the next version, I'll remove the "!", and replace pr_warn to pr_warn_once.

Some drivers that reference the clock may not check the function’s return value (even though that's not ideal), so adding this warning makes the issue more noticeable.

Quoted 29 lines
Quoted 26 lines
drivers/clk/meson/clk-pll.c +1 -17
                return -EIO;
+     }
 
        return 0;
   }
 
-static void meson_clk_pll_disable(struct clk_hw *hw)
-{
-     struct clk_regmap *clk = to_clk_regmap(hw);
-     struct meson_clk_pll_data *pll = meson_clk_pll_data(clk);
-
-     /* Put the pll is in reset */
-     if (MESON_PARM_APPLICABLE(&pll->rst))
-             meson_parm_write(clk->map, &pll->rst, 1);
-
-     /* Disable the pll */
-     meson_parm_write(clk->map, &pll->en, 0);
-
-     /* Disable PLL internal self-adaption current module */
-     if (MESON_PARM_APPLICABLE(&pll->current_en))
-             meson_parm_write(clk->map, &pll->current_en, 0);
-}
-
   static int meson_clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
                                  unsigned long parent_rate)
   {
Signature · 1 line
Jerome
author
#9 lore raw

PATCH v2 4/5 clk: amlogic: Optimize PLL enable timing

In reply to Chuan Liu

l_detect controls the enablement of the PLL lock detection module. It should remain disabled while the internal PLL circuits are reaching a steady state; otherwise, the lock signal may be falsely triggered high.

Before enabling the internal power supply of the PLL, l_detect should be disabled. After the PLL’s internal circuits have stabilized, l_detect should be enabled to prevent false lock signal triggers.

Currently, only A1 supports both l_detect and current_en, so this patch will only affect A1.

---
 drivers/clk/meson/clk-pll.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)
drivers/clk/meson/clk-pll.c +15 -13
index 6c794adb8ccd..c6eebde1f516 100644
@@ -383,36 +383,38 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
 	if (MESON_PARM_APPLICABLE(&pll->rst))
 		meson_parm_write(clk->map, &pll->rst, 1);
 
+	/* Disable the PLL lock-detect module */
+	if (MESON_PARM_APPLICABLE(&pll->l_detect))
+		meson_parm_write(clk->map, &pll->l_detect, 1);
+
 	/* Enable the pll */
 	meson_parm_write(clk->map, &pll->en, 1);
 	/* Wait for Bandgap and LDO to power up and stabilize */
 	udelay(20);
 
-	/* Take the pll out reset */
-	if (MESON_PARM_APPLICABLE(&pll->rst))
-		meson_parm_write(clk->map, &pll->rst, 0);
-
-	/* Wait for PLL loop stabilization */
-	udelay(20);
-
 	/*
 	 * Compared with the previous SoCs, self-adaption current module
 	 * is newly added for A1, keep the new power-on sequence to enable the
 	 * PLL. The sequence is:
-	 * 1. enable the pll, delay for 10us
+	 * 1. enable the pll, delay for 20us
 	 * 2. enable the pll self-adaption current module, delay for 40us
 	 * 3. enable the lock detect module
 	 */
 	if (MESON_PARM_APPLICABLE(&pll->current_en)) {
-		udelay(10);
 		meson_parm_write(clk->map, &pll->current_en, 1);
-		udelay(40);
+		udelay(20);
 	}
 
-	if (MESON_PARM_APPLICABLE(&pll->l_detect)) {
-		meson_parm_write(clk->map, &pll->l_detect, 1);
+	/* Take the pll out reset */
+	if (MESON_PARM_APPLICABLE(&pll->rst))
+		meson_parm_write(clk->map, &pll->rst, 0);
+
+	/* Wait for PLL loop stabilization */
+	udelay(20);
+
+	/* Enable the lock-detect module */
+	if (MESON_PARM_APPLICABLE(&pll->l_detect))
 		meson_parm_write(clk->map, &pll->l_detect, 0);
-	}
 
 	if (meson_clk_pll_wait_lock(hw)) {
 		/* disable PLL when PLL lock failed. */
Signature · 1 line
2.42.0
maintainer
#10 lore raw

Re: [PATCH v2 4/5] clk: amlogic: Optimize PLL enable timing

Quoted 10 lines · On Thu 30 Oct 2025 at 13:24, Chuan Liu via B4 Relay…

From: Chuan Liu <[email protected]>

l_detect controls the enablement of the PLL lock detection module. It should remain disabled while the internal PLL circuits are reaching a steady state; otherwise, the lock signal may be falsely triggered high.

Before enabling the internal power supply of the PLL, l_detect should be disabled. After the PLL’s internal circuits have stabilized, l_detect should be enabled to prevent false lock signal triggers.

You to reformat this description. It feel that both paragraph are saying the same thing.

Quoted 19 lines

Currently, only A1 supports both l_detect and current_en, so this patch will only affect A1.

---
 drivers/clk/meson/clk-pll.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)
drivers/clk/meson/clk-pll.c +2 -0
index 6c794adb8ccd..c6eebde1f516 100644
@@ -383,36 +383,38 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
 	if (MESON_PARM_APPLICABLE(&pll->rst))
 		meson_parm_write(clk->map, &pll->rst, 1);
 
+	/* Disable the PLL lock-detect module */
+	if (MESON_PARM_APPLICABLE(&pll->l_detect))

drivers/clk/meson/clk-pll.c static int meson_clk_pll_enable(struct clk_hw *hw) · line 393

Quoted 10 lines
drivers/clk/meson/clk-pll.c +2 -3
+		meson_parm_write(clk->map, &pll->l_detect, 1);
+
 	/* Enable the pll */
 	meson_parm_write(clk->map, &pll->en, 1);
 	/* Wait for Bandgap and LDO to power up and stabilize */
 	udelay(20);
 
-	/* Take the pll out reset */
-	if (MESON_PARM_APPLICABLE(&pll->rst))
-		meson_parm_write(clk->map, &pll->rst, 0);

Why is the reset moving around ? nothing is said in the description about that

Quoted 36 lines
drivers/clk/meson/clk-pll.c +11 -10
-
-	/* Wait for PLL loop stabilization */
-	udelay(20);
-
 	/*
 	 * Compared with the previous SoCs, self-adaption current module
 	 * is newly added for A1, keep the new power-on sequence to enable the
 	 * PLL. The sequence is:
-	 * 1. enable the pll, delay for 10us
+	 * 1. enable the pll, delay for 20us
 	 * 2. enable the pll self-adaption current module, delay for 40us
 	 * 3. enable the lock detect module
 	 */
 	if (MESON_PARM_APPLICABLE(&pll->current_en)) {
-		udelay(10);
 		meson_parm_write(clk->map, &pll->current_en, 1);
-		udelay(40);
+		udelay(20);
 	}
 
-	if (MESON_PARM_APPLICABLE(&pll->l_detect)) {
-		meson_parm_write(clk->map, &pll->l_detect, 1);
+	/* Take the pll out reset */
+	if (MESON_PARM_APPLICABLE(&pll->rst))
+		meson_parm_write(clk->map, &pll->rst, 0);
+
+	/* Wait for PLL loop stabilization */
+	udelay(20);
+
+	/* Enable the lock-detect module */
+	if (MESON_PARM_APPLICABLE(&pll->l_detect))
 		meson_parm_write(clk->map, &pll->l_detect, 0);
-	}
 
 	if (meson_clk_pll_wait_lock(hw)) {
 		/* disable PLL when PLL lock failed. */
Signature · 1 line
Jerome
author
#11 lore raw

Re: [PATCH v2 4/5] clk: amlogic: Optimize PLL enable timing

Hi Jerome,

Quoted 11 lines · Jerome Brunet

[ EXTERNAL EMAIL ]

Quoted 7 lines · On Thu 30 Oct 2025 at 13:24, Chuan Liu via B4 Relay…

From: Chuan Liu <[email protected]>

l_detect controls the enablement of the PLL lock detection module. It should remain disabled while the internal PLL circuits are reaching a steady state; otherwise, the lock signal may be falsely triggered high.

Quoted 7 lines
Quoted 3 lines

Before enabling the internal power supply of the PLL, l_detect should be disabled. After the PLL’s internal circuits have stabilized, l_detect should be enabled to prevent false lock signal triggers.

You to reformat this description. It feel that both paragraph are saying the same thing.

Ok, drop it.

Quoted 26 lines
Quoted 26 lines

Currently, only A1 supports both l_detect and current_en, so this patch will only affect A1.

---
  drivers/clk/meson/clk-pll.c | 28 +++++++++++++++-------------
  1 file changed, 15 insertions(+), 13 deletions(-)
drivers/clk/meson/clk-pll.c +4 -0
index 6c794adb8ccd..c6eebde1f516 100644
@@ -383,36 +383,38 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
       if (MESON_PARM_APPLICABLE(&pll->rst))
               meson_parm_write(clk->map, &pll->rst, 1);
 
+     /* Disable the PLL lock-detect module */
+     if (MESON_PARM_APPLICABLE(&pll->l_detect))
+             meson_parm_write(clk->map, &pll->l_detect, 1);
+
       /* Enable the pll */
       meson_parm_write(clk->map, &pll->en, 1);
       /* Wait for Bandgap and LDO to power up and stabilize */
       udelay(20);
 
Quoted 7 lines

drivers/clk/meson/clk-pll.c static int meson_clk_pll_enable(struct clk_hw *hw) · line 393

Quoted 3 lines
drivers/clk/meson/clk-pll.c +0 -3
-     /* Take the pll out reset */
-     if (MESON_PARM_APPLICABLE(&pll->rst))
-             meson_parm_write(clk->map, &pll->rst, 0);

Why is the reset moving around ? nothing is said in the description about that

The function of current_en in the PLL is similar to en. It's more reliable to assert the reset signal after current_en is set high.

I'll update the commit description accordingly in the next version.

Quoted 39 lines
Quoted 26 lines
drivers/clk/meson/clk-pll.c +6 -9
-
-     /* Wait for PLL loop stabilization */
-     udelay(20);
-
       /*
        * Compared with the previous SoCs, self-adaption current module
        * is newly added for A1, keep the new power-on sequence to enable the
        * PLL. The sequence is:
-      * 1. enable the pll, delay for 10us
+      * 1. enable the pll, delay for 20us
        * 2. enable the pll self-adaption current module, delay for 40us
        * 3. enable the lock detect module
        */
       if (MESON_PARM_APPLICABLE(&pll->current_en)) {
-             udelay(10);
               meson_parm_write(clk->map, &pll->current_en, 1);
-             udelay(40);
+             udelay(20);
       }
 
-     if (MESON_PARM_APPLICABLE(&pll->l_detect)) {
-             meson_parm_write(clk->map, &pll->l_detect, 1);
+     /* Take the pll out reset */
+     if (MESON_PARM_APPLICABLE(&pll->rst))
+             meson_parm_write(clk->map, &pll->rst, 0);
+

drivers/clk/meson/clk-pll.c static int meson_clk_pll_enable(struct clk_hw *hw) · line 420

Quoted 10 lines
drivers/clk/meson/clk-pll.c +5 -1
+     /* Wait for PLL loop stabilization */
+     udelay(20);
+
+     /* Enable the lock-detect module */
+     if (MESON_PARM_APPLICABLE(&pll->l_detect))
               meson_parm_write(clk->map, &pll->l_detect, 0);
-     }
 
       if (meson_clk_pll_wait_lock(hw)) {
               /* disable PLL when PLL lock failed. */

--
Jerome

author
#12 lore raw

PATCH v2 5/5 clk: amlogic: Change the active level of l_detect

In reply to Chuan Liu

l_detect controls the enable/disable of the PLL lock-detect module.

The enable signal is normally active-high. This design ensures that the module remains disabled during the power-on process, preventing power fluctuations from affecting its operating state.

For A1, the l_detect signal is active-low:
0 -> Enable lock-detect module;
1 -> Disable lock-detect module.

Here, a flag CLK_MESON_PLL_L_DETECT_N is added to handle cases like A1, where the signal is active-low.

---
 drivers/clk/meson/a1-pll.c  |  1 +
 drivers/clk/meson/clk-pll.c | 16 ++++++++++++----
 drivers/clk/meson/clk-pll.h |  2 ++
 3 files changed, 15 insertions(+), 4 deletions(-)
drivers/clk/meson/a1-pll.c +1 -0
index 1f82e9c7c14e..bfe559c71402 100644
@@ -137,6 +137,7 @@ static struct clk_regmap a1_hifi_pll = {
 		.range = &a1_hifi_pll_range,
 		.init_regs = a1_hifi_pll_init_regs,
 		.init_count = ARRAY_SIZE(a1_hifi_pll_init_regs),
+		.flags = CLK_MESON_PLL_L_DETECT_N
 	},
 	.hw.init = &(struct clk_init_data){
 		.name = "hifi_pll",
drivers/clk/meson/clk-pll.c +12 -4
index c6eebde1f516..d729e933aa1c 100644
@@ -384,8 +384,12 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
 		meson_parm_write(clk->map, &pll->rst, 1);
 
 	/* Disable the PLL lock-detect module */
-	if (MESON_PARM_APPLICABLE(&pll->l_detect))
-		meson_parm_write(clk->map, &pll->l_detect, 1);
+	if (MESON_PARM_APPLICABLE(&pll->l_detect)) {
+		if (pll->flags & CLK_MESON_PLL_L_DETECT_N)
+			meson_parm_write(clk->map, &pll->l_detect, 1);
+		else
+			meson_parm_write(clk->map, &pll->l_detect, 0);
+	}
 
 	/* Enable the pll */
 	meson_parm_write(clk->map, &pll->en, 1);
@@ -413,8 +417,12 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
 	udelay(20);
 
 	/* Enable the lock-detect module */
-	if (MESON_PARM_APPLICABLE(&pll->l_detect))
-		meson_parm_write(clk->map, &pll->l_detect, 0);
+	if (MESON_PARM_APPLICABLE(&pll->l_detect)) {
+		if (pll->flags & CLK_MESON_PLL_L_DETECT_N)
+			meson_parm_write(clk->map, &pll->l_detect, 0);
+		else
+			meson_parm_write(clk->map, &pll->l_detect, 1);
+	}
 
 	if (meson_clk_pll_wait_lock(hw)) {
 		/* disable PLL when PLL lock failed. */
drivers/clk/meson/clk-pll.h +2 -0
index 949157fb7bf5..83295a24721f 100644
@@ -29,6 +29,8 @@ struct pll_mult_range {
 
 #define CLK_MESON_PLL_ROUND_CLOSEST	BIT(0)
 #define CLK_MESON_PLL_NOINIT_ENABLED	BIT(1)
+/* l_detect signal is active-low */
+#define CLK_MESON_PLL_L_DETECT_N	BIT(2)
 
 struct meson_clk_pll_data {
 	struct parm en;
Signature · 1 line
2.42.0
maintainer
#13 lore raw

Re: [PATCH v2 5/5] clk: amlogic: Change the active level of l_detect

Quoted 8 lines · On Thu 30 Oct 2025 at 13:24, Chuan Liu via B4 Relay…

From: Chuan Liu <[email protected]>

l_detect controls the enable/disable of the PLL lock-detect module.

The enable signal is normally active-high. This design ensures that the module remains disabled during the power-on process, preventing power fluctuations from affecting its operating state.

Quoted 6 lines

For A1, the l_detect signal is active-low:
0 -> Enable lock-detect module;
1 -> Disable lock-detect module.

Here, a flag CLK_MESON_PLL_L_DETECT_N is added to handle cases like A1, where the signal is active-low.

Given that A1 is the only ship supporting l_detect, this change is not necessary.

Not now at least.

Quoted 67 lines
---
 drivers/clk/meson/a1-pll.c  |  1 +
 drivers/clk/meson/clk-pll.c | 16 ++++++++++++----
 drivers/clk/meson/clk-pll.h |  2 ++
 3 files changed, 15 insertions(+), 4 deletions(-)
drivers/clk/meson/a1-pll.c +1 -0
index 1f82e9c7c14e..bfe559c71402 100644
@@ -137,6 +137,7 @@ static struct clk_regmap a1_hifi_pll = {
 		.range = &a1_hifi_pll_range,
 		.init_regs = a1_hifi_pll_init_regs,
 		.init_count = ARRAY_SIZE(a1_hifi_pll_init_regs),
+		.flags = CLK_MESON_PLL_L_DETECT_N
 	},
 	.hw.init = &(struct clk_init_data){
 		.name = "hifi_pll",
drivers/clk/meson/clk-pll.c +12 -4
index c6eebde1f516..d729e933aa1c 100644
@@ -384,8 +384,12 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
 		meson_parm_write(clk->map, &pll->rst, 1);
 
 	/* Disable the PLL lock-detect module */
-	if (MESON_PARM_APPLICABLE(&pll->l_detect))
-		meson_parm_write(clk->map, &pll->l_detect, 1);
+	if (MESON_PARM_APPLICABLE(&pll->l_detect)) {
+		if (pll->flags & CLK_MESON_PLL_L_DETECT_N)
+			meson_parm_write(clk->map, &pll->l_detect, 1);
+		else
+			meson_parm_write(clk->map, &pll->l_detect, 0);
+	}
 
 	/* Enable the pll */
 	meson_parm_write(clk->map, &pll->en, 1);
@@ -413,8 +417,12 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
 	udelay(20);
 
 	/* Enable the lock-detect module */
-	if (MESON_PARM_APPLICABLE(&pll->l_detect))
-		meson_parm_write(clk->map, &pll->l_detect, 0);
+	if (MESON_PARM_APPLICABLE(&pll->l_detect)) {
+		if (pll->flags & CLK_MESON_PLL_L_DETECT_N)
+			meson_parm_write(clk->map, &pll->l_detect, 0);
+		else
+			meson_parm_write(clk->map, &pll->l_detect, 1);
+	}
 
 	if (meson_clk_pll_wait_lock(hw)) {
 		/* disable PLL when PLL lock failed. */
drivers/clk/meson/clk-pll.h +2 -0
index 949157fb7bf5..83295a24721f 100644
@@ -29,6 +29,8 @@ struct pll_mult_range {
 
 #define CLK_MESON_PLL_ROUND_CLOSEST	BIT(0)
 #define CLK_MESON_PLL_NOINIT_ENABLED	BIT(1)
+/* l_detect signal is active-low */
+#define CLK_MESON_PLL_L_DETECT_N	BIT(2)
 
 struct meson_clk_pll_data {
 	struct parm en;
Signature · 1 line
Jerome
author
#14 lore raw

Re: [PATCH v2 5/5] clk: amlogic: Change the active level of l_detect

Hi Jerome,

Quoted 16 lines · Jerome Brunet

[ EXTERNAL EMAIL ]

Quoted 12 lines · On Thu 30 Oct 2025 at 13:24, Chuan Liu via B4 Relay…

From: Chuan Liu <[email protected]>

l_detect controls the enable/disable of the PLL lock-detect module.

The enable signal is normally active-high. This design ensures that the module remains disabled during the power-on process, preventing power fluctuations from affecting its operating state.

For A1, the l_detect signal is active-low:
0 -> Enable lock-detect module;
1 -> Disable lock-detect module.

Quoted 8 lines
Quoted 2 lines

Here, a flag CLK_MESON_PLL_L_DETECT_N is added to handle cases like A1, where the signal is active-low.

Given that A1 is the only ship supporting l_detect, this change is not necessary.

Not now at least.

The SoCs queued for upstreaming later will depend on this patch, so I included it in this patchset.

If that’s not appropriate, would it be acceptable for me to include it in the A4 submission instead?

Quoted 70 lines
Quoted 59 lines
---
  drivers/clk/meson/a1-pll.c  |  1 +
  drivers/clk/meson/clk-pll.c | 16 ++++++++++++----
  drivers/clk/meson/clk-pll.h |  2 ++
  3 files changed, 15 insertions(+), 4 deletions(-)
drivers/clk/meson/a1-pll.c +1 -0
index 1f82e9c7c14e..bfe559c71402 100644
@@ -137,6 +137,7 @@ static struct clk_regmap a1_hifi_pll = {
               .range = &a1_hifi_pll_range,
               .init_regs = a1_hifi_pll_init_regs,
               .init_count = ARRAY_SIZE(a1_hifi_pll_init_regs),
+             .flags = CLK_MESON_PLL_L_DETECT_N
       },
       .hw.init = &(struct clk_init_data){
               .name = "hifi_pll",
drivers/clk/meson/clk-pll.c +12 -4
index c6eebde1f516..d729e933aa1c 100644
@@ -384,8 +384,12 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
               meson_parm_write(clk->map, &pll->rst, 1);
 
       /* Disable the PLL lock-detect module */
-     if (MESON_PARM_APPLICABLE(&pll->l_detect))
-             meson_parm_write(clk->map, &pll->l_detect, 1);
+     if (MESON_PARM_APPLICABLE(&pll->l_detect)) {
+             if (pll->flags & CLK_MESON_PLL_L_DETECT_N)
+                     meson_parm_write(clk->map, &pll->l_detect, 1);
+             else
+                     meson_parm_write(clk->map, &pll->l_detect, 0);
+     }
 
       /* Enable the pll */
       meson_parm_write(clk->map, &pll->en, 1);
@@ -413,8 +417,12 @@ static int meson_clk_pll_enable(struct clk_hw *hw)
       udelay(20);
 
       /* Enable the lock-detect module */
-     if (MESON_PARM_APPLICABLE(&pll->l_detect))
-             meson_parm_write(clk->map, &pll->l_detect, 0);
+     if (MESON_PARM_APPLICABLE(&pll->l_detect)) {
+             if (pll->flags & CLK_MESON_PLL_L_DETECT_N)
+                     meson_parm_write(clk->map, &pll->l_detect, 0);
+             else
+                     meson_parm_write(clk->map, &pll->l_detect, 1);
+     }
 
       if (meson_clk_pll_wait_lock(hw)) {
               /* disable PLL when PLL lock failed. */
drivers/clk/meson/clk-pll.h +0 -0
index 949157fb7bf5..83295a24721f 100644

drivers/clk/meson/clk-pll.h struct pll_mult_range { · line 36

Quoted 8 lines
drivers/clk/meson/clk-pll.h +2 -0
@@ -29,6 +29,8 @@ struct pll_mult_range {
 
  #define CLK_MESON_PLL_ROUND_CLOSEST  BIT(0)
  #define CLK_MESON_PLL_NOINIT_ENABLED BIT(1)
+/* l_detect signal is active-low */
+#define CLK_MESON_PLL_L_DETECT_N     BIT(2)
 
  struct meson_clk_pll_data {
       struct parm en;

--
Jerome