750d3f6be226b6230423bd87e15c4e36feee8da0
[openwrt/staging/blogic.git] /
1 From a8bb5f5ddbef4ac5b0e256c7c3bde4ac5636f429 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Wed, 8 Sep 2021 14:21:38 +0100
4 Subject: [PATCH] drm/panel/raspberrypi-touchscreen: Handle I2C errors.
5
6 rpi_touchscreen_i2c_read returns any errors from i2c_transfer,
7 or the 8 bit received value.
8 Check for error values before trying to process the data as
9 valid.
10
11 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
12 ---
13 drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c | 5 +++--
14 1 file changed, 3 insertions(+), 2 deletions(-)
15
16 --- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
17 +++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
18 @@ -296,13 +296,14 @@ static int rpi_touchscreen_noop(struct d
19 static int rpi_touchscreen_prepare(struct drm_panel *panel)
20 {
21 struct rpi_touchscreen *ts = panel_to_ts(panel);
22 - int i;
23 + int i, data;
24
25 rpi_touchscreen_i2c_write(ts, REG_POWERON, 1);
26 usleep_range(20000, 25000);
27 /* Wait for nPWRDWN to go low to indicate poweron is done. */
28 for (i = 0; i < 100; i++) {
29 - if (rpi_touchscreen_i2c_read(ts, REG_PORTB) & 1)
30 + data = rpi_touchscreen_i2c_read(ts, REG_PORTB);
31 + if (data >= 0 && (data & 1))
32 break;
33 }
34