Two bq24190 PM improvments
cover Two bq24190 PM improvments
Hi,
Here are the two bq24190 patches rebased against current power-supply tree now that Liam's changes are applied.
I've kept Mark's acks as the changes were minor and mostly limited to bq24190_probe() basedon Liam's changes.
Regards,
Tony
Changes from earlier set:
- Separated from Liam's changes that are now in the power-supply tree
- Moved bdi->initialized before devm_request_threaded_irq() as suggested by Liam
- Added missing return value check for pm_runtime_get() as suggested by Liam
- Updated against current power-supply tree, mostly for the probe error handling
Tony Lindgren (2):
power: bq24190_charger: Check the interrupt status on resume
power: bq24190_charger: Use PM runtime autosuspend
drivers/power/supply/bq24190_charger.c | 180 ++++++++++++++++++++++++++------- 1 file changed, 143 insertions(+), 37 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/2 power: bq24190_charger: Check the interrupt status on resume
Some SoCs like omap3 can configure GPIO irqs to use Linux generic dedicated wakeirq support. If the dedicated wakeirq is configured, the SoC will use a always-on interrupt controller to produce wake-up events.
If bq24190 is configured for dedicated wakeirq, we need to check the interrupt status on PM runtime resume. This is because the Linux generic wakeirq will call pm_runtime_resume() on the device on a wakeirq. And as the bq24190 interrupt is falling edge sensitive and only active for 250 us, there will be no device interrupt seen by the runtime SoC IRQ controller.
Note that this can cause spurious interrupts on omap3 devices with bq24190 connected to gpio banks 2 - 5 as there's a glitch on those pins waking from off mode as listed in "Advisory 1.45". Devices with this issue should not configure the optional wakeirq interrupt in the dts file.
--- drivers/power/supply/bq24190_charger.c | 62 ++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 10 deletions(-)
drivers/power/supply/bq24190_charger.c +52 -10
@@ -155,6 +155,8 @@ struct bq24190_dev_info {kernel_ulong_t model;unsigned int gpio_int;unsigned int irq; +bool initialized; +bool irq_event;struct mutex f_reg_lock;u8 f_reg;u8 ss_reg;
@@ -1157,9 +1159,8 @@ static const struct power_supply_desc bq24190_battery_desc = { .property_is_writeable = bq24190_battery_property_is_writeable, }; -static irqreturn_t bq24190_irq_handler_thread (int irq,void *data) +static void bq24190_check_status (struct bq24190_dev_info *bdi) { -struct bq24190_dev_info *bdi = data;const u8 battery_mask_ss =BQ24190_REG_SS_CHRG_STAT_MASK ;const u8 battery_mask_f =BQ24190_REG_F_BAT_FAULT_MASK |BQ24190_REG_F_NTC_FAULT_MASK ;
@@ -1167,12 +1168,10 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)u8 ss_reg =0 , f_reg =0 ;int i, ret; -pm_runtime_get_sync (bdi->dev); - ret =bq24190_read (bdi,BQ24190_REG_SS , &ss_reg);if (ret <0 ) {dev_err (bdi->dev,"Can't read SS reg: %d\n" , ret); - goto out; +return ; } i =0 ;
@@ -1180,7 +1179,7 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data) ret =bq24190_read (bdi,BQ24190_REG_F , &f_reg);if (ret <0 ) {dev_err (bdi->dev,"Can't read F reg: %d\n" , ret); - goto out; +return ; } }while (f_reg && ++i <2 );
@@ -1229,10 +1228,18 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)if (alert_battery)power_supply_changed (bdi->battery); -out: -pm_runtime_put_sync (bdi->dev); -dev_dbg (bdi->dev,"ss_reg: 0x%02x, f_reg: 0x%02x\n" , ss_reg, f_reg); +} + +static irqreturn_t bq24190_irq_handler_thread (int irq,void *data) +{ +struct bq24190_dev_info *bdi = data; + + bdi->irq_event = true; +pm_runtime_get_sync (bdi->dev); +bq24190_check_status (bdi); +pm_runtime_put_sync (bdi->dev); + bdi->irq_event = false;return IRQ_HANDLED ; }
@@ -1391,6 +1398,8 @@ static int bq24190_probe(struct i2c_client *client, goto out3; } + bdi->initialized = true; + ret = devm_request_threaded_irq(dev, bdi->irq, NULL, bq24190_irq_handler_thread, IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
@@ -1437,6 +1446,35 @@ static int bq24190_remove(struct i2c_client *client)return 0 ; } +static int bq24190_runtime_suspend (struct device *dev) +{ +struct i2c_client *client =to_i2c_client (dev); +struct bq24190_dev_info *bdi =i2c_get_clientdata (client); + +if (!bdi->initialized) +return 0 ; + +dev_dbg (bdi->dev,"%s\n" , __func__); + +return 0 ; +} + +static int bq24190_runtime_resume (struct device *dev) +{ +struct i2c_client *client =to_i2c_client (dev); +struct bq24190_dev_info *bdi =i2c_get_clientdata (client); + +if (!bdi->initialized) +return 0 ; + +if (!bdi->irq_event) { +dev_dbg (bdi->dev,"checking events on possible wakeirq\n" ); +bq24190_check_status (bdi); + } + +return 0 ; +} +#ifdef CONFIG_PM_SLEEP static int bq24190_pm_suspend (struct device *dev) {
@@ -1472,7 +1510,11 @@ static int bq24190_pm_resume(struct device *dev) }#endif -static SIMPLE_DEV_PM_OPS(bq24190_pm_ops, bq24190_pm_suspend, bq24190_pm_resume); +static const struct dev_pm_ops bq24190_pm_ops = { + SET_RUNTIME_PM_OPS(bq24190_runtime_suspend, bq24190_runtime_resume, + NULL) +SET_SYSTEM_SLEEP_PM_OPS (bq24190_pm_suspend, bq24190_pm_resume) +};/* * Only support the bq24190 right now. The bq24192, bq24192i, and bq24193
Signature · 1 line
2.11.0
Re: [PATCH 1/2] power: bq24190_charger: Check the interrupt status on resume
Quoted 78 lines · Tony Lindgren
Some SoCs like omap3 can configure GPIO irqs to use Linux generic dedicated wakeirq support. If the dedicated wakeirq is configured, the SoC will use a always-on interrupt controller to produce wake-up events.
If bq24190 is configured for dedicated wakeirq, we need to check the interrupt status on PM runtime resume. This is because the Linux generic wakeirq will call
pm_runtime_resume()on the device on a wakeirq. And as the bq24190 interrupt is falling edge sensitive and only active for 250 us, there will be no device interrupt seen by the runtime SoC IRQ controller.Note that this can cause spurious interrupts on omap3 devices with bq24190 connected to gpio banks 2 - 5 as there's a glitch on those pins waking from off mode as listed in "Advisory 1.45". Devices with this issue should not configure the optional wakeirq interrupt in the dts file.
Cc Matt Ranostay <[email protected]>Cc Liam Breck <[email protected]>Acked-by Mark Greer <[email protected]>Signed-off-by Tony Lindgren <[email protected]>--- drivers/power/supply/bq24190_charger.c | 62 ++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 10 deletions(-)drivers/power/supply/bq24190_charger.c +5
-8@@ -155,6 +155,8 @@ struct bq24190_dev_info {kernel_ulong_t model;unsigned int gpio_int;unsigned int irq; +bool initialized; +bool irq_event;struct mutex f_reg_lock;u8 f_reg;u8 ss_reg;@@ -1157,9 +1159,8 @@ static const struct power_supply_desc bq24190_battery_desc = { .property_is_writeable = bq24190_battery_property_is_writeable, }; -static irqreturn_t bq24190_irq_handler_thread (int irq,void *data) +static void bq24190_check_status (struct bq24190_dev_info *bdi) { -struct bq24190_dev_info *bdi = data;const u8 battery_mask_ss =BQ24190_REG_SS_CHRG_STAT_MASK ;const u8 battery_mask_f =BQ24190_REG_F_BAT_FAULT_MASK |BQ24190_REG_F_NTC_FAULT_MASK ;@@ -1167,12 +1168,10 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)u8 ss_reg =0 , f_reg =0 ;int i, ret; -pm_runtime_get_sync (bdi->dev); - ret =bq24190_read (bdi,BQ24190_REG_SS , &ss_reg);if (ret <0 ) {dev_err (bdi->dev,"Can't read SS reg: %d\n" , ret); - goto out; +return ; } i =0 ;@@ -1180,7 +1179,7 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data) ret =bq24190_read (bdi,BQ24190_REG_F , &f_reg);if (ret <0 ) {dev_err (bdi->dev,"Can't read F reg: %d\n" , ret); - goto out; +return ; } }while (f_reg && ++i <2 );@@ -1229,10 +1228,18 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)if (alert_battery)power_supply_changed (bdi->battery); -out: -pm_runtime_put_sync (bdi->dev);
drivers/power/supply/bq24190_charger.c static irqreturn_t bq24190_irq_handler_thread(int irq, void *data) · line 1239
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +8
-1-dev_dbg (bdi->dev,"ss_reg: 0x%02x, f_reg: 0x%02x\n" , ss_reg, f_reg); +} + +static irqreturn_t bq24190_irq_handler_thread (int irq,void *data) +{ +struct bq24190_dev_info *bdi = data; + + bdi->irq_event = true; +pm_runtime_get_sync (bdi->dev);
Do we need to call pm_runtime_irq_safe() prior to the above?
Quoted 7 lines
drivers/power/supply/bq24190_charger.c +3
-0+bq24190_check_status (bdi); +pm_runtime_put_sync (bdi->dev); + bdi->irq_event = false;return IRQ_HANDLED ; }
Sebastian Reichel
maintainerRe: [PATCH 1/2] power: bq24190_charger: Check the interrupt status on resume
Hi,
Quoted 8 lines · Liam Breck
drivers/power/supply/bq24190_charger.c static irqreturn_t bq24190_irq_handler_thread(int irq, void *data) · line 1239
Quoted 6 lines
drivers/power/supply/bq24190_charger.c +6
-0+static irqreturn_t bq24190_irq_handler_thread (int irq,void *data) +{ +struct bq24190_dev_info *bdi = data; + + bdi->irq_event = true; +pm_runtime_get_sync (bdi->dev);Do we need to call
pm_runtime_irq_safe()prior to the above?
It's not needed here, since the irq handler does not run in irq context (it's a threaded irq handler).
Btw. calling pm_runtime_irq_safe() basically means, that your driver's power-management is broken:
http://lxr.free-electrons.com/source/drivers/base/power/runtime.c#L1288
(The relevant part is: »It also causes the parent's usage counter to be permanently incremented«)
Quoted 6 lines
drivers/power/supply/bq24190_charger.c static irqreturn_t bq24190_irq_handler_thread(int irq, void *data) · line 1245
Quoted 6 lines
drivers/power/supply/bq24190_charger.c +3
-0+bq24190_check_status (bdi); +pm_runtime_put_sync (bdi->dev); + bdi->irq_event = false;return IRQ_HANDLED ; }
-- Sebastian
Sebastian Reichel
maintainerRe: [PATCH 1/2] power: bq24190_charger: Check the interrupt status on resume
In reply to Tony LindgrenHi Tony,
I think your runtime_resume is missing runtime_pm_get/put_sync, see below:
drivers/power/supply/bq24190_charger.c static irqreturn_t bq24190_irq_handler_thread(int irq, void *data) · line 1241
Quoted 9 lines · Tony Lindgren
[...]
drivers/power/supply/bq24190_charger.c +8
-0+static irqreturn_t bq24190_irq_handler_thread (int irq,void *data) +{ +struct bq24190_dev_info *bdi = data; + + bdi->irq_event = true; +pm_runtime_get_sync (bdi->dev); +bq24190_check_status (bdi); +pm_runtime_put_sync (bdi->dev);
bq24190_check_status is called with runtime_pm enabled.
Quoted 8 lines
drivers/power/supply/bq24190_charger.c +2
-0+ bdi->irq_event = false;return IRQ_HANDLED ; } +static int bq24190_runtime_resume (struct device *dev)
drivers/power/supply/bq24190_charger.c static int bq24190_remove(struct i2c_client *client) · line 1472
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +10
-0+{ +struct i2c_client *client =to_i2c_client (dev); +struct bq24190_dev_info *bdi =i2c_get_clientdata (client); + +if (!bdi->initialized) +return 0 ; + +if (!bdi->irq_event) { +dev_dbg (bdi->dev,"checking events on possible wakeirq\n" ); +bq24190_check_status (bdi);
bq24190_check_status is called without runtime_pm enabled.
drivers/power/supply/bq24190_charger.c static int bq24190_remove(struct i2c_client *client)
Quoted 6 lines
drivers/power/supply/bq24190_charger.c +4
-0+ } + +return 0 ; +}
-- Sebastian
Re: [PATCH 1/2] power: bq24190_charger: Check the interrupt status on resume
Quoted 25 lines · Sebastian Reichel
Hi Tony,
I think your
runtime_resumeis missing runtime_pm_get/put_sync, see below:drivers/power/supply/bq24190_charger.c static irqreturn_t bq24190_irq_handler_thread(int irq, void *data) · line 1241
Quoted 9 lines · Tony Lindgren
[...]
drivers/power/supply/bq24190_charger.c +8
-0+static irqreturn_t bq24190_irq_handler_thread (int irq,void *data) +{ +struct bq24190_dev_info *bdi = data; + + bdi->irq_event = true; +pm_runtime_get_sync (bdi->dev); +bq24190_check_status (bdi); +pm_runtime_put_sync (bdi->dev);
bq24190_check_statusis called withruntime_pmenabled.Quoted 7 lines
drivers/power/supply/bq24190_charger.c +1
-0+ bdi->irq_event = false;return IRQ_HANDLED ; }
Quoted 13 lines
drivers/power/supply/bq24190_charger.c static int bq24190_remove(struct i2c_client *client) · line 1472
Quoted 11 lines
drivers/power/supply/bq24190_charger.c +11
-0+static int bq24190_runtime_resume (struct device *dev) +{ +struct i2c_client *client =to_i2c_client (dev); +struct bq24190_dev_info *bdi =i2c_get_clientdata (client); + +if (!bdi->initialized) +return 0 ; + +if (!bdi->irq_event) { +dev_dbg (bdi->dev,"checking events on possible wakeirq\n" ); +bq24190_check_status (bdi);
bq24190_check_statusis called withoutruntime_pmenabled.
But it's the runtime_resume call we're calling it from :)
I don't think there is anything to configure in bq24190 at least at this point, we just want to see if we got the wakeirq call resume while in some deeper idle state.
Regards,
Tony
PATCH 2/2 power: bq24190_charger: Use PM runtime autosuspend
In reply to Tony LindgrenWe can get quite a few interrupts when the battery is trickle charging. Let's enable PM runtime autosuspend to avoid constantly toggling device state.
Let's use a 600 ms timeout as that's how long the USB chager detection might take.
--- drivers/power/supply/bq24190_charger.c | 122 +++++++++++++++++++++++++-------- 1 file changed, 93 insertions(+), 29 deletions(-)
drivers/power/supply/bq24190_charger.c +93 -29
@@ -420,6 +420,7 @@ static ssize_t bq24190_sysfs_show(struct device *dev,struct power_supply *psy =dev_get_drvdata (dev);struct bq24190_dev_info *bdi =power_supply_get_drvdata (psy);struct bq24190_sysfs_field_info *info; +ssize_t count;int ret;u8 v;
@@ -427,11 +428,20 @@ static ssize_t bq24190_sysfs_show(struct device *dev,if (!info)return -EINVAL ; + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret; + ret =bq24190_read_mask (bdi, info->reg, info->mask, info->shift, &v);if (ret) -return ret; + count = ret; +else + count =scnprintf (buf,PAGE_SIZE ,"%hhx\n" , v); + +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); -return scnprintf (buf,PAGE_SIZE ,"%hhx\n" , v); +return count; } static ssize_t bq24190_sysfs_store(struct device *dev,
@@ -451,9 +461,16 @@ static ssize_t bq24190_sysfs_store(struct device *dev,if (ret <0 )return ret; + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret; + ret =bq24190_write_mask (bdi, info->reg, info->mask, info->shift, v);if (ret) -return ret; + count = ret; + +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev);return count; }
@@ -795,7 +812,9 @@ static int bq24190_charger_get_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_CHARGE_TYPE :
@@ -835,7 +854,9 @@ static int bq24190_charger_get_property(struct power_supply *psy, ret = -ENODATA ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }
@@ -848,7 +869,9 @@ static int bq24190_charger_set_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_CHARGE_TYPE :
@@ -864,7 +887,9 @@ static int bq24190_charger_set_property(struct power_supply *psy, ret = -EINVAL ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }
@@ -1065,7 +1090,9 @@ static int bq24190_battery_get_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_STATUS :
@@ -1093,7 +1120,9 @@ static int bq24190_battery_get_property(struct power_supply *psy, ret = -ENODATA ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }
@@ -1106,7 +1135,9 @@ static int bq24190_battery_set_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_ONLINE :
@@ -1119,7 +1150,9 @@ static int bq24190_battery_set_property(struct power_supply *psy, ret = -EINVAL ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }
@@ -1234,11 +1267,15 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi)static irqreturn_t bq24190_irq_handler_thread (int irq,void *data) {struct bq24190_dev_info *bdi = data; +int ret; bdi->irq_event = true; -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;bq24190_check_status (bdi); -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); bdi->irq_event = false;return IRQ_HANDLED ;
@@ -1249,7 +1286,9 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)u8 v;int ret; -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;/* First check that the device really is what its supposed to be */ ret = bq24190_read_mask(bdi, BQ24190_REG_VPRS,
@@ -1274,7 +1313,9 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi) ret =bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); out: -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }
@@ -1364,12 +1405,16 @@ static int bq24190_probe(struct i2c_client *client, }pm_runtime_enable (dev); -pm_runtime_resume (dev); +pm_runtime_set_autosuspend_delay (dev,600 ); +pm_runtime_use_autosuspend (dev); + ret =pm_runtime_get_sync (dev); +if (ret <0 ) + goto out1; ret =bq24190_hw_init (bdi);if (ret <0 ) {dev_err (dev,"Hardware init failed\n" ); - goto out1; + goto out2; } charger_cfg.drv_data = bdi;
@@ -1380,7 +1425,7 @@ static int bq24190_probe(struct i2c_client *client,if (IS_ERR (bdi->charger)) {dev_err (dev,"Can't register charger\n" ); ret =PTR_ERR (bdi->charger); - goto out1; + goto out2; } battery_cfg.drv_data = bdi;
@@ -1389,13 +1434,13 @@ static int bq24190_probe(struct i2c_client *client,if (IS_ERR (bdi->battery)) {dev_err (dev,"Can't register battery\n" ); ret =PTR_ERR (bdi->battery); - goto out2; + goto out3; } ret =bq24190_sysfs_create_group (bdi);if (ret) {dev_err (dev,"Can't create sysfs entries\n" ); - goto out3; + goto out4; } bdi->initialized = true;
@@ -1406,21 +1451,28 @@ static int bq24190_probe(struct i2c_client *client, "bq24190-charger", bdi);if (ret <0 ) {dev_err (dev,"Can't set up irq handler\n" ); - goto out4; + goto out5; } +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); +return 0 ; -out4: +out5:bq24190_sysfs_remove_group (bdi); -out3: +out4:power_supply_unregister (bdi->battery); -out2: +out3:power_supply_unregister (bdi->charger); +out2: +pm_runtime_put_sync (dev); + out1: +pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev);if (bdi->gpio_int)gpio_free (bdi->gpio_int);
@@ -1430,9 +1482,13 @@ static int bq24190_probe(struct i2c_client *client,static int bq24190_remove (struct i2c_client *client) {struct bq24190_dev_info *bdi =i2c_get_clientdata (client); +int ret; -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , ret);bq24190_register_reset (bdi); +pm_runtime_dont_use_autosuspend (bdi->dev);pm_runtime_put_sync (bdi->dev);bq24190_sysfs_remove_group (bdi);
@@ -1480,10 +1536,14 @@ static int bq24190_pm_suspend(struct device *dev) {struct i2c_client *client =to_i2c_client (dev);struct bq24190_dev_info *bdi =i2c_get_clientdata (client); +int error; -pm_runtime_get_sync (bdi->dev); + error =pm_runtime_get_sync (bdi->dev); +if (error <0 ) +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error);bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev);return 0 ; }
@@ -1492,15 +1552,19 @@ static int bq24190_pm_resume(struct device *dev) {struct i2c_client *client =to_i2c_client (dev);struct bq24190_dev_info *bdi =i2c_get_clientdata (client); +int error; bdi->f_reg =0 ; bdi->ss_reg =BQ24190_REG_SS_VBUS_STAT_MASK ;/* impossible state */ -pm_runtime_get_sync (bdi->dev); + error =pm_runtime_get_sync (bdi->dev); +if (error <0 ) +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error);bq24190_register_reset (bdi);bq24190_set_mode_host (bdi);bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev);/* Things may have changed while suspended so alert upper layer */ power_supply_changed (bdi->charger);
Signature · 1 line
2.11.0
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 3 lines · Tony Lindgren
We can get quite a few interrupts when the battery is trickle charging. Let's enable PM runtime autosuspend to avoid constantly toggling device state.
Which device state would constantly toggle?
Quoted 4 lines
Let's use a 600 ms timeout as that's how long the USB chager detection might take.
Cc Matt Ranostay <[email protected]>
We can probably drop Matt from this thread; he's been busy with the fuel gauge, etc.
Quoted 22 lines
Cc Liam Breck <[email protected]>Acked-by Mark Greer <[email protected]>Signed-off-by Tony Lindgren <[email protected]>--- drivers/power/supply/bq24190_charger.c | 122 +++++++++++++++++++++++++-------- 1 file changed, 93 insertions(+), 29 deletions(-)drivers/power/supply/bq24190_charger.c +1
-0@@ -420,6 +420,7 @@ static ssize_t bq24190_sysfs_show(struct device *dev,struct power_supply *psy =dev_get_drvdata (dev);struct bq24190_dev_info *bdi =power_supply_get_drvdata (psy);struct bq24190_sysfs_field_info *info; +ssize_t count;int ret;u8 v;@@ -427,11 +428,20 @@ static ssize_t bq24190_sysfs_show(struct device *dev,if (!info)return -EINVAL ;
drivers/power/supply/bq24190_charger.c static ssize_t bq24190_sysfs_show(struct device *dev, · line 439
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +7
-1+ ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret; + ret =bq24190_read_mask (bdi, info->reg, info->mask, info->shift, &v);if (ret) -return ret; + count = ret; +else + count =scnprintf (buf,PAGE_SIZE ,"%hhx\n" , v);
Unless it violates a style guide, I prefer
count = ret ? ret : scnprintf(buf, PAGE_SIZE, "%hhx\n", v);
Quoted 134 lines
drivers/power/supply/bq24190_charger.c +42
-12+ +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); -return scnprintf (buf,PAGE_SIZE ,"%hhx\n" , v); +return count; } static ssize_t bq24190_sysfs_store(struct device *dev,@@ -451,9 +461,16 @@ static ssize_t bq24190_sysfs_store(struct device *dev,if (ret <0 )return ret; + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret; + ret =bq24190_write_mask (bdi, info->reg, info->mask, info->shift, v);if (ret) -return ret; + count = ret; + +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev);return count; }@@ -795,7 +812,9 @@ static int bq24190_charger_get_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_CHARGE_TYPE :@@ -835,7 +854,9 @@ static int bq24190_charger_get_property(struct power_supply *psy, ret = -ENODATA ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }@@ -848,7 +869,9 @@ static int bq24190_charger_set_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_CHARGE_TYPE :@@ -864,7 +887,9 @@ static int bq24190_charger_set_property(struct power_supply *psy, ret = -EINVAL ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }@@ -1065,7 +1090,9 @@ static int bq24190_battery_get_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_STATUS :@@ -1093,7 +1120,9 @@ static int bq24190_battery_get_property(struct power_supply *psy, ret = -ENODATA ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }@@ -1106,7 +1135,9 @@ static int bq24190_battery_set_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_ONLINE :@@ -1119,7 +1150,9 @@ static int bq24190_battery_set_property(struct power_supply *psy, ret = -EINVAL ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }@@ -1234,11 +1267,15 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi)static irqreturn_t bq24190_irq_handler_thread (int irq,void *data) {struct bq24190_dev_info *bdi = data; +int ret; bdi->irq_event = true; -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;bq24190_check_status (bdi); -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); bdi->irq_event = false;return IRQ_HANDLED ;
drivers/power/supply/bq24190_charger.c static int bq24190_hw_init(struct bq24190_dev_info *bdi) · line 1291
Quoted 7 lines
drivers/power/supply/bq24190_charger.c +3
-1@@ -1249,7 +1286,9 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)u8 v;int ret; -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;
Why is pm_runtime_*() necessary in this function?probe() already calls pm_runtime_*() around hw_init(); nothing else calls it.
Quoted 14 lines
drivers/power/supply/bq24190_charger.c +3
-1/* First check that the device really is what its supposed to be */ ret = bq24190_read_mask(bdi, BQ24190_REG_VPRS,@@ -1274,7 +1313,9 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi) ret =bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); out: -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }
drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1405
Quoted 1 line
drivers/power/supply/bq24190_charger.c +0
-0@@ -1364,12 +1405,16 @@ static int bq24190_probe(struct i2c_client *client, }
v1 patchset called enable_irq_wake() here. v2 change list does not mention its removal.
Quoted 59 lines
drivers/power/supply/bq24190_charger.c +14
-8pm_runtime_enable (dev); -pm_runtime_resume (dev); +pm_runtime_set_autosuspend_delay (dev,600 ); +pm_runtime_use_autosuspend (dev); + ret =pm_runtime_get_sync (dev); +if (ret <0 ) + goto out1; ret =bq24190_hw_init (bdi);if (ret <0 ) {dev_err (dev,"Hardware init failed\n" ); - goto out1; + goto out2; } charger_cfg.drv_data = bdi;@@ -1380,7 +1425,7 @@ static int bq24190_probe(struct i2c_client *client,if (IS_ERR (bdi->charger)) {dev_err (dev,"Can't register charger\n" ); ret =PTR_ERR (bdi->charger); - goto out1; + goto out2; } battery_cfg.drv_data = bdi;@@ -1389,13 +1434,13 @@ static int bq24190_probe(struct i2c_client *client,if (IS_ERR (bdi->battery)) {dev_err (dev,"Can't register battery\n" ); ret =PTR_ERR (bdi->battery); - goto out2; + goto out3; } ret =bq24190_sysfs_create_group (bdi);if (ret) {dev_err (dev,"Can't create sysfs entries\n" ); - goto out3; + goto out4; } bdi->initialized = true;@@ -1406,21 +1451,28 @@ static int bq24190_probe(struct i2c_client *client, "bq24190-charger", bdi);if (ret <0 ) {dev_err (dev,"Can't set up irq handler\n" ); - goto out4; + goto out5; } +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); +return 0 ; -out4: +out5:bq24190_sysfs_remove_group (bdi); -out3:
drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1473
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +5
-1+out4:power_supply_unregister (bdi->battery); -out2: +out3:power_supply_unregister (bdi->charger); +out2: +pm_runtime_put_sync (dev); +
v2 change list does not mention this addition
Quoted 8 lines
drivers/power/supply/bq24190_charger.c +1
-0out1: +pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev);if (bdi->gpio_int)gpio_free (bdi->gpio_int);@@ -1430,9 +1482,13 @@ static int bq24190_probe(struct i2c_client *client,static int bq24190_remove (struct i2c_client *client) {
drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1492
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +5
-1struct bq24190_dev_info *bdi =i2c_get_clientdata (client); +int ret; -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , ret);bq24190_register_reset (bdi); +pm_runtime_dont_use_autosuspend (bdi->dev);pm_runtime_put_sync (bdi->dev);
Should skip these if get_sync() failed? Is pm_runtime_disable() needed here?
Quoted 5 lines
drivers/power/supply/bq24190_charger.c +0
-0bq24190_sysfs_remove_group (bdi);@@ -1480,10 +1536,14 @@ static int bq24190_pm_suspend(struct device *dev) {struct i2c_client *client =to_i2c_client (dev);struct bq24190_dev_info *bdi =i2c_get_clientdata (client);
drivers/power/supply/bq24190_charger.c static int bq24190_pm_suspend(struct device *dev) · line 1546
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +6
-2+int error; -pm_runtime_get_sync (bdi->dev); + error =pm_runtime_get_sync (bdi->dev); +if (error <0 ) +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error);bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev);
Should skip these if get_sync() failed?
Quoted 11 lines
drivers/power/supply/bq24190_charger.c +1
-0return 0 ; }@@ -1492,15 +1552,19 @@ static int bq24190_pm_resume(struct device *dev) {struct i2c_client *client =to_i2c_client (dev);struct bq24190_dev_info *bdi =i2c_get_clientdata (client); +int error; bdi->f_reg =0 ; bdi->ss_reg =BQ24190_REG_SS_VBUS_STAT_MASK ;/* impossible state */
drivers/power/supply/bq24190_charger.c static int bq24190_pm_resume(struct device *dev) · line 1567
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +5
-2-pm_runtime_get_sync (bdi->dev); + error =pm_runtime_get_sync (bdi->dev); +if (error <0 ) +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error);bq24190_register_reset (bdi);bq24190_set_mode_host (bdi);bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev);
Should skip these if get_sync() failed?
Thanks,
Liam
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 6 lines · Liam Breck
Quoted 3 lines · Tony Lindgren
We can get quite a few interrupts when the battery is trickle charging. Let's enable PM runtime autosuspend to avoid constantly toggling device state.
Which device state would constantly toggle?
The device driver PM runtime state. I've updated the description for that.
Quoted 4 lines
Quoted 1 line
Cc Matt Ranostay <[email protected]>We can probably drop Matt from this thread; he's been busy with the fuel gauge, etc.
Fair enough :)
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -427,11 +428,20 @@ static ssize_t bq24190_sysfs_show(struct device *dev, if (!info) return -EINVAL;
Quoted 13 lines
Review static ssize_t bq24190_sysfs_show(struct device *dev, · line 439
Quoted 10 lines
(quoted diff) +7
-1+ ret = pm_runtime_get_sync(bdi->dev); + if (ret < 0) + return ret; + ret = bq24190_read_mask(bdi, info->reg, info->mask, info->shift, &v); if (ret) - return ret; + count = ret; + else + count = scnprintf(buf, PAGE_SIZE, "%hhx\n", v);Unless it violates a style guide, I prefer
count = ret ? ret :scnprintf(buf, PAGE_SIZE, "%hhx\n", v);
I don't like that, I find it hard to read.
Quoted 11 lines
Review static int bq24190_hw_init(struct bq24190_dev_info *bdi) · line 1291
Quoted 8 lines
(quoted diff) +3
-1@@ -1249,7 +1286,9 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi) u8 v; int ret; - pm_runtime_get_sync(bdi->dev); + ret = pm_runtime_get_sync(bdi->dev); + if (ret < 0) + return ret;Why is pm_runtime_*() necessary in this function?
probe()already calls pm_runtime_*() aroundhw_init(); nothing else calls it.
Good point, it's not needed. I've removed the pm_runtime_calls.
Quoted 5 lines
Review static int bq24190_probe(struct i2c_client *client, · line 1405
Quoted 2 lines
(quoted diff) +0
-0@@ -1364,12 +1405,16 @@ static int bq24190_probe(struct i2c_client *client, }v1 patchset called
enable_irq_wake()here.
v2 change list does not mention its removal.
Oops sorry about that, that's a mismerge on the rebase. I've added that now to after request_threaded_irq().
Quoted 12 lines
Quoted 12 lines
(quoted diff) +3
-3-out4: +out5: bq24190_sysfs_remove_group(bdi); -out3: +out4: power_supply_unregister(bdi->battery); -out2: +out3: power_supply_unregister(bdi->charger);
Quoted 5 lines
Review static int bq24190_probe(struct i2c_client *client, · line 1417
Quoted 3 lines
(quoted diff) +3
-0+out2: + pm_runtime_put_sync(dev); +v2 change list does not mention this addition
Well I mentioned the changes for "mostly for the probe error handling" in the cover letter and that's needed as we now have the multiple out labels.
Quoted 6 lines
Quoted 6 lines
(quoted diff) +1
-0@@ -1430,9 +1482,13 @@ static int bq24190_probe(struct i2c_client *client, static int bq24190_remove(struct i2c_client *client) { struct bq24190_dev_info *bdi = i2c_get_clientdata(client); + int ret;
Quoted 9 lines
Review static int bq24190_probe(struct i2c_client *client, · line 1492
Quoted 7 lines
(quoted diff) +4
-1- pm_runtime_get_sync(bdi->dev); + ret = pm_runtime_get_sync(bdi->dev); + if (ret < 0) + dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret); bq24190_register_reset(bdi); + pm_runtime_dont_use_autosuspend(bdi->dev); pm_runtime_put_sync(bdi->dev);Should skip these if
get_sync()failed?
Yes, I've fixed it.
Quoted 1 line
Is
pm_runtime_disable()needed here?
Yes it's best to keep the pm_runtime calls always paired.
Quoted 6 lines
Quoted 6 lines
(quoted diff) +1
-0@@ -1480,10 +1536,14 @@ static int bq24190_pm_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct bq24190_dev_info *bdi = i2c_get_clientdata(client); + int error;
Quoted 10 lines
Review static int bq24190_pm_suspend(struct device *dev) · line 1546
Quoted 8 lines
(quoted diff) +5
-2- pm_runtime_get_sync(bdi->dev); + error = pm_runtime_get_sync(bdi->dev); + if (error < 0) + dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error); bq24190_register_reset(bdi); - pm_runtime_put_sync(bdi->dev); + pm_runtime_mark_last_busy(bdi->dev); + pm_runtime_put_autosuspend(bdi->dev);Should skip these if
get_sync()failed?
Yes fixed.
Quoted 9 lines
Quoted 9 lines
(quoted diff) +1
-0@@ -1492,15 +1552,19 @@ static int bq24190_pm_resume(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct bq24190_dev_info *bdi = i2c_get_clientdata(client); + int error; bdi->f_reg = 0; bdi->ss_reg = BQ24190_REG_SS_VBUS_STAT_MASK; /* impossible state */
Quoted 12 lines
Review static int bq24190_pm_resume(struct device *dev) · line 1567
Quoted 10 lines
(quoted diff) +5
-2- pm_runtime_get_sync(bdi->dev); + error = pm_runtime_get_sync(bdi->dev); + if (error < 0) + dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error); bq24190_register_reset(bdi); bq24190_set_mode_host(bdi); bq24190_read(bdi, BQ24190_REG_SS, &bdi->ss_reg); - pm_runtime_put_sync(bdi->dev); + pm_runtime_mark_last_busy(bdi->dev); + pm_runtime_put_autosuspend(bdi->dev);Should skip these if
get_sync()failed?
Here too.
Updated patch below with fixes for the comments above. I've dropped Mark's ack as there are several changes so please re-review.
Regards,
Tony
8< ---------------------------
Quoted 1 line
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Fri, 20 Jan 2017 09:58:51 -0800
Subject: [PATCH] power: bq24190_charger: Use PM runtime autosuspend
We can get quite a few interrupts when the battery is trickle charging. Let's enable PM runtime autosuspend to avoid constantly toggling device driver PM runtime state.
Let's use a 600 ms timeout as that's how long the USB chager detection might take.
--- drivers/power/supply/bq24190_charger.c | 147 ++++++++++++++++++++++----------- 1 file changed, 101 insertions(+), 46 deletions(-)
drivers/power/supply/bq24190_charger.c +101 -46
@@ -420,6 +420,7 @@ static ssize_t bq24190_sysfs_show(struct device *dev,struct power_supply *psy =dev_get_drvdata (dev);struct bq24190_dev_info *bdi =power_supply_get_drvdata (psy);struct bq24190_sysfs_field_info *info; +ssize_t count;int ret;u8 v;
@@ -427,11 +428,20 @@ static ssize_t bq24190_sysfs_show(struct device *dev,if (!info)return -EINVAL ; + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret; + ret =bq24190_read_mask (bdi, info->reg, info->mask, info->shift, &v);if (ret) -return ret; + count = ret; +else + count =scnprintf (buf,PAGE_SIZE ,"%hhx\n" , v); -return scnprintf (buf,PAGE_SIZE ,"%hhx\n" , v); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); + +return count; } static ssize_t bq24190_sysfs_store(struct device *dev,
@@ -451,9 +461,16 @@ static ssize_t bq24190_sysfs_store(struct device *dev,if (ret <0 )return ret; + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret; + ret =bq24190_write_mask (bdi, info->reg, info->mask, info->shift, v);if (ret) -return ret; + count = ret; + +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev);return count; }
@@ -795,7 +812,9 @@ static int bq24190_charger_get_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_CHARGE_TYPE :
@@ -835,7 +854,9 @@ static int bq24190_charger_get_property(struct power_supply *psy, ret = -ENODATA ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }
@@ -848,7 +869,9 @@ static int bq24190_charger_set_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_CHARGE_TYPE :
@@ -864,7 +887,9 @@ static int bq24190_charger_set_property(struct power_supply *psy, ret = -EINVAL ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }
@@ -1065,7 +1090,9 @@ static int bq24190_battery_get_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_STATUS :
@@ -1093,7 +1120,9 @@ static int bq24190_battery_get_property(struct power_supply *psy, ret = -ENODATA ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }
@@ -1106,7 +1135,9 @@ static int bq24190_battery_set_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_ONLINE :
@@ -1119,7 +1150,9 @@ static int bq24190_battery_set_property(struct power_supply *psy, ret = -EINVAL ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }
@@ -1234,11 +1267,15 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi)static irqreturn_t bq24190_irq_handler_thread (int irq,void *data) {struct bq24190_dev_info *bdi = data; +int ret; bdi->irq_event = true; -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;bq24190_check_status (bdi); -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); bdi->irq_event = false;return IRQ_HANDLED ;
@@ -1249,33 +1286,26 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)u8 v;int ret; -pm_runtime_get_sync (bdi->dev); -/* First check that the device really is what its supposed to be */ ret =bq24190_read_mask (bdi,BQ24190_REG_VPRS ,BQ24190_REG_VPRS_PN_MASK ,BQ24190_REG_VPRS_PN_SHIFT , &v);if (ret <0 ) - goto out; +return ret; -if (v != bdi->model) { - ret = -ENODEV ; - goto out; - } +if (v != bdi->model) +return -ENODEV ; ret =bq24190_register_reset (bdi);if (ret <0 ) - goto out; +return ret; ret =bq24190_set_mode_host (bdi);if (ret <0 ) - goto out; +return ret; - ret =bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); -out: -pm_runtime_put_sync (bdi->dev); -return ret; +return bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); }#ifdef CONFIG_OF
@@ -1364,12 +1394,16 @@ static int bq24190_probe(struct i2c_client *client, }pm_runtime_enable (dev); -pm_runtime_resume (dev); +pm_runtime_set_autosuspend_delay (dev,600 ); +pm_runtime_use_autosuspend (dev); + ret =pm_runtime_get_sync (dev); +if (ret <0 ) + goto out1; ret =bq24190_hw_init (bdi);if (ret <0 ) {dev_err (dev,"Hardware init failed\n" ); - goto out1; + goto out2; } charger_cfg.drv_data = bdi;
@@ -1380,7 +1414,7 @@ static int bq24190_probe(struct i2c_client *client,if (IS_ERR (bdi->charger)) {dev_err (dev,"Can't register charger\n" ); ret =PTR_ERR (bdi->charger); - goto out1; + goto out2; } battery_cfg.drv_data = bdi;
@@ -1389,13 +1423,13 @@ static int bq24190_probe(struct i2c_client *client,if (IS_ERR (bdi->battery)) {dev_err (dev,"Can't register battery\n" ); ret =PTR_ERR (bdi->battery); - goto out2; + goto out3; } ret =bq24190_sysfs_create_group (bdi);if (ret) {dev_err (dev,"Can't create sysfs entries\n" ); - goto out3; + goto out4; } bdi->initialized = true;
@@ -1406,21 +1440,30 @@ static int bq24190_probe(struct i2c_client *client, "bq24190-charger", bdi);if (ret <0 ) {dev_err (dev,"Can't set up irq handler\n" ); - goto out4; + goto out5; } +enable_irq_wake (bdi->irq); + +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); +return 0 ; -out4: +out5:bq24190_sysfs_remove_group (bdi); -out3: +out4:power_supply_unregister (bdi->battery); -out2: +out3:power_supply_unregister (bdi->charger); +out2: +pm_runtime_put_sync (dev); + out1: +pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev);if (bdi->gpio_int)gpio_free (bdi->gpio_int);
@@ -1431,13 +1474,17 @@ static int bq24190_remove(struct i2c_client *client) {struct bq24190_dev_info *bdi =i2c_get_clientdata (client); -pm_runtime_get_sync (bdi->dev); -bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); +if (!pm_runtime_get_sync (bdi->dev)) { +bq24190_register_reset (bdi); +pm_runtime_put_sync (bdi->dev); + }else { +dev_warn (bdi->dev,"pm_runtime_get failed\n" ); + }bq24190_sysfs_remove_group (bdi);power_supply_unregister (bdi->battery);power_supply_unregister (bdi->charger); +pm_runtime_dont_use_autosuspend (bdi->dev);pm_runtime_disable (bdi->dev);if (bdi->gpio_int)
@@ -1481,9 +1528,13 @@ static int bq24190_pm_suspend(struct device *dev)struct i2c_client *client =to_i2c_client (dev);struct bq24190_dev_info *bdi =i2c_get_clientdata (client); -pm_runtime_get_sync (bdi->dev); -bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); +if (!pm_runtime_get_sync (bdi->dev)) { +bq24190_register_reset (bdi); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); + }else { +dev_warn (bdi->dev,"pm_runtime_get failed\n" ); + }return 0 ; }
@@ -1496,11 +1547,15 @@ static int bq24190_pm_resume(struct device *dev) bdi->f_reg =0 ; bdi->ss_reg =BQ24190_REG_SS_VBUS_STAT_MASK ;/* impossible state */ -pm_runtime_get_sync (bdi->dev); -bq24190_register_reset (bdi); -bq24190_set_mode_host (bdi); -bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); -pm_runtime_put_sync (bdi->dev); +if (!pm_runtime_get_sync (bdi->dev)) { +bq24190_register_reset (bdi); +bq24190_set_mode_host (bdi); +bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); + }else { +dev_warn (bdi->dev,"pm_runtime_get failed\n" ); + }/* Things may have changed while suspended so alert upper layer */ power_supply_changed (bdi->charger);
Signature · 1 line
2.11.0
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 21 lines
From: Tony Lindgren <[email protected]>
Date: Fri, 20 Jan 2017 09:58:51 -0800
Subject: [PATCH] power:bq24190_charger: Use PM runtime autosuspendWe can get quite a few interrupts when the battery is trickle charging. Let's enable PM runtime autosuspend to avoid constantly toggling device driver PM runtime state.
Let's use a 600 ms timeout as that's how long the USB chager detection might take.
Cc Liam Breck <[email protected]>Cc Mark Greer <[email protected]>Signed-off-by Tony Lindgren <[email protected]>--- drivers/power/supply/bq24190_charger.c | 147 ++++++++++++++++++++++----------- 1 file changed, 101 insertions(+), 46 deletions(-)drivers/power/supply/bq24190_charger.c +0
-0
...
drivers/power/supply/bq24190_charger.c static int bq24190_remove(struct i2c_client *client) · line 1482
Quoted 13 lines
drivers/power/supply/bq24190_charger.c +6
-3@@ -1431,13 +1474,17 @@ static int bq24190_remove(struct i2c_client *client) {struct bq24190_dev_info *bdi =i2c_get_clientdata (client); -pm_runtime_get_sync (bdi->dev); -bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); +if (!pm_runtime_get_sync (bdi->dev)) { +bq24190_register_reset (bdi); +pm_runtime_put_sync (bdi->dev); + }else { +dev_warn (bdi->dev,"pm_runtime_get failed\n" ); + }
If we skip the register_reset, things may break.
Only the other pm_runtime_* calls should be skipped if get_sync() fails.
Quoted 11 lines
drivers/power/supply/bq24190_charger.c +1
-0bq24190_sysfs_remove_group (bdi);power_supply_unregister (bdi->battery);power_supply_unregister (bdi->charger); +pm_runtime_dont_use_autosuspend (bdi->dev);pm_runtime_disable (bdi->dev);if (bdi->gpio_int)@@ -1481,9 +1528,13 @@ static int bq24190_pm_suspend(struct device *dev)struct i2c_client *client =to_i2c_client (dev);struct bq24190_dev_info *bdi =i2c_get_clientdata (client);
drivers/power/supply/bq24190_charger.c static int bq24190_pm_suspend(struct device *dev) · line 1537
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +7
-3-pm_runtime_get_sync (bdi->dev); -bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); +if (!pm_runtime_get_sync (bdi->dev)) { +bq24190_register_reset (bdi); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); + }else { +dev_warn (bdi->dev,"pm_runtime_get failed\n" ); + }
Only the other pm_runtime_* calls should be skipped.
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +0
-4return 0 ; }@@ -1496,11 +1547,15 @@ static int bq24190_pm_resume(struct device *dev) bdi->f_reg =0 ; bdi->ss_reg =BQ24190_REG_SS_VBUS_STAT_MASK ;/* impossible state */ -pm_runtime_get_sync (bdi->dev); -bq24190_register_reset (bdi); -bq24190_set_mode_host (bdi); -bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg);
drivers/power/supply/bq24190_charger.c static int bq24190_pm_resume(struct device *dev) · line 1558
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +9
-1-pm_runtime_put_sync (bdi->dev); +if (!pm_runtime_get_sync (bdi->dev)) { +bq24190_register_reset (bdi); +bq24190_set_mode_host (bdi); +bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); + }else { +dev_warn (bdi->dev,"pm_runtime_get failed\n" ); + }
Only the other pm_runtime_* calls should be skipped.
Quoted 4 lines
drivers/power/supply/bq24190_charger.c +0
-1/* Things may have changed while suspended so alert upper layer */ power_supply_changed (bdi->charger); --2.11.0
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 26 lines · Liam Breck
Quoted 21 lines
From: Tony Lindgren <[email protected]>
Date: Fri, 20 Jan 2017 09:58:51 -0800
Subject: [PATCH] power:bq24190_charger: Use PM runtime autosuspendWe can get quite a few interrupts when the battery is trickle charging. Let's enable PM runtime autosuspend to avoid constantly toggling device driver PM runtime state.
Let's use a 600 ms timeout as that's how long the USB chager detection might take.
Cc Liam Breck <[email protected]>Cc Mark Greer <[email protected]>Signed-off-by Tony Lindgren <[email protected]>--- drivers/power/supply/bq24190_charger.c | 147 ++++++++++++++++++++++----------- 1 file changed, 101 insertions(+), 46 deletions(-)drivers/power/supply/bq24190_charger.c +0
-0...
Quoted 4 lines
drivers/power/supply/bq24190_charger.c +0
-0@@ -1431,13 +1474,17 @@ static int bq24190_remove(struct i2c_client *client) {struct bq24190_dev_info *bdi =i2c_get_clientdata (client);
Quoted 12 lines
drivers/power/supply/bq24190_charger.c static int bq24190_remove(struct i2c_client *client) · line 1482
Quoted 9 lines
drivers/power/supply/bq24190_charger.c +6
-3-pm_runtime_get_sync (bdi->dev); -bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); +if (!pm_runtime_get_sync (bdi->dev)) { +bq24190_register_reset (bdi); +pm_runtime_put_sync (bdi->dev); + }else { +dev_warn (bdi->dev,"pm_runtime_get failed\n" ); + }If we skip the
register_reset, things may break.
Only the other pm_runtime_* calls should be skipped ifget_sync()fails.
Hmm yeah I guess the pm_runtime_get() could fail and yet we still could have i2c access working. I've added handling with pm_runtime_put_noidle() on error. Also replaced int ret with int error as we're not returning anything. Updated patch below.
Regards,
Tony
8< -----------------------------------------
Quoted 1 line
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Fri, 20 Jan 2017 09:58:51 -0800
Subject: [PATCH] power: bq24190_charger: Use PM runtime autosuspend
We can get quite a few interrupts when the battery is trickle charging. Let's enable PM runtime autosuspend to avoid constantly toggling device driver PM runtime state.
Let's use a 600 ms timeout as that's how long the USB chager detection might take.
--- drivers/power/supply/bq24190_charger.c | 155 ++++++++++++++++++++++++--------- 1 file changed, 114 insertions(+), 41 deletions(-)
drivers/power/supply/bq24190_charger.c +114 -41
@@ -420,6 +420,7 @@ static ssize_t bq24190_sysfs_show(struct device *dev,struct power_supply *psy =dev_get_drvdata (dev);struct bq24190_dev_info *bdi =power_supply_get_drvdata (psy);struct bq24190_sysfs_field_info *info; +ssize_t count;int ret;u8 v;
@@ -427,11 +428,20 @@ static ssize_t bq24190_sysfs_show(struct device *dev,if (!info)return -EINVAL ; + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret; + ret =bq24190_read_mask (bdi, info->reg, info->mask, info->shift, &v);if (ret) -return ret; + count = ret; +else + count =scnprintf (buf,PAGE_SIZE ,"%hhx\n" , v); -return scnprintf (buf,PAGE_SIZE ,"%hhx\n" , v); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); + +return count; } static ssize_t bq24190_sysfs_store(struct device *dev,
@@ -451,9 +461,16 @@ static ssize_t bq24190_sysfs_store(struct device *dev,if (ret <0 )return ret; + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret; + ret =bq24190_write_mask (bdi, info->reg, info->mask, info->shift, v);if (ret) -return ret; + count = ret; + +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev);return count; }
@@ -795,7 +812,9 @@ static int bq24190_charger_get_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_CHARGE_TYPE :
@@ -835,7 +854,9 @@ static int bq24190_charger_get_property(struct power_supply *psy, ret = -ENODATA ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }
@@ -848,7 +869,9 @@ static int bq24190_charger_set_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_CHARGE_TYPE :
@@ -864,7 +887,9 @@ static int bq24190_charger_set_property(struct power_supply *psy, ret = -EINVAL ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }
@@ -1065,7 +1090,9 @@ static int bq24190_battery_get_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_STATUS :
@@ -1093,7 +1120,9 @@ static int bq24190_battery_get_property(struct power_supply *psy, ret = -ENODATA ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }
@@ -1106,7 +1135,9 @@ static int bq24190_battery_set_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_ONLINE :
@@ -1119,7 +1150,9 @@ static int bq24190_battery_set_property(struct power_supply *psy, ret = -EINVAL ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }
@@ -1234,11 +1267,15 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi)static irqreturn_t bq24190_irq_handler_thread (int irq,void *data) {struct bq24190_dev_info *bdi = data; +int ret; bdi->irq_event = true; -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;bq24190_check_status (bdi); -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); bdi->irq_event = false;return IRQ_HANDLED ;
@@ -1249,33 +1286,26 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)u8 v;int ret; -pm_runtime_get_sync (bdi->dev); -/* First check that the device really is what its supposed to be */ ret =bq24190_read_mask (bdi,BQ24190_REG_VPRS ,BQ24190_REG_VPRS_PN_MASK ,BQ24190_REG_VPRS_PN_SHIFT , &v);if (ret <0 ) - goto out; +return ret; -if (v != bdi->model) { - ret = -ENODEV ; - goto out; - } +if (v != bdi->model) +return -ENODEV ; ret =bq24190_register_reset (bdi);if (ret <0 ) - goto out; +return ret; ret =bq24190_set_mode_host (bdi);if (ret <0 ) - goto out; +return ret; - ret =bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); -out: -pm_runtime_put_sync (bdi->dev); -return ret; +return bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); }#ifdef CONFIG_OF
@@ -1364,12 +1394,16 @@ static int bq24190_probe(struct i2c_client *client, }pm_runtime_enable (dev); -pm_runtime_resume (dev); +pm_runtime_set_autosuspend_delay (dev,600 ); +pm_runtime_use_autosuspend (dev); + ret =pm_runtime_get_sync (dev); +if (ret <0 ) + goto out1; ret =bq24190_hw_init (bdi);if (ret <0 ) {dev_err (dev,"Hardware init failed\n" ); - goto out1; + goto out2; } charger_cfg.drv_data = bdi;
@@ -1380,7 +1414,7 @@ static int bq24190_probe(struct i2c_client *client,if (IS_ERR (bdi->charger)) {dev_err (dev,"Can't register charger\n" ); ret =PTR_ERR (bdi->charger); - goto out1; + goto out2; } battery_cfg.drv_data = bdi;
@@ -1389,13 +1423,13 @@ static int bq24190_probe(struct i2c_client *client,if (IS_ERR (bdi->battery)) {dev_err (dev,"Can't register battery\n" ); ret =PTR_ERR (bdi->battery); - goto out2; + goto out3; } ret =bq24190_sysfs_create_group (bdi);if (ret) {dev_err (dev,"Can't create sysfs entries\n" ); - goto out3; + goto out4; } bdi->initialized = true;
@@ -1406,21 +1440,30 @@ static int bq24190_probe(struct i2c_client *client, "bq24190-charger", bdi);if (ret <0 ) {dev_err (dev,"Can't set up irq handler\n" ); - goto out4; + goto out5; } +enable_irq_wake (bdi->irq); + +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); +return 0 ; -out4: +out5:bq24190_sysfs_remove_group (bdi); -out3: +out4:power_supply_unregister (bdi->battery); -out2: +out3:power_supply_unregister (bdi->charger); +out2: +pm_runtime_put_sync (dev); + out1: +pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev);if (bdi->gpio_int)gpio_free (bdi->gpio_int);
@@ -1430,10 +1473,20 @@ static int bq24190_probe(struct i2c_client *client,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 ) { +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error); +pm_runtime_put_noidle (bdi->dev); + } -pm_runtime_get_sync (bdi->dev);bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); + +if (!error) { +pm_runtime_dont_use_autosuspend (bdi->dev); +pm_runtime_put_sync (bdi->dev); + }bq24190_sysfs_remove_group (bdi);power_supply_unregister (bdi->battery);
@@ -1480,10 +1533,20 @@ static int bq24190_pm_suspend(struct device *dev) {struct i2c_client *client =to_i2c_client (dev);struct bq24190_dev_info *bdi =i2c_get_clientdata (client); +int error; + + error =pm_runtime_get_sync (bdi->dev); +if (error <0 ) { +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error); +pm_runtime_put_noidle (bdi->dev); + } -pm_runtime_get_sync (bdi->dev);bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); + +if (!error) { +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); + }return 0 ; }
@@ -1492,15 +1555,25 @@ static int bq24190_pm_resume(struct device *dev) {struct i2c_client *client =to_i2c_client (dev);struct bq24190_dev_info *bdi =i2c_get_clientdata (client); +int error; bdi->f_reg =0 ; bdi->ss_reg =BQ24190_REG_SS_VBUS_STAT_MASK ;/* impossible state */ -pm_runtime_get_sync (bdi->dev); + error =pm_runtime_get_sync (bdi->dev); +if (error <0 ) { +pm_runtime_put_noidle (bdi->dev); +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error); + } +bq24190_register_reset (bdi);bq24190_set_mode_host (bdi);bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); -pm_runtime_put_sync (bdi->dev); + +if (!error) { +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); + }/* Things may have changed while suspended so alert upper layer */ power_supply_changed (bdi->charger);
Signature · 1 line
2.11.0
Mark Greer
Acked-byRe: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 10 lines · Tony Lindgren
8< -----------------------------------------
Quoted 1 line
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Fri, 20 Jan 2017 09:58:51 -0800
Subject: [PATCH] power:bq24190_charger: Use PM runtime autosuspendWe can get quite a few interrupts when the battery is trickle charging. Let's enable PM runtime autosuspend to avoid constantly toggling device driver PM runtime state.
Quoted 7 lines
Let's use a 600 ms timeout as that's how long the USB chager detection might take.
Cc Liam Breck <[email protected]>Cc Mark Greer <[email protected]>Signed-off-by Tony Lindgren <[email protected]>---
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 15 lines · Mark Greer
Quoted 13 lines · Tony Lindgren
8< -----------------------------------------
Quoted 1 line
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Fri, 20 Jan 2017 09:58:51 -0800
Subject: [PATCH] power:bq24190_charger: Use PM runtime autosuspendWe can get quite a few interrupts when the battery is trickle charging. Let's enable PM runtime autosuspend to avoid constantly toggling device driver PM runtime state.
Let's use a 600 ms timeout as that's how long the USB chager detection might take.
Quoted 6 lines
Quoted 4 lines
Cc Liam Breck <[email protected]>Cc Mark Greer <[email protected]>Signed-off-by Tony Lindgren <[email protected]>---
Acked-by Mark Greer <[email protected]>
OK thanks will repost the two patches. Liam, got any more comments or care to ack?
Regards,
Tony
Liam Breck
Acked-byRe: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
In reply to Tony LindgrenQuoted 22 lines · Tony Lindgren
Quoted 2 lines
If we skip the
register_reset, things may break.
Only the other pm_runtime_* calls should be skipped ifget_sync()fails.Hmm yeah I guess the
pm_runtime_get()could fail and yet we still could have i2c access working. I've added handling withpm_runtime_put_noidle()on error. Also replaced int ret with int error as we're not returning anything. Updated patch below.Regards,
Tony
8< -----------------------------------------
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Fri, 20 Jan 2017 09:58:51 -0800
Subject: [PATCH] power:bq24190_charger: Use PM runtime autosuspendWe can get quite a few interrupts when the battery is trickle charging. Let's enable PM runtime autosuspend to avoid constantly toggling device driver PM runtime state.
Quoted 6 lines
Let's use a 600 ms timeout as that's how long the USB chager detection might take.
Cc Liam Breck <[email protected]>Cc Mark Greer <[email protected]>Signed-off-by Tony Lindgren <[email protected]>
Assuming resolution of my 2 comments below,
Quoted 291 lines
--- drivers/power/supply/bq24190_charger.c | 155 ++++++++++++++++++++++++--------- 1 file changed, 114 insertions(+), 41 deletions(-)drivers/power/supply/bq24190_charger.c +84
-35@@ -420,6 +420,7 @@ static ssize_t bq24190_sysfs_show(struct device *dev,struct power_supply *psy =dev_get_drvdata (dev);struct bq24190_dev_info *bdi =power_supply_get_drvdata (psy);struct bq24190_sysfs_field_info *info; +ssize_t count;int ret;u8 v;@@ -427,11 +428,20 @@ static ssize_t bq24190_sysfs_show(struct device *dev,if (!info)return -EINVAL ; + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret; + ret =bq24190_read_mask (bdi, info->reg, info->mask, info->shift, &v);if (ret) -return ret; + count = ret; +else + count =scnprintf (buf,PAGE_SIZE ,"%hhx\n" , v); -return scnprintf (buf,PAGE_SIZE ,"%hhx\n" , v); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); + +return count; } static ssize_t bq24190_sysfs_store(struct device *dev,@@ -451,9 +461,16 @@ static ssize_t bq24190_sysfs_store(struct device *dev,if (ret <0 )return ret; + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret; + ret =bq24190_write_mask (bdi, info->reg, info->mask, info->shift, v);if (ret) -return ret; + count = ret; + +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev);return count; }@@ -795,7 +812,9 @@ static int bq24190_charger_get_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_CHARGE_TYPE :@@ -835,7 +854,9 @@ static int bq24190_charger_get_property(struct power_supply *psy, ret = -ENODATA ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }@@ -848,7 +869,9 @@ static int bq24190_charger_set_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_CHARGE_TYPE :@@ -864,7 +887,9 @@ static int bq24190_charger_set_property(struct power_supply *psy, ret = -EINVAL ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }@@ -1065,7 +1090,9 @@ static int bq24190_battery_get_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_STATUS :@@ -1093,7 +1120,9 @@ static int bq24190_battery_get_property(struct power_supply *psy, ret = -ENODATA ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }@@ -1106,7 +1135,9 @@ static int bq24190_battery_set_property(struct power_supply *psy,dev_dbg (bdi->dev,"prop: %d\n" , psp); -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;switch (psp) {case POWER_SUPPLY_PROP_ONLINE :@@ -1119,7 +1150,9 @@ static int bq24190_battery_set_property(struct power_supply *psy, ret = -EINVAL ; } -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +return ret; }@@ -1234,11 +1267,15 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi)static irqreturn_t bq24190_irq_handler_thread (int irq,void *data) {struct bq24190_dev_info *bdi = data; +int ret; bdi->irq_event = true; -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) +return ret;bq24190_check_status (bdi); -pm_runtime_put_sync (bdi->dev); +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); bdi->irq_event = false;return IRQ_HANDLED ;@@ -1249,33 +1286,26 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)u8 v;int ret; -pm_runtime_get_sync (bdi->dev); -/* First check that the device really is what its supposed to be */ ret =bq24190_read_mask (bdi,BQ24190_REG_VPRS ,BQ24190_REG_VPRS_PN_MASK ,BQ24190_REG_VPRS_PN_SHIFT , &v);if (ret <0 ) - goto out; +return ret; -if (v != bdi->model) { - ret = -ENODEV ; - goto out; - } +if (v != bdi->model) +return -ENODEV ; ret =bq24190_register_reset (bdi);if (ret <0 ) - goto out; +return ret; ret =bq24190_set_mode_host (bdi);if (ret <0 ) - goto out; +return ret; - ret =bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); -out: -pm_runtime_put_sync (bdi->dev); -return ret; +return bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); }#ifdef CONFIG_OF @@ -1364,12 +1394,16 @@ static int bq24190_probe(struct i2c_client *client, }pm_runtime_enable (dev); -pm_runtime_resume (dev); +pm_runtime_set_autosuspend_delay (dev,600 ); +pm_runtime_use_autosuspend (dev); + ret =pm_runtime_get_sync (dev); +if (ret <0 ) + goto out1; ret =bq24190_hw_init (bdi);if (ret <0 ) {dev_err (dev,"Hardware init failed\n" ); - goto out1; + goto out2; } charger_cfg.drv_data = bdi;@@ -1380,7 +1414,7 @@ static int bq24190_probe(struct i2c_client *client,if (IS_ERR (bdi->charger)) {dev_err (dev,"Can't register charger\n" ); ret =PTR_ERR (bdi->charger); - goto out1; + goto out2; } battery_cfg.drv_data = bdi;@@ -1389,13 +1423,13 @@ static int bq24190_probe(struct i2c_client *client,if (IS_ERR (bdi->battery)) {dev_err (dev,"Can't register battery\n" ); ret =PTR_ERR (bdi->battery); - goto out2; + goto out3; } ret =bq24190_sysfs_create_group (bdi);if (ret) {dev_err (dev,"Can't create sysfs entries\n" ); - goto out3; + goto out4; } bdi->initialized = true;@@ -1406,21 +1440,30 @@ static int bq24190_probe(struct i2c_client *client, "bq24190-charger", bdi);if (ret <0 ) {dev_err (dev,"Can't set up irq handler\n" ); - goto out4; + goto out5; } +enable_irq_wake (bdi->irq); + +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); +return 0 ; -out4: +out5:bq24190_sysfs_remove_group (bdi); -out3: +out4:power_supply_unregister (bdi->battery); -out2: +out3:power_supply_unregister (bdi->charger); +out2: +pm_runtime_put_sync (dev); + out1: +pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev);if (bdi->gpio_int)gpio_free (bdi->gpio_int);@@ -1430,10 +1473,20 @@ static int bq24190_probe(struct i2c_client *client,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 ) { +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error); +pm_runtime_put_noidle (bdi->dev);
drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1489
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +6
-2+ } -pm_runtime_get_sync (bdi->dev);bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); + +if (!error) { +pm_runtime_dont_use_autosuspend (bdi->dev); +pm_runtime_put_sync (bdi->dev); + }
Should put_sync() be called before dont_use_autosuspend(), as in probe()?
Should the pm_runtime_disable() further on in remove() go inside the above block?
Quoted 55 lines
drivers/power/supply/bq24190_charger.c +24
-5bq24190_sysfs_remove_group (bdi);power_supply_unregister (bdi->battery);@@ -1480,10 +1533,20 @@ static int bq24190_pm_suspend(struct device *dev) {struct i2c_client *client =to_i2c_client (dev);struct bq24190_dev_info *bdi =i2c_get_clientdata (client); +int error; + + error =pm_runtime_get_sync (bdi->dev); +if (error <0 ) { +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error); +pm_runtime_put_noidle (bdi->dev); + } -pm_runtime_get_sync (bdi->dev);bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); + +if (!error) { +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); + }return 0 ; }@@ -1492,15 +1555,25 @@ static int bq24190_pm_resume(struct device *dev) {struct i2c_client *client =to_i2c_client (dev);struct bq24190_dev_info *bdi =i2c_get_clientdata (client); +int error; bdi->f_reg =0 ; bdi->ss_reg =BQ24190_REG_SS_VBUS_STAT_MASK ;/* impossible state */ -pm_runtime_get_sync (bdi->dev); + error =pm_runtime_get_sync (bdi->dev); +if (error <0 ) { +pm_runtime_put_noidle (bdi->dev); +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error); + } +bq24190_register_reset (bdi);bq24190_set_mode_host (bdi);bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); -pm_runtime_put_sync (bdi->dev); + +if (!error) { +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); + }/* Things may have changed while suspended so alert upper layer */ power_supply_changed (bdi->charger); --2.11.0
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 13 lines · Liam Breck
Quoted 12 lines · Tony Lindgren
drivers/power/supply/bq24190_charger.c +7
-0@@ -1430,10 +1473,20 @@ static int bq24190_probe(struct i2c_client *client,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 ) { +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error); +pm_runtime_put_noidle (bdi->dev); + }
Quoted 10 lines
drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1489
Quoted 8 lines
drivers/power/supply/bq24190_charger.c +5
-2-pm_runtime_get_sync (bdi->dev);bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); + +if (!error) { +pm_runtime_dont_use_autosuspend (bdi->dev); +pm_runtime_put_sync (bdi->dev); + }Should
put_sync()be called beforedont_use_autosuspend(), as inprobe()?
Yeah good to have them paired. With pm_runtime_put_noidle() we're active on error, so we can just call pm_runtime_dont_use_autosuspend() and pm_runtime_put_sync() unconditionally.
Quoted 2 lines
Should the
pm_runtime_disable()further on inremove()go inside the above block?
No need to because of the pm_runtime_put_noidle(). I'll just move the pm_runtime_dont_use_autosuspend() and pm_runtime_put_sync() to the end.
I'll repost both patches one more time with acks.
Regards,
Tony
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 25 lines · Tony Lindgren
Quoted 13 lines · Liam Breck
Quoted 12 lines · Tony Lindgren
drivers/power/supply/bq24190_charger.c +7
-0@@ -1430,10 +1473,20 @@ static int bq24190_probe(struct i2c_client *client,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 ) { +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error); +pm_runtime_put_noidle (bdi->dev); + }Quoted 10 lines
drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1489
Quoted 8 lines
drivers/power/supply/bq24190_charger.c +5
-2-pm_runtime_get_sync (bdi->dev);bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); + +if (!error) { +pm_runtime_dont_use_autosuspend (bdi->dev); +pm_runtime_put_sync (bdi->dev); + }Should
put_sync()be called beforedont_use_autosuspend(), as inprobe()?
Quoted 3 lines
Yeah good to have them paired. With
pm_runtime_put_noidle()we're active on error, so we can just callpm_runtime_dont_use_autosuspend()andpm_runtime_put_sync()unconditionally.
I meant should the two pm_runtime_* calls above be flipped, so put_sync() is first. That's the order in probe()
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 26 lines · Liam Breck
Quoted 25 lines · Tony Lindgren
Quoted 23 lines · Liam Breck
Quoted 10 lines · Tony Lindgren
drivers/power/supply/bq24190_charger.c +6
-0@@ -1430,10 +1473,20 @@ static int bq24190_probe(struct i2c_client *client,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 ) { +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error); +pm_runtime_put_noidle (bdi->dev);drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1489
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +6
-2+ } -pm_runtime_get_sync (bdi->dev);bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); + +if (!error) { +pm_runtime_dont_use_autosuspend (bdi->dev); +pm_runtime_put_sync (bdi->dev); + }Should
put_sync()be called beforedont_use_autosuspend(), as inprobe()?
Quoted 6 lines
Quoted 3 lines
Yeah good to have them paired. With
pm_runtime_put_noidle()we're active on error, so we can just callpm_runtime_dont_use_autosuspend()andpm_runtime_put_sync()unconditionally.I meant should the two pm_runtime_* calls above be flipped, so
put_sync()is first. That's the order inprobe()
Oh I see yeah ideally yes.
Regards,
Tony