Skip to contentSkip to conversation

Common/typical fractional divider HW API

DISCUSSION Mason 2 participants 8 messages Feb 5, 2016 – Feb 15, 2016 Common clk

lore
Share & tools
lore

Mason

author
#0 lore raw

Hello,

AFAICT, the clk-fractional-divider driver implements the following hardware API:

M and N are two fields in the same register.
DIV = M / N

Is this HW API common/typical in the embedded world? in the PC world?

My hardware uses a slightly weird (to me) API:

I = 0-255 (8 bits)
F = 0-15 (4 bits)

I = 0 => DIV = +INF
I = 1 => DIV = 1 + F/(32-F)
I > 1 => DIV = I + F/16

Is this HW API common/typical in the embedded world? (Perhaps just the linear part for I > 1)

I see two downsides to this API:

1) I = 1 is a special case
2) A lot of the value space is wasted on large values.

For example, when I = 250, we don't really care about 250.0625, 250.125, etc, or even nearby integer values, for that matter.

I think it's better to have a distribution with high density in small values, and low density in high values (sort of like floating point).

For example:

I = 0-15 (4 bits)
F = 0-255 (8 bits)
DIV = 2^I * (1 + F/256)

(We could probably even shave 2-4 bits on F.)

Are there downsides to this HW API?
Is this HW API common/typical in the embedded world?

Regards.

#1 lore raw
Quoted 11 lines · Mason

Hello,

AFAICT, the clk-fractional-divider driver implements the following hardware API:

? M and N are two fields in the same register.
? DIV = M / N

Is this HW API common/typical in the embedded world? in the PC world?

At least all new Intel SoCs have it, besides that there is one more user of the struct clk_fractional_divider, but I have no idea if they have something similar to this.

Quoted 5 lines

My hardware uses a slightly weird (to me) API:

? I = 0-255 (8 bits)
? F = 0-15??(4 bits)

This part is okay.

Quoted 2 lines

? I = 0 => DIV = +INF

On Intel we recognize this as an absence of the divider.

Quoted 1 line

? I = 1 => DIV = 1 + F/(32-F)

Weird part, indeed. But seems it doubles a precision in a range [1 .. 1 + 1/2]

Quoted 1 line

? I > 1 => DIV = I + F/16

This just normal operation.

Quoted 3 lines

Is this HW API common/typical in the embedded world? (Perhaps just the linear part for I > 1)

I saw similar approach in few UART drivers, but they do not use CLK framework.

So, I could consider this one is more popular / wider, than what we have in Intel SoCs.

Quoted 16 lines

I see two downsides to this API:

1) I = 1 is a special case

2) A lot of the value space is wasted on large values.

For example, when I = 250, we don't really care about 250.0625, 250.125,
etc, or even nearby integer values, for that matter.

I think it's better to have a distribution with high density in small values, and low density in high values (sort of like floating point).

For example:

Quoted 8 lines

? I = 0-15??(4 bits)
? F = 0-255 (8 bits)
? DIV = 2^I * (1 + F/256)

(We could probably even shave 2-4 bits on F.)

Are there downsides to this HW API?
Is this HW API common/typical in the embedded world?

So, what is your intention? If you would like to use CLK framework you might consider existing providers and users and might implement a specific one for similar cases.

Also it's possible to convert clock providers for, e.g., UARTs to use this kind of divider.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
author
#2 lore raw
Quoted 63 lines · Andy Shevchenko
Quoted 8 lines · Mason

AFAICT, the clk-fractional-divider driver implements the following hardware API:

M and N are two fields in the same register.
DIV = M / N

Is this HW API common/typical in the embedded world? in the PC world?

At least all new Intel SoCs have it, besides that there is one more user of the struct clk_fractional_divider, but I have no idea if they have something similar to this.

Quoted 4 lines

My hardware uses a slightly weird (to me) API:

I = 0-255 (8 bits)
F = 0-15 (4 bits)

This part is okay.

Quoted 1 line

I = 0 => DIV = +INF

On Intel we recognize this as an absence of the divider.

