Skip to content

Commit ce174f4

Browse files
6by9pelwell
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>
1 parent 425e873 commit ce174f4

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
@@ -234,6 +234,39 @@ static void attiny_gpio_set(struct gpio_chip *gc, unsigned int off, int val)
234234
mutex_unlock(&state->lock);
235235
}
236236

237+
static int attiny_i2c_read(struct i2c_client *client, u8 reg, unsigned int *buf)
238+
{
239+
struct i2c_msg msgs[1];
240+
u8 addr_buf[1] = { reg };
241+
u8 data_buf[1] = { 0, };
242+
int ret;
243+
244+
/* Write register address */
245+
msgs[0].addr = client->addr;
246+
msgs[0].flags = 0;
247+
msgs[0].len = ARRAY_SIZE(addr_buf);
248+
msgs[0].buf = addr_buf;
249+
250+
ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
251+
if (ret != ARRAY_SIZE(msgs))
252+
return -EIO;
253+
254+
usleep_range(5000, 10000);
255+
256+
/* Read data from register */
257+
msgs[0].addr = client->addr;
258+
msgs[0].flags = I2C_M_RD;
259+
msgs[0].len = 1;
260+
msgs[0].buf = data_buf;
261+
262+
ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
263+
if (ret != ARRAY_SIZE(msgs))
264+
return -EIO;
265+
266+
*buf = data_buf[0];
267+
return 0;
268+
}
269+
237270
/*
238271
* I2C driver interface functions
239272
*/
@@ -264,7 +297,7 @@ static int attiny_i2c_probe(struct i2c_client *i2c,
264297
goto error;
265298
}
266299

267-
ret = regmap_read(regmap, REG_ID, &data);
300+
ret = attiny_i2c_read(i2c, REG_ID, &data);
268301
if (ret < 0) {
269302
dev_err(&i2c->dev, "Failed to read REG_ID reg: %d\n", ret);
270303
goto error;

0 commit comments

Comments
 (0)