1 From de0ad7df43a7399f9c09394b35d74bc75ebc60a4 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 25 Nov 2021 14:50:10 +0000
4 Subject: [PATCH] regulator/rpi-panel-attiny: Use two transactions for
7 The I2C to the Atmel is very fussy, and locks up easily on
8 Pi0-3 particularly on reads.
9 If running at 100kHz on Pi3, reading the ID register generally
10 locks up the Atmel, but splitting the register select write and
11 read into two transactions is reliable.
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
15 .../regulator/rpi-panel-attiny-regulator.c | 35 ++++++++++++++++++-
16 1 file changed, 34 insertions(+), 1 deletion(-)
18 --- a/drivers/regulator/rpi-panel-attiny-regulator.c
19 +++ b/drivers/regulator/rpi-panel-attiny-regulator.c
20 @@ -234,6 +234,39 @@ static void attiny_gpio_set(struct gpio_
21 mutex_unlock(&state->lock);
24 +static int attiny_i2c_read(struct i2c_client *client, u8 reg, unsigned int *buf)
26 + struct i2c_msg msgs[1];
27 + u8 addr_buf[1] = { reg };
28 + u8 data_buf[1] = { 0, };
31 + /* Write register address */
32 + msgs[0].addr = client->addr;
34 + msgs[0].len = ARRAY_SIZE(addr_buf);
35 + msgs[0].buf = addr_buf;
37 + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
38 + if (ret != ARRAY_SIZE(msgs))
41 + usleep_range(5000, 10000);
43 + /* Read data from register */
44 + msgs[0].addr = client->addr;
45 + msgs[0].flags = I2C_M_RD;
47 + msgs[0].buf = data_buf;
49 + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
50 + if (ret != ARRAY_SIZE(msgs))
58 * I2C driver interface functions
60 @@ -264,7 +297,7 @@ static int attiny_i2c_probe(struct i2c_c
64 - ret = regmap_read(regmap, REG_ID, &data);
65 + ret = attiny_i2c_read(i2c, REG_ID, &data);
67 dev_err(&i2c->dev, "Failed to read REG_ID reg: %d\n", ret);