Quoted 1 line

I = 1 => DIV = 1 + F/(32-F)

Weird part, indeed. But seems it doubles a precision in a range [1 .. 1 + 1/2]

Quoted 1 line

I > 1 => DIV = I + F/16

This just normal operation.

Quoted 2 lines

Is this HW API common/typical in the embedded world? (Perhaps just the linear part for I > 1)

I saw similar approach in few UART drivers, but they do not use CLK framework.

So, I could consider this one is more popular / wider, than what we have in Intel SoCs.

Quoted 19 lines

I see two downsides to this API:

1) I = 1 is a special case

2) A lot of the value space is wasted on large values.

For example, when I = 250, we don't really care about 250.0625, 250.125,
etc, or even nearby integer values, for that matter.

I think it's better to have a distribution with high density in small values, and low density in high values (sort of like floating point).

For example:

I = 0-15 (4 bits)
F = 0-255 (8 bits)
DIV = 2^I * (1 + F/256)

Quoted 8 lines
Quoted 4 lines

(We could probably even shave 2-4 bits on F.)

Are there downsides to this HW API?
Is this HW API common/typical in the embedded world?

So, what is your intention? If you would like to use CLK framework you might consider existing providers and users and might implement a specific one for similar cases.

Right now, I'm using the clk-divider driver (integer divider).
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/clk/clk-tango4.c

I was trying to avoid writing any code, but it looks like I would need a specific driver if I want to support the hardware's fractional divider logic.

Once I started looking at the HW API, I was thinking that it could be improved (and perhaps the HW engineers would agree to make the change) but I wanted to get feedback from seasoned devs with respect to the proposed HW API.

So, do you agree that

DIV = 2^I * (1 + F/256)

gives a more useful DIV distribution than

DIV = I + F/16

Quoted 2 lines

Also it's possible to convert clock providers for, e.g., UARTs to use this kind of divider.

I'm not sure how to parse that. I'm using the divider driver for a CPU clock, to do D(V)FS in cpufreq.

Regards.

#3 lore raw
Quoted 7 lines · Mason

So, do you agree that

? DIV = 2^I * (1 + F/256)

gives a more useful DIV distribution than

? DIV = I + F/16

If you can change hardware why not to use any existing approach which suits better to your device?

I don't remember any existing, though I didn't check much, divider register which takes something like that.

Quoted 6 lines
Quoted 3 lines

Also it's possible to convert clock providers for, e.g., UARTs to use
this kind of divider.

I'm not sure how to parse that. I'm using the divider driver for a CPU clock, to do D(V)FS in cpufreq.

If you are using custom stuff for custom hardware, I hope it's okay. But if we are talking about generic solutions (like clk-fractional- divider), I would suggest to consider existing users / hardware.

What I saw is mostly about

I [0 .. 2^n - 1]
F [0 .. 2^k - 1]
n + k < 32

And I + 1 / (2^k - F) as a formula.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
author
#4 lore raw
Quoted 4 lines · Andy Shevchenko
Quoted 2 lines · Mason

So, do you agree that

Quoted 8 lines
Quoted 5 lines

DIV = 2^I * (1 + F/256)

gives a more useful DIV distribution than

DIV = I + F/16

If you can change hardware why not to use any existing approach which suits better to your device?

Sorry, I don't understand the question.

In this part of my message, I was trying to argue that one HW API "2^I * (1 + F/256)" seemed better than another one "I + F/16" on any hardware.

Quoted 2 lines

I don't remember any existing, though I didn't check much, divider register which takes something like that.

IIUC, you are saying that you've never seen hardware use the "2^I * (1 + F/256)" formula, is that correct?

Quoted 6 lines
Quoted 2 lines

I'm not sure how to parse that. I'm using the divider driver for a CPU clock, to do D(V)FS in cpufreq.

If you are using custom stuff for custom hardware, I hope it's okay. But if we are talking about generic solutions (like clk-fractional- divider), I would suggest to consider existing users / hardware.

Are you saying that I could use the clk-fractional-divider with hardware that computes "I + F/16" ?

