Skip to content

Conversation

@danieldegrasse
Copy link
Contributor

This PR should not be merged, and discussion should not occur here. It is a duplicate of #72102, so that I can get twister results before requesting someone at NXP push to the branch that PR is based from (since I no longer have push access to that repo)

@danieldegrasse danieldegrasse force-pushed the rfc/clock-mgmt-drivers branch 2 times, most recently from 5641389 to da4771e Compare April 29, 2025 13:55
danieldegrasse and others added 27 commits April 29, 2025 14:04
Generate macros needed to support Zephyr's clock management subsystem.
The following new macros will be generated to support clock management:
- {DT_NODE_ID}_SUPPORTS_CLK_ORDS: a comma separated list of DT ordinal
  numbers for clock nodes that a given DT node supports (generally the
  clock children for that node)
- {DT_NODE_ID}_CLOCK_OUTPUT_NAME_{NAME}_IDX: the index of a string
  within the `clock-output-names` property for a given node, used to
  access clock output phandles by their name
- {DT_NODE_ID}_CLOCK_STATE_NAME_{NAME}_IDX: the index of a string
  within the `clock-state-names` property for a given node, used to
  access clock state phandles by their name

Signed-off-by: Daniel DeGrasse <[email protected]>
The clock management subsystem references clock children via clock
handles, which work in a manner similar to device handles, but use
different section names (and only track clock children).
Add gen_clock_deps.py and update elf_parser.py to handle clock handles.

Update CMakeLists.txt to use a two stage link process when clock
management is enabled. gen_clock_deps.py will parse a list of clock
ordinals provided in the first link stage of the build, and replace
the weak symbol defining those ordinals with a strong symbol defining
the array of clock handles.

This approach is required for clock children because directly
referencing children via a pointer would result in all clock children
being linked into every build, and significantly increase the image
size. By only referencing children via clock handles, clocks that are
not needed for a specific build (IE not referenced by any clock
consumer) will be discarded during the link phase.

Signed-off-by: Daniel DeGrasse <[email protected]>
Define common clock management bindings for clock producer nodes and
clock consumer devices.

Signed-off-by: Daniel DeGrasse <[email protected]>
Add devicetree helpers for clock management support. These helpers
expose access to the new devicetree macros needed for the clock management
subsystem.

Also add testcases for these helpers to the devicetree lib test

Signed-off-by: Daniel DeGrasse <[email protected]>
Add clock model header, which describes macros for defining and
accessing clock objects within the clock driver layer of the clock
management subsystem.

Signed-off-by: Daniel DeGrasse <[email protected]>
Add clock driver API header, which defines all APIs that clock node
drivers should implement, and will have access to in order to configure
and request rates from their parent clocks. These APIs are all
considered internal to the clock management subsystem, and should not be
accessed by clock consumers (such as peripheral drivers)

Signed-off-by: Daniel DeGrasse <[email protected]>
Add clock management subsystem header. This header defines the API that
will be exposed to clock consumers, and is the external facing portion
of the clock subsystem.

Signed-off-by: Daniel DeGrasse <[email protected]>
Add add_clock_management_header() function to cmake extensions. This can be
used by drivers to register their header files as part of the clock
management subsystem. Clock driver headers should be used to define the
`Z_CLOCK_MANAGEMENT_XXX` macros needed for each clock to read its
configuration data.

Signed-off-by: Daniel DeGrasse <[email protected]>
Add initial clock management infrastructure for clock drivers. This
includes common clock management functions, and the Kconfig/CMake
infrastructure to define drivers.

Note that all SOC clock trees should define leaf nodes within their
clock tree using the "clock-output" compatible, which will be handled by
the common clock management drivers. These clock output nodes can have
clock states defined as child nodes.

Signed-off-by: Daniel DeGrasse <[email protected]>
Implement common clock management drivers. Currently three generic
drivers are available:
- fixed clock source driver. Represents a non-configurable root clock
  source
- clock source drivers. Represents a fixed clock source, with a single
  bit to enable or disable its output

Signed-off-by: Daniel DeGrasse <[email protected]>
The NXP syscon peripheral manages clock control for LPC SOCs, as well as
some iMX RT series and MCX series SOCs. Add clock node drivers for
common clock types present on SOCs implementing the syscon IP.

Signed-off-by: Daniel DeGrasse <[email protected]>
Implement driver for the LPC55Sxx PLL IP. These SOCs have two PLLs, one
of which includes a spread spectrum generator that permits better
precision when setting output clock rates, and can be used to reduce EMI
in spread spectrum mode. These PLLs are specific to the LPC55Sxx series,
so the drivers and compatibles are named accordingly.

Signed-off-by: Daniel DeGrasse <[email protected]>
Add LPC55Sxx clock tree. This clock tree is automatically generated from
MCUX clock data, and includes all clock nodes within the SOC, as well as
clock output nodes where required.

