Commit a1ecb041 authored by Claudiu Beznea's avatar Claudiu Beznea Committed by Andi Shyti

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: default avatarAndi Shyti <andi.shyti@kernel.org>
Reviewed-by: default avatarWolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: default avatarClaudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Signed-off-by: default avatarAndi Shyti <andi.shyti@kernel.org>
parent b42ed9fd
...@@ -301,19 +301,15 @@ static const struct i2c_algorithm riic_algo = { ...@@ -301,19 +301,15 @@ static const struct i2c_algorithm riic_algo = {
static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t) static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t)
{ {
int ret = 0;
unsigned long rate; unsigned long rate;
int total_ticks, cks, brl, brh; int total_ticks, cks, brl, brh;
struct device *dev = riic->adapter.dev.parent; struct device *dev = riic->adapter.dev.parent;
pm_runtime_get_sync(dev);
if (t->bus_freq_hz > I2C_MAX_FAST_MODE_FREQ) { if (t->bus_freq_hz > I2C_MAX_FAST_MODE_FREQ) {
dev_err(&riic->adapter.dev, dev_err(&riic->adapter.dev,
"unsupported bus speed (%dHz). %d max\n", "unsupported bus speed (%dHz). %d max\n",
t->bus_freq_hz, I2C_MAX_FAST_MODE_FREQ); t->bus_freq_hz, I2C_MAX_FAST_MODE_FREQ);
ret = -EINVAL; return -EINVAL;
goto out;
} }
rate = clk_get_rate(riic->clk); rate = clk_get_rate(riic->clk);
...@@ -351,8 +347,7 @@ static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t) ...@@ -351,8 +347,7 @@ static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t)
if (brl > (0x1F + 3)) { if (brl > (0x1F + 3)) {
dev_err(&riic->adapter.dev, "invalid speed (%lu). Too slow.\n", dev_err(&riic->adapter.dev, "invalid speed (%lu). Too slow.\n",
(unsigned long)t->bus_freq_hz); (unsigned long)t->bus_freq_hz);
ret = -EINVAL; return -EINVAL;
goto out;
} }
brh = total_ticks - brl; brh = total_ticks - brl;
...@@ -384,6 +379,8 @@ static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t) ...@@ -384,6 +379,8 @@ static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t)
t->scl_fall_ns / (1000000000 / rate), t->scl_fall_ns / (1000000000 / rate),
t->scl_rise_ns / (1000000000 / rate), cks, brl, brh); t->scl_rise_ns / (1000000000 / rate), cks, brl, brh);
pm_runtime_get_sync(dev);
/* Changing the order of accessing IICRST and ICE may break things! */ /* Changing the order of accessing IICRST and ICE may break things! */
riic_writeb(riic, ICCR1_IICRST | ICCR1_SOWP, RIIC_ICCR1); riic_writeb(riic, ICCR1_IICRST | ICCR1_SOWP, RIIC_ICCR1);
riic_clear_set_bit(riic, 0, ICCR1_ICE, RIIC_ICCR1); 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) ...@@ -397,9 +394,8 @@ static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t)
riic_clear_set_bit(riic, ICCR1_IICRST, 0, RIIC_ICCR1); riic_clear_set_bit(riic, ICCR1_IICRST, 0, RIIC_ICCR1);
out:
pm_runtime_put(dev); pm_runtime_put(dev);
return ret; return 0;
} }
static struct riic_irq_desc riic_irqs[] = { static struct riic_irq_desc riic_irqs[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment