Skip to content

Commit a1ecb04

Browse files
claudiubezneaAndi Shyti
authored andcommitted
i2c: riic: Call pm_runtime_get_sync() when need to access registers
There is no need to runtime resume the device as long as the IP registers are not accessed. Calling pm_runtime_get_sync() at the register access time leads to a simpler error path. Reviewed-by: Andi Shyti <[email protected]> Reviewed-by: Wolfram Sang <[email protected]> Signed-off-by: Claudiu Beznea <[email protected]> Signed-off-by: Andi Shyti <[email protected]>
1 parent b42ed9f commit a1ecb04

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

drivers/i2c/busses/i2c-riic.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,19 +301,15 @@ static const struct i2c_algorithm riic_algo = {
301301

302302
static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t)
303303
{
304-
int ret = 0;
305304
unsigned long rate;
306305
int total_ticks, cks, brl, brh;
307306
struct device *dev = riic->adapter.dev.parent;
308307

309-
pm_runtime_get_sync(dev);
310-
311308
if (t->bus_freq_hz > I2C_MAX_FAST_MODE_FREQ) {
312309
dev_err(&riic->adapter.dev,
313310
"unsupported bus speed (%dHz). %d max\n",
314311
t->bus_freq_hz, I2C_MAX_FAST_MODE_FREQ);
315-
ret = -EINVAL;
316-
goto out;
312+
return -EINVAL;
317313
}
318314

319315
rate = clk_get_rate(riic->clk);
@@ -351,8 +347,7 @@ static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t)
351347
if (brl > (0x1F + 3)) {
352348
dev_err(&riic->adapter.dev, "invalid speed (%lu). Too slow.\n",
353349
(unsigned long)t->bus_freq_hz);
354-
ret = -EINVAL;
355-
goto out;
350+
return -EINVAL;
356351
}
357352

358353
brh = total_ticks - brl;
@@ -384,6 +379,8 @@ static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t)
384379
t->scl_fall_ns / (1000000000 / rate),
385380
t->scl_rise_ns / (1000000000 / rate), cks, brl, brh);
386381

382+
pm_runtime_get_sync(dev);
383+
387384
/* Changing the order of accessing IICRST and ICE may break things! */
388385
riic_writeb(riic, ICCR1_IICRST | ICCR1_SOWP, RIIC_ICCR1);
389386
riic_clear_set_bit(riic, 0, ICCR1_ICE, RIIC_ICCR1);
@@ -397,9 +394,8 @@ static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t)
397394

398395
riic_clear_set_bit(riic, ICCR1_IICRST, 0, RIIC_ICCR1);
399396

400-
out:
401397
pm_runtime_put(dev);
402-
return ret;
398+
return 0;
403399
}
404400

405401
static struct riic_irq_desc riic_irqs[] = {

0 commit comments

Comments
 (0)