diff mbox series

[v2,1/2] clk: tegra: divider: Add missing check for enable-bit on rate's recalculation

Message ID 20190723025245.27754-1-digetx@gmail.com
State Changes Requested
Headers show
Series [v2,1/2] clk: tegra: divider: Add missing check for enable-bit on rate's recalculation | expand

Commit Message

Dmitry Osipenko July 23, 2019, 2:52 a.m. UTC
Unset "enable" bit means that divider is in bypass mode, hence it doesn't
have any effect in that case. Please note that there are no known bugs
caused by the missing check.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---

Changelog:

v2: Changed the commit's description from 'Fix' to 'Add' in response to the
    Stephen's Boyd question about the need to backport the patch into stable
    kernels. The backporting is not really needed.

 drivers/clk/tegra/clk-divider.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Dmitry Osipenko Sept. 22, 2019, 9:47 p.m. UTC | #1
23.07.2019 5:52, Dmitry Osipenko пишет:
> Unset "enable" bit means that divider is in bypass mode, hence it doesn't
> have any effect in that case. Please note that there are no known bugs
> caused by the missing check.
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
> 
> Changelog:
> 
> v2: Changed the commit's description from 'Fix' to 'Add' in response to the
>     Stephen's Boyd question about the need to backport the patch into stable
>     kernels. The backporting is not really needed.
> 
>  drivers/clk/tegra/clk-divider.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clk/tegra/clk-divider.c b/drivers/clk/tegra/clk-divider.c
> index e76731fb7d69..f33c19045386 100644
> --- a/drivers/clk/tegra/clk-divider.c
> +++ b/drivers/clk/tegra/clk-divider.c
> @@ -40,8 +40,13 @@ static unsigned long clk_frac_div_recalc_rate(struct clk_hw *hw,
>  	int div, mul;
>  	u64 rate = parent_rate;
>  
> -	reg = readl_relaxed(divider->reg) >> divider->shift;
> -	div = reg & div_mask(divider);
> +	reg = readl_relaxed(divider->reg);
> +
> +	if ((divider->flags & TEGRA_DIVIDER_UART) &&
> +	    !(reg & PERIPH_CLK_UART_DIV_ENB))
> +		return rate;
> +
> +	div = (reg >> divider->shift) & div_mask(divider);
>  
>  	mul = get_mul(divider);
>  	div += mul;
> 

Hello Peter,

ACK?
Peter De Schrijver Oct. 28, 2019, 2:27 p.m. UTC | #2
On Tue, Jul 23, 2019 at 05:52:44AM +0300, Dmitry Osipenko wrote:
> Unset "enable" bit means that divider is in bypass mode, hence it doesn't
> have any effect in that case. Please note that there are no known bugs
> caused by the missing check.
> 

Technically this is not quite true, but for the purposes of CCF you can
treat it that way. This bits defines if the value in the lower 16 bits
of the divider register is used to configure the divider or if the
contents of the UART DLM/DLL registers is used. So the divider isn't
actually bypassed, it's just configured differently.
In practice this bit is only set when the divider is non-zero when doing
set rate. So the extra test isn't strictly needed as long as the sw
running before the kernel also ensures the bit is only set when the
divider is non-zero.

Acked-by: Peter De Schrijver <pdeschrijver@nvidia.com>

> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
> 
> Changelog:
> 
> v2: Changed the commit's description from 'Fix' to 'Add' in response to the
>     Stephen's Boyd question about the need to backport the patch into stable
>     kernels. The backporting is not really needed.
> 
>  drivers/clk/tegra/clk-divider.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clk/tegra/clk-divider.c b/drivers/clk/tegra/clk-divider.c
> index e76731fb7d69..f33c19045386 100644
> --- a/drivers/clk/tegra/clk-divider.c
> +++ b/drivers/clk/tegra/clk-divider.c
> @@ -40,8 +40,13 @@ static unsigned long clk_frac_div_recalc_rate(struct clk_hw *hw,
>  	int div, mul;
>  	u64 rate = parent_rate;
>  
> -	reg = readl_relaxed(divider->reg) >> divider->shift;
> -	div = reg & div_mask(divider);
> +	reg = readl_relaxed(divider->reg);
> +
> +	if ((divider->flags & TEGRA_DIVIDER_UART) &&
> +	    !(reg & PERIPH_CLK_UART_DIV_ENB))
> +		return rate;
> +
> +	div = (reg >> divider->shift) & div_mask(divider);
>  
>  	mul = get_mul(divider);
>  	div += mul;
> -- 
> 2.22.0
>
Dmitry Osipenko Oct. 29, 2019, 12:14 a.m. UTC | #3
28.10.2019 17:27, Peter De Schrijver пишет:
> On Tue, Jul 23, 2019 at 05:52:44AM +0300, Dmitry Osipenko wrote:
>> Unset "enable" bit means that divider is in bypass mode, hence it doesn't
>> have any effect in that case. Please note that there are no known bugs
>> caused by the missing check.
>>
> 
> Technically this is not quite true, but for the purposes of CCF you can
> treat it that way. This bits defines if the value in the lower 16 bits
> of the divider register is used to configure the divider or if the
> contents of the UART DLM/DLL registers is used. So the divider isn't
> actually bypassed, it's just configured differently.
> In practice this bit is only set when the divider is non-zero when doing
> set rate. So the extra test isn't strictly needed as long as the sw
> running before the kernel also ensures the bit is only set when the
> divider is non-zero.
> 
> Acked-by: Peter De Schrijver <pdeschrijver@nvidia.com>

Thank you for the clarification. I hope that bootloader doesn't enable
the divider because it looks like standard 8250 driver won't be ready
for that. But serial-tegra driver seems should be good.
Dmitry Osipenko Oct. 29, 2019, 12:50 p.m. UTC | #4
29.10.2019 03:14, Dmitry Osipenko пишет:
> 28.10.2019 17:27, Peter De Schrijver пишет:
>> On Tue, Jul 23, 2019 at 05:52:44AM +0300, Dmitry Osipenko wrote:
>>> Unset "enable" bit means that divider is in bypass mode, hence it doesn't
>>> have any effect in that case. Please note that there are no known bugs
>>> caused by the missing check.
>>>
>>
>> Technically this is not quite true, but for the purposes of CCF you can
>> treat it that way. This bits defines if the value in the lower 16 bits
>> of the divider register is used to configure the divider or if the
>> contents of the UART DLM/DLL registers is used. So the divider isn't
>> actually bypassed, it's just configured differently.
>> In practice this bit is only set when the divider is non-zero when doing
>> set rate. So the extra test isn't strictly needed as long as the sw
>> running before the kernel also ensures the bit is only set when the
>> divider is non-zero.
>>
>> Acked-by: Peter De Schrijver <pdeschrijver@nvidia.com>
> 
> Thank you for the clarification. I hope that bootloader doesn't enable
> the divider because it looks like standard 8250 driver won't be ready
> for that. But serial-tegra driver seems should be good.

Actually, it should be good because I missed that UART clocks are
per-initialized in the clk driver init table.

I'll update commit's message and send a new version of this patch.
diff mbox series

Patch

diff --git a/drivers/clk/tegra/clk-divider.c b/drivers/clk/tegra/clk-divider.c
index e76731fb7d69..f33c19045386 100644
--- a/drivers/clk/tegra/clk-divider.c
+++ b/drivers/clk/tegra/clk-divider.c
@@ -40,8 +40,13 @@  static unsigned long clk_frac_div_recalc_rate(struct clk_hw *hw,
 	int div, mul;
 	u64 rate = parent_rate;
 
-	reg = readl_relaxed(divider->reg) >> divider->shift;
-	div = reg & div_mask(divider);
+	reg = readl_relaxed(divider->reg);
+
+	if ((divider->flags & TEGRA_DIVIDER_UART) &&
+	    !(reg & PERIPH_CLK_UART_DIV_ENB))
+		return rate;
+
+	div = (reg >> divider->shift) & div_mask(divider);
 
 	mul = get_mul(divider);
 	div += mul;