Message ID | 20230308084419.11934-3-clamor95@gmail.com |
---|---|
State | New |
Headers | show |
Series | Add optional properties to MAX17040 | expand |
Hi, On Wed, Mar 08, 2023 at 10:44:17AM +0200, Svyatoslav Ryhel wrote: > Simple battery cell allows to pass some constant data > about battery controlled by this fuel gauge. > > Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> > --- This patch is no longer needed, since the core should automatically expose the properties with the latest kernel: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=27a2195efa8d26447c40dd4a6299ea0247786d75 -- Sebastian > drivers/power/supply/max17040_battery.c | 34 +++++++++++++++++++++++++ > 1 file changed, 34 insertions(+) > > diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c > index d1075959dd46..2778ed5b5c14 100644 > --- a/drivers/power/supply/max17040_battery.c > +++ b/drivers/power/supply/max17040_battery.c > @@ -141,6 +141,7 @@ struct max17040_chip { > struct regmap *regmap; > struct delayed_work work; > struct power_supply *battery; > + struct power_supply_battery_info *batt_info; > struct chip_data data; > > /* battery capacity */ > @@ -400,6 +401,28 @@ static int max17040_get_property(struct power_supply *psy, > case POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN: > val->intval = chip->low_soc_alert; > break; > + > + case POWER_SUPPLY_PROP_TECHNOLOGY: > + val->intval = chip->batt_info->technology; > + break; > + case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: > + val->intval = chip->batt_info->energy_full_design_uwh; > + break; > + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: > + val->intval = chip->batt_info->charge_full_design_uah; > + break; > + case POWER_SUPPLY_PROP_TEMP_MIN: > + if (chip->batt_info->temp_min == INT_MIN) > + return -ENODATA; > + > + val->intval = chip->batt_info->temp_min * 10; > + break; > + case POWER_SUPPLY_PROP_TEMP_MAX: > + if (chip->batt_info->temp_max == INT_MAX) > + return -ENODATA; > + > + val->intval = chip->batt_info->temp_max * 10; > + break; > default: > return -EINVAL; > } > @@ -418,6 +441,11 @@ static enum power_supply_property max17040_battery_props[] = { > POWER_SUPPLY_PROP_VOLTAGE_NOW, > POWER_SUPPLY_PROP_CAPACITY, > POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN, > + POWER_SUPPLY_PROP_TECHNOLOGY, > + POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, > + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, > + POWER_SUPPLY_PROP_TEMP_MIN, > + POWER_SUPPLY_PROP_TEMP_MAX, > }; > > static const struct power_supply_desc max17040_battery_desc = { > @@ -470,6 +498,12 @@ static int max17040_probe(struct i2c_client *client) > return PTR_ERR(chip->battery); > } > > + if (client->dev.of_node) { > + if (power_supply_get_battery_info(chip->battery, &chip->batt_info)) > + dev_warn(&client->dev, > + "No monitored battery, some properties will be missing\n"); > + } > + > ret = max17040_get_version(chip); > if (ret < 0) > return ret; > -- > 2.37.2 >
diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c index d1075959dd46..2778ed5b5c14 100644 --- a/drivers/power/supply/max17040_battery.c +++ b/drivers/power/supply/max17040_battery.c @@ -141,6 +141,7 @@ struct max17040_chip { struct regmap *regmap; struct delayed_work work; struct power_supply *battery; + struct power_supply_battery_info *batt_info; struct chip_data data; /* battery capacity */ @@ -400,6 +401,28 @@ static int max17040_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN: val->intval = chip->low_soc_alert; break; + + case POWER_SUPPLY_PROP_TECHNOLOGY: + val->intval = chip->batt_info->technology; + break; + case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: + val->intval = chip->batt_info->energy_full_design_uwh; + break; + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: + val->intval = chip->batt_info->charge_full_design_uah; + break; + case POWER_SUPPLY_PROP_TEMP_MIN: + if (chip->batt_info->temp_min == INT_MIN) + return -ENODATA; + + val->intval = chip->batt_info->temp_min * 10; + break; + case POWER_SUPPLY_PROP_TEMP_MAX: + if (chip->batt_info->temp_max == INT_MAX) + return -ENODATA; + + val->intval = chip->batt_info->temp_max * 10; + break; default: return -EINVAL; } @@ -418,6 +441,11 @@ static enum power_supply_property max17040_battery_props[] = { POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_CAPACITY, POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN, + POWER_SUPPLY_PROP_TECHNOLOGY, + POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, + POWER_SUPPLY_PROP_TEMP_MIN, + POWER_SUPPLY_PROP_TEMP_MAX, }; static const struct power_supply_desc max17040_battery_desc = { @@ -470,6 +498,12 @@ static int max17040_probe(struct i2c_client *client) return PTR_ERR(chip->battery); } + if (client->dev.of_node) { + if (power_supply_get_battery_info(chip->battery, &chip->batt_info)) + dev_warn(&client->dev, + "No monitored battery, some properties will be missing\n"); + } + ret = max17040_get_version(chip); if (ret < 0) return ret;
Simple battery cell allows to pass some constant data about battery controlled by this fuel gauge. Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> --- drivers/power/supply/max17040_battery.c | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+)