[G2 and Desire Z Android Development] coolbho3000:
Now that we have permanent root, we can have even more fun with overclocking. This is an actual kernel, not a module, meaning that there are no scripts to run every time you restart the device, and there are a lot more speeds to choose from, from 806MHz all the way up to 1497MHz.

Just run SetCPU (set on boot will work if you have permanent root!) and set the speed to whatever you want. This is purely an overclocking kernel and is not undervolted, but undervolting is easy for other devs. Just tweak the frequency tables and recompile.

We can now properly changes voltages! With voltage increases, it is possible to push the G2 to absolutely ludicrous speeds. I've limited this kernel to 1497MHz, but I've seen speeds as high as 1.7GHz (!!!) at 1400mV. It scales remarkably in most benchmarks, too. The MSM7x30 chipset is a true overclocking champion.

For safety, this kernel defaults to 806MHz at boot (like overclocking kernels on most other devices). Use SetCPU (in my sig or on the Market) to tweak speeds precisely. (Devs: the max frequency on boot can also be adjusted in the modified cpufreq.c file).

I am not responsible for any damage these instructions or this software may cause!

Installation

I recommend flashing Cyanogen's BaconBits which contains this, more CPU governors, a newer kernel, no wifi bug, and other goodies: http://xdaforums.com/showthread.php?t=834565. The binaries below are not necessary if you flash BaconBits. You'll get the overclock anyway!

Github: https://github.com/coolbho3k/vision_oc_kernel

Binaries: http://pokedev.com/setcpu/vision_oc_kernel_2.zip

Mirror: http://dl.dropbox.com/u/36553/vision_oc_kernel_2.zip

If you want to install using the old method and the binaries I posted above:

Boot into fastboot. Using the fastboot utility, run:

fastboot flash zimage zImage

Where "zImage" is the path to the zImage posted in the zip above.

You'll notice at first that your wifi doesn't work. Don't worry! In Android:

adb push bcm4329.ko /sdcard/bcm4329.ko

adb shell

su

mount -o remount,rw /dev/block/mmcblk0p25 /system

cat /sdcard/bcm4329.ko > /system/lib/modules/bcm4329.ko

EDIT: argh, I keep forgetting our ro.secure is still 1. Fixed the instructions.

Where "bcm4329.ko" is the path to the wifi module posted in the zip above. Then reboot and enjoy.

Have fun guys. This was a lot less of a pain to make than the module and I only had to actually write like three lines of code. :)

Developers: customizing the overclocked speeds and voltages

Just add lines to the struct acpu_freq_tbl. There are no L values to worry about unlike the 8x50 platform (this time, we automatically detect the required L value), but remember that each speed must be a multiple of 19200. The only thing you need to worry about is the voltage and the VDD_RAW:

...
{ 1017600, PLL_2, 3, 0, 192000, 1200, VDD_RAW(1200) },
{ 1113600, PLL_2, 3, 0, 192000, 1200, VDD_RAW(1200) },
{ 1209600, PLL_2, 3, 0, 192000, 1200, VDD_RAW(1200) },
{ 1305600, PLL_2, 3, 0, 192000, 1200, VDD_RAW(1200) },
{ 1401600, PLL_2, 3, 0, 192000, 1300, VDD_RAW(1300) },
{ 1497600, PLL_2, 3, 0, 192000, 1300, VDD_RAW(1300) },
...

For a lower voltage, in this case 1100mV, at 1017.6MHz:

{ 1017600, PLL_2, 3, 0, 192000, 1100, VDD_RAW(1100) },

For 1.7GHz @1400mV (warning: only tested once, and the phone got very hot. I would not recommend this ;)) edit: actually, 1350mV is the max you can go, I don't know what I was thinking, but this works anyway:

{ 1708800, PLL_2, 3, 0, 192000, 1400, VDD_RAW(1400) },

Then add the speeds you actually want to use to the freq_table struct, remembering to keep incrementing the first column as you go down.

...
{ 4, 1017600 },
{ 5, 1113600 },
{ 6, 1209600 },
{ 7, 1305600 },
{ 8, 1401600 },
{ 9, 1497600 },
...

How it works

The G2's CPU speeds are based on the clock output of one of several PLLs. In the default MSM7x30 configuration, the 806.4MHz speed is based on PLL2, which also runs at 806.4MHz by default. (the MSM8x55 is an identical SoC, but runs PLL2 at 1017.6MHz. There is also a 1.2GHz version of the 8x55 floating around somewhere! The stock kernel for the 8x55 reports 1024MHz as the speed, but I think this is off by a few MHz).

So to overclock, we have to change the output of PLL2. The output of PLL2 is based on the speed of TCXO, which runs at 19.2MHz. The output of PLL2 is defined as 19.2 multiplied by an integer at the address MSM_CLK_CTL_BASE + 0x33c, called the L value. By manipulating this multiplier, we can also safely manipulate the output of PLL2, and as a result, safely manipulate the CPU speed when cpufreq switches us to a speed that uses PLL2. I was able to figure out the location of the PLL2 L value using this commit on Code Aurora. Turns out the address is the same as it is on the MSM7200 platform!

My previous kernel module hack that we used did this kind of inelegantly. It wrote a new multiplier to PLL2 and basically corrected cpufreq so that it (correctly) thought that this speed was no longer 806.4MHz. It required the addresses of several data structures in the kernel because it needed to know where to manipulate cpufreq. However, since our module could only change PLL2 once and not every time there is a frequency switch, we could only have one overclocked speed. If we overclocked to 1.42GHz, we lost 806.4MHz and everything in between.

The ability to flash kernels, however, makes our lives a lot easier. Without the need to hack kernel memory to get it to do what we want, overclocking practically requires only four lines of code:

From there, changes to the frequency table to define speeds/voltages is rather trivial.

#define PLL2_L_VAL_ADDR (MSM_CLK_CTL_BASE + 0x33)
...
/* Program PLL2 L val for overclocked speeds. */
if(s->src == PLL_2) {
writel(s->acpu_clk_khz/19200, PLL2_L_VAL_ADDR);
}

The above runs during frequency switching. It basically checks if the speed we're switching to runs on PLL2, and if it does, we write the value equal to (clock speed we want)/19200 to the L value address. A much simpler solution, and much more flexible, than the kernel module method. Thank god for permaroot (or just scotty and #g2root) ;)