Skip to content

Commit

Permalink
Input: atmel_mxt_ts - split large i2c transfers into blocks
Browse files Browse the repository at this point in the history
On some firmware variants, the size of the info block exceeds what can
be read in a single transfer.
  • Loading branch information
ndyer committed Apr 26, 2016
1 parent d88aadd commit 74c4f52
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions drivers/input/touchscreen/atmel_mxt_ts.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#define MXT_OBJECT_START 0x07
#define MXT_OBJECT_SIZE 6
#define MXT_INFO_CHECKSUM_SIZE 3
#define MXT_MAX_BLOCK_WRITE 256
#define MXT_MAX_BLOCK_WRITE 255

/* Object types */
#define MXT_DEBUG_DIAGNOSTIC_T37 37
Expand Down Expand Up @@ -575,6 +575,27 @@ static int __mxt_read_reg(struct i2c_client *client,
return ret;
}

static int mxt_read_blks(struct mxt_data *data, u16 start, u16 count, u8 *buf)
{
u16 offset = 0;
int error;
u16 size;

while (offset < count) {
size = min(MXT_MAX_BLOCK_WRITE, count - offset);

error = __mxt_read_reg(data->client,
start + offset,
size, buf + offset);
if (error)
return error;

offset += size;
}

return 0;
}

static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
const void *val)
{
Expand Down Expand Up @@ -1704,7 +1725,7 @@ static int mxt_read_info_block(struct mxt_data *data)
}

/* Read rest of info block */
error = __mxt_read_reg(client, MXT_OBJECT_START,
error = mxt_read_blks(data, MXT_OBJECT_START,
size - MXT_OBJECT_START,
buf + MXT_OBJECT_START);
if (error)
Expand Down Expand Up @@ -2243,7 +2264,7 @@ static ssize_t mxt_object_show(struct device *dev,
u16 size = mxt_obj_size(object);
u16 addr = object->start_address + j * size;

error = __mxt_read_reg(data->client, addr, size, obuf);
error = mxt_read_blks(data, addr, size, obuf);
if (error)
goto done;

Expand Down

0 comments on commit 74c4f52

Please sign in to comment.