# How to make powerd works in FREEBSD 12.1 STABLE over RPI-B



## Miguel (Oct 26, 2019)

Greetings to the whole community in this my first post!
I have used powerd as a daemon since version 10.2 on my RPI-B but when upgrading to FREEBSD 12 I can't get it to work.
If i run

```
powerd
powerd: no cpufreq (4) support - aborting: No such file or directory
```

it seems that this feature is not enabled by default
I also can't find any CPU when running

```
dmesg | grep cpu
```

What do I need to add to activate this service?


----------



## trev (Oct 27, 2019)

If you haven't compiled the kernel with cpufreq support, you can simply load the kernel module with `kldload cpufreq` and/or add it to your /boot/loader.conf.local.

As for the missing CPU, try `grep CPU /var/run/dmesg.boot`.


----------



## Miguel (Oct 28, 2019)

Thanks for your reply.
My custom kernel does not have cpufreq support, I have followed the suggested steps but nothing happens.
If I run 

```
kldload cpufreq
kldload: can't load cpufreq: No such file or directory
```

It seems that the module does not exist


----------



## acheron (Oct 28, 2019)

Is it 12.0 or 12.1-rc?


----------



## Miguel (Oct 28, 2019)

```
uname -a
FreeBSD prototipo.local 12.1-STABLE FreeBSD 12.1-STABLE r354027 RPI-B  arm
```


----------



## acheron (Oct 28, 2019)

Can you post the dmesg somewhere?


----------



## Miguel (Oct 28, 2019)

attached 
	
	



```
dmesg > dmesg.txt
```


----------



## rigoletto@ (Oct 28, 2019)

Miguel said:


> ```
> uname -a
> FreeBSD prototipo.local 12.1-STABLE FreeBSD 12.1-STABLE r354027 RPI-B  arm
> ```



Might be an issue in the ARM version specificaly, better ask at the ARM Mailing list or IRC Freenode #freebsd-embedded.

Btw, sysutils/powerdxx usually work better for most people.


----------



## acheron (Oct 28, 2019)

Maybe something is missing in the dts, this is a dmesg with bcm2835_cpufreq0: 
https://dmesgd.nycbug.org/index.cgi?do=view&id=3902


----------



## Miguel (Oct 29, 2019)

rigoletto@ said:


> Might be an issue in the ARM version specificaly, better ask at the ARM Mailing list or IRC Freenode #freebsd-embedded.


I just sent an email to the ARM mailing list exposing this case. If there is any conclusion I will bring it here


> Btw, sysutils/powerdxx usually work better for most people.


Thanks, I will try it


----------



## Miguel (Oct 29, 2019)

acheron said:


> Maybe something is missing in the dts, this is a dmesg with bcm2835_cpufreq0:
> https://dmesgd.nycbug.org/index.cgi?do=view&id=3902


That is what it seems.
That file is a FreeBSD 11.2-STABLE dmesg where everything was fine but not now


----------



## acheron (Oct 29, 2019)

I just gave a quick look, this is the compat string to find cpufreq on the rpi:

```
static struct ofw_compat_data compat_data[] = {
    { "broadcom,bcm2835-vc",    1 },
    { "broadcom,bcm2708-vc",    1 },
    { "brcm,bcm2709",    1 },
    { "brcm,bcm2835",    1 },
    { "brcm,bcm2836",    1 },
    { "brcm,bcm2837",    1 },
    { NULL, 0 }
};
```


This is the interesting part of the fdt on 11.2 (obtained with ofwdump -ap):

```
snip   
    Node 0x1e28: vchiq
      compatible:
        62 72 6f 61 64 63 6f 6d 2c 62 63 6d 32 38 33 35 2d 76 63 68
        69 71 00
        'broadcom,bcm2835-vchiq'
snip
```

and the one in 12.0:

```
snip   
    Node 0x3890: vchiq
      compatible:
        62 72 63 6d 2c 62 63 6d 32 38 33 35 2d 76 63 68 69 71 00
        'brcm,bcm2835-vchiq'
snip
```

Adding brcm,bcm2835-vchiq to the compat list should solve this issue.


----------



## acheron (Oct 29, 2019)

ping manu


----------



## acheron (Oct 29, 2019)

It doesn't work. I just noticed that there is no cpu node with newer fdt...
on 11.2:

```
cpulist0: <Open Firmware CPU Group> on ofwbus0
cpu0: <Open Firmware CPU> on cpulist0
bcm2835_cpufreq0: <CPU Frequency Control> on cpu0
```
nothing on 12.0


