[Nexus 4 Android Development] thracemerin:
Setting custom Gamma settings via sysfs - thanks to faux123 for sharing his code

Warning: changing these values can be potentially be dangerous to your display if you make a mistake.

Important, please read!

There are ten digits in the string separated by one space

First digit is a checksum and is never stored. The checksum is simply the sum of the other 9 numbers. This is to make it harder to so the interface is respected and you are forced to think about what you are doing.

There are 3 sysfs interfaces for gamma, one for each color:

#!/system/bin/sh
# Show the current configuration and the checksum
cat /sys/devices/platform/mipi_lgit.1537/kgamma_red
cat /sys/devices/platform/mipi_lgit.1537/kgamma_green
cat /sys/devices/platform/mipi_lgit.1537/kgamma_blue

Update:

Recently molesarecoming started opening this up and showing us what the values can be used to adjust. Franco then suggested that the white and grays should be swapped in moles original work. So, for init.d values using this interface, we have the following "banks" if values if we agree with Franco on the swap of the whites and grays.

R: checksum, g_white, g_mids, g_black, 0, g_contrast, g_brightness, g_saturation, g_grey, 2
G: checksum, g_white, g_mids, g_black, 0, g_contrast, g_brightness, g_saturation, g_grey, 2
B: checksum, g_white, g_mids, g_black, 0, g_contrast, g_brightness, g_saturation, g_grey, 2
(the zero in position 5's and the 2's in position 10 are recommended to be left alone since they are currently unknowns)

Minus the checksum, the 27 values mirror the 3 color arrays (3 x 9 = 27) in the actual LG LCD driver. Minus the unknowns, we are left with 21 values. Note that every one of the variables can have their value tweaked by color (saturation for red, saturation for green etc.), however, it is recommended that you start with all the values of one type being the same and then tweak from there if you really want to fine tune.

You have a lot of power in your hands even without fine tuning. Many will argue that fine tuning isn't required. If you look at the stock settings by Google in post 2, they took advantage of fine tuning for whatever reason. Even though many don't like these settings by Google, it shows how flexible the interface can be.

Instructions:

1) Start with a preset config (LG or Google) as shown further below. This is a set of 3 lines, 10 numbers for each line.

2) Tweak columns for their values as above. For example, we tweak contrast and brightness as in faux's original app. We could also do the same for saturation, blacks, whites, grays etc.

Example: start with LG presets with numbers to adjust:

383 114 21 118 0 10 4 80 48 2
383 114 21 118 0 7 4 80 48 2
383 114 21 118 0 5 1 80 48 2

3) Now update the checksum in column 1 (first digit = sum of last 9 digits)

397 114 21 118 0 10 4 80 48 2
394 114 21 118 0 7 4 80 48 2
389 114 21 118 0 5 1 80 48 2

4) Create a script inside a text file - my recommendation for your first test

#!/system/bin/sh
# Set data color pro presets from shared Google spreadsheet (thanks user acer73!)
# Use LG presents as your starting values and then adjust columns 6 & 7 from the spreadsheet
echo "397 114 21 118 0 10 4 80 48 2" > /sys/devices/platform/mipi_lgit.1537/kgamma_red
echo "394 114 21 118 0 7 4 80 48 2" > /sys/devices/platform/mipi_lgit.1537/kgamma_green
echo "389 114 21 118 0 5 1 80 48 2" > /sys/devices/platform/mipi_lgit.1537/kgamma_blue

#Set the complimentary RGB values for this calibration
echo "248 248 248" > /sys/devices/platform/kcal_ctrl.0/kcal
echo 1 > /sys/devices/platform/kcal_ctrl.0/kcal_ctrl

5) Run the script (or you can echo each line manually to test from adb if you prefer).

6) Turn the screen off and on for the gamma change to take effect.

7) Check the dmesg output for any clues and to see the output of the result.

8) Place the script into your /system/etc/init.d/ folder (or equivalent) for a permanent color change!

Screen refresh - this should only be called by apps or scripts while adjusting and testing colors "live" with the motley or faux sysfs interface. It should NOT be implemented on startup via init.d or by apps since it will compete with the normal power on process.

echo 1 > /sys/devices/platform/mipi_lgit.1537/refresh_screen

Presets:

#!/system/bin/sh
# Set LG presets (motley stock) - i.e. popular partial revert of Google's tweaks just before release
echo "383 114 21 118 0 0 0 80 48 2" > /sys/devices/platform/mipi_lgit.1537/kgamma_red
echo "383 114 21 118 0 0 0 80 48 2" > /sys/devices/platform/mipi_lgit.1537/kgamma_green
echo "383 114 21 118 0 0 0 80 48 2" > /sys/devices/platform/mipi_lgit.1537/kgamma_blue

