Skip to content

Commit cef16d9

Browse files
ndyerehristev
authored andcommitted
Input: atmel_mxt_ts - split large i2c transfers into blocks
On some firmware variants, the size of the info block exceeds what can be read in a single transfer. Signed-off-by: [cyrille.pitchen@atmel.com: adapt original patch to mainline] Signed-off-by: Cyrille Pitchen <cyrille.pitchen@atmel.com>
1 parent 4e6558b commit cef16d9

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

drivers/input/touchscreen/atmel_mxt_ts.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#define MXT_OBJECT_START 0x07
4848
#define MXT_OBJECT_SIZE 6
4949
#define MXT_INFO_CHECKSUM_SIZE 3
50-
#define MXT_MAX_BLOCK_WRITE 256
50+
#define MXT_MAX_BLOCK_WRITE 255
5151

5252
/* Object types */
5353
#define MXT_DEBUG_DIAGNOSTIC_T37 37
@@ -654,6 +654,27 @@ static int __mxt_read_reg(struct i2c_client *client,
654654
return ret;
655655
}
656656

657+
static int mxt_read_blks(struct mxt_data *data, u16 start, u16 count, u8 *buf)
658+
{
659+
u16 offset = 0;
660+
int error;
661+
u16 size;
662+
663+
while (offset < count) {
664+
size = min(MXT_MAX_BLOCK_WRITE, count - offset);
665+
666+
error = __mxt_read_reg(data->client,
667+
start + offset,
668+
size, buf + offset);
669+
if (error)
670+
return error;
671+
672+
offset += size;
673+
}
674+
675+
return 0;
676+
}
677+
657678
static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
658679
const void *val)
659680
{
@@ -1761,7 +1782,7 @@ static int mxt_read_info_block(struct mxt_data *data)
17611782
}
17621783

17631784
/* Read rest of info block */
1764-
error = __mxt_read_reg(client, MXT_OBJECT_START,
1785+
error = mxt_read_blks(data, MXT_OBJECT_START,
17651786
size - MXT_OBJECT_START,
17661787
buf + MXT_OBJECT_START);
17671788
if (error)
@@ -2813,7 +2834,7 @@ static ssize_t mxt_object_show(struct device *dev,
28132834
u16 size = mxt_obj_size(object);
28142835
u16 addr = object->start_address + j * size;
28152836

2816-
error = __mxt_read_reg(data->client, addr, size, obuf);
2837+
error = mxt_read_blks(data, addr, size, obuf);
28172838
if (error)
28182839
goto done;
28192840

0 commit comments

Comments
 (0)