----------



## acheron (Oct 29, 2019)

Warning, I don't know what I'm doing.
I was able to "restore" the cpu node with an overlay, and the cpufreq device is there:


```
uname -a
FreeBSD rpi-b 13.0-CURRENT FreeBSD 13.0-CURRENT #0 r353798

cpulist0: <Open Firmware CPU Group> on ofwbus0
cpu0: <Open Firmware CPU> on cpulist0
bcm2835_cpufreq0: <CPU Frequency Control> on cpu0
```

This is the overlay, I called it cpu.dtso:

```
/dts-v1/;
/plugin/;

/ {
        compatible = "brcm,bcm2835";
};


&{/} {
        cpus {
                #address-cells = <0x1>;
                #size-cells = <0x0>;
                cpu@0 {
                        compatible = "arm,1176jzf-s";
                        device_type = "cpu";
                        reg = <0x0>;
                        clock-frequency = <0x29b92700>;
                };
        };
}
```
Compile it:
`dtc -I dts -O dtb -b0 -@ -o cpu.dtbo cpu.dtso`

Copy it to the sdcard in /boot/dtb/overlays
Add this to /boot/loader.conf:

```
fdt_overlays="cpu.dtbo"
```
And reboot.


----------



## Miguel (Oct 29, 2019)

I have followed all the steps.
dmesg now display the missing bcm2835_cpufreq

```
dmesg > dmesg.txt
```
(attached)
and there is already frequency control for the CPU.

```
root@prototipo:/home/pi # powerd -v
powerd: unable to determine AC line status
load   6%, current freq 1000 MHz ( 0), wanted freq  968 MHz
load   7%, current freq 1000 MHz ( 0), wanted freq  937 MHz
load  10%, current freq 1000 MHz ( 0), wanted freq  907 MHz
load   0%, current freq 1000 MHz ( 0), wanted freq  878 MHz
changing clock speed from 1000 MHz to 900 MHz
load   4%, current freq  900 MHz ( 1), wanted freq  850 MHz
load   0%, current freq  900 MHz ( 1), wanted freq  823 MHz
load   0%, current freq  900 MHz ( 1), wanted freq  797 MHz
changing clock speed from 900 MHz to 800 MHz
load   4%, current freq  800 MHz ( 2), wanted freq  772 MHz
load   0%, current freq  800 MHz ( 2), wanted freq  747 MHz
^C
```
This issue is solved 
thank you very much


----------



## acheron (Oct 29, 2019)

Miguel said:


> ```
> root@prototipo:/home/pi # powerd -v
> powerd: unable to determine AC line status
> load   6%, current freq 1000 MHz ( 0), wanted freq  968 MHz
> ```


Weird value, the max should be 700MHz.


----------



## Miguel (Oct 29, 2019)

that's what I was thinking
may be wrong this value?

```
clock-frequency = <0x29b92700>
```
29b92700(hex) is 700.000.000 decimal


----------



## acheron (Oct 29, 2019)

Not sure. I decompiled the dts from the 11.2 iso and copy pasted the result in the dtso...


----------



## acheron (Oct 29, 2019)

Can you post the result of `sysctl dev.cpu.0.freq_levels`. This is what I have:
`dev.cpu.0.freq_levels: 700/-1 600/-1 500/-1 400/-1 300/-1`


----------



## Miguel (Oct 29, 2019)

Here is...

```
sysctl dev.cpu.0.freq_levels
dev.cpu.0.freq_levels: 1000/-1 900/-1 800/-1 700/-1 600/-1 500/-1 400/-1 300/-1
```
This is a Raspberry Pi Zero I suppose they must be the same values as for a RPI-B


----------



## acheron (Oct 29, 2019)

The Zero seems to run at 1000MHz, so your values are correct.


----------



## Miguel (Oct 29, 2019)

acheron said:


> The Zero seems to run at 1000MHz, so your values are correct.


Ok
Do you think it would be a good idea to set the value of 1000mhz for clock-frequency in cpu.dtso and recompile?


----------



## acheron (Oct 29, 2019)

clock-frequency doesn't seem to be used in sys/arm/broadcom/bcm2835. I think you can delete the line and it'll still work.


----------



## Miguel (Oct 29, 2019)

Ok, I leave it as is


----------



## pidloop (Feb 3, 2021)

Hi All,

Trying to get freq control on rpi4 running 13.0-ALPHA2. Tried the recipe by acheron above but made no change. Ideas? Thanks.


----------