#!/system/bin/sh
# Set stock Google presets (from kernel source code)
echo "332 64 68 118 1 0 0 48 32 1" > /sys/devices/platform/mipi_lgit.1537/kgamma_red
echo "332 64 68 118 1 0 0 48 32 1" > /sys/devices/platform/mipi_lgit.1537/kgamma_green
echo "364 32 35 116 0 31 16 80 51 3" > /sys/devices/platform/mipi_lgit.1537/kgamma_blue

#!/system/bin/sh
# Set faux Google presets (not sure why his numbers differ)
echo "460 64 68 118 1 32 96 48 32 1" > /sys/devices/platform/mipi_lgit.1537/kgamma_red
echo "461 64 68 118 1 33 96 48 32 1" > /sys/devices/platform/mipi_lgit.1537/kgamma_green
echo "445 32 35 116 0 32 96 80 51 3" > /sys/devices/platform/mipi_lgit.1537/kgamma_blue

Voltage Control

Warning: Every chip is different, even those from the same bin may handle undervolting differently, proceed with caution until you know that your device can handle it.

Note: The minimum allowable undervolt is 600mV for all frequencies (this doesn't mean your device can handle this low voltage, see above)

The voltage table can be viewed by typing the following:

cat /sys/devices/system/cpu/cpufreq/vdd_table/vdd_levels

To make changes do the following:

echo 'X Y' > /sys/devices/system/cpu/cpufreq/vdd_table/vdd_levels

For example: (set the voltage for 384MHz to 850mV)

echo '384000 850000' > /sys/devices/system/cpu/cpufreq/vdd_table/vdd_levels

For those of you who are interested, here are the default voltage tables from Motley b49: https://docs.google.com/spreadsheet/ccc?key=0AlgoC5O8VXsLdFU4U2xnSUxwUlNyQ05TVHF3ZDJCdXc&usp=sharing

USB Fast Charge

Turn on: (off by default)

echo 1 > /sys/kernel/fast_charge/force_fast_charge

Turn Off:

echo 0 > /sys/kernel/fast_charge/force_fast_charge

Simple GPU Governor Tunables - Thanks to faux123

Switching the governor: (options are simple, ondemand (default) & performance)

echo 'ondemand' > /sys/devices/platform/kgsl-3d0.0/kgsl/kgsl-3d0/pwrscale/trustzone/governor

Simple tunables:

/sys/module/msm_kgsl_core/parameters/simple_laziness

Laziness: Adjusts the number of times the governor skips ramp down requests. (Higher = better performance, higher battery drain)

/sys/module/msm_kgsl_core/parameters/simple_ramp_threshold

Threshold: Adjusts the threshold to ramp up or down the GPU frequencies. (Lower = better performance, higher battery drain)

C State Information

(thanks to faux123 - more info here: https://plus.google.com/109078966818501160423/posts/9R8fjQdHDXD)

faux123 recommends C0, C1 and C3 here: http://xdaforums.com/showpost.php?p=40151528&postcount=9775

C0 (WFI) - Shallowest Sleep (default enabled)

enable: echo 1 > /sys/module/pm_8x60/modes/cpu0/wfi/idle_enabled
disable: echo 0 > /sys/module/pm_8x60/modes/cpu0/wfi/idle_enabled

C1 (Retention) - slightly deeper sleep

enable: echo 1 > /sys/module/pm_8x60/modes/cpu0/retention/idle_enabled
disable: echo 0 > /sys/module/pm_8x60/modes/cpu0/retention/idle_enabled

C2 (Stand Alone Power Collapse) - deeper sleep

enable: echo 1 > /sys/module/pm_8x60/modes/cpu0/standalone_power_collapse/idle_enabled
disable: echo 0 > /sys/module/pm_8x60/modes/cpu0/standalone_power_collapse/idle_enabled

C3 (Power Collapse) - deepest sleep

enable: echo 1 > /sys/module/pm_8x60/modes/cpu0/power_collapse/idle_enabled
disable: echo 0 > /sys/module/pm_8x60/modes/cpu0/power_collapse/idle_enabled

TCP Congestion Control

Options: veno (default), reno, bic, westwood, vegas, yeah, illinois, cubic

echo 'cubic' > /proc/sys/net/ipv4/tcp_congestion_control

Sweep2Wake, Doubletap2Wake, Sweep2Sleep only

Sweep2Wake: (1 enable, 0 disable)

echo 1 > /sys/android_touch/sweep2wake

Doubletap2Wake: (1 enable, 0 disable)

echo 1 > /sys/android_touch/doubletap2wake

Sweep2Sleep Only: (1 enable, 0 disable) (sweep2wake must be enabled)

echo 1 > /sys/android_touch/s2w_s2sonly