Changing clock rate on new Linux kernels


(Wladimir van der Laan) #1

It looks like recent kernels (currently running 5.4.0rc5) no longer handle run-time clock changes
(as described in https://wiki.debian.org/InstallingDebianOn/SiFive/HiFiveUnleashed)

echo 1250000000 > /sys/devices/platform/soc/10000000.prci/rate

It appears that the pcri has a new driver: the path is now /sys/devices/platform/soc/10000000.clock-controller and there’s no rate entry.

How to do this?

Edit: Couldn’t find any clock values in the dts that obviously relate to this frequency

/* Clock frequency (in Hz) of the PCB crystal for rtcclk */
#define RTCCLK_FREQ             1000000
…
        hfclk: hfclk {
                #clock-cells = <0>;
                compatible = "fixed-clock";
                clock-frequency = <33333333>;
                clock-output-names = "hfclk";
        };

        rtcclk: rtcclk {
                #clock-cells = <0>;
                compatible = "fixed-clock";
                clock-frequency = <RTCCLK_FREQ>;
                clock-output-names = "rtcclk";
        };

I think these are related to the crystals. How to I set the desired rate?


(Wladimir van der Laan) #2

I found at least how to query it:

$ cat /sys/kernel/debug/clk/corepll/clk_rate
999999990

This seems to work to change the frequency from the dts:

diff --git a/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts b/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts
index 88cfcb96bf23..97b09ee09dfd 100644
--- a/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts
+++ b/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts
@@ -45,6 +45,9 @@
 
 &uart0 {
        status = "okay";
+
+        assigned-clocks = <&prci PRCI_CLK_COREPLL>;
+        assigned-clock-rates = <1250000000>;
 };
 
 &uart1 {

(uart0 is arbitrary; some device needs to assign the clock; this is obviously not an official solution)


(Jim Wilson) #3

I’m told that we have patches for cpufreq support, but they are not in the upsteam kernel yet. See for instance https://github.com/sifive/meta-sifive/blob/master/recipes-kernel/linux/files/fu540-cpufreq.patch


(Wladimir van der Laan) #4

Thanks! That’s a much better solution.