Skip to contentSkip to conversation

clk: Add fractional scale clock support

PATCH In review Hoan Tran 2 participants 7 messages Jun 20, 2016 – Aug 16, 2016 2 messages not in the archive Common clk

lore
Share & tools
lore

Hoan Tran

author
#0 lore raw

PATCH v2 1/1 clk: Add fractional scale clock support

This patch adds fractional scale clock support.
Fractional scale clock is implemented for a single register field.
Output rate = parent_rate * scale / denominator
For example, for 1 / 8 fractional scale, denominator will be 8 and scale will be computed and programmed accordingly.

v2
* Fix compile error by using DIV_ROUND_UP_ULL() macro
* Remove DT binding document
* Remove DT clk_fractional_scale_init() function

v1
* Initial

---
 drivers/clk/Makefile               |   1 +
 drivers/clk/clk-fractional-scale.c | 195 +++++++++++++++++++++++++++++++++++++
 include/linux/clk-provider.h       |  41 ++++++++
 3 files changed, 237 insertions(+)
 create mode 100644 drivers/clk/clk-fractional-scale.c
drivers/clk/Makefile +1 -0
index dcc5e69..d7deddf 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_COMMON_CLK)	+= clk-multiplier.o
 obj-$(CONFIG_COMMON_CLK)	+= clk-mux.o
 obj-$(CONFIG_COMMON_CLK)	+= clk-composite.o
 obj-$(CONFIG_COMMON_CLK)	+= clk-fractional-divider.o
+obj-$(CONFIG_COMMON_CLK)	+= clk-fractional-scale.o
 obj-$(CONFIG_COMMON_CLK)	+= clk-gpio.o
 ifeq ($(CONFIG_OF), y)
 obj-$(CONFIG_COMMON_CLK)	+= clk-conf.o
drivers/clk/clk-fractional-scale.c new file +195 -0

195 lines not on this page · raw message

include/linux/clk-provider.h +41 -0

47 lines not on this page · raw message

Signature · 1 line
1.9.1
#3 lore raw
In reply to a message not in the archive

Sorry I replied offlist before. Pressed the wrong key.

Quoted 9 lines · Hoan Tran
Quoted 3 lines · Stephen Boyd

How is this different from clk-fractional-divider.c?

This is a driver which clock output is multiplied with a fixed fractional scale (denominator).
A field inside a register is used to configure the multiplier.

Quoted 8 lines

Example: With fractional scale is 1/8.
Freq_out = Freq_parent * multiplier * (1/8)

For fractional-divider, there are 2 fields of a register are used which
- A field for numerator
- A field for denominator
Freq_out = Freq_parent * numerator / denominator

Ok so the difference is that the denominator is a fixed value? Perhaps that can be modeled as a clk-multiplier that is used as the only parent of a fixed divider? Or we can add a flag to the clk-fractional-divider code to handle this minor difference.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
author
#4 lore raw

Hi Stephen,

Quoted 15 lines · Stephen Boyd

Sorry I replied offlist before. Pressed the wrong key.

Quoted 12 lines · Hoan Tran
Quoted 3 lines · Stephen Boyd

How is this different from clk-fractional-divider.c?

This is a driver which clock output is multiplied with a fixed fractional scale (denominator).
A field inside a register is used to configure the multiplier.

Example: With fractional scale is 1/8.
Freq_out = Freq_parent * multiplier * (1/8)

Quoted 7 lines
Quoted 5 lines

For fractional-divider, there are 2 fields of a register are used which
- A field for numerator
- A field for denominator
Freq_out = Freq_parent * numerator / denominator

Ok so the difference is that the denominator is a fixed value?

The major difference is a fixed denominator.
Another difference is:
In case CLK_FRACTIONAL_SCALE_INVERTED=1, the freq_out is calculated as below

Freq_out = Freq_parent * (fixed_denominator - multiplier) / fixed_denominator.

