diff mbox series

[2/3] Input: ads7846 - always set last command to PWRDOWN

Message ID 20230120124544.5993-3-l.ellero@asem.it (mailing list archive)
State Superseded
Headers show
Series Input: ads7846 - fix support for ADS7845 | expand

Commit Message

Luca Ellero Jan. 20, 2023, 12:45 p.m. UTC
Controllers that report pressure (e.g. ADS7846) use 5 commands and the
correct sequence is READ_X, READ_Y, READ_Z1, READ_Z2, PWRDOWN.

Controllers that don't report pressure (e.g. ADS7845/ADS7843) use only 3
commands and the correct sequence should be READ_X, READ_Y, PWRDOWN. But
the sequence sent was incorrect: READ_X, READ_Y, READ_Z1.

Fix this by setting the third (and last) command to PWRDOWN.

Signed-off-by: Luca Ellero <l.ellero@asem.it>
---
 drivers/input/touchscreen/ads7846.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Andy Shevchenko Jan. 20, 2023, 3:17 p.m. UTC | #1
On Fri, Jan 20, 2023 at 01:45:43PM +0100, Luca Ellero wrote:
> Controllers that report pressure (e.g. ADS7846) use 5 commands and the
> correct sequence is READ_X, READ_Y, READ_Z1, READ_Z2, PWRDOWN.
> 
> Controllers that don't report pressure (e.g. ADS7845/ADS7843) use only 3
> commands and the correct sequence should be READ_X, READ_Y, PWRDOWN. But
> the sequence sent was incorrect: READ_X, READ_Y, READ_Z1.
> 
> Fix this by setting the third (and last) command to PWRDOWN.

Provide a Fixes: tag?

> Signed-off-by: Luca Ellero <l.ellero@asem.it>
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index f11b444f2138..15da1047a577 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -1066,6 +1066,9 @@  static int ads7846_setup_spi_msg(struct ads7846 *ts,
 		struct ads7846_buf_layout *l = &packet->l[cmd_idx];
 		unsigned int max_count;
 
+		if (cmd_idx == packet->cmds - 1)
+			cmd_idx = ADS7846_PWDOWN;
+
 		if (ads7846_cmd_need_settle(cmd_idx))
 			max_count = packet->count + packet->count_skip;
 		else
@@ -1102,7 +1105,12 @@  static int ads7846_setup_spi_msg(struct ads7846 *ts,
 
 	for (cmd_idx = 0; cmd_idx < packet->cmds; cmd_idx++) {
 		struct ads7846_buf_layout *l = &packet->l[cmd_idx];
-		u8 cmd = ads7846_get_cmd(cmd_idx, vref);
+		u8 cmd;
+
+		if (cmd_idx == packet->cmds - 1)
+			cmd_idx = ADS7846_PWDOWN;
+
+		cmd = ads7846_get_cmd(cmd_idx, vref);
 
 		for (b = 0; b < l->count; b++)
 			packet->tx[l->offset + b].cmd = cmd;