Run the NPU at 594 MHz, from a fragment that can be commented out - #10
Merged
Conversation
The NPU came up at 500 MHz because that is where clk_500m_src comes up: CPLL/2. Its ACLK is a plain gate on aclk_npu_root, and aclk_npu_root is a mux with no divider, so the NPU is exactly its selected parent and the rate on ACLK_RKNN in the board dts was a silent no-op. A gate has neither .set_rate nor CLK_SET_RATE_PARENT, so the number has to be set on clk_500m_src, which is where Rockchip's own rv1106g3.dtsi sets it too. 594 MHz is GPLL/2 exactly. Setting it means repeating rv1106.dtsi's whole &cru assigned-clocks list, because the property is replaced rather than appended to and a dropped entry would revert that clock to its boot value, so it goes in its own dtsi rather than sprawling across the board dts. The board dts #includes it after &npu, and commenting that one line out is the whole of going back to 500 MHz. CPLL stays at 1000 MHz: clk_250m_src, clk_100m_src and clk_50m_src are exact CPLL divisions and would come out wrong at any other rate. build-kernel.sh copies .dtsi alongside .dts now, since cpp resolves the #include against the directory it is compiling from. Co-authored-by: Codesmith <codesmith-bot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports the Luckfox SDK's 594 MHz NPU clocking onto this tree, as an optional devicetree fragment that the board dts
#includes. Commenting that one line out is the whole of going back to 500 MHz.Worth knowing why this cannot be done on the
&npunode, because the board dts has been asking for 500 MHz there and getting it by coincidence.aclk_rknnis a plain gate onaclk_npu_root, andaclk_npu_rootis aCOMPOSITE_NODIV, a mux with no divider. A gate has neither.set_ratenorCLK_SET_RATE_PARENT, soassigned-clock-ratesonACLK_RKNNis silently a no-op; the NPU is exactly whatever its selected parent runs at, and that parent isclk_500m_src, which comes up at CPLL/2. So the rate has to be set onclk_500m_src, which is where Rockchip's ownrv1106g3.dtsisets it too (at 700 MHz, for the G3 profile). 594 MHz is GPLL/2 exactly.That means repeating all of
rv1106.dtsi's&crulist, sinceassigned-clocksis replaced wholesale rather than appended to and a dropped entry would revert that clock to its boot value. Hence a fragment rather than 20 lines in the middle of the board dts:CPLL deliberately stays at 1000 MHz:
clk_250m_src,clk_100m_srcandclk_50m_srcare exact CPLL divisions (/4, /10, /20) and would come out wrong at any other rate. The&npuline is kept only so the two numbers are written together.The include sits after
&npuin the board dts, because a later override wins.build-kernel.shnow copies.dtsialongside.dtsinto the kernel tree, since cpp resolves the#includeagainst the directory it is compiling from.One caveat, in the fragment's comment:
clk_500m_srcalso feedsaclk_ddr_rootandsclk_sfc, so anything on that leg of their muxes goes up with the NPU. SFC has its own divider and asks the clock framework for the rate it wants;aclk_ddr_rootdoes not, but Rockchip run this clock at 700 MHz on the G3, so 594 is inside what the part is expected to take.Verified by building the kernel and decompiling the DTB both ways: with the include,
clk_500m_src(id 150) is appended to the&crulist at0x2367b880and the NPU node reads the same; with the include commented out, the&crulist falls back torv1106.dtsi's ten entries and the NPU reads0x1dcd6500. The OPP table from #9 is unaffected.make checkpasses. Untested on hardware.Need help on this PR? Tag
@codesmithwith what you need. Autofix is enabled.