a40898bfdaae7b762c0fb8452e963b61cc8391cd
[openwrt/staging/blogic.git] /
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
5 I2C read
6
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.
12
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
14 ---
15 .../regulator/rpi-panel-attiny-regulator.c | 35 ++++++++++++++++++-
16 1 file changed, 34 insertions(+), 1 deletion(-)
17
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);
22 }
23
24 +static int attiny_i2c_read(struct i2c_client *client, u8 reg, unsigned int *buf)
25 +{
26 + struct i2c_msg msgs[1];
27 + u8 addr_buf[1] = { reg };
28 + u8 data_buf[1] = { 0, };
29 + int ret;
30 +
31 + /* Write register address */
32 + msgs[0].addr = client->addr;
33 + msgs[0].flags = 0;
34 + msgs[0].len = ARRAY_SIZE(addr_buf);
35 + msgs[0].buf = addr_buf;
36 +
37 + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
38 + if (ret != ARRAY_SIZE(msgs))
39 + return -EIO;
40 +
41 + usleep_range(5000, 10000);
42 +
43 + /* Read data from register */
44 + msgs[0].addr = client->addr;
45 + msgs[0].flags = I2C_M_RD;
46 + msgs[0].len = 1;
47 + msgs[0].buf = data_buf;
48 +
49 + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
50 + if (ret != ARRAY_SIZE(msgs))
51 + return -EIO;
52 +
53 + *buf = data_buf[0];
54 + return 0;
55 +}
56 +
57 /*
58 * I2C driver interface functions
59 */
60 @@ -264,7 +297,7 @@ static int attiny_i2c_probe(struct i2c_c
61 goto error;
62 }
63
64 - ret = regmap_read(regmap, REG_ID, &data);
65 + ret = attiny_i2c_read(i2c, REG_ID, &data);
66 if (ret < 0) {
67 dev_err(&i2c->dev, "Failed to read REG_ID reg: %d\n", ret);
68 goto error;