Take peripherals into account when computing clock dependencies (#4540)

This commit is contained in:
Dániel Buga 2025-11-24 13:25:59 +01:00 committed by GitHub
parent 036d98bba5
commit 70e4ccc2ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 13 deletions

View File

@ -679,6 +679,9 @@ macro_rules! define_clock_tree_types {
rc_fast_clk_refcount: u32,
apb_clk_refcount: u32,
ref_tick_refcount: u32,
xtal32k_clk_refcount: u32,
rc_slow_clk_refcount: u32,
rc_fast_div_clk_refcount: u32,
rtc_slow_clk_refcount: u32,
rtc_fast_clk_refcount: u32,
timg0_calibration_clock_refcount: u32,
@ -714,6 +717,9 @@ macro_rules! define_clock_tree_types {
rc_fast_clk_refcount: 0,
apb_clk_refcount: 0,
ref_tick_refcount: 0,
xtal32k_clk_refcount: 0,
rc_slow_clk_refcount: 0,
rc_fast_div_clk_refcount: 0,
rtc_slow_clk_refcount: 0,
rtc_fast_clk_refcount: 0,
timg0_calibration_clock_refcount: 0,
@ -1140,30 +1146,42 @@ macro_rules! define_clock_tree_types {
80000000
}
pub fn request_xtal32k_clk(clocks: &mut ClockTree) {
enable_xtal32k_clk_impl(clocks, true);
if increment_reference_count(&mut clocks.xtal32k_clk_refcount) {
enable_xtal32k_clk_impl(clocks, true);
}
}
pub fn release_xtal32k_clk(clocks: &mut ClockTree) {
enable_xtal32k_clk_impl(clocks, false);
if decrement_reference_count(&mut clocks.xtal32k_clk_refcount) {
enable_xtal32k_clk_impl(clocks, false);
}
}
pub fn xtal32k_clk_frequency(clocks: &mut ClockTree) -> u32 {
32768
}
pub fn request_rc_slow_clk(clocks: &mut ClockTree) {
enable_rc_slow_clk_impl(clocks, true);
if increment_reference_count(&mut clocks.rc_slow_clk_refcount) {
enable_rc_slow_clk_impl(clocks, true);
}
}
pub fn release_rc_slow_clk(clocks: &mut ClockTree) {
enable_rc_slow_clk_impl(clocks, false);
if decrement_reference_count(&mut clocks.rc_slow_clk_refcount) {
enable_rc_slow_clk_impl(clocks, false);
}
}
pub fn rc_slow_clk_frequency(clocks: &mut ClockTree) -> u32 {
150000
}
pub fn request_rc_fast_div_clk(clocks: &mut ClockTree) {
request_rc_fast_clk(clocks);
enable_rc_fast_div_clk_impl(clocks, true);
if increment_reference_count(&mut clocks.rc_fast_div_clk_refcount) {
request_rc_fast_clk(clocks);
enable_rc_fast_div_clk_impl(clocks, true);
}
}
pub fn release_rc_fast_div_clk(clocks: &mut ClockTree) {
enable_rc_fast_div_clk_impl(clocks, false);
release_rc_fast_clk(clocks);
if decrement_reference_count(&mut clocks.rc_fast_div_clk_refcount) {
enable_rc_fast_div_clk_impl(clocks, false);
release_rc_fast_clk(clocks);
}
}
pub fn rc_fast_div_clk_frequency(clocks: &mut ClockTree) -> u32 {
(rc_fast_clk_frequency(clocks) / 256)

View File

@ -602,11 +602,6 @@ impl DeviceClocks {
})
.collect::<Vec<_>>();
// To compute refcount requirement and correct initialization order, we need to be able to
// access direct dependencies (downstream clocks). As it is simpler to define
// dependents (inputs), we have to do a bit of maths.
let dependency_graph = DependencyGraph::build_from(&clock_tree);
let validation_context = ValidationContext {
tree: self.system_clocks.clock_tree.as_slice(),
};
@ -657,6 +652,11 @@ impl DeviceClocks {
}
}
// To compute refcount requirement and correct initialization order, we need to be able to
// access direct dependencies (downstream clocks). As it is simpler to define
// dependents (inputs), we have to do a bit of maths.
let dependency_graph = DependencyGraph::build_from(&clock_tree);
// Classify clock tree items
for node in clock_tree.iter() {
// If item A configures item B, then item B is a dependent clock tree item.