-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
soc: silabs: Initialize oscillators and clock tree from DT, clean up init sequence #79415
soc: silabs: Initialize oscillators and clock tree from DT, clean up init sequence #79415
Conversation
The following west manifest projects have been modified in this Pull Request:
Note: This message is automatically posted and updated by the Manifest GitHub Action. |
2611b2f
to
603fede
Compare
603fede
to
45e1fab
Compare
|
||
silabs,pfmx-peak-current-microamp: | ||
type: int | ||
description: Peak current draw in PFMX mode. |
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 suggest to expand PFMX
acronym here.
* Copyright (c) 2024 Silicon Laboratories Inc. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ |
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.
If I understand right, this file is implicitly consumed by sl_device_init_dcdc()
. Maybe you could add a comment explaining that.
That's said, I believe this file is not in the spirit of Zephyr. I feel we should create a new driver. This driver could directly call EMU_DCDCInit()
, EMU_DCDCSetPFMXModePeakCurrent()
, EMU_DCDCPowerOff()
and EMU_DCDCBoostInit()
. So, we could get rid of this layer of translation between DT and SL_DEVICE_INIT_DCDC_*
definitions.
description: | | ||
Operating mode. Allowed values are: | ||
- 0: buck mode | ||
- 1: boost mode |
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.
We could introduce symbols for that (see include/zephyr/dt-bindings/regulator/nrf5x.h
)
(not a big deal)
@@ -60,13 +60,55 @@ | |||
}; | |||
|
|||
&cpu0 { | |||
clock-frequency = <39000000>; | |||
clock-frequency = <78000000>; |
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.
Doesn't this change be placed in the previous commit?
#define SL_CLOCK_MANAGER_OSCILLATOR_CONFIG_H | ||
|
||
#include <zephyr/devicetree.h> | ||
#include <soc.h> |
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 the same comment than with DC-DC. I believe we should add a driver and directly call the inner functions.
However, after I have seen the upstream file (sl_clock_manager_init_hal_s2.c
), I don't exactly if it is possible to do a proper integration. Maybe we should with upstream on this file.
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.
So good!
soc/silabs/silabs_s2/soc.c
Outdated
#ifdef CONFIG_PM | ||
#include <sl_hfxo_manager.h> | ||
#include <sl_power_manager.h> | ||
#endif |
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.
Probably it does not hurt to include sl_hfxo_manager.h
and sl_power_manager.h
even if !CONFIG_PM
.
soc/silabs/silabs_s2/soc.c
Outdated
#ifdef CONFIG_PM | ||
sl_power_manager_init(); | ||
sl_hfxo_manager_init(); | ||
#endif |
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.
If you include sl_hfxo_manager.h
and sl_power_manager.h
unconditionally, you can change the #ifdef CONFIG_PM
in if (IS_ENABLED(CONFIG_PM))
and make the code easier.
soc/silabs/silabs_s2/soc.c
Outdated
|
||
#if CONFIG_HW_HAS_SILABS_DCDC | ||
sl_device_init_dcdc(); | ||
#endif |
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 suggest:
if (IS_ENABLED(CONFIG_HW_HAS_SILABS_DCDC)) {
sl_device_init_dcdc();
}
&dcdc { | ||
status = "okay"; | ||
regulator-boot-on; | ||
regulator-initial-mode = <0>; /* buck */ |
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.
please, provide mode definitions to make DT readable, /* buck */
comment proofs it is not right now.
description: | | ||
Output voltage for boost mode. Not used in buck mode. |
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.
no descriptions in standard properties please
- 2300000 | ||
- 2400000 | ||
|
||
silabs,pfmx-peak-current-microamp: |
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.
why not milliamps? all values have a x1000 scale factor
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 used microamp for symmetry with the standard regulator properties regulator-*-microamp
. I agree that the scale factor of 1000 is silly, and if milliamp is OK, I will change to it.
soc/silabs/silabs_s2/Kconfig
Outdated
config HW_HAS_SILABS_DCDC | ||
def_bool $(dt_compat_enabled,$(DT_COMPAT_SILABS_SERIES2_DCDC)) |
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.
please avoid these redundant Kconfig options and just use DT natively in C code
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 had been pointed to https://github.com/zephyrproject-rtos/zephyr/blob/main/soc/nordic/common/Kconfig.peripherals in the past, but if this is a pattern that we don't want to propagate, and just use DT directly instead, that is completely fine by me :)
#define SL_DEVICE_INIT_DCDC_CONFIG_H | ||
|
||
#include <zephyr/devicetree.h> | ||
#include <soc.h> |
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.
no soc.h please
#define SL_DEVICE_INIT_DCDC_BOOST_OUTPUT \ | ||
(DT_ENUM_HAS_VALUE(DCDC_NODE, regulator_init_microvolt, 1800000) \ | ||
? emuDcdcBoostOutputVoltage_1v8 \ | ||
: DT_ENUM_HAS_VALUE(DCDC_NODE, regulator_init_microvolt, 1900000) \ | ||
? emuDcdcBoostOutputVoltage_1v9 \ | ||
: DT_ENUM_HAS_VALUE(DCDC_NODE, regulator_init_microvolt, 2000000) \ | ||
? emuDcdcBoostOutputVoltage_2v0 \ | ||
: DT_ENUM_HAS_VALUE(DCDC_NODE, regulator_init_microvolt, 2100000) \ | ||
? emuDcdcBoostOutputVoltage_2v1 \ | ||
: DT_ENUM_HAS_VALUE(DCDC_NODE, regulator_init_microvolt, 2200000) \ | ||
? emuDcdcBoostOutputVoltage_2v2 \ | ||
: DT_ENUM_HAS_VALUE(DCDC_NODE, regulator_init_microvolt, 2300000) \ | ||
? emuDcdcBoostOutputVoltage_2v3 \ | ||
: DT_ENUM_HAS_VALUE(DCDC_NODE, regulator_init_microvolt, 2400000) \ | ||
? emuDcdcBoostOutputVoltage_2v4 \ | ||
: emuDcdcBoostOutputVoltage_1v8) |
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.
aren't enums correlated to voltages so that something like linear range can be used? This looks seriously ugly.
(DT_ENUM_HAS_VALUE(DCDC_NODE, silabs_pfmx_peak_current_microamp, 50000) \ | ||
? DCDC_PFMXCTRL_IPKVAL_LOAD50MA \ | ||
: DT_ENUM_HAS_VALUE(DCDC_NODE, silabs_pfmx_peak_current_microamp, 65000) \ | ||
? DCDC_PFMXCTRL_IPKVAL_LOAD65MA \ | ||
: DT_ENUM_HAS_VALUE(DCDC_NODE, silabs_pfmx_peak_current_microamp, 73000) \ |
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
@@ -5,6 +5,5 @@ CONFIG_CONSOLE=y | |||
CONFIG_UART_CONSOLE=y | |||
CONFIG_SERIAL=y | |||
CONFIG_GPIO=y | |||
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=38400000 | |||
CONFIG_CMU_HFCLK_HFXO=y | |||
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=76800000 |
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.
this setting should be grabbed from DT, see other examples in tree
dts/arm/silabs/efr32mg21.dtsi
Outdated
clocks { | ||
clk_hfxo: clk-hfxo { | ||
#clock-cells = <0>; | ||
compatible = "silabs,hfxo"; |
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.
is this device addressable? if so, it should have a @reg
.
45e1fab
to
f8e8e43
Compare
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 still have some concerns with use of config/sl_*_config.h
. I believe we should work on a long term fix for these files. However, we can probably live with that for now.
That's said, I am happy to see much ugly code disappeared with this PR :-).
compatible: "silabs,series2-lfrco" | ||
|
||
description: | | ||
Silicon Labs LFRCO peripheral. |
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.
Help messages are the right place to expand acronyms (in many case it provide a sufficient documentation).
mode: | ||
type: string | ||
description: | | ||
HFXO mode. Defaults to "xtal", expecting a 32768 Hz crystal oscillator on XI and XO pins. |
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.
HFXO? (BTW, you can probably get rid of this description. "LFXO mode" is not very helpful when the attribute is named "mode" and the device "LFXO").
f8e8e43
to
17569f1
Compare
@gmarull Is my latest change what you had in mind? CMakeLists.txt will be updated to avoid referring to |
eff9265
to
2eaa3d0
Compare
Rebased on top of latest main to resolve conflict. |
Move the CMakeLists.txt and Kconfig files from the hal_silabs tree under modules/hal_silabs in the main tree. This also includes all Zephyr shim code from the hal_silabs tree. Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2eaa3d0
to
6ededac
Compare
The DC-DC converter was unconditionally initialized with default settings on Series 2. Add device tree binding and nodes, and guard call to init function. Map DT options to config header from HAL. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Defconfig was only available at the vendor and series level, make it possible to have family specific definitions too. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
On Series 2, set the SYS_CLOCK_HW_CYCLES_PER_SEC Kconfig option from DeviceTree, rather than separately configuring it in board-level defconfig. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Switch EFR32MG21 to use the device init HAL. This makes the init sequence the same as the rest of Series 2. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Introduce bindings for Series 2 oscillators: HFRCODPLL, HFRCOEM23, LFRCO and LFXO. Add clock tree representation in devicetree `clocks` node. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Swap from the deprecated device_init_* functions to clock manager for clock tree configuration. Populate config headers using device tree representation of clock tree and oscillator config. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Clock setup is now done by the clock manager based on device tree configuration. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Clock setup is now done by the clock manager based on device tree configuration. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Series 2 always uses the device init HAL, while Series 0/1 never do. Create a separate soc.c for Series 2 to make both versions easier to read. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
6ededac
to
144e17a
Compare
a11f0e6
into
zephyrproject-rtos:main
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.
Still works for the board sim3u1xx_dk
👍
This PR cleans up the Series 2 init sequence by