Fix Versa3 clock mapping
Subsystems (4)
Biju Das
maintainerv3 cover Fix Versa3 clock mapping
According to Table 3. ("Output Source") in the 5P35023 datasheet, the output clock mapping should be 0=REF, 1=SE1, 2=SE2, 3=SE3, 4=DIFF1, 5=DIFF2. But the code uses inverse.
This patch series aims to document clock-output-names in bindings and fix the mapping in driver.
Also added a fix for 64 by 64 division.
v2->v3:
* Dropped dts patch and added fix for 64 byte division to this patch series.
* Added Rb tag from Geert for patch#3
* Added a patch to make vc3_clk_mux enum values depend on vc3_clk enum values.v1->v2:
* Updated binding commit description to make it clear it fixes "assigned-clock-rates" in the example based on 5P35023 datasheet.
Biju Das (4):
dt-bindings: clock: versaclock3: Document clock-output-names
clk: vc3: Fix 64 by 64 division
clk: vc3: Fix output clock mapping
clk: vc3: Make vc3_clk_mux enum values based on vc3_clk enum values
.../bindings/clock/renesas,5p35023.yaml | 14 +++- drivers/clk/clk-versaclock3.c | 79 +++++++++---------- 2 files changed, 49 insertions(+), 44 deletions(-)
Signature · 1 line
2.25.1
Biju Das
maintainerPATCH v3 1/4 dt-bindings: clock: versaclock3: Document clock-output-names
Document clock-output-names property and fix the "assigned-clock-rates" for each clock output in the example based on Table 3. ("Output Source") in the 5P35023 datasheet(ie: {REF,SE1,SE2,SE3,DIFF1,DIFF2}).
While at it, replace clocks phandle in the example from x1_x2->x1 as X2 is a different 32768 kHz crystal.
---v2->v3:
* No change.v1->v2:
* Updated commit description to make it clear it fixes "assigned-clock-rates" in the example based on 5P35023 datasheet.
--- .../devicetree/bindings/clock/renesas,5p35023.yaml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/clock/renesas,5p35023.yaml +10 -4
@@ -49,6 +49,9 @@ properties: $ref: /schemas/types.yaml#/definitions/uint8-array maxItems: 37 + clock-output-names: + maxItems: 6 + required: - compatible - reg
@@ -68,7 +71,7 @@ examples: reg = <0x68>; #clock-cells = <1>; - clocks = <&x1_x2>; + clocks = <&x1>; renesas,settings = [ 80 00 11 19 4c 02 23 7f 83 19 08 a9 5f 25 24 bf
@@ -76,11 +79,14 @@ examples: 80 b0 45 c4 95 ]; + clock-output-names = "ref", "se1", "se2", "se3", + "diff1", "diff2"; + assigned-clocks = <&versa3 0>, <&versa3 1>, <&versa3 2>, <&versa3 3>, <&versa3 4>, <&versa3 5>; - assigned-clock-rates = <12288000>, <25000000>, - <12000000>, <11289600>, - <11289600>, <24000000>; + assigned-clock-rates = <24000000>, <11289600>, + <11289600>, <12000000>, + <25000000>, <12288000>; }; };
Signature · 1 line
2.25.1
Re: [PATCH v3 1/4] dt-bindings: clock: versaclock3: Document clock-output-names
Quoted 4 lines · Biju Das
Document clock-output-names property and fix the "assigned-clock-rates" for each clock output in the example based on Table 3. ("Output Source") in the 5P35023
datasheet(ie: {REF,SE1,SE2,SE3,DIFF1,DIFF2}).
Quoted 8 lines
While at it, replace clocks phandle in the example from
x1_x2->x1as X2 is a different 32768 kHz crystal.Suggested-by Geert Uytterhoeven <[email protected]>Closes https://lore.kernel.org/all/CAMuHMdUHD+bEco=WYTYWsTAyRt3dTQQt4Xpaejss0Y2ZpLCMNg@mail.gmail.com/ open hereFixes a03d23f860eb ("dt-bindings: clock: Add Renesas versa3 clock generator bindings")Signed-off-by Biju Das <[email protected]>---
Best regards,
Krzysztof
Re: [PATCH v3 1/4] dt-bindings: clock: versaclock3: Document clock-output-names
In reply to Biju DasQuoting Biju Das (2023-08-17 07:22:08)
Quoted 4 lines
Document clock-output-names property and fix the "assigned-clock-rates" for each clock output in the example based on Table 3. ("Output Source") in the 5P35023
datasheet(ie: {REF,SE1,SE2,SE3,DIFF1,DIFF2}).
Quoted 8 lines
While at it, replace clocks phandle in the example from
x1_x2->x1as X2 is a different 32768 kHz crystal.Suggested-by Geert Uytterhoeven <[email protected]>Closes https://lore.kernel.org/all/CAMuHMdUHD+bEco=WYTYWsTAyRt3dTQQt4Xpaejss0Y2ZpLCMNg@mail.gmail.com/ open hereFixes a03d23f860eb ("dt-bindings: clock: Add Renesas versa3 clock generator bindings")Signed-off-by Biju Das <[email protected]>---
Applied to clk-next
Biju Das
maintainerRE: [PATCH v3 1/4] dt-bindings: clock: versaclock3: Document clock-output-names
Hi Stephen Boyd,
Quoted 11 lines
Subject: Re: [PATCH v3 1/4] dt-bindings: clock: versaclock3: Document clock-output-names
Quoting Biju Das (2023-08-17 07:22:08)
Quoted 7 lines
Document clock-output-names property and fix the "assigned-clock-rates" for each clock output in the example based on Table 3. ("Output Source") in the 5P35023
datasheet(ie: {REF,SE1,SE2,SE3,DIFF1,DIFF2}).While at it, replace clocks phandle in the example from
x1_x2->x1as X2 is a different 32768 kHz crystal.
Quoted 8 lines
Quoted 6 lines
Suggested-by Geert Uytterhoeven <[email protected]>Closes:
Fixes a03d23f860eb ("dt-bindings: clock: Add Renesas versa3 clockgenerator bindings")
Signed-off-by Biju Das <[email protected]>---
Applied to clk-next
As per Geert's suggestion [1], I am about to send a patch
for dropping "clock-output-names", as there is no validation for it and people can get it wrong.
Is it ok,if I send a patch dropping clock-output-names? Please let me know your opinion on this.
[1] https://patchwork.kernel.org/project/linux-renesas-soc/patch/[email protected]/
Cheers,
Biju
Biju Das
maintainerPATCH v3 2/4 clk: vc3: Fix 64 by 64 division
In reply to Biju DasFix the below cocci warnings by replacing do_div()->div64_ul() and bound the result with a max value of U16_MAX.
cocci warnings:
drivers/clk/clk-versaclock3.c:404:2-8: WARNING: do_div() does a 64-by-32 division, please consider using div64_ul instead.
---v2->v3:
* Added to this patch series.v1->v2:
* Added fixes tag.
--- drivers/clk/clk-versaclock3.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/clk/clk-versaclock3.c +1 -2
@@ -401,9 +401,8 @@ static long vc3_pll_round_rate(struct clk_hw *hw, unsigned long rate,/* Determine best fractional part, which is 16 bit wide */ div_frc = rate % *parent_rate; div_frc *=BIT (16 ) -1 ; -do_div (div_frc, *parent_rate); - vc3->div_frc = (u32 )div_frc; + vc3->div_frc =min_t (u64,div64_ul (div_frc, *parent_rate),U16_MAX ); rate = (*parent_rate * (vc3->div_int *VC3_2_POW_16 + div_frc) /VC3_2_POW_16 ); }else {
Signature · 1 line
2.25.1
Stephen Boyd
maintainerRe: [PATCH v3 2/4] clk: vc3: Fix 64 by 64 division
Quoting Biju Das (2023-08-17 07:22:09)
Quoted 25 lines
Fix the below cocci warnings by replacing do_div()->div64_ul() and bound the result with a max value of
U16_MAX.cocci warnings:
drivers/clk/clk-versaclock3.c:404:2-8: WARNING:do_div()does a 64-by-32 division, please consider usingdiv64_ulinstead.Reported-by Julia Lawall <[email protected]>Fixes 6e9aff555db7 ("clk: Add support for versa3 clock driver")Signed-off-by Biju Das <[email protected]>---
v2->v3:
* Added to this patch series.v1->v2:
* Added fixes tag.--- drivers/clk/clk-versaclock3.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/clk/clk-versaclock3.c +0
-0
drivers/clk/clk-versaclock3.c static long vc3_pll_round_rate(struct clk_hw *hw, unsigned long rate, · line 407
Quoted 9 lines
drivers/clk/clk-versaclock3.c +1
-2@@ -401,9 +401,8 @@ static long vc3_pll_round_rate(struct clk_hw *hw, unsigned long rate,/* Determine best fractional part, which is 16 bit wide */ div_frc = rate % *parent_rate; div_frc *=BIT (16 ) -1 ; -do_div (div_frc, *parent_rate); - vc3->div_frc = (u32 )div_frc; + vc3->div_frc =min_t (u64,div64_ul (div_frc, *parent_rate),U16_MAX ); rate = (*parent_rate * (vc3->div_int *VC3_2_POW_16 + div_frc) /VC3_2_POW_16 );
^
Should this be vc3->div_frc now to get the clamped value? --|
Biju Das
maintainerRE: [PATCH v3 2/4] clk: vc3: Fix 64 by 64 division
Hi Stephen Boyd,
Thanks for the feedback.
Quoted 44 lines
Subject: Re: [PATCH v3 2/4] clk: vc3: Fix 64 by 64 division
Quoting Biju Das (2023-08-17 07:22:09)
drivers/clk/clk-versaclock3.c static long vc3_pll_round_rate(struct clk_hw *hw,
Quoted 27 lines
Fix the below cocci warnings by replacing do_div()->div64_ul() and bound the result with a max value of
U16_MAX.cocci warnings:
drivers/clk/clk-versaclock3.c:404:2-8: WARNING:do_div()does a 64-by-32 division, please consider usingdiv64_ulinstead.Reported-by Julia Lawall <[email protected]>Closes:
Fixes 6e9aff555db7 ("clk: Add support for versa3 clock driver")Signed-off-by Biju Das <[email protected]>---
v2->v3:
* Added to this patch series.v1->v2:
* Added fixes tag.--- drivers/clk/clk-versaclock3.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/clk/clk-versaclock3.cindex7ab2447bd203..3ded616a0d15100644drivers/clk/clk-versaclock3.c +0
-0@@ -401,9 +401,8 @@ static long vc3_pll_round_rate(struct clk_hw *hw,unsigned long rate,
drivers/clk/clk-versaclock3.c static long vc3_pll_round_rate(struct clk_hw *hw, · line 401
Quoted 1 line
drivers/clk/clk-versaclock3.c +0
-0/* Determine best fractional part, which is 16 bit wide */
Quoted 10 lines
drivers/clk/clk-versaclock3.c +2
-2div_frc = rate % *parent_rate; div_frc *=BIT (16 ) -1 ; -do_div (div_frc, *parent_rate); - vc3->div_frc = (u32 )div_frc; + vc3->div_frc =min_t (u64,div64_ul (div_frc, + *parent_rate),U16_MAX ); rate = (*parent_rate * (vc3->div_int * VC3_2_POW_16 + div_frc) /
VC3_2_POW_16);
Quoted 2 lines
^ Should this
bevc3->div_frcnow to get the clamped value? --|
Yes, it is clamped value. I will send next version fixing this.
Cheers,
Biju
Biju Das
maintainerPATCH v3 3/4 clk: vc3: Fix output clock mapping
In reply to Biju DasAccording to Table 3. ("Output Source") in the 5P35023 datasheet, the output clock mapping should be 0=REF, 1=SE1, 2=SE2, 3=SE3, 4=DIFF1, 5=DIFF2. But the code uses inverse. Fix this mapping issue.
---v2->v3:
* Added Rb tag from Geert.v1->v2:
* No change.
--- drivers/clk/clk-versaclock3.c | 68 +++++++++++++++++------------------ 1 file changed, 34 insertions(+), 34 deletions(-)
drivers/clk/clk-versaclock3.c +34 -34
@@ -119,20 +119,20 @@ enum vc3_div { };enum vc3_clk_mux { -VC3_DIFF2_MUX , -VC3_DIFF1_MUX , -VC3_SE3_MUX , -VC3_SE2_MUX ,VC3_SE1_MUX , +VC3_SE2_MUX , +VC3_SE3_MUX , +VC3_DIFF1_MUX , +VC3_DIFF2_MUX , };enum vc3_clk { -VC3_DIFF2 , -VC3_DIFF1 , -VC3_SE3 , -VC3_SE2 , -VC3_SE1 ,VC3_REF , +VC3_SE1 , +VC3_SE2 , +VC3_SE3 , +VC3_DIFF1 , +VC3_DIFF2 , };struct vc3_clk_data {
@@ -896,33 +896,33 @@ static struct vc3_hw_data clk_div[] = { };static struct vc3_hw_data clk_mux[] = { - [VC3_DIFF2_MUX ] = { + [VC3_SE1_MUX ] = { .data = &(struct vc3_clk_data ) { - .offs =VC3_DIFF2_CTRL_REG , - .bitmsk =VC3_DIFF2_CTRL_REG_DIFF2_CLK_SEL + .offs =VC3_SE1_DIV4_CTRL , + .bitmsk =VC3_SE1_DIV4_CTRL_SE1_CLK_SEL }, .hw.init = &(struct clk_init_data ){ - .name ="diff2_mux" , + .name ="se1_mux" , .ops = &vc3_clk_mux_ops, .parent_hws = (const struct clk_hw *[]) { - &clk_div[VC3_DIV1 ].hw, - &clk_div[VC3_DIV3 ].hw + &clk_div[VC3_DIV5 ].hw, + &clk_div[VC3_DIV4 ].hw }, .num_parents =2 , .flags =CLK_SET_RATE_PARENT } }, - [VC3_DIFF1_MUX ] = { + [VC3_SE2_MUX ] = { .data = &(struct vc3_clk_data ) { - .offs =VC3_DIFF1_CTRL_REG , - .bitmsk =VC3_DIFF1_CTRL_REG_DIFF1_CLK_SEL + .offs =VC3_SE2_CTRL_REG0 , + .bitmsk =VC3_SE2_CTRL_REG0_SE2_CLK_SEL }, .hw.init = &(struct clk_init_data ){ - .name ="diff1_mux" , + .name ="se2_mux" , .ops = &vc3_clk_mux_ops, .parent_hws = (const struct clk_hw *[]) { - &clk_div[VC3_DIV1 ].hw, - &clk_div[VC3_DIV3 ].hw + &clk_div[VC3_DIV5 ].hw, + &clk_div[VC3_DIV4 ].hw }, .num_parents =2 , .flags =CLK_SET_RATE_PARENT
@@ -944,33 +944,33 @@ static struct vc3_hw_data clk_mux[] = { .flags = CLK_SET_RATE_PARENT } }, - [VC3_SE2_MUX] = { + [VC3_DIFF1_MUX] = { .data = &(struct vc3_clk_data) { - .offs = VC3_SE2_CTRL_REG0, - .bitmsk = VC3_SE2_CTRL_REG0_SE2_CLK_SEL + .offs = VC3_DIFF1_CTRL_REG, + .bitmsk = VC3_DIFF1_CTRL_REG_DIFF1_CLK_SEL }, .hw.init = &(struct clk_init_data){ - .name = "se2_mux", + .name = "diff1_mux", .ops = &vc3_clk_mux_ops, .parent_hws = (const struct clk_hw *[]) { - &clk_div[VC3_DIV5].hw, - &clk_div[VC3_DIV4].hw + &clk_div[VC3_DIV1].hw, + &clk_div[VC3_DIV3].hw }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT } }, - [VC3_SE1_MUX] = { + [VC3_DIFF2_MUX] = { .data = &(struct vc3_clk_data) { - .offs = VC3_SE1_DIV4_CTRL, - .bitmsk = VC3_SE1_DIV4_CTRL_SE1_CLK_SEL + .offs = VC3_DIFF2_CTRL_REG, + .bitmsk = VC3_DIFF2_CTRL_REG_DIFF2_CLK_SEL }, .hw.init = &(struct clk_init_data){ - .name = "se1_mux", + .name = "diff2_mux", .ops = &vc3_clk_mux_ops, .parent_hws = (const struct clk_hw *[]) { - &clk_div[VC3_DIV5].hw, - &clk_div[VC3_DIV4].hw + &clk_div[VC3_DIV1].hw, + &clk_div[VC3_DIV3].hw }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT
@@ -1109,7 +1109,7 @@ static int vc3_probe(struct i2c_client *client) name, 0, CLK_SET_RATE_PARENT, 1, 1); else clk_out[i] =devm_clk_hw_register_fixed_factor_parent_hw (dev, - name, &clk_mux[i].hw,CLK_SET_RATE_PARENT ,1 ,1 ); + name, &clk_mux[i -1 ].hw,CLK_SET_RATE_PARENT ,1 ,1 );if (IS_ERR (clk_out[i]))return PTR_ERR (clk_out[i]);
Signature · 1 line
2.25.1
Re: [PATCH v3 3/4] clk: vc3: Fix output clock mapping
Quoting Biju Das (2023-08-17 07:22:10)
Quoted 10 lines
According to Table 3. ("Output Source") in the 5P35023 datasheet, the output clock mapping should be 0=REF, 1=SE1, 2=SE2, 3=SE3, 4=DIFF1, 5=DIFF2. But the code uses inverse. Fix this mapping issue.
Suggested-by Geert Uytterhoeven <[email protected]>Closes https://lore.kernel.org/all/CAMuHMdUHD+bEco=WYTYWsTAyRt3dTQQt4Xpaejss0Y2ZpLCMNg@mail.gmail.com/ open hereFixes 6e9aff555db7 ("clk: Add support for versa3 clock driver")Signed-off-by Biju Das <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>---
Applied to clk-next
Biju Das
maintainerPATCH v3 4/4 clk: vc3: Make vc3_clk_mux enum values based on vc3_clk enum values
In reply to Biju DasMake vc3_clk_mux enum values depend upon vc3_clk enum values to avoid any accidental breakage in the future.
---
v3:
* New patch.
--- drivers/clk/clk-versaclock3.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/clk/clk-versaclock3.c +8 -8
@@ -118,14 +118,6 @@ enum vc3_div { VC3_DIV5, }; -enum vc3_clk_mux { -VC3_SE1_MUX , -VC3_SE2_MUX , -VC3_SE3_MUX , -VC3_DIFF1_MUX , -VC3_DIFF2_MUX , -}; -enum vc3_clk {VC3_REF ,VC3_SE1 ,
@@ -135,6 +127,14 @@ enum vc3_clk { VC3_DIFF2, }; +enum vc3_clk_mux { +VC3_SE1_MUX =VC3_SE1 -1 , +VC3_SE2_MUX =VC3_SE2 -1 , +VC3_SE3_MUX =VC3_SE3 -1 , +VC3_DIFF1_MUX =VC3_DIFF1 -1 , +VC3_DIFF2_MUX =VC3_DIFF2 -1 , +}; +struct vc3_clk_data {u8 offs;u8 bitmsk;
Signature · 1 line
2.25.1
Re: [PATCH v3 4/4] clk: vc3: Make vc3_clk_mux enum values based on vc3_clk enum values
Quoting Biju Das (2023-08-17 07:22:11)
Quoted 5 lines
Make
vc3_clk_muxenum values depend uponvc3_clkenum values to avoid any accidental breakage in the future.Signed-off-by Biju Das <[email protected]>---
Applied to clk-next