Skip to contentSkip to conversation

Input: ads7846 - don't use scratch for tx_buf when clearing register

PATCH Superseded Kris Bahnsen 2 participants 3 messages Apr 27 – Apr 30

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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. Also set rx_buf to NULL because the value returned does not matter. Thus moving the 3 byte pattern to clear the command register to a single message.

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")

---

V1 -> V2: Don't use rx_buf when clearing command reg

 drivers/input/touchscreen/ads7846.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/input/touchscreen/ads7846.c +3 -9
index 4b39f7212d35c..93edd2419db5b 100644
@@ -327,7 +327,7 @@ struct ser_req {
 	u8			ref_off;
 	u16			scratch;
 	struct spi_message	msg;
-	struct spi_transfer	xfer[8];
+	struct spi_transfer	xfer[7];
 	/*
 	 * DMA (thus cache coherency maintenance) requires the
 	 * transfer buffers to live in their own cache lines.
@@ -403,16 +403,10 @@ 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].len = 1;
+	req->xfer[6].len = 3;
+	CS_CHANGE(req->xfer[6]);
 	spi_message_add_tail(&req->xfer[6], &req->msg);
 
-	req->xfer[7].rx_buf = &req->scratch;
-	req->xfer[7].len = 2;
-	CS_CHANGE(req->xfer[7]);
-	spi_message_add_tail(&req->xfer[7], &req->msg);
-
 	scoped_guard(mutex, &ts->lock) {
 		ads7846_stop(ts);
 		status = spi_sync(spi, &req->msg);

base-commit: dd6c438c3e64a5ff0b5d7e78f7f9be547803ef1b

Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 8 lines · Kris Bahnsen

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.

Quoted 4 lines

Instead, rely on the spi_transfer behavior of tx_buf being NULL to transmit all 0 bits. Also set rx_buf to NULL because the value returned does not matter. Thus moving the 3 byte pattern to clear the command register to a single message.

Unfortunately my suggestion was flawed: I think this will flood the logs with "Bufferless transfer has length %3". We need to have either tx or rx buffer :(

Thanks.

Signature · 1 line
Dmitry
#2 lore raw

Dmitry,

Quoted 9 lines · Dmitry Torokhov
Quoted 8 lines · Kris Bahnsen

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.

Quoted 8 lines
Quoted 4 lines

Instead, rely on the spi_transfer behavior of tx_buf being NULL to transmit all 0 bits. Also set rx_buf to NULL because the value returned does not matter. Thus moving the 3 byte pattern to clear the command register to a single message.

Unfortunately my suggestion was flawed: I think this will flood the logs with "Bufferless transfer has length %3". We need to have either tx or rx buffer :(

Ah. I do see that dev_err() line in spi_transfer_one_message(). All of my testing up to this point has been with an SPI host driver that implements its own transfer_one() operation so that error was never actually reached.

I'll send a v3 today that reverts back to the two separate xfers, using scratch for the rx_buf, and then NULL for tx_buf. That sounds like that should be the path of least resistance.

Quoted 3 lines

Thanks.

Signature · 3 lines
Kris Bahnsen
Software Engineer
embeddedTS