Two bq24190 PM improvments
v2 cover Two bq24190 PM improvments
Hi,
Here's a repost of the two bq24190 patches rebased against current power-supply tree.
Regards,
Tony
Changes from v1:
- Call pm_runtime_dont_use_autosuspend() and pm_runtime_put_sync() unconditionally in bq24190_remove() as suggested by Liam
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 | 211 +++++++++++++++++++++++++-------- 1 file changed, 161 insertions(+), 50 deletions(-)
Signature · 1 line
2.11.0
PATCH v2 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 30 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 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 +0
-0
drivers/power/supply/bq24190_charger.c static int bq24190_pm_resume(struct device *dev) · line 1516
Quoted 8 lines
drivers/power/supply/bq24190_charger.c +4
-1@@ -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)
Can delete newline before NULL) here, if so inclined :-)
PATCH v2 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 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 | 153 ++++++++++++++++++++++++--------- 1 file changed, 111 insertions(+), 42 deletions(-)
drivers/power/supply/bq24190_charger.c +111 -42
@@ -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,14 +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; -pm_runtime_get_sync (bdi->dev); -bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); + 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); + } +bq24190_register_reset (bdi);bq24190_sysfs_remove_group (bdi);power_supply_unregister (bdi->battery);power_supply_unregister (bdi->charger); +pm_runtime_dont_use_autosuspend (bdi->dev); +pm_runtime_put_sync (bdi->dev);pm_runtime_disable (bdi->dev);if (bdi->gpio_int)
@@ -1480,10 +1529,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 +1551,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
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Hi, these emails are missing v2 in subject line.
Quoted 20 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 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]>Acked-by Mark Greer <[email protected]>Acked-by Liam Breck <[email protected]>Signed-off-by Tony Lindgren <[email protected]>--- drivers/power/supply/bq24190_charger.c | 153 ++++++++++++++++++++++++--------- 1 file changed, 111 insertions(+), 42 deletions(-)drivers/power/supply/bq24190_charger.c +0
-0
drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1401
Quoted 9 lines
drivers/power/supply/bq24190_charger.c +5
-1@@ -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;
Call get_sync() before set_autosuspend() ?
Quoted 55 lines
drivers/power/supply/bq24190_charger.c +12
-7ret =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);
drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1466
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +5
-1-out2: +out3:power_supply_unregister (bdi->charger); +out2: +pm_runtime_put_sync (dev); + out1: +pm_runtime_dont_use_autosuspend (dev);
Change order of above two if my prev comment is right.
Quoted 14 lines
drivers/power/supply/bq24190_charger.c +3
-3pm_runtime_disable (dev);if (bdi->gpio_int)gpio_free (bdi->gpio_int);@@ -1430,14 +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; -pm_runtime_get_sync (bdi->dev); -bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); + error =pm_runtime_get_sync (bdi->dev); +if (error <0 ) {
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
-0+dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error); +pm_runtime_put_noidle (bdi->dev); + } +bq24190_register_reset (bdi);bq24190_sysfs_remove_group (bdi);power_supply_unregister (bdi->battery);power_supply_unregister (bdi->charger); +pm_runtime_dont_use_autosuspend (bdi->dev); +pm_runtime_put_sync (bdi->dev);
Alternatively, switch order of above two.
drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1492
Quoted 3 lines
drivers/power/supply/bq24190_charger.c +0
-0pm_runtime_disable (bdi->dev);if (bdi->gpio_int)
Apologies if I'm nitpicking!
~.~
Tony Lindgren
Acked-by Mark GreerRe: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 1 line · Liam Breck
Hi, these emails are missing v2 in subject line.
Oh sorry it's in the cover letter. Looks like you did not get Cc:ed on the cover letter, I need to update my scripts to properly collect all the acks to the cover letter.
Quoted 7 lines · Tony Lindgren
Quoted 6 lines
drivers/power/supply/bq24190_charger.c +0
-0@@ -1364,12 +1394,16 @@ static int bq24190_probe(struct i2c_client *client, }
Quoted 9 lines
drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1401
Quoted 7 lines
drivers/power/supply/bq24190_charger.c +5
-1pm_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;Call
get_sync()beforeset_autosuspend()?
No need to, but I'll move pm_runtime_set_autosuspend_delay() after pm_runtime_use_autosuspend() :)
Quoted 4 lines
drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1403
Quoted 2 lines
drivers/power/supply/bq24190_charger.c +1
-0out1: +pm_runtime_dont_use_autosuspend (dev);Change order of above two if my prev comment is right.
No need to.
Quoted 15 lines
Quoted 15 lines
drivers/power/supply/bq24190_charger.c +6
-3@@ -1430,14 +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; -pm_runtime_get_sync (bdi->dev); -bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); + 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 8 lines
drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1489
Quoted 6 lines
drivers/power/supply/bq24190_charger.c +3
-0+bq24190_register_reset (bdi);bq24190_sysfs_remove_group (bdi);power_supply_unregister (bdi->battery);power_supply_unregister (bdi->charger); +pm_runtime_dont_use_autosuspend (bdi->dev); +pm_runtime_put_sync (bdi->dev);Alternatively, switch order of above two.
Yeah will do.
Quoted 1 line
Apologies if I'm nitpicking!
No worries, this should be a boringly trivial patch so it's good to have somebody look through it to avoid bad changes. Updated patch below, please check and re-ack if it now looks OK to you.
Regards,
Tony
8< ---------------------
Quoted 1 line
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Mon, 30 Jan 2017 07:10:31 -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 | 153 ++++++++++++++++++++++++--------- 1 file changed, 111 insertions(+), 42 deletions(-)
drivers/power/supply/bq24190_charger.c +111 -42
@@ -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_use_autosuspend (dev); +pm_runtime_set_autosuspend_delay (dev,600 ); + 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,14 +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; -pm_runtime_get_sync (bdi->dev); -bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); + 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); + } +bq24190_register_reset (bdi);bq24190_sysfs_remove_group (bdi);power_supply_unregister (bdi->battery);power_supply_unregister (bdi->charger); +pm_runtime_put_sync (bdi->dev); +pm_runtime_dont_use_autosuspend (bdi->dev);pm_runtime_disable (bdi->dev);if (bdi->gpio_int)
@@ -1480,10 +1529,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 +1551,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
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 30 lines · Tony Lindgren
From: Tony Lindgren <[email protected]>
Date: Mon, 30 Jan 2017 07:10:31 -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]>Acked-by Mark Greer <[email protected]>Signed-off-by Tony Lindgren <[email protected]>--- drivers/power/supply/bq24190_charger.c | 153 ++++++++++++++++++++++++--------- 1 file changed, 111 insertions(+), 42 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;
drivers/power/supply/bq24190_charger.c static ssize_t bq24190_sysfs_show(struct device *dev, · line 433
Quoted 6 lines
drivers/power/supply/bq24190_charger.c +3
-0@@ -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;
Let's not stop here if get_sync fails.
Quoted 16 lines
drivers/power/supply/bq24190_charger.c +7
-2ret =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,
drivers/power/supply/bq24190_charger.c static ssize_t bq24190_sysfs_store(struct device *dev, · line 466
Quoted 6 lines
drivers/power/supply/bq24190_charger.c +3
-0@@ -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;
Nor here 2.
Quoted 11 lines
drivers/power/supply/bq24190_charger.c +4
-1ret =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; }
drivers/power/supply/bq24190_charger.c static int bq24190_charger_get_property(struct power_supply *psy, · line 817
Quoted 7 lines
drivers/power/supply/bq24190_charger.c +3
-1@@ -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;
Nor here 3.
Quoted 14 lines
drivers/power/supply/bq24190_charger.c +3
-1switch (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; }
drivers/power/supply/bq24190_charger.c static int bq24190_charger_set_property(struct power_supply *psy, · line 874
Quoted 7 lines
drivers/power/supply/bq24190_charger.c +3
-1@@ -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;
Nor here 4.
Quoted 14 lines
drivers/power/supply/bq24190_charger.c +3
-1switch (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; }
drivers/power/supply/bq24190_charger.c static int bq24190_battery_get_property(struct power_supply *psy, · line 1095
Quoted 7 lines
drivers/power/supply/bq24190_charger.c +3
-1@@ -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;
Nor here 5.
Quoted 14 lines
drivers/power/supply/bq24190_charger.c +3
-1switch (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; }
drivers/power/supply/bq24190_charger.c static int bq24190_battery_set_property(struct power_supply *psy, · line 1140
Quoted 7 lines
drivers/power/supply/bq24190_charger.c +3
-1@@ -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;
Nor here 6.
Quoted 14 lines
drivers/power/supply/bq24190_charger.c +3
-1switch (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; }
drivers/power/supply/bq24190_charger.c static void bq24190_check_status(struct bq24190_dev_info *bdi) · line 1275
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +4
-1@@ -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;
Nor here 7.
Quoted 48 lines
drivers/power/supply/bq24190_charger.c +8
-14bq24190_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
drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1401
Quoted 9 lines
drivers/power/supply/bq24190_charger.c +5
-1@@ -1364,12 +1394,16 @@ static int bq24190_probe(struct i2c_client *client, }pm_runtime_enable (dev); -pm_runtime_resume (dev); +pm_runtime_use_autosuspend (dev); +pm_runtime_set_autosuspend_delay (dev,600 ); + ret =pm_runtime_get_sync (dev); +if (ret <0 ) + goto out1;
Nor here 8.
Quoted 130 lines
drivers/power/supply/bq24190_charger.c +44
-14ret =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,14 +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; -pm_runtime_get_sync (bdi->dev); -bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); + 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); + } +bq24190_register_reset (bdi);bq24190_sysfs_remove_group (bdi);power_supply_unregister (bdi->battery);power_supply_unregister (bdi->charger); +pm_runtime_put_sync (bdi->dev); +pm_runtime_dont_use_autosuspend (bdi->dev);pm_runtime_disable (bdi->dev);if (bdi->gpio_int)@@ -1480,10 +1529,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 +1551,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); + }
drivers/power/supply/bq24190_charger.c static int bq24190_pm_resume(struct device *dev) · line 1572
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +6
-1+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); + }
We need helper funcs...
static inline int bq24190_pmrt_get(struct device* dev) {
int err = pm_runtime_get_sync(dev);
if (err < 0) {
dev_warn(dev, "pm_runtime_get failed: %i\n", err);
pm_runtime_put_noidle(dev); }
return err;
}
static inline void bq24190_pmrt_put(struct device* dev, int err) {
if (!err) {
pm_runtime_mark_last_busy(dev);
pm_runtime_put_autosuspend(dev); }
}
Apologies, should have raised this on last version!
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 9 lines · Liam Breck
drivers/power/supply/bq24190_charger.c static ssize_t bq24190_sysfs_show(struct device *dev, · line 433
Quoted 7 lines
drivers/power/supply/bq24190_charger.c +3
-0@@ -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;Let's not stop here if
get_syncfails.
Hmm care to describe why we would want to ignore errors on pm_runtime_get()? I don't think that's a good idea.. And for sysfs_show() output?
If these calls fail it's a sign of a serious problem somewhere and it should be fixed instead of ignoring the errors and attempting to continue. Ignoring errors with these calls can lead into problems that are hard to debug.
Quoted 12 lines
drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1401
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +5
-1@@ -1364,12 +1394,16 @@ static int bq24190_probe(struct i2c_client *client, }pm_runtime_enable (dev); -pm_runtime_resume (dev); +pm_runtime_use_autosuspend (dev); +pm_runtime_set_autosuspend_delay (dev,600 ); + ret =pm_runtime_get_sync (dev); +if (ret <0 ) + goto out1;Nor here 8.
Eek, let's not try to continue the probe if pm_runtime_get_fails. Let's just assume it's either implemented and must be working, or a nop operation that will not do anything. Depending on the implementation, this could affect something in the hardware like pin multiplexing, parent device clocking.. On the module exit path it might make sense as we know the device was working to get there so it might be possible to do something :)
Quoted 11 lines
We need helper funcs...
static inline int
bq24190_pmrt_get(struct device* dev){
int err =pm_runtime_get_sync(dev);if (err < 0) { dev_warn(dev, "pm_runtime_get failed: %i\n", err); pm_runtime_put_noidle(dev);}
return err;
}
Quoted 6 lines
static inline void
bq24190_pmrt_put(struct device* dev, int err){if (!err) { pm_runtime_mark_last_busy(dev); pm_runtime_put_autosuspend(dev);}
}
If you want to implement something like that it should probably be done in a Linux generic way. There's still quite a bit boilerplate code needed for the autosuspend usage.
Regards,
Tony
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
In reply to Tony LindgrenQuoted 30 lines · Tony Lindgren
From: Tony Lindgren <[email protected]>
Date: Mon, 30 Jan 2017 07:10:31 -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]>Acked-by Mark Greer <[email protected]>Signed-off-by Tony Lindgren <[email protected]>--- drivers/power/supply/bq24190_charger.c | 153 ++++++++++++++++++++++++--------- 1 file changed, 111 insertions(+), 42 deletions(-)drivers/power/supply/bq24190_charger.c +1
-1@@ -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);
drivers/power/supply/bq24190_charger.c static void bq24190_check_status(struct bq24190_dev_info *bdi) · line 1281
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +5
-1+ 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 ;
OK get_sync() failure should return error to userspace callers, and abort probe(), makes sense.
But should the interrupt handler (above) emit a warning and continue as in resume() and suspend()?
If not is ret the right value to return in lieu of irq_handled?
Tony Lindgren
Acked-by Mark GreerRe: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 21 lines · Liam Breck
Quoted 20 lines · Tony Lindgren
drivers/power/supply/bq24190_charger.c +6
-2@@ -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;
Quoted 4 lines
drivers/power/supply/bq24190_charger.c static void bq24190_check_status(struct bq24190_dev_info *bdi) · line 1281
Quoted 1 line
drivers/power/supply/bq24190_charger.c +0
-0return IRQ_HANDLED ;OK
get_sync()failure should return error to userspace callers, and abortprobe(), makes sense.
OK
Quoted 2 lines
But should the interrupt handler (above) emit a warning and continue as in
resume()andsuspend()?
The interrupt subsystem will retry and eventually just give up with errors. No need to do anything special here to disable the irq, let's just add dev_err().
Quoted 1 line
If not is ret the right value to return in lieu of
irq_handled?
Oh you're right, we should return IRQ_NONE here.
Updated patch below doing dev_err() + IRQ_NONE.
Regards,
Tony
8< ----------------
Quoted 1 line
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Mon, 30 Jan 2017 07:10:31 -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 | 156 ++++++++++++++++++++++++--------- 1 file changed, 114 insertions(+), 42 deletions(-)
drivers/power/supply/bq24190_charger.c +114 -42
@@ -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,18 @@ 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 ) { +dev_err (bdi->dev,"Runtime PM failed in %s: %i\n" , + __func__, ret); +return IRQ_NONE ; + }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 +1289,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 +1397,16 @@ static int bq24190_probe(struct i2c_client *client, }pm_runtime_enable (dev); -pm_runtime_resume (dev); +pm_runtime_use_autosuspend (dev); +pm_runtime_set_autosuspend_delay (dev,600 ); + 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 +1417,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 +1426,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 +1443,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,14 +1476,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; -pm_runtime_get_sync (bdi->dev); -bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); + 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); + } +bq24190_register_reset (bdi);bq24190_sysfs_remove_group (bdi);power_supply_unregister (bdi->battery);power_supply_unregister (bdi->charger); +pm_runtime_put_sync (bdi->dev); +pm_runtime_dont_use_autosuspend (bdi->dev);pm_runtime_disable (bdi->dev);if (bdi->gpio_int)
@@ -1480,10 +1532,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 +1554,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
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 27 lines · Tony Lindgren
...
From: Tony Lindgren <[email protected]>
Date: Mon, 30 Jan 2017 07:10:31 -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]>Acked-by Mark Greer <[email protected]>Signed-off-by Tony Lindgren <[email protected]>--- drivers/power/supply/bq24190_charger.c | 156 ++++++++++++++++++++++++--------- 1 file changed, 114 insertions(+), 42 deletions(-)drivers/power/supply/bq24190_charger.c +0
-0@@ -1234,11 +1267,18 @@ 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;
drivers/power/supply/bq24190_charger.c static void bq24190_check_status(struct bq24190_dev_info *bdi) · line 1278
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +7
-1+int ret; bdi->irq_event = true; -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) { +dev_err (bdi->dev,"Runtime PM failed in %s: %i\n" , + __func__, ret); +return IRQ_NONE ; + }
Now this is a nitpick... Error msg should be consistent with suspend/resume:
drivers/power/supply/bq24190_charger.c static int bq24190_pm_suspend(struct device *dev) · line 1541
Quoted 11 lines
drivers/power/supply/bq24190_charger.c +7
-0@@ -1480,10 +1532,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); + }
Like here.
Quoted 5 lines
drivers/power/supply/bq24190_charger.c +1
-0@@ -1492,15 +1554,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;
drivers/power/supply/bq24190_charger.c static int bq24190_pm_resume(struct device *dev) · line 1566
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +5
-1bdi->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); + }
And here.
Tony Lindgren
Acked-by Mark GreerRe: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 10 lines · Liam Breck
Quoted 9 lines · Tony Lindgren
drivers/power/supply/bq24190_charger.c +1
-0@@ -1234,11 +1267,18 @@ 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;
Quoted 10 lines
drivers/power/supply/bq24190_charger.c static void bq24190_check_status(struct bq24190_dev_info *bdi) · line 1278
Quoted 8 lines
drivers/power/supply/bq24190_charger.c +6
-1bdi->irq_event = true; -pm_runtime_get_sync (bdi->dev); + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) { +dev_err (bdi->dev,"Runtime PM failed in %s: %i\n" , + __func__, ret); +return IRQ_NONE ; + }Now this is a nitpick... Error msg should be consistent with suspend/resume:
Sure, updated below.
Regards,
Tony
8< ----------------
Quoted 1 line
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Mon, 30 Jan 2017 07:10:31 -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, 113 insertions(+), 42 deletions(-)
drivers/power/supply/bq24190_charger.c +113 -42
@@ -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,17 @@ 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 ) { +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , ret); +return IRQ_NONE ; + }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 +1288,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 +1396,16 @@ static int bq24190_probe(struct i2c_client *client, }pm_runtime_enable (dev); -pm_runtime_resume (dev); +pm_runtime_use_autosuspend (dev); +pm_runtime_set_autosuspend_delay (dev,600 ); + 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 +1416,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 +1425,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 +1442,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,14 +1475,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; -pm_runtime_get_sync (bdi->dev); -bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); + 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); + } +bq24190_register_reset (bdi);bq24190_sysfs_remove_group (bdi);power_supply_unregister (bdi->battery);power_supply_unregister (bdi->charger); +pm_runtime_put_sync (bdi->dev); +pm_runtime_dont_use_autosuspend (bdi->dev);pm_runtime_disable (bdi->dev);if (bdi->gpio_int)
@@ -1480,10 +1531,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 +1553,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
Liam Breck
Acked-byRe: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 8 lines · Tony Lindgren
From: Tony Lindgren <[email protected]>
Date: Mon, 30 Jan 2017 07:10:31 -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]>Acked-by Mark Greer <[email protected]>Signed-off-by Tony Lindgren <[email protected]>
Quoted 28 lines
drivers/power/supply/bq24190_charger.c +13
-2@@ -1480,10 +1531,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 +1553,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;
drivers/power/supply/bq24190_charger.c static int bq24190_pm_resume(struct device *dev) · line 1565
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +5
-1bdi->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); + }
Last nitpick: call put_noidle after dev_warn, as in suspend :-)
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 6 lines · Liam Breck
Quoted 3 lines · Tony Lindgren
Cc Liam Breck <[email protected]>Acked-by Mark Greer <[email protected]>Signed-off-by Tony Lindgren <[email protected]>Acked-by Liam Breck <[email protected]>
Thanks for looking though it.
Quoted 9 lines
Quoted 9 lines
drivers/power/supply/bq24190_charger.c +1
-0@@ -1492,15 +1553,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 */
Quoted 8 lines
drivers/power/supply/bq24190_charger.c static int bq24190_pm_resume(struct device *dev) · line 1565
Quoted 6 lines
drivers/power/supply/bq24190_charger.c +5
-1-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); + }Last nitpick: call
put_noidleafterdev_warn, as in suspend :-)
Sure, will do that and repost v3 of both patches shortly.
Regards,
Tony
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
In reply to Tony LindgrenQuoted 34 lines · Tony Lindgren
From: Tony Lindgren <[email protected]>
Date: Mon, 30 Jan 2017 07:10:31 -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]>Acked-by Mark Greer <[email protected]>Signed-off-by Tony Lindgren <[email protected]>--- drivers/power/supply/bq24190_charger.c | 155 ++++++++++++++++++++++++--------- 1 file changed, 113 insertions(+), 42 deletions(-)drivers/power/supply/bq24190_charger.c +4
-3@@ -1430,14 +1475,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; -pm_runtime_get_sync (bdi->dev); -bq24190_register_reset (bdi); -pm_runtime_put_sync (bdi->dev); + error =pm_runtime_get_sync (bdi->dev); +if (error <0 ) { +dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error);
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
-0+pm_runtime_put_noidle (bdi->dev); + } +bq24190_register_reset (bdi);bq24190_sysfs_remove_group (bdi);power_supply_unregister (bdi->battery);power_supply_unregister (bdi->charger); +pm_runtime_put_sync (bdi->dev); +pm_runtime_dont_use_autosuspend (bdi->dev);pm_runtime_disable (bdi->dev);
I think you addressed this, but should the above be
if (!error)
pm_runtime_put_sync(bdi->dev);
Re: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 23 lines · Liam Breck
Quoted 11 lines · Tony Lindgren
static int
bq24190_remove(struct i2c_client *client){ struct bq24190_dev_info *bdi = i2c_get_clientdata(client);(quoted diff) +4
-3+ int error; - pm_runtime_get_sync(bdi->dev); - bq24190_register_reset(bdi); - pm_runtime_put_sync(bdi->dev); + error = pm_runtime_get_sync(bdi->dev); + if (error < 0) { + dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);Review
Quoted 10 lines
(quoted diff) +5
-0+ pm_runtime_put_noidle(bdi->dev); + } + bq24190_register_reset(bdi); bq24190_sysfs_remove_group(bdi); power_supply_unregister(bdi->battery); power_supply_unregister(bdi->charger); + pm_runtime_put_sync(bdi->dev); + pm_runtime_dont_use_autosuspend(bdi->dev); pm_runtime_disable(bdi->dev);
Quoted 4 lines
I think you addressed this, but should the above be
if (!error)
pm_runtime_put_sync(bdi->dev);
Hmm yeah.. But we need to check for if (error >= 0), also in the other places see below.
Regards,
Tony
8< --------------------
drivers/power/supply/bq24190_charger.c +4 -3
@@ -1487,7 +1487,8 @@ static int bq24190_remove(struct i2c_client *client)bq24190_sysfs_remove_group (bdi);power_supply_unregister (bdi->battery);power_supply_unregister (bdi->charger); -pm_runtime_put_sync (bdi->dev); +if (error >=0 ) +pm_runtime_put_sync (bdi->dev);pm_runtime_dont_use_autosuspend (bdi->dev);pm_runtime_disable (bdi->dev);
@@ -1541,7 +1542,7 @@ static int bq24190_pm_suspend(struct device *dev)bq24190_register_reset (bdi); -if (!error) { +if (error >=0 ) {pm_runtime_mark_last_busy (bdi->dev);pm_runtime_put_autosuspend (bdi->dev); }
@@ -1568,7 +1569,7 @@ static int bq24190_pm_resume(struct device *dev)bq24190_set_mode_host (bdi);bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); -if (!error) { +if (error >=0 ) {pm_runtime_mark_last_busy (bdi->dev);pm_runtime_put_autosuspend (bdi->dev); }
Signature · 1 line
2.11.0
Liam Breck
Acked-byRe: [PATCH 2/2] power: bq24190_charger: Use PM runtime autosuspend
Quoted 24 lines · Tony Lindgren
Quoted 23 lines · Liam Breck
Quoted 21 lines · Tony Lindgren
static int
bq24190_remove(struct i2c_client *client){ struct bq24190_dev_info *bdi = i2c_get_clientdata(client);(quoted diff) +9
-3+ int error; - pm_runtime_get_sync(bdi->dev); - bq24190_register_reset(bdi); - pm_runtime_put_sync(bdi->dev); + 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); + } + bq24190_register_reset(bdi); bq24190_sysfs_remove_group(bdi); power_supply_unregister(bdi->battery); power_supply_unregister(bdi->charger); + pm_runtime_put_sync(bdi->dev); + pm_runtime_dont_use_autosuspend(bdi->dev); pm_runtime_disable(bdi->dev);
Quoted 7 lines
Quoted 4 lines
I think you addressed this, but should the above be
if (!error)
pm_runtime_put_sync(bdi->dev);Hmm yeah.. But we need to check for if (error >= 0), also in the other places see below.
OK, let's roll v4. it is
(and pls include the v4 in all subjects :-)
I have a patchset for DT support in the works which depends on this one.