power: supply: core: Add power_supply_battery_info and API
power_supply_get_battery_info() reads battery data from devicetree. struct power_supply_battery_info provides battery data to drivers. Its fields correspond to elements in enum power_supply_property. Drivers may surface battery data in sysfs via corresponding POWER_SUPPLY_PROP_* fields. Signed-off-by: Matt Ranostay <matt@ranostay.consulting> Signed-off-by: Liam Breck <kernel@networkimprov.net> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
This commit is contained in:
committed by
Sebastian Reichel
parent
230670479a
commit
c08b1f45d7
@ -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"
|
||||
@ -519,6 +520,62 @@ 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)
|
||||
{
|
||||
struct device_node *battery_np;
|
||||
const char *value;
|
||||
int err;
|
||||
|
||||
info->energy_full_design_uwh = -EINVAL;
|
||||
info->charge_full_design_uah = -EINVAL;
|
||||
info->voltage_min_design_uv = -EINVAL;
|
||||
info->precharge_current_ua = -EINVAL;
|
||||
info->charge_term_current_ua = -EINVAL;
|
||||
info->constant_charge_current_max_ua = -EINVAL;
|
||||
info->constant_charge_voltage_max_uv = -EINVAL;
|
||||
|
||||
if (!psy->of_node) {
|
||||
dev_warn(&psy->dev, "%s currently only supports devicetree\n",
|
||||
__func__);
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0);
|
||||
if (!battery_np)
|
||||
return -ENODEV;
|
||||
|
||||
err = of_property_read_string(battery_np, "compatible", &value);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (strcmp("simple-battery", value))
|
||||
return -ENODEV;
|
||||
|
||||
/* The property and field names below must correspond to elements
|
||||
* in enum power_supply_property. For reasoning, see
|
||||
* Documentation/power/power_supply_class.txt.
|
||||
*/
|
||||
|
||||
of_property_read_u32(battery_np, "energy-full-design-microwatt-hours",
|
||||
&info->energy_full_design_uwh);
|
||||
of_property_read_u32(battery_np, "charge-full-design-microamp-hours",
|
||||
&info->charge_full_design_uah);
|
||||
of_property_read_u32(battery_np, "voltage-min-design-microvolt",
|
||||
&info->voltage_min_design_uv);
|
||||
of_property_read_u32(battery_np, "precharge-current-microamp",
|
||||
&info->precharge_current_ua);
|
||||
of_property_read_u32(battery_np, "charge-term-current-microamp",
|
||||
&info->charge_term_current_ua);
|
||||
of_property_read_u32(battery_np, "constant_charge_current_max_microamp",
|
||||
&info->constant_charge_current_max_ua);
|
||||
of_property_read_u32(battery_np, "constant_charge_voltage_max_microvolt",
|
||||
&info->constant_charge_voltage_max_uv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
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)
|
||||
|
Reference in New Issue
Block a user