arco/samsung-kernel-msm7x30 — pull request #24 by CastagnaIT (2013-05-01 14:58:23+00:00)
Title: ariesve: cypress-touchkey: attempt to filter out "phantom" key-presses

Attempt to workaround a well known hardware bug of some Samsung devices.
Pratically, the high activity of the radio hardware, in particular the antenna, could cause interference on Melfas chip, which is located very close to the antenna.
This interference could induce bad interrupts that are seen by the chip as possible HOME, MENU or BACK key presses.
These phantom key presses are happening expecially in 2G mode.

The solution includes a new device module (phantom_kp_filter), which also allow the filtering parameters customization, and various changes to cypress-touchkey and pmic8xxx-keypad modules.

-- Phantom MENU and BACK key presses --

The solution can be divided into two parts:
- Validity check of the interrupt _3_TOUCH_INT checking for a predefined (and customizable) times that the corresponding value is 0, in fact, in the case of interference, the value can be 1, then you can decide whether or not to ignore the key press interrupt
- Validity check of the key pressed event, ignoring the possible events of key down and up on different keys (eg. MENU key down -> BACK key up), or too rapid wrong key presses

The problem and the possible workarounds are described by Electric Bill on this XDA forum thread:
http://forum.xda-developers.com/showthread.php?t=1551580

The code changes are also based on these commits made by CyanogenMod Team:
- https://github.com/CyanogenMod/android_kernel_samsung_aries/commit/4afad77c61c7cb54cce293034cdb07a928f22d20
- https://github.com/CyanogenMod/android_kernel_samsung_aries/commit/cb8fa22cba177709848321e8100ee60ee1684530

-- Phantom HOME key presses --

The solution can be divided into two parts:
- Validity check of the incoming key state, ignoring the key press if the status is not changed
- The key press states are temporarly collected inside a bit array and reported with a small delayed time, if there are too many interrupts, they could be related to radio interference, so the collected key states won't be reported to avoid phantom key presses

-- Module sysfs interface --

The new device module allow to show the number of ignored key press and to customize the filtering parameters by means of a sysfs interface, at the following system path:
/sys/class/misc/phantom_kp_filter

- home_enabled: the enabled status of the phantom HOME key presses filtering (0 = disabled, 1 = enabled)
- home_allowed_irqs: show/edit the allowed max number of incoming interrupts to consider a HOME key press as valid (from 1 to 32)
- home_report_wait: show/edit the wait time in ms before report the collected HOME key presses (from 5 to 25 ms)
- home_ignored_kp: show the ignored possible phantom HOME key presses
- menuback_enabled: show/edit the enabled status of the phantom MENU and BACK key presses filtering (0 = disabled, 1 = enabled)
- menuback_interrupt_checks: show/edit the interrupt checks number to be performed for the incoming MENU and BACK key presses (from 1 to 10)
- menuback_first_err_wait: show/edit the time in ms to wait after the first error on MENU or BACK keys if there are many invalid key errors in rapid sequence (from 50 to 1000 ms)
- menuback_last_err_wait: show/edit the time in ms to wait after the last error on MENU or BACK keys if there are many invalid key errors in rapid sequence (from 50 to 1000 ms)
- menuback_ignored_kp: show the ignored possible phantom MENU and BACK key presses
- version: show the module version

Signed-off-by: Cristoforo Cataldo