[Android Software/Hacking General [Developers Only]] Cpasjuste:
Hi,

I did release an OC/UV kernel for the Optimus 2x device, which come with an application ( Pimp My Cpu ) to manage/change the frequency/voltage on the fly. I had a lot of questions about adding this capability to other devices/kernels, so i tought i could write some little explanation on how it work. This could also be a way to have a common way to add OC/UV so developpers can easly work for any oc/uv kernel (by respecting the two added sysfs interfaces names/capability).

First, we will assume that you sucessfully added overclocking capability to your kernel. So now to be able to "talk" with your kernel and change the frequency/voltage on the fly, we need to use cpufreq capability.

Some of the required "sysfs" interfaces are already provided by cpufreq on all (i guess) kernel. Here is a list of used cpufreq interfaces that should already be present in any default kernel :

"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" :

This interface will show the maximum cpu frequency available on your device. This interface is read only, and you won't be able, in any case, to set an higher cpu frequency than this one. The Optimus 2X for example report "1000000" Khz (1Ghz) by default, after hacking the kernel to enable a higher frequency it can report "1200000" (1.2Ghz).

"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq" :

This interface will show the minimum cpu frequency available on your device. This interface is read only, and you won't be able, in any case, to set an lower cpu frequency than this one.

"/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq" :

This interface will show/set the maxmimum possible cpu frequency.

If you read this interface ( "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq" ) it will return the current maxmimum possible cpu frequency.

You can write a new maximum frequency to this interface (anything higher reported by "cpuinfo_max_freq" will not work) so you cpu will never go higher.

"/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq" :

This interface will show/set the minimum possible cpu frequency.

If you read this interface ( "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq" ) it will return the current minimum possible cpu frequency.

You can write a new minimum frequency to this interface (anything lower reported by "cpuinfo_min_freq" will not work) so you cpu will never go lower.

That's it for the standard cpufreq interfaces. Now if you want to be able to change this values "on the fly", with "Pimp My Cpu" for example, you'll have to add two new interfaces to cpufreq :

"/sys/devices/system/cpu/cpu0/cpufreq/frequency_voltage_table" :

This interface will return a table of all the availabe cpu frequency and voltages for each steps, higher to lower and is read only. This allow some utility like "Pimp My Cpu" to know each possible available frequency/voltage your kernel have.

You'll have to hack your kernel around to store this table and be able to show it a new cpufreq sysfs interface. You can take a look at my github to see how i did achieve that.

An read of this interface on the Optimus 2x will report :

FREQ	STOCK_MV CURRENT_MV

1200000 1100 1100
1000000 1000 1000
900000 950 950
750000 875 875
650000 850 850
500000 800 800
300000 770 770
216000 770 770

"/sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table" :

This interface enable on the fly voltage change (in mV). You can read/write to it. It will report the current millivolts modifier ( this means : "STOCK_MV" - "UV_mV_table value" ) from higher frequency to lower.

Of course, you'll have to find where the voltage change occur in your kernel and substract this value from the original value. You'll find how i did that on the Optimus 2x kernel on my github.

If you want to undervolt the 1000000 Khz (1Ghz) frequency by 50mV (based on the previous "frequency_voltage_table" you would do it like this :

echo "0 50 0 0 0 0 0 0" > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table

That's all for now, i'll try to add some more details as possible.