Quoted 2 lines

Perhaps that can be modeled as a clk-multiplier that is used as the only parent of a fixed divider?

Because of CLK_FRACTIONAL_SCALE_INVERTED flag, I don't know how to model as a clk-multiplier. And how to pass the fixed denominator into a clk-multiplier.

Quoted 2 lines

Or we can add a flag to the
clk-fractional-divider code to handle this minor difference.

This driver is used 2 register fields for numerator, denominator and calculates both of them.
Do you think I can integrate this fractional scale into it ?

Thanks
Hoan

Quoted 4 lines

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

author
#5 lore raw
Quoted 43 lines · Hoan Tran

Hi Stephen,

Quoted 15 lines · Stephen Boyd

Sorry I replied offlist before. Pressed the wrong key.

Quoted 12 lines · Hoan Tran
Quoted 3 lines · Stephen Boyd

How is this different from clk-fractional-divider.c?

This is a driver which clock output is multiplied with a fixed fractional scale (denominator).
A field inside a register is used to configure the multiplier.

Example: With fractional scale is 1/8.
Freq_out = Freq_parent * multiplier * (1/8)

Quoted 7 lines
Quoted 5 lines

For fractional-divider, there are 2 fields of a register are used which
- A field for numerator
- A field for denominator
Freq_out = Freq_parent * numerator / denominator

Ok so the difference is that the denominator is a fixed value?

The major difference is a fixed denominator.
Another difference is:
In case CLK_FRACTIONAL_SCALE_INVERTED=1, the freq_out is calculated as below

Freq_out = Freq_parent * (fixed_denominator - multiplier) / fixed_denominator.

Quoted 2 lines

Perhaps that can be modeled as a clk-multiplier that is used as the only parent of a fixed divider?

Because of CLK_FRACTIONAL_SCALE_INVERTED flag, I don't know how to model as a clk-multiplier. And how to pass the fixed denominator into a clk-multiplier.

Quoted 2 lines

Or we can add a flag to the
clk-fractional-divider code to handle this minor difference.

Quoted 7 lines

This driver is used 2 register fields for numerator, denominator and calculates both of them.
Do you think I can integrate this fractional scale into it ?

Thanks
Hoan

Hi Stephen,

Do you have any comments ?

Thanks
Hoan

Quoted 5 lines
Quoted 5 lines

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

author
#6 lore raw
Quoted 52 lines · Hoan Tran
Quoted 43 lines · Hoan Tran

Hi Stephen,

Quoted 15 lines · Stephen Boyd

Sorry I replied offlist before. Pressed the wrong key.

Quoted 12 lines · Hoan Tran
Quoted 3 lines · Stephen Boyd

How is this different from clk-fractional-divider.c?

This is a driver which clock output is multiplied with a fixed fractional scale (denominator).
A field inside a register is used to configure the multiplier.

Example: With fractional scale is 1/8.
Freq_out = Freq_parent * multiplier * (1/8)

Quoted 7 lines
Quoted 5 lines

For fractional-divider, there are 2 fields of a register are used which
- A field for numerator
- A field for denominator
Freq_out = Freq_parent * numerator / denominator

Ok so the difference is that the denominator is a fixed value?

The major difference is a fixed denominator.
Another difference is:
In case CLK_FRACTIONAL_SCALE_INVERTED=1, the freq_out is calculated as below

Freq_out = Freq_parent * (fixed_denominator - multiplier) / fixed_denominator.

Quoted 2 lines

Perhaps that can be modeled as a clk-multiplier that is used as the only parent of a fixed divider?

Because of CLK_FRACTIONAL_SCALE_INVERTED flag, I don't know how to model as a clk-multiplier. And how to pass the fixed denominator into a clk-multiplier.

Quoted 2 lines

Or we can add a flag to the
clk-fractional-divider code to handle this minor difference.

Quoted 7 lines

