Skip to content

Commit

Permalink
power: supply: bq24190_charger: using pm_runtime_resume_and_get inste…
Browse files Browse the repository at this point in the history
…ad of pm_runtime_get_sync

Using pm_runtime_resume_and_get is more appropriate
for simplifing code

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
  • Loading branch information
Minghao Chi authored and Sebastian Reichel committed May 4, 2022
1 parent 68fdbe0 commit d96a894
Showing 1 changed file with 21 additions and 42 deletions.
63 changes: 21 additions & 42 deletions drivers/power/supply/bq24190_charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,9 @@ static ssize_t bq24190_sysfs_show(struct device *dev,
if (!info)
return -EINVAL;

ret = pm_runtime_get_sync(bdi->dev);
if (ret < 0) {
pm_runtime_put_noidle(bdi->dev);
ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0)
return ret;
}

ret = bq24190_read_mask(bdi, info->reg, info->mask, info->shift, &v);
if (ret)
Expand Down Expand Up @@ -490,11 +488,9 @@ static ssize_t bq24190_sysfs_store(struct device *dev,
if (ret < 0)
return ret;

ret = pm_runtime_get_sync(bdi->dev);
if (ret < 0) {
pm_runtime_put_noidle(bdi->dev);
ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0)
return ret;
}

ret = bq24190_write_mask(bdi, info->reg, info->mask, info->shift, v);
if (ret)
Expand All @@ -512,10 +508,9 @@ static int bq24190_set_otg_vbus(struct bq24190_dev_info *bdi, bool enable)
union power_supply_propval val = { .intval = bdi->charge_type };
int ret;

ret = pm_runtime_get_sync(bdi->dev);
ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0) {
dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret);
pm_runtime_put_noidle(bdi->dev);
return ret;
}

Expand Down Expand Up @@ -551,10 +546,9 @@ static int bq24190_vbus_is_enabled(struct regulator_dev *dev)
int ret;
u8 val;

ret = pm_runtime_get_sync(bdi->dev);
ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0) {
dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret);
pm_runtime_put_noidle(bdi->dev);
return ret;
}

Expand Down Expand Up @@ -1128,11 +1122,9 @@ static int bq24190_charger_get_property(struct power_supply *psy,

dev_dbg(bdi->dev, "prop: %d\n", psp);

ret = pm_runtime_get_sync(bdi->dev);
if (ret < 0) {
pm_runtime_put_noidle(bdi->dev);
ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0)
return ret;
}

switch (psp) {
case POWER_SUPPLY_PROP_CHARGE_TYPE:
Expand Down Expand Up @@ -1204,11 +1196,9 @@ static int bq24190_charger_set_property(struct power_supply *psy,

dev_dbg(bdi->dev, "prop: %d\n", psp);

ret = pm_runtime_get_sync(bdi->dev);
if (ret < 0) {
pm_runtime_put_noidle(bdi->dev);
ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0)
return ret;
}

switch (psp) {
case POWER_SUPPLY_PROP_ONLINE:
Expand Down Expand Up @@ -1477,11 +1467,9 @@ static int bq24190_battery_get_property(struct power_supply *psy,
dev_warn(bdi->dev, "warning: /sys/class/power_supply/bq24190-battery is deprecated\n");
dev_dbg(bdi->dev, "prop: %d\n", psp);

ret = pm_runtime_get_sync(bdi->dev);
if (ret < 0) {
pm_runtime_put_noidle(bdi->dev);
ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0)
return ret;
}

switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
Expand Down Expand Up @@ -1525,11 +1513,9 @@ static int bq24190_battery_set_property(struct power_supply *psy,
dev_warn(bdi->dev, "warning: /sys/class/power_supply/bq24190-battery is deprecated\n");
dev_dbg(bdi->dev, "prop: %d\n", psp);

ret = pm_runtime_get_sync(bdi->dev);
if (ret < 0) {
pm_runtime_put_noidle(bdi->dev);
ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0)
return ret;
}

switch (psp) {
case POWER_SUPPLY_PROP_ONLINE:
Expand Down Expand Up @@ -1683,10 +1669,9 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)
int error;

bdi->irq_event = true;
error = pm_runtime_get_sync(bdi->dev);
error = pm_runtime_resume_and_get(bdi->dev);
if (error < 0) {
dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
pm_runtime_put_noidle(bdi->dev);
return IRQ_NONE;
}
bq24190_check_status(bdi);
Expand Down Expand Up @@ -1921,11 +1906,9 @@ static int bq24190_remove(struct i2c_client *client)
struct bq24190_dev_info *bdi = i2c_get_clientdata(client);
int error;

error = pm_runtime_get_sync(bdi->dev);
if (error < 0) {
error = pm_runtime_resume_and_get(bdi->dev);
if (error < 0)
dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
pm_runtime_put_noidle(bdi->dev);
}

bq24190_register_reset(bdi);
if (bdi->battery)
Expand Down Expand Up @@ -1982,11 +1965,9 @@ static __maybe_unused int bq24190_pm_suspend(struct device *dev)
struct bq24190_dev_info *bdi = i2c_get_clientdata(client);
int error;

error = pm_runtime_get_sync(bdi->dev);
if (error < 0) {
error = pm_runtime_resume_and_get(bdi->dev);
if (error < 0)
dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
pm_runtime_put_noidle(bdi->dev);
}

bq24190_register_reset(bdi);

Expand All @@ -2007,11 +1988,9 @@ static __maybe_unused int bq24190_pm_resume(struct device *dev)
bdi->f_reg = 0;
bdi->ss_reg = BQ24190_REG_SS_VBUS_STAT_MASK; /* impossible state */

error = pm_runtime_get_sync(bdi->dev);
if (error < 0) {
error = pm_runtime_resume_and_get(bdi->dev);
if (error < 0)
dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
pm_runtime_put_noidle(bdi->dev);
}

bq24190_register_reset(bdi);
bq24190_set_config(bdi);
Expand Down

0 comments on commit d96a894

Please sign in to comment.