JensPi
Posts: 3
Joined: Mon Apr 17, 2023 9:41 am

Setting mmc0 4-bit mode actual clock speed on rpi4b

Thu May 25, 2023 6:37 pm

Today when I was playing around with clock speed of mmc0 interface (the sd card slot), I realized the "actual clock" in /sys/kernel/debug/mmc0/ios won't change (stuck at 50000000 Hz), no matter what value I try to put in clock file.

I even tried to create my own emmc2 overlay with max-frequency = <200000>, indeed the clock value changed to 200000 after applying the overlay, but actual clock is still the same: 50000000 Hz.

However, when I also set bus-width=<1>, the frequency limit starts to take effect and actual clock is also limited to the value I set.

My guess now is that in the default DDR52 timing spec, something else (like sdhci driver) is taking over the control of the actual clock speed. Only when the the timing spec is not DDR52 (broken by bus-width=<1>), the frequency limit starts to take effect.

I'm developing a mmc adapter right now and my goal is try to find a clock speed that has both good signal integrity and reasonable speed.
It's taking a eternity to read/write the mmc in 1-bit bus width, so the question now is if there are any way, either from device tree overlay or from the debug fs, that's possible to set arbitrary clock speed (or timing spec) with 4-bit bus width?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5061
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Setting mmc0 4-bit mode actual clock speed on rpi4b

Thu May 25, 2023 9:40 pm

SD cards are meant to run as fast as they can, which for that interface is 50MHz. Linux has no standard way to change that. However, the Pi MMC/SD drivers have an extra setting that allows the clock to be changed. To run the interface at 20MHz, add "dtparam=sd_overclock=20" to confíg.txt. Not all speeds are achievable, but the kernel will get as close as it can without exceeding the requested value. You can discover the actual clock it is using with:

Code: Select all

$ sudo cat /sys/kernel/debug/mmc0/ios

JensPi
Posts: 3
Joined: Mon Apr 17, 2023 9:41 am

Re: Setting mmc0 4-bit mode actual clock speed on rpi4b

Fri May 26, 2023 3:11 am

PhilE wrote:
Thu May 25, 2023 9:40 pm
SD cards are meant to run as fast as they can, which for that interface is 50MHz. Linux has no standard way to change that. However, the Pi MMC/SD drivers have an extra setting that allows the clock to be changed. To run the interface at 20MHz, add "dtparam=sd_overclock=20" to confíg.txt. Not all speeds are achievable, but the kernel will get as close as it can without exceeding the requested value. You can discover the actual clock it is using with:

Code: Select all

$ sudo cat /sys/kernel/debug/mmc0/ios
Hi Phil, thanks for your reply and info!

I tried dtparam=sd_overclock=20 but it seems it's not working as intended even after reboot, at least on my rpi4. The actual clock speed is still 50MHz.
If I understand correctly, the SD card slot is controlled by emmc2 instead of SD interface on the rpi4?

Image

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5061
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Setting mmc0 4-bit mode actual clock speed on rpi4b

Fri May 26, 2023 3:04 pm

I made a mistake - the sd_overclock parameter is currently only supported on the older Pis, and was intended to boost the clock as well as reduce it. Something similar could probably added to the sdhci-iproc driver used by BCM2711, but it isn't there yet.

And you're right about the sdhci-iproc driver ignoring the max-frequency value. Although the requested clock value is getting through to the driver, it is in some kind "preset" mode, that causes it to use specific fractional multiples of the input clock speed.

Return to “Device Tree”