Skip to content

Commit f1a2a9a

Browse files
6by9pelwell
authored andcommitted
regulator: rpi_panel_v2: Add delay on I2C reads
As with many microcontrollers, the panel wants to use clock stretching during a read so that the appropriate return value can be generated and programmed into the hardware. With Pi0-3 really not supporting clock stretching, this resulted in the panel firmware dying. Insert a delay between the write and the read to give the firmware a chance to generate the relevant return value. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
1 parent fd373fb commit f1a2a9a

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

drivers/regulator/rpi-panel-v2-regulator.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,39 @@ static const struct backlight_ops rpi_panel_v2_bl = {
8787
.update_status = rpi_panel_v2_update_status,
8888
};
8989

90+
static int rpi_panel_v2_i2c_read(struct i2c_client *client, u8 reg, unsigned int *buf)
91+
{
92+
struct i2c_msg msgs[1];
93+
u8 addr_buf[1] = { reg };
94+
u8 data_buf[1] = { 0, };
95+
int ret;
96+
97+
/* Write register address */
98+
msgs[0].addr = client->addr;
99+
msgs[0].flags = 0;
100+
msgs[0].len = ARRAY_SIZE(addr_buf);
101+
msgs[0].buf = addr_buf;
102+
103+
ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
104+
if (ret != ARRAY_SIZE(msgs))
105+
return -EIO;
106+
107+
usleep_range(5000, 10000);
108+
109+
/* Read data from register */
110+
msgs[0].addr = client->addr;
111+
msgs[0].flags = I2C_M_RD;
112+
msgs[0].len = 1;
113+
msgs[0].buf = data_buf;
114+
115+
ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
116+
if (ret != ARRAY_SIZE(msgs))
117+
return -EIO;
118+
119+
*buf = data_buf[0];
120+
return 0;
121+
}
122+
90123
/*
91124
* I2C driver interface functions
92125
*/
@@ -114,7 +147,7 @@ static int rpi_panel_v2_i2c_probe(struct i2c_client *i2c)
114147
goto error;
115148
}
116149

117-
ret = regmap_read(regmap, REG_ID, &data);
150+
ret = rpi_panel_v2_i2c_read(i2c, REG_ID, &data);
118151
if (ret < 0) {
119152
dev_err(&i2c->dev, "Failed to read REG_ID reg: %d\n", ret);
120153
goto error;

0 commit comments

Comments
 (0)