Maybe the clk-fractional-divider could be made more generic by having the register update part done in a call-back function?

Regards.

#5 lore raw
Quoted 10 lines · Mason
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Mason

So, do you agree that

? DIV = 2^I * (1 + F/256)

gives a more useful DIV distribution than

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

? DIV = I + F/16

If you can change hardware why not to use any existing approach which
suits better to your device?

Sorry, I don't understand the question.

There are plenty of implementations of the divider. You might consider to use one than inventing new one:

https://xkcd.com/927/

Quoted 3 lines

In this part of my message, I was trying to argue that one HW API "2^I * (1 + F/256)" seemed better than another one "I + F/16" on any hardware.

I disagree in a part 2^I.

Quoted 6 lines
Quoted 3 lines

I don't remember any existing, though I didn't check much, divider register which takes something like that.

IIUC, you are saying that you've never seen hardware use the "2^I * (1 + F/256)" formula, is that correct?

Yep, though it doesn't mean there is no such.

Quoted 10 lines

I'm not sure how to parse that. I'm using the divider driver

Quoted 6 lines
Quoted 1 line

for a CPU clock, to do D(V)FS in cpufreq.

If you are using custom stuff for custom hardware, I hope it's okay.
But if we are talking about generic solutions (like clk-fractional- divider), I would suggest to consider existing users / hardware.

Are you saying that I could use the clk-fractional-divider with hardware that computes "I + F/16" ?

No.

Quoted 2 lines

Maybe the clk-fractional-divider could be made more generic by having the register update part done in a call-back function?

Why do you need to touch that module at all if your hardware doesn't suit it?

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
author
#6 lore raw
Quoted 1 line · Andy Shevchenko

There are plenty of implementations of the divider.

I'd be happy to read an overview on the subject, if you have some links to share.

Quoted 1 line

You might consider to use one than inventing new one

I find it hard to believe that the interface I'm discussing has not been used (several times) in the past. (It's merely a trivial floating point scheme.)

As a matter of fact, the integer divider driver supports "I" and "2^I", so extending 2^I to "2^I * (1 + F/256)" is an obvious step.

Quoted 5 lines
Quoted 3 lines

In this part of my message, I was trying to argue that one HW API "2^I * (1 + F/256)" seemed better than another one "I + F/16" on any hardware.

I disagree in a part 2^I.

I don't know what that means. If you speak Russian, maybe you can write in Russian, and I'll try to figure it out.

Quoted 5 lines
Quoted 2 lines

Maybe the clk-fractional-divider could be made more generic by having the register update part done in a call-back function?

Why do you need to touch that module at all if your hardware doesn't suit it?

What does it mean "your hardware doesn't suit it" ?

I am saying that if the register update were moved into a call-back function, then any scheme could be supported. Maybe you think this is just vague hand-waving. I'll send a patch to illustrate what I'm saying.

Regards.

#7 lore raw
Quoted 6 lines · Mason
Quoted 1 line · Andy Shevchenko

There are plenty of implementations of the divider.

I'd be happy to read an overview on the subject, if you have some links to share.

drivers/tty/serial/*

Quoted 10 lines
Quoted 2 lines

You might consider to use one than inventing new one

I find it hard to believe that the interface I'm discussing has not been used (several times) in the past. (It's merely a trivial floating point scheme.)

As a matter of fact, the integer divider driver supports "I" and "2^I", so extending 2^I to "2^I * (1 + F/256)" is an obvious step.

Just to be simple:
Why do you have to modify existing clk-fractional-divider.c module?

May I suggest to reconsider your design to be fit in the existing CLK divider implementations? Also, some of the hardware IPs have inside divider registers, like mentioned above UARTs. I already suggested to look at them to see how hardware is done.

Again, (actually I bored to repeat) I didn't see (yet!) any HW divider which has integer part as 2^I. I don't get why you stuck with that formula and why 1/256? Who prevents to have 1/32768 in HW (like we have in LPSS of Intel SoCs)?

Here I'm giving up this discussion. Perhaps more experienced people could correct me.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy