The cpufreq subsystem is a Linux kernel subsystem responsible for managing the CPU frequency. It's commonly used in laptops to reduce power usage when idle.
On the S3C2410, adjusting the CPU frequency changes the clocks for almost all devices on the chip. This means that, to write a cpufreq driver for the S3C2410, you have to also adjust some values on almost all devices.
This project aims to implement the cpufreq driver (which manages the CPU frequency transitions) and a cpufreq notifier for all the affected drivers (to do two things: quiesce the device before the change, and adjust the frequency after the change). Deciding which frequency to use is the responsability of code from somewhere else (either cpufreq governors or userspace).
The most recent version of the code can be found at http://repo.or.cz/w/linux-2.6/s3c2410-cpufreq.git on the s3c2410-cpufreq-om branch.
|NOTE: Do not run on real hardware, unless you really know what you are doing. This code is mostly untested, and changes frequently. It might even not compile.|
You need a fully built OpenMoko tree for the cross-compiler and uboot tools.
- Checkout the s3c2410-cpufreq-om branch (or the wip branch for work in progress)
- Copy the defconfig file from branches/src/target/kernel/2.6.24.x/config on the OpenMoko svn as the
- Set the PATH to the correct value (check the run.* temporary files bitbake generates to find out the correct value)
make ARCH=arm CROSS_COMPILE=arm-angstrom-linux-gnueabi- oldconfigand answer correctly the questions
make ARCH=arm CROSS_COMPILE=arm-angstrom-linux-gnueabi- uImage
- The last line of the output tells you the correct file which should be flashed on the emulator.
cpufreq.debug=7to the kernel command line to enable the relevant debug output. You can also enable it after boot by going to the correct place at /sys/modules and changing the values there.
- Do not compile the cpufreq driver as a module, since several of the notifiers depend on functions defined in it and would thus end up being compiled as modules too.
- To test on 22.214.171.124, use
git format-patch -o dir master-om..s3c2410-cpufreq-omto generate a set of patches, and apply them all on top of the OpenMoko patches 126.96.36.199 kernel, except the framebuffer patch(es) (the 2.6.24.x code for the framebuffer is different from the 188.8.131.52 one).
- When trying for the first time, it's best to start slow:
- Do all the tests without the USB cable (disconnect before changing the governor/frequencies), since it misbehaves (will be later changed to prohibit changing frequencies when the cable is connected). It's best to also remove the SD card and SIM, just in case.
- Boot with
cpufreq.debug=7on the kernel command line and carefully inspect the kernel output for any incorrect output.
- Disable the cpufreq printk rate limit (
cpufreq.debug_ratelimit=0; it can be set via
- Set the governor to
userspaceand switch to the second highest frequency. Check the kernel output again (be on the lookout in particular for frequency mismatch messages from the cpufreq core).
- Work down the list of frequencies and check if they all work correctly (not all can be selected since the drivers reject some of them).
- Edit the code to disable the policy rejection of frequencies (returning at the top of
s3c2410_cpufreq_adjust_pinshould be enough) to be able to test all frequencies. Start again from the top of the list; watch in particular for the SLOW mode ones (12000 and below). There's no need to go all the way down to 1000; all SLOW mode ones should work the same, and it's very annoying. Test going back from SLOW mode to the lowest non-SLOW frequency, and jumping from SLOW mode to the maximum frequency (this last case can cause misterious crashes if the registers were set out of order, causing the bus to go too fast).
- Revert the changes made to the code above.
- Try the
- Try the
ondemandgovernor (it's the one which stresses the most the cpufreq mechanism).
What's already done
|Driver||Status (GTA01)||Status (GTA02)|
S3C2410A cpufreq driver
This code resides on
arch/arm/mach-s3c2410/s3c2410-cpufreq.c and is responsible for actually changing the frequency.
The list of available frequencies and their parameters (HCLK/PCLK dividers) can be found on this file.
Timer 4 driver
Timer 4 is used by the kernel as the periodic tick timer. The cpufreq notifier on
arch/arm/plat-s3c24xx/time.c is responsible for adjusting the current and reload values of the timer to match the new frequency.
The cpufreq notifier on
drivers/serial/s3c2410.c is responsible for (if possible) pausing both sides of the serial transmission before the frequency change and reloading the baud generator (and unpausing the serial transmission) after the change.
Pausing the transmission is currently only possible with hardware flow control. Since both serial ports on GTA01 use hardware flow control, that's not a problem (unless you are using the serial console).
The cpufreq notifier on
drivers/video/s3c2410fb.c is responsible for dynamically changing the frequency divider used to derive the video clocks.
The cpufreq notifier on
drivers/mtd/nand/s3c2410.c is responsible for reprogramming the NAND timings after a frequency change.
- Backlight (uses a PWM timer; not a problem with full brightness)
- Vibrator (uses a PWM timer)
- MMC/SD (can be avoided by not plugging it in)
- I2C (without a notifier and booting at the maximum speed, it can only get slower; there should be no side effects, since there's no minimum bus speed)
Some drivers need specific frequencies. Currently there's no way to tell the cpufreq core of that, but at minimum a cpufreq notifier should be used to turn them off if they won't be able to work with that frequency.
- The datasheet says the USB device gets unstable if the frequency is below a minimum value
- When using the IIS device, changing the frequency might not be a good idea, since it can cause audio glitches. It also probably needs a minimum frequency depending on the output audio frequency and sample size.
- The LCD device might also need a minimum frequency.
- The serial baudrate generator might not have a good enough divider value for some baud rates and some clock frequencies (for instance, 115200 at 12000 kHz)