Skip to content

Commit 05dee40

Browse files
ts-krisgregkh
authored andcommitted
Input: ads7846 - don't use scratch for tx_buf when clearing register
commit 8566683 upstream. The workaround for XPT2046 clears the command register, giving the touchscreen controller a NOP. The change incorrectly re-uses the req->scratch variable which is used as rx_buf for xfer[5], so by the time xfer[6] occurs, the contents of req->scratch may not be 0. It was found that the touchscreen controller can end up in a completely unresponsive state due to it being given a command the driver does not expect. Instead, rely on the spi_transfer behavior of tx_buf being NULL to transmit all 0 bits and use the scratch variable for the rx_buf for both the 1 byte command to and 2 byte response from the controller. Also relocates the scratch member of struct ser_req to force it into a different cache line to prevent any potential issues of DMA stepping on unrelated data in other struct members due to sharing the same cache line. This change was tested on real TSC2046 and ADS7843 controllers, but not the XPT2046 the workaround was originally created for. Confirming that the original modification to clear the command register does not impact either real controller. Fixes: 781a07d ("Input: ads7846 - add dummy command register clearing cycle") Cc: stable@vger.kernel.org Co-developed-by: Mark Featherston <mark@embeddedTS.com> Signed-off-by: Mark Featherston <mark@embeddedTS.com> Signed-off-by: Kris Bahnsen <kris@embeddedTS.com> Link: https://patch.msgid.link/20260507164943.760009-1-kris@embeddedTS.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 75b1287 commit 05dee40

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

drivers/input/touchscreen/ads7846.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,14 @@ struct ser_req {
329329
u8 ref_on;
330330
u8 command;
331331
u8 ref_off;
332-
u16 scratch;
333332
struct spi_message msg;
334333
struct spi_transfer xfer[8];
335334
/*
336335
* DMA (thus cache coherency maintenance) requires the
337336
* transfer buffers to live in their own cache lines.
338337
*/
339338
__be16 sample ____cacheline_aligned;
339+
u16 scratch;
340340
};
341341

342342
struct ads7845_ser_req {
@@ -408,8 +408,7 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
408408
spi_message_add_tail(&req->xfer[5], &req->msg);
409409

410410
/* clear the command register */
411-
req->scratch = 0;
412-
req->xfer[6].tx_buf = &req->scratch;
411+
req->xfer[6].rx_buf = &req->scratch;
413412
req->xfer[6].len = 1;
414413
spi_message_add_tail(&req->xfer[6], &req->msg);
415414

0 commit comments

Comments
 (0)