This driver is used 2 register fields for numerator, denominator and calculates both of them.
Do you think I can integrate this fractional scale into it ?

Thanks
Hoan

Quoted 13 lines

Hi Stephen,

Do you have any comments ?

Thanks
Hoan

Quoted 5 lines
Quoted 5 lines

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

Hi Stephen,

Do you have any comments or suggestions on this patch ?

Thanks
Hoan

#7 lore raw

Sorry I was away for some time.

Quoted 33 lines · Hoan Tran
Quoted 32 lines · Hoan Tran
Quoted 31 lines · Hoan Tran

Hi Stephen,

Quoted 15 lines · Stephen Boyd

Sorry I replied offlist before. Pressed the wrong key.

Quoted 12 lines · Hoan Tran
Quoted 3 lines · Stephen Boyd

How is this different from clk-fractional-divider.c?

This is a driver which clock output is multiplied with a fixed fractional scale (denominator).
A field inside a register is used to configure the multiplier.

Example: With fractional scale is 1/8.
Freq_out = Freq_parent * multiplier * (1/8)

Quoted 7 lines
Quoted 5 lines

For fractional-divider, there are 2 fields of a register are used which
- A field for numerator
- A field for denominator
Freq_out = Freq_parent * numerator / denominator

Ok so the difference is that the denominator is a fixed value?

The major difference is a fixed denominator.
Another difference is:
In case CLK_FRACTIONAL_SCALE_INVERTED=1, the freq_out is calculated as below

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Freq_out = Freq_parent * (fixed_denominator - multiplier) / fixed_denominator.

Quoted 2 lines

Perhaps that can be modeled as a clk-multiplier that is used as the only parent of a fixed divider?

Because of CLK_FRACTIONAL_SCALE_INVERTED flag, I don't know how to model as a clk-multiplier. And how to pass the fixed denominator into a clk-multiplier.

Would it be possible to add a flag to clk-multiplier to handle the inverted case? I haven't seen anyone else with hardware like that though, so perhaps the implementation should just go into the vendor specific clk driver instead of being written as a "basic clk type".

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
author
#8 lore raw
Quoted 45 lines · Stephen Boyd

Sorry I was away for some time.

Quoted 33 lines · Hoan Tran
Quoted 32 lines · Hoan Tran
Quoted 31 lines · Hoan Tran

Hi Stephen,

Quoted 15 lines · Stephen Boyd

Sorry I replied offlist before. Pressed the wrong key.

Quoted 12 lines · Hoan Tran
Quoted 3 lines · Stephen Boyd

How is this different from clk-fractional-divider.c?

This is a driver which clock output is multiplied with a fixed fractional scale (denominator).
A field inside a register is used to configure the multiplier.

Example: With fractional scale is 1/8.
Freq_out = Freq_parent * multiplier * (1/8)

Quoted 7 lines
Quoted 5 lines

For fractional-divider, there are 2 fields of a register are used which
- A field for numerator
- A field for denominator
Freq_out = Freq_parent * numerator / denominator

Ok so the difference is that the denominator is a fixed value?

The major difference is a fixed denominator.
Another difference is:
In case CLK_FRACTIONAL_SCALE_INVERTED=1, the freq_out is calculated as below

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Freq_out = Freq_parent * (fixed_denominator - multiplier) / fixed_denominator.

Quoted 2 lines

Perhaps that can be modeled as a clk-multiplier that is used as the only parent of a fixed divider?

Because of CLK_FRACTIONAL_SCALE_INVERTED flag, I don't know how to model as a clk-multiplier. And how to pass the fixed denominator into a clk-multiplier.

Quoted 5 lines

Would it be possible to add a flag to clk-multiplier to handle the inverted case? I haven't seen anyone else with hardware like that though, so perhaps the implementation should just go into the vendor specific clk driver instead of being written as a "basic clk type".

Yes, I'll move it into our clk-xgene driver.

Thanks
Hoan

Quoted 4 lines

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project