yaw moo
Posts: 79
Joined: Sun Nov 17, 2019 9:08 pm

Variable clocks and peripherals

Sat Mar 02, 2024 3:55 am

Hi all,

how do peripherals deal with variable clocks on the pi?

For example, UART has a clock divider to set up that I believe is relative to the system clock.

I query the clock rate using the property mailbox and set up the divider accordingly.

What happens when the system decides it wants to change that clock rate, for example for power saving?

Does the firmware update the dividers automatically to keep the peripheral clock constant?

cleverca22
Posts: 8833
Joined: Sat Aug 18, 2012 2:33 pm

Re: Variable clocks and peripherals

Sat Mar 02, 2024 4:01 am

the mini-uart clock is referenced off the main VPU clock

if you set enable_uart=1 in config.txt, then the VPU clock just stops doing powersaving things, and will not change freq, because there is no standard way to handle things with 2 kernels fighting over the hw

the PL011 uart has its own dedicated divisor and wont change during power savings

yaw moo
Posts: 79
Joined: Sun Nov 17, 2019 9:08 pm

Re: Variable clocks and peripherals

Sat Mar 02, 2024 5:12 pm

That makes sense for UART.

What about SD host? Does it need a setting in config.txt as well?

cleverca22
Posts: 8833
Joined: Sat Aug 18, 2012 2:33 pm

Re: Variable clocks and peripherals

Sat Mar 02, 2024 6:07 pm

yaw moo wrote:
Sat Mar 02, 2024 5:12 pm
What about SD host? Does it need a setting in config.txt as well?
good question, ive never heard of such a flag, and checking the device-tree, i dont see a proper answer

https://github.com/raspberrypi/linux/bl ... 1566-L1575
but over in the source, i can see a special firmware_sets_cdiv flag

i believe whats happening, is that linux just tells the firmware the desired clock rate
any time the VPU changes clocks for power-saving reasons, it fixes the sdhost cvid register for you
but the SD interface may run slower then desired for a few clocks as things transition

sd has a clock pin, so it can survive that
uart cant

yaw moo
Posts: 79
Joined: Sun Nov 17, 2019 9:08 pm

Re: Variable clocks and peripherals

Wed Mar 06, 2024 12:44 am

Thanks, I'll need to look into that a little further. Do we get a notification about clock changes for power savings or do we have to look into the mailbox periodically?

cleverca22
Posts: 8833
Joined: Sat Aug 18, 2012 2:33 pm

Re: Variable clocks and peripherals

Wed Mar 06, 2024 12:54 am

yaw moo wrote:
Wed Mar 06, 2024 12:44 am
Thanks, I'll need to look into that a little further. Do we get a notification about clock changes for power savings or do we have to look into the mailbox periodically?
no notification and no need to poll
the firmware knows what rate the sdhost should run at, and fixes the divisors for you

yaw moo
Posts: 79
Joined: Sun Nov 17, 2019 9:08 pm

Re: Variable clocks and peripherals

Wed Mar 06, 2024 9:07 am

ah, very cool indeed. Thanks :-)

Return to “Bare metal, Assembly language”