-
Notifications
You must be signed in to change notification settings - Fork 8.4k
drivers: rcc: Improve the RCC definition for the sf32lb platform #99542
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
Conversation
989c861 to
4e1673d
Compare
4e1673d to
bebd11b
Compare
fix typo and commit format, also rebase and resovle conflicts. |
gmarull
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job on extending this, see my comments
| requires the corresponding DLL child node to be enabled. Defaults to | ||
| ``peri`` if not provided. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaults need to be justified (e.g. boot time default) per bindings rules
| requires the corresponding DLL child node to be enabled. Defaults to | ||
| ``peri`` if not provided. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
| Source used for the HPSYS peripheral clock domain. Defaults to ``hxt48`` if | ||
| not provided. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, default actually not set
| enum: ["hrc48", "hxt48", "lpclk", "dll1"] | ||
| description: | | ||
| Source used for the HPSYS system clock. When set to ``dll1`` the DLL1 child | ||
| node must be enabled. Defaults to ``hxt48`` if not provided. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, default not set?
| Divider applied to the selected USB clock source. The divided clock must | ||
| be 60 MHz. For example, when ``clk_dll2`` runs at 240 MHz the divider must | ||
| be ``4``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default should not be set if its value depends on how other things are configured.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, why isn't this computed automatically if target clock freq is known?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. all settings have been assigned default values and corresponding descriptions.
| enum sf32lb_sys_clk_idx { | ||
| SF32LB_SYS_CLK_IDX_HRC48, | ||
| SF32LB_SYS_CLK_IDX_HXT48, | ||
| SF32LB_SYS_CLK_IDX_LPCLK, | ||
| SF32LB_SYS_CLK_IDX_DLL1, | ||
| }; | ||
|
|
||
| enum sf32lb_peri_clk_idx { | ||
| SF32LB_PERI_CLK_IDX_HRC48, | ||
| SF32LB_PERI_CLK_IDX_HXT48, | ||
| }; | ||
|
|
||
| enum sf32lb_mpi_clk_idx { | ||
| SF32LB_MPI_CLK_IDX_DLL1, | ||
| SF32LB_MPI_CLK_IDX_DLL2, | ||
| SF32LB_MPI_CLK_IDX_PERI, | ||
| }; | ||
|
|
||
| enum sf32lb_usb_clk_idx { | ||
| SF32LB_USB_CLK_IDX_SYSCLK, | ||
| SF32LB_USB_CLK_IDX_DLL2, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this seems to mimic DT enums, you may consider using this approach (so everything resides on a DT header): https://wiki.st.com/stm32mpu/wiki/Clock_device_tree_configuration (ref st,clksrc). I think it's better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a slightly different perspective on this matter... While listing all data in the header file does significantly simplify the driver code, it makes editing the device tree less intuitive and prone to errors (such as misconfiguring the corresponding macro definitions).
Is there a recommended best practice for handling this scenario in Zephyr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think there’s really a standard here, but it’s a common thing to look into other projects using devicetree to see how they have solved the same or similar problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After internal discussion, we concluded that using strings as enumerations would be preferable
I adjusted the order of the enumeration values so that each enum matches the final register setting value, making the driver code easier to read
0ad0230 to
ecd0f69
Compare
Add the RCC configuration binding on the sf32lb52 platform. - sys-clk-src - peri-clk-src - mpi1/2-clk-src - A - usb-div Signed-off-by: Haoran Jiang <halfsweet@halfsweet.cn>
ecd0f69 to
e969966
Compare
Add RCC configuration driver. Signed-off-by: Haoran Jiang <halfsweet@halfsweet.cn>
Add sys-clk-src. Signed-off-by: Haoran Jiang <halfsweet@halfsweet.cn>
e969966 to
e10be0c
Compare
|
| Divider applied to the selected USB clock source. The divided clock must | ||
| be 60 MHz. For example, when ``clk_dll2`` runs at 240 MHz the divider must | ||
| be ``4`` (reset default). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as said, providing default here may not be ideal if clk_dll2 is configured to other frequencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calculating the USB clock source and frequency division during compilation in C is simply too complex. Perhaps the correct allocation of the clock tree should be ensured by the person writing the device tree—when they enable the USB module, the corresponding frequency division should already be calculated. Of course, if it's not enabled, nothing happens. The default value of 4 here is merely because that's the default value after startup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough




Improve the RCC definition for the sf32lb platform.
All RCC configurations in sf32lb have been completed, with the following additions: