clk: zynqmp: pll: add set_pll_mode to check condition in zynqmp_pll_enable
Subsystems (2)
PATCH 1/2 clk: zynqmp: pll: add set_pll_mode to check condition in zynqmp_pll_enable
From: Quanyang Wang <[email protected]>
If there is a IOCTL_SET_PLL_FRAC_MODE request sent to ATF ever, we shouldn't skip invoking PM_CLOCK_ENABLE fn even though this pll has been enabled. In ATF implementation, it will only assign the mode to the variable (struct pm_pll *)pll->mode when handling IOCTL_SET_PLL_FRAC_MODE call. Invoking PM_CLOCK_ENABLE can force ATF send request to PWU to set the pll mode to PLL's register.
There is a scenario that happens in enabling VPLL_INT(clk_id:96):
1) VPLL_INT has been enabled during booting.
2) A driver calls clk_set_rate and according to the rate, the VPLL_INT should be set to FRAC mode. Then zynqmp_pll_set_mode is called to pass IOCTL_SET_PLL_FRAC_MODE to ATF. Note that at this point ATF just stores the mode to a variable.
3) This driver calls clk_prepare_enable and zynqmp_pll_enable is called to try to enable VPLL_INT pll. Because of 1), the function zynqmp_pll_enable just returns without doing anything after checking that this pll has been enabled.
In the scenario above, the pll mode of VPLL_INT will never be set successfully. So adding set_pll_mode to chec condition to fix it.
--- drivers/clk/zynqmp/pll.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/clk/zynqmp/pll.c +10 -1
@@ -14,10 +14,12 @@* struct zynqmp_pll - PLL clock * @hw: Handle between common and hardware-specific interfaces * @clk_id: PLL clock ID +* @set_pll_mode: Whether an IOCTL_SET_PLL_FRAC_MODE request be sent to ATF */ struct zynqmp_pll {struct clk_hw hw;u32 clk_id; +bool set_pll_mode; };#define to_zynqmp_pll (_hw) container_of(_hw, struct zynqmp_pll, hw)
@@ -81,6 +83,8 @@ static inline void zynqmp_pll_set_mode(struct clk_hw *hw, bool on)if (ret)pr_warn_once ("%s() PLL set frac mode failed for %s, ret = %d\n" , __func__, clk_name, ret); +else + clk->set_pll_mode = true; }/**
@@ -240,9 +244,14 @@ static int zynqmp_pll_enable(struct clk_hw *hw)u32 clk_id = clk->clk_id;int ret; -if (zynqmp_pll_is_enabled (hw)) +/* Don't skip enabling clock if there is an IOCTL_SET_PLL_FRAC_MODE request +* that has been sent to ATF. +*/ +if (zynqmp_pll_is_enabled (hw) && (!clk->set_pll_mode))return 0 ; + clk->set_pll_mode = false; + ret =zynqmp_pm_clock_enable (clk_id);if (ret) pr_warn_once("%s() clock enable failed for %s, ret = %d\n",
Signature · 1 line
2.25.1
Hi Quanyang,
Thank you for the patch.
Quoted 20 lines · On Fri, Mar 19, 2021 at 06:07:17PM +0800, [email protected] wrote:
From: Quanyang Wang <[email protected]>
If there is a
IOCTL_SET_PLL_FRAC_MODErequest sent to ATF ever, we shouldn't skip invokingPM_CLOCK_ENABLEfn even though this pll has been enabled. In ATF implementation, it will only assign the mode to the variable (structpm_pll*)pll->mode when handlingIOCTL_SET_PLL_FRAC_MODEcall. InvokingPM_CLOCK_ENABLEcan force ATF send request to PWU to set the pll mode to PLL's register.There is a scenario that happens in enabling
VPLL_INT(clk_id:96):
1)VPLL_INThas been enabled during booting.
2) A driver callsclk_set_rateand according to the rate, theVPLL_INTshould be set to FRAC mode. Thenzynqmp_pll_set_modeis called to passIOCTL_SET_PLL_FRAC_MODEto ATF. Note that at this point ATF just stores the mode to a variable.
3) This driver callsclk_prepare_enableandzynqmp_pll_enableis called to try to enableVPLL_INTpll. Because of 1), the functionzynqmp_pll_enablejust returns without doing anything after checking that this pll has been enabled.
Quoted 2 lines
In the scenario above, the pll mode of
VPLL_INTwill never be set successfully. So addingset_pll_modeto chec condition to fix it.
s/chec/check/
Quoted 32 lines
Signed-off-by Quanyang Wang <[email protected]>--- drivers/clk/zynqmp/pll.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/clk/zynqmp/pll.c +4
-0@@ -14,10 +14,12 @@* struct zynqmp_pll - PLL clock * @hw: Handle between common and hardware-specific interfaces * @clk_id: PLL clock ID +* @set_pll_mode: Whether an IOCTL_SET_PLL_FRAC_MODE request be sent to ATF */ struct zynqmp_pll {struct clk_hw hw;u32 clk_id; +bool set_pll_mode; };#define to_zynqmp_pll (_hw) container_of(_hw, struct zynqmp_pll, hw)@@ -81,6 +83,8 @@ static inline void zynqmp_pll_set_mode(struct clk_hw *hw, bool on)if (ret)pr_warn_once ("%s() PLL set frac mode failed for %s, ret = %d\n" , __func__, clk_name, ret); +else + clk->set_pll_mode = true; }/**
drivers/clk/zynqmp/pll.c static int zynqmp_pll_enable(struct clk_hw *hw) · line 249
Quoted 7 lines
drivers/clk/zynqmp/pll.c +3
-1@@ -240,9 +244,14 @@ static int zynqmp_pll_enable(struct clk_hw *hw)u32 clk_id = clk->clk_id;int ret; -if (zynqmp_pll_is_enabled (hw)) +/* Don't skip enabling clock if there is an IOCTL_SET_PLL_FRAC_MODE request +* that has been sent to ATF. +*/
Very small issue, multiline kerneldoc comments are supposed to start with a '/*' on its own line:
/* * Don't skip enabling clock if there is an IOCTL_SET_PLL_FRAC_MODE * request that has been sent to ATF. */
drivers/clk/zynqmp/pll.c static int zynqmp_pll_enable(struct clk_hw *hw) · line 257
Quoted 8 lines
drivers/clk/zynqmp/pll.c +3
-0+if (zynqmp_pll_is_enabled (hw) && (!clk->set_pll_mode))return 0 ; + clk->set_pll_mode = false; + ret =zynqmp_pm_clock_enable (clk_id);if (ret) pr_warn_once("%s() clock enable failed for %s, ret = %d\n",
This fixes the DPSUB clock issue, so
I however wonder if this is the best solution. Shouldn't we instead fix it on the ATF side, to program the hardware when zynqmp_pll_set_mode() is called if the clock is already enabled ?
Just reading the code, I can immediately see another potential issue in zynqmp_pll_set_mode(). The function is called from zynqmp_pll_round_rate(), which seems completely wrong, as zynqmp_pll_round_rate() is supposed to only perform rate calculation, not program the hardware. Am I missing something, or does the PLL implementation need to be reworked more extensively than this ?
Signature · 3 lines
Regards, Laurent Pinchart
Hi Laurent,
Quoted 25 lines · Laurent Pinchart
Hi Quanyang,
Thank you for the patch.
Quoted 20 lines · On Fri, Mar 19, 2021 at 06:07:17PM +0800, [email protected] wrote:
From: Quanyang Wang <[email protected]>
If there is a
IOCTL_SET_PLL_FRAC_MODErequest sent to ATF ever, we shouldn't skip invokingPM_CLOCK_ENABLEfn even though this pll has been enabled. In ATF implementation, it will only assign the mode to the variable (structpm_pll*)pll->mode when handlingIOCTL_SET_PLL_FRAC_MODEcall. InvokingPM_CLOCK_ENABLEcan force ATF send request to PWU to set the pll mode to PLL's register.There is a scenario that happens in enabling
VPLL_INT(clk_id:96):
1)VPLL_INThas been enabled during booting.
2) A driver callsclk_set_rateand according to the rate, theVPLL_INTshould be set to FRAC mode. Thenzynqmp_pll_set_modeis called to passIOCTL_SET_PLL_FRAC_MODEto ATF. Note that at this point ATF just stores the mode to a variable.
3) This driver callsclk_prepare_enableandzynqmp_pll_enableis called to try to enableVPLL_INTpll. Because of 1), the functionzynqmp_pll_enablejust returns without doing anything after checking that this pll has been enabled.
Quoted 3 lines
Quoted 2 lines
In the scenario above, the pll mode of
VPLL_INTwill never be set successfully. So addingset_pll_modeto chec condition to fix it.s/chec/check/
Thanks for pointing it out. Will fix it in the next version.
Quoted 43 lines
Quoted 33 lines
Signed-off-by Quanyang Wang <[email protected]>--- drivers/clk/zynqmp/pll.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/clk/zynqmp/pll.c +4
-0@@ -14,10 +14,12 @@* struct zynqmp_pll - PLL clock * @hw: Handle between common and hardware-specific interfaces * @clk_id: PLL clock ID +* @set_pll_mode: Whether an IOCTL_SET_PLL_FRAC_MODE request be sent to ATF */ struct zynqmp_pll {struct clk_hw hw;u32 clk_id; +bool set_pll_mode; };#define to_zynqmp_pll (_hw) container_of(_hw, struct zynqmp_pll, hw)@@ -81,6 +83,8 @@ static inline void zynqmp_pll_set_mode(struct clk_hw *hw, bool on)if (ret)pr_warn_once ("%s() PLL set frac mode failed for %s, ret = %d\n" , __func__, clk_name, ret); +else + clk->set_pll_mode = true; }/** drivers/clk/zynqmp/pll.c static int zynqmp_pll_enable(struct clk_hw *hw) · line 249
Quoted 7 lines
drivers/clk/zynqmp/pll.c +3
-1@@ -240,9 +244,14 @@ static int zynqmp_pll_enable(struct clk_hw *hw)u32 clk_id = clk->clk_id;int ret; -if (zynqmp_pll_is_enabled (hw)) +/* Don't skip enabling clock if there is an IOCTL_SET_PLL_FRAC_MODE request +* that has been sent to ATF. +*/ Very small issue, multiline kerneldoc comments are supposed to start with a '/*' on its own line:
Quoted 4 lines
/* * Don't skip enabling clock if there is an IOCTL_SET_PLL_FRAC_MODE * request that has been sent to ATF. */
OK. Will fix it in the next version.
Quoted 10 lines
drivers/clk/zynqmp/pll.c static int zynqmp_pll_enable(struct clk_hw *hw) · line 257
Quoted 8 lines
drivers/clk/zynqmp/pll.c +3
-0+if (zynqmp_pll_is_enabled (hw) && (!clk->set_pll_mode))return 0 ; + clk->set_pll_mode = false; + ret =zynqmp_pm_clock_enable (clk_id);if (ret) pr_warn_once("%s() clock enable failed for %s, ret = %d\n",This fixes the DPSUB clock issue, so
Quoted 5 lines
Tested-by Laurent Pinchart <[email protected]>I however wonder if this is the best solution. Shouldn't we instead fix it on the ATF side, to program the hardware when
zynqmp_pll_set_mode()is called if the clock is already enabled ?
I found the commit message which records the reason of this change. And in this commit,
it shows that the code is changing from programming the hardware to buffering the mode.
https://github.com/Xilinx/arm-trusted-firmware.git
commit 8975f317e7608c832192b71531901602dc625484
Author: Jolly Shah <[email protected]>
Date: Wed Jan 2 12:46:46 2019 -0800
zynqmp: pm: Buffer the PLL mode that is set using IOCTL API
When linux calls pm_ioctl_set_pll_frac_mode() it doesn't expect the fractional mode to be changed in hardware. Furthermore, even before this patch setting the mode which is done by writing into register takes no effect until the PLL reset is deasserted, i.e. until linux "enables" the PLL. To adjust the code to system-level PLL EEMI API and avoid unnecessary IPIs that would otherwise be issued, we buffer the mode value set via IOCTL until the PLL mode really needs to be set.
Quoted 6 lines
Just reading the code, I can immediately see another potential issue in
zynqmp_pll_set_mode(). The function is called fromzynqmp_pll_round_rate(), which seems completely wrong, aszynqmp_pll_round_rate()is supposed to only perform rate calculation, not program the hardware.
I agree. Moving zynqmp_pll_set_mode out of zynqmp_pll_round_rate
and putting it in zynqmp_pll_set_rate may be better.
Thanks,
Quanyang
Quoted 2 lines
Am I missing something, or does the PLL
implementation need to be reworked more extensively than this ?
Hi Laurent,
Quoted 92 lines · Laurent Pinchart
Hi Quanyang,
Thank you for the patch.
Quoted 20 lines · On Fri, Mar 19, 2021 at 06:07:17PM +0800, [email protected] wrote:
From: Quanyang Wang <[email protected]>
If there is a
IOCTL_SET_PLL_FRAC_MODErequest sent to ATF ever, we shouldn't skip invokingPM_CLOCK_ENABLEfn even though this pll has been enabled. In ATF implementation, it will only assign the mode to the variable (structpm_pll*)pll->mode when handlingIOCTL_SET_PLL_FRAC_MODEcall. InvokingPM_CLOCK_ENABLEcan force ATF send request to PWU to set the pll mode to PLL's register.There is a scenario that happens in enabling
VPLL_INT(clk_id:96):
1)VPLL_INThas been enabled during booting.
2) A driver callsclk_set_rateand according to the rate, theVPLL_INTshould be set to FRAC mode. Thenzynqmp_pll_set_modeis called to passIOCTL_SET_PLL_FRAC_MODEto ATF. Note that at this point ATF just stores the mode to a variable.
3) This driver callsclk_prepare_enableandzynqmp_pll_enableis called to try to enableVPLL_INTpll. Because of 1), the functionzynqmp_pll_enablejust returns without doing anything after checking that this pll has been enabled.Quoted 2 lines
In the scenario above, the pll mode of
VPLL_INTwill never be set successfully. So addingset_pll_modeto chec condition to fix it.s/chec/check/
Quoted 32 lines
Signed-off-by Quanyang Wang <[email protected]>--- drivers/clk/zynqmp/pll.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/clk/zynqmp/pll.c +4
-0@@ -14,10 +14,12 @@* struct zynqmp_pll - PLL clock * @hw: Handle between common and hardware-specific interfaces * @clk_id: PLL clock ID +* @set_pll_mode: Whether an IOCTL_SET_PLL_FRAC_MODE request be sent to ATF */ struct zynqmp_pll {struct clk_hw hw;u32 clk_id; +bool set_pll_mode; };#define to_zynqmp_pll (_hw) container_of(_hw, struct zynqmp_pll, hw)@@ -81,6 +83,8 @@ static inline void zynqmp_pll_set_mode(struct clk_hw *hw, bool on)if (ret)pr_warn_once ("%s() PLL set frac mode failed for %s, ret = %d\n" , __func__, clk_name, ret); +else + clk->set_pll_mode = true; }/** drivers/clk/zynqmp/pll.c static int zynqmp_pll_enable(struct clk_hw *hw) · line 249
Quoted 7 lines
drivers/clk/zynqmp/pll.c +3
-1@@ -240,9 +244,14 @@ static int zynqmp_pll_enable(struct clk_hw *hw)u32 clk_id = clk->clk_id;int ret; -if (zynqmp_pll_is_enabled (hw)) +/* Don't skip enabling clock if there is an IOCTL_SET_PLL_FRAC_MODE request +* that has been sent to ATF. +*/ Very small issue, multiline kerneldoc comments are supposed to start with a '/*' on its own line:
/* * Don't skip enabling clock if there is an IOCTL_SET_PLL_FRAC_MODE * request that has been sent to ATF. */drivers/clk/zynqmp/pll.c static int zynqmp_pll_enable(struct clk_hw *hw) · line 257
Quoted 8 lines
drivers/clk/zynqmp/pll.c +3
-0+if (zynqmp_pll_is_enabled (hw) && (!clk->set_pll_mode))return 0 ; + clk->set_pll_mode = false; + ret =zynqmp_pm_clock_enable (clk_id);if (ret) pr_warn_once("%s() clock enable failed for %s, ret = %d\n",This fixes the DPSUB clock issue, so
Tested-by Laurent Pinchart <[email protected]>I however wonder if this is the best solution. Shouldn't we instead fix it on the ATF side, to program the hardware when
zynqmp_pll_set_mode()is called if the clock is already enabled ?
Quoted 6 lines
Just reading the code, I can immediately see another potential issue in
zynqmp_pll_set_mode(). The function is called fromzynqmp_pll_round_rate(), which seems completely wrong, aszynqmp_pll_round_rate()is supposed to only perform rate calculation, not program the hardware. Am I missing something, or does the PLL implementation need to be reworked more extensively than this ?
I will send another patch to fix this issue.
Thanks,
Quanyang