Input: ads7846 - don't use scratch for tx_buf when clearing register
Subsystems (3)
PATCH v4 1/1 Input: ads7846 - don't use scratch for tx_buf when clearing register
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.
---
V1 -> V2: Don't use rx_buf when clearing command reg V2 -> V3: Modify original 2 xfer command to eliminate dev_err()
output on xfer with len and NULL buffers
V3 -> V4: Move scratch to end of ser_req to force it to a new
cache line.
V4 Note: Change to moving scratch was tested against an SPI
controller without DMA. We do not currently have a platform using this controller on an SPI bus supporting DMA.
drivers/input/touchscreen/ads7846.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/input/touchscreen/ads7846.c +2 -3
@@ -325,7 +325,6 @@ struct ser_req {u8 ref_on;u8 command;u8 ref_off; -u16 scratch;struct spi_message msg;struct spi_transfer xfer[8 ];/*
@@ -333,6 +332,7 @@ struct ser_req {* transfer buffers to live in their own cache lines. */ __be16 sample____cacheline_aligned ; +u16 scratch; };struct ads7845_ser_req {
@@ -403,8 +403,7 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)spi_message_add_tail (&req->xfer[5 ], &req->msg);/* clear the command register */ - req->scratch =0 ; - req->xfer[6 ].tx_buf = &req->scratch; + req->xfer[6 ].rx_buf = &req->scratch; req->xfer[6 ].len =1 ;spi_message_add_tail (&req->xfer[6 ], &req->msg);
base-commit: dd6c438c3e64a5ff0b5d7e78f7f9be547803ef1b
Signature · 1 line
2.34.1
Dmitry Torokhov
maintainerQuoted 35 lines · Kris Bahnsen
The workaround for XPT2046 clears the command register, giving the touchscreen controller a NOP. The change incorrectly re-uses the
req->scratchvariable which is used asrx_buffor xfer[5], so by the time xfer[6] occurs, the contents ofreq->scratchmay 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_transferbehavior oftx_bufbeing NULL to transmit all 0 bits and use the scratch variable for therx_buffor both the 1 byte command to and 2 byte response from the controller.Also relocates the scratch member of struct
ser_reqto 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 781a07da9bb94 ("Input: ads7846 - add dummy command register clearing cycle")Co-developed-by Mark Featherston <[email protected]>Signed-off-by Mark Featherston <[email protected]>Signed-off-by Kris Bahnsen <[email protected]>---
V1 -> V2: Don't use
rx_bufwhen clearing command reg V2 -> V3: Modify original 2 xfer command to eliminatedev_err()
output on xfer with len and NULL buffers
V3 -> V4: Move scratch to end ofser_reqto force it to a new
cache line.
Quoted 4 lines
V4 Note: Change to moving scratch was tested against an SPI
controller without DMA. We do not currently have a platform using this controller on an SPI bus supporting DMA.
Marek, any chance you could give it a quick spin?
Thanks!
Signature · 1 line
Dmitry
Quoted 22 lines · Kris Bahnsen
The workaround for XPT2046 clears the command register, giving the touchscreen controller a NOP. The change incorrectly re-uses the
req->scratchvariable which is used asrx_buffor xfer[5], so by the time xfer[6] occurs, the contents ofreq->scratchmay 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_transferbehavior oftx_bufbeing NULL to transmit all 0 bits and use the scratch variable for therx_buffor both the 1 byte command to and 2 byte response from the controller.Also relocates the scratch member of struct
ser_reqto 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.
Quoted 5 lines
Fixes 781a07da9bb94 ("Input: ads7846 - add dummy command register clearing cycle")Co-developed-by Mark Featherston <[email protected]>Signed-off-by Mark Featherston <[email protected]>Signed-off-by Kris Bahnsen <[email protected]>
Applied, thank you.
Signature · 1 line
Dmitry