iMX233 bootlets and changing the CPU speed?

Started by dingbatca, September 26, 2012, 06:34:33 PM

Previous topic - Next topic

dingbatca

I am trying to figure out how to change the CPU speed of my iMX233-OLinuXino-MICRO.  According to Freescale's
power calculator the valid CPU speeds for the i.MX233 are:
454.74MHz
392.73MHz
360.00MHz
261.82MHz
64.00MHz

I would really like to change the CPU speed down to 261MHz, or 64MHz.  This is all about saving power as my board is solar powered. I know the setting are some where in the bootlets code, I just don't know where, or how to tweak them.

Any and all help would be GREATLY appreciated!

petri

To set CPU speed you have to change CLKCTRL module registers.
Please read the i.MX233 reference manual which explains how
clock subsystem works. With that knowledge, you are possibly able to understand the code which sets register
that eventually core runs @ 455 MHz.

I did that once, on my own project. You can see the code and try to guess what I did.

http://zomg.asd.fi/cgi-bin/netbsd-imx23_olinuxino.cgi/artifact/6ea2237d51f4b6e131353f46ed6514bc020f3466

Please note, this code is not from Freescale's bootlets but maybe it can help you figure out which clock
settings have to change to archive low MHz's on your project.

Petri


dingbatca

The closest I can find is:

mach-mx28/includes/registers/regsclkctrl.h
...
#define HW_CLKCTRL_ETM_ADDR         (REGS_CLKCTRL_BASE + 0x130)
...


Sorry, I am not that would with register magic. Is this what I am looking for?

petri

Quote from: dingbatca on September 26, 2012, 10:03:05 PM
The closest I can find is:

mach-mx28/includes/registers/regsclkctrl.h
...
#define HW_CLKCTRL_ETM_ADDR         (REGS_CLKCTRL_BASE + 0x130)
...


Sorry, I am not that would with register magic. Is this what I am looking for?

I'm sorry, but this is kind of advanced topic which needs basics skills to read and modify bootlets code.
And after modification you should be able to build new sboot-image, to make changes effect.
Other fellows here can share, if it is possible to change CPU frequencies from the Linux kernel configuration, I have not experience on that...



dingbatca

I am just fine building new sboot images.  I would like a hand in understanding the "advanced topic" of messing with bootlet code. 

Any one out there willing to write a "How to" on changing the CPU speed.  Don't really care if it is from standpoint of the bootlets, or the Linux kernel.

dpwhittaker

The file you are looking for, at least in koliqi's build system (https://github.com/koliqi/imx23-olinuxino/blob/master/Building%20a%20kernel%20%20for%20the%20OLinuXino.md) is:

boot/imx-bootlets-src-10.05.02/boot_prep/init_mx23.c

Look at the change_cpu_freq() function on line 627.  As a first order test, just change the CPUFRAC from 19 to 33 (this seems to be the value for 261 MHz.  You'll probably also have to edit the init_clock function to lower the ram timing as well.  As a first order test, just uncomment #define EMI_96M at the top of the file.

Now, grab the MX233 Reference Manual, a cup of coffee, and a comfy recliner, and turn to chapter 4.  Read it all the way through until you understand it.  You might want to read chapters 1-3 as well for background information.  Look carefully at how the init_mx23.c code sets up the registers, then modify and enhance until you end up with the clock setup you want.  Follow koliqi's guide above to recompile bootlets and dd it back onto your SD card.  Then grab your kill-a-watt, measure the power consumption, and refine your clock setups until you have the best compromise between power consumption and performance for your application.

It looks like you have a lot more options that the 4 presented on the spreadsheet.  It also looks like you are going to want to completely gate off the PLL clock source and divide the XTAL clock source down as low as you can tolerate, plus gate off any UARTs are other clocks you are not using, if you really want to get down as low as you can on the power consumption, but I haven't read the whole chapter, just glanced over it.

Don't forget to also correspondingly lower the EMI bus, the AHB bus, the APBX clock, and turn off the LCD, TV ENC, analog, audio, and any other subsystems you are not using.

Good luck.  Solar powered linux sound fun.  I hope you keep us informed on your progress.

marcolazzaroni

Hello,
  I was able to reduce the clock speed by using a (dirty) trick

in drivers/clk/mxs/clk-imx23.c, change this line
clks[ref_xtal] = mxs_clk_fixed("ref_xtal", 24000000);
and put a higher value; if you put 240M instead of 24M it will believe it has a 240MHz oscillator.
This would break a number of things but the system boots 10x slower...
If you find a smarter way please let me know.

dingbatca

Thanks for the great responses.

When the Linux kernel boots and sets up the CPU will it overwrite all my speed settings?

In the Linux kernel (2.6.31 Freescale) I can adjust the CPU speed from /sys.  But cant get any lower then 262MHz. Is the speed settings passed from the bootlets code to the kernel?

Sorry for being the complete n00b. I am fluent in X86, but the ARM boot process is all new to me.

dpwhittaker

The linux kernel retained my memory timing changes after boot, but I don't know if it overwrites the cpu timing.

261 is as slow as you can get it using the PLL.  You have to turn off the PLL and only use the XTAL to get any slower, which is a pretty significant change, and may be incompatible with the way the kernel is set up currently (it may expect to be able to switch back and forth between low-power (XTAL) and high performance (PLL) mode based on system utilization).

In the end, you'll probably have some edits in the bootlets and some in the drivers/clk/mx23-clk.c file, and possibly some device tree entries... You'll just have to start trying stuff and see what works, unless someone else has already written some low-power patches for this platform.

dingbatca

#9
Just wanted to get a few power numbers out there.

Following this guide to build the kernel/bootlets: https://github.com/koliqi/imx23-olinuxino/blob/master/Building%20a%20kernel%20%20for%20the%20OLinuXino.md

Running a 3.6.0-rc7 Kernel, with power management turned on.

5V supply, reads 5.05V on my Fluke 115 volt meter.
Raw board with out an SD card: 58MA
Board while booting: 120MA (peak)
Board after booting, idle: 58MA
Board at 100% CPU load: 104MA  (dd if=/dev/urandom of=/dev/null)

csebastian

Hi everyone

I'm a fresh starter on embedded Linux on Olimex; i need to reduce clock speed in order to minimize power consumption; i saw previous posts but some links are broken; i am wondering if there is a simple way of achieving this without going through bootlets, kernel recompilation and so on; can anyone help on this  ?

olimex