power: supply: bq27xxx: add bq34z100
Subsystems (4)
v2 cover power: supply: bq27xxx: add bq34z100
Hi,
Changes since v1:
1. Squash patch 3 and 4 - cleanups, as suggested.
Best regards,
Krzysztof
Krzysztof Kozlowski (6):
dt-bindings: power: bq27xxx: add bq34z100
power: supply: bq27xxx: report "not charging" on all types
power: supply: bq27xxx: adjust whitespace and use BIT() for bitflags
power: supply: bq27xxx: add separate flag for single SoC register
power: supply: bq27xxx: add separate flag for capacity inaccurate
power: supply: bq27xxx: add support for TI bq34z100
.../bindings/power/supply/bq27xxx.yaml | 1 + drivers/power/supply/bq27xxx_battery.c | 83 +++++++++++++++---- drivers/power/supply/bq27xxx_battery_i2c.c | 2 + include/linux/power/bq27xxx_battery.h | 1 + 4 files changed, 72 insertions(+), 15 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/6 dt-bindings: power: bq27xxx: add bq34z100
Add compatible for bq34z100 charger.
--- Documentation/devicetree/bindings/power/supply/bq27xxx.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/power/supply/bq27xxx.yaml +1 -0
@@ -51,6 +51,7 @@ properties: - ti,bq27621 - ti,bq27z561 - ti,bq28z610 + - ti,bq34z100 reg: maxItems: 1
Signature · 1 line
2.17.1
PATCH v2 2/6 power: supply: bq27xxx: report "not charging" on all types
In reply to Krzysztof KozlowskiCommit 6f24ff97e323 ("power: supply: bq27xxx_battery: Add the BQ27Z561 Battery monitor") and commit d74534c27775 ("power:bq27xxx_battery: Add support for additional bq27xxx family devices") added support for new device types by copying most of the code and adding necessary quirks.
However they did not copy the code in bq27xxx_battery_status() responsible for returning POWER_SUPPLY_STATUS_NOT_CHARGING.
Unify the bq27xxx_battery_status() so for all types when charger is supplied, it will return "not charging" status.
---
Not tested on BQ27Z561 or other types of batteries. Tested however on bq34z100.
--- drivers/power/supply/bq27xxx_battery.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/power/supply/bq27xxx_battery.c +4 -2
@@ -1765,8 +1765,6 @@ static int bq27xxx_battery_status(struct bq27xxx_device_info *di, status =POWER_SUPPLY_STATUS_FULL ; else if (di->cache.flags & BQ27000_FLAG_CHGS) status =POWER_SUPPLY_STATUS_CHARGING ; - else if (power_supply_am_i_supplied(di->bat) > 0) - status =POWER_SUPPLY_STATUS_NOT_CHARGING ; else status =POWER_SUPPLY_STATUS_DISCHARGING ; }else if (di->opts &BQ27Z561_O_BITS ) {
@@ -1785,6 +1783,10 @@ static int bq27xxx_battery_status(struct bq27xxx_device_info *di, status =POWER_SUPPLY_STATUS_CHARGING ; } +if ((status ==POWER_SUPPLY_STATUS_DISCHARGING ) && + (power_supply_am_i_supplied (di->bat) >0 )) + status =POWER_SUPPLY_STATUS_NOT_CHARGING ; + val->intval = status;return 0 ;
Signature · 1 line
2.17.1
PATCH v2 3/6 power: supply: bq27xxx: adjust whitespace and use BIT() for bitflags
In reply to Krzysztof KozlowskiBIT() is a preferred way to toggle bit-like flags: no problems with 32/64 bit systems, less chances for mistakes. Remove also unneeded whitespace.
--- drivers/power/supply/bq27xxx_battery.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/power/supply/bq27xxx_battery.c +9 -8
@@ -76,7 +76,7 @@/* BQ27Z561 has different layout for Flags register */ #define BQ27Z561_FLAG_FDC BIT(4)/* Battery fully discharged */ -#define BQ27Z561_FLAG_FC BIT(5)/* Battery fully charged */ +#define BQ27Z561_FLAG_FC BIT(5)/* Battery fully charged */ #define BQ27Z561_FLAG_DIS_CH BIT(6)/* Battery is discharging */ /* control register params */
@@ -847,13 +847,14 @@ static struct bq27xxx_dm_reg bq27621_dm_regs[] = {#define bq27z561_dm_regs 0#define bq28z610_dm_regs 0 - -#define BQ27XXX_O_ZERO 0x00000001 -#define BQ27XXX_O_OTDC 0x00000002/* has OTC/OTD overtemperature flags */ -#define BQ27XXX_O_UTOT 0x00000004/* has OT overtemperature flag */ -#define BQ27XXX_O_CFGUP 0x00000008 -#define BQ27XXX_O_RAM 0x00000010 -#define BQ27Z561_O_BITS 0x00000020 +#define bq34z100_dm_regs 0 + +#define BQ27XXX_O_ZERO BIT(0) +#define BQ27XXX_O_OTDC BIT(1)/* has OTC/OTD overtemperature flags */ +#define BQ27XXX_O_UTOT BIT(2)/* has OT overtemperature flag */ +#define BQ27XXX_O_CFGUP BIT(3) +#define BQ27XXX_O_RAM BIT(4) +#define BQ27Z561_O_BITS BIT(5)#define BQ27XXX_DATA (ref, key, opt) { \ .opts = (opt), \
Signature · 1 line
2.17.1
PATCH v2 4/6 power: supply: bq27xxx: add separate flag for single SoC register
In reply to Krzysztof Kozlowskibq27000, bq27010 and upcoming bq34z100 have a single byte SoC register. However except this similarity, bq34z100 is quite different than bq27000/bq27010, so flag BQ27XXX_O_ZERO cannot be reused here. Add a new bit flag describing that SoC is a single byte register.
No functional change for bq27000 and bq27010.
--- drivers/power/supply/bq27xxx_battery.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/power/supply/bq27xxx_battery.c +4 -3
@@ -855,6 +855,7 @@ static struct bq27xxx_dm_reg bq27621_dm_regs[] = {#define BQ27XXX_O_CFGUP BIT(3)#define BQ27XXX_O_RAM BIT(4)#define BQ27Z561_O_BITS BIT(5) +#define BQ27XXX_O_SOC_SI BIT(6)/* SoC is single register */ #define BQ27XXX_DATA (ref, key, opt) { \ .opts = (opt), \
@@ -872,8 +873,8 @@ static struct {enum power_supply_property *props;size_t props_size; } bq27xxx_chip_data[] = { - [BQ27000] = BQ27XXX_DATA(bq27000, 0 , BQ27XXX_O_ZERO), - [BQ27010] = BQ27XXX_DATA(bq27010, 0 , BQ27XXX_O_ZERO), + [BQ27000] = BQ27XXX_DATA(bq27000, 0 , BQ27XXX_O_ZERO | BQ27XXX_O_SOC_SI), + [BQ27010] = BQ27XXX_DATA(bq27010, 0 , BQ27XXX_O_ZERO | BQ27XXX_O_SOC_SI), [BQ2750X] = BQ27XXX_DATA(bq2750x, 0 , BQ27XXX_O_OTDC), [BQ2751X] = BQ27XXX_DATA(bq2751x, 0 , BQ27XXX_O_OTDC), [BQ2752X] = BQ27XXX_DATA(bq2752x, 0 , BQ27XXX_O_OTDC),
@@ -1420,7 +1421,7 @@ static int bq27xxx_battery_read_soc(struct bq27xxx_device_info *di) {int soc; -if (di->opts &BQ27XXX_O_ZERO ) +if (di->opts &BQ27XXX_O_SOC_SI ) soc =bq27xxx_read (di,BQ27XXX_REG_SOC , true);else soc =bq27xxx_read (di,BQ27XXX_REG_SOC , false);
Signature · 1 line
2.17.1
PATCH v2 5/6 power: supply: bq27xxx: add separate flag for capacity inaccurate
In reply to Krzysztof Kozlowskibq27000, bq27010 and upcoming bq34z100 have a Capacity Inaccurate flag. However except this similarity, bq34z100 is quite different than bq27000/bq27010, so flag BQ27XXX_O_ZERO cannot be reused here. Add a new bit flag describing this capability.
No functional change for bq27000 and bq27010.
--- drivers/power/supply/bq27xxx_battery.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/power/supply/bq27xxx_battery.c +4 -3
@@ -856,6 +856,7 @@ static struct bq27xxx_dm_reg bq27621_dm_regs[] = {#define BQ27XXX_O_RAM BIT(4)#define BQ27Z561_O_BITS BIT(5)#define BQ27XXX_O_SOC_SI BIT(6)/* SoC is single register */ +#define BQ27XXX_O_HAS_CI BIT(7)/* has Capacity Inaccurate flag */ #define BQ27XXX_DATA (ref, key, opt) { \ .opts = (opt), \
@@ -873,8 +874,8 @@ static struct {enum power_supply_property *props;size_t props_size; } bq27xxx_chip_data[] = { - [BQ27000] = BQ27XXX_DATA(bq27000, 0 , BQ27XXX_O_ZERO | BQ27XXX_O_SOC_SI), - [BQ27010] = BQ27XXX_DATA(bq27010, 0 , BQ27XXX_O_ZERO | BQ27XXX_O_SOC_SI), + [BQ27000] = BQ27XXX_DATA(bq27000, 0 , BQ27XXX_O_ZERO | BQ27XXX_O_SOC_SI | BQ27XXX_O_HAS_CI), + [BQ27010] = BQ27XXX_DATA(bq27010, 0 , BQ27XXX_O_ZERO | BQ27XXX_O_SOC_SI | BQ27XXX_O_HAS_CI), [BQ2750X] = BQ27XXX_DATA(bq2750x, 0 , BQ27XXX_O_OTDC), [BQ2751X] = BQ27XXX_DATA(bq2751x, 0 , BQ27XXX_O_OTDC), [BQ2752X] = BQ27XXX_DATA(bq2752x, 0 , BQ27XXX_O_OTDC),
@@ -1659,7 +1660,7 @@ static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di)void bq27xxx_battery_update (struct bq27xxx_device_info *di) {struct bq27xxx_reg_cache cache = {0 , }; -bool has_ci_flag = di->opts &BQ27XXX_O_ZERO ; +bool has_ci_flag = di->opts &BQ27XXX_O_HAS_CI ;bool has_singe_flag = di->opts &BQ27XXX_O_ZERO ; cache.flags =bq27xxx_read (di,BQ27XXX_REG_FLAGS , has_singe_flag);
Signature · 1 line
2.17.1
PATCH v2 6/6 power: supply: bq27xxx: add support for TI bq34z100
In reply to Krzysztof KozlowskiAdd support for new device: the TI bq34z100-G1, a Wide Range Fuel Gauge for Li-Ion, PbA, NiMH, and NiCd batteries. The device shares a lot with other models, although it has its own differences requiring new quirks.
This patch was tested on a system equipped with NiMH batteries.
--- drivers/power/supply/bq27xxx_battery.c | 50 +++++++++++++++++++++- drivers/power/supply/bq27xxx_battery_i2c.c | 2 + include/linux/power/bq27xxx_battery.h | 1 + 3 files changed, 52 insertions(+), 1 deletion(-)
drivers/power/supply/bq27xxx_battery.c +49 -1
@@ -38,6 +38,7 @@* https://www.ti.com/product/bq27621-g1 * https://www.ti.com/product/bq27z561 * https://www.ti.com/product/bq28z610 +* https://www.ti.com/product/bq34z100-g1 */ #include <linux/device.h>
@@ -476,6 +477,26 @@ static u8 [BQ27XXX_REG_DCAP] = 0x3c, [BQ27XXX_REG_AP ] =0x22 ,BQ27XXX_DM_REG_ROWS , + }, + bq34z100_regs[BQ27XXX_REG_MAX ] = { + [BQ27XXX_REG_CTRL ] =0x00 , + [BQ27XXX_REG_TEMP ] =0x0c , + [BQ27XXX_REG_INT_TEMP ] =0x2a , + [BQ27XXX_REG_VOLT ] =0x08 , + [BQ27XXX_REG_AI ] =0x0a , + [BQ27XXX_REG_FLAGS ] =0x0e , + [BQ27XXX_REG_TTE ] =0x18 , + [BQ27XXX_REG_TTF ] =0x1a , + [BQ27XXX_REG_TTES ] =0x1e , + [BQ27XXX_REG_TTECP ] =INVALID_REG_ADDR , + [BQ27XXX_REG_NAC ] =INVALID_REG_ADDR , + [BQ27XXX_REG_FCC ] =0x06 , + [BQ27XXX_REG_CYCT ] =0x2c , + [BQ27XXX_REG_AE ] =0x24 , + [BQ27XXX_REG_SOC ] =0x02 , + [BQ27XXX_REG_DCAP ] =0x3c , + [BQ27XXX_REG_AP ] =0x22 , +BQ27XXX_DM_REG_ROWS , };static enum power_supply_property bq27000_props[] = {
@@ -750,6 +771,27 @@ static enum power_supply_property bq28z610_props[] = { POWER_SUPPLY_PROP_MANUFACTURER, }; +static enum power_supply_property bq34z100_props[] = { +POWER_SUPPLY_PROP_STATUS , +POWER_SUPPLY_PROP_PRESENT , +POWER_SUPPLY_PROP_VOLTAGE_NOW , +POWER_SUPPLY_PROP_CURRENT_NOW , +POWER_SUPPLY_PROP_CAPACITY , +POWER_SUPPLY_PROP_CAPACITY_LEVEL , +POWER_SUPPLY_PROP_TEMP , +POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW , +POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG , +POWER_SUPPLY_PROP_TIME_TO_FULL_NOW , +POWER_SUPPLY_PROP_TECHNOLOGY , +POWER_SUPPLY_PROP_CHARGE_FULL , +POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN , +POWER_SUPPLY_PROP_CYCLE_COUNT , +POWER_SUPPLY_PROP_ENERGY_NOW , +POWER_SUPPLY_PROP_POWER_AVG , +POWER_SUPPLY_PROP_HEALTH , +POWER_SUPPLY_PROP_MANUFACTURER , +}; +struct bq27xxx_dm_reg {u8 subclass_id;u8 offset;
@@ -857,6 +899,7 @@ static struct bq27xxx_dm_reg bq27621_dm_regs[] = {#define BQ27Z561_O_BITS BIT(5)#define BQ27XXX_O_SOC_SI BIT(6)/* SoC is single register */ #define BQ27XXX_O_HAS_CI BIT(7)/* has Capacity Inaccurate flag */ +#define BQ27XXX_O_MUL_CHEM BIT(8)/* multiple chemistries supported */ #define BQ27XXX_DATA (ref, key, opt) { \ .opts = (opt), \
@@ -903,6 +946,8 @@ static struct { [BQ27621] = BQ27XXX_DATA(bq27621, 0x80008000, BQ27XXX_O_UTOT | BQ27XXX_O_CFGUP | BQ27XXX_O_RAM), [BQ27Z561] = BQ27XXX_DATA(bq27z561, 0 , BQ27Z561_O_BITS), [BQ28Z610] = BQ27XXX_DATA(bq28z610, 0 , BQ27Z561_O_BITS), + [BQ34Z100 ] =BQ27XXX_DATA (bq34z100,0 ,BQ27XXX_O_OTDC |BQ27XXX_O_SOC_SI | \ + BQ27XXX_O_HAS_CI | BQ27XXX_O_MUL_CHEM), };static DEFINE_MUTEX (bq27xxx_list_lock);
@@ -1914,7 +1959,10 @@ static int bq27xxx_battery_get_property(struct power_supply *psy, ret =bq27xxx_simple_value (di->cache.time_to_full, val);break ;case POWER_SUPPLY_PROP_TECHNOLOGY : - val->intval =POWER_SUPPLY_TECHNOLOGY_LION ; +if (di->opts &BQ27XXX_O_MUL_CHEM ) + val->intval =POWER_SUPPLY_TECHNOLOGY_UNKNOWN ; +else + val->intval =POWER_SUPPLY_TECHNOLOGY_LION ;break ;case POWER_SUPPLY_PROP_CHARGE_NOW : ret =bq27xxx_simple_value (bq27xxx_battery_read_nac (di), val);
drivers/power/supply/bq27xxx_battery_i2c.c +2 -0
@@ -247,6 +247,7 @@ static const struct i2c_device_id bq27xxx_i2c_id_table[] = { { "bq27621", BQ27621 }, { "bq27z561", BQ27Z561 }, { "bq28z610", BQ28Z610 }, + { "bq34z100", BQ34Z100 }, {}, };MODULE_DEVICE_TABLE (i2c, bq27xxx_i2c_id_table);
@@ -282,6 +283,7 @@ static const struct of_device_id bq27xxx_battery_i2c_of_match_table[] = { { .compatible = "ti,bq27621" }, { .compatible = "ti,bq27z561" }, { .compatible = "ti,bq28z610" }, + { .compatible = "ti,bq34z100" }, {}, };MODULE_DEVICE_TABLE (of, bq27xxx_battery_i2c_of_match_table);
include/linux/power/bq27xxx_battery.h +1 -0
@@ -32,6 +32,7 @@ enum bq27xxx_chip {BQ27621 ,BQ27Z561 ,BQ28Z610 , + BQ34Z100, };struct bq27xxx_device_info ;
Signature · 1 line
2.17.1
Sebastian Reichel
maintainerHi,
Quoted 14 lines · Krzysztof Kozlowski
Changes since v1:
1. Squash patch 3 and 4 - cleanups, as suggested.Best regards,
KrzysztofKrzysztof Kozlowski (6):
dt-bindings: power: bq27xxx: add bq34z100
power: supply: bq27xxx: report "not charging" on all types
power: supply: bq27xxx: adjust whitespace and useBIT()for bitflags
power: supply: bq27xxx: add separate flag for single SoC register
power: supply: bq27xxx: add separate flag for capacity inaccurate
power: supply: bq27xxx: add support for TI bq34z100
Quoted 5 lines
.../bindings/power/supply/bq27xxx.yaml | 1 + drivers/power/supply/bq27xxx_battery.c | 83 +++++++++++++++---- drivers/power/supply/bq27xxx_battery_i2c.c | 2 + include/linux/power/bq27xxx_battery.h | 1 + 4 files changed, 72 insertions(+), 15 deletions(-)
Thanks, queued.
-- Sebastian