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

soc: silabs: Initialize oscillators and clock tree from DT, clean up init sequence #79415

Merged

Conversation

asmellby
Copy link
Contributor

@asmellby asmellby commented Oct 4, 2024

This PR cleans up the Series 2 init sequence by

  • Unifying all Series 2 devices on using the device init HAL (adding EFR32MG21, all the others already used it)
    • DCDC is added to DeviceTree to be able to only initialize it if present
  • Migrating oscillator init from device init HAL to clock manager HAL based on DT
  • Migrating clock tree init from ad hoc board and driver config to clock manager HAL based on DT
  • Separating soc.c for Series 2 from Series 0 and 1, since the init sequence is fully disjoint

@zephyrbot
Copy link
Collaborator

zephyrbot commented Oct 4, 2024

The following west manifest projects have been modified in this Pull Request:

Name Old Revision New Revision Diff
hal_silabs zephyrproject-rtos/hal_silabs@d07d744 zephyrproject-rtos/hal_silabs@5c7a783 (main) zephyrproject-rtos/hal_silabs@d07d744a..5c7a7834

Note: This message is automatically posted and updated by the Manifest GitHub Action.


silabs,pfmx-peak-current-microamp:
type: int
description: Peak current draw in PFMX mode.
Copy link
Contributor

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
*/
Copy link
Contributor

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
Copy link
Contributor

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>;
Copy link
Contributor

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>
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

So good!

#ifdef CONFIG_PM
#include <sl_hfxo_manager.h>
#include <sl_power_manager.h>
#endif
Copy link
Contributor

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.

#ifdef CONFIG_PM
sl_power_manager_init();
sl_hfxo_manager_init();
#endif
Copy link
Contributor

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.


#if CONFIG_HW_HAS_SILABS_DCDC
sl_device_init_dcdc();
#endif
Copy link
Contributor

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 */
Copy link
Member

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.

Comment on lines 39 to 40
description: |
Output voltage for boost mode. Not used in buck mode.
Copy link
Member

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:
Copy link
Member

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

Copy link
Contributor Author

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.

Comment on lines 13 to 14
config HW_HAS_SILABS_DCDC
def_bool $(dt_compat_enabled,$(DT_COMPAT_SILABS_SERIES2_DCDC))
Copy link
Member

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

Copy link
Contributor Author

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>
Copy link
Member

Choose a reason for hiding this comment

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

no soc.h please

Comment on lines 22 to 37
#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)
Copy link
Member

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.

Comment on lines 43 to 47
(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) \
Copy link
Member

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
Copy link
Member

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

clocks {
clk_hfxo: clk-hfxo {
#clock-cells = <0>;
compatible = "silabs,hfxo";
Copy link
Member

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.

@asmellby asmellby force-pushed the feature/series2-init-cleanup branch from 45e1fab to f8e8e43 Compare October 9, 2024 14:25
@zephyrbot zephyrbot added the platform: Silabs SiM3U Silicon Labs SiM3U label Oct 9, 2024
jerome-pouiller
jerome-pouiller previously approved these changes Oct 9, 2024
Copy link
Contributor

@jerome-pouiller jerome-pouiller left a 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.
Copy link
Contributor

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.
Copy link
Contributor

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").

@asmellby
Copy link
Contributor Author

@gmarull Is my latest change what you had in mind? CMakeLists.txt will be updated to avoid referring to modules/hal_silabs from inside soc/ in the follow-on PR that introduces cmake-ext for hal_silabs.

@asmellby
Copy link
Contributor Author

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>
@asmellby asmellby added the DNM This PR should not be merged (Do Not Merge) label Oct 22, 2024
@asmellby
Copy link
Contributor Author

Rebased on top of @jhedberg's change in #80148, adding DNM label until his PR is merged.

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>
@zephyrbot zephyrbot removed the DNM This PR should not be merged (Do Not Merge) label Oct 22, 2024
@henrikbrixandersen henrikbrixandersen merged commit a11f0e6 into zephyrproject-rtos:main Oct 22, 2024
32 of 33 checks passed
Copy link
Contributor

@rettichschnidi rettichschnidi left a 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 👍

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.

8 participants