Input: atmel_mxt_ts - Set default irqflags when there is no pdata

This is the preparation for supporting the code path when there is
platform data provided and still boot the device into a sane state
with backup NVRAM config.

Make the irqflags default to be IRQF_TRIGGER_FALLING if no platform data is
provided.

Signed-off-by: Yufeng Shen <miletus@chromium.org>
Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit 9d6dbdb0ce5f89aa4bdf87a387b089fe993fa33b)

Change-Id: Ieb91bb39826611c2dd3f46f421b0b66add8163d8
Input: atmel_mxt_ts - Use deep sleep mode when stopped

By writing zero to both the active and idle cycle times the maXTouch device is
put into a deep sleep mode when it consumes minimal power. It is unnecessary
to change the configuration of any other objects (for example to disable T9
touchscreen).

It is counterproductive to reset the chip on resume, it will result in a long
delay. However it is necessary to issue a calibrate command after the chip
has spent any time in deep sleep.

This patch also deals with the situation where the power configuration is zero
on probe, which would mean that the device never wakes up to execute commands.

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit 5c0705dfd725ec70ef4fb759d18f70c69ad4c510)
Input: atmel_mxt_ts - Add shutdown function

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit a73af60c0055fb7a8a594cb6f99986a188c2c61d)

Change-Id: Iee1a83164084a8d78f9751116bc7d94cbf007aee
Input: atmel_mxt_ts - Rename pressure to amplitude to match spec

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit 9fad0d4837364c589ca9dfaf7bd19e8b08d6e5cb)
Input: atmel_mxt_ts - Rename touchscreen defines to include T9

This avoids confusion with the newer T100 touchscreen object.

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit 23894ef11e1fb41150a013d4cc080350605f4037)
Input: atmel_mxt_ts - Handle multiple input reports in one message

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit e8ff3ecc71e18f3a224cf141bc319b244bde59cf)
Input: atmel_mxt_ts - Move input device init into separate function

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit 5435ef940d13f01378cb059517d2fd0655e6f3fb)

Change-Id: Ib259425701a0dbd95d2f26e690ace0841231d642
Input: atmel_mxt_ts - Handle APP_CRC_FAIL on startup

If the bootloader fails to start the appmode image on the touch controller, it
stays in bootloader mode. It is possible to reflash a working firmware image
from this state.

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit b039552c275f2412b5bf870bed878a057053679d)
Input: atmel_mxt_ts - Handle bootloader previously unlocked

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit 8cb7c176160ebfc941347f3270e77a62e21185ca)
Input: atmel_mxt_ts - Add bootloader addresses for new chips

Later chips (for example mXT1664S) different mappings for bootloader addresses.
This means that we must look at the family ID to determine which address to
use. There is an additional complication: when we probe and we don't know the
family ID yet, we need to try both possible addresses to find the bootloader.

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit 93cca9e4e5d7072b3a159784a82684105ef3624a)
Input: atmel_mxt_ts - Recover from bootloader on probe

The MXT device may be in bootloader mode on probe, due to:
1) APP CRC failure, either:
  a) flash corruption
  b) bad power or other intermittent problem while checking CRC
2) If the device has been reset 10 or more times without accessing comms
3) Warm probe, device was in bootloader mode already

This code attempts to recover from 1(b) and 3.

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit 3ecfe80274d1c023ad6078d0affc89cb26f328a8)
Input: atmel_mxt_ts - Add support for dynamic message size

The T5 object may have various sizes depending on the objects used on the
particular maXTouch chip and firmware version, therefore it can't be hardcoded
in the driver. Allocate a buffer on probe instead.

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit 193878139d98a4aabb75b4c26ae086ca31f1d46c)
Input: atmel_mxt_ts - Decode T6 status messages

By storing the previous T6 status byte we can detect reset completion more
correctly, and multiple debug output of the same status can be suppressed (for
example CFGERR).

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit 8ac4fbf0fe19b6d9d31e361bb720bdf2385d849c)
Input: atmel_mxt_ts - Split message handler into separate functions

This is in preparation for support of the T44 message count object.

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit 70e54d5aca78aae5857d8066607daaef934d4b72)
Input: atmel_mxt_ts - Implement T44 message handling

maXTouch chips allow the reading of multiple messages in a single I2C
transaction. The number of messages available to be read is given by the value
in the T44 object which is located directly before the T5 object.

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit 79b90d596a92b325766c2c28669a751bc2d54154)
Input: atmel_mxt_ts - Output status from T48 Noise Supression

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit f1d5628ac07e20c68ca35b451d751faa6aa6c397)
Input: atmel_mxt_ts - Output status from T42 Touch Suppression

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit f7b41b83f5be5e962e6e6cf72916d68909e83c7a)
Input: atmel_mxt_ts - Implement vector/orientation support

The atmel touch messages contain orientation information as a byte in a packed
format which can be passed straight on to Android if the input device
configuration is correct, see
http://source.android.com/tech/input/touch-devices.html#touchorientationcalibration

This requires vector reports to be enabled in maXTouch config (zero DISVECT
bit in T9 CTRL field)

Android converts the format in frameworks/base/services/input/Input.cpp,
search for ORIENTATION_CALIBRATION_VECTOR.

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit 048738be430b215dbad6f7ee9b745e458bd21564)
Input: atmel_mxt_ts - implement I2C retries

Some maXTouch chips (eg mXT1386) will not respond on the first I2C request
when they are in a sleep state. It must be retried after a delay for the chip
to wake up.

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Yufeng Shen <miletus@chromium.org>
(cherry picked from commit 6b02d007f2036de8399bfefef7d798b617063d74)
Input: atmel_mxt_ts - Implement T63 Active Stylus support

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
(cherry picked from commit c845f7e99df0c62c1fef9eccbb95c22f6adc3ba4)

Change-Id: If2b4d24c1e8cf33a81ac8cc907ef59520c73f56a