Signed-off-by: Daniel DeGrasse <[email protected]>
CPU nodes will be clock consumers, so add clock-device binding include
to pull in properties needed by clock consumers in clock management code

Signed-off-by: Daniel DeGrasse <[email protected]>
Add clock-output property for CPU0 on the LPC55S6x, which sources its clock
from the system_clock node.

Signed-off-by: Daniel DeGrasse <[email protected]>
Apply default CPU0 clock state at boot for the LPC55sxx. This will allow
the core clock to be configured using the clock management subsystem.

Signed-off-by: Daniel DeGrasse <[email protected]>
Make clock setup for each peripheral on the LPC55S69 dependent on if the
Kconfig for that peripheral driver is enabled. This reduces the flash
size of the LPC55S69 hello world image, since the code to setup these
clocks no longer needs to run at boot.

It also better mirrors how clocks will be setup within clock management,
IE where each peripheral will setup its own clocks.

Signed-off-by: Daniel DeGrasse <[email protected]>
Add clock-device include to flexcomm, as it can be used as a clock
consumer within the clock subsystem.

Signed-off-by: Daniel DeGrasse <[email protected]>
Add clock outputs for all LPC55Sxx flexcomm nodes, so these nodes can
request their frequency via the clock management subsystem

Signed-off-by: Daniel DeGrasse <[email protected]>
Add support for clock management to the serial flexcomm driver, dependent
on CONFIG_CLOCK_MGMT. When clock management is not enabled, the flexcomm
driver will fall back to the clock control API.

Signed-off-by: Daniel DeGrasse <[email protected]>
Add support for clock management on CPU0. This requires adding clock
setup for the CPU0 core clock to run at 144MHz from PLL1, and adding
clock setup for the flexcomm0 uart node to use the FROHF clock input.

Signed-off-by: Daniel DeGrasse <[email protected]>
For most builds, CONFIG_CLOCK_CONTROL is still required. However, for
simple applications that only use UART on the lpcxpresso55s69, it is now
possible to build with CONFIG_CLOCK_CONTROL=n and run the application as
expected. Move to implying this symbol so applications can opt to
disable it.

Signed-off-by: Daniel DeGrasse <[email protected]>
The native_sim board will be used within the clock mgmt API test to
verify the clock management subsystem (using emulated clock node
drivers). Therefore, indicate support for clock mgmt in the board YAML
so that twister will run the clock mgmt API test on it.

Signed-off-by: Daniel DeGrasse <[email protected]>
Add clock_management_api test. This test is intended to verify features
of the clock management API, including the following:
- verify that clock notification callbacks work as expected when a clock
  root is reconfigured
- verify that if a driver returns an error when configuring a clock,
  this will be propagated to the user.
- verify that consumer constraints will be able to block other consumers
  from reconfiguring clocks
- verify that consumers can remove constraints on their clocks

The test is supported on the `native_sim` target using emulated clock
drivers for testing purposes in CI, and on the
`lpcxpresso55s69/lpc55s69/cpu0` target to verify the clock management
API on real hardware.

Signed-off-by: Daniel DeGrasse <[email protected]>
Add clock management hardware test. This test applies a series of clock
states for a given consumer, and verifies that each state produces the
expected rate. This test is intended to verify that each clock node
driver within an SOC implementation works as expected.

Boards should define their test overlays for this test to exercise as
much of the clock tree as possible, and ensure some clock states do not
define an explicit clocks property, to test their `clock_set_rate` and
`clock_round_rate` implementations.

Initial support is added for the `lpcxpresso55s69/lpc55s69/cpu0` target,
as this is the only hardware supporting clock management.

Signed-off-by: Daniel DeGrasse <[email protected]>
Add clock_management_minimal test. This test is intended to verify that
clock management functions correctly when runtime notifications and rate
setting are disabled. It also verifies that support for multiple clock
outputs on a device works as expected.

The test has the following phases:
- apply default clock state for both clock outputs of the emulated
  consumer. Verify that the resulting clock frequencies match what is
  expected.
- apply sleep clock state for both clock outputs of the emulated
  consumer. Verify that the resulting clock frequencies match what is
  expected.
- Request a clock frequency from each clock output, which should match
  the frequency of one of the defined states exactly. Verify that the
  expected state is applied.

The test is supported on the `native_sim` target using emulated clock
drivers for testing purposes in CI, and on the
`lpcxpresso55s69/lpc55s69/cpu0` target to verify the clock management
API on real hardware.

Signed-off-by: Daniel DeGrasse <[email protected]>
Add documentation for clock management subsystem. This documentation
includes descriptions of the clock management consumer API, as well as
implementation guidelines for clock drivers themselves

Signed-off-by: Daniel DeGrasse <[email protected]>
@danieldegrasse danieldegrasse force-pushed the rfc/clock-mgmt-drivers branch from da4771e to afeb2bd Compare April 29, 2025 19:04
@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Jun 29, 2025
@github-actions github-actions bot closed this Jul 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant