Input: atmel_mxt_ts - update object list

Update the object list to include new objects, and add unique identifiers
so we can distinguish between old & new generation of the same object.

Signed-off-by: Iiro Valkonen <iiro.valkonen@atmel.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
(cherry picked from commit 81c88a711aef5552375c4296bb473fdf9b12273c)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - handle objects with multiple instances correctly

Handle the objects with multiple instances correctly when the configuration
data is loaded.

Signed-off-by: Iiro Valkonen <iiro.valkonen@atmel.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
(cherry picked from commit a93d4f2d023ea5e84c0104d4e479243c6ac77d17)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - report pressure information from the driver

Atmel mxt1386 touch controller has the touch pressure information so
let's report it to the user space.

[dtor@mail.ru: added ABS_RESSURE reporting for ST emulation.]

Signed-off-by: Yufeng Shen <miletus@chromium.org>
Acked-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
Acked-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
(cherry picked from commit 28ac293363368650963ee4c1e323c1ff502c121f)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - use snprintf for sysfs attribute show method

Sysfs attribute show methods are always passed a buffer of length
PAGE_SIZE.  To keep from overwriting this buffer and causing havoc, use
snprintf() to guarantee we never write more than the buffer can hold.

In addition, at least for my touchscreen, the number and size of objects
was far too big to fit in a single 4K page.  Therefore, this patch also
trims some redundant framing text to leave more room for actual data.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Acked-by: Nick Dyer <nick.dyer@itdev.co.uk>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
(cherry picked from commit 626af8611211c55595cd316103abd2419cd4d861)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - use CONFIG_PM_SLEEP

Simple cleanup to use newer PM APIs.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Reviewed-by: Joonyoung Shim <jy0922.shim@samsung.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
(cherry picked from commit 3a73c8169e4f56c1161a95985b8489dd04a7bcbe)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - only allow root to update firmware

Restrict permissions on the update_fw sysfs entry to read only for root
only.

Also, update object permission to use a macro S_IRUGO macro instead of
hard coded 0444.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Reviewed-by: Joonyoung Shim <jy0922.shim@samsung.com>
Acked-by: Nick Dyer <nick.dyer@itdev.co.uk>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
(cherry picked from commit 71b3e938cb97f6cf324fb5aaca46d8e400dc38f0)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - verify object size in mxt_write_object

Don't allow writing past the length of an object.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
(cherry picked from commit d1ff320f0a9766a53ae412d96f72bd861a889af6)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - do not read extra (checksum) byte

atmel_mxt devices will send a checksum byte at the end of a message if
the MSB of the object address is set.
However, since this driver does not set this bit, the checksum byte
isn't actually sent, so don't even try to read it.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
(cherry picked from commit 822115ff4bd7141a6069dcc17b35dfd823a44dff)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - dump each message on just 1 line

Helps ensure all bytes for a single message together in the system log.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Reviewed-by: Joonyoung Shim <jy0922.shim@samsung.com>
Acked-by: Nick Dyer <nick.dyer@itdev.co.uk>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
(cherry picked from commit 6ee3dbf93a895fce7c11d4d79e12beab1beb7860)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - derive phys from i2c client adapter

This allows userspace to more easily distinguish which bus a particular
atmel_mxt_ts device is attached to.

The resulting phys will be something like:
 i2c-1-0067/input0

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
(cherry picked from commit ec02ac2b7e1ad04ab2486fe9b2fbfc3ad5178f7c)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - use client name for irq

The atmel_mxt_ts driver can support multiple devices simultaneously.
Use the i2c_client name instead of the driver name when requesting an
interrupt to make the different interrupts distinguishable in
/proc/interrupts and top.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
(cherry picked from commit c2ef9a1a248bc597f3275e8d52e8ad68416d039f)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - detect OOM when creating mt slots

Hopefully this new code path will never be used, but better safe than
sorry...

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
(cherry picked from commit e1e1658d2eeb06e09f9855bdf6edb93474eca0c0)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - don't read T5 when dumping objects

T5 is the message processor object.  Reading it will only have two
outcomes, neither of which is particularly useful:
 1) the message count decrements, and a valid message will be lost
 2) an invalid message will be read (reportid == 0xff)

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
(cherry picked from commit 55d6867fe659f4783e57db7b2ae0bb04e4ac816e)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - use scnprintf for object sysfs entry

Using scnprintf() is a cleaner way to ensure that we don't overwrite the
PAGE_SIZE sysfs output buffer.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
(cherry picked from commit 9c67b789e051449d3914d683ba3604c5babc4dd9)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - optimize reading objects in object sysfs entry

Read each object in a single i2c transaction instead of byte-by-byte

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
(cherry picked from commit 43a91d51d3750dd9d5a6e5d14e9250a51f01f3c1)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - print less overhead when dumping objects

Conserve limited (PAGE_SIZE) sysfs output buffer space by only showing
readable objects and not printing the object's index, which is not useful
to userspace.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
(cherry picked from commit 91630955cb4c9899aa4521d1459837c66c5e9c7a)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - print all instances when dumping objects

For objects with multiple instances, dump them all, prepending each with
its "Instance #".

[rydberg@euromail.se: break out mxt_show_instance()]
Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
(cherry picked from commit 794eb67e76118108af5280ace2be8ae4983a6a81)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - return errors from i2c layer

The i2c layer can report a variety of errors, including -ENXIO for an i2c
NAK.  Instead of treating them all as -EIO, pass the actual i2c layer
error up to the caller.

However, still report as -EIO the unlikely case that a transaction was
partially completed, and no error message was returned from i2c_*().

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
(cherry picked from commit 771733e348e3df5b6283ab3b97d28577452bf09f)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - add variable length __mxt_write_reg

The i2c bus requires 4 bytes to do a 1-byte write
(1 byte i2c address + 2 byte offset + 1 byte data).

By taking a length with writes, the driver can amortize transaction
overhead by performing larger transactions where appropriate.

This patch just sets up the new API.  Later patches refactor writes
to take advantage of the larger transactions.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
(cherry picked from commit 9638ab7c9c3b352d54f4f7e80027bd6e1c0584e8)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Input: atmel_mxt_ts - optimize writing of object table entries

Write each object using a single bulk i2c write transfer.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Reviewed-by: Joonyoung Shim <jy0922.shim@samsung.com>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
(cherry picked from commit cf94bc09c89c923d339c68cf89360c02578ceee3)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>