Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple system timer and drivers: I2C #15415

Conversation

pizi-nordic
Copy link
Collaborator

During our work in timer area, we found that system clock frequency is used incorrectly in several drivers.
For example, it is used to obtain bus frequency needed to calculate speed of I2C interfaces.
If we select different system timer device, all these calculations become invalid.

This PR fixes the problem by obtaining all needed information directly from the DTS.
Brings us closer to: #15363

Please note, that for I2C devices the clock-frequency property specifies SCK frequency, instead of frequency of the clock driving peripheral. To solve that problem, a new property was added.
(I used https://www.kernel.org/doc/Documentation/devicetree/bindings/i2c/i2c-ocores.txt as a reference)

Copy link
Member

@ioannisg ioannisg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, I don't disagree with the change (and in general with this kind of patches), I wonder if the "clock-frequency" is actually going to be "copied" in all DTS driver nodes, for each platform, e.g. SPIs, UARTs, etc.

If, so, I wonder if there a way to "get" the value of this clock-frequency, somehow, and not hard-code it in every peripheral node. I understand that different peripherals might have different clock sources, so until we have a proper clock management, this, all , might be hard, so I am just wondering.

@pizi-nordic
Copy link
Collaborator Author

We should have a "clock" node which references the clock source for the peripheral. But this needs both entries in DTS as well as better DTS infrastructure (ideally we should have something like DT_I2C_0_CLOCK_0_FREQUENCY extracted from clock node.).

@@ -18,6 +18,12 @@ properties:
generation: define
category: required

"cc32xx,clock-frequency" :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about naming it ip-clock-frequency? And consistently using IP_ also in the fixup label? DT_I2C_0_CLOCK_FREQUENCY looks like something generated for the clock-frequency property.

Copy link
Collaborator Author

@pizi-nordic pizi-nordic Apr 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem for me. Any other opinions/suggestions on that?

Copy link
Member

@carlescufi carlescufi Apr 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem with IP is that it really reminds of IP block, and this is not the case. So I would instead either:

  1. Go with <name>,clock-frequency
  2. Use something like <name>,hw-clock-frequency

@anangl @erwango @galak thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did something on sifive, looks like we used input-frequency. But I'm not keen on propagating that everywhere

@carlescufi
Copy link
Member

carlescufi commented Apr 17, 2019

We should have a "clock" node which references the clock source for the peripheral. But this needs both entries in DTS as well as better DTS infrastructure (ideally we should have something like DT_I2C_0_CLOCK_0_FREQUENCY extracted from clock node.).

I agree that this is the real solution, as shown in examples like this one:
https://www.kernel.org/doc/Documentation/devicetree/bindings/i2c/i2c-stm32.txt

In the meantime we can go with one of the options here

The i2c_cc32xx driver used system clock frequency
as a base for I2C clock frequency calculation.
This commit corrects that by obtaining the needed value from DTS.

Please note, that for I2C devices the clock-frequency property
specifies SCK frequency, instead of frequency of the clock driving
peripheral. To solve that problem, a new property was added.

Signed-off-by: Piotr Zięcik <[email protected]>
@pizi-nordic pizi-nordic force-pushed the decouple-system-timer-and-clock-i2c branch from 5ad9de5 to 6896de9 Compare April 24, 2019 11:15
Copy link
Collaborator

@galak galak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we doing this via DTS? Why isn't this some inline function?

"cc32xx,clock-frequency" :
type: int
category: required
description: Clock frequency the SPI peripheral is being driven at
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the description is wrong.

@@ -18,6 +18,12 @@ properties:
generation: define
category: required

"cc32xx,clock-frequency" :
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did something on sifive, looks like we used input-frequency. But I'm not keen on propagating that everywhere

@galak galak added the dev-review To be discussed in dev-review meeting label Apr 24, 2019
@nashif nashif removed dev-review To be discussed in dev-review meeting labels May 2, 2019
@galak
Copy link
Collaborator

galak commented May 2, 2019

@pizi-nordic was the thread of discussion about how to handle 'clock' vs 'clock-frequency' for i2c here or somewhere else?

@pizi-nordic
Copy link
Collaborator Author

@galak: Here: #15415 (comment).

@pizi-nordic pizi-nordic deleted the decouple-system-timer-and-clock-i2c branch May 29, 2019 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants