power: bq27xxx: add support for NVRAM R/W access
Subsystems (4)
v3 cover power: bq27xxx: add support for NVRAM R/W access
Enable access to the NVRAM for the bq27425 chipset which allows to update the battery metrics that are used in the state machine.
This allows adjustments of a termination voltage, design energy, and design voltage.
Changes from v1:
* add documentation for mWh and mAh property units
* change devicetree entries to match new property units
Changes from v2:
* split i2c changes into respective patches
* add documentation for battery information for fuel gauge
* rebased documentation patches on change on the list
* abstracted the battery configuration for the state machine to an generic struct and platform data access function
Matt Ranostay (7):
devicetree: power: add battery state machine documentation
power: power_supply: add battery information struct
power: power_supply: add battery info platform data retrieval
power: bq27xxx_battery: add BQ27425 chip id
power: bq27xxx_battery: add i2c bulk read/write functions
devicetree: power: bq27xxx: add monitored battery documentation
power: bq27xxx_battery: add initial state machine support
.../devicetree/bindings/power/supply/battery.txt | 20 ++ .../devicetree/bindings/power/supply/bq27xxx.txt | 8 + drivers/power/supply/bq27xxx_battery.c | 253 ++++++++++++++++++++- drivers/power/supply/bq27xxx_battery_i2c.c | 64 +++++- drivers/power/supply/power_supply_core.c | 31 +++ include/linux/power/bq27xxx_battery.h | 7 +- include/linux/power_supply.h | 16 ++ 7 files changed, 395 insertions(+), 4 deletions(-) create mode 100644 Documentation/devicetree/bindings/power/supply/battery.txt
Signature · 1 line
2.10.2
A message that is not in the archive (sent off-list or not yet received): 20170111062003.10110-1-matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org
PATCH v3 1/7 devicetree: power: add battery state machine documentation
Documentation on battery properties that can be defined for fine tuning fuel gauge state machines.
--- .../devicetree/bindings/power/supply/battery.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/battery.txt
Documentation/devicetree/bindings/power/supply/battery.txt new file +20 -0
@@ -0,0 +1,20 @@ +Battery State Machine Support + +Optional Properties + - nominal-microvolt: dead battery voltage in microvolts + - design-microwatt-hours: battery design mWh in microwatts + - design-microamp-hours: battery design mAh in microamps + +Example: + + bat: battery@0 { + nominal-microvolt = <3700000>; + design-microwatt-hours = <5290000>; + design-microamp-hours = <1430000>; + }; + + charger: charger@0 { + .... + monitored-battery = <&bat>; + ... + };
Signature · 6 lines
2.10.2 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20170111062003.10110-2-matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org
Re: [PATCH v3 1/7] devicetree: power: add battery state machine documentation
Quoted 16 lines · Matt Ranostay
Documentation on battery properties that can be defined for fine tuning fuel gauge state machines.
Cc Rob Herring <[email protected]>Signed-off-by Matt Ranostay <[email protected]>--- .../devicetree/bindings/power/supply/battery.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/battery.txtDocumentation/devicetree/bindings/power/supply/battery.txt new file +0
-0
Documentation/devicetree/bindings/power/supply/battery.txt line 5
Quoted 5 lines
Documentation/devicetree/bindings/power/supply/battery.txt new file +5
-0@@ -0,0 +1,20 @@ +Battery State Machine Support + +Optional Properties + - nominal-microvolt: dead battery voltage in microvolts + - design-microwatt-hours: battery design mWh in microwatts
mWh in microwatts?
mWh would be milliwatt-hours.
Documentation/devicetree/bindings/power/supply/battery.txt line 6
Quoted 1 line
Documentation/devicetree/bindings/power/supply/battery.txt new file +1
-0+ - design-microamp-hours: battery design mAh in microamps
ditto
Documentation/devicetree/bindings/power/supply/battery.txt line 10
Quoted 4 lines
Documentation/devicetree/bindings/power/supply/battery.txt new file +4
-0+ +Example: + + bat: battery@0 {
No reg prop, so no unit-address.
Quoted 13 lines
Documentation/devicetree/bindings/power/supply/battery.txt new file +10
-0+ nominal-microvolt = <3700000>; + design-microwatt-hours = <5290000>; + design-microamp-hours = <1430000>; + }; + + charger: charger@0 { + .... + monitored-battery = <&bat>; + ... + };Signature · 1 line
2.10.2
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Sebastian Reichel
maintainerRe: [PATCH v3 1/7] devicetree: power: add battery state machine documentation
In reply to Matt RanostayHi,
Quoted 16 lines · Matt Ranostay
Documentation on battery properties that can be defined for fine tuning fuel gauge state machines.
Cc Rob Herring <[email protected]>Signed-off-by Matt Ranostay <[email protected]>--- .../devicetree/bindings/power/supply/battery.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/battery.txtDocumentation/devicetree/bindings/power/supply/battery.txt new file +0
-0
Documentation/devicetree/bindings/power/supply/battery.txt line 1
Quoted 1 line
Documentation/devicetree/bindings/power/supply/battery.txt new file +1
-0@@ -0,0 +1,20 @@ +Battery State Machine Support
Let's also add a mandatory compatible string. This binding is only relevant for dumb batteries, since other ones can self-identify. I suggest
compatible = "fixed-battery"
Documentation/devicetree/bindings/power/supply/battery.txt line 6
Quoted 4 lines
Documentation/devicetree/bindings/power/supply/battery.txt new file +4
-0+Optional Properties + - nominal-microvolt: dead battery voltage in microvolts + - design-microwatt-hours: battery design mWh in microwatts + - design-microamp-hours: battery design mAh in microamps
I think we should mandate the property name of the phandle in the generic binding instead of each potential fuel-gauge/charger. Maybe something like the following paragraph:
Batteries are supposed to be referenced by chargers and/or fuel-gauges using a phandle. The phandle's property should be named "monitored-battery".
Documentation/devicetree/bindings/power/supply/battery.txt line 20
Quoted 13 lines
Documentation/devicetree/bindings/power/supply/battery.txt new file +13
-0+Example: + + bat: battery@0 { + nominal-microvolt = <3700000>; + design-microwatt-hours = <5290000>; + design-microamp-hours = <1430000>; + }; + + charger: charger@0 { + ... + monitored-battery = <&bat>; + ... + };
Let's also add a fuel-gauge to the example to avoid any confusion between fuel-gauge and battery.
fuel_gauge: fuel-gauge {
...
monitored-battery = <&bat>;
...
};-- Sebastian
PATCH v3 4/7 power: bq27xxx_battery: add BQ27425 chip id
In reply to a message not in the archive--- drivers/power/supply/bq27xxx_battery.c | 23 ++++++++++++++++++++++- drivers/power/supply/bq27xxx_battery_i2c.c | 2 +- include/linux/power/bq27xxx_battery.h | 3 ++- 3 files changed, 25 insertions(+), 3 deletions(-)
drivers/power/supply/bq27xxx_battery.c +22 -1
@@ -259,6 +259,25 @@ static u8 bq27xxx_regs[][BQ27XXX_REG_MAX] = { [BQ27XXX_REG_DCAP] = 0x3c, [BQ27XXX_REG_AP] = 0x18, }, + [BQ27425] = { + [BQ27XXX_REG_CTRL] = 0x00, + [BQ27XXX_REG_TEMP] = 0x02, + [BQ27XXX_REG_INT_TEMP] = 0x1e, + [BQ27XXX_REG_VOLT] = 0x04, + [BQ27XXX_REG_AI] = 0x10, + [BQ27XXX_REG_FLAGS] = 0x06, + [BQ27XXX_REG_TTE] = INVALID_REG_ADDR, + [BQ27XXX_REG_TTF] = INVALID_REG_ADDR, + [BQ27XXX_REG_TTES] = INVALID_REG_ADDR, + [BQ27XXX_REG_TTECP] = INVALID_REG_ADDR, + [BQ27XXX_REG_NAC] = 0x08, + [BQ27XXX_REG_FCC] = 0x0e, + [BQ27XXX_REG_CYCT] = INVALID_REG_ADDR, + [BQ27XXX_REG_AE] = INVALID_REG_ADDR, + [BQ27XXX_REG_SOC] = 0x1c, + [BQ27XXX_REG_DCAP] = 0x3c, + [BQ27XXX_REG_AP] = 0x18, + }, };static enum power_supply_property bq27000_battery_props[] = {
@@ -427,6 +446,7 @@ static struct {BQ27XXX_PROP (BQ27541 , bq27541_battery_props),BQ27XXX_PROP (BQ27545 , bq27545_battery_props),BQ27XXX_PROP (BQ27421 , bq27421_battery_props), + BQ27XXX_PROP(BQ27425, bq27421_battery_props), };static DEFINE_MUTEX (bq27xxx_list_lock);
@@ -682,6 +702,7 @@ static bool bq27xxx_battery_overtemp(struct bq27xxx_device_info *di, u16 flags)return flags & (BQ27XXX_FLAG_OTC |BQ27XXX_FLAG_OTD );case BQ27530 :case BQ27421 : +case BQ27425 :return flags &BQ27XXX_FLAG_OT ;default :return false;
@@ -693,7 +714,7 @@ static bool bq27xxx_battery_overtemp(struct bq27xxx_device_info *di, u16 flags)*/ static bool bq27xxx_battery_undertemp (struct bq27xxx_device_info *di,u16 flags) { -if (di->chip ==BQ27530 || di->chip ==BQ27421 ) +if (di->chip ==BQ27530 || di->chip ==BQ27421 || di->chip ==BQ27425 )return flags &BQ27XXX_FLAG_UT ;return false;
drivers/power/supply/bq27xxx_battery_i2c.c +1 -1
@@ -159,9 +159,9 @@ static const struct i2c_device_id bq27xxx_i2c_id_table[] = { { "bq27742", BQ27541 }, { "bq27545", BQ27545 }, { "bq27421", BQ27421 }, - { "bq27425", BQ27421 }, { "bq27441", BQ27421 }, { "bq27621", BQ27421 }, + { "bq27425", BQ27425 }, {}, };MODULE_DEVICE_TABLE (i2c, bq27xxx_i2c_id_table);
include/linux/power/bq27xxx_battery.h +2 -1
@@ -9,7 +9,8 @@ enum bq27xxx_chip {BQ27530 ,/* bq27530, bq27531 */ BQ27541 ,/* bq27541, bq27542, bq27546, bq27742 */ BQ27545 ,/* bq27545 */ - BQ27421, /* bq27421, bq27425, bq27441, bq27621 */ +BQ27421 ,/* bq27421, bq27441, bq27621 */ + BQ27425, /* bq27425 */ };/**
Signature · 6 lines
2.10.2 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 5/7 power: bq27xxx_battery: add i2c bulk read/write functions
In reply to a message not in the archive--- drivers/power/supply/bq27xxx_battery_i2c.c | 62 ++++++++++++++++++++++++++++++ include/linux/power/bq27xxx_battery.h | 4 ++ 2 files changed, 66 insertions(+)
drivers/power/supply/bq27xxx_battery_i2c.c +62 -0
@@ -68,6 +68,64 @@ static int bq27xxx_battery_i2c_read(struct bq27xxx_device_info *di, u8 reg,return ret; } +static int bq27xxx_battery_i2c_write (struct bq27xxx_device_info *di,u8 reg, +int value,bool single) +{ +struct i2c_client *client =to_i2c_client (di->dev); +struct i2c_msg msg; +unsigned char data[4 ]; + +if (!client->adapter) +return -ENODEV ; + + data[0 ] = reg; +if (single) { + data[1 ] = (unsigned char ) value; + msg.len =2 ; + }else { +put_unaligned_le16 (value, &data[1 ]); + msg.len =3 ; + } + + msg.buf = data; + msg.addr = client->addr; + msg.flags =0 ; + +return i2c_transfer (client->adapter, &msg,1 ) ==1 ?0 : -EINVAL ; +} + +static int bq27xxx_battery_i2c_bulk_read (struct bq27xxx_device_info *di,u8 reg, +u8 *data,int len) +{ +struct i2c_client *client =to_i2c_client (di->dev); + +if (!client->adapter) +return -ENODEV ; + +return i2c_smbus_read_i2c_block_data (client, reg, len, data); +} + +static int bq27xxx_battery_i2c_bulk_write (struct bq27xxx_device_info *di, +u8 reg,u8 *data,int len) +{ +struct i2c_client *client =to_i2c_client (di->dev); +struct i2c_msg msg; +u8 buf[33 ]; + +if (!client->adapter) +return -ENODEV ; + + buf[0 ] = reg; +memcpy (&buf[1 ], data, len); + + msg.buf = buf; + msg.addr = client->addr; + msg.flags =0 ; + msg.len = len +1 ; + +return i2c_transfer (client->adapter, &msg,1 ) ==1 ?0 : -EINVAL ; +} +static int bq27xxx_battery_i2c_probe (struct i2c_client *client,const struct i2c_device_id *id) {
@@ -95,7 +153,11 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client, di->dev = &client->dev; di->chip = id->driver_data; di->name = name; + di->bus.read = bq27xxx_battery_i2c_read; + di->bus.write = bq27xxx_battery_i2c_write; + di->bus.read_bulk = bq27xxx_battery_i2c_bulk_read; + di->bus.write_bulk = bq27xxx_battery_i2c_bulk_write; ret =bq27xxx_battery_setup (di);if (ret)
include/linux/power/bq27xxx_battery.h +4 -0
@@ -33,6 +33,9 @@ struct bq27xxx_platform_data {struct bq27xxx_device_info ;struct bq27xxx_access_methods {int (*read)(struct bq27xxx_device_info *di,u8 reg,bool single); +int (*write)(struct bq27xxx_device_info *di,u8 reg,int value,bool single); +int (*read_bulk)(struct bq27xxx_device_info *di,u8 reg,u8 *data,int len); +int (*write_bulk)(struct bq27xxx_device_info *di,u8 reg,u8 *data,int len); };struct bq27xxx_reg_cache {
@@ -63,6 +66,7 @@ struct bq27xxx_device_info {struct list_head list;struct mutex lock;u8 *regs; +u8 buffer[32 ]; };void bq27xxx_battery_update (struct bq27xxx_device_info *di);
Signature · 6 lines
2.10.2 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 7/7 power: bq27xxx_battery: add initial state machine support
In reply to a message not in the archive--- drivers/power/supply/bq27xxx_battery.c | 230 ++++++++++++++++++++++++++++++++- 1 file changed, 229 insertions(+), 1 deletion(-)
drivers/power/supply/bq27xxx_battery.c +229 -1
@@ -37,6 +37,7 @@* http://www.ti.com/product/bq27621-g1 */ +#include <linux/delay.h> #include <linux/device.h> #include <linux/module.h> #include <linux/mutex.h>
@@ -452,6 +453,46 @@ static struct {static DEFINE_MUTEX (bq27xxx_list_lock);static LIST_HEAD (bq27xxx_battery_devices); +#define BQ27XXX_TERM_V_MIN 2800 +#define BQ27XXX_TERM_V_MAX 3700 + +#define BQ27XXX_BLOCK_DATA_CLASS 0x3E +#define BQ27XXX_DATA_BLOCK 0x3F +#define BQ27XXX_BLOCK_DATA 0x40 +#define BQ27XXX_BLOCK_DATA_CHECKSUM 0x60 +#define BQ27XXX_BLOCK_DATA_CONTROL 0x61 +#define BQ27XXX_SET_CFGUPDATE 0x13 +#define BQ27XXX_SOFT_RESET 0x42 + +enum bq27xxx_dm_subclass_index { +BQ27XXX_DM_DESIGN_CAP =0 , +BQ27XXX_DM_DESIGN_ENERGY , +BQ27XXX_DM_TERMINATE_VOLTAGE , +BQ27XXX_NUM_IDX , +}; + +struct bq27xxx_dm_regs { +unsigned int subclass_id; +unsigned int offset; +char *name; +}; + +#define BQ27XXX_GAS_GAUGING_STATE_SUBCLASS 82 + +static struct bq27xxx_dm_regs bq27425_dm_subclass_regs[] = { + {BQ27XXX_GAS_GAUGING_STATE_SUBCLASS ,12 ,"design-capacity" }, + {BQ27XXX_GAS_GAUGING_STATE_SUBCLASS ,14 ,"design-energy" }, + {BQ27XXX_GAS_GAUGING_STATE_SUBCLASS ,18 ,"terminate-voltage" }, +}; + +static struct bq27xxx_dm_regs *bq27xxx_dm_subclass_regs[] = { + [BQ27425 ] = bq27425_dm_subclass_regs, +}; + +static unsigned int bq27xxx_unseal_keys[] = { + [BQ27425 ] =0x04143672 , +}; +static int poll_interval_param_set (const char *val,const struct kernel_param *kp) {struct bq27xxx_device_info *di;
@@ -496,6 +537,165 @@ static inline int bq27xxx_read(struct bq27xxx_device_info *di, int reg_index,return di->bus.read (di, di->regs[reg_index], single); } +static int bq27xxx_battery_set_seal_state (struct bq27xxx_device_info *di, +bool state) +{ +unsigned int key = bq27xxx_unseal_keys[di->chip]; +int ret; + +if (state) +return di->bus.write (di,BQ27XXX_REG_CTRL ,0x20 , false); + + ret = di->bus.write (di,BQ27XXX_REG_CTRL , (key >>16 ) &0xffff , false); +if (ret <0 ) +return ret; + +return di->bus.write (di,BQ27XXX_REG_CTRL , key &0xffff , false); +} + +static int bq27xxx_battery_read_dm_block (struct bq27xxx_device_info *di, +int subclass) +{ +int ret = di->bus.write (di,BQ27XXX_REG_CTRL ,0 , false); + +if (ret <0 ) +return ret; + + ret = di->bus.write (di,BQ27XXX_BLOCK_DATA_CONTROL ,0 , true); +if (ret <0 ) +return ret; + + ret = di->bus.write (di,BQ27XXX_BLOCK_DATA_CLASS , subclass, true); +if (ret <0 ) +return ret; + + ret = di->bus.write (di,BQ27XXX_DATA_BLOCK ,0 , true); +if (ret <0 ) +return ret; + +usleep_range (1000 ,1500 ); + +return di->bus.read_bulk (di,BQ27XXX_BLOCK_DATA , + (u8 *) &di->buffer,sizeof (di->buffer)); +} + +static int bq27xxx_battery_print_config (struct bq27xxx_device_info *di) +{ +struct bq27xxx_dm_regs *reg = bq27xxx_dm_subclass_regs[di->chip]; +int ret, i; + + ret =bq27xxx_battery_read_dm_block (di, +BQ27XXX_GAS_GAUGING_STATE_SUBCLASS ); +if (ret <0 ) +return ret; + +for (i =0 ; i <BQ27XXX_NUM_IDX ; i++) { +int val; + +if (reg->subclass_id !=BQ27XXX_GAS_GAUGING_STATE_SUBCLASS ) +continue ; + + val =be16_to_cpup ((u16 *) &di->buffer[reg->offset]); + +dev_info (di->dev,"settings for %s set at %d\n" , reg->name, val); + + reg++; + } + +return 0 ; +} + +static bool bq27xxx_battery_update_dm_setting (struct bq27xxx_device_info *di, +unsigned int reg,unsigned int val) +{ +struct bq27xxx_dm_regs *dm_reg = &bq27xxx_dm_subclass_regs[di->chip][reg]; +u16 *prev = (u16 *) &di->buffer[dm_reg->offset]; + +if (be16_to_cpup (prev) == val) +return false; + + *prev =cpu_to_be16 (val); + +return true; +} + +static u8 bq27xxx_battery_checksum (struct bq27xxx_device_info *di) +{ +u8 *data = (u8 *) &di->buffer; +u16 sum =0 ; +int i; + +for (i =0 ; i <sizeof (di->buffer); i++) { + sum += data[i]; + sum &=0xff ; + } + +return 0xff - sum; +} + +static int bq27xxx_battery_write_nvram (struct bq27xxx_device_info *di, +unsigned int subclass) +{ +int ret; + + ret = di->bus.write (di,BQ27XXX_REG_CTRL ,BQ27XXX_SET_CFGUPDATE , false); +if (ret) +return ret; + + ret = di->bus.write (di,BQ27XXX_BLOCK_DATA_CONTROL ,0 , true); +if (ret) +return ret; + + ret = di->bus.write (di,BQ27XXX_BLOCK_DATA_CLASS , subclass, true); +if (ret) +return ret; + + ret = di->bus.write (di,BQ27XXX_DATA_BLOCK ,0 , true); +if (ret) +return ret; + + ret = di->bus.write_bulk (di,BQ27XXX_BLOCK_DATA , + (u8 *) &di->buffer,sizeof (di->buffer)); +if (ret <0 ) +return ret; + +usleep_range (1000 ,1500 ); + + di->bus.write (di,BQ27XXX_BLOCK_DATA_CHECKSUM , +bq27xxx_battery_checksum (di), true); + +usleep_range (1000 ,1500 ); + + di->bus.write (di,BQ27XXX_REG_CTRL ,BQ27XXX_SOFT_RESET , false); + +return 0 ; +} + +static int bq27xxx_battery_set_config (struct bq27xxx_device_info *di, +struct power_supply_battery_info *info) +{ +int ret =bq27xxx_battery_read_dm_block (di, +BQ27XXX_GAS_GAUGING_STATE_SUBCLASS ); + +if (ret <0 ) +return ret; + + ret =bq27xxx_battery_update_dm_setting (di,BQ27XXX_DM_DESIGN_CAP , + info->power /1000 ); + ret |=bq27xxx_battery_update_dm_setting (di,BQ27XXX_DM_DESIGN_ENERGY , + info->energy /1000 ); + ret |=bq27xxx_battery_update_dm_setting (di,BQ27XXX_DM_TERMINATE_VOLTAGE , + info->nominal_voltage /1000 ); + +if (ret) { +dev_info (di->dev,"updating NVM settings\n" ); +return bq27xxx_battery_write_nvram (di, +BQ27XXX_GAS_GAUGING_STATE_SUBCLASS ); + } + +return 0 ; +} +/* * Return the battery State-of-Charge * Or < 0 if something fails.
@@ -757,6 +957,30 @@ static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di)return POWER_SUPPLY_HEALTH_GOOD ; } +void bq27xxx_battery_settings (struct bq27xxx_device_info *di) +{ +struct power_supply_battery_info info = {}; + +/* functions don't exist for writing data so abort */ +if (!di->bus.write || !di->bus.write_bulk) +return ; + +/* no settings to be set for this chipset so abort */ +if (!bq27xxx_dm_subclass_regs[di->chip]) +return ; + +bq27xxx_battery_set_seal_state (di, false); + +if (power_supply_get_battery_info (di->bat, &info,"monitored-battery" ) <0 ) + goto out; + +bq27xxx_battery_set_config (di, &info); + +out: +bq27xxx_battery_print_config (di); +bq27xxx_battery_set_seal_state (di, true); +} +void bq27xxx_battery_update (struct bq27xxx_device_info *di) {struct bq27xxx_reg_cache cache = {0 , };
@@ -1039,7 +1263,10 @@ static void bq27xxx_external_power_changed(struct power_supply *psy)int bq27xxx_battery_setup (struct bq27xxx_device_info *di) {struct power_supply_desc *psy_desc; -struct power_supply_config psy_cfg = { .drv_data = di, }; +struct power_supply_config psy_cfg; + + psy_cfg.of_node = di->dev->of_node; + psy_cfg.drv_data = di;INIT_DELAYED_WORK (&di->work, bq27xxx_battery_poll);mutex_init (&di->lock);
@@ -1064,6 +1291,7 @@ int bq27xxx_battery_setup(struct bq27xxx_device_info *di)dev_info (di->dev,"support ver. %s enabled\n" ,DRIVER_VERSION ); +bq27xxx_battery_settings (di);bq27xxx_battery_update (di);mutex_lock (&bq27xxx_list_lock);
Signature · 6 lines
2.10.2 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 2/7 power: power_supply: add battery information struct
In reply to Matt RanostayAdd power_supply_battery_info structure that is used to enumerate battery state machine settings.
--- include/linux/power_supply.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/linux/power_supply.h +12 -0
@@ -288,6 +288,18 @@ struct power_supply_info {int use_for_apm; }; +/* +* This is the recommended struct to specify static battery parameters. +* Power supply class itself doesn't use this, but it implements access +* that most platform drivers should use for consistency. +*/ + +struct power_supply_battery_info { +int energy;/* uWh */ +int power;/* uAh */ +int nominal_voltage;/* uV */ +}; +extern struct atomic_notifier_head power_supply_notifier;extern int power_supply_reg_notifier (struct notifier_block *nb);extern void power_supply_unreg_notifier (struct notifier_block *nb);
Signature · 1 line
2.10.2
PATCH v3 3/7 power: power_supply: add battery info platform data retrieval
In reply to Matt RanostayAdd power_supply_get_battery_info() to get battery platform data
--- drivers/power/supply/power_supply_core.c | 31 +++++++++++++++++++++++++++++++ include/linux/power_supply.h | 4 ++++ 2 files changed, 35 insertions(+)
drivers/power/supply/power_supply_core.c +31 -0
@@ -17,6 +17,7 @@#include <linux/device.h> #include <linux/notifier.h> #include <linux/err.h> +#include <linux/of.h> #include <linux/power_supply.h> #include <linux/thermal.h> #include "power_supply.h"
@@ -487,6 +488,36 @@ struct power_supply *devm_power_supply_get_by_phandle(struct device *dev,EXPORT_SYMBOL_GPL (devm_power_supply_get_by_phandle);#endif /* CONFIG_OF */ +int power_supply_get_battery_info (struct power_supply *psy, +struct power_supply_battery_info *info, +const char *property) +{ +struct device_node *np = psy->of_node; +struct device_node *power_supply_battery_info_np; +int ret; + +if (!np) +return -ENXIO ; + + power_supply_battery_info_np =of_parse_phandle (np, property,0 ); +if (!power_supply_battery_info_np) +return -ENODEV ; + + ret =of_property_read_u32 (power_supply_battery_info_np, +"nominal-microvolt" , &info->nominal_voltage); +if (ret <0 ) +return ret; + + ret =of_property_read_u32 (power_supply_battery_info_np, +"design-microwatt-hours" , &info->energy); +if (ret <0 ) +return ret; + +return of_property_read_u32 (power_supply_battery_info_np, +"design-microamp-hours" , &info->power); +} +EXPORT_SYMBOL_GPL (power_supply_get_battery_info); +int power_supply_get_property (struct power_supply *psy,enum power_supply_property psp,union power_supply_propval *val)
include/linux/power_supply.h +4 -0
@@ -318,6 +318,10 @@ static inline struct power_supply * devm_power_supply_get_by_phandle(struct device *dev, const char *property) {return NULL ; }#endif /* CONFIG_OF */ + +extern int power_supply_get_battery_info (struct power_supply *psy, +struct power_supply_battery_info *info, +const char *property);extern void power_supply_changed (struct power_supply *psy);extern int power_supply_am_i_supplied (struct power_supply *psy);extern int power_supply_set_battery_charged (struct power_supply *psy);
Signature · 1 line
2.10.2
PATCH v3 6/7 devicetree: power: bq27xxx: add monitored battery documentation
In reply to Matt RanostayDepends-On: http://marc.info/?l=linux-pm&m=148392292830015&w=2
--- Documentation/devicetree/bindings/power/supply/bq27xxx.txt | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/power/supply/bq27xxx.txt +8 -0
@@ -28,9 +28,17 @@ Required properties: * "ti,bq27621" - BQ27621 - reg: integer, i2c address of the device. +Optional properties: +- monitored-battery: phandle of battery information devicetree node + + See Documentation/devicetree/bindings/power/supply/battery.txt + If any of the referenced battery properties are set, then all must be. + Example: bq27510g3 { compatible = "ti,bq27510g3"; reg = <0x55>; + + monitored-battery = <&bat>; };
Signature · 1 line
2.10.2
A message that is not in the archive (sent off-list or not yet received): 20170111062003.10110-7-matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org
Re: [PATCH v3 6/7] devicetree: power: bq27xxx: add monitored battery documentation
Quoted 12 lines · Matt Ranostay
Depends-On: http://marc.info/?l=linux-pm&m=148392292830015&w=2
Cc Rob Herring <[email protected]>Signed-off-by Matt Ranostay <[email protected]>--- Documentation/devicetree/bindings/power/supply/bq27xxx.txt | 8 ++++++++ 1 file changed, 8 insertions(+)Documentation/devicetree/bindings/power/supply/bq27xxx.txt +0
-0
Documentation/devicetree/bindings/power/supply/bq27xxx.txt Required properties: · line 32
Quoted 5 lines
Documentation/devicetree/bindings/power/supply/bq27xxx.txt +2
-0@@ -28,9 +28,17 @@ Required properties: * "ti,bq27621" - BQ27621 - reg: integer, i2c address of the device. +Optional properties: +- monitored-battery: phandle of battery information devicetree node
We need a common way to describe charger/monitor to battery connections, not yet another way. The battery and power supply related bindings are a bit of a mess from what I've looked at.
Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 6/7] devicetree: power: bq27xxx: add monitored battery documentation
Quoted 16 lines · Rob Herring
Quoted 15 lines · Matt Ranostay
Depends-On: http://marc.info/?l=linux-pm&m=148392292830015&w=2
Cc Rob Herring <[email protected]>Signed-off-by Matt Ranostay <[email protected]>--- Documentation/devicetree/bindings/power/supply/bq27xxx.txt | 8 ++++++++ 1 file changed, 8 insertions(+)Documentation/devicetree/bindings/power/supply/bq27xxx.txt +0
-0@@ -28,9 +28,17 @@ Required properties: * "ti,bq27621" - BQ27621 - reg: integer, i2c address of the device.
Quoted 6 lines
Documentation/devicetree/bindings/power/supply/bq27xxx.txt Required properties: · line 32
Quoted 2 lines
Documentation/devicetree/bindings/power/supply/bq27xxx.txt +2
-0+Optional properties: +- monitored-battery: phandle of battery information devicetree nodeWe need a common way to describe charger/monitor to battery connections, not yet another way. The battery and power supply related bindings are a bit of a mess from what I've looked at.
Sebastian, your thoughts here?
Thanks,
Matt
Quoted 2 lines
Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): CAJ_EiSRnU1q8QPKO43hk3ajS=RaAtQ2tVJ-060GcmPoPA6Ranw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [PATCH v3 6/7] devicetree: power: bq27xxx: add monitored battery documentation
Hi Matt,
Quoted 17 lines · Matt Ranostay
Quoted 16 lines · Rob Herring
Quoted 15 lines · Matt Ranostay
Depends-On: http://marc.info/?l=linux-pm&m=148392292830015&w=2
Cc Rob Herring <[email protected]>Signed-off-by Matt Ranostay <[email protected]>--- Documentation/devicetree/bindings/power/supply/bq27xxx.txt | 8 ++++++++ 1 file changed, 8 insertions(+)Documentation/devicetree/bindings/power/supply/bq27xxx.txt +0
-0@@ -28,9 +28,17 @@ Required properties: * "ti,bq27621" - BQ27621 - reg: integer, i2c address of the device.
Quoted 8 lines
Quoted 6 lines
Documentation/devicetree/bindings/power/supply/bq27xxx.txt Required properties: · line 32
Quoted 2 lines
Documentation/devicetree/bindings/power/supply/bq27xxx.txt +2
-0+Optional properties: +- monitored-battery: phandle of battery information devicetree nodeWe need a common way to describe charger/monitor to battery connections, not yet another way. The battery and power supply related bindings are a bit of a mess from what I've looked at.
Sebastian, your thoughts here?
On what part? Did you receive my comment on patch 1 from this patchset? There I wrote basically the same:
Quoted 7 lines
I think we should mandate the property name of the phandle in the generic binding instead of each potential fuel-gauge/charger. Maybe something like the following paragraph:
Batteries are supposed to be referenced by chargers and/or fuel-gauges using a phandle. The phandle's property should be named "monitored-battery".
If you mean the second sentence: Yes, DT bindings for the power-supply subsystem are a mess unfortunately. It's partially my fault, but the (IMHO) really bad ones were already there when I took over the power-supply subsystem (e.g. charger-manager, which does not even describe real HW).
One of the problems is, that the power-supply subsystem does not know about the difference between a fuel-gauge and a battery, since smart batteries contain a fuel-gauge.
Regarding the phandles: We do have a standard property for the battery <-> charger connection, which is described in
Documentation/devicetree/bindings/power/supply/power_supply.txt
Like most of the power-supply subsystem it expects, that battery is a smart-battery with fuel-gauge. It does not really fit for the battery <-> fuel-gauge connection, though.
TLDR: I suggest you implement the changes suggested by me and Rob in patch 1 and resend the patch series. Then let's see if Rob is ok with it.
-- Sebastian