Skip to content

Commit e4a7e3f

Browse files
6by9broonie
authored andcommitted
regulator/rpi-panel-attiny: Use two transactions for I2C read
The I2C to the Atmel is very fussy, and locks up easily on Pi0-3 particularly on reads. If running at 100kHz on Pi3, reading the ID register generally locks up the Atmel, but splitting the register select write and read into two transactions is reliable. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com> Link: https://lore.kernel.org/r/20220124220129.158891-10-detlev.casanova@collabora.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 5fa4e8e commit e4a7e3f

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,39 @@ static void attiny_gpio_set(struct gpio_chip *gc, unsigned int off, int val)
250250
mutex_unlock(&state->lock);
251251
}
252252

253+
static int attiny_i2c_read(struct i2c_client *client, u8 reg, unsigned int *buf)
254+
{
255+
struct i2c_msg msgs[1];
256+
u8 addr_buf[1] = { reg };
257+
u8 data_buf[1] = { 0, };
258+
int ret;
259+
260+
/* Write register address */
261+
msgs[0].addr = client->addr;
262+
msgs[0].flags = 0;
263+
msgs[0].len = ARRAY_SIZE(addr_buf);
264+
msgs[0].buf = addr_buf;
265+
266+
ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
267+
if (ret != ARRAY_SIZE(msgs))
268+
return -EIO;
269+
270+
usleep_range(5000, 10000);
271+
272+
/* Read data from register */
273+
msgs[0].addr = client->addr;
274+
msgs[0].flags = I2C_M_RD;
275+
msgs[0].len = 1;
276+
msgs[0].buf = data_buf;
277+
278+
ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
279+
if (ret != ARRAY_SIZE(msgs))
280+
return -EIO;
281+
282+
*buf = data_buf[0];
283+
return 0;
284+
}
285+
253286
/*
254287
* I2C driver interface functions
255288
*/
@@ -280,7 +313,7 @@ static int attiny_i2c_probe(struct i2c_client *i2c,
280313
goto error;
281314
}
282315

283-
ret = regmap_read(regmap, REG_ID, &data);
316+
ret = attiny_i2c_read(i2c, REG_ID, &data);
284317
if (ret < 0) {
285318
dev_err(&i2c->dev, "Failed to read REG_ID reg: %d\n", ret);
286319
goto error;

0 commit comments

Comments
 (0)