Skip to content

Commit c15f8ba

Browse files
Hans Verkuildtor
authored andcommitted
Input: rmi_f54 - read from FIFO in 32 byte blocks
The F54 Report Data is apparently read through a fifo and for the smbus protocol that means that between reading a block of 32 bytes the rmiaddr shouldn't be incremented. However, changing that causes other non-fifo reads to fail and so that change was reverted. This patch changes just the F54 function and it now reads 32 bytes at a time from the fifo, using the F54_FIFO_OFFSET to update the start address that is used when reading from the fifo. This has only been tested with smbus, not with i2c or spi. But I suspect that the same is needed there since I think similar problems will occur there when reading more than 256 bytes. Signed-off-by: Hans Verkuil <[email protected]> Tested-by: Hans Verkuil <[email protected]> Reported-by: Timo Kaufmann <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 8ff771f commit c15f8ba

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

drivers/input/rmi4/rmi_f54.c

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
#define F54_NUM_TX_OFFSET 1
2525
#define F54_NUM_RX_OFFSET 0
2626

27+
/*
28+
* The smbus protocol can read only 32 bytes max at a time.
29+
* But this should be fine for i2c/spi as well.
30+
*/
31+
#define F54_REPORT_DATA_SIZE 32
32+
2733
/* F54 commands */
2834
#define F54_GET_REPORT 1
2935
#define F54_FORCE_CAL 2
@@ -526,6 +532,7 @@ static void rmi_f54_work(struct work_struct *work)
526532
int report_size;
527533
u8 command;
528534
int error;
535+
int i;
529536

530537
report_size = rmi_f54_get_report_size(f54);
531538
if (report_size == 0) {
@@ -558,23 +565,27 @@ static void rmi_f54_work(struct work_struct *work)
558565

559566
rmi_dbg(RMI_DEBUG_FN, &fn->dev, "Get report command completed, reading data\n");
560567

561-
fifo[0] = 0;
562-
fifo[1] = 0;
563-
error = rmi_write_block(fn->rmi_dev,
564-
fn->fd.data_base_addr + F54_FIFO_OFFSET,
565-
fifo, sizeof(fifo));
566-
if (error) {
567-
dev_err(&fn->dev, "Failed to set fifo start offset\n");
568-
goto abort;
569-
}
568+
for (i = 0; i < report_size; i += F54_REPORT_DATA_SIZE) {
569+
int size = min(F54_REPORT_DATA_SIZE, report_size - i);
570+
571+
fifo[0] = i & 0xff;
572+
fifo[1] = i >> 8;
573+
error = rmi_write_block(fn->rmi_dev,
574+
fn->fd.data_base_addr + F54_FIFO_OFFSET,
575+
fifo, sizeof(fifo));
576+
if (error) {
577+
dev_err(&fn->dev, "Failed to set fifo start offset\n");
578+
goto abort;
579+
}
570580

571-
error = rmi_read_block(fn->rmi_dev, fn->fd.data_base_addr +
572-
F54_REPORT_DATA_OFFSET, f54->report_data,
573-
report_size);
574-
if (error) {
575-
dev_err(&fn->dev, "%s: read [%d bytes] returned %d\n",
576-
__func__, report_size, error);
577-
goto abort;
581+
error = rmi_read_block(fn->rmi_dev, fn->fd.data_base_addr +
582+
F54_REPORT_DATA_OFFSET,
583+
f54->report_data + i, size);
584+
if (error) {
585+
dev_err(&fn->dev, "%s: read [%d bytes] returned %d\n",
586+
__func__, size, error);
587+
goto abort;
588+
}
578589
}
579590

580591
abort:

0 commit comments

Comments
 (0)