power: supply: bq24190_charger: Various fixes + extcon support
cover power: supply: bq24190_charger: Various fixes + extcon support
Hi Sebastian, Liam, All,
As discussed here is a v2 of my bq24190 charges. I'm not 100% sure the last patch should go upstream as is, we do want to remove the battery power_supply but I'm not sure about the timing of doing so.
Quoted 1 line
From my pov the other patches are ready for merging, but I guess there
may be some remarks and a v3 of this set will be necessary :)
Regards,
Hans
PATCH v2 1/7 power: supply: bq24190_charger: Use i2c-core irq-mapping code
The i2c-core already maps of irqs before calling the driver's probe function and there are no in tree users of bq24190_platform_data->gpio_int.
Remove the redundant custom irq-mapping code and just use client->irq.
---
Changes in v2:
-Completely drop platform_data and include/linux/power/bq24190_charger.h
--- drivers/power/supply/bq24190_charger.c | 66 ++-------------------------------- include/linux/power/bq24190_charger.h | 16 --------- 2 files changed, 3 insertions(+), 79 deletions(-) delete mode 100644 include/linux/power/bq24190_charger.h
drivers/power/supply/bq24190_charger.c +3 -63
@@ -18,9 +18,6 @@#include <linux/gpio.h> #include <linux/i2c.h> -#include <linux/power/bq24190_charger.h> - -#define BQ24190_MANUFACTURER "Texas Instruments"#define BQ24190_REG_ISC 0x00/* Input Source Control */
@@ -153,8 +150,6 @@ struct bq24190_dev_info {struct power_supply *battery;char model_name[I2C_NAME_SIZE ];kernel_ulong_t model; -unsigned int gpio_int; -unsigned int irq;bool initialized;bool irq_event;struct mutex f_reg_lock;
@@ -1310,56 +1305,11 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)return bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); } -#ifdef CONFIG_OF -static int bq24190_setup_dt (struct bq24190_dev_info *bdi) -{ - bdi->irq =irq_of_parse_and_map (bdi->dev->of_node,0 ); -if (bdi->irq <=0 ) -return -1 ; - -return 0 ; -} -#else -static int bq24190_setup_dt (struct bq24190_dev_info *bdi) -{ -return -1 ; -} -#endif - -static int bq24190_setup_pdata (struct bq24190_dev_info *bdi, -struct bq24190_platform_data *pdata) -{ -int ret; - -if (!gpio_is_valid (pdata->gpio_int)) -return -1 ; - - ret =gpio_request (pdata->gpio_int,dev_name (bdi->dev)); -if (ret <0 ) -return -1 ; - - ret =gpio_direction_input (pdata->gpio_int); -if (ret <0 ) - goto out; - - bdi->irq =gpio_to_irq (pdata->gpio_int); -if (!bdi->irq) - goto out; - - bdi->gpio_int = pdata->gpio_int; -return 0 ; - -out: -gpio_free (pdata->gpio_int); -return -1 ; -} -static int bq24190_probe (struct i2c_client *client,const struct i2c_device_id *id) {struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent);struct device *dev = &client->dev; -struct bq24190_platform_data *pdata = client->dev.platform_data;struct power_supply_config charger_cfg = {}, battery_cfg = {};struct bq24190_dev_info *bdi;int ret;
@@ -1385,12 +1335,7 @@ static int bq24190_probe(struct i2c_client *client,i2c_set_clientdata (client, bdi); -if (dev->of_node) - ret =bq24190_setup_dt (bdi); -else - ret =bq24190_setup_pdata (bdi, pdata); - -if (ret) { +if (!client->irq) {dev_err (dev,"Can't get irq info\n" );return -EINVAL ; }
@@ -1436,7 +1381,7 @@ static int bq24190_probe(struct i2c_client *client, bdi->initialized = true; - ret =devm_request_threaded_irq (dev, bdi->irq,NULL , + ret =devm_request_threaded_irq (dev, client->irq,NULL , bq24190_irq_handler_thread,IRQF_TRIGGER_FALLING |IRQF_ONESHOT ,"bq24190-charger" , bdi);
@@ -1445,7 +1390,7 @@ static int bq24190_probe(struct i2c_client *client, goto out5; } -enable_irq_wake (bdi->irq); +enable_irq_wake (client->irq);pm_runtime_mark_last_busy (dev);pm_runtime_put_autosuspend (dev);
@@ -1467,8 +1412,6 @@ static int bq24190_probe(struct i2c_client *client, out1:pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev); -if (bdi->gpio_int) -gpio_free (bdi->gpio_int);return ret; }
@@ -1492,9 +1435,6 @@ static int bq24190_remove(struct i2c_client *client)pm_runtime_dont_use_autosuspend (bdi->dev);pm_runtime_disable (bdi->dev); -if (bdi->gpio_int) -gpio_free (bdi->gpio_int); -return 0 ; }
include/linux/power/bq24190_charger.h deleted +0 -16
@@ -1,16 +0,0 @@ -/* -* Platform data for the TI bq24190 battery charger driver. -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -*/ - -#ifndef _BQ24190_CHARGER_H_ -#define _BQ24190_CHARGER_H_ - -struct bq24190_platform_data { -unsigned int gpio_int;/* GPIO pin that's connected to INT# */ -}; - -#endif
Signature · 1 line
2.9.3
Re: [PATCH v2 1/7] power: supply: bq24190_charger: Use i2c-core irq-mapping code
Quoted 5 lines · Hans de Goede
The i2c-core already maps of irqs before calling the driver's probe function and there are no in tree users of
bq24190_platform_data->gpio_int.Remove the redundant custom irq-mapping code and just use
client->irq.
Looks right to me:
Sebastian Reichel
maintainerRe: [PATCH v2 1/7] power: supply: bq24190_charger: Use i2c-core irq-mapping code
In reply to Hans de GoedeHi,
Quoted 11 lines · Hans de Goede
The i2c-core already maps of irqs before calling the driver's probe function and there are no in tree users of
bq24190_platform_data->gpio_int.Remove the redundant custom irq-mapping code and just use
client->irq.Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>
Quoted 4 lines
---
Changes in v2:
-Completely dropplatform_dataandinclude/linux/power/bq24190_charger.h
---
Thanks, queued.
-- Sebastian
Re: [PATCH v2 1/7] power: supply: bq24190_charger: Use i2c-core irq-mapping code
In reply to Hans de GoedeQuoted 11 lines · Hans de Goede
The i2c-core already maps of irqs before calling the driver's probe function and there are no in tree users of
bq24190_platform_data->gpio_int.Remove the redundant custom irq-mapping code and just use
client->irq.Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>
Quoted 165 lines
---
Changes in v2:(quoted diff) +0
-2-Completely drop platform_data and include/linux/power/bq24190_charger.h --- drivers/power/supply/bq24190_charger.c | 66 ++-------------------------------- include/linux/power/bq24190_charger.h | 16 --------- 2 files changed, 3 insertions(+), 79 deletions(-) delete mode 100644 include/linux/power/bq24190_charger.hdrivers/power/supply/bq24190_charger.c +3
-63@@ -18,9 +18,6 @@#include <linux/gpio.h> #include <linux/i2c.h> -#include <linux/power/bq24190_charger.h> - -#define BQ24190_MANUFACTURER "Texas Instruments"#define BQ24190_REG_ISC 0x00/* Input Source Control */ @@ -153,8 +150,6 @@ struct bq24190_dev_info {struct power_supply *battery;char model_name[I2C_NAME_SIZE ];kernel_ulong_t model; -unsigned int gpio_int; -unsigned int irq;bool initialized;bool irq_event;struct mutex f_reg_lock;@@ -1310,56 +1305,11 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)return bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg); } -#ifdef CONFIG_OF -static int bq24190_setup_dt (struct bq24190_dev_info *bdi) -{ - bdi->irq =irq_of_parse_and_map (bdi->dev->of_node,0 ); -if (bdi->irq <=0 ) -return -1 ; - -return 0 ; -} -#else -static int bq24190_setup_dt (struct bq24190_dev_info *bdi) -{ -return -1 ; -} -#endif - -static int bq24190_setup_pdata (struct bq24190_dev_info *bdi, -struct bq24190_platform_data *pdata) -{ -int ret; - -if (!gpio_is_valid (pdata->gpio_int)) -return -1 ; - - ret =gpio_request (pdata->gpio_int,dev_name (bdi->dev)); -if (ret <0 ) -return -1 ; - - ret =gpio_direction_input (pdata->gpio_int); -if (ret <0 ) - goto out; - - bdi->irq =gpio_to_irq (pdata->gpio_int); -if (!bdi->irq) - goto out; - - bdi->gpio_int = pdata->gpio_int; -return 0 ; - -out: -gpio_free (pdata->gpio_int); -return -1 ; -} -static int bq24190_probe (struct i2c_client *client,const struct i2c_device_id *id) {struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent);struct device *dev = &client->dev; -struct bq24190_platform_data *pdata = client->dev.platform_data;struct power_supply_config charger_cfg = {}, battery_cfg = {};struct bq24190_dev_info *bdi;int ret;@@ -1385,12 +1335,7 @@ static int bq24190_probe(struct i2c_client *client,i2c_set_clientdata (client, bdi); -if (dev->of_node) - ret =bq24190_setup_dt (bdi); -else - ret =bq24190_setup_pdata (bdi, pdata); - -if (ret) { +if (!client->irq) {dev_err (dev,"Can't get irq info\n" );return -EINVAL ; }@@ -1436,7 +1381,7 @@ static int bq24190_probe(struct i2c_client *client, bdi->initialized = true; - ret =devm_request_threaded_irq (dev, bdi->irq,NULL , + ret =devm_request_threaded_irq (dev, client->irq,NULL , bq24190_irq_handler_thread,IRQF_TRIGGER_FALLING |IRQF_ONESHOT ,"bq24190-charger" , bdi);@@ -1445,7 +1390,7 @@ static int bq24190_probe(struct i2c_client *client, goto out5; } -enable_irq_wake (bdi->irq); +enable_irq_wake (client->irq);pm_runtime_mark_last_busy (dev);pm_runtime_put_autosuspend (dev);@@ -1467,8 +1412,6 @@ static int bq24190_probe(struct i2c_client *client, out1:pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev); -if (bdi->gpio_int) -gpio_free (bdi->gpio_int);return ret; }@@ -1492,9 +1435,6 @@ static int bq24190_remove(struct i2c_client *client)pm_runtime_dont_use_autosuspend (bdi->dev);pm_runtime_disable (bdi->dev); -if (bdi->gpio_int) -gpio_free (bdi->gpio_int); -return 0 ; }include/linux/power/bq24190_charger.h deleted +0
-17@@ -1,16 +0,0 @@ -/* -* Platform data for the TI bq24190 battery charger driver. -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -*/ - -#ifndef _BQ24190_CHARGER_H_ -#define _BQ24190_CHARGER_H_ - -struct bq24190_platform_data { -unsigned int gpio_int;/* GPIO pin that's connected to INT# */ -}; - -#endif --2.9.3
PATCH v2 2/7 power: supply: bq24190_charger: Add support for bq24192i
In reply to Hans de GoedeThe bq24192 and bq24192i are mostly identical to the bq24190, TI even published a single datasheet for all 3 of them. The difference between the bq24190 and bq24192[i] is the way charger-type detection is done, the bq24190 is to be directly connected to the USB a/b lines, where as the the bq24192[i] has a gpio which should be driven high/low externally depending on the type of charger connected, from a register level access pov there is no difference.
The differences between the bq24192 and bq24192i are:
1) Lower default charge rate on the bq24192i
2) Pre-charge-current can be max 640 mA on the bq24192i
On x86/ACPI systems the code which instantiates the i2c client may not know the exact variant being used, so instead of coding the model-id in the i2c_id struct and bailing if it does not match, check the reported model-id matches one of the supported variants.
This commit only adds support for the bq24192i as I don't have a bq24192 to test with, adding support for the bq24192 should be as simple as also accepting its model-id in the model-id test.
---
Changes in v2:
-Improve commit msg
-Drop model-id from bq24190_i2c_ids table and bdi struct -Only add support for the bq24192i and not for the bq24192
--- drivers/power/supply/bq24190_charger.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/power/supply/bq24190_charger.c +6 -9
@@ -149,7 +149,6 @@ struct bq24190_dev_info {struct power_supply *charger;struct power_supply *battery;char model_name[I2C_NAME_SIZE ]; -kernel_ulong_t model;bool initialized;bool irq_event;struct mutex f_reg_lock;
@@ -1291,8 +1290,11 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)if (ret <0 )return ret; -if (v != bdi->model) +if (v !=BQ24190_REG_VPRS_PN_24190 && + v !=BQ24190_REG_VPRS_PN_24192I ) { +dev_err (bdi->dev,"Error unknown model: 0x%02x\n" , v);return -ENODEV ; + } ret =bq24190_register_reset (bdi);if (ret <0 )
@@ -1327,7 +1329,6 @@ static int bq24190_probe(struct i2c_client *client, bdi->client = client; bdi->dev = dev; - bdi->model = id->driver_data;strncpy (bdi->model_name, id->name,I2C_NAME_SIZE );mutex_init (&bdi->f_reg_lock); bdi->f_reg =0 ;
@@ -1526,13 +1527,9 @@ static const struct dev_pm_ops bq24190_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(bq24190_pm_suspend, bq24190_pm_resume) }; -/* -* Only support the bq24190 right now. The bq24192, bq24192i, and bq24193 -* are similar but not identical so the driver needs to be extended to -* support them. -*/ static const struct i2c_device_id bq24190_i2c_ids[] = { - {"bq24190" ,BQ24190_REG_VPRS_PN_24190 }, + {"bq24190" }, + {"bq24192i" }, { }, };MODULE_DEVICE_TABLE (i2c, bq24190_i2c_ids);
Signature · 1 line
2.9.3
Sebastian Reichel
maintainerRe: [PATCH v2 2/7] power: supply: bq24190_charger: Add support for bq24192i
Hi,
Quoted 26 lines · Hans de Goede
The bq24192 and bq24192i are mostly identical to the bq24190, TI even published a single datasheet for all 3 of them. The difference between the bq24190 and bq24192[i] is the way charger-type detection is done, the bq24190 is to be directly connected to the USB a/b lines, where as the the bq24192[i] has a gpio which should be driven high/low externally depending on the type of charger connected, from a register level access pov there is no difference.
The differences between the bq24192 and bq24192i are:
1) Lower default charge rate on the bq24192i
2) Pre-charge-current can be max 640 mA on the bq24192iOn x86/ACPI systems the code which instantiates the i2c client may not know the exact variant being used, so instead of coding the model-id in the
i2c_idstruct and bailing if it does not match, check the reported model-id matches one of the supported variants.This commit only adds support for the bq24192i as I don't have a bq24192 to test with, adding support for the bq24192 should be as simple as also accepting its model-id in the model-id test.
Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
Review
Quoted 4 lines
(quoted diff) +0
-4-Improve commit msg -Drop model-id from bq24190_i2c_ids table and bdi struct -Only add support for the bq24192i and not for the bq24192 ---
Thanks, queued.
-- Sebastian
Re: [PATCH v2 2/7] power: supply: bq24190_charger: Add support for bq24192i
In reply to Hans de GoedeQuoted 17 lines · Hans de Goede
The bq24192 and bq24192i are mostly identical to the bq24190, TI even published a single datasheet for all 3 of them. The difference between the bq24190 and bq24192[i] is the way charger-type detection is done, the bq24190 is to be directly connected to the USB a/b lines, where as the the bq24192[i] has a gpio which should be driven high/low externally depending on the type of charger connected, from a register level access pov there is no difference.
The differences between the bq24192 and bq24192i are:
1) Lower default charge rate on the bq24192i
2) Pre-charge-current can be max 640 mA on the bq24192iOn x86/ACPI systems the code which instantiates the i2c client may not know the exact variant being used, so instead of coding the model-id in the
i2c_idstruct and bailing if it does not match, check the reported model-id matches one of the supported variants.
Quoted 7 lines
This commit only adds support for the bq24192i as I don't have a bq24192 to test with, adding support for the bq24192 should be as simple as also accepting its model-id in the model-id test.
Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>
Quoted 61 lines
---
Changes in v2:(quoted diff) +0
-4-Improve commit msg -Drop model-id from bq24190_i2c_ids table and bdi struct -Only add support for the bq24192i and not for the bq24192 --- drivers/power/supply/bq24190_charger.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)drivers/power/supply/bq24190_charger.c +6
-10@@ -149,7 +149,6 @@ struct bq24190_dev_info {struct power_supply *charger;struct power_supply *battery;char model_name[I2C_NAME_SIZE ]; -kernel_ulong_t model;bool initialized;bool irq_event;struct mutex f_reg_lock;@@ -1291,8 +1290,11 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)if (ret <0 )return ret; -if (v != bdi->model) +if (v !=BQ24190_REG_VPRS_PN_24190 && + v !=BQ24190_REG_VPRS_PN_24192I ) { +dev_err (bdi->dev,"Error unknown model: 0x%02x\n" , v);return -ENODEV ; + } ret =bq24190_register_reset (bdi);if (ret <0 )@@ -1327,7 +1329,6 @@ static int bq24190_probe(struct i2c_client *client, bdi->client = client; bdi->dev = dev; - bdi->model = id->driver_data;strncpy (bdi->model_name, id->name,I2C_NAME_SIZE );mutex_init (&bdi->f_reg_lock); bdi->f_reg =0 ;@@ -1526,13 +1527,9 @@ static const struct dev_pm_ops bq24190_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(bq24190_pm_suspend, bq24190_pm_resume) }; -/* -* Only support the bq24190 right now. The bq24192, bq24192i, and bq24193 -* are similar but not identical so the driver needs to be extended to -* support them. -*/ static const struct i2c_device_id bq24190_i2c_ids[] = { - {"bq24190" ,BQ24190_REG_VPRS_PN_24190 }, + {"bq24190" }, + {"bq24192i" }, { }, };MODULE_DEVICE_TABLE (i2c, bq24190_i2c_ids); --2.9.3
PATCH v2 3/7 power: supply: bq24190_charger: Use extcon to determine ilimit, 5v boost
In reply to Hans de GoedeAdd support for monitoring an extcon device with USB SDP/CDP/DCP and HOST cables and adjust ilimit and enable/disable the 5V boost converter accordingly. This is necessary on systems where the PSEL pin is hardwired high and ILIM needs to be set by software based on the detected charger type, as well as on systems where the 5V boost converter is used, as that always needs to be enabled from software.
---
Changes in v2:
-Use a device-property for extcon-name instead of platform_data -Delay 300ms before applying the extcon detected charger-type to iinlim
(see the added comment for why this is done)
--- drivers/power/supply/Kconfig | 1 + drivers/power/supply/bq24190_charger.c | 107 +++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+)
drivers/power/supply/Kconfig +1 -0
@@ -442,6 +442,7 @@ config CHARGER_BQ2415X config CHARGER_BQ24190 tristate "TI BQ24190 battery charger driver" depends on I2C + depends on EXTCON depends on GPIOLIB || COMPILE_TEST help Say Y to enable support for the TI BQ24190 battery charger.
drivers/power/supply/bq24190_charger.c +107 -0
159 lines not on this page · raw message
Signature · 1 line
2.9.3
Re: [PATCH v2 3/7] power: supply: bq24190_charger: Use extcon to determine ilimit, 5v boost
Quoted 6 lines · Hans de Goede
Add support for monitoring an extcon device with USB SDP/CDP/DCP and HOST cables and adjust ilimit and enable/disable the 5V boost converter accordingly. This is necessary on systems where the PSEL pin is hardwired high and ILIM needs to be set by software based on the detected charger type, as well as on systems where the 5V boost converter is used, as that always needs to be enabled from software.
I wonder if these cross device and cross subsystem events really should be handled at the framework level? Otherwise the permutations get out of control fast..
Regards,
Tony
Re: [PATCH v2 3/7] power: supply: bq24190_charger: Use extcon to determine ilimit, 5v boost
Hi,
Quoted 11 lines · Tony Lindgren
Quoted 6 lines · Hans de Goede
Add support for monitoring an extcon device with USB SDP/CDP/DCP and HOST cables and adjust ilimit and enable/disable the 5V boost converter accordingly. This is necessary on systems where the PSEL pin is hardwired high and ILIM needs to be set by software based on the detected charger type, as well as on systems where the 5V boost converter is used, as that always needs to be enabled from software.
I wonder if these cross device and cross subsystem events really should be handled at the framework level? Otherwise the permutations get out of control fast..
There are a lot of hw specific things in here which are hard to generalize, like not only setting iilim but also enabling the booster when there is no charger and we are in host mode (the no charger condition is necessary for USB ACAs).
Regards,
Hans
Re: [PATCH v2 3/7] power: supply: bq24190_charger: Use extcon to determine ilimit, 5v boost
In reply to Hans de GoedeQuoted 170 lines · Hans de Goede
Add support for monitoring an extcon device with USB SDP/CDP/DCP and HOST cables and adjust ilimit and enable/disable the 5V boost converter accordingly. This is necessary on systems where the PSEL pin is hardwired high and ILIM needs to be set by software based on the detected charger type, as well as on systems where the 5V boost converter is used, as that always needs to be enabled from software.
Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-3-Use a device-property for extcon-name instead of platform_data -Delay 300ms before applying the extcon detected charger-type to iinlim (see the added comment for why this is done) --- drivers/power/supply/Kconfig | 1 + drivers/power/supply/bq24190_charger.c | 107 +++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+)drivers/power/supply/Kconfig +1
-0@@ -442,6 +442,7 @@ config CHARGER_BQ2415X config CHARGER_BQ24190 tristate "TI BQ24190 battery charger driver" depends on I2C + depends on EXTCON depends on GPIOLIB || COMPILE_TEST help Say Y to enable support for the TI BQ24190 battery charger.drivers/power/supply/bq24190_charger.c +85
-0@@ -11,10 +11,12 @@#include <linux/module.h> #include <linux/interrupt.h> #include <linux/delay.h> +#include <linux/extcon.h> #include <linux/of_irq.h> #include <linux/of_device.h> #include <linux/pm_runtime.h> #include <linux/power_supply.h> +#include <linux/workqueue.h> #include <linux/gpio.h> #include <linux/i2c.h> @@ -36,6 +38,8 @@#define BQ24190_REG_POC_WDT_RESET_SHIFT 6#define BQ24190_REG_POC_CHG_CONFIG_MASK (BIT(5) | BIT(4))#define BQ24190_REG_POC_CHG_CONFIG_SHIFT 4 +#define BQ24190_REG_POC_CHG_CONFIG_CHARGE 1 +#define BQ24190_REG_POC_CHG_CONFIG_OTG 2#define BQ24190_REG_POC_SYS_MIN_MASK (BIT(3) | BIT(2) | BIT(1))#define BQ24190_REG_POC_SYS_MIN_SHIFT 1#define BQ24190_REG_POC_BOOST_LIM_MASK BIT(0)@@ -148,6 +152,9 @@ struct bq24190_dev_info {struct device *dev;struct power_supply *charger;struct power_supply *battery; +struct extcon_dev *extcon; +struct notifier_block extcon_nb; +struct delayed_work extcon_work;char model_name[I2C_NAME_SIZE ];bool initialized;bool irq_event;@@ -164,6 +171,11 @@ struct bq24190_dev_info {* number at that index in the array is the real-world value that it * represents. */ + +/* REG00[2:0] (IINLIM) in uAh */ +static const int bq24190_iinlim_values[] = { +100000 ,150000 ,500000 ,900000 ,1200000 ,1500000 ,2000000 ,3000000 }; +/* REG02[7:2] (ICHG) in uAh */ static const int bq24190_ccc_ichg_values[] = {512000 ,576000 ,640000 ,704000 ,768000 ,832000 ,896000 ,960000 ,@@ -1277,6 +1289,78 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)return IRQ_HANDLED ; } +static void bq24190_extcon_work (struct work_struct *work) +{ +struct bq24190_dev_info *bdi = + container_of(work, struct bq24190_dev_info, extcon_work.work); +int ret, iinlim =0 ; + + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) { +dev_err (bdi->dev,"Error getting runtime-pm ref: %d\n" , ret); +return ; + } + +if (extcon_get_state (bdi->extcon,EXTCON_CHG_USB_SDP ) ==1 ) + iinlim =500000 ; +else if (extcon_get_state (bdi->extcon,EXTCON_CHG_USB_CDP ) ==1 || +extcon_get_state (bdi->extcon,EXTCON_CHG_USB_ACA ) ==1 ) + iinlim =1500000 ; +else if (extcon_get_state (bdi->extcon,EXTCON_CHG_USB_DCP ) ==1 ) + iinlim =2000000 ; + +if (iinlim) { + ret =bq24190_set_field_val (bdi,BQ24190_REG_ISC , +BQ24190_REG_ISC_IINLIM_MASK , +BQ24190_REG_ISC_IINLIM_SHIFT , + bq24190_iinlim_values, +ARRAY_SIZE (bq24190_iinlim_values), + iinlim); +if (ret) +dev_err (bdi->dev,"Can't set IINLIM: %d\n" , ret); + } + +/* +* If no charger has been detected and host mode is requested, activate +* the 5V boost converter, otherwise deactivate it. +*/ +if (!iinlim &&extcon_get_state (bdi->extcon,EXTCON_USB_HOST ) ==1 ) { + ret =bq24190_write_mask (bdi,BQ24190_REG_POC , +BQ24190_REG_POC_CHG_CONFIG_MASK , +BQ24190_REG_POC_CHG_CONFIG_SHIFT , +BQ24190_REG_POC_CHG_CONFIG_OTG ); + }else { + ret =bq24190_write_mask (bdi,BQ24190_REG_POC , +BQ24190_REG_POC_CHG_CONFIG_MASK , +BQ24190_REG_POC_CHG_CONFIG_SHIFT , +BQ24190_REG_POC_CHG_CONFIG_CHARGE ); + } +if (ret) +dev_err (bdi->dev,"Can't set CHG_CONFIG: %d\n" , ret); + +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +} + +static int bq24190_extcon_event (struct notifier_block *nb,unsigned long event, +void *param) +{ +struct bq24190_dev_info *bdi = + container_of(nb, struct bq24190_dev_info, extcon_nb); + +/* +* The Power-Good detection may take up to 220ms, sometimes +* the external charger detection is quicker, and the bq24190 will +* reset to iinlim based on its own charger detection (which is not +* hooked up when using external charger detection) resulting in +* a too low default 500mA iinlim. Delay applying the extcon value +* for 300ms to avoid this. +*/ +queue_delayed_work (system_wq, &bdi->extcon_work,msecs_to_jiffies (300 )); + +return NOTIFY_OK ; +} +static int bq24190_hw_init (struct bq24190_dev_info *bdi) {u8 v;@@ -1314,6 +1398,7 @@ static int bq24190_probe(struct i2c_client *client,struct device *dev = &client->dev;struct power_supply_config charger_cfg = {}, battery_cfg = {};struct bq24190_dev_info *bdi; +const char *name;int ret;if (!i2c_check_functionality (adapter,I2C_FUNC_SMBUS_BYTE_DATA )) {@@ -1341,6 +1426,16 @@ static int bq24190_probe(struct i2c_client *client,return -EINVAL ;
drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1436
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +8
-0} +/* +* The extcon-name property is purely an in kernel interface for +* x86/ACPI use, DT platforms should get extcon via phandle. +*/ +if (device_property_read_string (dev,"extcon-name" , &name) ==0 ) { + bdi->extcon =extcon_get_extcon_dev (name); +if (!bdi->extcon) +return -EPROBE_DEFER ;
needs
dev_info(bdi->dev, "using extcon device %s\n", name);
I didn't see the device property for preferred charge voltage limit from v1 patchset?
Quoted 27 lines
drivers/power/supply/bq24190_charger.c +14
-1+ } +pm_runtime_enable (dev);pm_runtime_use_autosuspend (dev);pm_runtime_set_autosuspend_delay (dev,600 );@@ -1391,6 +1486,18 @@ static int bq24190_probe(struct i2c_client *client, goto out5; } +if (bdi->extcon) { +INIT_DELAYED_WORK (&bdi->extcon_work, bq24190_extcon_work); + bdi->extcon_nb.notifier_call = bq24190_extcon_event; + ret =devm_extcon_register_notifier (dev, bdi->extcon,-1 , + &bdi->extcon_nb); +if (ret) + goto out5; + +/* Sync initial cable state */ +queue_delayed_work (system_wq, &bdi->extcon_work,0 ); + } +enable_irq_wake (client->irq);pm_runtime_mark_last_busy (dev); --2.9.3
Re: [PATCH v2 3/7] power: supply: bq24190_charger: Use extcon to determine ilimit, 5v boost
Hi,
Quoted 183 lines · Liam Breck
Quoted 170 lines · Hans de Goede
Add support for monitoring an extcon device with USB SDP/CDP/DCP and HOST cables and adjust ilimit and enable/disable the 5V boost converter accordingly. This is necessary on systems where the PSEL pin is hardwired high and ILIM needs to be set by software based on the detected charger type, as well as on systems where the 5V boost converter is used, as that always needs to be enabled from software.
Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-3-Use a device-property for extcon-name instead of platform_data -Delay 300ms before applying the extcon detected charger-type to iinlim (see the added comment for why this is done) --- drivers/power/supply/Kconfig | 1 + drivers/power/supply/bq24190_charger.c | 107 +++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+)drivers/power/supply/Kconfig +1
-0@@ -442,6 +442,7 @@ config CHARGER_BQ2415X config CHARGER_BQ24190 tristate "TI BQ24190 battery charger driver" depends on I2C + depends on EXTCON depends on GPIOLIB || COMPILE_TEST help Say Y to enable support for the TI BQ24190 battery charger.drivers/power/supply/bq24190_charger.c +85
-0@@ -11,10 +11,12 @@#include <linux/module.h> #include <linux/interrupt.h> #include <linux/delay.h> +#include <linux/extcon.h> #include <linux/of_irq.h> #include <linux/of_device.h> #include <linux/pm_runtime.h> #include <linux/power_supply.h> +#include <linux/workqueue.h> #include <linux/gpio.h> #include <linux/i2c.h> @@ -36,6 +38,8 @@#define BQ24190_REG_POC_WDT_RESET_SHIFT 6#define BQ24190_REG_POC_CHG_CONFIG_MASK (BIT(5) | BIT(4))#define BQ24190_REG_POC_CHG_CONFIG_SHIFT 4 +#define BQ24190_REG_POC_CHG_CONFIG_CHARGE 1 +#define BQ24190_REG_POC_CHG_CONFIG_OTG 2#define BQ24190_REG_POC_SYS_MIN_MASK (BIT(3) | BIT(2) | BIT(1))#define BQ24190_REG_POC_SYS_MIN_SHIFT 1#define BQ24190_REG_POC_BOOST_LIM_MASK BIT(0)@@ -148,6 +152,9 @@ struct bq24190_dev_info {struct device *dev;struct power_supply *charger;struct power_supply *battery; +struct extcon_dev *extcon; +struct notifier_block extcon_nb; +struct delayed_work extcon_work;char model_name[I2C_NAME_SIZE ];bool initialized;bool irq_event;@@ -164,6 +171,11 @@ struct bq24190_dev_info {* number at that index in the array is the real-world value that it * represents. */ + +/* REG00[2:0] (IINLIM) in uAh */ +static const int bq24190_iinlim_values[] = { +100000 ,150000 ,500000 ,900000 ,1200000 ,1500000 ,2000000 ,3000000 }; +/* REG02[7:2] (ICHG) in uAh */ static const int bq24190_ccc_ichg_values[] = {512000 ,576000 ,640000 ,704000 ,768000 ,832000 ,896000 ,960000 ,@@ -1277,6 +1289,78 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)return IRQ_HANDLED ; } +static void bq24190_extcon_work (struct work_struct *work) +{ +struct bq24190_dev_info *bdi = + container_of(work, struct bq24190_dev_info, extcon_work.work); +int ret, iinlim =0 ; + + ret =pm_runtime_get_sync (bdi->dev); +if (ret <0 ) { +dev_err (bdi->dev,"Error getting runtime-pm ref: %d\n" , ret); +return ; + } + +if (extcon_get_state (bdi->extcon,EXTCON_CHG_USB_SDP ) ==1 ) + iinlim =500000 ; +else if (extcon_get_state (bdi->extcon,EXTCON_CHG_USB_CDP ) ==1 || +extcon_get_state (bdi->extcon,EXTCON_CHG_USB_ACA ) ==1 ) + iinlim =1500000 ; +else if (extcon_get_state (bdi->extcon,EXTCON_CHG_USB_DCP ) ==1 ) + iinlim =2000000 ; + +if (iinlim) { + ret =bq24190_set_field_val (bdi,BQ24190_REG_ISC , +BQ24190_REG_ISC_IINLIM_MASK , +BQ24190_REG_ISC_IINLIM_SHIFT , + bq24190_iinlim_values, +ARRAY_SIZE (bq24190_iinlim_values), + iinlim); +if (ret) +dev_err (bdi->dev,"Can't set IINLIM: %d\n" , ret); + } + +/* +* If no charger has been detected and host mode is requested, activate +* the 5V boost converter, otherwise deactivate it. +*/ +if (!iinlim &&extcon_get_state (bdi->extcon,EXTCON_USB_HOST ) ==1 ) { + ret =bq24190_write_mask (bdi,BQ24190_REG_POC , +BQ24190_REG_POC_CHG_CONFIG_MASK , +BQ24190_REG_POC_CHG_CONFIG_SHIFT , +BQ24190_REG_POC_CHG_CONFIG_OTG ); + }else { + ret =bq24190_write_mask (bdi,BQ24190_REG_POC , +BQ24190_REG_POC_CHG_CONFIG_MASK , +BQ24190_REG_POC_CHG_CONFIG_SHIFT , +BQ24190_REG_POC_CHG_CONFIG_CHARGE ); + } +if (ret) +dev_err (bdi->dev,"Can't set CHG_CONFIG: %d\n" , ret); + +pm_runtime_mark_last_busy (bdi->dev); +pm_runtime_put_autosuspend (bdi->dev); +} + +static int bq24190_extcon_event (struct notifier_block *nb,unsigned long event, +void *param) +{ +struct bq24190_dev_info *bdi = + container_of(nb, struct bq24190_dev_info, extcon_nb); + +/* +* The Power-Good detection may take up to 220ms, sometimes +* the external charger detection is quicker, and the bq24190 will +* reset to iinlim based on its own charger detection (which is not +* hooked up when using external charger detection) resulting in +* a too low default 500mA iinlim. Delay applying the extcon value +* for 300ms to avoid this. +*/ +queue_delayed_work (system_wq, &bdi->extcon_work,msecs_to_jiffies (300 )); + +return NOTIFY_OK ; +} +static int bq24190_hw_init (struct bq24190_dev_info *bdi) {u8 v;@@ -1314,6 +1398,7 @@ static int bq24190_probe(struct i2c_client *client,struct device *dev = &client->dev;struct power_supply_config charger_cfg = {}, battery_cfg = {};struct bq24190_dev_info *bdi; +const char *name;int ret;if (!i2c_check_functionality (adapter,I2C_FUNC_SMBUS_BYTE_DATA )) {@@ -1341,6 +1426,16 @@ static int bq24190_probe(struct i2c_client *client,return -EINVAL ;drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1436
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +8
-0} +/* +* The extcon-name property is purely an in kernel interface for +* x86/ACPI use, DT platforms should get extcon via phandle. +*/ +if (device_property_read_string (dev,"extcon-name" , &name) ==0 ) { + bdi->extcon =extcon_get_extcon_dev (name); +if (!bdi->extcon) +return -EPROBE_DEFER ;needs
Quoted 1 line
dev_info(bdi->dev, "using extcon device %s\n", name);
Right, I forgot about that v3 coming up.
Quoted 2 lines
I didn't see the device property for preferred charge voltage limit from v1 patchset?
I decided to drop that patch, the limit set by the firmware is within the limits of the LiHV battery it just is not an ideal limit from a number of charge-cycles the battery will endure pov, but second guessing the firmware here / doing our own tweaks is in hindsight a bad idea.
Regards,
Hans
Quoted 28 lines
Quoted 28 lines
drivers/power/supply/bq24190_charger.c +14
-1+ } +pm_runtime_enable (dev);pm_runtime_use_autosuspend (dev);pm_runtime_set_autosuspend_delay (dev,600 );@@ -1391,6 +1486,18 @@ static int bq24190_probe(struct i2c_client *client, goto out5; } +if (bdi->extcon) { +INIT_DELAYED_WORK (&bdi->extcon_work, bq24190_extcon_work); + bdi->extcon_nb.notifier_call = bq24190_extcon_event; + ret =devm_extcon_register_notifier (dev, bdi->extcon,-1 , + &bdi->extcon_nb); +if (ret) + goto out5; + +/* Sync initial cable state */ +queue_delayed_work (system_wq, &bdi->extcon_work,0 ); + } +enable_irq_wake (client->irq);pm_runtime_mark_last_busy (dev); --2.9.3
PATCH v2 4/7 power: supply: bq24190_charger: Never reset the charger chip
In reply to Hans de GoedeResetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery.
The reset in suspend() is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has been programmed with a higher max charge_current / charge_voltage then putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the max charge_current / charge_voltage after the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep using custom charge settings while suspending is to keep the charger in its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full.
Besides never being necessary resetting the charger also causes problems on systems where the charge voltage limit is set higher then the reset value, if this is the case and the charger is reset while charging and the battery voltage is between the 2 voltages, then about half the time the charger gets confused and claims to be charging (REG08 contains 0x64) but in reality the charger has decoupled itself from VBUS (Q1 off) and is drawing 0A from VBUS, leaving the system running from the battery.
---
Changes in v2:
-This is a new patch in v2 of this patch-set
--- drivers/power/supply/bq24190_charger.c | 58 ---------------------------------- 1 file changed, 58 deletions(-)
drivers/power/supply/bq24190_charger.c +0 -58
@@ -526,40 +526,6 @@ static int bq24190_set_mode_host(struct bq24190_dev_info *bdi)return bq24190_write (bdi,BQ24190_REG_CTTC , v); } -static int bq24190_register_reset (struct bq24190_dev_info *bdi) -{ -int ret, limit =100 ; -u8 v; - -/* Reset the registers */ - ret =bq24190_write_mask (bdi,BQ24190_REG_POC , -BQ24190_REG_POC_RESET_MASK , -BQ24190_REG_POC_RESET_SHIFT , -0x1 ); -if (ret <0 ) -return ret; - -/* Reset bit will be cleared by hardware so poll until it is */ -do { - ret =bq24190_read_mask (bdi,BQ24190_REG_POC , -BQ24190_REG_POC_RESET_MASK , -BQ24190_REG_POC_RESET_SHIFT , - &v); -if (ret <0 ) -return ret; - -if (!v) -break ; - -udelay (10 ); - }while (--limit); - -if (!limit) -return -EIO ; - -return 0 ; -} -/* Charger power supply property routines */ static int bq24190_charger_get_charge_type(struct bq24190_dev_info *bdi,
@@ -1380,10 +1346,6 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)return -ENODEV ; } - ret =bq24190_register_reset (bdi); -if (ret <0 ) -return ret; - ret =bq24190_set_mode_host (bdi);if (ret <0 )return ret;
@@ -1534,7 +1496,6 @@ static int bq24190_remove(struct i2c_client *client)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);
@@ -1577,23 +1538,6 @@ static __maybe_unused int bq24190_runtime_resume(struct device *dev)static __maybe_unused 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); - } - -bq24190_register_reset (bdi); - -if (error >=0 ) { -pm_runtime_mark_last_busy (bdi->dev); -pm_runtime_put_autosuspend (bdi->dev); - } -return 0 ; }
@@ -1612,8 +1556,6 @@ static __maybe_unused int bq24190_pm_resume(struct device *dev)pm_runtime_put_noidle (bdi->dev); } -bq24190_register_reset (bdi); -bq24190_set_mode_host (bdi);bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg);if (error >=0 ) {
Signature · 1 line
2.9.3
Re: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
Quoted 4 lines · Hans de Goede
Resetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery.
And some systems may only configure it in the bootloader with no configuration passed to the kernel at all.
Quoted 17 lines
The reset in
suspend()is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has been programmed with a higher maxcharge_current/charge_voltagethen putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the maxcharge_current/charge_voltageafter the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep using custom charge settings while suspending is to keep the charger in its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full.
Quoted 7 lines
Besides never being necessary resetting the charger also causes problems on systems where the charge voltage limit is set higher then the reset value, if this is the case and the charger is reset while charging and the battery voltage is between the 2 voltages, then about half the time the charger gets confused and claims to be charging (REG08 contains
0x64) but in reality the charger has decoupled itself from VBUS (Q1 off) and is drawing 0A from VBUS, leaving the system running from the battery.
We do have cases where Linux kernel is the bootloader though using kexec. And in those cases we may need to reset, so I wonder if the reset should just be optional based on a proper device tree (or platform_data) configuration?
Regards,
Tony
Re: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
Hi,
Quoted 8 lines · Tony Lindgren
Quoted 4 lines · Hans de Goede
Resetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery.
And some systems may only configure it in the bootloader with no configuration passed to the kernel at all.
Right.
Quoted 25 lines
Quoted 17 lines
The reset in
suspend()is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has been programmed with a higher maxcharge_current/charge_voltagethen putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the maxcharge_current/charge_voltageafter the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep using custom charge settings while suspending is to keep the charger in its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full.Quoted 7 lines
Besides never being necessary resetting the charger also causes problems on systems where the charge voltage limit is set higher then the reset value, if this is the case and the charger is reset while charging and the battery voltage is between the 2 voltages, then about half the time the charger gets confused and claims to be charging (REG08 contains
0x64) but in reality the charger has decoupled itself from VBUS (Q1 off) and is drawing 0A from VBUS, leaving the system running from the battery.
Quoted 4 lines
We do have cases where Linux kernel is the bootloader though using kexec. And in those cases we may need to reset, so I wonder if the reset should just be optional based on a proper device tree (or
platform_data) configuration?
As described above during my testing I've found that the chip does not respond well to reset under certain conditions, so I think that if we have settings to apply we should just overwrite the settings with our settings, what does doing a reset before overwriting the registers buy us? We still need to do the overwrite anyways.
Regards,
Hans
Re: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
Quoted 44 lines · Hans de Goede
Hi,
Quoted 8 lines · Tony Lindgren
Quoted 4 lines · Hans de Goede
Resetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery.
And some systems may only configure it in the bootloader with no configuration passed to the kernel at all.
Right.
Quoted 25 lines
Quoted 17 lines
The reset in
suspend()is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has been programmed with a higher maxcharge_current/charge_voltagethen putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the maxcharge_current/charge_voltageafter the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep using custom charge settings while suspending is to keep the charger in its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full.Quoted 7 lines
Besides never being necessary resetting the charger also causes problems on systems where the charge voltage limit is set higher then the reset value, if this is the case and the charger is reset while charging and the battery voltage is between the 2 voltages, then about half the time the charger gets confused and claims to be charging (REG08 contains
0x64) but in reality the charger has decoupled itself from VBUS (Q1 off) and is drawing 0A from VBUS, leaving the system running from the battery.Quoted 4 lines
We do have cases where Linux kernel is the bootloader though using kexec. And in those cases we may need to reset, so I wonder if the reset should just be optional based on a proper device tree (or
platform_data) configuration?
Quoted 5 lines
As described above during my testing I've found that the chip does not respond well to reset under certain conditions, so I think that if we have settings to apply we should just overwrite the settings with our settings, what does doing a reset before overwriting the registers buy us? We still need to do the overwrite anyways.
OK with me if that works and reset is buggy.
Regards,
Tony
Re: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
In reply to Hans de GoedeQuoted 51 lines · Hans de Goede
Hi,
Quoted 11 lines · Tony Lindgren
Quoted 5 lines · Hans de Goede
Resetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery.
And some systems may only configure it in the bootloader with no configuration passed to the kernel at all.
Right.
Quoted 26 lines
Quoted 17 lines
The reset in
suspend()is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has been programmed with a higher maxcharge_current/charge_voltagethen putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the maxcharge_current/charge_voltageafter the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep using custom charge settings while suspending is to keep the charger in its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full.Quoted 7 lines
Besides never being necessary resetting the charger also causes problems on systems where the charge voltage limit is set higher then the reset value, if this is the case and the charger is reset while charging and the battery voltage is between the 2 voltages, then about half the time the charger gets confused and claims to be charging (REG08 contains
0x64) but in reality the charger has decoupled itself from VBUS (Q1 off) and is drawing 0A from VBUS, leaving the system running from the battery.Quoted 4 lines
We do have cases where Linux kernel is the bootloader though using kexec. And in those cases we may need to reset, so I wonder if the reset should just be optional based on a proper device tree (or
platform_data) configuration?
Quoted 5 lines
As described above during my testing I've found that the chip does not respond well to reset under certain conditions, so I think that if we have settings to apply we should just overwrite the settings with our settings, what does doing a reset before overwriting the registers buy us? We still need to do the overwrite anyways.
When driver loads on any conceivable hw, how do we know the chip is in a state we predicted? If it isn't, how can we fix any undesirable settings? Reset + fix a,b,c is simple way to do that.
I'm OK with abandoning reset on suspend. Tho I need to review the docs about host mode...
Re: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
Hi,
Quoted 52 lines · Liam Breck
Quoted 51 lines · Hans de Goede
Hi,
Quoted 11 lines · Tony Lindgren
Quoted 5 lines · Hans de Goede
Resetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery.
And some systems may only configure it in the bootloader with no configuration passed to the kernel at all.
Right.
Quoted 30 lines
Quoted 17 lines
The reset in
suspend()is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has been programmed with a higher maxcharge_current/charge_voltagethen putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the maxcharge_current/charge_voltageafter the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep using custom charge settings while suspending is to keep the charger in its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full.Quoted 7 lines
Besides never being necessary resetting the charger also causes problems on systems where the charge voltage limit is set higher then the reset value, if this is the case and the charger is reset while charging and the battery voltage is between the 2 voltages, then about half the time the charger gets confused and claims to be charging (REG08 contains
0x64) but in reality the charger has decoupled itself from VBUS (Q1 off) and is drawing 0A from VBUS, leaving the system running from the battery.We do have cases where Linux kernel is the bootloader though using kexec. And in those cases we may need to reset, so I wonder if the reset should just be optional based on a proper device tree (or
platform_data) configuration?
Quoted 8 lines
Quoted 5 lines
As described above during my testing I've found that the chip does not respond well to reset under certain conditions, so I think that if we have settings to apply we should just overwrite the settings with our settings, what does doing a reset before overwriting the registers buy us? We still need to do the overwrite anyways.
When driver loads on any conceivable hw, how do we know the chip is in a state we predicted?
Any non reset values have to come from somewhere, likely firmware, and unless we've platform data telling us the exact settings we should use why would we decide the reset values are better then the ones the charger was *already using* before our driver loads ? As said in the commit msg: "If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery."
Quoted 2 lines
If it isn't, how can we fix any undesirable
settings?
Why would the chip not be in a sane state? Where would the undesirable settings come from ?
Quoted 1 line
Reset + fix a,b,c is simple way to do that.
As my testing using real-world hardware under real-world conditions has shown resetting the charger IC while it is charging can cause it to misbehave. So we have this theoretical problem of there somehow being undesirable settings at boot vs a real-world problem...
Regards,
Hans
Re: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
Quoted 94 lines · Hans de Goede
Hi,
Quoted 71 lines · Liam Breck
Quoted 61 lines · Hans de Goede
Hi,
Quoted 12 lines · Tony Lindgren
Quoted 6 lines · Hans de Goede
Resetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery.
Quoted 2 lines
And some systems may only configure it in the bootloader with no configuration passed to the kernel at all.
Right.
Quoted 30 lines
Quoted 18 lines
The reset in
suspend()is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has been programmed with a higher maxcharge_current/charge_voltagethen putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the maxcharge_current/charge_voltageafter the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog
expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep using custom charge settings while suspending is to keep the charger in its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full.Quoted 9 lines
Besides never being necessary resetting the charger also causes problems
on systems where the charge voltage limit is set higher then the reset value, if this is the case and the charger is reset while charging and the battery voltage is between the 2 voltages, then about half the time the charger gets confused and claims to be charging (REG08 contains0x64)
but in reality the charger has decoupled itself from VBUS (Q1 off) and is drawing 0A from VBUS, leaving the system running from the battery.Quoted 4 lines
We do have cases where Linux kernel is the bootloader though using kexec. And in those cases we may need to reset, so I wonder if the reset should just be optional based on a proper device tree (or
platform_data) configuration?Quoted 5 lines
As described above during my testing I've found that the chip does not respond well to reset under certain conditions, so I think that if we have settings to apply we should just overwrite the settings with our settings, what does doing a reset before overwriting the registers buy us? We still need to do the overwrite anyways.
Quoted 2 lines
When driver loads on any conceivable hw, how do we know the chip is in a state we predicted?
Any non reset values have to come from somewhere, likely firmware, and unless we've platform data telling us the exact settings we should use why would we decide the reset values are better then the ones the charger was *already using* before our driver loads ? As said in the commit msg: "If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery."
Quoted 2 lines
If it isn't, how can we fix any undesirable
settings?Why would the chip not be in a sane state? Where would the undesirable settings come from ?
Quoted 7 lines
Quoted 1 line
Reset + fix a,b,c is simple way to do that.
As my testing using real-world hardware under real-world conditions has shown resetting the charger IC while it is charging can cause it to misbehave. So we have this theoretical problem of there somehow being undesirable settings at boot vs a real-world problem...
A bug in the charger? Or in the platform hw/fw?
Re: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
Hi,
Quoted 98 lines · Liam Breck
Quoted 97 lines · Hans de Goede
Hi,
Quoted 71 lines · Liam Breck
Quoted 61 lines · Hans de Goede
Hi,
Quoted 12 lines · Tony Lindgren
Quoted 6 lines · Hans de Goede
Resetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery.
Quoted 2 lines
And some systems may only configure it in the bootloader with no configuration passed to the kernel at all.
Right.
Quoted 30 lines
Quoted 18 lines
The reset in
suspend()is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has been programmed with a higher maxcharge_current/charge_voltagethen putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the maxcharge_current/charge_voltageafter the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog
expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep using custom charge settings while suspending is to keep the charger in its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full.Quoted 9 lines
Besides never being necessary resetting the charger also causes problems
on systems where the charge voltage limit is set higher then the reset value, if this is the case and the charger is reset while charging and the battery voltage is between the 2 voltages, then about half the time the charger gets confused and claims to be charging (REG08 contains0x64)
but in reality the charger has decoupled itself from VBUS (Q1 off) and is drawing 0A from VBUS, leaving the system running from the battery.Quoted 4 lines
We do have cases where Linux kernel is the bootloader though using kexec. And in those cases we may need to reset, so I wonder if the reset should just be optional based on a proper device tree (or
platform_data) configuration?Quoted 5 lines
As described above during my testing I've found that the chip does not respond well to reset under certain conditions, so I think that if we have settings to apply we should just overwrite the settings with our settings, what does doing a reset before overwriting the registers buy us? We still need to do the overwrite anyways.
Quoted 2 lines
When driver loads on any conceivable hw, how do we know the chip is in a state we predicted?
Any non reset values have to come from somewhere, likely firmware, and unless we've platform data telling us the exact settings we should use why would we decide the reset values are better then the ones the charger was *already using* before our driver loads ? As said in the commit msg: "If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery."
Quoted 2 lines
If it isn't, how can we fix any undesirable
settings?Why would the chip not be in a sane state? Where would the undesirable settings come from ?
Quoted 1 line
Reset + fix a,b,c is simple way to do that.
Quoted 6 lines
Quoted 4 lines
As my testing using real-world hardware under real-world conditions has shown resetting the charger IC while it is charging can cause it to misbehave. So we have this theoretical problem of there somehow being undesirable settings at boot vs a real-world problem...
A bug in the charger? Or in the platform hw/fw?
I'm pretty sure the fw is not touching the charger, still the problem might be something specific to my hw. Either way there does not seem to be a good reason to reset the chip and doing a reset despite it not being necessary does cause real problems independently of the root cause (I'm running this on production hardware which many people have, so no way to modify the hardware).
If you want to test this on your systems you can easily add a patch on top of your current branch which just comments out all the reset calls (and the bq24190_set_mode_host call in resume) to get the same result on top of your current branch.
Regards,
Hans
Re: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
Quoted 142 lines · Hans de Goede
Hi,
Quoted 122 lines · Liam Breck
Quoted 119 lines · Hans de Goede
Hi,
Quoted 89 lines · Liam Breck
Quoted 77 lines · Hans de Goede
Hi,
Quoted 16 lines · Tony Lindgren
Quoted 8 lines · Hans de Goede
Resetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem
as that may lead to overcharging the battery.Quoted 2 lines
And some systems may only configure it in the bootloader with no configuration passed to the kernel at all.
Right.
Quoted 39 lines
Quoted 22 lines
The reset in
suspend()is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has
been programmed with a higher maxcharge_current/charge_voltagethen
putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the maxcharge_current/charge_voltageafter the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog
expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep
using custom charge settings while suspending is to keep the charger in
its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full.Quoted 13 lines
Besides never being necessary resetting the charger also causes problems
on systems where the charge voltage limit is set higher then the reset
value, if this is the case and the charger is reset while charging and
the battery voltage is between the 2 voltages, then about half the time
the charger gets confused and claims to be charging (REG08 contains0x64)
but in reality the charger has decoupled itself from VBUS (Q1 off) and
is drawing 0A from VBUS, leaving the system running from the battery.Quoted 4 lines
We do have cases where Linux kernel is the bootloader though using kexec. And in those cases we may need to reset, so I wonder if the reset should just be optional based on a proper device tree (or
platform_data) configuration?Quoted 5 lines
As described above during my testing I've found that the chip does not respond well to reset under certain conditions, so I think that if we have settings to apply we should just overwrite the settings with our settings, what does doing a reset before overwriting the registers buy us? We still need to do the overwrite anyways.
Quoted 2 lines
When driver loads on any conceivable hw, how do we know the chip is in a state we predicted?
Any non reset values have to come from somewhere, likely firmware, and unless we've platform data telling us the exact settings we should use why would we decide the reset values are better then the ones the charger was *already using* before our driver loads ? As said in the commit msg: "If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery."
Quoted 2 lines
If it isn't, how can we fix any undesirable
settings?Why would the chip not be in a sane state? Where would the undesirable settings come from ?
Quoted 1 line
Reset + fix a,b,c is simple way to do that.
Quoted 7 lines
Quoted 4 lines
As my testing using real-world hardware under real-world conditions has shown resetting the charger IC while it is charging can cause it to misbehave. So we have this theoretical problem of there somehow being undesirable settings at boot vs a real-world problem...
A bug in the charger? Or in the platform hw/fw?
I'm pretty sure the fw is not touching the charger, still the problem might be something specific to my hw. Either way there does not seem to be a good reason to reset the chip and doing a reset despite it not being necessary does cause real problems independently of the root cause (I'm running this on production hardware which many people have, so no way to modify the hardware).
Quoted 4 lines
If you want to test this on your systems you can easily add a patch on top of your current branch which just comments out all the reset calls (and the
bq24190_set_mode_hostcall in resume) to get the same result on top of your current branch.
I'll try it.
Why would you not want set_mode_host()?
Re: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
Hi,
Quoted 143 lines · Liam Breck
Quoted 142 lines · Hans de Goede
Hi,
Quoted 122 lines · Liam Breck
Quoted 119 lines · Hans de Goede
Hi,
Quoted 89 lines · Liam Breck
Quoted 77 lines · Hans de Goede
Hi,
Quoted 16 lines · Tony Lindgren
Quoted 8 lines · Hans de Goede
Resetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem
as that may lead to overcharging the battery.Quoted 2 lines
And some systems may only configure it in the bootloader with no configuration passed to the kernel at all.
Right.
Quoted 39 lines
Quoted 22 lines
The reset in
suspend()is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has
been programmed with a higher maxcharge_current/charge_voltagethen
putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the maxcharge_current/charge_voltageafter the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog
expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep
using custom charge settings while suspending is to keep the charger in
its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full.Quoted 13 lines
Besides never being necessary resetting the charger also causes problems
on systems where the charge voltage limit is set higher then the reset
value, if this is the case and the charger is reset while charging and
the battery voltage is between the 2 voltages, then about half the time
the charger gets confused and claims to be charging (REG08 contains0x64)
but in reality the charger has decoupled itself from VBUS (Q1 off) and
is drawing 0A from VBUS, leaving the system running from the battery.Quoted 4 lines
We do have cases where Linux kernel is the bootloader though using kexec. And in those cases we may need to reset, so I wonder if the reset should just be optional based on a proper device tree (or
platform_data) configuration?Quoted 5 lines
As described above during my testing I've found that the chip does not respond well to reset under certain conditions, so I think that if we have settings to apply we should just overwrite the settings with our settings, what does doing a reset before overwriting the registers buy us? We still need to do the overwrite anyways.
Quoted 2 lines
When driver loads on any conceivable hw, how do we know the chip is in a state we predicted?
Any non reset values have to come from somewhere, likely firmware, and unless we've platform data telling us the exact settings we should use why would we decide the reset values are better then the ones the charger was *already using* before our driver loads ? As said in the commit msg: "If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery."
Quoted 2 lines
If it isn't, how can we fix any undesirable
settings?Why would the chip not be in a sane state? Where would the undesirable settings come from ?
Quoted 1 line
Reset + fix a,b,c is simple way to do that.
Quoted 7 lines
Quoted 4 lines
As my testing using real-world hardware under real-world conditions has shown resetting the charger IC while it is charging can cause it to misbehave. So we have this theoretical problem of there somehow being undesirable settings at boot vs a real-world problem...
A bug in the charger? Or in the platform hw/fw?
I'm pretty sure the fw is not touching the charger, still the problem might be something specific to my hw. Either way there does not seem to be a good reason to reset the chip and doing a reset despite it not being necessary does cause real problems independently of the root cause (I'm running this on production hardware which many people have, so no way to modify the hardware).
Quoted 8 lines
Quoted 4 lines
If you want to test this on your systems you can easily add a patch on top of your current branch which just comments out all the reset calls (and the
bq24190_set_mode_hostcall in resume) to get the same result on top of your current branch.I'll try it.
Why would you not want
set_mode_host()?
Doing set_mode_host() on resume is redundant if we do not reset the chip on suspend/resume. Note we still want the set_mode_host on boot / probe and my patch preservers that set_mode_host call.
Regards,
Hans
Re: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
In reply to Hans de GoedeQuoted 142 lines · Hans de Goede
Hi,
Quoted 122 lines · Liam Breck
Quoted 119 lines · Hans de Goede
Hi,
Quoted 89 lines · Liam Breck
Quoted 77 lines · Hans de Goede
Hi,
Quoted 16 lines · Tony Lindgren
Quoted 8 lines · Hans de Goede
Resetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem
as that may lead to overcharging the battery.Quoted 2 lines
And some systems may only configure it in the bootloader with no configuration passed to the kernel at all.
Right.
Quoted 39 lines
Quoted 22 lines
The reset in
suspend()is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has
been programmed with a higher maxcharge_current/charge_voltagethen
putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the maxcharge_current/charge_voltageafter the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog
expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep
using custom charge settings while suspending is to keep the charger in
its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full.Quoted 13 lines
Besides never being necessary resetting the charger also causes problems
on systems where the charge voltage limit is set higher then the reset
value, if this is the case and the charger is reset while charging and
the battery voltage is between the 2 voltages, then about half the time
the charger gets confused and claims to be charging (REG08 contains0x64)
but in reality the charger has decoupled itself from VBUS (Q1 off) and
is drawing 0A from VBUS, leaving the system running from the battery.Quoted 4 lines
We do have cases where Linux kernel is the bootloader though using kexec. And in those cases we may need to reset, so I wonder if the reset should just be optional based on a proper device tree (or
platform_data) configuration?Quoted 5 lines
As described above during my testing I've found that the chip does not respond well to reset under certain conditions, so I think that if we have settings to apply we should just overwrite the settings with our settings, what does doing a reset before overwriting the registers buy us? We still need to do the overwrite anyways.
Quoted 2 lines
When driver loads on any conceivable hw, how do we know the chip is in a state we predicted?
Any non reset values have to come from somewhere, likely firmware, and unless we've platform data telling us the exact settings we should use why would we decide the reset values are better then the ones the charger was *already using* before our driver loads ? As said in the commit msg: "If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery."
Quoted 2 lines
If it isn't, how can we fix any undesirable
settings?Why would the chip not be in a sane state? Where would the undesirable settings come from ?
Quoted 1 line
Reset + fix a,b,c is simple way to do that.
Quoted 7 lines
Quoted 4 lines
As my testing using real-world hardware under real-world conditions has shown resetting the charger IC while it is charging can cause it to misbehave. So we have this theoretical problem of there somehow being undesirable settings at boot vs a real-world problem...
A bug in the charger? Or in the platform hw/fw?
I'm pretty sure the fw is not touching the charger, still the problem might be something specific to my hw. Either way there does not seem to be a good reason to reset the chip and doing a reset despite it not being necessary does cause real problems independently of the root cause (I'm running this on production hardware which many people have, so no way to modify the hardware).
Quoted 4 lines
If you want to test this on your systems you can easily add a patch on top of your current branch which just comments out all the reset calls (and the
bq24190_set_mode_hostcall in resume) to get the same result on top of your current branch.
My mistake... what I need to try is reproducing your failure due to reset during charge. Can you explain what switches I need to flip and dials to watch?
Re: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
Hi,
Quoted 143 lines · Liam Breck
Quoted 142 lines · Hans de Goede
Hi,
Quoted 122 lines · Liam Breck
Quoted 119 lines · Hans de Goede
Hi,
Quoted 89 lines · Liam Breck
Quoted 77 lines · Hans de Goede
Hi,
Quoted 16 lines · Tony Lindgren
Quoted 8 lines · Hans de Goede
Resetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem
as that may lead to overcharging the battery.Quoted 2 lines
And some systems may only configure it in the bootloader with no configuration passed to the kernel at all.
Right.
Quoted 39 lines
Quoted 22 lines
The reset in
suspend()is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has
been programmed with a higher maxcharge_current/charge_voltagethen
putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the maxcharge_current/charge_voltageafter the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog
expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep
using custom charge settings while suspending is to keep the charger in
its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full.Quoted 13 lines
Besides never being necessary resetting the charger also causes problems
on systems where the charge voltage limit is set higher then the reset
value, if this is the case and the charger is reset while charging and
the battery voltage is between the 2 voltages, then about half the time
the charger gets confused and claims to be charging (REG08 contains0x64)
but in reality the charger has decoupled itself from VBUS (Q1 off) and
is drawing 0A from VBUS, leaving the system running from the battery.Quoted 4 lines
We do have cases where Linux kernel is the bootloader though using kexec. And in those cases we may need to reset, so I wonder if the reset should just be optional based on a proper device tree (or
platform_data) configuration?Quoted 5 lines
As described above during my testing I've found that the chip does not respond well to reset under certain conditions, so I think that if we have settings to apply we should just overwrite the settings with our settings, what does doing a reset before overwriting the registers buy us? We still need to do the overwrite anyways.
Quoted 2 lines
When driver loads on any conceivable hw, how do we know the chip is in a state we predicted?
Any non reset values have to come from somewhere, likely firmware, and unless we've platform data telling us the exact settings we should use why would we decide the reset values are better then the ones the charger was *already using* before our driver loads ? As said in the commit msg: "If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery."
Quoted 2 lines
If it isn't, how can we fix any undesirable
settings?Why would the chip not be in a sane state? Where would the undesirable settings come from ?
Quoted 1 line
Reset + fix a,b,c is simple way to do that.
Quoted 7 lines
Quoted 4 lines
As my testing using real-world hardware under real-world conditions has shown resetting the charger IC while it is charging can cause it to misbehave. So we have this theoretical problem of there somehow being undesirable settings at boot vs a real-world problem...
A bug in the charger? Or in the platform hw/fw?
I'm pretty sure the fw is not touching the charger, still the problem might be something specific to my hw. Either way there does not seem to be a good reason to reset the chip and doing a reset despite it not being necessary does cause real problems independently of the root cause (I'm running this on production hardware which many people have, so no way to modify the hardware).
Quoted 8 lines
Quoted 4 lines
If you want to test this on your systems you can easily add a patch on top of your current branch which just comments out all the reset calls (and the
bq24190_set_mode_hostcall in resume) to get the same result on top of your current branch.My mistake... what I need to try is reproducing your failure due to reset during charge. Can you explain what switches I need to flip and dials to watch?
The GPDwin mini laptop I'm developing this on /for has a bq24292i (bq24192i compatible) with a LiHV battery and max charging voltage set to 4.38V When resetting the charger while the battery voltage is between 4.1V (reset max volt) and 4.38V and the charger is charging. Sometimes instead of just turning of charging as the bat voltage is now above the max voltage, it turns of Q1 (disconnects itself from Vbus) while it thinks it is still charging (observed from REG08 as well as the charging LED.
Regards,
Hans
Re: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
Quoted 191 lines · Hans de Goede
Hi,
Quoted 182 lines · Liam Breck
Quoted 173 lines · Hans de Goede
Hi,
Quoted 150 lines · Liam Breck
Quoted 146 lines · Hans de Goede
Hi,
Quoted 112 lines · Liam Breck
Quoted 96 lines · Hans de Goede
Hi,
Quoted 21 lines · Tony Lindgren
Quoted 11 lines · Hans de Goede
Resetting the charger should never be necessary it should always have
sane values programmed. If it is running with invalid values while we
are not running (system turned off or suspended) there is a big problem
as that may lead to overcharging the battery.Quoted 2 lines
And some systems may only configure it in the bootloader with no configuration passed to the kernel at all.
Right.
Quoted 50 lines
Quoted 31 lines
The reset in
suspend()is meant to put the charger back into default
mode, but this is not necessary and not a good idea. If the charger has
been programmed with a higher maxcharge_current/charge_voltagethen
putting it back in default-mode will reset those to the safe power-on
defaults, leading to slower charging, or charging to a lower voltage
(and thus not using the full capacity) while suspended which is undesirable. Reprogramming the maxcharge_current/charge_voltageafter the reset will not help here as that will put the charger back
in host mode and start the i2c watchdog if the host then does not do
anything for 40s (iow if we're suspended for more then 40s) the watchdog
expires resetting the device to default-mode, including resetting all
the registers to there safe power-on defaults. So the only way to keep
using custom charge settings while suspending is to keep the charger
in
its normal running state with the i2c watchdog disabled. This is fine
as the charger will still automatically switch from constant current
to constant voltage and stop charging when the battery is full.Quoted 14 lines
Besides never being necessary resetting the charger also causes problems
on systems where the charge voltage limit is set higher then the reset
value, if this is the case and the charger is reset while charging and
the battery voltage is between the 2 voltages, then about half the time
the charger gets confused and claims to be charging (REG08 contains0x64)
but in reality the charger has decoupled itself from VBUS (Q1 off) and
is drawing 0A from VBUS, leaving the system running from the battery.Quoted 4 lines
We do have cases where Linux kernel is the bootloader though using kexec. And in those cases we may need to reset, so I wonder if the reset should just be optional based on a proper device tree (or
platform_data) configuration?Quoted 7 lines
As described above during my testing I've found that the chip does not
respond well to reset under certain conditions, so I think that if we have settings to apply we should just overwrite the settings with our settings, what does doing a reset before overwriting the registers
buy us? We still need to do the overwrite anyways.Quoted 2 lines
When driver loads on any conceivable hw, how do we know the chip is in a state we predicted?
Any non reset values have to come from somewhere, likely firmware, and unless we've platform data telling us the exact settings we should use why would we decide the reset values are better then the ones the charger was *already using* before our driver loads ? As said in the commit msg: "If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery."
Quoted 2 lines
If it isn't, how can we fix any undesirable
settings?Why would the chip not be in a sane state? Where would the undesirable settings come from ?
Quoted 1 line
Reset + fix a,b,c is simple way to do that.
Quoted 8 lines
Quoted 4 lines
As my testing using real-world hardware under real-world conditions has shown resetting the charger IC while it is charging can cause it to misbehave. So we have this theoretical problem of there somehow being undesirable settings at boot vs a real-world problem...
A bug in the charger? Or in the platform hw/fw?
I'm pretty sure the fw is not touching the charger, still the problem might be something specific to my hw. Either way there does not seem to be a good reason to reset the chip and doing a reset despite it not being necessary does cause real problems independently of the root cause (I'm running this on production hardware which many people have, so no way to modify the hardware).
Quoted 4 lines
If you want to test this on your systems you can easily add a patch on top of your current branch which just comments out all the reset calls (and the
bq24190_set_mode_hostcall in resume) to get the same result on top of your current branch.Quoted 3 lines
My mistake... what I need to try is reproducing your failure due to reset during charge. Can you explain what switches I need to flip and dials to watch?
Quoted 9 lines
The GPDwin mini laptop I'm developing this on /for has a bq24292i (bq24192i compatible) with a LiHV battery and max charging voltage set to 4.38V When resetting the charger while the battery voltage is between 4.1V (reset max volt) and 4.38V and the charger is charging. Sometimes instead of just turning of charging as the bat voltage is now above the max voltage, it turns of Q1 (disconnects itself from Vbus) while it thinks it is still charging (observed from REG08 as well as the charging LED.
Thanks. It will take me a few days to get to this.
In the meantime, note that on a DT-configured system, we don't want any charger settings made by the bootloader, as we're going to change default settings (e.g. precharge & endcharge from my patchset) based on DT params.
Re: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
In reply to Hans de GoedeQuoted 71 lines · Hans de Goede
Resetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery.
The reset in
suspend()is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has been programmed with a higher maxcharge_current/charge_voltagethen putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the maxcharge_current/charge_voltageafter the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep using custom charge settings while suspending is to keep the charger in its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full.Besides never being necessary resetting the charger also causes problems on systems where the charge voltage limit is set higher then the reset value, if this is the case and the charger is reset while charging and the battery voltage is between the 2 voltages, then about half the time the charger gets confused and claims to be charging (REG08 contains
0x64) but in reality the charger has decoupled itself from VBUS (Q1 off) and is drawing 0A from VBUS, leaving the system running from the battery.Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-2-This is a new patch in v2 of this patch-set --- drivers/power/supply/bq24190_charger.c | 58 ---------------------------------- 1 file changed, 58 deletions(-)drivers/power/supply/bq24190_charger.c +0
-23@@ -526,40 +526,6 @@ static int bq24190_set_mode_host(struct bq24190_dev_info *bdi)return bq24190_write (bdi,BQ24190_REG_CTTC , v); } -static int bq24190_register_reset (struct bq24190_dev_info *bdi) -{ -int ret, limit =100 ; -u8 v; - -/* Reset the registers */ - ret =bq24190_write_mask (bdi,BQ24190_REG_POC , -BQ24190_REG_POC_RESET_MASK , -BQ24190_REG_POC_RESET_SHIFT , -0x1 ); -if (ret <0 ) -return ret; - -/* Reset bit will be cleared by hardware so poll until it is */ - do { - ret = bq24190_read_mask(bdi, BQ24190_REG_POC, - BQ24190_REG_POC_RESET_MASK, - BQ24190_REG_POC_RESET_SHIFT, - &v); - if (ret < 0) - return ret; - - if (!v)
drivers/power/supply/bq24190_charger.c static int bq24190_set_mode_host(struct bq24190_dev_info *bdi) · line 561
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +0
-10-break ; - -udelay (10 ); - }while (--limit); - -if (!limit) -return -EIO ; - -return 0 ; -}
Let's leave this in with __maybe_unused.
Quoted 58 lines
drivers/power/supply/bq24190_charger.c +0
-25/* Charger power supply property routines */ static int bq24190_charger_get_charge_type(struct bq24190_dev_info *bdi,@@ -1380,10 +1346,6 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)return -ENODEV ; } - ret =bq24190_register_reset (bdi); -if (ret <0 ) -return ret; - ret =bq24190_set_mode_host (bdi);if (ret <0 )return ret;@@ -1534,7 +1496,6 @@ static int bq24190_remove(struct i2c_client *client)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);@@ -1577,23 +1538,6 @@ static __maybe_unused int bq24190_runtime_resume(struct device *dev)static __maybe_unused 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); - } - -bq24190_register_reset (bdi); - -if (error >=0 ) { -pm_runtime_mark_last_busy (bdi->dev); -pm_runtime_put_autosuspend (bdi->dev); - } -return 0 ; }@@ -1612,8 +1556,6 @@ static __maybe_unused int bq24190_pm_resume(struct device *dev)pm_runtime_put_noidle (bdi->dev); } -bq24190_register_reset (bdi); -bq24190_set_mode_host (bdi);bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg);if (error >=0 ) { --2.9.3
Re: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
Hi,
Quoted 76 lines · Liam Breck
Quoted 75 lines · Hans de Goede
Resetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery.
The reset in
suspend()is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has been programmed with a higher maxcharge_current/charge_voltagethen putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the maxcharge_current/charge_voltageafter the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep using custom charge settings while suspending is to keep the charger in its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full.Besides never being necessary resetting the charger also causes problems on systems where the charge voltage limit is set higher then the reset value, if this is the case and the charger is reset while charging and the battery voltage is between the 2 voltages, then about half the time the charger gets confused and claims to be charging (REG08 contains
0x64) but in reality the charger has decoupled itself from VBUS (Q1 off) and is drawing 0A from VBUS, leaving the system running from the battery.Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-2-This is a new patch in v2 of this patch-set --- drivers/power/supply/bq24190_charger.c | 58 ---------------------------------- 1 file changed, 58 deletions(-)drivers/power/supply/bq24190_charger.c +0
-27@@ -526,40 +526,6 @@ static int bq24190_set_mode_host(struct bq24190_dev_info *bdi)return bq24190_write (bdi,BQ24190_REG_CTTC , v); } -static int bq24190_register_reset (struct bq24190_dev_info *bdi) -{ -int ret, limit =100 ; -u8 v; - -/* Reset the registers */ - ret =bq24190_write_mask (bdi,BQ24190_REG_POC , -BQ24190_REG_POC_RESET_MASK , -BQ24190_REG_POC_RESET_SHIFT , -0x1 ); -if (ret <0 ) -return ret; - -/* Reset bit will be cleared by hardware so poll until it is */ -do { - ret =bq24190_read_mask (bdi,BQ24190_REG_POC , -BQ24190_REG_POC_RESET_MASK , -BQ24190_REG_POC_RESET_SHIFT , - &v); -if (ret <0 ) -return ret; - -if (!v) -break ; - -udelay (10 ); - }while (--limit);
Quoted 8 lines
drivers/power/supply/bq24190_charger.c static int bq24190_set_mode_host(struct bq24190_dev_info *bdi) · line 561
Quoted 6 lines
drivers/power/supply/bq24190_charger.c +0
-6- -if (!limit) -return -EIO ; - -return 0 ; -}Let's leave this in with
__maybe_unused.
I don't like leaving dead code around and bringing it back from git history is quite easy.
Regards,
Hans
Quoted 59 lines
Quoted 59 lines
drivers/power/supply/bq24190_charger.c +0
-25/* Charger power supply property routines */ static int bq24190_charger_get_charge_type(struct bq24190_dev_info *bdi,@@ -1380,10 +1346,6 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)return -ENODEV ; } - ret =bq24190_register_reset (bdi); -if (ret <0 ) -return ret; - ret =bq24190_set_mode_host (bdi);if (ret <0 )return ret;@@ -1534,7 +1496,6 @@ static int bq24190_remove(struct i2c_client *client)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);@@ -1577,23 +1538,6 @@ static __maybe_unused int bq24190_runtime_resume(struct device *dev)static __maybe_unused 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); - } - -bq24190_register_reset (bdi); - -if (error >=0 ) { -pm_runtime_mark_last_busy (bdi->dev); -pm_runtime_put_autosuspend (bdi->dev); - } -return 0 ; }@@ -1612,8 +1556,6 @@ static __maybe_unused int bq24190_pm_resume(struct device *dev)pm_runtime_put_noidle (bdi->dev); } -bq24190_register_reset (bdi); -bq24190_set_mode_host (bdi);bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg);if (error >=0 ) { --2.9.3
Sebastian Reichel
maintainerRe: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
In reply to Liam BreckHi,
Quoted 28 lines · Liam Breck
Quoted 27 lines · Hans de Goede
drivers/power/supply/bq24190_charger.c +0
-27-static int bq24190_register_reset (struct bq24190_dev_info *bdi) -{ -int ret, limit =100 ; -u8 v; - -/* Reset the registers */ - ret =bq24190_write_mask (bdi,BQ24190_REG_POC , -BQ24190_REG_POC_RESET_MASK , -BQ24190_REG_POC_RESET_SHIFT , -0x1 ); -if (ret <0 ) -return ret; - -/* Reset bit will be cleared by hardware so poll until it is */ -do { - ret =bq24190_read_mask (bdi,BQ24190_REG_POC , -BQ24190_REG_POC_RESET_MASK , -BQ24190_REG_POC_RESET_SHIFT , - &v); -if (ret <0 ) -return ret; - -if (!v) -break ; - -udelay (10 ); - }while (--limit);
Quoted 8 lines
drivers/power/supply/bq24190_charger.c static int bq24190_set_mode_host(struct bq24190_dev_info *bdi) · line 561
Quoted 6 lines
drivers/power/supply/bq24190_charger.c +0
-6- -if (!limit) -return -EIO ; - -return 0 ; -}Let's leave this in with
__maybe_unused.
It's named __maybe_unused instead of __always_unused for a reason.
-- Sebastian
Sebastian Reichel
maintainerRe: [PATCH v2 4/7] power: supply: bq24190_charger: Never reset the charger chip
In reply to Hans de GoedeHi,
Quoted 30 lines · Hans de Goede
Resetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery.
The reset in
suspend()is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has been programmed with a higher maxcharge_current/charge_voltagethen putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the maxcharge_current/charge_voltageafter the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep using custom charge settings while suspending is to keep the charger in its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full.Besides never being necessary resetting the charger also causes problems on systems where the charge voltage limit is set higher then the reset value, if this is the case and the charger is reset while charging and the battery voltage is between the 2 voltages, then about half the time the charger gets confused and claims to be charging (REG08 contains
0x64) but in reality the charger has decoupled itself from VBUS (Q1 off) and is drawing 0A from VBUS, leaving the system running from the battery.
Quoted 7 lines
Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
-This is a new patch in v2 of this patch-set
---
I skipped this patch for now due to ongoing discussion and behaviour change. I think your reasoning makes sense and will queue this, if I don't hear it results in regression in the next few days.
-- Sebastian
Quoted 103 lines
drivers/power/supply/bq24190_charger.c | 58 ---------------------------------- 1 file changed, 58 deletions(-)drivers/power/supply/bq24190_charger.c +0
-58@@ -526,40 +526,6 @@ static int bq24190_set_mode_host(struct bq24190_dev_info *bdi)return bq24190_write (bdi,BQ24190_REG_CTTC , v); } -static int bq24190_register_reset (struct bq24190_dev_info *bdi) -{ -int ret, limit =100 ; -u8 v; - -/* Reset the registers */ - ret =bq24190_write_mask (bdi,BQ24190_REG_POC , -BQ24190_REG_POC_RESET_MASK , -BQ24190_REG_POC_RESET_SHIFT , -0x1 ); -if (ret <0 ) -return ret; - -/* Reset bit will be cleared by hardware so poll until it is */ -do { - ret =bq24190_read_mask (bdi,BQ24190_REG_POC , -BQ24190_REG_POC_RESET_MASK , -BQ24190_REG_POC_RESET_SHIFT , - &v); -if (ret <0 ) -return ret; - -if (!v) -break ; - -udelay (10 ); - }while (--limit); - -if (!limit) -return -EIO ; - -return 0 ; -} -/* Charger power supply property routines */ static int bq24190_charger_get_charge_type(struct bq24190_dev_info *bdi,@@ -1380,10 +1346,6 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)return -ENODEV ; } - ret =bq24190_register_reset (bdi); -if (ret <0 ) -return ret; - ret =bq24190_set_mode_host (bdi);if (ret <0 )return ret;@@ -1534,7 +1496,6 @@ static int bq24190_remove(struct i2c_client *client)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);@@ -1577,23 +1538,6 @@ static __maybe_unused int bq24190_runtime_resume(struct device *dev)static __maybe_unused 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); - } - -bq24190_register_reset (bdi); - -if (error >=0 ) { -pm_runtime_mark_last_busy (bdi->dev); -pm_runtime_put_autosuspend (bdi->dev); - } -return 0 ; }@@ -1612,8 +1556,6 @@ static __maybe_unused int bq24190_pm_resume(struct device *dev)pm_runtime_put_noidle (bdi->dev); } -bq24190_register_reset (bdi); -bq24190_set_mode_host (bdi);bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg);if (error >=0 ) {Signature · 1 line
2.9.3
PATCH v2 5/7 power: supply: bq24190_charger: Don't spam the logs on charger plug / unplug
In reply to Hans de GoedeIf the charger gets unplugged before the battery is fully charged we will get a one time Input fault. Ignore this rather then logging a message for it. Likewise on the next interrupt after the one time Input fault all fault flags will be 0, do not log a message when there are no faults.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0
---
Changes in v2:
-This is a new patch in v2 of this patch-set
--- drivers/power/supply/bq24190_charger.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/power/supply/bq24190_charger.c +11 -6
@@ -1189,12 +1189,17 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) }while (f_reg && ++i <2 );if (f_reg != bdi->f_reg) { -dev_info (bdi->dev, -"Fault: boost %d, charge %d, battery %d, ntc %d\n" , - !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_BAT_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_NTC_FAULT_MASK )); +/* +* Don't spam the logs if all faults are cleared, or when the +* cable providing Vbus gets unplugged. +*/ +if (f_reg && f_reg != (1 <<BQ24190_REG_F_CHRG_FAULT_SHIFT )) +dev_info (bdi->dev, +"Fault: boost %d, charge %d, battery %d, ntc %d\n" , + !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_BAT_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_NTC_FAULT_MASK ));mutex_lock (&bdi->f_reg_lock);if ((bdi->f_reg & battery_mask_f) != (f_reg & battery_mask_f))
Signature · 1 line
2.9.3
Re: [PATCH v2 5/7] power: supply: bq24190_charger: Don't spam the logs on charger plug / unplug
Quoted 8 lines · Hans de Goede
If the charger gets unplugged before the battery is fully charged we will get a one time Input fault. Ignore this rather then logging a message for it. Likewise on the next interrupt after the one time Input fault all fault flags will be 0, do not log a message when there are no faults.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0
Sebastian Reichel
maintainerRe: [PATCH v2 5/7] power: supply: bq24190_charger: Don't spam the logs on charger plug / unplug
In reply to Hans de GoedeHi,
Quoted 9 lines · Hans de Goede
If the charger gets unplugged before the battery is fully charged we will get a one time Input fault. Ignore this rather then logging a message for it. Likewise on the next interrupt after the one time Input fault all fault flags will be 0, do not log a message when there are no faults.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0
Quoted 7 lines
Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
-This is a new patch in v2 of this patch-set
---
Thanks, queued.
-- Sebastian
Re: [PATCH v2 5/7] power: supply: bq24190_charger: Don't spam the logs on charger plug / unplug
In reply to Hans de GoedeQuoted 28 lines · Hans de Goede
If the charger gets unplugged before the battery is fully charged we will get a one time Input fault. Ignore this rather then logging a message for it. Likewise on the next interrupt after the one time Input fault all fault flags will be 0, do not log a message when there are no faults.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-2-This is a new patch in v2 of this patch-set --- drivers/power/supply/bq24190_charger.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)drivers/power/supply/bq24190_charger.c +0
-1@@ -1189,12 +1189,17 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) }while (f_reg && ++i <2 );if (f_reg != bdi->f_reg) { - dev_info(bdi->dev,
drivers/power/supply/bq24190_charger.c static void bq24190_check_status(struct bq24190_dev_info *bdi) · line 1196
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +5
-5-"Fault: boost %d, charge %d, battery %d, ntc %d\n" , - !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_BAT_FAULT_MASK ), - !!(f_reg & BQ24190_REG_F_NTC_FAULT_MASK)); +/* +* Don't spam the logs if all faults are cleared, or when the +* cable providing Vbus gets unplugged. +*/ +if (f_reg && f_reg != (1 <<BQ24190_REG_F_CHRG_FAULT_SHIFT ))
I have seen this too, but I think you masked input over-voltage, as it's not differentiated from under-voltage. Maybe check pgstat?
Quoted 12 lines
drivers/power/supply/bq24190_charger.c +6
-1+dev_info (bdi->dev, +"Fault: boost %d, charge %d, battery %d, ntc %d\n" , + !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_BAT_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_NTC_FAULT_MASK ));mutex_lock (&bdi->f_reg_lock);if ((bdi->f_reg & battery_mask_f) != (f_reg & battery_mask_f)) --2.9.3
Re: [PATCH v2 5/7] power: supply: bq24190_charger: Don't spam the logs on charger plug / unplug
In reply to Hans de GoedeQuoted 28 lines · Hans de Goede
If the charger gets unplugged before the battery is fully charged we will get a one time Input fault. Ignore this rather then logging a message for it. Likewise on the next interrupt after the one time Input fault all fault flags will be 0, do not log a message when there are no faults.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-2-This is a new patch in v2 of this patch-set --- drivers/power/supply/bq24190_charger.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)drivers/power/supply/bq24190_charger.c +0
-1@@ -1189,12 +1189,17 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) }while (f_reg && ++i <2 );if (f_reg != bdi->f_reg) { - dev_info(bdi->dev,
drivers/power/supply/bq24190_charger.c static void bq24190_check_status(struct bq24190_dev_info *bdi) · line 1196
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +5
-5-"Fault: boost %d, charge %d, battery %d, ntc %d\n" , - !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_BAT_FAULT_MASK ), - !!(f_reg & BQ24190_REG_F_NTC_FAULT_MASK)); +/* +* Don't spam the logs if all faults are cleared, or when the +* cable providing Vbus gets unplugged. +*/ +if (f_reg && f_reg != (1 <<BQ24190_REG_F_CHRG_FAULT_SHIFT ))
if (f_reg && ((ss_reg & BQ24190_REG_SS_PG_STAT_MASK) ||
f_reg != (1 << BQ24190_REG_F_CHRG_FAULT_SHIFT)) )
Quoted 12 lines
drivers/power/supply/bq24190_charger.c +6
-1+dev_info (bdi->dev, +"Fault: boost %d, charge %d, battery %d, ntc %d\n" , + !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_BAT_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_NTC_FAULT_MASK ));mutex_lock (&bdi->f_reg_lock);if ((bdi->f_reg & battery_mask_f) != (f_reg & battery_mask_f)) --2.9.3
Re: [PATCH v2 5/7] power: supply: bq24190_charger: Don't spam the logs on charger plug / unplug
Hi,
Quoted 41 lines · Liam Breck
Quoted 28 lines · Hans de Goede
If the charger gets unplugged before the battery is fully charged we will get a one time Input fault. Ignore this rather then logging a message for it. Likewise on the next interrupt after the one time Input fault all fault flags will be 0, do not log a message when there are no faults.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-2-This is a new patch in v2 of this patch-set --- drivers/power/supply/bq24190_charger.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)drivers/power/supply/bq24190_charger.c +0
-1@@ -1189,12 +1189,17 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) }while (f_reg && ++i <2 );if (f_reg != bdi->f_reg) { - dev_info(bdi->dev,drivers/power/supply/bq24190_charger.c static void bq24190_check_status(struct bq24190_dev_info *bdi) · line 1196
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +5
-5-"Fault: boost %d, charge %d, battery %d, ntc %d\n" , - !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_BAT_FAULT_MASK ), - !!(f_reg & BQ24190_REG_F_NTC_FAULT_MASK)); +/* +* Don't spam the logs if all faults are cleared, or when the +* cable providing Vbus gets unplugged. +*/ +if (f_reg && f_reg != (1 <<BQ24190_REG_F_CHRG_FAULT_SHIFT ))if (
f_reg&& ((ss_reg&BQ24190_REG_SS_PG_STAT_MASK) ||
Quoted 1 line
f_reg != (1 << BQ24190_REG_F_CHRG_FAULT_SHIFT)) )
Sebastian has already merged the original patch into his for-next branch, please provide a patch on top.
Regards,
Hans
Quoted 13 lines
Quoted 13 lines
drivers/power/supply/bq24190_charger.c +6
-1+dev_info (bdi->dev, +"Fault: boost %d, charge %d, battery %d, ntc %d\n" , + !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_BAT_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_NTC_FAULT_MASK ));mutex_lock (&bdi->f_reg_lock);if ((bdi->f_reg & battery_mask_f) != (f_reg & battery_mask_f)) --2.9.3
Re: [PATCH v2 5/7] power: supply: bq24190_charger: Don't spam the logs on charger plug / unplug
Quoted 57 lines · Hans de Goede
Hi,
Quoted 50 lines · Liam Breck
Quoted 43 lines · Hans de Goede
If the charger gets unplugged before the battery is fully charged we will get a one time Input fault. Ignore this rather then logging a message for it. Likewise on the next interrupt after the one time Input fault all fault flags will be 0, do not log a message when there are no faults.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-2-This is a new patch in v2 of this patch-set --- drivers/power/supply/bq24190_charger.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)drivers/power/supply/bq24190_charger.c +2
-6@@ -1189,12 +1189,17 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) }while (f_reg && ++i <2 );if (f_reg != bdi->f_reg) { -dev_info (bdi->dev, - "Fault: boost %d, charge %d, battery %d, ntc %d\n", - !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_BAT_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_NTC_FAULT_MASK )); +/* +* Don't spam the logs if all faults are cleared, or when the
drivers/power/supply/bq24190_charger.c +3
-0+* cable providing Vbus gets unplugged. +*/ + if (f_reg && f_reg != (1 <<Quoted 1 line
BQ24190_REG_F_CHRG_FAULT_SHIFT))if (
f_reg&& ((ss_reg&BQ24190_REG_SS_PG_STAT_MASK) ||Quoted 1 line
f_reg != (1 << BQ24190_REG_F_CHRG_FAULT_SHIFT)) )
Quoted 3 lines
Sebastian has already merged the original patch into his for-next branch, please
provide a patch on top.
I recall Sebastian merging and then dropping a commit from the other series I'm working on.
I'll return to the charger once the dependency for my charger patchset is merged. I just got a big change request for that.
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ dev_info(bdi->dev,
This should probably be dev_warn now.
Quoted 17 lines
Quoted 16 lines
Quoted 16 lines
+ "Fault: boost %d, charge %d, battery %d,
ntc %d\n",
+ !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK),
+ !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK),drivers/power/supply/bq24190_charger.c +2
-0+ !!(f_reg & BQ24190_REG_F_BAT_FAULT_MASK), + !!(f_reg &
BQ24190_REG_F_NTC_FAULT_MASK));mutex_lock(&bdi->f_reg_lock); if ((bdi->f_reg & battery_mask_f) != (f_reg &
battery_mask_f))
--
2.9.3
Sebastian Reichel
maintainerRe: [PATCH v2 5/7] power: supply: bq24190_charger: Don't spam the logs on charger plug / unplug
Hi,
Quoted 54 lines · Liam Breck
Quoted 53 lines · Hans de Goede
Quoted 50 lines · Liam Breck
Quoted 43 lines · Hans de Goede
If the charger gets unplugged before the battery is fully charged we will get a one time Input fault. Ignore this rather then logging a message for it. Likewise on the next interrupt after the one time Input fault all fault flags will be 0, do not log a message when there are no faults.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-2-This is a new patch in v2 of this patch-set --- drivers/power/supply/bq24190_charger.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)drivers/power/supply/bq24190_charger.c +2
-6@@ -1189,12 +1189,17 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) }while (f_reg && ++i <2 );if (f_reg != bdi->f_reg) { -dev_info (bdi->dev, - "Fault: boost %d, charge %d, battery %d, ntc %d\n", - !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_BAT_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_NTC_FAULT_MASK )); +/* +* Don't spam the logs if all faults are cleared, or when the
drivers/power/supply/bq24190_charger.c +3
-0+* cable providing Vbus gets unplugged. +*/ + if (f_reg && f_reg != (1 <<Quoted 1 line
BQ24190_REG_F_CHRG_FAULT_SHIFT))if (
f_reg&& ((ss_reg&BQ24190_REG_SS_PG_STAT_MASK) ||f_reg != (1 << BQ24190_REG_F_CHRG_FAULT_SHIFT)) )
Quoted 6 lines
Quoted 3 lines
Sebastian has already merged the original patch into his for-next branch, please
provide a patch on top.I recall Sebastian merging and then dropping a commit from the other series I'm working on.
Yeah, I thought it was a fix, but it was useless without the remaining series.
Quoted 2 lines
I'll return to the charger once the dependency for my charger patchset is merged. I just got a big change request for that.
Ok.
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ dev_info(bdi->dev,
This should probably be
dev_warnnow.
makes sense to me.
FWIW I think a follow-up commit for this is enough, but I can also swap the existing commit.
-- Sebastian
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 16 lines
+ "Fault: boost %d, charge %d, battery %d,
ntc %d\n",
+ !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK),
+ !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK),drivers/power/supply/bq24190_charger.c +2
-0+ !!(f_reg & BQ24190_REG_F_BAT_FAULT_MASK), + !!(f_reg &
BQ24190_REG_F_NTC_FAULT_MASK));mutex_lock(&bdi->f_reg_lock); if ((bdi->f_reg & battery_mask_f) != (f_reg &
battery_mask_f))
--
2.9.3
Re: [PATCH v2 5/7] power: supply: bq24190_charger: Don't spam the logs on charger plug / unplug
Quoted 73 lines · Sebastian Reichel
Hi,
Quoted 54 lines · Liam Breck
Quoted 53 lines · Hans de Goede
Quoted 50 lines · Liam Breck
Quoted 43 lines · Hans de Goede
If the charger gets unplugged before the battery is fully charged we will get a one time Input fault. Ignore this rather then logging a message for it. Likewise on the next interrupt after the one time Input fault all fault flags will be 0, do not log a message when there are no faults.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-2-This is a new patch in v2 of this patch-set --- drivers/power/supply/bq24190_charger.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)drivers/power/supply/bq24190_charger.c +2
-6@@ -1189,12 +1189,17 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) }while (f_reg && ++i <2 );if (f_reg != bdi->f_reg) { -dev_info (bdi->dev, - "Fault: boost %d, charge %d, battery %d, ntc %d\n", - !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_BAT_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_NTC_FAULT_MASK )); +/* +* Don't spam the logs if all faults are cleared, or when the
drivers/power/supply/bq24190_charger.c +3
-0+* cable providing Vbus gets unplugged. +*/ + if (f_reg && f_reg != (1 <<Quoted 1 line
BQ24190_REG_F_CHRG_FAULT_SHIFT))if (
f_reg&& ((ss_reg&BQ24190_REG_SS_PG_STAT_MASK) ||f_reg != (1 << BQ24190_REG_F_CHRG_FAULT_SHIFT)) )Quoted 6 lines
Quoted 3 lines
Sebastian has already merged the original patch into his for-next branch, please
provide a patch on top.I recall Sebastian merging and then dropping a commit from the other series I'm working on.
Yeah, I thought it was a fix, but it was useless without the remaining series.
Quoted 2 lines
I'll return to the charger once the dependency for my charger patchset is merged. I just got a big change request for that.
Ok.
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ dev_info(bdi->dev,
This should probably be
dev_warnnow.makes sense to me.
FWIW I think a follow-up commit for this is enough, but I can also swap the existing commit.
I posted a replacement for this commit.
In future could you wait for my ack on patches for this driver? I have more time to study this stuff than Tony does.
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 16 lines
+ "Fault: boost %d, charge %d, battery %d,
ntc %d\n",
+ !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK),
+ !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK),drivers/power/supply/bq24190_charger.c +2
-0+ !!(f_reg & BQ24190_REG_F_BAT_FAULT_MASK), + !!(f_reg &
BQ24190_REG_F_NTC_FAULT_MASK));mutex_lock(&bdi->f_reg_lock); if ((bdi->f_reg & battery_mask_f) != (f_reg &
battery_mask_f))
--
2.9.3
PATCH 1/1 power: bq24190_charger: Limit over/under voltage fault logging
In reply to Hans de GoedeFrom: Liam Breck <[email protected]>
If the charger gets unplugged before the battery is fully charged we will get an over/under voltage fault. Ignore this rather then logging a message for it. Likewise on the next interrupt after the fault all fault flags will be 0, do not log a message when there are no faults.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0
---
Sebastian, here is a replacement for the original version. I include Hans' sign-off since he wrote the original.
drivers/power/supply/bq24190_charger.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/power/supply/bq24190_charger.c +9 -6
@@ -1257,12 +1257,15 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) }while (f_reg && ++i <2 );if (f_reg != bdi->f_reg) { -dev_info (bdi->dev, -"Fault: boost %d, charge %d, battery %d, ntc %d\n" , - !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_BAT_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_NTC_FAULT_MASK )); +if (f_reg && ((ss_reg &BQ24190_REG_SS_PG_STAT_MASK ) || + f_reg != (1 <<BQ24190_REG_F_CHRG_FAULT_SHIFT ))) +/* omit over/under voltage fault after disconnect */ +dev_warn (bdi->dev, +"Fault: boost %d, charge %d, battery %d, ntc %d\n" , + !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_BAT_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_NTC_FAULT_MASK ));mutex_lock (&bdi->f_reg_lock);if ((bdi->f_reg & battery_mask_f) != (f_reg & battery_mask_f))
Signature · 1 line
2.9.3
Re: [PATCH] power: bq24190_charger: Limit over/under voltage fault logging
Hi,
Quoted 11 lines · Liam Breck
From: Liam Breck <[email protected]>
If the charger gets unplugged before the battery is fully charged we will get an over/under voltage fault. Ignore this rather then logging a message for it. Likewise on the next interrupt after the fault all fault flags will be 0, do not log a message when there are no faults.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0
Quoted 6 lines
Cc Tony Lindgren <[email protected]>Signed-off-by Liam Breck <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Sebastian, here is a replacement for the original version. I include Hans' sign-off since he wrote the original.
I can confirm that this still silences the log messages on charger plug / unplug for me:
Regards,
Hans
Quoted 31 lines
drivers/power/supply/bq24190_charger.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)drivers/power/supply/bq24190_charger.c +9
-6@@ -1257,12 +1257,15 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) }while (f_reg && ++i <2 );if (f_reg != bdi->f_reg) { -dev_info (bdi->dev, -"Fault: boost %d, charge %d, battery %d, ntc %d\n" , - !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_BAT_FAULT_MASK ), - !!(f_reg &BQ24190_REG_F_NTC_FAULT_MASK )); +if (f_reg && ((ss_reg &BQ24190_REG_SS_PG_STAT_MASK ) || + f_reg != (1 <<BQ24190_REG_F_CHRG_FAULT_SHIFT ))) +/* omit over/under voltage fault after disconnect */ +dev_warn (bdi->dev, +"Fault: boost %d, charge %d, battery %d, ntc %d\n" , + !!(f_reg &BQ24190_REG_F_BOOST_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_CHRG_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_BAT_FAULT_MASK ), + !!(f_reg &BQ24190_REG_F_NTC_FAULT_MASK ));mutex_lock (&bdi->f_reg_lock);if ((bdi->f_reg & battery_mask_f) != (f_reg & battery_mask_f))
PATCH v2 1/1 power: bq24190_charger: Limit over/under voltage fault logging
In reply to Hans de GoedeFrom: Liam Breck <[email protected]>
If the charger is unplugged before the battery is full we may see an over/under voltage fault. Ignore this rather then emitting a message or uevent.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0
---
v2: Don't hide clearance of other more urgent faults, or produce
a uevent for this superficial fault.
drivers/power/supply/bq24190_charger.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/power/supply/bq24190_charger.c +6 -1
@@ -1256,8 +1256,13 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) } }while (f_reg && ++i <2 ); +/* ignore over/under voltage fault after disconnect */ +if (f_reg == (1 <<BQ24190_REG_F_CHRG_FAULT_SHIFT ) && + !(ss_reg &BQ24190_REG_SS_PG_STAT_MASK )) + f_reg =0 ; +if (f_reg != bdi->f_reg) { - dev_info(bdi->dev, + dev_warn(bdi->dev, "Fault: boost %d, charge %d, battery %d, ntc %d\n", !!(f_reg & BQ24190_REG_F_BOOST_FAULT_MASK), !!(f_reg & BQ24190_REG_F_CHRG_FAULT_MASK),
Signature · 1 line
2.9.3
Re: [PATCH v2] power: bq24190_charger: Limit over/under voltage fault logging
Hi,
Quoted 30 lines · Liam Breck
From: Liam Breck <[email protected]>
If the charger is unplugged before the battery is full we may see an over/under voltage fault. Ignore this rather then emitting a message or uevent.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0Cc Tony Lindgren <[email protected]>Cc Hans de Goede <[email protected]>Signed-off-by Liam Breck <[email protected]>---
v2: Don't hide clearance of other more urgent faults, or produce
a uevent for this superficial fault.drivers/power/supply/bq24190_charger.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/power/supply/bq24190_charger.c +1
-0@@ -1256,8 +1256,13 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) } }while (f_reg && ++i <2 ); +/* ignore over/under voltage fault after disconnect */
drivers/power/supply/bq24190_charger.c static void bq24190_check_status(struct bq24190_dev_info *bdi) · line 1268
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +5
-1+if (f_reg == (1 <<BQ24190_REG_F_CHRG_FAULT_SHIFT ) && + !(ss_reg &BQ24190_REG_SS_PG_STAT_MASK )) + f_reg =0 ; +if (f_reg != bdi->f_reg) { - dev_info(bdi->dev, + dev_warn(bdi->dev, "Fault: boost %d, charge %d, battery %d, ntc %d\n", !!(f_reg & BQ24190_REG_F_BOOST_FAULT_MASK), !!(f_reg & BQ24190_REG_F_CHRG_FAULT_MASK),
You're now once again logging a warning when all faults clear, I believe this should now be:
if (freg) dev_warn(bdi->dev, "Fault: boost %d, charge %d, battery %d, ntc %d\n", !!(f_reg & BQ24190_REG_F_BOOST_FAULT_MASK), !!(f_reg & BQ24190_REG_F_CHRG_FAULT_MASK),
Regards,
Hans
Re: [PATCH v2] power: bq24190_charger: Limit over/under voltage fault logging
Quoted 35 lines · Hans de Goede
Hi,
Quoted 31 lines · Liam Breck
From: Liam Breck <[email protected]>
If the charger is unplugged before the battery is full we may see an over/under voltage fault. Ignore this rather then emitting a message or uevent.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0Cc Tony Lindgren <[email protected]>Cc Hans de Goede <[email protected]>Signed-off-by Liam Breck <[email protected]>---
v2: Don't hide clearance of other more urgent faults, or produce
a uevent for this superficial fault.drivers/power/supply/bq24190_charger.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/power/supply/bq24190_charger.c +0
-0@@ -1256,8 +1256,13 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) } }while (f_reg && ++i <2 );
Quoted 15 lines
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +6
-1+/* ignore over/under voltage fault after disconnect */ +if (f_reg == (1 <<BQ24190_REG_F_CHRG_FAULT_SHIFT ) && + !(ss_reg &BQ24190_REG_SS_PG_STAT_MASK )) + f_reg =0 ; + if (f_reg != bdi->f_reg) { - dev_info(bdi->dev, + dev_warn(bdi->dev, "Fault: boost %d, charge %d, battery %d, ntc %d\n",Quoted 3 lines
!!(f_reg & BQ24190_REG_F_BOOST_FAULT_MASK), !!(f_reg & BQ24190_REG_F_CHRG_FAULT_MASK),You're now once again logging a warning when all faults clear,
By design; I want to know when any serious fault clears.
The under-voltage fault on disconnect will not trigger a cleared msg, because the orig error is not recorded in bdi->f_reg.
Quoted 15 lines
I believe this should now be:
if (freg)
dev_warn(bdi->dev,
"Fault: boost %d, charge %d, battery %d, ntc
%d\n",!!(f_reg & BQ24190_REG_F_BOOST_FAULT_MASK), !!(f_reg & BQ24190_REG_F_CHRG_FAULT_MASK),Regards,
Hans
Re: [PATCH v2] power: bq24190_charger: Limit over/under voltage fault logging
Hi,
Quoted 52 lines · Liam Breck
Quoted 35 lines · Hans de Goede
Hi,
Quoted 31 lines · Liam Breck
From: Liam Breck <[email protected]>
If the charger is unplugged before the battery is full we may see an over/under voltage fault. Ignore this rather then emitting a message or uevent.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0Cc Tony Lindgren <[email protected]>Cc Hans de Goede <[email protected]>Signed-off-by Liam Breck <[email protected]>---
v2: Don't hide clearance of other more urgent faults, or produce
a uevent for this superficial fault.drivers/power/supply/bq24190_charger.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/power/supply/bq24190_charger.c +0
-0@@ -1256,8 +1256,13 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) } }while (f_reg && ++i <2 );Quoted 15 lines
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +6
-1+/* ignore over/under voltage fault after disconnect */ +if (f_reg == (1 <<BQ24190_REG_F_CHRG_FAULT_SHIFT ) && + !(ss_reg &BQ24190_REG_SS_PG_STAT_MASK )) + f_reg =0 ; + if (f_reg != bdi->f_reg) { - dev_info(bdi->dev, + dev_warn(bdi->dev, "Fault: boost %d, charge %d, battery %d, ntc %d\n",Quoted 3 lines
!!(f_reg & BQ24190_REG_F_BOOST_FAULT_MASK), !!(f_reg & BQ24190_REG_F_CHRG_FAULT_MASK),You're now once again logging a warning when all faults clear,
Quoted 4 lines
By design; I want to know when any serious fault clears.
The under-voltage fault on disconnect will not trigger a cleared msg, because the orig error is not recorded in
bdi->f_reg.
Ok fine by me.
Regards,
Hans
Quoted 16 lines
Quoted 16 lines
I believe this should now be:
if (freg)
dev_warn(bdi->dev,
"Fault: boost %d, charge %d, battery %d, ntc
%d\n",!!(f_reg & BQ24190_REG_F_BOOST_FAULT_MASK), !!(f_reg & BQ24190_REG_F_CHRG_FAULT_MASK),Regards,
Hans
Tony Lindgren
Acked-byRe: [PATCH v2] power: bq24190_charger: Limit over/under voltage fault logging
Quoted 55 lines · Hans de Goede
Hi,
Quoted 52 lines · Liam Breck
Quoted 50 lines · Hans de Goede
Hi,
Quoted 41 lines · Liam Breck
From: Liam Breck <[email protected]>
If the charger is unplugged before the battery is full we may see an over/under voltage fault. Ignore this rather then emitting a message or uevent.
This fixes messages like these getting logged on charger unplug + replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0Cc Tony Lindgren <[email protected]>Cc Hans de Goede <[email protected]>Signed-off-by Liam Breck <[email protected]>---
v2: Don't hide clearance of other more urgent faults, or produce
a uevent for this superficial fault.drivers/power/supply/bq24190_charger.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/power/supply/bq24190_charger.c +6
-1@@ -1256,8 +1256,13 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) } }while (f_reg && ++i <2 ); +/* ignore over/under voltage fault after disconnect */ +if (f_reg == (1 <<BQ24190_REG_F_CHRG_FAULT_SHIFT ) && + !(ss_reg &BQ24190_REG_SS_PG_STAT_MASK )) + f_reg =0 ; + if (f_reg != bdi->f_reg) { - dev_info(bdi->dev, + dev_warn(bdi->dev, "Fault: boost %d, charge %d, battery %d, ntc %d\n",Quoted 3 lines
!!(f_reg & BQ24190_REG_F_BOOST_FAULT_MASK), !!(f_reg & BQ24190_REG_F_CHRG_FAULT_MASK),You're now once again logging a warning when all faults clear,
Quoted 6 lines
Quoted 4 lines
By design; I want to know when any serious fault clears.
The under-voltage fault on disconnect will not trigger a cleared msg, because the orig error is not recorded in
bdi->f_reg.Ok fine by me.
Fine with me too:
PATCH v2 6/7 power: supply: bq24190_charger: Cleanup error-exit labels in probe()
In reply to Hans de GoedeNames like out1, out2, etc. do not make it easier to follow what is going on and make it harder (require renaming) if any steps are later added / removed. Rename the labels to sane names.
This also folds out1 and out2 into one pm_runtime_disable step, if pm_runtime_get_sync fails we still need to do the put, it failing means that the device failed to resume, but the refcount will have been incremented and we need to decrement it.
---
Changes in v2:
-This is a new patch in v2 of this patch-set
--- drivers/power/supply/bq24190_charger.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
drivers/power/supply/bq24190_charger.c +11 -13
@@ -1408,12 +1408,12 @@ static int bq24190_probe(struct i2c_client *client,pm_runtime_set_autosuspend_delay (dev,600 ); ret =pm_runtime_get_sync (dev);if (ret <0 ) - goto out1; + goto pm_runtime_disable; ret =bq24190_hw_init (bdi);if (ret <0 ) {dev_err (dev,"Hardware init failed\n" ); - goto out2; + goto pm_runtime_disable; } charger_cfg.drv_data = bdi;
@@ -1424,7 +1424,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 out2; + goto pm_runtime_disable; } battery_cfg.drv_data = bdi;
@@ -1433,13 +1433,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 out3; + goto unregister_charger; } ret =bq24190_sysfs_create_group (bdi);if (ret) {dev_err (dev,"Can't create sysfs entries\n" ); - goto out4; + goto unregister_battery; } bdi->initialized = true;
@@ -1450,7 +1450,7 @@ 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 out5; + goto remove_sysfs_group; }if (bdi->extcon) {
@@ -1459,7 +1459,7 @@ static int bq24190_probe(struct i2c_client *client, ret =devm_extcon_register_notifier (dev, bdi->extcon,-1 , &bdi->extcon_nb);if (ret) - goto out5; + goto remove_sysfs_group;/* Sync initial cable state */ queue_delayed_work (system_wq, &bdi->extcon_work,0 );
@@ -1472,19 +1472,17 @@ static int bq24190_probe(struct i2c_client *client,return 0 ; -out5: +remove_sysfs_group:bq24190_sysfs_remove_group (bdi); -out4: +unregister_battery:power_supply_unregister (bdi->battery); -out3: +unregister_charger:power_supply_unregister (bdi->charger); -out2: +pm_runtime_disable:pm_runtime_put_sync (dev); - -out1:pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev);return ret;
Signature · 1 line
2.9.3
Re: [PATCH v2 6/7] power: supply: bq24190_charger: Cleanup error-exit labels in probe()
Quoted 8 lines · Hans de Goede
Names like out1, out2, etc. do not make it easier to follow what is going on and make it harder (require renaming) if any steps are later added / removed. Rename the labels to sane names.
This also folds out1 and out2 into one
pm_runtime_disablestep, ifpm_runtime_get_syncfails we still need to do the put, it failing means that the device failed to resume, but the refcount will have been incremented and we need to decrement it.
Seems OK to me:
Re: [PATCH v2 6/7] power: supply: bq24190_charger: Cleanup error-exit labels in probe()
In reply to Hans de GoedeQuoted 3 lines · Hans de Goede
Names like out1, out2, etc. do not make it easier to follow what is going on and make it harder (require renaming) if any steps are later added / removed. Rename the labels to sane names.
Good idea. But the new labels look like function names, so maybe:
out_charger, out_battery, out_sysfs, out_pmrt
Quoted 104 lines
This also folds out1 and out2 into one
pm_runtime_disablestep, ifpm_runtime_get_syncfails we still need to do the put, it failing means that the device failed to resume, but the refcount will have been incremented and we need to decrement it.Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-2-This is a new patch in v2 of this patch-set --- drivers/power/supply/bq24190_charger.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)drivers/power/supply/bq24190_charger.c +11
-14@@ -1408,12 +1408,12 @@ static int bq24190_probe(struct i2c_client *client,pm_runtime_set_autosuspend_delay (dev,600 ); ret =pm_runtime_get_sync (dev);if (ret <0 ) - goto out1; + goto pm_runtime_disable; ret =bq24190_hw_init (bdi);if (ret <0 ) {dev_err (dev,"Hardware init failed\n" ); - goto out2; + goto pm_runtime_disable; } charger_cfg.drv_data = bdi;@@ -1424,7 +1424,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 out2; + goto pm_runtime_disable; } battery_cfg.drv_data = bdi;@@ -1433,13 +1433,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 out3; + goto unregister_charger; } ret =bq24190_sysfs_create_group (bdi);if (ret) {dev_err (dev,"Can't create sysfs entries\n" ); - goto out4; + goto unregister_battery; } bdi->initialized = true;@@ -1450,7 +1450,7 @@ 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 out5; + goto remove_sysfs_group; }if (bdi->extcon) {@@ -1459,7 +1459,7 @@ static int bq24190_probe(struct i2c_client *client, ret =devm_extcon_register_notifier (dev, bdi->extcon,-1 , &bdi->extcon_nb);if (ret) - goto out5; + goto remove_sysfs_group;/* Sync initial cable state */ queue_delayed_work (system_wq, &bdi->extcon_work,0 );@@ -1472,19 +1472,17 @@ static int bq24190_probe(struct i2c_client *client,return 0 ; -out5: +remove_sysfs_group:bq24190_sysfs_remove_group (bdi); -out4: +unregister_battery:power_supply_unregister (bdi->battery); -out3: +unregister_charger:power_supply_unregister (bdi->charger); -out2: +pm_runtime_disable:pm_runtime_put_sync (dev); - -out1:pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev);return ret; --2.9.3
Re: [PATCH v2 6/7] power: supply: bq24190_charger: Cleanup error-exit labels in probe()
Hi,
Quoted 6 lines · Liam Breck
Quoted 3 lines · Hans de Goede
Names like out1, out2, etc. do not make it easier to follow what is going on and make it harder (require renaming) if any steps are later added / removed. Rename the labels to sane names.
Good idea. But the new labels look like function names
labels named like this are used all throughout the kernel, see for example drivers/power/supply/pm2301_charger.c, drivers/power/supply/ab8500_*.c
Quoted 1 line
so maybe:
out_charger,out_battery,out_sysfs,out_pmrt
Maybe paint the bike-shed yellow ? (Sorry couldn't resist).
Regards,
Hans
Quoted 105 lines
Quoted 105 lines
This also folds out1 and out2 into one
pm_runtime_disablestep, ifpm_runtime_get_syncfails we still need to do the put, it failing means that the device failed to resume, but the refcount will have been incremented and we need to decrement it.Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-2-This is a new patch in v2 of this patch-set --- drivers/power/supply/bq24190_charger.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)drivers/power/supply/bq24190_charger.c +11
-14@@ -1408,12 +1408,12 @@ static int bq24190_probe(struct i2c_client *client,pm_runtime_set_autosuspend_delay (dev,600 ); ret =pm_runtime_get_sync (dev);if (ret <0 ) - goto out1; + goto pm_runtime_disable; ret =bq24190_hw_init (bdi);if (ret <0 ) {dev_err (dev,"Hardware init failed\n" ); - goto out2; + goto pm_runtime_disable; } charger_cfg.drv_data = bdi;@@ -1424,7 +1424,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 out2; + goto pm_runtime_disable; } battery_cfg.drv_data = bdi;@@ -1433,13 +1433,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 out3; + goto unregister_charger; } ret =bq24190_sysfs_create_group (bdi);if (ret) {dev_err (dev,"Can't create sysfs entries\n" ); - goto out4; + goto unregister_battery; } bdi->initialized = true;@@ -1450,7 +1450,7 @@ 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 out5; + goto remove_sysfs_group; }if (bdi->extcon) {@@ -1459,7 +1459,7 @@ static int bq24190_probe(struct i2c_client *client, ret =devm_extcon_register_notifier (dev, bdi->extcon,-1 , &bdi->extcon_nb);if (ret) - goto out5; + goto remove_sysfs_group;/* Sync initial cable state */ queue_delayed_work (system_wq, &bdi->extcon_work,0 );@@ -1472,19 +1472,17 @@ static int bq24190_probe(struct i2c_client *client,return 0 ; -out5: +remove_sysfs_group:bq24190_sysfs_remove_group (bdi); -out4: +unregister_battery:power_supply_unregister (bdi->battery); -out3: +unregister_charger:power_supply_unregister (bdi->charger); -out2: +pm_runtime_disable:pm_runtime_put_sync (dev); - -out1:pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev);return ret; --2.9.3
Re: [PATCH v2 6/7] power: supply: bq24190_charger: Cleanup error-exit labels in probe()
Quoted 15 lines · Hans de Goede
Hi,
Quoted 10 lines · Liam Breck
Quoted 4 lines · Hans de Goede
Names like out1, out2, etc. do not make it easier to follow what is going on and make it harder (require renaming) if any steps are later added / removed. Rename the labels to sane names.
Good idea. But the new labels look like function names
Quoted 7 lines
labels named like this are used all throughout the kernel, see for example
drivers/power/supply/pm2301_charger.c,drivers/power/supply/ab8500_*.cQuoted 1 line
so maybe:
out_charger,out_battery,out_sysfs,out_pmrtMaybe paint the bike-shed yellow ? (Sorry couldn't resist).
Well the convention for one goto is "out", so it's sensible to use out_whatever for multiple cases. Conventions and names matter, so could you adjust these?
Quoted 113 lines
Quoted 112 lines
Quoted 112 lines
This also folds out1 and out2 into one
pm_runtime_disablestep, ifpm_runtime_get_syncfails we still need to do the put, it failing means that the device failed to resume, but the refcount will have been incremented and we need to decrement it.Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-2-This is a new patch in v2 of this patch-set --- drivers/power/supply/bq24190_charger.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)drivers/power/supply/bq24190_charger.c +2
-2@@ -1408,12 +1408,12 @@ static int bq24190_probe(struct i2c_client *client,pm_runtime_set_autosuspend_delay (dev,600 ); ret =pm_runtime_get_sync (dev);if (ret <0 ) - goto out1; + goto pm_runtime_disable; ret =bq24190_hw_init (bdi);if (ret <0 ) {dev_err (dev,"Hardware init failed\n" ); - goto out2; + goto pm_runtime_disable; }charger_cfg.drv_data = bdi;drivers/power/supply/bq24190_charger.c +3
-3@@ -1424,7 +1424,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 out2; + goto pm_runtime_disable; } battery_cfg.drv_data = bdi;@@ -1433,13 +1433,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 out3; + goto unregister_charger; } ret =bq24190_sysfs_create_group (bdi);if (ret) {dev_err (dev,"Can't create sysfs entries\n" ); - goto out4; + goto unregister_battery; }bdi->initialized = true;drivers/power/supply/bq24190_charger.c +6
-8@@ -1450,7 +1450,7 @@ 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 out5; + goto remove_sysfs_group; }if (bdi->extcon) {@@ -1459,7 +1459,7 @@ static int bq24190_probe(struct i2c_client *client, ret =devm_extcon_register_notifier (dev, bdi->extcon,-1 , &bdi->extcon_nb);if (ret) - goto out5; + goto remove_sysfs_group;/* Sync initial cable state */ queue_delayed_work (system_wq, &bdi->extcon_work,0 );@@ -1472,19 +1472,17 @@ static int bq24190_probe(struct i2c_client *client, return 0; -out5: +remove_sysfs_group:bq24190_sysfs_remove_group (bdi); -out4: +unregister_battery:power_supply_unregister (bdi->battery); -out3: +unregister_charger:power_supply_unregister (bdi->charger); -out2: +pm_runtime_disable:pm_runtime_put_sync (dev); - -out1:pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev);return ret;--
2.9.3
Sebastian Reichel
maintainerRe: [PATCH v2 6/7] power: supply: bq24190_charger: Cleanup error-exit labels in probe()
In reply to Hans de GoedeHi,
Quoted 9 lines · Hans de Goede
Names like out1, out2, etc. do not make it easier to follow what is going on and make it harder (require renaming) if any steps are later added / removed. Rename the labels to sane names.
This also folds out1 and out2 into one
pm_runtime_disablestep, ifpm_runtime_get_syncfails we still need to do the put, it failing means that the device failed to resume, but the refcount will have been incremented and we need to decrement it.
Quoted 7 lines
Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
-This is a new patch in v2 of this patch-set
---
I tried to queue this, but it does not apply without the reset patch.
-- Sebastian
Quoted 92 lines
drivers/power/supply/bq24190_charger.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)drivers/power/supply/bq24190_charger.c +11
-13@@ -1408,12 +1408,12 @@ static int bq24190_probe(struct i2c_client *client,pm_runtime_set_autosuspend_delay (dev,600 ); ret =pm_runtime_get_sync (dev);if (ret <0 ) - goto out1; + goto pm_runtime_disable; ret =bq24190_hw_init (bdi);if (ret <0 ) {dev_err (dev,"Hardware init failed\n" ); - goto out2; + goto pm_runtime_disable; } charger_cfg.drv_data = bdi;@@ -1424,7 +1424,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 out2; + goto pm_runtime_disable; } battery_cfg.drv_data = bdi;@@ -1433,13 +1433,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 out3; + goto unregister_charger; } ret =bq24190_sysfs_create_group (bdi);if (ret) {dev_err (dev,"Can't create sysfs entries\n" ); - goto out4; + goto unregister_battery; } bdi->initialized = true;@@ -1450,7 +1450,7 @@ 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 out5; + goto remove_sysfs_group; }if (bdi->extcon) {@@ -1459,7 +1459,7 @@ static int bq24190_probe(struct i2c_client *client, ret =devm_extcon_register_notifier (dev, bdi->extcon,-1 , &bdi->extcon_nb);if (ret) - goto out5; + goto remove_sysfs_group;/* Sync initial cable state */ queue_delayed_work (system_wq, &bdi->extcon_work,0 );@@ -1472,19 +1472,17 @@ static int bq24190_probe(struct i2c_client *client,return 0 ; -out5: +remove_sysfs_group:bq24190_sysfs_remove_group (bdi); -out4: +unregister_battery:power_supply_unregister (bdi->battery); -out3: +unregister_charger:power_supply_unregister (bdi->charger); -out2: +pm_runtime_disable:pm_runtime_put_sync (dev); - -out1:pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev);return ret;Signature · 1 line
2.9.3
Re: [PATCH v2 6/7] power: supply: bq24190_charger: Cleanup error-exit labels in probe()
Hi,
Quoted 20 lines · Sebastian Reichel
Hi,
Quoted 9 lines · Hans de Goede
Names like out1, out2, etc. do not make it easier to follow what is going on and make it harder (require renaming) if any steps are later added / removed. Rename the labels to sane names.
This also folds out1 and out2 into one
pm_runtime_disablestep, ifpm_runtime_get_syncfails we still need to do the put, it failing means that the device failed to resume, but the refcount will have been incremented and we need to decrement it.Quoted 7 lines
Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
-This is a new patch in v2 of this patch-set
---
Quoted 2 lines
I tried to queue this, but it does not apply without the reset patch.
Thank you for queuing the others, this is mainly a preparation patch to make the patch removing the battery interface cleaner, so merging this can wait till some form of the reset patch is merged.
Regards,
Hans
Quoted 95 lines
-- Sebastian
Quoted 92 lines
drivers/power/supply/bq24190_charger.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)drivers/power/supply/bq24190_charger.c +11
-14@@ -1408,12 +1408,12 @@ static int bq24190_probe(struct i2c_client *client,pm_runtime_set_autosuspend_delay (dev,600 ); ret =pm_runtime_get_sync (dev);if (ret <0 ) - goto out1; + goto pm_runtime_disable; ret =bq24190_hw_init (bdi);if (ret <0 ) {dev_err (dev,"Hardware init failed\n" ); - goto out2; + goto pm_runtime_disable; } charger_cfg.drv_data = bdi;@@ -1424,7 +1424,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 out2; + goto pm_runtime_disable; } battery_cfg.drv_data = bdi;@@ -1433,13 +1433,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 out3; + goto unregister_charger; } ret =bq24190_sysfs_create_group (bdi);if (ret) {dev_err (dev,"Can't create sysfs entries\n" ); - goto out4; + goto unregister_battery; } bdi->initialized = true;@@ -1450,7 +1450,7 @@ 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 out5; + goto remove_sysfs_group; }if (bdi->extcon) {@@ -1459,7 +1459,7 @@ static int bq24190_probe(struct i2c_client *client, ret =devm_extcon_register_notifier (dev, bdi->extcon,-1 , &bdi->extcon_nb);if (ret) - goto out5; + goto remove_sysfs_group;/* Sync initial cable state */ queue_delayed_work (system_wq, &bdi->extcon_work,0 );@@ -1472,19 +1472,17 @@ static int bq24190_probe(struct i2c_client *client,return 0 ; -out5: +remove_sysfs_group:bq24190_sysfs_remove_group (bdi); -out4: +unregister_battery:power_supply_unregister (bdi->battery); -out3: +unregister_charger:power_supply_unregister (bdi->charger); -out2: +pm_runtime_disable:pm_runtime_put_sync (dev); - -out1:pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev);return ret; --2.9.3
PATCH v2 7/7 power: supply: bq24190_charger: Remove battery power_supply device
In reply to Hans de GoedeThe TI bq24190 chip is purely a charger chip, as such it has very little battery info to export to userspace and in practice it is almost always used together with a separate fuel-gauge chip which does have interesting info to export.
Since the userspace ABI requires there to be only 1 power_supply device registered per physical battery, the limited battery power_supply device the bq24190_charger driver is registering is actually getting in the way of a fuel-gauge driver exporting more useful info, therefor this commit removes the battery power_supply device.
---
Changes in v2:
-This is a new patch in v2 of this patch-set
--- drivers/power/supply/bq24190_charger.c | 290 +-------------------------------- 1 file changed, 5 insertions(+), 285 deletions(-)
drivers/power/supply/bq24190_charger.c +5 -285
@@ -151,7 +151,6 @@ struct bq24190_dev_info {struct i2c_client *client;struct device *dev;struct power_supply *charger; -struct power_supply *battery;struct extcon_dev *extcon;struct notifier_block extcon_nb;struct delayed_work extcon_work;
@@ -910,266 +909,9 @@ static const struct power_supply_desc bq24190_charger_desc = { .property_is_writeable = bq24190_charger_property_is_writeable, }; -/* Battery power supply property routines */ - -static int bq24190_battery_get_status (struct bq24190_dev_info *bdi, -union power_supply_propval *val) -{ -u8 ss_reg, chrg_fault; -int status, ret; - -mutex_lock (&bdi->f_reg_lock); - chrg_fault = bdi->f_reg; -mutex_unlock (&bdi->f_reg_lock); - - chrg_fault &=BQ24190_REG_F_CHRG_FAULT_MASK ; - chrg_fault >>=BQ24190_REG_F_CHRG_FAULT_SHIFT ; - - ret =bq24190_read (bdi,BQ24190_REG_SS , &ss_reg); -if (ret <0 ) -return ret; - -/* -* The battery must be discharging when any of these are true: -* - there is no good power source; -* - there is a charge fault. -* Could also be discharging when in "supplement mode" but -* there is no way to tell when its in that mode. -*/ -if (!(ss_reg &BQ24190_REG_SS_PG_STAT_MASK ) || chrg_fault) { - status =POWER_SUPPLY_STATUS_DISCHARGING ; - }else { - ss_reg &=BQ24190_REG_SS_CHRG_STAT_MASK ; - ss_reg >>=BQ24190_REG_SS_CHRG_STAT_SHIFT ; - -switch (ss_reg) { -case 0x0 :/* Not Charging */ - status =POWER_SUPPLY_STATUS_NOT_CHARGING ; -break ; -case 0x1 :/* Pre-charge */ -case 0x2 :/* Fast Charging */ - status =POWER_SUPPLY_STATUS_CHARGING ; -break ; -case 0x3 :/* Charge Termination Done */ - status =POWER_SUPPLY_STATUS_FULL ; -break ; -default : - ret = -EIO ; - } - } - -if (!ret) - val->intval = status; - -return ret; -} - -static int bq24190_battery_get_health (struct bq24190_dev_info *bdi, -union power_supply_propval *val) -{ -u8 v; -int health; - -mutex_lock (&bdi->f_reg_lock); - v = bdi->f_reg; -mutex_unlock (&bdi->f_reg_lock); - -if (v &BQ24190_REG_F_BAT_FAULT_MASK ) { - health =POWER_SUPPLY_HEALTH_OVERVOLTAGE ; - }else { - v &=BQ24190_REG_F_NTC_FAULT_MASK ; - v >>=BQ24190_REG_F_NTC_FAULT_SHIFT ; - -switch (v) { -case 0x0 :/* Normal */ - health =POWER_SUPPLY_HEALTH_GOOD ; -break ; -case 0x1 :/* TS1 Cold */ -case 0x3 :/* TS2 Cold */ -case 0x5 :/* Both Cold */ - health =POWER_SUPPLY_HEALTH_COLD ; -break ; -case 0x2 :/* TS1 Hot */ -case 0x4 :/* TS2 Hot */ -case 0x6 :/* Both Hot */ - health =POWER_SUPPLY_HEALTH_OVERHEAT ; -break ; -default : - health =POWER_SUPPLY_HEALTH_UNKNOWN ; - } - } - - val->intval = health; -return 0 ; -} - -static int bq24190_battery_get_online (struct bq24190_dev_info *bdi, -union power_supply_propval *val) -{ -u8 batfet_disable; -int ret; - - ret =bq24190_read_mask (bdi,BQ24190_REG_MOC , -BQ24190_REG_MOC_BATFET_DISABLE_MASK , -BQ24190_REG_MOC_BATFET_DISABLE_SHIFT , &batfet_disable); -if (ret <0 ) -return ret; - - val->intval = !batfet_disable; -return 0 ; -} - -static int bq24190_battery_set_online (struct bq24190_dev_info *bdi, -const union power_supply_propval *val) -{ -return bq24190_write_mask (bdi,BQ24190_REG_MOC , -BQ24190_REG_MOC_BATFET_DISABLE_MASK , -BQ24190_REG_MOC_BATFET_DISABLE_SHIFT , !val->intval); -} - -static int bq24190_battery_get_temp_alert_max (struct bq24190_dev_info *bdi, -union power_supply_propval *val) -{ -int temp, ret; - - ret =bq24190_get_field_val (bdi,BQ24190_REG_ICTRC , -BQ24190_REG_ICTRC_TREG_MASK , -BQ24190_REG_ICTRC_TREG_SHIFT , - bq24190_ictrc_treg_values, -ARRAY_SIZE (bq24190_ictrc_treg_values), &temp); -if (ret <0 ) -return ret; - - val->intval = temp; -return 0 ; -} - -static int bq24190_battery_set_temp_alert_max (struct bq24190_dev_info *bdi, -const union power_supply_propval *val) -{ -return bq24190_set_field_val (bdi,BQ24190_REG_ICTRC , -BQ24190_REG_ICTRC_TREG_MASK , -BQ24190_REG_ICTRC_TREG_SHIFT , - bq24190_ictrc_treg_values, -ARRAY_SIZE (bq24190_ictrc_treg_values), val->intval); -} - -static int bq24190_battery_get_property (struct power_supply *psy, -enum power_supply_property psp,union power_supply_propval *val) -{ -struct bq24190_dev_info *bdi =power_supply_get_drvdata (psy); -int ret; - -dev_dbg (bdi->dev,"prop: %d\n" , psp); - - ret =pm_runtime_get_sync (bdi->dev); -if (ret <0 ) -return ret; - -switch (psp) { -case POWER_SUPPLY_PROP_STATUS : - ret =bq24190_battery_get_status (bdi, val); -break ; -case POWER_SUPPLY_PROP_HEALTH : - ret =bq24190_battery_get_health (bdi, val); -break ; -case POWER_SUPPLY_PROP_ONLINE : - ret =bq24190_battery_get_online (bdi, val); -break ; -case POWER_SUPPLY_PROP_TECHNOLOGY : -/* Could be Li-on or Li-polymer but no way to tell which */ - val->intval =POWER_SUPPLY_TECHNOLOGY_UNKNOWN ; - ret =0 ; -break ; -case POWER_SUPPLY_PROP_TEMP_ALERT_MAX : - ret =bq24190_battery_get_temp_alert_max (bdi, val); -break ; -case POWER_SUPPLY_PROP_SCOPE : - val->intval =POWER_SUPPLY_SCOPE_SYSTEM ; - ret =0 ; -break ; -default : - ret = -ENODATA ; - } - -pm_runtime_mark_last_busy (bdi->dev); -pm_runtime_put_autosuspend (bdi->dev); - -return ret; -} - -static int bq24190_battery_set_property (struct power_supply *psy, -enum power_supply_property psp, -const union power_supply_propval *val) -{ -struct bq24190_dev_info *bdi =power_supply_get_drvdata (psy); -int ret; - -dev_dbg (bdi->dev,"prop: %d\n" , psp); - - ret =pm_runtime_get_sync (bdi->dev); -if (ret <0 ) -return ret; - -switch (psp) { -case POWER_SUPPLY_PROP_ONLINE : - ret =bq24190_battery_set_online (bdi, val); -break ; -case POWER_SUPPLY_PROP_TEMP_ALERT_MAX : - ret =bq24190_battery_set_temp_alert_max (bdi, val); -break ; -default : - ret = -EINVAL ; - } - -pm_runtime_mark_last_busy (bdi->dev); -pm_runtime_put_autosuspend (bdi->dev); - -return ret; -} - -static int bq24190_battery_property_is_writeable (struct power_supply *psy, -enum power_supply_property psp) -{ -int ret; - -switch (psp) { -case POWER_SUPPLY_PROP_ONLINE : -case POWER_SUPPLY_PROP_TEMP_ALERT_MAX : - ret =1 ; -break ; -default : - ret =0 ; - } - -return ret; -} - -static enum power_supply_property bq24190_battery_properties[] = { -POWER_SUPPLY_PROP_STATUS , -POWER_SUPPLY_PROP_HEALTH , -POWER_SUPPLY_PROP_ONLINE , -POWER_SUPPLY_PROP_TECHNOLOGY , -POWER_SUPPLY_PROP_TEMP_ALERT_MAX , -POWER_SUPPLY_PROP_SCOPE , -}; - -static const struct power_supply_desc bq24190_battery_desc = { - .name ="bq24190-battery" , - .type =POWER_SUPPLY_TYPE_BATTERY , - .properties = bq24190_battery_properties, - .num_properties =ARRAY_SIZE (bq24190_battery_properties), - .get_property = bq24190_battery_get_property, - .set_property = bq24190_battery_set_property, - .property_is_writeable = bq24190_battery_property_is_writeable, -}; -static void bq24190_check_status (struct bq24190_dev_info *bdi) { -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 ; -bool alert_charger = false, alert_battery = false; +bool alert_charger = false;u8 ss_reg =0 , f_reg =0 ;int i, ret;
@@ -1202,12 +944,9 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) !!(f_reg & BQ24190_REG_F_NTC_FAULT_MASK));mutex_lock (&bdi->f_reg_lock); -if ((bdi->f_reg & battery_mask_f) != (f_reg & battery_mask_f)) - alert_battery = true; -if ((bdi->f_reg & ~battery_mask_f) != (f_reg & ~battery_mask_f)) - alert_charger = true; bdi->f_reg = f_reg;mutex_unlock (&bdi->f_reg_lock); + alert_charger = true; }if (ss_reg != bdi->ss_reg) {
@@ -1226,17 +965,12 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) ret); } -if ((bdi->ss_reg & battery_mask_ss) != (ss_reg & battery_mask_ss)) - alert_battery = true; -if ((bdi->ss_reg & ~battery_mask_ss) != (ss_reg & ~battery_mask_ss)) - alert_charger = true; bdi->ss_reg = ss_reg; + alert_charger = true; }if (alert_charger)power_supply_changed (bdi->charger); -if (alert_battery) -power_supply_changed (bdi->battery);dev_dbg (bdi->dev,"ss_reg: 0x%02x, f_reg: 0x%02x\n" , ss_reg, f_reg); }
@@ -1363,7 +1097,7 @@ static int bq24190_probe(struct i2c_client *client, {struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent);struct device *dev = &client->dev; -struct power_supply_config charger_cfg = {}, battery_cfg = {}; +struct power_supply_config charger_cfg = {};struct bq24190_dev_info *bdi;const char *name;int ret;
@@ -1427,19 +1161,10 @@ static int bq24190_probe(struct i2c_client *client, goto pm_runtime_disable; } - battery_cfg.drv_data = bdi; - bdi->battery =power_supply_register (dev, &bq24190_battery_desc, - &battery_cfg); -if (IS_ERR (bdi->battery)) { -dev_err (dev,"Can't register battery\n" ); - ret =PTR_ERR (bdi->battery); - goto unregister_charger; - } - ret =bq24190_sysfs_create_group (bdi);if (ret) {dev_err (dev,"Can't create sysfs entries\n" ); - goto unregister_battery; + goto unregister_charger; } bdi->initialized = true;
@@ -1475,9 +1200,6 @@ static int bq24190_probe(struct i2c_client *client, remove_sysfs_group:bq24190_sysfs_remove_group (bdi); -unregister_battery: -power_supply_unregister (bdi->battery); - unregister_charger:power_supply_unregister (bdi->charger);
@@ -1500,7 +1222,6 @@ static int bq24190_remove(struct i2c_client *client) }bq24190_sysfs_remove_group (bdi); -power_supply_unregister (bdi->battery);power_supply_unregister (bdi->charger);if (error >=0 )pm_runtime_put_sync (bdi->dev);
@@ -1568,7 +1289,6 @@ static __maybe_unused int bq24190_pm_resume(struct device *dev)/* Things may have changed while suspended so alert upper layer */ power_supply_changed (bdi->charger); -power_supply_changed (bdi->battery);return 0 ; }
Signature · 1 line
2.9.3
Re: [PATCH v2 7/7] power: supply: bq24190_charger: Remove battery power_supply device
Quoted 10 lines · Hans de Goede
The TI bq24190 chip is purely a charger chip, as such it has very little battery info to export to userspace and in practice it is almost always used together with a separate fuel-gauge chip which does have interesting info to export.
Since the userspace ABI requires there to be only 1
power_supplydevice registered per physical battery, the limited batterypower_supplydevice thebq24190_chargerdriver is registering is actually getting in the way of a fuel-gauge driver exporting more useful info, therefor this commit removes the batterypower_supplydevice.
As discussed on the thread for my bq24190 patchset, this is not what's required.
I have a specific plan to move -battery properties to -charger, which I will post when I get a chance.
Meanwhile...
Quoted 263 lines
Cc Liam Breck <[email protected]>Cc Tony Lindgren <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-2-This is a new patch in v2 of this patch-set --- drivers/power/supply/bq24190_charger.c | 290 +-------------------------------- 1 file changed, 5 insertions(+), 285 deletions(-)drivers/power/supply/bq24190_charger.c +0
-238@@ -151,7 +151,6 @@ struct bq24190_dev_info {struct i2c_client *client;struct device *dev;struct power_supply *charger; -struct power_supply *battery;struct extcon_dev *extcon;struct notifier_block extcon_nb;struct delayed_work extcon_work;@@ -910,266 +909,9 @@ static const struct power_supply_desc bq24190_charger_desc = { .property_is_writeable = bq24190_charger_property_is_writeable, }; -/* Battery power supply property routines */ - -static int bq24190_battery_get_status (struct bq24190_dev_info *bdi, -union power_supply_propval *val) -{ -u8 ss_reg, chrg_fault; -int status, ret; - -mutex_lock (&bdi->f_reg_lock); - chrg_fault = bdi->f_reg; -mutex_unlock (&bdi->f_reg_lock); - - chrg_fault &=BQ24190_REG_F_CHRG_FAULT_MASK ; - chrg_fault >>=BQ24190_REG_F_CHRG_FAULT_SHIFT ; - - ret =bq24190_read (bdi,BQ24190_REG_SS , &ss_reg); -if (ret <0 ) -return ret; - -/* -* The battery must be discharging when any of these are true: -* - there is no good power source; -* - there is a charge fault. -* Could also be discharging when in "supplement mode" but -* there is no way to tell when its in that mode. -*/ -if (!(ss_reg &BQ24190_REG_SS_PG_STAT_MASK ) || chrg_fault) { - status =POWER_SUPPLY_STATUS_DISCHARGING ; - }else { - ss_reg &=BQ24190_REG_SS_CHRG_STAT_MASK ; - ss_reg >>=BQ24190_REG_SS_CHRG_STAT_SHIFT ; - -switch (ss_reg) { -case 0x0 :/* Not Charging */ - status =POWER_SUPPLY_STATUS_NOT_CHARGING ; -break ; -case 0x1 :/* Pre-charge */ -case 0x2 :/* Fast Charging */ - status =POWER_SUPPLY_STATUS_CHARGING ; -break ; -case 0x3 :/* Charge Termination Done */ - status =POWER_SUPPLY_STATUS_FULL ; -break ; -default : - ret = -EIO ; - } - } - -if (!ret) - val->intval = status; - -return ret; -} - -static int bq24190_battery_get_health (struct bq24190_dev_info *bdi, -union power_supply_propval *val) -{ -u8 v; -int health; - -mutex_lock (&bdi->f_reg_lock); - v = bdi->f_reg; -mutex_unlock (&bdi->f_reg_lock); - -if (v &BQ24190_REG_F_BAT_FAULT_MASK ) { - health =POWER_SUPPLY_HEALTH_OVERVOLTAGE ; - }else { - v &=BQ24190_REG_F_NTC_FAULT_MASK ; - v >>=BQ24190_REG_F_NTC_FAULT_SHIFT ; - -switch (v) { -case 0x0 :/* Normal */ - health =POWER_SUPPLY_HEALTH_GOOD ; -break ; -case 0x1 :/* TS1 Cold */ -case 0x3 :/* TS2 Cold */ -case 0x5 :/* Both Cold */ - health =POWER_SUPPLY_HEALTH_COLD ; -break ; -case 0x2 :/* TS1 Hot */ -case 0x4 :/* TS2 Hot */ -case 0x6 :/* Both Hot */ - health =POWER_SUPPLY_HEALTH_OVERHEAT ; -break ; -default : - health =POWER_SUPPLY_HEALTH_UNKNOWN ; - } - } - - val->intval = health; -return 0 ; -} - -static int bq24190_battery_get_online (struct bq24190_dev_info *bdi, -union power_supply_propval *val) -{ -u8 batfet_disable; -int ret; - - ret =bq24190_read_mask (bdi,BQ24190_REG_MOC , -BQ24190_REG_MOC_BATFET_DISABLE_MASK , -BQ24190_REG_MOC_BATFET_DISABLE_SHIFT , &batfet_disable); -if (ret <0 ) -return ret; - - val->intval = !batfet_disable; -return 0 ; -} - -static int bq24190_battery_set_online (struct bq24190_dev_info *bdi, -const union power_supply_propval *val) -{ -return bq24190_write_mask (bdi,BQ24190_REG_MOC , -BQ24190_REG_MOC_BATFET_DISABLE_MASK , -BQ24190_REG_MOC_BATFET_DISABLE_SHIFT , !val->intval); -} - -static int bq24190_battery_get_temp_alert_max (struct bq24190_dev_info *bdi, -union power_supply_propval *val) -{ -int temp, ret; - - ret =bq24190_get_field_val (bdi,BQ24190_REG_ICTRC , -BQ24190_REG_ICTRC_TREG_MASK , -BQ24190_REG_ICTRC_TREG_SHIFT , - bq24190_ictrc_treg_values, -ARRAY_SIZE (bq24190_ictrc_treg_values), &temp); -if (ret <0 ) -return ret; - - val->intval = temp; -return 0 ; -} - -static int bq24190_battery_set_temp_alert_max (struct bq24190_dev_info *bdi, -const union power_supply_propval *val) -{ -return bq24190_set_field_val (bdi,BQ24190_REG_ICTRC , -BQ24190_REG_ICTRC_TREG_MASK , -BQ24190_REG_ICTRC_TREG_SHIFT , - bq24190_ictrc_treg_values, -ARRAY_SIZE (bq24190_ictrc_treg_values), val->intval); -} - -static int bq24190_battery_get_property (struct power_supply *psy, -enum power_supply_property psp,union power_supply_propval *val) -{ -struct bq24190_dev_info *bdi =power_supply_get_drvdata (psy); -int ret; - -dev_dbg (bdi->dev,"prop: %d\n" , psp); - - ret =pm_runtime_get_sync (bdi->dev); -if (ret <0 ) -return ret; - -switch (psp) { -case POWER_SUPPLY_PROP_STATUS : - ret =bq24190_battery_get_status (bdi, val); -break ; -case POWER_SUPPLY_PROP_HEALTH : - ret =bq24190_battery_get_health (bdi, val); -break ; -case POWER_SUPPLY_PROP_ONLINE : - ret =bq24190_battery_get_online (bdi, val); -break ; -case POWER_SUPPLY_PROP_TECHNOLOGY : -/* Could be Li-on or Li-polymer but no way to tell which */ - val->intval =POWER_SUPPLY_TECHNOLOGY_UNKNOWN ; - ret =0 ; -break ; -case POWER_SUPPLY_PROP_TEMP_ALERT_MAX : - ret =bq24190_battery_get_temp_alert_max (bdi, val); -break ; -case POWER_SUPPLY_PROP_SCOPE : - val->intval =POWER_SUPPLY_SCOPE_SYSTEM ; - ret =0 ; -break ; -default : - ret = -ENODATA ; - } - -pm_runtime_mark_last_busy (bdi->dev); -pm_runtime_put_autosuspend (bdi->dev); - -return ret; -} - -static int bq24190_battery_set_property (struct power_supply *psy, -enum power_supply_property psp, -const union power_supply_propval *val) -{ -struct bq24190_dev_info *bdi =power_supply_get_drvdata (psy); -int ret; - -dev_dbg (bdi->dev,"prop: %d\n" , psp); - - ret =pm_runtime_get_sync (bdi->dev); -if (ret <0 ) -return ret; - -switch (psp) { -case POWER_SUPPLY_PROP_ONLINE : - ret =bq24190_battery_set_online (bdi, val); -break ; -case POWER_SUPPLY_PROP_TEMP_ALERT_MAX : - ret =bq24190_battery_set_temp_alert_max (bdi, val); -break ; -default : - ret = -EINVAL ; - } - -pm_runtime_mark_last_busy (bdi->dev); -pm_runtime_put_autosuspend (bdi->dev); - -return ret; -} - -static int bq24190_battery_property_is_writeable (struct power_supply *psy, -enum power_supply_property psp) -{ -int ret; - -switch (psp) { -case POWER_SUPPLY_PROP_ONLINE : -case POWER_SUPPLY_PROP_TEMP_ALERT_MAX : - ret =1 ; -break ; -default : - ret =0 ; - } - -return ret; -} - -static enum power_supply_property bq24190_battery_properties[] = { -POWER_SUPPLY_PROP_STATUS ,
drivers/power/supply/bq24190_charger.c static const struct power_supply_desc bq24190_charger_desc = { · line 1159
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +0
-10-POWER_SUPPLY_PROP_HEALTH , -POWER_SUPPLY_PROP_ONLINE , -POWER_SUPPLY_PROP_TECHNOLOGY , -POWER_SUPPLY_PROP_TEMP_ALERT_MAX , - POWER_SUPPLY_PROP_SCOPE, -}; - -static const struct power_supply_desc bq24190_battery_desc = { - .name ="bq24190-battery" , - .type = POWER_SUPPLY_TYPE_BATTERY,
...use _TYPE_UNKNOWN above in your fuel gauge branch so that this sysfs device doesn't conflict with the gauge's _TYPE_BATTERY sysfs device.
Quoted 109 lines
drivers/power/supply/bq24190_charger.c +5
-38- .properties = bq24190_battery_properties, - .num_properties = ARRAY_SIZE(bq24190_battery_properties), - .get_property = bq24190_battery_get_property, - .set_property = bq24190_battery_set_property, - .property_is_writeable = bq24190_battery_property_is_writeable, -}; -static void bq24190_check_status (struct bq24190_dev_info *bdi) { -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 ; -bool alert_charger = false, alert_battery = false; +bool alert_charger = false;u8 ss_reg =0 , f_reg =0 ;int i, ret;@@ -1202,12 +944,9 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) !!(f_reg & BQ24190_REG_F_NTC_FAULT_MASK));mutex_lock (&bdi->f_reg_lock); -if ((bdi->f_reg & battery_mask_f) != (f_reg & battery_mask_f)) - alert_battery = true; -if ((bdi->f_reg & ~battery_mask_f) != (f_reg & ~battery_mask_f)) - alert_charger = true; bdi->f_reg = f_reg;mutex_unlock (&bdi->f_reg_lock); + alert_charger = true; }if (ss_reg != bdi->ss_reg) {@@ -1226,17 +965,12 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi) ret); } -if ((bdi->ss_reg & battery_mask_ss) != (ss_reg & battery_mask_ss)) - alert_battery = true; -if ((bdi->ss_reg & ~battery_mask_ss) != (ss_reg & ~battery_mask_ss)) - alert_charger = true; bdi->ss_reg = ss_reg; + alert_charger = true; }if (alert_charger)power_supply_changed (bdi->charger); -if (alert_battery) -power_supply_changed (bdi->battery);dev_dbg (bdi->dev,"ss_reg: 0x%02x, f_reg: 0x%02x\n" , ss_reg, f_reg); }@@ -1363,7 +1097,7 @@ static int bq24190_probe(struct i2c_client *client, {struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent);struct device *dev = &client->dev; -struct power_supply_config charger_cfg = {}, battery_cfg = {}; +struct power_supply_config charger_cfg = {};struct bq24190_dev_info *bdi;const char *name;int ret;@@ -1427,19 +1161,10 @@ static int bq24190_probe(struct i2c_client *client, goto pm_runtime_disable; } - battery_cfg.drv_data = bdi; - bdi->battery =power_supply_register (dev, &bq24190_battery_desc, - &battery_cfg); -if (IS_ERR (bdi->battery)) { -dev_err (dev,"Can't register battery\n" ); - ret =PTR_ERR (bdi->battery); - goto unregister_charger; - } - ret =bq24190_sysfs_create_group (bdi);if (ret) {dev_err (dev,"Can't create sysfs entries\n" ); - goto unregister_battery; + goto unregister_charger; } bdi->initialized = true;@@ -1475,9 +1200,6 @@ static int bq24190_probe(struct i2c_client *client, remove_sysfs_group:bq24190_sysfs_remove_group (bdi); -unregister_battery: -power_supply_unregister (bdi->battery); - unregister_charger:power_supply_unregister (bdi->charger);@@ -1500,7 +1222,6 @@ static int bq24190_remove(struct i2c_client *client) }bq24190_sysfs_remove_group (bdi); -power_supply_unregister (bdi->battery);power_supply_unregister (bdi->charger);if (error >=0 )pm_runtime_put_sync (bdi->dev);@@ -1568,7 +1289,6 @@ static __maybe_unused int bq24190_pm_resume(struct device *dev)/* Things may have changed while suspended so alert upper layer */ power_supply_changed (bdi->charger); -power_supply_changed (bdi->battery);return 0 ; } --2.9.3